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