diff options
Diffstat (limited to 'drivers/media/video/bt8xx')
-rw-r--r-- | drivers/media/video/bt8xx/bttv-cards.c | 22 | ||||
-rw-r--r-- | drivers/media/video/bt8xx/bttv-driver.c | 273 | ||||
-rw-r--r-- | drivers/media/video/bt8xx/bttv-i2c.c | 43 | ||||
-rw-r--r-- | drivers/media/video/bt8xx/bttv-input.c | 84 | ||||
-rw-r--r-- | drivers/media/video/bt8xx/bttv-risc.c | 2 | ||||
-rw-r--r-- | drivers/media/video/bt8xx/bttv.h | 1 | ||||
-rw-r--r-- | drivers/media/video/bt8xx/bttvp.h | 13 |
7 files changed, 279 insertions, 159 deletions
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c index 7af56cde0c7..87d8b006ef7 100644 --- a/drivers/media/video/bt8xx/bttv-cards.c +++ b/drivers/media/video/bt8xx/bttv-cards.c @@ -3529,7 +3529,7 @@ void __devinit bttv_init_card2(struct bttv *btv) struct v4l2_subdev *sd; sd = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "saa6588", "saa6588", 0, addrs); + &btv->c.i2c_adap, NULL, "saa6588", 0, addrs); btv->has_saa6588 = (sd != NULL); } @@ -3554,7 +3554,7 @@ void __devinit bttv_init_card2(struct bttv *btv) }; btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "msp3400", "msp3400", 0, addrs); + &btv->c.i2c_adap, NULL, "msp3400", 0, addrs); if (btv->sd_msp34xx) return; goto no_audio; @@ -3568,7 +3568,7 @@ void __devinit bttv_init_card2(struct bttv *btv) }; if (v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "tda7432", "tda7432", 0, addrs)) + &btv->c.i2c_adap, NULL, "tda7432", 0, addrs)) return; goto no_audio; } @@ -3576,7 +3576,7 @@ void __devinit bttv_init_card2(struct bttv *btv) case 3: { /* The user specified that we should probe for tvaudio */ btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "tvaudio", "tvaudio", 0, tvaudio_addrs()); + &btv->c.i2c_adap, NULL, "tvaudio", 0, tvaudio_addrs()); if (btv->sd_tvaudio) return; goto no_audio; @@ -3596,11 +3596,11 @@ void __devinit bttv_init_card2(struct bttv *btv) found is really something else (e.g. a tea6300). */ if (!bttv_tvcards[btv->c.type].no_msp34xx) { btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "msp3400", "msp3400", + &btv->c.i2c_adap, NULL, "msp3400", 0, I2C_ADDRS(I2C_ADDR_MSP3400 >> 1)); } else if (bttv_tvcards[btv->c.type].msp34xx_alt) { btv->sd_msp34xx = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "msp3400", "msp3400", + &btv->c.i2c_adap, NULL, "msp3400", 0, I2C_ADDRS(I2C_ADDR_MSP3400_ALT >> 1)); } @@ -3616,13 +3616,13 @@ void __devinit bttv_init_card2(struct bttv *btv) }; if (v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "tda7432", "tda7432", 0, addrs)) + &btv->c.i2c_adap, NULL, "tda7432", 0, addrs)) return; } /* Now see if we can find one of the tvaudio devices. */ btv->sd_tvaudio = v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "tvaudio", "tvaudio", 0, tvaudio_addrs()); + &btv->c.i2c_adap, NULL, "tvaudio", 0, tvaudio_addrs()); if (btv->sd_tvaudio) return; @@ -3646,13 +3646,13 @@ void __devinit bttv_init_tuner(struct bttv *btv) /* Load tuner module before issuing tuner config call! */ if (bttv_tvcards[btv->c.type].has_radio) v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "tuner", "tuner", + &btv->c.i2c_adap, NULL, "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_RADIO)); v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "tuner", "tuner", + &btv->c.i2c_adap, NULL, "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_DEMOD)); v4l2_i2c_new_subdev(&btv->c.v4l2_dev, - &btv->c.i2c_adap, "tuner", "tuner", + &btv->c.i2c_adap, NULL, "tuner", 0, v4l2_i2c_tuner_addrs(ADDRS_TV_WITH_DEMOD)); tun_setup.mode_mask = T_ANALOG_TV | T_DIGITAL_TV; diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c index 38c7f78ad9c..3da6e80e104 100644 --- a/drivers/media/video/bt8xx/bttv-driver.c +++ b/drivers/media/video/bt8xx/bttv-driver.c @@ -842,7 +842,7 @@ static const struct v4l2_queryctrl *ctrl_by_id(int id) RESOURCE_OVERLAY) static -int check_alloc_btres(struct bttv *btv, struct bttv_fh *fh, int bit) +int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit) { int xbits; /* mutual exclusive resources */ @@ -935,7 +935,7 @@ disclaim_video_lines(struct bttv *btv) } static -void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits) +void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits) { if ((fh->resources & bits) != bits) { /* trying to free ressources not allocated by us ... */ @@ -1682,7 +1682,7 @@ bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh, kfree(old); } if (NULL == new) - free_btres(btv,fh,RESOURCE_OVERLAY); + free_btres_lock(btv,fh,RESOURCE_OVERLAY); dprintk("switch_overlay: done\n"); return retval; } @@ -1859,21 +1859,25 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id) unsigned int i; int err; + mutex_lock(&btv->lock); err = v4l2_prio_check(&btv->prio, fh->prio); - if (0 != err) - return err; + if (err) + goto err; for (i = 0; i < BTTV_TVNORMS; i++) if (*id & bttv_tvnorms[i].v4l2_id) break; - if (i == BTTV_TVNORMS) - return -EINVAL; + if (i == BTTV_TVNORMS) { + err = -EINVAL; + goto err; + } - mutex_lock(&btv->lock); set_tvnorm(btv, i); + +err: mutex_unlock(&btv->lock); - return 0; + return err; } static int bttv_querystd(struct file *file, void *f, v4l2_std_id *id) @@ -1893,10 +1897,13 @@ static int bttv_enum_input(struct file *file, void *priv, { struct bttv_fh *fh = priv; struct bttv *btv = fh->btv; - int n; + int rc = 0; - if (i->index >= bttv_tvcards[btv->c.type].video_inputs) - return -EINVAL; + mutex_lock(&btv->lock); + if (i->index >= bttv_tvcards[btv->c.type].video_inputs) { + rc = -EINVAL; + goto err; + } i->type = V4L2_INPUT_TYPE_CAMERA; i->audioset = 1; @@ -1919,10 +1926,12 @@ static int bttv_enum_input(struct file *file, void *priv, i->status |= V4L2_IN_ST_NO_H_LOCK; } - for (n = 0; n < BTTV_TVNORMS; n++) - i->std |= bttv_tvnorms[n].v4l2_id; + i->std = BTTV_NORMS; - return 0; +err: + mutex_unlock(&btv->lock); + + return rc; } static int bttv_g_input(struct file *file, void *priv, unsigned int *i) @@ -1930,7 +1939,10 @@ static int bttv_g_input(struct file *file, void *priv, unsigned int *i) struct bttv_fh *fh = priv; struct bttv *btv = fh->btv; + mutex_lock(&btv->lock); *i = btv->input; + mutex_unlock(&btv->lock); + return 0; } @@ -1941,15 +1953,19 @@ static int bttv_s_input(struct file *file, void *priv, unsigned int i) int err; + mutex_lock(&btv->lock); err = v4l2_prio_check(&btv->prio, fh->prio); - if (0 != err) - return err; + if (unlikely(err)) + goto err; - if (i > bttv_tvcards[btv->c.type].video_inputs) - return -EINVAL; + if (i > bttv_tvcards[btv->c.type].video_inputs) { + err = -EINVAL; + goto err; + } - mutex_lock(&btv->lock); set_input(btv, i, btv->tvnorm); + +err: mutex_unlock(&btv->lock); return 0; } @@ -1961,22 +1977,25 @@ static int bttv_s_tuner(struct file *file, void *priv, struct bttv *btv = fh->btv; int err; - err = v4l2_prio_check(&btv->prio, fh->prio); - if (0 != err) - return err; - - if (btv->tuner_type == TUNER_ABSENT) - return -EINVAL; - - if (0 != t->index) + if (unlikely(0 != t->index)) return -EINVAL; mutex_lock(&btv->lock); + if (unlikely(btv->tuner_type == TUNER_ABSENT)) { + err = -EINVAL; + goto err; + } + + err = v4l2_prio_check(&btv->prio, fh->prio); + if (unlikely(err)) + goto err; + bttv_call_all(btv, tuner, s_tuner, t); if (btv->audio_mode_gpio) btv->audio_mode_gpio(btv, t, 1); +err: mutex_unlock(&btv->lock); return 0; @@ -1988,8 +2007,10 @@ static int bttv_g_frequency(struct file *file, void *priv, struct bttv_fh *fh = priv; struct bttv *btv = fh->btv; + mutex_lock(&btv->lock); f->type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; f->frequency = btv->freq; + mutex_unlock(&btv->lock); return 0; } @@ -2001,21 +2022,26 @@ static int bttv_s_frequency(struct file *file, void *priv, struct bttv *btv = fh->btv; int err; - err = v4l2_prio_check(&btv->prio, fh->prio); - if (0 != err) - return err; - if (unlikely(f->tuner != 0)) return -EINVAL; - if (unlikely(f->type != (btv->radio_user - ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV))) - return -EINVAL; + mutex_lock(&btv->lock); + err = v4l2_prio_check(&btv->prio, fh->prio); + if (unlikely(err)) + goto err; + + if (unlikely(f->type != (btv->radio_user + ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV))) { + err = -EINVAL; + goto err; + } btv->freq = f->frequency; bttv_call_all(btv, tuner, s_frequency, f); if (btv->has_matchbox && btv->radio_user) tea5757_set_freq(btv, btv->freq); +err: mutex_unlock(&btv->lock); + return 0; } @@ -2124,7 +2150,7 @@ bttv_crop_adjust (struct bttv_crop * c, also adjust the current cropping parameters to get closer to the desired image size. */ static int -limit_scaled_size (struct bttv_fh * fh, +limit_scaled_size_lock (struct bttv_fh * fh, __s32 * width, __s32 * height, enum v4l2_field field, @@ -2238,7 +2264,7 @@ limit_scaled_size (struct bttv_fh * fh, may also adjust the current cropping parameters to get closer to the desired window size. */ static int -verify_window (struct bttv_fh * fh, +verify_window_lock (struct bttv_fh * fh, struct v4l2_window * win, int adjust_size, int adjust_crop) @@ -2257,7 +2283,9 @@ verify_window (struct bttv_fh * fh, if (V4L2_FIELD_ANY == field) { __s32 height2; + mutex_lock(&fh->btv->lock); height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1; + mutex_unlock(&fh->btv->lock); field = (win->w.height > height2) ? V4L2_FIELD_INTERLACED : V4L2_FIELD_TOP; @@ -2292,7 +2320,7 @@ verify_window (struct bttv_fh * fh, win->w.width -= win->w.left & ~width_mask; win->w.left = (win->w.left - width_mask - 1) & width_mask; - rc = limit_scaled_size(fh, &win->w.width, &win->w.height, + rc = limit_scaled_size_lock(fh, &win->w.width, &win->w.height, field, width_mask, /* width_bias: round down */ 0, adjust_size, adjust_crop); @@ -2303,7 +2331,7 @@ verify_window (struct bttv_fh * fh, return 0; } -static int setup_window(struct bttv_fh *fh, struct bttv *btv, +static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv, struct v4l2_window *win, int fixup) { struct v4l2_clip *clips = NULL; @@ -2313,7 +2341,7 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv, return -EINVAL; if (!(fh->ovfmt->flags & FORMAT_FLAGS_PACKED)) return -EINVAL; - retval = verify_window(fh, win, + retval = verify_window_lock(fh, win, /* adjust_size */ fixup, /* adjust_crop */ fixup); if (0 != retval) @@ -2332,6 +2360,8 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv, return -EFAULT; } } + + mutex_lock(&fh->cap.vb_lock); /* clip against screen */ if (NULL != btv->fbuf.base) n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height, @@ -2354,7 +2384,6 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv, BUG(); } - mutex_lock(&fh->cap.vb_lock); kfree(fh->ov.clips); fh->ov.clips = clips; fh->ov.nclips = n; @@ -2362,6 +2391,14 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv, fh->ov.w = win->w; fh->ov.field = win->field; fh->ov.setup_ok = 1; + + /* + * FIXME: btv is protected by btv->lock mutex, while btv->init + * is protected by fh->cap.vb_lock. This seems to open the + * possibility for some race situations. Maybe the better would + * be to unify those locks or to use another way to store the + * init values that will be consumed by videobuf callbacks + */ btv->init.ov.w.width = win->w.width; btv->init.ov.w.height = win->w.height; btv->init.ov.field = win->field; @@ -2490,7 +2527,9 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv, if (V4L2_FIELD_ANY == field) { __s32 height2; + mutex_lock(&btv->lock); height2 = btv->crop[!!fh->do_crop].rect.height >> 1; + mutex_unlock(&btv->lock); field = (f->fmt.pix.height > height2) ? V4L2_FIELD_INTERLACED : V4L2_FIELD_BOTTOM; @@ -2516,7 +2555,7 @@ static int bttv_try_fmt_vid_cap(struct file *file, void *priv, width = f->fmt.pix.width; height = f->fmt.pix.height; - rc = limit_scaled_size(fh, &width, &height, field, + rc = limit_scaled_size_lock(fh, &width, &height, field, /* width_mask: 4 pixels */ ~3, /* width_bias: nearest */ 2, /* adjust_size */ 1, @@ -2536,7 +2575,7 @@ static int bttv_try_fmt_vid_overlay(struct file *file, void *priv, { struct bttv_fh *fh = priv; - return verify_window(fh, &f->fmt.win, + return verify_window_lock(fh, &f->fmt.win, /* adjust_size */ 1, /* adjust_crop */ 0); } @@ -2563,7 +2602,7 @@ static int bttv_s_fmt_vid_cap(struct file *file, void *priv, height = f->fmt.pix.height; field = f->fmt.pix.field; - retval = limit_scaled_size(fh, &width, &height, f->fmt.pix.field, + retval = limit_scaled_size_lock(fh, &width, &height, f->fmt.pix.field, /* width_mask: 4 pixels */ ~3, /* width_bias: nearest */ 2, /* adjust_size */ 1, @@ -2601,7 +2640,7 @@ static int bttv_s_fmt_vid_overlay(struct file *file, void *priv, return -EINVAL; } - return setup_window(fh, btv, &f->fmt.win, 1); + return setup_window_lock(fh, btv, &f->fmt.win, 1); } #ifdef CONFIG_VIDEO_V4L1_COMPAT @@ -2651,11 +2690,15 @@ static int bttv_querycap(struct file *file, void *priv, V4L2_CAP_VBI_CAPTURE | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; - if (btv->has_saa6588) - cap->capabilities |= V4L2_CAP_RDS_CAPTURE; if (no_overlay <= 0) cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; + /* + * No need to lock here: those vars are initialized during board + * probe and remains untouched during the rest of the driver lifecycle + */ + if (btv->has_saa6588) + cap->capabilities |= V4L2_CAP_RDS_CAPTURE; if (btv->tuner_type != TUNER_ABSENT) cap->capabilities |= V4L2_CAP_TUNER; return 0; @@ -2730,19 +2773,25 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on) struct bttv_fh *fh = f; struct bttv *btv = fh->btv; struct bttv_buffer *new; - int retval; + int retval = 0; if (on) { + mutex_lock(&fh->cap.vb_lock); /* verify args */ - if (NULL == btv->fbuf.base) + if (unlikely(!btv->fbuf.base)) { + mutex_unlock(&fh->cap.vb_lock); return -EINVAL; - if (!fh->ov.setup_ok) { + } + if (unlikely(!fh->ov.setup_ok)) { dprintk("bttv%d: overlay: !setup_ok\n", btv->c.nr); - return -EINVAL; + retval = -EINVAL; } + if (retval) + return retval; + mutex_unlock(&fh->cap.vb_lock); } - if (!check_alloc_btres(btv, fh, RESOURCE_OVERLAY)) + if (!check_alloc_btres_lock(btv, fh, RESOURCE_OVERLAY)) return -EBUSY; mutex_lock(&fh->cap.vb_lock); @@ -2785,7 +2834,7 @@ static int bttv_s_fbuf(struct file *file, void *f, __s32 width = fb->fmt.width; __s32 height = fb->fmt.height; - retval = limit_scaled_size(fh, &width, &height, + retval = limit_scaled_size_lock(fh, &width, &height, V4L2_FIELD_INTERLACED, /* width_mask */ ~3, /* width_bias */ 2, @@ -2852,7 +2901,7 @@ static int bttv_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) struct bttv *btv = fh->btv; int res = bttv_resource(fh); - if (!check_alloc_btres(btv, fh, res)) + if (!check_alloc_btres_lock(btv, fh, res)) return -EBUSY; return videobuf_qbuf(bttv_queue(fh), b); @@ -2872,7 +2921,7 @@ static int bttv_streamon(struct file *file, void *priv, struct bttv *btv = fh->btv; int res = bttv_resource(fh); - if (!check_alloc_btres(btv, fh, res)) + if (!check_alloc_btres_lock(btv, fh, res)) return -EBUSY; return videobuf_streamon(bttv_queue(fh)); } @@ -2890,7 +2939,7 @@ static int bttv_streamoff(struct file *file, void *priv, retval = videobuf_streamoff(bttv_queue(fh)); if (retval < 0) return retval; - free_btres(btv, fh, res); + free_btres_lock(btv, fh, res); return 0; } @@ -2907,6 +2956,7 @@ static int bttv_queryctrl(struct file *file, void *priv, c->id >= V4L2_CID_PRIVATE_LASTP1)) return -EINVAL; + mutex_lock(&btv->lock); if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME)) *c = no_ctl; else { @@ -2914,6 +2964,7 @@ static int bttv_queryctrl(struct file *file, void *priv, *c = (NULL != ctrl) ? *ctrl : no_ctl; } + mutex_unlock(&btv->lock); return 0; } @@ -2924,8 +2975,11 @@ static int bttv_g_parm(struct file *file, void *f, struct bttv_fh *fh = f; struct bttv *btv = fh->btv; + mutex_lock(&btv->lock); v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id, &parm->parm.capture.timeperframe); + mutex_unlock(&btv->lock); + return 0; } @@ -2961,7 +3015,9 @@ static int bttv_g_priority(struct file *file, void *f, enum v4l2_priority *p) struct bttv_fh *fh = f; struct bttv *btv = fh->btv; + mutex_lock(&btv->lock); *p = v4l2_prio_max(&btv->prio); + mutex_unlock(&btv->lock); return 0; } @@ -2971,8 +3027,13 @@ static int bttv_s_priority(struct file *file, void *f, { struct bttv_fh *fh = f; struct bttv *btv = fh->btv; + int rc; - return v4l2_prio_change(&btv->prio, &fh->prio, prio); + mutex_lock(&btv->lock); + rc = v4l2_prio_change(&btv->prio, &fh->prio, prio); + mutex_unlock(&btv->lock); + + return rc; } static int bttv_cropcap(struct file *file, void *priv, @@ -2985,7 +3046,9 @@ static int bttv_cropcap(struct file *file, void *priv, cap->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) return -EINVAL; + mutex_lock(&btv->lock); *cap = bttv_tvnorms[btv->tvnorm].cropcap; + mutex_unlock(&btv->lock); return 0; } @@ -3003,7 +3066,9 @@ static int bttv_g_crop(struct file *file, void *f, struct v4l2_crop *crop) inconsistent with fh->width or fh->height and apps do not expect a change here. */ + mutex_lock(&btv->lock); crop->c = btv->crop[!!fh->do_crop].rect; + mutex_unlock(&btv->lock); return 0; } @@ -3024,14 +3089,15 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop) crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) return -EINVAL; - retval = v4l2_prio_check(&btv->prio, fh->prio); - if (0 != retval) - return retval; - /* Make sure tvnorm, vbi_end and the current cropping parameters remain consistent until we're done. Note - read() may change vbi_end in check_alloc_btres(). */ + read() may change vbi_end in check_alloc_btres_lock(). */ mutex_lock(&btv->lock); + retval = v4l2_prio_check(&btv->prio, fh->prio); + if (0 != retval) { + mutex_unlock(&btv->lock); + return retval; + } retval = -EBUSY; @@ -3128,17 +3194,17 @@ static ssize_t bttv_read(struct file *file, char __user *data, switch (fh->type) { case V4L2_BUF_TYPE_VIDEO_CAPTURE: - if (!check_alloc_btres(fh->btv, fh, RESOURCE_VIDEO_READ)) { + if (!check_alloc_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ)) { /* VIDEO_READ in use by another fh, or VIDEO_STREAM by any fh. */ return -EBUSY; } retval = videobuf_read_one(&fh->cap, data, count, ppos, file->f_flags & O_NONBLOCK); - free_btres(fh->btv, fh, RESOURCE_VIDEO_READ); + free_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ); break; case V4L2_BUF_TYPE_VBI_CAPTURE: - if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI)) + if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) return -EBUSY; retval = videobuf_read_stream(&fh->vbi, data, count, ppos, 1, file->f_flags & O_NONBLOCK); @@ -3157,20 +3223,19 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait) unsigned int rc = POLLERR; if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { - if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI)) + if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) return POLLERR; return videobuf_poll_stream(file, &fh->vbi, wait); } + mutex_lock(&fh->cap.vb_lock); if (check_btres(fh,RESOURCE_VIDEO_STREAM)) { - mutex_lock(&fh->cap.vb_lock); /* streaming capture */ if (list_empty(&fh->cap.stream)) goto err; buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream); } else { /* read() capture */ - mutex_lock(&fh->cap.vb_lock); if (NULL == fh->cap.read_buf) { /* need to capture a new frame */ if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM)) @@ -3188,7 +3253,6 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait) fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); fh->cap.read_off = 0; } - mutex_unlock(&fh->cap.vb_lock); buf = (struct bttv_buffer*)fh->cap.read_buf; } @@ -3221,21 +3285,32 @@ static int bttv_open(struct file *file) return -ENODEV; } - lock_kernel(); - dprintk(KERN_DEBUG "bttv%d: open called (type=%s)\n", btv->c.nr,v4l2_type_names[type]); /* allocate per filehandle data */ - fh = kmalloc(sizeof(*fh),GFP_KERNEL); - if (NULL == fh) { - unlock_kernel(); + fh = kmalloc(sizeof(*fh), GFP_KERNEL); + if (unlikely(!fh)) return -ENOMEM; - } file->private_data = fh; + + /* + * btv is protected by btv->lock mutex, while btv->init and other + * streaming vars are protected by fh->cap.vb_lock. We need to take + * care of both locks to avoid troubles. However, vb_lock is used also + * inside videobuf, without calling buf->lock. So, it is a very bad + * idea to hold both locks at the same time. + * Let's first copy btv->init at fh, holding cap.vb_lock, and then work + * with the rest of init, holding btv->lock. + */ + mutex_lock(&fh->cap.vb_lock); *fh = btv->init; + mutex_unlock(&fh->cap.vb_lock); + fh->type = type; fh->ov.setup_ok = 0; + + mutex_lock(&btv->lock); v4l2_prio_open(&btv->prio, &fh->prio); videobuf_queue_sg_init(&fh->cap, &bttv_video_qops, @@ -3243,13 +3318,13 @@ static int bttv_open(struct file *file) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, sizeof(struct bttv_buffer), - fh); + fh, NULL); videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops, &btv->c.pci->dev, &btv->s_lock, V4L2_BUF_TYPE_VBI_CAPTURE, V4L2_FIELD_SEQ_TB, sizeof(struct bttv_buffer), - fh); + fh, NULL); set_tvnorm(btv,btv->tvnorm); set_input(btv, btv->input, btv->tvnorm); @@ -3272,7 +3347,7 @@ static int bttv_open(struct file *file) bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); bttv_field_count(btv); - unlock_kernel(); + mutex_unlock(&btv->lock); return 0; } @@ -3281,6 +3356,7 @@ static int bttv_release(struct file *file) struct bttv_fh *fh = file->private_data; struct bttv *btv = fh->btv; + mutex_lock(&btv->lock); /* turn off overlay */ if (check_btres(fh, RESOURCE_OVERLAY)) bttv_switch_overlay(btv,fh,NULL); @@ -3288,25 +3364,32 @@ static int bttv_release(struct file *file) /* stop video capture */ if (check_btres(fh, RESOURCE_VIDEO_STREAM)) { videobuf_streamoff(&fh->cap); - free_btres(btv,fh,RESOURCE_VIDEO_STREAM); + free_btres_lock(btv,fh,RESOURCE_VIDEO_STREAM); } if (fh->cap.read_buf) { buffer_release(&fh->cap,fh->cap.read_buf); kfree(fh->cap.read_buf); } if (check_btres(fh, RESOURCE_VIDEO_READ)) { - free_btres(btv, fh, RESOURCE_VIDEO_READ); + free_btres_lock(btv, fh, RESOURCE_VIDEO_READ); } /* stop vbi capture */ if (check_btres(fh, RESOURCE_VBI)) { videobuf_stop(&fh->vbi); - free_btres(btv,fh,RESOURCE_VBI); + free_btres_lock(btv,fh,RESOURCE_VBI); } /* free stuff */ + + /* + * videobuf uses cap.vb_lock - we should avoid holding btv->lock, + * otherwise we may have dead lock conditions + */ + mutex_unlock(&btv->lock); videobuf_mmap_free(&fh->cap); videobuf_mmap_free(&fh->vbi); + mutex_lock(&btv->lock); v4l2_prio_close(&btv->prio, fh->prio); file->private_data = NULL; kfree(fh); @@ -3316,6 +3399,7 @@ static int bttv_release(struct file *file) if (!btv->users) audio_mute(btv, 1); + mutex_unlock(&btv->lock); return 0; } @@ -3333,13 +3417,13 @@ bttv_mmap(struct file *file, struct vm_area_struct *vma) static const struct v4l2_file_operations bttv_fops = { - .owner = THIS_MODULE, - .open = bttv_open, - .release = bttv_release, - .ioctl = video_ioctl2, - .read = bttv_read, - .mmap = bttv_mmap, - .poll = bttv_poll, + .owner = THIS_MODULE, + .open = bttv_open, + .release = bttv_release, + .unlocked_ioctl = video_ioctl2, + .read = bttv_read, + .mmap = bttv_mmap, + .poll = bttv_poll, }; static const struct v4l2_ioctl_ops bttv_ioctl_ops = { @@ -3412,21 +3496,19 @@ static int radio_open(struct file *file) dprintk("bttv: open dev=%s\n", video_device_node_name(vdev)); - lock_kernel(); - dprintk("bttv%d: open called (radio)\n",btv->c.nr); /* allocate per filehandle data */ fh = kmalloc(sizeof(*fh), GFP_KERNEL); - if (NULL == fh) { - unlock_kernel(); + if (unlikely(!fh)) return -ENOMEM; - } file->private_data = fh; + mutex_lock(&fh->cap.vb_lock); *fh = btv->init; - v4l2_prio_open(&btv->prio, &fh->prio); + mutex_unlock(&fh->cap.vb_lock); mutex_lock(&btv->lock); + v4l2_prio_open(&btv->prio, &fh->prio); btv->radio_user++; @@ -3434,7 +3516,6 @@ static int radio_open(struct file *file) audio_input(btv,TVAUDIO_INPUT_RADIO); mutex_unlock(&btv->lock); - unlock_kernel(); return 0; } @@ -3444,6 +3525,7 @@ static int radio_release(struct file *file) struct bttv *btv = fh->btv; struct rds_command cmd; + mutex_lock(&btv->lock); v4l2_prio_close(&btv->prio, fh->prio); file->private_data = NULL; kfree(fh); @@ -3451,6 +3533,7 @@ static int radio_release(struct file *file) btv->radio_user--; bttv_call_all(btv, core, ioctl, RDS_CMD_CLOSE, &cmd); + mutex_unlock(&btv->lock); return 0; } diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c index 685d6597ee7..d49b675045f 100644 --- a/drivers/media/video/bt8xx/bttv-i2c.c +++ b/drivers/media/video/bt8xx/bttv-i2c.c @@ -121,9 +121,8 @@ bttv_i2c_wait_done(struct bttv *btv) /* timeout */ if (wait_event_interruptible_timeout(btv->i2c_queue, - btv->i2c_done, msecs_to_jiffies(85)) == -ERESTARTSYS) - - rc = -EIO; + btv->i2c_done, msecs_to_jiffies(85)) == -ERESTARTSYS) + rc = -EIO; if (btv->i2c_done & BT848_INT_RACK) rc = 1; @@ -390,41 +389,3 @@ int __devinit init_bttv_i2c(struct bttv *btv) return btv->i2c_rc; } - -/* Instantiate the I2C IR receiver device, if present */ -void __devinit init_bttv_i2c_ir(struct bttv *btv) -{ - if (0 == btv->i2c_rc) { - struct i2c_board_info info; - /* The external IR receiver is at i2c address 0x34 (0x35 for - reads). Future Hauppauge cards will have an internal - receiver at 0x30 (0x31 for reads). In theory, both can be - fitted, and Hauppauge suggest an external overrides an - internal. - - That's why we probe 0x1a (~0x34) first. CB - */ - const unsigned short addr_list[] = { - 0x1a, 0x18, 0x4b, 0x64, 0x30, 0x71, - I2C_CLIENT_END - }; - - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "ir_video", I2C_NAME_SIZE); - i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL); - } -} - -int __devexit fini_bttv_i2c(struct bttv *btv) -{ - if (0 != btv->i2c_rc) - return 0; - - return i2c_del_adapter(&btv->c.i2c_adap); -} - -/* - * Local variables: - * c-basic-offset: 8 - * End: - */ diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c index f68717a4bde..6bf05a7dc5f 100644 --- a/drivers/media/video/bt8xx/bttv-input.c +++ b/drivers/media/video/bt8xx/bttv-input.c @@ -245,6 +245,83 @@ static void bttv_ir_stop(struct bttv *btv) } } +/* + * Get_key functions used by I2C remotes + */ + +static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) +{ + unsigned char b; + + /* poll IR chip */ + if (1 != i2c_master_recv(ir->c, &b, 1)) { + dprintk(KERN_INFO DEVNAME ": read error\n"); + return -EIO; + } + + /* ignore 0xaa */ + if (b==0xaa) + return 0; + dprintk(KERN_INFO DEVNAME ": key %02x\n", b); + + *ir_key = b; + *ir_raw = b; + return 1; +} + +/* Instantiate the I2C IR receiver device, if present */ +void __devinit init_bttv_i2c_ir(struct bttv *btv) +{ + const unsigned short addr_list[] = { + 0x1a, 0x18, 0x64, 0x30, 0x71, + I2C_CLIENT_END + }; + struct i2c_board_info info; + + if (0 != btv->i2c_rc) + return; + + memset(&info, 0, sizeof(struct i2c_board_info)); + memset(&btv->init_data, 0, sizeof(btv->init_data)); + strlcpy(info.type, "ir_video", I2C_NAME_SIZE); + + switch (btv->c.type) { + case BTTV_BOARD_PV951: + btv->init_data.name = "PV951"; + btv->init_data.get_key = get_key_pv951; + btv->init_data.ir_codes = RC_MAP_PV951; + btv->init_data.type = IR_TYPE_OTHER; + info.addr = 0x4b; + break; + default: + /* + * The external IR receiver is at i2c address 0x34 (0x35 for + * reads). Future Hauppauge cards will have an internal + * receiver at 0x30 (0x31 for reads). In theory, both can be + * fitted, and Hauppauge suggest an external overrides an + * internal. + * That's why we probe 0x1a (~0x34) first. CB + */ + + i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL); + return; + } + + if (btv->init_data.name) + info.platform_data = &btv->init_data; + i2c_new_device(&btv->c.i2c_adap, &info); + + return; +} + +int __devexit fini_bttv_i2c(struct bttv *btv) +{ + if (0 != btv->i2c_rc) + return 0; + + return i2c_del_adapter(&btv->c.i2c_adap); +} + int bttv_input_init(struct bttv *btv) { struct card_ir *ir; @@ -420,10 +497,3 @@ void bttv_input_fini(struct bttv *btv) kfree(btv->remote); btv->remote = NULL; } - - -/* - * Local variables: - * c-basic-offset: 8 - * End: - */ diff --git a/drivers/media/video/bt8xx/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c index 0fa9f39f37a..9b57d091da4 100644 --- a/drivers/media/video/bt8xx/bttv-risc.c +++ b/drivers/media/video/bt8xx/bttv-risc.c @@ -582,7 +582,7 @@ bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); BUG_ON(in_interrupt()); - videobuf_waiton(&buf->vb,0,0); + videobuf_waiton(q, &buf->vb, 0, 0); videobuf_dma_unmap(q->dev, dma); videobuf_dma_free(dma); btcx_riscmem_free(btv->c.pci,&buf->bottom); diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h index 3ec2402c6b4..6fd2a8ebda1 100644 --- a/drivers/media/video/bt8xx/bttv.h +++ b/drivers/media/video/bt8xx/bttv.h @@ -18,7 +18,6 @@ #include <linux/i2c.h> #include <media/v4l2-device.h> #include <media/ir-common.h> -#include <media/ir-kbd-i2c.h> #include <media/i2c-addr.h> #include <media/tuner.h> diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h index 6cccc2a17ee..d1e26a448ed 100644 --- a/drivers/media/video/bt8xx/bttvp.h +++ b/drivers/media/video/bt8xx/bttvp.h @@ -42,7 +42,7 @@ #include <media/videobuf-dma-sg.h> #include <media/tveeprom.h> #include <media/ir-common.h> - +#include <media/ir-kbd-i2c.h> #include "bt848.h" #include "bttv.h" @@ -271,6 +271,12 @@ int bttv_sub_del_devices(struct bttv_core *core); extern int no_overlay; /* ---------------------------------------------------------- */ +/* bttv-input.c */ + +extern void init_bttv_i2c_ir(struct bttv *btv); +extern int fini_bttv_i2c(struct bttv *btv); + +/* ---------------------------------------------------------- */ /* bttv-driver.c */ /* insmod options */ @@ -279,8 +285,6 @@ extern unsigned int bttv_debug; extern unsigned int bttv_gpio; extern void bttv_gpio_tracking(struct bttv *btv, char *comment); extern int init_bttv_i2c(struct bttv *btv); -extern void init_bttv_i2c_ir(struct bttv *btv); -extern int fini_bttv_i2c(struct bttv *btv); #define bttv_printk if (bttv_verbose) printk #define dprintk if (bttv_debug >= 1) printk @@ -366,6 +370,9 @@ struct bttv { int has_remote; struct card_ir *remote; + /* I2C remote data */ + struct IR_i2c_init_data init_data; + /* locking */ spinlock_t s_lock; struct mutex lock; |