[PATCH 00/26] dm: Preparation for enhanced of-platdata (part C)

classic Classic list List threaded Threaded
60 messages Options
123
Reply | Threaded
Open this post in threaded view
|

[PATCH 00/26] dm: Preparation for enhanced of-platdata (part C)

Simon Glass-3
At present various driver model data structures are accessed outside the
core driver mode code. This makes it harder to adjust how certain values
are stored, which is needed for of-platdata.

This series updates several a few more fields so that they are only
accessed via functions.

This series also includes some changes to sandbox and x86 drivers to get
them ready for the new of-platdata.

It is available at u-boot-dm/prepc-working


Simon Glass (26):
  sandbox: serial: Move priv into a header file
  sandbox: i2c: Move priv into a header file
  sandbox: Add a compatible string for spltest
  sandbox: Update dts files to reduce SPL size
  x86: apl: Move priv/plat structs to headers
  x86: Move priv/plat structs for intel_common to headers
  x86: spl: Move priv/plat structs to headers
  spi: Tidy up get/set of device node
  spi: Tweak a few strange SPI NOR features for of-platdata
  x86: apl: Use struct spi_nor instead of struct spi_flash
  dm: core: Move priv/plat structs for simple_bus to headers
  x86: sysreset: Move priv/plat structs to headers
  x86: apl: Adjust how the UART gets its platform data
  x86: coral: Remove unwanted nodes from SPL/TPL
  x86: Drop rtc from SPL
  dm: core: Split out alloc code into a new function
  dm: core: Rename sqq to seq_
  dm: core: Access device flags through functions
  dm: core: Rename device flags to indicate it is private
  dm: core: Rename dev_has_of_node() to dev_has_ofnode()
  dm: core: Use dev_has_ofnode() instead of dev_of_valid()
  dm: core: Access device ofnode through functions
  dm: core: Rename device node to indicate it is private
  dm: core: Split out scanning code to dm_scan()
  dm: core: Allow the uclass list to move
  dm: core: Add logging when lists_bind_fdt() fails

 arch/arm/mach-stm32mp/pwr_regulator.c         |   2 +-
 arch/sandbox/dts/sandbox.dts                  |   4 +-
 arch/sandbox/dts/sandbox.dtsi                 |  11 +-
 arch/sandbox/include/asm/i2c.h                |  14 ++
 arch/sandbox/include/asm/serial.h             |  30 ++++
 arch/x86/cpu/apollolake/hostbridge.c          |  20 +--
 arch/x86/cpu/apollolake/pmc.c                 |   8 +-
 arch/x86/cpu/apollolake/spl.c                 |   2 +-
 arch/x86/cpu/apollolake/uart.c                |  43 +++---
 arch/x86/cpu/intel_common/itss.c              |  19 ---
 arch/x86/cpu/intel_common/p2sb.c              |   9 +-
 arch/x86/dts/chromebook_coral.dts             |  17 ++-
 arch/x86/dts/rtc.dtsi                         |   2 +-
 arch/x86/include/asm/arch-apollolake/gpio.h   |  18 +++
 .../include/asm/arch-apollolake/hostbridge.h  |  28 ++++
 arch/x86/include/asm/arch-apollolake/pmc.h    |  16 +++
 arch/x86/include/asm/arch-apollolake/uart.h   |  19 ++-
 arch/x86/include/asm/itss.h                   |  21 +++
 arch/x86/include/asm/p2sb.h                   |  18 +++
 arch/x86/include/asm/sysreset.h               |  18 +++
 board/synopsys/hsdk/clk-lib.c                 |   2 +-
 cmd/remoteproc.c                              |   2 +-
 drivers/ata/mtk_ahci.c                        |   3 +-
 drivers/clk/clk-uclass.c                      |   2 +-
 drivers/clk/clk.c                             |   2 +-
 drivers/clk/meson/axg.c                       |   2 +-
 drivers/clk/meson/g12a.c                      |   2 +-
 drivers/clk/meson/gxbb.c                      |   2 +-
 drivers/core/device-remove.c                  |  18 +--
 drivers/core/device.c                         | 135 ++++++++++--------
 drivers/core/devres.c                         |   4 +-
 drivers/core/dump.c                           |   6 +-
 drivers/core/lists.c                          |   2 +-
 drivers/core/root.c                           |  58 +++++---
 drivers/core/simple-bus.c                     |   7 +-
 drivers/core/uclass.c                         |  12 +-
 drivers/gpio/mpc8xxx_gpio.c                   |   4 +-
 drivers/gpio/octeon_gpio.c                    |   2 +-
 drivers/gpio/sandbox.c                        |   2 +-
 drivers/i2c/designware_i2c_pci.c              |   4 +-
 drivers/i2c/i2c-uclass.c                      |   2 +-
 drivers/i2c/sandbox_i2c.c                     |   5 +-
 drivers/misc/spltest_sandbox.c                |   6 +
 drivers/misc/swap_case.c                      |   2 +-
 drivers/mmc/octeontx_hsmmc.c                  |  25 ++--
 drivers/mmc/pci_mmc.c                         |   2 +-
 drivers/mtd/nand/raw/octeontx_nand.c          |   4 +-
 drivers/mtd/nand/spi/core.c                   |   2 +-
 drivers/mtd/spi/sf-uclass.c                   |   2 +-
 drivers/mtd/spi/sf_probe.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/pci/pci-uclass.c                      |   8 +-
 drivers/phy/phy-ti-am654.c                    |   2 +-
 drivers/pinctrl/intel/pinctrl_apl.c           |  12 --
 drivers/pinctrl/pinctrl-uclass.c              |   4 +-
 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/remoteproc/rproc-uclass.c             |   2 +-
 drivers/reset/reset-socfpga.c                 |   2 +-
 drivers/serial/sandbox.c                      |  16 +--
 drivers/serial/serial-uclass.c                |   2 +-
 drivers/spi/fsl_dspi.c                        |   6 +-
 drivers/spi/ich.c                             |  11 --
 drivers/spi/ich.h                             |  11 ++
 drivers/spi/spi-uclass.c                      |   2 +-
 drivers/sysreset/sysreset_sandbox.c           |   2 +-
 drivers/sysreset/sysreset_x86.c               |   5 +-
 drivers/tee/optee/core.c                      |   2 +-
 drivers/timer/timer-uclass.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/usb-uclass.c                 |   4 +-
 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/asm-generic/global_data.h             |   8 +-
 include/dm/device-internal.h                  |   1 +
 include/dm/device.h                           |  74 ++++++++--
 include/dm/read.h                             |  18 +--
 include/dm/simple_bus.h                       |  15 ++
 include/linux/mtd/mtd.h                       |   9 +-
 include/linux/mtd/nand.h                      |  14 ++
 include/linux/mtd/spi-nor.h                   |   6 +-
 include/linux/mtd/spinand.h                   |  15 ++
 include/virtio.h                              |   2 +-
 net/mdio-mux-uclass.c                         |   2 +-
 net/mdio-uclass.c                             |   8 +-
 test/dm/bus.c                                 |  10 +-
 test/dm/core.c                                |  26 ++--
 test/dm/cpu.c                                 |   2 +-
 test/dm/pci.c                                 |   6 +-
 test/dm/test-fdt.c                            |  20 +--
 test/dm/virtio.c                              |   2 +-
 112 files changed, 655 insertions(+), 410 deletions(-)
 create mode 100644 arch/sandbox/include/asm/i2c.h
 create mode 100644 arch/sandbox/include/asm/serial.h
 create mode 100644 arch/x86/include/asm/arch-apollolake/hostbridge.h
 create mode 100644 arch/x86/include/asm/arch-apollolake/pmc.h
 create mode 100644 arch/x86/include/asm/p2sb.h
 create mode 100644 arch/x86/include/asm/sysreset.h
 create mode 100644 include/dm/simple_bus.h

