aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/pci
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2013-02-10 07:24:14 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2013-03-05 12:24:58 -0500
commitb8e2a361ce4247118fe81224b43137821cda50f7 (patch)
treeb7391eff8a9ec1fbefeb5b8262971264cd06f71a /drivers/media/pci
parentc13eb7039f612cc666764d6685a3764f4e6c8821 (diff)
[media] bttv: do not switch to the radio tuner unless it is accessed
Just opening the radio tuner should not cause a switch to the radio tuner. Only after calling g/s_tuner or g/s_frequency should this happen. This prevents audio being unmuted as soon as the driver is loaded because some process opens /dev/radioX just to see what sort of node it is, which switches on the radio tuner and unmutes audio. This code can be improved further by actually keeping track of who owns the tuner and returning -EBUSY if switching tuner modes will cause problems. But for now just fix the annoying case where on boot the radio turns on automatically. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/pci')
-rw-r--r--drivers/media/pci/bt8xx/bttv-driver.c23
-rw-r--r--drivers/media/pci/bt8xx/bttvp.h1
2 files changed, 21 insertions, 3 deletions
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index b5100da854c0..265263a47a13 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -1004,7 +1004,7 @@ audio_mux(struct bttv *btv, int input, int mute)
1004 1004
1005 /* automute */ 1005 /* automute */
1006 mute = mute || (btv->opt_automute && (!signal || !btv->users) 1006 mute = mute || (btv->opt_automute && (!signal || !btv->users)
1007 && !btv->radio_user); 1007 && !btv->has_radio_tuner);
1008 1008
1009 if (mute) 1009 if (mute)
1010 gpio_val = bttv_tvcards[btv->c.type].gpiomute; 1010 gpio_val = bttv_tvcards[btv->c.type].gpiomute;
@@ -1701,6 +1701,16 @@ static struct videobuf_queue_ops bttv_video_qops = {
1701 .buf_release = buffer_release, 1701 .buf_release = buffer_release,
1702}; 1702};
1703 1703
1704static void radio_enable(struct bttv *btv)
1705{
1706 /* Switch to the radio tuner */
1707 if (!btv->has_radio_tuner) {
1708 btv->has_radio_tuner = 1;
1709 bttv_call_all(btv, tuner, s_radio);
1710 audio_input(btv, TVAUDIO_INPUT_RADIO);
1711 }
1712}
1713
1704static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id) 1714static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id)
1705{ 1715{
1706 struct bttv_fh *fh = priv; 1716 struct bttv_fh *fh = priv;
@@ -1832,6 +1842,8 @@ static int bttv_g_frequency(struct file *file, void *priv,
1832 if (f->tuner) 1842 if (f->tuner)
1833 return -EINVAL; 1843 return -EINVAL;
1834 1844
1845 if (f->type == V4L2_TUNER_RADIO)
1846 radio_enable(btv);
1835 f->frequency = f->type == V4L2_TUNER_RADIO ? 1847 f->frequency = f->type == V4L2_TUNER_RADIO ?
1836 btv->radio_freq : btv->tv_freq; 1848 btv->radio_freq : btv->tv_freq;
1837 1849
@@ -1845,6 +1857,7 @@ static void bttv_set_frequency(struct bttv *btv, struct v4l2_frequency *f)
1845 frequency before assigning radio/tv_freq. */ 1857 frequency before assigning radio/tv_freq. */
1846 bttv_call_all(btv, tuner, g_frequency, f); 1858 bttv_call_all(btv, tuner, g_frequency, f);
1847 if (f->type == V4L2_TUNER_RADIO) { 1859 if (f->type == V4L2_TUNER_RADIO) {
1860 radio_enable(btv);
1848 btv->radio_freq = f->frequency; 1861 btv->radio_freq = f->frequency;
1849 if (btv->has_matchbox) 1862 if (btv->has_matchbox)
1850 tea5757_set_freq(btv, btv->radio_freq); 1863 tea5757_set_freq(btv, btv->radio_freq);
@@ -3235,8 +3248,6 @@ static int radio_open(struct file *file)
3235 3248
3236 btv->radio_user++; 3249 btv->radio_user++;
3237 3250
3238 bttv_call_all(btv, tuner, s_radio);
3239 audio_input(btv,TVAUDIO_INPUT_RADIO);
3240 v4l2_fh_add(&fh->fh); 3251 v4l2_fh_add(&fh->fh);
3241 3252
3242 return 0; 3253 return 0;
@@ -3257,6 +3268,8 @@ static int radio_release(struct file *file)
3257 3268
3258 bttv_call_all(btv, core, ioctl, SAA6588_CMD_CLOSE, &cmd); 3269 bttv_call_all(btv, core, ioctl, SAA6588_CMD_CLOSE, &cmd);
3259 3270
3271 if (btv->radio_user == 0)
3272 btv->has_radio_tuner = 0;
3260 return 0; 3273 return 0;
3261} 3274}
3262 3275
@@ -3269,6 +3282,7 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
3269 return -EINVAL; 3282 return -EINVAL;
3270 strcpy(t->name, "Radio"); 3283 strcpy(t->name, "Radio");
3271 t->type = V4L2_TUNER_RADIO; 3284 t->type = V4L2_TUNER_RADIO;
3285 radio_enable(btv);
3272 3286
3273 bttv_call_all(btv, tuner, g_tuner, t); 3287 bttv_call_all(btv, tuner, g_tuner, t);
3274 3288
@@ -3287,6 +3301,7 @@ static int radio_s_tuner(struct file *file, void *priv,
3287 if (0 != t->index) 3301 if (0 != t->index)
3288 return -EINVAL; 3302 return -EINVAL;
3289 3303
3304 radio_enable(btv);
3290 bttv_call_all(btv, tuner, s_tuner, t); 3305 bttv_call_all(btv, tuner, s_tuner, t);
3291 return 0; 3306 return 0;
3292} 3307}
@@ -3301,6 +3316,7 @@ static ssize_t radio_read(struct file *file, char __user *data,
3301 cmd.buffer = data; 3316 cmd.buffer = data;
3302 cmd.instance = file; 3317 cmd.instance = file;
3303 cmd.result = -ENODEV; 3318 cmd.result = -ENODEV;
3319 radio_enable(btv);
3304 3320
3305 bttv_call_all(btv, core, ioctl, SAA6588_CMD_READ, &cmd); 3321 bttv_call_all(btv, core, ioctl, SAA6588_CMD_READ, &cmd);
3306 3322
@@ -3319,6 +3335,7 @@ static unsigned int radio_poll(struct file *file, poll_table *wait)
3319 res = POLLPRI; 3335 res = POLLPRI;
3320 else if (req_events & POLLPRI) 3336 else if (req_events & POLLPRI)
3321 poll_wait(file, &fh->fh.wait, wait); 3337 poll_wait(file, &fh->fh.wait, wait);
3338 radio_enable(btv);
3322 cmd.instance = file; 3339 cmd.instance = file;
3323 cmd.event_list = wait; 3340 cmd.event_list = wait;
3324 cmd.result = res; 3341 cmd.result = res;
diff --git a/drivers/media/pci/bt8xx/bttvp.h b/drivers/media/pci/bt8xx/bttvp.h
index 86d67bb5adec..eb13be7ae3f4 100644
--- a/drivers/media/pci/bt8xx/bttvp.h
+++ b/drivers/media/pci/bt8xx/bttvp.h
@@ -437,6 +437,7 @@ struct bttv {
437 437
438 /* radio data/state */ 438 /* radio data/state */
439 int has_radio; 439 int has_radio;
440 int has_radio_tuner;
440 int radio_user; 441 int radio_user;
441 int radio_uses_msp_demodulator; 442 int radio_uses_msp_demodulator;
442 unsigned long radio_freq; 443 unsigned long radio_freq;