* [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand
@ 2023-01-16 13:36 Ahmad Fatoum
2023-01-16 13:36 ` [PATCH 2/3] i2c: write debug print when registering any i2c client Ahmad Fatoum
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-01-16 13:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Most devices featuring a detect callback use it to probe an underlying
bus. However, of_device_create_on_demand so far created devices on the
platform bus, ignoring that it might be e.g. an I2C device that's
supposed to be crated by the parent controller.
Fix this by calling the parent's detect callback if available. Busses
that probe via device tree, but register their devices on a different
bus will need to register a detect callback to benefit from this.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/of/platform.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index ff7096b6eedd..edb082b106ff 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -414,11 +414,18 @@ static struct device *of_device_create_on_demand(struct device_node *np)
{
struct device_node *parent;
struct device *parent_dev, *dev;
+ int ret;
parent = of_get_parent(np);
if (!parent)
return NULL;
+ if (!np->dev && parent->dev) {
+ ret = device_detect(parent->dev);
+ if (ret && ret != -ENOSYS)
+ return ERR_PTR(ret);
+ }
+
if (!np->dev)
pr_debug("Creating device for %s\n", np->full_name);
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] i2c: write debug print when registering any i2c client
2023-01-16 13:36 [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand Ahmad Fatoum
@ 2023-01-16 13:36 ` Ahmad Fatoum
2023-01-16 13:36 ` [PATCH 3/3] i2c: implement detect callback Ahmad Fatoum
2023-01-20 7:36 ` [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-01-16 13:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
There's no debug message when registering a device over DT, only via
legacy board info. Add a common print instead.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/i2c/i2c.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index a7b5cb94ff13..3b5e68618dff 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -410,6 +410,9 @@ static struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
if (chip->of_node)
chip->of_node->dev = &client->dev;
+ dev_dbg(&client->dev, "registered on bus %d, chip->addr 0x%02x\n",
+ adapter->nr, client->addr);
+
return client;
}
@@ -541,7 +544,6 @@ static void scan_boardinfo(struct i2c_adapter *adapter)
continue;
for (n = bi->n_board_info; n > 0; n--, chip++) {
- debug("%s: bus_num: %d, chip->addr 0x%02x\n", __func__, bi->bus_num, chip->addr);
/*
* NOTE: this relies on i2c_new_device to
* issue diagnostics when given bogus inputs
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] i2c: implement detect callback
2023-01-16 13:36 [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand Ahmad Fatoum
2023-01-16 13:36 ` [PATCH 2/3] i2c: write debug print when registering any i2c client Ahmad Fatoum
@ 2023-01-16 13:36 ` Ahmad Fatoum
2023-01-20 7:36 ` [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-01-16 13:36 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
of_device_ensure_probed will call device::detect on the I2C adapter,
so it can detect its children node, in case they were not probed before.
This can happen if the nodes were added dynamically via device tree
fixup or overlay. Implement a detect callback to support this.
To keep existing behavior, we call this detect callback unconditionally
while newly registering the adapter.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/i2c/i2c.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 3b5e68618dff..7e1cea49f3b6 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -420,10 +420,6 @@ static void of_i2c_register_devices(struct i2c_adapter *adap)
{
struct device_node *n;
- /* Only register child devices if the adapter has a node pointer set */
- if (!IS_ENABLED(CONFIG_OFDEVICE) || !adap->dev.of_node)
- return;
-
for_each_available_child_of_node(adap->dev.of_node, n) {
struct i2c_board_info info = {};
struct i2c_client *result;
@@ -475,6 +471,20 @@ int of_i2c_register_devices_by_node(struct device_node *node)
return 0;
}
+static int i2c_bus_detect(struct device *dev)
+{
+ struct i2c_adapter *adap;
+
+ list_for_each_entry(adap, &i2c_adapter_list, list) {
+ if (dev != adap->dev.parent)
+ continue;
+ of_i2c_register_devices(adap);
+ break;
+ }
+
+ return 0;
+}
+
/**
* i2c_new_dummy - return a new i2c device bound to a dummy driver
* @adapter: the adapter managing the device
@@ -686,6 +696,7 @@ EXPORT_SYMBOL_GPL(i2c_parse_fw_timings);
*/
int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
{
+ struct device *hw_dev;
int ret;
if (adapter->nr < 0) {
@@ -712,7 +723,12 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
/* populate children from any i2c device tables */
scan_boardinfo(adapter);
- of_i2c_register_devices(adapter);
+ hw_dev = adapter->dev.parent;
+ if (hw_dev && dev_of_node(hw_dev)) {
+ if (!hw_dev->detect)
+ hw_dev->detect = i2c_bus_detect;
+ i2c_bus_detect(hw_dev);
+ }
return 0;
}
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand
2023-01-16 13:36 [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand Ahmad Fatoum
2023-01-16 13:36 ` [PATCH 2/3] i2c: write debug print when registering any i2c client Ahmad Fatoum
2023-01-16 13:36 ` [PATCH 3/3] i2c: implement detect callback Ahmad Fatoum
@ 2023-01-20 7:36 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-01-20 7:36 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Jan 16, 2023 at 02:36:37PM +0100, Ahmad Fatoum wrote:
> Most devices featuring a detect callback use it to probe an underlying
> bus. However, of_device_create_on_demand so far created devices on the
> platform bus, ignoring that it might be e.g. an I2C device that's
> supposed to be crated by the parent controller.
>
> Fix this by calling the parent's detect callback if available. Busses
> that probe via device tree, but register their devices on a different
> bus will need to register a detect callback to benefit from this.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/of/platform.c | 7 +++++++
> 1 file changed, 7 insertions(+)
Applied, thanks
Sascha
>
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index ff7096b6eedd..edb082b106ff 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -414,11 +414,18 @@ static struct device *of_device_create_on_demand(struct device_node *np)
> {
> struct device_node *parent;
> struct device *parent_dev, *dev;
> + int ret;
>
> parent = of_get_parent(np);
> if (!parent)
> return NULL;
>
> + if (!np->dev && parent->dev) {
> + ret = device_detect(parent->dev);
> + if (ret && ret != -ENOSYS)
> + return ERR_PTR(ret);
> + }
> +
> if (!np->dev)
> pr_debug("Creating device for %s\n", np->full_name);
>
> --
> 2.30.2
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-20 7:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-16 13:36 [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand Ahmad Fatoum
2023-01-16 13:36 ` [PATCH 2/3] i2c: write debug print when registering any i2c client Ahmad Fatoum
2023-01-16 13:36 ` [PATCH 3/3] i2c: implement detect callback Ahmad Fatoum
2023-01-20 7:36 ` [PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox