Lines Matching defs:btv
177 struct bttv *btv = video_get_drvdata(vfd);
178 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
652 int check_alloc_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bit)
665 if (btv->resources & xbits) {
671 && 0 == (btv->resources & VIDEO_RESOURCES)) {
673 __s32 top = btv->crop[!!fh->do_crop].rect.top;
675 if (btv->vbi_end > top)
680 btv->crop_start = top;
684 if (end > btv->crop_start)
688 btv->vbi_end = end;
693 btv->resources |= bit;
707 int locked_btres(struct bttv *btv, int bit)
709 return (btv->resources & bit);
712 /* Call with btv->lock down. */
714 disclaim_vbi_lines(struct bttv *btv)
716 btv->vbi_end = 0;
719 /* Call with btv->lock down. */
721 disclaim_video_lines(struct bttv *btv)
726 tvnorm = &bttv_tvnorms[btv->tvnorm];
727 btv->crop_start = tvnorm->cropcap.bounds.top
742 void free_btres_lock(struct bttv *btv, struct bttv_fh *fh, int bits)
749 btv->resources &= ~bits;
751 bits = btv->resources;
754 disclaim_video_lines(btv);
757 disclaim_vbi_lines(btv);
773 static void set_pll_freq(struct bttv *btv, unsigned int fin, unsigned int fout)
795 static void set_pll(struct bttv *btv)
799 if (!btv->pll.pll_crystal)
802 if (btv->pll.pll_ofreq == btv->pll.pll_current) {
803 dprintk("%d: PLL: no change required\n", btv->c.nr);
807 if (btv->pll.pll_ifreq == btv->pll.pll_ofreq) {
809 if (btv->pll.pll_current == 0)
813 btv->c.nr, btv->pll.pll_ifreq);
816 btv->pll.pll_current = 0;
822 btv->c.nr,
823 btv->pll.pll_ifreq, btv->pll.pll_ofreq);
824 set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq);
834 btv->pll.pll_current = btv->pll.pll_ofreq;
840 btv->pll.pll_current = -1;
847 static void bt848A_set_timing(struct bttv *btv)
850 int table_idx = bttv_tvnorms[btv->tvnorm].sram;
851 int fsc = bttv_tvnorms[btv->tvnorm].Fsc;
853 if (btv->input == btv->dig) {
855 btv->c.nr,table_idx);
865 btv->pll.pll_ofreq = 27000000;
867 set_pll(btv);
871 btv->pll.pll_ofreq = fsc;
872 set_pll(btv);
879 static void bt848_bright(struct bttv *btv, int bright)
884 btv->bright = bright;
891 static void bt848_hue(struct bttv *btv, int hue)
895 btv->hue = hue;
902 static void bt848_contrast(struct bttv *btv, int cont)
906 btv->contrast = cont;
916 static void bt848_sat(struct bttv *btv, int color)
920 btv->saturation = color;
923 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7;
924 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254;
936 video_mux(struct bttv *btv, unsigned int input)
940 if (input >= bttv_tvcards[btv->c.type].video_inputs)
944 mask2 = bttv_tvcards[btv->c.type].gpiomask2;
948 if (input == btv->svhs) {
955 mux = bttv_muxsel(btv, input);
957 dprintk("%d: video mux: input=%d mux=%d\n", btv->c.nr, input, mux);
960 if(bttv_tvcards[btv->c.type].muxsel_hook)
961 bttv_tvcards[btv->c.type].muxsel_hook (btv, input);
971 audio_mux_gpio(struct bttv *btv, int input, int mute)
975 gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
976 bttv_tvcards[btv->c.type].gpiomask);
980 mute_gpio = mute || (btv->opt_automute && (!signal || !btv->users)
981 && !btv->has_radio_tuner);
984 gpio_val = bttv_tvcards[btv->c.type].gpiomute;
986 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
988 switch (btv->c.type) {
991 gpio_val = bttv_tda9880_setnorm(btv, gpio_val);
995 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val);
999 bttv_gpio_tracking(btv, audio_modes[mute_gpio ? 4 : input]);
1003 audio_mute(struct bttv *btv, int mute)
1007 audio_mux_gpio(btv, btv->audio_input, mute);
1009 if (btv->sd_msp34xx) {
1010 ctrl = v4l2_ctrl_find(btv->sd_msp34xx->ctrl_handler, V4L2_CID_AUDIO_MUTE);
1014 if (btv->sd_tvaudio) {
1015 ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE);
1019 if (btv->sd_tda7432) {
1020 ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE);
1028 audio_input(struct bttv *btv, int input)
1030 audio_mux_gpio(btv, input, btv->mute);
1032 if (btv->sd_msp34xx) {
1043 if (btv->radio_uses_msp_demodulator) {
1068 if (btv->c.type == BTTV_BOARD_VOODOOTV_200)
1075 v4l2_subdev_call(btv->sd_msp34xx, audio, s_routing,
1078 if (btv->sd_tvaudio) {
1079 v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing,
1114 /* Call with btv->lock down. */
1116 set_tvnorm(struct bttv *btv, unsigned int norm)
1122 BUG_ON(btv->tvnorm >= BTTV_TVNORMS);
1126 if (memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap,
1128 bttv_crop_reset(&btv->crop[0], norm);
1129 btv->crop[1] = btv->crop[0]; /* current = default */
1131 if (0 == (btv->resources & VIDEO_RESOURCES)) {
1132 btv->crop_start = tvnorm->cropcap.bounds.top
1137 btv->tvnorm = norm;
1145 bt848A_set_timing(btv);
1147 switch (btv->c.type) {
1150 bttv_tda9880_setnorm(btv, gpio_read());
1154 bttv_call_all(btv, video, s_std, id);
1159 /* Call with btv->lock down. */
1161 set_input(struct bttv *btv, unsigned int input, unsigned int norm)
1165 btv->input = input;
1167 spin_lock_irqsave(&btv->s_lock,flags);
1168 if (btv->curr.frame_irq) {
1170 btv->new_input = input;
1172 video_mux(btv,input);
1174 spin_unlock_irqrestore(&btv->s_lock,flags);
1176 video_mux(btv,input);
1178 btv->audio_input = (btv->tuner_type != TUNER_ABSENT && input == 0) ?
1180 audio_input(btv, btv->audio_input);
1181 set_tvnorm(btv, norm);
1184 static void init_irqreg(struct bttv *btv)
1189 if (bttv_tvcards[btv->c.type].no_video) {
1195 btwrite((btv->triton1) |
1196 (btv->gpioirq ? BT848_INT_GPINT : 0) |
1206 static void init_bt848(struct bttv *btv)
1208 if (bttv_tvcards[btv->c.type].no_video) {
1210 init_irqreg(btv);
1230 v4l2_ctrl_handler_setup(&btv->ctrl_handler);
1233 init_irqreg(btv);
1236 static void bttv_reinit_bt848(struct bttv *btv)
1241 pr_info("%d: reset, reinitialize\n", btv->c.nr);
1242 spin_lock_irqsave(&btv->s_lock,flags);
1243 btv->errors=0;
1244 bttv_set_dma(btv,0);
1245 spin_unlock_irqrestore(&btv->s_lock,flags);
1247 init_bt848(btv);
1248 btv->pll.pll_current = -1;
1249 set_input(btv, btv->input, btv->tvnorm);
1254 struct bttv *btv = container_of(c->handler, struct bttv, ctrl_handler);
1259 bt848_bright(btv, c->val);
1262 bt848_hue(btv, c->val);
1265 bt848_contrast(btv, c->val);
1268 bt848_sat(btv, c->val);
1280 audio_mute(btv, c->val);
1281 btv->mute = c->val;
1284 btv->volume_gpio(btv, c->val);
1293 btv->opt_combfilter = c->val;
1305 btv->opt_automute = c->val;
1313 btv->opt_vcr_hack = c->val;
1322 btv->opt_uv_ratio = c->val;
1323 bt848_sat(btv, btv->saturation);
1454 void bttv_gpio_tracking(struct bttv *btv, char *comment)
1460 btv->c.nr, outbits, data & outbits, data & ~outbits, comment);
1463 static void bttv_field_count(struct bttv *btv)
1467 if (btv->users)
1476 btv->field_count = 0;
1498 bttv_switch_overlay(struct bttv *btv, struct bttv_fh *fh,
1507 spin_lock_irqsave(&btv->s_lock,flags);
1508 old = btv->screen;
1509 btv->screen = new;
1510 btv->loop_irq |= 1;
1511 bttv_set_dma(btv, 0x03);
1512 spin_unlock_irqrestore(&btv->s_lock,flags);
1516 bttv_dma_free(&fh->cap,btv, old);
1520 free_btres_lock(btv,fh,RESOURCE_OVERLAY);
1528 static int bttv_prepare_buffer(struct videobuf_queue *q,struct bttv *btv,
1553 norm = btv->tvnorm;
1557 if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) {
1563 norm = btv->tvnorm;
1564 c = btv->crop[!!fh->do_crop];
1575 /* btv->crop counts frame lines. Max. scale
1612 if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf)))
1617 if (0 != (rc = bttv_buffer_risc(btv,buf)))
1624 bttv_dma_free(q,btv,buf);
1648 return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt,
1657 struct bttv *btv = fh->btv;
1660 list_add_tail(&buf->vb.queue,&btv->capture);
1661 if (!btv->curr.frame_irq) {
1662 btv->loop_irq |= 1;
1663 bttv_set_dma(btv, 0x03);
1672 bttv_dma_free(q,fh->btv,buf);
1682 static void radio_enable(struct bttv *btv)
1685 if (!btv->has_radio_tuner) {
1686 btv->has_radio_tuner = 1;
1687 bttv_call_all(btv, tuner, s_radio);
1688 btv->audio_input = TVAUDIO_INPUT_RADIO;
1689 audio_input(btv, btv->audio_input);
1696 struct bttv *btv = fh->btv;
1704 btv->std = id;
1705 set_tvnorm(btv, i);
1712 struct bttv *btv = fh->btv;
1714 *id = btv->std;
1721 struct bttv *btv = fh->btv;
1734 struct bttv *btv = fh->btv;
1736 if (i->index >= bttv_tvcards[btv->c.type].video_inputs)
1742 if (btv->tuner_type != TUNER_ABSENT && i->index == 0) {
1746 } else if (i->index == btv->svhs) {
1752 if (i->index == btv->input) {
1767 struct bttv *btv = fh->btv;
1769 *i = btv->input;
1777 struct bttv *btv = fh->btv;
1779 if (i >= bttv_tvcards[btv->c.type].video_inputs)
1782 set_input(btv, i, btv->tvnorm);
1790 struct bttv *btv = fh->btv;
1795 bttv_call_all(btv, tuner, s_tuner, t);
1797 if (btv->audio_mode_gpio) {
1800 btv->audio_mode_gpio(btv, ©, 1);
1809 struct bttv *btv = fh->btv;
1815 radio_enable(btv);
1817 btv->radio_freq : btv->tv_freq;
1822 static void bttv_set_frequency(struct bttv *btv, const struct v4l2_frequency *f)
1826 bttv_call_all(btv, tuner, s_frequency, f);
1829 bttv_call_all(btv, tuner, g_frequency, &new_freq);
1831 radio_enable(btv);
1832 btv->radio_freq = new_freq.frequency;
1833 if (btv->has_tea575x) {
1834 btv->tea.freq = btv->radio_freq;
1835 snd_tea575x_set_freq(&btv->tea);
1838 btv->tv_freq = new_freq.frequency;
1846 struct bttv *btv = fh->btv;
1851 bttv_set_frequency(btv, f);
1859 struct bttv *btv = fh->btv;
1861 v4l2_ctrl_handler_log_status(vdev->ctrl_handler, btv->c.v4l2_dev.name);
1862 bttv_call_all(btv, core, log_status);
1871 struct bttv *btv = fh->btv;
1885 struct bttv *btv = fh->btv;
1954 struct bttv *btv = fh->btv;
1969 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
1972 c = &btv->crop[!!fh->do_crop];
1977 && !locked_btres(btv, VIDEO_RESOURCES)) {
1988 Note btv->vbi_end is really a minimum, see
1990 if (btv->vbi_end > b->top) {
1991 max_height -= btv->vbi_end - b->top;
1998 if (btv->vbi_end > c->rect.top)
2026 if (btv->vbi_end > c->rect.top) {
2028 c->rect.top = btv->vbi_end;
2086 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1;
2123 static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv,
2154 if (NULL != btv->fbuf.base)
2155 n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height,
2183 btv->init.ov.w.width = win->w.width;
2184 btv->init.ov.w.height = win->w.height;
2185 btv->init.ov.field = win->field;
2193 new->crop = btv->crop[!!fh->do_crop].rect;
2194 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2195 retval = bttv_switch_overlay(btv,fh,new);
2310 struct bttv *btv = fh->btv;
2337 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2380 struct bttv *btv = fh->btv;
2414 btv->init.fmt = fmt;
2415 btv->init.width = f->fmt.pix.width;
2416 btv->init.height = f->fmt.pix.height;
2425 struct bttv *btv = fh->btv;
2432 return setup_window_lock(fh, btv, &f->fmt.win, 1);
2439 struct bttv *btv = fh->btv;
2445 strscpy(cap->card, btv->video_dev.name, sizeof(cap->card));
2447 "PCI:%s", pci_name(btv->c.pci));
2452 if (video_is_registered(&btv->vbi_dev))
2454 if (video_is_registered(&btv->radio_dev)) {
2456 if (btv->has_tea575x)
2464 if (btv->has_saa6588)
2466 if (btv->tuner_type != TUNER_ABSENT)
2525 struct bttv *btv = fh->btv;
2527 *fb = btv->fbuf;
2538 struct bttv *btv = fh->btv;
2544 if (unlikely(!btv->fbuf.base)) {
2548 dprintk("%d: overlay: !setup_ok\n", btv->c.nr);
2555 if (!check_alloc_btres_lock(btv, fh, RESOURCE_OVERLAY))
2559 fh->ov.tvnorm = btv->tvnorm;
2561 new->crop = btv->crop[!!fh->do_crop].rect;
2562 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2568 retval = bttv_switch_overlay(btv, fh, new);
2576 struct bttv *btv = fh->btv;
2607 btv->fbuf.base = fb->base;
2608 btv->fbuf.fmt.width = fb->fmt.width;
2609 btv->fbuf.fmt.height = fb->fmt.height;
2611 btv->fbuf.fmt.bytesperline = fb->fmt.bytesperline;
2613 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8;
2617 btv->init.ovfmt = fmt;
2623 btv->init.ov.w.width = fb->fmt.width;
2624 btv->init.ov.w.height = fb->fmt.height;
2634 new->crop = btv->crop[!!fh->do_crop].rect;
2635 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2636 retval = bttv_switch_overlay(btv, fh, new);
2659 struct bttv *btv = fh->btv;
2662 if (!check_alloc_btres_lock(btv, fh, res))
2679 struct bttv *btv = fh->btv;
2682 if (!check_alloc_btres_lock(btv, fh, res))
2692 struct bttv *btv = fh->btv;
2700 free_btres_lock(btv, fh, res);
2708 struct bttv *btv = fh->btv;
2713 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id,
2723 struct bttv *btv = fh->btv;
2730 bttv_call_all(btv, tuner, g_tuner, t);
2736 if (btv->audio_mode_gpio)
2737 btv->audio_mode_gpio(btv, t, 0);
2746 struct bttv *btv = fh->btv;
2752 *f = bttv_tvnorms[btv->tvnorm].cropcap.pixelaspect;
2759 struct bttv *btv = fh->btv;
2768 * No fh->do_crop = 1; because btv->crop[1] may be
2772 sel->r = btv->crop[!!fh->do_crop].rect;
2775 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.defrect;
2778 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2790 struct bttv *btv = fh->btv;
2811 if (locked_btres(fh->btv, VIDEO_RESOURCES)) {
2815 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2821 b_top = max(b->top, btv->vbi_end);
2845 btv->crop[1] = c;
2851 btv->init.width = c.min_scaled_width;
2854 btv->init.width = c.max_scaled_width;
2859 btv->init.height = c.min_scaled_height;
2862 btv->init.height = c.max_scaled_height;
2874 if (fh->btv->errors)
2875 bttv_reinit_bt848(fh->btv);
2877 fh->btv->c.nr, (int)count, v4l2_type_names[fh->type]);
2881 if (!check_alloc_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ)) {
2888 free_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ);
2891 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI))
2919 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI))
2933 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM))
2961 struct bttv *btv = video_drvdata(file);
2977 btv->c.nr, v4l2_type_names[type]);
2983 btv->users++;
2986 *fh = btv->init;
2993 &btv->c.pci->dev, &btv->s_lock,
2997 fh, &btv->lock);
2999 &btv->c.pci->dev, &btv->s_lock,
3003 fh, &btv->lock);
3004 set_tvnorm(btv,btv->tvnorm);
3005 set_input(btv, btv->input, btv->tvnorm);
3006 audio_mute(btv, btv->mute);
3009 which only change on request. These are stored in btv->crop[1].
3013 will use btv->crop[0], the default cropping parameters for the
3022 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);
3024 bttv_field_count(btv);
3032 struct bttv *btv = fh->btv;
3036 bttv_switch_overlay(btv,fh,NULL);
3041 free_btres_lock(btv,fh,RESOURCE_VIDEO_STREAM);
3048 free_btres_lock(btv, fh, RESOURCE_VIDEO_READ);
3054 free_btres_lock(btv,fh,RESOURCE_VBI);
3063 btv->users--;
3064 bttv_field_count(btv);
3066 if (!btv->users)
3067 audio_mute(btv, btv->mute);
3081 fh->btv->c.nr, v4l2_type_names[fh->type],
3154 struct bttv *btv = video_drvdata(file);
3159 dprintk("%d: open called (radio)\n", btv->c.nr);
3166 *fh = btv->init;
3169 btv->radio_user++;
3170 audio_mute(btv, btv->mute);
3180 struct bttv *btv = fh->btv;
3188 btv->radio_user--;
3190 bttv_call_all(btv, core, command, SAA6588_CMD_CLOSE, &cmd);
3192 if (btv->radio_user == 0)
3193 btv->has_radio_tuner = 0;
3200 struct bttv *btv = fh->btv;
3206 radio_enable(btv);
3208 bttv_call_all(btv, tuner, g_tuner, t);
3210 if (btv->audio_mode_gpio)
3211 btv->audio_mode_gpio(btv, t, 0);
3213 if (btv->has_tea575x)
3214 return snd_tea575x_g_tuner(&btv->tea, t);
3223 struct bttv *btv = fh->btv;
3228 radio_enable(btv);
3229 bttv_call_all(btv, tuner, s_tuner, t);
3237 struct bttv *btv = fh->btv;
3239 if (btv->has_tea575x)
3240 return snd_tea575x_s_hw_freq_seek(file, &btv->tea, a);
3249 struct bttv *btv = fh->btv;
3251 if (btv->has_tea575x)
3252 return snd_tea575x_enum_freq_bands(&btv->tea, band);
3261 struct bttv *btv = fh->btv;
3269 radio_enable(btv);
3271 bttv_call_all(btv, core, command, SAA6588_CMD_READ, &cmd);
3279 struct bttv *btv = fh->btv;
3288 radio_enable(btv);
3292 bttv_call_all(btv, core, command, SAA6588_CMD_POLL, &cmd);
3365 static void bttv_risc_disasm(struct bttv *btv,
3371 btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma);
3374 btv->c.v4l2_dev.name,
3379 btv->c.v4l2_dev.name,
3387 static void bttv_print_riscaddr(struct bttv *btv)
3389 pr_info(" main: %08llx\n", (unsigned long long)btv->main.dma);
3391 btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0,
3392 btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0);
3394 btv->curr.top
3395 ? (unsigned long long)btv->curr.top->top.dma : 0,
3396 btv->curr.bottom
3397 ? (unsigned long long)btv->curr.bottom->bottom.dma : 0);
3399 btv->screen ? (unsigned long long)btv->screen->top.dma : 0,
3400 btv->screen ? (unsigned long long)btv->screen->bottom.dma : 0);
3401 bttv_risc_disasm(btv, &btv->main);
3442 static void bttv_irq_debug_low_latency(struct bttv *btv, u32 rc)
3445 btv->c.nr,
3446 (unsigned long)btv->main.dma,
3447 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]),
3448 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]),
3453 btv->c.nr);
3457 btv->c.nr);
3459 btv->c.nr);
3464 bttv_irq_next_video(struct bttv *btv, struct bttv_buffer_set *set)
3471 if (!list_empty(&btv->capture)) {
3473 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue);
3481 (item->vb.queue.next != &btv->capture)) {
3522 if (NULL != btv->screen) {
3523 if (V4L2_FIELD_HAS_BOTH(btv->screen->vb.field)) {
3525 set->top = btv->screen;
3526 set->bottom = btv->screen;
3529 if (V4L2_FIELD_TOP == btv->screen->vb.field &&
3531 set->top = btv->screen;
3533 if (V4L2_FIELD_BOTTOM == btv->screen->vb.field &&
3535 set->bottom = btv->screen;
3541 btv->c.nr, set->top, set->bottom,
3542 btv->screen, set->frame_irq, set->top_irq);
3547 bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
3556 btv->c.nr, wakeup->top);
3558 wakeup->top->vb.field_count = btv->field_count;
3566 btv->c.nr, wakeup->top);
3568 wakeup->top->vb.field_count = btv->field_count;
3575 btv->c.nr, wakeup->bottom);
3577 wakeup->bottom->vb.field_count = btv->field_count;
3585 bttv_irq_wakeup_vbi(struct bttv *btv, struct bttv_buffer *wakeup,
3592 wakeup->vb.field_count = btv->field_count;
3599 struct bttv *btv = from_timer(btv, t, timeout);
3607 btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total,
3613 spin_lock_irqsave(&btv->s_lock,flags);
3617 old = btv->curr;
3618 ovbi = btv->cvbi;
3619 btv->curr = new;
3620 btv->cvbi = NULL;
3621 btv->loop_irq = 0;
3622 bttv_buffer_activate_video(btv, &new);
3623 bttv_buffer_activate_vbi(btv, NULL);
3624 bttv_set_dma(btv, 0);
3627 bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_ERROR);
3628 bttv_irq_wakeup_vbi(btv, ovbi, VIDEOBUF_ERROR);
3631 while (!list_empty(&btv->capture)) {
3632 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue);
3637 while (!list_empty(&btv->vcapture)) {
3638 item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue);
3644 btv->errors++;
3645 spin_unlock_irqrestore(&btv->s_lock,flags);
3649 bttv_irq_wakeup_top(struct bttv *btv)
3651 struct bttv_buffer *wakeup = btv->curr.top;
3656 spin_lock(&btv->s_lock);
3657 btv->curr.top_irq = 0;
3658 btv->curr.top = NULL;
3659 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
3662 wakeup->vb.field_count = btv->field_count;
3665 spin_unlock(&btv->s_lock);
3678 bttv_irq_switch_video(struct bttv *btv)
3684 spin_lock(&btv->s_lock);
3687 bttv_irq_next_video(btv, &new);
3689 if ((btv->curr.top && is_active(&btv->curr.top->top, rc)) ||
3690 (btv->curr.bottom && is_active(&btv->curr.bottom->bottom, rc))) {
3691 btv->framedrop++;
3693 bttv_irq_debug_low_latency(btv, rc);
3694 spin_unlock(&btv->s_lock);
3699 old = btv->curr;
3700 btv->curr = new;
3701 btv->loop_irq &= ~1;
3702 bttv_buffer_activate_video(btv, &new);
3703 bttv_set_dma(btv, 0);
3706 if (UNSET != btv->new_input) {
3707 video_mux(btv,btv->new_input);
3708 btv->new_input = UNSET;
3712 bttv_irq_wakeup_video(btv, &old, &new, VIDEOBUF_DONE);
3713 spin_unlock(&btv->s_lock);
3717 bttv_irq_switch_vbi(struct bttv *btv)
3723 spin_lock(&btv->s_lock);
3725 if (!list_empty(&btv->vcapture))
3726 new = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue);
3727 old = btv->cvbi;
3732 btv->framedrop++;
3734 bttv_irq_debug_low_latency(btv, rc);
3735 spin_unlock(&btv->s_lock);
3740 btv->cvbi = new;
3741 btv->loop_irq &= ~4;
3742 bttv_buffer_activate_vbi(btv, new);
3743 bttv_set_dma(btv, 0);
3745 bttv_irq_wakeup_vbi(btv, old, VIDEOBUF_DONE);
3746 spin_unlock(&btv->s_lock);
3754 struct bttv *btv;
3757 btv=(struct bttv *)dev_id;
3774 btv->c.nr, count, btv->field_count,
3793 btv->field_count++;
3795 if ((astat & BT848_INT_GPINT) && btv->remote) {
3796 bttv_input_irq(btv);
3800 btv->i2c_done = stat;
3801 wake_up(&btv->i2c_queue);
3805 bttv_irq_switch_vbi(btv);
3808 bttv_irq_wakeup_top(btv);
3811 bttv_irq_switch_video(btv);
3813 if ((astat & BT848_INT_HLOCK) && btv->opt_automute)
3815 audio_mux_gpio(btv, btv->audio_input, btv->mute);
3819 btv->c.nr,
3826 bttv_print_riscaddr(btv);
3830 btv->c.nr, btread(BT848_RISC_COUNT));
3832 bttv_print_riscaddr(btv);
3842 btv->c.nr);
3845 btv->c.nr);
3856 btv->irq_total++;
3858 btv->irq_me++;
3866 static void vdev_init(struct bttv *btv,
3872 vfd->v4l2_dev = &btv->c.v4l2_dev;
3874 video_set_drvdata(vfd, btv);
3876 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
3877 type_name, bttv_tvcards[btv->c.type].name);
3878 if (btv->tuner_type == TUNER_ABSENT) {
3886 static void bttv_unregister_video(struct bttv *btv)
3888 video_unregister_device(&btv->video_dev);
3889 video_unregister_device(&btv->vbi_dev);
3890 video_unregister_device(&btv->radio_dev);
3894 static int bttv_register_video(struct bttv *btv)
3900 vdev_init(btv, &btv->video_dev, &bttv_video_template, "video");
3901 btv->video_dev.device_caps = V4L2_CAP_VIDEO_CAPTURE |
3903 if (btv->tuner_type != TUNER_ABSENT)
3904 btv->video_dev.device_caps |= V4L2_CAP_TUNER;
3906 btv->video_dev.device_caps |= V4L2_CAP_VIDEO_OVERLAY;
3908 if (video_register_device(&btv->video_dev, VFL_TYPE_VIDEO,
3909 video_nr[btv->c.nr]) < 0)
3912 btv->c.nr, video_device_node_name(&btv->video_dev));
3913 if (device_create_file(&btv->video_dev.dev,
3915 pr_err("%d: device_create_file 'card' failed\n", btv->c.nr);
3920 vdev_init(btv, &btv->vbi_dev, &bttv_video_template, "vbi");
3921 btv->vbi_dev.device_caps = V4L2_CAP_VBI_CAPTURE | V4L2_CAP_READWRITE |
3923 if (btv->tuner_type != TUNER_ABSENT)
3924 btv->vbi_dev.device_caps |= V4L2_CAP_TUNER;
3926 if (video_register_device(&btv->vbi_dev, VFL_TYPE_VBI,
3927 vbi_nr[btv->c.nr]) < 0)
3930 btv->c.nr, video_device_node_name(&btv->vbi_dev));
3932 if (!btv->has_radio)
3935 vdev_init(btv, &btv->radio_dev, &radio_template, "radio");
3936 btv->radio_dev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
3937 if (btv->has_saa6588)
3938 btv->radio_dev.device_caps |= V4L2_CAP_READWRITE |
3940 if (btv->has_tea575x)
3941 btv->radio_dev.device_caps |= V4L2_CAP_HW_FREQ_SEEK;
3942 btv->radio_dev.ctrl_handler = &btv->radio_ctrl_handler;
3943 if (video_register_device(&btv->radio_dev, VFL_TYPE_RADIO,
3944 radio_nr[btv->c.nr]) < 0)
3947 btv->c.nr, video_device_node_name(&btv->radio_dev));
3953 bttv_unregister_video(btv);
3980 struct bttv *btv;
3986 bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL);
3987 if (btv == NULL) {
3991 btv->c.nr = bttv_num;
3992 snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name),
3993 "bttv%d", btv->c.nr);
3996 mutex_init(&btv->lock);
3997 spin_lock_init(&btv->s_lock);
3998 spin_lock_init(&btv->gpio_lock);
3999 init_waitqueue_head(&btv->i2c_queue);
4000 INIT_LIST_HEAD(&btv->c.subs);
4001 INIT_LIST_HEAD(&btv->capture);
4002 INIT_LIST_HEAD(&btv->vcapture);
4004 timer_setup(&btv->timeout, bttv_irq_timeout, 0);
4006 btv->i2c_rc = -1;
4007 btv->tuner_type = UNSET;
4008 btv->new_input = UNSET;
4009 btv->has_radio=radio[btv->c.nr];
4012 btv->c.pci = dev;
4013 btv->id = dev->device;
4015 pr_warn("%d: Can't enable device\n", btv->c.nr);
4020 pr_warn("%d: No suitable DMA available\n", btv->c.nr);
4026 btv->c.v4l2_dev.name)) {
4028 btv->c.nr,
4036 result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev);
4038 pr_warn("%d: v4l2_device_register() failed\n", btv->c.nr);
4041 hdl = &btv->ctrl_handler;
4043 btv->c.v4l2_dev.ctrl_handler = hdl;
4044 v4l2_ctrl_handler_init(&btv->radio_ctrl_handler, 6);
4046 btv->revision = dev->revision;
4049 bttv_num, btv->id, btv->revision, pci_name(dev),
4050 btv->c.pci->irq, lat,
4054 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
4055 if (NULL == btv->bt848_mmio) {
4056 pr_err("%d: ioremap() failed\n", btv->c.nr);
4062 bttv_idcard(btv);
4066 result = request_irq(btv->c.pci->irq, bttv_irq,
4067 IRQF_SHARED, btv->c.v4l2_dev.name, (void *)btv);
4070 bttv_num, btv->c.pci->irq);
4074 if (0 != bttv_handle_chipset(btv)) {
4080 btv->opt_combfilter = combfilter;
4083 btv->opt_automute = automute;
4086 btv->opt_vcr_hack = vcr_hack;
4090 btv->opt_uv_ratio = uv_ratio;
4096 btv->init.btv = btv;
4097 btv->init.ov.w.width = 320;
4098 btv->init.ov.w.height = 240;
4099 btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
4100 btv->init.width = 320;
4101 btv->init.height = 240;
4102 btv->init.ov.w.width = 320;
4103 btv->init.ov.w.height = 240;
4104 btv->init.ov.field = V4L2_FIELD_INTERLACED;
4105 btv->input = 0;
4121 if (btv->volume_gpio)
4137 bttv_gpio_tracking(btv,"pre-init");
4139 bttv_risc_init_main(btv);
4140 init_bt848(btv);
4146 bttv_gpio_tracking(btv,"init");
4149 bttv_init_card1(btv);
4152 init_bttv_i2c(btv);
4155 bttv_init_card2(btv);
4156 bttv_init_tuner(btv);
4157 if (btv->tuner_type != TUNER_ABSENT) {
4158 bttv_set_frequency(btv, &init_freq);
4159 btv->radio_freq = 90500 * 16; /* 90.5Mhz default */
4161 btv->std = V4L2_STD_PAL;
4162 init_irqreg(btv);
4163 if (!bttv_tvcards[btv->c.type].no_video)
4170 audio_mute(btv, 1);
4173 if (!bttv_tvcards[btv->c.type].no_video) {
4174 v4l2_ctrl_add_handler(&btv->radio_ctrl_handler, hdl,
4176 if (btv->radio_ctrl_handler.error) {
4177 result = btv->radio_ctrl_handler.error;
4180 set_input(btv, 0, btv->tvnorm);
4181 bttv_crop_reset(&btv->crop[0], btv->tvnorm);
4182 btv->crop[1] = btv->crop[0]; /* current = default */
4183 disclaim_vbi_lines(btv);
4184 disclaim_video_lines(btv);
4185 bttv_register_video(btv);
4189 if (bttv_tvcards[btv->c.type].has_dvb) {
4190 bttv_sub_add_device(&btv->c, "dvb");
4191 request_modules(btv);
4195 init_bttv_i2c_ir(btv);
4196 bttv_input_init(btv);
4204 free_irq(btv->c.pci->irq,btv);
4207 v4l2_ctrl_handler_free(&btv->ctrl_handler);
4208 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler);
4209 v4l2_device_unregister(&btv->c.v4l2_dev);
4212 if (btv->bt848_mmio)
4213 iounmap(btv->bt848_mmio);
4214 release_mem_region(pci_resource_start(btv->c.pci,0),
4215 pci_resource_len(btv->c.pci,0));
4216 pci_disable_device(btv->c.pci);
4219 bttvs[btv->c.nr] = NULL;
4220 kfree(btv);
4227 struct bttv *btv = to_bttv(v4l2_dev);
4230 pr_info("%d: unloading\n", btv->c.nr);
4232 if (bttv_tvcards[btv->c.type].has_dvb)
4233 flush_request_modules(btv);
4241 bttv_gpio_tracking(btv,"cleanup");
4244 btv->shutdown=1;
4245 bttv_input_fini(btv);
4246 bttv_sub_del_devices(&btv->c);
4249 fini_bttv_i2c(btv);
4252 bttv_unregister_video(btv);
4255 v4l2_ctrl_handler_free(&btv->ctrl_handler);
4256 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler);
4257 btcx_riscmem_free(btv->c.pci,&btv->main);
4260 free_irq(btv->c.pci->irq,btv);
4261 del_timer_sync(&btv->timeout);
4262 iounmap(btv->bt848_mmio);
4263 release_mem_region(pci_resource_start(btv->c.pci,0),
4264 pci_resource_len(btv->c.pci,0));
4265 pci_disable_device(btv->c.pci);
4267 v4l2_device_unregister(&btv->c.v4l2_dev);
4268 bttvs[btv->c.nr] = NULL;
4269 kfree(btv);
4278 struct bttv *btv = to_bttv(v4l2_dev);
4282 dprintk("%d: suspend %d\n", btv->c.nr, state.event);
4285 spin_lock_irqsave(&btv->s_lock,flags);
4287 btv->state.video = btv->curr;
4288 btv->state.vbi = btv->cvbi;
4289 btv->state.loop_irq = btv->loop_irq;
4290 btv->curr = idle;
4291 btv->loop_irq = 0;
4292 bttv_buffer_activate_video(btv, &idle);
4293 bttv_buffer_activate_vbi(btv, NULL);
4294 bttv_set_dma(btv, 0);
4296 spin_unlock_irqrestore(&btv->s_lock,flags);
4299 btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN);
4300 btv->state.gpio_data = gpio_read();
4306 btv->state.disabled = 1;
4314 struct bttv *btv = to_bttv(v4l2_dev);
4318 dprintk("%d: resume\n", btv->c.nr);
4321 if (btv->state.disabled) {
4324 pr_warn("%d: Can't enable device\n", btv->c.nr);
4327 btv->state.disabled = 0;
4332 pr_warn("%d: Can't enable device\n", btv->c.nr);
4333 btv->state.disabled = 1;
4340 bttv_reinit_bt848(btv);
4341 gpio_inout(0xffffff, btv->state.gpio_enable);
4342 gpio_write(btv->state.gpio_data);
4345 spin_lock_irqsave(&btv->s_lock,flags);
4346 btv->curr = btv->state.video;
4347 btv->cvbi = btv->state.vbi;
4348 btv->loop_irq = btv->state.loop_irq;
4349 bttv_buffer_activate_video(btv, &btv->curr);
4350 bttv_buffer_activate_vbi(btv, btv->cvbi);
4351 bttv_set_dma(btv, 0);
4352 spin_unlock_irqrestore(&btv->s_lock,flags);