xref: /openbmc/linux/drivers/media/usb/dvb-usb/cxusb.h (revision ead14a70754f8d7f5dbcb0553c7f11eb0fc4a6ac)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _DVB_USB_CXUSB_H_
3 #define _DVB_USB_CXUSB_H_
4 
5 #include <linux/completion.h>
6 #include <linux/i2c.h>
7 #include <linux/list.h>
8 #include <linux/mutex.h>
9 #include <linux/usb.h>
10 #include <linux/workqueue.h>
11 #include <media/v4l2-common.h>
12 #include <media/v4l2-dev.h>
13 #include <media/v4l2-device.h>
14 #include <media/videobuf2-core.h>
15 #include <media/videobuf2-v4l2.h>
16 
17 #define DVB_USB_LOG_PREFIX "cxusb"
18 #include "dvb-usb.h"
19 
20 #define CXUSB_VIDEO_URBS (5)
21 #define CXUSB_VIDEO_URB_MAX_SIZE (512 * 1024)
22 
23 #define CXUSB_VIDEO_PKT_SIZE 3030
24 #define CXUSB_VIDEO_MAX_FRAME_PKTS 346
25 #define CXUSB_VIDEO_MAX_FRAME_SIZE (CXUSB_VIDEO_MAX_FRAME_PKTS * \
26 					CXUSB_VIDEO_PKT_SIZE)
27 
28 /* usb commands - some of it are guesses, don't have a reference yet */
29 #define CMD_BLUEBIRD_GPIO_RW 0x05
30 
31 #define CMD_I2C_WRITE     0x08
32 #define CMD_I2C_READ      0x09
33 
34 #define CMD_GPIO_READ     0x0d
35 #define CMD_GPIO_WRITE    0x0e
36 #define     GPIO_TUNER         0x02
37 
38 #define CMD_POWER_OFF     0xdc
39 #define CMD_POWER_ON      0xde
40 
41 #define CMD_STREAMING_ON  0x36
42 #define CMD_STREAMING_OFF 0x37
43 
44 #define CMD_AVER_STREAM_ON  0x18
45 #define CMD_AVER_STREAM_OFF 0x19
46 
47 #define CMD_GET_IR_CODE   0x47
48 
49 #define CMD_ANALOG        0x50
50 #define CMD_DIGITAL       0x51
51 
52 #define CXUSB_BT656_PREAMBLE ((const u8 *)"\xff\x00\x00")
53 
54 #define CXUSB_BT656_FIELD_MASK BIT(6)
55 #define CXUSB_BT656_FIELD_1 0
56 #define CXUSB_BT656_FIELD_2 BIT(6)
57 
58 #define CXUSB_BT656_VBI_MASK BIT(5)
59 #define CXUSB_BT656_VBI_ON BIT(5)
60 #define CXUSB_BT656_VBI_OFF 0
61 
62 #define CXUSB_BT656_SEAV_MASK BIT(4)
63 #define CXUSB_BT656_SEAV_EAV BIT(4)
64 #define CXUSB_BT656_SEAV_SAV 0
65 
66 /* Max transfer size done by I2C transfer functions */
67 #define MAX_XFER_SIZE  80
68 
69 struct cxusb_state {
70 	u8 gpio_write_state[3];
71 	bool gpio_write_refresh[3];
72 	struct i2c_client *i2c_client_demod;
73 	struct i2c_client *i2c_client_tuner;
74 
75 	unsigned char data[MAX_XFER_SIZE];
76 
77 	struct mutex stream_mutex;
78 	u8 last_lock;
79 	int (*fe_read_status)(struct dvb_frontend *fe,
80 		enum fe_status *status);
81 };
82 
83 enum cxusb_open_type {
84 	CXUSB_OPEN_INIT, CXUSB_OPEN_NONE,
85 	CXUSB_OPEN_ANALOG, CXUSB_OPEN_DIGITAL
86 };
87 
88 struct cxusb_medion_auxbuf {
89 	u8 *buf;
90 	unsigned int len;
91 	unsigned int paylen;
92 };
93 
94 enum cxusb_bt656_mode {
95 	NEW_FRAME, FIRST_FIELD, SECOND_FIELD
96 };
97 
98 enum cxusb_bt656_fmode {
99 	START_SEARCH, LINE_SAMPLES, VBI_SAMPLES
100 };
101 
102 struct cxusb_bt656_params {
103 	enum cxusb_bt656_mode mode;
104 	enum cxusb_bt656_fmode fmode;
105 	unsigned int pos;
106 	unsigned int line;
107 	unsigned int linesamples;
108 	u8 *buf;
109 };
110 
111 struct cxusb_medion_dev {
112 	/* has to be the first one */
113 	struct cxusb_state state;
114 
115 	struct dvb_usb_device *dvbdev;
116 
117 	enum cxusb_open_type open_type;
118 	unsigned int open_ctr;
119 	struct mutex open_lock;
120 
121 #ifdef CONFIG_DVB_USB_CXUSB_ANALOG
122 	struct v4l2_device v4l2dev;
123 	struct v4l2_subdev *cx25840;
124 	struct v4l2_subdev *tuner;
125 	struct v4l2_subdev *tda9887;
126 	struct video_device *videodev, *radiodev;
127 	struct mutex dev_lock;
128 
129 	struct vb2_queue videoqueue;
130 	u32 input;
131 	bool stop_streaming;
132 	u32 width, height;
133 	u32 field_order;
134 	bool raw_mode;
135 	struct cxusb_medion_auxbuf auxbuf;
136 	v4l2_std_id norm;
137 
138 	struct urb *streamurbs[CXUSB_VIDEO_URBS];
139 	unsigned long urbcomplete;
140 	struct work_struct urbwork;
141 	unsigned int nexturb;
142 
143 	struct cxusb_bt656_params bt656;
144 	struct cxusb_medion_vbuffer *vbuf;
145 	__u32 vbuf_sequence;
146 
147 	struct list_head buflist;
148 
149 	struct completion v4l2_release;
150 #endif
151 };
152 
153 struct cxusb_medion_vbuffer {
154 	struct vb2_v4l2_buffer vb2;
155 	struct list_head list;
156 };
157 
158 /* Capture streaming parameters extendedmode field flags */
159 #define CXUSB_EXTENDEDMODE_CAPTURE_RAW 1
160 
161 /* defines for "debug" module parameter */
162 #define CXUSB_DBG_RC BIT(0)
163 #define CXUSB_DBG_I2C BIT(1)
164 #define CXUSB_DBG_MISC BIT(2)
165 #define CXUSB_DBG_BT656 BIT(3)
166 #define CXUSB_DBG_URB BIT(4)
167 #define CXUSB_DBG_OPS BIT(5)
168 #define CXUSB_DBG_AUXB BIT(6)
169 
170 extern int dvb_usb_cxusb_debug;
171 
172 #define cxusb_vprintk(dvbdev, lvl, ...) do {				\
173 		struct cxusb_medion_dev *_cxdev = (dvbdev)->priv;	\
174 		if (dvb_usb_cxusb_debug & CXUSB_DBG_##lvl)		\
175 			v4l2_printk(KERN_DEBUG,			\
176 				    &_cxdev->v4l2dev, __VA_ARGS__);	\
177 	} while (0)
178 
179 int cxusb_ctrl_msg(struct dvb_usb_device *d,
180 		   u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen);
181 
182 #ifdef CONFIG_DVB_USB_CXUSB_ANALOG
183 int cxusb_medion_analog_init(struct dvb_usb_device *dvbdev);
184 int cxusb_medion_register_analog(struct dvb_usb_device *dvbdev);
185 void cxusb_medion_unregister_analog(struct dvb_usb_device *dvbdev);
186 #else
187 static inline int cxusb_medion_analog_init(struct dvb_usb_device *dvbdev)
188 {
189 	return -EINVAL;
190 }
191 
192 static inline int cxusb_medion_register_analog(struct dvb_usb_device *dvbdev)
193 {
194 	return 0;
195 }
196 
197 static inline void cxusb_medion_unregister_analog(struct dvb_usb_device *dvbdev)
198 {
199 }
200 #endif
201 
202 int cxusb_medion_get(struct dvb_usb_device *dvbdev,
203 		     enum cxusb_open_type open_type);
204 void cxusb_medion_put(struct dvb_usb_device *dvbdev);
205 
206 #endif
207