public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL
@ 2014-10-23 19:15 Simon Glass
  2014-10-23 19:15 ` [U-Boot] [PATCH v2 01/13] dm: dts: Move omap device tree includes to correct place Simon Glass
                   ` (12 more replies)
  0 siblings, 13 replies; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:15 UTC (permalink / raw)
  To: u-boot

Now that driver model operations prior to relocation, the remaining
area where it does not work is SPL. This series enables this.

Since SPL is quite memory-constrained, code and data size need to be
kept as small as possible. This series includes a few changes to help
with this:

- Small and simple malloc() implementation
- Dropping device removal features
- Dropping stdio features
- Dropping driver model warnings

With these the code size impact of driver model is small, around 2-3KB.
Data usage is typically 200-300 bytes. In many cases this can squeeze
into the available SPL RAM space.

This requires a revert of the SPL global_data revert (commit 1ee30ae).
I believe that is planned for early in this merge window. We need that
revert undone to be able to support the simple malloc in SPL on ARM.

This series is available at u-boot-dm branch 'spl-working'.

Changes in v2:
- Correct the Makefile condition for simple_malloc
- Rebase on top of the SPI series
- Rebase to master

Simon Glass (13):
  dm: dts: Move omap device tree includes to correct place
  dm: Split the simple malloc() implementation into its own file
  dm: arm: spl: Allow simple malloc() in SPL
  dm: spl: Make simple malloc() available when enabled
  dm: spl: Allow driver model to be used
  dm: Allow device removal features to be dropped
  dm: Allow stdio registration to be dropped
  dm: Disable dm_warn() in SPL
  dm: tegra: Add platform data for the SPL uart
  dm: tegra: Add platform data for the GPIO driver
  dm: arm: spl: Make driver model linker lists available
  dm: tegra: Enable driver model in SPL and adjust the GPIO driver
  dm: Update documentation to include CONFIG_DM... options

 README                                             | 119 +++++++++++++
 arch/arm/cpu/u-boot-spl.lds                        |   7 +
 arch/arm/dts/dt-bindings/gpio/gpio.h               |  15 --
 arch/arm/lib/crt0.S                                |   2 +-
 board/nvidia/common/board.c                        |   8 +
 board/nvidia/seaboard/seaboard.c                   |   4 +-
 common/Makefile                                    |   3 +
 common/board_r.c                                   |   3 +-
 common/dlmalloc.c                                  |  19 +--
 common/malloc_simple.c                             |  38 +++++
 common/spl/spl.c                                   |  16 +-
 doc/driver-model/README.txt                        |  44 +++--
 drivers/core/Makefile                              |   3 +-
 drivers/core/device-remove.c                       | 187 +++++++++++++++++++++
 drivers/core/device.c                              | 168 ------------------
 drivers/gpio/Makefile                              |   4 +
 drivers/gpio/tegra_gpio.c                          |  27 ++-
 drivers/serial/serial-uclass.c                     |   8 +-
 drivers/serial/serial_tegra.c                      |  16 ++
 include/asm-generic/global_data.h                  |   1 +
 include/config_defaults.h                          |   6 +
 include/configs/tegra-common.h                     |  12 +-
 include/dm/device-internal.h                       |  10 ++
 include/dm/util.h                                  |   6 +
 .../dts => include}/dt-bindings/pinctrl/am33xx.h   |   0
 .../arm/dts => include}/dt-bindings/pinctrl/omap.h |   0
 include/malloc.h                                   |  60 ++++---
 scripts/Makefile.spl                               |   1 +
 28 files changed, 522 insertions(+), 265 deletions(-)
 delete mode 100644 arch/arm/dts/dt-bindings/gpio/gpio.h
 create mode 100644 common/malloc_simple.c
 create mode 100644 drivers/core/device-remove.c
 rename {arch/arm/dts => include}/dt-bindings/pinctrl/am33xx.h (100%)
 rename {arch/arm/dts => include}/dt-bindings/pinctrl/omap.h (100%)

-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 01/13] dm: dts: Move omap device tree includes to correct place
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
@ 2014-10-23 19:15 ` Simon Glass
  2014-10-24 19:05   ` Tom Rini
  2014-10-23 19:15 ` [U-Boot] [PATCH v2 02/13] dm: Split the simple malloc() implementation into its own file Simon Glass
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:15 UTC (permalink / raw)
  To: u-boot

These ended up in arch/arm/dts/dt-bindings temporarily, but in fact the
correct place is now include/dt-bindings. Move them to be consistent.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 arch/arm/dts/dt-bindings/gpio/gpio.h                   | 15 ---------------
 {arch/arm/dts => include}/dt-bindings/pinctrl/am33xx.h |  0
 {arch/arm/dts => include}/dt-bindings/pinctrl/omap.h   |  0
 3 files changed, 15 deletions(-)
 delete mode 100644 arch/arm/dts/dt-bindings/gpio/gpio.h
 rename {arch/arm/dts => include}/dt-bindings/pinctrl/am33xx.h (100%)
 rename {arch/arm/dts => include}/dt-bindings/pinctrl/omap.h (100%)

diff --git a/arch/arm/dts/dt-bindings/gpio/gpio.h b/arch/arm/dts/dt-bindings/gpio/gpio.h
deleted file mode 100644
index e6b1e0a..0000000
--- a/arch/arm/dts/dt-bindings/gpio/gpio.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * This header provides constants for most GPIO bindings.
- *
- * Most GPIO bindings include a flags cell as part of the GPIO specifier.
- * In most cases, the format of the flags cell uses the standard values
- * defined in this header.
- */
-
-#ifndef _DT_BINDINGS_GPIO_GPIO_H
-#define _DT_BINDINGS_GPIO_GPIO_H
-
-#define GPIO_ACTIVE_HIGH 0
-#define GPIO_ACTIVE_LOW 1
-
-#endif
diff --git a/arch/arm/dts/dt-bindings/pinctrl/am33xx.h b/include/dt-bindings/pinctrl/am33xx.h
similarity index 100%
rename from arch/arm/dts/dt-bindings/pinctrl/am33xx.h
rename to include/dt-bindings/pinctrl/am33xx.h
diff --git a/arch/arm/dts/dt-bindings/pinctrl/omap.h b/include/dt-bindings/pinctrl/omap.h
similarity index 100%
rename from arch/arm/dts/dt-bindings/pinctrl/omap.h
rename to include/dt-bindings/pinctrl/omap.h
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 02/13] dm: Split the simple malloc() implementation into its own file
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
  2014-10-23 19:15 ` [U-Boot] [PATCH v2 01/13] dm: dts: Move omap device tree includes to correct place Simon Glass
