mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/18] Barebox Deep-Probe
@ 2020-09-28 15:50 Marco Felsch
  2020-09-28 15:50 ` [PATCH 01/18] video: ssd1307fb: fix VBAT supply id Marco Felsch
                   ` (18 more replies)
  0 siblings, 19 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

Hi all,

this series is our approach to address the EPROBE_DEFER and initcall
shifting problem. I skip the deep-probe explanation here and instead
refer to the detailed commit message of patch 15. 

Patche 1-11:
 - Fixes and cleanups I found during the development of deep-probe

Patch 12-14:
 - Preliminary for the deep-probe mechanism

Patch 15:
 - The interesting part of this series. This patch implements the
   deep-probe mechanism and adds helpers to make your board deep-probe
   aware.

Patch 16-17:
 - Adds STM32MP1 and i.MX architecture specific deep-probe code. For
   those architectures this means that we need to populate the
   memory-controller.

Patch 18:
 - Convert the sabrelite board to use the deep_probe mechanism. This can
   be used as example for others :)

Comments & testers are welcome :)

PS:
This series is based on Sascha's commit
http://lists.infradead.org/pipermail/barebox/2020-September/033979.html.
You need to apply this one before applying this series.

Regards,
  Marco

Lucas Stach (1):
  of: base: move memory init from DT to initcall

Marco Felsch (17):
  video: ssd1307fb: fix VBAT supply id
  ARM: boards: mx6-sabrelite: [cosmetic] make use of IMX_GPIO_NR
  drivers: gpio: treewide: [cosmetic] use register_driver_macros
  ARM: mx6-sabrelite: remove obsolete sabrelite_mem_init()
  spi: core: don't ignore register_device failures
  regulator: improve of_regulator_register error handling
  regulator: test of_regulator_register input before accessing it
  regulator: stpmic1: fix registering missed regulators
  regulator: add device reference to regulator_dev
  regulator: treewide: drop local device_d reference
  of: platform: fix of_amba_device_create stub return value
  of: base: move clock init from of_probe() to barebox_register_of()
  initcall: add of_populate_initcall
  common: add initial barebox deep-probe support
  ARM: i.MX: esdctl: add deep-probe support
  ARM: stm32mp: ddrctrl: add deep-probe support
  ARM: boards: mx6-sabrelite: add deep-probe support

 .../boards/freescale-mx6-sabrelite/board.c    |  56 +++++-----
 arch/arm/mach-imx/esdctl.c                    |  16 ++-
 arch/arm/mach-stm32mp/ddrctrl.c               |  15 ++-
 common/Makefile                               |   1 +
 common/deep-probe.c                           |  39 +++++++
 drivers/base/driver.c                         |  11 +-
 drivers/clk/clk.c                             |   5 +
 drivers/gpio/gpio-ath79.c                     |   7 +-
 drivers/gpio/gpio-davinci.c                   |   7 +-
 drivers/gpio/gpio-digic.c                     |   7 +-
 drivers/gpio/gpio-dw.c                        |   7 +-
 drivers/gpio/gpio-generic.c                   |   7 +-
 drivers/gpio/gpio-imx.c                       |   8 +-
 drivers/gpio/gpio-jz4740.c                    |   7 +-
 drivers/gpio/gpio-malta-fpga-i2c.c            |   7 +-
 drivers/gpio/gpio-mpc8xxx.c                   |   7 +-
 drivers/gpio/gpio-mxs.c                       |   8 +-
 drivers/gpio/gpio-omap.c                      |   7 +-
 drivers/gpio/gpio-stmpe.c                     |   7 +-
 drivers/gpio/gpio-tegra.c                     |   7 +-
 drivers/gpio/gpio-vf610.c                     |   7 +-
 drivers/i2c/i2c.c                             |   6 +
 drivers/of/base.c                             |  28 ++++-
 drivers/of/platform.c                         | 103 +++++++++++++++++-
 drivers/regulator/anatop-regulator.c          |   1 +
 drivers/regulator/bcm2835.c                   |  24 ++--
 drivers/regulator/core.c                      |  12 ++
 drivers/regulator/fixed.c                     |   1 +
 drivers/regulator/stm32-pwr.c                 |   7 +-
 drivers/regulator/stpmic1_regulator.c         |   8 +-
 drivers/reset/core.c                          |   5 +
 drivers/spi/spi.c                             |   6 +-
 drivers/video/ssd1307fb.c                     |   2 +-
 include/asm-generic/barebox.lds.h             |   1 +
 include/deep-probe.h                          |  17 +++
 include/init.h                                |  10 +-
 include/of.h                                  |  37 ++++++-
 include/regulator.h                           |   2 +
 38 files changed, 357 insertions(+), 156 deletions(-)
 create mode 100644 common/deep-probe.c
 create mode 100644 include/deep-probe.h

-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 01/18] video: ssd1307fb: fix VBAT supply id
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:58   ` Ahmad Fatoum
  2020-09-28 15:50 ` [PATCH 02/18] ARM: boards: mx6-sabrelite: [cosmetic] make use of IMX_GPIO_NR Marco Felsch
                   ` (17 subsequent siblings)
  18 siblings, 1 reply; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

The regulator id should be given without the "-supply" suffix else the
core is searching for "vbat-supply-supply".

Fixes: bf8f62d334 ("video/ssd1307fb: add support for VBAT")
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/video/ssd1307fb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/ssd1307fb.c b/drivers/video/ssd1307fb.c
index 0709399358..994f43dc5c 100644
--- a/drivers/video/ssd1307fb.c
+++ b/drivers/video/ssd1307fb.c
@@ -421,7 +421,7 @@ static int ssd1307fb_probe(struct device_d *dev)
 		goto fb_alloc_error;
 	}
 
-	par->vbat = regulator_get(&client->dev, "vbat-supply");
+	par->vbat = regulator_get(&client->dev, "vbat");
 	if (IS_ERR(par->vbat)) {
 		dev_info(&client->dev, "Will not use VBAT");
 		par->vbat = NULL;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 02/18] ARM: boards: mx6-sabrelite: [cosmetic] make use of IMX_GPIO_NR
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
  2020-09-28 15:50 ` [PATCH 01/18] video: ssd1307fb: fix VBAT supply id Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 16:00   ` Ahmad Fatoum
  2020-09-28 15:50 ` [PATCH 03/18] drivers: gpio: treewide: [cosmetic] use register_driver_macros Marco Felsch
                   ` (16 subsequent siblings)
  18 siblings, 1 reply; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

Convert the global number to the more readable IMX_GPIO_NR() macro, no
functional changes.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 .../boards/freescale-mx6-sabrelite/board.c    | 20 +++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/arm/boards/freescale-mx6-sabrelite/board.c b/arch/arm/boards/freescale-mx6-sabrelite/board.c
index f4f2994a51..020a44297a 100644
--- a/arch/arm/boards/freescale-mx6-sabrelite/board.c
+++ b/arch/arm/boards/freescale-mx6-sabrelite/board.c
@@ -70,37 +70,37 @@ static int ksz9021rn_phy_fixup(struct phy_device *dev)
 
 static struct gpio fec_gpios[] = {
 	{
-		.gpio = 87,
+		.gpio = IMX_GPIO_NR(3, 23),
 		.flags = GPIOF_OUT_INIT_LOW,
 		.label = "phy-rst",
 	}, {
-		.gpio = 190,
+		.gpio = IMX_GPIO_NR(6, 30),
 		.flags = GPIOF_OUT_INIT_HIGH,
 		.label = "phy-addr2",
 	}, {
-		.gpio = 23,
+		.gpio = IMX_GPIO_NR(1, 23),
 		.flags = GPIOF_OUT_INIT_LOW,
 		.label = "phy-led-mode",
 	}, {
 		/* MODE strap-in pins: advertise all capabilities */
-		.gpio = 185,
+		.gpio = IMX_GPIO_NR(6, 25),
 		.flags = GPIOF_OUT_INIT_HIGH,
 		.label = "phy-adv1",
 	}, {
-		.gpio = 187,
+		.gpio = IMX_GPIO_NR(6, 27),
 		.flags = GPIOF_OUT_INIT_HIGH,
 		.label = "phy-adv1",
 	}, {
-		.gpio = 188,
+		.gpio = IMX_GPIO_NR(6, 28),
 		.flags = GPIOF_OUT_INIT_HIGH,
 		.label = "phy-adv1",
 	}, {
-		.gpio = 189,
+		.gpio = IMX_GPIO_NR(6, 29),
 		.flags = GPIOF_OUT_INIT_HIGH,
 		.label = "phy-adv1",
 	}, {
 		/* Enable 125 MHz clock output */
-		.gpio = 184,
+		.gpio = IMX_GPIO_NR(6, 24),
 		.flags = GPIOF_OUT_INIT_HIGH,
 		.label = "phy-125MHz",
 	},
@@ -139,9 +139,9 @@ fs_initcall(sabrelite_ksz9021rn_setup);
 static void sabrelite_ehci_init(void)
 {
 	/* hub reset */
-	gpio_direction_output(204, 0);
+	gpio_direction_output(IMX_GPIO_NR(7, 12), 0);
 	udelay(2000);
-	gpio_set_value(204, 1);
+	gpio_set_value(IMX_GPIO_NR(7, 12), 1);
 }
 
 static int sabrelite_devices_init(void)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 03/18] drivers: gpio: treewide: [cosmetic] use register_driver_macros
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
  2020-09-28 15:50 ` [PATCH 01/18] video: ssd1307fb: fix VBAT supply id Marco Felsch
  2020-09-28 15:50 ` [PATCH 02/18] ARM: boards: mx6-sabrelite: [cosmetic] make use of IMX_GPIO_NR Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 16:04   ` Ahmad Fatoum
  2020-09-29  8:20   ` Sascha Hauer
  2020-09-28 15:50 ` [PATCH 04/18] ARM: mx6-sabrelite: remove obsolete sabrelite_mem_init() Marco Felsch
                   ` (15 subsequent siblings)
  18 siblings, 2 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

Use the existing macros to register the drivers. No functional changes
except for the gpio-mxs and gpio-imx driver. Now they do not ignore the
return values anymore.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/gpio/gpio-ath79.c          | 7 +------
 drivers/gpio/gpio-davinci.c        | 7 +------
 drivers/gpio/gpio-digic.c          | 7 +------
 drivers/gpio/gpio-dw.c             | 7 +------
 drivers/gpio/gpio-generic.c        | 7 +------
 drivers/gpio/gpio-imx.c            | 8 +-------
 drivers/gpio/gpio-jz4740.c         | 7 +------
 drivers/gpio/gpio-malta-fpga-i2c.c | 7 +------
 drivers/gpio/gpio-mpc8xxx.c        | 7 +------
 drivers/gpio/gpio-mxs.c            | 8 +-------
 drivers/gpio/gpio-omap.c           | 7 +------
 drivers/gpio/gpio-stmpe.c          | 7 +------
 drivers/gpio/gpio-tegra.c          | 7 +------
 drivers/gpio/gpio-vf610.c          | 7 +------
 14 files changed, 14 insertions(+), 86 deletions(-)

diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
index d08d743b54..a33d7d290e 100644
--- a/drivers/gpio/gpio-ath79.c
+++ b/drivers/gpio/gpio-ath79.c
@@ -150,9 +150,4 @@ static struct driver_d ath79_gpio_driver = {
 	.probe = ath79_gpio_probe,
 	.of_compatible = DRV_OF_COMPAT(ath79_gpio_of_match),
 };
-
-static int ath79_gpio_init(void)
-{
-	return platform_driver_register(&ath79_gpio_driver);
-}
-coredevice_initcall(ath79_gpio_init);
+coredevice_platform_driver(ath79_gpio_driver);
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 7c060a09b1..bffe385860 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -205,9 +205,4 @@ static struct driver_d davinci_gpio_driver = {
 	.probe		= davinci_gpio_probe,
 	.of_compatible	= DRV_OF_COMPAT(davinci_gpio_ids),
 };
-
-static int davinci_gpio_drv_reg(void)
-{
-	return platform_driver_register(&davinci_gpio_driver);
-}
-coredevice_initcall(davinci_gpio_drv_reg);
+coredevice_platform_driver(davinci_gpio_driver);
diff --git a/drivers/gpio/gpio-digic.c b/drivers/gpio/gpio-digic.c
index f7a68d09fc..4cf45397ce 100644
--- a/drivers/gpio/gpio-digic.c
+++ b/drivers/gpio/gpio-digic.c
@@ -175,9 +175,4 @@ static struct driver_d digic_gpio_driver = {
 	.probe = digic_gpio_probe,
 	.of_compatible = DRV_OF_COMPAT(digic_gpio_dt_ids),
 };
-
-static int digic_gpio_init(void)
-{
-	return platform_driver_register(&digic_gpio_driver);
-}
-coredevice_initcall(digic_gpio_init);
+coredevice_platform_driver(digic_gpio_driver);
diff --git a/drivers/gpio/gpio-dw.c b/drivers/gpio/gpio-dw.c
index b81e6a75c5..dd7efd2942 100644
--- a/drivers/gpio/gpio-dw.c
+++ b/drivers/gpio/gpio-dw.c
@@ -194,9 +194,4 @@ static struct driver_d dwgpio_driver = {
 	.probe = dw_gpio_probe,
 	.of_compatible = DRV_OF_COMPAT(dwgpio_match),
 };
-
-static int __init dwgpio_init(void)
-{
-	return platform_driver_register(&dwgpio_driver);
-}
-postcore_initcall(dwgpio_init);
+postcore_platform_driver(dwgpio_driver);
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index 2e0dad9974..ad4e6859cb 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -423,12 +423,7 @@ static struct driver_d bgpio_driver = {
 	.probe		= bgpio_dev_probe,
 	.remove		= bgpio_dev_remove,
 };
-
-static int bgpio_register(void)
-{
-	return platform_driver_register(&bgpio_driver);
-}
-coredevice_initcall(bgpio_register);
+coredevice_platform_driver(bgpio_driver);
 
 #endif
 
diff --git a/drivers/gpio/gpio-imx.c b/drivers/gpio/gpio-imx.c
index 2827e11e73..6f913377f0 100644
--- a/drivers/gpio/gpio-imx.c
+++ b/drivers/gpio/gpio-imx.c
@@ -216,10 +216,4 @@ static struct driver_d imx_gpio_driver = {
 	.of_compatible = DRV_OF_COMPAT(imx_gpio_dt_ids),
 	.id_table = imx_gpio_ids,
 };
-
-static int imx_gpio_add(void)
-{
-	platform_driver_register(&imx_gpio_driver);
-	return 0;
-}
-postcore_initcall(imx_gpio_add);
+postcore_platform_driver(imx_gpio_driver);
diff --git a/drivers/gpio/gpio-jz4740.c b/drivers/gpio/gpio-jz4740.c
index 87e0716b06..bd126c83c1 100644
--- a/drivers/gpio/gpio-jz4740.c
+++ b/drivers/gpio/gpio-jz4740.c
@@ -135,9 +135,4 @@ static struct driver_d jz4740_gpio_driver = {
 	.probe = jz4740_gpio_probe,
 	.of_compatible	= DRV_OF_COMPAT(jz4740_gpio_dt_ids),
 };
-
-static int jz4740_gpio_init(void)
-{
-	return platform_driver_register(&jz4740_gpio_driver);
-}
-coredevice_initcall(jz4740_gpio_init);
+coredevice_platform_driver(jz4740_gpio_driver);
diff --git a/drivers/gpio/gpio-malta-fpga-i2c.c b/drivers/gpio/gpio-malta-fpga-i2c.c
index 9142248571..7afa40460f 100644
--- a/drivers/gpio/gpio-malta-fpga-i2c.c
+++ b/drivers/gpio/gpio-malta-fpga-i2c.c
@@ -179,9 +179,4 @@ static struct driver_d malta_i2c_gpio_driver = {
 	.probe = malta_i2c_gpio_probe,
 	.of_compatible	= DRV_OF_COMPAT(malta_i2c_gpio_dt_ids),
 };
-
-static int malta_i2c_gpio_driver_init(void)
-{
-	return platform_driver_register(&malta_i2c_gpio_driver);
-}
-coredevice_initcall(malta_i2c_gpio_driver_init);
+coredevice_platform_driver(malta_i2c_gpio_driver);
diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
index 979f92ad30..a5a383bfd6 100644
--- a/drivers/gpio/gpio-mpc8xxx.c
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -114,9 +114,4 @@ static struct driver_d mpc8xxx_driver = {
 	.probe		= mpc8xxx_probe,
 	.of_compatible  = DRV_OF_COMPAT(mpc8xxx_gpio_ids),
 };
-
-static int __init mpc8xxx_init(void)
-{
-	return platform_driver_register(&mpc8xxx_driver);
-}
-postcore_initcall(mpc8xxx_init);
+postcore_platform_driver(mpc8xxx_driver);
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index ef78873ad2..43a1379077 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -177,10 +177,4 @@ static struct driver_d mxs_gpio_driver = {
 	.of_compatible = DRV_OF_COMPAT(mxs_gpio_dt_ids),
 	.id_table = mxs_gpio_ids,
 };
-
-static int mxs_gpio_add(void)
-{
-	platform_driver_register(&mxs_gpio_driver);
-	return 0;
-}
-postcore_initcall(mxs_gpio_add);
+postcore_platform_driver(mxs_gpio_driver);
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index b00766a6aa..9075f68926 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -191,9 +191,4 @@ static struct driver_d omap_gpio_driver = {
 	.probe = omap_gpio_probe,
 	.of_compatible = DRV_OF_COMPAT(omap_gpio_dt_ids),
 };
-
-static int omap_gpio_add(void)
-{
-	return platform_driver_register(&omap_gpio_driver);
-}
-coredevice_initcall(omap_gpio_add);
+coredevice_platform_driver(omap_gpio_driver);
diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
index d7e64045b4..d0319a6dc8 100644
--- a/drivers/gpio/gpio-stmpe.c
+++ b/drivers/gpio/gpio-stmpe.c
@@ -153,9 +153,4 @@ static struct driver_d stmpe_gpio_driver = {
 	.name = "stmpe-gpio",
 	.probe = stmpe_gpio_probe,
 };
-
-static int stmpe_gpio_add(void)
-{
-	return platform_driver_register(&stmpe_gpio_driver);
-}
-coredevice_initcall(stmpe_gpio_add);
+coredevice_platform_driver(stmpe_gpio_driver);
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 56808b57e4..331402607c 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -200,9 +200,4 @@ static struct driver_d tegra_gpio_driver = {
 	.of_compatible	= DRV_OF_COMPAT(tegra_gpio_dt_ids),
 	.probe		= tegra_gpio_probe,
 };
-
-static int __init tegra_gpio_init(void)
-{
-	return platform_driver_register(&tegra_gpio_driver);
-}
-coredevice_initcall(tegra_gpio_init);
+coredevice_platform_driver(tegra_gpio_driver);
diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index ab35310fbe..55df0a591c 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -155,9 +155,4 @@ static struct driver_d vf610_gpio_driver = {
 	.probe  = vf610_gpio_probe,
 	.of_compatible = DRV_OF_COMPAT(vf610_gpio_dt_ids),
 };
-
-static int __init gpio_vf610_init(void)
-{
-	return platform_driver_register(&vf610_gpio_driver);
-}
-postcore_initcall(gpio_vf610_init);
+postcore_platform_driver(vf610_gpio_driver);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 04/18] ARM: mx6-sabrelite: remove obsolete sabrelite_mem_init()
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (2 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 03/18] drivers: gpio: treewide: [cosmetic] use register_driver_macros Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 16:07   ` Ahmad Fatoum
  2020-09-28 15:50 ` [PATCH 05/18] spi: core: don't ignore register_device failures Marco Felsch
                   ` (14 subsequent siblings)
  18 siblings, 1 reply; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

