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"
49 #define DM1105_BOARD_NOAUTO UNSET
50 #define DM1105_BOARD_UNKNOWN 0
51 #define DM1105_BOARD_DVBWORLD_2002 1
52 #define DM1105_BOARD_DVBWORLD_2004 2
53 #define DM1105_BOARD_AXESS_DM05 3
55 /* ----------------------------------------------- */
59 #ifndef PCI_VENDOR_ID_TRIGEM
60 #define PCI_VENDOR_ID_TRIGEM 0x109f
62 #ifndef PCI_VENDOR_ID_AXESS
63 #define PCI_VENDOR_ID_AXESS 0x195d
65 #ifndef PCI_DEVICE_ID_DM1105
66 #define PCI_DEVICE_ID_DM1105 0x036f
68 #ifndef PCI_DEVICE_ID_DW2002
69 #define PCI_DEVICE_ID_DW2002 0x2002
71 #ifndef PCI_DEVICE_ID_DW2004
72 #define PCI_DEVICE_ID_DW2004 0x2004
74 #ifndef PCI_DEVICE_ID_DM05
75 #define PCI_DEVICE_ID_DM05 0x1105
77 /* ----------------------------------------------- */
78 /* sdmc dm1105 registers */
81 #define DM1105_TSCTR 0x00
82 #define DM1105_DTALENTH 0x04
85 #define DM1105_GPIOVAL 0x08
86 #define DM1105_GPIOCTR 0x0c
88 /* PID serial number */
89 #define DM1105_PIDN 0x10
91 /* Odd-even secret key select */
92 #define DM1105_CWSEL 0x14
94 /* Host Command Interface */
95 #define DM1105_HOST_CTR 0x18
96 #define DM1105_HOST_AD 0x1c
99 #define DM1105_CR 0x30
100 #define DM1105_RST 0x34
101 #define DM1105_STADR 0x38
102 #define DM1105_RLEN 0x3c
103 #define DM1105_WRP 0x40
104 #define DM1105_INTCNT 0x44
105 #define DM1105_INTMAK 0x48
106 #define DM1105_INTSTS 0x4c
109 #define DM1105_ODD 0x50
110 #define DM1105_EVEN 0x58
113 #define DM1105_PID 0x60
116 #define DM1105_IRCTR 0x64
117 #define DM1105_IRMODE 0x68
118 #define DM1105_SYSTEMCODE 0x6c
119 #define DM1105_IRCODE 0x70
122 #define DM1105_ENCRYPT 0x74
123 #define DM1105_VER 0x7c
126 #define DM1105_I2CCTR 0x80
127 #define DM1105_I2CSTS 0x81
128 #define DM1105_I2CDAT 0x82
129 #define DM1105_I2C_RA 0x83
130 /* ----------------------------------------------- */
131 /* Interrupt Mask Bits */
133 #define INTMAK_TSIRQM 0x01
134 #define INTMAK_HIRQM 0x04
135 #define INTMAK_IRM 0x08
136 #define INTMAK_ALLMASK (INTMAK_TSIRQM | \
139 #define INTMAK_NONEMASK 0x00
141 /* Interrupt Status Bits */
142 #define INTSTS_TSIRQ 0x01
143 #define INTSTS_HIRQ 0x04
144 #define INTSTS_IR 0x08
146 /* IR Control Bits */
147 #define DM1105_IR_EN 0x01
148 #define DM1105_SYS_CHK 0x02
149 #define DM1105_REP_FLG 0x08
152 #define IIC_24C01_addr 0xa0
153 /* Max board count */
154 #define DM1105_MAX 0x04
156 #define DRIVER_NAME "dm1105"
158 #define DM1105_DMA_PACKETS 47
159 #define DM1105_DMA_PACKET_LENGTH (128*4)
160 #define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS)
162 /* GPIO's for LNB power control */
163 #define DM1105_LNB_MASK 0x00000000
164 #define DM1105_LNB_OFF 0x00020000
165 #define DM1105_LNB_13V 0x00010100
166 #define DM1105_LNB_18V 0x00000100
168 /* GPIO's for LNB power control for Axess DM05 */
169 #define DM05_LNB_MASK 0x00000000
170 #define DM05_LNB_OFF 0x00020000/* actually 13v */
171 #define DM05_LNB_13V 0x00020000
172 #define DM05_LNB_18V 0x00030000
174 static unsigned int card
[] = {[0 ... 3] = UNSET
};
175 module_param_array(card
, int, NULL
, 0444);
176 MODULE_PARM_DESC(card
, "card type");
179 module_param(ir_debug
, int, 0644);
180 MODULE_PARM_DESC(ir_debug
, "enable debugging information for IR decoding");
182 static unsigned int dm1105_devcount
;
184 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
186 struct dm1105_board
{
190 struct dm1105_subid
{
196 static const struct dm1105_board dm1105_boards
[] = {
197 [DM1105_BOARD_UNKNOWN
] = {
198 .name
= "UNKNOWN/GENERIC",
200 [DM1105_BOARD_DVBWORLD_2002
] = {
201 .name
= "DVBWorld PCI 2002",
203 [DM1105_BOARD_DVBWORLD_2004
] = {
204 .name
= "DVBWorld PCI 2004",
206 [DM1105_BOARD_AXESS_DM05
] = {
207 .name
= "Axess/EasyTv DM05",
211 static const struct dm1105_subid dm1105_subids
[] = {
215 .card
= DM1105_BOARD_DVBWORLD_2002
,
219 .card
= DM1105_BOARD_DVBWORLD_2002
,
223 .card
= DM1105_BOARD_DVBWORLD_2004
,
227 .card
= DM1105_BOARD_DVBWORLD_2004
,
231 .card
= DM1105_BOARD_AXESS_DM05
,
235 static void dm1105_card_list(struct pci_dev
*pci
)
239 if (0 == pci
->subsystem_vendor
&&
240 0 == pci
->subsystem_device
) {
242 "dm1105: Your board has no valid PCI Subsystem ID\n"
243 "dm1105: and thus can't be autodetected\n"
244 "dm1105: Please pass card=<n> insmod option to\n"
245 "dm1105: workaround that. Redirect complaints to\n"
246 "dm1105: the vendor of the TV card. Best regards,\n"
250 "dm1105: Your board isn't known (yet) to the driver.\n"
251 "dm1105: You can try to pick one of the existing\n"
252 "dm1105: card configs via card=<n> insmod option.\n"
253 "dm1105: Updating to the latest version might help\n"
254 "dm1105: as well.\n");
256 printk(KERN_ERR
"Here is a list of valid choices for the card=<n> "
258 for (i
= 0; i
< ARRAY_SIZE(dm1105_boards
); i
++)
259 printk(KERN_ERR
"dm1105: card=%d -> %s\n",
260 i
, dm1105_boards
[i
].name
);
263 /* infrared remote control */
265 struct input_dev
*input_dev
;
266 struct ir_input_state ir
;
268 struct work_struct work
;
274 struct pci_dev
*pdev
;
281 struct dmx_frontend hw_frontend
;
282 struct dmx_frontend mem_frontend
;
283 struct dmxdev dmxdev
;
284 struct dvb_adapter dvb_adapter
;
285 struct dvb_demux demux
;
286 struct dvb_frontend
*fe
;
287 struct dvb_net dvbnet
;
288 unsigned int full_ts_users
;
289 unsigned int boardnr
;
293 struct i2c_adapter i2c_adap
;
296 struct work_struct work
;
297 struct workqueue_struct
*wq
;
302 unsigned char *ts_buf
;
306 unsigned int PacketErrorCount
;
311 #define dm_io_mem(reg) ((unsigned long)(&dm1105dvb->io_mem[reg]))
313 static int dm1105_i2c_xfer(struct i2c_adapter
*i2c_adap
,
314 struct i2c_msg
*msgs
, int num
)
316 struct dm1105dvb
*dm1105dvb
;
318 int addr
, rc
, i
, j
, k
, len
, byte
, data
;
321 dm1105dvb
= i2c_adap
->algo_data
;
322 for (i
= 0; i
< num
; i
++) {
323 outb(0x00, dm_io_mem(DM1105_I2CCTR
));
324 if (msgs
[i
].flags
& I2C_M_RD
) {
326 addr
= msgs
[i
].addr
<< 1;
328 outb(addr
, dm_io_mem(DM1105_I2CDAT
));
329 for (byte
= 0; byte
< msgs
[i
].len
; byte
++)
330 outb(0, dm_io_mem(DM1105_I2CDAT
+ byte
+ 1));
332 outb(0x81 + msgs
[i
].len
, dm_io_mem(DM1105_I2CCTR
));
333 for (j
= 0; j
< 55; j
++) {
335 status
= inb(dm_io_mem(DM1105_I2CSTS
));
336 if ((status
& 0xc0) == 0x40)
342 for (byte
= 0; byte
< msgs
[i
].len
; byte
++) {
343 rc
= inb(dm_io_mem(DM1105_I2CDAT
+ byte
+ 1));
346 msgs
[i
].buf
[byte
] = rc
;
349 if ((msgs
[i
].buf
[0] == 0xf7) && (msgs
[i
].addr
== 0x55)) {
350 /* prepaired for cx24116 firmware */
351 /* Write in small blocks */
352 len
= msgs
[i
].len
- 1;
355 outb(msgs
[i
].addr
<< 1, dm_io_mem(DM1105_I2CDAT
));
356 outb(0xf7, dm_io_mem(DM1105_I2CDAT
+ 1));
357 for (byte
= 0; byte
< (len
> 48 ? 48 : len
); byte
++) {
358 data
= msgs
[i
].buf
[k
+byte
];
359 outb(data
, dm_io_mem(DM1105_I2CDAT
+ byte
+ 2));
361 outb(0x82 + (len
> 48 ? 48 : len
), dm_io_mem(DM1105_I2CCTR
));
362 for (j
= 0; j
< 25; j
++) {
364 status
= inb(dm_io_mem(DM1105_I2CSTS
));
365 if ((status
& 0xc0) == 0x40)
377 outb(msgs
[i
].addr
<<1, dm_io_mem(DM1105_I2CDAT
));
378 for (byte
= 0; byte
< msgs
[i
].len
; byte
++) {
379 data
= msgs
[i
].buf
[byte
];
380 outb(data
, dm_io_mem(DM1105_I2CDAT
+ byte
+ 1));
382 outb(0x81 + msgs
[i
].len
, dm_io_mem(DM1105_I2CCTR
));
383 for (j
= 0; j
< 25; j
++) {
385 status
= inb(dm_io_mem(DM1105_I2CSTS
));
386 if ((status
& 0xc0) == 0x40)
400 static u32
functionality(struct i2c_adapter
*adap
)
405 static struct i2c_algorithm dm1105_algo
= {
406 .master_xfer
= dm1105_i2c_xfer
,
407 .functionality
= functionality
,
410 static inline struct dm1105dvb
*feed_to_dm1105dvb(struct dvb_demux_feed
*feed
)
412 return container_of(feed
->demux
, struct dm1105dvb
, demux
);
415 static inline struct dm1105dvb
*frontend_to_dm1105dvb(struct dvb_frontend
*fe
)
417 return container_of(fe
->dvb
, struct dm1105dvb
, dvb_adapter
);
420 static int dm1105dvb_set_voltage(struct dvb_frontend
*fe
, fe_sec_voltage_t voltage
)
422 struct dm1105dvb
*dm1105dvb
= frontend_to_dm1105dvb(fe
);
423 u32 lnb_mask
, lnb_13v
, lnb_18v
, lnb_off
;
425 switch (dm1105dvb
->boardnr
) {
426 case DM1105_BOARD_AXESS_DM05
:
427 lnb_mask
= DM05_LNB_MASK
;
428 lnb_off
= DM05_LNB_OFF
;
429 lnb_13v
= DM05_LNB_13V
;
430 lnb_18v
= DM05_LNB_18V
;
432 case DM1105_BOARD_DVBWORLD_2002
:
433 case DM1105_BOARD_DVBWORLD_2004
:
435 lnb_mask
= DM1105_LNB_MASK
;
436 lnb_off
= DM1105_LNB_OFF
;
437 lnb_13v
= DM1105_LNB_13V
;
438 lnb_18v
= DM1105_LNB_18V
;
441 outl(lnb_mask
, dm_io_mem(DM1105_GPIOCTR
));
442 if (voltage
== SEC_VOLTAGE_18
)
443 outl(lnb_18v
, dm_io_mem(DM1105_GPIOVAL
));
444 else if (voltage
== SEC_VOLTAGE_13
)
445 outl(lnb_13v
, dm_io_mem(DM1105_GPIOVAL
));
447 outl(lnb_off
, dm_io_mem(DM1105_GPIOVAL
));
452 static void dm1105dvb_set_dma_addr(struct dm1105dvb
*dm1105dvb
)
454 outl(cpu_to_le32(dm1105dvb
->dma_addr
), dm_io_mem(DM1105_STADR
));
457 static int __devinit
dm1105dvb_dma_map(struct dm1105dvb
*dm1105dvb
)
459 dm1105dvb
->ts_buf
= pci_alloc_consistent(dm1105dvb
->pdev
, 6*DM1105_DMA_BYTES
, &dm1105dvb
->dma_addr
);
461 return !dm1105dvb
->ts_buf
;
464 static void dm1105dvb_dma_unmap(struct dm1105dvb
*dm1105dvb
)
466 pci_free_consistent(dm1105dvb
->pdev
, 6*DM1105_DMA_BYTES
, dm1105dvb
->ts_buf
, dm1105dvb
->dma_addr
);
469 static void dm1105dvb_enable_irqs(struct dm1105dvb
*dm1105dvb
)
471 outb(INTMAK_ALLMASK
, dm_io_mem(DM1105_INTMAK
));
472 outb(1, dm_io_mem(DM1105_CR
));
475 static void dm1105dvb_disable_irqs(struct dm1105dvb
*dm1105dvb
)
477 outb(INTMAK_IRM
, dm_io_mem(DM1105_INTMAK
));
478 outb(0, dm_io_mem(DM1105_CR
));
481 static int dm1105dvb_start_feed(struct dvb_demux_feed
*f
)
483 struct dm1105dvb
*dm1105dvb
= feed_to_dm1105dvb(f
);
485 if (dm1105dvb
->full_ts_users
++ == 0)
486 dm1105dvb_enable_irqs(dm1105dvb
);
491 static int dm1105dvb_stop_feed(struct dvb_demux_feed
*f
)
493 struct dm1105dvb
*dm1105dvb
= feed_to_dm1105dvb(f
);
495 if (--dm1105dvb
->full_ts_users
== 0)
496 dm1105dvb_disable_irqs(dm1105dvb
);
501 /* ir work handler */
502 static void dm1105_emit_key(struct work_struct
*work
)
504 struct infrared
*ir
= container_of(work
, struct infrared
, work
);
505 u32 ircom
= ir
->ir_command
;
509 printk(KERN_INFO
"%s: received byte 0x%04x\n", __func__
, ircom
);
511 data
= (ircom
>> 8) & 0x7f;
513 ir_input_keydown(ir
->input_dev
, &ir
->ir
, data
, data
);
514 ir_input_nokey(ir
->input_dev
, &ir
->ir
);
518 static void dm1105_dmx_buffer(struct work_struct
*work
)
520 struct dm1105dvb
*dm1105dvb
=
521 container_of(work
, struct dm1105dvb
, work
);
522 unsigned int nbpackets
;
523 u32 oldwrp
= dm1105dvb
->wrp
;
524 u32 nextwrp
= dm1105dvb
->nextwrp
;
526 if (!((dm1105dvb
->ts_buf
[oldwrp
] == 0x47) &&
527 (dm1105dvb
->ts_buf
[oldwrp
+ 188] == 0x47) &&
528 (dm1105dvb
->ts_buf
[oldwrp
+ 188 * 2] == 0x47))) {
529 dm1105dvb
->PacketErrorCount
++;
530 /* bad packet found */
531 if ((dm1105dvb
->PacketErrorCount
>= 2) &&
532 (dm1105dvb
->dmarst
== 0)) {
533 outb(1, dm_io_mem(DM1105_RST
));
535 dm1105dvb
->PacketErrorCount
= 0;
536 dm1105dvb
->dmarst
= 0;
541 if (nextwrp
< oldwrp
) {
542 memcpy(dm1105dvb
->ts_buf
+ dm1105dvb
->buffer_size
,
543 dm1105dvb
->ts_buf
, nextwrp
);
544 nbpackets
= ((dm1105dvb
->buffer_size
- oldwrp
) + nextwrp
) / 188;
546 nbpackets
= (nextwrp
- oldwrp
) / 188;
548 dm1105dvb
->wrp
= nextwrp
;
549 dvb_dmx_swfilter_packets(&dm1105dvb
->demux
,
550 &dm1105dvb
->ts_buf
[oldwrp
], nbpackets
);
553 static irqreturn_t
dm1105dvb_irq(int irq
, void *dev_id
)
555 struct dm1105dvb
*dm1105dvb
= dev_id
;
557 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */
558 unsigned int intsts
= inb(dm_io_mem(DM1105_INTSTS
));
559 outb(intsts
, dm_io_mem(DM1105_INTSTS
));
563 case (INTSTS_TSIRQ
| INTSTS_IR
):
564 dm1105dvb
->nextwrp
= inl(dm_io_mem(DM1105_WRP
)) -
565 inl(dm_io_mem(DM1105_STADR
));
566 queue_work(dm1105dvb
->wq
, &dm1105dvb
->work
);
569 dm1105dvb
->ir
.ir_command
= inl(dm_io_mem(DM1105_IRCODE
));
570 schedule_work(&dm1105dvb
->ir
.work
);
577 int __devinit
dm1105_ir_init(struct dm1105dvb
*dm1105
)
579 struct input_dev
*input_dev
;
580 struct ir_scancode_table
*ir_codes
= &ir_codes_dm1105_nec_table
;
581 int ir_type
= IR_TYPE_OTHER
;
584 input_dev
= input_allocate_device();
588 dm1105
->ir
.input_dev
= input_dev
;
589 snprintf(dm1105
->ir
.input_phys
, sizeof(dm1105
->ir
.input_phys
),
590 "pci-%s/ir0", pci_name(dm1105
->pdev
));
592 ir_input_init(input_dev
, &dm1105
->ir
.ir
, ir_type
, ir_codes
);
593 input_dev
->name
= "DVB on-card IR receiver";
594 input_dev
->phys
= dm1105
->ir
.input_phys
;
595 input_dev
->id
.bustype
= BUS_PCI
;
596 input_dev
->id
.version
= 1;
597 if (dm1105
->pdev
->subsystem_vendor
) {
598 input_dev
->id
.vendor
= dm1105
->pdev
->subsystem_vendor
;
599 input_dev
->id
.product
= dm1105
->pdev
->subsystem_device
;
601 input_dev
->id
.vendor
= dm1105
->pdev
->vendor
;
602 input_dev
->id
.product
= dm1105
->pdev
->device
;
605 input_dev
->dev
.parent
= &dm1105
->pdev
->dev
;
607 INIT_WORK(&dm1105
->ir
.work
, dm1105_emit_key
);
609 err
= input_register_device(input_dev
);
611 input_free_device(input_dev
);
618 void __devexit
dm1105_ir_exit(struct dm1105dvb
*dm1105
)
620 input_unregister_device(dm1105
->ir
.input_dev
);
624 static int __devinit
dm1105dvb_hw_init(struct dm1105dvb
*dm1105dvb
)
626 dm1105dvb_disable_irqs(dm1105dvb
);
628 outb(0, dm_io_mem(DM1105_HOST_CTR
));
631 outb(188, dm_io_mem(DM1105_DTALENTH
));
632 /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/
633 outw(0xc10a, dm_io_mem(DM1105_TSCTR
));
635 /* map DMA and set address */
636 dm1105dvb_dma_map(dm1105dvb
);
637 dm1105dvb_set_dma_addr(dm1105dvb
);
639 outl(5*DM1105_DMA_BYTES
, dm_io_mem(DM1105_RLEN
));
640 outb(47, dm_io_mem(DM1105_INTCNT
));
642 /* IR NEC mode enable */
643 outb((DM1105_IR_EN
| DM1105_SYS_CHK
), dm_io_mem(DM1105_IRCTR
));
644 outb(0, dm_io_mem(DM1105_IRMODE
));
645 outw(0, dm_io_mem(DM1105_SYSTEMCODE
));
650 static void dm1105dvb_hw_exit(struct dm1105dvb
*dm1105dvb
)
652 dm1105dvb_disable_irqs(dm1105dvb
);
655 outb(0, dm_io_mem(DM1105_IRCTR
));
656 outb(INTMAK_NONEMASK
, dm_io_mem(DM1105_INTMAK
));
658 dm1105dvb_dma_unmap(dm1105dvb
);
661 static struct stv0299_config sharp_z0194a_config
= {
662 .demod_address
= 0x68,
663 .inittab
= sharp_z0194a_inittab
,
667 .lock_output
= STV0299_LOCKOUTPUT_1
,
668 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
670 .set_symbol_rate
= sharp_z0194a_set_symbol_rate
,
673 static struct stv0288_config earda_config
= {
674 .demod_address
= 0x68,
678 static struct si21xx_config serit_config
= {
679 .demod_address
= 0x68,
684 static struct cx24116_config serit_sp2633_config
= {
685 .demod_address
= 0x55,
688 static int __devinit
frontend_init(struct dm1105dvb
*dm1105dvb
)
692 switch (dm1105dvb
->boardnr
) {
693 case DM1105_BOARD_DVBWORLD_2004
:
694 dm1105dvb
->fe
= dvb_attach(
695 cx24116_attach
, &serit_sp2633_config
,
696 &dm1105dvb
->i2c_adap
);
698 dm1105dvb
->fe
->ops
.set_voltage
= dm1105dvb_set_voltage
;
701 case DM1105_BOARD_DVBWORLD_2002
:
702 case DM1105_BOARD_AXESS_DM05
:
704 dm1105dvb
->fe
= dvb_attach(
705 stv0299_attach
, &sharp_z0194a_config
,
706 &dm1105dvb
->i2c_adap
);
708 dm1105dvb
->fe
->ops
.set_voltage
=
709 dm1105dvb_set_voltage
;
710 dvb_attach(dvb_pll_attach
, dm1105dvb
->fe
, 0x60,
711 &dm1105dvb
->i2c_adap
, DVB_PLL_OPERA1
);
715 dm1105dvb
->fe
= dvb_attach(
716 stv0288_attach
, &earda_config
,
717 &dm1105dvb
->i2c_adap
);
719 dm1105dvb
->fe
->ops
.set_voltage
=
720 dm1105dvb_set_voltage
;
721 dvb_attach(stb6000_attach
, dm1105dvb
->fe
, 0x61,
722 &dm1105dvb
->i2c_adap
);
726 dm1105dvb
->fe
= dvb_attach(
727 si21xx_attach
, &serit_config
,
728 &dm1105dvb
->i2c_adap
);
730 dm1105dvb
->fe
->ops
.set_voltage
=
731 dm1105dvb_set_voltage
;
735 if (!dm1105dvb
->fe
) {
736 dev_err(&dm1105dvb
->pdev
->dev
, "could not attach frontend\n");
740 ret
= dvb_register_frontend(&dm1105dvb
->dvb_adapter
, dm1105dvb
->fe
);
742 if (dm1105dvb
->fe
->ops
.release
)
743 dm1105dvb
->fe
->ops
.release(dm1105dvb
->fe
);
744 dm1105dvb
->fe
= NULL
;
751 static void __devinit
dm1105dvb_read_mac(struct dm1105dvb
*dm1105dvb
, u8
*mac
)
753 static u8 command
[1] = { 0x28 };
755 struct i2c_msg msg
[] = {
757 .addr
= IIC_24C01_addr
>> 1,
762 .addr
= IIC_24C01_addr
>> 1,
769 dm1105_i2c_xfer(&dm1105dvb
->i2c_adap
, msg
, 2);
770 dev_info(&dm1105dvb
->pdev
->dev
, "MAC %pM\n", mac
);
773 static int __devinit
dm1105_probe(struct pci_dev
*pdev
,
774 const struct pci_device_id
*ent
)
776 struct dm1105dvb
*dm1105dvb
;
777 struct dvb_adapter
*dvb_adapter
;
778 struct dvb_demux
*dvbdemux
;
779 struct dmx_demux
*dmx
;
783 dm1105dvb
= kzalloc(sizeof(struct dm1105dvb
), GFP_KERNEL
);
788 dm1105dvb
->nr
= dm1105_devcount
;
789 dm1105dvb
->boardnr
= UNSET
;
790 if (card
[dm1105dvb
->nr
] < ARRAY_SIZE(dm1105_boards
))
791 dm1105dvb
->boardnr
= card
[dm1105dvb
->nr
];
792 for (i
= 0; UNSET
== dm1105dvb
->boardnr
&&
793 i
< ARRAY_SIZE(dm1105_subids
); i
++)
794 if (pdev
->subsystem_vendor
==
795 dm1105_subids
[i
].subvendor
&&
796 pdev
->subsystem_device
==
797 dm1105_subids
[i
].subdevice
)
798 dm1105dvb
->boardnr
= dm1105_subids
[i
].card
;
800 if (UNSET
== dm1105dvb
->boardnr
) {
801 dm1105dvb
->boardnr
= DM1105_BOARD_UNKNOWN
;
802 dm1105_card_list(pdev
);
806 dm1105dvb
->pdev
= pdev
;
807 dm1105dvb
->buffer_size
= 5 * DM1105_DMA_BYTES
;
808 dm1105dvb
->PacketErrorCount
= 0;
809 dm1105dvb
->dmarst
= 0;
811 ret
= pci_enable_device(pdev
);
815 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
817 goto err_pci_disable_device
;
819 pci_set_master(pdev
);
821 ret
= pci_request_regions(pdev
, DRIVER_NAME
);
823 goto err_pci_disable_device
;
825 dm1105dvb
->io_mem
= pci_iomap(pdev
, 0, pci_resource_len(pdev
, 0));
826 if (!dm1105dvb
->io_mem
) {
828 goto err_pci_release_regions
;
831 spin_lock_init(&dm1105dvb
->lock
);
832 pci_set_drvdata(pdev
, dm1105dvb
);
834 ret
= dm1105dvb_hw_init(dm1105dvb
);
836 goto err_pci_iounmap
;
839 i2c_set_adapdata(&dm1105dvb
->i2c_adap
, dm1105dvb
);
840 strcpy(dm1105dvb
->i2c_adap
.name
, DRIVER_NAME
);
841 dm1105dvb
->i2c_adap
.owner
= THIS_MODULE
;
842 dm1105dvb
->i2c_adap
.class = I2C_CLASS_TV_DIGITAL
;
843 dm1105dvb
->i2c_adap
.dev
.parent
= &pdev
->dev
;
844 dm1105dvb
->i2c_adap
.algo
= &dm1105_algo
;
845 dm1105dvb
->i2c_adap
.algo_data
= dm1105dvb
;
846 ret
= i2c_add_adapter(&dm1105dvb
->i2c_adap
);
849 goto err_dm1105dvb_hw_exit
;
852 ret
= dvb_register_adapter(&dm1105dvb
->dvb_adapter
, DRIVER_NAME
,
853 THIS_MODULE
, &pdev
->dev
, adapter_nr
);
855 goto err_i2c_del_adapter
;
857 dvb_adapter
= &dm1105dvb
->dvb_adapter
;
859 dm1105dvb_read_mac(dm1105dvb
, dvb_adapter
->proposed_mac
);
861 dvbdemux
= &dm1105dvb
->demux
;
862 dvbdemux
->filternum
= 256;
863 dvbdemux
->feednum
= 256;
864 dvbdemux
->start_feed
= dm1105dvb_start_feed
;
865 dvbdemux
->stop_feed
= dm1105dvb_stop_feed
;
866 dvbdemux
->dmx
.capabilities
= (DMX_TS_FILTERING
|
867 DMX_SECTION_FILTERING
| DMX_MEMORY_BASED_FILTERING
);
868 ret
= dvb_dmx_init(dvbdemux
);
870 goto err_dvb_unregister_adapter
;
872 dmx
= &dvbdemux
->dmx
;
873 dm1105dvb
->dmxdev
.filternum
= 256;
874 dm1105dvb
->dmxdev
.demux
= dmx
;
875 dm1105dvb
->dmxdev
.capabilities
= 0;
877 ret
= dvb_dmxdev_init(&dm1105dvb
->dmxdev
, dvb_adapter
);
879 goto err_dvb_dmx_release
;
881 dm1105dvb
->hw_frontend
.source
= DMX_FRONTEND_0
;
883 ret
= dmx
->add_frontend(dmx
, &dm1105dvb
->hw_frontend
);
885 goto err_dvb_dmxdev_release
;
887 dm1105dvb
->mem_frontend
.source
= DMX_MEMORY_FE
;
889 ret
= dmx
->add_frontend(dmx
, &dm1105dvb
->mem_frontend
);
891 goto err_remove_hw_frontend
;
893 ret
= dmx
->connect_frontend(dmx
, &dm1105dvb
->hw_frontend
);
895 goto err_remove_mem_frontend
;
897 ret
= frontend_init(dm1105dvb
);
899 goto err_disconnect_frontend
;
901 dvb_net_init(dvb_adapter
, &dm1105dvb
->dvbnet
, dmx
);
902 dm1105_ir_init(dm1105dvb
);
904 INIT_WORK(&dm1105dvb
->work
, dm1105_dmx_buffer
);
905 sprintf(dm1105dvb
->wqn
, "%s/%d", dvb_adapter
->name
, dvb_adapter
->num
);
906 dm1105dvb
->wq
= create_singlethread_workqueue(dm1105dvb
->wqn
);
910 ret
= request_irq(pdev
->irq
, dm1105dvb_irq
, IRQF_SHARED
,
911 DRIVER_NAME
, dm1105dvb
);
918 destroy_workqueue(dm1105dvb
->wq
);
920 dvb_net_release(&dm1105dvb
->dvbnet
);
921 err_disconnect_frontend
:
922 dmx
->disconnect_frontend(dmx
);
923 err_remove_mem_frontend
:
924 dmx
->remove_frontend(dmx
, &dm1105dvb
->mem_frontend
);
925 err_remove_hw_frontend
:
926 dmx
->remove_frontend(dmx
, &dm1105dvb
->hw_frontend
);
927 err_dvb_dmxdev_release
:
928 dvb_dmxdev_release(&dm1105dvb
->dmxdev
);
930 dvb_dmx_release(dvbdemux
);
931 err_dvb_unregister_adapter
:
932 dvb_unregister_adapter(dvb_adapter
);
934 i2c_del_adapter(&dm1105dvb
->i2c_adap
);
935 err_dm1105dvb_hw_exit
:
936 dm1105dvb_hw_exit(dm1105dvb
);
938 pci_iounmap(pdev
, dm1105dvb
->io_mem
);
939 err_pci_release_regions
:
940 pci_release_regions(pdev
);
941 err_pci_disable_device
:
942 pci_disable_device(pdev
);
944 pci_set_drvdata(pdev
, NULL
);
949 static void __devexit
dm1105_remove(struct pci_dev
*pdev
)
951 struct dm1105dvb
*dm1105dvb
= pci_get_drvdata(pdev
);
952 struct dvb_adapter
*dvb_adapter
= &dm1105dvb
->dvb_adapter
;
953 struct dvb_demux
*dvbdemux
= &dm1105dvb
->demux
;
954 struct dmx_demux
*dmx
= &dvbdemux
->dmx
;
956 dm1105_ir_exit(dm1105dvb
);
958 dvb_net_release(&dm1105dvb
->dvbnet
);
960 dvb_unregister_frontend(dm1105dvb
->fe
);
962 dmx
->disconnect_frontend(dmx
);
963 dmx
->remove_frontend(dmx
, &dm1105dvb
->mem_frontend
);
964 dmx
->remove_frontend(dmx
, &dm1105dvb
->hw_frontend
);
965 dvb_dmxdev_release(&dm1105dvb
->dmxdev
);
966 dvb_dmx_release(dvbdemux
);
967 dvb_unregister_adapter(dvb_adapter
);
968 if (&dm1105dvb
->i2c_adap
)
969 i2c_del_adapter(&dm1105dvb
->i2c_adap
);
971 dm1105dvb_hw_exit(dm1105dvb
);
972 synchronize_irq(pdev
->irq
);
973 free_irq(pdev
->irq
, dm1105dvb
);
974 pci_iounmap(pdev
, dm1105dvb
->io_mem
);
975 pci_release_regions(pdev
);
976 pci_disable_device(pdev
);
977 pci_set_drvdata(pdev
, NULL
);
982 static struct pci_device_id dm1105_id_table
[] __devinitdata
= {
984 .vendor
= PCI_VENDOR_ID_TRIGEM
,
985 .device
= PCI_DEVICE_ID_DM1105
,
986 .subvendor
= PCI_ANY_ID
,
987 .subdevice
= PCI_ANY_ID
,
989 .vendor
= PCI_VENDOR_ID_AXESS
,
990 .device
= PCI_DEVICE_ID_DM05
,
991 .subvendor
= PCI_ANY_ID
,
992 .subdevice
= PCI_ANY_ID
,
998 MODULE_DEVICE_TABLE(pci
, dm1105_id_table
);
1000 static struct pci_driver dm1105_driver
= {
1001 .name
= DRIVER_NAME
,
1002 .id_table
= dm1105_id_table
,
1003 .probe
= dm1105_probe
,
1004 .remove
= __devexit_p(dm1105_remove
),
1007 static int __init
dm1105_init(void)
1009 return pci_register_driver(&dm1105_driver
);
1012 static void __exit
dm1105_exit(void)
1014 pci_unregister_driver(&dm1105_driver
);
1017 module_init(dm1105_init
);
1018 module_exit(dm1105_exit
);
1020 MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
1021 MODULE_DESCRIPTION("SDMC DM1105 DVB driver");
1022 MODULE_LICENSE("GPL");