37 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40 #include <linux/module.h>
42 #include <linux/slab.h>
43 #include <linux/errno.h>
45 #include <linux/kernel.h>
46 #include <linux/sched.h>
48 #include <linux/kdev_t.h>
58 #include <asm/byteorder.h>
62 #define BTTV_VERSION "0.9.19"
73 static unsigned int bigendian=1;
75 static unsigned int bigendian;
77 static unsigned int radio[BTTV_MAX];
78 static unsigned int irq_debug;
79 static unsigned int gbuffers = 8;
80 static unsigned int gbufsize = 0x208000;
81 static unsigned int reset_crop = 1;
83 static int video_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
84 static int radio_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
85 static int vbi_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
86 static int debug_latency;
87 static int disable_ir;
89 static unsigned int fdsr;
92 static unsigned int combfilter;
93 static unsigned int lumafilter;
94 static unsigned int automute = 1;
95 static unsigned int chroma_agc;
96 static unsigned int adc_crush = 1;
97 static unsigned int whitecrush_upper = 0xCF;
98 static unsigned int whitecrush_lower = 0x7F;
99 static unsigned int vcr_hack;
100 static unsigned int irq_iswitch;
101 static unsigned int uv_ratio = 50;
102 static unsigned int full_luma_range;
103 static unsigned int coring;
106 static unsigned int v4l2 = 1;
142 MODULE_PARM_DESC(bigendian,
"byte order of the framebuffer, default is native endian");
146 MODULE_PARM_DESC(irq_debug,
"irq handler debug messages, default is 0 (no)");
148 MODULE_PARM_DESC(gbuffers,
"number of capture buffers. range 2-32, default 8");
149 MODULE_PARM_DESC(gbufsize,
"size of the capture buffers, default is 0x208000");
151 "is 1 (yes) for compatibility with older applications");
152 MODULE_PARM_DESC(automute,
"mute audio on bad/missing video signal, default is 1 (yes)");
153 MODULE_PARM_DESC(chroma_agc,
"enables the AGC of chroma signal, default is 0 (no)");
154 MODULE_PARM_DESC(adc_crush,
"enables the luminance ADC crush, default is 1 (yes)");
155 MODULE_PARM_DESC(whitecrush_upper,
"sets the white crush upper value, default is 207");
156 MODULE_PARM_DESC(whitecrush_lower,
"sets the white crush lower value, default is 127");
157 MODULE_PARM_DESC(vcr_hack,
"enables the VCR hack (improves synch on poor VCR tapes), default is 0 (no)");
160 MODULE_PARM_DESC(full_luma_range,
"use the full luma range, default is 0 (no)");
167 MODULE_AUTHOR(
"Ralph Metzler & Marcus Metzler & Gerd Knorr");
178 struct bttv *btv = video_get_drvdata(vfd);
185 #if defined(CONFIG_MODULES) && defined(MODULE)
188 request_module(
"dvb-bt8xx");
193 INIT_WORK(&dev->request_module_wk, request_module_async);
202 #define request_modules(dev)
203 #define flush_request_modules(dev)
211 static u8 SRAM_Table[][60] =
216 0x36,0x11,0x01,0x00,0x90,0x02,0x05,0x10,0x04,0x16,
217 0x12,0x05,0x11,0x00,0x04,0x12,0xC0,0x00,0x31,0x00,
218 0x06,0x51,0x08,0x03,0x89,0x08,0x07,0xC0,0x44,0x00,
219 0x81,0x01,0x01,0xA9,0x0D,0x02,0x02,0x50,0x03,0x37,
220 0x37,0x00,0xAF,0x21,0x00
225 0x0C,0xC0,0x00,0x00,0x90,0x02,0x03,0x10,0x03,0x06,
226 0x10,0x04,0x12,0x12,0x05,0x02,0x13,0x04,0x19,0x00,
227 0x04,0x39,0x00,0x06,0x59,0x08,0x03,0x83,0x08,0x07,
228 0x03,0x50,0x00,0xC0,0x40,0x00,0x86,0x01,0x01,0xA6,
229 0x0D,0x02,0x03,0x11,0x01,0x05,0x37,0x00,0xAC,0x21,
236 0x06, 0x08, 0x04, 0x0a, 0xc0, 0x00, 0x18, 0x08, 0x03, 0x24,
237 0x08, 0x07, 0x02, 0x90, 0x02, 0x08, 0x10, 0x04, 0x0c, 0x10,
238 0x05, 0x2c, 0x11, 0x04, 0x55, 0x48, 0x00, 0x05, 0x50, 0x00,
239 0xbf, 0x0c, 0x02, 0x2f, 0x3d, 0x00, 0x2f, 0x3f, 0x00, 0xc3,
255 #define CROPCAP(minhdelayx1, hdelayx1, swidth, totalwidth, sqwidth, \
256 vdelay, sheight, videostart0) \
257 .cropcap.bounds.left = minhdelayx1, \
260 .cropcap.bounds.top = (videostart0) * 2 - (vdelay) + MIN_VDELAY, \
262 .cropcap.bounds.width = (totalwidth) - (minhdelayx1) - 4, \
263 .cropcap.bounds.height = (sheight) + (vdelay) - MIN_VDELAY, \
264 .cropcap.defrect.left = hdelayx1, \
265 .cropcap.defrect.top = (videostart0) * 2, \
266 .cropcap.defrect.width = swidth, \
267 .cropcap.defrect.height = sheight, \
268 .cropcap.pixelaspect.numerator = totalwidth, \
269 .cropcap.pixelaspect.denominator = sqwidth,
285 .scaledtwidth = 1135,
294 .vbistart = { 7, 320 },
308 .cropcap.bounds.height = (576 + 2) + 0x20 - 2,
325 .vbistart = { 10, 273 },
345 .scaledtwidth = 1135,
351 .vbistart = { 7, 320 },
376 .vbistart = { 7, 320 },
379 (640 * 910 + 780 / 2) / 780,
401 .vbistart = { 10, 273 },
404 (640 * 910 + 780 / 2) / 780,
426 .vbistart = { 7, 320 },
429 (768 * 1135 + 944 / 2) / 944,
451 .vbistart = { 10, 273 },
454 (640 * 910 + 780 / 2) / 780,
473 .scaledtwidth = 1135,
480 .vbistart = { 10, 273 },
491 static const unsigned int BTTV_TVNORMS =
ARRAY_SIZE(bttv_tvnorms);
496 static const struct bttv_format formats[] = {
498 .name =
"8 bpp, gray",
504 .name =
"8 bpp, dithered color",
510 .name =
"15 bpp RGB, le",
516 .name =
"15 bpp RGB, be",
523 .name =
"16 bpp RGB, le",
529 .name =
"16 bpp RGB, be",
536 .name =
"24 bpp RGB, le",
542 .name =
"32 bpp RGB, le",
548 .name =
"32 bpp RGB, be",
555 .name =
"4:2:2, packed, YUYV",
561 .name =
"4:2:2, packed, UYVY",
568 .name =
"4:2:2, planar, Y-Cb-Cr",
576 .name =
"4:2:0, planar, Y-Cb-Cr",
584 .name =
"4:2:0, planar, Y-Cr-Cb",
592 .name =
"4:1:1, planar, Y-Cb-Cr",
600 .name =
"4:1:0, planar, Y-Cb-Cr",
608 .name =
"4:1:0, planar, Y-Cr-Cb",
616 .name =
"raw scanlines",
620 .flags = FORMAT_FLAGS_RAW,
627 #define V4L2_CID_PRIVATE_CHROMA_AGC (V4L2_CID_PRIVATE_BASE + 0)
628 #define V4L2_CID_PRIVATE_COMBFILTER (V4L2_CID_PRIVATE_BASE + 1)
629 #define V4L2_CID_PRIVATE_AUTOMUTE (V4L2_CID_PRIVATE_BASE + 2)
630 #define V4L2_CID_PRIVATE_LUMAFILTER (V4L2_CID_PRIVATE_BASE + 3)
631 #define V4L2_CID_PRIVATE_AGC_CRUSH (V4L2_CID_PRIVATE_BASE + 4)
632 #define V4L2_CID_PRIVATE_VCR_HACK (V4L2_CID_PRIVATE_BASE + 5)
633 #define V4L2_CID_PRIVATE_WHITECRUSH_UPPER (V4L2_CID_PRIVATE_BASE + 6)
634 #define V4L2_CID_PRIVATE_WHITECRUSH_LOWER (V4L2_CID_PRIVATE_BASE + 7)
635 #define V4L2_CID_PRIVATE_UV_RATIO (V4L2_CID_PRIVATE_BASE + 8)
636 #define V4L2_CID_PRIVATE_FULL_LUMA_RANGE (V4L2_CID_PRIVATE_BASE + 9)
637 #define V4L2_CID_PRIVATE_CORING (V4L2_CID_PRIVATE_BASE + 10)
638 #define V4L2_CID_PRIVATE_LASTP1 (V4L2_CID_PRIVATE_BASE + 11)
648 .name =
"Brightness",
652 .default_value = 32768,
660 .default_value = 27648,
664 .name =
"Saturation",
668 .default_value = 32768,
672 .name =
"Color killer",
682 .default_value = 32768,
698 .default_value = 65535,
706 .default_value = 32768,
714 .default_value = 32768,
722 .default_value = 32768,
728 .name =
"chroma agc",
734 .name =
"combfilter",
746 .name =
"luma decimation filter",
764 .name =
"whitecrush upper",
768 .default_value = 0xCF,
772 .name =
"whitecrush lower",
776 .default_value = 0x7F,
788 .name =
"full luma range",
811 if (bttv_ctls[i].
id ==
id)
848 #define VBI_RESOURCES (RESOURCE_VBI)
849 #define VIDEO_RESOURCES (RESOURCE_VIDEO_READ | \
850 RESOURCE_VIDEO_STREAM | \
854 int check_alloc_btres_lock(
struct bttv *btv,
struct bttv_fh *fh,
int bit)
858 if (fh->resources & bit)
863 if (bit & (RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM))
864 xbits |= RESOURCE_VIDEO_READ | RESOURCE_VIDEO_STREAM;
867 if (btv->resources & xbits) {
873 && 0 == (btv->resources & VIDEO_RESOURCES)) {
875 __s32 top = btv->crop[!!fh->do_crop].rect.top;
877 if (btv->vbi_end > top)
882 btv->crop_start =
top;
886 if (end > btv->crop_start)
894 fh->resources |=
bit;
895 btv->resources |=
bit;
903 int check_btres(
struct bttv_fh *fh,
int bit)
905 return (fh->resources & bit);
909 int locked_btres(
struct bttv *btv,
int bit)
911 return (btv->resources & bit);
916 disclaim_vbi_lines(
struct bttv *btv)
923 disclaim_video_lines(
struct bttv *btv)
925 const struct bttv_tvnorm *
tvnorm;
928 tvnorm = &bttv_tvnorms[btv->tvnorm];
929 btv->crop_start = tvnorm->cropcap.bounds.top
930 + tvnorm->cropcap.bounds.height;
944 void free_btres_lock(
struct bttv *btv,
struct bttv_fh *fh,
int bits)
946 if ((fh->resources & bits) != bits) {
950 fh->resources &= ~bits;
951 btv->resources &= ~bits;
953 bits = btv->resources;
956 disclaim_video_lines(btv);
959 disclaim_vbi_lines(btv);
975 static void set_pll_freq(
struct bttv *btv,
unsigned int fin,
unsigned int fout)
977 unsigned char fl, fh, fi;
997 static void set_pll(
struct bttv *btv)
1001 if (!btv->pll.pll_crystal)
1004 if (btv->pll.pll_ofreq == btv->pll.pll_current) {
1005 dprintk(
"%d: PLL: no change required\n", btv->c.nr);
1009 if (btv->pll.pll_ifreq == btv->pll.pll_ofreq) {
1011 if (btv->pll.pll_current == 0)
1014 pr_info(
"%d: PLL can sleep, using XTAL (%d)\n",
1015 btv->c.nr, btv->pll.pll_ifreq);
1018 btv->pll.pll_current = 0;
1023 pr_info(
"%d: Setting PLL: %d => %d (needs up to 100ms)\n",
1025 btv->pll.pll_ifreq, btv->pll.pll_ofreq);
1026 set_pll_freq(btv, btv->pll.pll_ifreq, btv->pll.pll_ofreq);
1028 for (i=0; i<10; i++) {
1036 btv->pll.pll_current = btv->pll.pll_ofreq;
1042 btv->pll.pll_current = -1;
1044 pr_info(
"Setting PLL failed\n");
1049 static void bt848A_set_timing(
struct bttv *btv)
1052 int table_idx = bttv_tvnorms[btv->tvnorm].sram;
1053 int fsc = bttv_tvnorms[btv->tvnorm].Fsc;
1055 if (btv->input == btv->dig) {
1056 dprintk(
"%d: load digital timing table (table_idx=%d)\n",
1057 btv->c.nr,table_idx);
1064 len=SRAM_Table[table_idx][0];
1065 for(i = 1; i <= len; i++)
1067 btv->pll.pll_ofreq = 27000000;
1073 btv->pll.pll_ofreq = fsc;
1081 static void bt848_bright(
struct bttv *btv,
int bright)
1086 btv->bright = bright;
1089 value = (bright >> 8) - 128;
1093 static void bt848_hue(
struct bttv *btv,
int hue)
1100 value = (hue >> 8) - 128;
1104 static void bt848_contrast(
struct bttv *btv,
int cont)
1108 btv->contrast =
cont;
1111 value = (cont >> 7);
1112 hibit = (value >> 6) & 4;
1118 static void bt848_sat(
struct bttv *btv,
int color)
1120 int val_u,val_v,hibits;
1122 btv->saturation =
color;
1125 val_u = ((color * btv->opt_uv_ratio) / 50) >> 7;
1126 val_v = (((color * (100 - btv->opt_uv_ratio) / 50) >>7)*180L)/254;
1127 hibits = (val_u >> 7) & 2;
1128 hibits |= (val_v >> 8) & 1;
1138 video_mux(
struct bttv *btv,
unsigned int input)
1150 if (input == btv->svhs) {
1157 mux = bttv_muxsel(btv, input);
1159 dprintk(
"%d: video mux: input=%d mux=%d\n", btv->c.nr, input, mux);
1167 static char *audio_modes[] = {
1168 "audio: tuner",
"audio: radio",
"audio: extern",
1169 "audio: intern",
"audio: mute"
1173 audio_mux(
struct bttv *btv,
int input,
int mute)
1175 int gpio_val, signal;
1186 mute = mute || (btv->opt_automute && !signal && !btv->radio_user);
1193 switch (btv->c.type) {
1209 ctrl.value = btv->mute;
1211 if (btv->sd_msp34xx) {
1222 if (btv->radio_uses_msp_demodulator) {
1257 if (btv->sd_tvaudio) {
1265 audio_mute(
struct bttv *btv,
int mute)
1267 return audio_mux(btv, btv->audio, mute);
1271 audio_input(
struct bttv *btv,
int input)
1273 return audio_mux(btv, input, btv->mute);
1277 bttv_crop_calc_limits(
struct bttv_crop *
c)
1285 c->min_scaled_width = 48;
1286 c->min_scaled_height = 32;
1288 c->min_scaled_width =
1289 (
max(48, c->rect.width >> 4) + 3) & ~3;
1290 c->min_scaled_height =
1291 max(32, c->rect.height >> 4);
1294 c->max_scaled_width = c->rect.width & ~3;
1295 c->max_scaled_height = c->rect.height;
1299 bttv_crop_reset(
struct bttv_crop *c,
unsigned int norm)
1301 c->rect = bttv_tvnorms[norm].cropcap.defrect;
1302 bttv_crop_calc_limits(c);
1307 set_tvnorm(
struct bttv *btv,
unsigned int norm)
1309 const struct bttv_tvnorm *
tvnorm;
1312 BUG_ON(norm >= BTTV_TVNORMS);
1313 BUG_ON(btv->tvnorm >= BTTV_TVNORMS);
1315 tvnorm = &bttv_tvnorms[norm];
1317 if (
memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap,
1318 sizeof (tvnorm->cropcap))) {
1319 bttv_crop_reset(&btv->crop[0], norm);
1320 btv->crop[1] = btv->crop[0];
1322 if (0 == (btv->resources & VIDEO_RESOURCES)) {
1323 btv->crop_start = tvnorm->cropcap.bounds.top
1324 + tvnorm->cropcap.bounds.height;
1336 bt848A_set_timing(btv);
1338 switch (btv->c.type) {
1344 id = tvnorm->v4l2_id;
1352 set_input(
struct bttv *btv,
unsigned int input,
unsigned int norm)
1354 unsigned long flags;
1359 if (btv->curr.frame_irq) {
1361 btv->new_input =
input;
1363 video_mux(btv,input);
1365 spin_unlock_irqrestore(&btv->s_lock,flags);
1367 video_mux(btv,input);
1369 audio_input(btv, (btv->tuner_type != TUNER_ABSENT && input == 0) ?
1371 set_tvnorm(btv, norm);
1374 static void init_irqreg(
struct bttv *btv)
1396 static void init_bt848(
struct bttv *btv)
1431 if (btv->opt_lumafilter) {
1439 bt848_bright(btv, btv->bright);
1440 bt848_hue(btv, btv->hue);
1441 bt848_contrast(btv, btv->contrast);
1442 bt848_sat(btv, btv->saturation);
1448 static void bttv_reinit_bt848(
struct bttv *btv)
1450 unsigned long flags;
1453 pr_info(
"%d: reset, reinitialize\n", btv->c.nr);
1457 spin_unlock_irqrestore(&btv->s_lock,flags);
1460 btv->pll.pll_current = -1;
1461 set_input(btv, btv->input, btv->tvnorm);
1467 struct bttv_fh *fh =
priv;
1468 struct bttv *btv = fh->btv;
1472 c->
value = btv->bright;
1475 c->
value = btv->hue;
1478 c->
value = btv->contrast;
1481 c->
value = btv->saturation;
1484 c->
value = btv->opt_color_killer;
1496 c->
value = btv->opt_chroma_agc;
1499 c->
value = btv->opt_combfilter;
1502 c->
value = btv->opt_lumafilter;
1505 c->
value = btv->opt_automute;
1508 c->
value = btv->opt_adc_crush;
1511 c->
value = btv->opt_vcr_hack;
1514 c->
value = btv->opt_whitecrush_upper;
1517 c->
value = btv->opt_whitecrush_lower;
1520 c->
value = btv->opt_uv_ratio;
1523 c->
value = btv->opt_full_luma_range;
1526 c->
value = btv->opt_coring;
1534 static int bttv_s_ctrl(
struct file *file,
void *
f,
1538 struct bttv_fh *fh =
f;
1539 struct bttv *btv = fh->btv;
1547 bt848_bright(btv, c->
value);
1550 bt848_hue(btv, c->
value);
1553 bt848_contrast(btv, c->
value);
1556 bt848_sat(btv, c->
value);
1559 btv->opt_color_killer = c->
value;
1560 if (btv->opt_color_killer) {
1569 audio_mute(btv, c->
value);
1572 if (btv->volume_gpio)
1573 btv->volume_gpio(btv, c->
value);
1584 btv->opt_chroma_agc = c->
value;
1585 if (btv->opt_chroma_agc) {
1594 btv->opt_combfilter = c->
value;
1597 btv->opt_lumafilter = c->
value;
1598 if (btv->opt_lumafilter) {
1607 btv->opt_automute = c->
value;
1610 btv->opt_adc_crush = c->
value;
1616 btv->opt_vcr_hack = c->
value;
1619 btv->opt_whitecrush_upper = c->
value;
1623 btv->opt_whitecrush_lower = c->
value;
1627 btv->opt_uv_ratio = c->
value;
1628 bt848_sat(btv, btv->saturation);
1631 btv->opt_full_luma_range = c->
value;
1635 btv->opt_coring = c->
value;
1648 unsigned int outbits,
data;
1651 pr_debug(
"%d: gpio: en=%08x, out=%08x in=%08x [%s]\n",
1652 btv->c.nr, outbits, data & outbits, data & ~outbits, comment);
1655 static void bttv_field_count(
struct bttv *btv)
1668 btv->field_count = 0;
1672 static const struct bttv_format*
1677 for (i = 0; i <
FORMATS; i++) {
1678 if (-1 == formats[i].fourcc)
1680 if (formats[i].fourcc == fourcc)
1690 bttv_switch_overlay(
struct bttv *btv,
struct bttv_fh *fh,
1691 struct bttv_buffer *
new)
1693 struct bttv_buffer *old;
1694 unsigned long flags;
1697 dprintk(
"switch_overlay: enter [new=%p]\n",
new);
1705 spin_unlock_irqrestore(&btv->s_lock,flags);
1707 dprintk(
"switch_overlay: old=%p state is %d\n",
1708 old, old->vb.state);
1714 dprintk(
"switch_overlay: done\n");
1721 static int bttv_prepare_buffer(
struct videobuf_queue *
q,
struct bttv *btv,
1722 struct bttv_buffer *buf,
1723 const struct bttv_format *
fmt,
1728 int redo_dma_risc = 0;
1738 height = RAW_LINES*2;
1739 if (width*height > buf->vb.bsize)
1741 buf->vb.size = buf->vb.bsize;
1750 if (btv->vbi_end > bttv_tvnorms[norm].cropcap.defrect.top) {
1754 c.rect = bttv_tvnorms[norm].cropcap.defrect;
1757 c = btv->crop[!!fh->do_crop];
1759 if (width < c.min_scaled_width ||
1760 width > c.max_scaled_width ||
1761 height < c.min_scaled_height)
1770 if (height * 2 > c.max_scaled_height)
1775 if (height > c.max_scaled_height)
1780 buf->vb.size = (width * height * fmt->depth) >> 3;
1781 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
1786 if (buf->vb.width != width || buf->vb.height != height ||
1787 buf->vb.field != field ||
1788 buf->tvnorm != norm || buf->fmt != fmt ||
1789 buf->crop.top != c.rect.top ||
1790 buf->crop.left != c.rect.left ||
1791 buf->crop.width != c.rect.width ||
1792 buf->crop.height != c.rect.height) {
1793 buf->vb.width =
width;
1795 buf->vb.field =
field;
1826 *size = fh->fmt->depth*fh->width*fh->height >> 3;
1829 if (*size * *count > gbuffers * gbufsize)
1830 *count = (gbuffers * gbufsize) / *size;
1838 struct bttv_buffer *buf =
container_of(vb,
struct bttv_buffer,vb);
1841 return bttv_prepare_buffer(q,fh->btv, buf, fh->fmt,
1842 fh->width, fh->height, field);
1848 struct bttv_buffer *buf =
container_of(vb,
struct bttv_buffer,vb);
1850 struct bttv *btv = fh->btv;
1854 if (!btv->curr.frame_irq) {
1862 struct bttv_buffer *buf =
container_of(vb,
struct bttv_buffer,vb);
1869 .buf_setup = buffer_setup,
1870 .buf_prepare = buffer_prepare,
1871 .buf_queue = buffer_queue,
1872 .buf_release = buffer_release,
1875 static int bttv_s_std(
struct file *file,
void *priv,
v4l2_std_id *
id)
1877 struct bttv_fh *fh =
priv;
1878 struct bttv *btv = fh->btv;
1886 for (i = 0; i < BTTV_TVNORMS; i++)
1887 if (*
id & bttv_tvnorms[i].v4l2_id)
1889 if (i == BTTV_TVNORMS) {
1901 static int bttv_querystd(
struct file *file,
void *f,
v4l2_std_id *
id)
1903 struct bttv_fh *fh =
f;
1904 struct bttv *btv = fh->btv;
1913 static int bttv_enum_input(
struct file *file,
void *priv,
1916 struct bttv_fh *fh =
priv;
1917 struct bttv *btv = fh->btv;
1928 if (btv->tuner_type != TUNER_ABSENT && i->
index == 0) {
1932 }
else if (i->
index == btv->svhs) {
1938 if (i->
index == btv->input) {
1946 i->
std = BTTV_NORMS;
1953 static int bttv_g_input(
struct file *file,
void *priv,
unsigned int *i)
1955 struct bttv_fh *fh =
priv;
1956 struct bttv *btv = fh->btv;
1963 static int bttv_s_input(
struct file *file,
void *priv,
unsigned int i)
1965 struct bttv_fh *fh =
priv;
1966 struct bttv *btv = fh->btv;
1979 set_input(btv, i, btv->tvnorm);
1985 static int bttv_s_tuner(
struct file *file,
void *priv,
1988 struct bttv_fh *fh =
priv;
1989 struct bttv *btv = fh->btv;
1995 if (
unlikely(btv->tuner_type == TUNER_ABSENT)) {
2006 if (btv->audio_mode_gpio)
2007 btv->audio_mode_gpio(btv, t, 1);
2014 static int bttv_g_frequency(
struct file *file,
void *priv,
2017 struct bttv_fh *fh =
priv;
2018 struct bttv *btv = fh->btv;
2026 static int bttv_s_frequency(
struct file *file,
void *priv,
2029 struct bttv_fh *fh =
priv;
2030 struct bttv *btv = fh->btv;
2047 if (btv->has_matchbox && btv->radio_user)
2054 static int bttv_log_status(
struct file *file,
void *f)
2056 struct bttv_fh *fh =
f;
2057 struct bttv *btv = fh->btv;
2063 #ifdef CONFIG_VIDEO_ADV_DEBUG
2064 static int bttv_g_register(
struct file *file,
void *f,
2067 struct bttv_fh *fh =
f;
2068 struct bttv *btv = fh->btv;
2084 static int bttv_s_register(
struct file *file,
void *f,
2087 struct bttv_fh *fh =
f;
2088 struct bttv *btv = fh->btv;
2108 bttv_crop_adjust (
struct bttv_crop * c,
2118 if (width < c->min_scaled_width) {
2120 c->rect.width = width * 16;
2121 }
else if (width > c->max_scaled_width) {
2123 c->rect.width =
width;
2126 max_left =
min(max_left, (
__s32) MAX_HDELAY);
2127 if (c->rect.left > max_left)
2128 c->rect.left = max_left;
2131 if (height < c->min_scaled_height) {
2133 c->rect.height = height * 16;
2134 }
else if (frame_height > c->max_scaled_height) {
2137 c->rect.height = (frame_height + 1) & ~1;
2139 max_top = b->
top + b->
height - c->rect.height;
2140 if (c->rect.top > max_top)
2141 c->rect.top = max_top;
2144 bttv_crop_calc_limits(c);
2155 limit_scaled_size_lock (
struct bttv_fh * fh,
2159 unsigned int width_mask,
2160 unsigned int width_bias,
2164 struct bttv *btv = fh->btv;
2166 struct bttv_crop *
c;
2173 BUG_ON((
int) width_mask >= 0 ||
2174 width_bias >= (
unsigned int) -width_mask);
2179 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
2182 c = &btv->crop[!!fh->do_crop];
2187 && !locked_btres(btv, VIDEO_RESOURCES)) {
2200 if (btv->vbi_end > b->
top) {
2201 max_height -= btv->vbi_end - b->
top;
2203 if (min_height > max_height)
2208 if (btv->vbi_end > c->rect.top)
2211 min_width = c->min_scaled_width;
2212 min_height = c->min_scaled_height;
2213 max_width = c->max_scaled_width;
2214 max_height = c->max_scaled_height;
2219 min_width = (min_width - width_mask - 1) & width_mask;
2220 max_width = max_width & width_mask;
2228 *width =
clamp(*width, min_width, max_width);
2229 *height =
clamp(*height, min_height, max_height);
2232 *width = (*width + width_bias) & width_mask;
2235 bttv_crop_adjust(c, b, *width, *height, field);
2237 if (btv->vbi_end > c->rect.top) {
2239 c->rect.top = btv->vbi_end;
2244 if (*width < min_width ||
2245 *height < min_height ||
2246 *width > max_width ||
2247 *height > max_height ||
2248 0 != (*width & ~width_mask))
2267 verify_window_lock (
struct bttv_fh * fh,
2273 unsigned int width_mask;
2276 if (win->
w.width < 48 || win->
w.height < 32)
2286 height2 = fh->btv->crop[!!fh->do_crop].rect.height >> 1;
2287 field = (win->
w.height > height2)
2301 if (
NULL == fh->ovfmt)
2304 switch (fh->ovfmt->depth) {
2318 win->
w.width -= win->
w.left & ~width_mask;
2319 win->
w.left = (win->
w.left - width_mask - 1) & width_mask;
2321 rc = limit_scaled_size_lock(fh, &win->
w.width, &win->
w.height,
2324 adjust_size, adjust_crop);
2332 static int setup_window_lock(
struct bttv_fh *fh,
struct bttv *btv,
2336 int n,
size,retval = 0;
2338 if (
NULL == fh->ovfmt)
2342 retval = verify_window_lock(fh, win,
2351 size =
sizeof(*clips)*(n+4);
2363 if (
NULL != btv->fbuf.base)
2369 switch (fh->ovfmt->depth) {
2384 kfree(fh->ov.clips);
2385 fh->ov.clips = clips;
2389 fh->ov.field = win->
field;
2390 fh->ov.setup_ok = 1;
2392 btv->init.ov.w.width = win->
w.width;
2393 btv->init.ov.w.height = win->
w.height;
2394 btv->init.ov.field = win->
field;
2399 struct bttv_buffer *
new;
2402 new->crop = btv->crop[!!fh->do_crop].rect;
2404 retval = bttv_switch_overlay(btv,fh,
new);
2428 static int bttv_resource(
struct bttv_fh *fh)
2434 res = RESOURCE_VIDEO_STREAM;
2448 int res = bttv_resource(fh);
2450 if (check_btres(fh,res))
2460 const struct bttv_format * fmt,
2462 unsigned int height)
2469 f->
sizeimage = (width * height * fmt->depth) >> 3;
2476 static int bttv_g_fmt_vid_cap(
struct file *file,
void *priv,
2479 struct bttv_fh *fh =
priv;
2481 pix_format_set_size(&f->
fmt.
pix, fh->fmt,
2482 fh->width, fh->height);
2483 f->
fmt.
pix.field = fh->cap.field;
2484 f->
fmt.
pix.pixelformat = fh->fmt->fourcc;
2489 static int bttv_g_fmt_vid_overlay(
struct file *file,
void *priv,
2492 struct bttv_fh *fh =
priv;
2495 f->
fmt.
win.field = fh->ov.field;
2500 static int bttv_try_fmt_vid_cap(
struct file *file,
void *priv,
2503 const struct bttv_format *
fmt;
2504 struct bttv_fh *fh =
priv;
2505 struct bttv *btv = fh->btv;
2514 field = f->
fmt.
pix.field;
2519 height2 = btv->crop[!!fh->do_crop].rect.height >> 1;
2520 field = (f->
fmt.
pix.height > height2)
2542 width = f->
fmt.
pix.width;
2543 height = f->
fmt.
pix.height;
2545 rc = limit_scaled_size_lock(fh, &width, &height, field,
2555 pix_format_set_size(&f->
fmt.
pix, fmt, width, height);
2560 static int bttv_try_fmt_vid_overlay(
struct file *file,
void *priv,
2563 struct bttv_fh *fh =
priv;
2565 return verify_window_lock(fh, &f->
fmt.
win,
2570 static int bttv_s_fmt_vid_cap(
struct file *file,
void *priv,
2574 const struct bttv_format *
fmt;
2575 struct bttv_fh *fh =
priv;
2576 struct bttv *btv = fh->btv;
2580 retval = bttv_switch_type(fh, f->
type);
2584 retval = bttv_try_fmt_vid_cap(file, priv, f);
2588 width = f->
fmt.
pix.width;
2589 height = f->
fmt.
pix.height;
2590 field = f->
fmt.
pix.field;
2592 retval = limit_scaled_size_lock(fh, &width, &height, f->
fmt.
pix.field,
2606 fh->cap.field = f->
fmt.
pix.field;
2608 fh->width = f->
fmt.
pix.width;
2609 fh->height = f->
fmt.
pix.height;
2610 btv->init.fmt =
fmt;
2611 btv->init.width = f->
fmt.
pix.width;
2612 btv->init.height = f->
fmt.
pix.height;
2617 static int bttv_s_fmt_vid_overlay(
struct file *file,
void *priv,
2620 struct bttv_fh *fh =
priv;
2621 struct bttv *btv = fh->btv;
2624 pr_err(
"V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
2628 return setup_window_lock(fh, btv, &f->
fmt.
win, 1);
2631 static int bttv_querycap(
struct file *file,
void *priv,
2634 struct bttv_fh *fh =
priv;
2635 struct bttv *btv = fh->btv;
2643 "PCI:%s", pci_name(btv->c.pci));
2656 if (btv->has_saa6588)
2658 if (btv->tuner_type != TUNER_ABSENT)
2663 static int bttv_enum_fmt_cap_ovr(
struct v4l2_fmtdesc *f)
2667 for (i = 0; i <
FORMATS; i++) {
2668 if (formats[i].fourcc != -1)
2670 if ((
unsigned int)index == f->
index)
2682 static int bttv_enum_fmt_vid_cap(
struct file *file,
void *priv,
2685 int rc = bttv_enum_fmt_cap_ovr(f);
2693 static int bttv_enum_fmt_vid_overlay(
struct file *file,
void *priv,
2699 pr_err(
"V4L2_BUF_TYPE_VIDEO_OVERLAY: no_overlay\n");
2703 rc = bttv_enum_fmt_cap_ovr(f);
2714 static int bttv_g_fbuf(
struct file *file,
void *f,
2717 struct bttv_fh *fh =
f;
2718 struct bttv *btv = fh->btv;
2723 fb->
fmt.pixelformat = fh->ovfmt->fourcc;
2727 static int bttv_overlay(
struct file *file,
void *f,
unsigned int on)
2729 struct bttv_fh *fh =
f;
2730 struct bttv *btv = fh->btv;
2731 struct bttv_buffer *
new;
2740 dprintk(
"%d: overlay: !setup_ok\n", btv->c.nr);
2751 fh->ov.tvnorm = btv->tvnorm;
2753 new->crop = btv->crop[!!fh->do_crop].rect;
2760 retval = bttv_switch_overlay(btv, fh,
new);
2764 static int bttv_s_fbuf(
struct file *file,
void *f,
2767 struct bttv_fh *fh =
f;
2768 struct bttv *btv = fh->btv;
2769 const struct bttv_format *
fmt;
2788 retval = limit_scaled_size_lock(fh, &width, &height,
2799 btv->fbuf.base = fb->
base;
2800 btv->fbuf.fmt.width = fb->
fmt.width;
2801 btv->fbuf.fmt.height = fb->
fmt.height;
2802 if (0 != fb->
fmt.bytesperline)
2803 btv->fbuf.fmt.bytesperline = fb->
fmt.bytesperline;
2805 btv->fbuf.fmt.bytesperline = btv->fbuf.fmt.width*fmt->depth/8;
2809 btv->init.ovfmt =
fmt;
2813 fh->ov.w.width = fb->
fmt.width;
2814 fh->ov.w.height = fb->
fmt.height;
2815 btv->init.ov.w.width = fb->
fmt.width;
2816 btv->init.ov.w.height = fb->
fmt.height;
2817 kfree(fh->ov.clips);
2818 fh->ov.clips =
NULL;
2822 struct bttv_buffer *
new;
2825 new->crop = btv->crop[!!fh->do_crop].rect;
2827 retval = bttv_switch_overlay(btv, fh,
new);
2833 static int bttv_reqbufs(
struct file *file,
void *priv,
2836 struct bttv_fh *fh =
priv;
2840 static int bttv_querybuf(
struct file *file,
void *priv,
2843 struct bttv_fh *fh =
priv;
2847 static int bttv_qbuf(
struct file *file,
void *priv,
struct v4l2_buffer *b)
2849 struct bttv_fh *fh =
priv;
2850 struct bttv *btv = fh->btv;
2851 int res = bttv_resource(fh);
2853 if (!check_alloc_btres_lock(btv, fh, res))
2859 static int bttv_dqbuf(
struct file *file,
void *priv,
struct v4l2_buffer *b)
2861 struct bttv_fh *fh =
priv;
2866 static int bttv_streamon(
struct file *file,
void *priv,
2869 struct bttv_fh *fh =
priv;
2870 struct bttv *btv = fh->btv;
2871 int res = bttv_resource(fh);
2873 if (!check_alloc_btres_lock(btv, fh, res))
2879 static int bttv_streamoff(
struct file *file,
void *priv,
2882 struct bttv_fh *fh =
priv;
2883 struct bttv *btv = fh->btv;
2885 int res = bttv_resource(fh);
2891 free_btres_lock(btv, fh, res);
2895 static int bttv_queryctrl(
struct file *file,
void *priv,
2898 struct bttv_fh *fh =
priv;
2899 struct bttv *btv = fh->btv;
2911 ctrl = ctrl_by_id(c->
id);
2913 *c = (
NULL !=
ctrl) ? *ctrl : no_ctl;
2919 static int bttv_g_parm(
struct file *file,
void *f,
2922 struct bttv_fh *fh =
f;
2923 struct bttv *btv = fh->btv;
2931 static int bttv_g_tuner(
struct file *file,
void *priv,
2934 struct bttv_fh *fh =
priv;
2935 struct bttv *btv = fh->btv;
2937 if (btv->tuner_type == TUNER_ABSENT)
2950 if (btv->audio_mode_gpio)
2951 btv->audio_mode_gpio(btv, t, 0);
2956 static int bttv_g_priority(
struct file *file,
void *f,
enum v4l2_priority *p)
2958 struct bttv_fh *fh =
f;
2959 struct bttv *btv = fh->btv;
2966 static int bttv_s_priority(
struct file *file,
void *f,
2969 struct bttv_fh *fh =
f;
2970 struct bttv *btv = fh->btv;
2978 static int bttv_cropcap(
struct file *file,
void *priv,
2981 struct bttv_fh *fh =
priv;
2982 struct bttv *btv = fh->btv;
2988 *cap = bttv_tvnorms[btv->tvnorm].cropcap;
2993 static int bttv_g_crop(
struct file *file,
void *f,
struct v4l2_crop *crop)
2995 struct bttv_fh *fh =
f;
2996 struct bttv *btv = fh->btv;
3006 crop->
c = btv->crop[!!fh->do_crop].rect;
3011 static int bttv_s_crop(
struct file *file,
void *f,
const struct v4l2_crop *crop)
3013 struct bttv_fh *fh =
f;
3014 struct bttv *btv = fh->btv;
3037 if (locked_btres(fh->btv, VIDEO_RESOURCES)) {
3041 b = &bttv_tvnorms[btv->tvnorm].cropcap.bounds;
3044 b_right = b_left + b->
width;
3047 b_top =
max(b->
top, btv->vbi_end);
3048 if (b_top + 32 >= b_bottom) {
3053 c.rect.left =
clamp_t(
s32, crop->
c.left, b_left, b_right - 48);
3054 c.rect.left =
min(c.rect.left, (
__s32) MAX_HDELAY);
3057 48, b_right - c.rect.left);
3059 c.rect.top =
clamp_t(
s32, crop->
c.top, b_top, b_bottom - 32);
3061 c.rect.top = (c.rect.top + 1) & ~1;
3064 32, b_bottom - c.rect.top);
3065 c.rect.height = (c.rect.height + 1) & ~1;
3067 bttv_crop_calc_limits(&c);
3073 if (fh->width < c.min_scaled_width) {
3074 fh->width = c.min_scaled_width;
3075 btv->init.width = c.min_scaled_width;
3076 }
else if (fh->width > c.max_scaled_width) {
3077 fh->width = c.max_scaled_width;
3078 btv->init.width = c.max_scaled_width;
3081 if (fh->height < c.min_scaled_height) {
3082 fh->height = c.min_scaled_height;
3083 btv->init.height = c.min_scaled_height;
3084 }
else if (fh->height > c.max_scaled_height) {
3085 fh->height = c.max_scaled_height;
3086 btv->init.height = c.max_scaled_height;
3092 static int bttv_g_audio(
struct file *file,
void *priv,
struct v4l2_audio *
a)
3101 static int bttv_s_audio(
struct file *file,
void *priv,
const struct v4l2_audio *a)
3109 static ssize_t bttv_read(
struct file *file,
char __user *
data,
3110 size_t count, loff_t *ppos)
3115 if (fh->btv->errors)
3116 bttv_reinit_bt848(fh->btv);
3117 dprintk(
"%d: read count=%d type=%s\n",
3122 if (!check_alloc_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ)) {
3129 free_btres_lock(fh->btv, fh, RESOURCE_VIDEO_READ);
3143 static unsigned int bttv_poll(
struct file *file,
poll_table *
wait)
3146 struct bttv_buffer *
buf;
3156 if (check_btres(fh,RESOURCE_VIDEO_STREAM)) {
3158 if (list_empty(&fh->cap.stream))
3163 if (
NULL == fh->cap.read_buf) {
3165 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM))
3168 if (
NULL == fh->cap.read_buf)
3172 if (0 != fh->cap.ops->buf_prepare(&fh->cap,fh->cap.read_buf,field)) {
3173 kfree (fh->cap.read_buf);
3174 fh->cap.read_buf =
NULL;
3177 fh->cap.ops->buf_queue(&fh->cap,fh->cap.read_buf);
3178 fh->cap.read_off = 0;
3180 buf = (
struct bttv_buffer*)fh->cap.read_buf;
3183 poll_wait(file, &buf->vb.done, wait);
3193 static int bttv_open(
struct file *file)
3196 struct bttv *btv = video_drvdata(file);
3200 dprintk(
"open dev=%s\n", video_device_node_name(vdev));
3211 dprintk(
"%d: open called (type=%s)\n",
3223 fh->ov.setup_ok = 0;
3228 &btv->c.pci->dev, &btv->s_lock,
3231 sizeof(
struct bttv_buffer),
3234 &btv->c.pci->dev, &btv->s_lock,
3237 sizeof(
struct bttv_buffer),
3239 set_tvnorm(btv,btv->tvnorm);
3240 set_input(btv, btv->input, btv->tvnorm);
3253 fh->do_crop = !reset_crop;
3260 bttv_field_count(btv);
3264 static int bttv_release(
struct file *file)
3267 struct bttv *btv = fh->btv;
3271 bttv_switch_overlay(btv,fh,
NULL);
3274 if (check_btres(fh, RESOURCE_VIDEO_STREAM)) {
3276 free_btres_lock(btv,fh,RESOURCE_VIDEO_STREAM);
3278 if (fh->cap.read_buf) {
3279 buffer_release(&fh->cap,fh->cap.read_buf);
3280 kfree(fh->cap.read_buf);
3282 if (check_btres(fh, RESOURCE_VIDEO_READ)) {
3283 free_btres_lock(btv, fh, RESOURCE_VIDEO_READ);
3301 bttv_field_count(btv);
3314 dprintk(
"%d: mmap type=%s 0x%lx+%ld\n",
3324 .release = bttv_release,
3332 .vidioc_querycap = bttv_querycap,
3333 .vidioc_enum_fmt_vid_cap = bttv_enum_fmt_vid_cap,
3334 .vidioc_g_fmt_vid_cap = bttv_g_fmt_vid_cap,
3335 .vidioc_try_fmt_vid_cap = bttv_try_fmt_vid_cap,
3336 .vidioc_s_fmt_vid_cap = bttv_s_fmt_vid_cap,
3337 .vidioc_enum_fmt_vid_overlay = bttv_enum_fmt_vid_overlay,
3338 .vidioc_g_fmt_vid_overlay = bttv_g_fmt_vid_overlay,
3339 .vidioc_try_fmt_vid_overlay = bttv_try_fmt_vid_overlay,
3340 .vidioc_s_fmt_vid_overlay = bttv_s_fmt_vid_overlay,
3344 .vidioc_g_audio = bttv_g_audio,
3345 .vidioc_s_audio = bttv_s_audio,
3346 .vidioc_cropcap = bttv_cropcap,
3347 .vidioc_reqbufs = bttv_reqbufs,
3348 .vidioc_querybuf = bttv_querybuf,
3349 .vidioc_qbuf = bttv_qbuf,
3350 .vidioc_dqbuf = bttv_dqbuf,
3351 .vidioc_s_std = bttv_s_std,
3352 .vidioc_enum_input = bttv_enum_input,
3353 .vidioc_g_input = bttv_g_input,
3354 .vidioc_s_input = bttv_s_input,
3355 .vidioc_queryctrl = bttv_queryctrl,
3356 .vidioc_g_ctrl = bttv_g_ctrl,
3357 .vidioc_s_ctrl = bttv_s_ctrl,
3358 .vidioc_streamon = bttv_streamon,
3359 .vidioc_streamoff = bttv_streamoff,
3360 .vidioc_g_tuner = bttv_g_tuner,
3361 .vidioc_s_tuner = bttv_s_tuner,
3362 .vidioc_g_crop = bttv_g_crop,
3363 .vidioc_s_crop = bttv_s_crop,
3364 .vidioc_g_fbuf = bttv_g_fbuf,
3365 .vidioc_s_fbuf = bttv_s_fbuf,
3366 .vidioc_overlay = bttv_overlay,
3367 .vidioc_g_priority = bttv_g_priority,
3368 .vidioc_s_priority = bttv_s_priority,
3369 .vidioc_g_parm = bttv_g_parm,
3370 .vidioc_g_frequency = bttv_g_frequency,
3371 .vidioc_s_frequency = bttv_s_frequency,
3372 .vidioc_log_status = bttv_log_status,
3373 .vidioc_querystd = bttv_querystd,
3374 #ifdef CONFIG_VIDEO_ADV_DEBUG
3375 .vidioc_g_register = bttv_g_register,
3376 .vidioc_s_register = bttv_s_register,
3382 .ioctl_ops = &bttv_ioctl_ops,
3383 .tvnorms = BTTV_NORMS,
3390 static int radio_open(
struct file *file)
3393 struct bttv *btv = video_drvdata(file);
3396 dprintk(
"open dev=%s\n", video_device_node_name(vdev));
3398 dprintk(
"%d: open called (radio)\n", btv->c.nr);
3417 static int radio_release(
struct file *file)
3420 struct bttv *btv = fh->btv;
3434 static int radio_querycap(
struct file *file,
void *priv,
3437 struct bttv_fh *fh =
priv;
3438 struct bttv *btv = fh->btv;
3448 static int radio_g_tuner(
struct file *file,
void *priv,
struct v4l2_tuner *t)
3450 struct bttv_fh *fh =
priv;
3451 struct bttv *btv = fh->btv;
3453 if (btv->tuner_type == TUNER_ABSENT)
3462 if (btv->audio_mode_gpio)
3463 btv->audio_mode_gpio(btv, t, 0);
3468 static int radio_enum_input(
struct file *file,
void *priv,
3480 static int radio_g_audio(
struct file *file,
void *priv,
3491 static int radio_s_tuner(
struct file *file,
void *priv,
3494 struct bttv_fh *fh =
priv;
3495 struct bttv *btv = fh->btv;
3504 static int radio_s_audio(
struct file *file,
void *priv,
3513 static int radio_s_input(
struct file *filp,
void *priv,
unsigned int i)
3521 static int radio_s_std(
struct file *file,
void *fh,
v4l2_std_id *norm)
3526 static int radio_queryctrl(
struct file *file,
void *priv,
3536 ctrl = ctrl_by_id(c->
id);
3544 static int radio_g_input(
struct file *filp,
void *priv,
unsigned int *i)
3550 static ssize_t radio_read(
struct file *file,
char __user *data,
3551 size_t count, loff_t *ppos)
3554 struct bttv *btv = fh->btv;
3556 cmd.block_count = count/3;
3566 static unsigned int radio_poll(
struct file *file,
poll_table *wait)
3569 struct bttv *btv = fh->btv;
3584 .release = radio_release,
3590 .vidioc_querycap = radio_querycap,
3591 .vidioc_g_tuner = radio_g_tuner,
3592 .vidioc_enum_input = radio_enum_input,
3593 .vidioc_g_audio = radio_g_audio,
3594 .vidioc_s_tuner = radio_s_tuner,
3595 .vidioc_s_audio = radio_s_audio,
3596 .vidioc_s_input = radio_s_input,
3597 .vidioc_s_std = radio_s_std,
3598 .vidioc_queryctrl = radio_queryctrl,
3599 .vidioc_g_input = radio_g_input,
3600 .vidioc_g_ctrl = bttv_g_ctrl,
3601 .vidioc_s_ctrl = bttv_s_ctrl,
3602 .vidioc_g_frequency = bttv_g_frequency,
3603 .vidioc_s_frequency = bttv_s_frequency,
3607 .fops = &radio_fops,
3608 .ioctl_ops = &radio_ioctl_ops,
3614 static int bttv_risc_decode(
u32 risc)
3616 static char *
instr[16] = {
3626 static int incr[16] = {
3634 static char *bits[] = {
3635 "be0",
"be1",
"be2",
"be3/resync",
3636 "set0",
"set1",
"set2",
"set3",
3637 "clr0",
"clr1",
"clr2",
"clr3",
3638 "irq",
"res",
"eol",
"sol",
3643 instr[risc >> 28] ? instr[risc >> 28] :
"INVALID");
3645 if (risc & (1 << (i + 12)))
3647 pr_cont(
" count=%d ]\n", risc & 0xfff);
3648 return incr[risc >> 28] ? incr[risc >> 28] : 1;
3651 static void bttv_risc_disasm(
struct bttv *btv,
3656 pr_info(
"%s: risc disasm: %p [dma=0x%08lx]\n",
3657 btv->c.v4l2_dev.name, risc->
cpu, (
unsigned long)risc->
dma);
3658 for (i = 0; i < (risc->
size >> 2); i +=
n) {
3660 btv->c.v4l2_dev.name,
3661 (
unsigned long)(risc->
dma + (i<<2)));
3663 for (j = 1; j <
n; j++)
3664 pr_info(
"%s: 0x%lx: 0x%08x [ arg #%d ]\n",
3665 btv->c.v4l2_dev.name,
3666 (
unsigned long)(risc->
dma + ((i+j)<<2)),
3668 if (0 == risc->
cpu[i])
3673 static void bttv_print_riscaddr(
struct bttv *btv)
3675 pr_info(
" main: %08llx\n", (
unsigned long long)btv->main.dma);
3676 pr_info(
" vbi : o=%08llx e=%08llx\n",
3677 btv->cvbi ? (
unsigned long long)btv->cvbi->top.dma : 0,
3678 btv->cvbi ? (
unsigned long long)btv->cvbi->bottom.dma : 0);
3679 pr_info(
" cap : o=%08llx e=%08llx\n",
3681 ? (
unsigned long long)btv->curr.top->top.dma : 0,
3683 ? (
unsigned long long)btv->curr.bottom->bottom.dma : 0);
3684 pr_info(
" scr : o=%08llx e=%08llx\n",
3685 btv->screen ? (
unsigned long long)btv->screen->top.dma : 0,
3686 btv->screen ? (
unsigned long long)btv->screen->bottom.dma : 0);
3687 bttv_risc_disasm(btv, &btv->main);
3693 static char *irq_name[] = {
3715 static void bttv_print_irqbits(
u32 print,
u32 mark)
3721 if (print & (1 << i))
3723 if (mark & (1 << i))
3728 static void bttv_irq_debug_low_latency(
struct bttv *btv,
u32 rc)
3730 pr_warn(
"%d: irq: skipped frame [main=%lx,o_vbi=%lx,o_field=%lx,rc=%lx]\n",
3732 (
unsigned long)btv->main.dma,
3733 (
unsigned long)
le32_to_cpu(btv->main.cpu[RISC_SLOT_O_VBI+1]),
3734 (
unsigned long)
le32_to_cpu(btv->main.cpu[RISC_SLOT_O_FIELD+1]),
3738 pr_notice(
"%d: Oh, there (temporarily?) is no input signal. "
3739 "Ok, then this is harmless, don't worry ;)\n",
3743 pr_notice(
"%d: Uhm. Looks like we have unusual high IRQ latencies\n",
3745 pr_notice(
"%d: Lets try to catch the culpit red-handed ...\n",
3751 bttv_irq_next_video(
struct bttv *btv,
struct bttv_buffer_set *
set)
3753 struct bttv_buffer *
item;
3755 memset(
set,0,
sizeof(*
set));
3758 if (!list_empty(&btv->capture)) {
3768 (item->vb.queue.next != &btv->capture)) {
3809 if (
NULL != btv->screen) {
3812 set->top = btv->screen;
3813 set->bottom = btv->screen;
3818 set->top = btv->screen;
3822 set->bottom = btv->screen;
3827 dprintk(
"%d: next set: top=%p bottom=%p [screen=%p,irq=%d,%d]\n",
3828 btv->c.nr,
set->top,
set->bottom,
3829 btv->screen,
set->frame_irq,
set->top_irq);
3834 bttv_irq_wakeup_video(
struct bttv *btv,
struct bttv_buffer_set *wakeup,
3835 struct bttv_buffer_set *
curr,
unsigned int state)
3841 if (wakeup->top == wakeup->bottom) {
3842 if (
NULL != wakeup->top && curr->top != wakeup->top) {
3845 btv->c.nr, wakeup->top);
3846 wakeup->top->vb.ts =
ts;
3847 wakeup->top->vb.field_count = btv->field_count;
3848 wakeup->top->vb.state =
state;
3849 wake_up(&wakeup->top->vb.done);
3852 if (
NULL != wakeup->top && curr->top != wakeup->top) {
3855 btv->c.nr, wakeup->top);
3856 wakeup->top->vb.ts =
ts;
3857 wakeup->top->vb.field_count = btv->field_count;
3858 wakeup->top->vb.state =
state;
3859 wake_up(&wakeup->top->vb.done);
3861 if (
NULL != wakeup->bottom && curr->bottom != wakeup->bottom) {
3863 pr_debug(
"%d: wakeup: bottom=%p\n",
3864 btv->c.nr, wakeup->bottom);
3865 wakeup->bottom->vb.ts =
ts;
3866 wakeup->bottom->vb.field_count = btv->field_count;
3867 wakeup->bottom->vb.state =
state;
3868 wake_up(&wakeup->bottom->vb.done);
3874 bttv_irq_wakeup_vbi(
struct bttv *btv,
struct bttv_buffer *wakeup,
3884 wakeup->vb.field_count = btv->field_count;
3885 wakeup->vb.state =
state;
3889 static void bttv_irq_timeout(
unsigned long data)
3891 struct bttv *btv = (
struct bttv *)data;
3892 struct bttv_buffer_set old,new;
3893 struct bttv_buffer *ovbi;
3894 struct bttv_buffer *
item;
3895 unsigned long flags;
3898 pr_info(
"%d: timeout: drop=%d irq=%d/%d, risc=%08x, ",
3899 btv->c.nr, btv->framedrop, btv->irq_me, btv->irq_total,
3908 memset(&
new,0,
sizeof(
new));
3923 while (!list_empty(&btv->capture)) {
3929 while (!list_empty(&btv->vcapture)) {
3937 spin_unlock_irqrestore(&btv->s_lock,flags);
3941 bttv_irq_wakeup_top(
struct bttv *btv)
3943 struct bttv_buffer *wakeup = btv->curr.top;
3948 spin_lock(&btv->s_lock);
3949 btv->curr.top_irq = 0;
3950 btv->curr.top =
NULL;
3954 wakeup->vb.field_count = btv->field_count;
3957 spin_unlock(&btv->s_lock);
3964 if (rc > risc->
dma + risc->
size)
3970 bttv_irq_switch_video(
struct bttv *btv)
3972 struct bttv_buffer_set new;
3973 struct bttv_buffer_set old;
3976 spin_lock(&btv->s_lock);
3979 bttv_irq_next_video(btv, &
new);
3981 if ((btv->curr.top &&
is_active(&btv->curr.top->top, rc)) ||
3982 (btv->curr.bottom &&
is_active(&btv->curr.bottom->bottom, rc))) {
3985 bttv_irq_debug_low_latency(btv, rc);
3986 spin_unlock(&btv->s_lock);
3993 btv->loop_irq &= ~1;
3998 if (
UNSET != btv->new_input) {
3999 video_mux(btv,btv->new_input);
4000 btv->new_input =
UNSET;
4005 spin_unlock(&btv->s_lock);
4009 bttv_irq_switch_vbi(
struct bttv *btv)
4011 struct bttv_buffer *
new =
NULL;
4012 struct bttv_buffer *old;
4015 spin_lock(&btv->s_lock);
4017 if (!list_empty(&btv->vcapture))
4026 bttv_irq_debug_low_latency(btv, rc);
4027 spin_unlock(&btv->s_lock);
4033 btv->loop_irq &= ~4;
4038 spin_unlock(&btv->s_lock);
4049 btv=(
struct bttv *)dev_id;
4065 pr_debug(
"%d: irq loop=%d fc=%d riscs=%x, riscc=%08x, ",
4066 btv->c.nr, count, btv->field_count,
4068 bttv_print_irqbits(stat,astat);
4071 dstat & BT848_DSTATUS_HLOC
4075 dstat & BT848_DSTATUS_PRES
4092 btv->i2c_done =
stat;
4097 bttv_irq_switch_vbi(btv);
4099 if ((astat & BT848_INT_RISCI) && (stat & (2<<28)))
4100 bttv_irq_wakeup_top(btv);
4102 if ((astat & BT848_INT_RISCI) && (stat & (1<<28)))
4103 bttv_irq_switch_video(btv);
4105 if ((astat & BT848_INT_HLOCK) && btv->opt_automute)
4106 audio_mute(btv, btv->mute);
4114 bttv_print_irqbits(stat,astat);
4117 bttv_print_riscaddr(btv);
4123 bttv_print_riscaddr(btv);
4129 if (count > 8 || !(astat & BT848_INT_GPINT)) {
4132 pr_err(
"%d: IRQ lockup, cleared int mask [",
4135 pr_err(
"%d: IRQ lockup, clearing GPINT from int mask [",
4142 bttv_print_irqbits(stat,astat);
4157 static struct video_device *vdev_init(
struct bttv *btv,
4159 const char *type_name)
4170 video_set_drvdata(vfd, btv);
4172 btv->id, (btv->id==848 && btv->revision==0x12) ?
"A" :
"",
4177 static void bttv_unregister_video(
struct bttv *btv)
4179 if (btv->video_dev) {
4180 if (video_is_registered(btv->video_dev))
4184 btv->video_dev =
NULL;
4187 if (video_is_registered(btv->vbi_dev))
4191 btv->vbi_dev =
NULL;
4193 if (btv->radio_dev) {
4194 if (video_is_registered(btv->radio_dev))
4198 btv->radio_dev =
NULL;
4203 static int __devinit bttv_register_video(
struct bttv *btv)
4206 pr_notice(
"Overlay support disabled\n");
4209 btv->video_dev = vdev_init(btv, &bttv_video_template,
"video");
4211 if (
NULL == btv->video_dev)
4214 video_nr[btv->c.nr]) < 0)
4216 pr_info(
"%d: registered device %s\n",
4217 btv->c.nr, video_device_node_name(btv->video_dev));
4219 &dev_attr_card)<0) {
4220 pr_err(
"%d: device_create_file 'card' failed\n", btv->c.nr);
4225 btv->vbi_dev = vdev_init(btv, &bttv_video_template,
"vbi");
4227 if (
NULL == btv->vbi_dev)
4230 vbi_nr[btv->c.nr]) < 0)
4232 pr_info(
"%d: registered device %s\n",
4233 btv->c.nr, video_device_node_name(btv->vbi_dev));
4235 if (!btv->has_radio)
4238 btv->radio_dev = vdev_init(btv, &radio_template,
"radio");
4239 if (
NULL == btv->radio_dev)
4242 radio_nr[btv->c.nr]) < 0)
4244 pr_info(
"%d: registered device %s\n",
4245 btv->c.nr, video_device_node_name(btv->radio_dev));
4251 bttv_unregister_video(btv);
4258 static void pci_set_command(
struct pci_dev *dev)
4260 #if defined(__powerpc__)
4281 pr_err(
"out of memory\n");
4285 snprintf(btv->c.v4l2_dev.name,
sizeof(btv->c.v4l2_dev.name),
4286 "bttv%d", btv->c.nr);
4293 INIT_LIST_HEAD(&btv->c.subs);
4294 INIT_LIST_HEAD(&btv->capture);
4295 INIT_LIST_HEAD(&btv->vcapture);
4299 btv->timeout.function = bttv_irq_timeout;
4300 btv->timeout.data = (
unsigned long)btv;
4303 btv->tuner_type =
UNSET;
4304 btv->new_input =
UNSET;
4305 btv->has_radio=radio[btv->c.nr];
4311 pr_warn(
"%d: Can't enable device\n", btv->c.nr);
4315 pr_warn(
"%d: No suitable DMA available\n", btv->c.nr);
4320 btv->c.v4l2_dev.name)) {
4321 pr_warn(
"%d: can't request iomem (0x%llx)\n",
4327 pci_set_command(dev);
4331 pr_warn(
"%d: v4l2_device_register() failed\n", btv->c.nr);
4337 pr_info(
"%d: Bt%d (rev %d) at %s, irq: %d, latency: %d, mmio: 0x%llx\n",
4338 bttv_num, btv->id, btv->revision, pci_name(dev),
4339 btv->c.pci->irq, lat,
4344 if (
NULL == btv->bt848_mmio) {
4345 pr_err(
"%d: ioremap() failed\n", btv->c.nr);
4358 pr_err(
"%d: can't get IRQ %d\n",
4369 btv->opt_combfilter = combfilter;
4370 btv->opt_lumafilter = lumafilter;
4371 btv->opt_automute = automute;
4372 btv->opt_chroma_agc = chroma_agc;
4373 btv->opt_adc_crush = adc_crush;
4374 btv->opt_vcr_hack = vcr_hack;
4375 btv->opt_whitecrush_upper = whitecrush_upper;
4376 btv->opt_whitecrush_lower = whitecrush_lower;
4377 btv->opt_uv_ratio = uv_ratio;
4378 btv->opt_full_luma_range = full_luma_range;
4379 btv->opt_coring = coring;
4382 btv->init.btv = btv;
4383 btv->init.ov.w.width = 320;
4384 btv->init.ov.w.height = 240;
4386 btv->init.width = 320;
4387 btv->init.height = 240;
4416 bttv_register_video(btv);
4417 bt848_bright(btv,32768);
4418 bt848_contrast(btv, 27648);
4419 bt848_hue(btv,32768);
4420 bt848_sat(btv,32768);
4422 set_input(btv, 0, btv->tvnorm);
4423 bttv_crop_reset(&btv->crop[0], btv->tvnorm);
4424 btv->crop[1] = btv->crop[0];
4425 disclaim_vbi_lines(btv);
4426 disclaim_video_lines(btv);
4451 if (btv->bt848_mmio)
4461 struct bttv *btv = to_bttv(v4l2_dev);
4464 pr_info(
"%d: unloading\n", btv->c.nr);
4486 bttv_unregister_video(btv);
4505 static int bttv_suspend(
struct pci_dev *pci_dev,
pm_message_t state)
4507 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
4508 struct bttv *btv = to_bttv(v4l2_dev);
4509 struct bttv_buffer_set
idle;
4510 unsigned long flags;
4516 memset(&idle, 0,
sizeof(idle));
4517 btv->state.video = btv->curr;
4518 btv->state.vbi = btv->cvbi;
4519 btv->state.loop_irq = btv->loop_irq;
4526 spin_unlock_irqrestore(&btv->s_lock,flags);
4536 btv->state.disabled = 1;
4541 static int bttv_resume(
struct pci_dev *pci_dev)
4543 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
4544 struct bttv *btv = to_bttv(v4l2_dev);
4545 unsigned long flags;
4548 dprintk(
"%d: resume\n", btv->c.nr);
4551 if (btv->state.disabled) {
4554 pr_warn(
"%d: Can't enable device\n", btv->c.nr);
4557 btv->state.disabled = 0;
4562 pr_warn(
"%d: Can't enable device\n", btv->c.nr);
4563 btv->state.disabled = 1;
4570 bttv_reinit_bt848(btv);
4571 gpio_inout(0xffffff, btv->state.gpio_enable);
4576 btv->curr = btv->state.video;
4577 btv->cvbi = btv->state.vbi;
4578 btv->loop_irq = btv->state.loop_irq;
4582 spin_unlock_irqrestore(&btv->s_lock,flags);
4600 .id_table = bttv_pci_tbl,
4601 .probe = bttv_probe,
4604 .suspend = bttv_suspend,
4605 .resume = bttv_resume,
4609 static int __init bttv_init_module(
void)
4618 if (gbufsize > BTTV_MAX_FBUF)
4619 gbufsize = BTTV_MAX_FBUF;
4622 pr_info(
"using %d buffers with %dk (%d pages) each for capture\n",
4623 gbuffers, gbufsize >> 10, gbufsize >>
PAGE_SHIFT);
4629 pr_warn(
"bus_register error: %d\n", ret);
4632 ret = pci_register_driver(&bttv_pci_driver);
4639 static void __exit bttv_cleanup_module(
void)