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