• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/src/linux/linux-2.6/drivers/media/video/bt8xx/

Lines Matching refs:btv

161 	struct bttv *btv = dev_get_drvdata(vfd->dev);
162 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
840 int check_alloc_btres(struct bttv *btv, struct bttv_fh *fh, int bit)
853 mutex_lock(&btv->lock);
854 if (btv->resources & xbits) {
860 && 0 == (btv->resources & VIDEO_RESOURCES)) {
862 __s32 top = btv->crop[!!fh->do_crop].rect.top;
864 if (btv->vbi_end > top)
869 btv->crop_start = top;
873 if (end > btv->crop_start)
877 btv->vbi_end = end;
882 btv->resources |= bit;
883 mutex_unlock(&btv->lock);
887 mutex_unlock(&btv->lock);
898 int locked_btres(struct bttv *btv, int bit)
900 return (btv->resources & bit);
903 /* Call with btv->lock down. */
905 disclaim_vbi_lines(struct bttv *btv)
907 btv->vbi_end = 0;
910 /* Call with btv->lock down. */
912 disclaim_video_lines(struct bttv *btv)
917 tvnorm = &bttv_tvnorms[btv->tvnorm];
918 btv->crop_start = tvnorm->cropcap.bounds.top
933 void free_btres(struct bttv *btv, struct bttv_fh *fh, int bits)
939 mutex_lock(&btv->lock);
941 btv->resources &= ~bits;
943 bits = btv->resources;
946 disclaim_video_lines(btv);
949 disclaim_vbi_lines(btv);
951 mutex_unlock(&btv->lock);
967 static void set_pll_freq(struct bttv *btv, unsigned int fin, unsigned int fout)
989 static void set_pll(struct bttv *btv)
993 if (!btv->pll.pll_crystal)
996 if (btv->pll.pll_ofreq == btv->pll.pll_current) {
997 dprintk("bttv%d: PLL: no change required\n",btv->c.nr);
1001 if (btv->pll.pll_ifreq == btv->pll.pll_ofreq) {
1003 if (btv->pll.pll_current == 0)
1006 btv->c.nr,btv->pll.pll_ifreq);
1009 btv->pll.pll_current = 0;
1013 bttv_printk(KERN_INFO "bttv%d: PLL: %d => %d ",btv->c.nr,
1014 btv->pll.pll_ifreq, btv->pll.pll_ofreq);
1015 set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq);
1026 btv->pll.pll_current = btv->pll.pll_ofreq;
1031 btv->pll.pll_current = -1;
1037 static void bt848A_set_timing(struct bttv *btv)
1040 int table_idx = bttv_tvnorms[btv->tvnorm].sram;
1041 int fsc = bttv_tvnorms[btv->tvnorm].Fsc;
1043 if (UNSET == bttv_tvcards[btv->c.type].muxsel[btv->input]) {
1045 btv->c.nr,table_idx);
1055 btv->pll.pll_ofreq = 27000000;
1057 set_pll(btv);
1061 btv->pll.pll_ofreq = fsc;
1062 set_pll(btv);
1069 static void bt848_bright(struct bttv *btv, int bright)
1074 btv->bright = bright;
1081 static void bt848_hue(struct bttv *btv, int hue)
1085 btv->hue = hue;
1092 static void bt848_contrast(struct bttv *btv, int cont)
1096 btv->contrast = cont;
1106 static void bt848_sat(struct bttv *btv, int color)
1110 btv->saturation = color;
1113 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7;
1114 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254;
1126 video_mux(struct bttv *btv, unsigned int input)
1130 if (input >= bttv_tvcards[btv->c.type].video_inputs)
1134 mask2 = bttv_tvcards[btv->c.type].gpiomask2;
1138 if (input == btv->svhs) {
1145 mux = bttv_tvcards[btv->c.type].muxsel[input] & 3;
1148 btv->c.nr,input,mux);
1151 if(bttv_tvcards[btv->c.type].muxsel_hook)
1152 bttv_tvcards[btv->c.type].muxsel_hook (btv, input);
1162 audio_mux(struct bttv *btv, int input, int mute)
1168 gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
1169 bttv_tvcards[btv->c.type].gpiomask);
1172 btv->mute = mute;
1173 btv->audio = input;
1176 mute = mute || (btv->opt_automute && !signal && !btv->radio_user);
1179 gpio_val = bttv_tvcards[btv->c.type].gpiomute;
1181 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
1183 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val);
1185 bttv_gpio_tracking(btv, audio_modes[mute ? 4 : input]);
1190 ctrl.value = btv->mute;
1191 bttv_call_i2c_clients(btv, VIDIOC_S_CTRL, &ctrl);
1192 c = btv->i2c_msp34xx_client;
1227 c = btv->i2c_tvaudio_client;
1239 audio_mute(struct bttv *btv, int mute)
1241 return audio_mux(btv, btv->audio, mute);
1245 audio_input(struct bttv *btv, int input)
1247 return audio_mux(btv, input, btv->mute);
1251 i2c_vidiocschan(struct bttv *btv)
1253 v4l2_std_id std = bttv_tvnorms[btv->tvnorm].v4l2_id;
1255 bttv_call_i2c_clients(btv, VIDIOC_S_STD, &std);
1256 if (btv->c.type == BTTV_BOARD_VOODOOTV_FM)
1257 bttv_tda9880_setnorm(btv,btv->tvnorm);
1289 /* Call with btv->lock down. */
1291 set_tvnorm(struct bttv *btv, unsigned int norm)
1300 if (btv->tvnorm < 0 ||
1301 btv->tvnorm >= BTTV_TVNORMS ||
1302 0 != memcmp(&bttv_tvnorms[btv->tvnorm].cropcap,
1305 bttv_crop_reset(&btv->crop[0], norm);
1306 btv->crop[1] = btv->crop[0]; /* current = default */
1308 if (0 == (btv->resources & VIDEO_RESOURCES)) {
1309 btv->crop_start = tvnorm->cropcap.bounds.top
1314 btv->tvnorm = norm;
1322 bt848A_set_timing(btv);
1324 switch (btv->c.type) {
1326 bttv_tda9880_setnorm(btv,norm);
1332 /* Call with btv->lock down. */
1334 set_input(struct bttv *btv, unsigned int input, unsigned int norm)
1338 btv->input = input;
1340 spin_lock_irqsave(&btv->s_lock,flags);
1341 if (btv->curr.frame_irq) {
1343 btv->new_input = input;
1345 video_mux(btv,input);
1347 spin_unlock_irqrestore(&btv->s_lock,flags);
1349 video_mux(btv,input);
1351 audio_input(btv,(input == bttv_tvcards[btv->c.type].tuner ?
1353 set_tvnorm(btv, norm);
1354 i2c_vidiocschan(btv);
1357 static void init_irqreg(struct bttv *btv)
1362 if (bttv_tvcards[btv->c.type].no_video) {
1368 btwrite((btv->triton1) |
1369 (btv->gpioirq ? BT848_INT_GPINT : 0) |
1379 static void init_bt848(struct bttv *btv)
1383 if (bttv_tvcards[btv->c.type].no_video) {
1385 init_irqreg(btv);
1402 val = btv->opt_chroma_agc ? BT848_SCLOOP_CAGC : 0;
1408 btwrite(BT848_ADC_RESERVED | (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0),
1414 if (btv->opt_lumafilter) {
1422 bt848_bright(btv, btv->bright);
1423 bt848_hue(btv, btv->hue);
1424 bt848_contrast(btv, btv->contrast);
1425 bt848_sat(btv, btv->saturation);
1428 init_irqreg(btv);
1431 static void bttv_reinit_bt848(struct bttv *btv)
1436 printk(KERN_INFO "bttv%d: reset, reinitialize\n",btv->c.nr);
1437 spin_lock_irqsave(&btv->s_lock,flags);
1438 btv->errors=0;
1439 bttv_set_dma(btv,0);
1440 spin_unlock_irqrestore(&btv->s_lock,flags);
1442 init_bt848(btv);
1443 btv->pll.pll_current = -1;
1444 set_input(btv, btv->input, btv->tvnorm);
1447 static int get_control(struct bttv *btv, struct v4l2_control *c)
1457 if (btv->audio_hook && i >= 4 && i <= 8) {
1459 btv->audio_hook(btv,&va,0);
1481 c->value = btv->bright;
1484 c->value = btv->hue;
1487 c->value = btv->contrast;
1490 c->value = btv->saturation;
1498 bttv_call_i2c_clients(btv,VIDIOC_G_CTRL,c);
1502 c->value = btv->opt_chroma_agc;
1505 c->value = btv->opt_combfilter;
1508 c->value = btv->opt_lumafilter;
1511 c->value = btv->opt_automute;
1514 c->value = btv->opt_adc_crush;
1517 c->value = btv->opt_vcr_hack;
1520 c->value = btv->opt_whitecrush_upper;
1523 c->value = btv->opt_whitecrush_lower;
1526 c->value = btv->opt_uv_ratio;
1529 c->value = btv->opt_full_luma_range;
1532 c->value = btv->opt_coring;
1540 static int set_control(struct bttv *btv, struct v4l2_control *c)
1550 if (btv->audio_hook && i >= 4 && i <= 8) {
1552 btv->audio_hook(btv,&va,0);
1557 audio_mute(btv, 1);
1560 audio_mute(btv, 0);
1577 btv->audio_hook(btv,&va,1);
1582 bt848_bright(btv,c->value);
1585 bt848_hue(btv,c->value);
1588 bt848_contrast(btv,c->value);
1591 bt848_sat(btv,c->value);
1594 audio_mute(btv, c->value);
1600 bttv_call_i2c_clients(btv,VIDIOC_S_CTRL,c);
1604 btv->opt_chroma_agc = c->value;
1605 val = btv->opt_chroma_agc ? BT848_SCLOOP_CAGC : 0;
1610 btv->opt_combfilter = c->value;
1613 btv->opt_lumafilter = c->value;
1614 if (btv->opt_lumafilter) {
1623 btv->opt_automute = c->value;
1626 btv->opt_adc_crush = c->value;
1627 btwrite(BT848_ADC_RESERVED | (btv->opt_adc_crush ? BT848_ADC_CRUSH : 0),
1631 btv->opt_vcr_hack = c->value;
1634 btv->opt_whitecrush_upper = c->value;
1638 btv->opt_whitecrush_lower = c->value;
1642 btv->opt_uv_ratio = c->value;
1643 bt848_sat(btv, btv->saturation);
1646 btv->opt_full_luma_range = c->value;
1650 btv->opt_coring = c->value;
1661 void bttv_gpio_tracking(struct bttv *btv, char *comment)
1667 btv->c.nr,outbits,data & outbits, data & ~outbits, comment);
1670 static void bttv_field_count(struct bttv *btv)
1674 if (btv->users)
1683 btv->field_count = 0;
1719 bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
1729 spin_lock_irqsave(&btv->s_lock,flags);
1730 old = btv->screen;
1731 btv->screen = new;
1732 btv->loop_irq |= 1;
1733 bttv_set_dma(btv, 0x03);
1734 spin_unlock_irqrestore(&btv->s_lock,flags);
1737 bttv_dma_free(&fh->cap,btv, old);
1741 free_btres(btv,fh,RESOURCE_OVERLAY);
1749 static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1773 mutex_lock(&btv->lock);
1775 norm = btv->tvnorm;
1779 if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) {
1780 mutex_unlock(&btv->lock);
1784 mutex_unlock(&btv->lock);
1788 mutex_lock(&btv->lock);
1790 norm = btv->tvnorm;
1791 c = btv->crop[!!fh->do_crop];
1793 mutex_unlock(&btv->lock);
1804 /* btv->crop counts frame lines. Max. scale
1841 if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf)))
1846 if (0 != (rc = bttv_buffer_risc(btv,buf)))
1853 bttv_dma_free(q,btv,buf);
1877 return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt,
1886 struct bttv *btv = fh->btv;
1889 list_add_tail(&buf->vb.queue,&btv->capture);
1890 if (!btv->curr.frame_irq) {
1891 btv->loop_irq |= 1;
1892 bttv_set_dma(btv, 0x03);
1901 bttv_dma_free(q,fh->btv,buf);
1911 static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1921 *freq = btv->freq;
1930 mutex_lock(&btv->lock);
1931 freq.type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1932 btv->freq = *(unsigned long *)arg;
1933 bttv_call_i2c_clients(btv,VIDIOC_S_FREQUENCY,&freq);
1934 if (btv->has_matchbox && btv->radio_user)
1935 tea5757_set_freq(btv,*(unsigned long *)arg);
1936 mutex_unlock(&btv->lock);
1944 if (UNSET == bttv_tvcards[btv->c.type].tuner)
1952 v->mode = btv->tvnorm;
1954 bttv_call_i2c_clients(btv,cmd,v);
1966 mutex_lock(&btv->lock);
1967 set_tvnorm(btv,v->mode);
1968 bttv_call_i2c_clients(btv,cmd,v);
1969 mutex_unlock(&btv->lock);
1978 if (channel >= bttv_tvcards[btv->c.type].video_inputs)
1983 v->norm = btv->tvnorm;
1984 if (channel == bttv_tvcards[btv->c.type].tuner) {
1989 } else if (channel == btv->svhs) {
2001 if (channel >= bttv_tvcards[btv->c.type].video_inputs)
2006 mutex_lock(&btv->lock);
2007 if (channel == btv->input &&
2008 v->norm == btv->tvnorm) {
2010 mutex_unlock(&btv->lock);
2014 set_input(btv, v->channel, v->norm);
2015 mutex_unlock(&btv->lock);
2028 mutex_lock(&btv->lock);
2029 bttv_call_i2c_clients(btv,cmd,v);
2032 if (btv->audio_hook)
2033 btv->audio_hook(btv,v,0);
2035 mutex_unlock(&btv->lock);
2043 if (audio >= bttv_tvcards[btv->c.type].audio_inputs)
2046 mutex_lock(&btv->lock);
2047 audio_mute(btv, (v->flags&VIDEO_AUDIO_MUTE) ? 1 : 0);
2048 bttv_call_i2c_clients(btv,cmd,v);
2051 if (btv->audio_hook)
2052 btv->audio_hook(btv,v,1);
2054 mutex_unlock(&btv->lock);
2074 *id = bttv_tvnorms[btv->tvnorm].v4l2_id;
2088 mutex_lock(&btv->lock);
2089 set_tvnorm(btv,i);
2090 i2c_vidiocschan(btv);
2091 mutex_unlock(&btv->lock);
2111 if (n >= bttv_tvcards[btv->c.type].video_inputs)
2117 if (i->index == bttv_tvcards[btv->c.type].tuner) {
2121 } else if (i->index == btv->svhs) {
2126 if (i->index == btv->input) {
2140 *i = btv->input;
2147 if (*i > bttv_tvcards[btv->c.type].video_inputs)
2149 mutex_lock(&btv->lock);
2150 set_input(btv, *i, btv->tvnorm);
2151 mutex_unlock(&btv->lock);
2159 if (UNSET == bttv_tvcards[btv->c.type].tuner)
2163 mutex_lock(&btv->lock);
2166 bttv_call_i2c_clients(btv, VIDIOC_G_TUNER, t);
2173 if (btv->audio_hook) {
2177 btv->audio_hook(btv,&va,0);
2190 mutex_unlock(&btv->lock);
2197 if (UNSET == bttv_tvcards[btv->c.type].tuner)
2201 mutex_lock(&btv->lock);
2202 bttv_call_i2c_clients(btv, VIDIOC_S_TUNER, t);
2203 if (btv->audio_hook) {
2215 btv->audio_hook(btv,&va,1);
2217 mutex_unlock(&btv->lock);
2227 f->frequency = btv->freq;
2238 mutex_lock(&btv->lock);
2239 btv->freq = f->frequency;
2240 bttv_call_i2c_clients(btv,VIDIOC_S_FREQUENCY,f);
2241 if (btv->has_matchbox && btv->radio_user)
2242 tea5757_set_freq(btv,btv->freq);
2243 mutex_unlock(&btv->lock);
2248 printk(KERN_INFO "bttv%d: ================= START STATUS CARD #%d =================\n", btv->c.nr, btv->c.nr);
2249 bttv_call_i2c_clients(btv, VIDIOC_LOG_STATUS, NULL);
2250 printk(KERN_INFO "bttv%d: ================== END STATUS CARD #%d ==================\n", btv->c.nr, btv->c.nr);
2321 struct bttv *btv = fh->btv;
2335 mutex_lock(&btv->lock);
2337 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2340 c = &btv->crop[!!fh->do_crop];
2345 && !locked_btres(btv, VIDEO_RESOURCES)) {
2356 Note btv->vbi_end is really a minimum, see
2358 if (btv->vbi_end > b->top) {
2359 max_height -= btv->vbi_end - b->top;
2366 if (btv->vbi_end > c->rect.top)
2395 if (btv->vbi_end > c->rect.top) {
2397 c->rect.top = btv->vbi_end;
2413 mutex_unlock(&btv->lock);
2445 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1;
2491 static int setup_window(struct bttv_fh *fh, struct bttv *btv,
2521 if (NULL != btv->fbuf.base)
2522 n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height,
2550 btv->init.ov.w.width = win->w.width;
2551 btv->init.ov.w.height = win->w.height;
2552 btv->init.ov.field = win->field;
2560 new->crop = btv->crop[!!fh->do_crop].rect;
2561 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2562 retval = bttv_switch_overlay(btv,fh,new);
2658 static int bttv_try_fmt(struct bttv_fh *fh, struct bttv *btv,
2677 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2726 static int bttv_s_fmt(struct bttv_fh *fh, struct bttv *btv,
2739 retval = bttv_try_fmt(fh,btv,f, /* adjust_crop */ 1);
2751 btv->init.fmt = fmt;
2752 btv->init.width = f->fmt.pix.width;
2753 btv->init.height = f->fmt.pix.height;
2763 return setup_window(fh, btv, &f->fmt.win, 1);
2778 struct bttv *btv = fh->btv;
2783 v4l_print_ioctl(btv->c.name, cmd);
2785 if (btv->errors)
2786 bttv_reinit_bt848(btv);
2797 retval = v4l2_prio_check(&btv->prio,&fh->prio);
2810 strcpy(cap->name,btv->video_dev->name);
2823 cap->maxwidth = bttv_tvnorms[btv->tvnorm].swidth;
2824 cap->maxheight = bttv_tvnorms[btv->tvnorm].sheight;
2828 cap->channels = bttv_tvcards[btv->c.type].video_inputs;
2829 cap->audios = bttv_tvcards[btv->c.type].audio_inputs;
2838 pic->brightness = btv->bright;
2839 pic->contrast = btv->contrast;
2840 pic->hue = btv->hue;
2841 pic->colour = btv->saturation;
2867 btv->init.width = RAW_BPL;
2868 btv->init.height = gbufsize / RAW_BPL;
2872 btv->init.ovfmt = fmt;
2873 btv->init.fmt = fmt;
2883 bt848_bright(btv,pic->brightness);
2884 bt848_contrast(btv,pic->contrast);
2885 bt848_hue(btv,pic->hue);
2886 bt848_sat(btv,pic->colour);
2919 retval = setup_window(fh, btv, &w2, 0);
2924 btv->init.width = fh->ov.w.width;
2925 btv->init.height = fh->ov.w.height;
2934 fbuf->base = btv->fbuf.base;
2935 fbuf->width = btv->fbuf.fmt.width;
2936 fbuf->height = btv->fbuf.fmt.height;
2937 fbuf->bytesperline = btv->fbuf.fmt.bytesperline;
2990 btv->init.ovfmt = fmt;
2991 btv->init.fmt = fmt;
2992 btv->fbuf.base = fbuf->base;
2993 btv->fbuf.fmt.width = fbuf->width;
2994 btv->fbuf.fmt.height = fbuf->height;
2996 btv->fbuf.fmt.bytesperline = fbuf->bytesperline;
2998 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fbuf->depth/8;
3011 if (NULL == btv->fbuf.base)
3014 dprintk("bttv%d: overlay: !setup_ok\n",btv->c.nr);
3019 if (!check_alloc_btres(btv,fh,RESOURCE_OVERLAY))
3024 fh->ov.tvnorm = btv->tvnorm;
3026 new->crop = btv->crop[!!fh->do_crop].rect;
3027 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
3033 retval = bttv_switch_overlay(btv,fh,new);
3068 if (!check_alloc_btres(btv, fh, res))
3082 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
3086 retval = bttv_prepare_buffer(&fh->cap,btv,buf,
3091 spin_lock_irqsave(&btv->s_lock,flags);
3093 spin_unlock_irqrestore(&btv->s_lock,flags);
3119 bttv_dma_free(&fh->cap,btv,buf);
3151 return bttv_common_ioctls(btv,cmd,arg);
3162 strlcpy(cap->card, btv->video_dev->name, sizeof (cap->card));
3164 "PCI:%s", pci_name(btv->c.pci));
3174 if (bttv_tvcards[btv->c.type].tuner != UNSET &&
3175 bttv_tvcards[btv->c.type].tuner != TUNER_ABSENT)
3233 return bttv_try_fmt(fh,btv,f, /* adjust_crop */ 0);
3243 return bttv_s_fmt(fh,btv,f);
3250 *fb = btv->fbuf;
3289 btv->fbuf.base = fb->base;
3290 btv->fbuf.fmt.width = fb->fmt.width;
3291 btv->fbuf.fmt.height = fb->fmt.height;
3293 btv->fbuf.fmt.bytesperline = fb->fmt.bytesperline;
3295 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8;
3299 btv->init.ovfmt = fmt;
3305 btv->init.ov.w.width = fb->fmt.width;
3306 btv->init.ov.w.height = fb->fmt.height;
3315 new->crop = btv->crop[!!fh->do_crop].rect;
3316 bttv_overlay_risc(btv,&fh->ov,fh->ovfmt,new);
3317 retval = bttv_switch_overlay(btv,fh,new);
3334 if (!check_alloc_btres(btv, fh, res))
3347 if (!check_alloc_btres(btv,fh,res))
3358 free_btres(btv,fh,res);
3380 if (btv->audio_hook && i >= 4 && i <= 8) {
3383 btv->audio_hook(btv,&va,0);
3406 return get_control(btv,arg);
3408 return set_control(btv,arg);
3416 v4l2_video_std_construct(&s, bttv_tvnorms[btv->tvnorm].v4l2_id,
3417 bttv_tvnorms[btv->tvnorm].name);
3426 *p = v4l2_prio_max(&btv->prio);
3433 return v4l2_prio_change(&btv->prio, &fh->prio, *prio);
3447 *cap = bttv_tvnorms[btv->tvnorm].cropcap;
3460 /* No fh->do_crop = 1; because btv->crop[1] may be
3464 crop->c = btv->crop[!!fh->do_crop].rect;
3482 retval = v4l2_prio_check(&btv->prio,&fh->prio);
3489 mutex_lock(&btv->lock);
3493 if (locked_btres(fh->btv, VIDEO_RESOURCES))
3496 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
3502 b_top = max(b->top, btv->vbi_end);
3523 btv->crop[1] = c;
3525 mutex_unlock(&btv->lock);
3533 btv->init.width = c.min_scaled_width;
3536 btv->init.width = c.max_scaled_width;
3541 btv->init.height = c.min_scaled_height;
3544 btv->init.height = c.max_scaled_height;
3563 return bttv_common_ioctls(btv,cmd,arg);
3575 mutex_unlock(&btv->lock);
3617 if (fh->btv->errors)
3618 bttv_reinit_bt848(fh->btv);
3620 fh->btv->c.nr,(int)count,v4l2_type_names[fh->type]);
3624 if (!check_alloc_btres(fh->btv, fh, RESOURCE_VIDEO_READ)) {
3631 free_btres(fh->btv, fh, RESOURCE_VIDEO_READ);
3634 if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI))
3652 if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI))
3667 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM)) {
3701 struct bttv *btv = NULL;
3711 btv = &bttvs[i];
3717 btv = &bttvs[i];
3722 if (NULL == btv)
3726 btv->c.nr,v4l2_type_names[type]);
3733 *fh = btv->init;
3736 v4l2_prio_open(&btv->prio,&fh->prio);
3739 btv->c.pci, &btv->s_lock,
3745 btv->c.pci, &btv->s_lock,
3750 i2c_vidiocschan(btv);
3752 btv->users++;
3755 which only change on request. These are stored in btv->crop[1].
3759 will use btv->crop[0], the default cropping parameters for the
3768 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);
3770 bttv_field_count(btv);
3777 struct bttv *btv = fh->btv;
3781 bttv_switch_overlay(btv,fh,NULL);
3786 free_btres(btv,fh,RESOURCE_VIDEO_STREAM);
3793 free_btres(btv, fh, RESOURCE_VIDEO_READ);
3802 free_btres(btv,fh,RESOURCE_VBI);
3808 v4l2_prio_close(&btv->prio,&fh->prio);
3812 btv->users--;
3813 bttv_field_count(btv);
3823 fh->btv->c.nr, v4l2_type_names[fh->type],
3866 struct bttv *btv = NULL;
3873 btv = &bttvs[i];
3877 if (NULL == btv)
3880 dprintk("bttv%d: open called (radio)\n",btv->c.nr);
3881 mutex_lock(&btv->lock);
3883 btv->radio_user++;
3885 file->private_data = btv;
3887 bttv_call_i2c_clients(btv,AUDC_SET_RADIO,NULL);
3888 audio_input(btv,TVAUDIO_INPUT_RADIO);
3890 mutex_unlock(&btv->lock);
3896 struct bttv *btv = file->private_data;
3899 btv->radio_user--;
3901 bttv_call_i2c_clients(btv, RDS_CMD_CLOSE, &cmd);
3909 struct bttv *btv = file->private_data;
3917 strcpy(cap->name,btv->radio_dev->name);
3932 bttv_call_i2c_clients(btv,cmd,v);
3945 return bttv_common_ioctls(btv,cmd,arg);
3962 struct bttv *btv = file->private_data;
3969 bttv_call_i2c_clients(btv, RDS_CMD_READ, &cmd);
3976 struct bttv *btv = file->private_data;
3981 bttv_call_i2c_clients(btv, RDS_CMD_POLL, &cmd);
4046 static void bttv_risc_disasm(struct bttv *btv,
4052 btv->c.name, risc->cpu, (unsigned long)risc->dma);
4054 printk("%s: 0x%lx: ", btv->c.name,
4059 btv->c.name, (unsigned long)(risc->dma + ((i+j)<<2)),
4066 static void bttv_print_riscaddr(struct bttv *btv)
4069 (unsigned long long)btv->main.dma);
4071 btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0,
4072 btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0);
4074 btv->curr.top ? (unsigned long long)btv->curr.top->top.dma : 0,
4075 btv->curr.bottom ? (unsigned long long)btv->curr.bottom->bottom.dma : 0);
4077 btv->screen ? (unsigned long long)btv->screen->top.dma : 0,
4078 btv->screen ? (unsigned long long)btv->screen->bottom.dma : 0);
4079 bttv_risc_disasm(btv, &btv->main);
4120 static void bttv_irq_debug_low_latency(struct bttv *btv, u32 rc)
4123 btv->c.nr,
4124 (unsigned long)btv->main.dma,
4125 (unsigned long)btv->main.cpu[RISC_SLOT_O_VBI+1],
4126 (unsigned long)btv->main.cpu[RISC_SLOT_O_FIELD+1],
4132 btv->c.nr);
4136 btv->c.nr);
4138 btv->c.nr);
4143 bttv_irq_next_video(struct bttv *btv, struct bttv_buffer_set *set)
4150 if (!list_empty(&btv->capture)) {
4152 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue);
4160 (item->vb.queue.next != &btv->capture)) {
4178 if (NULL != btv->screen) {
4179 if (V4L2_FIELD_HAS_BOTH(btv->screen->vb.field)) {
4181 set->top = btv->screen;
4182 set->bottom = btv->screen;
4185 if (V4L2_FIELD_TOP == btv->screen->vb.field &&
4187 set->top = btv->screen;
4189 if (V4L2_FIELD_BOTTOM == btv->screen->vb.field &&
4191 set->bottom = btv->screen;
4197 btv->c.nr,set->top, set->bottom,
4198 btv->screen,set->frame_irq,set->top_irq);
4203 bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
4213 printk("bttv%d: wakeup: both=%p\n",btv->c.nr,wakeup->top);
4215 wakeup->top->vb.field_count = btv->field_count;
4222 printk("bttv%d: wakeup: top=%p\n",btv->c.nr,wakeup->top);
4224 wakeup->top->vb.field_count = btv->field_count;
4230 printk("bttv%d: wakeup: bottom=%p\n",btv->c.nr,wakeup->bottom);
4232 wakeup->bottom->vb.field_count = btv->field_count;
4240 bttv_irq_wakeup_vbi(struct bttv *btv, struct bttv_buffer *wakeup,
4250 wakeup->vb.field_count = btv->field_count;
4257 struct bttv *btv = (struct bttv *)data;
4265 btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total,
4271 spin_lock_irqsave(&btv->s_lock,flags);
4275 old = btv->curr;
4276 ovbi = btv->cvbi;
4277 btv->curr = new;
4278 btv->cvbi = NULL;
4279 btv->loop_irq = 0;
4280 bttv_buffer_activate_video(btv, &new);
4281 bttv_buffer_activate_vbi(btv, NULL);
4282 bttv_set_dma(btv, 0);
4285 bttv_irq_wakeup_video(btv, &old, &new, STATE_ERROR);
4286 bttv_irq_wakeup_vbi(btv, ovbi, STATE_ERROR);
4289 while (!list_empty(&btv->capture)) {
4290 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue);
4295 while (!list_empty(&btv->vcapture)) {
4296 item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue);
4302 btv->errors++;
4303 spin_unlock_irqrestore(&btv->s_lock,flags);
4307 bttv_irq_wakeup_top(struct bttv *btv)
4309 struct bttv_buffer *wakeup = btv->curr.top;
4314 spin_lock(&btv->s_lock);
4315 btv->curr.top_irq = 0;
4316 btv->curr.top = NULL;
4317 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
4320 wakeup->vb.field_count = btv->field_count;
4323 spin_unlock(&btv->s_lock);
4336 bttv_irq_switch_video(struct bttv *btv)
4342 spin_lock(&btv->s_lock);
4345 bttv_irq_next_video(btv, &new);
4347 if ((btv->curr.top && is_active(&btv->curr.top->top, rc)) ||
4348 (btv->curr.bottom && is_active(&btv->curr.bottom->bottom, rc))) {
4349 btv->framedrop++;
4351 bttv_irq_debug_low_latency(btv, rc);
4352 spin_unlock(&btv->s_lock);
4357 old = btv->curr;
4358 btv->curr = new;
4359 btv->loop_irq &= ~1;
4360 bttv_buffer_activate_video(btv, &new);
4361 bttv_set_dma(btv, 0);
4364 if (UNSET != btv->new_input) {
4365 video_mux(btv,btv->new_input);
4366 btv->new_input = UNSET;
4370 bttv_irq_wakeup_video(btv, &old, &new, STATE_DONE);
4371 spin_unlock(&btv->s_lock);
4375 bttv_irq_switch_vbi(struct bttv *btv)
4381 spin_lock(&btv->s_lock);
4383 if (!list_empty(&btv->vcapture))
4384 new = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue);
4385 old = btv->cvbi;
4390 btv->framedrop++;
4392 bttv_irq_debug_low_latency(btv, rc);
4393 spin_unlock(&btv->s_lock);
4398 btv->cvbi = new;
4399 btv->loop_irq &= ~4;
4400 bttv_buffer_activate_vbi(btv, new);
4401 bttv_set_dma(btv, 0);
4403 bttv_irq_wakeup_vbi(btv, old, STATE_DONE);
4404 spin_unlock(&btv->s_lock);
4412 struct bttv *btv;
4415 btv=(struct bttv *)dev_id;
4417 if (btv->custom_irq)
4418 handled = btv->custom_irq(btv);
4436 btv->c.nr, count, btv->field_count,
4452 btv->field_count++;
4454 if ((astat & BT848_INT_GPINT) && btv->remote) {
4455 wake_up(&btv->gpioq);
4456 bttv_input_irq(btv);
4460 btv->i2c_done = stat;
4461 wake_up(&btv->i2c_queue);
4465 bttv_irq_switch_vbi(btv);
4468 bttv_irq_wakeup_top(btv);
4471 bttv_irq_switch_video(btv);
4473 if ((astat & BT848_INT_HLOCK) && btv->opt_automute)
4474 audio_mute(btv, btv->mute); /* trigger automute */
4477 printk(KERN_INFO "bttv%d: %s%s @ %08x,",btv->c.nr,
4484 bttv_print_riscaddr(btv);
4488 btv->c.nr,btread(BT848_RISC_COUNT));
4490 bttv_print_riscaddr(btv);
4500 "bttv%d: IRQ lockup, cleared int mask [", btv->c.nr);
4503 "bttv%d: IRQ lockup, clearing GPINT from int mask [", btv->c.nr);
4514 btv->irq_total++;
4516 btv->irq_me++;
4524 static struct video_device *vdev_init(struct bttv *btv,
4535 vfd->dev = &btv->c.pci->dev;
4538 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
4539 type, bttv_tvcards[btv->c.type].name);
4543 static void bttv_unregister_video(struct bttv *btv)
4545 if (btv->video_dev) {
4546 if (-1 != btv->video_dev->minor)
4547 video_unregister_device(btv->video_dev);
4549 video_device_release(btv->video_dev);
4550 btv->video_dev = NULL;
4552 if (btv->vbi_dev) {
4553 if (-1 != btv->vbi_dev->minor)
4554 video_unregister_device(btv->vbi_dev);
4556 video_device_release(btv->vbi_dev);
4557 btv->vbi_dev = NULL;
4559 if (btv->radio_dev) {
4560 if (-1 != btv->radio_dev->minor)
4561 video_unregister_device(btv->radio_dev);
4563 video_device_release(btv->radio_dev);
4564 btv->radio_dev = NULL;
4569 static int __devinit bttv_register_video(struct bttv *btv)
4578 btv->video_dev = vdev_init(btv, &bttv_video_template, "video");
4579 if (NULL == btv->video_dev)
4581 if (video_register_device(btv->video_dev,VFL_TYPE_GRABBER,video_nr)<0)
4584 btv->c.nr,btv->video_dev->minor & 0x1f);
4585 if (class_device_create_file(&btv->video_dev->class_dev,
4588 "failed\n", btv->c.nr);
4593 btv->vbi_dev = vdev_init(btv, &bttv_vbi_template, "vbi");
4594 if (NULL == btv->vbi_dev)
4596 if (video_register_device(btv->vbi_dev,VFL_TYPE_VBI,vbi_nr)<0)
4599 btv->c.nr,btv->vbi_dev->minor & 0x1f);
4601 if (!btv->has_radio)
4604 btv->radio_dev = vdev_init(btv, &radio_template, "radio");
4605 if (NULL == btv->radio_dev)
4607 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,radio_nr)<0)
4610 btv->c.nr,btv->radio_dev->minor & 0x1f);
4616 bttv_unregister_video(btv);
4639 struct bttv *btv;
4644 btv=&bttvs[bttv_num];
4645 memset(btv,0,sizeof(*btv));
4646 btv->c.nr = bttv_num;
4647 sprintf(btv->c.name,"bttv%d",btv->c.nr);
4650 mutex_init(&btv->lock);
4651 spin_lock_init(&btv->s_lock);
4652 spin_lock_init(&btv->gpio_lock);
4653 init_waitqueue_head(&btv->gpioq);
4654 init_waitqueue_head(&btv->i2c_queue);
4655 INIT_LIST_HEAD(&btv->c.subs);
4656 INIT_LIST_HEAD(&btv->capture);
4657 INIT_LIST_HEAD(&btv->vcapture);
4658 v4l2_prio_init(&btv->prio);
4660 init_timer(&btv->timeout);
4661 btv->timeout.function = bttv_irq_timeout;
4662 btv->timeout.data = (unsigned long)btv;
4664 btv->i2c_rc = -1;
4665 btv->tuner_type = UNSET;
4666 btv->new_input = UNSET;
4667 btv->has_radio=radio[btv->c.nr];
4670 btv->c.pci = dev;
4671 btv->id = dev->device;
4674 btv->c.nr);
4679 btv->c.nr);
4684 btv->c.name)) {
4686 btv->c.nr,
4692 pci_set_drvdata(dev,btv);
4694 pci_read_config_byte(dev, PCI_CLASS_REVISION, &btv->revision);
4697 bttv_num,btv->id, btv->revision, pci_name(dev));
4699 btv->c.pci->irq, lat,
4703 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
4704 if (NULL == btv->bt848_mmio) {
4705 printk("bttv%d: ioremap() failed\n", btv->c.nr);
4711 bttv_idcard(btv);
4715 result = request_irq(btv->c.pci->irq, bttv_irq,
4716 IRQF_SHARED | IRQF_DISABLED,btv->c.name,(void *)btv);
4719 bttv_num,btv->c.pci->irq);
4723 if (0 != bttv_handle_chipset(btv)) {
4729 btv->opt_combfilter = combfilter;
4730 btv->opt_lumafilter = lumafilter;
4731 btv->opt_automute = automute;
4732 btv->opt_chroma_agc = chroma_agc;
4733 btv->opt_adc_crush = adc_crush;
4734 btv->opt_vcr_hack = vcr_hack;
4735 btv->opt_whitecrush_upper = whitecrush_upper;
4736 btv->opt_whitecrush_lower = whitecrush_lower;
4737 btv->opt_uv_ratio = uv_ratio;
4738 btv->opt_full_luma_range = full_luma_range;
4739 btv->opt_coring = coring;
4742 btv->init.btv = btv;
4743 btv->init.ov.w.width = 320;
4744 btv->init.ov.w.height = 240;
4745 btv->init.fmt = format_by_palette(VIDEO_PALETTE_RGB24);
4746 btv->init.width = 320;
4747 btv->init.height = 240;
4748 btv->input = 0;
4752 bttv_gpio_tracking(btv,"pre-init");
4754 bttv_risc_init_main(btv);
4755 init_bt848(btv);
4761 bttv_gpio_tracking(btv,"init");
4764 bttv_init_card1(btv);
4767 init_bttv_i2c(btv);
4770 bttv_init_card2(btv);
4771 init_irqreg(btv);
4774 if (!bttv_tvcards[btv->c.type].no_video) {
4775 bttv_register_video(btv);
4776 bt848_bright(btv,32768);
4777 bt848_contrast(btv,32768);
4778 bt848_hue(btv,32768);
4779 bt848_sat(btv,32768);
4780 audio_mute(btv, 1);
4781 set_input(btv, 0, btv->tvnorm);
4782 bttv_crop_reset(&btv->crop[0], btv->tvnorm);
4783 btv->crop[1] = btv->crop[0]; /* current = default */
4784 disclaim_vbi_lines(btv);
4785 disclaim_video_lines(btv);
4789 if (bttv_tvcards[btv->c.type].has_dvb) {
4790 bttv_sub_add_device(&btv->c, "dvb");
4791 request_modules(btv);
4794 bttv_input_init(btv);
4801 free_irq(btv->c.pci->irq,btv);
4804 if (btv->bt848_mmio)
4805 iounmap(btv->bt848_mmio);
4806 release_mem_region(pci_resource_start(btv->c.pci,0),
4807 pci_resource_len(btv->c.pci,0));
4814 struct bttv *btv = pci_get_drvdata(pci_dev);
4817 printk("bttv%d: unloading\n",btv->c.nr);
4825 bttv_gpio_tracking(btv,"cleanup");
4828 btv->shutdown=1;
4829 wake_up(&btv->gpioq);
4830 bttv_input_fini(btv);
4831 bttv_sub_del_devices(&btv->c);
4834 fini_bttv_i2c(btv);
4837 bttv_unregister_video(btv);
4840 btcx_riscmem_free(btv->c.pci,&btv->main);
4843 free_irq(btv->c.pci->irq,btv);
4844 iounmap(btv->bt848_mmio);
4845 release_mem_region(pci_resource_start(btv->c.pci,0),
4846 pci_resource_len(btv->c.pci,0));
4855 struct bttv *btv = pci_get_drvdata(pci_dev);
4859 dprintk("bttv%d: suspend %d\n", btv->c.nr, state.event);
4862 spin_lock_irqsave(&btv->s_lock,flags);
4864 btv->state.video = btv->curr;
4865 btv->state.vbi = btv->cvbi;
4866 btv->state.loop_irq = btv->loop_irq;
4867 btv->curr = idle;
4868 btv->loop_irq = 0;
4869 bttv_buffer_activate_video(btv, &idle);
4870 bttv_buffer_activate_vbi(btv, NULL);
4871 bttv_set_dma(btv, 0);
4873 spin_unlock_irqrestore(&btv->s_lock,flags);
4876 btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN);
4877 btv->state.gpio_data = gpio_read();
4883 btv->state.disabled = 1;
4890 struct bttv *btv = pci_get_drvdata(pci_dev);
4894 dprintk("bttv%d: resume\n", btv->c.nr);
4897 if (btv->state.disabled) {
4901 btv->c.nr);
4904 btv->state.disabled = 0;
4910 btv->c.nr);
4911 btv->state.disabled = 1;
4918 bttv_reinit_bt848(btv);
4919 gpio_inout(0xffffff, btv->state.gpio_enable);
4920 gpio_write(btv->state.gpio_data);
4923 spin_lock_irqsave(&btv->s_lock,flags);
4924 btv->curr = btv->state.video;
4925 btv->cvbi = btv->state.vbi;
4926 btv->loop_irq = btv->state.loop_irq;
4927 bttv_buffer_activate_video(btv, &btv->curr);
4928 bttv_buffer_activate_vbi(btv, btv->cvbi);
4929 bttv_set_dma(btv, 0);
4930 spin_unlock_irqrestore(&btv->s_lock,flags);