Skip to contentSkip to conversation

tegra: warmboot (suspend / resume) support

PATCH Superseded Simon Glass 9 participants 54 messages Apr 2, 2012 – Oct 6, 2012 1 message not in the archive

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover tegra: warmboot (suspend / resume) support

This series adds support for warm boot, allowing the device to suspend and resume. U-Boot sets up some 'warm boot' code in a special area such that the SOC can find it on a resume. This code is responsible for setting up memory and clocked and then allowing the OS to continue where it left off.

Also included here is support for the EMC, which allows setting the memory timings correctly in U-Boot for maximum speed operation.

Note: sign-offs are needed from Jimmy Zhang, Wei Ni and Yen Lin.

Changes in v2:
- Add check of undocumented values in hidrev register
- Add debug() output to EMC
- Add new fdtdec_locate_array() function
- Add patch to find DVC bus number
- Check error return from pmu_set_nominal() in debug mode
- Move EMC tables to device tree
- Move structs shared between A9 and AVP into warmboot.h header file
- New patch to add low-level clock functions
- Rely on compiler to optimise out debug_print_vector()
- Remove unused crypto code
- Remove unused crypto code from crypto.c
- Removed check for nominal voltage (not needed as it is done just before)
- Split PMU code into separate TPS6586X driver
- Tidy SDRAM range check in warmboot_prepare_code()
- Tidy whitespace problems
- Use const for sbox arrays
- Use low-level clock functions in warmboot code instead of register access

Changes in v3:
- Add apb_misc.h header file in new patch
- Add better error reporting when EMC setup fails
- Add new fdtdec_next_compatible_subnode() patch
- Add new patch to put abs() in common.h
- Fix CONFIG_TEGRA_I2C define
- Move abs() macro into common.h
- Support nvidia,use-ram-code binding option for EMC
- Try to return a useful error code when EMC config fails

Jimmy Zhang (3):
tegra: Add EMC support for optimal memory timings
tegra: Add PMU to manage power supplies
tegra: Add EMC settings for Seaboard

Simon Glass (14):
fdt: Add function to locate an array in the device tree
fdt: Add function to return next compatible subnode Add abs() macro to return absolute value
i2c: Add TPS6586X driver
tegra: Move ap20.h header into arch location
tegra: Add functions to access low-level Osc/PLL details
tegra: Add tegra_get_chip_type() to detect SKU
tegra: Add header file for APB_MISC register
tegra: Set up PMU for Nvidia boards
tegra: Set up warmboot code on Nvidia boards
fdt: tegra: Add EMC node to device tree
tegra: i2c: Add function to find DVC bus
tegra: fdt: Add EMC data for Tegra2 Seaboard
tegra: Enable LP0 on Seaboard

Wei Ni (1):
tegra: Turn off power detect in board init

Yen Lin (5):
Add AES crypto library
tegra: Add crypto library for warmboot code
tegra: Add flow, gp_padctl, fuse, sdram headers
tegra: Add warmboot implementation
tegra: Setup PMC scratch info from ap20 setup

 arch/arm/cpu/armv7/tegra2/Makefile                 |    4 +
 arch/arm/cpu/armv7/tegra2/ap20.c                   |   44 ++-
 arch/arm/cpu/armv7/tegra2/board.c                  |    4 +-
 arch/arm/cpu/armv7/tegra2/clock.c                  |   32 +
 arch/arm/cpu/armv7/tegra2/crypto.c                 |  230 ++++++++
 arch/arm/cpu/armv7/tegra2/crypto.h                 |   36 ++
 arch/arm/cpu/armv7/tegra2/emc.c                    |  286 ++++++++++
 arch/arm/cpu/armv7/tegra2/pmu.c                    |   70 +++
 arch/arm/cpu/armv7/tegra2/warmboot.c               |  382 +++++++++++++
 arch/arm/cpu/armv7/tegra2/warmboot_avp.c           |  250 ++++++++
 arch/arm/cpu/armv7/tegra2/warmboot_avp.h           |   81 +++
 arch/arm/dts/tegra20.dtsi                          |    7 +
 .../tegra2 => include/asm/arch-tegra2}/ap20.h      |    7 +
 arch/arm/include/asm/arch-tegra2/apb_misc.h        |   36 ++
 arch/arm/include/asm/arch-tegra2/clk_rst.h         |    3 +
 arch/arm/include/asm/arch-tegra2/clock.h           |   22 +
 arch/arm/include/asm/arch-tegra2/emc.h             |  113 ++++
 arch/arm/include/asm/arch-tegra2/flow.h            |   36 ++
 arch/arm/include/asm/arch-tegra2/fuse.h            |   39 ++
 arch/arm/include/asm/arch-tegra2/gp_padctrl.h      |   73 +++
 arch/arm/include/asm/arch-tegra2/pmu.h             |   30 +
 arch/arm/include/asm/arch-tegra2/sdram_param.h     |  148 +++++
 arch/arm/include/asm/arch-tegra2/tegra2.h          |   25 +
 arch/arm/include/asm/arch-tegra2/tegra_i2c.h       |    7 +
 arch/arm/include/asm/arch-tegra2/warmboot.h        |  150 +++++
 board/nvidia/common/Makefile                       |    1 +
 board/nvidia/common/board.c                        |   41 ++-
 board/nvidia/common/emc.c                          |   53 ++
 board/nvidia/common/emc.h                          |   29 +
 board/nvidia/dts/tegra2-seaboard.dts               |   72 +++
 drivers/i2c/tegra_i2c.c                            |   14 +
 drivers/power/Makefile                             |    1 +
 drivers/power/tps6586x.c                           |  280 +++++++++
 include/aes.h                                      |   70 +++
 include/common.h                                   |   13 +
 include/configs/seaboard.h                         |    8 +
 include/configs/tegra2-common.h                    |   17 +
 include/fdtdec.h                                   |   38 ++
 include/tps6586x.h                                 |   68 +++
 lib/Makefile                                       |    1 +
 lib/aes.c                                          |  598 ++++++++++++++++++++
 lib/fdtdec.c                                       |   28 +
 42 files changed, 3443 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/cpu/armv7/tegra2/crypto.c
 create mode 100644 arch/arm/cpu/armv7/tegra2/crypto.h
 create mode 100644 arch/arm/cpu/armv7/tegra2/emc.c
 create mode 100644 arch/arm/cpu/armv7/tegra2/pmu.c
 create mode 100644 arch/arm/cpu/armv7/tegra2/warmboot.c
 create mode 100644 arch/arm/cpu/armv7/tegra2/warmboot_avp.c
 create mode 100644 arch/arm/cpu/armv7/tegra2/warmboot_avp.h
 rename arch/arm/{cpu/armv7/tegra2 => include/asm/arch-tegra2}/ap20.h (96%)
 create mode 100644 arch/arm/include/asm/arch-tegra2/apb_misc.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/emc.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/flow.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/fuse.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/gp_padctrl.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/pmu.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/sdram_param.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/warmboot.h
 create mode 100644 board/nvidia/common/emc.c
 create mode 100644 board/nvidia/common/emc.h
 create mode 100644 drivers/power/tps6586x.c
 create mode 100644 include/aes.h
 create mode 100644 include/tps6586x.h
 create mode 100644 lib/aes.c
Signature · 1 line
1.7.7.3

A message that is not in the archive (sent off-list or not yet received): 1333408743-28720-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org

#2 lore raw

PATCH v3 1/23 fdt: Add function to locate an array in the device tree

fdtdec_locate_array() locates an integer array but does not copy it. This saves the caller having to allocated wasted space.

Access to array elements should be through the fdt32_to_cpu() macro.

---
Changes in v2:
- Add new fdtdec_locate_array() function

 include/fdtdec.h |   19 +++++++++++++++++++
 lib/fdtdec.c     |   11 +++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
include/fdtdec.h +19 -0
index 171c628..84f0768 100644
@@ -272,6 +272,25 @@ int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
 		u32 *array, int count);
 
 /**
+ * Look up a property in a node and return a pointer to its contents as a
+ * unsigned int array of given length. The property must have at least enough
+ * data for the array ('count' cells). It may have more, but this will be
+ * ignored. The data is not copied.
+ *
+ * Note that you must access elements of the array with fdt32_to_cpu(),
+ * since the elements will be big endian even on a little endian machine.
+ *
+ * @param blob		FDT blob
+ * @param node		node to examine
+ * @param prop_name	name of property to find
+ * @param count		number of array elements
+ * @return pointer to array if found, or NULL if the property is not
+ *		found or there is not enough data
+ */
+const u32 *fdtdec_locate_array(const void *blob, int node,
+			       const char *prop_name, int count);
+
+/**
  * Look up a boolean property in a node and return it.
  *
  * A boolean properly is true if present in the device tree and false if not
lib/fdtdec.c +11 -0
index bdec1a0..4a5ab71 100644
@@ -363,6 +363,17 @@ int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
 	return err;
 }
 
+const u32 *fdtdec_locate_array(const void *blob, int node,
+			       const char *prop_name, int count)
+{
+	const u32 *cell;
+	int err;
+
+	cell = get_prop_check_min_len(blob, node, prop_name,
+				      sizeof(u32) * count, &err);
+	return err ? NULL : cell;
+}
+
 int fdtdec_get_bool(const void *blob, int node, const char *prop_name)
 {
 	const s32 *cell;
Signature · 1 line
1.7.7.3
#3 lore raw

PATCH v3 20/23 fdt: tegra: Add EMC node to device tree

In reply to a message not in the archive

Add a definition of the memory controller node according to the bindings here:

http://patchwork.ozlabs.org/patch/132928/

---

 arch/arm/dts/tegra20.dtsi |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
arch/arm/dts/tegra20.dtsi +7 -0
index d5ca02c..bc64f42 100644
@@ -193,4 +193,11 @@
 		clocks = <&tegra_car 59>;	/* PERIPH_ID_USB3 */
 	};
 
+	emc@7000f400 {
+		#address-cells = < 1 >;
+		#size-cells = < 0 >;
+		compatible = "nvidia,tegra20-emc";
+		reg = <0x7000f400 0x200>;
+	};
+
 };
Signature · 1 line
1.7.7.3
#4 lore raw

PATCH v3 22/23 tegra: fdt: Add EMC data for Tegra2 Seaboard

In reply to a message not in the archive

This adds timings for T20 and T25 Seaboards, using the bindings found here:

http://patchwork.ozlabs.org/patch/132928/

We supply both full speed options for normal running, and half speed options for testing / development.

---

 board/nvidia/dts/tegra2-seaboard.dts |   72 ++++++++++++++++++++++++++++++++++
 1 files changed, 72 insertions(+), 0 deletions(-)
board/nvidia/dts/tegra2-seaboard.dts +72 -0
index 6ba3ec4..31e0f9d 100644
@@ -89,4 +89,76 @@
 	i2c@7000c500 {
 		clock-frequency = <100000>;
 	};
