[PATCH 24/26] dm: core: Split out scanning code to dm_scan()

2020-12-19 Thread Simon Glass
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 fe7359433f6..2a5ebec27d8 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
-- 
2.29.2.684.gfbc64c5ab5-goog



[PATCH 26/26] dm: core: Add logging when lists_bind_fdt() fails

2020-12-19 Thread Simon Glass
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 426444db3a9..e214306b904 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)
-- 
2.29.2.684.gfbc64c5ab5-goog



[PATCH 25/26] dm: core: Allow the uclass list to move

2020-12-19 Thread Simon Glass
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 6a9bee093d0..aeab3836ed7 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 2a5ebec27d8..3adbc94eb94 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 e773e34833e..cdb975d5b31 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 87d827d0f43..b63575919f0 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 03b092bdf7d..639bbd293d9 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 565896ed504..580d171e30e 100644
--- a/test/dm/core.c
+++ b/test

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

2020-12-19 Thread Simon Glass
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/

[PATCH 22/26] dm: core: Access device ofnode through functions

2020-12-19 Thread Simon Glass
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 af6ea439646..766ed95f1a6 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 1c74bfb93a3..bd43179fc79 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 cd28e0cae37..46b7677783f 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 82068578ffb..d6da59d269b 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_n

Re: [BUG]odroid-c2 does not hotplug usb-devices

2020-12-19 Thread Otto Meier

Hi Martin,

Am 19.12.20 um 14:58 schrieb Martin Blumenstingl:

Hi Otto,

On Mon, Dec 14, 2020 at 8:34 PM Otto Meier  wrote:

Hi Martin,

Am 13.12.20 um 19:46 schrieb Martin Blumenstingl:

Hi Otto,

On Mon, Dec 7, 2020 at 1:43 PM Otto Meier  wrote:
[...]

So with the latest u-boot and the kernel from 
https://github.com/chewitt/linux/tree/amlogic-5.10.y
commit 725fc8df7898102f9031ba2075f763884ffa3ee8 everything is working again.
USB does hotplugging as expected.

So, this fixes USB under Linux ?? It's not clear

if you have time it would be great if you could figure out which of
the patches from Christian's tree fixes USB hotplugging for you.
Or is it fixed in Linux 5.10-rcX even without any patches?


The new mainline kernel 5.10.0 from Linus, without any other patches
does detect USB hotpluging,
when using u-boot DMI: Hardkernel Co., Ltd. ODROID-C2/ODROID-C2, BIOS
2021.01-rc3-00039-gec79f5ce22-dirty 12/08/2020
and the following u-boot patch:

[...]

When i use the last unpatched emmc bootable u-boot 2020.04 the kernel
boots, but usb hotplugging
does not work.

Thank you for testing this!


Hope this describes my findings. If i can help further, please give me a
note.

to be honest: I am a bit lost here. I don't understand how the BOOT_*
pins interfere with USB.
I also don't have any Odroid-C2 board myself so I cannot do any
experiments myself.
Neil, please let me know if you have any idea here.

The latest Patch from Neil in U-boot also
fixes all the problems:

This fixes the wrong usage of clrsetbits_le32(), badly setting the set argument.

Fixes: c4c726c26b ("pinctrl: meson: add pinconf support")
Reported-by: Anton Arapov
Reported-by: Otto Meier
Signed-off-by: Neil Armstrong
---
Hi Anton, Otto,

This should fix eMMC booting on Odroid-C2, could you have a quick try to 
confirm ?

Thanks,
Neil

 drivers/pinctrl/meson/pinctrl-meson.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/meson/pinctrl-meson.c 
b/drivers/pinctrl/meson/pinctrl-meson.c
index d4539b02d8..5065b62436 100644
--- a/drivers/pinctrl/meson/pinctrl-meson.c
+++ b/drivers/pinctrl/meson/pinctrl-meson.c
@@ -216,13 +216,13 @@ static int meson_pinconf_bias_set(struct udevice *dev, 
unsigned int pin,
}

/* othewise, enable the bias and select level */
-   clrsetbits_le32(priv->reg_pullen + reg, BIT(bit), 1);
+   clrsetbits_le32(priv->reg_pullen + reg, BIT(bit), BIT(bit));
ret = meson_gpio_calc_reg_and_bit(dev, offset, REG_PULL, ®, &bit);
if (ret)
return ret;

clrsetbits_le32(priv->reg_pull + reg, BIT(bit),
-   param == PIN_CONFIG_BIAS_PULL_UP);
+   (param == PIN_CONFIG_BIAS_PULL_UP ? BIT(bit) : 0));

return 0;
 }
--
2.25.1

perhaps this gives an idea of what was wrong.
But anyhow for me the issues with U-boot and usb hotplug is solved so far.
For me this is even more i understand.




Best regards,
Martin


Thanks for your help.

Otto


Re: [BUG]odroid-c2 does not hotplug usb-devices

2020-12-19 Thread Anand Moon
Hi Martin,

On Sat, 19 Dec 2020 at 19:29, Martin Blumenstingl
 wrote:
>
> Hi Otto,
>
> On Mon, Dec 14, 2020 at 8:34 PM Otto Meier  wrote:
> >
> > Hi Martin,
> >
> > Am 13.12.20 um 19:46 schrieb Martin Blumenstingl:
> > > Hi Otto,
> > >
> > > On Mon, Dec 7, 2020 at 1:43 PM Otto Meier  wrote:
> > > [...]
> >  So with the latest u-boot and the kernel from 
> >  https://github.com/chewitt/linux/tree/amlogic-5.10.y
> >  commit 725fc8df7898102f9031ba2075f763884ffa3ee8 everything is working 
> >  again.
> >  USB does hotplugging as expected.
> > >>> So, this fixes USB under Linux ?? It's not clear
> > > if you have time it would be great if you could figure out which of
> > > the patches from Christian's tree fixes USB hotplugging for you.
> > > Or is it fixed in Linux 5.10-rcX even without any patches?
> > >
> > The new mainline kernel 5.10.0 from Linus, without any other patches
> > does detect USB hotpluging,
> > when using u-boot DMI: Hardkernel Co., Ltd. ODROID-C2/ODROID-C2, BIOS
> > 2021.01-rc3-00039-gec79f5ce22-dirty 12/08/2020
> > and the following u-boot patch:
> [...]
> > When i use the last unpatched emmc bootable u-boot 2020.04 the kernel
> > boots, but usb hotplugging
> > does not work.
> Thank you for testing this!
>
> > Hope this describes my findings. If i can help further, please give me a
> > note.
> to be honest: I am a bit lost here. I don't understand how the BOOT_*
> pins interfere with USB.
> I also don't have any Odroid-C2 board myself so I cannot do any
> experiments myself.
> Neil, please let me know if you have any idea here.
>
>
> Best regards,
> Martin
>

I was also looking into this issue so I made some changes in the
phy driver to resolve the issue. Plz share your thoughts on the changes below.

Best Regards
-Anand

