Lines Matching +full:ld +full:- +full:pulse +full:- +full:delay +full:- +full:us

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>
29 #include <linux/delay.h>
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 show_card()
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 /* ----------------------------------------------------------------------- */
245 /HRESET pulse (0H) in 1 / fCLKx1.
250 trailing edge of /VRESET pulse (VDELAY register).
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 /* ----------------------------------------------------------------------- */
656 if (fh->resources & bit) in check_alloc_btres_lock()
665 if (btv->resources & xbits) { in check_alloc_btres_lock()
671 && 0 == (btv->resources & VIDEO_RESOURCES)) { in check_alloc_btres_lock()
672 /* Do crop - use current, don't - use default parameters. */ in check_alloc_btres_lock()
673 __s32 top = btv->crop[!!fh->do_crop].rect.top; in check_alloc_btres_lock()
675 if (btv->vbi_end > top) in check_alloc_btres_lock()
680 btv->crop_start = top; in check_alloc_btres_lock()
682 __s32 end = fh->vbi_fmt.end; in check_alloc_btres_lock()
684 if (end > btv->crop_start) in check_alloc_btres_lock()
687 /* Claim scan lines above fh->vbi_fmt.end. */ in check_alloc_btres_lock()
688 btv->vbi_end = end; in check_alloc_btres_lock()
692 fh->resources |= bit; in check_alloc_btres_lock()
693 btv->resources |= bit; in check_alloc_btres_lock()
703 return (fh->resources & bit); in check_btres()
709 return (btv->resources & bit); in locked_btres()
712 /* Call with btv->lock down. */
716 btv->vbi_end = 0; in disclaim_vbi_lines()
719 /* Call with btv->lock down. */
726 tvnorm = &bttv_tvnorms[btv->tvnorm]; in disclaim_video_lines()
727 btv->crop_start = tvnorm->cropcap.bounds.top in disclaim_video_lines()
728 + tvnorm->cropcap.bounds.height; in disclaim_video_lines()
744 if ((fh->resources & bits) != bits) { in free_btres_lock()
745 /* trying to free resources not allocated by us ... */ in free_btres_lock()
748 fh->resources &= ~bits; in free_btres_lock()
749 btv->resources &= ~bits; in free_btres_lock()
751 bits = btv->resources; in free_btres_lock()
760 /* ----------------------------------------------------------------------- */
764 PLL_X = Reference pre-divider (0=1, 1=2)
799 if (!btv->pll.pll_crystal) in set_pll()
802 if (btv->pll.pll_ofreq == btv->pll.pll_current) { in set_pll()
803 dprintk("%d: PLL: no change required\n", btv->c.nr); in set_pll()
807 if (btv->pll.pll_ifreq == btv->pll.pll_ofreq) { in set_pll()
809 if (btv->pll.pll_current == 0) in set_pll()
813 btv->c.nr, btv->pll.pll_ifreq); in set_pll()
816 btv->pll.pll_current = 0; in set_pll()
822 btv->c.nr, in set_pll()
823 btv->pll.pll_ifreq, btv->pll.pll_ofreq); in set_pll()
824 set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq); in set_pll()
834 btv->pll.pll_current = btv->pll.pll_ofreq; in set_pll()
840 btv->pll.pll_current = -1; in set_pll()
850 int table_idx = bttv_tvnorms[btv->tvnorm].sram; in bt848A_set_timing()
851 int fsc = bttv_tvnorms[btv->tvnorm].Fsc; in bt848A_set_timing()
853 if (btv->input == btv->dig) { in bt848A_set_timing()
855 btv->c.nr,table_idx); in bt848A_set_timing()
865 btv->pll.pll_ofreq = 27000000; in bt848A_set_timing()
871 btv->pll.pll_ofreq = fsc; in bt848A_set_timing()
877 /* ----------------------------------------------------------------------- */
884 btv->bright = bright; in bt848_bright()
886 /* We want -128 to 127 we get 0-65535 */ in bt848_bright()
887 value = (bright >> 8) - 128; in bt848_bright()
895 btv->hue = hue; in bt848_hue()
897 /* -128 to 127 */ in bt848_hue()
898 value = (hue >> 8) - 128; in bt848_hue()
906 btv->contrast = cont; in bt848_contrast()
908 /* 0-511 */ in bt848_contrast()
920 btv->saturation = color; in bt848_sat()
922 /* 0-511 for the color */ in bt848_sat()
923 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7; in bt848_sat()
924 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254; in bt848_sat()
933 /* ----------------------------------------------------------------------- */
940 if (input >= bttv_tvcards[btv->c.type].video_inputs) in video_mux()
941 return -EINVAL; in video_mux()
944 mask2 = bttv_tvcards[btv->c.type].gpiomask2; in video_mux()
948 if (input == btv->svhs) { in video_mux()
957 dprintk("%d: video mux: input=%d mux=%d\n", btv->c.nr, input, mux); in video_mux()
960 if(bttv_tvcards[btv->c.type].muxsel_hook) in video_mux()
961 bttv_tvcards[btv->c.type].muxsel_hook (btv, input); in video_mux()
975 gpio_inout(bttv_tvcards[btv->c.type].gpiomask, in audio_mux_gpio()
976 bttv_tvcards[btv->c.type].gpiomask); in audio_mux_gpio()
980 mute_gpio = mute || (btv->opt_automute && (!signal || !btv->users) in audio_mux_gpio()
981 && !btv->has_radio_tuner); in audio_mux_gpio()
984 gpio_val = bttv_tvcards[btv->c.type].gpiomute; in audio_mux_gpio()
986 gpio_val = bttv_tvcards[btv->c.type].gpiomux[input]; in audio_mux_gpio()
988 switch (btv->c.type) { in audio_mux_gpio()
995 gpio_bits(bttv_tvcards[btv->c.type].gpiomask, gpio_val); in audio_mux_gpio()
1007 audio_mux_gpio(btv, btv->audio_input, mute); in audio_mute()
1009 if (btv->sd_msp34xx) { in audio_mute()
1010 ctrl = v4l2_ctrl_find(btv->sd_msp34xx->ctrl_handler, V4L2_CID_AUDIO_MUTE); in audio_mute()
1014 if (btv->sd_tvaudio) { in audio_mute()
1015 ctrl = v4l2_ctrl_find(btv->sd_tvaudio->ctrl_handler, V4L2_CID_AUDIO_MUTE); in audio_mute()
1019 if (btv->sd_tda7432) { in audio_mute()
1020 ctrl = v4l2_ctrl_find(btv->sd_tda7432->ctrl_handler, V4L2_CID_AUDIO_MUTE); in audio_mute()
1030 audio_mux_gpio(btv, input, btv->mute); in audio_input()
1032 if (btv->sd_msp34xx) { in audio_input()
1043 if (btv->radio_uses_msp_demodulator) { in audio_input()
1068 if (btv->c.type == BTTV_BOARD_VOODOOTV_200) in audio_input()
1075 v4l2_subdev_call(btv->sd_msp34xx, audio, s_routing, in audio_input()
1078 if (btv->sd_tvaudio) { in audio_input()
1079 v4l2_subdev_call(btv->sd_tvaudio, audio, s_routing, in audio_input()
1094 c->min_scaled_width = 48; in bttv_crop_calc_limits()
1095 c->min_scaled_height = 32; in bttv_crop_calc_limits()
1097 c->min_scaled_width = in bttv_crop_calc_limits()
1098 (max_t(unsigned int, 48, c->rect.width >> 4) + 3) & ~3; in bttv_crop_calc_limits()
1099 c->min_scaled_height = in bttv_crop_calc_limits()
1100 max_t(unsigned int, 32, c->rect.height >> 4); in bttv_crop_calc_limits()
1103 c->max_scaled_width = c->rect.width & ~3; in bttv_crop_calc_limits()
1104 c->max_scaled_height = c->rect.height; in bttv_crop_calc_limits()
1110 c->rect = bttv_tvnorms[norm].cropcap.defrect; in bttv_crop_reset()
1114 /* Call with btv->lock down. */
1122 BUG_ON(btv->tvnorm >= BTTV_TVNORMS); in set_tvnorm()
1126 if (memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap, in set_tvnorm()
1127 sizeof (tvnorm->cropcap))) { in set_tvnorm()
1128 bttv_crop_reset(&btv->crop[0], norm); in set_tvnorm()
1129 btv->crop[1] = btv->crop[0]; /* current = default */ in set_tvnorm()
1131 if (0 == (btv->resources & VIDEO_RESOURCES)) { in set_tvnorm()
1132 btv->crop_start = tvnorm->cropcap.bounds.top in set_tvnorm()
1133 + tvnorm->cropcap.bounds.height; in set_tvnorm()
1137 btv->tvnorm = norm; in set_tvnorm()
1139 btwrite(tvnorm->adelay, BT848_ADELAY); in set_tvnorm()
1140 btwrite(tvnorm->bdelay, BT848_BDELAY); in set_tvnorm()
1141 btaor(tvnorm->iform,~(BT848_IFORM_NORM|BT848_IFORM_XTBOTH), in set_tvnorm()
1143 btwrite(tvnorm->vbipack, BT848_VBI_PACK_SIZE); in set_tvnorm()
1147 switch (btv->c.type) { in set_tvnorm()
1153 id = tvnorm->v4l2_id; in set_tvnorm()
1159 /* Call with btv->lock down. */
1165 btv->input = input; in set_input()
1167 spin_lock_irqsave(&btv->s_lock,flags); in set_input()
1168 if (btv->curr.frame_irq) { in set_input()
1169 /* active capture -> delayed input switch */ in set_input()
1170 btv->new_input = input; in set_input()
1174 spin_unlock_irqrestore(&btv->s_lock,flags); in set_input()
1178 btv->audio_input = (btv->tuner_type != TUNER_ABSENT && input == 0) ? in set_input()
1180 audio_input(btv, btv->audio_input); in set_input()
1189 if (bttv_tvcards[btv->c.type].no_video) { in init_irqreg()
1195 btwrite((btv->triton1) | in init_irqreg()
1196 (btv->gpioirq ? BT848_INT_GPINT : 0) | in init_irqreg()
1208 if (bttv_tvcards[btv->c.type].no_video) { in init_bt848()
1230 v4l2_ctrl_handler_setup(&btv->ctrl_handler); in init_bt848()
1241 pr_info("%d: reset, reinitialize\n", btv->c.nr); in bttv_reinit_bt848()
1242 spin_lock_irqsave(&btv->s_lock,flags); in bttv_reinit_bt848()
1243 btv->errors=0; in bttv_reinit_bt848()
1245 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_reinit_bt848()
1248 btv->pll.pll_current = -1; in bttv_reinit_bt848()
1249 set_input(btv, btv->input, btv->tvnorm); in bttv_reinit_bt848()
1254 struct bttv *btv = container_of(c->handler, struct bttv, ctrl_handler); in bttv_s_ctrl()
1257 switch (c->id) { in bttv_s_ctrl()
1259 bt848_bright(btv, c->val); in bttv_s_ctrl()
1262 bt848_hue(btv, c->val); in bttv_s_ctrl()
1265 bt848_contrast(btv, c->val); in bttv_s_ctrl()
1268 bt848_sat(btv, c->val); in bttv_s_ctrl()
1271 if (c->val) { in bttv_s_ctrl()
1280 audio_mute(btv, c->val); in bttv_s_ctrl()
1281 btv->mute = c->val; in bttv_s_ctrl()
1284 btv->volume_gpio(btv, c->val); in bttv_s_ctrl()
1288 val = c->val ? BT848_SCLOOP_CAGC : 0; in bttv_s_ctrl()
1293 btv->opt_combfilter = c->val; in bttv_s_ctrl()
1296 if (c->val) { in bttv_s_ctrl()
1305 btv->opt_automute = c->val; in bttv_s_ctrl()
1309 (c->val ? BT848_ADC_CRUSH : 0), in bttv_s_ctrl()
1313 btv->opt_vcr_hack = c->val; in bttv_s_ctrl()
1316 btwrite(c->val, BT848_WC_UP); in bttv_s_ctrl()
1319 btwrite(c->val, BT848_WC_DOWN); in bttv_s_ctrl()
1322 btv->opt_uv_ratio = c->val; in bttv_s_ctrl()
1323 bt848_sat(btv, btv->saturation); in bttv_s_ctrl()
1326 btaor((c->val << 7), ~BT848_OFORM_RANGE, BT848_OFORM); in bttv_s_ctrl()
1329 btaor((c->val << 5), ~BT848_OFORM_CORE32, BT848_OFORM); in bttv_s_ctrl()
1332 return -EINVAL; in bttv_s_ctrl()
1337 /* ----------------------------------------------------------------------- */
1452 /* ----------------------------------------------------------------------- */
1460 btv->c.nr, outbits, data & outbits, data & ~outbits, comment); in bttv_gpio_tracking()
1467 if (btv->users) in bttv_field_count()
1476 btv->field_count = 0; in bttv_field_count()
1486 if (-1 == formats[i].fourcc) in format_by_fourcc()
1494 /* ----------------------------------------------------------------------- */
1506 new->vb.state = VIDEOBUF_DONE; in bttv_switch_overlay()
1507 spin_lock_irqsave(&btv->s_lock,flags); in bttv_switch_overlay()
1508 old = btv->screen; in bttv_switch_overlay()
1509 btv->screen = new; in bttv_switch_overlay()
1510 btv->loop_irq |= 1; in bttv_switch_overlay()
1512 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_switch_overlay()
1515 old, old->vb.state); in bttv_switch_overlay()
1516 bttv_dma_free(&fh->cap,btv, old); in bttv_switch_overlay()
1525 /* ----------------------------------------------------------------------- */
1534 struct bttv_fh *fh = q->priv_data; in bttv_prepare_buffer()
1542 return -EINVAL; in bttv_prepare_buffer()
1543 if (fmt->btformat == BT848_COLOR_FMT_RAW) { in bttv_prepare_buffer()
1546 if (width*height > buf->vb.bsize) in bttv_prepare_buffer()
1547 return -EINVAL; in bttv_prepare_buffer()
1548 buf->vb.size = buf->vb.bsize; in bttv_prepare_buffer()
1553 norm = btv->tvnorm; in bttv_prepare_buffer()
1557 if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) { in bttv_prepare_buffer()
1558 return -EINVAL; in bttv_prepare_buffer()
1563 norm = btv->tvnorm; in bttv_prepare_buffer()
1564 c = btv->crop[!!fh->do_crop]; in bttv_prepare_buffer()
1569 return -EINVAL; in bttv_prepare_buffer()
1575 /* btv->crop counts frame lines. Max. scale in bttv_prepare_buffer()
1578 return -EINVAL; in bttv_prepare_buffer()
1583 return -EINVAL; in bttv_prepare_buffer()
1587 buf->vb.size = (width * height * fmt->depth) >> 3; in bttv_prepare_buffer()
1588 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) in bttv_prepare_buffer()
1589 return -EINVAL; in bttv_prepare_buffer()
1593 if (buf->vb.width != width || buf->vb.height != height || in bttv_prepare_buffer()
1594 buf->vb.field != field || in bttv_prepare_buffer()
1595 buf->tvnorm != norm || buf->fmt != fmt || in bttv_prepare_buffer()
1596 buf->crop.top != c.rect.top || in bttv_prepare_buffer()
1597 buf->crop.left != c.rect.left || in bttv_prepare_buffer()
1598 buf->crop.width != c.rect.width || in bttv_prepare_buffer()
1599 buf->crop.height != c.rect.height) { in bttv_prepare_buffer()
1600 buf->vb.width = width; in bttv_prepare_buffer()
1601 buf->vb.height = height; in bttv_prepare_buffer()
1602 buf->vb.field = field; in bttv_prepare_buffer()
1603 buf->tvnorm = norm; in bttv_prepare_buffer()
1604 buf->fmt = fmt; in bttv_prepare_buffer()
1605 buf->crop = c.rect; in bttv_prepare_buffer()
1610 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { in bttv_prepare_buffer()
1612 if (0 != (rc = videobuf_iolock(q,&buf->vb,&btv->fbuf))) in bttv_prepare_buffer()
1620 buf->vb.state = VIDEOBUF_PREPARED; in bttv_prepare_buffer()
1631 struct bttv_fh *fh = q->priv_data; in buffer_setup()
1633 *size = fh->fmt->depth*fh->width*fh->height >> 3; in buffer_setup()
1646 struct bttv_fh *fh = q->priv_data; in buffer_prepare()
1648 return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt, in buffer_prepare()
1649 fh->width, fh->height, field); in buffer_prepare()
1656 struct bttv_fh *fh = q->priv_data; in buffer_queue()
1657 struct bttv *btv = fh->btv; in buffer_queue()
1659 buf->vb.state = VIDEOBUF_QUEUED; in buffer_queue()
1660 list_add_tail(&buf->vb.queue,&btv->capture); in buffer_queue()
1661 if (!btv->curr.frame_irq) { in buffer_queue()
1662 btv->loop_irq |= 1; in buffer_queue()
1670 struct bttv_fh *fh = q->priv_data; in buffer_release()
1672 bttv_dma_free(q,fh->btv,buf); in buffer_release()
1685 if (!btv->has_radio_tuner) { in radio_enable()
1686 btv->has_radio_tuner = 1; in radio_enable()
1688 btv->audio_input = TVAUDIO_INPUT_RADIO; in radio_enable()
1689 audio_input(btv, btv->audio_input); in radio_enable()
1696 struct bttv *btv = fh->btv; in bttv_s_std()
1703 return -EINVAL; in bttv_s_std()
1704 btv->std = id; in bttv_s_std()
1712 struct bttv *btv = fh->btv; in bttv_g_std()
1714 *id = btv->std; in bttv_g_std()
1721 struct bttv *btv = fh->btv; in bttv_querystd()
1734 struct bttv *btv = fh->btv; in bttv_enum_input()
1736 if (i->index >= bttv_tvcards[btv->c.type].video_inputs) in bttv_enum_input()
1737 return -EINVAL; in bttv_enum_input()
1739 i->type = V4L2_INPUT_TYPE_CAMERA; in bttv_enum_input()
1740 i->audioset = 0; in bttv_enum_input()
1742 if (btv->tuner_type != TUNER_ABSENT && i->index == 0) { in bttv_enum_input()
1743 sprintf(i->name, "Television"); in bttv_enum_input()
1744 i->type = V4L2_INPUT_TYPE_TUNER; in bttv_enum_input()
1745 i->tuner = 0; in bttv_enum_input()
1746 } else if (i->index == btv->svhs) { in bttv_enum_input()
1747 sprintf(i->name, "S-Video"); in bttv_enum_input()
1749 sprintf(i->name, "Composite%d", i->index); in bttv_enum_input()
1752 if (i->index == btv->input) { in bttv_enum_input()
1755 i->status |= V4L2_IN_ST_NO_SIGNAL; in bttv_enum_input()
1757 i->status |= V4L2_IN_ST_NO_H_LOCK; in bttv_enum_input()
1760 i->std = BTTV_NORMS; in bttv_enum_input()
1767 struct bttv *btv = fh->btv; in bttv_g_input()
1769 *i = btv->input; in bttv_g_input()
1777 struct bttv *btv = fh->btv; in bttv_s_input()
1779 if (i >= bttv_tvcards[btv->c.type].video_inputs) in bttv_s_input()
1780 return -EINVAL; in bttv_s_input()
1782 set_input(btv, i, btv->tvnorm); in bttv_s_input()
1790 struct bttv *btv = fh->btv; in bttv_s_tuner()
1792 if (t->index) in bttv_s_tuner()
1793 return -EINVAL; in bttv_s_tuner()
1797 if (btv->audio_mode_gpio) { in bttv_s_tuner()
1800 btv->audio_mode_gpio(btv, &copy, 1); in bttv_s_tuner()
1809 struct bttv *btv = fh->btv; in bttv_g_frequency()
1811 if (f->tuner) in bttv_g_frequency()
1812 return -EINVAL; in bttv_g_frequency()
1814 if (f->type == V4L2_TUNER_RADIO) in bttv_g_frequency()
1816 f->frequency = f->type == V4L2_TUNER_RADIO ? in bttv_g_frequency()
1817 btv->radio_freq : btv->tv_freq; in bttv_g_frequency()
1832 btv->radio_freq = new_freq.frequency; in bttv_set_frequency()
1833 if (btv->has_tea575x) { in bttv_set_frequency()
1834 btv->tea.freq = btv->radio_freq; in bttv_set_frequency()
1835 snd_tea575x_set_freq(&btv->tea); in bttv_set_frequency()
1838 btv->tv_freq = new_freq.frequency; in bttv_set_frequency()
1846 struct bttv *btv = fh->btv; in bttv_s_frequency()
1848 if (f->tuner) in bttv_s_frequency()
1849 return -EINVAL; in bttv_s_frequency()
1859 struct bttv *btv = fh->btv; in bttv_log_status()
1861 v4l2_ctrl_handler_log_status(vdev->ctrl_handler, btv->c.v4l2_dev.name); in bttv_log_status()
1871 struct bttv *btv = fh->btv; in bttv_g_register()
1873 /* bt848 has a 12-bit register space */ in bttv_g_register()
1874 reg->reg &= 0xfff; in bttv_g_register()
1875 reg->val = btread(reg->reg); in bttv_g_register()
1876 reg->size = 1; in bttv_g_register()
1885 struct bttv *btv = fh->btv; in bttv_s_register()
1887 /* bt848 has a 12-bit register space */ in bttv_s_register()
1888 btwrite(reg->val, reg->reg & 0xfff); in bttv_s_register()
1908 if (width < c->min_scaled_width) { in bttv_crop_adjust()
1910 c->rect.width = width * 16; in bttv_crop_adjust()
1911 } else if (width > c->max_scaled_width) { in bttv_crop_adjust()
1913 c->rect.width = width; in bttv_crop_adjust()
1915 max_left = b->left + b->width - width; in bttv_crop_adjust()
1917 if (c->rect.left > max_left) in bttv_crop_adjust()
1918 c->rect.left = max_left; in bttv_crop_adjust()
1921 if (height < c->min_scaled_height) { in bttv_crop_adjust()
1923 c->rect.height = height * 16; in bttv_crop_adjust()
1924 } else if (frame_height > c->max_scaled_height) { in bttv_crop_adjust()
1927 c->rect.height = (frame_height + 1) & ~1; in bttv_crop_adjust()
1929 max_top = b->top + b->height - c->rect.height; in bttv_crop_adjust()
1930 if (c->rect.top > max_top) in bttv_crop_adjust()
1931 c->rect.top = max_top; in bttv_crop_adjust()
1954 struct bttv *btv = fh->btv; in limit_scaled_size_lock()
1964 width_bias >= (unsigned int) -width_mask); in limit_scaled_size_lock()
1969 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; in limit_scaled_size_lock()
1971 /* Do crop - use current, don't - use default parameters. */ in limit_scaled_size_lock()
1972 c = &btv->crop[!!fh->do_crop]; in limit_scaled_size_lock()
1974 if (fh->do_crop in limit_scaled_size_lock()
1984 max_width = min_t(unsigned int, b->width, MAX_HACTIVE); in limit_scaled_size_lock()
1985 max_height = b->height; in limit_scaled_size_lock()
1988 Note btv->vbi_end is really a minimum, see in limit_scaled_size_lock()
1990 if (btv->vbi_end > b->top) { in limit_scaled_size_lock()
1991 max_height -= btv->vbi_end - b->top; in limit_scaled_size_lock()
1992 rc = -EBUSY; in limit_scaled_size_lock()
1997 rc = -EBUSY; in limit_scaled_size_lock()
1998 if (btv->vbi_end > c->rect.top) in limit_scaled_size_lock()
2001 min_width = c->min_scaled_width; in limit_scaled_size_lock()
2002 min_height = c->min_scaled_height; in limit_scaled_size_lock()
2003 max_width = c->max_scaled_width; in limit_scaled_size_lock()
2004 max_height = c->max_scaled_height; in limit_scaled_size_lock()
2009 min_width = (min_width - width_mask - 1) & width_mask; in limit_scaled_size_lock()
2026 if (btv->vbi_end > c->rect.top) { in limit_scaled_size_lock()
2028 c->rect.top = btv->vbi_end; in limit_scaled_size_lock()
2032 rc = -EINVAL; in limit_scaled_size_lock()
2063 if (win->w.width < 48) in verify_window_lock()
2064 win->w.width = 48; in verify_window_lock()
2065 if (win->w.height < 32) in verify_window_lock()
2066 win->w.height = 32; in verify_window_lock()
2067 if (win->clipcount > 2048) in verify_window_lock()
2068 win->clipcount = 2048; in verify_window_lock()
2070 win->chromakey = 0; in verify_window_lock()
2071 win->global_alpha = 0; in verify_window_lock()
2072 field = win->field; in verify_window_lock()
2086 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1; in verify_window_lock()
2087 field = (win->w.height > height2) in verify_window_lock()
2091 win->field = field; in verify_window_lock()
2093 if (NULL == fh->ovfmt) in verify_window_lock()
2094 return -EINVAL; in verify_window_lock()
2095 /* 4-byte alignment. */ in verify_window_lock()
2097 switch (fh->ovfmt->depth) { in verify_window_lock()
2111 win->w.width -= win->w.left & ~width_mask; in verify_window_lock()
2112 win->w.left = (win->w.left - width_mask - 1) & width_mask; in verify_window_lock()
2114 rc = limit_scaled_size_lock(fh, &win->w.width, &win->w.height, in verify_window_lock()
2129 if (NULL == fh->ovfmt) in setup_window_lock()
2130 return -EINVAL; in setup_window_lock()
2131 if (!(fh->ovfmt->flags & FORMAT_FLAGS_PACKED)) in setup_window_lock()
2132 return -EINVAL; in setup_window_lock()
2139 /* copy clips -- luckily v4l1 + v4l2 are binary in setup_window_lock()
2141 n = win->clipcount; in setup_window_lock()
2145 return -ENOMEM; in setup_window_lock()
2147 if (copy_from_user(clips,win->clips,sizeof(struct v4l2_clip)*n)) { in setup_window_lock()
2149 return -EFAULT; in setup_window_lock()
2154 if (NULL != btv->fbuf.base) in setup_window_lock()
2155 n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height, in setup_window_lock()
2156 &win->w, clips, n); in setup_window_lock()
2159 /* 4-byte alignments */ in setup_window_lock()
2160 switch (fh->ovfmt->depth) { in setup_window_lock()
2163 btcx_align(&win->w, clips, n, 3); in setup_window_lock()
2166 btcx_align(&win->w, clips, n, 1); in setup_window_lock()
2175 kfree(fh->ov.clips); in setup_window_lock()
2176 fh->ov.clips = clips; in setup_window_lock()
2177 fh->ov.nclips = n; in setup_window_lock()
2179 fh->ov.w = win->w; in setup_window_lock()
2180 fh->ov.field = win->field; in setup_window_lock()
2181 fh->ov.setup_ok = 1; in setup_window_lock()
2183 btv->init.ov.w.width = win->w.width; in setup_window_lock()
2184 btv->init.ov.w.height = win->w.height; in setup_window_lock()
2185 btv->init.ov.field = win->field; in setup_window_lock()
2193 new->crop = btv->crop[!!fh->do_crop].rect; in setup_window_lock()
2194 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); in setup_window_lock()
2200 /* ----------------------------------------------------------------------- */
2206 switch (fh->type) { in bttv_queue()
2208 q = &fh->cap; in bttv_queue()
2211 q = &fh->vbi; in bttv_queue()
2223 switch (fh->type) { in bttv_resource()
2242 return -EBUSY; in bttv_switch_type()
2244 return -EBUSY; in bttv_switch_type()
2245 fh->type = type; in bttv_switch_type()
2255 f->width = width; in pix_format_set_size()
2256 f->height = height; in pix_format_set_size()
2258 if (fmt->flags & FORMAT_FLAGS_PLANAR) { in pix_format_set_size()
2259 f->bytesperline = width; /* Y plane */ in pix_format_set_size()
2260 f->sizeimage = (width * height * fmt->depth) >> 3; in pix_format_set_size()
2262 f->bytesperline = (width * fmt->depth) >> 3; in pix_format_set_size()
2263 f->sizeimage = height * f->bytesperline; in pix_format_set_size()
2272 pix_format_set_size(&f->fmt.pix, fh->fmt, in bttv_g_fmt_vid_cap()
2273 fh->width, fh->height); in bttv_g_fmt_vid_cap()
2274 f->fmt.pix.field = fh->cap.field; in bttv_g_fmt_vid_cap()
2275 f->fmt.pix.pixelformat = fh->fmt->fourcc; in bttv_g_fmt_vid_cap()
2276 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in bttv_g_fmt_vid_cap()
2286 f->fmt.win.w = fh->ov.w; in bttv_g_fmt_vid_overlay()
2287 f->fmt.win.field = fh->ov.field; in bttv_g_fmt_vid_overlay()
2296 if (fmt->flags & FORMAT_FLAGS_PLANAR) { in bttv_get_width_mask_vid_cap()
2310 struct bttv *btv = fh->btv; in bttv_try_fmt_vid_cap()
2317 fmt = format_by_fourcc(f->fmt.pix.pixelformat); in bttv_try_fmt_vid_cap()
2319 return -EINVAL; in bttv_try_fmt_vid_cap()
2321 field = f->fmt.pix.field; in bttv_try_fmt_vid_cap()
2331 if (!(fmt->flags & FORMAT_FLAGS_PLANAR)) { in bttv_try_fmt_vid_cap()
2337 height2 = btv->crop[!!fh->do_crop].rect.height >> 1; in bttv_try_fmt_vid_cap()
2338 field = (f->fmt.pix.height > height2) in bttv_try_fmt_vid_cap()
2344 width = f->fmt.pix.width; in bttv_try_fmt_vid_cap()
2345 height = f->fmt.pix.height; in bttv_try_fmt_vid_cap()
2356 f->fmt.pix.field = field; in bttv_try_fmt_vid_cap()
2357 pix_format_set_size(&f->fmt.pix, fmt, width, height); in bttv_try_fmt_vid_cap()
2358 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in bttv_try_fmt_vid_cap()
2368 verify_window_lock(fh, &f->fmt.win, in bttv_try_fmt_vid_overlay()
2380 struct bttv *btv = fh->btv; in bttv_s_fmt_vid_cap()
2385 retval = bttv_switch_type(fh, f->type); in bttv_s_fmt_vid_cap()
2393 width = f->fmt.pix.width; in bttv_s_fmt_vid_cap()
2394 height = f->fmt.pix.height; in bttv_s_fmt_vid_cap()
2395 field = f->fmt.pix.field; in bttv_s_fmt_vid_cap()
2397 fmt = format_by_fourcc(f->fmt.pix.pixelformat); in bttv_s_fmt_vid_cap()
2399 retval = limit_scaled_size_lock(fh, &width, &height, f->fmt.pix.field, in bttv_s_fmt_vid_cap()
2406 f->fmt.pix.field = field; in bttv_s_fmt_vid_cap()
2409 fh->fmt = fmt; in bttv_s_fmt_vid_cap()
2410 fh->cap.field = f->fmt.pix.field; in bttv_s_fmt_vid_cap()
2411 fh->cap.last = V4L2_FIELD_NONE; in bttv_s_fmt_vid_cap()
2412 fh->width = f->fmt.pix.width; in bttv_s_fmt_vid_cap()
2413 fh->height = f->fmt.pix.height; in bttv_s_fmt_vid_cap()
2414 btv->init.fmt = fmt; in bttv_s_fmt_vid_cap()
2415 btv->init.width = f->fmt.pix.width; in bttv_s_fmt_vid_cap()
2416 btv->init.height = f->fmt.pix.height; in bttv_s_fmt_vid_cap()
2425 struct bttv *btv = fh->btv; in bttv_s_fmt_vid_overlay()
2429 return -EINVAL; in bttv_s_fmt_vid_overlay()
2432 return setup_window_lock(fh, btv, &f->fmt.win, 1); in bttv_s_fmt_vid_overlay()
2439 struct bttv *btv = fh->btv; in bttv_querycap()
2442 return -EINVAL; in bttv_querycap()
2444 strscpy(cap->driver, "bttv", sizeof(cap->driver)); in bttv_querycap()
2445 strscpy(cap->card, btv->video_dev.name, sizeof(cap->card)); in bttv_querycap()
2446 snprintf(cap->bus_info, sizeof(cap->bus_info), in bttv_querycap()
2447 "PCI:%s", pci_name(btv->c.pci)); in bttv_querycap()
2448 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in bttv_querycap()
2451 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; in bttv_querycap()
2452 if (video_is_registered(&btv->vbi_dev)) in bttv_querycap()
2453 cap->capabilities |= V4L2_CAP_VBI_CAPTURE; in bttv_querycap()
2454 if (video_is_registered(&btv->radio_dev)) { in bttv_querycap()
2455 cap->capabilities |= V4L2_CAP_RADIO; in bttv_querycap()
2456 if (btv->has_tea575x) in bttv_querycap()
2457 cap->capabilities |= V4L2_CAP_HW_FREQ_SEEK; in bttv_querycap()
2464 if (btv->has_saa6588) in bttv_querycap()
2465 cap->capabilities |= V4L2_CAP_RDS_CAPTURE; in bttv_querycap()
2466 if (btv->tuner_type != TUNER_ABSENT) in bttv_querycap()
2467 cap->capabilities |= V4L2_CAP_TUNER; in bttv_querycap()
2473 int index = -1, i; in bttv_enum_fmt_cap_ovr()
2476 if (formats[i].fourcc != -1) in bttv_enum_fmt_cap_ovr()
2478 if ((unsigned int)index == f->index) in bttv_enum_fmt_cap_ovr()
2482 return -EINVAL; in bttv_enum_fmt_cap_ovr()
2484 f->pixelformat = formats[i].fourcc; in bttv_enum_fmt_cap_ovr()
2507 return -EINVAL; in bttv_enum_fmt_vid_overlay()
2516 return -EINVAL; in bttv_enum_fmt_vid_overlay()
2525 struct bttv *btv = fh->btv; in bttv_g_fbuf()
2527 *fb = btv->fbuf; in bttv_g_fbuf()
2528 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; in bttv_g_fbuf()
2529 fb->flags = V4L2_FBUF_FLAG_PRIMARY; in bttv_g_fbuf()
2530 if (fh->ovfmt) in bttv_g_fbuf()
2531 fb->fmt.pixelformat = fh->ovfmt->fourcc; in bttv_g_fbuf()
2538 struct bttv *btv = fh->btv; in bttv_overlay()
2544 if (unlikely(!btv->fbuf.base)) { in bttv_overlay()
2545 return -EINVAL; in bttv_overlay()
2547 if (unlikely(!fh->ov.setup_ok)) { in bttv_overlay()
2548 dprintk("%d: overlay: !setup_ok\n", btv->c.nr); in bttv_overlay()
2549 retval = -EINVAL; in bttv_overlay()
2556 return -EBUSY; in bttv_overlay()
2559 fh->ov.tvnorm = btv->tvnorm; in bttv_overlay()
2561 new->crop = btv->crop[!!fh->do_crop].rect; in bttv_overlay()
2562 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); in bttv_overlay()
2576 struct bttv *btv = fh->btv; in bttv_s_fbuf()
2582 return -EPERM; in bttv_s_fbuf()
2585 fmt = format_by_fourcc(fb->fmt.pixelformat); in bttv_s_fbuf()
2587 return -EINVAL; in bttv_s_fbuf()
2588 if (0 == (fmt->flags & FORMAT_FLAGS_PACKED)) in bttv_s_fbuf()
2589 return -EINVAL; in bttv_s_fbuf()
2591 retval = -EINVAL; in bttv_s_fbuf()
2592 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { in bttv_s_fbuf()
2593 __s32 width = fb->fmt.width; in bttv_s_fbuf()
2594 __s32 height = fb->fmt.height; in bttv_s_fbuf()
2607 btv->fbuf.base = fb->base; in bttv_s_fbuf()
2608 btv->fbuf.fmt.width = fb->fmt.width; in bttv_s_fbuf()
2609 btv->fbuf.fmt.height = fb->fmt.height; in bttv_s_fbuf()
2610 if (0 != fb->fmt.bytesperline) in bttv_s_fbuf()
2611 btv->fbuf.fmt.bytesperline = fb->fmt.bytesperline; in bttv_s_fbuf()
2613 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8; in bttv_s_fbuf()
2616 fh->ovfmt = fmt; in bttv_s_fbuf()
2617 btv->init.ovfmt = fmt; in bttv_s_fbuf()
2618 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { in bttv_s_fbuf()
2619 fh->ov.w.left = 0; in bttv_s_fbuf()
2620 fh->ov.w.top = 0; in bttv_s_fbuf()
2621 fh->ov.w.width = fb->fmt.width; in bttv_s_fbuf()
2622 fh->ov.w.height = fb->fmt.height; in bttv_s_fbuf()
2623 btv->init.ov.w.width = fb->fmt.width; in bttv_s_fbuf()
2624 btv->init.ov.w.height = fb->fmt.height; in bttv_s_fbuf()
2626 kfree(fh->ov.clips); in bttv_s_fbuf()
2627 fh->ov.clips = NULL; in bttv_s_fbuf()
2628 fh->ov.nclips = 0; in bttv_s_fbuf()
2634 new->crop = btv->crop[!!fh->do_crop].rect; in bttv_s_fbuf()
2635 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); in bttv_s_fbuf()
2659 struct bttv *btv = fh->btv; in bttv_qbuf()
2663 return -EBUSY; in bttv_qbuf()
2672 file->f_flags & O_NONBLOCK); in bttv_dqbuf()
2679 struct bttv *btv = fh->btv; in bttv_streamon()
2683 return -EBUSY; in bttv_streamon()
2692 struct bttv *btv = fh->btv; in bttv_streamoff()
2708 struct bttv *btv = fh->btv; in bttv_g_parm()
2710 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in bttv_g_parm()
2711 return -EINVAL; in bttv_g_parm()
2712 parm->parm.capture.readbuffers = gbuffers; in bttv_g_parm()
2713 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id, in bttv_g_parm()
2714 &parm->parm.capture.timeperframe); in bttv_g_parm()
2723 struct bttv *btv = fh->btv; in bttv_g_tuner()
2725 if (0 != t->index) in bttv_g_tuner()
2726 return -EINVAL; in bttv_g_tuner()
2728 t->rxsubchans = V4L2_TUNER_SUB_MONO; in bttv_g_tuner()
2729 t->capability = V4L2_TUNER_CAP_NORM; in bttv_g_tuner()
2731 strscpy(t->name, "Television", sizeof(t->name)); in bttv_g_tuner()
2732 t->type = V4L2_TUNER_ANALOG_TV; in bttv_g_tuner()
2734 t->signal = 0xffff; in bttv_g_tuner()
2736 if (btv->audio_mode_gpio) in bttv_g_tuner()
2737 btv->audio_mode_gpio(btv, t, 0); in bttv_g_tuner()
2746 struct bttv *btv = fh->btv; in bttv_g_pixelaspect()
2749 return -EINVAL; in bttv_g_pixelaspect()
2752 *f = bttv_tvnorms[btv->tvnorm].cropcap.pixelaspect; in bttv_g_pixelaspect()
2759 struct bttv *btv = fh->btv; in bttv_g_selection()
2761 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && in bttv_g_selection()
2762 sel->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) in bttv_g_selection()
2763 return -EINVAL; in bttv_g_selection()
2765 switch (sel->target) { in bttv_g_selection()
2768 * No fh->do_crop = 1; because btv->crop[1] may be in bttv_g_selection()
2769 * inconsistent with fh->width or fh->height and apps in bttv_g_selection()
2772 sel->r = btv->crop[!!fh->do_crop].rect; in bttv_g_selection()
2775 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.defrect; in bttv_g_selection()
2778 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.bounds; in bttv_g_selection()
2781 return -EINVAL; in bttv_g_selection()
2790 struct bttv *btv = fh->btv; in bttv_s_selection()
2799 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && in bttv_s_selection()
2800 sel->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) in bttv_s_selection()
2801 return -EINVAL; in bttv_s_selection()
2803 if (sel->target != V4L2_SEL_TGT_CROP) in bttv_s_selection()
2804 return -EINVAL; in bttv_s_selection()
2809 retval = -EBUSY; in bttv_s_selection()
2811 if (locked_btres(fh->btv, VIDEO_RESOURCES)) { in bttv_s_selection()
2815 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; in bttv_s_selection()
2817 b_left = b->left; in bttv_s_selection()
2818 b_right = b_left + b->width; in bttv_s_selection()
2819 b_bottom = b->top + b->height; in bttv_s_selection()
2821 b_top = max(b->top, btv->vbi_end); in bttv_s_selection()
2827 c.rect.left = clamp_t(s32, sel->r.left, b_left, b_right - 48); in bttv_s_selection()
2830 c.rect.width = clamp_t(s32, sel->r.width, in bttv_s_selection()
2831 48, b_right - c.rect.left); in bttv_s_selection()
2833 c.rect.top = clamp_t(s32, sel->r.top, b_top, b_bottom - 32); in bttv_s_selection()
2837 c.rect.height = clamp_t(s32, sel->r.height, in bttv_s_selection()
2838 32, b_bottom - c.rect.top); in bttv_s_selection()
2843 sel->r = c.rect; in bttv_s_selection()
2845 btv->crop[1] = c; in bttv_s_selection()
2847 fh->do_crop = 1; in bttv_s_selection()
2849 if (fh->width < c.min_scaled_width) { in bttv_s_selection()
2850 fh->width = c.min_scaled_width; in bttv_s_selection()
2851 btv->init.width = c.min_scaled_width; in bttv_s_selection()
2852 } else if (fh->width > c.max_scaled_width) { in bttv_s_selection()
2853 fh->width = c.max_scaled_width; in bttv_s_selection()
2854 btv->init.width = c.max_scaled_width; in bttv_s_selection()
2857 if (fh->height < c.min_scaled_height) { in bttv_s_selection()
2858 fh->height = c.min_scaled_height; in bttv_s_selection()
2859 btv->init.height = c.min_scaled_height; in bttv_s_selection()
2860 } else if (fh->height > c.max_scaled_height) { in bttv_s_selection()
2861 fh->height = c.max_scaled_height; in bttv_s_selection()
2862 btv->init.height = c.max_scaled_height; in bttv_s_selection()
2871 struct bttv_fh *fh = file->private_data; in bttv_read()
2874 if (fh->btv->errors) in bttv_read()
2875 bttv_reinit_bt848(fh->btv); in bttv_read()
2877 fh->btv->c.nr, (int)count, v4l2_type_names[fh->type]); in bttv_read()
2879 switch (fh->type) { in bttv_read()
2881 if (!check_alloc_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ)) { in bttv_read()
2884 return -EBUSY; in bttv_read()
2886 retval = videobuf_read_one(&fh->cap, data, count, ppos, in bttv_read()
2887 file->f_flags & O_NONBLOCK); in bttv_read()
2888 free_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ); in bttv_read()
2891 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) in bttv_read()
2892 return -EBUSY; in bttv_read()
2893 retval = videobuf_read_stream(&fh->vbi, data, count, ppos, 1, in bttv_read()
2894 file->f_flags & O_NONBLOCK); in bttv_read()
2904 struct bttv_fh *fh = file->private_data; in bttv_poll()
2910 if (v4l2_event_pending(&fh->fh)) in bttv_poll()
2913 poll_wait(file, &fh->fh.wait, wait); in bttv_poll()
2918 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { in bttv_poll()
2919 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) in bttv_poll()
2921 return rc | videobuf_poll_stream(file, &fh->vbi, wait); in bttv_poll()
2926 if (list_empty(&fh->cap.stream)) in bttv_poll()
2928 buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream); in bttv_poll()
2931 if (NULL == fh->cap.read_buf) { in bttv_poll()
2933 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM)) in bttv_poll()
2935 fh->cap.read_buf = videobuf_sg_alloc(fh->cap.msize); in bttv_poll()
2936 if (NULL == fh->cap.read_buf) in bttv_poll()
2938 fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR; in bttv_poll()
2939 field = videobuf_next_field(&fh->cap); in bttv_poll()
2940 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) { in bttv_poll()
2941 kfree (fh->cap.read_buf); in bttv_poll()
2942 fh->cap.read_buf = NULL; in bttv_poll()
2945 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); in bttv_poll()
2946 fh->cap.read_off = 0; in bttv_poll()
2948 buf = (struct bttv_buffer*)fh->cap.read_buf; in bttv_poll()
2951 poll_wait(file, &buf->vb.done, wait); in bttv_poll()
2952 if (buf->vb.state == VIDEOBUF_DONE || in bttv_poll()
2953 buf->vb.state == VIDEOBUF_ERROR) in bttv_poll()
2967 if (vdev->vfl_type == VFL_TYPE_VIDEO) { in bttv_open()
2969 } else if (vdev->vfl_type == VFL_TYPE_VBI) { in bttv_open()
2973 return -ENODEV; in bttv_open()
2977 btv->c.nr, v4l2_type_names[type]); in bttv_open()
2982 return -ENOMEM; in bttv_open()
2983 btv->users++; in bttv_open()
2984 file->private_data = fh; in bttv_open()
2986 *fh = btv->init; in bttv_open()
2987 v4l2_fh_init(&fh->fh, vdev); in bttv_open()
2989 fh->type = type; in bttv_open()
2990 fh->ov.setup_ok = 0; in bttv_open()
2992 videobuf_queue_sg_init(&fh->cap, &bttv_video_qops, in bttv_open()
2993 &btv->c.pci->dev, &btv->s_lock, in bttv_open()
2997 fh, &btv->lock); in bttv_open()
2998 videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops, in bttv_open()
2999 &btv->c.pci->dev, &btv->s_lock, in bttv_open()
3003 fh, &btv->lock); in bttv_open()
3004 set_tvnorm(btv,btv->tvnorm); in bttv_open()
3005 set_input(btv, btv->input, btv->tvnorm); in bttv_open()
3006 audio_mute(btv, btv->mute); in bttv_open()
3009 which only change on request. These are stored in btv->crop[1]. in bttv_open()
3013 will use btv->crop[0], the default cropping parameters for the in bttv_open()
3017 fh->do_crop = !reset_crop; /* module parameter */ in bttv_open()
3022 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); in bttv_open()
3025 v4l2_fh_add(&fh->fh); in bttv_open()
3031 struct bttv_fh *fh = file->private_data; in bttv_release()
3032 struct bttv *btv = fh->btv; in bttv_release()
3040 videobuf_streamoff(&fh->cap); in bttv_release()
3043 if (fh->cap.read_buf) { in bttv_release()
3044 buffer_release(&fh->cap,fh->cap.read_buf); in bttv_release()
3045 kfree(fh->cap.read_buf); in bttv_release()
3053 videobuf_stop(&fh->vbi); in bttv_release()
3059 videobuf_mmap_free(&fh->cap); in bttv_release()
3060 videobuf_mmap_free(&fh->vbi); in bttv_release()
3061 file->private_data = NULL; in bttv_release()
3063 btv->users--; in bttv_release()
3066 if (!btv->users) in bttv_release()
3067 audio_mute(btv, btv->mute); in bttv_release()
3069 v4l2_fh_del(&fh->fh); in bttv_release()
3070 v4l2_fh_exit(&fh->fh); in bttv_release()
3078 struct bttv_fh *fh = file->private_data; in bttv_mmap()
3080 dprintk("%d: mmap type=%s 0x%lx+%ld\n", in bttv_mmap()
3081 fh->btv->c.nr, v4l2_type_names[fh->type], in bttv_mmap()
3082 vma->vm_start, vma->vm_end - vma->vm_start); in bttv_mmap()
3148 /* ----------------------------------------------------------------------- */
3159 dprintk("%d: open called (radio)\n", btv->c.nr); in radio_open()
3164 return -ENOMEM; in radio_open()
3165 file->private_data = fh; in radio_open()
3166 *fh = btv->init; in radio_open()
3167 v4l2_fh_init(&fh->fh, vdev); in radio_open()
3169 btv->radio_user++; in radio_open()
3170 audio_mute(btv, btv->mute); in radio_open()
3172 v4l2_fh_add(&fh->fh); in radio_open()
3179 struct bttv_fh *fh = file->private_data; in radio_release()
3180 struct bttv *btv = fh->btv; in radio_release()
3183 file->private_data = NULL; in radio_release()
3184 v4l2_fh_del(&fh->fh); in radio_release()
3185 v4l2_fh_exit(&fh->fh); in radio_release()
3188 btv->radio_user--; in radio_release()
3192 if (btv->radio_user == 0) in radio_release()
3193 btv->has_radio_tuner = 0; in radio_release()
3200 struct bttv *btv = fh->btv; in radio_g_tuner()
3202 if (0 != t->index) in radio_g_tuner()
3203 return -EINVAL; in radio_g_tuner()
3204 strscpy(t->name, "Radio", sizeof(t->name)); in radio_g_tuner()
3205 t->type = V4L2_TUNER_RADIO; in radio_g_tuner()
3210 if (btv->audio_mode_gpio) in radio_g_tuner()
3211 btv->audio_mode_gpio(btv, t, 0); in radio_g_tuner()
3213 if (btv->has_tea575x) in radio_g_tuner()
3214 return snd_tea575x_g_tuner(&btv->tea, t); in radio_g_tuner()
3223 struct bttv *btv = fh->btv; in radio_s_tuner()
3225 if (0 != t->index) in radio_s_tuner()
3226 return -EINVAL; in radio_s_tuner()
3237 struct bttv *btv = fh->btv; in radio_s_hw_freq_seek()
3239 if (btv->has_tea575x) in radio_s_hw_freq_seek()
3240 return snd_tea575x_s_hw_freq_seek(file, &btv->tea, a); in radio_s_hw_freq_seek()
3242 return -ENOTTY; in radio_s_hw_freq_seek()
3249 struct bttv *btv = fh->btv; in radio_enum_freq_bands()
3251 if (btv->has_tea575x) in radio_enum_freq_bands()
3252 return snd_tea575x_enum_freq_bands(&btv->tea, band); in radio_enum_freq_bands()
3254 return -ENOTTY; in radio_enum_freq_bands()
3260 struct bttv_fh *fh = file->private_data; in radio_read()
3261 struct bttv *btv = fh->btv; in radio_read()
3265 cmd.nonblocking = file->f_flags & O_NONBLOCK; in radio_read()
3268 cmd.result = -ENODEV; in radio_read()
3278 struct bttv_fh *fh = file->private_data; in radio_poll()
3279 struct bttv *btv = fh->btv; in radio_poll()
3284 if (v4l2_event_pending(&fh->fh)) in radio_poll()
3287 poll_wait(file, &fh->fh.wait, wait); in radio_poll()
3325 /* ----------------------------------------------------------------------- */
3358 for (i = ARRAY_SIZE(bits)-1; i >= 0; i--) in bttv_risc_decode()
3371 btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma); in bttv_risc_disasm()
3372 for (i = 0; i < (risc->size >> 2); i += n) { in bttv_risc_disasm()
3374 btv->c.v4l2_dev.name, in bttv_risc_disasm()
3375 (unsigned long)(risc->dma + (i<<2))); in bttv_risc_disasm()
3376 n = bttv_risc_decode(le32_to_cpu(risc->cpu[i])); in bttv_risc_disasm()
3379 btv->c.v4l2_dev.name, in bttv_risc_disasm()
3380 (unsigned long)(risc->dma + ((i+j)<<2)), in bttv_risc_disasm()
3381 risc->cpu[i+j], j); in bttv_risc_disasm()
3382 if (0 == risc->cpu[i]) in bttv_risc_disasm()
3389 pr_info(" main: %08llx\n", (unsigned long long)btv->main.dma); in bttv_print_riscaddr()
3391 btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0, in bttv_print_riscaddr()
3392 btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0); in bttv_print_riscaddr()
3394 btv->curr.top in bttv_print_riscaddr()
3395 ? (unsigned long long)btv->curr.top->top.dma : 0, in bttv_print_riscaddr()
3396 btv->curr.bottom in bttv_print_riscaddr()
3397 ? (unsigned long long)btv->curr.bottom->bottom.dma : 0); in bttv_print_riscaddr()
3399 btv->screen ? (unsigned long long)btv->screen->top.dma : 0, in bttv_print_riscaddr()
3400 btv->screen ? (unsigned long long)btv->screen->bottom.dma : 0); in bttv_print_riscaddr()
3401 bttv_risc_disasm(btv, &btv->main); in bttv_print_riscaddr()
3404 /* ----------------------------------------------------------------------- */
3445 btv->c.nr, in bttv_irq_debug_low_latency()
3446 (unsigned long)btv->main.dma, in bttv_irq_debug_low_latency()
3447 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]), in bttv_irq_debug_low_latency()
3448 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]), in bttv_irq_debug_low_latency()
3453 btv->c.nr); in bttv_irq_debug_low_latency()
3457 btv->c.nr); in bttv_irq_debug_low_latency()
3458 pr_notice("%d: Lets try to catch the culprit red-handed ...\n", in bttv_irq_debug_low_latency()
3459 btv->c.nr); in bttv_irq_debug_low_latency()
3471 if (!list_empty(&btv->capture)) { in bttv_irq_next_video()
3472 set->frame_irq = 1; in bttv_irq_next_video()
3473 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue); in bttv_irq_next_video()
3474 if (V4L2_FIELD_HAS_TOP(item->vb.field)) in bttv_irq_next_video()
3475 set->top = item; in bttv_irq_next_video()
3476 if (V4L2_FIELD_HAS_BOTTOM(item->vb.field)) in bttv_irq_next_video()
3477 set->bottom = item; in bttv_irq_next_video()
3480 if (!V4L2_FIELD_HAS_BOTH(item->vb.field) && in bttv_irq_next_video()
3481 (item->vb.queue.next != &btv->capture)) { in bttv_irq_next_video()
3482 item = list_entry(item->vb.queue.next, struct bttv_buffer, vb.queue); in bttv_irq_next_video()
3483 /* Mike Isely <isely@pobox.com> - Only check in bttv_irq_next_video()
3492 * That will then cause us here to set up a in bttv_irq_next_video()
3498 * field first - the effect will be the two in bttv_irq_next_video()
3510 if (!V4L2_FIELD_HAS_BOTH(item->vb.field)) { in bttv_irq_next_video()
3511 if (NULL == set->bottom && in bttv_irq_next_video()
3512 V4L2_FIELD_BOTTOM == item->vb.field) { in bttv_irq_next_video()
3513 set->bottom = item; in bttv_irq_next_video()
3515 if (NULL != set->top && NULL != set->bottom) in bttv_irq_next_video()
3516 set->top_irq = 2; in bttv_irq_next_video()
3522 if (NULL != btv->screen) { in bttv_irq_next_video()
3523 if (V4L2_FIELD_HAS_BOTH(btv->screen->vb.field)) { in bttv_irq_next_video()
3524 if (NULL == set->top && NULL == set->bottom) { in bttv_irq_next_video()
3525 set->top = btv->screen; in bttv_irq_next_video()
3526 set->bottom = btv->screen; in bttv_irq_next_video()
3529 if (V4L2_FIELD_TOP == btv->screen->vb.field && in bttv_irq_next_video()
3530 NULL == set->top) { in bttv_irq_next_video()
3531 set->top = btv->screen; in bttv_irq_next_video()
3533 if (V4L2_FIELD_BOTTOM == btv->screen->vb.field && in bttv_irq_next_video()
3534 NULL == set->bottom) { in bttv_irq_next_video()
3535 set->bottom = btv->screen; in bttv_irq_next_video()
3541 btv->c.nr, set->top, set->bottom, in bttv_irq_next_video()
3542 btv->screen, set->frame_irq, set->top_irq); in bttv_irq_next_video()
3552 if (wakeup->top == wakeup->bottom) { in bttv_irq_wakeup_video()
3553 if (NULL != wakeup->top && curr->top != wakeup->top) { in bttv_irq_wakeup_video()
3556 btv->c.nr, wakeup->top); in bttv_irq_wakeup_video()
3557 wakeup->top->vb.ts = ts; in bttv_irq_wakeup_video()
3558 wakeup->top->vb.field_count = btv->field_count; in bttv_irq_wakeup_video()
3559 wakeup->top->vb.state = state; in bttv_irq_wakeup_video()
3560 wake_up(&wakeup->top->vb.done); in bttv_irq_wakeup_video()
3563 if (NULL != wakeup->top && curr->top != wakeup->top) { in bttv_irq_wakeup_video()
3566 btv->c.nr, wakeup->top); in bttv_irq_wakeup_video()
3567 wakeup->top->vb.ts = ts; in bttv_irq_wakeup_video()
3568 wakeup->top->vb.field_count = btv->field_count; in bttv_irq_wakeup_video()
3569 wakeup->top->vb.state = state; in bttv_irq_wakeup_video()
3570 wake_up(&wakeup->top->vb.done); in bttv_irq_wakeup_video()
3572 if (NULL != wakeup->bottom && curr->bottom != wakeup->bottom) { in bttv_irq_wakeup_video()
3575 btv->c.nr, wakeup->bottom); in bttv_irq_wakeup_video()
3576 wakeup->bottom->vb.ts = ts; in bttv_irq_wakeup_video()
3577 wakeup->bottom->vb.field_count = btv->field_count; in bttv_irq_wakeup_video()
3578 wakeup->bottom->vb.state = state; in bttv_irq_wakeup_video()
3579 wake_up(&wakeup->bottom->vb.done); in bttv_irq_wakeup_video()
3591 wakeup->vb.ts = ktime_get_ns(); in bttv_irq_wakeup_vbi()
3592 wakeup->vb.field_count = btv->field_count; in bttv_irq_wakeup_vbi()
3593 wakeup->vb.state = state; in bttv_irq_wakeup_vbi()
3594 wake_up(&wakeup->vb.done); in bttv_irq_wakeup_vbi()
3607 btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total, in bttv_irq_timeout()
3613 spin_lock_irqsave(&btv->s_lock,flags); in bttv_irq_timeout()
3617 old = btv->curr; in bttv_irq_timeout()
3618 ovbi = btv->cvbi; in bttv_irq_timeout()
3619 btv->curr = new; in bttv_irq_timeout()
3620 btv->cvbi = NULL; in bttv_irq_timeout()
3621 btv->loop_irq = 0; in bttv_irq_timeout()
3631 while (!list_empty(&btv->capture)) { in bttv_irq_timeout()
3632 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue); in bttv_irq_timeout()
3633 list_del(&item->vb.queue); in bttv_irq_timeout()
3634 item->vb.state = VIDEOBUF_ERROR; in bttv_irq_timeout()
3635 wake_up(&item->vb.done); in bttv_irq_timeout()
3637 while (!list_empty(&btv->vcapture)) { in bttv_irq_timeout()
3638 item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue); in bttv_irq_timeout()
3639 list_del(&item->vb.queue); in bttv_irq_timeout()
3640 item->vb.state = VIDEOBUF_ERROR; in bttv_irq_timeout()
3641 wake_up(&item->vb.done); in bttv_irq_timeout()
3644 btv->errors++; in bttv_irq_timeout()
3645 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_irq_timeout()
3651 struct bttv_buffer *wakeup = btv->curr.top; in bttv_irq_wakeup_top()
3656 spin_lock(&btv->s_lock); in bttv_irq_wakeup_top()
3657 btv->curr.top_irq = 0; in bttv_irq_wakeup_top()
3658 btv->curr.top = NULL; in bttv_irq_wakeup_top()
3661 wakeup->vb.ts = ktime_get_ns(); in bttv_irq_wakeup_top()
3662 wakeup->vb.field_count = btv->field_count; in bttv_irq_wakeup_top()
3663 wakeup->vb.state = VIDEOBUF_DONE; in bttv_irq_wakeup_top()
3664 wake_up(&wakeup->vb.done); in bttv_irq_wakeup_top()
3665 spin_unlock(&btv->s_lock); in bttv_irq_wakeup_top()
3670 if (rc < risc->dma) in is_active()
3672 if (rc > risc->dma + risc->size) in is_active()
3684 spin_lock(&btv->s_lock); in bttv_irq_switch_video()
3689 if ((btv->curr.top && is_active(&btv->curr.top->top, rc)) || in bttv_irq_switch_video()
3690 (btv->curr.bottom && is_active(&btv->curr.bottom->bottom, rc))) { in bttv_irq_switch_video()
3691 btv->framedrop++; in bttv_irq_switch_video()
3694 spin_unlock(&btv->s_lock); in bttv_irq_switch_video()
3699 old = btv->curr; in bttv_irq_switch_video()
3700 btv->curr = new; in bttv_irq_switch_video()
3701 btv->loop_irq &= ~1; in bttv_irq_switch_video()
3706 if (UNSET != btv->new_input) { in bttv_irq_switch_video()
3707 video_mux(btv,btv->new_input); in bttv_irq_switch_video()
3708 btv->new_input = UNSET; in bttv_irq_switch_video()
3713 spin_unlock(&btv->s_lock); in bttv_irq_switch_video()
3723 spin_lock(&btv->s_lock); in bttv_irq_switch_vbi()
3725 if (!list_empty(&btv->vcapture)) in bttv_irq_switch_vbi()
3726 new = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue); in bttv_irq_switch_vbi()
3727 old = btv->cvbi; in bttv_irq_switch_vbi()
3730 if (NULL != old && (is_active(&old->top, rc) || in bttv_irq_switch_vbi()
3731 is_active(&old->bottom, rc))) { in bttv_irq_switch_vbi()
3732 btv->framedrop++; in bttv_irq_switch_vbi()
3735 spin_unlock(&btv->s_lock); in bttv_irq_switch_vbi()
3740 btv->cvbi = new; in bttv_irq_switch_vbi()
3741 btv->loop_irq &= ~4; in bttv_irq_switch_vbi()
3746 spin_unlock(&btv->s_lock); in bttv_irq_switch_vbi()
3774 btv->c.nr, count, btv->field_count, in bttv_irq()
3793 btv->field_count++; in bttv_irq()
3795 if ((astat & BT848_INT_GPINT) && btv->remote) { in bttv_irq()
3800 btv->i2c_done = stat; in bttv_irq()
3801 wake_up(&btv->i2c_queue); in bttv_irq()
3813 if ((astat & BT848_INT_HLOCK) && btv->opt_automute) in bttv_irq()
3815 audio_mux_gpio(btv, btv->audio_input, btv->mute); in bttv_irq()
3819 btv->c.nr, in bttv_irq()
3830 btv->c.nr, btread(BT848_RISC_COUNT)); in bttv_irq()
3842 btv->c.nr); in bttv_irq()
3845 btv->c.nr); in bttv_irq()
3847 btwrite(btread(BT848_INT_MASK) & (-1 ^ BT848_INT_GPINT), in bttv_irq()
3856 btv->irq_total++; in bttv_irq()
3858 btv->irq_me++; in bttv_irq()
3863 /* ----------------------------------------------------------------------- */
3872 vfd->v4l2_dev = &btv->c.v4l2_dev; in vdev_init()
3873 vfd->release = video_device_release_empty; in vdev_init()
3875 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", in vdev_init()
3876 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", in vdev_init()
3877 type_name, bttv_tvcards[btv->c.type].name); in vdev_init()
3878 if (btv->tuner_type == TUNER_ABSENT) { in vdev_init()
3888 video_unregister_device(&btv->video_dev); in bttv_unregister_video()
3889 video_unregister_device(&btv->vbi_dev); in bttv_unregister_video()
3890 video_unregister_device(&btv->radio_dev); in bttv_unregister_video()
3900 vdev_init(btv, &btv->video_dev, &bttv_video_template, "video"); in bttv_register_video()
3901 btv->video_dev.device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | in bttv_register_video()
3903 if (btv->tuner_type != TUNER_ABSENT) in bttv_register_video()
3904 btv->video_dev.device_caps |= V4L2_CAP_TUNER; in bttv_register_video()
3906 btv->video_dev.device_caps |= V4L2_CAP_VIDEO_OVERLAY; in bttv_register_video()
3908 if (video_register_device(&btv->video_dev, VFL_TYPE_VIDEO, in bttv_register_video()
3909 video_nr[btv->c.nr]) < 0) in bttv_register_video()
3912 btv->c.nr, video_device_node_name(&btv->video_dev)); in bttv_register_video()
3913 if (device_create_file(&btv->video_dev.dev, in bttv_register_video()
3915 pr_err("%d: device_create_file 'card' failed\n", btv->c.nr); in bttv_register_video()
3920 vdev_init(btv, &btv->vbi_dev, &bttv_video_template, "vbi"); in bttv_register_video()
3921 btv->vbi_dev.device_caps = V4L2_CAP_VBI_CAPTURE | V4L2_CAP_READWRITE | in bttv_register_video()
3923 if (btv->tuner_type != TUNER_ABSENT) in bttv_register_video()
3924 btv->vbi_dev.device_caps |= V4L2_CAP_TUNER; in bttv_register_video()
3926 if (video_register_device(&btv->vbi_dev, VFL_TYPE_VBI, in bttv_register_video()
3927 vbi_nr[btv->c.nr]) < 0) in bttv_register_video()
3930 btv->c.nr, video_device_node_name(&btv->vbi_dev)); in bttv_register_video()
3932 if (!btv->has_radio) in bttv_register_video()
3935 vdev_init(btv, &btv->radio_dev, &radio_template, "radio"); in bttv_register_video()
3936 btv->radio_dev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER; in bttv_register_video()
3937 if (btv->has_saa6588) in bttv_register_video()
3938 btv->radio_dev.device_caps |= V4L2_CAP_READWRITE | in bttv_register_video()
3940 if (btv->has_tea575x) in bttv_register_video()
3941 btv->radio_dev.device_caps |= V4L2_CAP_HW_FREQ_SEEK; in bttv_register_video()
3942 btv->radio_dev.ctrl_handler = &btv->radio_ctrl_handler; in bttv_register_video()
3943 if (video_register_device(&btv->radio_dev, VFL_TYPE_RADIO, in bttv_register_video()
3944 radio_nr[btv->c.nr]) < 0) in bttv_register_video()
3947 btv->c.nr, video_device_node_name(&btv->radio_dev)); in bttv_register_video()
3954 return -1; in bttv_register_video()
3984 return -ENOMEM; in bttv_probe()
3989 return -ENOMEM; in bttv_probe()
3991 btv->c.nr = bttv_num; in bttv_probe()
3992 snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name), in bttv_probe()
3993 "bttv%d", btv->c.nr); in bttv_probe()
3996 mutex_init(&btv->lock); in bttv_probe()
3997 spin_lock_init(&btv->s_lock); in bttv_probe()
3998 spin_lock_init(&btv->gpio_lock); in bttv_probe()
3999 init_waitqueue_head(&btv->i2c_queue); in bttv_probe()
4000 INIT_LIST_HEAD(&btv->c.subs); in bttv_probe()
4001 INIT_LIST_HEAD(&btv->capture); in bttv_probe()
4002 INIT_LIST_HEAD(&btv->vcapture); in bttv_probe()
4004 timer_setup(&btv->timeout, bttv_irq_timeout, 0); in bttv_probe()
4006 btv->i2c_rc = -1; in bttv_probe()
4007 btv->tuner_type = UNSET; in bttv_probe()
4008 btv->new_input = UNSET; in bttv_probe()
4009 btv->has_radio=radio[btv->c.nr]; in bttv_probe()
4012 btv->c.pci = dev; in bttv_probe()
4013 btv->id = dev->device; in bttv_probe()
4015 pr_warn("%d: Can't enable device\n", btv->c.nr); in bttv_probe()
4016 result = -EIO; in bttv_probe()
4020 pr_warn("%d: No suitable DMA available\n", btv->c.nr); in bttv_probe()
4021 result = -EIO; in bttv_probe()
4026 btv->c.v4l2_dev.name)) { in bttv_probe()
4028 btv->c.nr, in bttv_probe()
4030 result = -EBUSY; in bttv_probe()
4036 result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev); in bttv_probe()
4038 pr_warn("%d: v4l2_device_register() failed\n", btv->c.nr); in bttv_probe()
4041 hdl = &btv->ctrl_handler; in bttv_probe()
4043 btv->c.v4l2_dev.ctrl_handler = hdl; in bttv_probe()
4044 v4l2_ctrl_handler_init(&btv->radio_ctrl_handler, 6); in bttv_probe()
4046 btv->revision = dev->revision; in bttv_probe()
4049 bttv_num, btv->id, btv->revision, pci_name(dev), in bttv_probe()
4050 btv->c.pci->irq, lat, in bttv_probe()
4054 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000); in bttv_probe()
4055 if (NULL == btv->bt848_mmio) { in bttv_probe()
4056 pr_err("%d: ioremap() failed\n", btv->c.nr); in bttv_probe()
4057 result = -EIO; in bttv_probe()
4066 result = request_irq(btv->c.pci->irq, bttv_irq, in bttv_probe()
4067 IRQF_SHARED, btv->c.v4l2_dev.name, (void *)btv); in bttv_probe()
4070 bttv_num, btv->c.pci->irq); in bttv_probe()
4075 result = -EIO; in bttv_probe()
4080 btv->opt_combfilter = combfilter; in bttv_probe()
4083 btv->opt_automute = automute; in bttv_probe()
4086 btv->opt_vcr_hack = vcr_hack; in bttv_probe()
4090 btv->opt_uv_ratio = uv_ratio; in bttv_probe()
4096 btv->init.btv = btv; in bttv_probe()
4097 btv->init.ov.w.width = 320; in bttv_probe()
4098 btv->init.ov.w.height = 240; in bttv_probe()
4099 btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); in bttv_probe()
4100 btv->init.width = 320; in bttv_probe()
4101 btv->init.height = 240; in bttv_probe()
4102 btv->init.ov.w.width = 320; in bttv_probe()
4103 btv->init.ov.w.height = 240; in bttv_probe()
4104 btv->init.ov.field = V4L2_FIELD_INTERLACED; in bttv_probe()
4105 btv->input = 0; in bttv_probe()
4121 if (btv->volume_gpio) in bttv_probe()
4137 bttv_gpio_tracking(btv,"pre-init"); in bttv_probe()
4154 /* some card-specific stuff (needs working i2c) */ in bttv_probe()
4157 if (btv->tuner_type != TUNER_ABSENT) { in bttv_probe()
4159 btv->radio_freq = 90500 * 16; /* 90.5Mhz default */ in bttv_probe()
4161 btv->std = V4L2_STD_PAL; in bttv_probe()
4163 if (!bttv_tvcards[btv->c.type].no_video) in bttv_probe()
4165 if (hdl->error) { in bttv_probe()
4166 result = hdl->error; in bttv_probe()
4173 if (!bttv_tvcards[btv->c.type].no_video) { in bttv_probe()
4174 v4l2_ctrl_add_handler(&btv->radio_ctrl_handler, hdl, in bttv_probe()
4176 if (btv->radio_ctrl_handler.error) { in bttv_probe()
4177 result = btv->radio_ctrl_handler.error; in bttv_probe()
4180 set_input(btv, 0, btv->tvnorm); in bttv_probe()
4181 bttv_crop_reset(&btv->crop[0], btv->tvnorm); in bttv_probe()
4182 btv->crop[1] = btv->crop[0]; /* current = default */ in bttv_probe()
4188 /* add subdevices and autoload dvb-bt8xx if needed */ in bttv_probe()
4189 if (bttv_tvcards[btv->c.type].has_dvb) { in bttv_probe()
4190 bttv_sub_add_device(&btv->c, "dvb"); in bttv_probe()
4204 free_irq(btv->c.pci->irq,btv); in bttv_probe()
4207 v4l2_ctrl_handler_free(&btv->ctrl_handler); in bttv_probe()
4208 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler); in bttv_probe()
4209 v4l2_device_unregister(&btv->c.v4l2_dev); in bttv_probe()
4212 if (btv->bt848_mmio) in bttv_probe()
4213 iounmap(btv->bt848_mmio); in bttv_probe()
4214 release_mem_region(pci_resource_start(btv->c.pci,0), in bttv_probe()
4215 pci_resource_len(btv->c.pci,0)); in bttv_probe()
4216 pci_disable_device(btv->c.pci); in bttv_probe()
4219 bttvs[btv->c.nr] = NULL; in bttv_probe()
4230 pr_info("%d: unloading\n", btv->c.nr); in bttv_remove()
4232 if (bttv_tvcards[btv->c.type].has_dvb) in bttv_remove()
4244 btv->shutdown=1; in bttv_remove()
4246 bttv_sub_del_devices(&btv->c); in bttv_remove()
4255 v4l2_ctrl_handler_free(&btv->ctrl_handler); in bttv_remove()
4256 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler); in bttv_remove()
4257 btcx_riscmem_free(btv->c.pci,&btv->main); in bttv_remove()
4260 free_irq(btv->c.pci->irq,btv); in bttv_remove()
4261 iounmap(btv->bt848_mmio); in bttv_remove()
4262 release_mem_region(pci_resource_start(btv->c.pci,0), in bttv_remove()
4263 pci_resource_len(btv->c.pci,0)); in bttv_remove()
4264 pci_disable_device(btv->c.pci); in bttv_remove()
4266 v4l2_device_unregister(&btv->c.v4l2_dev); in bttv_remove()
4267 bttvs[btv->c.nr] = NULL; in bttv_remove()
4281 dprintk("%d: suspend %d\n", btv->c.nr, state.event); in bttv_suspend()
4284 spin_lock_irqsave(&btv->s_lock,flags); in bttv_suspend()
4286 btv->state.video = btv->curr; in bttv_suspend()
4287 btv->state.vbi = btv->cvbi; in bttv_suspend()
4288 btv->state.loop_irq = btv->loop_irq; in bttv_suspend()
4289 btv->curr = idle; in bttv_suspend()
4290 btv->loop_irq = 0; in bttv_suspend()
4295 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_suspend()
4298 btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN); in bttv_suspend()
4299 btv->state.gpio_data = gpio_read(); in bttv_suspend()
4305 btv->state.disabled = 1; in bttv_suspend()
4317 dprintk("%d: resume\n", btv->c.nr); in bttv_resume()
4320 if (btv->state.disabled) { in bttv_resume()
4323 pr_warn("%d: Can't enable device\n", btv->c.nr); in bttv_resume()
4326 btv->state.disabled = 0; in bttv_resume()
4331 pr_warn("%d: Can't enable device\n", btv->c.nr); in bttv_resume()
4332 btv->state.disabled = 1; in bttv_resume()
4340 gpio_inout(0xffffff, btv->state.gpio_enable); in bttv_resume()
4341 gpio_write(btv->state.gpio_data); in bttv_resume()
4344 spin_lock_irqsave(&btv->s_lock,flags); in bttv_resume()
4345 btv->curr = btv->state.video; in bttv_resume()
4346 btv->cvbi = btv->state.vbi; in bttv_resume()
4347 btv->loop_irq = btv->state.loop_irq; in bttv_resume()
4348 bttv_buffer_activate_video(btv, &btv->curr); in bttv_resume()
4349 bttv_buffer_activate_vbi(btv, btv->cvbi); in bttv_resume()
4351 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_resume()
4389 gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK; in bttv_init_module()