]>
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. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
20 | */ | |
21 | ||
22 | #include <linux/usb.h> | |
23 | #include <linux/i2c.h> | |
24 | #include <linux/i2c-algo-bit.h> | |
28930fa9 | 25 | #include <media/tveeprom.h> |
265a6510 | 26 | |
8b2f0795 DH |
27 | /* Analog */ |
28 | #include <linux/videodev2.h> | |
29 | #include <media/videobuf-vmalloc.h> | |
b14667f3 | 30 | #include <media/v4l2-device.h> |
e8c26f45 | 31 | #include <media/v4l2-ctrls.h> |
83b09422 | 32 | #include <media/v4l2-fh.h> |
8b2f0795 | 33 | |
265a6510 ST |
34 | /* DVB */ |
35 | #include "demux.h" | |
36 | #include "dmxdev.h" | |
37 | #include "dvb_demux.h" | |
38 | #include "dvb_frontend.h" | |
39 | #include "dvb_net.h" | |
40 | #include "dvbdev.h" | |
41 | ||
42 | #include "au0828-reg.h" | |
43 | #include "au0828-cards.h" | |
44 | ||
45 | #define DRIVER_NAME "au0828" | |
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 | |
54 | #define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0) | |
55 | ||
56 | /* Defination for AU0828 USB transfer */ | |
57 | #define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */ | |
83f859c5 | 58 | #define AU0828_ISO_PACKETS_PER_URB 128 |
8b2f0795 DH |
59 | |
60 | #define AU0828_MIN_BUF 4 | |
61 | #define AU0828_DEF_BUF 8 | |
62 | ||
8b2f0795 DH |
63 | #define AU0828_MAX_INPUT 4 |
64 | ||
7f8eacd2 DH |
65 | /* au0828 resource types (used for res_get/res_lock etc */ |
66 | #define AU0828_RESOURCE_VIDEO 0x01 | |
67 | #define AU0828_RESOURCE_VBI 0x02 | |
68 | ||
8b2f0795 | 69 | enum au0828_itype { |
220be77c DH |
70 | AU0828_VMUX_UNDEFINED = 0, |
71 | AU0828_VMUX_COMPOSITE, | |
8b2f0795 DH |
72 | AU0828_VMUX_SVIDEO, |
73 | AU0828_VMUX_CABLE, | |
74 | AU0828_VMUX_TELEVISION, | |
75 | AU0828_VMUX_DVB, | |
76 | AU0828_VMUX_DEBUG | |
77 | }; | |
78 | ||
79 | struct au0828_input { | |
80 | enum au0828_itype type; | |
81 | unsigned int vmux; | |
82 | unsigned int amux; | |
83 | void (*audio_setup) (void *priv, int enable); | |
84 | }; | |
85 | ||
265a6510 ST |
86 | struct au0828_board { |
87 | char *name; | |
f1add5b5 DH |
88 | unsigned int tuner_type; |
89 | unsigned char tuner_addr; | |
16af6f5a | 90 | unsigned char i2c_clk_divider; |
8b2f0795 DH |
91 | struct au0828_input input[AU0828_MAX_INPUT]; |
92 | ||
265a6510 ST |
93 | }; |
94 | ||
95 | struct au0828_dvb { | |
96 | struct mutex lock; | |
97 | struct dvb_adapter adapter; | |
98 | struct dvb_frontend *frontend; | |
99 | struct dvb_demux demux; | |
100 | struct dmxdev dmxdev; | |
101 | struct dmx_frontend fe_hw; | |
102 | struct dmx_frontend fe_mem; | |
103 | struct dvb_net net; | |
104 | int feeding; | |
4609981f TM |
105 | int start_count; |
106 | int stop_count; | |
265a6510 ST |
107 | }; |
108 | ||
8b2f0795 DH |
109 | enum au0828_stream_state { |
110 | STREAM_OFF, | |
111 | STREAM_INTERRUPT, | |
112 | STREAM_ON | |
113 | }; | |
114 | ||
f1add5b5 | 115 | #define AUVI_INPUT(nr) (dev->board.input[nr]) |
8b2f0795 DH |
116 | |
117 | /* device state */ | |
118 | enum au0828_dev_state { | |
119 | DEV_INITIALIZED = 0x01, | |
120 | DEV_DISCONNECTED = 0x02, | |
121 | DEV_MISCONFIGURED = 0x04 | |
122 | }; | |
123 | ||
124 | struct au0828_fh { | |
83b09422 HV |
125 | /* must be the first field of this struct! */ |
126 | struct v4l2_fh fh; | |
127 | ||
8b2f0795 | 128 | struct au0828_dev *dev; |
7f8eacd2 DH |
129 | unsigned int resources; |
130 | ||
8b2f0795 | 131 | struct videobuf_queue vb_vidq; |
7f8eacd2 | 132 | struct videobuf_queue vb_vbiq; |
8b2f0795 DH |
133 | enum v4l2_buf_type type; |
134 | }; | |
135 | ||
136 | struct au0828_usb_isoc_ctl { | |
137 | /* max packet size of isoc transaction */ | |
138 | int max_pkt_size; | |
139 | ||
140 | /* number of allocated urbs */ | |
141 | int num_bufs; | |
142 | ||
143 | /* urb for isoc transfers */ | |
144 | struct urb **urb; | |
145 | ||
146 | /* transfer buffers for isoc transfer */ | |
147 | char **transfer_buffer; | |
148 | ||
149 | /* Last buffer command and region */ | |
150 | u8 cmd; | |
151 | int pos, size, pktsize; | |
152 | ||
153 | /* Last field: ODD or EVEN? */ | |
154 | int field; | |
155 | ||
156 | /* Stores incomplete commands */ | |
157 | u32 tmp_buf; | |
158 | int tmp_buf_len; | |
159 | ||
160 | /* Stores already requested buffers */ | |
7f8eacd2 DH |
161 | struct au0828_buffer *buf; |
162 | struct au0828_buffer *vbi_buf; | |
8b2f0795 DH |
163 | |
164 | /* Stores the number of received fields */ | |
165 | int nfields; | |
166 | ||
167 | /* isoc urb callback */ | |
168 | int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb); | |
169 | ||
170 | }; | |
171 | ||
172 | /* buffer for one video frame */ | |
173 | struct au0828_buffer { | |
174 | /* common v4l buffer stuff -- must be first */ | |
175 | struct videobuf_buffer vb; | |
176 | ||
177 | struct list_head frame; | |
178 | int top_field; | |
179 | int receiving; | |
180 | }; | |
181 | ||
182 | struct au0828_dmaqueue { | |
183 | struct list_head active; | |
184 | struct list_head queued; | |
185 | ||
186 | wait_queue_head_t wq; | |
187 | ||
188 | /* Counters to control buffer fill */ | |
189 | int pos; | |
190 | }; | |
191 | ||
265a6510 ST |
192 | struct au0828_dev { |
193 | struct mutex mutex; | |
194 | struct usb_device *usbdev; | |
f1add5b5 DH |
195 | int boardnr; |
196 | struct au0828_board board; | |
265a6510 ST |
197 | u8 ctrlmsg[64]; |
198 | ||
199 | /* I2C */ | |
200 | struct i2c_adapter i2c_adap; | |
b14667f3 | 201 | struct i2c_algorithm i2c_algo; |
265a6510 ST |
202 | struct i2c_client i2c_client; |
203 | u32 i2c_rc; | |
204 | ||
205 | /* Digital */ | |
206 | struct au0828_dvb dvb; | |
43f2cccf | 207 | struct work_struct restart_streaming; |
265a6510 | 208 | |
8a4e7866 | 209 | #ifdef CONFIG_VIDEO_AU0828_V4L2 |
8b2f0795 | 210 | /* Analog */ |
b14667f3 | 211 | struct v4l2_device v4l2_dev; |
e8c26f45 | 212 | struct v4l2_ctrl_handler v4l2_ctrl_hdl; |
8a4e7866 | 213 | #endif |
8b2f0795 | 214 | int users; |
7f8eacd2 | 215 | unsigned int resources; /* resources in use */ |
8b2f0795 DH |
216 | struct video_device *vdev; |
217 | struct video_device *vbi_dev; | |
6e04b7b9 | 218 | struct timer_list vid_timeout; |
78ca5005 | 219 | int vid_timeout_running; |
6e04b7b9 | 220 | struct timer_list vbi_timeout; |
78ca5005 | 221 | int vbi_timeout_running; |
8b2f0795 DH |
222 | int width; |
223 | int height; | |
7f8eacd2 DH |
224 | int vbi_width; |
225 | int vbi_height; | |
226 | u32 vbi_read; | |
33b6b89b | 227 | v4l2_std_id std; |
8b2f0795 DH |
228 | u32 field_size; |
229 | u32 frame_size; | |
230 | u32 bytesperline; | |
231 | int type; | |
232 | u8 ctrl_ainput; | |
233 | __u8 isoc_in_endpointaddr; | |
234 | u8 isoc_init_ok; | |
235 | int greenscreen_detected; | |
236 | unsigned int frame_count; | |
237 | int ctrl_freq; | |
238 | int input_type; | |
c98bc032 | 239 | int std_set_in_tuner_core; |
8b2f0795 DH |
240 | unsigned int ctrl_input; |
241 | enum au0828_dev_state dev_state; | |
242 | enum au0828_stream_state stream_state; | |
243 | wait_queue_head_t open; | |
244 | ||
245 | struct mutex lock; | |
246 | ||
247 | /* Isoc control struct */ | |
248 | struct au0828_dmaqueue vidq; | |
7f8eacd2 | 249 | struct au0828_dmaqueue vbiq; |
8b2f0795 DH |
250 | struct au0828_usb_isoc_ctl isoc_ctl; |
251 | spinlock_t slock; | |
252 | ||
253 | /* usb transfer */ | |
254 | int alt; /* alternate */ | |
255 | int max_pkt_size; /* max packet size of isoc transaction */ | |
256 | int num_alt; /* Number of alternative settings */ | |
257 | unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ | |
258 | struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */ | |
259 | char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc | |
260 | transfer */ | |
261 | ||
265a6510 ST |
262 | /* USB / URB Related */ |
263 | int urb_streaming; | |
264 | struct urb *urbs[URB_COUNT]; | |
265a6510 ST |
265 | }; |
266 | ||
267 | /* ----------------------------------------------------------- */ | |
18d73c58 MCC |
268 | #define au0828_read(dev, reg) au0828_readreg(dev, reg) |
269 | #define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value) | |
270 | #define au0828_andor(dev, reg, mask, value) \ | |
271 | au0828_writereg(dev, reg, \ | |
272 | (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask))) | |
273 | ||
274 | #define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit)) | |
275 | #define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0) | |
265a6510 ST |
276 | |
277 | /* ----------------------------------------------------------- */ | |
278 | /* au0828-core.c */ | |
279 | extern u32 au0828_read(struct au0828_dev *dev, u16 reg); | |
280 | extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val); | |
b33d24c4 | 281 | extern int au0828_debug; |
265a6510 ST |
282 | |
283 | /* ----------------------------------------------------------- */ | |
284 | /* au0828-cards.c */ | |
285 | extern struct au0828_board au0828_boards[]; | |
286 | extern struct usb_device_id au0828_usb_id_table[]; | |
265a6510 | 287 | extern void au0828_gpio_setup(struct au0828_dev *dev); |
d7cba043 MK |
288 | extern int au0828_tuner_callback(void *priv, int component, |
289 | int command, int arg); | |
28930fa9 | 290 | extern void au0828_card_setup(struct au0828_dev *dev); |
265a6510 ST |
291 | |
292 | /* ----------------------------------------------------------- */ | |
293 | /* au0828-i2c.c */ | |
294 | extern int au0828_i2c_register(struct au0828_dev *dev); | |
295 | extern int au0828_i2c_unregister(struct au0828_dev *dev); | |
265a6510 | 296 | |
8b2f0795 DH |
297 | /* ----------------------------------------------------------- */ |
298 | /* au0828-video.c */ | |
fc4ce6cd DH |
299 | int au0828_analog_register(struct au0828_dev *dev, |
300 | struct usb_interface *interface); | |
8b2f0795 DH |
301 | int au0828_analog_stream_disable(struct au0828_dev *d); |
302 | void au0828_analog_unregister(struct au0828_dev *dev); | |
303 | ||
265a6510 ST |
304 | /* ----------------------------------------------------------- */ |
305 | /* au0828-dvb.c */ | |
306 | extern int au0828_dvb_register(struct au0828_dev *dev); | |
307 | extern void au0828_dvb_unregister(struct au0828_dev *dev); | |
bc3c613c | 308 | |
7f8eacd2 DH |
309 | /* au0828-vbi.c */ |
310 | extern struct videobuf_queue_ops au0828_vbi_qops; | |
311 | ||
bc3c613c | 312 | #define dprintk(level, fmt, arg...)\ |
b33d24c4 | 313 | do { if (au0828_debug & level)\ |
bc3c613c ST |
314 | printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\ |
315 | } while (0) |