+
+	emc@7000f400 {
+		emc-table@166500 {
+			reg = <166500>;
+			compatible = "nvidia,tegra20-emc-table";
+			clock-frequency = < 166500 >;
+			nvidia,emc-registers = < 0x0000000a 0x00000021
+				0x00000008 0x00000003 0x00000004 0x00000004
+				0x00000002 0x0000000c 0x00000003 0x00000003
+				0x00000002 0x00000001 0x00000004 0x00000005
+				0x00000004 0x00000009 0x0000000d 0x000004df
+				0x00000000 0x00000003 0x00000003 0x00000003
+				0x00000003 0x00000001 0x0000000a 0x000000c8
+				0x00000003 0x00000006 0x00000004 0x0000000f
+				0x00000002 0x00000000 0x00000000 0x00000002
+				0x00000000 0x00000000 0x00000083 0xa04004ae
+				0x007fd010 0x00000000 0x00000000 0x00000000
+				0x00000000 0x00000000 0x00000000 0x00000000 >;
+		};
+		emc-table@333000 {
+			reg = <333000>;
+			compatible = "nvidia,tegra20-emc-table";
+			clock-frequency = < 333000 >;
+			nvidia,emc-registers = < 0x00000014 0x00000041
+				0x0000000f 0x00000005 0x00000004 0x00000005
+				0x00000003 0x0000000c 0x00000005 0x00000005
+				0x00000003 0x00000001 0x00000004 0x00000005
+				0x00000004 0x00000009 0x0000000d 0x000009ff
+				0x00000000 0x00000003 0x00000003 0x00000005
+				0x00000005 0x00000001 0x0000000f 0x000000c8
+				0x00000003 0x0000000c 0x00000006 0x0000000f
+				0x00000002 0x00000000 0x00000000 0x00000002
+				0x00000000 0x00000000 0x00000083 0xe034048b
+				0x007e8010 0x00000000 0x00000000 0x00000000
+				0x00000000 0x00000000 0x00000000 0x00000000 >;
+		};
+
+		emc-table@190000 {
+			reg = < 190000 >;
+			compatible = "nvidia,tegra20-emc-table";
+			clock-frequency = < 190000 >;
+			nvidia,emc-registers = < 0x0000000c 0x00000026
+				0x00000009 0x00000003 0x00000004 0x00000004
+				0x00000002 0x0000000c 0x00000003 0x00000003
+				0x00000002 0x00000001 0x00000004 0x00000005
+				0x00000004 0x00000009 0x0000000d 0x0000059f
+				0x00000000 0x00000003 0x00000003 0x00000003
+				0x00000003 0x00000001 0x0000000b 0x000000c8
+				0x00000003 0x00000007 0x00000004 0x0000000f
+				0x00000002 0x00000000 0x00000000 0x00000002
+				0x00000000 0x00000000 0x00000083 0xa06204ae
+				0x007dc010 0x00000000 0x00000000 0x00000000
+				0x00000000 0x00000000 0x00000000 0x00000000 >;
+		};
+		emc-table@380000 {
+			reg = < 380000 >;
+			compatible = "nvidia,tegra20-emc-table";
+			clock-frequency = < 380000 >;
+			nvidia,emc-registers = < 0x00000017 0x0000004b
+				0x00000012 0x00000006 0x00000004 0x00000005
+				0x00000003 0x0000000c 0x00000006 0x00000006
+				0x00000003 0x00000001 0x00000004 0x00000005
+				0x00000004 0x00000009 0x0000000d 0x00000b5f
+				0x00000000 0x00000003 0x00000003 0x00000006
+				0x00000006 0x00000001 0x00000011 0x000000c8
+				0x00000003 0x0000000e 0x00000007 0x0000000f
+				0x00000002 0x00000000 0x00000000 0x00000002
+				0x00000000 0x00000000 0x00000083 0xe044048b
+				0x007d8010 0x00000000 0x00000000 0x00000000
+				0x00000000 0x00000000 0x00000000 0x00000000 >;
+		};
+	};
 };
Signature · 1 line
1.7.7.3
#5 lore raw

Re: [PATCH v3 22/23] tegra: fdt: Add EMC data for Tegra2 Seaboard

Quoted 8 lines · Simon Glass

This adds timings for T20 and T25 Seaboards, using the bindings found here:

http://patchwork.ozlabs.org/patch/132928/

We supply both full speed options for normal running, and half speed options for testing / development.

This seems incorrect to me. You provide both T20 and T25 EMC tables in the same device tree with no way to determine which one to use.

Unfortunately nvidia didn't use the boot straps to tell if they were on a t20 or t25 seaboard, so you'll just have to know. At the kernel side we chose to just ditch T20 since most boards still in use are T25.

-Olof

#6 lore raw

Re: [PATCH v3 22/23] tegra: fdt: Add EMC data for Tegra2 Seaboard

Hi Olof,

Quoted 10 lines · Olof Johansson
Quoted 8 lines · Simon Glass

This adds timings for T20 and T25 Seaboards, using the bindings found here:

http://patchwork.ozlabs.org/patch/132928/

We supply both full speed options for normal running, and half speed options for testing / development.

Quoted 7 lines

This seems incorrect to me. You provide both T20 and T25 EMC tables in the same device tree with no way to determine which one to use.

Unfortunately nvidia didn't use the boot straps to tell if they were on a t20 or t25 seaboard, so you'll just have to know. At the kernel side we chose to just ditch T20 since most boards still in use are T25.

The selection of memory speed is down to the board. There is a later patch in this series (just cc'd to you) which looks at the SOC ID to determine whether it is T20 or T25, and selects the speed accordingly. This speed is used to look up the correct table in the device tree

Quoted 4 lines

-Olof

Regards,
Simon

#7 lore raw

Re: [PATCH v3 22/23] tegra: fdt: Add EMC data for Tegra2 Seaboard

Hi,

Quoted 21 lines · Simon Glass

Hi Olof,

Quoted 10 lines · Olof Johansson
Quoted 8 lines · Simon Glass

This adds timings for T20 and T25 Seaboards, using the bindings found here:

http://patchwork.ozlabs.org/patch/132928/

We supply both full speed options for normal running, and half speed options for testing / development.

Quoted 7 lines

This seems incorrect to me. You provide both T20 and T25 EMC tables in the same device tree with no way to determine which one to use.

Unfortunately nvidia didn't use the boot straps to tell if they were on a t20 or t25 seaboard, so you'll just have to know. At the kernel side we chose to just ditch T20 since most boards still in use are T25.

Quoted 4 lines

The selection of memory speed is down to the board. There is a later patch in this series (just cc'd to you) which looks at the SOC ID to determine whether it is T20 or T25, and selects the speed accordingly. This speed is used to look up the correct table in the device tree

Well if we really want to do this properly we should have a separate device tree file for the T20 Seaboard. Since the kernel has dropped T20 support, we should do the same. I have updated this patch.

Regards,
Simon

Quoted 8 lines
Quoted 5 lines

-Olof

Regards,
Simon

#8 lore raw

PATCH v3 2/23 fdt: Add function to return next compatible subnode

In reply to Simon Glass

We need to iterate through subnodes of a parent, looking only at compatible nodes. Add a utility function to do this for us.

---
Changes in v3:
- Add new fdtdec_next_compatible_subnode() patch

 include/fdtdec.h |   17 +++++++++++++++++
 lib/fdtdec.c     |   15 +++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)
include/fdtdec.h +17 -0
index 84f0768..0351a25 100644
@@ -117,6 +117,23 @@ int fdtdec_next_compatible(const void *blob, int node,
 		enum fdt_compat_id id);
 
 /**
+ * Find the next compatible subnode for a peripheral.
+ *
+ * Do the first call with node set to the parent and depth = 0. This
+ * function will return the offset of the next compatible node. Next time
+ * you call this function, pass the node value returned last time, with
+ * depth unchanged, and the next node will be provided.
+ *
+ * @param blob		FDT blob to use
+ * @param node		Start node for search
+ * @param id		Compatible ID to look for (enum fdt_compat_id)
+ * @param depthp	Current depth (set to 0 before first call)
+ * @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more
+ */
+int fdtdec_next_compatible_subnode(const void *blob, int node,
+		enum fdt_compat_id id, int *depthp);
+
+/**
  * Look up an address property in a node and return it as an address.
  * The property must hold either one address with no trailing data or
  * one address with a length. This is only tested on 32-bit machines.
lib/fdtdec.c +15 -0
index 4a5ab71..76d3808 100644
@@ -133,6 +133,21 @@ int fdtdec_next_compatible(const void *blob, int node,
 	return fdt_node_offset_by_compatible(blob, node, compat_names[id]);
 }
 
+int fdtdec_next_compatible_subnode(const void *blob, int node,
+		enum fdt_compat_id id, int *depthp)
+{
+	do {
+		node = fdt_next_node(blob, node, depthp);
+	} while (*depthp > 1);
+
+	/* If this is a direct subnode, and compatible, return it */
+	if (*depthp == 1 && 0 == fdt_node_check_compatible(
+						blob, node, compat_names[id]))
+		return node;
+
+	return -FDT_ERR_NOTFOUND;
+}
+
 int fdtdec_next_alias(const void *blob, const char *name,
 		enum fdt_compat_id id, int *upto)
 {
Signature · 1 line
1.7.7.3
#9 lore raw

PATCH v3 3/23 Add abs() macro to return absolute value

In reply to Simon Glass

This macro is generally useful to make it available in common.

---
Changes in v3:
- Add new patch to put abs() in common.h

 include/common.h |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
include/common.h +13 -0
index 74d9704..92eac2c 100644
@@ -229,6 +229,19 @@ ulong timer_get_boot_us(void);
 #define MIN(x, y)  min(x, y)
 #define MAX(x, y)  max(x, y)
 
+/*
+ * Return the absolute value of a number. This handles unsigned ints, shorts
+ * and chars and returns a signed long.
+ */
+#define abs(x) ({					\
+		long ret;				\
+		{					\
+			typeof((x)) __x = (x);		\
+			ret = (__x < 0) ? -__x : __x;	\
+		}					\
+		ret;					\
+	})
+
 #if defined(CONFIG_ENV_IS_EMBEDDED)
 #define TOTAL_MALLOC_LEN	CONFIG_SYS_MALLOC_LEN
 #elif ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \
Signature · 1 line
1.7.7.3
#10 lore raw

PATCH v3 4/23 i2c: Add TPS6586X driver

In reply to Simon Glass

This power management chip supports battery charging and a large number of power supplies. This initial driver only provides the ability to adjust the two synchronous buck converters SM0 and SM1 in a stepwise manner.

---
Changes in v2:
- Split PMU code into separate TPS6586X driver

Changes in v3:
- Move abs() macro into common.h

 drivers/power/Makefile   |    1 +
 drivers/power/tps6586x.c |  280 ++++++++++++++++++++++++++++++++++++++++++++++
 include/tps6586x.h       |   68 +++++++++++
 3 files changed, 349 insertions(+), 0 deletions(-)
 create mode 100644 drivers/power/tps6586x.c
 create mode 100644 include/tps6586x.h
drivers/power/Makefile +1 -0
index ead00f8..e327688 100644
@@ -26,6 +26,7 @@ include $(TOPDIR)/config.mk
 LIB 	:= $(obj)libpower.o
 
 COBJS-$(CONFIG_FTPMU010_POWER)	+= ftpmu010.o
+COBJS-$(CONFIG_TPS6586X_POWER)	+= tps6586x.o
 COBJS-$(CONFIG_TWL4030_POWER)	+= twl4030.o
 COBJS-$(CONFIG_TWL6030_POWER)	+= twl6030.o
 
drivers/power/tps6586x.c new file +280 -0

280 lines not on this page · raw message

include/tps6586x.h new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#11 lore raw

PATCH v3 4/23 i2c: Add TPS6586X driver

Quoted 8 lines · Simon Glass

This power management chip supports battery charging and a large number of power supplies. This initial driver only provides the ability to adjust the two synchronous buck converters SM0 and SM1 in a stepwise manner.

drivers/power/tps6586x.c new file +2 -0
+#define MAX_I2C_RETRY	3
+int tps6586x_read(int reg)

...

drivers/power/tps6586x.c line 69

Quoted 9 lines
drivers/power/tps6586x.c new file +9 -0
+	for (i = 0; i < MAX_I2C_RETRY; ++i) {
+		if (!i2c_read(I2C_ADDRESS, reg, 1, &data, 1)) {
+			retval = (int)data;
+			goto exit;
+		}
+
+		/* i2c access failed, retry */
+		udelay(100);
+	}

Why do we need this retry logic; the kernel driver doesn't appear to have this.

#12 lore raw

PATCH v3 4/23 i2c: Add TPS6586X driver

Hi Stephen,

Quoted 20 lines · Stephen Warren
Quoted 8 lines · Simon Glass

This power management chip supports battery charging and a large number of power supplies. This initial driver only provides the ability to adjust the two synchronous buck converters SM0 and SM1 in a stepwise manner.

(quoted diff) +2 -0
+#define MAX_I2C_RETRY ? ? ? ?3
+int tps6586x_read(int reg)

...

Quoted 9 lines

+ ? ? for (i = 0; i < MAX_I2C_RETRY; ++i) {
+ ? ? ? ? ? ? if (!i2c_read(I2C_ADDRESS, reg, 1, &data, 1)) {
+ ? ? ? ? ? ? ? ? ? ? retval = (int)data;
+ ? ? ? ? ? ? ? ? ? ? goto exit;
+ ? ? ? ? ? ? }
+
+ ? ? ? ? ? ? /* i2c access failed, retry */
+ ? ? ? ? ? ? udelay(100);
+ ? ? }

Quoted 2 lines

