2 * SMI PCIe driver for DVBSky cards.
4 * Copyright (C) 2014 Max nibble <nibble.max@gmail.com>
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 "m88ds3103.h"
20 #include "m88rs6000t.h"
24 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
26 static int smi_hw_init(struct smi_dev
*dev
)
28 u32 port_mux
, port_ctrl
, int_stat
;
31 port_mux
= smi_read(MUX_MODE_CTRL
);
32 port_mux
&= ~(rbPaMSMask
);
33 port_mux
|= rbPaMSDtvNoGpio
;
34 port_mux
&= ~(rbPbMSMask
);
35 port_mux
|= rbPbMSDtvNoGpio
;
36 port_mux
&= ~(0x0f0000);
38 smi_write(MUX_MODE_CTRL
, port_mux
);
40 /* set DTV register.*/
42 port_ctrl
= smi_read(VIDEO_CTRL_STATUS_A
);
44 smi_write(VIDEO_CTRL_STATUS_A
, port_ctrl
);
45 port_ctrl
= smi_read(MPEG2_CTRL_A
);
48 smi_write(MPEG2_CTRL_A
, port_ctrl
);
50 port_ctrl
= smi_read(VIDEO_CTRL_STATUS_B
);
52 smi_write(VIDEO_CTRL_STATUS_B
, port_ctrl
);
53 port_ctrl
= smi_read(MPEG2_CTRL_B
);
56 smi_write(MPEG2_CTRL_B
, port_ctrl
);
58 /* disable and clear interrupt.*/
59 smi_write(MSI_INT_ENA_CLR
, ALL_INT
);
60 int_stat
= smi_read(MSI_INT_STATUS
);
61 smi_write(MSI_INT_STATUS_CLR
, int_stat
);
64 smi_clear(PERIPHERAL_CTRL
, 0x0303);
66 smi_set(PERIPHERAL_CTRL
, 0x0101);
71 static void smi_i2c_cfg(struct smi_dev
*dev
, u32 sw_ctl
)
75 dwCtrl
= smi_read(sw_ctl
);
76 dwCtrl
&= ~0x18; /* disable output.*/
77 dwCtrl
|= 0x21; /* reset and software mode.*/
80 smi_write(sw_ctl
, dwCtrl
);
82 dwCtrl
= smi_read(sw_ctl
);
84 smi_write(sw_ctl
, dwCtrl
);
87 static void smi_i2c_setsda(struct smi_dev
*dev
, int state
, u32 sw_ctl
)
91 smi_clear(sw_ctl
, SW_I2C_MSK_DAT_EN
);
93 smi_clear(sw_ctl
, SW_I2C_MSK_DAT_OUT
);
95 smi_set(sw_ctl
, SW_I2C_MSK_DAT_EN
);
99 static void smi_i2c_setscl(void *data
, int state
, u32 sw_ctl
)
101 struct smi_dev
*dev
= data
;
105 smi_clear(sw_ctl
, SW_I2C_MSK_CLK_EN
);
107 smi_clear(sw_ctl
, SW_I2C_MSK_CLK_OUT
);
109 smi_set(sw_ctl
, SW_I2C_MSK_CLK_EN
);
113 static int smi_i2c_getsda(void *data
, u32 sw_ctl
)
115 struct smi_dev
*dev
= data
;
117 smi_clear(sw_ctl
, SW_I2C_MSK_DAT_EN
);
119 return (smi_read(sw_ctl
) & SW_I2C_MSK_DAT_IN
) ? 1 : 0;
122 static int smi_i2c_getscl(void *data
, u32 sw_ctl
)
124 struct smi_dev
*dev
= data
;
126 smi_clear(sw_ctl
, SW_I2C_MSK_CLK_EN
);
128 return (smi_read(sw_ctl
) & SW_I2C_MSK_CLK_IN
) ? 1 : 0;
131 static void smi_i2c0_setsda(void *data
, int state
)
133 struct smi_dev
*dev
= data
;
135 smi_i2c_setsda(dev
, state
, I2C_A_SW_CTL
);
138 static void smi_i2c0_setscl(void *data
, int state
)
140 struct smi_dev
*dev
= data
;
142 smi_i2c_setscl(dev
, state
, I2C_A_SW_CTL
);
145 static int smi_i2c0_getsda(void *data
)
147 struct smi_dev
*dev
= data
;
149 return smi_i2c_getsda(dev
, I2C_A_SW_CTL
);
152 static int smi_i2c0_getscl(void *data
)
154 struct smi_dev
*dev
= data
;
156 return smi_i2c_getscl(dev
, I2C_A_SW_CTL
);
159 static void smi_i2c1_setsda(void *data
, int state
)
161 struct smi_dev
*dev
= data
;
163 smi_i2c_setsda(dev
, state
, I2C_B_SW_CTL
);
166 static void smi_i2c1_setscl(void *data
, int state
)
168 struct smi_dev
*dev
= data
;
170 smi_i2c_setscl(dev
, state
, I2C_B_SW_CTL
);
173 static int smi_i2c1_getsda(void *data
)
175 struct smi_dev
*dev
= data
;
177 return smi_i2c_getsda(dev
, I2C_B_SW_CTL
);
180 static int smi_i2c1_getscl(void *data
)
182 struct smi_dev
*dev
= data
;
184 return smi_i2c_getscl(dev
, I2C_B_SW_CTL
);
187 static int smi_i2c_init(struct smi_dev
*dev
)
192 smi_i2c_cfg(dev
, I2C_A_SW_CTL
);
193 i2c_set_adapdata(&dev
->i2c_bus
[0], dev
);
194 strcpy(dev
->i2c_bus
[0].name
, "SMI-I2C0");
195 dev
->i2c_bus
[0].owner
= THIS_MODULE
;
196 dev
->i2c_bus
[0].dev
.parent
= &dev
->pci_dev
->dev
;
197 dev
->i2c_bus
[0].algo_data
= &dev
->i2c_bit
[0];
198 dev
->i2c_bit
[0].data
= dev
;
199 dev
->i2c_bit
[0].setsda
= smi_i2c0_setsda
;
200 dev
->i2c_bit
[0].setscl
= smi_i2c0_setscl
;
201 dev
->i2c_bit
[0].getsda
= smi_i2c0_getsda
;
202 dev
->i2c_bit
[0].getscl
= smi_i2c0_getscl
;
203 dev
->i2c_bit
[0].udelay
= 12;
204 dev
->i2c_bit
[0].timeout
= 10;
205 /* Raise SCL and SDA */
206 smi_i2c0_setsda(dev
, 1);
207 smi_i2c0_setscl(dev
, 1);
209 ret
= i2c_bit_add_bus(&dev
->i2c_bus
[0]);
214 smi_i2c_cfg(dev
, I2C_B_SW_CTL
);
215 i2c_set_adapdata(&dev
->i2c_bus
[1], dev
);
216 strcpy(dev
->i2c_bus
[1].name
, "SMI-I2C1");
217 dev
->i2c_bus
[1].owner
= THIS_MODULE
;
218 dev
->i2c_bus
[1].dev
.parent
= &dev
->pci_dev
->dev
;
219 dev
->i2c_bus
[1].algo_data
= &dev
->i2c_bit
[1];
220 dev
->i2c_bit
[1].data
= dev
;
221 dev
->i2c_bit
[1].setsda
= smi_i2c1_setsda
;
222 dev
->i2c_bit
[1].setscl
= smi_i2c1_setscl
;
223 dev
->i2c_bit
[1].getsda
= smi_i2c1_getsda
;
224 dev
->i2c_bit
[1].getscl
= smi_i2c1_getscl
;
225 dev
->i2c_bit
[1].udelay
= 12;
226 dev
->i2c_bit
[1].timeout
= 10;
227 /* Raise SCL and SDA */
228 smi_i2c1_setsda(dev
, 1);
229 smi_i2c1_setscl(dev
, 1);
231 ret
= i2c_bit_add_bus(&dev
->i2c_bus
[1]);
233 i2c_del_adapter(&dev
->i2c_bus
[0]);
238 static void smi_i2c_exit(struct smi_dev
*dev
)
240 i2c_del_adapter(&dev
->i2c_bus
[0]);
241 i2c_del_adapter(&dev
->i2c_bus
[1]);
244 static int smi_read_eeprom(struct i2c_adapter
*i2c
, u16 reg
, u8
*data
, u16 size
)
247 u8 b0
[2] = { (reg
>> 8) & 0xff, reg
& 0xff };
249 struct i2c_msg msg
[] = {
250 { .addr
= 0x50, .flags
= 0,
251 .buf
= b0
, .len
= 2 },
252 { .addr
= 0x50, .flags
= I2C_M_RD
,
253 .buf
= data
, .len
= size
}
256 ret
= i2c_transfer(i2c
, msg
, 2);
259 dev_err(&i2c
->dev
, "%s: reg=0x%x (error=%d)\n",
266 /* ts port interrupt operations */
267 static void smi_port_disableInterrupt(struct smi_port
*port
)
269 struct smi_dev
*dev
= port
->dev
;
271 smi_write(MSI_INT_ENA_CLR
,
272 (port
->_dmaInterruptCH0
| port
->_dmaInterruptCH1
));
275 static void smi_port_enableInterrupt(struct smi_port
*port
)
277 struct smi_dev
*dev
= port
->dev
;
279 smi_write(MSI_INT_ENA_SET
,
280 (port
->_dmaInterruptCH0
| port
->_dmaInterruptCH1
));
283 static void smi_port_clearInterrupt(struct smi_port
*port
)
285 struct smi_dev
*dev
= port
->dev
;
287 smi_write(MSI_INT_STATUS_CLR
,
288 (port
->_dmaInterruptCH0
| port
->_dmaInterruptCH1
));
291 /* tasklet handler: DMA data to dmx.*/
292 static void smi_dma_xfer(unsigned long data
)
294 struct smi_port
*port
= (struct smi_port
*) data
;
295 struct smi_dev
*dev
= port
->dev
;
296 u32 intr_status
, finishedData
, dmaManagement
;
297 u8 dmaChan0State
, dmaChan1State
;
299 intr_status
= port
->_int_status
;
300 dmaManagement
= smi_read(port
->DMA_MANAGEMENT
);
301 dmaChan0State
= (u8
)((dmaManagement
& 0x00000030) >> 4);
302 dmaChan1State
= (u8
)((dmaManagement
& 0x00300000) >> 20);
304 /* CH-0 DMA interrupt.*/
305 if ((intr_status
& port
->_dmaInterruptCH0
) && (dmaChan0State
== 0x01)) {
306 dev_dbg(&dev
->pci_dev
->dev
,
307 "Port[%d]-DMA CH0 engine complete successful !\n",
309 finishedData
= smi_read(port
->DMA_CHAN0_TRANS_STATE
);
310 finishedData
&= 0x003FFFFF;
311 /* value of DMA_PORT0_CHAN0_TRANS_STATE register [21:0]
312 * indicate dma total transfer length and
313 * zero of [21:0] indicate dma total transfer length
314 * equal to 0x400000 (4MB)*/
315 if (finishedData
== 0)
316 finishedData
= 0x00400000;
317 if (finishedData
!= SMI_TS_DMA_BUF_SIZE
) {
318 dev_dbg(&dev
->pci_dev
->dev
,
319 "DMA CH0 engine complete length mismatched, finish data=%d !\n",
322 dvb_dmx_swfilter_packets(&port
->demux
,
323 port
->cpu_addr
[0], (finishedData
/ 188));
324 /*dvb_dmx_swfilter(&port->demux,
325 port->cpu_addr[0], finishedData);*/
327 /* CH-1 DMA interrupt.*/
328 if ((intr_status
& port
->_dmaInterruptCH1
) && (dmaChan1State
== 0x01)) {
329 dev_dbg(&dev
->pci_dev
->dev
,
330 "Port[%d]-DMA CH1 engine complete successful !\n",
332 finishedData
= smi_read(port
->DMA_CHAN1_TRANS_STATE
);
333 finishedData
&= 0x003FFFFF;
334 /* value of DMA_PORT0_CHAN0_TRANS_STATE register [21:0]
335 * indicate dma total transfer length and
336 * zero of [21:0] indicate dma total transfer length
337 * equal to 0x400000 (4MB)*/
338 if (finishedData
== 0)
339 finishedData
= 0x00400000;
340 if (finishedData
!= SMI_TS_DMA_BUF_SIZE
) {
341 dev_dbg(&dev
->pci_dev
->dev
,
342 "DMA CH1 engine complete length mismatched, finish data=%d !\n",
345 dvb_dmx_swfilter_packets(&port
->demux
,
346 port
->cpu_addr
[1], (finishedData
/ 188));
347 /*dvb_dmx_swfilter(&port->demux,
348 port->cpu_addr[1], finishedData);*/
351 if (intr_status
& port
->_dmaInterruptCH0
)
352 dmaManagement
|= 0x00000002;
353 if (intr_status
& port
->_dmaInterruptCH1
)
354 dmaManagement
|= 0x00020000;
355 smi_write(port
->DMA_MANAGEMENT
, dmaManagement
);
356 /* Re-enable interrupts */
357 smi_port_enableInterrupt(port
);
360 static void smi_port_dma_free(struct smi_port
*port
)
362 if (port
->cpu_addr
[0]) {
363 pci_free_consistent(port
->dev
->pci_dev
, SMI_TS_DMA_BUF_SIZE
,
364 port
->cpu_addr
[0], port
->dma_addr
[0]);
365 port
->cpu_addr
[0] = NULL
;
367 if (port
->cpu_addr
[1]) {
368 pci_free_consistent(port
->dev
->pci_dev
, SMI_TS_DMA_BUF_SIZE
,
369 port
->cpu_addr
[1], port
->dma_addr
[1]);
370 port
->cpu_addr
[1] = NULL
;
374 static int smi_port_init(struct smi_port
*port
, int dmaChanUsed
)
376 dev_dbg(&port
->dev
->pci_dev
->dev
,
377 "%s, port %d, dmaused %d\n", __func__
, port
->idx
, dmaChanUsed
);
379 if (port
->idx
== 0) {
381 port
->_dmaInterruptCH0
= dmaChanUsed
& 0x01;
382 port
->_dmaInterruptCH1
= dmaChanUsed
& 0x02;
384 port
->DMA_CHAN0_ADDR_LOW
= DMA_PORTA_CHAN0_ADDR_LOW
;
385 port
->DMA_CHAN0_ADDR_HI
= DMA_PORTA_CHAN0_ADDR_HI
;
386 port
->DMA_CHAN0_TRANS_STATE
= DMA_PORTA_CHAN0_TRANS_STATE
;
387 port
->DMA_CHAN0_CONTROL
= DMA_PORTA_CHAN0_CONTROL
;
388 port
->DMA_CHAN1_ADDR_LOW
= DMA_PORTA_CHAN1_ADDR_LOW
;
389 port
->DMA_CHAN1_ADDR_HI
= DMA_PORTA_CHAN1_ADDR_HI
;
390 port
->DMA_CHAN1_TRANS_STATE
= DMA_PORTA_CHAN1_TRANS_STATE
;
391 port
->DMA_CHAN1_CONTROL
= DMA_PORTA_CHAN1_CONTROL
;
392 port
->DMA_MANAGEMENT
= DMA_PORTA_MANAGEMENT
;
395 port
->_dmaInterruptCH0
= (dmaChanUsed
<< 2) & 0x04;
396 port
->_dmaInterruptCH1
= (dmaChanUsed
<< 2) & 0x08;
398 port
->DMA_CHAN0_ADDR_LOW
= DMA_PORTB_CHAN0_ADDR_LOW
;
399 port
->DMA_CHAN0_ADDR_HI
= DMA_PORTB_CHAN0_ADDR_HI
;
400 port
->DMA_CHAN0_TRANS_STATE
= DMA_PORTB_CHAN0_TRANS_STATE
;
401 port
->DMA_CHAN0_CONTROL
= DMA_PORTB_CHAN0_CONTROL
;
402 port
->DMA_CHAN1_ADDR_LOW
= DMA_PORTB_CHAN1_ADDR_LOW
;
403 port
->DMA_CHAN1_ADDR_HI
= DMA_PORTB_CHAN1_ADDR_HI
;
404 port
->DMA_CHAN1_TRANS_STATE
= DMA_PORTB_CHAN1_TRANS_STATE
;
405 port
->DMA_CHAN1_CONTROL
= DMA_PORTB_CHAN1_CONTROL
;
406 port
->DMA_MANAGEMENT
= DMA_PORTB_MANAGEMENT
;
409 if (port
->_dmaInterruptCH0
) {
410 port
->cpu_addr
[0] = pci_alloc_consistent(port
->dev
->pci_dev
,
413 if (!port
->cpu_addr
[0]) {
414 dev_err(&port
->dev
->pci_dev
->dev
,
415 "Port[%d] DMA CH0 memory allocation failed!\n",
421 if (port
->_dmaInterruptCH1
) {
422 port
->cpu_addr
[1] = pci_alloc_consistent(port
->dev
->pci_dev
,
425 if (!port
->cpu_addr
[1]) {
426 dev_err(&port
->dev
->pci_dev
->dev
,
427 "Port[%d] DMA CH1 memory allocation failed!\n",
433 smi_port_disableInterrupt(port
);
434 tasklet_init(&port
->tasklet
, smi_dma_xfer
, (unsigned long)port
);
435 tasklet_disable(&port
->tasklet
);
439 smi_port_dma_free(port
);
443 static void smi_port_exit(struct smi_port
*port
)
445 smi_port_disableInterrupt(port
);
446 tasklet_kill(&port
->tasklet
);
447 smi_port_dma_free(port
);
451 static int smi_port_irq(struct smi_port
*port
, u32 int_status
)
453 u32 port_req_irq
= port
->_dmaInterruptCH0
| port
->_dmaInterruptCH1
;
456 if (int_status
& port_req_irq
) {
457 smi_port_disableInterrupt(port
);
458 port
->_int_status
= int_status
;
459 smi_port_clearInterrupt(port
);
460 tasklet_schedule(&port
->tasklet
);
466 static irqreturn_t
smi_irq_handler(int irq
, void *dev_id
)
468 struct smi_dev
*dev
= dev_id
;
469 struct smi_port
*port0
= &dev
->ts_port
[0];
470 struct smi_port
*port1
= &dev
->ts_port
[1];
471 struct smi_rc
*ir
= &dev
->ir
;
474 u32 intr_status
= smi_read(MSI_INT_STATUS
);
478 handled
+= smi_port_irq(port0
, intr_status
);
482 handled
+= smi_port_irq(port1
, intr_status
);
485 handled
+= smi_ir_irq(ir
, intr_status
);
487 return IRQ_RETVAL(handled
);
490 static struct i2c_client
*smi_add_i2c_client(struct i2c_adapter
*adapter
,
491 struct i2c_board_info
*info
)
493 struct i2c_client
*client
;
495 request_module(info
->type
);
496 client
= i2c_new_device(adapter
, info
);
497 if (client
== NULL
|| client
->dev
.driver
== NULL
)
498 goto err_add_i2c_client
;
500 if (!try_module_get(client
->dev
.driver
->owner
)) {
501 i2c_unregister_device(client
);
502 goto err_add_i2c_client
;
511 static void smi_del_i2c_client(struct i2c_client
*client
)
513 module_put(client
->dev
.driver
->owner
);
514 i2c_unregister_device(client
);
517 static const struct m88ds3103_config smi_dvbsky_m88ds3103_cfg
= {
522 .ts_mode
= M88DS3103_TS_PARALLEL
,
530 static int smi_dvbsky_m88ds3103_fe_attach(struct smi_port
*port
)
533 struct smi_dev
*dev
= port
->dev
;
534 struct i2c_adapter
*i2c
;
535 /* tuner I2C module */
536 struct i2c_adapter
*tuner_i2c_adapter
;
537 struct i2c_client
*tuner_client
;
538 struct i2c_board_info tuner_info
;
539 struct ts2020_config ts2020_config
= {};
540 memset(&tuner_info
, 0, sizeof(struct i2c_board_info
));
541 i2c
= (port
->idx
== 0) ? &dev
->i2c_bus
[0] : &dev
->i2c_bus
[1];
544 port
->fe
= dvb_attach(m88ds3103_attach
,
545 &smi_dvbsky_m88ds3103_cfg
, i2c
, &tuner_i2c_adapter
);
551 ts2020_config
.fe
= port
->fe
;
552 strlcpy(tuner_info
.type
, "ts2020", I2C_NAME_SIZE
);
553 tuner_info
.addr
= 0x60;
554 tuner_info
.platform_data
= &ts2020_config
;
555 tuner_client
= smi_add_i2c_client(tuner_i2c_adapter
, &tuner_info
);
558 goto err_tuner_i2c_device
;
561 /* delegate signal strength measurement to tuner */
562 port
->fe
->ops
.read_signal_strength
=
563 port
->fe
->ops
.tuner_ops
.get_rf_strength
;
565 port
->i2c_client_tuner
= tuner_client
;
568 err_tuner_i2c_device
:
569 dvb_frontend_detach(port
->fe
);
573 static const struct m88ds3103_config smi_dvbsky_m88rs6000_cfg
= {
577 .ts_mode
= M88DS3103_TS_PARALLEL
,
585 static int smi_dvbsky_m88rs6000_fe_attach(struct smi_port
*port
)
588 struct smi_dev
*dev
= port
->dev
;
589 struct i2c_adapter
*i2c
;
590 /* tuner I2C module */
591 struct i2c_adapter
*tuner_i2c_adapter
;
592 struct i2c_client
*tuner_client
;
593 struct i2c_board_info tuner_info
;
594 struct m88rs6000t_config m88rs6000t_config
;
596 memset(&tuner_info
, 0, sizeof(struct i2c_board_info
));
597 i2c
= (port
->idx
== 0) ? &dev
->i2c_bus
[0] : &dev
->i2c_bus
[1];
600 port
->fe
= dvb_attach(m88ds3103_attach
,
601 &smi_dvbsky_m88rs6000_cfg
, i2c
, &tuner_i2c_adapter
);
607 m88rs6000t_config
.fe
= port
->fe
;
608 strlcpy(tuner_info
.type
, "m88rs6000t", I2C_NAME_SIZE
);
609 tuner_info
.addr
= 0x21;
610 tuner_info
.platform_data
= &m88rs6000t_config
;
611 tuner_client
= smi_add_i2c_client(tuner_i2c_adapter
, &tuner_info
);
614 goto err_tuner_i2c_device
;
617 /* delegate signal strength measurement to tuner */
618 port
->fe
->ops
.read_signal_strength
=
619 port
->fe
->ops
.tuner_ops
.get_rf_strength
;
621 port
->i2c_client_tuner
= tuner_client
;
624 err_tuner_i2c_device
:
625 dvb_frontend_detach(port
->fe
);
629 static int smi_dvbsky_sit2_fe_attach(struct smi_port
*port
)
632 struct smi_dev
*dev
= port
->dev
;
633 struct i2c_adapter
*i2c
;
634 struct i2c_adapter
*tuner_i2c_adapter
;
635 struct i2c_client
*client_tuner
, *client_demod
;
636 struct i2c_board_info client_info
;
637 struct si2168_config si2168_config
;
638 struct si2157_config si2157_config
;
641 i2c
= (port
->idx
== 0) ? &dev
->i2c_bus
[0] : &dev
->i2c_bus
[1];
644 memset(&si2168_config
, 0, sizeof(si2168_config
));
645 si2168_config
.i2c_adapter
= &tuner_i2c_adapter
;
646 si2168_config
.fe
= &port
->fe
;
647 si2168_config
.ts_mode
= SI2168_TS_PARALLEL
;
649 memset(&client_info
, 0, sizeof(struct i2c_board_info
));
650 strlcpy(client_info
.type
, "si2168", I2C_NAME_SIZE
);
651 client_info
.addr
= 0x64;
652 client_info
.platform_data
= &si2168_config
;
654 client_demod
= smi_add_i2c_client(i2c
, &client_info
);
659 port
->i2c_client_demod
= client_demod
;
662 memset(&si2157_config
, 0, sizeof(si2157_config
));
663 si2157_config
.fe
= port
->fe
;
664 si2157_config
.if_port
= 1;
666 memset(&client_info
, 0, sizeof(struct i2c_board_info
));
667 strlcpy(client_info
.type
, "si2157", I2C_NAME_SIZE
);
668 client_info
.addr
= 0x60;
669 client_info
.platform_data
= &si2157_config
;
671 client_tuner
= smi_add_i2c_client(tuner_i2c_adapter
, &client_info
);
673 smi_del_i2c_client(port
->i2c_client_demod
);
674 port
->i2c_client_demod
= NULL
;
678 port
->i2c_client_tuner
= client_tuner
;
682 static int smi_fe_init(struct smi_port
*port
)
685 struct smi_dev
*dev
= port
->dev
;
686 struct dvb_adapter
*adap
= &port
->dvb_adapter
;
689 dev_dbg(&port
->dev
->pci_dev
->dev
,
690 "%s: port %d, fe_type = %d\n",
691 __func__
, port
->idx
, port
->fe_type
);
692 switch (port
->fe_type
) {
693 case DVBSKY_FE_M88DS3103
:
694 ret
= smi_dvbsky_m88ds3103_fe_attach(port
);
696 case DVBSKY_FE_M88RS6000
:
697 ret
= smi_dvbsky_m88rs6000_fe_attach(port
);
700 ret
= smi_dvbsky_sit2_fe_attach(port
);
706 /* register dvb frontend */
707 ret
= dvb_register_frontend(adap
, port
->fe
);
709 if (port
->i2c_client_tuner
)
710 smi_del_i2c_client(port
->i2c_client_tuner
);
711 if (port
->i2c_client_demod
)
712 smi_del_i2c_client(port
->i2c_client_demod
);
713 dvb_frontend_detach(port
->fe
);
717 ret
= smi_read_eeprom(&dev
->i2c_bus
[0], 0xc0, mac_ee
, 16);
718 dev_info(&port
->dev
->pci_dev
->dev
,
719 "%s port %d MAC: %pM\n", dev
->info
->name
,
720 port
->idx
, mac_ee
+ (port
->idx
)*8);
721 memcpy(adap
->proposed_mac
, mac_ee
+ (port
->idx
)*8, 6);
725 static void smi_fe_exit(struct smi_port
*port
)
727 dvb_unregister_frontend(port
->fe
);
728 /* remove I2C demod and tuner */
729 if (port
->i2c_client_tuner
)
730 smi_del_i2c_client(port
->i2c_client_tuner
);
731 if (port
->i2c_client_demod
)
732 smi_del_i2c_client(port
->i2c_client_demod
);
733 dvb_frontend_detach(port
->fe
);
736 static int my_dvb_dmx_ts_card_init(struct dvb_demux
*dvbdemux
, char *id
,
737 int (*start_feed
)(struct dvb_demux_feed
*),
738 int (*stop_feed
)(struct dvb_demux_feed
*),
741 dvbdemux
->priv
= priv
;
743 dvbdemux
->filternum
= 256;
744 dvbdemux
->feednum
= 256;
745 dvbdemux
->start_feed
= start_feed
;
746 dvbdemux
->stop_feed
= stop_feed
;
747 dvbdemux
->write_to_decoder
= NULL
;
748 dvbdemux
->dmx
.capabilities
= (DMX_TS_FILTERING
|
749 DMX_SECTION_FILTERING
|
750 DMX_MEMORY_BASED_FILTERING
);
751 return dvb_dmx_init(dvbdemux
);
754 static int my_dvb_dmxdev_ts_card_init(struct dmxdev
*dmxdev
,
755 struct dvb_demux
*dvbdemux
,
756 struct dmx_frontend
*hw_frontend
,
757 struct dmx_frontend
*mem_frontend
,
758 struct dvb_adapter
*dvb_adapter
)
762 dmxdev
->filternum
= 256;
763 dmxdev
->demux
= &dvbdemux
->dmx
;
764 dmxdev
->capabilities
= 0;
765 ret
= dvb_dmxdev_init(dmxdev
, dvb_adapter
);
769 hw_frontend
->source
= DMX_FRONTEND_0
;
770 dvbdemux
->dmx
.add_frontend(&dvbdemux
->dmx
, hw_frontend
);
771 mem_frontend
->source
= DMX_MEMORY_FE
;
772 dvbdemux
->dmx
.add_frontend(&dvbdemux
->dmx
, mem_frontend
);
773 return dvbdemux
->dmx
.connect_frontend(&dvbdemux
->dmx
, hw_frontend
);
776 static u32
smi_config_DMA(struct smi_port
*port
)
778 struct smi_dev
*dev
= port
->dev
;
779 u32 totalLength
= 0, dmaMemPtrLow
, dmaMemPtrHi
, dmaCtlReg
;
780 u8 chanLatencyTimer
= 0, dmaChanEnable
= 1, dmaTransStart
= 1;
781 u32 dmaManagement
= 0, tlpTransUnit
= DMA_TRANS_UNIT_188
;
782 u8 tlpTc
= 0, tlpTd
= 1, tlpEp
= 0, tlpAttr
= 0;
785 dmaManagement
= smi_read(port
->DMA_MANAGEMENT
);
786 /* Setup Channel-0 */
787 if (port
->_dmaInterruptCH0
) {
788 totalLength
= SMI_TS_DMA_BUF_SIZE
;
789 mem
= port
->dma_addr
[0];
790 dmaMemPtrLow
= mem
& 0xffffffff;
791 dmaMemPtrHi
= mem
>> 32;
792 dmaCtlReg
= (totalLength
) | (tlpTransUnit
<< 22) | (tlpTc
<< 25)
793 | (tlpTd
<< 28) | (tlpEp
<< 29) | (tlpAttr
<< 30);
794 dmaManagement
|= dmaChanEnable
| (dmaTransStart
<< 1)
795 | (chanLatencyTimer
<< 8);
796 /* write DMA register, start DMA engine */
797 smi_write(port
->DMA_CHAN0_ADDR_LOW
, dmaMemPtrLow
);
798 smi_write(port
->DMA_CHAN0_ADDR_HI
, dmaMemPtrHi
);
799 smi_write(port
->DMA_CHAN0_CONTROL
, dmaCtlReg
);
801 /* Setup Channel-1 */
802 if (port
->_dmaInterruptCH1
) {
803 totalLength
= SMI_TS_DMA_BUF_SIZE
;
804 mem
= port
->dma_addr
[1];
805 dmaMemPtrLow
= mem
& 0xffffffff;
806 dmaMemPtrHi
= mem
>> 32;
807 dmaCtlReg
= (totalLength
) | (tlpTransUnit
<< 22) | (tlpTc
<< 25)
808 | (tlpTd
<< 28) | (tlpEp
<< 29) | (tlpAttr
<< 30);
809 dmaManagement
|= (dmaChanEnable
<< 16) | (dmaTransStart
<< 17)
810 | (chanLatencyTimer
<< 24);
811 /* write DMA register, start DMA engine */
812 smi_write(port
->DMA_CHAN1_ADDR_LOW
, dmaMemPtrLow
);
813 smi_write(port
->DMA_CHAN1_ADDR_HI
, dmaMemPtrHi
);
814 smi_write(port
->DMA_CHAN1_CONTROL
, dmaCtlReg
);
816 return dmaManagement
;
819 static int smi_start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
821 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
822 struct smi_port
*port
= dvbdmx
->priv
;
823 struct smi_dev
*dev
= port
->dev
;
826 if (port
->users
++ == 0) {
827 dmaManagement
= smi_config_DMA(port
);
828 smi_port_clearInterrupt(port
);
829 smi_port_enableInterrupt(port
);
830 smi_write(port
->DMA_MANAGEMENT
, dmaManagement
);
831 tasklet_enable(&port
->tasklet
);
836 static int smi_stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
838 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
839 struct smi_port
*port
= dvbdmx
->priv
;
840 struct smi_dev
*dev
= port
->dev
;
845 tasklet_disable(&port
->tasklet
);
846 smi_port_disableInterrupt(port
);
847 smi_clear(port
->DMA_MANAGEMENT
, 0x30003);
851 static int smi_dvb_init(struct smi_port
*port
)
854 struct dvb_adapter
*adap
= &port
->dvb_adapter
;
855 struct dvb_demux
*dvbdemux
= &port
->demux
;
857 dev_dbg(&port
->dev
->pci_dev
->dev
,
858 "%s, port %d\n", __func__
, port
->idx
);
860 ret
= dvb_register_adapter(adap
, "SMI_DVB", THIS_MODULE
,
861 &port
->dev
->pci_dev
->dev
,
864 dev_err(&port
->dev
->pci_dev
->dev
, "Fail to register DVB adapter.\n");
867 ret
= my_dvb_dmx_ts_card_init(dvbdemux
, "SW demux",
869 smi_stop_feed
, port
);
871 goto err_del_dvb_register_adapter
;
873 ret
= my_dvb_dmxdev_ts_card_init(&port
->dmxdev
, &port
->demux
,
875 &port
->mem_frontend
, adap
);
877 goto err_del_dvb_dmx
;
879 ret
= dvb_net_init(adap
, &port
->dvbnet
, port
->dmxdev
.demux
);
881 goto err_del_dvb_dmxdev
;
884 dvbdemux
->dmx
.close(&dvbdemux
->dmx
);
885 dvbdemux
->dmx
.remove_frontend(&dvbdemux
->dmx
, &port
->hw_frontend
);
886 dvbdemux
->dmx
.remove_frontend(&dvbdemux
->dmx
, &port
->mem_frontend
);
887 dvb_dmxdev_release(&port
->dmxdev
);
889 dvb_dmx_release(&port
->demux
);
890 err_del_dvb_register_adapter
:
891 dvb_unregister_adapter(&port
->dvb_adapter
);
895 static void smi_dvb_exit(struct smi_port
*port
)
897 struct dvb_demux
*dvbdemux
= &port
->demux
;
899 dvb_net_release(&port
->dvbnet
);
901 dvbdemux
->dmx
.close(&dvbdemux
->dmx
);
902 dvbdemux
->dmx
.remove_frontend(&dvbdemux
->dmx
, &port
->hw_frontend
);
903 dvbdemux
->dmx
.remove_frontend(&dvbdemux
->dmx
, &port
->mem_frontend
);
904 dvb_dmxdev_release(&port
->dmxdev
);
905 dvb_dmx_release(&port
->demux
);
907 dvb_unregister_adapter(&port
->dvb_adapter
);
910 static int smi_port_attach(struct smi_dev
*dev
,
911 struct smi_port
*port
, int index
)
917 port
->fe_type
= (index
== 0) ? dev
->info
->fe_0
: dev
->info
->fe_1
;
918 dmachs
= (index
== 0) ? dev
->info
->ts_0
: dev
->info
->ts_1
;
920 ret
= smi_port_init(port
, dmachs
);
924 ret
= smi_dvb_init(port
);
926 goto err_del_port_init
;
928 ret
= smi_fe_init(port
);
930 goto err_del_dvb_init
;
939 static void smi_port_detach(struct smi_port
*port
)
946 static int smi_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
951 if (pci_enable_device(pdev
) < 0)
954 dev
= kzalloc(sizeof(struct smi_dev
), GFP_KERNEL
);
957 goto err_pci_disable_device
;
961 pci_set_drvdata(pdev
, dev
);
962 dev
->info
= (struct smi_cfg_info
*) id
->driver_data
;
963 dev_info(&dev
->pci_dev
->dev
,
964 "card detected: %s\n", dev
->info
->name
);
966 dev
->nr
= dev
->info
->type
;
967 dev
->lmmio
= ioremap(pci_resource_start(dev
->pci_dev
, 0),
968 pci_resource_len(dev
->pci_dev
, 0));
974 /* should we set to 32bit DMA? */
975 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
977 goto err_pci_iounmap
;
979 pci_set_master(pdev
);
981 ret
= smi_hw_init(dev
);
983 goto err_pci_iounmap
;
985 ret
= smi_i2c_init(dev
);
987 goto err_pci_iounmap
;
989 if (dev
->info
->ts_0
) {
990 ret
= smi_port_attach(dev
, &dev
->ts_port
[0], 0);
992 goto err_del_i2c_adaptor
;
995 if (dev
->info
->ts_1
) {
996 ret
= smi_port_attach(dev
, &dev
->ts_port
[1], 1);
998 goto err_del_port0_attach
;
1001 ret
= smi_ir_init(dev
);
1003 goto err_del_port1_attach
;
1005 #ifdef CONFIG_PCI_MSI /* to do msi interrupt.???*/
1006 if (pci_msi_enabled())
1007 ret
= pci_enable_msi(dev
->pci_dev
);
1009 dev_info(&dev
->pci_dev
->dev
, "MSI not available.\n");
1012 ret
= request_irq(dev
->pci_dev
->irq
, smi_irq_handler
,
1013 IRQF_SHARED
, "SMI_PCIE", dev
);
1017 smi_ir_start(&dev
->ir
);
1022 err_del_port1_attach
:
1023 if (dev
->info
->ts_1
)
1024 smi_port_detach(&dev
->ts_port
[1]);
1025 err_del_port0_attach
:
1026 if (dev
->info
->ts_0
)
1027 smi_port_detach(&dev
->ts_port
[0]);
1028 err_del_i2c_adaptor
:
1031 iounmap(dev
->lmmio
);
1033 pci_set_drvdata(pdev
, NULL
);
1035 err_pci_disable_device
:
1036 pci_disable_device(pdev
);
1040 static void smi_remove(struct pci_dev
*pdev
)
1042 struct smi_dev
*dev
= pci_get_drvdata(pdev
);
1044 smi_write(MSI_INT_ENA_CLR
, ALL_INT
);
1045 free_irq(dev
->pci_dev
->irq
, dev
);
1046 #ifdef CONFIG_PCI_MSI
1047 pci_disable_msi(dev
->pci_dev
);
1049 if (dev
->info
->ts_1
)
1050 smi_port_detach(&dev
->ts_port
[1]);
1051 if (dev
->info
->ts_0
)
1052 smi_port_detach(&dev
->ts_port
[0]);
1056 iounmap(dev
->lmmio
);
1057 pci_set_drvdata(pdev
, NULL
);
1058 pci_disable_device(pdev
);
1063 static const struct smi_cfg_info dvbsky_s950_cfg
= {
1064 .type
= SMI_DVBSKY_S950
,
1065 .name
= "DVBSky S950 V3",
1066 .ts_0
= SMI_TS_NULL
,
1067 .ts_1
= SMI_TS_DMA_BOTH
,
1068 .fe_0
= DVBSKY_FE_NULL
,
1069 .fe_1
= DVBSKY_FE_M88DS3103
,
1070 .rc_map
= RC_MAP_DVBSKY
,
1073 static const struct smi_cfg_info dvbsky_s952_cfg
= {
1074 .type
= SMI_DVBSKY_S952
,
1075 .name
= "DVBSky S952 V3",
1076 .ts_0
= SMI_TS_DMA_BOTH
,
1077 .ts_1
= SMI_TS_DMA_BOTH
,
1078 .fe_0
= DVBSKY_FE_M88RS6000
,
1079 .fe_1
= DVBSKY_FE_M88RS6000
,
1080 .rc_map
= RC_MAP_DVBSKY
,
1083 static const struct smi_cfg_info dvbsky_t9580_cfg
= {
1084 .type
= SMI_DVBSKY_T9580
,
1085 .name
= "DVBSky T9580 V3",
1086 .ts_0
= SMI_TS_DMA_BOTH
,
1087 .ts_1
= SMI_TS_DMA_BOTH
,
1088 .fe_0
= DVBSKY_FE_SIT2
,
1089 .fe_1
= DVBSKY_FE_M88DS3103
,
1090 .rc_map
= RC_MAP_DVBSKY
,
1093 static const struct smi_cfg_info technotrend_s2_4200_cfg
= {
1094 .type
= SMI_TECHNOTREND_S2_4200
,
1095 .name
= "TechnoTrend TT-budget S2-4200 Twin",
1096 .ts_0
= SMI_TS_DMA_BOTH
,
1097 .ts_1
= SMI_TS_DMA_BOTH
,
1098 .fe_0
= DVBSKY_FE_M88RS6000
,
1099 .fe_1
= DVBSKY_FE_M88RS6000
,
1100 .rc_map
= RC_MAP_TT_1500
,
1104 #define SMI_ID(_subvend, _subdev, _driverdata) { \
1105 .vendor = SMI_VID, .device = SMI_PID, \
1106 .subvendor = _subvend, .subdevice = _subdev, \
1107 .driver_data = (unsigned long)&_driverdata }
1109 static const struct pci_device_id smi_id_table
[] = {
1110 SMI_ID(0x4254, 0x0550, dvbsky_s950_cfg
),
1111 SMI_ID(0x4254, 0x0552, dvbsky_s952_cfg
),
1112 SMI_ID(0x4254, 0x5580, dvbsky_t9580_cfg
),
1113 SMI_ID(0x13c2, 0x3016, technotrend_s2_4200_cfg
),
1116 MODULE_DEVICE_TABLE(pci
, smi_id_table
);
1118 static struct pci_driver smipcie_driver
= {
1119 .name
= "SMI PCIe driver",
1120 .id_table
= smi_id_table
,
1122 .remove
= smi_remove
,
1125 module_pci_driver(smipcie_driver
);
1127 MODULE_AUTHOR("Max nibble <nibble.max@gmail.com>");
1128 MODULE_DESCRIPTION("SMI PCIe driver");
1129 MODULE_LICENSE("GPL");