amoon@ThinkPad-T440s:~/mainline/linux-aml-5.y-devel$ git diff
diff --git a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
index 7c029f552a23..363dd2ac17e6 100644
--- a/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
+++ b/arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi
@@ -20,6 +20,7 @@ usb0_phy: phy@c000 {
#phy-cells = <0>;
reg = <0x0 0xc000 0x0 0x20>;
resets = <&reset RESET_USB_OTG>;
+   reset-names = "phy-reset";
clocks = <&clkc CLKID_USB>, <&clkc CLKID_USB0>;
clock-names = "usb_general", "usb";
status = "disabled";
@@ -30,6 +31,7 @@ usb1_phy: phy@c020 {
#phy-cells = <0>;
reg = <0x0 0xc020 0x0 0x20>;
resets = <&reset RESET_USB_OTG>;
+   reset-names = "phy-reset";
clocks = <&clkc CLKID_USB>, <&clkc CLKID_USB1>;
clock-names = "usb_general", "usb";
status = "disabled";
diff --git a/drivers/phy/amlogic/phy-meson8b-usb2.c
b/drivers/phy/amlogic/phy-meson8b-usb2.c
index 03c061dd5f0d..31523becc878 100644
--- a/drivers/phy/amlogic/phy-meson8b-usb2.c
+++ b/drivers/phy/amlogic/phy-meson8b-usb2.c
@@ -143,14 +143,6 @@ static int phy_meson8b_usb2_power_on(struct phy *phy)
u32 reg;
int ret;

-   if (!IS_ERR_OR_NULL(priv->reset)) {
-   ret = reset_control_reset(priv->reset);
-   if (ret) {
-   dev_err(&phy->dev, "Failed to trigger USB reset\n");
-   return ret;
-   }
-   }
-
ret = clk_prepare_enable(priv->clk_usb_general);
if (ret) {
dev_err(&phy->dev, "Failed to enable USB general clock\n");
@@ -222,9 +214,23 @@ static int phy_meson8b_usb2_power_off(struct phy *phy)
return 0;
 }

+static int phy_meson8b_usb2_reset(struct phy *phy)
+{
+   struct phy_meson8b_usb2_priv *priv = phy_get_drvdata(phy);
+
+   if (priv->reset) {
+   reset_control_assert(priv->reset);
+   udelay(10);
+   reset_control_deassert(priv->reset);
+   }
+
+   return 0;
+}
+
 static const struct phy_ops phy_meson8b_usb2_ops = {
.power_on   = phy_meson8b_usb2_power_on,
.power_off  = phy_meson8b_usb2_power_off,
+   .reset  = phy_meson8b_usb2_reset,
.owner  = THIS_MODULE,
 };

@@ -271,6 +277,10 @@ static int phy_meson8b_usb2_probe(struct
platform_device *pdev)
return -EINVAL;
}

+   priv->reset = of_reset_control_get_shared(pdev->dev.of_node,
"phy-reset");
+   if (IS_ERR(priv->reset))
+   priv->reset = NULL;
+
phy = devm_phy_create(&pdev->dev, NULL, &phy_meson8b_usb2_ops);
if (IS_ERR(phy)) {
dev_err(&pdev->dev, "failed to create PHY\n");

> ___
> linux-amlogic mailing list
> linux-amlo...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-amlogic


Re: AXP803 Driver

2020-12-19 Thread Torsten Duwe
On Sat, 19 Dec 2020 17:15:21 +0100
Torsten Duwe  wrote:

> On Fri, 18 Dec 2020 21:41:28 +0300
> Anton Gorlov  wrote:
> 
> > Hi all.
> > 
> > Are there any plans to support AXP803 power regulator in u-boot?
> 
> Well, I already wrote some generic AXP driver, inspired by the code in
> the Linux kernel:
> 
> https://build.opensuse.org/source/home:duwe:Teres-I/u-boot/0103-Add-AXP803-PMIC-support.patch

Sorry, linked too deeply; open build service gets picky here.

https://build.opensuse.org/package/show/home:duwe:Teres-I/u-boot

Should get you to "0103-Add-AXP803-PMIC-support.patch"
without logging in.

> It needs some more clean-up and maybe separation into smaller patches,
> which both I've not gotten at yet.

Torsten


Re: AXP803 Driver

2020-12-19 Thread Anton Gorlov

Thank you!


20.12.2020 2:41, Torsten Duwe пишет:

On Sat, 19 Dec 2020 17:15:21 +0100
Torsten Duwe  wrote:


On Fri, 18 Dec 2020 21:41:28 +0300
Anton Gorlov  wrote:


Hi all.

Are there any plans to support AXP803 power regulator in u-boot?


Well, I already wrote some generic AXP driver, inspired by the code in
the Linux kernel:

https://build.opensuse.org/source/home:duwe:Teres-I/u-boot/0103-Add-AXP803-PMIC-support.patch


Sorry, linked too deeply; open build service gets picky here.

https://build.opensuse.org/package/show/home:duwe:Teres-I/u-boot

Should get you to "0103-Add-AXP803-PMIC-support.patch"
without logging in.


It needs some more clean-up and maybe separation into smaller patches,
which both I've not gotten at yet.


Torsten





Re: [PATCH 00/13] Nokia RX-51: Fix USB TTY console and enable it

2020-12-19 Thread Pali Rohár
On Friday 11 December 2020 16:23:50 Lokesh Vutla wrote:
> Hi Pali,
> 
> On 11/12/20 1:31 am, Pali Rohár wrote:
> > Hello Lokesh, could you please process this patch series? USB serial
> > console on Nokia N900 is really useful for debugging and currently in
> > U-Boot master code is broken. Pavel has already reviewed patches and
> > also CI tests passed.
> 
> I am out of office from past 3 weeks and will be back on Monday. Will try to 
> get
> to this series early next week. Sorry for the delayed response.

Ok! Let me know then if there are any issues in these patches.

> Thanks and regards,
> Lokesh
> 
> > 
> > On Sunday 29 November 2020 17:46:05 Pali Rohár wrote:
> >> This patch series fix usbtty code (serial console via USB peripheral
> >> mode), fix underlying musb peripheral code, fix compilation of
> >> CONFIG_USB_DEVICE (used by usbtty), remove unused Nokia RX-51 code to
> >> decrease size of U-Boot binary and finally enable usbtty serial console
> >> for Nokia RX-51.
> >>
> >> With this patch series debugging of Nokia RX-51 can be done also via USB
> >> serial console.
> >>
> >> On computer this serial console is accessible via /dev/ttyACM0 device.
> >>
> >> With current implementation there is an issue in musb driver that it
> >> loose receiving bytes from USB bus when too many a characters are send
> >> over USB tty from computer. Typing on keyboard to kermit terminal
> >> connected to /dev/ttyACM0 is working fine. But pasting more more bytes
> >> to terminal cause data lost on receiving side. I do not know where is
> >> the issue or how to fix it (it looks like that data are lost at low
> >> level when reading them from msub FIFO hardware) but typing on keyboard
> >> is working fine. This is rather issue for sending files via x/y/z-modem
> >> or kermit protocol. Currently U-Boot is not able to receive any file
> >> via usbtty with musb driver due to this issue.
> >>
> >> Pali Rohár (13):
> >>   serial: usbtty: Fix puts function
> >>   usb: musb: Fix compilation of gadget code
> >>   usb: musb: Always clear the data toggle bit when configuring ep
> >>   usb: musb: Fix configuring FIFO for endpoints
> >>   usb: musb: Read value of PERI_RXCSR to 16bit variable
> >>   usb: musb: Fix transmission of bigger buffers
> >>   usb: gadget: Do not export usbd_device_* arrays
> >>   usb: gadget: Use dbg_ep0() macro instead of serial_printf()
> >>   arm: omap3: Compile lowlevel_init() function only when it is used
> >>   arm: omap3: Compile s_init() function only when it is used
> >>   Nokia RX-51: Remove function set_muxconf_regs()
> >>   Nokia RX-51: Move content of rx51.h to rx51.c
> >>   Nokia RX-51: Enable usbtty serial console by default
> >>
> >>  Makefile  |   1 +
> >>  arch/arm/mach-omap2/omap3/board.c |   3 +
> >>  arch/arm/mach-omap2/omap3/lowlevel_init.S |   6 +-
> >>  board/nokia/rx51/rx51.c   |  28 +-
> >>  board/nokia/rx51/rx51.h   | 377 --
> >>  configs/nokia_rx51_defconfig  |   6 +-
> >>  doc/README.nokia_rx51 |  15 +-
> >>  drivers/serial/usbtty.c   |   4 +-
> >>  drivers/usb/gadget/core.c |  38 +--
> >>  drivers/usb/gadget/ep0.c  |  47 ++-
> >>  drivers/usb/musb/musb_core.c  |  10 +-
> >>  drivers/usb/musb/musb_udc.c   |  19 +-
> >>  include/configs/nokia_rx51.h  |  16 +-
> >>  include/usbdevice.h   |  15 -
> >>  14 files changed, 92 insertions(+), 493 deletions(-)
> >>  delete mode 100644 board/nokia/rx51/rx51.h
> >>
> >> -- 
> >> 2.20.1
> >>


RE: [RESEND,PATCH v3] cmd: Add a pwm command

2020-12-19 Thread Pragnesh Patel
Hi Simon,

>-Original Message-
>From: Simon Glass 
>Sent: 12 December 2020 21:05
>To: Pragnesh Patel 
>Cc: U-Boot Mailing List ; Atish Patra
>; Palmer Dabbelt ; Bin
>Meng ; Paul Walmsley ( Sifive)
>; Anup Patel ; Sagar Kadam
>; rick ; Naoki Hayama
>; Marek Vasut ;
>Patrick Delaunay ; Adam Ford
>; Thomas Hebb ; Ramon Fried
>; Heinrich Schuchardt ; Bin Meng
>; Sam Protsenko ; Miquel
>Raynal ; Frédéric Danis
>; Philippe Reynes
>; Patrice Chotard ;
>Baruch Siach ; Vladimir Olovyannikov
>
>Subject: Re: [RESEND,PATCH v3] cmd: Add a pwm command
>
>[External Email] Do not click links or attachments unless you recognize the
>sender and know the content is safe
>
>Hi Pragnesh,
>
>On Wed, 2 Dec 2020 at 21:59, Pragnesh Patel 
>wrote:
>>
>> Add the command "pwm" for controlling the pwm channels. This command
>> provides pwm invert/config/enable/disable functionalities via PWM
>> uclass drivers
>>
>> Signed-off-by: Pragnesh Patel 
>> Reviewed-by: Simon Glass 
>> ---
>>
>> Changes in v3:
>> - Replace goto with return
>> - Print return value for error
>> - Change the assert condition for success
>>
>> Changes in v2:
>> - Add test for pwm command
>>
>>  README|   1 +
>>  cmd/Kconfig   |   6 ++
>>  cmd/Makefile  |   1 +
>>  cmd/pwm.c | 117 ++
>>  configs/sandbox_defconfig |   1 +
>>  test/cmd/Makefile |   1 +
>>  test/cmd/pwm.c|  47 +++
>>  7 files changed, 174 insertions(+)
>>  create mode 100644 cmd/pwm.c
>>  create mode 100644 test/cmd/pwm.c
>>
>> diff --git a/README b/README
>> index cb49aa15da..dab291e0d0 100644
>> --- a/README
>> +++ b/README
>> @@ -3160,6 +3160,7 @@ i2c   - I2C sub-system
>>  sspi   - SPI utility commands
>>  base   - print or set address offset
>>  printenv- print environment variables
>> +pwm- control pwm channels
>>  setenv - set environment variables
>>  saveenv - save environment variables to persistent storage  protect -
>> enable or disable FLASH write protection diff --git a/cmd/Kconfig
>> b/cmd/Kconfig index 1595de999b..0d085108f4 100644
>> --- a/cmd/Kconfig
>> +++ b/cmd/Kconfig
>> @@ -918,6 +918,12 @@ config CMD_GPIO
>> help
>>   GPIO support.
>>
>> +config CMD_PWM
>> +   bool "pwm"
>> +   depends on DM_PWM
>> +   help
>> + Control PWM channels, this allows invert/config/enable/disable PWM
>channels.
>> +
>>  config CMD_GPT
>> bool "GPT (GUID Partition Table) command"
>> select EFI_PARTITION
>> diff --git a/cmd/Makefile b/cmd/Makefile index dd86675bf2..75df3c136c
>> 100644
>> --- a/cmd/Makefile
>> +++ b/cmd/Makefile
>> @@ -120,6 +120,7 @@ endif
>>  obj-$(CONFIG_CMD_PINMUX) += pinmux.o
>>  obj-$(CONFIG_CMD_PMC) += pmc.o
>>  obj-$(CONFIG_CMD_PSTORE) += pstore.o
>> +obj-$(CONFIG_CMD_PWM) += pwm.o
>>  obj-$(CONFIG_CMD_PXE) += pxe.o pxe_utils.o
>>  obj-$(CONFIG_CMD_WOL) += wol.o
>>  obj-$(CONFIG_CMD_QFW) += qfw.o
>> diff --git a/cmd/pwm.c b/cmd/pwm.c
>> new file mode 100644
>> index 00..5849fc57b6
>> --- /dev/null
>> +++ b/cmd/pwm.c
>> @@ -0,0 +1,117 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * Control PWM channels
>> + *
>> + * Copyright (c) 2020 SiFive, Inc
>> + * author: Pragnesh Patel   */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +
>> +enum pwm_cmd {
>> +   PWM_SET_INVERT,
>> +   PWM_SET_CONFIG,
>> +   PWM_SET_ENABLE,
>> +   PWM_SET_DISABLE,
>> +};
>> +
>> +static int do_pwm(struct cmd_tbl *cmdtp, int flag, int argc,
>> + char *const argv[])
>> +{
>> +   const char *str_cmd, *str_channel = NULL, *str_enable = NULL;
>> +   const char *str_pwm = NULL, *str_period = NULL, *str_duty = NULL;
>> +   enum pwm_cmd sub_cmd;
>> +   struct udevice *dev;
>> +   u32 channel, pwm_enable, pwm_dev, period_ns = 0, duty_ns = 0;
>> +   int ret;
>> +
>> +   if (argc < 4)
>> +   return CMD_RET_USAGE;
>> +
>> +   str_cmd = argv[1];
>> +   argc -= 2;
>> +   argv += 2;
>> +
>> +   if (argc > 0) {
>> +   str_pwm = *argv;
>> +   argc--;
>> +   argv++;
>> +   }
>> +
>> +   if (!str_pwm)
>> +   return CMD_RET_USAGE;
>> +
>> +   switch (*str_cmd) {
>> +   case 'i':
>> +   sub_cmd = PWM_SET_INVERT;
>> +   break;
>> +   case 'c':
>> +   sub_cmd = PWM_SET_CONFIG;
>> +   break;
>> +   case 'e':
>> +   sub_cmd = PWM_SET_ENABLE;
>> +   break;
>> +   case 'd':
>> +   sub_cmd = PWM_SET_DISABLE;
>> +   break;
>> +   default:
>> +   return CMD_RET_USAGE;
>> +   }
>> +
>> +   pwm_dev = simple_strtoul(str_pwm, NULL, 10);
>> +   ret = uclass_get_device(UCLASS_PWM, pwm_dev, &dev);
>> +   if (ret) {
>> +   printf("pwm: '%s' not found\n", str_pwm);
>> +   return cmd_process_error(cmdtp, ret);
>> +   

[PATCH] i2c: mxc_i2c: improve error message readability

2020-12-19 Thread ferlandm
From: Marc Ferland 

Signed-off-by: Marc Ferland 
---
 drivers/i2c/mxc_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
index 7609594bd0..d486dab043 100644
--- a/drivers/i2c/mxc_i2c.c
+++ b/drivers/i2c/mxc_i2c.c
@@ -954,7 +954,7 @@ static int mxc_i2c_probe(struct udevice *bus)
!dm_gpio_is_valid(&i2c_bus->scl_gpio) ||
ret || ret2) {
dev_err(bus,
-   "i2c bus %d at %lu, fail to request scl/sda 
gpio\n",
+   "i2c bus %d at 0x%2lx, fail to request scl/sda 
gpio\n",
bus->seq, i2c_bus->base);
return -EINVAL;
}
-- 
2.25.1



Re: [BUG]odroid-c2 does not hotplug usb-devices

2020-12-19 Thread Martin Blumenstingl
Hi Otto,

On Mon, Dec 14, 2020 at 8:34 PM Otto Meier  wrote:
>
> Hi Martin,
>
> Am 13.12.20 um 19:46 schrieb Martin Blumenstingl:
> > Hi Otto,
> >
> > On Mon, Dec 7, 2020 at 1:43 PM Otto Meier  wrote:
> > [...]
>  So with the latest u-boot and the kernel from 
>  https://github.com/chewitt/linux/tree/amlogic-5.10.y
>  commit 725fc8df7898102f9031ba2075f763884ffa3ee8 everything is working 
>  again.
>  USB does hotplugging as expected.
> >>> So, this fixes USB under Linux ?? It's not clear
> > if you have time it would be great if you could figure out which of
> > the patches from Christian's tree fixes USB hotplugging for you.
> > Or is it fixed in Linux 5.10-rcX even without any patches?
> >
> The new mainline kernel 5.10.0 from Linus, without any other patches
> does detect USB hotpluging,
> when using u-boot DMI: Hardkernel Co., Ltd. ODROID-C2/ODROID-C2, BIOS
> 2021.01-rc3-00039-gec79f5ce22-dirty 12/08/2020
> and the following u-boot patch:
[...]
> When i use the last unpatched emmc bootable u-boot 2020.04 the kernel
> boots, but usb hotplugging
> does not work.
Thank you for testing this!

> Hope this describes my findings. If i can help further, please give me a
> note.
to be honest: I am a bit lost here. I don't understand how the BOOT_*
pins interfere with USB.
I also don't have any Odroid-C2 board myself so I cannot do any
experiments myself.
Neil, please let me know if you have any idea here.


Best regards,
Martin


Re: [PATCH] i2c: mxc_i2c: improve error message readability

2020-12-19 Thread Fabio Estevam
Hi Marc,

On Sat, Dec 19, 2020 at 11:27 AM  wrote:
>
> From: Marc Ferland 
>
> Signed-off-by: Marc Ferland 
> ---
>  drivers/i2c/mxc_i2c.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
> index 7609594bd0..d486dab043 100644
> --- a/drivers/i2c/mxc_i2c.c
> +++ b/drivers/i2c/mxc_i2c.c
> @@ -954,7 +954,7 @@ static int mxc_i2c_probe(struct udevice *bus)
> !dm_gpio_is_valid(&i2c_bus->scl_gpio) ||
> ret || ret2) {
> dev_err(bus,
> -   "i2c bus %d at %lu, fail to request scl/sda 
> gpio\n",
> +   "i2c bus %d at 0x%2lx, fail to request 
> scl/sda gpio\n",

The change looks good.

I would suggest adding a commit message though.

Thanks


[PATCH v2 0/6] Add MMC/SD support for S700

2020-12-19 Thread Amit Singh Tomar
From: Amit Singh Tomar 

This series(v2) has few important updates, while loading large files we found
that MMC framework puts "0x1fffe00" into DMA Frame Length(DMA_FRAME_LEN 0x000C)
but register itself is limited to 24 bits and hence it was failing.
It is due to the wrong Block count(cfg->b_max) used in driver, that should be
just 512. This is now fixed in patch 5/6.

Apart from it, as Andre pointed that we might be just overclocking the MMC/SD
clock, and to confirm this we run following test:

$ md5sum clang 
349eac46cbbe28f8e44da2dce07fa7b7  clang

U-Boot => ext4load mmc 0:2 0x0 clang
503316480 bytes read in 19516 ms (24.6 MiB/s)
U-Boot => md5sum 0x0 0x1e00
md5 for  ... 1dff ==> d793bb51c4a1cf83c96d1980927461ff

Even though file gets loaded but md5sum doesn't match. This is now fixed in
patch 2/6

U-Boot => ext4load mmc 0:2 0x0 clang
503316480 bytes read in 41524 ms (11.6 MiB/s)
U-Boot => md5sum 0x0 0x1e00
md5 for  ... 1dff ==> 349eac46cbbe28f8e44da2dce07fa7b7

-
At the moment on S700 based platforms, only way to load/boot the Kernel
is from Ethernet, and with these patches one can now load/boot the
Kernel from uSD card.

Patches(1/6 and 2/6) adds changes needed for MMC/SD clock. It introduces
set/get callback routine and get/set MMC/SD clock rate based on device id.

Patch 4/6 adds MMC/SD node in U-boot specific dtsi file, which is used by MMC/SD
driver to read controller base address later on.

Patch 5/6 adds driver for MMC/SD controller present on S700 SoC, and its based
on Mainline Linux driver and DMA related bits is picked and simpilified from 
vendor source.

Final patch 6/6 enables the driver support along with MMC commands in
Cubieboard7 config file.

Also, while at it just took the opportunity to synchronize the S700 SoC DT with
Linux in patch 3/6.

This patch-set is tested on Cubieboard7-lite board with following results:

U-Boot 2021.01-rc1-04434-g6589149-dirty (Dec 13 2020 - 13:51:07 +0530)
cubieboard7

DRAM:  1 GiB
PSCI:  v0.2
MMC:   mmc@e021: 0
In:serial@e0126000
Out:   serial@e0126000
Err:   serial@e0126000
Net:   eth0: ethernet@e022
Hit any key to stop autoboot:  0 
U-Boot => 
U-Boot => 
U-Boot => 
U-Boot => mmc info
Device: mmc@e021
Manufacturer ID: 3
OEM: 5344
Name: SC16G 
Bus Speed: 5000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 14.8 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
U-Boot => setenv bootargs console=ttyOWL3,115200n8 earlycon=owl,0xe0126000 
init=/sbin/init  root=/dev/mmcblk0p2 rw rootwait
U-Boot => setenv kernel_addr_r 0x8;setenv fdt_addr_r 0x1000;
U-Boot => fatload mmc 0:1 ${kernel_addr_r} image ;fatload mmc 0:1 ${fdt_addr_r} 
s700-cubieboard7.dtb
27480576 bytes read in 1041 ms (25.2 MiB/s)
7056 bytes read in 2 ms (3.4 MiB/s)
U-Boot => booti $kernel_addr_r - $fdt_addr_r
## Flattened Device Tree blob at 1000
   Booting using the fdt blob at 0x1000
   Loading Device Tree to 3df56000, end 3df5ab8f ... OK

Amit Singh Tomar (6):
  clk: actions: Introduce dummy get/set_rate callbacks
  clk: actions: Add SD/MMC clocks
  ARM: dts: sync Actions Semi S700 DT from Linux 5.10-rc7
  ARM: dts: s700: add MMC/SD controller node
  mmc: actions: add MMC driver for Actions OWL S700
  configs: Enable mmc support

 arch/arm/dts/s700-u-boot.dtsi  |  10 +
 arch/arm/dts/s700.dtsi |  17 +-
 configs/cubieboard7_defconfig  |   3 +
 drivers/clk/owl/clk_owl.c  |  98 ++
 drivers/clk/owl/clk_owl.h  |   2 +
 drivers/mmc/Kconfig|   7 +
 drivers/mmc/Makefile   |   1 +
 drivers/mmc/owl_mmc.c  | 399 +
 include/dt-bindings/power/owl-s700-powergate.h |  19 ++
 9 files changed, 555 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mmc/owl_mmc.c
 create mode 100644 include/dt-bindings/power/owl-s700-powergate.h

-- 
2.7.4



[PATCH v2 1/6] clk: actions: Introduce dummy get/set_rate callbacks

2020-12-19 Thread Amit Singh Tomar
From: Amit Singh Tomar 

This commit introduces get/set_rate callbacks, these are dummy at
the moment, and can be used to get/set clock for various devices
based on the clk id.

Signed-off-by: Amit Singh Tomar 
---
Changes since previous version:
* Removed premature initialization to avoid 
  compiler warnings.
---
 drivers/clk/owl/clk_owl.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/drivers/clk/owl/clk_owl.c b/drivers/clk/owl/clk_owl.c
index 1999c87..5be1b3b 100644
--- a/drivers/clk/owl/clk_owl.c
+++ b/drivers/clk/owl/clk_owl.c
@@ -128,6 +128,30 @@ int owl_clk_disable(struct clk *clk)
return 0;
 }
 
+static ulong owl_clk_get_rate(struct clk *clk)
+{
+   ulong rate;
+
+   switch (clk->id) {
+   default:
+   return -ENOENT;
+   }
+
+   return rate;
+}
+
+static ulong owl_clk_set_rate(struct clk *clk, ulong rate)
+{
+   ulong new_rate;
+
+   switch (clk->id) {
+   default:
+   return -ENOENT;
+   }
+
+   return new_rate;
+}
+
 static int owl_clk_probe(struct udevice *dev)
 {
struct owl_clk_priv *priv = dev_get_priv(dev);
@@ -145,6 +169,8 @@ static int owl_clk_probe(struct udevice *dev)
 static const struct clk_ops owl_clk_ops = {
.enable = owl_clk_enable,
.disable = owl_clk_disable,
+   .get_rate = owl_clk_get_rate,
+   .set_rate = owl_clk_set_rate,
 };
 
 static const struct udevice_id owl_clk_ids[] = {
-- 
2.7.4



[PATCH v2 2/6] clk: actions: Add SD/MMC clocks

2020-12-19 Thread Amit Singh Tomar
From: Amit Singh Tomar 

This commit adds SD/MMC clocks, and provides .set/get_rate callbacks
for SD/MMC device present on Actions OWL S700 SoCs.

Signed-off-by: Amit Singh Tomar 
---
Changes since previous version:
* Removed rate *= 2 as this just overclocks.
* Separated the divide by 128 bit from divider value.
* Provided the separate routine to get sd parent rate
  based on bit 9.   
* Removed unnecessary initialization.
---
 drivers/clk/owl/clk_owl.c | 72 +++
 drivers/clk/owl/clk_owl.h |  2 ++
 2 files changed, 74 insertions(+)

diff --git a/drivers/clk/owl/clk_owl.c b/drivers/clk/owl/clk_owl.c
index 5be1b3b..cac8e6e 100644
--- a/drivers/clk/owl/clk_owl.c
+++ b/drivers/clk/owl/clk_owl.c
@@ -92,6 +92,9 @@ int owl_clk_enable(struct clk *clk)
setbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_ETH);
setbits_le32(priv->base + CMU_ETHERNETPLL, 5);
break;
+   case CLK_SD0:
+   setbits_le32(priv->base + CMU_DEVCLKEN0, CMU_DEVCLKEN0_SD0);
+   break;
default:
return -EINVAL;
}
@@ -121,6 +124,9 @@ int owl_clk_disable(struct clk *clk)
case CLK_ETHERNET:
clrbits_le32(priv->base + CMU_DEVCLKEN1, CMU_DEVCLKEN1_ETH);
break;
+   case CLK_SD0:
+   clrbits_le32(priv->base + CMU_DEVCLKEN0, CMU_DEVCLKEN0_SD0);
+   break;
default:
return -EINVAL;
}
@@ -128,11 +134,73 @@ int owl_clk_disable(struct clk *clk)
return 0;
 }
 
+static ulong get_sd_parent_rate(struct owl_clk_priv *priv, u32 dev_index)
+{
+   ulong rate;
+   u32 reg;
+
+   reg = readl(priv->base + (CMU_SD0CLK + dev_index * 0x4));
+   /* Clock output of DEV/NAND_PLL
+* Range: 48M ~ 756M
+* Frequency= PLLCLK * 6
+*/
+   if (reg & 0x200)
+   rate = readl(priv->base + CMU_NANDPLL) & 0x7f;
+   else
+   rate = readl(priv->base + CMU_DEVPLL) & 0x7f;
+
+   rate *= 600;
+
+   return rate;
+}
+
+static ulong owl_get_sd_clk_rate(struct owl_clk_priv *priv, int sd_index)
+{
+   uint div;
+   ulong parent_rate = get_sd_parent_rate(priv, sd_index);
+
+   div = readl(priv->base + (CMU_SD0CLK + sd_index * 0x4)) & 0x1f;
+   div++;
+
+   return (parent_rate / div);
+}
+
+static ulong owl_set_sd_clk_rate(struct owl_clk_priv *priv, ulong rate,
+int sd_index)
+{
+   uint div, val;
+   ulong parent_rate = get_sd_parent_rate(priv, sd_index);
+
+   if (rate <= 0)
+   return rate;
+
+   div = (parent_rate / rate);
+
+   val = readl(priv->base + (CMU_SD0CLK + sd_index * 0x4));
+   /* Bits 4..0 is used to program div value and bit 8 to enable
+* divide by 128 circuit
+*/
+   val &= ~0x11f;
+   if (div >= 128) {
+   div = div / 128;
+   val |= 0x100; /* enable divide by 128 circuit */
+   }
+   div--;
+   val |= (div & 0x1f);
+   writel(val, priv->base + (CMU_SD0CLK + sd_index * 0x4));
+
+   return owl_get_sd_clk_rate(priv, 0);
+}
+
 static ulong owl_clk_get_rate(struct clk *clk)
 {
+   struct owl_clk_priv *priv = dev_get_priv(clk->dev);
ulong rate;
 
switch (clk->id) {
+   case CLK_SD0:
+   rate = owl_get_sd_clk_rate(priv, 0);
+   break;
default:
return -ENOENT;
}
@@ -142,9 +210,13 @@ static ulong owl_clk_get_rate(struct clk *clk)
 
 static ulong owl_clk_set_rate(struct clk *clk, ulong rate)
 {
+   struct owl_clk_priv *priv = dev_get_priv(clk->dev);
ulong new_rate;
 
switch (clk->id) {
+   case CLK_SD0:
+   new_rate = owl_set_sd_clk_rate(priv, rate, 0);
+   break;
default:
return -ENOENT;
}
diff --git a/drivers/clk/owl/clk_owl.h b/drivers/clk/owl/clk_owl.h
index a01f81a..ee5eba4 100644
--- a/drivers/clk/owl/clk_owl.h
+++ b/drivers/clk/owl/clk_owl.h
@@ -62,4 +62,6 @@ struct owl_clk_priv {
 #define CMU_DEVCLKEN1_UART5BIT(21)
 #define CMU_DEVCLKEN1_UART3BIT(11)
 
+#define CMU_DEVCLKEN0_SD0  BIT(22)
+
 #endif
-- 
2.7.4



[PATCH v2 3/6] ARM: dts: sync Actions Semi S700 DT from Linux 5.10-rc7

2020-12-19 Thread Amit Singh Tomar
From: Amit Singh Tomar 

This Synchronizes the Actions Semi S700 SoC DT changes from
commit "0477e9288185" ("Linux 5.10-rc7").

Signed-off-by: Amit Singh Tomar 
---
Changes since previous version
* No change.
---
 arch/arm/dts/s700.dtsi | 17 -
 include/dt-bindings/power/owl-s700-powergate.h | 19 +++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 include/dt-bindings/power/owl-s700-powergate.h

diff --git a/arch/arm/dts/s700.dtsi b/arch/arm/dts/s700.dtsi
index 2006ad5..2c78cae 100644
--- a/arch/arm/dts/s700.dtsi
+++ b/arch/arm/dts/s700.dtsi
@@ -5,6 +5,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 / {
@@ -231,7 +232,7 @@
 
pinctrl: pinctrl@e01b {
compatible = "actions,s700-pinctrl";
-   reg = <0x0 0xe01b 0x0 0x1000>;
+   reg = <0x0 0xe01b 0x0 0x100>;
clocks = <&cmu CLK_GPIO>;
gpio-controller;
gpio-ranges = <&pinctrl 0 0 136>;
@@ -244,5 +245,19 @@
 ,
 ;
};
+
+   dma: dma-controller@e023 {
+   compatible = "actions,s700-dma";
+   reg = <0x0 0xe023 0x0 0x1000>;
+   interrupts = ,
+,
+,
+;
+   #dma-cells = <1>;
+   dma-channels = <10>;
+   dma-requests = <44>;
+   clocks = <&cmu CLK_DMAC>;
+   power-domains = <&sps S700_PD_DMA>;
+   };
};
 };
diff --git a/include/dt-bindings/power/owl-s700-powergate.h 
b/include/dt-bindings/power/owl-s700-powergate.h
new file mode 100644
index 000..4cf1aef
--- /dev/null
+++ b/include/dt-bindings/power/owl-s700-powergate.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Actions Semi S700 SPS
+ *
+ * Copyright (c) 2017 Andreas Färber
+ */
+#ifndef DT_BINDINGS_POWER_OWL_S700_POWERGATE_H
+#define DT_BINDINGS_POWER_OWL_S700_POWERGATE_H
+
+#define S700_PD_VDE0
+#define S700_PD_VCE_SI 1
+#define S700_PD_USB2_1 2
+#define S700_PD_HDE3
+#define S700_PD_DMA4
+#define S700_PD_DS 5
+#define S700_PD_USB3   6
+#define S700_PD_USB2_0 7
+
+#endif
-- 
2.7.4



[PATCH v2 4/6] ARM: dts: s700: add MMC/SD controller node

2020-12-19 Thread Amit Singh Tomar
From: Amit Singh Tomar 

This patch adds node for ethernet controller found on Action Semi OWL
S700 SoC.

Since, upstream Linux binding has not been merged for S700 MMC/SD
controller, Changes are put in u-boot specific dtsi file.

Signed-off-by: Amit Singh Tomar 
---
Changes since previous version
* No change.
---
 arch/arm/dts/s700-u-boot.dtsi | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/dts/s700-u-boot.dtsi b/arch/arm/dts/s700-u-boot.dtsi
index 1b27682..3c3396b 100644
--- a/arch/arm/dts/s700-u-boot.dtsi
+++ b/arch/arm/dts/s700-u-boot.dtsi
@@ -19,6 +19,16 @@
status = "okay";
 };
 
+   mmc0: mmc@e021 {
+   compatible = "actions,s700-mmc", "actions,owl-mmc";
+   reg = <0x0 0xe021 0x0 0x4000>;
+   interrupts = ;
+   clocks = <&cmu CLK_SD0>;
+   dmas = <&dma 2>;
+   dma-names = "mmc";
+   bus-width = <4>;
+   status = "okay";
+   };
};
 };
 