Why do we need this retry logic; the kernel driver doesn't appear to have this.

We apparently have found the device to be flaky on i2c sometimes, which is why this is here.

Regards,
Simon

#13 lore raw

PATCH v3 4/23 i2c: Add TPS6586X driver

Quoted 23 lines · Simon Glass

Hi Stephen,

Quoted 20 lines · Stephen Warren
Quoted 8 lines · Simon Glass

This power management chip supports battery charging and a large number of power supplies. This initial driver only provides the ability to adjust the two synchronous buck converters SM0 and SM1 in a stepwise manner.

drivers/power/tps6586x.c new file +2 -0
+#define MAX_I2C_RETRY        3
+int tps6586x_read(int reg)

...

Quoted 9 lines
drivers/power/tps6586x.c new file +9 -0
+     for (i = 0; i < MAX_I2C_RETRY; ++i) {
+             if (!i2c_read(I2C_ADDRESS, reg, 1, &data, 1)) {
+                     retval = (int)data;
+                     goto exit;
+             }
+
+             /* i2c access failed, retry */
+             udelay(100);
+     }
Quoted 5 lines
Quoted 2 lines

Why do we need this retry logic; the kernel driver doesn't appear to have this.

We apparently have found the device to be flaky on i2c sometimes, which is why this is here.

Is it the device itself, or bad board layout/...? Do we need something similar in the kernel?

In general though, if we're having problems communicating with the PMIC, we're pretty screwed; how do we know whether failed transactions simply fail (e.g. no ACK), or send bogus data to the PMIC (e.g. set some random register so that something gets programmed to be over-voltage)? A better solution might be a full system reset when you fail to communicate with the PMIC.

#14 lore raw

PATCH v3 4/23 i2c: Add TPS6586X driver

+Jimmy, who wrote the original pmu code

Hi Stephen,

Quoted 24 lines · Stephen Warren
Quoted 23 lines · Simon Glass

Hi Stephen,

Quoted 20 lines · Stephen Warren
Quoted 8 lines · Simon Glass

This power management chip supports battery charging and a large number of power supplies. This initial driver only provides the ability to adjust the two synchronous buck converters SM0 and SM1 in a stepwise manner.

(quoted diff) +2 -0
+#define MAX_I2C_RETRY ? ? ? ?3
+int tps6586x_read(int reg)

...

Quoted 9 lines

+ ? ? for (i = 0; i < MAX_I2C_RETRY; ++i) {
+ ? ? ? ? ? ? if (!i2c_read(I2C_ADDRESS, reg, 1, &data, 1)) {
+ ? ? ? ? ? ? ? ? ? ? retval = (int)data;
+ ? ? ? ? ? ? ? ? ? ? goto exit;
+ ? ? ? ? ? ? }
+
+ ? ? ? ? ? ? /* i2c access failed, retry */
+ ? ? ? ? ? ? udelay(100);
+ ? ? }

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Why do we need this retry logic; the kernel driver doesn't appear to have this.

We apparently have found the device to be flaky on i2c sometimes, which is why this is here.

Is it the device itself, or bad board layout/...? Do we need something similar in the kernel?

I am not sure - Jimmy do you know?

Quoted 7 lines

In general though, if we're having problems communicating with the PMIC, we're pretty screwed; how do we know whether failed transactions simply fail (e.g. no ACK), or send bogus data to the PMIC (e.g. set some random register so that something gets programmed to be over-voltage)? A better solution might be a full system reset when you fail to communicate with the PMIC.

I believe the problem is that there is no ACK - it would be pretty bad if it ACKed but didn't work :-)

Regards,
Simon

#15 lore raw

PATCH v3 5/23 Add AES crypto library

In reply to Simon Glass

From: Yen Lin <[email protected]>

Add support for AES using an implementation form Karl Malbrain. This offers small code size (around 5KB on ARM) and supports 128-bit AES only.

---
Changes in v2:
- Tidy whitespace problems
- Use const for sbox arrays

 include/aes.h |   70 +++++++
 lib/Makefile  |    1 +
 lib/aes.c     |  598 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 669 insertions(+), 0 deletions(-)
 create mode 100644 include/aes.h
 create mode 100644 lib/aes.c
include/aes.h new file +70 -0
new file mode 100644
index 0000000..41b0db2
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * (C) Copyright 2010 - 2011 NVIDIA Corporation <www.nvidia.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _AES_REF_H_
+#define _AES_REF_H_
+
+/*
+ * AES encryption library, with small code size, supporting only 128-bit AES
+ *
+ * AES is a stream cipher which works a block at a time, with each block
+ * in this case being AES_KEY_LENGTH bytes.
+ */
+
+enum {
+	AES_STATECOLS	= 4,	/* columns in the state & expanded key */
+	AES_KEYCOLS	= 4,	/* columns in a key */
+	AES_ROUNDS	= 10,	/* rounds in encryption */
+
+	AES_KEY_LENGTH	= 128 / 8,
+	AES_EXPAND_KEY_LENGTH	= 4 * AES_STATECOLS * (AES_ROUNDS + 1),
+};
+
+/**
+ * Expand a key into a key schedule, which is then used for the other
+ * operations.
+ *
+ * \param key		Key, of length AES_KEY_LENGTH bytes
+ * \param expkey	Buffer to place expanded key, AES_EXPAND_KEY_LENGTH
+ */
+void aes_expand_key(u8 *key, u8 *expkey);
+
+/**
+ * Encrypt a single block of data
+ *
+ * in		Input data
+ * expkey	Expanded key to use for encryption (from aes_expand_key())
+ * out		Output data
+ */
+void aes_encrypt(u8 *in, u8 *expkey, u8 *out);
+
+/**
+ * Decrypt a single block of data
+ *
+ * in		Input data
+ * expkey	Expanded key to use for decryption (from aes_expand_key())
+ * out		Output data
+ */
+void aes_decrypt(u8 *in, u8 *expkey, u8 *out);
+
+#endif /* _AES_REF_H_ */
lib/Makefile +1 -0
index a0fec60..1e8478f 100644
@@ -28,6 +28,7 @@ LIB	= $(obj)libgeneric.o
 ifndef CONFIG_SPL_BUILD
 COBJS-$(CONFIG_ADDR_MAP) += addr_map.o
 COBJS-$(CONFIG_BCH) += bch.o
+COBJS-$(CONFIG_AES) += aes.o
 COBJS-$(CONFIG_BZIP2) += bzlib.o
 COBJS-$(CONFIG_BZIP2) += bzlib_crctable.o
 COBJS-$(CONFIG_BZIP2) += bzlib_decompress.o
lib/aes.c new file +598 -0

598 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#16 lore raw

PATCH v3 5/23 Add AES crypto library

Hi Simon,

Quoted 6 lines · Simon Glass

From: Yen Lin <[email protected]>

Add support for AES using an implementation form Karl Malbrain. This offers small code size (around 5KB on ARM) and supports 128-bit AES only.

Could you fix "form" to "from"?

Regards,
Yen

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

#17 lore raw

PATCH v3 5/23 Add AES crypto library

Hi Yen,

Quoted 11 lines · Yen Lin

Hi Simon,

Quoted 6 lines · Simon Glass

From: Yen Lin <[email protected]>

Add support for AES using an implementation form Karl Malbrain. This offers small code size (around 5KB on ARM) and supports 128-bit AES only.

Could you fix "form" to "from"?

done - I will update this patch.

Quoted 7 lines

Regards,
Yen

Quoted 6 lines

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. ?Any unauthorized review, use, disclosure or distribution is prohibited. ?If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

Regards,
Simon

#18 lore raw

PATCH v3 6/23 tegra: Move ap20.h header into arch location

In reply to Simon Glass

We want to include this from board code, so move the header into an easily-accessible location.

---

 arch/arm/cpu/armv7/tegra2/ap20.c                   |    2 +-
 arch/arm/cpu/armv7/tegra2/board.c                  |    4 ++--
 .../tegra2 => include/asm/arch-tegra2}/ap20.h      |    0
 3 files changed, 3 insertions(+), 3 deletions(-)
 rename arch/arm/{cpu/armv7/tegra2 => include/asm/arch-tegra2}/ap20.h (100%)
arch/arm/cpu/armv7/tegra2/ap20.c +1 -1
index b749821..a6dd3e4 100644
@@ -21,9 +21,9 @@
 * MA 02111-1307 USA
 */
 
-#include "ap20.h"
 #include <asm/io.h>
 #include <asm/arch/tegra2.h>
+#include <asm/arch/ap20.h>
 #include <asm/arch/clk_rst.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/pmc.h>
arch/arm/cpu/armv7/tegra2/board.c +2 -2
index a797e6f..a50b1b9 100644
@@ -23,12 +23,12 @@
 
 #include <common.h>
 #include <asm/io.h>
-#include "ap20.h"
+#include <asm/arch/ap20.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/funcmux.h>
+#include <asm/arch/pmc.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/arch/tegra2.h>
-#include <asm/arch/pmc.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
arch/arm/include/asm/arch-tegra2/ap20.h renamed from arch/arm/cpu/armv7/tegra2/ap20.h +0 -0
similarity index 100%
rename from arch/arm/cpu/armv7/tegra2/ap20.h
rename to arch/arm/include/asm/arch-tegra2/ap20.h
Signature · 1 line
1.7.7.3
#19 lore raw

PATCH v3 6/23 tegra: Move ap20.h header into arch location

arch/arm/cpu/armv7/tegra2/board.c line 29

Quoted 8 lines · Simon Glass

We want to include this from board code, so move the header into an easily-accessible location.

arch/arm/cpu/armv7/tegra2/board.c +1 -0
 
+#include <asm/arch/pmc.h>

That seems unrelated.

#20 lore raw

PATCH v3 6/23 tegra: Move ap20.h header into arch location

In reply to Simon Glass

arch/arm/cpu/armv7/tegra2/ap20.c line 26

Quoted 9 lines · Simon Glass

We want to include this from board code, so move the header into an easily-accessible location.

arch/arm/cpu/armv7/tegra2/ap20.c +1 -1
 
-#include "ap20.h"
 #include <asm/io.h>
 #include <asm/arch/tegra2.h>
+#include <asm/arch/ap20.h>

BTW, why do we have separate tegra2.h and ap20.h?

#21 lore raw

PATCH v3 6/23 tegra: Move ap20.h header into arch location

Hi Stephen,

Quoted 4 lines · Stephen Warren
Quoted 2 lines · Simon Glass

We want to include this from board code, so move the header into an easily-accessible location.

Quoted 8 lines
Quoted 6 lines
arch/arm/cpu/armv7/tegra2/ap20.c +0 -1
 
-#include "ap20.h"

?#include <asm/io.h>
?#include <asm/arch/tegra2.h>
+#include <asm/arch/ap20.h>

BTW, why do we have separate tegra2.h and ap20.h?

I'm not sure - was ap20 the old name? Tom do you know? For now we use ap20 as the interface to the AVP side, and where we start up the A9.

Regards,
Simon

#22 lore raw

PATCH v3 6/23 tegra: Move ap20.h header into arch location

Simon/Stephen,

Quoted 25 lines

-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: Monday, April 09, 2012 2:24 PM
To: Stephen Warren
Cc: U-Boot Mailing List; Tom Warren
Subject: Re: [PATCH v3 06/23] tegra: Move ap20.h header into arch location

Hi Stephen,

Quoted 7 lines · Stephen Warren
Quoted 5 lines · Simon Glass

We want to include this from board code, so move the header into an easily-accessible location.

arch/arm/cpu/armv7/tegra2/ap20.c +0 -0
Quoted 6 lines
Quoted 4 lines

-#include "ap20.h"
?#include <asm/io.h>
?#include <asm/arch/tegra2.h>
+#include <asm/arch/ap20.h>

BTW, why do we have separate tegra2.h and ap20.h?

Quoted 2 lines

I'm not sure - was ap20 the old name? Tom do you know? For now we use ap20 as the interface to the AVP side, and where we start up the A9.

AP20 is the name of one classification/sku/bin/type of Tegra20 chip - Application Processor, IIRC. Usually AP20 and T20 are used interchangeably. The history of ap20.h is messy - it came from our Embedded group originally and was ported to U-Boot by stripping out all the NV-proprietary-API cruft, changing CamelCase var/func names, to U-Boot-compliant code, etc. At this point, it might be able to be merged w/tegra2.h, but tegra2.h is more general to the entire chip and its periphs, and ap20.h is more specific to the CPU(s) and AVP/CPU init. But I won't object to a merger.

