]>
Commit | Line | Data |
---|---|---|
265a6510 ST |
1 | /* |
2 | * Driver for the Auvitek AU0828 USB bridge | |
3 | * | |
6d897616 | 4 | * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org> |
265a6510 ST |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * | |
15 | * GNU General Public License for more details. | |
265a6510 ST |
16 | */ |
17 | ||
83afb32a MCC |
18 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
19 | ||
e8e3039f | 20 | #include <linux/bitops.h> |
265a6510 ST |
21 | #include <linux/usb.h> |
22 | #include <linux/i2c.h> | |
23 | #include <linux/i2c-algo-bit.h> | |
28930fa9 | 24 | #include <media/tveeprom.h> |
265a6510 | 25 | |
8b2f0795 DH |
26 | /* Analog */ |
27 | #include <linux/videodev2.h> | |
2d700715 | 28 | #include <media/videobuf2-v4l2.h> |
05439b1a | 29 | #include <media/videobuf2-vmalloc.h> |
b14667f3 | 30 | #include <media/v4l2-device.h> |
e8c26f45 | 31 | #include <media/v4l2-ctrls.h> |
83b09422 | 32 | #include <media/v4l2-fh.h> |
bed69196 | 33 | #include <media/media-device.h> |
8b2f0795 | 34 | |
265a6510 ST |
35 | /* DVB */ |
36 | #include "demux.h" | |
37 | #include "dmxdev.h" | |
38 | #include "dvb_demux.h" | |
39 | #include "dvb_frontend.h" | |
40 | #include "dvb_net.h" | |
41 | #include "dvbdev.h" | |
42 | ||
43 | #include "au0828-reg.h" | |
44 | #include "au0828-cards.h" | |
45 | ||
265a6510 | 46 | #define URB_COUNT 16 |
265a6510 ST |
47 | #define URB_BUFSIZE (0xe522) |
48 | ||
8b2f0795 DH |
49 | /* Analog constants */ |
50 | #define NTSC_STD_W 720 | |
51 | #define NTSC_STD_H 480 | |
52 | ||
53 | #define AU0828_INTERLACED_DEFAULT 1 | |
8b2f0795 DH |
54 | |
55 | /* Defination for AU0828 USB transfer */ | |
56 | #define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */ | |
83f859c5 | 57 | #define AU0828_ISO_PACKETS_PER_URB 128 |
8b2f0795 DH |
58 | |
59 | #define AU0828_MIN_BUF 4 | |
60 | #define AU0828_DEF_BUF 8 | |
61 | ||
8b2f0795 DH |
62 | #define AU0828_MAX_INPUT 4 |
63 | ||
7f8eacd2 DH |
64 | /* au0828 resource types (used for res_get/res_lock etc */ |
65 | #define AU0828_RESOURCE_VIDEO 0x01 | |
66 | #define AU0828_RESOURCE_VBI 0x02 | |
67 | ||
8b2f0795 | 68 | enum au0828_itype { |
220be77c DH |
69 | AU0828_VMUX_UNDEFINED = 0, |
70 | AU0828_VMUX_COMPOSITE, | |
8b2f0795 DH |
71 | AU0828_VMUX_SVIDEO, |
72 | AU0828_VMUX_CABLE, | |
73 | AU0828_VMUX_TELEVISION, | |
74 | AU0828_VMUX_DVB, | |
8b2f0795 DH |
75 | }; |
76 | ||
77 | struct au0828_input { | |
78 | enum au0828_itype type; | |
79 | unsigned int vmux; | |
80 | unsigned int amux; | |
81 | void (*audio_setup) (void *priv, int enable); | |
82 | }; | |
83 | ||
265a6510 ST |
84 | struct au0828_board { |
85 | char *name; | |
f1add5b5 DH |
86 | unsigned int tuner_type; |
87 | unsigned char tuner_addr; | |
16af6f5a | 88 | unsigned char i2c_clk_divider; |
2fcfd317 | 89 | unsigned char has_ir_i2c:1; |
b13b47e0 | 90 | unsigned char has_analog:1; |
8b2f0795 | 91 | struct au0828_input input[AU0828_MAX_INPUT]; |
265a6510 ST |
92 | }; |
93 | ||
94 | struct au0828_dvb { | |
95 | struct mutex lock; | |
96 | struct dvb_adapter adapter; | |
97 | struct dvb_frontend *frontend; | |
98 | struct dvb_demux demux; | |
99 | struct dmxdev dmxdev; | |
100 | struct dmx_frontend fe_hw; | |
101 | struct dmx_frontend fe_mem; | |
102 | struct dvb_net net; | |
103 | int feeding; | |
4609981f TM |
104 | int start_count; |
105 | int stop_count; | |
f6fef863 MCC |
106 | |
107 | int (*set_frontend)(struct dvb_frontend *fe); | |
265a6510 ST |
108 | }; |
109 | ||
8b2f0795 DH |
110 | enum au0828_stream_state { |
111 | STREAM_OFF, | |
112 | STREAM_INTERRUPT, | |
113 | STREAM_ON | |
114 | }; | |
115 | ||
f1add5b5 | 116 | #define AUVI_INPUT(nr) (dev->board.input[nr]) |
8b2f0795 DH |
117 | |
118 | /* device state */ | |
119 | enum au0828_dev_state { | |
e8e3039f MCC |
120 | DEV_INITIALIZED = 0, |
121 | DEV_DISCONNECTED = 1, | |
122 | DEV_MISCONFIGURED = 2 | |
8b2f0795 DH |
123 | }; |
124 | ||
05439b1a | 125 | struct au0828_dev; |
8b2f0795 DH |
126 | |
127 | struct au0828_usb_isoc_ctl { | |
128 | /* max packet size of isoc transaction */ | |
129 | int max_pkt_size; | |
130 | ||
131 | /* number of allocated urbs */ | |
132 | int num_bufs; | |
133 | ||
134 | /* urb for isoc transfers */ | |
135 | struct urb **urb; | |
136 | ||
137 | /* transfer buffers for isoc transfer */ | |
138 | char **transfer_buffer; | |
139 | ||
140 | /* Last buffer command and region */ | |
141 | u8 cmd; | |
142 | int pos, size, pktsize; | |
143 | ||
144 | /* Last field: ODD or EVEN? */ | |
145 | int field; | |
146 | ||
147 | /* Stores incomplete commands */ | |
148 | u32 tmp_buf; | |
149 | int tmp_buf_len; | |
150 | ||
151 | /* Stores already requested buffers */ | |
7f8eacd2 DH |
152 | struct au0828_buffer *buf; |
153 | struct au0828_buffer *vbi_buf; | |
8b2f0795 DH |
154 | |
155 | /* Stores the number of received fields */ | |
156 | int nfields; | |
157 | ||
158 | /* isoc urb callback */ | |
159 | int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb); | |
160 | ||
161 | }; | |
162 | ||
163 | /* buffer for one video frame */ | |
164 | struct au0828_buffer { | |
165 | /* common v4l buffer stuff -- must be first */ | |
2d700715 | 166 | struct vb2_v4l2_buffer vb; |
05439b1a | 167 | struct list_head list; |
8b2f0795 | 168 | |
05439b1a SK |
169 | void *mem; |
170 | unsigned long length; | |
8b2f0795 | 171 | int top_field; |
05439b1a SK |
172 | /* pointer to vmalloc memory address in vb */ |
173 | char *vb_buf; | |
8b2f0795 DH |
174 | }; |
175 | ||
176 | struct au0828_dmaqueue { | |
177 | struct list_head active; | |
8b2f0795 | 178 | /* Counters to control buffer fill */ |
05439b1a | 179 | int pos; |
8b2f0795 DH |
180 | }; |
181 | ||
265a6510 ST |
182 | struct au0828_dev { |
183 | struct mutex mutex; | |
184 | struct usb_device *usbdev; | |
f1add5b5 DH |
185 | int boardnr; |
186 | struct au0828_board board; | |
265a6510 ST |
187 | u8 ctrlmsg[64]; |
188 | ||
189 | /* I2C */ | |
190 | struct i2c_adapter i2c_adap; | |
b14667f3 | 191 | struct i2c_algorithm i2c_algo; |
265a6510 ST |
192 | struct i2c_client i2c_client; |
193 | u32 i2c_rc; | |
194 | ||
195 | /* Digital */ | |
196 | struct au0828_dvb dvb; | |
43f2cccf | 197 | struct work_struct restart_streaming; |
265a6510 | 198 | |
8a4e7866 | 199 | #ifdef CONFIG_VIDEO_AU0828_V4L2 |
8b2f0795 | 200 | /* Analog */ |
b14667f3 | 201 | struct v4l2_device v4l2_dev; |
e8c26f45 | 202 | struct v4l2_ctrl_handler v4l2_ctrl_hdl; |
8a4e7866 | 203 | #endif |
2fcfd317 MCC |
204 | #ifdef CONFIG_VIDEO_AU0828_RC |
205 | struct au0828_rc *ir; | |
206 | #endif | |
207 | ||
41071bb8 SK |
208 | struct video_device vdev; |
209 | struct video_device vbi_dev; | |
05439b1a SK |
210 | |
211 | /* Videobuf2 */ | |
212 | struct vb2_queue vb_vidq; | |
213 | struct vb2_queue vb_vbiq; | |
214 | struct mutex vb_queue_lock; | |
215 | struct mutex vb_vbi_queue_lock; | |
216 | ||
217 | unsigned int frame_count; | |
218 | unsigned int vbi_frame_count; | |
219 | ||
6e04b7b9 | 220 | struct timer_list vid_timeout; |
78ca5005 | 221 | int vid_timeout_running; |
6e04b7b9 | 222 | struct timer_list vbi_timeout; |
78ca5005 | 223 | int vbi_timeout_running; |
05439b1a SK |
224 | |
225 | int users; | |
226 | int streaming_users; | |
227 | ||
8b2f0795 DH |
228 | int width; |
229 | int height; | |
7f8eacd2 DH |
230 | int vbi_width; |
231 | int vbi_height; | |
232 | u32 vbi_read; | |
33b6b89b | 233 | v4l2_std_id std; |
8b2f0795 DH |
234 | u32 field_size; |
235 | u32 frame_size; | |
236 | u32 bytesperline; | |
237 | int type; | |
238 | u8 ctrl_ainput; | |
239 | __u8 isoc_in_endpointaddr; | |
240 | u8 isoc_init_ok; | |
241 | int greenscreen_detected; | |
8b2f0795 DH |
242 | int ctrl_freq; |
243 | int input_type; | |
c98bc032 | 244 | int std_set_in_tuner_core; |
8b2f0795 | 245 | unsigned int ctrl_input; |
e8e3039f | 246 | long unsigned int dev_state; /* defined at enum au0828_dev_state */; |
8b2f0795 DH |
247 | enum au0828_stream_state stream_state; |
248 | wait_queue_head_t open; | |
249 | ||
250 | struct mutex lock; | |
251 | ||
252 | /* Isoc control struct */ | |
253 | struct au0828_dmaqueue vidq; | |
7f8eacd2 | 254 | struct au0828_dmaqueue vbiq; |
8b2f0795 DH |
255 | struct au0828_usb_isoc_ctl isoc_ctl; |
256 | spinlock_t slock; | |
257 | ||
258 | /* usb transfer */ | |
259 | int alt; /* alternate */ | |
260 | int max_pkt_size; /* max packet size of isoc transaction */ | |
261 | int num_alt; /* Number of alternative settings */ | |
262 | unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ | |
263 | struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */ | |
264 | char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc | |
265 | transfer */ | |
266 | ||
2930977a MCC |
267 | /* DVB USB / URB Related */ |
268 | bool urb_streaming, need_urb_start; | |
265a6510 | 269 | struct urb *urbs[URB_COUNT]; |
f251b3e7 TM |
270 | |
271 | /* Preallocated transfer digital transfer buffers */ | |
272 | ||
273 | char *dig_transfer_buffer[URB_COUNT]; | |
bed69196 RLLC |
274 | |
275 | #ifdef CONFIG_MEDIA_CONTROLLER | |
276 | struct media_device *media_dev; | |
277 | struct media_pad video_pad, vbi_pad; | |
0158e7b6 | 278 | struct media_entity *decoder; |
d1f33737 MCC |
279 | struct media_entity input_ent[AU0828_MAX_INPUT]; |
280 | struct media_pad input_pad[AU0828_MAX_INPUT]; | |
f90c5d79 | 281 | struct media_entity_notify entity_notify; |
c94903f1 SK |
282 | struct media_entity *tuner; |
283 | struct media_link *active_link; | |
284 | struct media_entity *active_link_owner; | |
285 | struct media_entity *active_source; | |
286 | struct media_entity *active_sink; | |
bed69196 | 287 | #endif |
265a6510 ST |
288 | }; |
289 | ||
05439b1a | 290 | |
265a6510 | 291 | /* ----------------------------------------------------------- */ |
18d73c58 MCC |
292 | #define au0828_read(dev, reg) au0828_readreg(dev, reg) |
293 | #define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value) | |
294 | #define au0828_andor(dev, reg, mask, value) \ | |
295 | au0828_writereg(dev, reg, \ | |
296 | (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask))) | |
297 | ||
298 | #define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit)) | |
299 | #define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0) | |
265a6510 ST |
300 | |
301 | /* ----------------------------------------------------------- */ | |
302 | /* au0828-core.c */ | |
303 | extern u32 au0828_read(struct au0828_dev *dev, u16 reg); | |
304 | extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val); | |
7b606ffd | 305 | extern void au0828_usb_release(struct au0828_dev *dev); |
b33d24c4 | 306 | extern int au0828_debug; |
265a6510 ST |
307 | |
308 | /* ----------------------------------------------------------- */ | |
309 | /* au0828-cards.c */ | |
310 | extern struct au0828_board au0828_boards[]; | |
311 | extern struct usb_device_id au0828_usb_id_table[]; | |
265a6510 | 312 | extern void au0828_gpio_setup(struct au0828_dev *dev); |
d7cba043 MK |
313 | extern int au0828_tuner_callback(void *priv, int component, |
314 | int command, int arg); | |
28930fa9 | 315 | extern void au0828_card_setup(struct au0828_dev *dev); |
265a6510 ST |
316 | |
317 | /* ----------------------------------------------------------- */ | |
318 | /* au0828-i2c.c */ | |
319 | extern int au0828_i2c_register(struct au0828_dev *dev); | |
320 | extern int au0828_i2c_unregister(struct au0828_dev *dev); | |
265a6510 | 321 | |
8b2f0795 DH |
322 | /* ----------------------------------------------------------- */ |
323 | /* au0828-video.c */ | |
05439b1a SK |
324 | extern int au0828_start_analog_streaming(struct vb2_queue *vq, |
325 | unsigned int count); | |
326 | extern void au0828_stop_vbi_streaming(struct vb2_queue *vq); | |
1a1ba95e | 327 | #ifdef CONFIG_VIDEO_AU0828_V4L2 |
7b606ffd MCC |
328 | extern int au0828_v4l2_device_register(struct usb_interface *interface, |
329 | struct au0828_dev *dev); | |
330 | ||
331 | extern int au0828_analog_register(struct au0828_dev *dev, | |
332 | struct usb_interface *interface); | |
333 | extern int au0828_analog_unregister(struct au0828_dev *dev); | |
334 | extern void au0828_usb_v4l2_media_release(struct au0828_dev *dev); | |
05439b1a SK |
335 | extern void au0828_v4l2_suspend(struct au0828_dev *dev); |
336 | extern void au0828_v4l2_resume(struct au0828_dev *dev); | |
1a1ba95e | 337 | #else |
7b606ffd MCC |
338 | static inline int au0828_v4l2_device_register(struct usb_interface *interface, |
339 | struct au0828_dev *dev) | |
340 | { return 0; }; | |
341 | static inline int au0828_analog_register(struct au0828_dev *dev, | |
342 | struct usb_interface *interface) | |
343 | { return 0; }; | |
344 | static inline int au0828_analog_unregister(struct au0828_dev *dev) | |
345 | { return 0; }; | |
346 | static inline void au0828_usb_v4l2_media_release(struct au0828_dev *dev) { }; | |
1a1ba95e MCC |
347 | static inline void au0828_v4l2_suspend(struct au0828_dev *dev) { }; |
348 | static inline void au0828_v4l2_resume(struct au0828_dev *dev) { }; | |
349 | #endif | |
8b2f0795 | 350 | |
265a6510 ST |
351 | /* ----------------------------------------------------------- */ |
352 | /* au0828-dvb.c */ | |
353 | extern int au0828_dvb_register(struct au0828_dev *dev); | |
354 | extern void au0828_dvb_unregister(struct au0828_dev *dev); | |
b799de75 MCC |
355 | void au0828_dvb_suspend(struct au0828_dev *dev); |
356 | void au0828_dvb_resume(struct au0828_dev *dev); | |
bc3c613c | 357 | |
7f8eacd2 | 358 | /* au0828-vbi.c */ |
05439b1a | 359 | extern struct vb2_ops au0828_vbi_qops; |
7f8eacd2 | 360 | |
bc3c613c | 361 | #define dprintk(level, fmt, arg...)\ |
b33d24c4 | 362 | do { if (au0828_debug & level)\ |
83afb32a | 363 | printk(KERN_DEBUG pr_fmt(fmt), ## arg);\ |
bc3c613c | 364 | } while (0) |
2fcfd317 MCC |
365 | |
366 | /* au0828-input.c */ | |
917cbcde SK |
367 | #ifdef CONFIG_VIDEO_AU0828_RC |
368 | extern int au0828_rc_register(struct au0828_dev *dev); | |
369 | extern void au0828_rc_unregister(struct au0828_dev *dev); | |
370 | extern int au0828_rc_suspend(struct au0828_dev *dev); | |
371 | extern int au0828_rc_resume(struct au0828_dev *dev); | |
372 | #else | |
373 | static inline int au0828_rc_register(struct au0828_dev *dev) { return 0; } | |
374 | static inline void au0828_rc_unregister(struct au0828_dev *dev) { } | |
375 | static inline int au0828_rc_suspend(struct au0828_dev *dev) { return 0; } | |
376 | static inline int au0828_rc_resume(struct au0828_dev *dev) { return 0; } | |
377 | #endif |