-- 
2.7.4



[PATCH v2 5/6] mmc: actions: add MMC driver for Actions OWL S700

2020-12-19 Thread Amit Singh Tomar
From: Amit Singh Tomar 

This commit adds support for MMC controllers found on Actions OWL
S700 SoC platform.

Signed-off-by: Amit Singh Tomar 
---
Changes since previous version
* Corrected block count to 512.
* Changed the command timeout value to 30ms.
* Used readl_poll_timeout. 
* Read DMA parameters from DT instead of hardcoding it.
* Reduced number of arguments passed to own_dma_cofig.
* Removed debug leftover.
* Used mmc_of_parse().
---
 drivers/mmc/Kconfig   |   7 +
 drivers/mmc/Makefile  |   1 +
 drivers/mmc/owl_mmc.c | 399 ++
 3 files changed, 407 insertions(+)
 create mode 100644 drivers/mmc/owl_mmc.c

diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 14d7913..61f9c67 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -289,6 +289,13 @@ config MMC_MXC
 
  If unsure, say N.
 
+config MMC_OWL
+   bool "Actions OWL Multimedia Card Interface support"
+   depends on ARCH_OWL && DM_MMC && BLK
+   help
+ This selects the OWL SD/MMC host controller found on board
+ based on Actions S700 SoC.
+
 config MMC_MXS
