Skip to contentSkip to conversation

dm: tegra: Move nyan-big, jetson-tk1, beaver to livetree

PATCH Superseded Simon Glass 2 participants 27 messages Jul 12, 2017 – Jul 25, 2017

Subsystems (13)

v4 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v4 cover dm: tegra: Move nyan-big, jetson-tk1, beaver to livetree

This moves four entire boards to use a live device tree as an example of the impact.

Nyan-big was chosen because I can easily and boot U-Boot without any media swapping, etc. Beaver is enabled as well since it failed to boot with serial v1 due to a disabled console node. Jetson-TK1 is chosen because I found some USB problems in the v2 patches. Jetson-TX1 is added because Stephen Warren found some problems with PCI.

Total code size impact on this board is approximately 9KB on U-Boot and 64 bytes on SPL:

27: dm: tegra: nyan-big: Move to livetree

       arm: (for 1/1 boards) all +9264.0 bss -16.0 data +44.0 rodata +92.0
          spl/u-boot-spl:all +326.0 spl/u-boot-spl:rodata +262.0
          spl/u-boot-spl:text +64.0 text +9144.0

Tegra does not use Thumb2, which would likely reduce the code size by about 25%, indicating a code-size impact of perhaps 7KB.

Boot time is affected slightly. For nyan-big the times with flat tree are:

                 2,108  dm_r
                 7,924  dm_spl
               120,724  dm_f
               171,816  lcd

With the livetree:

                   721  dm_r
                 3,764  of_live
                 7,990  dm_spl
               120,736  dm_f
               168,215  lcd

As expected the spl and pre-relocation times are not affected. In the post-relocation case, the live tree must be built, which here takes about 3.8ms. Driver-model device creation takes a bit of 1ms less time with the livetree, so all up the cost is about 2.4ms. After DM init there appears to be a slight reduction in the time taken to set up devices (from 327ms to 319ms) so overall the live tree does not appear to be any slower. This is because pre-parsing the device tree makes reading it later faster.

The use of livetree is controlled by a the CONFIG_OF_LIVE option. When enabled, U-Boot builds a livetree immediately after relocation and uses it from then on.

This series is available at u-boot-dm/livet-working

Changes in v4:
- Add new patch to add ofnode_read_resource()
- Add new patch to fix up ofnode_get_addr_index() for 64-bit values
- Update to use ofnode_read_resource()
- Drop fdtdec.h header
- Update to deal with rename of ofnode_read_prop()
- Rebase to master
- Drop changes already applied
- Fix PCI and i2c init problems on jetson-tx1

Changes in v3:
- Update commit message, enable for all tegra124 boards not just nyan-big
- Add new patch to convert tegra PCI to device tree
- Enable livetree for jetson-tk1 also

Changes in v2:
- Enable livetree for beaver also
- Add timing information

Simon Glass (20):
dm: core: Add ofnode_read_resource()
dm: core: Fix up ofnode_get_addr_index() for 64-bit values
tegra: spl: Enable debug UART
tegra: tegra124: Add a PMC syscon driver
dm: tegra: Convert USB setup to livetree
dm: tegra: Convert clock_decode_periph_id() to support livetree
dm: video: tegra124: Convert to livetree
tegra: dts: Move stdout-path to /chosen
dm: tegra: gpio: Convert to support livetree
dm: tegra: usb: Convert to livetree
dm: tegra: spi: Convert to livetree
dm: tegra: i2c: Convert to livetree
dm: tegra: pwm: Convert to livetree
dm: tegra: mmc: Convert to livetree
dm: tegra: pci: Convert to livetree
power: Add a regulator driver for the as3722 PMIC
power: Add a GPIO driver for the as3722 PMIC
dm: power: Convert as3722 to driver model
fdtdec: Drop old compatible values
dm: tegra: Move nyan-big, jetson-tk1/tx1, beaver to livetree

 arch/arm/dts/tegra124-nyan-big.dts            |   5 +-
 arch/arm/include/asm/arch-tegra/clock.h       |   2 +-
 arch/arm/include/asm/arch-tegra/tegra.h       |   5 +
 arch/arm/include/asm/arch-tegra/xusb-padctl.h |   2 +-
 arch/arm/mach-tegra/Kconfig                   |   2 +
 arch/arm/mach-tegra/board2.c                  |   8 +-
 arch/arm/mach-tegra/clock.c                   |   5 +-
 arch/arm/mach-tegra/spl.c                     |   4 +
 arch/arm/mach-tegra/tegra124/Makefile         |   1 +
 arch/arm/mach-tegra/tegra124/pmc.c            |  19 ++
 arch/arm/mach-tegra/tegra124/xusb-padctl.c    |  36 +++-
 arch/arm/mach-tegra/tegra210/xusb-padctl.c    |  42 +++-
 arch/arm/mach-tegra/xusb-padctl-common.c      |  60 +++---
 arch/arm/mach-tegra/xusb-padctl-common.h      |   8 +-
 arch/arm/mach-tegra/xusb-padctl-dummy.c       |   2 +-
 board/cei/cei-tk1-som/cei-tk1-som.c           |   2 +
 board/nvidia/jetson-tk1/jetson-tk1.c          |   2 +
 board/nvidia/nyan-big/nyan-big.c              |  22 +-
 board/toradex/apalis-tk1/apalis-tk1.c         |   6 +
 configs/apalis-tk1_defconfig                  |   3 +
 configs/beaver_defconfig                      |   1 +
 configs/cei-tk1-som_defconfig                 |   3 +
 configs/jetson-tk1_defconfig                  |   4 +
 configs/nyan-big_defconfig                    |   2 +
 configs/p2371-2180_defconfig                  |   1 +
 drivers/core/ofnode.c                         |  30 ++-
 drivers/core/read.c                           |   5 +
 drivers/core/read_extra.c                     |  25 +--
 drivers/gpio/tegra_gpio.c                     |  10 +-
 drivers/i2c/tegra_i2c.c                       |   7 +-
 drivers/mmc/tegra_mmc.c                       |  17 +-
 drivers/pci/pci_tegra.c                       |  53 +++--
 drivers/power/pmic/Makefile                   |   2 +-
 drivers/power/pmic/as3722.c                   | 292 +++++++++-----------------
 drivers/power/pmic/as3722_gpio.c              | 120 +++++++++++
 drivers/power/regulator/Kconfig               |   9 +
 drivers/power/regulator/Makefile              |   1 +
 drivers/power/regulator/as3722_regulator.c    | 149 +++++++++++++
 drivers/pwm/tegra_pwm.c                       |   2 +-
 drivers/spi/tegra114_spi.c                    |  15 +-
 drivers/spi/tegra20_sflash.c                  |   2 +-
 drivers/spi/tegra20_slink.c                   |   2 +-
 drivers/spi/tegra210_qspi.c                   |   2 +-
 drivers/usb/host/ehci-tegra.c                 |  36 ++--
 drivers/video/tegra124/display.c              |   8 +-
 drivers/video/tegra124/dp.c                   |   3 +-
 drivers/video/tegra124/sor.c                  |  25 +--
 include/dm/ofnode.h                           |   4 +
 include/dm/read.h                             |  26 ++-
 include/fdtdec.h                              |   6 -
 include/power/as3722.h                        |  27 ++-
 lib/fdtdec.c                                  |   6 -
 52 files changed, 698 insertions(+), 433 deletions(-)
 create mode 100644 arch/arm/mach-tegra/tegra124/pmc.c
 create mode 100644 drivers/power/pmic/as3722_gpio.c
 create mode 100644 drivers/power/regulator/as3722_regulator.c
Signature · 1 line
2.13.2.932.g7449e964c-goog
#1 lore raw

PATCH v4 1/20 dm: core: Add ofnode_read_resource()

We sometimes need to read a resource from an arbitrary node. In any case for consistency we should not put the live-tree switching code in a dev_read_...() function. Update this to suit.

---

Changes in v4:
- Add new patch to add ofnode_read_resource()

Changes in v3: None
Changes in v2: None

 drivers/core/ofnode.c     | 21 +++++++++++++++++++++
 drivers/core/read.c       |  5 +++++
 drivers/core/read_extra.c | 25 +------------------------
 include/dm/ofnode.h       |  4 ++++
 include/dm/read.h         | 26 ++++++++++++++++----------
 5 files changed, 47 insertions(+), 34 deletions(-)
drivers/core/ofnode.c +21 -0
index fd068b06ef..e4b2a85f19 100644
@@ -14,6 +14,7 @@
 #include <dm/of_addr.h>
 #include <dm/ofnode.h>
 #include <linux/err.h>
+#include <linux/ioport.h>
 
 int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
 {
@@ -593,3 +594,23 @@ bool ofnode_pre_reloc(ofnode node)
 
 	return false;
 }
+
+int ofnode_read_resource(ofnode node, uint index, struct resource *res)
+{
+	if (ofnode_is_np(node)) {
+		return of_address_to_resource(ofnode_to_np(node), index, res);
+	} else {
+		struct fdt_resource fres;
+		int ret;
+
+		ret = fdt_get_resource(gd->fdt_blob, ofnode_to_offset(node),
+				       "reg", index, &fres);
+		if (ret < 0)
+			return -EINVAL;
+		memset(res, '\0', sizeof(*res));
+		res->start = fres.start;
+		res->end = fres.end;
+
+		return 0;
+	}
+}
drivers/core/read.c +5 -0
index eafe727f03..f6562073ed 100644
@@ -159,3 +159,8 @@ int dev_read_enabled(struct udevice *dev)
 		return fdtdec_get_is_enabled(gd->fdt_blob,
 					     ofnode_to_offset(node));
 }
+
+int dev_read_resource(struct udevice *dev, uint index, struct resource *res)
+{
+	return ofnode_read_resource(dev_ofnode(dev), index, res);
+}
drivers/core/read_extra.c +1 -24
index a6d2f342d9..e94648f1b5 100644
@@ -11,27 +11,4 @@
 #include <dm/read.h>
 #include <linux/ioport.h>
 
-int dev_read_resource(struct udevice *dev, uint index, struct resource *res)
-{
-	ofnode node = dev_ofnode(dev);
-
-#ifdef CONFIG_OF_LIVE
-	if (ofnode_is_np(node)) {
-		return of_address_to_resource(ofnode_to_np(node), index, res);
-	} else
-#endif
-		{
-		struct fdt_resource fres;
-		int ret;
-
-		ret = fdt_get_resource(gd->fdt_blob, ofnode_to_offset(node),
-				       "reg", index, &fres);
-		if (ret < 0)
-			return -EINVAL;
-		memset(res, '\0', sizeof(*res));
-		res->start = fres.start;
-		res->end = fres.end;
-
-		return 0;
-	}
-}
+/* This file can hold non-inlined dev_read_...() functions */
include/dm/ofnode.h +4 -0
index 15ad5199c2..966ca9309a 100644
@@ -15,6 +15,8 @@
 /* Enable checks to protect against invalid calls */
 #undef OF_CHECKS
 
+struct resource;
+
 /**
  * ofnode - reference to a device tree node
  *
@@ -605,4 +607,6 @@ int ofnode_read_simple_size_cells(ofnode node);
  */
 bool ofnode_pre_reloc(ofnode node);
 
+int ofnode_read_resource(ofnode node, uint index, struct resource *res);
+
 #endif
include/dm/read.h +16 -10
index b86a2f5fec..b2b8fc6d05 100644
@@ -44,16 +44,6 @@ static inline bool dev_of_valid(struct udevice *dev)
 	return ofnode_valid(dev_ofnode(dev));
 }
 
-/**
- * dev_read_resource() - obtain an indexed resource from a device.
- *
- * @dev: devuce to examine
- * @index index of the resource to retrieve (0 = first)
- * @res returns the resource
- * @return 0 if ok, negative on error
- */
-int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
-
 #ifndef CONFIG_DM_DEV_READ_INLINE
 /**
  * dev_read_u32_default() - read a 32-bit integer from a device's DT property
@@ -348,6 +338,16 @@ const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
  */
 int dev_read_enabled(struct udevice *dev);
 
+/**
+ * dev_read_resource() - obtain an indexed resource from a device.
+ *
+ * @dev: devuce to examine
+ * @index index of the resource to retrieve (0 = first)
+ * @res returns the resource
+ * @return 0 if ok, negative on error
+ */
+int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
+
 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
 
 static inline int dev_read_u32_default(struct udevice *dev,
@@ -482,6 +482,12 @@ static inline int dev_read_enabled(struct udevice *dev)
 	return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
 }
 
+static inline int dev_read_resource(struct udevice *dev, uint index,
+				    struct resource *res)
+{
+	return ofnode_read_resource(dev_ofnode(dev), index, res);
+}
+
 #endif /* CONFIG_DM_DEV_READ_INLINE */
 
 /**
Signature · 1 line
2.13.2.932.g7449e964c-goog
#2 lore raw

PATCH v4 2/20 dm: core: Fix up ofnode_get_addr_index() for 64-bit values

In reply to Simon Glass

At present this function only supports 32-bit (single-cell) values. Update it to support two-cell values also.

---

Changes in v4:
- Add new patch to fix up ofnode_get_addr_index() for 64-bit values

Changes in v3: None
Changes in v2: None

 drivers/core/ofnode.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/core/ofnode.c +5 -4
index e4b2a85f19..c3fb0ae7b9 100644
@@ -199,13 +199,14 @@ fdt_addr_t ofnode_get_addr_index(ofnode node, int index)
 		const __be32 *prop_val;
 		uint flags;
 		u64 size;
+		int na;
 
-		prop_val = of_get_address(
-			(struct device_node *)ofnode_to_np(node), index,
-			&size, &flags);
+		prop_val = of_get_address(ofnode_to_np(node), index, &size,
+					  &flags);
 		if (!prop_val)
 			return FDT_ADDR_T_NONE;
-		return  be32_to_cpup(prop_val);
+		na = of_n_addr_cells(ofnode_to_np(node));
+		return of_read_number(prop_val, na);
 	} else {
 		return fdt_get_base_address(gd->fdt_blob,
 					    ofnode_to_offset(node));
Signature · 1 line
2.13.2.932.g7449e964c-goog
#3 lore raw

PATCH v4 3/20 tegra: spl: Enable debug UART

In reply to Simon Glass

Enable the debug UART in SPL to allow early serial output even if the standard UART does not work (e.g. due to driver model problem).

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/mach-tegra/spl.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/mach-tegra/spl.c +4 -0
index 41c88cb2b4..189b3da026 100644
@@ -7,6 +7,7 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
+#include <debug_uart.h>
 #include <spl.h>
 
 #include <asm/io.h>
@@ -32,6 +33,9 @@ void spl_board_init(void)
 	gpio_early_init_uart();
 
 	clock_early_init();
+#ifdef CONFIG_DEBUG_UART
+	debug_uart_init();
+#endif
 	preloader_console_init();
 }
 
Signature · 1 line
2.13.2.932.g7449e964c-goog
#4 lore raw

PATCH v4 4/20 tegra: tegra124: Add a PMC syscon driver

In reply to Simon Glass

The PMC can be modelled as a syscon peripheral. Add a driver for this so that it can be accessed by drivers when needed. Enable it for tegra124 boards.

---

Changes in v4: None
Changes in v3:
- Update commit message, enable for all tegra124 boards not just nyan-big

Changes in v2: None

 arch/arm/include/asm/arch-tegra/tegra.h |  5 +++++
 arch/arm/mach-tegra/Kconfig             |  2 ++
 arch/arm/mach-tegra/tegra124/Makefile   |  1 +
 arch/arm/mach-tegra/tegra124/pmc.c      | 19 +++++++++++++++++++
 4 files changed, 27 insertions(+)
 create mode 100644 arch/arm/mach-tegra/tegra124/pmc.c
arch/arm/include/asm/arch-tegra/tegra.h +5 -0
index 3add1b3c09..3b9711d28e 100644
@@ -97,6 +97,11 @@ enum {
 	TEGRA_SOC_UNKNOWN	= -1,
 };
 
+/* Tegra system controller (SYSCON) devices */
+enum {
+	TEGRA_SYSCON_PMC,
+};
+
 #else  /* __ASSEMBLY__ */
 #define PRM_RSTCTRL		NV_PA_PMC_BASE
 #endif
