Commit | Line | Data |
---|---|---|
265a6510 ST |
1 | /* |
2 | * Driver for the Auvitek 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 | ||
83afb32a | 22 | #include "au0828.h" |
f90c5d79 | 23 | #include "au8522.h" |
83afb32a | 24 | |
265a6510 | 25 | #include <linux/module.h> |
5a0e3ad6 | 26 | #include <linux/slab.h> |
265a6510 ST |
27 | #include <linux/videodev2.h> |
28 | #include <media/v4l2-common.h> | |
29 | #include <linux/mutex.h> | |
30 | ||
188d2d55 MCC |
31 | /* Due to enum tuner_pad_index */ |
32 | #include <media/tuner.h> | |
33 | ||
bc3c613c ST |
34 | /* |
35 | * 1 = General debug messages | |
36 | * 2 = USB handling | |
37 | * 4 = I2C related | |
38 | * 8 = Bridge related | |
2fcfd317 | 39 | * 16 = IR related |
bc3c613c | 40 | */ |
b33d24c4 AB |
41 | int au0828_debug; |
42 | module_param_named(debug, au0828_debug, int, 0644); | |
2fcfd317 MCC |
43 | MODULE_PARM_DESC(debug, |
44 | "set debug bitmask: 1=general, 2=USB, 4=I2C, 8=bridge, 16=IR"); | |
265a6510 | 45 | |
d6a9a430 DH |
46 | static unsigned int disable_usb_speed_check; |
47 | module_param(disable_usb_speed_check, int, 0444); | |
48 | MODULE_PARM_DESC(disable_usb_speed_check, | |
49 | "override min bandwidth requirement of 480M bps"); | |
50 | ||
265a6510 ST |
51 | #define _AU0828_BULKPIPE 0x03 |
52 | #define _BULKPIPESIZE 0xffff | |
53 | ||
54 | static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value, | |
8ff63de6 | 55 | u16 index); |
265a6510 ST |
56 | static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value, |
57 | u16 index, unsigned char *cp, u16 size); | |
58 | ||
59 | /* USB Direction */ | |
60 | #define CMD_REQUEST_IN 0x00 | |
61 | #define CMD_REQUEST_OUT 0x01 | |
62 | ||
63 | u32 au0828_readreg(struct au0828_dev *dev, u16 reg) | |
64 | { | |
77fc2863 DH |
65 | u8 result = 0; |
66 | ||
67 | recv_control_msg(dev, CMD_REQUEST_IN, 0, reg, &result, 1); | |
68 | dprintk(8, "%s(0x%04x) = 0x%02x\n", __func__, reg, result); | |
69 | ||
70 | return result; | |
265a6510 ST |
71 | } |
72 | ||
73 | u32 au0828_writereg(struct au0828_dev *dev, u16 reg, u32 val) | |
74 | { | |
b80f770a | 75 | dprintk(8, "%s(0x%04x, 0x%02x)\n", __func__, reg, val); |
8ff63de6 | 76 | return send_control_msg(dev, CMD_REQUEST_OUT, val, reg); |
265a6510 ST |
77 | } |
78 | ||
265a6510 | 79 | static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value, |
8ff63de6 | 80 | u16 index) |
265a6510 ST |
81 | { |
82 | int status = -ENODEV; | |
8ff63de6 | 83 | |
265a6510 ST |
84 | if (dev->usbdev) { |
85 | ||
86 | /* cp must be memory that has been allocated by kmalloc */ | |
87 | status = usb_control_msg(dev->usbdev, | |
88 | usb_sndctrlpipe(dev->usbdev, 0), | |
89 | request, | |
a8eb912c ST |
90 | USB_DIR_OUT | USB_TYPE_VENDOR | |
91 | USB_RECIP_DEVICE, | |
8ff63de6 | 92 | value, index, NULL, 0, 1000); |
265a6510 ST |
93 | |
94 | status = min(status, 0); | |
95 | ||
96 | if (status < 0) { | |
83afb32a | 97 | pr_err("%s() Failed sending control message, error %d.\n", |
f07e8e4b | 98 | __func__, status); |
265a6510 ST |
99 | } |
100 | ||
101 | } | |
8ff63de6 | 102 | |
265a6510 ST |
103 | return status; |
104 | } | |
105 | ||
106 | static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value, | |
107 | u16 index, unsigned char *cp, u16 size) | |
108 | { | |
109 | int status = -ENODEV; | |
110 | mutex_lock(&dev->mutex); | |
111 | if (dev->usbdev) { | |
265a6510 ST |
112 | status = usb_control_msg(dev->usbdev, |
113 | usb_rcvctrlpipe(dev->usbdev, 0), | |
114 | request, | |
115 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, | |
116 | value, index, | |
77fc2863 | 117 | dev->ctrlmsg, size, 1000); |
265a6510 ST |
118 | |
119 | status = min(status, 0); | |
120 | ||
121 | if (status < 0) { | |
83afb32a | 122 | pr_err("%s() Failed receiving control message, error %d.\n", |
f07e8e4b | 123 | __func__, status); |
77fc2863 DH |
124 | } |
125 | ||
126 | /* the host controller requires heap allocated memory, which | |
127 | is why we didn't just pass "cp" into usb_control_msg */ | |
128 | memcpy(cp, dev->ctrlmsg, size); | |
265a6510 ST |
129 | } |
130 | mutex_unlock(&dev->mutex); | |
131 | return status; | |
132 | } | |
a9c36aad | 133 | |
bed69196 RLLC |
134 | static void au0828_unregister_media_device(struct au0828_dev *dev) |
135 | { | |
136 | ||
137 | #ifdef CONFIG_MEDIA_CONTROLLER | |
182dde7c SK |
138 | if (dev->media_dev && |
139 | media_devnode_is_registered(&dev->media_dev->devnode)) { | |
ffa8576a SK |
140 | /* clear enable_source, disable_source */ |
141 | dev->media_dev->source_priv = NULL; | |
142 | dev->media_dev->enable_source = NULL; | |
143 | dev->media_dev->disable_source = NULL; | |
144 | ||
bed69196 | 145 | media_device_unregister(dev->media_dev); |
9832e155 | 146 | media_device_cleanup(dev->media_dev); |
405ddbfa | 147 | kfree(dev->media_dev); |
bed69196 RLLC |
148 | dev->media_dev = NULL; |
149 | } | |
150 | #endif | |
151 | } | |
152 | ||
7b606ffd | 153 | void au0828_usb_release(struct au0828_dev *dev) |
265a6510 | 154 | { |
bed69196 RLLC |
155 | au0828_unregister_media_device(dev); |
156 | ||
265a6510 ST |
157 | /* I2C */ |
158 | au0828_i2c_unregister(dev); | |
159 | ||
823beb7e HV |
160 | kfree(dev); |
161 | } | |
162 | ||
823beb7e HV |
163 | static void au0828_usb_disconnect(struct usb_interface *interface) |
164 | { | |
165 | struct au0828_dev *dev = usb_get_intfdata(interface); | |
166 | ||
167 | dprintk(1, "%s()\n", __func__); | |
168 | ||
eb336eab SK |
169 | /* there is a small window after disconnect, before |
170 | dev->usbdev is NULL, for poll (e.g: IR) try to access | |
171 | the device and fill the dmesg with error messages. | |
172 | Set the status so poll routines can check and avoid | |
173 | access after disconnect. | |
174 | */ | |
e8e3039f | 175 | set_bit(DEV_DISCONNECTED, &dev->dev_state); |
eb336eab | 176 | |
2fcfd317 | 177 | au0828_rc_unregister(dev); |
823beb7e HV |
178 | /* Digital TV */ |
179 | au0828_dvb_unregister(dev); | |
265a6510 | 180 | |
823beb7e | 181 | usb_set_intfdata(interface, NULL); |
265a6510 ST |
182 | mutex_lock(&dev->mutex); |
183 | dev->usbdev = NULL; | |
184 | mutex_unlock(&dev->mutex); | |
7b606ffd | 185 | if (au0828_analog_unregister(dev)) { |
7e9a8ad5 MCC |
186 | /* |
187 | * No need to call au0828_usb_release() if V4L2 is enabled, | |
188 | * as this is already called via au0828_usb_v4l2_release() | |
189 | */ | |
823beb7e HV |
190 | return; |
191 | } | |
823beb7e | 192 | au0828_usb_release(dev); |
265a6510 ST |
193 | } |
194 | ||
9f806795 MCC |
195 | static int au0828_media_device_init(struct au0828_dev *dev, |
196 | struct usb_device *udev) | |
bed69196 RLLC |
197 | { |
198 | #ifdef CONFIG_MEDIA_CONTROLLER | |
199 | struct media_device *mdev; | |
bed69196 | 200 | |
405ddbfa | 201 | mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); |
67873d4e MCC |
202 | if (!mdev) |
203 | return -ENOMEM; | |
bed69196 | 204 | |
7b12adf6 SK |
205 | /* check if media device is already initialized */ |
206 | if (!mdev->dev) | |
207 | media_device_usb_init(mdev, udev, udev->product); | |
6cf5dad1 | 208 | |
bed69196 RLLC |
209 | dev->media_dev = mdev; |
210 | #endif | |
9f806795 | 211 | return 0; |
bed69196 RLLC |
212 | } |
213 | ||
0a82edd0 | 214 | #ifdef CONFIG_MEDIA_CONTROLLER |
f90c5d79 SK |
215 | static void au0828_media_graph_notify(struct media_entity *new, |
216 | void *notify_data) | |
217 | { | |
f90c5d79 SK |
218 | struct au0828_dev *dev = (struct au0828_dev *) notify_data; |
219 | int ret; | |
9096cae1 | 220 | struct media_entity *entity, *mixer = NULL, *decoder = NULL; |
f90c5d79 | 221 | |
9096cae1 SK |
222 | if (!new) { |
223 | /* | |
224 | * Called during au0828 probe time to connect | |
225 | * entites that were created prior to registering | |
226 | * the notify handler. Find mixer and decoder. | |
227 | */ | |
228 | media_device_for_each_entity(entity, dev->media_dev) { | |
229 | if (entity->function == MEDIA_ENT_F_AUDIO_MIXER) | |
230 | mixer = entity; | |
231 | else if (entity->function == MEDIA_ENT_F_ATV_DECODER) | |
232 | decoder = entity; | |
233 | } | |
234 | goto create_link; | |
235 | } | |
f90c5d79 SK |
236 | |
237 | switch (new->function) { | |
238 | case MEDIA_ENT_F_AUDIO_MIXER: | |
9096cae1 SK |
239 | mixer = new; |
240 | if (dev->decoder) | |
241 | decoder = dev->decoder; | |
242 | break; | |
243 | case MEDIA_ENT_F_ATV_DECODER: | |
244 | /* In case, Mixer is added first, find mixer and create link */ | |
245 | media_device_for_each_entity(entity, dev->media_dev) { | |
246 | if (entity->function == MEDIA_ENT_F_AUDIO_MIXER) | |
247 | mixer = entity; | |
248 | } | |
249 | decoder = new; | |
250 | break; | |
251 | default: | |
252 | break; | |
253 | } | |
254 | ||
255 | create_link: | |
256 | if (decoder && mixer) { | |
257 | ret = media_create_pad_link(decoder, | |
bddc4187 | 258 | DEMOD_PAD_AUDIO_OUT, |
9096cae1 | 259 | mixer, 0, |
f90c5d79 SK |
260 | MEDIA_LNK_FL_ENABLED); |
261 | if (ret) | |
262 | dev_err(&dev->usbdev->dev, | |
9096cae1 | 263 | "Mixer Pad Link Create Error: %d\n", ret); |
f90c5d79 | 264 | } |
f90c5d79 SK |
265 | } |
266 | ||
c94903f1 SK |
267 | static int au0828_enable_source(struct media_entity *entity, |
268 | struct media_pipeline *pipe) | |
269 | { | |
c94903f1 SK |
270 | struct media_entity *source, *find_source; |
271 | struct media_entity *sink; | |
272 | struct media_link *link, *found_link = NULL; | |
273 | int ret = 0; | |
274 | struct media_device *mdev = entity->graph_obj.mdev; | |
275 | struct au0828_dev *dev; | |
276 | ||
277 | if (!mdev) | |
278 | return -ENODEV; | |
279 | ||
280 | mutex_lock(&mdev->graph_mutex); | |
281 | ||
282 | dev = mdev->source_priv; | |
283 | ||
284 | /* | |
285 | * For Audio and V4L2 entity, find the link to which decoder | |
286 | * is the sink. Look for an active link between decoder and | |
287 | * source (tuner/s-video/Composite), if one exists, nothing | |
288 | * to do. If not, look for any active links between source | |
289 | * and any other entity. If one exists, source is busy. If | |
290 | * source is free, setup link and start pipeline from source. | |
291 | * For DVB FE entity, the source for the link is the tuner. | |
292 | * Check if tuner is available and setup link and start | |
293 | * pipeline. | |
294 | */ | |
295 | if (entity->function == MEDIA_ENT_F_DTV_DEMOD) { | |
296 | sink = entity; | |
297 | find_source = dev->tuner; | |
298 | } else { | |
299 | /* Analog isn't configured or register failed */ | |
300 | if (!dev->decoder) { | |
301 | ret = -ENODEV; | |
302 | goto end; | |
303 | } | |
304 | ||
305 | sink = dev->decoder; | |
306 | ||
307 | /* | |
308 | * Default input is tuner and default input_type | |
309 | * is AU0828_VMUX_TELEVISION. | |
310 | * FIXME: | |
311 | * There is a problem when s_input is called to | |
312 | * change the default input. s_input will try to | |
313 | * enable_source before attempting to change the | |
314 | * input on the device, and will end up enabling | |
315 | * default source which is tuner. | |
316 | * | |
317 | * Additional logic is necessary in au0828 | |
318 | * to detect that the input has changed and | |
319 | * enable the right source. | |
320 | */ | |
321 | ||
322 | if (dev->input_type == AU0828_VMUX_TELEVISION) | |
323 | find_source = dev->tuner; | |
324 | else if (dev->input_type == AU0828_VMUX_SVIDEO || | |
325 | dev->input_type == AU0828_VMUX_COMPOSITE) | |
326 | find_source = &dev->input_ent[dev->input_type]; | |
327 | else { | |
328 | /* unknown input - let user select input */ | |
329 | ret = 0; | |
330 | goto end; | |
331 | } | |
332 | } | |
333 | ||
334 | /* Is an active link between sink and source */ | |
335 | if (dev->active_link) { | |
336 | /* | |
337 | * If DVB is using the tuner and calling entity is | |
338 | * audio/video, the following check will be false, | |
339 | * since sink is different. Result is Busy. | |
340 | */ | |
341 | if (dev->active_link->sink->entity == sink && | |
342 | dev->active_link->source->entity == find_source) { | |
343 | /* | |
344 | * Either ALSA or Video own tuner. sink is | |
345 | * the same for both. Prevent Video stepping | |
346 | * on ALSA when ALSA owns the source. | |
347 | */ | |
348 | if (dev->active_link_owner != entity && | |
349 | dev->active_link_owner->function == | |
350 | MEDIA_ENT_F_AUDIO_CAPTURE) { | |
351 | pr_debug("ALSA has the tuner\n"); | |
352 | ret = -EBUSY; | |
353 | goto end; | |
354 | } | |
355 | ret = 0; | |
356 | goto end; | |
357 | } else { | |
358 | ret = -EBUSY; | |
359 | goto end; | |
360 | } | |
361 | } | |
362 | ||
363 | list_for_each_entry(link, &sink->links, list) { | |
364 | /* Check sink, and source */ | |
365 | if (link->sink->entity == sink && | |
366 | link->source->entity == find_source) { | |
367 | found_link = link; | |
368 | break; | |
369 | } | |
370 | } | |
371 | ||
372 | if (!found_link) { | |
373 | ret = -ENODEV; | |
374 | goto end; | |
375 | } | |
376 | ||
377 | /* activate link between source and sink and start pipeline */ | |
378 | source = found_link->source->entity; | |
379 | ret = __media_entity_setup_link(found_link, MEDIA_LNK_FL_ENABLED); | |
380 | if (ret) { | |
381 | pr_err("Activate tuner link %s->%s. Error %d\n", | |
382 | source->name, sink->name, ret); | |
383 | goto end; | |
384 | } | |
385 | ||
386 | ret = __media_entity_pipeline_start(entity, pipe); | |
387 | if (ret) { | |
388 | pr_err("Start Pipeline: %s->%s Error %d\n", | |
389 | source->name, entity->name, ret); | |
390 | ret = __media_entity_setup_link(found_link, 0); | |
391 | pr_err("Deactivate link Error %d\n", ret); | |
392 | goto end; | |
393 | } | |
394 | /* | |
395 | * save active link and active link owner to avoid audio | |
396 | * deactivating video owned link from disable_source and | |
397 | * vice versa | |
398 | */ | |
399 | dev->active_link = found_link; | |
400 | dev->active_link_owner = entity; | |
401 | dev->active_source = source; | |
402 | dev->active_sink = sink; | |
403 | ||
404 | pr_debug("Enabled Source: %s->%s->%s Ret %d\n", | |
405 | dev->active_source->name, dev->active_sink->name, | |
406 | dev->active_link_owner->name, ret); | |
407 | end: | |
408 | mutex_unlock(&mdev->graph_mutex); | |
409 | pr_debug("au0828_enable_source() end %s %d %d\n", | |
410 | entity->name, entity->function, ret); | |
411 | return ret; | |
c94903f1 SK |
412 | } |
413 | ||
414 | static void au0828_disable_source(struct media_entity *entity) | |
415 | { | |
c94903f1 SK |
416 | int ret = 0; |
417 | struct media_device *mdev = entity->graph_obj.mdev; | |
418 | struct au0828_dev *dev; | |
419 | ||
420 | if (!mdev) | |
421 | return; | |
422 | ||
423 | mutex_lock(&mdev->graph_mutex); | |
424 | dev = mdev->source_priv; | |
425 | ||
426 | if (!dev->active_link) { | |
427 | ret = -ENODEV; | |
428 | goto end; | |
429 | } | |
430 | ||
431 | /* link is active - stop pipeline from source (tuner) */ | |
432 | if (dev->active_link->sink->entity == dev->active_sink && | |
433 | dev->active_link->source->entity == dev->active_source) { | |
434 | /* | |
435 | * prevent video from deactivating link when audio | |
436 | * has active pipeline | |
437 | */ | |
438 | if (dev->active_link_owner != entity) | |
439 | goto end; | |
440 | __media_entity_pipeline_stop(entity); | |
441 | ret = __media_entity_setup_link(dev->active_link, 0); | |
442 | if (ret) | |
443 | pr_err("Deactivate link Error %d\n", ret); | |
444 | ||
445 | pr_debug("Disabled Source: %s->%s->%s Ret %d\n", | |
446 | dev->active_source->name, dev->active_sink->name, | |
447 | dev->active_link_owner->name, ret); | |
448 | ||
449 | dev->active_link = NULL; | |
450 | dev->active_link_owner = NULL; | |
451 | dev->active_source = NULL; | |
452 | dev->active_sink = NULL; | |
453 | } | |
454 | ||
455 | end: | |
456 | mutex_unlock(&mdev->graph_mutex); | |
c94903f1 | 457 | } |
0a82edd0 | 458 | #endif |
c94903f1 | 459 | |
7b12adf6 SK |
460 | static int au0828_media_device_register(struct au0828_dev *dev, |
461 | struct usb_device *udev) | |
462 | { | |
463 | #ifdef CONFIG_MEDIA_CONTROLLER | |
464 | int ret; | |
2e208c64 MCC |
465 | struct media_entity *entity, *demod = NULL; |
466 | struct media_link *link; | |
7b12adf6 | 467 | |
f90c5d79 SK |
468 | if (!dev->media_dev) |
469 | return 0; | |
470 | ||
471 | if (!media_devnode_is_registered(&dev->media_dev->devnode)) { | |
7b12adf6 SK |
472 | |
473 | /* register media device */ | |
474 | ret = media_device_register(dev->media_dev); | |
475 | if (ret) { | |
476 | dev_err(&udev->dev, | |
477 | "Media Device Register Error: %d\n", ret); | |
478 | return ret; | |
479 | } | |
9096cae1 SK |
480 | } else { |
481 | /* | |
482 | * Call au0828_media_graph_notify() to connect | |
483 | * audio graph to our graph. In this case, audio | |
484 | * driver registered the device and there is no | |
485 | * entity_notify to be called when new entities | |
486 | * are added. Invoke it now. | |
487 | */ | |
488 | au0828_media_graph_notify(NULL, (void *) dev); | |
7b12adf6 | 489 | } |
840f5b05 SK |
490 | |
491 | /* | |
2e208c64 MCC |
492 | * Find tuner, decoder and demod. |
493 | * | |
494 | * The tuner and decoder should be cached, as they'll be used by | |
495 | * au0828_enable_source. | |
496 | * | |
497 | * It also needs to disable the link between tuner and | |
498 | * decoder/demod, to avoid disable step when tuner is requested | |
499 | * by video or audio. Note that this step can't be done until dvb | |
500 | * graph is created during dvb register. | |
840f5b05 SK |
501 | */ |
502 | media_device_for_each_entity(entity, dev->media_dev) { | |
2e208c64 MCC |
503 | switch (entity->function) { |
504 | case MEDIA_ENT_F_TUNER: | |
505 | dev->tuner = entity; | |
506 | break; | |
507 | case MEDIA_ENT_F_ATV_DECODER: | |
508 | dev->decoder = entity; | |
509 | break; | |
510 | case MEDIA_ENT_F_DTV_DEMOD: | |
840f5b05 | 511 | demod = entity; |
2e208c64 MCC |
512 | break; |
513 | } | |
840f5b05 | 514 | } |
840f5b05 | 515 | |
2e208c64 MCC |
516 | /* Disable link between tuner->demod and/or tuner->decoder */ |
517 | if (dev->tuner) { | |
518 | list_for_each_entry(link, &dev->tuner->links, list) { | |
519 | if (demod && link->sink->entity == demod) | |
520 | media_entity_setup_link(link, 0); | |
521 | if (dev->decoder && link->sink->entity == dev->decoder) | |
840f5b05 | 522 | media_entity_setup_link(link, 0); |
840f5b05 SK |
523 | } |
524 | } | |
525 | ||
f90c5d79 SK |
526 | /* register entity_notify callback */ |
527 | dev->entity_notify.notify_data = (void *) dev; | |
528 | dev->entity_notify.notify = (void *) au0828_media_graph_notify; | |
529 | ret = media_device_register_entity_notify(dev->media_dev, | |
530 | &dev->entity_notify); | |
531 | if (ret) { | |
532 | dev_err(&udev->dev, | |
533 | "Media Device register entity_notify Error: %d\n", | |
534 | ret); | |
535 | return ret; | |
536 | } | |
c94903f1 SK |
537 | /* set enable_source */ |
538 | dev->media_dev->source_priv = (void *) dev; | |
539 | dev->media_dev->enable_source = au0828_enable_source; | |
540 | dev->media_dev->disable_source = au0828_disable_source; | |
7b12adf6 SK |
541 | #endif |
542 | return 0; | |
543 | } | |
bed69196 | 544 | |
18d73c58 | 545 | static int au0828_usb_probe(struct usb_interface *interface, |
265a6510 ST |
546 | const struct usb_device_id *id) |
547 | { | |
8a4e7866 | 548 | int ifnum; |
f251b3e7 TM |
549 | int retval = 0; |
550 | ||
265a6510 ST |
551 | struct au0828_dev *dev; |
552 | struct usb_device *usbdev = interface_to_usbdev(interface); | |
553 | ||
554 | ifnum = interface->altsetting->desc.bInterfaceNumber; | |
555 | ||
556 | if (ifnum != 0) | |
557 | return -ENODEV; | |
558 | ||
a9c36aad | 559 | dprintk(1, "%s() vendor id 0x%x device id 0x%x ifnum:%d\n", __func__, |
265a6510 ST |
560 | le16_to_cpu(usbdev->descriptor.idVendor), |
561 | le16_to_cpu(usbdev->descriptor.idProduct), | |
562 | ifnum); | |
563 | ||
ee3436b8 DH |
564 | /* |
565 | * Make sure we have 480 Mbps of bandwidth, otherwise things like | |
566 | * video stream wouldn't likely work, since 12 Mbps is generally | |
567 | * not enough even for most Digital TV streams. | |
568 | */ | |
d6a9a430 | 569 | if (usbdev->speed != USB_SPEED_HIGH && disable_usb_speed_check == 0) { |
83afb32a MCC |
570 | pr_err("au0828: Device initialization failed.\n"); |
571 | pr_err("au0828: Device must be connected to a high-speed USB 2.0 port.\n"); | |
ee3436b8 DH |
572 | return -ENODEV; |
573 | } | |
574 | ||
265a6510 ST |
575 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
576 | if (dev == NULL) { | |
83afb32a | 577 | pr_err("%s() Unable to allocate memory\n", __func__); |
265a6510 ST |
578 | return -ENOMEM; |
579 | } | |
580 | ||
549ee4df DH |
581 | mutex_init(&dev->lock); |
582 | mutex_lock(&dev->lock); | |
265a6510 ST |
583 | mutex_init(&dev->mutex); |
584 | mutex_init(&dev->dvb.lock); | |
585 | dev->usbdev = usbdev; | |
f1add5b5 | 586 | dev->boardnr = id->driver_info; |
e42c8c6e RLLC |
587 | dev->board = au0828_boards[dev->boardnr]; |
588 | ||
9832e155 | 589 | /* Initialize the media controller */ |
9f806795 MCC |
590 | retval = au0828_media_device_init(dev, usbdev); |
591 | if (retval) { | |
592 | pr_err("%s() au0828_media_device_init failed\n", | |
593 | __func__); | |
594 | mutex_unlock(&dev->lock); | |
595 | kfree(dev); | |
596 | return retval; | |
597 | } | |
265a6510 | 598 | |
7b606ffd | 599 | retval = au0828_v4l2_device_register(interface, dev); |
b14667f3 | 600 | if (retval) { |
7b606ffd | 601 | au0828_usb_v4l2_media_release(dev); |
549ee4df | 602 | mutex_unlock(&dev->lock); |
b14667f3 | 603 | kfree(dev); |
e8c26f45 | 604 | return retval; |
b14667f3 DH |
605 | } |
606 | ||
265a6510 ST |
607 | /* Power Up the bridge */ |
608 | au0828_write(dev, REG_600, 1 << 4); | |
609 | ||
610 | /* Bring up the GPIO's and supporting devices */ | |
611 | au0828_gpio_setup(dev); | |
612 | ||
613 | /* I2C */ | |
614 | au0828_i2c_register(dev); | |
615 | ||
28930fa9 ST |
616 | /* Setup */ |
617 | au0828_card_setup(dev); | |
618 | ||
8b2f0795 | 619 | /* Analog TV */ |
7b606ffd MCC |
620 | retval = au0828_analog_register(dev, interface); |
621 | if (retval) { | |
622 | pr_err("%s() au0282_dev_register failed to register on V4L2\n", | |
623 | __func__); | |
624 | goto done; | |
82e92f4c | 625 | } |
8b2f0795 | 626 | |
265a6510 | 627 | /* Digital TV */ |
f251b3e7 TM |
628 | retval = au0828_dvb_register(dev); |
629 | if (retval) | |
630 | pr_err("%s() au0282_dev_register failed\n", | |
631 | __func__); | |
632 | ||
2fcfd317 MCC |
633 | /* Remote controller */ |
634 | au0828_rc_register(dev); | |
265a6510 | 635 | |
2fcfd317 MCC |
636 | /* |
637 | * Store the pointer to the au0828_dev so it can be accessed in | |
638 | * au0828_usb_disconnect | |
639 | */ | |
fe78a49c DH |
640 | usb_set_intfdata(interface, dev); |
641 | ||
83afb32a | 642 | pr_info("Registered device AU0828 [%s]\n", |
f1add5b5 | 643 | dev->board.name == NULL ? "Unset" : dev->board.name); |
265a6510 | 644 | |
549ee4df DH |
645 | mutex_unlock(&dev->lock); |
646 | ||
7b12adf6 | 647 | retval = au0828_media_device_register(dev, usbdev); |
9832e155 JMC |
648 | |
649 | done: | |
650 | if (retval < 0) | |
651 | au0828_usb_disconnect(interface); | |
652 | ||
f251b3e7 | 653 | return retval; |
265a6510 ST |
654 | } |
655 | ||
aaeac199 MCC |
656 | static int au0828_suspend(struct usb_interface *interface, |
657 | pm_message_t message) | |
658 | { | |
659 | struct au0828_dev *dev = usb_get_intfdata(interface); | |
660 | ||
661 | if (!dev) | |
662 | return 0; | |
663 | ||
81187240 MCC |
664 | pr_info("Suspend\n"); |
665 | ||
aaeac199 | 666 | au0828_rc_suspend(dev); |
1a1ba95e | 667 | au0828_v4l2_suspend(dev); |
b799de75 | 668 | au0828_dvb_suspend(dev); |
aaeac199 MCC |
669 | |
670 | /* FIXME: should suspend also ATV/DTV */ | |
671 | ||
672 | return 0; | |
673 | } | |
674 | ||
675 | static int au0828_resume(struct usb_interface *interface) | |
676 | { | |
677 | struct au0828_dev *dev = usb_get_intfdata(interface); | |
678 | if (!dev) | |
679 | return 0; | |
680 | ||
81187240 MCC |
681 | pr_info("Resume\n"); |
682 | ||
fa500461 MCC |
683 | /* Power Up the bridge */ |
684 | au0828_write(dev, REG_600, 1 << 4); | |
685 | ||
686 | /* Bring up the GPIO's and supporting devices */ | |
687 | au0828_gpio_setup(dev); | |
688 | ||
aaeac199 | 689 | au0828_rc_resume(dev); |
1a1ba95e | 690 | au0828_v4l2_resume(dev); |
b799de75 | 691 | au0828_dvb_resume(dev); |
aaeac199 MCC |
692 | |
693 | /* FIXME: should resume also ATV/DTV */ | |
694 | ||
695 | return 0; | |
696 | } | |
697 | ||
265a6510 | 698 | static struct usb_driver au0828_usb_driver = { |
83afb32a | 699 | .name = KBUILD_MODNAME, |
265a6510 ST |
700 | .probe = au0828_usb_probe, |
701 | .disconnect = au0828_usb_disconnect, | |
702 | .id_table = au0828_usb_id_table, | |
aaeac199 MCC |
703 | .suspend = au0828_suspend, |
704 | .resume = au0828_resume, | |
705 | .reset_resume = au0828_resume, | |
265a6510 ST |
706 | }; |
707 | ||
708 | static int __init au0828_init(void) | |
709 | { | |
710 | int ret; | |
711 | ||
b33d24c4 | 712 | if (au0828_debug & 1) |
83afb32a | 713 | pr_info("%s() Debugging is enabled\n", __func__); |
bc3c613c | 714 | |
b33d24c4 | 715 | if (au0828_debug & 2) |
83afb32a | 716 | pr_info("%s() USB Debugging is enabled\n", __func__); |
bc3c613c | 717 | |
b33d24c4 | 718 | if (au0828_debug & 4) |
83afb32a | 719 | pr_info("%s() I2C Debugging is enabled\n", __func__); |
bc3c613c | 720 | |
b33d24c4 | 721 | if (au0828_debug & 8) |
83afb32a | 722 | pr_info("%s() Bridge Debugging is enabled\n", |
f07e8e4b | 723 | __func__); |
bc3c613c | 724 | |
2fcfd317 | 725 | if (au0828_debug & 16) |
83afb32a | 726 | pr_info("%s() IR Debugging is enabled\n", |
2fcfd317 MCC |
727 | __func__); |
728 | ||
83afb32a | 729 | pr_info("au0828 driver loaded\n"); |
265a6510 ST |
730 | |
731 | ret = usb_register(&au0828_usb_driver); | |
732 | if (ret) | |
83afb32a | 733 | pr_err("usb_register failed, error = %d\n", ret); |
265a6510 ST |
734 | |
735 | return ret; | |
736 | } | |
737 | ||
738 | static void __exit au0828_exit(void) | |
739 | { | |
740 | usb_deregister(&au0828_usb_driver); | |
741 | } | |
742 | ||
743 | module_init(au0828_init); | |
744 | module_exit(au0828_exit); | |
745 | ||
746 | MODULE_DESCRIPTION("Driver for Auvitek AU0828 based products"); | |
6d897616 | 747 | MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>"); |
265a6510 | 748 | MODULE_LICENSE("GPL"); |
2fcfd317 | 749 | MODULE_VERSION("0.0.3"); |