Commit 140b932f authored by Olaf Hering's avatar Olaf Hering Committed by Paul Mackerras

[POWERPC] Create modalias file in sysfs for of_platform bus

Create /sys/bus/of_platform/devices/*/modalias file to allow autoloading
of modules.  Modalias files are already present for many other bus types.
This adds also a newline to the devspec files.

Also create a devspec file for mac-io devices.  They were created as a
side effect.  Use correct buffer size for mac-io modalias buffer.

Tested on iBook1 and Efika.
Signed-off-by: default avatarOlaf Hering <olaf@aepfle.de>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent 9d5f525b
...@@ -44,7 +44,7 @@ static ssize_t modalias_show (struct device *dev, struct device_attribute *attr, ...@@ -44,7 +44,7 @@ static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
struct of_device *ofdev = to_of_device(dev); struct of_device *ofdev = to_of_device(dev);
int len; int len;
len = of_device_get_modalias(ofdev, buf, PAGE_SIZE); len = of_device_get_modalias(ofdev, buf, PAGE_SIZE - 2);
buf[len] = '\n'; buf[len] = '\n';
buf[len+1] = 0; buf[len+1] = 0;
...@@ -52,6 +52,15 @@ static ssize_t modalias_show (struct device *dev, struct device_attribute *attr, ...@@ -52,6 +52,15 @@ static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
return len+1; return len+1;
} }
static ssize_t devspec_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct of_device *ofdev;
ofdev = to_of_device(dev);
return sprintf(buf, "%s\n", ofdev->node->full_name);
}
macio_config_of_attr (name, "%s\n"); macio_config_of_attr (name, "%s\n");
macio_config_of_attr (type, "%s\n"); macio_config_of_attr (type, "%s\n");
...@@ -60,5 +69,6 @@ struct device_attribute macio_dev_attrs[] = { ...@@ -60,5 +69,6 @@ struct device_attribute macio_dev_attrs[] = {
__ATTR_RO(type), __ATTR_RO(type),
__ATTR_RO(compatible), __ATTR_RO(compatible),
__ATTR_RO(modalias), __ATTR_RO(modalias),
__ATTR_RO(devspec),
__ATTR_NULL __ATTR_NULL
}; };
...@@ -48,16 +48,32 @@ void of_dev_put(struct of_device *dev) ...@@ -48,16 +48,32 @@ void of_dev_put(struct of_device *dev)
} }
EXPORT_SYMBOL(of_dev_put); EXPORT_SYMBOL(of_dev_put);
static ssize_t dev_show_devspec(struct device *dev, static ssize_t devspec_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct of_device *ofdev; struct of_device *ofdev;
ofdev = to_of_device(dev); ofdev = to_of_device(dev);
return sprintf(buf, "%s", ofdev->node->full_name); return sprintf(buf, "%s\n", ofdev->node->full_name);
} }
static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL); static ssize_t modalias_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct of_device *ofdev = to_of_device(dev);
ssize_t len = 0;
len = of_device_get_modalias(ofdev, buf, PAGE_SIZE - 2);
buf[len] = '\n';
buf[len+1] = 0;
return len+1;
}
struct device_attribute of_platform_device_attrs[] = {
__ATTR_RO(devspec),
__ATTR_RO(modalias),
__ATTR_NULL
};
/** /**
* of_release_dev - free an of device structure when all users of it are finished. * of_release_dev - free an of device structure when all users of it are finished.
...@@ -78,25 +94,13 @@ EXPORT_SYMBOL(of_release_dev); ...@@ -78,25 +94,13 @@ EXPORT_SYMBOL(of_release_dev);
int of_device_register(struct of_device *ofdev) int of_device_register(struct of_device *ofdev)
{ {
int rc;
BUG_ON(ofdev->node == NULL); BUG_ON(ofdev->node == NULL);
return device_register(&ofdev->dev);
rc = device_register(&ofdev->dev);
if (rc)
return rc;
rc = device_create_file(&ofdev->dev, &dev_attr_devspec);
if (rc)
device_unregister(&ofdev->dev);
return rc;
} }
EXPORT_SYMBOL(of_device_register); EXPORT_SYMBOL(of_device_register);
void of_device_unregister(struct of_device *ofdev) void of_device_unregister(struct of_device *ofdev)
{ {
device_remove_file(&ofdev->dev, &dev_attr_devspec);
device_unregister(&ofdev->dev); device_unregister(&ofdev->dev);
} }
EXPORT_SYMBOL(of_device_unregister); EXPORT_SYMBOL(of_device_unregister);
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
extern struct device_attribute of_platform_device_attrs[];
static int of_platform_bus_match(struct device *dev, struct device_driver *drv) static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
{ {
struct of_device *of_dev = to_of_device(dev); struct of_device *of_dev = to_of_device(dev);
...@@ -103,6 +105,7 @@ int of_bus_type_init(struct bus_type *bus, const char *name) ...@@ -103,6 +105,7 @@ int of_bus_type_init(struct bus_type *bus, const char *name)
bus->suspend = of_platform_device_suspend; bus->suspend = of_platform_device_suspend;
bus->resume = of_platform_device_resume; bus->resume = of_platform_device_resume;
bus->shutdown = of_platform_device_shutdown; bus->shutdown = of_platform_device_shutdown;
bus->dev_attrs = of_platform_device_attrs;
return bus_register(bus); return bus_register(bus);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment