blob: 7c3900dec3686811501f22648cb047e8611ef2e5 [file] [log] [blame]
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001/*
2 * dm1105.c - driver for DVB cards based on SDMC DM1105 PCI chip
3 *
4 * Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by>
5 *
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.
10 *
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.
15 *
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030016 */
17
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030018#include <linux/i2c.h>
Igor M. Liplianin00175052011-05-05 16:35:01 -030019#include <linux/i2c-algo-bit.h>
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030020#include <linux/init.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000021#include <linux/interrupt.h>
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030022#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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Mauro Carvalho Chehab6bda9642010-11-17 13:28:38 -030028#include <media/rc-core.h>
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030029
30#include "demux.h"
31#include "dmxdev.h"
32#include "dvb_demux.h"
33#include "dvb_frontend.h"
34#include "dvb_net.h"
35#include "dvbdev.h"
36#include "dvb-pll.h"
37
38#include "stv0299.h"
Igor M. Liplianine4aab642008-09-23 15:43:57 -030039#include "stv0288.h"
40#include "stb6000.h"
Igor M. Liplianin04ad28c2008-09-16 18:21:11 -030041#include "si21xx.h"
Igor M. Liplianin35d9c422008-09-13 20:56:59 -030042#include "cx24116.h"
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030043#include "z0194a.h"
Konstantin Dimitrov73f0af42012-12-23 19:25:38 -030044#include "ts2020.h"
Igor M. Liplianinb4a0e812010-01-17 10:32:26 -030045#include "ds3000.h"
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030046
Mauro Carvalho Chehab727e6252010-03-12 21:18:14 -030047#define MODULE_NAME "dm1105"
48
Igor M. Liplianind8300df2009-07-22 17:30:25 -030049#define UNSET (-1U)
50
Igor M. Liplianin00175052011-05-05 16:35:01 -030051#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
Igor M. Liplianind8300df2009-07-22 17:30:25 -030057
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030058/* ----------------------------------------------- */
59/*
60 * PCI ID's
61 */
62#ifndef PCI_VENDOR_ID_TRIGEM
63#define PCI_VENDOR_ID_TRIGEM 0x109f
64#endif
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -030065#ifndef PCI_VENDOR_ID_AXESS
66#define PCI_VENDOR_ID_AXESS 0x195d
67#endif
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030068#ifndef PCI_DEVICE_ID_DM1105
69#define PCI_DEVICE_ID_DM1105 0x036f
70#endif
71#ifndef PCI_DEVICE_ID_DW2002
72#define PCI_DEVICE_ID_DW2002 0x2002
73#endif
74#ifndef PCI_DEVICE_ID_DW2004
75#define PCI_DEVICE_ID_DW2004 0x2004
76#endif
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -030077#ifndef PCI_DEVICE_ID_DM05
78#define PCI_DEVICE_ID_DM05 0x1105
79#endif
Igor M. Liplianina611d0c2008-09-13 10:10:53 -030080/* ----------------------------------------------- */
81/* sdmc dm1105 registers */
82
83/* TS Control */
84#define DM1105_TSCTR 0x00
85#define DM1105_DTALENTH 0x04
86
87/* GPIO Interface */
88#define DM1105_GPIOVAL 0x08
89#define DM1105_GPIOCTR 0x0c
90
91/* PID serial number */
92#define DM1105_PIDN 0x10
93
94/* Odd-even secret key select */
95#define DM1105_CWSEL 0x14
96
97/* Host Command Interface */
98#define DM1105_HOST_CTR 0x18
99#define DM1105_HOST_AD 0x1c
100
101/* PCI Interface */
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
110
111/* CW Value */
112#define DM1105_ODD 0x50
113#define DM1105_EVEN 0x58
114
115/* PID Value */
116#define DM1105_PID 0x60
117
118/* IR Control */
119#define DM1105_IRCTR 0x64
120#define DM1105_IRMODE 0x68
121#define DM1105_SYSTEMCODE 0x6c
122#define DM1105_IRCODE 0x70
123
124/* Unknown Values */
125#define DM1105_ENCRYPT 0x74
126#define DM1105_VER 0x7c
127
128/* I2C Interface */
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 */
135
136#define INTMAK_TSIRQM 0x01
137#define INTMAK_HIRQM 0x04
138#define INTMAK_IRM 0x08
139#define INTMAK_ALLMASK (INTMAK_TSIRQM | \
140 INTMAK_HIRQM | \
141 INTMAK_IRM)
142#define INTMAK_NONEMASK 0x00
143
144/* Interrupt Status Bits */
145#define INTSTS_TSIRQ 0x01
146#define INTSTS_HIRQ 0x04
147#define INTSTS_IR 0x08
148
149/* IR Control Bits */
150#define DM1105_IR_EN 0x01
151#define DM1105_SYS_CHK 0x02
152#define DM1105_REP_FLG 0x08
153
154/* EEPROM addr */
155#define IIC_24C01_addr 0xa0
156/* Max board count */
157#define DM1105_MAX 0x04
158
159#define DRIVER_NAME "dm1105"
Igor M. Liplianin00175052011-05-05 16:35:01 -0300160#define DM1105_I2C_GPIO_NAME "dm1105-gpio"
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300161
162#define DM1105_DMA_PACKETS 47
163#define DM1105_DMA_PACKET_LENGTH (128*4)
164#define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS)
165
Igor M. Liplianin00175052011-05-05 16:35:01 -0300166/* */
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
174
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300175/* GPIO's for LNB power control */
Igor M. Liplianin00175052011-05-05 16:35:01 -0300176#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
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300180
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300181/* GPIO's for LNB power control for Axess DM05 */
Igor M. Liplianin00175052011-05-05 16:35:01 -0300182#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)
186
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)
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300192
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300193static unsigned int card[] = {[0 ... 3] = UNSET };
194module_param_array(card, int, NULL, 0444);
195MODULE_PARM_DESC(card, "card type");
196
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300197static int ir_debug;
198module_param(ir_debug, int, 0644);
199MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
200
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300201static unsigned int dm1105_devcount;
202
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300203DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
204
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300205struct dm1105_board {
Igor M. Liplianin00175052011-05-05 16:35:01 -0300206 char *name;
207 struct {
208 u32 mask, off, v13, v18;
209 } lnb;
210 u32 gpio_scl, gpio_sda;
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300211};
212
213struct dm1105_subid {
214 u16 subvendor;
215 u16 subdevice;
216 u32 card;
217};
218
219static const struct dm1105_board dm1105_boards[] = {
220 [DM1105_BOARD_UNKNOWN] = {
221 .name = "UNKNOWN/GENERIC",
Igor M. Liplianin00175052011-05-05 16:35:01 -0300222 .lnb = {
223 .mask = DM1105_LNB_MASK,
224 .off = DM1105_LNB_OFF,
225 .v13 = DM1105_LNB_13V,
226 .v18 = DM1105_LNB_18V,
227 },
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300228 },
229 [DM1105_BOARD_DVBWORLD_2002] = {
230 .name = "DVBWorld PCI 2002",
Igor M. Liplianin00175052011-05-05 16:35:01 -0300231 .lnb = {
232 .mask = DM1105_LNB_MASK,
233 .off = DM1105_LNB_OFF,
234 .v13 = DM1105_LNB_13V,
235 .v18 = DM1105_LNB_18V,
236 },
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300237 },
238 [DM1105_BOARD_DVBWORLD_2004] = {
239 .name = "DVBWorld PCI 2004",
Igor M. Liplianin00175052011-05-05 16:35:01 -0300240 .lnb = {
241 .mask = DM1105_LNB_MASK,
242 .off = DM1105_LNB_OFF,
243 .v13 = DM1105_LNB_13V,
244 .v18 = DM1105_LNB_18V,
245 },
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300246 },
247 [DM1105_BOARD_AXESS_DM05] = {
248 .name = "Axess/EasyTv DM05",
Igor M. Liplianin00175052011-05-05 16:35:01 -0300249 .lnb = {
250 .mask = DM05_LNB_MASK,
251 .off = DM05_LNB_OFF,
252 .v13 = DM05_LNB_13V,
253 .v18 = DM05_LNB_18V,
254 },
255 },
256 [DM1105_BOARD_UNBRANDED_I2C_ON_GPIO] = {
257 .name = "Unbranded DM1105 with i2c on GPIOs",
258 .lnb = {
259 .mask = UNBR_LNB_MASK,
260 .off = UNBR_LNB_OFF,
261 .v13 = UNBR_LNB_13V,
262 .v18 = UNBR_LNB_18V,
263 },
264 .gpio_scl = GPIO14,
265 .gpio_sda = GPIO13,
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300266 },
267};
268
269static const struct dm1105_subid dm1105_subids[] = {
270 {
271 .subvendor = 0x0000,
272 .subdevice = 0x2002,
273 .card = DM1105_BOARD_DVBWORLD_2002,
274 }, {
275 .subvendor = 0x0001,
276 .subdevice = 0x2002,
277 .card = DM1105_BOARD_DVBWORLD_2002,
278 }, {
279 .subvendor = 0x0000,
280 .subdevice = 0x2004,
281 .card = DM1105_BOARD_DVBWORLD_2004,
282 }, {
283 .subvendor = 0x0001,
284 .subdevice = 0x2004,
285 .card = DM1105_BOARD_DVBWORLD_2004,
286 }, {
287 .subvendor = 0x195d,
288 .subdevice = 0x1105,
289 .card = DM1105_BOARD_AXESS_DM05,
290 },
291};
292
293static void dm1105_card_list(struct pci_dev *pci)
294{
295 int i;
296
297 if (0 == pci->subsystem_vendor &&
298 0 == pci->subsystem_device) {
299 printk(KERN_ERR
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"
305 "dm1105: -- tux\n");
306 } else {
307 printk(KERN_ERR
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");
313 }
Mauro Carvalho Chehab0e8aebb2016-10-18 17:44:04 -0200314 printk(KERN_ERR "Here is a list of valid choices for the card=<n> insmod option:\n");
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300315 for (i = 0; i < ARRAY_SIZE(dm1105_boards); i++)
316 printk(KERN_ERR "dm1105: card=%d -> %s\n",
317 i, dm1105_boards[i].name);
318}
319
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300320/* infrared remote control */
321struct infrared {
David Härdemand8b4b582010-10-29 16:08:23 -0300322 struct rc_dev *dev;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300323 char input_phys[32];
Igor M. Liplianinb72857d2009-02-26 03:49:44 -0300324 struct work_struct work;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300325 u32 ir_command;
326};
327
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300328struct dm1105_dev {
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300329 /* pci */
330 struct pci_dev *pdev;
331 u8 __iomem *io_mem;
332
333 /* ir */
334 struct infrared ir;
335
336 /* dvb */
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;
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300345 unsigned int boardnr;
346 int nr;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300347
348 /* i2c */
349 struct i2c_adapter i2c_adap;
Igor M. Liplianin00175052011-05-05 16:35:01 -0300350 struct i2c_adapter i2c_bb_adap;
351 struct i2c_algo_bit_data i2c_bit;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300352
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300353 /* irq */
354 struct work_struct work;
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300355 struct workqueue_struct *wq;
356 char wqn[16];
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300357
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300358 /* dma */
359 dma_addr_t dma_addr;
360 unsigned char *ts_buf;
361 u32 wrp;
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300362 u32 nextwrp;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300363 u32 buffer_size;
364 unsigned int PacketErrorCount;
365 unsigned int dmarst;
366 spinlock_t lock;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300367};
368
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300369#define dm_io_mem(reg) ((unsigned long)(&dev->io_mem[reg]))
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300370
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300371#define dm_readb(reg) inb(dm_io_mem(reg))
372#define dm_writeb(reg, value) outb((value), (dm_io_mem(reg)))
373
374#define dm_readw(reg) inw(dm_io_mem(reg))
375#define dm_writew(reg, value) outw((value), (dm_io_mem(reg)))
376
377#define dm_readl(reg) inl(dm_io_mem(reg))
378#define dm_writel(reg, value) outl((value), (dm_io_mem(reg)))
379
380#define dm_andorl(reg, mask, value) \
381 outl((inl(dm_io_mem(reg)) & ~(mask)) |\
382 ((value) & (mask)), (dm_io_mem(reg)))
383
384#define dm_setl(reg, bit) dm_andorl((reg), (bit), (bit))
385#define dm_clearl(reg, bit) dm_andorl((reg), (bit), 0)
386
Igor M. Liplianin00175052011-05-05 16:35:01 -0300387/* 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.
390 */
391static void dm1105_gpio_set(struct dm1105_dev *dev, u32 mask)
392{
393 if (mask & 0xfffc0000)
394 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
395
396 if (mask & 0x0003ffff)
397 dm_setl(DM1105_GPIOVAL, mask & 0x0003ffff);
398
399}
400
401static void dm1105_gpio_clear(struct dm1105_dev *dev, u32 mask)
402{
403 if (mask & 0xfffc0000)
404 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
405
406 if (mask & 0x0003ffff)
407 dm_clearl(DM1105_GPIOVAL, mask & 0x0003ffff);
408
409}
410
411static void dm1105_gpio_andor(struct dm1105_dev *dev, u32 mask, u32 val)
412{
413 if (mask & 0xfffc0000)
414 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
415
416 if (mask & 0x0003ffff)
417 dm_andorl(DM1105_GPIOVAL, mask & 0x0003ffff, val);
418
419}
420
421static u32 dm1105_gpio_get(struct dm1105_dev *dev, u32 mask)
422{
423 if (mask & 0xfffc0000)
424 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
425
426 if (mask & 0x0003ffff)
427 return dm_readl(DM1105_GPIOVAL) & mask & 0x0003ffff;
428
429 return 0;
430}
431
432static void dm1105_gpio_enable(struct dm1105_dev *dev, u32 mask, int asoutput)
433{
434 if (mask & 0xfffc0000)
435 printk(KERN_ERR "%s: Only 18 GPIO's are allowed\n", __func__);
436
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);
441
442}
443
444static void dm1105_setline(struct dm1105_dev *dev, u32 line, int state)
445{
446 if (state)
447 dm1105_gpio_enable(dev, line, 0);
448 else {
449 dm1105_gpio_enable(dev, line, 1);
450 dm1105_gpio_clear(dev, line);
451 }
452}
453
454static void dm1105_setsda(void *data, int state)
455{
456 struct dm1105_dev *dev = data;
457
458 dm1105_setline(dev, dm1105_boards[dev->boardnr].gpio_sda, state);
459}
460
461static void dm1105_setscl(void *data, int state)
462{
463 struct dm1105_dev *dev = data;
464
465 dm1105_setline(dev, dm1105_boards[dev->boardnr].gpio_scl, state);
466}
467
468static int dm1105_getsda(void *data)
469{
470 struct dm1105_dev *dev = data;
471
472 return dm1105_gpio_get(dev, dm1105_boards[dev->boardnr].gpio_sda)
473 ? 1 : 0;
474}
475
476static int dm1105_getscl(void *data)
477{
478 struct dm1105_dev *dev = data;
479
480 return dm1105_gpio_get(dev, dm1105_boards[dev->boardnr].gpio_scl)
481 ? 1 : 0;
482}
483
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300484static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap,
485 struct i2c_msg *msgs, int num)
486{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300487 struct dm1105_dev *dev ;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300488
489 int addr, rc, i, j, k, len, byte, data;
490 u8 status;
491
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300492 dev = i2c_adap->algo_data;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300493 for (i = 0; i < num; i++) {
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300494 dm_writeb(DM1105_I2CCTR, 0x00);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300495 if (msgs[i].flags & I2C_M_RD) {
496 /* read bytes */
497 addr = msgs[i].addr << 1;
498 addr |= 1;
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300499 dm_writeb(DM1105_I2CDAT, addr);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300500 for (byte = 0; byte < msgs[i].len; byte++)
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300501 dm_writeb(DM1105_I2CDAT + byte + 1, 0);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300502
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300503 dm_writeb(DM1105_I2CCTR, 0x81 + msgs[i].len);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300504 for (j = 0; j < 55; j++) {
505 mdelay(10);
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300506 status = dm_readb(DM1105_I2CSTS);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300507 if ((status & 0xc0) == 0x40)
508 break;
509 }
510 if (j >= 55)
511 return -1;
512
513 for (byte = 0; byte < msgs[i].len; byte++) {
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300514 rc = dm_readb(DM1105_I2CDAT + byte + 1);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300515 if (rc < 0)
516 goto err;
517 msgs[i].buf[byte] = rc;
518 }
Igor M. Liplianined7c8472010-01-17 11:15:06 -0300519 } 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;
523 k = 1;
524 do {
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300525 dm_writeb(DM1105_I2CDAT, msgs[i].addr << 1);
526 dm_writeb(DM1105_I2CDAT + 1, 0xf7);
Igor M. Liplianined7c8472010-01-17 11:15:06 -0300527 for (byte = 0; byte < (len > 48 ? 48 : len); byte++) {
528 data = msgs[i].buf[k + byte];
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300529 dm_writeb(DM1105_I2CDAT + byte + 2, data);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300530 }
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300531 dm_writeb(DM1105_I2CCTR, 0x82 + (len > 48 ? 48 : len));
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300532 for (j = 0; j < 25; j++) {
533 mdelay(10);
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300534 status = dm_readb(DM1105_I2CSTS);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300535 if ((status & 0xc0) == 0x40)
536 break;
537 }
538
539 if (j >= 25)
540 return -1;
Igor M. Liplianined7c8472010-01-17 11:15:06 -0300541
542 k += 48;
543 len -= 48;
544 } while (len > 0);
545 } else {
546 /* write bytes */
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300547 dm_writeb(DM1105_I2CDAT, msgs[i].addr << 1);
Igor M. Liplianined7c8472010-01-17 11:15:06 -0300548 for (byte = 0; byte < msgs[i].len; byte++) {
549 data = msgs[i].buf[byte];
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300550 dm_writeb(DM1105_I2CDAT + byte + 1, data);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300551 }
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300552 dm_writeb(DM1105_I2CCTR, 0x81 + msgs[i].len);
Igor M. Liplianined7c8472010-01-17 11:15:06 -0300553 for (j = 0; j < 25; j++) {
554 mdelay(10);
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300555 status = dm_readb(DM1105_I2CSTS);
Igor M. Liplianined7c8472010-01-17 11:15:06 -0300556 if ((status & 0xc0) == 0x40)
557 break;
558 }
559
560 if (j >= 25)
561 return -1;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300562 }
563 }
564 return num;
565 err:
566 return rc;
567}
568
569static u32 functionality(struct i2c_adapter *adap)
570{
571 return I2C_FUNC_I2C;
572}
573
Gustavo A. R. Silva3c139782017-07-09 21:19:36 -0400574static const struct i2c_algorithm dm1105_algo = {
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300575 .master_xfer = dm1105_i2c_xfer,
576 .functionality = functionality,
577};
578
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300579static inline struct dm1105_dev *feed_to_dm1105_dev(struct dvb_demux_feed *feed)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300580{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300581 return container_of(feed->demux, struct dm1105_dev, demux);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300582}
583
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300584static inline struct dm1105_dev *frontend_to_dm1105_dev(struct dvb_frontend *fe)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300585{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300586 return container_of(fe->dvb, struct dm1105_dev, dvb_adapter);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300587}
588
Mauro Carvalho Chehab0df289a2015-06-07 14:53:52 -0300589static int dm1105_set_voltage(struct dvb_frontend *fe,
590 enum fe_sec_voltage voltage)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300591{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300592 struct dm1105_dev *dev = frontend_to_dm1105_dev(fe);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300593
Igor M. Liplianin00175052011-05-05 16:35:01 -0300594 dm1105_gpio_enable(dev, dm1105_boards[dev->boardnr].lnb.mask, 1);
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300595 if (voltage == SEC_VOLTAGE_18)
Igor M. Liplianin00175052011-05-05 16:35:01 -0300596 dm1105_gpio_andor(dev,
597 dm1105_boards[dev->boardnr].lnb.mask,
598 dm1105_boards[dev->boardnr].lnb.v18);
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300599 else if (voltage == SEC_VOLTAGE_13)
Igor M. Liplianin00175052011-05-05 16:35:01 -0300600 dm1105_gpio_andor(dev,
601 dm1105_boards[dev->boardnr].lnb.mask,
602 dm1105_boards[dev->boardnr].lnb.v13);
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300603 else
Igor M. Liplianin00175052011-05-05 16:35:01 -0300604 dm1105_gpio_andor(dev,
605 dm1105_boards[dev->boardnr].lnb.mask,
606 dm1105_boards[dev->boardnr].lnb.off);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300607
608 return 0;
609}
610
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300611static void dm1105_set_dma_addr(struct dm1105_dev *dev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300612{
Hans Verkuil888bd5d2014-08-21 11:50:34 -0300613 dm_writel(DM1105_STADR, (__force u32)cpu_to_le32(dev->dma_addr));
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300614}
615
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800616static int dm1105_dma_map(struct dm1105_dev *dev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300617{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300618 dev->ts_buf = pci_alloc_consistent(dev->pdev,
619 6 * DM1105_DMA_BYTES,
620 &dev->dma_addr);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300621
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300622 return !dev->ts_buf;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300623}
624
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300625static void dm1105_dma_unmap(struct dm1105_dev *dev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300626{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300627 pci_free_consistent(dev->pdev,
628 6 * DM1105_DMA_BYTES,
629 dev->ts_buf,
630 dev->dma_addr);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300631}
632
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300633static void dm1105_enable_irqs(struct dm1105_dev *dev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300634{
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300635 dm_writeb(DM1105_INTMAK, INTMAK_ALLMASK);
636 dm_writeb(DM1105_CR, 1);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300637}
638
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300639static void dm1105_disable_irqs(struct dm1105_dev *dev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300640{
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300641 dm_writeb(DM1105_INTMAK, INTMAK_IRM);
642 dm_writeb(DM1105_CR, 0);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300643}
644
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300645static int dm1105_start_feed(struct dvb_demux_feed *f)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300646{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300647 struct dm1105_dev *dev = feed_to_dm1105_dev(f);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300648
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300649 if (dev->full_ts_users++ == 0)
650 dm1105_enable_irqs(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300651
652 return 0;
653}
654
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300655static int dm1105_stop_feed(struct dvb_demux_feed *f)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300656{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300657 struct dm1105_dev *dev = feed_to_dm1105_dev(f);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300658
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300659 if (--dev->full_ts_users == 0)
660 dm1105_disable_irqs(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300661
662 return 0;
663}
664
Igor M. Liplianinb72857d2009-02-26 03:49:44 -0300665/* ir work handler */
666static void dm1105_emit_key(struct work_struct *work)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300667{
Igor M. Liplianinb72857d2009-02-26 03:49:44 -0300668 struct infrared *ir = container_of(work, struct infrared, work);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300669 u32 ircom = ir->ir_command;
670 u8 data;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300671
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300672 if (ir_debug)
673 printk(KERN_INFO "%s: received byte 0x%04x\n", __func__, ircom);
674
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300675 data = (ircom >> 8) & 0x7f;
676
David Härdeman120703f2014-04-03 20:31:30 -0300677 /* FIXME: UNKNOWN because we don't generate a full NEC scancode (yet?) */
Sean Young6d741bf2017-08-07 16:20:58 -0400678 rc_keydown(ir->dev, RC_PROTO_UNKNOWN, data, 0);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300679}
680
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300681/* work handler */
682static void dm1105_dmx_buffer(struct work_struct *work)
683{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300684 struct dm1105_dev *dev = container_of(work, struct dm1105_dev, work);
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300685 unsigned int nbpackets;
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300686 u32 oldwrp = dev->wrp;
687 u32 nextwrp = dev->nextwrp;
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300688
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300689 if (!((dev->ts_buf[oldwrp] == 0x47) &&
690 (dev->ts_buf[oldwrp + 188] == 0x47) &&
691 (dev->ts_buf[oldwrp + 188 * 2] == 0x47))) {
692 dev->PacketErrorCount++;
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300693 /* bad packet found */
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300694 if ((dev->PacketErrorCount >= 2) &&
695 (dev->dmarst == 0)) {
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300696 dm_writeb(DM1105_RST, 1);
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300697 dev->wrp = 0;
698 dev->PacketErrorCount = 0;
699 dev->dmarst = 0;
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300700 return;
701 }
702 }
703
704 if (nextwrp < oldwrp) {
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300705 memcpy(dev->ts_buf + dev->buffer_size, dev->ts_buf, nextwrp);
706 nbpackets = ((dev->buffer_size - oldwrp) + nextwrp) / 188;
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300707 } else
708 nbpackets = (nextwrp - oldwrp) / 188;
709
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300710 dev->wrp = nextwrp;
711 dvb_dmx_swfilter_packets(&dev->demux, &dev->ts_buf[oldwrp], nbpackets);
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300712}
713
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300714static irqreturn_t dm1105_irq(int irq, void *dev_id)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300715{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300716 struct dm1105_dev *dev = dev_id;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300717
718 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300719 unsigned int intsts = dm_readb(DM1105_INTSTS);
720 dm_writeb(DM1105_INTSTS, intsts);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300721
722 switch (intsts) {
723 case INTSTS_TSIRQ:
724 case (INTSTS_TSIRQ | INTSTS_IR):
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300725 dev->nextwrp = dm_readl(DM1105_WRP) - dm_readl(DM1105_STADR);
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300726 queue_work(dev->wq, &dev->work);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300727 break;
728 case INTSTS_IR:
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300729 dev->ir.ir_command = dm_readl(DM1105_IRCODE);
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300730 schedule_work(&dev->ir.work);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300731 break;
732 }
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300733
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300734 return IRQ_HANDLED;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300735}
736
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800737static int dm1105_ir_init(struct dm1105_dev *dm1105)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300738{
David Härdemand8b4b582010-10-29 16:08:23 -0300739 struct rc_dev *dev;
Igor M. Liplianinb72857d2009-02-26 03:49:44 -0300740 int err = -ENOMEM;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300741
Andi Shyti0f7499f2016-12-16 06:50:58 -0200742 dev = rc_allocate_device(RC_DRIVER_SCANCODE);
David Härdemand8b4b582010-10-29 16:08:23 -0300743 if (!dev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300744 return -ENOMEM;
745
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300746 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys),
747 "pci-%s/ir0", pci_name(dm1105->pdev));
748
David Härdemand8b4b582010-10-29 16:08:23 -0300749 dev->driver_name = MODULE_NAME;
750 dev->map_name = RC_MAP_DM1105_NEC;
Sean Young518f4b22017-07-01 12:13:19 -0400751 dev->device_name = "DVB on-card IR receiver";
David Härdemand8b4b582010-10-29 16:08:23 -0300752 dev->input_phys = dm1105->ir.input_phys;
753 dev->input_id.bustype = BUS_PCI;
754 dev->input_id.version = 1;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300755 if (dm1105->pdev->subsystem_vendor) {
David Härdemand8b4b582010-10-29 16:08:23 -0300756 dev->input_id.vendor = dm1105->pdev->subsystem_vendor;
757 dev->input_id.product = dm1105->pdev->subsystem_device;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300758 } else {
David Härdemand8b4b582010-10-29 16:08:23 -0300759 dev->input_id.vendor = dm1105->pdev->vendor;
760 dev->input_id.product = dm1105->pdev->device;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300761 }
David Härdemand8b4b582010-10-29 16:08:23 -0300762 dev->dev.parent = &dm1105->pdev->dev;
Igor M. Liplianinb72857d2009-02-26 03:49:44 -0300763
764 INIT_WORK(&dm1105->ir.work, dm1105_emit_key);
765
David Härdemand8b4b582010-10-29 16:08:23 -0300766 err = rc_register_device(dev);
David Härdeman15100d82010-04-15 18:46:15 -0300767 if (err < 0) {
David Härdemand8b4b582010-10-29 16:08:23 -0300768 rc_free_device(dev);
David Härdeman15100d82010-04-15 18:46:15 -0300769 return err;
770 }
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300771
David Härdemand8b4b582010-10-29 16:08:23 -0300772 dm1105->ir.dev = dev;
David Härdeman15100d82010-04-15 18:46:15 -0300773 return 0;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300774}
775
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800776static void dm1105_ir_exit(struct dm1105_dev *dm1105)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300777{
David Härdemand8b4b582010-10-29 16:08:23 -0300778 rc_unregister_device(dm1105->ir.dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300779}
780
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800781static int dm1105_hw_init(struct dm1105_dev *dev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300782{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300783 dm1105_disable_irqs(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300784
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300785 dm_writeb(DM1105_HOST_CTR, 0);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300786
787 /*DATALEN 188,*/
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300788 dm_writeb(DM1105_DTALENTH, 188);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300789 /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300790 dm_writew(DM1105_TSCTR, 0xc10a);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300791
792 /* map DMA and set address */
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300793 dm1105_dma_map(dev);
794 dm1105_set_dma_addr(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300795 /* big buffer */
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300796 dm_writel(DM1105_RLEN, 5 * DM1105_DMA_BYTES);
797 dm_writeb(DM1105_INTCNT, 47);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300798
799 /* IR NEC mode enable */
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300800 dm_writeb(DM1105_IRCTR, (DM1105_IR_EN | DM1105_SYS_CHK));
801 dm_writeb(DM1105_IRMODE, 0);
802 dm_writew(DM1105_SYSTEMCODE, 0);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300803
804 return 0;
805}
806
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300807static void dm1105_hw_exit(struct dm1105_dev *dev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300808{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300809 dm1105_disable_irqs(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300810
811 /* IR disable */
Igor M. Liplianin5eb32912010-01-17 12:23:04 -0300812 dm_writeb(DM1105_IRCTR, 0);
813 dm_writeb(DM1105_INTMAK, INTMAK_NONEMASK);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300814
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300815 dm1105_dma_unmap(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300816}
Igor M. Liplianine4aab642008-09-23 15:43:57 -0300817
Bhumika Goyal650497f2017-02-19 15:04:41 -0300818static const struct stv0299_config sharp_z0194a_config = {
Igor M. Liplianind4305c62008-10-17 13:45:55 -0300819 .demod_address = 0x68,
820 .inittab = sharp_z0194a_inittab,
821 .mclk = 88000000UL,
822 .invert = 1,
823 .skip_reinit = 0,
824 .lock_output = STV0299_LOCKOUTPUT_1,
825 .volt13_op0_op1 = STV0299_VOLT13_OP1,
826 .min_delay_ms = 100,
827 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
828};
829
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300830static struct stv0288_config earda_config = {
831 .demod_address = 0x68,
832 .min_delay_ms = 100,
833};
834
835static struct si21xx_config serit_config = {
836 .demod_address = 0x68,
837 .min_delay_ms = 100,
838
839};
840
841static struct cx24116_config serit_sp2633_config = {
842 .demod_address = 0x55,
843};
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300844
Igor M. Liplianinb4a0e812010-01-17 10:32:26 -0300845static struct ds3000_config dvbworld_ds3000_config = {
846 .demod_address = 0x68,
847};
848
Konstantin Dimitrov73f0af42012-12-23 19:25:38 -0300849static struct ts2020_config dvbworld_ts2020_config = {
850 .tuner_address = 0x60,
Igor M. Liplianinb858c332012-12-28 19:40:33 -0300851 .clk_out_div = 1,
Konstantin Dimitrov73f0af42012-12-23 19:25:38 -0300852};
853
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800854static int frontend_init(struct dm1105_dev *dev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300855{
856 int ret;
857
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300858 switch (dev->boardnr) {
Igor M. Liplianin00175052011-05-05 16:35:01 -0300859 case DM1105_BOARD_UNBRANDED_I2C_ON_GPIO:
860 dm1105_gpio_enable(dev, GPIO15, 1);
861 dm1105_gpio_clear(dev, GPIO15);
862 msleep(100);
863 dm1105_gpio_set(dev, GPIO15);
864 msleep(200);
865 dev->fe = dvb_attach(
866 stv0299_attach, &sharp_z0194a_config,
867 &dev->i2c_bb_adap);
868 if (dev->fe) {
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);
872 break;
873 }
874
875 dev->fe = dvb_attach(
876 stv0288_attach, &earda_config,
877 &dev->i2c_bb_adap);
878 if (dev->fe) {
879 dev->fe->ops.set_voltage = dm1105_set_voltage;
880 dvb_attach(stb6000_attach, dev->fe, 0x61,
881 &dev->i2c_bb_adap);
882 break;
883 }
884
885 dev->fe = dvb_attach(
886 si21xx_attach, &serit_config,
887 &dev->i2c_bb_adap);
888 if (dev->fe)
889 dev->fe->ops.set_voltage = dm1105_set_voltage;
890 break;
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300891 case DM1105_BOARD_DVBWORLD_2004:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300892 dev->fe = dvb_attach(
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300893 cx24116_attach, &serit_sp2633_config,
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300894 &dev->i2c_adap);
895 if (dev->fe) {
896 dev->fe->ops.set_voltage = dm1105_set_voltage;
Igor M. Liplianinb4a0e812010-01-17 10:32:26 -0300897 break;
898 }
899
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300900 dev->fe = dvb_attach(
Igor M. Liplianinb4a0e812010-01-17 10:32:26 -0300901 ds3000_attach, &dvbworld_ds3000_config,
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300902 &dev->i2c_adap);
Konstantin Dimitrov73f0af42012-12-23 19:25:38 -0300903 if (dev->fe) {
904 dvb_attach(ts2020_attach, dev->fe,
905 &dvbworld_ts2020_config, &dev->i2c_adap);
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300906 dev->fe->ops.set_voltage = dm1105_set_voltage;
Konstantin Dimitrov73f0af42012-12-23 19:25:38 -0300907 }
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300908
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300909 break;
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300910 case DM1105_BOARD_DVBWORLD_2002:
911 case DM1105_BOARD_AXESS_DM05:
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300912 default:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300913 dev->fe = dvb_attach(
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300914 stv0299_attach, &sharp_z0194a_config,
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300915 &dev->i2c_adap);
916 if (dev->fe) {
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);
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300920 break;
921 }
922
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300923 dev->fe = dvb_attach(
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300924 stv0288_attach, &earda_config,
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300925 &dev->i2c_adap);
926 if (dev->fe) {
927 dev->fe->ops.set_voltage = dm1105_set_voltage;
928 dvb_attach(stb6000_attach, dev->fe, 0x61,
929 &dev->i2c_adap);
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300930 break;
931 }
932
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300933 dev->fe = dvb_attach(
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300934 si21xx_attach, &serit_config,
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300935 &dev->i2c_adap);
936 if (dev->fe)
937 dev->fe->ops.set_voltage = dm1105_set_voltage;
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300938
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300939 }
940
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300941 if (!dev->fe) {
942 dev_err(&dev->pdev->dev, "could not attach frontend\n");
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300943 return -ENODEV;
944 }
945
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300946 ret = dvb_register_frontend(&dev->dvb_adapter, dev->fe);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300947 if (ret < 0) {
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300948 if (dev->fe->ops.release)
949 dev->fe->ops.release(dev->fe);
950 dev->fe = NULL;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300951 return ret;
952 }
953
954 return 0;
955}
956
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800957static void dm1105_read_mac(struct dm1105_dev *dev, u8 *mac)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300958{
959 static u8 command[1] = { 0x28 };
960
961 struct i2c_msg msg[] = {
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -0300962 {
963 .addr = IIC_24C01_addr >> 1,
964 .flags = 0,
965 .buf = command,
966 .len = 1
967 }, {
968 .addr = IIC_24C01_addr >> 1,
969 .flags = I2C_M_RD,
970 .buf = mac,
971 .len = 6
972 },
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300973 };
974
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300975 dm1105_i2c_xfer(&dev->i2c_adap, msg , 2);
976 dev_info(&dev->pdev->dev, "MAC %pM\n", mac);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300977}
978
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -0800979static int dm1105_probe(struct pci_dev *pdev,
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300980 const struct pci_device_id *ent)
981{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300982 struct dm1105_dev *dev;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300983 struct dvb_adapter *dvb_adapter;
984 struct dvb_demux *dvbdemux;
985 struct dmx_demux *dmx;
986 int ret = -ENOMEM;
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300987 int i;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300988
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300989 dev = kzalloc(sizeof(struct dm1105_dev), GFP_KERNEL);
990 if (!dev)
Igor M. Liplianind1498ff2009-02-26 03:40:41 -0300991 return -ENOMEM;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -0300992
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300993 /* board config */
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -0300994 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 &&
Igor M. Liplianind8300df2009-07-22 17:30:25 -0300999 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)
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001004 dev->boardnr = dm1105_subids[i].card;
Igor M. Liplianind8300df2009-07-22 17:30:25 -03001005
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001006 if (UNSET == dev->boardnr) {
1007 dev->boardnr = DM1105_BOARD_UNKNOWN;
Igor M. Liplianind8300df2009-07-22 17:30:25 -03001008 dm1105_card_list(pdev);
1009 }
1010
1011 dm1105_devcount++;
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001012 dev->pdev = pdev;
1013 dev->buffer_size = 5 * DM1105_DMA_BYTES;
1014 dev->PacketErrorCount = 0;
1015 dev->dmarst = 0;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001016
1017 ret = pci_enable_device(pdev);
1018 if (ret < 0)
1019 goto err_kfree;
1020
Yang Hongyang284901a2009-04-06 19:01:15 -07001021 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001022 if (ret < 0)
1023 goto err_pci_disable_device;
1024
1025 pci_set_master(pdev);
1026
1027 ret = pci_request_regions(pdev, DRIVER_NAME);
1028 if (ret < 0)
1029 goto err_pci_disable_device;
1030
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001031 dev->io_mem = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
1032 if (!dev->io_mem) {
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001033 ret = -EIO;
1034 goto err_pci_release_regions;
1035 }
1036
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001037 spin_lock_init(&dev->lock);
1038 pci_set_drvdata(pdev, dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001039
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001040 ret = dm1105_hw_init(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001041 if (ret < 0)
Igor M. Liplianind1498ff2009-02-26 03:40:41 -03001042 goto err_pci_iounmap;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001043
1044 /* i2c */
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001045 i2c_set_adapdata(&dev->i2c_adap, dev);
1046 strcpy(dev->i2c_adap.name, DRIVER_NAME);
1047 dev->i2c_adap.owner = THIS_MODULE;
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001048 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);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001052
1053 if (ret < 0)
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001054 goto err_dm1105_hw_exit;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001055
Igor M. Liplianin00175052011-05-05 16:35:01 -03001056 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;
1068
1069 /* Raise SCL and SDA */
1070 dm1105_setsda(dev, 1);
1071 dm1105_setscl(dev, 1);
1072
1073 ret = i2c_bit_add_bus(&dev->i2c_bb_adap);
1074 if (ret < 0)
1075 goto err_i2c_del_adapter;
1076
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001077 /* dvb */
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001078 ret = dvb_register_adapter(&dev->dvb_adapter, DRIVER_NAME,
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001079 THIS_MODULE, &pdev->dev, adapter_nr);
1080 if (ret < 0)
Igor M. Liplianin00175052011-05-05 16:35:01 -03001081 goto err_i2c_del_adapters;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001082
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001083 dvb_adapter = &dev->dvb_adapter;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001084
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001085 dm1105_read_mac(dev, dvb_adapter->proposed_mac);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001086
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001087 dvbdemux = &dev->demux;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001088 dvbdemux->filternum = 256;
1089 dvbdemux->feednum = 256;
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001090 dvbdemux->start_feed = dm1105_start_feed;
1091 dvbdemux->stop_feed = dm1105_stop_feed;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001092 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
1093 DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
1094 ret = dvb_dmx_init(dvbdemux);
1095 if (ret < 0)
1096 goto err_dvb_unregister_adapter;
1097
1098 dmx = &dvbdemux->dmx;
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001099 dev->dmxdev.filternum = 256;
1100 dev->dmxdev.demux = dmx;
1101 dev->dmxdev.capabilities = 0;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001102
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001103 ret = dvb_dmxdev_init(&dev->dmxdev, dvb_adapter);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001104 if (ret < 0)
1105 goto err_dvb_dmx_release;
1106
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001107 dev->hw_frontend.source = DMX_FRONTEND_0;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001108
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001109 ret = dmx->add_frontend(dmx, &dev->hw_frontend);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001110 if (ret < 0)
1111 goto err_dvb_dmxdev_release;
1112
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001113 dev->mem_frontend.source = DMX_MEMORY_FE;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001114
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001115 ret = dmx->add_frontend(dmx, &dev->mem_frontend);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001116 if (ret < 0)
1117 goto err_remove_hw_frontend;
1118
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001119 ret = dmx->connect_frontend(dmx, &dev->hw_frontend);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001120 if (ret < 0)
1121 goto err_remove_mem_frontend;
1122
Jonathan Nieder5584c642011-12-31 08:08:45 -03001123 ret = dvb_net_init(dvb_adapter, &dev->dvbnet, dmx);
1124 if (ret < 0)
1125 goto err_disconnect_frontend;
1126
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001127 ret = frontend_init(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001128 if (ret < 0)
Jonathan Niedere9966342012-01-06 14:40:26 -03001129 goto err_dvb_net;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001130
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001131 dm1105_ir_init(dev);
Igor M. Liplianind1498ff2009-02-26 03:40:41 -03001132
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001133 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);
Peter Senna Tschudin95d08122012-09-06 11:23:55 -03001136 if (!dev->wq) {
1137 ret = -ENOMEM;
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -03001138 goto err_dvb_net;
Peter Senna Tschudin95d08122012-09-06 11:23:55 -03001139 }
Igor M. Liplianind1498ff2009-02-26 03:40:41 -03001140
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001141 ret = request_irq(pdev->irq, dm1105_irq, IRQF_SHARED,
1142 DRIVER_NAME, dev);
Igor M. Liplianind1498ff2009-02-26 03:40:41 -03001143 if (ret < 0)
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -03001144 goto err_workqueue;
Igor M. Liplianind1498ff2009-02-26 03:40:41 -03001145
1146 return 0;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001147
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -03001148err_workqueue:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001149 destroy_workqueue(dev->wq);
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -03001150err_dvb_net:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001151 dvb_net_release(&dev->dvbnet);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001152err_disconnect_frontend:
1153 dmx->disconnect_frontend(dmx);
1154err_remove_mem_frontend:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001155 dmx->remove_frontend(dmx, &dev->mem_frontend);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001156err_remove_hw_frontend:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001157 dmx->remove_frontend(dmx, &dev->hw_frontend);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001158err_dvb_dmxdev_release:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001159 dvb_dmxdev_release(&dev->dmxdev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001160err_dvb_dmx_release:
1161 dvb_dmx_release(dvbdemux);
1162err_dvb_unregister_adapter:
1163 dvb_unregister_adapter(dvb_adapter);
Igor M. Liplianin00175052011-05-05 16:35:01 -03001164err_i2c_del_adapters:
1165 i2c_del_adapter(&dev->i2c_bb_adap);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001166err_i2c_del_adapter:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001167 i2c_del_adapter(&dev->i2c_adap);
1168err_dm1105_hw_exit:
1169 dm1105_hw_exit(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001170err_pci_iounmap:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001171 pci_iounmap(pdev, dev->io_mem);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001172err_pci_release_regions:
1173 pci_release_regions(pdev);
1174err_pci_disable_device:
1175 pci_disable_device(pdev);
1176err_kfree:
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001177 kfree(dev);
Igor M. Liplianind1498ff2009-02-26 03:40:41 -03001178 return ret;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001179}
1180
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001181static void dm1105_remove(struct pci_dev *pdev)
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001182{
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001183 struct dm1105_dev *dev = pci_get_drvdata(pdev);
1184 struct dvb_adapter *dvb_adapter = &dev->dvb_adapter;
1185 struct dvb_demux *dvbdemux = &dev->demux;
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001186 struct dmx_demux *dmx = &dvbdemux->dmx;
1187
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001188 dm1105_ir_exit(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001189 dmx->close(dmx);
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001190 dvb_net_release(&dev->dvbnet);
1191 if (dev->fe)
1192 dvb_unregister_frontend(dev->fe);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001193
1194 dmx->disconnect_frontend(dmx);
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001195 dmx->remove_frontend(dmx, &dev->mem_frontend);
1196 dmx->remove_frontend(dmx, &dev->hw_frontend);
1197 dvb_dmxdev_release(&dev->dmxdev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001198 dvb_dmx_release(dvbdemux);
1199 dvb_unregister_adapter(dvb_adapter);
Alexandru Juncu0e48a3e2013-09-04 11:41:34 -03001200 i2c_del_adapter(&dev->i2c_adap);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001201
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001202 dm1105_hw_exit(dev);
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001203 free_irq(pdev->irq, dev);
1204 pci_iounmap(pdev, dev->io_mem);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001205 pci_release_regions(pdev);
1206 pci_disable_device(pdev);
Igor M. Liplianind8300df2009-07-22 17:30:25 -03001207 dm1105_devcount--;
Igor M. Liplianin34d2f9b2010-01-17 12:11:00 -03001208 kfree(dev);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001209}
1210
Arvind Yadav82c055c2017-08-01 13:56:22 -04001211static const struct pci_device_id dm1105_id_table[] = {
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001212 {
1213 .vendor = PCI_VENDOR_ID_TRIGEM,
1214 .device = PCI_DEVICE_ID_DM1105,
1215 .subvendor = PCI_ANY_ID,
Igor M. Liplianind8300df2009-07-22 17:30:25 -03001216 .subdevice = PCI_ANY_ID,
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001217 }, {
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -03001218 .vendor = PCI_VENDOR_ID_AXESS,
1219 .device = PCI_DEVICE_ID_DM05,
Igor M. Liplianind8300df2009-07-22 17:30:25 -03001220 .subvendor = PCI_ANY_ID,
1221 .subdevice = PCI_ANY_ID,
Igor M. Liplianin519a4bd2009-06-14 21:34:12 -03001222 }, {
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001223 /* empty */
1224 },
1225};
1226
1227MODULE_DEVICE_TABLE(pci, dm1105_id_table);
1228
1229static struct pci_driver dm1105_driver = {
1230 .name = DRIVER_NAME,
1231 .id_table = dm1105_id_table,
1232 .probe = dm1105_probe,
Greg Kroah-Hartman4c62e972012-12-21 13:17:53 -08001233 .remove = dm1105_remove,
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001234};
1235
Libo Chen548006c2013-05-26 22:31:49 -03001236module_pci_driver(dm1105_driver);
Igor M. Liplianina611d0c2008-09-13 10:10:53 -03001237
1238MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
1239MODULE_DESCRIPTION("SDMC DM1105 DVB driver");
1240MODULE_LICENSE("GPL");