Lines Matching +full:decimation +full:- +full:ratio

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");
147 MODULE_PARM_DESC(uv_ratio, "ratio between u and v gains, default is 50");
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 /* ----------------------------------------------------------------------- */
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()
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 /* ----------------------------------------------------------------------- */
1368 .name = "Luma Decimation Filter",
1423 .name = "UV Ratio",
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()
2062 if (win->w.width < 48) in verify_window_lock()
2063 win->w.width = 48; in verify_window_lock()
2064 if (win->w.height < 32) in verify_window_lock()
2065 win->w.height = 32; in verify_window_lock()
2066 if (win->clipcount > 2048) in verify_window_lock()
2067 win->clipcount = 2048; in verify_window_lock()
2069 win->chromakey = 0; in verify_window_lock()
2070 win->global_alpha = 0; in verify_window_lock()
2071 field = win->field; in verify_window_lock()
2085 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1; in verify_window_lock()
2086 field = (win->w.height > height2) in verify_window_lock()
2090 win->field = field; in verify_window_lock()
2092 if (NULL == fh->ovfmt) in verify_window_lock()
2093 return -EINVAL; in verify_window_lock()
2094 /* 4-byte alignment. */ in verify_window_lock()
2096 switch (fh->ovfmt->depth) { in verify_window_lock()
2110 win->w.width -= win->w.left & ~width_mask; in verify_window_lock()
2111 win->w.left = (win->w.left - width_mask - 1) & width_mask; in verify_window_lock()
2113 return limit_scaled_size_lock(fh, &win->w.width, &win->w.height, in verify_window_lock()
2125 if (NULL == fh->ovfmt) in setup_window_lock()
2126 return -EINVAL; in setup_window_lock()
2127 if (!(fh->ovfmt->flags & FORMAT_FLAGS_PACKED)) in setup_window_lock()
2128 return -EINVAL; in setup_window_lock()
2135 /* copy clips -- luckily v4l1 + v4l2 are binary in setup_window_lock()
2137 n = win->clipcount; in setup_window_lock()
2141 return -ENOMEM; in setup_window_lock()
2143 memcpy(clips, win->clips, sizeof(struct v4l2_clip) * n); in setup_window_lock()
2146 if (NULL != btv->fbuf.base) in setup_window_lock()
2147 n = btcx_screen_clips(btv->fbuf.fmt.width, btv->fbuf.fmt.height, in setup_window_lock()
2148 &win->w, clips, n); in setup_window_lock()
2151 /* 4-byte alignments */ in setup_window_lock()
2152 switch (fh->ovfmt->depth) { in setup_window_lock()
2155 btcx_align(&win->w, clips, n, 3); in setup_window_lock()
2158 btcx_align(&win->w, clips, n, 1); in setup_window_lock()
2167 kfree(fh->ov.clips); in setup_window_lock()
2168 fh->ov.clips = clips; in setup_window_lock()
2169 fh->ov.nclips = n; in setup_window_lock()
2171 fh->ov.w = win->w; in setup_window_lock()
2172 fh->ov.field = win->field; in setup_window_lock()
2173 fh->ov.setup_ok = 1; in setup_window_lock()
2175 btv->init.ov.w.width = win->w.width; in setup_window_lock()
2176 btv->init.ov.w.height = win->w.height; in setup_window_lock()
2177 btv->init.ov.field = win->field; in setup_window_lock()
2185 new->crop = btv->crop[!!fh->do_crop].rect; in setup_window_lock()
2186 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); in setup_window_lock()
2192 /* ----------------------------------------------------------------------- */
2198 switch (fh->type) { in bttv_queue()
2200 q = &fh->cap; in bttv_queue()
2203 q = &fh->vbi; in bttv_queue()
2215 switch (fh->type) { in bttv_resource()
2234 return -EBUSY; in bttv_switch_type()
2236 return -EBUSY; in bttv_switch_type()
2237 fh->type = type; in bttv_switch_type()
2247 f->width = width; in pix_format_set_size()
2248 f->height = height; in pix_format_set_size()
2250 if (fmt->flags & FORMAT_FLAGS_PLANAR) { in pix_format_set_size()
2251 f->bytesperline = width; /* Y plane */ in pix_format_set_size()
2252 f->sizeimage = (width * height * fmt->depth) >> 3; in pix_format_set_size()
2254 f->bytesperline = (width * fmt->depth) >> 3; in pix_format_set_size()
2255 f->sizeimage = height * f->bytesperline; in pix_format_set_size()
2264 pix_format_set_size(&f->fmt.pix, fh->fmt, in bttv_g_fmt_vid_cap()
2265 fh->width, fh->height); in bttv_g_fmt_vid_cap()
2266 f->fmt.pix.field = fh->cap.field; in bttv_g_fmt_vid_cap()
2267 f->fmt.pix.pixelformat = fh->fmt->fourcc; in bttv_g_fmt_vid_cap()
2268 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in bttv_g_fmt_vid_cap()
2278 f->fmt.win.w = fh->ov.w; in bttv_g_fmt_vid_overlay()
2279 f->fmt.win.field = fh->ov.field; in bttv_g_fmt_vid_overlay()
2288 if (fmt->flags & FORMAT_FLAGS_PLANAR) { in bttv_get_width_mask_vid_cap()
2302 struct bttv *btv = fh->btv; in bttv_try_fmt_vid_cap()
2309 fmt = format_by_fourcc(f->fmt.pix.pixelformat); in bttv_try_fmt_vid_cap()
2311 return -EINVAL; in bttv_try_fmt_vid_cap()
2313 field = f->fmt.pix.field; in bttv_try_fmt_vid_cap()
2323 if (!(fmt->flags & FORMAT_FLAGS_PLANAR)) { in bttv_try_fmt_vid_cap()
2329 height2 = btv->crop[!!fh->do_crop].rect.height >> 1; in bttv_try_fmt_vid_cap()
2330 field = (f->fmt.pix.height > height2) in bttv_try_fmt_vid_cap()
2336 width = f->fmt.pix.width; in bttv_try_fmt_vid_cap()
2337 height = f->fmt.pix.height; in bttv_try_fmt_vid_cap()
2348 f->fmt.pix.field = field; in bttv_try_fmt_vid_cap()
2349 pix_format_set_size(&f->fmt.pix, fmt, width, height); in bttv_try_fmt_vid_cap()
2350 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; in bttv_try_fmt_vid_cap()
2360 verify_window_lock(fh, &f->fmt.win, in bttv_try_fmt_vid_overlay()
2372 struct bttv *btv = fh->btv; in bttv_s_fmt_vid_cap()
2377 retval = bttv_switch_type(fh, f->type); in bttv_s_fmt_vid_cap()
2385 width = f->fmt.pix.width; in bttv_s_fmt_vid_cap()
2386 height = f->fmt.pix.height; in bttv_s_fmt_vid_cap()
2387 field = f->fmt.pix.field; in bttv_s_fmt_vid_cap()
2389 fmt = format_by_fourcc(f->fmt.pix.pixelformat); in bttv_s_fmt_vid_cap()
2391 retval = limit_scaled_size_lock(fh, &width, &height, f->fmt.pix.field, in bttv_s_fmt_vid_cap()
2398 f->fmt.pix.field = field; in bttv_s_fmt_vid_cap()
2401 fh->fmt = fmt; in bttv_s_fmt_vid_cap()
2402 fh->cap.field = f->fmt.pix.field; in bttv_s_fmt_vid_cap()
2403 fh->cap.last = V4L2_FIELD_NONE; in bttv_s_fmt_vid_cap()
2404 fh->width = f->fmt.pix.width; in bttv_s_fmt_vid_cap()
2405 fh->height = f->fmt.pix.height; in bttv_s_fmt_vid_cap()
2406 btv->init.fmt = fmt; in bttv_s_fmt_vid_cap()
2407 btv->init.width = f->fmt.pix.width; in bttv_s_fmt_vid_cap()
2408 btv->init.height = f->fmt.pix.height; in bttv_s_fmt_vid_cap()
2417 struct bttv *btv = fh->btv; in bttv_s_fmt_vid_overlay()
2421 return -EINVAL; in bttv_s_fmt_vid_overlay()
2424 return setup_window_lock(fh, btv, &f->fmt.win, 1); in bttv_s_fmt_vid_overlay()
2431 struct bttv *btv = fh->btv; in bttv_querycap()
2434 return -EINVAL; in bttv_querycap()
2436 strscpy(cap->driver, "bttv", sizeof(cap->driver)); in bttv_querycap()
2437 strscpy(cap->card, btv->video_dev.name, sizeof(cap->card)); in bttv_querycap()
2438 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in bttv_querycap()
2441 cap->capabilities |= V4L2_CAP_VIDEO_OVERLAY; in bttv_querycap()
2442 if (video_is_registered(&btv->vbi_dev)) in bttv_querycap()
2443 cap->capabilities |= V4L2_CAP_VBI_CAPTURE; in bttv_querycap()
2444 if (video_is_registered(&btv->radio_dev)) { in bttv_querycap()
2445 cap->capabilities |= V4L2_CAP_RADIO; in bttv_querycap()
2446 if (btv->has_tea575x) in bttv_querycap()
2447 cap->capabilities |= V4L2_CAP_HW_FREQ_SEEK; in bttv_querycap()
2454 if (btv->has_saa6588) in bttv_querycap()
2455 cap->capabilities |= V4L2_CAP_RDS_CAPTURE; in bttv_querycap()
2456 if (btv->tuner_type != TUNER_ABSENT) in bttv_querycap()
2457 cap->capabilities |= V4L2_CAP_TUNER; in bttv_querycap()
2463 int index = -1, i; in bttv_enum_fmt_cap_ovr()
2466 if (formats[i].fourcc != -1) in bttv_enum_fmt_cap_ovr()
2468 if ((unsigned int)index == f->index) in bttv_enum_fmt_cap_ovr()
2472 return -EINVAL; in bttv_enum_fmt_cap_ovr()
2474 f->pixelformat = formats[i].fourcc; in bttv_enum_fmt_cap_ovr()
2497 return -EINVAL; in bttv_enum_fmt_vid_overlay()
2506 return -EINVAL; in bttv_enum_fmt_vid_overlay()
2515 struct bttv *btv = fh->btv; in bttv_g_fbuf()
2517 *fb = btv->fbuf; in bttv_g_fbuf()
2518 fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING; in bttv_g_fbuf()
2519 fb->flags = V4L2_FBUF_FLAG_PRIMARY; in bttv_g_fbuf()
2520 if (fh->ovfmt) in bttv_g_fbuf()
2521 fb->fmt.pixelformat = fh->ovfmt->fourcc; in bttv_g_fbuf()
2528 struct bttv *btv = fh->btv; in bttv_overlay()
2534 if (unlikely(!btv->fbuf.base)) { in bttv_overlay()
2535 return -EINVAL; in bttv_overlay()
2537 if (unlikely(!fh->ov.setup_ok)) { in bttv_overlay()
2538 dprintk("%d: overlay: !setup_ok\n", btv->c.nr); in bttv_overlay()
2539 retval = -EINVAL; in bttv_overlay()
2546 return -EBUSY; in bttv_overlay()
2549 fh->ov.tvnorm = btv->tvnorm; in bttv_overlay()
2551 new->crop = btv->crop[!!fh->do_crop].rect; in bttv_overlay()
2552 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); in bttv_overlay()
2566 struct bttv *btv = fh->btv; in bttv_s_fbuf()
2572 return -EPERM; in bttv_s_fbuf()
2575 fmt = format_by_fourcc(fb->fmt.pixelformat); in bttv_s_fbuf()
2577 return -EINVAL; in bttv_s_fbuf()
2578 if (0 == (fmt->flags & FORMAT_FLAGS_PACKED)) in bttv_s_fbuf()
2579 return -EINVAL; in bttv_s_fbuf()
2581 retval = -EINVAL; in bttv_s_fbuf()
2582 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { in bttv_s_fbuf()
2583 __s32 width = fb->fmt.width; in bttv_s_fbuf()
2584 __s32 height = fb->fmt.height; in bttv_s_fbuf()
2597 btv->fbuf.base = fb->base; in bttv_s_fbuf()
2598 btv->fbuf.fmt.width = fb->fmt.width; in bttv_s_fbuf()
2599 btv->fbuf.fmt.height = fb->fmt.height; in bttv_s_fbuf()
2600 if (0 != fb->fmt.bytesperline) in bttv_s_fbuf()
2601 btv->fbuf.fmt.bytesperline = fb->fmt.bytesperline; in bttv_s_fbuf()
2603 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8; in bttv_s_fbuf()
2606 fh->ovfmt = fmt; in bttv_s_fbuf()
2607 btv->init.ovfmt = fmt; in bttv_s_fbuf()
2608 if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { in bttv_s_fbuf()
2609 fh->ov.w.left = 0; in bttv_s_fbuf()
2610 fh->ov.w.top = 0; in bttv_s_fbuf()
2611 fh->ov.w.width = fb->fmt.width; in bttv_s_fbuf()
2612 fh->ov.w.height = fb->fmt.height; in bttv_s_fbuf()
2613 btv->init.ov.w.width = fb->fmt.width; in bttv_s_fbuf()
2614 btv->init.ov.w.height = fb->fmt.height; in bttv_s_fbuf()
2616 kfree(fh->ov.clips); in bttv_s_fbuf()
2617 fh->ov.clips = NULL; in bttv_s_fbuf()
2618 fh->ov.nclips = 0; in bttv_s_fbuf()
2624 new->crop = btv->crop[!!fh->do_crop].rect; in bttv_s_fbuf()
2625 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); in bttv_s_fbuf()
2649 struct bttv *btv = fh->btv; in bttv_qbuf()
2653 return -EBUSY; in bttv_qbuf()
2662 file->f_flags & O_NONBLOCK); in bttv_dqbuf()
2669 struct bttv *btv = fh->btv; in bttv_streamon()
2673 return -EBUSY; in bttv_streamon()
2682 struct bttv *btv = fh->btv; in bttv_streamoff()
2698 struct bttv *btv = fh->btv; in bttv_g_parm()
2700 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) in bttv_g_parm()
2701 return -EINVAL; in bttv_g_parm()
2702 parm->parm.capture.readbuffers = gbuffers; in bttv_g_parm()
2703 v4l2_video_std_frame_period(bttv_tvnorms[btv->tvnorm].v4l2_id, in bttv_g_parm()
2704 &parm->parm.capture.timeperframe); in bttv_g_parm()
2713 struct bttv *btv = fh->btv; in bttv_g_tuner()
2715 if (0 != t->index) in bttv_g_tuner()
2716 return -EINVAL; in bttv_g_tuner()
2718 t->rxsubchans = V4L2_TUNER_SUB_MONO; in bttv_g_tuner()
2719 t->capability = V4L2_TUNER_CAP_NORM; in bttv_g_tuner()
2721 strscpy(t->name, "Television", sizeof(t->name)); in bttv_g_tuner()
2722 t->type = V4L2_TUNER_ANALOG_TV; in bttv_g_tuner()
2724 t->signal = 0xffff; in bttv_g_tuner()
2726 if (btv->audio_mode_gpio) in bttv_g_tuner()
2727 btv->audio_mode_gpio(btv, t, 0); in bttv_g_tuner()
2736 struct bttv *btv = fh->btv; in bttv_g_pixelaspect()
2739 return -EINVAL; in bttv_g_pixelaspect()
2742 *f = bttv_tvnorms[btv->tvnorm].cropcap.pixelaspect; in bttv_g_pixelaspect()
2749 struct bttv *btv = fh->btv; in bttv_g_selection()
2751 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && in bttv_g_selection()
2752 sel->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) in bttv_g_selection()
2753 return -EINVAL; in bttv_g_selection()
2755 switch (sel->target) { in bttv_g_selection()
2758 * No fh->do_crop = 1; because btv->crop[1] may be in bttv_g_selection()
2759 * inconsistent with fh->width or fh->height and apps in bttv_g_selection()
2762 sel->r = btv->crop[!!fh->do_crop].rect; in bttv_g_selection()
2765 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.defrect; in bttv_g_selection()
2768 sel->r = bttv_tvnorms[btv->tvnorm].cropcap.bounds; in bttv_g_selection()
2771 return -EINVAL; in bttv_g_selection()
2780 struct bttv *btv = fh->btv; in bttv_s_selection()
2789 if (sel->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && in bttv_s_selection()
2790 sel->type != V4L2_BUF_TYPE_VIDEO_OVERLAY) in bttv_s_selection()
2791 return -EINVAL; in bttv_s_selection()
2793 if (sel->target != V4L2_SEL_TGT_CROP) in bttv_s_selection()
2794 return -EINVAL; in bttv_s_selection()
2799 retval = -EBUSY; in bttv_s_selection()
2801 if (locked_btres(fh->btv, VIDEO_RESOURCES)) { in bttv_s_selection()
2805 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds; in bttv_s_selection()
2807 b_left = b->left; in bttv_s_selection()
2808 b_right = b_left + b->width; in bttv_s_selection()
2809 b_bottom = b->top + b->height; in bttv_s_selection()
2811 b_top = max(b->top, btv->vbi_end); in bttv_s_selection()
2817 c.rect.left = clamp_t(s32, sel->r.left, b_left, b_right - 48); in bttv_s_selection()
2820 c.rect.width = clamp_t(s32, sel->r.width, in bttv_s_selection()
2821 48, b_right - c.rect.left); in bttv_s_selection()
2823 c.rect.top = clamp_t(s32, sel->r.top, b_top, b_bottom - 32); in bttv_s_selection()
2827 c.rect.height = clamp_t(s32, sel->r.height, in bttv_s_selection()
2828 32, b_bottom - c.rect.top); in bttv_s_selection()
2833 sel->r = c.rect; in bttv_s_selection()
2835 btv->crop[1] = c; in bttv_s_selection()
2837 fh->do_crop = 1; in bttv_s_selection()
2839 if (fh->width < c.min_scaled_width) { in bttv_s_selection()
2840 fh->width = c.min_scaled_width; in bttv_s_selection()
2841 btv->init.width = c.min_scaled_width; in bttv_s_selection()
2842 } else if (fh->width > c.max_scaled_width) { in bttv_s_selection()
2843 fh->width = c.max_scaled_width; in bttv_s_selection()
2844 btv->init.width = c.max_scaled_width; in bttv_s_selection()
2847 if (fh->height < c.min_scaled_height) { in bttv_s_selection()
2848 fh->height = c.min_scaled_height; in bttv_s_selection()
2849 btv->init.height = c.min_scaled_height; in bttv_s_selection()
2850 } else if (fh->height > c.max_scaled_height) { in bttv_s_selection()
2851 fh->height = c.max_scaled_height; in bttv_s_selection()
2852 btv->init.height = c.max_scaled_height; in bttv_s_selection()
2861 struct bttv_fh *fh = file->private_data; in bttv_read()
2864 if (fh->btv->errors) in bttv_read()
2865 bttv_reinit_bt848(fh->btv); in bttv_read()
2867 fh->btv->c.nr, (int)count, v4l2_type_names[fh->type]); in bttv_read()
2869 switch (fh->type) { in bttv_read()
2871 if (!check_alloc_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ)) { in bttv_read()
2874 return -EBUSY; in bttv_read()
2876 retval = videobuf_read_one(&fh->cap, data, count, ppos, in bttv_read()
2877 file->f_flags & O_NONBLOCK); in bttv_read()
2878 free_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ); in bttv_read()
2881 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) in bttv_read()
2882 return -EBUSY; in bttv_read()
2883 retval = videobuf_read_stream(&fh->vbi, data, count, ppos, 1, in bttv_read()
2884 file->f_flags & O_NONBLOCK); in bttv_read()
2894 struct bttv_fh *fh = file->private_data; in bttv_poll()
2900 if (v4l2_event_pending(&fh->fh)) in bttv_poll()
2903 poll_wait(file, &fh->fh.wait, wait); in bttv_poll()
2908 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { in bttv_poll()
2909 if (!check_alloc_btres_lock(fh->btv,fh,RESOURCE_VBI)) in bttv_poll()
2911 return rc | videobuf_poll_stream(file, &fh->vbi, wait); in bttv_poll()
2916 if (list_empty(&fh->cap.stream)) in bttv_poll()
2918 buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream); in bttv_poll()
2921 if (NULL == fh->cap.read_buf) { in bttv_poll()
2923 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM)) in bttv_poll()
2925 fh->cap.read_buf = videobuf_sg_alloc(fh->cap.msize); in bttv_poll()
2926 if (NULL == fh->cap.read_buf) in bttv_poll()
2928 fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR; in bttv_poll()
2929 field = videobuf_next_field(&fh->cap); in bttv_poll()
2930 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) { in bttv_poll()
2931 kfree (fh->cap.read_buf); in bttv_poll()
2932 fh->cap.read_buf = NULL; in bttv_poll()
2935 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf); in bttv_poll()
2936 fh->cap.read_off = 0; in bttv_poll()
2938 buf = (struct bttv_buffer*)fh->cap.read_buf; in bttv_poll()
2941 poll_wait(file, &buf->vb.done, wait); in bttv_poll()
2942 if (buf->vb.state == VIDEOBUF_DONE || in bttv_poll()
2943 buf->vb.state == VIDEOBUF_ERROR) in bttv_poll()
2957 if (vdev->vfl_type == VFL_TYPE_VIDEO) { in bttv_open()
2959 } else if (vdev->vfl_type == VFL_TYPE_VBI) { in bttv_open()
2963 return -ENODEV; in bttv_open()
2967 btv->c.nr, v4l2_type_names[type]); in bttv_open()
2972 return -ENOMEM; in bttv_open()
2973 btv->users++; in bttv_open()
2974 file->private_data = fh; in bttv_open()
2976 *fh = btv->init; in bttv_open()
2977 v4l2_fh_init(&fh->fh, vdev); in bttv_open()
2979 fh->type = type; in bttv_open()
2980 fh->ov.setup_ok = 0; in bttv_open()
2982 videobuf_queue_sg_init(&fh->cap, &bttv_video_qops, in bttv_open()
2983 &btv->c.pci->dev, &btv->s_lock, in bttv_open()
2987 fh, &btv->lock); in bttv_open()
2988 videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops, in bttv_open()
2989 &btv->c.pci->dev, &btv->s_lock, in bttv_open()
2993 fh, &btv->lock); in bttv_open()
2994 set_tvnorm(btv,btv->tvnorm); in bttv_open()
2995 set_input(btv, btv->input, btv->tvnorm); in bttv_open()
2996 audio_mute(btv, btv->mute); in bttv_open()
2999 which only change on request. These are stored in btv->crop[1]. in bttv_open()
3003 will use btv->crop[0], the default cropping parameters for the in bttv_open()
3007 fh->do_crop = !reset_crop; /* module parameter */ in bttv_open()
3012 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); in bttv_open()
3015 v4l2_fh_add(&fh->fh); in bttv_open()
3021 struct bttv_fh *fh = file->private_data; in bttv_release()
3022 struct bttv *btv = fh->btv; in bttv_release()
3030 videobuf_streamoff(&fh->cap); in bttv_release()
3033 if (fh->cap.read_buf) { in bttv_release()
3034 buffer_release(&fh->cap,fh->cap.read_buf); in bttv_release()
3035 kfree(fh->cap.read_buf); in bttv_release()
3043 videobuf_stop(&fh->vbi); in bttv_release()
3049 videobuf_mmap_free(&fh->cap); in bttv_release()
3050 videobuf_mmap_free(&fh->vbi); in bttv_release()
3051 file->private_data = NULL; in bttv_release()
3053 btv->users--; in bttv_release()
3056 if (!btv->users) in bttv_release()
3057 audio_mute(btv, btv->mute); in bttv_release()
3059 v4l2_fh_del(&fh->fh); in bttv_release()
3060 v4l2_fh_exit(&fh->fh); in bttv_release()
3068 struct bttv_fh *fh = file->private_data; in bttv_mmap()
3071 fh->btv->c.nr, v4l2_type_names[fh->type], in bttv_mmap()
3072 vma->vm_start, vma->vm_end - vma->vm_start); in bttv_mmap()
3138 /* ----------------------------------------------------------------------- */
3149 dprintk("%d: open called (radio)\n", btv->c.nr); in radio_open()
3154 return -ENOMEM; in radio_open()
3155 file->private_data = fh; in radio_open()
3156 *fh = btv->init; in radio_open()
3157 v4l2_fh_init(&fh->fh, vdev); in radio_open()
3159 btv->radio_user++; in radio_open()
3160 audio_mute(btv, btv->mute); in radio_open()
3162 v4l2_fh_add(&fh->fh); in radio_open()
3169 struct bttv_fh *fh = file->private_data; in radio_release()
3170 struct bttv *btv = fh->btv; in radio_release()
3173 file->private_data = NULL; in radio_release()
3174 v4l2_fh_del(&fh->fh); in radio_release()
3175 v4l2_fh_exit(&fh->fh); in radio_release()
3178 btv->radio_user--; in radio_release()
3182 if (btv->radio_user == 0) in radio_release()
3183 btv->has_radio_tuner = 0; in radio_release()
3190 struct bttv *btv = fh->btv; in radio_g_tuner()
3192 if (0 != t->index) in radio_g_tuner()
3193 return -EINVAL; in radio_g_tuner()
3194 strscpy(t->name, "Radio", sizeof(t->name)); in radio_g_tuner()
3195 t->type = V4L2_TUNER_RADIO; in radio_g_tuner()
3200 if (btv->audio_mode_gpio) in radio_g_tuner()
3201 btv->audio_mode_gpio(btv, t, 0); in radio_g_tuner()
3203 if (btv->has_tea575x) in radio_g_tuner()
3204 return snd_tea575x_g_tuner(&btv->tea, t); in radio_g_tuner()
3213 struct bttv *btv = fh->btv; in radio_s_tuner()
3215 if (0 != t->index) in radio_s_tuner()
3216 return -EINVAL; in radio_s_tuner()
3227 struct bttv *btv = fh->btv; in radio_s_hw_freq_seek()
3229 if (btv->has_tea575x) in radio_s_hw_freq_seek()
3230 return snd_tea575x_s_hw_freq_seek(file, &btv->tea, a); in radio_s_hw_freq_seek()
3232 return -ENOTTY; in radio_s_hw_freq_seek()
3239 struct bttv *btv = fh->btv; in radio_enum_freq_bands()
3241 if (btv->has_tea575x) in radio_enum_freq_bands()
3242 return snd_tea575x_enum_freq_bands(&btv->tea, band); in radio_enum_freq_bands()
3244 return -ENOTTY; in radio_enum_freq_bands()
3250 struct bttv_fh *fh = file->private_data; in radio_read()
3251 struct bttv *btv = fh->btv; in radio_read()
3255 cmd.nonblocking = file->f_flags & O_NONBLOCK; in radio_read()
3258 cmd.result = -ENODEV; in radio_read()
3268 struct bttv_fh *fh = file->private_data; in radio_poll()
3269 struct bttv *btv = fh->btv; in radio_poll()
3274 if (v4l2_event_pending(&fh->fh)) in radio_poll()
3277 poll_wait(file, &fh->fh.wait, wait); in radio_poll()
3315 /* ----------------------------------------------------------------------- */
3348 for (i = ARRAY_SIZE(bits)-1; i >= 0; i--) in bttv_risc_decode()
3361 btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma); in bttv_risc_disasm()
3362 for (i = 0; i < (risc->size >> 2); i += n) { in bttv_risc_disasm()
3364 btv->c.v4l2_dev.name, in bttv_risc_disasm()
3365 (unsigned long)(risc->dma + (i<<2))); in bttv_risc_disasm()
3366 n = bttv_risc_decode(le32_to_cpu(risc->cpu[i])); in bttv_risc_disasm()
3369 btv->c.v4l2_dev.name, in bttv_risc_disasm()
3370 (unsigned long)(risc->dma + ((i+j)<<2)), in bttv_risc_disasm()
3371 risc->cpu[i+j], j); in bttv_risc_disasm()
3372 if (0 == risc->cpu[i]) in bttv_risc_disasm()
3379 pr_info(" main: %08llx\n", (unsigned long long)btv->main.dma); in bttv_print_riscaddr()
3381 btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0, in bttv_print_riscaddr()
3382 btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0); in bttv_print_riscaddr()
3384 btv->curr.top in bttv_print_riscaddr()
3385 ? (unsigned long long)btv->curr.top->top.dma : 0, in bttv_print_riscaddr()
3386 btv->curr.bottom in bttv_print_riscaddr()
3387 ? (unsigned long long)btv->curr.bottom->bottom.dma : 0); in bttv_print_riscaddr()
3389 btv->screen ? (unsigned long long)btv->screen->top.dma : 0, in bttv_print_riscaddr()
3390 btv->screen ? (unsigned long long)btv->screen->bottom.dma : 0); in bttv_print_riscaddr()
3391 bttv_risc_disasm(btv, &btv->main); in bttv_print_riscaddr()
3394 /* ----------------------------------------------------------------------- */
3435 btv->c.nr, in bttv_irq_debug_low_latency()
3436 (unsigned long)btv->main.dma, in bttv_irq_debug_low_latency()
3437 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]), in bttv_irq_debug_low_latency()
3438 (unsigned long)le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]), in bttv_irq_debug_low_latency()
3443 btv->c.nr); in bttv_irq_debug_low_latency()
3447 btv->c.nr); in bttv_irq_debug_low_latency()
3448 pr_notice("%d: Lets try to catch the culprit red-handed ...\n", in bttv_irq_debug_low_latency()
3449 btv->c.nr); in bttv_irq_debug_low_latency()
3461 if (!list_empty(&btv->capture)) { in bttv_irq_next_video()
3462 set->frame_irq = 1; in bttv_irq_next_video()
3463 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue); in bttv_irq_next_video()
3464 if (V4L2_FIELD_HAS_TOP(item->vb.field)) in bttv_irq_next_video()
3465 set->top = item; in bttv_irq_next_video()
3466 if (V4L2_FIELD_HAS_BOTTOM(item->vb.field)) in bttv_irq_next_video()
3467 set->bottom = item; in bttv_irq_next_video()
3470 if (!V4L2_FIELD_HAS_BOTH(item->vb.field) && in bttv_irq_next_video()
3471 (item->vb.queue.next != &btv->capture)) { in bttv_irq_next_video()
3472 item = list_entry(item->vb.queue.next, struct bttv_buffer, vb.queue); in bttv_irq_next_video()
3473 /* Mike Isely <isely@pobox.com> - Only check in bttv_irq_next_video()
3488 * field first - the effect will be the two in bttv_irq_next_video()
3500 if (!V4L2_FIELD_HAS_BOTH(item->vb.field)) { in bttv_irq_next_video()
3501 if (NULL == set->bottom && in bttv_irq_next_video()
3502 V4L2_FIELD_BOTTOM == item->vb.field) { in bttv_irq_next_video()
3503 set->bottom = item; in bttv_irq_next_video()
3505 if (NULL != set->top && NULL != set->bottom) in bttv_irq_next_video()
3506 set->top_irq = 2; in bttv_irq_next_video()
3512 if (NULL != btv->screen) { in bttv_irq_next_video()
3513 if (V4L2_FIELD_HAS_BOTH(btv->screen->vb.field)) { in bttv_irq_next_video()
3514 if (NULL == set->top && NULL == set->bottom) { in bttv_irq_next_video()
3515 set->top = btv->screen; in bttv_irq_next_video()
3516 set->bottom = btv->screen; in bttv_irq_next_video()
3519 if (V4L2_FIELD_TOP == btv->screen->vb.field && in bttv_irq_next_video()
3520 NULL == set->top) { in bttv_irq_next_video()
3521 set->top = btv->screen; in bttv_irq_next_video()
3523 if (V4L2_FIELD_BOTTOM == btv->screen->vb.field && in bttv_irq_next_video()
3524 NULL == set->bottom) { in bttv_irq_next_video()
3525 set->bottom = btv->screen; in bttv_irq_next_video()
3531 btv->c.nr, set->top, set->bottom, in bttv_irq_next_video()
3532 btv->screen, set->frame_irq, set->top_irq); in bttv_irq_next_video()
3542 if (wakeup->top == wakeup->bottom) { in bttv_irq_wakeup_video()
3543 if (NULL != wakeup->top && curr->top != wakeup->top) { in bttv_irq_wakeup_video()
3546 btv->c.nr, wakeup->top); in bttv_irq_wakeup_video()
3547 wakeup->top->vb.ts = ts; in bttv_irq_wakeup_video()
3548 wakeup->top->vb.field_count = btv->field_count; in bttv_irq_wakeup_video()
3549 wakeup->top->vb.state = state; in bttv_irq_wakeup_video()
3550 wake_up(&wakeup->top->vb.done); 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()
3562 if (NULL != wakeup->bottom && curr->bottom != wakeup->bottom) { in bttv_irq_wakeup_video()
3565 btv->c.nr, wakeup->bottom); in bttv_irq_wakeup_video()
3566 wakeup->bottom->vb.ts = ts; in bttv_irq_wakeup_video()
3567 wakeup->bottom->vb.field_count = btv->field_count; in bttv_irq_wakeup_video()
3568 wakeup->bottom->vb.state = state; in bttv_irq_wakeup_video()
3569 wake_up(&wakeup->bottom->vb.done); in bttv_irq_wakeup_video()
3581 wakeup->vb.ts = ktime_get_ns(); in bttv_irq_wakeup_vbi()
3582 wakeup->vb.field_count = btv->field_count; in bttv_irq_wakeup_vbi()
3583 wakeup->vb.state = state; in bttv_irq_wakeup_vbi()
3584 wake_up(&wakeup->vb.done); in bttv_irq_wakeup_vbi()
3597 btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total, in bttv_irq_timeout()
3603 spin_lock_irqsave(&btv->s_lock,flags); in bttv_irq_timeout()
3607 old = btv->curr; in bttv_irq_timeout()
3608 ovbi = btv->cvbi; in bttv_irq_timeout()
3609 btv->curr = new; in bttv_irq_timeout()
3610 btv->cvbi = NULL; in bttv_irq_timeout()
3611 btv->loop_irq = 0; in bttv_irq_timeout()
3621 while (!list_empty(&btv->capture)) { in bttv_irq_timeout()
3622 item = list_entry(btv->capture.next, struct bttv_buffer, vb.queue); in bttv_irq_timeout()
3623 list_del(&item->vb.queue); in bttv_irq_timeout()
3624 item->vb.state = VIDEOBUF_ERROR; in bttv_irq_timeout()
3625 wake_up(&item->vb.done); in bttv_irq_timeout()
3627 while (!list_empty(&btv->vcapture)) { in bttv_irq_timeout()
3628 item = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue); in bttv_irq_timeout()
3629 list_del(&item->vb.queue); in bttv_irq_timeout()
3630 item->vb.state = VIDEOBUF_ERROR; in bttv_irq_timeout()
3631 wake_up(&item->vb.done); in bttv_irq_timeout()
3634 btv->errors++; in bttv_irq_timeout()
3635 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_irq_timeout()
3641 struct bttv_buffer *wakeup = btv->curr.top; in bttv_irq_wakeup_top()
3646 spin_lock(&btv->s_lock); in bttv_irq_wakeup_top()
3647 btv->curr.top_irq = 0; in bttv_irq_wakeup_top()
3648 btv->curr.top = NULL; in bttv_irq_wakeup_top()
3651 wakeup->vb.ts = ktime_get_ns(); in bttv_irq_wakeup_top()
3652 wakeup->vb.field_count = btv->field_count; in bttv_irq_wakeup_top()
3653 wakeup->vb.state = VIDEOBUF_DONE; in bttv_irq_wakeup_top()
3654 wake_up(&wakeup->vb.done); in bttv_irq_wakeup_top()
3655 spin_unlock(&btv->s_lock); in bttv_irq_wakeup_top()
3660 if (rc < risc->dma) in is_active()
3662 if (rc > risc->dma + risc->size) in is_active()
3674 spin_lock(&btv->s_lock); in bttv_irq_switch_video()
3679 if ((btv->curr.top && is_active(&btv->curr.top->top, rc)) || in bttv_irq_switch_video()
3680 (btv->curr.bottom && is_active(&btv->curr.bottom->bottom, rc))) { in bttv_irq_switch_video()
3681 btv->framedrop++; in bttv_irq_switch_video()
3684 spin_unlock(&btv->s_lock); in bttv_irq_switch_video()
3689 old = btv->curr; in bttv_irq_switch_video()
3690 btv->curr = new; in bttv_irq_switch_video()
3691 btv->loop_irq &= ~1; in bttv_irq_switch_video()
3696 if (UNSET != btv->new_input) { in bttv_irq_switch_video()
3697 video_mux(btv,btv->new_input); in bttv_irq_switch_video()
3698 btv->new_input = UNSET; in bttv_irq_switch_video()
3703 spin_unlock(&btv->s_lock); in bttv_irq_switch_video()
3713 spin_lock(&btv->s_lock); in bttv_irq_switch_vbi()
3715 if (!list_empty(&btv->vcapture)) in bttv_irq_switch_vbi()
3716 new = list_entry(btv->vcapture.next, struct bttv_buffer, vb.queue); in bttv_irq_switch_vbi()
3717 old = btv->cvbi; in bttv_irq_switch_vbi()
3720 if (NULL != old && (is_active(&old->top, rc) || in bttv_irq_switch_vbi()
3721 is_active(&old->bottom, rc))) { in bttv_irq_switch_vbi()
3722 btv->framedrop++; in bttv_irq_switch_vbi()
3725 spin_unlock(&btv->s_lock); in bttv_irq_switch_vbi()
3730 btv->cvbi = new; in bttv_irq_switch_vbi()
3731 btv->loop_irq &= ~4; in bttv_irq_switch_vbi()
3736 spin_unlock(&btv->s_lock); in bttv_irq_switch_vbi()
3764 btv->c.nr, count, btv->field_count, in bttv_irq()
3783 btv->field_count++; in bttv_irq()
3785 if ((astat & BT848_INT_GPINT) && btv->remote) { in bttv_irq()
3790 btv->i2c_done = stat; in bttv_irq()
3791 wake_up(&btv->i2c_queue); in bttv_irq()
3803 if ((astat & BT848_INT_HLOCK) && btv->opt_automute) in bttv_irq()
3805 audio_mux_gpio(btv, btv->audio_input, btv->mute); in bttv_irq()
3809 btv->c.nr, in bttv_irq()
3820 btv->c.nr, btread(BT848_RISC_COUNT)); in bttv_irq()
3832 btv->c.nr); in bttv_irq()
3835 btv->c.nr); in bttv_irq()
3837 btwrite(btread(BT848_INT_MASK) & (-1 ^ BT848_INT_GPINT), in bttv_irq()
3846 btv->irq_total++; in bttv_irq()
3848 btv->irq_me++; in bttv_irq()
3853 /* ----------------------------------------------------------------------- */
3862 vfd->v4l2_dev = &btv->c.v4l2_dev; in vdev_init()
3863 vfd->release = video_device_release_empty; in vdev_init()
3865 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", in vdev_init()
3866 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", in vdev_init()
3867 type_name, bttv_tvcards[btv->c.type].name); in vdev_init()
3868 if (btv->tuner_type == TUNER_ABSENT) { in vdev_init()
3878 video_unregister_device(&btv->video_dev); in bttv_unregister_video()
3879 video_unregister_device(&btv->vbi_dev); in bttv_unregister_video()
3880 video_unregister_device(&btv->radio_dev); in bttv_unregister_video()
3890 vdev_init(btv, &btv->video_dev, &bttv_video_template, "video"); in bttv_register_video()
3891 btv->video_dev.device_caps = V4L2_CAP_VIDEO_CAPTURE | in bttv_register_video()
3893 if (btv->tuner_type != TUNER_ABSENT) in bttv_register_video()
3894 btv->video_dev.device_caps |= V4L2_CAP_TUNER; in bttv_register_video()
3896 btv->video_dev.device_caps |= V4L2_CAP_VIDEO_OVERLAY; in bttv_register_video()
3898 if (video_register_device(&btv->video_dev, VFL_TYPE_VIDEO, in bttv_register_video()
3899 video_nr[btv->c.nr]) < 0) in bttv_register_video()
3902 btv->c.nr, video_device_node_name(&btv->video_dev)); in bttv_register_video()
3903 if (device_create_file(&btv->video_dev.dev, in bttv_register_video()
3905 pr_err("%d: device_create_file 'card' failed\n", btv->c.nr); in bttv_register_video()
3910 vdev_init(btv, &btv->vbi_dev, &bttv_video_template, "vbi"); in bttv_register_video()
3911 btv->vbi_dev.device_caps = V4L2_CAP_VBI_CAPTURE | V4L2_CAP_READWRITE | in bttv_register_video()
3913 if (btv->tuner_type != TUNER_ABSENT) in bttv_register_video()
3914 btv->vbi_dev.device_caps |= V4L2_CAP_TUNER; in bttv_register_video()
3916 if (video_register_device(&btv->vbi_dev, VFL_TYPE_VBI, in bttv_register_video()
3917 vbi_nr[btv->c.nr]) < 0) in bttv_register_video()
3920 btv->c.nr, video_device_node_name(&btv->vbi_dev)); in bttv_register_video()
3922 if (!btv->has_radio) in bttv_register_video()
3925 vdev_init(btv, &btv->radio_dev, &radio_template, "radio"); in bttv_register_video()
3926 btv->radio_dev.device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER; in bttv_register_video()
3927 if (btv->has_saa6588) in bttv_register_video()
3928 btv->radio_dev.device_caps |= V4L2_CAP_READWRITE | in bttv_register_video()
3930 if (btv->has_tea575x) in bttv_register_video()
3931 btv->radio_dev.device_caps |= V4L2_CAP_HW_FREQ_SEEK; in bttv_register_video()
3932 btv->radio_dev.ctrl_handler = &btv->radio_ctrl_handler; in bttv_register_video()
3933 if (video_register_device(&btv->radio_dev, VFL_TYPE_RADIO, in bttv_register_video()
3934 radio_nr[btv->c.nr]) < 0) in bttv_register_video()
3937 btv->c.nr, video_device_node_name(&btv->radio_dev)); in bttv_register_video()
3944 return -1; in bttv_register_video()
3974 return -ENOMEM; in bttv_probe()
3979 return -ENOMEM; in bttv_probe()
3981 btv->c.nr = bttv_num; in bttv_probe()
3982 snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name), in bttv_probe()
3983 "bttv%d", btv->c.nr); in bttv_probe()
3986 mutex_init(&btv->lock); in bttv_probe()
3987 spin_lock_init(&btv->s_lock); in bttv_probe()
3988 spin_lock_init(&btv->gpio_lock); in bttv_probe()
3989 init_waitqueue_head(&btv->i2c_queue); in bttv_probe()
3990 INIT_LIST_HEAD(&btv->c.subs); in bttv_probe()
3991 INIT_LIST_HEAD(&btv->capture); in bttv_probe()
3992 INIT_LIST_HEAD(&btv->vcapture); in bttv_probe()
3994 timer_setup(&btv->timeout, bttv_irq_timeout, 0); in bttv_probe()
3996 btv->i2c_rc = -1; in bttv_probe()
3997 btv->tuner_type = UNSET; in bttv_probe()
3998 btv->new_input = UNSET; in bttv_probe()
3999 btv->has_radio=radio[btv->c.nr]; in bttv_probe()
4002 btv->c.pci = dev; in bttv_probe()
4003 btv->id = dev->device; in bttv_probe()
4005 pr_warn("%d: Can't enable device\n", btv->c.nr); in bttv_probe()
4006 result = -EIO; in bttv_probe()
4009 if (dma_set_mask(&dev->dev, DMA_BIT_MASK(32))) { in bttv_probe()
4010 pr_warn("%d: No suitable DMA available\n", btv->c.nr); in bttv_probe()
4011 result = -EIO; in bttv_probe()
4016 btv->c.v4l2_dev.name)) { in bttv_probe()
4018 btv->c.nr, in bttv_probe()
4020 result = -EBUSY; in bttv_probe()
4026 result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev); in bttv_probe()
4028 pr_warn("%d: v4l2_device_register() failed\n", btv->c.nr); in bttv_probe()
4031 hdl = &btv->ctrl_handler; in bttv_probe()
4033 btv->c.v4l2_dev.ctrl_handler = hdl; in bttv_probe()
4034 v4l2_ctrl_handler_init(&btv->radio_ctrl_handler, 6); in bttv_probe()
4036 btv->revision = dev->revision; in bttv_probe()
4039 bttv_num, btv->id, btv->revision, pci_name(dev), in bttv_probe()
4040 btv->c.pci->irq, lat, in bttv_probe()
4044 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000); in bttv_probe()
4045 if (NULL == btv->bt848_mmio) { in bttv_probe()
4046 pr_err("%d: ioremap() failed\n", btv->c.nr); in bttv_probe()
4047 result = -EIO; in bttv_probe()
4056 result = request_irq(btv->c.pci->irq, bttv_irq, in bttv_probe()
4057 IRQF_SHARED, btv->c.v4l2_dev.name, (void *)btv); in bttv_probe()
4060 bttv_num, btv->c.pci->irq); in bttv_probe()
4065 result = -EIO; in bttv_probe()
4070 btv->opt_combfilter = combfilter; in bttv_probe()
4073 btv->opt_automute = automute; in bttv_probe()
4076 btv->opt_vcr_hack = vcr_hack; in bttv_probe()
4080 btv->opt_uv_ratio = uv_ratio; in bttv_probe()
4086 btv->init.btv = btv; in bttv_probe()
4087 btv->init.ov.w.width = 320; in bttv_probe()
4088 btv->init.ov.w.height = 240; in bttv_probe()
4089 btv->init.fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); in bttv_probe()
4090 btv->init.width = 320; in bttv_probe()
4091 btv->init.height = 240; in bttv_probe()
4092 btv->init.ov.w.width = 320; in bttv_probe()
4093 btv->init.ov.w.height = 240; in bttv_probe()
4094 btv->init.ov.field = V4L2_FIELD_INTERLACED; in bttv_probe()
4095 btv->input = 0; in bttv_probe()
4111 if (btv->volume_gpio) in bttv_probe()
4127 bttv_gpio_tracking(btv,"pre-init"); in bttv_probe()
4144 /* some card-specific stuff (needs working i2c) */ in bttv_probe()
4147 if (btv->tuner_type != TUNER_ABSENT) { in bttv_probe()
4149 btv->radio_freq = 90500 * 16; /* 90.5Mhz default */ in bttv_probe()
4151 btv->std = V4L2_STD_PAL; in bttv_probe()
4153 if (!bttv_tvcards[btv->c.type].no_video) in bttv_probe()
4155 if (hdl->error) { in bttv_probe()
4156 result = hdl->error; in bttv_probe()
4163 if (!bttv_tvcards[btv->c.type].no_video) { in bttv_probe()
4164 v4l2_ctrl_add_handler(&btv->radio_ctrl_handler, hdl, in bttv_probe()
4166 if (btv->radio_ctrl_handler.error) { in bttv_probe()
4167 result = btv->radio_ctrl_handler.error; in bttv_probe()
4170 set_input(btv, 0, btv->tvnorm); in bttv_probe()
4171 bttv_crop_reset(&btv->crop[0], btv->tvnorm); in bttv_probe()
4172 btv->crop[1] = btv->crop[0]; /* current = default */ in bttv_probe()
4178 /* add subdevices and autoload dvb-bt8xx if needed */ in bttv_probe()
4179 if (bttv_tvcards[btv->c.type].has_dvb) { in bttv_probe()
4180 bttv_sub_add_device(&btv->c, "dvb"); in bttv_probe()
4194 free_irq(btv->c.pci->irq,btv); in bttv_probe()
4197 v4l2_ctrl_handler_free(&btv->ctrl_handler); in bttv_probe()
4198 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler); in bttv_probe()
4199 v4l2_device_unregister(&btv->c.v4l2_dev); in bttv_probe()
4202 if (btv->bt848_mmio) in bttv_probe()
4203 iounmap(btv->bt848_mmio); in bttv_probe()
4204 release_mem_region(pci_resource_start(btv->c.pci,0), in bttv_probe()
4205 pci_resource_len(btv->c.pci,0)); in bttv_probe()
4206 pci_disable_device(btv->c.pci); in bttv_probe()
4209 bttvs[btv->c.nr] = NULL; in bttv_probe()
4220 pr_info("%d: unloading\n", btv->c.nr); in bttv_remove()
4222 if (bttv_tvcards[btv->c.type].has_dvb) in bttv_remove()
4234 btv->shutdown=1; in bttv_remove()
4236 bttv_sub_del_devices(&btv->c); in bttv_remove()
4245 v4l2_ctrl_handler_free(&btv->ctrl_handler); in bttv_remove()
4246 v4l2_ctrl_handler_free(&btv->radio_ctrl_handler); in bttv_remove()
4247 btcx_riscmem_free(btv->c.pci,&btv->main); in bttv_remove()
4250 free_irq(btv->c.pci->irq,btv); in bttv_remove()
4251 iounmap(btv->bt848_mmio); in bttv_remove()
4252 release_mem_region(pci_resource_start(btv->c.pci,0), in bttv_remove()
4253 pci_resource_len(btv->c.pci,0)); in bttv_remove()
4254 pci_disable_device(btv->c.pci); in bttv_remove()
4256 v4l2_device_unregister(&btv->c.v4l2_dev); in bttv_remove()
4257 bttvs[btv->c.nr] = NULL; in bttv_remove()
4270 dprintk("%d: suspend\n", btv->c.nr); in bttv_suspend()
4273 spin_lock_irqsave(&btv->s_lock,flags); in bttv_suspend()
4275 btv->state.video = btv->curr; in bttv_suspend()
4276 btv->state.vbi = btv->cvbi; in bttv_suspend()
4277 btv->state.loop_irq = btv->loop_irq; in bttv_suspend()
4278 btv->curr = idle; in bttv_suspend()
4279 btv->loop_irq = 0; in bttv_suspend()
4284 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_suspend()
4287 btv->state.gpio_enable = btread(BT848_GPIO_OUT_EN); in bttv_suspend()
4288 btv->state.gpio_data = gpio_read(); in bttv_suspend()
4290 btv->state.disabled = 1; in bttv_suspend()
4300 dprintk("%d: resume\n", btv->c.nr); in bttv_resume()
4302 btv->state.disabled = 0; in bttv_resume()
4306 gpio_inout(0xffffff, btv->state.gpio_enable); in bttv_resume()
4307 gpio_write(btv->state.gpio_data); in bttv_resume()
4310 spin_lock_irqsave(&btv->s_lock,flags); in bttv_resume()
4311 btv->curr = btv->state.video; in bttv_resume()
4312 btv->cvbi = btv->state.vbi; in bttv_resume()
4313 btv->loop_irq = btv->state.loop_irq; in bttv_resume()
4314 bttv_buffer_activate_video(btv, &btv->curr); in bttv_resume()
4315 bttv_buffer_activate_vbi(btv, btv->cvbi); in bttv_resume()
4317 spin_unlock_irqrestore(&btv->s_lock,flags); in bttv_resume()
4355 gbufsize = (gbufsize + PAGE_SIZE - 1) & PAGE_MASK; in bttv_init_module()