Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * tm6000.h - driver for TM5600/TM6000/TM6010 USB video capture devices
0004  *
0005  * Copyright (c) 2006-2007 Mauro Carvalho Chehab <mchehab@kernel.org>
0006  *
0007  * Copyright (c) 2007 Michel Ludwig <michel.ludwig@gmail.com>
0008  *  - DVB-T support
0009  */
0010 
0011 #include <linux/videodev2.h>
0012 #include <media/v4l2-common.h>
0013 #include <media/videobuf-vmalloc.h>
0014 #include "tm6000-usb-isoc.h"
0015 #include <linux/i2c.h>
0016 #include <linux/mutex.h>
0017 #include <media/v4l2-device.h>
0018 #include <media/v4l2-ctrls.h>
0019 #include <media/v4l2-fh.h>
0020 
0021 #include <linux/dvb/frontend.h>
0022 #include <media/dvb_demux.h>
0023 #include <media/dvb_frontend.h>
0024 #include <media/dmxdev.h>
0025 
0026 /* Inputs */
0027 enum tm6000_itype {
0028     TM6000_INPUT_TV = 1,
0029     TM6000_INPUT_COMPOSITE1,
0030     TM6000_INPUT_COMPOSITE2,
0031     TM6000_INPUT_SVIDEO,
0032     TM6000_INPUT_DVB,
0033     TM6000_INPUT_RADIO,
0034 };
0035 
0036 enum tm6000_mux {
0037     TM6000_VMUX_VIDEO_A = 1,
0038     TM6000_VMUX_VIDEO_B,
0039     TM6000_VMUX_VIDEO_AB,
0040     TM6000_AMUX_ADC1,
0041     TM6000_AMUX_ADC2,
0042     TM6000_AMUX_SIF1,
0043     TM6000_AMUX_SIF2,
0044     TM6000_AMUX_I2S,
0045 };
0046 
0047 enum tm6000_devtype {
0048     TM6000 = 0,
0049     TM5600,
0050     TM6010,
0051 };
0052 
0053 struct tm6000_input {
0054     enum tm6000_itype   type;
0055     enum tm6000_mux     vmux;
0056     enum tm6000_mux     amux;
0057     unsigned int        v_gpio;
0058     unsigned int        a_gpio;
0059 };
0060 
0061 /* ------------------------------------------------------------------
0062  *  Basic structures
0063  * ------------------------------------------------------------------
0064  */
0065 
0066 struct tm6000_fmt {
0067     u32   fourcc;          /* v4l2 format id */
0068     int   depth;
0069 };
0070 
0071 /* buffer for one video frame */
0072 struct tm6000_buffer {
0073     /* common v4l buffer stuff -- must be first */
0074     struct videobuf_buffer vb;
0075 
0076     struct tm6000_fmt      *fmt;
0077 };
0078 
0079 struct tm6000_dmaqueue {
0080     struct list_head       active;
0081     struct list_head       queued;
0082 
0083     /* thread for generating video stream*/
0084     struct task_struct         *kthread;
0085     wait_queue_head_t          wq;
0086     /* Counters to control fps rate */
0087     int                        frame;
0088     int                        ini_jiffies;
0089 };
0090 
0091 /* device states */
0092 enum tm6000_core_state {
0093     DEV_INITIALIZED   = 0x01,
0094     DEV_DISCONNECTED  = 0x02,
0095     DEV_MISCONFIGURED = 0x04,
0096 };
0097 
0098 /* io methods */
0099 enum tm6000_io_method {
0100     IO_NONE,
0101     IO_READ,
0102     IO_MMAP,
0103 };
0104 
0105 enum tm6000_mode {
0106     TM6000_MODE_UNKNOWN = 0,
0107     TM6000_MODE_ANALOG,
0108     TM6000_MODE_DIGITAL,
0109 };
0110 
0111 struct tm6000_gpio {
0112     int     tuner_reset;
0113     int     tuner_on;
0114     int     demod_reset;
0115     int     demod_on;
0116     int     power_led;
0117     int     dvb_led;
0118     int     ir;
0119 };
0120 
0121 struct tm6000_capabilities {
0122     unsigned int    has_tuner:1;
0123     unsigned int    has_tda9874:1;
0124     unsigned int    has_dvb:1;
0125     unsigned int    has_zl10353:1;
0126     unsigned int    has_eeprom:1;
0127     unsigned int    has_remote:1;
0128     unsigned int    has_radio:1;
0129 };
0130 
0131 struct tm6000_dvb {
0132     struct dvb_adapter  adapter;
0133     struct dvb_demux    demux;
0134     struct dvb_frontend *frontend;
0135     struct dmxdev       dmxdev;
0136     unsigned int        streams;
0137     struct urb      *bulk_urb;
0138     struct mutex        mutex;
0139 };
0140 
0141 struct snd_tm6000_card {
0142     struct snd_card         *card;
0143     spinlock_t          reg_lock;
0144     struct tm6000_core      *core;
0145     struct snd_pcm_substream    *substream;
0146 
0147     /* temporary data for buffer fill processing */
0148     unsigned            buf_pos;
0149     unsigned            period_pos;
0150 };
0151 
0152 struct tm6000_endpoint {
0153     struct usb_host_endpoint    *endp;
0154     __u8                bInterfaceNumber;
0155     __u8                bAlternateSetting;
0156     unsigned            maxsize;
0157 };
0158 
0159 #define TM6000_QUIRK_NO_USB_DELAY (1 << 0)
0160 
0161 struct tm6000_core {
0162     /* generic device properties */
0163     char                name[30];   /* name (including minor) of the device */
0164     int             model;      /* index in the device_data struct */
0165     int             devno;      /* marks the number of this device */
0166     enum tm6000_devtype     dev_type;   /* type of device */
0167     unsigned char           eedata[256];    /* Eeprom data */
0168     unsigned            eedata_size;    /* Size of the eeprom info */
0169 
0170     v4l2_std_id                     norm;           /* Current norm */
0171     int             width, height;  /* Selected resolution */
0172 
0173     enum tm6000_core_state      state;
0174 
0175     /* Device Capabilities*/
0176     struct tm6000_capabilities  caps;
0177 
0178     /* Used to load alsa/dvb */
0179     struct work_struct      request_module_wk;
0180 
0181     /* Tuner configuration */
0182     int             tuner_type;     /* type of the tuner */
0183     int             tuner_addr;     /* tuner address */
0184 
0185     struct tm6000_gpio      gpio;
0186 
0187     char                *ir_codes;
0188 
0189     __u8                radio;
0190 
0191     /* Demodulator configuration */
0192     int             demod_addr; /* demodulator address */
0193 
0194     int             audio_bitrate;
0195     /* i2c i/o */
0196     struct i2c_adapter      i2c_adap;
0197     struct i2c_client       i2c_client;
0198 
0199 
0200     /* extension */
0201     struct list_head        devlist;
0202 
0203     /* video for linux */
0204     int             users;
0205 
0206     /* various device info */
0207     struct tm6000_fh        *resources; /* Points to fh that is streaming */
0208     bool                is_res_read;
0209 
0210     struct video_device     vfd;
0211     struct video_device     radio_dev;
0212     struct tm6000_dmaqueue      vidq;
0213     struct v4l2_device      v4l2_dev;
0214     struct v4l2_ctrl_handler    ctrl_handler;
0215     struct v4l2_ctrl_handler    radio_ctrl_handler;
0216 
0217     int             input;
0218     struct tm6000_input     vinput[3];  /* video input */
0219     struct tm6000_input     rinput;     /* radio input */
0220 
0221     int             freq;
0222     unsigned int            fourcc;
0223 
0224     enum tm6000_mode        mode;
0225 
0226     int             ctl_mute;             /* audio */
0227     int             ctl_volume;
0228     int             amode;
0229 
0230     /* DVB-T support */
0231     struct tm6000_dvb       *dvb;
0232 
0233     /* audio support */
0234     struct snd_tm6000_card      *adev;
0235     struct work_struct      wq_trigger;   /* Trigger to start/stop audio for alsa module */
0236     atomic_t            stream_started;  /* stream should be running if true */
0237 
0238     struct tm6000_IR        *ir;
0239 
0240     /* locks */
0241     struct mutex            lock;
0242     struct mutex            usb_lock;
0243 
0244     /* usb transfer */
0245     struct usb_device       *udev;      /* the usb device */
0246 
0247     struct tm6000_endpoint      bulk_in, bulk_out, isoc_in, isoc_out;
0248     struct tm6000_endpoint      int_in, int_out;
0249 
0250     /* scaler!=0 if scaler is active*/
0251     int             scaler;
0252 
0253         /* Isoc control struct */
0254     struct usb_isoc_ctl          isoc_ctl;
0255 
0256     spinlock_t                   slock;
0257 
0258     /* urb dma buffers */
0259     char                **urb_buffer;
0260     dma_addr_t          *urb_dma;
0261     unsigned int            urb_size;
0262 
0263     unsigned long quirks;
0264 };
0265 
0266 enum tm6000_ops_type {
0267     TM6000_AUDIO = 0x10,
0268     TM6000_DVB = 0x20,
0269 };
0270 
0271 struct tm6000_ops {
0272     struct list_head    next;
0273     char            *name;
0274     enum tm6000_ops_type    type;
0275     int (*init)(struct tm6000_core *);
0276     int (*fini)(struct tm6000_core *);
0277     int (*fillbuf)(struct tm6000_core *, char *buf, int size);
0278 };
0279 
0280 struct tm6000_fh {
0281     struct v4l2_fh           fh;
0282     struct tm6000_core           *dev;
0283     unsigned int                 radio;
0284 
0285     /* video capture */
0286     struct tm6000_fmt            *fmt;
0287     unsigned int                 width, height;
0288     struct videobuf_queue        vb_vidq;
0289 
0290     enum v4l2_buf_type           type;
0291 };
0292 
0293 #define TM6000_STD  (V4L2_STD_PAL|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|    \
0294             V4L2_STD_PAL_M|V4L2_STD_PAL_60|V4L2_STD_NTSC_M| \
0295             V4L2_STD_NTSC_M_JP|V4L2_STD_SECAM)
0296 
0297 /* In tm6000-cards.c */
0298 
0299 int tm6000_tuner_callback(void *ptr, int component, int command, int arg);
0300 int tm6000_xc5000_callback(void *ptr, int component, int command, int arg);
0301 int tm6000_cards_setup(struct tm6000_core *dev);
0302 void tm6000_flash_led(struct tm6000_core *dev, u8 state);
0303 
0304 /* In tm6000-core.c */
0305 
0306 int tm6000_read_write_usb(struct tm6000_core *dev, u8 reqtype, u8 req,
0307                u16 value, u16 index, u8 *buf, u16 len);
0308 int tm6000_get_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index);
0309 int tm6000_get_reg16(struct tm6000_core *dev, u8 req, u16 value, u16 index);
0310 int tm6000_get_reg32(struct tm6000_core *dev, u8 req, u16 value, u16 index);
0311 int tm6000_set_reg(struct tm6000_core *dev, u8 req, u16 value, u16 index);
0312 int tm6000_set_reg_mask(struct tm6000_core *dev, u8 req, u16 value,
0313                         u16 index, u16 mask);
0314 int tm6000_i2c_reset(struct tm6000_core *dev, u16 tsleep);
0315 int tm6000_init(struct tm6000_core *dev);
0316 int tm6000_reset(struct tm6000_core *dev);
0317 
0318 int tm6000_init_analog_mode(struct tm6000_core *dev);
0319 int tm6000_init_digital_mode(struct tm6000_core *dev);
0320 int tm6000_set_audio_bitrate(struct tm6000_core *dev, int bitrate);
0321 int tm6000_set_audio_rinput(struct tm6000_core *dev);
0322 int tm6000_tvaudio_set_mute(struct tm6000_core *dev, u8 mute);
0323 void tm6000_set_volume(struct tm6000_core *dev, int vol);
0324 
0325 int tm6000_v4l2_register(struct tm6000_core *dev);
0326 int tm6000_v4l2_unregister(struct tm6000_core *dev);
0327 int tm6000_v4l2_exit(void);
0328 void tm6000_set_fourcc_format(struct tm6000_core *dev);
0329 
0330 void tm6000_remove_from_devlist(struct tm6000_core *dev);
0331 void tm6000_add_into_devlist(struct tm6000_core *dev);
0332 int tm6000_register_extension(struct tm6000_ops *ops);
0333 void tm6000_unregister_extension(struct tm6000_ops *ops);
0334 void tm6000_init_extension(struct tm6000_core *dev);
0335 void tm6000_close_extension(struct tm6000_core *dev);
0336 int tm6000_call_fillbuf(struct tm6000_core *dev, enum tm6000_ops_type type,
0337             char *buf, int size);
0338 
0339 
0340 /* In tm6000-stds.c */
0341 void tm6000_get_std_res(struct tm6000_core *dev);
0342 int tm6000_set_standard(struct tm6000_core *dev);
0343 
0344 /* In tm6000-i2c.c */
0345 int tm6000_i2c_register(struct tm6000_core *dev);
0346 int tm6000_i2c_unregister(struct tm6000_core *dev);
0347 
0348 /* In tm6000-queue.c */
0349 
0350 int tm6000_v4l2_mmap(struct file *filp, struct vm_area_struct *vma);
0351 
0352 int tm6000_vidioc_streamon(struct file *file, void *priv,
0353                enum v4l2_buf_type i);
0354 int tm6000_vidioc_streamoff(struct file *file, void *priv,
0355                 enum v4l2_buf_type i);
0356 int tm6000_vidioc_reqbufs(struct file *file, void *priv,
0357               struct v4l2_requestbuffers *rb);
0358 int tm6000_vidioc_querybuf(struct file *file, void *priv,
0359                struct v4l2_buffer *b);
0360 int tm6000_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b);
0361 int tm6000_vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b);
0362 ssize_t tm6000_v4l2_read(struct file *filp, char __user * buf, size_t count,
0363              loff_t *f_pos);
0364 unsigned int tm6000_v4l2_poll(struct file *file,
0365                   struct poll_table_struct *wait);
0366 int tm6000_queue_init(struct tm6000_core *dev);
0367 
0368 /* In tm6000-alsa.c */
0369 /*int tm6000_audio_init(struct tm6000_core *dev, int idx);*/
0370 
0371 /* In tm6000-input.c */
0372 int tm6000_ir_init(struct tm6000_core *dev);
0373 int tm6000_ir_fini(struct tm6000_core *dev);
0374 void tm6000_ir_wait(struct tm6000_core *dev, u8 state);
0375 int tm6000_ir_int_start(struct tm6000_core *dev);
0376 void tm6000_ir_int_stop(struct tm6000_core *dev);
0377 
0378 /* Debug stuff */
0379 
0380 extern int tm6000_debug;
0381 
0382 #define dprintk(dev, level, fmt, arg...) do {\
0383     if (tm6000_debug & level) \
0384         printk(KERN_INFO "(%lu) %s %s :"fmt, jiffies, \
0385              dev->name, __func__ , ##arg); } while (0)
0386 
0387 #define V4L2_DEBUG_REG      0x0004
0388 #define V4L2_DEBUG_I2C      0x0008
0389 #define V4L2_DEBUG_QUEUE    0x0010
0390 #define V4L2_DEBUG_ISOC     0x0020
0391 #define V4L2_DEBUG_RES_LOCK 0x0040  /* Resource locking */
0392 #define V4L2_DEBUG_OPEN     0x0080  /* video open/close debug */
0393 
0394 #define tm6000_err(fmt, arg...) do {\
0395     printk(KERN_ERR "tm6000 %s :"fmt, \
0396         __func__ , ##arg); } while (0)