mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] i2c: implement detect callback for virtual adapter device as well
@ 2023-01-25  7:53 Ahmad Fatoum
  2023-01-25  9:27 ` Marco Felsch
  2023-01-26  8:18 ` Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-01-25  7:53 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

For MMCs, we already support detect on both the hardware device and the
mmcX virtual device. Let's do the same for i2c, so users have the option
to do `detect i2c0` instead of `detect 30a30000.i2c@30a30000.of`.

`detect -a` still works as expected, as the detect callback is a no-op
if everything on the bus is already registered.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/i2c/i2c.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 7e1cea49f3b6..4ecf7bb163e6 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -472,6 +472,14 @@ int of_i2c_register_devices_by_node(struct device_node *node)
 }
 
 static int i2c_bus_detect(struct device *dev)
+{
+	struct i2c_adapter *adap = container_of(dev, struct i2c_adapter, dev);
+
+	of_i2c_register_devices(adap);
+	return 0;
+}
+
+static int i2c_hw_detect(struct device *dev)
 {
 	struct i2c_adapter *adap;
 
@@ -712,6 +720,7 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
 	}
 
 	adapter->dev.id = adapter->nr;
+	adapter->dev.detect = i2c_bus_detect;
 	dev_set_name(&adapter->dev, "i2c");
 
 	ret = register_device(&adapter->dev);
@@ -726,8 +735,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *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);
+			hw_dev->detect = i2c_hw_detect;
+		i2c_hw_detect(hw_dev);
 	}
 
 	return 0;
-- 
2.30.2




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: implement detect callback for virtual adapter device as well
  2023-01-25  7:53 [PATCH] i2c: implement detect callback for virtual adapter device as well Ahmad Fatoum
@ 2023-01-25  9:27 ` Marco Felsch
  2023-01-25  9:43   ` Ahmad Fatoum
  2023-01-26  8:18 ` Sascha Hauer
  1 sibling, 1 reply; 4+ messages in thread
From: Marco Felsch @ 2023-01-25  9:27 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

Hi Ahmad,

On 23-01-25, Ahmad Fatoum wrote:
> For MMCs, we already support detect on both the hardware device and the
> mmcX virtual device. Let's do the same for i2c, so users have the option
> to do `detect i2c0` instead of `detect 30a30000.i2c@30a30000.of`.

nice :)

> `detect -a` still works as expected, as the detect callback is a no-op
> if everything on the bus is already registered.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>

> ---
>  drivers/i2c/i2c.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index 7e1cea49f3b6..4ecf7bb163e6 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -472,6 +472,14 @@ int of_i2c_register_devices_by_node(struct device_node *node)
>  }
>  
>  static int i2c_bus_detect(struct device *dev)
> +{
> +	struct i2c_adapter *adap = container_of(dev, struct i2c_adapter, dev);
> +
> +	of_i2c_register_devices(adap);
> +	return 0;
> +}
> +
> +static int i2c_hw_detect(struct device *dev)
>  {
>  	struct i2c_adapter *adap;
>  
> @@ -712,6 +720,7 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
>  	}
>  
>  	adapter->dev.id = adapter->nr;
> +	adapter->dev.detect = i2c_bus_detect;
>  	dev_set_name(&adapter->dev, "i2c");
>  
>  	ret = register_device(&adapter->dev);
> @@ -726,8 +735,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *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);
> +			hw_dev->detect = i2c_hw_detect;
> +		i2c_hw_detect(hw_dev);
>  	}
>  
>  	return 0;
> -- 
> 2.30.2
> 
> 
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] i2c: implement detect callback for virtual adapter device as well
  2023-01-25  9:27 ` Marco Felsch
