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, 85 CXUSB_OPEN_NONE, 86 CXUSB_OPEN_ANALOG, 87 CXUSB_OPEN_DIGITAL 88 }; 89 90 struct cxusb_medion_auxbuf { 91 u8 *buf; 92 unsigned int len; 93 unsigned int paylen; 94 }; 95 96 enum cxusb_bt656_mode { 97 NEW_FRAME, FIRST_FIELD, SECOND_FIELD 98 }; 99 100 enum cxusb_bt656_fmode { 101 START_SEARCH, LINE_SAMPLES, VBI_SAMPLES 102 }; 103 104 struct cxusb_bt656_params { 105 enum cxusb_bt656_mode mode; 106 enum cxusb_bt656_fmode fmode; 107 unsigned int pos; 108 unsigned int line; 109 unsigned int linesamples; 110 u8 *buf; 111 }; 112 113 struct cxusb_medion_dev { 114 /* has to be the first one */ 115 struct cxusb_state state; 116 117 struct dvb_usb_device *dvbdev; 118 119 enum cxusb_open_type open_type; 120 unsigned int open_ctr; 121 struct mutex open_lock; 122 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; 130 131 struct vb2_queue videoqueue; 132 u32 input; 133 bool stop_streaming; 134 u32 width, height; 135 u32 field_order; 136 struct cxusb_medion_auxbuf auxbuf; 137 v4l2_std_id norm; 138 139 struct urb *streamurbs[CXUSB_VIDEO_URBS]; 140 unsigned long urbcomplete; 141 struct work_struct urbwork; 142 unsigned int nexturb; 143 144 struct cxusb_bt656_params bt656; 145 struct cxusb_medion_vbuffer *vbuf; 146 __u32 vbuf_sequence; 147 148 struct list_head buflist; 149 150 struct completion v4l2_release; 151 #endif 152 }; 153 154 struct cxusb_medion_vbuffer { 155 struct vb2_v4l2_buffer vb2; 156 struct list_head list; 157 }; 158 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) 167 168 extern int dvb_usb_cxusb_debug; 169 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__); \ 175 } while (0) 176 177 int cxusb_ctrl_msg(struct dvb_usb_device *d, 178 u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen); 179 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); 184 #else 185 static inline int cxusb_medion_analog_init(struct dvb_usb_device *dvbdev) 186 { 187 return -EINVAL; 188 } 189 190 static inline int cxusb_medion_register_analog(struct dvb_usb_device *dvbdev) 191 { 192 return 0; 193 } 194 195 static inline void cxusb_medion_unregister_analog(struct dvb_usb_device *dvbdev) 196 { 197 } 198 #endif 199 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); 203 204 #endif 205