staticint send_control_msg(struct au0828_dev *dev, u16 request, u32 value,
u16 index)
{ int status = -ENODEV;
if (dev->usbdev) {
/* cp must be memory that has been allocated by kmalloc */
status = usb_control_msg(dev->usbdev,
usb_sndctrlpipe(dev->usbdev, 0),
request,
USB_DIR_OUT | USB_TYPE_VENDOR |
USB_RECIP_DEVICE,
value, index, NULL, 0, 1000);
status = min(status, 0);
if (status < 0) {
pr_err("%s() Failed sending control message, error %d.\n",
__func__, status);
}
}
return status;
}
staticint recv_control_msg(struct au0828_dev *dev, u16 request, u32 value,
u16 index, unsignedchar *cp, u16 size)
{ int status = -ENODEV;
mutex_lock(&dev->mutex); if (dev->usbdev) {
status = usb_control_msg(dev->usbdev,
usb_rcvctrlpipe(dev->usbdev, 0),
request,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
value, index,
dev->ctrlmsg, size, 1000);
status = min(status, 0);
if (status < 0) {
pr_err("%s() Failed receiving control message, error %d.\n",
__func__, status);
}
/* the host controller requires heap allocated memory, which
is why we didn't just pass "cp" into usb_control_msg */
memcpy(cp, dev->ctrlmsg, size);
}
mutex_unlock(&dev->mutex); return status;
}
/* there is a small window after disconnect, before dev->usbdev is NULL, for poll (e.g: IR) try to access the device and fill the dmesg with error messages. Set the status so poll routines can check and avoid access after disconnect.
*/
set_bit(DEV_DISCONNECTED, &dev->dev_state);
au0828_rc_unregister(dev); /* Digital TV */
au0828_dvb_unregister(dev);
usb_set_intfdata(interface, NULL);
mutex_lock(&dev->mutex);
dev->usbdev = NULL;
mutex_unlock(&dev->mutex); if (au0828_analog_unregister(dev)) { /* * No need to call au0828_usb_release() if V4L2 is enabled, * as this is already called via au0828_usb_v4l2_release()
*/ return;
}
au0828_usb_release(dev);
}
if (!new) { /* * Called during au0828 probe time to connect * entities that were created prior to registering * the notify handler. Find mixer and decoder.
*/
media_device_for_each_entity(entity, dev->media_dev) { if (entity->function == MEDIA_ENT_F_AUDIO_MIXER)
mixer = entity; elseif (entity->function == MEDIA_ENT_F_ATV_DECODER)
decoder = entity;
} goto create_link;
}
switch (new->function) { case MEDIA_ENT_F_AUDIO_MIXER:
mixer = new; if (dev->decoder)
decoder = dev->decoder; break; case MEDIA_ENT_F_ATV_DECODER: /* In case, Mixer is added first, find mixer and create link */
media_device_for_each_entity(entity, dev->media_dev) { if (entity->function == MEDIA_ENT_F_AUDIO_MIXER)
mixer = entity;
}
decoder = new; break; default: break;
}
create_link: if (decoder && mixer) {
ret = media_get_pad_index(decoder, MEDIA_PAD_FL_SOURCE,
PAD_SIGNAL_AUDIO); if (ret >= 0)
ret = media_create_pad_link(decoder, ret,
mixer, 0,
MEDIA_LNK_FL_ENABLED); if (ret < 0)
dev_err(&dev->usbdev->dev, "Mixer Pad Link Create Error: %d\n", ret);
}
}
/* Tuner link can be shared by audio, video, and VBI */ switch (owner->function) { case MEDIA_ENT_F_IO_V4L: case MEDIA_ENT_F_AUDIO_CAPTURE: case MEDIA_ENT_F_IO_VBI: if (entity->function == MEDIA_ENT_F_IO_V4L ||
entity->function == MEDIA_ENT_F_AUDIO_CAPTURE ||
entity->function == MEDIA_ENT_F_IO_VBI)
shareable = true; break; case MEDIA_ENT_F_DTV_DEMOD: default: break;
} return shareable;
}
/* Callers should hold graph_mutex */ staticint au0828_enable_source(struct media_entity *entity, struct media_pipeline *pipe)
{ struct media_entity *source, *find_source; struct media_entity *sink; struct media_link *link, *found_link = NULL; int ret = 0; struct media_device *mdev = entity->graph_obj.mdev; struct au0828_dev *dev;
if (!mdev) return -ENODEV;
dev = mdev->source_priv;
/* * For Audio and V4L2 entity, find the link to which decoder * is the sink. Look for an active link between decoder and * source (tuner/s-video/Composite), if one exists, nothing * to do. If not, look for any active links between source * and any other entity. If one exists, source is busy. If * source is free, setup link and start pipeline from source. * For DVB FE entity, the source for the link is the tuner. * Check if tuner is available and setup link and start * pipeline.
*/ if (entity->function == MEDIA_ENT_F_DTV_DEMOD) {
sink = entity;
find_source = dev->tuner;
} else { /* Analog isn't configured or register failed */ if (!dev->decoder) {
ret = -ENODEV; goto end;
}
sink = dev->decoder;
/* * Default input is tuner and default input_type * is AU0828_VMUX_TELEVISION. * * There is a problem when s_input is called to * change the default input. s_input will try to * enable_source before attempting to change the * input on the device, and will end up enabling * default source which is tuner. * * Additional logic is necessary in au0828 to detect * that the input has changed and enable the right * source. au0828 handles this case in its s_input. * It will disable the old source and enable the new * source. *
*/ if (dev->input_type == AU0828_VMUX_TELEVISION)
find_source = dev->tuner; elseif (dev->input_type == AU0828_VMUX_SVIDEO ||
dev->input_type == AU0828_VMUX_COMPOSITE)
find_source = &dev->input_ent[dev->input_type]; else { /* unknown input - let user select input */
ret = 0; goto end;
}
}
/* Is there an active link between sink and source */ if (dev->active_link) { if (dev->active_link_owner == entity) { /* This check is necessary to handle multiple * enable_source calls from v4l_ioctls during * the course of video/vbi application run-time.
*/
pr_debug("%s already owns the tuner\n", entity->name);
ret = 0; goto end;
} elseif (au0828_is_link_shareable(dev->active_link_owner,
entity)) { /* Either ALSA or Video own tuner. Sink is the same * for both. Allow sharing the active link between * their common source (tuner) and sink (decoder). * Starting pipeline between sharing entity and sink * will fail with pipe mismatch, while owner has an * active pipeline. Switch pipeline ownership from * user to owner when owner disables the source.
*/
dev->active_link_shared = true; /* save the user info to use from disable */
dev->active_link_user = entity;
dev->active_link_user_pipe = pipe;
pr_debug("%s owns the tuner %s can share!\n",
dev->active_link_owner->name,
entity->name);
ret = 0; goto end;
} else {
ret = -EBUSY; goto end;
}
}
/* activate link between source and sink and start pipeline */
source = found_link->source->entity;
ret = __media_entity_setup_link(found_link, MEDIA_LNK_FL_ENABLED); if (ret) {
pr_err("Activate link from %s->%s. Error %d\n",
source->name, sink->name, ret); goto end;
}
ret = __media_pipeline_start(entity->pads, pipe); if (ret) {
pr_err("Start Pipeline: %s->%s Error %d\n",
source->name, entity->name, ret);
ret = __media_entity_setup_link(found_link, 0); if (ret)
pr_err("Deactivate link Error %d\n", ret); goto end;
}
/* save link state to allow audio and video share the link * and not disable the link while the other is using it. * active_link_owner is used to deactivate the link.
*/
dev->active_link = found_link;
dev->active_link_owner = entity;
dev->active_source = source;
dev->active_sink = sink;
/* Callers should hold graph_mutex */ staticvoid au0828_disable_source(struct media_entity *entity)
{ int ret = 0; struct media_device *mdev = entity->graph_obj.mdev; struct au0828_dev *dev;
if (!mdev) return;
dev = mdev->source_priv;
if (!dev->active_link) return;
/* link is active - stop pipeline from source * (tuner/s-video/Composite) to the entity * When DVB/s-video/Composite owns tuner, it won't be in * shared state.
*/ if (dev->active_link->sink->entity == dev->active_sink &&
dev->active_link->source->entity == dev->active_source) { /* * Prevent video from deactivating link when audio * has active pipeline and vice versa. In addition * handle the case when more than one video/vbi * application is sharing the link.
*/ bool owner_is_audio = false;
if (dev->active_link_owner->function ==
MEDIA_ENT_F_AUDIO_CAPTURE)
owner_is_audio = true;
if (dev->active_link_shared) {
pr_debug("Shared link owner %s user %s %d\n",
dev->active_link_owner->name,
entity->name, dev->users);
/* Handle video device users > 1 * When audio owns the shared link with * more than one video users, avoid * disabling the source and/or switching * the owner until the last disable_source * call from video _close(). Use dev->users to * determine when to switch/disable.
*/ if (dev->active_link_owner != entity) { /* video device has users > 1 */ if (owner_is_audio && dev->users > 1) return;
/* video owns the link and has users > 1 */ if (!owner_is_audio && dev->users > 1) return;
/* stop pipeline */
__media_pipeline_stop(dev->active_link_owner->pads);
pr_debug("Pipeline stop for %s\n",
dev->active_link_owner->name);
ret = __media_pipeline_start(
dev->active_link_user->pads,
dev->active_link_user_pipe); if (ret) {
pr_err("Start Pipeline: %s->%s %d\n",
dev->active_source->name,
dev->active_link_user->name,
ret); goto deactivate_link;
} /* link user is now the owner */
dev->active_link_owner = dev->active_link_user;
dev->active_link_user = NULL;
dev->active_link_user_pipe = NULL;
dev->active_link_shared = false;
pr_debug("Pipeline started for %s\n",
dev->active_link_owner->name); return;
} elseif (!owner_is_audio && dev->users > 1) /* video/vbi owns the link and has users > 1 */ return;
if (dev->active_link_owner != entity) return;
/* stop pipeline */
__media_pipeline_stop(dev->active_link_owner->pads);
pr_debug("Pipeline stop for %s\n",
dev->active_link_owner->name);
deactivate_link:
ret = __media_entity_setup_link(dev->active_link, 0); if (ret)
pr_err("Deactivate link Error %d\n", ret);
pr_info("Disabled Source: %s->%s->%s Ret %d\n",
dev->active_source->name, dev->active_sink->name,
dev->active_link_owner->name, ret);
if (!media_devnode_is_registered(dev->media_dev->devnode)) {
/* register media device */
ret = media_device_register(dev->media_dev); if (ret) {
media_device_delete(dev->media_dev, KBUILD_MODNAME,
THIS_MODULE);
dev->media_dev = NULL;
dev_err(&udev->dev, "Media Device Register Error: %d\n", ret); return ret;
}
} else { /* * Call au0828_media_graph_notify() to connect * audio graph to our graph. In this case, audio * driver registered the device and there is no * entity_notify to be called when new entities * are added. Invoke it now.
*/
au0828_media_graph_notify(NULL, (void *) dev);
}
/* * Find tuner, decoder and demod. * * The tuner and decoder should be cached, as they'll be used by * au0828_enable_source. * * It also needs to disable the link between tuner and * decoder/demod, to avoid disable step when tuner is requested * by video or audio. Note that this step can't be done until dvb * graph is created during dvb register.
*/
media_device_for_each_entity(entity, dev->media_dev) { switch (entity->function) { case MEDIA_ENT_F_TUNER:
dev->tuner = entity; break; case MEDIA_ENT_F_ATV_DECODER:
dev->decoder = entity; break; case MEDIA_ENT_F_DTV_DEMOD:
demod = entity; break;
}
}
/* Disable link between tuner->demod and/or tuner->decoder */ if (dev->tuner) {
list_for_each_entry(link, &dev->tuner->links, list) { if (demod && link->sink->entity == demod)
media_entity_setup_link(link, 0); if (dev->decoder && link->sink->entity == dev->decoder)
media_entity_setup_link(link, 0);
}
}
dprintk(1, "%s() vendor id 0x%x device id 0x%x ifnum:%d\n", __func__,
le16_to_cpu(usbdev->descriptor.idVendor),
le16_to_cpu(usbdev->descriptor.idProduct),
ifnum);
/* * Make sure we have 480 Mbps of bandwidth, otherwise things like * video stream wouldn't likely work, since 12 Mbps is generally * not enough even for most Digital TV streams.
*/ if (usbdev->speed != USB_SPEED_HIGH && disable_usb_speed_check == 0) {
pr_err("au0828: Device initialization failed.\n");
pr_err("au0828: Device must be connected to a high-speed USB 2.0 port.\n"); return -ENODEV;
}
dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (dev == NULL) {
pr_err("%s() Unable to allocate memory\n", __func__); return -ENOMEM;
}
/* Power Up the bridge */
au0828_write(dev, REG_600, 1 << 4);
/* Bring up the GPIO's and supporting devices */
au0828_gpio_setup(dev);
/* I2C */
au0828_i2c_register(dev);
/* Setup */
au0828_card_setup(dev);
/* * Store the pointer to the au0828_dev so it can be accessed in * au0828_usb_disconnect
*/
usb_set_intfdata(interface, dev);
/* Analog TV */
retval = au0828_analog_register(dev, interface); if (retval) {
pr_err("%s() au0828_analog_register failed to register on V4L2\n",
__func__);
mutex_unlock(&dev->lock); goto done;
}
/* Digital TV */
retval = au0828_dvb_register(dev); if (retval)
pr_err("%s() au0828_dvb_register failed\n",
__func__);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.