* [PATCH] add modalias file for of_devices to sysfs
@ 2007-04-02 12:45 Olaf Hering
2007-04-02 17:04 ` Sylvain Munaut
0 siblings, 1 reply; 3+ messages in thread
From: Olaf Hering @ 2007-04-02 12:45 UTC (permalink / raw)
To: Paul Mackeras, linuxppc-dev
modalias files are supposed to be there for every node.
They allow module autoloading, and it is possible to match required kernel modules.
Tested on Efika:
==> /sys/devices/f0000000.builtin/f0003a00.ata/devspec <==
/builtin@F0000000/ata@F0003A00
==> /sys/devices/f0000000.builtin/f0003a00.ata/modalias <==
of:NataTataCmpc5200b-ataCmpc5200-ata
Also add a newline to the 'devspec' file output.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
arch/powerpc/kernel/of_device.c | 47 ++++++++++++++++++++++++++++----------
arch/powerpc/kernel/of_platform.c | 3 ++
2 files changed, 38 insertions(+), 12 deletions(-)
Index: b/arch/powerpc/kernel/of_device.c
===================================================================
--- a/arch/powerpc/kernel/of_device.c
+++ b/arch/powerpc/kernel/of_device.c
@@ -72,16 +72,47 @@ void of_dev_put(struct of_device *dev)
put_device(&dev->dev);
}
-static ssize_t dev_show_devspec(struct device *dev,
+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", 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;
+ const char *compat;
+ int cplen;
+ int length;
+
+ ofdev = to_of_device(dev);
+ compat = get_property(ofdev->node, "compatible", &cplen);
+ if (!compat) compat = "", cplen = 1;
+ length = sprintf (buf, "of:N%sT%s", ofdev->node->name, ofdev->node->type);
+ buf += length;
+ while (cplen > 0) {
+ int l;
+ l = sprintf (buf, "C%s", compat);
+ length += l;
+ buf += l;
+ l = strlen (compat) + 1;
+ compat += l;
+ cplen -= l;
+ }
+ length += sprintf (buf, "\n");
+
+ return length;
+}
+
+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.
@@ -101,21 +132,13 @@ void of_release_dev(struct device *dev)
int of_device_register(struct of_device *ofdev)
{
- int rc;
-
BUG_ON(ofdev->node == NULL);
- rc = device_register(&ofdev->dev);
- if (rc)
- return rc;
-
- return device_create_file(&ofdev->dev, &dev_attr_devspec);
+ return device_register(&ofdev->dev);
}
void of_device_unregister(struct of_device *ofdev)
{
- device_remove_file(&ofdev->dev, &dev_attr_devspec);
-
device_unregister(&ofdev->dev);
}
Index: b/arch/powerpc/kernel/of_platform.c
===================================================================
--- a/arch/powerpc/kernel/of_platform.c
+++ b/arch/powerpc/kernel/of_platform.c
@@ -130,6 +130,8 @@ static int of_platform_device_resume(str
return error;
}
+extern struct device_attribute of_platform_device_attrs[];
+
struct bus_type of_platform_bus_type = {
.name = "of_platform",
.match = of_platform_bus_match,
@@ -137,6 +139,7 @@ struct bus_type of_platform_bus_type = {
.remove = of_platform_device_remove,
.suspend = of_platform_device_suspend,
.resume = of_platform_device_resume,
+ .dev_attrs = of_platform_device_attrs,
};
EXPORT_SYMBOL(of_platform_bus_type);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] add modalias file for of_devices to sysfs
2007-04-02 12:45 [PATCH] add modalias file for of_devices to sysfs Olaf Hering
@ 2007-04-02 17:04 ` Sylvain Munaut
2007-04-03 12:28 ` Olaf Hering
0 siblings, 1 reply; 3+ messages in thread
From: Sylvain Munaut @ 2007-04-02 17:04 UTC (permalink / raw)
To: Olaf Hering; +Cc: linuxppc-dev, Paul Mackeras
In my patch to "unify" the uevent generation, I've made a separate
function that generate
the modalias string especially so that we don't repeat the same piece of
code twice.
It's prototype is :
+static ssize_t of_device_get_modalias(struct of_device *ofdev,
+ char *str, ssize_t len)
So the modalias_show can be shortened to
return of_device_get_modalias(to_of_device(dev), buf, PAGE_SIZE);
Of course that depends on Paulus merging my patches ...
Sylvain
Olaf Hering wrote:
> modalias files are supposed to be there for every node.
> They allow module autoloading, and it is possible to match required kernel modules.
> Tested on Efika:
>
> ==> /sys/devices/f0000000.builtin/f0003a00.ata/devspec <==
> /builtin@F0000000/ata@F0003A00
>
> ==> /sys/devices/f0000000.builtin/f0003a00.ata/modalias <==
> of:NataTataCmpc5200b-ataCmpc5200-ata
>
> Also add a newline to the 'devspec' file output.
>
> Signed-off-by: Olaf Hering <olaf@aepfle.de>
>
> ---
> arch/powerpc/kernel/of_device.c | 47 ++++++++++++++++++++++++++++----------
> arch/powerpc/kernel/of_platform.c | 3 ++
> 2 files changed, 38 insertions(+), 12 deletions(-)
>
> Index: b/arch/powerpc/kernel/of_device.c
> ===================================================================
> --- a/arch/powerpc/kernel/of_device.c
> +++ b/arch/powerpc/kernel/of_device.c
> @@ -72,16 +72,47 @@ void of_dev_put(struct of_device *dev)
> put_device(&dev->dev);
> }
>
> -static ssize_t dev_show_devspec(struct device *dev,
> +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", 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;
> + const char *compat;
> + int cplen;
> + int length;
> +
> + ofdev = to_of_device(dev);
> + compat = get_property(ofdev->node, "compatible", &cplen);
> + if (!compat) compat = "", cplen = 1;
> + length = sprintf (buf, "of:N%sT%s", ofdev->node->name, ofdev->node->type);
> + buf += length;
> + while (cplen > 0) {
> + int l;
> + l = sprintf (buf, "C%s", compat);
> + length += l;
> + buf += l;
> + l = strlen (compat) + 1;
> + compat += l;
> + cplen -= l;
> + }
> + length += sprintf (buf, "\n");
> +
> + return length;
> +}
> +
> +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.
> @@ -101,21 +132,13 @@ void of_release_dev(struct device *dev)
>
> int of_device_register(struct of_device *ofdev)
> {
> - int rc;
> -
> BUG_ON(ofdev->node == NULL);
>
> - rc = device_register(&ofdev->dev);
> - if (rc)
> - return rc;
> -
> - return device_create_file(&ofdev->dev, &dev_attr_devspec);
> + return device_register(&ofdev->dev);
> }
>
> void of_device_unregister(struct of_device *ofdev)
> {
> - device_remove_file(&ofdev->dev, &dev_attr_devspec);
> -
> device_unregister(&ofdev->dev);
> }
>
> Index: b/arch/powerpc/kernel/of_platform.c
> ===================================================================
> --- a/arch/powerpc/kernel/of_platform.c
> +++ b/arch/powerpc/kernel/of_platform.c
> @@ -130,6 +130,8 @@ static int of_platform_device_resume(str
> return error;
> }
>
> +extern struct device_attribute of_platform_device_attrs[];
> +
> struct bus_type of_platform_bus_type = {
> .name = "of_platform",
> .match = of_platform_bus_match,
> @@ -137,6 +139,7 @@ struct bus_type of_platform_bus_type = {
> .remove = of_platform_device_remove,
> .suspend = of_platform_device_suspend,
> .resume = of_platform_device_resume,
> + .dev_attrs = of_platform_device_attrs,
> };
> EXPORT_SYMBOL(of_platform_bus_type);
>
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] add modalias file for of_devices to sysfs
2007-04-02 17:04 ` Sylvain Munaut
@ 2007-04-03 12:28 ` Olaf Hering
0 siblings, 0 replies; 3+ messages in thread
From: Olaf Hering @ 2007-04-03 12:28 UTC (permalink / raw)
To: Sylvain Munaut; +Cc: linuxppc-dev, Paul Mackeras
On Mon, Apr 02, Sylvain Munaut wrote:
> In my patch to "unify" the uevent generation, I've made a separate
> function that generate
> the modalias string especially so that we don't repeat the same piece of
> code twice.
>
> It's prototype is :
>
> +static ssize_t of_device_get_modalias(struct of_device *ofdev,
> + char *str, ssize_t len)
>
> So the modalias_show can be shortened to
>
> return of_device_get_modalias(to_of_device(dev), buf, PAGE_SIZE);
macio_sysfs needs to be adapted as well.
Your version does not append a newline to the moalias content.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-04-03 12:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-02 12:45 [PATCH] add modalias file for of_devices to sysfs Olaf Hering
2007-04-02 17:04 ` Sylvain Munaut
2007-04-03 12:28 ` Olaf Hering
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).