@ 2014-10-23 19:15 ` Simon Glass
  2014-10-24 19:05   ` Tom Rini
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 03/13] dm: arm: spl: Allow simple malloc() in SPL Simon Glass
                   ` (10 subsequent siblings)
  12 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:15 UTC (permalink / raw)
  To: u-boot

The simple malloc() implementation is used when memory is tight. It provides
a simple buffer with an incrementing pointer.

At present the implementation is inside dlmalloc. Move it into its own file
so that it is easier to find.

Rather than using relocation as a signal that the full malloc() is
available, add a special GD_FLG_FULL_MALLOC_INIT flag. This signals that the
simple malloc() should no longer be used.

In some cases, such as SPL, even the code space used by the full malloc() is
wasteful. Add a CONFIG_SYS_MALLOC_SIMPLE option to provide only the simple
malloc. In this case the full malloc is not available at all. It saves about
1KB of code space and about 0.5KB of data on Thumb 2.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Correct the Makefile condition for simple_malloc

 common/Makefile                   |  3 ++
 common/board_r.c                  |  3 +-
 common/dlmalloc.c                 | 19 ++++---------
 common/malloc_simple.c            | 38 +++++++++++++++++++++++++
 include/asm-generic/global_data.h |  1 +
 include/malloc.h                  | 60 ++++++++++++++++++++++++---------------
 6 files changed, 86 insertions(+), 38 deletions(-)
 create mode 100644 common/malloc_simple.c

diff --git a/common/Makefile b/common/Makefile
index c84b3bc..ad2fc7d 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -250,6 +250,9 @@ obj-$(CONFIG_BOUNCE_BUFFER) += bouncebuf.o
 obj-y += console.o
 obj-$(CONFIG_CROS_EC) += cros_ec.o
 obj-y += dlmalloc.o
+ifdef CONFIG_SYS_MALLOC_F_LEN
+obj-y += malloc_simple.o
+endif
 obj-y += image.o
 obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o
 obj-$(CONFIG_OF_LIBFDT) += image-fdt.o
diff --git a/common/board_r.c b/common/board_r.c
index 3affb63..54e9a93 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -105,7 +105,8 @@ static int initr_trace(void)
 
 static int initr_reloc(void)
 {
-	gd->flags |= GD_FLG_RELOC;	/* tell others: relocation done */
+	/* tell others: relocation done */
+	gd->flags |= GD_FLG_RELOC | GD_FLG_FULL_MALLOC_INIT;
 	bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_R, "board_init_r");
 
 	return 0;
diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index f987339..16dc2ff 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -2181,17 +2181,8 @@ Void_t* mALLOc(bytes) size_t bytes;
   INTERNAL_SIZE_T nb;
 
 #ifdef CONFIG_SYS_MALLOC_F_LEN
-	if (!(gd->flags & GD_FLG_RELOC)) {
-		ulong new_ptr;
-		void *ptr;
-
-		new_ptr = gd->malloc_ptr + bytes;
-		if (new_ptr > gd->malloc_limit)
-			panic("Out of pre-reloc memory");
-		ptr = map_sysmem(gd->malloc_base + gd->malloc_ptr, bytes);
-		gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
-		return ptr;
-	}
+	if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT))
+		return malloc_simple(bytes);
 #endif
 
   /* check if mem_malloc_init() was run */
@@ -2459,7 +2450,7 @@ void fREe(mem) Void_t* mem;
 
 #ifdef CONFIG_SYS_MALLOC_F_LEN
 	/* free() is a no-op - all the memory will be freed on relocation */
-	if (!(gd->flags & GD_FLG_RELOC))
+	if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT))
 		return;
 #endif
 
@@ -2615,7 +2606,7 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes;
   if (oldmem == NULL) return mALLOc(bytes);
 
 #ifdef CONFIG_SYS_MALLOC_F_LEN
-	if (!(gd->flags & GD_FLG_RELOC)) {
+	if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) {
 		/* This is harder to support and should not be needed */
 		panic("pre-reloc realloc() is not supported");
 	}
@@ -2967,7 +2958,7 @@ Void_t* cALLOc(n, elem_size) size_t n; size_t elem_size;
   else
   {
 #ifdef CONFIG_SYS_MALLOC_F_LEN
-	if (!(gd->flags & GD_FLG_RELOC)) {
+	if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) {
 		MALLOC_ZERO(mem, sz);
 		return mem;
 	}
diff --git a/common/malloc_simple.c b/common/malloc_simple.c
new file mode 100644
index 0000000..bed227a
--- /dev/null
+++ b/common/malloc_simple.c
@@ -0,0 +1,38 @@
+/*
+ * Simple malloc implementation
+ *
+ * Copyright (c) 2014 Google, Inc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <malloc.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+void *malloc_simple(size_t bytes)
+{
+	ulong new_ptr;
+	void *ptr;
+
+	new_ptr = gd->malloc_ptr + bytes;
+	if (new_ptr > gd->malloc_limit)
+		panic("Out of pre-reloc memory");
+	ptr = map_sysmem(gd->malloc_base + gd->malloc_ptr, bytes);
+	gd->malloc_ptr = ALIGN(new_ptr, sizeof(new_ptr));
+	return ptr;
+}
+
+#ifdef CONFIG_SYS_MALLOC_SIMPLE
+void *calloc(size_t nmemb, size_t elem_size)
+{
+	size_t size = nmemb * elem_size;
+	void *ptr;
+
+	ptr = malloc(size);
+	memset(ptr, '\0', size);
+
+	return ptr;
+}
+#endif
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 74df210..5e5dc37 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -107,5 +107,6 @@ typedef struct global_data {
 #define GD_FLG_DISABLE_CONSOLE	0x00040	/* Disable console (in & out)	   */
 #define GD_FLG_ENV_READY	0x00080	/* Env. imported into hash table   */
 #define GD_FLG_SERIAL_READY	0x00100	/* Pre-reloc serial console ready  */
+#define GD_FLG_FULL_MALLOC_INIT	0x00200	/* Full malloc() is ready	   */
 
 #endif /* __ASM_GENERIC_GBL_DATA_H */
diff --git a/include/malloc.h b/include/malloc.h
index c33f3b4..5df6348 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -872,33 +872,46 @@ extern Void_t*     sbrk();
 
 #else
 
-#ifdef USE_DL_PREFIX
-#define cALLOc		dlcalloc
-#define fREe		dlfree
-#define mALLOc		dlmalloc
-#define mEMALIGn	dlmemalign
-#define rEALLOc		dlrealloc
-#define vALLOc		dlvalloc
-#define pvALLOc		dlpvalloc
-#define mALLINFo	dlmallinfo
-#define mALLOPt		dlmallopt
-#else /* USE_DL_PREFIX */
-#define cALLOc		calloc
-#define fREe		free
-#define mALLOc		malloc
-#define mEMALIGn	memalign
-#define rEALLOc		realloc
-#define vALLOc		valloc
-#define pvALLOc		pvalloc
-#define mALLINFo	mallinfo
-#define mALLOPt		mallopt
-#endif /* USE_DL_PREFIX */
+#ifdef CONFIG_SYS_MALLOC_SIMPLE
+#define malloc malloc_simple
+#define realloc realloc_simple
+#define memalign memalign_simple
+static inline void free(void *ptr) {}
+void *calloc(size_t nmemb, size_t size);
+void *memalign_simple(size_t alignment, size_t bytes);
+void *realloc_simple(void *ptr, size_t size);
+#else
+
+# ifdef USE_DL_PREFIX
+# define cALLOc		dlcalloc
+# define fREe		dlfree
+# define mALLOc		dlmalloc
+# define mEMALIGn	dlmemalign
+# define rEALLOc		dlrealloc
+# define vALLOc		dlvalloc
+# define pvALLOc		dlpvalloc
+# define mALLINFo	dlmallinfo
+# define mALLOPt		dlmallopt
+# else /* USE_DL_PREFIX */
+# define cALLOc		calloc
+# define fREe		free
+# define mALLOc		malloc
+# define mEMALIGn	memalign
+# define rEALLOc		realloc
+# define vALLOc		valloc
+# define pvALLOc		pvalloc
+# define mALLINFo	mallinfo
+# define mALLOPt		mallopt
+# endif /* USE_DL_PREFIX */
 
 #endif
 
 /* Public routines */
 
-#if __STD_C
+/* Simple versions which can be used when space is tight */
+void *malloc_simple(size_t size);
+
+# if __STD_C
 
 Void_t* mALLOc(size_t);
 void    fREe(Void_t*);
@@ -913,7 +926,7 @@ size_t  malloc_usable_size(Void_t*);
 void    malloc_stats(void);
 int     mALLOPt(int, int);
 struct mallinfo mALLINFo(void);
-#else
+# else
 Void_t* mALLOc();
 void    fREe();
 Void_t* rEALLOc();
@@ -927,6 +940,7 @@ size_t  malloc_usable_size();
 void    malloc_stats();
 int     mALLOPt();
 struct mallinfo mALLINFo();
+# endif
 #endif
 
 /*
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 03/13] dm: arm: spl: Allow simple malloc() in SPL
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
  2014-10-23 19:15 ` [U-Boot] [PATCH v2 01/13] dm: dts: Move omap device tree includes to correct place Simon Glass
  2014-10-23 19:15 ` [U-Boot] [PATCH v2 02/13] dm: Split the simple malloc() implementation into its own file Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 04/13] dm: spl: Make simple malloc() available when enabled Simon Glass
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

For SPL it is sometimes useful to have a simple malloc() just to permit
driver model to work, in the cases where the full malloc() is not made
available by the board config.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 arch/arm/lib/crt0.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
index 29cdad0..823b233 100644
--- a/arch/arm/lib/crt0.S
+++ b/arch/arm/lib/crt0.S
@@ -78,7 +78,7 @@ clr_gd:
 	strlo	r0, [r1]		/* clear 32-bit GD word */
 	addlo	r1, r1, #4		/* move to next */
 	blo	clr_gd
-#if defined(CONFIG_SYS_MALLOC_F_LEN) && !defined(CONFIG_SPL_BUILD)
+#if defined(CONFIG_SYS_MALLOC_F_LEN)
 	sub	sp, sp, #CONFIG_SYS_MALLOC_F_LEN
 	str	sp, [r9, #GD_MALLOC_BASE]
 #endif
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 04/13] dm: spl: Make simple malloc() available when enabled
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (2 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 03/13] dm: arm: spl: Allow simple malloc() in SPL Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-24 18:59   ` Tom Rini
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 05/13] dm: spl: Allow driver model to be used Simon Glass
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

Set up the simple malloc() implementation when requested, in preference to
the full malloc().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 common/spl/spl.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index b16664f..7168854 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -134,9 +134,13 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	u32 boot_device;
 	debug(">>spl:board_init_r()\n");
 
-#ifdef CONFIG_SYS_SPL_MALLOC_START
+#if defined(CONFIG_SYS_SPL_MALLOC_START)
 	mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
 			CONFIG_SYS_SPL_MALLOC_SIZE);
+	gd->flags |= GD_FLG_FULL_MALLOC_INIT;
+#elif defined(CONFIG_SYS_MALLOC_F_LEN)
+	gd->malloc_limit = gd->malloc_base + CONFIG_SYS_MALLOC_F_LEN;
+	gd->malloc_ptr = 0;
 #endif
 
 #ifndef CONFIG_PPC
@@ -233,6 +237,11 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	default:
 		debug("Unsupported OS image.. Jumping nevertheless..\n");
 	}
