diff options
-rw-r--r-- | Documentation/video4linux/v4l2-framework.txt | 5 | ||||
-rw-r--r-- | drivers/media/video/v4l2-device.c | 16 | ||||
-rw-r--r-- | include/media/v4l2-device.h | 21 |
3 files changed, 42 insertions, 0 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt index 854808b67fae..d54c1e4c6a9c 100644 --- a/Documentation/video4linux/v4l2-framework.txt +++ b/Documentation/video4linux/v4l2-framework.txt | |||
@@ -89,6 +89,11 @@ from dev (driver name followed by the bus_id, to be precise). If you set it | |||
89 | up before calling v4l2_device_register then it will be untouched. If dev is | 89 | up before calling v4l2_device_register then it will be untouched. If dev is |
90 | NULL, then you *must* setup v4l2_dev->name before calling v4l2_device_register. | 90 | NULL, then you *must* setup v4l2_dev->name before calling v4l2_device_register. |
91 | 91 | ||
92 | You can use v4l2_device_set_name() to set the name based on a driver name and | ||
93 | a driver-global atomic_t instance. This will generate names like ivtv0, ivtv1, | ||
94 | etc. If the name ends with a digit, then it will insert a dash: cx18-0, | ||
95 | cx18-1, etc. This function returns the instance number. | ||
96 | |||
92 | The first 'dev' argument is normally the struct device pointer of a pci_dev, | 97 | The first 'dev' argument is normally the struct device pointer of a pci_dev, |
93 | usb_interface or platform_device. It is rare for dev to be NULL, but it happens | 98 | usb_interface or platform_device. It is rare for dev to be NULL, but it happens |
94 | with ISA devices or when one device creates multiple PCI devices, thus making | 99 | with ISA devices or when one device creates multiple PCI devices, thus making |
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c index 94aa485ade52..ffb425f7c24c 100644 --- a/drivers/media/video/v4l2-device.c +++ b/drivers/media/video/v4l2-device.c | |||
@@ -49,6 +49,22 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) | |||
49 | } | 49 | } |
50 | EXPORT_SYMBOL_GPL(v4l2_device_register); | 50 | EXPORT_SYMBOL_GPL(v4l2_device_register); |
51 | 51 | ||
52 | int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename, | ||
53 | atomic_t *instance) | ||
54 | { | ||
55 | int num = atomic_inc_return(instance) - 1; | ||
56 | int len = strlen(basename); | ||
57 | |||
58 | if (basename[len - 1] >= '0' && basename[len - 1] <= '9') | ||
59 | snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), | ||
60 | "%s-%d", basename, num); | ||
61 | else | ||
62 | snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), | ||
63 | "%s%d", basename, num); | ||
64 | return num; | ||
65 | } | ||
66 | EXPORT_SYMBOL_GPL(v4l2_device_set_name); | ||
67 | |||
52 | void v4l2_device_disconnect(struct v4l2_device *v4l2_dev) | 68 | void v4l2_device_disconnect(struct v4l2_device *v4l2_dev) |
53 | { | 69 | { |
54 | if (v4l2_dev->dev) { | 70 | if (v4l2_dev->dev) { |
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h index 9afd39fb2cfc..5d5d550e63ad 100644 --- a/include/media/v4l2-device.h +++ b/include/media/v4l2-device.h | |||
@@ -53,10 +53,31 @@ struct v4l2_device { | |||
53 | dev may be NULL in rare cases (ISA devices). In that case you | 53 | dev may be NULL in rare cases (ISA devices). In that case you |
54 | must fill in the v4l2_dev->name field before calling this function. */ | 54 | must fill in the v4l2_dev->name field before calling this function. */ |
55 | int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev); | 55 | int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev); |
56 | |||
57 | /* Optional function to initialize the name field of struct v4l2_device using | ||
58 | the driver name and a driver-global atomic_t instance. | ||
59 | This function will increment the instance counter and returns the instance | ||
60 | value used in the name. | ||
61 | |||
62 | Example: | ||
63 | |||
64 | static atomic_t drv_instance = ATOMIC_INIT(0); | ||
65 | |||
66 | ... | ||
67 | |||
68 | instance = v4l2_device_set_name(&v4l2_dev, "foo", &drv_instance); | ||
69 | |||
70 | The first time this is called the name field will be set to foo0 and | ||
71 | this function returns 0. If the name ends with a digit (e.g. cx18), | ||
72 | then the name will be set to cx18-0 since cx180 looks really odd. */ | ||
73 | int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename, | ||
74 | atomic_t *instance); | ||
75 | |||
56 | /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects. | 76 | /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects. |
57 | Since the parent disappears this ensures that v4l2_dev doesn't have an | 77 | Since the parent disappears this ensures that v4l2_dev doesn't have an |
58 | invalid parent pointer. */ | 78 | invalid parent pointer. */ |
59 | void v4l2_device_disconnect(struct v4l2_device *v4l2_dev); | 79 | void v4l2_device_disconnect(struct v4l2_device *v4l2_dev); |
80 | |||
60 | /* Unregister all sub-devices and any other resources related to v4l2_dev. */ | 81 | /* Unregister all sub-devices and any other resources related to v4l2_dev. */ |
61 | void v4l2_device_unregister(struct v4l2_device *v4l2_dev); | 82 | void v4l2_device_unregister(struct v4l2_device *v4l2_dev); |
62 | 83 | ||