--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 01/26] sandbox: serial: Move priv into a header file

Simon Glass-3
Move this struct into a header file so that dtoc can include it in its
dt-platdata.c file.

Signed-off-by: Simon Glass <[hidden email]>
---

 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 00000000000..bc82aebd0ea
--- /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 <[hidden email]>
+ */
+
+#ifndef __asm_serial_h
+#define __asm_serial_h
+
+#include <dt-structs.h>
+
+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 a05c56458b0..19368ba2560 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -17,25 +17,11 @@
 #include <serial.h>
 #include <video.h>
 #include <linux/compiler.h>
+#include <asm/serial.h>
 #include <asm/state.h>
 
 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
  *
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 02/26] sandbox: i2c: Move priv into a header file

Simon Glass-3
In reply to this post by Simon Glass-3
Move this struct into a header file so that dtoc can include it in its
dt-platdata.c file.

Signed-off-by: Simon Glass <[hidden email]>
---

 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 00000000000..b482be485ca
--- /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 <[hidden email]>
+ */
+
+#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 a61dfc096b3..c99e6de9332 100644
--- a/drivers/i2c/sandbox_i2c.c
+++ b/drivers/i2c/sandbox_i2c.c
@@ -10,15 +10,12 @@
 #include <errno.h>
 #include <i2c.h>
 #include <log.h>