+#if defined(CONFIG_SYS_MALLOC_F_LEN) && !defined(CONFIG_SYS_SPL_MALLOC_SIZE)
+	debug("SPL malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
+	      gd->malloc_ptr / 1024);
+#endif
+
 	jump_to_image_no_args(&spl_image);
 }
 
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 05/13] dm: spl: Allow driver model to be used
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (3 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 04/13] dm: spl: Make simple malloc() available when enabled Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-24 19:06   ` Tom Rini
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 06/13] dm: Allow device removal features to be dropped Simon Glass
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

When enabled, set up driver model for SPL. This allows SPL to use the same
drivers as the main U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 common/spl/spl.c     | 5 +++++
 scripts/Makefile.spl | 1 +
 2 files changed, 6 insertions(+)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 7168854..c92d01e 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -7,6 +7,7 @@
  * SPDX-License-Identifier:	GPL-2.0+
  */
 #include <common.h>
+#include <dm.h>
 #include <spl.h>
 #include <asm/u-boot.h>
 #include <nand.h>
@@ -15,6 +16,7 @@
 #include <i2c.h>
 #include <image.h>
 #include <malloc.h>
+#include <dm/root.h>
 #include <linux/compiler.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -142,6 +144,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	gd->malloc_limit = gd->malloc_base + CONFIG_SYS_MALLOC_F_LEN;
 	gd->malloc_ptr = 0;
 #endif
+#ifdef CONFIG_SPL_DM
+	dm_init_and_scan(true);
+#endif
 
 #ifndef CONFIG_PPC
 	/*
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 88c01d1..c053770 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -69,6 +69,7 @@ libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
 libs-$(CONFIG_SPL_FRAMEWORK) += common/spl/
 libs-$(CONFIG_SPL_LIBCOMMON_SUPPORT) += common/
 libs-$(CONFIG_SPL_LIBDISK_SUPPORT) += disk/
+libs-$(CONFIG_SPL_DM) += drivers/core/
 libs-$(CONFIG_SPL_I2C_SUPPORT) += drivers/i2c/
 libs-$(CONFIG_SPL_GPIO_SUPPORT) += drivers/gpio/
 libs-$(CONFIG_SPL_MMC_SUPPORT) += drivers/mmc/
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 06/13] dm: Allow device removal features to be dropped
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (4 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 05/13] dm: spl: Allow driver model to be used Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 07/13] dm: Allow stdio registration " Simon Glass
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

For SPL we don't expect to need to remove a device. Save some code space
by dropping this feature. The board config can define
CONFIG_DM_DEVICE_REMOVE if this is in fact needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 drivers/core/Makefile        |   3 +-
 drivers/core/device-remove.c | 187 +++++++++++++++++++++++++++++++++++++++++++
 drivers/core/device.c        | 168 --------------------------------------
 include/config_defaults.h    |   4 +
 include/dm/device-internal.h |  10 +++
 5 files changed, 203 insertions(+), 169 deletions(-)
 create mode 100644 drivers/core/device-remove.c

diff --git a/drivers/core/Makefile b/drivers/core/Makefile
index 151c239..f14695b 100644
--- a/drivers/core/Makefile
+++ b/drivers/core/Makefile
@@ -4,5 +4,6 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
-obj-y := device.o lists.o root.o uclass.o util.o
+obj-$(CONFIG_DM)	+= device.o lists.o root.o uclass.o util.o
 obj-$(CONFIG_OF_CONTROL) += simple-bus.o
+obj-$(CONFIG_DM_DEVICE_REMOVE)	+= device-remove.o
diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
new file mode 100644
index 0000000..8fc6b71
--- /dev/null
+++ b/drivers/core/device-remove.c
@@ -0,0 +1,187 @@
+/*
+ * Device manager
+ *
+ * Copyright (c) 2014 Google, Inc
+ *
+ * (C) Copyright 2012
+ * Pavel Herrmann <morpheus.ibis@gmail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <malloc.h>
+#include <dm/device.h>
+#include <dm/device-internal.h>
+#include <dm/uclass.h>
+#include <dm/uclass-internal.h>
+#include <dm/util.h>
+
+/**
+ * device_chld_unbind() - Unbind all device's children from the device
+ *
+ * On error, the function continues to unbind all children, and reports the
+ * first error.
+ *
+ * @dev:	The device that is to be stripped of its children
+ * @return 0 on success, -ve on error
+ */
+static int device_chld_unbind(struct udevice *dev)
+{
+	struct udevice *pos, *n;
+	int ret, saved_ret = 0;
+
+	assert(dev);
+
+	list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) {
+		ret = device_unbind(pos);
+		if (ret && !saved_ret)
+			saved_ret = ret;
+	}
+
+	return saved_ret;
+}
+
+/**
+ * device_chld_remove() - Stop all device's children
+ * @dev:	The device whose children are to be removed
+ * @return 0 on success, -ve on error
+ */
+static int device_chld_remove(struct udevice *dev)
+{
+	struct udevice *pos, *n;
+	int ret;
+
+	assert(dev);
+
+	list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) {
+		ret = device_remove(pos);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+int device_unbind(struct udevice *dev)
+{
+	struct driver *drv;
+	int ret;
+
+	if (!dev)
+		return -EINVAL;
+
+	if (dev->flags & DM_FLAG_ACTIVATED)
+		return -EINVAL;
+
+	drv = dev->driver;
+	assert(drv);
+
+	if (drv->unbind) {
+		ret = drv->unbind(dev);
+		if (ret)
+			return ret;
+	}
+
+	ret = device_chld_unbind(dev);
+	if (ret)
+		return ret;
+
+	ret = uclass_unbind_device(dev);
+	if (ret)
+		return ret;
+
+	if (dev->parent)
+		list_del(&dev->sibling_node);
+	free(dev);
+
+	return 0;
+}
+
+/**
+ * device_free() - Free memory buffers allocated by a device
+ * @dev:	Device that is to be started
+ */
+void device_free(struct udevice *dev)
+{
+	int size;
+
+	if (dev->driver->priv_auto_alloc_size) {
+		free(dev->priv);
+		dev->priv = NULL;
+	}
+	if (dev->flags & DM_FLAG_ALLOC_PDATA) {
+		free(dev->platdata);
+		dev->platdata = NULL;
+	}
+	size = dev->uclass->uc_drv->per_device_auto_alloc_size;
+	if (size) {
+		free(dev->uclass_priv);
+		dev->uclass_priv = NULL;
+	}
+	if (dev->parent) {
+		size = dev->parent->driver->per_child_auto_alloc_size;
+		if (size) {
+			free(dev->parent_priv);
+			dev->parent_priv = NULL;
+		}
+	}
+}
+
+int device_remove(struct udevice *dev)
+{
+	struct driver *drv;
+	int ret;
+
+	if (!dev)
+		return -EINVAL;
+
+	if (!(dev->flags & DM_FLAG_ACTIVATED))
+		return 0;
+
+	drv = dev->driver;
+	assert(drv);
+
+	ret = uclass_pre_remove_device(dev);
+	if (ret)
+		return ret;
+
+	ret = device_chld_remove(dev);
+	if (ret)
+		goto err;
+
+	if (drv->remove) {
+		ret = drv->remove(dev);
+		if (ret)
+			goto err_remove;
+	}
+
+	if (dev->parent && dev->parent->driver->child_post_remove) {
+		ret = dev->parent->driver->child_post_remove(dev);
+		if (ret) {
+			dm_warn("%s: Device '%s' failed child_post_remove()",
+				__func__, dev->name);
+		}
+	}
+
+	device_free(dev);
+
+	dev->seq = -1;
+	dev->flags &= ~DM_FLAG_ACTIVATED;
+
+	return ret;
+
+err_remove:
+	/* We can't put the children back */
+	dm_warn("%s: Device '%s' failed to remove, but children are gone\n",
+		__func__, dev->name);
+err:
+	ret = uclass_post_probe_device(dev);
+	if (ret) {
+		dm_warn("%s: Device '%s' failed to post_probe on error path\n",
+			__func__, dev->name);
+	}
+
+	return ret;
+}
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 49faa29..576a4f2 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -24,52 +24,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-/**
- * device_chld_unbind() - Unbind all device's children from the device
- *
- * On error, the function continues to unbind all children, and reports the
- * first error.
- *
- * @dev:	The device that is to be stripped of its children
- * @return 0 on success, -ve on error
- */
-static int device_chld_unbind(struct udevice *dev)
-{
-	struct udevice *pos, *n;
-	int ret, saved_ret = 0;
-
-	assert(dev);
-
-	list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) {
-		ret = device_unbind(pos);
-		if (ret && !saved_ret)
-			saved_ret = ret;
-	}
-
-	return saved_ret;
-}
-
-/**
- * device_chld_remove() - Stop all device's children
- * @dev:	The device whose children are to be removed
- * @return 0 on success, -ve on error
- */
-static int device_chld_remove(struct udevice *dev)
-{
-	struct udevice *pos, *n;
-	int ret;
-
-	assert(dev);
-
-	list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) {
-		ret = device_remove(pos);
-		if (ret)
-			return ret;
-	}
-
-	return 0;
-}
-
 int device_bind(struct udevice *parent, struct driver *drv, const char *name,
 		void *platdata, int of_offset, struct udevice **devp)
 {
@@ -167,71 +121,6 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
 			   -1, devp);
 }
 
-int device_unbind(struct udevice *dev)
-{
-	struct driver *drv;
-	int ret;
-
-	if (!dev)
-		return -EINVAL;
-
-	if (dev->flags & DM_FLAG_ACTIVATED)
-		return -EINVAL;
-
-	drv = dev->driver;
-	assert(drv);
-
-	if (drv->unbind) {
-		ret = drv->unbind(dev);
-		if (ret)
-			return ret;
-	}
-
-	ret = device_chld_unbind(dev);
-	if (ret)
-		return ret;
-
-	ret = uclass_unbind_device(dev);
-	if (ret)
-		return ret;
-
-	if (dev->parent)
-		list_del(&dev->sibling_node);
-	free(dev);
-
-	return 0;
-}
-
-/**
- * device_free() - Free memory buffers allocated by a device
- * @dev:	Device that is to be started
- */
-static void device_free(struct udevice *dev)
-{
-	int size;
-
-	if (dev->driver->priv_auto_alloc_size) {
-		free(dev->priv);
-		dev->priv = NULL;
-	}
-	if (dev->flags & DM_FLAG_ALLOC_PDATA) {
-		free(dev->platdata);
-		dev->platdata = NULL;
-	}
-	size = dev->uclass->uc_drv->per_device_auto_alloc_size;
-	if (size) {
-		free(dev->uclass_priv);
-		dev->uclass_priv = NULL;
-	}
-	if (dev->parent) {
-		size = dev->parent->driver->per_child_auto_alloc_size;
-		if (size) {
-			free(dev->parent_priv);
-			dev->parent_priv = NULL;
-		}
-	}
-}
-
 int device_probe_child(struct udevice *dev, void *parent_priv)
 {
 	struct driver *drv;
@@ -342,63 +231,6 @@ int device_probe(struct udevice *dev)
 	return device_probe_child(dev, NULL);
 }
 
-int device_remove(struct udevice *dev)
-{
-	struct driver *drv;
-	int ret;
-
-	if (!dev)
-		return -EINVAL;
-
-	if (!(dev->flags & DM_FLAG_ACTIVATED))
-		return 0;
-
-	drv = dev->driver;
-	assert(drv);
-
-	ret = uclass_pre_remove_device(dev);
-	if (ret)
-		return ret;
-
-	ret = device_chld_remove(dev);
-	if (ret)
-		goto err;
-
-	if (drv->remove) {
-		ret = drv->remove(dev);
-		if (ret)
-			goto err_remove;
-	}
-
-	if (dev->parent && dev->parent->driver->child_post_remove) {
-		ret = dev->parent->driver->child_post_remove(dev);
-		if (ret) {
-			dm_warn("%s: Device '%s' failed child_post_remove()",
-				__func__, dev->name);
-		}
-	}
-
-	device_free(dev);
-
-	dev->seq = -1;
-	dev->flags &= ~DM_FLAG_ACTIVATED;
-
-	return ret;
-
-err_remove:
-	/* We can't put the children back */
-	dm_warn("%s: Device '%s' failed to remove, but children are gone\n",
-		__func__, dev->name);
-err:
-	ret = uclass_post_probe_device(dev);
-	if (ret) {
-		dm_warn("%s: Device '%s' failed to post_probe on error path\n",
-			__func__, dev->name);
-	}
-
-	return ret;
-}
-
 void *dev_get_platdata(struct udevice *dev)
 {
 	if (!dev) {
diff --git a/include/config_defaults.h b/include/config_defaults.h
index ad08c1d..985f055 100644
--- a/include/config_defaults.h
+++ b/include/config_defaults.h
@@ -20,4 +20,8 @@
 #define CONFIG_ZLIB 1
 #define CONFIG_PARTITIONS 1
 
+#ifndef CONFIG_SPL_BUILD
+#define CONFIG_DM_DEVICE_REMOVE
+#endif
+
 #endif
diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h
index 44cb7ef..f0cc794 100644
--- a/include/dm/device-internal.h
+++ b/include/dm/device-internal.h
@@ -87,7 +87,11 @@ int device_probe_child(struct udevice *dev, void *parent_priv);
  * @dev: Pointer to device to remove
  * @return 0 if OK, -ve on error (an error here is normally a very bad thing)
  */
+#ifdef CONFIG_DM_DEVICE_REMOVE
 int device_remove(struct udevice *dev);
+#else
+static inline int device_remove(struct udevice *dev) { return 0; }
+#endif
 
 /**
  * device_unbind() - Unbind a device, destroying it
@@ -99,6 +103,12 @@ int device_remove(struct udevice *dev);
  */
 int device_unbind(struct udevice *dev);
 
+#ifdef CONFIG_DM_DEVICE_REMOVE
+void device_free(struct udevice *dev);
+#else
+static inline void device_free(struct udevice *dev) {}
+#endif
+
 /* Cast away any volatile pointer */
 #define DM_ROOT_NON_CONST		(((gd_t *)gd)->dm_root)
 #define DM_UCLASS_ROOT_NON_CONST	(((gd_t *)gd)->uclass_root)
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 07/13] dm: Allow stdio registration to be dropped
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (5 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 06/13] dm: Allow device removal features to be dropped Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-24 19:06   ` Tom Rini
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 08/13] dm: Disable dm_warn() in SPL Simon Glass
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

