Skip to contentSkip to conversation

improve OF_PLATDATA support

PATCH Superseded Walter Lozano 2 participants 34 messages Jun 19, 2020 – Jun 23, 2020

Subsystems (20)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover improve OF_PLATDATA support

When using OF_PLATDATA dtbs are converted to C structs in order to save space as we can remove both dtbs and libraries from TPL/SPL binaries.

This patchset tries to improve its support by overcoming some limitations in the current implementation

First, the support for scan and check for valid driver/aliases is added in order to generate U_BOOT_DEVICE entries with valid driver names.

Secondly, the way information about linked noded (phandle) is generated in C structs is improved in order to make it easier to get a device associated to its data.

Lastly the support for the property cd-gpios is added, which is used to configure the card detection gpio on MMC is added.

This implementation is based in discussion in [1], [2] and [3]

[1] https://patchwork.ozlabs.org/patch/1249198/
[2] https://patchwork.ozlabs.org/project/uboot/list/?series=167495&state=*
[3] https://patchwork.ozlabs.org/project/uboot/list/?series=176759&state=*

Walter Lozano (14):
drivers: rename drivers to match compatible string
dtoc: add missing code comments
dtoc: add support to scan drivers
dtoc: add option to disable warnings
dm: doc: update of-plat with the support for driver aliases
core: drop const for struct driver_info
core: extend struct driver_info to point to device
dtoc: extend dtoc to use struct driver_info when linking nodes
dm: doc: update of-plat with new phandle support
dtoc: update tests to match new platdata
sandbox: Move section u_boot_list to make it RW
arm: dts: include gpio nodes for card detect
dtoc: update dtb_platdata to support cd-gpios
dtoc add test for cd-gpios

 arch/arm/dts/da850-evm-u-boot.dtsi            |   4 +
 arch/arm/dts/da850-lcdk-u-boot.dtsi           |   4 +
 arch/arm/dts/rk3288-u-boot.dtsi               |   4 +
 arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi |   2 +-
 arch/arm/dts/rk3288-veyron-u-boot.dtsi        |  11 +
 .../mach-at91/arm926ejs/at91sam9260_devices.c |   6 +-
 .../arm926ejs/at91sam9m10g45_devices.c        |  10 +-
 arch/arm/mach-rockchip/rk3328/syscon_rk3328.c |   4 +-
 arch/sandbox/cpu/u-boot-spl.lds               |   2 +-
 board/davinci/da8xxevm/omapl138_lcdk.c        |   2 +-
 board/sandbox/sandbox.c                       |   2 +-
 doc/driver-model/of-plat.rst                  |  38 ++-
 drivers/clk/at91/clk-master.c                 |   4 +-
 drivers/clk/at91/clk-peripheral.c             |   4 +-
 drivers/clk/at91/pmc.c                        |   6 +-
 drivers/clk/clk-uclass.c                      |  11 +-
 drivers/core/device.c                         |  28 +-
 drivers/core/root.c                           |   6 +-
 drivers/core/simple-bus.c                     |   4 +-
 drivers/gpio/at91_gpio.c                      |   4 +-
 drivers/gpio/da8xx_gpio.c                     |   4 +-
 drivers/gpio/mxs_gpio.c                       |   8 +-
 drivers/gpio/rk_gpio.c                        |   4 +-
 drivers/gpio/sandbox.c                        |   6 +-
 drivers/i2c/rk_i2c.c                          |   6 +-
 drivers/input/cros_ec_keyb.c                  |   4 +-
 drivers/misc/cros_ec_sandbox.c                |   4 +-
 drivers/misc/irq-uclass.c                     |  10 +-
 drivers/mmc/davinci_mmc.c                     |   4 +-
 drivers/mmc/ftsdc010_mci.c                    |   2 +-
 drivers/mmc/mxsmmc.c                          |   7 +-
 drivers/mmc/rockchip_dw_mmc.c                 |   7 +-
 drivers/mmc/rockchip_sdhci.c                  |   2 +-
 drivers/mtd/spi/sf-uclass.c                   |   2 +-
 drivers/mtd/spi/sf_probe.c                    |   6 +-
 drivers/pinctrl/nxp/pinctrl-mxs.c             |   6 +-
 drivers/pinctrl/pinctrl-at91.c                |   6 +-
 drivers/pinctrl/rockchip/pinctrl-rk3188.c     |   2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3288.c     |   2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3328.c     |   2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3368.c     |   2 +-
 drivers/power/pmic/rk8xx.c                    |   6 +-
 drivers/power/regulator/fixed.c               |   4 +-
 drivers/ram/rockchip/dmc-rk3368.c             |   2 +-
 drivers/ram/rockchip/sdram_rk3188.c           |   2 +-
 drivers/ram/rockchip/sdram_rk3288.c           |   2 +-
 drivers/ram/rockchip/sdram_rk3328.c           |   2 +-
 drivers/ram/rockchip/sdram_rk3399.c           |   2 +-
 drivers/serial/ns16550.c                      |   4 +
 drivers/serial/sandbox.c                      |   6 +-
 drivers/spi/mxs_spi.c                         |   8 +-
 drivers/spi/rk_spi.c                          |  10 +-
 drivers/spi/sandbox_spi.c                     |   4 +-
 drivers/tpm/tpm_tis_sandbox.c                 |   4 +-
 drivers/video/rockchip/rk3288_vop.c           |   4 +-
 drivers/video/sandbox_sdl.c                   |   4 +-
 drivers/watchdog/at91sam9_wdt.c               |   4 +-
 include/clk.h                                 |   4 +-
 include/dm/device-internal.h                  |   2 +-
 include/dm/device.h                           |  22 ++
 include/dm/platdata.h                         |  14 +
 test/dm/gpio.c                                |   2 +-
 test/dm/spi.c                                 |   6 +-
 test/py/tests/test_bind.py                    |  54 ++--
 tools/dtoc/dtb_platdata.py                    | 138 ++++++++-
 tools/dtoc/dtoc_test_driver_alias.dts         |  20 ++
 tools/dtoc/dtoc_test_invalid_driver.dts       |  15 +
 tools/dtoc/dtoc_test_phandle_cd_gpios.dts     |  42 +++
 tools/dtoc/test_dtoc.py                       | 286 +++++++++++++-----
 69 files changed, 686 insertions(+), 239 deletions(-)
 create mode 100644 arch/arm/dts/rk3288-veyron-u-boot.dtsi
 create mode 100644 tools/dtoc/dtoc_test_driver_alias.dts
 create mode 100644 tools/dtoc/dtoc_test_invalid_driver.dts
 create mode 100644 tools/dtoc/dtoc_test_phandle_cd_gpios.dts
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/14 drivers: rename drivers to match compatible string

When using OF_PLATDATA, the bind process between devices and drivers is performed trying to match compatible string with driver names. However driver names are not strictly defined, and also there are different names used when declaring a driver with U_BOOT_DRIVER, the name of the symbol used in the linker list and the used in the struct driver_info.

In order to make things a bit more clear, rename the drivers names. This will also help for further OF_PLATDATA improvements, such as checking for valid driver names.

---
 .../mach-at91/arm926ejs/at91sam9260_devices.c |  6 +--
 .../arm926ejs/at91sam9m10g45_devices.c        | 10 ++--
 arch/arm/mach-rockchip/rk3328/syscon_rk3328.c |  4 +-
 board/davinci/da8xxevm/omapl138_lcdk.c        |  2 +-
 board/sandbox/sandbox.c                       |  2 +-
 drivers/clk/at91/clk-master.c                 |  4 +-
 drivers/clk/at91/clk-peripheral.c             |  4 +-
 drivers/clk/at91/pmc.c                        |  4 +-
 drivers/core/simple-bus.c                     |  4 +-
 drivers/gpio/at91_gpio.c                      |  4 +-
 drivers/gpio/da8xx_gpio.c                     |  4 +-
 drivers/gpio/mxs_gpio.c                       |  6 +--
 drivers/gpio/rk_gpio.c                        |  4 +-
 drivers/gpio/sandbox.c                        |  4 +-
 drivers/i2c/rk_i2c.c                          |  4 +-
 drivers/input/cros_ec_keyb.c                  |  4 +-
 drivers/misc/cros_ec_sandbox.c                |  4 +-
 drivers/mmc/davinci_mmc.c                     |  4 +-
 drivers/mmc/mxsmmc.c                          |  6 +--
 drivers/mmc/rockchip_dw_mmc.c                 |  2 +-
 drivers/mtd/spi/sf-uclass.c                   |  2 +-
 drivers/mtd/spi/sf_probe.c                    |  4 +-
 drivers/pinctrl/nxp/pinctrl-mxs.c             |  4 +-
 drivers/pinctrl/pinctrl-at91.c                |  4 +-
 drivers/pinctrl/rockchip/pinctrl-rk3188.c     |  2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3288.c     |  2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3328.c     |  2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3368.c     |  2 +-
 drivers/power/pmic/rk8xx.c                    |  4 +-
 drivers/power/regulator/fixed.c               |  4 +-
 drivers/ram/rockchip/dmc-rk3368.c             |  2 +-
 drivers/ram/rockchip/sdram_rk3188.c           |  2 +-
 drivers/ram/rockchip/sdram_rk3288.c           |  2 +-
 drivers/ram/rockchip/sdram_rk3328.c           |  2 +-
 drivers/serial/sandbox.c                      |  6 +--
 drivers/spi/mxs_spi.c                         |  6 +--
 drivers/spi/rk_spi.c                          |  6 +--
 drivers/spi/sandbox_spi.c                     |  4 +-
 drivers/tpm/tpm_tis_sandbox.c                 |  4 +-
 drivers/video/rockchip/rk3288_vop.c           |  4 +-
 drivers/video/sandbox_sdl.c                   |  4 +-
 drivers/watchdog/at91sam9_wdt.c               |  4 +-
 test/dm/gpio.c                                |  2 +-
 test/dm/spi.c                                 |  6 +--
 test/py/tests/test_bind.py                    | 54 +++++++++----------
 45 files changed, 104 insertions(+), 120 deletions(-)
arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c +3 -3
index c033ed6d16..8122d2f98e 100644
@@ -220,7 +220,7 @@ static const struct at91_port_platdata at91sam9260_plat[] = {
 };
 
 U_BOOT_DEVICES(at91sam9260_gpios) = {
-	{ "gpio_at91", &at91sam9260_plat[0] },
-	{ "gpio_at91", &at91sam9260_plat[1] },
-	{ "gpio_at91", &at91sam9260_plat[2] },
+	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[0] },
+	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[1] },
+	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[2] },
 };
arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c +5 -5
index 89cbeafa20..08ca3edd78 100644
@@ -176,9 +176,9 @@ static const struct at91_port_platdata at91sam9260_plat[] = {
 };
 
 U_BOOT_DEVICES(at91sam9260_gpios) = {
-	{ "gpio_at91", &at91sam9260_plat[0] },
-	{ "gpio_at91", &at91sam9260_plat[1] },
-	{ "gpio_at91", &at91sam9260_plat[2] },
-	{ "gpio_at91", &at91sam9260_plat[3] },
-	{ "gpio_at91", &at91sam9260_plat[4] },
+	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[0] },
+	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[1] },
+	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[2] },
+	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[3] },
+	{ "atmel_at91rm9200_gpio", &at91sam9260_plat[4] },
 };