The memory init is done by of_probe_memory() first which is part of the
core_initcall's because the device tree has an valid memory node.
Otherwise the memory-controller driver (esdctl) would add it by reading
the information from the controller which are set by the DCD data.
Therefore we can drop it from the local board file.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 arch/arm/boards/freescale-mx6-sabrelite/board.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/arch/arm/boards/freescale-mx6-sabrelite/board.c b/arch/arm/boards/freescale-mx6-sabrelite/board.c
index 020a44297a..1b39ef82c6 100644
--- a/arch/arm/boards/freescale-mx6-sabrelite/board.c
+++ b/arch/arm/boards/freescale-mx6-sabrelite/board.c
@@ -39,18 +39,6 @@ static iomux_v3_cfg_t sabrelite_enet_gpio_pads[] = {
 	MX6Q_PAD_RGMII_RX_CTL__GPIO_6_24,
 };
 
-static int sabrelite_mem_init(void)
-{
-	if (!of_machine_is_compatible("fsl,imx6q-sabrelite") &&
-	    !of_machine_is_compatible("fsl,imx6dl-sabrelite"))
-		return 0;
-
-	arm_add_mem_device("ram0", 0x10000000, SZ_1G);
-
-	return 0;
-}
-mem_initcall(sabrelite_mem_init);
-
 static int ksz9021rn_phy_fixup(struct phy_device *dev)
 {
 	phy_write(dev, 0x09, 0x0f00);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 05/18] spi: core: don't ignore register_device failures
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (3 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 04/18] ARM: mx6-sabrelite: remove obsolete sabrelite_mem_init() Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 06/18] regulator: improve of_regulator_register error handling Marco Felsch
                   ` (13 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

Add missing error handling for spi_new_device().

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/spi/spi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 0694f14c39..8421d9d7c1 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -103,7 +103,9 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl,
 		goto fail;
 	}
 
-	register_device(&proxy->dev);
+	status = register_device(&proxy->dev);
+	if (status)
+		goto fail;
 
 	return proxy;
 fail:
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 06/18] regulator: improve of_regulator_register error handling
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (4 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 05/18] spi: core: don't ignore register_device failures Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 07/18] regulator: test of_regulator_register input before accessing it Marco Felsch
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

Don't ignore errors from __regulator_register().

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/regulator/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 74e00d7791..a767e383fb 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -168,6 +168,9 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
 	name = of_get_property(node, "regulator-name", NULL);
 
 	ri = __regulator_register(rd, name);
+	if (IS_ERR(ri))
+		return PTR_ERR(ri);
+
 	ri->node = node;
 
 	of_property_read_u32(node, "regulator-enable-ramp-delay",
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 07/18] regulator: test of_regulator_register input before accessing it
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (5 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 06/18] regulator: improve of_regulator_register error handling Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 16:11   ` Ahmad Fatoum
  2020-09-28 15:50 ` [PATCH 08/18] regulator: stpmic1: fix registering missed regulators Marco Felsch
                   ` (11 subsequent siblings)
  18 siblings, 1 reply; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

Add simple parameter check to avoid possible NULL pointer dereferences.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/regulator/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a767e383fb..6ea21a4609 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -163,6 +163,9 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
 	struct regulator_internal *ri;
 	const char *name;
 
+	if (!rd || !node)
+		return -EINVAL;
+
 	rd->boot_on = of_property_read_bool(node, "regulator-boot-on");
 
 	name = of_get_property(node, "regulator-name", NULL);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 08/18] regulator: stpmic1: fix registering missed regulators
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (6 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 07/18] regulator: test of_regulator_register input before accessing it Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 09/18] regulator: add device reference to regulator_dev Marco Felsch
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

The dts regulators subnode can be incomplete e.g. if the pre-programmed
values are valid and shouldn't be changed. Missing regulator nodes are
indicated by "of_regulator_match->of_node == NULL". Take missing
regulators into account and register only existing ones.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/regulator/stpmic1_regulator.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/regulator/stpmic1_regulator.c b/drivers/regulator/stpmic1_regulator.c
index 71a4ae80c3..2b4b729541 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -383,6 +383,11 @@ static int stpmic1_regulator_register(struct device_d *dev, int id,
 {
 	int ret;
 
+	if (!match->of_node) {
+		dev_dbg(dev, "Skip missing DTB regulator %s", match->name);
+		return 0;
+	}
+
 	cfg->dev = dev;
 	cfg->rdev.desc = &cfg->desc;
 	cfg->rdev.regmap = dev_get_regmap(dev->parent, NULL);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 09/18] regulator: add device reference to regulator_dev
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (7 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 08/18] regulator: stpmic1: fix registering missed regulators Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 10/18] regulator: treewide: drop local device_d reference Marco Felsch
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

It is useful to know the physical device a regulator_dev belongs to.
This is at least needed for the new deep-probe mechanism. It is also
useful for a few regulator drivers to drop their own device_d reference.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/regulator/anatop-regulator.c  | 1 +
 drivers/regulator/bcm2835.c           | 1 +
 drivers/regulator/fixed.c             | 1 +
 drivers/regulator/stm32-pwr.c         | 1 +
 drivers/regulator/stpmic1_regulator.c | 1 +
 include/regulator.h                   | 2 ++
 6 files changed, 7 insertions(+)

diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c
index 7ec9446a0a..917f7e8fdd 100644
--- a/drivers/regulator/anatop-regulator.c
+++ b/drivers/regulator/anatop-regulator.c
@@ -67,6 +67,7 @@ static int anatop_regulator_probe(struct device_d *dev)
 
 	rdev->desc = rdesc;
 	rdev->regmap = syscon_node_to_regmap(anatop_np);
+	rdev->dev = dev;
 	if (IS_ERR(rdev->regmap))
 		return PTR_ERR(rdev->regmap);
 
diff --git a/drivers/regulator/bcm2835.c b/drivers/regulator/bcm2835.c
index ea7cf7fe1e..1b1eeaf3b8 100644
--- a/drivers/regulator/bcm2835.c
+++ b/drivers/regulator/bcm2835.c
@@ -126,6 +126,7 @@ static int regulator_bcm2835_probe(struct device_d *dev)
 		rb->rdesc.ops = &bcm2835_ops;
 		rb->rdev.desc = &rb->rdesc;
 		rb->dev = dev;
+		rb->rdev.dev = dev;
 
 		ret = dev_regulator_register(&rb->rdev, rb->devname, NULL);
 		if (ret)
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 0b1c752493..160a55163f 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -82,6 +82,7 @@ static int regulator_fixed_probe(struct device_d *dev)
 
 	fix->rdesc.ops = &fixed_ops;
 	fix->rdev.desc = &fix->rdesc;