Tom

Quoted 3 lines

Regards,
Simon

Signature · 1 line
nvpublic
#23 lore raw

PATCH v3 6/23 tegra: Move ap20.h header into arch location

Hi Tom,

Quoted 27 lines · Tom Warren

Simon/Stephen,

Quoted 25 lines

-----Original Message-----
From: sjg at google.com [mailto:sjg at google.com] On Behalf Of Simon Glass
Sent: Monday, April 09, 2012 2:24 PM
To: Stephen Warren
Cc: U-Boot Mailing List; Tom Warren
Subject: Re: [PATCH v3 06/23] tegra: Move ap20.h header into arch location

Hi Stephen,

Quoted 13 lines · Stephen Warren
Quoted 10 lines · Simon Glass

We want to include this from board code, so move the header into an easily-accessible location.

arch/arm/cpu/armv7/tegra2/ap20.c +0 -1
 
-#include "ap20.h"

?#include <asm/io.h>
?#include <asm/arch/tegra2.h>
+#include <asm/arch/ap20.h>

BTW, why do we have separate tegra2.h and ap20.h?

Quoted 3 lines
Quoted 2 lines

I'm not sure - was ap20 the old name? Tom do you know? For now we use ap20 as the interface to the AVP side, and where we start up the A9.

AP20 is the name of one classification/sku/bin/type of Tegra20 chip - Application Processor, IIRC. Usually AP20 and T20 are used interchangeably. The history of ap20.h is messy - it came from our Embedded group originally and was ported to U-Boot by stripping out all the NV-proprietary-API cruft, changing CamelCase var/func names, to U-Boot-compliant code, etc. ?At this point, it might be able to be merged w/tegra2.h, but tegra2.h is more general to the entire chip and its periphs, and ap20.h is more specific to the CPU(s) and AVP/CPU init. ?But I won't object to a merger.

Thanks for that. Perhaps we should rename it to avp or cpu_init. Something to think about.

Quoted 7 lines

Tom

Quoted 3 lines

Regards,
Simon

--
nvpublic

Regards,
Simon

#24 lore raw

PATCH v3 6/23 tegra: Move ap20.h header into arch location

In reply to Simon Glass
Quoted 16 lines · Simon Glass

Hi Stephen,

Quoted 4 lines · Stephen Warren
Quoted 2 lines · Simon Glass

We want to include this from board code, so move the header into an easily-accessible location.

Quoted 8 lines

arch/arm/cpu/armv7/tegra2/ap20.c line 26

Quoted 6 lines
arch/arm/cpu/armv7/tegra2/ap20.c +1 -1
 
-#include "ap20.h"
 #include <asm/io.h>
 #include <asm/arch/tegra2.h>
+#include <asm/arch/ap20.h>

BTW, why do we have separate tegra2.h and ap20.h?

Quoted 2 lines

I'm not sure - was ap20 the old name? Tom do you know? For now we use ap20 as the interface to the AVP side, and where we start up the A9.

AP20 and T20 are different SKUs of Tegra 2/Tegra20.

#25 lore raw

PATCH v3 7/23 tegra: Add functions to access low-level Osc/PLL details

In reply to Simon Glass

Add clock_ll_read_pll() to read PLL parameters and clock_get_osc_bypass() to find out if the Oscillator is bypassed. These are needed by warmboot.

---
Changes in v2:
- New patch to add low-level clock functions

 arch/arm/cpu/armv7/tegra2/clock.c          |   32 ++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-tegra2/clk_rst.h |    3 ++
 arch/arm/include/asm/arch-tegra2/clock.h   |   22 +++++++++++++++++++
 3 files changed, 57 insertions(+), 0 deletions(-)
arch/arm/cpu/armv7/tegra2/clock.c +32 -0
index 39376ab..b6b3210 100644
@@ -410,6 +410,16 @@ enum clock_osc_freq clock_get_osc_freq(void)
 	return (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
 }
 
