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/i2c.h>
23 #include <linux/init.h>
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/proc_fs.h>
27 #include <linux/pci.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/slab.h>
30 #include <media/rc-core.h>
34 #include "dvb_demux.h"
35 #include "dvb_frontend.h"
48 #define MODULE_NAME "dm1105"
52 #define DM1105_BOARD_NOAUTO UNSET
53 #define DM1105_BOARD_UNKNOWN 0
54 #define DM1105_BOARD_DVBWORLD_2002 1
55 #define DM1105_BOARD_DVBWORLD_2004 2
56 #define DM1105_BOARD_AXESS_DM05 3
58 /* ----------------------------------------------- */
62 #ifndef PCI_VENDOR_ID_TRIGEM
63 #define PCI_VENDOR_ID_TRIGEM 0x109f
65 #ifndef PCI_VENDOR_ID_AXESS
66 #define PCI_VENDOR_ID_AXESS 0x195d
68 #ifndef PCI_DEVICE_ID_DM1105
69 #define PCI_DEVICE_ID_DM1105 0x036f
71 #ifndef PCI_DEVICE_ID_DW2002
72 #define PCI_DEVICE_ID_DW2002 0x2002
74 #ifndef PCI_DEVICE_ID_DW2004
75 #define PCI_DEVICE_ID_DW2004 0x2004
77 #ifndef PCI_DEVICE_ID_DM05
78 #define PCI_DEVICE_ID_DM05 0x1105
80 /* ----------------------------------------------- */
81 /* sdmc dm1105 registers */
84 #define DM1105_TSCTR 0x00
85 #define DM1105_DTALENTH 0x04
88 #define DM1105_GPIOVAL 0x08
89 #define DM1105_GPIOCTR 0x0c
91 /* PID serial number */
92 #define DM1105_PIDN 0x10
94 /* Odd-even secret key select */
95 #define DM1105_CWSEL 0x14
97 /* Host Command Interface */
98 #define DM1105_HOST_CTR 0x18
99 #define DM1105_HOST_AD 0x1c
102 #define DM1105_CR 0x30
103 #define DM1105_RST 0x34
104 #define DM1105_STADR 0x38
105 #define DM1105_RLEN 0x3c
106 #define DM1105_WRP 0x40
107 #define DM1105_INTCNT 0x44
108 #define DM1105_INTMAK 0x48
109 #define DM1105_INTSTS 0x4c
112 #define DM1105_ODD 0x50
113 #define DM1105_EVEN 0x58
116 #define DM1105_PID 0x60
119 #define DM1105_IRCTR 0x64
120 #define DM1105_IRMODE 0x68
121 #define DM1105_SYSTEMCODE 0x6c
122 #define DM1105_IRCODE 0x70
125 #define DM1105_ENCRYPT 0x74
126 #define DM1105_VER 0x7c
129 #define DM1105_I2CCTR 0x80
130 #define DM1105_I2CSTS 0x81
131 #define DM1105_I2CDAT 0x82
132 #define DM1105_I2C_RA 0x83
133 /* ----------------------------------------------- */
134 /* Interrupt Mask Bits */
136 #define INTMAK_TSIRQM 0x01
137 #define INTMAK_HIRQM 0x04
138 #define INTMAK_IRM 0x08
139 #define INTMAK_ALLMASK (INTMAK_TSIRQM | \
142 #define INTMAK_NONEMASK 0x00
144 /* Interrupt Status Bits */
145 #define INTSTS_TSIRQ 0x01
146 #define INTSTS_HIRQ 0x04
147 #define INTSTS_IR 0x08
149 /* IR Control Bits */
150 #define DM1105_IR_EN 0x01
151 #define DM1105_SYS_CHK 0x02
152 #define DM1105_REP_FLG 0x08
155 #define IIC_24C01_addr 0xa0
156 /* Max board count */
157 #define DM1105_MAX 0x04
159 #define DRIVER_NAME "dm1105"
161 #define DM1105_DMA_PACKETS 47
162 #define DM1105_DMA_PACKET_LENGTH (128*4)
163 #define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS)
165 /* GPIO's for LNB power control */
166 #define DM1105_LNB_MASK 0x00000000
167 #define DM1105_LNB_OFF 0x00020000
168 #define DM1105_LNB_13V 0x00010100
169 #define DM1105_LNB_18V 0x00000100
171 /* GPIO's for LNB power control for Axess DM05 */
172 #define DM05_LNB_MASK 0x00000000
173 #define DM05_LNB_OFF 0x00020000/* actually 13v */
174 #define DM05_LNB_13V 0x00020000
175 #define DM05_LNB_18V 0x00030000
177 static unsigned int card
[] = {[0 ... 3] = UNSET
};
178 module_param_array(card
, int, NULL
, 0444);
179 MODULE_PARM_DESC(card
, "card type");
182 module_param(ir_debug
, int, 0644);
183 MODULE_PARM_DESC(ir_debug
, "enable debugging information for IR decoding");
185 static unsigned int dm1105_devcount
;
187 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
189 struct dm1105_board
{
193 struct dm1105_subid
{
199 static const struct dm1105_board dm1105_boards
[] = {
200 [DM1105_BOARD_UNKNOWN
] = {
201 .name
= "UNKNOWN/GENERIC",
203 [DM1105_BOARD_DVBWORLD_2002
] = {
204 .name
= "DVBWorld PCI 2002",
206 [DM1105_BOARD_DVBWORLD_2004
] = {
207 .name
= "DVBWorld PCI 2004",
209 [DM1105_BOARD_AXESS_DM05
] = {
210 .name
= "Axess/EasyTv DM05",
214 static const struct dm1105_subid dm1105_subids
[] = {
218 .card
= DM1105_BOARD_DVBWORLD_2002
,
222 .card
= DM1105_BOARD_DVBWORLD_2002
,
226 .card
= DM1105_BOARD_DVBWORLD_2004
,
230 .card
= DM1105_BOARD_DVBWORLD_2004
,
234 .card
= DM1105_BOARD_AXESS_DM05
,
238 static void dm1105_card_list(struct pci_dev
*pci
)
242 if (0 == pci
->subsystem_vendor
&&
243 0 == pci
->subsystem_device
) {
245 "dm1105: Your board has no valid PCI Subsystem ID\n"
246 "dm1105: and thus can't be autodetected\n"
247 "dm1105: Please pass card=<n> insmod option to\n"
248 "dm1105: workaround that. Redirect complaints to\n"
249 "dm1105: the vendor of the TV card. Best regards,\n"
253 "dm1105: Your board isn't known (yet) to the driver.\n"
254 "dm1105: You can try to pick one of the existing\n"
255 "dm1105: card configs via card=<n> insmod option.\n"
256 "dm1105: Updating to the latest version might help\n"
257 "dm1105: as well.\n");
259 printk(KERN_ERR
"Here is a list of valid choices for the card=<n> "
261 for (i
= 0; i
< ARRAY_SIZE(dm1105_boards
); i
++)
262 printk(KERN_ERR
"dm1105: card=%d -> %s\n",
263 i
, dm1105_boards
[i
].name
);
266 /* infrared remote control */
270 struct work_struct work
;
276 struct pci_dev
*pdev
;
283 struct dmx_frontend hw_frontend
;
284 struct dmx_frontend mem_frontend
;
285 struct dmxdev dmxdev
;
286 struct dvb_adapter dvb_adapter
;
287 struct dvb_demux demux
;
288 struct dvb_frontend
*fe
;
289 struct dvb_net dvbnet
;
290 unsigned int full_ts_users
;
291 unsigned int boardnr
;
295 struct i2c_adapter i2c_adap
;
298 struct work_struct work
;
299 struct workqueue_struct
*wq
;
304 unsigned char *ts_buf
;
308 unsigned int PacketErrorCount
;
313 #define dm_io_mem(reg) ((unsigned long)(&dev->io_mem[reg]))
315 #define dm_readb(reg) inb(dm_io_mem(reg))
316 #define dm_writeb(reg, value) outb((value), (dm_io_mem(reg)))
318 #define dm_readw(reg) inw(dm_io_mem(reg))
319 #define dm_writew(reg, value) outw((value), (dm_io_mem(reg)))
321 #define dm_readl(reg) inl(dm_io_mem(reg))
322 #define dm_writel(reg, value) outl((value), (dm_io_mem(reg)))
324 #define dm_andorl(reg, mask, value) \
325 outl((inl(dm_io_mem(reg)) & ~(mask)) |\
326 ((value) & (mask)), (dm_io_mem(reg)))
328 #define dm_setl(reg, bit) dm_andorl((reg), (bit), (bit))
329 #define dm_clearl(reg, bit) dm_andorl((reg), (bit), 0)
331 static int dm1105_i2c_xfer(struct i2c_adapter
*i2c_adap
,
332 struct i2c_msg
*msgs
, int num
)
334 struct dm1105_dev
*dev
;
336 int addr
, rc
, i
, j
, k
, len
, byte
, data
;
339 dev
= i2c_adap
->algo_data
;
340 for (i
= 0; i
< num
; i
++) {
341 dm_writeb(DM1105_I2CCTR
, 0x00);
342 if (msgs
[i
].flags
& I2C_M_RD
) {
344 addr
= msgs
[i
].addr
<< 1;
346 dm_writeb(DM1105_I2CDAT
, addr
);
347 for (byte
= 0; byte
< msgs
[i
].len
; byte
++)
348 dm_writeb(DM1105_I2CDAT
+ byte
+ 1, 0);
350 dm_writeb(DM1105_I2CCTR
, 0x81 + msgs
[i
].len
);
351 for (j
= 0; j
< 55; j
++) {
353 status
= dm_readb(DM1105_I2CSTS
);
354 if ((status
& 0xc0) == 0x40)
360 for (byte
= 0; byte
< msgs
[i
].len
; byte
++) {
361 rc
= dm_readb(DM1105_I2CDAT
+ byte
+ 1);
364 msgs
[i
].buf
[byte
] = rc
;
366 } else if ((msgs
[i
].buf
[0] == 0xf7) && (msgs
[i
].addr
== 0x55)) {
367 /* prepaired for cx24116 firmware */
368 /* Write in small blocks */
369 len
= msgs
[i
].len
- 1;
372 dm_writeb(DM1105_I2CDAT
, msgs
[i
].addr
<< 1);
373 dm_writeb(DM1105_I2CDAT
+ 1, 0xf7);
374 for (byte
= 0; byte
< (len
> 48 ? 48 : len
); byte
++) {
375 data
= msgs
[i
].buf
[k
+ byte
];
376 dm_writeb(DM1105_I2CDAT
+ byte
+ 2, data
);
378 dm_writeb(DM1105_I2CCTR
, 0x82 + (len
> 48 ? 48 : len
));
379 for (j
= 0; j
< 25; j
++) {
381 status
= dm_readb(DM1105_I2CSTS
);
382 if ((status
& 0xc0) == 0x40)
394 dm_writeb(DM1105_I2CDAT
, msgs
[i
].addr
<< 1);
395 for (byte
= 0; byte
< msgs
[i
].len
; byte
++) {
396 data
= msgs
[i
].buf
[byte
];
397 dm_writeb(DM1105_I2CDAT
+ byte
+ 1, data
);
399 dm_writeb(DM1105_I2CCTR
, 0x81 + msgs
[i
].len
);
400 for (j
= 0; j
< 25; j
++) {
402 status
= dm_readb(DM1105_I2CSTS
);
403 if ((status
& 0xc0) == 0x40)
416 static u32
functionality(struct i2c_adapter
*adap
)
421 static struct i2c_algorithm dm1105_algo
= {
422 .master_xfer
= dm1105_i2c_xfer
,
423 .functionality
= functionality
,
426 static inline struct dm1105_dev
*feed_to_dm1105_dev(struct dvb_demux_feed
*feed
)
428 return container_of(feed
->demux
, struct dm1105_dev
, demux
);
431 static inline struct dm1105_dev
*frontend_to_dm1105_dev(struct dvb_frontend
*fe
)
433 return container_of(fe
->dvb
, struct dm1105_dev
, dvb_adapter
);
436 static int dm1105_set_voltage(struct dvb_frontend
*fe
, fe_sec_voltage_t voltage
)
438 struct dm1105_dev
*dev
= frontend_to_dm1105_dev(fe
);
439 u32 lnb_mask
, lnb_13v
, lnb_18v
, lnb_off
;
441 switch (dev
->boardnr
) {
442 case DM1105_BOARD_AXESS_DM05
:
443 lnb_mask
= DM05_LNB_MASK
;
444 lnb_off
= DM05_LNB_OFF
;
445 lnb_13v
= DM05_LNB_13V
;
446 lnb_18v
= DM05_LNB_18V
;
448 case DM1105_BOARD_DVBWORLD_2002
:
449 case DM1105_BOARD_DVBWORLD_2004
:
451 lnb_mask
= DM1105_LNB_MASK
;
452 lnb_off
= DM1105_LNB_OFF
;
453 lnb_13v
= DM1105_LNB_13V
;
454 lnb_18v
= DM1105_LNB_18V
;
457 dm_writel(DM1105_GPIOCTR
, lnb_mask
);
458 if (voltage
== SEC_VOLTAGE_18
)
459 dm_writel(DM1105_GPIOVAL
, lnb_18v
);
460 else if (voltage
== SEC_VOLTAGE_13
)
461 dm_writel(DM1105_GPIOVAL
, lnb_13v
);
463 dm_writel(DM1105_GPIOVAL
, lnb_off
);
468 static void dm1105_set_dma_addr(struct dm1105_dev
*dev
)
470 dm_writel(DM1105_STADR
, cpu_to_le32(dev
->dma_addr
));
473 static int __devinit
dm1105_dma_map(struct dm1105_dev
*dev
)
475 dev
->ts_buf
= pci_alloc_consistent(dev
->pdev
,
476 6 * DM1105_DMA_BYTES
,
482 static void dm1105_dma_unmap(struct dm1105_dev
*dev
)
484 pci_free_consistent(dev
->pdev
,
485 6 * DM1105_DMA_BYTES
,
490 static void dm1105_enable_irqs(struct dm1105_dev
*dev
)
492 dm_writeb(DM1105_INTMAK
, INTMAK_ALLMASK
);
493 dm_writeb(DM1105_CR
, 1);
496 static void dm1105_disable_irqs(struct dm1105_dev
*dev
)
498 dm_writeb(DM1105_INTMAK
, INTMAK_IRM
);
499 dm_writeb(DM1105_CR
, 0);
502 static int dm1105_start_feed(struct dvb_demux_feed
*f
)
504 struct dm1105_dev
*dev
= feed_to_dm1105_dev(f
);
506 if (dev
->full_ts_users
++ == 0)
507 dm1105_enable_irqs(dev
);
512 static int dm1105_stop_feed(struct dvb_demux_feed
*f
)
514 struct dm1105_dev
*dev
= feed_to_dm1105_dev(f
);
516 if (--dev
->full_ts_users
== 0)
517 dm1105_disable_irqs(dev
);
522 /* ir work handler */
523 static void dm1105_emit_key(struct work_struct
*work
)
525 struct infrared
*ir
= container_of(work
, struct infrared
, work
);
526 u32 ircom
= ir
->ir_command
;
530 printk(KERN_INFO
"%s: received byte 0x%04x\n", __func__
, ircom
);
532 data
= (ircom
>> 8) & 0x7f;
534 rc_keydown(ir
->dev
, data
, 0);
538 static void dm1105_dmx_buffer(struct work_struct
*work
)
540 struct dm1105_dev
*dev
= container_of(work
, struct dm1105_dev
, work
);
541 unsigned int nbpackets
;
542 u32 oldwrp
= dev
->wrp
;
543 u32 nextwrp
= dev
->nextwrp
;
545 if (!((dev
->ts_buf
[oldwrp
] == 0x47) &&
546 (dev
->ts_buf
[oldwrp
+ 188] == 0x47) &&
547 (dev
->ts_buf
[oldwrp
+ 188 * 2] == 0x47))) {
548 dev
->PacketErrorCount
++;
549 /* bad packet found */
550 if ((dev
->PacketErrorCount
>= 2) &&
551 (dev
->dmarst
== 0)) {
552 dm_writeb(DM1105_RST
, 1);
554 dev
->PacketErrorCount
= 0;
560 if (nextwrp
< oldwrp
) {
561 memcpy(dev
->ts_buf
+ dev
->buffer_size
, dev
->ts_buf
, nextwrp
);
562 nbpackets
= ((dev
->buffer_size
- oldwrp
) + nextwrp
) / 188;
564 nbpackets
= (nextwrp
- oldwrp
) / 188;
567 dvb_dmx_swfilter_packets(&dev
->demux
, &dev
->ts_buf
[oldwrp
], nbpackets
);
570 static irqreturn_t
dm1105_irq(int irq
, void *dev_id
)
572 struct dm1105_dev
*dev
= dev_id
;
574 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */
575 unsigned int intsts
= dm_readb(DM1105_INTSTS
);
576 dm_writeb(DM1105_INTSTS
, intsts
);
580 case (INTSTS_TSIRQ
| INTSTS_IR
):
581 dev
->nextwrp
= dm_readl(DM1105_WRP
) - dm_readl(DM1105_STADR
);
582 queue_work(dev
->wq
, &dev
->work
);
585 dev
->ir
.ir_command
= dm_readl(DM1105_IRCODE
);
586 schedule_work(&dev
->ir
.work
);
593 int __devinit
dm1105_ir_init(struct dm1105_dev
*dm1105
)
598 dev
= rc_allocate_device();
602 snprintf(dm1105
->ir
.input_phys
, sizeof(dm1105
->ir
.input_phys
),
603 "pci-%s/ir0", pci_name(dm1105
->pdev
));
605 dev
->driver_name
= MODULE_NAME
;
606 dev
->map_name
= RC_MAP_DM1105_NEC
;
607 dev
->driver_type
= RC_DRIVER_SCANCODE
;
608 dev
->input_name
= "DVB on-card IR receiver";
609 dev
->input_phys
= dm1105
->ir
.input_phys
;
610 dev
->input_id
.bustype
= BUS_PCI
;
611 dev
->input_id
.version
= 1;
612 if (dm1105
->pdev
->subsystem_vendor
) {
613 dev
->input_id
.vendor
= dm1105
->pdev
->subsystem_vendor
;
614 dev
->input_id
.product
= dm1105
->pdev
->subsystem_device
;
616 dev
->input_id
.vendor
= dm1105
->pdev
->vendor
;
617 dev
->input_id
.product
= dm1105
->pdev
->device
;
619 dev
->dev
.parent
= &dm1105
->pdev
->dev
;
621 INIT_WORK(&dm1105
->ir
.work
, dm1105_emit_key
);
623 err
= rc_register_device(dev
);
629 dm1105
->ir
.dev
= dev
;
633 void __devexit
dm1105_ir_exit(struct dm1105_dev
*dm1105
)
635 rc_unregister_device(dm1105
->ir
.dev
);
638 static int __devinit
dm1105_hw_init(struct dm1105_dev
*dev
)
640 dm1105_disable_irqs(dev
);
642 dm_writeb(DM1105_HOST_CTR
, 0);
645 dm_writeb(DM1105_DTALENTH
, 188);
646 /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/
647 dm_writew(DM1105_TSCTR
, 0xc10a);
649 /* map DMA and set address */
651 dm1105_set_dma_addr(dev
);
653 dm_writel(DM1105_RLEN
, 5 * DM1105_DMA_BYTES
);
654 dm_writeb(DM1105_INTCNT
, 47);
656 /* IR NEC mode enable */
657 dm_writeb(DM1105_IRCTR
, (DM1105_IR_EN
| DM1105_SYS_CHK
));
658 dm_writeb(DM1105_IRMODE
, 0);
659 dm_writew(DM1105_SYSTEMCODE
, 0);
664 static void dm1105_hw_exit(struct dm1105_dev
*dev
)
666 dm1105_disable_irqs(dev
);
669 dm_writeb(DM1105_IRCTR
, 0);
670 dm_writeb(DM1105_INTMAK
, INTMAK_NONEMASK
);
672 dm1105_dma_unmap(dev
);
675 static struct stv0299_config sharp_z0194a_config
= {
676 .demod_address
= 0x68,
677 .inittab
= sharp_z0194a_inittab
,
681 .lock_output
= STV0299_LOCKOUTPUT_1
,
682 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
684 .set_symbol_rate
= sharp_z0194a_set_symbol_rate
,
687 static struct stv0288_config earda_config
= {
688 .demod_address
= 0x68,
692 static struct si21xx_config serit_config
= {
693 .demod_address
= 0x68,
698 static struct cx24116_config serit_sp2633_config
= {
699 .demod_address
= 0x55,
702 static struct ds3000_config dvbworld_ds3000_config
= {
703 .demod_address
= 0x68,
706 static int __devinit
frontend_init(struct dm1105_dev
*dev
)
710 switch (dev
->boardnr
) {
711 case DM1105_BOARD_DVBWORLD_2004
:
712 dev
->fe
= dvb_attach(
713 cx24116_attach
, &serit_sp2633_config
,
716 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
720 dev
->fe
= dvb_attach(
721 ds3000_attach
, &dvbworld_ds3000_config
,
724 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
727 case DM1105_BOARD_DVBWORLD_2002
:
728 case DM1105_BOARD_AXESS_DM05
:
730 dev
->fe
= dvb_attach(
731 stv0299_attach
, &sharp_z0194a_config
,
734 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
735 dvb_attach(dvb_pll_attach
, dev
->fe
, 0x60,
736 &dev
->i2c_adap
, DVB_PLL_OPERA1
);
740 dev
->fe
= dvb_attach(
741 stv0288_attach
, &earda_config
,
744 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
745 dvb_attach(stb6000_attach
, dev
->fe
, 0x61,
750 dev
->fe
= dvb_attach(
751 si21xx_attach
, &serit_config
,
754 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
759 dev_err(&dev
->pdev
->dev
, "could not attach frontend\n");
763 ret
= dvb_register_frontend(&dev
->dvb_adapter
, dev
->fe
);
765 if (dev
->fe
->ops
.release
)
766 dev
->fe
->ops
.release(dev
->fe
);
774 static void __devinit
dm1105_read_mac(struct dm1105_dev
*dev
, u8
*mac
)
776 static u8 command
[1] = { 0x28 };
778 struct i2c_msg msg
[] = {
780 .addr
= IIC_24C01_addr
>> 1,
785 .addr
= IIC_24C01_addr
>> 1,
792 dm1105_i2c_xfer(&dev
->i2c_adap
, msg
, 2);
793 dev_info(&dev
->pdev
->dev
, "MAC %pM\n", mac
);
796 static int __devinit
dm1105_probe(struct pci_dev
*pdev
,
797 const struct pci_device_id
*ent
)
799 struct dm1105_dev
*dev
;
800 struct dvb_adapter
*dvb_adapter
;
801 struct dvb_demux
*dvbdemux
;
802 struct dmx_demux
*dmx
;
806 dev
= kzalloc(sizeof(struct dm1105_dev
), GFP_KERNEL
);
811 dev
->nr
= dm1105_devcount
;
812 dev
->boardnr
= UNSET
;
813 if (card
[dev
->nr
] < ARRAY_SIZE(dm1105_boards
))
814 dev
->boardnr
= card
[dev
->nr
];
815 for (i
= 0; UNSET
== dev
->boardnr
&&
816 i
< ARRAY_SIZE(dm1105_subids
); i
++)
817 if (pdev
->subsystem_vendor
==
818 dm1105_subids
[i
].subvendor
&&
819 pdev
->subsystem_device
==
820 dm1105_subids
[i
].subdevice
)
821 dev
->boardnr
= dm1105_subids
[i
].card
;
823 if (UNSET
== dev
->boardnr
) {
824 dev
->boardnr
= DM1105_BOARD_UNKNOWN
;
825 dm1105_card_list(pdev
);
830 dev
->buffer_size
= 5 * DM1105_DMA_BYTES
;
831 dev
->PacketErrorCount
= 0;
834 ret
= pci_enable_device(pdev
);
838 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
840 goto err_pci_disable_device
;
842 pci_set_master(pdev
);
844 ret
= pci_request_regions(pdev
, DRIVER_NAME
);
846 goto err_pci_disable_device
;
848 dev
->io_mem
= pci_iomap(pdev
, 0, pci_resource_len(pdev
, 0));
851 goto err_pci_release_regions
;
854 spin_lock_init(&dev
->lock
);
855 pci_set_drvdata(pdev
, dev
);
857 ret
= dm1105_hw_init(dev
);
859 goto err_pci_iounmap
;
862 i2c_set_adapdata(&dev
->i2c_adap
, dev
);
863 strcpy(dev
->i2c_adap
.name
, DRIVER_NAME
);
864 dev
->i2c_adap
.owner
= THIS_MODULE
;
865 dev
->i2c_adap
.dev
.parent
= &pdev
->dev
;
866 dev
->i2c_adap
.algo
= &dm1105_algo
;
867 dev
->i2c_adap
.algo_data
= dev
;
868 ret
= i2c_add_adapter(&dev
->i2c_adap
);
871 goto err_dm1105_hw_exit
;
874 ret
= dvb_register_adapter(&dev
->dvb_adapter
, DRIVER_NAME
,
875 THIS_MODULE
, &pdev
->dev
, adapter_nr
);
877 goto err_i2c_del_adapter
;
879 dvb_adapter
= &dev
->dvb_adapter
;
881 dm1105_read_mac(dev
, dvb_adapter
->proposed_mac
);
883 dvbdemux
= &dev
->demux
;
884 dvbdemux
->filternum
= 256;
885 dvbdemux
->feednum
= 256;
886 dvbdemux
->start_feed
= dm1105_start_feed
;
887 dvbdemux
->stop_feed
= dm1105_stop_feed
;
888 dvbdemux
->dmx
.capabilities
= (DMX_TS_FILTERING
|
889 DMX_SECTION_FILTERING
| DMX_MEMORY_BASED_FILTERING
);
890 ret
= dvb_dmx_init(dvbdemux
);
892 goto err_dvb_unregister_adapter
;
894 dmx
= &dvbdemux
->dmx
;
895 dev
->dmxdev
.filternum
= 256;
896 dev
->dmxdev
.demux
= dmx
;
897 dev
->dmxdev
.capabilities
= 0;
899 ret
= dvb_dmxdev_init(&dev
->dmxdev
, dvb_adapter
);
901 goto err_dvb_dmx_release
;
903 dev
->hw_frontend
.source
= DMX_FRONTEND_0
;
905 ret
= dmx
->add_frontend(dmx
, &dev
->hw_frontend
);
907 goto err_dvb_dmxdev_release
;
909 dev
->mem_frontend
.source
= DMX_MEMORY_FE
;
911 ret
= dmx
->add_frontend(dmx
, &dev
->mem_frontend
);
913 goto err_remove_hw_frontend
;
915 ret
= dmx
->connect_frontend(dmx
, &dev
->hw_frontend
);
917 goto err_remove_mem_frontend
;
919 ret
= frontend_init(dev
);
921 goto err_disconnect_frontend
;
923 dvb_net_init(dvb_adapter
, &dev
->dvbnet
, dmx
);
926 INIT_WORK(&dev
->work
, dm1105_dmx_buffer
);
927 sprintf(dev
->wqn
, "%s/%d", dvb_adapter
->name
, dvb_adapter
->num
);
928 dev
->wq
= create_singlethread_workqueue(dev
->wqn
);
932 ret
= request_irq(pdev
->irq
, dm1105_irq
, IRQF_SHARED
,
940 destroy_workqueue(dev
->wq
);
942 dvb_net_release(&dev
->dvbnet
);
943 err_disconnect_frontend
:
944 dmx
->disconnect_frontend(dmx
);
945 err_remove_mem_frontend
:
946 dmx
->remove_frontend(dmx
, &dev
->mem_frontend
);
947 err_remove_hw_frontend
:
948 dmx
->remove_frontend(dmx
, &dev
->hw_frontend
);
949 err_dvb_dmxdev_release
:
950 dvb_dmxdev_release(&dev
->dmxdev
);
952 dvb_dmx_release(dvbdemux
);
953 err_dvb_unregister_adapter
:
954 dvb_unregister_adapter(dvb_adapter
);
956 i2c_del_adapter(&dev
->i2c_adap
);
960 pci_iounmap(pdev
, dev
->io_mem
);
961 err_pci_release_regions
:
962 pci_release_regions(pdev
);
963 err_pci_disable_device
:
964 pci_disable_device(pdev
);
966 pci_set_drvdata(pdev
, NULL
);
971 static void __devexit
dm1105_remove(struct pci_dev
*pdev
)
973 struct dm1105_dev
*dev
= pci_get_drvdata(pdev
);
974 struct dvb_adapter
*dvb_adapter
= &dev
->dvb_adapter
;
975 struct dvb_demux
*dvbdemux
= &dev
->demux
;
976 struct dmx_demux
*dmx
= &dvbdemux
->dmx
;
980 dvb_net_release(&dev
->dvbnet
);
982 dvb_unregister_frontend(dev
->fe
);
984 dmx
->disconnect_frontend(dmx
);
985 dmx
->remove_frontend(dmx
, &dev
->mem_frontend
);
986 dmx
->remove_frontend(dmx
, &dev
->hw_frontend
);
987 dvb_dmxdev_release(&dev
->dmxdev
);
988 dvb_dmx_release(dvbdemux
);
989 dvb_unregister_adapter(dvb_adapter
);
991 i2c_del_adapter(&dev
->i2c_adap
);
994 synchronize_irq(pdev
->irq
);
995 free_irq(pdev
->irq
, dev
);
996 pci_iounmap(pdev
, dev
->io_mem
);
997 pci_release_regions(pdev
);
998 pci_disable_device(pdev
);
999 pci_set_drvdata(pdev
, NULL
);
1004 static struct pci_device_id dm1105_id_table
[] __devinitdata
= {
1006 .vendor
= PCI_VENDOR_ID_TRIGEM
,
1007 .device
= PCI_DEVICE_ID_DM1105
,
1008 .subvendor
= PCI_ANY_ID
,
1009 .subdevice
= PCI_ANY_ID
,
1011 .vendor
= PCI_VENDOR_ID_AXESS
,
1012 .device
= PCI_DEVICE_ID_DM05
,
1013 .subvendor
= PCI_ANY_ID
,
1014 .subdevice
= PCI_ANY_ID
,
1020 MODULE_DEVICE_TABLE(pci
, dm1105_id_table
);
1022 static struct pci_driver dm1105_driver
= {
1023 .name
= DRIVER_NAME
,
1024 .id_table
= dm1105_id_table
,
1025 .probe
= dm1105_probe
,
1026 .remove
= __devexit_p(dm1105_remove
),
1029 static int __init
dm1105_init(void)
1031 return pci_register_driver(&dm1105_driver
);
1034 static void __exit
dm1105_exit(void)
1036 pci_unregister_driver(&dm1105_driver
);
1039 module_init(dm1105_init
);
1040 module_exit(dm1105_exit
);
1042 MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
1043 MODULE_DESCRIPTION("SDMC DM1105 DVB driver");
1044 MODULE_LICENSE("GPL");