bool "Freescale MXS Multimedia Card Interface support"
depends on MX23 || MX28 || MX6 || MX7
diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile
index 1c849cb..f270f6c 100644
--- a/drivers/mmc/Makefile
+++ b/drivers/mmc/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_MMC_OMAP_HS) += omap_hsmmc.o
 obj-$(CONFIG_MMC_MXC)  += mxcmmc.o
 obj-$(CONFIG_MMC_MXS)  += mxsmmc.o
 obj-$(CONFIG_MMC_OCTEONTX) += octeontx_hsmmc.o
+obj-$(CONFIG_MMC_OWL)  += owl_mmc.o
 obj-$(CONFIG_MMC_PCI)  += pci_mmc.o
 obj-$(CONFIG_PXA_MMC_GENERIC) += pxa_mmc_gen.o
 obj-$(CONFIG_$(SPL_TPL_)SUPPORT_EMMC_RPMB) += rpmb.o
diff --git a/drivers/mmc/owl_mmc.c b/drivers/mmc/owl_mmc.c
new file mode 100644
index 000..5c48307
--- /dev/null
+++ b/drivers/mmc/owl_mmc.c
@@ -0,0 +1,399 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Amit Singh Tomar 
+ *
+ * Driver for SD/MMC controller present on Actions Semi S700 SoC, based
+ * on Linux Driver "drivers/mmc/host/owl-mmc.c".
+ *
+ * Though, there is a bit (BSEL, BUS or DMA Special Channel Selection) that
+ * controls the data transfer from SDx_DAT register either using CPU AHB Bus
+ * or DMA channel, but seems like, it only works correctly using external DMA
+ * channel, and those special bits used in this driver is picked from vendor
+ * source exclusively for MMC/SD.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*
+ * SDC registers
+ */
+#define OWL_REG_SD_EN   0x
+#define OWL_REG_SD_CTL  0x0004
+#define OWL_REG_SD_STATE0x0008
+#define OWL_REG_SD_CMD  0x000c
+#define OWL_REG_SD_ARG  0x0010
+#define OWL_REG_SD_RSPBUF0  0x0014
+#define OWL_REG_SD_RSPBUF1  0x0018
+#define OWL_REG_SD_RSPBUF2  0x001c
+#define OWL_REG_SD_RSPBUF3  0x0020
+#define OWL_REG_SD_RSPBUF4  0x0024
+#define OWL_REG_SD_DAT  0x0028
+#define OWL_REG_SD_BLK_SIZE 0x002c
+#define OWL_REG_SD_BLK_NUM  0x0030
+#define OWL_REG_SD_BUF_SIZE 0x0034
+
+/* SD_EN Bits */
+#define OWL_SD_EN_RANE  BIT(31)
+#define OWL_SD_EN_RESE  BIT(10)
+#define OWL_SD_ENABLE   BIT(7)
+#define OWL_SD_EN_BSEL  BIT(6)
+#define OWL_SD_EN_DATAWID(x)(((x) & 0x3) << 0)
+#define OWL_SD_EN_DATAWID_MASK 0x03
+
+/* SD_CTL Bits */
+#define OWL_SD_CTL_TOUTEN   BIT(31)
+#define OWL_SD_CTL_DELAY_MSKGENMASK(23, 16)
+#define OWL_SD_CTL_RDELAY(x)(((x) & 0xf) << 20)
+#define OWL_SD_CTL_WDELAY(x)(((x) & 0xf) << 16)
+#define OWL_SD_CTL_TS   BIT(7)
+#define OWL_SD_CTL_LBE  BIT(6)
+#define OWL_SD_CTL_TM(x)(((x) & 0xf) << 0)
+
+#define OWL_SD_DELAY_LOW_CLK0x0f
+#define OWL_SD_DELAY_MID_CLK0x0a
+#define OWL_SD_RDELAY_HIGH 0x08
+#define OWL_SD_WDELAY_HIGH 0x09
+
+/* SD_STATE Bits */
+#define OWL_SD_STATE_DAT0S  BIT(7)
+#define OWL_SD_STATE_CLNR   BIT(4)
+#define OWL_SD_STATE_CRC7ER BIT(0)
+
+#define OWL_MMC_OCR (MMC_VDD_32_33 | MMC_VDD_33_34 | \
+MMC_VDD_165_195)
+
+#define DATA_TRANSFER_TIMEOUT  3
+
+/*
+ * Simple DMA transfer operations defines for MMC/SD card
+ */
+#define SD_DMA_CHANNEL(base, channel)   ((base) + 0x100 * (channel))
+
+#define DMA_MODE   0x
+#define DMA_SOURCE 0x0004
+#define DMA_DESTINATION0x0008
+#de