+int clock_get_osc_bypass(void)
+{
+	struct clk_rst_ctlr *clkrst =
+			(struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
+	u32 reg;
+
+	reg = readl(&clkrst->crc_osc_ctrl);
+	return (reg & OSC_XOBP_MASK) >> OSC_XOBP_SHIFT;
+}
+
 /* Returns a pointer to the registers of the given pll */
 static struct clk_pll *get_pll(enum clock_id clkid)
 {
@@ -420,6 +430,28 @@ static struct clk_pll *get_pll(enum clock_id clkid)
 	return &clkrst->crc_pll[clkid];
 }
 
+int clock_ll_read_pll(enum clock_id clkid, u32 *divm, u32 *divn,
+		u32 *divp, u32 *cpcon, u32 *lfcon)
+{
+	struct clk_pll *pll = get_pll(clkid);
+	u32 data;
+
+	assert(clkid != CLOCK_ID_USB);
+
+	/* Safety check, adds to code size but is small */
+	if (!clock_id_isvalid(clkid) || clkid == CLOCK_ID_USB)
+		return -1;
+	data = readl(&pll->pll_base);
+	*divm = (data & PLL_DIVM_MASK) >> PLL_DIVM_SHIFT;
+	*divn = (data & PLL_DIVN_MASK) >> PLL_DIVN_SHIFT;
+	*divp = (data & PLL_DIVP_MASK) >> PLL_DIVP_SHIFT;
+	data = readl(&pll->pll_misc);
+	*cpcon = (data & PLL_CPCON_MASK) >> PLL_CPCON_SHIFT;
+	*lfcon = (data & PLL_LFCON_MASK) >> PLL_LFCON_SHIFT;
+
+	return 0;
+}
+
 unsigned long clock_start_pll(enum clock_id clkid, u32 divm, u32 divn,
 		u32 divp, u32 cpcon, u32 lfcon)
 {
arch/arm/include/asm/arch-tegra2/clk_rst.h +3 -0
index 415e420..8c3be91 100644
@@ -117,6 +117,7 @@ struct clk_rst_ctlr {
 #define PLL_CPCON_MASK		(15U << PLL_CPCON_SHIFT)
 
 #define PLL_LFCON_SHIFT		4
+#define PLL_LFCON_MASK		(15U << PLL_LFCON_SHIFT)
 
 #define PLLU_VCO_FREQ_SHIFT	20
 #define PLLU_VCO_FREQ_MASK	(1U << PLLU_VCO_FREQ_SHIFT)
@@ -124,6 +125,8 @@ struct clk_rst_ctlr {
 /* CLK_RST_CONTROLLER_OSC_CTRL_0 */
 #define OSC_FREQ_SHIFT		30
 #define OSC_FREQ_MASK		(3U << OSC_FREQ_SHIFT)
+#define OSC_XOBP_SHIFT		1
+#define OSC_XOBP_MASK		(1U << OSC_XOBP_SHIFT)
 
 /*
  * CLK_RST_CONTROLLER_CLK_SOURCE_x_OUT_0 - the mask here is normally 8 bits
arch/arm/include/asm/arch-tegra2/clock.h +22 -0
index 6b12c76..1d3ae38 100644
@@ -210,6 +210,21 @@ enum clock_osc_freq clock_get_osc_freq(void);
 unsigned long clock_start_pll(enum clock_id id, u32 divm, u32 divn,
 		u32 divp, u32 cpcon, u32 lfcon);
 
+/**
+ * Read low-level parameters of a PLL.
+ *
+ * @param id	clock id to read (note: USB is not supported)
+ * @param divm	returns input divider
+ * @param divn	returns feedback divider
+ * @param divp	returns post divider 2^n
+ * @param cpcon	returns charge pump setup control
+ * @param lfcon	returns loop filter setup control
+ *
+ * @returns 0 if ok, -1 on error (invalid clock id)
+ */
+int clock_ll_read_pll(enum clock_id clkid, u32 *divm, u32 *divn,
+		      u32 *divp, u32 *cpcon, u32 *lfcon);
+
 /*
  * Enable a clock
  *
@@ -368,6 +383,13 @@ void clock_ll_start_uart(enum periph_id periph_id);
  */
 enum periph_id clock_decode_periph_id(const void *blob, int node);
 
+/**
+ * Checks if the oscillator bypass is enabled (XOBP bit)
+ *
+ * @return 1 if bypass is enabled, 0 if not
+ */
+int clock_get_osc_bypass(void);
+
 /*
  * Checks that clocks are valid and prints a warning if not
  *
Signature · 1 line
1.7.7.3
#26 lore raw

PATCH v3 8/23 tegra: Add crypto library for warmboot code

In reply to Simon Glass

From: Yen Lin <[email protected]>

Provides an interface to aes.c for the warmboot code.

---
Changes in v2:
- Rely on compiler to optimise out debug_print_vector()
- Remove unused crypto code from crypto.c

 arch/arm/cpu/armv7/tegra2/crypto.c |  230 ++++++++++++++++++++++++++++++++++++
 arch/arm/cpu/armv7/tegra2/crypto.h |   36 ++++++
 2 files changed, 266 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/cpu/armv7/tegra2/crypto.c
 create mode 100644 arch/arm/cpu/armv7/tegra2/crypto.h
arch/arm/cpu/armv7/tegra2/crypto.c new file +230 -0
new file mode 100644
index 0000000..5f0b240
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * (C) Copyright 2010 - 2011 NVIDIA Corporation <www.nvidia.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <asm/errno.h>
+#include "crypto.h"
+#include "aes.h"
+
+static u8 zero_key[16];
+
+#define AES_CMAC_CONST_RB 0x87  /* from RFC 4493, Figure 2.2 */
+
+enum security_op {
+	SECURITY_SIGN		= 1 << 0,	/* Sign the data */
+	SECURITY_ENCRYPT	= 1 << 1,	/* Encrypt the data */
+};
+
+static void debug_print_vector(char *name, u32 num_bytes, u8 *data)
+{
+	u32 i;
+
+	debug("%s [%d] @0x%08x", name, num_bytes, (u32)data);
+	for (i = 0; i < num_bytes; i++) {
+		if (i % 16 == 0)
+			debug(" = ");
+		debug("%02x", data[i]);
+		if ((i+1) % 16 != 0)
+			debug(" ");
+	}
+	debug("\n");
+}
+
+/**
+ * Apply chain data to the destination using EOR
+ *
+ * Each array is of length AES_AES_KEY_LENGTH.
+ *
+ * \param cbc_chain_data	Chain data
+ * \param src			Source data
+ * \param dst			Destination data, which is modified here
+ */
+static void apply_cbc_chain_data(u8 *cbc_chain_data, u8 *src, u8 *dst)
+{
+	int i;
+
+	for (i = 0; i < 16; i++)
+		*dst++ = *src++ ^ *cbc_chain_data++;
+}
+
+/**
+ * Encrypt some data with AES.
+ *
+ * \param key_schedule		Expanded key to use
+ * \param src			Source data to encrypt
+ * \param dst			Destination buffer
+ * \param num_aes_blocks	Number of AES blocks to encrypt
+ */
+static void encrypt_object(u8 *key_schedule, u8 *src, u8 *dst,
+			   u32 num_aes_blocks)
+{
+	u8 tmp_data[AES_KEY_LENGTH];
+	u8 *cbc_chain_data;
+	u32 i;
+
+	cbc_chain_data = zero_key;	/* Convenient array of 0's for IV */
+
+	for (i = 0; i < num_aes_blocks; i++) {
+		debug("encrypt_object: block %d of %d\n", i, num_aes_blocks);
+		debug_print_vector("AES Src", AES_KEY_LENGTH, src);
+
+		/* Apply the chain data */
+		apply_cbc_chain_data(cbc_chain_data, src, tmp_data);
+		debug_print_vector("AES Xor", AES_KEY_LENGTH, tmp_data);
+
+		/* encrypt the AES block */
+		aes_encrypt(tmp_data, key_schedule, dst);
+		debug_print_vector("AES Dst", AES_KEY_LENGTH, dst);
+
+		/* Update pointers for next loop. */
+		cbc_chain_data = dst;
+		src += AES_KEY_LENGTH;
+		dst += AES_KEY_LENGTH;
+	}
+}
+
+/**
+ * Shift a vector left by one bit
+ *
+ * \param in	Input vector
+ * \param out	Output vector
+ * \param size	Length of vector in bytes
+ */
+static void left_shift_vector(u8 *in, u8 *out, int size)
+{
+	int carry = 0;
+	int i;
+
+	for (i = size - 1; i >= 0; i--) {
+		out[i] = (in[i] << 1) | carry;
+		carry = in[i] >> 7;	/* get most significant bit */
+	}
+}
+
+/**
+ * Sign a block of data, putting the result into dst.
+ *
+ * \param key			Input AES key, length AES_KEY_LENGTH
+ * \param key_schedule		Expanded key to use
+ * \param src			Source data of length 'num_aes_blocks' blocks
+ * \param dst			Destination buffer, length AES_KEY_LENGTH
+ * \param num_aes_blocks	Number of AES blocks to encrypt
+ */
+static void sign_object(u8 *key, u8 *key_schedule, u8 *src, u8 *dst,
+			u32 num_aes_blocks)
+{
+	u8 tmp_data[AES_KEY_LENGTH];
+	u8 left[AES_KEY_LENGTH];
+	u8 k1[AES_KEY_LENGTH];
+	u8 *cbc_chain_data;
+	unsigned i;
+
+	cbc_chain_data = zero_key;	/* Convenient array of 0's for IV */
+
+	/* compute K1 constant needed by AES-CMAC calculation */
+	for (i = 0; i < AES_KEY_LENGTH; i++)
+		tmp_data[i] = 0;
+
+	encrypt_object(key_schedule, tmp_data, left, 1);
+	debug_print_vector("AES(key, nonce)", AES_KEY_LENGTH, left);
+
+	left_shift_vector(left, k1, sizeof(left));
+	debug_print_vector("L", AES_KEY_LENGTH, left);
+
+	if ((left[0] >> 7) != 0) /* get MSB of L */
+		k1[AES_KEY_LENGTH-1] ^= AES_CMAC_CONST_RB;
+	debug_print_vector("K1", AES_KEY_LENGTH, k1);
+
+	/* compute the AES-CMAC value */
+	for (i = 0; i < num_aes_blocks; i++) {
+		/* Apply the chain data */
+		apply_cbc_chain_data(cbc_chain_data, src, tmp_data);
+
+		/* for the final block, XOR K1 into the IV */
+		if (i == num_aes_blocks - 1)
+			apply_cbc_chain_data(tmp_data, k1, tmp_data);
+
+		/* encrypt the AES block */
+		aes_encrypt(tmp_data, key_schedule, dst);
+
+		debug("sign_obj: block %d of %d\n", i, num_aes_blocks);
+		debug_print_vector("AES-CMAC Src", AES_KEY_LENGTH, src);
+		debug_print_vector("AES-CMAC Xor", AES_KEY_LENGTH, tmp_data);
+		debug_print_vector("AES-CMAC Dst", AES_KEY_LENGTH, dst);
+
+		/* Update pointers for next loop. */
+		cbc_chain_data = dst;
+		src += AES_KEY_LENGTH;
+	}
+
+	debug_print_vector("AES-CMAC Hash", AES_KEY_LENGTH, dst);
+}
+
+/**
+ * Encrypt and sign a block of data (depending on security mode).
+ *
+ * \param key		Input AES key, length AES_KEY_LENGTH
+ * \param oper		Security operations mask to perform (enum security_op)
+ * \param src		Source data
+ * \param length	Size of source data
+ * \param sig_dst	Destination address for signature, AES_KEY_LENGTH bytes
+ */
+static int encrypt_and_sign(u8 *key, enum security_op oper, u8 *src,
+			    u32 length, u8 *sig_dst)
+{
+	u32 num_aes_blocks;
+	u8 key_schedule[AES_EXPAND_KEY_LENGTH];
+
+	debug("encrypt_and_sign: length = %d\n", length);
+	debug_print_vector("AES key", AES_KEY_LENGTH, key);
+
+	/*
+	 * The only need for a key is for signing/checksum purposes, so
+	 * if not encrypting, expand a key of 0s.
+	 */
+	aes_expand_key(oper & SECURITY_ENCRYPT ? key : zero_key, key_schedule);
+
+	num_aes_blocks = (length + AES_KEY_LENGTH - 1) / AES_KEY_LENGTH;
+
+	if (oper & SECURITY_ENCRYPT) {
+		/* Perform this in place, resulting in src being encrypted. */
+		debug("encrypt_and_sign: begin encryption\n");
+		encrypt_object(key_schedule, src, src, num_aes_blocks);
+		debug("encrypt_and_sign: end encryption\n");
+	}
+
+	if (oper & SECURITY_SIGN) {
+		/* encrypt the data, overwriting the result in signature. */
+		debug("encrypt_and_sign: begin signing\n");
+		sign_object(key, key_schedule, src, sig_dst, num_aes_blocks);
+		debug("encrypt_and_sign: end signing\n");
+	}
+
+	return 0;
+}
+
+int sign_data_block(u8 *source, unsigned length, u8 *signature)
+{
+	return encrypt_and_sign(zero_key, SECURITY_SIGN, source,
+				length, signature);
+}
arch/arm/cpu/armv7/tegra2/crypto.h new file +36 -0
new file mode 100644
index 0000000..aff67e7
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * (C) Copyright 2010 - 2011 NVIDIA Corporation <www.nvidia.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _CRYPTO_H_
+#define _CRYPTO_H_
+
+/**
+ * Sign a block of data
+ *
+ * \param source	Source data
+ * \param length	Size of source data
+ * \param signature	Destination address for signature, AES_KEY_LENGTH bytes
+ */
+int sign_data_block(u8 *source, unsigned length, u8 *signature);
+
+#endif /* #ifndef _CRYPTO_H_ */
Signature · 1 line
1.7.7.3
#27 lore raw

PATCH v3 8/23 tegra: Add crypto library for warmboot code

Quoted 4 lines · Simon Glass

From: Yen Lin <[email protected]>

Provides an interface to aes.c for the warmboot code.

Quoted 5 lines

---
Changes in v2:
- Rely on compiler to optimise out debug_print_vector()
- Remove unused crypto code from crypto.c

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

#28 lore raw

PATCH v3 9/23 tegra: Add flow, gp_padctl, fuse, sdram headers

In reply to Simon Glass

From: Yen Lin <[email protected]>

These headers provide access to additional Tegra features.

flow - start/stop CPUs
sdram - parameters for SDRAM
fuse - access to on-chip fuses / security settings gp_padctl - pad control and general purpose registers

---

 arch/arm/include/asm/arch-tegra2/flow.h        |   36 ++++++
 arch/arm/include/asm/arch-tegra2/fuse.h        |   39 ++++++
 arch/arm/include/asm/arch-tegra2/gp_padctrl.h  |   64 ++++++++++
 arch/arm/include/asm/arch-tegra2/sdram_param.h |  148 ++++++++++++++++++++++++
 arch/arm/include/asm/arch-tegra2/tegra2.h      |    1 +
 5 files changed, 288 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-tegra2/flow.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/fuse.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/gp_padctrl.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/sdram_param.h
arch/arm/include/asm/arch-tegra2/flow.h new file +36 -0
new file mode 100644
index 0000000..cce6cbf
@@ -0,0 +1,36 @@
+/*
+ * (C) Copyright 2010, 2011
+ * NVIDIA Corporation <www.nvidia.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _FLOW_H_
+#define _FLOW_H_
+
+struct flow_ctlr {
+	u32	halt_cpu_events;
+	u32	halt_cop_events;
+	u32	cpu_csr;
+	u32	cop_csr;
+	u32	halt_cpu1_events;
+	u32	cpu1_csr;
+};
+
+#endif
arch/arm/include/asm/arch-tegra2/fuse.h new file +39 -0
new file mode 100644
index 0000000..b7e3808
@@ -0,0 +1,39 @@
+/*
+ *  (C) Copyright 2010,2011
+ *  NVIDIA Corporation <www.nvidia.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _FUSE_H_
+#define _FUSE_H_
+
+/* FUSE registers */
+struct fuse_regs {
+	u32 reserved0[64];		/* 0x00 - 0xFC: */
+	u32 production_mode;		/* 0x100: FUSE_PRODUCTION_MODE */
+	u32 reserved1[3];		/* 0x104 - 0x10c: */
+	u32 sku_info;			/* 0x110 */
+	u32 reserved2[13];		/* 0x114 - 0x144: */
+	u32 fa;				/* 0x148: FUSE_FA */
+	u32 reserved3[21];		/* 0x14C - 0x19C: */
+	u32 security_mode;		/* 0x1A0: FUSE_SECURITY_MODE */
+};
+
+#endif	/* ifndef _FUSE_H_ */
arch/arm/include/asm/arch-tegra2/gp_padctrl.h new file +64 -0

64 lines not on this page · raw message

arch/arm/include/asm/arch-tegra2/sdram_param.h new file +148 -0

148 lines not on this page · raw message

arch/arm/include/asm/arch-tegra2/tegra2.h +1 -0
index ca1881e..2e152fd 100644
@@ -40,6 +40,7 @@
 #define NV_PA_APB_UARTE_BASE	(NV_PA_APB_MISC_BASE + 0x6400)
 #define TEGRA2_SPI_BASE		(NV_PA_APB_MISC_BASE + 0xC380)
 #define TEGRA2_PMC_BASE		(NV_PA_APB_MISC_BASE + 0xE400)
+#define TEGRA2_FUSE_BASE	(NV_PA_APB_MISC_BASE + 0xF800)
 #define NV_PA_CSITE_BASE	0x70040000
 #define TEGRA_USB1_BASE		0xC5000000
 #define TEGRA_USB3_BASE		0xC5008000
Signature · 1 line
1.7.7.3
#29 lore raw

PATCH v3 9/23 tegra: Add flow, gp_padctl, fuse, sdram headers

Quoted 9 lines · Simon Glass

From: Yen Lin <[email protected]>

These headers provide access to additional Tegra features.

flow - start/stop CPUs
sdram - parameters for SDRAM
fuse - access to on-chip fuses / security settings gp_padctl - pad control and general purpose registers

Quoted 2 lines

---

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

#30 lore raw

PATCH v3 10/23 tegra: Add tegra_get_chip_type() to detect SKU

In reply to Simon Glass

We want to know which type of chip we are running on - the Tegra family has several SKUs. This can be determined by reading a fuse register, so add this function to ap20.

---
Changes in v2:
- Add check of undocumented values in hidrev register

 arch/arm/cpu/armv7/tegra2/ap20.c              |   36 +++++++++++++++++++++++++
 arch/arm/include/asm/arch-tegra2/ap20.h       |    7 +++++
 arch/arm/include/asm/arch-tegra2/gp_padctrl.h |    9 ++++++
 arch/arm/include/asm/arch-tegra2/tegra2.h     |   24 ++++++++++++++++
 4 files changed, 76 insertions(+), 0 deletions(-)
arch/arm/cpu/armv7/tegra2/ap20.c +36 -0
index a6dd3e4..150fbfd 100644
@@ -26,11 +26,47 @@
 #include <asm/arch/ap20.h>
 #include <asm/arch/clk_rst.h>
 #include <asm/arch/clock.h>
+#include <asm/arch/fuse.h>
+#include <asm/arch/gp_padctrl.h>
 #include <asm/arch/pmc.h>
 #include <asm/arch/pinmux.h>
 #include <asm/arch/scu.h>
 #include <common.h>
 
+int tegra_get_chip_type(void)
+{
+	struct apb_misc_gp_ctlr *gp;
+	struct fuse_regs *fuse = (struct fuse_regs *)TEGRA2_FUSE_BASE;
+	uint tegra_sku_id, rev;
+
+	/*
+	 * This is undocumented, Chip ID is bits 15:8 of the register
+	 * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
+	 * Tegra30
+	 */
+	gp = (struct apb_misc_gp_ctlr *)TEGRA2_APB_MISC_GP_BASE;
+	rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;
+
+	tegra_sku_id = readl(&fuse->sku_info) & 0xff;
+
+	switch (rev) {
+	case CHIPID_TEGRA2:
+		switch (tegra_sku_id) {
+		case SKU_ID_T20:
+			return TEGRA_SOC_T20;
+		case SKU_ID_T25SE:
+		case SKU_ID_AP25:
+		case SKU_ID_T25:
+		case SKU_ID_AP25E:
+		case SKU_ID_T25E:
+			return TEGRA_SOC_T25;
+		}
+		break;
+	}
+	/* unknown sku id */
+	return TEGRA_SOC_UNKNOWN;
+}
+
 /* Returns 1 if the current CPU executing is a Cortex-A9, else 0 */
 static int ap20_cpu_is_cortexa9(void)
 {
arch/arm/include/asm/arch-tegra2/ap20.h +7 -0
index a4b4d73..d222c44 100644
@@ -100,3 +100,10 @@ void tegra2_start(void);
 
 /* This is the main entry into U-Boot, used by the Cortex-A9 */
 extern void _start(void);
+
+/**
+ * Works out the SOC type used for clocks settings
+ *
+ * @return	SOC type - see TEGRA_SOC...
+ */
+int tegra_get_chip_type(void);
arch/arm/include/asm/arch-tegra2/gp_padctrl.h +9 -0
index 25bb46d..1755ab2 100644
@@ -61,4 +61,13 @@ struct apb_misc_gp_ctlr {
 	u32	memcomp;	/* 0xD4: APB_MISC_GP_MEMCOMPPADCTRL */
 };
 
+/* bit fields definitions for APB_MISC_GP_HIDREV register */
+#define HIDREV_CHIPID_SHIFT		8
+#define HIDREV_CHIPID_MASK		(0xff << HIDREV_CHIPID_SHIFT)
+#define HIDREV_MAJORPREV_SHIFT		4
+#define HIDREV_MAJORPREV_MASK		(0xf << HIDREV_MAJORPREV_SHIFT)
+
+/* CHIPID field returned from APB_MISC_GP_HIDREV register */
+#define CHIPID_TEGRA2				0x20
+
 #endif
arch/arm/include/asm/arch-tegra2/tegra2.h +24 -0
index 2e152fd..d4ada10 100644
@@ -33,6 +33,7 @@
 #define NV_PA_GPIO_BASE		0x6000D000
 #define NV_PA_EVP_BASE		0x6000F000
 #define NV_PA_APB_MISC_BASE	0x70000000
+#define TEGRA2_APB_MISC_GP_BASE	(NV_PA_APB_MISC_BASE + 0x0800)
 #define NV_PA_APB_UARTA_BASE	(NV_PA_APB_MISC_BASE + 0x6000)
 #define NV_PA_APB_UARTB_BASE	(NV_PA_APB_MISC_BASE + 0x6040)
 #define NV_PA_APB_UARTC_BASE	(NV_PA_APB_MISC_BASE + 0x6200)
@@ -55,6 +56,29 @@
 struct timerus {
 	unsigned int cntr_1us;
 };
+
+/* Address@which WB code runs, it must not overlap Bootrom's IRAM usage */
+#define AP20_WB_RUN_ADDRESS	0x40020000
+
+/* These are the available SKUs (product types) for Tegra */
+enum {
+	SKU_ID_T20		= 0x8,
+	SKU_ID_T25SE		= 0x14,
+	SKU_ID_AP25		= 0x17,
+	SKU_ID_T25		= 0x18,
+	SKU_ID_AP25E		= 0x1b,
+	SKU_ID_T25E		= 0x1c,
+};
+
+/* These are the SOC categories that affect clocking */
+enum {
+	TEGRA_SOC_T20,
+	TEGRA_SOC_T25,
+
+	TEGRA_SOC_COUNT,
+	TEGRA_SOC_UNKNOWN	= -1,
+};
+
 #else  /* __ASSEMBLY__ */
 #define PRM_RSTCTRL		TEGRA2_PMC_BASE
 #endif
Signature · 1 line
1.7.7.3
#31 lore raw

PATCH v3 10/23 tegra: Add tegra_get_chip_type() to detect SKU

Quoted 15 lines · Simon Glass

We want to know which type of chip we are running on - the Tegra family has several SKUs. This can be determined by reading a fuse register, so add this function to ap20.

---
Changes in v2:
- Add check of undocumented values in hidrev register

arch/arm/cpu/armv7/tegra2/ap20.c +3 -0
 
+int tegra_get_chip_type(void)
+{
+	struct apb_misc_gp_ctlr *gp;

arch/arm/cpu/armv7/tegra2/ap20.c line 48

Quoted 10 lines
arch/arm/cpu/armv7/tegra2/ap20.c +10 -0
+	struct fuse_regs *fuse = (struct fuse_regs *)TEGRA2_FUSE_BASE;
+	uint tegra_sku_id, rev;
+
+	/*
+	 * This is undocumented, Chip ID is bits 15:8 of the register
+	 * APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
+	 * Tegra30
+	 */
+	gp = (struct apb_misc_gp_ctlr *)TEGRA2_APB_MISC_GP_BASE;
+	rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;

That's not entirely true; the register and its fields are documented in the TRM. The values of the CHIPID field itself are indeed not documented.

#32 lore raw

PATCH v3 10/23 tegra: Add tegra_get_chip_type() to detect SKU

Hi Stephen,

Quoted 13 lines · Stephen Warren
Quoted 11 lines · Simon Glass

We want to know which type of chip we are running on - the Tegra family has several SKUs. This can be determined by reading a fuse register, so add this function to ap20.

---
Changes in v2:
- Add check of undocumented values in hidrev register

arch/arm/cpu/armv7/tegra2/ap20.c +0 -0
Quoted 16 lines

arch/arm/cpu/armv7/tegra2/ap20.c

Quoted 13 lines
arch/arm/cpu/armv7/tegra2/ap20.c +13 -0
+int tegra_get_chip_type(void)
+{
+ ? ? struct apb_misc_gp_ctlr *gp;
+ ? ? struct fuse_regs *fuse = (struct fuse_regs *)TEGRA2_FUSE_BASE;
+ ? ? uint tegra_sku_id, rev;
+
+ ? ? /*
+ ? ? ?* This is undocumented, Chip ID is bits 15:8 of the register
+ ? ? ?* APB_MISC + 0x804, and has value 0x20 for Tegra20, 0x30 for
+ ? ? ?* Tegra30
+ ? ? ?*/
+ ? ? gp = (struct apb_misc_gp_ctlr *)TEGRA2_APB_MISC_GP_BASE;
+ ? ? rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT;

That's not entirely true; the register and its fields are documented in the TRM. The values of the CHIPID field itself are indeed not documented.

OK I have updated this. It is confusing because there is another register at TEGRA2_APB_MISC_PP_BASE which has a space in those fields.

Regards,
Simon

#33 lore raw

PATCH v3 11/23 tegra: Add header file for APB_MISC register

In reply to Simon Glass

Add a basic header file for this register, to be filled in as needed.

---
Changes in v3:
- Add apb_misc.h header file in new patch

 arch/arm/include/asm/arch-tegra2/apb_misc.h |   36 +++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-tegra2/apb_misc.h
arch/arm/include/asm/arch-tegra2/apb_misc.h new file +36 -0
new file mode 100644
index 0000000..eb69d18
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2012 The Chromium OS Authors.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _GP_PADCTRL_H_
+#define _GP_PADCTRL_H_
+
+/* APB_MISC_PP registers */
+struct apb_misc_pp_ctlr {
+	u32	reserved0[2];
+	u32	strapping_opt_a;/* 0x08: APB_MISC_PP_STRAPPING_OPT_A */
+};
+
+/* bit fields definitions for APB_MISC_PP_STRAPPING_OPT_A register */
+#define RAM_CODE_SHIFT		4
+#define RAM_CODE_MASK		(0xf << RAM_CODE_SHIFT)
+
+#endif
Signature · 1 line
1.7.7.3
#34 lore raw

PATCH v3 12/23 tegra: Add EMC support for optimal memory timings

In reply to Simon Glass

From: Jimmy Zhang <[email protected]>

Add support for setting up the memory controller parameters. Boards can set up an appropriate table in the device tree.

---
Changes in v2:
- Add debug() output to EMC
- Move EMC tables to device tree

Changes in v3:
- Support nvidia,use-ram-code binding option for EMC
- Try to return a useful error code when EMC config fails

 arch/arm/cpu/armv7/tegra2/Makefile     |    1 +
 arch/arm/cpu/armv7/tegra2/emc.c        |  286 ++++++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-tegra2/emc.h |  113 +++++++++++++
 include/fdtdec.h                       |    2 +
 lib/fdtdec.c                           |    2 +
 5 files changed, 404 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/cpu/armv7/tegra2/emc.c
 create mode 100644 arch/arm/include/asm/arch-tegra2/emc.h
arch/arm/cpu/armv7/tegra2/Makefile +1 -0
index e9ac6c9..dcd6329 100644
@@ -34,6 +34,7 @@ LIB	=  $(obj)lib$(SOC).o
 
 SOBJS	:= lowlevel_init.o
 COBJS-y	:= ap20.o board.o clock.o funcmux.o pinmux.o sys_info.o timer.o
+COBJS-$(CONFIG_TEGRA_CLOCK_SCALING) += emc.o
 COBJS-$(CONFIG_USB_EHCI_TEGRA) += usb.o
 
 COBJS	:= $(COBJS-y)
arch/arm/cpu/armv7/tegra2/emc.c new file +286 -0

286 lines not on this page · raw message

arch/arm/include/asm/arch-tegra2/emc.h new file +113 -0

113 lines not on this page · raw message

include/fdtdec.h +2 -0
index 0351a25..49251d5 100644
@@ -60,6 +60,8 @@ enum fdt_compat_id {
 	COMPAT_NVIDIA_TEGRA20_USB,	/* Tegra2 USB port */
 	COMPAT_NVIDIA_TEGRA20_I2C,	/* Tegra2 i2c */
 	COMPAT_NVIDIA_TEGRA20_DVC,	/* Tegra2 dvc (really just i2c) */
+	COMPAT_NVIDIA_TEGRA20_EMC,	/* Tegra2 memory controller */
+	COMPAT_NVIDIA_TEGRA20_EMC_TABLE, /* Tegra2 memory timing table */
 
 	COMPAT_COUNT,
 };
lib/fdtdec.c +2 -0
index 76d3808..42c3e89 100644
@@ -40,6 +40,8 @@ static const char * const compat_names[COMPAT_COUNT] = {
 	COMPAT(NVIDIA_TEGRA20_USB, "nvidia,tegra20-ehci"),
 	COMPAT(NVIDIA_TEGRA20_I2C, "nvidia,tegra20-i2c"),
 	COMPAT(NVIDIA_TEGRA20_DVC, "nvidia,tegra20-i2c-dvc"),
+	COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"),
+	COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"),
 };
 
 const char *fdtdec_get_compatible(enum fdt_compat_id id)
Signature · 1 line
1.7.7.3
#35 lore raw

PATCH v3 12/23 tegra: Add EMC support for optimal memory timings

Quoted 5 lines · Simon Glass

From: Jimmy Zhang <[email protected]>

Add support for setting up the memory controller parameters. Boards can set up an appropriate table in the device tree.

Quoted 2 lines

---

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

#36 lore raw

PATCH v3 12/23 tegra: Add EMC support for optimal memory timings

Hi Jimmy,

Quoted 11 lines · jimmzhang
Quoted 5 lines · Simon Glass

From: Jimmy Zhang <[email protected]>

Add support for setting up the memory controller parameters. Boards can set up an appropriate table in the device tree.

Quoted 2 lines

---

This patch causes a warning with building with the debian cross tool chain:

emc.c: In function 'tegra_set_emc':
emc.c:272:15: warning: 'table' may be used uninitialized in this function [-Wmaybe-uninitialized] emc.c: In function 'tegra_set_emc':
emc.c:272:15: warning: 'table' may be used uninitialized in this function [-Wmaybe-uninitialized]

Could you provide a patch to fix this?

Amicalement,

Signature · 1 line
Albert.
#37 lore raw

PATCH v3 13/23 tegra: Add PMU to manage power supplies

In reply to Simon Glass

From: Jimmy Zhang <[email protected]>

Power supplies must be adjusted in line with clock frequency. This code provides a simple routine to set the voltage to allow operation at maximum frequency.

- Split PMU code into separate TPS6586X driver

---

 arch/arm/cpu/armv7/tegra2/Makefile     |    1 +
 arch/arm/cpu/armv7/tegra2/pmu.c        |   70 ++++++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-tegra2/pmu.h |   30 ++++++++++++++
 3 files changed, 101 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/cpu/armv7/tegra2/pmu.c
 create mode 100644 arch/arm/include/asm/arch-tegra2/pmu.h
arch/arm/cpu/armv7/tegra2/Makefile +1 -0
index dcd6329..dba684d 100644
@@ -35,6 +35,7 @@ LIB	=  $(obj)lib$(SOC).o
 SOBJS	:= lowlevel_init.o
 COBJS-y	:= ap20.o board.o clock.o funcmux.o pinmux.o sys_info.o timer.o
 COBJS-$(CONFIG_TEGRA_CLOCK_SCALING) += emc.o
+COBJS-$(CONFIG_TEGRA_PMU) += pmu.o
 COBJS-$(CONFIG_USB_EHCI_TEGRA) += usb.o
 
 COBJS	:= $(COBJS-y)
arch/arm/cpu/armv7/tegra2/pmu.c new file +70 -0

70 lines not on this page · raw message

arch/arm/include/asm/arch-tegra2/pmu.h new file +30 -0
new file mode 100644
index 0000000..390815f
@@ -0,0 +1,30 @@
+/*
+ *  (C) Copyright 2010,2011
+ *  NVIDIA Corporation <www.nvidia.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _ARCH_PMU_H_
+#define _ARCH_PMU_H_
+
+/* Set core and CPU voltages to nominal levels */
+int pmu_set_nominal(void);
+
+#endif	/* _ARCH_PMU_H_ */
Signature · 1 line
1.7.7.3
#38 lore raw

PATCH v3 13/23 tegra: Add PMU to manage power supplies

Quoted 8 lines · Simon Glass

From: Jimmy Zhang <[email protected]>

Power supplies must be adjusted in line with clock frequency. This code provides a simple routine to set the voltage to allow operation at maximum frequency.

- Split PMU code into separate TPS6586X driver

Quoted 3 lines

---

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

#39 lore raw

PATCH v3 14/23 tegra: Set up PMU for Nvidia boards

In reply to Simon Glass

Adjust PMU to permit maximum frequency operation.

---
Changes in v2:
- Check error return from pmu_set_nominal() in debug mode

 board/nvidia/common/board.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
board/nvidia/common/board.c +6 -0
index 85dd359..640b9c4 100644
@@ -31,6 +31,8 @@
 #include <asm/arch/clk_rst.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/pinmux.h>
+#include <asm/arch/pmc.h>
+#include <asm/arch/pmu.h>
 #include <asm/arch/uart.h>
 #include <spi.h>
 #include <asm/arch/usb.h>
@@ -81,6 +83,10 @@ int board_init(void)
 #error "You must define CONFIG_SYS_I2C_INIT_BOARD to use i2c on Nvidia boards"
 #endif
 	i2c_init_board();
+# ifdef CONFIG_TEGRA_PMU
+	if (pmu_set_nominal())
+		debug("Failed to select nominal voltages\n");
+# endif
 #endif
 
 #ifdef CONFIG_USB_EHCI_TEGRA
Signature · 1 line
1.7.7.3
#40 lore raw

PATCH v3 15/23 tegra: Add warmboot implementation

In reply to Simon Glass

From: Yen Lin <[email protected]>

Add code to set up the warm boot area in the Tegra CPU ready for a resume after suspend.

---
Changes in v2:
- Move structs shared between A9 and AVP into warmboot.h header file
- Remove unused crypto code
- Tidy SDRAM range check in warmboot_prepare_code()
- Use low-level clock functions in warmboot code instead of register access

 arch/arm/cpu/armv7/tegra2/Makefile          |    2 +
 arch/arm/cpu/armv7/tegra2/warmboot.c        |  382 +++++++++++++++++++++++++++
 arch/arm/cpu/armv7/tegra2/warmboot_avp.c    |  250 +++++++++++++++++
 arch/arm/cpu/armv7/tegra2/warmboot_avp.h    |   81 ++++++
 arch/arm/include/asm/arch-tegra2/warmboot.h |  150 +++++++++++
 5 files changed, 865 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/cpu/armv7/tegra2/warmboot.c
 create mode 100644 arch/arm/cpu/armv7/tegra2/warmboot_avp.c
 create mode 100644 arch/arm/cpu/armv7/tegra2/warmboot_avp.h
 create mode 100644 arch/arm/include/asm/arch-tegra2/warmboot.h
arch/arm/cpu/armv7/tegra2/Makefile +2 -0
index dba684d..08c4137 100644
@@ -27,6 +27,7 @@
 # flags for any startup files it might use.
 CFLAGS_arch/arm/cpu/armv7/tegra2/ap20.o += -march=armv4t
 CFLAGS_arch/arm/cpu/armv7/tegra2/clock.o += -march=armv4t
+CFLAGS_arch/arm/cpu/armv7/tegra2/warmboot_avp.o += -march=armv4t
 
 include $(TOPDIR)/config.mk
 
@@ -37,6 +38,7 @@ COBJS-y	:= ap20.o board.o clock.o funcmux.o pinmux.o sys_info.o timer.o
 COBJS-$(CONFIG_TEGRA_CLOCK_SCALING) += emc.o
 COBJS-$(CONFIG_TEGRA_PMU) += pmu.o
 COBJS-$(CONFIG_USB_EHCI_TEGRA) += usb.o
+COBJS-$(CONFIG_TEGRA2_LP0) += crypto.o warmboot.o warmboot_avp.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
arch/arm/cpu/armv7/tegra2/warmboot.c new file +382 -0

382 lines not on this page · raw message

arch/arm/cpu/armv7/tegra2/warmboot_avp.c new file +250 -0

250 lines not on this page · raw message

arch/arm/cpu/armv7/tegra2/warmboot_avp.h new file +81 -0

81 lines not on this page · raw message

arch/arm/include/asm/arch-tegra2/warmboot.h new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
1.7.7.3
#41 lore raw

PATCH v3 15/23 tegra: Add warmboot implementation

Quoted 5 lines · Simon Glass

From: Yen Lin <[email protected]>

Add code to set up the warm boot area in the Tegra CPU ready for a resume after suspend.

Quoted 8 lines

---
Changes in v2:
- Move structs shared between A9 and AVP into warmboot.h header file
- Remove unused crypto code
- Tidy SDRAM range check in warmboot_prepare_code()
- Use low-level clock functions in warmboot code instead of register access

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

#42 lore raw

PATCH v3 15/23 tegra: Add warmboot implementation

In reply to Simon Glass
Quoted 8 lines · Simon Glass

From: Yen Lin <[email protected]>

Add code to set up the warm boot area in the Tegra CPU ready for a resume after suspend.

arch/arm/cpu/armv7/tegra2/warmboot.c line 259

Quoted 8 lines
arch/arm/cpu/armv7/tegra2/warmboot.c new file +8 -0
+static enum fuse_operating_mode fuse_get_operation_mode(void)
+{
+	u32 chip_id;
+	struct apb_misc_gp_ctlr *gp =
+		(struct apb_misc_gp_ctlr *)TEGRA2_APB_MISC_GP_BASE;
+
+	chip_id = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >>
+			HIDREV_CHIPID_SHIFT;

This duplicates code from the SKU retrieval function added in an earlier patch. Not a big deal; it could be unified in a followon patch.

#43 lore raw

PATCH v3 15/23 tegra: Add warmboot implementation

Hi Stephen,

Quoted 9 lines · Stephen Warren
Quoted 7 lines · Simon Glass

From: Yen Lin <[email protected]>

Add code to set up the warm boot area in the Tegra CPU ready for a resume after suspend.

Quoted 11 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+static enum fuse_operating_mode fuse_get_operation_mode(void)
+{
+ ? ? u32 chip_id;
+ ? ? struct apb_misc_gp_ctlr *gp =
+ ? ? ? ? ? ? (struct apb_misc_gp_ctlr *)TEGRA2_APB_MISC_GP_BASE;
+
+ ? ? chip_id = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >>
+ ? ? ? ? ? ? ? ? ? ? HIDREV_CHIPID_SHIFT;

This duplicates code from the SKU retrieval function added in an earlier patch. Not a big deal; it could be unified in a followon patch.

Yes, I didn't notice that - yes we can tidy it up later.

Regards,
Simon

#44 lore raw

PATCH v3 16/23 tegra: Setup PMC scratch info from ap20 setup

In reply to Simon Glass

From: Yen Lin <[email protected]>

Save SDRAM parameters into the warmboot scratch registers

---

 arch/arm/cpu/armv7/tegra2/ap20.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/arm/cpu/armv7/tegra2/ap20.c +6 -0
index 150fbfd..698bfd0 100644
@@ -31,6 +31,7 @@
 #include <asm/arch/pmc.h>
 #include <asm/arch/pinmux.h>
 #include <asm/arch/scu.h>
+#include <asm/arch/warmboot.h>
 #include <common.h>
 
 int tegra_get_chip_type(void)
@@ -322,6 +323,11 @@ void init_pmc_scratch(void)
 
 	/* ODMDATA is for kernel use to determine RAM size, LP config, etc. */
 	writel(CONFIG_SYS_BOARD_ODMDATA, &pmc->pmc_scratch20);
+
+#ifdef CONFIG_TEGRA2_LP0
+	/* save Sdram params to PMC 2, 4, and 24 for WB0 */
+	warmboot_save_sdram_params();
+#endif
 }
 
 void tegra2_start(void)
Signature · 1 line
1.7.7.3
#45 lore raw

PATCH v3 16/23 tegra: Setup PMC scratch info from ap20 setup

Quoted 4 lines · Simon Glass

From: Yen Lin <[email protected]>

Save SDRAM parameters into the warmboot scratch registers

Quoted 3 lines

---

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

#46 lore raw

PATCH v3 17/23 tegra: Set up warmboot code on Nvidia boards

In reply to Simon Glass

Call the function to put warmboot boot in a suitable place for resume.

---

 board/nvidia/common/board.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
board/nvidia/common/board.c +6 -0
index 640b9c4..b82e61a 100644
@@ -34,6 +34,7 @@
 #include <asm/arch/pmc.h>
 #include <asm/arch/pmu.h>
 #include <asm/arch/uart.h>
+#include <asm/arch/warmboot.h>
 #include <spi.h>
 #include <asm/arch/usb.h>
 #include <i2c.h>
@@ -94,6 +95,11 @@ int board_init(void)
 	board_usb_init(gd->fdt_blob);
 #endif
 
+#ifdef CONFIG_TEGRA2_LP0
+	/* prepare the WB code to LP0 location */
+	warmboot_prepare_code(TEGRA_LP0_ADDR, TEGRA_LP0_SIZE);
+#endif
+
 	return 0;
 }
 
Signature · 1 line
1.7.7.3
#47 lore raw

PATCH v3 18/23 tegra: Turn off power detect in board init

In reply to Simon Glass

From: Wei Ni <[email protected]>

Tegra core power rail has leakage voltage around 0.2V while system in suspend mode. The source of the leakage should be coming from PMC power detect logic for IO rails power detection.
That can be disabled by writing a '0' to PWR_DET_LATCH followed by writing '0' to PWR_DET (APBDEV_PMC_PWR_DET_0).

---
Changes in v3:
- Fix CONFIG_TEGRA_I2C define

 board/nvidia/common/board.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
board/nvidia/common/board.c +18 -0
index b82e61a..1d6b002 100644
@@ -62,6 +62,21 @@ void __pin_mux_usb(void)
 void pin_mux_usb(void) __attribute__((weak, alias("__pin_mux_usb")));
 
 /*
+ * Routine: power_det_init
+ * Description: turn off power detects
+ */
+static void power_det_init(void)
+{
+#if defined(CONFIG_TEGRA2)
+	struct pmc_ctlr *const pmc = (struct pmc_ctlr *)TEGRA2_PMC_BASE;
+
+	/* turn off power detects */
+	writel(0, &pmc->pmc_pwr_det_latch);
+	writel(0, &pmc->pmc_pwr_det);
+#endif
+}
+
+/*
  * Routine: board_init
  * Description: Early hardware init.
  */
@@ -79,6 +94,9 @@ int board_init(void)
 #endif
 	/* boot param addr */
 	gd->bd->bi_boot_params = (NV_PA_SDRAM_BASE + 0x100);
+
+	power_det_init();
+
 #ifdef CONFIG_TEGRA_I2C
 #ifndef CONFIG_SYS_I2C_INIT_BOARD
 #error "You must define CONFIG_SYS_I2C_INIT_BOARD to use i2c on Nvidia boards"
Signature · 1 line
1.7.7.3
#48 lore raw

PATCH v3 18/23 tegra: Turn off power detect in board init

Quoted 9 lines

-----Original Message-----
From: Simon Glass [mailto:sjg at chromium.org]
Sent: Tuesday, April 03, 2012 7:19 AM
To: U-Boot Mailing List
Cc: Tom Warren; Stephen Warren; Wei Ni; Simon Glass; Stephen Warren
Subject: [PATCH v3 18/23] tegra: Turn off power detect in board init

Quoted 7 lines

From: Wei Ni <[email protected]>

Tegra core power rail has leakage voltage around 0.2V while system in suspend mode. The source of the leakage should be coming from PMC power detect logic for IO rails power detection.
That can be disabled by writing a '0' to PWR_DET_LATCH followed by writing '0' to PWR_DET (APBDEV_PMC_PWR_DET_0).

Quoted 5 lines

---
Changes in v3:
- Fix CONFIG_TEGRA_I2C define

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------

#49 lore raw

PATCH v3 19/23 tegra: Add EMC settings for Seaboard

In reply to Simon Glass

From: Jimmy Zhang <[email protected]>

Set Seaboard to optimal memory settings based on the SOC in use (T20 or T25).

---
Changes in v2:
- Move EMC tables to device tree
- Removed check for nominal voltage (not needed as it is done just before)

Changes in v3:
- Add better error reporting when EMC setup fails

 board/nvidia/common/Makefile |    1 +
 board/nvidia/common/board.c  |   13 ++++++++-
 board/nvidia/common/emc.c    |   53 ++++++++++++++++++++++++++++++++++++++++++
 board/nvidia/common/emc.h    |   29 +++++++++++++++++++++++
 4 files changed, 94 insertions(+), 2 deletions(-)
 create mode 100644 board/nvidia/common/emc.c
 create mode 100644 board/nvidia/common/emc.h
board/nvidia/common/Makefile +1 -0
index 3e748fd..a93d458 100644
@@ -27,6 +27,7 @@ LIB	= $(obj)lib$(VENDOR).o
 
 COBJS-y += board.o
 COBJS-$(CONFIG_SPI_UART_SWITCH) += uart-spi-switch.o
+COBJS-$(CONFIG_TEGRA_CLOCK_SCALING) += emc.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
board/nvidia/common/board.c +11 -2
index 1d6b002..e2cdb6e 100644
@@ -30,6 +30,7 @@
 #include <asm/arch/board.h>
 #include <asm/arch/clk_rst.h>
 #include <asm/arch/clock.h>
+#include <asm/arch/emc.h>
 #include <asm/arch/pinmux.h>
 #include <asm/arch/pmc.h>
 #include <asm/arch/pmu.h>
@@ -39,6 +40,7 @@
 #include <asm/arch/usb.h>
 #include <i2c.h>
 #include "board.h"
+#include "emc.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -82,6 +84,8 @@ static void power_det_init(void)
  */
 int board_init(void)
 {
+	int err;
+
 	/* Do clocks and UART first so that printf() works */
 	clock_init();
 	clock_verify();
@@ -105,8 +109,13 @@ int board_init(void)
 # ifdef CONFIG_TEGRA_PMU
 	if (pmu_set_nominal())
 		debug("Failed to select nominal voltages\n");
-# endif
-#endif
+#  ifdef CONFIG_TEGRA_CLOCK_SCALING
+	err = board_emc_init();
+	if (err)
+		debug("Memory controller init failed: %d\n", err);
+#  endif
+# endif /* CONFIG_TEGRA_PMU */
+#endif /* CONFIG_TEGRA_I2C */
 
 #ifdef CONFIG_USB_EHCI_TEGRA
 	pin_mux_usb();
board/nvidia/common/emc.c new file +53 -0

53 lines not on this page · raw message

board/nvidia/common/emc.h new file +29 -0
new file mode 100644
index 0000000..ec1b115
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ * (C) Copyright 2010,2011 NVIDIA Corporation <www.nvidia.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _NVIDIA_EMC_H_
+#define _NVIDIA_EMC_H_
+
+int board_emc_init(void);
+
+#endif
Signature · 1 line
1.7.7.3
#50 lore raw

PATCH v3 21/23 tegra: i2c: Add function to find DVC bus

In reply to Simon Glass

Add tegra_i2c_get_dvc_bus_num() to obtain the I2C bus number of DVC bus. This allows us to talk to the PMU.

---
Changes in v2:
- Add patch to find DVC bus number

 arch/arm/include/asm/arch-tegra2/tegra_i2c.h |    7 +++++++
 drivers/i2c/tegra_i2c.c                      |   14 ++++++++++++++
 2 files changed, 21 insertions(+), 0 deletions(-)
arch/arm/include/asm/arch-tegra2/tegra_i2c.h +7 -0
index 0a7d99c..cfb136c 100644
@@ -154,4 +154,11 @@ struct i2c_ctlr {
 #define I2C_INT_ARBITRATION_LOST_SHIFT	2
 #define I2C_INT_ARBITRATION_LOST_MASK	(1 << I2C_INT_ARBITRATION_LOST_SHIFT)
 
+/**
+ * Returns the bus number of the DVC controller
+ *
+ * @return number of bus, or -1 if there is no DVC active
+ */
+int tegra_i2c_get_dvc_bus_num(void);
+
 #endif
drivers/i2c/tegra_i2c.c +14 -0
index 21f6897..5b6ea0e 100644
@@ -567,3 +567,17 @@ int i2c_set_bus_num(unsigned int bus)
 	return 0;
 }
 #endif
+
+int tegra_i2c_get_dvc_bus_num(void)
+{
+	int i;
+
+	for (i = 0; i < CONFIG_SYS_MAX_I2C_BUS; i++) {
+		struct i2c_bus *bus = &i2c_controllers[i];
+
+		if (bus->inited && bus->is_dvc)
+			return i;
+	}
+
+	return -1;
+}
Signature · 1 line
1.7.7.3
#51 lore raw

PATCH v3 23/23 tegra: Enable LP0 on Seaboard

In reply to Simon Glass

This enables LP0 to support suspend / resume on Seaboard.

---

 include/configs/seaboard.h      |    8 ++++++++
 include/configs/tegra2-common.h |   17 +++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
include/configs/seaboard.h +8 -0
index ea7e4f0..5d33dc5 100644
@@ -25,6 +25,14 @@
 #define __CONFIG_H
 
 #include <asm/sizes.h>
+
+/* LP0 suspend / resume */
+#define CONFIG_TEGRA2_LP0
+#define CONFIG_AES
+#define CONFIG_TEGRA_PMU
+#define CONFIG_TPS6586X_POWER
+#define CONFIG_TEGRA_CLOCK_SCALING
+
 #include "tegra2-common.h"
 
 #define CONFIG_SYS_DCACHE_OFF
include/configs/tegra2-common.h +17 -0
index 837f859..c5870dd 100644
@@ -26,6 +26,14 @@
 #include <asm/sizes.h>
 
 /*
+ * QUOTE(m) will evaluate to a string version of the value of the macro m
+ * passed in.  The extra level of indirection here is to first evaluate the
+ * macro m before applying the quoting operator.
+ */
+#define QUOTE_(m)       #m
+#define QUOTE(m)        QUOTE_(m)
+
+/*
  * High Level Configuration Options
  */
 #define CONFIG_ARMCORTEXA9		/* This is an ARM V7 CPU core */
@@ -50,6 +58,15 @@
 #define CONFIG_CMDLINE_TAG		/* enable passing of ATAGs */
 #define CONFIG_OF_LIBFDT		/* enable passing of devicetree */
 
+#ifdef CONFIG_TEGRA2_LP0
+#define TEGRA_LP0_ADDR			0x1C406000
+#define TEGRA_LP0_SIZE			0x2000
+#define TEGRA_LP0_VEC \
+	"lp0_vec=" QUOTE(TEGRA_LP0_SIZE) "@" QUOTE(TEGRA_LP0_ADDR) " "
+#else
+#define TEGRA_LP0_VEC
+#endif
+
 /* Environment */
 #define CONFIG_ENV_SIZE			0x2000	/* Total Size Environment */
 
Signature · 1 line
1.7.7.3
#52 lore raw

v3 cover tegra: warmboot (suspend / resume) support

In reply to Simon Glass
Quoted 8 lines · Simon Glass

This series adds support for warm boot, allowing the device to suspend and resume. U-Boot sets up some 'warm boot' code in a special area such that the SOC can find it on a resume. This code is responsible for setting up memory and clocked and then allowing the OS to continue where it left off.

Also included here is support for the EMC, which allows setting the memory timings correctly in U-Boot for maximum speed operation.

The series partially:

I tested that on both Harmony and Seaboard, this series didn't seem to impact existing operation (boot to a command-prompt, load files from an SD card, produce serial output). I didn't actually test LP0.

Note:

Neither board appears to be able to actually boot a kernel any more, failing with the following error:

=============
Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Warning: Neither atags nor dtb found
=============

However, this problem is present in u-boot-tegra/master before any changes in this series.

Tom, do you want me to file an internal bug for this?

#53 lore raw

v3 cover tegra: warmboot (suspend / resume) support

Stephen,

Quoted 33 lines

-----Original Message-----
From: Stephen Warren [mailto:swarren at wwwdotorg.org]
Sent: Monday, April 09, 2012 2:54 PM
To: Simon Glass; Tom Warren
Cc: U-Boot Mailing List
Subject: Re: [PATCH v3 0/23] tegra: warmboot (suspend / resume) support

Quoted 8 lines · Simon Glass

This series adds support for warm boot, allowing the device to suspend and resume. U-Boot sets up some 'warm boot' code in a special area such that the SOC can find it on a resume. This code is responsible for setting up memory and clocked and then allowing the OS to continue where it left off.

Also included here is support for the EMC, which allows setting the memory timings correctly in U-Boot for maximum speed operation.

The series partially:

I tested that on both Harmony and Seaboard, this series didn't seem to impact existing operation (boot to a command-prompt, load files from an SD card, produce serial output). I didn't actually test LP0.

Note:

Neither board appears to be able to actually boot a kernel any more, failing with the following error:

=============
Starting kernel ...

Quoted 8 lines

Uncompressing Linux... done, booting the kernel.
Warning: Neither atags nor dtb found
=============

However, this problem is present in u-boot-tegra/master before any changes in this series.

Tom, do you want me to file an internal bug for this?

Has the upstream Seaboard (or Harmony) build ever been able to boot a kernel? I've never tried it, as I thought it was too incomplete for that yet (i.e. needs more drivers/periphs init'd first).

You can file a bug if you wish as a placeholder. I'm not sure what's missing (if it's not a regression) - bootargs for a kernel? _ATAG config items? If they were there & were taken out in a particular patch series, I'd like to see the person responsible for that be tasked w/replacing them (edited, if need be, for current state such as WB/LP0 vec, usb/mmc boot, etc.).

Tom

Signature · 1 line
nvpublic
#54 lore raw

v3 cover tegra: warmboot (suspend / resume) support

Quoted 1 line · Tom Warren

From: Stephen Warren wrote at Monday, April 09, 2012 2:54 PM:

...

Quoted 12 lines
Quoted 12 lines

Note:

Neither board appears to be able to actually boot a kernel any more, failing with the following error:

=============
Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Warning: Neither atags nor dtb found
=============

Quoted 6 lines
Quoted 4 lines

However, this problem is present in u-boot-tegra/master before any changes in this series.

Tom, do you want me to file an internal bug for this?

Has the upstream Seaboard (or Harmony) build ever been able to boot a kernel? I've never tried it, as I thought it was too incomplete for that yet (i.e. needs more drivers/periphs init'd first).

Yes, this (used to) work just fine, on both boards, booting with either ATAGs or device tree. Same for Ventana and Paz00.

For reference, I use commit 9a420986cccc9bd2c37affd931d627b3c3e72952 plus a few patches that have since been upstreamed, plus a local change to the default environment. I believe I tested a much later commmit than that while testing other patches of Simon's as well (an earlier version of the DT/USB/I2C patchset), but didn't update all my systems since I didn't need that functionality.