1 /* SPDX-License-Identifier: GPL-2.0 */
3 * ddbridge.h: Digital Devices PCIe bridge driver
5 * Copyright (C) 2010-2017 Digital Devices GmbH
6 * Ralph Metzler <rmetzler@digitaldevices.de>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 only, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
21 #include <linux/clk.h>
22 #include <linux/completion.h>
23 #include <linux/delay.h>
24 #include <linux/device.h>
25 #include <linux/dvb/ca.h>
26 #include <linux/gpio.h>
27 #include <linux/i2c.h>
28 #include <linux/init.h>
29 #include <linux/interrupt.h>
31 #include <linux/kthread.h>
32 #include <linux/module.h>
33 #include <linux/mutex.h>
34 #include <linux/pci.h>
35 #include <linux/platform_device.h>
36 #include <linux/poll.h>
37 #include <linux/sched.h>
38 #include <linux/slab.h>
39 #include <linux/socket.h>
40 #include <linux/spi/spi.h>
41 #include <linux/swab.h>
42 #include <linux/timer.h>
43 #include <linux/types.h>
44 #include <linux/uaccess.h>
45 #include <linux/vmalloc.h>
46 #include <linux/workqueue.h>
51 #include <media/dmxdev.h>
52 #include <media/dvb_ca_en50221.h>
53 #include <media/dvb_demux.h>
54 #include <media/dvbdev.h>
55 #include <media/dvb_frontend.h>
56 #include <media/dvb_net.h>
57 #include <media/dvb_ringbuffer.h>
59 #define DDBRIDGE_VERSION "0.9.33-integrated"
61 #define DDB_MAX_I2C 32
62 #define DDB_MAX_PORT 32
63 #define DDB_MAX_INPUT 64
64 #define DDB_MAX_OUTPUT 32
65 #define DDB_MAX_LINK 4
66 #define DDB_LINK_SHIFT 28
68 #define DDB_LINK_TAG(_x) (_x << DDB_LINK_SHIFT)
81 const struct ddb_regset
*i2c
;
82 const struct ddb_regset
*i2c_buf
;
83 const struct ddb_regset
*idma
;
84 const struct ddb_regset
*idma_buf
;
85 const struct ddb_regset
*odma
;
86 const struct ddb_regset
*odma_buf
;
88 const struct ddb_regset
*input
;
89 const struct ddb_regset
*output
;
91 const struct ddb_regset
*channel
;
109 #define DDB_OCTOPUS 1
110 #define DDB_OCTOPUS_CI 2
111 #define DDB_OCTOPUS_MAX 5
112 #define DDB_OCTOPUS_MAX_CT 6
113 #define DDB_OCTOPUS_MCI 9
124 u8 con_clock
; /* use a continuous clock */
126 #define TS_QUIRK_SERIAL 1
127 #define TS_QUIRK_REVERSED 2
128 #define TS_QUIRK_ALT_OSC 8
133 const struct ddb_regmap
*regmap
;
136 #define DMA_MAX_BUFS 32 /* hardware table limit */
146 dma_addr_t pbuf
[DMA_MAX_BUFS
];
147 u8
*vbuf
[DMA_MAX_BUFS
];
153 struct work_struct work
;
154 spinlock_t lock
; /* DMA lock */
155 wait_queue_head_t wq
;
164 struct dvb_adapter
*adap
;
166 struct dvb_device
*dev
;
167 struct i2c_client
*i2c_client
[1];
168 struct dvb_frontend
*fe
;
169 struct dvb_frontend
*fe2
;
170 struct dmxdev dmxdev
;
171 struct dvb_demux demux
;
172 struct dvb_net dvbnet
;
173 struct dmx_frontend hw_frontend
;
174 struct dmx_frontend mem_frontend
;
179 enum fe_sec_tone_mode tone
;
180 enum fe_sec_voltage voltage
;
182 int (*i2c_gate_ctrl
)(struct dvb_frontend
*, int);
183 int (*set_voltage
)(struct dvb_frontend
*fe
,
184 enum fe_sec_voltage voltage
);
185 int (*set_input
)(struct dvb_frontend
*fe
, int input
);
186 int (*diseqc_send_master_cmd
)(struct dvb_frontend
*fe
,
187 struct dvb_diseqc_master_cmd
*cmd
);
191 struct dvb_ca_en50221 en
;
192 struct ddb_port
*port
;
197 struct ddb_port
*port
;
205 #define ddb_output ddb_io
206 #define ddb_input ddb_io
213 struct i2c_adapter adap
;
217 struct completion completion
;
227 struct mutex i2c_gate_lock
; /* I2C access lock */
229 #define DDB_PORT_NONE 0
230 #define DDB_PORT_CI 1
231 #define DDB_PORT_TUNER 2
232 #define DDB_PORT_LOOP 3
236 #define DDB_TUNER_DUMMY 0xffffffff
237 #define DDB_TUNER_NONE 0
238 #define DDB_TUNER_DVBS_ST 1
239 #define DDB_TUNER_DVBS_ST_AA 2
240 #define DDB_TUNER_DVBCT_TR 3
241 #define DDB_TUNER_DVBCT_ST 4
242 #define DDB_CI_INTERNAL 5
243 #define DDB_CI_EXTERNAL_SONY 6
244 #define DDB_TUNER_DVBCT2_SONY_P 7
245 #define DDB_TUNER_DVBC2T2_SONY_P 8
246 #define DDB_TUNER_ISDBT_SONY_P 9
247 #define DDB_TUNER_DVBS_STV0910_P 10
248 #define DDB_TUNER_MXL5XX 11
249 #define DDB_CI_EXTERNAL_XO2 12
250 #define DDB_CI_EXTERNAL_XO2_B 13
251 #define DDB_TUNER_DVBS_STV0910_PR 14
252 #define DDB_TUNER_DVBC2T2I_SONY_P 15
254 #define DDB_TUNER_XO2 32
255 #define DDB_TUNER_DVBS_STV0910 (DDB_TUNER_XO2 + 0)
256 #define DDB_TUNER_DVBCT2_SONY (DDB_TUNER_XO2 + 1)
257 #define DDB_TUNER_ISDBT_SONY (DDB_TUNER_XO2 + 2)
258 #define DDB_TUNER_DVBC2T2_SONY (DDB_TUNER_XO2 + 3)
259 #define DDB_TUNER_ATSC_ST (DDB_TUNER_XO2 + 4)
260 #define DDB_TUNER_DVBC2T2I_SONY (DDB_TUNER_XO2 + 5)
262 #define DDB_TUNER_MCI 48
263 #define DDB_TUNER_MCI_SX8 (DDB_TUNER_MCI + 0)
265 struct ddb_input
*input
[2];
266 struct ddb_output
*output
;
267 struct dvb_ca_en50221
*en
;
269 struct ddb_dvb dvb
[2];
275 #define CM_STARTUP_DELAY 2
276 #define CM_AVERAGE 20
279 #define HW_LSB_SHIFT 12
280 #define HW_LSB_MASK 0x1000
286 #define TS_CAPTURE_LEN (4096)
289 struct mutex lock
; /* lock lnb access */
291 enum fe_sec_voltage oldvoltage
[4];
298 void (*handler
)(void *);
304 const struct ddb_info
*info
;
307 spinlock_t lock
; /* lock link access */
308 struct mutex flash_mutex
; /* lock flash access */
310 struct tasklet_struct tasklet
;
313 spinlock_t temp_lock
; /* lock temp chip access */
314 int overtemperature_error
;
316 struct ddb_irq irq
[256];
320 struct pci_dev
*pdev
;
321 struct platform_device
*pfdev
;
325 struct workqueue_struct
*wq
;
328 struct ddb_link link
[DDB_MAX_LINK
];
329 unsigned char __iomem
*regs
;
332 struct ddb_port port
[DDB_MAX_PORT
];
334 struct ddb_i2c i2c
[DDB_MAX_I2C
];
335 struct ddb_input input
[DDB_MAX_INPUT
];
336 struct ddb_output output
[DDB_MAX_OUTPUT
];
337 struct dvb_adapter adap
[DDB_MAX_INPUT
];
338 struct ddb_dma idma
[DDB_MAX_INPUT
];
339 struct ddb_dma odma
[DDB_MAX_OUTPUT
];
341 struct device
*ddb_dev
;
350 struct mutex mutex
; /* lock access to global ddb array */
352 u8 tsbuf
[TS_CAPTURE_LEN
];
355 /****************************************************************************/
356 /****************************************************************************/
357 /****************************************************************************/
359 int ddbridge_flashread(struct ddb
*dev
, u32 link
, u8
*buf
, u32 addr
, u32 len
);
361 /****************************************************************************/
363 /* ddbridge-core.c */
364 struct ddb_irq
*ddb_irq_set(struct ddb
*dev
, u32 link
, u32 nr
,
365 void (*handler
)(void *), void *data
);
366 void ddb_ports_detach(struct ddb
*dev
);
367 void ddb_ports_release(struct ddb
*dev
);
368 void ddb_buffers_free(struct ddb
*dev
);
369 void ddb_device_destroy(struct ddb
*dev
);
370 irqreturn_t
ddb_irq_handler0(int irq
, void *dev_id
);
371 irqreturn_t
ddb_irq_handler1(int irq
, void *dev_id
);
372 irqreturn_t
ddb_irq_handler(int irq
, void *dev_id
);
373 void ddb_ports_init(struct ddb
*dev
);
374 int ddb_buffers_alloc(struct ddb
*dev
);
375 int ddb_ports_attach(struct ddb
*dev
);
376 int ddb_device_create(struct ddb
*dev
);
377 int ddb_init(struct ddb
*dev
);
378 void ddb_unmap(struct ddb
*dev
);
379 int ddb_exit_ddbridge(int stage
, int error
);
380 int ddb_init_ddbridge(void);
382 #endif /* DDBRIDGE_H */