[PATCH v2 6/6] configs: Enable mmc support

2020-12-19 Thread Amit Singh Tomar
From: Amit Singh Tomar 

This commits enables mmc on the Actions Cubieboard7 board.

Signed-off-by: Amit Singh Tomar 
---
Changes since previous version
* No change
---
 configs/cubieboard7_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/configs/cubieboard7_defconfig b/configs/cubieboard7_defconfig
index 64dc593..d1ee862 100644
--- a/configs/cubieboard7_defconfig
+++ b/configs/cubieboard7_defconfig
@@ -14,3 +14,6 @@ CONFIG_PHY_REALTEK=y
 CONFIG_RTL8201F_PHY_S700_RMII_TIMINGS=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_ETH_DESIGNWARE_S700=y
+CONFIG_DM_MMC=y
+CONFIG_MMC_OWL=y
+CONFIG_CMD_MMC=y
-- 
2.7.4



Re: AXP803 Driver

2020-12-19 Thread Torsten Duwe
On Fri, 18 Dec 2020 21:41:28 +0300
Anton Gorlov  wrote:

> Hi all.
> 
> Are there any plans to support AXP803 power regulator in u-boot?

Well, I already wrote some generic AXP driver, inspired by the code in
the Linux kernel:

https://build.opensuse.org/source/home:duwe:Teres-I/u-boot/0103-Add-AXP803-PMIC-support.patch