+#include <asm/i2c.h>
 #include <asm/test.h>
 #include <dm/acpi.h>
 #include <dm/lists.h>
 #include <dm/device-internal.h>
 
-struct sandbox_i2c_priv {
- bool test_mode;
-};
-
 static int get_emul(struct udevice *dev, struct udevice **devp,
     struct dm_i2c_ops **opsp)
 {
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 03/26] sandbox: Add a compatible string for spltest

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 3ae6707593e..6b9701a06ae 100644
--- a/drivers/misc/spltest_sandbox.c
+++ b/drivers/misc/spltest_sandbox.c
@@ -8,8 +8,14 @@
 #include <dm.h>
 #include <dt-structs.h>
 
+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,
 };
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 04/26] sandbox: Update dts files to reduce SPL size

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 8b50a402898..a8938a3accb 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 7b4fc94495a..d842f021760 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;
  };
 };
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 05/26] x86: apl: Move priv/plat structs to headers

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 arch/x86/cpu/apollolake/hostbridge.c          | 20 +------------
 arch/x86/cpu/apollolake/pmc.c                 |  8 +-----
 arch/x86/include/asm/arch-apollolake/gpio.h   | 18 ++++++++++++
 .../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 9ec2309d086..9decab7aa33 100644
--- a/arch/x86/cpu/apollolake/hostbridge.c
+++ b/arch/x86/cpu/apollolake/hostbridge.c
@@ -24,6 +24,7 @@
 #include <asm/io.h>
 #include <asm/pci.h>
 #include <asm/arch/acpi.h>
+#include <asm/arch/hostbridge.h>
 #include <asm/arch/systemagent.h>
 #include <dt-bindings/sound/nhlt.h>
 #include <dm/acpi.h>
@@ -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 e033baf1205..e23d38ea072 100644
--- a/arch/x86/cpu/apollolake/pmc.c
+++ b/arch/x86/cpu/apollolake/pmc.c
@@ -16,6 +16,7 @@
 #include <acpi/acpi_s3.h>
 #include <asm/io.h>
 #include <asm/pci.h>
+#include <asm/arch/pmc.h>
 #include <linux/bitops.h>
 #include <power/acpi_pmc.h>
 
@@ -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 ab5860c0fd0..762160da882 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 <dt-structs.h>
+
+/**
+ * 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 00000000000..f4dce0d5224
--- /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 00000000000..23ac8fe7e20
--- /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 b512a85f3e6..acaa55d2e7f 100644
--- a/drivers/pinctrl/intel/pinctrl_apl.c
+++ b/drivers/pinctrl/intel/pinctrl_apl.c
@@ -17,18 +17,6 @@
 #include <asm-generic/gpio.h>
 #include <asm/intel_pinctrl_defs.h>
 
-/**
- * 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 },
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 06/26] x86: Move priv/plat structs for intel_common to headers

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 6515d1f471f..ae4de4ca8c6 100644
--- a/arch/x86/cpu/intel_common/itss.c
+++ b/arch/x86/cpu/intel_common/itss.c
@@ -19,25 +19,6 @@
 #include <spl.h>
 #include <asm/itss.h>
 
-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 cb901f265e2..d73ae438bbb 100644
--- a/arch/x86/cpu/intel_common/p2sb.c
+++ b/arch/x86/cpu/intel_common/p2sb.c
@@ -13,20 +13,13 @@
 #include <log.h>
 #include <p2sb.h>
 #include <spl.h>
+#include <asm/p2sb.h>
 #include <asm/pci.h>
 #include <linux/bitops.h>
 
 #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 f7d32403849..6d4793277e6 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 <irq.h>
+
 #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 00000000000..6f63eae8e27
--- /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 */
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 07/26] x86: spl: Move priv/plat structs to headers

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 e02850e9f22..1cd410493b0 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 23c7827740b..8fd150d44a4 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_ */
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 08/26] spi: Tidy up get/set of device node

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 fc9d4edbe04..ab9a24ed5b5 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 1b9151714c0..54d03d02402 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 13e8dd11035..7774c17ad5d 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 233fdc341a7..2642bf91d00 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 88bacde91e5..15bcd59f341 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,
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 09/26] spi: Tweak a few strange SPI NOR features for of-platdata

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 ed629f1d458..3017022abbb 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 c8bcec3c589..630787df1bf 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 2642bf91d00..363f2749d7d 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
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 10/26] x86: apl: Use struct spi_nor instead of struct spi_flash

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 16a2f15c6bc..8991d5e648e 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,
 };
 
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 11/26] dm: core: Move priv/plat structs for simple_bus to headers

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 7dbcbecd948..b0c2c209587 100644
--- a/drivers/core/simple-bus.c
+++ b/drivers/core/simple-bus.c
@@ -5,12 +5,7 @@
 
 #include <common.h>
 #include <dm.h>
