29 #include <linux/list.h>
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/slab.h>
34 #include <linux/sound.h>
36 #include <linux/pci.h>
38 #include <linux/videodev2.h>
51 static unsigned int core_debug;
55 static unsigned int nicam;
59 static unsigned int nocomb;
63 #define dprintk(level,fmt, arg...) if (core_debug >= level) \
64 printk(KERN_DEBUG "%s: " fmt, core->name , ## arg)
66 static unsigned int cx88_devcount;
70 #define NO_SYNC_LINE (-1U)
76 unsigned int bpl,
unsigned int padding,
77 unsigned int lines,
unsigned int lpi)
88 for (line = 0; line < lines; line++) {
93 if (lpi && line>0 && !(line % lpi))
130 unsigned int top_offset,
unsigned int bottom_offset,
131 unsigned int bpl,
unsigned int padding,
unsigned int lines)
138 if (
UNSET != top_offset)
140 if (
UNSET != bottom_offset)
147 instructions = fields * (1 + ((bpl +
padding) * lines) /
PAGE_SIZE + lines);
154 if (
UNSET != top_offset)
155 rp = cx88_risc_field(rp, sglist, top_offset, 0,
156 bpl, padding, lines, 0);
157 if (
UNSET != bottom_offset)
158 rp = cx88_risc_field(rp, sglist, bottom_offset, 0x200,
159 bpl, padding, lines, 0);
169 unsigned int lines,
unsigned int lpi)
179 instructions = 1 + (bpl * lines) /
PAGE_SIZE + lines;
186 rp = cx88_risc_field(rp, sglist, 0,
NO_SYNC_LINE, bpl, 0, lines, lpi);
258 .name =
"video y / packed",
259 .cmds_start = 0x180040,
260 .ctrl_start = 0x180400,
261 .cdt = 0x180400 + 64,
262 .fifo_start = 0x180c00,
263 .fifo_size = 0x002800,
271 .cmds_start = 0x180080,
272 .ctrl_start = 0x1804a0,
273 .cdt = 0x1804a0 + 64,
274 .fifo_start = 0x183400,
275 .fifo_size = 0x000800,
283 .cmds_start = 0x1800c0,
284 .ctrl_start = 0x180540,
285 .cdt = 0x180540 + 64,
286 .fifo_start = 0x183c00,
287 .fifo_size = 0x000800,
295 .cmds_start = 0x180100,
296 .ctrl_start = 0x1805e0,
297 .cdt = 0x1805e0 + 64,
298 .fifo_start = 0x184400,
299 .fifo_size = 0x001000,
306 .name =
"audio from",
307 .cmds_start = 0x180140,
308 .ctrl_start = 0x180680,
309 .cdt = 0x180680 + 64,
310 .fifo_start = 0x185400,
311 .fifo_size = 0x001000,
319 .cmds_start = 0x180180,
320 .ctrl_start = 0x180720,
321 .cdt = 0x180680 + 64,
322 .fifo_start = 0x185400,
323 .fifo_size = 0x001000,
331 .cmds_start = 0x180200,
332 .ctrl_start = 0x1807C0,
333 .cdt = 0x1807C0 + 64,
334 .fifo_start = 0x186400,
335 .fifo_size = 0x001000,
343 .cmds_start = 0x1801C0,
344 .ctrl_start = 0x180860,
345 .cdt = 0x180860 + 64,
346 .fifo_start = 0x187400,
347 .fifo_size = 0x000C00,
357 unsigned int bpl,
u32 risc)
359 unsigned int i,lines;
362 bpl = (bpl + 7) & ~7;
370 for (i = 0; i < lines; i++)
379 for (i = 20; i < 64; i += 4)
388 dprintk(2,
"sram setup %s: bpl=%d lines=%d\n", ch->
name, bpl, lines);
395 static int cx88_risc_decode(
u32 risc)
397 static const char *
const instr[16] = {
409 static int const incr[16] = {
416 static const char *
const bits[] = {
417 "12",
"13",
"14",
"resync",
418 "cnt0",
"cnt1",
"18",
"19",
419 "20",
"21",
"22",
"23",
420 "irq1",
"irq2",
"eol",
"sol",
424 printk(
"0x%08x [ %s", risc,
425 instr[risc >> 28] ? instr[risc >> 28] :
"INVALID");
427 if (risc & (1 << (i + 12)))
429 printk(
" count=%d ]\n", risc & 0xfff);
430 return incr[risc >> 28] ? incr[risc >> 28] : 1;
437 static const char *
const name[] = {
453 printk(
"%s: %s - dma channel status dump\n",
456 printk(
"%s: cmds: %-12s: 0x%08x\n",
459 for (n = 1, i = 0; i < 4; i++) {
463 printk(
"0x%08x [ arg #%d ]\n", risc, n);
465 n = cx88_risc_decode(risc);
467 for (i = 0; i < 16; i +=
n) {
470 n = cx88_risc_decode(risc);
471 for (j = 1; j <
n; j++) {
473 printk(
"%s: iq %x: 0x%08x [ arg #%d ]\n",
474 core->
name, i+j, risc, j);
478 printk(
"%s: fifo: 0x%08x -> 0x%x\n",
480 printk(
"%s: ctrl: 0x%08x -> 0x%x\n",
482 printk(
"%s: ptr1_reg: 0x%08x\n",
484 printk(
"%s: ptr2_reg: 0x%08x\n",
486 printk(
"%s: cnt1_reg: 0x%08x\n",
488 printk(
"%s: cnt2_reg: 0x%08x\n",
492 static const char *cx88_pci_irqs[32] = {
493 "vid",
"aud",
"ts",
"vip",
"hst",
"5",
"6",
"tm1",
494 "src_dma",
"dst_dma",
"risc_rd_err",
"risc_wr_err",
495 "brdg_err",
"src_dma_err",
"dst_dma_err",
"ipb_dma_err",
496 "i2c",
"i2c_rack",
"ir_smp",
"gpio0",
"gpio1"
505 for (i = 0; i < len; i++) {
506 if (!(bits & (1 << i)))
509 printk(
" %s", strings[i]);
512 if (!(mask & (1 << i)))
542 for (bc = 0;; bc++) {
543 if (list_empty(&q->
active))
553 dprintk(2,
"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->
vb.i,
559 if (list_empty(&q->
active)) {
565 dprintk(2,
"%s: %d buffers handled (should be 1)\n",
649 static unsigned int inline norm_swidth(
v4l2_std_id norm)
654 static unsigned int inline norm_hdelay(
v4l2_std_id norm)
659 static unsigned int inline norm_vdelay(
v4l2_std_id norm)
664 static unsigned int inline norm_fsc8(
v4l2_std_id norm)
684 static unsigned int inline norm_htotal(
v4l2_std_id norm)
687 unsigned int fsc4=norm_fsc8(norm)/2;
691 ((fsc4+312)/625+12)/25 :
692 ((fsc4+262)/525*1001+15000)/30000;
695 static unsigned int inline norm_vbipack(
v4l2_std_id norm)
703 unsigned int swidth = norm_swidth(core->
tvnorm);
707 dprintk(1,
"set_scale: %dx%d [%s%s,%s]\n", width, height,
715 value = (width * norm_hdelay(core->
tvnorm)) / swidth;
719 dprintk(1,
"set_scale: hdelay 0x%04x (width %d)\n", value,swidth);
721 value = (swidth * 4096 /
width) - 4096;
724 dprintk(1,
"set_scale: hscale 0x%04x\n", value);
728 dprintk(1,
"set_scale: hactive 0x%04x\n", width);
733 dprintk(1,
"set_scale: vdelay 0x%04x\n", norm_vdelay(core->
tvnorm));
735 value = (0x10000 - (sheight * 512 / height - 512)) & 0x1fff;
738 dprintk(1,
"set_scale: vscale 0x%04x\n", value);
742 dprintk(1,
"set_scale: vactive 0x%04x\n", sheight);
752 value |= (1 << 13) | (1 << 5);
764 dprintk(1,
"set_scale: filter 0x%04x\n", value);
769 static const u32 xtal = 28636363;
773 static const u32 pre[] = { 0, 0, 0, 3, 2, 1 };
783 pll = ofreq * 8 * prescale * (
u64)(1 << 20);
785 reg = (pll & 0x3ffffff) | (pre[prescale] << 26);
786 if (((reg >> 20) & 0x3f) < 14) {
787 printk(
"%s/0: pll out of range\n",core->
name);
791 dprintk(1,
"set_pll: MO_PLL_REG 0x%08x [old=0x%08x,freq=%d]\n",
794 for (i = 0; i < 100; i++) {
797 dprintk(1,
"pll locked [pre=%d,ofreq=%d]\n",
801 dprintk(1,
"pll not locked yet, waiting ...\n");
804 dprintk(1,
"pll NOT locked [pre=%d,ofreq=%d]\n",prescale,ofreq);
846 static int set_tvaudio(
struct cx88_core *core)
873 (V4L2_STD_PAL_M & norm)) {
880 printk(
"%s/0: tvaudio support needs work for this tv norm [%s], sorry\n",
907 u32 bdelay,agcdelay,htotal;
908 u32 cxiformat, cxoformat;
911 fsc8 = norm_fsc8(norm);
919 cxoformat = 0x181f0008;
922 cxoformat = 0x181f0008;
923 }
else if (norm & V4L2_STD_PAL_M) {
925 cxoformat = 0x1c1f0008;
928 cxoformat = 0x1c1f0008;
931 cxoformat = 0x1c1f0008;
934 cxoformat = 0x181f0008;
937 cxoformat = 0x181f0008;
939 step_db = 4250000 * 8;
940 step_dr = 4406250 * 8;
943 cxoformat = 0x181f0008;
946 cxoformat = 0x181f0008;
949 dprintk(1,
"set_tvnorm: \"%s\" fsc8=%d adc=%d vdec=%d db/dr=%d/%d\n",
952 set_pll(core,2,vdec_clock);
954 dprintk(1,
"set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n",
959 norm & V4L2_STD_SECAM ? cxiformat : cxiformat | 0x400);
962 dprintk(1,
"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n",
967 tmp64 = adc_clock * (
u64)(1 << 17);
968 do_div(tmp64, vdec_clock);
969 dprintk(1,
"set_tvnorm: MO_SCONV_REG 0x%08x [old=0x%08x]\n",
974 tmp64 = step_db * (
u64)(1 << 22);
975 do_div(tmp64, vdec_clock);
976 dprintk(1,
"set_tvnorm: MO_SUB_STEP 0x%08x [old=0x%08x]\n",
981 tmp64 = step_dr * (
u64)(1 << 22);
982 do_div(tmp64, vdec_clock);
983 dprintk(1,
"set_tvnorm: MO_SUB_STEP_DR 0x%08x [old=0x%08x]\n",
988 bdelay = vdec_clock * 65 / 20000000 + 21;
989 agcdelay = vdec_clock * 68 / 20000000 + 15;
990 dprintk(1,
"set_tvnorm: MO_AGC_BURST 0x%08x [old=0x%08x,bdelay=%d,agcdelay=%d]\n",
995 tmp64 = norm_htotal(norm) * (
u64)vdec_clock;
998 dprintk(1,
"set_tvnorm: MO_HTOTAL 0x%08x [old=0x%08x,htotal=%d]\n",