1 From 46e67acd5d4cacda758e871eebd15cef4e2c2665 Mon Sep 17 00:00:00 2001
2 From: Mauro Carvalho Chehab <mchehab@redhat.com>
3 Date: Mon, 3 Jan 2011 09:09:56 -0200
4 Subject: [PATCH 51/66] [media] wm8775: Revert changeset fcb9757333 to avoid a regression
6 It seems that cx88 and ivtv use wm8775 on some different modes. The
7 patch that added support for a board with wm8775 broke ivtv boards with
8 this device. As we're too close to release 2.6.37, let's just revert
11 Reported-by: Andy Walls <awalls@md.metrocast.net>
12 Reported-by: Eric Sharkey <eric@lisaneric.org>
13 Reported-by: Auric <auric@aanet.com.au>
14 Reported by: David Gesswein <djg@pdp8online.com>
15 Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
17 drivers/media/video/cx88/cx88-alsa.c | 99 ++++---------------------------
18 drivers/media/video/cx88/cx88-cards.c | 7 ++
19 drivers/media/video/cx88/cx88-video.c | 27 +--------
20 drivers/media/video/cx88/cx88.h | 6 +-
21 drivers/media/video/wm8775.c | 104 ++++++++++++--------------------
22 include/media/wm8775.h | 3 -
23 6 files changed, 61 insertions(+), 185 deletions(-)
25 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
26 index 4aaa47c..54b7fcd 100644
27 --- a/drivers/media/video/cx88/cx88-alsa.c
28 +++ b/drivers/media/video/cx88/cx88-alsa.c
30 #include <sound/control.h>
31 #include <sound/initval.h>
32 #include <sound/tlv.h>
33 -#include <media/wm8775.h>
37 @@ -587,47 +586,26 @@ static int snd_cx88_volume_put(struct snd_kcontrol *kcontrol,
38 int left, right, v, b;
41 - struct v4l2_control client_ctl;
43 - /* Pass volume & balance onto any WM8775 */
44 - if (value->value.integer.value[0] >= value->value.integer.value[1]) {
45 - v = value->value.integer.value[0] << 10;
46 - b = value->value.integer.value[0] ?
47 - (0x8000 * value->value.integer.value[1]) / value->value.integer.value[0] :
50 - v = value->value.integer.value[1] << 10;
51 - b = value->value.integer.value[1] ?
52 - 0xffff - (0x8000 * value->value.integer.value[0]) / value->value.integer.value[1] :
55 - client_ctl.value = v;
56 - client_ctl.id = V4L2_CID_AUDIO_VOLUME;
57 - call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
59 - client_ctl.value = b;
60 - client_ctl.id = V4L2_CID_AUDIO_BALANCE;
61 - call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
63 left = value->value.integer.value[0] & 0x3f;
64 right = value->value.integer.value[1] & 0x3f;
75 /* Do we really know this will always be called with IRQs on? */
76 spin_lock_irq(&chip->reg_lock);
77 old = cx_read(AUD_VOL_CTL);
78 if (v != (old & 0x3f)) {
79 - cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, (old & ~0x3f) | v);
81 + cx_write(AUD_VOL_CTL, (old & ~0x3f) | v);
84 - if ((cx_read(AUD_BAL_CTL) & 0x7f) != b) {
85 - cx_write(AUD_BAL_CTL, b);
87 + if (cx_read(AUD_BAL_CTL) != b) {
88 + cx_write(AUD_BAL_CTL, b);
91 spin_unlock_irq(&chip->reg_lock);
93 @@ -640,7 +618,7 @@ static const struct snd_kcontrol_new snd_cx88_volume = {
94 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
95 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
96 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
97 - .name = "Analog-TV Volume",
98 + .name = "Playback Volume",
99 .info = snd_cx88_volume_info,
100 .get = snd_cx88_volume_get,
101 .put = snd_cx88_volume_put,
102 @@ -671,14 +649,7 @@ static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol,
103 vol = cx_read(AUD_VOL_CTL);
104 if (value->value.integer.value[0] != !(vol & bit)) {
106 - cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, vol);
107 - /* Pass mute onto any WM8775 */
108 - if ((1<<6) == bit) {
109 - struct v4l2_control client_ctl;
110 - client_ctl.value = 0 != (vol & bit);
111 - client_ctl.id = V4L2_CID_AUDIO_MUTE;
112 - call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
114 + cx_write(AUD_VOL_CTL, vol);
117 spin_unlock_irq(&chip->reg_lock);
118 @@ -687,7 +658,7 @@ static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol,
120 static const struct snd_kcontrol_new snd_cx88_dac_switch = {
121 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
122 - .name = "Audio-Out Switch",
123 + .name = "Playback Switch",
124 .info = snd_ctl_boolean_mono_info,
125 .get = snd_cx88_switch_get,
126 .put = snd_cx88_switch_put,
127 @@ -696,49 +667,13 @@ static const struct snd_kcontrol_new snd_cx88_dac_switch = {
129 static const struct snd_kcontrol_new snd_cx88_source_switch = {
130 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
131 - .name = "Analog-TV Switch",
132 + .name = "Capture Switch",
133 .info = snd_ctl_boolean_mono_info,
134 .get = snd_cx88_switch_get,
135 .put = snd_cx88_switch_put,
136 .private_value = (1<<6),
139 -static int snd_cx88_alc_get(struct snd_kcontrol *kcontrol,
140 - struct snd_ctl_elem_value *value)
142 - snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
143 - struct cx88_core *core = chip->core;
144 - struct v4l2_control client_ctl;
146 - client_ctl.id = V4L2_CID_AUDIO_LOUDNESS;
147 - call_hw(core, WM8775_GID, core, g_ctrl, &client_ctl);
148 - value->value.integer.value[0] = client_ctl.value ? 1 : 0;
153 -static int snd_cx88_alc_put(struct snd_kcontrol *kcontrol,
154 - struct snd_ctl_elem_value *value)
156 - snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
157 - struct cx88_core *core = chip->core;
158 - struct v4l2_control client_ctl;
160 - client_ctl.value = 0 != value->value.integer.value[0];
161 - client_ctl.id = V4L2_CID_AUDIO_LOUDNESS;
162 - call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
167 -static struct snd_kcontrol_new snd_cx88_alc_switch = {
168 - .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
169 - .name = "Line-In ALC Switch",
170 - .info = snd_ctl_boolean_mono_info,
171 - .get = snd_cx88_alc_get,
172 - .put = snd_cx88_alc_put,
175 /****************************************************************************
176 Basic Flow for Sound Devices
177 ****************************************************************************/
178 @@ -860,7 +795,6 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
180 struct snd_card *card;
181 snd_cx88_card_t *chip;
182 - struct v4l2_subdev *sd;
185 if (devno >= SNDRV_CARDS)
186 @@ -896,15 +830,6 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
190 - /* If there's a wm8775 then add a Line-In ALC switch */
191 - list_for_each_entry(sd, &chip->core->v4l2_dev.subdevs, list) {
192 - if (WM8775_GID == sd->grp_id) {
193 - snd_ctl_add(card, snd_ctl_new1(&snd_cx88_alc_switch,
199 strcpy (card->driver, "CX88x");
200 sprintf(card->shortname, "Conexant CX%x", pci->device);
201 sprintf(card->longname, "%s at %#llx",
202 diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
203 index 9b9e169..0ccc2af 100644
204 --- a/drivers/media/video/cx88/cx88-cards.c
205 +++ b/drivers/media/video/cx88/cx88-cards.c
206 @@ -1007,15 +1007,22 @@ static const struct cx88_board cx88_boards[] = {
208 .tuner_addr = ADDR_UNSET,
209 .radio_addr = ADDR_UNSET,
210 + .audio_chip = V4L2_IDENT_WM8775,
212 .type = CX88_VMUX_DVB,
217 .type = CX88_VMUX_COMPOSITE1,
222 .type = CX88_VMUX_SVIDEO,
227 .mpeg = CX88_MPEG_DVB,
229 diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
230 index 62cea95..d9249e5 100644
231 --- a/drivers/media/video/cx88/cx88-video.c
232 +++ b/drivers/media/video/cx88/cx88-video.c
235 #include <media/v4l2-common.h>
236 #include <media/v4l2-ioctl.h>
237 -#include <media/wm8775.h>
239 MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
240 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
241 @@ -977,7 +976,6 @@ int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl)
242 const struct cx88_ctrl *c = NULL;
245 - struct v4l2_control client_ctl;
247 for (i = 0; i < CX8800_CTLS; i++) {
248 if (cx8800_ctls[i].v.id == ctl->id) {
249 @@ -991,27 +989,6 @@ int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl)
250 ctl->value = c->v.minimum;
251 if (ctl->value > c->v.maximum)
252 ctl->value = c->v.maximum;
254 - /* Pass changes onto any WM8775 */
255 - client_ctl.id = ctl->id;
257 - case V4L2_CID_AUDIO_MUTE:
258 - client_ctl.value = ctl->value;
260 - case V4L2_CID_AUDIO_VOLUME:
261 - client_ctl.value = (ctl->value) ?
262 - (0x90 + ctl->value) << 8 : 0;
264 - case V4L2_CID_AUDIO_BALANCE:
265 - client_ctl.value = ctl->value << 9;
272 - call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl);
276 case V4L2_CID_AUDIO_BALANCE:
277 @@ -1558,9 +1535,7 @@ static int radio_queryctrl (struct file *file, void *priv,
278 if (c->id < V4L2_CID_BASE ||
279 c->id >= V4L2_CID_LASTP1)
281 - if (c->id == V4L2_CID_AUDIO_MUTE ||
282 - c->id == V4L2_CID_AUDIO_VOLUME ||
283 - c->id == V4L2_CID_AUDIO_BALANCE) {
284 + if (c->id == V4L2_CID_AUDIO_MUTE) {
285 for (i = 0; i < CX8800_CTLS; i++) {
286 if (cx8800_ctls[i].v.id == c->id)
288 diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
289 index e8c732e..c9981e7 100644
290 --- a/drivers/media/video/cx88/cx88.h
291 +++ b/drivers/media/video/cx88/cx88.h
292 @@ -398,19 +398,17 @@ static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev)
293 return container_of(v4l2_dev, struct cx88_core, v4l2_dev);
296 -#define call_hw(core, grpid, o, f, args...) \
297 +#define call_all(core, o, f, args...) \
299 if (!core->i2c_rc) { \
300 if (core->gate_ctrl) \
301 core->gate_ctrl(core, 1); \
302 - v4l2_device_call_all(&core->v4l2_dev, grpid, o, f, ##args); \
303 + v4l2_device_call_all(&core->v4l2_dev, 0, o, f, ##args); \
304 if (core->gate_ctrl) \
305 core->gate_ctrl(core, 0); \
309 -#define call_all(core, o, f, args...) call_hw(core, 0, o, f, ##args)
314 diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
315 index 1355256..fe8ef64 100644
316 --- a/drivers/media/video/wm8775.c
317 +++ b/drivers/media/video/wm8775.c
319 #include <media/v4l2-device.h>
320 #include <media/v4l2-chip-ident.h>
321 #include <media/v4l2-ctrls.h>
322 -#include <media/wm8775.h>
324 MODULE_DESCRIPTION("wm8775 driver");
325 MODULE_AUTHOR("Ulf Eklund, Hans Verkuil");
326 @@ -51,16 +50,10 @@ enum {
330 -#define ALC_HOLD 0x85 /* R17: use zero cross detection, ALC hold time 42.6 ms */
331 -#define ALC_EN 0x100 /* R17: ALC enable */
333 struct wm8775_state {
334 struct v4l2_subdev sd;
335 struct v4l2_ctrl_handler hdl;
336 struct v4l2_ctrl *mute;
337 - struct v4l2_ctrl *vol;
338 - struct v4l2_ctrl *bal;
339 - struct v4l2_ctrl *loud;
340 u8 input; /* Last selected input (0-0xf) */
343 @@ -92,30 +85,6 @@ static int wm8775_write(struct v4l2_subdev *sd, int reg, u16 val)
347 -static void wm8775_set_audio(struct v4l2_subdev *sd, int quietly)
349 - struct wm8775_state *state = to_state(sd);
351 - int muted = 0 != state->mute->val;
352 - u16 volume = (u16)state->vol->val;
353 - u16 balance = (u16)state->bal->val;
355 - /* normalize ( 65535 to 0 -> 255 to 0 (+24dB to -103dB) ) */
356 - vol_l = (min(65536 - balance, 32768) * volume) >> 23;
357 - vol_r = (min(balance, (u16)32768) * volume) >> 23;
360 - if (muted || quietly)
361 - wm8775_write(sd, R21, 0x0c0 | state->input);
363 - wm8775_write(sd, R14, vol_l | 0x100); /* 0x100= Left channel ADC zero cross enable */
364 - wm8775_write(sd, R15, vol_r | 0x100); /* 0x100= Right channel ADC zero cross enable */
368 - wm8775_write(sd, R21, state->input);
371 static int wm8775_s_routing(struct v4l2_subdev *sd,
372 u32 input, u32 output, u32 config)
374 @@ -133,26 +102,25 @@ static int wm8775_s_routing(struct v4l2_subdev *sd,
375 state->input = input;
376 if (!v4l2_ctrl_g_ctrl(state->mute))
378 - if (!v4l2_ctrl_g_ctrl(state->vol))
380 - if (!v4l2_ctrl_g_ctrl(state->bal))
382 - wm8775_set_audio(sd, 1);
383 + wm8775_write(sd, R21, 0x0c0);
384 + wm8775_write(sd, R14, 0x1d4);
385 + wm8775_write(sd, R15, 0x1d4);
386 + wm8775_write(sd, R21, 0x100 + state->input);
390 static int wm8775_s_ctrl(struct v4l2_ctrl *ctrl)
392 struct v4l2_subdev *sd = to_sd(ctrl);
393 + struct wm8775_state *state = to_state(sd);
396 case V4L2_CID_AUDIO_MUTE:
397 - case V4L2_CID_AUDIO_VOLUME:
398 - case V4L2_CID_AUDIO_BALANCE:
399 - wm8775_set_audio(sd, 0);
401 - case V4L2_CID_AUDIO_LOUDNESS:
402 - wm8775_write(sd, R17, (ctrl->val ? ALC_EN : 0) | ALC_HOLD);
403 + wm8775_write(sd, R21, 0x0c0);
404 + wm8775_write(sd, R14, 0x1d4);
405 + wm8775_write(sd, R15, 0x1d4);
407 + wm8775_write(sd, R21, 0x100 + state->input);
411 @@ -176,7 +144,16 @@ static int wm8775_log_status(struct v4l2_subdev *sd)
413 static int wm8775_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq)
415 - wm8775_set_audio(sd, 0);
416 + struct wm8775_state *state = to_state(sd);
418 + /* If I remove this, then it can happen that I have no
419 + sound the first time I tune from static to a valid channel.
420 + It's difficult to reproduce and is almost certainly related
421 + to the zero cross detect circuit. */
422 + wm8775_write(sd, R21, 0x0c0);
423 + wm8775_write(sd, R14, 0x1d4);
424 + wm8775_write(sd, R15, 0x1d4);
425 + wm8775_write(sd, R21, 0x100 + state->input);
429 @@ -226,7 +203,6 @@ static int wm8775_probe(struct i2c_client *client,
431 struct wm8775_state *state;
432 struct v4l2_subdev *sd;
435 /* Check if the adapter supports the needed features */
436 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
437 @@ -240,21 +216,15 @@ static int wm8775_probe(struct i2c_client *client,
440 v4l2_i2c_subdev_init(sd, client, &wm8775_ops);
441 - sd->grp_id = WM8775_GID; /* subdev group id */
444 - v4l2_ctrl_handler_init(&state->hdl, 4);
445 + v4l2_ctrl_handler_init(&state->hdl, 1);
446 state->mute = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
447 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
448 - state->vol = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
449 - V4L2_CID_AUDIO_VOLUME, 0, 65535, (65535+99)/100, 0xCF00); /* 0dB*/
450 - state->bal = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
451 - V4L2_CID_AUDIO_BALANCE, 0, 65535, (65535+99)/100, 32768);
452 - state->loud = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
453 - V4L2_CID_AUDIO_LOUDNESS, 0, 1, 1, 1);
454 sd->ctrl_handler = &state->hdl;
455 - err = state->hdl.error;
457 + if (state->hdl.error) {
458 + int err = state->hdl.error;
460 v4l2_ctrl_handler_free(&state->hdl);
463 @@ -266,25 +236,29 @@ static int wm8775_probe(struct i2c_client *client,
464 wm8775_write(sd, R23, 0x000);
465 /* Disable zero cross detect timeout */
466 wm8775_write(sd, R7, 0x000);
467 - /* HPF enable, I2S mode, 24-bit */
468 - wm8775_write(sd, R11, 0x022);
469 + /* Left justified, 24-bit mode */
470 + wm8775_write(sd, R11, 0x021);
471 /* Master mode, clock ratio 256fs */
472 wm8775_write(sd, R12, 0x102);
474 wm8775_write(sd, R13, 0x000);
475 - /* ALC stereo, ALC target level -5dB FS, ALC max gain +8dB */
476 - wm8775_write(sd, R16, 0x1bb);
477 - /* Set ALC mode and hold time */
478 - wm8775_write(sd, R17, (state->loud->val ? ALC_EN : 0) | ALC_HOLD);
479 + /* ADC gain +2.5dB, enable zero cross */
480 + wm8775_write(sd, R14, 0x1d4);
481 + /* ADC gain +2.5dB, enable zero cross */
482 + wm8775_write(sd, R15, 0x1d4);
483 + /* ALC Stereo, ALC target level -1dB FS max gain +8dB */
484 + wm8775_write(sd, R16, 0x1bf);
485 + /* Enable gain control, use zero cross detection,
486 + ALC hold time 42.6 ms */
487 + wm8775_write(sd, R17, 0x185);
488 /* ALC gain ramp up delay 34 s, ALC gain ramp down delay 33 ms */
489 wm8775_write(sd, R18, 0x0a2);
490 /* Enable noise gate, threshold -72dBfs */
491 wm8775_write(sd, R19, 0x005);
492 - /* Transient window 4ms, ALC min gain -5dB */
493 - wm8775_write(sd, R20, 0x0fb);
495 - wm8775_set_audio(sd, 1); /* set volume/mute/mux */
497 + /* Transient window 4ms, lower PGA gain limit -1dB */
498 + wm8775_write(sd, R20, 0x07a);
499 + /* LRBOTH = 1, use input 2. */
500 + wm8775_write(sd, R21, 0x102);
504 diff --git a/include/media/wm8775.h b/include/media/wm8775.h
505 index a1c4d41..60739c5 100644
506 --- a/include/media/wm8775.h
507 +++ b/include/media/wm8775.h
509 #define WM8775_AIN3 4
510 #define WM8775_AIN4 8
512 -/* subdev group ID */
513 -#define WM8775_GID (1 << 0)