-
-struct simple_bus_plat {
- u32 base;
- u32 size;
- u32 target;
-};
+#include <dm/simple_bus.h>
 
 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 00000000000..4ad4cc4051d
--- /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
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 12/26] x86: sysreset: Move priv/plat structs to headers

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 00000000000..5e586f51c00
--- /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 <dt-structs.h>
+
+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 8f9970301e5..8042f3994fe 100644
--- a/drivers/sysreset/sysreset_x86.c
+++ b/drivers/sysreset/sysreset_x86.c
@@ -13,10 +13,7 @@
 #include <acpi/acpi_s3.h>
 #include <asm/io.h>
 #include <asm/processor.h>
-
-struct x86_sysreset_plat {
- struct udevice *pch;
-};
+#include <asm/sysreset.h>
 
 /*
  * Power down the machine by using the power management sleep control
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 13/26] x86: apl: Adjust how the UART gets its platform data

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 69e5899235b..876fa592b8d 100644
--- a/arch/x86/cpu/apollolake/uart.c
+++ b/arch/x86/cpu/apollolake/uart.c
@@ -17,6 +17,7 @@
 #include <asm/pci.h>
 #include <asm/lpss.h>
 #include <dm/device-internal.h>
+#include <asm/arch/uart.h>
 
 /* 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([hidden email]): 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 d4fffe6525c..38335b04903 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 <ns16550.h>
+
+/**
+ * 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
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 14/26] x86: coral: Remove unwanted nodes from SPL/TPL

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 3c8fdf23809..a8460220957 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>;
 
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 15/26] x86: Drop rtc from SPL

Simon Glass-3
In reply to this post by Simon Glass-3
The RTC is not currently used in SPL. Drop it so that it does not take up
space.

Signed-off-by: Simon Glass <[hidden email]>
---

 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 d0bbd84e509..942cc937dc4 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>;
  };
 };
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 16/26] dm: core: Split out alloc code into a new function

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 a4c8310f812..72169632c88 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);
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 17/26] dm: core: Rename sqq to seq_

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 72169632c88..f4ae7786ee9 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 7784ec02dea..1d4628abc74 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 f60bc9a8504..e773e34833e 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 37a233878d0..1f6c51f1e8d 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 daebd6eb68d..a063bbaa176 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 cf66e27db4e..b274b043882 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);
  }
  }
 
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 18/26] dm: core: Access device flags through functions

Simon Glass-3
In reply to this post by Simon Glass-3
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 <[hidden email]>
---

 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 5f9ba925609..b3ddcebe314 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 eb75132f27e..1efb7fe9f3e 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 e15ab051be7..44eaa67d566 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 f4ae7786ee9..ba50d46effe 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 522b07d613f..313ddc7089c 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 1d4628abc74..f8afea30a93 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 b1ed4d910a7..96a5fe6592a 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 773b8119f4f..c2d6a4e0c17 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 b6457242dea..58a6541d8cc 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 a063bbaa176..4ec423e9618 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 10a9c073ba1..a42bdad6b87 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 785ccfc25d1..e768eab6957 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 b274b043882..565896ed504 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 28869c1d6ff..ed12cafee2b 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 633256821c2..711bf20a9c5 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 2e876c36e43..ad355981cf4 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;
--
2.29.2.684.gfbc64c5ab5-goog

Reply | Threaded
Open this post in threaded view
|

[PATCH 19/26] dm: core: Rename device flags to indicate it is private

Simon Glass-3
In reply to this post by Simon Glass-3
To avoid having people accidentally access this member, add a trailing
underscore.

Signed-off-by: Simon Glass <[hidden email]>
---

 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 4ec423e9618..a0c1752cddc 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);
--
2.29.2.684.gfbc64c5ab5-goog

123