cx88-core.c
来自「trident tm5600的linux驱动」· C语言 代码 · 共 1,130 行 · 第 1/3 页
C
1,130 行
}/* ------------------------------------------------------------------ *//* debug helper code */static int cx88_risc_decode(u32 risc){ static char *instr[16] = { [ RISC_SYNC >> 28 ] = "sync", [ RISC_WRITE >> 28 ] = "write", [ RISC_WRITEC >> 28 ] = "writec", [ RISC_READ >> 28 ] = "read", [ RISC_READC >> 28 ] = "readc", [ RISC_JUMP >> 28 ] = "jump", [ RISC_SKIP >> 28 ] = "skip", [ RISC_WRITERM >> 28 ] = "writerm", [ RISC_WRITECM >> 28 ] = "writecm", [ RISC_WRITECR >> 28 ] = "writecr", }; static int incr[16] = { [ RISC_WRITE >> 28 ] = 2, [ RISC_JUMP >> 28 ] = 2, [ RISC_WRITERM >> 28 ] = 3, [ RISC_WRITECM >> 28 ] = 3, [ RISC_WRITECR >> 28 ] = 4, }; static char *bits[] = { "12", "13", "14", "resync", "cnt0", "cnt1", "18", "19", "20", "21", "22", "23", "irq1", "irq2", "eol", "sol", }; int i; printk("0x%08x [ %s", risc, instr[risc >> 28] ? instr[risc >> 28] : "INVALID"); for (i = ARRAY_SIZE(bits)-1; i >= 0; i--) if (risc & (1 << (i + 12))) printk(" %s",bits[i]); printk(" count=%d ]\n", risc & 0xfff); return incr[risc >> 28] ? incr[risc >> 28] : 1;}#if 0 /* currently unused, but useful for debugging */void cx88_risc_disasm(struct cx88_core *core, struct btcx_riscmem *risc){ unsigned int i,j,n; printk("%s: risc disasm: %p [dma=0x%08lx]\n", core->name, risc->cpu, (unsigned long)risc->dma); for (i = 0; i < (risc->size >> 2); i += n) { printk("%s: %04d: ", core->name, i); n = cx88_risc_decode(risc->cpu[i]); for (j = 1; j < n; j++) printk("%s: %04d: 0x%08x [ arg #%d ]\n", core->name, i+j, risc->cpu[i+j], j); if (risc->cpu[i] == RISC_JUMP) break; }}#endifvoid cx88_sram_channel_dump(struct cx88_core *core, struct sram_channel *ch){ static char *name[] = { "initial risc", "cdt base", "cdt size", "iq base", "iq size", "risc pc", "iq wr ptr", "iq rd ptr", "cdt current", "pci target", "line / byte", }; u32 risc; unsigned int i,j,n; printk("%s: %s - dma channel status dump\n", core->name,ch->name); for (i = 0; i < ARRAY_SIZE(name); i++) printk("%s: cmds: %-12s: 0x%08x\n", core->name,name[i], cx_read(ch->cmds_start + 4*i)); for (n = 1, i = 0; i < 4; i++) { risc = cx_read(ch->cmds_start + 4 * (i+11)); printk("%s: risc%d: ", core->name, i); if (--n) printk("0x%08x [ arg #%d ]\n", risc, n); else n = cx88_risc_decode(risc); } for (i = 0; i < 16; i += n) { risc = cx_read(ch->ctrl_start + 4 * i); printk("%s: iq %x: ", core->name, i); n = cx88_risc_decode(risc); for (j = 1; j < n; j++) { risc = cx_read(ch->ctrl_start + 4 * (i+j)); printk("%s: iq %x: 0x%08x [ arg #%d ]\n", core->name, i+j, risc, j); } } printk("%s: fifo: 0x%08x -> 0x%x\n", core->name, ch->fifo_start, ch->fifo_start+ch->fifo_size); printk("%s: ctrl: 0x%08x -> 0x%x\n", core->name, ch->ctrl_start, ch->ctrl_start+6*16); printk("%s: ptr1_reg: 0x%08x\n", core->name,cx_read(ch->ptr1_reg)); printk("%s: ptr2_reg: 0x%08x\n", core->name,cx_read(ch->ptr2_reg)); printk("%s: cnt1_reg: 0x%08x\n", core->name,cx_read(ch->cnt1_reg)); printk("%s: cnt2_reg: 0x%08x\n", core->name,cx_read(ch->cnt2_reg));}static char *cx88_pci_irqs[32] = { "vid", "aud", "ts", "vip", "hst", "5", "6", "tm1", "src_dma", "dst_dma", "risc_rd_err", "risc_wr_err", "brdg_err", "src_dma_err", "dst_dma_err", "ipb_dma_err", "i2c", "i2c_rack", "ir_smp", "gpio0", "gpio1"};void cx88_print_irqbits(char *name, char *tag, char **strings, int len, u32 bits, u32 mask){ unsigned int i; printk(KERN_DEBUG "%s: %s [0x%x]", name, tag, bits); for (i = 0; i < len; i++) { if (!(bits & (1 << i))) continue; if (strings[i]) printk(" %s", strings[i]); else printk(" %d", i); if (!(mask & (1 << i))) continue; printk("*"); } printk("\n");}/* ------------------------------------------------------------------ */int cx88_core_irq(struct cx88_core *core, u32 status){ int handled = 0; if (status & PCI_INT_IR_SMPINT) { cx88_ir_irq(core); handled++; } if (!handled) cx88_print_irqbits(core->name, "irq pci", cx88_pci_irqs, ARRAY_SIZE(cx88_pci_irqs), status, core->pci_irqmask); return handled;}void cx88_wakeup(struct cx88_core *core, struct cx88_dmaqueue *q, u32 count){ struct cx88_buffer *buf; int bc; for (bc = 0;; bc++) { if (list_empty(&q->active)) break; buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);#if 0 if (buf->count > count) break;#else /* count comes from the hw and is is 16bit wide -- * this trick handles wrap-arounds correctly for * up to 32767 buffers in flight... */ if ((s16) (count - buf->count) < 0) break;#endif do_gettimeofday(&buf->vb.ts); dprintk(2,"[%p/%d] wakeup reg=%d buf=%d\n",buf,buf->vb.i, count, buf->count); buf->vb.state = VIDEOBUF_DONE; list_del(&buf->vb.queue); wake_up(&buf->vb.done); } if (list_empty(&q->active)) { del_timer(&q->timeout); } else { mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); } if (bc != 1) dprintk(2, "%s: %d buffers handled (should be 1)\n", __func__, bc);}void cx88_shutdown(struct cx88_core *core){ /* disable RISC controller + IRQs */ cx_write(MO_DEV_CNTRL2, 0); /* stop dma transfers */ cx_write(MO_VID_DMACNTRL, 0x0); cx_write(MO_AUD_DMACNTRL, 0x0); cx_write(MO_TS_DMACNTRL, 0x0); cx_write(MO_VIP_DMACNTRL, 0x0); cx_write(MO_GPHST_DMACNTRL, 0x0); /* stop interrupts */ cx_write(MO_PCI_INTMSK, 0x0); cx_write(MO_VID_INTMSK, 0x0); cx_write(MO_AUD_INTMSK, 0x0); cx_write(MO_TS_INTMSK, 0x0); cx_write(MO_VIP_INTMSK, 0x0); cx_write(MO_GPHST_INTMSK, 0x0); /* stop capturing */ cx_write(VID_CAPTURE_CONTROL, 0);}int cx88_reset(struct cx88_core *core){ dprintk(1,"%s\n",__func__); cx88_shutdown(core); /* clear irq status */ cx_write(MO_VID_INTSTAT, 0xFFFFFFFF); // Clear PIV int cx_write(MO_PCI_INTSTAT, 0xFFFFFFFF); // Clear PCI int cx_write(MO_INT1_STAT, 0xFFFFFFFF); // Clear RISC int /* wait a bit */ msleep(100); /* init sram */ cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH21], 720*4, 0); cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH22], 128, 0); cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH23], 128, 0); cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH24], 128, 0); cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH25], 128, 0); cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH26], 128, 0); cx88_sram_channel_setup(core, &cx88_sram_channels[SRAM_CH28], 188*4, 0); /* misc init ... */ cx_write(MO_INPUT_FORMAT, ((1 << 13) | // agc enable (1 << 12) | // agc gain (1 << 11) | // adaptibe agc (0 << 10) | // chroma agc (0 << 9) | // ckillen (7))); /* setup image format */ cx_andor(MO_COLOR_CTRL, 0x4000, 0x4000); /* setup FIFO Threshholds */ cx_write(MO_PDMA_STHRSH, 0x0807); cx_write(MO_PDMA_DTHRSH, 0x0807); /* fixes flashing of image */ cx_write(MO_AGC_SYNC_TIP1, 0x0380000F); cx_write(MO_AGC_BACK_VBI, 0x00E00555); cx_write(MO_VID_INTSTAT, 0xFFFFFFFF); // Clear PIV int cx_write(MO_PCI_INTSTAT, 0xFFFFFFFF); // Clear PCI int cx_write(MO_INT1_STAT, 0xFFFFFFFF); // Clear RISC int /* Reset on-board parts */ cx_write(MO_SRST_IO, 0); msleep(10); cx_write(MO_SRST_IO, 1); return 0;}/* ------------------------------------------------------------------ */static unsigned int inline norm_swidth(v4l2_std_id norm){ return (norm & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 754 : 922;}static unsigned int inline norm_hdelay(v4l2_std_id norm){ return (norm & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 135 : 186;}static unsigned int inline norm_vdelay(v4l2_std_id norm){ return (norm & V4L2_STD_625_50) ? 0x24 : 0x18;}static unsigned int inline norm_fsc8(v4l2_std_id norm){ if (norm & V4L2_STD_PAL_M) return 28604892; // 3.575611 MHz if (norm & (V4L2_STD_PAL_Nc)) return 28656448; // 3.582056 MHz if (norm & V4L2_STD_NTSC) // All NTSC/M and variants return 28636360; // 3.57954545 MHz +/- 10 Hz /* SECAM have also different sub carrier for chroma, but step_db and step_dr, at cx88_set_tvnorm already handles that. The same FSC applies to PAL/BGDKIH, PAL/60, NTSC/4.43 and PAL/N */ return 35468950; // 4.43361875 MHz +/- 5 Hz}static unsigned int inline norm_htotal(v4l2_std_id norm){ unsigned int fsc4=norm_fsc8(norm)/2; /* returns 4*FSC / vtotal / frames per seconds */ return (norm & V4L2_STD_625_50) ? ((fsc4+312)/625+12)/25 : ((fsc4+262)/525*1001+15000)/30000;}static unsigned int inline norm_vbipack(v4l2_std_id norm){ return (norm & V4L2_STD_625_50) ? 511 : 400;}int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int height, enum v4l2_field field){ unsigned int swidth = norm_swidth(core->tvnorm); unsigned int sheight = norm_maxh(core->tvnorm); u32 value; dprintk(1,"set_scale: %dx%d [%s%s,%s]\n", width, height, V4L2_FIELD_HAS_TOP(field) ? "T" : "", V4L2_FIELD_HAS_BOTTOM(field) ? "B" : "", v4l2_norm_to_name(core->tvnorm)); if (!V4L2_FIELD_HAS_BOTH(field)) height *= 2; // recalc H delay and scale registers value = (width * norm_hdelay(core->tvnorm)) / swidth; value &= 0x3fe; cx_write(MO_HDELAY_EVEN, value); cx_write(MO_HDELAY_ODD, value); dprintk(1,"set_scale: hdelay 0x%04x (width %d)\n", value,swidth); value = (swidth * 4096 / width) - 4096; cx_write(MO_HSCALE_EVEN, value); cx_write(MO_HSCALE_ODD, value); dprintk(1,"set_scale: hscale 0x%04x\n", value); cx_write(MO_HACTIVE_EVEN, width); cx_write(MO_HACTIVE_ODD, width); dprintk(1,"set_scale: hactive 0x%04x\n", width); // recalc V scale Register (delay is constant) cx_write(MO_VDELAY_EVEN, norm_vdelay(core->tvnorm)); cx_write(MO_VDELAY_ODD, norm_vdelay(core->tvnorm)); dprintk(1,"set_scale: vdelay 0x%04x\n", norm_vdelay(core->tvnorm)); value = (0x10000 - (sheight * 512 / height - 512)) & 0x1fff; cx_write(MO_VSCALE_EVEN, value); cx_write(MO_VSCALE_ODD, value); dprintk(1,"set_scale: vscale 0x%04x\n", value); cx_write(MO_VACTIVE_EVEN, sheight); cx_write(MO_VACTIVE_ODD, sheight); dprintk(1,"set_scale: vactive 0x%04x\n", sheight);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?