Lines Matching +full:pix +full:- +full:limits
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 bttv - Bt848 frame grabber driver
6 Copyright (C) 1996,97,98 Ralph Metzler <rjkm@thp.uni-koeln.de>
7 & Marcus Metzler <mocm@thp.uni-koeln.de>
8 (c) 1999-2002 Gerd Knorr <kraxel@bytesex.org>
14 (c) 2005-2006 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
38 #include <media/v4l2-common.h>
39 #include <media/v4l2-ioctl.h>
40 #include <media/v4l2-event.h>
42 #include <media/drv-intf/msp3400.h>
44 #include <linux/dma-mapping.h>
72 static int video_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
73 static int radio_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
74 static int vbi_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
137 MODULE_PARM_DESC(gbuffers, "number of capture buffers. range 2-32, default 8");
154 MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards");
170 /* ----------------------------------------------------------------------- */
178 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET); in card_show()
182 /* ----------------------------------------------------------------------- */
183 /* dvb auto-load setup */
187 request_module("dvb-bt8xx"); in request_module_async()
192 INIT_WORK(&dev->request_module_wk, request_module_async); in request_modules()
193 schedule_work(&dev->request_module_wk); in request_modules()
198 flush_work(&dev->request_module_wk); in flush_request_modules()
206 /* ----------------------------------------------------------------------- */
253 videostart0 ITU-R frame line number of the line corresponding
259 /* e.g. 23 * 2 to 23 * 2 + 576 in PAL-BGHI defrect. */ \
260 .cropcap.bounds.top = (videostart0) * 2 - (vdelay) + MIN_VDELAY, \
262 .cropcap.bounds.width = (totalwidth) - (minhdelayx1) - 4, \
263 .cropcap.bounds.height = (sheight) + (extraheight) + (vdelay) - \
273 /* PAL-BDGHI */
275 /* actually, max active PAL with HSCALE=0 is 948, NTSC is 768 - nil */
292 /* ITU-R frame line number of the first VBI line
365 .name = "PAL-Nc",
378 .sram = -1,
391 .name = "PAL-M",
404 .sram = -1,
417 .name = "PAL-N",
430 .sram = -1,
443 .name = "NTSC-JP",
456 .sram = -1,
472 .name = "PAL-60",
486 .sram = -1,
501 /* ----------------------------------------------------------------------- */
607 .fourcc = -1,
615 /* ----------------------------------------------------------------------- */
653 if (btv->resources & xbits) { in check_alloc_btres_lock()
659 && 0 == (btv->resources & VIDEO_RESOURCES)) { in check_alloc_btres_lock()
660 /* Do crop - use current, don't - use default parameters. */ in check_alloc_btres_lock()
661 __s32 top = btv->crop[!!btv->do_crop].rect.top; in check_alloc_btres_lock()
663 if (btv->vbi_end > top) in check_alloc_btres_lock()
668 btv->crop_start = top; in check_alloc_btres_lock()
670 __s32 end = btv->vbi_fmt.end; in check_alloc_btres_lock()
672 if (end > btv->crop_start) in check_alloc_btres_lock()
675 /* Claim scan lines above btv->vbi_fmt.end. */ in check_alloc_btres_lock()
676 btv->vbi_end = end; in check_alloc_btres_lock()
680 btv->resources |= bit; in check_alloc_btres_lock()
690 return (btv->resources & bit); in check_btres()
696 return (btv->resources & bit); in locked_btres()
699 /* Call with btv->lock down. */
703 btv->vbi_end = 0; in disclaim_vbi_lines()
706 /* Call with btv->lock down. */
713 tvnorm = &bttv_tvnorms[btv->tvnorm]; in disclaim_video_lines()
714 btv->crop_start = tvnorm->cropcap.bounds.top in disclaim_video_lines()
715 + tvnorm->cropcap.bounds.height; in disclaim_video_lines()
730 if ((btv->resources & bits) != bits) { in free_btres_lock()
734 btv->resources &= ~bits; in free_btres_lock()
736 bits = btv->resources; in free_btres_lock()
745 /* ----------------------------------------------------------------------- */
749 PLL_X = Reference pre-divider (0=1, 1=2)
784 if (!btv->pll.pll_crystal) in set_pll()
787 if (btv->pll.pll_ofreq == btv->pll.pll_current) { in set_pll()
788 dprintk("%d: PLL: no change required\n", btv->c.nr); in set_pll()
792 if (btv->pll.pll_ifreq == btv->pll.pll_ofreq) { in set_pll()
794 if (btv->pll.pll_current == 0) in set_pll()
798 btv->c.nr, btv->pll.pll_ifreq); in set_pll()
801 btv->pll.pll_current = 0; in set_pll()
807 btv->c.nr, in set_pll()
808 btv->pll.pll_ifreq, btv->pll.pll_ofreq); in set_pll()
809 set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq); in set_pll()
819 btv->pll.pll_current = btv->pll.pll_ofreq; in set_pll()
825 btv->pll.pll_current = -1; in set_pll()
835 int table_idx = bttv_tvnorms[btv->tvnorm].sram; in bt848A_set_timing()
836 int fsc = bttv_tvnorms[btv->tvnorm].Fsc; in bt848A_set_timing()
838 if (btv->input == btv->dig) { in bt848A_set_timing()
840 btv->c.nr,table_idx); in bt848A_set_timing()
850 btv->pll.pll_ofreq = 27000000; in bt848A_set_timing()
856 btv->pll.pll_ofreq = fsc; in bt848A_set_timing()
862 /* ----------------------------------------------------------------------- */
869 btv->bright = bright; in bt848_bright()
871 /* We want -128 to 127 we get 0-65535 */ in bt848_bright()
872 value = (bright >> 8) - 128; in bt848_bright()
880 btv->hue = hue; in bt848_hue()
882 /* -128 to 127 */ in bt848_hue()
883 value = (hue >> 8) - 128; in bt848_hue()
891 btv->contrast = cont; in bt848_contrast()
893 /* 0-511 */ in bt848_contrast()
905 btv->saturation = color; in bt848_sat()
907 /* 0-511 for the color */ in bt848_sat()
908 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7; in bt848_sat()
909 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254; in bt848_sat()
918 /* ----------------------------------------------------------------------- */
925 if (input >= bttv_tvcards[btv->c.type].video_inputs) in video_mux()
926 return -EINVAL; in video_mux()
929 mask2 = bttv_tvcards[btv->c.type].gpiomask2; in video_mux()
933 if (input == btv->svhs) { in video_mux()
942 dprintk("%d: video mux: input=%d mux=%d\n", btv->c.nr, input, mux); in video_mux()
945 if(bttv_tvcards[btv->c.type].muxsel_hook) in video_mux()
946 bttv_tvcards[btv->c.type].muxsel_hook (btv, input); in video_mux()
960 gpio_inout(bttv_tvcards[btv->c.type].gpiomask, in audio_mux_gpio()
961 bttv_tvcards[btv->c.type].gpiomask); in audio_mux_gpio()
965 mute_gpio = mute || (btv->opt_automute && (!signal || !btv->users) in audio_mux_gpio()
966 && !btv->has_radio_tuner); in audio_mux_gpio()
969 gpio_val = bttv_tvcards[btv->c.type].gpiomute; in audio_mux_gpio()
971 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input]; in audio_mux_gpio()
973 switch (btv->c.type) { in audio_mux_gpio()
980 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val); in audio_mux_gpio()
992 audio_mux_gpio(btv, btv->audio_input, mute); in audio_mute()
994 if (btv->sd_msp34xx) { in audio_mute()
995 ctrl = v4l2_ctrl_find(btv->sd_msp34xx->ctrl_handler, V4L2_CID_AUDIO_MUTE); in audio_mute()
999 if (btv->sd_tvaudio) { in audio_mute()
1000 ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE); in audio_mute()
1004 if (btv->sd_tda7432) { in audio_mute()
1005 ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE); in audio_mute()
1015 audio_mux_gpio(btv, input, btv->mute); in audio_input()
1017 if (btv->sd_msp34xx) { in audio_input()
1028 if (btv->radio_uses_msp_demodulator) { in audio_input()
1053 if (btv->c.type == BTTV_BOARD_VOODOOTV_200) in audio_input()
1060 v4l2_subdev_call(btv->sd_msp34xx, audio, s_routing, in audio_input()
1063 if (btv->sd_tvaudio) { in audio_input()
1064 v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing, in audio_input()
1079 c->min_scaled_width = 48; in bttv_crop_calc_limits()
1080 c->min_scaled_height = 32; in bttv_crop_calc_limits()
1082 c->min_scaled_width = in bttv_crop_calc_limits()
1083 (max_t(unsigned int, 48, c->rect.width >> 4) + 3) & ~3; in bttv_crop_calc_limits()
1084 c->min_scaled_height = in bttv_crop_calc_limits()
1085 max_t(unsigned int, 32, c->rect.height >> 4); in bttv_crop_calc_limits()
1088 c->max_scaled_width = c->rect.width & ~3; in bttv_crop_calc_limits()
1089 c->max_scaled_height = c->rect.height; in bttv_crop_calc_limits()
1095 c->rect = bttv_tvnorms[norm].cropcap.defrect; in bttv_crop_reset()
1099 /* Call with btv->lock down. */
1107 WARN_ON(btv->tvnorm >= BTTV_TVNORMS); in set_tvnorm()
1111 if (memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap, in set_tvnorm()
1112 sizeof (tvnorm->cropcap))) { in set_tvnorm()
1113 bttv_crop_reset(&btv->crop[0], norm); in set_tvnorm()
1114 btv->crop[1] = btv->crop[0]; /* current = default */ in set_tvnorm()
1116 if (0 == (btv->resources & VIDEO_RESOURCES)) { in set_tvnorm()
1117 btv->crop_start = tvnorm->cropcap.bounds.top in set_tvnorm()
1118 + tvnorm->cropcap.bounds.height; in set_tvnorm()
1122 btv->tvnorm = norm; in set_tvnorm()
1124 btwrite(tvnorm->adelay, BT848_ADELAY); in set_tvnorm()
1125 btwrite(tvnorm->bdelay, BT848_BDELAY); in set_tvnorm()
1126 btaor(tvnorm->iform,~(BT848_IFORM_NORM|BT848_IFORM_XTBOTH), in set_tvnorm()
1128 btwrite(tvnorm->vbipack, BT848_VBI_PACK_SIZE); in set_tvnorm()
1132 switch (btv->c.type) { in set_tvnorm()
1138 id = tvnorm->v4l2_id; in set_tvnorm()
1144 /* Call with btv->lock down. */
1150 btv->input = input; in set_input()
1152 spin_lock_irqsave(&btv->s_lock,flags); in set_input()
1153 if (btv->curr.frame_irq) { in set_input()
1154 /* active capture -> delayed input switch */ in set_input()
1155 btv->new_input = input; in set_input()
1159 spin_unlock_irqrestore(&btv->s_lock,flags); in set_input()
1163 btv->audio_input = (btv->tuner_type != TUNER_ABSENT && input == 0) ? in set_input()
1165 audio_input(btv, btv->audio_input); in set_input()
1174 if (bttv_tvcards[btv->c.type].no_video) { in init_irqreg()
1180 btwrite((btv->triton1) | in init_irqreg()
1181 (btv->gpioirq ? BT848_INT_GPINT : 0) | in init_irqreg()
1193 if (bttv_tvcards[btv->c.type].no_video) { in init_bt848()
1215 v4l2_ctrl_handler_setup(&btv->ctrl_handler); in init_bt848()
1226 pr_info("%d: reset, reinitialize\n", btv->c.nr); in bttv_reinit_bt848()
1227 spin_lock_irqsave(&btv->s_lock,flags); in bttv_reinit_bt848()
1228 btv->errors=0; in bttv_reinit_bt848()
1230 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_reinit_bt848()
1233 btv->pll.pll_current = -1; in bttv_reinit_bt848()
1234 set_input(btv, btv->input, btv->tvnorm); in bttv_reinit_bt848()
1239 struct bttv *btv = container_of(c->handler, struct bttv, ctrl_handler); in bttv_s_ctrl()
1242 switch (c->id) { in bttv_s_ctrl()
1244 bt848_bright(btv, c->val); in bttv_s_ctrl()
1247 bt848_hue(btv, c->val); in bttv_s_ctrl()
1250 bt848_contrast(btv, c->val); in bttv_s_ctrl()
1253 bt848_sat(btv, c->val); in bttv_s_ctrl()
1256 if (c->val) { in bttv_s_ctrl()
1265 audio_mute(btv, c->val); in bttv_s_ctrl()
1266 btv->mute = c->val; in bttv_s_ctrl()
1269 btv->volume_gpio(btv, c->val); in bttv_s_ctrl()
1273 val = c->val ? BT848_SCLOOP_CAGC : 0; in bttv_s_ctrl()
1278 btv->opt_combfilter = c->val; in bttv_s_ctrl()
1281 if (c->val) { in bttv_s_ctrl()
1290 btv->opt_automute = c->val; in bttv_s_ctrl()
1294 (c->val ? BT848_ADC_CRUSH : 0), in bttv_s_ctrl()
1298 btv->opt_vcr_hack = c->val; in bttv_s_ctrl()
1301 btwrite(c->val, BT848_WC_UP); in bttv_s_ctrl()
1304 btwrite(c->val, BT848_WC_DOWN); in bttv_s_ctrl()
1307 btv->opt_uv_ratio = c->val; in bttv_s_ctrl()
1308 bt848_sat(btv, btv->saturation); in bttv_s_ctrl()
1311 btaor((c->val << 7), ~BT848_OFORM_RANGE, BT848_OFORM); in bttv_s_ctrl()
1314 btaor((c->val << 5), ~BT848_OFORM_CORE32, BT848_OFORM); in bttv_s_ctrl()
1317 return -EINVAL; in bttv_s_ctrl()
1322 /* ----------------------------------------------------------------------- */
1437 /* ----------------------------------------------------------------------- */
1445 btv->c.nr, outbits, data & outbits, data & ~outbits, comment); in bttv_gpio_tracking()
1454 if (-1 == formats[i].fourcc) in format_by_fourcc()
1462 /* ----------------------------------------------------------------------- */
1470 unsigned int size = btv->fmt->depth * btv->width * btv->height >> 3; in queue_setup()
1473 return sizes[0] < size ? -EINVAL : 0; in queue_setup()
1483 struct vb2_queue *vq = vb->vb2_queue; in buf_queue()
1488 spin_lock_irqsave(&btv->s_lock, flags); in buf_queue()
1489 if (list_empty(&btv->capture)) { in buf_queue()
1490 btv->loop_irq = BT848_RISC_VIDEO; in buf_queue()
1491 if (vb2_is_streaming(&btv->vbiq)) in buf_queue()
1492 btv->loop_irq |= BT848_RISC_VBI; in buf_queue()
1496 list_add_tail(&buf->list, &btv->capture); in buf_queue()
1497 spin_unlock_irqrestore(&btv->s_lock, flags); in buf_queue()
1502 struct vb2_queue *vq = vb->vb2_queue; in buf_prepare()
1506 unsigned int size = (btv->fmt->depth * btv->width * btv->height) >> 3; in buf_prepare()
1509 return -EINVAL; in buf_prepare()
1512 if (btv->field != V4L2_FIELD_ALTERNATE) { in buf_prepare()
1513 buf->vbuf.field = btv->field; in buf_prepare()
1514 } else if (btv->field_last == V4L2_FIELD_TOP) { in buf_prepare()
1515 buf->vbuf.field = V4L2_FIELD_BOTTOM; in buf_prepare()
1516 btv->field_last = V4L2_FIELD_BOTTOM; in buf_prepare()
1518 buf->vbuf.field = V4L2_FIELD_TOP; in buf_prepare()
1519 btv->field_last = V4L2_FIELD_TOP; in buf_prepare()
1528 struct vb2_queue *vq = vb->vb2_queue; in buf_cleanup()
1533 btcx_riscmem_free(btv->c.pci, &buf->top); in buf_cleanup()
1534 btcx_riscmem_free(btv->c.pci, &buf->bottom); in buf_cleanup()
1544 if (btv->field_count) in start_streaming()
1546 while (!list_empty(&btv->capture)) { in start_streaming()
1547 buf = list_entry(btv->capture.next, in start_streaming()
1549 list_del(&buf->list); in start_streaming()
1550 buf->vbuf.sequence = (btv->field_count >> 1) + seqnr++; in start_streaming()
1551 vb2_buffer_done(&buf->vbuf.vb2_buf, in start_streaming()
1554 return -EBUSY; in start_streaming()
1556 if (!vb2_is_streaming(&btv->vbiq)) { in start_streaming()
1558 btv->field_count = 0; in start_streaming()
1560 btv->framedrop = 0; in start_streaming()
1571 spin_lock_irqsave(&btv->s_lock, flags); in stop_streaming()
1573 if (!vb2_is_streaming(&btv->vbiq)) { in stop_streaming()
1577 spin_unlock_irqrestore(&btv->s_lock, flags); in stop_streaming()
1594 if (!btv->has_radio_tuner) { in radio_enable()
1595 btv->has_radio_tuner = 1; in radio_enable()
1597 btv->audio_input = TVAUDIO_INPUT_RADIO; in radio_enable()
1598 audio_input(btv, btv->audio_input); in radio_enable()
1611 return -EINVAL; in bttv_s_std()
1612 btv->std = id; in bttv_s_std()
1621 *id = btv->std; in bttv_g_std()
1641 if (i->index >= bttv_tvcards[btv->c.type].video_inputs) in bttv_enum_input()
1642 return -EINVAL; in bttv_enum_input()
1644 i->type = V4L2_INPUT_TYPE_CAMERA; in bttv_enum_input()
1645 i->audioset = 0; in bttv_enum_input()
1647 if (btv->tuner_type != TUNER_ABSENT && i->index == 0) { in bttv_enum_input()
1648 sprintf(i->name, "Television"); in bttv_enum_input()
1649 i->type = V4L2_INPUT_TYPE_TUNER; in bttv_enum_input()
1650 i->tuner = 0; in bttv_enum_input()
1651 } else if (i->index == btv->svhs) { in bttv_enum_input()
1652 sprintf(i->name, "S-Video"); in bttv_enum_input()
1654 sprintf(i->name, "Composite%d", i->index); in bttv_enum_input()
1657 if (i->index == btv->input) { in bttv_enum_input()
1660 i->status |= V4L2_IN_ST_NO_SIGNAL; in bttv_enum_input()
1662 i->status |= V4L2_IN_ST_NO_H_LOCK; in bttv_enum_input()
1665 i->std = BTTV_NORMS; in bttv_enum_input()
1673 *i = btv->input; in bttv_g_input()
1682 if (i >= bttv_tvcards[btv->c.type].video_inputs) in bttv_s_input()
1683 return -EINVAL; in bttv_s_input()
1685 set_input(btv, i, btv->tvnorm); in bttv_s_input()
1694 if (t->index) in bttv_s_tuner()
1695 return -EINVAL; in bttv_s_tuner()
1699 if (btv->audio_mode_gpio) { in bttv_s_tuner()
1702 btv->audio_mode_gpio(btv, ©, 1); in bttv_s_tuner()
1712 if (f->tuner) in bttv_g_frequency()
1713 return -EINVAL; in bttv_g_frequency()
1715 if (f->type == V4L2_TUNER_RADIO) in bttv_g_frequency()
1717 f->frequency = f->type == V4L2_TUNER_RADIO ? in bttv_g_frequency()
1718 btv->radio_freq : btv->tv_freq; in bttv_g_frequency()
1733 btv->radio_freq = new_freq.frequency; in bttv_set_frequency()
1734 if (btv->has_tea575x) { in bttv_set_frequency()
1735 btv->tea.freq = btv->radio_freq; in bttv_set_frequency()
1736 snd_tea575x_set_freq(&btv->tea); in bttv_set_frequency()
1739 btv->tv_freq = new_freq.frequency; in bttv_set_frequency()
1748 if (f->tuner) in bttv_s_frequency()
1749 return -EINVAL; in bttv_s_frequency()
1760 v4l2_ctrl_handler_log_status(vdev->ctrl_handler, btv->c.v4l2_dev.name); in bttv_log_status()
1771 /* bt848 has a 12-bit register space */ in bttv_g_register()
1772 reg->reg &= 0xfff; in bttv_g_register()
1773 reg->val = btread(reg->reg); in bttv_g_register()
1774 reg->size = 1; in bttv_g_register()
1784 /* bt848 has a 12-bit register space */ in bttv_s_register()
1785 btwrite(reg->val, reg->reg & 0xfff); in bttv_s_register()
1792 single field or frame, which must not exceed hardware limits, this
1805 if (width < c->min_scaled_width) { in bttv_crop_adjust()
1807 c->rect.width = width * 16; in bttv_crop_adjust()
1808 } else if (width > c->max_scaled_width) { in bttv_crop_adjust()
1810 c->rect.width = width; in bttv_crop_adjust()
1812 max_left = b->left + b->width - width; in bttv_crop_adjust()
1814 if (c->rect.left > max_left) in bttv_crop_adjust()
1815 c->rect.left = max_left; in bttv_crop_adjust()
1818 if (height < c->min_scaled_height) { in bttv_crop_adjust()
1820 c->rect.height = height * 16; in bttv_crop_adjust()
1821 } else if (frame_height > c->max_scaled_height) { in bttv_crop_adjust()
1824 c->rect.height = (frame_height + 1) & ~1; in bttv_crop_adjust()
1826 max_top = b->top + b->height - c->rect.height; in bttv_crop_adjust()
1827 if (c->rect.top > max_top) in bttv_crop_adjust()
1828 c->rect.top = max_top; in bttv_crop_adjust()
1856 width_bias >= (unsigned int)(-width_mask)); in limit_scaled_size_lock()
1861 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; in limit_scaled_size_lock()
1863 /* Do crop - use current, don't - use default parameters. */ in limit_scaled_size_lock()
1864 c = &btv->crop[!!btv->do_crop]; in limit_scaled_size_lock()
1866 if (btv->do_crop in limit_scaled_size_lock()
1876 max_width = min_t(unsigned int, b->width, MAX_HACTIVE); in limit_scaled_size_lock()
1877 max_height = b->height; in limit_scaled_size_lock()
1880 Note btv->vbi_end is really a minimum, see in limit_scaled_size_lock()
1882 if (btv->vbi_end > b->top) { in limit_scaled_size_lock()
1883 max_height -= btv->vbi_end - b->top; in limit_scaled_size_lock()
1884 rc = -EBUSY; in limit_scaled_size_lock()
1889 rc = -EBUSY; in limit_scaled_size_lock()
1890 if (btv->vbi_end > c->rect.top) in limit_scaled_size_lock()
1893 min_width = c->min_scaled_width; in limit_scaled_size_lock()
1894 min_height = c->min_scaled_height; in limit_scaled_size_lock()
1895 max_width = c->max_scaled_width; in limit_scaled_size_lock()
1896 max_height = c->max_scaled_height; in limit_scaled_size_lock()
1901 min_width = (min_width - width_mask - 1) & width_mask; in limit_scaled_size_lock()
1918 if (btv->vbi_end > c->rect.top) { in limit_scaled_size_lock()
1920 c->rect.top = btv->vbi_end; in limit_scaled_size_lock()
1924 rc = -EINVAL; in limit_scaled_size_lock()
1947 q = &btv->capq; in bttv_switch_type()
1951 q = &btv->vbiq; in bttv_switch_type()
1956 return -EINVAL; in bttv_switch_type()
1960 return -EBUSY; in bttv_switch_type()
1962 return -EBUSY; in bttv_switch_type()
1963 btv->type = type; in bttv_switch_type()
1974 f->width = width; in pix_format_set_size()
1975 f->height = height; in pix_format_set_size()
1977 if (fmt->flags & FORMAT_FLAGS_PLANAR) { in pix_format_set_size()
1978 f->bytesperline = width; /* Y plane */ in pix_format_set_size()
1979 f->sizeimage = (width * height * fmt->depth) >> 3; in pix_format_set_size()
1981 f->bytesperline = (width * fmt->depth) >> 3; in pix_format_set_size()
1982 f->sizeimage = height * f->bytesperline; in pix_format_set_size()
1991 pix_format_set_size(&f->fmt.pix, btv->fmt, btv->width, btv->height); in bttv_g_fmt_vid_cap()
1992 f->fmt.pix.field = btv->field; in bttv_g_fmt_vid_cap()
1993 f->fmt.pix.pixelformat = btv->fmt->fourcc; in bttv_g_fmt_vid_cap()
1994 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in bttv_g_fmt_vid_cap()
2003 if (fmt->flags & FORMAT_FLAGS_PLANAR) { in bttv_get_width_mask_vid_cap()
2023 fmt = format_by_fourcc(f->fmt.pix.pixelformat); in bttv_try_fmt_vid_cap()
2025 return -EINVAL; in bttv_try_fmt_vid_cap()
2027 field = f->fmt.pix.field; in bttv_try_fmt_vid_cap()
2037 if (!(fmt->flags & FORMAT_FLAGS_PLANAR)) { in bttv_try_fmt_vid_cap()
2043 height2 = btv->crop[!!btv->do_crop].rect.height >> 1; in bttv_try_fmt_vid_cap()
2044 field = (f->fmt.pix.height > height2) in bttv_try_fmt_vid_cap()
2050 width = f->fmt.pix.width; in bttv_try_fmt_vid_cap()
2051 height = f->fmt.pix.height; in bttv_try_fmt_vid_cap()
2060 f->fmt.pix.field = field; in bttv_try_fmt_vid_cap()
2061 pix_format_set_size(&f->fmt.pix, fmt, width, height); in bttv_try_fmt_vid_cap()
2062 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in bttv_try_fmt_vid_cap()
2077 retval = bttv_switch_type(btv, f->type); in bttv_s_fmt_vid_cap()
2085 width = f->fmt.pix.width; in bttv_s_fmt_vid_cap()
2086 height = f->fmt.pix.height; in bttv_s_fmt_vid_cap()
2087 field = f->fmt.pix.field; in bttv_s_fmt_vid_cap()
2089 fmt = format_by_fourcc(f->fmt.pix.pixelformat); in bttv_s_fmt_vid_cap()
2091 retval = limit_scaled_size_lock(btv, &width, &height, f->fmt.pix.field, in bttv_s_fmt_vid_cap()
2096 f->fmt.pix.field = field; in bttv_s_fmt_vid_cap()
2099 btv->fmt = fmt; in bttv_s_fmt_vid_cap()
2100 btv->width = f->fmt.pix.width; in bttv_s_fmt_vid_cap()
2101 btv->height = f->fmt.pix.height; in bttv_s_fmt_vid_cap()
2102 btv->field = f->fmt.pix.field; in bttv_s_fmt_vid_cap()
2109 btv->field_last = V4L2_FIELD_BOTTOM; in bttv_s_fmt_vid_cap()
2120 return -EINVAL; in bttv_querycap()
2122 strscpy(cap->driver, "bttv", sizeof(cap->driver)); in bttv_querycap()
2123 strscpy(cap->card, btv->video_dev.name, sizeof(cap->card)); in bttv_querycap()
2124 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in bttv_querycap()
2126 if (video_is_registered(&btv->vbi_dev)) in bttv_querycap()
2127 cap->capabilities |= V4L2_CAP_VBI_CAPTURE; in bttv_querycap()
2128 if (video_is_registered(&btv->radio_dev)) { in bttv_querycap()
2129 cap->capabilities |= V4L2_CAP_RADIO; in bttv_querycap()
2130 if (btv->has_tea575x) in bttv_querycap()
2131 cap->capabilities |= V4L2_CAP_HW_FREQ_SEEK; in bttv_querycap()
2138 if (btv->has_saa6588) in bttv_querycap()
2139 cap->capabilities |= V4L2_CAP_RDS_CAPTURE; in bttv_querycap()
2140 if (btv->tuner_type != TUNER_ABSENT) in bttv_querycap()
2141 cap->capabilities |= V4L2_CAP_TUNER; in bttv_querycap()
2148 int index = -1, i; in bttv_enum_fmt_vid_cap()
2151 if (formats[i].fourcc != -1) in bttv_enum_fmt_vid_cap()
2153 if ((unsigned int)index == f->index) in bttv_enum_fmt_vid_cap()
2157 return -EINVAL; in bttv_enum_fmt_vid_cap()
2159 f->pixelformat = formats[i].fourcc; in bttv_enum_fmt_vid_cap()
2169 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in bttv_g_parm()
2170 return -EINVAL; in bttv_g_parm()
2171 parm->parm.capture.readbuffers = gbuffers; in bttv_g_parm()
2172 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id, in bttv_g_parm()
2173 &parm->parm.capture.timeperframe); in bttv_g_parm()
2183 if (0 != t->index) in bttv_g_tuner()
2184 return -EINVAL; in bttv_g_tuner()
2186 t->rxsubchans = V4L2_TUNER_SUB_MONO; in bttv_g_tuner()
2187 t->capability = V4L2_TUNER_CAP_NORM; in bttv_g_tuner()
2189 strscpy(t->name, "Television", sizeof(t->name)); in bttv_g_tuner()
2190 t->type = V4L2_TUNER_ANALOG_TV; in bttv_g_tuner()
2192 t->signal = 0xffff; in bttv_g_tuner()
2194 if (btv->audio_mode_gpio) in bttv_g_tuner()
2195 btv->audio_mode_gpio(btv, t, 0); in bttv_g_tuner()
2206 return -EINVAL; in bttv_g_pixelaspect()
2209 *f = bttv_tvnorms[btv->tvnorm].cropcap.pixelaspect; in bttv_g_pixelaspect()
2217 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in bttv_g_selection()
2218 return -EINVAL; in bttv_g_selection()
2220 switch (sel->target) { in bttv_g_selection()
2222 sel->r = btv->crop[!!btv->do_crop].rect; in bttv_g_selection()
2225 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.defrect; in bttv_g_selection()
2228 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.bounds; in bttv_g_selection()
2231 return -EINVAL; in bttv_g_selection()
2248 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in bttv_s_selection()
2249 return -EINVAL; in bttv_s_selection()
2251 if (sel->target != V4L2_SEL_TGT_CROP) in bttv_s_selection()
2252 return -EINVAL; in bttv_s_selection()
2257 retval = -EBUSY; in bttv_s_selection()
2262 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; in bttv_s_selection()
2264 b_left = b->left; in bttv_s_selection()
2265 b_right = b_left + b->width; in bttv_s_selection()
2266 b_bottom = b->top + b->height; in bttv_s_selection()
2268 b_top = max(b->top, btv->vbi_end); in bttv_s_selection()
2274 c.rect.left = clamp_t(s32, sel->r.left, b_left, b_right - 48); in bttv_s_selection()
2277 c.rect.width = clamp_t(s32, sel->r.width, in bttv_s_selection()
2278 48, b_right - c.rect.left); in bttv_s_selection()
2280 c.rect.top = clamp_t(s32, sel->r.top, b_top, b_bottom - 32); in bttv_s_selection()
2284 c.rect.height = clamp_t(s32, sel->r.height, in bttv_s_selection()
2285 32, b_bottom - c.rect.top); in bttv_s_selection()
2290 sel->r = c.rect; in bttv_s_selection()
2292 btv->crop[1] = c; in bttv_s_selection()
2294 btv->do_crop = 1; in bttv_s_selection()
2296 if (btv->width < c.min_scaled_width) in bttv_s_selection()
2297 btv->width = c.min_scaled_width; in bttv_s_selection()
2298 else if (btv->width > c.max_scaled_width) in bttv_s_selection()
2299 btv->width = c.max_scaled_width; in bttv_s_selection()
2301 if (btv->height < c.min_scaled_height) in bttv_s_selection()
2302 btv->height = c.min_scaled_height; in bttv_s_selection()
2303 else if (btv->height > c.max_scaled_height) in bttv_s_selection()
2304 btv->height = c.max_scaled_height; in bttv_s_selection()
2365 /* ----------------------------------------------------------------------- */
2378 dprintk("%d: open called (radio)\n", btv->c.nr); in radio_open()
2380 btv->radio_user++; in radio_open()
2381 audio_mute(btv, btv->mute); in radio_open()
2391 btv->radio_user--; in radio_release()
2395 if (btv->radio_user == 0) in radio_release()
2396 btv->has_radio_tuner = 0; in radio_release()
2407 if (0 != t->index) in radio_g_tuner()
2408 return -EINVAL; in radio_g_tuner()
2409 strscpy(t->name, "Radio", sizeof(t->name)); in radio_g_tuner()
2410 t->type = V4L2_TUNER_RADIO; in radio_g_tuner()
2415 if (btv->audio_mode_gpio) in radio_g_tuner()
2416 btv->audio_mode_gpio(btv, t, 0); in radio_g_tuner()
2418 if (btv->has_tea575x) in radio_g_tuner()
2419 return snd_tea575x_g_tuner(&btv->tea, t); in radio_g_tuner()
2429 if (0 != t->index) in radio_s_tuner()
2430 return -EINVAL; in radio_s_tuner()
2442 if (btv->has_tea575x) in radio_s_hw_freq_seek()
2443 return snd_tea575x_s_hw_freq_seek(file, &btv->tea, a); in radio_s_hw_freq_seek()
2445 return -ENOTTY; in radio_s_hw_freq_seek()
2453 if (btv->has_tea575x) in radio_enum_freq_bands()
2454 return snd_tea575x_enum_freq_bands(&btv->tea, band); in radio_enum_freq_bands()
2456 return -ENOTTY; in radio_enum_freq_bands()
2466 cmd.nonblocking = file->f_flags & O_NONBLOCK; in radio_read()
2469 cmd.result = -ENODEV; in radio_read()
2520 /* ----------------------------------------------------------------------- */
2553 for (i = ARRAY_SIZE(bits)-1; i >= 0; i--) in bttv_risc_decode()
2566 btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma); in bttv_risc_disasm()
2567 for (i = 0; i < (risc->size >> 2); i += n) { in bttv_risc_disasm()
2569 btv->c.v4l2_dev.name, in bttv_risc_disasm()
2570 (unsigned long)(risc->dma + (i<<2))); in bttv_risc_disasm()
2571 n = bttv_risc_decode(le32_to_cpu(risc->cpu[i])); in bttv_risc_disasm()
2574 btv->c.v4l2_dev.name, in bttv_risc_disasm()
2575 (unsigned long)(risc->dma + ((i+j)<<2)), in bttv_risc_disasm()
2576 risc->cpu[i+j], j); in bttv_risc_disasm()
2577 if (0 == risc->cpu[i]) in bttv_risc_disasm()
2584 pr_info(" main: %08llx\n", (unsigned long long)btv->main.dma); in bttv_print_riscaddr()
2586 btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0, in bttv_print_riscaddr()
2587 btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0); in bttv_print_riscaddr()
2589 btv->curr.top in bttv_print_riscaddr()
2590 ? (unsigned long long)btv->curr.top->top.dma : 0, in bttv_print_riscaddr()
2591 btv->curr.bottom in bttv_print_riscaddr()
2592 ? (unsigned long long)btv->curr.bottom->bottom.dma : 0); in bttv_print_riscaddr()
2593 bttv_risc_disasm(btv, &btv->main); in bttv_print_riscaddr()
2596 /* ----------------------------------------------------------------------- */
2637 btv->c.nr, in bttv_irq_debug_low_latency()
2638 (unsigned long)btv->main.dma, in bttv_irq_debug_low_latency()
2639 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]), in bttv_irq_debug_low_latency()
2640 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]), in bttv_irq_debug_low_latency()
2645 btv->c.nr); in bttv_irq_debug_low_latency()
2649 btv->c.nr); in bttv_irq_debug_low_latency()
2650 pr_notice("%d: Lets try to catch the culprit red-handed ...\n", in bttv_irq_debug_low_latency()
2651 btv->c.nr); in bttv_irq_debug_low_latency()
2663 if (!list_empty(&btv->capture)) { in bttv_irq_next_video()
2664 set->frame_irq = BT848_RISC_VIDEO; in bttv_irq_next_video()
2665 item = list_entry(btv->capture.next, struct bttv_buffer, list); in bttv_irq_next_video()
2667 if (V4L2_FIELD_HAS_TOP(item->vbuf.field)) in bttv_irq_next_video()
2668 set->top = item; in bttv_irq_next_video()
2669 if (V4L2_FIELD_HAS_BOTTOM(item->vbuf.field)) in bttv_irq_next_video()
2670 set->bottom = item; in bttv_irq_next_video()
2673 if (!V4L2_FIELD_HAS_BOTH(item->vbuf.field) && in bttv_irq_next_video()
2674 item->list.next != &btv->capture) { in bttv_irq_next_video()
2675 item = list_entry(item->list.next, in bttv_irq_next_video()
2677 /* Mike Isely <isely@pobox.com> - Only check in bttv_irq_next_video()
2692 * field first - the effect will be the two in bttv_irq_next_video()
2704 if (!V4L2_FIELD_HAS_BOTH(item->vbuf.field)) { in bttv_irq_next_video()
2705 if (!set->bottom && in bttv_irq_next_video()
2706 item->vbuf.field == V4L2_FIELD_BOTTOM) in bttv_irq_next_video()
2707 set->bottom = item; in bttv_irq_next_video()
2708 if (set->top && set->bottom) { in bttv_irq_next_video()
2714 set->top_irq = BT848_RISC_TOP; in bttv_irq_next_video()
2721 btv->c.nr, set->top, set->bottom, in bttv_irq_next_video()
2722 set->frame_irq, set->top_irq); in bttv_irq_next_video()
2732 if (wakeup->top == wakeup->bottom) { in bttv_irq_wakeup_video()
2733 if (NULL != wakeup->top && curr->top != wakeup->top) { in bttv_irq_wakeup_video()
2736 btv->c.nr, wakeup->top); in bttv_irq_wakeup_video()
2737 wakeup->top->vbuf.vb2_buf.timestamp = ts; in bttv_irq_wakeup_video()
2738 wakeup->top->vbuf.sequence = btv->field_count >> 1; in bttv_irq_wakeup_video()
2739 vb2_buffer_done(&wakeup->top->vbuf.vb2_buf, state); in bttv_irq_wakeup_video()
2740 if (btv->field_count == 0) in bttv_irq_wakeup_video()
2744 if (NULL != wakeup->top && curr->top != wakeup->top) { in bttv_irq_wakeup_video()
2747 btv->c.nr, wakeup->top); in bttv_irq_wakeup_video()
2748 wakeup->top->vbuf.vb2_buf.timestamp = ts; in bttv_irq_wakeup_video()
2749 wakeup->top->vbuf.sequence = btv->field_count >> 1; in bttv_irq_wakeup_video()
2750 vb2_buffer_done(&wakeup->top->vbuf.vb2_buf, state); in bttv_irq_wakeup_video()
2751 if (btv->field_count == 0) in bttv_irq_wakeup_video()
2754 if (NULL != wakeup->bottom && curr->bottom != wakeup->bottom) { in bttv_irq_wakeup_video()
2757 btv->c.nr, wakeup->bottom); in bttv_irq_wakeup_video()
2758 wakeup->bottom->vbuf.vb2_buf.timestamp = ts; in bttv_irq_wakeup_video()
2759 wakeup->bottom->vbuf.sequence = btv->field_count >> 1; in bttv_irq_wakeup_video()
2760 vb2_buffer_done(&wakeup->bottom->vbuf.vb2_buf, state); in bttv_irq_wakeup_video()
2761 if (btv->field_count == 0) in bttv_irq_wakeup_video()
2773 wakeup->vbuf.vb2_buf.timestamp = ktime_get_ns(); in bttv_irq_wakeup_vbi()
2774 wakeup->vbuf.sequence = btv->field_count >> 1; in bttv_irq_wakeup_vbi()
2785 if (vb2_fileio_is_active(wakeup->vbuf.vb2_buf.vb2_queue)) { in bttv_irq_wakeup_vbi()
2786 u32 *vaddr = vb2_plane_vaddr(&wakeup->vbuf.vb2_buf, 0); in bttv_irq_wakeup_vbi()
2788 vb2_get_plane_payload(&wakeup->vbuf.vb2_buf, 0) / 4; in bttv_irq_wakeup_vbi()
2791 vaddr += size - 1; in bttv_irq_wakeup_vbi()
2792 *vaddr = wakeup->vbuf.sequence; in bttv_irq_wakeup_vbi()
2796 vb2_buffer_done(&wakeup->vbuf.vb2_buf, state); in bttv_irq_wakeup_vbi()
2797 if (btv->field_count == 0) in bttv_irq_wakeup_vbi()
2812 btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total, in bttv_irq_timeout()
2818 spin_lock_irqsave(&btv->s_lock,flags); in bttv_irq_timeout()
2822 old = btv->curr; in bttv_irq_timeout()
2823 ovbi = btv->cvbi; in bttv_irq_timeout()
2824 btv->curr = new; in bttv_irq_timeout()
2825 btv->cvbi = NULL; in bttv_irq_timeout()
2826 btv->loop_irq = 0; in bttv_irq_timeout()
2836 if (btv->field_count) in bttv_irq_timeout()
2838 while (!list_empty(&btv->capture)) { in bttv_irq_timeout()
2839 item = list_entry(btv->capture.next, struct bttv_buffer, list); in bttv_irq_timeout()
2840 list_del(&item->list); in bttv_irq_timeout()
2841 item->vbuf.vb2_buf.timestamp = ktime_get_ns(); in bttv_irq_timeout()
2842 item->vbuf.sequence = (btv->field_count >> 1) + seqnr++; in bttv_irq_timeout()
2843 vb2_buffer_done(&item->vbuf.vb2_buf, VB2_BUF_STATE_ERROR); in bttv_irq_timeout()
2845 while (!list_empty(&btv->vcapture)) { in bttv_irq_timeout()
2846 item = list_entry(btv->vcapture.next, struct bttv_buffer, list); in bttv_irq_timeout()
2847 list_del(&item->list); in bttv_irq_timeout()
2848 item->vbuf.vb2_buf.timestamp = ktime_get_ns(); in bttv_irq_timeout()
2849 item->vbuf.sequence = (btv->field_count >> 1) + seqnr++; in bttv_irq_timeout()
2850 vb2_buffer_done(&item->vbuf.vb2_buf, VB2_BUF_STATE_ERROR); in bttv_irq_timeout()
2853 btv->errors++; in bttv_irq_timeout()
2854 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_irq_timeout()
2860 struct bttv_buffer *wakeup = btv->curr.top; in bttv_irq_wakeup_top()
2865 spin_lock(&btv->s_lock); in bttv_irq_wakeup_top()
2866 btv->curr.top_irq = 0; in bttv_irq_wakeup_top()
2867 btv->curr.top = NULL; in bttv_irq_wakeup_top()
2869 wakeup->vbuf.vb2_buf.timestamp = ktime_get_ns(); in bttv_irq_wakeup_top()
2870 wakeup->vbuf.sequence = btv->field_count >> 1; in bttv_irq_wakeup_top()
2871 vb2_buffer_done(&wakeup->vbuf.vb2_buf, VB2_BUF_STATE_DONE); in bttv_irq_wakeup_top()
2872 if (btv->field_count == 0) in bttv_irq_wakeup_top()
2874 spin_unlock(&btv->s_lock); in bttv_irq_wakeup_top()
2879 if (rc < risc->dma) in is_active()
2881 if (rc > risc->dma + risc->size) in is_active()
2893 spin_lock(&btv->s_lock); in bttv_irq_switch_video()
2898 if ((btv->curr.top && is_active(&btv->curr.top->top, rc)) || in bttv_irq_switch_video()
2899 (btv->curr.bottom && is_active(&btv->curr.bottom->bottom, rc))) { in bttv_irq_switch_video()
2900 btv->framedrop++; in bttv_irq_switch_video()
2903 spin_unlock(&btv->s_lock); in bttv_irq_switch_video()
2908 old = btv->curr; in bttv_irq_switch_video()
2909 btv->curr = new; in bttv_irq_switch_video()
2910 btv->loop_irq &= ~BT848_RISC_VIDEO; in bttv_irq_switch_video()
2915 if (UNSET != btv->new_input) { in bttv_irq_switch_video()
2916 video_mux(btv,btv->new_input); in bttv_irq_switch_video()
2917 btv->new_input = UNSET; in bttv_irq_switch_video()
2922 spin_unlock(&btv->s_lock); in bttv_irq_switch_video()
2932 spin_lock(&btv->s_lock); in bttv_irq_switch_vbi()
2934 if (!list_empty(&btv->vcapture)) in bttv_irq_switch_vbi()
2935 new = list_entry(btv->vcapture.next, struct bttv_buffer, list); in bttv_irq_switch_vbi()
2936 old = btv->cvbi; in bttv_irq_switch_vbi()
2939 if (NULL != old && (is_active(&old->top, rc) || in bttv_irq_switch_vbi()
2940 is_active(&old->bottom, rc))) { in bttv_irq_switch_vbi()
2941 btv->framedrop++; in bttv_irq_switch_vbi()
2944 spin_unlock(&btv->s_lock); in bttv_irq_switch_vbi()
2949 btv->cvbi = new; in bttv_irq_switch_vbi()
2950 btv->loop_irq &= ~BT848_RISC_VBI; in bttv_irq_switch_vbi()
2955 spin_unlock(&btv->s_lock); in bttv_irq_switch_vbi()
2983 btv->c.nr, count, btv->field_count, in bttv_irq()
3002 btv->field_count++; in bttv_irq()
3004 if ((astat & BT848_INT_GPINT) && btv->remote) { in bttv_irq()
3009 btv->i2c_done = stat; in bttv_irq()
3010 wake_up(&btv->i2c_queue); in bttv_irq()
3022 if ((astat & BT848_INT_HLOCK) && btv->opt_automute) in bttv_irq()
3024 audio_mux_gpio(btv, btv->audio_input, btv->mute); in bttv_irq()
3028 btv->c.nr, in bttv_irq()
3039 btv->c.nr, btread(BT848_RISC_COUNT)); in bttv_irq()
3051 btv->c.nr); in bttv_irq()
3054 btv->c.nr); in bttv_irq()
3056 btwrite(btread(BT848_INT_MASK) & (-1 ^ BT848_INT_GPINT), in bttv_irq()
3065 btv->irq_total++; in bttv_irq()
3067 btv->irq_me++; in bttv_irq()
3072 /* ----------------------------------------------------------------------- */
3082 vfd->v4l2_dev = &btv->c.v4l2_dev; in vdev_init()
3083 vfd->release = video_device_release_empty; in vdev_init()
3085 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", in vdev_init()
3086 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", in vdev_init()
3087 type_name, bttv_tvcards[btv->c.type].name); in vdev_init()
3088 if (btv->tuner_type == TUNER_ABSENT) { in vdev_init()
3099 q = &btv->capq; in vdev_init()
3100 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in vdev_init()
3101 q->ops = &bttv_video_qops; in vdev_init()
3103 q = &btv->vbiq; in vdev_init()
3104 q->type = V4L2_BUF_TYPE_VBI_CAPTURE; in vdev_init()
3105 q->ops = &bttv_vbi_qops; in vdev_init()
3107 return -EINVAL; in vdev_init()
3109 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in vdev_init()
3110 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ | VB2_DMABUF; in vdev_init()
3111 q->mem_ops = &vb2_dma_sg_memops; in vdev_init()
3112 q->drv_priv = btv; in vdev_init()
3113 q->gfp_flags = __GFP_DMA32; in vdev_init()
3114 q->buf_struct_size = sizeof(struct bttv_buffer); in vdev_init()
3115 q->lock = &btv->lock; in vdev_init()
3116 q->min_queued_buffers = 2; in vdev_init()
3117 q->dev = &btv->c.pci->dev; in vdev_init()
3121 vfd->queue = q; in vdev_init()
3128 video_unregister_device(&btv->video_dev); in bttv_unregister_video()
3129 video_unregister_device(&btv->vbi_dev); in bttv_unregister_video()
3130 video_unregister_device(&btv->radio_dev); in bttv_unregister_video()
3137 vdev_init(btv, &btv->video_dev, &bttv_video_template, "video"); in bttv_register_video()
3138 btv->video_dev.device_caps = V4L2_CAP_VIDEO_CAPTURE | in bttv_register_video()
3140 if (btv->tuner_type != TUNER_ABSENT) in bttv_register_video()
3141 btv->video_dev.device_caps |= V4L2_CAP_TUNER; in bttv_register_video()
3143 if (video_register_device(&btv->video_dev, VFL_TYPE_VIDEO, in bttv_register_video()
3144 video_nr[btv->c.nr]) < 0) in bttv_register_video()
3147 btv->c.nr, video_device_node_name(&btv->video_dev)); in bttv_register_video()
3148 if (device_create_file(&btv->video_dev.dev, in bttv_register_video()
3150 pr_err("%d: device_create_file 'card' failed\n", btv->c.nr); in bttv_register_video()
3155 vdev_init(btv, &btv->vbi_dev, &bttv_video_template, "vbi"); in bttv_register_video()
3156 btv->vbi_dev.device_caps = V4L2_CAP_VBI_CAPTURE | V4L2_CAP_READWRITE | in bttv_register_video()
3158 if (btv->tuner_type != TUNER_ABSENT) in bttv_register_video()
3159 btv->vbi_dev.device_caps |= V4L2_CAP_TUNER; in bttv_register_video()
3161 if (video_register_device(&btv->vbi_dev, VFL_TYPE_VBI, in bttv_register_video()
3162 vbi_nr[btv->c.nr]) < 0) in bttv_register_video()
3165 btv->c.nr, video_device_node_name(&btv->vbi_dev)); in bttv_register_video()
3167 if (!btv->has_radio) in bttv_register_video()
3170 vdev_init(btv, &btv->radio_dev, &radio_template, "radio"); in bttv_register_video()
3171 btv->radio_dev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER; in bttv_register_video()
3172 if (btv->has_saa6588) in bttv_register_video()
3173 btv->radio_dev.device_caps |= V4L2_CAP_READWRITE | in bttv_register_video()
3175 if (btv->has_tea575x) in bttv_register_video()
3176 btv->radio_dev.device_caps |= V4L2_CAP_HW_FREQ_SEEK; in bttv_register_video()
3177 btv->radio_dev.ctrl_handler = &btv->radio_ctrl_handler; in bttv_register_video()
3178 if (video_register_device(&btv->radio_dev, VFL_TYPE_RADIO, in bttv_register_video()
3179 radio_nr[btv->c.nr]) < 0) in bttv_register_video()
3182 btv->c.nr, video_device_node_name(&btv->radio_dev)); in bttv_register_video()
3189 return -1; in bttv_register_video()
3219 return -ENOMEM; in bttv_probe()
3224 return -ENOMEM; in bttv_probe()
3226 btv->c.nr = bttv_num; in bttv_probe()
3227 snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name), in bttv_probe()
3228 "bttv%d", btv->c.nr); in bttv_probe()
3231 mutex_init(&btv->lock); in bttv_probe()
3232 spin_lock_init(&btv->s_lock); in bttv_probe()
3233 spin_lock_init(&btv->gpio_lock); in bttv_probe()
3234 init_waitqueue_head(&btv->i2c_queue); in bttv_probe()
3235 INIT_LIST_HEAD(&btv->c.subs); in bttv_probe()
3236 INIT_LIST_HEAD(&btv->capture); in bttv_probe()
3237 INIT_LIST_HEAD(&btv->vcapture); in bttv_probe()
3239 timer_setup(&btv->timeout, bttv_irq_timeout, 0); in bttv_probe()
3241 btv->i2c_rc = -1; in bttv_probe()
3242 btv->tuner_type = UNSET; in bttv_probe()
3243 btv->new_input = UNSET; in bttv_probe()
3244 btv->has_radio=radio[btv->c.nr]; in bttv_probe()
3247 btv->c.pci = dev; in bttv_probe()
3248 btv->id = dev->device; in bttv_probe()
3250 pr_warn("%d: Can't enable device\n", btv->c.nr); in bttv_probe()
3251 result = -EIO; in bttv_probe()
3254 if (dma_set_mask(&dev->dev, DMA_BIT_MASK(32))) { in bttv_probe()
3255 pr_warn("%d: No suitable DMA available\n", btv->c.nr); in bttv_probe()
3256 result = -EIO; in bttv_probe()
3261 btv->c.v4l2_dev.name)) { in bttv_probe()
3263 btv->c.nr, in bttv_probe()
3265 result = -EBUSY; in bttv_probe()
3271 result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev); in bttv_probe()
3273 pr_warn("%d: v4l2_device_register() failed\n", btv->c.nr); in bttv_probe()
3276 hdl = &btv->ctrl_handler; in bttv_probe()
3278 btv->c.v4l2_dev.ctrl_handler = hdl; in bttv_probe()
3279 v4l2_ctrl_handler_init(&btv->radio_ctrl_handler, 6); in bttv_probe()
3281 btv->revision = dev->revision; in bttv_probe()
3284 bttv_num, btv->id, btv->revision, pci_name(dev), in bttv_probe()
3285 btv->c.pci->irq, lat, in bttv_probe()
3289 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000); in bttv_probe()
3290 if (NULL == btv->bt848_mmio) { in bttv_probe()
3291 pr_err("%d: ioremap() failed\n", btv->c.nr); in bttv_probe()
3292 result = -EIO; in bttv_probe()
3301 result = request_irq(btv->c.pci->irq, bttv_irq, in bttv_probe()
3302 IRQF_SHARED, btv->c.v4l2_dev.name, (void *)btv); in bttv_probe()
3305 bttv_num, btv->c.pci->irq); in bttv_probe()
3310 result = -EIO; in bttv_probe()
3315 btv->opt_combfilter = combfilter; in bttv_probe()
3318 btv->opt_automute = automute; in bttv_probe()
3321 btv->opt_vcr_hack = vcr_hack; in bttv_probe()
3325 btv->opt_uv_ratio = uv_ratio; in bttv_probe()
3331 btv->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); in bttv_probe()
3332 btv->width = 320; in bttv_probe()
3333 btv->height = 240; in bttv_probe()
3334 btv->field = V4L2_FIELD_INTERLACED; in bttv_probe()
3335 btv->input = 0; in bttv_probe()
3336 btv->tvnorm = 0; /* Index into bttv_tvnorms[] i.e. PAL. */ in bttv_probe()
3337 bttv_vbi_fmt_reset(&btv->vbi_fmt, btv->tvnorm); in bttv_probe()
3338 btv->vbi_count[0] = VBI_DEFLINES; in bttv_probe()
3339 btv->vbi_count[1] = VBI_DEFLINES; in bttv_probe()
3340 btv->do_crop = 0; in bttv_probe()
3356 if (btv->volume_gpio) in bttv_probe()
3372 bttv_gpio_tracking(btv,"pre-init"); in bttv_probe()
3389 /* some card-specific stuff (needs working i2c) */ in bttv_probe()
3392 if (btv->tuner_type != TUNER_ABSENT) { in bttv_probe()
3394 btv->radio_freq = 90500 * 16; /* 90.5Mhz default */ in bttv_probe()
3396 btv->std = V4L2_STD_PAL; in bttv_probe()
3398 if (!bttv_tvcards[btv->c.type].no_video) in bttv_probe()
3400 if (hdl->error) { in bttv_probe()
3401 result = hdl->error; in bttv_probe()
3408 if (!bttv_tvcards[btv->c.type].no_video) { in bttv_probe()
3409 v4l2_ctrl_add_handler(&btv->radio_ctrl_handler, hdl, in bttv_probe()
3411 if (btv->radio_ctrl_handler.error) { in bttv_probe()
3412 result = btv->radio_ctrl_handler.error; in bttv_probe()
3415 set_input(btv, btv->input, btv->tvnorm); in bttv_probe()
3416 bttv_crop_reset(&btv->crop[0], btv->tvnorm); in bttv_probe()
3417 btv->crop[1] = btv->crop[0]; /* current = default */ in bttv_probe()
3423 /* add subdevices and autoload dvb-bt8xx if needed */ in bttv_probe()
3424 if (bttv_tvcards[btv->c.type].has_dvb) { in bttv_probe()
3425 bttv_sub_add_device(&btv->c, "dvb"); in bttv_probe()
3439 free_irq(btv->c.pci->irq,btv); in bttv_probe()
3442 v4l2_ctrl_handler_free(&btv->ctrl_handler); in bttv_probe()
3443 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler); in bttv_probe()
3444 v4l2_device_unregister(&btv->c.v4l2_dev); in bttv_probe()
3447 if (btv->bt848_mmio) in bttv_probe()
3448 iounmap(btv->bt848_mmio); in bttv_probe()
3449 release_mem_region(pci_resource_start(btv->c.pci,0), in bttv_probe()
3450 pci_resource_len(btv->c.pci,0)); in bttv_probe()
3451 pci_disable_device(btv->c.pci); in bttv_probe()
3454 bttvs[btv->c.nr] = NULL; in bttv_probe()
3465 pr_info("%d: unloading\n", btv->c.nr); in bttv_remove()
3467 if (bttv_tvcards[btv->c.type].has_dvb) in bttv_remove()
3479 btv->shutdown=1; in bttv_remove()
3481 bttv_sub_del_devices(&btv->c); in bttv_remove()
3490 v4l2_ctrl_handler_free(&btv->ctrl_handler); in bttv_remove()
3491 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler); in bttv_remove()
3492 btcx_riscmem_free(btv->c.pci,&btv->main); in bttv_remove()
3495 free_irq(btv->c.pci->irq,btv); in bttv_remove()
3496 del_timer_sync(&btv->timeout); in bttv_remove()
3497 iounmap(btv->bt848_mmio); in bttv_remove()
3498 release_mem_region(pci_resource_start(btv->c.pci,0), in bttv_remove()
3499 pci_resource_len(btv->c.pci,0)); in bttv_remove()
3500 pci_disable_device(btv->c.pci); in bttv_remove()
3502 v4l2_device_unregister(&btv->c.v4l2_dev); in bttv_remove()
3503 bttvs[btv->c.nr] = NULL; in bttv_remove()
3516 dprintk("%d: suspend\n", btv->c.nr); in bttv_suspend()
3519 spin_lock_irqsave(&btv->s_lock,flags); in bttv_suspend()
3521 btv->state.video = btv->curr; in bttv_suspend()
3522 btv->state.vbi = btv->cvbi; in bttv_suspend()
3523 btv->state.loop_irq = btv->loop_irq; in bttv_suspend()
3524 btv->curr = idle; in bttv_suspend()
3525 btv->loop_irq = 0; in bttv_suspend()
3530 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_suspend()
3533 btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN); in bttv_suspend()
3534 btv->state.gpio_data = gpio_read(); in bttv_suspend()
3536 btv->state.disabled = 1; in bttv_suspend()
3546 dprintk("%d: resume\n", btv->c.nr); in bttv_resume()
3548 btv->state.disabled = 0; in bttv_resume()
3552 gpio_inout(0xffffff, btv->state.gpio_enable); in bttv_resume()
3553 gpio_write(btv->state.gpio_data); in bttv_resume()
3556 spin_lock_irqsave(&btv->s_lock,flags); in bttv_resume()
3557 btv->curr = btv->state.video; in bttv_resume()
3558 btv->cvbi = btv->state.vbi; in bttv_resume()
3559 btv->loop_irq = btv->state.loop_irq; in bttv_resume()
3560 bttv_buffer_activate_video(btv, &btv->curr); in bttv_resume()
3561 bttv_buffer_activate_vbi(btv, btv->cvbi); in bttv_resume()
3563 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_resume()
3601 gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK; in bttv_init_module()