1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _DVB_USB_CXUSB_H_
3 #define _DVB_USB_CXUSB_H_
5 #include <linux/completion.h>
7 #include <linux/list.h>
8 #include <linux/mutex.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>
17 #define DVB_USB_LOG_PREFIX "cxusb"
20 #define CXUSB_VIDEO_URBS (5)
21 #define CXUSB_VIDEO_URB_MAX_SIZE (512 * 1024)
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 * \
28 /* usb commands - some of it are guesses, don't have a reference yet */
29 #define CMD_BLUEBIRD_GPIO_RW 0x05
31 #define CMD_I2C_WRITE 0x08
32 #define CMD_I2C_READ 0x09
34 #define CMD_GPIO_READ 0x0d
35 #define CMD_GPIO_WRITE 0x0e
36 #define GPIO_TUNER 0x02
38 #define CMD_POWER_OFF 0xdc
39 #define CMD_POWER_ON 0xde
41 #define CMD_STREAMING_ON 0x36
42 #define CMD_STREAMING_OFF 0x37
44 #define CMD_AVER_STREAM_ON 0x18
45 #define CMD_AVER_STREAM_OFF 0x19
47 #define CMD_GET_IR_CODE 0x47
49 #define CMD_ANALOG 0x50
50 #define CMD_DIGITAL 0x51
52 #define CXUSB_BT656_PREAMBLE ((const u8 *)"\xff\x00\x00")
54 #define CXUSB_BT656_FIELD_MASK BIT(6)
55 #define CXUSB_BT656_FIELD_1 0
56 #define CXUSB_BT656_FIELD_2 BIT(6)
58 #define CXUSB_BT656_VBI_MASK BIT(5)
59 #define CXUSB_BT656_VBI_ON BIT(5)
60 #define CXUSB_BT656_VBI_OFF 0
62 #define CXUSB_BT656_SEAV_MASK BIT(4)
63 #define CXUSB_BT656_SEAV_EAV BIT(4)
64 #define CXUSB_BT656_SEAV_SAV 0
66 /* Max transfer size done by I2C transfer functions */
67 #define MAX_XFER_SIZE 80
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
;
75 unsigned char data
[MAX_XFER_SIZE
];
77 struct mutex stream_mutex
;
79 int (*fe_read_status
)(struct dvb_frontend
*fe
,
80 enum fe_status
*status
);
83 enum cxusb_open_type
{
90 struct cxusb_medion_auxbuf
{
96 enum cxusb_bt656_mode
{
97 NEW_FRAME
, FIRST_FIELD
, SECOND_FIELD
100 enum cxusb_bt656_fmode
{
101 START_SEARCH
, LINE_SAMPLES
, VBI_SAMPLES
104 struct cxusb_bt656_params
{
105 enum cxusb_bt656_mode mode
;
106 enum cxusb_bt656_fmode fmode
;
109 unsigned int linesamples
;
113 struct cxusb_medion_dev
{
114 /* has to be the first one */
115 struct cxusb_state state
;
117 struct dvb_usb_device
*dvbdev
;
119 enum cxusb_open_type open_type
;
120 unsigned int open_ctr
;
121 struct mutex open_lock
;
123 #ifdef CONFIG_DVB_USB_CXUSB_ANALOG
124 struct v4l2_device v4l2dev
;
125 struct v4l2_subdev
*cx25840
;
126 struct v4l2_subdev
*tuner
;
127 struct v4l2_subdev
*tda9887
;
128 struct video_device
*videodev
, *radiodev
;
129 struct mutex dev_lock
;
131 struct vb2_queue videoqueue
;
136 struct cxusb_medion_auxbuf auxbuf
;
139 struct urb
*streamurbs
[CXUSB_VIDEO_URBS
];
140 unsigned long urbcomplete
;
141 struct work_struct urbwork
;
142 unsigned int nexturb
;
144 struct cxusb_bt656_params bt656
;
145 struct cxusb_medion_vbuffer
*vbuf
;
148 struct list_head buflist
;
150 struct completion v4l2_release
;
154 struct cxusb_medion_vbuffer
{
155 struct vb2_v4l2_buffer vb2
;
156 struct list_head list
;
159 /* defines for "debug" module parameter */
160 #define CXUSB_DBG_RC BIT(0)
161 #define CXUSB_DBG_I2C BIT(1)
162 #define CXUSB_DBG_MISC BIT(2)
163 #define CXUSB_DBG_BT656 BIT(3)
164 #define CXUSB_DBG_URB BIT(4)
165 #define CXUSB_DBG_OPS BIT(5)
166 #define CXUSB_DBG_AUXB BIT(6)
168 extern int dvb_usb_cxusb_debug
;
170 #define cxusb_vprintk(dvbdev, lvl, ...) do { \
171 struct cxusb_medion_dev *_cxdev = (dvbdev)->priv; \
172 if (dvb_usb_cxusb_debug & CXUSB_DBG_##lvl) \
173 v4l2_printk(KERN_DEBUG, \
174 &_cxdev->v4l2dev, __VA_ARGS__); \
177 int cxusb_ctrl_msg(struct dvb_usb_device
*d
,
178 u8 cmd
, const u8
*wbuf
, int wlen
, u8
*rbuf
, int rlen
);
180 #ifdef CONFIG_DVB_USB_CXUSB_ANALOG
181 int cxusb_medion_analog_init(struct dvb_usb_device
*dvbdev
);
182 int cxusb_medion_register_analog(struct dvb_usb_device
*dvbdev
);
183 void cxusb_medion_unregister_analog(struct dvb_usb_device
*dvbdev
);
185 static inline int cxusb_medion_analog_init(struct dvb_usb_device
*dvbdev
)
190 static inline int cxusb_medion_register_analog(struct dvb_usb_device
*dvbdev
)
195 static inline void cxusb_medion_unregister_analog(struct dvb_usb_device
*dvbdev
)
200 int cxusb_medion_get(struct dvb_usb_device
*dvbdev
,
201 enum cxusb_open_type open_type
);
202 void cxusb_medion_put(struct dvb_usb_device
*dvbdev
);