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.
18 #include <linux/i2c.h>
19 #include <linux/i2c-algo-bit.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/proc_fs.h>
25 #include <linux/pci.h>
26 #include <linux/dma-mapping.h>
27 #include <linux/slab.h>
28 #include <media/rc-core.h>
30 #include <media/demux.h>
31 #include <media/dmxdev.h>
32 #include <media/dvb_demux.h>
33 #include <media/dvb_frontend.h>
34 #include <media/dvb_net.h>
35 #include <media/dvbdev.h>
47 #define MODULE_NAME "dm1105"
51 #define DM1105_BOARD_NOAUTO UNSET
52 #define DM1105_BOARD_UNKNOWN 0
53 #define DM1105_BOARD_DVBWORLD_2002 1
54 #define DM1105_BOARD_DVBWORLD_2004 2
55 #define DM1105_BOARD_AXESS_DM05 3
56 #define DM1105_BOARD_UNBRANDED_I2C_ON_GPIO 4
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"
160 #define DM1105_I2C_GPIO_NAME "dm1105-gpio"
162 #define DM1105_DMA_PACKETS 47
163 #define DM1105_DMA_PACKET_LENGTH (128*4)
164 #define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS)
167 #define GPIO08 (1 << 8)
168 #define GPIO13 (1 << 13)
169 #define GPIO14 (1 << 14)
170 #define GPIO15 (1 << 15)
171 #define GPIO16 (1 << 16)
172 #define GPIO17 (1 << 17)
173 #define GPIO_ALL 0x03ffff
175 /* GPIO's for LNB power control */
176 #define DM1105_LNB_MASK (GPIO_ALL & ~(GPIO14 | GPIO13))
177 #define DM1105_LNB_OFF GPIO17
178 #define DM1105_LNB_13V (GPIO16 | GPIO08)
179 #define DM1105_LNB_18V GPIO08
181 /* GPIO's for LNB power control for Axess DM05 */
182 #define DM05_LNB_MASK (GPIO_ALL & ~(GPIO14 | GPIO13))
183 #define DM05_LNB_OFF GPIO17/* actually 13v */
184 #define DM05_LNB_13V GPIO17
185 #define DM05_LNB_18V (GPIO17 | GPIO16)
187 /* GPIO's for LNB power control for unbranded with I2C on GPIO */
188 #define UNBR_LNB_MASK (GPIO17 | GPIO16)
189 #define UNBR_LNB_OFF 0
190 #define UNBR_LNB_13V GPIO17
191 #define UNBR_LNB_18V (GPIO17 | GPIO16)
193 static unsigned int card
[] = {[0 ... 3] = UNSET
};
194 module_param_array(card
, int, NULL
, 0444);
195 MODULE_PARM_DESC(card
, "card type");
198 module_param(ir_debug
, int, 0644);
199 MODULE_PARM_DESC(ir_debug
, "enable debugging information for IR decoding");
201 static unsigned int dm1105_devcount
;
203 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
205 struct dm1105_board
{
208 u32 mask
, off
, v13
, v18
;
210 u32 gpio_scl
, gpio_sda
;
213 struct dm1105_subid
{
219 static const struct dm1105_board dm1105_boards
[] = {
220 [DM1105_BOARD_UNKNOWN
] = {
221 .name
= "UNKNOWN/GENERIC",
223 .mask
= DM1105_LNB_MASK
,
224 .off
= DM1105_LNB_OFF
,
225 .v13
= DM1105_LNB_13V
,
226 .v18
= DM1105_LNB_18V
,
229 [DM1105_BOARD_DVBWORLD_2002
] = {
230 .name
= "DVBWorld PCI 2002",
232 .mask
= DM1105_LNB_MASK
,
233 .off
= DM1105_LNB_OFF
,
234 .v13
= DM1105_LNB_13V
,
235 .v18
= DM1105_LNB_18V
,
238 [DM1105_BOARD_DVBWORLD_2004
] = {
239 .name
= "DVBWorld PCI 2004",
241 .mask
= DM1105_LNB_MASK
,
242 .off
= DM1105_LNB_OFF
,
243 .v13
= DM1105_LNB_13V
,
244 .v18
= DM1105_LNB_18V
,
247 [DM1105_BOARD_AXESS_DM05
] = {
248 .name
= "Axess/EasyTv DM05",
250 .mask
= DM05_LNB_MASK
,
256 [DM1105_BOARD_UNBRANDED_I2C_ON_GPIO
] = {
257 .name
= "Unbranded DM1105 with i2c on GPIOs",
259 .mask
= UNBR_LNB_MASK
,
269 static const struct dm1105_subid dm1105_subids
[] = {
273 .card
= DM1105_BOARD_DVBWORLD_2002
,
277 .card
= DM1105_BOARD_DVBWORLD_2002
,
281 .card
= DM1105_BOARD_DVBWORLD_2004
,
285 .card
= DM1105_BOARD_DVBWORLD_2004
,
289 .card
= DM1105_BOARD_AXESS_DM05
,
293 static void dm1105_card_list(struct pci_dev
*pci
)
297 if (0 == pci
->subsystem_vendor
&&
298 0 == pci
->subsystem_device
) {
300 "dm1105: Your board has no valid PCI Subsystem ID\n"
301 "dm1105: and thus can't be autodetected\n"
302 "dm1105: Please pass card=<n> insmod option to\n"
303 "dm1105: workaround that. Redirect complaints to\n"
304 "dm1105: the vendor of the TV card. Best regards,\n"
308 "dm1105: Your board isn't known (yet) to the driver.\n"
309 "dm1105: You can try to pick one of the existing\n"
310 "dm1105: card configs via card=<n> insmod option.\n"
311 "dm1105: Updating to the latest version might help\n"
312 "dm1105: as well.\n");
314 printk(KERN_ERR
"Here is a list of valid choices for the card=<n> insmod option:\n");
315 for (i
= 0; i
< ARRAY_SIZE(dm1105_boards
); i
++)
316 printk(KERN_ERR
"dm1105: card=%d -> %s\n",
317 i
, dm1105_boards
[i
].name
);
320 /* infrared remote control */
324 struct work_struct work
;
330 struct pci_dev
*pdev
;
337 struct dmx_frontend hw_frontend
;
338 struct dmx_frontend mem_frontend
;
339 struct dmxdev dmxdev
;
340 struct dvb_adapter dvb_adapter
;
341 struct dvb_demux demux
;
342 struct dvb_frontend
*fe
;
343 struct dvb_net dvbnet
;
344 unsigned int full_ts_users
;
345 unsigned int boardnr
;
349 struct i2c_adapter i2c_adap
;
350 struct i2c_adapter i2c_bb_adap
;
351 struct i2c_algo_bit_data i2c_bit
;
354 struct work_struct work
;
355 struct workqueue_struct
*wq
;
360 unsigned char *ts_buf
;
364 unsigned int PacketErrorCount
;
369 #define dm_io_mem(reg) ((unsigned long)(&dev->io_mem[reg]))
371 #define dm_readb(reg) inb(dm_io_mem(reg))
372 #define dm_writeb(reg, value) outb((value), (dm_io_mem(reg)))
374 #define dm_readw(reg) inw(dm_io_mem(reg))
375 #define dm_writew(reg, value) outw((value), (dm_io_mem(reg)))
377 #define dm_readl(reg) inl(dm_io_mem(reg))
378 #define dm_writel(reg, value) outl((value), (dm_io_mem(reg)))
380 #define dm_andorl(reg, mask, value) \
381 outl((inl(dm_io_mem(reg)) & ~(mask)) |\
382 ((value) & (mask)), (dm_io_mem(reg)))
384 #define dm_setl(reg, bit) dm_andorl((reg), (bit), (bit))
385 #define dm_clearl(reg, bit) dm_andorl((reg), (bit), 0)
387 /* The chip has 18 GPIOs. In HOST mode GPIO's used as 15 bit address lines,
388 so we can use only 3 GPIO's from GPIO15 to GPIO17.
389 Here I don't check whether HOST is enebled as it is not implemented yet.
391 static void dm1105_gpio_set(struct dm1105_dev
*dev
, u32 mask
)
393 if (mask
& 0xfffc0000)
394 printk(KERN_ERR
"%s: Only 18 GPIO's are allowed\n", __func__
);
396 if (mask
& 0x0003ffff)
397 dm_setl(DM1105_GPIOVAL
, mask
& 0x0003ffff);
401 static void dm1105_gpio_clear(struct dm1105_dev
*dev
, u32 mask
)
403 if (mask
& 0xfffc0000)
404 printk(KERN_ERR
"%s: Only 18 GPIO's are allowed\n", __func__
);
406 if (mask
& 0x0003ffff)
407 dm_clearl(DM1105_GPIOVAL
, mask
& 0x0003ffff);
411 static void dm1105_gpio_andor(struct dm1105_dev
*dev
, u32 mask
, u32 val
)
413 if (mask
& 0xfffc0000)
414 printk(KERN_ERR
"%s: Only 18 GPIO's are allowed\n", __func__
);
416 if (mask
& 0x0003ffff)
417 dm_andorl(DM1105_GPIOVAL
, mask
& 0x0003ffff, val
);
421 static u32
dm1105_gpio_get(struct dm1105_dev
*dev
, u32 mask
)
423 if (mask
& 0xfffc0000)
424 printk(KERN_ERR
"%s: Only 18 GPIO's are allowed\n", __func__
);
426 if (mask
& 0x0003ffff)
427 return dm_readl(DM1105_GPIOVAL
) & mask
& 0x0003ffff;
432 static void dm1105_gpio_enable(struct dm1105_dev
*dev
, u32 mask
, int asoutput
)
434 if (mask
& 0xfffc0000)
435 printk(KERN_ERR
"%s: Only 18 GPIO's are allowed\n", __func__
);
437 if ((mask
& 0x0003ffff) && asoutput
)
438 dm_clearl(DM1105_GPIOCTR
, mask
& 0x0003ffff);
439 else if ((mask
& 0x0003ffff) && !asoutput
)
440 dm_setl(DM1105_GPIOCTR
, mask
& 0x0003ffff);
444 static void dm1105_setline(struct dm1105_dev
*dev
, u32 line
, int state
)
447 dm1105_gpio_enable(dev
, line
, 0);
449 dm1105_gpio_enable(dev
, line
, 1);
450 dm1105_gpio_clear(dev
, line
);
454 static void dm1105_setsda(void *data
, int state
)
456 struct dm1105_dev
*dev
= data
;
458 dm1105_setline(dev
, dm1105_boards
[dev
->boardnr
].gpio_sda
, state
);
461 static void dm1105_setscl(void *data
, int state
)
463 struct dm1105_dev
*dev
= data
;
465 dm1105_setline(dev
, dm1105_boards
[dev
->boardnr
].gpio_scl
, state
);
468 static int dm1105_getsda(void *data
)
470 struct dm1105_dev
*dev
= data
;
472 return dm1105_gpio_get(dev
, dm1105_boards
[dev
->boardnr
].gpio_sda
)
476 static int dm1105_getscl(void *data
)
478 struct dm1105_dev
*dev
= data
;
480 return dm1105_gpio_get(dev
, dm1105_boards
[dev
->boardnr
].gpio_scl
)
484 static int dm1105_i2c_xfer(struct i2c_adapter
*i2c_adap
,
485 struct i2c_msg
*msgs
, int num
)
487 struct dm1105_dev
*dev
;
489 int addr
, rc
, i
, j
, k
, len
, byte
, data
;
492 dev
= i2c_adap
->algo_data
;
493 for (i
= 0; i
< num
; i
++) {
494 dm_writeb(DM1105_I2CCTR
, 0x00);
495 if (msgs
[i
].flags
& I2C_M_RD
) {
497 addr
= msgs
[i
].addr
<< 1;
499 dm_writeb(DM1105_I2CDAT
, addr
);
500 for (byte
= 0; byte
< msgs
[i
].len
; byte
++)
501 dm_writeb(DM1105_I2CDAT
+ byte
+ 1, 0);
503 dm_writeb(DM1105_I2CCTR
, 0x81 + msgs
[i
].len
);
504 for (j
= 0; j
< 55; j
++) {
506 status
= dm_readb(DM1105_I2CSTS
);
507 if ((status
& 0xc0) == 0x40)
513 for (byte
= 0; byte
< msgs
[i
].len
; byte
++) {
514 rc
= dm_readb(DM1105_I2CDAT
+ byte
+ 1);
517 msgs
[i
].buf
[byte
] = rc
;
519 } else if ((msgs
[i
].buf
[0] == 0xf7) && (msgs
[i
].addr
== 0x55)) {
520 /* prepaired for cx24116 firmware */
521 /* Write in small blocks */
522 len
= msgs
[i
].len
- 1;
525 dm_writeb(DM1105_I2CDAT
, msgs
[i
].addr
<< 1);
526 dm_writeb(DM1105_I2CDAT
+ 1, 0xf7);
527 for (byte
= 0; byte
< (len
> 48 ? 48 : len
); byte
++) {
528 data
= msgs
[i
].buf
[k
+ byte
];
529 dm_writeb(DM1105_I2CDAT
+ byte
+ 2, data
);
531 dm_writeb(DM1105_I2CCTR
, 0x82 + (len
> 48 ? 48 : len
));
532 for (j
= 0; j
< 25; j
++) {
534 status
= dm_readb(DM1105_I2CSTS
);
535 if ((status
& 0xc0) == 0x40)
547 dm_writeb(DM1105_I2CDAT
, msgs
[i
].addr
<< 1);
548 for (byte
= 0; byte
< msgs
[i
].len
; byte
++) {
549 data
= msgs
[i
].buf
[byte
];
550 dm_writeb(DM1105_I2CDAT
+ byte
+ 1, data
);
552 dm_writeb(DM1105_I2CCTR
, 0x81 + msgs
[i
].len
);
553 for (j
= 0; j
< 25; j
++) {
555 status
= dm_readb(DM1105_I2CSTS
);
556 if ((status
& 0xc0) == 0x40)
569 static u32
functionality(struct i2c_adapter
*adap
)
574 static const struct i2c_algorithm dm1105_algo
= {
575 .master_xfer
= dm1105_i2c_xfer
,
576 .functionality
= functionality
,
579 static inline struct dm1105_dev
*feed_to_dm1105_dev(struct dvb_demux_feed
*feed
)
581 return container_of(feed
->demux
, struct dm1105_dev
, demux
);
584 static inline struct dm1105_dev
*frontend_to_dm1105_dev(struct dvb_frontend
*fe
)
586 return container_of(fe
->dvb
, struct dm1105_dev
, dvb_adapter
);
589 static int dm1105_set_voltage(struct dvb_frontend
*fe
,
590 enum fe_sec_voltage voltage
)
592 struct dm1105_dev
*dev
= frontend_to_dm1105_dev(fe
);
594 dm1105_gpio_enable(dev
, dm1105_boards
[dev
->boardnr
].lnb
.mask
, 1);
595 if (voltage
== SEC_VOLTAGE_18
)
596 dm1105_gpio_andor(dev
,
597 dm1105_boards
[dev
->boardnr
].lnb
.mask
,
598 dm1105_boards
[dev
->boardnr
].lnb
.v18
);
599 else if (voltage
== SEC_VOLTAGE_13
)
600 dm1105_gpio_andor(dev
,
601 dm1105_boards
[dev
->boardnr
].lnb
.mask
,
602 dm1105_boards
[dev
->boardnr
].lnb
.v13
);
604 dm1105_gpio_andor(dev
,
605 dm1105_boards
[dev
->boardnr
].lnb
.mask
,
606 dm1105_boards
[dev
->boardnr
].lnb
.off
);
611 static void dm1105_set_dma_addr(struct dm1105_dev
*dev
)
613 dm_writel(DM1105_STADR
, (__force u32
)cpu_to_le32(dev
->dma_addr
));
616 static int dm1105_dma_map(struct dm1105_dev
*dev
)
618 dev
->ts_buf
= pci_alloc_consistent(dev
->pdev
,
619 6 * DM1105_DMA_BYTES
,
625 static void dm1105_dma_unmap(struct dm1105_dev
*dev
)
627 pci_free_consistent(dev
->pdev
,
628 6 * DM1105_DMA_BYTES
,
633 static void dm1105_enable_irqs(struct dm1105_dev
*dev
)
635 dm_writeb(DM1105_INTMAK
, INTMAK_ALLMASK
);
636 dm_writeb(DM1105_CR
, 1);
639 static void dm1105_disable_irqs(struct dm1105_dev
*dev
)
641 dm_writeb(DM1105_INTMAK
, INTMAK_IRM
);
642 dm_writeb(DM1105_CR
, 0);
645 static int dm1105_start_feed(struct dvb_demux_feed
*f
)
647 struct dm1105_dev
*dev
= feed_to_dm1105_dev(f
);
649 if (dev
->full_ts_users
++ == 0)
650 dm1105_enable_irqs(dev
);
655 static int dm1105_stop_feed(struct dvb_demux_feed
*f
)
657 struct dm1105_dev
*dev
= feed_to_dm1105_dev(f
);
659 if (--dev
->full_ts_users
== 0)
660 dm1105_disable_irqs(dev
);
665 /* ir work handler */
666 static void dm1105_emit_key(struct work_struct
*work
)
668 struct infrared
*ir
= container_of(work
, struct infrared
, work
);
669 u32 ircom
= ir
->ir_command
;
673 printk(KERN_INFO
"%s: received byte 0x%04x\n", __func__
, ircom
);
675 data
= (ircom
>> 8) & 0x7f;
677 /* FIXME: UNKNOWN because we don't generate a full NEC scancode (yet?) */
678 rc_keydown(ir
->dev
, RC_PROTO_UNKNOWN
, data
, 0);
682 static void dm1105_dmx_buffer(struct work_struct
*work
)
684 struct dm1105_dev
*dev
= container_of(work
, struct dm1105_dev
, work
);
685 unsigned int nbpackets
;
686 u32 oldwrp
= dev
->wrp
;
687 u32 nextwrp
= dev
->nextwrp
;
689 if (!((dev
->ts_buf
[oldwrp
] == 0x47) &&
690 (dev
->ts_buf
[oldwrp
+ 188] == 0x47) &&
691 (dev
->ts_buf
[oldwrp
+ 188 * 2] == 0x47))) {
692 dev
->PacketErrorCount
++;
693 /* bad packet found */
694 if ((dev
->PacketErrorCount
>= 2) &&
695 (dev
->dmarst
== 0)) {
696 dm_writeb(DM1105_RST
, 1);
698 dev
->PacketErrorCount
= 0;
704 if (nextwrp
< oldwrp
) {
705 memcpy(dev
->ts_buf
+ dev
->buffer_size
, dev
->ts_buf
, nextwrp
);
706 nbpackets
= ((dev
->buffer_size
- oldwrp
) + nextwrp
) / 188;
708 nbpackets
= (nextwrp
- oldwrp
) / 188;
711 dvb_dmx_swfilter_packets(&dev
->demux
, &dev
->ts_buf
[oldwrp
], nbpackets
);
714 static irqreturn_t
dm1105_irq(int irq
, void *dev_id
)
716 struct dm1105_dev
*dev
= dev_id
;
718 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */
719 unsigned int intsts
= dm_readb(DM1105_INTSTS
);
720 dm_writeb(DM1105_INTSTS
, intsts
);
724 case (INTSTS_TSIRQ
| INTSTS_IR
):
725 dev
->nextwrp
= dm_readl(DM1105_WRP
) - dm_readl(DM1105_STADR
);
726 queue_work(dev
->wq
, &dev
->work
);
729 dev
->ir
.ir_command
= dm_readl(DM1105_IRCODE
);
730 schedule_work(&dev
->ir
.work
);
737 static int dm1105_ir_init(struct dm1105_dev
*dm1105
)
742 dev
= rc_allocate_device(RC_DRIVER_SCANCODE
);
746 snprintf(dm1105
->ir
.input_phys
, sizeof(dm1105
->ir
.input_phys
),
747 "pci-%s/ir0", pci_name(dm1105
->pdev
));
749 dev
->driver_name
= MODULE_NAME
;
750 dev
->map_name
= RC_MAP_DM1105_NEC
;
751 dev
->device_name
= "DVB on-card IR receiver";
752 dev
->input_phys
= dm1105
->ir
.input_phys
;
753 dev
->input_id
.bustype
= BUS_PCI
;
754 dev
->input_id
.version
= 1;
755 if (dm1105
->pdev
->subsystem_vendor
) {
756 dev
->input_id
.vendor
= dm1105
->pdev
->subsystem_vendor
;
757 dev
->input_id
.product
= dm1105
->pdev
->subsystem_device
;
759 dev
->input_id
.vendor
= dm1105
->pdev
->vendor
;
760 dev
->input_id
.product
= dm1105
->pdev
->device
;
762 dev
->dev
.parent
= &dm1105
->pdev
->dev
;
764 INIT_WORK(&dm1105
->ir
.work
, dm1105_emit_key
);
766 err
= rc_register_device(dev
);
772 dm1105
->ir
.dev
= dev
;
776 static void dm1105_ir_exit(struct dm1105_dev
*dm1105
)
778 rc_unregister_device(dm1105
->ir
.dev
);
781 static int dm1105_hw_init(struct dm1105_dev
*dev
)
783 dm1105_disable_irqs(dev
);
785 dm_writeb(DM1105_HOST_CTR
, 0);
788 dm_writeb(DM1105_DTALENTH
, 188);
789 /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/
790 dm_writew(DM1105_TSCTR
, 0xc10a);
792 /* map DMA and set address */
794 dm1105_set_dma_addr(dev
);
796 dm_writel(DM1105_RLEN
, 5 * DM1105_DMA_BYTES
);
797 dm_writeb(DM1105_INTCNT
, 47);
799 /* IR NEC mode enable */
800 dm_writeb(DM1105_IRCTR
, (DM1105_IR_EN
| DM1105_SYS_CHK
));
801 dm_writeb(DM1105_IRMODE
, 0);
802 dm_writew(DM1105_SYSTEMCODE
, 0);
807 static void dm1105_hw_exit(struct dm1105_dev
*dev
)
809 dm1105_disable_irqs(dev
);
812 dm_writeb(DM1105_IRCTR
, 0);
813 dm_writeb(DM1105_INTMAK
, INTMAK_NONEMASK
);
815 dm1105_dma_unmap(dev
);
818 static const struct stv0299_config sharp_z0194a_config
= {
819 .demod_address
= 0x68,
820 .inittab
= sharp_z0194a_inittab
,
824 .lock_output
= STV0299_LOCKOUTPUT_1
,
825 .volt13_op0_op1
= STV0299_VOLT13_OP1
,
827 .set_symbol_rate
= sharp_z0194a_set_symbol_rate
,
830 static struct stv0288_config earda_config
= {
831 .demod_address
= 0x68,
835 static struct si21xx_config serit_config
= {
836 .demod_address
= 0x68,
841 static struct cx24116_config serit_sp2633_config
= {
842 .demod_address
= 0x55,
845 static struct ds3000_config dvbworld_ds3000_config
= {
846 .demod_address
= 0x68,
849 static struct ts2020_config dvbworld_ts2020_config
= {
850 .tuner_address
= 0x60,
854 static int frontend_init(struct dm1105_dev
*dev
)
858 switch (dev
->boardnr
) {
859 case DM1105_BOARD_UNBRANDED_I2C_ON_GPIO
:
860 dm1105_gpio_enable(dev
, GPIO15
, 1);
861 dm1105_gpio_clear(dev
, GPIO15
);
863 dm1105_gpio_set(dev
, GPIO15
);
865 dev
->fe
= dvb_attach(
866 stv0299_attach
, &sharp_z0194a_config
,
869 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
870 dvb_attach(dvb_pll_attach
, dev
->fe
, 0x60,
871 &dev
->i2c_bb_adap
, DVB_PLL_OPERA1
);
875 dev
->fe
= dvb_attach(
876 stv0288_attach
, &earda_config
,
879 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
880 dvb_attach(stb6000_attach
, dev
->fe
, 0x61,
885 dev
->fe
= dvb_attach(
886 si21xx_attach
, &serit_config
,
889 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
891 case DM1105_BOARD_DVBWORLD_2004
:
892 dev
->fe
= dvb_attach(
893 cx24116_attach
, &serit_sp2633_config
,
896 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
900 dev
->fe
= dvb_attach(
901 ds3000_attach
, &dvbworld_ds3000_config
,
904 dvb_attach(ts2020_attach
, dev
->fe
,
905 &dvbworld_ts2020_config
, &dev
->i2c_adap
);
906 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
910 case DM1105_BOARD_DVBWORLD_2002
:
911 case DM1105_BOARD_AXESS_DM05
:
913 dev
->fe
= dvb_attach(
914 stv0299_attach
, &sharp_z0194a_config
,
917 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
918 dvb_attach(dvb_pll_attach
, dev
->fe
, 0x60,
919 &dev
->i2c_adap
, DVB_PLL_OPERA1
);
923 dev
->fe
= dvb_attach(
924 stv0288_attach
, &earda_config
,
927 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
928 dvb_attach(stb6000_attach
, dev
->fe
, 0x61,
933 dev
->fe
= dvb_attach(
934 si21xx_attach
, &serit_config
,
937 dev
->fe
->ops
.set_voltage
= dm1105_set_voltage
;
942 dev_err(&dev
->pdev
->dev
, "could not attach frontend\n");
946 ret
= dvb_register_frontend(&dev
->dvb_adapter
, dev
->fe
);
948 if (dev
->fe
->ops
.release
)
949 dev
->fe
->ops
.release(dev
->fe
);
957 static void dm1105_read_mac(struct dm1105_dev
*dev
, u8
*mac
)
959 static u8 command
[1] = { 0x28 };
961 struct i2c_msg msg
[] = {
963 .addr
= IIC_24C01_addr
>> 1,
968 .addr
= IIC_24C01_addr
>> 1,
975 dm1105_i2c_xfer(&dev
->i2c_adap
, msg
, 2);
976 dev_info(&dev
->pdev
->dev
, "MAC %pM\n", mac
);
979 static int dm1105_probe(struct pci_dev
*pdev
,
980 const struct pci_device_id
*ent
)
982 struct dm1105_dev
*dev
;
983 struct dvb_adapter
*dvb_adapter
;
984 struct dvb_demux
*dvbdemux
;
985 struct dmx_demux
*dmx
;
989 dev
= kzalloc(sizeof(struct dm1105_dev
), GFP_KERNEL
);
994 dev
->nr
= dm1105_devcount
;
995 dev
->boardnr
= UNSET
;
996 if (card
[dev
->nr
] < ARRAY_SIZE(dm1105_boards
))
997 dev
->boardnr
= card
[dev
->nr
];
998 for (i
= 0; UNSET
== dev
->boardnr
&&
999 i
< ARRAY_SIZE(dm1105_subids
); i
++)
1000 if (pdev
->subsystem_vendor
==
1001 dm1105_subids
[i
].subvendor
&&
1002 pdev
->subsystem_device
==
1003 dm1105_subids
[i
].subdevice
)
1004 dev
->boardnr
= dm1105_subids
[i
].card
;
1006 if (UNSET
== dev
->boardnr
) {
1007 dev
->boardnr
= DM1105_BOARD_UNKNOWN
;
1008 dm1105_card_list(pdev
);
1013 dev
->buffer_size
= 5 * DM1105_DMA_BYTES
;
1014 dev
->PacketErrorCount
= 0;
1017 ret
= pci_enable_device(pdev
);
1021 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
1023 goto err_pci_disable_device
;
1025 pci_set_master(pdev
);
1027 ret
= pci_request_regions(pdev
, DRIVER_NAME
);
1029 goto err_pci_disable_device
;
1031 dev
->io_mem
= pci_iomap(pdev
, 0, pci_resource_len(pdev
, 0));
1034 goto err_pci_release_regions
;
1037 spin_lock_init(&dev
->lock
);
1038 pci_set_drvdata(pdev
, dev
);
1040 ret
= dm1105_hw_init(dev
);
1042 goto err_pci_iounmap
;
1045 i2c_set_adapdata(&dev
->i2c_adap
, dev
);
1046 strcpy(dev
->i2c_adap
.name
, DRIVER_NAME
);
1047 dev
->i2c_adap
.owner
= THIS_MODULE
;
1048 dev
->i2c_adap
.dev
.parent
= &pdev
->dev
;
1049 dev
->i2c_adap
.algo
= &dm1105_algo
;
1050 dev
->i2c_adap
.algo_data
= dev
;
1051 ret
= i2c_add_adapter(&dev
->i2c_adap
);
1054 goto err_dm1105_hw_exit
;
1056 i2c_set_adapdata(&dev
->i2c_bb_adap
, dev
);
1057 strcpy(dev
->i2c_bb_adap
.name
, DM1105_I2C_GPIO_NAME
);
1058 dev
->i2c_bb_adap
.owner
= THIS_MODULE
;
1059 dev
->i2c_bb_adap
.dev
.parent
= &pdev
->dev
;
1060 dev
->i2c_bb_adap
.algo_data
= &dev
->i2c_bit
;
1061 dev
->i2c_bit
.data
= dev
;
1062 dev
->i2c_bit
.setsda
= dm1105_setsda
;
1063 dev
->i2c_bit
.setscl
= dm1105_setscl
;
1064 dev
->i2c_bit
.getsda
= dm1105_getsda
;
1065 dev
->i2c_bit
.getscl
= dm1105_getscl
;
1066 dev
->i2c_bit
.udelay
= 10;
1067 dev
->i2c_bit
.timeout
= 10;
1069 /* Raise SCL and SDA */
1070 dm1105_setsda(dev
, 1);
1071 dm1105_setscl(dev
, 1);
1073 ret
= i2c_bit_add_bus(&dev
->i2c_bb_adap
);
1075 goto err_i2c_del_adapter
;
1078 ret
= dvb_register_adapter(&dev
->dvb_adapter
, DRIVER_NAME
,
1079 THIS_MODULE
, &pdev
->dev
, adapter_nr
);
1081 goto err_i2c_del_adapters
;
1083 dvb_adapter
= &dev
->dvb_adapter
;
1085 dm1105_read_mac(dev
, dvb_adapter
->proposed_mac
);
1087 dvbdemux
= &dev
->demux
;
1088 dvbdemux
->filternum
= 256;
1089 dvbdemux
->feednum
= 256;
1090 dvbdemux
->start_feed
= dm1105_start_feed
;
1091 dvbdemux
->stop_feed
= dm1105_stop_feed
;
1092 dvbdemux
->dmx
.capabilities
= (DMX_TS_FILTERING
|
1093 DMX_SECTION_FILTERING
| DMX_MEMORY_BASED_FILTERING
);
1094 ret
= dvb_dmx_init(dvbdemux
);
1096 goto err_dvb_unregister_adapter
;
1098 dmx
= &dvbdemux
->dmx
;
1099 dev
->dmxdev
.filternum
= 256;
1100 dev
->dmxdev
.demux
= dmx
;
1101 dev
->dmxdev
.capabilities
= 0;
1103 ret
= dvb_dmxdev_init(&dev
->dmxdev
, dvb_adapter
);
1105 goto err_dvb_dmx_release
;
1107 dev
->hw_frontend
.source
= DMX_FRONTEND_0
;
1109 ret
= dmx
->add_frontend(dmx
, &dev
->hw_frontend
);
1111 goto err_dvb_dmxdev_release
;
1113 dev
->mem_frontend
.source
= DMX_MEMORY_FE
;
1115 ret
= dmx
->add_frontend(dmx
, &dev
->mem_frontend
);
1117 goto err_remove_hw_frontend
;
1119 ret
= dmx
->connect_frontend(dmx
, &dev
->hw_frontend
);
1121 goto err_remove_mem_frontend
;
1123 ret
= dvb_net_init(dvb_adapter
, &dev
->dvbnet
, dmx
);
1125 goto err_disconnect_frontend
;
1127 ret
= frontend_init(dev
);
1131 dm1105_ir_init(dev
);
1133 INIT_WORK(&dev
->work
, dm1105_dmx_buffer
);
1134 sprintf(dev
->wqn
, "%s/%d", dvb_adapter
->name
, dvb_adapter
->num
);
1135 dev
->wq
= create_singlethread_workqueue(dev
->wqn
);
1141 ret
= request_irq(pdev
->irq
, dm1105_irq
, IRQF_SHARED
,
1149 destroy_workqueue(dev
->wq
);
1151 dvb_net_release(&dev
->dvbnet
);
1152 err_disconnect_frontend
:
1153 dmx
->disconnect_frontend(dmx
);
1154 err_remove_mem_frontend
:
1155 dmx
->remove_frontend(dmx
, &dev
->mem_frontend
);
1156 err_remove_hw_frontend
:
1157 dmx
->remove_frontend(dmx
, &dev
->hw_frontend
);
1158 err_dvb_dmxdev_release
:
1159 dvb_dmxdev_release(&dev
->dmxdev
);
1160 err_dvb_dmx_release
:
1161 dvb_dmx_release(dvbdemux
);
1162 err_dvb_unregister_adapter
:
1163 dvb_unregister_adapter(dvb_adapter
);
1164 err_i2c_del_adapters
:
1165 i2c_del_adapter(&dev
->i2c_bb_adap
);
1166 err_i2c_del_adapter
:
1167 i2c_del_adapter(&dev
->i2c_adap
);
1169 dm1105_hw_exit(dev
);
1171 pci_iounmap(pdev
, dev
->io_mem
);
1172 err_pci_release_regions
:
1173 pci_release_regions(pdev
);
1174 err_pci_disable_device
:
1175 pci_disable_device(pdev
);
1181 static void dm1105_remove(struct pci_dev
*pdev
)
1183 struct dm1105_dev
*dev
= pci_get_drvdata(pdev
);
1184 struct dvb_adapter
*dvb_adapter
= &dev
->dvb_adapter
;
1185 struct dvb_demux
*dvbdemux
= &dev
->demux
;
1186 struct dmx_demux
*dmx
= &dvbdemux
->dmx
;
1188 dm1105_ir_exit(dev
);
1190 dvb_net_release(&dev
->dvbnet
);
1192 dvb_unregister_frontend(dev
->fe
);
1194 dmx
->disconnect_frontend(dmx
);
1195 dmx
->remove_frontend(dmx
, &dev
->mem_frontend
);
1196 dmx
->remove_frontend(dmx
, &dev
->hw_frontend
);
1197 dvb_dmxdev_release(&dev
->dmxdev
);
1198 dvb_dmx_release(dvbdemux
);
1199 dvb_unregister_adapter(dvb_adapter
);
1200 i2c_del_adapter(&dev
->i2c_adap
);
1202 dm1105_hw_exit(dev
);
1203 free_irq(pdev
->irq
, dev
);
1204 pci_iounmap(pdev
, dev
->io_mem
);
1205 pci_release_regions(pdev
);
1206 pci_disable_device(pdev
);
1211 static const struct pci_device_id dm1105_id_table
[] = {
1213 .vendor
= PCI_VENDOR_ID_TRIGEM
,
1214 .device
= PCI_DEVICE_ID_DM1105
,
1215 .subvendor
= PCI_ANY_ID
,
1216 .subdevice
= PCI_ANY_ID
,
1218 .vendor
= PCI_VENDOR_ID_AXESS
,
1219 .device
= PCI_DEVICE_ID_DM05
,
1220 .subvendor
= PCI_ANY_ID
,
1221 .subdevice
= PCI_ANY_ID
,
1227 MODULE_DEVICE_TABLE(pci
, dm1105_id_table
);
1229 static struct pci_driver dm1105_driver
= {
1230 .name
= DRIVER_NAME
,
1231 .id_table
= dm1105_id_table
,
1232 .probe
= dm1105_probe
,
1233 .remove
= dm1105_remove
,
1236 module_pci_driver(dm1105_driver
);
1238 MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
1239 MODULE_DESCRIPTION("SDMC DM1105 DVB driver");
1240 MODULE_LICENSE("GPL");