• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/drivers/media/video/bt8xx/

Lines Matching refs:btv

175 	struct bttv *btv = video_get_drvdata(vfd);
176 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
845 int check_alloc_btres(struct bttv *btv, struct bttv_fh *fh, int bit)
858 mutex_lock(&btv->lock);
859 if (btv->resources & xbits) {
865 && 0 == (btv->resources & VIDEO_RESOURCES)) {
867 __s32 top = btv->crop[!!fh->do_crop].rect.top;
869 if (btv->vbi_end > top)
874 btv->crop_start = top;
878 if (end > btv->crop_start)
882 btv->vbi_end = end;
887 btv->resources |= bit;
888 mutex_unlock(&btv->lock);
892 mutex_unlock(&btv->lock);
903 int locked_btres(struct bttv *btv, int bit)
905 return (btv->resources & bit);
908 /* Call with btv->lock down. */
910 disclaim_vbi_lines(struct bttv *btv)
912 btv->vbi_end = 0;
915 /* Call with btv->lock down. */
917 disclaim_video_lines(struct bttv *btv)
922 tvnorm = &bttv_tvnorms[btv->tvnorm];
923 btv->crop_start = tvnorm->cropcap.bounds.top
938 void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits)
944 mutex_lock(&btv->lock);
946 btv->resources &= ~bits;
948 bits = btv->resources;
951 disclaim_video_lines(btv);
954 disclaim_vbi_lines(btv);
956 mutex_unlock(&btv->lock);
972 static void set_pll_freq(struct bttv *btv, unsigned int fin, unsigned int fout)
994 static void set_pll(struct bttv *btv)
998 if (!btv->pll.pll_crystal)
1001 if (btv->pll.pll_ofreq == btv->pll.pll_current) {
1002 dprintk("bttv%d: PLL: no change required\n",btv->c.nr);
1006 if (btv->pll.pll_ifreq == btv->pll.pll_ofreq) {
1008 if (btv->pll.pll_current == 0)
1011 btv->c.nr,btv->pll.pll_ifreq);
1014 btv->pll.pll_current = 0;
1018 bttv_printk(KERN_INFO "bttv%d: PLL: %d => %d ",btv->c.nr,
1019 btv->pll.pll_ifreq, btv->pll.pll_ofreq);
1020 set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq);
1031 btv->pll.pll_current = btv->pll.pll_ofreq;
1036 btv->pll.pll_current = -1;
1042 static void bt848A_set_timing(struct bttv *btv)
1045 int table_idx = bttv_tvnorms[btv->tvnorm].sram;
1046 int fsc = bttv_tvnorms[btv->tvnorm].Fsc;
1048 if (btv->input == btv->dig) {
1050 btv->c.nr,table_idx);
1060 btv->pll.pll_ofreq = 27000000;
1062 set_pll(btv);
1066 btv->pll.pll_ofreq = fsc;
1067 set_pll(btv);
1074 static void bt848_bright(struct bttv *btv, int bright)
1079 btv->bright = bright;
1086 static void bt848_hue(struct bttv *btv, int hue)
1090 btv->hue = hue;
1097 static void bt848_contrast(struct bttv *btv, int cont)
1101 btv->contrast = cont;
1111 static void bt848_sat(struct bttv *btv, int color)
1115 btv->saturation = color;
1118 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7;
1119 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254;
1131 video_mux(struct bttv *btv, unsigned int input)
1135 if (input >= bttv_tvcards[btv->c.type].video_inputs)
1139 mask2 = bttv_tvcards[btv->c.type].gpiomask2;
1143 if (input == btv->svhs) {
1150 mux = bttv_muxsel(btv, input);
1153 btv->c.nr,input,mux);
1156 if(bttv_tvcards[btv->c.type].muxsel_hook)
1157 bttv_tvcards[btv->c.type].muxsel_hook (btv, input);
1167 audio_mux(struct bttv *btv, int input, int mute)
1172 gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
1173 bttv_tvcards[btv->c.type].gpiomask);
1176 btv->mute = mute;
1177 btv->audio = input;
1180 mute = mute || (btv->opt_automute && !signal && !btv->radio_user);
1183 gpio_val = bttv_tvcards[btv->c.type].gpiomute;
1185 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
1187 switch (btv->c.type) {
1190 gpio_val = bttv_tda9880_setnorm(btv, gpio_val);
1194 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val);
1198 bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]);
1203 ctrl.value = btv->mute;
1204 bttv_call_all(btv, core, s_ctrl, &ctrl);
1205 if (btv->sd_msp34xx) {
1236 if (btv->c.type == BTTV_BOARD_VOODOOTV_200)
1243 v4l2_subdev_call(btv->sd_msp34xx, audio, s_routing,
1246 if (btv->sd_tvaudio) {
1247 v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing,
1254 audio_mute(struct bttv *btv, int mute)
1256 return audio_mux(btv, btv->audio, mute);
1260 audio_input(struct bttv *btv, int input)
1262 return audio_mux(btv, input, btv->mute);
1294 /* Call with btv->lock down. */
1296 set_tvnorm(struct bttv *btv, unsigned int norm)
1302 BUG_ON(btv->tvnorm >= BTTV_TVNORMS);
1306 if (memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap,
1308 bttv_crop_reset(&btv->crop[0], norm);
1309 btv->crop[1] = btv->crop[0]; /* current = default */
1311 if (0 == (btv->resources & VIDEO_RESOURCES)) {
1312 btv->crop_start = tvnorm->cropcap.bounds.top
1317 btv->tvnorm = norm;
1325 bt848A_set_timing(btv);
1327 switch (btv->c.type) {
1330 bttv_tda9880_setnorm(btv, gpio_read());
1334 bttv_call_all(btv, core, s_std, id);
1339 /* Call with btv->lock down. */
1341 set_input(struct bttv *btv, unsigned int input, unsigned int norm)
1345 btv->input = input;
1347 spin_lock_irqsave(&btv->s_lock,flags);
1348 if (btv->curr.frame_irq) {
1350 btv->new_input = input;
1352 video_mux(btv,input);
1354 spin_unlock_irqrestore(&btv->s_lock,flags);
1356 video_mux(btv,input);
1358 audio_input(btv, (btv->tuner_type != TUNER_ABSENT && input == 0) ?
1360 set_tvnorm(btv, norm);
1363 static void init_irqreg(struct bttv *btv)
1368 if (bttv_tvcards[btv->c.type].no_video) {
1374 btwrite((btv->triton1) |
1375 (btv->gpioirq ? BT848_INT_GPINT : 0) |
1385 static void init_bt848(struct bttv *btv)
1389 if (bttv_tvcards[btv->c.type].no_video) {
1391 init_irqreg(btv);
1408 val = btv->opt_chroma_agc ? BT848_SCLOOP_CAGC : 0;
1414 btwrite(BT848_ADC_RESERVED | (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0),
1420 if (btv->opt_lumafilter) {
1428 bt848_bright(btv, btv->bright);
1429 bt848_hue(btv, btv->hue);
1430 bt848_contrast(btv, btv->contrast);
1431 bt848_sat(btv, btv->saturation);
1434 init_irqreg(btv);
1437 static void bttv_reinit_bt848(struct bttv *btv)
1442 printk(KERN_INFO "bttv%d: reset, reinitialize\n",btv->c.nr);
1443 spin_lock_irqsave(&btv->s_lock,flags);
1444 btv->errors=0;
1445 bttv_set_dma(btv,0);
1446 spin_unlock_irqrestore(&btv->s_lock,flags);
1448 init_bt848(btv);
1449 btv->pll.pll_current = -1;
1450 set_input(btv, btv->input, btv->tvnorm);
1457 struct bttv *btv = fh->btv;
1461 c->value = btv->bright;
1464 c->value = btv->hue;
1467 c->value = btv->contrast;
1470 c->value = btv->saturation;
1478 bttv_call_all(btv, core, g_ctrl, c);
1482 c->value = btv->opt_chroma_agc;
1485 c->value = btv->opt_combfilter;
1488 c->value = btv->opt_lumafilter;
1491 c->value = btv->opt_automute;
1494 c->value = btv->opt_adc_crush;
1497 c->value = btv->opt_vcr_hack;
1500 c->value = btv->opt_whitecrush_upper;
1503 c->value = btv->opt_whitecrush_lower;
1506 c->value = btv->opt_uv_ratio;
1509 c->value = btv->opt_full_luma_range;
1512 c->value = btv->opt_coring;
1526 struct bttv *btv = fh->btv;
1528 err = v4l2_prio_check(&btv->prio, fh->prio);
1534 bt848_bright(btv, c->value);
1537 bt848_hue(btv, c->value);
1540 bt848_contrast(btv, c->value);
1543 bt848_sat(btv, c->value);
1546 audio_mute(btv, c->value);
1549 if (btv->volume_gpio)
1550 btv->volume_gpio(btv, c->value);
1552 bttv_call_all(btv, core, s_ctrl, c);
1557 bttv_call_all(btv, core, s_ctrl, c);
1561 btv->opt_chroma_agc = c->value;
1562 val = btv->opt_chroma_agc ? BT848_SCLOOP_CAGC : 0;
1567 btv->opt_combfilter = c->value;
1570 btv->opt_lumafilter = c->value;
1571 if (btv->opt_lumafilter) {
1580 btv->opt_automute = c->value;
1583 btv->opt_adc_crush = c->value;
1585 (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0),
1589 btv->opt_vcr_hack = c->value;
1592 btv->opt_whitecrush_upper = c->value;
1596 btv->opt_whitecrush_lower = c->value;
1600 btv->opt_uv_ratio = c->value;
1601 bt848_sat(btv, btv->saturation);
1604 btv->opt_full_luma_range = c->value;
1608 btv->opt_coring = c->value;
1619 void bttv_gpio_tracking(struct bttv *btv, char *comment)
1625 btv->c.nr,outbits,data & outbits, data & ~outbits, comment);
1628 static void bttv_field_count(struct bttv *btv)
1632 if (btv->users)
1641 btv->field_count = 0;
1663 bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
1673 spin_lock_irqsave(&btv->s_lock,flags);
1674 old = btv->screen;
1675 btv->screen = new;
1676 btv->loop_irq |= 1;
1677 bttv_set_dma(btv, 0x03);
1678 spin_unlock_irqrestore(&btv->s_lock,flags);
1681 bttv_dma_free(&fh->cap,btv, old);
1685 free_btres(btv,fh,RESOURCE_OVERLAY);
1693 static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1717 mutex_lock(&btv->lock);
1719 norm = btv->tvnorm;
1723 if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) {
1724 mutex_unlock(&btv->lock);
1728 mutex_unlock(&btv->lock);
1732 mutex_lock(&btv->lock);
1734 norm = btv->tvnorm;
1735 c = btv->crop[!!fh->do_crop];
1737 mutex_unlock(&btv->lock);
1748 /* btv->crop counts frame lines. Max. scale
1785 if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf)))
1790 if (0 != (rc = bttv_buffer_risc(btv,buf)))
1797 bttv_dma_free(q,btv,buf);
1821 return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt,
1830 struct bttv *btv = fh->btv;
1833 list_add_tail(&buf->vb.queue,&btv->capture);
1834 if (!btv->curr.frame_irq) {
1835 btv->loop_irq |= 1;
1836 bttv_set_dma(btv, 0x03);
1845 bttv_dma_free(q,fh->btv,buf);
1858 struct bttv *btv = fh->btv;
1862 err = v4l2_prio_check(&btv->prio, fh->prio);
1872 mutex_lock(&btv->lock);
1873 set_tvnorm(btv, i);
1874 mutex_unlock(&btv->lock);
1882 struct bttv *btv = fh->btv;
1895 struct bttv *btv = fh->btv;
1898 if (i->index >= bttv_tvcards[btv->c.type].video_inputs)
1904 if (btv->tuner_type != TUNER_ABSENT && i->index == 0) {
1908 } else if (i->index == btv->svhs) {
1914 if (i->index == btv->input) {
1931 struct bttv *btv = fh->btv;
1933 *i = btv->input;
1940 struct bttv *btv = fh->btv;
1944 err = v4l2_prio_check(&btv->prio, fh->prio);
1948 if (i > bttv_tvcards[btv->c.type].video_inputs)
1951 mutex_lock(&btv->lock);
1952 set_input(btv, i, btv->tvnorm);
1953 mutex_unlock(&btv->lock);
1961 struct bttv *btv = fh->btv;
1964 err = v4l2_prio_check(&btv->prio, fh->prio);
1968 if (btv->tuner_type == TUNER_ABSENT)
1974 mutex_lock(&btv->lock);
1975 bttv_call_all(btv, tuner, s_tuner, t);
1977 if (btv->audio_mode_gpio)
1978 btv->audio_mode_gpio(btv, t, 1);
1980 mutex_unlock(&btv->lock);
1989 struct bttv *btv = fh->btv;
1991 f->type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1992 f->frequency = btv->freq;
2001 struct bttv *btv = fh->btv;
2004 err = v4l2_prio_check(&btv->prio, fh->prio);
2010 if (unlikely(f->type != (btv->radio_user
2013 mutex_lock(&btv->lock);
2014 btv->freq = f->frequency;
2015 bttv_call_all(btv, tuner, s_frequency, f);
2016 if (btv->has_matchbox && btv->radio_user)
2017 tea5757_set_freq(btv, btv->freq);
2018 mutex_unlock(&btv->lock);
2025 struct bttv *btv = fh->btv;
2028 btv->c.nr, btv->c.nr);
2029 bttv_call_all(btv, core, log_status);
2031 btv->c.nr, btv->c.nr);
2040 struct bttv *btv = fh->btv;
2060 struct bttv *btv = fh->btv;
2136 struct bttv *btv = fh->btv;
2150 mutex_lock(&btv->lock);
2152 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2155 c = &btv->crop[!!fh->do_crop];
2160 && !locked_btres(btv, VIDEO_RESOURCES)) {
2171 Note btv->vbi_end is really a minimum, see
2173 if (btv->vbi_end > b->top) {
2174 max_height -= btv->vbi_end - b->top;
2181 if (btv->vbi_end > c->rect.top)
2210 if (btv->vbi_end > c->rect.top) {
2212 c->rect.top = btv->vbi_end;
2228 mutex_unlock(&btv->lock);
2260 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1;
2306 static int setup_window(struct bttv_fh *fh, struct bttv *btv,
2336 if (NULL != btv->fbuf.base)
2337 n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height,
2365 btv->init.ov.w.width = win->w.width;
2366 btv->init.ov.w.height = win->w.height;
2367 btv->init.ov.field = win->field;
2375 new->crop = btv->crop[!!fh->do_crop].rect;
2376 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2377 retval = bttv_switch_overlay(btv,fh,new);
2479 struct bttv *btv = fh->btv;
2493 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2550 struct bttv *btv = fh->btv;
2585 btv->init.fmt = fmt;
2586 btv->init.width = f->fmt.pix.width;
2587 btv->init.height = f->fmt.pix.height;
2597 struct bttv *btv = fh->btv;
2604 return setup_window(fh, btv, &f->fmt.win, 1);
2639 struct bttv *btv = fh->btv;
2645 strlcpy(cap->card, btv->video_dev->name, sizeof(cap->card));
2647 "PCI:%s", pci_name(btv->c.pci));
2654 if (btv->has_saa6588)
2659 if (btv->tuner_type != TUNER_ABSENT)
2719 struct bttv *btv = fh->btv;
2721 *fb = btv->fbuf;
2731 struct bttv *btv = fh->btv;
2737 if (NULL == btv->fbuf.base)
2740 dprintk("bttv%d: overlay: !setup_ok\n", btv->c.nr);
2745 if (!check_alloc_btres(btv, fh, RESOURCE_OVERLAY))
2750 fh->ov.tvnorm = btv->tvnorm;
2752 new->crop = btv->crop[!!fh->do_crop].rect;
2753 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2759 retval = bttv_switch_overlay(btv, fh, new);
2768 struct bttv *btv = fh->btv;
2800 btv->fbuf.base = fb->base;
2801 btv->fbuf.fmt.width = fb->fmt.width;
2802 btv->fbuf.fmt.height = fb->fmt.height;
2804 btv->fbuf.fmt.bytesperline = fb->fmt.bytesperline;
2806 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8;
2810 btv->init.ovfmt = fmt;
2816 btv->init.ov.w.width = fb->fmt.width;
2817 btv->init.ov.w.height = fb->fmt.height;
2826 new->crop = btv->crop[!!fh->do_crop].rect;
2827 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2828 retval = bttv_switch_overlay(btv, fh, new);
2852 struct bttv *btv = fh->btv;
2855 if (!check_alloc_btres(btv, fh, res))
2872 struct bttv *btv = fh->btv;
2875 if (!check_alloc_btres(btv, fh, res))
2885 struct bttv *btv = fh->btv;
2893 free_btres(btv, fh, res);
2901 struct bttv *btv = fh->btv;
2910 if (!btv->volume_gpio && (c->id == V4L2_CID_AUDIO_VOLUME))
2925 struct bttv *btv = fh->btv;
2927 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id,
2936 struct bttv *btv = fh->btv;
2938 if (btv->tuner_type == TUNER_ABSENT)
2943 mutex_lock(&btv->lock);
2945 bttv_call_all(btv, tuner, g_tuner, t);
2952 if (btv->audio_mode_gpio)
2953 btv->audio_mode_gpio(btv, t, 0);
2955 mutex_unlock(&btv->lock);
2962 struct bttv *btv = fh->btv;
2964 *p = v4l2_prio_max(&btv->prio);
2973 struct bttv *btv = fh->btv;
2975 return v4l2_prio_change(&btv->prio, &fh->prio, prio);
2982 struct bttv *btv = fh->btv;
2988 *cap = bttv_tvnorms[btv->tvnorm].cropcap;
2996 struct bttv *btv = fh->btv;
3002 /* No fh->do_crop = 1; because btv->crop[1] may be
3006 crop->c = btv->crop[!!fh->do_crop].rect;
3014 struct bttv *btv = fh->btv;
3027 retval = v4l2_prio_check(&btv->prio, fh->prio);
3034 mutex_lock(&btv->lock);
3038 if (locked_btres(fh->btv, VIDEO_RESOURCES)) {
3039 mutex_unlock(&btv->lock);
3043 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
3049 b_top = max(b->top, btv->vbi_end);
3051 mutex_unlock(&btv->lock);
3072 btv->crop[1] = c;
3074 mutex_unlock(&btv->lock);
3082 btv->init.width = c.min_scaled_width;
3085 btv->init.width = c.max_scaled_width;
3090 btv->init.height = c.min_scaled_height;
3093 btv->init.height = c.max_scaled_height;
3124 if (fh->btv->errors)
3125 bttv_reinit_bt848(fh->btv);
3127 fh->btv->c.nr,(int)count,v4l2_type_names[fh->type]);
3131 if (!check_alloc_btres(fh->btv, fh, RESOURCE_VIDEO_READ)) {
3138 free_btres(fh->btv, fh, RESOURCE_VIDEO_READ);
3141 if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI))
3160 if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI))
3176 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM))
3209 struct bttv *btv = video_drvdata(file);
3227 btv->c.nr,v4l2_type_names[type]);
3236 *fh = btv->init;
3239 v4l2_prio_open(&btv->prio, &fh->prio);
3242 &btv->c.pci->dev, &btv->s_lock,
3248 &btv->c.pci->dev, &btv->s_lock,
3253 set_tvnorm(btv,btv->tvnorm);
3254 set_input(btv, btv->input, btv->tvnorm);
3256 btv->users++;
3259 which only change on request. These are stored in btv->crop[1].
3263 will use btv->crop[0], the default cropping parameters for the
3272 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);
3274 bttv_field_count(btv);
3282 struct bttv *btv = fh->btv;
3286 bttv_switch_overlay(btv,fh,NULL);
3291 free_btres(btv,fh,RESOURCE_VIDEO_STREAM);
3298 free_btres(btv, fh, RESOURCE_VIDEO_READ);
3304 free_btres(btv,fh,RESOURCE_VBI);
3310 v4l2_prio_close(&btv->prio, fh->prio);
3314 btv->users--;
3315 bttv_field_count(btv);
3317 if (!btv->users)
3318 audio_mute(btv, 1);
3329 fh->btv->c.nr, v4l2_type_names[fh->type],
3410 struct bttv *btv = video_drvdata(file);
3417 dprintk("bttv%d: open called (radio)\n",btv->c.nr);
3426 *fh = btv->init;
3427 v4l2_prio_open(&btv->prio, &fh->prio);
3429 mutex_lock(&btv->lock);
3431 btv->radio_user++;
3433 bttv_call_all(btv, tuner, s_radio);
3434 audio_input(btv,TVAUDIO_INPUT_RADIO);
3436 mutex_unlock(&btv->lock);
3444 struct bttv *btv = fh->btv;
3447 v4l2_prio_close(&btv->prio, fh->prio);
3451 btv->radio_user--;
3453 bttv_call_all(btv, core, ioctl, RDS_CMD_CLOSE, &cmd);
3462 struct bttv *btv = fh->btv;
3465 strlcpy(cap->card, btv->radio_dev->name, sizeof(cap->card));
3466 sprintf(cap->bus_info, "PCI:%s", pci_name(btv->c.pci));
3476 struct bttv *btv = fh->btv;
3478 if (btv->tuner_type == TUNER_ABSENT)
3482 mutex_lock(&btv->lock);
3486 bttv_call_all(btv, tuner, g_tuner, t);
3488 if (btv->audio_mode_gpio)
3489 btv->audio_mode_gpio(btv, t, 0);
3491 mutex_unlock(&btv->lock);
3523 struct bttv *btv = fh->btv;
3528 bttv_call_all(btv, tuner, g_tuner, t);
3582 struct bttv *btv = fh->btv;
3589 bttv_call_all(btv, core, ioctl, RDS_CMD_READ, &cmd);
3597 struct bttv *btv = fh->btv;
3602 bttv_call_all(btv, core, ioctl, RDS_CMD_POLL, &cmd);
3679 static void bttv_risc_disasm(struct bttv *btv,
3685 btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma);
3687 printk("%s: 0x%lx: ", btv->c.v4l2_dev.name,
3692 btv->c.v4l2_dev.name, (unsigned long)(risc->dma + ((i+j)<<2)),
3699 static void bttv_print_riscaddr(struct bttv *btv)
3702 (unsigned long long)btv->main.dma);
3704 btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0,
3705 btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0);
3707 btv->curr.top ? (unsigned long long)btv->curr.top->top.dma : 0,
3708 btv->curr.bottom ? (unsigned long long)btv->curr.bottom->bottom.dma : 0);
3710 btv->screen ? (unsigned long long)btv->screen->top.dma : 0,
3711 btv->screen ? (unsigned long long)btv->screen->bottom.dma : 0);
3712 bttv_risc_disasm(btv, &btv->main);
3753 static void bttv_irq_debug_low_latency(struct bttv *btv, u32 rc)
3756 btv->c.nr,
3757 (unsigned long)btv->main.dma,
3758 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]),
3759 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]),
3765 btv->c.nr);
3769 btv->c.nr);
3771 btv->c.nr);
3776 bttv_irq_next_video(struct bttv *btv, struct bttv_buffer_set *set)
3783 if (!list_empty(&btv->capture)) {
3785 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue);
3793 (item->vb.queue.next != &btv->capture)) {
3834 if (NULL != btv->screen) {
3835 if (V4L2_FIELD_HAS_BOTH(btv->screen->vb.field)) {
3837 set->top = btv->screen;
3838 set->bottom = btv->screen;
3841 if (V4L2_FIELD_TOP == btv->screen->vb.field &&
3843 set->top = btv->screen;
3845 if (V4L2_FIELD_BOTTOM == btv->screen->vb.field &&
3847 set->bottom = btv->screen;
3853 btv->c.nr,set->top, set->bottom,
3854 btv->screen,set->frame_irq,set->top_irq);
3859 bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
3869 printk("bttv%d: wakeup: both=%p\n",btv->c.nr,wakeup->top);
3871 wakeup->top->vb.field_count = btv->field_count;
3878 printk("bttv%d: wakeup: top=%p\n",btv->c.nr,wakeup->top);
3880 wakeup->top->vb.field_count = btv->field_count;
3886 printk("bttv%d: wakeup: bottom=%p\n",btv->c.nr,wakeup->bottom);
3888 wakeup->bottom->vb.field_count = btv->field_count;
3896 bttv_irq_wakeup_vbi(struct bttv *btv, struct bttv_buffer *wakeup,
3906 wakeup->vb.field_count = btv->field_count;
3913 struct bttv *btv = (struct bttv *)data;
3921 btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total,
3927 spin_lock_irqsave(&btv->s_lock,flags);
3931 old = btv->curr;
3932 ovbi = btv->cvbi;
3933 btv->curr = new;
3934 btv->cvbi = NULL;
3935 btv->loop_irq = 0;
3936 bttv_buffer_activate_video(btv, &new);
3937 bttv_buffer_activate_vbi(btv, NULL);
3938 bttv_set_dma(btv, 0);
3941 bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_ERROR);
3942 bttv_irq_wakeup_vbi(btv, ovbi, VIDEOBUF_ERROR);
3945 while (!list_empty(&btv->capture)) {
3946 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue);
3951 while (!list_empty(&btv->vcapture)) {
3952 item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue);
3958 btv->errors++;
3959 spin_unlock_irqrestore(&btv->s_lock,flags);
3963 bttv_irq_wakeup_top(struct bttv *btv)
3965 struct bttv_buffer *wakeup = btv->curr.top;
3970 spin_lock(&btv->s_lock);
3971 btv->curr.top_irq = 0;
3972 btv->curr.top = NULL;
3973 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
3976 wakeup->vb.field_count = btv->field_count;
3979 spin_unlock(&btv->s_lock);
3992 bttv_irq_switch_video(struct bttv *btv)
3998 spin_lock(&btv->s_lock);
4001 bttv_irq_next_video(btv, &new);
4003 if ((btv->curr.top && is_active(&btv->curr.top->top, rc)) ||
4004 (btv->curr.bottom && is_active(&btv->curr.bottom->bottom, rc))) {
4005 btv->framedrop++;
4007 bttv_irq_debug_low_latency(btv, rc);
4008 spin_unlock(&btv->s_lock);
4013 old = btv->curr;
4014 btv->curr = new;
4015 btv->loop_irq &= ~1;
4016 bttv_buffer_activate_video(btv, &new);
4017 bttv_set_dma(btv, 0);
4020 if (UNSET != btv->new_input) {
4021 video_mux(btv,btv->new_input);
4022 btv->new_input = UNSET;
4026 bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_DONE);
4027 spin_unlock(&btv->s_lock);
4031 bttv_irq_switch_vbi(struct bttv *btv)
4037 spin_lock(&btv->s_lock);
4039 if (!list_empty(&btv->vcapture))
4040 new = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue);
4041 old = btv->cvbi;
4046 btv->framedrop++;
4048 bttv_irq_debug_low_latency(btv, rc);
4049 spin_unlock(&btv->s_lock);
4054 btv->cvbi = new;
4055 btv->loop_irq &= ~4;
4056 bttv_buffer_activate_vbi(btv, new);
4057 bttv_set_dma(btv, 0);
4059 bttv_irq_wakeup_vbi(btv, old, VIDEOBUF_DONE);
4060 spin_unlock(&btv->s_lock);
4068 struct bttv *btv;
4071 btv=(struct bttv *)dev_id;
4073 if (btv->custom_irq)
4074 handled = btv->custom_irq(btv);
4092 btv->c.nr, count, btv->field_count,
4108 btv->field_count++;
4110 if ((astat & BT848_INT_GPINT) && btv->remote) {
4111 wake_up(&btv->gpioq);
4112 bttv_input_irq(btv);
4116 btv->i2c_done = stat;
4117 wake_up(&btv->i2c_queue);
4121 bttv_irq_switch_vbi(btv);
4124 bttv_irq_wakeup_top(btv);
4127 bttv_irq_switch_video(btv);
4129 if ((astat & BT848_INT_HLOCK) && btv->opt_automute)
4130 audio_mute(btv, btv->mute); /* trigger automute */
4133 printk(KERN_INFO "bttv%d: %s%s @ %08x,",btv->c.nr,
4140 bttv_print_riscaddr(btv);
4144 btv->c.nr,btread(BT848_RISC_COUNT));
4146 bttv_print_riscaddr(btv);
4156 "bttv%d: IRQ lockup, cleared int mask [", btv->c.nr);
4159 "bttv%d: IRQ lockup, clearing GPINT from int mask [", btv->c.nr);
4170 btv->irq_total++;
4172 btv->irq_me++;
4180 static struct video_device *vdev_init(struct bttv *btv,
4190 vfd->v4l2_dev = &btv->c.v4l2_dev;
4193 video_set_drvdata(vfd, btv);
4195 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
4196 type_name, bttv_tvcards[btv->c.type].name);
4200 static void bttv_unregister_video(struct bttv *btv)
4202 if (btv->video_dev) {
4203 if (video_is_registered(btv->video_dev))
4204 video_unregister_device(btv->video_dev);
4206 video_device_release(btv->video_dev);
4207 btv->video_dev = NULL;
4209 if (btv->vbi_dev) {
4210 if (video_is_registered(btv->vbi_dev))
4211 video_unregister_device(btv->vbi_dev);
4213 video_device_release(btv->vbi_dev);
4214 btv->vbi_dev = NULL;
4216 if (btv->radio_dev) {
4217 if (video_is_registered(btv->radio_dev))
4218 video_unregister_device(btv->radio_dev);
4220 video_device_release(btv->radio_dev);
4221 btv->radio_dev = NULL;
4226 static int __devinit bttv_register_video(struct bttv *btv)
4232 btv->video_dev = vdev_init(btv, &bttv_video_template, "video");
4234 if (NULL == btv->video_dev)
4236 if (video_register_device(btv->video_dev, VFL_TYPE_GRABBER,
4237 video_nr[btv->c.nr]) < 0)
4240 btv->c.nr, video_device_node_name(btv->video_dev));
4241 if (device_create_file(&btv->video_dev->dev,
4244 "failed\n", btv->c.nr);
4249 btv->vbi_dev = vdev_init(btv, &bttv_video_template, "vbi");
4251 if (NULL == btv->vbi_dev)
4253 if (video_register_device(btv->vbi_dev, VFL_TYPE_VBI,
4254 vbi_nr[btv->c.nr]) < 0)
4257 btv->c.nr, video_device_node_name(btv->vbi_dev));
4259 if (!btv->has_radio)
4262 btv->radio_dev = vdev_init(btv, &radio_template, "radio");
4263 if (NULL == btv->radio_dev)
4265 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,
4266 radio_nr[btv->c.nr]) < 0)
4269 btv->c.nr, video_device_node_name(btv->radio_dev));
4275 bttv_unregister_video(btv);
4298 struct bttv *btv;
4303 bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL);
4304 if (btv == NULL) {
4308 btv->c.nr = bttv_num;
4309 snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name),
4310 "bttv%d", btv->c.nr);
4313 mutex_init(&btv->lock);
4314 spin_lock_init(&btv->s_lock);
4315 spin_lock_init(&btv->gpio_lock);
4316 init_waitqueue_head(&btv->gpioq);
4317 init_waitqueue_head(&btv->i2c_queue);
4318 INIT_LIST_HEAD(&btv->c.subs);
4319 INIT_LIST_HEAD(&btv->capture);
4320 INIT_LIST_HEAD(&btv->vcapture);
4321 v4l2_prio_init(&btv->prio);
4323 init_timer(&btv->timeout);
4324 btv->timeout.function = bttv_irq_timeout;
4325 btv->timeout.data = (unsigned long)btv;
4327 btv->i2c_rc = -1;
4328 btv->tuner_type = UNSET;
4329 btv->new_input = UNSET;
4330 btv->has_radio=radio[btv->c.nr];
4333 btv->c.pci = dev;
4334 btv->id = dev->device;
4337 btv->c.nr);
4342 btv->c.nr);
4347 btv->c.v4l2_dev.name)) {
4349 btv->c.nr,
4356 result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev);
4358 printk(KERN_WARNING "bttv%d: v4l2_device_register() failed\n", btv->c.nr);
4362 pci_read_config_byte(dev, PCI_CLASS_REVISION, &btv->revision);
4365 bttv_num,btv->id, btv->revision, pci_name(dev));
4367 btv->c.pci->irq, lat,
4371 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
4372 if (NULL == btv->bt848_mmio) {
4373 printk("bttv%d: ioremap() failed\n", btv->c.nr);
4379 bttv_idcard(btv);
4383 result = request_irq(btv->c.pci->irq, bttv_irq,
4384 IRQF_SHARED | IRQF_DISABLED, btv->c.v4l2_dev.name, (void *)btv);
4387 bttv_num,btv->c.pci->irq);
4391 if (0 != bttv_handle_chipset(btv)) {
4397 btv->opt_combfilter = combfilter;
4398 btv->opt_lumafilter = lumafilter;
4399 btv->opt_automute = automute;
4400 btv->opt_chroma_agc = chroma_agc;
4401 btv->opt_adc_crush = adc_crush;
4402 btv->opt_vcr_hack = vcr_hack;
4403 btv->opt_whitecrush_upper = whitecrush_upper;
4404 btv->opt_whitecrush_lower = whitecrush_lower;
4405 btv->opt_uv_ratio = uv_ratio;
4406 btv->opt_full_luma_range = full_luma_range;
4407 btv->opt_coring = coring;
4410 btv->init.btv = btv;
4411 btv->init.ov.w.width = 320;
4412 btv->init.ov.w.height = 240;
4413 btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
4414 btv->init.width = 320;
4415 btv->init.height = 240;
4416 btv->input = 0;
4420 bttv_gpio_tracking(btv,"pre-init");
4422 bttv_risc_init_main(btv);
4423 init_bt848(btv);
4429 bttv_gpio_tracking(btv,"init");
4432 bttv_init_card1(btv);
4435 init_bttv_i2c(btv);
4438 bttv_init_card2(btv);
4439 bttv_init_tuner(btv);
4440 init_irqreg(btv);
4443 if (!bttv_tvcards[btv->c.type].no_video) {
4444 bttv_register_video(btv);
4445 bt848_bright(btv,32768);
4446 bt848_contrast(btv,32768);
4447 bt848_hue(btv,32768);
4448 bt848_sat(btv,32768);
4449 audio_mute(btv, 1);
4450 set_input(btv, 0, btv->tvnorm);
4451 bttv_crop_reset(&btv->crop[0], btv->tvnorm);
4452 btv->crop[1] = btv->crop[0]; /* current = default */
4453 disclaim_vbi_lines(btv);
4454 disclaim_video_lines(btv);
4458 if (bttv_tvcards[btv->c.type].has_dvb) {
4459 bttv_sub_add_device(&btv->c, "dvb");
4460 request_modules(btv);
4464 init_bttv_i2c_ir(btv);
4465 bttv_input_init(btv);
4473 free_irq(btv->c.pci->irq,btv);
4476 v4l2_device_unregister(&btv->c.v4l2_dev);
4479 if (btv->bt848_mmio)
4480 iounmap(btv->bt848_mmio);
4481 release_mem_region(pci_resource_start(btv->c.pci,0),
4482 pci_resource_len(btv->c.pci,0));
4489 struct bttv *btv = to_bttv(v4l2_dev);
4492 printk("bttv%d: unloading\n",btv->c.nr);
4500 bttv_gpio_tracking(btv,"cleanup");
4503 btv->shutdown=1;
4504 wake_up(&btv->gpioq);
4505 bttv_input_fini(btv);
4506 bttv_sub_del_devices(&btv->c);
4509 fini_bttv_i2c(btv);
4512 bttv_unregister_video(btv);
4515 btcx_riscmem_free(btv->c.pci,&btv->main);
4518 free_irq(btv->c.pci->irq,btv);
4519 iounmap(btv->bt848_mmio);
4520 release_mem_region(pci_resource_start(btv->c.pci,0),
4521 pci_resource_len(btv->c.pci,0));
4523 v4l2_device_unregister(&btv->c.v4l2_dev);
4524 bttvs[btv->c.nr] = NULL;
4525 kfree(btv);
4534 struct bttv *btv = to_bttv(v4l2_dev);
4538 dprintk("bttv%d: suspend %d\n", btv->c.nr, state.event);
4541 spin_lock_irqsave(&btv->s_lock,flags);
4543 btv->state.video = btv->curr;
4544 btv->state.vbi = btv->cvbi;
4545 btv->state.loop_irq = btv->loop_irq;
4546 btv->curr = idle;
4547 btv->loop_irq = 0;
4548 bttv_buffer_activate_video(btv, &idle);
4549 bttv_buffer_activate_vbi(btv, NULL);
4550 bttv_set_dma(btv, 0);
4552 spin_unlock_irqrestore(&btv->s_lock,flags);
4555 btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN);
4556 btv->state.gpio_data = gpio_read();
4562 btv->state.disabled = 1;
4570 struct bttv *btv = to_bttv(v4l2_dev);
4574 dprintk("bttv%d: resume\n", btv->c.nr);
4577 if (btv->state.disabled) {
4581 btv->c.nr);
4584 btv->state.disabled = 0;
4590 btv->c.nr);
4591 btv->state.disabled = 1;
4598 bttv_reinit_bt848(btv);
4599 gpio_inout(0xffffff, btv->state.gpio_enable);
4600 gpio_write(btv->state.gpio_data);
4603 spin_lock_irqsave(&btv->s_lock,flags);
4604 btv->curr = btv->state.video;
4605 btv->cvbi = btv->state.vbi;
4606 btv->loop_irq = btv->state.loop_irq;
4607 bttv_buffer_activate_video(btv, &btv->curr);
4608 bttv_buffer_activate_vbi(btv, btv->cvbi);
4609 bttv_set_dma(btv, 0);
4610 spin_unlock_irqrestore(&btv->s_lock,flags);