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-v4l2.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_AC97_TIMEOUT 50
54
55#define STK1160_I2C_TIMEOUT 100
56
57
58
59
60
61
62
63#ifdef DEBUG
64#define stk1160_dbg(fmt, args...) \
65 printk(KERN_DEBUG "stk1160: " fmt, ## args)
66#else
67#define stk1160_dbg(fmt, args...)
68#endif
69
70#define stk1160_info(fmt, args...) \
71 pr_info("stk1160: " fmt, ## args)
72
73#define stk1160_warn(fmt, args...) \
74 pr_warn("stk1160: " fmt, ## args)
75
76#define stk1160_err(fmt, args...) \
77 pr_err("stk1160: " fmt, ## args)
78
79
80struct stk1160_buffer {
81
82 struct vb2_v4l2_buffer vb;
83 struct list_head list;
84
85 void *mem;
86 unsigned int length;
87 unsigned int bytesused;
88 int odd;
89
90
91
92
93
94 unsigned int pos;
95};
96
97struct stk1160_isoc_ctl {
98
99 int max_pkt_size;
100
101
102 int num_bufs;
103
104
105 struct urb **urb;
106
107
108 char **transfer_buffer;
109
110
111 struct stk1160_buffer *buf;
112};
113
114struct stk1160_fmt {
115 char *name;
116 u32 fourcc;
117 int depth;
118};
119
120struct stk1160 {
121 struct v4l2_device v4l2_dev;
122 struct video_device vdev;
123 struct v4l2_ctrl_handler ctrl_handler;
124
125 struct device *dev;
126 struct usb_device *udev;
127
128
129 struct v4l2_subdev *sd_saa7115;
130
131
132 struct list_head avail_bufs;
133
134
135 struct vb2_queue vb_vidq;
136
137
138 int max_pkt_size;
139
140 unsigned int *alt_max_pkt_size;
141
142 int alt;
143
144 int num_alt;
145
146 struct stk1160_isoc_ctl isoc_ctl;
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 sequence;
156
157
158 struct i2c_adapter i2c_adap;
159 struct i2c_client i2c_client;
160
161 struct mutex v4l_lock;
162 struct mutex vb_queue_lock;
163 spinlock_t buf_lock;
164
165 struct file *fh_owner;
166
167
168 struct snd_card *snd_card;
169};
170
171struct regval {
172 u16 reg;
173 u16 val;
174};
175
176
177int stk1160_vb2_setup(struct stk1160 *dev);
178int stk1160_video_register(struct stk1160 *dev);
179void stk1160_video_unregister(struct stk1160 *dev);
180void stk1160_clear_queue(struct stk1160 *dev);
181
182
183int stk1160_alloc_isoc(struct stk1160 *dev);
184void stk1160_free_isoc(struct stk1160 *dev);
185void stk1160_cancel_isoc(struct stk1160 *dev);
186void stk1160_uninit_isoc(struct stk1160 *dev);
187
188
189int stk1160_i2c_register(struct stk1160 *dev);
190int stk1160_i2c_unregister(struct stk1160 *dev);
191
192
193int stk1160_read_reg(struct stk1160 *dev, u16 reg, u8 *value);
194int stk1160_write_reg(struct stk1160 *dev, u16 reg, u16 value);
195int stk1160_write_regs_req(struct stk1160 *dev, u8 req, u16 reg,
196 char *buf, int len);
197int stk1160_read_reg_req_len(struct stk1160 *dev, u8 req, u16 reg,
198 char *buf, int len);
199void stk1160_select_input(struct stk1160 *dev);
200
201
202void stk1160_ac97_setup(struct stk1160 *dev);
203