OSDN Git Service

[media] dvb-usb-v2: add support for the media controller at USB driver
authorRafael Lourenço de Lima Chehab <chehabrafael@gmail.com>
Thu, 12 Feb 2015 11:37:25 +0000 (08:37 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Thu, 26 Feb 2015 12:49:07 +0000 (09:49 -0300)
Create a struct media_device and add it to the dvb adapter.

Please notice that the tuner is not mapped yet by the dvb core.

[mchehab@osg.samsung.com: use config option MEDIA_CONTROLLER_DVB due to a rebase]
Signed-off-by: Rafael Lourenço de Lima Chehab <chehabrafael@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/usb/dvb-usb-v2/dvb_usb.h
drivers/media/usb/dvb-usb-v2/dvb_usb_core.c

index 41c6363..dbac163 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/usb/input.h>
 #include <linux/firmware.h>
 #include <media/rc-core.h>
+#include <media/media-device.h>
 
 #include "dvb_frontend.h"
 #include "dvb_demux.h"
@@ -391,6 +392,10 @@ struct dvb_usb_device {
        struct delayed_work rc_query_work;
 
        void *priv;
+
+#if defined(CONFIG_MEDIA_CONTROLLER_DVB)
+       struct media_device *media_dev;
+#endif
 };
 
 extern int dvb_usbv2_probe(struct usb_interface *,
index 9913e0f..94a7f63 100644 (file)
@@ -400,6 +400,55 @@ skip_feed_stop:
        return ret;
 }
 
+static void dvb_usbv2_media_device_register(struct dvb_usb_device *d)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER_DVB
+
+       struct media_device *mdev;
+       struct usb_device *udev = d->udev;
+       int ret;
+
+       mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
+       if (!mdev)
+               return;
+
+       mdev->dev = &udev->dev;
+       strlcpy(mdev->model, d->name, sizeof(mdev->model));
+       if (udev->serial)
+               strlcpy(mdev->serial, udev->serial, sizeof(mdev->serial));
+       strcpy(mdev->bus_info, udev->devpath);
+       mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
+       mdev->driver_version = LINUX_VERSION_CODE;
+
+       ret = media_device_register(mdev);
+       if (ret) {
+               dev_err(&d->udev->dev,
+                       "Couldn't create a media device. Error: %d\n",
+                       ret);
+               kfree(mdev);
+               return;
+       }
+
+       d->media_dev = mdev;
+
+       dev_info(&d->udev->dev, "media controller created\n");
+
+#endif
+}
+
+static void dvb_usbv2_media_device_unregister(struct dvb_usb_device *d)
+{
+#ifdef CONFIG_MEDIA_CONTROLLER_DVB
+       if (!d->media_dev)
+               return;
+
+       media_device_unregister(d->media_dev);
+       kfree(d->media_dev);
+       d->media_dev = NULL;
+
+#endif
+}
+
 static int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter *adap)
 {
        int ret;
@@ -416,6 +465,11 @@ static int dvb_usbv2_adapter_dvb_init(struct dvb_usb_adapter *adap)
 
        adap->dvb_adap.priv = adap;
 
+#ifdef CONFIG_MEDIA_CONTROLLER_DVB
+       dvb_usbv2_media_device_register(d);
+       adap->dvb_adap.mdev = d->media_dev;
+#endif
+
        if (d->props->read_mac_address) {
                ret = d->props->read_mac_address(adap,
                                adap->dvb_adap.proposed_mac);
@@ -464,6 +518,7 @@ err_dvb_net_init:
 err_dvb_dmxdev_init:
        dvb_dmx_release(&adap->demux);
 err_dvb_dmx_init:
+       dvb_usbv2_media_device_unregister(d);
        dvb_unregister_adapter(&adap->dvb_adap);
 err_dvb_register_adapter:
        adap->dvb_adap.priv = NULL;
@@ -472,6 +527,8 @@ err_dvb_register_adapter:
 
 static int dvb_usbv2_adapter_dvb_exit(struct dvb_usb_adapter *adap)
 {
+       struct dvb_usb_device *d = adap_to_d(adap);
+
        dev_dbg(&adap_to_d(adap)->udev->dev, "%s: adap=%d\n", __func__,
                        adap->id);
 
@@ -480,6 +537,7 @@ static int dvb_usbv2_adapter_dvb_exit(struct dvb_usb_adapter *adap)
                adap->demux.dmx.close(&adap->demux.dmx);
                dvb_dmxdev_release(&adap->dmxdev);
                dvb_dmx_release(&adap->demux);
+               dvb_usbv2_media_device_unregister(d);
                dvb_unregister_adapter(&adap->dvb_adap);
        }
 
@@ -643,6 +701,8 @@ static int dvb_usbv2_adapter_frontend_init(struct dvb_usb_adapter *adap)
                }
        }
 
+       dvb_create_media_graph(d->media_dev);
+
        return 0;
 
 err_dvb_unregister_frontend:
@@ -955,6 +1015,7 @@ void dvb_usbv2_disconnect(struct usb_interface *intf)
        struct dvb_usb_device *d = usb_get_intfdata(intf);
        const char *name = d->name;
        struct device dev = d->udev->dev;
+
        dev_dbg(&d->udev->dev, "%s: bInterfaceNumber=%d\n", __func__,
                        intf->cur_altsetting->desc.bInterfaceNumber);