Provide a CONFIG_DM_STDIO option to enable registering a serial device
with the stdio library. This is seldom useful in SPL, so disable it by
default when building for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 drivers/serial/serial-uclass.c | 8 +++++---
 include/config_defaults.h      | 1 +
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 4fad654..092d50a 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -180,9 +180,11 @@ int serial_stub_tstc(struct stdio_dev *sdev)
 
 static int serial_post_probe(struct udevice *dev)
 {
-	struct stdio_dev sdev;
 	struct dm_serial_ops *ops = serial_get_ops(dev);
+#ifdef CONFIG_DM_STDIO
 	struct serial_dev_priv *upriv = dev->uclass_priv;
+	struct stdio_dev sdev;
+#endif
 	int ret;
 
 	/* Set the baud rate */
@@ -192,9 +194,9 @@ static int serial_post_probe(struct udevice *dev)
 			return ret;
 	}
 
+#ifdef CONFIG_DM_STDIO
 	if (!(gd->flags & GD_FLG_RELOC))
 		return 0;
-
 	memset(&sdev, '\0', sizeof(sdev));
 
 	strncpy(sdev.name, dev->name, sizeof(sdev.name));
@@ -205,7 +207,7 @@ static int serial_post_probe(struct udevice *dev)
 	sdev.getc = serial_stub_getc;
 	sdev.tstc = serial_stub_tstc;
 	stdio_register_dev(&sdev, &upriv->sdev);
-
+#endif
 	return 0;
 }
 
diff --git a/include/config_defaults.h b/include/config_defaults.h
index 985f055..f1b225d 100644
--- a/include/config_defaults.h
+++ b/include/config_defaults.h
@@ -22,6 +22,7 @@
 
 #ifndef CONFIG_SPL_BUILD
 #define CONFIG_DM_DEVICE_REMOVE
+#define CONFIG_DM_STDIO
 #endif
 
 #endif
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 08/13] dm: Disable dm_warn() in SPL
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (6 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 07/13] dm: Allow stdio registration " Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-24 19:07   ` Tom Rini
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 09/13] dm: tegra: Add platform data for the SPL uart Simon Glass
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

Since this function can use up quite a bit of space for its strings, disable
it by default in SPL. Use CONFIG_DM_WARN to re-enable it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 include/config_defaults.h | 1 +
 include/dm/util.h         | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/include/config_defaults.h b/include/config_defaults.h
index f1b225d..4d49315 100644
--- a/include/config_defaults.h
+++ b/include/config_defaults.h
@@ -21,6 +21,7 @@
 #define CONFIG_PARTITIONS 1
 
 #ifndef CONFIG_SPL_BUILD
+#define CONFIG_DM_WARN
 #define CONFIG_DM_DEVICE_REMOVE
 #define CONFIG_DM_STDIO
 #endif
diff --git a/include/dm/util.h b/include/dm/util.h
index 6ac3a38..0cec17b 100644
--- a/include/dm/util.h
+++ b/include/dm/util.h
@@ -7,7 +7,13 @@
 #ifndef __DM_UTIL_H
 #define __DM_UTIL_H
 
+#ifdef CONFIG_DM_WARN
 void dm_warn(const char *fmt, ...);
+#else
+static inline void dm_warn(const char *fmt, ...)
+{
+}
+#endif
 
 #ifdef DEBUG
 void dm_dbg(const char *fmt, ...);
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 09/13] dm: tegra: Add platform data for the SPL uart
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (7 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 08/13] dm: Disable dm_warn() in SPL Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 10/13] dm: tegra: Add platform data for the GPIO driver Simon Glass
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

Since we currently don't have device tree available in SPL, add platform
data so the uart works.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 drivers/serial/serial_tegra.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/serial/serial_tegra.c b/drivers/serial/serial_tegra.c
index 7eb70e1..b9227f0 100644
--- a/drivers/serial/serial_tegra.c
+++ b/drivers/serial/serial_tegra.c
@@ -9,6 +9,7 @@
 #include <ns16550.h>
 #include <serial.h>
 
+#ifdef CONFIG_OF_CONTROL
 static const struct udevice_id tegra_serial_ids[] = {
 	{ .compatible = "nvidia,tegra20-uart" },
 	{ }
@@ -26,13 +27,28 @@ static int tegra_serial_ofdata_to_platdata(struct udevice *dev)
 
 	return 0;
 }
+#else
+struct ns16550_platdata tegra_serial = {
+	.base = CONFIG_SYS_NS16550_COM1,
+	.reg_shift = 2,
+	.clock = V_NS16550_CLK,
+};
+
+U_BOOT_DEVICE(ns16550_serial) = {
+	"serial_tegra20", &tegra_serial
+};
+#endif
+
 U_BOOT_DRIVER(serial_ns16550) = {
 	.name	= "serial_tegra20",
 	.id	= UCLASS_SERIAL,
+#ifdef CONFIG_OF_CONTROL
 	.of_match = tegra_serial_ids,
 	.ofdata_to_platdata = tegra_serial_ofdata_to_platdata,
 	.platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
+#endif
 	.priv_auto_alloc_size = sizeof(struct NS16550),
 	.probe = ns16550_serial_probe,
 	.ops	= &ns16550_serial_ops,
+	.flags	= DM_FLAG_PRE_RELOC,
 };
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 10/13] dm: tegra: Add platform data for the GPIO driver
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (8 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 09/13] dm: tegra: Add platform data for the SPL uart Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 11/13] dm: arm: spl: Make driver model linker lists available Simon Glass
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

Add platform data for the GPIO driver. It doesn't need to contain anything
since the GPIO driver will actually use information from the CONFIGs for
now. This merely serves to ensure that the GPIO driver is bound.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 board/nvidia/common/board.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/board/nvidia/common/board.c b/board/nvidia/common/board.c
index 03f055d..9c7ad9b 100644
--- a/board/nvidia/common/board.c
+++ b/board/nvidia/common/board.c
@@ -6,6 +6,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <ns16550.h>
 #include <linux/compiler.h>
 #include <asm/io.h>
