1 // SPDX-License-Identifier: GPL-2.0
3 * ddbridge-core.c: Digital Devices bridge core functions
5 * Copyright (C) 2010-2017 Digital Devices GmbH
6 * Marcus Metzler <mocm@metzlerbros.de>
7 * Ralph Metzler <rjkm@metzlerbros.de>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 only, as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/delay.h>
23 #include <linux/slab.h>
24 #include <linux/poll.h>
26 #include <linux/pci.h>
27 #include <linux/pci_ids.h>
28 #include <linux/timer.h>
29 #include <linux/i2c.h>
30 #include <linux/swab.h>
31 #include <linux/vmalloc.h>
34 #include "ddbridge-i2c.h"
35 #include "ddbridge-regs.h"
36 #include "ddbridge-max.h"
37 #include "ddbridge-ci.h"
38 #include "ddbridge-io.h"
40 #include "tda18271c2dd.h"
46 #include "stv0367_priv.h"
47 #include "cxd2841er.h"
53 #include "ddbridge-dummy-fe.h"
55 /****************************************************************************/
57 #define DDB_MAX_ADAPTER 64
59 /****************************************************************************/
61 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
63 static int adapter_alloc
;
64 module_param(adapter_alloc
, int, 0444);
65 MODULE_PARM_DESC(adapter_alloc
,
66 "0-one adapter per io, 1-one per tab with io, 2-one per tab, 3-one for all");
68 static int ci_bitrate
= 70000;
69 module_param(ci_bitrate
, int, 0444);
70 MODULE_PARM_DESC(ci_bitrate
, " Bitrate in KHz for output to CI.");
72 static int ts_loop
= -1;
73 module_param(ts_loop
, int, 0444);
74 MODULE_PARM_DESC(ts_loop
, "TS in/out test loop on port ts_loop");
76 static int xo2_speed
= 2;
77 module_param(xo2_speed
, int, 0444);
78 MODULE_PARM_DESC(xo2_speed
, "default transfer speed for xo2 based duoflex, 0=55,1=75,2=90,3=104 MBit/s, default=2, use attribute to change for individual cards");
81 static int alt_dma
= 1;
85 module_param(alt_dma
, int, 0444);
86 MODULE_PARM_DESC(alt_dma
, "use alternative DMA buffer handling");
89 module_param(no_init
, int, 0444);
90 MODULE_PARM_DESC(no_init
, "do not initialize most devices");
92 static int stv0910_single
;
93 module_param(stv0910_single
, int, 0444);
94 MODULE_PARM_DESC(stv0910_single
, "use stv0910 cards as single demods");
96 static int dma_buf_num
= 8;
97 module_param(dma_buf_num
, int, 0444);
98 MODULE_PARM_DESC(dma_buf_num
, "Number of DMA buffers, possible values: 8-32");
100 static int dma_buf_size
= 21;
101 module_param(dma_buf_size
, int, 0444);
102 MODULE_PARM_DESC(dma_buf_size
,
103 "DMA buffer size as multiple of 128*47, possible values: 1-43");
105 static int dummy_tuner
;
106 module_param(dummy_tuner
, int, 0444);
107 MODULE_PARM_DESC(dummy_tuner
,
108 "attach dummy tuner to port 0 on Octopus V3 or Octopus Mini cards");
110 /****************************************************************************/
112 static DEFINE_MUTEX(redirect_lock
);
114 static struct workqueue_struct
*ddb_wq
;
116 static struct ddb
*ddbs
[DDB_MAX_ADAPTER
];
118 /****************************************************************************/
119 /****************************************************************************/
120 /****************************************************************************/
122 struct ddb_irq
*ddb_irq_set(struct ddb
*dev
, u32 link
, u32 nr
,
123 void (*handler
)(void *), void *data
)
125 struct ddb_irq
*irq
= &dev
->link
[link
].irq
[nr
];
127 irq
->handler
= handler
;
132 static void ddb_set_dma_table(struct ddb_io
*io
)
134 struct ddb
*dev
= io
->port
->dev
;
135 struct ddb_dma
*dma
= io
->dma
;
141 for (i
= 0; i
< dma
->num
; i
++) {
143 ddbwritel(dev
, mem
& 0xffffffff, dma
->bufregs
+ i
* 8);
144 ddbwritel(dev
, mem
>> 32, dma
->bufregs
+ i
* 8 + 4);
146 dma
->bufval
= ((dma
->div
& 0x0f) << 16) |
147 ((dma
->num
& 0x1f) << 11) |
148 ((dma
->size
>> 7) & 0x7ff);
151 static void ddb_set_dma_tables(struct ddb
*dev
)
155 for (i
= 0; i
< DDB_MAX_PORT
; i
++) {
156 if (dev
->port
[i
].input
[0])
157 ddb_set_dma_table(dev
->port
[i
].input
[0]);
158 if (dev
->port
[i
].input
[1])
159 ddb_set_dma_table(dev
->port
[i
].input
[1]);
160 if (dev
->port
[i
].output
)
161 ddb_set_dma_table(dev
->port
[i
].output
);
165 /****************************************************************************/
166 /****************************************************************************/
167 /****************************************************************************/
169 static void ddb_redirect_dma(struct ddb
*dev
,
170 struct ddb_dma
*sdma
,
171 struct ddb_dma
*ddma
)
176 sdma
->bufval
= ddma
->bufval
;
177 base
= sdma
->bufregs
;
178 for (i
= 0; i
< ddma
->num
; i
++) {
180 ddbwritel(dev
, mem
& 0xffffffff, base
+ i
* 8);
181 ddbwritel(dev
, mem
>> 32, base
+ i
* 8 + 4);
185 static int ddb_unredirect(struct ddb_port
*port
)
187 struct ddb_input
*oredi
, *iredi
= NULL
;
188 struct ddb_output
*iredo
= NULL
;
190 /* dev_info(port->dev->dev,
191 * "unredirect %d.%d\n", port->dev->nr, port->nr);
193 mutex_lock(&redirect_lock
);
194 if (port
->output
->dma
->running
) {
195 mutex_unlock(&redirect_lock
);
198 oredi
= port
->output
->redi
;
201 if (port
->input
[0]) {
202 iredi
= port
->input
[0]->redi
;
203 iredo
= port
->input
[0]->redo
;
206 iredo
->port
->output
->redi
= oredi
;
207 if (iredo
->port
->input
[0]) {
208 iredo
->port
->input
[0]->redi
= iredi
;
209 ddb_redirect_dma(oredi
->port
->dev
,
210 oredi
->dma
, iredo
->dma
);
212 port
->input
[0]->redo
= NULL
;
213 ddb_set_dma_table(port
->input
[0]);
216 port
->input
[0]->redi
= NULL
;
219 port
->output
->redi
= NULL
;
221 ddb_set_dma_table(oredi
);
223 mutex_unlock(&redirect_lock
);
227 static int ddb_redirect(u32 i
, u32 p
)
229 struct ddb
*idev
= ddbs
[(i
>> 4) & 0x3f];
230 struct ddb_input
*input
, *input2
;
231 struct ddb
*pdev
= ddbs
[(p
>> 4) & 0x3f];
232 struct ddb_port
*port
;
236 if (!idev
->has_dma
|| !pdev
->has_dma
)
239 port
= &pdev
->port
[p
& 0x0f];
242 if (ddb_unredirect(port
))
248 input
= &idev
->input
[i
& 7];
252 mutex_lock(&redirect_lock
);
253 if (port
->output
->dma
->running
|| input
->dma
->running
) {
254 mutex_unlock(&redirect_lock
);
257 input2
= port
->input
[0];
260 input2
->redi
= input
->redi
;
263 input2
->redi
= input
;
266 input
->redo
= port
->output
;
267 port
->output
->redi
= input
;
269 ddb_redirect_dma(input
->port
->dev
, input
->dma
, port
->output
->dma
);
270 mutex_unlock(&redirect_lock
);
274 /****************************************************************************/
275 /****************************************************************************/
276 /****************************************************************************/
278 static void dma_free(struct pci_dev
*pdev
, struct ddb_dma
*dma
, int dir
)
284 for (i
= 0; i
< dma
->num
; i
++) {
287 dma_unmap_single(&pdev
->dev
, dma
->pbuf
[i
],
289 dir
? DMA_TO_DEVICE
:
294 dma_free_coherent(&pdev
->dev
, dma
->size
,
295 dma
->vbuf
[i
], dma
->pbuf
[i
]);
303 static int dma_alloc(struct pci_dev
*pdev
, struct ddb_dma
*dma
, int dir
)
309 for (i
= 0; i
< dma
->num
; i
++) {
311 dma
->vbuf
[i
] = kmalloc(dma
->size
, __GFP_RETRY_MAYFAIL
);
314 dma
->pbuf
[i
] = dma_map_single(&pdev
->dev
,
317 dir
? DMA_TO_DEVICE
:
319 if (dma_mapping_error(&pdev
->dev
, dma
->pbuf
[i
])) {
325 dma
->vbuf
[i
] = dma_alloc_coherent(&pdev
->dev
,
336 int ddb_buffers_alloc(struct ddb
*dev
)
339 struct ddb_port
*port
;
341 for (i
= 0; i
< dev
->port_num
; i
++) {
342 port
= &dev
->port
[i
];
343 switch (port
->class) {
345 if (port
->input
[0]->dma
)
346 if (dma_alloc(dev
->pdev
, port
->input
[0]->dma
, 0)
349 if (port
->input
[1]->dma
)
350 if (dma_alloc(dev
->pdev
, port
->input
[1]->dma
, 0)
356 if (port
->input
[0]->dma
)
357 if (dma_alloc(dev
->pdev
, port
->input
[0]->dma
, 0)
360 if (port
->output
->dma
)
361 if (dma_alloc(dev
->pdev
, port
->output
->dma
, 1)
369 ddb_set_dma_tables(dev
);
373 void ddb_buffers_free(struct ddb
*dev
)
376 struct ddb_port
*port
;
378 for (i
= 0; i
< dev
->port_num
; i
++) {
379 port
= &dev
->port
[i
];
381 if (port
->input
[0] && port
->input
[0]->dma
)
382 dma_free(dev
->pdev
, port
->input
[0]->dma
, 0);
383 if (port
->input
[1] && port
->input
[1]->dma
)
384 dma_free(dev
->pdev
, port
->input
[1]->dma
, 0);
385 if (port
->output
&& port
->output
->dma
)
386 dma_free(dev
->pdev
, port
->output
->dma
, 1);
390 static void calc_con(struct ddb_output
*output
, u32
*con
, u32
*con2
, u32 flags
)
392 struct ddb
*dev
= output
->port
->dev
;
393 u32 bitrate
= output
->port
->obr
, max_bitrate
= 72000;
394 u32 gap
= 4, nco
= 0;
397 if (output
->port
->gap
!= 0xffffffff) {
399 gap
= output
->port
->gap
;
402 if (dev
->link
[0].info
->type
== DDB_OCTOPUS_CI
&& output
->port
->nr
> 1) {
404 if (dev
->link
[0].ids
.regmapid
>= 0x10003 && !(flags
& 1)) {
409 if (bitrate
!= 72000) {
410 if (bitrate
>= 96000) {
414 nco
= (bitrate
* 8192 + 71999)
419 /* Divider and gap */
421 if (bitrate
<= 64000) {
424 } else if (bitrate
<= 72000) {
433 if (bitrate
> 72000) {
434 *con
|= 0x810; /* 96 MBit/s and gap */
437 *con
|= 0x10; /* enable gap */
440 if (max_bitrate
> 0) {
441 if (bitrate
> max_bitrate
)
442 bitrate
= max_bitrate
;
445 gap
= ((max_bitrate
- bitrate
) * 94) / bitrate
;
447 *con
&= ~0x10; /* Disable gap */
454 *con2
= (nco
<< 16) | gap
;
457 static void ddb_output_start(struct ddb_output
*output
)
459 struct ddb
*dev
= output
->port
->dev
;
460 u32 con
= 0x11c, con2
= 0;
462 spin_lock_irq(&output
->dma
->lock
);
463 output
->dma
->cbuf
= 0;
464 output
->dma
->coff
= 0;
465 output
->dma
->stat
= 0;
466 ddbwritel(dev
, 0, DMA_BUFFER_CONTROL(output
->dma
));
468 if (output
->port
->input
[0]->port
->class == DDB_PORT_LOOP
)
469 con
= (1UL << 13) | 0x14;
471 calc_con(output
, &con
, &con2
, 0);
473 ddbwritel(dev
, 0, TS_CONTROL(output
));
474 ddbwritel(dev
, 2, TS_CONTROL(output
));
475 ddbwritel(dev
, 0, TS_CONTROL(output
));
476 ddbwritel(dev
, con
, TS_CONTROL(output
));
477 ddbwritel(dev
, con2
, TS_CONTROL2(output
));
479 ddbwritel(dev
, output
->dma
->bufval
,
480 DMA_BUFFER_SIZE(output
->dma
));
481 ddbwritel(dev
, 0, DMA_BUFFER_ACK(output
->dma
));
482 ddbwritel(dev
, 1, DMA_BASE_READ
);
483 ddbwritel(dev
, 7, DMA_BUFFER_CONTROL(output
->dma
));
485 ddbwritel(dev
, con
| 1, TS_CONTROL(output
));
487 output
->dma
->running
= 1;
488 spin_unlock_irq(&output
->dma
->lock
);
491 static void ddb_output_stop(struct ddb_output
*output
)
493 struct ddb
*dev
= output
->port
->dev
;
495 spin_lock_irq(&output
->dma
->lock
);
497 ddbwritel(dev
, 0, TS_CONTROL(output
));
499 ddbwritel(dev
, 0, DMA_BUFFER_CONTROL(output
->dma
));
500 output
->dma
->running
= 0;
501 spin_unlock_irq(&output
->dma
->lock
);
504 static void ddb_input_stop(struct ddb_input
*input
)
506 struct ddb
*dev
= input
->port
->dev
;
507 u32 tag
= DDB_LINK_TAG(input
->port
->lnr
);
509 spin_lock_irq(&input
->dma
->lock
);
511 ddbwritel(dev
, 0, tag
| TS_CONTROL(input
));
513 ddbwritel(dev
, 0, DMA_BUFFER_CONTROL(input
->dma
));
514 input
->dma
->running
= 0;
515 spin_unlock_irq(&input
->dma
->lock
);
518 static void ddb_input_start(struct ddb_input
*input
)
520 struct ddb
*dev
= input
->port
->dev
;
522 spin_lock_irq(&input
->dma
->lock
);
523 input
->dma
->cbuf
= 0;
524 input
->dma
->coff
= 0;
525 input
->dma
->stat
= 0;
526 ddbwritel(dev
, 0, DMA_BUFFER_CONTROL(input
->dma
));
528 ddbwritel(dev
, 0, TS_CONTROL(input
));
529 ddbwritel(dev
, 2, TS_CONTROL(input
));
530 ddbwritel(dev
, 0, TS_CONTROL(input
));
532 ddbwritel(dev
, input
->dma
->bufval
,
533 DMA_BUFFER_SIZE(input
->dma
));
534 ddbwritel(dev
, 0, DMA_BUFFER_ACK(input
->dma
));
535 ddbwritel(dev
, 1, DMA_BASE_WRITE
);
536 ddbwritel(dev
, 3, DMA_BUFFER_CONTROL(input
->dma
));
538 ddbwritel(dev
, 0x09, TS_CONTROL(input
));
540 if (input
->port
->type
== DDB_TUNER_DUMMY
)
541 ddbwritel(dev
, 0x000fff01, TS_CONTROL2(input
));
543 input
->dma
->running
= 1;
544 spin_unlock_irq(&input
->dma
->lock
);
547 static void ddb_input_start_all(struct ddb_input
*input
)
549 struct ddb_input
*i
= input
;
550 struct ddb_output
*o
;
552 mutex_lock(&redirect_lock
);
553 while (i
&& (o
= i
->redo
)) {
555 i
= o
->port
->input
[0];
559 ddb_input_start(input
);
560 mutex_unlock(&redirect_lock
);
563 static void ddb_input_stop_all(struct ddb_input
*input
)
565 struct ddb_input
*i
= input
;
566 struct ddb_output
*o
;
568 mutex_lock(&redirect_lock
);
569 ddb_input_stop(input
);
570 while (i
&& (o
= i
->redo
)) {
572 i
= o
->port
->input
[0];
576 mutex_unlock(&redirect_lock
);
579 static u32
ddb_output_free(struct ddb_output
*output
)
581 u32 idx
, off
, stat
= output
->dma
->stat
;
584 idx
= (stat
>> 11) & 0x1f;
585 off
= (stat
& 0x7ff) << 7;
587 if (output
->dma
->cbuf
!= idx
) {
588 if ((((output
->dma
->cbuf
+ 1) % output
->dma
->num
) == idx
) &&
589 (output
->dma
->size
- output
->dma
->coff
<= (2 * 188)))
593 diff
= off
- output
->dma
->coff
;
594 if (diff
<= 0 || diff
> (2 * 188))
599 static ssize_t
ddb_output_write(struct ddb_output
*output
,
600 const __user u8
*buf
, size_t count
)
602 struct ddb
*dev
= output
->port
->dev
;
603 u32 idx
, off
, stat
= output
->dma
->stat
;
604 u32 left
= count
, len
;
606 idx
= (stat
>> 11) & 0x1f;
607 off
= (stat
& 0x7ff) << 7;
610 len
= output
->dma
->size
- output
->dma
->coff
;
611 if ((((output
->dma
->cbuf
+ 1) % output
->dma
->num
) == idx
) &&
617 if (output
->dma
->cbuf
== idx
) {
618 if (off
> output
->dma
->coff
) {
619 len
= off
- output
->dma
->coff
;
628 if (copy_from_user(output
->dma
->vbuf
[output
->dma
->cbuf
] +
633 dma_sync_single_for_device(
635 output
->dma
->pbuf
[output
->dma
->cbuf
],
636 output
->dma
->size
, DMA_TO_DEVICE
);
639 output
->dma
->coff
+= len
;
640 if (output
->dma
->coff
== output
->dma
->size
) {
641 output
->dma
->coff
= 0;
642 output
->dma
->cbuf
= ((output
->dma
->cbuf
+ 1) %
646 (output
->dma
->cbuf
<< 11) |
647 (output
->dma
->coff
>> 7),
648 DMA_BUFFER_ACK(output
->dma
));
653 static u32
ddb_input_avail(struct ddb_input
*input
)
655 struct ddb
*dev
= input
->port
->dev
;
656 u32 idx
, off
, stat
= input
->dma
->stat
;
657 u32 ctrl
= ddbreadl(dev
, DMA_BUFFER_CONTROL(input
->dma
));
659 idx
= (stat
>> 11) & 0x1f;
660 off
= (stat
& 0x7ff) << 7;
663 dev_err(dev
->dev
, "IA %d %d %08x\n", idx
, off
, ctrl
);
664 ddbwritel(dev
, stat
, DMA_BUFFER_ACK(input
->dma
));
667 if (input
->dma
->cbuf
!= idx
)
672 static ssize_t
ddb_input_read(struct ddb_input
*input
,
673 __user u8
*buf
, size_t count
)
675 struct ddb
*dev
= input
->port
->dev
;
677 u32 idx
, free
, stat
= input
->dma
->stat
;
680 idx
= (stat
>> 11) & 0x1f;
683 if (input
->dma
->cbuf
== idx
)
685 free
= input
->dma
->size
- input
->dma
->coff
;
689 dma_sync_single_for_cpu(
691 input
->dma
->pbuf
[input
->dma
->cbuf
],
692 input
->dma
->size
, DMA_FROM_DEVICE
);
693 ret
= copy_to_user(buf
, input
->dma
->vbuf
[input
->dma
->cbuf
] +
694 input
->dma
->coff
, free
);
697 input
->dma
->coff
+= free
;
698 if (input
->dma
->coff
== input
->dma
->size
) {
699 input
->dma
->coff
= 0;
700 input
->dma
->cbuf
= (input
->dma
->cbuf
+ 1) %
706 (input
->dma
->cbuf
<< 11) | (input
->dma
->coff
>> 7),
707 DMA_BUFFER_ACK(input
->dma
));
712 /****************************************************************************/
713 /****************************************************************************/
715 static ssize_t
ts_write(struct file
*file
, const __user
char *buf
,
716 size_t count
, loff_t
*ppos
)
718 struct dvb_device
*dvbdev
= file
->private_data
;
719 struct ddb_output
*output
= dvbdev
->priv
;
720 struct ddb
*dev
= output
->port
->dev
;
727 if (ddb_output_free(output
) < 188) {
728 if (file
->f_flags
& O_NONBLOCK
)
730 if (wait_event_interruptible(
732 ddb_output_free(output
) >= 188) < 0)
735 stat
= ddb_output_write(output
, buf
, left
);
741 return (left
== count
) ? -EAGAIN
: (count
- left
);
744 static ssize_t
ts_read(struct file
*file
, __user
char *buf
,
745 size_t count
, loff_t
*ppos
)
747 struct dvb_device
*dvbdev
= file
->private_data
;
748 struct ddb_output
*output
= dvbdev
->priv
;
749 struct ddb_input
*input
= output
->port
->input
[0];
750 struct ddb
*dev
= output
->port
->dev
;
757 if (ddb_input_avail(input
) < 188) {
758 if (file
->f_flags
& O_NONBLOCK
)
760 if (wait_event_interruptible(
762 ddb_input_avail(input
) >= 188) < 0)
765 stat
= ddb_input_read(input
, buf
, left
);
771 return (count
&& (left
== count
)) ? -EAGAIN
: (count
- left
);
774 static __poll_t
ts_poll(struct file
*file
, poll_table
*wait
)
776 struct dvb_device
*dvbdev
= file
->private_data
;
777 struct ddb_output
*output
= dvbdev
->priv
;
778 struct ddb_input
*input
= output
->port
->input
[0];
782 poll_wait(file
, &input
->dma
->wq
, wait
);
783 poll_wait(file
, &output
->dma
->wq
, wait
);
784 if (ddb_input_avail(input
) >= 188)
785 mask
|= EPOLLIN
| EPOLLRDNORM
;
786 if (ddb_output_free(output
) >= 188)
787 mask
|= EPOLLOUT
| EPOLLWRNORM
;
791 static int ts_release(struct inode
*inode
, struct file
*file
)
793 struct dvb_device
*dvbdev
= file
->private_data
;
794 struct ddb_output
*output
= NULL
;
795 struct ddb_input
*input
= NULL
;
798 output
= dvbdev
->priv
;
799 input
= output
->port
->input
[0];
802 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) {
805 ddb_input_stop(input
);
806 } else if ((file
->f_flags
& O_ACCMODE
) == O_WRONLY
) {
809 ddb_output_stop(output
);
811 return dvb_generic_release(inode
, file
);
814 static int ts_open(struct inode
*inode
, struct file
*file
)
817 struct dvb_device
*dvbdev
= file
->private_data
;
818 struct ddb_output
*output
= NULL
;
819 struct ddb_input
*input
= NULL
;
822 output
= dvbdev
->priv
;
823 input
= output
->port
->input
[0];
826 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
) {
829 if (input
->redo
|| input
->redi
)
831 } else if ((file
->f_flags
& O_ACCMODE
) == O_WRONLY
) {
838 err
= dvb_generic_open(inode
, file
);
841 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
)
842 ddb_input_start(input
);
843 else if ((file
->f_flags
& O_ACCMODE
) == O_WRONLY
)
844 ddb_output_start(output
);
848 static const struct file_operations ci_fops
= {
849 .owner
= THIS_MODULE
,
853 .release
= ts_release
,
858 static struct dvb_device dvbdev_ci
= {
866 /****************************************************************************/
867 /****************************************************************************/
869 static int locked_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
871 struct ddb_input
*input
= fe
->sec_priv
;
872 struct ddb_port
*port
= input
->port
;
873 struct ddb_dvb
*dvb
= &port
->dvb
[input
->nr
& 1];
877 mutex_lock(&port
->i2c_gate_lock
);
878 status
= dvb
->i2c_gate_ctrl(fe
, 1);
880 status
= dvb
->i2c_gate_ctrl(fe
, 0);
881 mutex_unlock(&port
->i2c_gate_lock
);
886 static int demod_attach_drxk(struct ddb_input
*input
)
888 struct i2c_adapter
*i2c
= &input
->port
->i2c
->adap
;
889 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
890 struct device
*dev
= input
->port
->dev
->dev
;
891 struct drxk_config config
;
893 memset(&config
, 0, sizeof(config
));
894 config
.adr
= 0x29 + (input
->nr
& 1);
895 config
.microcode_name
= "drxk_a3.mc";
897 dvb
->fe
= dvb_attach(drxk_attach
, &config
, i2c
);
899 dev_err(dev
, "No DRXK found!\n");
902 dvb
->fe
->sec_priv
= input
;
903 dvb
->i2c_gate_ctrl
= dvb
->fe
->ops
.i2c_gate_ctrl
;
904 dvb
->fe
->ops
.i2c_gate_ctrl
= locked_gate_ctrl
;
908 static int tuner_attach_tda18271(struct ddb_input
*input
)
910 struct i2c_adapter
*i2c
= &input
->port
->i2c
->adap
;
911 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
912 struct device
*dev
= input
->port
->dev
->dev
;
913 struct dvb_frontend
*fe
;
915 if (dvb
->fe
->ops
.i2c_gate_ctrl
)
916 dvb
->fe
->ops
.i2c_gate_ctrl(dvb
->fe
, 1);
917 fe
= dvb_attach(tda18271c2dd_attach
, dvb
->fe
, i2c
, 0x60);
918 if (dvb
->fe
->ops
.i2c_gate_ctrl
)
919 dvb
->fe
->ops
.i2c_gate_ctrl(dvb
->fe
, 0);
921 dev_err(dev
, "No TDA18271 found!\n");
927 /******************************************************************************/
928 /******************************************************************************/
929 /******************************************************************************/
931 static struct stv0367_config ddb_stv0367_config
[] = {
933 .demod_address
= 0x1f,
936 .if_iq_mode
= FE_TER_NORMAL_IF_TUNER
,
937 .ts_mode
= STV0367_SERIAL_PUNCT_CLOCK
,
938 .clk_pol
= STV0367_CLOCKPOLARITY_DEFAULT
,
940 .demod_address
= 0x1e,
943 .if_iq_mode
= FE_TER_NORMAL_IF_TUNER
,
944 .ts_mode
= STV0367_SERIAL_PUNCT_CLOCK
,
945 .clk_pol
= STV0367_CLOCKPOLARITY_DEFAULT
,
949 static int demod_attach_stv0367(struct ddb_input
*input
)
951 struct i2c_adapter
*i2c
= &input
->port
->i2c
->adap
;
952 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
953 struct device
*dev
= input
->port
->dev
->dev
;
955 /* attach frontend */
956 dvb
->fe
= dvb_attach(stv0367ddb_attach
,
957 &ddb_stv0367_config
[(input
->nr
& 1)], i2c
);
960 dev_err(dev
, "No stv0367 found!\n");
963 dvb
->fe
->sec_priv
= input
;
964 dvb
->i2c_gate_ctrl
= dvb
->fe
->ops
.i2c_gate_ctrl
;
965 dvb
->fe
->ops
.i2c_gate_ctrl
= locked_gate_ctrl
;
969 static int tuner_tda18212_ping(struct ddb_input
*input
, unsigned short adr
)
971 struct i2c_adapter
*adapter
= &input
->port
->i2c
->adap
;
972 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
973 struct device
*dev
= input
->port
->dev
->dev
;
977 dev_dbg(dev
, "stv0367-tda18212 tuner ping\n");
978 if (dvb
->fe
->ops
.i2c_gate_ctrl
)
979 dvb
->fe
->ops
.i2c_gate_ctrl(dvb
->fe
, 1);
981 if (i2c_read_regs(adapter
, adr
, subaddr
, tda_id
, sizeof(tda_id
)) < 0)
982 dev_dbg(dev
, "tda18212 ping 1 fail\n");
983 if (i2c_read_regs(adapter
, adr
, subaddr
, tda_id
, sizeof(tda_id
)) < 0)
984 dev_warn(dev
, "tda18212 ping failed, expect problems\n");
986 if (dvb
->fe
->ops
.i2c_gate_ctrl
)
987 dvb
->fe
->ops
.i2c_gate_ctrl(dvb
->fe
, 0);
992 static int demod_attach_cxd28xx(struct ddb_input
*input
, int par
, int osc24
)
994 struct i2c_adapter
*i2c
= &input
->port
->i2c
->adap
;
995 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
996 struct device
*dev
= input
->port
->dev
->dev
;
997 struct cxd2841er_config cfg
;
999 /* the cxd2841er driver expects 8bit/shifted I2C addresses */
1000 cfg
.i2c_addr
= ((input
->nr
& 1) ? 0x6d : 0x6c) << 1;
1002 cfg
.xtal
= osc24
? SONY_XTAL_24000
: SONY_XTAL_20500
;
1003 cfg
.flags
= CXD2841ER_AUTO_IFHZ
| CXD2841ER_EARLY_TUNE
|
1004 CXD2841ER_NO_WAIT_LOCK
| CXD2841ER_NO_AGCNEG
|
1008 cfg
.flags
|= CXD2841ER_TS_SERIAL
;
1010 /* attach frontend */
1011 dvb
->fe
= dvb_attach(cxd2841er_attach_t_c
, &cfg
, i2c
);
1014 dev_err(dev
, "No cxd2837/38/43/54 found!\n");
1017 dvb
->fe
->sec_priv
= input
;
1018 dvb
->i2c_gate_ctrl
= dvb
->fe
->ops
.i2c_gate_ctrl
;
1019 dvb
->fe
->ops
.i2c_gate_ctrl
= locked_gate_ctrl
;
1023 static int tuner_attach_tda18212(struct ddb_input
*input
, u32 porttype
)
1025 struct i2c_adapter
*adapter
= &input
->port
->i2c
->adap
;
1026 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1027 struct device
*dev
= input
->port
->dev
->dev
;
1028 struct i2c_client
*client
;
1029 struct tda18212_config config
= {
1039 u8 addr
= (input
->nr
& 1) ? 0x63 : 0x60;
1041 /* due to a hardware quirk with the I2C gate on the stv0367+tda18212
1042 * combo, the tda18212 must be probed by reading it's id _twice_ when
1043 * cold started, or it very likely will fail.
1045 if (porttype
== DDB_TUNER_DVBCT_ST
)
1046 tuner_tda18212_ping(input
, addr
);
1048 /* perform tuner probe/init/attach */
1049 client
= dvb_module_probe("tda18212", NULL
, adapter
, addr
, &config
);
1053 dvb
->i2c_client
[0] = client
;
1056 dev_err(dev
, "TDA18212 tuner not found. Device is not fully operational.\n");
1060 /****************************************************************************/
1061 /****************************************************************************/
1062 /****************************************************************************/
1064 static struct stv090x_config stv0900
= {
1066 .demod_mode
= STV090x_DUAL
,
1067 .clk_mode
= STV090x_CLK_EXT
,
1072 .ts1_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
1073 .ts2_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
1078 .repeater_level
= STV090x_RPTLEVEL_16
,
1080 .adc1_range
= STV090x_ADC_1Vpp
,
1081 .adc2_range
= STV090x_ADC_1Vpp
,
1083 .diseqc_envelope_mode
= true,
1086 static struct stv090x_config stv0900_aa
= {
1088 .demod_mode
= STV090x_DUAL
,
1089 .clk_mode
= STV090x_CLK_EXT
,
1094 .ts1_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
1095 .ts2_mode
= STV090x_TSMODE_SERIAL_PUNCTURED
,
1100 .repeater_level
= STV090x_RPTLEVEL_16
,
1102 .adc1_range
= STV090x_ADC_1Vpp
,
1103 .adc2_range
= STV090x_ADC_1Vpp
,
1105 .diseqc_envelope_mode
= true,
1108 static struct stv6110x_config stv6110a
= {
1114 static struct stv6110x_config stv6110b
= {
1120 static int demod_attach_stv0900(struct ddb_input
*input
, int type
)
1122 struct i2c_adapter
*i2c
= &input
->port
->i2c
->adap
;
1123 struct stv090x_config
*feconf
= type
? &stv0900_aa
: &stv0900
;
1124 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1125 struct device
*dev
= input
->port
->dev
->dev
;
1127 dvb
->fe
= dvb_attach(stv090x_attach
, feconf
, i2c
,
1128 (input
->nr
& 1) ? STV090x_DEMODULATOR_1
1129 : STV090x_DEMODULATOR_0
);
1131 dev_err(dev
, "No STV0900 found!\n");
1134 if (!dvb_attach(lnbh24_attach
, dvb
->fe
, i2c
, 0,
1135 0, (input
->nr
& 1) ?
1136 (0x09 - type
) : (0x0b - type
))) {
1137 dev_err(dev
, "No LNBH24 found!\n");
1138 dvb_frontend_detach(dvb
->fe
);
1144 static int tuner_attach_stv6110(struct ddb_input
*input
, int type
)
1146 struct i2c_adapter
*i2c
= &input
->port
->i2c
->adap
;
1147 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1148 struct device
*dev
= input
->port
->dev
->dev
;
1149 struct stv090x_config
*feconf
= type
? &stv0900_aa
: &stv0900
;
1150 struct stv6110x_config
*tunerconf
= (input
->nr
& 1) ?
1151 &stv6110b
: &stv6110a
;
1152 const struct stv6110x_devctl
*ctl
;
1154 ctl
= dvb_attach(stv6110x_attach
, dvb
->fe
, tunerconf
, i2c
);
1156 dev_err(dev
, "No STV6110X found!\n");
1159 dev_info(dev
, "attach tuner input %d adr %02x\n",
1160 input
->nr
, tunerconf
->addr
);
1162 feconf
->tuner_init
= ctl
->tuner_init
;
1163 feconf
->tuner_sleep
= ctl
->tuner_sleep
;
1164 feconf
->tuner_set_mode
= ctl
->tuner_set_mode
;
1165 feconf
->tuner_set_frequency
= ctl
->tuner_set_frequency
;
1166 feconf
->tuner_get_frequency
= ctl
->tuner_get_frequency
;
1167 feconf
->tuner_set_bandwidth
= ctl
->tuner_set_bandwidth
;
1168 feconf
->tuner_get_bandwidth
= ctl
->tuner_get_bandwidth
;
1169 feconf
->tuner_set_bbgain
= ctl
->tuner_set_bbgain
;
1170 feconf
->tuner_get_bbgain
= ctl
->tuner_get_bbgain
;
1171 feconf
->tuner_set_refclk
= ctl
->tuner_set_refclk
;
1172 feconf
->tuner_get_status
= ctl
->tuner_get_status
;
1177 static const struct stv0910_cfg stv0910_p
= {
1185 static const struct lnbh25_config lnbh25_cfg
= {
1186 .i2c_address
= 0x0c << 1,
1187 .data2_config
= LNBH25_TEN
1190 static int has_lnbh25(struct i2c_adapter
*i2c
, u8 adr
)
1194 return i2c_read_reg(i2c
, adr
, 0, &val
) ? 0 : 1;
1197 static int demod_attach_stv0910(struct ddb_input
*input
, int type
, int tsfast
)
1199 struct i2c_adapter
*i2c
= &input
->port
->i2c
->adap
;
1200 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1201 struct device
*dev
= input
->port
->dev
->dev
;
1202 struct stv0910_cfg cfg
= stv0910_p
;
1203 struct lnbh25_config lnbcfg
= lnbh25_cfg
;
1212 dev_info(dev
, "Enabling stv0910 higher speed TS\n");
1216 dvb
->fe
= dvb_attach(stv0910_attach
, i2c
, &cfg
, (input
->nr
& 1));
1219 dvb
->fe
= dvb_attach(stv0910_attach
, i2c
,
1220 &cfg
, (input
->nr
& 1));
1223 dev_err(dev
, "No STV0910 found!\n");
1227 /* attach lnbh25 - leftshift by one as the lnbh25 driver expects 8bit
1230 if (has_lnbh25(i2c
, 0x0d))
1231 lnbcfg
.i2c_address
= (((input
->nr
& 1) ? 0x0d : 0x0c) << 1);
1233 lnbcfg
.i2c_address
= (((input
->nr
& 1) ? 0x09 : 0x08) << 1);
1235 if (!dvb_attach(lnbh25_attach
, dvb
->fe
, &lnbcfg
, i2c
)) {
1236 dev_err(dev
, "No LNBH25 found!\n");
1237 dvb_frontend_detach(dvb
->fe
);
1244 static int tuner_attach_stv6111(struct ddb_input
*input
, int type
)
1246 struct i2c_adapter
*i2c
= &input
->port
->i2c
->adap
;
1247 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1248 struct device
*dev
= input
->port
->dev
->dev
;
1249 struct dvb_frontend
*fe
;
1250 u8 adr
= (type
? 0 : 4) + ((input
->nr
& 1) ? 0x63 : 0x60);
1252 fe
= dvb_attach(stv6111_attach
, dvb
->fe
, i2c
, adr
);
1254 fe
= dvb_attach(stv6111_attach
, dvb
->fe
, i2c
, adr
& ~4);
1256 dev_err(dev
, "No STV6111 found at 0x%02x!\n", adr
);
1263 static int demod_attach_dummy(struct ddb_input
*input
)
1265 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1266 struct device
*dev
= input
->port
->dev
->dev
;
1268 dvb
->fe
= dvb_attach(ddbridge_dummy_fe_qam_attach
);
1270 dev_err(dev
, "QAM dummy attach failed!\n");
1277 static int start_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1279 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
1280 struct ddb_input
*input
= dvbdmx
->priv
;
1281 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1284 ddb_input_start_all(input
);
1286 return ++dvb
->users
;
1289 static int stop_feed(struct dvb_demux_feed
*dvbdmxfeed
)
1291 struct dvb_demux
*dvbdmx
= dvbdmxfeed
->demux
;
1292 struct ddb_input
*input
= dvbdmx
->priv
;
1293 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1298 ddb_input_stop_all(input
);
1302 static void dvb_input_detach(struct ddb_input
*input
)
1304 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1305 struct dvb_demux
*dvbdemux
= &dvb
->demux
;
1307 switch (dvb
->attached
) {
1310 dvb_unregister_frontend(dvb
->fe2
);
1312 dvb_unregister_frontend(dvb
->fe
);
1315 dvb_module_release(dvb
->i2c_client
[0]);
1316 dvb
->i2c_client
[0] = NULL
;
1319 dvb_frontend_detach(dvb
->fe2
);
1321 dvb_frontend_detach(dvb
->fe
);
1326 dvb_net_release(&dvb
->dvbnet
);
1329 dvbdemux
->dmx
.remove_frontend(&dvbdemux
->dmx
,
1331 dvbdemux
->dmx
.remove_frontend(&dvbdemux
->dmx
,
1332 &dvb
->mem_frontend
);
1335 dvb_dmxdev_release(&dvb
->dmxdev
);
1338 dvb_dmx_release(&dvb
->demux
);
1343 dvb
->attached
= 0x00;
1346 static int dvb_register_adapters(struct ddb
*dev
)
1349 struct ddb_port
*port
;
1350 struct dvb_adapter
*adap
;
1352 if (adapter_alloc
== 3) {
1353 port
= &dev
->port
[0];
1354 adap
= port
->dvb
[0].adap
;
1355 ret
= dvb_register_adapter(adap
, "DDBridge", THIS_MODULE
,
1360 port
->dvb
[0].adap_registered
= 1;
1361 for (i
= 0; i
< dev
->port_num
; i
++) {
1362 port
= &dev
->port
[i
];
1363 port
->dvb
[0].adap
= adap
;
1364 port
->dvb
[1].adap
= adap
;
1369 for (i
= 0; i
< dev
->port_num
; i
++) {
1370 port
= &dev
->port
[i
];
1371 switch (port
->class) {
1372 case DDB_PORT_TUNER
:
1373 adap
= port
->dvb
[0].adap
;
1374 ret
= dvb_register_adapter(adap
, "DDBridge",
1380 port
->dvb
[0].adap_registered
= 1;
1382 if (adapter_alloc
> 0) {
1383 port
->dvb
[1].adap
= port
->dvb
[0].adap
;
1386 adap
= port
->dvb
[1].adap
;
1387 ret
= dvb_register_adapter(adap
, "DDBridge",
1393 port
->dvb
[1].adap_registered
= 1;
1398 adap
= port
->dvb
[0].adap
;
1399 ret
= dvb_register_adapter(adap
, "DDBridge",
1405 port
->dvb
[0].adap_registered
= 1;
1408 if (adapter_alloc
< 2)
1410 adap
= port
->dvb
[0].adap
;
1411 ret
= dvb_register_adapter(adap
, "DDBridge",
1417 port
->dvb
[0].adap_registered
= 1;
1424 static void dvb_unregister_adapters(struct ddb
*dev
)
1427 struct ddb_port
*port
;
1428 struct ddb_dvb
*dvb
;
1430 for (i
= 0; i
< dev
->link
[0].info
->port_num
; i
++) {
1431 port
= &dev
->port
[i
];
1433 dvb
= &port
->dvb
[0];
1434 if (dvb
->adap_registered
)
1435 dvb_unregister_adapter(dvb
->adap
);
1436 dvb
->adap_registered
= 0;
1438 dvb
= &port
->dvb
[1];
1439 if (dvb
->adap_registered
)
1440 dvb_unregister_adapter(dvb
->adap
);
1441 dvb
->adap_registered
= 0;
1445 static int dvb_input_attach(struct ddb_input
*input
)
1448 struct ddb_dvb
*dvb
= &input
->port
->dvb
[input
->nr
& 1];
1449 struct ddb_port
*port
= input
->port
;
1450 struct dvb_adapter
*adap
= dvb
->adap
;
1451 struct dvb_demux
*dvbdemux
= &dvb
->demux
;
1452 struct ddb_ids
*devids
= &input
->port
->dev
->link
[input
->port
->lnr
].ids
;
1453 int par
= 0, osc24
= 0, tsfast
= 0;
1456 * Determine if bridges with stv0910 demods can run with fast TS and
1457 * thus support high bandwidth transponders.
1458 * STV0910_PR and STV0910_P tuner types covers all relevant bridges,
1459 * namely the CineS2 V7(A) and the Octopus CI S2 Pro/Advanced. All
1460 * DuoFlex S2 V4(A) have type=DDB_TUNER_DVBS_STV0910 without any suffix
1461 * and are limited by the serial link to the bridge, thus won't work
1464 if (port
->nr
== 0 &&
1465 (port
->type
== DDB_TUNER_DVBS_STV0910_PR
||
1466 port
->type
== DDB_TUNER_DVBS_STV0910_P
)) {
1467 /* fast TS on port 0 requires FPGA version >= 1.7 */
1468 if ((devids
->hwid
& 0x00ffffff) >= 0x00010007)
1472 dvb
->attached
= 0x01;
1474 dvbdemux
->priv
= input
;
1475 dvbdemux
->dmx
.capabilities
= DMX_TS_FILTERING
|
1476 DMX_SECTION_FILTERING
| DMX_MEMORY_BASED_FILTERING
;
1477 dvbdemux
->start_feed
= start_feed
;
1478 dvbdemux
->stop_feed
= stop_feed
;
1479 dvbdemux
->filternum
= 256;
1480 dvbdemux
->feednum
= 256;
1481 ret
= dvb_dmx_init(dvbdemux
);
1484 dvb
->attached
= 0x10;
1486 dvb
->dmxdev
.filternum
= 256;
1487 dvb
->dmxdev
.demux
= &dvbdemux
->dmx
;
1488 ret
= dvb_dmxdev_init(&dvb
->dmxdev
, adap
);
1491 dvb
->attached
= 0x11;
1493 dvb
->mem_frontend
.source
= DMX_MEMORY_FE
;
1494 dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->mem_frontend
);
1495 dvb
->hw_frontend
.source
= DMX_FRONTEND_0
;
1496 dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->hw_frontend
);
1497 ret
= dvbdemux
->dmx
.connect_frontend(&dvbdemux
->dmx
, &dvb
->hw_frontend
);
1500 dvb
->attached
= 0x12;
1502 ret
= dvb_net_init(adap
, &dvb
->dvbnet
, dvb
->dmxdev
.demux
);
1505 dvb
->attached
= 0x20;
1509 switch (port
->type
) {
1510 case DDB_TUNER_MXL5XX
:
1511 if (ddb_fe_attach_mxl5xx(input
) < 0)
1514 case DDB_TUNER_DVBS_ST
:
1515 if (demod_attach_stv0900(input
, 0) < 0)
1517 if (tuner_attach_stv6110(input
, 0) < 0)
1520 case DDB_TUNER_DVBS_ST_AA
:
1521 if (demod_attach_stv0900(input
, 1) < 0)
1523 if (tuner_attach_stv6110(input
, 1) < 0)
1526 case DDB_TUNER_DVBS_STV0910
:
1527 if (demod_attach_stv0910(input
, 0, tsfast
) < 0)
1529 if (tuner_attach_stv6111(input
, 0) < 0)
1532 case DDB_TUNER_DVBS_STV0910_PR
:
1533 if (demod_attach_stv0910(input
, 1, tsfast
) < 0)
1535 if (tuner_attach_stv6111(input
, 1) < 0)
1538 case DDB_TUNER_DVBS_STV0910_P
:
1539 if (demod_attach_stv0910(input
, 0, tsfast
) < 0)
1541 if (tuner_attach_stv6111(input
, 1) < 0)
1544 case DDB_TUNER_DVBCT_TR
:
1545 if (demod_attach_drxk(input
) < 0)
1547 if (tuner_attach_tda18271(input
) < 0)
1550 case DDB_TUNER_DVBCT_ST
:
1551 if (demod_attach_stv0367(input
) < 0)
1553 if (tuner_attach_tda18212(input
, port
->type
) < 0)
1556 case DDB_TUNER_DVBC2T2I_SONY_P
:
1557 if (input
->port
->dev
->link
[input
->port
->lnr
].info
->ts_quirks
&
1563 case DDB_TUNER_DVBCT2_SONY_P
:
1564 case DDB_TUNER_DVBC2T2_SONY_P
:
1565 case DDB_TUNER_ISDBT_SONY_P
:
1566 if (input
->port
->dev
->link
[input
->port
->lnr
].info
->ts_quirks
1571 if (demod_attach_cxd28xx(input
, par
, osc24
) < 0)
1573 if (tuner_attach_tda18212(input
, port
->type
) < 0)
1576 case DDB_TUNER_DVBC2T2I_SONY
:
1579 case DDB_TUNER_DVBCT2_SONY
:
1580 case DDB_TUNER_DVBC2T2_SONY
:
1581 case DDB_TUNER_ISDBT_SONY
:
1582 if (demod_attach_cxd28xx(input
, 0, osc24
) < 0)
1584 if (tuner_attach_tda18212(input
, port
->type
) < 0)
1587 case DDB_TUNER_DUMMY
:
1588 if (demod_attach_dummy(input
) < 0)
1591 case DDB_TUNER_MCI_SX8
:
1592 if (ddb_fe_attach_mci(input
, port
->type
) < 0)
1598 dvb
->attached
= 0x30;
1601 if (dvb_register_frontend(adap
, dvb
->fe
) < 0)
1605 if (dvb_register_frontend(adap
, dvb
->fe2
) < 0) {
1606 dvb_unregister_frontend(dvb
->fe
);
1609 dvb
->fe2
->tuner_priv
= dvb
->fe
->tuner_priv
;
1610 memcpy(&dvb
->fe2
->ops
.tuner_ops
,
1611 &dvb
->fe
->ops
.tuner_ops
,
1612 sizeof(struct dvb_tuner_ops
));
1616 dvb
->attached
= 0x31;
1620 dev_err(port
->dev
->dev
, "tuner attach failed!\n");
1623 dvb_frontend_detach(dvb
->fe2
);
1625 dvb_frontend_detach(dvb
->fe
);
1627 dvb_input_detach(input
);
1629 /* return error from ret if set */
1636 static int port_has_encti(struct ddb_port
*port
)
1638 struct device
*dev
= port
->dev
->dev
;
1640 int ret
= i2c_read_reg(&port
->i2c
->adap
, 0x20, 0, &val
);
1643 dev_info(dev
, "[0x20]=0x%02x\n", val
);
1647 static int port_has_cxd(struct ddb_port
*port
, u8
*type
)
1650 u8 probe
[4] = { 0xe0, 0x00, 0x00, 0x00 }, data
[4];
1651 struct i2c_msg msgs
[2] = {{ .addr
= 0x40, .flags
= 0,
1652 .buf
= probe
, .len
= 4 },
1653 { .addr
= 0x40, .flags
= I2C_M_RD
,
1654 .buf
= data
, .len
= 4 } };
1655 val
= i2c_transfer(&port
->i2c
->adap
, msgs
, 2);
1659 if (data
[0] == 0x02 && data
[1] == 0x2b && data
[3] == 0x43)
1666 static int port_has_xo2(struct ddb_port
*port
, u8
*type
, u8
*id
)
1668 u8 probe
[1] = { 0x00 }, data
[4];
1670 if (i2c_io(&port
->i2c
->adap
, 0x10, probe
, 1, data
, 4))
1672 if (data
[0] == 'D' && data
[1] == 'F') {
1677 if (data
[0] == 'C' && data
[1] == 'I') {
1685 static int port_has_stv0900(struct ddb_port
*port
)
1689 if (i2c_read_reg16(&port
->i2c
->adap
, 0x69, 0xf100, &val
) < 0)
1694 static int port_has_stv0900_aa(struct ddb_port
*port
, u8
*id
)
1696 if (i2c_read_reg16(&port
->i2c
->adap
, 0x68, 0xf100, id
) < 0)
1701 static int port_has_drxks(struct ddb_port
*port
)
1705 if (i2c_read(&port
->i2c
->adap
, 0x29, &val
) < 0)
1707 if (i2c_read(&port
->i2c
->adap
, 0x2a, &val
) < 0)
1712 static int port_has_stv0367(struct ddb_port
*port
)
1716 if (i2c_read_reg16(&port
->i2c
->adap
, 0x1e, 0xf000, &val
) < 0)
1720 if (i2c_read_reg16(&port
->i2c
->adap
, 0x1f, 0xf000, &val
) < 0)
1727 static int init_xo2(struct ddb_port
*port
)
1729 struct i2c_adapter
*i2c
= &port
->i2c
->adap
;
1730 struct ddb
*dev
= port
->dev
;
1734 res
= i2c_read_regs(i2c
, 0x10, 0x04, data
, 2);
1738 if (data
[0] != 0x01) {
1739 dev_info(dev
->dev
, "Port %d: invalid XO2\n", port
->nr
);
1743 i2c_read_reg(i2c
, 0x10, 0x08, &val
);
1745 i2c_write_reg(i2c
, 0x10, 0x08, 0x00);
1748 /* Enable tuner power, disable pll, reset demods */
1749 i2c_write_reg(i2c
, 0x10, 0x08, 0x04);
1750 usleep_range(2000, 3000);
1751 /* Release demod resets */
1752 i2c_write_reg(i2c
, 0x10, 0x08, 0x07);
1754 /* speed: 0=55,1=75,2=90,3=104 MBit/s */
1755 i2c_write_reg(i2c
, 0x10, 0x09, xo2_speed
);
1757 if (dev
->link
[port
->lnr
].info
->con_clock
) {
1758 dev_info(dev
->dev
, "Setting continuous clock for XO2\n");
1759 i2c_write_reg(i2c
, 0x10, 0x0a, 0x03);
1760 i2c_write_reg(i2c
, 0x10, 0x0b, 0x03);
1762 i2c_write_reg(i2c
, 0x10, 0x0a, 0x01);
1763 i2c_write_reg(i2c
, 0x10, 0x0b, 0x01);
1766 usleep_range(2000, 3000);
1768 i2c_write_reg(i2c
, 0x10, 0x08, 0x87);
1773 static int init_xo2_ci(struct ddb_port
*port
)
1775 struct i2c_adapter
*i2c
= &port
->i2c
->adap
;
1776 struct ddb
*dev
= port
->dev
;
1780 res
= i2c_read_regs(i2c
, 0x10, 0x04, data
, 2);
1785 dev_info(dev
->dev
, "Port %d: invalid XO2 CI %02x\n",
1789 dev_info(dev
->dev
, "Port %d: DuoFlex CI %u.%u\n",
1790 port
->nr
, data
[0], data
[1]);
1792 i2c_read_reg(i2c
, 0x10, 0x08, &val
);
1794 i2c_write_reg(i2c
, 0x10, 0x08, 0x00);
1797 /* Enable both CI */
1798 i2c_write_reg(i2c
, 0x10, 0x08, 3);
1799 usleep_range(2000, 3000);
1801 /* speed: 0=55,1=75,2=90,3=104 MBit/s */
1802 i2c_write_reg(i2c
, 0x10, 0x09, 1);
1804 i2c_write_reg(i2c
, 0x10, 0x08, 0x83);
1805 usleep_range(2000, 3000);
1807 if (dev
->link
[port
->lnr
].info
->con_clock
) {
1808 dev_info(dev
->dev
, "Setting continuous clock for DuoFlex CI\n");
1809 i2c_write_reg(i2c
, 0x10, 0x0a, 0x03);
1810 i2c_write_reg(i2c
, 0x10, 0x0b, 0x03);
1812 i2c_write_reg(i2c
, 0x10, 0x0a, 0x01);
1813 i2c_write_reg(i2c
, 0x10, 0x0b, 0x01);
1818 static int port_has_cxd28xx(struct ddb_port
*port
, u8
*id
)
1820 struct i2c_adapter
*i2c
= &port
->i2c
->adap
;
1823 status
= i2c_write_reg(&port
->i2c
->adap
, 0x6e, 0, 0);
1826 status
= i2c_read_reg(i2c
, 0x6e, 0xfd, id
);
1832 static char *xo2names
[] = {
1833 "DUAL DVB-S2", "DUAL DVB-C/T/T2",
1834 "DUAL DVB-ISDBT", "DUAL DVB-C/C2/T/T2",
1835 "DUAL ATSC", "DUAL DVB-C/C2/T/T2,ISDB-T",
1839 static char *xo2types
[] = {
1840 "DVBS_ST", "DVBCT2_SONY",
1841 "ISDBT_SONY", "DVBC2T2_SONY",
1842 "ATSC_ST", "DVBC2T2I_SONY"
1845 static void ddb_port_probe(struct ddb_port
*port
)
1847 struct ddb
*dev
= port
->dev
;
1849 struct ddb_link
*link
= &dev
->link
[l
];
1852 port
->name
= "NO MODULE";
1853 port
->type_name
= "NONE";
1854 port
->class = DDB_PORT_NONE
;
1856 /* Handle missing ports and ports without I2C */
1858 if (dummy_tuner
&& !port
->nr
&&
1859 link
->ids
.device
== 0x0005) {
1860 port
->name
= "DUMMY";
1861 port
->class = DDB_PORT_TUNER
;
1862 port
->type
= DDB_TUNER_DUMMY
;
1863 port
->type_name
= "DUMMY";
1867 if (port
->nr
== ts_loop
) {
1868 port
->name
= "TS LOOP";
1869 port
->class = DDB_PORT_LOOP
;
1873 if (port
->nr
== 1 && link
->info
->type
== DDB_OCTOPUS_CI
&&
1874 link
->info
->i2c_mask
== 1) {
1875 port
->name
= "NO TAB";
1876 port
->class = DDB_PORT_NONE
;
1880 if (link
->info
->type
== DDB_OCTOPUS_MAX
) {
1881 port
->name
= "DUAL DVB-S2 MAX";
1882 port
->type_name
= "MXL5XX";
1883 port
->class = DDB_PORT_TUNER
;
1884 port
->type
= DDB_TUNER_MXL5XX
;
1886 ddbwritel(dev
, I2C_SPEED_400
,
1887 port
->i2c
->regs
+ I2C_TIMING
);
1891 if (link
->info
->type
== DDB_OCTOPUS_MCI
) {
1892 if (port
->nr
>= link
->info
->mci_ports
)
1894 port
->name
= "DUAL MCI";
1895 port
->type_name
= "MCI";
1896 port
->class = DDB_PORT_TUNER
;
1897 port
->type
= DDB_TUNER_MCI
+ link
->info
->mci_type
;
1901 if (port
->nr
> 1 && link
->info
->type
== DDB_OCTOPUS_CI
) {
1902 port
->name
= "CI internal";
1903 port
->type_name
= "INTERNAL";
1904 port
->class = DDB_PORT_CI
;
1905 port
->type
= DDB_CI_INTERNAL
;
1911 /* Probe ports with I2C */
1913 if (port_has_cxd(port
, &id
)) {
1916 port
->type_name
= "CXD2099";
1917 port
->class = DDB_PORT_CI
;
1918 port
->type
= DDB_CI_EXTERNAL_SONY
;
1919 ddbwritel(dev
, I2C_SPEED_400
,
1920 port
->i2c
->regs
+ I2C_TIMING
);
1922 dev_info(dev
->dev
, "Port %d: Uninitialized DuoFlex\n",
1926 } else if (port_has_xo2(port
, &type
, &id
)) {
1927 ddbwritel(dev
, I2C_SPEED_400
, port
->i2c
->regs
+ I2C_TIMING
);
1928 /*dev_info(dev->dev, "XO2 ID %02x\n", id);*/
1930 port
->name
= "DuoFlex CI";
1931 port
->class = DDB_PORT_CI
;
1932 port
->type
= DDB_CI_EXTERNAL_XO2
;
1933 port
->type_name
= "CI_XO2";
1939 port
->name
= "unknown XO2 DuoFlex";
1940 port
->type_name
= "UNKNOWN";
1942 port
->name
= xo2names
[id
];
1943 port
->class = DDB_PORT_TUNER
;
1944 port
->type
= DDB_TUNER_XO2
+ id
;
1945 port
->type_name
= xo2types
[id
];
1948 } else if (port_has_cxd28xx(port
, &id
)) {
1951 port
->name
= "DUAL DVB-C2T2 CXD2843";
1952 port
->type
= DDB_TUNER_DVBC2T2_SONY_P
;
1953 port
->type_name
= "DVBC2T2_SONY";
1956 port
->name
= "DUAL DVB-CT2 CXD2837";
1957 port
->type
= DDB_TUNER_DVBCT2_SONY_P
;
1958 port
->type_name
= "DVBCT2_SONY";
1961 port
->name
= "DUAL ISDB-T CXD2838";
1962 port
->type
= DDB_TUNER_ISDBT_SONY_P
;
1963 port
->type_name
= "ISDBT_SONY";
1966 port
->name
= "DUAL DVB-C2T2 ISDB-T CXD2854";
1967 port
->type
= DDB_TUNER_DVBC2T2I_SONY_P
;
1968 port
->type_name
= "DVBC2T2I_ISDBT_SONY";
1973 port
->class = DDB_PORT_TUNER
;
1974 ddbwritel(dev
, I2C_SPEED_400
, port
->i2c
->regs
+ I2C_TIMING
);
1975 } else if (port_has_stv0900(port
)) {
1976 port
->name
= "DUAL DVB-S2";
1977 port
->class = DDB_PORT_TUNER
;
1978 port
->type
= DDB_TUNER_DVBS_ST
;
1979 port
->type_name
= "DVBS_ST";
1980 ddbwritel(dev
, I2C_SPEED_100
, port
->i2c
->regs
+ I2C_TIMING
);
1981 } else if (port_has_stv0900_aa(port
, &id
)) {
1982 port
->name
= "DUAL DVB-S2";
1983 port
->class = DDB_PORT_TUNER
;
1985 if (port
->nr
== 0 &&
1986 link
->info
->ts_quirks
& TS_QUIRK_REVERSED
)
1987 port
->type
= DDB_TUNER_DVBS_STV0910_PR
;
1989 port
->type
= DDB_TUNER_DVBS_STV0910_P
;
1990 port
->type_name
= "DVBS_ST_0910";
1992 port
->type
= DDB_TUNER_DVBS_ST_AA
;
1993 port
->type_name
= "DVBS_ST_AA";
1995 ddbwritel(dev
, I2C_SPEED_100
, port
->i2c
->regs
+ I2C_TIMING
);
1996 } else if (port_has_drxks(port
)) {
1997 port
->name
= "DUAL DVB-C/T";
1998 port
->class = DDB_PORT_TUNER
;
1999 port
->type
= DDB_TUNER_DVBCT_TR
;
2000 port
->type_name
= "DVBCT_TR";
2001 ddbwritel(dev
, I2C_SPEED_400
, port
->i2c
->regs
+ I2C_TIMING
);
2002 } else if (port_has_stv0367(port
)) {
2003 port
->name
= "DUAL DVB-C/T";
2004 port
->class = DDB_PORT_TUNER
;
2005 port
->type
= DDB_TUNER_DVBCT_ST
;
2006 port
->type_name
= "DVBCT_ST";
2007 ddbwritel(dev
, I2C_SPEED_100
, port
->i2c
->regs
+ I2C_TIMING
);
2008 } else if (port_has_encti(port
)) {
2009 port
->name
= "ENCTI";
2010 port
->class = DDB_PORT_LOOP
;
2014 /****************************************************************************/
2015 /****************************************************************************/
2016 /****************************************************************************/
2018 static int ddb_port_attach(struct ddb_port
*port
)
2022 switch (port
->class) {
2023 case DDB_PORT_TUNER
:
2024 ret
= dvb_input_attach(port
->input
[0]);
2027 ret
= dvb_input_attach(port
->input
[1]);
2029 dvb_input_detach(port
->input
[0]);
2032 port
->input
[0]->redi
= port
->input
[0];
2033 port
->input
[1]->redi
= port
->input
[1];
2036 ret
= ddb_ci_attach(port
, ci_bitrate
);
2041 ret
= dvb_register_device(port
->dvb
[0].adap
,
2043 &dvbdev_ci
, (void *)port
->output
,
2050 dev_err(port
->dev
->dev
, "port_attach on port %d failed\n",
2055 int ddb_ports_attach(struct ddb
*dev
)
2057 int i
, numports
, err_ports
= 0, ret
= 0;
2058 struct ddb_port
*port
;
2060 if (dev
->port_num
) {
2061 ret
= dvb_register_adapters(dev
);
2063 dev_err(dev
->dev
, "Registering adapters failed. Check DVB_MAX_ADAPTERS in config.\n");
2068 numports
= dev
->port_num
;
2070 for (i
= 0; i
< dev
->port_num
; i
++) {
2071 port
= &dev
->port
[i
];
2072 if (port
->class != DDB_PORT_NONE
) {
2073 ret
= ddb_port_attach(port
);
2082 if (err_ports
== numports
) {
2083 dev_err(dev
->dev
, "All connected ports failed to initialise!\n");
2087 dev_warn(dev
->dev
, "%d of %d connected ports failed to initialise!\n",
2088 err_ports
, numports
);
2094 void ddb_ports_detach(struct ddb
*dev
)
2097 struct ddb_port
*port
;
2099 for (i
= 0; i
< dev
->port_num
; i
++) {
2100 port
= &dev
->port
[i
];
2102 switch (port
->class) {
2103 case DDB_PORT_TUNER
:
2104 dvb_input_detach(port
->input
[1]);
2105 dvb_input_detach(port
->input
[0]);
2109 ddb_ci_detach(port
);
2113 dvb_unregister_adapters(dev
);
2116 /* Copy input DMA pointers to output DMA and ACK. */
2118 static void input_write_output(struct ddb_input
*input
,
2119 struct ddb_output
*output
)
2121 ddbwritel(output
->port
->dev
,
2122 input
->dma
->stat
, DMA_BUFFER_ACK(output
->dma
));
2123 output
->dma
->cbuf
= (input
->dma
->stat
>> 11) & 0x1f;
2124 output
->dma
->coff
= (input
->dma
->stat
& 0x7ff) << 7;
2127 static void output_ack_input(struct ddb_output
*output
,
2128 struct ddb_input
*input
)
2130 ddbwritel(input
->port
->dev
,
2131 output
->dma
->stat
, DMA_BUFFER_ACK(input
->dma
));
2134 static void input_write_dvb(struct ddb_input
*input
,
2135 struct ddb_input
*input2
)
2137 struct ddb_dvb
*dvb
= &input2
->port
->dvb
[input2
->nr
& 1];
2138 struct ddb_dma
*dma
, *dma2
;
2139 struct ddb
*dev
= input
->port
->dev
;
2145 * if there also is an output connected, do not ACK.
2146 * input_write_output will ACK.
2149 dma2
= input
->redo
->dma
;
2152 while (dma
->cbuf
!= ((dma
->stat
>> 11) & 0x1f) ||
2154 if (4 & dma
->ctrl
) {
2155 /* dev_err(dev->dev, "Overflow dma %d\n", dma->nr); */
2159 dma_sync_single_for_cpu(dev
->dev
, dma2
->pbuf
[dma
->cbuf
],
2160 dma2
->size
, DMA_FROM_DEVICE
);
2161 dvb_dmx_swfilter_packets(&dvb
->demux
,
2162 dma2
->vbuf
[dma
->cbuf
],
2164 dma
->cbuf
= (dma
->cbuf
+ 1) % dma2
->num
;
2166 ddbwritel(dev
, (dma
->cbuf
<< 11),
2167 DMA_BUFFER_ACK(dma
));
2168 dma
->stat
= safe_ddbreadl(dev
, DMA_BUFFER_CURRENT(dma
));
2169 dma
->ctrl
= safe_ddbreadl(dev
, DMA_BUFFER_CONTROL(dma
));
2173 static void input_work(struct work_struct
*work
)
2175 struct ddb_dma
*dma
= container_of(work
, struct ddb_dma
, work
);
2176 struct ddb_input
*input
= (struct ddb_input
*)dma
->io
;
2177 struct ddb
*dev
= input
->port
->dev
;
2178 unsigned long flags
;
2180 spin_lock_irqsave(&dma
->lock
, flags
);
2181 if (!dma
->running
) {
2182 spin_unlock_irqrestore(&dma
->lock
, flags
);
2185 dma
->stat
= ddbreadl(dev
, DMA_BUFFER_CURRENT(dma
));
2186 dma
->ctrl
= ddbreadl(dev
, DMA_BUFFER_CONTROL(dma
));
2189 input_write_dvb(input
, input
->redi
);
2191 input_write_output(input
, input
->redo
);
2193 spin_unlock_irqrestore(&dma
->lock
, flags
);
2196 static void input_handler(void *data
)
2198 struct ddb_input
*input
= (struct ddb_input
*)data
;
2199 struct ddb_dma
*dma
= input
->dma
;
2201 queue_work(ddb_wq
, &dma
->work
);
2204 static void output_work(struct work_struct
*work
)
2206 struct ddb_dma
*dma
= container_of(work
, struct ddb_dma
, work
);
2207 struct ddb_output
*output
= (struct ddb_output
*)dma
->io
;
2208 struct ddb
*dev
= output
->port
->dev
;
2209 unsigned long flags
;
2211 spin_lock_irqsave(&dma
->lock
, flags
);
2214 dma
->stat
= ddbreadl(dev
, DMA_BUFFER_CURRENT(dma
));
2215 dma
->ctrl
= ddbreadl(dev
, DMA_BUFFER_CONTROL(dma
));
2217 output_ack_input(output
, output
->redi
);
2220 spin_unlock_irqrestore(&dma
->lock
, flags
);
2223 static void output_handler(void *data
)
2225 struct ddb_output
*output
= (struct ddb_output
*)data
;
2226 struct ddb_dma
*dma
= output
->dma
;
2228 queue_work(ddb_wq
, &dma
->work
);
2231 /****************************************************************************/
2232 /****************************************************************************/
2234 static const struct ddb_regmap
*io_regmap(struct ddb_io
*io
, int link
)
2236 const struct ddb_info
*info
;
2239 info
= io
->port
->dev
->link
[io
->port
->lnr
].info
;
2241 info
= io
->port
->dev
->link
[0].info
;
2246 return info
->regmap
;
2249 static void ddb_dma_init(struct ddb_io
*io
, int nr
, int out
)
2251 struct ddb_dma
*dma
;
2252 const struct ddb_regmap
*rm
= io_regmap(io
, 0);
2254 dma
= out
? &io
->port
->dev
->odma
[nr
] : &io
->port
->dev
->idma
[nr
];
2258 spin_lock_init(&dma
->lock
);
2259 init_waitqueue_head(&dma
->wq
);
2261 INIT_WORK(&dma
->work
, output_work
);
2262 dma
->regs
= rm
->odma
->base
+ rm
->odma
->size
* nr
;
2263 dma
->bufregs
= rm
->odma_buf
->base
+ rm
->odma_buf
->size
* nr
;
2264 dma
->num
= dma_buf_num
;
2265 dma
->size
= dma_buf_size
* 128 * 47;
2268 INIT_WORK(&dma
->work
, input_work
);
2269 dma
->regs
= rm
->idma
->base
+ rm
->idma
->size
* nr
;
2270 dma
->bufregs
= rm
->idma_buf
->base
+ rm
->idma_buf
->size
* nr
;
2271 dma
->num
= dma_buf_num
;
2272 dma
->size
= dma_buf_size
* 128 * 47;
2275 ddbwritel(io
->port
->dev
, 0, DMA_BUFFER_ACK(dma
));
2276 dev_dbg(io
->port
->dev
->dev
, "init link %u, io %u, dma %u, dmaregs %08x bufregs %08x\n",
2277 io
->port
->lnr
, io
->nr
, nr
, dma
->regs
, dma
->bufregs
);
2280 static void ddb_input_init(struct ddb_port
*port
, int nr
, int pnr
, int anr
)
2282 struct ddb
*dev
= port
->dev
;
2283 struct ddb_input
*input
= &dev
->input
[anr
];
2284 const struct ddb_regmap
*rm
;
2286 port
->input
[pnr
] = input
;
2289 rm
= io_regmap(input
, 1);
2290 input
->regs
= DDB_LINK_TAG(port
->lnr
) |
2291 (rm
->input
->base
+ rm
->input
->size
* nr
);
2292 dev_dbg(dev
->dev
, "init link %u, input %u, regs %08x\n",
2293 port
->lnr
, nr
, input
->regs
);
2296 const struct ddb_regmap
*rm0
= io_regmap(input
, 0);
2297 u32 base
= rm0
->irq_base_idma
;
2301 dma_nr
+= 32 + (port
->lnr
- 1) * 8;
2303 dev_dbg(dev
->dev
, "init link %u, input %u, handler %u\n",
2304 port
->lnr
, nr
, dma_nr
+ base
);
2306 ddb_irq_set(dev
, 0, dma_nr
+ base
, &input_handler
, input
);
2307 ddb_dma_init(input
, dma_nr
, 0);
2311 static void ddb_output_init(struct ddb_port
*port
, int nr
)
2313 struct ddb
*dev
= port
->dev
;
2314 struct ddb_output
*output
= &dev
->output
[nr
];
2315 const struct ddb_regmap
*rm
;
2317 port
->output
= output
;
2319 output
->port
= port
;
2320 rm
= io_regmap(output
, 1);
2321 output
->regs
= DDB_LINK_TAG(port
->lnr
) |
2322 (rm
->output
->base
+ rm
->output
->size
* nr
);
2324 dev_dbg(dev
->dev
, "init link %u, output %u, regs %08x\n",
2325 port
->lnr
, nr
, output
->regs
);
2328 const struct ddb_regmap
*rm0
= io_regmap(output
, 0);
2329 u32 base
= rm0
->irq_base_odma
;
2331 ddb_irq_set(dev
, 0, nr
+ base
, &output_handler
, output
);
2332 ddb_dma_init(output
, nr
, 1);
2336 static int ddb_port_match_i2c(struct ddb_port
*port
)
2338 struct ddb
*dev
= port
->dev
;
2341 for (i
= 0; i
< dev
->i2c_num
; i
++) {
2342 if (dev
->i2c
[i
].link
== port
->lnr
&&
2343 dev
->i2c
[i
].nr
== port
->nr
) {
2344 port
->i2c
= &dev
->i2c
[i
];
2351 static int ddb_port_match_link_i2c(struct ddb_port
*port
)
2353 struct ddb
*dev
= port
->dev
;
2356 for (i
= 0; i
< dev
->i2c_num
; i
++) {
2357 if (dev
->i2c
[i
].link
== port
->lnr
) {
2358 port
->i2c
= &dev
->i2c
[i
];
2365 void ddb_ports_init(struct ddb
*dev
)
2368 struct ddb_port
*port
;
2369 const struct ddb_info
*info
;
2370 const struct ddb_regmap
*rm
;
2372 for (p
= l
= 0; l
< DDB_MAX_LINK
; l
++) {
2373 info
= dev
->link
[l
].info
;
2379 for (i
= 0; i
< info
->port_num
; i
++, p
++) {
2380 port
= &dev
->port
[p
];
2385 port
->gap
= 0xffffffff;
2386 port
->obr
= ci_bitrate
;
2387 mutex_init(&port
->i2c_gate_lock
);
2389 if (!ddb_port_match_i2c(port
)) {
2390 if (info
->type
== DDB_OCTOPUS_MAX
)
2391 ddb_port_match_link_i2c(port
);
2394 ddb_port_probe(port
);
2396 port
->dvb
[0].adap
= &dev
->adap
[2 * p
];
2397 port
->dvb
[1].adap
= &dev
->adap
[2 * p
+ 1];
2399 if (port
->class == DDB_PORT_NONE
&& i
&& p
&&
2400 dev
->port
[p
- 1].type
== DDB_CI_EXTERNAL_XO2
) {
2401 port
->class = DDB_PORT_CI
;
2402 port
->type
= DDB_CI_EXTERNAL_XO2_B
;
2403 port
->name
= "DuoFlex CI_B";
2404 port
->i2c
= dev
->port
[p
- 1].i2c
;
2407 dev_info(dev
->dev
, "Port %u: Link %u, Link Port %u (TAB %u): %s\n",
2408 port
->pnr
, port
->lnr
, port
->nr
, port
->nr
+ 1,
2411 if (port
->class == DDB_PORT_CI
&&
2412 port
->type
== DDB_CI_EXTERNAL_XO2
) {
2413 ddb_input_init(port
, 2 * i
, 0, 2 * i
);
2414 ddb_output_init(port
, i
);
2418 if (port
->class == DDB_PORT_CI
&&
2419 port
->type
== DDB_CI_EXTERNAL_XO2_B
) {
2420 ddb_input_init(port
, 2 * i
- 1, 0, 2 * i
- 1);
2421 ddb_output_init(port
, i
);
2425 if (port
->class == DDB_PORT_NONE
)
2428 switch (dev
->link
[l
].info
->type
) {
2429 case DDB_OCTOPUS_CI
:
2431 ddb_input_init(port
, 2 + i
, 0, 2 + i
);
2432 ddb_input_init(port
, 4 + i
, 1, 4 + i
);
2433 ddb_output_init(port
, i
);
2438 ddb_input_init(port
, 2 * i
, 0, 2 * i
);
2439 ddb_input_init(port
, 2 * i
+ 1, 1, 2 * i
+ 1);
2440 ddb_output_init(port
, i
);
2442 case DDB_OCTOPUS_MAX
:
2443 case DDB_OCTOPUS_MAX_CT
:
2444 case DDB_OCTOPUS_MCI
:
2445 ddb_input_init(port
, 2 * i
, 0, 2 * p
);
2446 ddb_input_init(port
, 2 * i
+ 1, 1, 2 * p
+ 1);
2456 void ddb_ports_release(struct ddb
*dev
)
2459 struct ddb_port
*port
;
2461 for (i
= 0; i
< dev
->port_num
; i
++) {
2462 port
= &dev
->port
[i
];
2463 if (port
->input
[0] && port
->input
[0]->dma
)
2464 cancel_work_sync(&port
->input
[0]->dma
->work
);
2465 if (port
->input
[1] && port
->input
[1]->dma
)
2466 cancel_work_sync(&port
->input
[1]->dma
->work
);
2467 if (port
->output
&& port
->output
->dma
)
2468 cancel_work_sync(&port
->output
->dma
->work
);
2472 /****************************************************************************/
2473 /****************************************************************************/
2474 /****************************************************************************/
2476 #define IRQ_HANDLE(_nr) \
2477 do { if ((s & (1UL << ((_nr) & 0x1f))) && \
2478 dev->link[0].irq[_nr].handler) \
2479 dev->link[0].irq[_nr].handler(dev->link[0].irq[_nr].data); } \
2482 #define IRQ_HANDLE_NIBBLE(_shift) { \
2483 if (s & (0x0000000f << ((_shift) & 0x1f))) { \
2484 IRQ_HANDLE(0 + (_shift)); \
2485 IRQ_HANDLE(1 + (_shift)); \
2486 IRQ_HANDLE(2 + (_shift)); \
2487 IRQ_HANDLE(3 + (_shift)); \
2491 #define IRQ_HANDLE_BYTE(_shift) { \
2492 if (s & (0x000000ff << ((_shift) & 0x1f))) { \
2493 IRQ_HANDLE(0 + (_shift)); \
2494 IRQ_HANDLE(1 + (_shift)); \
2495 IRQ_HANDLE(2 + (_shift)); \
2496 IRQ_HANDLE(3 + (_shift)); \
2497 IRQ_HANDLE(4 + (_shift)); \
2498 IRQ_HANDLE(5 + (_shift)); \
2499 IRQ_HANDLE(6 + (_shift)); \
2500 IRQ_HANDLE(7 + (_shift)); \
2504 static void irq_handle_msg(struct ddb
*dev
, u32 s
)
2507 IRQ_HANDLE_NIBBLE(0);
2510 static void irq_handle_io(struct ddb
*dev
, u32 s
)
2513 IRQ_HANDLE_NIBBLE(4);
2515 IRQ_HANDLE_BYTE(16);
2516 IRQ_HANDLE_BYTE(24);
2519 irqreturn_t
ddb_irq_handler0(int irq
, void *dev_id
)
2521 struct ddb
*dev
= (struct ddb
*)dev_id
;
2522 u32 mask
= 0x8fffff00;
2523 u32 s
= mask
& ddbreadl(dev
, INTERRUPT_STATUS
);
2530 ddbwritel(dev
, s
, INTERRUPT_ACK
);
2531 irq_handle_io(dev
, s
);
2532 } while ((s
= mask
& ddbreadl(dev
, INTERRUPT_STATUS
)));
2537 irqreturn_t
ddb_irq_handler1(int irq
, void *dev_id
)
2539 struct ddb
*dev
= (struct ddb
*)dev_id
;
2540 u32 mask
= 0x8000000f;
2541 u32 s
= mask
& ddbreadl(dev
, INTERRUPT_STATUS
);
2548 ddbwritel(dev
, s
, INTERRUPT_ACK
);
2549 irq_handle_msg(dev
, s
);
2550 } while ((s
= mask
& ddbreadl(dev
, INTERRUPT_STATUS
)));
2555 irqreturn_t
ddb_irq_handler(int irq
, void *dev_id
)
2557 struct ddb
*dev
= (struct ddb
*)dev_id
;
2558 u32 s
= ddbreadl(dev
, INTERRUPT_STATUS
);
2559 int ret
= IRQ_HANDLED
;
2566 ddbwritel(dev
, s
, INTERRUPT_ACK
);
2569 irq_handle_msg(dev
, s
);
2571 irq_handle_io(dev
, s
);
2572 } while ((s
= ddbreadl(dev
, INTERRUPT_STATUS
)));
2577 /****************************************************************************/
2578 /****************************************************************************/
2579 /****************************************************************************/
2581 static int reg_wait(struct ddb
*dev
, u32 reg
, u32 bit
)
2585 while (safe_ddbreadl(dev
, reg
) & bit
) {
2593 static int flashio(struct ddb
*dev
, u32 lnr
, u8
*wbuf
, u32 wlen
, u8
*rbuf
,
2597 u32 tag
= DDB_LINK_TAG(lnr
);
2598 struct ddb_link
*link
= &dev
->link
[lnr
];
2600 mutex_lock(&link
->flash_mutex
);
2602 ddbwritel(dev
, 1, tag
| SPI_CONTROL
);
2604 /* FIXME: check for big-endian */
2605 data
= swab32(*(u32
*)wbuf
);
2608 ddbwritel(dev
, data
, tag
| SPI_DATA
);
2609 if (reg_wait(dev
, tag
| SPI_CONTROL
, 4))
2613 ddbwritel(dev
, 0x0001 | ((wlen
<< (8 + 3)) & 0x1f00),
2616 ddbwritel(dev
, 0x0003 | ((wlen
<< (8 + 3)) & 0x1f00),
2620 shift
= ((4 - wlen
) * 8);
2629 ddbwritel(dev
, data
, tag
| SPI_DATA
);
2630 if (reg_wait(dev
, tag
| SPI_CONTROL
, 4))
2634 ddbwritel(dev
, 0, tag
| SPI_CONTROL
);
2638 ddbwritel(dev
, 1, tag
| SPI_CONTROL
);
2641 ddbwritel(dev
, 0xffffffff, tag
| SPI_DATA
);
2642 if (reg_wait(dev
, tag
| SPI_CONTROL
, 4))
2644 data
= ddbreadl(dev
, tag
| SPI_DATA
);
2645 *(u32
*)rbuf
= swab32(data
);
2649 ddbwritel(dev
, 0x0003 | ((rlen
<< (8 + 3)) & 0x1F00),
2651 ddbwritel(dev
, 0xffffffff, tag
| SPI_DATA
);
2652 if (reg_wait(dev
, tag
| SPI_CONTROL
, 4))
2655 data
= ddbreadl(dev
, tag
| SPI_DATA
);
2656 ddbwritel(dev
, 0, tag
| SPI_CONTROL
);
2659 data
<<= ((4 - rlen
) * 8);
2662 *rbuf
= ((data
>> 24) & 0xff);
2668 mutex_unlock(&link
->flash_mutex
);
2671 mutex_unlock(&link
->flash_mutex
);
2675 int ddbridge_flashread(struct ddb
*dev
, u32 link
, u8
*buf
, u32 addr
, u32 len
)
2677 u8 cmd
[4] = {0x03, (addr
>> 16) & 0xff,
2678 (addr
>> 8) & 0xff, addr
& 0xff};
2680 return flashio(dev
, link
, cmd
, 4, buf
, len
);
2684 * TODO/FIXME: add/implement IOCTLs from upstream driver
2687 #define DDB_NAME "ddbridge"
2690 static int ddb_major
;
2691 static DEFINE_MUTEX(ddb_mutex
);
2693 static int ddb_release(struct inode
*inode
, struct file
*file
)
2695 struct ddb
*dev
= file
->private_data
;
2697 dev
->ddb_dev_users
--;
2701 static int ddb_open(struct inode
*inode
, struct file
*file
)
2703 struct ddb
*dev
= ddbs
[iminor(inode
)];
2705 if (dev
->ddb_dev_users
)
2707 dev
->ddb_dev_users
++;
2708 file
->private_data
= dev
;
2712 static long ddb_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2714 struct ddb
*dev
= file
->private_data
;
2716 dev_warn(dev
->dev
, "DDB IOCTLs unsupported (cmd: %d, arg: %lu)\n",
2722 static const struct file_operations ddb_fops
= {
2723 .unlocked_ioctl
= ddb_ioctl
,
2725 .release
= ddb_release
,
2728 static char *ddb_devnode(struct device
*device
, umode_t
*mode
)
2730 struct ddb
*dev
= dev_get_drvdata(device
);
2732 return kasprintf(GFP_KERNEL
, "ddbridge/card%d", dev
->nr
);
2735 #define __ATTR_MRO(_name, _show) { \
2736 .attr = { .name = __stringify(_name), .mode = 0444 }, \
2740 #define __ATTR_MWO(_name, _store) { \
2741 .attr = { .name = __stringify(_name), .mode = 0222 }, \
2745 static ssize_t
ports_show(struct device
*device
,
2746 struct device_attribute
*attr
, char *buf
)
2748 struct ddb
*dev
= dev_get_drvdata(device
);
2750 return sprintf(buf
, "%d\n", dev
->port_num
);
2753 static ssize_t
ts_irq_show(struct device
*device
,
2754 struct device_attribute
*attr
, char *buf
)
2756 struct ddb
*dev
= dev_get_drvdata(device
);
2758 return sprintf(buf
, "%d\n", dev
->ts_irq
);
2761 static ssize_t
i2c_irq_show(struct device
*device
,
2762 struct device_attribute
*attr
, char *buf
)
2764 struct ddb
*dev
= dev_get_drvdata(device
);
2766 return sprintf(buf
, "%d\n", dev
->i2c_irq
);
2769 static ssize_t
fan_show(struct device
*device
,
2770 struct device_attribute
*attr
, char *buf
)
2772 struct ddb
*dev
= dev_get_drvdata(device
);
2775 val
= ddbreadl(dev
, GPIO_OUTPUT
) & 1;
2776 return sprintf(buf
, "%d\n", val
);
2779 static ssize_t
fan_store(struct device
*device
, struct device_attribute
*d
,
2780 const char *buf
, size_t count
)
2782 struct ddb
*dev
= dev_get_drvdata(device
);
2785 if (sscanf(buf
, "%u\n", &val
) != 1)
2787 ddbwritel(dev
, 1, GPIO_DIRECTION
);
2788 ddbwritel(dev
, val
& 1, GPIO_OUTPUT
);
2792 static ssize_t
fanspeed_show(struct device
*device
,
2793 struct device_attribute
*attr
, char *buf
)
2795 struct ddb
*dev
= dev_get_drvdata(device
);
2796 int num
= attr
->attr
.name
[8] - 0x30;
2797 struct ddb_link
*link
= &dev
->link
[num
];
2800 spd
= ddblreadl(link
, TEMPMON_FANCONTROL
) & 0xff;
2801 return sprintf(buf
, "%u\n", spd
* 100);
2804 static ssize_t
temp_show(struct device
*device
,
2805 struct device_attribute
*attr
, char *buf
)
2807 struct ddb
*dev
= dev_get_drvdata(device
);
2808 struct ddb_link
*link
= &dev
->link
[0];
2809 struct i2c_adapter
*adap
;
2813 if (!link
->info
->temp_num
)
2814 return sprintf(buf
, "no sensor\n");
2815 adap
= &dev
->i2c
[link
->info
->temp_bus
].adap
;
2816 if (i2c_read_regs(adap
, 0x48, 0, tmp
, 2) < 0)
2817 return sprintf(buf
, "read_error\n");
2818 temp
= (tmp
[0] << 3) | (tmp
[1] >> 5);
2820 if (link
->info
->temp_num
== 2) {
2821 if (i2c_read_regs(adap
, 0x49, 0, tmp
, 2) < 0)
2822 return sprintf(buf
, "read_error\n");
2823 temp2
= (tmp
[0] << 3) | (tmp
[1] >> 5);
2825 return sprintf(buf
, "%d %d\n", temp
, temp2
);
2827 return sprintf(buf
, "%d\n", temp
);
2830 static ssize_t
ctemp_show(struct device
*device
,
2831 struct device_attribute
*attr
, char *buf
)
2833 struct ddb
*dev
= dev_get_drvdata(device
);
2834 struct i2c_adapter
*adap
;
2837 int num
= attr
->attr
.name
[4] - 0x30;
2839 adap
= &dev
->i2c
[num
].adap
;
2842 if (i2c_read_regs(adap
, 0x49, 0, tmp
, 2) < 0)
2843 if (i2c_read_regs(adap
, 0x4d, 0, tmp
, 2) < 0)
2844 return sprintf(buf
, "no sensor\n");
2845 temp
= tmp
[0] * 1000;
2846 return sprintf(buf
, "%d\n", temp
);
2849 static ssize_t
led_show(struct device
*device
,
2850 struct device_attribute
*attr
, char *buf
)
2852 struct ddb
*dev
= dev_get_drvdata(device
);
2853 int num
= attr
->attr
.name
[3] - 0x30;
2855 return sprintf(buf
, "%d\n", dev
->leds
& (1 << num
) ? 1 : 0);
2858 static void ddb_set_led(struct ddb
*dev
, int num
, int val
)
2860 if (!dev
->link
[0].info
->led_num
)
2862 switch (dev
->port
[num
].class) {
2863 case DDB_PORT_TUNER
:
2864 switch (dev
->port
[num
].type
) {
2865 case DDB_TUNER_DVBS_ST
:
2866 i2c_write_reg16(&dev
->i2c
[num
].adap
,
2867 0x69, 0xf14c, val
? 2 : 0);
2869 case DDB_TUNER_DVBCT_ST
:
2870 i2c_write_reg16(&dev
->i2c
[num
].adap
,
2872 i2c_write_reg16(&dev
->i2c
[num
].adap
,
2873 0x1f, 0xf00f, val
? 1 : 0);
2875 case DDB_TUNER_XO2
... DDB_TUNER_DVBC2T2I_SONY
:
2879 i2c_read_reg(&dev
->i2c
[num
].adap
, 0x10, 0x08, &v
);
2880 v
= (v
& ~0x10) | (val
? 0x10 : 0);
2881 i2c_write_reg(&dev
->i2c
[num
].adap
, 0x10, 0x08, v
);
2891 static ssize_t
led_store(struct device
*device
,
2892 struct device_attribute
*attr
,
2893 const char *buf
, size_t count
)
2895 struct ddb
*dev
= dev_get_drvdata(device
);
2896 int num
= attr
->attr
.name
[3] - 0x30;
2899 if (sscanf(buf
, "%u\n", &val
) != 1)
2902 dev
->leds
|= (1 << num
);
2904 dev
->leds
&= ~(1 << num
);
2905 ddb_set_led(dev
, num
, val
);
2909 static ssize_t
snr_show(struct device
*device
,
2910 struct device_attribute
*attr
, char *buf
)
2912 struct ddb
*dev
= dev_get_drvdata(device
);
2914 int num
= attr
->attr
.name
[3] - 0x30;
2916 if (dev
->port
[num
].type
>= DDB_TUNER_XO2
) {
2917 if (i2c_read_regs(&dev
->i2c
[num
].adap
, 0x10, 0x10, snr
, 16) < 0)
2918 return sprintf(buf
, "NO SNR\n");
2921 /* serial number at 0x100-0x11f */
2922 if (i2c_read_regs16(&dev
->i2c
[num
].adap
,
2923 0x57, 0x100, snr
, 32) < 0)
2924 if (i2c_read_regs16(&dev
->i2c
[num
].adap
,
2925 0x50, 0x100, snr
, 32) < 0)
2926 return sprintf(buf
, "NO SNR\n");
2927 snr
[31] = 0; /* in case it is not terminated on EEPROM */
2929 return sprintf(buf
, "%s\n", snr
);
2932 static ssize_t
bsnr_show(struct device
*device
,
2933 struct device_attribute
*attr
, char *buf
)
2935 struct ddb
*dev
= dev_get_drvdata(device
);
2938 ddbridge_flashread(dev
, 0, snr
, 0x10, 15);
2939 snr
[15] = 0; /* in case it is not terminated on EEPROM */
2940 return sprintf(buf
, "%s\n", snr
);
2943 static ssize_t
bpsnr_show(struct device
*device
,
2944 struct device_attribute
*attr
, char *buf
)
2946 struct ddb
*dev
= dev_get_drvdata(device
);
2947 unsigned char snr
[32];
2952 if (i2c_read_regs16(&dev
->i2c
[0].adap
,
2953 0x50, 0x0000, snr
, 32) < 0 ||
2955 return sprintf(buf
, "NO SNR\n");
2956 snr
[31] = 0; /* in case it is not terminated on EEPROM */
2957 return sprintf(buf
, "%s\n", snr
);
2960 static ssize_t
redirect_show(struct device
*device
,
2961 struct device_attribute
*attr
, char *buf
)
2966 static ssize_t
redirect_store(struct device
*device
,
2967 struct device_attribute
*attr
,
2968 const char *buf
, size_t count
)
2973 if (sscanf(buf
, "%x %x\n", &i
, &p
) != 2)
2975 res
= ddb_redirect(i
, p
);
2978 dev_info(device
, "redirect: %02x, %02x\n", i
, p
);
2982 static ssize_t
gap_show(struct device
*device
,
2983 struct device_attribute
*attr
, char *buf
)
2985 struct ddb
*dev
= dev_get_drvdata(device
);
2986 int num
= attr
->attr
.name
[3] - 0x30;
2988 return sprintf(buf
, "%d\n", dev
->port
[num
].gap
);
2991 static ssize_t
gap_store(struct device
*device
, struct device_attribute
*attr
,
2992 const char *buf
, size_t count
)
2994 struct ddb
*dev
= dev_get_drvdata(device
);
2995 int num
= attr
->attr
.name
[3] - 0x30;
2998 if (sscanf(buf
, "%u\n", &val
) != 1)
3004 dev
->port
[num
].gap
= val
;
3008 static ssize_t
version_show(struct device
*device
,
3009 struct device_attribute
*attr
, char *buf
)
3011 struct ddb
*dev
= dev_get_drvdata(device
);
3013 return sprintf(buf
, "%08x %08x\n",
3014 dev
->link
[0].ids
.hwid
, dev
->link
[0].ids
.regmapid
);
3017 static ssize_t
hwid_show(struct device
*device
,
3018 struct device_attribute
*attr
, char *buf
)
3020 struct ddb
*dev
= dev_get_drvdata(device
);
3022 return sprintf(buf
, "0x%08X\n", dev
->link
[0].ids
.hwid
);
3025 static ssize_t
regmap_show(struct device
*device
,
3026 struct device_attribute
*attr
, char *buf
)
3028 struct ddb
*dev
= dev_get_drvdata(device
);
3030 return sprintf(buf
, "0x%08X\n", dev
->link
[0].ids
.regmapid
);
3033 static ssize_t
fmode_show(struct device
*device
,
3034 struct device_attribute
*attr
, char *buf
)
3036 int num
= attr
->attr
.name
[5] - 0x30;
3037 struct ddb
*dev
= dev_get_drvdata(device
);
3039 return sprintf(buf
, "%u\n", dev
->link
[num
].lnb
.fmode
);
3042 static ssize_t
devid_show(struct device
*device
,
3043 struct device_attribute
*attr
, char *buf
)
3045 int num
= attr
->attr
.name
[5] - 0x30;
3046 struct ddb
*dev
= dev_get_drvdata(device
);
3048 return sprintf(buf
, "%08x\n", dev
->link
[num
].ids
.devid
);
3051 static ssize_t
fmode_store(struct device
*device
, struct device_attribute
*attr
,
3052 const char *buf
, size_t count
)
3054 struct ddb
*dev
= dev_get_drvdata(device
);
3055 int num
= attr
->attr
.name
[5] - 0x30;
3058 if (sscanf(buf
, "%u\n", &val
) != 1)
3062 ddb_lnb_init_fmode(dev
, &dev
->link
[num
], val
);
3066 static struct device_attribute ddb_attrs
[] = {
3071 __ATTR(gap0
, 0664, gap_show
, gap_store
),
3072 __ATTR(gap1
, 0664, gap_show
, gap_store
),
3073 __ATTR(gap2
, 0664, gap_show
, gap_store
),
3074 __ATTR(gap3
, 0664, gap_show
, gap_store
),
3075 __ATTR(fmode0
, 0664, fmode_show
, fmode_store
),
3076 __ATTR(fmode1
, 0664, fmode_show
, fmode_store
),
3077 __ATTR(fmode2
, 0664, fmode_show
, fmode_store
),
3078 __ATTR(fmode3
, 0664, fmode_show
, fmode_store
),
3079 __ATTR_MRO(devid0
, devid_show
),
3080 __ATTR_MRO(devid1
, devid_show
),
3081 __ATTR_MRO(devid2
, devid_show
),
3082 __ATTR_MRO(devid3
, devid_show
),
3085 __ATTR(redirect
, 0664, redirect_show
, redirect_store
),
3086 __ATTR_MRO(snr
, bsnr_show
),
3091 static struct device_attribute ddb_attrs_temp
[] = {
3095 static struct device_attribute ddb_attrs_fan
[] = {
3096 __ATTR(fan
, 0664, fan_show
, fan_store
),
3099 static struct device_attribute ddb_attrs_snr
[] = {
3100 __ATTR_MRO(snr0
, snr_show
),
3101 __ATTR_MRO(snr1
, snr_show
),
3102 __ATTR_MRO(snr2
, snr_show
),
3103 __ATTR_MRO(snr3
, snr_show
),
3106 static struct device_attribute ddb_attrs_ctemp
[] = {
3107 __ATTR_MRO(temp0
, ctemp_show
),
3108 __ATTR_MRO(temp1
, ctemp_show
),
3109 __ATTR_MRO(temp2
, ctemp_show
),
3110 __ATTR_MRO(temp3
, ctemp_show
),
3113 static struct device_attribute ddb_attrs_led
[] = {
3114 __ATTR(led0
, 0664, led_show
, led_store
),
3115 __ATTR(led1
, 0664, led_show
, led_store
),
3116 __ATTR(led2
, 0664, led_show
, led_store
),
3117 __ATTR(led3
, 0664, led_show
, led_store
),
3120 static struct device_attribute ddb_attrs_fanspeed
[] = {
3121 __ATTR_MRO(fanspeed0
, fanspeed_show
),
3122 __ATTR_MRO(fanspeed1
, fanspeed_show
),
3123 __ATTR_MRO(fanspeed2
, fanspeed_show
),
3124 __ATTR_MRO(fanspeed3
, fanspeed_show
),
3127 static struct class ddb_class
= {
3129 .owner
= THIS_MODULE
,
3130 .devnode
= ddb_devnode
,
3133 static int ddb_class_create(void)
3135 ddb_major
= register_chrdev(0, DDB_NAME
, &ddb_fops
);
3138 if (class_register(&ddb_class
) < 0)
3143 static void ddb_class_destroy(void)
3145 class_unregister(&ddb_class
);
3146 unregister_chrdev(ddb_major
, DDB_NAME
);
3149 static void ddb_device_attrs_del(struct ddb
*dev
)
3153 for (i
= 0; i
< 4; i
++)
3154 if (dev
->link
[i
].info
&& dev
->link
[i
].info
->tempmon_irq
)
3155 device_remove_file(dev
->ddb_dev
,
3156 &ddb_attrs_fanspeed
[i
]);
3157 for (i
= 0; i
< dev
->link
[0].info
->temp_num
; i
++)
3158 device_remove_file(dev
->ddb_dev
, &ddb_attrs_temp
[i
]);
3159 for (i
= 0; i
< dev
->link
[0].info
->fan_num
; i
++)
3160 device_remove_file(dev
->ddb_dev
, &ddb_attrs_fan
[i
]);
3161 for (i
= 0; i
< dev
->i2c_num
&& i
< 4; i
++) {
3162 if (dev
->link
[0].info
->led_num
)
3163 device_remove_file(dev
->ddb_dev
, &ddb_attrs_led
[i
]);
3164 device_remove_file(dev
->ddb_dev
, &ddb_attrs_snr
[i
]);
3165 device_remove_file(dev
->ddb_dev
, &ddb_attrs_ctemp
[i
]);
3167 for (i
= 0; ddb_attrs
[i
].attr
.name
; i
++)
3168 device_remove_file(dev
->ddb_dev
, &ddb_attrs
[i
]);
3171 static int ddb_device_attrs_add(struct ddb
*dev
)
3175 for (i
= 0; ddb_attrs
[i
].attr
.name
; i
++)
3176 if (device_create_file(dev
->ddb_dev
, &ddb_attrs
[i
]))
3178 for (i
= 0; i
< dev
->link
[0].info
->temp_num
; i
++)
3179 if (device_create_file(dev
->ddb_dev
, &ddb_attrs_temp
[i
]))
3181 for (i
= 0; i
< dev
->link
[0].info
->fan_num
; i
++)
3182 if (device_create_file(dev
->ddb_dev
, &ddb_attrs_fan
[i
]))
3184 for (i
= 0; (i
< dev
->i2c_num
) && (i
< 4); i
++) {
3185 if (device_create_file(dev
->ddb_dev
, &ddb_attrs_snr
[i
]))
3187 if (device_create_file(dev
->ddb_dev
, &ddb_attrs_ctemp
[i
]))
3189 if (dev
->link
[0].info
->led_num
)
3190 if (device_create_file(dev
->ddb_dev
,
3194 for (i
= 0; i
< 4; i
++)
3195 if (dev
->link
[i
].info
&& dev
->link
[i
].info
->tempmon_irq
)
3196 if (device_create_file(dev
->ddb_dev
,
3197 &ddb_attrs_fanspeed
[i
]))
3204 int ddb_device_create(struct ddb
*dev
)
3208 if (ddb_num
== DDB_MAX_ADAPTER
)
3210 mutex_lock(&ddb_mutex
);
3212 ddbs
[dev
->nr
] = dev
;
3213 dev
->ddb_dev
= device_create(&ddb_class
, dev
->dev
,
3214 MKDEV(ddb_major
, dev
->nr
),
3215 dev
, "ddbridge%d", dev
->nr
);
3216 if (IS_ERR(dev
->ddb_dev
)) {
3217 res
= PTR_ERR(dev
->ddb_dev
);
3218 dev_info(dev
->dev
, "Could not create ddbridge%d\n", dev
->nr
);
3221 res
= ddb_device_attrs_add(dev
);
3223 ddb_device_attrs_del(dev
);
3224 device_destroy(&ddb_class
, MKDEV(ddb_major
, dev
->nr
));
3225 ddbs
[dev
->nr
] = NULL
;
3226 dev
->ddb_dev
= ERR_PTR(-ENODEV
);
3231 mutex_unlock(&ddb_mutex
);
3235 void ddb_device_destroy(struct ddb
*dev
)
3237 if (IS_ERR(dev
->ddb_dev
))
3239 ddb_device_attrs_del(dev
);
3240 device_destroy(&ddb_class
, MKDEV(ddb_major
, dev
->nr
));
3243 /****************************************************************************/
3244 /****************************************************************************/
3245 /****************************************************************************/
3247 static void tempmon_setfan(struct ddb_link
*link
)
3249 u32 temp
, temp2
, pwm
;
3251 if ((ddblreadl(link
, TEMPMON_CONTROL
) &
3252 TEMPMON_CONTROL_OVERTEMP
) != 0) {
3253 dev_info(link
->dev
->dev
, "Over temperature condition\n");
3254 link
->overtemperature_error
= 1;
3256 temp
= (ddblreadl(link
, TEMPMON_SENSOR0
) >> 8) & 0xFF;
3259 temp2
= (ddblreadl(link
, TEMPMON_SENSOR1
) >> 8) & 0xFF;
3265 pwm
= (ddblreadl(link
, TEMPMON_FANCONTROL
) >> 8) & 0x0F;
3269 if (temp
>= link
->temp_tab
[pwm
]) {
3270 while (pwm
< 10 && temp
>= link
->temp_tab
[pwm
+ 1])
3273 while (pwm
> 1 && temp
< link
->temp_tab
[pwm
- 2])
3276 ddblwritel(link
, (pwm
<< 8), TEMPMON_FANCONTROL
);
3279 static void temp_handler(void *data
)
3281 struct ddb_link
*link
= (struct ddb_link
*)data
;
3283 spin_lock(&link
->temp_lock
);
3284 tempmon_setfan(link
);
3285 spin_unlock(&link
->temp_lock
);
3288 static int tempmon_init(struct ddb_link
*link
, int first_time
)
3290 struct ddb
*dev
= link
->dev
;
3294 spin_lock_irq(&link
->temp_lock
);
3296 static u8 temperature_table
[11] = {
3297 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80 };
3299 memcpy(link
->temp_tab
, temperature_table
,
3300 sizeof(temperature_table
));
3302 ddb_irq_set(dev
, l
, link
->info
->tempmon_irq
, temp_handler
, link
);
3303 ddblwritel(link
, (TEMPMON_CONTROL_OVERTEMP
| TEMPMON_CONTROL_AUTOSCAN
|
3304 TEMPMON_CONTROL_INTENABLE
),
3306 ddblwritel(link
, (3 << 8), TEMPMON_FANCONTROL
);
3308 link
->overtemperature_error
=
3309 ((ddblreadl(link
, TEMPMON_CONTROL
) &
3310 TEMPMON_CONTROL_OVERTEMP
) != 0);
3311 if (link
->overtemperature_error
) {
3312 dev_info(link
->dev
->dev
, "Over temperature condition\n");
3315 tempmon_setfan(link
);
3316 spin_unlock_irq(&link
->temp_lock
);
3320 static int ddb_init_tempmon(struct ddb_link
*link
)
3322 const struct ddb_info
*info
= link
->info
;
3324 if (!info
->tempmon_irq
)
3326 if (info
->type
== DDB_OCTOPUS_MAX_CT
)
3327 if (link
->ids
.regmapid
< 0x00010002)
3329 spin_lock_init(&link
->temp_lock
);
3330 dev_dbg(link
->dev
->dev
, "init_tempmon\n");
3331 return tempmon_init(link
, 1);
3334 /****************************************************************************/
3335 /****************************************************************************/
3336 /****************************************************************************/
3338 static int ddb_init_boards(struct ddb
*dev
)
3340 const struct ddb_info
*info
;
3341 struct ddb_link
*link
;
3344 for (l
= 0; l
< DDB_MAX_LINK
; l
++) {
3345 link
= &dev
->link
[l
];
3350 if (info
->board_control
) {
3351 ddbwritel(dev
, 0, DDB_LINK_TAG(l
) | BOARD_CONTROL
);
3353 ddbwritel(dev
, info
->board_control_2
,
3354 DDB_LINK_TAG(l
) | BOARD_CONTROL
);
3355 usleep_range(2000, 3000);
3357 info
->board_control_2
| info
->board_control
,
3358 DDB_LINK_TAG(l
) | BOARD_CONTROL
);
3359 usleep_range(2000, 3000);
3361 ddb_init_tempmon(link
);
3366 int ddb_init(struct ddb
*dev
)
3368 mutex_init(&dev
->link
[0].lnb
.lock
);
3369 mutex_init(&dev
->link
[0].flash_mutex
);
3371 ddb_device_create(dev
);
3375 ddb_init_boards(dev
);
3377 if (ddb_i2c_init(dev
) < 0)
3379 ddb_ports_init(dev
);
3380 if (ddb_buffers_alloc(dev
) < 0) {
3381 dev_info(dev
->dev
, "Could not allocate buffer memory\n");
3384 if (ddb_ports_attach(dev
) < 0)
3387 ddb_device_create(dev
);
3389 if (dev
->link
[0].info
->fan_num
) {
3390 ddbwritel(dev
, 1, GPIO_DIRECTION
);
3391 ddbwritel(dev
, 1, GPIO_OUTPUT
);
3396 dev_err(dev
->dev
, "fail3\n");
3397 ddb_ports_detach(dev
);
3398 ddb_buffers_free(dev
);
3400 dev_err(dev
->dev
, "fail2\n");
3401 ddb_ports_release(dev
);
3402 ddb_i2c_release(dev
);
3404 dev_err(dev
->dev
, "fail1\n");
3408 void ddb_unmap(struct ddb
*dev
)
3415 int ddb_exit_ddbridge(int stage
, int error
)
3420 destroy_workqueue(ddb_wq
);
3423 ddb_class_destroy();
3430 int ddb_init_ddbridge(void)
3432 if (dma_buf_num
< 8)
3434 if (dma_buf_num
> 32)
3436 if (dma_buf_size
< 1)
3438 if (dma_buf_size
> 43)
3441 if (ddb_class_create() < 0)
3443 ddb_wq
= alloc_workqueue("ddbridge", 0, 0);
3445 return ddb_exit_ddbridge(1, -1);