diff options
author | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2016-02-11 20:21:46 +0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2016-02-16 13:38:59 +0300 |
commit | eee7d353a19032b48c0f71504081de84a0ee79d8 (patch) | |
tree | a9161248e5606ee9ea2730e40c43c25dc1e2a3cd /drivers/media/v4l2-core | |
parent | db152276ce720baadcbd6bccebbeb17da001d312 (diff) | |
download | linux-eee7d353a19032b48c0f71504081de84a0ee79d8.tar.xz |
[media] v4l2-mc: add a routine to create USB media_device
Instead of copying exactly the same code on all USB devices,
add an ancillary routine that will create and fill the
struct media_device with the values imported from the USB
device.
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Diffstat (limited to 'drivers/media/v4l2-core')
-rw-r--r-- | drivers/media/v4l2-core/v4l2-mc.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/drivers/media/v4l2-core/v4l2-mc.c b/drivers/media/v4l2-core/v4l2-mc.c index b6cf6dbd4cd5..97b2e1e64d2e 100644 --- a/drivers/media/v4l2-core/v4l2-mc.c +++ b/drivers/media/v4l2-core/v4l2-mc.c @@ -16,12 +16,13 @@ #include <linux/module.h> #include <linux/pci.h> +#include <linux/usb.h> #include <media/media-entity.h> #include <media/v4l2-mc.h> struct media_device *v4l2_mc_pci_media_device_init(struct pci_dev *pci_dev, - char *name) + const char *name) { #ifdef CONFIG_PCI struct media_device *mdev; @@ -53,6 +54,44 @@ struct media_device *v4l2_mc_pci_media_device_init(struct pci_dev *pci_dev, } EXPORT_SYMBOL_GPL(v4l2_mc_pci_media_device_init); +struct media_device *__v4l2_mc_usb_media_device_init(struct usb_device *udev, + const char *board_name, + const char *driver_name) +{ +#ifdef CONFIG_USB + struct media_device *mdev; + + mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); + if (!mdev) + return NULL; + + mdev->dev = &udev->dev; + + if (driver_name) + strlcpy(mdev->driver_name, driver_name, + sizeof(mdev->driver_name)); + + if (board_name) + strlcpy(mdev->model, board_name, sizeof(mdev->model)); + else if (udev->product) + strlcpy(mdev->model, udev->product, sizeof(mdev->model)); + else + strlcpy(mdev->model, "unknown model", sizeof(mdev->model)); + if (udev->serial) + strlcpy(mdev->serial, udev->serial, sizeof(mdev->serial)); + usb_make_path(udev, mdev->bus_info, sizeof(mdev->bus_info)); + mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice); + mdev->driver_version = LINUX_VERSION_CODE; + + media_device_init(mdev); + + return mdev; +#else + return NULL; +#endif +} +EXPORT_SYMBOL_GPL(__v4l2_mc_usb_media_device_init); + int v4l2_mc_create_media_graph(struct media_device *mdev) { |