0001
0002
0003
0004
0005
0006
0007
0008 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0009
0010 #include <linux/bitops.h>
0011 #include <linux/usb.h>
0012 #include <linux/i2c.h>
0013 #include <linux/i2c-algo-bit.h>
0014 #include <media/tveeprom.h>
0015
0016
0017 #include <linux/videodev2.h>
0018 #include <media/videobuf2-v4l2.h>
0019 #include <media/videobuf2-vmalloc.h>
0020 #include <media/v4l2-device.h>
0021 #include <media/v4l2-ctrls.h>
0022 #include <media/v4l2-fh.h>
0023 #include <media/media-device.h>
0024 #include <media/media-dev-allocator.h>
0025
0026
0027 #include <media/demux.h>
0028 #include <media/dmxdev.h>
0029 #include <media/dvb_demux.h>
0030 #include <media/dvb_frontend.h>
0031 #include <media/dvb_net.h>
0032 #include <media/dvbdev.h>
0033
0034 #include "au0828-reg.h"
0035 #include "au0828-cards.h"
0036
0037 #define URB_COUNT 16
0038 #define URB_BUFSIZE (0xe522)
0039
0040
0041 #define NTSC_STD_W 720
0042 #define NTSC_STD_H 480
0043
0044 #define AU0828_INTERLACED_DEFAULT 1
0045
0046
0047 #define AU0828_MAX_ISO_BUFS 12
0048 #define AU0828_ISO_PACKETS_PER_URB 128
0049
0050 #define AU0828_MIN_BUF 4
0051 #define AU0828_DEF_BUF 8
0052
0053 #define AU0828_MAX_INPUT 4
0054
0055
0056 #define AU0828_RESOURCE_VIDEO 0x01
0057 #define AU0828_RESOURCE_VBI 0x02
0058
0059 enum au0828_itype {
0060 AU0828_VMUX_UNDEFINED = 0,
0061 AU0828_VMUX_COMPOSITE,
0062 AU0828_VMUX_SVIDEO,
0063 AU0828_VMUX_CABLE,
0064 AU0828_VMUX_TELEVISION,
0065 AU0828_VMUX_DVB,
0066 };
0067
0068 struct au0828_input {
0069 enum au0828_itype type;
0070 unsigned int vmux;
0071 unsigned int amux;
0072 void (*audio_setup) (void *priv, int enable);
0073 };
0074
0075 struct au0828_board {
0076 char *name;
0077 unsigned int tuner_type;
0078 unsigned char tuner_addr;
0079 unsigned char i2c_clk_divider;
0080 unsigned char has_ir_i2c:1;
0081 unsigned char has_analog:1;
0082 struct au0828_input input[AU0828_MAX_INPUT];
0083 };
0084
0085 struct au0828_dvb {
0086 struct mutex lock;
0087 struct dvb_adapter adapter;
0088 struct dvb_frontend *frontend;
0089 struct dvb_demux demux;
0090 struct dmxdev dmxdev;
0091 struct dmx_frontend fe_hw;
0092 struct dmx_frontend fe_mem;
0093 struct dvb_net net;
0094 int feeding;
0095 int start_count;
0096 int stop_count;
0097
0098 int (*set_frontend)(struct dvb_frontend *fe);
0099 };
0100
0101 enum au0828_stream_state {
0102 STREAM_OFF,
0103 STREAM_INTERRUPT,
0104 STREAM_ON
0105 };
0106
0107 #define AUVI_INPUT(nr) (dev->board.input[nr])
0108
0109
0110 enum au0828_dev_state {
0111 DEV_INITIALIZED = 0,
0112 DEV_DISCONNECTED = 1,
0113 DEV_MISCONFIGURED = 2
0114 };
0115
0116 struct au0828_dev;
0117
0118 struct au0828_usb_isoc_ctl {
0119
0120 int max_pkt_size;
0121
0122
0123 int num_bufs;
0124
0125
0126 struct urb **urb;
0127
0128
0129 char **transfer_buffer;
0130
0131
0132 u8 cmd;
0133 int pos, size, pktsize;
0134
0135
0136 int field;
0137
0138
0139 u32 tmp_buf;
0140 int tmp_buf_len;
0141
0142
0143 struct au0828_buffer *buf;
0144 struct au0828_buffer *vbi_buf;
0145
0146
0147 int nfields;
0148
0149
0150 int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb);
0151
0152 };
0153
0154
0155 struct au0828_buffer {
0156
0157 struct vb2_v4l2_buffer vb;
0158 struct list_head list;
0159
0160 void *mem;
0161 unsigned long length;
0162 int top_field;
0163
0164 char *vb_buf;
0165 };
0166
0167 struct au0828_dmaqueue {
0168 struct list_head active;
0169
0170 int pos;
0171 };
0172
0173 struct au0828_dev {
0174 struct mutex mutex;
0175 struct usb_device *usbdev;
0176 int boardnr;
0177 struct au0828_board board;
0178 u8 ctrlmsg[64];
0179
0180
0181 struct i2c_adapter i2c_adap;
0182 struct i2c_algorithm i2c_algo;
0183 struct i2c_client i2c_client;
0184 u32 i2c_rc;
0185
0186
0187 struct au0828_dvb dvb;
0188 struct work_struct restart_streaming;
0189 struct timer_list bulk_timeout;
0190 int bulk_timeout_running;
0191
0192 #ifdef CONFIG_VIDEO_AU0828_V4L2
0193
0194 struct v4l2_device v4l2_dev;
0195 struct v4l2_ctrl_handler v4l2_ctrl_hdl;
0196 #endif
0197 #ifdef CONFIG_VIDEO_AU0828_RC
0198 struct au0828_rc *ir;
0199 #endif
0200
0201 struct video_device vdev;
0202 struct video_device vbi_dev;
0203
0204
0205 struct vb2_queue vb_vidq;
0206 struct vb2_queue vb_vbiq;
0207 struct mutex vb_queue_lock;
0208 struct mutex vb_vbi_queue_lock;
0209
0210 unsigned int frame_count;
0211 unsigned int vbi_frame_count;
0212
0213 struct timer_list vid_timeout;
0214 int vid_timeout_running;
0215 struct timer_list vbi_timeout;
0216 int vbi_timeout_running;
0217
0218 int users;
0219 int streaming_users;
0220
0221 int width;
0222 int height;
0223 int vbi_width;
0224 int vbi_height;
0225 u32 vbi_read;
0226 v4l2_std_id std;
0227 u32 field_size;
0228 u32 frame_size;
0229 u32 bytesperline;
0230 int type;
0231 u8 ctrl_ainput;
0232 __u8 isoc_in_endpointaddr;
0233 u8 isoc_init_ok;
0234 int greenscreen_detected;
0235 int ctrl_freq;
0236 int input_type;
0237 int std_set_in_tuner_core;
0238 unsigned int ctrl_input;
0239 long unsigned int dev_state; ;
0240 enum au0828_stream_state stream_state;
0241 wait_queue_head_t open;
0242
0243 struct mutex lock;
0244
0245
0246 struct au0828_dmaqueue vidq;
0247 struct au0828_dmaqueue vbiq;
0248 struct au0828_usb_isoc_ctl isoc_ctl;
0249 spinlock_t slock;
0250
0251
0252 int alt;
0253 int max_pkt_size;
0254 int num_alt;
0255 unsigned int *alt_max_pkt_size;
0256 struct urb *urb[AU0828_MAX_ISO_BUFS];
0257 char *transfer_buffer[AU0828_MAX_ISO_BUFS];
0258
0259
0260
0261 bool urb_streaming, need_urb_start;
0262 struct urb *urbs[URB_COUNT];
0263
0264
0265
0266 char *dig_transfer_buffer[URB_COUNT];
0267
0268 #ifdef CONFIG_MEDIA_CONTROLLER
0269 struct media_device *media_dev;
0270 struct media_pad video_pad, vbi_pad;
0271 struct media_entity *decoder;
0272 struct media_entity input_ent[AU0828_MAX_INPUT];
0273 struct media_pad input_pad[AU0828_MAX_INPUT];
0274 struct media_entity_notify entity_notify;
0275 struct media_entity *tuner;
0276 struct media_link *active_link;
0277 struct media_entity *active_source;
0278 struct media_entity *active_sink;
0279 struct media_entity *active_link_owner;
0280 struct media_entity *active_link_user;
0281 struct media_pipeline *active_link_user_pipe;
0282 bool active_link_shared;
0283 #endif
0284 };
0285
0286
0287
0288 #define au0828_read(dev, reg) au0828_readreg(dev, reg)
0289 #define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
0290 #define au0828_andor(dev, reg, mask, value) \
0291 au0828_writereg(dev, reg, \
0292 (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
0293
0294 #define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
0295 #define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
0296
0297
0298
0299 extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
0300 extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
0301 extern void au0828_usb_release(struct au0828_dev *dev);
0302 extern int au0828_debug;
0303
0304
0305
0306 extern struct au0828_board au0828_boards[];
0307 extern struct usb_device_id au0828_usb_id_table[];
0308 extern void au0828_gpio_setup(struct au0828_dev *dev);
0309 extern int au0828_tuner_callback(void *priv, int component,
0310 int command, int arg);
0311 extern void au0828_card_setup(struct au0828_dev *dev);
0312
0313
0314
0315 extern int au0828_i2c_register(struct au0828_dev *dev);
0316 extern int au0828_i2c_unregister(struct au0828_dev *dev);
0317
0318
0319
0320 extern int au0828_start_analog_streaming(struct vb2_queue *vq,
0321 unsigned int count);
0322 extern void au0828_stop_vbi_streaming(struct vb2_queue *vq);
0323 #ifdef CONFIG_VIDEO_AU0828_V4L2
0324 extern int au0828_v4l2_device_register(struct usb_interface *interface,
0325 struct au0828_dev *dev);
0326
0327 extern int au0828_analog_register(struct au0828_dev *dev,
0328 struct usb_interface *interface);
0329 extern int au0828_analog_unregister(struct au0828_dev *dev);
0330 extern void au0828_usb_v4l2_media_release(struct au0828_dev *dev);
0331 extern void au0828_v4l2_suspend(struct au0828_dev *dev);
0332 extern void au0828_v4l2_resume(struct au0828_dev *dev);
0333 #else
0334 static inline int au0828_v4l2_device_register(struct usb_interface *interface,
0335 struct au0828_dev *dev)
0336 { return 0; };
0337 static inline int au0828_analog_register(struct au0828_dev *dev,
0338 struct usb_interface *interface)
0339 { return 0; };
0340 static inline int au0828_analog_unregister(struct au0828_dev *dev)
0341 { return 0; };
0342 static inline void au0828_usb_v4l2_media_release(struct au0828_dev *dev) { };
0343 static inline void au0828_v4l2_suspend(struct au0828_dev *dev) { };
0344 static inline void au0828_v4l2_resume(struct au0828_dev *dev) { };
0345 #endif
0346
0347
0348
0349 extern int au0828_dvb_register(struct au0828_dev *dev);
0350 extern void au0828_dvb_unregister(struct au0828_dev *dev);
0351 void au0828_dvb_suspend(struct au0828_dev *dev);
0352 void au0828_dvb_resume(struct au0828_dev *dev);
0353
0354
0355 extern const struct vb2_ops au0828_vbi_qops;
0356
0357 #define dprintk(level, fmt, arg...)\
0358 do { if (au0828_debug & level)\
0359 printk(KERN_DEBUG pr_fmt(fmt), ## arg);\
0360 } while (0)
0361
0362
0363 #ifdef CONFIG_VIDEO_AU0828_RC
0364 extern int au0828_rc_register(struct au0828_dev *dev);
0365 extern void au0828_rc_unregister(struct au0828_dev *dev);
0366 extern int au0828_rc_suspend(struct au0828_dev *dev);
0367 extern int au0828_rc_resume(struct au0828_dev *dev);
0368 #else
0369 static inline int au0828_rc_register(struct au0828_dev *dev) { return 0; }
0370 static inline void au0828_rc_unregister(struct au0828_dev *dev) { }
0371 static inline int au0828_rc_suspend(struct au0828_dev *dev) { return 0; }
0372 static inline int au0828_rc_resume(struct au0828_dev *dev) { return 0; }
0373 #endif