@@ -43,6 +44,13 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#ifdef CONFIG_SPL_BUILD
+/* TODO(sjg at chromium.org): Remove once SPL supports device tree */
+U_BOOT_DEVICE(tegra_gpios) = {
+	"gpio_tegra"
+};
+#endif
+
 const struct tegra_sysinfo sysinfo = {
 	CONFIG_TEGRA_BOARD_STRING
 };
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 11/13] dm: arm: spl: Make driver model linker lists available
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (9 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 10/13] dm: tegra: Add platform data for the GPIO driver Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-24 19:08   ` Tom Rini
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 12/13] dm: tegra: Enable driver model in SPL and adjust the GPIO driver Simon Glass
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 13/13] dm: Update documentation to include CONFIG_DM... options Simon Glass
  12 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

The linker lists feature is useful in SPL as it holds the driver model
platform data. So don't throw away the lists.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2: None

 arch/arm/cpu/u-boot-spl.lds | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/arm/cpu/u-boot-spl.lds b/arch/arm/cpu/u-boot-spl.lds
index 4beddf0..a69b006 100644
--- a/arch/arm/cpu/u-boot-spl.lds
+++ b/arch/arm/cpu/u-boot-spl.lds
@@ -34,6 +34,13 @@ SECTIONS
 	. = ALIGN(4);
 
 	. = .;
+#ifdef CONFIG_SPL_DM
+	.u_boot_list : {
+		KEEP(*(SORT(.u_boot_list_*_driver_*)));
+		KEEP(*(SORT(.u_boot_list_*_uclass_*)));
+	}
+#endif
+	. = ALIGN(4);
 
 	__image_copy_end = .;
 
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 12/13] dm: tegra: Enable driver model in SPL and adjust the GPIO driver
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (10 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 11/13] dm: arm: spl: Make driver model linker lists available Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 13/13] dm: Update documentation to include CONFIG_DM... options Simon Glass
  12 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

Use the full driver model GPIO and serial drivers in SPL now that these are
supported. Since device tree is not available they will use platform data.

Remove the special SPL GPIO function as it is no longer needed.

This is all in one commit to maintain bisectability.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Rebase on top of the SPI series

 board/nvidia/seaboard/seaboard.c |  4 +---
 drivers/gpio/Makefile            |  4 ++++
 drivers/gpio/tegra_gpio.c        | 27 +++++++++++----------------
 include/configs/tegra-common.h   | 12 +++---------
 4 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/board/nvidia/seaboard/seaboard.c b/board/nvidia/seaboard/seaboard.c
index 6a243f0..3e52826 100644
--- a/board/nvidia/seaboard/seaboard.c
+++ b/board/nvidia/seaboard/seaboard.c
@@ -19,10 +19,8 @@
 void gpio_early_init_uart(void)
 {
 	/* Enable UART via GPIO_PI3 (port 8, bit 3) so serial console works */
-#ifndef CONFIG_SPL_BUILD
 	gpio_request(GPIO_PI3, NULL);
-#endif
-	tegra_spl_gpio_direction_output(GPIO_PI3, 0);
+	gpio_direction_output(GPIO_PI3, 0);
 }
 #endif
 
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index aa11f15..fe9a3b2 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -8,6 +8,10 @@
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_DM_GPIO)		+= gpio-uclass.o
 endif
+/* TODO(sjg at chromium.org): Only tegra supports driver model in SPL */
+ifdef CONFIG_TEGRA_GPIO
+obj-$(CONFIG_DM_GPIO)		+= gpio-uclass.o
+endif
 
 obj-$(CONFIG_AT91_GPIO)	+= at91_gpio.o
 obj-$(CONFIG_INTEL_ICH6_GPIO)	+= intel_ich6_gpio.o
diff --git a/drivers/gpio/tegra_gpio.c b/drivers/gpio/tegra_gpio.c
index 88f7ef5..a1e51c0 100644
--- a/drivers/gpio/tegra_gpio.c
+++ b/drivers/gpio/tegra_gpio.c
@@ -131,21 +131,6 @@ static void set_level(unsigned gpio, int high)
 	writel(u, &bank->gpio_out[GPIO_PORT(gpio)]);
 }
 
-/* set GPIO pin 'gpio' as an output, with polarity 'value' */
-int tegra_spl_gpio_direction_output(int gpio, int value)
-{
-	/* Configure as a GPIO */
-	set_config(gpio, 1);
-
-	/* Configure GPIO output value. */
-	set_level(gpio, value);
-
-	/* Configure GPIO direction as output. */
-	set_direction(gpio, 1);
-
-	return 0;
-}
-
 /*
  * Generic_GPIO primitives.
  */
@@ -320,12 +305,19 @@ static int gpio_tegra_bind(struct udevice *parent)
 	int bank_count;
 	int bank;
 	int ret;
-	int len;
 
 	/* If this is a child device, there is nothing to do here */
 	if (plat)
 		return 0;
 
+	/* TODO(sjg at chromium.org): Remove once SPL supports device tree */
+#ifdef CONFIG_SPL_BUILD
+	ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE;
+	bank_count = TEGRA_GPIO_BANKS;
+#else
+	{
+	int len;
+
 	/*
 	 * This driver does not make use of interrupts, other than to figure
 	 * out the number of GPIO banks
@@ -335,6 +327,8 @@ static int gpio_tegra_bind(struct udevice *parent)
 	bank_count = len / 3 / sizeof(u32);
 	ctlr = (struct gpio_ctlr *)fdtdec_get_addr(gd->fdt_blob,
 						   parent->of_offset, "reg");
+	}
+#endif
 	for (bank = 0; bank < bank_count; bank++) {
 		int port;
 
@@ -370,4 +364,5 @@ U_BOOT_DRIVER(gpio_tegra) = {
 	.probe = gpio_tegra_probe,
 	.priv_auto_alloc_size = sizeof(struct tegra_port_info),
 	.ops	= &gpio_tegra_ops,
+	.flags	= DM_FLAG_PRE_RELOC,
 };
diff --git a/include/configs/tegra-common.h b/include/configs/tegra-common.h
index 4719ee1..b72f64f 100644
--- a/include/configs/tegra-common.h
+++ b/include/configs/tegra-common.h
@@ -19,13 +19,12 @@
 #include <asm/arch/tegra.h>		/* get chip and board defs */
 
 #define CONFIG_DM
+#define CONFIG_SPL_DM
 #define CONFIG_CMD_DM
-#define CONFIG_DM_GPIO
-#ifndef CONFIG_SPL_BUILD
 #define CONFIG_DM_SERIAL
-#endif
 #define CONFIG_DM_SPI
 #define CONFIG_DM_SPI_FLASH
+#define CONFIG_DM_GPIO
 
 #define CONFIG_SYS_TIMER_RATE		1000000
 #define CONFIG_SYS_TIMER_COUNTER	NV_PA_TMRUS_BASE
@@ -51,13 +50,7 @@
 /*
  * NS16550 Configuration
  */
-#ifdef CONFIG_SPL_BUILD
-#define CONFIG_SYS_NS16550_SERIAL
-#define CONFIG_SYS_NS16550_REG_SIZE	(-4)
-#define CONFIG_SYS_NS16550_CLK		V_NS16550_CLK
-#else
 #define CONFIG_TEGRA_SERIAL
-#endif
 #define CONFIG_SYS_NS16550
 
 /*
@@ -137,6 +130,7 @@
 						GENERATED_GBL_DATA_SIZE)
 
 #define CONFIG_TEGRA_GPIO
+
 #define CONFIG_CMD_GPIO
 #define CONFIG_CMD_ENTERRCM
 
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 13/13] dm: Update documentation to include CONFIG_DM... options
  2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
                   ` (11 preceding siblings ...)
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 12/13] dm: tegra: Enable driver model in SPL and adjust the GPIO driver Simon Glass
@ 2014-10-23 19:16 ` Simon Glass
  2014-10-23 20:17   ` Masahiro YAMADA
  12 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2014-10-23 19:16 UTC (permalink / raw)
  To: u-boot

Add documentation for the various driver model options that are now
available.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Rebase to master

 README                      | 119 ++++++++++++++++++++++++++++++++++++++++++++
 doc/driver-model/README.txt |  44 ++++++++++++----
 2 files changed, 153 insertions(+), 10 deletions(-)

diff --git a/README b/README
index 19abe20..b679164 100644
--- a/README
+++ b/README
@@ -630,6 +630,120 @@ The following options need to be configured:
 		get_timer() must operate in milliseconds and this CONFIG
 		option must be set to 1000.
 