arch/arm/mach-tegra/Kconfig +2 -0
index 89d2a499e4..51e50907d2 100644
@@ -85,6 +85,8 @@ config TEGRA114
 config TEGRA124
 	bool "Tegra124 family"
 	select TEGRA_ARMV7_COMMON
+	imply REGMAP
+	imply SYSCON
 
 config TEGRA210
 	bool "Tegra210 family"
arch/arm/mach-tegra/tegra124/Makefile +1 -0
index c00de6151e..d275dafdc4 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_SPL_BUILD) += cpu.o
 obj-y	+= clock.o
 obj-y	+= funcmux.o
 obj-y	+= pinmux.o
+obj-y	+= pmc.o
 obj-y	+= xusb-padctl.o
 obj-y	+= ../xusb-padctl-common.o
 
arch/arm/mach-tegra/tegra124/pmc.c new file +19 -0
new file mode 100644
index 0000000000..be82acf11e
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2017 Google, Inc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <syscon.h>
+
+static const struct udevice_id tegra124_syscon_ids[] = {
+	{ .compatible = "nvidia,tegra124-pmc", .data = TEGRA_SYSCON_PMC },
+};
+
+U_BOOT_DRIVER(syscon_tegra124) = {
+	.name = "tegra124_syscon",
+	.id = UCLASS_SYSCON,
+	.of_match = tegra124_syscon_ids,
+};
Signature · 1 line
2.13.2.932.g7449e964c-goog
#5 lore raw

PATCH v4 5/20 dm: tegra: Convert USB setup to livetree

In reply to Simon Glass

Adjust this code to support a live device tree. This should be implemented as a PHY driver but that is left as an exercise for the maintainer.

---

Changes in v4:
- Update to use ofnode_read_resource()

Changes in v3: None
Changes in v2: None

 arch/arm/include/asm/arch-tegra/xusb-padctl.h |  2 +-
 arch/arm/mach-tegra/board2.c                  |  2 +-
 arch/arm/mach-tegra/tegra124/xusb-padctl.c    | 36 ++++++++++++----
 arch/arm/mach-tegra/tegra210/xusb-padctl.c    | 42 ++++++++++++++-----
 arch/arm/mach-tegra/xusb-padctl-common.c      | 60 ++++++++++++++++-----------
 arch/arm/mach-tegra/xusb-padctl-common.h      |  8 ++--
 arch/arm/mach-tegra/xusb-padctl-dummy.c       |  2 +-
 7 files changed, 103 insertions(+), 49 deletions(-)
arch/arm/include/asm/arch-tegra/xusb-padctl.h +1 -1
index b4b4c8ba4d..deccdf455d 100644
@@ -15,7 +15,7 @@ struct tegra_xusb_phy;
  */
 struct tegra_xusb_phy *tegra_xusb_phy_get(unsigned int type);
 
-void tegra_xusb_padctl_init(const void *fdt);
+void tegra_xusb_padctl_init(void);
 int tegra_xusb_phy_prepare(struct tegra_xusb_phy *phy);
 int tegra_xusb_phy_enable(struct tegra_xusb_phy *phy);
 int tegra_xusb_phy_disable(struct tegra_xusb_phy *phy);
arch/arm/mach-tegra/board2.c +1 -1
index 6b5fa7df62..181dc30a6b 100644
@@ -166,7 +166,7 @@ int board_init(void)
 	pin_mux_nand();
 #endif
 
-	tegra_xusb_padctl_init(gd->fdt_blob);
+	tegra_xusb_padctl_init();
 
 #ifdef CONFIG_TEGRA_LP0
 	/* save Sdram params to PMC 2, 4, and 24 for WB0 */
arch/arm/mach-tegra/tegra124/xusb-padctl.c +29 -7
index 76af924b94..d326a6ae57 100644
@@ -8,6 +8,8 @@
 
 #include <common.h>
 #include <errno.h>
+#include <dm/of_access.h>
+#include <dm/ofnode.h>
 
 #include "../xusb-padctl-common.h"
 
@@ -317,13 +319,33 @@ static const struct tegra_xusb_padctl_soc tegra124_socdata = {
 	.num_phys = ARRAY_SIZE(tegra124_phys),
 };
 
-void tegra_xusb_padctl_init(const void *fdt)
+void tegra_xusb_padctl_init(void)
 {
-	int count, nodes[1];
+	ofnode nodes[1];
+	int count = 0;
+	int ret;
+
+	debug("%s: start\n", __func__);
+	if (of_live_active()) {
+		struct device_node *np = of_find_compatible_node(NULL, NULL,
+						"nvidia,tegra124-xusb-padctl");
+
+		debug("np=%p\n", np);
+		if (np) {
+			nodes[0] = np_to_ofnode(np);
+			count = 1;
+		}
+	} else {
+		int node_offsets[1];
+		int i;
+
+		count = fdtdec_find_aliases_for_id(gd->fdt_blob, "padctl",
+				COMPAT_NVIDIA_TEGRA124_XUSB_PADCTL,
+				node_offsets, ARRAY_SIZE(node_offsets));
+		for (i = 0; i < count; i++)
+			nodes[i] = offset_to_ofnode(node_offsets[i]);
+	}
 
-	count = fdtdec_find_aliases_for_id(fdt, "padctl",
-					   COMPAT_NVIDIA_TEGRA124_XUSB_PADCTL,
-					   nodes, ARRAY_SIZE(nodes));
-	if (tegra_xusb_process_nodes(fdt, nodes, count, &tegra124_socdata))
-		return;
+	ret = tegra_xusb_process_nodes(nodes, count, &tegra124_socdata);
+	debug("%s: done, ret=%d\n", __func__, ret);
 }
arch/arm/mach-tegra/tegra210/xusb-padctl.c +31 -11

60 lines not on this page · raw message

arch/arm/mach-tegra/xusb-padctl-common.c +35 -25

142 lines not on this page · raw message

arch/arm/mach-tegra/xusb-padctl-common.h +5 -3
index f44790a650..68365883c7 100644
@@ -9,9 +9,11 @@
 
 #include <common.h>
 #include <fdtdec.h>
+#include <dm/ofnode.h>
 
 #include <asm/io.h>
 #include <asm/arch-tegra/xusb-padctl.h>
