Commit 6e12db37 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven

base: soc: Allow early registration of a single SoC device

Commit 1da1b362 ("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: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Acked-by: default avatarArnd Bergmann <arnd@arndb.de>
parent 0656db9e
...@@ -109,15 +109,18 @@ static void soc_release(struct device *dev) ...@@ -109,15 +109,18 @@ static void soc_release(struct device *dev)
kfree(soc_dev); kfree(soc_dev);
} }
static struct soc_device_attribute *early_soc_dev_attr;
struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr) struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)
{ {
struct soc_device *soc_dev; struct soc_device *soc_dev;
int ret; int ret;
if (!soc_bus_type.p) { if (!soc_bus_type.p) {
ret = bus_register(&soc_bus_type); if (early_soc_dev_attr)
if (ret) return ERR_PTR(-EBUSY);
goto out1; early_soc_dev_attr = soc_dev_attr;
return NULL;
} }
soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL); soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL);
...@@ -159,45 +162,53 @@ void soc_device_unregister(struct soc_device *soc_dev) ...@@ -159,45 +162,53 @@ void soc_device_unregister(struct soc_device *soc_dev)
ida_simple_remove(&soc_ida, soc_dev->soc_dev_num); ida_simple_remove(&soc_ida, soc_dev->soc_dev_num);
device_unregister(&soc_dev->dev); device_unregister(&soc_dev->dev);
early_soc_dev_attr = NULL;
} }
static int __init soc_bus_register(void) static int __init soc_bus_register(void)
{ {
if (soc_bus_type.p) int ret;
return 0;
return bus_register(&soc_bus_type); 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;
} }
core_initcall(soc_bus_register); core_initcall(soc_bus_register);
static int soc_device_match_one(struct device *dev, void *arg) static int soc_device_match_attr(const struct soc_device_attribute *attr,
const struct soc_device_attribute *match)
{ {
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
const struct soc_device_attribute *match = arg;
if (match->machine && if (match->machine &&
(!soc_dev->attr->machine || (!attr->machine || !glob_match(match->machine, attr->machine)))
!glob_match(match->machine, soc_dev->attr->machine)))
return 0; return 0;
if (match->family && if (match->family &&
(!soc_dev->attr->family || (!attr->family || !glob_match(match->family, attr->family)))
!glob_match(match->family, soc_dev->attr->family)))
return 0; return 0;
if (match->revision && if (match->revision &&
(!soc_dev->attr->revision || (!attr->revision || !glob_match(match->revision, attr->revision)))
!glob_match(match->revision, soc_dev->attr->revision)))
return 0; return 0;
if (match->soc_id && if (match->soc_id &&
(!soc_dev->attr->soc_id || (!attr->soc_id || !glob_match(match->soc_id, attr->soc_id)))
!glob_match(match->soc_id, soc_dev->attr->soc_id)))
return 0; return 0;
return 1; return 1;
} }
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);
}
/* /*
* soc_device_match - identify the SoC in the machine * soc_device_match - identify the SoC in the machine
* @matches: zero-terminated array of possible matches * @matches: zero-terminated array of possible matches
...@@ -230,6 +241,9 @@ const struct soc_device_attribute *soc_device_match( ...@@ -230,6 +241,9 @@ const struct soc_device_attribute *soc_device_match(
break; break;
ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches, ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches,
soc_device_match_one); soc_device_match_one);
if (ret < 0 && early_soc_dev_attr)
ret = soc_device_match_attr(early_soc_dev_attr,
matches);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
if (!ret) if (!ret)
......
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