0001
0002 #ifndef _DVB_USB_CXUSB_H_
0003 #define _DVB_USB_CXUSB_H_
0004
0005 #include <linux/completion.h>
0006 #include <linux/i2c.h>
0007 #include <linux/list.h>
0008 #include <linux/mutex.h>
0009 #include <linux/usb.h>
0010 #include <linux/workqueue.h>
0011 #include <media/v4l2-common.h>
0012 #include <media/v4l2-dev.h>
0013 #include <media/v4l2-device.h>
0014 #include <media/videobuf2-core.h>
0015 #include <media/videobuf2-v4l2.h>
0016
0017 #define DVB_USB_LOG_PREFIX "cxusb"
0018 #include "dvb-usb.h"
0019
0020 #define CXUSB_VIDEO_URBS (5)
0021 #define CXUSB_VIDEO_URB_MAX_SIZE (512 * 1024)
0022
0023 #define CXUSB_VIDEO_PKT_SIZE 3030
0024 #define CXUSB_VIDEO_MAX_FRAME_PKTS 346
0025 #define CXUSB_VIDEO_MAX_FRAME_SIZE (CXUSB_VIDEO_MAX_FRAME_PKTS * \
0026 CXUSB_VIDEO_PKT_SIZE)
0027
0028
0029 #define CMD_BLUEBIRD_GPIO_RW 0x05
0030
0031 #define CMD_I2C_WRITE 0x08
0032 #define CMD_I2C_READ 0x09
0033
0034 #define CMD_GPIO_READ 0x0d
0035 #define CMD_GPIO_WRITE 0x0e
0036 #define GPIO_TUNER 0x02
0037
0038 #define CMD_POWER_OFF 0xdc
0039 #define CMD_POWER_ON 0xde
0040
0041 #define CMD_STREAMING_ON 0x36
0042 #define CMD_STREAMING_OFF 0x37
0043
0044 #define CMD_AVER_STREAM_ON 0x18
0045 #define CMD_AVER_STREAM_OFF 0x19
0046
0047 #define CMD_GET_IR_CODE 0x47
0048
0049 #define CMD_ANALOG 0x50
0050 #define CMD_DIGITAL 0x51
0051
0052 #define CXUSB_BT656_PREAMBLE ((const u8 *)"\xff\x00\x00")
0053
0054 #define CXUSB_BT656_FIELD_MASK BIT(6)
0055 #define CXUSB_BT656_FIELD_1 0
0056 #define CXUSB_BT656_FIELD_2 BIT(6)
0057
0058 #define CXUSB_BT656_VBI_MASK BIT(5)
0059 #define CXUSB_BT656_VBI_ON BIT(5)
0060 #define CXUSB_BT656_VBI_OFF 0
0061
0062 #define CXUSB_BT656_SEAV_MASK BIT(4)
0063 #define CXUSB_BT656_SEAV_EAV BIT(4)
0064 #define CXUSB_BT656_SEAV_SAV 0
0065
0066
0067 #define MAX_XFER_SIZE 80
0068
0069 struct cxusb_state {
0070 u8 gpio_write_state[3];
0071 bool gpio_write_refresh[3];
0072 struct i2c_client *i2c_client_demod;
0073 struct i2c_client *i2c_client_tuner;
0074
0075 unsigned char data[MAX_XFER_SIZE];
0076
0077 struct mutex stream_mutex;
0078 u8 last_lock;
0079 int (*fe_read_status)(struct dvb_frontend *fe,
0080 enum fe_status *status);
0081 };
0082
0083 enum cxusb_open_type {
0084 CXUSB_OPEN_INIT,
0085 CXUSB_OPEN_NONE,
0086 CXUSB_OPEN_ANALOG,
0087 CXUSB_OPEN_DIGITAL
0088 };
0089
0090 struct cxusb_medion_auxbuf {
0091 u8 *buf;
0092 unsigned int len;
0093 unsigned int paylen;
0094 };
0095
0096 enum cxusb_bt656_mode {
0097 NEW_FRAME, FIRST_FIELD, SECOND_FIELD
0098 };
0099
0100 enum cxusb_bt656_fmode {
0101 START_SEARCH, LINE_SAMPLES, VBI_SAMPLES
0102 };
0103
0104 struct cxusb_bt656_params {
0105 enum cxusb_bt656_mode mode;
0106 enum cxusb_bt656_fmode fmode;
0107 unsigned int pos;
0108 unsigned int line;
0109 unsigned int linesamples;
0110 u8 *buf;
0111 };
0112
0113 struct cxusb_medion_dev {
0114
0115 struct cxusb_state state;
0116
0117 struct dvb_usb_device *dvbdev;
0118
0119 enum cxusb_open_type open_type;
0120 unsigned int open_ctr;
0121 struct mutex open_lock;
0122
0123 #ifdef CONFIG_DVB_USB_CXUSB_ANALOG
0124 struct v4l2_device v4l2dev;
0125 struct v4l2_subdev *cx25840;
0126 struct v4l2_subdev *tuner;
0127 struct v4l2_subdev *tda9887;
0128 struct video_device *videodev, *radiodev;
0129 struct mutex dev_lock;
0130
0131 struct vb2_queue videoqueue;
0132 u32 input;
0133 bool stop_streaming;
0134 u32 width, height;
0135 u32 field_order;
0136 struct cxusb_medion_auxbuf auxbuf;
0137 v4l2_std_id norm;
0138
0139 struct urb *streamurbs[CXUSB_VIDEO_URBS];
0140 unsigned long urbcomplete;
0141 struct work_struct urbwork;
0142 unsigned int nexturb;
0143
0144 struct cxusb_bt656_params bt656;
0145 struct cxusb_medion_vbuffer *vbuf;
0146 __u32 vbuf_sequence;
0147
0148 struct list_head buflist;
0149
0150 struct completion v4l2_release;
0151 #endif
0152 };
0153
0154 struct cxusb_medion_vbuffer {
0155 struct vb2_v4l2_buffer vb2;
0156 struct list_head list;
0157 };
0158
0159
0160 #define CXUSB_DBG_RC BIT(0)
0161 #define CXUSB_DBG_I2C BIT(1)
0162 #define CXUSB_DBG_MISC BIT(2)
0163 #define CXUSB_DBG_BT656 BIT(3)
0164 #define CXUSB_DBG_URB BIT(4)
0165 #define CXUSB_DBG_OPS BIT(5)
0166 #define CXUSB_DBG_AUXB BIT(6)
0167
0168 extern int dvb_usb_cxusb_debug;
0169
0170 #define cxusb_vprintk(dvbdev, lvl, ...) do { \
0171 struct cxusb_medion_dev *_cxdev = (dvbdev)->priv; \
0172 if (dvb_usb_cxusb_debug & CXUSB_DBG_##lvl) \
0173 v4l2_printk(KERN_DEBUG, \
0174 &_cxdev->v4l2dev, __VA_ARGS__); \
0175 } while (0)
0176
0177 int cxusb_ctrl_msg(struct dvb_usb_device *d,
0178 u8 cmd, const u8 *wbuf, int wlen, u8 *rbuf, int rlen);
0179
0180 #ifdef CONFIG_DVB_USB_CXUSB_ANALOG
0181 int cxusb_medion_analog_init(struct dvb_usb_device *dvbdev);
0182 int cxusb_medion_register_analog(struct dvb_usb_device *dvbdev);
0183 void cxusb_medion_unregister_analog(struct dvb_usb_device *dvbdev);
0184 #else
0185 static inline int cxusb_medion_analog_init(struct dvb_usb_device *dvbdev)
0186 {
0187 return -EINVAL;
0188 }
0189
0190 static inline int cxusb_medion_register_analog(struct dvb_usb_device *dvbdev)
0191 {
0192 return 0;
0193 }
0194
0195 static inline void cxusb_medion_unregister_analog(struct dvb_usb_device *dvbdev)
0196 {
0197 }
0198 #endif
0199
0200 int cxusb_medion_get(struct dvb_usb_device *dvbdev,
0201 enum cxusb_open_type open_type);
0202 void cxusb_medion_put(struct dvb_usb_device *dvbdev);
0203
0204 #endif