mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/7] support overlays to the barebox live tree
@ 2023-03-08 14:05 Sascha Hauer
  2023-03-08 14:05 ` [PATCH 1/7] kbuild: Add target to build dtb overlay files Sascha Hauer
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Sascha Hauer @ 2023-03-08 14:05 UTC (permalink / raw)
  To: Barebox List

Support for applying a device tree overlay to the barebox live tree
is already present. This series adds a few missing pieces:

- add support for applying overlays to the live tree from the command
  line
- add support for adding new I2C/SPI devices via overlays
- add Makefile magic to build dtbo files and dtbo.o files to include
  into the barebox binary from dtso files

Sascha Hauer (7):
  kbuild: Add target to build dtb overlay files
  driver: Add rescan hook to struct device
  i2c: implement rescan
  spi: Directly register SPI device
  spi: reduce scope of 'chip'
  spi: implement rescan
  of_overlay: Add option to apply overlay to live tree

 commands/of_overlay.c  | 38 ++++++++++++++++++++++++++++++++++----
 drivers/i2c/i2c.c      | 16 +++-------------
 drivers/of/platform.c  |  5 ++++-
 drivers/spi/spi.c      | 31 ++++++++++++++++++++++++++-----
 include/driver.h       |  1 +
 scripts/Makefile.build |  4 ++++
 scripts/Makefile.lib   | 11 ++++++++++-
 7 files changed, 82 insertions(+), 24 deletions(-)

-- 
2.30.2




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

* [PATCH 1/7] kbuild: Add target to build dtb overlay files
  2023-03-08 14:05 [PATCH 0/7] support overlays to the barebox live tree Sascha Hauer
@ 2023-03-08 14:05 ` Sascha Hauer
  2023-03-08 14:05 ` [PATCH 2/7] driver: Add rescan hook to struct device Sascha Hauer
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2023-03-08 14:05 UTC (permalink / raw)
  To: Barebox List

Device tree overlay files have the suffix dtso in source format
and dtbo in binary format. Add the necessary targets to build dtbo
files from dtso files and also dtbo.o files to include into the
barebox binary.
The overlay files shouldn't include the device tree snippets from
CONFIG_EXTERNAL_DTS_FRAGMENTS which makes it necessary to specify
these fragments as an argument to cmd_dtc.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 scripts/Makefile.build |  4 ++++
 scripts/Makefile.lib   | 11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 216f03677b..33480a81b4 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -258,12 +258,16 @@ intermediate_targets = $(foreach sfx, $(2), \
 					$(filter %$(strip $(1)), $(targets))))
 # %.asn1.o <- %.asn1.[ch] <- %.asn1
 # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
+# %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso
 # %.dtb.pbl.o <- %.dtb.S <- %.dtb <- %.dts (Barebox only)
+# %.dtbo.pbl.o <- %.dtbo.S <- %.dtbo <- %.dtso (Barebox only)
 # %.lex.o <- %.lex.c <- %.l
 # %.tab.o <- %.tab.[ch] <- %.y
 targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
 	   $(call intermediate_targets, .dtb.o, .dtb.S .dtb.z .dtb) \
+	   $(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo.z .dtbo) \
 	   $(call intermediate_targets, .dtb.pbl.o, .dtb.S .dtb.z .dtb) \
+	   $(call intermediate_targets, .dtbo.pbl.o, .dtbo.S .dtbo.z .dtbo) \
 	   $(call intermediate_targets, .lex.o, .lex.c) \
 	   $(call intermediate_targets, .tab.o, .tab.c .tab.h)
 
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 6e0d92cf75..6af2fe07b2 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -361,13 +361,19 @@ cmd_dt_S_dtb = $(srctree)/scripts/gen-dtb-s $(subst -,_,$(*F)) $< $(CONFIG_IMD)
 $(obj)/%.dtb.S: $(obj)/%.dtb $(obj)/%.dtb.z $(srctree)/scripts/gen-dtb-s FORCE
 	$(call if_changed,dt_S_dtb)
 
+$(obj)/%.dtbo.S: $(obj)/%.dtbo $(obj)/%.dtbo.z $(srctree)/scripts/gen-dtb-s FORCE
+	$(call if_changed,dt_S_dtb)
+
 $(obj)/%.dtb.z: $(obj)/%.dtb FORCE
 	$(call if_changed,$(suffix_y))
 
+$(obj)/%.dtbo.z: $(obj)/%.dtbo FORCE
+	$(call if_changed,$(suffix_y))
+
 dts-frags = $(subst $(quote),,$(CONFIG_EXTERNAL_DTS_FRAGMENTS))
 quiet_cmd_dtc = DTC     $@
 # For compatibility between make 4.2 and 4.3
-cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(dts-frags),'$(pound)include "$(f)"\n') | \
+cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(foreach f,$< $(2),'$(pound)include "$(f)"\n') | \
 	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) - ; \
 	$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 \
 		-i $(srctree)/arch/$(SRCARCH)/dts $(DTC_FLAGS) \
@@ -376,6 +382,9 @@ cmd_dtc = /usr/bin/env echo -e '$(pound)define $(subst -,_,$(*F))_dts 1\n'$(fore
 	cat $(depfile).pre $(depfile).dtc > $(depfile)
 
 $(obj)/%.dtb: $(src)/%.dts FORCE
+	$(call if_changed_dep,dtc,$(dts-frags))
+
+$(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE
 	$(call if_changed_dep,dtc)
 
 dtc-tmp = $(subst $(comma),_,$(dot-target).dts)
-- 
2.30.2




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

* [PATCH 2/7] driver: Add rescan hook to struct device
  2023-03-08 14:05 [PATCH 0/7] support overlays to the barebox live tree Sascha Hauer
  2023-03-08 14:05 ` [PATCH 1/7] kbuild: Add target to build dtb overlay files Sascha Hauer
