Lines Matching defs:btv

177 	struct bttv *btv = video_get_drvdata(vfd);
178 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
644 int check_alloc_btres_lock(struct bttv *btv, int bit)
653 if (btv->resources & xbits) {
659 && 0 == (btv->resources & VIDEO_RESOURCES)) {
661 __s32 top = btv->crop[!!btv->do_crop].rect.top;
663 if (btv->vbi_end > top)
668 btv->crop_start = top;
670 __s32 end = btv->vbi_fmt.end;
672 if (end > btv->crop_start)
675 /* Claim scan lines above btv->vbi_fmt.end. */
676 btv->vbi_end = end;
680 btv->resources |= bit;
688 int check_btres(struct bttv *btv, int bit)
690 return (btv->resources & bit);
694 int locked_btres(struct bttv *btv, int bit)
696 return (btv->resources & bit);
699 /* Call with btv->lock down. */
701 disclaim_vbi_lines(struct bttv *btv)
703 btv->vbi_end = 0;
706 /* Call with btv->lock down. */
708 disclaim_video_lines(struct bttv *btv)
713 tvnorm = &bttv_tvnorms[btv->tvnorm];
714 btv->crop_start = tvnorm->cropcap.bounds.top
728 void free_btres_lock(struct bttv *btv, int bits)
730 if ((btv->resources & bits) != bits) {
734 btv->resources &= ~bits;
736 bits = btv->resources;
739 disclaim_video_lines(btv);
742 disclaim_vbi_lines(btv);
758 static void set_pll_freq(struct bttv *btv, unsigned int fin, unsigned int fout)
780 static void set_pll(struct bttv *btv)
784 if (!btv->pll.pll_crystal)
787 if (btv->pll.pll_ofreq == btv->pll.pll_current) {
788 dprintk("%d: PLL: no change required\n", btv->c.nr);
792 if (btv->pll.pll_ifreq == btv->pll.pll_ofreq) {
794 if (btv->pll.pll_current == 0)
798 btv->c.nr, btv->pll.pll_ifreq);
801 btv->pll.pll_current = 0;
807 btv->c.nr,
808 btv->pll.pll_ifreq, btv->pll.pll_ofreq);
809 set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq);
819 btv->pll.pll_current = btv->pll.pll_ofreq;
825 btv->pll.pll_current = -1;
832 static void bt848A_set_timing(struct bttv *btv)
835 int table_idx = bttv_tvnorms[btv->tvnorm].sram;
836 int fsc = bttv_tvnorms[btv->tvnorm].Fsc;
838 if (btv->input == btv->dig) {
840 btv->c.nr,table_idx);
850 btv->pll.pll_ofreq = 27000000;
852 set_pll(btv);
856 btv->pll.pll_ofreq = fsc;
857 set_pll(btv);
864 static void bt848_bright(struct bttv *btv, int bright)
869 btv->bright = bright;
876 static void bt848_hue(struct bttv *btv, int hue)
880 btv->hue = hue;
887 static void bt848_contrast(struct bttv *btv, int cont)
891 btv->contrast = cont;
901 static void bt848_sat(struct bttv *btv, int color)
905 btv->saturation = color;
908 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7;
909 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254;
921 video_mux(struct bttv *btv, unsigned int input)
925 if (input >= bttv_tvcards[btv->c.type].video_inputs)
929 mask2 = bttv_tvcards[btv->c.type].gpiomask2;
933 if (input == btv->svhs) {
940 mux = bttv_muxsel(btv, input);
942 dprintk("%d: video mux: input=%d mux=%d\n", btv->c.nr, input, mux);
945 if(bttv_tvcards[btv->c.type].muxsel_hook)
946 bttv_tvcards[btv->c.type].muxsel_hook (btv, input);
956 audio_mux_gpio(struct bttv *btv, int input, int mute)
960 gpio_inout(bttv_tvcards[btv->c.type].gpiomask,
961 bttv_tvcards[btv->c.type].gpiomask);
965 mute_gpio = mute || (btv->opt_automute && (!signal || !btv->users)
966 && !btv->has_radio_tuner);
969 gpio_val = bttv_tvcards[btv->c.type].gpiomute;
971 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input];
973 switch (btv->c.type) {
976 gpio_val = bttv_tda9880_setnorm(btv, gpio_val);
980 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val);
984 bttv_gpio_tracking(btv, audio_modes[mute_gpio ? 4 : input]);
988 audio_mute(struct bttv *btv, int mute)
992 audio_mux_gpio(btv, btv->audio_input, mute);
994 if (btv->sd_msp34xx) {
995 ctrl = v4l2_ctrl_find(btv->sd_msp34xx->ctrl_handler, V4L2_CID_AUDIO_MUTE);
999 if (btv->sd_tvaudio) {
1000 ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE);
1004 if (btv->sd_tda7432) {
1005 ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE);
1013 audio_input(struct bttv *btv, int input)
1015 audio_mux_gpio(btv, input, btv->mute);
1017 if (btv->sd_msp34xx) {
1028 if (btv->radio_uses_msp_demodulator) {
1053 if (btv->c.type == BTTV_BOARD_VOODOOTV_200)
1060 v4l2_subdev_call(btv->sd_msp34xx, audio, s_routing,
1063 if (btv->sd_tvaudio) {
1064 v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing,
1099 /* Call with btv->lock down. */
1101 set_tvnorm(struct bttv *btv, unsigned int norm)
1107 WARN_ON(btv->tvnorm >= BTTV_TVNORMS);
1111 if (memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap,
1113 bttv_crop_reset(&btv->crop[0], norm);
1114 btv->crop[1] = btv->crop[0]; /* current = default */
1116 if (0 == (btv->resources & VIDEO_RESOURCES)) {
1117 btv->crop_start = tvnorm->cropcap.bounds.top
1122 btv->tvnorm = norm;
1130 bt848A_set_timing(btv);
1132 switch (btv->c.type) {
1135 bttv_tda9880_setnorm(btv, gpio_read());
1139 bttv_call_all(btv, video, s_std, id);
1144 /* Call with btv->lock down. */
1146 set_input(struct bttv *btv, unsigned int input, unsigned int norm)
1150 btv->input = input;
1152 spin_lock_irqsave(&btv->s_lock,flags);
1153 if (btv->curr.frame_irq) {
1155 btv->new_input = input;
1157 video_mux(btv,input);
1159 spin_unlock_irqrestore(&btv->s_lock,flags);
1161 video_mux(btv,input);
1163 btv->audio_input = (btv->tuner_type != TUNER_ABSENT && input == 0) ?
1165 audio_input(btv, btv->audio_input);
1166 set_tvnorm(btv, norm);
1169 void init_irqreg(struct bttv *btv)
1174 if (bttv_tvcards[btv->c.type].no_video) {
1180 btwrite((btv->triton1) |
1181 (btv->gpioirq ? BT848_INT_GPINT : 0) |
1191 static void init_bt848(struct bttv *btv)
1193 if (bttv_tvcards[btv->c.type].no_video) {
1195 init_irqreg(btv);
1215 v4l2_ctrl_handler_setup(&btv->ctrl_handler);
1218 init_irqreg(btv);
1221 static void bttv_reinit_bt848(struct bttv *btv)
1226 pr_info("%d: reset, reinitialize\n", btv->c.nr);
1227 spin_lock_irqsave(&btv->s_lock,flags);
1228 btv->errors=0;
1229 bttv_set_dma(btv,0);
1230 spin_unlock_irqrestore(&btv->s_lock,flags);
1232 init_bt848(btv);
1233 btv->pll.pll_current = -1;
1234 set_input(btv, btv->input, btv->tvnorm);
1239 struct bttv *btv = container_of(c->handler, struct bttv, ctrl_handler);
1244 bt848_bright(btv, c->val);
1247 bt848_hue(btv, c->val);
1250 bt848_contrast(btv, c->val);
1253 bt848_sat(btv, c->val);
1265 audio_mute(btv, c->val);
1266 btv->mute = c->val;
1269 btv->volume_gpio(btv, c->val);
1278 btv->opt_combfilter = c->val;
1290 btv->opt_automute = c->val;
1298 btv->opt_vcr_hack = c->val;
1307 btv->opt_uv_ratio = c->val;
1308 bt848_sat(btv, btv->saturation);
1439 void bttv_gpio_tracking(struct bttv *btv, char *comment)
1445 btv->c.nr, outbits, data & outbits, data & ~outbits, comment);
1469 struct bttv *btv = vb2_get_drv_priv(q);
1470 unsigned int size = btv->fmt->depth * btv->width * btv->height >> 3;
1484 struct bttv *btv = vb2_get_drv_priv(vq);
1488 spin_lock_irqsave(&btv->s_lock, flags);
1489 if (list_empty(&btv->capture)) {
1490 btv->loop_irq = BT848_RISC_VIDEO;
1491 if (vb2_is_streaming(&btv->vbiq))
1492 btv->loop_irq |= BT848_RISC_VBI;
1493 bttv_set_dma(btv, BT848_CAP_CTL_CAPTURE_ODD |
1496 list_add_tail(&buf->list, &btv->capture);
1497 spin_unlock_irqrestore(&btv->s_lock, flags);
1503 struct bttv *btv = vb2_get_drv_priv(vq);
1506 unsigned int size = (btv->fmt->depth * btv->width * btv->height) >> 3;
1512 if (btv->field != V4L2_FIELD_ALTERNATE) {
1513 buf->vbuf.field = btv->field;
1514 } else if (btv->field_last == V4L2_FIELD_TOP) {
1516 btv->field_last = V4L2_FIELD_BOTTOM;
1519 btv->field_last = V4L2_FIELD_TOP;
1523 return bttv_buffer_risc(btv, buf);
1529 struct bttv *btv = vb2_get_drv_priv(vq);
1533 btcx_riscmem_free(btv->c.pci, &buf->top);
1534 btcx_riscmem_free(btv->c.pci, &buf->bottom);
1541 struct bttv *btv = vb2_get_drv_priv(q);
1543 if (!check_alloc_btres_lock(btv, RESOURCE_VIDEO_STREAM)) {
1544 if (btv->field_count)
1546 while (!list_empty(&btv->capture)) {
1547 buf = list_entry(btv->capture.next,
1550 buf->vbuf.sequence = (btv->field_count >> 1) + seqnr++;
1556 if (!vb2_is_streaming(&btv->vbiq)) {
1557 init_irqreg(btv);
1558 btv->field_count = 0;
1560 btv->framedrop = 0;
1568 struct bttv *btv = vb2_get_drv_priv(q);
1571 spin_lock_irqsave(&btv->s_lock, flags);
1572 free_btres_lock(btv, RESOURCE_VIDEO_STREAM);
1573 if (!vb2_is_streaming(&btv->vbiq)) {
1577 spin_unlock_irqrestore(&btv->s_lock, flags);
1591 static void radio_enable(struct bttv *btv)
1594 if (!btv->has_radio_tuner) {
1595 btv->has_radio_tuner = 1;
1596 bttv_call_all(btv, tuner, s_radio);
1597 btv->audio_input = TVAUDIO_INPUT_RADIO;
1598 audio_input(btv, btv->audio_input);
1604 struct bttv *btv = video_drvdata(file);
1612 btv->std = id;
1613 set_tvnorm(btv, i);
1619 struct bttv *btv = video_drvdata(file);
1621 *id = btv->std;
1627 struct bttv *btv = video_drvdata(file);
1639 struct bttv *btv = video_drvdata(file);
1641 if (i->index >= bttv_tvcards[btv->c.type].video_inputs)
1647 if (btv->tuner_type != TUNER_ABSENT && i->index == 0) {
1651 } else if (i->index == btv->svhs) {
1657 if (i->index == btv->input) {
1671 struct bttv *btv = video_drvdata(file);
1673 *i = btv->input;
1680 struct bttv *btv = video_drvdata(file);
1682 if (i >= bttv_tvcards[btv->c.type].video_inputs)
1685 set_input(btv, i, btv->tvnorm);
1692 struct bttv *btv = video_drvdata(file);
1697 bttv_call_all(btv, tuner, s_tuner, t);
1699 if (btv->audio_mode_gpio) {
1702 btv->audio_mode_gpio(btv, &copy, 1);
1710 struct bttv *btv = video_drvdata(file);
1716 radio_enable(btv);
1718 btv->radio_freq : btv->tv_freq;
1723 static void bttv_set_frequency(struct bttv *btv, const struct v4l2_frequency *f)
1727 bttv_call_all(btv, tuner, s_frequency, f);
1730 bttv_call_all(btv, tuner, g_frequency, &new_freq);
1732 radio_enable(btv);
1733 btv->radio_freq = new_freq.frequency;
1734 if (btv->has_tea575x) {
1735 btv->tea.freq = btv->radio_freq;
1736 snd_tea575x_set_freq(&btv->tea);
1739 btv->tv_freq = new_freq.frequency;
1746 struct bttv *btv = video_drvdata(file);
1751 bttv_set_frequency(btv, f);
1758 struct bttv *btv = video_drvdata(file);
1760 v4l2_ctrl_handler_log_status(vdev->ctrl_handler, btv->c.v4l2_dev.name);
1761 bttv_call_all(btv, core, log_status);
1769 struct bttv *btv = video_drvdata(file);
1782 struct bttv *btv = video_drvdata(file);
1842 limit_scaled_size_lock(struct bttv *btv, __s32 *width, __s32 *height,
1861 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
1864 c = &btv->crop[!!btv->do_crop];
1866 if (btv->do_crop
1869 && !locked_btres(btv, VIDEO_RESOURCES)) {
1880 Note btv->vbi_end is really a minimum, see
1882 if (btv->vbi_end > b->top) {
1883 max_height -= btv->vbi_end - b->top;
1890 if (btv->vbi_end > c->rect.top)
1918 if (btv->vbi_end > c->rect.top) {
1920 c->rect.top = btv->vbi_end;
1940 static int bttv_switch_type(struct bttv *btv, enum v4l2_buf_type type)
1947 q = &btv->capq;
1951 q = &btv->vbiq;
1959 if (check_btres(btv, res))
1963 btv->type = type;
1989 struct bttv *btv = video_drvdata(file);
1991 pix_format_set_size(&f->fmt.pix, btv->fmt, btv->width, btv->height);
1992 f->fmt.pix.field = btv->field;
1993 f->fmt.pix.pixelformat = btv->fmt->fourcc;
2016 struct bttv *btv = video_drvdata(file);
2043 height2 = btv->crop[!!btv->do_crop].rect.height >> 1;
2054 rc = limit_scaled_size_lock(btv, &width, &height, field, width_mask,
2072 struct bttv *btv = video_drvdata(file);
2077 retval = bttv_switch_type(btv, f->type);
2091 retval = limit_scaled_size_lock(btv, &width, &height, f->fmt.pix.field,
2099 btv->fmt = fmt;
2100 btv->width = f->fmt.pix.width;
2101 btv->height = f->fmt.pix.height;
2102 btv->field = f->fmt.pix.field;
2109 btv->field_last = V4L2_FIELD_BOTTOM;
2117 struct bttv *btv = video_drvdata(file);
2123 strscpy(cap->card, btv->video_dev.name, sizeof(cap->card));
2126 if (video_is_registered(&btv->vbi_dev))
2128 if (video_is_registered(&btv->radio_dev)) {
2130 if (btv->has_tea575x)
2138 if (btv->has_saa6588)
2140 if (btv->tuner_type != TUNER_ABSENT)
2167 struct bttv *btv = video_drvdata(file);
2172 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id,
2181 struct bttv *btv = video_drvdata(file);
2188 bttv_call_all(btv, tuner, g_tuner, t);
2194 if (btv->audio_mode_gpio)
2195 btv->audio_mode_gpio(btv, t, 0);
2203 struct bttv *btv = video_drvdata(file);
2209 *f = bttv_tvnorms[btv->tvnorm].cropcap.pixelaspect;
2215 struct bttv *btv = video_drvdata(file);
2222 sel->r = btv->crop[!!btv->do_crop].rect;
2225 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.defrect;
2228 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2239 struct bttv *btv = video_drvdata(file);
2259 if (locked_btres(btv, VIDEO_RESOURCES))
2262 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2268 b_top = max(b->top, btv->vbi_end);
2292 btv->crop[1] = c;
2294 btv->do_crop = 1;
2296 if (btv->width < c.min_scaled_width)
2297 btv->width = c.min_scaled_width;
2298 else if (btv->width > c.max_scaled_width)
2299 btv->width = c.max_scaled_width;
2301 if (btv->height < c.min_scaled_height)
2302 btv->height = c.min_scaled_height;
2303 else if (btv->height > c.max_scaled_height)
2304 btv->height = c.max_scaled_height;
2371 struct bttv *btv = video_drvdata(file);
2378 dprintk("%d: open called (radio)\n", btv->c.nr);
2380 btv->radio_user++;
2381 audio_mute(btv, btv->mute);
2388 struct bttv *btv = video_drvdata(file);
2391 btv->radio_user--;
2393 bttv_call_all(btv, core, command, SAA6588_CMD_CLOSE, &cmd);
2395 if (btv->radio_user == 0)
2396 btv->has_radio_tuner = 0;
2405 struct bttv *btv = video_drvdata(file);
2411 radio_enable(btv);
2413 bttv_call_all(btv, tuner, g_tuner, t);
2415 if (btv->audio_mode_gpio)
2416 btv->audio_mode_gpio(btv, t, 0);
2418 if (btv->has_tea575x)
2419 return snd_tea575x_g_tuner(&btv->tea, t);
2427 struct bttv *btv = video_drvdata(file);
2432 radio_enable(btv);
2433 bttv_call_all(btv, tuner, s_tuner, t);
2440 struct bttv *btv = video_drvdata(file);
2442 if (btv->has_tea575x)
2443 return snd_tea575x_s_hw_freq_seek(file, &btv->tea, a);
2451 struct bttv *btv = video_drvdata(file);
2453 if (btv->has_tea575x)
2454 return snd_tea575x_enum_freq_bands(&btv->tea, band);
2462 struct bttv *btv = video_drvdata(file);
2470 radio_enable(btv);
2472 bttv_call_all(btv, core, command, SAA6588_CMD_READ, &cmd);
2479 struct bttv *btv = video_drvdata(file);
2483 radio_enable(btv);
2487 bttv_call_all(btv, core, command, SAA6588_CMD_POLL, &cmd);
2560 static void bttv_risc_disasm(struct bttv *btv,
2566 btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma);
2569 btv->c.v4l2_dev.name,
2574 btv->c.v4l2_dev.name,
2582 static void bttv_print_riscaddr(struct bttv *btv)
2584 pr_info(" main: %08llx\n", (unsigned long long)btv->main.dma);
2586 btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0,
2587 btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0);
2589 btv->curr.top
2590 ? (unsigned long long)btv->curr.top->top.dma : 0,
2591 btv->curr.bottom
2592 ? (unsigned long long)btv->curr.bottom->bottom.dma : 0);
2593 bttv_risc_disasm(btv, &btv->main);
2634 static void bttv_irq_debug_low_latency(struct bttv *btv, u32 rc)
2637 btv->c.nr,
2638 (unsigned long)btv->main.dma,
2639 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]),
2640 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]),
2645 btv->c.nr);
2649 btv->c.nr);
2651 btv->c.nr);
2656 bttv_irq_next_video(struct bttv *btv, struct bttv_buffer_set *set)
2663 if (!list_empty(&btv->capture)) {
2665 item = list_entry(btv->capture.next, struct bttv_buffer, list);
2674 item->list.next != &btv->capture) {
2721 btv->c.nr, set->top, set->bottom,
2727 bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
2736 btv->c.nr, wakeup->top);
2738 wakeup->top->vbuf.sequence = btv->field_count >> 1;
2740 if (btv->field_count == 0)
2747 btv->c.nr, wakeup->top);
2749 wakeup->top->vbuf.sequence = btv->field_count >> 1;
2751 if (btv->field_count == 0)
2757 btv->c.nr, wakeup->bottom);
2759 wakeup->bottom->vbuf.sequence = btv->field_count >> 1;
2761 if (btv->field_count == 0)
2768 bttv_irq_wakeup_vbi(struct bttv *btv, struct bttv_buffer *wakeup,
2774 wakeup->vbuf.sequence = btv->field_count >> 1;
2797 if (btv->field_count == 0)
2803 struct bttv *btv = from_timer(btv, t, timeout);
2812 btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total,
2818 spin_lock_irqsave(&btv->s_lock,flags);
2822 old = btv->curr;
2823 ovbi = btv->cvbi;
2824 btv->curr = new;
2825 btv->cvbi = NULL;
2826 btv->loop_irq = 0;
2827 bttv_buffer_activate_video(btv, &new);
2828 bttv_buffer_activate_vbi(btv, NULL);
2829 bttv_set_dma(btv, 0);
2832 bttv_irq_wakeup_video(btv, &old, &new, VB2_BUF_STATE_DONE);
2833 bttv_irq_wakeup_vbi(btv, ovbi, VB2_BUF_STATE_DONE);
2836 if (btv->field_count)
2838 while (!list_empty(&btv->capture)) {
2839 item = list_entry(btv->capture.next, struct bttv_buffer, list);
2842 item->vbuf.sequence = (btv->field_count >> 1) + seqnr++;
2845 while (!list_empty(&btv->vcapture)) {
2846 item = list_entry(btv->vcapture.next, struct bttv_buffer, list);
2849 item->vbuf.sequence = (btv->field_count >> 1) + seqnr++;
2853 btv->errors++;
2854 spin_unlock_irqrestore(&btv->s_lock,flags);
2858 bttv_irq_wakeup_top(struct bttv *btv)
2860 struct bttv_buffer *wakeup = btv->curr.top;
2865 spin_lock(&btv->s_lock);
2866 btv->curr.top_irq = 0;
2867 btv->curr.top = NULL;
2868 bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
2870 wakeup->vbuf.sequence = btv->field_count >> 1;
2872 if (btv->field_count == 0)
2874 spin_unlock(&btv->s_lock);
2887 bttv_irq_switch_video(struct bttv *btv)
2893 spin_lock(&btv->s_lock);
2896 bttv_irq_next_video(btv, &new);
2898 if ((btv->curr.top && is_active(&btv->curr.top->top, rc)) ||
2899 (btv->curr.bottom && is_active(&btv->curr.bottom->bottom, rc))) {
2900 btv->framedrop++;
2902 bttv_irq_debug_low_latency(btv, rc);
2903 spin_unlock(&btv->s_lock);
2908 old = btv->curr;
2909 btv->curr = new;
2910 btv->loop_irq &= ~BT848_RISC_VIDEO;
2911 bttv_buffer_activate_video(btv, &new);
2912 bttv_set_dma(btv, 0);
2915 if (UNSET != btv->new_input) {
2916 video_mux(btv,btv->new_input);
2917 btv->new_input = UNSET;
2921 bttv_irq_wakeup_video(btv, &old, &new, VB2_BUF_STATE_DONE);
2922 spin_unlock(&btv->s_lock);
2926 bttv_irq_switch_vbi(struct bttv *btv)
2932 spin_lock(&btv->s_lock);
2934 if (!list_empty(&btv->vcapture))
2935 new = list_entry(btv->vcapture.next, struct bttv_buffer, list);
2936 old = btv->cvbi;
2941 btv->framedrop++;
2943 bttv_irq_debug_low_latency(btv, rc);
2944 spin_unlock(&btv->s_lock);
2949 btv->cvbi = new;
2950 btv->loop_irq &= ~BT848_RISC_VBI;
2951 bttv_buffer_activate_vbi(btv, new);
2952 bttv_set_dma(btv, 0);
2954 bttv_irq_wakeup_vbi(btv, old, VB2_BUF_STATE_DONE);
2955 spin_unlock(&btv->s_lock);
2963 struct bttv *btv;
2966 btv=(struct bttv *)dev_id;
2983 btv->c.nr, count, btv->field_count,
3002 btv->field_count++;
3004 if ((astat & BT848_INT_GPINT) && btv->remote) {
3005 bttv_input_irq(btv);
3009 btv->i2c_done = stat;
3010 wake_up(&btv->i2c_queue);
3014 bttv_irq_switch_vbi(btv);
3017 bttv_irq_wakeup_top(btv);
3020 bttv_irq_switch_video(btv);
3022 if ((astat & BT848_INT_HLOCK) && btv->opt_automute)
3024 audio_mux_gpio(btv, btv->audio_input, btv->mute);
3028 btv->c.nr,
3035 bttv_print_riscaddr(btv);
3039 btv->c.nr, btread(BT848_RISC_COUNT));
3041 bttv_print_riscaddr(btv);
3051 btv->c.nr);
3054 btv->c.nr);
3065 btv->irq_total++;
3067 btv->irq_me++;
3075 static int vdev_init(struct bttv *btv, struct video_device *vfd,
3082 vfd->v4l2_dev = &btv->c.v4l2_dev;
3084 video_set_drvdata(vfd, btv);
3086 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
3087 type_name, bttv_tvcards[btv->c.type].name);
3088 if (btv->tuner_type == TUNER_ABSENT) {
3099 q = &btv->capq;
3103 q = &btv->vbiq;
3112 q->drv_priv = btv;
3115 q->lock = &btv->lock;
3117 q->dev = &btv->c.pci->dev;
3126 static void bttv_unregister_video(struct bttv *btv)
3128 video_unregister_device(&btv->video_dev);
3129 video_unregister_device(&btv->vbi_dev);
3130 video_unregister_device(&btv->radio_dev);
3134 static int bttv_register_video(struct bttv *btv)
3137 vdev_init(btv, &btv->video_dev, &bttv_video_template, "video");
3138 btv->video_dev.device_caps = V4L2_CAP_VIDEO_CAPTURE |
3140 if (btv->tuner_type != TUNER_ABSENT)
3141 btv->video_dev.device_caps |= V4L2_CAP_TUNER;
3143 if (video_register_device(&btv->video_dev, VFL_TYPE_VIDEO,
3144 video_nr[btv->c.nr]) < 0)
3147 btv->c.nr, video_device_node_name(&btv->video_dev));
3148 if (device_create_file(&btv->video_dev.dev,
3150 pr_err("%d: device_create_file 'card' failed\n", btv->c.nr);
3155 vdev_init(btv, &btv->vbi_dev, &bttv_video_template, "vbi");
3156 btv->vbi_dev.device_caps = V4L2_CAP_VBI_CAPTURE | V4L2_CAP_READWRITE |
3158 if (btv->tuner_type != TUNER_ABSENT)
3159 btv->vbi_dev.device_caps |= V4L2_CAP_TUNER;
3161 if (video_register_device(&btv->vbi_dev, VFL_TYPE_VBI,
3162 vbi_nr[btv->c.nr]) < 0)
3165 btv->c.nr, video_device_node_name(&btv->vbi_dev));
3167 if (!btv->has_radio)
3170 vdev_init(btv, &btv->radio_dev, &radio_template, "radio");
3171 btv->radio_dev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
3172 if (btv->has_saa6588)
3173 btv->radio_dev.device_caps |= V4L2_CAP_READWRITE |
3175 if (btv->has_tea575x)
3176 btv->radio_dev.device_caps |= V4L2_CAP_HW_FREQ_SEEK;
3177 btv->radio_dev.ctrl_handler = &btv->radio_ctrl_handler;
3178 if (video_register_device(&btv->radio_dev, VFL_TYPE_RADIO,
3179 radio_nr[btv->c.nr]) < 0)
3182 btv->c.nr, video_device_node_name(&btv->radio_dev));
3188 bttv_unregister_video(btv);
3215 struct bttv *btv;
3221 bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL);
3222 if (btv == NULL) {
3226 btv->c.nr = bttv_num;
3227 snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name),
3228 "bttv%d", btv->c.nr);
3231 mutex_init(&btv->lock);
3232 spin_lock_init(&btv->s_lock);
3233 spin_lock_init(&btv->gpio_lock);
3234 init_waitqueue_head(&btv->i2c_queue);
3235 INIT_LIST_HEAD(&btv->c.subs);
3236 INIT_LIST_HEAD(&btv->capture);
3237 INIT_LIST_HEAD(&btv->vcapture);
3239 timer_setup(&btv->timeout, bttv_irq_timeout, 0);
3241 btv->i2c_rc = -1;
3242 btv->tuner_type = UNSET;
3243 btv->new_input = UNSET;
3244 btv->has_radio=radio[btv->c.nr];
3247 btv->c.pci = dev;
3248 btv->id = dev->device;
3250 pr_warn("%d: Can't enable device\n", btv->c.nr);
3255 pr_warn("%d: No suitable DMA available\n", btv->c.nr);
3261 btv->c.v4l2_dev.name)) {
3263 btv->c.nr,
3271 result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev);
3273 pr_warn("%d: v4l2_device_register() failed\n", btv->c.nr);
3276 hdl = &btv->ctrl_handler;
3278 btv->c.v4l2_dev.ctrl_handler = hdl;
3279 v4l2_ctrl_handler_init(&btv->radio_ctrl_handler, 6);
3281 btv->revision = dev->revision;
3284 bttv_num, btv->id, btv->revision, pci_name(dev),
3285 btv->c.pci->irq, lat,
3289 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
3290 if (NULL == btv->bt848_mmio) {
3291 pr_err("%d: ioremap() failed\n", btv->c.nr);
3297 bttv_idcard(btv);
3301 result = request_irq(btv->c.pci->irq, bttv_irq,
3302 IRQF_SHARED, btv->c.v4l2_dev.name, (void *)btv);
3305 bttv_num, btv->c.pci->irq);
3309 if (0 != bttv_handle_chipset(btv)) {
3315 btv->opt_combfilter = combfilter;
3318 btv->opt_automute = automute;
3321 btv->opt_vcr_hack = vcr_hack;
3325 btv->opt_uv_ratio = uv_ratio;
3331 btv->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
3332 btv->width = 320;
3333 btv->height = 240;
3334 btv->field = V4L2_FIELD_INTERLACED;
3335 btv->input = 0;
3336 btv->tvnorm = 0; /* Index into bttv_tvnorms[] i.e. PAL. */
3337 bttv_vbi_fmt_reset(&btv->vbi_fmt, btv->tvnorm);
3338 btv->vbi_count[0] = VBI_DEFLINES;
3339 btv->vbi_count[1] = VBI_DEFLINES;
3340 btv->do_crop = 0;
3356 if (btv->volume_gpio)
3372 bttv_gpio_tracking(btv,"pre-init");
3374 bttv_risc_init_main(btv);
3375 init_bt848(btv);
3381 bttv_gpio_tracking(btv,"init");
3384 bttv_init_card1(btv);
3387 init_bttv_i2c(btv);
3390 bttv_init_card2(btv);
3391 bttv_init_tuner(btv);
3392 if (btv->tuner_type != TUNER_ABSENT) {
3393 bttv_set_frequency(btv, &init_freq);
3394 btv->radio_freq = 90500 * 16; /* 90.5Mhz default */
3396 btv->std = V4L2_STD_PAL;
3397 init_irqreg(btv);
3398 if (!bttv_tvcards[btv->c.type].no_video)
3405 audio_mute(btv, 1);
3408 if (!bttv_tvcards[btv->c.type].no_video) {
3409 v4l2_ctrl_add_handler(&btv->radio_ctrl_handler, hdl,
3411 if (btv->radio_ctrl_handler.error) {
3412 result = btv->radio_ctrl_handler.error;
3415 set_input(btv, btv->input, btv->tvnorm);
3416 bttv_crop_reset(&btv->crop[0], btv->tvnorm);
3417 btv->crop[1] = btv->crop[0]; /* current = default */
3418 disclaim_vbi_lines(btv);
3419 disclaim_video_lines(btv);
3420 bttv_register_video(btv);
3424 if (bttv_tvcards[btv->c.type].has_dvb) {
3425 bttv_sub_add_device(&btv->c, "dvb");
3426 request_modules(btv);
3430 init_bttv_i2c_ir(btv);
3431 bttv_input_init(btv);
3439 free_irq(btv->c.pci->irq,btv);
3442 v4l2_ctrl_handler_free(&btv->ctrl_handler);
3443 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler);
3444 v4l2_device_unregister(&btv->c.v4l2_dev);
3447 if (btv->bt848_mmio)
3448 iounmap(btv->bt848_mmio);
3449 release_mem_region(pci_resource_start(btv->c.pci,0),
3450 pci_resource_len(btv->c.pci,0));
3451 pci_disable_device(btv->c.pci);
3454 bttvs[btv->c.nr] = NULL;
3455 kfree(btv);
3462 struct bttv *btv = to_bttv(v4l2_dev);
3465 pr_info("%d: unloading\n", btv->c.nr);
3467 if (bttv_tvcards[btv->c.type].has_dvb)
3468 flush_request_modules(btv);
3476 bttv_gpio_tracking(btv,"cleanup");
3479 btv->shutdown=1;
3480 bttv_input_fini(btv);
3481 bttv_sub_del_devices(&btv->c);
3484 fini_bttv_i2c(btv);
3487 bttv_unregister_video(btv);
3490 v4l2_ctrl_handler_free(&btv->ctrl_handler);
3491 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler);
3492 btcx_riscmem_free(btv->c.pci,&btv->main);
3495 free_irq(btv->c.pci->irq,btv);
3496 del_timer_sync(&btv->timeout);
3497 iounmap(btv->bt848_mmio);
3498 release_mem_region(pci_resource_start(btv->c.pci,0),
3499 pci_resource_len(btv->c.pci,0));
3500 pci_disable_device(btv->c.pci);
3502 v4l2_device_unregister(&btv->c.v4l2_dev);
3503 bttvs[btv->c.nr] = NULL;
3504 kfree(btv);
3512 struct bttv *btv = to_bttv(v4l2_dev);
3516 dprintk("%d: suspend\n", btv->c.nr);
3519 spin_lock_irqsave(&btv->s_lock,flags);
3521 btv->state.video = btv->curr;
3522 btv->state.vbi = btv->cvbi;
3523 btv->state.loop_irq = btv->loop_irq;
3524 btv->curr = idle;
3525 btv->loop_irq = 0;
3526 bttv_buffer_activate_video(btv, &idle);
3527 bttv_buffer_activate_vbi(btv, NULL);
3528 bttv_set_dma(btv, 0);
3530 spin_unlock_irqrestore(&btv->s_lock,flags);
3533 btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN);
3534 btv->state.gpio_data = gpio_read();
3536 btv->state.disabled = 1;
3543 struct bttv *btv = to_bttv(v4l2_dev);
3546 dprintk("%d: resume\n", btv->c.nr);
3548 btv->state.disabled = 0;
3551 bttv_reinit_bt848(btv);
3552 gpio_inout(0xffffff, btv->state.gpio_enable);
3553 gpio_write(btv->state.gpio_data);
3556 spin_lock_irqsave(&btv->s_lock,flags);
3557 btv->curr = btv->state.video;
3558 btv->cvbi = btv->state.vbi;
3559 btv->loop_irq = btv->state.loop_irq;
3560 bttv_buffer_activate_video(btv, &btv->curr);
3561 bttv_buffer_activate_vbi(btv, btv->cvbi);
3562 bttv_set_dma(btv, 0);
3563 spin_unlock_irqrestore(&btv->s_lock,flags);