Skip to content

Commit 6e12db3

Browse files
committed
base: soc: Allow early registration of a single SoC device
Commit 1da1b36 ("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>
1 parent 0656db9 commit 6e12db3

1 file changed

Lines changed: 32 additions & 18 deletions

File tree

‎drivers/base/soc.c‎

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,18 @@ static void soc_release(struct device *dev)
109109
kfree(soc_dev);
110110
}
111111

112+
static struct soc_device_attribute *early_soc_dev_attr;
113+
112114
struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)
113115
{
114116
struct soc_device *soc_dev;
115117
int ret;
116118

117119
if (!soc_bus_type.p) {
118-
ret = bus_register(&soc_bus_type);
119-
if (ret)
120-
goto out1;
120+
if (early_soc_dev_attr)
121+
return ERR_PTR(-EBUSY);
122+
early_soc_dev_attr = soc_dev_attr;
123+
return NULL;
121124
}
122125

123126
soc_dev = kzalloc(sizeof(*soc_dev), GFP_KERNEL);
@@ -159,45 +162,53 @@ void soc_device_unregister(struct soc_device *soc_dev)
159162
ida_simple_remove(&soc_ida, soc_dev->soc_dev_num);
160163

161164
device_unregister(&soc_dev->dev);
165+
early_soc_dev_attr = NULL;
162166
}
163167

164168
static int __init soc_bus_register(void)
165169
{
166-
if (soc_bus_type.p)
167-
return 0;
170+
int ret;
168171

169-
return bus_register(&soc_bus_type);
172+
ret = bus_register(&soc_bus_type);
173+
if (ret)
174+
return ret;
175+
176+
if (early_soc_dev_attr)
177+
return PTR_ERR(soc_device_register(early_soc_dev_attr));
178+
179+
return 0;
170180
}
171181
core_initcall(soc_bus_register);
172182

173-
static int soc_device_match_one(struct device *dev, void *arg)
183+
static int soc_device_match_attr(const struct soc_device_attribute *attr,
184+
const struct soc_device_attribute *match)
174185
{
175-
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
176-
const struct soc_device_attribute *match = arg;
177-
178186
if (match->machine &&
179-
(!soc_dev->attr->machine ||
180-
!glob_match(match->machine, soc_dev->attr->machine)))
187+
(!attr->machine || !glob_match(match->machine, attr->machine)))
181188
return 0;
182189

183190
if (match->family &&
184-
(!soc_dev->attr->family ||
185-
!glob_match(match->family, soc_dev->attr->family)))
191+
(!attr->family || !glob_match(match->family, attr->family)))
186192
return 0;
187193

188194
if (match->revision &&
189-
(!soc_dev->attr->revision ||
190-
!glob_match(match->revision, soc_dev->attr->revision)))
195+
(!attr->revision || !glob_match(match->revision, attr->revision)))
191196
return 0;
192197

193198
if (match->soc_id &&
194-
(!soc_dev->attr->soc_id ||
195-
!glob_match(match->soc_id, soc_dev->attr->soc_id)))
199+
(!attr->soc_id || !glob_match(match->soc_id, attr->soc_id)))
196200
return 0;
197201

198202
return 1;
199203
}
200204

205+
static int soc_device_match_one(struct device *dev, void *arg)
206+
{
207+
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
208+
209+
return soc_device_match_attr(soc_dev->attr, arg);
210+
}
211+
201212
/*
202213
* soc_device_match - identify the SoC in the machine
203214
* @matches: zero-terminated array of possible matches
@@ -230,6 +241,9 @@ const struct soc_device_attribute *soc_device_match(
230241
break;
231242
ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches,
232243
soc_device_match_one);
244+
if (ret < 0 && early_soc_dev_attr)
245+
ret = soc_device_match_attr(early_soc_dev_attr,
246+
matches);
233247
if (ret < 0)
234248
return NULL;
235249
if (!ret)

0 commit comments

Comments
 (0)