Commit 3192e006 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[media] bttv: fix audio hooks

as reported by smatch:
	drivers/media/pci/bt8xx/bttv-audio-hook.c:201 lt9415_audio() warn: bitwise AND condition is false here
	drivers/media/pci/bt8xx/bttv-audio-hook.c:241 winfast2000_audio() warn: bitwise AND condition is false here
	drivers/media/pci/bt8xx/bttv-audio-hook.c:276 pvbt878p9b_audio() warn: bitwise AND condition is false here
	drivers/media/pci/bt8xx/bttv-audio-hook.c:307 fv2000s_audio() warn: bitwise AND condition is false here
	drivers/media/pci/bt8xx/bttv-audio-hook.c:334 windvr_audio() warn: bitwise AND condition is false here
	drivers/media/pci/bt8xx/bttv-audio-hook.c:371 adtvk503_audio() warn: bitwise AND condition is false here

there are some serious issues at the audio hook implementation.

They're not following what's specified at the DocBook:
	http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-g-tuner.html#tuner-audmode

Basically, it was assuming that the audmode (V4L2_TUNER_MODE_foo)
is a variable with a bit maskk. However, it isn't.

The bitmask only applies to rxsubchans field (V4L2_TUNER_SUB_foo).

As the code is also too complex, and not all hooks were returning
both audmode and rxsubchans to a VIDIOC_G_TUNER, rewrite the
functions, in order to fix both for get and set tuner ioctls.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent b674ac29
...@@ -54,23 +54,33 @@ void winview_volume(struct bttv *btv, __u16 volume) ...@@ -54,23 +54,33 @@ void winview_volume(struct bttv *btv, __u16 volume)
void gvbctv3pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set) void gvbctv3pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
{ {
unsigned int con = 0; unsigned int con;
if (set) { if (!set) {
gpio_inout(0x300, 0x300); /* Not much to do here */
if (t->audmode & V4L2_TUNER_MODE_LANG1) t->audmode = V4L2_TUNER_MODE_LANG1;
con = 0x000; t->rxsubchans = V4L2_TUNER_SUB_MONO |
if (t->audmode & V4L2_TUNER_MODE_LANG2) V4L2_TUNER_SUB_STEREO |
con = 0x300; V4L2_TUNER_SUB_LANG1 |
if (t->audmode & V4L2_TUNER_MODE_STEREO) V4L2_TUNER_SUB_LANG2;
con = 0x200;
/* if (t->audmode & V4L2_TUNER_MODE_MONO) return;
* con = 0x100; */ }
gpio_bits(0x300, con);
} else { gpio_inout(0x300, 0x300);
t->audmode = V4L2_TUNER_MODE_STEREO | switch (t->audmode) {
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; case V4L2_TUNER_MODE_LANG1:
default:
con = 0x000;
break;
case V4L2_TUNER_MODE_LANG2:
con = 0x300;
break;
case V4L2_TUNER_MODE_STEREO:
con = 0x200;
break;
} }
gpio_bits(0x300, con);
} }
void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set) void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
...@@ -82,47 +92,51 @@ void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set) ...@@ -82,47 +92,51 @@ void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
val = gpio_read(); val = gpio_read();
if (set) { if (set) {
con = 0x000; switch (t->audmode) {
if (t->audmode & V4L2_TUNER_MODE_LANG2) { case V4L2_TUNER_MODE_LANG2:
if (t->audmode & V4L2_TUNER_MODE_LANG1) { con = 0x300;
/* LANG1 + LANG2 */ break;
con = 0x100; case V4L2_TUNER_MODE_LANG1_LANG2:
} con = 0x100;
else { break;
/* LANG2 */ default:
con = 0x300; con = 0x000;
} break;
} }
if (con != (val & 0x300)) { if (con != (val & 0x300)) {
gpio_bits(0x300, con); gpio_bits(0x300, con);
if (bttv_gpio) if (bttv_gpio)
bttv_gpio_tracking(btv,"gvbctv5pci"); bttv_gpio_tracking(btv, "gvbctv5pci");
} }
} else { } else {
switch (val & 0x70) { switch (val & 0x70) {
case 0x10: case 0x10:
t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
break; break;
case 0x30: case 0x30:
t->rxsubchans = V4L2_TUNER_SUB_LANG2; t->rxsubchans = V4L2_TUNER_SUB_LANG2;
t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
break; break;
case 0x50: case 0x50:
t->rxsubchans = V4L2_TUNER_SUB_LANG1; t->rxsubchans = V4L2_TUNER_SUB_LANG1;
t->audmode = V4L2_TUNER_MODE_LANG1_LANG2;
break; break;
case 0x60: case 0x60:
t->rxsubchans = V4L2_TUNER_SUB_STEREO; t->rxsubchans = V4L2_TUNER_SUB_STEREO;
t->audmode = V4L2_TUNER_MODE_STEREO;
break; break;
case 0x70: case 0x70:
t->rxsubchans = V4L2_TUNER_SUB_MONO; t->rxsubchans = V4L2_TUNER_SUB_MONO;
t->audmode = V4L2_TUNER_MODE_MONO;
break; break;
default: default:
t->rxsubchans = V4L2_TUNER_SUB_MONO | t->rxsubchans = V4L2_TUNER_SUB_MONO |
V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_STEREO |
V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG1 |
V4L2_TUNER_SUB_LANG2; V4L2_TUNER_SUB_LANG2;
t->audmode = V4L2_TUNER_MODE_LANG1;
} }
t->audmode = V4L2_TUNER_MODE_STEREO |
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
} }
} }
...@@ -142,23 +156,32 @@ void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set) ...@@ -142,23 +156,32 @@ void gvbctv5pci_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set) void avermedia_tvphone_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
{ {
int val = 0; int val;
if (set) { if (!set) {
if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */ /* Not much to do here */
val = 0x02; t->audmode = V4L2_TUNER_MODE_LANG1;
if (t->audmode & V4L2_TUNER_MODE_STEREO) t->rxsubchans = V4L2_TUNER_SUB_MONO |
val = 0x01; V4L2_TUNER_SUB_STEREO |
if (val) { V4L2_TUNER_SUB_LANG1 |
gpio_bits(0x03,val); V4L2_TUNER_SUB_LANG2;
if (bttv_gpio)
bttv_gpio_tracking(btv,"avermedia"); return;
} }
} else {
t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO | switch (t->audmode) {
V4L2_TUNER_MODE_LANG1; case V4L2_TUNER_MODE_LANG2: /* SAP */
val = 0x02;
break;
case V4L2_TUNER_MODE_STEREO:
val = 0x01;
break;
default:
return; return;
} }
gpio_bits(0x03, val);
if (bttv_gpio)
bttv_gpio_tracking(btv, "avermedia");
} }
...@@ -166,19 +189,31 @@ void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set) ...@@ -166,19 +189,31 @@ void avermedia_tv_stereo_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
{ {
int val = 0; int val = 0;
if (set) { if (!set) {
if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */ /* Not much to do here */
val = 0x01; t->audmode = V4L2_TUNER_MODE_LANG1;
if (t->audmode & V4L2_TUNER_MODE_STEREO) /* STEREO */ t->rxsubchans = V4L2_TUNER_SUB_MONO |
val = 0x02; V4L2_TUNER_SUB_STEREO |
btaor(val, ~0x03, BT848_GPIO_DATA); V4L2_TUNER_SUB_LANG1 |
if (bttv_gpio) V4L2_TUNER_SUB_LANG2;
bttv_gpio_tracking(btv,"avermedia");
} else {
t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
return; return;
} }
switch (t->audmode) {
case V4L2_TUNER_MODE_LANG2: /* SAP */
val = 0x01;
break;
case V4L2_TUNER_MODE_STEREO:
val = 0x02;
break;
default:
val = 0;
break;
}
btaor(val, ~0x03, BT848_GPIO_DATA);
if (bttv_gpio)
bttv_gpio_tracking(btv, "avermedia");
} }
/* Lifetec 9415 handling */ /* Lifetec 9415 handling */
...@@ -192,23 +227,32 @@ void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set) ...@@ -192,23 +227,32 @@ void lt9415_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
return; return;
} }
if (set) { if (!set) {
if (t->audmode & V4L2_TUNER_MODE_LANG2) /* A2 SAP */ /* Not much to do here */
val = 0x0080; t->audmode = V4L2_TUNER_MODE_LANG1;
if (t->audmode & V4L2_TUNER_MODE_STEREO) /* A2 stereo */ t->rxsubchans = V4L2_TUNER_SUB_MONO |
val = 0x0880; V4L2_TUNER_SUB_STEREO |
if ((t->audmode & V4L2_TUNER_MODE_LANG1) || V4L2_TUNER_SUB_LANG1 |
(t->audmode & V4L2_TUNER_MODE_MONO)) V4L2_TUNER_SUB_LANG2;
val = 0;
gpio_bits(0x0880, val);
if (bttv_gpio)
bttv_gpio_tracking(btv,"lt9415");
} else {
/* autodetect doesn't work with this card :-( */
t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
return; return;
} }
switch (t->audmode) {
case V4L2_TUNER_MODE_LANG2: /* A2 SAP */
val = 0x0080;
break;
case V4L2_TUNER_MODE_STEREO: /* A2 stereo */
val = 0x0880;
break;
default:
val = 0;
break;
}
gpio_bits(0x0880, val);
if (bttv_gpio)
bttv_gpio_tracking(btv, "lt9415");
} }
/* TDA9821 on TerraTV+ Bt848, Bt878 */ /* TDA9821 on TerraTV+ Bt848, Bt878 */
...@@ -216,45 +260,69 @@ void terratv_audio(struct bttv *btv, struct v4l2_tuner *t, int set) ...@@ -216,45 +260,69 @@ void terratv_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
{ {
unsigned int con = 0; unsigned int con = 0;
if (set) { if (!set) {
gpio_inout(0x180000,0x180000); /* Not much to do here */
if (t->audmode & V4L2_TUNER_MODE_LANG2) t->audmode = V4L2_TUNER_MODE_LANG1;
con = 0x080000; t->rxsubchans = V4L2_TUNER_SUB_MONO |
if (t->audmode & V4L2_TUNER_MODE_STEREO) V4L2_TUNER_SUB_STEREO |
con = 0x180000; V4L2_TUNER_SUB_LANG1 |
gpio_bits(0x180000, con); V4L2_TUNER_SUB_LANG2;
if (bttv_gpio)
bttv_gpio_tracking(btv,"terratv"); return;
} else { }
t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; gpio_inout(0x180000, 0x180000);
switch (t->audmode) {
case V4L2_TUNER_MODE_LANG2:
con = 0x080000;
break;
case V4L2_TUNER_MODE_STEREO:
con = 0x180000;
break;
default:
con = 0;
break;
} }
gpio_bits(0x180000, con);
if (bttv_gpio)
bttv_gpio_tracking(btv, "terratv");
} }
void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set) void winfast2000_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
{ {
unsigned long val = 0; unsigned long val;
if (set) { if (!set) {
/*btor (0xc32000, BT848_GPIO_OUT_EN);*/ /* Not much to do here */
if (t->audmode & V4L2_TUNER_MODE_MONO) /* Mono */ t->audmode = V4L2_TUNER_MODE_LANG1;
val = 0x420000; t->rxsubchans = V4L2_TUNER_SUB_MONO |
if (t->audmode & V4L2_TUNER_MODE_LANG1) /* Mono */ V4L2_TUNER_SUB_STEREO |
val = 0x420000; V4L2_TUNER_SUB_LANG1 |
if (t->audmode & V4L2_TUNER_MODE_LANG2) /* SAP */ V4L2_TUNER_SUB_LANG2;
val = 0x410000;
if (t->audmode & V4L2_TUNER_MODE_STEREO) /* Stereo */ return;
val = 0x020000;
if (val) {
gpio_bits(0x430000, val);
if (bttv_gpio)
bttv_gpio_tracking(btv,"winfast2000");
}
} else {
t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
} }
/*btor (0xc32000, BT848_GPIO_OUT_EN);*/
switch (t->audmode) {
case V4L2_TUNER_MODE_MONO:
case V4L2_TUNER_MODE_LANG1:
val = 0x420000;
break;
case V4L2_TUNER_MODE_LANG2: /* SAP */
val = 0x410000;
break;
case V4L2_TUNER_MODE_STEREO:
val = 0x020000;
break;
default:
return;
}
gpio_bits(0x430000, val);
if (bttv_gpio)
bttv_gpio_tracking(btv, "winfast2000");
} }
/* /*
...@@ -272,23 +340,33 @@ void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set) ...@@ -272,23 +340,33 @@ void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
if (btv->radio_user) if (btv->radio_user)
return; return;
if (set) { if (!set) {
if (t->audmode & V4L2_TUNER_MODE_MONO) { /* Not much to do here */
val = 0x01; t->audmode = V4L2_TUNER_MODE_LANG1;
} t->rxsubchans = V4L2_TUNER_SUB_MONO |
if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2)) V4L2_TUNER_SUB_STEREO |
|| (t->audmode & V4L2_TUNER_MODE_STEREO)) { V4L2_TUNER_SUB_LANG1 |
val = 0x02; V4L2_TUNER_SUB_LANG2;
}
if (val) { return;
gpio_bits(0x03,val);
if (bttv_gpio)
bttv_gpio_tracking(btv,"pvbt878p9b");
}
} else {
t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
} }
switch (t->audmode) {
case V4L2_TUNER_MODE_MONO:
val = 0x01;
break;
case V4L2_TUNER_MODE_LANG1:
case V4L2_TUNER_MODE_LANG2:
case V4L2_TUNER_MODE_STEREO:
val = 0x02;
break;
default:
return;
}
gpio_bits(0x03, val);
if (bttv_gpio)
bttv_gpio_tracking(btv, "pvbt878p9b");
} }
/* /*
...@@ -298,28 +376,37 @@ void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set) ...@@ -298,28 +376,37 @@ void pvbt878p9b_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
*/ */
void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set) void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
{ {
unsigned int val = 0xffff; unsigned int val;
if (btv->radio_user) if (btv->radio_user)
return; return;
if (set) { if (!set) {
if (t->audmode & V4L2_TUNER_MODE_MONO) { /* Not much to do here */
val = 0x0000; t->audmode = V4L2_TUNER_MODE_LANG1;
} t->rxsubchans = V4L2_TUNER_SUB_MONO |
if ((t->audmode & (V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2)) V4L2_TUNER_SUB_STEREO |
|| (t->audmode & V4L2_TUNER_MODE_STEREO)) { V4L2_TUNER_SUB_LANG1 |
val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */ V4L2_TUNER_SUB_LANG2;
}
if (val != 0xffff) { return;
gpio_bits(0x1800, val);
if (bttv_gpio)
bttv_gpio_tracking(btv,"fv2000s");
}
} else {
t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
} }
switch (t->audmode) {
case V4L2_TUNER_MODE_MONO:
val = 0x0000;
break;
case V4L2_TUNER_MODE_LANG1:
case V4L2_TUNER_MODE_LANG2:
case V4L2_TUNER_MODE_STEREO:
val = 0x1080; /*-dk-???: 0x0880, 0x0080, 0x1800 ... */
break;
default:
return;
}
gpio_bits(0x1800, val);
if (bttv_gpio)
bttv_gpio_tracking(btv, "fv2000s");
} }
/* /*
...@@ -328,26 +415,33 @@ void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set) ...@@ -328,26 +415,33 @@ void fv2000s_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
*/ */
void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set) void windvr_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
{ {
unsigned long val = 0; unsigned long val;
if (set) { if (!set) {
if (t->audmode & V4L2_TUNER_MODE_MONO) /* Not much to do here */
val = 0x040000; t->audmode = V4L2_TUNER_MODE_LANG1;
if (t->audmode & V4L2_TUNER_MODE_LANG1) t->rxsubchans = V4L2_TUNER_SUB_MONO |
val = 0; V4L2_TUNER_SUB_STEREO |
if (t->audmode & V4L2_TUNER_MODE_LANG2) V4L2_TUNER_SUB_LANG1 |
val = 0x100000; V4L2_TUNER_SUB_LANG2;
if (t->audmode & V4L2_TUNER_MODE_STEREO)
val = 0; return;
if (val) { }
gpio_bits(0x140000, val);
if (bttv_gpio) switch (t->audmode) {
bttv_gpio_tracking(btv,"windvr"); case V4L2_TUNER_MODE_MONO:
} val = 0x040000;
} else { break;
t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO | case V4L2_TUNER_MODE_LANG2:
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; val = 0x100000;
break;
default:
return;
} }
gpio_bits(0x140000, val);
if (bttv_gpio)
bttv_gpio_tracking(btv, "windvr");
} }
/* /*
...@@ -360,23 +454,36 @@ void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *t, int set) ...@@ -360,23 +454,36 @@ void adtvk503_audio(struct bttv *btv, struct v4l2_tuner *t, int set)
/* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */ /* btaor(0x1e0000, ~0x1e0000, BT848_GPIO_OUT_EN); */
if (set) { if (!set) {
/* btor(***, BT848_GPIO_OUT_EN); */ /* Not much to do here */
if (t->audmode & V4L2_TUNER_MODE_LANG1) t->audmode = V4L2_TUNER_MODE_LANG1;
con = 0x00000000; t->rxsubchans = V4L2_TUNER_SUB_MONO |
if (t->audmode & V4L2_TUNER_MODE_LANG2) V4L2_TUNER_SUB_STEREO |
con = 0x00180000; V4L2_TUNER_SUB_LANG1 |
if (t->audmode & V4L2_TUNER_MODE_STEREO) V4L2_TUNER_SUB_LANG2;
con = 0x00000000;
if (t->audmode & V4L2_TUNER_MODE_MONO) return;
con = 0x00060000;
if (con != 0xffffff) {
gpio_bits(0x1e0000,con);
if (bttv_gpio)
bttv_gpio_tracking(btv, "adtvk503");
}
} else {
t->audmode = V4L2_TUNER_MODE_MONO | V4L2_TUNER_MODE_STEREO |
V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2;
} }
/* btor(***, BT848_GPIO_OUT_EN); */
switch (t->audmode) {
case V4L2_TUNER_MODE_LANG1:
con = 0x00000000;
break;
case V4L2_TUNER_MODE_LANG2:
con = 0x00180000;
break;
case V4L2_TUNER_MODE_STEREO:
con = 0x00000000;
break;
case V4L2_TUNER_MODE_MONO:
con = 0x00060000;
break;
default:
return;
}
gpio_bits(0x1e0000, con);
if (bttv_gpio)
bttv_gpio_tracking(btv, "adtvk503");
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment