26 #include <linux/i2c.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/pci.h>
34 #include <linux/slab.h>
46 #define DRIVER_NAME "pluto2"
48 #define REG_PIDn(n) ((n) << 2)
49 #define REG_PCAR 0x0020
50 #define REG_TSCR 0x0024
51 #define REG_MISC 0x0028
52 #define REG_MMAC 0x002c
53 #define REG_IMAC 0x0030
54 #define REG_LMAC 0x0034
55 #define REG_SPID 0x0038
56 #define REG_SLCS 0x003c
58 #define PID0_NOFIL (0x0001 << 16)
59 #define PIDn_ENP (0x0001 << 15)
60 #define PID0_END (0x0001 << 14)
61 #define PID0_AFIL (0x0001 << 13)
62 #define PIDn_PID (0x1fff << 0)
64 #define TSCR_NBPACKETS (0x00ff << 24)
65 #define TSCR_DEM (0x0001 << 17)
66 #define TSCR_DE (0x0001 << 16)
67 #define TSCR_RSTN (0x0001 << 15)
68 #define TSCR_MSKO (0x0001 << 14)
69 #define TSCR_MSKA (0x0001 << 13)
70 #define TSCR_MSKL (0x0001 << 12)
71 #define TSCR_OVR (0x0001 << 11)
72 #define TSCR_AFUL (0x0001 << 10)
73 #define TSCR_LOCK (0x0001 << 9)
74 #define TSCR_IACK (0x0001 << 8)
75 #define TSCR_ADEF (0x007f << 0)
77 #define MISC_DVR (0x0fff << 4)
78 #define MISC_ALED (0x0001 << 3)
79 #define MISC_FRST (0x0001 << 2)
80 #define MISC_LED1 (0x0001 << 1)
81 #define MISC_LED0 (0x0001 << 0)
83 #define SPID_SPIDR (0x00ff << 0)
85 #define SLCS_SCL (0x0001 << 7)
86 #define SLCS_SDA (0x0001 << 6)
87 #define SLCS_CSN (0x0001 << 2)
88 #define SLCS_OVR (0x0001 << 1)
89 #define SLCS_SWC (0x0001 << 0)
91 #define TS_DMA_PACKETS (8)
92 #define TS_DMA_BYTES (188 * TS_DMA_PACKETS)
94 #define I2C_ADDR_TDA10046 0x10
95 #define I2C_ADDR_TUA6034 0xc2
163 pluto_writereg(pluto,
REG_TSCR, val);
166 static void pluto_setsda(
void *
data,
int state)
176 static void pluto_setscl(
void *data,
int state)
178 struct pluto *pluto =
data;
187 if ((state) && (pluto->
i2cbug == 0)) {
190 if ((!state) && (pluto->
i2cbug == 1))
191 pluto_setsda(pluto, 1);
196 static int pluto_getsda(
void *data)
198 struct pluto *pluto =
data;
203 static int pluto_getscl(
void *data)
205 struct pluto *pluto =
data;
210 static void pluto_reset_frontend(
struct pluto *pluto,
int reenable)
216 pluto_writereg(pluto,
REG_MISC, val);
220 pluto_writereg(pluto,
REG_MISC, val);
224 static void pluto_reset_ts(
struct pluto *pluto,
int reenable)
230 pluto_write_tscr(pluto, val);
234 pluto_write_tscr(pluto, val);
238 static void pluto_set_dma_addr(
struct pluto *pluto)
243 static int __devinit pluto_dma_map(
struct pluto *pluto)
248 return pci_dma_mapping_error(pluto->
pdev, pluto->
dma_addr);
251 static void pluto_dma_unmap(
struct pluto *pluto)
259 struct pluto *pluto = feed_to_pluto(f);
262 if (pluto->
users++ == 0)
275 struct pluto *pluto = feed_to_pluto(f);
278 if (--pluto->
users == 0)
289 static void pluto_dma_end(
struct pluto *pluto,
unsigned int nbpackets)
293 pci_dma_sync_single_for_cpu(pluto->
pdev, pluto->
dma_addr,
308 while (pluto->
dma_buf[i] == 0x47)
312 pluto_reset_ts(pluto, 1);
313 dev_printk(
KERN_DEBUG, &pluto->
pdev->dev,
"resetting TS because of invalid packet counter\n");
324 pluto_set_dma_addr(pluto);
327 pci_dma_sync_single_for_device(pluto->
pdev, pluto->
dma_addr,
333 struct pluto *pluto =
dev_id;
337 tscr = pluto_readreg(pluto,
REG_TSCR);
341 if (tscr == 0xffffffff) {
342 if (pluto->
dead == 0)
343 dev_err(&pluto->
pdev->dev,
"card has hung or been ejected.\n");
358 pluto_reset_ts(pluto, 1);
361 }
else if (tscr & TSCR_OVR) {
366 pluto_write_tscr(pluto, tscr |
TSCR_IACK);
371 static void __devinit pluto_enable_irqs(
struct pluto *pluto)
382 pluto_write_tscr(pluto, val);
385 static void pluto_disable_irqs(
struct pluto *pluto)
394 pluto_write_tscr(pluto, val);
397 static int __devinit pluto_hw_init(
struct pluto *pluto)
399 pluto_reset_frontend(pluto, 1);
405 #ifdef __LITTLE_ENDIAN
411 pluto_dma_map(pluto);
412 pluto_set_dma_addr(pluto);
415 pluto_enable_irqs(pluto);
418 pluto_reset_ts(pluto, 1);
423 static void pluto_hw_exit(
struct pluto *pluto)
426 pluto_disable_irqs(pluto);
428 pluto_reset_ts(pluto, 0);
434 pluto_dma_unmap(pluto);
436 pluto_reset_frontend(pluto, 0);
441 if (denominator == 0)
451 struct pluto *pluto = frontend_to_pluto(fe);
463 buf[0] = (div >> 8) & 0x7f;
464 buf[1] = (div >> 0) & 0xff;
489 if (fe->
ops.i2c_gate_ctrl)
490 fe->
ops.i2c_gate_ctrl(fe, 1);
500 static int pluto2_request_firmware(
struct dvb_frontend *fe,
503 struct pluto *pluto = frontend_to_pluto(fe);
515 .request_firmware = pluto2_request_firmware,
518 static int __devinit frontend_init(
struct pluto *pluto)
524 dev_err(&pluto->
pdev->dev,
"could not attach frontend\n");
527 pluto->
fe->ops.tuner_ops.set_params = lg_tdtpe001p_tuner_set_params;
531 if (pluto->
fe->ops.release)
532 pluto->
fe->ops.release(pluto->
fe);
539 static void __devinit pluto_read_rev(
struct pluto *pluto)
543 (val >> 12) & 0x0f, (val >> 4) & 0xff);
546 static void __devinit pluto_read_mac(
struct pluto *pluto,
u8 *
mac)
549 mac[0] = (val >> 8) & 0xff;
550 mac[1] = (val >> 0) & 0xff;
552 val = pluto_readreg(pluto,
REG_IMAC);
553 mac[2] = (val >> 8) & 0xff;
554 mac[3] = (val >> 0) & 0xff;
556 val = pluto_readreg(pluto,
REG_LMAC);
557 mac[4] = (val >> 8) & 0xff;
558 mac[5] = (val >> 0) & 0xff;
563 static int __devinit pluto_read_serial(
struct pluto *pluto)
569 cis = pci_iomap(pdev, 1, 0);
575 for (i = 0xe0; i < 0x100; i += 4) {
577 for (j = 0; j < 32; j += 8) {
578 if ((val & 0xff) == 0xff)
600 pluto = kzalloc(
sizeof(
struct pluto),
GFP_KERNEL);
611 pci_write_config_dword(pdev, 0x6c, 0x8000);
615 goto err_pci_disable_device;
621 goto err_pci_disable_device;
623 pluto->
io_mem = pci_iomap(pdev, 0, 0x40);
626 goto err_pci_release_regions;
629 pci_set_drvdata(pdev, pluto);
633 goto err_pci_iounmap;
635 ret = pluto_hw_init(pluto);
640 i2c_set_adapdata(&pluto->
i2c_adap, pluto);
646 pluto->
i2c_bit.setsda = pluto_setsda;
647 pluto->
i2c_bit.setscl = pluto_setscl;
648 pluto->
i2c_bit.getsda = pluto_getsda;
649 pluto->
i2c_bit.getscl = pluto_getscl;
654 pluto_setsda(pluto, 1);
655 pluto_setscl(pluto, 1);
659 goto err_pluto_hw_exit;
665 goto err_i2c_del_adapter;
669 pluto_read_rev(pluto);
670 pluto_read_serial(pluto);
673 dvbdemux = &pluto->
demux;
682 goto err_dvb_unregister_adapter;
684 dmx = &dvbdemux->
dmx;
689 pluto->
dmxdev.demux = dmx;
693 goto err_dvb_dmx_release;
697 goto err_dvb_dmxdev_release;
701 goto err_remove_hw_frontend;
705 goto err_remove_mem_frontend;
707 ret = frontend_init(pluto);
709 goto err_disconnect_frontend;
715 err_disconnect_frontend:
717 err_remove_mem_frontend:
719 err_remove_hw_frontend:
721 err_dvb_dmxdev_release:
725 err_dvb_unregister_adapter:
730 pluto_hw_exit(pluto);
735 err_pci_release_regions:
737 err_pci_disable_device:
740 pci_set_drvdata(pdev,
NULL);
747 struct pluto *pluto = pci_get_drvdata(pdev);
748 struct dvb_adapter *dvb_adapter = &pluto->
dvb_adapter;
764 pluto_hw_exit(pluto);
769 pci_set_drvdata(pdev,
NULL);
773 #ifndef PCI_VENDOR_ID_SCM
774 #define PCI_VENDOR_ID_SCM 0x0432
776 #ifndef PCI_DEVICE_ID_PLUTO2
777 #define PCI_DEVICE_ID_PLUTO2 0x0001
780 static struct pci_device_id pluto2_id_table[] __devinitdata = {
795 .id_table = pluto2_id_table,
796 .probe = pluto2_probe,
800 static int __init pluto2_init(
void)
802 return pci_register_driver(&pluto2_driver);
805 static void __exit pluto2_exit(
void)