22 #include <linux/i2c.h>
26 #include <linux/kernel.h>
27 #include <linux/module.h>
29 #include <linux/pci.h>
31 #include <linux/slab.h>
50 #define MODULE_NAME "dm1105"
54 #define DM1105_BOARD_NOAUTO UNSET
55 #define DM1105_BOARD_UNKNOWN 0
56 #define DM1105_BOARD_DVBWORLD_2002 1
57 #define DM1105_BOARD_DVBWORLD_2004 2
58 #define DM1105_BOARD_AXESS_DM05 3
59 #define DM1105_BOARD_UNBRANDED_I2C_ON_GPIO 4
65 #ifndef PCI_VENDOR_ID_TRIGEM
66 #define PCI_VENDOR_ID_TRIGEM 0x109f
68 #ifndef PCI_VENDOR_ID_AXESS
69 #define PCI_VENDOR_ID_AXESS 0x195d
71 #ifndef PCI_DEVICE_ID_DM1105
72 #define PCI_DEVICE_ID_DM1105 0x036f
74 #ifndef PCI_DEVICE_ID_DW2002
75 #define PCI_DEVICE_ID_DW2002 0x2002
77 #ifndef PCI_DEVICE_ID_DW2004
78 #define PCI_DEVICE_ID_DW2004 0x2004
80 #ifndef PCI_DEVICE_ID_DM05
81 #define PCI_DEVICE_ID_DM05 0x1105
87 #define DM1105_TSCTR 0x00
88 #define DM1105_DTALENTH 0x04
91 #define DM1105_GPIOVAL 0x08
92 #define DM1105_GPIOCTR 0x0c
95 #define DM1105_PIDN 0x10
98 #define DM1105_CWSEL 0x14
101 #define DM1105_HOST_CTR 0x18
102 #define DM1105_HOST_AD 0x1c
105 #define DM1105_CR 0x30
106 #define DM1105_RST 0x34
107 #define DM1105_STADR 0x38
108 #define DM1105_RLEN 0x3c
109 #define DM1105_WRP 0x40
110 #define DM1105_INTCNT 0x44
111 #define DM1105_INTMAK 0x48
112 #define DM1105_INTSTS 0x4c
115 #define DM1105_ODD 0x50
116 #define DM1105_EVEN 0x58
119 #define DM1105_PID 0x60
122 #define DM1105_IRCTR 0x64
123 #define DM1105_IRMODE 0x68
124 #define DM1105_SYSTEMCODE 0x6c
125 #define DM1105_IRCODE 0x70
128 #define DM1105_ENCRYPT 0x74
129 #define DM1105_VER 0x7c
132 #define DM1105_I2CCTR 0x80
133 #define DM1105_I2CSTS 0x81
134 #define DM1105_I2CDAT 0x82
135 #define DM1105_I2C_RA 0x83
139 #define INTMAK_TSIRQM 0x01
140 #define INTMAK_HIRQM 0x04
141 #define INTMAK_IRM 0x08
142 #define INTMAK_ALLMASK (INTMAK_TSIRQM | \
145 #define INTMAK_NONEMASK 0x00
148 #define INTSTS_TSIRQ 0x01
149 #define INTSTS_HIRQ 0x04
150 #define INTSTS_IR 0x08
153 #define DM1105_IR_EN 0x01
154 #define DM1105_SYS_CHK 0x02
155 #define DM1105_REP_FLG 0x08
158 #define IIC_24C01_addr 0xa0
160 #define DM1105_MAX 0x04
162 #define DRIVER_NAME "dm1105"
163 #define DM1105_I2C_GPIO_NAME "dm1105-gpio"
165 #define DM1105_DMA_PACKETS 47
166 #define DM1105_DMA_PACKET_LENGTH (128*4)
167 #define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS)
170 #define GPIO08 (1 << 8)
171 #define GPIO13 (1 << 13)
172 #define GPIO14 (1 << 14)
173 #define GPIO15 (1 << 15)
174 #define GPIO16 (1 << 16)
175 #define GPIO17 (1 << 17)
176 #define GPIO_ALL 0x03ffff
179 #define DM1105_LNB_MASK (GPIO_ALL & ~(GPIO14 | GPIO13))
180 #define DM1105_LNB_OFF GPIO17
181 #define DM1105_LNB_13V (GPIO16 | GPIO08)
182 #define DM1105_LNB_18V GPIO08
185 #define DM05_LNB_MASK (GPIO_ALL & ~(GPIO14 | GPIO13))
186 #define DM05_LNB_OFF GPIO17
187 #define DM05_LNB_13V GPIO17
188 #define DM05_LNB_18V (GPIO17 | GPIO16)
191 #define UNBR_LNB_MASK (GPIO17 | GPIO16)
192 #define UNBR_LNB_OFF 0
193 #define UNBR_LNB_13V GPIO17
194 #define UNBR_LNB_18V (GPIO17 | GPIO16)
196 static unsigned int card[] = {[0 ... 3] =
UNSET };
204 static unsigned int dm1105_devcount;
224 .name =
"UNKNOWN/GENERIC",
233 .name =
"DVBWorld PCI 2002",
242 .name =
"DVBWorld PCI 2004",
251 .name =
"Axess/EasyTv DM05",
260 .name =
"Unbranded DM1105 with i2c on GPIOs",
296 static void dm1105_card_list(
struct pci_dev *pci)
303 "dm1105: Your board has no valid PCI Subsystem ID\n"
304 "dm1105: and thus can't be autodetected\n"
305 "dm1105: Please pass card=<n> insmod option to\n"
306 "dm1105: workaround that. Redirect complaints to\n"
307 "dm1105: the vendor of the TV card. Best regards,\n"
311 "dm1105: Your board isn't known (yet) to the driver.\n"
312 "dm1105: You can try to pick one of the existing\n"
313 "dm1105: card configs via card=<n> insmod option.\n"
314 "dm1105: Updating to the latest version might help\n"
315 "dm1105: as well.\n");
317 printk(
KERN_ERR "Here is a list of valid choices for the card=<n> "
319 for (i = 0; i <
ARRAY_SIZE(dm1105_boards); i++)
321 i, dm1105_boards[i].
name);
373 #define dm_io_mem(reg) ((unsigned long)(&dev->io_mem[reg]))
375 #define dm_readb(reg) inb(dm_io_mem(reg))
376 #define dm_writeb(reg, value) outb((value), (dm_io_mem(reg)))
378 #define dm_readw(reg) inw(dm_io_mem(reg))
379 #define dm_writew(reg, value) outw((value), (dm_io_mem(reg)))
381 #define dm_readl(reg) inl(dm_io_mem(reg))
382 #define dm_writel(reg, value) outl((value), (dm_io_mem(reg)))
384 #define dm_andorl(reg, mask, value) \
385 outl((inl(dm_io_mem(reg)) & ~(mask)) |\
386 ((value) & (mask)), (dm_io_mem(reg)))
388 #define dm_setl(reg, bit) dm_andorl((reg), (bit), (bit))
389 #define dm_clearl(reg, bit) dm_andorl((reg), (bit), 0)
397 if (mask & 0xfffc0000)
400 if (mask & 0x0003ffff)
407 if (mask & 0xfffc0000)
410 if (mask & 0x0003ffff)
417 if (mask & 0xfffc0000)
420 if (mask & 0x0003ffff)
427 if (mask & 0xfffc0000)
430 if (mask & 0x0003ffff)
436 static void dm1105_gpio_enable(
struct dm1105_dev *dev,
u32 mask,
int asoutput)
438 if (mask & 0xfffc0000)
441 if ((mask & 0x0003ffff) && asoutput)
443 else if ((mask & 0x0003ffff) && !asoutput)
451 dm1105_gpio_enable(dev, line, 0);
453 dm1105_gpio_enable(dev, line, 1);
454 dm1105_gpio_clear(dev, line);
458 static void dm1105_setsda(
void *
data,
int state)
465 static void dm1105_setscl(
void *
data,
int state)
472 static int dm1105_getsda(
void *
data)
480 static int dm1105_getscl(
void *
data)
497 for (i = 0; i < num; i++) {
501 addr = msgs[
i].
addr << 1;
504 for (byte = 0; byte < msgs[
i].
len; byte++)
508 for (j = 0; j < 55; j++) {
511 if ((status & 0xc0) == 0x40)
517 for (byte = 0; byte < msgs[
i].
len; byte++) {
523 }
else if ((msgs[i].
buf[0] == 0xf7) && (msgs[i].addr == 0x55)) {
526 len = msgs[
i].
len - 1;
536 for (j = 0; j < 25; j++) {
539 if ((status & 0xc0) == 0x40)
552 for (byte = 0; byte < msgs[
i].
len; byte++) {
557 for (j = 0; j < 25; j++) {
560 if ((status & 0xc0) == 0x40)
579 .master_xfer = dm1105_i2c_xfer,
595 struct dm1105_dev *dev = frontend_to_dm1105_dev(fe);
597 dm1105_gpio_enable(dev, dm1105_boards[dev->
boardnr].
lnb.mask, 1);
599 dm1105_gpio_andor(dev,
603 dm1105_gpio_andor(dev,
607 dm1105_gpio_andor(dev,
614 static void dm1105_set_dma_addr(
struct dm1105_dev *dev)
628 static void dm1105_dma_unmap(
struct dm1105_dev *dev)
636 static void dm1105_enable_irqs(
struct dm1105_dev *dev)
642 static void dm1105_disable_irqs(
struct dm1105_dev *dev)
650 struct dm1105_dev *dev = feed_to_dm1105_dev(f);
653 dm1105_enable_irqs(dev);
660 struct dm1105_dev *dev = feed_to_dm1105_dev(f);
663 dm1105_disable_irqs(dev);
678 data = (ircom >> 8) & 0x7f;
684 static void dm1105_dmx_buffer(
struct work_struct *work)
687 unsigned int nbpackets;
691 if (!((dev->
ts_buf[oldwrp] == 0x47) &&
692 (dev->
ts_buf[oldwrp + 188] == 0x47) &&
693 (dev->
ts_buf[oldwrp + 188 * 2] == 0x47))) {
706 if (nextwrp < oldwrp) {
708 nbpackets = ((dev->
buffer_size - oldwrp) + nextwrp) / 188;
710 nbpackets = (nextwrp - oldwrp) / 188;
748 snprintf(dm1105->
ir.input_phys,
sizeof(dm1105->
ir.input_phys),
749 "pci-%s/ir0", pci_name(dm1105->
pdev));
758 if (dm1105->
pdev->subsystem_vendor) {
765 dev->
dev.parent = &dm1105->
pdev->dev;
775 dm1105->
ir.dev =
dev;
786 dm1105_disable_irqs(dev);
797 dm1105_set_dma_addr(dev);
810 static void dm1105_hw_exit(
struct dm1105_dev *dev)
812 dm1105_disable_irqs(dev);
818 dm1105_dma_unmap(dev);
822 .demod_address = 0x68,
823 .inittab = sharp_z0194a_inittab,
830 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
834 .demod_address = 0x68,
839 .demod_address = 0x68,
845 .demod_address = 0x55,
849 .demod_address = 0x68,
858 dm1105_gpio_enable(dev,
GPIO15, 1);
859 dm1105_gpio_clear(dev,
GPIO15);
861 dm1105_gpio_set(dev,
GPIO15);
867 dev->
fe->ops.set_voltage = dm1105_set_voltage;
877 dev->
fe->ops.set_voltage = dm1105_set_voltage;
887 dev->
fe->ops.set_voltage = dm1105_set_voltage;
894 dev->
fe->ops.set_voltage = dm1105_set_voltage;
902 dev->
fe->ops.set_voltage = dm1105_set_voltage;
912 dev->
fe->ops.set_voltage = dm1105_set_voltage;
922 dev->
fe->ops.set_voltage = dm1105_set_voltage;
932 dev->
fe->ops.set_voltage = dm1105_set_voltage;
937 dev_err(&dev->
pdev->dev,
"could not attach frontend\n");
943 if (dev->
fe->ops.release)
944 dev->
fe->ops.release(dev->
fe);
970 dm1105_i2c_xfer(&dev->
i2c_adap, msg , 2);
989 dev->
nr = dm1105_devcount;
1003 dm1105_card_list(pdev);
1018 goto err_pci_disable_device;
1024 goto err_pci_disable_device;
1029 goto err_pci_release_regions;
1033 pci_set_drvdata(pdev, dev);
1035 ret = dm1105_hw_init(dev);
1037 goto err_pci_iounmap;
1040 i2c_set_adapdata(&dev->
i2c_adap, dev);
1049 goto err_dm1105_hw_exit;
1057 dev->
i2c_bit.setsda = dm1105_setsda;
1058 dev->
i2c_bit.setscl = dm1105_setscl;
1059 dev->
i2c_bit.getsda = dm1105_getsda;
1060 dev->
i2c_bit.getscl = dm1105_getscl;
1065 dm1105_setsda(dev, 1);
1066 dm1105_setscl(dev, 1);
1070 goto err_i2c_del_adapter;
1076 goto err_i2c_del_adapters;
1082 dvbdemux = &dev->
demux;
1091 goto err_dvb_unregister_adapter;
1093 dmx = &dvbdemux->
dmx;
1094 dev->
dmxdev.filternum = 256;
1096 dev->
dmxdev.capabilities = 0;
1100 goto err_dvb_dmx_release;
1106 goto err_dvb_dmxdev_release;
1112 goto err_remove_hw_frontend;
1116 goto err_remove_mem_frontend;
1120 goto err_disconnect_frontend;
1122 ret = frontend_init(dev);
1145 err_disconnect_frontend:
1147 err_remove_mem_frontend:
1149 err_remove_hw_frontend:
1151 err_dvb_dmxdev_release:
1153 err_dvb_dmx_release:
1155 err_dvb_unregister_adapter:
1157 err_i2c_del_adapters:
1159 err_i2c_del_adapter:
1162 dm1105_hw_exit(dev);
1165 err_pci_release_regions:
1167 err_pci_disable_device:
1170 pci_set_drvdata(pdev,
NULL);
1177 struct dm1105_dev *dev = pci_get_drvdata(pdev);
1178 struct dvb_adapter *dvb_adapter = &dev->
dvb_adapter;
1197 dm1105_hw_exit(dev);
1203 pci_set_drvdata(pdev,
NULL);
1228 .id_table = dm1105_id_table,
1229 .probe = dm1105_probe,
1233 static int __init dm1105_init(
void)
1235 return pci_register_driver(&dm1105_driver);
1238 static void __exit dm1105_exit(
void)