+	fix->rdev.dev = dev;
 
 	if (of_find_property(dev->device_node, "regulator-always-on", NULL) ||
 	    of_find_property(dev->device_node, "regulator-boot-on", NULL)) {
diff --git a/drivers/regulator/stm32-pwr.c b/drivers/regulator/stm32-pwr.c
index 296f95bc4c..a509eb6ae6 100644
--- a/drivers/regulator/stm32-pwr.c
+++ b/drivers/regulator/stm32-pwr.c
@@ -182,6 +182,7 @@ static int stm32_pwr_regulator_probe(struct device_d *dev)
 		priv->dev = dev;
 
 		priv->rdev.desc = &desc->desc;
+		priv->rdev.dev = dev;
 
 		priv->supply = regulator_get(dev, desc->supply_name);
 		if (IS_ERR(priv->supply))
diff --git a/drivers/regulator/stpmic1_regulator.c b/drivers/regulator/stpmic1_regulator.c
index 2b4b729541..60905d394e 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -390,6 +390,7 @@ static int stpmic1_regulator_register(struct device_d *dev, int id,
 
 	cfg->dev = dev;
 	cfg->rdev.desc = &cfg->desc;
+	cfg->rdev.dev = dev;
 	cfg->rdev.regmap = dev_get_regmap(dev->parent, NULL);
 	if (IS_ERR(cfg->rdev.regmap))
 		return PTR_ERR(cfg->rdev.regmap);
diff --git a/include/regulator.h b/include/regulator.h
index a9cb6dedca..44eee7b0ad 100644
--- a/include/regulator.h
+++ b/include/regulator.h
@@ -77,6 +77,8 @@ struct regulator_dev {
 	const struct regulator_desc *desc;
 	struct regmap *regmap;
 	int boot_on;
+	/* the device this regulator device belongs to */
+	struct device_d *dev;
 };
 
 struct regulator_ops {
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 10/18] regulator: treewide: drop local device_d reference
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (8 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 09/18] regulator: add device reference to regulator_dev Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 11/18] of: platform: fix of_amba_device_create stub return value Marco Felsch
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

Drop the local reference for each driver since the regulator_dev can
handle this now. Attention: The pfuze is out of scope since this driver
is not really a regulator driver.

While on it fix a few minor style issues on the bcm2835 driver too.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/regulator/bcm2835.c           | 23 +++++++++--------------
 drivers/regulator/stm32-pwr.c         |  6 ++----
 drivers/regulator/stpmic1_regulator.c |  2 --
 3 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/drivers/regulator/bcm2835.c b/drivers/regulator/bcm2835.c
index 1b1eeaf3b8..6423b8a834 100644
--- a/drivers/regulator/bcm2835.c
+++ b/drivers/regulator/bcm2835.c
@@ -14,7 +14,7 @@
 
 #define REG_DEV(_id, _name)		\
 	{				\
-		.id 		= _id,	\
+		.id		= _id,	\
 		.devname	= _name,\
 	}
 
@@ -22,7 +22,6 @@ static struct regulator_bcm2835 {
 	int id;
 	char *devname;
 
-	struct device_d *dev;
 	struct regulator_dev rdev;
 	struct regulator_desc rdesc;
 } regs[] = {
@@ -43,8 +42,9 @@ struct msg_set_power_state {
 	u32 end_tag;
 };
 
-static int regulator_bcm2835_set(struct regulator_bcm2835 *rb, int state)
+static int regulator_bcm2835_set(struct regulator_dev *rdev, int state)
 {
+	struct regulator_bcm2835 *rb = container_of(rdev, struct regulator_bcm2835, rdev);
 	BCM2835_MBOX_STACK_ALIGN(struct msg_set_power_state, msg_pwr);
 	int ret;
 
@@ -59,8 +59,8 @@ static int regulator_bcm2835_set(struct regulator_bcm2835 *rb, int state)
 	ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
 				     &msg_pwr->hdr);
 	if (ret) {
-		dev_err(rb->dev ,"bcm2835: Could not set module %u power state\n",
-		       rb->id);
+		dev_err(rdev->dev, "bcm2835: Could not set module %u power state\n",
+			rb->id);
 		return ret;
 	}
 
@@ -69,16 +69,12 @@ static int regulator_bcm2835_set(struct regulator_bcm2835 *rb, int state)
 
 static int regulator_bcm2835_enable(struct regulator_dev *rdev)
 {
-	struct regulator_bcm2835 *rb = container_of(rdev, struct regulator_bcm2835, rdev);
-
-	return regulator_bcm2835_set(rb, BCM2835_MBOX_SET_POWER_STATE_REQ_ON);
+	return regulator_bcm2835_set(rdev, BCM2835_MBOX_SET_POWER_STATE_REQ_ON);
 }
 
 static int regulator_bcm2835_disable(struct regulator_dev *rdev)
 {
-	struct regulator_bcm2835 *rb = container_of(rdev, struct regulator_bcm2835, rdev);
-
-	return regulator_bcm2835_set(rb, BCM2835_MBOX_SET_POWER_STATE_REQ_OFF);
+	return regulator_bcm2835_set(rdev, BCM2835_MBOX_SET_POWER_STATE_REQ_OFF);
 }
 
 struct msg_get_power_state {
@@ -101,8 +97,8 @@ static int regulator_bcm2835_is_enabled(struct regulator_dev *rdev)
 	ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
 				     &msg_pwr->hdr);
 	if (ret) {
-		dev_err(rb->dev ,"bcm2835: Could not get module %u power state\n",
-		       rb->id);
+		dev_err(rdev->dev, "bcm2835: Could not get module %u power state\n",
+			rb->id);
 		return ret;
 	}
 
@@ -125,7 +121,6 @@ static int regulator_bcm2835_probe(struct device_d *dev)
 
 		rb->rdesc.ops = &bcm2835_ops;
 		rb->rdev.desc = &rb->rdesc;
-		rb->dev = dev;
 		rb->rdev.dev = dev;
 
 		ret = dev_regulator_register(&rb->rdev, rb->devname, NULL);
diff --git a/drivers/regulator/stm32-pwr.c b/drivers/regulator/stm32-pwr.c
index a509eb6ae6..54ba716a8f 100644
--- a/drivers/regulator/stm32-pwr.c
+++ b/drivers/regulator/stm32-pwr.c
@@ -44,7 +44,6 @@ static u32 ready_mask_table[STM32PWR_REG_NUM_REGS] = {
 
 struct stm32_pwr_reg {
 	void __iomem *base;
-	struct device_d *dev;
 	u32 ready_mask;
 	struct regulator_dev rdev;
 	struct regulator *supply;
@@ -97,7 +96,7 @@ static int stm32_pwr_reg_enable(struct regulator_dev *rdev)
 	ret = readx_poll_timeout(stm32_pwr_reg_is_ready, rdev, val, val,
 				 20 * USEC_PER_MSEC);
 	if (ret)
-		dev_err(priv->dev, "%s: regulator enable timed out!\n",
+		dev_err(rdev->dev, "%s: regulator enable timed out!\n",
 			desc->name);
 
 	return ret;
@@ -118,7 +117,7 @@ static int stm32_pwr_reg_disable(struct regulator_dev *rdev)
 	ret = readx_poll_timeout(stm32_pwr_reg_is_ready, rdev, val, !val,
 				 20 * USEC_PER_MSEC);
 	if (ret)
-		dev_err(priv->dev, "%s: regulator disable timed out!\n",
+		dev_err(rdev->dev, "%s: regulator disable timed out!\n",
 			desc->name);
 
 	regulator_disable(priv->supply);
@@ -179,7 +178,6 @@ static int stm32_pwr_regulator_probe(struct device_d *dev)
 		priv = xzalloc(sizeof(*priv));
 		priv->base = IOMEM(iores->start);
 		priv->ready_mask = ready_mask_table[i];
-		priv->dev = dev;
 
 		priv->rdev.desc = &desc->desc;
 		priv->rdev.dev = dev;
diff --git a/drivers/regulator/stpmic1_regulator.c b/drivers/regulator/stpmic1_regulator.c
index 60905d394e..61227e0855 100644
--- a/drivers/regulator/stpmic1_regulator.c
+++ b/drivers/regulator/stpmic1_regulator.c
@@ -21,7 +21,6 @@
  * @icc_mask: icc register mask
  */
 struct stpmic1_regulator_cfg {
-	struct device_d *dev;
 	struct regulator_dev rdev;
 	struct regulator_desc desc;
 	u8 mask_reset_reg;
@@ -388,7 +387,6 @@ static int stpmic1_regulator_register(struct device_d *dev, int id,
 		return 0;
 	}
 
-	cfg->dev = dev;
 	cfg->rdev.desc = &cfg->desc;
 	cfg->rdev.dev = dev;
 	cfg->rdev.regmap = dev_get_regmap(dev->parent, NULL);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 11/18] of: platform: fix of_amba_device_create stub return value
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (9 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 10/18] regulator: treewide: drop local device_d reference Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 12/18] of: base: move memory init from DT to initcall Marco Felsch
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

The stub should have the same function signature as the non-stub
function.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/of/platform.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index ca84cede23..21c7cce1a5 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -282,7 +282,7 @@ amba_err_free:
 	return NULL;
 }
 #else /* CONFIG_ARM_AMBA */
-static inline struct amba_device *of_amba_device_create(struct device_node *np)
+static inline struct device_d *of_amba_device_create(struct device_node *np)
 {
 	return NULL;
 }
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 12/18] of: base: move memory init from DT to initcall
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (10 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 11/18] of: platform: fix of_amba_device_create stub return value Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 13/18] of: base: move clock init from of_probe() to barebox_register_of() Marco Felsch
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

From: Lucas Stach <dev@lynxeye.de>

Instead of calling it from of_probe, convert it to a initcall at
the appropriate level. This allows to move of_probe to later in
the init sequence while keeping the memory init at the same place,
which is important as many other drivers need the valid memory area
to be set up properly.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/of/base.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 6e2fb8b281..4f08c45e40 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2144,10 +2144,13 @@ const struct of_device_id of_default_bus_match_table[] = {
 	}
 };
 
-static void of_probe_memory(void)
+static int of_probe_memory(void)
 {
 	struct device_node *memory = root_node;
 
+	if (!IS_ENABLED(CONFIG_OFDEVICE))
+		return 0;
+
 	/* Parse all available node with "memory" device_type */
 	while (1) {
 		memory = of_find_node_by_type(memory, "memory");
@@ -2156,7 +2159,10 @@ static void of_probe_memory(void)
 
 		of_add_memory(memory, false);
 	}
+
+	return 0;
 }
+mem_initcall(of_probe_memory);
 
 static void of_platform_device_create_root(struct device_node *np)
 {
@@ -2186,8 +2192,6 @@ int of_probe(void)
 	if (of_model)
 		barebox_set_model(of_model);
 
-	of_probe_memory();
-
 	firmware = of_find_node_by_path("/firmware");
 	if (firmware)
 		of_platform_populate(firmware, NULL, NULL);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 13/18] of: base: move clock init from of_probe() to barebox_register_of()
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (11 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 12/18] of: base: move memory init from DT to initcall Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 14/18] initcall: add of_populate_initcall Marco Felsch
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

This is required for the new deep-probe mechanism. Barebox deep-probe
calls of_probe() very late and so clock drivers using the old
CLK_OF_DECLARE_DRIVER() mechanism are added very late. This would break
the deep-probe approach.

Move of_clk_init() and call it right before the the of_probe() should
have no impact because of_clk_init() only depends on an unflatten dtb.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 drivers/of/base.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4f08c45e40..861871b221 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1575,8 +1575,10 @@ void barebox_register_of(struct device_node *root)
 	of_fix_tree(root);
 	of_set_root_node(root);
 
-	if (IS_ENABLED(CONFIG_OFDEVICE))
+	if (IS_ENABLED(CONFIG_OFDEVICE)) {
+		of_clk_init(root, NULL);
 		of_probe();
+	}
 }
 
 void barebox_register_fdt(const void *dtb)
@@ -2198,7 +2200,6 @@ int of_probe(void)
 
 	of_platform_device_create_root(root_node);
 
-	of_clk_init(root_node, NULL);
 	of_platform_populate(root_node, of_default_bus_match_table, NULL);
 
 	return 0;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 14/18] initcall: add of_populate_initcall
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (12 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 13/18] of: base: move clock init from of_probe() to barebox_register_of() Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 15/18] common: add initial barebox deep-probe support Marco Felsch
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

Add dedicated initcall for of_probe() which is required for the following
device-on-demand/deep-probe mechanism.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 include/asm-generic/barebox.lds.h |  1 +
 include/init.h                    | 10 +++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index 6971e2c1d2..a7d32160d1 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -33,6 +33,7 @@
 	KEEP(*(.initcall.12))			\
 	KEEP(*(.initcall.13))			\
 	KEEP(*(.initcall.14))			\
+	KEEP(*(.initcall.15))			\
 	__barebox_initcalls_end = .;
 
 #define BAREBOX_EXITCALLS			\
diff --git a/include/init.h b/include/init.h
index 2d61bc8963..1bd5c94b14 100644
--- a/include/init.h
+++ b/include/init.h
@@ -47,6 +47,9 @@ typedef void (*exitcall_t)(void);
  * initializes variables that couldn't be statically initialized.
  *
  * This only exists for built-in code, not for modules.
+ *
+ * The only purpose for "of_populate" is to call of_probe() other functions are
+ * not allowed.
  */
 #define pure_initcall(fn)		__define_initcall("0",fn,0)
 
@@ -61,9 +64,10 @@ typedef void (*exitcall_t)(void);
 #define fs_initcall(fn)			__define_initcall("9",fn,9)
 #define device_initcall(fn)		__define_initcall("10",fn,10)
 #define crypto_initcall(fn)		__define_initcall("11",fn,11)