@ 2023-01-25  9:43   ` Ahmad Fatoum
  0 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-01-25  9:43 UTC (permalink / raw)
  To: Marco Felsch; +Cc: barebox

On 25.01.23 10:27, Marco Felsch wrote:
> Hi Ahmad,
> 
> On 23-01-25, Ahmad Fatoum wrote:
>> For MMCs, we already support detect on both the hardware device and the
>> mmcX virtual device. Let's do the same for i2c, so users have the option
>> to do `detect i2c0` instead of `detect 30a30000.i2c@30a30000.of`.
> 
> nice :)

Glad you like it. Only usecase I have for this is detecting an I2C device
tat was added by an overlay to a bus that was already probed beforehand.

I2C bus probe is still on-by-default, though we could change
that in future.

I still need to wire this into the overlay code to call bus detect automatically.

> 
>> `detect -a` still works as expected, as the detect callback is a no-op
>> if everything on the bus is already registered.
>>
>> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> 
> Reviewed-by: Marco Felsch <m.felsch@pengutronix.de>
> 
>> ---
>>  drivers/i2c/i2c.c | 13 +++++++++++--
>>  1 file changed, 11 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
>> index 7e1cea49f3b6..4ecf7bb163e6 100644
>> --- a/drivers/i2c/i2c.c
>> +++ b/drivers/i2c/i2c.c
>> @@ -472,6 +472,14 @@ int of_i2c_register_devices_by_node(struct device_node *node)
>>  }
>>  
>>  static int i2c_bus_detect(struct device *dev)
>> +{
>> +	struct i2c_adapter *adap = container_of(dev, struct i2c_adapter, dev);
>> +
>> +	of_i2c_register_devices(adap);
>> +	return 0;
>> +}
>> +
>> +static int i2c_hw_detect(struct device *dev)
>>  {
>>  	struct i2c_adapter *adap;
>>  
>> @@ -712,6 +720,7 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
>>  	}
>>  
>>  	adapter->dev.id = adapter->nr;
>> +	adapter->dev.detect = i2c_bus_detect;
>>  	dev_set_name(&adapter->dev, "i2c");
>>  
>>  	ret = register_device(&adapter->dev);
>> @@ -726,8 +735,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *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);
>> +			hw_dev->detect = i2c_hw_detect;
>> +		i2c_hw_detect(hw_dev);
>>  	}
>>  
>>  	return 0;
>> -- 
>> 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

* Re: [PATCH] i2c: implement detect callback for virtual adapter device as well
  2023-01-25  7:53 [PATCH] i2c: implement detect callback for virtual adapter device as well Ahmad Fatoum
  2023-01-25  9:27 ` Marco Felsch
@ 2023-01-26  8:18 ` Sascha Hauer
  1 sibling, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-01-26  8:18 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Wed, Jan 25, 2023 at 08:53:23AM +0100, Ahmad Fatoum wrote:
> For MMCs, we already support detect on both the hardware device and the
> mmcX virtual device. Let's do the same for i2c, so users have the option
> to do `detect i2c0` instead of `detect 30a30000.i2c@30a30000.of`.
> 
> `detect -a` still works as expected, as the detect callback is a no-op
> if everything on the bus is already registered.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/i2c/i2c.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index 7e1cea49f3b6..4ecf7bb163e6 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -472,6 +472,14 @@ int of_i2c_register_devices_by_node(struct device_node *node)
>  }
>  
>  static int i2c_bus_detect(struct device *dev)
> +{
> +	struct i2c_adapter *adap = container_of(dev, struct i2c_adapter, dev);
> +
> +	of_i2c_register_devices(adap);
> +	return 0;
> +}
> +
> +static int i2c_hw_detect(struct device *dev)
>  {
>  	struct i2c_adapter *adap;
>  
> @@ -712,6 +720,7 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
>  	}
>  
>  	adapter->dev.id = adapter->nr;
> +	adapter->dev.detect = i2c_bus_detect;
>  	dev_set_name(&adapter->dev, "i2c");
>  
>  	ret = register_device(&adapter->dev);
> @@ -726,8 +735,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *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);
> +			hw_dev->detect = i2c_hw_detect;
> +		i2c_hw_detect(hw_dev);
>  	}
>  
>  	return 0;
> -- 
> 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-26  8:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25  7:53 [PATCH] i2c: implement detect callback for virtual adapter device as well Ahmad Fatoum
2023-01-25  9:27 ` Marco Felsch
2023-01-25  9:43   ` Ahmad Fatoum
2023-01-26  8:18 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox