1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 #include <linux/i2c.h>
  14 #include <sound/core.h>
  15 #include <sound/ac97_codec.h>
  16 #include <media/videobuf2-v4l2.h>
  17 #include <media/v4l2-device.h>
  18 #include <media/v4l2-ctrls.h>
  19 
  20 #define STK1160_VERSION         "0.9.5"
  21 #define STK1160_VERSION_NUM     0x000905
  22 
  23 
  24 #define STK1160_NUM_PACKETS 64
  25 
  26 
  27 #define STK1160_NUM_BUFS 16
  28 #define STK1160_MIN_BUFS 1
  29 
  30 
  31 #define STK1160_EP_VIDEO 0x82
  32 #define STK1160_EP_AUDIO 0x81
  33 
  34 
  35 #define STK1160_MIN_VIDEO_BUFFERS 8
  36 #define STK1160_MAX_VIDEO_BUFFERS 32
  37 
  38 #define STK1160_MIN_PKT_SIZE 3072
  39 
  40 #define STK1160_MAX_INPUT 4
  41 #define STK1160_SVIDEO_INPUT 4
  42 
  43 #define STK1160_AC97_TIMEOUT 50
  44 
  45 #define STK1160_I2C_TIMEOUT 100
  46 
  47 
  48 
  49 
  50 
  51 
  52 
  53 #ifdef DEBUG
  54 #define stk1160_dbg(fmt, args...) \
  55         printk(KERN_DEBUG "stk1160: " fmt,  ## args)
  56 #else
  57 #define stk1160_dbg(fmt, args...)
  58 #endif
  59 
  60 #define stk1160_info(fmt, args...) \
  61         pr_info("stk1160: " fmt, ## args)
  62 
  63 #define stk1160_warn(fmt, args...) \
  64         pr_warn("stk1160: " fmt, ## args)
  65 
  66 #define stk1160_err(fmt, args...) \
  67         pr_err("stk1160: " fmt, ## args)
  68 
  69 
  70 struct stk1160_buffer {
  71         
  72         struct vb2_v4l2_buffer vb;
  73         struct list_head list;
  74 
  75         void *mem;
  76         unsigned int length;            
  77         unsigned int bytesused;         
  78         int odd;                        
  79 
  80         
  81 
  82 
  83 
  84         unsigned int pos;               
  85 };
  86 
  87 struct stk1160_isoc_ctl {
  88         
  89         int max_pkt_size;
  90 
  91         
  92         int num_bufs;
  93 
  94         
  95         struct urb **urb;
  96 
  97         
  98         char **transfer_buffer;
  99 
 100         
 101         struct stk1160_buffer *buf;
 102 };
 103 
 104 struct stk1160_fmt {
 105         u32   fourcc;          
 106         int   depth;
 107 };
 108 
 109 struct stk1160 {
 110         struct v4l2_device v4l2_dev;
 111         struct video_device vdev;
 112         struct v4l2_ctrl_handler ctrl_handler;
 113 
 114         struct device *dev;
 115         struct usb_device *udev;
 116 
 117         
 118         struct v4l2_subdev *sd_saa7115;
 119 
 120         
 121         struct list_head avail_bufs;
 122 
 123         
 124         struct vb2_queue vb_vidq;
 125 
 126         
 127         int max_pkt_size;
 128         
 129         unsigned int *alt_max_pkt_size;
 130         
 131         int alt;
 132         
 133         int num_alt;
 134 
 135         struct stk1160_isoc_ctl isoc_ctl;
 136 
 137         
 138         int width;                
 139         int height;               
 140         unsigned int ctl_input;   
 141         v4l2_std_id norm;         
 142         struct stk1160_fmt *fmt;  
 143 
 144         unsigned int sequence;
 145 
 146         
 147         struct i2c_adapter i2c_adap;
 148         struct i2c_client i2c_client;
 149 
 150         struct mutex v4l_lock;
 151         struct mutex vb_queue_lock;
 152         spinlock_t buf_lock;
 153 
 154         struct file *fh_owner;  
 155 
 156         
 157         struct snd_card *snd_card;
 158 };
 159 
 160 struct regval {
 161         u16 reg;
 162         u16 val;
 163 };
 164 
 165 
 166 int stk1160_vb2_setup(struct stk1160 *dev);
 167 int stk1160_video_register(struct stk1160 *dev);
 168 void stk1160_video_unregister(struct stk1160 *dev);
 169 void stk1160_clear_queue(struct stk1160 *dev);
 170 
 171 
 172 int stk1160_alloc_isoc(struct stk1160 *dev);
 173 void stk1160_free_isoc(struct stk1160 *dev);
 174 void stk1160_cancel_isoc(struct stk1160 *dev);
 175 void stk1160_uninit_isoc(struct stk1160 *dev);
 176 
 177 
 178 int stk1160_i2c_register(struct stk1160 *dev);
 179 int stk1160_i2c_unregister(struct stk1160 *dev);
 180 
 181 
 182 int stk1160_read_reg(struct stk1160 *dev, u16 reg, u8 *value);
 183 int stk1160_write_reg(struct stk1160 *dev, u16 reg, u16 value);
 184 int stk1160_write_regs_req(struct stk1160 *dev, u8 req, u16 reg,
 185                 char *buf, int len);
 186 int stk1160_read_reg_req_len(struct stk1160 *dev, u8 req, u16 reg,
 187                 char *buf, int len);
 188 void stk1160_select_input(struct stk1160 *dev);
 189 
 190 
 191 void stk1160_ac97_setup(struct stk1160 *dev);