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/input.h>
30 #include <media/ir-common.h>
34 #include "dvb_demux.h"
35 #include "dvb_frontend.h"
50 #define DM1105_BOARD_NOAUTO UNSET
51 #define DM1105_BOARD_UNKNOWN 0
52 #define DM1105_BOARD_DVBWORLD_2002 1
53 #define DM1105_BOARD_DVBWORLD_2004 2
54 #define DM1105_BOARD_AXESS_DM05 3
56 /* ----------------------------------------------- */
60 #ifndef PCI_VENDOR_ID_TRIGEM
61 #define PCI_VENDOR_ID_TRIGEM 0x109f
63 #ifndef PCI_VENDOR_ID_AXESS
64 #define PCI_VENDOR_ID_AXESS 0x195d
66 #ifndef PCI_DEVICE_ID_DM1105
67 #define PCI_DEVICE_ID_DM1105 0x036f
69 #ifndef PCI_DEVICE_ID_DW2002
70 #define PCI_DEVICE_ID_DW2002 0x2002
72 #ifndef PCI_DEVICE_ID_DW2004
73 #define PCI_DEVICE_ID_DW2004 0x2004
75 #ifndef PCI_DEVICE_ID_DM05
76 #define PCI_DEVICE_ID_DM05 0x1105
78 /* ----------------------------------------------- */
79 /* sdmc dm1105 registers */
82 #define DM1105_TSCTR 0x00
83 #define DM1105_DTALENTH 0x04
86 #define DM1105_GPIOVAL 0x08
87 #define DM1105_GPIOCTR 0x0c
89 /* PID serial number */
90 #define DM1105_PIDN 0x10
92 /* Odd-even secret key select */
93 #define DM1105_CWSEL 0x14
95 /* Host Command Interface */
96 #define DM1105_HOST_CTR 0x18
97 #define DM1105_HOST_AD 0x1c
100 #define DM1105_CR 0x30
101 #define DM1105_RST 0x34
102 #define DM1105_STADR 0x38
103 #define DM1105_RLEN 0x3c
104 #define DM1105_WRP 0x40
105 #define DM1105_INTCNT 0x44
106 #define DM1105_INTMAK 0x48
107 #define DM1105_INTSTS 0x4c
110 #define DM1105_ODD 0x50
111 #define DM1105_EVEN 0x58
114 #define DM1105_PID 0x60
117 #define DM1105_IRCTR 0x64
118 #define DM1105_IRMODE 0x68
119 #define DM1105_SYSTEMCODE 0x6c
120 #define DM1105_IRCODE 0x70
123 #define DM1105_ENCRYPT 0x74
124 #define DM1105_VER 0x7c
127 #define DM1105_I2CCTR 0x80
128 #define DM1105_I2CSTS 0x81
129 #define DM1105_I2CDAT 0x82
130 #define DM1105_I2C_RA 0x83
131 /* ----------------------------------------------- */
132 /* Interrupt Mask Bits */
134 #define INTMAK_TSIRQM 0x01
135 #define INTMAK_HIRQM 0x04
136 #define INTMAK_IRM 0x08
137 #define INTMAK_ALLMASK (INTMAK_TSIRQM | \
140 #define INTMAK_NONEMASK 0x00
142 /* Interrupt Status Bits */
143 #define INTSTS_TSIRQ 0x01
144 #define INTSTS_HIRQ 0x04
145 #define INTSTS_IR 0x08
147 /* IR Control Bits */
148 #define DM1105_IR_EN 0x01
149 #define DM1105_SYS_CHK 0x02
150 #define DM1105_REP_FLG 0x08
153 #define IIC_24C01_addr 0xa0
154 /* Max board count */
155 #define DM1105_MAX 0x04
157 #define DRIVER_NAME "dm1105"
159 #define DM1105_DMA_PACKETS 47
160 #define DM1105_DMA_PACKET_LENGTH (128*4)
161 #define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS)
163 /* GPIO's for LNB power control */
164 #define DM1105_LNB_MASK 0x00000000
165 #define DM1105_LNB_OFF 0x00020000
166 #define DM1105_LNB_13V 0x00010100
167 #define DM1105_LNB_18V 0x00000100
169 /* GPIO's for LNB power control for Axess DM05 */
170 #define DM05_LNB_MASK 0x00000000
171 #define DM05_LNB_OFF 0x00020000/* actually 13v */
172 #define DM05_LNB_13V 0x00020000
173 #define DM05_LNB_18V 0x00030000
175 static unsigned int card
[] = {[0 ... 3] = UNSET
};
176 module_param_array(card
, int, NULL
, 0444);
177 MODULE_PARM_DESC(card
, "card type");
180 module_param(ir_debug
, int, 0644);
181 MODULE_PARM_DESC(ir_debug
, "enable debugging information for IR decoding");
183 static unsigned int dm1105_devcount
;
185 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
187 struct dm1105_board
{
191 struct dm1105_subid
{
197 static const struct dm1105_board dm1105_boards
[] = {
198 [DM1105_BOARD_UNKNOWN
] = {
199 .name
= "UNKNOWN/GENERIC",
201 [DM1105_BOARD_DVBWORLD_2002
] = {
202 .name
= "DVBWorld PCI 2002",
204 [DM1105_BOARD_DVBWORLD_2004
] = {
205 .name
= "DVBWorld PCI 2004",
207 [DM1105_BOARD_AXESS_DM05
] = {
208 .name
= "Axess/EasyTv DM05",
212 static const struct dm1105_subid dm1105_subids
[] = {
216 .card
= DM1105_BOARD_DVBWORLD_2002
,
220 .card
= DM1105_BOARD_DVBWORLD_2002
,
224 .card
= DM1105_BOARD_DVBWORLD_2004
,
228 .card
= DM1105_BOARD_DVBWORLD_2004
,
232 .card
= DM1105_BOARD_AXESS_DM05
,
236 static void dm1105_card_list(struct pci_dev
*pci
)
240 if (0 == pci
->subsystem_vendor
&&
241 0 == pci
->subsystem_device
) {
243 "dm1105: Your board has no valid PCI Subsystem ID\n"
244 "dm1105: and thus can't be autodetected\n"
245 "dm1105: Please pass card=<n> insmod option to\n"
246 "dm1105: workaround that. Redirect complaints to\n"
247 "dm1105: the vendor of the TV card. Best regards,\n"
251 "dm1105: Your board isn't known (yet) to the driver.\n"
252 "dm1105: You can try to pick one of the existing\n"
253 "dm1105: card configs via card=<n> insmod option.\n"
254 "dm1105: Updating to the latest version might help\n"
255 "dm1105: as well.\n");
257 printk(KERN_ERR
"Here is a list of valid choices for the card=<n> "
259 for (i
= 0; i
< ARRAY_SIZE(dm1105_boards
); i
++)
260 printk(KERN_ERR
"dm1105: card=%d -> %s\n",
261 i
, dm1105_boards
[i
].name
);
264 /* infrared remote control */
266 struct input_dev
*input_dev
;
267 struct ir_input_state ir
;
269 struct work_struct work
;
275 struct pci_dev
*pdev
;
282 struct dmx_frontend hw_frontend
;
283 struct dmx_frontend mem_frontend
;
284 struct dmxdev dmxdev
;
285 struct dvb_adapter dvb_adapter
;
286 struct dvb_demux demux
;
287 struct dvb_frontend
*fe
;
288 struct dvb_net dvbnet
;
289 unsigned int full_ts_users
;
290 unsigned int boardnr
;
294 struct i2c_adapter i2c_adap
;
297 struct work_struct work
;
298 struct workqueue_struct
*wq
;
303 unsigned char *ts_buf
;
307 unsigned int PacketErrorCount
;
312 #define dm_io_mem(reg) ((unsigned long)(&dev->io_mem[reg]))
314 #define dm_readb(reg) inb(dm_io_mem(reg))
315 #define dm_writeb(reg, value) outb((value), (dm_io_mem(reg)))
317 #define dm_readw(reg) inw(dm_io_mem(reg))
318 #define dm_writew(reg, value) outw((value), (dm_io_mem(reg)))
320 #define dm_readl(reg) inl(dm_io_mem(reg))
321 #define dm_writel(reg, value) outl((value), (dm_io_mem(reg)))
323 #define dm_andorl(reg, mask, value) \
324 outl((inl(dm_io_mem(reg)) & ~(mask)) |\
325 ((value) & (mask)), (dm_io_mem(reg)))
327 #define dm_setl(reg, bit) dm_andorl((reg), (bit), (bit))
328 #define dm_clearl(reg, bit) dm_andorl((reg), (bit), 0)
330 static int dm1105_i2c_xfer(struct i2c_adapter
*i2c_adap
,
331 struct i2c_msg
*msgs
, int num
)
333 struct dm1105_dev
*dev
;
335 int addr
, rc
, i
, j
, k
, len
, byte
, data
;
338 dev
= i2c_adap
->algo_data
;
339 for (i
= 0; i
< num
; i
++) {
340 dm_writeb(DM1105_I2CCTR
, 0x00);
341 if (msgs
[i
].flags
& I2C_M_RD
) {
343 addr
= msgs
[i
].addr
<< 1;
345 dm_writeb(DM1105_I2CDAT
, addr
);
346 for (byte
= 0; byte
< msgs
[i
].len
; byte
++)
347 dm_writeb(DM1105_I2CDAT
+ byte
+ 1, 0);
349 dm_writeb(DM1105_I2CCTR
, 0x81 + msgs
[i
].len
);
350 for (j
= 0; j
< 55; j
++) {
352 status
= dm_readb(DM1105_I2CSTS
);
353 if ((status
& 0xc0) == 0x40)
359 for (byte
= 0; byte
< msgs
[i
].len
; byte
++) {
360 rc
= dm_readb(DM1105_I2CDAT
+ byte
+ 1);
363 msgs
[i
].buf
[byte
] = rc
;
365 } else if ((msgs
[i
].buf
[0] == 0xf7) && (msgs
[i
].addr
== 0x55)) {
366 /* prepaired for cx24116 firmware */
367 /* Write in small blocks */
368 len
= msgs
[i
].len
- 1;
371 dm_writeb(DM1105_I2CDAT
, msgs
[i
].addr
<< 1);
372 dm_writeb(DM1105_I2CDAT
+ 1, 0xf7);
373 for (byte
= 0; byte
< (len
> 48 ? 48 : len
); byte
++) {
374 data
= msgs
[i
].buf
[k
+ byte
];
375 dm_writeb(DM1105_I2CDAT
+ byte
+ 2, data
);
377 dm_writeb(DM1105_I2CCTR
, 0x82 + (len
> 48 ? 48 : len
));
378 for (j
= 0; j
< 25; j
++) {
380 status
= dm_readb(DM1105_I2CSTS
);
381 if ((status
& 0xc0) == 0x40)
393 dm_writeb(DM1105_I2CDAT
, msgs
[i
].addr
<< 1);
394 for (byte
= 0; byte
< msgs
[i
].len
; byte
++) {
395 data
= msgs
[i
].buf
[byte
];
396 dm_writeb(DM1105_I2CDAT
+ byte
+ 1, data
);
398 dm_writeb(DM1105_I2CCTR
, 0x81 + msgs
[i
].len
);
399 for (j
= 0; j
< 25; j
++) {
401 status
= dm_readb(DM1105_I2CSTS
);
402 if ((status
& 0xc0) == 0x40)
415 static u32
functionality(struct i2c_adapter
*adap
)
420 static struct i2c_algorithm dm1105_algo
= {
421 .master_xfer
= dm1105_i2c_xfer
,
422 .functionality
= functionality
,
425 static inline struct dm1105_dev
*feed_to_dm1105_dev(struct dvb_demux_feed
*feed
)
427 return container_of(feed
->demux
, struct dm1105_dev
, demux
);
430 static inline struct dm1105_dev
*frontend_to_dm1105_dev(struct dvb_frontend
*fe
)
432 return container_of(fe
->dvb
, struct dm1105_dev
, dvb_adapter
);
435 static int dm1105_set_voltage(struct dvb_frontend
*fe
, fe_sec_voltage_t voltage
)
437 struct dm1105_dev
*dev
= frontend_to_dm1105_dev(fe
);
438 u32 lnb_mask
, lnb_13v
, lnb_18v
, lnb_off
;
440 switch (dev
->boardnr
) {
441 case DM1105_BOARD_AXESS_DM05
:
442 lnb_mask
= DM05_LNB_MASK
;
443 lnb_off
= DM05_LNB_OFF
;
444 lnb_13v
= DM05_LNB_13V
;
445 lnb_18v
= DM05_LNB_18V
;
447 case DM1105_BOARD_DVBWORLD_2002
:
448 case DM1105_BOARD_DVBWORLD_2004
:
450 lnb_mask
= DM1105_LNB_MASK
;
451 lnb_off
= DM1105_LNB_OFF
;
452 lnb_13v
= DM1105_LNB_13V
;
453 lnb_18v
= DM1105_LNB_18V
;
456 dm_writel(DM1105_GPIOCTR
, lnb_mask
);
457 if (voltage
== SEC_VOLTAGE_18
)
458 dm_writel(DM1105_GPIOVAL
, lnb_18v
);
459 else if (voltage
== SEC_VOLTAGE_13
)
460 dm_writel(DM1105_GPIOVAL
, lnb_13v
);
462 dm_writel(DM1105_GPIOVAL
, lnb_off
);
467 static void dm1105_set_dma_addr(struct dm1105_dev
*dev
)
469 dm_writel(DM1105_STADR
, cpu_to_le32(dev
->dma_addr
));
472 static int __devinit
dm1105_dma_map(struct dm1105_dev
*dev
)
474 dev
->ts_buf
= pci_alloc_consistent(dev
->pdev
,
475 6 * DM1105_DMA_BYTES
,
481 static void dm1105_dma_unmap(struct dm1105_dev
*dev
)
483 pci_free_consistent(dev
->pdev
,
484 6 * DM1105_DMA_BYTES
,
489 static void dm1105_enable_irqs(struct dm1105_dev
*dev
)
491 dm_writeb(DM1105_INTMAK
, INTMAK_ALLMASK
);
492 dm_writeb(DM1105_CR
, 1);
495 static void dm1105_disable_irqs(struct dm1105_dev
*dev
)
497 dm_writeb(DM1105_INTMAK
, INTMAK_IRM
);
498 dm_writeb(DM1105_CR
, 0);
501 static int dm1105_start_feed(struct dvb_demux_feed
*f
)
503 struct dm1105_dev
*dev
= feed_to_dm1105_dev(f
);
505 if (dev
->full_ts_users
++ == 0)
506 dm1105_enable_irqs(dev
);
511 static int dm1105_stop_feed(struct dvb_demux_feed
*f
)
513 struct dm1105_dev
*dev
= feed_to_dm1105_dev(f
);
515 if (--dev
->full_ts_users
== 0)
516 dm1105_disable_irqs(dev
);
521 /* ir work handler */
522 static void dm1105_emit_key(struct work_struct
*work
)
524 struct infrared
*ir
= container_of(work
, struct infrared
, work
);
525 u32 ircom
= ir
->ir_command
;
529 printk(KERN_INFO
"%s: received byte 0x%04x\n", __func__
, ircom
);
531 data
= (ircom
>> 8) & 0x7f;
533 ir_input_keydown(ir
->input_dev
, &ir
->ir
, data
);
534 ir_input_nokey(ir
->input_dev
, &ir
->ir
);
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
)
595 struct input_dev
*input_dev
;
596 struct ir_scancode_table
*ir_codes
= &ir_codes_dm1105_nec_table
;
597 u64 ir_type
= IR_TYPE_OTHER
;
600 input_dev
= input_allocate_device();
604 dm1105
->ir
.input_dev
= input_dev
;
605 snprintf(dm1105
->ir
.input_phys
, sizeof(dm1105
->ir
.input_phys
),
606 "pci-%s/ir0", pci_name(dm1105
->pdev
));
608 err
= ir_input_init(input_dev
, &dm1105
->ir
.ir
, ir_type
);
610 input_free_device(input_dev
);
614 input_dev
->name
= "DVB on-card IR receiver";
615 input_dev
->phys
= dm1105
->ir
.input_phys
;
616 input_dev
->id
.bustype
= BUS_PCI
;
617 input_dev
->id
.version
= 1;
618 if (dm1105
->pdev
->subsystem_vendor
) {
619 input_dev
->id
.vendor
= dm1105
->pdev
->subsystem_vendor
;
620 input_dev
->id
.product
= dm1105
->pdev
->subsystem_device
;
622 input_dev
->id
.vendor
= dm1105
->pdev
->vendor
;
623 input_dev
->id
.product
= dm1105
->pdev
->device
;
626 input_dev
->dev
.parent
= &dm1105
->pdev
->dev
;
628 INIT_WORK(&dm1105
->ir
.work
, dm1105_emit_key
);
630 err
= ir_input_register(input_dev
, ir_codes
, NULL
);
635 void __devexit
dm1105_ir_exit(struct dm1105_dev
*dm1105
)
637 ir_input_unregister(dm1105
->ir
.input_dev
);
640 static int __devinit
dm1105_hw_init(struct dm1105_dev
*dev
)
642 dm1105_disable_irqs(dev
);
644 dm_writeb(DM1105_HOST_CTR
, 0);
647 dm_writeb(DM1105_DTALENTH
, 188);
648 /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/
649 dm_writew(DM1105_TSCTR
, 0xc10a);
651 /* map DMA and set address */
653 dm1105_set_dma_addr(dev
);
655 dm_writel(DM1105_RLEN
, 5 * DM1105_DMA_BYTES
);
656 dm_writeb(DM1105_INTCNT
, 47);
658 /* IR NEC mode enable */
659 dm_writeb(DM1105_IRCTR
, (DM1105_IR_EN
| DM1105_SYS_CHK
));
660 dm_writeb(DM1105_IRMODE
, 0);
661 dm_writew(DM1105_SYSTEMCODE
, 0);
666 static void dm1105_hw_exit(struct dm1105_dev
*dev
)
668 dm1105_disable_irqs(dev
);
671 dm_writeb(DM1105_IRCTR
, 0);
672 dm_writeb(DM1105_INTMAK
, INTMAK_NONEMASK
);
674 dm1105_dma_unmap(dev
);
677 static struct stv0299_config sharp_z0194a_config
= {
678 .demod_address
= 0x68,
679 .inittab
= sharp_z0194a_inittab
,
683 .lock_output
= STV0299_LOCKOUTPUT_1
,
684 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
686 .set_symbol_rate
= sharp_z0194a_set_symbol_rate
,
689 static struct stv0288_config earda_config
= {
690 .demod_address
= 0x68,
694 static struct si21xx_config serit_config
= {
695 .demod_address
= 0x68,
700 static struct cx24116_config serit_sp2633_config
= {
701 .demod_address
= 0x55,
704 static struct ds3000_config dvbworld_ds3000_config
= {
705 .demod_address
= 0x68,
708 static int __devinit
frontend_init(struct dm1105_dev
*dev
)
712 switch (dev
->boardnr
) {
713 case DM1105_BOARD_DVBWORLD_2004
:
714 dev
->fe
= dvb_attach(
715 cx24116_attach
, &serit_sp2633_config
,
718 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
722 dev
->fe
= dvb_attach(
723 ds3000_attach
, &dvbworld_ds3000_config
,
726 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
729 case DM1105_BOARD_DVBWORLD_2002
:
730 case DM1105_BOARD_AXESS_DM05
:
732 dev
->fe
= dvb_attach(
733 stv0299_attach
, &sharp_z0194a_config
,
736 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
737 dvb_attach(dvb_pll_attach
, dev
->fe
, 0x60,
738 &dev
->i2c_adap
, DVB_PLL_OPERA1
);
742 dev
->fe
= dvb_attach(
743 stv0288_attach
, &earda_config
,
746 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
747 dvb_attach(stb6000_attach
, dev
->fe
, 0x61,
752 dev
->fe
= dvb_attach(
753 si21xx_attach
, &serit_config
,
756 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
761 dev_err(&dev
->pdev
->dev
, "could not attach frontend\n");
765 ret
= dvb_register_frontend(&dev
->dvb_adapter
, dev
->fe
);
767 if (dev
->fe
->ops
.release
)
768 dev
->fe
->ops
.release(dev
->fe
);
776 static void __devinit
dm1105_read_mac(struct dm1105_dev
*dev
, u8
*mac
)
778 static u8 command
[1] = { 0x28 };
780 struct i2c_msg msg
[] = {
782 .addr
= IIC_24C01_addr
>> 1,
787 .addr
= IIC_24C01_addr
>> 1,
794 dm1105_i2c_xfer(&dev
->i2c_adap
, msg
, 2);
795 dev_info(&dev
->pdev
->dev
, "MAC %pM\n", mac
);
798 static int __devinit
dm1105_probe(struct pci_dev
*pdev
,
799 const struct pci_device_id
*ent
)
801 struct dm1105_dev
*dev
;
802 struct dvb_adapter
*dvb_adapter
;
803 struct dvb_demux
*dvbdemux
;
804 struct dmx_demux
*dmx
;
808 dev
= kzalloc(sizeof(struct dm1105_dev
), GFP_KERNEL
);
813 dev
->nr
= dm1105_devcount
;
814 dev
->boardnr
= UNSET
;
815 if (card
[dev
->nr
] < ARRAY_SIZE(dm1105_boards
))
816 dev
->boardnr
= card
[dev
->nr
];
817 for (i
= 0; UNSET
== dev
->boardnr
&&
818 i
< ARRAY_SIZE(dm1105_subids
); i
++)
819 if (pdev
->subsystem_vendor
==
820 dm1105_subids
[i
].subvendor
&&
821 pdev
->subsystem_device
==
822 dm1105_subids
[i
].subdevice
)
823 dev
->boardnr
= dm1105_subids
[i
].card
;
825 if (UNSET
== dev
->boardnr
) {
826 dev
->boardnr
= DM1105_BOARD_UNKNOWN
;
827 dm1105_card_list(pdev
);
832 dev
->buffer_size
= 5 * DM1105_DMA_BYTES
;
833 dev
->PacketErrorCount
= 0;
836 ret
= pci_enable_device(pdev
);
840 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
842 goto err_pci_disable_device
;
844 pci_set_master(pdev
);
846 ret
= pci_request_regions(pdev
, DRIVER_NAME
);
848 goto err_pci_disable_device
;
850 dev
->io_mem
= pci_iomap(pdev
, 0, pci_resource_len(pdev
, 0));
853 goto err_pci_release_regions
;
856 spin_lock_init(&dev
->lock
);
857 pci_set_drvdata(pdev
, dev
);
859 ret
= dm1105_hw_init(dev
);
861 goto err_pci_iounmap
;
864 i2c_set_adapdata(&dev
->i2c_adap
, dev
);
865 strcpy(dev
->i2c_adap
.name
, DRIVER_NAME
);
866 dev
->i2c_adap
.owner
= THIS_MODULE
;
867 dev
->i2c_adap
.class = I2C_CLASS_TV_DIGITAL
;
868 dev
->i2c_adap
.dev
.parent
= &pdev
->dev
;
869 dev
->i2c_adap
.algo
= &dm1105_algo
;
870 dev
->i2c_adap
.algo_data
= dev
;
871 ret
= i2c_add_adapter(&dev
->i2c_adap
);
874 goto err_dm1105_hw_exit
;
877 ret
= dvb_register_adapter(&dev
->dvb_adapter
, DRIVER_NAME
,
878 THIS_MODULE
, &pdev
->dev
, adapter_nr
);
880 goto err_i2c_del_adapter
;
882 dvb_adapter
= &dev
->dvb_adapter
;
884 dm1105_read_mac(dev
, dvb_adapter
->proposed_mac
);
886 dvbdemux
= &dev
->demux
;
887 dvbdemux
->filternum
= 256;
888 dvbdemux
->feednum
= 256;
889 dvbdemux
->start_feed
= dm1105_start_feed
;
890 dvbdemux
->stop_feed
= dm1105_stop_feed
;
891 dvbdemux
->dmx
.capabilities
= (DMX_TS_FILTERING
|
892 DMX_SECTION_FILTERING
| DMX_MEMORY_BASED_FILTERING
);
893 ret
= dvb_dmx_init(dvbdemux
);
895 goto err_dvb_unregister_adapter
;
897 dmx
= &dvbdemux
->dmx
;
898 dev
->dmxdev
.filternum
= 256;
899 dev
->dmxdev
.demux
= dmx
;
900 dev
->dmxdev
.capabilities
= 0;
902 ret
= dvb_dmxdev_init(&dev
->dmxdev
, dvb_adapter
);
904 goto err_dvb_dmx_release
;
906 dev
->hw_frontend
.source
= DMX_FRONTEND_0
;
908 ret
= dmx
->add_frontend(dmx
, &dev
->hw_frontend
);
910 goto err_dvb_dmxdev_release
;
912 dev
->mem_frontend
.source
= DMX_MEMORY_FE
;
914 ret
= dmx
->add_frontend(dmx
, &dev
->mem_frontend
);
916 goto err_remove_hw_frontend
;
918 ret
= dmx
->connect_frontend(dmx
, &dev
->hw_frontend
);
920 goto err_remove_mem_frontend
;
922 ret
= frontend_init(dev
);
924 goto err_disconnect_frontend
;
926 dvb_net_init(dvb_adapter
, &dev
->dvbnet
, dmx
);
929 INIT_WORK(&dev
->work
, dm1105_dmx_buffer
);
930 sprintf(dev
->wqn
, "%s/%d", dvb_adapter
->name
, dvb_adapter
->num
);
931 dev
->wq
= create_singlethread_workqueue(dev
->wqn
);
935 ret
= request_irq(pdev
->irq
, dm1105_irq
, IRQF_SHARED
,
943 destroy_workqueue(dev
->wq
);
945 dvb_net_release(&dev
->dvbnet
);
946 err_disconnect_frontend
:
947 dmx
->disconnect_frontend(dmx
);
948 err_remove_mem_frontend
:
949 dmx
->remove_frontend(dmx
, &dev
->mem_frontend
);
950 err_remove_hw_frontend
:
951 dmx
->remove_frontend(dmx
, &dev
->hw_frontend
);
952 err_dvb_dmxdev_release
:
953 dvb_dmxdev_release(&dev
->dmxdev
);
955 dvb_dmx_release(dvbdemux
);
956 err_dvb_unregister_adapter
:
957 dvb_unregister_adapter(dvb_adapter
);
959 i2c_del_adapter(&dev
->i2c_adap
);
963 pci_iounmap(pdev
, dev
->io_mem
);
964 err_pci_release_regions
:
965 pci_release_regions(pdev
);
966 err_pci_disable_device
:
967 pci_disable_device(pdev
);
969 pci_set_drvdata(pdev
, NULL
);
974 static void __devexit
dm1105_remove(struct pci_dev
*pdev
)
976 struct dm1105_dev
*dev
= pci_get_drvdata(pdev
);
977 struct dvb_adapter
*dvb_adapter
= &dev
->dvb_adapter
;
978 struct dvb_demux
*dvbdemux
= &dev
->demux
;
979 struct dmx_demux
*dmx
= &dvbdemux
->dmx
;
983 dvb_net_release(&dev
->dvbnet
);
985 dvb_unregister_frontend(dev
->fe
);
987 dmx
->disconnect_frontend(dmx
);
988 dmx
->remove_frontend(dmx
, &dev
->mem_frontend
);
989 dmx
->remove_frontend(dmx
, &dev
->hw_frontend
);
990 dvb_dmxdev_release(&dev
->dmxdev
);
991 dvb_dmx_release(dvbdemux
);
992 dvb_unregister_adapter(dvb_adapter
);
994 i2c_del_adapter(&dev
->i2c_adap
);
997 synchronize_irq(pdev
->irq
);
998 free_irq(pdev
->irq
, dev
);
999 pci_iounmap(pdev
, dev
->io_mem
);
1000 pci_release_regions(pdev
);
1001 pci_disable_device(pdev
);
1002 pci_set_drvdata(pdev
, NULL
);
1007 static struct pci_device_id dm1105_id_table
[] __devinitdata
= {
1009 .vendor
= PCI_VENDOR_ID_TRIGEM
,
1010 .device
= PCI_DEVICE_ID_DM1105
,
1011 .subvendor
= PCI_ANY_ID
,
1012 .subdevice
= PCI_ANY_ID
,
1014 .vendor
= PCI_VENDOR_ID_AXESS
,
1015 .device
= PCI_DEVICE_ID_DM05
,
1016 .subvendor
= PCI_ANY_ID
,
1017 .subdevice
= PCI_ANY_ID
,
1023 MODULE_DEVICE_TABLE(pci
, dm1105_id_table
);
1025 static struct pci_driver dm1105_driver
= {
1026 .name
= DRIVER_NAME
,
1027 .id_table
= dm1105_id_table
,
1028 .probe
= dm1105_probe
,
1029 .remove
= __devexit_p(dm1105_remove
),
1032 static int __init
dm1105_init(void)
1034 return pci_register_driver(&dm1105_driver
);
1037 static void __exit
dm1105_exit(void)
1039 pci_unregister_driver(&dm1105_driver
);
1042 module_init(dm1105_init
);
1043 module_exit(dm1105_exit
);
1045 MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
1046 MODULE_DESCRIPTION("SDMC DM1105 DVB driver");
1047 MODULE_LICENSE("GPL");