arch/arm/mach-rockchip/rk3328/syscon_rk3328.c +2 -2
index 8a0eceb178..daf74a0e2d 100644
@@ -13,8 +13,8 @@ static const struct udevice_id rk3328_syscon_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(syscon_rk3328) = {
-	.name = "rk3328_syscon",
+U_BOOT_DRIVER(rockchip_rk3328_grf) = {
+	.name = "rockchip_rk3328_grf",
 	.id = UCLASS_SYSCON,
 	.of_match = rk3328_syscon_ids,
 };
board/davinci/da8xxevm/omapl138_lcdk.c +1 -1
index 608a7f28eb..269071e503 100644
@@ -368,7 +368,7 @@ U_BOOT_DEVICE(omapl138_uart) = {
 };
 
 U_BOOT_DEVICE(omapl138_mmc) = {
-	.name = "davinci_mmc",
+	.name = "ti_da830_mmc",
 };
 
 void spl_board_init(void)
board/sandbox/sandbox.c +1 -1
index 1372003018..bd39109f3b 100644
@@ -22,7 +22,7 @@ gd_t *gd;
 
 /* Add a simple GPIO device */
 U_BOOT_DEVICE(gpio_sandbox) = {
-	.name = "gpio_sandbox",
+	.name = "sandbox_gpio",
 };
 
 void flush_cache(unsigned long start, unsigned long size)
drivers/clk/at91/clk-master.c +2 -2
index 4fa33c4715..e078fab7b4 100644
@@ -25,8 +25,8 @@ static const struct udevice_id at91_master_clk_match[] = {
 	{}
 };
 
-U_BOOT_DRIVER(at91_master_clk) = {
-	.name = "at91-master-clk",
+U_BOOT_DRIVER(atmel_at91rm9200_clk_master) = {
+	.name = "atmel_at91rm9200_clk_master",
 	.id = UCLASS_CLK,
 	.of_match = at91_master_clk_match,
 	.ops = &at91_master_clk_ops,
drivers/clk/at91/clk-peripheral.c +2 -2
index c55e6214b2..cd9d5e77c0 100644
@@ -43,8 +43,8 @@ static const struct udevice_id sam9x5_periph_clk_match[] = {
 	{}
 };
 
-U_BOOT_DRIVER(sam9x5_periph_clk) = {
-	.name = "sam9x5-periph-clk",
+U_BOOT_DRIVER(atmel_at91rm9200_clk_peripheral) = {
+	.name = "atmel_at91rm9200_clk_peripheral",
 	.id = UCLASS_MISC,
 	.of_match = sam9x5_periph_clk_match,
 	.bind = sam9x5_periph_clk_bind,
drivers/clk/at91/pmc.c +2 -2
index f5808449a6..1fede16a0c 100644
@@ -24,8 +24,8 @@ static const struct udevice_id at91_pmc_match[] = {
 	{}
 };
 
-U_BOOT_DRIVER(at91_pmc) = {
-	.name = "at91-pmc",
+U_BOOT_DRIVER(atmel_at91rm9200_pmc) = {
+	.name = "atmel_at91rm9200_pmc",
 	.id = UCLASS_SIMPLE_BUS,
 	.of_match = at91_pmc_match,
 };
drivers/core/simple-bus.c +2 -2
index 7fc23ef82d..7cc1d46009 100644
@@ -56,8 +56,8 @@ static const struct udevice_id generic_simple_bus_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(simple_bus_drv) = {
-	.name	= "generic_simple_bus",
+U_BOOT_DRIVER(simple_bus) = {
+	.name	= "simple_bus",
 	.id	= UCLASS_SIMPLE_BUS,
 	.of_match = generic_simple_bus_ids,
 	.flags	= DM_FLAG_PRE_RELOC,
drivers/gpio/at91_gpio.c +2 -2
index 3621cf2408..4a8b2e6ff6 100644
@@ -624,8 +624,8 @@ static const struct udevice_id at91_gpio_ids[] = {
 };
 #endif
 
-U_BOOT_DRIVER(gpio_at91) = {
-	.name	= "gpio_at91",
+U_BOOT_DRIVER(atmel_at91rm9200_gpio) = {
+	.name	= "atmel_at91rm9200_gpio",
 	.id	= UCLASS_GPIO,
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 	.of_match = at91_gpio_ids,
drivers/gpio/da8xx_gpio.c +2 -2
index 0d0e9d2254..ab0a5cfd33 100644
@@ -553,8 +553,8 @@ static int davinci_gpio_ofdata_to_platdata(struct udevice *dev)
 	return 0;
 }
 
-U_BOOT_DRIVER(gpio_davinci) = {
-	.name	= "gpio_davinci",
+U_BOOT_DRIVER(ti_dm6441_gpio) = {
+	.name	= "ti_dm6441_gpio",
 	.id	= UCLASS_GPIO,
 	.ops	= &gpio_davinci_ops,
 	.ofdata_to_platdata = of_match_ptr(davinci_gpio_ofdata_to_platdata),
drivers/gpio/mxs_gpio.c +1 -5
index 405e9ac135..e43484d13a 100644
@@ -297,12 +297,8 @@ static const struct udevice_id mxs_gpio_ids[] = {
 };
 #endif
 
-U_BOOT_DRIVER(gpio_mxs) = {
-#ifdef CONFIG_MX28
-	.name = "fsl_imx28_gpio",
-#else /* CONFIG_MX23 */
+U_BOOT_DRIVER(fsl_imx23_gpio) = {
 	.name = "fsl_imx23_gpio",
-#endif
 	.id	= UCLASS_GPIO,
 	.ops	= &gpio_mxs_ops,
 	.probe	= mxs_gpio_probe,
drivers/gpio/rk_gpio.c +2 -2
index 3d96678a45..8cc288581c 100644
@@ -172,8 +172,8 @@ static const struct udevice_id rockchip_gpio_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(gpio_rockchip) = {
-	.name	= "gpio_rockchip",
+U_BOOT_DRIVER(rockchip_gpio_bank) = {
+	.name	= "rockchip_gpio_bank",
 	.id	= UCLASS_GPIO,
 	.of_match = rockchip_gpio_ids,
 	.ops	= &gpio_rockchip_ops,
drivers/gpio/sandbox.c +2 -2
index 9549c74c2b..ff46d3c8d1 100644
@@ -243,8 +243,8 @@ static const struct udevice_id sandbox_gpio_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(gpio_sandbox) = {
-	.name	= "gpio_sandbox",
+U_BOOT_DRIVER(sandbox_gpio) = {
+	.name	= "sandbox_gpio",
 	.id	= UCLASS_GPIO,
 	.of_match = sandbox_gpio_ids,
 	.ofdata_to_platdata = sandbox_gpio_ofdata_to_platdata,
drivers/i2c/rk_i2c.c +2 -2
index 32b2ee8578..eceef80e70 100644
@@ -483,8 +483,8 @@ static const struct udevice_id rockchip_i2c_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(i2c_rockchip) = {
-	.name	= "i2c_rockchip",
+U_BOOT_DRIVER(rockchip_rk3066_i2c) = {
+	.name	= "rockchip_rk3066_i2c",
 	.id	= UCLASS_I2C,
 	.of_match = rockchip_i2c_ids,
 	.ofdata_to_platdata = rockchip_i2c_ofdata_to_platdata,
drivers/input/cros_ec_keyb.c +2 -2
index 8c1a25c73f..6c26157b07 100644
@@ -224,8 +224,8 @@ static const struct udevice_id cros_ec_kbd_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(cros_ec_kbd) = {
-	.name	= "cros_ec_kbd",
+U_BOOT_DRIVER(google_cros_ec_keyb) = {
+	.name	= "google_cros_ec_keyb",
 	.id	= UCLASS_KEYBOARD,
 	.of_match = cros_ec_kbd_ids,
 	.probe = cros_ec_kbd_probe,
drivers/misc/cros_ec_sandbox.c +2 -2
index 9dd6a18b2b..dc72a2c43d 100644
@@ -571,8 +571,8 @@ static const struct udevice_id cros_ec_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(cros_ec_sandbox) = {
-	.name		= "cros_ec_sandbox",
+U_BOOT_DRIVER(google_cros_ec_sandbox) = {
+	.name		= "google_cros_ec_sandbox",
 	.id		= UCLASS_CROS_EC,
 	.of_match	= cros_ec_ids,
 	.probe		= cros_ec_probe,
drivers/mmc/davinci_mmc.c +2 -2
index ef5cd4e723..4da3827e47 100644
@@ -538,8 +538,8 @@ static const struct udevice_id davinci_mmc_ids[] = {
 	{},
 };
 
-U_BOOT_DRIVER(davinci_mmc_drv) = {
-	.name = "davinci_mmc",
+U_BOOT_DRIVER(ti_da830_mmc) = {
+	.name = "ti_da830_mmc",
 	.id		= UCLASS_MMC,
 	.of_match	= davinci_mmc_ids,
 #if CONFIG_BLK
drivers/mmc/mxsmmc.c +1 -5
index 9414eff42b..35c336b499 100644
@@ -708,12 +708,8 @@ static const struct udevice_id mxsmmc_ids[] = {
 };
 #endif
 
-U_BOOT_DRIVER(mxsmmc) = {
-#ifdef CONFIG_MX28
-	.name = "fsl_imx28_mmc",
-#else /* CONFIG_MX23 */
+U_BOOT_DRIVER(fsl_imx23_mmc) = {
 	.name = "fsl_imx23_mmc",
-#endif
 	.id	= UCLASS_MMC,
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 	.of_match = mxsmmc_ids,
drivers/mmc/rockchip_dw_mmc.c +1 -1
index a0e1be8794..ef75367b3e 100644
@@ -166,7 +166,7 @@ static const struct udevice_id rockchip_dwmmc_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(rockchip_dwmmc_drv) = {
+U_BOOT_DRIVER(rockchip_rk3288_dw_mshc) = {
 	.name		= "rockchip_rk3288_dw_mshc",
 	.id		= UCLASS_MMC,
 	.of_match	= rockchip_dwmmc_ids,
drivers/mtd/spi/sf-uclass.c +1 -1
index 5ebcca590a..b335cbc90b 100644
@@ -76,7 +76,7 @@ int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs,
 	str = strdup(name);
 #endif
 	ret = spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode,
-				  "spi_flash_std", str, &bus, &slave);
+				  "jedec_spi_nor", str, &bus, &slave);
 	if (ret)
 		return ret;
 
drivers/mtd/spi/sf_probe.c +2 -2
index 72b6ee702d..1b44cc68c6 100644
@@ -170,8 +170,8 @@ static const struct udevice_id spi_flash_std_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(spi_flash_std) = {
-	.name		= "spi_flash_std",
+U_BOOT_DRIVER(jedec_spi_nor) = {
+	.name		= "jedec_spi_nor",
 	.id		= UCLASS_SPI_FLASH,
 	.of_match	= spi_flash_std_ids,
 	.probe		= spi_flash_std_probe,
drivers/pinctrl/nxp/pinctrl-mxs.c +2 -2
index 8d61dfe863..bd434667b1 100644
@@ -179,8 +179,8 @@ static const struct udevice_id mxs_pinctrl_match[] = {
 	{ /* sentinel */ }
 };
 
-U_BOOT_DRIVER(mxs_pinctrl) = {
-	.name = "mxs-pinctrl",
+U_BOOT_DRIVER(fsl_imx23_pinctrl) = {
+	.name = "fsl_imx23_pinctrl",
 	.id = UCLASS_PINCTRL,
 	.of_match = of_match_ptr(mxs_pinctrl_match),
 	.probe = mxs_pinctrl_probe,
drivers/pinctrl/pinctrl-at91.c +2 -2
index 27f274ff02..0cc35042f5 100644
@@ -517,8 +517,8 @@ static const struct udevice_id at91_pinctrl_match[] = {
 	{}
 };
 
-U_BOOT_DRIVER(at91_pinctrl) = {
-	.name = "pinctrl_at91",
+U_BOOT_DRIVER(atmel_sama5d3_pinctrl) = {
+	.name = "atmel_sama5d3_pinctrl",
 	.id = UCLASS_PINCTRL,
 	.of_match = at91_pinctrl_match,
 	.probe = at91_pinctrl_probe,
drivers/pinctrl/rockchip/pinctrl-rk3188.c +1 -1
index 043764fc92..f1d76b1c8f 100644
@@ -119,7 +119,7 @@ static const struct udevice_id rk3188_pinctrl_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(pinctrl_rk3188) = {
+U_BOOT_DRIVER(rockchip_rk3188_pinctrl) = {
 	.name		= "rockchip_rk3188_pinctrl",
 	.id		= UCLASS_PINCTRL,
 	.of_match	= rk3188_pinctrl_ids,
drivers/pinctrl/rockchip/pinctrl-rk3288.c +1 -1
index 7ae147f304..c617d21b7a 100644
@@ -240,7 +240,7 @@ static const struct udevice_id rk3288_pinctrl_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(pinctrl_rk3288) = {
+U_BOOT_DRIVER(rockchip_rk3288_pinctrl) = {
 	.name		= "rockchip_rk3288_pinctrl",
 	.id		= UCLASS_PINCTRL,
 	.of_match	= rk3288_pinctrl_ids,
drivers/pinctrl/rockchip/pinctrl-rk3328.c +1 -1
index 8d37a6f945..6da9eee16e 100644
@@ -315,7 +315,7 @@ static const struct udevice_id rk3328_pinctrl_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(pinctrl_rk3328) = {
+U_BOOT_DRIVER(rockchip_rk3328_pinctrl) = {
 	.name		= "rockchip_rk3328_pinctrl",
 	.id		= UCLASS_PINCTRL,
 	.of_match	= rk3328_pinctrl_ids,
drivers/pinctrl/rockchip/pinctrl-rk3368.c +1 -1
index 6cb7bb45d9..52ecffeddd 100644
@@ -170,7 +170,7 @@ static const struct udevice_id rk3368_pinctrl_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(pinctrl_rk3368) = {
+U_BOOT_DRIVER(rockchip_rk3368_pinctrl) = {
 	.name		= "rockchip_rk3368_pinctrl",
 	.id		= UCLASS_PINCTRL,
 	.of_match	= rk3368_pinctrl_ids,
drivers/power/pmic/rk8xx.c +2 -2
index 52e6d9d8c0..d870ed7113 100644
@@ -182,8 +182,8 @@ static const struct udevice_id rk8xx_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(pmic_rk8xx) = {
-	.name = "rk8xx pmic",
+U_BOOT_DRIVER(rockchip_rk805) = {
+	.name = "rockchip_rk805",
 	.id = UCLASS_PMIC,
 	.of_match = rk8xx_ids,
 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
drivers/power/regulator/fixed.c +2 -2
index 763e671d54..ac3ec7814c 100644
@@ -81,8 +81,8 @@ static const struct udevice_id fixed_regulator_ids[] = {
 	{ },
 };
 
-U_BOOT_DRIVER(fixed_regulator) = {
-	.name = "fixed regulator",
+U_BOOT_DRIVER(regulator_fixed) = {
+	.name = "regulator_fixed",
 	.id = UCLASS_REGULATOR,
 	.ops = &fixed_regulator_ops,
 	.of_match = fixed_regulator_ids,
drivers/ram/rockchip/dmc-rk3368.c +1 -1
index 2d82a176db..b97a629eae 100644
@@ -989,7 +989,7 @@ static const struct udevice_id rk3368_dmc_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(dmc_rk3368) = {
+U_BOOT_DRIVER(rockchip_rk3368_dmc) = {
 	.name = "rockchip_rk3368_dmc",
 	.id = UCLASS_RAM,
 	.of_match = rk3368_dmc_ids,
drivers/ram/rockchip/sdram_rk3188.c +1 -1
index 9b5eb38ecc..0822898f6f 100644
@@ -942,7 +942,7 @@ static const struct udevice_id rk3188_dmc_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(dmc_rk3188) = {
+U_BOOT_DRIVER(rockchip_rk3188_dmc) = {
 	.name = "rockchip_rk3188_dmc",
 	.id = UCLASS_RAM,
 	.of_match = rk3188_dmc_ids,
drivers/ram/rockchip/sdram_rk3288.c +1 -1
index 9f6f555147..0245ad9844 100644
@@ -1110,7 +1110,7 @@ static const struct udevice_id rk3288_dmc_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(dmc_rk3288) = {
+U_BOOT_DRIVER(rockchip_rk3288_dmc) = {
 	.name = "rockchip_rk3288_dmc",
 	.id = UCLASS_RAM,
 	.of_match = rk3288_dmc_ids,
drivers/ram/rockchip/sdram_rk3328.c +1 -1
index 8329f4a352..d91e0c0f95 100644
@@ -603,7 +603,7 @@ static const struct udevice_id rk3328_dmc_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(dmc_rk3328) = {
+U_BOOT_DRIVER(rockchip_rk3328_dmc) = {
 	.name = "rockchip_rk3328_dmc",
 	.id = UCLASS_RAM,
 	.of_match = rk3328_dmc_ids,
drivers/serial/sandbox.c +3 -3
index 545ff3f747..36e081f08c 100644
@@ -252,8 +252,8 @@ static const struct udevice_id sandbox_serial_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(serial_sandbox) = {
-	.name	= "serial_sandbox",
+U_BOOT_DRIVER(sandbox_serial) = {
+	.name	= "sandbox_serial",
 	.id	= UCLASS_SERIAL,
 	.of_match = sandbox_serial_ids,
 	.ofdata_to_platdata = sandbox_serial_ofdata_to_platdata,
@@ -270,7 +270,7 @@ static const struct sandbox_serial_platdata platdata_non_fdt = {
 };
 
 U_BOOT_DEVICE(serial_sandbox_non_fdt) = {
-	.name = "serial_sandbox",
+	.name = "sandbox_serial",
 	.platdata = &platdata_non_fdt,
 };
 #endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
drivers/spi/mxs_spi.c +1 -5
index 3ca30887fb..087cd50788 100644
@@ -606,12 +606,8 @@ static const struct udevice_id mxs_spi_ids[] = {
 };
 #endif
 
-U_BOOT_DRIVER(mxs_spi) = {
-#ifdef CONFIG_MX28
-	.name = "fsl_imx28_spi",
-#else /* CONFIG_MX23 */
+U_BOOT_DRIVER(fsl_imx23_spi) = {
 	.name = "fsl_imx23_spi",
-#endif
 	.id	= UCLASS_SPI,
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 	.of_match = mxs_spi_ids,
drivers/spi/rk_spi.c +1 -5
index 95eeb8307a..d25a87fad6 100644
@@ -551,12 +551,8 @@ static const struct udevice_id rockchip_spi_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(rockchip_spi) = {
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
+U_BOOT_DRIVER(rockchip_rk3288_spi) = {
 	.name	= "rockchip_rk3288_spi",
-#else
-	.name	= "rockchip_spi",
-#endif
 	.id	= UCLASS_SPI,
 	.of_match = rockchip_spi_ids,
 	.ops	= &rockchip_spi_ops,
drivers/spi/sandbox_spi.c +2 -2
index 6b610ff823..d3c0e621d3 100644
@@ -145,8 +145,8 @@ static const struct udevice_id sandbox_spi_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(spi_sandbox) = {
-	.name	= "spi_sandbox",
+U_BOOT_DRIVER(sandbox_spi) = {
+	.name	= "sandbox_spi",
 	.id	= UCLASS_SPI,
 	.of_match = sandbox_spi_ids,
 	.ops	= &sandbox_spi_ops,
drivers/tpm/tpm_tis_sandbox.c +2 -2
index 2dff0d3eee..e167d0a2fe 100644
@@ -355,8 +355,8 @@ static const struct udevice_id sandbox_tpm_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(sandbox_tpm) = {
-	.name   = "sandbox_tpm",
+U_BOOT_DRIVER(google_sandbox_tpm) = {
+	.name   = "google_sandbox_tpm",
 	.id     = UCLASS_TPM,
 	.of_match = sandbox_tpm_ids,
 	.ops    = &sandbox_tpm_ops,
drivers/video/rockchip/rk3288_vop.c +2 -2
index 0f91dab1f2..cac86aeaad 100644
@@ -96,8 +96,8 @@ static const struct udevice_id rk3288_vop_ids[] = {
 static const struct video_ops rk3288_vop_ops = {
 };
 
-U_BOOT_DRIVER(rk_vop) = {
-	.name	= "rk3288_vop",
+U_BOOT_DRIVER(rockchip_rk3288_vop) = {
+	.name	= "rockchip_rk3288_vop",
 	.id	= UCLASS_VIDEO,
 	.of_match = rk3288_vop_ids,
 	.ops	= &rk3288_vop_ops,
drivers/video/sandbox_sdl.c +2 -2
index 1196e6c671..7e7a7eff02 100644
@@ -63,8 +63,8 @@ static const struct udevice_id sandbox_sdl_ids[] = {
 	{ }
 };
 
-U_BOOT_DRIVER(sdl_sandbox) = {
-	.name	= "sdl_sandbox",
+U_BOOT_DRIVER(sandbox_lcd_sdl) = {
+	.name	= "sandbox_lcd_sdl",
 	.id	= UCLASS_VIDEO,
 	.of_match = sandbox_sdl_ids,
 	.bind	= sandbox_sdl_bind,
drivers/watchdog/at91sam9_wdt.c +2 -2
index 48433cc158..cd05acbc28 100644
@@ -112,8 +112,8 @@ static int at91_wdt_probe(struct udevice *dev)
 	return 0;
 }
 
-U_BOOT_DRIVER(at91_wdt) = {
-	.name = "at91_wdt",
+U_BOOT_DRIVER(atmel_at91sam9260_wdt) = {
+	.name = "atmel_at91sam9260_wdt",
 	.id = UCLASS_WDT,
 	.of_match = at91_wdt_ids,
 	.priv_auto_alloc_size = sizeof(struct at91_wdt_priv),
test/dm/gpio.c +1 -1
index 7c18e5c411..7133ccffa9 100644
@@ -211,7 +211,7 @@ static int dm_test_gpio_anon(struct unit_test_state *uts)
 
 	/* And the anonymous bank */
 	ut_assertok(gpio_lookup_name("14", &dev, &offset, &gpio));
-	ut_asserteq_str(dev->name, "gpio_sandbox");
+	ut_asserteq_str(dev->name, "sandbox_gpio");
 	ut_asserteq(14, offset);
 	ut_asserteq(14, gpio);
 
test/dm/spi.c +3 -3
index 8e417acc5f..fc859027a7 100644
@@ -58,7 +58,7 @@ static int dm_test_spi_find(struct unit_test_state *uts)
 	 */
 	ut_asserteq(-ENODEV, spi_find_bus_and_cs(busnum, cs, &bus, &dev));
 	ut_asserteq(-ENOENT, spi_get_bus_and_cs(busnum, cs, speed, mode,
-						"spi_flash_std", "name", &bus,
+						"jedec_spi_nor", "name", &bus,
 						&slave));
 	sandbox_sf_unbind_emul(state_get_current(), busnum, cs);
 	ut_assertok(spi_cs_info(bus, cs, &info));
@@ -69,7 +69,7 @@ static int dm_test_spi_find(struct unit_test_state *uts)
 					 "name"));
 	ut_assertok(spi_find_bus_and_cs(busnum, cs, &bus, &dev));
 	ut_assertok(spi_get_bus_and_cs(busnum, cs, speed, mode,
-				       "spi_flash_std", "name", &bus, &slave));
+				       "jedec_spi_nor", "name", &bus, &slave));
 
 	ut_assertok(spi_cs_info(bus, cs, &info));
 	ut_asserteq_ptr(info.dev, slave->dev);
@@ -78,7 +78,7 @@ static int dm_test_spi_find(struct unit_test_state *uts)
 	ut_assertok(sandbox_sf_bind_emul(state, busnum, cs_b, bus, node,
 					 "name"));
 	ut_asserteq(-EINVAL, spi_get_bus_and_cs(busnum, cs_b, speed, mode,
-				       "spi_flash_std", "name", &bus, &slave));
+				       "jedec_spi_nor", "name", &bus, &slave));
 	ut_asserteq(-EINVAL, spi_cs_info(bus, cs_b, &info));
 	ut_asserteq_ptr(NULL, info.dev);
 
test/py/tests/test_bind.py +27 -27

148 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 1/14 drivers: rename drivers to match compatible string

Quoted 51 lines · Walter Lozano

When using OF_PLATDATA, the bind process between devices and drivers is performed trying to match compatible string with driver names. However driver names are not strictly defined, and also there are different names used when declaring a driver with U_BOOT_DRIVER, the name of the symbol used in the linker list and the used in the struct driver_info.

In order to make things a bit more clear, rename the drivers names. This will also help for further OF_PLATDATA improvements, such as checking for valid driver names.

---
 .../mach-at91/arm926ejs/at91sam9260_devices.c |  6 +--
 .../arm926ejs/at91sam9m10g45_devices.c        | 10 ++--
 arch/arm/mach-rockchip/rk3328/syscon_rk3328.c |  4 +-
 board/davinci/da8xxevm/omapl138_lcdk.c        |  2 +-
 board/sandbox/sandbox.c                       |  2 +-
 drivers/clk/at91/clk-master.c                 |  4 +-
 drivers/clk/at91/clk-peripheral.c             |  4 +-
 drivers/clk/at91/pmc.c                        |  4 +-
 drivers/core/simple-bus.c                     |  4 +-
 drivers/gpio/at91_gpio.c                      |  4 +-
 drivers/gpio/da8xx_gpio.c                     |  4 +-
 drivers/gpio/mxs_gpio.c                       |  6 +--
 drivers/gpio/rk_gpio.c                        |  4 +-
 drivers/gpio/sandbox.c                        |  4 +-
 drivers/i2c/rk_i2c.c                          |  4 +-
 drivers/input/cros_ec_keyb.c                  |  4 +-
 drivers/misc/cros_ec_sandbox.c                |  4 +-
 drivers/mmc/davinci_mmc.c                     |  4 +-
 drivers/mmc/mxsmmc.c                          |  6 +--
 drivers/mmc/rockchip_dw_mmc.c                 |  2 +-
 drivers/mtd/spi/sf-uclass.c                   |  2 +-
 drivers/mtd/spi/sf_probe.c                    |  4 +-
 drivers/pinctrl/nxp/pinctrl-mxs.c             |  4 +-
 drivers/pinctrl/pinctrl-at91.c                |  4 +-
 drivers/pinctrl/rockchip/pinctrl-rk3188.c     |  2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3288.c     |  2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3328.c     |  2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3368.c     |  2 +-
 drivers/power/pmic/rk8xx.c                    |  4 +-
 drivers/power/regulator/fixed.c               |  4 +-
 drivers/ram/rockchip/dmc-rk3368.c             |  2 +-
 drivers/ram/rockchip/sdram_rk3188.c           |  2 +-
 drivers/ram/rockchip/sdram_rk3288.c           |  2 +-
 drivers/ram/rockchip/sdram_rk3328.c           |  2 +-
 drivers/serial/sandbox.c                      |  6 +--
 drivers/spi/mxs_spi.c                         |  6 +--
 drivers/spi/rk_spi.c                          |  6 +--
 drivers/spi/sandbox_spi.c                     |  4 +-
Quoted 9 lines
 drivers/tpm/tpm_tis_sandbox.c                 |  4 +-
 drivers/video/rockchip/rk3288_vop.c           |  4 +-
 drivers/video/sandbox_sdl.c                   |  4 +-
 drivers/watchdog/at91sam9_wdt.c               |  4 +-
 test/dm/gpio.c                                |  2 +-
 test/dm/spi.c                                 |  6 +--
 test/py/tests/test_bind.py                    | 54 +++++++++----------
 45 files changed, 104 insertions(+), 120 deletions(-)
#3 lore raw

PATCH v2 2/14 dtoc: add missing code comments

In reply to Walter Lozano

Add missing information about internal class members in order to make the code easier to follow.

---
 tools/dtoc/dtb_platdata.py | 3 +++
 1 file changed, 3 insertions(+)
tools/dtoc/dtb_platdata.py +3 -0
index ecfe0624d1..bc0de426a9 100644
@@ -140,6 +140,9 @@ class DtbPlatdata(object):
         _include_disabled: true to include nodes marked status = "disabled"
         _outfile: The current output file (sys.stdout or a real file)
         _lines: Stashed list of output lines for outputting in the future
+        _aliases: Dict that hold aliases for compatible strings
+            key: First compatible string declared in a node
+            value: List of additional compatible strings declared in a node
     """
     def __init__(self, dtb_fname, include_disabled):
         self._fdt = None
Signature · 1 line
2.20.1
#5 lore raw

PATCH v2 3/14 dtoc: add support to scan drivers

In reply to Walter Lozano

Currently dtoc scans dtbs to convert them to struct platdata and to generate U_BOOT_DEVICE entries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.

In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an U_BOOT_DEVICE entry will try to use a name not valid.

Additionally, in order to add more flexibility to the solution, adds the U_BOOT_DRIVER_ALIAS macro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates the U_BOOT_DEVICE entry.

---
 drivers/clk/at91/pmc.c                |  2 +
 drivers/gpio/mxs_gpio.c               |  2 +
 drivers/gpio/sandbox.c                |  2 +
 drivers/i2c/rk_i2c.c                  |  2 +
 drivers/mmc/mxsmmc.c                  |  1 +
 drivers/mmc/rockchip_dw_mmc.c         |  3 +
 drivers/mtd/spi/sf_probe.c            |  2 +
 drivers/pinctrl/nxp/pinctrl-mxs.c     |  2 +
 drivers/pinctrl/pinctrl-at91.c        |  2 +
 drivers/power/pmic/rk8xx.c            |  2 +
 drivers/serial/ns16550.c              |  4 ++
 drivers/spi/mxs_spi.c                 |  2 +
 drivers/spi/rk_spi.c                  |  2 +
 include/dm/device.h                   |  7 +++
 tools/dtoc/dtb_platdata.py            | 89 +++++++++++++++++++++++++--
 tools/dtoc/dtoc_test_driver_alias.dts | 20 ++++++
 tools/dtoc/test_dtoc.py               | 33 ++++++++++
 17 files changed, 173 insertions(+), 4 deletions(-)
 create mode 100644 tools/dtoc/dtoc_test_driver_alias.dts
drivers/clk/at91/pmc.c +2 -0
index 1fede16a0c..793a506d27 100644
@@ -30,6 +30,8 @@ U_BOOT_DRIVER(atmel_at91rm9200_pmc) = {
 	.of_match = at91_pmc_match,
 };
 
+U_BOOT_DRIVER_ALIAS(atmel_at91rm9200_pmc, atmel_at91sam9260_pmc)
+
 /*---------------------------------------------------------*/
 
 int at91_pmc_core_probe(struct udevice *dev)
drivers/gpio/mxs_gpio.c +2 -0
index e43484d13a..bcdf08c255 100644
@@ -309,4 +309,6 @@ U_BOOT_DRIVER(fsl_imx23_gpio) = {
 	.ofdata_to_platdata = mxs_ofdata_to_platdata,
 #endif
 };
+
+U_BOOT_DRIVER_ALIAS(fsl_imx23_gpio, fsl_imx28_gpio)
 #endif /* DM_GPIO */
drivers/gpio/sandbox.c +2 -0
index ff46d3c8d1..8923e54867 100644
@@ -253,6 +253,8 @@ U_BOOT_DRIVER(sandbox_gpio) = {
 	.ops	= &gpio_sandbox_ops,
 };
 
+U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias)
+
 /* pincontrol: used only to check GPIO pin configuration (pinmux command) */
 
 struct sb_pinctrl_priv {
drivers/i2c/rk_i2c.c +2 -0
index eceef80e70..e76c087b1d 100644
@@ -492,3 +492,5 @@ U_BOOT_DRIVER(rockchip_rk3066_i2c) = {
 	.priv_auto_alloc_size = sizeof(struct rk_i2c),
 	.ops	= &rockchip_i2c_ops,
 };
+
+U_BOOT_DRIVER_ALIAS(rockchip_rk3066_i2c, rockchip_rk3288_i2c)
drivers/mmc/mxsmmc.c +1 -0
index 35c336b499..afa95e57ee 100644
@@ -724,4 +724,5 @@ U_BOOT_DRIVER(fsl_imx23_mmc) = {
 	.platdata_auto_alloc_size = sizeof(struct mxsmmc_platdata),
 };
 
+U_BOOT_DRIVER_ALIAS(fsl_imx23_mmc, fsl_imx28_mmc)
 #endif /* CONFIG_DM_MMC */
drivers/mmc/rockchip_dw_mmc.c +3 -0
index ef75367b3e..ac710324c8 100644
@@ -178,6 +178,9 @@ U_BOOT_DRIVER(rockchip_rk3288_dw_mshc) = {
 	.platdata_auto_alloc_size = sizeof(struct rockchip_mmc_plat),
 };
 
+U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc)
+U_BOOT_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3368_dw_mshc)
+
 #ifdef CONFIG_PWRSEQ
 static int rockchip_dwmmc_pwrseq_set_power(struct udevice *dev, bool enable)
 {
drivers/mtd/spi/sf_probe.c +2 -0
index 1b44cc68c6..97fa22a4b3 100644
@@ -180,4 +180,6 @@ U_BOOT_DRIVER(jedec_spi_nor) = {
 	.ops		= &spi_flash_std_ops,
 };
 
+U_BOOT_DRIVER_ALIAS(jedec_spi_nor, spansion_m25p16)
+
 #endif /* CONFIG_DM_SPI_FLASH */
drivers/pinctrl/nxp/pinctrl-mxs.c +2 -0
index bd434667b1..da6b95acc5 100644
@@ -190,3 +190,5 @@ U_BOOT_DRIVER(fsl_imx23_pinctrl) = {
 	.priv_auto_alloc_size = sizeof(struct mxs_pinctrl_priv),
 	.ops = &mxs_pinctrl_ops,
 };
+
+U_BOOT_DRIVER_ALIAS(fsl_imx23_pinctrl, fsl_imx28_pinctrl)
drivers/pinctrl/pinctrl-at91.c +2 -0
index 0cc35042f5..b40ff8c823 100644
@@ -525,3 +525,5 @@ U_BOOT_DRIVER(atmel_sama5d3_pinctrl) = {
 	.priv_auto_alloc_size = sizeof(struct at91_pinctrl_priv),
 	.ops = &at91_pinctrl_ops,
 };
+
+U_BOOT_DRIVER_ALIAS(atmel_sama5d3_pinctrl, atmel_at91rm9200_pinctrl)
drivers/power/pmic/rk8xx.c +2 -0
index d870ed7113..c8ae28b8f3 100644
@@ -193,3 +193,5 @@ U_BOOT_DRIVER(rockchip_rk805) = {
 	.probe = rk8xx_probe,
 	.ops = &rk8xx_ops,
 };
+
+U_BOOT_DRIVER_ALIAS(rockchip_rk805, rockchip_rk808)
drivers/serial/ns16550.c +4 -0
index 6415d2e1e5..df958a688b 100644
@@ -619,6 +619,10 @@ U_BOOT_DRIVER(ns16550_serial) = {
 	.flags	= DM_FLAG_PRE_RELOC,
 #endif
 };
+
+U_BOOT_DRIVER_ALIAS(ns16550_serial, rockchip_rk3328_uart)
+U_BOOT_DRIVER_ALIAS(ns16550_serial, rockchip_rk3368_uart)
+U_BOOT_DRIVER_ALIAS(ns16550_serial, ti_da830_uart)
 #endif
 #endif /* SERIAL_PRESENT */
 
drivers/spi/mxs_spi.c +2 -0
index 087cd50788..2779501176 100644
@@ -618,4 +618,6 @@ U_BOOT_DRIVER(fsl_imx23_spi) = {
 	.priv_auto_alloc_size = sizeof(struct mxs_spi_priv),
 	.probe	= mxs_spi_probe,
 };
+
+U_BOOT_DRIVER_ALIAS(fsl_imx23_spi, fsl_imx28_spi)
 #endif
drivers/spi/rk_spi.c +2 -0
index d25a87fad6..0ac7f767ca 100644
@@ -561,3 +561,5 @@ U_BOOT_DRIVER(rockchip_rk3288_spi) = {
 	.priv_auto_alloc_size = sizeof(struct rockchip_spi_priv),
 	.probe	= rockchip_spi_probe,
 };
+
+U_BOOT_DRIVER_ALIAS(rockchip_rk3288_spi, rockchip_rk3368_spi)
include/dm/device.h +7 -0
index 975eec5d0e..2cfe10766f 100644
@@ -282,6 +282,13 @@ struct driver {
 #define DM_GET_DRIVER(__name)						\
 	ll_entry_get(struct driver, __name, driver)
 
+/**
+ * Declare a macro to state a alias for a driver name. This macro will
+ * produce no code but its information will be parsed by tools like
+ * dtoc
+ */
+#define U_BOOT_DRIVER_ALIAS(__name, __alias)
+
 /**
  * dev_get_platdata() - Get the platform data for a device
  *
tools/dtoc/dtb_platdata.py +85 -4

143 lines not on this page · raw message

tools/dtoc/dtoc_test_driver_alias.dts new file +20 -0
new file mode 100644
index 0000000000..da7973b2e5
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test device tree file for dtoc
+ *
+ * Copyright 2020 Collabora Ltd.
+ */
+
+/dts-v1/;
+
+/ {
+	gpio_a: gpios at 0 {
+		u-boot,dm-pre-reloc;
+		gpio-controller;
+		compatible = "sandbox_gpio_alias";
+		#gpio-cells = <1>;
+		gpio-bank-name = "a";
+		sandbox,gpio-count = <20>;
+	};
+
+};
tools/dtoc/test_dtoc.py +33 -0
index 8498e8303c..91fc9d77f3 100755
@@ -266,6 +266,39 @@ U_BOOT_DEVICE(pmic_at_9) = {
 \t.platdata_size\t= sizeof(dtv_pmic_at_9),
 };
 
+''', data)
+
+    def test_driver_alias(self):
+        """Test output from a device tree file with a driver alias"""
+        dtb_file = get_dtb_file('dtoc_test_driver_alias.dts')
+        output = tools.GetOutputFilename('output')
+        dtb_platdata.run_steps(['struct'], dtb_file, False, output)
+        with open(output) as infile:
+            data = infile.read()
+        self._CheckStrings(HEADER + '''
+struct dtd_sandbox_gpio {
+\tconst char *\tgpio_bank_name;
+\tbool\t\tgpio_controller;
+\tfdt32_t\t\tsandbox_gpio_count;
+};
+#define dtd_sandbox_gpio_alias dtd_sandbox_gpio
+''', data)
+
+        dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
+        with open(output) as infile:
+            data = infile.read()
+        self._CheckStrings(C_HEADER + '''
+static const struct dtd_sandbox_gpio dtv_gpios_at_0 = {
+\t.gpio_bank_name\t\t= "a",
+\t.gpio_controller\t= true,
+\t.sandbox_gpio_count\t= 0x14,
+};
+U_BOOT_DEVICE(gpios_at_0) = {
+\t.name\t\t= "sandbox_gpio",
+\t.platdata\t= &dtv_gpios_at_0,
+\t.platdata_size\t= sizeof(dtv_gpios_at_0),
+};
+
 ''', data)
 
     def test_phandle(self):
Signature · 1 line
2.20.1
#6 lore raw

PATCH v2 3/14 dtoc: add support to scan drivers

Hi Walter,

Quoted 32 lines · Walter Lozano

Currently dtoc scans dtbs to convert them to struct platdata and to generate U_BOOT_DEVICE entries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.

In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an U_BOOT_DEVICE entry will try to use a name not valid.

Additionally, in order to add more flexibility to the solution, adds the U_BOOT_DRIVER_ALIAS macro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates the U_BOOT_DEVICE entry.

---
 drivers/clk/at91/pmc.c                |  2 +
 drivers/gpio/mxs_gpio.c               |  2 +
 drivers/gpio/sandbox.c                |  2 +
 drivers/i2c/rk_i2c.c                  |  2 +
 drivers/mmc/mxsmmc.c                  |  1 +
 drivers/mmc/rockchip_dw_mmc.c         |  3 +
 drivers/mtd/spi/sf_probe.c            |  2 +
 drivers/pinctrl/nxp/pinctrl-mxs.c     |  2 +
 drivers/pinctrl/pinctrl-at91.c        |  2 +
 drivers/power/pmic/rk8xx.c            |  2 +
 drivers/serial/ns16550.c              |  4 ++
Quoted 9 lines
 drivers/spi/mxs_spi.c                 |  2 +
 drivers/spi/rk_spi.c                  |  2 +
 include/dm/device.h                   |  7 +++
 tools/dtoc/dtb_platdata.py            | 89 +++++++++++++++++++++++++--
 tools/dtoc/dtoc_test_driver_alias.dts | 20 ++++++
 tools/dtoc/test_dtoc.py               | 33 ++++++++++
 17 files changed, 173 insertions(+), 4 deletions(-)
 create mode 100644 tools/dtoc/dtoc_test_driver_alias.dts

But please can you split out the changes to drivers and device.h into a separate, earlier patch? I'd like to keep tools changes separate where possible.

Regards,
Simon

#7 lore raw

PATCH v2 3/14 dtoc: add support to scan drivers

Hi Simon,

Quoted 43 lines · Simon Glass

Hi Walter,

Quoted 38 lines · Walter Lozano

Currently dtoc scans dtbs to convert them to struct platdata and to generate U_BOOT_DEVICE entries. These entries need to be filled with the driver name, but at this moment the information used is the compatible name present in the dtb. This causes that only nodes with a compatible name that matches a driver name generate a working entry.

In order to improve this behaviour, this patch adds to dtoc the capability of scan drivers source code to generate a list of valid driver names. This allows to rise a warning in the case that an U_BOOT_DEVICE entry will try to use a name not valid.

Additionally, in order to add more flexibility to the solution, adds the U_BOOT_DRIVER_ALIAS macro, which generates no code at all, but allows an easy way to declare driver name aliases. Thanks to this, dtoc can look for the driver name based on its alias when it populates the U_BOOT_DEVICE entry.

---
  drivers/clk/at91/pmc.c                |  2 +
  drivers/gpio/mxs_gpio.c               |  2 +
  drivers/gpio/sandbox.c                |  2 +
  drivers/i2c/rk_i2c.c                  |  2 +
  drivers/mmc/mxsmmc.c                  |  1 +
  drivers/mmc/rockchip_dw_mmc.c         |  3 +
  drivers/mtd/spi/sf_probe.c            |  2 +
  drivers/pinctrl/nxp/pinctrl-mxs.c     |  2 +
  drivers/pinctrl/pinctrl-at91.c        |  2 +
  drivers/power/pmic/rk8xx.c            |  2 +
  drivers/serial/ns16550.c              |  4 ++
  drivers/spi/mxs_spi.c                 |  2 +
  drivers/spi/rk_spi.c                  |  2 +
  include/dm/device.h                   |  7 +++
  tools/dtoc/dtb_platdata.py            | 89 +++++++++++++++++++++++++--
  tools/dtoc/dtoc_test_driver_alias.dts | 20 ++++++
  tools/dtoc/test_dtoc.py               | 33 ++++++++++
  17 files changed, 173 insertions(+), 4 deletions(-)
Quoted 2 lines

create mode 100644 tools/dtoc/dtoc_test_driver_alias.dts

Quoted 5 lines

But please can you split out the changes to drivers and device.h into a separate, earlier patch? I'd like to keep tools changes separate where possible.

Sure, thanks for your suggestion.

Regards,

Walter

#8 lore raw

PATCH v2 4/14 dtoc: add option to disable warnings

In reply to Walter Lozano

As dtoc now performs checks for valid driver names, when running dtoc tests several warnings arise as these tests don't use valid driver names.

This patch adds an option to disable those warning, which is only intended for running tests.

---
 tools/dtoc/dtb_platdata.py              | 11 +--
 tools/dtoc/dtoc_test_invalid_driver.dts | 15 ++++
 tools/dtoc/test_dtoc.py                 | 91 +++++++++++++++++--------
 3 files changed, 84 insertions(+), 33 deletions(-)
 create mode 100644 tools/dtoc/dtoc_test_invalid_driver.dts
tools/dtoc/dtb_platdata.py +7 -4
index c4701d3211..84c39608c3 100644
@@ -141,6 +141,7 @@ class DtbPlatdata(object):
         _valid_nodes: A list of Node object with compatible strings
         _include_disabled: true to include nodes marked status = "disabled"
         _outfile: The current output file (sys.stdout or a real file)
+        _warning_disabled: true to disable warnings about driver names not found
         _lines: Stashed list of output lines for outputting in the future
         _aliases: Dict that hold aliases for compatible strings
             key: First compatible string declared in a node
@@ -151,12 +152,13 @@ class DtbPlatdata(object):
                 U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
             value: Driver name declared with U_BOOT_DRIVER(driver_name)
     """
-    def __init__(self, dtb_fname, include_disabled):
+    def __init__(self, dtb_fname, include_disabled, warning_disabled):
         self._fdt = None
         self._dtb_fname = dtb_fname
         self._valid_nodes = None
         self._include_disabled = include_disabled
         self._outfile = None
+        self._warning_disabled = warning_disabled
         self._lines = []
         self._aliases = {}
         self._drivers = []
@@ -184,7 +186,8 @@ class DtbPlatdata(object):
             compat_c_old = compat_c
             compat_c = self._driver_aliases.get(compat_c)
             if not compat_c:
-                print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))
+                if not self._warning_disabled:
+                    print('WARNING: the driver %s was not found in the driver list' % (compat_c_old))
                 compat_c = compat_c_old
             else:
                 aliases_c = [compat_c_old] + aliases_c
@@ -632,7 +635,7 @@ class DtbPlatdata(object):
             nodes_to_output.remove(node)
 
 
-def run_steps(args, dtb_file, include_disabled, output):
+def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False):
     """Run all the steps of the dtoc tool
 
     Args:
@@ -644,7 +647,7 @@ def run_steps(args, dtb_file, include_disabled, output):
     if not args:
         raise ValueError('Please specify a command: struct, platdata')
 
-    plat = DtbPlatdata(dtb_file, include_disabled)
+    plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled)
     plat.scan_drivers()
     plat.scan_dtb()
     plat.scan_tree()
tools/dtoc/dtoc_test_invalid_driver.dts new file +15 -0
new file mode 100644
index 0000000000..914ac3e899
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test device tree file for dtoc
+ *
+ * Copyright 2017 Google, Inc
+ */
+
+/dts-v1/;
+
+/ {
+	spl-test {
+		u-boot,dm-pre-reloc;
+		compatible = "invalid";
+	};
+};
tools/dtoc/test_dtoc.py +62 -29

278 lines not on this page · raw message

Signature · 1 line
2.20.1
#9 lore raw

PATCH v2 4/14 dtoc: add option to disable warnings

Quoted 8 lines · Walter Lozano

As dtoc now performs checks for valid driver names, when running dtoc tests several warnings arise as these tests don't use valid driver names.

This patch adds an option to disable those warning, which is only intended for running tests.

Quoted 7 lines
---
 tools/dtoc/dtb_platdata.py              | 11 +--
 tools/dtoc/dtoc_test_invalid_driver.dts | 15 ++++
 tools/dtoc/test_dtoc.py                 | 91 +++++++++++++++++--------
 3 files changed, 84 insertions(+), 33 deletions(-)
 create mode 100644 tools/dtoc/dtoc_test_invalid_driver.dts
#10 lore raw

PATCH v2 5/14 dm: doc: update of-plat with the support for driver aliases

In reply to Walter Lozano

Update the documentation with the support for driver aliases using U_BOOT_DRIVER_ALIAS.

---
 doc/driver-model/of-plat.rst | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
doc/driver-model/of-plat.rst +13 -1
index 034a68bb4e..376d4409a5 100644
@@ -183,6 +183,17 @@ via U_BOOT_DRIVER(). This effectively means that a U_BOOT_DRIVER() with a
 it to a valid name for C) is needed, so a dedicated driver is required for
 each 'compatible' string.
 
+In order to make this a bit more flexible U_BOOT_DRIVER_ALIAS macro can be
+used to declare an alias for a driver name, typically a 'compatible' string.
+This macro produces no code, but it is by dtoc tool.
+
+During the build process dtoc parses both U_BOOT_DRIVER and U_BOOT_DRIVER_ALIAS
+to build a list of valid driver names and driver aliases. If the 'compatible'
+string used for a device does not not match a valid driver name, it will be
+checked against the list of driver aliases in order to get the right driver
+name to use. If in this step there is no match found a warning is issued to
+avoid run-time failures.
+
 Where a node has multiple compatible strings, a #define is used to make them
 equivalent, e.g.:
 
@@ -269,7 +280,7 @@ For example:
     };
 
     U_BOOT_DRIVER(mmc_drv) = {
-            .name           = "vendor_mmc",  /* matches compatible string */
+            .name           = "mmc_drv",
             .id             = UCLASS_MMC,
             .of_match       = mmc_ids,
             .ofdata_to_platdata = mmc_ofdata_to_platdata,
@@ -278,6 +289,7 @@ For example:
             .platdata_auto_alloc_size = sizeof(struct mmc_platdata),
     };
 
+    U_BOOT_DRIVER_ALIAS(mmc_drv, vendor_mmc) /* matches compatible string */
 
 Note that struct mmc_platdata is defined in the C file, not in a header. This
 is to avoid needing to include dt-structs.h in a header file. The idea is to
Signature · 1 line
2.20.1
#12 lore raw

PATCH v2 6/14 core: drop const for struct driver_info

In reply to Walter Lozano

In order to prepare for a new support of phandle when OF_PLATDATA is used drop the const for struct driver_info as this struct will need to be updated on runtime.

---
 drivers/core/device.c        | 2 +-
 drivers/core/root.c          | 2 +-
 include/dm/device-internal.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/core/device.c +1 -1
index 0157bb1fe0..a0ad080aaf 100644
@@ -246,7 +246,7 @@ int device_bind_ofnode(struct udevice *parent, const struct driver *drv,
 }
 
 int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
-			const struct driver_info *info, struct udevice **devp)
+			struct driver_info *info, struct udevice **devp)
 {
 	struct driver *drv;
 	uint platdata_size = 0;
drivers/core/root.c +1 -1
index 14df16c280..c9ee56478a 100644
@@ -25,7 +25,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static const struct driver_info root_info = {
+static struct driver_info root_info = {
 	.name		= "root_driver",
 };
 
include/dm/device-internal.h +1 -1
index 294d6c1810..5145fb4e14 100644
@@ -81,7 +81,7 @@ int device_bind_with_driver_data(struct udevice *parent,
  * @return 0 if OK, -ve on error
  */
 int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
-			const struct driver_info *info, struct udevice **devp);
+			struct driver_info *info, struct udevice **devp);
 
 /**
  * device_ofdata_to_platdata() - Read platform data for a device
Signature · 1 line
2.20.1
#13 lore raw

PATCH v2 6/14 core: drop const for struct driver_info

Quoted 5 lines · Walter Lozano

In order to prepare for a new support of phandle when OF_PLATDATA is used drop the const for struct driver_info as this struct will need to be updated on runtime.

Quoted 7 lines
---
 drivers/core/device.c        | 2 +-
 drivers/core/root.c          | 2 +-
 include/dm/device-internal.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
#14 lore raw

PATCH v2 7/14 core: extend struct driver_info to point to device

In reply to Walter Lozano

Currently when creating an U_BOOT_DEVICE entry a struct driver_info is declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its struct driver_info.

This patch extends struct driver_info adding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its struct driver_info.

---
 drivers/core/device.c | 26 +++++++++++++++++++++++---
 drivers/core/root.c   |  4 ++++
 include/dm/device.h   | 15 +++++++++++++++
 include/dm/platdata.h | 14 ++++++++++++++
 4 files changed, 56 insertions(+), 3 deletions(-)
drivers/core/device.c +23 -3
index a0ad080aaf..4f8c97a195 100644
@@ -250,6 +250,7 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
 {
 	struct driver *drv;
 	uint platdata_size = 0;
+	int ret;
 
 	drv = lists_driver_lookup_name(info->name);
 	if (!drv)
@@ -260,9 +261,16 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
 #if CONFIG_IS_ENABLED(OF_PLATDATA)
 	platdata_size = info->platdata_size;
 #endif
-	return device_bind_common(parent, drv, info->name,
-			(void *)info->platdata, 0, ofnode_null(), platdata_size,
-			devp);
+	ret = device_bind_common(parent, drv, info->name,
+				 (void *)info->platdata, 0, ofnode_null(),
+				 platdata_size, devp);
+	if (ret)
+		return ret;
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+	info->dev = *devp;
+#endif
+
+	return ret;
 }
 
 static void *alloc_priv(int size, uint flags)
@@ -727,6 +735,18 @@ int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp)
 	return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp);
 }
 
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+int device_get_by_driver_info(const struct driver_info *info,
+			      struct udevice **devp)
+{
+	struct udevice *dev;
+
+	dev = info->dev;
+
+	return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp);
+}
+#endif
+
 int device_find_first_child(const struct udevice *parent, struct udevice **devp)
 {
 	if (list_empty(&parent->child_head)) {
drivers/core/root.c +4 -0
index c9ee56478a..2643ef68a7 100644
@@ -346,6 +346,10 @@ int dm_init_and_scan(bool pre_reloc_only)
 {
 	int ret;
 
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+	dm_populate_phandle_data();
+#endif
+
 	ret = dm_init(IS_ENABLED(CONFIG_OF_LIVE));
 	if (ret) {
 		debug("dm_init() failed: %d\n", ret);
include/dm/device.h +15 -0
index 2cfe10766f..f5738a0cee 100644
@@ -538,6 +538,21 @@ int device_find_global_by_ofnode(ofnode node, struct udevice **devp);
  */
 int device_get_global_by_ofnode(ofnode node, struct udevice **devp);
 
+/**
+ * device_get_by_driver_info() - Get a device based on driver_info
+ *
+ * Locates a device by its struct driver_info, by using its reference which
+ * is updated during the bind process.
+ *
+ * The device is probed to activate it ready for use.
+ *
+ * @info: Struct driver_info
+ * @devp: Returns pointer to device if found, otherwise this is set to NULL
+ * @return 0 if OK, -ve on error
+ */
+int device_get_by_driver_info(const struct driver_info *info,
+			      struct udevice **devp);
+
 /**
  * device_find_first_child() - Find the first child of a device
  *
include/dm/platdata.h +14 -0
index c972fa6936..cab93b071b 100644
@@ -22,12 +22,14 @@
  * @name:	Driver name
  * @platdata:	Driver-specific platform data
  * @platdata_size: Size of platform data structure
+ * @dev:	Device created from this structure data
  */
 struct driver_info {
 	const char *name;
 	const void *platdata;
 #if CONFIG_IS_ENABLED(OF_PLATDATA)
 	uint platdata_size;
+	struct udevice *dev;
 #endif
 };
 
@@ -43,4 +45,16 @@ struct driver_info {
 #define U_BOOT_DEVICES(__name)						\
 	ll_entry_declare_list(struct driver_info, __name, driver_info)
 
+/* Get a pointer to a given driver */
+#define DM_GET_DEVICE(__name)						\
+	ll_entry_get(struct driver_info, __name, driver_info)
+
+/**
+ * dm_populate_phandle_data() - Populates phandle data in platda
+ *
+ * This populates phandle data with an U_BOOT_DEVICE entry get by
+ * DM_GET_DEVICE. The implementation of this function will be done
+ * by dtoc when parsing dtb.
+ */
+void dm_populate_phandle_data(void);
 #endif
Signature · 1 line
2.20.1
#15 lore raw

PATCH v2 7/14 core: extend struct driver_info to point to device

Quoted 10 lines · Walter Lozano

Currently when creating an U_BOOT_DEVICE entry a struct driver_info is declared, which contains the data needed to instantiate the device. However, the actual device is created at runtime and there is no proper way to get the device based on its struct driver_info.

This patch extends struct driver_info adding a pointer to udevice which is populated during the bind process, allowing to generate a set of functions to get the device based on its struct driver_info.

Quoted 8 lines
---
 drivers/core/device.c | 26 +++++++++++++++++++++++---
 drivers/core/root.c   |  4 ++++
 include/dm/device.h   | 15 +++++++++++++++
 include/dm/platdata.h | 14 ++++++++++++++
 4 files changed, 56 insertions(+), 3 deletions(-)
#16 lore raw

PATCH v2 8/14 dtoc: extend dtoc to use struct driver_info when linking nodes

In reply to Walter Lozano

In the current implementation, when dtoc parses a dtb to generate a struct platdata it converts the information related to linked nodes as pointers to struct platdata of destination nodes. By doing this, it makes difficult to get pointer to udevices created based on these information.

This patch extends dtoc to use struct driver_info when populating information about linked nodes, which makes it easier to later get the devices created. In this context, reimplement functions like clk_get_by_index_platdata() which made use of the previous approach.

---
 drivers/clk/clk-uclass.c            | 11 +++++------
 drivers/misc/irq-uclass.c           | 10 ++++------
 drivers/mmc/ftsdc010_mci.c          |  2 +-
 drivers/mmc/rockchip_dw_mmc.c       |  2 +-
 drivers/mmc/rockchip_sdhci.c        |  2 +-
 drivers/ram/rockchip/sdram_rk3399.c |  2 +-
 drivers/spi/rk_spi.c                |  2 +-
 include/clk.h                       |  4 ++--
 tools/dtoc/dtb_platdata.py          | 24 +++++++++++++++++++++---
 9 files changed, 37 insertions(+), 22 deletions(-)
drivers/clk/clk-uclass.c +5 -6
index 71878474eb..412f26cd29 100644
@@ -25,17 +25,16 @@ static inline const struct clk_ops *clk_dev_ops(struct udevice *dev)
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
 # if CONFIG_IS_ENABLED(OF_PLATDATA)
-int clk_get_by_index_platdata(struct udevice *dev, int index,
-			      struct phandle_1_arg *cells, struct clk *clk)
+int clk_get_by_driver_info(struct udevice *dev, struct phandle_1_arg *cells,
+			   struct clk *clk)
 {
 	int ret;
 
-	if (index != 0)
-		return -ENOSYS;
-	ret = uclass_get_device(UCLASS_CLK, 0, &clk->dev);
+	ret = device_get_by_driver_info((struct driver_info *)cells->node,
+					&clk->dev);
 	if (ret)
 		return ret;
-	clk->id = cells[0].arg[0];
+	clk->id = cells->arg[0];
 
 	return 0;
 }
drivers/misc/irq-uclass.c +4 -6
index 61aa10e465..3c38681108 100644
@@ -63,17 +63,15 @@ int irq_read_and_clear(struct irq *irq)
 }
 
 #if CONFIG_IS_ENABLED(OF_PLATDATA)
-int irq_get_by_index_platdata(struct udevice *dev, int index,
-			      struct phandle_1_arg *cells, struct irq *irq)
+int irq_get_by_driver_info(struct udevice *dev,
+			   struct phandle_1_arg *cells, struct irq *irq)
 {
 	int ret;
 
-	if (index != 0)
-		return -ENOSYS;
-	ret = uclass_get_device(UCLASS_IRQ, 0, &irq->dev);
+	ret = device_get_by_driver_info(cells->node, &irq->dev);
 	if (ret)
 		return ret;
-	irq->id = cells[0].arg[0];
+	irq->id = cells->arg[0];
 
 	return 0;
 }
drivers/mmc/ftsdc010_mci.c +1 -1
index 9c15eb36d6..efa92d48be 100644
@@ -437,7 +437,7 @@ static int ftsdc010_mmc_probe(struct udevice *dev)
 	chip->priv = dev;
 	chip->dev_index = 1;
 	memcpy(priv->minmax, dtplat->clock_freq_min_max, sizeof(priv->minmax));
-	ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->clk);
+	ret = clk_get_by_driver_info(dev, dtplat->clocks, &priv->clk);
 	if (ret < 0)
 		return ret;
 #endif
drivers/mmc/rockchip_dw_mmc.c +1 -1
index ac710324c8..80432ddbbc 100644
@@ -120,7 +120,7 @@ static int rockchip_dwmmc_probe(struct udevice *dev)
 	priv->minmax[0] = 400000;  /*  400 kHz */
 	priv->minmax[1] = dtplat->max_frequency;
 
-	ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->clk);
+	ret = clk_get_by_driver_info(dev, dtplat->clocks, &priv->clk);
 	if (ret < 0)
 		return ret;
 #else
drivers/mmc/rockchip_sdhci.c +1 -1
index b440996b26..b073f1a08d 100644
@@ -46,7 +46,7 @@ static int arasan_sdhci_probe(struct udevice *dev)
 	host->name = dev->name;
 	host->ioaddr = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
 	max_frequency = dtplat->max_frequency;
-	ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &clk);
+	ret = clk_get_by_driver_info(dev, dtplat->clocks, &clk);
 #else
 	max_frequency = dev_read_u32_default(dev, "max-frequency", 0);
 	ret = clk_get_by_index(dev, 0, &clk);
drivers/ram/rockchip/sdram_rk3399.c +1 -1
index d69ef01d08..87ec25f893 100644
@@ -3125,7 +3125,7 @@ static int rk3399_dmc_init(struct udevice *dev)
 	      priv->cic, priv->pmugrf, priv->pmusgrf, priv->pmucru, priv->pmu);
 
 #if CONFIG_IS_ENABLED(OF_PLATDATA)
-	ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->ddr_clk);
+	ret = clk_get_by_driver_info(dev, dtplat->clocks, &priv->ddr_clk);
 #else
 	ret = clk_get_by_index(dev, 0, &priv->ddr_clk);
 #endif
drivers/spi/rk_spi.c +1 -1
index 0ac7f767ca..3a85f6d98c 100644
@@ -181,7 +181,7 @@ static int conv_of_platdata(struct udevice *dev)
 
 	plat->base = dtplat->reg[0];
 	plat->frequency = 20000000;
-	ret = clk_get_by_index_platdata(dev, 0, dtplat->clocks, &priv->clk);
+	ret = clk_get_by_driver_info(dev, dtplat->clocks, &priv->clk);
 	if (ret < 0)
 		return ret;
 	dev->req_seq = 0;
include/clk.h +2 -2
index c6a2713f62..a62e2efa2c 100644
@@ -89,8 +89,8 @@ struct clk_bulk {
 
 #if CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(CLK)
 struct phandle_1_arg;
-int clk_get_by_index_platdata(struct udevice *dev, int index,
-			      struct phandle_1_arg *cells, struct clk *clk);
+int clk_get_by_driver_info(struct udevice *dev,
+			   struct phandle_1_arg *cells, struct clk *clk);
 
 /**
  * clk_get_by_index - Get/request a clock by integer index.
tools/dtoc/dtb_platdata.py +21 -3
index 84c39608c3..4262b8687f 100644
@@ -151,6 +151,7 @@ class DtbPlatdata(object):
             key: Driver alias declared with
                 U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
             value: Driver name declared with U_BOOT_DRIVER(driver_name)
+        _links: List of links to be included in dm_populate_phandle_data()
     """
     def __init__(self, dtb_fname, include_disabled, warning_disabled):
         self._fdt = None
@@ -163,6 +164,7 @@ class DtbPlatdata(object):
         self._aliases = {}
         self._drivers = []
         self._driver_aliases = {}
+        self._links = []
 
     def get_normalized_compat_name(self, node):
         """Get a node's normalized compat name
@@ -549,7 +551,7 @@ class DtbPlatdata(object):
         """
         struct_name, _ = self.get_normalized_compat_name(node)
         var_name = conv_name_to_c(node.name)
-        self.buf('static const struct %s%s %s%s = {\n' %
+        self.buf('static struct %s%s %s%s = {\n' %
                  (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))
         for pname in sorted(node.props):
             prop = node.props[pname]
@@ -568,6 +570,7 @@ class DtbPlatdata(object):
                 if info:
                     # Process the list as pairs of (phandle, id)
                     pos = 0
+                    item = 0
                     for args in info.args:
                         phandle_cell = prop.value[pos]
                         phandle = fdt_util.fdt32_to_cpu(phandle_cell)
@@ -577,8 +580,14 @@ class DtbPlatdata(object):
                         for i in range(args):
                             arg_values.append(str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i])))
                         pos += 1 + args
-                        vals.append('\t{&%s%s, {%s}}' % (VAL_PREFIX, name,
-                                                     ', '.join(arg_values)))
+                        # node member is filled with NULL as the real value
+                        # will be update at run-time by dm_populate_phandle_data()
+                        vals.append('\t{NULL, {%s}}' % (', '.join(arg_values)))
+                        var_node = '%s%s.%s[%d].node' % (VAL_PREFIX, var_name, member_name, item)
+                        # Save the the link information to be use to define
+                        # dm_populate_phandle_data()
+                        self._links.append({'var_node': var_node, 'dev_name': name})
+                        item += 1
                     for val in vals:
                         self.buf('\n\t\t%s,' % val)
                 else:
@@ -634,6 +643,15 @@ class DtbPlatdata(object):
             self.output_node(node)
             nodes_to_output.remove(node)
 
+        # Define dm_populate_phandle_data() which will add the linking between
+        # nodes using DM_GET_DEVICE
+        # dtv_dmc_at_xxx.clocks[0].node = DM_GET_DEVICE(clock_controller_at_xxx)
+        self.buf('void dm_populate_phandle_data(void) {\n')
+        for l in self._links:
+            self.buf('\t%s = DM_GET_DEVICE(%s);\n' % (l['var_node'], l['dev_name']))
+        self.buf('}\n')
+
+        self.out(''.join(self.get_buf()))
 
 def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False):
     """Run all the steps of the dtoc tool
Signature · 1 line
2.20.1
#17 lore raw

PATCH v2 8/14 dtoc: extend dtoc to use struct driver_info when linking nodes

Quoted 13 lines · Walter Lozano

In the current implementation, when dtoc parses a dtb to generate a struct platdata it converts the information related to linked nodes as pointers to struct platdata of destination nodes. By doing this, it makes difficult to get pointer to udevices created based on these information.

This patch extends dtoc to use struct driver_info when populating information about linked nodes, which makes it easier to later get the devices created. In this context, reimplement functions like clk_get_by_index_platdata() which made use of the previous approach.

Quoted 11 lines
---
 drivers/clk/clk-uclass.c            | 11 +++++------
 drivers/misc/irq-uclass.c           | 10 ++++------
 drivers/mmc/ftsdc010_mci.c          |  2 +-
 drivers/mmc/rockchip_dw_mmc.c       |  2 +-
 drivers/mmc/rockchip_sdhci.c        |  2 +-
 drivers/ram/rockchip/sdram_rk3399.c |  2 +-
 drivers/spi/rk_spi.c                |  2 +-
 include/clk.h                       |  4 ++--
 tools/dtoc/dtb_platdata.py          | 24 +++++++++++++++++++++---
 9 files changed, 37 insertions(+), 22 deletions(-)

But I think you need to squash something else in here, or make another changes, as 'make qcheck' fails on this commit.

#18 lore raw

PATCH v2 8/14 dtoc: extend dtoc to use struct driver_info when linking nodes

Hi Simon,

Quoted 24 lines · Simon Glass
Quoted 12 lines · Walter Lozano

In the current implementation, when dtoc parses a dtb to generate a struct platdata it converts the information related to linked nodes as pointers to struct platdata of destination nodes. By doing this, it makes difficult to get pointer to udevices created based on these information.

This patch extends dtoc to use struct driver_info when populating information about linked nodes, which makes it easier to later get the devices created. In this context, reimplement functions like clk_get_by_index_platdata() which made use of the previous approach.

Quoted 11 lines
---
  drivers/clk/clk-uclass.c            | 11 +++++------
  drivers/misc/irq-uclass.c           | 10 ++++------
  drivers/mmc/ftsdc010_mci.c          |  2 +-
  drivers/mmc/rockchip_dw_mmc.c       |  2 +-
  drivers/mmc/rockchip_sdhci.c        |  2 +-
  drivers/ram/rockchip/sdram_rk3399.c |  2 +-
  drivers/spi/rk_spi.c                |  2 +-
  include/clk.h                       |  4 ++--
  tools/dtoc/dtb_platdata.py          | 24 +++++++++++++++++++++---
  9 files changed, 37 insertions(+), 22 deletions(-)
Quoted 4 lines

But I think you need to squash something else in here, or make another changes, as 'make qcheck' fails on this commit.

You are right, I will squash the patch which updates the tests.

Regards,

Walter

#19 lore raw

PATCH v2 9/14 dm: doc: update of-plat with new phandle support

In reply to Walter Lozano

Update documentation to reflect the new phandle support when OF_PLATDATA is used. Now phandles are implemented as pointers to U_BOOT_DEVICE, which makes it possible to get a pointer to the actual device.

---
 doc/driver-model/of-plat.rst | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
doc/driver-model/of-plat.rst +16 -8
index 376d4409a5..1e3fad137b 100644
@@ -69,9 +69,8 @@ strictly necessary. Notable problems include:
    - Correct relations between nodes are not implemented. This means that
      parent/child relations (like bus device iteration) do not work yet.
      Some phandles (those that are recognised as such) are converted into
-     a pointer to platform data. This pointer can potentially be used to
-     access the referenced device (by searching for the pointer value).
-     This feature is not yet implemented, however.
+     a pointer to struct driver_info. This pointer can be used to access
+     the referenced device.
 
 
 How it works
@@ -146,10 +145,10 @@ and the following device declaration:
             .clock_freq_min_max     = {0x61a80, 0x8f0d180},
             .vmmc_supply            = 0xb,
             .num_slots              = 0x1,
-            .clocks                 = {{&dtv_clock_controller_at_ff760000, 456},
-                                       {&dtv_clock_controller_at_ff760000, 68},
-                                       {&dtv_clock_controller_at_ff760000, 114},
-                                       {&dtv_clock_controller_at_ff760000, 118}},
+            .clocks                 = {{NULL, 456},
+                                       {NULL, 68},
+                                       {NULL, 114},
+                                       {NULL, 118}},
             .cap_mmc_highspeed      = true,
             .disable_wp             = true,
             .bus_width              = 0x4,
@@ -164,6 +163,13 @@ and the following device declaration:
             .platdata_size  = sizeof(dtv_dwmmc_at_ff0c0000),
     };
 
+    void dm_populate_phandle_data(void) {
+            dtv_dwmmc_at_ff0c0000.clocks[0].node = DM_GET_DEVICE(clock_controller_at_ff760000);
+            dtv_dwmmc_at_ff0c0000.clocks[1].node = DM_GET_DEVICE(clock_controller_at_ff760000);
+            dtv_dwmmc_at_ff0c0000.clocks[2].node = DM_GET_DEVICE(clock_controller_at_ff760000);
+            dtv_dwmmc_at_ff0c0000.clocks[3].node = DM_GET_DEVICE(clock_controller_at_ff760000);
+    }
+
 The device is then instantiated at run-time and the platform data can be
 accessed using:
 
@@ -329,7 +335,9 @@ prevents them being used inadvertently. All usage must be bracketed with
 #if CONFIG_IS_ENABLED(OF_PLATDATA).
 
 The dt-platdata.c file contains the device declarations and is is built in
-spl/dt-platdata.c.
+spl/dt-platdata.c. It additionally contains the definition of
+dm_populate_phandle_data() which is responsible of filling the phandle
+information by adding references to U_BOOT_DEVICE by using DM_GET_DEVICE
 
 The beginnings of a libfdt Python module are provided. So far this only
 implements a subset of the features.
Signature · 1 line
2.20.1
#20 lore raw

PATCH v2 9/14 dm: doc: update of-plat with new phandle support

Quoted 9 lines · Walter Lozano

Update documentation to reflect the new phandle support when OF_PLATDATA is used. Now phandles are implemented as pointers to U_BOOT_DEVICE, which makes it possible to get a pointer to the actual device.

---
 doc/driver-model/of-plat.rst | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
#21 lore raw

PATCH v2 10/14 dtoc: update tests to match new platdata

In reply to Walter Lozano

After using a new approach to link nodes when OF_PLATDATA is enabled the test cases need to be update.

This patch updates the tests based on this new implementation.

---
 tools/dtoc/test_dtoc.py | 103 +++++++++++++++++++++++-----------------
 1 file changed, 60 insertions(+), 43 deletions(-)
tools/dtoc/test_dtoc.py +60 -43
index ae3ec509c1..b13904008a 100755
@@ -48,6 +48,9 @@ C_HEADER = '''/*
 #include <dt-structs.h>
 '''
 
+C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) {
+}
+'''
 
 
 def get_dtb_file(dts_fname, capture_stderr=False):
@@ -167,7 +170,7 @@ class TestDtoc(unittest.TestCase):
         self.run_test(['platdata'], dtb_file, output)
         with open(output) as infile:
             lines = infile.read().splitlines()
-        self.assertEqual(C_HEADER.splitlines() + [''], lines)
+        self.assertEqual(C_HEADER.splitlines() + [''] + C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines)
 
     def test_simple(self):
         """Test output from some simple nodes with various types of data"""
@@ -202,7 +205,7 @@ struct dtd_sandbox_spl_test_2 {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_sandbox_spl_test dtv_spl_test = {
+static struct dtd_sandbox_spl_test dtv_spl_test = {
 \t.boolval\t\t= true,
 \t.bytearray\t\t= {0x6, 0x0, 0x0},
 \t.byteval\t\t= 0x5,
@@ -220,7 +223,7 @@ U_BOOT_DEVICE(spl_test) = {
 \t.platdata_size\t= sizeof(dtv_spl_test),
 };
 
-static const struct dtd_sandbox_spl_test dtv_spl_test2 = {
+static struct dtd_sandbox_spl_test dtv_spl_test2 = {
 \t.bytearray\t\t= {0x1, 0x23, 0x34},
 \t.byteval\t\t= 0x8,
 \t.intarray\t\t= {0x5, 0x0, 0x0, 0x0},
@@ -236,7 +239,7 @@ U_BOOT_DEVICE(spl_test2) = {
 \t.platdata_size\t= sizeof(dtv_spl_test2),
 };
 
-static const struct dtd_sandbox_spl_test dtv_spl_test3 = {
+static struct dtd_sandbox_spl_test dtv_spl_test3 = {
 \t.stringarray\t\t= {"one", "", ""},
 };
 U_BOOT_DEVICE(spl_test3) = {
@@ -245,7 +248,7 @@ U_BOOT_DEVICE(spl_test3) = {
 \t.platdata_size\t= sizeof(dtv_spl_test3),
 };
 
-static const struct dtd_sandbox_spl_test_2 dtv_spl_test4 = {
+static struct dtd_sandbox_spl_test_2 dtv_spl_test4 = {
 };
 U_BOOT_DEVICE(spl_test4) = {
 \t.name\t\t= "sandbox_spl_test_2",
@@ -253,7 +256,7 @@ U_BOOT_DEVICE(spl_test4) = {
 \t.platdata_size\t= sizeof(dtv_spl_test4),
 };
 
-static const struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
+static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
 };
 U_BOOT_DEVICE(i2c_at_0) = {
 \t.name\t\t= "sandbox_i2c_test",
@@ -261,7 +264,7 @@ U_BOOT_DEVICE(i2c_at_0) = {
 \t.platdata_size\t= sizeof(dtv_i2c_at_0),
 };
 
-static const struct dtd_sandbox_pmic_test dtv_pmic_at_9 = {
+static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = {
 \t.low_power\t\t= true,
 \t.reg\t\t\t= {0x9, 0x0},
 };
@@ -271,7 +274,7 @@ U_BOOT_DEVICE(pmic_at_9) = {
 \t.platdata_size\t= sizeof(dtv_pmic_at_9),
 };
 
-''', data)
+''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
 
     def test_driver_alias(self):
         """Test output from a device tree file with a driver alias"""
@@ -293,7 +296,7 @@ struct dtd_sandbox_gpio {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_sandbox_gpio dtv_gpios_at_0 = {
+static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
 \t.gpio_bank_name\t\t= "a",
 \t.gpio_controller\t= true,
 \t.sandbox_gpio_count\t= 0x14,
@@ -304,6 +307,8 @@ U_BOOT_DEVICE(gpios_at_0) = {
 \t.platdata_size\t= sizeof(dtv_gpios_at_0),
 };
 
+void dm_populate_phandle_data(void) {
+}
 ''', data)
 
     def test_invalid_driver(self):
@@ -324,7 +329,7 @@ struct dtd_invalid {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_invalid dtv_spl_test = {
+static struct dtd_invalid dtv_spl_test = {
 };
 U_BOOT_DEVICE(spl_test) = {
 \t.name\t\t= "invalid",
@@ -332,6 +337,8 @@ U_BOOT_DEVICE(spl_test) = {
 \t.platdata_size\t= sizeof(dtv_spl_test),
 };
 
+void dm_populate_phandle_data(void) {
+}
 ''', data)
 
     def test_phandle(self):
@@ -354,7 +361,7 @@ struct dtd_target {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_target dtv_phandle_target = {
+static struct dtd_target dtv_phandle_target = {
 \t.intval\t\t\t= 0x0,
 };
 U_BOOT_DEVICE(phandle_target) = {
@@ -363,7 +370,7 @@ U_BOOT_DEVICE(phandle_target) = {
 \t.platdata_size\t= sizeof(dtv_phandle_target),
 };
 
-static const struct dtd_target dtv_phandle2_target = {
+static struct dtd_target dtv_phandle2_target = {
 \t.intval\t\t\t= 0x1,
 };
 U_BOOT_DEVICE(phandle2_target) = {
@@ -372,7 +379,7 @@ U_BOOT_DEVICE(phandle2_target) = {
 \t.platdata_size\t= sizeof(dtv_phandle2_target),
 };
 
-static const struct dtd_target dtv_phandle3_target = {
+static struct dtd_target dtv_phandle3_target = {
 \t.intval\t\t\t= 0x2,
 };
 U_BOOT_DEVICE(phandle3_target) = {
@@ -381,12 +388,12 @@ U_BOOT_DEVICE(phandle3_target) = {
 \t.platdata_size\t= sizeof(dtv_phandle3_target),
 };
 
-static const struct dtd_source dtv_phandle_source = {
+static struct dtd_source dtv_phandle_source = {
 \t.clocks\t\t\t= {
-\t\t\t{&dtv_phandle_target, {}},
-\t\t\t{&dtv_phandle2_target, {11}},
-\t\t\t{&dtv_phandle3_target, {12, 13}},
-\t\t\t{&dtv_phandle_target, {}},},
+\t\t\t{NULL, {}},
+\t\t\t{NULL, {11}},
+\t\t\t{NULL, {12, 13}},
+\t\t\t{NULL, {}},},
 };
 U_BOOT_DEVICE(phandle_source) = {
 \t.name\t\t= "source",
@@ -394,9 +401,9 @@ U_BOOT_DEVICE(phandle_source) = {
 \t.platdata_size\t= sizeof(dtv_phandle_source),
 };
 
-static const struct dtd_source dtv_phandle_source2 = {
+static struct dtd_source dtv_phandle_source2 = {
 \t.clocks\t\t\t= {
-\t\t\t{&dtv_phandle_target, {}},},
+\t\t\t{NULL, {}},},
 };
 U_BOOT_DEVICE(phandle_source2) = {
 \t.name\t\t= "source",
@@ -404,6 +411,13 @@ U_BOOT_DEVICE(phandle_source2) = {
 \t.platdata_size\t= sizeof(dtv_phandle_source2),
 };
 
+void dm_populate_phandle_data(void) {
+\tdtv_phandle_source.clocks[0].node = DM_GET_DEVICE(phandle_target);
+\tdtv_phandle_source.clocks[1].node = DM_GET_DEVICE(phandle2_target);
+\tdtv_phandle_source.clocks[2].node = DM_GET_DEVICE(phandle3_target);
+\tdtv_phandle_source.clocks[3].node = DM_GET_DEVICE(phandle_target);
+\tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target);
+}
 ''', data)
 
     def test_phandle_single(self):
@@ -430,7 +444,7 @@ struct dtd_target {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_target dtv_phandle_target = {
+static struct dtd_target dtv_phandle_target = {
 };
 U_BOOT_DEVICE(phandle_target) = {
 \t.name\t\t= "target",
@@ -438,9 +452,9 @@ U_BOOT_DEVICE(phandle_target) = {
 \t.platdata_size\t= sizeof(dtv_phandle_target),
 };
 
-static const struct dtd_source dtv_phandle_source2 = {
+static struct dtd_source dtv_phandle_source2 = {
 \t.clocks\t\t\t= {
-\t\t\t{&dtv_phandle_target, {}},},
+\t\t\t{NULL, {}},},
 };
 U_BOOT_DEVICE(phandle_source2) = {
 \t.name\t\t= "source",
@@ -448,6 +462,9 @@ U_BOOT_DEVICE(phandle_source2) = {
 \t.platdata_size\t= sizeof(dtv_phandle_source2),
 };
 
+void dm_populate_phandle_data(void) {
+\tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target);
+}
 ''', data)
 
     def test_phandle_bad(self):
@@ -489,7 +506,7 @@ struct dtd_compat1 {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_compat1 dtv_spl_test = {
+static struct dtd_compat1 dtv_spl_test = {
 \t.intval\t\t\t= 0x1,
 };
 U_BOOT_DEVICE(spl_test) = {
@@ -498,7 +515,7 @@ U_BOOT_DEVICE(spl_test) = {
 \t.platdata_size\t= sizeof(dtv_spl_test),
 };
 
-''', data)
+''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
 
     def test_addresses64(self):
         """Test output from a node with a 'reg' property with na=2, ns=2"""
@@ -523,7 +540,7 @@ struct dtd_test3 {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_test1 dtv_test1 = {
+static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x1234, 0x5678},
 };
 U_BOOT_DEVICE(test1) = {
@@ -532,7 +549,7 @@ U_BOOT_DEVICE(test1) = {
 \t.platdata_size\t= sizeof(dtv_test1),
 };
 
-static const struct dtd_test2 dtv_test2 = {
+static struct dtd_test2 dtv_test2 = {
 \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654},
 };
 U_BOOT_DEVICE(test2) = {
@@ -541,7 +558,7 @@ U_BOOT_DEVICE(test2) = {
 \t.platdata_size\t= sizeof(dtv_test2),
 };
 
-static const struct dtd_test3 dtv_test3 = {
+static struct dtd_test3 dtv_test3 = {
 \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3},
 };
 U_BOOT_DEVICE(test3) = {
@@ -550,7 +567,7 @@ U_BOOT_DEVICE(test3) = {
 \t.platdata_size\t= sizeof(dtv_test3),
 };
 
-''', data)
+''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
 
     def test_addresses32(self):
         """Test output from a node with a 'reg' property with na=1, ns=1"""
@@ -572,7 +589,7 @@ struct dtd_test2 {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_test1 dtv_test1 = {
+static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x1234, 0x5678},
 };
 U_BOOT_DEVICE(test1) = {
@@ -581,7 +598,7 @@ U_BOOT_DEVICE(test1) = {
 \t.platdata_size\t= sizeof(dtv_test1),
 };
 
-static const struct dtd_test2 dtv_test2 = {
+static struct dtd_test2 dtv_test2 = {
 \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3},
 };
 U_BOOT_DEVICE(test2) = {
@@ -590,7 +607,7 @@ U_BOOT_DEVICE(test2) = {
 \t.platdata_size\t= sizeof(dtv_test2),
 };
 
-''', data)
+''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
 
     def test_addresses64_32(self):
         """Test output from a node with a 'reg' property with na=2, ns=1"""
@@ -615,7 +632,7 @@ struct dtd_test3 {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_test1 dtv_test1 = {
+static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x123400000000, 0x5678},
 };
 U_BOOT_DEVICE(test1) = {
@@ -624,7 +641,7 @@ U_BOOT_DEVICE(test1) = {
 \t.platdata_size\t= sizeof(dtv_test1),
 };
 
-static const struct dtd_test2 dtv_test2 = {
+static struct dtd_test2 dtv_test2 = {
 \t.reg\t\t\t= {0x1234567890123456, 0x98765432},
 };
 U_BOOT_DEVICE(test2) = {
@@ -633,7 +650,7 @@ U_BOOT_DEVICE(test2) = {
 \t.platdata_size\t= sizeof(dtv_test2),
 };
 
-static const struct dtd_test3 dtv_test3 = {
+static struct dtd_test3 dtv_test3 = {
 \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3},
 };
 U_BOOT_DEVICE(test3) = {
@@ -642,7 +659,7 @@ U_BOOT_DEVICE(test3) = {
 \t.platdata_size\t= sizeof(dtv_test3),
 };
 
-''', data)
+''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
 
     def test_addresses32_64(self):
         """Test output from a node with a 'reg' property with na=1, ns=2"""
@@ -667,7 +684,7 @@ struct dtd_test3 {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_test1 dtv_test1 = {
+static struct dtd_test1 dtv_test1 = {
 \t.reg\t\t\t= {0x1234, 0x567800000000},
 };
 U_BOOT_DEVICE(test1) = {
@@ -676,7 +693,7 @@ U_BOOT_DEVICE(test1) = {
 \t.platdata_size\t= sizeof(dtv_test1),
 };
 
-static const struct dtd_test2 dtv_test2 = {
+static struct dtd_test2 dtv_test2 = {
 \t.reg\t\t\t= {0x12345678, 0x9876543210987654},
 };
 U_BOOT_DEVICE(test2) = {
@@ -685,7 +702,7 @@ U_BOOT_DEVICE(test2) = {
 \t.platdata_size\t= sizeof(dtv_test2),
 };
 
-static const struct dtd_test3 dtv_test3 = {
+static struct dtd_test3 dtv_test3 = {
 \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3},
 };
 U_BOOT_DEVICE(test3) = {
@@ -694,7 +711,7 @@ U_BOOT_DEVICE(test3) = {
 \t.platdata_size\t= sizeof(dtv_test3),
 };
 
-''', data)
+''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
 
     def test_bad_reg(self):
         """Test that a reg property with an invalid type generates an error"""
@@ -734,7 +751,7 @@ struct dtd_sandbox_spl_test {
         with open(output) as infile:
             data = infile.read()
         self._CheckStrings(C_HEADER + '''
-static const struct dtd_sandbox_spl_test dtv_spl_test = {
+static struct dtd_sandbox_spl_test dtv_spl_test = {
 \t.intval\t\t\t= 0x1,
 };
 U_BOOT_DEVICE(spl_test) = {
@@ -743,7 +760,7 @@ U_BOOT_DEVICE(spl_test) = {
 \t.platdata_size\t= sizeof(dtv_spl_test),
 };
 
-static const struct dtd_sandbox_spl_test dtv_spl_test2 = {
+static struct dtd_sandbox_spl_test dtv_spl_test2 = {
 \t.intarray\t\t= 0x5,
 };
 U_BOOT_DEVICE(spl_test2) = {
@@ -752,7 +769,7 @@ U_BOOT_DEVICE(spl_test2) = {
 \t.platdata_size\t= sizeof(dtv_spl_test2),
 };
 
-''', data)
+''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
 
     def testStdout(self):
         """Test output to stdout"""
Signature · 1 line
2.20.1
#22 lore raw

PATCH v2 10/14 dtoc: update tests to match new platdata

Quoted 10 lines · Walter Lozano

After using a new approach to link nodes when OF_PLATDATA is enabled the test cases need to be update.

This patch updates the tests based on this new implementation.

---
 tools/dtoc/test_dtoc.py | 103 +++++++++++++++++++++++-----------------
 1 file changed, 60 insertions(+), 43 deletions(-)
#23 lore raw

PATCH v2 11/14 sandbox: Move section u_boot_list to make it RW

In reply to Walter Lozano

In order to be able to update data in u_boot_list, move this section to make it RW.

---
 arch/sandbox/cpu/u-boot-spl.lds | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sandbox/cpu/u-boot-spl.lds +1 -1
index de65b01b33..c60eb109b1 100644
@@ -20,4 +20,4 @@ SECTIONS
 	__bss_start = .;
 }
 
-INSERT BEFORE .data;
+INSERT AFTER .data;
Signature · 1 line
2.20.1
#25 lore raw

PATCH v2 12/14 arm: dts: include gpio nodes for card detect

In reply to Walter Lozano

Several MMC drivers use GPIO for card detection with cd-gpios property in the MMC node pointing to a GPIO node. However, as U-Boot tries to save space by keeping only required nodes using u-boot* properties, several devices tree result in having only in the MMC node but not the GPIO node associated to cd-gpios.

This patch, fixes several ocurrence of this issue.

---
 arch/arm/dts/da850-evm-u-boot.dtsi            |  4 ++++
 arch/arm/dts/da850-lcdk-u-boot.dtsi           |  4 ++++
 arch/arm/dts/rk3288-u-boot.dtsi               |  4 ++++
 arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi |  2 +-
 arch/arm/dts/rk3288-veyron-u-boot.dtsi        | 11 +++++++++++
 5 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/rk3288-veyron-u-boot.dtsi
arch/arm/dts/da850-evm-u-boot.dtsi +4 -0
index d9afc5edf4..d588628641 100644
@@ -39,3 +39,7 @@
 &spi1 {
 	u-boot,dm-spl;
 };
+
+&gpio {
+	u-boot,dm-spl;
+};
arch/arm/dts/da850-lcdk-u-boot.dtsi +4 -0
index b372d06ca9..d50775c173 100644
@@ -28,3 +28,7 @@
 &serial2 {
 	u-boot,dm-spl;
 };
+
+&gpio {
+	u-boot,dm-spl;
+};
arch/arm/dts/rk3288-u-boot.dtsi +4 -0
index 6d31735362..51b6e018bd 100644
@@ -43,3 +43,7 @@
 &noc {
 	u-boot,dm-pre-reloc;
 };
+
+&gpio7 {
+	u-boot,dm-pre-reloc;
+};
arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi +1 -1
index eccc069368..251fbdee71 100644
@@ -3,7 +3,7 @@
  * Copyright 2015 Google, Inc
  */
 
-#include "rk3288-u-boot.dtsi"
+#include "rk3288-veyron-u-boot.dtsi"
 
 &dmc {
 	rockchip,pctl-timing = <0x215 0xc8 0x0 0x35 0x26 0x2 0x70 0x2000d
arch/arm/dts/rk3288-veyron-u-boot.dtsi new file +11 -0
new file mode 100644
index 0000000000..899fe6e7a0
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright 2015 Google, Inc
+ */
+
+#include "rk3288-u-boot.dtsi"
+
+&gpio7 {
+	u-boot,dm-pre-reloc;
+};
+
Signature · 1 line
2.20.1
#26 lore raw

PATCH v2 12/14 arm: dts: include gpio nodes for card detect

Quoted 10 lines · Walter Lozano

Several MMC drivers use GPIO for card detection with cd-gpios property in the MMC node pointing to a GPIO node. However, as U-Boot tries to save space by keeping only required nodes using u-boot* properties, several devices tree result in having only in the MMC node but not the GPIO node associated to cd-gpios.

This patch, fixes several ocurrence of this issue.

Quoted 8 lines
---
 arch/arm/dts/da850-evm-u-boot.dtsi            |  4 ++++
 arch/arm/dts/da850-lcdk-u-boot.dtsi           |  4 ++++
 arch/arm/dts/rk3288-u-boot.dtsi               |  4 ++++
 arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi |  2 +-
 arch/arm/dts/rk3288-veyron-u-boot.dtsi        | 11 +++++++++++
 5 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/rk3288-veyron-u-boot.dtsi

This patch did not go out to maintainers. If you are using patman, it should do this automatically.

#27 lore raw

PATCH v2 12/14 arm: dts: include gpio nodes for card detect

Hi Simon,

Quoted 18 lines · Simon Glass
Quoted 9 lines · Walter Lozano

Several MMC drivers use GPIO for card detection with cd-gpios property in the MMC node pointing to a GPIO node. However, as U-Boot tries to save space by keeping only required nodes using u-boot* properties, several devices tree result in having only in the MMC node but not the GPIO node associated to cd-gpios.

This patch, fixes several ocurrence of this issue.

Quoted 8 lines
---
  arch/arm/dts/da850-evm-u-boot.dtsi            |  4 ++++
  arch/arm/dts/da850-lcdk-u-boot.dtsi           |  4 ++++
  arch/arm/dts/rk3288-u-boot.dtsi               |  4 ++++
  arch/arm/dts/rk3288-veyron-speedy-u-boot.dtsi |  2 +-
  arch/arm/dts/rk3288-veyron-u-boot.dtsi        | 11 +++++++++++
  5 files changed, 24 insertions(+), 1 deletion(-)

create mode 100644 arch/arm/dts/rk3288-veyron-u-boot.dtsi

Quoted 4 lines

This patch did not go out to maintainers. If you are using patman, it should do this automatically.

Thanks again. It is a good point to start using patman, I will do.

Regards,

Walter

#28 lore raw

PATCH v2 13/14 dtoc: update dtb_platdata to support cd-gpios

In reply to Walter Lozano

Currently dtoc does not support the property cd-gpios used to declare the gpios for card detect in mmc.

This patch adds support to cd-gpios property.

---
 tools/dtoc/dtb_platdata.py | 13 ++++++++-----
 tools/dtoc/test_dtoc.py    |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
tools/dtoc/dtb_platdata.py +8 -5
index 4262b8687f..831acf3b8a 100644
@@ -257,7 +257,7 @@ class DtbPlatdata(object):
         Return:
             Number of argument cells is this is a phandle, else None
         """
-        if prop.name in ['clocks']:
+        if prop.name in ['clocks', 'cd-gpios']:
             if not isinstance(prop.value, list):
                 prop.value = [prop.value]
             val = prop.value
@@ -277,11 +277,14 @@ class DtbPlatdata(object):
                 if not target:
                     raise ValueError("Cannot parse '%s' in node '%s'" %
                                      (prop.name, node_name))
-                prop_name = '#clock-cells'
-                cells = target.props.get(prop_name)
+                cells = None
+                for prop_name in ['#clock-cells', '#gpio-cells']:
+                    cells = target.props.get(prop_name)
+                    if cells:
+                        break
                 if not cells:
-                    raise ValueError("Node '%s' has no '%s' property" %
-                            (target.name, prop_name))
+                    raise ValueError("Node '%s' has no cells property" %
+                            (target.name))
                 num_args = fdt_util.fdt32_to_cpu(cells.value)
                 max_args = max(max_args, num_args)
                 args.append(num_args)
tools/dtoc/test_dtoc.py +1 -1
index b13904008a..72831dc2df 100755
@@ -484,7 +484,7 @@ void dm_populate_phandle_data(void) {
         output = tools.GetOutputFilename('output')
         with self.assertRaises(ValueError) as e:
             self.run_test(['struct'], dtb_file, output)
-        self.assertIn("Node 'phandle-target' has no '#clock-cells' property",
+        self.assertIn("Node 'phandle-target' has no cells property",
                       str(e.exception))
 
     def test_aliases(self):
Signature · 1 line
2.20.1
#29 lore raw

PATCH v2 13/14 dtoc: update dtb_platdata to support cd-gpios

Quoted 4 lines · Walter Lozano

Currently dtoc does not support the property cd-gpios used to declare the gpios for card detect in mmc.

Quoted 8 lines

This patch adds support to cd-gpios property.

---
 tools/dtoc/dtb_platdata.py | 13 ++++++++-----
 tools/dtoc/test_dtoc.py    |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
#30 lore raw

PATCH v2 14/14 dtoc add test for cd-gpios

In reply to Walter Lozano

Add a test for dtoc taking into account the cd-gpios property.

---
 tools/dtoc/dtoc_test_phandle_cd_gpios.dts | 42 ++++++++++++++
 tools/dtoc/test_dtoc.py                   | 67 +++++++++++++++++++++++
 2 files changed, 109 insertions(+)
 create mode 100644 tools/dtoc/dtoc_test_phandle_cd_gpios.dts
tools/dtoc/dtoc_test_phandle_cd_gpios.dts new file +42 -0
new file mode 100644
index 0000000000..241743e73e
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test device tree file for dtoc
+ *
+ * Copyright 2020 Collabora Ltd.
+ */
+
+/dts-v1/;
+
+/ {
+	phandle: phandle-target {
+		u-boot,dm-pre-reloc;
+		compatible = "target";
+		intval = <0>;
+		#gpio-cells = <0>;
+	};
+
+	phandle_1: phandle2-target {
+		u-boot,dm-pre-reloc;
+		compatible = "target";
+		intval = <1>;
+		#gpio-cells = <1>;
+	};
+	phandle_2: phandle3-target {
+		u-boot,dm-pre-reloc;
+		compatible = "target";
+		intval = <2>;
+		#gpio-cells = <2>;
+	};
+
+	phandle-source {
+		u-boot,dm-pre-reloc;
+		compatible = "source";
+		cd-gpios = <&phandle &phandle_1 11 &phandle_2 12 13 &phandle>;
+	};
+
+	phandle-source2 {
+		u-boot,dm-pre-reloc;
+		compatible = "source";
+		cd-gpios = <&phandle>;
+	};
+};
tools/dtoc/test_dtoc.py +67 -0

73 lines not on this page · raw message

Signature · 1 line
2.20.1
#31 lore raw

PATCH v2 14/14 dtoc add test for cd-gpios

Quoted 9 lines · Walter Lozano

Add a test for dtoc taking into account the cd-gpios property.

---
 tools/dtoc/dtoc_test_phandle_cd_gpios.dts | 42 ++++++++++++++
 tools/dtoc/test_dtoc.py                   | 67 +++++++++++++++++++++++
 2 files changed, 109 insertions(+)
 create mode 100644 tools/dtoc/dtoc_test_phandle_cd_gpios.dts
#32 lore raw

v2 cover improve OF_PLATDATA support

In reply to Walter Lozano

Hi Walter,

Quoted 23 lines · Walter Lozano

When using OF_PLATDATA dtbs are converted to C structs in order to save space as we can remove both dtbs and libraries from TPL/SPL binaries.

This patchset tries to improve its support by overcoming some limitations in the current implementation

First, the support for scan and check for valid driver/aliases is added in order to generate U_BOOT_DEVICE entries with valid driver names.

Secondly, the way information about linked noded (phandle) is generated in C structs is improved in order to make it easier to get a device associated to its data.

Lastly the support for the property cd-gpios is added, which is used to configure the card detection gpio on MMC is added.

This implementation is based in discussion in [1], [2] and [3]

[1] https://patchwork.ozlabs.org/patch/1249198/
[2] https://patchwork.ozlabs.org/project/uboot/list/?series=167495&state=*
[3] https://patchwork.ozlabs.org/project/uboot/list/?series=176759&state=*

Quoted 16 lines

Walter Lozano (14):
drivers: rename drivers to match compatible string
dtoc: add missing code comments
dtoc: add support to scan drivers
dtoc: add option to disable warnings
dm: doc: update of-plat with the support for driver aliases
core: drop const for struct driver_info
core: extend struct driver_info to point to device
dtoc: extend dtoc to use struct driver_info when linking nodes
dm: doc: update of-plat with new phandle support
dtoc: update tests to match new platdata
sandbox: Move section u_boot_list to make it RW
arm: dts: include gpio nodes for card detect
dtoc: update dtb_platdata to support cd-gpios
dtoc add test for cd-gpios

One quick point - can you please check the line lengths in the Python code? It looks like some of the lines are over 80cols. That's OK if you are trying to avoid skipping a string which is the first parameter, but otherwise, it should be possible to avoid it.

Regards,
Simon

#33 lore raw

v2 cover improve OF_PLATDATA support

Quoted 41 lines · Simon Glass

Hi Walter,

Quoted 22 lines · Walter Lozano

When using OF_PLATDATA dtbs are converted to C structs in order to save space as we can remove both dtbs and libraries from TPL/SPL binaries.

This patchset tries to improve its support by overcoming some limitations in the current implementation

First, the support for scan and check for valid driver/aliases is added in order to generate U_BOOT_DEVICE entries with valid driver names.

Secondly, the way information about linked noded (phandle) is generated in C structs is improved in order to make it easier to get a device associated to its data.

Lastly the support for the property cd-gpios is added, which is used to configure the card detection gpio on MMC is added.

This implementation is based in discussion in [1], [2] and [3]

[1] https://patchwork.ozlabs.org/patch/1249198/
[2] https://patchwork.ozlabs.org/project/uboot/list/?series=167495&state=*
[3] https://patchwork.ozlabs.org/project/uboot/list/?series=176759&state=*

Quoted 16 lines

Walter Lozano (14):
drivers: rename drivers to match compatible string
dtoc: add missing code comments
dtoc: add support to scan drivers
dtoc: add option to disable warnings
dm: doc: update of-plat with the support for driver aliases
core: drop const for struct driver_info
core: extend struct driver_info to point to device
dtoc: extend dtoc to use struct driver_info when linking nodes
dm: doc: update of-plat with new phandle support
dtoc: update tests to match new platdata
sandbox: Move section u_boot_list to make it RW
arm: dts: include gpio nodes for card detect
dtoc: update dtb_platdata to support cd-gpios
dtoc add test for cd-gpios

Quoted 5 lines

One quick point - can you please check the line lengths in the Python code? It looks like some of the lines are over 80cols. That's OK if you are trying to avoid skipping a string which is the first parameter, but otherwise, it should be possible to avoid it.

Sure. I thought checkpatch.pl would warn me, but it looks it didn't. Thanks for pointing the issue.

Regards,

Walter