From: Sylvain Munaut <tnt@246tNt.com>
To: Olaf Hering <olaf@aepfle.de>
Cc: linuxppc-dev@ozlabs.org, Paul Mackeras <paulus@samba.org>
Subject: Re: [PATCH] add modalias file for of_devices to sysfs
Date: Mon, 02 Apr 2007 19:04:56 +0200 [thread overview]
Message-ID: <461137B8.9000404@246tNt.com> (raw)
In-Reply-To: <20070402124547.GA11415@aepfle.de>
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
>
>
next prev parent reply other threads:[~2007-04-02 17:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-02 12:45 [PATCH] add modalias file for of_devices to sysfs Olaf Hering
2007-04-02 17:04 ` Sylvain Munaut [this message]
2007-04-03 12:28 ` Olaf Hering
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=461137B8.9000404@246tNt.com \
--to=tnt@246tnt.com \
--cc=linuxppc-dev@ozlabs.org \
--cc=olaf@aepfle.de \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.