-#define late_initcall(fn)		__define_initcall("12",fn,12)
-#define environment_initcall(fn)	__define_initcall("13",fn,13)
-#define postenvironment_initcall(fn)	__define_initcall("14",fn,14)
+#define of_populate_initcall(fn)	__define_initcall("12",fn,15)
+#define late_initcall(fn)		__define_initcall("13",fn,12)
+#define environment_initcall(fn)	__define_initcall("14",fn,13)
+#define postenvironment_initcall(fn)	__define_initcall("15",fn,14)
 
 #define early_exitcall(fn)		__define_exitcall("0",fn,0)
 #define predevshutdown_exitcall(fn)	__define_exitcall("1",fn,1)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 15/18] common: add initial barebox deep-probe support
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (13 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 14/18] initcall: add of_populate_initcall Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 16:53   ` Ahmad Fatoum
  2020-09-28 15:50 ` [PATCH 16/18] ARM: i.MX: esdctl: add " Marco Felsch
                   ` (3 subsequent siblings)
  18 siblings, 1 reply; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

The barebox 'deep probe' or 'probe on demand' mechanism is the answer of
unwanted -EPROBE_DEFER failures. The EPROBE_DEFER error code was
introduced by commit ab3da15bc14c ("base: Introduce deferred probing")
and since then it causes a few problems.

The error is returned if either the device is not yet present or the
driver is not yet registered. This makes sense on linux systems where
modules and hot-plug devices are used very often but not for barebox.
The module support is rarely used and devices aren't hot pluggable.

The current barebox behaviour populates all devices before the drivers
are registered so all devices are present during the driver
registration. So the driver probe() function gets called immediately
after the driver registration and causes the -EPROBE_DEFER error if this
driver depends on an other not yet registered driver.

To get rid of the EPROBE_DEFER error code we need to reorder the device
population and the driver registration. All drivers must be registered
first. In an ideal world all driver can be registered by the same
initcall level. Then devices are getting populated which causes calling
the driver probe() function but this time resources/devices are created
on demand if not yet available.

Dependencies between devices are normally expressed as references to
other device nodes. With deep probe barebox provides helper functions
which take a device node and probe the device behind that node if
necessary. This means instead of returning -EPROBE_DEFER, we can now
make the desired resources available once we need them.

If the resource can't be created we are returning -ENODEV since we are
not supporting hot-plugging. Dropping EPROBE_DEFER is the long-term
goal, avoid initcall shifting is the short-term goal.

Call it deep-probe since the on-demand device creation can greate very
deep stacks. This commit adds the initial support for: spi, i2c, reset,
regulator and clk resource on-demand creation. The deep-probe mechanism
must be enabled for each board to avoid breaking changes using
deep_probe_enable(). This can be changed later after all boards are
converted to the new mechanism.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 common/Makefile          |   1 +
 common/deep-probe.c      |  39 +++++++++++++++
 drivers/base/driver.c    |  11 ++++-
 drivers/clk/clk.c        |   5 ++
 drivers/i2c/i2c.c        |   6 +++
 drivers/of/base.c        |  13 ++++-
 drivers/of/platform.c    | 101 ++++++++++++++++++++++++++++++++++++++-
 drivers/regulator/core.c |   6 +++
 drivers/reset/core.c     |   5 ++
 drivers/spi/spi.c        |   2 +
 include/deep-probe.h     |  17 +++++++
 include/of.h             |  37 +++++++++++++-
 12 files changed, 238 insertions(+), 5 deletions(-)
 create mode 100644 common/deep-probe.c
 create mode 100644 include/deep-probe.h

diff --git a/common/Makefile b/common/Makefile
index c3ae3ca1b9..8525240422 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -3,6 +3,7 @@ obj-y				+= memory_display.o
 pbl-$(CONFIG_PBL_CONSOLE)	+= memory_display.o
 obj-y				+= clock.o
 obj-y				+= console_common.o
+obj-y				+= deep-probe.o
 obj-y				+= startup.o
 obj-y				+= misc.o
 obj-pbl-y			+= memsize.o
diff --git a/common/deep-probe.c b/common/deep-probe.c
new file mode 100644
index 0000000000..05ce4352b1
--- /dev/null
+++ b/common/deep-probe.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <common.h>
+#include <deep-probe.h>
+#include <of.h>
+
+struct deep_probe_entry {
+	struct list_head entry;
+	const char *compatible;
+};
+
+static LIST_HEAD(boards);
+
+int deep_probe_add_board(const char *machine)
+{
+	struct deep_probe_entry *new_machine;
+
+	new_machine = xzalloc(sizeof(*new_machine));
+	if (!new_machine)
+		return -ENOMEM;
+
+	new_machine->compatible = machine;
+	list_add(&new_machine->entry, &boards);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(deep_probe_add_board);
+
+bool deep_probe_is_supported(void)
+{
+	struct deep_probe_entry *machine;
+
+	list_for_each_entry(machine, &boards, entry) {
+		if (of_machine_is_compatible(machine->compatible))
+			return true;
+	}
+	return false;
+}
+EXPORT_SYMBOL_GPL(deep_probe_is_supported);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 412db6c406..b797655c15 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -21,6 +21,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <deep-probe.h>
 #include <driver.h>
 #include <malloc.h>
 #include <console.h>
@@ -95,7 +96,15 @@ int device_probe(struct device_d *dev)
 	if (ret == -EPROBE_DEFER) {
 		list_del(&dev->active);
 		list_add(&dev->active, &deferred);
-		dev_dbg(dev, "probe deferred\n");
+
+		/*
+		 * -EPROBE_DEFER should never appear on a deep-probe machine so
+		 * inform the user immediately.
+		 */
+		if (deep_probe_is_supported())
+			dev_warn(dev, "probe deferred\n");
+		else
+			dev_dbg(dev, "probe deferred\n");
 		return ret;
 	}
 
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index b04d44593b..218317d00d 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -437,9 +437,14 @@ EXPORT_SYMBOL_GPL(of_clk_del_provider);
 
 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
 {
+	struct device_d *dev;
 	struct of_clk_provider *provider;
 	struct clk *clk = ERR_PTR(-EPROBE_DEFER);
 
+	dev = of_device_create_on_demand(clkspec->np);
+	if (IS_ERR(dev))
+		return ERR_CAST(dev);
+
 	/* Check if we have such a provider in our array */
 	list_for_each_entry(provider, &of_clk_providers, link) {
 		if (provider->node == clkspec->np)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 57d8c7017f..dbc0bd4f0b 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -406,6 +406,7 @@ static struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
 		return NULL;
 	}
 	client->dev.info = i2c_info;
+	chip->of_node->dev = &client->dev;
 
 	return client;
 }
@@ -547,8 +548,13 @@ struct i2c_adapter *i2c_get_adapter(int busnum)
 
 struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
 {
+	struct device_d *dev;
 	struct i2c_adapter *adap;
 
+	dev = of_device_create_on_demand(node);
+	if (IS_ERR(dev))
+		return ERR_CAST(dev);
+
 	for_each_i2c_adapter(adap)
 		if (adap->dev.device_node == node)
 			return adap;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 861871b221..cea6d5b1aa 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -15,6 +15,7 @@
  * GNU General Public License for more details.
  */
 #include <common.h>
+#include <deep-probe.h>
 #include <of.h>
 #include <of_address.h>
 #include <errno.h>
@@ -1567,6 +1568,15 @@ int of_set_root_node(struct device_node *node)
 	return 0;
 }
 
+static int barebox_of_populate(void)
+{
+	if (IS_ENABLED(CONFIG_OFDEVICE) && deep_probe_is_supported())
+		of_probe();
+
+	return 0;
+}
+of_populate_initcall(barebox_of_populate);
+
 void barebox_register_of(struct device_node *root)
 {
 	if (root_node)
@@ -1577,7 +1587,8 @@ void barebox_register_of(struct device_node *root)
 
 	if (IS_ENABLED(CONFIG_OFDEVICE)) {
 		of_clk_init(root, NULL);
-		of_probe();
+		if (!deep_probe_is_supported())
+			of_probe();
 	}
 }
 
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 21c7cce1a5..c837adf8e8 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -15,6 +15,7 @@
  * GNU General Public License for more details.
  */
 #include <common.h>
+#include <deep-probe.h>
 #include <malloc.h>
 #include <of.h>
 #include <of_address.h>
@@ -29,6 +30,11 @@
 struct device_d *of_find_device_by_node(struct device_node *np)
 {
 	struct device_d *dev;
+
+	dev = of_device_create_on_demand(np);
+	if (IS_ERR(dev))
+		return NULL;
+
 	for_each_device(dev)
 		if (dev->device_node == np)
 			return dev;
@@ -106,6 +112,9 @@ struct device_d *of_platform_device_create(struct device_node *np,
 	if (!of_device_is_available(np))
 		return NULL;
 
+	if (np->dev)
+		return np->dev;
+
 	/* count the io resources */
 	if (of_can_translate_address(np))
 		while (of_address_to_resource(np, num_reg, &temp_res) == 0)
@@ -170,8 +179,10 @@ struct device_d *of_platform_device_create(struct device_node *np,
 		(num_reg) ? &dev->resource[0].start : &resinval);
 
 	ret = platform_device_register(dev);
-	if (!ret)
+	if (!ret) {
+		np->dev = dev;
 		return dev;
+	}
 
 	free(dev);
 	if (num_reg)
@@ -252,6 +263,9 @@ static struct device_d *of_amba_device_create(struct device_node *np)
 	if (!of_device_is_available(np))
 		return NULL;
 
+	if (np->dev)
+		return np->dev;
+
 	dev = xzalloc(sizeof(*dev));
 
 	/* setup generic device info */
@@ -275,6 +289,8 @@ static struct device_d *of_amba_device_create(struct device_node *np)
 	if (ret)
 		goto amba_err_free;
 
+	np->dev = &dev->dev;
+
 	return &dev->dev;
 
 amba_err_free:
@@ -364,3 +380,86 @@ int of_platform_populate(struct device_node *root,
 	return rc;
 }
 EXPORT_SYMBOL_GPL(of_platform_populate);
+
+struct device_d *of_device_create_on_demand(struct device_node *np)
+{
+	struct device_node *parent;
+	struct device_d *parent_dev, *dev;
+
+	if (!deep_probe_is_supported())
+		return NULL;
+
+	parent = of_get_parent(np);
+	if (!parent)
+		return NULL;
+
+	/* Create all parent devices needed for the requested device */
+	parent_dev = parent->dev ? : of_device_create_on_demand(parent);
+	if (IS_ERR(parent_dev))
+		return parent_dev;
+
+	/*
+	 * Parent devices like i2c/spi controllers are populating their own
+	 * devices. So it can be that the requested device already exist after
+	 * the parent device creation.
+	 */
+	if (np->dev)
+		return np->dev;
+
+	pr_debug("%s: Create %s (%s) on demand\n", __func__,
+		 np->name, np->full_name);
+
+	if (of_device_is_compatible(np, "arm,primecell"))
+		dev = of_amba_device_create(np);
+	else
+		dev = of_platform_device_create(np, parent_dev);
+
+	return dev ? : ERR_PTR(-ENODEV);
+}
+EXPORT_SYMBOL_GPL(of_device_create_on_demand);
+
+struct device_d *of_device_create_on_demand_by_alias(const char *alias)
+{
+	struct device_node *dev_node;
+
+	dev_node = of_find_node_by_alias(NULL, alias);
+	return of_device_create_on_demand(dev_node);
+}
+EXPORT_SYMBOL_GPL(of_device_create_on_demand_by_alias);
+
+struct device_d *
+of_device_create_on_demand_by_dev_id(struct device_node *np,
+				     const struct of_device_id *ids)
+{
+	struct device_node *child;
+
+	if (of_match_node(ids, np))
+		return of_device_create_on_demand(np);
+
+	for_each_child_of_node(np, child) {
+		struct device_d *dev;
+
+		dev = of_device_create_on_demand_by_dev_id(child, ids);
+		if (!IS_ERR(dev))
+			return dev;
+	}
+
+	return ERR_PTR(-ENODEV);
+}
+EXPORT_SYMBOL_GPL(of_device_create_on_demand_by_dev_id);
+
+int of_devices_create_on_demand_by_property(const char *property_name)
+{
+	struct device_node *node;
+
+	for_each_node_with_property(node, property_name) {
+		struct device_d *dev;
+
+		dev = of_device_create_on_demand(node);
+		if (IS_ERR(dev))
+			return PTR_ERR(dev);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_devices_create_on_demand_by_property);
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 6ea21a4609..25973acaf0 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -175,6 +175,7 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
 		return PTR_ERR(ri);
 
 	ri->node = node;
+	node->dev = rd->dev;
 
 	of_property_read_u32(node, "regulator-enable-ramp-delay",
 			&ri->enable_time_us);
@@ -188,6 +189,7 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
 
 static struct regulator_internal *of_regulator_get(struct device_d *dev, const char *supply)
 {
+	struct device_d *dev_ondemand;
 	char *propname;
 	struct regulator_internal *ri;
 	struct device_node *node;
@@ -222,6 +224,10 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c
 		goto out;
 	}
 
+	dev_ondemand = of_device_create_on_demand(node);
+	if (IS_ERR(dev_ondemand))
+		return ERR_CAST(dev_ondemand);
+
 	list_for_each_entry(ri, &regulator_list, list) {
 		if (ri->node == node) {
 			dev_dbg(dev, "Using %s regulator from %s\n",
diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 99b9c80655..874de11b0c 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -153,6 +153,7 @@ static struct reset_control *of_reset_control_get(struct device_node *node,
 	struct reset_control *rstc = ERR_PTR(-ENODEV);
 	struct reset_controller_dev *r, *rcdev;
 	struct of_phandle_args args;
+	struct device_d *dev;
 	int index = 0;
 	int rstc_id;
 	int ret;
@@ -168,6 +169,10 @@ static struct reset_control *of_reset_control_get(struct device_node *node,
 	if (ret)
 		return ERR_PTR(ret);
 
+	dev = of_device_create_on_demand(args.np);
+	if (IS_ERR(dev))
+		return ERR_CAST(dev);
+
 	rcdev = NULL;
 	list_for_each_entry(r, &reset_controller_list, list) {
 		if (args.np == r->of_node) {
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 8421d9d7c1..d1d3bdcc41 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -107,6 +107,8 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl,
 	if (status)
 		goto fail;
 
+	chip->device_node->dev = &proxy->dev;
+
 	return proxy;
 fail:
 	free(proxy);
diff --git a/include/deep-probe.h b/include/deep-probe.h
new file mode 100644
index 0000000000..f9a1f61fde
--- /dev/null
+++ b/include/deep-probe.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __DEEP_PROBE_H
+#define __DEEP_PROBE_H
+
+#include <linux/types.h>
+
+int deep_probe_add_board(const char *machine);
+bool deep_probe_is_supported(void);
+
+#define deep_probe_enable(func,board)				\
+	static int __init func##_deep_probe_register(void)	\
+	{							\
+		return deep_probe_add_board(board);		\
+	}							\
+	pure_initcall(func##_deep_probe_register)
+
+#endif /* __DEEP_PROBE_H */
diff --git a/include/of.h b/include/of.h
index 1b3ceaff40..0f8d6f7546 100644
--- a/include/of.h
+++ b/include/of.h
@@ -35,6 +35,7 @@ struct device_node {
 	struct list_head parent_list;
 	struct list_head list;
 	phandle phandle;
+	struct device_d *dev;
 };
 
 struct of_device_id {
@@ -266,6 +267,13 @@ extern struct device_d *of_device_enable_and_register_by_name(const char *name);
 extern struct device_d *of_device_enable_and_register_by_alias(
 							const char *alias);
 
+extern struct device_d *of_device_create_on_demand(struct device_node *np);
+extern struct device_d *of_device_create_on_demand_by_alias(const char *alias);
+extern struct device_d *
+of_device_create_on_demand_by_dev_id(struct device_node *np,
+				     const struct of_device_id *ids);
+extern int of_devices_create_on_demand_by_property(const char *property_name);
+
 struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node);
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_partitions_register_fixup(struct cdev *cdev);
@@ -331,12 +339,37 @@ static inline int of_set_root_node(struct device_node *node)
 	return -ENOSYS;
 }
 
-static inline struct device_d *of_platform_device_create(struct device_node *np,
-							 struct device_d *parent)
+static inline struct device_d *
+of_platform_device_create(struct device_node *np, struct device_d *parent)
+{
+	return NULL;
+}
+
+static inline struct device_d *
+of_device_create_on_demand(struct device_node *np);
+{
+	return NULL;
+}
+
+static inline struct device_d *
+of_device_create_on_demand_by_alias(struct device_node *np);
 {
 	return NULL;
 }
 
+static inline struct device_d *
+of_device_create_on_demand_by_dev_id(struct device_node *np,
+				     const struct of_device_id *ids)
+{
+	return NULL;
+}
+
+static inline int
+of_devices_create_on_demand_by_property(const char *property_name)
+{
+	return 0;
+}
+
 static inline int of_bus_n_addr_cells(struct device_node *np)
 {
 	return 0;
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 16/18] ARM: i.MX: esdctl: add deep-probe support
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (14 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 15/18] common: add initial barebox deep-probe support Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 17/18] ARM: stm32mp: ddrctrl: " Marco Felsch
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

In case of deep-probe we have to ensure that the memory device is
available after the mem_initcall().

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 arch/arm/mach-imx/esdctl.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/esdctl.c b/arch/arm/mach-imx/esdctl.c
index cc5d3a8359..3819c1a9a6 100644
--- a/arch/arm/mach-imx/esdctl.c
+++ b/arch/arm/mach-imx/esdctl.c
@@ -14,6 +14,7 @@
  */
 
 #include <common.h>
+#include <deep-probe.h>
 #include <io.h>
 #include <errno.h>
 #include <linux/sizes.h>
@@ -705,9 +706,20 @@ static struct driver_d imx_esdctl_driver = {
 
 static int imx_esdctl_init(void)
 {
-	return platform_driver_register(&imx_esdctl_driver);
-}
+	struct device_d *dev;
+	int ret;
+
+	ret = platform_driver_register(&imx_esdctl_driver);
+	if (ret)
+		return ret;
+
+	dev = of_device_create_on_demand_by_dev_id(of_get_root_node(),
+						   imx_esdctl_dt_ids);
+	if (IS_ERR(dev))
+		return PTR_ERR(dev);
 
+	return 0;
+}
 mem_initcall(imx_esdctl_init);
 
 /*
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 17/18] ARM: stm32mp: ddrctrl: add deep-probe support
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (15 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 16/18] ARM: i.MX: esdctl: add " Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 15:50 ` [PATCH 18/18] ARM: boards: mx6-sabrelite: " Marco Felsch
  2020-09-29  8:30 ` [PATCH 00/18] Barebox Deep-Probe Sascha Hauer
  18 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

In case of deep-probe we have to ensure that the memory device is
available after the mem_initcall().

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 arch/arm/mach-stm32mp/ddrctrl.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-stm32mp/ddrctrl.c b/arch/arm/mach-stm32mp/ddrctrl.c
index 962d4c0d52..c108bbee1e 100644
--- a/arch/arm/mach-stm32mp/ddrctrl.c
+++ b/arch/arm/mach-stm32mp/ddrctrl.c
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <deep-probe.h>
 #include <init.h>
 #include <mach/stm32.h>
 #include <mach/ddr_regs.h>
@@ -150,6 +151,18 @@ static struct driver_d stm32mp1_ddr_driver = {
 
 static int stm32mp1_ddr_init(void)
 {
-	return platform_driver_register(&stm32mp1_ddr_driver);
+	struct device_d *dev;
+	int ret;
+
+	ret = platform_driver_register(&stm32mp1_ddr_driver);
+	if (ret)
+		return ret;
+
+	dev = of_device_create_on_demand_by_dev_id(of_get_root_node(),
+						   stm32mp1_ddr_dt_ids);
+	if (IS_ERR(dev))
+		return PTR_ERR(dev);
+
+	return 0;
 }
 mem_initcall(stm32mp1_ddr_init);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 18/18] ARM: boards: mx6-sabrelite: add deep-probe support
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (16 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 17/18] ARM: stm32mp: ddrctrl: " Marco Felsch
@ 2020-09-28 15:50 ` Marco Felsch
  2020-09-28 16:58   ` Ahmad Fatoum
  2020-09-29  8:30 ` [PATCH 00/18] Barebox Deep-Probe Sascha Hauer
  18 siblings, 1 reply; 29+ messages in thread
