2017-11-07 09:30:07 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2012-02-06 12:22:22 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) ST-Ericsson SA 2011
|
|
|
|
*
|
|
|
|
* Author: Lee Jones <lee.jones@linaro.org> for ST-Ericsson.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/sys_soc.h>
|
|
|
|
#include <linux/err.h>
|
2016-09-21 00:57:19 -06:00
|
|
|
#include <linux/glob.h>
|
2012-02-06 12:22:22 -07:00
|
|
|
|
2012-03-17 03:17:49 -06:00
|
|
|
static DEFINE_IDA(soc_ida);
|
2012-02-06 12:22:22 -07:00
|
|
|
|
|
|
|
static ssize_t soc_info_get(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf);
|
|
|
|
|
|
|
|
struct soc_device {
|
|
|
|
struct device dev;
|
|
|
|
struct soc_device_attribute *attr;
|
|
|
|
int soc_dev_num;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct bus_type soc_bus_type = {
|
|
|
|
.name = "soc",
|
|
|
|
};
|
|
|
|
|
|
|
|
static DEVICE_ATTR(machine, S_IRUGO, soc_info_get, NULL);
|
|
|
|
static DEVICE_ATTR(family, S_IRUGO, soc_info_get, NULL);
|
2019-07-23 16:35:11 -06:00
|
|
|
static DEVICE_ATTR(serial_number, S_IRUGO, soc_info_get, NULL);
|
2012-02-06 12:22:22 -07:00
|
|
|
static DEVICE_ATTR(soc_id, S_IRUGO, soc_info_get, NULL);
|
|
|
|
static DEVICE_ATTR(revision, S_IRUGO, soc_info_get, NULL);
|
|
|
|
|
|
|
|
struct device *soc_device_to_device(struct soc_device *soc_dev)
|
|
|
|
{
|
|
|
|
return &soc_dev->dev;
|
|
|
|
}
|
|
|
|
|
2012-05-19 08:00:52 -06:00
|
|
|
static umode_t soc_attribute_mode(struct kobject *kobj,
|
2015-03-08 14:33:44 -06:00
|
|
|
struct attribute *attr,
|
|
|
|
int index)
|
2012-02-06 12:22:22 -07:00
|
|
|
{
|
2020-04-25 23:13:51 -06:00
|
|
|
struct device *dev = kobj_to_dev(kobj);
|
2012-02-06 12:22:22 -07:00
|
|
|
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
|
|
|
|
|
|
|
|
if ((attr == &dev_attr_machine.attr)
|
|
|
|
&& (soc_dev->attr->machine != NULL))
|
|
|
|
return attr->mode;
|
|
|
|
if ((attr == &dev_attr_family.attr)
|
|
|
|
&& (soc_dev->attr->family != NULL))
|
|
|
|
return attr->mode;
|
|
|
|
if ((attr == &dev_attr_revision.attr)
|
|
|
|
&& (soc_dev->attr->revision != NULL))
|
|
|
|
return attr->mode;
|
2019-07-23 16:35:11 -06:00
|
|
|
if ((attr == &dev_attr_serial_number.attr)
|
|
|
|
&& (soc_dev->attr->serial_number != NULL))
|
|
|
|
return attr->mode;
|
2012-02-06 12:22:22 -07:00
|
|
|
if ((attr == &dev_attr_soc_id.attr)
|
|
|
|
&& (soc_dev->attr->soc_id != NULL))
|
2015-03-08 14:33:44 -06:00
|
|
|
return attr->mode;
|
2012-02-06 12:22:22 -07:00
|
|
|
|
|
|
|
/* Unknown or unfilled attribute. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t soc_info_get(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
|
|
|
|
|
|
|
|
if (attr == &dev_attr_machine)
|
|
|
|
return sprintf(buf, "%s\n", soc_dev->attr->machine);
|
|
|
|
if (attr == &dev_attr_family)
|
|
|
|
return sprintf(buf, "%s\n", soc_dev->attr->family);
|
|
|
|
if (attr == &dev_attr_revision)
|
|
|
|
return sprintf(buf, "%s\n", soc_dev->attr->revision);
|
2019-07-23 16:35:11 -06:00
|
|
|
if (attr == &dev_attr_serial_number)
|
|
|
|
return sprintf(buf, "%s\n", soc_dev->attr->serial_number);
|
2012-02-06 12:22:22 -07:00
|
|
|
if (attr == &dev_attr_soc_id)
|
|
|
|
return sprintf(buf, "%s\n", soc_dev->attr->soc_id);
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct attribute *soc_attr[] = {
|
|
|
|
&dev_attr_machine.attr,
|
|
|
|
&dev_attr_family.attr,
|
2019-07-23 16:35:11 -06:00
|
|
|
&dev_attr_serial_number.attr,
|
2012-02-06 12:22:22 -07:00
|
|
|
&dev_attr_soc_id.attr,
|
|
|
|
&dev_attr_revision.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group soc_attr_group = {
|
|
|
|
.attrs = soc_attr,
|
|
|
|
.is_visible = soc_attribute_mode,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void soc_release(struct device *dev)
|
|
|
|
{
|
|
|
|
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
|
|
|
|
|
2019-10-07 14:37:42 -06:00
|
|
|
ida_simple_remove(&soc_ida, soc_dev->soc_dev_num);
|
|
|
|
kfree(soc_dev->dev.groups);
|
2012-02-06 12:22:22 -07:00
|
|
|
kfree(soc_dev);
|
|
|
|
}
|
|
|
|
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
static struct soc_device_attribute *early_soc_dev_attr;
|
|
|
|
|
2012-02-06 12:22:22 -07:00
|
|
|
struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)
|
|
|
|
{
|
|
|
|
struct soc_device *soc_dev;
|
2019-10-07 14:37:42 -06:00
|
|
|
const struct attribute_group **soc_attr_groups;
|
2012-02-06 12:22:22 -07:00
|
|
|
int ret;
|
|
|
|
|
2016-09-27 09:10:29 -06:00
|
|
|
if (!soc_bus_type.p) {
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
if (early_soc_dev_attr)
|
|
|
|
return ERR_PTR(-EBUSY);
|
|
|
|
early_soc_dev_attr = soc_dev_attr;
|
|
|
|
return NULL;
|
2016-09-27 09:10:29 -06:00
|
|
|
}
|
|
|
|
|
2012-02-06 12:22:22 -07:00
|
|
|
soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL);
|
|
|
|
if (!soc_dev) {
|
2015-03-08 14:33:44 -06:00
|
|
|
ret = -ENOMEM;
|
2012-02-06 12:22:22 -07:00
|
|
|
goto out1;
|
|
|
|
}
|
|
|
|
|
2019-10-07 14:37:42 -06:00
|
|
|
soc_attr_groups = kcalloc(3, sizeof(*soc_attr_groups), GFP_KERNEL);
|
|
|
|
if (!soc_attr_groups) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
soc_attr_groups[0] = &soc_attr_group;
|
|
|
|
soc_attr_groups[1] = soc_dev_attr->custom_attr_group;
|
|
|
|
|
2012-02-06 12:22:22 -07:00
|
|
|
/* Fetch a unique (reclaimable) SOC ID. */
|
2015-10-01 12:59:09 -06:00
|
|
|
ret = ida_simple_get(&soc_ida, 0, 0, GFP_KERNEL);
|
|
|
|
if (ret < 0)
|
2019-10-07 14:37:42 -06:00
|
|
|
goto out3;
|
2015-10-01 12:59:09 -06:00
|
|
|
soc_dev->soc_dev_num = ret;
|
2012-02-06 12:22:22 -07:00
|
|
|
|
|
|
|
soc_dev->attr = soc_dev_attr;
|
|
|
|
soc_dev->dev.bus = &soc_bus_type;
|
|
|
|
soc_dev->dev.groups = soc_attr_groups;
|
|
|
|
soc_dev->dev.release = soc_release;
|
|
|
|
|
|
|
|
dev_set_name(&soc_dev->dev, "soc%d", soc_dev->soc_dev_num);
|
|
|
|
|
|
|
|
ret = device_register(&soc_dev->dev);
|
2019-10-07 14:37:42 -06:00
|
|
|
if (ret) {
|
|
|
|
put_device(&soc_dev->dev);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
2012-02-06 12:22:22 -07:00
|
|
|
|
|
|
|
return soc_dev;
|
|
|
|
|
|
|
|
out3:
|
2019-10-07 14:37:42 -06:00
|
|
|
kfree(soc_attr_groups);
|
2012-02-06 12:22:22 -07:00
|
|
|
out2:
|
|
|
|
kfree(soc_dev);
|
|
|
|
out1:
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
2019-07-23 16:35:12 -06:00
|
|
|
EXPORT_SYMBOL_GPL(soc_device_register);
|
2012-02-06 12:22:22 -07:00
|
|
|
|
|
|
|
/* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
|
|
|
|
void soc_device_unregister(struct soc_device *soc_dev)
|
|
|
|
{
|
|
|
|
device_unregister(&soc_dev->dev);
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
early_soc_dev_attr = NULL;
|
2012-02-06 12:22:22 -07:00
|
|
|
}
|
2019-07-23 16:35:12 -06:00
|
|
|
EXPORT_SYMBOL_GPL(soc_device_unregister);
|
2012-02-06 12:22:22 -07:00
|
|
|
|
|
|
|
static int __init soc_bus_register(void)
|
|
|
|
{
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
int ret;
|
2016-09-27 09:10:29 -06:00
|
|
|
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
ret = bus_register(&soc_bus_type);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (early_soc_dev_attr)
|
|
|
|
return PTR_ERR(soc_device_register(early_soc_dev_attr));
|
|
|
|
|
|
|
|
return 0;
|
2012-02-06 12:22:22 -07:00
|
|
|
}
|
|
|
|
core_initcall(soc_bus_register);
|
2016-09-21 00:57:19 -06:00
|
|
|
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
static int soc_device_match_attr(const struct soc_device_attribute *attr,
|
|
|
|
const struct soc_device_attribute *match)
|
2016-09-21 00:57:19 -06:00
|
|
|
{
|
|
|
|
if (match->machine &&
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
(!attr->machine || !glob_match(match->machine, attr->machine)))
|
2016-09-21 00:57:19 -06:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (match->family &&
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
(!attr->family || !glob_match(match->family, attr->family)))
|
2016-09-21 00:57:19 -06:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (match->revision &&
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
(!attr->revision || !glob_match(match->revision, attr->revision)))
|
2016-09-21 00:57:19 -06:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (match->soc_id &&
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
(!attr->soc_id || !glob_match(match->soc_id, attr->soc_id)))
|
2016-09-21 00:57:19 -06:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
static int soc_device_match_one(struct device *dev, void *arg)
|
|
|
|
{
|
|
|
|
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
|
|
|
|
|
|
|
|
return soc_device_match_attr(soc_dev->attr, arg);
|
|
|
|
}
|
|
|
|
|
2016-09-21 00:57:19 -06:00
|
|
|
/*
|
|
|
|
* soc_device_match - identify the SoC in the machine
|
|
|
|
* @matches: zero-terminated array of possible matches
|
|
|
|
*
|
|
|
|
* returns the first matching entry of the argument array, or NULL
|
|
|
|
* if none of them match.
|
|
|
|
*
|
|
|
|
* This function is meant as a helper in place of of_match_node()
|
|
|
|
* in cases where either no device tree is available or the information
|
|
|
|
* in a device node is insufficient to identify a particular variant
|
|
|
|
* by its compatible strings or other properties. For new devices,
|
|
|
|
* the DT binding should always provide unique compatible strings
|
|
|
|
* that allow the use of of_match_node() instead.
|
|
|
|
*
|
|
|
|
* The calling function can use the .data entry of the
|
|
|
|
* soc_device_attribute to pass a structure or function pointer for
|
|
|
|
* each entry.
|
|
|
|
*/
|
|
|
|
const struct soc_device_attribute *soc_device_match(
|
|
|
|
const struct soc_device_attribute *matches)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!matches)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while (!ret) {
|
|
|
|
if (!(matches->machine || matches->family ||
|
|
|
|
matches->revision || matches->soc_id))
|
|
|
|
break;
|
|
|
|
ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches,
|
|
|
|
soc_device_match_one);
|
base: soc: Allow early registration of a single SoC device
Commit 1da1b3628df34a2a ("base: soc: Early register bus when needed")
added support for early registration of SoC devices from a
core_initcall(). However, some drivers need to check the SoC revision
from an early_initcall(), which is even earlier.
A specific example is the Renesas R-Car SYSC driver, which manages PM
Domains and thus needs to be initialized from an early_initcall.
Preproduction versions of the R-Car H3 SoC have an additional power
area, which no longer exists on H3 ES2.0, so the R-Car SYSC driver needs
to check the exact SoC revision before instantiating a PM Domain for
that power area.
While registering the SoC bus and device, and using soc_device_match(),
from an early_initcall() do work, the "soc" directory and the "soc0"
file end up wrongly in the sysfs root, as the "bus" resp. "devices"
directories haven't been created yet.
To fix this, allow to register a single SoC device early on.
As long as the SoC bus isn't registered, soc_device_match() just
matches against this early device.
When the SoC bus is registered later, the early device is registered for
real.
Note that soc_device_register() returns NULL (no error, but also not a
valid pointer) when registering an early device. Hence platform devices
cannot be instantiated as children of the "soc0" node representing an
early SoC device. This should not be an issue, as that practice has
been deprecated for new platforms.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Arnd Bergmann <arnd@arndb.de>
2017-03-09 06:17:50 -07:00
|
|
|
if (ret < 0 && early_soc_dev_attr)
|
|
|
|
ret = soc_device_match_attr(early_soc_dev_attr,
|
|
|
|
matches);
|
2017-03-09 04:28:18 -07:00
|
|
|
if (ret < 0)
|
|
|
|
return NULL;
|
2016-09-21 00:57:19 -06:00
|
|
|
if (!ret)
|
|
|
|
matches++;
|
|
|
|
else
|
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(soc_device_match);
|