xref: /linux/drivers/media/pci/mantis/mantis_common.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
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 		.vendor		= TWINHAN_TECHNOLOGIES,			\
62 		.device		= MANTIS,				\
63 		.subvendor	= (__subven),				\
64 		.subdevice	= (__subdev),				\
65 		.driver_data	= (unsigned long)			\
66 			&(struct mantis_pci_drvdata){__configptr, __rc}	\
67 }
68 
69 enum mantis_i2c_mode {
70 	MANTIS_PAGE_MODE = 0,
71 	MANTIS_BYTE_MODE,
72 };
73 
74 struct mantis_pci;
75 
76 struct mantis_hwconfig {
77 	char			*model_name;
78 	char			*dev_type;
79 	u32			ts_size;
80 
81 	enum mantis_baud	baud_rate;
82 	enum mantis_parity	parity;
83 	u32			bytes;
84 
85 	irqreturn_t (*irq_handler)(int irq, void *dev_id);
86 	int (*frontend_init)(struct mantis_pci *mantis, struct dvb_frontend *fe);
87 
88 	u8			power;
89 	u8			reset;
90 
91 	enum mantis_i2c_mode	i2c_mode;
92 };
93 
94 struct mantis_pci_drvdata {
95 	struct mantis_hwconfig *hwconfig;
96 	char *rc_map_name;
97 };
98 
99 struct mantis_pci {
100 	unsigned int		verbose;
101 
102 	/*	PCI stuff		*/
103 	u16			vendor_id;
104 	u16			device_id;
105 	u16			subsystem_vendor;
106 	u16			subsystem_device;
107 
108 	u8			latency;
109 
110 	struct pci_dev		*pdev;
111 
112 	unsigned long		mantis_addr;
113 	void __iomem		*mmio;
114 
115 	u8			irq;
116 	u8			revision;
117 
118 	unsigned int		num;
119 
120 	/*	RISC Core		*/
121 	u32			busy_block;
122 	u32			last_block;
123 	u8			*buf_cpu;
124 	dma_addr_t		buf_dma;
125 	__le32			*risc_cpu;
126 	dma_addr_t		risc_dma;
127 
128 	struct work_struct	bh_work;
129 	spinlock_t		intmask_lock;
130 
131 	struct i2c_adapter	adapter;
132 	int			i2c_rc;
133 	wait_queue_head_t	i2c_wq;
134 	struct mutex		i2c_lock;
135 
136 	/*	DVB stuff		*/
137 	struct dvb_adapter	dvb_adapter;
138 	struct dvb_frontend	*fe;
139 	struct dvb_demux	demux;
140 	struct dmxdev		dmxdev;
141 	struct dmx_frontend	fe_hw;
142 	struct dmx_frontend	fe_mem;
143 	struct dvb_net		dvbnet;
144 
145 	u8			feeds;
146 
147 	struct mantis_hwconfig	*hwconfig;
148 
149 	u32			mantis_int_stat;
150 	u32			mantis_int_mask;
151 
152 	/*	board specific		*/
153 	u8			mac_address[8];
154 	u32			sub_vendor_id;
155 	u32			sub_device_id;
156 
157 	 /*	A12 A13 A14		*/
158 	u32			gpio_status;
159 
160 	u32			gpif_status;
161 
162 	struct mantis_ca	*mantis_ca;
163 
164 	struct work_struct	uart_work;
165 
166 	struct rc_dev		*rc;
167 	char			device_name[80];
168 	char			input_phys[80];
169 	char			*rc_map_name;
170 };
171 
172 #define MANTIS_HIF_STATUS	(mantis->gpio_status)
173 
mantis_mask_ints(struct mantis_pci * mantis,u32 mask)174 static inline void mantis_mask_ints(struct mantis_pci *mantis, u32 mask)
175 {
176 	unsigned long flags;
177 
178 	spin_lock_irqsave(&mantis->intmask_lock, flags);
179 	mmwrite(mmread(MANTIS_INT_MASK) & ~mask, MANTIS_INT_MASK);
180 	spin_unlock_irqrestore(&mantis->intmask_lock, flags);
181 }
182 
mantis_unmask_ints(struct mantis_pci * mantis,u32 mask)183 static inline void mantis_unmask_ints(struct mantis_pci *mantis, u32 mask)
184 {
185 	unsigned long flags;
186 
187 	spin_lock_irqsave(&mantis->intmask_lock, flags);
188 	mmwrite(mmread(MANTIS_INT_MASK) | mask, MANTIS_INT_MASK);
189 	spin_unlock_irqrestore(&mantis->intmask_lock, flags);
190 }
191 
192 #endif /* __MANTIS_COMMON_H */
193