Skip to content

Commit

Permalink
[media] v4l2-mc: add a routine to create USB media_device
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mchehab committed Feb 16, 2016
1 parent db15227 commit eee7d35
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
41 changes: 40 additions & 1 deletion drivers/media/v4l2-core/v4l2-mc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)

{
Expand Down
39 changes: 34 additions & 5 deletions include/media/v4l2-mc.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ enum demod_pad_index {
DEMOD_NUM_PADS
};


struct pci_dev; /* We don't need to include pci.h here */
/* We don't need to include pci.h or usb.h here */
struct pci_dev;
struct usb_device;

#ifdef CONFIG_MEDIA_CONTROLLER
/**
Expand Down Expand Up @@ -124,20 +125,48 @@ int v4l2_mc_create_media_graph(struct media_device *mdev);
* name for the pci device, given by pci_name() macro.
*/
struct media_device *v4l2_mc_pci_media_device_init(struct pci_dev *pci_dev,
char *name);

const char *name);
/**
* __v4l2_mc_usb_media_device_init() - create and initialize a
* struct &media_device from a PCI device.
*
* @udev: pointer to struct usb_device
* @board_name: media device name. If %NULL, the routine will use the usb
* product name, if available.
* @driver_name: name of the driver. if %NULL, the routine will use the name
* given by udev->dev->driver->name, with is usually the wrong
* thing to do.
*
* NOTE: It is better to call v4l2_mc_usb_media_device_init() instead, as
* such macro fills driver_name with %KBUILD_MODNAME.
*/
struct media_device *__v4l2_mc_usb_media_device_init(struct usb_device *udev,
const char *board_name,
const char *driver_name);

#else
static inline int v4l2_mc_create_media_graph(struct media_device *mdev)
{
return 0;
}

static inline
struct media_device *v4l2_mc_pci_media_device_init(struct pci_dev *pci_dev,
char *name) {
char *name)
{
return NULL;
}

static inline
struct media_device *__v4l2_mc_usb_media_device_init(struct usb_device *udev,
char *board_name,
char *driver_name)
{
return NULL;
}
#endif

#define v4l2_mc_usb_media_device_init(udev, name) \
__v4l2_mc_usb_media_device_init(udev, name, KBUILD_MODNAME)

#endif

0 comments on commit eee7d35

Please sign in to comment.