2 * dm1105.c - driver for DVB cards based on SDMC DM1105 PCI chip
4 * Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/version.h>
23 #include <linux/i2c.h>
24 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/proc_fs.h>
28 #include <linux/pci.h>
29 #include <linux/dma-mapping.h>
30 #include <linux/input.h>
31 #include <media/ir-common.h>
35 #include "dvb_demux.h"
36 #include "dvb_frontend.h"
48 /* ----------------------------------------------- */
52 #ifndef PCI_VENDOR_ID_TRIGEM
53 #define PCI_VENDOR_ID_TRIGEM 0x109f
55 #ifndef PCI_DEVICE_ID_DM1105
56 #define PCI_DEVICE_ID_DM1105 0x036f
58 #ifndef PCI_DEVICE_ID_DW2002
59 #define PCI_DEVICE_ID_DW2002 0x2002
61 #ifndef PCI_DEVICE_ID_DW2004
62 #define PCI_DEVICE_ID_DW2004 0x2004
64 /* ----------------------------------------------- */
65 /* sdmc dm1105 registers */
68 #define DM1105_TSCTR 0x00
69 #define DM1105_DTALENTH 0x04
72 #define DM1105_GPIOVAL 0x08
73 #define DM1105_GPIOCTR 0x0c
75 /* PID serial number */
76 #define DM1105_PIDN 0x10
78 /* Odd-even secret key select */
79 #define DM1105_CWSEL 0x14
81 /* Host Command Interface */
82 #define DM1105_HOST_CTR 0x18
83 #define DM1105_HOST_AD 0x1c
86 #define DM1105_CR 0x30
87 #define DM1105_RST 0x34
88 #define DM1105_STADR 0x38
89 #define DM1105_RLEN 0x3c
90 #define DM1105_WRP 0x40
91 #define DM1105_INTCNT 0x44
92 #define DM1105_INTMAK 0x48
93 #define DM1105_INTSTS 0x4c
96 #define DM1105_ODD 0x50
97 #define DM1105_EVEN 0x58
100 #define DM1105_PID 0x60
103 #define DM1105_IRCTR 0x64
104 #define DM1105_IRMODE 0x68
105 #define DM1105_SYSTEMCODE 0x6c
106 #define DM1105_IRCODE 0x70
109 #define DM1105_ENCRYPT 0x74
110 #define DM1105_VER 0x7c
113 #define DM1105_I2CCTR 0x80
114 #define DM1105_I2CSTS 0x81
115 #define DM1105_I2CDAT 0x82
116 #define DM1105_I2C_RA 0x83
117 /* ----------------------------------------------- */
118 /* Interrupt Mask Bits */
120 #define INTMAK_TSIRQM 0x01
121 #define INTMAK_HIRQM 0x04
122 #define INTMAK_IRM 0x08
123 #define INTMAK_ALLMASK (INTMAK_TSIRQM | \
126 #define INTMAK_NONEMASK 0x00
128 /* Interrupt Status Bits */
129 #define INTSTS_TSIRQ 0x01
130 #define INTSTS_HIRQ 0x04
131 #define INTSTS_IR 0x08
133 /* IR Control Bits */
134 #define DM1105_IR_EN 0x01
135 #define DM1105_SYS_CHK 0x02
136 #define DM1105_REP_FLG 0x08
139 #define IIC_24C01_addr 0xa0
140 /* Max board count */
141 #define DM1105_MAX 0x04
143 #define DRIVER_NAME "dm1105"
145 #define DM1105_DMA_PACKETS 47
146 #define DM1105_DMA_PACKET_LENGTH (128*4)
147 #define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS)
149 /* GPIO's for LNB power control */
150 #define DM1105_LNB_MASK 0x00000000
151 #define DM1105_LNB_13V 0x00010100
152 #define DM1105_LNB_18V 0x00000100
155 module_param(ir_debug, int, 0644);
156 MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
158 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
160 static u16 ir_codes_dm1105_nec[128] = {
161 [0x0a] = KEY_Q, /*power*/
162 [0x0c] = KEY_M, /*mute*/
173 [0x1c] = KEY_PAGEUP, /*ch+*/
174 [0x0f] = KEY_PAGEDOWN, /*ch-*/
175 [0x1a] = KEY_O, /*vol+*/
176 [0x0e] = KEY_Z, /*vol-*/
177 [0x04] = KEY_R, /*rec*/
178 [0x09] = KEY_D, /*fav*/
179 [0x08] = KEY_BACKSPACE, /*rewind*/
180 [0x07] = KEY_A, /*fast*/
181 [0x0b] = KEY_P, /*pause*/
182 [0x02] = KEY_ESC, /*cancel*/
183 [0x03] = KEY_G, /*tab*/
184 [0x00] = KEY_UP, /*up*/
185 [0x1f] = KEY_ENTER, /*ok*/
186 [0x01] = KEY_DOWN, /*down*/
187 [0x05] = KEY_C, /*cap*/
188 [0x06] = KEY_S, /*stop*/
189 [0x40] = KEY_F, /*full*/
190 [0x1e] = KEY_W, /*tvmode*/
191 [0x1b] = KEY_B, /*recall*/
194 /* infrared remote control */
197 struct input_dev *input_dev;
199 struct tasklet_struct ir_tasklet;
205 struct pci_dev *pdev;
212 struct dmx_frontend hw_frontend;
213 struct dmx_frontend mem_frontend;
214 struct dmxdev dmxdev;
215 struct dvb_adapter dvb_adapter;
216 struct dvb_demux demux;
217 struct dvb_frontend *fe;
218 struct dvb_net dvbnet;
219 unsigned int full_ts_users;
222 struct i2c_adapter i2c_adap;
226 unsigned char *ts_buf;
229 unsigned int PacketErrorCount;
235 #define dm_io_mem(reg) ((unsigned long)(&dm1105dvb->io_mem[reg]))
237 static struct dm1105dvb *dm1105dvb_local;
239 static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap,
240 struct i2c_msg *msgs, int num)
242 struct dm1105dvb *dm1105dvb ;
244 int addr, rc, i, j, k, len, byte, data;
247 dm1105dvb = i2c_adap->algo_data;
248 for (i = 0; i < num; i++) {
249 outb(0x00, dm_io_mem(DM1105_I2CCTR));
250 if (msgs[i].flags & I2C_M_RD) {
252 addr = msgs[i].addr << 1;
254 outb(addr, dm_io_mem(DM1105_I2CDAT));
255 for (byte = 0; byte < msgs[i].len; byte++)
256 outb(0, dm_io_mem(DM1105_I2CDAT + byte + 1));
258 outb(0x81 + msgs[i].len, dm_io_mem(DM1105_I2CCTR));
259 for (j = 0; j < 55; j++) {
261 status = inb(dm_io_mem(DM1105_I2CSTS));
262 if ((status & 0xc0) == 0x40)
268 for (byte = 0; byte < msgs[i].len; byte++) {
269 rc = inb(dm_io_mem(DM1105_I2CDAT + byte + 1));
272 msgs[i].buf[byte] = rc;
275 if ((msgs[i].buf[0] == 0xf7) && (msgs[i].addr == 0x55)) {
276 /* prepaired for cx24116 firmware */
277 /* Write in small blocks */
278 len = msgs[i].len - 1;
281 outb(msgs[i].addr << 1, dm_io_mem(DM1105_I2CDAT));
282 outb(0xf7, dm_io_mem(DM1105_I2CDAT + 1));
283 for (byte = 0; byte < (len > 48 ? 48 : len); byte++) {
284 data = msgs[i].buf[k+byte];
285 outb(data, dm_io_mem(DM1105_I2CDAT + byte + 2));
287 outb(0x82 + (len > 48 ? 48 : len), dm_io_mem(DM1105_I2CCTR));
288 for (j = 0; j < 25; j++) {
290 status = inb(dm_io_mem(DM1105_I2CSTS));
291 if ((status & 0xc0) == 0x40)
303 outb(msgs[i].addr<<1, dm_io_mem(DM1105_I2CDAT));
304 for (byte = 0; byte < msgs[i].len; byte++) {
305 data = msgs[i].buf[byte];
306 outb(data, dm_io_mem(DM1105_I2CDAT + byte + 1));
308 outb(0x81 + msgs[i].len, dm_io_mem(DM1105_I2CCTR));
309 for (j = 0; j < 25; j++) {
311 status = inb(dm_io_mem(DM1105_I2CSTS));
312 if ((status & 0xc0) == 0x40)
326 static u32 functionality(struct i2c_adapter *adap)
331 static struct i2c_algorithm dm1105_algo = {
332 .master_xfer = dm1105_i2c_xfer,
333 .functionality = functionality,
336 static inline struct dm1105dvb *feed_to_dm1105dvb(struct dvb_demux_feed *feed)
338 return container_of(feed->demux, struct dm1105dvb, demux);
341 static inline struct dm1105dvb *frontend_to_dm1105dvb(struct dvb_frontend *fe)
343 return container_of(fe->dvb, struct dm1105dvb, dvb_adapter);
346 static int dm1105dvb_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
348 struct dm1105dvb *dm1105dvb = frontend_to_dm1105dvb(fe);
350 if (voltage == SEC_VOLTAGE_18) {
351 outl(DM1105_LNB_MASK, dm_io_mem(DM1105_GPIOCTR));
352 outl(DM1105_LNB_18V, dm_io_mem(DM1105_GPIOVAL));
354 /*LNB ON-13V by default!*/
355 outl(DM1105_LNB_MASK, dm_io_mem(DM1105_GPIOCTR));
356 outl(DM1105_LNB_13V, dm_io_mem(DM1105_GPIOVAL));
362 static void dm1105dvb_set_dma_addr(struct dm1105dvb *dm1105dvb)
364 outl(cpu_to_le32(dm1105dvb->dma_addr), dm_io_mem(DM1105_STADR));
367 static int __devinit dm1105dvb_dma_map(struct dm1105dvb *dm1105dvb)
369 dm1105dvb->ts_buf = pci_alloc_consistent(dm1105dvb->pdev, 6*DM1105_DMA_BYTES, &dm1105dvb->dma_addr);
371 return pci_dma_mapping_error(dm1105dvb->pdev, dm1105dvb->dma_addr);
374 static void dm1105dvb_dma_unmap(struct dm1105dvb *dm1105dvb)
376 pci_free_consistent(dm1105dvb->pdev, 6*DM1105_DMA_BYTES, dm1105dvb->ts_buf, dm1105dvb->dma_addr);
379 static void __devinit dm1105dvb_enable_irqs(struct dm1105dvb *dm1105dvb)
381 outb(INTMAK_ALLMASK, dm_io_mem(DM1105_INTMAK));
382 outb(1, dm_io_mem(DM1105_CR));
385 static void dm1105dvb_disable_irqs(struct dm1105dvb *dm1105dvb)
387 outb(INTMAK_IRM, dm_io_mem(DM1105_INTMAK));
388 outb(0, dm_io_mem(DM1105_CR));
391 static int dm1105dvb_start_feed(struct dvb_demux_feed *f)
393 struct dm1105dvb *dm1105dvb = feed_to_dm1105dvb(f);
395 if (dm1105dvb->full_ts_users++ == 0)
396 dm1105dvb_enable_irqs(dm1105dvb);
401 static int dm1105dvb_stop_feed(struct dvb_demux_feed *f)
403 struct dm1105dvb *dm1105dvb = feed_to_dm1105dvb(f);
405 if (--dm1105dvb->full_ts_users == 0)
406 dm1105dvb_disable_irqs(dm1105dvb);
412 static void dm1105_emit_key(unsigned long parm)
414 struct infrared *ir = (struct infrared *) parm;
415 u32 ircom = ir->ir_command;
419 data = (ircom >> 8) & 0x7f;
421 input_event(ir->input_dev, EV_MSC, MSC_RAW, (0x0000f8 << 16) | data);
422 input_event(ir->input_dev, EV_MSC, MSC_SCAN, data);
423 keycode = ir->key_map[data];
428 input_event(ir->input_dev, EV_KEY, keycode, 1);
429 input_sync(ir->input_dev);
430 input_event(ir->input_dev, EV_KEY, keycode, 0);
431 input_sync(ir->input_dev);
435 static irqreturn_t dm1105dvb_irq(int irq, void *dev_id)
437 struct dm1105dvb *dm1105dvb = dev_id;
439 unsigned int nbpackets;
444 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */
445 unsigned int intsts = inb(dm_io_mem(DM1105_INTSTS));
446 outb(intsts, dm_io_mem(DM1105_INTSTS));
450 case (INTSTS_TSIRQ | INTSTS_IR):
451 nextwrp = inl(dm_io_mem(DM1105_WRP)) -
452 inl(dm_io_mem(DM1105_STADR)) ;
453 oldwrp = dm1105dvb->wrp;
454 spin_lock(&dm1105dvb->lock);
455 if (!((dm1105dvb->ts_buf[oldwrp] == 0x47) &&
456 (dm1105dvb->ts_buf[oldwrp + 188] == 0x47) &&
457 (dm1105dvb->ts_buf[oldwrp + 188 * 2] == 0x47))) {
458 dm1105dvb->PacketErrorCount++;
459 /* bad packet found */
460 if ((dm1105dvb->PacketErrorCount >= 2) &&
461 (dm1105dvb->dmarst == 0)) {
462 outb(1, dm_io_mem(DM1105_RST));
464 dm1105dvb->PacketErrorCount = 0;
465 dm1105dvb->dmarst = 0;
466 spin_unlock(&dm1105dvb->lock);
470 if (nextwrp < oldwrp) {
471 piece = dm1105dvb->buffer_size - oldwrp;
472 memcpy(dm1105dvb->ts_buf + dm1105dvb->buffer_size, dm1105dvb->ts_buf, nextwrp);
473 nbpackets = (piece + nextwrp)/188;
475 nbpackets = (nextwrp - oldwrp)/188;
477 dvb_dmx_swfilter_packets(&dm1105dvb->demux, &dm1105dvb->ts_buf[oldwrp], nbpackets);
478 dm1105dvb->wrp = nextwrp;
479 spin_unlock(&dm1105dvb->lock);
482 command = inl(dm_io_mem(DM1105_IRCODE));
484 printk("dm1105: received byte 0x%04x\n", command);
486 dm1105dvb->ir.ir_command = command;
487 tasklet_schedule(&dm1105dvb->ir.ir_tasklet);
495 /* register with input layer */
496 static void input_register_keys(struct infrared *ir)
500 memset(ir->input_dev->keybit, 0, sizeof(ir->input_dev->keybit));
502 for (i = 0; i < ARRAY_SIZE(ir->key_map); i++)
503 set_bit(ir->key_map[i], ir->input_dev->keybit);
505 ir->input_dev->keycode = ir->key_map;
506 ir->input_dev->keycodesize = sizeof(ir->key_map[0]);
507 ir->input_dev->keycodemax = ARRAY_SIZE(ir->key_map);
510 int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)
512 struct input_dev *input_dev;
515 dm1105dvb_local = dm1105;
517 input_dev = input_allocate_device();
521 dm1105->ir.input_dev = input_dev;
522 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys),
523 "pci-%s/ir0", pci_name(dm1105->pdev));
525 input_dev->evbit[0] = BIT(EV_KEY);
526 input_dev->name = "DVB on-card IR receiver";
528 input_dev->phys = dm1105->ir.input_phys;
529 input_dev->id.bustype = BUS_PCI;
530 input_dev->id.version = 2;
531 if (dm1105->pdev->subsystem_vendor) {
532 input_dev->id.vendor = dm1105->pdev->subsystem_vendor;
533 input_dev->id.product = dm1105->pdev->subsystem_device;
535 input_dev->id.vendor = dm1105->pdev->vendor;
536 input_dev->id.product = dm1105->pdev->device;
538 input_dev->dev.parent = &dm1105->pdev->dev;
540 memcpy(dm1105->ir.key_map, ir_codes_dm1105_nec, sizeof dm1105->ir.key_map);
541 input_register_keys(&dm1105->ir);
542 err = input_register_device(input_dev);
544 input_free_device(input_dev);
548 tasklet_init(&dm1105->ir.ir_tasklet, dm1105_emit_key, (unsigned long) &dm1105->ir);
554 void __devexit dm1105_ir_exit(struct dm1105dvb *dm1105)
556 tasklet_kill(&dm1105->ir.ir_tasklet);
557 input_unregister_device(dm1105->ir.input_dev);
561 static int __devinit dm1105dvb_hw_init(struct dm1105dvb *dm1105dvb)
563 dm1105dvb_disable_irqs(dm1105dvb);
565 outb(0, dm_io_mem(DM1105_HOST_CTR));
568 outb(188, dm_io_mem(DM1105_DTALENTH));
569 /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/
570 outw(0xc10a, dm_io_mem(DM1105_TSCTR));
572 /* map DMA and set address */
573 dm1105dvb_dma_map(dm1105dvb);
574 dm1105dvb_set_dma_addr(dm1105dvb);
576 outl(5*DM1105_DMA_BYTES, dm_io_mem(DM1105_RLEN));
577 outb(47, dm_io_mem(DM1105_INTCNT));
579 /* IR NEC mode enable */
580 outb((DM1105_IR_EN | DM1105_SYS_CHK), dm_io_mem(DM1105_IRCTR));
581 outb(0, dm_io_mem(DM1105_IRMODE));
582 outw(0, dm_io_mem(DM1105_SYSTEMCODE));
587 static void dm1105dvb_hw_exit(struct dm1105dvb *dm1105dvb)
589 dm1105dvb_disable_irqs(dm1105dvb);
592 outb(0, dm_io_mem(DM1105_IRCTR));
593 outb(INTMAK_NONEMASK, dm_io_mem(DM1105_INTMAK));
595 dm1105dvb_dma_unmap(dm1105dvb);
598 static struct stv0299_config sharp_z0194a_config = {
599 .demod_address = 0x68,
600 .inittab = sharp_z0194a_inittab,
604 .lock_output = STV0299_LOCKOUTPUT_1,
605 .volt13_op0_op1 = STV0299_VOLT13_OP1,
607 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
610 static struct stv0288_config earda_config = {
611 .demod_address = 0x68,
615 static struct si21xx_config serit_config = {
616 .demod_address = 0x68,
621 static struct cx24116_config serit_sp2633_config = {
622 .demod_address = 0x55,
625 static int __devinit frontend_init(struct dm1105dvb *dm1105dvb)
629 switch (dm1105dvb->pdev->subsystem_device) {
630 case PCI_DEVICE_ID_DW2002:
631 dm1105dvb->fe = dvb_attach(
632 stv0299_attach, &sharp_z0194a_config,
633 &dm1105dvb->i2c_adap);
636 dm1105dvb->fe->ops.set_voltage =
637 dm1105dvb_set_voltage;
638 dvb_attach(dvb_pll_attach, dm1105dvb->fe, 0x60,
639 &dm1105dvb->i2c_adap, DVB_PLL_OPERA1);
642 if (!dm1105dvb->fe) {
643 dm1105dvb->fe = dvb_attach(
644 stv0288_attach, &earda_config,
645 &dm1105dvb->i2c_adap);
647 dm1105dvb->fe->ops.set_voltage =
648 dm1105dvb_set_voltage;
649 dvb_attach(stb6000_attach, dm1105dvb->fe, 0x61,
650 &dm1105dvb->i2c_adap);
654 if (!dm1105dvb->fe) {
655 dm1105dvb->fe = dvb_attach(
656 si21xx_attach, &serit_config,
657 &dm1105dvb->i2c_adap);
659 dm1105dvb->fe->ops.set_voltage =
660 dm1105dvb_set_voltage;
663 case PCI_DEVICE_ID_DW2004:
664 dm1105dvb->fe = dvb_attach(
665 cx24116_attach, &serit_sp2633_config,
666 &dm1105dvb->i2c_adap);
668 dm1105dvb->fe->ops.set_voltage = dm1105dvb_set_voltage;
672 if (!dm1105dvb->fe) {
673 dev_err(&dm1105dvb->pdev->dev, "could not attach frontend\n");
677 ret = dvb_register_frontend(&dm1105dvb->dvb_adapter, dm1105dvb->fe);
679 if (dm1105dvb->fe->ops.release)
680 dm1105dvb->fe->ops.release(dm1105dvb->fe);
681 dm1105dvb->fe = NULL;
688 static void __devinit dm1105dvb_read_mac(struct dm1105dvb *dm1105dvb, u8 *mac)
690 static u8 command[1] = { 0x28 };
692 struct i2c_msg msg[] = {
693 { .addr = IIC_24C01_addr >> 1, .flags = 0,
694 .buf = command, .len = 1 },
695 { .addr = IIC_24C01_addr >> 1, .flags = I2C_M_RD,
696 .buf = mac, .len = 6 },
699 dm1105_i2c_xfer(&dm1105dvb->i2c_adap, msg , 2);
700 dev_info(&dm1105dvb->pdev->dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
701 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
704 static int __devinit dm1105_probe(struct pci_dev *pdev,
705 const struct pci_device_id *ent)
707 struct dm1105dvb *dm1105dvb;
708 struct dvb_adapter *dvb_adapter;
709 struct dvb_demux *dvbdemux;
710 struct dmx_demux *dmx;
713 dm1105dvb = kzalloc(sizeof(struct dm1105dvb), GFP_KERNEL);
717 dm1105dvb->pdev = pdev;
718 dm1105dvb->buffer_size = 5 * DM1105_DMA_BYTES;
719 dm1105dvb->PacketErrorCount = 0;
720 dm1105dvb->dmarst = 0;
722 ret = pci_enable_device(pdev);
726 ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
728 goto err_pci_disable_device;
730 pci_set_master(pdev);
732 ret = pci_request_regions(pdev, DRIVER_NAME);
734 goto err_pci_disable_device;
736 dm1105dvb->io_mem = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
737 if (!dm1105dvb->io_mem) {
739 goto err_pci_release_regions;
742 spin_lock_init(&dm1105dvb->lock);
743 pci_set_drvdata(pdev, dm1105dvb);
745 ret = request_irq(pdev->irq, dm1105dvb_irq, IRQF_SHARED, DRIVER_NAME, dm1105dvb);
747 goto err_pci_iounmap;
749 ret = dm1105dvb_hw_init(dm1105dvb);
754 i2c_set_adapdata(&dm1105dvb->i2c_adap, dm1105dvb);
755 strcpy(dm1105dvb->i2c_adap.name, DRIVER_NAME);
756 dm1105dvb->i2c_adap.owner = THIS_MODULE;
757 dm1105dvb->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
758 dm1105dvb->i2c_adap.dev.parent = &pdev->dev;
759 dm1105dvb->i2c_adap.algo = &dm1105_algo;
760 dm1105dvb->i2c_adap.algo_data = dm1105dvb;
761 ret = i2c_add_adapter(&dm1105dvb->i2c_adap);
764 goto err_dm1105dvb_hw_exit;
767 ret = dvb_register_adapter(&dm1105dvb->dvb_adapter, DRIVER_NAME,
768 THIS_MODULE, &pdev->dev, adapter_nr);
770 goto err_i2c_del_adapter;
772 dvb_adapter = &dm1105dvb->dvb_adapter;
774 dm1105dvb_read_mac(dm1105dvb, dvb_adapter->proposed_mac);
776 dvbdemux = &dm1105dvb->demux;
777 dvbdemux->filternum = 256;
778 dvbdemux->feednum = 256;
779 dvbdemux->start_feed = dm1105dvb_start_feed;
780 dvbdemux->stop_feed = dm1105dvb_stop_feed;
781 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
782 DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
783 ret = dvb_dmx_init(dvbdemux);
785 goto err_dvb_unregister_adapter;
787 dmx = &dvbdemux->dmx;
788 dm1105dvb->dmxdev.filternum = 256;
789 dm1105dvb->dmxdev.demux = dmx;
790 dm1105dvb->dmxdev.capabilities = 0;
792 ret = dvb_dmxdev_init(&dm1105dvb->dmxdev, dvb_adapter);
794 goto err_dvb_dmx_release;
796 dm1105dvb->hw_frontend.source = DMX_FRONTEND_0;
798 ret = dmx->add_frontend(dmx, &dm1105dvb->hw_frontend);
800 goto err_dvb_dmxdev_release;
802 dm1105dvb->mem_frontend.source = DMX_MEMORY_FE;
804 ret = dmx->add_frontend(dmx, &dm1105dvb->mem_frontend);
806 goto err_remove_hw_frontend;
808 ret = dmx->connect_frontend(dmx, &dm1105dvb->hw_frontend);
810 goto err_remove_mem_frontend;
812 ret = frontend_init(dm1105dvb);
814 goto err_disconnect_frontend;
816 dvb_net_init(dvb_adapter, &dm1105dvb->dvbnet, dmx);
817 dm1105_ir_init(dm1105dvb);
821 err_disconnect_frontend:
822 dmx->disconnect_frontend(dmx);
823 err_remove_mem_frontend:
824 dmx->remove_frontend(dmx, &dm1105dvb->mem_frontend);
825 err_remove_hw_frontend:
826 dmx->remove_frontend(dmx, &dm1105dvb->hw_frontend);
827 err_dvb_dmxdev_release:
828 dvb_dmxdev_release(&dm1105dvb->dmxdev);
830 dvb_dmx_release(dvbdemux);
831 err_dvb_unregister_adapter:
832 dvb_unregister_adapter(dvb_adapter);
834 i2c_del_adapter(&dm1105dvb->i2c_adap);
835 err_dm1105dvb_hw_exit:
836 dm1105dvb_hw_exit(dm1105dvb);
838 free_irq(pdev->irq, dm1105dvb);
840 pci_iounmap(pdev, dm1105dvb->io_mem);
841 err_pci_release_regions:
842 pci_release_regions(pdev);
843 err_pci_disable_device:
844 pci_disable_device(pdev);
846 pci_set_drvdata(pdev, NULL);
851 static void __devexit dm1105_remove(struct pci_dev *pdev)
853 struct dm1105dvb *dm1105dvb = pci_get_drvdata(pdev);
854 struct dvb_adapter *dvb_adapter = &dm1105dvb->dvb_adapter;
855 struct dvb_demux *dvbdemux = &dm1105dvb->demux;
856 struct dmx_demux *dmx = &dvbdemux->dmx;
858 dm1105_ir_exit(dm1105dvb);
860 dvb_net_release(&dm1105dvb->dvbnet);
862 dvb_unregister_frontend(dm1105dvb->fe);
864 dmx->disconnect_frontend(dmx);
865 dmx->remove_frontend(dmx, &dm1105dvb->mem_frontend);
866 dmx->remove_frontend(dmx, &dm1105dvb->hw_frontend);
867 dvb_dmxdev_release(&dm1105dvb->dmxdev);
868 dvb_dmx_release(dvbdemux);
869 dvb_unregister_adapter(dvb_adapter);
870 if (&dm1105dvb->i2c_adap)
871 i2c_del_adapter(&dm1105dvb->i2c_adap);
873 dm1105dvb_hw_exit(dm1105dvb);
874 synchronize_irq(pdev->irq);
875 free_irq(pdev->irq, dm1105dvb);
876 pci_iounmap(pdev, dm1105dvb->io_mem);
877 pci_release_regions(pdev);
878 pci_disable_device(pdev);
879 pci_set_drvdata(pdev, NULL);
883 static struct pci_device_id dm1105_id_table[] __devinitdata = {
885 .vendor = PCI_VENDOR_ID_TRIGEM,
886 .device = PCI_DEVICE_ID_DM1105,
887 .subvendor = PCI_ANY_ID,
888 .subdevice = PCI_DEVICE_ID_DW2002,
890 .vendor = PCI_VENDOR_ID_TRIGEM,
891 .device = PCI_DEVICE_ID_DM1105,
892 .subvendor = PCI_ANY_ID,
893 .subdevice = PCI_DEVICE_ID_DW2004,
899 MODULE_DEVICE_TABLE(pci, dm1105_id_table);
901 static struct pci_driver dm1105_driver = {
903 .id_table = dm1105_id_table,
904 .probe = dm1105_probe,
905 .remove = __devexit_p(dm1105_remove),
908 static int __init dm1105_init(void)
910 return pci_register_driver(&dm1105_driver);
913 static void __exit dm1105_exit(void)
915 pci_unregister_driver(&dm1105_driver);
918 module_init(dm1105_init);
919 module_exit(dm1105_exit);
921 MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
922 MODULE_DESCRIPTION("SDMC DM1105 DVB driver");
923 MODULE_LICENSE("GPL");