xref: /linux/drivers/media/pci/mantis/mantis_common.h (revision 9cebfe6504488198b012e746bc6b313f88b95439)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 	Mantis PCI bridge driver
4 
5 	Copyright (C) Manu Abraham (abraham.manu@gmail.com)
6 
7 */
8 
9 #ifndef __MANTIS_COMMON_H
10 #define __MANTIS_COMMON_H
11 
12 #include <linux/interrupt.h>
13 #include <linux/mutex.h>
14 #include <linux/workqueue.h>
15 
16 #include "mantis_reg.h"
17 #include "mantis_uart.h"
18 
19 #include "mantis_link.h"
20 
21 #define MANTIS_ERROR		0
22 #define MANTIS_NOTICE		1
23 #define MANTIS_INFO		2
24 #define MANTIS_DEBUG		3
25 #define MANTIS_TMG		9
26 
27 #define dprintk(y, z, format, arg...) do {								\
28 	if (z) {											\
29 		if	((mantis->verbose > MANTIS_ERROR) && (mantis->verbose > y))			\
30 			printk(KERN_ERR "%s (%d): " format "\n" , __func__ , mantis->num , ##arg);	\
31 		else if	((mantis->verbose > MANTIS_NOTICE) && (mantis->verbose > y))			\
32 			printk(KERN_NOTICE "%s (%d): " format "\n" , __func__ , mantis->num , ##arg);	\
33 		else if ((mantis->verbose > MANTIS_INFO) && (mantis->verbose > y))			\
34 			printk(KERN_INFO "%s (%d): " format "\n" , __func__ , mantis->num , ##arg);	\
35 		else if ((mantis->verbose > MANTIS_DEBUG) && (mantis->verbose > y))			\
36 			printk(KERN_DEBUG "%s (%d): " format "\n" , __func__ , mantis->num , ##arg);	\
37 		else if ((mantis->verbose > MANTIS_TMG) && (mantis->verbose > y))			\
38 			printk(KERN_DEBUG "%s (%d): " format "\n" , __func__ , mantis->num , ##arg);	\
39 	} else {											\
40 		if (mantis->verbose > y)								\
41 			printk(format , ##arg);								\
42 	}												\
43 } while(0)
44 
45 #define mwrite(dat, addr)	writel((dat), addr)
46 #define mread(addr)		readl(addr)
47 
48 #define mmwrite(dat, addr)	mwrite((dat), (mantis->mmio + (addr)))
49 #define mmread(addr)		mread(mantis->mmio + (addr))
50 
51 #define MANTIS_TS_188		0
52 #define MANTIS_TS_204		1
53 
54 #define TWINHAN_TECHNOLOGIES	0x1822
55 #define MANTIS			0x4e35
56 
57 #define TECHNISAT		0x1ae4
58 #define TERRATEC		0x153b
59 
60 #define MAKE_ENTRY(__subven, __subdev, __configptr, __rc) {		\
61 		PCI_DEVICE_SUB(TWINHAN_TECHNOLOGIES, MANTIS,		\
62 			       (__subven), (__subdev)),			\
63 		.driver_data = (unsigned long)				\
64 			&(struct mantis_pci_drvdata){__configptr, __rc}	\
65 }
66 
67 enum mantis_i2c_mode {
68 	MANTIS_PAGE_MODE = 0,
69 	MANTIS_BYTE_MODE,
70 };
71 
72 struct mantis_pci;
73 
74 struct mantis_hwconfig {
75 	char			*model_name;
76 	char			*dev_type;
77 	u32			ts_size;
78 
79 	enum mantis_baud	baud_rate;
80 	enum mantis_parity	parity;
81 	u32			bytes;
82 
83 	irqreturn_t (*irq_handler)(int irq, void *dev_id);
84 	int (*frontend_init)(struct mantis_pci *mantis, struct dvb_frontend *fe);
85 
86 	u8			power;
87 	u8			reset;
88 
89 	enum mantis_i2c_mode	i2c_mode;
90 };
91 
92 struct mantis_pci_drvdata {
93 	struct mantis_hwconfig *hwconfig;
94 	char *rc_map_name;
95 };
96 
97 struct mantis_pci {
98 	unsigned int		verbose;
99 
100 	/*	PCI stuff		*/
101 	u16			vendor_id;
102 	u16			device_id;
103 	u16			subsystem_vendor;
104 	u16			subsystem_device;
105 
106 	u8			latency;
107 
108 	struct pci_dev		*pdev;
109 
110 	unsigned long		mantis_addr;
111 	void __iomem		*mmio;
112 
113 	u8			irq;
114 	u8			revision;
115 
116 	unsigned int		num;
117 
118 	/*	RISC Core		*/
119 	u32			busy_block;
120 	u32			last_block;
121 	u8			*buf_cpu;
122 	dma_addr_t		buf_dma;
123 	__le32			*risc_cpu;
124 	dma_addr_t		risc_dma;
125 
126 	struct work_struct	bh_work;
127 	spinlock_t		intmask_lock;
128 
129 	struct i2c_adapter	adapter;
130 	int			i2c_rc;
131 	wait_queue_head_t	i2c_wq;
132 	struct mutex		i2c_lock;
133 
134 	/*	DVB stuff		*/
135 	struct dvb_adapter	dvb_adapter;
136 	struct dvb_frontend	*fe;
137 	struct dvb_demux	demux;
138 	struct dmxdev		dmxdev;
139 	struct dmx_frontend	fe_hw;
140 	struct dmx_frontend	fe_mem;
141 	struct dvb_net		dvbnet;
142 
143 	u8			feeds;
144 
145 	struct mantis_hwconfig	*hwconfig;
146 
147 	u32			mantis_int_stat;
148 	u32			mantis_int_mask;
149 
150 	/*	board specific		*/
151 	u8			mac_address[8];
152 	u32			sub_vendor_id;
153 	u32			sub_device_id;
154 
155 	 /*	A12 A13 A14		*/
156 	u32			gpio_status;
157 
158 	u32			gpif_status;
159 
160 	struct mantis_ca	*mantis_ca;
161 
162 	struct work_struct	uart_work;
163 
164 	struct rc_dev		*rc;
165 	char			device_name[80];
166 	char			input_phys[80];
167 	char			*rc_map_name;
168 };
169 
170 #define MANTIS_HIF_STATUS	(mantis->gpio_status)
171 
172 static inline void mantis_mask_ints(struct mantis_pci *mantis, u32 mask)
173 {
174 	unsigned long flags;
175 
176 	spin_lock_irqsave(&mantis->intmask_lock, flags);
177 	mmwrite(mmread(MANTIS_INT_MASK) & ~mask, MANTIS_INT_MASK);
178 	spin_unlock_irqrestore(&mantis->intmask_lock, flags);
179 }
180 
181 static inline void mantis_unmask_ints(struct mantis_pci *mantis, u32 mask)
182 {
183 	unsigned long flags;
184 
185 	spin_lock_irqsave(&mantis->intmask_lock, flags);
186 	mmwrite(mmread(MANTIS_INT_MASK) | mask, MANTIS_INT_MASK);
187 	spin_unlock_irqrestore(&mantis->intmask_lock, flags);
188 }
189 
190 #endif /* __MANTIS_COMMON_H */
191