@ 2023-03-08 14:05 ` Sascha Hauer
  2023-03-08 14:05 ` [PATCH 3/7] i2c: implement rescan Sascha Hauer
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2023-03-08 14:05 UTC (permalink / raw)
  To: Barebox List

When devices are enabled with a device tree overlay the newly enabled
devices can be probed by doing a of_probe(). This works fine for the
regular platform devices, but doesn't work for devices which are not
probed by the core, but by the subsystem. Prominent examples are I2C or
SPI devices.

This patch adds a struct device::rescan hook that subsystems can
implement to trigger rescanning the device nodes.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/platform.c | 5 ++++-
 include/driver.h      | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index edb082b106..e688075f16 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -153,8 +153,11 @@ struct device *of_platform_device_create(struct device_node *np,
 	 * Linux uses the OF_POPULATED flag to skip already populated/created
 	 * devices.
 	 */
-	if (np->dev)
+	if (np->dev) {
+		if (np->dev->rescan)
+			np->dev->rescan(np->dev);
 		return np->dev;
+	}
 
 	/* count the io resources */
 	if (of_can_translate_address(np))
diff --git a/include/driver.h b/include/driver.h
index f53668711b..205f232753 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -91,6 +91,7 @@ struct device {
 	 * when the driver should actually detect client devices
 	 */
 	int     (*detect) (struct device *);
+	int	(*rescan) (struct device *);
 
 	/*
 	 * if a driver probe is deferred, this stores the last error
-- 
2.30.2




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

* [PATCH 3/7] i2c: implement rescan
  2023-03-08 14:05 [PATCH 0/7] support overlays to the barebox live tree Sascha Hauer
  2023-03-08 14:05 ` [PATCH 1/7] kbuild: Add target to build dtb overlay files Sascha Hauer
  2023-03-08 14:05 ` [PATCH 2/7] driver: Add rescan hook to struct device Sascha Hauer
@ 2023-03-08 14:05 ` Sascha Hauer
  2023-03-09 11:36   ` Ahmad Fatoum
  2023-03-08 14:05 ` [PATCH 4/7] spi: Directly register SPI device Sascha Hauer
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2023-03-08 14:05 UTC (permalink / raw)
  To: Barebox List

struct device::rescan is called by the core to let the subsystem rescan
the controllers device node. Implement that for I2C. Ahmad recently
implemented the struct device::detect hook for the very same purpose.
The downside of that approach was that device_detect() had to be called
manually and that either needs knowledge which device actually has
updated device nodes, or all devices were detected, like unrelated USB
or MMC/SD devices. The rescan hook doesn't need that manual detect call,
so just drop the I2C detect implementation in favour for implementing
rescan.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/i2c/i2c.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index efcad29342..aac4488b5c 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -471,15 +471,7 @@ 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 = container_of(dev, struct i2c_adapter, dev);
-
-	of_i2c_register_devices(adap);
-	return 0;
-}
-
-static int i2c_hw_detect(struct device *dev)
+static int i2c_hw_rescan(struct device *dev)
 {
 	struct i2c_adapter *adap;
 
@@ -720,7 +712,6 @@ 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);
@@ -734,9 +725,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_hw_detect;
-		i2c_hw_detect(hw_dev);
+		if (!hw_dev->rescan)
+			hw_dev->rescan = i2c_hw_rescan;
 	}
 
 	return 0;
-- 
2.30.2




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

* [PATCH 4/7] spi: Directly register SPI device
  2023-03-08 14:05 [PATCH 0/7] support overlays to the barebox live tree Sascha Hauer
                   ` (2 preceding siblings ...)
  2023-03-08 14:05 ` [PATCH 3/7] i2c: implement rescan Sascha Hauer
@ 2023-03-08 14:05 ` Sascha Hauer
  2023-03-08 14:05 ` [PATCH 5/7] spi: reduce scope of 'chip' Sascha Hauer
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2023-03-08 14:05 UTC (permalink / raw)
  To: Barebox List

SPI devices described in the device tree are not directly registered,
but instead added to the SPI board_list which is normally used to
register SPI devices from board code. This seems rather unnecessary,
drop this detour and register SPI devices directly from
spi_of_register_slaves().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/spi/spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index d6f939e51c..1444fe3741 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -138,7 +138,7 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
 			continue;
 		chip.chip_select = of_read_number(reg->value, 1);
 		chip.device_node = n;
-		spi_register_board_info(&chip, 1);
+		spi_new_device(ctrl, &chip);
 	}
 }
 
-- 
2.30.2




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

* [PATCH 5/7] spi: reduce scope of 'chip'
  2023-03-08 14:05 [PATCH 0/7] support overlays to the barebox live tree Sascha Hauer
                   ` (3 preceding siblings ...)
  2023-03-08 14:05 ` [PATCH 4/7] spi: Directly register SPI device Sascha Hauer
@ 2023-03-08 14:05 ` Sascha Hauer
  2023-03-08 14:05 ` [PATCH 6/7] spi: implement rescan Sascha Hauer
  2023-03-08 14:05 ` [PATCH 7/7] of_overlay: Add option to apply overlay to live tree Sascha Hauer
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2023-03-08 14:05 UTC (permalink / raw)
  To: Barebox List

Reducde scope of struct spi_board_info chip to the loop where it is
actually only used. While at it drop the memset and let the compiler
do the work of initialising it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/spi/spi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 1444fe3741..3684647f6e 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -108,7 +108,6 @@ EXPORT_SYMBOL(spi_new_device);
 static void spi_of_register_slaves(struct spi_controller *ctrl)
 {
 	struct device_node *n;
-	struct spi_board_info chip;
 	struct property *reg;
 	struct device_node *node = ctrl->dev->of_node;
 
@@ -119,7 +118,8 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
 		return;
 
 	for_each_available_child_of_node(node, n) {
-		memset(&chip, 0, sizeof(chip));
+		struct spi_board_info chip = {};
+
 		chip.name = xstrdup(n->name);
 		chip.bus_num = ctrl->bus_num;
 		/* Mode (clock phase/polarity/etc.) */
-- 
2.30.2




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

* [PATCH 6/7] spi: implement rescan
  2023-03-08 14:05 [PATCH 0/7] support overlays to the barebox live tree Sascha Hauer
                   ` (4 preceding siblings ...)
  2023-03-08 14:05 ` [PATCH 5/7] spi: reduce scope of 'chip' Sascha Hauer
@ 2023-03-08 14:05 ` Sascha Hauer
  2023-03-08 14:05 ` [PATCH 7/7] of_overlay: Add option to apply overlay to live tree Sascha Hauer
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2023-03-08 14:05 UTC (permalink / raw)
  To: Barebox List

Implement rescan to register and probe newly added devices via device
tree overlays.

While this is easy to do at SPI core level this is not the whole truth.
Many SPI controllers do not use their native chipselects for the SPI
devices, but GPIOs instead. These currently won't be rescanned when new
devices are added, so the chipselects for the new devices must be be
present in the base device tree already. You have been warned.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/spi/spi.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 3684647f6e..632c2dbc4a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -29,6 +29,7 @@ struct boardinfo {
 };
 
 static LIST_HEAD(board_list);
+static LIST_HEAD(spi_controller_list);
 
 /**
  * spi_new_device - instantiate one new SPI device
@@ -120,6 +121,12 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
 	for_each_available_child_of_node(node, n) {
 		struct spi_board_info chip = {};
 
+		if (n->dev) {
+			dev_dbg(ctrl->dev, "of_i2c: skipping already registered %s\n",
+				dev_name(n->dev));
+			continue;
+		}
+
 		chip.name = xstrdup(n->name);
 		chip.bus_num = ctrl->bus_num;
 		/* Mode (clock phase/polarity/etc.) */
@@ -142,6 +149,19 @@ static void spi_of_register_slaves(struct spi_controller *ctrl)
 	}
 }
 