It needs some more clean-up and maybe separation into smaller patches,
which both I've not gotten at yet.

Torsten


Re: [PATCH v3 28/28] dm: Update documentation for new sequence numbers

2020-12-19 Thread Simon Glass
Update the driver model documention to describe how sequence numbers now
work.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Update the docs to indicate all devices get a sequence number
- Update the docs to explain how aliases reserve sequence numbers
- Drop commit changing efi_uc_destroy()

 doc/driver-model/design.rst | 59 ++---
 1 file changed, 35 insertions(+), 24 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 27/28] dm: core: Drop seq and req_seq

2020-12-19 Thread Simon Glass
Now that migration to the new sequence numbers is complete, drop the old
fields. Add a test that covers the new behaviour.

Also drop the check for OF_PRIOR_STAGE since we always assign sequence
numbers now.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Adjust the tests to handle the new allocation scheme
- Simplify the logic so auto_seq is positive

 drivers/core/device-remove.c |  1 -
 drivers/core/device.c| 17 ++--
 include/dm/device.h  |  9 +
 test/dm/test-fdt.c   | 39 
 4 files changed, 42 insertions(+), 24 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 26/28] cmd: Drop use of old sequence numbers in commands

2020-12-19 Thread Simon Glass
Several commands use sequence numbers. Update them to use the new ones.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 cmd/axi.c   | 4 ++--
 cmd/i2c.c   | 2 +-
 cmd/osd.c   | 4 ++--
 drivers/core/dump.c | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 25/28] dm: core: Update uclass_find_next_free_req_seq() for new scheme

2020-12-19 Thread Simon Glass
This function current deals with req_seq which is deprecated. Update it to
use the new sequence numbers, putting them above existing aliases. Rename
the function to make this clear.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Update for new logic
- Adjust commit message
- Drop pointless check for max == -1

 drivers/core/device.c|  8 ++--
 drivers/core/uclass.c| 19 +--
 drivers/pci/pci-uclass.c |  2 +-
 include/dm/uclass-internal.h | 17 ++---
 4 files changed, 26 insertions(+), 20 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 23/28] dm: Drop uclass_resolve_seq()

2020-12-19 Thread Simon Glass
This function is not needed anymore. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/core/device.c |  8 
 drivers/core/uclass.c | 39 ---
 include/dm/uclass.h   | 15 ---
 3 files changed, 62 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 21/28] dm: Switch over to use new sequence number for dev_seq()

2020-12-19 Thread Simon Glass
Update this function to use the new sequence number and fix up the test
that deals with this.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Adjust the tests to handle the new allocation scheme
- Drop the networking changes which are no-longer needed

 arch/sandbox/dts/test.dts |  2 +-
 drivers/core/uclass.c |  6 ++--
 include/dm/device.h   |  2 +-
 test/dm/test-fdt.c| 65 ++-
 4 files changed, 40 insertions(+), 35 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 22/28] dm: test: Add a test for DM_UC_FLAG_NO_AUTO_SEQ

2020-12-19 Thread Simon Glass
Check that this flag operates as expected. This patch is not earlier in
this series since is uses the new behaviour of dev_seq().

Signed-off-by: Simon Glass 

---

Changes in v3:
- Add new patch to test DM_UC_FLAG_NO_AUTO_SEQ

 arch/sandbox/dts/test.dts | 13 
 include/dm/uclass-id.h|  1 +
 test/dm/test-fdt.c| 42 +++
 3 files changed, 56 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 20/28] pinctrl: Update for new sequence numbers

2020-12-19 Thread Simon Glass
Use the dev_seq() sequence number in all cases.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/pinctrl/exynos/pinctrl-exynos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 19/28] gpio: Update for new sequence numbers

2020-12-19 Thread Simon Glass
Use the dev_seq() sequence number in all cases.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/gpio/imx_rgpio2p.c | 2 +-
 drivers/gpio/iproc_gpio.c  | 2 +-
 drivers/gpio/mvebu_gpio.c  | 2 +-
 drivers/gpio/mxc_gpio.c| 2 +-
 drivers/gpio/vybrid_gpio.c | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 18/28] x86: Simplify acpi_device_infer_name()

2020-12-19 Thread Simon Glass
There is no-longer any need to check if sequence numbers are valid, since
this is ensured by driver model. Drop the unwanted logic.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 lib/acpi/acpi_device.c | 27 +++
 test/dm/acpi.c |  6 +-
 2 files changed, 4 insertions(+), 29 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 15/28] usb: ehci-mx6: Drop assignment of sequence number

2020-12-19 Thread Simon Glass
This hack cannot work in the new sequence-numbering scheme. Remove it
while we wait for the maintainer to complete DM conversion as noted in
the existing comment.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/usb/host/ehci-mx6.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 16/28] usb: Update for new sequence numbers

2020-12-19 Thread Simon Glass
Use the new sequence number in all cases. Since all devices are assigned
a number when bound, this hack should not be needed.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/usb/host/ehci-vf.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 10/28] i2c: Update for new sequence numbers

2020-12-19 Thread Simon Glass
Use the new sequence number in all cases. Drop the logic to check for a
valid number in designware_i2c, since it will always be valid.

Also drop the numbering in the uclass, since we can rely on driver
model giving us the right sequence numbers.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Drop special numbering in the i2c uclass

 drivers/i2c/designware_i2c_pci.c   | 22 +
 drivers/i2c/i2c-uclass.c   | 39 +-
 drivers/i2c/i2c-versatile.c|  5 
 drivers/i2c/intel_i2c.c| 12 +
 drivers/i2c/muxes/i2c-mux-uclass.c |  4 +--
 drivers/i2c/mvtwsi.c   |  6 ++---
 6 files changed, 8 insertions(+), 80 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 12/28] dm: core: Allow manual sequence numbering

2020-12-19 Thread Simon Glass
Some buses have their own rules which require assigning sequence numbers
with a bus-specific algorithm. For example, PCI requires that sub-buses
are numbered higher than their parent buses, meaning effectively that
parent buses must be numbered only after all of their child buses have
been numbered.

Add a uclass flag to indicate that driver model should not assign sequence
numbers. In this case, the uclass must do it.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Add new patch to allow manual sequence numbering

 drivers/core/device.c | 2 +-
 include/dm/uclass.h   | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 13/28] pci: Update to use new sequence numbers

