24 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 #include <linux/i2c.h>
27 #include <linux/slab.h>
36 static unsigned int debug;
44 static unsigned int cx25821_devcount;
229 .name =
"audio from",
243 .name =
"VID Upstream I",
269 .name =
"VID Upstream J",
295 .name =
"Audio Upstream Channel B",
334 static int cx25821_risc_decode(
u32 risc)
336 static const char *
const instr[16] = {
348 static const int incr[16] = {
357 static const char *
const bits[] = {
358 "12",
"13",
"14",
"resync",
359 "cnt0",
"cnt1",
"18",
"19",
360 "20",
"21",
"22",
"23",
361 "irq1",
"irq2",
"eol",
"sol",
366 risc, instr[risc >> 28] ? instr[risc >> 28] :
"INVALID");
368 if (risc & (1 << (i + 12)))
371 pr_cont(
" count=%d ]\n", risc & 0xfff);
372 return incr[risc >> 28] ? incr[risc >> 28] : 1;
375 static inline int i2c_slave_did_ack(
struct i2c_adapter *i2c_adap)
461 unsigned int bpl,
u32 risc)
463 unsigned int i, lines;
474 bpl = (bpl + 7) & ~7;
488 for (i = 0; i < lines; i++) {
496 for (i = 0; i < 128; i++)
515 for (i = 24; i < 80; i += 4)
530 unsigned int bpl,
u32 risc)
532 unsigned int i, lines;
543 bpl = (bpl + 7) & ~7;
557 for (i = 0; i < lines; i++) {
582 for (i = 24; i < 80; i += 4)
597 static char *
name[] = {
614 unsigned int i,
j,
n;
618 pr_warn(
"cmds + 0x%2x: %-15s: 0x%08x\n",
622 for (i = 0; i < 4;) {
624 pr_warn(
"cmds + 0x%2x: risc%d: ", j + i * 4, i);
625 i += cx25821_risc_decode(risc);
628 for (i = 0; i < (64 >> 2); i +=
n) {
632 pr_warn(
"ctrl + 0x%2x (0x%08x): iq %x: ",
634 n = cx25821_risc_decode(risc);
635 for (j = 1; j <
n; j++) {
637 pr_warn(
"ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n",
638 4 * (i + j), i + j, risc, j);
642 pr_warn(
" : fifo: 0x%08x -> 0x%x\n",
644 pr_warn(
" : ctrl: 0x%08x -> 0x%x\n",
646 pr_warn(
" : ptr1_reg: 0x%08x\n",
648 pr_warn(
" : ptr2_reg: 0x%08x\n",
650 pr_warn(
" : cnt1_reg: 0x%08x\n",
652 pr_warn(
" : cnt2_reg: 0x%08x\n",
660 static const char *
const name[] = {
678 unsigned int i,
j,
n;
680 pr_info(
"\n%s: %s - dma Audio channel status dump\n",
684 pr_info(
"%s: cmds + 0x%2x: %-15s: 0x%08x\n",
685 dev->
name, i * 4, name[i],
689 for (i = 0; i < 4;) {
691 pr_warn(
"cmds + 0x%2x: risc%d: ", j + i * 4, i);
692 i += cx25821_risc_decode(risc);
695 for (i = 0; i < (64 >> 2); i +=
n) {
699 pr_warn(
"ctrl + 0x%2x (0x%08x): iq %x: ",
701 n = cx25821_risc_decode(risc);
703 for (j = 1; j <
n; j++) {
705 pr_warn(
"ctrl + 0x%2x : iq %x: 0x%08x [ arg #%d ]\n",
706 4 * (i + j), i + j, risc, j);
710 pr_warn(
" : fifo: 0x%08x -> 0x%x\n",
712 pr_warn(
" : ctrl: 0x%08x -> 0x%x\n",
714 pr_warn(
" : ptr1_reg: 0x%08x\n",
716 pr_warn(
" : ptr2_reg: 0x%08x\n",
718 pr_warn(
" : cnt1_reg: 0x%08x\n",
720 pr_warn(
" : cnt2_reg: 0x%08x\n",
723 for (i = 0; i < 4; i++) {
725 pr_warn(
"instruction %d = 0x%x\n", i, risc);
730 pr_warn(
"\nread cdt loc=0x%x\n", risc);
731 for (i = 0; i < 8; i++) {
741 CX25821_INFO(
" PLL_A_POST_STAT_BIST = 0x%x\n\n", value);
746 CX25821_INFO(
" PLL_B_POST_STAT_BIST = 0x%x\n\n", value);
751 CX25821_INFO(
" PLL_C_POST_STAT_BIST = 0x%x\n\n", value);
756 CX25821_INFO(
" PLL_D_POST_STAT_BIST = 0x%x\n\n", value);
761 CX25821_INFO(
" AFE_AB_DIAG_CTRL (0x10900090) = 0x%x\n\n", value);
765 static void cx25821_shutdown(
struct cx25821_dev *dev)
798 if (channel_select <= 7 && channel_select >= 0) {
805 static void cx25821_set_vip_mode(
struct cx25821_dev *dev,
812 static void cx25821_initialize(
struct cx25821_dev *dev)
816 dprintk(1,
"%s()\n", __func__);
818 cx25821_shutdown(dev);
832 cx25821_registers_init(dev);
836 cx25821_set_vip_mode(dev, dev->
channels[i].sram_channels);
846 cx25821_set_vip_mode(dev, dev->
channels[i].sram_channels);
855 static int cx25821_get_resources(
struct cx25821_dev *dev)
861 pr_err(
"%s: can't get MMIO memory @ 0x%llx\n",
867 static void cx25821_dev_checkrevision(
struct cx25821_dev *dev)
871 pr_info(
"%s(): Hardware revision = 0x%02x\n",
875 static void cx25821_iounmap(
struct cx25821_dev *dev)
888 static int cx25821_dev_setup(
struct cx25821_dev *dev)
892 pr_info(
"\n***********************************\n");
894 pr_info(
"***********************************\n\n");
900 dev->
nr = ++cx25821_devcount;
907 if (dev->
pci->device != 0x8210) {
908 pr_info(
"%s(): Exiting. Incorrect Hardware device = 0x%02x\n",
909 __func__, dev->
pci->device);
912 pr_info(
"Athena Hardware device = 0x%02x\n", dev->
pci->device);
918 dev->
channels[i].sram_channels = &cx25821_sram_channels[i];
939 dev->
i2c_bus[0].i2c_period = (0x07 << 24);
941 if (cx25821_get_resources(dev) < 0) {
942 pr_err(
"%s: No more PCIe resources for subsystem: %04x:%04x\n",
943 dev->
name, dev->
pci->subsystem_vendor,
944 dev->
pci->subsystem_device);
954 CX25821_ERR(
"No PCI Memory resources, exiting!\n");
961 CX25821_ERR(
"ioremap failed, maybe increasing __VMALLOC_RESERVE in page.h\n");
962 cx25821_iounmap(dev);
968 pr_info(
"%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
969 dev->
name, dev->
pci->subsystem_vendor,
972 "insmod option" :
"autodetected");
975 cx25821_initialize(dev);
987 CX25821_ERR(
"%s(): Failed to initialize medusa!\n", __func__);
995 if (video_register_device
998 pr_err(
"%s(): Failed to register video adapter for IOCTL, so unregistering videoioctl device\n",
1002 cx25821_dev_checkrevision(dev);
1065 cx25821_iounmap(dev);
1071 unsigned int bpl,
unsigned int padding,
1083 for (line = 0; line < lines; line++) {
1126 struct scatterlist *sglist,
unsigned int top_offset,
1127 unsigned int bottom_offset,
unsigned int bpl,
1128 unsigned int padding,
unsigned int lines)
1136 if (
UNSET != top_offset)
1138 if (
UNSET != bottom_offset)
1157 if (
UNSET != top_offset) {
1158 rp = cx25821_risc_field(rp, sglist, top_offset, 0, bpl, padding,
1162 if (
UNSET != bottom_offset) {
1163 rp = cx25821_risc_field(rp, sglist, bottom_offset, 0x200, bpl,
1175 unsigned int offset,
u32 sync_line,
1176 unsigned int bpl,
unsigned int padding,
1177 unsigned int lines,
unsigned int lpi)
1180 unsigned int line,
todo, sol;
1188 for (line = 0; line < lines; line++) {
1194 if (lpi && line > 0 && !(line % lpi))
1239 unsigned int lines,
unsigned int lpi)
1250 instructions = 1 + (bpl * lines) /
PAGE_SIZE + lines;
1259 rp = cx25821_risc_field_audio(rp, sglist, 0,
NO_SYNC_LINE, bpl, 0,
1311 u32 mask[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
1315 if (pci_status == 0)
1319 if (pci_status & mask[i]) {
1321 sram_channels->int_stat);
1336 int len,
u32 bits,
u32 mask)
1342 for (i = 0; i < len; i++) {
1343 if (!(bits & (1 << i)))
1349 if (!(mask & (1 << i)))
1383 pr_info(
"pci enable failed!\n");
1385 goto fail_unregister_device;
1388 pr_info(
"Athena pci enable !\n");
1390 err = cx25821_dev_setup(dev);
1393 goto fail_unregister_device;
1395 goto fail_unregister_pci;
1401 pr_info(
"%s/0: found at %s, rev: %d, irq: %d, latency: %d, mmio: 0x%llx\n",
1406 if (!pci_dma_supported(pci_dev, 0xffffffff)) {
1407 pr_err(
"%s/0: Oops: no 32bit PCI DMA ???\n", dev->
name);
1423 pr_info(
"cx25821_initdev() can't get IRQ !\n");
1426 fail_unregister_pci:
1428 fail_unregister_device:
1436 static void __devexit cx25821_finidev(
struct pci_dev *pci_dev)
1438 struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
1441 cx25821_shutdown(dev);
1462 .subvendor = 0x14f1,
1463 .subdevice = 0x0920,
1468 .subvendor = 0x0000,
1469 .subdevice = 0x0000,
1477 static struct pci_driver cx25821_pci_driver = {
1479 .id_table = cx25821_pci_tbl,
1480 .probe = cx25821_initdev,
1487 static int __init cx25821_init(
void)
1489 pr_info(
"driver version %d.%d.%d loaded\n",
1493 return pci_register_driver(&cx25821_pci_driver);
1496 static void __exit cx25821_fini(
void)