4 * Copyright (C) 2012 Ezequiel Garcia
5 * <elezegarcia--a.t--gmail.com>
7 * Based on Easycap driver by R.M. Thomas
8 * Copyright (C) 2010 R.M. Thomas
9 * <rmthomas--a.t--sciolus.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
23 #include <linux/i2c.h>
24 #include <sound/core.h>
25 #include <sound/ac97_codec.h>
26 #include <media/videobuf2-core.h>
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-ctrls.h>
30 #define STK1160_VERSION "0.9.5"
31 #define STK1160_VERSION_NUM 0x000905
33 /* Decide on number of packets for each buffer */
34 #define STK1160_NUM_PACKETS 64
36 /* Number of buffers for isoc transfers */
37 #define STK1160_NUM_BUFS 16
38 #define STK1160_MIN_BUFS 1
40 /* TODO: This endpoint address should be retrieved */
41 #define STK1160_EP_VIDEO 0x82
42 #define STK1160_EP_AUDIO 0x81
44 /* Max and min video buffers */
45 #define STK1160_MIN_VIDEO_BUFFERS 8
46 #define STK1160_MAX_VIDEO_BUFFERS 32
48 #define STK1160_MIN_PKT_SIZE 3072
50 #define STK1160_MAX_INPUT 4
51 #define STK1160_SVIDEO_INPUT 4
53 #define STK1160_I2C_TIMEOUT 100
55 /* TODO: Print helpers
56 * I could use dev_xxx, pr_xxx, v4l2_xxx or printk.
57 * However, there isn't a solid consensus on which
58 * new drivers should use.
63 #define stk1160_dbg(fmt, args...) \
64 printk(KERN_DEBUG "stk1160: " fmt, ## args)
66 #define stk1160_dbg(fmt, args...)
69 #define stk1160_info(fmt, args...) \
70 pr_info("stk1160: " fmt, ## args)
72 #define stk1160_warn(fmt, args...) \
73 pr_warn("stk1160: " fmt, ## args)
75 #define stk1160_err(fmt, args...) \
76 pr_err("stk1160: " fmt, ## args)
78 /* Buffer for one video frame */
79 struct stk1160_buffer
{
80 /* common v4l buffer stuff -- must be first */
82 struct list_head list
;
85 unsigned int length
; /* buffer length */
86 unsigned int bytesused
; /* bytes written */
87 int odd
; /* current oddity */
90 * Since we interlace two fields per frame,
91 * this is different from bytesused.
93 unsigned int pos
; /* current pos inside buffer */
96 struct stk1160_isoc_ctl
{
97 /* max packet size of isoc transaction */
100 /* number of allocated urbs */
103 /* urb for isoc transfers */
106 /* transfer buffers for isoc transfer */
107 char **transfer_buffer
;
110 struct stk1160_buffer
*buf
;
115 u32 fourcc
; /* v4l2 format id */
120 struct v4l2_device v4l2_dev
;
121 struct video_device vdev
;
122 struct v4l2_ctrl_handler ctrl_handler
;
125 struct usb_device
*udev
;
128 struct v4l2_subdev
*sd_saa7115
;
130 /* isoc control struct */
131 struct list_head avail_bufs
;
134 struct vb2_queue vb_vidq
;
136 /* max packet size of isoc transaction */
138 /* array of wMaxPacketSize */
139 unsigned int *alt_max_pkt_size
;
142 /* Number of alternative settings */
145 struct stk1160_isoc_ctl isoc_ctl
;
146 char urb_buf
[255]; /* urb control msg buffer */
148 /* frame properties */
149 int width
; /* current frame width */
150 int height
; /* current frame height */
151 unsigned int ctl_input
; /* selected input */
152 v4l2_std_id norm
; /* current norm */
153 struct stk1160_fmt
*fmt
; /* selected format */
155 unsigned int field_count
; /* not sure ??? */
156 enum v4l2_field field
; /* also not sure :/ */
159 struct i2c_adapter i2c_adap
;
160 struct i2c_client i2c_client
;
162 struct mutex v4l_lock
;
163 struct mutex vb_queue_lock
;
166 struct file
*fh_owner
; /* filehandle ownership */
169 struct snd_card
*snd_card
;
177 /* Provided by stk1160-v4l.c */
178 int stk1160_vb2_setup(struct stk1160
*dev
);
179 int stk1160_video_register(struct stk1160
*dev
);
180 void stk1160_video_unregister(struct stk1160
*dev
);
181 void stk1160_clear_queue(struct stk1160
*dev
);
183 /* Provided by stk1160-video.c */
184 int stk1160_alloc_isoc(struct stk1160
*dev
);
185 void stk1160_free_isoc(struct stk1160
*dev
);
186 void stk1160_cancel_isoc(struct stk1160
*dev
);
187 void stk1160_uninit_isoc(struct stk1160
*dev
);
189 /* Provided by stk1160-i2c.c */
190 int stk1160_i2c_register(struct stk1160
*dev
);
191 int stk1160_i2c_unregister(struct stk1160
*dev
);
193 /* Provided by stk1160-core.c */
194 int stk1160_read_reg(struct stk1160
*dev
, u16 reg
, u8
*value
);
195 int stk1160_write_reg(struct stk1160
*dev
, u16 reg
, u16 value
);
196 int stk1160_write_regs_req(struct stk1160
*dev
, u8 req
, u16 reg
,
198 int stk1160_read_reg_req_len(struct stk1160
*dev
, u8 req
, u16 reg
,
200 void stk1160_select_input(struct stk1160
*dev
);
202 /* Provided by stk1160-ac97.c */
203 #ifdef CONFIG_VIDEO_STK1160_AC97
204 int stk1160_ac97_register(struct stk1160
*dev
);
205 int stk1160_ac97_unregister(struct stk1160
*dev
);
207 static inline int stk1160_ac97_register(struct stk1160
*dev
) { return 0; }
208 static inline int stk1160_ac97_unregister(struct stk1160
*dev
) { return 0; }