2020-12-19 Thread Simon Glass
Now that we know the sequence number at bind time, there is no need for
special-case code in dm_pci_hose_probe_bus().

Note: the PCI_CAP_ID_EA code may need a look, but there are no test
failures so I have left it as is.

Signed-off-by: Simon Glass 
---

Changes in v3:
- Update PCI to use manual sequence numbering

Changes in v2:
- Use the sequence number directly instead of max bus

 drivers/pci/pci-uclass.c | 45 
 drivers/pci/pci_auto.c   | 10 -
 2 files changed, 32 insertions(+), 23 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 11/28] net: Update to use new sequence numbers

2020-12-19 Thread Simon Glass
Checking for seq == -1 is effectively checking that the device is
activated. The new sequence numbers are never -1 for a bound device, so
update the check.

Also drop the note about valid sequence numbers so it is accurate with the
new approach.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/net/dwc_eth_qos.c | 2 +-
 net/eth-uclass.c  | 7 ++-
 2 files changed, 3 insertions(+), 6 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 09/28] octeon: Don't attempt to set the sequence number

2020-12-19 Thread Simon Glass
Several Octeon drivers operate by setting the sequence number of their
device. This should not be needed with the new sequence number setup. Also
it is not permitted. Drop it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/i2c/octeon_i2c.c | 1 -
 drivers/mmc/octeontx_hsmmc.c | 2 --
 drivers/net/octeontx/smi.c   | 1 -
 3 files changed, 4 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 08/28] dm: test: Drop assumptions of no sequence numbers

2020-12-19 Thread Simon Glass
Drop code in a few tests which assumes that sequence numbers are only
valid when a device is probed.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 test/dm/blk.c | 3 ---
 test/dm/i2c.c | 3 ---
 test/dm/spi.c | 3 ---
 3 files changed, 9 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 07/28] dm: Fix return value in dev_read_alias_seq()

2020-12-19 Thread Simon Glass
This should return 0 on success but currently does not. Fix it.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/core/read.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 04/28] dm: core: Add a new sequence number for devices

2020-12-19 Thread Simon Glass
At present each device has two sequence numbers, with 'req_seq' being
set up at bind time and 'seq' at probe time. The idea is that devices
can 'request' a sequence number and then the conflicts are resolved when
the device is probed.

This makes things complicated in a few cases, since we don't really know
what the sequence number will end up being. We want to honour the
bind-time requests if at all possible, but in fact the only source of
these at present is the devicetree aliases. Since we have the devicetree
available at bind time, we may as well just use it, in the hope that the
required processing will turn out to be useful later (i.e. the device
actually gets used).

Add a new 'sqq' member, the bind-time sequence number. It operates in
parallel to the old values for now. All devices get a valid sqq value,
i.e. it is never -1.

Drop an #ifdef while we are here.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Give all devices a sequence number
- Drop uclass_alloc_all_seqs() and GD_FLG_DM_NO_SEQ flag

 drivers/core/device.c | 22 --
 drivers/core/root.c   |  8 +---
 include/dm/device.h   |  8 
 3 files changed, 29 insertions(+), 9 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 03/28] dm: core: Update uclass_find_next_free_req_seq() args

2020-12-19 Thread Simon Glass
At present this is passed a uclass ID and it has to do a lookup. The
callers all have the uclass pointer, except for the I2C uclass where the
code will soon be deleted.

Update the argument to a uclass * instead of an ID since it is more
efficient.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/core/device.c| 4 ++--
 drivers/core/uclass.c| 8 +---
 drivers/i2c/designware_i2c_pci.c | 8 +++-
 include/dm/uclass-internal.h | 4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 05/28] dm: test: Check all devices have a sequence numbers

2020-12-19 Thread Simon Glass
Add a test that the new sequence numbers work as expected. Every device
should get one.

Signed-off-by: Simon Glass 
---

(no changes since v2)

Changes in v2:
- Drop the GD_FLG_DM_NO_SEQ flag

 test/dm/core.c | 19 +++
 1 file changed, 19 insertions(+)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 24/28] dm: Drop the unused arg in uclass_find_device_by_seq()

2020-12-19 Thread Simon Glass
Now that there is only one sequence number (rather than both requested and
assigned ones) we can simplify this function. Also update its caller to
simplify the logic.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/mach-k3/am6_init.c |  2 +-
 arch/arm/mach-k3/j721e_init.c   |  2 +-
 arch/arm/mach-k3/sysfw-loader.c |  2 +-
 drivers/core/device.c   | 16 --
 drivers/core/uclass.c   | 22 +-
 drivers/spi/spi-uclass.c|  4 +--
 drivers/usb/host/usb-uclass.c   |  4 +--
 include/dm/device.h | 18 
 include/dm/uclass-internal.h| 18 
 net/eth-uclass.c|  2 +-
 test/dm/bus.c   | 16 +-
 test/dm/test-fdt.c  | 52 -
 12 files changed, 64 insertions(+), 94 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 02/28] dm: Avoid accessing seq directly

2020-12-19 Thread Simon Glass
At present various drivers etc. access the device's 'seq' member directly.
This makes it harder to change the meaning of that member. Change access
to go through a function instead.

The drivers/i2c/lpc32xx_i2c.c file is left unchanged for now.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/arm/include/asm/mach-imx/mxc_i2c.h  |  2 +-
 arch/x86/cpu/broadwell/cpu_full.c|  2 +-
 arch/x86/cpu/ivybridge/model_206ax.c |  2 +-
 board/xilinx/versal/board.c  | 12 
 board/xilinx/zynqmp/zynqmp.c | 12 
 cmd/axi.c|  4 +--
 cmd/cpu.c|  2 +-
 cmd/i2c.c|  4 +--
 cmd/misc.c   |  2 +-
 cmd/osd.c|  4 +--
 cmd/pci.c|  7 +++--
 cmd/pmic.c   |  4 +--
 cmd/remoteproc.c |  2 +-
 cmd/w1.c |  4 +--
 drivers/core/device.c|  2 +-
 drivers/core/dump.c  |  4 +--
 drivers/core/uclass.c|  6 ++--
 drivers/gpio/octeon_gpio.c   |  2 +-
 drivers/i2c/ast_i2c.c|  4 +--
 drivers/i2c/davinci_i2c.c|  2 +-
 drivers/i2c/exynos_hs_i2c.c  |  2 +-
 drivers/i2c/i2c-gpio.c   |  2 +-
 drivers/i2c/imx_lpi2c.c  | 12 
 drivers/i2c/lpc32xx_i2c.c|  6 +++-
 drivers/i2c/mxc_i2c.c| 10 +++
 drivers/i2c/nx_i2c.c |  2 +-
 drivers/i2c/octeon_i2c.c |  2 +-
 drivers/i2c/s3c24x0_i2c.c|  2 +-
 drivers/i2c/tegra_i2c.c  |  5 ++--
 drivers/mmc/fsl_esdhc_imx.c  |  4 +--
 drivers/mtd/spi/sandbox.c|  4 +--
 drivers/net/fec_mxc.c|  7 +++--
 drivers/net/fsl-mc/mc.c  |  2 +-
 drivers/net/fsl_mcdmafec.c   |  2 +-
 drivers/net/ftgmac100.c  |  2 +-
 drivers/net/higmacv300.c |  2 +-
 drivers/net/mcffec.c |  2 +-
 drivers/net/octeontx/nicvf_main.c|  9 +++---
 drivers/net/octeontx/smi.c   |  2 +-
 drivers/net/octeontx2/nix.c  |  2 +-
 drivers/net/octeontx2/rvu_pf.c   |  6 ++--
 drivers/net/xilinx_axi_emac.c|  2 +-
 drivers/net/xilinx_emaclite.c|  2 +-
 drivers/net/zynq_gem.c   |  2 +-
 drivers/pci/pci-aardvark.c   |  2 +-
 drivers/pci/pci-uclass.c | 36 
 drivers/pci/pci_auto.c   |  6 ++--
 drivers/pci/pcie_dw_mvebu.c  |  6 ++--
 drivers/pci/pcie_dw_ti.c |  6 ++--
 drivers/pci/pcie_ecam_generic.c  |  2 +-
 drivers/pci/pcie_fsl.c   | 16 +--
 drivers/pci/pcie_intel_fpga.c|  2 +-
 drivers/pci/pcie_layerscape_fixup.c  |  4 +--
 drivers/pci/pcie_layerscape_gen4.c   | 10 +++
 drivers/pci/pcie_layerscape_gen4_fixup.c |  2 +-
 drivers/pci/pcie_layerscape_rc.c | 12 
 drivers/pci/pcie_mediatek.c  |  2 +-
 drivers/pci/pcie_rockchip.c  |  6 ++--
 drivers/serial/serial_mcf.c  |  2 +-
 drivers/serial/serial_s5p.c  |  2 +-
 drivers/spi/altera_spi.c |  2 +-
 drivers/spi/cf_spi.c | 12 
 drivers/spi/fsl_dspi.c   |  6 ++--
 drivers/spi/fsl_espi.c   |  2 +-
 drivers/spi/octeon_spi.c |  2 +-
 drivers/spi/pic32_spi.c  |  4 +--
 drivers/spi/sandbox_spi.c|  2 +-
 drivers/spi/tegra114_spi.c   |  2 +-
 drivers/spi/tegra20_sflash.c |  2 +-
 drivers/spi/tegra20_slink.c  |  2 +-
 drivers/spi/tegra210_qspi.c  |  2 +-
 drivers/spi/xilinx_spi.c |  2 +-
 drivers/spi/zynq_qspi.c  |  2 +-
 drivers/spi/zynq_spi.c   |  2 +-
 drivers/usb/gadget/max3420_udc.c |  2 +-
 drivers/usb/host/ehci-mx5.c  |  2 +-
 drivers/usb/host/ehci-mx6.c  |  2 +-
 drivers/usb/host/ehci-omap.c |  2 +-
 drivers/usb/host/ehci-vf.c   |  2 +-
 drivers/usb/host/usb-sandbox.c   |  2 +-
 drivers/usb/host/usb-uclass.c|  2 +-
 drivers/video/vidconsole-uclass.c|  4 +--
 drivers/virtio/virtio-uclass.c   |  2 +-
 drivers/watchdog/ast_wdt.c   |  2 +-
 drivers/watchdog/at91sam9_wdt.c  |  2 +-
 drivers/watchdog/cdns_wdt.c  |  2 +-
 drivers/watchdog/omap_wdt.c  |  2 +-
 drivers/watchdog/orion_wdt.c |  2 +-
 drivers/watchdog/sbsa_gwdt.c |  2 +-
 drivers/watchdog/sp805_wdt.c |  2 +-
 drivers/watchdog/tangier_wdt.c   |  2 +-
 drivers/watchdog/xilinx_tb_wdt.c   