+- Driver Model
+		Driver model is a new framework for devices in U-Boot
+		introduced in early 2014. U-Boot is being progressively
+		moved over to this. It offers a consistent device structure,
+		supports grouping devices into classes and has built-in
+		handling of platform data and device tree.
+
+		To enable transition to driver model in a relatively
+		painful fashion, each subsystem can be independently
+		switched between the legacy/ad-hoc approach and the new
+		driver model using the options below. Also, many uclass
+		interfaces include compatibility features which may be
+		removed once the conversion of that subsystem is complete.
+		As a result, the API provided by the subsystem may in fact
+		not change with driver model.
+
+		See doc/driver-model/README.txt for more information.
+
+		CONFIG_DM
+
+		Enable driver model. This brings in the core support,
+		including scanning of platform data on start-up. If
+		CONFIG_OF_CONTROL is enabled, the device tree will be
+		scanned also when available.
+
+		CONFIG_CMD_DM
+
+		Enable driver model test commands. These allow you to print
+		out the driver model tree and the uclasses.
+
+		CONFIG_DM_DEMO
+
+		Enable some demo devices and the 'demo' command. These are
+		really only useful for playing around while trying to
+		understand driver model in sandbox.
+
+		CONFIG_SPL_DM
+
+		Enable driver model in SPL. You will need to provide a
+		suitable malloc() implementation. If you are not using the
+		full malloc() enabled by CONFIG_SYS_SPL_MALLOC_START,
+		consider using CONFIG_SYS_MALLOC_SIMPLE. In that case you
+		must provide CONFIG_SYS_MALLOC_F_LEN to set the size.
+		In most cases driver model will only allocate a few uclasses
+		and devices in SPL, so 1KB should be enable. See
+		CONFIG_SYS_MALLOC_F_LEN for more details on how to enable
+		it.
+
+		CONFIG_DM_SERIAL
+
+		Enable driver model for serial. This replaces
+		drivers/serial/serial.c with the serial uclass, which
+		implements serial_putc() etc. The uclass interface is
+		defined in include/serial.h.
+
+		CONFIG_DM_GPIO
+
+		Enable driver model for GPIO access. The standard GPIO
+		interface (gpio_get_value(), etc.) is then implemented by
+		the GPIO uclass. Drivers provide methods to query the
+		particular GPIOs that they provide. The uclass interface
+		is defined in include/asm-generic/gpio.h.
+
+		CONFIG_DM_SPI
+
+		Enable driver model for SPI. The SPI slave interface
+		(spi_setup_slave(), spi_xfer(), etc.) is then implemented by
+		the SPI uclass. Drivers provide methods to access the SPI
+		buses that they control. The uclass interface is defined in
+		include/spi.h. The existing spi_slave structure is attached
+		as 'parent data' to every slave on each bus. Slaves
+		typically use driver-private data instead of extending the
+		spi_slave structure.
+
+		CONFIG_DM_SPI_FLASH
+
+		Enable driver model for SPI flash. This SPI flash interface
+		(spi_flash_probe(), spi_flash_write(), etc.) is then
+		implemented by the SPI flash uclass. There is one standard
+		SPI flash driver which knows how to probe most chips
+		supported by U-Boot. The uclass interface is defined in
+		include/spi_flash.h, but is currently fully compatible
+		with the old interface to avoid confusion and duplication
+		during the transition parent. SPI and SPI flash must be
+		enabled together (it is not possible to use driver model
+		for one and not the other).
+
+		CONFIG_DM_CROS_EC
+
+		Enable driver model for the Chrome OS EC interface. This
+		allows the cros_ec SPI driver to operate with CONFIG_DM_SPI
+		but otherwise makes few changes. Since cros_ec also supports
+		I2C and LPC (which don't support driver model yet), a full
+		conversion is not yet possible.
+
+
+		** Code size options: The following options are enabled by
+		default except in SPL. Enable them explicitly to get these
+		features in SPL.
+
+		CONFIG_DM_WARN
+
+		Enable the dm_warn() function. This can use up quite a bit
+		of space for its strings.
+
+		CONFIG_DM_STDIO
+
+		Enable registering a serial device with the stdio library.
+
+		CONFIG_DM_DEVICE_REMOVE
+
+		Enable removing of devices.
+
+
 - Linux Kernel Interface:
 		CONFIG_CLOCKS_IN_MHZ
 
@@ -3874,6 +3988,11 @@ Configuration Settings:
 		Pre-relocation malloc() is only supported on ARM and sandbox
 		at present but is fairly easy to enable for other archs.
 
+- CONFIG_SYS_MALLOC_SIMPLE
+		Provides a simple and small malloc() and calloc() for those
+		boards which do not use the full malloc in SPL (which is
+		enabled with CONFIG_SYS_SPL_MALLOC_START).
+
 - CONFIG_SYS_BOOTM_LEN:
 		Normally compressed uImages are limited to an
 		uncompressed size of 8 MBytes. If this is not enough,
diff --git a/doc/driver-model/README.txt b/doc/driver-model/README.txt
index 0278dda..3e2f622 100644
--- a/doc/driver-model/README.txt
+++ b/doc/driver-model/README.txt
@@ -750,19 +750,43 @@ device pointers, but this is not currently implemented (the root device
 pointer is saved but not made available through the driver model API).
 
 
-Things to punt for later
-------------------------
+SPL Support
+-----------
+
+Driver model can operate in SPL. Its efficient implementation and small code
+size provide for a small overhead which is acceptable for all but the most
+constrained systems.
+
+To enable driver model in SPL, define CONFIG_SPL_DM. You might want to
+consider the following option also. See the main README for more details.
+
+   - CONFIG_SYS_MALLOC_SIMPLE
+   - CONFIG_DM_WARN
+   - CONFIG_DM_DEVICE_REMOVE
+   - CONFIG_DM_STDIO
 
-- SPL support - this will have to be present before many drivers can be
-converted, but it seems like we can add it once we are happy with the
-core implementation.
 
-That is not to say that no thinking has gone into this - in fact there
-is quite a lot there. However, getting these right is non-trivial and
-there is a high cost associated with going down the wrong path.
+Enabling Driver Model
+---------------------
 
-For SPL, it may be possible to fit in a simplified driver model with only
-bind and probe methods, to reduce size.
+Driver model is being brought into U-Boot gradually. As each subsystems gets
+support, a uclass is created and a CONFIG to enable use of driver model for
+that subsystem.
+
+For example CONFIG_DM_SERIAL enables driver model for serial. With that
+defined, the old serial support is not enabled, and your serial driver must
+conform to driver model. With that undefined, the old serial support is
+enabled and driver model is not available for serial. This means that when
+you convert a driver, you must either convert all its boards, or provide for
+the driver to be compiled both with and without driver model (generally this
+is not very hard).
+
+See the main README for full details of the available driver model CONFIG
+options.
+
+
+Things to punt for later
+------------------------
 
 Uclasses are statically numbered at compile time. It would be possible to
 change this to dynamic numbering, but then we would require some sort of
-- 
2.1.0.rc2.206.gedb03e5

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 13/13] dm: Update documentation to include CONFIG_DM... options
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 13/13] dm: Update documentation to include CONFIG_DM... options Simon Glass
@ 2014-10-23 20:17   ` Masahiro YAMADA
  2014-10-24  1:05     ` Simon Glass
  0 siblings, 1 reply; 24+ messages in thread
From: Masahiro YAMADA @ 2014-10-23 20:17 UTC (permalink / raw)
  To: u-boot

Hi Simon,


2014-10-24 4:16 GMT+09:00 Simon Glass <sjg@chromium.org>:
> Add documentation for the various driver model options that are now
> available.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2:
> - Rebase to master
>
>  README                      | 119 ++++++++++++++++++++++++++++++++++++++++++++
>  doc/driver-model/README.txt |  44 ++++++++++++----
>  2 files changed, 153 insertions(+), 10 deletions(-)
>
> diff --git a/README b/README
> index 19abe20..b679164 100644
> --- a/README
> +++ b/README
> @@ -630,6 +630,120 @@ The following options need to be configured:
>                 get_timer() must operate in milliseconds and this CONFIG
>                 option must be set to 1000.
>
> +- Driver Model
> +               Driver model is a new framework for devices in U-Boot
> +               introduced in early 2014. U-Boot is being progressively
> +               moved over to this. It offers a consistent device structure,
> +               supports grouping devices into classes and has built-in
> +               handling of platform data and device tree.
> +
> +               To enable transition to driver model in a relatively
> +               painful fashion, each subsystem can be independently
> +               switched between the legacy/ad-hoc approach and the new
> +               driver model using the options below. Also, many uclass
> +               interfaces include compatibility features which may be
> +               removed once the conversion of that subsystem is complete.
> +               As a result, the API provided by the subsystem may in fact
> +               not change with driver model.
> +
> +               See doc/driver-model/README.txt for more information.
> +
> +               CONFIG_DM
> +
> +               Enable driver model. This brings in the core support,
> +               including scanning of platform data on start-up. If
> +               CONFIG_OF_CONTROL is enabled, the device tree will be
> +               scanned also when available.
> +
> +               CONFIG_CMD_DM
> +
> +               Enable driver model test commands. These allow you to print
> +               out the driver model tree and the uclasses.
> +
> +               CONFIG_DM_DEMO
> +
> +               Enable some demo devices and the 'demo' command. These are
> +               really only useful for playing around while trying to
> +               understand driver model in sandbox.
> +
> +               CONFIG_SPL_DM
> +
> +               Enable driver model in SPL. You will need to provide a
> +               suitable malloc() implementation. If you are not using the
> +               full malloc() enabled by CONFIG_SYS_SPL_MALLOC_START,
> +               consider using CONFIG_SYS_MALLOC_SIMPLE. In that case you
> +               must provide CONFIG_SYS_MALLOC_F_LEN to set the size.
> +               In most cases driver model will only allocate a few uclasses
> +               and devices in SPL, so 1KB should be enable. See
> +               CONFIG_SYS_MALLOC_F_LEN for more details on how to enable
> +               it.
> +
> +               CONFIG_DM_SERIAL
> +
> +               Enable driver model for serial. This replaces
> +               drivers/serial/serial.c with the serial uclass, which
> +               implements serial_putc() etc. The uclass interface is
> +               defined in include/serial.h.
> +
> +               CONFIG_DM_GPIO
> +
> +               Enable driver model for GPIO access. The standard GPIO
> +               interface (gpio_get_value(), etc.) is then implemented by
> +               the GPIO uclass. Drivers provide methods to query the
> +               particular GPIOs that they provide. The uclass interface
> +               is defined in include/asm-generic/gpio.h.
> +
> +               CONFIG_DM_SPI
> +
> +               Enable driver model for SPI. The SPI slave interface
> +               (spi_setup_slave(), spi_xfer(), etc.) is then implemented by
> +               the SPI uclass. Drivers provide methods to access the SPI
> +               buses that they control. The uclass interface is defined in
> +               include/spi.h. The existing spi_slave structure is attached
> +               as 'parent data' to every slave on each bus. Slaves
> +               typically use driver-private data instead of extending the
> +               spi_slave structure.
> +
> +               CONFIG_DM_SPI_FLASH
> +
> +               Enable driver model for SPI flash. This SPI flash interface
> +               (spi_flash_probe(), spi_flash_write(), etc.) is then
> +               implemented by the SPI flash uclass. There is one standard
> +               SPI flash driver which knows how to probe most chips
> +               supported by U-Boot. The uclass interface is defined in
> +               include/spi_flash.h, but is currently fully compatible
> +               with the old interface to avoid confusion and duplication
> +               during the transition parent. SPI and SPI flash must be
> +               enabled together (it is not possible to use driver model
> +               for one and not the other).
> +
> +               CONFIG_DM_CROS_EC
> +
> +               Enable driver model for the Chrome OS EC interface. This
> +               allows the cros_ec SPI driver to operate with CONFIG_DM_SPI
> +               but otherwise makes few changes. Since cros_ec also supports
> +               I2C and LPC (which don't support driver model yet), a full
> +               conversion is not yet possible.
> +
> +
> +               ** Code size options: The following options are enabled by
> +               default except in SPL. Enable them explicitly to get these
> +               features in SPL.
> +
> +               CONFIG_DM_WARN
> +
> +               Enable the dm_warn() function. This can use up quite a bit
> +               of space for its strings.
> +
> +               CONFIG_DM_STDIO
> +
> +               Enable registering a serial device with the stdio library.
> +
> +               CONFIG_DM_DEVICE_REMOVE
> +
> +               Enable removing of devices.
> +



Nice!

Can we move them to Kconfig help (in this series or in a follow-up patch) ?

I added some of them just for my instant necessity:
http://patchwork.ozlabs.org/patch/402483/
but my help messages might not be very nice.
Please feel free to rewrite them as you like.
Your documentation is more detailed!

If you could send patches to prepare DM entries in Kconfig,
that would be really helpful.



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 13/13] dm: Update documentation to include CONFIG_DM... options
  2014-10-23 20:17   ` Masahiro YAMADA
@ 2014-10-24  1:05     ` Simon Glass
  0 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2014-10-24  1:05 UTC (permalink / raw)
  To: u-boot