+#include <linux/ioport.h>
 
 struct tegra_xusb_padctl_lane {
 	const char *name;
@@ -77,7 +79,7 @@ struct tegra_xusb_padctl_config {
 struct tegra_xusb_padctl {
 	const struct tegra_xusb_padctl_soc *socdata;
 	struct tegra_xusb_padctl_config config;
-	struct fdt_resource regs;
+	struct resource regs;
 	unsigned int enable;
 
 };
@@ -95,7 +97,7 @@ static inline void padctl_writel(struct tegra_xusb_padctl *padctl,
 	writel(value, padctl->regs.start + offset);
 }
 
-int tegra_xusb_process_nodes(const void *fdt, int nodes[], unsigned int count,
-	const struct tegra_xusb_padctl_soc *socdata);
+int tegra_xusb_process_nodes(ofnode nodes[], unsigned int count,
+			     const struct tegra_xusb_padctl_soc *socdata);
 
 #endif
arch/arm/mach-tegra/xusb-padctl-dummy.c +1 -1
index 65f8d2ea96..856d712512 100644
@@ -34,6 +34,6 @@ int __weak tegra_xusb_phy_unprepare(struct tegra_xusb_phy *phy)
 	return -ENOSYS;
 }
 
-void __weak tegra_xusb_padctl_init(const void *fdt)
+void __weak tegra_xusb_padctl_init(void)
 {
 }
Signature · 1 line
2.13.2.932.g7449e964c-goog
#6 lore raw

PATCH v4 6/20 dm: tegra: Convert clock_decode_periph_id() to support livetree

In reply to Simon Glass

Adjust this to take a device as a parameter instead of a node.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/include/asm/arch-tegra/clock.h | 2 +-
 arch/arm/mach-tegra/clock.c             | 5 ++---
 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/usb/host/ehci-tegra.c           | 2 +-
 7 files changed, 8 insertions(+), 9 deletions(-)
arch/arm/include/asm/arch-tegra/clock.h +1 -1
index f62b2a4378..92180db321 100644
@@ -266,7 +266,7 @@ void clock_ll_start_uart(enum periph_id periph_id);
  * @param node		Node to look at
  * @return peripheral ID, or PERIPH_ID_NONE if none
  */
-enum periph_id clock_decode_periph_id(const void *blob, int node);
+int clock_decode_periph_id(struct udevice *dev);
 
 /**
  * Checks if the oscillator bypass is enabled (XOBP bit)
arch/arm/mach-tegra/clock.c +2 -3
index 668bbd20c1..dc58b3027d 100644
@@ -655,14 +655,13 @@ void clock_ll_start_uart(enum periph_id periph_id)
 }
 
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-int clock_decode_periph_id(const void *blob, int node)
+int clock_decode_periph_id(struct udevice *dev)
 {
 	enum periph_id id;
 	u32 cell[2];
 	int err;
 
-	err = fdtdec_get_int_array(blob, node, "clocks", cell,
-				   ARRAY_SIZE(cell));
+	err = dev_read_u32_array(dev, "clocks", cell, ARRAY_SIZE(cell));
 	if (err)
 		return -1;
 	id = clk_id_to_periph_id(cell[1]);
drivers/spi/tegra114_spi.c +1 -1
index 91659349a3..6478352c31 100644
@@ -104,7 +104,7 @@ static int tegra114_spi_ofdata_to_platdata(struct udevice *bus)
 	int node = dev_of_offset(bus);
 
 	plat->base = devfdt_get_addr(bus);
-	plat->periph_id = clock_decode_periph_id(blob, node);
+	plat->periph_id = clock_decode_periph_id(bus);
 
 	if (plat->periph_id == PERIPH_ID_NONE) {
 		debug("%s: could not decode periph id %d\n", __func__,
drivers/spi/tegra20_sflash.c +1 -1
index 299e1b44fa..e70210d7ab 100644
@@ -91,7 +91,7 @@ static int tegra20_sflash_ofdata_to_platdata(struct udevice *bus)
 	int node = dev_of_offset(bus);
 
 	plat->base = devfdt_get_addr(bus);
-	plat->periph_id = clock_decode_periph_id(blob, node);
+	plat->periph_id = clock_decode_periph_id(bus);
 
 	if (plat->periph_id == PERIPH_ID_NONE) {
 		debug("%s: could not decode periph id %d\n", __func__,
drivers/spi/tegra20_slink.c +1 -1
index 4cbde7b22f..f242574760 100644
@@ -97,7 +97,7 @@ static int tegra30_spi_ofdata_to_platdata(struct udevice *bus)
 	int node = dev_of_offset(bus);
 
 	plat->base = devfdt_get_addr(bus);
-	plat->periph_id = clock_decode_periph_id(blob, node);
+	plat->periph_id = clock_decode_periph_id(bus);
 
 	if (plat->periph_id == PERIPH_ID_NONE) {
 		debug("%s: could not decode periph id %d\n", __func__,
drivers/spi/tegra210_qspi.c +1 -1
index 6d0b5da261..2a35a583f5 100644
@@ -100,7 +100,7 @@ static int tegra210_qspi_ofdata_to_platdata(struct udevice *bus)
 	int node = dev_of_offset(bus);
 
 	plat->base = devfdt_get_addr(bus);
-	plat->periph_id = clock_decode_periph_id(blob, node);
+	plat->periph_id = clock_decode_periph_id(bus);
 
 	if (plat->periph_id == PERIPH_ID_NONE) {
 		debug("%s: could not decode periph id %d\n", __func__,
drivers/usb/host/ehci-tegra.c +1 -1
index 7dc37f045d..873bf8ecfd 100644
@@ -723,7 +723,7 @@ static int fdt_decode_usb(struct udevice *dev, struct fdt_usb *config)
 	config->enabled = fdtdec_get_is_enabled(blob, node);
 	config->has_legacy_mode = fdtdec_get_bool(blob, node,
 						  "nvidia,has-legacy-mode");
-	config->periph_id = clock_decode_periph_id(blob, node);
+	config->periph_id = clock_decode_periph_id(dev);
 	if (config->periph_id == PERIPH_ID_NONE) {
 		debug("%s: Missing/invalid peripheral ID\n", __func__);
 		return -EINVAL;
Signature · 1 line
2.13.2.932.g7449e964c-goog
#7 lore raw

PATCH v4 7/20 dm: video: tegra124: Convert to livetree

In reply to Simon Glass

Update these drives to support a live device tree.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/video/tegra124/display.c |  8 +++-----
 drivers/video/tegra124/dp.c      |  3 +--
 drivers/video/tegra124/sor.c     | 25 +++++++------------------
 3 files changed, 11 insertions(+), 25 deletions(-)
drivers/video/tegra124/display.c +3 -5
index 47752b27f1..4164fa1bd9 100644
@@ -12,7 +12,6 @@
 #include <errno.h>
 #include <display.h>
 #include <edid.h>
-#include <fdtdec.h>
 #include <lcd.h>
 #include <video.h>
 #include <asm/gpio.h>
@@ -334,7 +333,6 @@ static int display_init(struct udevice *dev, void *lcdbase,
 {
 	struct display_plat *disp_uc_plat;
 	struct dc_ctlr *dc_ctlr;
-	const void *blob = gd->fdt_blob;
 	struct udevice *dp_dev;
 	const int href_to_sync = 1, vref_to_sync = 1;
 	int panel_bpp = 18;	/* default 18 bits per pixel */
@@ -363,9 +361,8 @@ static int display_init(struct udevice *dev, void *lcdbase,
 		return ret;
 	}
 
-	dc_ctlr = (struct dc_ctlr *)fdtdec_get_addr(blob, dev_of_offset(dev),
-						    "reg");
-	if (fdtdec_decode_display_timing(blob, dev_of_offset(dev), 0, timing)) {
+	dc_ctlr = (struct dc_ctlr *)dev_read_addr(dev);
+	if (ofnode_decode_display_timing(dev_ofnode(dev), 0, timing)) {
 		debug("%s: Failed to decode display timing\n", __func__);
 		return -EINVAL;
 	}
@@ -416,6 +413,7 @@ static int display_init(struct udevice *dev, void *lcdbase,
 		debug("dc: failed to update window\n");
 		return ret;
 	}
+	debug("%s: ready\n", __func__);
 
 	return 0;
 }
drivers/video/tegra124/dp.c +1 -2
index c38b3e5335..95d743d0f4 100644
@@ -10,7 +10,6 @@
 #include <dm.h>
 #include <div64.h>
 #include <errno.h>
-#include <fdtdec.h>
 #include <video_bridge.h>
 #include <asm/io.h>
 #include <asm/arch-tegra/dc.h>
@@ -1572,7 +1571,7 @@ static int tegra_dp_ofdata_to_platdata(struct udevice *dev)
 {
 	struct tegra_dp_plat *plat = dev_get_platdata(dev);
 
-	plat->base = devfdt_get_addr(dev);
+	plat->base = dev_read_addr(dev);
 
 	return 0;
 }
drivers/video/tegra124/sor.c +7 -18
index 4324071cdc..700ab25d46 100644
@@ -7,9 +7,9 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
-#include <fdtdec.h>
 #include <malloc.h>
 #include <panel.h>
+#include <syscon.h>
 #include <video_bridge.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
@@ -759,15 +759,12 @@ int tegra_dc_sor_attach(struct udevice *dc_dev, struct udevice *dev,
 			const struct display_timing *timing)
 {
 	struct tegra_dc_sor_data *sor = dev_get_priv(dev);
-	const void *blob = gd->fdt_blob;
 	struct dc_ctlr *disp_ctrl;
 	u32 reg_val;
-	int node;
 
 	/* Use the first display controller */
 	debug("%s\n", __func__);
-	node = dev_of_offset(dc_dev);
-	disp_ctrl = (struct dc_ctlr *)fdtdec_get_addr(blob, node, "reg");
+	disp_ctrl = (struct dc_ctlr *)dev_read_addr(dc_dev);
 
 	tegra_dc_sor_enable_dc(disp_ctrl);
 	tegra_dc_sor_config_panel(sor, 0, link_cfg, timing);
@@ -974,16 +971,13 @@ int tegra_dc_sor_detach(struct udevice *dc_dev, struct udevice *dev)
 {
 	struct tegra_dc_sor_data *sor = dev_get_priv(dev);
 	int dc_reg_ctx[DC_REG_SAVE_SPACE];
-	const void *blob = gd->fdt_blob;
 	struct dc_ctlr *disp_ctrl;
 	unsigned long dc_int_mask;
-	int node;
 	int ret;
 
 	debug("%s\n", __func__);
 	/* Use the first display controller */
-	node = dev_of_offset(dc_dev);
-	disp_ctrl = (struct dc_ctlr *)fdtdec_get_addr(blob, node, "reg");
+	disp_ctrl = (struct dc_ctlr *)dev_read_addr(dev);
 
 	/* Sleep mode */
 	tegra_sor_writel(sor, SUPER_STATE1, SUPER_STATE1_ASY_HEAD_OP_SLEEP |
@@ -1050,18 +1044,13 @@ static int tegra_sor_set_backlight(struct udevice *dev, int percent)
 static int tegra_sor_ofdata_to_platdata(struct udevice *dev)
 {
 	struct tegra_dc_sor_data *priv = dev_get_priv(dev);
-	const void *blob = gd->fdt_blob;
-	int node;
 	int ret;
 
-	priv->base = (void *)fdtdec_get_addr(blob, dev_of_offset(dev), "reg");
+	priv->base = (void *)dev_read_addr(dev);
 
-	node = fdtdec_next_compatible(blob, 0, COMPAT_NVIDIA_TEGRA124_PMC);
-	if (node < 0) {
-		debug("%s: Cannot find PMC\n", __func__);
-		return -ENOENT;
-	}
-	priv->pmc_base = (void *)fdtdec_get_addr(blob, node, "reg");
+	priv->pmc_base = (void *)syscon_get_first_range(TEGRA_SYSCON_PMC);
+	if (IS_ERR(priv->pmc_base))
+		return PTR_ERR(priv->pmc_base);
 
 	ret = uclass_get_device_by_phandle(UCLASS_PANEL, dev, "nvidia,panel",
 					   &priv->panel);
Signature · 1 line
2.13.2.932.g7449e964c-goog
#8 lore raw

PATCH v4 8/20 tegra: dts: Move stdout-path to /chosen

In reply to Simon Glass

This property should be in the /chosen node, not /aliases.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/dts/tegra124-nyan-big.dts | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm/dts/tegra124-nyan-big.dts +4 -1
index 62f89d0f1a..f1c97052a8 100644
@@ -8,7 +8,6 @@
 
 	aliases {
 		console = &uarta;
-		stdout-path = &uarta;
 		i2c0 = "/i2c at 7000d000";
 		i2c1 = "/i2c at 7000c000";
 		i2c2 = "/i2c at 7000c400";
@@ -26,6 +25,10 @@
 		usb2 = "/usb at 7d004000";
 	};
 
+	chosen {
+		stdout-path = &uarta;
+	};
+
 	host1x at 50000000 {
 		dc at 54200000 {
 			display-timings {
Signature · 1 line
2.13.2.932.g7449e964c-goog
#9 lore raw

PATCH v4 9/20 dm: tegra: gpio: Convert to support livetree

In reply to Simon Glass

Update the GPIO driver to support a live device tree.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/gpio/tegra_gpio.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpio/tegra_gpio.c +6 -4
index 687cd74fee..4965583158 100644
@@ -337,11 +337,13 @@ static int gpio_tegra_bind(struct udevice *parent)
 	 * This driver does not make use of interrupts, other than to figure
 	 * out the number of GPIO banks
 	 */
-	if (!fdt_getprop(gd->fdt_blob, dev_of_offset(parent), "interrupts",
-			 &len))
-		return -EINVAL;
+	len = dev_read_size(parent, "interrupts");
+	if (len < 0)
+		return len;
 	bank_count = len / 3 / sizeof(u32);
-	ctlr = (struct gpio_ctlr *)devfdt_get_addr(parent);
+	ctlr = (struct gpio_ctlr *)dev_read_addr(parent);
+	if ((ulong)ctlr == FDT_ADDR_T_NONE)
+		return -EINVAL;
 	}
 #endif
 	for (bank = 0; bank < bank_count; bank++) {
Signature · 1 line
2.13.2.932.g7449e964c-goog
#10 lore raw

PATCH v4 10/20 dm: tegra: usb: Convert to livetree

In reply to Simon Glass

Update the Tegra EHCI driver to support a live device tree.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/usb/host/ehci-tegra.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)
drivers/usb/host/ehci-tegra.c +14 -20
index 873bf8ecfd..1c72330b0c 100644
@@ -17,7 +17,6 @@
 #include <usb.h>
 #include <usb/ulpi.h>
 #include <libfdt.h>
-#include <fdtdec.h>
 
 #include "ehci.h"
 
@@ -695,12 +694,11 @@ static void config_clock(const u32 timing[])
 
 static int fdt_decode_usb(struct udevice *dev, struct fdt_usb *config)
 {
-	const void *blob = gd->fdt_blob;
-	int node = dev_of_offset(dev);
 	const char *phy, *mode;
 
-	config->reg = (struct usb_ctlr *)devfdt_get_addr(dev);
-	mode = fdt_getprop(blob, node, "dr_mode", NULL);
+	config->reg = (struct usb_ctlr *)dev_read_addr(dev);
+	debug("reg=%p\n", config->reg);
+	mode = dev_read_string(dev, "dr_mode");
 	if (mode) {
 		if (0 == strcmp(mode, "host"))
 			config->dr_mode = DR_MODE_HOST;
@@ -717,28 +715,24 @@ static int fdt_decode_usb(struct udevice *dev, struct fdt_usb *config)
 		config->dr_mode = DR_MODE_HOST;
 	}
 
-	phy = fdt_getprop(blob, node, "phy_type", NULL);
+	phy = dev_read_string(dev, "phy_type");
 	config->utmi = phy && 0 == strcmp("utmi", phy);
 	config->ulpi = phy && 0 == strcmp("ulpi", phy);
-	config->enabled = fdtdec_get_is_enabled(blob, node);
-	config->has_legacy_mode = fdtdec_get_bool(blob, node,
-						  "nvidia,has-legacy-mode");
+	config->has_legacy_mode = dev_read_bool(dev, "nvidia,has-legacy-mode");
 	config->periph_id = clock_decode_periph_id(dev);
 	if (config->periph_id == PERIPH_ID_NONE) {
 		debug("%s: Missing/invalid peripheral ID\n", __func__);
 		return -EINVAL;
 	}
-	gpio_request_by_name_nodev(offset_to_ofnode(node), "nvidia,vbus-gpio",
-				   0, &config->vbus_gpio, GPIOD_IS_OUT);
-	gpio_request_by_name_nodev(offset_to_ofnode(node),
-				   "nvidia,phy-reset-gpio", 0,
-				   &config->phy_reset_gpio, GPIOD_IS_OUT);
-	debug("enabled=%d, legacy_mode=%d, utmi=%d, ulpi=%d, periph_id=%d, "
-		"vbus=%d, phy_reset=%d, dr_mode=%d\n",
-		config->enabled, config->has_legacy_mode, config->utmi,
-		config->ulpi, config->periph_id,
-		gpio_get_number(&config->vbus_gpio),
-		gpio_get_number(&config->phy_reset_gpio), config->dr_mode);
+	gpio_request_by_name(dev, "nvidia,vbus-gpio", 0, &config->vbus_gpio,
+			     GPIOD_IS_OUT);
+	gpio_request_by_name(dev, "nvidia,phy-reset-gpio", 0,
+			     &config->phy_reset_gpio, GPIOD_IS_OUT);
+	debug("legacy_mode=%d, utmi=%d, ulpi=%d, periph_id=%d, vbus=%d, phy_reset=%d, dr_mode=%d, reg=%p\n",
+	      config->has_legacy_mode, config->utmi, config->ulpi,
+	      config->periph_id, gpio_get_number(&config->vbus_gpio),
+	      gpio_get_number(&config->phy_reset_gpio), config->dr_mode,
+	      config->reg);
 
 	return 0;
 }
Signature · 1 line
2.13.2.932.g7449e964c-goog
#11 lore raw

PATCH v4 11/20 dm: tegra: spi: Convert to livetree

In reply to Simon Glass

Update the tegra114 spi driver to support a live device tree.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/spi/tegra114_spi.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/spi/tegra114_spi.c +5 -8
index 6478352c31..04b4fce061 100644
@@ -12,7 +12,6 @@
 #include <asm/arch/clock.h>
 #include <asm/arch-tegra/clk_rst.h>
 #include <spi.h>
-#include <fdtdec.h>
 #include "tegra_spi.h"
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -100,10 +99,8 @@ struct tegra114_spi_priv {
 static int tegra114_spi_ofdata_to_platdata(struct udevice *bus)
 {
 	struct tegra_spi_platdata *plat = bus->platdata;
-	const void *blob = gd->fdt_blob;
-	int node = dev_of_offset(bus);
 
-	plat->base = devfdt_get_addr(bus);
+	plat->base = dev_read_addr(bus);
 	plat->periph_id = clock_decode_periph_id(bus);
 
 	if (plat->periph_id == PERIPH_ID_NONE) {
@@ -113,10 +110,10 @@ static int tegra114_spi_ofdata_to_platdata(struct udevice *bus)
 	}
 
 	/* Use 500KHz as a suitable default */
-	plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency",
-					500000);
-	plat->deactivate_delay_us = fdtdec_get_int(blob, node,
-					"spi-deactivate-delay", 0);
+	plat->frequency = dev_read_u32_default(bus, "spi-max-frequency",
+					       500000);
+	plat->deactivate_delay_us = dev_read_u32_default(bus,
+						"spi-deactivate-delay", 0);
 	debug("%s: base=%#08lx, periph_id=%d, max-frequency=%d, deactivate_delay=%d\n",
 	      __func__, plat->base, plat->periph_id, plat->frequency,
 	      plat->deactivate_delay_us);
Signature · 1 line
2.13.2.932.g7449e964c-goog
#12 lore raw

PATCH v4 12/20 dm: tegra: i2c: Convert to livetree

In reply to Simon Glass

Update the tegra i2c driver to support a live device tree.

---

Changes in v4:
- Drop fdtdec.h header

Changes in v3: None
Changes in v2: None

 drivers/i2c/tegra_i2c.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/i2c/tegra_i2c.c +5 -2
index 055f48153a..3255e8ed37 100644
@@ -9,7 +9,6 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
-#include <fdtdec.h>
 #include <i2c.h>
 #include <asm/io.h>
 #include <clk.h>
@@ -365,7 +364,11 @@ static int tegra_i2c_probe(struct udevice *dev)
 
 	i2c_bus->id = dev->seq;
 	i2c_bus->type = dev_get_driver_data(dev);
-	i2c_bus->regs = (struct i2c_ctlr *)devfdt_get_addr(dev);
+	i2c_bus->regs = (struct i2c_ctlr *)dev_read_addr(dev);
+	if ((ulong)i2c_bus->regs == FDT_ADDR_T_NONE) {
+		debug("%s: Cannot get regs address\n", __func__);
+		return -EINVAL;
+	}
 
 	ret = reset_get_by_name(dev, "i2c", &i2c_bus->reset_ctl);
 	if (ret) {
Signature · 1 line
2.13.2.932.g7449e964c-goog
#13 lore raw

PATCH v4 13/20 dm: tegra: pwm: Convert to livetree

In reply to Simon Glass

Update the tegra pwm driver to support a live device tree.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/pwm/tegra_pwm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pwm/tegra_pwm.c +1 -1
index d93ac28c31..b8acc1583f 100644
@@ -59,7 +59,7 @@ static int tegra_pwm_ofdata_to_platdata(struct udevice *dev)
 {
 	struct tegra_pwm_priv *priv = dev_get_priv(dev);
 
-	priv->regs = (struct pwm_ctlr *)devfdt_get_addr(dev);
+	priv->regs = (struct pwm_ctlr *)dev_read_addr(dev);
 
 	return 0;
 }
Signature · 1 line
2.13.2.932.g7449e964c-goog
#14 lore raw

PATCH v4 14/20 dm: tegra: mmc: Convert to livetree

In reply to Simon Glass

Update the tegra mmc driver to support a live device tree.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/mmc/tegra_mmc.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/mmc/tegra_mmc.c +7 -10
index 7d945a172e..74745296b4 100644
@@ -11,10 +11,10 @@
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
+#include <mmc.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
 #include <asm/arch-tegra/tegra_mmc.h>
-#include <mmc.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -599,8 +599,7 @@ static int tegra_mmc_probe(struct udevice *dev)
 
 	cfg->name = dev->name;
 
-	bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-				   "bus-width", 1);
+	bus_width = dev_read_u32_default(dev, "bus-width", 1);
 
 	cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
 	cfg->host_caps = 0;
@@ -621,7 +620,7 @@ static int tegra_mmc_probe(struct udevice *dev)
 
 	cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
 
-	priv->reg = (void *)devfdt_get_addr(dev);
+	priv->reg = (void *)dev_read_addr(dev);
 
 	ret = reset_get_by_name(dev, "sdhci", &priv->reset_ctl);
 	if (ret) {
@@ -648,12 +647,10 @@ static int tegra_mmc_probe(struct udevice *dev)
 		return ret;
 
 	/* These GPIOs are optional */
-	gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio,
-			     GPIOD_IS_IN);
-	gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio,
-			     GPIOD_IS_IN);
-	gpio_request_by_name(dev, "power-gpios", 0,
-			     &priv->pwr_gpio, GPIOD_IS_OUT);
+	gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio, GPIOD_IS_IN);
+	gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio, GPIOD_IS_IN);
+	gpio_request_by_name(dev, "power-gpios", 0, &priv->pwr_gpio,
+			     GPIOD_IS_OUT);
 	if (dm_gpio_is_valid(&priv->pwr_gpio))
 		dm_gpio_set_value(&priv->pwr_gpio, 1);
 
Signature · 1 line
2.13.2.932.g7449e964c-goog
#15 lore raw

PATCH v4 15/20 dm: tegra: pci: Convert to livetree

In reply to Simon Glass

Update the tegra pci driver to support a live device tree. Fix the check for nvidia,num-lanes so that an error will actually be detected.

---

Changes in v4:
- Update to deal with rename of ofnode_read_prop()

Changes in v3:
- Add new patch to convert tegra PCI to device tree

Changes in v2: None

 drivers/pci/pci_tegra.c | 53 ++++++++++++++++++++++---------------------------
 1 file changed, 24 insertions(+), 29 deletions(-)
drivers/pci/pci_tegra.c +24 -29
index 7d9c63b06f..cb5cf8b043 100644
@@ -16,7 +16,6 @@
 #include <clk.h>
 #include <dm.h>
 #include <errno.h>
-#include <fdtdec.h>
 #include <malloc.h>
 #include <pci.h>
 #include <power-domain.h>
@@ -25,6 +24,7 @@
 #include <asm/io.h>
 #include <asm/gpio.h>
 
+#include <linux/ioport.h>
 #include <linux/list.h>
 
 #ifndef CONFIG_TEGRA186
@@ -220,9 +220,9 @@ struct tegra_pcie_soc {
 struct tegra_pcie {
 	struct pci_controller hose;
 
-	struct fdt_resource pads;
-	struct fdt_resource afi;
-	struct fdt_resource cs;
+	struct resource pads;
+	struct resource afi;
+	struct resource cs;
 
 	struct list_head ports;
 	unsigned long xbar;
@@ -364,13 +364,12 @@ static int pci_tegra_write_config(struct udevice *bus, pci_dev_t bdf,
 	return 0;
 }
 
-static int tegra_pcie_port_parse_dt(const void *fdt, int node,
-				    struct tegra_pcie_port *port)
+static int tegra_pcie_port_parse_dt(ofnode node, struct tegra_pcie_port *port)
 {
 	const u32 *addr;
 	int len;
 
-	addr = fdt_getprop(fdt, node, "assigned-addresses", &len);
+	addr = ofnode_get_property(node, "assigned-addresses", &len);
 	if (!addr) {
 		error("property \"assigned-addresses\" not found");
 		return -FDT_ERR_NOTFOUND;
@@ -382,7 +381,7 @@ static int tegra_pcie_port_parse_dt(const void *fdt, int node,
 	return 0;
 }
 
-static int tegra_pcie_get_xbar_config(const void *fdt, int node, u32 lanes,
+static int tegra_pcie_get_xbar_config(ofnode node, u32 lanes,
 				      enum tegra_pci_id id, unsigned long *xbar)
 {
 	switch (id) {
@@ -456,14 +455,12 @@ static int tegra_pcie_get_xbar_config(const void *fdt, int node, u32 lanes,
 	return -FDT_ERR_NOTFOUND;
 }
 
-static int tegra_pcie_parse_port_info(const void *fdt, int node,
-				      unsigned int *index,
-				      unsigned int *lanes)
+static int tegra_pcie_parse_port_info(ofnode node, uint *index, uint *lanes)
 {
 	struct fdt_pci_addr addr;
 	int err;
 
-	err = fdtdec_get_int(fdt, node, "nvidia,num-lanes", 0);
+	err = ofnode_read_u32_default(node, "nvidia,num-lanes", -1);
 	if (err < 0) {
 		error("failed to parse \"nvidia,num-lanes\" property");
 		return err;
@@ -471,7 +468,7 @@ static int tegra_pcie_parse_port_info(const void *fdt, int node,
 
 	*lanes = err;
 
-	err = fdtdec_get_pci_addr(fdt, node, 0, "reg", &addr);
+	err = ofnode_read_pci_addr(node, 0, "reg", &addr);
 	if (err < 0) {
 		error("failed to parse \"reg\" property");
 		return err;
@@ -487,28 +484,26 @@ int __weak tegra_pcie_board_init(void)
 	return 0;
 }
 
-static int tegra_pcie_parse_dt(const void *fdt, int node, enum tegra_pci_id id,
+static int tegra_pcie_parse_dt(struct udevice *dev, enum tegra_pci_id id,
 			       struct tegra_pcie *pcie)
 {
-	int err, subnode;
+	ofnode subnode;
 	u32 lanes = 0;
+	int err;
 
-	err = fdt_get_named_resource(fdt, node, "reg", "reg-names", "pads",
-				     &pcie->pads);
+	err = dev_read_resource(dev, 0, &pcie->pads);
 	if (err < 0) {
 		error("resource \"pads\" not found");
 		return err;
 	}
 
-	err = fdt_get_named_resource(fdt, node, "reg", "reg-names", "afi",
-				     &pcie->afi);
+	err = dev_read_resource(dev, 1, &pcie->afi);
 	if (err < 0) {
 		error("resource \"afi\" not found");
 		return err;
 	}
 
-	err = fdt_get_named_resource(fdt, node, "reg", "reg-names", "cs",
-				     &pcie->cs);
+	err = dev_read_resource(dev, 2, &pcie->cs);
 	if (err < 0) {
 		error("resource \"cs\" not found");
 		return err;
@@ -531,12 +526,11 @@ static int tegra_pcie_parse_dt(const void *fdt, int node, enum tegra_pci_id id,
 	}
 #endif
 
-	fdt_for_each_subnode(subnode, fdt, node) {
+	dev_for_each_subnode(subnode, dev) {
 		unsigned int index = 0, num_lanes = 0;
 		struct tegra_pcie_port *port;
 
-		err = tegra_pcie_parse_port_info(fdt, subnode, &index,
-						 &num_lanes);
+		err = tegra_pcie_parse_port_info(subnode, &index, &num_lanes);
 		if (err < 0) {
 			error("failed to obtain root port info");
 			continue;
@@ -544,7 +538,7 @@ static int tegra_pcie_parse_dt(const void *fdt, int node, enum tegra_pci_id id,
 
 		lanes |= num_lanes << (index << 3);
 
-		if (!fdtdec_get_is_enabled(fdt, subnode))
+		if (!ofnode_is_available(subnode))
 			continue;
 
 		port = malloc(sizeof(*port));
@@ -555,7 +549,7 @@ static int tegra_pcie_parse_dt(const void *fdt, int node, enum tegra_pci_id id,
 		port->num_lanes = num_lanes;
 		port->index = index;
 
-		err = tegra_pcie_port_parse_dt(fdt, subnode, port);
+		err = tegra_pcie_port_parse_dt(subnode, port);
 		if (err < 0) {
 			free(port);
 			continue;
@@ -565,7 +559,8 @@ static int tegra_pcie_parse_dt(const void *fdt, int node, enum tegra_pci_id id,
 		port->pcie = pcie;
 	}
 
-	err = tegra_pcie_get_xbar_config(fdt, node, lanes, id, &pcie->xbar);
+	err = tegra_pcie_get_xbar_config(dev_ofnode(dev), lanes, id,
+					 &pcie->xbar);
 	if (err < 0) {
 		error("invalid lane configuration");
 		return err;
@@ -815,7 +810,7 @@ static int tegra_pcie_setup_translations(struct udevice *bus)
 
 	/* BAR 0: type 1 extended configuration space */
 	fpci = 0xfe100000;
-	size = fdt_resource_size(&pcie->cs);
+	size = resource_size(&pcie->cs);
 	axi = pcie->cs.start;
 
 	afi_writel(pcie, axi, AFI_AXI_BAR0_START);
@@ -1099,7 +1094,7 @@ static int pci_tegra_ofdata_to_platdata(struct udevice *dev)
 
 	INIT_LIST_HEAD(&pcie->ports);
 
-	if (tegra_pcie_parse_dt(gd->fdt_blob, dev_of_offset(dev), id, pcie))
+	if (tegra_pcie_parse_dt(dev, id, pcie))
 		return -EINVAL;
 
 	return 0;
Signature · 1 line
2.13.2.932.g7449e964c-goog
#16 lore raw

PATCH v4 16/20 power: Add a regulator driver for the as3722 PMIC

In reply to Simon Glass

This pmic includes regulators which should have their own driver. Add a driver to support these.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/power/regulator/Kconfig            |   9 ++
 drivers/power/regulator/Makefile           |   1 +
 drivers/power/regulator/as3722_regulator.c | 149 +++++++++++++++++++++++++++++
 include/power/as3722.h                     |   8 ++
 4 files changed, 167 insertions(+)
 create mode 100644 drivers/power/regulator/as3722_regulator.c
drivers/power/regulator/Kconfig +9 -0
index f2134874c2..c82a936e8a 100644
@@ -34,6 +34,15 @@ config REGULATOR_ACT8846
 	by the PMIC device. This driver is controlled by a device tree node
 	which includes voltage limits.
 
+config REGULATOR_AS3722
+	bool "Enable driver for AS7322 regulator"
+	depends on DM_REGULATOR && PMIC_AS3722
+	help
+	  Enable support for the regulator functions of the AS3722. The
+	  driver implements enable/disable for step-down bucks and LDOs,
+	  but does not yet support change voltages. Currently this must be
+	  done using direct register writes to the PMIC.
+
 config DM_REGULATOR_PFUZE100
 	bool "Enable Driver Model for REGULATOR PFUZE100"
 	depends on DM_REGULATOR && DM_PMIC_PFUZE100
drivers/power/regulator/Makefile +1 -0
index ce14d08fd4..18fb870e43 100644
@@ -7,6 +7,7 @@
 
 obj-$(CONFIG_$(SPL_)DM_REGULATOR) += regulator-uclass.o
 obj-$(CONFIG_REGULATOR_ACT8846) += act8846.o
+obj-$(CONFIG_REGULATOR_AS3722)	+= as3722_regulator.o
 obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
 obj-$(CONFIG_DM_REGULATOR_PFUZE100) += pfuze100.o
 obj-$(CONFIG_REGULATOR_PWM) += pwm_regulator.o
drivers/power/regulator/as3722_regulator.c new file +149 -0

149 lines not on this page · raw message

include/power/as3722.h +8 -0
index 0f22482ff7..14afa0c81a 100644
@@ -12,6 +12,14 @@
 #define AS3722_GPIO_OUTPUT_VDDH (1 << 0)
 #define AS3722_GPIO_INVERT (1 << 1)
 
+#define AS3722_DEVICE_ID 0x0c
+#define AS3722_SD_VOLTAGE(n) (0x00 + (n))
+#define AS3722_LDO_VOLTAGE(n) (0x10 + (n))
+#define AS3722_SD_CONTROL 0x4d
+#define AS3722_LDO_CONTROL 0x4e
+#define AS3722_ASIC_ID1 0x90
+#define AS3722_ASIC_ID2 0x91
+
 struct udevice;
 
 int as3722_init(struct udevice **devp);
Signature · 1 line
2.13.2.932.g7449e964c-goog
#17 lore raw

PATCH v4 17/20 power: Add a GPIO driver for the as3722 PMIC

In reply to Simon Glass

This pmic includes GPIOs which should have their own driver. Add a driver to support these.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/power/pmic/as3722_gpio.c | 120 +++++++++++++++++++++++++++++++++++++++
 include/power/as3722.h           |   5 ++
 2 files changed, 125 insertions(+)
 create mode 100644 drivers/power/pmic/as3722_gpio.c
drivers/power/pmic/as3722_gpio.c new file +120 -0
new file mode 100644
index 0000000000..d0b681ca4a
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2014 NVIDIA Corporation
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <asm/gpio.h>
+#include <power/as3722.h>
+#include <power/pmic.h>
+
+#define NUM_GPIOS	8
+
+int as3722_gpio_configure(struct udevice *pmic, unsigned int gpio,
+			  unsigned long flags)
+{
+	u8 value = 0;
+	int err;
+
+	if (flags & AS3722_GPIO_OUTPUT_VDDH)
+		value |= AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;
+
+	if (flags & AS3722_GPIO_INVERT)
+		value |= AS3722_GPIO_CONTROL_INVERT;
+
+	err = pmic_reg_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
+	if (err) {
+		error("failed to configure GPIO#%u: %d", gpio, err);
+		return err;
+	}
+
+	return 0;
+}
+
+static int as3722_gpio_set_value(struct udevice *dev, unsigned int gpio,
+				 int level)
+{
+	struct udevice *pmic = dev_get_parent(dev);
+	const char *l;
+	u8 value;
+	int err;
+
+	if (gpio >= NUM_GPIOS)
+		return -EINVAL;
+
+	err = pmic_reg_read(pmic, AS3722_GPIO_SIGNAL_OUT);
+	if (err < 0) {
+		error("failed to read GPIO signal out register: %d", err);
+		return err;
+	}
+	value = err;
+
+	if (level == 0) {
+		value &= ~(1 << gpio);
+		l = "low";
+	} else {
+		value |= 1 << gpio;
+		l = "high";
+	}
+
+	err = pmic_reg_write(pmic, AS3722_GPIO_SIGNAL_OUT, value);
+	if (err) {
+		error("failed to set GPIO#%u %s: %d", gpio, l, err);
+		return err;
+	}
+
+	return 0;
+}
+
+int as3722_gpio_direction_output(struct udevice *dev, unsigned int gpio,
+				 int value)
+{
+	struct udevice *pmic = dev_get_parent(dev);
+	int err;
+
+	if (gpio > 7)
+		return -EINVAL;
+
+	if (value == 0)
+		value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL;
+	else
+		value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;
+
+	err = pmic_reg_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
+	if (err) {
+		error("failed to configure GPIO#%u as output: %d", gpio, err);
+		return err;
+	}
+
+	err = as3722_gpio_set_value(pmic, gpio, value);
+	if (err < 0) {
+		error("failed to set GPIO#%u high: %d", gpio, err);
+		return err;
+	}
+
+	return 0;
+}
+
+static int as3722_gpio_probe(struct udevice *dev)
+{
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
+	uc_priv->gpio_count = NUM_GPIOS;
+	uc_priv->bank_name = "as3722_";
+
+	return 0;
+}
+
+static const struct dm_gpio_ops gpio_as3722_ops = {
+	.direction_output	= as3722_gpio_direction_output,
+	.set_value		= as3722_gpio_set_value,
+};
+
+U_BOOT_DRIVER(gpio_as3722) = {
+	.name	= "gpio_as3722",
+	.id	= UCLASS_GPIO,
+	.ops	= &gpio_as3722_ops,
+	.probe	= as3722_gpio_probe,
+};
include/power/as3722.h +5 -0
index 14afa0c81a..713e79840f 100644
@@ -20,6 +20,11 @@
 #define AS3722_ASIC_ID1 0x90
 #define AS3722_ASIC_ID2 0x91
 
+#define AS3722_GPIO_CONTROL(n) (0x08 + (n))
+#define AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH (1 << 0)
+#define AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL (7 << 0)
+#define AS3722_GPIO_CONTROL_INVERT (1 << 7)
+
 struct udevice;
 
 int as3722_init(struct udevice **devp);
Signature · 1 line
2.13.2.932.g7449e964c-goog
#18 lore raw

PATCH v4 18/20 dm: power: Convert as3722 to driver model

In reply to Simon Glass

Convert this PMIC driver to driver model and fix up other users. The regulator and GPIO functions are now handled by separate drivers.

Update nyan-big to work correct. Three boards will need to be updated by the maintainers: apalis-tk1, jetson-tk1, cei-tk1-som

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/mach-tegra/board2.c          |   6 -
 board/cei/cei-tk1-som/cei-tk1-som.c   |   2 +
 board/nvidia/jetson-tk1/jetson-tk1.c  |   2 +
 board/nvidia/nyan-big/nyan-big.c      |  22 +--
 board/toradex/apalis-tk1/apalis-tk1.c |   6 +
 configs/apalis-tk1_defconfig          |   3 +
 configs/cei-tk1-som_defconfig         |   3 +
 configs/jetson-tk1_defconfig          |   3 +
 configs/nyan-big_defconfig            |   1 +
 drivers/power/pmic/Makefile           |   2 +-
 drivers/power/pmic/as3722.c           | 292 ++++++++++++----------------------
 include/power/as3722.h                |  18 +--
 12 files changed, 133 insertions(+), 227 deletions(-)
arch/arm/mach-tegra/board2.c +0 -6
index 181dc30a6b..bd137969f0 100644
@@ -29,7 +29,6 @@
 #ifdef CONFIG_TEGRA_CLOCK_SCALING
 #include <asm/arch/emc.h>
 #endif
-#include <power/as3722.h>
 #include "emc.h"
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -142,11 +141,6 @@ int board_init(void)
 		debug("Memory controller init failed: %d\n", err);
 #  endif
 # endif /* CONFIG_TEGRA_PMU */
-#ifdef CONFIG_PMIC_AS3722
-	err = as3722_init(NULL);
-	if (err && err != -ENODEV)
-		return err;
-#endif
 #endif /* CONFIG_SYS_I2C_TEGRA */
 
 #ifdef CONFIG_USB_EHCI_TEGRA
board/cei/cei-tk1-som/cei-tk1-som.c +2 -0
index 9ba7490c38..7c87bd1eb1 100644
@@ -39,6 +39,7 @@ void pinmux_init(void)
 #ifdef CONFIG_PCI_TEGRA
 int tegra_pcie_board_init(void)
 {
+/* TODO: Convert to driver model
 	struct udevice *pmic;
 	int err;
 
@@ -59,6 +60,7 @@ int tegra_pcie_board_init(void)
 		error("failed to set SD4 voltage: %d\n", err);
 		return err;
 	}
+*/
 
 	return 0;
 }
board/nvidia/jetson-tk1/jetson-tk1.c +2 -0
index a66b710cdd..48272d086c 100644
@@ -39,6 +39,7 @@ void pinmux_init(void)
 #ifdef CONFIG_PCI_TEGRA
 int tegra_pcie_board_init(void)
 {
+/* TODO: Convert to driver model
 	struct udevice *pmic;
 	int err;
 
@@ -59,6 +60,7 @@ int tegra_pcie_board_init(void)
 		error("failed to set SD4 voltage: %d\n", err);
 		return err;
 	}
+*/
 
 	return 0;
 }
board/nvidia/nyan-big/nyan-big.c +13 -9
index 8f68ae9fbe..54acf5418d 100644
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
@@ -46,20 +47,23 @@ int tegra_board_id(void)
 
 int tegra_lcd_pmic_init(int board_id)
 {
-	struct udevice *pmic;
+	struct udevice *dev;
 	int ret;
 
-	ret = as3722_get(&pmic);
-	if (ret)
-		return -ENOENT;
+	ret = uclass_get_device_by_driver(UCLASS_PMIC,
+					  DM_GET_DRIVER(pmic_as3722), &dev);
+	if (ret) {
+		debug("%s: Failed to find PMIC\n", __func__);
+		return ret;
+	}
 
 	if (board_id == 0)
-		as3722_write(pmic, 0x00, 0x3c);
+		pmic_reg_write(dev, 0x00, 0x3c);
 	else
-		as3722_write(pmic, 0x00, 0x50);
-	as3722_write(pmic, 0x12, 0x10);
-	as3722_write(pmic, 0x0c, 0x07);
-	as3722_write(pmic, 0x20, 0x10);
+		pmic_reg_write(dev, 0x00, 0x50);
+	pmic_reg_write(dev, 0x12, 0x10);
+	pmic_reg_write(dev, 0x0c, 0x07);
+	pmic_reg_write(dev, 0x20, 0x10);
 
 	return 0;
 }
board/toradex/apalis-tk1/apalis-tk1.c +6 -0
index c7e519c19b..5de61e7c2b 100644
@@ -61,6 +61,7 @@ void pinmux_init(void)
 #ifdef CONFIG_PCI_TEGRA
 int tegra_pcie_board_init(void)
 {
+	/* TODO: Convert to driver model
 	struct udevice *pmic;
 	int err;
 
@@ -94,6 +95,7 @@ int tegra_pcie_board_init(void)
 		error("failed to set GPIO#2 high: %d\n", err);
 		return err;
 	}
+	*/
 
 	/* Reset I210 Gigabit Ethernet Controller */
 	gpio_request(LAN_RESET_N, "LAN_RESET_N");
@@ -110,6 +112,7 @@ int tegra_pcie_board_init(void)
 	gpio_direction_output(TEGRA_GPIO(O, 6), 0);
 
 	/* Make sure LDO9 and LDO10 are initially enabled @ 0V */
+	/* TODO: Convert to driver model
 	err = as3722_ldo_enable(pmic, 9);
 	if (err < 0) {
 		error("failed to enable LDO9: %d\n", err);
@@ -130,6 +133,7 @@ int tegra_pcie_board_init(void)
 		error("failed to set LDO10 voltage: %d\n", err);
 		return err;
 	}
+	*/
 
 	mdelay(100);
 
@@ -137,6 +141,7 @@ int tegra_pcie_board_init(void)
 	gpio_set_value(TEGRA_GPIO(O, 6), 1);
 
 	/* Enable LDO9 and LDO10 for +V3.3_ETH on patched prototypes */
+	/* TODO: Convert to driver model
 	err = as3722_ldo_set_voltage(pmic, 9, 0xff);
 	if (err < 0) {
 		error("failed to set LDO9 voltage: %d\n", err);
@@ -147,6 +152,7 @@ int tegra_pcie_board_init(void)
 		error("failed to set LDO10 voltage: %d\n", err);
 		return err;
 	}
+	*/
 
 	mdelay(100);
 	gpio_set_value(LAN_RESET_N, 1);
configs/apalis-tk1_defconfig +3 -0
index 9179aaf92f..ccff112392 100644
@@ -32,7 +32,10 @@ CONFIG_PCI=y
 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_TEGRA=y
+CONFIG_DM_PMIC=y
 CONFIG_PMIC_AS3722=y
+CONFIG_DM_REGULATOR=y
+CONFIG_REGULATOR_AS3722=y
 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
 CONFIG_DM_USB=y
configs/cei-tk1-som_defconfig +3 -0
index 1a5e47dba5..5623bbfbc6 100644
@@ -36,7 +36,10 @@ CONFIG_PCI=y
 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_TEGRA=y
+CONFIG_DM_PMIC=y
 CONFIG_PMIC_AS3722=y
+CONFIG_DM_REGULATOR=y
+CONFIG_REGULATOR_AS3722=y
 CONFIG_SYS_NS16550=y
 CONFIG_TEGRA114_SPI=y
 CONFIG_USB=y
configs/jetson-tk1_defconfig +3 -0
index 65a5832e44..d086951299 100644
@@ -36,7 +36,10 @@ CONFIG_PCI=y
 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_TEGRA=y
+CONFIG_DM_PMIC=y
 CONFIG_PMIC_AS3722=y
+CONFIG_DM_REGULATOR=y
+CONFIG_REGULATOR_AS3722=y
 CONFIG_SYS_NS16550=y
 CONFIG_TEGRA114_SPI=y
 CONFIG_USB=y
configs/nyan-big_defconfig +1 -0
index cb3b0a85cf..8e11c2f15c 100644
@@ -49,6 +49,7 @@ CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_DM_PMIC=y
 CONFIG_PMIC_AS3722=y
 CONFIG_DM_REGULATOR=y
+CONFIG_REGULATOR_AS3722=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_PWM_TEGRA=y
 CONFIG_DEBUG_UART=y
drivers/power/pmic/Makefile +1 -1
index f488799a92..f7bdfa5609 100644
@@ -12,7 +12,7 @@ obj-$(CONFIG_DM_PMIC_PFUZE100) += pfuze100.o
 obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o
 obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o
 obj-$(CONFIG_PMIC_ACT8846) += act8846.o
-obj-$(CONFIG_PMIC_AS3722) += as3722.o
+obj-$(CONFIG_PMIC_AS3722) += as3722.o as3722_gpio.o
 obj-$(CONFIG_PMIC_MAX8997) += max8997.o
 obj-$(CONFIG_PMIC_PM8916) += pm8916.o
 obj-$(CONFIG_PMIC_RK8XX) += rk8xx.o
drivers/power/pmic/as3722.c +98 -194

362 lines not on this page · raw message

include/power/as3722.h +1 -17
index 713e79840f..491f1b7ea7 100644
@@ -7,8 +7,6 @@
 #ifndef __POWER_AS3722_H__
 #define __POWER_AS3722_H__
 
-#include <asm/types.h>
-
 #define AS3722_GPIO_OUTPUT_VDDH (1 << 0)
 #define AS3722_GPIO_INVERT (1 << 1)
 
@@ -21,23 +19,9 @@
 #define AS3722_ASIC_ID2 0x91
 
 #define AS3722_GPIO_CONTROL(n) (0x08 + (n))
+#define AS3722_GPIO_SIGNAL_OUT 0x20
 #define AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH (1 << 0)
 #define AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL (7 << 0)
 #define AS3722_GPIO_CONTROL_INVERT (1 << 7)
 
-struct udevice;
-
-int as3722_init(struct udevice **devp);
-int as3722_sd_enable(struct udevice *pmic, unsigned int sd);
-int as3722_sd_set_voltage(struct udevice *pmic, unsigned int sd, u8 value);
-int as3722_ldo_enable(struct udevice *pmic, unsigned int ldo);
-int as3722_ldo_set_voltage(struct udevice *pmic, unsigned int ldo, u8 value);
-int as3722_gpio_configure(struct udevice *pmic, unsigned int gpio,
-			  unsigned long flags);
-int as3722_gpio_direction_output(struct udevice *pmic, unsigned int gpio,
-				 unsigned int level);
-int as3722_read(struct udevice *pmic, u8 reg, u8 *value);
-int as3722_write(struct udevice *pmic, u8 reg, u8 value);
-int as3722_get(struct udevice **devp);
-
 #endif /* __POWER_AS3722_H__ */
Signature · 1 line
2.13.2.932.g7449e964c-goog
#19 lore raw

PATCH v4 18/20 dm: power: Convert as3722 to driver model

Quoted 82 lines · Simon Glass

Convert this PMIC driver to driver model and fix up other users. The regulator and GPIO functions are now handled by separate drivers.

Update nyan-big to work correct. Three boards will need to be updated by
the maintainers: apalis-tk1, jetson-tk1, cei-tk1-som

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/mach-tegra/board2.c          |   6 - board/cei/cei-tk1-som/cei-tk1-som.c   |   2 + board/nvidia/jetson-tk1/jetson-tk1.c  |   2 + board/nvidia/nyan-big/nyan-big.c      |  22 +-- board/toradex/apalis-tk1/apalis-tk1.c |   6 + configs/apalis-tk1_defconfig          |   3 + configs/cei-tk1-som_defconfig         |   3 + configs/jetson-tk1_defconfig          |   3 + configs/nyan-big_defconfig            |   1 + drivers/power/pmic/Makefile           |   2 +- drivers/power/pmic/as3722.c           | 292 ++++++++++++----------
------------
 include/power/as3722.h                |  18 +--

 12 files changed, 133 insertions(+), 227 deletions(-)
arch/arm/mach- renamed from arch/arm/mach-tegra/board2.c +0 -0

tegra/board2.c
index 181dc30a6b..bd137969f0 100644

arch/arm/mach-tegra/board2.c +0 -1
@@ -29,7 +29,6 @@
  #ifdef CONFIG_TEGRA_CLOCK_SCALING
  #include <asm/arch/emc.h>
  #endif
-#include <power/as3722.h>
  #include "emc.h"


 DECLARE_GLOBAL_DATA_PTR;

arch/arm/mach-tegra/board2.c +0 -5
@@ -142,11 +141,6 @@ int board_init(void)
  		debug("Memory controller init failed: %d\n", err);
  #  endif
  # endif /* CONFIG_TEGRA_PMU */
-#ifdef CONFIG_PMIC_AS3722
-	err = as3722_init(NULL);
-	if (err && err != -ENODEV)
-		return err;
-#endif
  #endif /* CONFIG_SYS_I2C_TEGRA */


 #ifdef CONFIG_USB_EHCI_TEGRA

board/cei/cei-tk1- renamed from board/cei/cei-tk1-som/cei-tk1-som.c +0 -0

som/cei-tk1-som.c
index 9ba7490c38..7c87bd1eb1 100644

board/cei/cei-tk1-som/cei-tk1-som.c +1 -0
@@ -39,6 +39,7 @@ void pinmux_init(void)
  #ifdef CONFIG_PCI_TEGRA
  int tegra_pcie_board_init(void)
  {
+/* TODO: Convert to driver model
  	struct udevice *pmic;
  	int err;

board/cei/cei-tk1-som/cei-tk1-som.c +1 -0
@@ -59,6 +60,7 @@ int tegra_pcie_board_init(void)
  		error("failed to set SD4 voltage: %d\n", err);
  		return err;
  	}
+*/


  return 0;
 }

board/nvidia/jetson-tk1/jetson-tk1.c +0 -0
index a66b710cdd..48272d086c 100644

board/nvidia/jetson-tk1/jetson-tk1.c void pinmux_init(void) · line 42

Quoted 4 lines
board/nvidia/jetson-tk1/jetson-tk1.c +1 -0
@@ -39,6 +39,7 @@ void pinmux_init(void)
  #ifdef CONFIG_PCI_TEGRA
  int tegra_pcie_board_init(void)
  {
+/* TODO: Convert to driver model

Is that still applicable or how was that one solved at the end?

Quoted 621 lines
board/nvidia/jetson-tk1/jetson-tk1.c +0 -0
  	struct udevice *pmic;
  	int err;

board/nvidia/jetson-tk1/jetson-tk1.c +1 -0
@@ -59,6 +60,7 @@ int tegra_pcie_board_init(void)
  		error("failed to set SD4 voltage: %d\n", err);
  		return err;
  	}
+*/


  return 0;
 }

board/nvidia/nyan- renamed from board/nvidia/nyan-big/nyan-big.c +0 -0

big/nyan-big.c
index 8f68ae9fbe..54acf5418d 100644

board/nvidia/nyan-big/nyan-big.c +0 -0
@@ -6,6 +6,7 @@
   */


 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <asm/gpio.h>
 #include <asm/io.h>

board/nvidia/nyan-big/nyan-big.c +0 -0
@@ -46,20 +47,23 @@ int tegra_board_id(void)


 int tegra_lcd_pmic_init(int board_id)
 {

board/nvidia/nyan-big/nyan-big.c +1 -1
-	struct udevice *pmic;
+	struct udevice *dev;

  int ret;

board/nvidia/nyan-big/nyan-big.c +2 -3
-	ret = as3722_get(&pmic);
-	if (ret)
-		return -ENOENT;
+	ret = uclass_get_device_by_driver(UCLASS_PMIC,
+					  DM_GET_DRIVER(pmic_as3722)

, &dev);

board/nvidia/nyan-big/nyan-big.c +4 -0
+	if (ret) {
+		debug("%s: Failed to find PMIC\n", __func__);
+		return ret;
+	}


  if (board_id == 0)

board/nvidia/nyan-big/nyan-big.c +1 -1
-		as3722_write(pmic, 0x00, 0x3c);
+		pmic_reg_write(dev, 0x00, 0x3c);

  else

board/nvidia/nyan-big/nyan-big.c +4 -4
-		as3722_write(pmic, 0x00, 0x50);
-	as3722_write(pmic, 0x12, 0x10);
-	as3722_write(pmic, 0x0c, 0x07);
-	as3722_write(pmic, 0x20, 0x10);
+		pmic_reg_write(dev, 0x00, 0x50);
+	pmic_reg_write(dev, 0x12, 0x10);
+	pmic_reg_write(dev, 0x0c, 0x07);
+	pmic_reg_write(dev, 0x20, 0x10);


  return 0;
 }

board/toradex/apalis-tk1/apalis-tk1.c +1 -0
index c7e519c19b..5de61e7c2b 100644
@@ -61,6 +61,7 @@ void pinmux_init(void)
  #ifdef CONFIG_PCI_TEGRA
  int tegra_pcie_board_init(void)
  {
+	/* TODO: Convert to driver model
  	struct udevice *pmic;
  	int err;

board/toradex/apalis-tk1/apalis-tk1.c +1 -0
@@ -94,6 +95,7 @@ int tegra_pcie_board_init(void)
  		error("failed to set GPIO#2 high: %d\n", err);
  		return err;
  	}
+	*/


  /* Reset I210 Gigabit Ethernet Controller */ gpio_request(LAN_RESET_N, "LAN_RESET_N");

board/toradex/apalis-tk1/apalis-tk1.c +0 -0
@@ -110,6 +112,7 @@ int tegra_pcie_board_init(void)
  	gpio_direction_output(TEGRA_GPIO(O, 6), 0);


  /* Make sure LDO9 and LDO10 are initially enabled @ 0V */

board/toradex/apalis-tk1/apalis-tk1.c +1 -0
+	/* TODO: Convert to driver model

  err = as3722_ldo_enable(pmic, 9);
  if (err < 0) {
  error("failed to enable LDO9: %d\n", err);

board/toradex/apalis-tk1/apalis-tk1.c +1 -0
@@ -130,6 +133,7 @@ int tegra_pcie_board_init(void)
  		error("failed to set LDO10 voltage: %d\n", err);
  		return err;
  	}
+	*/


  mdelay(100);

board/toradex/apalis-tk1/apalis-tk1.c +0 -0
@@ -137,6 +141,7 @@ int tegra_pcie_board_init(void)
  	gpio_set_value(TEGRA_GPIO(O, 6), 1);


  /* Enable LDO9 and LDO10 for +V3.3_ETH on patched prototypes */

board/toradex/apalis-tk1/apalis-tk1.c +1 -0
+	/* TODO: Convert to driver model

  err = as3722_ldo_set_voltage(pmic, 9, 0xff); if (err < 0) {
  error("failed to set LDO9 voltage: %d\n", err);

board/toradex/apalis-tk1/apalis-tk1.c +1 -0
@@ -147,6 +152,7 @@ int tegra_pcie_board_init(void)
  		error("failed to set LDO10 voltage: %d\n", err);
  		return err;
  	}
+	*/


  mdelay(100);
  gpio_set_value(LAN_RESET_N, 1);

configs/apalis- renamed from configs/apalis-tk1_defconfig +0 -0

tk1_defconfig
index 9179aaf92f..ccff112392 100644

configs/apalis-tk1_defconfig +0 -0
@@ -32,7 +32,10 @@ CONFIG_PCI=y

 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_TEGRA=y
+CONFIG_DM_PMIC=y
 CONFIG_PMIC_AS3722=y

configs/apalis-tk1_defconfig +2 -0
+CONFIG_DM_REGULATOR=y
+CONFIG_REGULATOR_AS3722=y

 CONFIG_SYS_NS16550=y
 CONFIG_USB=y
 CONFIG_DM_USB=y

configs/cei-tk1- renamed from configs/cei-tk1-som_defconfig +0 -0

som_defconfig
index 1a5e47dba5..5623bbfbc6 100644

configs/cei-tk1-som_defconfig +0 -0
@@ -36,7 +36,10 @@ CONFIG_PCI=y

 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_TEGRA=y
+CONFIG_DM_PMIC=y
 CONFIG_PMIC_AS3722=y

configs/cei-tk1-som_defconfig +2 -0
+CONFIG_DM_REGULATOR=y
+CONFIG_REGULATOR_AS3722=y

 CONFIG_SYS_NS16550=y
 CONFIG_TEGRA114_SPI=y
 CONFIG_USB=y

configs/jetson- renamed from configs/jetson-tk1_defconfig +0 -0

tk1_defconfig
index 65a5832e44..d086951299 100644

configs/jetson-tk1_defconfig +0 -0
@@ -36,7 +36,10 @@ CONFIG_PCI=y

 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_TEGRA=y
+CONFIG_DM_PMIC=y
 CONFIG_PMIC_AS3722=y

configs/jetson-tk1_defconfig +2 -0
+CONFIG_DM_REGULATOR=y
+CONFIG_REGULATOR_AS3722=y

 CONFIG_SYS_NS16550=y
 CONFIG_TEGRA114_SPI=y
 CONFIG_USB=y

configs/nyan-big_defconfig +0 -0
index cb3b0a85cf..8e11c2f15c 100644
@@ -49,6 +49,7 @@ CONFIG_SPI_FLASH_WINBOND=y

 CONFIG_DM_PMIC=y
 CONFIG_PMIC_AS3722=y
 CONFIG_DM_REGULATOR=y
+CONFIG_REGULATOR_AS3722=y
 CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_PWM_TEGRA=y
 CONFIG_DEBUG_UART=y

drivers/power/pmic/Makefile +0 -0
index f488799a92..f7bdfa5609 100644
@@ -12,7 +12,7 @@ obj-$(CONFIG_DM_PMIC_PFUZE100) += pfuze100.o

 obj-$(CONFIG_PMIC_S2MPS11) += s2mps11.o obj-$(CONFIG_DM_PMIC_SANDBOX) += sandbox.o i2c_pmic_emul.o obj-$(CONFIG_PMIC_ACT8846) += act8846.o

drivers/power/pmic/Makefile +1 -1
-obj-$(CONFIG_PMIC_AS3722) += as3722.o
+obj-$(CONFIG_PMIC_AS3722) += as3722.o as3722_gpio.o

 obj-$(CONFIG_PMIC_MAX8997) += max8997.o
 obj-$(CONFIG_PMIC_PM8916) += pm8916.o
 obj-$(CONFIG_PMIC_RK8XX) += rk8xx.o

drivers/power/pmic/as3722.c +2 -1
index c09e1de06f..4efe8ee183 100644
@@ -11,264 +11,168 @@
  #include <errno.h>
  #include <fdtdec.h>
  #include <i2c.h>
-
+#include <dm/lists.h>
  #include <power/as3722.h>
+#include <power/pmic.h>

drivers/power/pmic/as3722.c +1 -23
-#define AS3722_SD_VOLTAGE(n) (0x00 + (n))
-#define AS3722_GPIO_CONTROL(n) (0x08 + (n))
-#define  AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH (1 << 0)
-#define  AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL (7 << 0)
-#define  AS3722_GPIO_CONTROL_INVERT (1 << 7)
-#define AS3722_LDO_VOLTAGE(n) (0x10 + (n))
-#define AS3722_GPIO_SIGNAL_OUT 0x20
-#define AS3722_SD_CONTROL 0x4d
-#define AS3722_LDO_CONTROL 0x4e
-#define AS3722_ASIC_ID1 0x90
-#define  AS3722_DEVICE_ID 0x0c
-#define AS3722_ASIC_ID2 0x91
-
-int as3722_read(struct udevice *pmic, u8 reg, u8 *value)
-{
-	int err;
-
-	err = dm_i2c_read(pmic, reg, value, 1);
-	if (err < 0)
-		return err;
-
-	return 0;
-}
+#define AS3722_NUM_OF_REGS	0x92

drivers/power/pmic/as3722.c +1 -1
-int as3722_write(struct udevice *pmic, u8 reg, u8 value)
+static int as3722_read(struct udevice *dev, uint reg, uint8_t *buff,

int len)
 {

drivers/power/pmic/as3722.c +1 -1
-	int err;
+	int ret;

drivers/power/pmic/as3722.c +3 -3
-	err = dm_i2c_write(pmic, reg, &value, 1);
-	if (err < 0)
-		return err;
+	ret = dm_i2c_read(dev, reg, buff, len);
+	if (ret < 0)
+		return ret;


  return 0;
 }

-static int as3722_read_id(struct udevice *pmic, u8 *id, u8 *revision)
+static int as3722_write(struct udevice *dev, uint reg, const uint8_t *buff,

drivers/power/pmic/as3722.c +1 -0
+			int len)

 {

drivers/power/pmic/as3722.c +1 -1
-	int err;
+	int ret;

drivers/power/pmic/as3722.c +3 -11
-	err = as3722_read(pmic, AS3722_ASIC_ID1, id);
-	if (err) {
-		error("failed to read ID1 register: %d", err);
-		return err;
-	}
-
-	err = as3722_read(pmic, AS3722_ASIC_ID2, revision);
-	if (err) {
-		error("failed to read ID2 register: %d", err);
-		return err;
-	}
+	ret = dm_i2c_write(dev, reg, buff, len);
+	if (ret < 0)
+		return ret;


  return 0;
 }

drivers/power/pmic/as3722.c +1 -1
-int as3722_sd_enable(struct udevice *pmic, unsigned int sd)
+static int as3722_read_id(struct udevice *dev, uint *idp, uint

*revisionp)
 {

drivers/power/pmic/as3722.c +1 -5
-	u8 value;
-	int err;
-
-	if (sd > 6)
-		return -EINVAL;
+	int ret;

drivers/power/pmic/as3722.c +0 -3
-	err = as3722_read(pmic, AS3722_SD_CONTROL, &value);
-	if (err) {
-		error("failed to read SD control register: %d",

err);

drivers/power/pmic/as3722.c +4 -1
-		return err;
+	ret = pmic_reg_read(dev, AS3722_ASIC_ID1);
+	if (ret < 0) {
+		error("failed to read ID1 register: %d", ret);
+		return ret;

  }

drivers/power/pmic/as3722.c +1 -0
+	*idp = ret;

drivers/power/pmic/as3722.c +0 -5
-	value |= 1 << sd;
-
-	err = as3722_write(pmic, AS3722_SD_CONTROL, value);
-	if (err < 0) {
-		error("failed to write SD control register: %d",

err);

drivers/power/pmic/as3722.c +4 -1
-		return err;
+	ret = pmic_reg_read(dev, AS3722_ASIC_ID2);
+	if (ret < 0) {
+		error("failed to read ID2 register: %d", ret);
+		return ret;

  }

drivers/power/pmic/as3722.c +1 -0
+	*revisionp = ret;


  return 0;
 }

-int as3722_sd_set_voltage(struct udevice *pmic, unsigned int sd, u8 value)
+/* TODO(treding at nvidia.com): Add proper regulator support to avoid this */
+int as3722_sd_set_voltage(struct udevice *dev, unsigned int sd, u8 value)
 {

drivers/power/pmic/as3722.c +1 -1
-	int err;
+	int ret;


  if (sd > 6)
  return -EINVAL;

drivers/power/pmic/as3722.c +0 -3
-	err = as3722_write(pmic, AS3722_SD_VOLTAGE(sd), value);
-	if (err < 0) {
-		error("failed to write SD%u voltage register: %d",

sd, err);

drivers/power/pmic/as3722.c +3 -1
-		return err;
+	ret = pmic_reg_write(dev, AS3722_SD_VOLTAGE(sd), value);
+	if (ret < 0) {
+		error("failed to write SD%u voltage register: %d",

sd, ret);

drivers/power/pmic/as3722.c +1 -0
+		return ret;

  }

  return 0;
 }

drivers/power/pmic/as3722.c +1 -1
-int as3722_ldo_enable(struct udevice *pmic, unsigned int ldo)
+int as3722_ldo_set_voltage(struct udevice *dev, unsigned int ldo, u8

value)
 {

drivers/power/pmic/as3722.c +1 -2
-	u8 value;
-	int err;
+	int ret;


  if (ldo > 11)
  return -EINVAL;

drivers/power/pmic/as3722.c +0 -3
-	err = as3722_read(pmic, AS3722_LDO_CONTROL, &value);
-	if (err) {
-		error("failed to read LDO control register: %d",

err);

drivers/power/pmic/as3722.c +0 -8
-		return err;
-	}
-
-	value |= 1 << ldo;
-
-	err = as3722_write(pmic, AS3722_LDO_CONTROL, value);
-	if (err < 0) {
-		error("failed to write LDO control register: %d",

err);

drivers/power/pmic/as3722.c +0 -7
-		return err;
-	}
-
-	return 0;
-}
-
-int as3722_ldo_set_voltage(struct udevice *pmic, unsigned int ldo,

u8 value)

drivers/power/pmic/as3722.c +2 -8
-{
-	int err;
-
-	if (ldo > 11)
-		return -EINVAL;
-
-	err = as3722_write(pmic, AS3722_LDO_VOLTAGE(ldo), value);
-	if (err < 0) {
+	ret = pmic_reg_write(dev, AS3722_LDO_VOLTAGE(ldo), value);
+	if (ret < 0) {

  error("failed to write LDO%u voltage register: %d", ldo,

drivers/power/pmic/as3722.c +2 -2
-		      err);
-		return err;
+		      ret);
+		return ret;

  }

  return 0;
 }

drivers/power/pmic/as3722.c +1 -2
-int as3722_gpio_configure(struct udevice *pmic, unsigned int gpio,
-			  unsigned long flags)
+static int as3722_probe(struct udevice *dev)

 {

drivers/power/pmic/as3722.c +2 -2
-	u8 value = 0;
-	int err;
+	uint id, revision;
+	int ret;

drivers/power/pmic/as3722.c +4 -10
-	if (flags & AS3722_GPIO_OUTPUT_VDDH)
-		value |= AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;
-
-	if (flags & AS3722_GPIO_INVERT)
-		value |= AS3722_GPIO_CONTROL_INVERT;
-
-	err = as3722_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
-	if (err) {
-		error("failed to configure GPIO#%u: %d", gpio, err);
-		return err;
+	ret = as3722_read_id(dev, &id, &revision);
+	if (ret < 0) {
+		error("failed to read ID: %d", ret);
+		return ret;

  }

drivers/power/pmic/as3722.c +0 -16
-	return 0;
-}
-
-static int as3722_gpio_set(struct udevice *pmic, unsigned int gpio,
-			   unsigned int level)
-{
-	const char *l;
-	u8 value;
-	int err;
-
-	if (gpio > 7)
-		return -EINVAL;
-
-	err = as3722_read(pmic, AS3722_GPIO_SIGNAL_OUT, &value);
-	if (err < 0) {
-		error("failed to read GPIO signal out register: %d",

err);

drivers/power/pmic/as3722.c +3 -9
-		return err;
-	}
-
-	if (level == 0) {
-		value &= ~(1 << gpio);
-		l = "low";
-	} else {
-		value |= 1 << gpio;
-		l = "high";
+	if (id != AS3722_DEVICE_ID) {
+		error("unknown device");
+		return -ENOENT;

  }

drivers/power/pmic/as3722.c +1 -5
-	err = as3722_write(pmic, AS3722_GPIO_SIGNAL_OUT, value);
-	if (err) {
-		error("failed to set GPIO#%u %s: %d", gpio, l, err);
-		return err;
-	}
+	debug("AS3722 revision %#x found on I2C bus %s\n", revision,

dev->name);

  return 0;
 }

-int as3722_gpio_direction_output(struct udevice *pmic, unsigned int gpio,

drivers/power/pmic/as3722.c +6 -7
-				 unsigned int level)
-{
-	u8 value;
-	int err;
-
-	if (gpio > 7)
-		return -EINVAL;
+#if CONFIG_IS_ENABLED(PMIC_CHILDREN)
+static const struct pmic_child_info pmic_children_info[] = {
+	{ .prefix = "sd", .driver = "as3722_stepdown"},
+	{ .prefix = "ldo", .driver = "as3722_ldo"},
+	{ },
+};

drivers/power/pmic/as3722.c +6 -4
-	if (level == 0)
-		value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL;
-	else
-		value = AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH;
+static int as3722_bind(struct udevice *dev)
+{
+	struct udevice *gpio_dev;
+	ofnode regulators_node;
+	int children;
+	int ret;

drivers/power/pmic/as3722.c +0 -3
-	err = as3722_write(pmic, AS3722_GPIO_CONTROL(gpio), value);
-	if (err) {
-		error("failed to configure GPIO#%u as output: %d",

gpio, err);

drivers/power/pmic/as3722.c +3 -1
-		return err;
+	regulators_node = dev_read_subnode(dev, "regulators");
+	if (!ofnode_valid(regulators_node)) {
+		debug("%s: %s regulators subnode not found\n",

__func__,

drivers/power/pmic/as3722.c +2 -0
+		      dev->name);
+		return -ENXIO;

  }

drivers/power/pmic/as3722.c +1 -4
-	err = as3722_gpio_set(pmic, gpio, level);
-	if (err < 0) {
-		error("failed to set GPIO#%u high: %d", gpio, err);
-		return err;
+	children = pmic_bind_children(dev, regulators_node,

pmic_children_info);

drivers/power/pmic/as3722.c +2 -0
+	if (!children)
+		debug("%s: %s - no child found\n", __func__, dev-
Quoted 1 line

name);

drivers/power/pmic/as3722.c +1 -0
+	ret = device_bind_driver(dev, "gpio_as3722", "gpio_as3722",

&gpio_dev);

drivers/power/pmic/as3722.c +2 -0
+	if (ret) {
+		debug("%s: Cannot bind GPIOs (ret=%d)\n", __func__,

ret);

drivers/power/pmic/as3722.c +1 -0
+		return ret;

  }

  return 0;
 }
+#endif

drivers/power/pmic/as3722.c +1 -2
-/* Temporary function until we get the pmic framework */
-int as3722_get(struct udevice **devp)
+static int as3722_reg_count(struct udevice *dev)

 {

drivers/power/pmic/as3722.c +1 -4
-	int bus = 0;
-	int address = 0x40;
-
-	return i2c_get_chip_for_busnum(bus, address, 1, devp);
+	return AS3722_NUM_OF_REGS;

 }

drivers/power/pmic/as3722.c +0 -23
-int as3722_init(struct udevice **devp)
-{
-	struct udevice *pmic;
-	u8 id, revision;
-	const unsigned int bus = 0;
-	const unsigned int address = 0x40;
-	int err;
-
-	err = i2c_get_chip_for_busnum(bus, address, 1, &pmic);
-	if (err)
-		return err;
-	err = as3722_read_id(pmic, &id, &revision);
-	if (err < 0) {
-		error("failed to read ID: %d", err);
-		return err;
-	}
-
-	if (id != AS3722_DEVICE_ID) {
-		error("unknown device");
-		return -ENOENT;
-	}
-
-	debug("AS3722 revision %#x found on I2C bus %u, address

%#x\n",

drivers/power/pmic/as3722.c +21 -6
-	      revision, bus, address);
-	if (devp)
-		*devp = pmic;
-
-	return 0;
-}
+static struct dm_pmic_ops as3722_ops = {
+	.reg_count = as3722_reg_count,
+	.read = as3722_read,
+	.write = as3722_write,
+};
+
+static const struct udevice_id as3722_ids[] = {
+	{ .compatible = "ams,as3722" },
+	{ }
+};
+
+U_BOOT_DRIVER(pmic_as3722) = {
+	.name = "as3722_pmic",
+	.id = UCLASS_PMIC,
+	.of_match = as3722_ids,
+#if CONFIG_IS_ENABLED(PMIC_CHILDREN)
+	.bind = as3722_bind,
+#endif
+	.probe = as3722_probe,
+	.ops = &as3722_ops,
+};
include/power/as3722.h +0 -0
index 713e79840f..491f1b7ea7 100644
@@ -7,8 +7,6 @@
  #ifndef __POWER_AS3722_H__
  #define __POWER_AS3722_H__

include/power/as3722.h +0 -2
-#include <asm/types.h>
-

 #define AS3722_GPIO_OUTPUT_VDDH (1 << 0)
 #define AS3722_GPIO_INVERT (1 << 1)

include/power/as3722.h +0 -0
@@ -21,23 +19,9 @@
  #define AS3722_ASIC_ID2 0x91


 #define AS3722_GPIO_CONTROL(n) (0x08 + (n)) +#define AS3722_GPIO_SIGNAL_OUT 0x20
 #define AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDH (1 << 0) #define AS3722_GPIO_CONTROL_MODE_OUTPUT_VDDL (7 << 0) #define AS3722_GPIO_CONTROL_INVERT (1 << 7)

include/power/as3722.h +0 -5
-struct udevice;
-
-int as3722_init(struct udevice **devp);
-int as3722_sd_enable(struct udevice *pmic, unsigned int sd);
-int as3722_sd_set_voltage(struct udevice *pmic, unsigned int sd, u8

value);

include/power/as3722.h +0 -2
-int as3722_ldo_enable(struct udevice *pmic, unsigned int ldo);
-int as3722_ldo_set_voltage(struct udevice *pmic, unsigned int ldo,

u8 value);

include/power/as3722.h +0 -3
-int as3722_gpio_configure(struct udevice *pmic, unsigned int gpio,
-			  unsigned long flags);
-int as3722_gpio_direction_output(struct udevice *pmic, unsigned int

gpio,

include/power/as3722.h +0 -5
-				 unsigned int level);
-int as3722_read(struct udevice *pmic, u8 reg, u8 *value);
-int as3722_write(struct udevice *pmic, u8 reg, u8 value);
-int as3722_get(struct udevice **devp);
-

 #endif /* __POWER_AS3722_H__ */

#20 lore raw

PATCH v4 18/20 dm: power: Convert as3722 to driver model

Hi Marcel,

Quoted 30 lines · Marcel Ziswiler
Quoted 29 lines · Simon Glass

Convert this PMIC driver to driver model and fix up other users. The regulator and GPIO functions are now handled by separate drivers.

Update nyan-big to work correct. Three boards will need to be updated by
the maintainers: apalis-tk1, jetson-tk1, cei-tk1-som

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/mach-tegra/board2.c          |   6 -
 board/cei/cei-tk1-som/cei-tk1-som.c   |   2 +
 board/nvidia/jetson-tk1/jetson-tk1.c  |   2 +
 board/nvidia/nyan-big/nyan-big.c      |  22 +--
 board/toradex/apalis-tk1/apalis-tk1.c |   6 +
 configs/apalis-tk1_defconfig          |   3 +
 configs/cei-tk1-som_defconfig         |   3 +
 configs/jetson-tk1_defconfig          |   3 +
 configs/nyan-big_defconfig            |   1 +
 drivers/power/pmic/Makefile           |   2 +-
 drivers/power/pmic/as3722.c           | 292 ++++++++++++----------
------------
 include/power/as3722.h                |  18 +--
 12 files changed, 133 insertions(+), 227 deletions(-)

[..]

Quoted 4 lines
Quoted 4 lines
board/nvidia/jetson-tk1/jetson-tk1.c +0 -1
index a66b710cdd..48272d086c 100644
--- a/board/nvidia/jetson-tk1/jetson-tk1.c
Quoted 8 lines

board/nvidia/jetson-tk1/jetson-tk1.c void pinmux_init(void) · line 42

Quoted 6 lines

+++ b/board/nvidia/jetson-tk1/jetson-tk1.c

board/nvidia/jetson-tk1/jetson-tk1.c +1 -0
@@ -39,6 +39,7 @@ void pinmux_init(void)
 #ifdef CONFIG_PCI_TEGRA
 int tegra_pcie_board_init(void)
 {
+/* TODO: Convert to driver model

Is that still applicable or how was that one solved at the end?

I'm going to add back the work-around code in v5. But this code still need porting to DM. I am hoping that someone else can take on this work.

Quoted 4 lines
Quoted 4 lines
board/nvidia/jetson-tk1/jetson-tk1.c +0 -0
      struct udevice *pmic;
      int err;
 
Quoted 8 lines

board/nvidia/jetson-tk1/jetson-tk1.c int tegra_pcie_board_init(void) · line 66

Quoted 8 lines
board/nvidia/jetson-tk1/jetson-tk1.c +1 -0
@@ -59,6 +60,7 @@ int tegra_pcie_board_init(void)
              error("failed to set SD4 voltage: %d\n", err);
              return err;
      }
+*/
 
      return 0;
 }

Regards,
Simon

#21 lore raw

PATCH v4 19/20 fdtdec: Drop old compatible values

In reply to Simon Glass

These are not needed now since the drivers now use driver model. Drop them.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/fdtdec.h | 6 ------
 lib/fdtdec.c     | 6 ------
 2 files changed, 12 deletions(-)
include/fdtdec.h +0 -6
index eda2ffaf66..4a0947c626 100644
@@ -119,12 +119,6 @@ enum fdt_compat_id {
 	COMPAT_NVIDIA_TEGRA20_EMC,	/* Tegra20 memory controller */
 	COMPAT_NVIDIA_TEGRA20_EMC_TABLE, /* Tegra20 memory timing table */
 	COMPAT_NVIDIA_TEGRA20_NAND,	/* Tegra2 NAND controller */
-	COMPAT_NVIDIA_TEGRA124_PMC,	/* Tegra 124 power mgmt controller */
-	COMPAT_NVIDIA_TEGRA186_SDMMC,	/* Tegra186 SDMMC controller */
-	COMPAT_NVIDIA_TEGRA210_SDMMC,	/* Tegra210 SDMMC controller */
-	COMPAT_NVIDIA_TEGRA124_SDMMC,	/* Tegra124 SDMMC controller */
-	COMPAT_NVIDIA_TEGRA30_SDMMC,	/* Tegra30 SDMMC controller */
-	COMPAT_NVIDIA_TEGRA20_SDMMC,	/* Tegra20 SDMMC controller */
 	COMPAT_NVIDIA_TEGRA124_XUSB_PADCTL,
 					/* Tegra124 XUSB pad controller */
 	COMPAT_NVIDIA_TEGRA210_XUSB_PADCTL,
lib/fdtdec.c +0 -6
index fbb48bf74d..d2dbd0f122 100644
@@ -34,12 +34,6 @@ static const char * const compat_names[COMPAT_COUNT] = {
 	COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"),
 	COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"),
 	COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"),
-	COMPAT(NVIDIA_TEGRA124_PMC, "nvidia,tegra124-pmc"),
-	COMPAT(NVIDIA_TEGRA186_SDMMC, "nvidia,tegra186-sdhci"),
-	COMPAT(NVIDIA_TEGRA210_SDMMC, "nvidia,tegra210-sdhci"),
-	COMPAT(NVIDIA_TEGRA124_SDMMC, "nvidia,tegra124-sdhci"),
-	COMPAT(NVIDIA_TEGRA30_SDMMC, "nvidia,tegra30-sdhci"),
-	COMPAT(NVIDIA_TEGRA20_SDMMC, "nvidia,tegra20-sdhci"),
 	COMPAT(NVIDIA_TEGRA124_XUSB_PADCTL, "nvidia,tegra124-xusb-padctl"),
 	COMPAT(NVIDIA_TEGRA210_XUSB_PADCTL, "nvidia,tegra210-xusb-padctl"),
 	COMPAT(SMSC_LAN9215, "smsc,lan9215"),
Signature · 1 line
2.13.2.932.g7449e964c-goog
#22 lore raw

PATCH v4 20/20 dm: tegra: Move nyan-big, jetson-tk1/tx1, beaver to livetree

In reply to Simon Glass

Change these board to use a live device tree after relocation.

- Enable livetree for jetson-tk1 also

---

Changes in v4:
- Rebase to master
- Drop changes already applied
- Fix PCI and i2c init problems on jetson-tx1

Changes in v3:
- Enable livetree for jetson-tk1 also

Changes in v2:
- Enable livetree for beaver also
- Add timing information

 configs/beaver_defconfig     | 1 +
 configs/jetson-tk1_defconfig | 1 +
 configs/nyan-big_defconfig   | 1 +
 configs/p2371-2180_defconfig | 1 +
 4 files changed, 4 insertions(+)
configs/beaver_defconfig +1 -0
index 71d6cd52c1..10fd50d925 100644
@@ -25,6 +25,7 @@ CONFIG_CMD_EXT4_WRITE=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_OF_LIVE=y
 CONFIG_SPL_DM=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
configs/jetson-tk1_defconfig +1 -0
index d086951299..a533c6402f 100644
@@ -25,6 +25,7 @@ CONFIG_CMD_EXT4_WRITE=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_OF_LIVE=y
 CONFIG_SPL_DM=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
configs/nyan-big_defconfig +1 -0
index 8e11c2f15c..f62ebac04d 100644
@@ -37,6 +37,7 @@ CONFIG_CMD_EXT4_WRITE=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_ISO_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_OF_LIVE=y
 CONFIG_SPL_DM=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
configs/p2371-2180_defconfig +1 -0
index d04f052355..4345fb070a 100644
@@ -22,6 +22,7 @@ CONFIG_CMD_GPIO=y
 # CONFIG_CMD_SETEXPR is not set
 # CONFIG_CMD_NFS is not set
 CONFIG_CMD_EXT4_WRITE=y
+CONFIG_OF_LIVE=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
 CONFIG_DFU_SF=y
Signature · 1 line
2.13.2.932.g7449e964c-goog
#23 lore raw

v4 cover dm: tegra: Move nyan-big, jetson-tk1, beaver to livetree

In reply to Simon Glass
Quoted 63 lines · Simon Glass

This moves four entire boards to use a live device tree as an example of
the impact.

Nyan-big was chosen because I can easily and boot U-Boot without any media swapping, etc. Beaver is enabled as well since it failed to boot
with serial v1 due to a disabled console node. Jetson-TK1 is chosen because I found some USB problems in the v2 patches. Jetson-TX1 is added
because Stephen Warren found some problems with PCI.

Total code size impact on this board is approximately 9KB on U-Boot and
64 bytes on SPL:

27: dm: tegra: nyan-big: Move to livetree
       arm: (for 1/1 boards) all +9264.0 bss -16.0 data +44.0 rodata +92.0
          spl/u-boot-spl:all +326.0 spl/u-boot-spl:rodata +262.0 spl/u-boot-spl:text +64.0 text +9144.0

Tegra does not use Thumb2, which would likely reduce the code size by about
25%, indicating a code-size impact of perhaps 7KB.

Boot time is affected slightly. For nyan-big the times with flat tree are:

                 2,108  dm_r
                 7,924  dm_spl
               120,724  dm_f
               171,816  lcd

With the livetree:

                   721  dm_r
                 3,764  of_live
                 7,990  dm_spl
               120,736  dm_f
               168,215  lcd

As expected the spl and pre-relocation times are not affected. In the post-relocation case, the live tree must be built, which here takes about
3.8ms. Driver-model device creation takes a bit of 1ms less time with the
livetree, so all up the cost is about 2.4ms. After DM init there appears
to be a slight reduction in the time taken to set up devices (from 327ms
to 319ms) so overall the live tree does not appear to be any slower. This
is because pre-parsing the device tree makes reading it later faster.

The use of livetree is controlled by a the CONFIG_OF_LIVE option. When
enabled, U-Boot builds a livetree immediately after relocation and uses
it from then on.

This series is available at u-boot-dm/livet-working

Quoted 9 lines

Changes in v4:
- Add new patch to add ofnode_read_resource()
- Add new patch to fix up ofnode_get_addr_index() for 64-bit values
- Update to use ofnode_read_resource()
- Drop fdtdec.h header
- Update to deal with rename of ofnode_read_prop()
- Rebase to master
- Drop changes already applied
- Fix PCI and i2c init problems on jetson-tx1

Could you elaborate a little bit more on this as from the actual patch set I don't seem to be able to figure out how/what exactly you did in that respect.

Other than that it at least works for me on my Beaver and Jetson TK1 so you may add the following to the whole series:

Tested-on: Beaver, Jetson-TK1

Quoted 89 lines

Changes in v3:
- Update commit message, enable for all tegra124 boards not just nyan-big
- Add new patch to convert tegra PCI to device tree
- Enable livetree for jetson-tk1 also

Changes in v2:
- Enable livetree for beaver also
- Add timing information

Simon Glass (20):
  dm: core: Add ofnode_read_resource()
  dm: core: Fix up ofnode_get_addr_index() for 64-bit values
  tegra: spl: Enable debug UART
  tegra: tegra124: Add a PMC syscon driver
  dm: tegra: Convert USB setup to livetree
  dm: tegra: Convert clock_decode_periph_id() to support livetree
  dm: video: tegra124: Convert to livetree
  tegra: dts: Move stdout-path to /chosen
  dm: tegra: gpio: Convert to support livetree
  dm: tegra: usb: Convert to livetree
  dm: tegra: spi: Convert to livetree
  dm: tegra: i2c: Convert to livetree
  dm: tegra: pwm: Convert to livetree
  dm: tegra: mmc: Convert to livetree
  dm: tegra: pci: Convert to livetree
  power: Add a regulator driver for the as3722 PMIC
  power: Add a GPIO driver for the as3722 PMIC
  dm: power: Convert as3722 to driver model
  fdtdec: Drop old compatible values
  dm: tegra: Move nyan-big, jetson-tk1/tx1, beaver to livetree

 arch/arm/dts/tegra124-nyan-big.dts            |   5 +- arch/arm/include/asm/arch-tegra/clock.h       |   2 +- arch/arm/include/asm/arch-tegra/tegra.h       |   5 + arch/arm/include/asm/arch-tegra/xusb-padctl.h |   2 +- arch/arm/mach-tegra/Kconfig                   |   2 + arch/arm/mach-tegra/board2.c                  |   8 +- arch/arm/mach-tegra/clock.c                   |   5 +- arch/arm/mach-tegra/spl.c                     |   4 + arch/arm/mach-tegra/tegra124/Makefile         |   1 + arch/arm/mach-tegra/tegra124/pmc.c            |  19 ++ arch/arm/mach-tegra/tegra124/xusb-padctl.c    |  36 +++- arch/arm/mach-tegra/tegra210/xusb-padctl.c    |  42 +++- arch/arm/mach-tegra/xusb-padctl-common.c      |  60 +++--- arch/arm/mach-tegra/xusb-padctl-common.h      |   8 +- arch/arm/mach-tegra/xusb-padctl-dummy.c       |   2 +- board/cei/cei-tk1-som/cei-tk1-som.c           |   2 + board/nvidia/jetson-tk1/jetson-tk1.c          |   2 + board/nvidia/nyan-big/nyan-big.c              |  22 +- board/toradex/apalis-tk1/apalis-tk1.c         |   6 + configs/apalis-tk1_defconfig                  |   3 + configs/beaver_defconfig                      |   1 + configs/cei-tk1-som_defconfig                 |   3 + configs/jetson-tk1_defconfig                  |   4 + configs/nyan-big_defconfig                    |   2 + configs/p2371-2180_defconfig                  |   1 + drivers/core/ofnode.c                         |  30 ++- drivers/core/read.c                           |   5 + drivers/core/read_extra.c                     |  25 +-- drivers/gpio/tegra_gpio.c                     |  10 +-

 drivers/i2c/tegra_i2c.c                       |   7 +-
 drivers/mmc/tegra_mmc.c                       |  17 +-
 drivers/pci/pci_tegra.c                       |  53 +++--

 drivers/power/pmic/Makefile                   |   2 +- drivers/power/pmic/as3722.c                   | 292 +++++++++-------
----------
 drivers/power/pmic/as3722_gpio.c              | 120 +++++++++++ drivers/power/regulator/Kconfig               |   9 + drivers/power/regulator/Makefile              |   1 + drivers/power/regulator/as3722_regulator.c    | 149 +++++++++++++ drivers/pwm/tegra_pwm.c                       |   2 +- drivers/spi/tegra114_spi.c                    |  15 +- drivers/spi/tegra20_sflash.c                  |   2 +- drivers/spi/tegra20_slink.c                   |   2 +- drivers/spi/tegra210_qspi.c                   |   2 +- drivers/usb/host/ehci-tegra.c                 |  36 ++-- drivers/video/tegra124/display.c              |   8 +- drivers/video/tegra124/dp.c                   |   3 +- drivers/video/tegra124/sor.c                  |  25 +-- include/dm/ofnode.h                           |   4 + include/dm/read.h                             |  26 ++- include/fdtdec.h                              |   6 - include/power/as3722.h                        |  27 ++- lib/fdtdec.c                                  |   6 -

 52 files changed, 698 insertions(+), 433 deletions(-)

 create mode 100644 arch/arm/mach-tegra/tegra124/pmc.c create mode 100644 drivers/power/pmic/as3722_gpio.c create mode 100644 drivers/power/regulator/as3722_regulator.c

#24 lore raw

v4 cover dm: tegra: Move nyan-big, jetson-tk1, beaver to livetree

Hi Marcel,

Quoted 78 lines · Marcel Ziswiler
Quoted 63 lines · Simon Glass

This moves four entire boards to use a live device tree as an example of
the impact.

Nyan-big was chosen because I can easily and boot U-Boot without any media swapping, etc. Beaver is enabled as well since it failed to boot
with serial v1 due to a disabled console node. Jetson-TK1 is chosen because I found some USB problems in the v2 patches. Jetson-TX1 is added
because Stephen Warren found some problems with PCI.

Total code size impact on this board is approximately 9KB on U-Boot and
64 bytes on SPL:

27: dm: tegra: nyan-big: Move to livetree

       arm: (for 1/1 boards) all +9264.0 bss -16.0 data +44.0 rodata
+92.0
          spl/u-boot-spl:all +326.0 spl/u-boot-spl:rodata +262.0
          spl/u-boot-spl:text +64.0 text +9144.0

Tegra does not use Thumb2, which would likely reduce the code size by about
25%, indicating a code-size impact of perhaps 7KB.

Boot time is affected slightly. For nyan-big the times with flat tree are:

                 2,108  dm_r
                 7,924  dm_spl
               120,724  dm_f
               171,816  lcd

With the livetree:

                   721  dm_r
                 3,764  of_live
                 7,990  dm_spl
               120,736  dm_f
               168,215  lcd

As expected the spl and pre-relocation times are not affected. In the post-relocation case, the live tree must be built, which here takes about
3.8ms. Driver-model device creation takes a bit of 1ms less time with the
livetree, so all up the cost is about 2.4ms. After DM init there appears
to be a slight reduction in the time taken to set up devices (from 327ms
to 319ms) so overall the live tree does not appear to be any slower. This
is because pre-parsing the device tree makes reading it later faster.

The use of livetree is controlled by a the CONFIG_OF_LIVE option. When
enabled, U-Boot builds a livetree immediately after relocation and uses
it from then on.

This series is available at u-boot-dm/livet-working

Quoted 9 lines

Changes in v4:
- Add new patch to add ofnode_read_resource()
- Add new patch to fix up ofnode_get_addr_index() for 64-bit values
- Update to use ofnode_read_resource()
- Drop fdtdec.h header
- Update to deal with rename of ofnode_read_prop()
- Rebase to master
- Drop changes already applied
- Fix PCI and i2c init problems on jetson-tx1

Could you elaborate a little bit more on this as from the actual patch set I don't seem to be able to figure out how/what exactly you did in that respect.

Quoted 5 lines

Other than that it at least works for me on my Beaver and Jetson TK1 so you may add the following to the whole series:

Tested-on: Beaver, Jetson-TK1

Thanks.

I cannot test Jetson-TK1 yet but I think these changes are needed to make USB work, and possibly PCI:

Quoted 2 lines
Quoted 2 lines

- Add new patch to add ofnode_read_resource()
- Update to use ofnode_read_resource()

(see the appropriate patches with these changes mentioned in the change log)

Basically the code for setting up the USB PHY did not work and that stopped PCI from working, I believe.

The changes applicable to TX1 are:

Quoted 1 line
Quoted 1 line

- Add new patch to fix up ofnode_get_addr_index() for 64-bit values

(this fixed I2C reading the register address)

[..]

Regards,
Simon

#25 lore raw

v4 cover dm: tegra: Move nyan-big, jetson-tk1, beaver to livetree

Hi Simon

Quoted 100 lines · Simon Glass

Hi Marcel,

Quoted 96 lines · Marcel Ziswiler
Quoted 78 lines · Simon Glass

This moves four entire boards to use a live device tree as an example
of
the impact.

Nyan-big was chosen because I can easily and boot U-Boot without any
media swapping, etc. Beaver is enabled as well since it failed to boot
with serial v1 due to a disabled console node. Jetson-TK1 is chosen
because I found some USB problems in the v2 patches. Jetson-TX1 is
added
because Stephen Warren found some problems with PCI.

Total code size impact on this board is approximately 9KB on U- Boot
and
64 bytes on SPL:

27: dm: tegra: nyan-big: Move to livetree
       arm: (for 1/1 boards) all +9264.0 bss -16.0 data +44.0 rodata
+92.0
          spl/u-boot-spl:all +326.0 spl/u-boot-spl:rodata +262.0 spl/u-boot-spl:text +64.0 text +9144.0

Tegra does not use Thumb2, which would likely reduce the code size by
about
25%, indicating a code-size impact of perhaps 7KB.

Boot time is affected slightly. For nyan-big the times with flat tree
are:

                 2,108  dm_r
                 7,924  dm_spl
               120,724  dm_f
               171,816  lcd

With the livetree:

                   721  dm_r
                 3,764  of_live
                 7,990  dm_spl
               120,736  dm_f
               168,215  lcd

As expected the spl and pre-relocation times are not affected. In the
post-relocation case, the live tree must be built, which here takes
about
3.8ms. Driver-model device creation takes a bit of 1ms less time with
the
livetree, so all up the cost is about 2.4ms. After DM init there appears
to be a slight reduction in the time taken to set up devices (from
327ms
to 319ms) so overall the live tree does not appear to be any slower.
This
is because pre-parsing the device tree makes reading it later faster.

The use of livetree is controlled by a the CONFIG_OF_LIVE option. When
enabled, U-Boot builds a livetree immediately after relocation and
uses
it from then on.

This series is available at u-boot-dm/livet-working

Quoted 10 lines

Changes in v4:
- Add new patch to add ofnode_read_resource()
- Add new patch to fix up ofnode_get_addr_index() for 64-bit values
- Update to use ofnode_read_resource()
- Drop fdtdec.h header
- Update to deal with rename of ofnode_read_prop()
- Rebase to master
- Drop changes already applied
- Fix PCI and i2c init problems on jetson-tx1

Could you elaborate a little bit more on this as from the actual patch
set I don't seem to be able to figure out how/what exactly you did in
that respect.

Quoted 8 lines
Quoted 6 lines

Other than that it at least works for me on my Beaver and Jetson TK1 so
you may add the following to the whole series:

Tested-on: Beaver, Jetson-TK1

Thanks.

You are very welcome.

Quoted 8 lines

I cannot test Jetson-TK1 yet but I think these changes are needed to make USB work, and possibly PCI:

Quoted 2 lines
Quoted 2 lines

- Add new patch to add ofnode_read_resource()
- Update to use ofnode_read_resource()

(see the appropriate patches with these changes mentioned in the change log)

OK, yeah I saw those but just could not quite make the connection.

Quoted 2 lines

Basically the code for setting up the USB PHY did not work and that stopped PCI from working, I believe.

OK, makes sense. So it was rather a high level issue then.

Quoted 6 lines

The changes applicable to TX1 are:

Quoted 2 lines
Quoted 2 lines

- Add new patch to fix up ofnode_get_addr_index() for 64-bit values

(this fixed I2C reading the register address)

Perfect, while we should have a TX1 laying around somewhere as well I currently failed finding it. Probably one of my co-workers currently on vacation took it and is playing with it (;-p).

Quoted 4 lines

[..]

Regards,
Simon

Cheers

Marcel

BTW: I'm now in the process of migrating our boards as well and will send patches for that soon.

#26 lore raw

v4 cover dm: tegra: Move nyan-big, jetson-tk1, beaver to livetree

Hi Marcel,

Quoted 132 lines · Marcel Ziswiler

Hi Simon

Quoted 100 lines · Simon Glass

Hi Marcel,

Quoted 96 lines · Marcel Ziswiler
Quoted 78 lines · Simon Glass

This moves four entire boards to use a live device tree as an example
of
the impact.

Nyan-big was chosen because I can easily and boot U-Boot without any
media swapping, etc. Beaver is enabled as well since it failed to boot
with serial v1 due to a disabled console node. Jetson-TK1 is chosen
because I found some USB problems in the v2 patches. Jetson-TX1 is
added
because Stephen Warren found some problems with PCI.

Total code size impact on this board is approximately 9KB on U- Boot
and
64 bytes on SPL:

27: dm: tegra: nyan-big: Move to livetree

       arm: (for 1/1 boards) all +9264.0 bss -16.0 data +44.0
rodata
+92.0
          spl/u-boot-spl:all +326.0 spl/u-boot-spl:rodata +262.0
          spl/u-boot-spl:text +64.0 text +9144.0

Tegra does not use Thumb2, which would likely reduce the code size by
about
25%, indicating a code-size impact of perhaps 7KB.

Boot time is affected slightly. For nyan-big the times with flat tree
are:

                 2,108  dm_r
                 7,924  dm_spl
               120,724  dm_f
               171,816  lcd

With the livetree:

                   721  dm_r
                 3,764  of_live
                 7,990  dm_spl
               120,736  dm_f
               168,215  lcd

As expected the spl and pre-relocation times are not affected. In the
post-relocation case, the live tree must be built, which here takes
about
3.8ms. Driver-model device creation takes a bit of 1ms less time with
the
livetree, so all up the cost is about 2.4ms. After DM init there appears
to be a slight reduction in the time taken to set up devices (from
327ms
to 319ms) so overall the live tree does not appear to be any slower.
This
is because pre-parsing the device tree makes reading it later faster.

The use of livetree is controlled by a the CONFIG_OF_LIVE option. When
enabled, U-Boot builds a livetree immediately after relocation and
uses
it from then on.

This series is available at u-boot-dm/livet-working

Quoted 10 lines

Changes in v4:
- Add new patch to add ofnode_read_resource()
- Add new patch to fix up ofnode_get_addr_index() for 64-bit values
- Update to use ofnode_read_resource()
- Drop fdtdec.h header
- Update to deal with rename of ofnode_read_prop()
- Rebase to master
- Drop changes already applied
- Fix PCI and i2c init problems on jetson-tx1

Could you elaborate a little bit more on this as from the actual patch
set I don't seem to be able to figure out how/what exactly you did in
that respect.

Quoted 8 lines
Quoted 6 lines

Other than that it at least works for me on my Beaver and Jetson TK1 so
you may add the following to the whole series:

Tested-on: Beaver, Jetson-TK1

Thanks.

You are very welcome.

Quoted 8 lines

I cannot test Jetson-TK1 yet but I think these changes are needed to make USB work, and possibly PCI:

Quoted 2 lines
Quoted 2 lines

- Add new patch to add ofnode_read_resource()
- Update to use ofnode_read_resource()

(see the appropriate patches with these changes mentioned in the change log)

OK, yeah I saw those but just could not quite make the connection.

Quoted 2 lines

Basically the code for setting up the USB PHY did not work and that stopped PCI from working, I believe.

OK, makes sense. So it was rather a high level issue then.

Quoted 2 lines

The changes applicable to TX1 are:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

- Add new patch to fix up ofnode_get_addr_index() for 64-bit values

(this fixed I2C reading the register address)

Perfect, while we should have a TX1 laying around somewhere as well I currently failed finding it. Probably one of my co-workers currently on vacation took it and is playing with it (;-p).

I just tried TK1 (a new board) and hit some problems with PCI even with this version of the series, so I need to figure that out (later in the week).

Quoted 11 lines
Quoted 5 lines

[..]

Regards,
Simon

Cheers

Marcel

BTW: I'm now in the process of migrating our boards as well and will send patches for that soon.

Regards,
Smion