From: Marco Felsch @ 2020-09-28 15:50 UTC (permalink / raw)
  To: barebox

Explicit request the required gpio resources instead of relying on their
existence based on the initcall level.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
 .../boards/freescale-mx6-sabrelite/board.c    | 24 ++++++++++++-------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/arch/arm/boards/freescale-mx6-sabrelite/board.c b/arch/arm/boards/freescale-mx6-sabrelite/board.c
index 1b39ef82c6..7fc3d4dc3f 100644
--- a/arch/arm/boards/freescale-mx6-sabrelite/board.c
+++ b/arch/arm/boards/freescale-mx6-sabrelite/board.c
@@ -13,7 +13,9 @@
 #include <mach/bbu.h>
 #include <asm/armlinux.h>
 #include <generated/mach-types.h>
+#include <of.h>
 #include <partition.h>
+#include <deep-probe.h>
 #include <linux/phy.h>
 #include <asm/io.h>
 #include <asm/mmu.h>
@@ -98,10 +100,6 @@ static int sabrelite_ksz9021rn_setup(void)
 {
 	int ret;
 
-	if (!of_machine_is_compatible("fsl,imx6q-sabrelite") &&
-	    !of_machine_is_compatible("fsl,imx6dl-sabrelite"))
-		return 0;
-
 	mxc_iomux_v3_setup_multiple_pads(sabrelite_enet_gpio_pads,
 			ARRAY_SIZE(sabrelite_enet_gpio_pads));
 
@@ -118,11 +116,6 @@ static int sabrelite_ksz9021rn_setup(void)
 
 	return 0;
 }
-/*
- * Do this before the fec initializes but after our
- * gpios are available.
- */
-fs_initcall(sabrelite_ksz9021rn_setup);
 
 static void sabrelite_ehci_init(void)
 {
@@ -134,10 +127,20 @@ static void sabrelite_ehci_init(void)
 
 static int sabrelite_devices_init(void)
 {
+	int ret;
+
 	if (!of_machine_is_compatible("fsl,imx6q-sabrelite") &&
 	    !of_machine_is_compatible("fsl,imx6dl-sabrelite"))
 		return 0;
 
+	ret = of_devices_create_on_demand_by_property("gpio-controller");
+	if (ret)
+		return ret;
+
+	ret = sabrelite_ksz9021rn_setup();
+	if (ret)
+		return ret;
+
 	sabrelite_ehci_init();
 
 	armlinux_set_architecture(3769);
@@ -163,3 +166,6 @@ static int sabrelite_coredevices_init(void)
 	return 0;
 }
 coredevice_initcall(sabrelite_coredevices_init);
+
+deep_probe_enable(imx6q_sabrelite, "fsl,imx6q-sabrelite");
+deep_probe_enable(imx6dl_sabrelite, "fsl,imx6dl-sabrelite");
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 01/18] video: ssd1307fb: fix VBAT supply id
  2020-09-28 15:50 ` [PATCH 01/18] video: ssd1307fb: fix VBAT supply id Marco Felsch
@ 2020-09-28 15:58   ` Ahmad Fatoum
  0 siblings, 0 replies; 29+ messages in thread
From: Ahmad Fatoum @ 2020-09-28 15:58 UTC (permalink / raw)
  To: Marco Felsch, barebox, Bastian Krause



On 9/28/20 5:50 PM, Marco Felsch wrote:
> The regulator id should be given without the "-supply" suffix else the
> core is searching for "vbat-supply-supply".
> 
> Fixes: bf8f62d334 ("video/ssd1307fb: add support for VBAT")
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  drivers/video/ssd1307fb.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/video/ssd1307fb.c b/drivers/video/ssd1307fb.c
> index 0709399358..994f43dc5c 100644
> --- a/drivers/video/ssd1307fb.c
> +++ b/drivers/video/ssd1307fb.c
> @@ -421,7 +421,7 @@ static int ssd1307fb_probe(struct device_d *dev)
>  		goto fb_alloc_error;
>  	}
>  
> -	par->vbat = regulator_get(&client->dev, "vbat-supply");
> +	par->vbat = regulator_get(&client->dev, "vbat");
>  	if (IS_ERR(par->vbat)) {
>  		dev_info(&client->dev, "Will not use VBAT");
>  		par->vbat = NULL;
> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 02/18] ARM: boards: mx6-sabrelite: [cosmetic] make use of IMX_GPIO_NR
  2020-09-28 15:50 ` [PATCH 02/18] ARM: boards: mx6-sabrelite: [cosmetic] make use of IMX_GPIO_NR Marco Felsch
@ 2020-09-28 16:00   ` Ahmad Fatoum
  0 siblings, 0 replies; 29+ messages in thread
From: Ahmad Fatoum @ 2020-09-28 16:00 UTC (permalink / raw)
  To: Marco Felsch, barebox

