aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2009-04-30 09:23:42 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-06-16 00:30:25 -0400
commitf7a386c5b8ff34cd84ae922603d1c6f9d234edee (patch)
treeae1c03544dd511d85cc537c632eba6f035072e36
parentd405640539555b601e52f7d18f1f0b1345d18bf5 (diff)
Driver Core: usb: add nodename support for usb drivers.
This adds support for USB drivers to report their requested nodename to userspace. It also updates a number of USB drivers to provide the needed subdirectory and device name to be used for them. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Jan Blunck <jblunck@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/hid/usbhid/hiddev.c7
-rw-r--r--drivers/media/video/dabusb.c6
-rw-r--r--drivers/usb/class/usblp.c6
-rw-r--r--drivers/usb/core/file.c13
-rw-r--r--drivers/usb/core/usb.c11
-rw-r--r--drivers/usb/misc/iowarrior.c6
-rw-r--r--drivers/usb/misc/legousbtower.c6
-rw-r--r--include/linux/usb.h3
8 files changed, 56 insertions, 2 deletions
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index e9b436d2d944..9e9421525fb9 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -850,8 +850,14 @@ static const struct file_operations hiddev_fops = {
850#endif 850#endif
851}; 851};
852 852
853static char *hiddev_nodename(struct device *dev)
854{
855 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
856}
857
853static struct usb_class_driver hiddev_class = { 858static struct usb_class_driver hiddev_class = {
854 .name = "hiddev%d", 859 .name = "hiddev%d",
860 .nodename = hiddev_nodename,
855 .fops = &hiddev_fops, 861 .fops = &hiddev_fops,
856 .minor_base = HIDDEV_MINOR_BASE, 862 .minor_base = HIDDEV_MINOR_BASE,
857}; 863};
@@ -955,7 +961,6 @@ static int hiddev_usbd_probe(struct usb_interface *intf,
955 return -ENODEV; 961 return -ENODEV;
956} 962}
957 963
958
959static /* const */ struct usb_driver hiddev_driver = { 964static /* const */ struct usb_driver hiddev_driver = {
960 .name = "hiddev", 965 .name = "hiddev",
961 .probe = hiddev_usbd_probe, 966 .probe = hiddev_usbd_probe,
diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c
index ba3709bec3f0..ec2f45dde164 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -747,8 +747,14 @@ static const struct file_operations dabusb_fops =
747 .release = dabusb_release, 747 .release = dabusb_release,
748}; 748};
749 749
750static char *dabusb_nodename(struct device *dev)
751{
752 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
753}
754
750static struct usb_class_driver dabusb_class = { 755static struct usb_class_driver dabusb_class = {
751 .name = "dabusb%d", 756 .name = "dabusb%d",
757 .nodename = dabusb_nodename,
752 .fops = &dabusb_fops, 758 .fops = &dabusb_fops,
753 .minor_base = DABUSB_MINOR, 759 .minor_base = DABUSB_MINOR,
754}; 760};
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index d2747a49b974..26c09f0257db 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -1057,8 +1057,14 @@ static const struct file_operations usblp_fops = {
1057 .release = usblp_release, 1057 .release = usblp_release,
1058}; 1058};
1059 1059
1060static char *usblp_nodename(struct device *dev)
1061{
1062 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
1063}
1064
1060static struct usb_class_driver usblp_class = { 1065static struct usb_class_driver usblp_class = {
1061 .name = "lp%d", 1066 .name = "lp%d",
1067 .nodename = usblp_nodename,
1062 .fops = &usblp_fops, 1068 .fops = &usblp_fops,
1063 .minor_base = USBLP_MINOR_BASE, 1069 .minor_base = USBLP_MINOR_BASE,
1064}; 1070};
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 997e659ff693..5cef88929b3e 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -67,6 +67,16 @@ static struct usb_class {
67 struct class *class; 67 struct class *class;
68} *usb_class; 68} *usb_class;
69 69
70static char *usb_nodename(struct device *dev)
71{
72 struct usb_class_driver *drv;
73
74 drv = dev_get_drvdata(dev);
75 if (!drv || !drv->nodename)
76 return NULL;
77 return drv->nodename(dev);
78}
79
70static int init_usb_class(void) 80static int init_usb_class(void)
71{ 81{
72 int result = 0; 82 int result = 0;
@@ -90,6 +100,7 @@ static int init_usb_class(void)
90 kfree(usb_class); 100 kfree(usb_class);
91 usb_class = NULL; 101 usb_class = NULL;
92 } 102 }
103 usb_class->class->nodename = usb_nodename;
93 104
94exit: 105exit:
95 return result; 106 return result;
@@ -198,7 +209,7 @@ int usb_register_dev(struct usb_interface *intf,
198 else 209 else
199 temp = name; 210 temp = name;
200 intf->usb_dev = device_create(usb_class->class, &intf->dev, 211 intf->usb_dev = device_create(usb_class->class, &intf->dev,
201 MKDEV(USB_MAJOR, minor), NULL, 212 MKDEV(USB_MAJOR, minor), class_driver,
202 "%s", temp); 213 "%s", temp);
203 if (IS_ERR(intf->usb_dev)) { 214 if (IS_ERR(intf->usb_dev)) {
204 down_write(&minor_rwsem); 215 down_write(&minor_rwsem);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 7eee400d3e32..927a27dd2f85 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -305,10 +305,21 @@ static struct dev_pm_ops usb_device_pm_ops = {
305 305
306#endif /* CONFIG_PM */ 306#endif /* CONFIG_PM */
307 307
308
309static char *usb_nodename(struct device *dev)
310{
311 struct usb_device *usb_dev;
312
313 usb_dev = to_usb_device(dev);
314 return kasprintf(GFP_KERNEL, "bus/usb/%03d/%03d",
315 usb_dev->bus->busnum, usb_dev->devnum);
316}
317
308struct device_type usb_device_type = { 318struct device_type usb_device_type = {
309 .name = "usb_device", 319 .name = "usb_device",
310 .release = usb_release_dev, 320 .release = usb_release_dev,
311 .uevent = usb_dev_uevent, 321 .uevent = usb_dev_uevent,
322 .nodename = usb_nodename,
312 .pm = &usb_device_pm_ops, 323 .pm = &usb_device_pm_ops,
313}; 324};
314 325
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index a4ef77ef917d..3c5fe5cee05a 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -726,12 +726,18 @@ static const struct file_operations iowarrior_fops = {
726 .poll = iowarrior_poll, 726 .poll = iowarrior_poll,
727}; 727};
728 728
729static char *iowarrior_nodename(struct device *dev)
730{
731 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
732}
733
729/* 734/*
730 * usb class driver info in order to get a minor number from the usb core, 735 * usb class driver info in order to get a minor number from the usb core,
731 * and to have the device registered with devfs and the driver core 736 * and to have the device registered with devfs and the driver core
732 */ 737 */
733static struct usb_class_driver iowarrior_class = { 738static struct usb_class_driver iowarrior_class = {
734 .name = "iowarrior%d", 739 .name = "iowarrior%d",
740 .nodename = iowarrior_nodename,
735 .fops = &iowarrior_fops, 741 .fops = &iowarrior_fops,
736 .minor_base = IOWARRIOR_MINOR_BASE, 742 .minor_base = IOWARRIOR_MINOR_BASE,
737}; 743};
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index ab0f3226158b..c1e2433f640d 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -266,12 +266,18 @@ static const struct file_operations tower_fops = {
266 .llseek = tower_llseek, 266 .llseek = tower_llseek,
267}; 267};
268 268
269static char *legousbtower_nodename(struct device *dev)
270{
271 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
272}
273
269/* 274/*
270 * usb class driver info in order to get a minor number from the usb core, 275 * usb class driver info in order to get a minor number from the usb core,
271 * and to have the device registered with the driver core 276 * and to have the device registered with the driver core
272 */ 277 */
273static struct usb_class_driver tower_class = { 278static struct usb_class_driver tower_class = {
274 .name = "legousbtower%d", 279 .name = "legousbtower%d",
280 .nodename = legousbtower_nodename,
275 .fops = &tower_fops, 281 .fops = &tower_fops,
276 .minor_base = LEGO_USB_TOWER_MINOR_BASE, 282 .minor_base = LEGO_USB_TOWER_MINOR_BASE,
277}; 283};
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 3aa2cd1f8d08..34cdfcac4555 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -869,6 +869,8 @@ struct usb_driver {
869 * struct usb_device_driver - identifies USB device driver to usbcore 869 * struct usb_device_driver - identifies USB device driver to usbcore
870 * @name: The driver name should be unique among USB drivers, 870 * @name: The driver name should be unique among USB drivers,
871 * and should normally be the same as the module name. 871 * and should normally be the same as the module name.
872 * @nodename: Callback to provide a naming hint for a possible
873 * device node to create.
872 * @probe: Called to see if the driver is willing to manage a particular 874 * @probe: Called to see if the driver is willing to manage a particular
873 * device. If it is, probe returns zero and uses dev_set_drvdata() 875 * device. If it is, probe returns zero and uses dev_set_drvdata()
874 * to associate driver-specific data with the device. If unwilling 876 * to associate driver-specific data with the device. If unwilling
@@ -912,6 +914,7 @@ extern struct bus_type usb_bus_type;
912 */ 914 */
913struct usb_class_driver { 915struct usb_class_driver {
914 char *name; 916 char *name;
917 char *(*nodename)(struct device *dev);
915 const struct file_operations *fops; 918 const struct file_operations *fops;
916 int minor_base; 919 int minor_base;
917}; 920};