Hi Masahiro,

On 23 October 2014 14:17, Masahiro YAMADA <yamada.m@jp.panasonic.com> wrote:
> Hi Simon,
>
>
> 2014-10-24 4:16 GMT+09:00 Simon Glass <sjg@chromium.org>:
>> Add documentation for the various driver model options that are now
>> available.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>> Changes in v2:
>> - Rebase to master
>>
>>  README                      | 119 ++++++++++++++++++++++++++++++++++++++++++++
>>  doc/driver-model/README.txt |  44 ++++++++++++----
>>  2 files changed, 153 insertions(+), 10 deletions(-)
>>
>> diff --git a/README b/README
>> index 19abe20..b679164 100644
>> --- a/README
>> +++ b/README
>> @@ -630,6 +630,120 @@ The following options need to be configured:
>>                 get_timer() must operate in milliseconds and this CONFIG
>>                 option must be set to 1000.
>>
>> +- Driver Model
>> +               Driver model is a new framework for devices in U-Boot
>> +               introduced in early 2014. U-Boot is being progressively
>> +               moved over to this. It offers a consistent device structure,
>> +               supports grouping devices into classes and has built-in
>> +               handling of platform data and device tree.
>> +
>> +               To enable transition to driver model in a relatively
>> +               painful fashion, each subsystem can be independently
>> +               switched between the legacy/ad-hoc approach and the new
>> +               driver model using the options below. Also, many uclass
>> +               interfaces include compatibility features which may be
>> +               removed once the conversion of that subsystem is complete.
>> +               As a result, the API provided by the subsystem may in fact
>> +               not change with driver model.
>> +
>> +               See doc/driver-model/README.txt for more information.
>> +
>> +               CONFIG_DM
>> +
>> +               Enable driver model. This brings in the core support,
>> +               including scanning of platform data on start-up. If
>> +               CONFIG_OF_CONTROL is enabled, the device tree will be
>> +               scanned also when available.
>> +
>> +               CONFIG_CMD_DM
>> +
>> +               Enable driver model test commands. These allow you to print
>> +               out the driver model tree and the uclasses.
>> +
>> +               CONFIG_DM_DEMO
>> +
>> +               Enable some demo devices and the 'demo' command. These are
>> +               really only useful for playing around while trying to
>> +               understand driver model in sandbox.
>> +
>> +               CONFIG_SPL_DM
>> +
>> +               Enable driver model in SPL. You will need to provide a
>> +               suitable malloc() implementation. If you are not using the
>> +               full malloc() enabled by CONFIG_SYS_SPL_MALLOC_START,
>> +               consider using CONFIG_SYS_MALLOC_SIMPLE. In that case you
>> +               must provide CONFIG_SYS_MALLOC_F_LEN to set the size.
>> +               In most cases driver model will only allocate a few uclasses
>> +               and devices in SPL, so 1KB should be enable. See
>> +               CONFIG_SYS_MALLOC_F_LEN for more details on how to enable
>> +               it.
>> +
>> +               CONFIG_DM_SERIAL
>> +
>> +               Enable driver model for serial. This replaces
>> +               drivers/serial/serial.c with the serial uclass, which
>> +               implements serial_putc() etc. The uclass interface is
>> +               defined in include/serial.h.
>> +
>> +               CONFIG_DM_GPIO
>> +
>> +               Enable driver model for GPIO access. The standard GPIO
>> +               interface (gpio_get_value(), etc.) is then implemented by
>> +               the GPIO uclass. Drivers provide methods to query the
>> +               particular GPIOs that they provide. The uclass interface
>> +               is defined in include/asm-generic/gpio.h.
>> +
>> +               CONFIG_DM_SPI
>> +
>> +               Enable driver model for SPI. The SPI slave interface
>> +               (spi_setup_slave(), spi_xfer(), etc.) is then implemented by
>> +               the SPI uclass. Drivers provide methods to access the SPI
>> +               buses that they control. The uclass interface is defined in
>> +               include/spi.h. The existing spi_slave structure is attached
>> +               as 'parent data' to every slave on each bus. Slaves
>> +               typically use driver-private data instead of extending the
>> +               spi_slave structure.
>> +
>> +               CONFIG_DM_SPI_FLASH
>> +
>> +               Enable driver model for SPI flash. This SPI flash interface
>> +               (spi_flash_probe(), spi_flash_write(), etc.) is then
>> +               implemented by the SPI flash uclass. There is one standard
>> +               SPI flash driver which knows how to probe most chips
>> +               supported by U-Boot. The uclass interface is defined in
>> +               include/spi_flash.h, but is currently fully compatible
>> +               with the old interface to avoid confusion and duplication
>> +               during the transition parent. SPI and SPI flash must be
>> +               enabled together (it is not possible to use driver model
>> +               for one and not the other).
>> +
>> +               CONFIG_DM_CROS_EC
>> +
>> +               Enable driver model for the Chrome OS EC interface. This
>> +               allows the cros_ec SPI driver to operate with CONFIG_DM_SPI
>> +               but otherwise makes few changes. Since cros_ec also supports
>> +               I2C and LPC (which don't support driver model yet), a full
>> +               conversion is not yet possible.
>> +
>> +
>> +               ** Code size options: The following options are enabled by
>> +               default except in SPL. Enable them explicitly to get these
>> +               features in SPL.
>> +
>> +               CONFIG_DM_WARN
>> +
>> +               Enable the dm_warn() function. This can use up quite a bit
>> +               of space for its strings.
>> +
>> +               CONFIG_DM_STDIO
>> +
>> +               Enable registering a serial device with the stdio library.
>> +
>> +               CONFIG_DM_DEVICE_REMOVE
>> +
>> +               Enable removing of devices.
>> +
>
>
>
> Nice!
>
> Can we move them to Kconfig help (in this series or in a follow-up patch) ?
>
> I added some of them just for my instant necessity:
> http://patchwork.ozlabs.org/patch/402483/
> but my help messages might not be very nice.
> Please feel free to rewrite them as you like.
> Your documentation is more detailed!
>
> If you could send patches to prepare DM entries in Kconfig,
> that would be really helpful.

OK, let's merge everything and then one of us can move things over.
I'd like to move DM completely to Kconfig in the next week or so.

Regards,
Simon

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 04/13] dm: spl: Make simple malloc() available when enabled
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 04/13] dm: spl: Make simple malloc() available when enabled Simon Glass
@ 2014-10-24 18:59   ` Tom Rini
  2014-10-28  0:07     ` Simon Glass
  0 siblings, 1 reply; 24+ messages in thread
From: Tom Rini @ 2014-10-24 18:59 UTC (permalink / raw)
  To: u-boot

On Thu, Oct 23, 2014 at 01:16:01PM -0600, Simon Glass wrote:

> Set up the simple malloc() implementation when requested, in preference to
> the full malloc().
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> Changes in v2: None
> 
>  common/spl/spl.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/common/spl/spl.c b/common/spl/spl.c
> index b16664f..7168854 100644
> --- a/common/spl/spl.c
> +++ b/common/spl/spl.c
> @@ -134,9 +134,13 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
>  	u32 boot_device;
>  	debug(">>spl:board_init_r()\n");
>  
> -#ifdef CONFIG_SYS_SPL_MALLOC_START
> +#if defined(CONFIG_SYS_SPL_MALLOC_START)
>  	mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
>  			CONFIG_SYS_SPL_MALLOC_SIZE);
> +	gd->flags |= GD_FLG_FULL_MALLOC_INIT;
> +#elif defined(CONFIG_SYS_MALLOC_F_LEN)
> +	gd->malloc_limit = gd->malloc_base + CONFIG_SYS_MALLOC_F_LEN;
> +	gd->malloc_ptr = 0;
>  #endif
>  
>  #ifndef CONFIG_PPC
> @@ -233,6 +237,11 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
>  	default:
>  		debug("Unsupported OS image.. Jumping nevertheless..\n");
>  	}
> +#if defined(CONFIG_SYS_MALLOC_F_LEN) && !defined(CONFIG_SYS_SPL_MALLOC_SIZE)
> +	debug("SPL malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
> +	      gd->malloc_ptr / 1024);
> +#endif
> +
>  	jump_to_image_no_args(&spl_image);
>  }

I don't know if this is right.  Take the example of am335x + booting
from a FAT fs image.  We'll need early malloc prior to DDR being
available, so the tiny space (1-2kb).  But once DDR is up we need a more
complete malloc so that we can use FAT.  I don't have the size handy but
I'm going to guess that (a) it's bigger than 1-2kb (b) bigger than we
can squeeze into SRAM.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141024/79a92841/attachment.pgp>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 01/13] dm: dts: Move omap device tree includes to correct place
  2014-10-23 19:15 ` [U-Boot] [PATCH v2 01/13] dm: dts: Move omap device tree includes to correct place Simon Glass
@ 2014-10-24 19:05   ` Tom Rini
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2014-10-24 19:05 UTC (permalink / raw)
  To: u-boot