On 9/28/20 5:50 PM, Marco Felsch wrote:
> Convert the global number to the more readable IMX_GPIO_NR() macro, no
> functional changes.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  .../boards/freescale-mx6-sabrelite/board.c    | 20 +++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/arm/boards/freescale-mx6-sabrelite/board.c b/arch/arm/boards/freescale-mx6-sabrelite/board.c
> index f4f2994a51..020a44297a 100644
> --- a/arch/arm/boards/freescale-mx6-sabrelite/board.c
> +++ b/arch/arm/boards/freescale-mx6-sabrelite/board.c
> @@ -70,37 +70,37 @@ static int ksz9021rn_phy_fixup(struct phy_device *dev)
>  
>  static struct gpio fec_gpios[] = {
>  	{
> -		.gpio = 87,
> +		.gpio = IMX_GPIO_NR(3, 23),
>  		.flags = GPIOF_OUT_INIT_LOW,
>  		.label = "phy-rst",
>  	}, {
> -		.gpio = 190,
> +		.gpio = IMX_GPIO_NR(6, 30),
>  		.flags = GPIOF_OUT_INIT_HIGH,
>  		.label = "phy-addr2",
>  	}, {
> -		.gpio = 23,
> +		.gpio = IMX_GPIO_NR(1, 23),
>  		.flags = GPIOF_OUT_INIT_LOW,
>  		.label = "phy-led-mode",
>  	}, {
>  		/* MODE strap-in pins: advertise all capabilities */
> -		.gpio = 185,
> +		.gpio = IMX_GPIO_NR(6, 25),
>  		.flags = GPIOF_OUT_INIT_HIGH,
>  		.label = "phy-adv1",
>  	}, {
> -		.gpio = 187,
> +		.gpio = IMX_GPIO_NR(6, 27),
>  		.flags = GPIOF_OUT_INIT_HIGH,
>  		.label = "phy-adv1",
>  	}, {
> -		.gpio = 188,
> +		.gpio = IMX_GPIO_NR(6, 28),
>  		.flags = GPIOF_OUT_INIT_HIGH,
>  		.label = "phy-adv1",
>  	}, {
> -		.gpio = 189,
> +		.gpio = IMX_GPIO_NR(6, 29),
>  		.flags = GPIOF_OUT_INIT_HIGH,
>  		.label = "phy-adv1",
>  	}, {
>  		/* Enable 125 MHz clock output */
> -		.gpio = 184,
> +		.gpio = IMX_GPIO_NR(6, 24),
>  		.flags = GPIOF_OUT_INIT_HIGH,
>  		.label = "phy-125MHz",
>  	},
> @@ -139,9 +139,9 @@ fs_initcall(sabrelite_ksz9021rn_setup);
>  static void sabrelite_ehci_init(void)
>  {
>  	/* hub reset */
> -	gpio_direction_output(204, 0);
> +	gpio_direction_output(IMX_GPIO_NR(7, 12), 0);
>  	udelay(2000);
> -	gpio_set_value(204, 1);
> +	gpio_set_value(IMX_GPIO_NR(7, 12), 1);
>  }
>  
>  static int sabrelite_devices_init(void)
> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 03/18] drivers: gpio: treewide: [cosmetic] use register_driver_macros
  2020-09-28 15:50 ` [PATCH 03/18] drivers: gpio: treewide: [cosmetic] use register_driver_macros Marco Felsch
@ 2020-09-28 16:04   ` Ahmad Fatoum
  2020-09-29  8:20   ` Sascha Hauer
  1 sibling, 0 replies; 29+ messages in thread
From: Ahmad Fatoum @ 2020-09-28 16:04 UTC (permalink / raw)
  To: Marco Felsch, barebox



On 9/28/20 5:50 PM, Marco Felsch wrote:
> Use the existing macros to register the drivers. No functional changes
> except for the gpio-mxs and gpio-imx driver. Now they do not ignore the
> return values anymore.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  drivers/gpio/gpio-ath79.c          | 7 +------
>  drivers/gpio/gpio-davinci.c        | 7 +------
>  drivers/gpio/gpio-digic.c          | 7 +------
>  drivers/gpio/gpio-dw.c             | 7 +------
>  drivers/gpio/gpio-generic.c        | 7 +------
>  drivers/gpio/gpio-imx.c            | 8 +-------
>  drivers/gpio/gpio-jz4740.c         | 7 +------
>  drivers/gpio/gpio-malta-fpga-i2c.c | 7 +------
>  drivers/gpio/gpio-mpc8xxx.c        | 7 +------
>  drivers/gpio/gpio-mxs.c            | 8 +-------
>  drivers/gpio/gpio-omap.c           | 7 +------
>  drivers/gpio/gpio-stmpe.c          | 7 +------
>  drivers/gpio/gpio-tegra.c          | 7 +------
>  drivers/gpio/gpio-vf610.c          | 7 +------
>  14 files changed, 14 insertions(+), 86 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c
> index d08d743b54..a33d7d290e 100644
> --- a/drivers/gpio/gpio-ath79.c
> +++ b/drivers/gpio/gpio-ath79.c
> @@ -150,9 +150,4 @@ static struct driver_d ath79_gpio_driver = {
>  	.probe = ath79_gpio_probe,
>  	.of_compatible = DRV_OF_COMPAT(ath79_gpio_of_match),
>  };
> -
> -static int ath79_gpio_init(void)
> -{
> -	return platform_driver_register(&ath79_gpio_driver);
> -}
> -coredevice_initcall(ath79_gpio_init);
> +coredevice_platform_driver(ath79_gpio_driver);
> diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
> index 7c060a09b1..bffe385860 100644
> --- a/drivers/gpio/gpio-davinci.c
> +++ b/drivers/gpio/gpio-davinci.c
> @@ -205,9 +205,4 @@ static struct driver_d davinci_gpio_driver = {
>  	.probe		= davinci_gpio_probe,
>  	.of_compatible	= DRV_OF_COMPAT(davinci_gpio_ids),
>  };
> -
> -static int davinci_gpio_drv_reg(void)
> -{
> -	return platform_driver_register(&davinci_gpio_driver);
> -}
> -coredevice_initcall(davinci_gpio_drv_reg);
> +coredevice_platform_driver(davinci_gpio_driver);
> diff --git a/drivers/gpio/gpio-digic.c b/drivers/gpio/gpio-digic.c
> index f7a68d09fc..4cf45397ce 100644
> --- a/drivers/gpio/gpio-digic.c
> +++ b/drivers/gpio/gpio-digic.c
> @@ -175,9 +175,4 @@ static struct driver_d digic_gpio_driver = {
>  	.probe = digic_gpio_probe,
>  	.of_compatible = DRV_OF_COMPAT(digic_gpio_dt_ids),
>  };
> -
> -static int digic_gpio_init(void)
> -{
> -	return platform_driver_register(&digic_gpio_driver);
> -}
> -coredevice_initcall(digic_gpio_init);
> +coredevice_platform_driver(digic_gpio_driver);
> diff --git a/drivers/gpio/gpio-dw.c b/drivers/gpio/gpio-dw.c
> index b81e6a75c5..dd7efd2942 100644
> --- a/drivers/gpio/gpio-dw.c
> +++ b/drivers/gpio/gpio-dw.c
> @@ -194,9 +194,4 @@ static struct driver_d dwgpio_driver = {
>  	.probe = dw_gpio_probe,
>  	.of_compatible = DRV_OF_COMPAT(dwgpio_match),
>  };
> -
> -static int __init dwgpio_init(void)
> -{
> -	return platform_driver_register(&dwgpio_driver);
> -}
> -postcore_initcall(dwgpio_init);
> +postcore_platform_driver(dwgpio_driver);
> diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
> index 2e0dad9974..ad4e6859cb 100644
> --- a/drivers/gpio/gpio-generic.c
> +++ b/drivers/gpio/gpio-generic.c
> @@ -423,12 +423,7 @@ static struct driver_d bgpio_driver = {
>  	.probe		= bgpio_dev_probe,
>  	.remove		= bgpio_dev_remove,
>  };
> -
> -static int bgpio_register(void)
> -{
> -	return platform_driver_register(&bgpio_driver);
> -}
> -coredevice_initcall(bgpio_register);
> +coredevice_platform_driver(bgpio_driver);
>  
>  #endif
>  
> diff --git a/drivers/gpio/gpio-imx.c b/drivers/gpio/gpio-imx.c
> index 2827e11e73..6f913377f0 100644
> --- a/drivers/gpio/gpio-imx.c
> +++ b/drivers/gpio/gpio-imx.c
> @@ -216,10 +216,4 @@ static struct driver_d imx_gpio_driver = {
>  	.of_compatible = DRV_OF_COMPAT(imx_gpio_dt_ids),
>  	.id_table = imx_gpio_ids,
>  };
> -
> -static int imx_gpio_add(void)
> -{
> -	platform_driver_register(&imx_gpio_driver);
> -	return 0;
> -}
> -postcore_initcall(imx_gpio_add);
> +postcore_platform_driver(imx_gpio_driver);
> diff --git a/drivers/gpio/gpio-jz4740.c b/drivers/gpio/gpio-jz4740.c
> index 87e0716b06..bd126c83c1 100644
> --- a/drivers/gpio/gpio-jz4740.c
> +++ b/drivers/gpio/gpio-jz4740.c
> @@ -135,9 +135,4 @@ static struct driver_d jz4740_gpio_driver = {
>  	.probe = jz4740_gpio_probe,
>  	.of_compatible	= DRV_OF_COMPAT(jz4740_gpio_dt_ids),
>  };
> -
> -static int jz4740_gpio_init(void)
> -{
> -	return platform_driver_register(&jz4740_gpio_driver);
> -}
> -coredevice_initcall(jz4740_gpio_init);
> +coredevice_platform_driver(jz4740_gpio_driver);
> diff --git a/drivers/gpio/gpio-malta-fpga-i2c.c b/drivers/gpio/gpio-malta-fpga-i2c.c
> index 9142248571..7afa40460f 100644
> --- a/drivers/gpio/gpio-malta-fpga-i2c.c
> +++ b/drivers/gpio/gpio-malta-fpga-i2c.c
> @@ -179,9 +179,4 @@ static struct driver_d malta_i2c_gpio_driver = {
>  	.probe = malta_i2c_gpio_probe,
>  	.of_compatible	= DRV_OF_COMPAT(malta_i2c_gpio_dt_ids),
>  };
> -
> -static int malta_i2c_gpio_driver_init(void)
> -{
> -	return platform_driver_register(&malta_i2c_gpio_driver);
> -}
> -coredevice_initcall(malta_i2c_gpio_driver_init);
> +coredevice_platform_driver(malta_i2c_gpio_driver);
> diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
> index 979f92ad30..a5a383bfd6 100644
> --- a/drivers/gpio/gpio-mpc8xxx.c
> +++ b/drivers/gpio/gpio-mpc8xxx.c
> @@ -114,9 +114,4 @@ static struct driver_d mpc8xxx_driver = {
>  	.probe		= mpc8xxx_probe,
>  	.of_compatible  = DRV_OF_COMPAT(mpc8xxx_gpio_ids),
>  };
> -
> -static int __init mpc8xxx_init(void)
> -{
> -	return platform_driver_register(&mpc8xxx_driver);
> -}
> -postcore_initcall(mpc8xxx_init);
> +postcore_platform_driver(mpc8xxx_driver);
> diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
> index ef78873ad2..43a1379077 100644
> --- a/drivers/gpio/gpio-mxs.c
> +++ b/drivers/gpio/gpio-mxs.c
> @@ -177,10 +177,4 @@ static struct driver_d mxs_gpio_driver = {
>  	.of_compatible = DRV_OF_COMPAT(mxs_gpio_dt_ids),
>  	.id_table = mxs_gpio_ids,
>  };
> -
> -static int mxs_gpio_add(void)
> -{
> -	platform_driver_register(&mxs_gpio_driver);
> -	return 0;
> -}
> -postcore_initcall(mxs_gpio_add);
> +postcore_platform_driver(mxs_gpio_driver);
> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
> index b00766a6aa..9075f68926 100644
> --- a/drivers/gpio/gpio-omap.c
> +++ b/drivers/gpio/gpio-omap.c
> @@ -191,9 +191,4 @@ static struct driver_d omap_gpio_driver = {
>  	.probe = omap_gpio_probe,
>  	.of_compatible = DRV_OF_COMPAT(omap_gpio_dt_ids),
>  };
> -
> -static int omap_gpio_add(void)
> -{
> -	return platform_driver_register(&omap_gpio_driver);
> -}
> -coredevice_initcall(omap_gpio_add);
> +coredevice_platform_driver(omap_gpio_driver);
> diff --git a/drivers/gpio/gpio-stmpe.c b/drivers/gpio/gpio-stmpe.c
> index d7e64045b4..d0319a6dc8 100644
> --- a/drivers/gpio/gpio-stmpe.c
> +++ b/drivers/gpio/gpio-stmpe.c
> @@ -153,9 +153,4 @@ static struct driver_d stmpe_gpio_driver = {
>  	.name = "stmpe-gpio",
>  	.probe = stmpe_gpio_probe,
>  };
> -
> -static int stmpe_gpio_add(void)
> -{
> -	return platform_driver_register(&stmpe_gpio_driver);
> -}
> -coredevice_initcall(stmpe_gpio_add);
> +coredevice_platform_driver(stmpe_gpio_driver);
> diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
> index 56808b57e4..331402607c 100644
> --- a/drivers/gpio/gpio-tegra.c
> +++ b/drivers/gpio/gpio-tegra.c
> @@ -200,9 +200,4 @@ static struct driver_d tegra_gpio_driver = {
>  	.of_compatible	= DRV_OF_COMPAT(tegra_gpio_dt_ids),
>  	.probe		= tegra_gpio_probe,
>  };
> -
> -static int __init tegra_gpio_init(void)
> -{
> -	return platform_driver_register(&tegra_gpio_driver);
> -}
> -coredevice_initcall(tegra_gpio_init);
> +coredevice_platform_driver(tegra_gpio_driver);
> diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
> index ab35310fbe..55df0a591c 100644
> --- a/drivers/gpio/gpio-vf610.c
> +++ b/drivers/gpio/gpio-vf610.c
> @@ -155,9 +155,4 @@ static struct driver_d vf610_gpio_driver = {
>  	.probe  = vf610_gpio_probe,
>  	.of_compatible = DRV_OF_COMPAT(vf610_gpio_dt_ids),
>  };
> -
> -static int __init gpio_vf610_init(void)
> -{
> -	return platform_driver_register(&vf610_gpio_driver);
> -}
> -postcore_initcall(gpio_vf610_init);
> +postcore_platform_driver(vf610_gpio_driver);
> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 04/18] ARM: mx6-sabrelite: remove obsolete sabrelite_mem_init()
  2020-09-28 15:50 ` [PATCH 04/18] ARM: mx6-sabrelite: remove obsolete sabrelite_mem_init() Marco Felsch
@ 2020-09-28 16:07   ` Ahmad Fatoum
  0 siblings, 0 replies; 29+ messages in thread
From: Ahmad Fatoum @ 2020-09-28 16:07 UTC (permalink / raw)
  To: Marco Felsch, barebox



On 9/28/20 5:50 PM, Marco Felsch wrote:
> The memory init is done by of_probe_memory() first which is part of the
> core_initcall's because the device tree has an valid memory node.
> Otherwise the memory-controller driver (esdctl) would add it by reading
> the information from the controller which are set by the DCD data.
> Therefore we can drop it from the local board file.

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
>  arch/arm/boards/freescale-mx6-sabrelite/board.c | 12 ------------
>  1 file changed, 12 deletions(-)
> 
> diff --git a/arch/arm/boards/freescale-mx6-sabrelite/board.c b/arch/arm/boards/freescale-mx6-sabrelite/board.c
> index 020a44297a..1b39ef82c6 100644
> --- a/arch/arm/boards/freescale-mx6-sabrelite/board.c
> +++ b/arch/arm/boards/freescale-mx6-sabrelite/board.c
> @@ -39,18 +39,6 @@ static iomux_v3_cfg_t sabrelite_enet_gpio_pads[] = {
>  	MX6Q_PAD_RGMII_RX_CTL__GPIO_6_24,
>  };
>  
> -static int sabrelite_mem_init(void)
> -{
> -	if (!of_machine_is_compatible("fsl,imx6q-sabrelite") &&
> -	    !of_machine_is_compatible("fsl,imx6dl-sabrelite"))
> -		return 0;
> -
> -	arm_add_mem_device("ram0", 0x10000000, SZ_1G);
> -
> -	return 0;
> -}
> -mem_initcall(sabrelite_mem_init);
> -
>  static int ksz9021rn_phy_fixup(struct phy_device *dev)
>  {
>  	phy_write(dev, 0x09, 0x0f00);
> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 07/18] regulator: test of_regulator_register input before accessing it
  2020-09-28 15:50 ` [PATCH 07/18] regulator: test of_regulator_register input before accessing it Marco Felsch
@ 2020-09-28 16:11   ` Ahmad Fatoum
  0 siblings, 0 replies; 29+ messages in thread
From: Ahmad Fatoum @ 2020-09-28 16:11 UTC (permalink / raw)
  To: barebox



On 9/28/20 5:50 PM, Marco Felsch wrote:
> Add simple parameter check to avoid possible NULL pointer dereferences.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>

For patches 05,06,07:

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>


> ---
>  drivers/regulator/core.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index a767e383fb..6ea21a4609 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -163,6 +163,9 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
>  	struct regulator_internal *ri;
>  	const char *name;
>  
> +	if (!rd || !node)
> +		return -EINVAL;
> +
>  	rd->boot_on = of_property_read_bool(node, "regulator-boot-on");
>  
>  	name = of_get_property(node, "regulator-name", NULL);
> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 15/18] common: add initial barebox deep-probe support
  2020-09-28 15:50 ` [PATCH 15/18] common: add initial barebox deep-probe support Marco Felsch
@ 2020-09-28 16:53   ` Ahmad Fatoum
  2020-09-29 15:55     ` Marco Felsch
  0 siblings, 1 reply; 29+ messages in thread
From: Ahmad Fatoum @ 2020-09-28 16:53 UTC (permalink / raw)
  To: Marco Felsch, barebox



On 9/28/20 5:50 PM, Marco Felsch wrote:
> The barebox 'deep probe' or 'probe on demand' mechanism is the answer of
> unwanted -EPROBE_DEFER failures. The EPROBE_DEFER error code was
> introduced by commit ab3da15bc14c ("base: Introduce deferred probing")
> and since then it causes a few problems.
> 
> The error is returned if either the device is not yet present or the
> driver is not yet registered. This makes sense on linux systems where
> modules and hot-plug devices are used very often but not for barebox.
> The module support is rarely used and devices aren't hot pluggable.
> 
> The current barebox behaviour populates all devices before the drivers
> are registered so all devices are present during the driver
> registration. So the driver probe() function gets called immediately
> after the driver registration and causes the -EPROBE_DEFER error if this
> driver depends on an other not yet registered driver.
> 
> To get rid of the EPROBE_DEFER error code we need to reorder the device
> population and the driver registration. All drivers must be registered
> first. In an ideal world all driver can be registered by the same
> initcall level. Then devices are getting populated which causes calling
> the driver probe() function but this time resources/devices are created
> on demand if not yet available.
> 
> Dependencies between devices are normally expressed as references to
> other device nodes. With deep probe barebox provides helper functions
> which take a device node and probe the device behind that node if
> necessary. This means instead of returning -EPROBE_DEFER, we can now
> make the desired resources available once we need them.
> 
> If the resource can't be created we are returning -ENODEV since we are
> not supporting hot-plugging. Dropping EPROBE_DEFER is the long-term
> goal, avoid initcall shifting is the short-term goal.
> 
> Call it deep-probe since the on-demand device creation can greate very
> deep stacks. This commit adds the initial support for: spi, i2c, reset,
> regulator and clk resource on-demand creation. The deep-probe mechanism
> must be enabled for each board to avoid breaking changes using
> deep_probe_enable(). This can be changed later after all boards are
> converted to the new mechanism.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
>  common/Makefile          |   1 +
>  common/deep-probe.c      |  39 +++++++++++++++
>  drivers/base/driver.c    |  11 ++++-
>  drivers/clk/clk.c        |   5 ++
>  drivers/i2c/i2c.c        |   6 +++
>  drivers/of/base.c        |  13 ++++-
>  drivers/of/platform.c    | 101 ++++++++++++++++++++++++++++++++++++++-
>  drivers/regulator/core.c |   6 +++
>  drivers/reset/core.c     |   5 ++
>  drivers/spi/spi.c        |   2 +
>  include/deep-probe.h     |  17 +++++++
>  include/of.h             |  37 +++++++++++++-
>  12 files changed, 238 insertions(+), 5 deletions(-)
>  create mode 100644 common/deep-probe.c
>  create mode 100644 include/deep-probe.h
> 
> diff --git a/common/Makefile b/common/Makefile
> index c3ae3ca1b9..8525240422 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -3,6 +3,7 @@ obj-y				+= memory_display.o
>  pbl-$(CONFIG_PBL_CONSOLE)	+= memory_display.o
>  obj-y				+= clock.o
>  obj-y				+= console_common.o
> +obj-y				+= deep-probe.o
>  obj-y				+= startup.o
>  obj-y				+= misc.o
>  obj-pbl-y			+= memsize.o
> diff --git a/common/deep-probe.c b/common/deep-probe.c
> new file mode 100644
> index 0000000000..05ce4352b1
> --- /dev/null
> +++ b/common/deep-probe.c
> @@ -0,0 +1,39 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +#include <common.h>
> +#include <deep-probe.h>

