xref: /linux/drivers/media/pci/netup_unidvb/netup_unidvb.h (revision da1d9caf95def6f0320819cf941c9fd1069ba9e1)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * netup_unidvb.h
4  *
5  * Data type definitions for NetUP Universal Dual DVB-CI
6  *
7  * Copyright (C) 2014 NetUP Inc.
8  * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru>
9  * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru>
10  */
11 
12 #include <linux/pci.h>
13 #include <linux/i2c.h>
14 #include <linux/workqueue.h>
15 #include <media/v4l2-common.h>
16 #include <media/v4l2-device.h>
17 #include <media/videobuf2-dvb.h>
18 #include <media/dvb_ca_en50221.h>
19 
20 #define NETUP_UNIDVB_NAME	"netup_unidvb"
21 #define NETUP_UNIDVB_VERSION	"0.0.1"
22 #define NETUP_VENDOR_ID		0x1b55
23 #define NETUP_PCI_DEV_REVISION  0x2
24 
25 /* IRQ-related regisers */
26 #define REG_ISR			0x4890
27 #define REG_ISR_MASKED		0x4892
28 #define REG_IMASK_SET		0x4894
29 #define REG_IMASK_CLEAR		0x4896
30 /* REG_ISR register bits */
31 #define NETUP_UNIDVB_IRQ_SPI	(1 << 0)
32 #define NETUP_UNIDVB_IRQ_I2C0	(1 << 1)
33 #define NETUP_UNIDVB_IRQ_I2C1	(1 << 2)
34 #define NETUP_UNIDVB_IRQ_FRA0	(1 << 4)
35 #define NETUP_UNIDVB_IRQ_FRA1	(1 << 5)
36 #define NETUP_UNIDVB_IRQ_FRB0	(1 << 6)
37 #define NETUP_UNIDVB_IRQ_FRB1	(1 << 7)
38 #define NETUP_UNIDVB_IRQ_DMA1	(1 << 8)
39 #define NETUP_UNIDVB_IRQ_DMA2	(1 << 9)
40 #define NETUP_UNIDVB_IRQ_CI	(1 << 10)
41 #define NETUP_UNIDVB_IRQ_CAM0	(1 << 11)
42 #define NETUP_UNIDVB_IRQ_CAM1	(1 << 12)
43 
44 /* NetUP Universal DVB card hardware revisions and it's PCI device id's:
45  * 1.3 - CXD2841ER demod, ASCOT2E and HORUS3A tuners
46  * 1.4 - CXD2854ER demod, HELENE tuner
47 */
48 enum netup_hw_rev {
49 	NETUP_HW_REV_1_3 = 0x18F6,
50 	NETUP_HW_REV_1_4 = 0x18F7
51 };
52 
53 struct netup_dma {
54 	u8			num;
55 	spinlock_t		lock;
56 	struct netup_unidvb_dev	*ndev;
57 	struct netup_dma_regs __iomem *regs;
58 	u32			ring_buffer_size;
59 	u8			*addr_virt;
60 	dma_addr_t		addr_phys;
61 	u64			addr_last;
62 	u32			high_addr;
63 	u32			data_offset;
64 	u32			data_size;
65 	struct list_head	free_buffers;
66 	struct work_struct	work;
67 	struct timer_list	timeout;
68 };
69 
70 enum netup_i2c_state {
71 	STATE_DONE,
72 	STATE_WAIT,
73 	STATE_WANT_READ,
74 	STATE_WANT_WRITE,
75 	STATE_ERROR
76 };
77 
78 struct netup_i2c_regs;
79 
80 struct netup_i2c {
81 	spinlock_t			lock;
82 	wait_queue_head_t		wq;
83 	struct i2c_adapter		adap;
84 	struct netup_unidvb_dev		*dev;
85 	struct netup_i2c_regs __iomem	*regs;
86 	struct i2c_msg			*msg;
87 	enum netup_i2c_state		state;
88 	u32				xmit_size;
89 };
90 
91 struct netup_ci_state {
92 	struct dvb_ca_en50221		ca;
93 	u8 __iomem			*membase8_config;
94 	u8 __iomem			*membase8_io;
95 	struct netup_unidvb_dev		*dev;
96 	int status;
97 	int nr;
98 };
99 
100 struct netup_spi;
101 
102 struct netup_unidvb_dev {
103 	struct pci_dev			*pci_dev;
104 	int				pci_bus;
105 	int				pci_slot;
106 	int				pci_func;
107 	int				board_num;
108 	int				old_fw;
109 	u32 __iomem			*lmmio0;
110 	u8 __iomem			*bmmio0;
111 	u32 __iomem			*lmmio1;
112 	u8 __iomem			*bmmio1;
113 	u8				*dma_virt;
114 	dma_addr_t			dma_phys;
115 	u32				dma_size;
116 	struct vb2_dvb_frontends	frontends[2];
117 	struct netup_i2c		i2c[2];
118 	struct workqueue_struct		*wq;
119 	struct netup_dma		dma[2];
120 	struct netup_ci_state		ci[2];
121 	struct netup_spi		*spi;
122 	enum netup_hw_rev		rev;
123 };
124 
125 int netup_i2c_register(struct netup_unidvb_dev *ndev);
126 void netup_i2c_unregister(struct netup_unidvb_dev *ndev);
127 irqreturn_t netup_ci_interrupt(struct netup_unidvb_dev *ndev);
128 irqreturn_t netup_i2c_interrupt(struct netup_i2c *i2c);
129 irqreturn_t netup_spi_interrupt(struct netup_spi *spi);
130 int netup_unidvb_ci_register(struct netup_unidvb_dev *dev,
131 			     int num, struct pci_dev *pci_dev);
132 void netup_unidvb_ci_unregister(struct netup_unidvb_dev *dev, int num);
133 int netup_spi_init(struct netup_unidvb_dev *ndev);
134 void netup_spi_release(struct netup_unidvb_dev *ndev);
135