Re: [PATCH v3 01/28] linker_lists: Fix alignment issue

2020-12-19 Thread Simon Glass
The linker script uses alphabetic sorting to group the different linker
lists together. Each group has its own struct and potentially its own
alignment. But when the linker packs the structs together it cannot ensure
that a linker list starts on the expected alignment boundary.

For example, if the first list has a struct size of 8 and we place 3 of
them in the image, that means that the next struct will start at offset
0x18 from the start of the linker_list section. If the next struct has
a size of 16 then it will start at an 8-byte aligned offset, but not a
16-byte aligned offset.

With sandbox on x86_64, a reference to a linker list item using
ll_entry_get() can force alignment of that particular linker_list item,
if it is in the same file as the linker_list item is declared.

Consider this example, where struct driver is 0x80 bytes:

ll_entry_declare(struct driver, fred, driver)

...

void *p = ll_entry_get(struct driver, fred, driver)

If these two lines of code are in the same file, then the entry is forced
to be aligned at the 'struct driver' alignment, which is 16 bytes. If the
second line of code is in a different file, then no action is taken, since
the compiler cannot update the alignment of the linker_list item.

In the first case, an 8-byte 'fill' region is added:

 .u_boot_list_2_driver_2_testbus_drv
0x00270018   0x80 test/built-in.o
0x00270018
_u_boot_list_2_driver_2_testbus_drv
 .u_boot_list_2_driver_2_testfdt1_drv
0x00270098   0x80 test/built-in.o
0x00270098
_u_boot_list_2_driver_2_testfdt1_drv
 *fill* 0x002701180x8
 .u_boot_list_2_driver_2_testfdt_drv
0x00270120   0x80 test/built-in.o
0x00270120
_u_boot_list_2_driver_2_testfdt_drv
 .u_boot_list_2_driver_2_testprobe_drv
0x002701a0   0x80 test/built-in.o
0x002701a0
_u_boot_list_2_driver_2_testprobe_drv

With this, the linker_list no-longer works since items after testfdt1_drv
are not at the expected address.

Ideally we would have a way to tell gcc not to align structs in this way.
It is not clear how we could do this, and in any case it would require us
to adjust every struct used by the linker_list feature.

One possible fix is to force each separate linker_list to start on the
largest possible boundary that can be required by the compiler. However
that does not seem to work on x86_64, which uses 16-byte alignment in this
case but needs 32-byte alignment.

So add a Kconfig option to handle this. Set the default value to 4 so
as to avoid changing platforms that don't need it.

Update the ll_entry_start() accordingly.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/Kconfig | 11 
 doc/api/linker_lists.rst | 59 
 include/linker_lists.h   |  3 +-
 3 files changed, 72 insertions(+), 1 deletion(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 17/28] x86: Drop unnecessary mp_init logic

2020-12-19 Thread Simon Glass
Now that sequence numbers are set up when devices are bound, this code is
not needed. Also, we should use dev_seq() instead of req_seq. Update the
whole file accordingly.

Also fix up APL cpu while we are here.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 arch/x86/cpu/apollolake/cpu.c |  2 +-
 arch/x86/cpu/mp_init.c| 23 +++
 arch/x86/include/asm/mp.h |  2 +-
 3 files changed, 9 insertions(+), 18 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 14/28] spi: Update for new sequence numbers

2020-12-19 Thread Simon Glass
Use the new sequence number in all cases. Drop the rockchip case because
the sequence number should be 0 anyway, and assigning to the sequence
number is not permitted.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/spi/fsl_dspi.c | 2 +-
 drivers/spi/rk_spi.c   | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

Applied to u-boot-dm/next, thanks!


Re: [PATCH v3 06/28] dm: core: Switch binding to use new sequence numbers

2020-12-19 Thread Simon Glass
Update the core logic to use the new approach. For now the old code is
left as is. Update one test so it still passes.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 drivers/core/device.c | 5 +
 test/dm/bus.c | 3 ++-
 2 files changed, 3 insertions(+), 5 deletions(-)

Applied to u-boot-dm/next, thanks!


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

2020-12-19 Thread Simon Glass
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/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 000..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 
+ */
+
+#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 a05c56458b0..19368ba2560 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
  *
-- 
2.29.2.684.gfbc64c5ab5-goog



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

2020-12-19 Thread Simon Glass
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 000..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 
+ */
+
+#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 
 #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)
 {
-- 
2.29.2.684.gfbc64c5ab5-goog



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

2020-12-19 Thread Simon Glass
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 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 = <4000>;
@@ -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



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

2020-12-19 Thread Simon Glass
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 
 .../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 
 #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 e033baf1205..e23d38ea072 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 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 
+
+/**
+ * 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 000..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 000..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 
 #include 
 
-/**
- * struct apl_gpio_plat - platform data for each d

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

2020-12-19 Thread Simon Glass
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 3ae6707593e..6b9701a06ae 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,
 };
-- 
2.29.2.684.gfbc64c5ab5-goog



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

2020-12-19 Thread Simon Glass
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 6515d1f471f..ae4de4ca8c6 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 cb901f265e2..d73ae438bbb 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_E00xe0
 #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_OFFSET0x60
 #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 
+
 #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 000..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



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

2020-12-19 Thread Simon Glass
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 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



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

2020-12-19 Thread Simon Glass
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 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



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

2020-12-19 Thread Simon Glass
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 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



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

2020-12-19 Thread Simon Glass
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 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



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

2020-12-19 Thread Simon Glass
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 7dbcbecd948..b0c2c209587 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 000..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



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

2020-12-19 Thread Simon Glass
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 
---

 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 000..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 
+
+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 
 #include 
 #include 
-
-struct x86_sysreset_plat {
-   struct udevice *pch;
-};
+#include 
 
 /*
  * Power down the machine by using the power management sleep control
-- 
2.29.2.684.gfbc64c5ab5-goog



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

2020-12-19 Thread Simon Glass
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 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 = <0x0800 0 0 0 0>;
compatible = "intel,apl-punit";
};
 
gma@2,0 {
+   u-boot,dm-pre-proper;
reg = <0x1000 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



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

2020-12-19 Thread Simon Glass
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 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



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

2020-12-19 Thread Simon Glass
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 69e5899235b..876fa592b8d 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(s...@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 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 
+
+/**
+ * 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 a

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

2020-12-19 Thread Simon Glass
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 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



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

2020-12-19 Thread Simon Glass
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 
---

 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 

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

2020-12-19 Thread Simon Glass
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 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



[PATCH 21/26] dm: core: Use dev_has_ofnode() instead of dev_of_valid()

2020-12-19 Thread Simon Glass
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 
---

 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 ac954a34d27..5cfd00ce771 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 8c7ce220f84..bd4ecc9e24d 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 489271b560e..f8fa4baa2c3 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 18eef625f0f..ec0cdf62207 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 456cf3b85fb..be56785217c 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 fc09ad99e5e..c71c495d581 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 1f6c51f1e8d..4cdd06b1257 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 =
  

[PATCH 20/26] dm: core: Rename dev_has_of_node() to dev_has_ofnode()

2020-12-19 Thread Simon Glass
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 ba50d46effe..8c7ce220f84 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 57d107aac32..f3da6af9090 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 4e474cbff73..4653e86ba46 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 17db5eb0609..ae6b1450d3a 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 a0c1752cddc..b15a14ec330 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);
 }
-- 
2.29.2.684.gfbc64c5ab5-goog



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

2020-12-19 Thread Simon Glass
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 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_FL

[PATCH 23/26] dm: core: Rename device node to indicate it is private

2020-12-19 Thread Simon Glass
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 1b274206ea3..4469804a00e 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
 }
 
-- 
2.29.2.684.gfbc64c5ab5-goog