Shouldn't this rather be under drivers/of/ ?
maybe also name it something starting with of_ ?

> +#include <of.h>
> +
> +struct deep_probe_entry {
> +	struct list_head entry;
> +	const char *compatible;
> +};
> +
> +static LIST_HEAD(boards);
> +
> +int deep_probe_add_board(const char *machine)
> +{
> +	struct deep_probe_entry *new_machine;
> +
> +	new_machine = xzalloc(sizeof(*new_machine));
> +	if (!new_machine)
> +		return -ENOMEM;

xzalloc can't fail.

> +
> +	new_machine->compatible = machine;
> +	list_add(&new_machine->entry, &boards);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(deep_probe_add_board);
> +
> +bool deep_probe_is_supported(void)
> +{
> +	struct deep_probe_entry *machine;
> +
> +	list_for_each_entry(machine, &boards, entry) {
> +		if (of_machine_is_compatible(machine->compatible))
> +			return true;
> +	}
> +	return false;
> +}
> +EXPORT_SYMBOL_GPL(deep_probe_is_supported);
> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> index 412db6c406..b797655c15 100644
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -21,6 +21,7 @@
>  
>  #include <common.h>
>  #include <command.h>
> +#include <deep-probe.h>
>  #include <driver.h>
>  #include <malloc.h>
>  #include <console.h>
> @@ -95,7 +96,15 @@ int device_probe(struct device_d *dev)
>  	if (ret == -EPROBE_DEFER) {
>  		list_del(&dev->active);
>  		list_add(&dev->active, &deferred);
> -		dev_dbg(dev, "probe deferred\n");
> +
> +		/*
> +		 * -EPROBE_DEFER should never appear on a deep-probe machine so
> +		 * inform the user immediately.
> +		 */
> +		if (deep_probe_is_supported())
> +			dev_warn(dev, "probe deferred\n");
> +		else
> +			dev_dbg(dev, "probe deferred\n");
>  		return ret;
>  	}
>  
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index b04d44593b..218317d00d 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -437,9 +437,14 @@ EXPORT_SYMBOL_GPL(of_clk_del_provider);
>  
>  struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
>  {
> +	struct device_d *dev;
>  	struct of_clk_provider *provider;
>  	struct clk *clk = ERR_PTR(-EPROBE_DEFER);
>  
> +	dev = of_device_create_on_demand(clkspec->np);
> +	if (IS_ERR(dev))
> +		return ERR_CAST(dev);
> +
>  	/* Check if we have such a provider in our array */
>  	list_for_each_entry(provider, &of_clk_providers, link) {
>  		if (provider->node == clkspec->np)
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index 57d8c7017f..dbc0bd4f0b 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -406,6 +406,7 @@ static struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
>  		return NULL;
>  	}
>  	client->dev.info = i2c_info;
> +	chip->of_node->dev = &client->dev;

Are you sure, you can always assume of_node != NULL here?

>  
>  	return client;
>  }
> @@ -547,8 +548,13 @@ struct i2c_adapter *i2c_get_adapter(int busnum)
>  
>  struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
>  {
> +	struct device_d *dev;
>  	struct i2c_adapter *adap;
>  
> +	dev = of_device_create_on_demand(node);
> +	if (IS_ERR(dev))
> +		return ERR_CAST(dev);
> +
>  	for_each_i2c_adapter(adap)
>  		if (adap->dev.device_node == node)
>  			return adap;
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 861871b221..cea6d5b1aa 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -15,6 +15,7 @@
>   * GNU General Public License for more details.
>   */
>  #include <common.h>
> +#include <deep-probe.h>
>  #include <of.h>
>  #include <of_address.h>
>  #include <errno.h>
> @@ -1567,6 +1568,15 @@ int of_set_root_node(struct device_node *node)
>  	return 0;
>  }
>  
> +static int barebox_of_populate(void)
> +{
> +	if (IS_ENABLED(CONFIG_OFDEVICE) && deep_probe_is_supported())
> +		of_probe();
> +
> +	return 0;
> +}
> +of_populate_initcall(barebox_of_populate);
> +
>  void barebox_register_of(struct device_node *root)
>  {
>  	if (root_node)
> @@ -1577,7 +1587,8 @@ void barebox_register_of(struct device_node *root)
>  
>  	if (IS_ENABLED(CONFIG_OFDEVICE)) {
>  		of_clk_init(root, NULL);
> -		of_probe();
> +		if (!deep_probe_is_supported())
> +			of_probe();
>  	}
>  }
>  
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index 21c7cce1a5..c837adf8e8 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -15,6 +15,7 @@
>   * GNU General Public License for more details.
>   */
>  #include <common.h>
> +#include <deep-probe.h>
>  #include <malloc.h>
>  #include <of.h>
>  #include <of_address.h>
> @@ -29,6 +30,11 @@
>  struct device_d *of_find_device_by_node(struct device_node *np)
>  {
>  	struct device_d *dev;
> +
> +	dev = of_device_create_on_demand(np);
> +	if (IS_ERR(dev))
> +		return NULL;
> +
>  	for_each_device(dev)
>  		if (dev->device_node == np)
>  			return dev;
> @@ -106,6 +112,9 @@ struct device_d *of_platform_device_create(struct device_node *np,
>  	if (!of_device_is_available(np))
>  		return NULL;
>  
> +	if (np->dev)
> +		return np->dev;
> +

Unsure if this is correct. Seek down to the "check if all address resources match" comment.
It's possible that devices are registered multiple times and are coalesced later on.
I can't say for sure though, where we are doing this at the moment.

>  	/* count the io resources */
>  	if (of_can_translate_address(np))
>  		while (of_address_to_resource(np, num_reg, &temp_res) == 0)
> @@ -170,8 +179,10 @@ struct device_d *of_platform_device_create(struct device_node *np,
>  		(num_reg) ? &dev->resource[0].start : &resinval);
>  
>  	ret = platform_device_register(dev);
> -	if (!ret)
> +	if (!ret) {
> +		np->dev = dev;
>  		return dev;
> +	}
>  
>  	free(dev);
>  	if (num_reg)
> @@ -252,6 +263,9 @@ static struct device_d *of_amba_device_create(struct device_node *np)
>  	if (!of_device_is_available(np))
>  		return NULL;
>  
> +	if (np->dev)
> +		return np->dev;
> +
>  	dev = xzalloc(sizeof(*dev));
>  
>  	/* setup generic device info */
> @@ -275,6 +289,8 @@ static struct device_d *of_amba_device_create(struct device_node *np)
>  	if (ret)
>  		goto amba_err_free;
>  
> +	np->dev = &dev->dev;
> +
>  	return &dev->dev;
>  
>  amba_err_free:
> @@ -364,3 +380,86 @@ int of_platform_populate(struct device_node *root,
>  	return rc;
>  }
>  EXPORT_SYMBOL_GPL(of_platform_populate);
> +
> +struct device_d *of_device_create_on_demand(struct device_node *np)
> +{
> +	struct device_node *parent;
> +	struct device_d *parent_dev, *dev;
> +
> +	if (!deep_probe_is_supported())
> +		return NULL;
> +
> +	parent = of_get_parent(np);
> +	if (!parent)
> +		return NULL;
> +
> +	/* Create all parent devices needed for the requested device */
> +	parent_dev = parent->dev ? : of_device_create_on_demand(parent);
> +	if (IS_ERR(parent_dev))
> +		return parent_dev;
> +
> +	/*
> +	 * Parent devices like i2c/spi controllers are populating their own
> +	 * devices. So it can be that the requested device already exist after
> +	 * the parent device creation.
> +	 */
> +	if (np->dev)
> +		return np->dev;
> +
> +	pr_debug("%s: Create %s (%s) on demand\n", __func__,
> +		 np->name, np->full_name);
> +
> +	if (of_device_is_compatible(np, "arm,primecell"))
> +		dev = of_amba_device_create(np);
> +	else
> +		dev = of_platform_device_create(np, parent_dev);
> +
> +	return dev ? : ERR_PTR(-ENODEV);
> +}
> +EXPORT_SYMBOL_GPL(of_device_create_on_demand);
> +
> +struct device_d *of_device_create_on_demand_by_alias(const char *alias)
> +{
> +	struct device_node *dev_node;
> +
> +	dev_node = of_find_node_by_alias(NULL, alias);
> +	return of_device_create_on_demand(dev_node);
> +}
> +EXPORT_SYMBOL_GPL(of_device_create_on_demand_by_alias);
> +
> +struct device_d *
> +of_device_create_on_demand_by_dev_id(struct device_node *np,
> +				     const struct of_device_id *ids)
> +{

I find it surprising that this works recursively, while the previous
by_alias doesn't

> +	struct device_node *child;
> +
> +	if (of_match_node(ids, np))
> +		return of_device_create_on_demand(np);
> +
> +	for_each_child_of_node(np, child) {
> +		struct device_d *dev;
> +
> +		dev = of_device_create_on_demand_by_dev_id(child, ids);
> +		if (!IS_ERR(dev))
> +			return dev;
> +	}
> +
> +	return ERR_PTR(-ENODEV);
> +}
> +EXPORT_SYMBOL_GPL(of_device_create_on_demand_by_dev_id);
> +
> +int of_devices_create_on_demand_by_property(const char *property_name)
> +{
> +	struct device_node *node;
> +
> +	for_each_node_with_property(node, property_name) {
> +		struct device_d *dev;
> +
> +		dev = of_device_create_on_demand(node);
> +		if (IS_ERR(dev))
> +			return PTR_ERR(dev);
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(of_devices_create_on_demand_by_property);
> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index 6ea21a4609..25973acaf0 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -175,6 +175,7 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
>  		return PTR_ERR(ri);
>  
>  	ri->node = node;
> +	node->dev = rd->dev;
>  
>  	of_property_read_u32(node, "regulator-enable-ramp-delay",
>  			&ri->enable_time_us);
> @@ -188,6 +189,7 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
>  
>  static struct regulator_internal *of_regulator_get(struct device_d *dev, const char *supply)
>  {
> +	struct device_d *dev_ondemand;
>  	char *propname;
>  	struct regulator_internal *ri;
>  	struct device_node *node;
> @@ -222,6 +224,10 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c
>  		goto out;
>  	}
>  
> +	dev_ondemand = of_device_create_on_demand(node);
> +	if (IS_ERR(dev_ondemand))
> +		return ERR_CAST(dev_ondemand);
> +
>  	list_for_each_entry(ri, &regulator_list, list) {
>  		if (ri->node == node) {
>  			dev_dbg(dev, "Using %s regulator from %s\n",
> diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> index 99b9c80655..874de11b0c 100644
> --- a/drivers/reset/core.c
> +++ b/drivers/reset/core.c
> @@ -153,6 +153,7 @@ static struct reset_control *of_reset_control_get(struct device_node *node,
>  	struct reset_control *rstc = ERR_PTR(-ENODEV);
>  	struct reset_controller_dev *r, *rcdev;
>  	struct of_phandle_args args;
> +	struct device_d *dev;
>  	int index = 0;
>  	int rstc_id;
>  	int ret;
> @@ -168,6 +169,10 @@ static struct reset_control *of_reset_control_get(struct device_node *node,
>  	if (ret)
>  		return ERR_PTR(ret);
>  
> +	dev = of_device_create_on_demand(args.np);
> +	if (IS_ERR(dev))
> +		return ERR_CAST(dev);
> +
>  	rcdev = NULL;
>  	list_for_each_entry(r, &reset_controller_list, list) {
>  		if (args.np == r->of_node) {
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 8421d9d7c1..d1d3bdcc41 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -107,6 +107,8 @@ struct spi_device *spi_new_device(struct spi_controller *ctrl,
>  	if (status)
>  		goto fail;
>  
> +	chip->device_node->dev = &proxy->dev;
> +
>  	return proxy;
>  fail:
>  	free(proxy);
> diff --git a/include/deep-probe.h b/include/deep-probe.h
> new file mode 100644
> index 0000000000..f9a1f61fde
> --- /dev/null
> +++ b/include/deep-probe.h
> @@ -0,0 +1,17 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef __DEEP_PROBE_H
> +#define __DEEP_PROBE_H
> +
> +#include <linux/types.h>
> +
> +int deep_probe_add_board(const char *machine);
> +bool deep_probe_is_supported(void);
> +
> +#define deep_probe_enable(func,board)				\
> +	static int __init func##_deep_probe_register(void)	\
> +	{							\
> +		return deep_probe_add_board(board);		\
> +	}							\
> +	pure_initcall(func##_deep_probe_register)
> +
> +#endif /* __DEEP_PROBE_H */
> diff --git a/include/of.h b/include/of.h
> index 1b3ceaff40..0f8d6f7546 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -35,6 +35,7 @@ struct device_node {
>  	struct list_head parent_list;
>  	struct list_head list;
>  	phandle phandle;
> +	struct device_d *dev;
>  };
>  
>  struct of_device_id {
> @@ -266,6 +267,13 @@ extern struct device_d *of_device_enable_and_register_by_name(const char *name);
>  extern struct device_d *of_device_enable_and_register_by_alias(
>  							const char *alias);
>  
> +extern struct device_d *of_device_create_on_demand(struct device_node *np);
> +extern struct device_d *of_device_create_on_demand_by_alias(const char *alias);
> +extern struct device_d *
> +of_device_create_on_demand_by_dev_id(struct device_node *np,
> +				     const struct of_device_id *ids);
> +extern int of_devices_create_on_demand_by_property(const char *property_name);
> +
>  struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node);
>  int of_parse_partitions(struct cdev *cdev, struct device_node *node);
>  int of_partitions_register_fixup(struct cdev *cdev);
> @@ -331,12 +339,37 @@ static inline int of_set_root_node(struct device_node *node)
>  	return -ENOSYS;
>  }
>  
> -static inline struct device_d *of_platform_device_create(struct device_node *np,
> -							 struct device_d *parent)
> +static inline struct device_d *
> +of_platform_device_create(struct device_node *np, struct device_d *parent)
> +{
> +	return NULL;
> +}
> +
> +static inline struct device_d *
> +of_device_create_on_demand(struct device_node *np);

Extra semicolon. Could you compile test without CONFIG_OFTREE?

> +{
> +	return NULL;
> +}
> +
> +static inline struct device_d *
> +of_device_create_on_demand_by_alias(struct device_node *np);
>  {
>  	return NULL;
>  }
>  
> +static inline struct device_d *
> +of_device_create_on_demand_by_dev_id(struct device_node *np,
> +				     const struct of_device_id *ids)
> +{
> +	return NULL;
> +}
> +
> +static inline int
> +of_devices_create_on_demand_by_property(const char *property_name)
> +{
> +	return 0;
> +}
> +
>  static inline int of_bus_n_addr_cells(struct device_node *np)
>  {
>  	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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 18/18] ARM: boards: mx6-sabrelite: add deep-probe support
  2020-09-28 15:50 ` [PATCH 18/18] ARM: boards: mx6-sabrelite: " Marco Felsch
@ 2020-09-28 16:58   ` Ahmad Fatoum
  0 siblings, 0 replies; 29+ messages in thread
From: Ahmad Fatoum @ 2020-09-28 16:58 UTC (permalink / raw)
  To: Marco Felsch, barebox



On 9/28/20 5:50 PM, Marco Felsch wrote:
> Explicit request the required gpio resources instead of relying on their
> existence based on the initcall level.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
>  .../boards/freescale-mx6-sabrelite/board.c    | 24 ++++++++++++-------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/arm/boards/freescale-mx6-sabrelite/board.c b/arch/arm/boards/freescale-mx6-sabrelite/board.c
> index 1b39ef82c6..7fc3d4dc3f 100644
> --- a/arch/arm/boards/freescale-mx6-sabrelite/board.c
> +++ b/arch/arm/boards/freescale-mx6-sabrelite/board.c
> @@ -13,7 +13,9 @@
>  #include <mach/bbu.h>
>  #include <asm/armlinux.h>
>  #include <generated/mach-types.h>
> +#include <of.h>
>  #include <partition.h>
> +#include <deep-probe.h>
>  #include <linux/phy.h>
>  #include <asm/io.h>
>  #include <asm/mmu.h>
> @@ -98,10 +100,6 @@ static int sabrelite_ksz9021rn_setup(void)
>  {
>  	int ret;
>  
> -	if (!of_machine_is_compatible("fsl,imx6q-sabrelite") &&
> -	    !of_machine_is_compatible("fsl,imx6dl-sabrelite"))
> -		return 0;
> -
>  	mxc_iomux_v3_setup_multiple_pads(sabrelite_enet_gpio_pads,
>  			ARRAY_SIZE(sabrelite_enet_gpio_pads));
>  
> @@ -118,11 +116,6 @@ static int sabrelite_ksz9021rn_setup(void)
>  
>  	return 0;
>  }
> -/*
> - * Do this before the fec initializes but after our
> - * gpios are available.
> - */
> -fs_initcall(sabrelite_ksz9021rn_setup);
>  
>  static void sabrelite_ehci_init(void)
>  {
> @@ -134,10 +127,20 @@ static void sabrelite_ehci_init(void)
>  
>  static int sabrelite_devices_init(void)
>  {
> +	int ret;
> +
>  	if (!of_machine_is_compatible("fsl,imx6q-sabrelite") &&
>  	    !of_machine_is_compatible("fsl,imx6dl-sabrelite"))
>  		return 0;
>  
> +	ret = of_devices_create_on_demand_by_property("gpio-controller");
> +	if (ret)
> +		return ret;
> +
> +	ret = sabrelite_ksz9021rn_setup();
> +	if (ret)
> +		return ret;
> +
>  	sabrelite_ehci_init();
>  
>  	armlinux_set_architecture(3769);
> @@ -163,3 +166,6 @@ static int sabrelite_coredevices_init(void)
>  	return 0;
>  }
>  coredevice_initcall(sabrelite_coredevices_init);
> +
> +deep_probe_enable(imx6q_sabrelite, "fsl,imx6q-sabrelite");
> +deep_probe_enable(imx6dl_sabrelite, "fsl,imx6dl-sabrelite");

You can use __UNIQUE_ID and drop the first argument

> 

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 03/18] drivers: gpio: treewide: [cosmetic] use register_driver_macros
  2020-09-28 15:50 ` [PATCH 03/18] drivers: gpio: treewide: [cosmetic] use register_driver_macros Marco Felsch
  2020-09-28 16:04   ` Ahmad Fatoum
@ 2020-09-29  8:20   ` Sascha Hauer
  1 sibling, 0 replies; 29+ messages in thread
From: Sascha Hauer @ 2020-09-29  8:20 UTC (permalink / raw)
  To: Marco Felsch; +Cc: barebox

On Mon, Sep 28, 2020 at 05:50:26PM +0200, Marco Felsch wrote:
> Use the existing macros to register the drivers. No functional changes
> except for the gpio-mxs and gpio-imx driver. Now they do not ignore the
> return values anymore.
> 
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
>  drivers/gpio/gpio-ath79.c          | 7 +------
>  drivers/gpio/gpio-davinci.c        | 7 +------
>  drivers/gpio/gpio-digic.c          | 7 +------
>  drivers/gpio/gpio-dw.c             | 7 +------
>  drivers/gpio/gpio-generic.c        | 7 +------
>  drivers/gpio/gpio-imx.c            | 8 +-------
>  drivers/gpio/gpio-jz4740.c         | 7 +------
>  drivers/gpio/gpio-malta-fpga-i2c.c | 7 +------
>  drivers/gpio/gpio-mpc8xxx.c        | 7 +------
>  drivers/gpio/gpio-mxs.c            | 8 +-------
>  drivers/gpio/gpio-omap.c           | 7 +------
>  drivers/gpio/gpio-stmpe.c          | 7 +------
>  drivers/gpio/gpio-tegra.c          | 7 +------
>  drivers/gpio/gpio-vf610.c          | 7 +------
>  14 files changed, 14 insertions(+), 86 deletions(-)

I already had a patch which does this change for all drivers. I just
sent it out.

Sascha

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 00/18] Barebox Deep-Probe
  2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
                   ` (17 preceding siblings ...)
  2020-09-28 15:50 ` [PATCH 18/18] ARM: boards: mx6-sabrelite: " Marco Felsch
@ 2020-09-29  8:30 ` Sascha Hauer
  18 siblings, 0 replies; 29+ messages in thread
From: Sascha Hauer @ 2020-09-29  8:30 UTC (permalink / raw)
  To: Marco Felsch; +Cc: barebox

Hi Marco,

On Mon, Sep 28, 2020 at 05:50:23PM +0200, Marco Felsch wrote:
> Hi all,
> 
> this series is our approach to address the EPROBE_DEFER and initcall
> shifting problem. I skip the deep-probe explanation here and instead
> refer to the detailed commit message of patch 15. 
> 
> Patche 1-11:
>  - Fixes and cleanups I found during the development of deep-probe

I applied these to -next, so no need to resend them for the next round.

Sascha

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 15/18] common: add initial barebox deep-probe support
  2020-09-28 16:53   ` Ahmad Fatoum
@ 2020-09-29 15:55     ` Marco Felsch
  0 siblings, 0 replies; 29+ messages in thread
From: Marco Felsch @ 2020-09-29 15:55 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

Hi Ahmad,

thanks for the review.

On 20-09-28 18:53, Ahmad Fatoum wrote:

> > --- /dev/null
> > +++ b/common/deep-probe.c
> > @@ -0,0 +1,39 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +
> > +#include <common.h>
> > +#include <deep-probe.h>
> 
> Shouldn't this rather be under drivers/of/ ?
> maybe also name it something starting with of_ ?

I'm not sure. Currently it works only for OF but it can be adapted to
ACPI too. Therefore I thought it shouldn't be placed into drivers/of and
shouldn't start with of_*.

> > +int deep_probe_add_board(const char *machine)
> > +{
> > +	struct deep_probe_entry *new_machine;
> > +
> > +	new_machine = xzalloc(sizeof(*new_machine));
> > +	if (!new_machine)
> > +		return -ENOMEM;
> 
> xzalloc can't fail.
> 
> > +
> > +	new_machine->compatible = machine;
> > +	list_add(&new_machine->entry, &boards);
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(deep_probe_add_board);

The whole logic was replaced by an static linker array as we do for the
magicvar.

> > --- a/drivers/i2c/i2c.c
> > +++ b/drivers/i2c/i2c.c
> > @@ -406,6 +406,7 @@ static struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
> >  		return NULL;
> >  	}
> >  	client->dev.info = i2c_info;
> > +	chip->of_node->dev = &client->dev;
> 
> Are you sure, you can always assume of_node != NULL here?

Good catch, didn't checked the non-dt callers.. Fixed it in v2.

> >  struct device_d *of_find_device_by_node(struct device_node *np)
> >  {
> >  	struct device_d *dev;
> > +
> > +	dev = of_device_create_on_demand(np);
> > +	if (IS_ERR(dev))
> > +		return NULL;
> > +
> >  	for_each_device(dev)
> >  		if (dev->device_node == np)
> >  			return dev;
> > @@ -106,6 +112,9 @@ struct device_d *of_platform_device_create(struct device_node *np,
> >  	if (!of_device_is_available(np))
> >  		return NULL;
> >  
> > +	if (np->dev)
> > +		return np->dev;
> > +
> 
> Unsure if this is correct. Seek down to the "check if all address resources match" comment.
> It's possible that devices are registered multiple times and are coalesced later on.
> I can't say for sure though, where we are doing this at the moment.

I see.. Let me check this.

> > +struct device_d *
> > +of_device_create_on_demand_by_dev_id(struct device_node *np,
> > +				     const struct of_device_id *ids)
> > +{
> 
> I find it surprising that this works recursively, while the previous
> by_alias doesn't

I converted the name to of_devices_* to reflect that and added a
function documentation. I hope this avoids further confusions.


> > +static inline struct device_d *
> > +of_device_create_on_demand(struct device_node *np);
> 
> Extra semicolon. Could you compile test without CONFIG_OFTREE?

Unfortunately not, thanks for covering that. Fixed it in v2.

Regards,
  Marco

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2020-09-29 15:55 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-28 15:50 [PATCH 00/18] Barebox Deep-Probe Marco Felsch
2020-09-28 15:50 ` [PATCH 01/18] video: ssd1307fb: fix VBAT supply id Marco Felsch
2020-09-28 15:58   ` Ahmad Fatoum
2020-09-28 15:50 ` [PATCH 02/18] ARM: boards: mx6-sabrelite: [cosmetic] make use of IMX_GPIO_NR Marco Felsch
2020-09-28 16:00   ` Ahmad Fatoum
2020-09-28 15:50 ` [PATCH 03/18] drivers: gpio: treewide: [cosmetic] use register_driver_macros Marco Felsch
2020-09-28 16:04   ` Ahmad Fatoum
2020-09-29  8:20   ` Sascha Hauer
2020-09-28 15:50 ` [PATCH 04/18] ARM: mx6-sabrelite: remove obsolete sabrelite_mem_init() Marco Felsch
2020-09-28 16:07   ` Ahmad Fatoum
2020-09-28 15:50 ` [PATCH 05/18] spi: core: don't ignore register_device failures Marco Felsch
2020-09-28 15:50 ` [PATCH 06/18] regulator: improve of_regulator_register error handling Marco Felsch
2020-09-28 15:50 ` [PATCH 07/18] regulator: test of_regulator_register input before accessing it Marco Felsch
2020-09-28 16:11   ` Ahmad Fatoum
2020-09-28 15:50 ` [PATCH 08/18] regulator: stpmic1: fix registering missed regulators Marco Felsch
2020-09-28 15:50 ` [PATCH 09/18] regulator: add device reference to regulator_dev Marco Felsch
2020-09-28 15:50 ` [PATCH 10/18] regulator: treewide: drop local device_d reference Marco Felsch
2020-09-28 15:50 ` [PATCH 11/18] of: platform: fix of_amba_device_create stub return value Marco Felsch
2020-09-28 15:50 ` [PATCH 12/18] of: base: move memory init from DT to initcall Marco Felsch
2020-09-28 15:50 ` [PATCH 13/18] of: base: move clock init from of_probe() to barebox_register_of() Marco Felsch
2020-09-28 15:50 ` [PATCH 14/18] initcall: add of_populate_initcall Marco Felsch
2020-09-28 15:50 ` [PATCH 15/18] common: add initial barebox deep-probe support Marco Felsch
2020-09-28 16:53   ` Ahmad Fatoum
2020-09-29 15:55     ` Marco Felsch
2020-09-28 15:50 ` [PATCH 16/18] ARM: i.MX: esdctl: add " Marco Felsch
2020-09-28 15:50 ` [PATCH 17/18] ARM: stm32mp: ddrctrl: " Marco Felsch
2020-09-28 15:50 ` [PATCH 18/18] ARM: boards: mx6-sabrelite: " Marco Felsch
2020-09-28 16:58   ` Ahmad Fatoum
2020-09-29  8:30 ` [PATCH 00/18] Barebox Deep-Probe Sascha Hauer

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