23 #include <linux/list.h>
24 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
31 #include <asm/div64.h>
47 static unsigned int debug;
55 #define dprintk(level, fmt, arg...)\
56 do { if (debug >= level)\
57 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg);\
60 static unsigned int cx23885_devcount;
62 #define NO_SYNC_LINE (-1U)
87 .cmds_start = 0x10000,
88 .ctrl_start = 0x10380,
111 .cmds_start = 0x100A0,
112 .ctrl_start = 0x10400,
114 .fifo_start = 0x5000,
147 .cmds_start = 0x10140,
148 .ctrl_start = 0x10440,
150 .fifo_start = 0x6000,
159 .cmds_start = 0x10190,
160 .ctrl_start = 0x10480,
162 .fifo_start = 0x7000,
198 .cmds_start = 0x10000,
199 .ctrl_start = 0x105b0,
209 .name =
"VID A (VBI)",
210 .cmds_start = 0x10050,
211 .ctrl_start = 0x105F0,
213 .fifo_start = 0x3000,
222 .cmds_start = 0x100A0,
223 .ctrl_start = 0x10630,
225 .fifo_start = 0x5000,
258 .cmds_start = 0x10140,
259 .ctrl_start = 0x10670,
261 .fifo_start = 0x6000,
270 .cmds_start = 0x10190,
271 .ctrl_start = 0x106B0,
273 .fifo_start = 0x7000,
340 static inline void cx23885_irq_enable_all(
struct cx23885_dev *
dev)
355 static inline void cx23885_irq_disable_all(
struct cx23885_dev *
dev)
383 static int cx23885_risc_decode(
u32 risc)
385 static char *
instr[16] = {
397 static int incr[16] = {
406 static char *
bits[] = {
407 "12",
"13",
"14",
"resync",
408 "cnt0",
"cnt1",
"18",
"19",
409 "20",
"21",
"22",
"23",
410 "irq1",
"irq2",
"eol",
"sol",
414 printk(
"0x%08x [ %s", risc,
415 instr[risc >> 28] ? instr[risc >> 28] :
"INVALID");
417 if (risc & (1 << (i + 12)))
419 printk(
" count=%d ]\n", risc & 0xfff);
420 return incr[risc >> 28] ? incr[risc >> 28] : 1;
430 for (bc = 0;; bc++) {
431 if (list_empty(&q->
active))
443 dprintk(2,
"[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->
vb.i,
449 if (list_empty(&q->
active))
460 unsigned int bpl,
u32 risc)
462 unsigned int i, lines;
466 dprintk(1,
"%s() Erasing channel [%s]\n", __func__,
474 dprintk(1,
"%s() Configuring channel [%s]\n", __func__,
478 bpl = (bpl + 7) & ~7;
490 for (i = 0; i < lines; i++) {
491 dprintk(2,
"%s() 0x%08x <- 0x%08x\n", __func__, cdt + 16*i,
512 for (i = 24; i < 80; i += 4)
521 dprintk(2,
"[bridge %d] sram setup %s: bpl=%d lines=%d\n",
533 static char *
name[] = {
550 unsigned int i,
j,
n;
559 for (i = 0; i < 4; i++) {
562 cx23885_risc_decode(risc);
564 for (i = 0; i < (64 >> 2); i +=
n) {
570 n = cx23885_risc_decode(risc);
571 for (j = 1; j <
n; j++) {
574 dev->
name, i+j, risc, j);
596 unsigned int i,
j,
n;
599 dev->
name, risc->
cpu, (
unsigned long)risc->
dma);
600 for (i = 0; i < (risc->
size >> 2); i +=
n) {
603 for (j = 1; j <
n; j++)
605 dev->
name, i + j, risc->
cpu[i + j], j);
611 static void cx23885_shutdown(
struct cx23885_dev *dev)
632 cx23885_irq_disable_all(dev);
643 dprintk(1,
"%s()\n", __func__);
645 cx23885_shutdown(dev);
675 static int cx23885_pci_quirks(
struct cx23885_dev *dev)
677 dprintk(1,
"%s()\n", __func__);
702 static void cx23885_timeout(
unsigned long data);
706 static int cx23885_init_tsport(
struct cx23885_dev *dev,
709 dprintk(1,
"%s(portno=%d)\n", __func__, portno);
721 INIT_LIST_HEAD(&port->
mpegq.active);
722 INIT_LIST_HEAD(&port->
mpegq.queued);
723 port->
mpegq.timeout.function = cx23885_timeout;
724 port->
mpegq.timeout.data = (
unsigned long)port;
785 static void cx23885_dev_checkrevision(
struct cx23885_dev *dev)
801 if (dev->
pci->device == 0x8880) {
810 if (dev->
pci->device == 0x8880) {
855 static int cx23885_dev_setup(
struct cx23885_dev *dev)
866 dev->
nr = cx23885_devcount++;
870 if (dev->
pci->device == 0x8880) {
872 dev->
bridge = CX23885_BRIDGE_887;
877 if (dev->
pci->device == 0x8852) {
878 dev->
bridge = CX23885_BRIDGE_885;
885 dprintk(1,
"%s() Memory configured for PCIe bridge type %d\n",
917 dev->
i2c_bus[0].i2c_period = (0x9d << 24);
927 dev->
i2c_bus[1].i2c_period = (0x9d << 24);
937 dev->
i2c_bus[2].i2c_period = (0x07 << 24);
941 cx23885_init_tsport(dev, &dev->ts1, 1);
945 cx23885_init_tsport(dev, &dev->
ts2, 2);
947 if (get_resources(dev) < 0) {
949 "subsystem: %04x:%04x\n",
950 dev->
name, dev->
pci->subsystem_vendor,
951 dev->
pci->subsystem_device);
963 printk(
KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
964 dev->
name, dev->
pci->subsystem_vendor,
967 "insmod option" :
"autodetected");
969 cx23885_pci_quirks(dev);
978 dprintk(1,
"%s() tuner_type = 0x%x tuner_addr = 0x%x tuner_bus = %d\n",
980 dprintk(1,
"%s() radio_type = 0x%x radio_addr = 0x%x\n",
1004 "video adapters on VID_A\n", __func__);
1010 dev->ts1.num_frontends =
1013 printk(
KERN_ERR "%s() Failed to register dvb adapters on VID_B\n",
1020 "%s() Failed to register 417 on VID_B\n",
1027 dev->
ts2.num_frontends =
1031 "%s() Failed to register dvb on VID_C\n",
1038 "%s() Failed to register 417 on VID_C\n",
1043 cx23885_dev_checkrevision(dev);
1049 switch (dev->
board) {
1059 static void cx23885_dev_unregister(
struct cx23885_dev *dev)
1091 unsigned int bpl,
unsigned int padding,
1092 unsigned int lines,
unsigned int lpi)
1103 for (line = 0; line < lines; line++) {
1109 if (lpi && line > 0 && !(line % lpi))
1150 struct scatterlist *sglist,
unsigned int top_offset,
1151 unsigned int bottom_offset,
unsigned int bpl,
1152 unsigned int padding,
unsigned int lines)
1159 if (
UNSET != top_offset)
1161 if (
UNSET != bottom_offset)
1169 instructions = fields * (1 + ((bpl +
padding) * lines)
1178 if (
UNSET != top_offset)
1179 rp = cx23885_risc_field(rp, sglist, top_offset, 0,
1180 bpl, padding, lines, 0);
1181 if (
UNSET != bottom_offset)
1182 rp = cx23885_risc_field(rp, sglist, bottom_offset, 0x200,
1183 bpl, padding, lines, 0);
1195 unsigned int lines,
unsigned int lpi)
1206 instructions = 1 + (bpl * lines) /
PAGE_SIZE + lines;
1216 bpl, 0, lines, lpi);
1225 struct scatterlist *sglist,
unsigned int top_offset,
1226 unsigned int bottom_offset,
unsigned int bpl,
1227 unsigned int padding,
unsigned int lines)
1234 if (
UNSET != top_offset)
1236 if (
UNSET != bottom_offset)
1244 instructions = fields * (1 + ((bpl +
padding) * lines)
1255 if (
UNSET != top_offset)
1256 rp = cx23885_risc_field(rp, sglist, top_offset, 6,
1257 bpl, padding, lines, 0);
1259 if (
UNSET != bottom_offset)
1260 rp = cx23885_risc_field(rp, sglist, bottom_offset, 0x207,
1261 bpl, padding, lines, 0);
1310 dprintk(1,
"%s() Register Dump\n", __func__);
1311 dprintk(1,
"%s() DEV_CNTRL2 0x%08X\n", __func__,
1313 dprintk(1,
"%s() PCI_INT_MSK 0x%08X\n", __func__,
1314 cx23885_irq_get_mask(dev));
1315 dprintk(1,
"%s() AUD_INT_INT_MSK 0x%08X\n", __func__,
1317 dprintk(1,
"%s() AUD_INT_DMA_CTL 0x%08X\n", __func__,
1319 dprintk(1,
"%s() AUD_EXT_INT_MSK 0x%08X\n", __func__,
1321 dprintk(1,
"%s() AUD_EXT_DMA_CTL 0x%08X\n", __func__,
1323 dprintk(1,
"%s() PAD_CTRL 0x%08X\n", __func__,
1325 dprintk(1,
"%s() ALT_PIN_OUT_SEL 0x%08X\n", __func__,
1327 dprintk(1,
"%s() GPIO2 0x%08X\n", __func__,
1329 dprintk(1,
"%s() gpcnt(0x%08X) 0x%08X\n", __func__,
1331 dprintk(1,
"%s() gpcnt_ctl(0x%08X) 0x%08x\n", __func__,
1333 dprintk(1,
"%s() dma_ctl(0x%08X) 0x%08x\n", __func__,
1336 dprintk(1,
"%s() src_sel(0x%08X) 0x%08x\n", __func__,
1338 dprintk(1,
"%s() lngth(0x%08X) 0x%08x\n", __func__,
1340 dprintk(1,
"%s() hw_sop_ctrl(0x%08X) 0x%08x\n", __func__,
1342 dprintk(1,
"%s() gen_ctrl(0x%08X) 0x%08x\n", __func__,
1344 dprintk(1,
"%s() bd_pkt_status(0x%08X) 0x%08x\n", __func__,
1346 dprintk(1,
"%s() sop_status(0x%08X) 0x%08x\n", __func__,
1348 dprintk(1,
"%s() fifo_ovfl_stat(0x%08X) 0x%08x\n", __func__,
1350 dprintk(1,
"%s() vld_misc(0x%08X) 0x%08x\n", __func__,
1352 dprintk(1,
"%s() ts_clk_en(0x%08X) 0x%08x\n", __func__,
1354 dprintk(1,
"%s() ts_int_msk(0x%08X) 0x%08x\n", __func__,
1365 dprintk(1,
"%s() w: %d, h: %d, f: %d\n", __func__,
1366 buf->
vb.width, buf->
vb.height, buf->
vb.field);
1378 cx23885_risc_disasm(port, &buf->
risc);
1386 printk(
"%s() Unsupported .portb/c (0x%08x)/(0x%08x)\n",
1447 dprintk(1,
"%s() enabling TS int's and DMA\n", __func__);
1451 cx23885_irq_enable_all(dev);
1463 cx23885_tsport_reg_dump(port);
1473 dprintk(1,
"%s()\n", __func__);
1506 dprintk(5,
"%s()\n", __func__);
1507 if (list_empty(&q->
active)) {
1511 dprintk(5,
"%s() queue is empty\n", __func__);
1514 if (list_empty(&q->
queued))
1521 cx23885_start_dma(port, q, buf);
1525 dprintk(5,
"[%p/%d] restart_queue - f/active\n",
1528 }
else if (prev->
vb.width == buf->
vb.width &&
1529 prev->
vb.height == buf->
vb.height &&
1538 dprintk(5,
"[%p/%d] restart_queue - m/active\n",
1549 dprintk(2,
"restart_queue [%p/%d]: restart dma\n",
1551 cx23885_start_dma(port, q, buf);
1567 dprintk(1,
"%s: %p\n", __func__, buf);
1568 if (0 != buf->
vb.baddr && buf->
vb.bsize < size)
1575 buf->
vb.field = field ;
1582 buf->
vb.width, buf->
vb.height, 0);
1603 if (list_empty(&cx88q->
active)) {
1604 dprintk(1,
"queue is empty - first active\n");
1606 cx23885_start_dma(port, cx88q, buf);
1610 dprintk(1,
"[%p/%d] %s - first active\n",
1611 buf, buf->
vb.i, __func__);
1613 dprintk(1,
"queue is not empty - append to active\n");
1621 dprintk(1,
"[%p/%d] %s - append to active\n",
1622 buf, buf->
vb.i, __func__);
1634 unsigned long flags;
1637 while (!list_empty(&q->
active)) {
1643 dprintk(1,
"[%p/%d] %s - dma=0x%08lx\n",
1644 buf, buf->
vb.i, reason, (
unsigned long)buf->
risc.dma);
1647 dprintk(1,
"restarting queue\n");
1650 spin_unlock_irqrestore(&port->
slock, flags);
1658 dprintk(1,
"%s()\n", __func__);
1660 cx23885_stop_dma(port);
1661 do_cancel_buffers(port,
"cancel", 0);
1664 static void cx23885_timeout(
unsigned long data)
1669 dprintk(1,
"%s()\n", __func__);
1675 cx23885_stop_dma(port);
1676 do_cancel_buffers(port,
"timeout", 1);
1690 dprintk(7,
"status: 0x%08x mask: 0x%08x count: 0x%x\n",
1701 "= 0x%x\n", dev->
name, status);
1702 if (status & VID_B_MSK_BAD_PKT)
1703 dprintk(1,
" VID_B_MSK_BAD_PKT\n");
1704 if (status & VID_B_MSK_OPC_ERR)
1705 dprintk(1,
" VID_B_MSK_OPC_ERR\n");
1706 if (status & VID_B_MSK_VBI_OPC_ERR)
1707 dprintk(1,
" VID_B_MSK_VBI_OPC_ERR\n");
1708 if (status & VID_B_MSK_SYNC)
1709 dprintk(1,
" VID_B_MSK_SYNC\n");
1710 if (status & VID_B_MSK_VBI_SYNC)
1711 dprintk(1,
" VID_B_MSK_VBI_SYNC\n");
1712 if (status & VID_B_MSK_OF)
1713 dprintk(1,
" VID_B_MSK_OF\n");
1714 if (status & VID_B_MSK_VBI_OF)
1715 dprintk(1,
" VID_B_MSK_VBI_OF\n");
1722 dprintk(7,
" VID_B_MSK_RISCI1\n");
1723 spin_lock(&port->
slock);
1725 spin_unlock(&port->
slock);
1727 dprintk(7,
" VID_B_MSK_RISCI2\n");
1728 spin_lock(&port->
slock);
1730 spin_unlock(&port->
slock);
1751 if (status & VID_BC_MSK_OPC_ERR)
1752 dprintk(7,
" (VID_BC_MSK_OPC_ERR 0x%08x)\n",
1753 VID_BC_MSK_OPC_ERR);
1755 if (status & VID_BC_MSK_BAD_PKT)
1756 dprintk(7,
" (VID_BC_MSK_BAD_PKT 0x%08x)\n",
1757 VID_BC_MSK_BAD_PKT);
1759 if (status & VID_BC_MSK_SYNC)
1760 dprintk(7,
" (VID_BC_MSK_SYNC 0x%08x)\n",
1763 if (status & VID_BC_MSK_OF)
1764 dprintk(7,
" (VID_BC_MSK_OF 0x%08x)\n",
1775 dprintk(7,
" (RISCI1 0x%08x)\n", VID_BC_MSK_RISCI1);
1777 spin_lock(&port->
slock);
1780 spin_unlock(&port->
slock);
1784 dprintk(7,
" (RISCI2 0x%08x)\n", VID_BC_MSK_RISCI2);
1786 spin_lock(&port->
slock);
1788 spin_unlock(&port->
slock);
1804 u32 pci_status, pci_mask;
1805 u32 vida_status, vida_mask;
1806 u32 audint_status, audint_mask;
1807 u32 ts1_status, ts1_mask;
1808 u32 ts2_status, ts2_mask;
1809 int vida_count = 0, ts1_count = 0, ts2_count = 0, handled = 0;
1810 int audint_count = 0;
1811 bool subdev_handled;
1814 pci_mask = cx23885_irq_get_mask(dev);
1824 if ((pci_status == 0) && (ts2_status == 0) && (ts1_status == 0))
1831 dprintk(7,
"pci_status: 0x%08x pci_mask: 0x%08x\n",
1832 pci_status, pci_mask);
1833 dprintk(7,
"vida_status: 0x%08x vida_mask: 0x%08x count: 0x%x\n",
1834 vida_status, vida_mask, vida_count);
1835 dprintk(7,
"audint_status: 0x%08x audint_mask: 0x%08x count: 0x%x\n",
1836 audint_status, audint_mask, audint_count);
1837 dprintk(7,
"ts1_status: 0x%08x ts1_mask: 0x%08x count: 0x%x\n",
1838 ts1_status, ts1_mask, ts1_count);
1839 dprintk(7,
"ts2_status: 0x%08x ts2_mask: 0x%08x count: 0x%x\n",
1840 ts2_status, ts2_mask, ts2_count);
1850 dprintk(7,
" (PCI_MSK_RISC_RD 0x%08x)\n",
1854 dprintk(7,
" (PCI_MSK_RISC_WR 0x%08x)\n",
1858 dprintk(7,
" (PCI_MSK_AL_RD 0x%08x)\n",
1862 dprintk(7,
" (PCI_MSK_AL_WR 0x%08x)\n",
1866 dprintk(7,
" (PCI_MSK_APB_DMA 0x%08x)\n",
1870 dprintk(7,
" (PCI_MSK_VID_C 0x%08x)\n",
1874 dprintk(7,
" (PCI_MSK_VID_B 0x%08x)\n",
1878 dprintk(7,
" (PCI_MSK_VID_A 0x%08x)\n",
1882 dprintk(7,
" (PCI_MSK_AUD_INT 0x%08x)\n",
1886 dprintk(7,
" (PCI_MSK_AUD_EXT 0x%08x)\n",
1890 dprintk(7,
" (PCI_MSK_GPIO0 0x%08x)\n",
1894 dprintk(7,
" (PCI_MSK_GPIO1 0x%08x)\n",
1898 dprintk(7,
" (PCI_MSK_AV_CORE 0x%08x)\n",
1902 dprintk(7,
" (PCI_MSK_IR 0x%08x)\n",
1907 (pci_status & (PCI_MSK_GPIO1 | PCI_MSK_GPIO0)))
1911 (pci_status & PCI_MSK_GPIO0))
1916 handled += cx23885_irq_ts(ts1, ts1_status);
1924 handled += cx23885_irq_ts(ts2, ts2_status);
1937 subdev_handled =
false;
1939 pci_status, &subdev_handled);
1944 if ((pci_status & pci_mask) & PCI_MSK_AV_CORE) {
1948 " AV Core/IR interrupt. Interrupt is disabled"
1949 " and won't be re-enabled\n", dev->
name);
1969 switch (notification) {
1971 if (sd == dev->
sd_ir)
1975 if (sd == dev->
sd_ir)
1981 static void cx23885_v4l2_dev_notify_init(
struct cx23885_dev *dev)
1986 dev->
v4l2_dev.notify = cx23885_v4l2_dev_notify;
1989 static inline int encoder_on_portb(
struct cx23885_dev *dev)
1994 static inline int encoder_on_portc(
struct cx23885_dev *dev)
2016 if (mask & 0x0007fff8) {
2017 if (encoder_on_portb(dev) || encoder_on_portc(dev))
2019 "%s: Setting GPIO on encoder ports\n",
2025 if (mask & 0x00f80000)
2031 if (mask & 0x00000007)
2034 if (mask & 0x0007fff8) {
2035 if (encoder_on_portb(dev) || encoder_on_portc(dev))
2037 "%s: Clearing GPIO moving on encoder ports\n",
2043 if (mask & 0x00f80000)
2049 if (mask & 0x00000007)
2052 if (mask & 0x0007fff8) {
2053 if (encoder_on_portb(dev) || encoder_on_portc(dev))
2055 "%s: Reading GPIO moving on encoder ports\n",
2061 if (mask & 0x00f80000)
2069 if ((mask & 0x00000007) && asoutput)
2071 else if ((mask & 0x00000007) && !asoutput)
2074 if (mask & 0x0007fff8) {
2075 if (encoder_on_portb(dev) || encoder_on_portc(dev))
2077 "%s: Enabling GPIO on encoder ports\n",
2082 if ((mask & 0x0007fff8) && asoutput)
2085 else if ((mask & 0x0007fff8) && !asoutput)
2106 cx23885_v4l2_dev_notify_init(dev);
2115 if (cx23885_dev_setup(dev) < 0) {
2124 "latency: %d, mmio: 0x%llx\n", dev->
name,
2125 pci_name(pci_dev), dev->
pci_rev, pci_dev->
irq,
2130 if (!pci_dma_supported(pci_dev, 0xffffffff)) {
2131 printk(
"%s/0: Oops: no 32bit PCI DMA ???\n", dev->
name);
2144 switch (dev->
board) {
2164 cx23885_dev_unregister(dev);
2172 static void __devexit cx23885_finidev(
struct pci_dev *pci_dev)
2174 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
2180 cx23885_shutdown(dev);
2187 cx23885_dev_unregister(dev);
2211 static struct pci_driver cx23885_pci_driver = {
2213 .id_table = cx23885_pci_tbl,
2214 .probe = cx23885_initdev,
2221 static int __init cx23885_init(
void)
2225 return pci_register_driver(&cx23885_pci_driver);
2228 static void __exit cx23885_fini(
void)