+static int spi_controller_rescan(struct device *dev)
+{
+	struct spi_controller *ctrl;
+
+	list_for_each_entry(ctrl, &spi_controller_list, list) {
+		if (ctrl->dev != dev)
+			continue;
+		spi_of_register_slaves(ctrl);
+	}
+
+	return 0;
+}
+
 /**
  * spi_register_board_info - register SPI devices for a given board
  * @info: array of chip descriptors
@@ -196,8 +216,6 @@ static void scan_boardinfo(struct spi_controller *ctrl)
 	}
 }
 
-static LIST_HEAD(spi_controller_list);
-
 static int spi_controller_check_ops(struct spi_controller *ctlr)
 {
 	/*
@@ -274,6 +292,9 @@ int spi_register_controller(struct spi_controller *ctrl)
 	scan_boardinfo(ctrl);
 	status = 0;
 
+	if (!ctrl->dev->rescan)
+		ctrl->dev->rescan = spi_controller_rescan;
+
 	return status;
 }
 EXPORT_SYMBOL(spi_register_controller);
-- 
2.30.2




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

* [PATCH 7/7] of_overlay: Add option to apply overlay to live tree
  2023-03-08 14:05 [PATCH 0/7] support overlays to the barebox live tree Sascha Hauer
                   ` (5 preceding siblings ...)
  2023-03-08 14:05 ` [PATCH 6/7] spi: implement rescan Sascha Hauer
@ 2023-03-08 14:05 ` Sascha Hauer
  6 siblings, 0 replies; 9+ messages in thread
From: Sascha Hauer @ 2023-03-08 14:05 UTC (permalink / raw)
  To: Barebox List

The of_overlay command currently only supports applying overlays to the
Linux device tree. Add an option to apply an overlay to the live tree.
Using this option will apply the overlay and also triggers rescanning
the device tree in case new devices have been added.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/of_overlay.c | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/commands/of_overlay.c b/commands/of_overlay.c
index b3660b4bf1..1d68e31ef2 100644
--- a/commands/of_overlay.c
+++ b/commands/of_overlay.c
@@ -17,10 +17,20 @@ static int do_of_overlay(int argc, char *argv[])
 	struct fdt_header *fdt;
 	struct device_node *overlay;
 	size_t size;
+	bool live_tree = false;
+	int opt;
 
-	if (argc != 2)
+	if (argc < 2)
 		return COMMAND_ERROR_USAGE;
 
+	while ((opt = getopt(argc, argv, "l")) > 0) {
+		switch (opt) {
+		case 'l':
+			live_tree = true;
+			break;
+		}
+	}
+
 	fdt = read_file(argv[optind], &size);
 	if (!fdt) {
 		printf("cannot read %s\n", argv[optind]);
@@ -32,7 +42,14 @@ static int do_of_overlay(int argc, char *argv[])
 	if (IS_ERR(overlay))
 		return PTR_ERR(overlay);
 
-	ret = of_register_overlay(overlay);
+	if (live_tree) {
+		ret = of_overlay_apply_tree(of_get_root_node(), overlay);
+		if (!ret)
+			ret = of_probe();
+	} else {
+		ret = of_register_overlay(overlay);
+	}
+
 	if (ret) {
 		printf("cannot apply oftree overlay: %s\n", strerror(-ret));
 		goto err;
@@ -45,9 +62,22 @@ err:
 	return ret;
 }
 
+BAREBOX_CMD_HELP_START(of_overlay)
+BAREBOX_CMD_HELP_TEXT("Register a device tree overlay file (dtbo) with barebox.")
+BAREBOX_CMD_HELP_TEXT("By default the overlay is registered as a fixup and the")
+BAREBOX_CMD_HELP_TEXT("overlay will then be applied to the Linux device tree.")
+BAREBOX_CMD_HELP_TEXT("With -l given the overlay is applied to the barebox live")
+BAREBOX_CMD_HELP_TEXT("tree instead. This involves probing new devices added in")
+BAREBOX_CMD_HELP_TEXT("the overlay file.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-l", "apply to barebox live tree")
+BAREBOX_CMD_HELP_END
+
 BAREBOX_CMD_START(of_overlay)
 	.cmd = do_of_overlay,
-	BAREBOX_CMD_DESC("register device tree overlay as fixup")
-	BAREBOX_CMD_OPTS("FILE")
+	BAREBOX_CMD_DESC("register device tree overlay")
+	BAREBOX_CMD_OPTS("[-l] FILE")
 	BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+	BAREBOX_CMD_HELP(cmd_of_overlay_help)
 BAREBOX_CMD_END
-- 
2.30.2




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

* Re: [PATCH 3/7] i2c: implement rescan
  2023-03-08 14:05 ` [PATCH 3/7] i2c: implement rescan Sascha Hauer
@ 2023-03-09 11:36   ` Ahmad Fatoum
  0 siblings, 0 replies; 9+ messages in thread
From: Ahmad Fatoum @ 2023-03-09 11:36 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List

Hello Sascha,

On 08.03.23 15:05, Sascha Hauer wrote:
> struct device::rescan is called by the core to let the subsystem rescan
> the controllers device node. Implement that for I2C. Ahmad recently
> implemented the struct device::detect hook for the very same purpose.
> The downside of that approach was that device_detect() had to be called
> manually and that either needs knowledge which device actually has
> updated device nodes, or all devices were detected, like unrelated USB
> or MMC/SD devices. The rescan hook doesn't need that manual detect call,
> so just drop the I2C detect implementation in favour for implementing
> rescan.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/i2c/i2c.c | 16 +++-------------
>  1 file changed, 3 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index efcad29342..aac4488b5c 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -471,15 +471,7 @@ 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 = container_of(dev, struct i2c_adapter, dev);
> -
> -	of_i2c_register_devices(adap);
> -	return 0;
> -}
> -
> -static int i2c_hw_detect(struct device *dev)
> +static int i2c_hw_rescan(struct device *dev)
>  {
>  	struct i2c_adapter *adap;
>  
> @@ -720,7 +712,6 @@ 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);
> @@ -734,9 +725,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_hw_detect;
> -		i2c_hw_detect(hw_dev);

This breaks normal probe of child devices. You can stick a
of_i2c_register_devices(adapter); here instead.

> +		if (!hw_dev->rescan)
> +			hw_dev->rescan = i2c_hw_rescan;
>  	}
>  
>  	return 0;

-- 
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] 9+ messages in thread

end of thread, other threads:[~2023-03-09 11:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-08 14:05 [PATCH 0/7] support overlays to the barebox live tree Sascha Hauer
2023-03-08 14:05 ` [PATCH 1/7] kbuild: Add target to build dtb overlay files Sascha Hauer
2023-03-08 14:05 ` [PATCH 2/7] driver: Add rescan hook to struct device Sascha Hauer
2023-03-08 14:05 ` [PATCH 3/7] i2c: implement rescan Sascha Hauer
2023-03-09 11:36   ` Ahmad Fatoum
2023-03-08 14:05 ` [PATCH 4/7] spi: Directly register SPI device Sascha Hauer
2023-03-08 14:05 ` [PATCH 5/7] spi: reduce scope of 'chip' Sascha Hauer
2023-03-08 14:05 ` [PATCH 6/7] spi: implement rescan Sascha Hauer
2023-03-08 14:05 ` [PATCH 7/7] of_overlay: Add option to apply overlay to live tree Sascha Hauer

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