Commit 812658d8 authored by Shuah Khan's avatar Shuah Khan Committed by Mauro Carvalho Chehab

media: change au0828 to use Media Device Allocator API

Media Device Allocator API to allows multiple drivers share a media device.
This API solves a very common use-case for media devices where one physical
device (an USB stick) provides both audio and video. When such media device
exposes a standard USB Audio class, a proprietary Video class, two or more
independent drivers will share a single physical USB bridge. In such cases,
it is necessary to coordinate access to the shared resource.

Using this API, drivers can allocate a media device with the shared struct
device as the key. Once the media device is allocated by a driver, other
drivers can get a reference to it. The media device is released when all
the references are released.

Change au0828 to use Media Device Allocator API to allocate media device
with the parent usb struct device as the key, so it can be shared with the
snd_usb_audio driver.
Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 6e1d824e
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
config VIDEO_AU0828 config VIDEO_AU0828
tristate "Auvitek AU0828 support" tristate "Auvitek AU0828 support"
depends on I2C && INPUT && DVB_CORE && USB && VIDEO_V4L2 depends on I2C && INPUT && DVB_CORE && USB && VIDEO_V4L2
select MEDIA_CONTROLLER
select MEDIA_CONTROLLER_DVB
select I2C_ALGOBIT select I2C_ALGOBIT
select VIDEO_TVEEPROM select VIDEO_TVEEPROM
select VIDEOBUF2_VMALLOC if VIDEO_V4L2 select VIDEOBUF2_VMALLOC if VIDEO_V4L2
......
...@@ -155,9 +155,7 @@ static void au0828_unregister_media_device(struct au0828_dev *dev) ...@@ -155,9 +155,7 @@ static void au0828_unregister_media_device(struct au0828_dev *dev)
dev->media_dev->disable_source = NULL; dev->media_dev->disable_source = NULL;
mutex_unlock(&mdev->graph_mutex); mutex_unlock(&mdev->graph_mutex);
media_device_unregister(dev->media_dev); media_device_delete(dev->media_dev, KBUILD_MODNAME, THIS_MODULE);
media_device_cleanup(dev->media_dev);
kfree(dev->media_dev);
dev->media_dev = NULL; dev->media_dev = NULL;
#endif #endif
} }
...@@ -210,14 +208,10 @@ static int au0828_media_device_init(struct au0828_dev *dev, ...@@ -210,14 +208,10 @@ static int au0828_media_device_init(struct au0828_dev *dev,
#ifdef CONFIG_MEDIA_CONTROLLER #ifdef CONFIG_MEDIA_CONTROLLER
struct media_device *mdev; struct media_device *mdev;
mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); mdev = media_device_usb_allocate(udev, KBUILD_MODNAME, THIS_MODULE);
if (!mdev) if (!mdev)
return -ENOMEM; return -ENOMEM;
/* check if media device is already initialized */
if (!mdev->dev)
media_device_usb_init(mdev, udev, udev->product);
dev->media_dev = mdev; dev->media_dev = mdev;
#endif #endif
return 0; return 0;
...@@ -480,6 +474,9 @@ static int au0828_media_device_register(struct au0828_dev *dev, ...@@ -480,6 +474,9 @@ static int au0828_media_device_register(struct au0828_dev *dev,
/* register media device */ /* register media device */
ret = media_device_register(dev->media_dev); ret = media_device_register(dev->media_dev);
if (ret) { if (ret) {
media_device_delete(dev->media_dev, KBUILD_MODNAME,
THIS_MODULE);
dev->media_dev = NULL;
dev_err(&udev->dev, dev_err(&udev->dev,
"Media Device Register Error: %d\n", ret); "Media Device Register Error: %d\n", ret);
return ret; return ret;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <media/v4l2-ctrls.h> #include <media/v4l2-ctrls.h>
#include <media/v4l2-fh.h> #include <media/v4l2-fh.h>
#include <media/media-device.h> #include <media/media-device.h>
#include <media/media-dev-allocator.h>
/* DVB */ /* DVB */
#include <media/demux.h> #include <media/demux.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment