From 53db2eec7aa60b07f11c9d46f12041b571319dbc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:13 -0700 Subject: Makefile: Build a separate .dtb for TPL At present both SPL and TPL use the same devicetree binary. While there is logic to run fdtgrep separately on each one, it does not actually happen. Add a new TPL rule and use that instead. Make this rule conditional on there actually being a TPL. Do the same for SPL for consistency. Note that the SPL and TPL dtbs are build by a Makefule rule used for U-Boot proper. This is the 'dtbs' target in dts/Makefile. So the check for CONFIG_TPL_BUILD in cmd_fdtgrep never actually works at present. We don't support CONFIG_OF_EMBED for TPL at present. Signed-off-by: Simon Glass --- dts/Makefile | 11 ++++++++--- scripts/Makefile.spl | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dts/Makefile b/dts/Makefile index a20930eb9a..4cd65ce73d 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -19,6 +19,9 @@ endif $(obj)/dt-spl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE $(call if_changed,fdtgrep) +$(obj)/dt-tpl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE + $(call if_changed,fdtgrep) + ifeq ($(CONFIG_OF_DTB_PROPS_REMOVE),y) $(obj)/dt.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE $(call if_changed,fdt_rm_props) @@ -27,7 +30,7 @@ $(obj)/dt.dtb: $(DTB) FORCE $(call if_changed,shipped) endif -targets += dt.dtb dt-spl.dtb +targets += dt.dtb dt-spl.dtb dt-tpl.dtb $(DTB): arch-dtbs $(Q)test -e $@ || ( \ @@ -51,10 +54,12 @@ else obj-$(CONFIG_OF_EMBED) := dt.dtb.o endif -dtbs: $(obj)/dt.dtb $(obj)/dt-spl.dtb +dtbs: $(obj)/dt.dtb \ + $(if $(CONFIG_SPL),$(obj)/dt-spl.dtb) \ + $(if $(CONFIG_TPL),$(obj)/dt-tpl.dtb) @: -clean-files := dt.dtb.S dt-spl.dtb.S +clean-files := dt.dtb.S dt-spl.dtb.S dt-tpl.dtb.S # Let clean descend into dts directories subdir- += ../arch/arm/dts ../arch/microblaze/dts ../arch/mips/dts ../arch/sandbox/dts ../arch/x86/dts ../arch/powerpc/dts ../arch/riscv/dts diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index 9f1f7445d7..8ebe6a9840 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -31,8 +31,10 @@ endif ifeq ($(CONFIG_TPL_BUILD),y) SPL_BIN := u-boot-tpl +SPL_NAME := tpl else SPL_BIN := u-boot-spl +SPL_NAME := spl endif ifdef CONFIG_SPL_BUILD @@ -298,7 +300,7 @@ $(obj)/$(SPL_BIN)-pad.bin: $(obj)/$(SPL_BIN) @bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \ dd if=/dev/zero of=$@ bs=1 count=$${bss_size_str} 2>/dev/null; -$(obj)/$(SPL_BIN).dtb: dts/dt-spl.dtb FORCE +$(obj)/$(SPL_BIN).dtb: dts/dt-$(SPL_NAME).dtb FORCE $(call if_changed,copy) pythonpath = PYTHONPATH=scripts/dtc/pylibfdt -- cgit v1.2.3 From de3e372abdb553ff3a79f12830bb90252059f662 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:14 -0700 Subject: Makefile: Build SPL dtbs in the spl/ directory Rather than putting these in the top-level dts/ directory (which is intended for U-Boot proper), put them in the correct subdirectory for SPL (either spl/ or tpl/). This is where other SPL targets are kept, so this is more consistent. Signed-off-by: Simon Glass --- dts/Makefile | 9 +++++---- scripts/Makefile.spl | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dts/Makefile b/dts/Makefile index 4cd65ce73d..c0a953ffac 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -16,10 +16,11 @@ else DTB := arch/$(ARCH)/dts/$(DEVICE_TREE).dtb endif -$(obj)/dt-spl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE +spl/$(obj)/dt-spl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE + mkdir -p $(dir $@) $(call if_changed,fdtgrep) -$(obj)/dt-tpl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE +tpl/$(obj)/dt-tpl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE $(call if_changed,fdtgrep) ifeq ($(CONFIG_OF_DTB_PROPS_REMOVE),y) @@ -55,8 +56,8 @@ obj-$(CONFIG_OF_EMBED) := dt.dtb.o endif dtbs: $(obj)/dt.dtb \ - $(if $(CONFIG_SPL),$(obj)/dt-spl.dtb) \ - $(if $(CONFIG_TPL),$(obj)/dt-tpl.dtb) + $(if $(CONFIG_SPL),spl/$(obj)/dt-spl.dtb) \ + $(if $(CONFIG_TPL),tpl/$(obj)/dt-tpl.dtb) @: clean-files := dt.dtb.S dt-spl.dtb.S dt-tpl.dtb.S diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index 8ebe6a9840..e83e93e5fc 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -300,7 +300,7 @@ $(obj)/$(SPL_BIN)-pad.bin: $(obj)/$(SPL_BIN) @bss_size_str=$(shell $(NM) $< | awk 'BEGIN {size = 0} /__bss_size/ {size = $$1} END {print "ibase=16; " toupper(size)}' | bc); \ dd if=/dev/zero of=$@ bs=1 count=$${bss_size_str} 2>/dev/null; -$(obj)/$(SPL_BIN).dtb: dts/dt-$(SPL_NAME).dtb FORCE +$(obj)/$(SPL_BIN).dtb: $(obj)/dts/dt-$(SPL_NAME).dtb FORCE $(call if_changed,copy) pythonpath = PYTHONPATH=scripts/dtc/pylibfdt -- cgit v1.2.3 From c7674fcb0748a9a15853be7728c3ae887feb75c8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:15 -0700 Subject: Makefile: Tidy up SPL dtb production Use the SPL_NAME variable to simplify the rules. Drop the SPL targets clean-files since the SPL and TPL dts/ directories are removed by existing rules. Move the SPL rules into a new spl_dtbs to avoid the complicated $(if) construct. Also drop unused pieces from the 'targets' variable. With this, SPL and TPL have separate dtbs which respect the various u-boot,dm-spl / u-boot,dm-tpl tags. Signed-off-by: Simon Glass --- dts/Makefile | 18 +++++++++--------- scripts/Makefile.spl | 7 ++++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/dts/Makefile b/dts/Makefile index c0a953ffac..94967cf656 100644 --- a/dts/Makefile +++ b/dts/Makefile @@ -16,13 +16,10 @@ else DTB := arch/$(ARCH)/dts/$(DEVICE_TREE).dtb endif -spl/$(obj)/dt-spl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE +$(obj)/dt-$(SPL_NAME).dtb: dts/dt.dtb $(objtree)/tools/fdtgrep FORCE mkdir -p $(dir $@) $(call if_changed,fdtgrep) -tpl/$(obj)/dt-tpl.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE - $(call if_changed,fdtgrep) - ifeq ($(CONFIG_OF_DTB_PROPS_REMOVE),y) $(obj)/dt.dtb: $(DTB) $(objtree)/tools/fdtgrep FORCE $(call if_changed,fdt_rm_props) @@ -31,7 +28,7 @@ $(obj)/dt.dtb: $(DTB) FORCE $(call if_changed,shipped) endif -targets += dt.dtb dt-spl.dtb dt-tpl.dtb +targets += dt.dtb $(DTB): arch-dtbs $(Q)test -e $@ || ( \ @@ -55,12 +52,15 @@ else obj-$(CONFIG_OF_EMBED) := dt.dtb.o endif -dtbs: $(obj)/dt.dtb \ - $(if $(CONFIG_SPL),spl/$(obj)/dt-spl.dtb) \ - $(if $(CONFIG_TPL),tpl/$(obj)/dt-tpl.dtb) +# Target for U-Boot proper +dtbs: $(obj)/dt.dtb + @: + +# Target for SPL/TPL +spl_dtbs: $(obj)/dt-$(SPL_NAME).dtb @: -clean-files := dt.dtb.S dt-spl.dtb.S dt-tpl.dtb.S +clean-files := dt.dtb.S # Let clean descend into dts directories subdir- += ../arch/arm/dts ../arch/microblaze/dts ../arch/mips/dts ../arch/sandbox/dts ../arch/x86/dts ../arch/powerpc/dts ../arch/riscv/dts diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index e83e93e5fc..c92963833b 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -37,6 +37,8 @@ SPL_BIN := u-boot-spl SPL_NAME := spl endif +export SPL_NAME + ifdef CONFIG_SPL_BUILD SPL_ := SPL_ ifeq ($(CONFIG_TPL_BUILD),y) @@ -459,9 +461,8 @@ endif PHONY += FORCE FORCE: -PHONY += dtbs -dtbs: - $(Q)$(MAKE) $(build)=dts dtbs +$(obj)/dts/dt-$(SPL_NAME).dtb: dts/dt.dtb + $(Q)$(MAKE) $(build)=$(obj)/dts spl_dtbs # Declare the contents of the .PHONY variable as phony. We keep that # information in a variable so we can use it in if_changed and friends. -- cgit v1.2.3 From aa88ac884c998ab521b3a433e963bc001d31e5d8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:16 -0700 Subject: Makefile: Use common args for dtoc At present the dtoc commmand line is repeated twice in the Makefile. Use a variable to avoid this, so it is easier to add more conditional arguments. Signed-off-by: Simon Glass --- scripts/Makefile.spl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index c92963833b..161c15b200 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -307,11 +307,14 @@ $(obj)/$(SPL_BIN).dtb: $(obj)/dts/dt-$(SPL_NAME).dtb FORCE pythonpath = PYTHONPATH=scripts/dtc/pylibfdt +DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \ + -d $(obj)/$(SPL_BIN).dtb + quiet_cmd_dtocc = DTOC C $@ -cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata +cmd_dtocc = $(DTOC_ARGS) -o $@ platdata quiet_cmd_dtoch = DTOC H $@ -cmd_dtoch = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ struct +cmd_dtoch = $(DTOC_ARGS) -o $@ struct quiet_cmd_plat = PLAT $@ cmd_plat = $(CC) $(c_flags) -c $< -o $(filter-out $(PHONY),$@) -- cgit v1.2.3 From d30c7209dfb4c6e4f38f8b42354e44885b53f301 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:18 -0700 Subject: serial: Update NS16550_t and struct NS16550 Typedefs should not be used in U-Boot and structs should be lower case. Update the code to use struct ns16550 consistently. Put a header guard on the file while we are here. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko --- arch/arm/mach-davinci/da850_lowlevel.c | 4 +-- arch/arm/mach-davinci/spl.c | 4 +-- arch/arm/mach-keystone/init.c | 2 +- arch/x86/cpu/apollolake/uart.c | 2 +- arch/x86/cpu/slimbootloader/serial.c | 2 +- board/Arcturus/ucp1020/spl.c | 2 +- board/Arcturus/ucp1020/spl_minimal.c | 6 ++-- board/Synology/ds109/ds109.c | 8 +++--- board/freescale/mpc8313erdb/mpc8313erdb.c | 6 ++-- board/freescale/mpc8315erdb/mpc8315erdb.c | 6 ++-- board/freescale/p1010rdb/spl.c | 2 +- board/freescale/p1010rdb/spl_minimal.c | 8 +++--- board/freescale/p1_p2_rdb_pc/spl.c | 2 +- board/freescale/p1_p2_rdb_pc/spl_minimal.c | 8 +++--- board/freescale/t102xrdb/spl.c | 2 +- board/freescale/t104xrdb/spl.c | 2 +- board/freescale/t208xqds/spl.c | 2 +- board/freescale/t208xrdb/spl.c | 2 +- board/freescale/t4rdb/spl.c | 2 +- drivers/serial/ns16550.c | 44 +++++++++++++++--------------- drivers/serial/serial_coreboot.c | 2 +- drivers/serial/serial_intel_mid.c | 2 +- drivers/serial/serial_ns16550.c | 14 +++++----- drivers/serial/serial_omap.c | 6 ++-- drivers/serial/serial_rockchip.c | 4 +-- include/ns16550.h | 21 ++++++++------ lib/efi/efi_stub.c | 2 +- 27 files changed, 85 insertions(+), 82 deletions(-) diff --git a/arch/arm/mach-davinci/da850_lowlevel.c b/arch/arm/mach-davinci/da850_lowlevel.c index 07bf19b5e4..6994ded2c6 100644 --- a/arch/arm/mach-davinci/da850_lowlevel.c +++ b/arch/arm/mach-davinci/da850_lowlevel.c @@ -290,8 +290,8 @@ int arch_cpu_init(void) board_gpio_init(); #if !CONFIG_IS_ENABLED(DM_SERIAL) - NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM1), - CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); + NS16550_init((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), + CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); #endif /* * Fix Power and Emulation Management Register diff --git a/arch/arm/mach-davinci/spl.c b/arch/arm/mach-davinci/spl.c index 5fea935d6e..3c8330b47f 100644 --- a/arch/arm/mach-davinci/spl.c +++ b/arch/arm/mach-davinci/spl.c @@ -27,9 +27,9 @@ void puts(const char *str) void putc(char c) { if (c == '\n') - NS16550_putc((NS16550_t)(CONFIG_SYS_NS16550_COM1), '\r'); + NS16550_putc((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), '\r'); - NS16550_putc((NS16550_t)(CONFIG_SYS_NS16550_COM1), c); + NS16550_putc((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), c); } #endif /* CONFIG_SPL_LIBCOMMON_SUPPORT */ diff --git a/arch/arm/mach-keystone/init.c b/arch/arm/mach-keystone/init.c index 88e8912959..f4edaaaaac 100644 --- a/arch/arm/mach-keystone/init.c +++ b/arch/arm/mach-keystone/init.c @@ -185,7 +185,7 @@ int arch_cpu_init(void) * driver doesn't handle this. */ #ifndef CONFIG_DM_SERIAL - NS16550_init((NS16550_t)(CONFIG_SYS_NS16550_COM2), + NS16550_init((struct ns16550 *)(CONFIG_SYS_NS16550_COM2), CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); #endif diff --git a/arch/x86/cpu/apollolake/uart.c b/arch/x86/cpu/apollolake/uart.c index 26aef655be..8e6dfdb630 100644 --- a/arch/x86/cpu/apollolake/uart.c +++ b/arch/x86/cpu/apollolake/uart.c @@ -127,7 +127,7 @@ U_BOOT_DRIVER(intel_apl_ns16550) = { .id = UCLASS_SERIAL, .of_match = apl_ns16550_serial_ids, .plat_auto = sizeof(struct ns16550_plat), - .priv_auto = sizeof(struct NS16550), + .priv_auto = sizeof(struct ns16550), .ops = &ns16550_serial_ops, .of_to_plat = apl_ns16550_of_to_plat, .probe = apl_ns16550_probe, diff --git a/arch/x86/cpu/slimbootloader/serial.c b/arch/x86/cpu/slimbootloader/serial.c index 5d8963220d..ebbd2c552f 100644 --- a/arch/x86/cpu/slimbootloader/serial.c +++ b/arch/x86/cpu/slimbootloader/serial.c @@ -59,7 +59,7 @@ U_BOOT_DRIVER(serial_slimbootloader) = { .of_match = slimbootloader_serial_ids, .of_to_plat = slimbootloader_serial_of_to_plat, .plat_auto = sizeof(struct ns16550_plat), - .priv_auto = sizeof(struct NS16550), + .priv_auto = sizeof(struct ns16550), .probe = ns16550_serial_probe, .ops = &ns16550_serial_ops, }; diff --git a/board/Arcturus/ucp1020/spl.c b/board/Arcturus/ucp1020/spl.c index 0fd9532d74..8e607558f4 100644 --- a/board/Arcturus/ucp1020/spl.c +++ b/board/Arcturus/ucp1020/spl.c @@ -58,7 +58,7 @@ void board_init_f(ulong bootflag) bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; gd->bus_clk = bus_clk; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, bus_clk / 16 / CONFIG_BAUDRATE); #ifdef CONFIG_SPL_MMC_BOOT puts("\nSD boot...\n"); diff --git a/board/Arcturus/ucp1020/spl_minimal.c b/board/Arcturus/ucp1020/spl_minimal.c index cd0022a73e..38d84afc9e 100644 --- a/board/Arcturus/ucp1020/spl_minimal.c +++ b/board/Arcturus/ucp1020/spl_minimal.c @@ -34,7 +34,7 @@ void board_init_f(ulong bootflag) plat_ratio >>= 1; gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, gd->bus_clk / 16 / CONFIG_BAUDRATE); puts("\nNAND boot... "); @@ -55,9 +55,9 @@ void board_init_r(gd_t *gd, ulong dest_addr) void putc(char c) { if (c == '\n') - NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r'); + NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r'); - NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c); + NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c); } void puts(const char *str) diff --git a/board/Synology/ds109/ds109.c b/board/Synology/ds109/ds109.c index aa2987d924..c36e4d37fc 100644 --- a/board/Synology/ds109/ds109.c +++ b/board/Synology/ds109/ds109.c @@ -106,10 +106,10 @@ void reset_misc(void) printf("Synology reset..."); udelay(50000); - b_d = ns16550_calc_divisor((NS16550_t)CONFIG_SYS_NS16550_COM2, - CONFIG_SYS_NS16550_CLK, 9600); - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM2, b_d); - NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM2, SOFTWARE_REBOOT); + b_d = ns16550_calc_divisor((struct ns16550 *)CONFIG_SYS_NS16550_COM2, + CONFIG_SYS_NS16550_CLK, 9600); + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM2, b_d); + NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM2, SOFTWARE_REBOOT); } /* Support old kernels */ diff --git a/board/freescale/mpc8313erdb/mpc8313erdb.c b/board/freescale/mpc8313erdb/mpc8313erdb.c index 65a10c345a..69fa89146d 100644 --- a/board/freescale/mpc8313erdb/mpc8313erdb.c +++ b/board/freescale/mpc8313erdb/mpc8313erdb.c @@ -132,7 +132,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) void board_init_f(ulong bootflag) { board_early_init_f(); - NS16550_init((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), + NS16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); puts("NAND boot... "); timer_init(); @@ -152,8 +152,8 @@ void putc(char c) return; if (c == '\n') - NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), '\r'); + NS16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r'); - NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), c); + NS16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c); } #endif diff --git a/board/freescale/mpc8315erdb/mpc8315erdb.c b/board/freescale/mpc8315erdb/mpc8315erdb.c index f8e4599f13..fff8699d61 100644 --- a/board/freescale/mpc8315erdb/mpc8315erdb.c +++ b/board/freescale/mpc8315erdb/mpc8315erdb.c @@ -220,7 +220,7 @@ int checkboard(void) void board_init_f(ulong bootflag) { board_early_init_f(); - NS16550_init((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), + NS16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); puts("NAND boot... "); timer_init(); @@ -240,9 +240,9 @@ void putc(char c) return; if (c == '\n') - NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), '\r'); + NS16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r'); - NS16550_putc((NS16550_t)(CONFIG_SYS_IMMR + 0x4500), c); + NS16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c); } #endif /* CONFIG_NAND_SPL */ diff --git a/board/freescale/p1010rdb/spl.c b/board/freescale/p1010rdb/spl.c index fbaa6a6514..c015a6bf36 100644 --- a/board/freescale/p1010rdb/spl.c +++ b/board/freescale/p1010rdb/spl.c @@ -44,7 +44,7 @@ void board_init_f(ulong bootflag) plat_ratio >>= 1; gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, gd->bus_clk / 16 / CONFIG_BAUDRATE); #ifdef CONFIG_SPL_MMC_BOOT diff --git a/board/freescale/p1010rdb/spl_minimal.c b/board/freescale/p1010rdb/spl_minimal.c index 0bb2c83872..4cc70ea352 100644 --- a/board/freescale/p1010rdb/spl_minimal.c +++ b/board/freescale/p1010rdb/spl_minimal.c @@ -31,8 +31,8 @@ void board_init_f(ulong bootflag) plat_ratio >>= 1; gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, - gd->bus_clk / 16 / CONFIG_BAUDRATE); + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + gd->bus_clk / 16 / CONFIG_BAUDRATE); puts("\nNAND boot... "); @@ -53,9 +53,9 @@ void board_init_r(gd_t *gd, ulong dest_addr) void putc(char c) { if (c == '\n') - NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r'); + NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r'); - NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c); + NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c); } void puts(const char *str) diff --git a/board/freescale/p1_p2_rdb_pc/spl.c b/board/freescale/p1_p2_rdb_pc/spl.c index 8aceceb56a..0b8b8a7575 100644 --- a/board/freescale/p1_p2_rdb_pc/spl.c +++ b/board/freescale/p1_p2_rdb_pc/spl.c @@ -50,7 +50,7 @@ void board_init_f(ulong bootflag) bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; gd->bus_clk = bus_clk; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, bus_clk / 16 / CONFIG_BAUDRATE); #ifdef CONFIG_SPL_MMC_BOOT puts("\nSD boot...\n"); diff --git a/board/freescale/p1_p2_rdb_pc/spl_minimal.c b/board/freescale/p1_p2_rdb_pc/spl_minimal.c index ced5f3c3b5..7068e94a2d 100644 --- a/board/freescale/p1_p2_rdb_pc/spl_minimal.c +++ b/board/freescale/p1_p2_rdb_pc/spl_minimal.c @@ -30,8 +30,8 @@ void board_init_f(ulong bootflag) plat_ratio >>= 1; gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, - gd->bus_clk / 16 / CONFIG_BAUDRATE); + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + gd->bus_clk / 16 / CONFIG_BAUDRATE); puts("\nNAND boot... "); @@ -51,9 +51,9 @@ void board_init_r(gd_t *gd, ulong dest_addr) void putc(char c) { if (c == '\n') - NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r'); + NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r'); - NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c); + NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c); } void puts(const char *str) diff --git a/board/freescale/t102xrdb/spl.c b/board/freescale/t102xrdb/spl.c index 09dd88ac4e..d23b2f5fde 100644 --- a/board/freescale/t102xrdb/spl.c +++ b/board/freescale/t102xrdb/spl.c @@ -82,7 +82,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; ccb_clk = sys_clk * plat_ratio / 2; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, ccb_clk / 16 / CONFIG_BAUDRATE); #if defined(CONFIG_SPL_MMC_BOOT) diff --git a/board/freescale/t104xrdb/spl.c b/board/freescale/t104xrdb/spl.c index e7922954de..a93cc38450 100644 --- a/board/freescale/t104xrdb/spl.c +++ b/board/freescale/t104xrdb/spl.c @@ -81,7 +81,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; uart_clk = sys_clk * plat_ratio / 2; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, uart_clk / 16 / CONFIG_BAUDRATE); relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0); diff --git a/board/freescale/t208xqds/spl.c b/board/freescale/t208xqds/spl.c index d8c2bbe28d..c6b23e4c69 100644 --- a/board/freescale/t208xqds/spl.c +++ b/board/freescale/t208xqds/spl.c @@ -81,7 +81,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; ccb_clk = sys_clk * plat_ratio / 2; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, ccb_clk / 16 / CONFIG_BAUDRATE); #if defined(CONFIG_SPL_MMC_BOOT) diff --git a/board/freescale/t208xrdb/spl.c b/board/freescale/t208xrdb/spl.c index c64bd87115..4b84383016 100644 --- a/board/freescale/t208xrdb/spl.c +++ b/board/freescale/t208xrdb/spl.c @@ -51,7 +51,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; ccb_clk = sys_clk * plat_ratio / 2; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, ccb_clk / 16 / CONFIG_BAUDRATE); #if defined(CONFIG_SPL_MMC_BOOT) diff --git a/board/freescale/t4rdb/spl.c b/board/freescale/t4rdb/spl.c index 9aa0a9b052..efe2b4eb95 100644 --- a/board/freescale/t4rdb/spl.c +++ b/board/freescale/t4rdb/spl.c @@ -60,7 +60,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; ccb_clk = sys_clk * plat_ratio / 2; - NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, + NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, ccb_clk / 16 / CONFIG_BAUDRATE); puts("\nSD boot...\n"); diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 8dd81ad794..d529b1b807 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -156,7 +156,7 @@ static inline int serial_in_dynamic(struct ns16550_plat *plat, u8 *addr) #endif /* CONFIG_NS16550_DYNAMIC */ -static void ns16550_writeb(NS16550_t port, int offset, int value) +static void ns16550_writeb(struct ns16550 *port, int offset, int value) { struct ns16550_plat *plat = port->plat; unsigned char *addr; @@ -170,7 +170,7 @@ static void ns16550_writeb(NS16550_t port, int offset, int value) serial_out_shift(addr, plat->reg_shift, value); } -static int ns16550_readb(NS16550_t port, int offset) +static int ns16550_readb(struct ns16550 *port, int offset) { struct ns16550_plat *plat = port->plat; unsigned char *addr; @@ -184,7 +184,7 @@ static int ns16550_readb(NS16550_t port, int offset) return serial_in_shift(addr, plat->reg_shift); } -static u32 ns16550_getfcr(NS16550_t port) +static u32 ns16550_getfcr(struct ns16550 *port) { struct ns16550_plat *plat = port->plat; @@ -199,20 +199,20 @@ static u32 ns16550_getfcr(NS16550_t port) ns16550_readb(com_port, \ (unsigned char *)addr - (unsigned char *)com_port) #else -static u32 ns16550_getfcr(NS16550_t port) +static u32 ns16550_getfcr(struct ns16550 *port) { return UART_FCR_DEFVAL; } #endif -int ns16550_calc_divisor(NS16550_t port, int clock, int baudrate) +int ns16550_calc_divisor(struct ns16550 *port, int clock, int baudrate) { const unsigned int mode_x_div = 16; return DIV_ROUND_CLOSEST(clock, mode_x_div * baudrate); } -static void NS16550_setbrg(NS16550_t com_port, int baud_divisor) +static void NS16550_setbrg(struct ns16550 *com_port, int baud_divisor) { /* to keep serial format, read lcr before writing BKSE */ int lcr_val = serial_in(&com_port->lcr) & ~UART_LCR_BKSE; @@ -223,7 +223,7 @@ static void NS16550_setbrg(NS16550_t com_port, int baud_divisor) serial_out(lcr_val, &com_port->lcr); } -void NS16550_init(NS16550_t com_port, int baud_divisor) +void NS16550_init(struct ns16550 *com_port, int baud_divisor) { #if (defined(CONFIG_SPL_BUILD) && \ (defined(CONFIG_OMAP34XX) || defined(CONFIG_OMAP44XX))) @@ -272,7 +272,7 @@ void NS16550_init(NS16550_t com_port, int baud_divisor) } #ifndef CONFIG_NS16550_MIN_FUNCTIONS -void NS16550_reinit(NS16550_t com_port, int baud_divisor) +void NS16550_reinit(struct ns16550 *com_port, int baud_divisor) { serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier); NS16550_setbrg(com_port, 0); @@ -282,7 +282,7 @@ void NS16550_reinit(NS16550_t com_port, int baud_divisor) } #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ -void NS16550_putc(NS16550_t com_port, char c) +void NS16550_putc(struct ns16550 *com_port, char c) { while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0) ; @@ -299,7 +299,7 @@ void NS16550_putc(NS16550_t com_port, char c) } #ifndef CONFIG_NS16550_MIN_FUNCTIONS -char NS16550_getc(NS16550_t com_port) +char NS16550_getc(struct ns16550 *com_port) { while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) { #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_TTY) @@ -311,7 +311,7 @@ char NS16550_getc(NS16550_t com_port) return serial_in(&com_port->rbr); } -int NS16550_tstc(NS16550_t com_port) +int NS16550_tstc(struct ns16550 *com_port) { return (serial_in(&com_port->lsr) & UART_LSR_DR) != 0; } @@ -324,7 +324,7 @@ int NS16550_tstc(NS16550_t com_port) static inline void _debug_uart_init(void) { - struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE; + struct ns16550 *com_port = (struct ns16550 *)CONFIG_DEBUG_UART_BASE; int baud_divisor; /* @@ -345,7 +345,7 @@ static inline void _debug_uart_init(void) serial_dout(&com_port->lcr, UART_LCRVAL); } -static inline int NS16550_read_baud_divisor(struct NS16550 *com_port) +static inline int NS16550_read_baud_divisor(struct ns16550 *com_port) { int ret; @@ -359,7 +359,7 @@ static inline int NS16550_read_baud_divisor(struct NS16550 *com_port) static inline void _debug_uart_putc(int ch) { - struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE; + struct ns16550 *com_port = (struct ns16550 *)CONFIG_DEBUG_UART_BASE; while (!(serial_din(&com_port->lsr) & UART_LSR_THRE)) { #ifdef CONFIG_DEBUG_UART_NS16550_CHECK_ENABLED @@ -377,7 +377,7 @@ DEBUG_UART_FUNCS #if CONFIG_IS_ENABLED(DM_SERIAL) static int ns16550_serial_putc(struct udevice *dev, const char ch) { - struct NS16550 *const com_port = dev_get_priv(dev); + struct ns16550 *const com_port = dev_get_priv(dev); if (!(serial_in(&com_port->lsr) & UART_LSR_THRE)) return -EAGAIN; @@ -397,7 +397,7 @@ static int ns16550_serial_putc(struct udevice *dev, const char ch) static int ns16550_serial_pending(struct udevice *dev, bool input) { - struct NS16550 *const com_port = dev_get_priv(dev); + struct ns16550 *const com_port = dev_get_priv(dev); if (input) return (serial_in(&com_port->lsr) & UART_LSR_DR) ? 1 : 0; @@ -407,7 +407,7 @@ static int ns16550_serial_pending(struct udevice *dev, bool input) static int ns16550_serial_getc(struct udevice *dev) { - struct NS16550 *const com_port = dev_get_priv(dev); + struct ns16550 *const com_port = dev_get_priv(dev); if (!(serial_in(&com_port->lsr) & UART_LSR_DR)) return -EAGAIN; @@ -417,7 +417,7 @@ static int ns16550_serial_getc(struct udevice *dev) static int ns16550_serial_setbrg(struct udevice *dev, int baudrate) { - struct NS16550 *const com_port = dev_get_priv(dev); + struct ns16550 *const com_port = dev_get_priv(dev); struct ns16550_plat *plat = com_port->plat; int clock_divisor; @@ -430,7 +430,7 @@ static int ns16550_serial_setbrg(struct udevice *dev, int baudrate) static int ns16550_serial_setconfig(struct udevice *dev, uint serial_config) { - struct NS16550 *const com_port = dev_get_priv(dev); + struct ns16550 *const com_port = dev_get_priv(dev); int lcr_val = UART_LCR_WLS_8; uint parity = SERIAL_GET_PARITY(serial_config); uint bits = SERIAL_GET_BITS(serial_config); @@ -464,7 +464,7 @@ static int ns16550_serial_setconfig(struct udevice *dev, uint serial_config) static int ns16550_serial_getinfo(struct udevice *dev, struct serial_device_info *info) { - struct NS16550 *const com_port = dev_get_priv(dev); + struct ns16550 *const com_port = dev_get_priv(dev); struct ns16550_plat *plat = com_port->plat; info->type = SERIAL_CHIP_16550_COMPATIBLE; @@ -499,7 +499,7 @@ static int ns16550_serial_assign_base(struct ns16550_plat *plat, ulong base) int ns16550_serial_probe(struct udevice *dev) { struct ns16550_plat *plat = dev->plat; - struct NS16550 *const com_port = dev_get_priv(dev); + struct ns16550 *const com_port = dev_get_priv(dev); struct reset_ctl_bulk reset_bulk; fdt_addr_t addr; int ret; @@ -613,7 +613,7 @@ U_BOOT_DRIVER(ns16550_serial) = { .of_to_plat = ns16550_serial_of_to_plat, .plat_auto = sizeof(struct ns16550_plat), #endif - .priv_auto = sizeof(struct NS16550), + .priv_auto = sizeof(struct ns16550), .probe = ns16550_serial_probe, .ops = &ns16550_serial_ops, #if !CONFIG_IS_ENABLED(OF_CONTROL) diff --git a/drivers/serial/serial_coreboot.c b/drivers/serial/serial_coreboot.c index 904e1b306e..88c8209c5d 100644 --- a/drivers/serial/serial_coreboot.c +++ b/drivers/serial/serial_coreboot.c @@ -37,7 +37,7 @@ U_BOOT_DRIVER(coreboot_uart) = { .name = "coreboot_uart", .id = UCLASS_SERIAL, .of_match = coreboot_serial_ids, - .priv_auto = sizeof(struct NS16550), + .priv_auto = sizeof(struct ns16550), .plat_auto = sizeof(struct ns16550_plat), .of_to_plat = coreboot_of_to_plat, .probe = ns16550_serial_probe, diff --git a/drivers/serial/serial_intel_mid.c b/drivers/serial/serial_intel_mid.c index be9bf662fd..bbf19057c4 100644 --- a/drivers/serial/serial_intel_mid.c +++ b/drivers/serial/serial_intel_mid.c @@ -61,7 +61,7 @@ U_BOOT_DRIVER(serial_intel_mid) = { .of_match = mid_serial_ids, .of_to_plat = ns16550_serial_of_to_plat, .plat_auto = sizeof(struct ns16550_plat), - .priv_auto = sizeof(struct NS16550), + .priv_auto = sizeof(struct ns16550), .probe = mid_serial_probe, .ops = &ns16550_serial_ops, }; diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c index ef394b7235..a8d3602e9b 100644 --- a/drivers/serial/serial_ns16550.c +++ b/drivers/serial/serial_ns16550.c @@ -36,34 +36,34 @@ DECLARE_GLOBAL_DATA_PTR; /* Note: The port number specified in the functions is 1 based. * the array is 0 based. */ -static NS16550_t serial_ports[6] = { +static struct ns16550 *serial_ports[6] = { #ifdef CONFIG_SYS_NS16550_COM1 - (NS16550_t)CONFIG_SYS_NS16550_COM1, + (struct ns16550 *)CONFIG_SYS_NS16550_COM1, #else NULL, #endif #ifdef CONFIG_SYS_NS16550_COM2 - (NS16550_t)CONFIG_SYS_NS16550_COM2, + (struct ns16550 *)CONFIG_SYS_NS16550_COM2, #else NULL, #endif #ifdef CONFIG_SYS_NS16550_COM3 - (NS16550_t)CONFIG_SYS_NS16550_COM3, + (struct ns16550 *)CONFIG_SYS_NS16550_COM3, #else NULL, #endif #ifdef CONFIG_SYS_NS16550_COM4 - (NS16550_t)CONFIG_SYS_NS16550_COM4, + (struct ns16550 *)CONFIG_SYS_NS16550_COM4, #else NULL, #endif #ifdef CONFIG_SYS_NS16550_COM5 - (NS16550_t)CONFIG_SYS_NS16550_COM5, + (struct ns16550 *)CONFIG_SYS_NS16550_COM5, #else NULL, #endif #ifdef CONFIG_SYS_NS16550_COM6 - (NS16550_t)CONFIG_SYS_NS16550_COM6 + (struct ns16550 *)CONFIG_SYS_NS16550_COM6 #else NULL #endif diff --git a/drivers/serial/serial_omap.c b/drivers/serial/serial_omap.c index 2f38e1b890..c235215541 100644 --- a/drivers/serial/serial_omap.c +++ b/drivers/serial/serial_omap.c @@ -66,7 +66,7 @@ static inline int serial_in_shift(void *addr, int shift) static inline void _debug_uart_init(void) { - struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE; + struct ns16550 *com_port = (struct ns16550 *)CONFIG_DEBUG_UART_BASE; int baud_divisor; baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK, @@ -85,7 +85,7 @@ static inline void _debug_uart_init(void) static inline void _debug_uart_putc(int ch) { - struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE; + struct ns16550 *com_port = (struct ns16550 *)CONFIG_DEBUG_UART_BASE; while (!(serial_din(&com_port->lsr) & UART_LSR_THRE)) ; @@ -160,7 +160,7 @@ U_BOOT_DRIVER(omap_serial) = { .of_to_plat = omap_serial_of_to_plat, .plat_auto = sizeof(struct ns16550_plat), #endif - .priv_auto = sizeof(struct NS16550), + .priv_auto = sizeof(struct ns16550), .probe = ns16550_serial_probe, .ops = &ns16550_serial_ops, #if !CONFIG_IS_ENABLED(OF_CONTROL) diff --git a/drivers/serial/serial_rockchip.c b/drivers/serial/serial_rockchip.c index 4c0548ed0f..036c07262b 100644 --- a/drivers/serial/serial_rockchip.c +++ b/drivers/serial/serial_rockchip.c @@ -42,7 +42,7 @@ static int rockchip_serial_probe(struct udevice *dev) U_BOOT_DRIVER(rockchip_rk3188_uart) = { .name = "rockchip_rk3188_uart", .id = UCLASS_SERIAL, - .priv_auto = sizeof(struct NS16550), + .priv_auto = sizeof(struct ns16550), .plat_auto = sizeof(struct rockchip_uart_plat), .probe = rockchip_serial_probe, .ops = &ns16550_serial_ops, @@ -52,7 +52,7 @@ U_BOOT_DRIVER(rockchip_rk3188_uart) = { U_BOOT_DRIVER(rockchip_rk3288_uart) = { .name = "rockchip_rk3288_uart", .id = UCLASS_SERIAL, - .priv_auto = sizeof(struct NS16550), + .priv_auto = sizeof(struct ns16550), .plat_auto = sizeof(struct rockchip_uart_plat), .probe = rockchip_serial_probe, .ops = &ns16550_serial_ops, diff --git a/include/ns16550.h b/include/ns16550.h index bef2961032..75c5bf61fd 100644 --- a/include/ns16550.h +++ b/include/ns16550.h @@ -21,6 +21,9 @@ * will not allocate storage for arrays of size 0 */ +#ifndef __ns16550_h +#define __ns16550_h + #include #ifdef CONFIG_DM_SERIAL @@ -82,7 +85,7 @@ struct ns16550_plat { struct udevice; -struct NS16550 { +struct ns16550 { UART_REG(rbr); /* 0 */ UART_REG(ier); /* 1 */ UART_REG(fcr); /* 2 */ @@ -120,8 +123,6 @@ struct NS16550 { #define dll rbr #define dlm ier -typedef struct NS16550 *NS16550_t; - /* * These are the definitions for the FIFO Control Register */ @@ -221,11 +222,11 @@ typedef struct NS16550 *NS16550_t; /* useful defaults for LCR */ #define UART_LCR_8N1 0x03 -void NS16550_init(NS16550_t com_port, int baud_divisor); -void NS16550_putc(NS16550_t com_port, char c); -char NS16550_getc(NS16550_t com_port); -int NS16550_tstc(NS16550_t com_port); -void NS16550_reinit(NS16550_t com_port, int baud_divisor); +void NS16550_init(struct ns16550 *com_port, int baud_divisor); +void NS16550_putc(struct ns16550 *com_port, char c); +char NS16550_getc(struct ns16550 *com_port); +int NS16550_tstc(struct ns16550 *com_port); +void NS16550_reinit(struct ns16550 *com_port, int baud_divisor); /** * ns16550_calc_divisor() - calculate the divisor given clock and baud rate @@ -238,7 +239,7 @@ void NS16550_reinit(NS16550_t com_port, int baud_divisor); * @baudrate: Required baud rate * @return baud rate divisor that should be used */ -int ns16550_calc_divisor(NS16550_t port, int clock, int baudrate); +int ns16550_calc_divisor(struct ns16550 *port, int clock, int baudrate); /** * ns16550_serial_of_to_plat() - convert DT to platform data @@ -266,3 +267,5 @@ int ns16550_serial_probe(struct udevice *dev); * These should be used by the client driver for the driver's 'ops' member */ extern const struct dm_serial_ops ns16550_serial_ops; + +#endif /* __ns16550_h */ diff --git a/lib/efi/efi_stub.c b/lib/efi/efi_stub.c index 7d650d512e..b3393e47fa 100644 --- a/lib/efi/efi_stub.c +++ b/lib/efi/efi_stub.c @@ -67,7 +67,7 @@ void putc(const char ch) putc('\r'); if (use_uart) { - NS16550_t com_port = (NS16550_t)0x3f8; + struct ns16550 *com_port = (struct ns16550 *)0x3f8; while ((inb((ulong)&com_port->lsr) & UART_LSR_THRE) == 0) ; -- cgit v1.2.3 From 2d6bf754ced8fc66cb945d026b66865da4fede85 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:19 -0700 Subject: serial: Rename ns16550 functions to lower case Lower case should be used for function names. Update this driver and its callers accordingly. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko --- arch/arm/mach-davinci/da850_lowlevel.c | 2 +- arch/arm/mach-davinci/spl.c | 4 ++-- arch/arm/mach-keystone/init.c | 2 +- board/Arcturus/ucp1020/spl.c | 2 +- board/Arcturus/ucp1020/spl_minimal.c | 6 +++--- board/Synology/ds109/ds109.c | 5 +++-- board/freescale/mpc8313erdb/mpc8313erdb.c | 6 +++--- board/freescale/mpc8315erdb/mpc8315erdb.c | 6 +++--- board/freescale/p1010rdb/spl.c | 2 +- board/freescale/p1010rdb/spl_minimal.c | 6 +++--- board/freescale/p1_p2_rdb_pc/spl.c | 2 +- board/freescale/p1_p2_rdb_pc/spl_minimal.c | 6 +++--- board/freescale/t102xrdb/spl.c | 2 +- board/freescale/t104xrdb/spl.c | 2 +- board/freescale/t208xqds/spl.c | 2 +- board/freescale/t208xrdb/spl.c | 2 +- board/freescale/t4rdb/spl.c | 2 +- drivers/serial/ns16550.c | 26 +++++++++++++------------- drivers/serial/serial_ns16550.c | 12 ++++++------ include/ns16550.h | 10 +++++----- 20 files changed, 54 insertions(+), 53 deletions(-) diff --git a/arch/arm/mach-davinci/da850_lowlevel.c b/arch/arm/mach-davinci/da850_lowlevel.c index 6994ded2c6..759c93747c 100644 --- a/arch/arm/mach-davinci/da850_lowlevel.c +++ b/arch/arm/mach-davinci/da850_lowlevel.c @@ -290,7 +290,7 @@ int arch_cpu_init(void) board_gpio_init(); #if !CONFIG_IS_ENABLED(DM_SERIAL) - NS16550_init((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), + ns16550_init((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); #endif /* diff --git a/arch/arm/mach-davinci/spl.c b/arch/arm/mach-davinci/spl.c index 3c8330b47f..d0d7a81471 100644 --- a/arch/arm/mach-davinci/spl.c +++ b/arch/arm/mach-davinci/spl.c @@ -27,9 +27,9 @@ void puts(const char *str) void putc(char c) { if (c == '\n') - NS16550_putc((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), '\r'); + ns16550_putc((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), '\r'); - NS16550_putc((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), c); + ns16550_putc((struct ns16550 *)(CONFIG_SYS_NS16550_COM1), c); } #endif /* CONFIG_SPL_LIBCOMMON_SUPPORT */ diff --git a/arch/arm/mach-keystone/init.c b/arch/arm/mach-keystone/init.c index f4edaaaaac..4950f14655 100644 --- a/arch/arm/mach-keystone/init.c +++ b/arch/arm/mach-keystone/init.c @@ -185,7 +185,7 @@ int arch_cpu_init(void) * driver doesn't handle this. */ #ifndef CONFIG_DM_SERIAL - NS16550_init((struct ns16550 *)(CONFIG_SYS_NS16550_COM2), + ns16550_init((struct ns16550 *)(CONFIG_SYS_NS16550_COM2), CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); #endif diff --git a/board/Arcturus/ucp1020/spl.c b/board/Arcturus/ucp1020/spl.c index 8e607558f4..4ed06a80b7 100644 --- a/board/Arcturus/ucp1020/spl.c +++ b/board/Arcturus/ucp1020/spl.c @@ -58,7 +58,7 @@ void board_init_f(ulong bootflag) bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; gd->bus_clk = bus_clk; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, bus_clk / 16 / CONFIG_BAUDRATE); #ifdef CONFIG_SPL_MMC_BOOT puts("\nSD boot...\n"); diff --git a/board/Arcturus/ucp1020/spl_minimal.c b/board/Arcturus/ucp1020/spl_minimal.c index 38d84afc9e..90abec9cce 100644 --- a/board/Arcturus/ucp1020/spl_minimal.c +++ b/board/Arcturus/ucp1020/spl_minimal.c @@ -34,7 +34,7 @@ void board_init_f(ulong bootflag) plat_ratio >>= 1; gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, gd->bus_clk / 16 / CONFIG_BAUDRATE); puts("\nNAND boot... "); @@ -55,9 +55,9 @@ void board_init_r(gd_t *gd, ulong dest_addr) void putc(char c) { if (c == '\n') - NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r'); + ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r'); - NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c); + ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c); } void puts(const char *str) diff --git a/board/Synology/ds109/ds109.c b/board/Synology/ds109/ds109.c index c36e4d37fc..fe3b0eb554 100644 --- a/board/Synology/ds109/ds109.c +++ b/board/Synology/ds109/ds109.c @@ -108,8 +108,9 @@ void reset_misc(void) b_d = ns16550_calc_divisor((struct ns16550 *)CONFIG_SYS_NS16550_COM2, CONFIG_SYS_NS16550_CLK, 9600); - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM2, b_d); - NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM2, SOFTWARE_REBOOT); + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM2, b_d); + ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM2, + SOFTWARE_REBOOT); } /* Support old kernels */ diff --git a/board/freescale/mpc8313erdb/mpc8313erdb.c b/board/freescale/mpc8313erdb/mpc8313erdb.c index 69fa89146d..7e1a31f265 100644 --- a/board/freescale/mpc8313erdb/mpc8313erdb.c +++ b/board/freescale/mpc8313erdb/mpc8313erdb.c @@ -132,7 +132,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) void board_init_f(ulong bootflag) { board_early_init_f(); - NS16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), + ns16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); puts("NAND boot... "); timer_init(); @@ -152,8 +152,8 @@ void putc(char c) return; if (c == '\n') - NS16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r'); + ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r'); - NS16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c); + ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c); } #endif diff --git a/board/freescale/mpc8315erdb/mpc8315erdb.c b/board/freescale/mpc8315erdb/mpc8315erdb.c index fff8699d61..05b983a3f2 100644 --- a/board/freescale/mpc8315erdb/mpc8315erdb.c +++ b/board/freescale/mpc8315erdb/mpc8315erdb.c @@ -220,7 +220,7 @@ int checkboard(void) void board_init_f(ulong bootflag) { board_early_init_f(); - NS16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), + ns16550_init((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), CONFIG_SYS_NS16550_CLK / 16 / CONFIG_BAUDRATE); puts("NAND boot... "); timer_init(); @@ -240,9 +240,9 @@ void putc(char c) return; if (c == '\n') - NS16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r'); + ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), '\r'); - NS16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c); + ns16550_putc((struct ns16550 *)(CONFIG_SYS_IMMR + 0x4500), c); } #endif /* CONFIG_NAND_SPL */ diff --git a/board/freescale/p1010rdb/spl.c b/board/freescale/p1010rdb/spl.c index c015a6bf36..35b95e0838 100644 --- a/board/freescale/p1010rdb/spl.c +++ b/board/freescale/p1010rdb/spl.c @@ -44,7 +44,7 @@ void board_init_f(ulong bootflag) plat_ratio >>= 1; gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, gd->bus_clk / 16 / CONFIG_BAUDRATE); #ifdef CONFIG_SPL_MMC_BOOT diff --git a/board/freescale/p1010rdb/spl_minimal.c b/board/freescale/p1010rdb/spl_minimal.c index 4cc70ea352..989c5b139a 100644 --- a/board/freescale/p1010rdb/spl_minimal.c +++ b/board/freescale/p1010rdb/spl_minimal.c @@ -31,7 +31,7 @@ void board_init_f(ulong bootflag) plat_ratio >>= 1; gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, gd->bus_clk / 16 / CONFIG_BAUDRATE); puts("\nNAND boot... "); @@ -53,9 +53,9 @@ void board_init_r(gd_t *gd, ulong dest_addr) void putc(char c) { if (c == '\n') - NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r'); + ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r'); - NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c); + ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c); } void puts(const char *str) diff --git a/board/freescale/p1_p2_rdb_pc/spl.c b/board/freescale/p1_p2_rdb_pc/spl.c index 0b8b8a7575..b16f701ae1 100644 --- a/board/freescale/p1_p2_rdb_pc/spl.c +++ b/board/freescale/p1_p2_rdb_pc/spl.c @@ -50,7 +50,7 @@ void board_init_f(ulong bootflag) bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; gd->bus_clk = bus_clk; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, bus_clk / 16 / CONFIG_BAUDRATE); #ifdef CONFIG_SPL_MMC_BOOT puts("\nSD boot...\n"); diff --git a/board/freescale/p1_p2_rdb_pc/spl_minimal.c b/board/freescale/p1_p2_rdb_pc/spl_minimal.c index 7068e94a2d..eb3f2c83fa 100644 --- a/board/freescale/p1_p2_rdb_pc/spl_minimal.c +++ b/board/freescale/p1_p2_rdb_pc/spl_minimal.c @@ -30,7 +30,7 @@ void board_init_f(ulong bootflag) plat_ratio >>= 1; gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, gd->bus_clk / 16 / CONFIG_BAUDRATE); puts("\nNAND boot... "); @@ -51,9 +51,9 @@ void board_init_r(gd_t *gd, ulong dest_addr) void putc(char c) { if (c == '\n') - NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r'); + ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, '\r'); - NS16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c); + ns16550_putc((struct ns16550 *)CONFIG_SYS_NS16550_COM1, c); } void puts(const char *str) diff --git a/board/freescale/t102xrdb/spl.c b/board/freescale/t102xrdb/spl.c index d23b2f5fde..66d2f3bda7 100644 --- a/board/freescale/t102xrdb/spl.c +++ b/board/freescale/t102xrdb/spl.c @@ -82,7 +82,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; ccb_clk = sys_clk * plat_ratio / 2; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, ccb_clk / 16 / CONFIG_BAUDRATE); #if defined(CONFIG_SPL_MMC_BOOT) diff --git a/board/freescale/t104xrdb/spl.c b/board/freescale/t104xrdb/spl.c index a93cc38450..28ac12a1fd 100644 --- a/board/freescale/t104xrdb/spl.c +++ b/board/freescale/t104xrdb/spl.c @@ -81,7 +81,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; uart_clk = sys_clk * plat_ratio / 2; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, uart_clk / 16 / CONFIG_BAUDRATE); relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0); diff --git a/board/freescale/t208xqds/spl.c b/board/freescale/t208xqds/spl.c index c6b23e4c69..13e61f083f 100644 --- a/board/freescale/t208xqds/spl.c +++ b/board/freescale/t208xqds/spl.c @@ -81,7 +81,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; ccb_clk = sys_clk * plat_ratio / 2; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, ccb_clk / 16 / CONFIG_BAUDRATE); #if defined(CONFIG_SPL_MMC_BOOT) diff --git a/board/freescale/t208xrdb/spl.c b/board/freescale/t208xrdb/spl.c index 4b84383016..2bba94da7b 100644 --- a/board/freescale/t208xrdb/spl.c +++ b/board/freescale/t208xrdb/spl.c @@ -51,7 +51,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; ccb_clk = sys_clk * plat_ratio / 2; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, ccb_clk / 16 / CONFIG_BAUDRATE); #if defined(CONFIG_SPL_MMC_BOOT) diff --git a/board/freescale/t4rdb/spl.c b/board/freescale/t4rdb/spl.c index efe2b4eb95..fc624efbe6 100644 --- a/board/freescale/t4rdb/spl.c +++ b/board/freescale/t4rdb/spl.c @@ -60,7 +60,7 @@ void board_init_f(ulong bootflag) plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; ccb_clk = sys_clk * plat_ratio / 2; - NS16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, + ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1, ccb_clk / 16 / CONFIG_BAUDRATE); puts("\nSD boot...\n"); diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index d529b1b807..17808fb70a 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -212,7 +212,7 @@ int ns16550_calc_divisor(struct ns16550 *port, int clock, int baudrate) return DIV_ROUND_CLOSEST(clock, mode_x_div * baudrate); } -static void NS16550_setbrg(struct ns16550 *com_port, int baud_divisor) +static void ns16550_setbrg(struct ns16550 *com_port, int baud_divisor) { /* to keep serial format, read lcr before writing BKSE */ int lcr_val = serial_in(&com_port->lcr) & ~UART_LCR_BKSE; @@ -223,7 +223,7 @@ static void NS16550_setbrg(struct ns16550 *com_port, int baud_divisor) serial_out(lcr_val, &com_port->lcr); } -void NS16550_init(struct ns16550 *com_port, int baud_divisor) +void ns16550_init(struct ns16550 *com_port, int baud_divisor) { #if (defined(CONFIG_SPL_BUILD) && \ (defined(CONFIG_OMAP34XX) || defined(CONFIG_OMAP44XX))) @@ -235,13 +235,13 @@ void NS16550_init(struct ns16550 *com_port, int baud_divisor) if ((serial_in(&com_port->lsr) & (UART_LSR_TEMT | UART_LSR_THRE)) == UART_LSR_THRE) { if (baud_divisor != -1) - NS16550_setbrg(com_port, baud_divisor); + ns16550_setbrg(com_port, baud_divisor); else { // Re-use old baud rate divisor to flush transmit reg. const int dll = serial_in(&com_port->dll); const int dlm = serial_in(&com_port->dlm); const int divisor = dll | (dlm << 8); - NS16550_setbrg(com_port, divisor); + ns16550_setbrg(com_port, divisor); } serial_out(0, &com_port->mdr1); } @@ -260,7 +260,7 @@ void NS16550_init(struct ns16550 *com_port, int baud_divisor) /* initialize serial config to 8N1 before writing baudrate */ serial_out(UART_LCRVAL, &com_port->lcr); if (baud_divisor != -1) - NS16550_setbrg(com_port, baud_divisor); + ns16550_setbrg(com_port, baud_divisor); #if defined(CONFIG_ARCH_OMAP2PLUS) || defined(CONFIG_SOC_DA8XX) || \ defined(CONFIG_OMAP_SERIAL) /* /16 is proper to hit 115200 with 48MHz */ @@ -272,17 +272,17 @@ void NS16550_init(struct ns16550 *com_port, int baud_divisor) } #ifndef CONFIG_NS16550_MIN_FUNCTIONS -void NS16550_reinit(struct ns16550 *com_port, int baud_divisor) +void ns16550_reinit(struct ns16550 *com_port, int baud_divisor) { serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier); - NS16550_setbrg(com_port, 0); + ns16550_setbrg(com_port, 0); serial_out(UART_MCRVAL, &com_port->mcr); serial_out(ns16550_getfcr(com_port), &com_port->fcr); - NS16550_setbrg(com_port, baud_divisor); + ns16550_setbrg(com_port, baud_divisor); } #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ -void NS16550_putc(struct ns16550 *com_port, char c) +void ns16550_putc(struct ns16550 *com_port, char c) { while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0) ; @@ -299,7 +299,7 @@ void NS16550_putc(struct ns16550 *com_port, char c) } #ifndef CONFIG_NS16550_MIN_FUNCTIONS -char NS16550_getc(struct ns16550 *com_port) +char ns16550_getc(struct ns16550 *com_port) { while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) { #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_TTY) @@ -311,7 +311,7 @@ char NS16550_getc(struct ns16550 *com_port) return serial_in(&com_port->rbr); } -int NS16550_tstc(struct ns16550 *com_port) +int ns16550_tstc(struct ns16550 *com_port) { return (serial_in(&com_port->lsr) & UART_LSR_DR) != 0; } @@ -423,7 +423,7 @@ static int ns16550_serial_setbrg(struct udevice *dev, int baudrate) clock_divisor = ns16550_calc_divisor(com_port, plat->clock, baudrate); - NS16550_setbrg(com_port, clock_divisor); + ns16550_setbrg(com_port, clock_divisor); return 0; } @@ -520,7 +520,7 @@ int ns16550_serial_probe(struct udevice *dev) reset_deassert_bulk(&reset_bulk); com_port->plat = dev_get_plat(dev); - NS16550_init(com_port, -1); + ns16550_init(com_port, -1); return 0; } diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c index a8d3602e9b..b5beca976d 100644 --- a/drivers/serial/serial_ns16550.c +++ b/drivers/serial/serial_ns16550.c @@ -78,7 +78,7 @@ static struct ns16550 *serial_ports[6] = { int clock_divisor; \ clock_divisor = ns16550_calc_divisor(serial_ports[port-1], \ CONFIG_SYS_NS16550_CLK, gd->baudrate); \ - NS16550_init(serial_ports[port-1], clock_divisor); \ + ns16550_init(serial_ports[port - 1], clock_divisor); \ return 0 ; \ } \ static void eserial##port##_setbrg(void) \ @@ -117,9 +117,9 @@ static struct ns16550 *serial_ports[6] = { static void _serial_putc(const char c, const int port) { if (c == '\n') - NS16550_putc(PORT, '\r'); + ns16550_putc(PORT, '\r'); - NS16550_putc(PORT, c); + ns16550_putc(PORT, c); } static void _serial_puts(const char *s, const int port) @@ -131,12 +131,12 @@ static void _serial_puts(const char *s, const int port) static int _serial_getc(const int port) { - return NS16550_getc(PORT); + return ns16550_getc(PORT); } static int _serial_tstc(const int port) { - return NS16550_tstc(PORT); + return ns16550_tstc(PORT); } static void _serial_setbrg(const int port) @@ -145,7 +145,7 @@ static void _serial_setbrg(const int port) clock_divisor = ns16550_calc_divisor(PORT, CONFIG_SYS_NS16550_CLK, gd->baudrate); - NS16550_reinit(PORT, clock_divisor); + ns16550_reinit(PORT, clock_divisor); } static inline void diff --git a/include/ns16550.h b/include/ns16550.h index 75c5bf61fd..bef2071998 100644 --- a/include/ns16550.h +++ b/include/ns16550.h @@ -222,11 +222,11 @@ struct ns16550 { /* useful defaults for LCR */ #define UART_LCR_8N1 0x03 -void NS16550_init(struct ns16550 *com_port, int baud_divisor); -void NS16550_putc(struct ns16550 *com_port, char c); -char NS16550_getc(struct ns16550 *com_port); -int NS16550_tstc(struct ns16550 *com_port); -void NS16550_reinit(struct ns16550 *com_port, int baud_divisor); +void ns16550_init(struct ns16550 *com_port, int baud_divisor); +void ns16550_putc(struct ns16550 *com_port, char c); +char ns16550_getc(struct ns16550 *com_port); +int ns16550_tstc(struct ns16550 *com_port); +void ns16550_reinit(struct ns16550 *com_port, int baud_divisor); /** * ns16550_calc_divisor() - calculate the divisor given clock and baud rate -- cgit v1.2.3 From acfb5308f5e51fd1f4428618d704ad0de2358871 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:20 -0700 Subject: sandbox: Drop unnecessary test node The spl-test4 node deliberately has an invalid compatible string. This causes a warning from dtoc and the check it does is not really necessary. Drop it, to avoid the warning and associated confusion. Signed-off-by: Simon Glass --- arch/sandbox/dts/sandbox.dtsi | 5 ----- test/py/tests/test_ofplatdata.py | 1 - tools/dtoc/dtoc_test_simple.dts | 5 ----- tools/dtoc/test_dtoc.py | 12 ------------ 4 files changed, 23 deletions(-) diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index 81cdc55b0d..7b4fc94495 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -248,11 +248,6 @@ stringarray = "one"; }; - spl-test4 { - u-boot,dm-pre-reloc; - compatible = "sandbox,spl-test.2"; - }; - spl-test5 { u-boot,dm-tpl; compatible = "sandbox,spl-test"; diff --git a/test/py/tests/test_ofplatdata.py b/test/py/tests/test_ofplatdata.py index 78837a3c00..d55338e37e 100644 --- a/test/py/tests/test_ofplatdata.py +++ b/test/py/tests/test_ofplatdata.py @@ -17,7 +17,6 @@ def test_spl_devicetree(u_boot_console): assert "u-boot,dm-spl" not in output assert "u-boot,dm-tpl" not in output - assert "spl-test4" in output assert "spl-test5" not in output assert "spl-test6" not in output assert "spl-test7" in output diff --git a/tools/dtoc/dtoc_test_simple.dts b/tools/dtoc/dtoc_test_simple.dts index fd168cb593..1c87b89192 100644 --- a/tools/dtoc/dtoc_test_simple.dts +++ b/tools/dtoc/dtoc_test_simple.dts @@ -44,11 +44,6 @@ longbytearray = [09 0a 0b 0c 0d 0e 0f 10]; }; - spl-test4 { - u-boot,dm-pre-reloc; - compatible = "sandbox,spl-test.2"; - }; - i2c@0 { compatible = "sandbox,i2c-test"; u-boot,dm-pre-reloc; diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 4913d95021..49ab75b85d 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -204,8 +204,6 @@ struct dtd_sandbox_spl_test { \tconst char *\tstringarray[3]; \tconst char *\tstringval; }; -struct dtd_sandbox_spl_test_2 { -}; ''', data) self.run_test(['platdata'], dtb_file, output) @@ -286,16 +284,6 @@ U_BOOT_DEVICE(spl_test3) = { \t.parent_idx\t= -1, }; -/* Node /spl-test4 index 5 */ -static struct dtd_sandbox_spl_test_2 dtv_spl_test4 = { -}; -U_BOOT_DEVICE(spl_test4) = { -\t.name\t\t= "sandbox_spl_test_2", -\t.plat\t= &dtv_spl_test4, -\t.plat_size\t= sizeof(dtv_spl_test4), -\t.parent_idx\t= -1, -}; - ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) def test_driver_alias(self): -- cgit v1.2.3 From 38d6b7ebdaee3e0e8426ef1b9df88bdce8ae2e75 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:21 -0700 Subject: spl: Drop bd_info in the data section This uses up space in the SPL binary but it always starts as zero. Also some boards cannot support data in TPL (e.g. Intel Apollo Lake). Use malloc() to allocate this structure instead, by moving the init a little later, after malloc() is inited. Make this function optional since it pulls in malloc(). This reduces the TPL binary size on coral by about 64 bytes Signed-off-by: Simon Glass --- arch/arm/cpu/armv8/fsl-layerscape/spl.c | 5 ++++- common/spl/Kconfig | 9 +++++++++ common/spl/spl.c | 20 ++++++++++++-------- include/spl.h | 10 +++++++++- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/arch/arm/cpu/armv8/fsl-layerscape/spl.c b/arch/arm/cpu/armv8/fsl-layerscape/spl.c index 77724336d6..215ed9759e 100644 --- a/arch/arm/cpu/armv8/fsl-layerscape/spl.c +++ b/arch/arm/cpu/armv8/fsl-layerscape/spl.c @@ -38,6 +38,9 @@ u32 spl_boot_device(void) #ifdef CONFIG_SPL_BUILD +/* Define board data structure */ +static struct bd_info bdata __attribute__ ((section(".data"))); + void spl_board_init(void) { #if defined(CONFIG_NXP_ESBC) && defined(CONFIG_FSL_LSCH2) @@ -74,7 +77,7 @@ void board_init_f(ulong dummy) get_clocks(); preloader_console_init(); - spl_set_bd(); + gd->bd = &bdata; #ifdef CONFIG_SYS_I2C #ifdef CONFIG_SPL_I2C_SUPPORT diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 6d980be0b7..6b0186763b 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -113,6 +113,15 @@ config SPL_FSL_PBL Create boot binary having SPL binary in PBI format concatenated with u-boot binary. +config SPL_ALLOC_BD + bool "Allocate memory for bd_info" + default y if X86 || SANDBOX + help + Some boards don't allocate space for this in their board_init_f() + code. In this case U-Boot can allocate space for gd->bd in the + standard SPL flow (board_init_r()). Enable this option to support + this feature. + endmenu config HANDOFF diff --git a/common/spl/spl.c b/common/spl/spl.c index 63c48fbf33..835c53deaa 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -53,9 +53,6 @@ binman_sym_declare(ulong, spl, image_pos); binman_sym_declare(ulong, spl, size); #endif -/* Define board data structure */ -static struct bd_info bdata __attribute__ ((section(".data"))); - /* * Board-specific Platform code can reimplement show_boot_progress () if needed */ @@ -443,14 +440,19 @@ static int spl_common_init(bool setup_malloc) return 0; } -void spl_set_bd(void) +int spl_alloc_bd(void) { /* * NOTE: On some platforms (e.g. x86) bdata may be in flash and not * writeable. */ - if (!gd->bd) - gd->bd = &bdata; + if (!gd->bd) { + gd->bd = malloc(sizeof(*gd->bd)); + if (!gd->bd) + return -ENOMEM; + } + + return 0; } int spl_early_init(void) @@ -600,8 +602,6 @@ void board_init_r(gd_t *dummy1, ulong dummy2) debug(">>" SPL_TPL_PROMPT "board_init_r()\n"); - spl_set_bd(); - #if defined(CONFIG_SYS_SPL_MALLOC_START) mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START, CONFIG_SYS_SPL_MALLOC_SIZE); @@ -611,6 +611,10 @@ void board_init_r(gd_t *dummy1, ulong dummy2) if (spl_init()) hang(); } + if (IS_ENABLED(CONFIG_SPL_ALLOC_BD) && spl_alloc_bd()) { + puts("Cannot alloc bd\n"); + hang(); + } #if !defined(CONFIG_PPC) && !defined(CONFIG_ARCH_MX6) /* * timer_init() does not exist on PPC systems. The timer is initialized diff --git a/include/spl.h b/include/spl.h index 374a295fa3..a7648787b7 100644 --- a/include/spl.h +++ b/include/spl.h @@ -285,7 +285,15 @@ u32 spl_mmc_boot_mode(const u32 boot_device); * If not overridden, it is weakly defined in common/spl/spl_mmc.c. */ int spl_mmc_boot_partition(const u32 boot_device); -void spl_set_bd(void); + +/** + * spl_alloc_bd() - Allocate space for bd_info + * + * This sets up the gd->bd pointer by allocating memory for it + * + * @return 0 if OK, -ENOMEM if out of memory + */ +int spl_alloc_bd(void); /** * spl_set_header_raw_uboot() - Set up a standard SPL image structure -- cgit v1.2.3 From 45ad176a7608c20162c4bc0895f2f31d0f773379 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:22 -0700 Subject: dm: core: Support dm_dump_all() in SPL At present the output from this function is hard to read in SPL, due to (intended) limitations in SPL's printf() function. Add an SPL version so it is clearer. Signed-off-by: Simon Glass --- drivers/core/dump.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/core/dump.c b/drivers/core/dump.c index 2012547321..7784ec02de 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -14,11 +14,13 @@ static void show_devices(struct udevice *dev, int depth, int last_flag) { int i, is_last; struct udevice *child; + u32 flags = dev->flags; /* print the first 20 characters to not break the tree-format. */ - printf(" %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name, + printf(IS_ENABLED(CONFIG_SPL_BUILD) ? " %s %d [ %c ] %s " : + " %-10.10s %3d [ %c ] %-20.20s ", dev->uclass->uc_drv->name, dev_get_uclass_index(dev, NULL), - dev->flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name); + flags & DM_FLAG_ACTIVATED ? '+' : ' ', dev->driver->name); for (i = depth; i >= 0; i--) { is_last = (last_flag >> i) & 1; -- cgit v1.2.3 From 9c503137b73534c3b5abb90691b4d9675b1cdead Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:23 -0700 Subject: dm: core: Use 'uclass_driver' for the uclass linker_list At present the name 'uclass_driver' is used for the uclass linker list. This does not follow the convention of using the struct name. Fix it. Signed-off-by: Simon Glass --- drivers/core/lists.c | 4 ++-- drivers/core/root.c | 4 ++-- include/dm/uclass.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/core/lists.c b/drivers/core/lists.c index b23ee3030e..426444db3a 100644 --- a/drivers/core/lists.c +++ b/drivers/core/lists.c @@ -39,8 +39,8 @@ struct driver *lists_driver_lookup_name(const char *name) struct uclass_driver *lists_uclass_lookup(enum uclass_id id) { struct uclass_driver *uclass = - ll_entry_start(struct uclass_driver, uclass); - const int n_ents = ll_entry_count(struct uclass_driver, uclass); + ll_entry_start(struct uclass_driver, uclass_driver); + const int n_ents = ll_entry_count(struct uclass_driver, uclass_driver); struct uclass_driver *entry; for (entry = uclass; entry != uclass + n_ents; entry++) { diff --git a/drivers/core/root.c b/drivers/core/root.c index f2fba5883a..9ef242979b 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -86,8 +86,8 @@ void fix_drivers(void) void fix_uclass(void) { struct uclass_driver *uclass = - ll_entry_start(struct uclass_driver, uclass); - const int n_ents = ll_entry_count(struct uclass_driver, uclass); + ll_entry_start(struct uclass_driver, uclass_driver); + const int n_ents = ll_entry_count(struct uclass_driver, uclass_driver); struct uclass_driver *entry; for (entry = uclass; entry != uclass + n_ents; entry++) { diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 91edbfb47d..fde08fe157 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -112,7 +112,7 @@ struct uclass_driver { /* Declare a new uclass_driver */ #define UCLASS_DRIVER(__name) \ - ll_entry_declare(struct uclass_driver, __name, uclass) + ll_entry_declare(struct uclass_driver, __name, uclass_driver) /** * uclass_get() - Get a uclass based on an ID, creating it if needed -- cgit v1.2.3 From 79ea8f749d6cf779706f297fa2ffbc8f384c57de Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:24 -0700 Subject: dm: core: Only include simple-bus devicetree id when needed This is not needed when of-platdata is in use. Update it. Signed-off-by: Simon Glass --- drivers/core/simple-bus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/core/simple-bus.c b/drivers/core/simple-bus.c index c45212a0d3..7dbcbecd94 100644 --- a/drivers/core/simple-bus.c +++ b/drivers/core/simple-bus.c @@ -50,15 +50,17 @@ UCLASS_DRIVER(simple_bus) = { .per_device_plat_auto = sizeof(struct simple_bus_plat), }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id generic_simple_bus_ids[] = { { .compatible = "simple-bus" }, { .compatible = "simple-mfd" }, { } }; +#endif U_BOOT_DRIVER(simple_bus) = { .name = "simple_bus", .id = UCLASS_SIMPLE_BUS, - .of_match = generic_simple_bus_ids, + .of_match = of_match_ptr(generic_simple_bus_ids), .flags = DM_FLAG_PRE_RELOC, }; -- cgit v1.2.3 From c238eeebc91f60e0240f9ab7dff245a4621c5d7a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:25 -0700 Subject: x86: apl: Drop support for !OF_PLATDATA_PARENT This code was kept around after of-platdata started supporting parent devices. That feature seems stable now, so let's drop it. Signed-off-by: Simon Glass --- arch/x86/cpu/apollolake/Kconfig | 1 + arch/x86/cpu/apollolake/spl.c | 28 ---------------------------- drivers/misc/p2sb-uclass.c | 15 --------------- drivers/pinctrl/intel/pinctrl_apl.c | 2 -- 4 files changed, 1 insertion(+), 45 deletions(-) diff --git a/arch/x86/cpu/apollolake/Kconfig b/arch/x86/cpu/apollolake/Kconfig index c6c1350f4f..f5dbd6cbd3 100644 --- a/arch/x86/cpu/apollolake/Kconfig +++ b/arch/x86/cpu/apollolake/Kconfig @@ -19,6 +19,7 @@ config INTEL_APOLLOLAKE select SMP_AP_WORK select INTEL_GMA_SWSMISCI select ACPI_GNVS_EXTERNAL + select TPL_OF_PLATDATA_PARENT imply ENABLE_MRC_CACHE imply AHCI_PCI imply SCSI diff --git a/arch/x86/cpu/apollolake/spl.c b/arch/x86/cpu/apollolake/spl.c index 3a1588bbd8..16a2f15c6b 100644 --- a/arch/x86/cpu/apollolake/spl.c +++ b/arch/x86/cpu/apollolake/spl.c @@ -83,33 +83,6 @@ static int apl_flash_probe(struct udevice *dev) return spi_flash_std_probe(dev); } -/* - * Manually set the parent of the SPI flash to SPI, since dtoc doesn't. We also - * need to allocate the parent_plat since by the time this function is - * called device_bind() has already gone past that step. - */ -static int apl_flash_bind(struct udevice *dev) -{ - if (CONFIG_IS_ENABLED(OF_PLATDATA) && - !CONFIG_IS_ENABLED(OF_PLATDATA_PARENT)) { - struct dm_spi_slave_plat *plat; - struct udevice *spi; - int ret; - - ret = uclass_first_device_err(UCLASS_SPI, &spi); - if (ret) - return ret; - dev->parent = spi; - - plat = calloc(sizeof(*plat), 1); - if (!plat) - return -ENOMEM; - dev->parent_plat = plat; - } - - return 0; -} - static const struct dm_spi_flash_ops apl_flash_ops = { .read = apl_flash_std_read, }; @@ -123,7 +96,6 @@ U_BOOT_DRIVER(winbond_w25q128fw) = { .name = "winbond_w25q128fw", .id = UCLASS_SPI_FLASH, .of_match = apl_flash_ids, - .bind = apl_flash_bind, .probe = apl_flash_probe, .priv_auto = sizeof(struct spi_flash), .ops = &apl_flash_ops, diff --git a/drivers/misc/p2sb-uclass.c b/drivers/misc/p2sb-uclass.c index 8f9ec027a2..ac2852559f 100644 --- a/drivers/misc/p2sb-uclass.c +++ b/drivers/misc/p2sb-uclass.c @@ -168,26 +168,11 @@ int p2sb_get_port_id(struct udevice *dev) int p2sb_set_port_id(struct udevice *dev, int portid) { - struct udevice *ps2b; struct p2sb_child_plat *pplat; if (!CONFIG_IS_ENABLED(OF_PLATDATA)) return -ENOSYS; - if (!CONFIG_IS_ENABLED(OF_PLATDATA_PARENT)) { - uclass_find_first_device(UCLASS_P2SB, &ps2b); - if (!ps2b) - return -EDEADLK; - dev->parent = ps2b; - - /* - * We must allocate this, since when the device was bound it did - * not have a parent. - */ - dev->parent_plat = malloc(sizeof(*pplat)); - if (!dev->parent_plat) - return -ENOMEM; - } pplat = dev_get_parent_plat(dev); pplat->pid = portid; diff --git a/drivers/pinctrl/intel/pinctrl_apl.c b/drivers/pinctrl/intel/pinctrl_apl.c index 48b0e9a161..2bb654c8a1 100644 --- a/drivers/pinctrl/intel/pinctrl_apl.c +++ b/drivers/pinctrl/intel/pinctrl_apl.c @@ -152,8 +152,6 @@ static int apl_pinctrl_of_to_plat(struct udevice *dev) * linker list (i.e. alphabetical order by driver name). So the GPIO * device may well be bound before its parent (p2sb), and this call * will fail if p2sb is not bound yet. - * - * TODO(sjg@chromium.org): Add a parent pointer to child devices in dtoc */ ret = p2sb_set_port_id(dev, plat->dtplat.intel_p2sb_port_id); if (ret) -- cgit v1.2.3 From 806473933adf52740864ab6cdab8c90a84c0b1f3 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:26 -0700 Subject: dm: core: Add function to access uclass priv Add functions so this information is not accessed directly. This will be needed for of-platdata which stores it in a different place. Signed-off-by: Simon Glass --- drivers/core/uclass.c | 10 ++++++++++ include/dm/uclass-internal.h | 14 ++++++++++++++ include/dm/uclass.h | 8 ++++++++ 3 files changed, 32 insertions(+) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 6409457fa9..5e24927b34 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -160,6 +160,16 @@ const char *uclass_get_name(enum uclass_id id) return uc->uc_drv->name; } +void *uclass_get_priv(const struct uclass *uc) +{ + return uc->priv; +} + +void uclass_set_priv(struct uclass *uc, void *priv) +{ + uc->priv = priv; +} + enum uclass_id uclass_get_by_name(const char *name) { int i; diff --git a/include/dm/uclass-internal.h b/include/dm/uclass-internal.h index 3e052f95d3..c5a464be7c 100644 --- a/include/dm/uclass-internal.h +++ b/include/dm/uclass-internal.h @@ -11,6 +11,20 @@ #include +/** + * uclass_set_priv() - Set the private data for a uclass + * + * This is normally handled by driver model, which automatically allocates + * private data when an 'auto' size if provided by the uclass driver. + * + * Use this function to override normal operation for special situations, such + * as needing to allocate a variable amount of data. + * + * @uc Uclass to update + * @priv New private-data pointer + */ +void uclass_set_priv(struct uclass *uc, void *priv); + /** * uclass_find_next_free_seq() - Get the next free sequence number * diff --git a/include/dm/uclass.h b/include/dm/uclass.h index fde08fe157..20d4b9e683 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -114,6 +114,14 @@ struct uclass_driver { #define UCLASS_DRIVER(__name) \ ll_entry_declare(struct uclass_driver, __name, uclass_driver) +/** + * uclass_get_priv() - Get the private data for a uclass + * + * @uc Uclass to check + * @return private data, or NULL if none + */ +void *uclass_get_priv(const struct uclass *uc); + /** * uclass_get() - Get a uclass based on an ID, creating it if needed * -- cgit v1.2.3 From 12559f5bab3e43b603dccfa6c354ffd7da03249c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:27 -0700 Subject: dm: core: Add functions to set priv/plat This should not normally be needed in drivers, but add accessors for the few cases that exist. Signed-off-by: Simon Glass --- drivers/core/device.c | 30 ++++++++++++++++ include/dm/device-internal.h | 84 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index d1a08ce783..f2d750c8de 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -959,6 +959,36 @@ int device_set_name(struct udevice *dev, const char *name) return 0; } +void dev_set_priv(struct udevice *dev, void *priv) +{ + dev->priv = priv; +} + +void dev_set_parent_priv(struct udevice *dev, void *parent_priv) +{ + dev->parent_priv = parent_priv; +} + +void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv) +{ + dev->uclass_priv = uclass_priv; +} + +void dev_set_plat(struct udevice *dev, void *plat) +{ + dev->plat = plat; +} + +void dev_set_parent_plat(struct udevice *dev, void *parent_plat) +{ + dev->parent_plat = parent_plat; +} + +void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat) +{ + dev->uclass_plat = uclass_plat; +} + #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) bool device_is_compatible(const struct udevice *dev, const char *compat) { diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index af3b6b2b05..03b092bdf7 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -189,6 +189,90 @@ static inline int device_chld_remove(struct udevice *dev, struct driver *drv, } #endif +/** + * dev_set_priv() - Set the private data for a device + * + * This is normally handled by driver model, which automatically allocates + * private data when an 'auto' size if provided by the driver. + * + * Use this function to override normal operation for special situations, such + * as needing to allocate a variable amount of data. + * + * @dev Device to check + * @priv New private-data pointer + */ +void dev_set_priv(struct udevice *dev, void *priv); + +/** + * dev_set_parent_priv() - Set the parent-private data for a device + * + * This is normally handled by driver model, which automatically allocates + * parent-private data when an 'auto' size if provided by the driver. + * + * Use this function to override normal operation for special situations, such + * as needing to allocate a variable amount of data. + * + * @dev: Device to update + * @parent_priv: New parent-private data + */ +void dev_set_parent_priv(struct udevice *dev, void *parent_priv); + +/** + * dev_set_uclass_priv() - Set the uclass private data for a device + * + * This is normally handled by driver model, which automatically allocates + * uclass-private data when an 'auto' size if provided by the driver. + * + * Use this function to override normal operation for special situations, such + * as needing to allocate a variable amount of data. + * + * @dev: Device to update + * @uclass_priv: New uclass private data + */ +void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv); + +/** + * dev_set_plat() - Set the platform data for a device + * + * This is normally handled by driver model, which automatically allocates + * platform data when an 'auto' size if provided by the driver. + * + * Use this function to override normal operation for special situations, such + * as needing to allocate a variable amount of data. + * + * @dev Device to check + * @plat New platform-data pointer + */ +void dev_set_plat(struct udevice *dev, void *priv); + +/** + * dev_set_parent_plat() - Set the parent platform data for a device + * + * This is normally handled by driver model, which automatically allocates + * parent platform data when an 'auto' size if provided by the driver. + * + * Use this function to override normal operation for special situations, such + * as needing to allocate a variable amount of data. + * + * @dev: Device to update + * @parent_plat: New parent platform data + */ +void dev_set_parent_plat(struct udevice *dev, void *parent_plat); + +/** + * dev_set_uclass_plat() - Set the uclass platform data for a device + * + * This is normally handled by driver model, which automatically allocates + * uclass platform data when an 'auto' size if provided by the driver. + * + * Use this function to override normal operation for special situations, such + * as needing to allocate a variable amount of data. + * + * @dev: Device to update + * @uclass_plat: New uclass platform data + */ +void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat); + /** * simple_bus_translate() - translate a bus address to a system address * -- cgit v1.2.3 From 0fd3d91152df5bb6c5f7b9ee68f01a9a1c9a875d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:28 -0700 Subject: dm: Use access methods for dev/uclass private data Most drivers use these access methods but a few do not. Update them. In some cases the access is not permitted, so mark those with a FIXME tag for the maintainer to check. Signed-off-by: Simon Glass Acked-by: Andy Shevchenko Acked-by: Pratyush Yadav --- arch/arm/cpu/armv7/ls102xa/fdt.c | 4 +++ arch/arm/mach-stm32mp/pwr_regulator.c | 3 +- arch/x86/cpu/apollolake/uart.c | 3 +- arch/x86/cpu/slimbootloader/serial.c | 2 +- drivers/clk/clk.c | 4 ++- drivers/clk/clk_fixed_rate.c | 4 ++- drivers/clk/rockchip/clk_px30.c | 3 +- drivers/clk/rockchip/clk_rk3036.c | 3 +- drivers/clk/rockchip/clk_rk3128.c | 3 +- drivers/clk/rockchip/clk_rk3188.c | 2 +- drivers/clk/rockchip/clk_rk322x.c | 3 +- drivers/clk/rockchip/clk_rk3288.c | 2 +- drivers/clk/rockchip/clk_rk3308.c | 3 +- drivers/clk/rockchip/clk_rk3328.c | 3 +- drivers/clk/rockchip/clk_rk3368.c | 3 +- drivers/clk/rockchip/clk_rk3399.c | 3 +- drivers/clk/rockchip/clk_rv1108.c | 3 +- drivers/core/device-remove.c | 16 +++++------ drivers/ddr/altera/sdram_agilex.c | 2 +- drivers/ddr/altera/sdram_gen5.c | 4 +-- drivers/ddr/altera/sdram_s10.c | 2 +- drivers/ddr/altera/sdram_soc64.c | 2 +- drivers/gpio/dwapb_gpio.c | 2 +- drivers/gpio/gpio-uclass.c | 2 +- drivers/gpio/hi6220_gpio.c | 2 +- drivers/gpio/imx_rgpio2p.c | 5 ++-- drivers/gpio/lpc32xx_gpio.c | 2 +- drivers/gpio/mt7621_gpio.c | 2 +- drivers/gpio/mxs_gpio.c | 2 +- drivers/gpio/omap_gpio.c | 3 +- drivers/gpio/s5p_gpio.c | 6 ++-- drivers/gpio/sandbox.c | 6 ++-- drivers/gpio/sunxi_gpio.c | 2 +- drivers/gpio/tegra186_gpio.c | 6 ++-- drivers/gpio/tegra_gpio.c | 6 ++-- drivers/misc/altera_sysid.c | 2 +- drivers/misc/cros_ec_sandbox.c | 4 +-- drivers/misc/fs_loader.c | 6 ++-- drivers/misc/vexpress_config.c | 2 +- drivers/mmc/arm_pl180_mmci.c | 6 ++-- drivers/mmc/mxsmmc.c | 2 +- drivers/mmc/octeontx_hsmmc.c | 17 ++++++++---- drivers/mux/mmio.c | 3 +- drivers/net/eth-phy-uclass.c | 4 +-- drivers/net/fm/eth.c | 22 ++++++++++++--- drivers/net/fsl_mcdmafec.c | 10 +++---- drivers/net/mcffec.c | 12 ++++---- drivers/net/mcfmii.c | 8 ++++++ drivers/net/pfe_eth/pfe_eth.c | 2 +- drivers/net/sunxi_emac.c | 2 +- drivers/net/tsec.c | 46 +++++++++++++++++++++++-------- drivers/net/xilinx_emaclite.c | 2 +- drivers/pci/pci-emul-uclass.c | 4 +-- drivers/pci/pci-uclass.c | 8 +++--- drivers/pinctrl/pinctrl-qe-io.c | 4 +-- drivers/pinctrl/pinctrl-single.c | 6 ++-- drivers/power/regulator/da9063.c | 24 ++++++++-------- drivers/power/regulator/pbias_regulator.c | 3 +- drivers/remoteproc/rproc-uclass.c | 4 +-- drivers/reset/reset-mediatek.c | 3 +- drivers/reset/reset-rockchip.c | 3 +- drivers/reset/reset-sifive.c | 3 +- drivers/reset/reset-sunxi.c | 3 +- drivers/serial/altera_jtag_uart.c | 8 +++--- drivers/serial/altera_uart.c | 8 +++--- drivers/serial/atmel_usart.c | 2 +- drivers/serial/ns16550.c | 4 +-- drivers/serial/sandbox.c | 6 ++-- drivers/serial/serial_arc.c | 8 +++--- drivers/serial/serial_linflexuart.c | 2 +- drivers/serial/serial_lpuart.c | 10 +++---- drivers/serial/serial_mcf.c | 10 +++---- drivers/serial/serial_meson.c | 12 ++++---- drivers/serial/serial_mxc.c | 12 ++++---- drivers/serial/serial_omap.c | 2 +- drivers/serial/serial_pxa.c | 10 +++---- drivers/serial/serial_rockchip.c | 3 +- drivers/serial/serial_s5p.c | 12 ++++---- drivers/spi/cadence_qspi.c | 12 ++++---- drivers/spi/cf_spi.c | 2 +- drivers/spi/davinci_spi.c | 4 +-- drivers/spi/designware_spi.c | 4 +-- drivers/spi/exynos_spi.c | 4 +-- drivers/spi/fsl_dspi.c | 4 +-- drivers/spi/fsl_espi.c | 2 +- drivers/spi/fsl_qspi.c | 2 +- drivers/spi/mxs_spi.c | 2 +- drivers/spi/pl022_spi.c | 2 +- drivers/spi/rk_spi.c | 6 ++-- drivers/spi/soft_spi.c | 4 +-- drivers/spi/tegra114_spi.c | 4 +-- drivers/spi/tegra20_sflash.c | 4 +-- drivers/spi/tegra20_slink.c | 4 +-- drivers/spi/tegra210_qspi.c | 4 +-- drivers/spi/uniphier_spi.c | 8 +++--- drivers/spi/zynq_qspi.c | 4 +-- drivers/spi/zynq_spi.c | 8 +++--- drivers/spi/zynqmp_gqspi.c | 6 ++-- drivers/timer/ag101p_timer.c | 4 +-- drivers/timer/altera_timer.c | 4 +-- drivers/timer/andes_plmt_timer.c | 7 +++-- drivers/timer/mpc83xx_timer.c | 2 +- drivers/timer/sifive_clint_timer.c | 7 +++-- drivers/timer/timer-uclass.c | 2 +- drivers/usb/gadget/ether.c | 16 ++++++++--- drivers/usb/host/usb-uclass.c | 6 ++-- drivers/video/video-uclass.c | 2 +- lib/efi_loader/efi_device_path.c | 2 +- net/eth-uclass.c | 22 +++++++-------- test/dm/core.c | 24 ++++++++-------- test/dm/test-driver.c | 7 +++-- test/dm/test-fdt.c | 4 +-- test/dm/test-uclass.c | 4 +-- 113 files changed, 372 insertions(+), 278 deletions(-) diff --git a/arch/arm/cpu/armv7/ls102xa/fdt.c b/arch/arm/cpu/armv7/ls102xa/fdt.c index d8cb78ecc6..2556980cde 100644 --- a/arch/arm/cpu/armv7/ls102xa/fdt.c +++ b/arch/arm/cpu/armv7/ls102xa/fdt.c @@ -52,7 +52,11 @@ void ft_fixup_enet_phy_connect_type(void *fdt) continue; } +#ifdef CONFIG_DM_ETH + priv = dev_get_priv(dev); +#else priv = dev->priv; +#endif if (priv->flags & TSEC_SGMII) continue; diff --git a/arch/arm/mach-stm32mp/pwr_regulator.c b/arch/arm/mach-stm32mp/pwr_regulator.c index 74a5df5948..af6ea43964 100644 --- a/arch/arm/mach-stm32mp/pwr_regulator.c +++ b/arch/arm/mach-stm32mp/pwr_regulator.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -165,7 +166,7 @@ static int stm32mp_pwr_regulator_probe(struct udevice *dev) } uc_pdata->type = REGULATOR_TYPE_FIXED; - dev->priv = (void *)*p; + dev_set_priv(dev, (void *)*p); return 0; } diff --git a/arch/x86/cpu/apollolake/uart.c b/arch/x86/cpu/apollolake/uart.c index 8e6dfdb630..e523d85b1b 100644 --- a/arch/x86/cpu/apollolake/uart.c +++ b/arch/x86/cpu/apollolake/uart.c @@ -16,6 +16,7 @@ #include #include #include +#include /* Low-power Subsystem (LPSS) clock register */ enum { @@ -105,7 +106,7 @@ static int apl_ns16550_of_to_plat(struct udevice *dev) plat->clock = dtplat->clock_frequency; plat->fcr = UART_FCR_DEFVAL; plat->bdf = pci_ofplat_get_devfn(dtplat->reg[0]); - dev->plat = plat; + dev_set_plat(dev, plat); #else int ret; diff --git a/arch/x86/cpu/slimbootloader/serial.c b/arch/x86/cpu/slimbootloader/serial.c index ebbd2c552f..772a94c31c 100644 --- a/arch/x86/cpu/slimbootloader/serial.c +++ b/arch/x86/cpu/slimbootloader/serial.c @@ -18,7 +18,7 @@ static int slimbootloader_serial_of_to_plat(struct udevice *dev) { const efi_guid_t guid = SBL_SERIAL_PORT_INFO_GUID; struct sbl_serial_port_info *data; - struct ns16550_plat *plat = dev->plat; + struct ns16550_plat *plat = dev_get_plat(dev); if (!gd->arch.hob_list) panic("hob list not found!"); diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 928ad13641..eb75132f27 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -44,8 +44,10 @@ int clk_register(struct clk *clk, const char *drv_name, } clk->enable_count = 0; + /* Store back pointer to clk from udevice */ - clk->dev->uclass_priv = clk; + /* FIXME: This is not allowed...should be allocated by driver model */ + dev_set_uclass_priv(clk->dev, clk); return 0; } diff --git a/drivers/clk/clk_fixed_rate.c b/drivers/clk/clk_fixed_rate.c index 12d81a7ff7..3c5a83c523 100644 --- a/drivers/clk/clk_fixed_rate.c +++ b/drivers/clk/clk_fixed_rate.c @@ -6,6 +6,7 @@ #include #include #include +#include #include static ulong clk_fixed_rate_get_rate(struct clk *clk) @@ -32,7 +33,8 @@ static int clk_fixed_rate_of_to_plat(struct udevice *dev) dev_read_u32_default(dev, "clock-frequency", 0); #endif /* Make fixed rate clock accessible from higher level struct clk */ - dev->uclass_priv = clk; + /* FIXME: This is not allowed */ + dev_set_uclass_priv(dev, clk); clk->dev = dev; clk->enable_count = 0; diff --git a/drivers/clk/rockchip/clk_px30.c b/drivers/clk/rockchip/clk_px30.c index 355362dd67..a2a5939d4b 100644 --- a/drivers/clk/rockchip/clk_px30.c +++ b/drivers/clk/rockchip/clk_px30.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -1458,7 +1459,7 @@ static int px30_clk_bind(struct udevice *dev) glb_srst_fst); priv->glb_srst_snd_value = offsetof(struct px30_cru, glb_srst_snd); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/clk/rockchip/clk_rk3036.c b/drivers/clk/rockchip/clk_rk3036.c index 07ef6133f2..026858459e 100644 --- a/drivers/clk/rockchip/clk_rk3036.c +++ b/drivers/clk/rockchip/clk_rk3036.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -353,7 +354,7 @@ static int rk3036_clk_bind(struct udevice *dev) cru_glb_srst_fst_value); priv->glb_srst_snd_value = offsetof(struct rk3036_cru, cru_glb_srst_snd_value); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/clk/rockchip/clk_rk3128.c b/drivers/clk/rockchip/clk_rk3128.c index 9349e14830..d5b2b63dd7 100644 --- a/drivers/clk/rockchip/clk_rk3128.c +++ b/drivers/clk/rockchip/clk_rk3128.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -581,7 +582,7 @@ static int rk3128_clk_bind(struct udevice *dev) cru_glb_srst_fst_value); priv->glb_srst_snd_value = offsetof(struct rk3128_cru, cru_glb_srst_snd_value); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } return 0; diff --git a/drivers/clk/rockchip/clk_rk3188.c b/drivers/clk/rockchip/clk_rk3188.c index 48bfe09b11..1b62d8d289 100644 --- a/drivers/clk/rockchip/clk_rk3188.c +++ b/drivers/clk/rockchip/clk_rk3188.c @@ -593,7 +593,7 @@ static int rk3188_clk_bind(struct udevice *dev) cru_glb_srst_fst_value); priv->glb_srst_snd_value = offsetof(struct rk3188_cru, cru_glb_srst_snd_value); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/clk/rockchip/clk_rk322x.c b/drivers/clk/rockchip/clk_rk322x.c index c2f5fc0fd7..dbef606d88 100644 --- a/drivers/clk/rockchip/clk_rk322x.c +++ b/drivers/clk/rockchip/clk_rk322x.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -510,7 +511,7 @@ static int rk322x_clk_bind(struct udevice *dev) cru_glb_srst_fst_value); priv->glb_srst_snd_value = offsetof(struct rk322x_cru, cru_glb_srst_snd_value); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/clk/rockchip/clk_rk3288.c b/drivers/clk/rockchip/clk_rk3288.c index e87fdfc54d..6226d55658 100644 --- a/drivers/clk/rockchip/clk_rk3288.c +++ b/drivers/clk/rockchip/clk_rk3288.c @@ -1018,7 +1018,7 @@ static int rk3288_clk_bind(struct udevice *dev) cru_glb_srst_fst_value); priv->glb_srst_snd_value = offsetof(struct rockchip_cru, cru_glb_srst_snd_value); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/clk/rockchip/clk_rk3308.c b/drivers/clk/rockchip/clk_rk3308.c index 30589512ec..a05efcfbab 100644 --- a/drivers/clk/rockchip/clk_rk3308.c +++ b/drivers/clk/rockchip/clk_rk3308.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -1045,7 +1046,7 @@ static int rk3308_clk_bind(struct udevice *dev) glb_srst_fst); priv->glb_srst_snd_value = offsetof(struct rk3308_cru, glb_srst_snd); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/clk/rockchip/clk_rk3328.c b/drivers/clk/rockchip/clk_rk3328.c index e2df71290f..b825ff4cf8 100644 --- a/drivers/clk/rockchip/clk_rk3328.c +++ b/drivers/clk/rockchip/clk_rk3328.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -823,7 +824,7 @@ static int rk3328_clk_bind(struct udevice *dev) glb_srst_fst_value); priv->glb_srst_snd_value = offsetof(struct rk3328_cru, glb_srst_snd_value); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/clk/rockchip/clk_rk3368.c b/drivers/clk/rockchip/clk_rk3368.c index 9267cac6bc..780b49ccd8 100644 --- a/drivers/clk/rockchip/clk_rk3368.c +++ b/drivers/clk/rockchip/clk_rk3368.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -621,7 +622,7 @@ static int rk3368_clk_bind(struct udevice *dev) glb_srst_fst_val); priv->glb_srst_snd_value = offsetof(struct rk3368_cru, glb_srst_snd_val); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/clk/rockchip/clk_rk3399.c b/drivers/clk/rockchip/clk_rk3399.c index 68d5dbb581..55ebac7057 100644 --- a/drivers/clk/rockchip/clk_rk3399.c +++ b/drivers/clk/rockchip/clk_rk3399.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -1425,7 +1426,7 @@ static int rk3399_clk_bind(struct udevice *dev) glb_srst_fst_value); priv->glb_srst_snd_value = offsetof(struct rockchip_cru, glb_srst_snd_value); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/clk/rockchip/clk_rv1108.c b/drivers/clk/rockchip/clk_rv1108.c index 62bcf5a2ab..1e22db0cb7 100644 --- a/drivers/clk/rockchip/clk_rv1108.c +++ b/drivers/clk/rockchip/clk_rv1108.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -697,7 +698,7 @@ static int rv1108_clk_bind(struct udevice *dev) glb_srst_fst_val); priv->glb_srst_snd_value = offsetof(struct rv1108_cru, glb_srst_snd_val); - sys_child->priv = priv; + dev_set_priv(sys_child, priv); } #if CONFIG_IS_ENABLED(RESET_ROCKCHIP) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 289220b98e..8c12169771 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -89,15 +89,15 @@ int device_unbind(struct udevice *dev) return log_msg_ret("child unbind", ret); if (dev->flags & DM_FLAG_ALLOC_PDATA) { - free(dev->plat); - dev->plat = NULL; + free(dev_get_plat(dev)); + dev_set_plat(dev, NULL); } if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { - free(dev->uclass_plat); + free(dev_get_uclass_plat(dev)); dev->uclass_plat = NULL; } if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { - free(dev->parent_plat); + free(dev_get_parent_plat(dev)); dev->parent_plat = NULL; } ret = uclass_unbind_device(dev); @@ -125,12 +125,12 @@ void device_free(struct udevice *dev) int size; if (dev->driver->priv_auto) { - free(dev->priv); - dev->priv = NULL; + free(dev_get_priv(dev)); + dev_set_priv(dev, NULL); } size = dev->uclass->uc_drv->per_device_auto; if (size) { - free(dev->uclass_priv); + free(dev_get_uclass_priv(dev)); dev->uclass_priv = NULL; } if (dev->parent) { @@ -140,7 +140,7 @@ void device_free(struct udevice *dev) per_child_auto; } if (size) { - free(dev->parent_priv); + free(dev_get_parent_priv(dev)); dev->parent_priv = NULL; } } diff --git a/drivers/ddr/altera/sdram_agilex.c b/drivers/ddr/altera/sdram_agilex.c index 868bf142b4..a4ceb36461 100644 --- a/drivers/ddr/altera/sdram_agilex.c +++ b/drivers/ddr/altera/sdram_agilex.c @@ -25,7 +25,7 @@ DECLARE_GLOBAL_DATA_PTR; int sdram_mmr_init_full(struct udevice *dev) { - struct altera_sdram_plat *plat = dev->plat; + struct altera_sdram_plat *plat = dev_get_plat(dev); struct altera_sdram_priv *priv = dev_get_priv(dev); u32 i; int ret; diff --git a/drivers/ddr/altera/sdram_gen5.c b/drivers/ddr/altera/sdram_gen5.c index 3ffe057543..8d3ce495de 100644 --- a/drivers/ddr/altera/sdram_gen5.c +++ b/drivers/ddr/altera/sdram_gen5.c @@ -565,7 +565,7 @@ static unsigned long sdram_calculate_size(struct socfpga_sdr_ctrl *sdr_ctrl) static int altera_gen5_sdram_of_to_plat(struct udevice *dev) { - struct altera_gen5_sdram_plat *plat = dev->plat; + struct altera_gen5_sdram_plat *plat = dev_get_plat(dev); plat->sdr = (struct socfpga_sdr *)devfdt_get_addr_index(dev, 0); if (!plat->sdr) @@ -578,7 +578,7 @@ static int altera_gen5_sdram_probe(struct udevice *dev) { int ret; unsigned long sdram_size; - struct altera_gen5_sdram_plat *plat = dev->plat; + struct altera_gen5_sdram_plat *plat = dev_get_plat(dev); struct altera_gen5_sdram_priv *priv = dev_get_priv(dev); struct socfpga_sdr_ctrl *sdr_ctrl = &plat->sdr->sdr_ctrl; struct reset_ctl_bulk resets; diff --git a/drivers/ddr/altera/sdram_s10.c b/drivers/ddr/altera/sdram_s10.c index 984dc32442..03a270f263 100644 --- a/drivers/ddr/altera/sdram_s10.c +++ b/drivers/ddr/altera/sdram_s10.c @@ -70,7 +70,7 @@ int match_ddr_conf(u32 ddr_conf) */ int sdram_mmr_init_full(struct udevice *dev) { - struct altera_sdram_plat *plat = dev->plat; + struct altera_sdram_plat *plat = dev_get_plat(dev); struct altera_sdram_priv *priv = dev_get_priv(dev); u32 update_value, io48_value, ddrioctl; u32 i; diff --git a/drivers/ddr/altera/sdram_soc64.c b/drivers/ddr/altera/sdram_soc64.c index 7e77c7b073..5aba655e5f 100644 --- a/drivers/ddr/altera/sdram_soc64.c +++ b/drivers/ddr/altera/sdram_soc64.c @@ -232,7 +232,7 @@ phys_size_t sdram_calculate_size(struct altera_sdram_plat *plat) static int altera_sdram_of_to_plat(struct udevice *dev) { - struct altera_sdram_plat *plat = dev->plat; + struct altera_sdram_plat *plat = dev_get_plat(dev); fdt_addr_t addr; addr = dev_read_addr_index(dev, 0); diff --git a/drivers/gpio/dwapb_gpio.c b/drivers/gpio/dwapb_gpio.c index acd77b6892..e6e919444f 100644 --- a/drivers/gpio/dwapb_gpio.c +++ b/drivers/gpio/dwapb_gpio.c @@ -141,7 +141,7 @@ static int gpio_dwapb_reset(struct udevice *dev) static int gpio_dwapb_probe(struct udevice *dev) { struct gpio_dev_priv *priv = dev_get_uclass_priv(dev); - struct gpio_dwapb_plat *plat = dev->plat; + struct gpio_dwapb_plat *plat = dev_get_plat(dev); if (!plat) { /* Reset on parent device only */ diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 65b18ce6c8..952c111b08 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -1165,7 +1165,7 @@ int gpio_get_number(const struct gpio_desc *desc) if (!dev) return -1; - uc_priv = dev->uclass_priv; + uc_priv = dev_get_uclass_priv(dev); return uc_priv->gpio_base + desc->offset; } diff --git a/drivers/gpio/hi6220_gpio.c b/drivers/gpio/hi6220_gpio.c index f5e5fc6e48..04f8d904a2 100644 --- a/drivers/gpio/hi6220_gpio.c +++ b/drivers/gpio/hi6220_gpio.c @@ -67,7 +67,7 @@ static int hi6220_gpio_probe(struct udevice *dev) { struct gpio_bank *bank = dev_get_priv(dev); struct hikey_gpio_plat *plat = dev_get_plat(dev); - struct gpio_dev_priv *uc_priv = dev->uclass_priv; + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); char name[18], *str; sprintf(name, "GPIO%d_", plat->bank_index); diff --git a/drivers/gpio/imx_rgpio2p.c b/drivers/gpio/imx_rgpio2p.c index 17edd40c5c..a5a290a00c 100644 --- a/drivers/gpio/imx_rgpio2p.c +++ b/drivers/gpio/imx_rgpio2p.c @@ -11,6 +11,7 @@ #include #include #include +#include #include enum imx_rgpio2p_direction { @@ -151,7 +152,7 @@ static int imx_rgpio2p_probe(struct udevice *dev) static int imx_rgpio2p_bind(struct udevice *dev) { - struct imx_rgpio2p_plat *plat = dev->plat; + struct imx_rgpio2p_plat *plat = dev_get_plat(dev); fdt_addr_t addr; /* @@ -184,7 +185,7 @@ static int imx_rgpio2p_bind(struct udevice *dev) plat->regs = (struct gpio_regs *)addr; plat->bank_index = dev_seq(dev); - dev->plat = plat; + dev_set_plat(dev, plat); return 0; } diff --git a/drivers/gpio/lpc32xx_gpio.c b/drivers/gpio/lpc32xx_gpio.c index ffaec32ac2..de66c765d1 100644 --- a/drivers/gpio/lpc32xx_gpio.c +++ b/drivers/gpio/lpc32xx_gpio.c @@ -295,7 +295,7 @@ static const struct dm_gpio_ops gpio_lpc32xx_ops = { static int lpc32xx_gpio_probe(struct udevice *dev) { struct lpc32xx_gpio_priv *gpio_priv = dev_get_priv(dev); - struct gpio_dev_priv *uc_priv = dev->uclass_priv; + struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); if (dev_of_offset(dev) == -1) { /* Tell the uclass how many GPIOs we have */ diff --git a/drivers/gpio/mt7621_gpio.c b/drivers/gpio/mt7621_gpio.c index 65b4cbf61b..43bb4df4da 100644 --- a/drivers/gpio/mt7621_gpio.c +++ b/drivers/gpio/mt7621_gpio.c @@ -130,7 +130,7 @@ static int gpio_mediatek_probe(struct udevice *dev) */ static int gpio_mediatek_bind(struct udevice *parent) { - struct mediatek_gpio_plat *plat = parent->plat; + struct mediatek_gpio_plat *plat = dev_get_plat(parent); ofnode node; int bank = 0; int ret; diff --git a/drivers/gpio/mxs_gpio.c b/drivers/gpio/mxs_gpio.c index 5ad65e4ee0..fd5e0ea5c2 100644 --- a/drivers/gpio/mxs_gpio.c +++ b/drivers/gpio/mxs_gpio.c @@ -264,7 +264,7 @@ static int mxs_gpio_probe(struct udevice *dev) #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) static int mxs_of_to_plat(struct udevice *dev) { - struct mxs_gpio_plat *plat = dev->plat; + struct mxs_gpio_plat *plat = dev_get_plat(dev); struct fdtdec_phandle_args args; int node = dev_of_offset(dev); int ret; diff --git a/drivers/gpio/omap_gpio.c b/drivers/gpio/omap_gpio.c index 400c6ca472..336ece4778 100644 --- a/drivers/gpio/omap_gpio.c +++ b/drivers/gpio/omap_gpio.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -328,7 +329,7 @@ static int omap_gpio_bind(struct udevice *dev) plat->base = base_addr; plat->port_name = fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL); - dev->plat = plat; + dev_set_plat(dev, plat); return 0; } diff --git a/drivers/gpio/s5p_gpio.c b/drivers/gpio/s5p_gpio.c index 9de9541c87..796fe3e110 100644 --- a/drivers/gpio/s5p_gpio.c +++ b/drivers/gpio/s5p_gpio.c @@ -286,8 +286,8 @@ static const struct dm_gpio_ops gpio_exynos_ops = { static int gpio_exynos_probe(struct udevice *dev) { struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); - struct exynos_bank_info *priv = dev->priv; - struct exynos_gpio_plat *plat = dev->plat; + struct exynos_bank_info *priv = dev_get_priv(dev); + struct exynos_gpio_plat *plat = dev_get_plat(dev); /* Only child devices have ports */ if (!plat) @@ -307,7 +307,7 @@ static int gpio_exynos_probe(struct udevice *dev) */ static int gpio_exynos_bind(struct udevice *parent) { - struct exynos_gpio_plat *plat = parent->plat; + struct exynos_gpio_plat *plat = dev_get_plat(parent); struct s5p_gpio_bank *bank, *base; const void *blob = gd->fdt_blob; int node; diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index 2708838adf..489271b560 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -297,14 +298,15 @@ static int gpio_sandbox_probe(struct udevice *dev) /* Tell the uclass how many GPIOs we have */ uc_priv->gpio_count = CONFIG_SANDBOX_GPIO_COUNT; - dev->priv = calloc(sizeof(struct gpio_state), uc_priv->gpio_count); + dev_set_priv(dev, + calloc(sizeof(struct gpio_state), uc_priv->gpio_count)); return 0; } static int gpio_sandbox_remove(struct udevice *dev) { - free(dev->priv); + free(dev_get_priv(dev)); return 0; } diff --git a/drivers/gpio/sunxi_gpio.c b/drivers/gpio/sunxi_gpio.c index 75494c7828..7633422b0b 100644 --- a/drivers/gpio/sunxi_gpio.c +++ b/drivers/gpio/sunxi_gpio.c @@ -285,7 +285,7 @@ static int gpio_sunxi_bind(struct udevice *parent) { struct sunxi_gpio_soc_data *soc_data = (struct sunxi_gpio_soc_data *)dev_get_driver_data(parent); - struct sunxi_gpio_plat *plat = parent->plat; + struct sunxi_gpio_plat *plat = dev_get_plat(parent); struct sunxi_gpio_reg *ctlr; int bank, ret; diff --git a/drivers/gpio/tegra186_gpio.c b/drivers/gpio/tegra186_gpio.c index cd1fb65a55..82dcaf9631 100644 --- a/drivers/gpio/tegra186_gpio.c +++ b/drivers/gpio/tegra186_gpio.c @@ -34,7 +34,7 @@ struct tegra186_gpio_plat { static uint32_t *tegra186_gpio_reg(struct udevice *dev, uint32_t reg, uint32_t gpio) { - struct tegra186_gpio_plat *plat = dev->plat; + struct tegra186_gpio_plat *plat = dev_get_plat(dev); uint32_t index = (reg + (gpio * TEGRA186_GPIO_PER_GPIO_STRIDE)) / 4; return &(plat->regs[index]); @@ -166,7 +166,7 @@ static const struct dm_gpio_ops tegra186_gpio_ops = { */ static int tegra186_gpio_bind(struct udevice *parent) { - struct tegra186_gpio_plat *parent_plat = parent->plat; + struct tegra186_gpio_plat *parent_plat = dev_get_plat(parent); struct tegra186_gpio_ctlr_data *ctlr_data = (struct tegra186_gpio_ctlr_data *)dev_get_driver_data(parent); uint32_t *regs; @@ -201,7 +201,7 @@ static int tegra186_gpio_bind(struct udevice *parent) static int tegra186_gpio_probe(struct udevice *dev) { - struct tegra186_gpio_plat *plat = dev->plat; + struct tegra186_gpio_plat *plat = dev_get_plat(dev); struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); /* Only child devices have ports */ diff --git a/drivers/gpio/tegra_gpio.c b/drivers/gpio/tegra_gpio.c index c489796f77..5d3af8a016 100644 --- a/drivers/gpio/tegra_gpio.c +++ b/drivers/gpio/tegra_gpio.c @@ -291,8 +291,8 @@ static const struct udevice_id tegra_gpio_ids[] = { static int gpio_tegra_probe(struct udevice *dev) { struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); - struct tegra_port_info *priv = dev->priv; - struct tegra_gpio_plat *plat = dev->plat; + struct tegra_port_info *priv = dev_get_priv(dev); + struct tegra_gpio_plat *plat = dev_get_plat(dev); /* Only child devices have ports */ if (!plat) @@ -313,7 +313,7 @@ static int gpio_tegra_probe(struct udevice *dev) */ static int gpio_tegra_bind(struct udevice *parent) { - struct tegra_gpio_plat *plat = parent->plat; + struct tegra_gpio_plat *plat = dev_get_plat(parent); struct gpio_ctlr *ctlr; int bank_count; int bank; diff --git a/drivers/misc/altera_sysid.c b/drivers/misc/altera_sysid.c index 057b431c25..878df12771 100644 --- a/drivers/misc/altera_sysid.c +++ b/drivers/misc/altera_sysid.c @@ -59,7 +59,7 @@ U_BOOT_CMD( static int altera_sysid_read(struct udevice *dev, int offset, void *buf, int size) { - struct altera_sysid_plat *plat = dev->plat; + struct altera_sysid_plat *plat = dev_get_plat(dev); struct altera_sysid_regs *const regs = plat->regs; u32 *sysid = buf; diff --git a/drivers/misc/cros_ec_sandbox.c b/drivers/misc/cros_ec_sandbox.c index cb7229ae96..64186b9a3e 100644 --- a/drivers/misc/cros_ec_sandbox.c +++ b/drivers/misc/cros_ec_sandbox.c @@ -522,8 +522,8 @@ void cros_ec_check_keyboard(struct udevice *dev) int cros_ec_probe(struct udevice *dev) { - struct ec_state *ec = dev->priv; - struct cros_ec_dev *cdev = dev->uclass_priv; + struct ec_state *ec = dev_get_priv(dev); + struct cros_ec_dev *cdev = dev_get_uclass_priv(dev); struct udevice *keyb_dev; ofnode node; int err; diff --git a/drivers/misc/fs_loader.c b/drivers/misc/fs_loader.c index 5ed8ab6530..f460b1a64c 100644 --- a/drivers/misc/fs_loader.c +++ b/drivers/misc/fs_loader.c @@ -161,7 +161,7 @@ static int fw_get_filesystem_firmware(struct udevice *dev) else ret = -ENODEV; } else { - ret = select_fs_dev(dev->plat); + ret = select_fs_dev(dev_get_plat(dev)); } if (ret) @@ -228,7 +228,7 @@ static int fs_loader_of_to_plat(struct udevice *dev) if (ofnode_valid(fs_loader_node)) { struct device_plat *plat; - plat = dev->plat; + plat = dev_get_plat(dev); if (!ofnode_read_u32_array(fs_loader_node, "phandlepart", phandlepart, 2)) { @@ -250,7 +250,7 @@ static int fs_loader_probe(struct udevice *dev) { #if CONFIG_IS_ENABLED(DM) && CONFIG_IS_ENABLED(BLK) int ret; - struct device_plat *plat = dev->plat; + struct device_plat *plat = dev_get_plat(dev); if (plat->phandlepart.phandle) { ofnode node = ofnode_get_by_phandle(plat->phandlepart.phandle); diff --git a/drivers/misc/vexpress_config.c b/drivers/misc/vexpress_config.c index 02e5b586e2..2baca48109 100644 --- a/drivers/misc/vexpress_config.c +++ b/drivers/misc/vexpress_config.c @@ -109,7 +109,7 @@ static int vexpress_config_probe(struct udevice *dev) if (!priv) return -ENOMEM; - dev->uclass_priv = priv; + dev_get_uclass_priv(dev) = priv; priv->addr = ofnode_get_addr(args.node); return dev_read_u32(dev, "arm,vexpress,site", &priv->site); diff --git a/drivers/mmc/arm_pl180_mmci.c b/drivers/mmc/arm_pl180_mmci.c index fe406fe4ad..b2d1b4f9aa 100644 --- a/drivers/mmc/arm_pl180_mmci.c +++ b/drivers/mmc/arm_pl180_mmci.c @@ -421,7 +421,7 @@ static int arm_pl180_mmc_probe(struct udevice *dev) struct arm_pl180_mmc_plat *pdata = dev_get_plat(dev); struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); struct mmc *mmc = &pdata->mmc; - struct pl180_mmc_host *host = dev->priv; + struct pl180_mmc_host *host = dev_get_priv(dev); struct mmc_config *cfg = &pdata->cfg; struct clk clk; u32 bus_width; @@ -508,7 +508,7 @@ static int dm_host_set_ios(struct udevice *dev) static int dm_mmc_getcd(struct udevice *dev) { - struct pl180_mmc_host *host = dev->priv; + struct pl180_mmc_host *host = dev_get_priv(dev); int value = 1; if (dm_gpio_is_valid(&host->cd_gpio)) @@ -525,7 +525,7 @@ static const struct dm_mmc_ops arm_pl180_dm_mmc_ops = { static int arm_pl180_mmc_of_to_plat(struct udevice *dev) { - struct pl180_mmc_host *host = dev->priv; + struct pl180_mmc_host *host = dev_get_priv(dev); fdt_addr_t addr; addr = dev_read_addr(dev); diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index 143818d401..b3fb559a67 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -668,7 +668,7 @@ static const struct dm_mmc_ops mxsmmc_ops = { #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) static int mxsmmc_of_to_plat(struct udevice *bus) { - struct mxsmmc_plat *plat = bus->plat; + struct mxsmmc_plat *plat = dev_get_plat(bus); u32 prop[2]; int ret; diff --git a/drivers/mmc/octeontx_hsmmc.c b/drivers/mmc/octeontx_hsmmc.c index 5552342f8d..57d107aac3 100644 --- a/drivers/mmc/octeontx_hsmmc.c +++ b/drivers/mmc/octeontx_hsmmc.c @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -3841,7 +3842,7 @@ static int octeontx_mmc_host_child_pre_probe(struct udevice *dev) } slot = &host->slots[bus_id]; - dev->priv = slot; + dev_set_priv(dev, slot); slot->host = host; slot->bus_id = bus_id; slot->dev = dev; @@ -3852,16 +3853,21 @@ static int octeontx_mmc_host_child_pre_probe(struct udevice *dev) snprintf(name, sizeof(name), "octeontx-mmc%d", bus_id); err = device_set_name(dev, name); - if (!dev->uclass_priv) { + /* FIXME: This code should not be needed */ + if (!dev_get_uclass_priv(dev)) { debug("%s(%s): Allocating uclass priv\n", __func__, dev->name); upriv = calloc(1, sizeof(struct mmc_uclass_priv)); if (!upriv) return -ENOMEM; - dev->uclass_priv = upriv; - dev->uclass->priv = upriv; + + /* + * FIXME: This is not allowed + * dev_set_uclass_priv(dev, upriv); + * uclass_set_priv(dev->uclass, upriv); + */ } else { - upriv = dev->uclass_priv; + upriv = dev_get_uclass_priv(dev); } upriv->mmc = &slot->mmc; @@ -3878,6 +3884,7 @@ static const struct udevice_id octeontx_hsmmc_host_ids[] = { U_BOOT_DRIVER(octeontx_hsmmc_host) = { .name = "octeontx_hsmmc_host", + /* FIXME: Why is this not UCLASS_MMC? */ .id = UCLASS_MISC, .of_match = of_match_ptr(octeontx_hsmmc_host_ids), .probe = octeontx_mmc_host_probe, diff --git a/drivers/mux/mmio.c b/drivers/mux/mmio.c index b9868505a3..00e0282dcc 100644 --- a/drivers/mux/mmio.c +++ b/drivers/mux/mmio.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -68,7 +69,7 @@ static int mmio_mux_probe(struct udevice *dev) fields = devm_kmalloc(dev, num_fields * sizeof(*fields), __GFP_ZERO); if (!fields) return -ENOMEM; - dev->priv = fields; + dev_set_priv(dev, fields); mux_reg_masks = devm_kmalloc(dev, num_fields * 2 * sizeof(u32), __GFP_ZERO); diff --git a/drivers/net/eth-phy-uclass.c b/drivers/net/eth-phy-uclass.c index 65615f1310..07aebd935e 100644 --- a/drivers/net/eth-phy-uclass.c +++ b/drivers/net/eth-phy-uclass.c @@ -54,7 +54,7 @@ int eth_phy_set_mdio_bus(struct udevice *eth_dev, struct mii_dev *mdio_bus) for (uclass_first_device(UCLASS_ETH_PHY, &dev); dev; uclass_next_device(&dev)) { if (dev->parent == eth_dev) { - uc_priv = (struct eth_phy_device_priv *)(dev->uclass_priv); + uc_priv = (struct eth_phy_device_priv *)(dev_get_uclass_priv(dev)); if (!uc_priv->mdio_bus) uc_priv->mdio_bus = mdio_bus; @@ -79,7 +79,7 @@ struct mii_dev *eth_phy_get_mdio_bus(struct udevice *eth_dev) * phy_dev is shared and controlled by * other eth controller */ - uc_priv = (struct eth_phy_device_priv *)(phy_dev->uclass_priv); + uc_priv = (struct eth_phy_device_priv *)(dev_get_uclass_priv(phy_dev)); if (uc_priv->mdio_bus) printf("Get shared mii bus on %s\n", eth_dev->name); else diff --git a/drivers/net/fm/eth.c b/drivers/net/fm/eth.c index 02ccf1efc3..a10f87eefc 100644 --- a/drivers/net/fm/eth.c +++ b/drivers/net/fm/eth.c @@ -547,7 +547,11 @@ static void fm_eth_halt(struct udevice *dev) struct fm_eth *fm_eth; struct fsl_enet_mac *mac; +#ifndef CONFIG_DM_ETH fm_eth = (struct fm_eth *)dev->priv; +#else + fm_eth = dev_get_priv(dev); +#endif mac = fm_eth->mac; /* graceful stop the transmission of frames */ @@ -577,7 +581,11 @@ static int fm_eth_send(struct udevice *dev, void *buf, int len) u16 offset_in; int i; +#ifndef CONFIG_DM_ETH fm_eth = (struct fm_eth *)dev->priv; +#else + fm_eth = dev_get_priv(dev); +#endif pram = fm_eth->tx_pram; txbd = fm_eth->cur_txbd; @@ -664,13 +672,19 @@ static int fm_eth_recv(struct eth_device *dev) static int fm_eth_recv(struct udevice *dev, int flags, uchar **packetp) #endif { - struct fm_eth *fm_eth = (struct fm_eth *)dev->priv; - struct fm_port_bd *rxbd = fm_eth->cur_rxbd; + struct fm_eth *fm_eth; + struct fm_port_bd *rxbd; u32 buf_lo, buf_hi; u16 status, len; int ret = -1; u8 *data; +#ifndef CONFIG_DM_ETH + fm_eth = (struct fm_eth *)dev->priv; +#else + fm_eth = dev_get_priv(dev); +#endif + rxbd = fm_eth->cur_rxbd; status = muram_readw(&rxbd->status); while (!(status & RxBD_EMPTY)) { @@ -704,7 +718,7 @@ static int fm_eth_recv(struct udevice *dev, int flags, uchar **packetp) #ifdef CONFIG_DM_ETH static int fm_eth_free_pkt(struct udevice *dev, uchar *packet, int length) { - struct fm_eth *fm_eth = (struct fm_eth *)dev->priv; + struct fm_eth *fm_eth = (struct fm_eth *)dev_get_priv(dev); fm_eth->cur_rxbd = fm_eth_free_one(fm_eth, fm_eth->cur_rxbd); @@ -1004,7 +1018,7 @@ static struct udevice *fm_get_internal_mdio(struct udevice *dev) static int fm_eth_probe(struct udevice *dev) { - struct fm_eth *fm_eth = (struct fm_eth *)dev->priv; + struct fm_eth *fm_eth = (struct fm_eth *)dev_get_priv(dev); struct ofnode_phandle_args args; void *reg; int ret, index; diff --git a/drivers/net/fsl_mcdmafec.c b/drivers/net/fsl_mcdmafec.c index 0196462beb..c36d40c911 100644 --- a/drivers/net/fsl_mcdmafec.c +++ b/drivers/net/fsl_mcdmafec.c @@ -79,7 +79,7 @@ static void init_eth_info(struct fec_info_dma *info) static void fec_halt(struct udevice *dev) { - struct fec_info_dma *info = dev->priv; + struct fec_info_dma *info = dev_get_priv(dev); volatile fecdma_t *fecp = (fecdma_t *)info->iobase; int counter = 0xffff; @@ -230,7 +230,7 @@ static void fec_set_hwaddr(volatile fecdma_t *fecp, u8 *mac) static int fec_init(struct udevice *dev) { - struct fec_info_dma *info = dev->priv; + struct fec_info_dma *info = dev_get_priv(dev); volatile fecdma_t *fecp = (fecdma_t *)info->iobase; int rval, i; uchar enetaddr[6]; @@ -352,7 +352,7 @@ static int mcdmafec_init(struct udevice *dev) static int mcdmafec_send(struct udevice *dev, void *packet, int length) { - struct fec_info_dma *info = dev->priv; + struct fec_info_dma *info = dev_get_priv(dev); cbd_t *p_tbd, *p_used_tbd; u16 phy_status; @@ -412,7 +412,7 @@ static int mcdmafec_send(struct udevice *dev, void *packet, int length) static int mcdmafec_recv(struct udevice *dev, int flags, uchar **packetp) { - struct fec_info_dma *info = dev->priv; + struct fec_info_dma *info = dev_get_priv(dev); volatile fecdma_t *fecp = (fecdma_t *)info->iobase; cbd_t *prbd = &info->rxbd[info->rx_idx]; @@ -496,7 +496,7 @@ static const struct eth_ops mcdmafec_ops = { */ static int mcdmafec_probe(struct udevice *dev) { - struct fec_info_dma *info = dev->priv; + struct fec_info_dma *info = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); int node = dev_of_offset(dev); int retval; diff --git a/drivers/net/mcffec.c b/drivers/net/mcffec.c index 4fa71360cf..cb343b446f 100644 --- a/drivers/net/mcffec.c +++ b/drivers/net/mcffec.c @@ -125,7 +125,7 @@ static void set_fec_duplex_speed(volatile fec_t *fecp, int dup_spd) #ifdef ET_DEBUG static void dbg_fec_regs(struct udevice *dev) { - struct fec_info_s *info = dev->priv; + struct fec_info_s *info = dev_get_priv(dev); volatile fec_t *fecp = (fec_t *)(info->iobase); printf("=====\n"); @@ -275,7 +275,7 @@ static void dbg_fec_regs(struct udevice *dev) int mcffec_init(struct udevice *dev) { - struct fec_info_s *info = dev->priv; + struct fec_info_s *info = dev_get_priv(dev); volatile fec_t *fecp = (fec_t *) (info->iobase); int rval, i; uchar ea[6]; @@ -374,7 +374,7 @@ int mcffec_init(struct udevice *dev) static int mcffec_send(struct udevice *dev, void *packet, int length) { - struct fec_info_s *info = dev->priv; + struct fec_info_s *info = dev_get_priv(dev); volatile fec_t *fecp = (fec_t *)info->iobase; int j, rc; u16 phy_status; @@ -440,7 +440,7 @@ static int mcffec_send(struct udevice *dev, void *packet, int length) static int mcffec_recv(struct udevice *dev, int flags, uchar **packetp) { - struct fec_info_s *info = dev->priv; + struct fec_info_s *info = dev_get_priv(dev); volatile fec_t *fecp = (fec_t *)info->iobase; int length = -1; @@ -492,7 +492,7 @@ static int mcffec_recv(struct udevice *dev, int flags, uchar **packetp) static void mcffec_halt(struct udevice *dev) { - struct fec_info_s *info = dev->priv; + struct fec_info_s *info = dev_get_priv(dev); fec_reset(info); fecpin_setclear(info, 0); @@ -519,7 +519,7 @@ static const struct eth_ops mcffec_ops = { static int mcffec_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - struct fec_info_s *info = dev->priv; + struct fec_info_s *info = dev_get_priv(dev); int node = dev_of_offset(dev); int retval, fec_idx; const u32 *val; diff --git a/drivers/net/mcfmii.c b/drivers/net/mcfmii.c index 393605512d..ec81320a86 100644 --- a/drivers/net/mcfmii.c +++ b/drivers/net/mcfmii.c @@ -100,7 +100,11 @@ uint mii_send(uint mii_cmd) /* retrieve from register structure */ dev = eth_get_dev(); +#ifdef CONFIG_DM_ETH + info = dev_get_priv(dev); +#else info = dev->priv; +#endif ep = (FEC_T *) info->miibase; @@ -216,7 +220,11 @@ void __mii_init(void) /* retrieve from register structure */ dev = eth_get_dev(); +#ifdef CONFIG_DM_ETH + info = dev_get_priv(dev); +#else info = dev->priv; +#endif fecp = (FEC_T *) info->miibase; diff --git a/drivers/net/pfe_eth/pfe_eth.c b/drivers/net/pfe_eth/pfe_eth.c index 3d14571114..0c27a668b5 100644 --- a/drivers/net/pfe_eth/pfe_eth.c +++ b/drivers/net/pfe_eth/pfe_eth.c @@ -157,7 +157,7 @@ static int pfe_eth_start(struct udevice *dev) static int pfe_eth_send(struct udevice *dev, void *packet, int length) { - struct pfe_eth_dev *priv = (struct pfe_eth_dev *)dev->priv; + struct pfe_eth_dev *priv = (struct pfe_eth_dev *)dev_get_priv(dev); int rc; int i = 0; diff --git a/drivers/net/sunxi_emac.c b/drivers/net/sunxi_emac.c index 7c6ae3cb81..17ad88e732 100644 --- a/drivers/net/sunxi_emac.c +++ b/drivers/net/sunxi_emac.c @@ -537,7 +537,7 @@ static int sunxi_emac_eth_start(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - return _sunxi_emac_eth_init(dev->priv, pdata->enetaddr); + return _sunxi_emac_eth_init(dev_get_priv(dev), pdata->enetaddr); } static int sunxi_emac_eth_send(struct udevice *dev, void *packet, int length) diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index 2271eb8251..2d124732cf 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -131,11 +131,17 @@ static int tsec_mcast_addr(struct eth_device *dev, const u8 *mcast_mac, static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int join) #endif { - struct tsec_private *priv = (struct tsec_private *)dev->priv; - struct tsec __iomem *regs = priv->regs; + struct tsec_private *priv; + struct tsec __iomem *regs; u32 result, value; u8 whichbit, whichreg; +#ifndef CONFIG_DM_ETH + priv = (struct tsec_private *)dev->priv; +#else + priv = dev_get_priv(dev); +#endif + regs = priv->regs; result = ether_crc(MAC_ADDR_LEN, mcast_mac); whichbit = (result >> 24) & 0x1f; /* the 5 LSB = which bit to set */ whichreg = result >> 29; /* the 3 MSB = which reg to set it in */ @@ -260,12 +266,18 @@ static int tsec_send(struct eth_device *dev, void *packet, int length) static int tsec_send(struct udevice *dev, void *packet, int length) #endif { - struct tsec_private *priv = (struct tsec_private *)dev->priv; - struct tsec __iomem *regs = priv->regs; + struct tsec_private *priv; + struct tsec __iomem *regs; int result = 0; u16 status; int i; +#ifndef CONFIG_DM_ETH + priv = (struct tsec_private *)dev->priv; +#else + priv = dev_get_priv(dev); +#endif + regs = priv->regs; /* Find an empty buffer descriptor */ for (i = 0; in_be16(&priv->txbd[priv->tx_idx].status) & TXBD_READY; @@ -339,7 +351,7 @@ static int tsec_recv(struct eth_device *dev) #else static int tsec_recv(struct udevice *dev, int flags, uchar **packetp) { - struct tsec_private *priv = (struct tsec_private *)dev->priv; + struct tsec_private *priv = (struct tsec_private *)dev_get_priv(dev); struct tsec __iomem *regs = priv->regs; int ret = -1; @@ -368,7 +380,7 @@ static int tsec_recv(struct udevice *dev, int flags, uchar **packetp) static int tsec_free_pkt(struct udevice *dev, uchar *packet, int length) { - struct tsec_private *priv = (struct tsec_private *)dev->priv; + struct tsec_private *priv = (struct tsec_private *)dev_get_priv(dev); u16 status; out_be16(&priv->rxbd[priv->rx_idx].length, 0); @@ -392,8 +404,14 @@ static void tsec_halt(struct eth_device *dev) static void tsec_halt(struct udevice *dev) #endif { - struct tsec_private *priv = (struct tsec_private *)dev->priv; - struct tsec __iomem *regs = priv->regs; + struct tsec_private *priv; + struct tsec __iomem *regs; +#ifndef CONFIG_DM_ETH + priv = (struct tsec_private *)dev->priv; +#else + priv = dev_get_priv(dev); +#endif + regs = priv->regs; clrbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS); setbits_be32(®s->dmactrl, DMACTRL_GRS | DMACTRL_GTS); @@ -560,16 +578,22 @@ static int tsec_init(struct eth_device *dev, struct bd_info *bd) static int tsec_init(struct udevice *dev) #endif { - struct tsec_private *priv = (struct tsec_private *)dev->priv; + struct tsec_private *priv; + struct tsec __iomem *regs; #ifdef CONFIG_DM_ETH struct eth_pdata *pdata = dev_get_plat(dev); #else struct eth_device *pdata = dev; #endif - struct tsec __iomem *regs = priv->regs; u32 tempval; int ret; +#ifndef CONFIG_DM_ETH + priv = (struct tsec_private *)dev->priv; +#else + priv = dev_get_priv(dev); +#endif + regs = priv->regs; /* Make sure the controller is stopped */ tsec_halt(dev); @@ -865,7 +889,7 @@ int tsec_probe(struct udevice *dev) int tsec_remove(struct udevice *dev) { - struct tsec_private *priv = dev->priv; + struct tsec_private *priv = dev_get_priv(dev); free(priv->phydev); mdio_unregister(priv->bus); diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c index 5c76887519..6b447537f6 100644 --- a/drivers/net/xilinx_emaclite.c +++ b/drivers/net/xilinx_emaclite.c @@ -457,7 +457,7 @@ static int emaclite_recv(struct udevice *dev, int flags, uchar **packetp) { u32 length, first_read, reg, attempt = 0; void *addr, *ack; - struct xemaclite *emaclite = dev->priv; + struct xemaclite *emaclite = dev_get_priv(dev); struct emaclite_regs *regs = emaclite->regs; struct ethernet_hdr *eth; struct ip_udp_hdr *ip; diff --git a/drivers/pci/pci-emul-uclass.c b/drivers/pci/pci-emul-uclass.c index 756d8ad744..a0b8afb87a 100644 --- a/drivers/pci/pci-emul-uclass.c +++ b/drivers/pci/pci-emul-uclass.c @@ -82,7 +82,7 @@ uint sandbox_pci_read_bar(u32 barval, int type, uint size) static int sandbox_pci_emul_post_probe(struct udevice *dev) { - struct sandbox_pci_emul_priv *priv = dev->uclass->priv; + struct sandbox_pci_emul_priv *priv = uclass_get_priv(dev->uclass); priv->dev_count++; sandbox_set_enable_pci_map(true); @@ -92,7 +92,7 @@ static int sandbox_pci_emul_post_probe(struct udevice *dev) static int sandbox_pci_emul_pre_remove(struct udevice *dev) { - struct sandbox_pci_emul_priv *priv = dev->uclass->priv; + struct sandbox_pci_emul_priv *priv = uclass_get_priv(dev->uclass); priv->dev_count--; sandbox_set_enable_pci_map(priv->dev_count > 0); diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 914217d0c9..37a233878d 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -524,7 +524,7 @@ static void set_vga_bridge_bits(struct udevice *dev) int pci_auto_config_devices(struct udevice *bus) { - struct pci_controller *hose = bus->uclass_priv; + struct pci_controller *hose = dev_get_uclass_priv(bus); struct pci_child_plat *pplat; unsigned int sub_bus; struct udevice *dev; @@ -1007,7 +1007,7 @@ static int pci_uclass_pre_probe(struct udevice *bus) debug("%s, bus=%d/%s, parent=%s\n", __func__, dev_seq(bus), bus->name, bus->parent->name); - hose = bus->uclass_priv; + hose = dev_get_uclass_priv(bus); /* * Set the sequence number, if device_bind() doesn't. We want control @@ -1109,7 +1109,7 @@ static int pci_bridge_read_config(const struct udevice *bus, pci_dev_t bdf, uint offset, ulong *valuep, enum pci_size_t size) { - struct pci_controller *hose = bus->uclass_priv; + struct pci_controller *hose = dev_get_uclass_priv(bus); return pci_bus_read_config(hose->ctlr, bdf, offset, valuep, size); } @@ -1118,7 +1118,7 @@ static int pci_bridge_write_config(struct udevice *bus, pci_dev_t bdf, uint offset, ulong value, enum pci_size_t size) { - struct pci_controller *hose = bus->uclass_priv; + struct pci_controller *hose = dev_get_uclass_priv(bus); return pci_bus_write_config(hose->ctlr, bdf, offset, value, size); } diff --git a/drivers/pinctrl/pinctrl-qe-io.c b/drivers/pinctrl/pinctrl-qe-io.c index 690e5c7706..e129ab2f83 100644 --- a/drivers/pinctrl/pinctrl-qe-io.c +++ b/drivers/pinctrl/pinctrl-qe-io.c @@ -122,7 +122,7 @@ void qe_config_iopin(u8 port, u8 pin, int dir, int open_drain, int assign) #else static int qe_io_of_to_plat(struct udevice *dev) { - struct qe_io_plat *plat = dev->plat; + struct qe_io_plat *plat = dev_get_plat(dev); fdt_addr_t addr; addr = dev_read_addr(dev); @@ -143,7 +143,7 @@ static int qe_io_of_to_plat(struct udevice *dev) */ static int par_io_of_config_node(struct udevice *dev, ofnode pio) { - struct qe_io_plat *plat = dev->plat; + struct qe_io_plat *plat = dev_get_plat(dev); qepio83xx_t *par_io = plat->base; const unsigned int *pio_map; int pio_map_len; diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c index 25d646a26f..20c3c82aa9 100644 --- a/drivers/pinctrl/pinctrl-single.c +++ b/drivers/pinctrl/pinctrl-single.c @@ -47,7 +47,7 @@ static int single_configure_pins(struct udevice *dev, const struct single_fdt_pin_cfg *pins, int size) { - struct single_pdata *pdata = dev->plat; + struct single_pdata *pdata = dev_get_plat(dev); int count = size / sizeof(struct single_fdt_pin_cfg); phys_addr_t n, reg; u32 val; @@ -81,7 +81,7 @@ static int single_configure_bits(struct udevice *dev, const struct single_fdt_bits_cfg *pins, int size) { - struct single_pdata *pdata = dev->plat; + struct single_pdata *pdata = dev_get_plat(dev); int count = size / sizeof(struct single_fdt_bits_cfg); phys_addr_t n, reg; u32 val, mask; @@ -153,7 +153,7 @@ static int single_of_to_plat(struct udevice *dev) fdt_addr_t addr; u32 of_reg[2]; int res; - struct single_pdata *pdata = dev->plat; + struct single_pdata *pdata = dev_get_plat(dev); pdata->width = dev_read_u32_default(dev, "pinctrl-single,register-width", 0); diff --git a/drivers/power/regulator/da9063.c b/drivers/power/regulator/da9063.c index 32be59e49e..8df1abcf78 100644 --- a/drivers/power/regulator/da9063.c +++ b/drivers/power/regulator/da9063.c @@ -135,7 +135,7 @@ static const struct da9063_reg_info da9063_buck_info[] = { static int da9063_get_enable(struct udevice *dev) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; int ret; @@ -148,7 +148,7 @@ static int da9063_get_enable(struct udevice *dev) static int da9063_set_enable(struct udevice *dev, bool enable) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; return pmic_clrsetbits(dev->parent, info->en_reg, @@ -157,7 +157,7 @@ static int da9063_set_enable(struct udevice *dev, bool enable) static int da9063_get_voltage(struct udevice *dev) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; int ret; @@ -170,7 +170,7 @@ static int da9063_get_voltage(struct udevice *dev) static int da9063_set_voltage(struct udevice *dev, int uV) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; uint sel; @@ -198,7 +198,7 @@ static const struct dm_regulator_mode static int ldo_get_mode(struct udevice *dev) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; int val; @@ -214,7 +214,7 @@ static int ldo_get_mode(struct udevice *dev) static int ldo_set_mode(struct udevice *dev, int mode_id) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; const struct dm_regulator_mode *mode; @@ -230,7 +230,7 @@ static int ldo_set_mode(struct udevice *dev, int mode_id) static int buck_get_mode(struct udevice *dev) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; int i; int val; @@ -261,7 +261,7 @@ static int buck_get_mode(struct udevice *dev) static int buck_set_mode(struct udevice *dev, int mode_id) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; const struct dm_regulator_mode *mode; @@ -277,7 +277,7 @@ static int buck_set_mode(struct udevice *dev, int mode_id) static int buck_get_current_limit(struct udevice *dev) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; int val; @@ -293,7 +293,7 @@ static int buck_get_current_limit(struct udevice *dev) static int buck_set_current_limit(struct udevice *dev, int uA) { - const struct da9063_priv *priv = dev->priv; + const struct da9063_priv *priv = dev_get_priv(dev); const struct da9063_reg_info *info = priv->reg_info; int val; @@ -310,7 +310,7 @@ static int buck_set_current_limit(struct udevice *dev, int uA) static int da9063_ldo_probe(struct udevice *dev) { struct dm_regulator_uclass_plat *uc_pdata; - struct da9063_priv *priv = dev->priv; + struct da9063_priv *priv = dev_get_priv(dev); /* LDOs are named numerically in DT so can directly index */ if (dev->driver_data < 1 || @@ -329,7 +329,7 @@ static int da9063_ldo_probe(struct udevice *dev) static int da9063_buck_probe(struct udevice *dev) { struct dm_regulator_uclass_plat *uc_pdata; - struct da9063_priv *priv = dev->priv; + struct da9063_priv *priv = dev_get_priv(dev); int i; /* Bucks have names rather than numbers so need to match with DT */ diff --git a/drivers/power/regulator/pbias_regulator.c b/drivers/power/regulator/pbias_regulator.c index c3df156749..6f0d0a59ff 100644 --- a/drivers/power/regulator/pbias_regulator.c +++ b/drivers/power/regulator/pbias_regulator.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #ifdef CONFIG_MMC_OMAP36XX_PINS #include @@ -208,7 +209,7 @@ static int pbias_regulator_probe(struct udevice *dev) } uc_pdata->type = REGULATOR_TYPE_OTHER; - dev->priv = (void *)*p; + dev_set_priv(dev, (void *)*p); return 0; } diff --git a/drivers/remoteproc/rproc-uclass.c b/drivers/remoteproc/rproc-uclass.c index ccc910e7c7..773b8119f4 100644 --- a/drivers/remoteproc/rproc-uclass.c +++ b/drivers/remoteproc/rproc-uclass.c @@ -115,7 +115,7 @@ static int rproc_pre_probe(struct udevice *dev) /* See if we need to populate via fdt */ - if (!dev->plat) { + if (!dev_get_plat(dev)) { #if CONFIG_IS_ENABLED(OF_CONTROL) int node = dev_of_offset(dev); const void *blob = gd->fdt_blob; @@ -140,7 +140,7 @@ static int rproc_pre_probe(struct udevice *dev) #endif } else { - struct dm_rproc_uclass_pdata *pdata = dev->plat; + struct dm_rproc_uclass_pdata *pdata = dev_get_plat(dev); debug("'%s': using legacy data\n", dev->name); if (pdata->name) diff --git a/drivers/reset/reset-mediatek.c b/drivers/reset/reset-mediatek.c index b97a21f671..7427013ab6 100644 --- a/drivers/reset/reset-mediatek.c +++ b/drivers/reset/reset-mediatek.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -92,7 +93,7 @@ int mediatek_reset_bind(struct udevice *pdev, u32 regofs, u32 num_regs) priv = malloc(sizeof(struct mediatek_reset_priv)); priv->regofs = regofs; priv->nr_resets = num_regs * 32; - rst_dev->priv = priv; + dev_set_priv(rst_dev, priv); return 0; } diff --git a/drivers/reset/reset-rockchip.c b/drivers/reset/reset-rockchip.c index e5e9918c0c..eeb3d2eea7 100644 --- a/drivers/reset/reset-rockchip.c +++ b/drivers/reset/reset-rockchip.c @@ -11,6 +11,7 @@ #include #include #include +#include #include /* * Each reg has 16 bits reset signal for devices @@ -121,7 +122,7 @@ int rockchip_reset_bind(struct udevice *pdev, u32 reg_offset, u32 reg_number) priv = malloc(sizeof(struct rockchip_reset_priv)); priv->reset_reg_offset = reg_offset; priv->reset_reg_num = reg_number; - rst_dev->priv = priv; + dev_set_priv(rst_dev, priv); return 0; } diff --git a/drivers/reset/reset-sifive.c b/drivers/reset/reset-sifive.c index f6110d85f9..eec840d677 100644 --- a/drivers/reset/reset-sifive.c +++ b/drivers/reset/reset-sifive.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -97,7 +98,7 @@ int sifive_reset_bind(struct udevice *dev, ulong count) } priv = malloc(sizeof(struct sifive_reset_priv)); priv->nr_reset = count; - rst_dev->priv = priv; + dev_set_priv(rst_dev, priv); return 0; } diff --git a/drivers/reset/reset-sunxi.c b/drivers/reset/reset-sunxi.c index 1db321ce1f..264337ed80 100644 --- a/drivers/reset/reset-sunxi.c +++ b/drivers/reset/reset-sunxi.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -113,7 +114,7 @@ int sunxi_reset_bind(struct udevice *dev, ulong count) priv = malloc(sizeof(struct sunxi_reset_priv)); priv->count = count; priv->desc = (const struct ccu_desc *)dev_get_driver_data(dev); - rst_dev->priv = priv; + dev_set_priv(rst_dev, priv); return 0; } diff --git a/drivers/serial/altera_jtag_uart.c b/drivers/serial/altera_jtag_uart.c index 0d3ccd880c..4435fcf56b 100644 --- a/drivers/serial/altera_jtag_uart.c +++ b/drivers/serial/altera_jtag_uart.c @@ -37,7 +37,7 @@ static int altera_jtaguart_setbrg(struct udevice *dev, int baudrate) static int altera_jtaguart_putc(struct udevice *dev, const char ch) { - struct altera_jtaguart_plat *plat = dev->plat; + struct altera_jtaguart_plat *plat = dev_get_plat(dev); struct altera_jtaguart_regs *const regs = plat->regs; u32 st = readl(®s->control); @@ -56,7 +56,7 @@ static int altera_jtaguart_putc(struct udevice *dev, const char ch) static int altera_jtaguart_pending(struct udevice *dev, bool input) { - struct altera_jtaguart_plat *plat = dev->plat; + struct altera_jtaguart_plat *plat = dev_get_plat(dev); struct altera_jtaguart_regs *const regs = plat->regs; u32 st = readl(®s->control); @@ -68,7 +68,7 @@ static int altera_jtaguart_pending(struct udevice *dev, bool input) static int altera_jtaguart_getc(struct udevice *dev) { - struct altera_jtaguart_plat *plat = dev->plat; + struct altera_jtaguart_plat *plat = dev_get_plat(dev); struct altera_jtaguart_regs *const regs = plat->regs; u32 val; @@ -83,7 +83,7 @@ static int altera_jtaguart_getc(struct udevice *dev) static int altera_jtaguart_probe(struct udevice *dev) { #ifdef CONFIG_ALTERA_JTAG_UART_BYPASS - struct altera_jtaguart_plat *plat = dev->plat; + struct altera_jtaguart_plat *plat = dev_get_plat(dev); struct altera_jtaguart_regs *const regs = plat->regs; writel(ALTERA_JTAG_AC, ®s->control); /* clear AC flag */ diff --git a/drivers/serial/altera_uart.c b/drivers/serial/altera_uart.c index a3efa1ee1b..b18be6e245 100644 --- a/drivers/serial/altera_uart.c +++ b/drivers/serial/altera_uart.c @@ -32,7 +32,7 @@ struct altera_uart_plat { static int altera_uart_setbrg(struct udevice *dev, int baudrate) { - struct altera_uart_plat *plat = dev->plat; + struct altera_uart_plat *plat = dev_get_plat(dev); struct altera_uart_regs *const regs = plat->regs; u32 div; @@ -44,7 +44,7 @@ static int altera_uart_setbrg(struct udevice *dev, int baudrate) static int altera_uart_putc(struct udevice *dev, const char ch) { - struct altera_uart_plat *plat = dev->plat; + struct altera_uart_plat *plat = dev_get_plat(dev); struct altera_uart_regs *const regs = plat->regs; if (!(readl(®s->status) & ALTERA_UART_TRDY)) @@ -57,7 +57,7 @@ static int altera_uart_putc(struct udevice *dev, const char ch) static int altera_uart_pending(struct udevice *dev, bool input) { - struct altera_uart_plat *plat = dev->plat; + struct altera_uart_plat *plat = dev_get_plat(dev); struct altera_uart_regs *const regs = plat->regs; u32 st = readl(®s->status); @@ -69,7 +69,7 @@ static int altera_uart_pending(struct udevice *dev, bool input) static int altera_uart_getc(struct udevice *dev) { - struct altera_uart_plat *plat = dev->plat; + struct altera_uart_plat *plat = dev_get_plat(dev); struct altera_uart_regs *const regs = plat->regs; if (!(readl(®s->status) & ALTERA_UART_RRDY)) diff --git a/drivers/serial/atmel_usart.c b/drivers/serial/atmel_usart.c index 7eabf76d92..7edec23e64 100644 --- a/drivers/serial/atmel_usart.c +++ b/drivers/serial/atmel_usart.c @@ -262,7 +262,7 @@ static int atmel_serial_enable_clk(struct udevice *dev) static int atmel_serial_probe(struct udevice *dev) { - struct atmel_serial_plat *plat = dev->plat; + struct atmel_serial_plat *plat = dev_get_plat(dev); struct atmel_serial_priv *priv = dev_get_priv(dev); int ret; #if CONFIG_IS_ENABLED(OF_CONTROL) diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 17808fb70a..508c134b94 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -498,7 +498,7 @@ static int ns16550_serial_assign_base(struct ns16550_plat *plat, ulong base) int ns16550_serial_probe(struct udevice *dev) { - struct ns16550_plat *plat = dev->plat; + struct ns16550_plat *plat = dev_get_plat(dev); struct ns16550 *const com_port = dev_get_priv(dev); struct reset_ctl_bulk reset_bulk; fdt_addr_t addr; @@ -535,7 +535,7 @@ enum { #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) int ns16550_serial_of_to_plat(struct udevice *dev) { - struct ns16550_plat *plat = dev->plat; + struct ns16550_plat *plat = dev_get_plat(dev); const u32 port_type = dev_get_driver_data(dev); fdt_addr_t addr; struct clk clk; diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index c7d5390b43..a05c56458b 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -72,7 +72,7 @@ static int sandbox_serial_probe(struct udevice *dev) static int sandbox_serial_remove(struct udevice *dev) { - struct sandbox_serial_plat *plat = dev->plat; + struct sandbox_serial_plat *plat = dev_get_plat(dev); if (plat->colour != -1) output_ansi_reset(); @@ -83,7 +83,7 @@ static int sandbox_serial_remove(struct udevice *dev) static int sandbox_serial_putc(struct udevice *dev, const char ch) { struct sandbox_serial_priv *priv = dev_get_priv(dev); - struct sandbox_serial_plat *plat = dev->plat; + struct sandbox_serial_plat *plat = dev_get_plat(dev); /* With of-platdata we don't real the colour correctly, so disable it */ if (!CONFIG_IS_ENABLED(OF_PLATDATA) && priv->start_of_line && @@ -203,7 +203,7 @@ static const char * const ansi_colour[] = { static int sandbox_serial_of_to_plat(struct udevice *dev) { - struct sandbox_serial_plat *plat = dev->plat; + struct sandbox_serial_plat *plat = dev_get_plat(dev); const char *colour; int i; diff --git a/drivers/serial/serial_arc.c b/drivers/serial/serial_arc.c index 022e37748c..445eacc8aa 100644 --- a/drivers/serial/serial_arc.c +++ b/drivers/serial/serial_arc.c @@ -37,7 +37,7 @@ struct arc_serial_plat { static int arc_serial_setbrg(struct udevice *dev, int baudrate) { - struct arc_serial_plat *plat = dev->plat; + struct arc_serial_plat *plat = dev_get_plat(dev); struct arc_serial_regs *const regs = plat->reg; int arc_console_baud = gd->cpu_clk / (baudrate * 4) - 1; @@ -49,7 +49,7 @@ static int arc_serial_setbrg(struct udevice *dev, int baudrate) static int arc_serial_putc(struct udevice *dev, const char c) { - struct arc_serial_plat *plat = dev->plat; + struct arc_serial_plat *plat = dev_get_plat(dev); struct arc_serial_regs *const regs = plat->reg; while (!(readb(®s->status) & UART_TXEMPTY)) @@ -67,7 +67,7 @@ static int arc_serial_tstc(struct arc_serial_regs *const regs) static int arc_serial_pending(struct udevice *dev, bool input) { - struct arc_serial_plat *plat = dev->plat; + struct arc_serial_plat *plat = dev_get_plat(dev); struct arc_serial_regs *const regs = plat->reg; uint32_t status = readb(®s->status); @@ -79,7 +79,7 @@ static int arc_serial_pending(struct udevice *dev, bool input) static int arc_serial_getc(struct udevice *dev) { - struct arc_serial_plat *plat = dev->plat; + struct arc_serial_plat *plat = dev_get_plat(dev); struct arc_serial_regs *const regs = plat->reg; while (!arc_serial_tstc(regs)) diff --git a/drivers/serial/serial_linflexuart.c b/drivers/serial/serial_linflexuart.c index ced005706a..c3714e1e1e 100644 --- a/drivers/serial/serial_linflexuart.c +++ b/drivers/serial/serial_linflexuart.c @@ -168,7 +168,7 @@ static void linflex_serial_init_internal(struct linflex_fsl *lfuart) static int linflex_serial_probe(struct udevice *dev) { - struct linflex_serial_plat *plat = dev->plat; + struct linflex_serial_plat *plat = dev_get_plat(dev); struct linflex_serial_priv *priv = dev_get_priv(dev); priv->lfuart = (struct linflex_fsl *)plat->base_addr; diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c index 5beb5f2ce6..a35e5be303 100644 --- a/drivers/serial/serial_lpuart.c +++ b/drivers/serial/serial_lpuart.c @@ -138,7 +138,7 @@ static inline int get_lpuart_clk_rate(struct udevice *dev, u32 *clk) static bool is_lpuart32(struct udevice *dev) { - struct lpuart_serial_plat *plat = dev->plat; + struct lpuart_serial_plat *plat = dev_get_plat(dev); return plat->flags & LPUART_FLAG_REGMAP_32BIT_REG; } @@ -445,7 +445,7 @@ static int lpuart_serial_setbrg(struct udevice *dev, int baudrate) static int lpuart_serial_getc(struct udevice *dev) { - struct lpuart_serial_plat *plat = dev->plat; + struct lpuart_serial_plat *plat = dev_get_plat(dev); if (is_lpuart32(dev)) return _lpuart32_serial_getc(plat); @@ -455,7 +455,7 @@ static int lpuart_serial_getc(struct udevice *dev) static int lpuart_serial_putc(struct udevice *dev, const char c) { - struct lpuart_serial_plat *plat = dev->plat; + struct lpuart_serial_plat *plat = dev_get_plat(dev); if (is_lpuart32(dev)) _lpuart32_serial_putc(plat, c); @@ -467,7 +467,7 @@ static int lpuart_serial_putc(struct udevice *dev, const char c) static int lpuart_serial_pending(struct udevice *dev, bool input) { - struct lpuart_serial_plat *plat = dev->plat; + struct lpuart_serial_plat *plat = dev_get_plat(dev); struct lpuart_fsl *reg = plat->reg; struct lpuart_fsl_reg32 *reg32 = plat->reg; u32 stat; @@ -513,7 +513,7 @@ static int lpuart_serial_probe(struct udevice *dev) static int lpuart_serial_of_to_plat(struct udevice *dev) { - struct lpuart_serial_plat *plat = dev->plat; + struct lpuart_serial_plat *plat = dev_get_plat(dev); const void *blob = gd->fdt_blob; int node = dev_of_offset(dev); fdt_addr_t addr; diff --git a/drivers/serial/serial_mcf.c b/drivers/serial/serial_mcf.c index 4ba6dc32f9..e6e21b2ce8 100644 --- a/drivers/serial/serial_mcf.c +++ b/drivers/serial/serial_mcf.c @@ -83,7 +83,7 @@ static void mcf_serial_setbrg_common(uart_t *uart, int baudrate) static int coldfire_serial_probe(struct udevice *dev) { - struct coldfire_serial_plat *plat = dev->plat; + struct coldfire_serial_plat *plat = dev_get_plat(dev); plat->port = dev_seq(dev); @@ -93,7 +93,7 @@ static int coldfire_serial_probe(struct udevice *dev) static int coldfire_serial_putc(struct udevice *dev, const char ch) { - struct coldfire_serial_plat *plat = dev->plat; + struct coldfire_serial_plat *plat = dev_get_plat(dev); uart_t *uart = (uart_t *)plat->base; /* Wait for last character to go. */ @@ -107,7 +107,7 @@ static int coldfire_serial_putc(struct udevice *dev, const char ch) static int coldfire_serial_getc(struct udevice *dev) { - struct coldfire_serial_plat *plat = dev->plat; + struct coldfire_serial_plat *plat = dev_get_plat(dev); uart_t *uart = (uart_t *)(plat->base); /* Wait for a character to arrive. */ @@ -119,7 +119,7 @@ static int coldfire_serial_getc(struct udevice *dev) int coldfire_serial_setbrg(struct udevice *dev, int baudrate) { - struct coldfire_serial_plat *plat = dev->plat; + struct coldfire_serial_plat *plat = dev_get_plat(dev); uart_t *uart = (uart_t *)(plat->base); mcf_serial_setbrg_common(uart, baudrate); @@ -129,7 +129,7 @@ int coldfire_serial_setbrg(struct udevice *dev, int baudrate) static int coldfire_serial_pending(struct udevice *dev, bool input) { - struct coldfire_serial_plat *plat = dev->plat; + struct coldfire_serial_plat *plat = dev_get_plat(dev); uart_t *uart = (uart_t *)(plat->base); if (input) diff --git a/drivers/serial/serial_meson.c b/drivers/serial/serial_meson.c index 40d9bfe7c6..d69ec221e4 100644 --- a/drivers/serial/serial_meson.c +++ b/drivers/serial/serial_meson.c @@ -57,7 +57,7 @@ static void meson_serial_init(struct meson_uart *uart) static int meson_serial_probe(struct udevice *dev) { - struct meson_serial_plat *plat = dev->plat; + struct meson_serial_plat *plat = dev_get_plat(dev); struct meson_uart *const uart = plat->reg; meson_serial_init(uart); @@ -67,7 +67,7 @@ static int meson_serial_probe(struct udevice *dev) static void meson_serial_rx_error(struct udevice *dev) { - struct meson_serial_plat *plat = dev->plat; + struct meson_serial_plat *plat = dev_get_plat(dev); struct meson_uart *const uart = plat->reg; u32 val = readl(&uart->control); @@ -83,7 +83,7 @@ static void meson_serial_rx_error(struct udevice *dev) static int meson_serial_getc(struct udevice *dev) { - struct meson_serial_plat *plat = dev->plat; + struct meson_serial_plat *plat = dev_get_plat(dev); struct meson_uart *const uart = plat->reg; uint32_t status = readl(&uart->status); @@ -100,7 +100,7 @@ static int meson_serial_getc(struct udevice *dev) static int meson_serial_putc(struct udevice *dev, const char ch) { - struct meson_serial_plat *plat = dev->plat; + struct meson_serial_plat *plat = dev_get_plat(dev); struct meson_uart *const uart = plat->reg; if (readl(&uart->status) & AML_UART_TX_FULL) @@ -113,7 +113,7 @@ static int meson_serial_putc(struct udevice *dev, const char ch) static int meson_serial_pending(struct udevice *dev, bool input) { - struct meson_serial_plat *plat = dev->plat; + struct meson_serial_plat *plat = dev_get_plat(dev); struct meson_uart *const uart = plat->reg; uint32_t status = readl(&uart->status); @@ -138,7 +138,7 @@ static int meson_serial_pending(struct udevice *dev, bool input) static int meson_serial_of_to_plat(struct udevice *dev) { - struct meson_serial_plat *plat = dev->plat; + struct meson_serial_plat *plat = dev_get_plat(dev); fdt_addr_t addr; addr = dev_read_addr(dev); diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c index 2603fa8611..e5795da99d 100644 --- a/drivers/serial/serial_mxc.c +++ b/drivers/serial/serial_mxc.c @@ -264,7 +264,7 @@ __weak struct serial_device *default_serial_console(void) int mxc_serial_setbrg(struct udevice *dev, int baudrate) { - struct mxc_serial_plat *plat = dev->plat; + struct mxc_serial_plat *plat = dev_get_plat(dev); u32 clk = imx_get_uartclk(); _mxc_serial_setbrg(plat->reg, clk, baudrate, plat->use_dte); @@ -274,7 +274,7 @@ int mxc_serial_setbrg(struct udevice *dev, int baudrate) static int mxc_serial_probe(struct udevice *dev) { - struct mxc_serial_plat *plat = dev->plat; + struct mxc_serial_plat *plat = dev_get_plat(dev); _mxc_serial_init(plat->reg, plat->use_dte); @@ -283,7 +283,7 @@ static int mxc_serial_probe(struct udevice *dev) static int mxc_serial_getc(struct udevice *dev) { - struct mxc_serial_plat *plat = dev->plat; + struct mxc_serial_plat *plat = dev_get_plat(dev); struct mxc_uart *const uart = plat->reg; if (readl(&uart->ts) & UTS_RXEMPTY) @@ -294,7 +294,7 @@ static int mxc_serial_getc(struct udevice *dev) static int mxc_serial_putc(struct udevice *dev, const char ch) { - struct mxc_serial_plat *plat = dev->plat; + struct mxc_serial_plat *plat = dev_get_plat(dev); struct mxc_uart *const uart = plat->reg; if (!(readl(&uart->ts) & UTS_TXEMPTY)) @@ -307,7 +307,7 @@ static int mxc_serial_putc(struct udevice *dev, const char ch) static int mxc_serial_pending(struct udevice *dev, bool input) { - struct mxc_serial_plat *plat = dev->plat; + struct mxc_serial_plat *plat = dev_get_plat(dev); struct mxc_uart *const uart = plat->reg; uint32_t sr2 = readl(&uart->sr2); @@ -327,7 +327,7 @@ static const struct dm_serial_ops mxc_serial_ops = { #if CONFIG_IS_ENABLED(OF_CONTROL) static int mxc_serial_of_to_plat(struct udevice *dev) { - struct mxc_serial_plat *plat = dev->plat; + struct mxc_serial_plat *plat = dev_get_plat(dev); fdt_addr_t addr; addr = dev_read_addr(dev); diff --git a/drivers/serial/serial_omap.c b/drivers/serial/serial_omap.c index c235215541..2b23ece442 100644 --- a/drivers/serial/serial_omap.c +++ b/drivers/serial/serial_omap.c @@ -101,7 +101,7 @@ DEBUG_UART_FUNCS #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) static int omap_serial_of_to_plat(struct udevice *dev) { - struct ns16550_plat *plat = dev->plat; + struct ns16550_plat *plat = dev_get_plat(dev); fdt_addr_t addr; struct clk clk; int err; diff --git a/drivers/serial/serial_pxa.c b/drivers/serial/serial_pxa.c index d82f3b9752..669841ede4 100644 --- a/drivers/serial/serial_pxa.c +++ b/drivers/serial/serial_pxa.c @@ -268,7 +268,7 @@ void pxa_serial_initialize(void) #ifdef CONFIG_DM_SERIAL static int pxa_serial_probe(struct udevice *dev) { - struct pxa_serial_plat *plat = dev->plat; + struct pxa_serial_plat *plat = dev_get_plat(dev); pxa_setbrg_common((struct pxa_uart_regs *)plat->base, plat->port, plat->baudrate); @@ -277,7 +277,7 @@ static int pxa_serial_probe(struct udevice *dev) static int pxa_serial_putc(struct udevice *dev, const char ch) { - struct pxa_serial_plat *plat = dev->plat; + struct pxa_serial_plat *plat = dev_get_plat(dev); struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base; /* Wait for last character to go. */ @@ -291,7 +291,7 @@ static int pxa_serial_putc(struct udevice *dev, const char ch) static int pxa_serial_getc(struct udevice *dev) { - struct pxa_serial_plat *plat = dev->plat; + struct pxa_serial_plat *plat = dev_get_plat(dev); struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base; /* Wait for a character to arrive. */ @@ -303,7 +303,7 @@ static int pxa_serial_getc(struct udevice *dev) int pxa_serial_setbrg(struct udevice *dev, int baudrate) { - struct pxa_serial_plat *plat = dev->plat; + struct pxa_serial_plat *plat = dev_get_plat(dev); struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base; int port = plat->port; @@ -314,7 +314,7 @@ int pxa_serial_setbrg(struct udevice *dev, int baudrate) static int pxa_serial_pending(struct udevice *dev, bool input) { - struct pxa_serial_plat *plat = dev->plat; + struct pxa_serial_plat *plat = dev_get_plat(dev); struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base; if (input) diff --git a/drivers/serial/serial_rockchip.c b/drivers/serial/serial_rockchip.c index 036c07262b..97d40869a2 100644 --- a/drivers/serial/serial_rockchip.c +++ b/drivers/serial/serial_rockchip.c @@ -10,6 +10,7 @@ #include #include #include +#include #if defined(CONFIG_ROCKCHIP_RK3188) struct rockchip_uart_plat { @@ -34,7 +35,7 @@ static int rockchip_serial_probe(struct udevice *dev) plat->plat.reg_shift = plat->dtplat.reg_shift; plat->plat.clock = plat->dtplat.clock_frequency; plat->plat.fcr = UART_FCR_DEFVAL; - dev->plat = &plat->plat; + dev_set_plat(dev, &plat->plat); return ns16550_serial_probe(dev); } diff --git a/drivers/serial/serial_s5p.c b/drivers/serial/serial_s5p.c index 120df835db..0eac0d53a5 100644 --- a/drivers/serial/serial_s5p.c +++ b/drivers/serial/serial_s5p.c @@ -88,7 +88,7 @@ static void __maybe_unused s5p_serial_baud(struct s5p_uart *uart, uint uclk, #ifndef CONFIG_SPL_BUILD int s5p_serial_setbrg(struct udevice *dev, int baudrate) { - struct s5p_serial_plat *plat = dev->plat; + struct s5p_serial_plat *plat = dev_get_plat(dev); struct s5p_uart *const uart = plat->reg; u32 uclk; @@ -111,7 +111,7 @@ int s5p_serial_setbrg(struct udevice *dev, int baudrate) static int s5p_serial_probe(struct udevice *dev) { - struct s5p_serial_plat *plat = dev->plat; + struct s5p_serial_plat *plat = dev_get_plat(dev); struct s5p_uart *const uart = plat->reg; s5p_serial_init(uart); @@ -140,7 +140,7 @@ static int serial_err_check(const struct s5p_uart *const uart, int op) static int s5p_serial_getc(struct udevice *dev) { - struct s5p_serial_plat *plat = dev->plat; + struct s5p_serial_plat *plat = dev_get_plat(dev); struct s5p_uart *const uart = plat->reg; if (!(readl(&uart->ufstat) & RX_FIFO_COUNT_MASK)) @@ -152,7 +152,7 @@ static int s5p_serial_getc(struct udevice *dev) static int s5p_serial_putc(struct udevice *dev, const char ch) { - struct s5p_serial_plat *plat = dev->plat; + struct s5p_serial_plat *plat = dev_get_plat(dev); struct s5p_uart *const uart = plat->reg; if (readl(&uart->ufstat) & TX_FIFO_FULL) @@ -166,7 +166,7 @@ static int s5p_serial_putc(struct udevice *dev, const char ch) static int s5p_serial_pending(struct udevice *dev, bool input) { - struct s5p_serial_plat *plat = dev->plat; + struct s5p_serial_plat *plat = dev_get_plat(dev); struct s5p_uart *const uart = plat->reg; uint32_t ufstat = readl(&uart->ufstat); @@ -178,7 +178,7 @@ static int s5p_serial_pending(struct udevice *dev, bool input) static int s5p_serial_of_to_plat(struct udevice *dev) { - struct s5p_serial_plat *plat = dev->plat; + struct s5p_serial_plat *plat = dev_get_plat(dev); fdt_addr_t addr; addr = dev_read_addr(dev); diff --git a/drivers/spi/cadence_qspi.c b/drivers/spi/cadence_qspi.c index b746501f5f..67980431ba 100644 --- a/drivers/spi/cadence_qspi.c +++ b/drivers/spi/cadence_qspi.c @@ -27,7 +27,7 @@ static int cadence_spi_write_speed(struct udevice *bus, uint hz) { - struct cadence_spi_plat *plat = bus->plat; + struct cadence_spi_plat *plat = dev_get_plat(bus); struct cadence_spi_priv *priv = dev_get_priv(bus); cadence_qspi_apb_config_baudrate_div(priv->regbase, @@ -130,7 +130,7 @@ static int spi_calibration(struct udevice *bus, uint hz) static int cadence_spi_set_speed(struct udevice *bus, uint hz) { - struct cadence_spi_plat *plat = bus->plat; + struct cadence_spi_plat *plat = dev_get_plat(bus); struct cadence_spi_priv *priv = dev_get_priv(bus); int err; @@ -165,7 +165,7 @@ static int cadence_spi_set_speed(struct udevice *bus, uint hz) static int cadence_spi_probe(struct udevice *bus) { - struct cadence_spi_plat *plat = bus->plat; + struct cadence_spi_plat *plat = dev_get_plat(bus); struct cadence_spi_priv *priv = dev_get_priv(bus); struct clk clk; int ret; @@ -212,7 +212,7 @@ static int cadence_spi_remove(struct udevice *dev) static int cadence_spi_set_mode(struct udevice *bus, uint mode) { - struct cadence_spi_plat *plat = bus->plat; + struct cadence_spi_plat *plat = dev_get_plat(bus); struct cadence_spi_priv *priv = dev_get_priv(bus); /* Disable QSPI */ @@ -235,7 +235,7 @@ static int cadence_spi_mem_exec_op(struct spi_slave *spi, const struct spi_mem_op *op) { struct udevice *bus = spi->dev->parent; - struct cadence_spi_plat *plat = bus->plat; + struct cadence_spi_plat *plat = dev_get_plat(bus); struct cadence_spi_priv *priv = dev_get_priv(bus); void *base = priv->regbase; int err = 0; @@ -284,7 +284,7 @@ static int cadence_spi_mem_exec_op(struct spi_slave *spi, static int cadence_spi_of_to_plat(struct udevice *bus) { - struct cadence_spi_plat *plat = bus->plat; + struct cadence_spi_plat *plat = dev_get_plat(bus); ofnode subnode; plat->regbase = (void *)devfdt_get_addr_index(bus, 0); diff --git a/drivers/spi/cf_spi.c b/drivers/spi/cf_spi.c index 8adff63edc..298f350ef3 100644 --- a/drivers/spi/cf_spi.c +++ b/drivers/spi/cf_spi.c @@ -387,7 +387,7 @@ static int coldfire_spi_probe(struct udevice *bus) static int coldfire_dspi_of_to_plat(struct udevice *bus) { fdt_addr_t addr; - struct coldfire_spi_plat *plat = bus->plat; + struct coldfire_spi_plat *plat = dev_get_plat(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); int *ctar, len; diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c index ea088ebd2c..53a791ea29 100644 --- a/drivers/spi/davinci_spi.c +++ b/drivers/spi/davinci_spi.c @@ -383,7 +383,7 @@ static const struct dm_spi_ops davinci_spi_ops = { static int davinci_spi_probe(struct udevice *bus) { struct davinci_spi_slave *ds = dev_get_priv(bus); - struct davinci_spi_plat *plat = bus->plat; + struct davinci_spi_plat *plat = dev_get_plat(bus); ds->regs = plat->regs; ds->num_cs = plat->num_cs; @@ -393,7 +393,7 @@ static int davinci_spi_probe(struct udevice *bus) #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) static int davinci_ofdata_to_platadata(struct udevice *bus) { - struct davinci_spi_plat *plat = bus->plat; + struct davinci_spi_plat *plat = dev_get_plat(bus); fdt_addr_t addr; addr = dev_read_addr(bus); diff --git a/drivers/spi/designware_spi.c b/drivers/spi/designware_spi.c index 4fa4585fc3..5ede00d080 100644 --- a/drivers/spi/designware_spi.c +++ b/drivers/spi/designware_spi.c @@ -155,7 +155,7 @@ static int request_gpio_cs(struct udevice *bus) static int dw_spi_of_to_plat(struct udevice *bus) { - struct dw_spi_plat *plat = bus->plat; + struct dw_spi_plat *plat = dev_get_plat(bus); plat->regs = dev_read_addr_ptr(bus); @@ -478,7 +478,7 @@ static int dw_spi_xfer(struct udevice *dev, unsigned int bitlen, static int dw_spi_set_speed(struct udevice *bus, uint speed) { - struct dw_spi_plat *plat = bus->plat; + struct dw_spi_plat *plat = dev_get_plat(bus); struct dw_spi_priv *priv = dev_get_priv(bus); u16 clk_div; diff --git a/drivers/spi/exynos_spi.c b/drivers/spi/exynos_spi.c index e4d2bade0f..30b1a77a73 100644 --- a/drivers/spi/exynos_spi.c +++ b/drivers/spi/exynos_spi.c @@ -253,7 +253,7 @@ static void spi_cs_deactivate(struct udevice *dev) static int exynos_spi_of_to_plat(struct udevice *bus) { - struct exynos_spi_plat *plat = bus->plat; + struct exynos_spi_plat *plat = dev_get_plat(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); @@ -368,7 +368,7 @@ static int exynos_spi_xfer(struct udevice *dev, unsigned int bitlen, static int exynos_spi_set_speed(struct udevice *bus, uint speed) { - struct exynos_spi_plat *plat = bus->plat; + struct exynos_spi_plat *plat = dev_get_plat(bus); struct exynos_spi_priv *priv = dev_get_priv(bus); int ret; diff --git a/drivers/spi/fsl_dspi.c b/drivers/spi/fsl_dspi.c index ddf4a9e413..b8c0216b39 100644 --- a/drivers/spi/fsl_dspi.c +++ b/drivers/spi/fsl_dspi.c @@ -486,7 +486,7 @@ static int fsl_dspi_probe(struct udevice *bus) struct dm_spi_bus *dm_spi_bus; uint mcr_cfg_val; - dm_spi_bus = bus->uclass_priv; + dm_spi_bus = dev_get_uclass_priv(bus); /* cpu speical pin muxing configure */ cpu_dspi_port_conf(); @@ -576,7 +576,7 @@ static int fsl_dspi_bind(struct udevice *bus) static int fsl_dspi_of_to_plat(struct udevice *bus) { fdt_addr_t addr; - struct fsl_dspi_plat *plat = bus->plat; + struct fsl_dspi_plat *plat = dev_get_plat(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); diff --git a/drivers/spi/fsl_espi.c b/drivers/spi/fsl_espi.c index e9e7ffd6b5..abc28e37d2 100644 --- a/drivers/spi/fsl_espi.c +++ b/drivers/spi/fsl_espi.c @@ -544,7 +544,7 @@ static const struct dm_spi_ops fsl_espi_ops = { static int fsl_espi_of_to_plat(struct udevice *bus) { fdt_addr_t addr; - struct fsl_espi_plat *plat = bus->plat; + struct fsl_espi_plat *plat = dev_get_plat(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c index fc3b844370..8bc7038a82 100644 --- a/drivers/spi/fsl_qspi.c +++ b/drivers/spi/fsl_qspi.c @@ -795,7 +795,7 @@ static const struct spi_controller_mem_ops fsl_qspi_mem_ops = { static int fsl_qspi_probe(struct udevice *bus) { - struct dm_spi_bus *dm_bus = bus->uclass_priv; + struct dm_spi_bus *dm_bus = dev_get_uclass_priv(bus); struct fsl_qspi *q = dev_get_priv(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c index 4fafe33af5..7f632d98bb 100644 --- a/drivers/spi/mxs_spi.c +++ b/drivers/spi/mxs_spi.c @@ -443,7 +443,7 @@ static const struct dm_spi_ops mxs_spi_ops = { #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) static int mxs_of_to_plat(struct udevice *bus) { - struct mxs_spi_plat *plat = bus->plat; + struct mxs_spi_plat *plat = dev_get_plat(bus); u32 prop[2]; int ret; diff --git a/drivers/spi/pl022_spi.c b/drivers/spi/pl022_spi.c index 179582cad7..133363ea7d 100644 --- a/drivers/spi/pl022_spi.c +++ b/drivers/spi/pl022_spi.c @@ -288,7 +288,7 @@ static const struct dm_spi_ops pl022_spi_ops = { #if !CONFIG_IS_ENABLED(OF_PLATDATA) static int pl022_spi_of_to_plat(struct udevice *bus) { - struct pl022_spi_pdata *plat = bus->plat; + struct pl022_spi_pdata *plat = dev_get_plat(bus); const void *fdt = gd->fdt_blob; int node = dev_of_offset(bus); struct clk clkdev; diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c index 44ac475c11..51abebb947 100644 --- a/drivers/spi/rk_spi.c +++ b/drivers/spi/rk_spi.c @@ -135,7 +135,7 @@ static int rkspi_wait_till_not_busy(struct rockchip_spi *regs) static void spi_cs_activate(struct udevice *dev, uint cs) { struct udevice *bus = dev->parent; - struct rockchip_spi_plat *plat = bus->plat; + struct rockchip_spi_plat *plat = dev_get_plat(bus); struct rockchip_spi_priv *priv = dev_get_priv(bus); struct rockchip_spi *regs = priv->regs; @@ -161,7 +161,7 @@ static void spi_cs_activate(struct udevice *dev, uint cs) static void spi_cs_deactivate(struct udevice *dev, uint cs) { struct udevice *bus = dev->parent; - struct rockchip_spi_plat *plat = bus->plat; + struct rockchip_spi_plat *plat = dev_get_plat(bus); struct rockchip_spi_priv *priv = dev_get_priv(bus); struct rockchip_spi *regs = priv->regs; @@ -176,7 +176,7 @@ static void spi_cs_deactivate(struct udevice *dev, uint cs) #if CONFIG_IS_ENABLED(OF_PLATDATA) static int conv_of_plat(struct udevice *dev) { - struct rockchip_spi_plat *plat = dev->plat; + struct rockchip_spi_plat *plat = dev_get_plat(dev); struct dtd_rockchip_rk3288_spi *dtplat = &plat->of_plat; struct rockchip_spi_priv *priv = dev_get_priv(dev); int ret; diff --git a/drivers/spi/soft_spi.c b/drivers/spi/soft_spi.c index afc98bfb66..3425d9950a 100644 --- a/drivers/spi/soft_spi.c +++ b/drivers/spi/soft_spi.c @@ -228,7 +228,7 @@ static const struct dm_spi_ops soft_spi_ops = { static int soft_spi_of_to_plat(struct udevice *dev) { - struct soft_spi_plat *plat = dev->plat; + struct soft_spi_plat *plat = dev_get_plat(dev); const void *blob = gd->fdt_blob; int node = dev_of_offset(dev); @@ -240,7 +240,7 @@ static int soft_spi_of_to_plat(struct udevice *dev) static int soft_spi_probe(struct udevice *dev) { struct spi_slave *slave = dev_get_parent_priv(dev); - struct soft_spi_plat *plat = dev->plat; + struct soft_spi_plat *plat = dev_get_plat(dev); int cs_flags, clk_flags; int ret; diff --git a/drivers/spi/tegra114_spi.c b/drivers/spi/tegra114_spi.c index e1fd82bdfa..f0256d8e66 100644 --- a/drivers/spi/tegra114_spi.c +++ b/drivers/spi/tegra114_spi.c @@ -99,7 +99,7 @@ struct tegra114_spi_priv { static int tegra114_spi_of_to_plat(struct udevice *bus) { - struct tegra_spi_plat *plat = bus->plat; + struct tegra_spi_plat *plat = dev_get_plat(bus); plat->base = dev_read_addr(bus); plat->periph_id = clock_decode_periph_id(bus); @@ -352,7 +352,7 @@ static int tegra114_spi_xfer(struct udevice *dev, unsigned int bitlen, static int tegra114_spi_set_speed(struct udevice *bus, uint speed) { - struct tegra_spi_plat *plat = bus->plat; + struct tegra_spi_plat *plat = dev_get_plat(bus); struct tegra114_spi_priv *priv = dev_get_priv(bus); if (speed > plat->frequency) diff --git a/drivers/spi/tegra20_sflash.c b/drivers/spi/tegra20_sflash.c index d38606100d..4384a48ec8 100644 --- a/drivers/spi/tegra20_sflash.c +++ b/drivers/spi/tegra20_sflash.c @@ -89,7 +89,7 @@ int tegra20_sflash_cs_info(struct udevice *bus, unsigned int cs, static int tegra20_sflash_of_to_plat(struct udevice *bus) { - struct tegra_spi_plat *plat = bus->plat; + struct tegra_spi_plat *plat = dev_get_plat(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); @@ -314,7 +314,7 @@ static int tegra20_sflash_xfer(struct udevice *dev, unsigned int bitlen, static int tegra20_sflash_set_speed(struct udevice *bus, uint speed) { - struct tegra_spi_plat *plat = bus->plat; + struct tegra_spi_plat *plat = dev_get_plat(bus); struct tegra20_sflash_priv *priv = dev_get_priv(bus); if (speed > plat->frequency) diff --git a/drivers/spi/tegra20_slink.c b/drivers/spi/tegra20_slink.c index b99ef38a14..3057fe1a22 100644 --- a/drivers/spi/tegra20_slink.c +++ b/drivers/spi/tegra20_slink.c @@ -95,7 +95,7 @@ struct tegra_spi_slave { static int tegra30_spi_of_to_plat(struct udevice *bus) { - struct tegra_spi_plat *plat = bus->plat; + struct tegra_spi_plat *plat = dev_get_plat(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); @@ -314,7 +314,7 @@ static int tegra30_spi_xfer(struct udevice *dev, unsigned int bitlen, static int tegra30_spi_set_speed(struct udevice *bus, uint speed) { - struct tegra_spi_plat *plat = bus->plat; + struct tegra_spi_plat *plat = dev_get_plat(bus); struct tegra30_spi_priv *priv = dev_get_priv(bus); if (speed > plat->frequency) diff --git a/drivers/spi/tegra210_qspi.c b/drivers/spi/tegra210_qspi.c index a2a7f4614c..b464b9ccb0 100644 --- a/drivers/spi/tegra210_qspi.c +++ b/drivers/spi/tegra210_qspi.c @@ -99,7 +99,7 @@ struct tegra210_qspi_priv { static int tegra210_qspi_of_to_plat(struct udevice *bus) { - struct tegra_spi_plat *plat = bus->plat; + struct tegra_spi_plat *plat = dev_get_plat(bus); plat->base = dev_read_addr(bus); plat->periph_id = clock_decode_periph_id(bus); @@ -380,7 +380,7 @@ static int tegra210_qspi_xfer(struct udevice *dev, unsigned int bitlen, static int tegra210_qspi_set_speed(struct udevice *bus, uint speed) { - struct tegra_spi_plat *plat = bus->plat; + struct tegra_spi_plat *plat = dev_get_plat(bus); struct tegra210_qspi_priv *priv = dev_get_priv(bus); if (speed > plat->frequency) diff --git a/drivers/spi/uniphier_spi.c b/drivers/spi/uniphier_spi.c index 48b8430d3d..e47ed5b221 100644 --- a/drivers/spi/uniphier_spi.c +++ b/drivers/spi/uniphier_spi.c @@ -113,7 +113,7 @@ static void uniphier_spi_regdump(struct uniphier_spi_priv *priv) static void spi_cs_activate(struct udevice *dev) { struct udevice *bus = dev->parent; - struct uniphier_spi_plat *plat = bus->plat; + struct uniphier_spi_plat *plat = dev_get_plat(bus); struct uniphier_spi_priv *priv = dev_get_priv(bus); ulong delay_us; /* The delay completed so far */ u32 val; @@ -139,7 +139,7 @@ static void spi_cs_activate(struct udevice *dev) static void spi_cs_deactivate(struct udevice *dev) { struct udevice *bus = dev->parent; - struct uniphier_spi_plat *plat = bus->plat; + struct uniphier_spi_plat *plat = dev_get_plat(bus); struct uniphier_spi_priv *priv = dev_get_priv(bus); u32 val; @@ -279,7 +279,7 @@ static int uniphier_spi_xfer(struct udevice *dev, unsigned int bitlen, static int uniphier_spi_set_speed(struct udevice *bus, uint speed) { - struct uniphier_spi_plat *plat = bus->plat; + struct uniphier_spi_plat *plat = dev_get_plat(bus); struct uniphier_spi_priv *priv = dev_get_priv(bus); u32 val, ckdiv; @@ -364,7 +364,7 @@ static int uniphier_spi_set_mode(struct udevice *bus, uint mode) static int uniphier_spi_of_to_plat(struct udevice *bus) { - struct uniphier_spi_plat *plat = bus->plat; + struct uniphier_spi_plat *plat = dev_get_plat(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); diff --git a/drivers/spi/zynq_qspi.c b/drivers/spi/zynq_qspi.c index 2fc28b6bee..845f2d2f5f 100644 --- a/drivers/spi/zynq_qspi.c +++ b/drivers/spi/zynq_qspi.c @@ -100,7 +100,7 @@ struct zynq_qspi_priv { static int zynq_qspi_of_to_plat(struct udevice *bus) { - struct zynq_qspi_plat *plat = bus->plat; + struct zynq_qspi_plat *plat = dev_get_plat(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); @@ -592,7 +592,7 @@ static int zynq_qspi_xfer(struct udevice *dev, unsigned int bitlen, static int zynq_qspi_set_speed(struct udevice *bus, uint speed) { - struct zynq_qspi_plat *plat = bus->plat; + struct zynq_qspi_plat *plat = dev_get_plat(bus); struct zynq_qspi_priv *priv = dev_get_priv(bus); struct zynq_qspi_regs *regs = priv->regs; uint32_t confr; diff --git a/drivers/spi/zynq_spi.c b/drivers/spi/zynq_spi.c index a6efa4a1c8..2971e55f41 100644 --- a/drivers/spi/zynq_spi.c +++ b/drivers/spi/zynq_spi.c @@ -75,7 +75,7 @@ struct zynq_spi_priv { static int zynq_spi_of_to_plat(struct udevice *bus) { - struct zynq_spi_plat *plat = bus->plat; + struct zynq_spi_plat *plat = dev_get_plat(bus); const void *blob = gd->fdt_blob; int node = dev_of_offset(bus); @@ -162,7 +162,7 @@ static int zynq_spi_probe(struct udevice *bus) static void spi_cs_activate(struct udevice *dev) { struct udevice *bus = dev->parent; - struct zynq_spi_plat *plat = bus->plat; + struct zynq_spi_plat *plat = dev_get_plat(bus); struct zynq_spi_priv *priv = dev_get_priv(bus); struct zynq_spi_regs *regs = priv->regs; u32 cr; @@ -193,7 +193,7 @@ static void spi_cs_activate(struct udevice *dev) static void spi_cs_deactivate(struct udevice *dev) { struct udevice *bus = dev->parent; - struct zynq_spi_plat *plat = bus->plat; + struct zynq_spi_plat *plat = dev_get_plat(bus); struct zynq_spi_priv *priv = dev_get_priv(bus); struct zynq_spi_regs *regs = priv->regs; @@ -296,7 +296,7 @@ static int zynq_spi_xfer(struct udevice *dev, unsigned int bitlen, static int zynq_spi_set_speed(struct udevice *bus, uint speed) { - struct zynq_spi_plat *plat = bus->plat; + struct zynq_spi_plat *plat = dev_get_plat(bus); struct zynq_spi_priv *priv = dev_get_priv(bus); struct zynq_spi_regs *regs = priv->regs; uint32_t confr; diff --git a/drivers/spi/zynqmp_gqspi.c b/drivers/spi/zynqmp_gqspi.c index f09c50757d..c9e476eefa 100644 --- a/drivers/spi/zynqmp_gqspi.c +++ b/drivers/spi/zynqmp_gqspi.c @@ -177,7 +177,7 @@ struct zynqmp_qspi_priv { static int zynqmp_qspi_of_to_plat(struct udevice *bus) { - struct zynqmp_qspi_plat *plat = bus->plat; + struct zynqmp_qspi_plat *plat = dev_get_plat(bus); debug("%s\n", __func__); @@ -255,7 +255,7 @@ static void zynqmp_qspi_chipselect(struct zynqmp_qspi_priv *priv, int is_on) void zynqmp_qspi_set_tapdelay(struct udevice *bus, u32 baudrateval) { - struct zynqmp_qspi_plat *plat = bus->plat; + struct zynqmp_qspi_plat *plat = dev_get_plat(bus); struct zynqmp_qspi_priv *priv = dev_get_priv(bus); struct zynqmp_qspi_regs *regs = priv->regs; u32 tapdlybypass = 0, lpbkdlyadj = 0, datadlyadj = 0, clk_rate; @@ -295,7 +295,7 @@ void zynqmp_qspi_set_tapdelay(struct udevice *bus, u32 baudrateval) static int zynqmp_qspi_set_speed(struct udevice *bus, uint speed) { - struct zynqmp_qspi_plat *plat = bus->plat; + struct zynqmp_qspi_plat *plat = dev_get_plat(bus); struct zynqmp_qspi_priv *priv = dev_get_priv(bus); struct zynqmp_qspi_regs *regs = priv->regs; u32 confr; diff --git a/drivers/timer/ag101p_timer.c b/drivers/timer/ag101p_timer.c index 17174345e3..27cf9b0247 100644 --- a/drivers/timer/ag101p_timer.c +++ b/drivers/timer/ag101p_timer.c @@ -64,7 +64,7 @@ struct atftmr_timer_plat { static u64 atftmr_timer_get_count(struct udevice *dev) { - struct atftmr_timer_plat *plat = dev->plat; + struct atftmr_timer_plat *plat = dev_get_plat(dev); struct atftmr_timer_regs *const regs = plat->regs; u32 val; val = readl(®s->t3_counter); @@ -73,7 +73,7 @@ static u64 atftmr_timer_get_count(struct udevice *dev) static int atftmr_timer_probe(struct udevice *dev) { - struct atftmr_timer_plat *plat = dev->plat; + struct atftmr_timer_plat *plat = dev_get_plat(dev); struct atftmr_timer_regs *const regs = plat->regs; u32 cr; writel(0, ®s->t3_load); diff --git a/drivers/timer/altera_timer.c b/drivers/timer/altera_timer.c index 7e9abee0ef..040dc65f48 100644 --- a/drivers/timer/altera_timer.c +++ b/drivers/timer/altera_timer.c @@ -34,7 +34,7 @@ struct altera_timer_plat { static u64 altera_timer_get_count(struct udevice *dev) { - struct altera_timer_plat *plat = dev->plat; + struct altera_timer_plat *plat = dev_get_plat(dev); struct altera_timer_regs *const regs = plat->regs; u32 val; @@ -49,7 +49,7 @@ static u64 altera_timer_get_count(struct udevice *dev) static int altera_timer_probe(struct udevice *dev) { - struct altera_timer_plat *plat = dev->plat; + struct altera_timer_plat *plat = dev_get_plat(dev); struct altera_timer_regs *const regs = plat->regs; writel(0, ®s->status); diff --git a/drivers/timer/andes_plmt_timer.c b/drivers/timer/andes_plmt_timer.c index cec86718c7..db2cf86f63 100644 --- a/drivers/timer/andes_plmt_timer.c +++ b/drivers/timer/andes_plmt_timer.c @@ -12,6 +12,7 @@ #include #include #include +#include #include /* mtime register */ @@ -19,7 +20,7 @@ static u64 andes_plmt_get_count(struct udevice *dev) { - return readq((void __iomem *)MTIME_REG(dev->priv)); + return readq((void __iomem *)MTIME_REG(dev_get_priv(dev))); } static const struct timer_ops andes_plmt_ops = { @@ -28,8 +29,8 @@ static const struct timer_ops andes_plmt_ops = { static int andes_plmt_probe(struct udevice *dev) { - dev->priv = dev_read_addr_ptr(dev); - if (!dev->priv) + dev_set_priv(dev, dev_read_addr_ptr(dev)); + if (!dev_get_priv(dev)) return -EINVAL; return timer_timebase_fallback(dev); diff --git a/drivers/timer/mpc83xx_timer.c b/drivers/timer/mpc83xx_timer.c index 9b1daaadeb..2f2b8be3dc 100644 --- a/drivers/timer/mpc83xx_timer.c +++ b/drivers/timer/mpc83xx_timer.c @@ -206,7 +206,7 @@ static u64 mpc83xx_timer_get_count(struct udevice *dev) static int mpc83xx_timer_probe(struct udevice *dev) { - struct timer_dev_priv *uc_priv = dev->uclass_priv; + struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); struct clk clock; int ret; diff --git a/drivers/timer/sifive_clint_timer.c b/drivers/timer/sifive_clint_timer.c index 00ce0f08d6..de23b85404 100644 --- a/drivers/timer/sifive_clint_timer.c +++ b/drivers/timer/sifive_clint_timer.c @@ -9,6 +9,7 @@ #include #include #include +#include #include /* mtime register */ @@ -16,7 +17,7 @@ static u64 sifive_clint_get_count(struct udevice *dev) { - return readq((void __iomem *)MTIME_REG(dev->priv)); + return readq((void __iomem *)MTIME_REG(dev_get_priv(dev))); } static const struct timer_ops sifive_clint_ops = { @@ -25,8 +26,8 @@ static const struct timer_ops sifive_clint_ops = { static int sifive_clint_probe(struct udevice *dev) { - dev->priv = dev_read_addr_ptr(dev); - if (!dev->priv) + dev_set_priv(dev, dev_read_addr_ptr(dev)); + if (!dev_get_priv(dev)) return -EINVAL; return timer_timebase_fallback(dev); diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c index ab53555327..8e63c17e9f 100644 --- a/drivers/timer/timer-uclass.c +++ b/drivers/timer/timer-uclass.c @@ -40,7 +40,7 @@ int notrace timer_get_count(struct udevice *dev, u64 *count) unsigned long notrace timer_get_rate(struct udevice *dev) { - struct timer_dev_priv *uc_priv = dev->uclass_priv; + struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev); return uc_priv->clock_rate; } diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 7830a4aee9..16922ff15c 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -1860,10 +1860,18 @@ static int rndis_control_ack(struct eth_device *net) static int rndis_control_ack(struct udevice *net) #endif { - struct ether_priv *priv = (struct ether_priv *)net->priv; - struct eth_dev *dev = &priv->ethdev; - int length; - struct usb_request *resp = dev->stat_req; + struct ether_priv *priv; + struct eth_dev *dev; + int length; + struct usb_request *resp; + +#ifndef CONFIG_DM_ETH + priv = (struct ether_priv *)net->priv; +#else + priv = dev_get_priv(net); +#endif + dev = &priv->ethdev; + resp = dev->stat_req; /* in case RNDIS calls this after disconnect */ if (!dev->status) { diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index a2bd7436f4..17db5eb060 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -60,7 +60,7 @@ int submit_control_msg(struct usb_device *udev, unsigned long pipe, { struct udevice *bus = udev->controller_dev; struct dm_usb_ops *ops = usb_get_ops(bus); - struct usb_uclass_priv *uc_priv = bus->uclass->priv; + struct usb_uclass_priv *uc_priv = uclass_get_priv(bus->uclass); int err; if (!ops->control) @@ -184,7 +184,7 @@ int usb_stop(void) if (ret) return ret; - uc_priv = uc->priv; + uc_priv = uclass_get_priv(uc); uclass_foreach_dev(bus, uc) { ret = device_remove(bus, DM_REMOVE_NORMAL); @@ -263,7 +263,7 @@ int usb_init(void) if (ret) return ret; - uc_priv = uc->priv; + uc_priv = uclass_get_priv(uc); uclass_foreach_dev(bus, uc) { /* init low_level USB */ diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 20f6973b4b..8883e29035 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -378,7 +378,7 @@ static int video_post_bind(struct udevice *dev) return 0; /* Set up the video pointer, if this is the first device */ - uc_priv = dev->uclass->priv; + uc_priv = uclass_get_priv(dev->uclass); if (!uc_priv->video_ptr) uc_priv->video_ptr = gd->video_top; diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 99b5078006..c9315dd458 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -531,7 +531,7 @@ __maybe_unused static void *dp_fill(void *buf, struct udevice *dev) case UCLASS_ETH: { struct efi_device_path_mac_addr *dp = dp_fill(buf, dev->parent); - struct eth_pdata *pdata = dev->plat; + struct eth_pdata *pdata = dev_get_plat(dev); dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR; diff --git a/net/eth-uclass.c b/net/eth-uclass.c index e2d6731975..0156324032 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -50,7 +50,7 @@ static struct eth_uclass_priv *eth_get_uclass_priv(void) return NULL; assert(uc); - return uc->priv; + return uclass_get_priv(uc); } void eth_set_current_to_next(void) @@ -146,7 +146,7 @@ unsigned char *eth_get_ethaddr(void) struct eth_pdata *pdata; if (eth_get_dev()) { - pdata = eth_get_dev()->plat; + pdata = dev_get_plat(eth_get_dev()); return pdata->enetaddr; } @@ -163,7 +163,7 @@ int eth_init_state_only(void) if (!current || !device_active(current)) return -EINVAL; - priv = current->uclass_priv; + priv = dev_get_uclass_priv(current); priv->state = ETH_STATE_ACTIVE; return 0; @@ -179,7 +179,7 @@ void eth_halt_state_only(void) if (!current || !device_active(current)) return; - priv = current->uclass_priv; + priv = dev_get_uclass_priv(current); priv->state = ETH_STATE_PASSIVE; } @@ -200,7 +200,7 @@ static int eth_write_hwaddr(struct udevice *dev) /* seq is valid since the device is active */ if (eth_get_ops(dev)->write_hwaddr && !eth_mac_skip(dev_seq(dev))) { - pdata = dev->plat; + pdata = dev_get_plat(dev); if (!is_valid_ethaddr(pdata->enetaddr)) { printf("\nError: %s address %pM illegal value\n", dev->name, pdata->enetaddr); @@ -234,7 +234,7 @@ static int on_ethaddr(const char *name, const char *value, enum env_op op, retval = uclass_find_device_by_seq(UCLASS_ETH, index, &dev); if (!retval) { - struct eth_pdata *pdata = dev->plat; + struct eth_pdata *pdata = dev_get_plat(dev); switch (op) { case env_op_create: case env_op_overwrite: @@ -287,7 +287,7 @@ int eth_init(void) ret = eth_get_ops(current)->start(current); if (ret >= 0) { struct eth_device_priv *priv = - current->uclass_priv; + dev_get_uclass_priv(current); priv->state = ETH_STATE_ACTIVE; return 0; @@ -323,7 +323,7 @@ void eth_halt(void) return; eth_get_ops(current)->stop(current); - priv = current->uclass_priv; + priv = dev_get_uclass_priv(current); if (priv) priv->state = ETH_STATE_PASSIVE; } @@ -502,8 +502,8 @@ static bool eth_dev_get_mac_address(struct udevice *dev, u8 mac[ARP_HLEN]) static int eth_post_probe(struct udevice *dev) { - struct eth_device_priv *priv = dev->uclass_priv; - struct eth_pdata *pdata = dev->plat; + struct eth_device_priv *priv = dev_get_uclass_priv(dev); + struct eth_pdata *pdata = dev_get_plat(dev); unsigned char env_enetaddr[ARP_HLEN]; char *source = "DT"; @@ -581,7 +581,7 @@ static int eth_post_probe(struct udevice *dev) static int eth_pre_remove(struct udevice *dev) { - struct eth_pdata *pdata = dev->plat; + struct eth_pdata *pdata = dev_get_plat(dev); eth_get_ops(dev)->stop(dev); diff --git a/test/dm/core.c b/test/dm/core.c index a7c0f40b77..cf66e27db4 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -255,7 +255,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts) ut_assert(priv); ut_asserteq(expected_base_add, priv->base_add); - pdata = dev->plat; + pdata = dev_get_plat(dev); expected_base_add += pdata->ping_add; } @@ -273,7 +273,7 @@ static int dm_test_plat(struct unit_test_state *uts) for (i = 0; i < 3; i++) { ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); ut_assert(dev); - pdata = dev->plat; + pdata = dev_get_plat(dev); ut_assert(pdata->ping_add == test_pdata[i].ping_add); } @@ -297,7 +297,7 @@ static int dm_test_lifecycle(struct unit_test_state *uts) ut_assert(dev); ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] == op_count[DM_TEST_OP_BIND] + 1); - ut_assert(!dev->priv); + ut_assert(!dev_get_priv(dev)); /* Probe the device - it should fail allocating private data */ dms->force_fail_alloc = 1; @@ -305,14 +305,14 @@ static int dm_test_lifecycle(struct unit_test_state *uts) ut_assert(ret == -ENOMEM); ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE] == op_count[DM_TEST_OP_PROBE] + 1); - ut_assert(!dev->priv); + ut_assert(!dev_get_priv(dev)); /* Try again without the alloc failure */ dms->force_fail_alloc = 0; ut_assertok(device_probe(dev)); ut_assert(dm_testdrv_op_count[DM_TEST_OP_PROBE] == op_count[DM_TEST_OP_PROBE] + 2); - ut_assert(dev->priv); + ut_assert(dev_get_priv(dev)); /* This should be device 3 in the uclass */ ut_assertok(uclass_find_device(UCLASS_TEST, 3, &test_dev)); @@ -402,8 +402,8 @@ int dm_check_operations(struct unit_test_state *uts, struct udevice *dev, /* Getting the child device should allocate plat / priv */ ut_assertok(testfdt_ping(dev, 10, &pingret)); - ut_assert(dev->priv); - ut_assert(dev->plat); + ut_assert(dev_get_priv(dev)); + ut_assert(dev_get_plat(dev)); expected = 10 + base; ut_asserteq(expected, pingret); @@ -414,7 +414,7 @@ int dm_check_operations(struct unit_test_state *uts, struct udevice *dev, ut_asserteq(expected, pingret); /* Now check the ping_total */ - priv = dev->priv; + priv = dev_get_priv(dev); ut_asserteq(DM_TEST_START_TOTAL + 10 + 20 + base * 2, priv->ping_total); @@ -444,7 +444,7 @@ static int dm_test_operations(struct unit_test_state *uts) base = test_pdata[i].ping_add; debug("dev=%d, base=%d\n", i, base); - ut_assert(!dm_check_operations(uts, dev, base, dev->priv)); + ut_assert(!dm_check_operations(uts, dev, base, dev_get_priv(dev))); } return 0; @@ -466,7 +466,7 @@ static int dm_test_remove(struct unit_test_state *uts) ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED), "Driver %d/%s should have deactivated", i, dev->name); - ut_assert(!dev->priv); + ut_assert(!dev_get_priv(dev)); } return 0; @@ -512,7 +512,7 @@ static int dm_test_uclass(struct unit_test_state *uts) ut_assertok(uclass_get(UCLASS_TEST, &uc)); ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]); ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_DESTROY]); - ut_assert(uc->priv); + ut_assert(uclass_get_priv(uc)); ut_assertok(uclass_destroy(uc)); ut_asserteq(1, dm_testdrv_op_count[DM_TEST_OP_INIT]); @@ -547,7 +547,7 @@ static int create_children(struct unit_test_state *uts, struct udevice *parent, &driver_info_manual, &dev)); pdata = calloc(1, sizeof(*pdata)); pdata->ping_add = key + i; - dev->plat = pdata; + dev_set_plat(dev, pdata); if (child) child[i] = dev; } diff --git a/test/dm/test-driver.c b/test/dm/test-driver.c index b9f49de10a..a67f5d3f98 100644 --- a/test/dm/test-driver.c +++ b/test/dm/test-driver.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -67,7 +68,7 @@ static int test_remove(struct udevice *dev) static int test_unbind(struct udevice *dev) { /* Private data should not be allocated */ - ut_assert(!dev->priv); + ut_assert(!dev_get_priv(dev)); dm_testdrv_op_count[DM_TEST_OP_UNBIND]++; return 0; @@ -119,8 +120,8 @@ static int test_manual_probe(struct udevice *dev) dm_testdrv_op_count[DM_TEST_OP_PROBE]++; if (!dms->force_fail_alloc) - dev->priv = calloc(1, sizeof(struct dm_test_priv)); - if (!dev->priv) + dev_set_priv(dev, calloc(1, sizeof(struct dm_test_priv))); + if (!dev_get_priv(dev)) return -ENOMEM; return 0; diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index eb3c2cf161..9e8c2906e8 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -25,7 +25,7 @@ DECLARE_GLOBAL_DATA_PTR; static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret) { - const struct dm_test_pdata *pdata = dev->plat; + const struct dm_test_pdata *pdata = dev_get_plat(dev); struct dm_test_priv *priv = dev_get_priv(dev); *pingret = pingval + pdata->ping_add; @@ -288,7 +288,7 @@ static int dm_test_fdt(struct unit_test_state *uts) ret = uclass_find_device(UCLASS_TEST_FDT, i, &dev); ut_assert(!ret); ut_assert(!dev_get_priv(dev)); - ut_assert(dev->plat); + ut_assert(dev_get_plat(dev)); } ut_assertok(dm_check_devices(uts, num_devices)); diff --git a/test/dm/test-uclass.c b/test/dm/test-uclass.c index 3ab4a23649..f1b7aaa727 100644 --- a/test/dm/test-uclass.c +++ b/test/dm/test-uclass.c @@ -82,7 +82,7 @@ static int test_post_probe(struct udevice *dev) if (&prev->uclass_node != &uc->dev_head) { struct dm_test_uclass_perdev_priv *prev_uc_priv = dev_get_uclass_priv(prev); - struct dm_test_pdata *pdata = prev->plat; + struct dm_test_pdata *pdata = dev_get_plat(prev); ut_assert(pdata); ut_assert(prev_uc_priv); @@ -102,7 +102,7 @@ static int test_pre_remove(struct udevice *dev) static int test_init(struct uclass *uc) { dm_testdrv_op_count[DM_TEST_OP_INIT]++; - ut_assert(uc->priv); + ut_assert(uclass_get_priv(uc)); return 0; } -- cgit v1.2.3 From 89ba6d553572fe9177ae472170b8373e49f97953 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:29 -0700 Subject: dm: core: Use access methods for dev/uclass private data Use these functions in the core code as much as possible. With this, there are only two places where each priv/plat pointer is accessed, one for read and one for write. Signed-off-by: Simon Glass --- drivers/core/device-remove.c | 8 +++--- drivers/core/device.c | 61 ++++++++++++++++++++++++-------------------- drivers/core/uclass.c | 13 ++++++---- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 8c12169771..e15ab051be 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -94,11 +94,11 @@ int device_unbind(struct udevice *dev) } if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { free(dev_get_uclass_plat(dev)); - dev->uclass_plat = NULL; + dev_set_uclass_plat(dev, NULL); } if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev_get_parent_plat(dev)); - dev->parent_plat = NULL; + dev_set_parent_plat(dev, NULL); } ret = uclass_unbind_device(dev); if (ret) @@ -131,7 +131,7 @@ void device_free(struct udevice *dev) size = dev->uclass->uc_drv->per_device_auto; if (size) { free(dev_get_uclass_priv(dev)); - dev->uclass_priv = NULL; + dev_set_uclass_priv(dev, NULL); } if (dev->parent) { size = dev->parent->driver->per_child_auto; @@ -141,7 +141,7 @@ void device_free(struct udevice *dev) } if (size) { free(dev_get_parent_priv(dev)); - dev->parent_priv = NULL; + dev_set_parent_priv(dev, NULL); } } dev->flags &= ~DM_FLAG_PLATDATA_VALID; diff --git a/drivers/core/device.c b/drivers/core/device.c index f2d750c8de..261c3b2793 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -42,6 +42,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, struct uclass *uc; int size, ret = 0; bool auto_seq = true; + void *ptr; if (devp) *devp = NULL; @@ -64,7 +65,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, #ifdef CONFIG_DEVRES INIT_LIST_HEAD(&dev->devres_head); #endif - dev->plat = plat; + dev_set_plat(dev, plat); dev->driver_data = driver_data; dev->name = name; dev->node = node; @@ -102,25 +103,26 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, } if (alloc) { dev->flags |= DM_FLAG_ALLOC_PDATA; - dev->plat = calloc(1, drv->plat_auto); - if (!dev->plat) { + ptr = calloc(1, drv->plat_auto); + if (!ptr) { ret = -ENOMEM; goto fail_alloc1; } - if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat) { - memcpy(dev->plat, plat, of_plat_size); - } + if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat) + memcpy(ptr, plat, of_plat_size); + dev_set_plat(dev, ptr); } } size = uc->uc_drv->per_device_plat_auto; if (size) { dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; - dev->uclass_plat = calloc(1, size); - if (!dev->uclass_plat) { + ptr = calloc(1, size); + if (!ptr) { ret = -ENOMEM; goto fail_alloc2; } + dev_set_uclass_plat(dev, ptr); } if (parent) { @@ -130,11 +132,12 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, } if (size) { dev->flags |= DM_FLAG_ALLOC_PARENT_PDATA; - dev->parent_plat = calloc(1, size); - if (!dev->parent_plat) { + ptr = calloc(1, size); + if (!ptr) { ret = -ENOMEM; goto fail_alloc3; } + dev_set_parent_plat(dev, ptr); } /* put dev into parent's successor list */ list_add_tail(&dev->sibling_node, &parent->child_head); @@ -191,19 +194,19 @@ fail_uclass_bind: if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) { list_del(&dev->sibling_node); if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { - free(dev->parent_plat); - dev->parent_plat = NULL; + free(dev_get_parent_plat(dev)); + dev_set_parent_plat(dev, NULL); } } fail_alloc3: if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { - free(dev->uclass_plat); - dev->uclass_plat = NULL; + free(dev_get_uclass_plat(dev)); + dev_set_uclass_plat(dev, NULL); } fail_alloc2: if (dev->flags & DM_FLAG_ALLOC_PDATA) { - free(dev->plat); - dev->plat = NULL; + free(dev_get_plat(dev)); + dev_set_plat(dev, NULL); } fail_alloc1: devres_release_all(dev); @@ -324,6 +327,7 @@ int device_of_to_plat(struct udevice *dev) { const struct driver *drv; int size = 0; + void *ptr; int ret; if (!dev) @@ -352,36 +356,37 @@ int device_of_to_plat(struct udevice *dev) assert(drv); /* Allocate private data if requested and not reentered */ - if (drv->priv_auto && !dev->priv) { - dev->priv = alloc_priv(drv->priv_auto, drv->flags); - if (!dev->priv) { + if (drv->priv_auto && !dev_get_priv(dev)) { + ptr = alloc_priv(drv->priv_auto, drv->flags); + if (!ptr) { ret = -ENOMEM; goto fail; } + dev_set_priv(dev, ptr); } /* Allocate private data if requested and not reentered */ size = dev->uclass->uc_drv->per_device_auto; - if (size && !dev->uclass_priv) { - dev->uclass_priv = alloc_priv(size, - dev->uclass->uc_drv->flags); - if (!dev->uclass_priv) { + if (size && !dev_get_uclass_priv(dev)) { + ptr = alloc_priv(size, dev->uclass->uc_drv->flags); + if (!ptr) { ret = -ENOMEM; goto fail; } + dev_set_uclass_priv(dev, ptr); } /* Allocate parent data for this child */ if (dev->parent) { size = dev->parent->driver->per_child_auto; - if (!size) { + if (!size) size = dev->parent->uclass->uc_drv->per_child_auto; - } - if (size && !dev->parent_priv) { - dev->parent_priv = alloc_priv(size, drv->flags); - if (!dev->parent_priv) { + if (size && !dev_get_parent_priv(dev)) { + ptr = alloc_priv(size, drv->flags); + if (!ptr) { ret = -ENOMEM; goto fail; } + dev_set_parent_priv(dev, ptr); } } diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 5e24927b34..e845f60472 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -72,11 +72,14 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp) if (!uc) return -ENOMEM; if (uc_drv->priv_auto) { - uc->priv = calloc(1, uc_drv->priv_auto); - if (!uc->priv) { + void *ptr; + + ptr = calloc(1, uc_drv->priv_auto); + if (!ptr) { ret = -ENOMEM; goto fail_mem; } + uclass_set_priv(uc, ptr); } uc->uc_drv = uc_drv; INIT_LIST_HEAD(&uc->sibling_node); @@ -94,8 +97,8 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp) return 0; fail: if (uc_drv->priv_auto) { - free(uc->priv); - uc->priv = NULL; + free(uclass_get_priv(uc)); + uclass_set_priv(uc, NULL); } list_del(&uc->sibling_node); fail_mem: @@ -132,7 +135,7 @@ int uclass_destroy(struct uclass *uc) uc_drv->destroy(uc); list_del(&uc->sibling_node); if (uc_drv->priv_auto) - free(uc->priv); + free(uclass_get_priv(uc)); free(uc); return 0; -- cgit v1.2.3 From fb8c9fb3fa422314d53516ba30f280be1e7216f9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 22 Dec 2020 19:30:30 -0700 Subject: dm: core: Rename the priv/plat members These are supposed to be private to driver model, not accessed by any code outside. Add a trailing underscore to indicate this. Signed-off-by: Simon Glass --- drivers/core/device.c | 24 ++++++++++++------------ drivers/core/uclass.c | 4 ++-- include/dm/device.h | 29 +++++++++++++++++------------ include/dm/uclass.h | 4 ++-- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 261c3b2793..a4c8310f81 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -514,7 +514,7 @@ void *dev_get_plat(const struct udevice *dev) return NULL; } - return dev->plat; + return dev->plat_; } void *dev_get_parent_plat(const struct udevice *dev) @@ -524,7 +524,7 @@ void *dev_get_parent_plat(const struct udevice *dev) return NULL; } - return dev->parent_plat; + return dev->parent_plat_; } void *dev_get_uclass_plat(const struct udevice *dev) @@ -534,7 +534,7 @@ void *dev_get_uclass_plat(const struct udevice *dev) return NULL; } - return dev->uclass_plat; + return dev->uclass_plat_; } void *dev_get_priv(const struct udevice *dev) @@ -544,7 +544,7 @@ void *dev_get_priv(const struct udevice *dev) return NULL; } - return dev->priv; + return dev->priv_; } void *dev_get_uclass_priv(const struct udevice *dev) @@ -554,7 +554,7 @@ void *dev_get_uclass_priv(const struct udevice *dev) return NULL; } - return dev->uclass_priv; + return dev->uclass_priv_; } void *dev_get_parent_priv(const struct udevice *dev) @@ -564,7 +564,7 @@ void *dev_get_parent_priv(const struct udevice *dev) return NULL; } - return dev->parent_priv; + return dev->parent_priv_; } static int device_get_device_tail(struct udevice *dev, int ret, @@ -966,32 +966,32 @@ int device_set_name(struct udevice *dev, const char *name) void dev_set_priv(struct udevice *dev, void *priv) { - dev->priv = priv; + dev->priv_ = priv; } void dev_set_parent_priv(struct udevice *dev, void *parent_priv) { - dev->parent_priv = parent_priv; + dev->parent_priv_ = parent_priv; } void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv) { - dev->uclass_priv = uclass_priv; + dev->uclass_priv_ = uclass_priv; } void dev_set_plat(struct udevice *dev, void *plat) { - dev->plat = plat; + dev->plat_ = plat; } void dev_set_parent_plat(struct udevice *dev, void *parent_plat) { - dev->parent_plat = parent_plat; + dev->parent_plat_ = parent_plat; } void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat) { - dev->uclass_plat = uclass_plat; + dev->uclass_plat_ = uclass_plat; } #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index e845f60472..f60bc9a850 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -165,12 +165,12 @@ const char *uclass_get_name(enum uclass_id id) void *uclass_get_priv(const struct uclass *uc) { - return uc->priv; + return uc->priv_; } void uclass_set_priv(struct uclass *uc, void *priv) { - uc->priv = priv; + uc->priv_ = priv; } enum uclass_id uclass_get_by_name(const char *name) diff --git a/include/dm/device.h b/include/dm/device.h index 30fc98dc34..daebd6eb68 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -116,17 +116,22 @@ enum { * * @driver: The driver used by this device * @name: Name of device, typically the FDT node name - * @plat: Configuration data for this device - * @parent_plat: The parent bus's configuration data for this device - * @uclass_plat: The uclass's configuration data for this device + * @plat_: Configuration data for this device (do not access outside driver + * model) + * @parent_plat_: The parent bus's configuration data for this device (do not + * access outside driver model) + * @uclass_plat_: The uclass's configuration data for this device (do not access + * outside driver model) * @node: Reference to device tree node for this device * @driver_data: Driver data word for the entry that matched this device with * its driver * @parent: Parent of this device, or NULL for the top level device - * @priv: Private data for this device + * @priv_: Private data for this device (do not access outside driver model) * @uclass: Pointer to uclass for this device - * @uclass_priv: The uclass's private data for this device - * @parent_priv: The parent's private data for this device + * @uclass_priv_: The uclass's private data for this device (do not access + * outside driver model) + * @parent_priv_: The parent's private data for this device (do not access + * outside driver model) * @uclass_node: Used by uclass to link its devices * @child_head: List of children of this device * @sibling_node: Next device in list of all devices @@ -144,16 +149,16 @@ enum { struct udevice { const struct driver *driver; const char *name; - void *plat; - void *parent_plat; - void *uclass_plat; + void *plat_; + void *parent_plat_; + void *uclass_plat_; ofnode node; ulong driver_data; struct udevice *parent; - void *priv; + void *priv_; struct uclass *uclass; - void *uclass_priv; - void *parent_priv; + void *uclass_priv_; + void *parent_priv_; struct list_head uclass_node; struct list_head child_head; struct list_head sibling_node; diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 20d4b9e683..f06339e4d6 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -24,7 +24,7 @@ * There may be drivers for on-chip SoC GPIO banks, I2C GPIO expanders and * PMIC IO lines, all made available in a unified way through the uclass. * - * @priv: Private data for this uclass + * @priv_: Private data for this uclass (do not access outside driver model) * @uc_drv: The driver for the uclass itself, not to be confused with a * 'struct driver' * @dev_head: List of devices in this uclass (devices are attached to their @@ -32,7 +32,7 @@ * @sibling_node: Next uclass in the linked list of uclasses */ struct uclass { - void *priv; + void *priv_; struct uclass_driver *uc_drv; struct list_head dev_head; struct list_head sibling_node; -- cgit v1.2.3 From c8fbf3089b2771d803b789c50f10c98e91d477a6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:13 -0700 Subject: pinctrl: Drop post_bind() method when not needed This is not used with of-platdata, so remove it in that case. Signed-off-by: Simon Glass --- drivers/pinctrl/pinctrl-uclass.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index aba8810474..4e474cbff7 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -305,7 +305,7 @@ int pinctrl_select_state(struct udevice *dev, const char *statename) * Some device which is logical like mmc.blk, do not have * a valid ofnode. */ - if (!ofnode_valid(dev->node)) + if (!dev_has_of_node(dev)) return 0; /* * Try full-implemented pinctrl first. @@ -416,7 +416,9 @@ static int __maybe_unused pinctrl_post_bind(struct udevice *dev) UCLASS_DRIVER(pinctrl) = { .id = UCLASS_PINCTRL, +#if !CONFIG_IS_ENABLED(OF_PLATDATA) .post_bind = pinctrl_post_bind, +#endif .flags = DM_UC_FLAG_SEQ_ALIAS, .name = "pinctrl", }; -- cgit v1.2.3 From 4c66cb4a780c3936f3585b8ffc977f64e03f7e7f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:14 -0700 Subject: sysreset: Use a shorter error with SPL Use a minimal error message to save space. Sort the header files while we are here. Signed-off-by: Simon Glass --- drivers/sysreset/sysreset-uclass.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/sysreset/sysreset-uclass.c b/drivers/sysreset/sysreset-uclass.c index 3f5414ed1f..e69fb2255b 100644 --- a/drivers/sysreset/sysreset-uclass.c +++ b/drivers/sysreset/sysreset-uclass.c @@ -9,12 +9,13 @@ #include #include #include -#include -#include -#include #include #include +#include +#include #include +#include +#include #include #include #include @@ -101,7 +102,10 @@ void sysreset_walk_halt(enum sysreset_t type) mdelay(100); /* Still no reset? Give up */ - log_err("System reset not supported on this platform\n"); + if (spl_phase() <= PHASE_SPL) + log_err("no sysreset\n"); + else + log_err("System reset not supported on this platform\n"); hang(); } -- cgit v1.2.3 From 477a6bcb3b8b3d9e6818e19bf9baaee750665bad Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:15 -0700 Subject: arc: m68k: nds32: nios2: sh: xtensa: Add empty spl.h header At present it is not possible to include spl.h in on these architectures since the asm/spl.h file is not present. We want to be able to use the spl_phase() function, so add empty headers to make things build. Signed-off-by: Simon Glass --- arch/arc/include/asm/spl.h | 0 arch/m68k/include/asm/spl.h | 0 arch/nds32/include/asm/spl.h | 0 arch/nios2/include/asm/spl.h | 0 arch/sh/include/asm/spl.h | 0 arch/xtensa/include/asm/spl.h | 0 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 arch/arc/include/asm/spl.h create mode 100644 arch/m68k/include/asm/spl.h create mode 100644 arch/nds32/include/asm/spl.h create mode 100644 arch/nios2/include/asm/spl.h create mode 100644 arch/sh/include/asm/spl.h create mode 100644 arch/xtensa/include/asm/spl.h diff --git a/arch/arc/include/asm/spl.h b/arch/arc/include/asm/spl.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/arch/m68k/include/asm/spl.h b/arch/m68k/include/asm/spl.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/arch/nds32/include/asm/spl.h b/arch/nds32/include/asm/spl.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/arch/nios2/include/asm/spl.h b/arch/nios2/include/asm/spl.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/arch/sh/include/asm/spl.h b/arch/sh/include/asm/spl.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/arch/xtensa/include/asm/spl.h b/arch/xtensa/include/asm/spl.h new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3 From 6d1a8ebefb8461f93e12b6e62efe36ca0a69e6d4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:16 -0700 Subject: timer: Use a shorter error in TPL This error should not happen in normal use. Reduce the length of it to save space in the image. Add an empty spl.h file to sh since it appears to lack this. Signed-off-by: Simon Glass --- lib/time.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/time.c b/lib/time.c index 88bc50405f..cc6944ec34 100644 --- a/lib/time.c +++ b/lib/time.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -96,8 +97,13 @@ uint64_t notrace get_ticks(void) } ret = timer_get_count(gd->timer, &count); - if (ret) - panic("Could not read count from timer (err %d)\n", ret); + if (ret) { + if (spl_phase() > PHASE_TPL) + panic("Could not read count from timer (err %d)\n", + ret); + else + panic("no timer (err %d)\n", ret); + } return count; } -- cgit v1.2.3 From 3f8760824e028f5710e3d8ec029c8cc9fade1729 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:17 -0700 Subject: test: Use a simple variable to record removed device At present the entire test state is effective passed into a test driver just to record which device was removed. This is unnecessary and makes it harder to track what is going on. Use a simple boolean instead. Also drop the unused 'removed' member while we are here. Signed-off-by: Simon Glass --- include/dm/test.h | 2 -- test/dm/bus.c | 14 ++++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/dm/test.h b/include/dm/test.h index b2adce730a..cbe1b57d95 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -134,14 +134,12 @@ extern struct unit_test_state global_dm_test_state; * @testdev: Test device * @force_fail_alloc: Force all memory allocs to fail * @skip_post_probe: Skip uclass post-probe processing - * @removed: Used to keep track of a device that was removed */ struct dm_test_state { struct udevice *root; struct udevice *testdev; int force_fail_alloc; int skip_post_probe; - struct udevice *removed; }; /* Declare a new driver model test */ diff --git a/test/dm/bus.c b/test/dm/bus.c index 60ddb1d6b1..b95c106f5f 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -30,7 +30,8 @@ enum { FLAG_CHILD_REMOVED = -7, }; -static struct dm_test_state *test_state; +/* Records the last testbus device that was removed */ +static struct udevice *testbus_removed; static int testbus_drv_probe(struct udevice *dev) { @@ -78,11 +79,9 @@ static int testbus_child_post_probe_uclass(struct udevice *dev) static int testbus_child_post_remove(struct udevice *dev) { struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev); - struct dm_test_state *dms = test_state; parent_data->flag += FLAG_CHILD_REMOVED; - if (dms) - dms->removed = dev; + testbus_removed = dev; return 0; } @@ -335,11 +334,10 @@ DM_TEST(dm_test_bus_parent_data_uclass, static int dm_test_bus_parent_ops(struct unit_test_state *uts) { struct dm_test_parent_data *parent_data; - struct dm_test_state *dms = uts->priv; struct udevice *bus, *dev; struct uclass *uc; - test_state = dms; + testbus_removed = NULL; ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc)); @@ -362,9 +360,9 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts) ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag); ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); ut_asserteq_ptr(NULL, dev_get_parent_priv(dev)); - ut_asserteq_ptr(dms->removed, dev); + ut_asserteq_ptr(testbus_removed, dev); } - test_state = NULL; + testbus_removed = NULL; return 0; } -- cgit v1.2.3 From 079ac59586fa1e0c69020e74e4f16cbfdf82232d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:18 -0700 Subject: test: Move some test drivers into their own file At present several test drivers are part of the test file itself. Some of these are useful for of-platdata tests. Separate them out so we can use them for other things also. A few adjustments are needed so this driver can build for sandbox_spl as well. Signed-off-by: Simon Glass --- drivers/misc/Kconfig | 9 ++ drivers/misc/Makefile | 1 + drivers/misc/test_drv.c | 222 ++++++++++++++++++++++++++++++++++++++++++++++++ include/dm/test.h | 18 ++++ include/test/test.h | 9 ++ test/dm/bus.c | 105 +---------------------- test/dm/test-fdt.c | 120 -------------------------- 7 files changed, 263 insertions(+), 221 deletions(-) create mode 100644 drivers/misc/test_drv.c diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 29432ae7eb..7d2a299779 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -343,6 +343,15 @@ config TEGRA186_BPMP can make requests to the BPMP. This driver is similar to an MFD driver in the Linux kernel. +config TEST_DRV + bool "Enable support for test drivers" + default y if SANDBOX + help + This enables drivers and uclasses that provides a way of testing the + operations of memory allocation and driver/uclass methods in driver + model. This should only be enabled for testing as it is not useful for + anything else. + config TWL4030_LED bool "Enable TWL4030 LED controller" help diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 947bd3a647..d737203704 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -67,6 +67,7 @@ obj-$(CONFIG_STM32_RCC) += stm32_rcc.o obj-$(CONFIG_SYS_DPAA_QBMAN) += fsl_portals.o obj-$(CONFIG_TEGRA186_BPMP) += tegra186_bpmp.o obj-$(CONFIG_TEGRA_CAR) += tegra_car.o +obj-$(CONFIG_TEST_DRV) += test_drv.o obj-$(CONFIG_TWL4030_LED) += twl4030_led.o obj-$(CONFIG_VEXPRESS_CONFIG) += vexpress_config.o obj-$(CONFIG_WINBOND_W83627) += winbond_w83627.o diff --git a/drivers/misc/test_drv.c b/drivers/misc/test_drv.c new file mode 100644 index 0000000000..7dd3de34c9 --- /dev/null +++ b/drivers/misc/test_drv.c @@ -0,0 +1,222 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2014 Google, Inc + */ + +#include +#include +#include + +/* Records the last testbus device that was removed */ +static struct udevice *testbus_removed; + +struct udevice *testbus_get_clear_removed(void) +{ + struct udevice *removed = testbus_removed; + + testbus_removed = NULL; + + return removed; +} + +static int testbus_drv_probe(struct udevice *dev) +{ + if (!CONFIG_IS_ENABLED(OF_PLATDATA)) { + int ret; + + ret = dm_scan_fdt_dev(dev); + if (ret) + return ret; + } + + return 0; +} + +static int testbus_child_post_bind(struct udevice *dev) +{ + struct dm_test_parent_plat *plat; + + plat = dev_get_parent_plat(dev); + plat->bind_flag = 1; + plat->uclass_bind_flag = 2; + + return 0; +} + +static int testbus_child_pre_probe(struct udevice *dev) +{ + struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev); + + parent_data->flag += TEST_FLAG_CHILD_PROBED; + + return 0; +} + +static int testbus_child_pre_probe_uclass(struct udevice *dev) +{ + struct dm_test_priv *priv = dev_get_priv(dev); + + priv->uclass_flag++; + + return 0; +} + +static int testbus_child_post_probe_uclass(struct udevice *dev) +{ + struct dm_test_priv *priv = dev_get_priv(dev); + + priv->uclass_postp++; + + return 0; +} + +static int testbus_child_post_remove(struct udevice *dev) +{ + struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev); + + parent_data->flag += TEST_FLAG_CHILD_REMOVED; + testbus_removed = dev; + + return 0; +} + +static const struct udevice_id testbus_ids[] = { + { .compatible = "denx,u-boot-test-bus", .data = DM_TEST_TYPE_FIRST }, + { } +}; + +U_BOOT_DRIVER(testbus_drv) = { + .name = "testbus_drv", + .of_match = testbus_ids, + .id = UCLASS_TEST_BUS, + .probe = testbus_drv_probe, + .child_post_bind = testbus_child_post_bind, + .priv_auto = sizeof(struct dm_test_priv), + .plat_auto = sizeof(struct dm_test_pdata), + .per_child_auto = sizeof(struct dm_test_parent_data), + .per_child_plat_auto = sizeof(struct dm_test_parent_plat), + .child_pre_probe = testbus_child_pre_probe, + .child_post_remove = testbus_child_post_remove, +}; + +UCLASS_DRIVER(testbus) = { + .name = "testbus", + .id = UCLASS_TEST_BUS, + .flags = DM_UC_FLAG_SEQ_ALIAS, + .child_pre_probe = testbus_child_pre_probe_uclass, + .child_post_probe = testbus_child_post_probe_uclass, +}; + +static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret) +{ + const struct dm_test_pdata *pdata = dev_get_plat(dev); + struct dm_test_priv *priv = dev_get_priv(dev); + + *pingret = pingval + pdata->ping_add; + priv->ping_total += *pingret; + + return 0; +} + +static const struct test_ops test_ops = { + .ping = testfdt_drv_ping, +}; + +static int testfdt_of_to_plat(struct udevice *dev) +{ + struct dm_test_pdata *pdata = dev_get_plat(dev); + + pdata->ping_add = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), + "ping-add", -1); + pdata->base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev), + "ping-expect"); + + return 0; +} + +static int testfdt_drv_probe(struct udevice *dev) +{ + struct dm_test_priv *priv = dev_get_priv(dev); + + priv->ping_total += DM_TEST_START_TOTAL; + + /* + * If this device is on a bus, the uclass_flag will be set before + * calling this function. In the meantime the uclass_postp is + * initlized to a value -1. These are used respectively by + * dm_test_bus_child_pre_probe_uclass() and + * dm_test_bus_child_post_probe_uclass(). + */ + priv->uclass_total += priv->uclass_flag; + priv->uclass_postp = -1; + + return 0; +} + +static const struct udevice_id testfdt_ids[] = { + { .compatible = "denx,u-boot-fdt-test", .data = DM_TEST_TYPE_FIRST }, + { .compatible = "google,another-fdt-test", .data = DM_TEST_TYPE_SECOND }, + { } +}; + +U_BOOT_DRIVER(testfdt_drv) = { + .name = "testfdt_drv", + .of_match = testfdt_ids, + .id = UCLASS_TEST_FDT, + .of_to_plat = testfdt_of_to_plat, + .probe = testfdt_drv_probe, + .ops = &test_ops, + .priv_auto = sizeof(struct dm_test_priv), + .plat_auto = sizeof(struct dm_test_pdata), +}; + +static const struct udevice_id testfdt1_ids[] = { + { .compatible = "denx,u-boot-fdt-test1", .data = DM_TEST_TYPE_FIRST }, + { } +}; + +U_BOOT_DRIVER(testfdt1_drv) = { + .name = "testfdt1_drv", + .of_match = testfdt1_ids, + .id = UCLASS_TEST_FDT, + .of_to_plat = testfdt_of_to_plat, + .probe = testfdt_drv_probe, + .ops = &test_ops, + .priv_auto = sizeof(struct dm_test_priv), + .plat_auto = sizeof(struct dm_test_pdata), + .flags = DM_FLAG_PRE_RELOC, +}; + +/* From here is the testfdt uclass code */ +int testfdt_ping(struct udevice *dev, int pingval, int *pingret) +{ + const struct test_ops *ops = device_get_ops(dev); + + if (!ops->ping) + return -ENOSYS; + + return ops->ping(dev, pingval, pingret); +} + +UCLASS_DRIVER(testfdt) = { + .name = "testfdt", + .id = UCLASS_TEST_FDT, + .flags = DM_UC_FLAG_SEQ_ALIAS, +}; + +static const struct udevice_id testfdtm_ids[] = { + { .compatible = "denx,u-boot-fdtm-test" }, + { } +}; + +U_BOOT_DRIVER(testfdtm_drv) = { + .name = "testfdtm_drv", + .of_match = testfdtm_ids, + .id = UCLASS_TEST_FDT_MANUAL, +}; + +UCLASS_DRIVER(testfdtm) = { + .name = "testfdtm", + .id = UCLASS_TEST_FDT_MANUAL, + .flags = DM_UC_FLAG_SEQ_ALIAS | DM_UC_FLAG_NO_AUTO_SEQ, +}; diff --git a/include/dm/test.h b/include/dm/test.h index cbe1b57d95..6ac6672cd6 100644 --- a/include/dm/test.h +++ b/include/dm/test.h @@ -167,6 +167,24 @@ struct sandbox_sdl_plat { int font_size; }; +/** + * struct dm_test_parent_plat - Used to track state in bus tests + * + * @count: + * @bind_flag: Indicates that the child post-bind method was called + * @uclass_bind_flag: Also indicates that the child post-bind method was called + */ +struct dm_test_parent_plat { + int count; + int bind_flag; + int uclass_bind_flag; +}; + +enum { + TEST_FLAG_CHILD_PROBED = 10, + TEST_FLAG_CHILD_REMOVED = -7, +}; + /* Declare ping methods for the drivers */ int test_ping(struct udevice *dev, int pingval, int *pingret); int testfdt_ping(struct udevice *dev, int pingval, int *pingret); diff --git a/include/test/test.h b/include/test/test.h index 03e29290bf..3fdaa2b5e5 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -94,6 +94,15 @@ enum { TEST_DEVRES_SIZE3 = 37, }; +/** + * testbus_get_clear_removed() - Test function to obtain removed device + * + * This is used in testbus to find out which device was removed. Calling this + * function returns a pointer to the device and then clears it back to NULL, so + * that a future test can check it. + */ +struct udevice *testbus_get_clear_removed(void); + /** * dm_test_main() - Run driver model tests * diff --git a/test/dm/bus.c b/test/dm/bus.c index b95c106f5f..785ccfc25d 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -19,102 +19,6 @@ DECLARE_GLOBAL_DATA_PTR; -struct dm_test_parent_plat { - int count; - int bind_flag; - int uclass_bind_flag; -}; - -enum { - FLAG_CHILD_PROBED = 10, - FLAG_CHILD_REMOVED = -7, -}; - -/* Records the last testbus device that was removed */ -static struct udevice *testbus_removed; - -static int testbus_drv_probe(struct udevice *dev) -{ - return dm_scan_fdt_dev(dev); -} - -static int testbus_child_post_bind(struct udevice *dev) -{ - struct dm_test_parent_plat *plat; - - plat = dev_get_parent_plat(dev); - plat->bind_flag = 1; - plat->uclass_bind_flag = 2; - - return 0; -} - -static int testbus_child_pre_probe(struct udevice *dev) -{ - struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev); - - parent_data->flag += FLAG_CHILD_PROBED; - - return 0; -} - -static int testbus_child_pre_probe_uclass(struct udevice *dev) -{ - struct dm_test_priv *priv = dev_get_priv(dev); - - priv->uclass_flag++; - - return 0; -} - -static int testbus_child_post_probe_uclass(struct udevice *dev) -{ - struct dm_test_priv *priv = dev_get_priv(dev); - - priv->uclass_postp++; - - return 0; -} - -static int testbus_child_post_remove(struct udevice *dev) -{ - struct dm_test_parent_data *parent_data = dev_get_parent_priv(dev); - - parent_data->flag += FLAG_CHILD_REMOVED; - testbus_removed = dev; - - return 0; -} - -static const struct udevice_id testbus_ids[] = { - { - .compatible = "denx,u-boot-test-bus", - .data = DM_TEST_TYPE_FIRST }, - { } -}; - -U_BOOT_DRIVER(testbus_drv) = { - .name = "testbus_drv", - .of_match = testbus_ids, - .id = UCLASS_TEST_BUS, - .probe = testbus_drv_probe, - .child_post_bind = testbus_child_post_bind, - .priv_auto = sizeof(struct dm_test_priv), - .plat_auto = sizeof(struct dm_test_pdata), - .per_child_auto = sizeof(struct dm_test_parent_data), - .per_child_plat_auto = sizeof(struct dm_test_parent_plat), - .child_pre_probe = testbus_child_pre_probe, - .child_post_remove = testbus_child_post_remove, -}; - -UCLASS_DRIVER(testbus) = { - .name = "testbus", - .id = UCLASS_TEST_BUS, - .flags = DM_UC_FLAG_SEQ_ALIAS, - .child_pre_probe = testbus_child_pre_probe_uclass, - .child_post_probe = testbus_child_post_probe_uclass, -}; - /* Test that we can probe for children */ static int dm_test_bus_children(struct unit_test_state *uts) { @@ -337,7 +241,7 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts) struct udevice *bus, *dev; struct uclass *uc; - testbus_removed = NULL; + testbus_get_clear_removed(); ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); ut_assertok(uclass_get(UCLASS_TEST_FDT, &uc)); @@ -349,7 +253,7 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts) ut_assertok(device_probe(dev)); parent_data = dev_get_parent_priv(dev); - ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag); + ut_asserteq(TEST_FLAG_CHILD_PROBED, parent_data->flag); } uclass_foreach_dev(dev, uc) { @@ -357,12 +261,11 @@ static int dm_test_bus_parent_ops(struct unit_test_state *uts) if (dev->parent != bus) continue; parent_data = dev_get_parent_priv(dev); - ut_asserteq(FLAG_CHILD_PROBED, parent_data->flag); + ut_asserteq(TEST_FLAG_CHILD_PROBED, parent_data->flag); ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); ut_asserteq_ptr(NULL, dev_get_parent_priv(dev)); - ut_asserteq_ptr(testbus_removed, dev); + ut_asserteq_ptr(testbus_get_clear_removed(), dev); } - testbus_removed = NULL; return 0; } diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 9e8c2906e8..633256821c 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -23,126 +23,6 @@ DECLARE_GLOBAL_DATA_PTR; -static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret) -{ - const struct dm_test_pdata *pdata = dev_get_plat(dev); - struct dm_test_priv *priv = dev_get_priv(dev); - - *pingret = pingval + pdata->ping_add; - priv->ping_total += *pingret; - - return 0; -} - -static const struct test_ops test_ops = { - .ping = testfdt_drv_ping, -}; - -static int testfdt_of_to_plat(struct udevice *dev) -{ - struct dm_test_pdata *pdata = dev_get_plat(dev); - - pdata->ping_add = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), - "ping-add", -1); - pdata->base = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev), - "ping-expect"); - - return 0; -} - -static int testfdt_drv_probe(struct udevice *dev) -{ - struct dm_test_priv *priv = dev_get_priv(dev); - - priv->ping_total += DM_TEST_START_TOTAL; - - /* - * If this device is on a bus, the uclass_flag will be set before - * calling this function. In the meantime the uclass_postp is - * initlized to a value -1. These are used respectively by - * dm_test_bus_child_pre_probe_uclass() and - * dm_test_bus_child_post_probe_uclass(). - */ - priv->uclass_total += priv->uclass_flag; - priv->uclass_postp = -1; - - return 0; -} - -static const struct udevice_id testfdt_ids[] = { - { - .compatible = "denx,u-boot-fdt-test", - .data = DM_TEST_TYPE_FIRST }, - { - .compatible = "google,another-fdt-test", - .data = DM_TEST_TYPE_SECOND }, - { } -}; - -U_BOOT_DRIVER(testfdt_drv) = { - .name = "testfdt_drv", - .of_match = testfdt_ids, - .id = UCLASS_TEST_FDT, - .of_to_plat = testfdt_of_to_plat, - .probe = testfdt_drv_probe, - .ops = &test_ops, - .priv_auto = sizeof(struct dm_test_priv), - .plat_auto = sizeof(struct dm_test_pdata), -}; - -static const struct udevice_id testfdt1_ids[] = { - { - .compatible = "denx,u-boot-fdt-test1", - .data = DM_TEST_TYPE_FIRST }, - { } -}; - -U_BOOT_DRIVER(testfdt1_drv) = { - .name = "testfdt1_drv", - .of_match = testfdt1_ids, - .id = UCLASS_TEST_FDT, - .of_to_plat = testfdt_of_to_plat, - .probe = testfdt_drv_probe, - .ops = &test_ops, - .priv_auto = sizeof(struct dm_test_priv), - .plat_auto = sizeof(struct dm_test_pdata), - .flags = DM_FLAG_PRE_RELOC, -}; - -/* From here is the testfdt uclass code */ -int testfdt_ping(struct udevice *dev, int pingval, int *pingret) -{ - const struct test_ops *ops = device_get_ops(dev); - - if (!ops->ping) - return -ENOSYS; - - return ops->ping(dev, pingval, pingret); -} - -UCLASS_DRIVER(testfdt) = { - .name = "testfdt", - .id = UCLASS_TEST_FDT, - .flags = DM_UC_FLAG_SEQ_ALIAS, -}; - -static const struct udevice_id testfdtm_ids[] = { - { .compatible = "denx,u-boot-fdtm-test" }, - { } -}; - -U_BOOT_DRIVER(testfdtm_drv) = { - .name = "testfdtm_drv", - .of_match = testfdtm_ids, - .id = UCLASS_TEST_FDT_MANUAL, -}; - -UCLASS_DRIVER(testfdtm) = { - .name = "testfdtm", - .id = UCLASS_TEST_FDT_MANUAL, - .flags = DM_UC_FLAG_SEQ_ALIAS | DM_UC_FLAG_NO_AUTO_SEQ, -}; - struct dm_testprobe_pdata { int probe_err; }; -- cgit v1.2.3 From ccc3da77aec69ed5bddd70c0ee598e4d6fc6bdc1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:19 -0700 Subject: dtoc: Fix a few pylint warnings in dtb_platdata These have crept in again. Update the file to fix all but these ones: dtb_platdata.py:143:0: R0902: Too many instance attributes (10/7) (too-many-instance-attributes) dtb_platdata.py:713:0: R0913: Too many arguments (6/5) (too-many-arguments) Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 82671138a9..cc3e58a1cd 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -112,18 +112,19 @@ def get_value(ftype, value): str: String representation of the value """ if ftype == fdt.Type.INT: - return '%#x' % fdt_util.fdt32_to_cpu(value) + val = '%#x' % fdt_util.fdt32_to_cpu(value) elif ftype == fdt.Type.BYTE: char = value[0] - return '%#x' % (ord(char) if isinstance(char, str) else char) + val = '%#x' % (ord(char) if isinstance(char, str) else char) elif ftype == fdt.Type.STRING: # Handle evil ACPI backslashes by adding another backslash before them. # So "\\_SB.GPO0" in the device tree effectively stays like that in C - return '"%s"' % value.replace('\\', '\\\\') + val = '"%s"' % value.replace('\\', '\\\\') elif ftype == fdt.Type.BOOL: - return 'true' + val = 'true' else: # ftype == fdt.Type.INT64: - return '%#x' % value + val = '%#x' % value + return val def get_compat_name(node): """Get the node's list of compatible string as a C identifiers @@ -131,7 +132,7 @@ def get_compat_name(node): Args: node (fdt.Node): Node object to check Return: - List of C identifiers for all the compatible strings + list of str: List of C identifiers for all the compatible strings """ compat = node.props['compatible'].value if not isinstance(compat, list): @@ -139,7 +140,7 @@ def get_compat_name(node): return [conv_name_to_c(c) for c in compat] -class DtbPlatdata(object): +class DtbPlatdata(): """Provide a means to convert device tree binary data to platform data The output of this process is C structures which can be used in space- @@ -183,7 +184,7 @@ class DtbPlatdata(object): and a lookup in driver_aliases printing a warning in case of failure. Args: - node: Node object to check + node (Node): Node object to check Return: Tuple: Driver name associated with the first compatible string @@ -330,7 +331,7 @@ class DtbPlatdata(object): # The following re will search for driver names declared as # U_BOOT_DRIVER(driver_name) - drivers = re.findall('U_BOOT_DRIVER\((.*)\)', buff) + drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff) for driver in drivers: self._drivers.append(driver) @@ -338,7 +339,7 @@ class DtbPlatdata(object): # The following re will search for driver aliases declared as # U_BOOT_DRIVER_ALIAS(alias, driver_name) driver_aliases = re.findall( - 'U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', + r'U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', buff) for alias in driver_aliases: # pragma: no cover @@ -383,8 +384,8 @@ class DtbPlatdata(object): This adds each node to self._valid_nodes. Args: - root: Root node for scan - valid_nodes: List of Node objects to add to + root (Node): Root node for scan + valid_nodes (list of Node): List of Node objects to add to """ for node in root.subnodes: if 'compatible' in node.props: @@ -484,7 +485,7 @@ class DtbPlatdata(object): updated to match that width. Returns: - dict containing structures: + dict of dict: dict containing structures: key (str): Node name, as a C identifier value: dict containing structure fields: key (str): Field name @@ -559,7 +560,7 @@ class DtbPlatdata(object): doc/driver-model/of-plat.rst for more information. Args: - structs: dict containing structures: + structs (dict): dict containing structures: key (str): Node name, as a C identifier value: dict containing structure fields: key (str): Field name @@ -720,7 +721,7 @@ def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False, output (str): Name of output file warning_disabled (bool): True to avoid showing warnings about missing drivers - _drivers_additional (list): List of additional drivers to use during + drivers_additional (list): List of additional drivers to use during scanning Raises: ValueError: if args has no command, or an unknown command -- cgit v1.2.3 From abf0c80292d62121d0c28cda27a92a10406428de Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:20 -0700 Subject: dtoc: Make _output_list a top-level function It is annoying to have this function inside its parent since it makes the parent longer and hard to read. Move it to the top level. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 80 +++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index cc3e58a1cd..372f756037 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -592,51 +592,51 @@ class DtbPlatdata(): self.out(';\n') self.out('};\n') + def _output_list(self, node, prop): + """Output the C code for a devicetree property that holds a list + + Args: + node (fdt.Node): Node to output + prop (fdt.Prop): Prop to output + """ + self.buf('{') + vals = [] + # For phandles, output a reference to the platform data + # of the target node. + info = self.get_phandle_argc(prop, node.name) + if info: + # Process the list as pairs of (phandle, id) + pos = 0 + for args in info.args: + phandle_cell = prop.value[pos] + phandle = fdt_util.fdt32_to_cpu(phandle_cell) + target_node = self._fdt.phandle_to_node[phandle] + arg_values = [] + 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{%d, {%s}}' % (target_node.idx, + ', '.join(arg_values))) + for val in vals: + self.buf('\n\t\t%s,' % val) + else: + for val in prop.value: + vals.append(get_value(prop.type, val)) + + # Put 8 values per line to avoid very long lines. + for i in range(0, len(vals), 8): + if i: + self.buf(',\n\t\t') + self.buf(', '.join(vals[i:i + 8])) + self.buf('}') + def output_node(self, node): """Output the C code for a node Args: node (fdt.Node): node to output """ - def _output_list(node, prop): - """Output the C code for a devicetree property that holds a list - - Args: - node (fdt.Node): Node to output - prop (fdt.Prop): Prop to output - """ - self.buf('{') - vals = [] - # For phandles, output a reference to the platform data - # of the target node. - info = self.get_phandle_argc(prop, node.name) - if info: - # Process the list as pairs of (phandle, id) - pos = 0 - for args in info.args: - phandle_cell = prop.value[pos] - phandle = fdt_util.fdt32_to_cpu(phandle_cell) - target_node = self._fdt.phandle_to_node[phandle] - arg_values = [] - 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{%d, {%s}}' % (target_node.idx, - ', '.join(arg_values))) - for val in vals: - self.buf('\n\t\t%s,' % val) - else: - for val in prop.value: - vals.append(get_value(prop.type, val)) - - # Put 8 values per line to avoid very long lines. - for i in range(0, len(vals), 8): - if i: - self.buf(',\n\t\t') - self.buf(', '.join(vals[i:i + 8])) - self.buf('}') - struct_name, _ = self.get_normalized_compat_name(node) var_name = conv_name_to_c(node.name) self.buf('/* Node %s index %d */\n' % (node.path, node.idx)) @@ -651,7 +651,7 @@ class DtbPlatdata(): # Special handling for lists if isinstance(prop.value, list): - _output_list(node, prop) + self._output_list(node, prop) else: self.buf(get_value(prop.type, prop.value)) self.buf(',\n') -- cgit v1.2.3 From 221ddc11586fa29b6fcaeae5ea06379f5c62e5e4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:21 -0700 Subject: dtoc: Output the device in a separate function Reduce the length of output_node() by moving the device-output functionality into a separate function. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 372f756037..2d701ac24d 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -631,6 +631,27 @@ class DtbPlatdata(): self.buf(', '.join(vals[i:i + 8])) self.buf('}') + def _declare_device(self, var_name, struct_name, node_parent): + """Add a device declaration to the output + + This declares a U_BOOT_DEVICE() for the device being processed + + Args: + var_name (str): C name for the node + struct_name (str): Name for the dt struct associated with the node + node_parent (Node): Parent of the node (or None if none) + """ + self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name) + self.buf('\t.name\t\t= "%s",\n' % struct_name) + self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name)) + self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name)) + idx = -1 + if node_parent and node_parent in self._valid_nodes: + idx = node_parent.idx + self.buf('\t.parent_idx\t= %d,\n' % idx) + self.buf('};\n') + self.buf('\n') + def output_node(self, node): """Output the C code for a node @@ -657,17 +678,7 @@ class DtbPlatdata(): self.buf(',\n') self.buf('};\n') - # Add a device declaration - self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name) - self.buf('\t.name\t\t= "%s",\n' % struct_name) - self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name)) - self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name)) - idx = -1 - if node.parent and node.parent in self._valid_nodes: - idx = node.parent.idx - self.buf('\t.parent_idx\t= %d,\n' % idx) - self.buf('};\n') - self.buf('\n') + self._declare_device(var_name, struct_name, node.parent) self.out(''.join(self.get_buf())) -- cgit v1.2.3 From 161dac1dd86fdc4e819b32ab12f656d8d738f95a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:22 -0700 Subject: dtoc: Output the struct values in a separate function Reduce the length of output_node() futher by moving the struct-output functionality into a two separate functions. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 50 +++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 2d701ac24d..1d89f77a00 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -652,6 +652,39 @@ class DtbPlatdata(): self.buf('};\n') self.buf('\n') + def _output_prop(self, node, prop): + """Output a line containing the value of a struct member + + Args: + node (Node): Node being output + prop (Prop): Prop object to output + """ + if prop.name in PROP_IGNORE_LIST or prop.name[0] == '#': + return + member_name = conv_name_to_c(prop.name) + self.buf('\t%s= ' % tab_to(3, '.' + member_name)) + + # Special handling for lists + if isinstance(prop.value, list): + self._output_list(node, prop) + else: + self.buf(get_value(prop.type, prop.value)) + self.buf(',\n') + + def _output_values(self, var_name, struct_name, node): + """Output the definition of a device's struct values + + Args: + var_name (str): C name for the node + struct_name (str): Name for the dt struct associated with the node + node (Node): Node being output + """ + self.buf('static struct %s%s %s%s = {\n' % + (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name)) + for pname in sorted(node.props): + self._output_prop(node, node.props[pname]) + self.buf('};\n') + def output_node(self, node): """Output the C code for a node @@ -661,23 +694,8 @@ class DtbPlatdata(): struct_name, _ = self.get_normalized_compat_name(node) var_name = conv_name_to_c(node.name) self.buf('/* Node %s index %d */\n' % (node.path, node.idx)) - 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] - if pname in PROP_IGNORE_LIST or pname[0] == '#': - continue - member_name = conv_name_to_c(prop.name) - self.buf('\t%s= ' % tab_to(3, '.' + member_name)) - - # Special handling for lists - if isinstance(prop.value, list): - self._output_list(node, prop) - else: - self.buf(get_value(prop.type, prop.value)) - self.buf(',\n') - self.buf('};\n') + self._output_values(var_name, struct_name, node) self._declare_device(var_name, struct_name, node.parent) self.out(''.join(self.get_buf())) -- cgit v1.2.3 From 7d637c122d772e472a211f6aa3f33cbe3c3e243c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:23 -0700 Subject: dtoc: Convert _drivers to a dict At present this member holds a simple list of driver names. Update it to be a dict of DriverInfo, with the name being the key. This will allow more information to be added about each driver, in future patches. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 26 ++++++++++++++++++++++---- tools/dtoc/test_dtoc.py | 10 ++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 1d89f77a00..5b1bb7e5fd 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -64,6 +64,22 @@ PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args']) PhandleLink = collections.namedtuple('PhandleLink', ['var_node', 'dev_name']) +class Driver: + """Information about a driver in U-Boot + + Attributes: + name: Name of driver. For U_BOOT_DRIVER(x) this is 'x' + """ + def __init__(self, name): + self.name = name + + def __eq__(self, other): + return self.name == other.name + + def __repr__(self): + return "Driver(name='%s')" % self.name + + def conv_name_to_c(name): """Convert a device-tree name to a C identifier @@ -156,7 +172,9 @@ class DtbPlatdata(): _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 - _drivers: List of valid driver names found in drivers/ + _drivers: Dict of valid driver names found in drivers/ + key: Driver name + value: Driver for that driver _driver_aliases: Dict that holds aliases for driver names key: Driver alias declared with U_BOOT_DRIVER_ALIAS(driver_alias, driver_name) @@ -172,7 +190,7 @@ class DtbPlatdata(): self._outfile = None self._warning_disabled = warning_disabled self._lines = [] - self._drivers = [] + self._drivers = {} self._driver_aliases = {} self._drivers_additional = drivers_additional or [] @@ -196,7 +214,7 @@ class DtbPlatdata(): compat_list_c = get_compat_name(node) for compat_c in compat_list_c: - if not compat_c in self._drivers: + if not compat_c in self._drivers.keys(): compat_c = self._driver_aliases.get(compat_c) if not compat_c: continue @@ -334,7 +352,7 @@ class DtbPlatdata(): drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff) for driver in drivers: - self._drivers.append(driver) + self._drivers[driver] = Driver(driver) # The following re will search for driver aliases declared as # U_BOOT_DRIVER_ALIAS(alias, driver_name) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 49ab75b85d..c76942c9e2 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -906,3 +906,13 @@ U_BOOT_DEVICE(spl_test2) = { with test_util.capture_sys_output() as (stdout, stderr): dtb_platdata.run_steps(['struct'], dtb_file, False, output, True, [driver_fn]) + + def testDriver(self): + """Test the Driver class""" + drv1 = dtb_platdata.Driver('fred') + drv2 = dtb_platdata.Driver('mary') + drv3 = dtb_platdata.Driver('fred') + self.assertEqual("Driver(name='fred')", str(drv1)) + self.assertEqual(drv1, drv3) + self.assertNotEqual(drv1, drv2) + self.assertNotEqual(drv2, drv3) -- cgit v1.2.3 From 52d2e9c142c0079bba51011bb95301c986ff11bb Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:26 -0700 Subject: x86: apl: Use const for driver operations Update these declarations to const to ensure that the data ends up in the rodata section. Signed-off-by: Simon Glass --- arch/x86/cpu/apollolake/pmc.c | 2 +- arch/x86/cpu/intel_common/p2sb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/cpu/apollolake/pmc.c b/arch/x86/cpu/apollolake/pmc.c index 290b2cb3e7..c40065ab8c 100644 --- a/arch/x86/cpu/apollolake/pmc.c +++ b/arch/x86/cpu/apollolake/pmc.c @@ -205,7 +205,7 @@ static int apl_pmc_probe(struct udevice *dev) return 0; } -static struct acpi_pmc_ops apl_pmc_ops = { +static const struct acpi_pmc_ops apl_pmc_ops = { .init = apl_pmc_fill_power_state, .prev_sleep_state = apl_prev_sleep_state, .disable_tco = apl_disable_tco, diff --git a/arch/x86/cpu/intel_common/p2sb.c b/arch/x86/cpu/intel_common/p2sb.c index e6edab0b05..3765eeeab0 100644 --- a/arch/x86/cpu/intel_common/p2sb.c +++ b/arch/x86/cpu/intel_common/p2sb.c @@ -180,7 +180,7 @@ static int p2sb_child_post_bind(struct udevice *dev) return 0; } -struct p2sb_ops p2sb_ops = { +static const struct p2sb_ops p2sb_ops = { .set_hide = intel_p2sb_set_hide, }; -- cgit v1.2.3 From 7dc82591d68e2ae922abb3e78e59f2d1a6d13c4e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:27 -0700 Subject: x86: Move call64 into its own section When this code is not used (e.g. by TPL) we want it to be excluded from the image. Put it in its own section so that this happens. Signed-off-by: Simon Glass --- arch/x86/cpu/i386/call64.S | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/cpu/i386/call64.S b/arch/x86/cpu/i386/call64.S index 275063c4af..0ffc1006bb 100644 --- a/arch/x86/cpu/i386/call64.S +++ b/arch/x86/cpu/i386/call64.S @@ -11,6 +11,7 @@ #include .code32 +.section .text_call64 .globl cpu_call64 cpu_call64: /* -- cgit v1.2.3 From 1d2b8585f6c58f786f52dbd770b346a8386b0d41 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:28 -0700 Subject: x86: coral: Move fsp-m settings to a subnode At present these settings are in the node for host-bridge and so are visible in TPL as well as SPL. But they are only used for SPL. Move them to a subnode so that TPL does not included them. Signed-off-by: Simon Glass --- arch/x86/cpu/apollolake/fsp_m.c | 5 ++++- arch/x86/dts/chromebook_coral.dts | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/cpu/apollolake/fsp_m.c b/arch/x86/cpu/apollolake/fsp_m.c index cef937573b..c6be707e4e 100644 --- a/arch/x86/cpu/apollolake/fsp_m.c +++ b/arch/x86/cpu/apollolake/fsp_m.c @@ -32,7 +32,10 @@ int fspm_update_config(struct udevice *dev, struct fspm_upd *upd) node = dev_ofnode(dev); if (!ofnode_valid(node)) - return log_msg_ret("fsp-m settings", -ENOENT); + return log_msg_ret("node", -ENOENT); + node = ofnode_find_subnode(node, "fsp-m"); + if (!ofnode_valid(node)) + return log_msg_ret("fspm", -ENOENT); ret = fsp_m_update_config_from_dtb(node, cfg); if (ret) diff --git a/arch/x86/dts/chromebook_coral.dts b/arch/x86/dts/chromebook_coral.dts index d66e128ae6..3c8fdf2380 100644 --- a/arch/x86/dts/chromebook_coral.dts +++ b/arch/x86/dts/chromebook_coral.dts @@ -174,6 +174,9 @@ */ fsp_s: fsp-s { }; + fsp_m: fsp-m { + u-boot,dm-spl; + }; nhlt { intel,dmic-channels = <4>; @@ -650,7 +653,9 @@ PAD_CFG_NF(LPC_CLKRUNB, UP_20K, DEEP, NF1) /* LPC_CLKRUN_N */ PAD_CFG_NF(LPC_FRAMEB, NATIVE, DEEP, NF1) /* LPC_FRAME_N */ >; +}; +&fsp_m { fspm,package = ; fspm,profile = ; fspm,memory-down = ; -- cgit v1.2.3 From 5e89be1efd4fb4633875f99b1dbe095ff4787c98 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:29 -0700 Subject: x86: apl: Update hostbridge to remove unwanted TPL code At present several strings from this file appear in the TPL binary. Add preprocessor checks to drop them. This reduces the TPL binary size by about 128 bytes. Signed-off-by: Simon Glass --- arch/x86/cpu/apollolake/hostbridge.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/x86/cpu/apollolake/hostbridge.c b/arch/x86/cpu/apollolake/hostbridge.c index e4674f3788..9ec2309d08 100644 --- a/arch/x86/cpu/apollolake/hostbridge.c +++ b/arch/x86/cpu/apollolake/hostbridge.c @@ -60,6 +60,7 @@ struct apl_hostbridge_plat { pci_dev_t bdf; }; +#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) static const struct nhlt_format_config dmic_1ch_formats[] = { /* 48 KHz 16-bits per sample. */ { @@ -155,6 +156,7 @@ static const struct nhlt_endp_descriptor dmic_4ch_descriptors[] = { .num_formats = ARRAY_SIZE(dmic_4ch_formats), }, }; +#endif static int apl_hostbridge_early_init_pinctrl(struct udevice *dev) { @@ -283,7 +285,7 @@ static int apl_acpi_hb_get_name(const struct udevice *dev, char *out_name) return acpi_copy_name(out_name, "RHUB"); } -#ifdef CONFIG_GENERATE_ACPI_TABLE +#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) static int apl_acpi_hb_write_tables(const struct udevice *dev, struct acpi_ctx *ctx) { @@ -322,7 +324,6 @@ static int apl_acpi_hb_write_tables(const struct udevice *dev, return 0; } -#endif static int apl_acpi_setup_nhlt(const struct udevice *dev, struct acpi_ctx *ctx) { @@ -347,6 +348,7 @@ static int apl_acpi_setup_nhlt(const struct udevice *dev, struct acpi_ctx *ctx) return log_msg_ret("channels", -EINVAL); } +#endif static int apl_hostbridge_remove(struct udevice *dev) { @@ -385,21 +387,23 @@ ulong sa_get_tseg_base(struct udevice *dev) struct acpi_ops apl_hostbridge_acpi_ops = { .get_name = apl_acpi_hb_get_name, -#ifdef CONFIG_GENERATE_ACPI_TABLE +#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) .write_tables = apl_acpi_hb_write_tables, -#endif .setup_nhlt = apl_acpi_setup_nhlt, +#endif }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id apl_hostbridge_ids[] = { { .compatible = "intel,apl-hostbridge" }, { } }; +#endif U_BOOT_DRIVER(intel_apl_hostbridge) = { .name = "intel_apl_hostbridge", .id = UCLASS_NORTHBRIDGE, - .of_match = apl_hostbridge_ids, + .of_match = of_match_ptr(apl_hostbridge_ids), .of_to_plat = apl_hostbridge_of_to_plat, .probe = apl_hostbridge_probe, .remove = apl_hostbridge_remove, -- cgit v1.2.3 From 8b842be10c2d40437b1f24a8dce8718c33045376 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:30 -0700 Subject: x86: apl: Reduce size for TPL Update various drivers to use of_match_ptr() and to avoid including debug strings in TPL. Omit the WiFi driver entirely, since it is not used in TPL. This reduces the TPL binary size by about 608 bytes. Signed-off-by: Simon Glass --- arch/x86/cpu/apollolake/lpc.c | 13 ++++++++----- arch/x86/cpu/apollolake/pch.c | 4 +++- arch/x86/cpu/apollolake/pmc.c | 4 +++- arch/x86/cpu/apollolake/uart.c | 4 +++- arch/x86/cpu/intel_common/Makefile | 2 +- arch/x86/cpu/intel_common/itss.c | 4 +++- arch/x86/cpu/intel_common/p2sb.c | 4 +++- arch/x86/cpu/turbo.c | 5 +++++ board/google/chromebook_coral/coral.c | 4 +++- drivers/gpio/intel_gpio.c | 4 +++- drivers/pinctrl/intel/pinctrl_apl.c | 4 +++- drivers/power/acpi_pmc/acpi-pmc-uclass.c | 4 +++- drivers/timer/tsc_timer.c | 4 +++- 13 files changed, 44 insertions(+), 16 deletions(-) diff --git a/arch/x86/cpu/apollolake/lpc.c b/arch/x86/cpu/apollolake/lpc.c index d8e05f6a8f..e085890d63 100644 --- a/arch/x86/cpu/apollolake/lpc.c +++ b/arch/x86/cpu/apollolake/lpc.c @@ -81,10 +81,11 @@ int lpc_open_pmio_window(uint base, uint size) lgir_reg_num = find_unused_pmio_window(); if (lgir_reg_num < 0) { - log_err("LPC: Cannot open IO window: %lx size %lx\n", - bridge_base, size - bridged_size); - log_err("No more IO windows\n"); - + if (spl_phase() > PHASE_TPL) { + log_err("LPC: Cannot open IO window: %lx size %lx\n", + bridge_base, size - bridged_size); + log_err("No more IO windows\n"); + } return -ENOSPC; } lgir_reg_offset = LPC_GENERIC_IO_RANGE(lgir_reg_num); @@ -127,15 +128,17 @@ struct acpi_ops apl_lpc_acpi_ops = { .inject_dsdt = southbridge_inject_dsdt, }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id apl_lpc_ids[] = { { .compatible = "intel,apl-lpc" }, { } }; +#endif /* All pads are LPC already configured by the hostbridge, so no probing here */ U_BOOT_DRIVER(intel_apl_lpc) = { .name = "intel_apl_lpc", .id = UCLASS_LPC, - .of_match = apl_lpc_ids, + .of_match = of_match_ptr(apl_lpc_ids), ACPI_OPS_PTR(&apl_lpc_acpi_ops) }; diff --git a/arch/x86/cpu/apollolake/pch.c b/arch/x86/cpu/apollolake/pch.c index d9832ff249..39d6ad5ed4 100644 --- a/arch/x86/cpu/apollolake/pch.c +++ b/arch/x86/cpu/apollolake/pch.c @@ -23,14 +23,16 @@ static const struct pch_ops apl_pch_ops = { .set_spi_protect = apl_set_spi_protect, }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id apl_pch_ids[] = { { .compatible = "intel,apl-pch" }, { } }; +#endif U_BOOT_DRIVER(intel_apl_pch) = { .name = "intel_apl_pch", .id = UCLASS_PCH, - .of_match = apl_pch_ids, + .of_match = of_match_ptr(apl_pch_ids), .ops = &apl_pch_ops, }; diff --git a/arch/x86/cpu/apollolake/pmc.c b/arch/x86/cpu/apollolake/pmc.c index c40065ab8c..e033baf120 100644 --- a/arch/x86/cpu/apollolake/pmc.c +++ b/arch/x86/cpu/apollolake/pmc.c @@ -212,15 +212,17 @@ static const struct acpi_pmc_ops apl_pmc_ops = { .global_reset_set_enable = apl_global_reset_set_enable, }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id apl_pmc_ids[] = { { .compatible = "intel,apl-pmc" }, { } }; +#endif U_BOOT_DRIVER(intel_apl_pmc) = { .name = "intel_apl_pmc", .id = UCLASS_ACPI_PMC, - .of_match = apl_pmc_ids, + .of_match = of_match_ptr(apl_pmc_ids), .of_to_plat = apl_pmc_ofdata_to_uc_plat, .probe = apl_pmc_probe, .ops = &apl_pmc_ops, diff --git a/arch/x86/cpu/apollolake/uart.c b/arch/x86/cpu/apollolake/uart.c index e523d85b1b..69e5899235 100644 --- a/arch/x86/cpu/apollolake/uart.c +++ b/arch/x86/cpu/apollolake/uart.c @@ -118,15 +118,17 @@ static int apl_ns16550_of_to_plat(struct udevice *dev) return 0; } +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id apl_ns16550_serial_ids[] = { { .compatible = "intel,apl-ns16550" }, { }, }; +#endif U_BOOT_DRIVER(intel_apl_ns16550) = { .name = "intel_apl_ns16550", .id = UCLASS_SERIAL, - .of_match = apl_ns16550_serial_ids, + .of_match = of_match_ptr(apl_ns16550_serial_ids), .plat_auto = sizeof(struct ns16550_plat), .priv_auto = sizeof(struct ns16550), .ops = &ns16550_serial_ops, diff --git a/arch/x86/cpu/intel_common/Makefile b/arch/x86/cpu/intel_common/Makefile index 4a5cf17e41..8b9a810f66 100644 --- a/arch/x86/cpu/intel_common/Makefile +++ b/arch/x86/cpu/intel_common/Makefile @@ -26,7 +26,7 @@ obj-y += cpu.o obj-y += fast_spi.o obj-y += lpc.o obj-y += lpss.o -obj-$(CONFIG_INTEL_GENERIC_WIFI) += generic_wifi.o +obj-$(CONFIG_$(SPL_)INTEL_GENERIC_WIFI) += generic_wifi.o ifndef CONFIG_TARGET_EFI_APP obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += microcode.o ifndef CONFIG_$(SPL_)X86_64 diff --git a/arch/x86/cpu/intel_common/itss.c b/arch/x86/cpu/intel_common/itss.c index e71ea029e5..6515d1f471 100644 --- a/arch/x86/cpu/intel_common/itss.c +++ b/arch/x86/cpu/intel_common/itss.c @@ -230,15 +230,17 @@ static const struct irq_ops itss_ops = { #endif }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id itss_ids[] = { { .compatible = "intel,itss", .data = X86_IRQT_ITSS }, { } }; +#endif U_BOOT_DRIVER(intel_itss) = { .name = "intel_itss", .id = UCLASS_IRQ, - .of_match = itss_ids, + .of_match = of_match_ptr(itss_ids), .ops = &itss_ops, .bind = itss_bind, .of_to_plat = itss_of_to_plat, diff --git a/arch/x86/cpu/intel_common/p2sb.c b/arch/x86/cpu/intel_common/p2sb.c index 3765eeeab0..cb901f265e 100644 --- a/arch/x86/cpu/intel_common/p2sb.c +++ b/arch/x86/cpu/intel_common/p2sb.c @@ -184,15 +184,17 @@ static const struct p2sb_ops p2sb_ops = { .set_hide = intel_p2sb_set_hide, }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id p2sb_ids[] = { { .compatible = "intel,p2sb" }, { } }; +#endif U_BOOT_DRIVER(intel_p2sb) = { .name = "intel_p2sb", .id = UCLASS_P2SB, - .of_match = p2sb_ids, + .of_match = of_match_ptr(p2sb_ids), .probe = p2sb_probe, .remove = p2sb_remove, .ops = &p2sb_ops, diff --git a/arch/x86/cpu/turbo.c b/arch/x86/cpu/turbo.c index f8d85d5a33..4a73cb240d 100644 --- a/arch/x86/cpu/turbo.c +++ b/arch/x86/cpu/turbo.c @@ -35,12 +35,15 @@ static inline void set_global_turbo_state(int state) } #endif +/* gcc 7.3 does not wwant to drop strings, so use #ifdef */ +#ifndef CONFIG_TPL_BUILD static const char *const turbo_state_desc[] = { [TURBO_UNKNOWN] = "unknown", [TURBO_UNAVAILABLE] = "unavailable", [TURBO_DISABLED] = "available but hidden", [TURBO_ENABLED] = "available and visible" }; +#endif /* * Determine the current state of Turbo and cache it for later. @@ -76,7 +79,9 @@ int turbo_get_state(void) } set_global_turbo_state(turbo_state); +#ifndef CONFIG_TPL_BUILD debug("Turbo is %s\n", turbo_state_desc[turbo_state]); +#endif return turbo_state; } diff --git a/board/google/chromebook_coral/coral.c b/board/google/chromebook_coral/coral.c index b8b923c139..34b2c2ac5d 100644 --- a/board/google/chromebook_coral/coral.c +++ b/board/google/chromebook_coral/coral.c @@ -143,14 +143,16 @@ struct acpi_ops coral_acpi_ops = { .inject_dsdt = chromeos_acpi_gpio_generate, }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id coral_ids[] = { { .compatible = "google,coral" }, { } }; +#endif U_BOOT_DRIVER(coral_drv) = { .name = "coral", .id = UCLASS_SYSINFO, - .of_match = coral_ids, + .of_match = of_match_ptr(coral_ids), ACPI_OPS_PTR(&coral_acpi_ops) }; diff --git a/drivers/gpio/intel_gpio.c b/drivers/gpio/intel_gpio.c index 41540d8ebc..eda95485c9 100644 --- a/drivers/gpio/intel_gpio.c +++ b/drivers/gpio/intel_gpio.c @@ -188,15 +188,17 @@ static const struct dm_gpio_ops gpio_intel_ops = { #endif }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id intel_intel_gpio_ids[] = { { .compatible = "intel,gpio" }, { } }; +#endif U_BOOT_DRIVER(intel_gpio) = { .name = "intel_gpio", .id = UCLASS_GPIO, - .of_match = intel_intel_gpio_ids, + .of_match = of_match_ptr(intel_intel_gpio_ids), .ops = &gpio_intel_ops, .of_to_plat = intel_gpio_of_to_plat, .probe = intel_gpio_probe, diff --git a/drivers/pinctrl/intel/pinctrl_apl.c b/drivers/pinctrl/intel/pinctrl_apl.c index 2bb654c8a1..b512a85f3e 100644 --- a/drivers/pinctrl/intel/pinctrl_apl.c +++ b/drivers/pinctrl/intel/pinctrl_apl.c @@ -167,15 +167,17 @@ static int apl_pinctrl_of_to_plat(struct udevice *dev) return intel_pinctrl_of_to_plat(dev, comm, 2); } +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id apl_gpio_ids[] = { { .compatible = "intel,apl-pinctrl"}, { } }; +#endif U_BOOT_DRIVER(intel_apl_pinctrl) = { .name = "intel_apl_pinctrl", .id = UCLASS_PINCTRL, - .of_match = apl_gpio_ids, + .of_match = of_match_ptr(apl_gpio_ids), .probe = intel_pinctrl_probe, .ops = &intel_pinctrl_ops, #if !CONFIG_IS_ENABLED(OF_PLATDATA) diff --git a/drivers/power/acpi_pmc/acpi-pmc-uclass.c b/drivers/power/acpi_pmc/acpi-pmc-uclass.c index 32a2836f0b..34446a34e6 100644 --- a/drivers/power/acpi_pmc/acpi-pmc-uclass.c +++ b/drivers/power/acpi_pmc/acpi-pmc-uclass.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #ifdef CONFIG_X86 #include @@ -60,7 +61,8 @@ int pmc_gpe_init(struct udevice *dev) * are different and if they aren't, use the reset values. */ if (dw[0] == dw[1] || dw[1] == dw[2]) { - log_info("PMC: Using default GPE route"); + if (spl_phase() > PHASE_TPL) + log_info("PMC: Using default GPE route"); gpio_cfg = readl(upriv->gpe_cfg); for (i = 0; i < upriv->gpe0_count; i++) dw[i] = gpio_cfg >> gpe0_shift(upriv, i); diff --git a/drivers/timer/tsc_timer.c b/drivers/timer/tsc_timer.c index e3677704b3..706d52b830 100644 --- a/drivers/timer/tsc_timer.c +++ b/drivers/timer/tsc_timer.c @@ -477,15 +477,17 @@ static const struct timer_ops tsc_timer_ops = { .get_count = tsc_timer_get_count, }; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id tsc_timer_ids[] = { { .compatible = "x86,tsc-timer", }, { } }; +#endif U_BOOT_DRIVER(x86_tsc_timer) = { .name = "x86_tsc_timer", .id = UCLASS_TIMER, - .of_match = tsc_timer_ids, + .of_match = of_match_ptr(tsc_timer_ids), .probe = tsc_timer_probe, .ops = &tsc_timer_ops, }; -- cgit v1.2.3 From 53d59694ce2412db5b3607fa54f516606aab168b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:31 -0700 Subject: x86: pinctrl: Drop unlikely error messages from TPL These errors are only really for development purposes. Drop them to reduce the size of TPL. The error numbers are still reported. This reduces the TPL binary size on coral by about 160 bytes. Signed-off-by: Simon Glass --- drivers/pinctrl/intel/pinctrl.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/pinctrl/intel/pinctrl.c b/drivers/pinctrl/intel/pinctrl.c index 9f96505dd5..987a56b715 100644 --- a/drivers/pinctrl/intel/pinctrl.c +++ b/drivers/pinctrl/intel/pinctrl.c @@ -274,7 +274,9 @@ static int pinctrl_configure_itss(struct udevice *dev, irq = pcr_read32(dev, PAD_CFG1_OFFSET(pad_cfg_offset)); irq &= PAD_CFG1_IRQ_MASK; if (!irq) { - log_err("GPIO %u doesn't support APIC routing\n", cfg->pad); + if (spl_phase() > PHASE_TPL) + log_err("GPIO %u doesn't support APIC routing\n", + cfg->pad); return -EPROTONOSUPPORT; } @@ -314,7 +316,8 @@ static int pinctrl_pad_reset_config_override(const struct pad_community *comm, return config_value; } } - log_err("Logical-to-Chipset mapping not found\n"); + if (spl_phase() > PHASE_TPL) + log_err("Logical-to-Chipset mapping not found\n"); return -ENOENT; } @@ -620,7 +623,9 @@ int intel_pinctrl_of_to_plat(struct udevice *dev, struct intel_pinctrl_priv *priv = dev_get_priv(dev); if (!comm) { - log_err("Cannot find community for pid %d\n", pplat->pid); + if (spl_phase() > PHASE_TPL) + log_err("Cannot find community for pid %d\n", + pplat->pid); return -EDOM; } priv->comm = comm; -- cgit v1.2.3 From cee58bd2ad952d7c5421f8ec266f26e4c6d6a972 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:32 -0700 Subject: x86: tpl: Remove unwanted devicetree string Update this driver to use of_match_ptr(). This reduces the TPL binary size by about 32 bytes. Signed-off-by: Simon Glass --- arch/x86/lib/tpl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/lib/tpl.c b/arch/x86/lib/tpl.c index 15b0212d19..04ff32277f 100644 --- a/arch/x86/lib/tpl.c +++ b/arch/x86/lib/tpl.c @@ -133,14 +133,16 @@ void spl_board_init(void) * for devices, so the TPL BARs continue to be used. Once U-Boot starts it does * the auto allocation (after relocation). */ +#if !CONFIG_IS_ENABLED(OF_PLATDATA) static const struct udevice_id tpl_fake_pci_ids[] = { { .compatible = "pci-x86" }, { } }; +#endif U_BOOT_DRIVER(pci_x86) = { .name = "pci_x86", .id = UCLASS_SIMPLE_BUS, - .of_match = tpl_fake_pci_ids, + .of_match = of_match_ptr(tpl_fake_pci_ids), }; #endif -- cgit v1.2.3 From 941e6304f49d5f47d8802b521619d9ae481a3366 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 23 Dec 2020 08:11:33 -0700 Subject: x86: Fix header guard in asm/pmu.h This has the wrong name. Fix it. Signed-off-by: Simon Glass --- arch/x86/include/asm/pmu.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/pmu.h b/arch/x86/include/asm/pmu.h index b76bdf64a3..818e80881e 100644 --- a/arch/x86/include/asm/pmu.h +++ b/arch/x86/include/asm/pmu.h @@ -2,9 +2,9 @@ /* * Copyright (c) 2017 Intel Corporation */ -#ifndef _X86_ASM_PMU_IPC_H_ -#define _X86_ASM_PMU_IPC_H_ +#ifndef _X86_ASM_PMU_H_ +#define _X86_ASM_PMU_H_ int pmu_turn_power(unsigned int lss, bool on); -#endif /* _X86_ASM_PMU_IPC_H_ */ +#endif /* _X86_ASM_PMU_H_ */ -- cgit v1.2.3 From 10bb90fa30e6e4479a06982e074bb8b3b981301d Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Fri, 20 Nov 2020 09:48:33 +0100 Subject: sandbox: remove ram buffer file when U-Boot is loaded by SPL Update management of "--rm_memory" sandbox's option and force this option when U-Boot is loaded by SPL in os_spl_to_uboot() and remove the ram file after reading in main() as described in option help message: "Remove memory file after reading". This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in os_jump_to_file() when U-Boot is loaded by SPL] is never deleted because state_uninit() is not called after U-Boot execution (CtrlC or with running pytest for example). This issue is reproduced by > build-sandbox_spl/spl/u-boot-spl and CtrlC in U-Bot console > make qcheck One temp file is created after each SPL and U-Boot execution (7 tims in qcheck after test_handoff.py, test_ofplatdata.py, test_spl.py execution). Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- arch/sandbox/cpu/os.c | 5 +++++ arch/sandbox/cpu/start.c | 7 +++++++ arch/sandbox/cpu/state.c | 4 ---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index b56fa04a34..80996a91ce 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -790,6 +790,11 @@ int os_find_u_boot(char *fname, int maxlen) int os_spl_to_uboot(const char *fname) { + struct sandbox_state *state = state_get_current(); + + printf("%s\n", __func__); + /* U-Boot will delete ram buffer after read: "--rm_memory"*/ + state->ram_buf_rm = true; return os_jump_to_file(fname); } diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index fe494aef75..8322ed7a1f 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -457,6 +457,13 @@ int main(int argc, char *argv[]) if (os_parse_args(state, argc, argv)) return 1; + /* Remove old memory file if required */ + if (state->ram_buf_rm && state->ram_buf_fname) { + os_unlink(state->ram_buf_fname); + state->write_ram_buf = false; + state->ram_buf_fname = NULL; + } + ret = sandbox_read_state(state, state->state_fname); if (ret) goto err; diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c index 59f37fab0b..b2901b7a8c 100644 --- a/arch/sandbox/cpu/state.c +++ b/arch/sandbox/cpu/state.c @@ -415,10 +415,6 @@ int state_uninit(void) } } - /* Remove old memory file if required */ - if (state->ram_buf_rm && state->ram_buf_fname) - os_unlink(state->ram_buf_fname); - /* Delete this at the last moment so as not to upset gdb too much */ if (state->jumped_fname) os_unlink(state->jumped_fname); -- cgit v1.2.3 From bfae6cc48afa5bc22703c93af70b27501900f56a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:39:53 -0700 Subject: sandbox: serial: Move priv into a header file Move this struct into a header file so that dtoc can include it in its dt-platdata.c file. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko --- arch/sandbox/include/asm/serial.h | 30 ++++++++++++++++++++++++++++++ drivers/serial/sandbox.c | 16 +--------------- 2 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 arch/sandbox/include/asm/serial.h diff --git a/arch/sandbox/include/asm/serial.h b/arch/sandbox/include/asm/serial.h new file mode 100644 index 0000000000..bc82aebd0e --- /dev/null +++ b/arch/sandbox/include/asm/serial.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 Google LLC + * Written by Simon Glass + */ + +#ifndef __asm_serial_h +#define __asm_serial_h + +#include + +struct sandbox_serial_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_sandbox_serial dtplat; +#endif + int colour; /* Text colour to use for output, -1 for none */ +}; + +/** + * struct sandbox_serial_priv - Private data for this driver + * + * @buf: holds input characters available to be read by this driver + */ +struct sandbox_serial_priv { + struct membuff buf; + char serial_buf[16]; + bool start_of_line; +}; + +#endif /* __asm_serial_h */ diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index a05c56458b..19368ba256 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -17,25 +17,11 @@ #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; -struct sandbox_serial_plat { - int colour; /* Text colour to use for output, -1 for none */ -}; - -/** - * struct sandbox_serial_priv - Private data for this driver - * - * @buf: holds input characters available to be read by this driver - */ -struct sandbox_serial_priv { - struct membuff buf; - char serial_buf[16]; - bool start_of_line; -}; - /** * output_ansi_colour() - Output an ANSI colour code * -- cgit v1.2.3 From f05a7c5ba452c3cee34378ed2ecc206c1605fce1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:39:54 -0700 Subject: sandbox: i2c: Move priv into a header file Move this struct into a header file so that dtoc can include it in its dt-platdata.c file. Signed-off-by: Simon Glass --- arch/sandbox/include/asm/i2c.h | 14 ++++++++++++++ drivers/i2c/sandbox_i2c.c | 5 +---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 arch/sandbox/include/asm/i2c.h diff --git a/arch/sandbox/include/asm/i2c.h b/arch/sandbox/include/asm/i2c.h new file mode 100644 index 0000000000..b482be485c --- /dev/null +++ b/arch/sandbox/include/asm/i2c.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 Google LLC + * Written by Simon Glass + */ + +#ifndef __asn_i2c_h +#define __asn_i2c_h + +struct sandbox_i2c_priv { + bool test_mode; +}; + +#endif /* __asn_i2c_h */ diff --git a/drivers/i2c/sandbox_i2c.c b/drivers/i2c/sandbox_i2c.c index a61dfc096b..c99e6de933 100644 --- a/drivers/i2c/sandbox_i2c.c +++ b/drivers/i2c/sandbox_i2c.c @@ -10,15 +10,12 @@ #include #include #include +#include #include #include #include #include -struct sandbox_i2c_priv { - bool test_mode; -}; - static int get_emul(struct udevice *dev, struct udevice **devp, struct dm_i2c_ops **opsp) { -- cgit v1.2.3 From b0603335673e20a075fc1d401bcdb316828e1a6f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:39:55 -0700 Subject: sandbox: Add a compatible string for spltest At present this driver does not have a compatible string. For it to be used with the coming of-platadata, it must have one. Update it accordingly. Signed-off-by: Simon Glass --- drivers/misc/spltest_sandbox.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/misc/spltest_sandbox.c b/drivers/misc/spltest_sandbox.c index 3ae6707593..6b9701a06a 100644 --- a/drivers/misc/spltest_sandbox.c +++ b/drivers/misc/spltest_sandbox.c @@ -8,8 +8,14 @@ #include #include +static const struct udevice_id sandbox_spl_ids[] = { + { .compatible = "sandbox,spl-test", }, + {} /* sentinel */ +}; + U_BOOT_DRIVER(sandbox_spl_test) = { .name = "sandbox_spl_test", .id = UCLASS_MISC, + .of_match = sandbox_spl_ids, .flags = DM_FLAG_PRE_RELOC, }; -- cgit v1.2.3 From 370746ada7cfd93de248c2274618ba635f9d1f46 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:39:56 -0700 Subject: sandbox: Update dts files to reduce SPL size At present there are require a few devices in the devicetree which are not actually used in SPL. This will cause problems with the new of-platdata, since it will try to instantiate devices which are not compiled into U-Boot. Update the devicetree to remove these devices from SPL. Signed-off-by: Simon Glass --- arch/sandbox/dts/sandbox.dts | 4 ++-- arch/sandbox/dts/sandbox.dtsi | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts index 8b50a40289..a8938a3acc 100644 --- a/arch/sandbox/dts/sandbox.dts +++ b/arch/sandbox/dts/sandbox.dts @@ -41,7 +41,7 @@ cros_ec: cros-ec { reg = <0 0>; - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; compatible = "google,cros-ec-sandbox"; }; @@ -83,7 +83,7 @@ }; spi: spi@0 { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; #address-cells = <1>; #size-cells = <0>; reg = <0 0>; diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index 7b4fc94495..d842f02176 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -56,7 +56,7 @@ }; gpio_a: gpios@0 { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; gpio-controller; compatible = "sandbox,gpio"; #gpio-cells = <1>; @@ -65,7 +65,7 @@ }; gpio_b: gpios@1 { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; gpio-controller; compatible = "sandbox,gpio"; #gpio-cells = <2>; @@ -120,7 +120,7 @@ }; lcd { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; compatible = "sandbox,lcd-sdl"; xres = <1366>; yres = <768>; @@ -209,7 +209,7 @@ spi@0 { firmware_storage_spi: flash@0 { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; reg = <0>; compatible = "spansion,m25p16", "jedec,spi-nor"; spi-max-frequency = <40000000>; @@ -278,7 +278,6 @@ }; tpm { - u-boot,dm-pre-reloc; compatible = "google,sandbox-tpm"; }; @@ -415,6 +414,6 @@ }; keyboard-controller { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; }; }; -- cgit v1.2.3 From 366c4eb4b5df420de3cc32be3089bef68a883d97 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:39:57 -0700 Subject: x86: apl: Move priv/plat structs to headers With the new of-platdata, these need to be available to dt_platdata.c so must be in header files. Move them. Signed-off-by: Simon Glass --- arch/x86/cpu/apollolake/hostbridge.c | 20 +--------------- arch/x86/cpu/apollolake/pmc.c | 8 +------ arch/x86/include/asm/arch-apollolake/gpio.h | 18 +++++++++++++++ arch/x86/include/asm/arch-apollolake/hostbridge.h | 28 +++++++++++++++++++++++ arch/x86/include/asm/arch-apollolake/pmc.h | 16 +++++++++++++ drivers/pinctrl/intel/pinctrl_apl.c | 12 ---------- 6 files changed, 64 insertions(+), 38 deletions(-) create mode 100644 arch/x86/include/asm/arch-apollolake/hostbridge.h create mode 100644 arch/x86/include/asm/arch-apollolake/pmc.h diff --git a/arch/x86/cpu/apollolake/hostbridge.c b/arch/x86/cpu/apollolake/hostbridge.c index 9ec2309d08..9decab7aa3 100644 --- a/arch/x86/cpu/apollolake/hostbridge.c +++ b/arch/x86/cpu/apollolake/hostbridge.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -41,25 +42,6 @@ enum { TOLUD = 0xbc, }; -/** - * struct apl_hostbridge_plat - platform data for hostbridge - * - * @dtplat: Platform data for of-platdata - * @early_pads: Early pad data to set up, each (pad, cfg0, cfg1) - * @early_pads_count: Number of pads to process - * @pciex_region_size: BAR length in bytes - * @bdf: Bus/device/function of hostbridge - */ -struct apl_hostbridge_plat { -#if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_intel_apl_hostbridge dtplat; -#endif - u32 *early_pads; - int early_pads_count; - uint pciex_region_size; - pci_dev_t bdf; -}; - #if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) static const struct nhlt_format_config dmic_1ch_formats[] = { /* 48 KHz 16-bits per sample. */ diff --git a/arch/x86/cpu/apollolake/pmc.c b/arch/x86/cpu/apollolake/pmc.c index e033baf120..e23d38ea07 100644 --- a/arch/x86/cpu/apollolake/pmc.c +++ b/arch/x86/cpu/apollolake/pmc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -53,13 +54,6 @@ enum { CF9_GLB_RST = 1 << 20, }; -struct apl_pmc_plat { -#if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_intel_apl_pmc dtplat; -#endif - pci_dev_t bdf; -}; - static int apl_pmc_fill_power_state(struct udevice *dev) { struct acpi_pmc_upriv *upriv = dev_get_uclass_priv(dev); diff --git a/arch/x86/include/asm/arch-apollolake/gpio.h b/arch/x86/include/asm/arch-apollolake/gpio.h index ab5860c0fd..762160da88 100644 --- a/arch/x86/include/asm/arch-apollolake/gpio.h +++ b/arch/x86/include/asm/arch-apollolake/gpio.h @@ -485,4 +485,22 @@ /* This is needed by ACPI */ #define GPIO_NUM_PAD_CFG_REGS 2 /* DW0, DW1 */ +#ifndef __ASSEMBLY__ + +#include + +/** + * struct apl_gpio_plat - platform data for each device + * + * @dtplat: of-platdata data from C struct + */ +struct apl_gpio_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + /* Put this first since driver model will copy the data here */ + struct dtd_intel_apl_pinctrl dtplat; +#endif +}; + +#endif /* __ASSEMBLY__ */ + #endif /* _ASM_ARCH_GPIO_H_ */ diff --git a/arch/x86/include/asm/arch-apollolake/hostbridge.h b/arch/x86/include/asm/arch-apollolake/hostbridge.h new file mode 100644 index 0000000000..f4dce0d522 --- /dev/null +++ b/arch/x86/include/asm/arch-apollolake/hostbridge.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 Google LLC + */ + +#ifndef _ASM_ARCH_HOSTBRIDGE_H_ +#define _ASM_ARCH_HOSTBRIDGE_H_ + +/** + * struct apl_hostbridge_plat - platform data for hostbridge + * + * @dtplat: Platform data for of-platdata + * @early_pads: Early pad data to set up, each (pad, cfg0, cfg1) + * @early_pads_count: Number of pads to process + * @pciex_region_size: BAR length in bytes + * @bdf: Bus/device/function of hostbridge + */ +struct apl_hostbridge_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_intel_apl_hostbridge dtplat; +#endif + u32 *early_pads; + int early_pads_count; + uint pciex_region_size; + pci_dev_t bdf; +}; + +#endif /* _ASM_ARCH_HOSTBRIDGE_H_ */ diff --git a/arch/x86/include/asm/arch-apollolake/pmc.h b/arch/x86/include/asm/arch-apollolake/pmc.h new file mode 100644 index 0000000000..23ac8fe7e2 --- /dev/null +++ b/arch/x86/include/asm/arch-apollolake/pmc.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 Google LLC + */ + +#ifndef ASM_ARCH_PMC_H +#define ASM_ARCH_PMC_H + +struct apl_pmc_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_intel_apl_pmc dtplat; +#endif + pci_dev_t bdf; +}; + +#endif /* ASM_ARCH_PMC_H */ diff --git a/drivers/pinctrl/intel/pinctrl_apl.c b/drivers/pinctrl/intel/pinctrl_apl.c index b512a85f3e..acaa55d2e7 100644 --- a/drivers/pinctrl/intel/pinctrl_apl.c +++ b/drivers/pinctrl/intel/pinctrl_apl.c @@ -17,18 +17,6 @@ #include #include -/** - * struct apl_gpio_plat - platform data for each device - * - * @dtplat: of-platdata data from C struct - */ -struct apl_gpio_plat { -#if CONFIG_IS_ENABLED(OF_PLATDATA) - /* Put this first since driver model will copy the data here */ - struct dtd_intel_apl_pinctrl dtplat; -#endif -}; - static const struct reset_mapping rst_map[] = { { .logical = PAD_CFG0_LOGICAL_RESET_PWROK, .chipset = 0U << 30 }, { .logical = PAD_CFG0_LOGICAL_RESET_DEEP, .chipset = 1U << 30 }, -- cgit v1.2.3 From f6257f7914858cd99219feb3185c679137857b60 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:39:58 -0700 Subject: x86: Move priv/plat structs for intel_common to headers With the new of-platdata, these need to be available to dt_platdata.c so must be in header files. Move them. Signed-off-by: Simon Glass --- arch/x86/cpu/intel_common/itss.c | 19 ------------------- arch/x86/cpu/intel_common/p2sb.c | 9 +-------- arch/x86/include/asm/itss.h | 21 +++++++++++++++++++++ arch/x86/include/asm/p2sb.h | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 arch/x86/include/asm/p2sb.h diff --git a/arch/x86/cpu/intel_common/itss.c b/arch/x86/cpu/intel_common/itss.c index 6515d1f471..ae4de4ca8c 100644 --- a/arch/x86/cpu/intel_common/itss.c +++ b/arch/x86/cpu/intel_common/itss.c @@ -19,25 +19,6 @@ #include #include -struct itss_plat { -#if CONFIG_IS_ENABLED(OF_PLATDATA) - /* Put this first since driver model will copy the data here */ - struct dtd_intel_itss dtplat; -#endif -}; - -/* struct pmc_route - Routing for PMC to GPIO */ -struct pmc_route { - u32 pmc; - u32 gpio; -}; - -struct itss_priv { - struct pmc_route *route; - uint route_count; - u32 irq_snapshot[NUM_IPC_REGS]; -}; - static int set_polarity(struct udevice *dev, uint irq, bool active_low) { u32 mask; diff --git a/arch/x86/cpu/intel_common/p2sb.c b/arch/x86/cpu/intel_common/p2sb.c index cb901f265e..d73ae438bb 100644 --- a/arch/x86/cpu/intel_common/p2sb.c +++ b/arch/x86/cpu/intel_common/p2sb.c @@ -13,20 +13,13 @@ #include #include #include +#include #include #include #define PCH_P2SB_E0 0xe0 #define HIDE_BIT BIT(0) -struct p2sb_plat { -#if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_intel_p2sb dtplat; -#endif - ulong mmio_base; - pci_dev_t bdf; -}; - /* PCI config space registers */ #define HPTC_OFFSET 0x60 #define HPTC_ADDR_ENABLE_BIT BIT(7) diff --git a/arch/x86/include/asm/itss.h b/arch/x86/include/asm/itss.h index f7d3240384..6d4793277e 100644 --- a/arch/x86/include/asm/itss.h +++ b/arch/x86/include/asm/itss.h @@ -11,6 +11,8 @@ #ifndef _ASM_ARCH_ITSS_H #define _ASM_ARCH_ITSS_H +#include + #define GPIO_IRQ_START 50 #define GPIO_IRQ_END ITSS_MAX_IRQ @@ -42,4 +44,23 @@ /* ITSS Power reduction control */ #define PCR_ITSS_ITSSPRC 0x3300 +struct itss_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + /* Put this first since driver model will copy the data here */ + struct dtd_intel_itss dtplat; +#endif +}; + +/* struct pmc_route - Routing for PMC to GPIO */ +struct pmc_route { + u32 pmc; + u32 gpio; +}; + +struct itss_priv { + struct pmc_route *route; + uint route_count; + u32 irq_snapshot[NUM_IPC_REGS]; +}; + #endif /* _ASM_ARCH_ITSS_H */ diff --git a/arch/x86/include/asm/p2sb.h b/arch/x86/include/asm/p2sb.h new file mode 100644 index 0000000000..6f63eae8e2 --- /dev/null +++ b/arch/x86/include/asm/p2sb.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 Google LLC + */ + +#ifndef ASM_P2SB_H +#define ASM_P2SB_H + +/* Platform data for the P2SB */ +struct p2sb_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_intel_p2sb dtplat; +#endif + ulong mmio_base; + pci_dev_t bdf; +}; + +#endif /* ASM_P2SB_H */ -- cgit v1.2.3 From a53f6fad7ea20f6ccde21f68e3b44ab7fe8bf6cd Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:39:59 -0700 Subject: x86: spl: Move priv/plat structs to headers With the new of-platdata, these need to be available to dt_platdata.c so must be in header files. Move them. Signed-off-by: Simon Glass --- drivers/spi/ich.c | 11 ----------- drivers/spi/ich.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/spi/ich.c b/drivers/spi/ich.c index e02850e9f2..1cd410493b 100644 --- a/drivers/spi/ich.c +++ b/drivers/spi/ich.c @@ -38,17 +38,6 @@ #define debug_trace(x, args...) #endif -struct ich_spi_plat { -#if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_intel_fast_spi dtplat; -#endif - enum ich_version ich_version; /* Controller version, 7 or 9 */ - bool lockdown; /* lock down controller settings? */ - ulong mmio_base; /* Base of MMIO registers */ - pci_dev_t bdf; /* PCI address used by of-platdata */ - bool hwseq; /* Use hardware sequencing (not s/w) */ -}; - static u8 ich_readb(struct ich_spi_priv *priv, int reg) { u8 value = readb(priv->base + reg); diff --git a/drivers/spi/ich.h b/drivers/spi/ich.h index 23c7827740..8fd150d44a 100644 --- a/drivers/spi/ich.h +++ b/drivers/spi/ich.h @@ -230,4 +230,15 @@ struct ich_spi_priv { struct udevice *pch; /* PCH, used to control SPI access */ }; +struct ich_spi_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_intel_fast_spi dtplat; +#endif + enum ich_version ich_version; /* Controller version, 7 or 9 */ + bool lockdown; /* lock down controller settings? */ + ulong mmio_base; /* Base of MMIO registers */ + pci_dev_t bdf; /* PCI address used by of-platdata */ + bool hwseq; /* Use hardware sequencing (not s/w) */ +}; + #endif /* _ICH_H_ */ -- cgit v1.2.3 From e2a7cfe9d5fce65789972a31ff50fb1d8d509848 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:00 -0700 Subject: spi: Tidy up get/set of device node This code is a bit odd in that it only reads and updates the livetree version of the device ofnode. This means it won't work with flattree. Update the code to work as it was presumably intended. Signed-off-by: Simon Glass --- drivers/mtd/nand/spi/core.c | 2 +- include/linux/mtd/mtd.h | 9 ++++----- include/linux/mtd/nand.h | 14 ++++++++++++++ include/linux/mtd/spi-nor.h | 2 ++ include/linux/mtd/spinand.h | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index fc9d4edbe0..ab9a24ed5b 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1173,7 +1173,7 @@ static int spinand_probe(struct udevice *dev) return -ENOMEM; sprintf(mtd->name, "spi-nand%d", spi_nand_idx++); spinand->slave = slave; - spinand_set_of_node(spinand, dev->node.np); + spinand_set_ofnode(spinand, dev->node); #endif ret = spinand_init(spinand); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 1b9151714c..54d03d0240 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -332,15 +332,14 @@ struct mtd_info { }; #if IS_ENABLED(CONFIG_DM) -static inline void mtd_set_of_node(struct mtd_info *mtd, - const struct device_node *np) +static inline void mtd_set_ofnode(struct mtd_info *mtd, ofnode node) { - mtd->dev->node.np = np; + mtd->dev->node = node; } -static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd) +static inline const ofnode mtd_get_ofnode(struct mtd_info *mtd) { - return mtd->dev->node.np; + return mtd->dev->node; } #else struct device_node; diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index 13e8dd1103..7774c17ad5 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h @@ -389,6 +389,7 @@ static inline int nanddev_unregister(struct nand_device *nand) return mtd_device_unregister(nand->mtd); } +#ifndef __UBOOT__ /** * nanddev_set_of_node() - Attach a DT node to a NAND device * @nand: NAND device @@ -412,6 +413,19 @@ static inline const struct device_node *nanddev_get_of_node(struct nand_device * { return mtd_get_of_node(nand->mtd); } +#else +/** + * nanddev_set_of_node() - Attach a DT node to a NAND device + * @nand: NAND device + * @node: ofnode + * + * Attach a DT node to a NAND device. + */ +static inline void nanddev_set_ofnode(struct nand_device *nand, ofnode node) +{ + mtd_set_ofnode(nand->mtd, node); +} +#endif /* __UBOOT__ */ /** * nanddev_offs_to_pos() - Convert an absolute NAND offset into a NAND position diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 233fdc341a..2642bf91d0 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -352,6 +352,7 @@ struct spi_nor { u32 erase_size; }; +#ifndef __UBOOT__ static inline void spi_nor_set_flash_node(struct spi_nor *nor, const struct device_node *np) { @@ -363,6 +364,7 @@ device_node *spi_nor_get_flash_node(struct spi_nor *nor) { return mtd_get_of_node(&nor->mtd); } +#endif /* __UBOOT__ */ /** * struct spi_nor_hwcaps - Structure for describing the hardware capabilies diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h index 88bacde91e..15bcd59f34 100644 --- a/include/linux/mtd/spinand.h +++ b/include/linux/mtd/spinand.h @@ -412,6 +412,7 @@ spinand_to_nand(struct spinand_device *spinand) return &spinand->base; } +#ifndef __UBOOT__ /** * spinand_set_of_node - Attach a DT node to a SPI NAND device * @spinand: SPI NAND device @@ -424,6 +425,20 @@ static inline void spinand_set_of_node(struct spinand_device *spinand, { nanddev_set_of_node(&spinand->base, np); } +#else +/** + * spinand_set_of_node - Attach a DT node to a SPI NAND device + * @spinand: SPI NAND device + * @node: ofnode + * + * Attach a DT node to a SPI NAND device. + */ +static inline void spinand_set_ofnode(struct spinand_device *spinand, + ofnode node) +{ + nanddev_set_ofnode(&spinand->base, node); +} +#endif /* __UBOOT__ */ int spinand_match_and_init(struct spinand_device *dev, const struct spinand_info *table, -- cgit v1.2.3 From a1a8a633859ce6ecfe298e3b40eb97c49248f8a0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:01 -0700 Subject: spi: Tweak a few strange SPI NOR features for of-platdata The #define of one struct to another has been around for a while. It confuses dtoc and makes it think that struct spi_flash does not exist. Make a few changes to improve things while we wait for migration to be completed: - Move the 'struct spi_flash' to column 1 so dtoc scans it - Remove the #define when compiling dt-platdata.c - Update the strange mtd_get/set_of_node() functions - Use struct spi_nor in the drivers, so dtoc sees the correct struct Signed-off-by: Simon Glass --- drivers/mtd/spi/sf-uclass.c | 2 +- drivers/mtd/spi/sf_probe.c | 2 +- include/linux/mtd/spi-nor.h | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index ed629f1d45..3017022abb 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -100,5 +100,5 @@ UCLASS_DRIVER(spi_flash) = { .id = UCLASS_SPI_FLASH, .name = "spi_flash", .post_bind = spi_flash_post_bind, - .per_device_auto = sizeof(struct spi_flash), + .per_device_auto = sizeof(struct spi_nor), }; diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index c8bcec3c58..630787df1b 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -166,7 +166,7 @@ U_BOOT_DRIVER(jedec_spi_nor) = { .of_match = spi_flash_std_ids, .probe = spi_flash_std_probe, .remove = spi_flash_std_remove, - .priv_auto = sizeof(struct spi_flash), + .priv_auto = sizeof(struct spi_nor), .ops = &spi_flash_std_ops, }; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 2642bf91d0..363f2749d7 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -258,11 +258,13 @@ struct flash_info; /* * TODO: Remove, once all users of spi_flash interface are moved to MTD * - * struct spi_flash { +struct spi_flash { * Defined below (keep this text to enable searching for spi_flash decl) * } */ +#ifndef DT_PLATDATA_C #define spi_flash spi_nor +#endif /** * struct spi_nor - Structure for defining a the SPI NOR layer -- cgit v1.2.3 From 332b98660f964895f05277dbbc2e0fd05d04ca9b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:02 -0700 Subject: x86: apl: Use struct spi_nor instead of struct spi_flash This construct effectively uses struct spi_nor due to a #define in spi-nor.h so we may as well use that struct here. This allows dtoc to parse it correctly. Signed-off-by: Simon Glass --- arch/x86/cpu/apollolake/spl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/cpu/apollolake/spl.c b/arch/x86/cpu/apollolake/spl.c index 16a2f15c6b..8991d5e648 100644 --- a/arch/x86/cpu/apollolake/spl.c +++ b/arch/x86/cpu/apollolake/spl.c @@ -97,7 +97,7 @@ U_BOOT_DRIVER(winbond_w25q128fw) = { .id = UCLASS_SPI_FLASH, .of_match = apl_flash_ids, .probe = apl_flash_probe, - .priv_auto = sizeof(struct spi_flash), + .priv_auto = sizeof(struct spi_nor), .ops = &apl_flash_ops, }; -- cgit v1.2.3 From 6563b205eb65653e8fe0d3f92106ec37d28a4af7 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:03 -0700 Subject: dm: core: Move priv/plat structs for simple_bus to headers With the new of-platdata, these need to be available to dt_platdata.c so must be in header files. Move them. Signed-off-by: Simon Glass --- drivers/core/simple-bus.c | 7 +------ include/dm/simple_bus.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 include/dm/simple_bus.h diff --git a/drivers/core/simple-bus.c b/drivers/core/simple-bus.c index 7dbcbecd94..b0c2c20958 100644 --- a/drivers/core/simple-bus.c +++ b/drivers/core/simple-bus.c @@ -5,12 +5,7 @@ #include #include - -struct simple_bus_plat { - u32 base; - u32 size; - u32 target; -}; +#include fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr) { diff --git a/include/dm/simple_bus.h b/include/dm/simple_bus.h new file mode 100644 index 0000000000..4ad4cc4051 --- /dev/null +++ b/include/dm/simple_bus.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 Google LLC + */ + +#ifndef __DM_SIMPLE_BUS_H +#define __DM_SIMPLE_BUS_H + +struct simple_bus_plat { + u32 base; + u32 size; + u32 target; +}; + +#endif -- cgit v1.2.3 From 6a2350f8c9d60f318b3ffff3231b4ca891957da4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:04 -0700 Subject: x86: sysreset: Move priv/plat structs to headers With the new of-platdata, these need to be available to dt_platdata.c so must be in header files. Move them and add the dtd struct too. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko --- arch/x86/include/asm/sysreset.h | 18 ++++++++++++++++++ drivers/sysreset/sysreset_x86.c | 5 +---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 arch/x86/include/asm/sysreset.h diff --git a/arch/x86/include/asm/sysreset.h b/arch/x86/include/asm/sysreset.h new file mode 100644 index 0000000000..5e586f51c0 --- /dev/null +++ b/arch/x86/include/asm/sysreset.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 Google LLC + */ +#ifndef _X86_ASM_SYSRESET_H_ +#define _X86_ASM_SYSRESET_H_ + +#include + +struct x86_sysreset_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_x86_reset dtplat; +#endif + + struct udevice *pch; +}; + +#endif /* _X86_ASM_SYSRESET_H_ */ diff --git a/drivers/sysreset/sysreset_x86.c b/drivers/sysreset/sysreset_x86.c index 8f9970301e..8042f3994f 100644 --- a/drivers/sysreset/sysreset_x86.c +++ b/drivers/sysreset/sysreset_x86.c @@ -13,10 +13,7 @@ #include #include #include - -struct x86_sysreset_plat { - struct udevice *pch; -}; +#include /* * Power down the machine by using the power management sleep control -- cgit v1.2.3 From 21303d1de7cabe1e2d4ebfe82425ca816a1394a6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:05 -0700 Subject: x86: apl: Adjust how the UART gets its platform data At present this driver calls malloc() to start a new platform data structure, fills it in and tells driver model to use it. We want to avoid malloc, particularly with the new version of of-platdata. Create a new struct which encompasses both the dtd struct and the ns16550 one, to avoid this. Unfortunately we must copy the data into the right place for the ns16550 driver. Add some comments about this. Signed-off-by: Simon Glass --- arch/x86/cpu/apollolake/uart.c | 43 ++++++++++++++++------------- arch/x86/include/asm/arch-apollolake/uart.h | 19 ++++++++++++- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/arch/x86/cpu/apollolake/uart.c b/arch/x86/cpu/apollolake/uart.c index 69e5899235..876fa592b8 100644 --- a/arch/x86/cpu/apollolake/uart.c +++ b/arch/x86/cpu/apollolake/uart.c @@ -17,6 +17,7 @@ #include #include #include +#include /* Low-power Subsystem (LPSS) clock register */ enum { @@ -69,7 +70,7 @@ void apl_uart_init(pci_dev_t bdf, ulong base) * This driver uses its own compatible string but almost everything else from * the standard ns16550 driver. This allows us to provide an of-platdata * implementation, since the platdata produced by of-platdata does not match - * struct ns16550_plat. + * struct apl_ns16550_plat. * * When running with of-platdata (generally TPL), the platdata is converted to * something that ns16550 expects. When running withoutof-platdata (SPL, U-Boot @@ -78,10 +79,10 @@ void apl_uart_init(pci_dev_t bdf, ulong base) static int apl_ns16550_probe(struct udevice *dev) { - struct ns16550_plat *plat = dev_get_plat(dev); + struct apl_ns16550_plat *plat = dev_get_plat(dev); if (!CONFIG_IS_ENABLED(PCI)) - apl_uart_init(plat->bdf, plat->base); + apl_uart_init(plat->ns16550.bdf, plat->ns16550.base); return ns16550_serial_probe(dev); } @@ -89,24 +90,28 @@ static int apl_ns16550_probe(struct udevice *dev) static int apl_ns16550_of_to_plat(struct udevice *dev) { #if CONFIG_IS_ENABLED(OF_PLATDATA) - struct dtd_intel_apl_ns16550 *dtplat = dev_get_plat(dev); - struct ns16550_plat *plat; + struct dtd_intel_apl_ns16550 *dtplat; + struct apl_ns16550_plat *plat = dev_get_plat(dev); + struct ns16550_plat ns; /* - * Convert our plat to the ns16550's plat, so we can just use - * that driver + * The device's plat uses struct apl_ns16550_plat which starts with the + * dtd struct, but the ns16550 driver expects it to be struct ns16550. + * Set up what that driver expects. Note that this means that the values + * cannot be read in this driver when using of-platdata. + * + * TODO(sjg@chromium.org): Consider having a separate plat pointer for + * of-platdata so that it is not necessary to overwrite this. */ - plat = malloc(sizeof(*plat)); - if (!plat) - return -ENOMEM; - plat->base = dtplat->early_regs[0]; - plat->reg_width = 1; - plat->reg_shift = dtplat->reg_shift; - plat->reg_offset = 0; - plat->clock = dtplat->clock_frequency; - plat->fcr = UART_FCR_DEFVAL; - plat->bdf = pci_ofplat_get_devfn(dtplat->reg[0]); - dev_set_plat(dev, plat); + dtplat = &plat->dtplat; + ns.base = dtplat->early_regs[0]; + ns.reg_width = 1; + ns.reg_shift = dtplat->reg_shift; + ns.reg_offset = 0; + ns.clock = dtplat->clock_frequency; + ns.fcr = UART_FCR_DEFVAL; + ns.bdf = pci_ofplat_get_devfn(dtplat->reg[0]); + memcpy(plat, &ns, sizeof(ns)); #else int ret; @@ -129,7 +134,7 @@ U_BOOT_DRIVER(intel_apl_ns16550) = { .name = "intel_apl_ns16550", .id = UCLASS_SERIAL, .of_match = of_match_ptr(apl_ns16550_serial_ids), - .plat_auto = sizeof(struct ns16550_plat), + .plat_auto = sizeof(struct apl_ns16550_plat), .priv_auto = sizeof(struct ns16550), .ops = &ns16550_serial_ops, .of_to_plat = apl_ns16550_of_to_plat, diff --git a/arch/x86/include/asm/arch-apollolake/uart.h b/arch/x86/include/asm/arch-apollolake/uart.h index d4fffe6525..38335b0490 100644 --- a/arch/x86/include/asm/arch-apollolake/uart.h +++ b/arch/x86/include/asm/arch-apollolake/uart.h @@ -6,6 +6,23 @@ #ifndef _ASM_ARCH_UART_H #define _ASM_ARCH_UART_H +#include + +/** + * struct apl_ns16550_plat - platform data for the APL UART + * + * Note that when of-platdata is in use, apl_ns16550_of_to_plat() actually + * copies the ns16550_plat contents to the start of this struct, meaning that + * dtplat is no-longer valid. This is done so that the ns16550 driver can use + * dev_get_plat() without any offsets or adjustments. + */ +struct apl_ns16550_plat { +#if CONFIG_IS_ENABLED(OF_PLATDATA) + struct dtd_intel_apl_ns16550 dtplat; +#endif + struct ns16550_plat ns16550; +}; + /** * apl_uart_init() - Set up the APL UART device and clock * @@ -15,6 +32,6 @@ * The UART won't actually work unless the GPIO settings are correct and the * signals actually exit the SoC. See board_debug_uart_init() for that. */ -int apl_uart_init(pci_dev_t bdf, ulong base); +void apl_uart_init(pci_dev_t bdf, ulong base); #endif -- cgit v1.2.3 From a59f3d230eb995fd740656c0f33b3036efec40f0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:06 -0700 Subject: x86: coral: Remove unwanted nodes from SPL/TPL Some devices are not needed in SPL/TPL. For TPL this causes the generation of unnecessary of-platadata structs. Make some adjustments to fix this. Signed-off-by: Simon Glass --- arch/x86/dts/chromebook_coral.dts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/arch/x86/dts/chromebook_coral.dts b/arch/x86/dts/chromebook_coral.dts index 3c8fdf2380..a846022095 100644 --- a/arch/x86/dts/chromebook_coral.dts +++ b/arch/x86/dts/chromebook_coral.dts @@ -102,12 +102,13 @@ }; cpus { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; #address-cells = <1>; #size-cells = <0>; cpu_0: cpu@0 { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; + u-boot,dm-spl; device_type = "cpu"; compatible = "intel,apl-cpu"; reg = <0>; @@ -184,12 +185,14 @@ }; punit@0,1 { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; + u-boot,dm-spl; reg = <0x00000800 0 0 0 0>; compatible = "intel,apl-punit"; }; gma@2,0 { + u-boot,dm-pre-proper; reg = <0x00001000 0 0 0 0>; compatible = "fsp-fb"; }; @@ -324,7 +327,8 @@ }; spi: fast-spi@d,2 { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; + u-boot,dm-spl; reg = <0x02006a10 0 0 0 0>; #address-cells = <1>; #size-cells = <0>; @@ -335,7 +339,8 @@ fwstore_spi: spi-flash@0 { #size-cells = <1>; #address-cells = <1>; - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; + u-boot,dm-spl; reg = <0>; compatible = "winbond,w25q128fw", "jedec,spi-nor"; @@ -577,7 +582,7 @@ #size-cells = <0>; u-boot,dm-pre-reloc; cros_ec: cros-ec { - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; compatible = "google,cros-ec-lpc"; reg = <0x204 1 0x200 1 0x880 0x80>; -- cgit v1.2.3 From e7144b07e46af8e7c10841aaeb4d517ad33f4242 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:07 -0700 Subject: x86: Drop rtc from SPL The RTC is not currently used in SPL. Drop it so that it does not take up space. Signed-off-by: Simon Glass --- arch/x86/dts/rtc.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/dts/rtc.dtsi b/arch/x86/dts/rtc.dtsi index d0bbd84e50..942cc937dc 100644 --- a/arch/x86/dts/rtc.dtsi +++ b/arch/x86/dts/rtc.dtsi @@ -1,7 +1,7 @@ / { rtc: rtc { compatible = "motorola,mc146818"; - u-boot,dm-pre-reloc; + u-boot,dm-pre-proper; reg = <0x70 2>; }; }; -- cgit v1.2.3 From 82021e31a71ae51bea1226e58727dd3163a26895 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:08 -0700 Subject: dm: core: Split out alloc code into a new function Add a new function to handle the allocation of private/platform data for a device. This will make it easier to skip this feature when using the new of-platdata. Signed-off-by: Simon Glass --- drivers/core/device.c | 89 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 37 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index a4c8310f81..72169632c8 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -323,34 +323,17 @@ static void *alloc_priv(int size, uint flags) return priv; } -int device_of_to_plat(struct udevice *dev) +/** + * device_alloc_priv() - Allocate priv/plat data required by the device + * + * @dev: Device to process + * @return 0 if OK, -ENOMEM if out of memory + */ +static int device_alloc_priv(struct udevice *dev) { const struct driver *drv; - int size = 0; void *ptr; - int ret; - - if (!dev) - return -EINVAL; - - if (dev->flags & DM_FLAG_PLATDATA_VALID) - return 0; - - /* Ensure all parents have ofdata */ - if (dev->parent) { - ret = device_of_to_plat(dev->parent); - if (ret) - goto fail; - - /* - * The device might have already been probed during - * the call to device_probe() on its parent device - * (e.g. PCI bridge devices). Test the flags again - * so that we don't mess up the device. - */ - if (dev->flags & DM_FLAG_PLATDATA_VALID) - return 0; - } + int size; drv = dev->driver; assert(drv); @@ -358,20 +341,17 @@ int device_of_to_plat(struct udevice *dev) /* Allocate private data if requested and not reentered */ if (drv->priv_auto && !dev_get_priv(dev)) { ptr = alloc_priv(drv->priv_auto, drv->flags); - if (!ptr) { - ret = -ENOMEM; - goto fail; - } + if (!ptr) + return -ENOMEM; dev_set_priv(dev, ptr); } + /* Allocate private data if requested and not reentered */ size = dev->uclass->uc_drv->per_device_auto; if (size && !dev_get_uclass_priv(dev)) { ptr = alloc_priv(size, dev->uclass->uc_drv->flags); - if (!ptr) { - ret = -ENOMEM; - goto fail; - } + if (!ptr) + return -ENOMEM; dev_set_uclass_priv(dev, ptr); } @@ -382,14 +362,49 @@ int device_of_to_plat(struct udevice *dev) size = dev->parent->uclass->uc_drv->per_child_auto; if (size && !dev_get_parent_priv(dev)) { ptr = alloc_priv(size, drv->flags); - if (!ptr) { - ret = -ENOMEM; - goto fail; - } + if (!ptr) + return -ENOMEM; dev_set_parent_priv(dev, ptr); } } + return 0; +} + +int device_of_to_plat(struct udevice *dev) +{ + const struct driver *drv; + int ret; + + if (!dev) + return -EINVAL; + + if (dev->flags & DM_FLAG_PLATDATA_VALID) + return 0; + + /* Ensure all parents have ofdata */ + if (dev->parent) { + ret = device_of_to_plat(dev->parent); + if (ret) + goto fail; + + /* + * The device might have already been probed during + * the call to device_probe() on its parent device + * (e.g. PCI bridge devices). Test the flags again + * so that we don't mess up the device. + */ + if (dev->flags & DM_FLAG_PLATDATA_VALID) + return 0; + } + + ret = device_alloc_priv(dev); + if (ret) + goto fail; + + drv = dev->driver; + assert(drv); + if (drv->of_to_plat && (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_of_node(dev))) { ret = drv->of_to_plat(dev); -- cgit v1.2.3 From 2462139fdd4f1f5eb50427e287a802b9c9eef097 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:09 -0700 Subject: dm: core: Rename sqq to seq_ Now that the sequence-numbering migration is complete, rename this member back to seq_, adding an underscore to indicate it is internal to driver model. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko --- drivers/core/device.c | 8 ++++---- drivers/core/dump.c | 2 +- drivers/core/uclass.c | 8 ++++---- drivers/pci/pci-uclass.c | 2 +- include/dm/device.h | 9 +++++---- test/dm/core.c | 6 +++--- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 72169632c8..f4ae7786ee 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -73,7 +73,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, dev->driver = drv; dev->uclass = uc; - dev->sqq = -1; + dev->seq_ = -1; if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) && (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) { /* @@ -83,13 +83,13 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { if (uc->uc_drv->name && ofnode_valid(node)) { - if (!dev_read_alias_seq(dev, &dev->sqq)) + if (!dev_read_alias_seq(dev, &dev->seq_)) auto_seq = false; } } } if (auto_seq && !(uc->uc_drv->flags & DM_UC_FLAG_NO_AUTO_SEQ)) - dev->sqq = uclass_find_next_free_seq(uc); + dev->seq_ = uclass_find_next_free_seq(uc); if (drv->plat_auto) { bool alloc = !plat; @@ -658,7 +658,7 @@ int device_find_child_by_seq(const struct udevice *parent, int seq, *devp = NULL; list_for_each_entry(dev, &parent->child_head, sibling_node) { - if (dev->sqq == seq) { + if (dev->seq_ == seq) { *devp = dev; return 0; } diff --git a/drivers/core/dump.c b/drivers/core/dump.c index 7784ec02de..1d4628abc7 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -69,7 +69,7 @@ static void dm_display_line(struct udevice *dev, int index) printf("%-3i %c %s @ %08lx", index, dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ', dev->name, (ulong)map_to_sysmem(dev)); - if (dev->sqq != -1) + if (dev->seq_ != -1) printf(", seq %d", dev_seq(dev)); puts("\n"); } diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index f60bc9a850..e773e34833 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -297,8 +297,8 @@ int uclass_find_next_free_seq(struct uclass *uc) /* Avoid conflict with existing devices */ list_for_each_entry(dev, &uc->dev_head, uclass_node) { - if (dev->sqq > max) - max = dev->sqq; + if (dev->seq_ > max) + max = dev->seq_; } /* * At this point, max will be -1 if there are no existing aliases or @@ -323,8 +323,8 @@ int uclass_find_device_by_seq(enum uclass_id id, int seq, struct udevice **devp) return ret; uclass_foreach_dev(dev, uc) { - log_debug(" - %d '%s'\n", dev->sqq, dev->name); - if (dev->sqq == seq) { + log_debug(" - %d '%s'\n", dev->seq_, dev->name); + if (dev->seq_ == seq) { *devp = dev; log_debug(" - found\n"); return 0; diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 37a233878d..1f6c51f1e8 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -1019,7 +1019,7 @@ static int pci_uclass_pre_probe(struct udevice *bus) ret = uclass_get(UCLASS_PCI, &uc); if (ret) return ret; - bus->sqq = uclass_find_next_free_seq(uc); + bus->seq_ = uclass_find_next_free_seq(uc); } /* For bridges, use the top-level PCI controller */ diff --git a/include/dm/device.h b/include/dm/device.h index daebd6eb68..a063bbaa17 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -136,11 +136,12 @@ enum { * @child_head: List of children of this device * @sibling_node: Next device in list of all devices * @flags: Flags for this device DM_FLAG_... - * @seq: Allocated sequence number for this device (-1 = none). This is set up + * @seq_: Allocated sequence number for this device (-1 = none). This is set up * when the device is bound and is unique within the device's uclass. If the * device has an alias in the devicetree then that is used to set the sequence * number. Otherwise, the next available number is used. Sequence numbers are - * used by certain commands that need device to be numbered (e.g. 'mmc dev') + * used by certain commands that need device to be numbered (e.g. 'mmc dev'). + * (do not access outside driver model) * @devres_head: List of memory allocations associated with this device. * When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will * add to this list. Memory so-allocated will be freed @@ -163,7 +164,7 @@ struct udevice { struct list_head child_head; struct list_head sibling_node; uint32_t flags; - int sqq; + int seq_; #ifdef CONFIG_DEVRES struct list_head devres_head; #endif @@ -190,7 +191,7 @@ static inline bool dev_has_of_node(struct udevice *dev) static inline int dev_seq(const struct udevice *dev) { - return dev->sqq; + return dev->seq_; } /** diff --git a/test/dm/core.c b/test/dm/core.c index cf66e27db4..b274b04388 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -1075,10 +1075,10 @@ static int dm_test_all_have_seq(struct unit_test_state *uts) list_for_each_entry(uc, &gd->uclass_root, sibling_node) { list_for_each_entry(dev, &uc->dev_head, uclass_node) { - if (dev->sqq == -1) + if (dev->seq_ == -1) printf("Device '%s' has no seq (%d)\n", - dev->name, dev->sqq); - ut_assert(dev->sqq != -1); + dev->name, dev->seq_); + ut_assert(dev->seq_ != -1); } } -- cgit v1.2.3 From 73466df3e214f6ff1966e69df351f273eec1a029 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:10 -0700 Subject: dm: core: Access device flags through functions At present flags are stored as part of the device. In preparation for storing them separately, change the access to go through inline functions. Signed-off-by: Simon Glass --- cmd/remoteproc.c | 2 +- drivers/clk/clk.c | 2 +- drivers/core/device-remove.c | 18 +++++++++--------- drivers/core/device.c | 32 ++++++++++++++++---------------- drivers/core/devres.c | 4 ++-- drivers/core/dump.c | 4 ++-- drivers/mtd/nand/raw/octeontx_nand.c | 2 +- drivers/remoteproc/rproc-uclass.c | 2 +- drivers/serial/serial-uclass.c | 2 +- include/dm/device.h | 15 +++++++++++++++ include/virtio.h | 2 +- test/dm/bus.c | 10 +++++----- test/dm/core.c | 14 +++++++------- test/dm/cpu.c | 2 +- test/dm/test-fdt.c | 20 ++++++++++---------- test/dm/virtio.c | 2 +- 16 files changed, 74 insertions(+), 59 deletions(-) diff --git a/cmd/remoteproc.c b/cmd/remoteproc.c index 5f9ba92560..b3ddcebe31 100644 --- a/cmd/remoteproc.c +++ b/cmd/remoteproc.c @@ -35,7 +35,7 @@ static int print_remoteproc_list(void) uc_pdata = dev_get_uclass_plat(dev); /* Do not print if rproc is not probed */ - if (!(dev->flags & DM_FLAG_ACTIVATED)) + if (!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)) continue; switch (uc_pdata->mem_type) { diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index eb75132f27..1efb7fe9f3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -67,7 +67,7 @@ const char *clk_hw_get_name(const struct clk *hw) bool clk_dev_binded(struct clk *clk) { - if (clk->dev && (clk->dev->flags & DM_FLAG_BOUND)) + if (clk->dev && (dev_get_flags(clk->dev) & DM_FLAG_BOUND)) return true; return false; diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index e15ab051be..44eaa67d56 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -69,10 +69,10 @@ int device_unbind(struct udevice *dev) if (!dev) return log_msg_ret("dev", -EINVAL); - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) return log_msg_ret("active", -EINVAL); - if (!(dev->flags & DM_FLAG_BOUND)) + if (!(dev_get_flags(dev) & DM_FLAG_BOUND)) return log_msg_ret("not-bound", -EINVAL); drv = dev->driver; @@ -88,15 +88,15 @@ int device_unbind(struct udevice *dev) if (ret) return log_msg_ret("child unbind", ret); - if (dev->flags & DM_FLAG_ALLOC_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) { free(dev_get_plat(dev)); dev_set_plat(dev, NULL); } - if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) { free(dev_get_uclass_plat(dev)); dev_set_uclass_plat(dev, NULL); } - if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev_get_parent_plat(dev)); dev_set_parent_plat(dev, NULL); } @@ -109,7 +109,7 @@ int device_unbind(struct udevice *dev) devres_release_all(dev); - if (dev->flags & DM_FLAG_NAME_ALLOCED) + if (dev_get_flags(dev) & DM_FLAG_NAME_ALLOCED) free((char *)dev->name); free(dev); @@ -144,7 +144,7 @@ void device_free(struct udevice *dev) dev_set_parent_priv(dev, NULL); } } - dev->flags &= ~DM_FLAG_PLATDATA_VALID; + dev_bic_flags(dev, DM_FLAG_PLATDATA_VALID); devres_release_probe(dev); } @@ -166,7 +166,7 @@ int device_remove(struct udevice *dev, uint flags) if (!dev) return -EINVAL; - if (!(dev->flags & DM_FLAG_ACTIVATED)) + if (!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)) return 0; drv = dev->driver; @@ -207,7 +207,7 @@ int device_remove(struct udevice *dev, uint flags) if (flags_remove(flags, drv->flags)) { device_free(dev); - dev->flags &= ~DM_FLAG_ACTIVATED; + dev_bic_flags(dev, DM_FLAG_ACTIVATED); } return ret; diff --git a/drivers/core/device.c b/drivers/core/device.c index f4ae7786ee..ba50d46eff 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -96,13 +96,13 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, if (CONFIG_IS_ENABLED(OF_PLATDATA)) { if (of_plat_size) { - dev->flags |= DM_FLAG_OF_PLATDATA; + dev_or_flags(dev, DM_FLAG_OF_PLATDATA); if (of_plat_size < drv->plat_auto) alloc = true; } } if (alloc) { - dev->flags |= DM_FLAG_ALLOC_PDATA; + dev_or_flags(dev, DM_FLAG_ALLOC_PDATA); ptr = calloc(1, drv->plat_auto); if (!ptr) { ret = -ENOMEM; @@ -116,7 +116,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, size = uc->uc_drv->per_device_plat_auto; if (size) { - dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA; + dev_or_flags(dev, DM_FLAG_ALLOC_UCLASS_PDATA); ptr = calloc(1, size); if (!ptr) { ret = -ENOMEM; @@ -131,7 +131,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, size = parent->uclass->uc_drv->per_child_plat_auto; } if (size) { - dev->flags |= DM_FLAG_ALLOC_PARENT_PDATA; + dev_or_flags(dev, DM_FLAG_ALLOC_PARENT_PDATA); ptr = calloc(1, size); if (!ptr) { ret = -ENOMEM; @@ -169,7 +169,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, if (devp) *devp = dev; - dev->flags |= DM_FLAG_BOUND; + dev_or_flags(dev, DM_FLAG_BOUND); return 0; @@ -193,18 +193,18 @@ fail_bind: fail_uclass_bind: if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) { list_del(&dev->sibling_node); - if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_PARENT_PDATA) { free(dev_get_parent_plat(dev)); dev_set_parent_plat(dev, NULL); } } fail_alloc3: - if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) { free(dev_get_uclass_plat(dev)); dev_set_uclass_plat(dev, NULL); } fail_alloc2: - if (dev->flags & DM_FLAG_ALLOC_PDATA) { + if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) { free(dev_get_plat(dev)); dev_set_plat(dev, NULL); } @@ -379,7 +379,7 @@ int device_of_to_plat(struct udevice *dev) if (!dev) return -EINVAL; - if (dev->flags & DM_FLAG_PLATDATA_VALID) + if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID) return 0; /* Ensure all parents have ofdata */ @@ -394,7 +394,7 @@ int device_of_to_plat(struct udevice *dev) * (e.g. PCI bridge devices). Test the flags again * so that we don't mess up the device. */ - if (dev->flags & DM_FLAG_PLATDATA_VALID) + if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID) return 0; } @@ -412,7 +412,7 @@ int device_of_to_plat(struct udevice *dev) goto fail; } - dev->flags |= DM_FLAG_PLATDATA_VALID; + dev_or_flags(dev, DM_FLAG_PLATDATA_VALID); return 0; fail: @@ -429,7 +429,7 @@ int device_probe(struct udevice *dev) if (!dev) return -EINVAL; - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) return 0; drv = dev->driver; @@ -451,11 +451,11 @@ int device_probe(struct udevice *dev) * (e.g. PCI bridge devices). Test the flags again * so that we don't mess up the device. */ - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) return 0; } - dev->flags |= DM_FLAG_ACTIVATED; + dev_or_flags(dev, DM_FLAG_ACTIVATED); /* * Process pinctrl for everything except the root device, and @@ -515,7 +515,7 @@ fail_uclass: __func__, dev->name); } fail: - dev->flags &= ~DM_FLAG_ACTIVATED; + dev_bic_flags(dev, DM_FLAG_ACTIVATED); device_free(dev); @@ -965,7 +965,7 @@ bool device_is_last_sibling(const struct udevice *dev) void device_set_name_alloced(struct udevice *dev) { - dev->flags |= DM_FLAG_NAME_ALLOCED; + dev_or_flags(dev, DM_FLAG_NAME_ALLOCED); } int device_set_name(struct udevice *dev, const char *name) diff --git a/drivers/core/devres.c b/drivers/core/devres.c index 522b07d613..313ddc7089 100644 --- a/drivers/core/devres.c +++ b/drivers/core/devres.c @@ -107,9 +107,9 @@ void devres_add(struct udevice *dev, void *res) devres_log(dev, dr, "ADD"); assert_noisy(list_empty(&dr->entry)); - if (dev->flags & DM_FLAG_PLATDATA_VALID) + if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID) dr->phase = DEVRES_PHASE_PROBE; - else if (dev->flags & DM_FLAG_BOUND) + else if (dev_get_flags(dev) & DM_FLAG_BOUND) dr->phase = DEVRES_PHASE_OFDATA; else dr->phase = DEVRES_PHASE_BIND; diff --git a/drivers/core/dump.c b/drivers/core/dump.c index 1d4628abc7..f8afea30a9 100644 --- a/drivers/core/dump.c +++ b/drivers/core/dump.c @@ -14,7 +14,7 @@ static void show_devices(struct udevice *dev, int depth, int last_flag) { int i, is_last; struct udevice *child; - u32 flags = dev->flags; + u32 flags = dev_get_flags(dev); /* print the first 20 characters to not break the tree-format. */ printf(IS_ENABLED(CONFIG_SPL_BUILD) ? " %s %d [ %c ] %s " : @@ -67,7 +67,7 @@ void dm_dump_all(void) static void dm_display_line(struct udevice *dev, int index) { printf("%-3i %c %s @ %08lx", index, - dev->flags & DM_FLAG_ACTIVATED ? '*' : ' ', + dev_get_flags(dev) & DM_FLAG_ACTIVATED ? '*' : ' ', dev->name, (ulong)map_to_sysmem(dev)); if (dev->seq_ != -1) printf(", seq %d", dev_seq(dev)); diff --git a/drivers/mtd/nand/raw/octeontx_nand.c b/drivers/mtd/nand/raw/octeontx_nand.c index b1ed4d910a..96a5fe6592 100644 --- a/drivers/mtd/nand/raw/octeontx_nand.c +++ b/drivers/mtd/nand/raw/octeontx_nand.c @@ -2187,7 +2187,7 @@ int octeontx_pci_nand_deferred_probe(void) debug("%s: Performing deferred probing\n", __func__); list_for_each_entry(pdev, &octeontx_pci_nand_deferred_devices, list) { debug("%s: Probing %s\n", __func__, pdev->dev->name); - pdev->dev->flags &= ~DM_FLAG_ACTIVATED; + dev_get_flags(pdev->dev) &= ~DM_FLAG_ACTIVATED; rc = device_probe(pdev->dev); if (rc && rc != -ENODEV) { printf("%s: Error %d with deferred probe of %s\n", diff --git a/drivers/remoteproc/rproc-uclass.c b/drivers/remoteproc/rproc-uclass.c index 773b8119f4..c2d6a4e0c1 100644 --- a/drivers/remoteproc/rproc-uclass.c +++ b/drivers/remoteproc/rproc-uclass.c @@ -247,7 +247,7 @@ static int _rproc_dev_is_probed(struct udevice *dev, struct dm_rproc_uclass_pdata *uc_pdata, const void *data) { - if (dev->flags & DM_FLAG_ACTIVATED) + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) return 0; return -EAGAIN; diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index b6457242de..58a6541d8c 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -123,7 +123,7 @@ static void serial_find_console_or_panic(void) #ifdef CONFIG_SERIAL_SEARCH_ALL if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) || !uclass_get_device(UCLASS_SERIAL, INDEX, &dev)) { - if (dev->flags & DM_FLAG_ACTIVATED) { + if (dev_get_flags(dev) & DM_FLAG_ACTIVATED) { gd->cur_serial_dev = dev; return; } diff --git a/include/dm/device.h b/include/dm/device.h index a063bbaa17..4ec423e961 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -179,6 +179,21 @@ struct udevice { /* Returns non-zero if the device is active (probed and not removed) */ #define device_active(dev) ((dev)->flags & DM_FLAG_ACTIVATED) +static inline u32 dev_get_flags(const struct udevice *dev) +{ + return dev->flags; +} + +static inline void dev_or_flags(struct udevice *dev, u32 or) +{ + dev->flags |= or; +} + +static inline void dev_bic_flags(struct udevice *dev, u32 bic) +{ + dev->flags &= ~bic; +} + static inline int dev_of_offset(const struct udevice *dev) { return ofnode_to_offset(dev->node); diff --git a/include/virtio.h b/include/virtio.h index 10a9c073ba..a42bdad6b8 100644 --- a/include/virtio.h +++ b/include/virtio.h @@ -492,7 +492,7 @@ static inline void __virtio_clear_bit(struct udevice *udev, unsigned int fbit) */ static inline bool virtio_has_feature(struct udevice *vdev, unsigned int fbit) { - if (!(vdev->flags & DM_FLAG_BOUND)) + if (!(dev_get_flags(vdev) & DM_FLAG_BOUND)) WARN_ON(true); return __virtio_test_bit(vdev->parent, fbit); diff --git a/test/dm/bus.c b/test/dm/bus.c index 785ccfc25d..e768eab695 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -55,16 +55,16 @@ static int dm_test_bus_children_funcs(struct unit_test_state *uts) ut_assertok(device_get_child(bus, 0, &dev)); ut_asserteq(-ENODEV, device_get_child(bus, 4, &dev)); ut_assertok(device_get_child_by_seq(bus, 5, &dev)); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); ut_asserteq_str("c-test@5", dev->name); /* Device with sequence number 0 should be accessible */ ut_asserteq(-ENODEV, device_find_child_by_seq(bus, -1, &dev)); ut_assertok(device_find_child_by_seq(bus, 0, &dev)); - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev)); ut_assertok(device_get_child_by_seq(bus, 0, &dev)); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); ut_asserteq(0, device_find_child_by_seq(bus, 0, &dev)); /* There is no device with sequence number 2 */ @@ -96,10 +96,10 @@ static int dm_test_bus_children_of_offset(struct unit_test_state *uts) ut_assert(node > 0); ut_assertok(device_find_child_by_of_offset(bus, node, &dev)); ut_assertnonnull(dev); - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); ut_assertok(device_get_child_by_of_offset(bus, node, &dev)); ut_assertnonnull(dev); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); return 0; } diff --git a/test/dm/core.c b/test/dm/core.c index b274b04388..565896ed50 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -131,7 +131,7 @@ static int dm_test_autobind(struct unit_test_state *uts) /* No devices should be probed */ list_for_each_entry(dev, &gd->dm_root->child_head, sibling_node) - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); /* Our test driver should have been bound 3 times */ ut_assert(dm_testdrv_op_count[DM_TEST_OP_BIND] == 3); @@ -212,7 +212,7 @@ static int dm_test_autoprobe(struct unit_test_state *uts) ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_PROBE]); /* The root device should not be activated until needed */ - ut_assert(dms->root->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED); /* * We should be able to find the three test devices, and they should @@ -222,17 +222,17 @@ static int dm_test_autoprobe(struct unit_test_state *uts) for (i = 0; i < 3; i++) { ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); ut_assert(dev); - ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED), + ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED), "Driver %d/%s already activated", i, dev->name); /* This should activate it */ ut_assertok(uclass_get_device(UCLASS_TEST, i, &dev)); ut_assert(dev); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); /* Activating a device should activate the root device */ if (!i) - ut_assert(dms->root->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dms->root) & DM_FLAG_ACTIVATED); } /* @@ -460,10 +460,10 @@ static int dm_test_remove(struct unit_test_state *uts) for (i = 0; i < 3; i++) { ut_assertok(uclass_find_device(UCLASS_TEST, i, &dev)); ut_assert(dev); - ut_assertf(dev->flags & DM_FLAG_ACTIVATED, + ut_assertf(dev_get_flags(dev) & DM_FLAG_ACTIVATED, "Driver %d/%s not activated", i, dev->name); ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); - ut_assertf(!(dev->flags & DM_FLAG_ACTIVATED), + ut_assertf(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED), "Driver %d/%s should have deactivated", i, dev->name); ut_assert(!dev_get_priv(dev)); diff --git a/test/dm/cpu.c b/test/dm/cpu.c index 28869c1d6f..ed12cafee2 100644 --- a/test/dm/cpu.c +++ b/test/dm/cpu.c @@ -25,7 +25,7 @@ static int dm_test_cpu(struct unit_test_state *uts) for (uclass_find_first_device(UCLASS_CPU, &dev); dev; uclass_find_next_device(&dev)) - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); ut_assertok(uclass_get_device_by_name(UCLASS_CPU, "cpu-test1", &dev)); ut_asserteq_ptr(cpu_get_current_dev(), dev); diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 633256821c..711bf20a9c 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -1031,8 +1031,8 @@ static int dm_test_child_ofdata(struct unit_test_state *uts) ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); count = 0; device_foreach_child_of_to_plat(dev, bus) { - ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); + ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); count++; } ut_asserteq(3, count); @@ -1050,8 +1050,8 @@ static int dm_test_first_child_probe(struct unit_test_state *uts) ut_assertok(uclass_first_device_err(UCLASS_TEST_BUS, &bus)); count = 0; device_foreach_child_probe(dev, bus) { - ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); - ut_assert(dev->flags & DM_FLAG_ACTIVATED); + ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID); + ut_assert(dev_get_flags(dev) & DM_FLAG_ACTIVATED); count++; } ut_asserteq(3, count); @@ -1067,19 +1067,19 @@ static int dm_test_ofdata_order(struct unit_test_state *uts) ut_assertok(uclass_find_first_device(UCLASS_I2C, &bus)); ut_assertnonnull(bus); - ut_assert(!(bus->flags & DM_FLAG_PLATDATA_VALID)); + ut_assert(!(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID)); ut_assertok(device_find_first_child(bus, &dev)); ut_assertnonnull(dev); - ut_assert(!(dev->flags & DM_FLAG_PLATDATA_VALID)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)); /* read the child's ofdata which should cause the parent's to be read */ ut_assertok(device_of_to_plat(dev)); - ut_assert(dev->flags & DM_FLAG_PLATDATA_VALID); - ut_assert(bus->flags & DM_FLAG_PLATDATA_VALID); + ut_assert(dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID); + ut_assert(dev_get_flags(bus) & DM_FLAG_PLATDATA_VALID); - ut_assert(!(dev->flags & DM_FLAG_ACTIVATED)); - ut_assert(!(bus->flags & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(dev) & DM_FLAG_ACTIVATED)); + ut_assert(!(dev_get_flags(bus) & DM_FLAG_ACTIVATED)); return 0; } diff --git a/test/dm/virtio.c b/test/dm/virtio.c index 2e876c36e4..ad355981cf 100644 --- a/test/dm/virtio.c +++ b/test/dm/virtio.c @@ -122,7 +122,7 @@ static int dm_test_virtio_remove(struct unit_test_state *uts) ut_assertok(virtio_set_status(dev, VIRTIO_CONFIG_S_DRIVER_OK)); /* check the device can be successfully removed */ - dev->flags |= DM_FLAG_ACTIVATED; + dev_or_flags(dev, DM_FLAG_ACTIVATED); ut_assertok(device_remove(bus, DM_REMOVE_ACTIVE_ALL)); return 0; -- cgit v1.2.3 From 156004f863c06ed985ed089450977827e11cb451 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:11 -0700 Subject: dm: core: Rename device flags to indicate it is private To avoid having people accidentally access this member, add a trailing underscore. Signed-off-by: Simon Glass --- include/dm/device.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/include/dm/device.h b/include/dm/device.h index 4ec423e961..a0c1752cdd 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -135,7 +135,8 @@ enum { * @uclass_node: Used by uclass to link its devices * @child_head: List of children of this device * @sibling_node: Next device in list of all devices - * @flags: Flags for this device DM_FLAG_... + * @flags_: Flags for this device DM_FLAG_... (do not access outside driver + * model) * @seq_: Allocated sequence number for this device (-1 = none). This is set up * when the device is bound and is unique within the device's uclass. If the * device has an alias in the devicetree then that is used to set the sequence @@ -163,7 +164,7 @@ struct udevice { struct list_head uclass_node; struct list_head child_head; struct list_head sibling_node; - uint32_t flags; + u32 flags_; int seq_; #ifdef CONFIG_DEVRES struct list_head devres_head; @@ -176,24 +177,24 @@ struct udevice { /* Returns the operations for a device */ #define device_get_ops(dev) (dev->driver->ops) -/* Returns non-zero if the device is active (probed and not removed) */ -#define device_active(dev) ((dev)->flags & DM_FLAG_ACTIVATED) - static inline u32 dev_get_flags(const struct udevice *dev) { - return dev->flags; + return dev->flags_; } static inline void dev_or_flags(struct udevice *dev, u32 or) { - dev->flags |= or; + dev->flags_ |= or; } static inline void dev_bic_flags(struct udevice *dev, u32 bic) { - dev->flags &= ~bic; + dev->flags_ &= ~bic; } +/* Returns non-zero if the device is active (probed and not removed) */ +#define device_active(dev) (dev_get_flags(dev) & DM_FLAG_ACTIVATED) + static inline int dev_of_offset(const struct udevice *dev) { return ofnode_to_offset(dev->node); -- cgit v1.2.3 From c23405f8176c8d32d36ad992eb203ec87c4f5507 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:12 -0700 Subject: dm: core: Rename dev_has_of_node() to dev_has_ofnode() We use 'ofnode' rather than 'of_node' in U-Boot. Rename this function to fit. Signed-off-by: Simon Glass --- drivers/core/device.c | 2 +- drivers/mmc/octeontx_hsmmc.c | 2 +- drivers/pinctrl/pinctrl-uclass.c | 2 +- drivers/usb/host/usb-uclass.c | 2 +- include/dm/device.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index ba50d46eff..8c7ce220f8 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -406,7 +406,7 @@ int device_of_to_plat(struct udevice *dev) assert(drv); if (drv->of_to_plat && - (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_of_node(dev))) { + (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_ofnode(dev))) { ret = drv->of_to_plat(dev); if (ret) goto fail; diff --git a/drivers/mmc/octeontx_hsmmc.c b/drivers/mmc/octeontx_hsmmc.c index 57d107aac3..f3da6af909 100644 --- a/drivers/mmc/octeontx_hsmmc.c +++ b/drivers/mmc/octeontx_hsmmc.c @@ -3752,7 +3752,7 @@ static int octeontx_mmc_host_probe(struct udevice *dev) host->dev = dev; debug("%s(%s): Base address: %p\n", __func__, dev->name, host->base_addr); - if (!dev_has_of_node(dev)) { + if (!dev_has_ofnode(dev)) { pr_err("%s: No device tree information found\n", __func__); return -1; } diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index 4e474cbff7..4653e86ba4 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -305,7 +305,7 @@ int pinctrl_select_state(struct udevice *dev, const char *statename) * Some device which is logical like mmc.blk, do not have * a valid ofnode. */ - if (!dev_has_of_node(dev)) + if (!dev_has_ofnode(dev)) return 0; /* * Try full-implemented pinctrl first. diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index 17db5eb060..ae6b1450d3 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -517,7 +517,7 @@ static ofnode usb_get_ofnode(struct udevice *hub, int port) ofnode node; u32 reg; - if (!dev_has_of_node(hub)) + if (!dev_has_ofnode(hub)) return ofnode_null(); /* diff --git a/include/dm/device.h b/include/dm/device.h index a0c1752cdd..b15a14ec33 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -200,7 +200,7 @@ static inline int dev_of_offset(const struct udevice *dev) return ofnode_to_offset(dev->node); } -static inline bool dev_has_of_node(struct udevice *dev) +static inline bool dev_has_ofnode(struct udevice *dev) { return ofnode_valid(dev->node); } -- cgit v1.2.3 From 7d14ee443ca674314e0fe5c3e25f48e52a8fd5ee Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:13 -0700 Subject: dm: core: Use dev_has_ofnode() instead of dev_of_valid() We have two functions which do the same thing. Standardise on dev_has_ofnode() since there is no such thing as an 'invalid' ofnode in normal operation: it is either null or missing. Also move the functions into one place. Signed-off-by: Simon Glass Reviewed-by: Andy Shevchenko --- drivers/clk/clk-uclass.c | 2 +- drivers/core/device.c | 2 +- drivers/gpio/sandbox.c | 2 +- drivers/i2c/designware_i2c_pci.c | 4 ++-- drivers/i2c/i2c-uclass.c | 2 +- drivers/mmc/pci_mmc.c | 2 +- drivers/pci/pci-uclass.c | 6 +++--- drivers/pinctrl/pinctrl-uclass.c | 2 +- drivers/spi/spi-uclass.c | 2 +- drivers/sysreset/sysreset_sandbox.c | 2 +- drivers/timer/timer-uclass.c | 2 +- drivers/usb/host/usb-uclass.c | 2 +- include/dm/device.h | 13 ++++++++++++- include/dm/read.h | 16 ---------------- test/dm/pci.c | 6 +++--- 15 files changed, 30 insertions(+), 35 deletions(-) diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c index ac954a34d2..5cfd00ce77 100644 --- a/drivers/clk/clk-uclass.c +++ b/drivers/clk/clk-uclass.c @@ -345,7 +345,7 @@ int clk_set_defaults(struct udevice *dev, int stage) { int ret; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; /* If this not in SPL and pre-reloc state, don't take any action. */ diff --git a/drivers/core/device.c b/drivers/core/device.c index 8c7ce220f8..bd4ecc9e24 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -485,7 +485,7 @@ int device_probe(struct udevice *dev) } /* Only handle devices that have a valid ofnode */ - if (dev_of_valid(dev)) { + if (dev_has_ofnode(dev)) { /* * Process 'assigned-{clocks/clock-parents/clock-rates}' * properties diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index 489271b560..f8fa4baa2c 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -294,7 +294,7 @@ static int gpio_sandbox_probe(struct udevice *dev) { struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) /* Tell the uclass how many GPIOs we have */ uc_priv->gpio_count = CONFIG_SANDBOX_GPIO_COUNT; diff --git a/drivers/i2c/designware_i2c_pci.c b/drivers/i2c/designware_i2c_pci.c index 18eef625f0..ec0cdf6220 100644 --- a/drivers/i2c/designware_i2c_pci.c +++ b/drivers/i2c/designware_i2c_pci.c @@ -92,7 +92,7 @@ static int designware_i2c_pci_bind(struct udevice *dev) { char name[20]; - if (dev_of_valid(dev)) + if (dev_has_ofnode(dev)) return 0; sprintf(name, "i2c_designware#%u", dev_seq(dev)); @@ -152,7 +152,7 @@ static int dw_i2c_acpi_fill_ssdt(const struct udevice *dev, int ret; /* If no device-tree node, ignore this since we assume it isn't used */ - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; ret = acpi_device_path(dev, path, sizeof(path)); diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c index 456cf3b85f..be56785217 100644 --- a/drivers/i2c/i2c-uclass.c +++ b/drivers/i2c/i2c-uclass.c @@ -678,7 +678,7 @@ static int i2c_child_post_bind(struct udevice *dev) #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) struct dm_i2c_chip *plat = dev_get_parent_plat(dev); - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; return i2c_chip_of_to_plat(dev, plat); #else diff --git a/drivers/mmc/pci_mmc.c b/drivers/mmc/pci_mmc.c index fc09ad99e5..c71c495d58 100644 --- a/drivers/mmc/pci_mmc.c +++ b/drivers/mmc/pci_mmc.c @@ -75,7 +75,7 @@ static int pci_mmc_acpi_fill_ssdt(const struct udevice *dev, struct acpi_dp *dp; int ret; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; ret = gpio_get_acpi(&priv->cd_gpio, &gpio); diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index 1f6c51f1e8..4cdd06b125 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -540,7 +540,7 @@ int pci_auto_config_devices(struct udevice *bus) int ret; debug("%s: device %s\n", __func__, dev->name); - if (dev_of_valid(dev) && + if (dev_has_ofnode(dev) && dev_read_bool(dev, "pci,no-autoconfig")) continue; ret = dm_pciauto_config_device(dev); @@ -1036,7 +1036,7 @@ static int pci_uclass_pre_probe(struct udevice *bus) hose->bus = bus; hose->first_busno = dev_seq(bus); hose->last_busno = dev_seq(bus); - if (dev_of_valid(bus)) { + if (dev_has_ofnode(bus)) { hose->skip_auto_config_until_reloc = dev_read_bool(bus, "u-boot,skip-auto-config-until-reloc"); @@ -1091,7 +1091,7 @@ static int pci_uclass_child_post_bind(struct udevice *dev) { struct pci_child_plat *pplat; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; pplat = dev_get_parent_plat(dev); diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index 4653e86ba4..7919e54e8d 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -112,7 +112,7 @@ static int pinconfig_post_bind(struct udevice *dev) ofnode node; int ret; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; dev_for_each_subnode(node, dev) { diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c index a392a93aa1..ba325cf4e0 100644 --- a/drivers/spi/spi-uclass.c +++ b/drivers/spi/spi-uclass.c @@ -160,7 +160,7 @@ static int spi_child_post_bind(struct udevice *dev) { struct dm_spi_slave_plat *plat = dev_get_parent_plat(dev); - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; return spi_slave_of_to_plat(dev, plat); diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c index 7026a48c4b..8eca7d8bfd 100644 --- a/drivers/sysreset/sysreset_sandbox.c +++ b/drivers/sysreset/sysreset_sandbox.c @@ -50,7 +50,7 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) * (see the U_BOOT_DEVICE() declaration below) should not do anything. * If we are that device, return an error. */ - if (state->fdt_fname && !dev_of_valid(dev)) + if (state->fdt_fname && !dev_has_ofnode(dev)) return -ENODEV; switch (type) { diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c index 8e63c17e9f..da1a72f025 100644 --- a/drivers/timer/timer-uclass.c +++ b/drivers/timer/timer-uclass.c @@ -54,7 +54,7 @@ static int timer_pre_probe(struct udevice *dev) ulong ret; /* It is possible that a timer device has a null ofnode */ - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; err = clk_get_by_index(dev, 0, &timer_clk); diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index ae6b1450d3..e3b616c326 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -773,7 +773,7 @@ static int usb_child_post_bind(struct udevice *dev) struct usb_dev_plat *plat = dev_get_parent_plat(dev); int val; - if (!dev_of_valid(dev)) + if (!dev_has_ofnode(dev)) return 0; /* We only support matching a few things */ diff --git a/include/dm/device.h b/include/dm/device.h index b15a14ec33..4a1224bcc2 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -192,6 +192,17 @@ static inline void dev_bic_flags(struct udevice *dev, u32 bic) dev->flags_ &= ~bic; } +/** + * dev_ofnode() - get the DT node reference associated with a udevice + * + * @dev: device to check + * @return reference of the the device's DT node + */ +static inline ofnode dev_ofnode(const struct udevice *dev) +{ + return dev->node; +} + /* Returns non-zero if the device is active (probed and not removed) */ #define device_active(dev) (dev_get_flags(dev) & DM_FLAG_ACTIVATED) @@ -200,7 +211,7 @@ static inline int dev_of_offset(const struct udevice *dev) return ofnode_to_offset(dev->node); } -static inline bool dev_has_ofnode(struct udevice *dev) +static inline bool dev_has_ofnode(const struct udevice *dev) { return ofnode_valid(dev->node); } diff --git a/include/dm/read.h b/include/dm/read.h index 0585eb1228..d5cdd87911 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -30,22 +30,6 @@ static inline const struct device_node *dev_np(const struct udevice *dev) } #endif -/** - * dev_ofnode() - get the DT node reference associated with a udevice - * - * @dev: device to check - * @return reference of the the device's DT node - */ -static inline ofnode dev_ofnode(const struct udevice *dev) -{ - return dev->node; -} - -static inline bool dev_of_valid(const struct udevice *dev) -{ - return ofnode_valid(dev_ofnode(dev)); -} - #ifndef CONFIG_DM_DEV_READ_INLINE /** diff --git a/test/dm/pci.c b/test/dm/pci.c index 76490befdf..fa2e4a8559 100644 --- a/test/dm/pci.c +++ b/test/dm/pci.c @@ -120,13 +120,13 @@ static int dm_test_pci_drvdata(struct unit_test_state *uts) ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap)); ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data); - ut_assertok(dev_of_valid(swap)); + ut_assertok(dev_has_ofnode(swap)); ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x0c, 0), &swap)); ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data); - ut_assertok(dev_of_valid(swap)); + ut_assertok(dev_has_ofnode(swap)); ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x10, 0), &swap)); ut_asserteq(SWAP_CASE_DRV_DATA, swap->driver_data); - ut_assertok(!dev_of_valid(swap)); + ut_assertok(!dev_has_ofnode(swap)); return 0; } -- cgit v1.2.3 From f10643cf8a4ca006d1ad194e930cd292fd869d17 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:14 -0700 Subject: dm: core: Access device ofnode through functions At present ofnode is present in the device even if it is never used. With of-platdata this field is not used, so can be removed. In preparation for this, change the access to go through inline functions. Signed-off-by: Simon Glass --- arch/arm/mach-stm32mp/pwr_regulator.c | 2 +- board/synopsys/hsdk/clk-lib.c | 2 +- drivers/ata/mtk_ahci.c | 3 ++- drivers/clk/meson/axg.c | 2 +- drivers/clk/meson/g12a.c | 2 +- drivers/clk/meson/gxbb.c | 2 +- drivers/core/device.c | 2 +- drivers/core/root.c | 2 +- drivers/gpio/mpc8xxx_gpio.c | 4 ++-- drivers/gpio/octeon_gpio.c | 2 +- drivers/misc/swap_case.c | 2 +- drivers/mmc/octeontx_hsmmc.c | 23 +++++++++++++---------- drivers/mtd/nand/raw/octeontx_nand.c | 2 +- drivers/mtd/nand/spi/core.c | 2 +- drivers/net/fm/eth.c | 4 ++-- drivers/net/fsl_enetc.c | 8 ++++---- drivers/net/fsl_enetc_mdio.c | 2 +- drivers/net/mdio-ipq4019.c | 4 ++-- drivers/net/mdio_mux_i2creg.c | 2 +- drivers/net/mvmdio.c | 4 ++-- drivers/net/octeontx/smi.c | 2 +- drivers/net/tsec.c | 3 ++- drivers/phy/phy-ti-am654.c | 2 +- drivers/power/domain/meson-ee-pwrc.c | 4 ++-- drivers/power/domain/meson-gx-pwrc-vpu.c | 4 ++-- drivers/power/regulator/pbias_regulator.c | 3 ++- drivers/pwm/pwm-meson.c | 9 ++++++--- drivers/reset/reset-socfpga.c | 2 +- drivers/spi/fsl_dspi.c | 6 ++++-- drivers/tee/optee/core.c | 2 +- drivers/usb/cdns3/core.c | 4 ++-- drivers/usb/dwc3/core.c | 2 +- drivers/usb/dwc3/dwc3-generic.c | 6 +++--- drivers/usb/dwc3/dwc3-meson-g12a.c | 2 +- drivers/usb/dwc3/dwc3-meson-gxl.c | 2 +- drivers/usb/gadget/dwc2_udc_otg.c | 4 ++-- drivers/usb/host/dwc3-octeon-glue.c | 2 +- drivers/usb/host/dwc3-sti-glue.c | 5 +++-- drivers/usb/host/ehci-mx6.c | 2 +- drivers/usb/host/xhci-dwc3.c | 2 +- drivers/usb/mtu3/mtu3_core.c | 2 +- drivers/usb/mtu3/mtu3_plat.c | 4 ++-- drivers/usb/musb-new/ti-musb.c | 2 +- drivers/video/nexell_display.c | 2 +- drivers/video/rockchip/rk_mipi.c | 2 +- include/dm/device.h | 23 +++++++++++++++++++++-- include/dm/read.h | 2 +- include/linux/mtd/mtd.h | 4 ++-- net/mdio-mux-uclass.c | 2 +- net/mdio-uclass.c | 8 ++++---- 50 files changed, 113 insertions(+), 82 deletions(-) diff --git a/arch/arm/mach-stm32mp/pwr_regulator.c b/arch/arm/mach-stm32mp/pwr_regulator.c index af6ea43964..766ed95f1a 100644 --- a/arch/arm/mach-stm32mp/pwr_regulator.c +++ b/arch/arm/mach-stm32mp/pwr_regulator.c @@ -81,7 +81,7 @@ static int stm32mp_pwr_bind(struct udevice *dev) { int children; - children = pmic_bind_children(dev, dev->node, pwr_children_info); + children = pmic_bind_children(dev, dev_ofnode(dev), pwr_children_info); if (!children) dev_dbg(dev, "no child found\n"); diff --git a/board/synopsys/hsdk/clk-lib.c b/board/synopsys/hsdk/clk-lib.c index 1c74bfb93a..bd43179fc7 100644 --- a/board/synopsys/hsdk/clk-lib.c +++ b/board/synopsys/hsdk/clk-lib.c @@ -23,8 +23,8 @@ int soc_clk_ctl(const char *name, ulong *rate, enum clk_ctl_ops ctl) /* Dummy fmeas device, just to be able to use standard clk_* api */ struct udevice fmeas = { .name = "clk-fmeas", - .node = ofnode_path("/clk-fmeas"), }; + dev_set_ofnode(&fmeas, ofnode_path("/clk-fmeas")); ret = clk_get_by_name(&fmeas, name, &clk); if (ret) { diff --git a/drivers/ata/mtk_ahci.c b/drivers/ata/mtk_ahci.c index cd28e0cae3..46b7677783 100644 --- a/drivers/ata/mtk_ahci.c +++ b/drivers/ata/mtk_ahci.c @@ -68,7 +68,8 @@ static int mtk_ahci_parse_property(struct ahci_uc_priv *hpriv, SYS_CFG_SATA_MSK, SYS_CFG_SATA_EN); } - ofnode_read_u32(dev->node, "ports-implemented", &hpriv->port_map); + ofnode_read_u32(dev_ofnode(dev), "ports-implemented", + &hpriv->port_map); return 0; } diff --git a/drivers/clk/meson/axg.c b/drivers/clk/meson/axg.c index 82068578ff..d6da59d269 100644 --- a/drivers/clk/meson/axg.c +++ b/drivers/clk/meson/axg.c @@ -289,7 +289,7 @@ static int meson_clk_probe(struct udevice *dev) { struct meson_clk *priv = dev_get_priv(dev); - priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->map)) return PTR_ERR(priv->map); diff --git a/drivers/clk/meson/g12a.c b/drivers/clk/meson/g12a.c index 01b22abc34..5058db1a47 100644 --- a/drivers/clk/meson/g12a.c +++ b/drivers/clk/meson/g12a.c @@ -979,7 +979,7 @@ static int meson_clk_probe(struct udevice *dev) { struct meson_clk *priv = dev_get_priv(dev); - priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->map)) return PTR_ERR(priv->map); diff --git a/drivers/clk/meson/gxbb.c b/drivers/clk/meson/gxbb.c index 2a20541dcb..e379540dee 100644 --- a/drivers/clk/meson/gxbb.c +++ b/drivers/clk/meson/gxbb.c @@ -885,7 +885,7 @@ static int meson_clk_probe(struct udevice *dev) { struct meson_clk *priv = dev_get_priv(dev); - priv->map = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->map)) return PTR_ERR(priv->map); diff --git a/drivers/core/device.c b/drivers/core/device.c index bd4ecc9e24..6a9bee093d 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -68,7 +68,7 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv, dev_set_plat(dev, plat); dev->driver_data = driver_data; dev->name = name; - dev->node = node; + dev_set_ofnode(dev, node); dev->parent = parent; dev->driver = drv; dev->uclass = uc; diff --git a/drivers/core/root.c b/drivers/core/root.c index 9ef242979b..fe7359433f 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -148,7 +148,7 @@ int dm_init(bool of_live) if (ret) return ret; if (CONFIG_IS_ENABLED(OF_CONTROL)) - DM_ROOT_NON_CONST->node = ofnode_root(); + dev_set_ofnode(DM_ROOT_NON_CONST, ofnode_root()); ret = device_probe(DM_ROOT_NON_CONST); if (ret) return ret; diff --git a/drivers/gpio/mpc8xxx_gpio.c b/drivers/gpio/mpc8xxx_gpio.c index 2bc1a0d571..a964347fa3 100644 --- a/drivers/gpio/mpc8xxx_gpio.c +++ b/drivers/gpio/mpc8xxx_gpio.c @@ -191,7 +191,7 @@ static int mpc8xxx_gpio_of_to_plat(struct udevice *dev) u32 i; u32 reg[4]; - if (ofnode_read_bool(dev->node, "little-endian")) + if (ofnode_read_bool(dev_ofnode(dev), "little-endian")) data->little_endian = true; if (data->little_endian) @@ -257,7 +257,7 @@ static int mpc8xxx_gpio_probe(struct udevice *dev) if (!str) return -ENOMEM; - if (ofnode_device_is_compatible(dev->node, "fsl,qoriq-gpio")) { + if (ofnode_device_is_compatible(dev_ofnode(dev), "fsl,qoriq-gpio")) { unsigned long gpibe = data->addr + sizeof(struct ccsr_gpio) - sizeof(u32); diff --git a/drivers/gpio/octeon_gpio.c b/drivers/gpio/octeon_gpio.c index 958516d8f8..42eae79d8c 100644 --- a/drivers/gpio/octeon_gpio.c +++ b/drivers/gpio/octeon_gpio.c @@ -190,7 +190,7 @@ static int octeon_gpio_probe(struct udevice *dev) GPIO_CONST_GPIOS_MASK; } else { priv->base = dev_remap_addr(dev); - uc_priv->gpio_count = ofnode_read_u32_default(dev->node, + uc_priv->gpio_count = ofnode_read_u32_default(dev_ofnode(dev), "nr-gpios", 32); } diff --git a/drivers/misc/swap_case.c b/drivers/misc/swap_case.c index abea0e7613..3cbc8f37ec 100644 --- a/drivers/misc/swap_case.c +++ b/drivers/misc/swap_case.c @@ -54,7 +54,7 @@ struct swap_case_priv { static int sandbox_swap_case_use_ea(const struct udevice *dev) { - return !!ofnode_get_property(dev->node, "use-ea", NULL); + return !!ofnode_get_property(dev_ofnode(dev), "use-ea", NULL); } /* Please keep these macros in sync with ea_regs below */ diff --git a/drivers/mmc/octeontx_hsmmc.c b/drivers/mmc/octeontx_hsmmc.c index f3da6af909..442ca493d7 100644 --- a/drivers/mmc/octeontx_hsmmc.c +++ b/drivers/mmc/octeontx_hsmmc.c @@ -3439,7 +3439,7 @@ static u32 xlate_voltage(u32 voltage) */ static bool octeontx_mmc_get_valid(struct udevice *dev) { - const char *stat = ofnode_read_string(dev->node, "status"); + const char *stat = ofnode_read_string(dev_ofnode(dev), "status"); if (!stat || !strncmp(stat, "ok", 2)) return true; @@ -3461,14 +3461,15 @@ static int octeontx_mmc_get_config(struct udevice *dev) uint low, high; char env_name[32]; int err; - ofnode node = dev->node; + ofnode node = dev_ofnode(dev); int bus_width = 1; ulong new_max_freq; debug("%s(%s)", __func__, dev->name); slot->cfg.name = dev->name; - slot->cfg.f_max = ofnode_read_s32_default(dev->node, "max-frequency", + slot->cfg.f_max = ofnode_read_s32_default(dev_ofnode(dev), + "max-frequency", 26000000); snprintf(env_name, sizeof(env_name), "mmc_max_frequency%d", slot->bus_id); @@ -3486,25 +3487,26 @@ static int octeontx_mmc_get_config(struct udevice *dev) if (IS_ENABLED(CONFIG_ARCH_OCTEONTX2)) { slot->hs400_tuning_block = - ofnode_read_s32_default(dev->node, + ofnode_read_s32_default(dev_ofnode(dev), "marvell,hs400-tuning-block", -1); debug("%s(%s): mmc HS400 tuning block: %d\n", __func__, dev->name, slot->hs400_tuning_block); slot->hs200_tap_adj = - ofnode_read_s32_default(dev->node, + ofnode_read_s32_default(dev_ofnode(dev), "marvell,hs200-tap-adjust", 0); debug("%s(%s): hs200-tap-adjust: %d\n", __func__, dev->name, slot->hs200_tap_adj); slot->hs400_tap_adj = - ofnode_read_s32_default(dev->node, + ofnode_read_s32_default(dev_ofnode(dev), "marvell,hs400-tap-adjust", 0); debug("%s(%s): hs400-tap-adjust: %d\n", __func__, dev->name, slot->hs400_tap_adj); } - err = ofnode_read_u32_array(dev->node, "voltage-ranges", voltages, 2); + err = ofnode_read_u32_array(dev_ofnode(dev), "voltage-ranges", + voltages, 2); if (err) { slot->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34; } else { @@ -3756,14 +3758,15 @@ static int octeontx_mmc_host_probe(struct udevice *dev) pr_err("%s: No device tree information found\n", __func__); return -1; } - host->node = dev->node; + host->node = dev_ofnode(dev); host->last_slotid = -1; if (otx_is_platform(PLATFORM_ASIM)) host->is_asim = true; if (otx_is_platform(PLATFORM_EMULATOR)) host->is_emul = true; host->dma_wait_delay = - ofnode_read_u32_default(dev->node, "marvell,dma-wait-delay", 1); + ofnode_read_u32_default(dev_ofnode(dev), + "marvell,dma-wait-delay", 1); /* Force reset of eMMC */ writeq(0, host->base_addr + MIO_EMM_CFG()); debug("%s: Clearing MIO_EMM_CFG\n", __func__); @@ -3824,7 +3827,7 @@ static int octeontx_mmc_host_child_pre_probe(struct udevice *dev) struct octeontx_mmc_host *host = dev_get_priv(dev_get_parent(dev)); struct octeontx_mmc_slot *slot; struct mmc_uclass_priv *upriv; - ofnode node = dev->node; + ofnode node = dev_ofnode(dev); u32 bus_id; char name[16]; int err; diff --git a/drivers/mtd/nand/raw/octeontx_nand.c b/drivers/mtd/nand/raw/octeontx_nand.c index 96a5fe6592..64433cf6cc 100644 --- a/drivers/mtd/nand/raw/octeontx_nand.c +++ b/drivers/mtd/nand/raw/octeontx_nand.c @@ -1999,7 +1999,7 @@ static int octeontx_nfc_chip_init(struct octeontx_nfc *tn, struct udevice *dev, static int octeontx_nfc_chips_init(struct octeontx_nfc *tn) { struct udevice *dev = tn->dev; - ofnode node = dev->node; + ofnode node = dev_ofnode(dev); ofnode nand_node; int nr_chips = of_get_child_count(node); int ret; diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index ab9a24ed5b..cd12376ab8 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1173,7 +1173,7 @@ static int spinand_probe(struct udevice *dev) return -ENOMEM; sprintf(mtd->name, "spi-nand%d", spi_nand_idx++); spinand->slave = slave; - spinand_set_ofnode(spinand, dev->node); + spinand_set_ofnode(spinand, dev_ofnode(dev)); #endif ret = spinand_init(spinand); diff --git a/drivers/net/fm/eth.c b/drivers/net/fm/eth.c index a10f87eefc..0e89e663f7 100644 --- a/drivers/net/fm/eth.c +++ b/drivers/net/fm/eth.c @@ -957,7 +957,7 @@ phy_interface_t fman_read_sys_if(struct udevice *dev) { const char *if_str; - if_str = ofnode_read_string(dev->node, "phy-connection-type"); + if_str = ofnode_read_string(dev_ofnode(dev), "phy-connection-type"); debug("MAC system interface mode %s\n", if_str); return phy_get_interface_by_name(if_str); @@ -969,7 +969,7 @@ static int fm_eth_bind(struct udevice *dev) char mac_name[11]; u32 fm, num; - if (ofnode_read_u32(ofnode_get_parent(dev->node), "cell-index", &fm)) { + if (ofnode_read_u32(ofnode_get_parent(dev_ofnode(dev)), "cell-index", &fm)) { printf("FMan node property cell-index missing\n"); return -EINVAL; } diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c index 2e684e5839..f6fc7801b9 100644 --- a/drivers/net/fsl_enetc.c +++ b/drivers/net/fsl_enetc.c @@ -99,7 +99,7 @@ static int enetc_bind(struct udevice *dev) * and some are not, use different naming scheme - enetc-N based on * PCI function # and enetc#N based on interface count */ - if (ofnode_valid(dev->node)) + if (ofnode_valid(dev_ofnode(dev))) sprintf(name, "enetc-%u", PCI_FUNC(pci_get_devfn(dev))); else sprintf(name, "enetc#%u", eth_num_devices++); @@ -253,12 +253,12 @@ static void enetc_start_pcs(struct udevice *dev) mdio_register(&priv->imdio); } - if (!ofnode_valid(dev->node)) { + if (!ofnode_valid(dev_ofnode(dev))) { enetc_dbg(dev, "no enetc ofnode found, skipping PCS set-up\n"); return; } - if_str = ofnode_read_string(dev->node, "phy-mode"); + if_str = ofnode_read_string(dev_ofnode(dev), "phy-mode"); if (if_str) priv->if_type = phy_get_interface_by_name(if_str); else @@ -306,7 +306,7 @@ static int enetc_probe(struct udevice *dev) { struct enetc_priv *priv = dev_get_priv(dev); - if (ofnode_valid(dev->node) && !ofnode_is_available(dev->node)) { + if (ofnode_valid(dev_ofnode(dev)) && !ofnode_is_available(dev_ofnode(dev))) { enetc_dbg(dev, "interface disabled\n"); return -ENODEV; } diff --git a/drivers/net/fsl_enetc_mdio.c b/drivers/net/fsl_enetc_mdio.c index 4da97b61d1..3eb6ac9fc8 100644 --- a/drivers/net/fsl_enetc_mdio.c +++ b/drivers/net/fsl_enetc_mdio.c @@ -112,7 +112,7 @@ static int enetc_mdio_bind(struct udevice *dev) * and some are not, use different naming scheme - enetc-N based on * PCI function # and enetc#N based on interface count */ - if (ofnode_valid(dev->node)) + if (ofnode_valid(dev_ofnode(dev))) sprintf(name, "emdio-%u", PCI_FUNC(pci_get_devfn(dev))); else sprintf(name, "emdio#%u", eth_num_devices++); diff --git a/drivers/net/mdio-ipq4019.c b/drivers/net/mdio-ipq4019.c index 13a8856286..50134b4d9b 100644 --- a/drivers/net/mdio-ipq4019.c +++ b/drivers/net/mdio-ipq4019.c @@ -107,8 +107,8 @@ static const struct mdio_ops ipq4019_mdio_ops = { static int ipq4019_mdio_bind(struct udevice *dev) { - if (ofnode_valid(dev->node)) - device_set_name(dev, ofnode_get_name(dev->node)); + if (ofnode_valid(dev_ofnode(dev))) + device_set_name(dev, ofnode_get_name(dev_ofnode(dev))); return 0; } diff --git a/drivers/net/mdio_mux_i2creg.c b/drivers/net/mdio_mux_i2creg.c index f8557dd2c4..3654230118 100644 --- a/drivers/net/mdio_mux_i2creg.c +++ b/drivers/net/mdio_mux_i2creg.c @@ -61,7 +61,7 @@ static int mdio_mux_i2creg_probe(struct udevice *dev) } /* parent should be an I2C chip, grandparent should be an I2C bus */ - chip_node = ofnode_get_parent(dev->node); + chip_node = ofnode_get_parent(dev_ofnode(dev)); bus_node = ofnode_get_parent(chip_node); err = uclass_get_device_by_ofnode(UCLASS_I2C, bus_node, &i2c_bus); diff --git a/drivers/net/mvmdio.c b/drivers/net/mvmdio.c index 005f28f1b2..96f8dc62b5 100644 --- a/drivers/net/mvmdio.c +++ b/drivers/net/mvmdio.c @@ -197,8 +197,8 @@ static int mvmdio_write(struct udevice *dev, int addr, int devad, int reg, */ static int mvmdio_bind(struct udevice *dev) { - if (ofnode_valid(dev->node)) - device_set_name(dev, ofnode_get_name(dev->node)); + if (ofnode_valid(dev_ofnode(dev))) + device_set_name(dev, ofnode_get_name(dev_ofnode(dev))); return 0; } diff --git a/drivers/net/octeontx/smi.c b/drivers/net/octeontx/smi.c index d1582b968b..58436419f1 100644 --- a/drivers/net/octeontx/smi.c +++ b/drivers/net/octeontx/smi.c @@ -313,7 +313,7 @@ read_error: int octeontx_smi_probe(struct udevice *dev) { - int ret, subnode, cnt = 0, node = dev->node.of_offset; + int ret, subnode, cnt = 0, node = dev_ofnode(dev).of_offset; struct mii_dev *bus; struct octeontx_smi_priv *priv; pci_dev_t bdf = dm_pci_get_bdf(dev); diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index 2d124732cf..ec48689372 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -707,7 +707,8 @@ static int init_phy(struct tsec_private *priv) tsec_configure_serdes(priv); #if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_MDIO) - if (ofnode_valid(ofnode_find_subnode(priv->dev->node, "fixed-link"))) + if (ofnode_valid(ofnode_find_subnode(dev_ofnode(priv->dev), + "fixed-link"))) phydev = phy_connect(NULL, 0, priv->dev, priv->interface); else phydev = dm_eth_phy_connect(priv->dev); diff --git a/drivers/phy/phy-ti-am654.c b/drivers/phy/phy-ti-am654.c index 8e35ea1475..82010e7c96 100644 --- a/drivers/phy/phy-ti-am654.c +++ b/drivers/phy/phy-ti-am654.c @@ -344,7 +344,7 @@ static int serdes_am654_bind(struct udevice *dev) ret = device_bind_driver_to_node(dev->parent, "ti-serdes-am654-mux-clk", - dev_read_name(dev), dev->node, + dev_read_name(dev), dev_ofnode(dev), NULL); if (ret) { dev_err(dev, "%s: not able to bind clock driver\n", __func__); diff --git a/drivers/power/domain/meson-ee-pwrc.c b/drivers/power/domain/meson-ee-pwrc.c index 2e7ab67128..ef8274ce96 100644 --- a/drivers/power/domain/meson-ee-pwrc.c +++ b/drivers/power/domain/meson-ee-pwrc.c @@ -397,11 +397,11 @@ static int meson_ee_pwrc_probe(struct udevice *dev) if (!priv->data) return -EINVAL; - priv->regmap_hhi = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->regmap_hhi = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->regmap_hhi)) return PTR_ERR(priv->regmap_hhi); - ret = ofnode_read_u32(dev->node, "amlogic,ao-sysctrl", + ret = ofnode_read_u32(dev_ofnode(dev), "amlogic,ao-sysctrl", &ao_phandle); if (ret) return ret; diff --git a/drivers/power/domain/meson-gx-pwrc-vpu.c b/drivers/power/domain/meson-gx-pwrc-vpu.c index 40947c66f3..eb94af2cf8 100644 --- a/drivers/power/domain/meson-gx-pwrc-vpu.c +++ b/drivers/power/domain/meson-gx-pwrc-vpu.c @@ -300,11 +300,11 @@ static int meson_gx_pwrc_vpu_probe(struct udevice *dev) ofnode hhi_node; int ret; - priv->regmap_ao = syscon_node_to_regmap(dev_get_parent(dev)->node); + priv->regmap_ao = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev))); if (IS_ERR(priv->regmap_ao)) return PTR_ERR(priv->regmap_ao); - ret = ofnode_read_u32(dev->node, "amlogic,hhi-sysctrl", + ret = ofnode_read_u32(dev_ofnode(dev), "amlogic,hhi-sysctrl", &hhi_phandle); if (ret) return ret; diff --git a/drivers/power/regulator/pbias_regulator.c b/drivers/power/regulator/pbias_regulator.c index 6f0d0a59ff..5bf186e4d4 100644 --- a/drivers/power/regulator/pbias_regulator.c +++ b/drivers/power/regulator/pbias_regulator.c @@ -103,7 +103,8 @@ static int pbias_bind(struct udevice *dev) { int children; - children = pmic_bind_children(dev, dev->node, pmic_children_info); + children = pmic_bind_children(dev, dev_ofnode(dev), + pmic_children_info); if (!children) debug("%s: %s - no child found\n", __func__, dev->name); diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 58b7469f97..03eeacc286 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -304,13 +304,14 @@ static int meson_pwm_probe(struct udevice *dev) if (strcmp(cdev->driver->name, "fixed_rate_clock")) continue; - str = ofnode_read_string(cdev->node, "clock-output-names"); + str = ofnode_read_string(dev_ofnode(cdev), + "clock-output-names"); if (!str) continue; if (!strcmp(str, "xtal")) { err = uclass_get_device_by_ofnode(UCLASS_CLK, - cdev->node, + dev_ofnode(cdev), &cdev); if (err) { printf("%s%d: Failed to get xtal clk\n", __func__, i); @@ -345,7 +346,9 @@ static int meson_pwm_probe(struct udevice *dev) return -EINVAL; } - err = uclass_get_device_by_ofnode(UCLASS_CLK, cdev->node, &cdev); + err = uclass_get_device_by_ofnode(UCLASS_CLK, + dev_ofnode(cdev), + &cdev); if (err) { printf("%s%d: Failed to get clk controller\n", __func__, i); return err; diff --git a/drivers/reset/reset-socfpga.c b/drivers/reset/reset-socfpga.c index c64c9b5917..98450db94b 100644 --- a/drivers/reset/reset-socfpga.c +++ b/drivers/reset/reset-socfpga.c @@ -148,7 +148,7 @@ static int socfpga_reset_bind(struct udevice *dev) * Bind it to the node, too, so that it can get its base address. */ ret = device_bind_driver_to_node(dev, "socfpga_sysreset", "sysreset", - dev->node, &sys_child); + dev_ofnode(dev), &sys_child); if (ret) debug("Warning: No sysreset driver: ret=%d\n", ret); diff --git a/drivers/spi/fsl_dspi.c b/drivers/spi/fsl_dspi.c index b8c0216b39..c17a5522bc 100644 --- a/drivers/spi/fsl_dspi.c +++ b/drivers/spi/fsl_dspi.c @@ -460,8 +460,10 @@ static int fsl_dspi_child_pre_probe(struct udevice *dev) return -EINVAL; } - ofnode_read_u32(dev->node, "fsl,spi-cs-sck-delay", &cs_sck_delay); - ofnode_read_u32(dev->node, "fsl,spi-sck-cs-delay", &sck_cs_delay); + ofnode_read_u32(dev_ofnode(dev), "fsl,spi-cs-sck-delay", + &cs_sck_delay); + ofnode_read_u32(dev_ofnode(dev), "fsl,spi-sck-cs-delay", + &sck_cs_delay); /* Set PCS to SCK delay scale values */ ns_delay_scale(&pcssck, &cssck, cs_sck_delay, priv->bus_clk); diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 7c38d6e052..b898c32edc 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -592,7 +592,7 @@ static optee_invoke_fn *get_invoke_func(struct udevice *dev) const char *method; debug("optee: looking for conduit method in DT.\n"); - method = ofnode_get_property(dev->node, "method", NULL); + method = ofnode_get_property(dev_ofnode(dev), "method", NULL); if (!method) { debug("optee: missing \"method\" property\n"); return ERR_PTR(-ENXIO); diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index e861c82f7e..798a21793f 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -110,7 +110,7 @@ static int cdns3_core_init_role(struct cdns3 *cdns) enum usb_dr_mode dr_mode; int ret = 0; - dr_mode = usb_get_dr_mode(dev->node); + dr_mode = usb_get_dr_mode(dev_ofnode(dev)); cdns->role = USB_ROLE_NONE; /* @@ -393,7 +393,7 @@ int cdns3_bind(struct udevice *parent) ofnode node; int ret; - node = ofnode_by_compatible(parent->node, "cdns,usb3"); + node = ofnode_by_compatible(dev_ofnode(parent), "cdns,usb3"); if (!ofnode_valid(node)) { ret = -ENODEV; goto fail; diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 2e003530a1..dfd7cf683f 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -905,7 +905,7 @@ void dwc3_of_parse(struct dwc3 *dwc) */ hird_threshold = 12; - dwc->hsphy_mode = usb_get_phy_mode(dev->node); + dwc->hsphy_mode = usb_get_phy_mode(dev_ofnode(dev)); dwc->has_lpm_erratum = dev_read_bool(dev, "snps,has-lpm-erratum"); diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 459add80c5..39e931f634 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -108,7 +108,7 @@ static int dwc3_generic_remove(struct udevice *dev, static int dwc3_generic_of_to_plat(struct udevice *dev) { struct dwc3_generic_plat *plat = dev_get_plat(dev); - ofnode node = dev->node; + ofnode node = dev_ofnode(dev); plat->base = dev_read_addr(dev); @@ -301,7 +301,7 @@ static int dwc3_glue_bind(struct udevice *parent) ofnode node; int ret; - ofnode_for_each_subnode(node, parent->node) { + ofnode_for_each_subnode(node, dev_ofnode(parent)) { const char *name = ofnode_get_name(node); enum usb_dr_mode dr_mode; struct udevice *dev; @@ -418,7 +418,7 @@ static int dwc3_glue_probe(struct udevice *dev) while (child) { enum usb_dr_mode dr_mode; - dr_mode = usb_get_dr_mode(child->node); + dr_mode = usb_get_dr_mode(dev_ofnode(child)); device_find_next_child(&child); if (ops && ops->select_dr_mode) ops->select_dr_mode(dev, index, dr_mode); diff --git a/drivers/usb/dwc3/dwc3-meson-g12a.c b/drivers/usb/dwc3/dwc3-meson-g12a.c index acc7866b64..6f99fb27f3 100644 --- a/drivers/usb/dwc3/dwc3-meson-g12a.c +++ b/drivers/usb/dwc3/dwc3-meson-g12a.c @@ -395,7 +395,7 @@ static int dwc3_meson_g12a_probe(struct udevice *dev) } #endif - priv->otg_mode = usb_get_dr_mode(dev->node); + priv->otg_mode = usb_get_dr_mode(dev_ofnode(dev)); ret = dwc3_meson_g12a_usb_init(priv); if (ret) diff --git a/drivers/usb/dwc3/dwc3-meson-gxl.c b/drivers/usb/dwc3/dwc3-meson-gxl.c index b63cc235f7..08467d6210 100644 --- a/drivers/usb/dwc3/dwc3-meson-gxl.c +++ b/drivers/usb/dwc3/dwc3-meson-gxl.c @@ -338,7 +338,7 @@ static int dwc3_meson_gxl_probe(struct udevice *dev) if (ret) return ret; - priv->otg_mode = usb_get_dr_mode(dev->node); + priv->otg_mode = usb_get_dr_mode(dev_ofnode(dev)); if (priv->otg_mode == USB_DR_MODE_PERIPHERAL) priv->otg_phy_mode = USB_DR_MODE_PERIPHERAL; diff --git a/drivers/usb/gadget/dwc2_udc_otg.c b/drivers/usb/gadget/dwc2_udc_otg.c index 4771b1e931..e3871e381e 100644 --- a/drivers/usb/gadget/dwc2_udc_otg.c +++ b/drivers/usb/gadget/dwc2_udc_otg.c @@ -987,8 +987,8 @@ static int dwc2_udc_otg_of_to_plat(struct udevice *dev) void (*set_params)(struct dwc2_plat_otg_data *data); int ret; - if (usb_get_dr_mode(dev->node) != USB_DR_MODE_PERIPHERAL && - usb_get_dr_mode(dev->node) != USB_DR_MODE_OTG) { + if (usb_get_dr_mode(dev_ofnode(dev)) != USB_DR_MODE_PERIPHERAL && + usb_get_dr_mode(dev_ofnode(dev)) != USB_DR_MODE_OTG) { dev_dbg(dev, "Invalid mode\n"); return -ENODEV; } diff --git a/drivers/usb/host/dwc3-octeon-glue.c b/drivers/usb/host/dwc3-octeon-glue.c index c3cac9c5ab..742e156cbb 100644 --- a/drivers/usb/host/dwc3-octeon-glue.c +++ b/drivers/usb/host/dwc3-octeon-glue.c @@ -366,7 +366,7 @@ static int octeon_dwc3_glue_bind(struct udevice *dev) /* Find snps,dwc3 node from subnode */ dwc3_node = ofnode_null(); - ofnode_for_each_subnode(node, dev->node) { + ofnode_for_each_subnode(node, dev_ofnode(dev)) { if (ofnode_device_is_compatible(node, "snps,dwc3")) dwc3_node = node; } diff --git a/drivers/usb/host/dwc3-sti-glue.c b/drivers/usb/host/dwc3-sti-glue.c index deb820a0f8..e5c6a1a67d 100644 --- a/drivers/usb/host/dwc3-sti-glue.c +++ b/drivers/usb/host/dwc3-sti-glue.c @@ -108,7 +108,8 @@ static int sti_dwc3_glue_of_to_plat(struct udevice *dev) int ret; u32 reg[4]; - ret = ofnode_read_u32_array(dev->node, "reg", reg, ARRAY_SIZE(reg)); + ret = ofnode_read_u32_array(dev_ofnode(dev), "reg", reg, + ARRAY_SIZE(reg)); if (ret) { pr_err("unable to find st,stih407-dwc3 reg property(%d)\n", ret); return ret; @@ -154,7 +155,7 @@ static int sti_dwc3_glue_bind(struct udevice *dev) ofnode node, dwc3_node; /* Find snps,dwc3 node from subnode */ - ofnode_for_each_subnode(node, dev->node) { + ofnode_for_each_subnode(node, dev_ofnode(dev)) { if (ofnode_device_is_compatible(node, "snps,dwc3")) dwc3_node = node; } diff --git a/drivers/usb/host/ehci-mx6.c b/drivers/usb/host/ehci-mx6.c index d2f49cf469..ef3a63afa4 100644 --- a/drivers/usb/host/ehci-mx6.c +++ b/drivers/usb/host/ehci-mx6.c @@ -523,7 +523,7 @@ static int ehci_usb_of_to_plat(struct udevice *dev) struct usb_plat *plat = dev_get_plat(dev); enum usb_dr_mode dr_mode; - dr_mode = usb_get_dr_mode(dev->node); + dr_mode = usb_get_dr_mode(dev_ofnode(dev)); switch (dr_mode) { case USB_DR_MODE_HOST: diff --git a/drivers/usb/host/xhci-dwc3.c b/drivers/usb/host/xhci-dwc3.c index 59408e4e50..3e0ae80cec 100644 --- a/drivers/usb/host/xhci-dwc3.c +++ b/drivers/usb/host/xhci-dwc3.c @@ -155,7 +155,7 @@ static int xhci_dwc3_probe(struct udevice *dev) writel(reg, &dwc3_reg->g_usb2phycfg[0]); - dr_mode = usb_get_dr_mode(dev->node); + dr_mode = usb_get_dr_mode(dev_ofnode(dev)); if (dr_mode == USB_DR_MODE_UNKNOWN) /* by default set dual role mode to HOST */ dr_mode = USB_DR_MODE_HOST; diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index 28136f88f4..2f5cc9b148 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -802,7 +802,7 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb) mtu->ippc_base = ssusb->ippc_base; mtu->mac_base = ssusb->mac_base; mtu->ssusb = ssusb; - mtu->max_speed = usb_get_maximum_speed(dev->node); + mtu->max_speed = usb_get_maximum_speed(dev_ofnode(dev)); mtu->force_vbus = dev_read_bool(dev, "mediatek,force-vbus"); ret = mtu3_hw_init(mtu); diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index c951107b20..b097471f3d 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -173,7 +173,7 @@ static int get_ssusb_rscs(struct udevice *dev, struct ssusb_mtk *ssusb) return -ENODEV; } - ssusb->dr_mode = usb_get_dr_mode(child->node); + ssusb->dr_mode = usb_get_dr_mode(dev_ofnode(child)); if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN || ssusb->dr_mode == USB_DR_MODE_OTG) @@ -313,7 +313,7 @@ static int mtu3_glue_bind(struct udevice *parent) ofnode node; int ret; - node = ofnode_by_compatible(parent->node, "mediatek,ssusb"); + node = ofnode_by_compatible(dev_ofnode(parent), "mediatek,ssusb"); if (!ofnode_valid(node)) return -ENODEV; diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c index 81b12fadfc..75cf1811f7 100644 --- a/drivers/usb/musb-new/ti-musb.c +++ b/drivers/usb/musb-new/ti-musb.c @@ -289,7 +289,7 @@ static int ti_musb_wrapper_bind(struct udevice *parent) ofnode node; int ret; - ofnode_for_each_subnode(node, parent->node) { + ofnode_for_each_subnode(node, dev_ofnode(parent)) { struct udevice *dev; const char *name = ofnode_get_name(node); enum usb_dr_mode dr_mode; diff --git a/drivers/video/nexell_display.c b/drivers/video/nexell_display.c index 00e2c36f37..b47bef3578 100644 --- a/drivers/video/nexell_display.c +++ b/drivers/video/nexell_display.c @@ -416,7 +416,7 @@ static struct nx_display_dev *nx_display_setup(void) __func__); return NULL; } - node = dev->node.of_offset; + node = dev_ofnode(dev).of_offset; if (CONFIG_IS_ENABLED(OF_CONTROL)) { ret = nx_display_parse_dt(dev, dp, plat); diff --git a/drivers/video/rockchip/rk_mipi.c b/drivers/video/rockchip/rk_mipi.c index d125a5ba73..159201a591 100644 --- a/drivers/video/rockchip/rk_mipi.c +++ b/drivers/video/rockchip/rk_mipi.c @@ -119,7 +119,7 @@ int rk_mipi_dsi_enable(struct udevice *dev, rk_mipi_dsi_write(regs, VID_PKT_SIZE, 0x4b0); /* Set dpi color coding depth 24 bit */ - timing_node = ofnode_find_subnode(dev->node, "display-timings"); + timing_node = ofnode_find_subnode(dev_ofnode(dev), "display-timings"); node = ofnode_first_subnode(timing_node); val = ofnode_read_u32_default(node, "bits-per-pixel", -1); diff --git a/include/dm/device.h b/include/dm/device.h index 4a1224bcc2..1b274206ea 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -200,7 +200,11 @@ static inline void dev_bic_flags(struct udevice *dev, u32 bic) */ static inline ofnode dev_ofnode(const struct udevice *dev) { +#if !CONFIG_IS_ENABLED(OF_PLATDATA) return dev->node; +#else + return ofnode_null(); +#endif } /* Returns non-zero if the device is active (probed and not removed) */ @@ -208,12 +212,27 @@ static inline ofnode dev_ofnode(const struct udevice *dev) static inline int dev_of_offset(const struct udevice *dev) { - return ofnode_to_offset(dev->node); +#if !CONFIG_IS_ENABLED(OF_PLATDATA) + return ofnode_to_offset(dev_ofnode(dev)); +#else + return -1; +#endif } static inline bool dev_has_ofnode(const struct udevice *dev) { - return ofnode_valid(dev->node); +#if !CONFIG_IS_ENABLED(OF_PLATDATA) + return ofnode_valid(dev_ofnode(dev)); +#else + return false; +#endif +} + +static inline void dev_set_ofnode(struct udevice *dev, ofnode node) +{ +#if !CONFIG_IS_ENABLED(OF_PLATDATA) + dev->node = node; +#endif } static inline int dev_seq(const struct udevice *dev) diff --git a/include/dm/read.h b/include/dm/read.h index d5cdd87911..fc987f7759 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -21,7 +21,7 @@ struct resource; #if CONFIG_IS_ENABLED(OF_LIVE) static inline const struct device_node *dev_np(const struct udevice *dev) { - return ofnode_to_np(dev->node); + return ofnode_to_np(dev_ofnode(dev)); } #else static inline const struct device_node *dev_np(const struct udevice *dev) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 54d03d0240..927854950a 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -334,12 +334,12 @@ struct mtd_info { #if IS_ENABLED(CONFIG_DM) static inline void mtd_set_ofnode(struct mtd_info *mtd, ofnode node) { - mtd->dev->node = node; + dev_set_ofnode(mtd->dev, node); } static inline const ofnode mtd_get_ofnode(struct mtd_info *mtd) { - return mtd->dev->node; + return dev_ofnode(mtd->dev); } #else struct device_node; diff --git a/net/mdio-mux-uclass.c b/net/mdio-mux-uclass.c index 5f38f9fde4..780526c19e 100644 --- a/net/mdio-mux-uclass.c +++ b/net/mdio-mux-uclass.c @@ -163,7 +163,7 @@ static int dm_mdio_mux_post_bind(struct udevice *mux) ofnode ch_node; int err, first_err = 0; - if (!ofnode_valid(mux->node)) { + if (!dev_has_ofnode(mux)) { debug("%s: no mux node found, no child MDIO busses set up\n", __func__); return 0; diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index d062382c2a..697e5f838d 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -40,8 +40,8 @@ static int dm_mdio_post_bind(struct udevice *dev) const char *dt_name; /* set a custom name for the MDIO device, if present in DT */ - if (ofnode_valid(dev->node)) { - dt_name = ofnode_read_string(dev->node, "device-name"); + if (dev_has_ofnode(dev)) { + dt_name = dev_read_string(dev, "device-name"); if (dt_name) { debug("renaming dev %s to %s\n", dev->name, dt_name); device_set_name(dev, dt_name); @@ -182,14 +182,14 @@ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev) struct phy_device *phy; int i; - if (!ofnode_valid(ethdev->node)) { + if (!dev_has_ofnode(ethdev)) { debug("%s: supplied eth dev has no DT node!\n", ethdev->name); return NULL; } interface = PHY_INTERFACE_MODE_NONE; for (i = 0; i < PHY_MODE_STR_CNT; i++) { - if_str = ofnode_read_string(ethdev->node, phy_mode_str[i]); + if_str = dev_read_string(ethdev, phy_mode_str[i]); if (if_str) { interface = phy_get_interface_by_name(if_str); break; -- cgit v1.2.3 From 84a42ae3668313e72b5056940f4f8e6f5c78e399 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:15 -0700 Subject: dm: core: Rename device node to indicate it is private To avoid having people accidentally access this member, add a trailing underscore. Also remove it when of-platdata is enabled, since it is not used. Signed-off-by: Simon Glass --- include/dm/device.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/dm/device.h b/include/dm/device.h index 1b274206ea..4469804a00 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -122,7 +122,6 @@ enum { * access outside driver model) * @uclass_plat_: The uclass's configuration data for this device (do not access * outside driver model) - * @node: Reference to device tree node for this device * @driver_data: Driver data word for the entry that matched this device with * its driver * @parent: Parent of this device, or NULL for the top level device @@ -143,6 +142,8 @@ enum { * number. Otherwise, the next available number is used. Sequence numbers are * used by certain commands that need device to be numbered (e.g. 'mmc dev'). * (do not access outside driver model) + * @node_: Reference to device tree node for this device (do not access outside + * driver model) * @devres_head: List of memory allocations associated with this device. * When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will * add to this list. Memory so-allocated will be freed @@ -154,7 +155,6 @@ struct udevice { void *plat_; void *parent_plat_; void *uclass_plat_; - ofnode node; ulong driver_data; struct udevice *parent; void *priv_; @@ -166,6 +166,9 @@ struct udevice { struct list_head sibling_node; u32 flags_; int seq_; +#if !CONFIG_IS_ENABLED(OF_PLATDATA) + ofnode node_; +#endif #ifdef CONFIG_DEVRES struct list_head devres_head; #endif @@ -201,7 +204,7 @@ static inline void dev_bic_flags(struct udevice *dev, u32 bic) static inline ofnode dev_ofnode(const struct udevice *dev) { #if !CONFIG_IS_ENABLED(OF_PLATDATA) - return dev->node; + return dev->node_; #else return ofnode_null(); #endif @@ -231,7 +234,7 @@ static inline bool dev_has_ofnode(const struct udevice *dev) static inline void dev_set_ofnode(struct udevice *dev, ofnode node) { #if !CONFIG_IS_ENABLED(OF_PLATDATA) - dev->node = node; + dev->node_ = node; #endif } -- cgit v1.2.3 From 49bbe6eab5babbc353f1dc76e6275671c69dffb2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:16 -0700 Subject: dm: core: Split out scanning code to dm_scan() Move the code related to scanning for devices to bind, into a new function. This will make it easier to skip this step with the new of-platdata improvements. Signed-off-by: Simon Glass --- drivers/core/root.c | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/drivers/core/root.c b/drivers/core/root.c index fe7359433f..2a5ebec27d 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -296,39 +296,60 @@ __weak int dm_scan_other(bool pre_reloc_only) return 0; } -int dm_init_and_scan(bool pre_reloc_only) +/** + * dm_scan() - Scan tables to bind devices + * + * Runs through the driver_info tables and binds the devices it finds. Then runs + * through the devicetree nodes. Finally calls dm_scan_other() to add any + * special devices + * + * @pre_reloc_only: If true, bind only nodes with special devicetree properties, + * or drivers with the DM_FLAG_PRE_RELOC flag. If false bind all drivers. + */ +static int dm_scan(bool pre_reloc_only) { int ret; - if (CONFIG_IS_ENABLED(OF_PLATDATA)) - dm_populate_phandle_data(); - - ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE)); - if (ret) { - debug("dm_init() failed: %d\n", ret); - return ret; - } ret = dm_scan_plat(pre_reloc_only); if (ret) { debug("dm_scan_plat() failed: %d\n", ret); - goto fail; + return ret; } if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) { ret = dm_extended_scan(pre_reloc_only); if (ret) { debug("dm_extended_scan() failed: %d\n", ret); - goto fail; + return ret; } } ret = dm_scan_other(pre_reloc_only); if (ret) - goto fail; + return ret; + + return 0; +} + +int dm_init_and_scan(bool pre_reloc_only) +{ + int ret; + + if (CONFIG_IS_ENABLED(OF_PLATDATA)) + dm_populate_phandle_data(); + + ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE)); + if (ret) { + debug("dm_init() failed: %d\n", ret); + return ret; + } + ret = dm_scan(pre_reloc_only); + if (ret) { + log_debug("dm_scan() failed: %d\n", ret); + return ret; + } return 0; -fail: - return ret; } #ifdef CONFIG_ACPIGEN -- cgit v1.2.3 From 8a715530bb1f9522030757379415b174f3109951 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:17 -0700 Subject: dm: core: Allow the uclass list to move At present the uclass list head is in global_data. This is convenient but with the new of-platdata we need the list head to be declared by the generated code. Change this over to be a pointer. Provide a 'static' version in global_data to retain the current behaviour. Signed-off-by: Simon Glass --- drivers/core/device.c | 4 ++-- drivers/core/root.c | 7 ++++--- drivers/core/uclass.c | 4 ++-- include/asm-generic/global_data.h | 8 +++++++- include/dm/device-internal.h | 1 + test/dm/core.c | 6 +++--- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 6a9bee093d..aeab3836ed 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -613,7 +613,7 @@ static int device_find_by_ofnode(ofnode node, struct udevice **devp) struct udevice *dev; int ret; - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev); if (!ret || dev) { @@ -1032,7 +1032,7 @@ int dev_disable_by_path(const char *path) if (!of_live_active()) return -ENOSYS; - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev); if (!ret) break; diff --git a/drivers/core/root.c b/drivers/core/root.c index 2a5ebec27d..3adbc94eb9 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -45,8 +45,8 @@ void dm_fixup_for_gd_move(struct global_data *new_gd) { /* The sentinel node has moved, so update things that point to it */ if (gd->dm_root) { - new_gd->uclass_root.next->prev = &new_gd->uclass_root; - new_gd->uclass_root.prev->next = &new_gd->uclass_root; + new_gd->uclass_root->next->prev = new_gd->uclass_root; + new_gd->uclass_root->prev->next = new_gd->uclass_root; } } @@ -136,7 +136,8 @@ int dm_init(bool of_live) dm_warn("Virtual root driver already exists!\n"); return -EINVAL; } - INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST); + gd->uclass_root = &DM_UCLASS_ROOT_S_NON_CONST; + INIT_LIST_HEAD(DM_UCLASS_ROOT_NON_CONST); if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC)) { fix_drivers(); diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index e773e34833..cdb975d5b3 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -33,7 +33,7 @@ struct uclass *uclass_find(enum uclass_id key) * node to the start of the list, or creating a linear array mapping * id to node. */ - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { if (uc->uc_drv->id == key) return uc; } @@ -84,7 +84,7 @@ static int uclass_add(enum uclass_id id, struct uclass **ucp) uc->uc_drv = uc_drv; INIT_LIST_HEAD(&uc->sibling_node); INIT_LIST_HEAD(&uc->dev_head); - list_add(&uc->sibling_node, &DM_UCLASS_ROOT_NON_CONST); + list_add(&uc->sibling_node, DM_UCLASS_ROOT_NON_CONST); if (uc_drv->init) { ret = uc_drv->init(uc); diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 87d827d0f4..b63575919f 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -194,7 +194,13 @@ struct global_data { /** * @uclass_root: head of core tree */ - struct list_head uclass_root; + struct list_head uclass_root_s; + /** + * @uclass_root: pointer to head of core tree, if uclasses are in + * read-only memory and cannot be adjusted to use @uclass_root as a + * list head. + */ + struct list_head *uclass_root; # if CONFIG_IS_ENABLED(OF_PLATDATA) /** Dynamic info about the driver */ struct driver_rt *dm_driver_rt; diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index 03b092bdf7..639bbd293d 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -288,6 +288,7 @@ fdt_addr_t simple_bus_translate(struct udevice *dev, fdt_addr_t addr); /* Cast away any volatile pointer */ #define DM_ROOT_NON_CONST (((gd_t *)gd)->dm_root) #define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root) +#define DM_UCLASS_ROOT_S_NON_CONST (((gd_t *)gd)->uclass_root_s) /* device resource management */ #ifdef CONFIG_DEVRES diff --git a/test/dm/core.c b/test/dm/core.c index 565896ed50..580d171e30 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -116,14 +116,14 @@ static int dm_test_autobind(struct unit_test_state *uts) * device with no children. */ ut_assert(dms->root); - ut_asserteq(1, list_count_items(&gd->uclass_root)); + ut_asserteq(1, list_count_items(gd->uclass_root)); ut_asserteq(0, list_count_items(&gd->dm_root->child_head)); ut_asserteq(0, dm_testdrv_op_count[DM_TEST_OP_POST_BIND]); ut_assertok(dm_scan_plat(false)); /* We should have our test class now at least, plus more children */ - ut_assert(1 < list_count_items(&gd->uclass_root)); + ut_assert(1 < list_count_items(gd->uclass_root)); ut_assert(0 < list_count_items(&gd->dm_root->child_head)); /* Our 3 dm_test_infox children should be bound to the test uclass */ @@ -1073,7 +1073,7 @@ static int dm_test_all_have_seq(struct unit_test_state *uts) struct udevice *dev; struct uclass *uc; - list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(uc, gd->uclass_root, sibling_node) { list_for_each_entry(dev, &uc->dev_head, uclass_node) { if (dev->seq_ == -1) printf("Device '%s' has no seq (%d)\n", -- cgit v1.2.3 From 97e8684c84e40b04c07f6abb5f9cecedf315d0c5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 19 Dec 2020 10:40:18 -0700 Subject: dm: core: Add logging when lists_bind_fdt() fails It is useful to see the error code when this fails. Add logging for this function. Signed-off-by: Simon Glass --- drivers/core/lists.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/core/lists.c b/drivers/core/lists.c index 426444db3a..e214306b90 100644 --- a/drivers/core/lists.c +++ b/drivers/core/lists.c @@ -251,7 +251,7 @@ int lists_bind_fdt(struct udevice *parent, ofnode node, struct udevice **devp, if (ret) { dm_warn("Error binding driver '%s': %d\n", entry->name, ret); - return ret; + return log_msg_ret("bind", ret); } else { found = true; if (devp) -- cgit v1.2.3 From 67b5ec54a5c19452c7aa33c693f281cc18a37d09 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:47 -0700 Subject: dtoc: Tidy up pylint warnings in test Tidy up this file to reduce the number of pylint warnings. Signed-off-by: Simon Glass --- tools/dtoc/test_dtoc.py | 156 ++++++++++++++++++++++++++---------------------- 1 file changed, 85 insertions(+), 71 deletions(-) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index c76942c9e2..4bf90444e1 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -12,21 +12,20 @@ tool. import collections import os import struct -import sys import tempfile import unittest -from dtoc import dtb_platdata from dtb_platdata import conv_name_to_c from dtb_platdata import get_compat_name from dtb_platdata import get_value from dtb_platdata import tab_to +from dtoc import dtb_platdata from dtoc import fdt from dtoc import fdt_util from patman import test_util from patman import tools -our_path = os.path.dirname(os.path.realpath(__file__)) +OUR_PATH = os.path.dirname(os.path.realpath(__file__)) HEADER = '''/* @@ -56,18 +55,21 @@ C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) { } ''' +# This is a test so is allowed to access private things in the module it is +# testing +# pylint: disable=W0212 def get_dtb_file(dts_fname, capture_stderr=False): """Compile a .dts file to a .dtb Args: - dts_fname: Filename of .dts file in the current directory - capture_stderr: True to capture and discard stderr output + dts_fname (str): Filename of .dts file in the current directory + capture_stderr (bool): True to capture and discard stderr output Returns: - Filename of compiled file in output directory + str: Filename of compiled file in output directory """ - return fdt_util.EnsureCompiled(os.path.join(our_path, dts_fname), + return fdt_util.EnsureCompiled(os.path.join(OUR_PATH, dts_fname), capture_stderr=capture_stderr) @@ -80,20 +82,21 @@ class TestDtoc(unittest.TestCase): @classmethod def tearDownClass(cls): - tools._RemoveOutputDir() + tools.FinaliseOutputDir() - def _WritePythonString(self, fname, data): + @staticmethod + def _write_python_string(fname, data): """Write a string with tabs expanded as done in this Python file Args: - fname: Filename to write to - data: Raw string to convert + fname (str): Filename to write to + data (str): Raw string to convert """ data = data.replace('\t', '\\t') - with open(fname, 'w') as fd: - fd.write(data) + with open(fname, 'w') as fout: + fout.write(data) - def _CheckStrings(self, expected, actual): + def _check_strings(self, expected, actual): """Check that a string matches its expected value If the strings do not match, they are written to the /tmp directory in @@ -101,17 +104,24 @@ class TestDtoc(unittest.TestCase): easy comparison and update of the tests. Args: - expected: Expected string - actual: Actual string + expected (str): Expected string + actual (str): Actual string """ if expected != actual: - self._WritePythonString('/tmp/binman.expected', expected) - self._WritePythonString('/tmp/binman.actual', actual) + self._write_python_string('/tmp/binman.expected', expected) + self._write_python_string('/tmp/binman.actual', actual) print('Failures written to /tmp/binman.{expected,actual}') - self.assertEquals(expected, actual) + self.assertEqual(expected, actual) + @staticmethod + def run_test(args, dtb_file, output): + """Run a test using dtoc - def run_test(self, args, dtb_file, output): + Args: + args (list of str): List of arguments for dtoc + dtb_file (str): Filename of .dtb file + output (str): Filename of output file + """ dtb_platdata.run_steps(args, dtb_file, False, output, True) def test_name(self): @@ -160,7 +170,7 @@ class TestDtoc(unittest.TestCase): prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third']) node = Node({'compatible': prop}) self.assertEqual((['rockchip_rk3399_sdhci_5_1', - 'arasan_sdhci_5_1', 'third']), + 'arasan_sdhci_5_1', 'third']), get_compat_name(node)) def test_empty_file(self): @@ -185,7 +195,7 @@ class TestDtoc(unittest.TestCase): self.run_test(['struct'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_sandbox_i2c_test { }; struct dtd_sandbox_pmic_test { @@ -209,7 +219,7 @@ struct dtd_sandbox_spl_test { self.run_test(['platdata'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /i2c@0 index 0 */ static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { }; @@ -293,7 +303,7 @@ U_BOOT_DEVICE(spl_test3) = { self.run_test(['struct'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_sandbox_gpio { \tconst char *\tgpio_bank_name; \tbool\t\tgpio_controller; @@ -304,7 +314,7 @@ struct dtd_sandbox_gpio { self.run_test(['platdata'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /gpios@0 index 0 */ static struct dtd_sandbox_gpio dtv_gpios_at_0 = { \t.gpio_bank_name\t\t= "a", @@ -326,20 +336,20 @@ void dm_populate_phandle_data(void) { """Test output from a device tree file with an invalid driver""" dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts') output = tools.GetOutputFilename('output') - with test_util.capture_sys_output() as (stdout, stderr): + with test_util.capture_sys_output() as _: dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_invalid { }; ''', data) - with test_util.capture_sys_output() as (stdout, stderr): + with test_util.capture_sys_output() as _: dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /spl-test index 0 */ static struct dtd_invalid dtv_spl_test = { }; @@ -361,7 +371,7 @@ void dm_populate_phandle_data(void) { self.run_test(['struct'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_source { \tstruct phandle_2_arg clocks[4]; }; @@ -373,7 +383,7 @@ struct dtd_target { self.run_test(['platdata'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /phandle2-target index 0 */ static struct dtd_target dtv_phandle2_target = { \t.intval\t\t\t= 0x1, @@ -445,7 +455,7 @@ void dm_populate_phandle_data(void) { self.run_test(['struct'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_source { \tstruct phandle_0_arg clocks[1]; }; @@ -461,7 +471,7 @@ struct dtd_target { self.run_test(['platdata'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /phandle-target index 1 */ static struct dtd_target dtv_phandle_target = { }; @@ -495,7 +505,7 @@ void dm_populate_phandle_data(void) { dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /phandle2-target index 0 */ static struct dtd_target dtv_phandle2_target = { \t.intval\t\t\t= 0x1, @@ -565,20 +575,20 @@ void dm_populate_phandle_data(void) { dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts', capture_stderr=True) output = tools.GetOutputFilename('output') - with self.assertRaises(ValueError) as e: + with self.assertRaises(ValueError) as exc: self.run_test(['struct'], dtb_file, output) self.assertIn("Cannot parse 'clocks' in node 'phandle-source'", - str(e.exception)) + str(exc.exception)) def test_phandle_bad2(self): """Test a phandle target missing its #*-cells property""" dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts', capture_stderr=True) output = tools.GetOutputFilename('output') - with self.assertRaises(ValueError) as e: + with self.assertRaises(ValueError) as exc: self.run_test(['struct'], dtb_file, output) self.assertIn("Node 'phandle-target' has no cells property", - str(e.exception)) + str(exc.exception)) def test_addresses64(self): """Test output from a node with a 'reg' property with na=2, ns=2""" @@ -587,7 +597,7 @@ void dm_populate_phandle_data(void) { self.run_test(['struct'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_test1 { \tfdt64_t\t\treg[2]; }; @@ -602,7 +612,7 @@ struct dtd_test3 { self.run_test(['platdata'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /test1 index 0 */ static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, @@ -645,7 +655,7 @@ U_BOOT_DEVICE(test3) = { self.run_test(['struct'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_test1 { \tfdt32_t\t\treg[2]; }; @@ -657,7 +667,7 @@ struct dtd_test2 { self.run_test(['platdata'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /test1 index 0 */ static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, @@ -689,7 +699,7 @@ U_BOOT_DEVICE(test2) = { self.run_test(['struct'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_test1 { \tfdt64_t\t\treg[2]; }; @@ -704,7 +714,7 @@ struct dtd_test3 { self.run_test(['platdata'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /test1 index 0 */ static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x123400000000, 0x5678}, @@ -747,7 +757,7 @@ U_BOOT_DEVICE(test3) = { self.run_test(['struct'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_test1 { \tfdt64_t\t\treg[2]; }; @@ -762,7 +772,7 @@ struct dtd_test3 { self.run_test(['platdata'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /test1 index 0 */ static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x567800000000}, @@ -803,20 +813,21 @@ U_BOOT_DEVICE(test3) = { # Capture stderr since dtc will emit warnings for this file dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True) output = tools.GetOutputFilename('output') - with self.assertRaises(ValueError) as e: + with self.assertRaises(ValueError) as exc: self.run_test(['struct'], dtb_file, output) self.assertIn("Node 'spl-test' reg property is not an int", - str(e.exception)) + str(exc.exception)) def test_bad_reg2(self): """Test that a reg property with an invalid cell count is detected""" # Capture stderr since dtc will emit warnings for this file dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True) output = tools.GetOutputFilename('output') - with self.assertRaises(ValueError) as e: + with self.assertRaises(ValueError) as exc: self.run_test(['struct'], dtb_file, output) - self.assertIn("Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", - str(e.exception)) + self.assertIn( + "Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", + str(exc.exception)) def test_add_prop(self): """Test that a subequent node can add a new property to a struct""" @@ -825,7 +836,7 @@ U_BOOT_DEVICE(test3) = { self.run_test(['struct'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(HEADER + ''' + self._check_strings(HEADER + ''' struct dtd_sandbox_spl_test { \tfdt32_t\t\tintarray; \tfdt32_t\t\tintval; @@ -835,7 +846,7 @@ struct dtd_sandbox_spl_test { self.run_test(['platdata'], dtb_file, output) with open(output) as infile: data = infile.read() - self._CheckStrings(C_HEADER + ''' + self._check_strings(C_HEADER + ''' /* Node /spl-test index 0 */ static struct dtd_sandbox_spl_test dtv_spl_test = { \t.intval\t\t\t= 0x1, @@ -860,37 +871,40 @@ U_BOOT_DEVICE(spl_test2) = { ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) - def testStdout(self): + def test_stdout(self): """Test output to stdout""" dtb_file = get_dtb_file('dtoc_test_simple.dts') - with test_util.capture_sys_output() as (stdout, stderr): + with test_util.capture_sys_output() as _: self.run_test(['struct'], dtb_file, '-') - def testNoCommand(self): + def test_no_command(self): """Test running dtoc without a command""" - with self.assertRaises(ValueError) as e: + with self.assertRaises(ValueError) as exc: self.run_test([], '', '') self.assertIn("Please specify a command: struct, platdata", - str(e.exception)) + str(exc.exception)) - def testBadCommand(self): + def test_bad_command(self): """Test running dtoc with an invalid command""" dtb_file = get_dtb_file('dtoc_test_simple.dts') output = tools.GetOutputFilename('output') - with self.assertRaises(ValueError) as e: + with self.assertRaises(ValueError) as exc: self.run_test(['invalid-cmd'], dtb_file, output) self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)", - str(e.exception)) + str(exc.exception)) - def testScanDrivers(self): + @staticmethod + def test_scan_drivers(): """Test running dtoc with additional drivers to scan""" dtb_file = get_dtb_file('dtoc_test_simple.dts') output = tools.GetOutputFilename('output') - with test_util.capture_sys_output() as (stdout, stderr): - dtb_platdata.run_steps(['struct'], dtb_file, False, output, True, - [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx']) + with test_util.capture_sys_output() as _: + dtb_platdata.run_steps( + ['struct'], dtb_file, False, output, True, + [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx']) - def testUnicodeError(self): + @staticmethod + def test_unicode_error(): """Test running dtoc with an invalid unicode file To be able to perform this test without adding a weird text file which @@ -900,14 +914,14 @@ U_BOOT_DEVICE(spl_test2) = { dtb_file = get_dtb_file('dtoc_test_simple.dts') output = tools.GetOutputFilename('output') driver_fn = '/tmp/' + next(tempfile._get_candidate_names()) - with open(driver_fn, 'wb+') as df: - df.write(b'\x81') + with open(driver_fn, 'wb+') as fout: + fout.write(b'\x81') - with test_util.capture_sys_output() as (stdout, stderr): + with test_util.capture_sys_output() as _: dtb_platdata.run_steps(['struct'], dtb_file, False, output, True, - [driver_fn]) + [driver_fn]) - def testDriver(self): + def test_driver(self): """Test the Driver class""" drv1 = dtb_platdata.Driver('fred') drv2 = dtb_platdata.Driver('mary') -- cgit v1.2.3 From f62cea0e205c905632be3aefa82b10ef36ce8a25 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:48 -0700 Subject: dtoc: Use None to mean stdout At present dtoc uses '-' internally to mean that output should go to stdout. This is not necessary and None is more convenient. Update it. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 10 +++++----- tools/dtoc/main.py | 2 +- tools/dtoc/test_dtoc.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 5b1bb7e5fd..118b1a5f43 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -237,12 +237,12 @@ class DtbPlatdata(): file. Args: - fname (str): Filename to send output to, or '-' for stdout + fname (str): Filename to send output to, or None for stdout """ - if fname == '-': - self._outfile = sys.stdout - else: + if fname: self._outfile = open(fname, 'w') + else: + self._outfile = sys.stdout def out(self, line): """Output a string to the output file @@ -765,7 +765,7 @@ def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False, args (list): List of non-option arguments provided to the problem dtb_file (str): Filename of dtb file to process include_disabled (bool): True to include disabled nodes - output (str): Name of output file + output (str): Name of output file (None for stdout) warning_disabled (bool): True to avoid showing warnings about missing drivers drivers_additional (list): List of additional drivers to use during diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py index b94d9c301f..7686c8784d 100755 --- a/tools/dtoc/main.py +++ b/tools/dtoc/main.py @@ -91,7 +91,7 @@ parser.add_option('-d', '--dtb-file', action='store', help='Specify the .dtb input file') parser.add_option('--include-disabled', action='store_true', help='Include disabled nodes') -parser.add_option('-o', '--output', action='store', default='-', +parser.add_option('-o', '--output', action='store', help='Select output filename') parser.add_option('-P', '--processes', type=int, help='set number of processes to use for running tests') diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 4bf90444e1..41a10eb400 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -875,7 +875,7 @@ U_BOOT_DEVICE(spl_test2) = { """Test output to stdout""" dtb_file = get_dtb_file('dtoc_test_simple.dts') with test_util.capture_sys_output() as _: - self.run_test(['struct'], dtb_file, '-') + self.run_test(['struct'], dtb_file, None) def test_no_command(self): """Test running dtoc without a command""" -- cgit v1.2.3 From de846cbb307486a1533dcf4d5c28568412149ddb Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:49 -0700 Subject: dtoc: Test the stdout output Normally dtoc outputs to a file but it also offers a way to write output to stdout. At present the test for that does not actually check that the output is correct. Add this to the test. This uses a member variable to hold the expected text, so it can be used in muitiple places. Signed-off-by: Simon Glass --- tools/dtoc/test_dtoc.py | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 41a10eb400..7cf2a5187c 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -188,14 +188,7 @@ class TestDtoc(unittest.TestCase): 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""" - dtb_file = get_dtb_file('dtoc_test_simple.dts') - output = tools.GetOutputFilename('output') - self.run_test(['struct'], dtb_file, output) - with open(output) as infile: - data = infile.read() - self._check_strings(HEADER + ''' + struct_text = HEADER + ''' struct dtd_sandbox_i2c_test { }; struct dtd_sandbox_pmic_test { @@ -214,12 +207,9 @@ struct dtd_sandbox_spl_test { \tconst char *\tstringarray[3]; \tconst char *\tstringval; }; -''', data) +''' - self.run_test(['platdata'], dtb_file, output) - with open(output) as infile: - data = infile.read() - self._check_strings(C_HEADER + ''' + platdata_text = C_HEADER + ''' /* Node /i2c@0 index 0 */ static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { }; @@ -294,7 +284,23 @@ U_BOOT_DEVICE(spl_test3) = { \t.parent_idx\t= -1, }; -''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) +''' + C_EMPTY_POPULATE_PHANDLE_DATA + + def test_simple(self): + """Test output from some simple nodes with various types of data""" + dtb_file = get_dtb_file('dtoc_test_simple.dts') + output = tools.GetOutputFilename('output') + self.run_test(['struct'], dtb_file, output) + with open(output) as infile: + data = infile.read() + + self._check_strings(self.struct_text, data) + + self.run_test(['platdata'], dtb_file, output) + with open(output) as infile: + data = infile.read() + + self._check_strings(self.platdata_text, data) def test_driver_alias(self): """Test output from a device tree file with a driver alias""" @@ -874,8 +880,9 @@ U_BOOT_DEVICE(spl_test2) = { def test_stdout(self): """Test output to stdout""" dtb_file = get_dtb_file('dtoc_test_simple.dts') - with test_util.capture_sys_output() as _: + with test_util.capture_sys_output() as (stdout, _): self.run_test(['struct'], dtb_file, None) + self._check_strings(self.struct_text, stdout.getvalue()) def test_no_command(self): """Test running dtoc without a command""" -- cgit v1.2.3 From 192c111cfce0684fa1cbbd4a4bd3df03720ef7a6 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:50 -0700 Subject: dtoc: Allow providing a directory to write files to At present dtoc writes only a single file on each invocation. U-Boot writes the two files it needs by separate invocations of dtoc. Since dtoc now scans all U-Boot driver source, this is fairly slow (about 1 second per file). It would be better if dtoc could write all the files at once. In preparation for this, add a way to specify an output directory for the files. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 8 ++++++-- tools/dtoc/main.py | 7 ++++++- tools/dtoc/test_dtoc.py | 14 +++++++------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 118b1a5f43..62a65d6214 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -757,8 +757,9 @@ class DtbPlatdata(): self.out(''.join(self.get_buf())) -def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False, - drivers_additional=None): + +def run_steps(args, dtb_file, include_disabled, output, output_dirs, + warning_disabled=False, drivers_additional=None): """Run all the steps of the dtoc tool Args: @@ -766,6 +767,9 @@ def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False, dtb_file (str): Filename of dtb file to process include_disabled (bool): True to include disabled nodes output (str): Name of output file (None for stdout) + output_dirs (tuple of str): + Directory to put C output files + Directory to put H output files warning_disabled (bool): True to avoid showing warnings about missing drivers drivers_additional (list): List of additional drivers to use during diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py index 7686c8784d..244c184ced 100755 --- a/tools/dtoc/main.py +++ b/tools/dtoc/main.py @@ -87,6 +87,10 @@ if __name__ != '__main__': parser = OptionParser() parser.add_option('-B', '--build-dir', type='string', default='b', help='Directory containing the build output') +parser.add_option('-c', '--c-output-dir', action='store', + help='Select output directory for C files') +parser.add_option('-C', '--h-output-dir', action='store', + help='Select output directory for H files (defaults to --c-output-di)') parser.add_option('-d', '--dtb-file', action='store', help='Specify the .dtb input file') parser.add_option('--include-disabled', action='store_true', @@ -111,4 +115,5 @@ elif options.test_coverage: else: dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled, - options.output) + options.output, + [options.c_output_dir, options.h_output_dir]) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 7cf2a5187c..b023a1e14a 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -122,7 +122,7 @@ class TestDtoc(unittest.TestCase): dtb_file (str): Filename of .dtb file output (str): Filename of output file """ - dtb_platdata.run_steps(args, dtb_file, False, output, True) + dtb_platdata.run_steps(args, dtb_file, False, output, [], True) def test_name(self): """Test conversion of device tree names to C identifiers""" @@ -343,7 +343,7 @@ void dm_populate_phandle_data(void) { dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts') output = tools.GetOutputFilename('output') with test_util.capture_sys_output() as _: - dtb_platdata.run_steps(['struct'], dtb_file, False, output) + dtb_platdata.run_steps(['struct'], dtb_file, False, output, []) with open(output) as infile: data = infile.read() self._check_strings(HEADER + ''' @@ -352,7 +352,7 @@ struct dtd_invalid { ''', data) with test_util.capture_sys_output() as _: - dtb_platdata.run_steps(['platdata'], dtb_file, False, output) + dtb_platdata.run_steps(['platdata'], dtb_file, False, output, []) with open(output) as infile: data = infile.read() self._check_strings(C_HEADER + ''' @@ -508,7 +508,7 @@ void dm_populate_phandle_data(void) { """Test that phandle targets are generated when unsing cd-gpios""" dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts') output = tools.GetOutputFilename('output') - dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True) + dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True) with open(output) as infile: data = infile.read() self._check_strings(C_HEADER + ''' @@ -907,7 +907,7 @@ U_BOOT_DEVICE(spl_test2) = { output = tools.GetOutputFilename('output') with test_util.capture_sys_output() as _: dtb_platdata.run_steps( - ['struct'], dtb_file, False, output, True, + ['struct'], dtb_file, False, output, [], True, [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx']) @staticmethod @@ -925,8 +925,8 @@ U_BOOT_DEVICE(spl_test2) = { fout.write(b'\x81') with test_util.capture_sys_output() as _: - dtb_platdata.run_steps(['struct'], dtb_file, False, output, True, - [driver_fn]) + dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], + True, [driver_fn]) def test_driver(self): """Test the Driver class""" -- cgit v1.2.3 From be44f27156bf46807049a0e1c303626d05f781f8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:51 -0700 Subject: dtoc: Allow outputing to multiple files Implement the 'output directory' feature, allowing dtoc to write the output files separately to the supplied directories. This allows us to handle the struct and platdata output in one run of dtoc. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 96 +++++++++++++++++++++++++++++++++++++++++----- tools/dtoc/test_dtoc.py | 8 ++++ 2 files changed, 94 insertions(+), 10 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 62a65d6214..e2fddfd301 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -15,6 +15,7 @@ See doc/driver-model/of-plat.rst for more informaiton import collections import copy +from enum import IntEnum import os import re import sys @@ -49,6 +50,15 @@ TYPE_NAMES = { STRUCT_PREFIX = 'dtd_' VAL_PREFIX = 'dtv_' +class Ftype(IntEnum): + SOURCE, HEADER = range(2) + + +# This holds information about each type of output file dtoc can create +# type: Type of file (Ftype) +# fname: Filename excluding directory, e.g. 'dt-platdata.c' +OutputFile = collections.namedtuple('OutputFile', ['ftype', 'fname']) + # This holds information about a property which includes phandles. # # max_args: integer: Maximum number or arguments that any phandle uses (int). @@ -180,6 +190,8 @@ class DtbPlatdata(): U_BOOT_DRIVER_ALIAS(driver_alias, driver_name) value: Driver name declared with U_BOOT_DRIVER(driver_name) _drivers_additional: List of additional drivers to use during scanning + _dirname: Directory to hold output files, or None for none (all files + go to stdout) """ def __init__(self, dtb_fname, include_disabled, warning_disabled, drivers_additional=None): @@ -193,6 +205,7 @@ class DtbPlatdata(): self._drivers = {} self._driver_aliases = {} self._drivers_additional = drivers_additional or [] + self._dirnames = [None] * len(Ftype) def get_normalized_compat_name(self, node): """Get a node's normalized compat name @@ -230,20 +243,68 @@ class DtbPlatdata(): return compat_list_c[0], compat_list_c[1:] - def setup_output(self, fname): + def setup_output_dirs(self, output_dirs): + """Set up the output directories + + This should be done before setup_output() is called + + Args: + output_dirs (tuple of str): + Directory to use for C output files. + Use None to write files relative current directory + Directory to use for H output files. + Defaults to the C output dir + """ + def process_dir(ftype, dirname): + if dirname: + os.makedirs(dirname, exist_ok=True) + self._dirnames[ftype] = dirname + + if output_dirs: + c_dirname = output_dirs[0] + h_dirname = output_dirs[1] if len(output_dirs) > 1 else c_dirname + process_dir(Ftype.SOURCE, c_dirname) + process_dir(Ftype.HEADER, h_dirname) + + def setup_output(self, ftype, fname): """Set up the output destination Once this is done, future calls to self.out() will output to this - file. + file. The file used is as follows: + + self._dirnames[ftype] is None: output to fname, or stdout if None + self._dirnames[ftype] is not None: output to fname in that directory + + Calling this function multiple times will close the old file and open + the new one. If they are the same file, nothing happens and output will + continue to the same file. Args: - fname (str): Filename to send output to, or None for stdout + ftype (str): Type of file to create ('c' or 'h') + fname (str): Filename to send output to. If there is a directory in + self._dirnames for this file type, it will be put in that + directory """ - if fname: - self._outfile = open(fname, 'w') + dirname = self._dirnames[ftype] + if dirname: + pathname = os.path.join(dirname, fname) + if self._outfile: + self._outfile.close() + self._outfile = open(pathname, 'w') + elif fname: + if not self._outfile: + self._outfile = open(fname, 'w') else: self._outfile = sys.stdout + def finish_output(self): + """Finish outputing to a file + + This closes the output file, if one is in use + """ + if self._outfile != sys.stdout: + self._outfile.close() + def out(self, line): """Output a string to the output file @@ -758,6 +819,15 @@ class DtbPlatdata(): self.out(''.join(self.get_buf())) +# Types of output file we understand +# key: Command used to generate this file +# value: OutputFile for this command +OUTPUT_FILES = { + 'struct': OutputFile(Ftype.HEADER, 'dt-structs-gen.h'), + 'platdata': OutputFile(Ftype.SOURCE, 'dt-platdata.c'), + } + + def run_steps(args, dtb_file, include_disabled, output, output_dirs, warning_disabled=False, drivers_additional=None): """Run all the steps of the dtoc tool @@ -778,7 +848,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, ValueError: if args has no command, or an unknown command """ if not args: - raise ValueError('Please specify a command: struct, platdata') + raise ValueError('Please specify a command: struct, platdata, all') + if output and output_dirs and any(output_dirs): + raise ValueError('Must specify either output or output_dirs, not both') plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled, drivers_additional) @@ -786,15 +858,19 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, plat.scan_dtb() plat.scan_tree() plat.scan_reg_sizes() - plat.setup_output(output) + plat.setup_output_dirs(output_dirs) structs = plat.scan_structs() plat.scan_phandles() for cmd in args[0].split(','): + outfile = OUTPUT_FILES.get(cmd) + if not outfile: + raise ValueError("Unknown command '%s': (use: %s)" % + (cmd, ', '.join(OUTPUT_FILES.keys()))) + plat.setup_output(outfile.ftype, + outfile.fname if output_dirs else output) if cmd == 'struct': plat.generate_structs(structs) elif cmd == 'platdata': plat.generate_tables() - else: - raise ValueError("Unknown command '%s': (use: struct, platdata)" % - cmd) + plat.finish_output() diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index b023a1e14a..6f9af905e8 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -884,6 +884,14 @@ U_BOOT_DEVICE(spl_test2) = { self.run_test(['struct'], dtb_file, None) self._check_strings(self.struct_text, stdout.getvalue()) + def test_multi_to_file(self): + """Test output of multiple pieces to a single file""" + dtb_file = get_dtb_file('dtoc_test_simple.dts') + output = tools.GetOutputFilename('output') + self.run_test(['struct,platdata'], dtb_file, output) + data = tools.ReadFile(output, binary=False) + self._check_strings(self.struct_text + self.platdata_text, data) + def test_no_command(self): """Test running dtoc without a command""" with self.assertRaises(ValueError) as exc: -- cgit v1.2.3 From 10cbd3b7da12e993c67d56182d30294661a93619 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:52 -0700 Subject: dtoc: Add an 'all' command With upcoming changes, dtoc will output several files for different of-platdata components. Add a way to output all ava!ilable files at once ('all'), to the appropriate directories, without needing to specify each one invidually. This puts the commands in alphabetical order, so update the tests accordingly. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 7 +++++-- tools/dtoc/main.py | 6 +----- tools/dtoc/test_dtoc.py | 40 +++++++++++++++++++++++++++++++++++++--- tools/patman/tools.py | 8 ++++++++ 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index e2fddfd301..7bd1989113 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -862,11 +862,14 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, structs = plat.scan_structs() plat.scan_phandles() - for cmd in args[0].split(','): + cmds = args[0].split(',') + if 'all' in cmds: + cmds = sorted(OUTPUT_FILES.keys()) + for cmd in cmds: outfile = OUTPUT_FILES.get(cmd) if not outfile: raise ValueError("Unknown command '%s': (use: %s)" % - (cmd, ', '.join(OUTPUT_FILES.keys()))) + (cmd, ', '.join(sorted(OUTPUT_FILES.keys())))) plat.setup_output(outfile.ftype, outfile.fname if output_dirs else output) if cmd == 'struct': diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py index 244c184ced..f82ee78268 100755 --- a/tools/dtoc/main.py +++ b/tools/dtoc/main.py @@ -13,11 +13,7 @@ having to link against libfdt. By putting the data from the device tree into C structures, normal C code can be used. This helps to reduce the size of the compiled program. -Dtoc produces two output files: - - dt-structs.h - contains struct definitions - dt-platdata.c - contains data from the device tree using the struct - definitions, as well as U-Boot driver definitions. +Dtoc produces several output files - see OUTPUT_FILES in dtb_platdata.py This tool is used in U-Boot to provide device tree data to SPL without increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 6f9af905e8..fb65f284ce 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -10,6 +10,7 @@ tool. """ import collections +import glob import os import struct import tempfile @@ -302,6 +303,11 @@ U_BOOT_DEVICE(spl_test3) = { self._check_strings(self.platdata_text, data) + # Try the 'all' command + self.run_test(['all'], dtb_file, output) + data = tools.ReadFile(output, binary=False) + self._check_strings(self.platdata_text + self.struct_text, 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') @@ -888,9 +894,9 @@ U_BOOT_DEVICE(spl_test2) = { """Test output of multiple pieces to a single file""" dtb_file = get_dtb_file('dtoc_test_simple.dts') output = tools.GetOutputFilename('output') - self.run_test(['struct,platdata'], dtb_file, output) + self.run_test(['all'], dtb_file, output) data = tools.ReadFile(output, binary=False) - self._check_strings(self.struct_text + self.platdata_text, data) + self._check_strings(self.platdata_text + self.struct_text, data) def test_no_command(self): """Test running dtoc without a command""" @@ -905,7 +911,7 @@ U_BOOT_DEVICE(spl_test2) = { output = tools.GetOutputFilename('output') with self.assertRaises(ValueError) as exc: self.run_test(['invalid-cmd'], dtb_file, output) - self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)", + self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)", str(exc.exception)) @staticmethod @@ -945,3 +951,31 @@ U_BOOT_DEVICE(spl_test2) = { self.assertEqual(drv1, drv3) self.assertNotEqual(drv1, drv2) self.assertNotEqual(drv2, drv3) + + def test_output_conflict(self): + """Test a conflict between and output dirs and output file""" + with self.assertRaises(ValueError) as exc: + dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True) + self.assertIn("Must specify either output or output_dirs, not both", + str(exc.exception)) + + def test_output_dirs(self): + """Test outputting files to a directory""" + # Remove the directory so that files from other tests are not there + tools._RemoveOutputDir() + tools.PrepareOutputDir(None) + + # This should create the .dts and .dtb in the output directory + dtb_file = get_dtb_file('dtoc_test_simple.dts') + outdir = tools.GetOutputDir() + fnames = glob.glob(outdir + '/*') + self.assertEqual(2, len(fnames)) + + dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True) + fnames = glob.glob(outdir + '/*') + self.assertEqual(4, len(fnames)) + + leafs = set(os.path.basename(fname) for fname in fnames) + self.assertEqual( + {'dt-structs-gen.h', 'source.dts', 'dt-platdata.c', 'source.dtb'}, + leafs) diff --git a/tools/patman/tools.py b/tools/patman/tools.py index 00c7013924..ba8b67f3ee 100644 --- a/tools/patman/tools.py +++ b/tools/patman/tools.py @@ -94,6 +94,14 @@ def GetOutputFilename(fname): """ return os.path.join(outdir, fname) +def GetOutputDir(): + """Return the current output directory + + Returns: + str: The output directory + """ + return outdir + def _FinaliseForTest(): """Remove the output directory (for use by tests)""" global outdir -- cgit v1.2.3 From be3bd3bb177ec913050745131687089c1ff69c44 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:53 -0700 Subject: Makefile: Invoke dtoc only once Update the Makefile to run dtoc only once, generating all required files. This saves time since there is a lot of processing in each invocation of dtoc. We already have a variable for the object files to build, so use that instead of repeating the same filenames. Add a C version of this also, for the same reason. This makes it easier to add new C files (generated by dtoc) to the build later, as needed. Signed-off-by: Simon Glass --- scripts/Makefile.spl | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index 161c15b200..3d60cf5120 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -121,6 +121,7 @@ u-boot-spl-init := $(head-y) u-boot-spl-main := $(libs-y) ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA u-boot-spl-platdata := $(obj)/dts/dt-platdata.o +u-boot-spl-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-platdata)) endif # Linker Script @@ -310,17 +311,15 @@ pythonpath = PYTHONPATH=scripts/dtc/pylibfdt DTOC_ARGS := $(pythonpath) $(srctree)/tools/dtoc/dtoc \ -d $(obj)/$(SPL_BIN).dtb -quiet_cmd_dtocc = DTOC C $@ -cmd_dtocc = $(DTOC_ARGS) -o $@ platdata - -quiet_cmd_dtoch = DTOC H $@ -cmd_dtoch = $(DTOC_ARGS) -o $@ struct +quiet_cmd_dtoc = DTOC $@ +cmd_dtoc = $(DTOC_ARGS) -c $(obj)/dts -C include/generated all quiet_cmd_plat = PLAT $@ cmd_plat = $(CC) $(c_flags) -c $< -o $(filter-out $(PHONY),$@) -targets += $(obj)/dts/dt-platdata.o -$(obj)/dts/dt-platdata.o: $(obj)/dts/dt-platdata.c \ +targets += $(u-boot-spl-platdata) + +$(obj)/dts/dt-%.o: $(obj)/dts/dt-%.c \ include/generated/dt-structs-gen.h prepare FORCE $(call if_changed,plat) @@ -328,11 +327,9 @@ PHONY += dts_dir dts_dir: $(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts) -include/generated/dt-structs-gen.h: $(obj)/$(SPL_BIN).dtb dts_dir FORCE - $(call if_changed,dtoch) - -$(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir FORCE - $(call if_changed,dtocc) +include/generated/dt-structs-gen.h $(u-boot-spl-platdata_c) &: \ + $(obj)/$(SPL_BIN).dtb dts_dir FORCE + $(call if_changed,dtoc) ifdef CONFIG_SAMSUNG ifdef CONFIG_VAR_SIZE_SPL -- cgit v1.2.3 From 20e442ab2df355450006574fff178c746d254a18 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:54 -0700 Subject: dm: Rename U_BOOT_DEVICE() to U_BOOT_DRVINFO() The current macro is a misnomer since it does not declare a device directly. Instead, it declares driver_info record which U-Boot uses at runtime to create a device. The distinction seems somewhat minor most of the time, but is becomes quite confusing when we actually want to declare a device, with of-platdata. We are left trying to distinguish between a device which isn't actually device, and a device that is (perhaps an 'instance'?) It seems better to rename this macro to describe what it actually is. The macros is not widely used, since boards should use devicetree to declare devices. Rename it to U_BOOT_DRVINFO(), which indicates clearly that this is declaring a new driver_info record, not a device. Signed-off-by: Simon Glass --- arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c | 2 +- .../mach-at91/arm926ejs/at91sam9m10g45_devices.c | 2 +- arch/arm/mach-imx/mx6/soc.c | 2 +- arch/arm/mach-imx/mx7/soc.c | 2 +- arch/arm/mach-lpc32xx/devices.c | 4 +- arch/arm/mach-omap2/am33xx/board.c | 10 ++-- arch/arm/mach-omap2/omap3/board.c | 2 +- arch/arm/mach-tegra/board.c | 2 +- arch/arm/mach-tegra/board2.c | 2 +- board/armltd/integrator/integrator.c | 2 +- board/armltd/total_compute/total_compute.c | 2 +- board/armltd/vexpress64/vexpress64.c | 2 +- board/bluewater/gurnard/gurnard.c | 2 +- board/bluewater/snapper9260/snapper9260.c | 2 +- board/cadence/xtfpga/xtfpga.c | 4 +- board/cavium/thunderx/thunderx.c | 4 +- board/compulab/cm_fx6/cm_fx6.c | 2 +- board/davinci/da8xxevm/omapl138_lcdk.c | 4 +- board/freescale/ls1012afrdm/eth.c | 4 +- board/freescale/ls1012aqds/eth.c | 4 +- board/freescale/ls1012ardb/eth.c | 4 +- board/freescale/lx2160a/lx2160a.c | 4 +- board/gateworks/gw_ventana/gw_ventana.c | 2 +- board/hisilicon/hikey/hikey.c | 4 +- board/hisilicon/hikey960/hikey960.c | 2 +- board/hisilicon/poplar/poplar.c | 2 +- board/isee/igep00x0/igep00x0.c | 2 +- board/lg/sniper/sniper.c | 2 +- board/nokia/rx51/rx51.c | 2 +- board/sandbox/sandbox.c | 2 +- board/siemens/corvus/board.c | 2 +- board/st/stv0991/stv0991.c | 2 +- board/sysam/amcore/amcore.c | 2 +- board/ti/am335x/board.c | 6 +- board/timll/devkit8000/devkit8000.c | 2 +- board/toradex/apalis_imx6/apalis_imx6.c | 2 +- board/toradex/colibri-imx6ull/colibri-imx6ull.c | 2 +- board/toradex/colibri_imx6/colibri_imx6.c | 2 +- board/toradex/colibri_pxa270/colibri_pxa270.c | 4 +- doc/driver-model/design.rst | 18 +++--- doc/driver-model/of-plat.rst | 12 ++-- doc/driver-model/remoteproc-framework.rst | 2 +- doc/driver-model/spi-howto.rst | 4 +- drivers/crypto/fsl/fsl_rsa.c | 2 +- drivers/crypto/rsa_mod_exp/mod_exp_sw.c | 2 +- drivers/demo/demo-pdata.c | 10 ++-- drivers/gpio/imx_rgpio2p.c | 4 +- drivers/gpio/mxc_gpio.c | 2 +- drivers/remoteproc/sandbox_testproc.c | 2 +- drivers/rtc/emul_rtc.c | 2 +- drivers/serial/sandbox.c | 2 +- drivers/sysreset/sysreset_sandbox.c | 4 +- drivers/timer/sandbox_timer.c | 2 +- drivers/video/sunxi/sunxi_de2.c | 2 +- drivers/video/sunxi/sunxi_dw_hdmi.c | 2 +- drivers/video/sunxi/sunxi_lcd.c | 2 +- dts/Kconfig | 8 +-- include/dm/device.h | 4 +- include/dm/lists.h | 2 +- include/dm/platdata.h | 16 +++--- include/dm/platform_data/spi_pl022.h | 2 +- test/dm/core.c | 6 +- tools/dtoc/dtb_platdata.py | 8 +-- tools/dtoc/test_dtoc.py | 66 +++++++++++----------- 64 files changed, 148 insertions(+), 148 deletions(-) diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c index 9d787197f3..c10571fa28 100644 --- a/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c +++ b/arch/arm/mach-at91/arm926ejs/at91sam9260_devices.c @@ -219,7 +219,7 @@ static const struct at91_port_plat at91sam9260_plat[] = { { ATMEL_BASE_PIOC, "PC" }, }; -U_BOOT_DEVICES(at91sam9260_gpios) = { +U_BOOT_DRVINFOS(at91sam9260_gpios) = { { "atmel_at91rm9200_gpio", &at91sam9260_plat[0] }, { "atmel_at91rm9200_gpio", &at91sam9260_plat[1] }, { "atmel_at91rm9200_gpio", &at91sam9260_plat[2] }, diff --git a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c index f503553b92..d517810c99 100644 --- a/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c +++ b/arch/arm/mach-at91/arm926ejs/at91sam9m10g45_devices.c @@ -175,7 +175,7 @@ static const struct at91_port_plat at91sam9260_plat[] = { { ATMEL_BASE_PIOE, "PE" }, }; -U_BOOT_DEVICES(at91sam9260_gpios) = { +U_BOOT_DRVINFOS(at91sam9260_gpios) = { { "atmel_at91rm9200_gpio", &at91sam9260_plat[0] }, { "atmel_at91rm9200_gpio", &at91sam9260_plat[1] }, { "atmel_at91rm9200_gpio", &at91sam9260_plat[2] }, diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c index 1649f6d948..bf6dddfdc9 100644 --- a/arch/arm/mach-imx/mx6/soc.c +++ b/arch/arm/mach-imx/mx6/soc.c @@ -44,7 +44,7 @@ static const struct imx_thermal_plat imx6_thermal_plat = { .fuse_word = 6, }; -U_BOOT_DEVICE(imx6_thermal) = { +U_BOOT_DRVINFO(imx6_thermal) = { .name = "imx_thermal", .plat = &imx6_thermal_plat, }; diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c index 13593994f1..fda25ba66a 100644 --- a/arch/arm/mach-imx/mx7/soc.c +++ b/arch/arm/mach-imx/mx7/soc.c @@ -60,7 +60,7 @@ static const struct imx_thermal_plat imx7_thermal_plat = { .fuse_word = 3, }; -U_BOOT_DEVICE(imx7_thermal) = { +U_BOOT_DRVINFO(imx7_thermal) = { .name = "imx_thermal", .plat = &imx7_thermal_plat, }; diff --git a/arch/arm/mach-lpc32xx/devices.c b/arch/arm/mach-lpc32xx/devices.c index 04e026a8b7..e1e2e0d094 100644 --- a/arch/arm/mach-lpc32xx/devices.c +++ b/arch/arm/mach-lpc32xx/devices.c @@ -62,7 +62,7 @@ static const struct lpc32xx_hsuart_plat lpc32xx_hsuart[] = { }; #endif -U_BOOT_DEVICES(lpc32xx_uarts) = { +U_BOOT_DRVINFOS(lpc32xx_uarts) = { #if defined(CONFIG_LPC32XX_HSUART) { "lpc32xx_hsuart", &lpc32xx_hsuart[0], }, { "lpc32xx_hsuart", &lpc32xx_hsuart[1], }, @@ -124,7 +124,7 @@ void lpc32xx_i2c_init(unsigned int devnum) writel(ctrl, &clk->i2cclk_ctrl); } -U_BOOT_DEVICE(lpc32xx_gpios) = { +U_BOOT_DRVINFO(lpc32xx_gpios) = { .name = "gpio_lpc32xx" }; diff --git a/arch/arm/mach-omap2/am33xx/board.c b/arch/arm/mach-omap2/am33xx/board.c index b5f2b75e24..e17898d8fb 100644 --- a/arch/arm/mach-omap2/am33xx/board.c +++ b/arch/arm/mach-omap2/am33xx/board.c @@ -99,7 +99,7 @@ static const struct ns16550_plat am33xx_serial[] = { # endif }; -U_BOOT_DEVICES(am33xx_uarts) = { +U_BOOT_DRVINFOS(am33xx_uarts) = { { "ns16550_serial", &am33xx_serial[0] }, # ifdef CONFIG_SYS_NS16550_COM2 { "ns16550_serial", &am33xx_serial[1] }, @@ -119,7 +119,7 @@ static const struct omap_i2c_plat am33xx_i2c[] = { { I2C_BASE3, 100000, OMAP_I2C_REV_V2}, }; -U_BOOT_DEVICES(am33xx_i2c) = { +U_BOOT_DRVINFOS(am33xx_i2c) = { { "i2c_omap", &am33xx_i2c[0] }, { "i2c_omap", &am33xx_i2c[1] }, { "i2c_omap", &am33xx_i2c[2] }, @@ -138,7 +138,7 @@ static const struct omap_gpio_plat am33xx_gpio[] = { #endif }; -U_BOOT_DEVICES(am33xx_gpios) = { +U_BOOT_DRVINFOS(am33xx_gpios) = { { "gpio_omap", &am33xx_gpio[0] }, { "gpio_omap", &am33xx_gpio[1] }, { "gpio_omap", &am33xx_gpio[2] }, @@ -155,7 +155,7 @@ static const struct omap3_spi_plat omap3_spi_pdata = { .pin_dir = MCSPI_PINDIR_D0_IN_D1_OUT, }; -U_BOOT_DEVICE(am33xx_spi) = { +U_BOOT_DRVINFO(am33xx_spi) = { .name = "omap3_spi", .plat = &omap3_spi_pdata, }; @@ -234,7 +234,7 @@ static struct ti_musb_plat usb1 = { }, }; -U_BOOT_DEVICES(am33xx_usbs) = { +U_BOOT_DRVINFOS(am33xx_usbs) = { #if CONFIG_AM335X_USB0_MODE == MUSB_PERIPHERAL { "ti-musb-peripheral", &usb0 }, #elif CONFIG_AM335X_USB0_MODE == MUSB_HOST diff --git a/arch/arm/mach-omap2/omap3/board.c b/arch/arm/mach-omap2/omap3/board.c index 6ffedd1769..4da8df47cc 100644 --- a/arch/arm/mach-omap2/omap3/board.c +++ b/arch/arm/mach-omap2/omap3/board.c @@ -47,7 +47,7 @@ static const struct omap_gpio_plat omap34xx_gpio[] = { { 5, OMAP34XX_GPIO6_BASE }, }; -U_BOOT_DEVICES(omap34xx_gpios) = { +U_BOOT_DRVINFOS(omap34xx_gpios) = { { "gpio_omap", &omap34xx_gpio[0] }, { "gpio_omap", &omap34xx_gpio[1] }, { "gpio_omap", &omap34xx_gpio[2] }, diff --git a/arch/arm/mach-tegra/board.c b/arch/arm/mach-tegra/board.c index bf01aa5ee8..9de9836c8d 100644 --- a/arch/arm/mach-tegra/board.c +++ b/arch/arm/mach-tegra/board.c @@ -264,7 +264,7 @@ static struct ns16550_plat ns16550_com1_pdata = { .fcr = UART_FCR_DEFVAL, }; -U_BOOT_DEVICE(ns16550_com1) = { +U_BOOT_DRVINFO(ns16550_com1) = { "ns16550_serial", &ns16550_com1_pdata }; #endif diff --git a/arch/arm/mach-tegra/board2.c b/arch/arm/mach-tegra/board2.c index 48c4f32d6f..8569ad7c6f 100644 --- a/arch/arm/mach-tegra/board2.c +++ b/arch/arm/mach-tegra/board2.c @@ -42,7 +42,7 @@ DECLARE_GLOBAL_DATA_PTR; #ifdef CONFIG_SPL_BUILD /* TODO(sjg@chromium.org): Remove once SPL supports device tree */ -U_BOOT_DEVICE(tegra_gpios) = { +U_BOOT_DRVINFO(tegra_gpios) = { "gpio_tegra" }; #endif diff --git a/board/armltd/integrator/integrator.c b/board/armltd/integrator/integrator.c index 21bea62e9b..3c56fa1c01 100644 --- a/board/armltd/integrator/integrator.c +++ b/board/armltd/integrator/integrator.c @@ -43,7 +43,7 @@ static const struct pl01x_serial_plat serial_plat = { #endif }; -U_BOOT_DEVICE(integrator_serials) = { +U_BOOT_DRVINFO(integrator_serials) = { .name = "serial_pl01x", .plat = &serial_plat, }; diff --git a/board/armltd/total_compute/total_compute.c b/board/armltd/total_compute/total_compute.c index 6263d0c361..da24b32333 100644 --- a/board/armltd/total_compute/total_compute.c +++ b/board/armltd/total_compute/total_compute.c @@ -15,7 +15,7 @@ static const struct pl01x_serial_plat serial_plat = { .clock = CONFIG_PL011_CLOCK, }; -U_BOOT_DEVICE(total_compute_serials) = { +U_BOOT_DRVINFO(total_compute_serials) = { .name = "serial_pl01x", .plat = &serial_plat, }; diff --git a/board/armltd/vexpress64/vexpress64.c b/board/armltd/vexpress64/vexpress64.c index 6df6bcd3cf..bd66d52cb7 100644 --- a/board/armltd/vexpress64/vexpress64.c +++ b/board/armltd/vexpress64/vexpress64.c @@ -26,7 +26,7 @@ static const struct pl01x_serial_plat serial_plat = { .clock = CONFIG_PL011_CLOCK, }; -U_BOOT_DEVICE(vexpress_serials) = { +U_BOOT_DRVINFO(vexpress_serials) = { .name = "serial_pl01x", .plat = &serial_plat, }; diff --git a/board/bluewater/gurnard/gurnard.c b/board/bluewater/gurnard/gurnard.c index a71b4eb733..17ecdb679e 100644 --- a/board/bluewater/gurnard/gurnard.c +++ b/board/bluewater/gurnard/gurnard.c @@ -420,7 +420,7 @@ static struct atmel_serial_plat at91sam9260_serial_plat = { .base_addr = ATMEL_BASE_DBGU, }; -U_BOOT_DEVICE(at91sam9260_serial) = { +U_BOOT_DRVINFO(at91sam9260_serial) = { .name = "serial_atmel", .plat = &at91sam9260_serial_plat, }; diff --git a/board/bluewater/snapper9260/snapper9260.c b/board/bluewater/snapper9260/snapper9260.c index 9e41a42263..58fab15c11 100644 --- a/board/bluewater/snapper9260/snapper9260.c +++ b/board/bluewater/snapper9260/snapper9260.c @@ -147,7 +147,7 @@ static struct atmel_serial_plat at91sam9260_serial_plat = { .base_addr = ATMEL_BASE_DBGU, }; -U_BOOT_DEVICE(at91sam9260_serial) = { +U_BOOT_DRVINFO(at91sam9260_serial) = { .name = "serial_atmel", .plat = &at91sam9260_serial_plat, }; diff --git a/board/cadence/xtfpga/xtfpga.c b/board/cadence/xtfpga/xtfpga.c index 29db51b026..c26793d76c 100644 --- a/board/cadence/xtfpga/xtfpga.c +++ b/board/cadence/xtfpga/xtfpga.c @@ -93,7 +93,7 @@ int misc_init_r(void) return 0; } -U_BOOT_DEVICE(sysreset) = { +U_BOOT_DRVINFO(sysreset) = { .name = "xtfpga_sysreset", }; @@ -104,7 +104,7 @@ static struct ethoc_eth_pdata ethoc_pdata = { .packet_base = CONFIG_SYS_ETHOC_BUFFER_ADDR, }; -U_BOOT_DEVICE(ethoc) = { +U_BOOT_DRVINFO(ethoc) = { .name = "ethoc", .plat = ðoc_pdata, }; diff --git a/board/cavium/thunderx/thunderx.c b/board/cavium/thunderx/thunderx.c index 22c4c72361..fd23472898 100644 --- a/board/cavium/thunderx/thunderx.c +++ b/board/cavium/thunderx/thunderx.c @@ -25,7 +25,7 @@ static const struct pl01x_serial_plat serial0 = { .skip_init = true, }; -U_BOOT_DEVICE(thunderx_serial0) = { +U_BOOT_DRVINFO(thunderx_serial0) = { .name = "serial_pl01x", .plat = &serial0, }; @@ -37,7 +37,7 @@ static const struct pl01x_serial_plat serial1 = { .skip_init = true, }; -U_BOOT_DEVICE(thunderx_serial1) = { +U_BOOT_DRVINFO(thunderx_serial1) = { .name = "serial_pl01x", .plat = &serial1, }; diff --git a/board/compulab/cm_fx6/cm_fx6.c b/board/compulab/cm_fx6/cm_fx6.c index bc3ce4d16c..7520e96e07 100644 --- a/board/compulab/cm_fx6/cm_fx6.c +++ b/board/compulab/cm_fx6/cm_fx6.c @@ -728,7 +728,7 @@ static struct mxc_serial_plat cm_fx6_mxc_serial_plat = { .reg = (struct mxc_uart *)UART4_BASE, }; -U_BOOT_DEVICE(cm_fx6_serial) = { +U_BOOT_DRVINFO(cm_fx6_serial) = { .name = "serial_mxc", .plat = &cm_fx6_mxc_serial_plat, }; diff --git a/board/davinci/da8xxevm/omapl138_lcdk.c b/board/davinci/da8xxevm/omapl138_lcdk.c index a8ece170ce..a08858550d 100644 --- a/board/davinci/da8xxevm/omapl138_lcdk.c +++ b/board/davinci/da8xxevm/omapl138_lcdk.c @@ -363,7 +363,7 @@ static const struct ns16550_plat serial_pdata = { .fcr = UART_FCR_DEFVAL, }; -U_BOOT_DEVICE(omapl138_uart) = { +U_BOOT_DRVINFO(omapl138_uart) = { .name = "ns16550_serial", .plat = &serial_pdata, }; @@ -379,7 +379,7 @@ static const struct davinci_mmc_plat mmc_plat = { .name = "da830-mmc", }, }; -U_BOOT_DEVICE(omapl138_mmc) = { +U_BOOT_DRVINFO(omapl138_mmc) = { .name = "ti_da830_mmc", .plat = &mmc_plat, }; diff --git a/board/freescale/ls1012afrdm/eth.c b/board/freescale/ls1012afrdm/eth.c index 85104ab22c..d2df9351ea 100644 --- a/board/freescale/ls1012afrdm/eth.c +++ b/board/freescale/ls1012afrdm/eth.c @@ -114,12 +114,12 @@ static struct pfe_eth_pdata pfe_pdata1 = { }, }; -U_BOOT_DEVICE(ls1012a_pfe0) = { +U_BOOT_DRVINFO(ls1012a_pfe0) = { .name = "pfe_eth", .plat = &pfe_pdata0, }; -U_BOOT_DEVICE(ls1012a_pfe1) = { +U_BOOT_DRVINFO(ls1012a_pfe1) = { .name = "pfe_eth", .plat = &pfe_pdata1, }; diff --git a/board/freescale/ls1012aqds/eth.c b/board/freescale/ls1012aqds/eth.c index f6f43d2b13..8189f41bec 100644 --- a/board/freescale/ls1012aqds/eth.c +++ b/board/freescale/ls1012aqds/eth.c @@ -298,12 +298,12 @@ static struct pfe_eth_pdata pfe_pdata1 = { }, }; -U_BOOT_DEVICE(ls1012a_pfe0) = { +U_BOOT_DRVINFO(ls1012a_pfe0) = { .name = "pfe_eth", .plat = &pfe_pdata0, }; -U_BOOT_DEVICE(ls1012a_pfe1) = { +U_BOOT_DRVINFO(ls1012a_pfe1) = { .name = "pfe_eth", .plat = &pfe_pdata1, }; diff --git a/board/freescale/ls1012ardb/eth.c b/board/freescale/ls1012ardb/eth.c index 5e923e5252..2241d061dd 100644 --- a/board/freescale/ls1012ardb/eth.c +++ b/board/freescale/ls1012ardb/eth.c @@ -160,12 +160,12 @@ static struct pfe_eth_pdata pfe_pdata1 = { }, }; -U_BOOT_DEVICE(ls1012a_pfe0) = { +U_BOOT_DRVINFO(ls1012a_pfe0) = { .name = "pfe_eth", .plat = &pfe_pdata0, }; -U_BOOT_DEVICE(ls1012a_pfe1) = { +U_BOOT_DRVINFO(ls1012a_pfe1) = { .name = "pfe_eth", .plat = &pfe_pdata1, }; diff --git a/board/freescale/lx2160a/lx2160a.c b/board/freescale/lx2160a/lx2160a.c index 8d0115eace..70dd34e7ce 100644 --- a/board/freescale/lx2160a/lx2160a.c +++ b/board/freescale/lx2160a/lx2160a.c @@ -62,7 +62,7 @@ static struct pl01x_serial_plat serial0 = { .type = TYPE_PL011, }; -U_BOOT_DEVICE(nxp_serial0) = { +U_BOOT_DRVINFO(nxp_serial0) = { .name = "serial_pl01x", .plat = &serial0, }; @@ -72,7 +72,7 @@ static struct pl01x_serial_plat serial1 = { .type = TYPE_PL011, }; -U_BOOT_DEVICE(nxp_serial1) = { +U_BOOT_DRVINFO(nxp_serial1) = { .name = "serial_pl01x", .plat = &serial1, }; diff --git a/board/gateworks/gw_ventana/gw_ventana.c b/board/gateworks/gw_ventana/gw_ventana.c index c7224d1efe..048f624c35 100644 --- a/board/gateworks/gw_ventana/gw_ventana.c +++ b/board/gateworks/gw_ventana/gw_ventana.c @@ -1375,7 +1375,7 @@ static struct mxc_serial_plat ventana_mxc_serial_plat = { .reg = (struct mxc_uart *)UART2_BASE, }; -U_BOOT_DEVICE(ventana_serial) = { +U_BOOT_DRVINFO(ventana_serial) = { .name = "serial_mxc", .plat = &ventana_mxc_serial_plat, }; diff --git a/board/hisilicon/hikey/hikey.c b/board/hisilicon/hikey/hikey.c index 0ac88306d0..65a8179adb 100644 --- a/board/hisilicon/hikey/hikey.c +++ b/board/hisilicon/hikey/hikey.c @@ -50,7 +50,7 @@ static const struct hikey_gpio_plat hi6220_gpio[] = { }; -U_BOOT_DEVICES(hi6220_gpios) = { +U_BOOT_DRVINFOS(hi6220_gpios) = { { "gpio_hi6220", &hi6220_gpio[0] }, { "gpio_hi6220", &hi6220_gpio[1] }, { "gpio_hi6220", &hi6220_gpio[2] }, @@ -89,7 +89,7 @@ static const struct pl01x_serial_plat serial_plat = { .clock = 19200000 }; -U_BOOT_DEVICE(hikey_seriala) = { +U_BOOT_DRVINFO(hikey_seriala) = { .name = "serial_pl01x", .plat = &serial_plat, }; diff --git a/board/hisilicon/hikey960/hikey960.c b/board/hisilicon/hikey960/hikey960.c index 04b8cde136..3fe4c60d02 100644 --- a/board/hisilicon/hikey960/hikey960.c +++ b/board/hisilicon/hikey960/hikey960.c @@ -32,7 +32,7 @@ static const struct pl01x_serial_plat serial_plat = { .clock = 19200000 }; -U_BOOT_DEVICE(hikey960_serial0) = { +U_BOOT_DRVINFO(hikey960_serial0) = { .name = "serial_pl01x", .plat = &serial_plat, }; diff --git a/board/hisilicon/poplar/poplar.c b/board/hisilicon/poplar/poplar.c index b8be4ce45a..bfb2c66a17 100644 --- a/board/hisilicon/poplar/poplar.c +++ b/board/hisilicon/poplar/poplar.c @@ -46,7 +46,7 @@ static const struct pl01x_serial_plat serial_plat = { .clock = 75000000, }; -U_BOOT_DEVICE(poplar_serial) = { +U_BOOT_DRVINFO(poplar_serial) = { .name = "serial_pl01x", .plat = &serial_plat, }; diff --git a/board/isee/igep00x0/igep00x0.c b/board/isee/igep00x0/igep00x0.c index 6a7da502dd..0932f62b9b 100644 --- a/board/isee/igep00x0/igep00x0.c +++ b/board/isee/igep00x0/igep00x0.c @@ -36,7 +36,7 @@ static const struct ns16550_plat igep_serial = { .fcr = UART_FCR_DEFVAL, }; -U_BOOT_DEVICE(igep_uart) = { +U_BOOT_DRVINFO(igep_uart) = { "ns16550_serial", &igep_serial }; diff --git a/board/lg/sniper/sniper.c b/board/lg/sniper/sniper.c index d11630b954..118ab269d6 100644 --- a/board/lg/sniper/sniper.c +++ b/board/lg/sniper/sniper.c @@ -37,7 +37,7 @@ static const struct ns16550_plat serial_omap_plat = { .fcr = UART_FCR_DEFVAL, }; -U_BOOT_DEVICE(sniper_serial) = { +U_BOOT_DRVINFO(sniper_serial) = { .name = "ns16550_serial", .plat = &serial_omap_plat }; diff --git a/board/nokia/rx51/rx51.c b/board/nokia/rx51/rx51.c index bafb6205bd..253ee3c7b2 100644 --- a/board/nokia/rx51/rx51.c +++ b/board/nokia/rx51/rx51.c @@ -709,7 +709,7 @@ static const struct omap_i2c_plat rx51_i2c[] = { { I2C_BASE3, 400000, OMAP_I2C_REV_V1 }, }; -U_BOOT_DEVICES(rx51_i2c) = { +U_BOOT_DRVINFOS(rx51_i2c) = { { "i2c_omap", &rx51_i2c[0] }, { "i2c_omap", &rx51_i2c[1] }, { "i2c_omap", &rx51_i2c[2] }, diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c index 3235541a7d..d152703b15 100644 --- a/board/sandbox/sandbox.c +++ b/board/sandbox/sandbox.c @@ -23,7 +23,7 @@ gd_t *gd; #if !CONFIG_IS_ENABLED(OF_PLATDATA) /* Add a simple GPIO device */ -U_BOOT_DEVICE(gpio_sandbox) = { +U_BOOT_DRVINFO(gpio_sandbox) = { .name = "sandbox_gpio", }; #endif diff --git a/board/siemens/corvus/board.c b/board/siemens/corvus/board.c index 1613c44929..25d85a8f17 100644 --- a/board/siemens/corvus/board.c +++ b/board/siemens/corvus/board.c @@ -318,7 +318,7 @@ static struct atmel_serial_plat at91sam9260_serial_plat = { .base_addr = ATMEL_BASE_DBGU, }; -U_BOOT_DEVICE(at91sam9260_serial) = { +U_BOOT_DRVINFO(at91sam9260_serial) = { .name = "serial_atmel", .plat = &at91sam9260_serial_plat, }; diff --git a/board/st/stv0991/stv0991.c b/board/st/stv0991/stv0991.c index 3371973600..95e203ff0e 100644 --- a/board/st/stv0991/stv0991.c +++ b/board/st/stv0991/stv0991.c @@ -30,7 +30,7 @@ static const struct pl01x_serial_plat serial_plat = { .clock = 2700 * 1000, }; -U_BOOT_DEVICE(stv09911_serials) = { +U_BOOT_DRVINFO(stv09911_serials) = { .name = "serial_pl01x", .plat = &serial_plat, }; diff --git a/board/sysam/amcore/amcore.c b/board/sysam/amcore/amcore.c index 42e1a80ec5..65fc60e2b4 100644 --- a/board/sysam/amcore/amcore.c +++ b/board/sysam/amcore/amcore.c @@ -113,7 +113,7 @@ static struct coldfire_serial_plat mcf5307_serial_plat = { .baudrate = CONFIG_BAUDRATE, }; -U_BOOT_DEVICE(coldfire_serial) = { +U_BOOT_DRVINFO(coldfire_serial) = { .name = "serial_coldfire", .plat = &mcf5307_serial_plat, }; diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c index 2aa385a937..40d2e0238f 100644 --- a/board/ti/am335x/board.c +++ b/board/ti/am335x/board.c @@ -927,7 +927,7 @@ struct eth_pdata cpsw_pdata = { .priv_pdata = &am335_eth_data, }; -U_BOOT_DEVICE(am335x_eth) = { +U_BOOT_DRVINFO(am335x_eth) = { .name = "eth_cpsw", .plat = &cpsw_pdata, }; @@ -972,7 +972,7 @@ static const struct omap_hsmmc_plat am335x_mmc0_plat = { .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT, }; -U_BOOT_DEVICE(am335x_mmc0) = { +U_BOOT_DRVINFO(am335x_mmc0) = { .name = "omap_hsmmc", .plat = &am335x_mmc0_plat, }; @@ -986,7 +986,7 @@ static const struct omap_hsmmc_plat am335x_mmc1_plat = { .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT, }; -U_BOOT_DEVICE(am335x_mmc1) = { +U_BOOT_DRVINFO(am335x_mmc1) = { .name = "omap_hsmmc", .plat = &am335x_mmc1_plat, }; diff --git a/board/timll/devkit8000/devkit8000.c b/board/timll/devkit8000/devkit8000.c index 875383625d..0731fb7645 100644 --- a/board/timll/devkit8000/devkit8000.c +++ b/board/timll/devkit8000/devkit8000.c @@ -54,7 +54,7 @@ static const struct ns16550_plat devkit8000_serial = { .fcr = UART_FCR_DEFVAL, }; -U_BOOT_DEVICE(devkit8000_uart) = { +U_BOOT_DRVINFO(devkit8000_uart) = { "ns16550_serial", &devkit8000_serial }; diff --git a/board/toradex/apalis_imx6/apalis_imx6.c b/board/toradex/apalis_imx6/apalis_imx6.c index 362a750b19..5ae5274584 100644 --- a/board/toradex/apalis_imx6/apalis_imx6.c +++ b/board/toradex/apalis_imx6/apalis_imx6.c @@ -1149,7 +1149,7 @@ static struct mxc_serial_plat mxc_serial_plat = { .use_dte = true, }; -U_BOOT_DEVICE(mxc_serial) = { +U_BOOT_DRVINFO(mxc_serial) = { .name = "serial_mxc", .plat = &mxc_serial_plat, }; diff --git a/board/toradex/colibri-imx6ull/colibri-imx6ull.c b/board/toradex/colibri-imx6ull/colibri-imx6ull.c index 056064f6b9..6ff55ce57b 100644 --- a/board/toradex/colibri-imx6ull/colibri-imx6ull.c +++ b/board/toradex/colibri-imx6ull/colibri-imx6ull.c @@ -208,7 +208,7 @@ static struct mxc_serial_plat mxc_serial_plat = { .use_dte = 1, }; -U_BOOT_DEVICE(mxc_serial) = { +U_BOOT_DRVINFO(mxc_serial) = { .name = "serial_mxc", .plat = &mxc_serial_plat, }; diff --git a/board/toradex/colibri_imx6/colibri_imx6.c b/board/toradex/colibri_imx6/colibri_imx6.c index a82daad739..57d3e526b4 100644 --- a/board/toradex/colibri_imx6/colibri_imx6.c +++ b/board/toradex/colibri_imx6/colibri_imx6.c @@ -1091,7 +1091,7 @@ static struct mxc_serial_plat mxc_serial_plat = { .use_dte = true, }; -U_BOOT_DEVICE(mxc_serial) = { +U_BOOT_DRVINFO(mxc_serial) = { .name = "serial_mxc", .plat = &mxc_serial_plat, }; diff --git a/board/toradex/colibri_pxa270/colibri_pxa270.c b/board/toradex/colibri_pxa270/colibri_pxa270.c index b9d0fb98af..645751a37e 100644 --- a/board/toradex/colibri_pxa270/colibri_pxa270.c +++ b/board/toradex/colibri_pxa270/colibri_pxa270.c @@ -133,7 +133,7 @@ static const struct pxa_mmc_plat mmc_plat = { .base = (struct pxa_mmc_regs *)MMC0_BASE, }; -U_BOOT_DEVICE(pxa_mmcs) = { +U_BOOT_DRVINFO(pxa_mmcs) = { .name = "pxa_mmc", .plat = &mmc_plat, }; @@ -146,7 +146,7 @@ static const struct pxa_serial_plat serial_plat = { .baudrate = CONFIG_BAUDRATE, }; -U_BOOT_DEVICE(pxa_serials) = { +U_BOOT_DRVINFO(pxa_serials) = { .name = "serial_pxa", .plat = &serial_plat, }; diff --git a/doc/driver-model/design.rst b/doc/driver-model/design.rst index f26e4f14df..ffed7d5f79 100644 --- a/doc/driver-model/design.rst +++ b/doc/driver-model/design.rst @@ -422,7 +422,7 @@ Device Tree While plat is useful, a more flexible way of providing device data is by using device tree. In U-Boot you should use this where possible. Avoid -sending patches which make use of the U_BOOT_DEVICE() macro unless strictly +sending patches which make use of the U_BOOT_DRVINFO() macro unless strictly necessary. With device tree we replace the above code with the following device tree @@ -436,7 +436,7 @@ fragment: sides = <4>; }; -This means that instead of having lots of U_BOOT_DEVICE() declarations in +This means that instead of having lots of U_BOOT_DRVINFO() declarations in the board file, we put these in the device tree. This approach allows a lot more generality, since the same board file can support many types of boards (e,g. with the same SoC) just by using different device trees. An added @@ -665,9 +665,9 @@ Bind stage U-Boot discovers devices using one of these two methods: -- Scan the U_BOOT_DEVICE() definitions. U-Boot looks up the name specified +- Scan the U_BOOT_DRVINFO() definitions. U-Boot looks up the name specified by each, to find the appropriate U_BOOT_DRIVER() definition. In this case, - there is no path by which driver_data may be provided, but the U_BOOT_DEVICE() + there is no path by which driver_data may be provided, but the U_BOOT_DRVINFO() may provide plat. - Scan through the device tree definitions. U-Boot looks at top-level @@ -685,7 +685,7 @@ driver's bind() method if one is defined. At this point all the devices are known, and bound to their drivers. There is a 'struct udevice' allocated for all devices. However, nothing has been activated (except for the root device). Each bound device that was created -from a U_BOOT_DEVICE() declaration will hold the plat pointer specified +from a U_BOOT_DRVINFO() declaration will hold the plat pointer specified in that declaration. For a bound device created from the device tree, plat will be NULL, but of_offset will be the offset of the device tree node that caused the device to be created. The uclass is set correctly for @@ -726,7 +726,7 @@ The steps are: 2. If plat_auto is non-zero, then the platform data space is allocated. This is only useful for device tree operation, since otherwise you would have to specific the platform data in the - U_BOOT_DEVICE() declaration. The space is allocated for the device and + U_BOOT_DRVINFO() declaration. The space is allocated for the device and zeroed. It will be accessible as dev->plat. 3. If the device's uclass specifies a non-zero per_device_auto, @@ -746,7 +746,7 @@ The steps are: do various calls like dev_read_u32(dev, ...) to access the node and store the resulting information into dev->plat. After this point, the device works the same way whether it was bound using a device tree node or - U_BOOT_DEVICE() structure. In either case, the platform data is now stored + U_BOOT_DRVINFO() structure. In either case, the platform data is now stored in the plat structure. Typically you will use the plat_auto feature to specify the size of the platform data structure, and U-Boot will automatically allocate and zero it for you before @@ -855,7 +855,7 @@ remove it. This performs the probe steps in reverse: 4. The device memory is freed (platform data, private data, uclass data, parent data). - Note: Because the platform data for a U_BOOT_DEVICE() is defined with a + Note: Because the platform data for a U_BOOT_DRVINFO() is defined with a static pointer, it is not de-allocated during the remove() method. For a device instantiated using the device tree data, the platform data will be dynamically allocated, and thus needs to be deallocated during the @@ -931,7 +931,7 @@ property can provide better control granularity on which device is bound before relocation. While with DM_FLAG_PRE_RELOC flag of the driver all devices with the same driver are bound, which requires allocation a large amount of memory. When device tree is not used, DM_FLAG_PRE_RELOC is the -only way for statically declared devices via U_BOOT_DEVICE() to be bound +only way for statically declared devices via U_BOOT_DRVINFO() to be bound prior to relocation. It is possible to limit this to specific relocation steps, by using diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst index afa27c211c..39e6295aa0 100644 --- a/doc/driver-model/of-plat.rst +++ b/doc/driver-model/of-plat.rst @@ -21,7 +21,7 @@ SoCs require a 16KB SPL image which must include a full MMC stack. In this case the overhead of device tree access may be too great. It is possible to create platform data manually by defining C structures -for it, and reference that data in a U_BOOT_DEVICE() declaration. This +for it, and reference that data in a U_BOOT_DRVINFO() declaration. This bypasses the use of device tree completely, effectively creating a parallel configuration mechanism. But it is an available option for SPL. @@ -79,7 +79,7 @@ SPL/TPL and should be tested with: A new tool called 'dtoc' converts a device tree file either into a set of struct declarations, one for each compatible node, and a set of -U_BOOT_DEVICE() declarations along with the actual platform data for each +U_BOOT_DRVINFO() declarations along with the actual platform data for each device. As an example, consider this MMC node: .. code-block:: none @@ -155,7 +155,7 @@ and the following device declarations: .card_detect_delay = 0xc8, }; - U_BOOT_DEVICE(dwmmc_at_ff0c0000) = { + U_BOOT_DRVINFO(dwmmc_at_ff0c0000) = { .name = "rockchip_rk3288_dw_mshc", .plat = &dtv_dwmmc_at_ff0c0000, .plat_size = sizeof(dtv_dwmmc_at_ff0c0000), @@ -178,7 +178,7 @@ platform data in the driver. The of_to_plat() method should therefore do nothing in such a driver. Note that for the platform data to be matched with a driver, the 'name' -property of the U_BOOT_DEVICE() declaration has to match a driver declared +property of the U_BOOT_DRVINFO() declaration has to match a driver declared via U_BOOT_DRIVER(). This effectively means that a U_BOOT_DRIVER() with a 'name' corresponding to the devicetree 'compatible' string (after converting it to a valid name for C) is needed, so a dedicated driver is required for @@ -189,7 +189,7 @@ used to declare an alias for a driver name, typically a 'compatible' string. This macro produces no code, but it is by dtoc tool. The parent_idx is the index of the parent driver_info structure within its -linker list (instantiated by the U_BOOT_DEVICE() macro). This is used to support +linker list (instantiated by the U_BOOT_DRVINFO() macro). This is used to support dev_get_parent(). The dm_populate_phandle_data() is included to allow for fix-ups required by dtoc. It is not currently used. The values in 'clocks' are the index of the driver_info for the target device followed by any phandle @@ -339,7 +339,7 @@ prevents them being used inadvertently. All usage must be bracketed with The dt-plat.c file contains the device declarations and is is built in spl/dt-plat.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 +information by adding references to U_BOOT_DRVINFO by using DM_GET_DEVICE The pylibfdt Python module is used to access the devicetree. diff --git a/doc/driver-model/remoteproc-framework.rst b/doc/driver-model/remoteproc-framework.rst index edb09cc105..566495a21c 100644 --- a/doc/driver-model/remoteproc-framework.rst +++ b/doc/driver-model/remoteproc-framework.rst @@ -125,7 +125,7 @@ a simplified definition of a device is as follows: .driver_plat_data = &mydriver_data; }; - U_BOOT_DEVICE(proc_3_demo) = { + U_BOOT_DRVINFO(proc_3_demo) = { .name = "sandbox_test_proc", .plat = &proc_3_test, }; diff --git a/doc/driver-model/spi-howto.rst b/doc/driver-model/spi-howto.rst index f1c4167139..97fbf750cb 100644 --- a/doc/driver-model/spi-howto.rst +++ b/doc/driver-model/spi-howto.rst @@ -270,7 +270,7 @@ fills in the fields from device tree. Add the platform data [non-device-tree only] -------------------------------------------- -Specify this data in a U_BOOT_DEVICE() declaration in your board file: +Specify this data in a U_BOOT_DRVINFO() declaration in your board file: .. code-block:: c @@ -281,7 +281,7 @@ Specify this data in a U_BOOT_DEVICE() declaration in your board file: .deactivate_delay_us = ... }; - U_BOOT_DEVICE(board_spi0) = { + U_BOOT_DRVINFO(board_spi0) = { .name = "exynos_spi", .plat = &platdata_spi0, }; diff --git a/drivers/crypto/fsl/fsl_rsa.c b/drivers/crypto/fsl/fsl_rsa.c index ed2a54f6ec..897ee855ea 100644 --- a/drivers/crypto/fsl/fsl_rsa.c +++ b/drivers/crypto/fsl/fsl_rsa.c @@ -55,6 +55,6 @@ U_BOOT_DRIVER(fsl_rsa_mod_exp) = { .ops = &fsl_mod_exp_ops, }; -U_BOOT_DEVICE(fsl_rsa) = { +U_BOOT_DRVINFO(fsl_rsa) = { .name = "fsl_rsa_mod_exp", }; diff --git a/drivers/crypto/rsa_mod_exp/mod_exp_sw.c b/drivers/crypto/rsa_mod_exp/mod_exp_sw.c index 4ce85b3224..7bed444c3f 100644 --- a/drivers/crypto/rsa_mod_exp/mod_exp_sw.c +++ b/drivers/crypto/rsa_mod_exp/mod_exp_sw.c @@ -35,6 +35,6 @@ U_BOOT_DRIVER(mod_exp_sw) = { .flags = DM_FLAG_PRE_RELOC, }; -U_BOOT_DEVICE(mod_exp_sw) = { +U_BOOT_DRVINFO(mod_exp_sw) = { .name = "mod_exp_sw", }; diff --git a/drivers/demo/demo-pdata.c b/drivers/demo/demo-pdata.c index b504c31373..818f77503a 100644 --- a/drivers/demo/demo-pdata.c +++ b/drivers/demo/demo-pdata.c @@ -20,27 +20,27 @@ static const struct dm_demo_pdata yellow_hexagon = { .sides = 6. }; -U_BOOT_DEVICE(demo0) = { +U_BOOT_DRVINFO(demo0) = { .name = "demo_shape_drv", .plat = &red_square, }; -U_BOOT_DEVICE(demo1) = { +U_BOOT_DRVINFO(demo1) = { .name = "demo_simple_drv", .plat = &red_square, }; -U_BOOT_DEVICE(demo2) = { +U_BOOT_DRVINFO(demo2) = { .name = "demo_shape_drv", .plat = &green_triangle, }; -U_BOOT_DEVICE(demo3) = { +U_BOOT_DRVINFO(demo3) = { .name = "demo_simple_drv", .plat = &yellow_hexagon, }; -U_BOOT_DEVICE(demo4) = { +U_BOOT_DRVINFO(demo4) = { .name = "demo_shape_drv", .plat = &yellow_hexagon, }; diff --git a/drivers/gpio/imx_rgpio2p.c b/drivers/gpio/imx_rgpio2p.c index a5a290a00c..0e2874ca95 100644 --- a/drivers/gpio/imx_rgpio2p.c +++ b/drivers/gpio/imx_rgpio2p.c @@ -158,7 +158,7 @@ static int imx_rgpio2p_bind(struct udevice *dev) /* * If plat already exsits, directly return. * Actually only when DT is not supported, plat - * is statically initialized in U_BOOT_DEVICES.Here + * is statically initialized in U_BOOT_DRVINFOS.Here * will return. */ if (plat) @@ -216,7 +216,7 @@ static const struct imx_rgpio2p_plat imx_plat[] = { { 5, (struct gpio_regs *)RGPIO2P_GPIO6_BASE_ADDR }, }; -U_BOOT_DEVICES(imx_rgpio2ps) = { +U_BOOT_DRVINFOS(imx_rgpio2ps) = { { "imx_rgpio2p", &imx_plat[0] }, { "imx_rgpio2p", &imx_plat[1] }, { "imx_rgpio2p", &imx_plat[2] }, diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c index 9fc217ae6a..6280fb5984 100644 --- a/drivers/gpio/mxc_gpio.c +++ b/drivers/gpio/mxc_gpio.c @@ -372,7 +372,7 @@ static const struct mxc_gpio_plat mxc_plat[] = { #endif }; -U_BOOT_DEVICES(mxc_gpios) = { +U_BOOT_DRVINFOS(mxc_gpios) = { { "gpio_mxc", &mxc_plat[0] }, { "gpio_mxc", &mxc_plat[1] }, { "gpio_mxc", &mxc_plat[2] }, diff --git a/drivers/remoteproc/sandbox_testproc.c b/drivers/remoteproc/sandbox_testproc.c index ee2ee73071..6836eca4c5 100644 --- a/drivers/remoteproc/sandbox_testproc.c +++ b/drivers/remoteproc/sandbox_testproc.c @@ -352,7 +352,7 @@ static struct dm_rproc_uclass_pdata proc_3_test = { .mem_type = RPROC_INTERNAL_MEMORY_MAPPED, }; -U_BOOT_DEVICE(proc_3_demo) = { +U_BOOT_DRVINFO(proc_3_demo) = { .name = "sandbox_test_proc", .plat = &proc_3_test, }; diff --git a/drivers/rtc/emul_rtc.c b/drivers/rtc/emul_rtc.c index 1dc80ca127..8f0e1ab5ac 100644 --- a/drivers/rtc/emul_rtc.c +++ b/drivers/rtc/emul_rtc.c @@ -91,6 +91,6 @@ U_BOOT_DRIVER(rtc_emul) = { .priv_auto = sizeof(struct emul_rtc), }; -U_BOOT_DEVICE(rtc_emul) = { +U_BOOT_DRVINFO(rtc_emul) = { .name = "rtc_emul", }; diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c index 19368ba256..756738c2d2 100644 --- a/drivers/serial/sandbox.c +++ b/drivers/serial/sandbox.c @@ -241,7 +241,7 @@ static const struct sandbox_serial_plat platdata_non_fdt = { .colour = -1, }; -U_BOOT_DEVICE(serial_sandbox_non_fdt) = { +U_BOOT_DRVINFO(serial_sandbox_non_fdt) = { .name = "sandbox_serial", .plat = &platdata_non_fdt, }; diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c index 8eca7d8bfd..08685823e9 100644 --- a/drivers/sysreset/sysreset_sandbox.c +++ b/drivers/sysreset/sysreset_sandbox.c @@ -47,7 +47,7 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) /* * If we have a device tree, the device we created from platform data - * (see the U_BOOT_DEVICE() declaration below) should not do anything. + * (see the U_BOOT_DRVINFO() declaration below) should not do anything. * If we are that device, return an error. */ if (state->fdt_fname && !dev_has_ofnode(dev)) @@ -135,7 +135,7 @@ U_BOOT_DRIVER(warm_sysreset_sandbox) = { #if !CONFIG_IS_ENABLED(OF_PLATDATA) /* This is here in case we don't have a device tree */ -U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = { +U_BOOT_DRVINFO(sysreset_sandbox_non_fdt) = { .name = "sysreset_sandbox", }; #endif diff --git a/drivers/timer/sandbox_timer.c b/drivers/timer/sandbox_timer.c index 135c0f38a4..2075cd4edd 100644 --- a/drivers/timer/sandbox_timer.c +++ b/drivers/timer/sandbox_timer.c @@ -65,6 +65,6 @@ U_BOOT_DRIVER(sandbox_timer) = { }; /* This is here in case we don't have a device tree */ -U_BOOT_DEVICE(sandbox_timer_non_fdt) = { +U_BOOT_DRVINFO(sandbox_timer_non_fdt) = { .name = "sandbox_timer", }; diff --git a/drivers/video/sunxi/sunxi_de2.c b/drivers/video/sunxi/sunxi_de2.c index 50657a77d3..a3e21aa5f1 100644 --- a/drivers/video/sunxi/sunxi_de2.c +++ b/drivers/video/sunxi/sunxi_de2.c @@ -319,7 +319,7 @@ U_BOOT_DRIVER(sunxi_de2) = { .flags = DM_FLAG_PRE_RELOC, }; -U_BOOT_DEVICE(sunxi_de2) = { +U_BOOT_DRVINFO(sunxi_de2) = { .name = "sunxi_de2" }; diff --git a/drivers/video/sunxi/sunxi_dw_hdmi.c b/drivers/video/sunxi/sunxi_dw_hdmi.c index 3e8d71538f..0b8cefc311 100644 --- a/drivers/video/sunxi/sunxi_dw_hdmi.c +++ b/drivers/video/sunxi/sunxi_dw_hdmi.c @@ -398,6 +398,6 @@ U_BOOT_DRIVER(sunxi_dw_hdmi) = { .priv_auto = sizeof(struct sunxi_dw_hdmi_priv), }; -U_BOOT_DEVICE(sunxi_dw_hdmi) = { +U_BOOT_DRVINFO(sunxi_dw_hdmi) = { .name = "sunxi_dw_hdmi" }; diff --git a/drivers/video/sunxi/sunxi_lcd.c b/drivers/video/sunxi/sunxi_lcd.c index dd2bb1f5fc..635edf6dd3 100644 --- a/drivers/video/sunxi/sunxi_lcd.c +++ b/drivers/video/sunxi/sunxi_lcd.c @@ -146,7 +146,7 @@ U_BOOT_DRIVER(sunxi_lcd) = { }; #ifdef CONFIG_MACH_SUN50I -U_BOOT_DEVICE(sunxi_lcd) = { +U_BOOT_DRVINFO(sunxi_lcd) = { .name = "sunxi_lcd" }; #endif diff --git a/dts/Kconfig b/dts/Kconfig index aeda542f98..71f50552e4 100644 --- a/dts/Kconfig +++ b/dts/Kconfig @@ -346,13 +346,13 @@ config SPL_OF_PLATDATA former can add 3KB or more to a Thumb 2 Image. This option enables generation of platform data from the device - tree as C code. This code creates devices using U_BOOT_DEVICE() + tree as C code. This code creates devices using U_BOOT_DRVINFO() declarations. The benefit is that it allows driver code to access the platform data directly in C structures, avoidin the libfdt overhead. This option works by generating C structure declarations for each - compatible string, then adding platform data and U_BOOT_DEVICE + compatible string, then adding platform data and U_BOOT_DRVINFO declarations for each node. See of-plat.txt for more information. config SPL_OF_PLATDATA_PARENT @@ -376,13 +376,13 @@ config TPL_OF_PLATDATA former can add 3KB or more to a Thumb 2 Image. This option enables generation of platform data from the device - tree as C code. This code creates devices using U_BOOT_DEVICE() + tree as C code. This code creates devices using U_BOOT_DRVINFO() declarations. The benefit is that it allows driver code to access the platform data directly in C structures, avoidin the libfdt overhead. This option works by generating C structure declarations for each - compatible string, then adding platform data and U_BOOT_DEVICE + compatible string, then adding platform data and U_BOOT_DRVINFO declarations for each node. See of-plat.txt for more information. config TPL_OF_PLATDATA_PARENT diff --git a/include/dm/device.h b/include/dm/device.h index 4469804a00..e16ba2405f 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -104,7 +104,7 @@ enum { * particular port or peripheral (essentially a driver instance). * * A device will come into existence through a 'bind' call, either due to - * a U_BOOT_DEVICE() macro (in which case plat is non-NULL) or a node + * a U_BOOT_DRVINFO() macro (in which case plat is non-NULL) or a node * in the device tree (in which case of_offset is >= 0). In the latter case * we translate the device tree information into plat in a function * implemented by the driver of_to_plat method (called just before the @@ -293,7 +293,7 @@ struct udevice_id { * platform data to be allocated in the device's ->plat pointer. * This is typically only useful for device-tree-aware drivers (those with * an of_match), since drivers which use plat will have the data - * provided in the U_BOOT_DEVICE() instantiation. + * provided in the U_BOOT_DRVINFO() instantiation. * @per_child_auto: Each device can hold private data owned by * its parent. If required this will be automatically allocated if this * value is non-zero. diff --git a/include/dm/lists.h b/include/dm/lists.h index 070bc9c19f..1a86552546 100644 --- a/include/dm/lists.h +++ b/include/dm/lists.h @@ -35,7 +35,7 @@ struct uclass_driver *lists_uclass_lookup(enum uclass_id id); /** * lists_bind_drivers() - search for and bind all drivers to parent * - * This searches the U_BOOT_DEVICE() structures and creates new devices for + * This searches the U_BOOT_DRVINFO() structures and creates new devices for * each one. The devices will have @parent as their parent. * * @parent: parent device (root) diff --git a/include/dm/platdata.h b/include/dm/platdata.h index d650fb3919..e2b16ce6e4 100644 --- a/include/dm/platdata.h +++ b/include/dm/platdata.h @@ -56,31 +56,31 @@ struct driver_rt { * is not feasible (e.g. serial driver in SPL where <8KB of SRAM is * available). U-Boot's driver model uses device tree for configuration. * - * When of-platdata is in use, U_BOOT_DEVICE() cannot be used outside of the + * When of-platdata is in use, U_BOOT_DRVINFO() cannot be used outside of the * dt-plat.c file created by dtoc */ #if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLATDATA_C) -#define U_BOOT_DEVICE(__name) _Static_assert(false, \ - "Cannot use U_BOOT_DEVICE with of-platdata. Please use devicetree instead") +#define U_BOOT_DRVINFO(__name) _Static_assert(false, \ + "Cannot use U_BOOT_DRVINFO with of-platdata. Please use devicetree instead") #else -#define U_BOOT_DEVICE(__name) \ +#define U_BOOT_DRVINFO(__name) \ ll_entry_declare(struct driver_info, __name, driver_info) #endif /* Declare a list of devices. The argument is a driver_info[] array */ -#define U_BOOT_DEVICES(__name) \ +#define U_BOOT_DRVINFOS(__name) \ ll_entry_declare_list(struct driver_info, __name, driver_info) /** * Get a pointer to a given device info given its name * - * With the declaration U_BOOT_DEVICE(name), DM_GET_DEVICE(name) will return a + * With the declaration U_BOOT_DRVINFO(name), DM_GET_DEVICE(name) will return a * pointer to the struct driver_info created by that declaration. * * if OF_PLATDATA is enabled, from this it is possible to use the @dev member of * struct driver_info to find the device pointer itself. * - * TODO(sjg@chromium.org): U_BOOT_DEVICE() tells U-Boot to create a device, so + * TODO(sjg@chromium.org): U_BOOT_DRVINFO() tells U-Boot to create a device, so * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it * finds the driver_info record, not the device. * @@ -93,7 +93,7 @@ struct driver_rt { /** * dm_populate_phandle_data() - Populates phandle data in platda * - * This populates phandle data with an U_BOOT_DEVICE entry get by + * This populates phandle data with an U_BOOT_DRVINFO entry get by * DM_GET_DEVICE. The implementation of this function will be done * by dtoc when parsing dtb. */ diff --git a/include/dm/platform_data/spi_pl022.h b/include/dm/platform_data/spi_pl022.h index c5aa321291..7f74b3cbc5 100644 --- a/include/dm/platform_data/spi_pl022.h +++ b/include/dm/platform_data/spi_pl022.h @@ -3,7 +3,7 @@ * (C) Copyright 2018 * Quentin Schulz, Bootlin, quentin.schulz@bootlin.com * - * Structure for use with U_BOOT_DEVICE for pl022 SPI devices or to use + * Structure for use with U_BOOT_DRVINFO for pl022 SPI devices or to use * in of_to_plat. */ diff --git a/test/dm/core.c b/test/dm/core.c index 580d171e30..82b7a668dd 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -43,17 +43,17 @@ static const struct dm_test_pdata test_pdata_pre_reloc = { .ping_add = TEST_INTVAL_PRE_RELOC, }; -U_BOOT_DEVICE(dm_test_info1) = { +U_BOOT_DRVINFO(dm_test_info1) = { .name = "test_drv", .plat = &test_pdata[0], }; -U_BOOT_DEVICE(dm_test_info2) = { +U_BOOT_DRVINFO(dm_test_info2) = { .name = "test_drv", .plat = &test_pdata[1], }; -U_BOOT_DEVICE(dm_test_info3) = { +U_BOOT_DRVINFO(dm_test_info3) = { .name = "test_drv", .plat = &test_pdata[2], }; diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 7bd1989113..ebe5132e14 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -713,14 +713,14 @@ class DtbPlatdata(): def _declare_device(self, var_name, struct_name, node_parent): """Add a device declaration to the output - This declares a U_BOOT_DEVICE() for the device being processed + This declares a U_BOOT_DRVINFO() for the device being processed Args: var_name (str): C name for the node struct_name (str): Name for the dt struct associated with the node node_parent (Node): Parent of the node (or None if none) """ - self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name) + self.buf('U_BOOT_DRVINFO(%s) = {\n' % var_name) self.buf('\t.name\t\t= "%s",\n' % struct_name) self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name)) self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name)) @@ -783,14 +783,14 @@ class DtbPlatdata(): """Generate device defintions for the platform data This writes out C platform data initialisation data and - U_BOOT_DEVICE() declarations for each valid node. Where a node has + U_BOOT_DRVINFO() declarations for each valid node. Where a node has multiple compatible strings, a #define is used to make them equivalent. See the documentation in doc/driver-model/of-plat.rst for more information. """ self.out_header() - self.out('/* Allow use of U_BOOT_DEVICE() in this file */\n') + self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n') self.out('#define DT_PLATDATA_C\n') self.out('\n') self.out('#include \n') diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index fb65f284ce..dbd4e3bf1d 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -44,7 +44,7 @@ C_HEADER = '''/* * This file was generated by dtoc from a .dtb (device tree binary) file. */ -/* Allow use of U_BOOT_DEVICE() in this file */ +/* Allow use of U_BOOT_DRVINFO() in this file */ #define DT_PLATDATA_C #include @@ -214,7 +214,7 @@ struct dtd_sandbox_spl_test { /* Node /i2c@0 index 0 */ static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { }; -U_BOOT_DEVICE(i2c_at_0) = { +U_BOOT_DRVINFO(i2c_at_0) = { \t.name\t\t= "sandbox_i2c_test", \t.plat\t= &dtv_i2c_at_0, \t.plat_size\t= sizeof(dtv_i2c_at_0), @@ -226,7 +226,7 @@ static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = { \t.low_power\t\t= true, \t.reg\t\t\t= {0x9, 0x0}, }; -U_BOOT_DEVICE(pmic_at_9) = { +U_BOOT_DRVINFO(pmic_at_9) = { \t.name\t\t= "sandbox_pmic_test", \t.plat\t= &dtv_pmic_at_9, \t.plat_size\t= sizeof(dtv_pmic_at_9), @@ -246,7 +246,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test = { \t.stringarray\t\t= {"multi-word", "message", ""}, \t.stringval\t\t= "message", }; -U_BOOT_DEVICE(spl_test) = { +U_BOOT_DRVINFO(spl_test) = { \t.name\t\t= "sandbox_spl_test", \t.plat\t= &dtv_spl_test, \t.plat_size\t= sizeof(dtv_spl_test), @@ -265,7 +265,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test2 = { \t.stringarray\t\t= {"another", "multi-word", "message"}, \t.stringval\t\t= "message2", }; -U_BOOT_DEVICE(spl_test2) = { +U_BOOT_DRVINFO(spl_test2) = { \t.name\t\t= "sandbox_spl_test", \t.plat\t= &dtv_spl_test2, \t.plat_size\t= sizeof(dtv_spl_test2), @@ -278,7 +278,7 @@ static struct dtd_sandbox_spl_test dtv_spl_test3 = { \t\t0x0}, \t.stringarray\t\t= {"one", "", ""}, }; -U_BOOT_DEVICE(spl_test3) = { +U_BOOT_DRVINFO(spl_test3) = { \t.name\t\t= "sandbox_spl_test", \t.plat\t= &dtv_spl_test3, \t.plat_size\t= sizeof(dtv_spl_test3), @@ -333,7 +333,7 @@ static struct dtd_sandbox_gpio dtv_gpios_at_0 = { \t.gpio_controller\t= true, \t.sandbox_gpio_count\t= 0x14, }; -U_BOOT_DEVICE(gpios_at_0) = { +U_BOOT_DRVINFO(gpios_at_0) = { \t.name\t\t= "sandbox_gpio", \t.plat\t= &dtv_gpios_at_0, \t.plat_size\t= sizeof(dtv_gpios_at_0), @@ -365,7 +365,7 @@ struct dtd_invalid { /* Node /spl-test index 0 */ static struct dtd_invalid dtv_spl_test = { }; -U_BOOT_DEVICE(spl_test) = { +U_BOOT_DRVINFO(spl_test) = { \t.name\t\t= "invalid", \t.plat\t= &dtv_spl_test, \t.plat_size\t= sizeof(dtv_spl_test), @@ -400,7 +400,7 @@ struct dtd_target { static struct dtd_target dtv_phandle2_target = { \t.intval\t\t\t= 0x1, }; -U_BOOT_DEVICE(phandle2_target) = { +U_BOOT_DRVINFO(phandle2_target) = { \t.name\t\t= "target", \t.plat\t= &dtv_phandle2_target, \t.plat_size\t= sizeof(dtv_phandle2_target), @@ -411,7 +411,7 @@ U_BOOT_DEVICE(phandle2_target) = { static struct dtd_target dtv_phandle3_target = { \t.intval\t\t\t= 0x2, }; -U_BOOT_DEVICE(phandle3_target) = { +U_BOOT_DRVINFO(phandle3_target) = { \t.name\t\t= "target", \t.plat\t= &dtv_phandle3_target, \t.plat_size\t= sizeof(dtv_phandle3_target), @@ -422,7 +422,7 @@ U_BOOT_DEVICE(phandle3_target) = { static struct dtd_target dtv_phandle_target = { \t.intval\t\t\t= 0x0, }; -U_BOOT_DEVICE(phandle_target) = { +U_BOOT_DRVINFO(phandle_target) = { \t.name\t\t= "target", \t.plat\t= &dtv_phandle_target, \t.plat_size\t= sizeof(dtv_phandle_target), @@ -437,7 +437,7 @@ static struct dtd_source dtv_phandle_source = { \t\t\t{1, {12, 13}}, \t\t\t{4, {}},}, }; -U_BOOT_DEVICE(phandle_source) = { +U_BOOT_DRVINFO(phandle_source) = { \t.name\t\t= "source", \t.plat\t= &dtv_phandle_source, \t.plat_size\t= sizeof(dtv_phandle_source), @@ -449,7 +449,7 @@ static struct dtd_source dtv_phandle_source2 = { \t.clocks\t\t\t= { \t\t\t{4, {}},}, }; -U_BOOT_DEVICE(phandle_source2) = { +U_BOOT_DRVINFO(phandle_source2) = { \t.name\t\t= "source", \t.plat\t= &dtv_phandle_source2, \t.plat_size\t= sizeof(dtv_phandle_source2), @@ -487,7 +487,7 @@ struct dtd_target { /* Node /phandle-target index 1 */ static struct dtd_target dtv_phandle_target = { }; -U_BOOT_DEVICE(phandle_target) = { +U_BOOT_DRVINFO(phandle_target) = { \t.name\t\t= "target", \t.plat\t= &dtv_phandle_target, \t.plat_size\t= sizeof(dtv_phandle_target), @@ -499,7 +499,7 @@ static struct dtd_source dtv_phandle_source2 = { \t.clocks\t\t\t= { \t\t\t{1, {}},}, }; -U_BOOT_DEVICE(phandle_source2) = { +U_BOOT_DRVINFO(phandle_source2) = { \t.name\t\t= "source", \t.plat\t= &dtv_phandle_source2, \t.plat_size\t= sizeof(dtv_phandle_source2), @@ -522,7 +522,7 @@ void dm_populate_phandle_data(void) { static struct dtd_target dtv_phandle2_target = { \t.intval\t\t\t= 0x1, }; -U_BOOT_DEVICE(phandle2_target) = { +U_BOOT_DRVINFO(phandle2_target) = { \t.name\t\t= "target", \t.plat\t= &dtv_phandle2_target, \t.plat_size\t= sizeof(dtv_phandle2_target), @@ -533,7 +533,7 @@ U_BOOT_DEVICE(phandle2_target) = { static struct dtd_target dtv_phandle3_target = { \t.intval\t\t\t= 0x2, }; -U_BOOT_DEVICE(phandle3_target) = { +U_BOOT_DRVINFO(phandle3_target) = { \t.name\t\t= "target", \t.plat\t= &dtv_phandle3_target, \t.plat_size\t= sizeof(dtv_phandle3_target), @@ -544,7 +544,7 @@ U_BOOT_DEVICE(phandle3_target) = { static struct dtd_target dtv_phandle_target = { \t.intval\t\t\t= 0x0, }; -U_BOOT_DEVICE(phandle_target) = { +U_BOOT_DRVINFO(phandle_target) = { \t.name\t\t= "target", \t.plat\t= &dtv_phandle_target, \t.plat_size\t= sizeof(dtv_phandle_target), @@ -559,7 +559,7 @@ static struct dtd_source dtv_phandle_source = { \t\t\t{1, {12, 13}}, \t\t\t{4, {}},}, }; -U_BOOT_DEVICE(phandle_source) = { +U_BOOT_DRVINFO(phandle_source) = { \t.name\t\t= "source", \t.plat\t= &dtv_phandle_source, \t.plat_size\t= sizeof(dtv_phandle_source), @@ -571,7 +571,7 @@ static struct dtd_source dtv_phandle_source2 = { \t.cd_gpios\t\t= { \t\t\t{4, {}},}, }; -U_BOOT_DEVICE(phandle_source2) = { +U_BOOT_DRVINFO(phandle_source2) = { \t.name\t\t= "source", \t.plat\t= &dtv_phandle_source2, \t.plat_size\t= sizeof(dtv_phandle_source2), @@ -629,7 +629,7 @@ struct dtd_test3 { static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, }; -U_BOOT_DEVICE(test1) = { +U_BOOT_DRVINFO(test1) = { \t.name\t\t= "test1", \t.plat\t= &dtv_test1, \t.plat_size\t= sizeof(dtv_test1), @@ -640,7 +640,7 @@ U_BOOT_DEVICE(test1) = { static struct dtd_test2 dtv_test2 = { \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654}, }; -U_BOOT_DEVICE(test2) = { +U_BOOT_DRVINFO(test2) = { \t.name\t\t= "test2", \t.plat\t= &dtv_test2, \t.plat_size\t= sizeof(dtv_test2), @@ -651,7 +651,7 @@ U_BOOT_DEVICE(test2) = { static struct dtd_test3 dtv_test3 = { \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3}, }; -U_BOOT_DEVICE(test3) = { +U_BOOT_DRVINFO(test3) = { \t.name\t\t= "test3", \t.plat\t= &dtv_test3, \t.plat_size\t= sizeof(dtv_test3), @@ -684,7 +684,7 @@ struct dtd_test2 { static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, }; -U_BOOT_DEVICE(test1) = { +U_BOOT_DRVINFO(test1) = { \t.name\t\t= "test1", \t.plat\t= &dtv_test1, \t.plat_size\t= sizeof(dtv_test1), @@ -695,7 +695,7 @@ U_BOOT_DEVICE(test1) = { static struct dtd_test2 dtv_test2 = { \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3}, }; -U_BOOT_DEVICE(test2) = { +U_BOOT_DRVINFO(test2) = { \t.name\t\t= "test2", \t.plat\t= &dtv_test2, \t.plat_size\t= sizeof(dtv_test2), @@ -731,7 +731,7 @@ struct dtd_test3 { static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x123400000000, 0x5678}, }; -U_BOOT_DEVICE(test1) = { +U_BOOT_DRVINFO(test1) = { \t.name\t\t= "test1", \t.plat\t= &dtv_test1, \t.plat_size\t= sizeof(dtv_test1), @@ -742,7 +742,7 @@ U_BOOT_DEVICE(test1) = { static struct dtd_test2 dtv_test2 = { \t.reg\t\t\t= {0x1234567890123456, 0x98765432}, }; -U_BOOT_DEVICE(test2) = { +U_BOOT_DRVINFO(test2) = { \t.name\t\t= "test2", \t.plat\t= &dtv_test2, \t.plat_size\t= sizeof(dtv_test2), @@ -753,7 +753,7 @@ U_BOOT_DEVICE(test2) = { static struct dtd_test3 dtv_test3 = { \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3}, }; -U_BOOT_DEVICE(test3) = { +U_BOOT_DRVINFO(test3) = { \t.name\t\t= "test3", \t.plat\t= &dtv_test3, \t.plat_size\t= sizeof(dtv_test3), @@ -789,7 +789,7 @@ struct dtd_test3 { static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x567800000000}, }; -U_BOOT_DEVICE(test1) = { +U_BOOT_DRVINFO(test1) = { \t.name\t\t= "test1", \t.plat\t= &dtv_test1, \t.plat_size\t= sizeof(dtv_test1), @@ -800,7 +800,7 @@ U_BOOT_DEVICE(test1) = { static struct dtd_test2 dtv_test2 = { \t.reg\t\t\t= {0x12345678, 0x9876543210987654}, }; -U_BOOT_DEVICE(test2) = { +U_BOOT_DRVINFO(test2) = { \t.name\t\t= "test2", \t.plat\t= &dtv_test2, \t.plat_size\t= sizeof(dtv_test2), @@ -811,7 +811,7 @@ U_BOOT_DEVICE(test2) = { static struct dtd_test3 dtv_test3 = { \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3}, }; -U_BOOT_DEVICE(test3) = { +U_BOOT_DRVINFO(test3) = { \t.name\t\t= "test3", \t.plat\t= &dtv_test3, \t.plat_size\t= sizeof(dtv_test3), @@ -863,7 +863,7 @@ struct dtd_sandbox_spl_test { static struct dtd_sandbox_spl_test dtv_spl_test = { \t.intval\t\t\t= 0x1, }; -U_BOOT_DEVICE(spl_test) = { +U_BOOT_DRVINFO(spl_test) = { \t.name\t\t= "sandbox_spl_test", \t.plat\t= &dtv_spl_test, \t.plat_size\t= sizeof(dtv_spl_test), @@ -874,7 +874,7 @@ U_BOOT_DEVICE(spl_test) = { static struct dtd_sandbox_spl_test dtv_spl_test2 = { \t.intarray\t\t= 0x5, }; -U_BOOT_DEVICE(spl_test2) = { +U_BOOT_DRVINFO(spl_test2) = { \t.name\t\t= "sandbox_spl_test", \t.plat\t= &dtv_spl_test2, \t.plat_size\t= sizeof(dtv_spl_test2), -- cgit v1.2.3 From 8629d30a32e7b4ff8323292364116c08033bd57b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:55 -0700 Subject: dm: Rename DM_GET_DEVICE() to DM_DRVINFO_GET() This does not get a device (struct udevice *) but a struct driver_info * so the name is confusing. Rename it accordingly. Since we plan to have several various of these macros, put GET at the end instead of the middle, so it is easier to spot the related macros. Signed-off-by: Simon Glass --- doc/driver-model/of-plat.rst | 2 +- include/dm/platdata.h | 10 +++------- tools/dtoc/dtb_platdata.py | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst index 39e6295aa0..21b45f6a7e 100644 --- a/doc/driver-model/of-plat.rst +++ b/doc/driver-model/of-plat.rst @@ -339,7 +339,7 @@ prevents them being used inadvertently. All usage must be bracketed with The dt-plat.c file contains the device declarations and is is built in spl/dt-plat.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_DRVINFO by using DM_GET_DEVICE +information by adding references to U_BOOT_DRVINFO by using DM_DRVINFO_GET The pylibfdt Python module is used to access the devicetree. diff --git a/include/dm/platdata.h b/include/dm/platdata.h index e2b16ce6e4..df1f6abcc7 100644 --- a/include/dm/platdata.h +++ b/include/dm/platdata.h @@ -74,27 +74,23 @@ struct driver_rt { /** * Get a pointer to a given device info given its name * - * With the declaration U_BOOT_DRVINFO(name), DM_GET_DEVICE(name) will return a + * With the declaration U_BOOT_DRVINFO(name), DM_DRVINFO_GET(name) will return a * pointer to the struct driver_info created by that declaration. * * if OF_PLATDATA is enabled, from this it is possible to use the @dev member of * struct driver_info to find the device pointer itself. * - * TODO(sjg@chromium.org): U_BOOT_DRVINFO() tells U-Boot to create a device, so - * the naming seems sensible, but DM_GET_DEVICE() is a bit of misnomer, since it - * finds the driver_info record, not the device. - * * @__name: Driver name (C identifier, not a string. E.g. gpio7_at_ff7e0000) * @return struct driver_info * to the driver that created the device */ -#define DM_GET_DEVICE(__name) \ +#define DM_DRVINFO_GET(__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_DRVINFO entry get by - * DM_GET_DEVICE. The implementation of this function will be done + * DM_DRVINFO_GET. The implementation of this function will be done * by dtoc when parsing dtb. */ void dm_populate_phandle_data(void); diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index ebe5132e14..1a6a511b01 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -811,8 +811,8 @@ class DtbPlatdata(): 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) + # nodes using DM_DRVINFO_GET + # dtv_dmc_at_xxx.clocks[0].node = DM_DRVINFO_GET(clock_controller_at_xxx) self.buf('void dm_populate_phandle_data(void) {\n') self.buf('}\n') -- cgit v1.2.3 From 65e25bea597ccaaea756c593318bea1e574d8df1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:56 -0700 Subject: dm: Rename DM_GET_DRIVER() to DM_DRIVER_GET() In the spirit of using the same base name for all of these related macros, rename this to have the operation at the end. This is not widely used so the impact is fairly small. Signed-off-by: Simon Glass --- arch/arm/lib/gic-v3-its.c | 10 +++++----- arch/arm/mach-aspeed/ast2500/clk_ast2500.c | 2 +- arch/arm/mach-k3/am6_init.c | 2 +- arch/arm/mach-k3/common.c | 2 +- arch/arm/mach-k3/j721e_init.c | 2 +- arch/arm/mach-mediatek/mt7629/init.c | 4 ++-- arch/arm/mach-mediatek/mt8516/init.c | 2 +- arch/arm/mach-rockchip/misc.c | 4 ++-- arch/arm/mach-rockchip/px30/clk_px30.c | 2 +- arch/arm/mach-rockchip/rk3036/clk_rk3036.c | 2 +- arch/arm/mach-rockchip/rk3128/clk_rk3128.c | 2 +- arch/arm/mach-rockchip/rk3188/clk_rk3188.c | 2 +- arch/arm/mach-rockchip/rk322x/clk_rk322x.c | 2 +- arch/arm/mach-rockchip/rk3288/clk_rk3288.c | 2 +- arch/arm/mach-rockchip/rk3308/clk_rk3308.c | 2 +- arch/arm/mach-rockchip/rk3328/clk_rk3328.c | 2 +- arch/arm/mach-rockchip/rk3368/clk_rk3368.c | 2 +- arch/arm/mach-rockchip/rk3399/clk_rk3399.c | 4 ++-- arch/arm/mach-rockchip/rv1108/clk_rv1108.c | 2 +- arch/arm/mach-socfpga/clock_manager_agilex.c | 2 +- arch/arm/mach-stm32mp/bsec.c | 2 +- arch/arm/mach-stm32mp/cmd_stm32key.c | 2 +- arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c | 6 +++--- arch/arm/mach-stm32mp/cpu.c | 6 +++--- arch/arm/mach-uniphier/micro-support-card.c | 2 +- arch/arm/mach-zynq/clk.c | 4 ++-- arch/arm/mach-zynq/timer.c | 2 +- arch/mips/mach-mtmips/mt7628/init.c | 2 +- arch/riscv/lib/sifive_clint.c | 2 +- board/dhelectronics/dh_stm32mp1/board.c | 6 +++--- board/google/gru/gru.c | 2 +- board/nvidia/jetson-tk1/jetson-tk1.c | 2 +- board/nvidia/nyan-big/nyan-big.c | 2 +- board/renesas/ulcb/cpld.c | 2 +- board/sifive/fu540/fu540.c | 2 +- board/st/common/cmd_stboard.c | 2 +- board/st/common/stm32mp_dfu.c | 4 ++-- board/st/common/stpmic1.c | 4 ++-- board/st/common/stusb160x.c | 2 +- board/st/stm32mp1/stm32mp1.c | 12 ++++++------ board/ti/j721e/evm.c | 4 ++-- board/toradex/apalis-tk1/apalis-tk1.c | 4 ++-- drivers/clk/clk_stm32mp1.c | 2 +- drivers/clk/clk_zynqmp.c | 2 +- drivers/clk/imx/clk-imx8.c | 2 +- drivers/clk/mediatek/clk-mtk.c | 6 +++--- drivers/clk/sifive/fu540-prci.c | 2 +- drivers/firmware/scmi/scmi_agent-uclass.c | 4 ++-- drivers/gpio/gpio-uclass.c | 2 +- drivers/misc/i2c_eeprom.c | 2 +- drivers/misc/rockchip-efuse.c | 2 +- drivers/misc/stm32mp_fuse.c | 16 ++++++++-------- drivers/mtd/nand/raw/arasan_nfc.c | 2 +- drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c | 2 +- drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c | 2 +- drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c | 2 +- drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c | 2 +- drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c | 2 +- drivers/mtd/nand/raw/davinci_nand.c | 2 +- drivers/mtd/nand/raw/denali_dt.c | 2 +- drivers/mtd/nand/raw/mxs_nand_dt.c | 2 +- drivers/mtd/nand/raw/octeontx_nand.c | 6 +++--- drivers/mtd/nand/raw/pxa3xx_nand.c | 2 +- drivers/mtd/nand/raw/stm32_fmc2_nand.c | 2 +- drivers/mtd/nand/raw/tegra_nand.c | 2 +- drivers/mtd/nand/raw/vf610_nfc.c | 2 +- drivers/mtd/nand/raw/zynq_nand.c | 2 +- drivers/reset/reset-ast2500.c | 2 +- drivers/video/lg4573.c | 2 +- include/dm/device.h | 2 +- include/dm/uclass.h | 2 +- test/dm/core.c | 2 +- test/dm/test-fdt.c | 6 +++--- 73 files changed, 110 insertions(+), 110 deletions(-) diff --git a/arch/arm/lib/gic-v3-its.c b/arch/arm/lib/gic-v3-its.c index a1657e3853..f5a921b3d1 100644 --- a/arch/arm/lib/gic-v3-its.c +++ b/arch/arm/lib/gic-v3-its.c @@ -43,10 +43,10 @@ static int gic_v3_its_get_gic_addr(struct gic_v3_its_priv *priv) int ret; ret = uclass_get_device_by_driver(UCLASS_IRQ, - DM_GET_DRIVER(arm_gic_v3_its), &dev); + DM_DRIVER_GET(arm_gic_v3_its), &dev); if (ret) { pr_err("%s: failed to get %s irq device\n", __func__, - DM_GET_DRIVER(arm_gic_v3_its)->name); + DM_DRIVER_GET(arm_gic_v3_its)->name); return ret; } @@ -74,17 +74,17 @@ static int gic_v3_its_get_gic_lpi_addr(struct gic_v3_its_priv *priv) int ret; ret = uclass_get_device_by_driver(UCLASS_SYSCON, - DM_GET_DRIVER(gic_lpi_syscon), &dev); + DM_DRIVER_GET(gic_lpi_syscon), &dev); if (ret) { pr_err("%s: failed to get %s syscon device\n", __func__, - DM_GET_DRIVER(gic_lpi_syscon)->name); + DM_DRIVER_GET(gic_lpi_syscon)->name); return ret; } regmap = syscon_get_regmap(dev); if (!regmap) { pr_err("%s: failed to regmap for %s syscon device\n", __func__, - DM_GET_DRIVER(gic_lpi_syscon)->name); + DM_DRIVER_GET(gic_lpi_syscon)->name); return -ENODEV; } priv->lpi_base = regmap->ranges[0].start; diff --git a/arch/arm/mach-aspeed/ast2500/clk_ast2500.c b/arch/arm/mach-aspeed/ast2500/clk_ast2500.c index 3e9f5e57ed..02bd3f67c9 100644 --- a/arch/arm/mach-aspeed/ast2500/clk_ast2500.c +++ b/arch/arm/mach-aspeed/ast2500/clk_ast2500.c @@ -12,7 +12,7 @@ int ast_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(aspeed_ast2500_scu), devp); + DM_DRIVER_GET(aspeed_ast2500_scu), devp); } void *ast_get_scu(void) diff --git a/arch/arm/mach-k3/am6_init.c b/arch/arm/mach-k3/am6_init.c index 0fed5aec59..dea470c02f 100644 --- a/arch/arm/mach-k3/am6_init.c +++ b/arch/arm/mach-k3/am6_init.c @@ -238,7 +238,7 @@ void board_init_f(ulong dummy) do_board_detect(); #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0) - ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs), + ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs), &dev); if (ret) printf("AVS init failed: %d\n", ret); diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c index 8c903f14ff..8b54e0cf52 100644 --- a/arch/arm/mach-k3/common.c +++ b/arch/arm/mach-k3/common.c @@ -33,7 +33,7 @@ struct ti_sci_handle *get_ti_sci_handle(void) int ret; ret = uclass_get_device_by_driver(UCLASS_FIRMWARE, - DM_GET_DRIVER(ti_sci), &dev); + DM_DRIVER_GET(ti_sci), &dev); if (ret) panic("Failed to get SYSFW (%d)\n", ret); diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c index 0201690f93..1a4f796e5e 100644 --- a/arch/arm/mach-k3/j721e_init.c +++ b/arch/arm/mach-k3/j721e_init.c @@ -206,7 +206,7 @@ void board_init_f(ulong dummy) do_board_detect(); #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0) - ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs), + ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs), &dev); if (ret) printf("AVS init failed: %d\n", ret); diff --git a/arch/arm/mach-mediatek/mt7629/init.c b/arch/arm/mach-mediatek/mt7629/init.c index c260413a57..1f102dddd4 100644 --- a/arch/arm/mach-mediatek/mt7629/init.c +++ b/arch/arm/mach-mediatek/mt7629/init.c @@ -40,7 +40,7 @@ int mtk_pll_early_init(void) int ret, i; ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(mtk_clk_apmixedsys), &dev); + DM_DRIVER_GET(mtk_clk_apmixedsys), &dev); if (ret) return ret; @@ -59,7 +59,7 @@ int mtk_pll_early_init(void) /* setup mcu bus */ ret = uclass_get_device_by_driver(UCLASS_SYSCON, - DM_GET_DRIVER(mtk_mcucfg), &dev); + DM_DRIVER_GET(mtk_mcucfg), &dev); if (ret) return ret; diff --git a/arch/arm/mach-mediatek/mt8516/init.c b/arch/arm/mach-mediatek/mt8516/init.c index 13be391221..2ffa5595cf 100644 --- a/arch/arm/mach-mediatek/mt8516/init.c +++ b/arch/arm/mach-mediatek/mt8516/init.c @@ -52,7 +52,7 @@ int mtk_pll_early_init(void) int ret, i; ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(mtk_clk_apmixedsys), &dev); + DM_DRIVER_GET(mtk_clk_apmixedsys), &dev); if (ret) return ret; diff --git a/arch/arm/mach-rockchip/misc.c b/arch/arm/mach-rockchip/misc.c index 28c7c7214c..87eebd9872 100644 --- a/arch/arm/mach-rockchip/misc.c +++ b/arch/arm/mach-rockchip/misc.c @@ -67,10 +67,10 @@ int rockchip_cpuid_from_efuse(const u32 cpuid_offset, /* retrieve the device */ #if CONFIG_IS_ENABLED(ROCKCHIP_EFUSE) ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(rockchip_efuse), &dev); + DM_DRIVER_GET(rockchip_efuse), &dev); #elif CONFIG_IS_ENABLED(ROCKCHIP_OTP) ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(rockchip_otp), &dev); + DM_DRIVER_GET(rockchip_otp), &dev); #endif if (ret) { debug("%s: could not find efuse device\n", __func__); diff --git a/arch/arm/mach-rockchip/px30/clk_px30.c b/arch/arm/mach-rockchip/px30/clk_px30.c index 98a1bcd224..7edf1321fe 100644 --- a/arch/arm/mach-rockchip/px30/clk_px30.c +++ b/arch/arm/mach-rockchip/px30/clk_px30.c @@ -13,7 +13,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_px30_cru), devp); + DM_DRIVER_GET(rockchip_px30_cru), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-rockchip/rk3036/clk_rk3036.c b/arch/arm/mach-rockchip/rk3036/clk_rk3036.c index 5d0def3b52..116dccd7b8 100644 --- a/arch/arm/mach-rockchip/rk3036/clk_rk3036.c +++ b/arch/arm/mach-rockchip/rk3036/clk_rk3036.c @@ -14,7 +14,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_rk3036_cru), devp); + DM_DRIVER_GET(rockchip_rk3036_cru), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-rockchip/rk3128/clk_rk3128.c b/arch/arm/mach-rockchip/rk3128/clk_rk3128.c index f9ce1f7234..a1b038c648 100644 --- a/arch/arm/mach-rockchip/rk3128/clk_rk3128.c +++ b/arch/arm/mach-rockchip/rk3128/clk_rk3128.c @@ -13,7 +13,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_rk3128_cru), devp); + DM_DRIVER_GET(rockchip_rk3128_cru), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-rockchip/rk3188/clk_rk3188.c b/arch/arm/mach-rockchip/rk3188/clk_rk3188.c index a0dcac3732..94d1d23e1f 100644 --- a/arch/arm/mach-rockchip/rk3188/clk_rk3188.c +++ b/arch/arm/mach-rockchip/rk3188/clk_rk3188.c @@ -14,7 +14,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_rk3188_cru), devp); + DM_DRIVER_GET(rockchip_rk3188_cru), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-rockchip/rk322x/clk_rk322x.c b/arch/arm/mach-rockchip/rk322x/clk_rk322x.c index fc5abd736e..2e57672b24 100644 --- a/arch/arm/mach-rockchip/rk322x/clk_rk322x.c +++ b/arch/arm/mach-rockchip/rk322x/clk_rk322x.c @@ -13,7 +13,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_rk322x_cru), devp); + DM_DRIVER_GET(rockchip_rk322x_cru), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-rockchip/rk3288/clk_rk3288.c b/arch/arm/mach-rockchip/rk3288/clk_rk3288.c index e05bd06a8d..fb4c0891d0 100644 --- a/arch/arm/mach-rockchip/rk3288/clk_rk3288.c +++ b/arch/arm/mach-rockchip/rk3288/clk_rk3288.c @@ -14,7 +14,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_rk3288_cru), devp); + DM_DRIVER_GET(rockchip_rk3288_cru), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-rockchip/rk3308/clk_rk3308.c b/arch/arm/mach-rockchip/rk3308/clk_rk3308.c index 1feb237224..ccda53380c 100644 --- a/arch/arm/mach-rockchip/rk3308/clk_rk3308.c +++ b/arch/arm/mach-rockchip/rk3308/clk_rk3308.c @@ -13,7 +13,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_rk3308_cru), devp); + DM_DRIVER_GET(rockchip_rk3308_cru), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-rockchip/rk3328/clk_rk3328.c b/arch/arm/mach-rockchip/rk3328/clk_rk3328.c index e5375514de..70c0eb6f98 100644 --- a/arch/arm/mach-rockchip/rk3328/clk_rk3328.c +++ b/arch/arm/mach-rockchip/rk3328/clk_rk3328.c @@ -12,7 +12,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_rk3328_cru), devp); + DM_DRIVER_GET(rockchip_rk3328_cru), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-rockchip/rk3368/clk_rk3368.c b/arch/arm/mach-rockchip/rk3368/clk_rk3368.c index 9a33c67bc9..b075319720 100644 --- a/arch/arm/mach-rockchip/rk3368/clk_rk3368.c +++ b/arch/arm/mach-rockchip/rk3368/clk_rk3368.c @@ -14,7 +14,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_rk3368_cru), devp); + DM_DRIVER_GET(rockchip_rk3368_cru), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-rockchip/rk3399/clk_rk3399.c b/arch/arm/mach-rockchip/rk3399/clk_rk3399.c index d23a5e9435..9d9a837fc7 100644 --- a/arch/arm/mach-rockchip/rk3399/clk_rk3399.c +++ b/arch/arm/mach-rockchip/rk3399/clk_rk3399.c @@ -14,7 +14,7 @@ static int rockchip_get_cruclk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(clk_rk3399), devp); + DM_DRIVER_GET(clk_rk3399), devp); } void *rockchip_get_cru(void) @@ -35,7 +35,7 @@ void *rockchip_get_cru(void) static int rockchip_get_pmucruclk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(rockchip_rk3399_pmuclk), devp); + DM_DRIVER_GET(rockchip_rk3399_pmuclk), devp); } void *rockchip_get_pmucru(void) diff --git a/arch/arm/mach-rockchip/rv1108/clk_rv1108.c b/arch/arm/mach-rockchip/rv1108/clk_rv1108.c index b37ae1c494..44b53c407a 100644 --- a/arch/arm/mach-rockchip/rv1108/clk_rv1108.c +++ b/arch/arm/mach-rockchip/rv1108/clk_rv1108.c @@ -14,7 +14,7 @@ int rockchip_get_clk(struct udevice **devp) { return uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(clk_rv1108), devp); + DM_DRIVER_GET(clk_rv1108), devp); } void *rockchip_get_cru(void) diff --git a/arch/arm/mach-socfpga/clock_manager_agilex.c b/arch/arm/mach-socfpga/clock_manager_agilex.c index 6188a8c3d2..a960176da7 100644 --- a/arch/arm/mach-socfpga/clock_manager_agilex.c +++ b/arch/arm/mach-socfpga/clock_manager_agilex.c @@ -24,7 +24,7 @@ static ulong cm_get_rate_dm(u32 id) int ret; ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(socfpga_agilex_clk), + DM_DRIVER_GET(socfpga_agilex_clk), &dev); if (ret) return 0; diff --git a/arch/arm/mach-stm32mp/bsec.c b/arch/arm/mach-stm32mp/bsec.c index 85a9e6f84e..84e0bddcd4 100644 --- a/arch/arm/mach-stm32mp/bsec.c +++ b/arch/arm/mach-stm32mp/bsec.c @@ -525,7 +525,7 @@ bool bsec_dbgswenable(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), &dev); + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret || !dev) { pr_debug("bsec driver not available\n"); return false; diff --git a/arch/arm/mach-stm32mp/cmd_stm32key.c b/arch/arm/mach-stm32mp/cmd_stm32key.c index f191085a12..544bab3848 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32key.c +++ b/arch/arm/mach-stm32mp/cmd_stm32key.c @@ -31,7 +31,7 @@ static void fuse_hash_value(u32 addr, bool print) int i, ret; ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) { pr_err("Can't find stm32mp_bsec driver\n"); diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c index a777827c55..fc9a2af545 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c @@ -1340,7 +1340,7 @@ int stm32prog_pmic_read(struct stm32prog_data *data, u32 offset, u8 *buffer, pr_debug("%s: %x %lx\n", __func__, offset, *size); ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stpmic1_nvm), + DM_DRIVER_GET(stpmic1_nvm), &dev); if (ret) return ret; @@ -1351,7 +1351,7 @@ int stm32prog_pmic_read(struct stm32prog_data *data, u32 offset, u8 *buffer, memset(data->pmic_part, 0, PMIC_SIZE); ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stpmic1_nvm), + DM_DRIVER_GET(stpmic1_nvm), &dev); if (ret) return ret; @@ -1389,7 +1389,7 @@ int stm32prog_pmic_start(struct stm32prog_data *data) } ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stpmic1_nvm), + DM_DRIVER_GET(stpmic1_nvm), &dev); if (ret) return ret; diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c index 1520c6eaed..29c0d92195 100644 --- a/arch/arm/mach-stm32mp/cpu.c +++ b/arch/arm/mach-stm32mp/cpu.c @@ -318,7 +318,7 @@ static u32 get_otp(int index, int shift, int mask) u32 otp = 0; ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (!ret) @@ -563,7 +563,7 @@ __weak int setup_mac_address(void) return 0; ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) return ret; @@ -601,7 +601,7 @@ static int setup_serial_number(void) return 0; ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) return ret; diff --git a/arch/arm/mach-uniphier/micro-support-card.c b/arch/arm/mach-uniphier/micro-support-card.c index dbd156ffce..95780f79c2 100644 --- a/arch/arm/mach-uniphier/micro-support-card.c +++ b/arch/arm/mach-uniphier/micro-support-card.c @@ -95,7 +95,7 @@ void support_card_init(void) /* The system bus must be initialized for access to the support card. */ ret = uclass_get_device_by_driver(UCLASS_SIMPLE_BUS, - DM_GET_DRIVER(uniphier_system_bus_driver), + DM_DRIVER_GET(uniphier_system_bus_driver), &dev); if (ret) return; diff --git a/arch/arm/mach-zynq/clk.c b/arch/arm/mach-zynq/clk.c index 1ace117fc8..856047613c 100644 --- a/arch/arm/mach-zynq/clk.c +++ b/arch/arm/mach-zynq/clk.c @@ -40,7 +40,7 @@ int set_cpu_clk_info(void) int i, ret; ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(zynq_clk), &dev); + DM_DRIVER_GET(zynq_clk), &dev); if (ret) return ret; @@ -75,7 +75,7 @@ int soc_clk_dump(void) int i, ret; ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(zynq_clk), &dev); + DM_DRIVER_GET(zynq_clk), &dev); if (ret) return ret; diff --git a/arch/arm/mach-zynq/timer.c b/arch/arm/mach-zynq/timer.c index cc0e24cbfe..37193157d9 100644 --- a/arch/arm/mach-zynq/timer.c +++ b/arch/arm/mach-zynq/timer.c @@ -68,7 +68,7 @@ int timer_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(zynq_clk), &dev); + DM_DRIVER_GET(zynq_clk), &dev); if (ret) return ret; diff --git a/arch/mips/mach-mtmips/mt7628/init.c b/arch/mips/mach-mtmips/mt7628/init.c index 77d1f2ea0d..33538647a2 100644 --- a/arch/mips/mach-mtmips/mt7628/init.c +++ b/arch/mips/mach-mtmips/mt7628/init.c @@ -74,7 +74,7 @@ int print_cpuinfo(void) ddr ? "" : "2", chipmode & 0x01 ? 4 : 3, chipmode & 0x02 ? "XTAL" : "CPLL"); - ret = uclass_get_device_by_driver(UCLASS_CLK, DM_GET_DRIVER(mt7628_clk), + ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(mt7628_clk), &clkdev); if (ret) return ret; diff --git a/arch/riscv/lib/sifive_clint.c b/arch/riscv/lib/sifive_clint.c index c8079dc510..cfa288a01a 100644 --- a/arch/riscv/lib/sifive_clint.c +++ b/arch/riscv/lib/sifive_clint.c @@ -25,7 +25,7 @@ int riscv_init_ipi(void) struct udevice *dev; ret = uclass_get_device_by_driver(UCLASS_TIMER, - DM_GET_DRIVER(sifive_clint), &dev); + DM_DRIVER_GET(sifive_clint), &dev); if (ret) return ret; diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c index f42d395098..35669c252b 100644 --- a/board/dhelectronics/dh_stm32mp1/board.c +++ b/board/dhelectronics/dh_stm32mp1/board.c @@ -343,7 +343,7 @@ int g_dnl_board_usb_cable_connected(void) int ret; ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC, - DM_GET_DRIVER(dwc2_udc_otg), + DM_DRIVER_GET(dwc2_udc_otg), &dwc2_udc_otg); if (!ret) debug("dwc2_udc_otg init failed\n"); @@ -475,11 +475,11 @@ static void sysconf_init(void) * but this value need to be consistent with board design */ ret = uclass_get_device_by_driver(UCLASS_PMIC, - DM_GET_DRIVER(stm32mp_pwr_pmic), + DM_DRIVER_GET(stm32mp_pwr_pmic), &pwr_dev); if (!ret) { ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) { pr_err("Can't find stm32mp_bsec driver\n"); diff --git a/board/google/gru/gru.c b/board/google/gru/gru.c index 441a1a376a..23080c1798 100644 --- a/board/google/gru/gru.c +++ b/board/google/gru/gru.c @@ -45,7 +45,7 @@ int board_early_init_r(void) * setting up. */ ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(clk_rk3399), &clk); + DM_DRIVER_GET(clk_rk3399), &clk); if (ret) { debug("%s: CLK init failed: %d\n", __func__, ret); return ret; diff --git a/board/nvidia/jetson-tk1/jetson-tk1.c b/board/nvidia/jetson-tk1/jetson-tk1.c index 9eccdc4a83..d349531261 100644 --- a/board/nvidia/jetson-tk1/jetson-tk1.c +++ b/board/nvidia/jetson-tk1/jetson-tk1.c @@ -60,7 +60,7 @@ int tegra_pcie_board_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_PMIC, - DM_GET_DRIVER(pmic_as3722), &dev); + DM_DRIVER_GET(pmic_as3722), &dev); if (ret) { debug("%s: Failed to find PMIC\n", __func__); return ret; diff --git a/board/nvidia/nyan-big/nyan-big.c b/board/nvidia/nyan-big/nyan-big.c index 71c71ed6ec..06a36f8ed3 100644 --- a/board/nvidia/nyan-big/nyan-big.c +++ b/board/nvidia/nyan-big/nyan-big.c @@ -52,7 +52,7 @@ int tegra_lcd_pmic_init(int board_id) int ret; ret = uclass_get_device_by_driver(UCLASS_PMIC, - DM_GET_DRIVER(pmic_as3722), &dev); + DM_DRIVER_GET(pmic_as3722), &dev); if (ret) { debug("%s: Failed to find PMIC\n", __func__); return ret; diff --git a/board/renesas/ulcb/cpld.c b/board/renesas/ulcb/cpld.c index e3fa3526b7..ebb2d6f742 100644 --- a/board/renesas/ulcb/cpld.c +++ b/board/renesas/ulcb/cpld.c @@ -91,7 +91,7 @@ static int do_cpld(struct cmd_tbl *cmdtp, int flag, int argc, int ret; ret = uclass_get_device_by_driver(UCLASS_SYSRESET, - DM_GET_DRIVER(sysreset_renesas_ulcb), + DM_DRIVER_GET(sysreset_renesas_ulcb), &dev); if (ret) return ret; diff --git a/board/sifive/fu540/fu540.c b/board/sifive/fu540/fu540.c index 54e5a4c167..a4e78220cb 100644 --- a/board/sifive/fu540/fu540.c +++ b/board/sifive/fu540/fu540.c @@ -58,7 +58,7 @@ static u32 fu540_read_serialnum(void) /* init OTP */ ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(sifive_otp), &dev); + DM_DRIVER_GET(sifive_otp), &dev); if (ret) { debug("%s: could not find otp device\n", __func__); diff --git a/board/st/common/cmd_stboard.c b/board/st/common/cmd_stboard.c index e1038619f0..2fba383168 100644 --- a/board/st/common/cmd_stboard.c +++ b/board/st/common/cmd_stboard.c @@ -85,7 +85,7 @@ static int do_stboard(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_USAGE; ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); ret = misc_read(dev, STM32_BSEC_OTP(BSEC_OTP_BOARD), diff --git a/board/st/common/stm32mp_dfu.c b/board/st/common/stm32mp_dfu.c index aab7d741ac..9c3d115dce 100644 --- a/board/st/common/stm32mp_dfu.c +++ b/board/st/common/stm32mp_dfu.c @@ -163,7 +163,7 @@ static int dfu_otp_read(u64 offset, u8 *buffer, long *size) int ret; ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) return ret; @@ -184,7 +184,7 @@ static int dfu_pmic_read(u64 offset, u8 *buffer, long *size) struct udevice *dev; ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stpmic1_nvm), + DM_DRIVER_GET(stpmic1_nvm), &dev); if (ret) return ret; diff --git a/board/st/common/stpmic1.c b/board/st/common/stpmic1.c index 3aa379e8a5..a313b817c5 100644 --- a/board/st/common/stpmic1.c +++ b/board/st/common/stpmic1.c @@ -20,7 +20,7 @@ int board_ddr_power_init(enum ddr_type ddr_type) u32 buck2; ret = uclass_get_device_by_driver(UCLASS_PMIC, - DM_GET_DRIVER(pmic_stpmic1), &dev); + DM_DRIVER_GET(pmic_stpmic1), &dev); if (ret) /* No PMIC on board */ return 0; @@ -187,7 +187,7 @@ void stpmic1_init(u32 voltage_mv) struct udevice *dev; if (uclass_get_device_by_driver(UCLASS_PMIC, - DM_GET_DRIVER(pmic_stpmic1), &dev)) + DM_DRIVER_GET(pmic_stpmic1), &dev)) return; /* update VDDCORE = BUCK1 */ diff --git a/board/st/common/stusb160x.c b/board/st/common/stusb160x.c index f1197f9faa..e0a2b76353 100644 --- a/board/st/common/stusb160x.c +++ b/board/st/common/stusb160x.c @@ -22,7 +22,7 @@ int stusb160x_cable_connected(void) int ret; ret = uclass_get_device_by_driver(UCLASS_I2C_GENERIC, - DM_GET_DRIVER(stusb160x), + DM_DRIVER_GET(stusb160x), &dev); if (ret < 0) return ret; diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 8a3ce0a6f5..08393b27eb 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -116,7 +116,7 @@ int checkboard(void) /* display the STMicroelectronics board identification */ if (CONFIG_IS_ENABLED(CMD_STBOARD)) { ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (!ret) ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD), @@ -196,7 +196,7 @@ int g_dnl_board_usb_cable_connected(void) return ret; ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC, - DM_GET_DRIVER(dwc2_udc_otg), + DM_DRIVER_GET(dwc2_udc_otg), &dwc2_udc_otg); if (!ret) debug("dwc2_udc_otg init failed\n"); @@ -464,11 +464,11 @@ static void sysconf_init(void) * but this value need to be consistent with board design */ ret = uclass_get_device_by_driver(UCLASS_PMIC, - DM_GET_DRIVER(stm32mp_pwr_pmic), + DM_DRIVER_GET(stm32mp_pwr_pmic), &pwr_dev); if (!ret && IS_ENABLED(CONFIG_DM_REGULATOR)) { ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) { pr_err("Can't find stm32mp_bsec driver\n"); @@ -618,7 +618,7 @@ static void board_ev1_init(void) struct udevice *dev; /* configure IRQ line on EV1 for touchscreen before LCD reset */ - uclass_get_device_by_driver(UCLASS_NOP, DM_GET_DRIVER(goodix), &dev); + uclass_get_device_by_driver(UCLASS_NOP, DM_DRIVER_GET(goodix), &dev); } /* board dependent setup after realloc */ @@ -680,7 +680,7 @@ int board_late_init(void) } } ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (!ret) diff --git a/board/ti/j721e/evm.c b/board/ti/j721e/evm.c index d8711eb900..44969e80b4 100644 --- a/board/ti/j721e/evm.c +++ b/board/ti/j721e/evm.c @@ -411,7 +411,7 @@ void spl_board_init(void) #ifdef CONFIG_ESM_K3 if (board_ti_k3_is("J721EX-PM2-SOM")) { ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(k3_esm), &dev); + DM_DRIVER_GET(k3_esm), &dev); if (ret) printf("ESM init failed: %d\n", ret); } @@ -420,7 +420,7 @@ void spl_board_init(void) #ifdef CONFIG_ESM_PMIC if (board_ti_k3_is("J721EX-PM2-SOM")) { ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(pmic_esm), + DM_DRIVER_GET(pmic_esm), &dev); if (ret) printf("ESM PMIC init failed: %d\n", ret); diff --git a/board/toradex/apalis-tk1/apalis-tk1.c b/board/toradex/apalis-tk1/apalis-tk1.c index e7a2186c2c..b97617cfca 100644 --- a/board/toradex/apalis-tk1/apalis-tk1.c +++ b/board/toradex/apalis-tk1/apalis-tk1.c @@ -155,7 +155,7 @@ int tegra_pcie_board_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_PMIC, - DM_GET_DRIVER(pmic_as3722), &dev); + DM_DRIVER_GET(pmic_as3722), &dev); if (ret) { pr_err("failed to find AS3722 PMIC: %d\n", ret); return ret; @@ -194,7 +194,7 @@ void tegra_pcie_board_port_reset(struct tegra_pcie_port *port) int ret; ret = uclass_get_device_by_driver(UCLASS_PMIC, - DM_GET_DRIVER(pmic_as3722), + DM_DRIVER_GET(pmic_as3722), &dev); if (ret) { debug("%s: Failed to find PMIC\n", __func__); diff --git a/drivers/clk/clk_stm32mp1.c b/drivers/clk/clk_stm32mp1.c index 72cbcdf6a2..5bea2b60b9 100644 --- a/drivers/clk/clk_stm32mp1.c +++ b/drivers/clk/clk_stm32mp1.c @@ -2253,7 +2253,7 @@ int soc_clk_dump(void) int ret; ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(stm32mp1_clock), + DM_DRIVER_GET(stm32mp1_clock), &dev); if (ret) return ret; diff --git a/drivers/clk/clk_zynqmp.c b/drivers/clk/clk_zynqmp.c index a9988d8f1a..e8acca0066 100644 --- a/drivers/clk/clk_zynqmp.c +++ b/drivers/clk/clk_zynqmp.c @@ -617,7 +617,7 @@ int soc_clk_dump(void) int i, ret; ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(zynqmp_clk), &dev); + DM_DRIVER_GET(zynqmp_clk), &dev); if (ret) return ret; diff --git a/drivers/clk/imx/clk-imx8.c b/drivers/clk/imx/clk-imx8.c index 27a652a625..8484613eed 100644 --- a/drivers/clk/imx/clk-imx8.c +++ b/drivers/clk/imx/clk-imx8.c @@ -51,7 +51,7 @@ int soc_clk_dump(void) int i, ret; ret = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(imx8_clk), &dev); + DM_DRIVER_GET(imx8_clk), &dev); if (ret) return ret; diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index 388471b03a..d43b8a0648 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -296,7 +296,7 @@ static ulong mtk_topckgen_get_factor_rate(struct clk *clk, u32 off) switch (fdiv->flags & CLK_PARENT_MASK) { case CLK_PARENT_APMIXED: rate = mtk_clk_find_parent_rate(clk, fdiv->parent, - DM_GET_DRIVER(mtk_clk_apmixedsys)); + DM_DRIVER_GET(mtk_clk_apmixedsys)); break; case CLK_PARENT_TOPCKGEN: rate = mtk_clk_find_parent_rate(clk, fdiv->parent, NULL); @@ -474,11 +474,11 @@ static ulong mtk_clk_gate_get_rate(struct clk *clk) switch (gate->flags & CLK_PARENT_MASK) { case CLK_PARENT_APMIXED: return mtk_clk_find_parent_rate(clk, gate->parent, - DM_GET_DRIVER(mtk_clk_apmixedsys)); + DM_DRIVER_GET(mtk_clk_apmixedsys)); break; case CLK_PARENT_TOPCKGEN: return mtk_clk_find_parent_rate(clk, gate->parent, - DM_GET_DRIVER(mtk_clk_topckgen)); + DM_DRIVER_GET(mtk_clk_topckgen)); break; default: diff --git a/drivers/clk/sifive/fu540-prci.c b/drivers/clk/sifive/fu540-prci.c index 9a08c148a0..b3882d0b77 100644 --- a/drivers/clk/sifive/fu540-prci.c +++ b/drivers/clk/sifive/fu540-prci.c @@ -537,7 +537,7 @@ static int __prci_consumer_reset(const char *rst_name, bool trigger) int ret; ret = uclass_get_device_by_driver(UCLASS_RESET, - DM_GET_DRIVER(sifive_reset), + DM_DRIVER_GET(sifive_reset), &dev); if (ret) { dev_err(dev, "Reset driver not found: %d\n", ret); diff --git a/drivers/firmware/scmi/scmi_agent-uclass.c b/drivers/firmware/scmi/scmi_agent-uclass.c index b3d3f0a51b..516e690ac2 100644 --- a/drivers/firmware/scmi/scmi_agent-uclass.c +++ b/drivers/firmware/scmi/scmi_agent-uclass.c @@ -73,11 +73,11 @@ static int scmi_bind_protocols(struct udevice *dev) switch (protocol_id) { case SCMI_PROTOCOL_ID_CLOCK: if (IS_ENABLED(CONFIG_CLK_SCMI)) - drv = DM_GET_DRIVER(scmi_clock); + drv = DM_DRIVER_GET(scmi_clock); break; case SCMI_PROTOCOL_ID_RESET_DOMAIN: if (IS_ENABLED(CONFIG_RESET_SCMI)) - drv = DM_GET_DRIVER(scmi_reset_domain); + drv = DM_DRIVER_GET(scmi_reset_domain); break; default: break; diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 952c111b08..bad6b71e0c 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -306,7 +306,7 @@ int gpio_hog_probe_all(void) for (uclass_first_device(UCLASS_NOP, &dev); dev; uclass_find_next_device(&dev)) { - if (dev->driver == DM_GET_DRIVER(gpio_hog)) { + if (dev->driver == DM_DRIVER_GET(gpio_hog)) { ret = device_probe(dev); if (ret) { printf("Failed to probe device %s err: %d\n", diff --git a/drivers/misc/i2c_eeprom.c b/drivers/misc/i2c_eeprom.c index 9ffd28f597..5926c91a2e 100644 --- a/drivers/misc/i2c_eeprom.c +++ b/drivers/misc/i2c_eeprom.c @@ -131,7 +131,7 @@ static int i2c_eeprom_std_bind(struct udevice *dev) if (!name) continue; - device_bind(dev, DM_GET_DRIVER(i2c_eeprom_partition), name, + device_bind(dev, DM_DRIVER_GET(i2c_eeprom_partition), name, NULL, partition, NULL); } diff --git a/drivers/misc/rockchip-efuse.c b/drivers/misc/rockchip-efuse.c index be25389e0e..083ee65e0a 100644 --- a/drivers/misc/rockchip-efuse.c +++ b/drivers/misc/rockchip-efuse.c @@ -58,7 +58,7 @@ static int dump_efuses(struct cmd_tbl *cmdtp, int flag, /* retrieve the device */ ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(rockchip_efuse), &dev); + DM_DRIVER_GET(rockchip_efuse), &dev); if (ret) { printf("%s: no misc-device found\n", __func__); return 0; diff --git a/drivers/misc/stm32mp_fuse.c b/drivers/misc/stm32mp_fuse.c index 0eed345973..9fd6c367dc 100644 --- a/drivers/misc/stm32mp_fuse.c +++ b/drivers/misc/stm32mp_fuse.c @@ -26,7 +26,7 @@ int fuse_read(u32 bank, u32 word, u32 *val) switch (bank) { case STM32MP_OTP_BANK: ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) return ret; @@ -41,7 +41,7 @@ int fuse_read(u32 bank, u32 word, u32 *val) #ifdef CONFIG_PMIC_STPMIC1 case STM32MP_NVM_BANK: ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stpmic1_nvm), + DM_DRIVER_GET(stpmic1_nvm), &dev); if (ret) return ret; @@ -71,7 +71,7 @@ int fuse_prog(u32 bank, u32 word, u32 val) switch (bank) { case STM32MP_OTP_BANK: ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) return ret; @@ -86,7 +86,7 @@ int fuse_prog(u32 bank, u32 word, u32 val) #ifdef CONFIG_PMIC_STPMIC1 case STM32MP_NVM_BANK: ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stpmic1_nvm), + DM_DRIVER_GET(stpmic1_nvm), &dev); if (ret) return ret; @@ -115,7 +115,7 @@ int fuse_sense(u32 bank, u32 word, u32 *val) switch (bank) { case STM32MP_OTP_BANK: ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) return ret; @@ -129,7 +129,7 @@ int fuse_sense(u32 bank, u32 word, u32 *val) #ifdef CONFIG_PMIC_STPMIC1 case STM32MP_NVM_BANK: ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stpmic1_nvm), + DM_DRIVER_GET(stpmic1_nvm), &dev); if (ret) return ret; @@ -159,7 +159,7 @@ int fuse_override(u32 bank, u32 word, u32 val) switch (bank) { case STM32MP_OTP_BANK: ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), + DM_DRIVER_GET(stm32mp_bsec), &dev); if (ret) return ret; @@ -174,7 +174,7 @@ int fuse_override(u32 bank, u32 word, u32 val) #ifdef CONFIG_PMIC_STPMIC1 case STM32MP_NVM_BANK: ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stpmic1_nvm), + DM_DRIVER_GET(stpmic1_nvm), &dev); if (ret) return ret; diff --git a/drivers/mtd/nand/raw/arasan_nfc.c b/drivers/mtd/nand/raw/arasan_nfc.c index d4e8f8df87..4621bfb03e 100644 --- a/drivers/mtd/nand/raw/arasan_nfc.c +++ b/drivers/mtd/nand/raw/arasan_nfc.c @@ -1319,7 +1319,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(arasan_nand), &dev); + DM_DRIVER_GET(arasan_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret); } diff --git a/drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c index 71682cb6e7..aa095c439b 100644 --- a/drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c @@ -118,7 +118,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(bcm63158_nand), &dev); + DM_DRIVER_GET(bcm63158_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret); diff --git a/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c index f424194ecc..e4bf193681 100644 --- a/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/bcm6368_nand.c @@ -111,7 +111,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(bcm6368_nand), &dev); + DM_DRIVER_GET(bcm6368_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret); diff --git a/drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c index 47ddde4f9b..586ea3d8fb 100644 --- a/drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/bcm68360_nand.c @@ -117,7 +117,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(bcm68360_nand), &dev); + DM_DRIVER_GET(bcm68360_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret); diff --git a/drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c index 646495096c..85f318bd77 100644 --- a/drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c @@ -117,7 +117,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(bcm6838_nand), &dev); + DM_DRIVER_GET(bcm6838_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret); diff --git a/drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c b/drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c index 7573cd944f..a5e159ad52 100644 --- a/drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c +++ b/drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c @@ -118,7 +118,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(bcm6858_nand), &dev); + DM_DRIVER_GET(bcm6858_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret); diff --git a/drivers/mtd/nand/raw/davinci_nand.c b/drivers/mtd/nand/raw/davinci_nand.c index 4645cc1699..9ad3a57690 100644 --- a/drivers/mtd/nand/raw/davinci_nand.c +++ b/drivers/mtd/nand/raw/davinci_nand.c @@ -825,7 +825,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(davinci_nand), &dev); + DM_DRIVER_GET(davinci_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize %s: %d\n", dev->name, ret); } diff --git a/drivers/mtd/nand/raw/denali_dt.c b/drivers/mtd/nand/raw/denali_dt.c index 140ef7f725..cf4df0168a 100644 --- a/drivers/mtd/nand/raw/denali_dt.c +++ b/drivers/mtd/nand/raw/denali_dt.c @@ -181,7 +181,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(denali_nand_dt), + DM_DRIVER_GET(denali_nand_dt), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize Denali NAND controller. (error %d)\n", diff --git a/drivers/mtd/nand/raw/mxs_nand_dt.c b/drivers/mtd/nand/raw/mxs_nand_dt.c index 78a423dbbf..878796d555 100644 --- a/drivers/mtd/nand/raw/mxs_nand_dt.c +++ b/drivers/mtd/nand/raw/mxs_nand_dt.c @@ -177,7 +177,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(mxs_nand_dt), + DM_DRIVER_GET(mxs_nand_dt), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize MXS NAND controller. (error %d)\n", diff --git a/drivers/mtd/nand/raw/octeontx_nand.c b/drivers/mtd/nand/raw/octeontx_nand.c index 64433cf6cc..9997135ef9 100644 --- a/drivers/mtd/nand/raw/octeontx_nand.c +++ b/drivers/mtd/nand/raw/octeontx_nand.c @@ -2233,14 +2233,14 @@ void board_nand_init(void) if (IS_ENABLED(CONFIG_NAND_OCTEONTX_HW_ECC)) { ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(octeontx_pci_bchpf), + DM_DRIVER_GET(octeontx_pci_bchpf), &dev); if (ret && ret != -ENODEV) { pr_err("Failed to initialize OcteonTX BCH PF controller. (error %d)\n", ret); } ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(octeontx_pci_bchvf), + DM_DRIVER_GET(octeontx_pci_bchvf), &dev); if (ret && ret != -ENODEV) { pr_err("Failed to initialize OcteonTX BCH VF controller. (error %d)\n", @@ -2249,7 +2249,7 @@ void board_nand_init(void) } ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(octeontx_pci_nand), + DM_DRIVER_GET(octeontx_pci_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize OcteonTX NAND controller. (error %d)\n", diff --git a/drivers/mtd/nand/raw/pxa3xx_nand.c b/drivers/mtd/nand/raw/pxa3xx_nand.c index e923ce363a..f6233756d8 100644 --- a/drivers/mtd/nand/raw/pxa3xx_nand.c +++ b/drivers/mtd/nand/raw/pxa3xx_nand.c @@ -1947,7 +1947,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(pxa3xx_nand), &dev); + DM_DRIVER_GET(pxa3xx_nand), &dev); if (ret && ret != -ENODEV) { pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret); diff --git a/drivers/mtd/nand/raw/stm32_fmc2_nand.c b/drivers/mtd/nand/raw/stm32_fmc2_nand.c index 8fe7ec1343..b8561b2516 100644 --- a/drivers/mtd/nand/raw/stm32_fmc2_nand.c +++ b/drivers/mtd/nand/raw/stm32_fmc2_nand.c @@ -1042,7 +1042,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(stm32_fmc2_nfc), + DM_DRIVER_GET(stm32_fmc2_nfc), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize STM32 FMC2 NFC controller. (error %d)\n", diff --git a/drivers/mtd/nand/raw/tegra_nand.c b/drivers/mtd/nand/raw/tegra_nand.c index 797fc23050..a530127cb7 100644 --- a/drivers/mtd/nand/raw/tegra_nand.c +++ b/drivers/mtd/nand/raw/tegra_nand.c @@ -999,7 +999,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(tegra_nand), &dev); + DM_DRIVER_GET(tegra_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret); diff --git a/drivers/mtd/nand/raw/vf610_nfc.c b/drivers/mtd/nand/raw/vf610_nfc.c index 422b9c57a8..e33953ec7c 100644 --- a/drivers/mtd/nand/raw/vf610_nfc.c +++ b/drivers/mtd/nand/raw/vf610_nfc.c @@ -794,7 +794,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(vf610_nfc_dt), + DM_DRIVER_GET(vf610_nfc_dt), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize NAND controller. (error %d)\n", diff --git a/drivers/mtd/nand/raw/zynq_nand.c b/drivers/mtd/nand/raw/zynq_nand.c index 7cf0ccb656..15d4a238e6 100644 --- a/drivers/mtd/nand/raw/zynq_nand.c +++ b/drivers/mtd/nand/raw/zynq_nand.c @@ -1295,7 +1295,7 @@ void board_nand_init(void) int ret; ret = uclass_get_device_by_driver(UCLASS_MTD, - DM_GET_DRIVER(zynq_nand), &dev); + DM_DRIVER_GET(zynq_nand), &dev); if (ret && ret != -ENODEV) pr_err("Failed to initialize %s. (error %d)\n", dev->name, ret); } diff --git a/drivers/reset/reset-ast2500.c b/drivers/reset/reset-ast2500.c index a229d490f3..c3d650fc6b 100644 --- a/drivers/reset/reset-ast2500.c +++ b/drivers/reset/reset-ast2500.c @@ -72,7 +72,7 @@ static int ast2500_reset_probe(struct udevice *dev) /* get SCU base from clock device */ rc = uclass_get_device_by_driver(UCLASS_CLK, - DM_GET_DRIVER(aspeed_ast2500_scu), &scu_dev); + DM_DRIVER_GET(aspeed_ast2500_scu), &scu_dev); if (rc) { debug("%s: clock device not found, rc=%d\n", __func__, rc); return rc; diff --git a/drivers/video/lg4573.c b/drivers/video/lg4573.c index abf40bddfb..dd87fc461b 100644 --- a/drivers/video/lg4573.c +++ b/drivers/video/lg4573.c @@ -219,7 +219,7 @@ static int do_lgset(struct cmd_tbl *cmdtp, int flag, int argc, int ret; ret = uclass_get_device_by_driver(UCLASS_DISPLAY, - DM_GET_DRIVER(lg4573_lcd), &dev); + DM_DRIVER_GET(lg4573_lcd), &dev); if (ret) { printf("%s: Could not get lg4573 device\n", __func__); return ret; diff --git a/include/dm/device.h b/include/dm/device.h index e16ba2405f..6899030105 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -335,7 +335,7 @@ struct driver { ll_entry_declare(struct driver, __name, driver) /* Get a pointer to a given driver */ -#define DM_GET_DRIVER(__name) \ +#define DM_DRIVER_GET(__name) \ ll_entry_get(struct driver, __name, driver) /** diff --git a/include/dm/uclass.h b/include/dm/uclass.h index f06339e4d6..b5f066dbf4 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -264,7 +264,7 @@ int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, * uclass_get_device_by_driver() - Get a uclass device for a driver * * This searches the devices in the uclass for one that uses the given - * driver. Use DM_GET_DRIVER(name) for the @drv argument, where 'name' is + * driver. Use DM_DRIVER_GET(name) for the @drv argument, where 'name' is * the driver name - as used in U_BOOT_DRIVER(name). * * The device is probed to activate it ready for use. diff --git a/test/dm/core.c b/test/dm/core.c index 82b7a668dd..1f5ca570dc 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -1052,7 +1052,7 @@ static int dm_test_inactive_child(struct unit_test_state *uts) */ ut_asserteq(-ENODEV, device_find_first_inactive_child(parent, UCLASS_TEST, &dev1)); - ut_assertok(device_bind(parent, DM_GET_DRIVER(test_drv), + ut_assertok(device_bind(parent, DM_DRIVER_GET(test_drv), "test_child", 0, ofnode_null(), &dev1)); ut_assertok(device_find_first_inactive_child(parent, UCLASS_TEST, diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 711bf20a9c..b53539055b 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -328,7 +328,7 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts) /* Check creating a device with an alias */ node = ofnode_path("/some-bus/c-test@1"); - ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv), + ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv), "c-test@1", NULL, node, &dev)); ut_asserteq(12, dev_seq(dev)); ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev)); @@ -348,11 +348,11 @@ static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts) * * So next available is 19 */ - ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv), + ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv), "fred", NULL, ofnode_null(), &dev)); ut_asserteq(19, dev_seq(dev)); - ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv), + ut_assertok(device_bind(dm_root(), DM_DRIVER_GET(testfdt_drv), "fred2", NULL, ofnode_null(), &dev)); ut_asserteq(20, dev_seq(dev)); -- cgit v1.2.3 From bdf8fd76c0184373bbd31e6ee9a3a9430dcfc485 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:57 -0700 Subject: dm: Rename U_BOOT_DRIVER_ALIAS to DM_DRIVER_ALIAS We use the U_BOOT_ prefix (i.e. U_BOOT_DRIVER) to declare a driver but in every other case we just use DM_. Update the alias macros to use the DM_ prefix. We could perhaps rename U_BOOT_DRIVER() to DM_DRIVER(), but this macro is widely used and there is at least some benefit to indicating it us a U-Boot driver, particularly for code ported from Linux. So for now, let's keep that name. Signed-off-by: Simon Glass --- doc/driver-model/of-plat.rst | 6 +++--- drivers/gpio/mxc_gpio.c | 2 +- drivers/gpio/mxs_gpio.c | 2 +- drivers/gpio/sandbox.c | 2 +- drivers/i2c/rk_i2c.c | 2 +- drivers/mmc/fsl_esdhc_imx.c | 2 +- drivers/mmc/mxsmmc.c | 2 +- drivers/mmc/rockchip_dw_mmc.c | 4 ++-- drivers/mtd/spi/sf_probe.c | 2 +- drivers/pinctrl/nxp/pinctrl-imx6.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 | 6 +++--- drivers/spi/mxs_spi.c | 2 +- drivers/spi/rk_spi.c | 2 +- include/dm/device.h | 2 +- tools/dtoc/dtb_platdata.py | 6 +++--- tools/dtoc/dtoc_test_scan_drivers.cxx | 2 +- 19 files changed, 26 insertions(+), 26 deletions(-) diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst index 21b45f6a7e..78afbdbcc9 100644 --- a/doc/driver-model/of-plat.rst +++ b/doc/driver-model/of-plat.rst @@ -184,7 +184,7 @@ 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 +In order to make this a bit more flexible DM_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. @@ -195,7 +195,7 @@ fix-ups required by dtoc. It is not currently used. The values in 'clocks' are the index of the driver_info for the target device followed by any phandle arguments. This is used to support device_get_by_driver_info_idx(). -During the build process dtoc parses both U_BOOT_DRIVER and U_BOOT_DRIVER_ALIAS +During the build process dtoc parses both U_BOOT_DRIVER and DM_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 @@ -297,7 +297,7 @@ For example: .plat_auto = sizeof(struct mmc_plat), }; - U_BOOT_DRIVER_ALIAS(mmc_drv, vendor_mmc) /* matches compatible string */ + DM_DRIVER_ALIAS(mmc_drv, vendor_mmc) /* matches compatible string */ Note that struct mmc_plat 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 diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c index 6280fb5984..06e6b2279f 100644 --- a/drivers/gpio/mxc_gpio.c +++ b/drivers/gpio/mxc_gpio.c @@ -345,7 +345,7 @@ U_BOOT_DRIVER(gpio_mxc) = { .bind = mxc_gpio_bind, }; -U_BOOT_DRIVER_ALIAS(gpio_mxc, fsl_imx6q_gpio) +DM_DRIVER_ALIAS(gpio_mxc, fsl_imx6q_gpio) #if !CONFIG_IS_ENABLED(OF_CONTROL) static const struct mxc_gpio_plat mxc_plat[] = { diff --git a/drivers/gpio/mxs_gpio.c b/drivers/gpio/mxs_gpio.c index fd5e0ea5c2..4b2b18fdb5 100644 --- a/drivers/gpio/mxs_gpio.c +++ b/drivers/gpio/mxs_gpio.c @@ -306,5 +306,5 @@ U_BOOT_DRIVER(fsl_imx23_gpio) = { #endif }; -U_BOOT_DRIVER_ALIAS(fsl_imx23_gpio, fsl_imx28_gpio) +DM_DRIVER_ALIAS(fsl_imx23_gpio, fsl_imx28_gpio) #endif /* DM_GPIO */ diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c index f8fa4baa2c..dc8d506e8d 100644 --- a/drivers/gpio/sandbox.c +++ b/drivers/gpio/sandbox.c @@ -327,7 +327,7 @@ U_BOOT_DRIVER(sandbox_gpio) = { ACPI_OPS_PTR(&gpio_sandbox_acpi_ops) }; -U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias) +DM_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias) /* pincontrol: used only to check GPIO pin configuration (pinmux command) */ diff --git a/drivers/i2c/rk_i2c.c b/drivers/i2c/rk_i2c.c index 704bafe238..f8fac45b6c 100644 --- a/drivers/i2c/rk_i2c.c +++ b/drivers/i2c/rk_i2c.c @@ -495,4 +495,4 @@ U_BOOT_DRIVER(rockchip_rk3066_i2c) = { .ops = &rockchip_i2c_ops, }; -U_BOOT_DRIVER_ALIAS(rockchip_rk3066_i2c, rockchip_rk3288_i2c) +DM_DRIVER_ALIAS(rockchip_rk3066_i2c, rockchip_rk3288_i2c) diff --git a/drivers/mmc/fsl_esdhc_imx.c b/drivers/mmc/fsl_esdhc_imx.c index 34c2dceb18..c528d345cd 100644 --- a/drivers/mmc/fsl_esdhc_imx.c +++ b/drivers/mmc/fsl_esdhc_imx.c @@ -1711,5 +1711,5 @@ U_BOOT_DRIVER(fsl_esdhc) = { .priv_auto = sizeof(struct fsl_esdhc_priv), }; -U_BOOT_DRIVER_ALIAS(fsl_esdhc, fsl_imx6q_usdhc) +DM_DRIVER_ALIAS(fsl_esdhc, fsl_imx6q_usdhc) #endif diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c index b3fb559a67..8fd4176415 100644 --- a/drivers/mmc/mxsmmc.c +++ b/drivers/mmc/mxsmmc.c @@ -722,5 +722,5 @@ U_BOOT_DRIVER(fsl_imx23_mmc) = { .plat_auto = sizeof(struct mxsmmc_plat), }; -U_BOOT_DRIVER_ALIAS(fsl_imx23_mmc, fsl_imx28_mmc) +DM_DRIVER_ALIAS(fsl_imx23_mmc, fsl_imx28_mmc) #endif /* CONFIG_DM_MMC */ diff --git a/drivers/mmc/rockchip_dw_mmc.c b/drivers/mmc/rockchip_dw_mmc.c index 75db81ba4c..1be3c1741f 100644 --- a/drivers/mmc/rockchip_dw_mmc.c +++ b/drivers/mmc/rockchip_dw_mmc.c @@ -180,8 +180,8 @@ U_BOOT_DRIVER(rockchip_rk3288_dw_mshc) = { .plat_auto = 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) +DM_DRIVER_ALIAS(rockchip_rk3288_dw_mshc, rockchip_rk3328_dw_mshc) +DM_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) diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 630787df1b..6c87434867 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -170,6 +170,6 @@ U_BOOT_DRIVER(jedec_spi_nor) = { .ops = &spi_flash_std_ops, }; -U_BOOT_DRIVER_ALIAS(jedec_spi_nor, spansion_m25p16) +DM_DRIVER_ALIAS(jedec_spi_nor, spansion_m25p16) #endif /* CONFIG_DM_SPI_FLASH */ diff --git a/drivers/pinctrl/nxp/pinctrl-imx6.c b/drivers/pinctrl/nxp/pinctrl-imx6.c index 3cb0bf3b5a..6994dbb61a 100644 --- a/drivers/pinctrl/nxp/pinctrl-imx6.c +++ b/drivers/pinctrl/nxp/pinctrl-imx6.c @@ -52,4 +52,4 @@ U_BOOT_DRIVER(fsl_imx6q_iomuxc) = { .flags = DM_FLAG_PRE_RELOC, }; -U_BOOT_DRIVER_ALIAS(fsl_imx6q_iomuxc, fsl_imx6dl_iomuxc) +DM_DRIVER_ALIAS(fsl_imx6q_iomuxc, fsl_imx6dl_iomuxc) diff --git a/drivers/pinctrl/nxp/pinctrl-mxs.c b/drivers/pinctrl/nxp/pinctrl-mxs.c index 5ada2ac405..449a0aa8b5 100644 --- a/drivers/pinctrl/nxp/pinctrl-mxs.c +++ b/drivers/pinctrl/nxp/pinctrl-mxs.c @@ -192,4 +192,4 @@ U_BOOT_DRIVER(fsl_imx23_pinctrl) = { .ops = &mxs_pinctrl_ops, }; -U_BOOT_DRIVER_ALIAS(fsl_imx23_pinctrl, fsl_imx28_pinctrl) +DM_DRIVER_ALIAS(fsl_imx23_pinctrl, fsl_imx28_pinctrl) diff --git a/drivers/pinctrl/pinctrl-at91.c b/drivers/pinctrl/pinctrl-at91.c index 74bfd3c3dc..ddaad55ddc 100644 --- a/drivers/pinctrl/pinctrl-at91.c +++ b/drivers/pinctrl/pinctrl-at91.c @@ -528,4 +528,4 @@ U_BOOT_DRIVER(atmel_sama5d3_pinctrl) = { .ops = &at91_pinctrl_ops, }; -U_BOOT_DRIVER_ALIAS(atmel_sama5d3_pinctrl, atmel_at91rm9200_pinctrl) +DM_DRIVER_ALIAS(atmel_sama5d3_pinctrl, atmel_at91rm9200_pinctrl) diff --git a/drivers/power/pmic/rk8xx.c b/drivers/power/pmic/rk8xx.c index 2f547a314d..5f442fea68 100644 --- a/drivers/power/pmic/rk8xx.c +++ b/drivers/power/pmic/rk8xx.c @@ -195,4 +195,4 @@ U_BOOT_DRIVER(rockchip_rk805) = { .ops = &rk8xx_ops, }; -U_BOOT_DRIVER_ALIAS(rockchip_rk805, rockchip_rk808) +DM_DRIVER_ALIAS(rockchip_rk805, rockchip_rk808) diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 508c134b94..65c6db073e 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -621,9 +621,9 @@ U_BOOT_DRIVER(ns16550_serial) = { #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) +DM_DRIVER_ALIAS(ns16550_serial, rockchip_rk3328_uart) +DM_DRIVER_ALIAS(ns16550_serial, rockchip_rk3368_uart) +DM_DRIVER_ALIAS(ns16550_serial, ti_da830_uart) #endif #endif /* SERIAL_PRESENT */ diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c index 7f632d98bb..d41352a0bb 100644 --- a/drivers/spi/mxs_spi.c +++ b/drivers/spi/mxs_spi.c @@ -493,4 +493,4 @@ U_BOOT_DRIVER(fsl_imx23_spi) = { .probe = mxs_spi_probe, }; -U_BOOT_DRIVER_ALIAS(fsl_imx23_spi, fsl_imx28_spi) +DM_DRIVER_ALIAS(fsl_imx23_spi, fsl_imx28_spi) diff --git a/drivers/spi/rk_spi.c b/drivers/spi/rk_spi.c index 51abebb947..40bd8851b7 100644 --- a/drivers/spi/rk_spi.c +++ b/drivers/spi/rk_spi.c @@ -565,4 +565,4 @@ U_BOOT_DRIVER(rockchip_rk3288_spi) = { .probe = rockchip_spi_probe, }; -U_BOOT_DRIVER_ALIAS(rockchip_rk3288_spi, rockchip_rk3368_spi) +DM_DRIVER_ALIAS(rockchip_rk3288_spi, rockchip_rk3368_spi) diff --git a/include/dm/device.h b/include/dm/device.h index 6899030105..f5b4cd6876 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -343,7 +343,7 @@ struct driver { * produce no code but its information will be parsed by tools like * dtoc */ -#define U_BOOT_DRIVER_ALIAS(__name, __alias) +#define DM_DRIVER_ALIAS(__name, __alias) /** * dev_get_plat() - Get the platform data for a device diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 1a6a511b01..e12aaa5399 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -187,7 +187,7 @@ class DtbPlatdata(): value: Driver for that driver _driver_aliases: Dict that holds aliases for driver names key: Driver alias declared with - U_BOOT_DRIVER_ALIAS(driver_alias, driver_name) + DM_DRIVER_ALIAS(driver_alias, driver_name) value: Driver name declared with U_BOOT_DRIVER(driver_name) _drivers_additional: List of additional drivers to use during scanning _dirname: Directory to hold output files, or None for none (all files @@ -416,9 +416,9 @@ class DtbPlatdata(): self._drivers[driver] = Driver(driver) # The following re will search for driver aliases declared as - # U_BOOT_DRIVER_ALIAS(alias, driver_name) + # DM_DRIVER_ALIAS(alias, driver_name) driver_aliases = re.findall( - r'U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', + r'DM_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', buff) for alias in driver_aliases: # pragma: no cover diff --git a/tools/dtoc/dtoc_test_scan_drivers.cxx b/tools/dtoc/dtoc_test_scan_drivers.cxx index 557c692ba2..f448767670 100644 --- a/tools/dtoc/dtoc_test_scan_drivers.cxx +++ b/tools/dtoc/dtoc_test_scan_drivers.cxx @@ -1 +1 @@ -U_BOOT_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias2) +DM_DRIVER_ALIAS(sandbox_gpio, sandbox_gpio_alias2) -- cgit v1.2.3 From fe2400895ba0957b332926784daf21143f0f4835 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:58 -0700 Subject: concurrencytest: Fix Python3 warning This gives a warning in some situations: File "tools/dtoc/../concurrencytest/concurrencytest.py", line 95, in do_fork stream = os.fdopen(c2pread, 'rb', 1) File "/usr/lib/python3.8/os.py", line 1023, in fdopen return io.open(fd, *args, **kwargs) RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used Fix this by dropping the line-buffer parameter. Signed-off-by: Simon Glass --- tools/concurrencytest/concurrencytest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/concurrencytest/concurrencytest.py b/tools/concurrencytest/concurrencytest.py index 418d7eed21..5e88b94f41 100644 --- a/tools/concurrencytest/concurrencytest.py +++ b/tools/concurrencytest/concurrencytest.py @@ -68,7 +68,7 @@ def fork_for_tests(concurrency_num=CPU_COUNT): pid = os.fork() if pid == 0: try: - stream = os.fdopen(c2pwrite, 'wb', 1) + stream = os.fdopen(c2pwrite, 'wb') os.close(c2pread) # Leave stderr and stdout open so we can see test noise # Close stdin so that the child goes away if it decides to @@ -92,7 +92,7 @@ def fork_for_tests(concurrency_num=CPU_COUNT): os._exit(0) else: os.close(c2pwrite) - stream = os.fdopen(c2pread, 'rb', 1) + stream = os.fdopen(c2pread, 'rb') test = ProtocolTestCase(stream) result.append(test) return result -- cgit v1.2.3 From 5d9a3aa99cc7a1ed6502a98152bd0e13b4e05539 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:34:59 -0700 Subject: dtoc: Run tests using test_util Use the standard function for running tests and reported results. This allows the tests to run in parallel, which is a significant speed-up on most machines (e.g. 4.5 seconds -> 1.5s on mine). Signed-off-by: Simon Glass --- tools/dtoc/main.py | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py index f82ee78268..9d0b3915c0 100755 --- a/tools/dtoc/main.py +++ b/tools/dtoc/main.py @@ -38,10 +38,11 @@ sys.path.insert(0, os.path.join(our_path, from dtoc import dtb_platdata from patman import test_util -def run_tests(args): +def run_tests(processes, args): """Run all the test we have for dtoc Args: + processes: Number of processes to use to run tests (None=same as #CPUs) args: List of positional args provided to dtoc. This can hold a test name to execute (as in 'dtoc -t test_empty_file', for example) """ @@ -50,25 +51,13 @@ def run_tests(args): result = unittest.TestResult() sys.argv = [sys.argv[0]] test_name = args and args[0] or None - for module in (test_dtoc.TestDtoc,): - if test_name: - try: - suite = unittest.TestLoader().loadTestsFromName(test_name, module) - except AttributeError: - continue - else: - suite = unittest.TestLoader().loadTestsFromTestCase(module) - suite.run(result) - - print(result) - for _, err in result.errors: - print(err) - for _, err in result.failures: - print(err) - if result.errors or result.failures: - print('dtoc tests FAILED') - return 1 - return 0 + + test_util.RunTestSuites( + result, debug=True, verbosity=1, test_preserve_dirs=False, + processes=processes, test_name=test_name, toolpath=[], + test_class_list=[test_dtoc.TestDtoc,]) + + return test_util.ReportResult('binman', test_name, result) def RunTestCoverage(): """Run the tests and check that we get 100% coverage""" @@ -103,7 +92,7 @@ parser.add_option('-T', '--test-coverage', action='store_true', # Run our meagre tests if options.test: - ret_code = run_tests(args) + ret_code = run_tests(options.processes, args) sys.exit(ret_code) elif options.test_coverage: -- cgit v1.2.3 From d1055d681af40963d1c4b1a517ae131f738983f4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:00 -0700 Subject: dtoc: Add a header comment to each generated file It is currently fairly obvious what the two generated files are for, but this will change as more are added. It is helpful for readers to describe the purpose of each file. Add a header commment field to OutputFile and use it to generate a comment at the top of each file. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 30 ++++++++++++++++++++---------- tools/dtoc/test_dtoc.py | 6 ++++-- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index e12aaa5399..b3d777e0c5 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -56,8 +56,10 @@ class Ftype(IntEnum): # This holds information about each type of output file dtoc can create # type: Type of file (Ftype) -# fname: Filename excluding directory, e.g. 'dt-platdata.c' -OutputFile = collections.namedtuple('OutputFile', ['ftype', 'fname']) +# fname: Filename excluding directory, e.g. 'dt-plat.c' +# hdr_comment: Comment explaining the purpose of the file +OutputFile = collections.namedtuple('OutputFile', + ['ftype', 'fname', 'hdr_comment']) # This holds information about a property which includes phandles. # @@ -331,15 +333,20 @@ class DtbPlatdata(): self._lines = [] return lines - def out_header(self): - """Output a message indicating that this is an auto-generated file""" + def out_header(self, outfile): + """Output a message indicating that this is an auto-generated file + + Args: + outfile: OutputFile describing the file being generated + """ self.out('''/* * DO NOT MODIFY * - * This file was generated by dtoc from a .dtb (device tree binary) file. + * %s. + * This was generated by dtoc from a .dtb (device tree binary) file. */ -''') +''' % outfile.hdr_comment) def get_phandle_argc(self, prop, node_name): """Check if a node contains phandles @@ -646,7 +653,6 @@ class DtbPlatdata(): value: Prop object with field information """ - self.out_header() self.out('#include \n') self.out('#include \n') @@ -789,7 +795,6 @@ class DtbPlatdata(): See the documentation in doc/driver-model/of-plat.rst for more information. """ - self.out_header() self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n') self.out('#define DT_PLATDATA_C\n') self.out('\n') @@ -823,8 +828,12 @@ class DtbPlatdata(): # key: Command used to generate this file # value: OutputFile for this command OUTPUT_FILES = { - 'struct': OutputFile(Ftype.HEADER, 'dt-structs-gen.h'), - 'platdata': OutputFile(Ftype.SOURCE, 'dt-platdata.c'), + 'struct': + OutputFile(Ftype.HEADER, 'dt-structs-gen.h', + 'Defines the structs used to hold devicetree data'), + 'platdata': + OutputFile(Ftype.SOURCE, 'dt-platdata.c', + 'Declares the U_BOOT_DRIVER() records and platform data'), } @@ -872,6 +881,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, (cmd, ', '.join(sorted(OUTPUT_FILES.keys())))) plat.setup_output(outfile.ftype, outfile.fname if output_dirs else output) + plat.out_header(outfile) if cmd == 'struct': plat.generate_structs(structs) elif cmd == 'platdata': diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index dbd4e3bf1d..2e4dd2b24d 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -32,7 +32,8 @@ OUR_PATH = os.path.dirname(os.path.realpath(__file__)) HEADER = '''/* * DO NOT MODIFY * - * This file was generated by dtoc from a .dtb (device tree binary) file. + * Defines the structs used to hold devicetree data. + * This was generated by dtoc from a .dtb (device tree binary) file. */ #include @@ -41,7 +42,8 @@ HEADER = '''/* C_HEADER = '''/* * DO NOT MODIFY * - * This file was generated by dtoc from a .dtb (device tree binary) file. + * Declares the U_BOOT_DRIVER() records and platform data. + * This was generated by dtoc from a .dtb (device tree binary) file. */ /* Allow use of U_BOOT_DRVINFO() in this file */ -- cgit v1.2.3 From f31fa99a9ed92c223fbf56e07eae57e7bdea19ae Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:01 -0700 Subject: dtoc: Rename dt-platdata.c to dt-plat.c Use this new name to be consistent with the rest of U-Boot, which talks about 'plat' for the platform data, which is what this file holds. Signed-off-by: Simon Glass --- include/dm/platdata.h | 2 +- include/linux/mtd/spi-nor.h | 2 +- scripts/Makefile.spl | 2 +- tools/dtoc/dtb_platdata.py | 4 ++-- tools/dtoc/test_dtoc.py | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/dm/platdata.h b/include/dm/platdata.h index df1f6abcc7..dc3cbfcbc7 100644 --- a/include/dm/platdata.h +++ b/include/dm/platdata.h @@ -59,7 +59,7 @@ struct driver_rt { * When of-platdata is in use, U_BOOT_DRVINFO() cannot be used outside of the * dt-plat.c file created by dtoc */ -#if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLATDATA_C) +#if CONFIG_IS_ENABLED(OF_PLATDATA) && !defined(DT_PLAT_C) #define U_BOOT_DRVINFO(__name) _Static_assert(false, \ "Cannot use U_BOOT_DRVINFO with of-platdata. Please use devicetree instead") #else diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 363f2749d7..4a8e19ee4f 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -262,7 +262,7 @@ struct spi_flash { * Defined below (keep this text to enable searching for spi_flash decl) * } */ -#ifndef DT_PLATDATA_C +#ifndef DT_PLAT_C #define spi_flash spi_nor #endif diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index 3d60cf5120..87021e22e5 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -120,7 +120,7 @@ endif u-boot-spl-init := $(head-y) u-boot-spl-main := $(libs-y) ifdef CONFIG_$(SPL_TPL_)OF_PLATDATA -u-boot-spl-platdata := $(obj)/dts/dt-platdata.o +u-boot-spl-platdata := $(obj)/dts/dt-plat.o u-boot-spl-platdata_c := $(patsubst %.o,%.c,$(u-boot-spl-platdata)) endif diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index b3d777e0c5..e07a5d3a1c 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -796,7 +796,7 @@ class DtbPlatdata(): information. """ self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n') - self.out('#define DT_PLATDATA_C\n') + self.out('#define DT_PLAT_C\n') self.out('\n') self.out('#include \n') self.out('#include \n') @@ -832,7 +832,7 @@ OUTPUT_FILES = { OutputFile(Ftype.HEADER, 'dt-structs-gen.h', 'Defines the structs used to hold devicetree data'), 'platdata': - OutputFile(Ftype.SOURCE, 'dt-platdata.c', + OutputFile(Ftype.SOURCE, 'dt-plat.c', 'Declares the U_BOOT_DRIVER() records and platform data'), } diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 2e4dd2b24d..d56cd311fa 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -47,7 +47,7 @@ C_HEADER = '''/* */ /* Allow use of U_BOOT_DRVINFO() in this file */ -#define DT_PLATDATA_C +#define DT_PLAT_C #include #include @@ -979,5 +979,5 @@ U_BOOT_DRVINFO(spl_test2) = { leafs = set(os.path.basename(fname) for fname in fnames) self.assertEqual( - {'dt-structs-gen.h', 'source.dts', 'dt-platdata.c', 'source.dtb'}, + {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'}, leafs) -- cgit v1.2.3 From a7d5f96ef1cf13b83a143d6977e2937bcc1b6c75 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:02 -0700 Subject: dtoc: Add the method for each command to OutputFile Rather than the if/else construct, update OutputFile with the method to call to process each command. This is easier to maintain as the number of commands increases. Rename generate_tables to generate_plat since it better describes what is being generated ('plat' is the U-Boot name for platform data). With this, each output method needs to have the same signature. Store the output structures in a member variable instead of using parameters, to accomplish this. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index e07a5d3a1c..4696ff6309 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -59,7 +59,7 @@ class Ftype(IntEnum): # fname: Filename excluding directory, e.g. 'dt-plat.c' # hdr_comment: Comment explaining the purpose of the file OutputFile = collections.namedtuple('OutputFile', - ['ftype', 'fname', 'hdr_comment']) + ['ftype', 'fname', 'method', 'hdr_comment']) # This holds information about a property which includes phandles. # @@ -194,6 +194,11 @@ class DtbPlatdata(): _drivers_additional: List of additional drivers to use during scanning _dirname: Directory to hold output files, or None for none (all files go to stdout) + _struct_data (dict): OrderedDict of dtplat structures to output + key (str): Node name, as a C identifier + value: dict containing structure fields: + key (str): Field name + value: Prop object with field information """ def __init__(self, dtb_fname, include_disabled, warning_disabled, drivers_additional=None): @@ -208,6 +213,7 @@ class DtbPlatdata(): self._driver_aliases = {} self._drivers_additional = drivers_additional or [] self._dirnames = [None] * len(Ftype) + self._struct_data = collections.OrderedDict() def get_normalized_compat_name(self, node): """Get a node's normalized compat name @@ -570,14 +576,9 @@ class DtbPlatdata(): Once the widest property is determined, all other properties are updated to match that width. - Returns: - dict of dict: dict containing structures: - key (str): Node name, as a C identifier - value: dict containing structure fields: - key (str): Field name - value: Prop object with field information + The results are written to self._struct_data """ - structs = collections.OrderedDict() + structs = self._struct_data for node in self._valid_nodes: node_name, _ = self.get_normalized_compat_name(node) fields = {} @@ -608,8 +609,6 @@ class DtbPlatdata(): if name not in PROP_IGNORE_LIST and name[0] != '#': prop.Widen(struct[name]) - return structs - def scan_phandles(self): """Figure out what phandles each node uses @@ -638,21 +637,14 @@ class DtbPlatdata(): pos += 1 + args - def generate_structs(self, structs): + def generate_structs(self): """Generate struct defintions for the platform data This writes out the body of a header file consisting of structure definitions for node in self._valid_nodes. See the documentation in doc/driver-model/of-plat.rst for more information. - - Args: - structs (dict): dict containing structures: - key (str): Node name, as a C identifier - value: dict containing structure fields: - key (str): Field name - value: Prop object with field information - """ + structs = self._struct_data self.out('#include \n') self.out('#include \n') @@ -785,7 +777,7 @@ class DtbPlatdata(): self.out(''.join(self.get_buf())) - def generate_tables(self): + def generate_plat(self): """Generate device defintions for the platform data This writes out C platform data initialisation data and @@ -830,9 +822,10 @@ class DtbPlatdata(): OUTPUT_FILES = { 'struct': OutputFile(Ftype.HEADER, 'dt-structs-gen.h', + DtbPlatdata.generate_structs, 'Defines the structs used to hold devicetree data'), 'platdata': - OutputFile(Ftype.SOURCE, 'dt-plat.c', + OutputFile(Ftype.SOURCE, 'dt-plat.c', DtbPlatdata.generate_plat, 'Declares the U_BOOT_DRIVER() records and platform data'), } @@ -868,7 +861,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, plat.scan_tree() plat.scan_reg_sizes() plat.setup_output_dirs(output_dirs) - structs = plat.scan_structs() + plat.scan_structs() plat.scan_phandles() cmds = args[0].split(',') @@ -882,8 +875,5 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, plat.setup_output(outfile.ftype, outfile.fname if output_dirs else output) plat.out_header(outfile) - if cmd == 'struct': - plat.generate_structs(structs) - elif cmd == 'platdata': - plat.generate_tables() + outfile.method(plat) plat.finish_output() -- cgit v1.2.3 From 1e0f3f46bd9afed12b331cbe945abd4046250ed5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:03 -0700 Subject: dtoc: Allow specifying the base directory for tests The base directory of U-Boot, where the source is, it currently calculated from the directory of the dtb_platdata.py script. If this is installed elsewhere that will not work. Also it is inconvenient for tests. Add a parameter to allow specifying this base directory. To test this, pass a temporary directory with some files in it and check that they are passed to scan_driver(). Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 18 ++++++++++++------ tools/dtoc/test_dtoc.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 4696ff6309..acb9689ea1 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -199,6 +199,7 @@ class DtbPlatdata(): value: dict containing structure fields: key (str): Field name value: Prop object with field information + _basedir (str): Base directory of source tree """ def __init__(self, dtb_fname, include_disabled, warning_disabled, drivers_additional=None): @@ -214,6 +215,7 @@ class DtbPlatdata(): self._drivers_additional = drivers_additional or [] self._dirnames = [None] * len(Ftype) self._struct_data = collections.OrderedDict() + self._basedir = None def get_normalized_compat_name(self, node): """Get a node's normalized compat name @@ -439,15 +441,17 @@ class DtbPlatdata(): continue self._driver_aliases[alias[1]] = alias[0] - def scan_drivers(self): + def scan_drivers(self, basedir=None): """Scan the driver folders to build a list of driver names and aliases This procedure will populate self._drivers and self._driver_aliases """ - basedir = sys.argv[0].replace('tools/dtoc/dtoc', '') - if basedir == '': - basedir = './' + if not basedir: + basedir = sys.argv[0].replace('tools/dtoc/dtoc', '') + if basedir == '': + basedir = './' + self._basedir = basedir for (dirpath, _, filenames) in os.walk(basedir): for fname in filenames: if not fname.endswith('.c'): @@ -831,7 +835,7 @@ OUTPUT_FILES = { def run_steps(args, dtb_file, include_disabled, output, output_dirs, - warning_disabled=False, drivers_additional=None): + warning_disabled=False, drivers_additional=None, basedir=None): """Run all the steps of the dtoc tool Args: @@ -846,6 +850,8 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, drivers drivers_additional (list): List of additional drivers to use during scanning + basedir (str): Base directory of U-Boot source code. Defaults to the + grandparent of this file's directory Raises: ValueError: if args has no command, or an unknown command """ @@ -856,7 +862,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled, drivers_additional) - plat.scan_drivers() + plat.scan_drivers(basedir) plat.scan_dtb() plat.scan_tree() plat.scan_reg_sizes() diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index d56cd311fa..c517fd5c4e 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -12,9 +12,11 @@ tool. import collections import glob import os +import shutil import struct import tempfile import unittest +from unittest import mock from dtb_platdata import conv_name_to_c from dtb_platdata import get_compat_name @@ -981,3 +983,35 @@ U_BOOT_DRVINFO(spl_test2) = { self.assertEqual( {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'}, leafs) + + def test_scan_dirs(self): + """Test scanning of source directories""" + def add_file(fname): + pathname = os.path.join(indir, fname) + dirname = os.path.dirname(pathname) + os.makedirs(dirname, exist_ok=True) + tools.WriteFile(pathname, '', binary=False) + fname_list.append(pathname) + + try: + outdir = tools.GetOutputDir() + indir = tempfile.mkdtemp(prefix='dtoc.') + dtb_file = get_dtb_file('dtoc_test_simple.dts') + + fname_list = [] + add_file('fname.c') + add_file('dir/fname2.c') + + # Mock out scan_driver and check that it is called with the + # expected files + with mock.patch.object(dtb_platdata.DtbPlatdata, "scan_driver") \ + as mocked: + dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], + True, basedir=indir) + self.assertEqual(2, len(mocked.mock_calls)) + self.assertEqual(mock.call(fname_list[0]), + mocked.mock_calls[0]) + self.assertEqual(mock.call(fname_list[1]), + mocked.mock_calls[1]) + finally: + shutil.rmtree(indir) -- cgit v1.2.3 From 9eca08dc5986c9e00bb68a4529ec9404a282bc57 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:04 -0700 Subject: dtoc: Output nodes in order Previously we had to worry about nodes being output before those that they depended on, thus causing build errors. So the current algorithm is careful to output nodes in the right order. We now use a different method for outputting phandles that does not involve pointers. Also we plan to add a 'declarations' header file to declare all drivers as 'extern'. Update the code to drop the dependency checking and output in a simple loop. This makes the output easier to follow since drivers are in order of thier indices (0, 1, ...), which is also the order it appears in in the linker list. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 13 ++-------- tools/dtoc/test_dtoc.py | 64 +++++++++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index acb9689ea1..4cdbd60c9a 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -798,18 +798,9 @@ class DtbPlatdata(): self.out('#include \n') self.out('#include \n') self.out('\n') - nodes_to_output = list(self._valid_nodes) - - # Keep outputing nodes until there is none left - while nodes_to_output: - node = nodes_to_output[0] - # Output all the node's dependencies first - for req_node in node.phandles: - if req_node in nodes_to_output: - self.output_node(req_node) - nodes_to_output.remove(req_node) + + for node in self._valid_nodes: self.output_node(node) - nodes_to_output.remove(node) # Define dm_populate_phandle_data() which will add the linking between # nodes using DM_DRVINFO_GET diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index c517fd5c4e..f17d2e4b45 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -422,17 +422,6 @@ U_BOOT_DRVINFO(phandle3_target) = { \t.parent_idx\t= -1, }; -/* Node /phandle-target index 4 */ -static struct dtd_target dtv_phandle_target = { -\t.intval\t\t\t= 0x0, -}; -U_BOOT_DRVINFO(phandle_target) = { -\t.name\t\t= "target", -\t.plat\t= &dtv_phandle_target, -\t.plat_size\t= sizeof(dtv_phandle_target), -\t.parent_idx\t= -1, -}; - /* Node /phandle-source index 2 */ static struct dtd_source dtv_phandle_source = { \t.clocks\t\t\t= { @@ -460,6 +449,17 @@ U_BOOT_DRVINFO(phandle_source2) = { \t.parent_idx\t= -1, }; +/* Node /phandle-target index 4 */ +static struct dtd_target dtv_phandle_target = { +\t.intval\t\t\t= 0x0, +}; +U_BOOT_DRVINFO(phandle_target) = { +\t.name\t\t= "target", +\t.plat\t= &dtv_phandle_target, +\t.plat_size\t= sizeof(dtv_phandle_target), +\t.parent_idx\t= -1, +}; + void dm_populate_phandle_data(void) { } ''', data) @@ -488,16 +488,6 @@ struct dtd_target { with open(output) as infile: data = infile.read() self._check_strings(C_HEADER + ''' -/* Node /phandle-target index 1 */ -static struct dtd_target dtv_phandle_target = { -}; -U_BOOT_DRVINFO(phandle_target) = { -\t.name\t\t= "target", -\t.plat\t= &dtv_phandle_target, -\t.plat_size\t= sizeof(dtv_phandle_target), -\t.parent_idx\t= -1, -}; - /* Node /phandle-source2 index 0 */ static struct dtd_source dtv_phandle_source2 = { \t.clocks\t\t\t= { @@ -510,6 +500,16 @@ U_BOOT_DRVINFO(phandle_source2) = { \t.parent_idx\t= -1, }; +/* Node /phandle-target index 1 */ +static struct dtd_target dtv_phandle_target = { +}; +U_BOOT_DRVINFO(phandle_target) = { +\t.name\t\t= "target", +\t.plat\t= &dtv_phandle_target, +\t.plat_size\t= sizeof(dtv_phandle_target), +\t.parent_idx\t= -1, +}; + void dm_populate_phandle_data(void) { } ''', data) @@ -544,17 +544,6 @@ U_BOOT_DRVINFO(phandle3_target) = { \t.parent_idx\t= -1, }; -/* Node /phandle-target index 4 */ -static struct dtd_target dtv_phandle_target = { -\t.intval\t\t\t= 0x0, -}; -U_BOOT_DRVINFO(phandle_target) = { -\t.name\t\t= "target", -\t.plat\t= &dtv_phandle_target, -\t.plat_size\t= sizeof(dtv_phandle_target), -\t.parent_idx\t= -1, -}; - /* Node /phandle-source index 2 */ static struct dtd_source dtv_phandle_source = { \t.cd_gpios\t\t= { @@ -582,6 +571,17 @@ U_BOOT_DRVINFO(phandle_source2) = { \t.parent_idx\t= -1, }; +/* Node /phandle-target index 4 */ +static struct dtd_target dtv_phandle_target = { +\t.intval\t\t\t= 0x0, +}; +U_BOOT_DRVINFO(phandle_target) = { +\t.name\t\t= "target", +\t.plat\t= &dtv_phandle_target, +\t.plat_size\t= sizeof(dtv_phandle_target), +\t.parent_idx\t= -1, +}; + void dm_populate_phandle_data(void) { } ''', data) -- cgit v1.2.3 From d960f0db289144a80553e4d226d5dd145d63926a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:05 -0700 Subject: dtoc: Drop dm_populate_phandle_data() This has not been needed since parent information was added and we started using indicies for references to other drivers instead of pointers. It was kept around in the expectation that it might be needed later. However with the latest updates, it doesn't seem likely that we'll need this in the foreseeable future. Drop dm_populate_phandle_data() from dtoc and driver model. Signed-off-by: Simon Glass --- doc/driver-model/of-plat.rst | 16 ++++++---------- drivers/core/root.c | 3 --- include/dm/platdata.h | 8 -------- tools/dtoc/dtb_platdata.py | 6 ------ tools/dtoc/test_dtoc.py | 29 +++++++---------------------- 5 files changed, 13 insertions(+), 49 deletions(-) diff --git a/doc/driver-model/of-plat.rst b/doc/driver-model/of-plat.rst index 78afbdbcc9..4ef2fe699a 100644 --- a/doc/driver-model/of-plat.rst +++ b/doc/driver-model/of-plat.rst @@ -162,9 +162,6 @@ and the following device declarations: .parent_idx = -1, }; - void dm_populate_phandle_data(void) { - } - The device is then instantiated at run-time and the platform data can be accessed using: @@ -190,10 +187,7 @@ This macro produces no code, but it is by dtoc tool. The parent_idx is the index of the parent driver_info structure within its linker list (instantiated by the U_BOOT_DRVINFO() macro). This is used to support -dev_get_parent(). The dm_populate_phandle_data() is included to allow for -fix-ups required by dtoc. It is not currently used. The values in 'clocks' are -the index of the driver_info for the target device followed by any phandle -arguments. This is used to support device_get_by_driver_info_idx(). +dev_get_parent(). During the build process dtoc parses both U_BOOT_DRIVER and DM_DRIVER_ALIAS to build a list of valid driver names and driver aliases. If the 'compatible' @@ -337,9 +331,11 @@ prevents them being used inadvertently. All usage must be bracketed with #if CONFIG_IS_ENABLED(OF_PLATDATA). The dt-plat.c file contains the device declarations and is is built in -spl/dt-plat.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_DRVINFO by using DM_DRVINFO_GET +spl/dt-plat.c. + +The dm_populate_phandle_data() function that was previous needed has now been +removed, since dtoc can address the drivers directly from dt-plat.c and does +not need to fix up things at runtime. The pylibfdt Python module is used to access the devicetree. diff --git a/drivers/core/root.c b/drivers/core/root.c index 3adbc94eb9..78de7cdf87 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -336,9 +336,6 @@ int dm_init_and_scan(bool pre_reloc_only) { int ret; - if (CONFIG_IS_ENABLED(OF_PLATDATA)) - dm_populate_phandle_data(); - ret = dm_init(CONFIG_IS_ENABLED(OF_LIVE)); if (ret) { debug("dm_init() failed: %d\n", ret); diff --git a/include/dm/platdata.h b/include/dm/platdata.h index dc3cbfcbc7..3821a56f2c 100644 --- a/include/dm/platdata.h +++ b/include/dm/platdata.h @@ -86,12 +86,4 @@ struct driver_rt { #define DM_DRVINFO_GET(__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_DRVINFO entry get by - * DM_DRVINFO_GET. The implementation of this function will be done - * by dtoc when parsing dtb. - */ -void dm_populate_phandle_data(void); #endif diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 4cdbd60c9a..f1c09d629f 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -802,12 +802,6 @@ class DtbPlatdata(): for node in self._valid_nodes: self.output_node(node) - # Define dm_populate_phandle_data() which will add the linking between - # nodes using DM_DRVINFO_GET - # dtv_dmc_at_xxx.clocks[0].node = DM_DRVINFO_GET(clock_controller_at_xxx) - self.buf('void dm_populate_phandle_data(void) {\n') - self.buf('}\n') - self.out(''.join(self.get_buf())) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index f17d2e4b45..bcbf58c45b 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -56,10 +56,6 @@ C_HEADER = '''/* #include ''' -C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) { -} -''' - # This is a test so is allowed to access private things in the module it is # testing # pylint: disable=W0212 @@ -190,8 +186,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() + [''] + - C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines) + self.assertEqual(C_HEADER.splitlines() + [''], lines) struct_text = HEADER + ''' struct dtd_sandbox_i2c_test { @@ -289,7 +284,7 @@ U_BOOT_DRVINFO(spl_test3) = { \t.parent_idx\t= -1, }; -''' + C_EMPTY_POPULATE_PHANDLE_DATA +''' def test_simple(self): """Test output from some simple nodes with various types of data""" @@ -344,8 +339,6 @@ U_BOOT_DRVINFO(gpios_at_0) = { \t.parent_idx\t= -1, }; -void dm_populate_phandle_data(void) { -} ''', data) def test_invalid_driver(self): @@ -376,8 +369,6 @@ U_BOOT_DRVINFO(spl_test) = { \t.parent_idx\t= -1, }; -void dm_populate_phandle_data(void) { -} ''', data) def test_phandle(self): @@ -460,8 +451,6 @@ U_BOOT_DRVINFO(phandle_target) = { \t.parent_idx\t= -1, }; -void dm_populate_phandle_data(void) { -} ''', data) def test_phandle_single(self): @@ -510,8 +499,6 @@ U_BOOT_DRVINFO(phandle_target) = { \t.parent_idx\t= -1, }; -void dm_populate_phandle_data(void) { -} ''', data) def test_phandle_cd_gpio(self): @@ -582,8 +569,6 @@ U_BOOT_DRVINFO(phandle_target) = { \t.parent_idx\t= -1, }; -void dm_populate_phandle_data(void) { -} ''', data) def test_phandle_bad(self): @@ -662,7 +647,7 @@ U_BOOT_DRVINFO(test3) = { \t.parent_idx\t= -1, }; -''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) +''', data) def test_addresses32(self): """Test output from a node with a 'reg' property with na=1, ns=1""" @@ -706,7 +691,7 @@ U_BOOT_DRVINFO(test2) = { \t.parent_idx\t= -1, }; -''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) +''', data) def test_addresses64_32(self): """Test output from a node with a 'reg' property with na=2, ns=1""" @@ -764,7 +749,7 @@ U_BOOT_DRVINFO(test3) = { \t.parent_idx\t= -1, }; -''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) +''', data) def test_addresses32_64(self): """Test output from a node with a 'reg' property with na=1, ns=2""" @@ -822,7 +807,7 @@ U_BOOT_DRVINFO(test3) = { \t.parent_idx\t= -1, }; -''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) +''', data) def test_bad_reg(self): """Test that a reg property with an invalid type generates an error""" @@ -885,7 +870,7 @@ U_BOOT_DRVINFO(spl_test2) = { \t.parent_idx\t= -1, }; -''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) +''', data) def test_stdout(self): """Test output to stdout""" -- cgit v1.2.3 From a542a70c2256e2250dfb876fd394e967d6a47156 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:06 -0700 Subject: dtoc: Split source-code scanning to a separate file Before expanding the scanning features any more, move this into a separate file. This will make it easier to maintain in the future. In particular, it reduces the size of dtb_platdata.py and allows us to add tests specifically for scanning, without going through that file. The pieces moved are the Driver class, the scanning code and the various naming functions, since they mostly depend on the scanning results. So far there is are no separate tests for src_scan. These will be added as new functionality appears. This introduces no functional change. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 174 +++--------------------------------------- tools/dtoc/src_scan.py | 185 +++++++++++++++++++++++++++++++++++++++++++++ tools/dtoc/test_dtoc.py | 14 ++-- 3 files changed, 204 insertions(+), 169 deletions(-) create mode 100644 tools/dtoc/src_scan.py diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index f1c09d629f..ad642f3062 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -22,6 +22,8 @@ import sys from dtoc import fdt from dtoc import fdt_util +from dtoc import src_scan +from dtoc.src_scan import conv_name_to_c # When we see these properties we ignore them - i.e. do not create a structure # member @@ -76,39 +78,6 @@ PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args']) PhandleLink = collections.namedtuple('PhandleLink', ['var_node', 'dev_name']) -class Driver: - """Information about a driver in U-Boot - - Attributes: - name: Name of driver. For U_BOOT_DRIVER(x) this is 'x' - """ - def __init__(self, name): - self.name = name - - def __eq__(self, other): - return self.name == other.name - - def __repr__(self): - return "Driver(name='%s')" % self.name - - -def conv_name_to_c(name): - """Convert a device-tree name to a C identifier - - This uses multiple replace() calls instead of re.sub() since it is faster - (400ms for 1m calls versus 1000ms for the 're' version). - - Args: - name (str): Name to convert - Return: - str: String containing the C version of this name - """ - new = name.replace('@', '_at_') - new = new.replace('-', '_') - new = new.replace(',', '_') - new = new.replace('.', '_') - return new - def tab_to(num_tabs, line): """Append tabs to a line of text to reach a tab stop. @@ -154,19 +123,6 @@ def get_value(ftype, value): val = '%#x' % value return val -def get_compat_name(node): - """Get the node's list of compatible string as a C identifiers - - Args: - node (fdt.Node): Node object to check - Return: - list of str: List of C identifiers for all the compatible strings - """ - compat = node.props['compatible'].value - if not isinstance(compat, list): - compat = [compat] - return [conv_name_to_c(c) for c in compat] - class DtbPlatdata(): """Provide a means to convert device tree binary data to platform data @@ -176,22 +132,15 @@ class DtbPlatdata(): code is not affordable. Properties: + _scan: Scan object, for scanning and reporting on useful information + from the U-Boot source code _fdt: Fdt object, referencing the device tree _dtb_fname: Filename of the input device tree binary file _valid_nodes: A list of Node object with compatible strings. The list is ordered by conv_name_to_c(node.name) _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 - _drivers: Dict of valid driver names found in drivers/ - key: Driver name - value: Driver for that driver - _driver_aliases: Dict that holds aliases for driver names - key: Driver alias declared with - DM_DRIVER_ALIAS(driver_alias, driver_name) - value: Driver name declared with U_BOOT_DRIVER(driver_name) - _drivers_additional: List of additional drivers to use during scanning _dirname: Directory to hold output files, or None for none (all files go to stdout) _struct_data (dict): OrderedDict of dtplat structures to output @@ -201,58 +150,18 @@ class DtbPlatdata(): value: Prop object with field information _basedir (str): Base directory of source tree """ - def __init__(self, dtb_fname, include_disabled, warning_disabled, - drivers_additional=None): + def __init__(self, scan, dtb_fname, include_disabled): + self._scan = scan 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._drivers = {} - self._driver_aliases = {} - self._drivers_additional = drivers_additional or [] self._dirnames = [None] * len(Ftype) self._struct_data = collections.OrderedDict() self._basedir = None - def get_normalized_compat_name(self, node): - """Get a node's normalized compat name - - Returns a valid driver name by retrieving node's list of compatible - string as a C identifier and performing a check against _drivers - and a lookup in driver_aliases printing a warning in case of failure. - - Args: - node (Node): Node object to check - Return: - Tuple: - Driver name associated with the first compatible string - List of C identifiers for all the other compatible strings - (possibly empty) - In case of no match found, the return will be the same as - get_compat_name() - """ - compat_list_c = get_compat_name(node) - - for compat_c in compat_list_c: - if not compat_c in self._drivers.keys(): - compat_c = self._driver_aliases.get(compat_c) - if not compat_c: - continue - - aliases_c = compat_list_c - if compat_c in aliases_c: - aliases_c.remove(compat_c) - return compat_c, aliases_c - - if not self._warning_disabled: - print('WARNING: the driver %s was not found in the driver list' - % (compat_list_c[0])) - - return compat_list_c[0], compat_list_c[1:] - def setup_output_dirs(self, output_dirs): """Set up the output directories @@ -407,65 +316,6 @@ class DtbPlatdata(): return PhandleInfo(max_args, args) return None - def scan_driver(self, fname): - """Scan a driver file to build a list of driver names and aliases - - This procedure will populate self._drivers and self._driver_aliases - - Args - fname: Driver filename to scan - """ - with open(fname, encoding='utf-8') as inf: - try: - buff = inf.read() - except UnicodeDecodeError: - # This seems to happen on older Python versions - print("Skipping file '%s' due to unicode error" % fname) - return - - # The following re will search for driver names declared as - # U_BOOT_DRIVER(driver_name) - drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff) - - for driver in drivers: - self._drivers[driver] = Driver(driver) - - # The following re will search for driver aliases declared as - # DM_DRIVER_ALIAS(alias, driver_name) - driver_aliases = re.findall( - r'DM_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', - buff) - - for alias in driver_aliases: # pragma: no cover - if len(alias) != 2: - continue - self._driver_aliases[alias[1]] = alias[0] - - def scan_drivers(self, basedir=None): - """Scan the driver folders to build a list of driver names and aliases - - This procedure will populate self._drivers and self._driver_aliases - - """ - if not basedir: - basedir = sys.argv[0].replace('tools/dtoc/dtoc', '') - if basedir == '': - basedir = './' - self._basedir = basedir - for (dirpath, _, filenames) in os.walk(basedir): - for fname in filenames: - if not fname.endswith('.c'): - continue - self.scan_driver(dirpath + '/' + fname) - - for fname in self._drivers_additional: - if not isinstance(fname, str) or len(fname) == 0: - continue - if fname[0] == '/': - self.scan_driver(fname) - else: - self.scan_driver(basedir + '/' + fname) - def scan_dtb(self): """Scan the device tree to obtain a tree of nodes and properties @@ -584,7 +434,7 @@ class DtbPlatdata(): """ structs = self._struct_data for node in self._valid_nodes: - node_name, _ = self.get_normalized_compat_name(node) + node_name, _ = self._scan.get_normalized_compat_name(node) fields = {} # Get a list of all the valid properties in this node. @@ -607,7 +457,7 @@ class DtbPlatdata(): structs[node_name] = fields for node in self._valid_nodes: - node_name, _ = self.get_normalized_compat_name(node) + node_name, _ = self._scan.get_normalized_compat_name(node) struct = structs[node_name] for name, prop in node.props.items(): if name not in PROP_IGNORE_LIST and name[0] != '#': @@ -772,7 +622,7 @@ class DtbPlatdata(): Args: node (fdt.Node): node to output """ - struct_name, _ = self.get_normalized_compat_name(node) + struct_name, _ = self._scan.get_normalized_compat_name(node) var_name = conv_name_to_c(node.name) self.buf('/* Node %s index %d */\n' % (node.path, node.idx)) @@ -845,9 +695,9 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, if output and output_dirs and any(output_dirs): raise ValueError('Must specify either output or output_dirs, not both') - plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled, - drivers_additional) - plat.scan_drivers(basedir) + scan = src_scan.Scanner(basedir, drivers_additional, warning_disabled) + plat = DtbPlatdata(scan, dtb_file, include_disabled) + scan.scan_drivers() plat.scan_dtb() plat.scan_tree() plat.scan_reg_sizes() diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py new file mode 100644 index 0000000000..185a6d9284 --- /dev/null +++ b/tools/dtoc/src_scan.py @@ -0,0 +1,185 @@ +#!/usr/bin/python +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2017 Google, Inc +# Written by Simon Glass +# + +"""Scanning of U-Boot source for drivers and structs + +This scans the source tree to find out things about all instances of +U_BOOT_DRIVER(), UCLASS_DRIVER and all struct declarations in header files. + +See doc/driver-model/of-plat.rst for more informaiton +""" + +import os +import re +import sys + + +def conv_name_to_c(name): + """Convert a device-tree name to a C identifier + + This uses multiple replace() calls instead of re.sub() since it is faster + (400ms for 1m calls versus 1000ms for the 're' version). + + Args: + name (str): Name to convert + Return: + str: String containing the C version of this name + """ + new = name.replace('@', '_at_') + new = new.replace('-', '_') + new = new.replace(',', '_') + new = new.replace('.', '_') + return new + +def get_compat_name(node): + """Get the node's list of compatible string as a C identifiers + + Args: + node (fdt.Node): Node object to check + Return: + list of str: List of C identifiers for all the compatible strings + """ + compat = node.props['compatible'].value + if not isinstance(compat, list): + compat = [compat] + return [conv_name_to_c(c) for c in compat] + + +class Driver: + """Information about a driver in U-Boot + + Attributes: + name: Name of driver. For U_BOOT_DRIVER(x) this is 'x' + """ + def __init__(self, name): + self.name = name + + def __eq__(self, other): + return self.name == other.name + + def __repr__(self): + return "Driver(name='%s')" % self.name + + +class Scanner: + """Scanning of the U-Boot source tree + + Properties: + _basedir (str): Base directory of U-Boot source code. Defaults to the + grandparent of this file's directory + _drivers: Dict of valid driver names found in drivers/ + key: Driver name + value: Driver for that driver + _driver_aliases: Dict that holds aliases for driver names + key: Driver alias declared with + DM_DRIVER_ALIAS(driver_alias, driver_name) + value: Driver name declared with U_BOOT_DRIVER(driver_name) + _drivers_additional (list or str): List of additional drivers to use + during scanning + _warning_disabled: true to disable warnings about driver names not found + """ + def __init__(self, basedir, drivers_additional, warning_disabled): + """Set up a new Scanner + """ + if not basedir: + basedir = sys.argv[0].replace('tools/dtoc/dtoc', '') + if basedir == '': + basedir = './' + self._basedir = basedir + self._drivers = {} + self._driver_aliases = {} + self._drivers_additional = drivers_additional or [] + self._warning_disabled = warning_disabled + + def get_normalized_compat_name(self, node): + """Get a node's normalized compat name + + Returns a valid driver name by retrieving node's list of compatible + string as a C identifier and performing a check against _drivers + and a lookup in driver_aliases printing a warning in case of failure. + + Args: + node (Node): Node object to check + Return: + Tuple: + Driver name associated with the first compatible string + List of C identifiers for all the other compatible strings + (possibly empty) + In case of no match found, the return will be the same as + get_compat_name() + """ + compat_list_c = get_compat_name(node) + + for compat_c in compat_list_c: + if not compat_c in self._drivers.keys(): + compat_c = self._driver_aliases.get(compat_c) + if not compat_c: + continue + + aliases_c = compat_list_c + if compat_c in aliases_c: + aliases_c.remove(compat_c) + return compat_c, aliases_c + + if not self._warning_disabled: + print('WARNING: the driver %s was not found in the driver list' + % (compat_list_c[0])) + + return compat_list_c[0], compat_list_c[1:] + + def scan_driver(self, fname): + """Scan a driver file to build a list of driver names and aliases + + This procedure will populate self._drivers and self._driver_aliases + + Args + fname: Driver filename to scan + """ + with open(fname, encoding='utf-8') as inf: + try: + buff = inf.read() + except UnicodeDecodeError: + # This seems to happen on older Python versions + print("Skipping file '%s' due to unicode error" % fname) + return + + # The following re will search for driver names declared as + # U_BOOT_DRIVER(driver_name) + drivers = re.findall(r'U_BOOT_DRIVER\((.*)\)', buff) + + for driver in drivers: + self._drivers[driver] = Driver(driver) + + # The following re will search for driver aliases declared as + # DM_DRIVER_ALIAS(alias, driver_name) + driver_aliases = re.findall( + r'DM_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', + buff) + + for alias in driver_aliases: # pragma: no cover + if len(alias) != 2: + continue + self._driver_aliases[alias[1]] = alias[0] + + def scan_drivers(self): + """Scan the driver folders to build a list of driver names and aliases + + This procedure will populate self._drivers and self._driver_aliases + """ + for (dirpath, _, filenames) in os.walk(self._basedir): + for fname in filenames: + if not fname.endswith('.c'): + continue + self.scan_driver(dirpath + '/' + fname) + + for fname in self._drivers_additional: + if not isinstance(fname, str) or len(fname) == 0: + continue + if fname[0] == '/': + self.scan_driver(fname) + else: + self.scan_driver(self._basedir + '/' + fname) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index bcbf58c45b..8e8dd847c1 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -18,13 +18,14 @@ import tempfile import unittest from unittest import mock -from dtb_platdata import conv_name_to_c -from dtb_platdata import get_compat_name from dtb_platdata import get_value from dtb_platdata import tab_to from dtoc import dtb_platdata from dtoc import fdt from dtoc import fdt_util +from dtoc import src_scan +from dtoc.src_scan import conv_name_to_c +from dtoc.src_scan import get_compat_name from patman import test_util from patman import tools @@ -933,9 +934,9 @@ U_BOOT_DRVINFO(spl_test2) = { def test_driver(self): """Test the Driver class""" - drv1 = dtb_platdata.Driver('fred') - drv2 = dtb_platdata.Driver('mary') - drv3 = dtb_platdata.Driver('fred') + drv1 = src_scan.Driver('fred') + drv2 = src_scan.Driver('mary') + drv3 = src_scan.Driver('fred') self.assertEqual("Driver(name='fred')", str(drv1)) self.assertEqual(drv1, drv3) self.assertNotEqual(drv1, drv2) @@ -989,8 +990,7 @@ U_BOOT_DRVINFO(spl_test2) = { # Mock out scan_driver and check that it is called with the # expected files - with mock.patch.object(dtb_platdata.DtbPlatdata, "scan_driver") \ - as mocked: + with mock.patch.object(src_scan.Scanner, "scan_driver") as mocked: dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True, basedir=indir) self.assertEqual(2, len(mocked.mock_calls)) -- cgit v1.2.3 From 10ea9c0b059c37e6b2026fe1334d1d57c465984d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:07 -0700 Subject: dtoc: Move src_scan tests to a separate file Move the tests related to scanning into their own class, updating them to avoid using dtb_platdata as a pass-through. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 2 +- tools/dtoc/main.py | 5 ++- tools/dtoc/src_scan.py | 4 +- tools/dtoc/test_dtoc.py | 73 ------------------------------------ tools/dtoc/test_src_scan.py | 91 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 78 deletions(-) create mode 100644 tools/dtoc/test_src_scan.py diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index ad642f3062..b7abaed67a 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -695,7 +695,7 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, if output and output_dirs and any(output_dirs): raise ValueError('Must specify either output or output_dirs, not both') - scan = src_scan.Scanner(basedir, drivers_additional, warning_disabled) + scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional) plat = DtbPlatdata(scan, dtb_file, include_disabled) scan.scan_drivers() plat.scan_dtb() diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py index 9d0b3915c0..b0ad0f3952 100755 --- a/tools/dtoc/main.py +++ b/tools/dtoc/main.py @@ -46,7 +46,8 @@ def run_tests(processes, args): args: List of positional args provided to dtoc. This can hold a test name to execute (as in 'dtoc -t test_empty_file', for example) """ - import test_dtoc + from dtoc import test_src_scan + from dtoc import test_dtoc result = unittest.TestResult() sys.argv = [sys.argv[0]] @@ -55,7 +56,7 @@ def run_tests(processes, args): test_util.RunTestSuites( result, debug=True, verbosity=1, test_preserve_dirs=False, processes=processes, test_name=test_name, toolpath=[], - test_class_list=[test_dtoc.TestDtoc,]) + test_class_list=[test_dtoc.TestDtoc,test_src_scan.TestSrcScan]) return test_util.ReportResult('binman', test_name, result) diff --git a/tools/dtoc/src_scan.py b/tools/dtoc/src_scan.py index 185a6d9284..f63c9fc166 100644 --- a/tools/dtoc/src_scan.py +++ b/tools/dtoc/src_scan.py @@ -78,11 +78,11 @@ class Scanner: key: Driver alias declared with DM_DRIVER_ALIAS(driver_alias, driver_name) value: Driver name declared with U_BOOT_DRIVER(driver_name) + _warning_disabled: true to disable warnings about driver names not found _drivers_additional (list or str): List of additional drivers to use during scanning - _warning_disabled: true to disable warnings about driver names not found """ - def __init__(self, basedir, drivers_additional, warning_disabled): + def __init__(self, basedir, warning_disabled, drivers_additional): """Set up a new Scanner """ if not basedir: diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 8e8dd847c1..d961d67b8f 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -12,18 +12,14 @@ tool. import collections import glob import os -import shutil import struct -import tempfile import unittest -from unittest import mock from dtb_platdata import get_value from dtb_platdata import tab_to from dtoc import dtb_platdata from dtoc import fdt from dtoc import fdt_util -from dtoc import src_scan from dtoc.src_scan import conv_name_to_c from dtoc.src_scan import get_compat_name from patman import test_util @@ -904,44 +900,6 @@ U_BOOT_DRVINFO(spl_test2) = { self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)", str(exc.exception)) - @staticmethod - def test_scan_drivers(): - """Test running dtoc with additional drivers to scan""" - dtb_file = get_dtb_file('dtoc_test_simple.dts') - output = tools.GetOutputFilename('output') - with test_util.capture_sys_output() as _: - dtb_platdata.run_steps( - ['struct'], dtb_file, False, output, [], True, - [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx']) - - @staticmethod - def test_unicode_error(): - """Test running dtoc with an invalid unicode file - - To be able to perform this test without adding a weird text file which - would produce issues when using checkpatch.pl or patman, generate the - file at runtime and then process it. - """ - dtb_file = get_dtb_file('dtoc_test_simple.dts') - output = tools.GetOutputFilename('output') - driver_fn = '/tmp/' + next(tempfile._get_candidate_names()) - with open(driver_fn, 'wb+') as fout: - fout.write(b'\x81') - - with test_util.capture_sys_output() as _: - dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], - True, [driver_fn]) - - def test_driver(self): - """Test the Driver class""" - drv1 = src_scan.Driver('fred') - drv2 = src_scan.Driver('mary') - drv3 = src_scan.Driver('fred') - self.assertEqual("Driver(name='fred')", str(drv1)) - self.assertEqual(drv1, drv3) - self.assertNotEqual(drv1, drv2) - self.assertNotEqual(drv2, drv3) - def test_output_conflict(self): """Test a conflict between and output dirs and output file""" with self.assertRaises(ValueError) as exc: @@ -969,34 +927,3 @@ U_BOOT_DRVINFO(spl_test2) = { self.assertEqual( {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'}, leafs) - - def test_scan_dirs(self): - """Test scanning of source directories""" - def add_file(fname): - pathname = os.path.join(indir, fname) - dirname = os.path.dirname(pathname) - os.makedirs(dirname, exist_ok=True) - tools.WriteFile(pathname, '', binary=False) - fname_list.append(pathname) - - try: - outdir = tools.GetOutputDir() - indir = tempfile.mkdtemp(prefix='dtoc.') - dtb_file = get_dtb_file('dtoc_test_simple.dts') - - fname_list = [] - add_file('fname.c') - add_file('dir/fname2.c') - - # Mock out scan_driver and check that it is called with the - # expected files - with mock.patch.object(src_scan.Scanner, "scan_driver") as mocked: - dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], - True, basedir=indir) - self.assertEqual(2, len(mocked.mock_calls)) - self.assertEqual(mock.call(fname_list[0]), - mocked.mock_calls[0]) - self.assertEqual(mock.call(fname_list[1]), - mocked.mock_calls[1]) - finally: - shutil.rmtree(indir) diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py new file mode 100644 index 0000000000..d25da5760a --- /dev/null +++ b/tools/dtoc/test_src_scan.py @@ -0,0 +1,91 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright 2020 Google LLC +# + +"""Tests for the src_scan module + +This includes unit tests for scanning of the source code +""" + +import os +import shutil +import tempfile +import unittest +from unittest import mock + +from dtoc import src_scan +from patman import tools + +# This is a test so is allowed to access private things in the module it is +# testing +# pylint: disable=W0212 + +class TestSrcScan(unittest.TestCase): + """Tests for src_scan""" + @classmethod + def setUpClass(cls): + tools.PrepareOutputDir(None) + + @classmethod + def tearDownClass(cls): + tools.FinaliseOutputDir() + + @classmethod + def test_scan_drivers(cls): + """Test running dtoc with additional drivers to scan""" + scan = src_scan.Scanner( + None, True, [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx']) + scan.scan_drivers() + + @classmethod + def test_unicode_error(cls): + """Test running dtoc with an invalid unicode file + + To be able to perform this test without adding a weird text file which + would produce issues when using checkpatch.pl or patman, generate the + file at runtime and then process it. + """ + driver_fn = '/tmp/' + next(tempfile._get_candidate_names()) + with open(driver_fn, 'wb+') as fout: + fout.write(b'\x81') + + src_scan.Scanner(None, True, [driver_fn]) + + def test_driver(self): + """Test the Driver class""" + drv1 = src_scan.Driver('fred') + drv2 = src_scan.Driver('mary') + drv3 = src_scan.Driver('fred') + self.assertEqual("Driver(name='fred')", str(drv1)) + self.assertEqual(drv1, drv3) + self.assertNotEqual(drv1, drv2) + self.assertNotEqual(drv2, drv3) + + def test_scan_dirs(self): + """Test scanning of source directories""" + def add_file(fname): + pathname = os.path.join(indir, fname) + dirname = os.path.dirname(pathname) + os.makedirs(dirname, exist_ok=True) + tools.WriteFile(pathname, '', binary=False) + fname_list.append(pathname) + + try: + indir = tempfile.mkdtemp(prefix='dtoc.') + + fname_list = [] + add_file('fname.c') + add_file('dir/fname2.c') + + # Mock out scan_driver and check that it is called with the + # expected files + with mock.patch.object(src_scan.Scanner, "scan_driver") as mocked: + scan = src_scan.Scanner(indir, True, None) + scan.scan_drivers() + self.assertEqual(2, len(mocked.mock_calls)) + self.assertEqual(mock.call(fname_list[0]), + mocked.mock_calls[0]) + self.assertEqual(mock.call(fname_list[1]), + mocked.mock_calls[1]) + finally: + shutil.rmtree(indir) -- cgit v1.2.3 From 970349a96dac3ad46c33851b1a773bfe3f1d4b33 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 28 Dec 2020 20:35:08 -0700 Subject: dtoc: Tidy up src_scan tests Some of these tests don't actually check anything. Add a few more checks to complete the tests. Also add a simple scan test that does the basics. Signed-off-by: Simon Glass --- tools/dtoc/test_src_scan.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/dtoc/test_src_scan.py b/tools/dtoc/test_src_scan.py index d25da5760a..7d686530d6 100644 --- a/tools/dtoc/test_src_scan.py +++ b/tools/dtoc/test_src_scan.py @@ -14,6 +14,7 @@ import unittest from unittest import mock from dtoc import src_scan +from patman import test_util from patman import tools # This is a test so is allowed to access private things in the module it is @@ -30,15 +31,26 @@ class TestSrcScan(unittest.TestCase): def tearDownClass(cls): tools.FinaliseOutputDir() - @classmethod - def test_scan_drivers(cls): - """Test running dtoc with additional drivers to scan""" + def test_simple(self): + """Simple test of scanning drivers""" + scan = src_scan.Scanner(None, True, None) + scan.scan_drivers() + self.assertIn('sandbox_gpio', scan._drivers) + self.assertIn('sandbox_gpio_alias', scan._driver_aliases) + self.assertEqual('sandbox_gpio', + scan._driver_aliases['sandbox_gpio_alias']) + self.assertNotIn('sandbox_gpio_alias2', scan._driver_aliases) + + def test_additional(self): + """Test with additional drivers to scan""" scan = src_scan.Scanner( None, True, [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx']) scan.scan_drivers() + self.assertIn('sandbox_gpio_alias2', scan._driver_aliases) + self.assertEqual('sandbox_gpio', + scan._driver_aliases['sandbox_gpio_alias2']) - @classmethod - def test_unicode_error(cls): + def test_unicode_error(self): """Test running dtoc with an invalid unicode file To be able to perform this test without adding a weird text file which @@ -49,7 +61,11 @@ class TestSrcScan(unittest.TestCase): with open(driver_fn, 'wb+') as fout: fout.write(b'\x81') - src_scan.Scanner(None, True, [driver_fn]) + scan = src_scan.Scanner(None, True, [driver_fn]) + with test_util.capture_sys_output() as (stdout, _): + scan.scan_drivers() + self.assertRegex(stdout.getvalue(), + r"Skipping file '.*' due to unicode error\s*") def test_driver(self): """Test the Driver class""" -- cgit v1.2.3