On Thu, Oct 23, 2014 at 01:15:58PM -0600, Simon Glass wrote:

> These ended up in arch/arm/dts/dt-bindings temporarily, but in fact the
> correct place is now include/dt-bindings. Move them to be consistent.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Acked-by: Tom Rini <trini@ti.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141024/811c8923/attachment.pgp>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 02/13] dm: Split the simple malloc() implementation into its own file
  2014-10-23 19:15 ` [U-Boot] [PATCH v2 02/13] dm: Split the simple malloc() implementation into its own file Simon Glass
@ 2014-10-24 19:05   ` Tom Rini
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2014-10-24 19:05 UTC (permalink / raw)
  To: u-boot

On Thu, Oct 23, 2014 at 01:15:59PM -0600, Simon Glass wrote:

> The simple malloc() implementation is used when memory is tight. It provides
> a simple buffer with an incrementing pointer.
> 
> At present the implementation is inside dlmalloc. Move it into its own file
> so that it is easier to find.
> 
> Rather than using relocation as a signal that the full malloc() is
> available, add a special GD_FLG_FULL_MALLOC_INIT flag. This signals that the
> simple malloc() should no longer be used.
> 
> In some cases, such as SPL, even the code space used by the full malloc() is
> wasteful. Add a CONFIG_SYS_MALLOC_SIMPLE option to provide only the simple
> malloc. In this case the full malloc is not available at all. It saves about
> 1KB of code space and about 0.5KB of data on Thumb 2.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Acked-by: Tom Rini <trini@ti.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141024/8ca37bae/attachment.pgp>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 05/13] dm: spl: Allow driver model to be used
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 05/13] dm: spl: Allow driver model to be used Simon Glass
@ 2014-10-24 19:06   ` Tom Rini
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2014-10-24 19:06 UTC (permalink / raw)
  To: u-boot

On Thu, Oct 23, 2014 at 01:16:02PM -0600, Simon Glass wrote:

> When enabled, set up driver model for SPL. This allows SPL to use the same
> drivers as the main U-Boot.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Acked-by: Tom Rini <trini@ti.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141024/d8920e5e/attachment.pgp>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 07/13] dm: Allow stdio registration to be dropped
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 07/13] dm: Allow stdio registration " Simon Glass
@ 2014-10-24 19:06   ` Tom Rini
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2014-10-24 19:06 UTC (permalink / raw)
  To: u-boot

On Thu, Oct 23, 2014 at 01:16:04PM -0600, Simon Glass wrote:

> Provide a CONFIG_DM_STDIO option to enable registering a serial device
> with the stdio library. This is seldom useful in SPL, so disable it by
> default when building for SPL.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Tom Rini <trini@ti.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141024/e1a1e777/attachment.pgp>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 08/13] dm: Disable dm_warn() in SPL
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 08/13] dm: Disable dm_warn() in SPL Simon Glass
@ 2014-10-24 19:07   ` Tom Rini
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2014-10-24 19:07 UTC (permalink / raw)
  To: u-boot

On Thu, Oct 23, 2014 at 01:16:05PM -0600, Simon Glass wrote:

> Since this function can use up quite a bit of space for its strings, disable
> it by default in SPL. Use CONFIG_DM_WARN to re-enable it.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Tom Rini <trini@ti.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141024/28e999e3/attachment.pgp>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 11/13] dm: arm: spl: Make driver model linker lists available
  2014-10-23 19:16 ` [U-Boot] [PATCH v2 11/13] dm: arm: spl: Make driver model linker lists available Simon Glass
@ 2014-10-24 19:08   ` Tom Rini
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2014-10-24 19:08 UTC (permalink / raw)
  To: u-boot

On Thu, Oct 23, 2014 at 01:16:08PM -0600, Simon Glass wrote:

> The linker lists feature is useful in SPL as it holds the driver model
> platform data. So don't throw away the lists.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Tom Rini <trini@ti.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141024/3ad644e8/attachment.pgp>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [U-Boot] [PATCH v2 04/13] dm: spl: Make simple malloc() available when enabled
  2014-10-24 18:59   ` Tom Rini
@ 2014-10-28  0:07     ` Simon Glass
  0 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2014-10-28  0:07 UTC (permalink / raw)
  To: u-boot

Hi Tom,

On 24 October 2014 12:59, Tom Rini <trini@ti.com> wrote:
>
> On Thu, Oct 23, 2014 at 01:16:01PM -0600, Simon Glass wrote:
>
> > Set up the simple malloc() implementation when requested, in preference to
> > the full malloc().
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> > Changes in v2: None
> >
> >  common/spl/spl.c | 11 ++++++++++-
> >  1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/common/spl/spl.c b/common/spl/spl.c
> > index b16664f..7168854 100644
> > --- a/common/spl/spl.c
> > +++ b/common/spl/spl.c
> > @@ -134,9 +134,13 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
> >       u32 boot_device;
> >       debug(">>spl:board_init_r()\n");
> >
> > -#ifdef CONFIG_SYS_SPL_MALLOC_START
> > +#if defined(CONFIG_SYS_SPL_MALLOC_START)
> >       mem_malloc_init(CONFIG_SYS_SPL_MALLOC_START,
> >                       CONFIG_SYS_SPL_MALLOC_SIZE);
> > +     gd->flags |= GD_FLG_FULL_MALLOC_INIT;
> > +#elif defined(CONFIG_SYS_MALLOC_F_LEN)
> > +     gd->malloc_limit = gd->malloc_base + CONFIG_SYS_MALLOC_F_LEN;
> > +     gd->malloc_ptr = 0;
> >  #endif
> >
> >  #ifndef CONFIG_PPC
> > @@ -233,6 +237,11 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
> >       default:
> >               debug("Unsupported OS image.. Jumping nevertheless..\n");
> >       }
> > +#if defined(CONFIG_SYS_MALLOC_F_LEN) && !defined(CONFIG_SYS_SPL_MALLOC_SIZE)
> > +     debug("SPL malloc() used %#lx bytes (%ld KB)\n", gd->malloc_ptr,
> > +           gd->malloc_ptr / 1024);
> > +#endif
> > +
> >       jump_to_image_no_args(&spl_image);
> >  }
>
> I don't know if this is right.  Take the example of am335x + booting
> from a FAT fs image.  We'll need early malloc prior to DDR being
> available, so the tiny space (1-2kb).  But once DDR is up we need a more
> complete malloc so that we can use FAT.  I don't have the size handy but
> I'm going to guess that (a) it's bigger than 1-2kb (b) bigger than we
> can squeeze into SRAM.

Here's the malloc() approach I think we need for each stage:

- SPL: full malloc() if enabled as with FAT support in SPL, else simple malloc()
- U-Boot pre-reloc: simple malloc()
- U-Boot post-reloc: full malloc()

So I think that even in the case you raise we need the simple
malloc(), not for SPL but for U-Boot pre-reloc. I have fiddled with
the logic here a few times while figuring this out, and I suspect we
will refine it. But the intent is to use full malloc() where available
and simple malloc() where not.

Regards,
Simon

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2014-10-28  0:07 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-23 19:15 [U-Boot] [PATCH v2 0/13] dm: Implement driver model support in SPL Simon Glass
2014-10-23 19:15 ` [U-Boot] [PATCH v2 01/13] dm: dts: Move omap device tree includes to correct place Simon Glass
2014-10-24 19:05   ` Tom Rini
2014-10-23 19:15 ` [U-Boot] [PATCH v2 02/13] dm: Split the simple malloc() implementation into its own file Simon Glass
2014-10-24 19:05   ` Tom Rini
2014-10-23 19:16 ` [U-Boot] [PATCH v2 03/13] dm: arm: spl: Allow simple malloc() in SPL Simon Glass
2014-10-23 19:16 ` [U-Boot] [PATCH v2 04/13] dm: spl: Make simple malloc() available when enabled Simon Glass
2014-10-24 18:59   ` Tom Rini
2014-10-28  0:07     ` Simon Glass
2014-10-23 19:16 ` [U-Boot] [PATCH v2 05/13] dm: spl: Allow driver model to be used Simon Glass
2014-10-24 19:06   ` Tom Rini
2014-10-23 19:16 ` [U-Boot] [PATCH v2 06/13] dm: Allow device removal features to be dropped Simon Glass
2014-10-23 19:16 ` [U-Boot] [PATCH v2 07/13] dm: Allow stdio registration " Simon Glass
2014-10-24 19:06   ` Tom Rini
2014-10-23 19:16 ` [U-Boot] [PATCH v2 08/13] dm: Disable dm_warn() in SPL Simon Glass
2014-10-24 19:07   ` Tom Rini
2014-10-23 19:16 ` [U-Boot] [PATCH v2 09/13] dm: tegra: Add platform data for the SPL uart Simon Glass
2014-10-23 19:16 ` [U-Boot] [PATCH v2 10/13] dm: tegra: Add platform data for the GPIO driver Simon Glass
2014-10-23 19:16 ` [U-Boot] [PATCH v2 11/13] dm: arm: spl: Make driver model linker lists available Simon Glass
2014-10-24 19:08   ` Tom Rini
2014-10-23 19:16 ` [U-Boot] [PATCH v2 12/13] dm: tegra: Enable driver model in SPL and adjust the GPIO driver Simon Glass
2014-10-23 19:16 ` [U-Boot] [PATCH v2 13/13] dm: Update documentation to include CONFIG_DM... options Simon Glass
2014-10-23 20:17   ` Masahiro YAMADA
2014-10-24  1:05     ` Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox