From antonynpavlov at gmail.com  Sat Jun  1 03:52:43 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Sat,  1 Jun 2013 11:52:43 +0400
Subject: [PATCH 0/6] MIPS: rework ns16550 debug_ll
Message-ID: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>

This patch series adds low-level debug ns16550 output helpers
for MIPS pbl. This helpers make possible easely produce
debug output via ns16550-like UART on very early pbl stage.

[PATCH 1/6] MIPS: XBurst: use mach-specific debug_ll setup
[PATCH 2/6] MIPS: pbl: add low-level debug asm macros for ns16550
[PATCH 3/6] MIPS: rzx50: pbl: use debug_ll
[PATCH 4/6] MIPS: rzx50_defconfig: use UART1 for low-level debug
[PATCH 5/6] MIPS: malta: adapt for new debug_ll
[PATCH 6/6] MIPS: unificate ns16550 debug_ll support code


From antonynpavlov at gmail.com  Sat Jun  1 03:52:45 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Sat,  1 Jun 2013 11:52:45 +0400
Subject: [PATCH 2/6] MIPS: pbl: add low-level debug asm macros for ns16550
In-Reply-To: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370073169-29009-3-git-send-email-antonynpavlov@gmail.com>

This patch adds macros for ns16550 port initialisation
and single char output. The macros can be used in
MIPS asm pbl code.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/include/asm/debug_ll_ns16550.h |  100 ++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)
 create mode 100644 arch/mips/include/asm/debug_ll_ns16550.h

diff --git a/arch/mips/include/asm/debug_ll_ns16550.h b/arch/mips/include/asm/debug_ll_ns16550.h
new file mode 100644
index 0000000..5dd1b39
--- /dev/null
+++ b/arch/mips/include/asm/debug_ll_ns16550.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2012, 2013 Antony Pavlov <antonynpavlov at gmail.com>
+ *
+ * This file is part of barebox.
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+/** @file
+ *  This file contains declaration for early output support
+ */
+#ifndef __INCLUDE_MIPS_ASM_DEBUG_LL_NS16550_H__
+#define __INCLUDE_MIPS_ASM_DEBUG_LL_NS16550_H__
+
+#ifdef CONFIG_DEBUG_LL
+
+#ifndef DEBUG_LL_UART_ADDR
+#error DEBUG_LL_UART_ADDR is undefined!
+#endif
+
+#ifndef DEBUG_LL_UART_SHIFT
+#error DEBUG_LL_UART_SHIFT is undefined!
+#endif
+
+#ifndef DEBUG_LL_UART_DIVISOR
+#error DEBUG_LL_UART_DIVISOR is undefined!
+#endif
+
+#endif /* CONFIG_DEBUG_LL */
+
+#define UART_THR	(0x0 << DEBUG_LL_UART_SHIFT)
+#define UART_DLL	(0x0 << DEBUG_LL_UART_SHIFT)
+#define UART_DLM	(0x1 << DEBUG_LL_UART_SHIFT)
+#define UART_LCR	(0x3 << DEBUG_LL_UART_SHIFT)
+#define UART_LSR	(0x5 << DEBUG_LL_UART_SHIFT)
+
+#define UART_LCR_W	0x07		/* Set UART to 8,N,2 & DLAB = 0 */
+#define UART_LCR_DLAB	0x87	/* Set UART to 8,N,2 & DLAB = 1 */
+
+#define UART_LSR_THRE	0x20	/* Xmit holding register empty */
+
+/*
+ * Macros for use in assembly language code
+ */
+
+.macro	debug_ll_ns16550_init
+#ifdef CONFIG_DEBUG_LL
+	la	t0, DEBUG_LL_UART_ADDR
+
+	li	t1, UART_LCR_DLAB		/* DLAB on */
+	sb	t1, UART_LCR(t0)		/* Write it out */
+
+	li	t1, DEBUG_LL_UART_DIVISOR
+	sb	t1, UART_DLL(t0)		/* write low order byte */
+	srl	t1, t1, 8
+	sb	t1, UART_DLM(t0)		/* write high order byte */
+
+	li	t1, UART_LCR_W			/* DLAB off */
+	sb	t1, UART_LCR(t0)		/* Write it out */
+#endif /* CONFIG_DEBUG_LL */
+.endm
+
+/*
+ * output a character in a0
+ */
+.macro	debug_ll_ns16550_outc chr
+#ifdef CONFIG_DEBUG_LL
+	li	a0, \chr
+	la	t0, DEBUG_LL_UART_ADDR
+
+1:	lbu	t1, UART_LSR(t0)	/* get line status */
+	nop
+	andi	t1, t1, UART_LSR_THRE	/* check for transmitter empty */
+	beqz	t1, 1b			/* try again */
+	 nop
+
+	sb	a0, UART_THR(t0)	/* write the character */
+#endif /* CONFIG_DEBUG_LL */
+.endm
+
+/*
+ * output CR + NL
+ */
+.macro	debug_ll_ns16550_outnl
+#ifdef CONFIG_DEBUG_LL
+	debug_ll_ns16550_outc '\r'
+	debug_ll_ns16550_outc '\n'
+#endif /* CONFIG_DEBUG_LL */
+.endm
+
+#endif /* __INCLUDE_MIPS_ASM_DEBUG_LL_NS16550_H__ */
-- 
1.7.10.4



From antonynpavlov at gmail.com  Sat Jun  1 03:52:44 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Sat,  1 Jun 2013 11:52:44 +0400
Subject: [PATCH 1/6] MIPS: XBurst: use mach-specific debug_ll setup
In-Reply-To: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370073169-29009-2-git-send-email-antonynpavlov@gmail.com>

Ingenic JZ4755 SoC (JZ4750D family) has three UARTs.
So we can give to the user choose which one of them
to use for low level debug (debug_ll) output.

Also this commit adapts the only JZ4755 board
(Ritmix RZX50) for using the new debug_ll port
selection.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/boards/rzx50/include/board/debug_ll.h    |    5 +--
 arch/mips/mach-xburst/Kconfig                      |   18 ++++++++++
 .../mach-xburst/include/mach/debug_ll_jz4750d.h    |   37 ++++++++++++++++++++
 arch/mips/mach-xburst/include/mach/jz4750d_regs.h  |    2 ++
 4 files changed, 58 insertions(+), 4 deletions(-)
 create mode 100644 arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h

diff --git a/arch/mips/boards/rzx50/include/board/debug_ll.h b/arch/mips/boards/rzx50/include/board/debug_ll.h
index 3d183b0..7ae0e2a 100644
--- a/arch/mips/boards/rzx50/include/board/debug_ll.h
+++ b/arch/mips/boards/rzx50/include/board/debug_ll.h
@@ -18,9 +18,6 @@
 #ifndef __INCLUDE_RZX50_BOARD_DEBUG_LL_H__
 #define __INCLUDE_RZX50_BOARD_DEBUG_LL_H__
 
-#include <mach/jz4750d_regs.h>
-
-#define DEBUG_LL_UART_ADDR	UART1_BASE
-#define DEBUG_LL_UART_SHIFT	2
+#include <mach/debug_ll_jz4750d.h>
 
 #endif  /* __INCLUDE_RZX50_BOARD_DEBUG_LL_H__ */
diff --git a/arch/mips/mach-xburst/Kconfig b/arch/mips/mach-xburst/Kconfig
index c72b741..e6413d5 100644
--- a/arch/mips/mach-xburst/Kconfig
+++ b/arch/mips/mach-xburst/Kconfig
@@ -17,6 +17,24 @@ config BOARD_RZX50
 
 endchoice
 
+if DEBUG_LL
+if CPU_JZ4755
+choice
+	prompt "DEBUG_LL port"
+
+config JZ4750D_DEBUG_LL_UART0
+	bool "UART0"
+
+config JZ4750D_DEBUG_LL_UART1
+	bool "UART1"
+
+config JZ4750D_DEBUG_LL_UART2
+	bool "UART2"
+
+endchoice
+endif # CPU_JZ4755
+endif # DEBUG_LL
+
 source arch/mips/boards/rzx50/Kconfig
 
 endif
diff --git a/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h b/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h
new file mode 100644
index 0000000..7bf66b1
--- /dev/null
+++ b/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013 Antony Pavlov <antonynpavlov at gmail.com>
+ *
+ * This file is part of barebox.
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+#ifndef __INCLUDE_DEBUG_LL_JZ4750D_H__
+#define __INCLUDE_DEBUG_LL_JZ4750D_H__
+
+#include <mach/jz4750d_regs.h>
+
+#ifdef CONFIG_JZ4750D_DEBUG_LL_UART0
+#define DEBUG_LL_UART_ADDR	UART0_BASE
+#endif
+
+#ifdef CONFIG_JZ4750D_DEBUG_LL_UART1
+#define DEBUG_LL_UART_ADDR	UART1_BASE
+#endif
+
+#ifdef CONFIG_JZ4750D_DEBUG_LL_UART2
+#define DEBUG_LL_UART_ADDR	UART2_BASE
+#endif
+
+#define DEBUG_LL_UART_SHIFT	2
+
+#endif /* __INCLUDE_DEBUG_LL_JZ4750D_H__ */
diff --git a/arch/mips/mach-xburst/include/mach/jz4750d_regs.h b/arch/mips/mach-xburst/include/mach/jz4750d_regs.h
index eafdd2f..7a3daad 100644
--- a/arch/mips/mach-xburst/include/mach/jz4750d_regs.h
+++ b/arch/mips/mach-xburst/include/mach/jz4750d_regs.h
@@ -16,7 +16,9 @@
 #define TCU_BASE        0xb0002000
 #define WDT_BASE        0xb0002000
 #define RTC_BASE        0xb0003000
+#define UART0_BASE      0xb0030000
 #define UART1_BASE      0xb0031000
+#define UART2_BASE      0xb0032000
 
 /*************************************************************************
  * TCU (Timer Counter Unit)
-- 
1.7.10.4



From antonynpavlov at gmail.com  Sat Jun  1 03:52:46 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Sat,  1 Jun 2013 11:52:46 +0400
Subject: [PATCH 3/6] MIPS: rzx50: pbl: use debug_ll
In-Reply-To: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370073169-29009-4-git-send-email-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/boards/rzx50/include/board/board_pbl_start.h |    6 ++++++
 arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h  |    4 ++++
 2 files changed, 10 insertions(+)

diff --git a/arch/mips/boards/rzx50/include/board/board_pbl_start.h b/arch/mips/boards/rzx50/include/board/board_pbl_start.h
index cba3e7f..f71641a 100644
--- a/arch/mips/boards/rzx50/include/board/board_pbl_start.h
+++ b/arch/mips/boards/rzx50/include/board/board_pbl_start.h
@@ -18,6 +18,7 @@
  */
 
 #include <asm/pbl_macros.h>
+#include <mach/debug_ll.h>
 
 	.macro	board_pbl_start
 	.set	push
@@ -28,6 +29,11 @@
 	/* CPU/SoC specific setup ... */
 	/* ... absent */
 
+	debug_ll_ns16550_init
+
+	debug_ll_ns16550_outc '.'
+	debug_ll_ns16550_outnl
+
 	copy_to_link_location	pbl_start
 
 	.set	pop
diff --git a/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h b/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h
index 7bf66b1..2a55dea 100644
--- a/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h
+++ b/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h
@@ -34,4 +34,8 @@
 
 #define DEBUG_LL_UART_SHIFT	2
 
+#define DEBUG_LL_UART_CLK	(12000000 / 16)
+#define DEBUG_LL_UART_BPS	CONFIG_BAUDRATE
+#define DEBUG_LL_UART_DIVISOR	(DEBUG_LL_UART_CLK / DEBUG_LL_UART_BPS)
+
 #endif /* __INCLUDE_DEBUG_LL_JZ4750D_H__ */
-- 
1.7.10.4



From antonynpavlov at gmail.com  Sat Jun  1 03:52:47 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Sat,  1 Jun 2013 11:52:47 +0400
Subject: [PATCH 4/6] MIPS: rzx50_defconfig: use UART1 for low-level debug
In-Reply-To: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370073169-29009-5-git-send-email-antonynpavlov@gmail.com>

By default CONFIG_JZ4750D_DEBUG_LL_UART0 is selected.
This can confuse the Ritmix RZX50 user as the board
has only UART1 connected.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/configs/rzx50_defconfig |    1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/configs/rzx50_defconfig b/arch/mips/configs/rzx50_defconfig
index 5d994c7..7b75909 100644
--- a/arch/mips/configs/rzx50_defconfig
+++ b/arch/mips/configs/rzx50_defconfig
@@ -1,4 +1,5 @@
 CONFIG_MACH_MIPS_XBURST=y
+CONFIG_JZ4750D_DEBUG_LL_UART1=y
 CONFIG_PBL_IMAGE=y
 CONFIG_BAUDRATE=57600
 CONFIG_GLOB=y
-- 
1.7.10.4



From antonynpavlov at gmail.com  Sat Jun  1 03:52:48 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Sat,  1 Jun 2013 11:52:48 +0400
Subject: [PATCH 5/6] MIPS: malta: adapt for new debug_ll
In-Reply-To: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370073169-29009-6-git-send-email-antonynpavlov@gmail.com>

Set fake DEBUG_LL_UART_DIVISOR to use <asm/debug_ll_ns16550.h>.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/mach-malta/include/mach/hardware.h |    1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/mach-malta/include/mach/hardware.h b/arch/mips/mach-malta/include/mach/hardware.h
index 5e8e276..8bd814d 100644
--- a/arch/mips/mach-malta/include/mach/hardware.h
+++ b/arch/mips/mach-malta/include/mach/hardware.h
@@ -20,6 +20,7 @@
 
 #define DEBUG_LL_UART_ADDR	0xb00003f8
 #define DEBUG_LL_UART_SHIFT	0
+#define DEBUG_LL_UART_DIVISOR	1	/* no matter for emulated port */
 
 /*
  * Reset register.
-- 
1.7.10.4



From antonynpavlov at gmail.com  Sat Jun  1 03:52:49 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Sat,  1 Jun 2013 11:52:49 +0400
Subject: [PATCH 6/6] MIPS: unificate ns16550 debug_ll support code
In-Reply-To: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370073169-29009-7-git-send-email-antonynpavlov@gmail.com>

This commit moves the C debug_ll code from
the MIPS <debug_ll_ns16550.h> header file to
the MIPS <asm/debug_ll_ns16550.h> header file,
so the C code and the asm code can use the same
register address macros.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/include/asm/debug_ll_ns16550.h      |   15 ++++++++++
 arch/mips/include/debug_ll_ns16550.h          |   37 -------------------------
 arch/mips/mach-malta/include/mach/debug_ll.h  |    2 +-
 arch/mips/mach-xburst/include/mach/debug_ll.h |    2 +-
 4 files changed, 17 insertions(+), 39 deletions(-)
 delete mode 100644 arch/mips/include/debug_ll_ns16550.h

diff --git a/arch/mips/include/asm/debug_ll_ns16550.h b/arch/mips/include/asm/debug_ll_ns16550.h
index 5dd1b39..f00f348 100644
--- a/arch/mips/include/asm/debug_ll_ns16550.h
+++ b/arch/mips/include/asm/debug_ll_ns16550.h
@@ -48,6 +48,20 @@
 
 #define UART_LSR_THRE	0x20	/* Xmit holding register empty */
 
+#ifndef __ASSEMBLY__
+/*
+ * C macros
+ */
+
+#include <asm/io.h>
+
+static __inline__ void PUTC_LL(char ch)
+{
+	while (!(__raw_readb((u8 *)DEBUG_LL_UART_ADDR + UART_LSR) & UART_LSR_THRE))
+		;
+	__raw_writeb(ch, (u8 *)DEBUG_LL_UART_ADDR + UART_THR);
+}
+#else /* __ASSEMBLY__ */
 /*
  * Macros for use in assembly language code
  */
@@ -96,5 +110,6 @@
 	debug_ll_ns16550_outc '\n'
 #endif /* CONFIG_DEBUG_LL */
 .endm
+#endif /* __ASSEMBLY__ */
 
 #endif /* __INCLUDE_MIPS_ASM_DEBUG_LL_NS16550_H__ */
diff --git a/arch/mips/include/debug_ll_ns16550.h b/arch/mips/include/debug_ll_ns16550.h
deleted file mode 100644
index e9c7ecf..0000000
--- a/arch/mips/include/debug_ll_ns16550.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2012 Antony Pavlov <antonynpavlov at gmail.com>
- *
- * This file is part of barebox.
- * 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 version 2
- * as published by the Free Software Foundation.
- *
- * 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.
- *
- */
-
-/** @file
- *  This file contains declaration for early output support
- */
-#ifndef __INCLUDE_ARCH_DEBUG_LL_NS16550_H__
-#define __INCLUDE_ARCH_DEBUG_LL_NS16550_H__
-
-#include <asm/io.h>
-
-#define rbr		(0 << DEBUG_LL_UART_SHIFT)
-#define lsr		(5 << DEBUG_LL_UART_SHIFT)
-
-#define LSR_THRE	0x20	/* Xmit holding register empty */
-
-static __inline__ void PUTC_LL(char ch)
-{
-	while (!(__raw_readb((u8 *)DEBUG_LL_UART_ADDR + lsr) & LSR_THRE));
-	__raw_writeb(ch, (u8 *)DEBUG_LL_UART_ADDR + rbr);
-}
-
-#endif  /* __INCLUDE_ARCH_DEBUG_LL_NS16550_H__ */
diff --git a/arch/mips/mach-malta/include/mach/debug_ll.h b/arch/mips/mach-malta/include/mach/debug_ll.h
index 3a91c93..3e8b01b 100644
--- a/arch/mips/mach-malta/include/mach/debug_ll.h
+++ b/arch/mips/mach-malta/include/mach/debug_ll.h
@@ -23,6 +23,6 @@
 
 #include <mach/hardware.h>
 
-#include <debug_ll_ns16550.h>
+#include <asm/debug_ll_ns16550.h>
 
 #endif  /* __INCLUDE_ARCH_DEBUG_LL_H__ */
diff --git a/arch/mips/mach-xburst/include/mach/debug_ll.h b/arch/mips/mach-xburst/include/mach/debug_ll.h
index f260e65..6c3c980 100644
--- a/arch/mips/mach-xburst/include/mach/debug_ll.h
+++ b/arch/mips/mach-xburst/include/mach/debug_ll.h
@@ -22,6 +22,6 @@
  *  This File contains declaration for early output support
  */
 #include <board/debug_ll.h>
-#include <debug_ll_ns16550.h>
+#include <asm/debug_ll_ns16550.h>
 
 #endif  /* __MACH_XBURST_DEBUG_LL__ */
-- 
1.7.10.4



From antonynpavlov at gmail.com  Sat Jun  1 04:07:48 2013
From: antonynpavlov at gmail.com (antonynpavlov at gmail.com)
Date: Sat, 1 Jun 2013 12:07:48 +0400
Subject: [PATCH 6/6] MIPS: unificate ns16550 debug_ll support code
In-Reply-To: <1370073169-29009-7-git-send-email-antonynpavlov@gmail.com>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
 <1370073169-29009-7-git-send-email-antonynpavlov@gmail.com>
Message-ID: <20130601120748.b43bc182517396a9b492736e@gmail.com>

On Sat,  1 Jun 2013 11:52:49 +0400
Antony Pavlov <antonynpavlov at gmail.com> wrote:

Sorry, not "unificate" but "unify".

> This commit moves the C debug_ll code from
> the MIPS <debug_ll_ns16550.h> header file to
> the MIPS <asm/debug_ll_ns16550.h> header file,
> so the C code and the asm code can use the same
> register address macros.
> 
> Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> ---
>  arch/mips/include/asm/debug_ll_ns16550.h      |   15 ++++++++++
>  arch/mips/include/debug_ll_ns16550.h          |   37 -------------------------
>  arch/mips/mach-malta/include/mach/debug_ll.h  |    2 +-
>  arch/mips/mach-xburst/include/mach/debug_ll.h |    2 +-
>  4 files changed, 17 insertions(+), 39 deletions(-)
>  delete mode 100644 arch/mips/include/debug_ll_ns16550.h
> 
> diff --git a/arch/mips/include/asm/debug_ll_ns16550.h b/arch/mips/include/asm/debug_ll_ns16550.h
> index 5dd1b39..f00f348 100644
> --- a/arch/mips/include/asm/debug_ll_ns16550.h
> +++ b/arch/mips/include/asm/debug_ll_ns16550.h
> @@ -48,6 +48,20 @@
>  
>  #define UART_LSR_THRE	0x20	/* Xmit holding register empty */
>  
> +#ifndef __ASSEMBLY__
> +/*
> + * C macros
> + */
> +
> +#include <asm/io.h>
> +
> +static __inline__ void PUTC_LL(char ch)
> +{
> +	while (!(__raw_readb((u8 *)DEBUG_LL_UART_ADDR + UART_LSR) & UART_LSR_THRE))
> +		;
> +	__raw_writeb(ch, (u8 *)DEBUG_LL_UART_ADDR + UART_THR);
> +}
> +#else /* __ASSEMBLY__ */
>  /*
>   * Macros for use in assembly language code
>   */
> @@ -96,5 +110,6 @@
>  	debug_ll_ns16550_outc '\n'
>  #endif /* CONFIG_DEBUG_LL */
>  .endm
> +#endif /* __ASSEMBLY__ */
>  
>  #endif /* __INCLUDE_MIPS_ASM_DEBUG_LL_NS16550_H__ */
> diff --git a/arch/mips/include/debug_ll_ns16550.h b/arch/mips/include/debug_ll_ns16550.h
> deleted file mode 100644
> index e9c7ecf..0000000
> --- a/arch/mips/include/debug_ll_ns16550.h
> +++ /dev/null
> @@ -1,37 +0,0 @@
> -/*
> - * Copyright (C) 2012 Antony Pavlov <antonynpavlov at gmail.com>
> - *
> - * This file is part of barebox.
> - * 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 version 2
> - * as published by the Free Software Foundation.
> - *
> - * 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.
> - *
> - */
> -
> -/** @file
> - *  This file contains declaration for early output support
> - */
> -#ifndef __INCLUDE_ARCH_DEBUG_LL_NS16550_H__
> -#define __INCLUDE_ARCH_DEBUG_LL_NS16550_H__
> -
> -#include <asm/io.h>
> -
> -#define rbr		(0 << DEBUG_LL_UART_SHIFT)
> -#define lsr		(5 << DEBUG_LL_UART_SHIFT)
> -
> -#define LSR_THRE	0x20	/* Xmit holding register empty */
> -
> -static __inline__ void PUTC_LL(char ch)
> -{
> -	while (!(__raw_readb((u8 *)DEBUG_LL_UART_ADDR + lsr) & LSR_THRE));
> -	__raw_writeb(ch, (u8 *)DEBUG_LL_UART_ADDR + rbr);
> -}
> -
> -#endif  /* __INCLUDE_ARCH_DEBUG_LL_NS16550_H__ */
> diff --git a/arch/mips/mach-malta/include/mach/debug_ll.h b/arch/mips/mach-malta/include/mach/debug_ll.h
> index 3a91c93..3e8b01b 100644
> --- a/arch/mips/mach-malta/include/mach/debug_ll.h
> +++ b/arch/mips/mach-malta/include/mach/debug_ll.h
> @@ -23,6 +23,6 @@
>  
>  #include <mach/hardware.h>
>  
> -#include <debug_ll_ns16550.h>
> +#include <asm/debug_ll_ns16550.h>
>  
>  #endif  /* __INCLUDE_ARCH_DEBUG_LL_H__ */
> diff --git a/arch/mips/mach-xburst/include/mach/debug_ll.h b/arch/mips/mach-xburst/include/mach/debug_ll.h
> index f260e65..6c3c980 100644
> --- a/arch/mips/mach-xburst/include/mach/debug_ll.h
> +++ b/arch/mips/mach-xburst/include/mach/debug_ll.h
> @@ -22,6 +22,6 @@
>   *  This File contains declaration for early output support
>   */
>  #include <board/debug_ll.h>
> -#include <debug_ll_ns16550.h>
> +#include <asm/debug_ll_ns16550.h>
>  
>  #endif  /* __MACH_XBURST_DEBUG_LL__ */
> -- 
> 1.7.10.4
> 


-- 
--?
Best regards,
? Antony Pavlov


From antonynpavlov at gmail.com  Sat Jun  1 04:13:11 2013
From: antonynpavlov at gmail.com (antonynpavlov at gmail.com)
Date: Sat, 1 Jun 2013 12:13:11 +0400
Subject: bootm command support for x86
In-Reply-To: <CAJBvFxM9zECHftuSLWfLaiN+ZiVRZQjx0zTggUD3KVRttRBTtg@mail.gmail.com>
References: <CAJBvFxM9zECHftuSLWfLaiN+ZiVRZQjx0zTggUD3KVRttRBTtg@mail.gmail.com>
Message-ID: <20130601121311.0128e813920fb934370e8caf@gmail.com>

On Sat, 1 Jun 2013 10:51:03 +0900
Masaki Muranaka <monaka at monami-ya.jp> wrote:

Can you use 'git format-patch' to prepare your patches and 'git send-email' to send them, please?

> It enables to build bootm command on generic_x86.
> I'm not sure but I guess we don't need defined(__I386__) check.
> I kept it for now.
> 
> diff --git a/include/image.h b/include/image.h
> index 219419b..0c8a4b1 100644
> --- a/include/image.h
> +++ b/include/image.h
> @@ -89,7 +89,7 @@
>  #define IH_ARCH IH_ARCH_PPC
>  #elif defined(__ARM__)
>  #define IH_ARCH IH_ARCH_ARM
> -#elif defined(__I386__) || defined(__x86_64__)
> +#elif defined(__I386__) || defined(__x86_64__) || defined(__i386__)
>  #define IH_ARCH IH_ARCH_I386
>  #elif defined(__mips__)
>  #define IH_ARCH IH_ARCH_MIPS
> 
> 
> --
> --
> Masaki Muranaka
> Monami-ya LLC, Japan.
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

--?
Best regards,
? Antony Pavlov


From s.hauer at pengutronix.de  Sat Jun  1 05:20:18 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 1 Jun 2013 11:20:18 +0200
Subject: [PATCH] gianfar: prevent resource conflict
In-Reply-To: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
References: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <20130601092018.GO32299@pengutronix.de>

On Thu, May 30, 2013 at 04:15:35PM +0100, Renaud Barbier wrote:
> On eTSEC Ethernet devices, there are three memory regions to map.
> These regions map registers to control the TSEC interfaces, PHY
> access and TBI interface.
> 
> Depending on the port number and TSEC version, some of these resources
> may be shared within an instance of the driver or between instances
> of the driver.
> 
> Since dev_request_mem_region returns NULL to avoid resource conflicts if
> a region is already mapped the TSEC driver fails to initialise when
> these regions are shared. This patch works around this and makes
> all three memory regions available to each instance.
> 
> Below is a description of TSEC Ethernet port mapping for port 1 to 3.
> These ports are present in CPUs susch as the mpc8544 and P2020.
> 
> Each port has three set of registers:
> * region 0 maps the TSEC registers.
> * region 1 maps the PHY access registers always through port 1.
> * region 2 maps the TBI interface registers.
> 
> The tables below shows how registers are mapped.
> For instance, for TSEC version 1:
> - port 2/register set 1 i.e p2/reg1 is the same region as
>   port 1/register set 1 i.e p1/reg1. That is they share port 1
>   register set 1 as the same region.
>   As well is p3/reg1, p1/reg0 and p1/reg2 uses p1/reg1.
> 
> - port 2/register set 0 i.e p2/reg0 is not the same region as
>   port 3/register set 0 i.e p3/reg0.
>   That is p2/r0 and p3/r0 are two different regions.
>   However, port 2/register 2 is the same as port 2/register 0.
> 
> TSEC version 1:
> ports/registers  reg0    reg1    reg2
> p1               p1/r1   p1/r1   p1/r1
> p2               p2/r0   p1/r1   p2/r0
> p3               p3/r0   p1/r1   p3/r0
> 
> TSEC version2:
> ports/registers  reg0    reg1    reg2
> p1               p1/r0   p1/r1   p1/r1
> p2               p2/r0   p1/r1   p2/r2
> p3               p3/r0   p1/r1   p3/r2
> 
> Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
> ---
>  drivers/net/gianfar.c |   19 ++++++++++++++++++-
>  1 files changed, 18 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
> index 96055bd..79113a8 100644
> --- a/drivers/net/gianfar.c
> +++ b/drivers/net/gianfar.c
> @@ -28,6 +28,8 @@
>  #define RX_BUF_CNT 	PKTBUFSRX
>  #define BUF_ALIGN	8
>  
> +static void __iomem *phyregs;
> +
>  /*
>   * Initialize required registers to appropriate values, zeroing
>   * those we don't care about (unless zero is bad, in which case,
> @@ -481,8 +483,23 @@ static int gfar_probe(struct device_d *dev)
>  	edev = &priv->edev;
>  
>  	priv->regs = dev_request_mem_region(dev, 0);
> -	priv->phyregs = dev_request_mem_region(dev, 1);
> +	if (priv->regs == NULL)
> +		priv->regs = phyregs;

the first resource is for the ethernet registers and no phy registers,
right?

> +
> +	if (phyregs == NULL) {
> +		phyregs = dev_request_mem_region(dev, 1);
> +		if (phyregs == NULL)
> +			phyregs = priv->regs;
> +	}
> +	priv->phyregs = phyregs;
> +
>  	priv->phyregs_sgmii = dev_request_mem_region(dev, 2);
> +	if (priv->phyregs_sgmii == NULL) {
> +		if (IS_ENABLED(CONFIG_TSECV2))
> +			priv->phyregs_sgmii = priv->phyregs;
> +		else
> +			priv->phyregs_sgmii = priv->regs;
> +	}

I think you should really register the mdio buses as separate devices
since it's the mdio buses that are shared between the different
instances, not the registers. The following may be a starting point
(untested)



>From 480a54380c42d56e1b5f16fb718fe2c4a1a38ab0 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer at pengutronix.de>
Date: Sat, 1 Jun 2013 11:16:37 +0200
Subject: [PATCH] net: gfar: register mdio buses as separate devices

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/ppc/boards/freescale-p2020rdb/p2020rdb.c |   2 +
 arch/ppc/mach-mpc85xx/eth-devices.c           |  32 +++----
 arch/ppc/mach-mpc85xx/include/mach/gianfar.h  |   2 +
 drivers/net/gianfar.c                         | 117 ++++++++++++++++++--------
 drivers/net/gianfar.h                         |   5 +-
 5 files changed, 103 insertions(+), 55 deletions(-)

diff --git a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
index edb9bcd..cc4af7f 100644
--- a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
+++ b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
@@ -65,6 +65,8 @@ static struct gfar_info_struct gfar_info[] = {
 		.phyaddr = 1,
 		.tbiana = 0,
 		.tbicr = 0,
+		.mdiobus = -1, /* FIXME */
+		.mdiobus_sgmii = -1, /* FIXME */
 	},
 };
 
diff --git a/arch/ppc/mach-mpc85xx/eth-devices.c b/arch/ppc/mach-mpc85xx/eth-devices.c
index c6e8f36..510e57c 100644
--- a/arch/ppc/mach-mpc85xx/eth-devices.c
+++ b/arch/ppc/mach-mpc85xx/eth-devices.c
@@ -22,28 +22,28 @@
 
 #include <common.h>
 #include <driver.h>
+#include <init.h>
 #include <mach/immap_85xx.h>
 #include <mach/gianfar.h>
 
-int fsl_eth_init(int num, struct gfar_info_struct *gf)
+static int fsl_phy_init(void)
 {
-	struct resource *res;
+	int i;
+
+	for (i = 0; i < 4; i++)
+		add_generic_device("gfar-phy", i, NULL,
+				MDIO_BASE_ADDR + i * 0x1000, 0x1000,
+				IORESOURCE_MEM, NULL);
+	return 0;
+}
 
-	res = xzalloc(3 * sizeof(struct resource));
-	/* TSEC interface registers */
-	res[0].start = GFAR_BASE_ADDR + ((num - 1) * 0x1000);
-	res[0].end = res[0].start + 0x1000 - 1;
-	res[0].flags = IORESOURCE_MEM;
-	/* External PHY access always through eTSEC1 */
-	res[1].start = MDIO_BASE_ADDR;
-	res[1].end = res[1].start + 0x1000 - 1;
-	res[1].flags = IORESOURCE_MEM;
-	/* Access to TBI/RTBI interface. */
-	res[2].start = MDIO_BASE_ADDR + ((num - 1) * 0x1000);
-	res[2].end = res[2].start + 0x1000 - 1;
-	res[2].flags = IORESOURCE_MEM;
+coredevice_initcall(fsl_phy_init);
 
-	add_generic_device_res("gfar", DEVICE_ID_DYNAMIC, res, 3, gf);
+int fsl_eth_init(int num, struct gfar_info_struct *gf)
+{
+	add_generic_device("gfar", num - 1, NULL,
+			GFAR_BASE_ADDR + (num - 1) * 0x1000, 0x1000,
+			IORESOURCE_MEM, gf);
 
 	return 0;
 }
diff --git a/arch/ppc/mach-mpc85xx/include/mach/gianfar.h b/arch/ppc/mach-mpc85xx/include/mach/gianfar.h
index ae31638..48dd945 100644
--- a/arch/ppc/mach-mpc85xx/include/mach/gianfar.h
+++ b/arch/ppc/mach-mpc85xx/include/mach/gianfar.h
@@ -26,6 +26,8 @@ struct gfar_info_struct {
 	unsigned int phyaddr;
 	unsigned int tbiana;
 	unsigned int tbicr;
+	unsigned int mdiobus; /* mdio bus number (0..3) */
+	unsigned int mdiobus_sgmii; /* mdio bus number for sgmii (0..3) */
 };
 
 int fsl_eth_init(int num, struct gfar_info_struct *gf);
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 96055bd..bb4931e 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -28,6 +28,14 @@
 #define RX_BUF_CNT 	PKTBUFSRX
 #define BUF_ALIGN	8
 
+struct gfar_phy {
+	void __iomem *regs;
+	struct device_d *dev;
+	struct mii_bus miibus;
+};
+
+static struct gfar_phy *phys[4];
+
 /*
  * Initialize required registers to appropriate values, zeroing
  * those we don't care about (unless zero is bad, in which case,
@@ -184,10 +192,11 @@ static int gfar_open(struct eth_device *edev)
 {
 	int ix;
 	struct gfar_private *priv = edev->priv;
+	struct gfar_phy *phy = phys[priv->mdiobus];
 	void __iomem *regs = priv->regs;
 	int ret;
 
-	ret = phy_device_connect(edev, &priv->miibus, priv->phyaddr,
+	ret = phy_device_connect(edev, &phy->miibus, priv->phyaddr,
 				 gfar_adjust_link, 0, PHY_INTERFACE_MODE_NA);
 	if (ret)
 		return ret;
@@ -255,17 +264,21 @@ static int gfar_set_ethaddr(struct eth_device *edev, unsigned char *mac)
 }
 
 /* Writes the given phy's reg with value, using the specified MDIO regs */
-static int gfar_local_mdio_write(void __iomem *phyregs, uint addr, uint reg,
+static int gfar_local_mdio_write(int mdiobus, uint addr, uint reg,
 				uint value)
 {
+	struct gfar_phy *phy = phys[mdiobus];
 	uint64_t start;
 
-	out_be32(phyregs + GFAR_MIIMADD_OFFSET, (addr << 8) | (reg & 0x1f));
-	out_be32(phyregs + GFAR_MIIMCON_OFFSET, value);
+	if (!phy)
+		return -ENODEV;
+
+	out_be32(phy->regs + GFAR_MIIMADD_OFFSET, (addr << 8) | (reg & 0x1f));
+	out_be32(phy->regs + GFAR_MIIMCON_OFFSET, value);
 
 	start = get_time_ns();
 	while (!is_timeout(start, 10 * MSECOND)) {
-		if (!(in_be32(phyregs + GFAR_MIIMMIND_OFFSET) &
+		if (!(in_be32(phy->regs + GFAR_MIIMMIND_OFFSET) &
 					GFAR_MIIMIND_BUSY))
 			return 0;
 	}
@@ -280,24 +293,28 @@ static int gfar_local_mdio_write(void __iomem *phyregs, uint addr, uint reg,
  * notvalid bit cleared), and the bus to cease activity (miimind
  * busy bit cleared), and then returns the value
  */
-static uint gfar_local_mdio_read(void __iomem *phyregs, uint phyid, uint regnum)
+static uint gfar_local_mdio_read(int mdiobus, uint phyid, uint regnum)
 {
+	struct gfar_phy *phy = phys[mdiobus];
 	uint64_t start;
 
+	if (!phy)
+		return -ENODEV;
+
 	/* Put the address of the phy, and the register number into MIIMADD */
-	out_be32(phyregs + GFAR_MIIMADD_OFFSET, (phyid << 8) | (regnum & 0x1f));
+	out_be32(phy->regs + GFAR_MIIMADD_OFFSET, (phyid << 8) | (regnum & 0x1f));
 
 	/* Clear the command register, and wait */
-	out_be32(phyregs + GFAR_MIIMCOM_OFFSET, 0);
+	out_be32(phy->regs + GFAR_MIIMCOM_OFFSET, 0);
 
 	/* Initiate a read command, and wait */
-	out_be32(phyregs + GFAR_MIIMCOM_OFFSET, GFAR_MIIM_READ_COMMAND);
+	out_be32(phy->regs + GFAR_MIIMCOM_OFFSET, GFAR_MIIM_READ_COMMAND);
 
 	start = get_time_ns();
 	while (!is_timeout(start, 10 * MSECOND)) {
-		if (!(in_be32(phyregs + GFAR_MIIMMIND_OFFSET) &
+		if (!(in_be32(phy->regs + GFAR_MIIMMIND_OFFSET) &
 			(GFAR_MIIMIND_NOTVALID | GFAR_MIIMIND_BUSY)))
-			return in_be32(phyregs + GFAR_MIIMSTAT_OFFSET);
+			return in_be32(phy->regs + GFAR_MIIMSTAT_OFFSET);
 	}
 
 	return -EIO;
@@ -305,13 +322,13 @@ static uint gfar_local_mdio_read(void __iomem *phyregs, uint phyid, uint regnum)
 
 static void gfar_configure_serdes(struct gfar_private *priv)
 {
-	gfar_local_mdio_write(priv->phyregs_sgmii,
+	gfar_local_mdio_write(priv->mdiobus_sgmii,
 			in_be32(priv->regs + GFAR_TBIPA_OFFSET), GFAR_TBI_ANA,
 			priv->tbiana);
-	gfar_local_mdio_write(priv->phyregs_sgmii,
+	gfar_local_mdio_write(priv->mdiobus_sgmii,
 			in_be32(priv->regs + GFAR_TBIPA_OFFSET),
 			GFAR_TBI_TBICON, GFAR_TBICON_CLK_SELECT);
-	gfar_local_mdio_write(priv->phyregs_sgmii,
+	gfar_local_mdio_write(priv->mdiobus_sgmii,
 			in_be32(priv->regs + GFAR_TBIPA_OFFSET), GFAR_TBI_CR,
 			priv->tbicr);
 }
@@ -320,29 +337,33 @@ static void gfar_configure_serdes(struct gfar_private *priv)
 static void gfar_init_phy(struct eth_device *dev)
 {
 	struct gfar_private *priv = dev->priv;
+	struct gfar_phy *phy = phys[priv->mdiobus];
 	void __iomem *regs = priv->regs;
 	uint64_t start;
 
+	if (!phy)
+		return;
+
 	/* Assign a Physical address to the TBI */
 	out_be32(regs + GFAR_TBIPA_OFFSET, GFAR_TBIPA_VALUE);
 
 	/* Reset MII (due to new addresses) */
-	out_be32(priv->phyregs + GFAR_MIIMCFG_OFFSET, GFAR_MIIMCFG_RESET);
-	out_be32(priv->phyregs + GFAR_MIIMCFG_OFFSET, GFAR_MIIMCFG_INIT_VALUE);
+	out_be32(phy->regs + GFAR_MIIMCFG_OFFSET, GFAR_MIIMCFG_RESET);
+	out_be32(phy->regs + GFAR_MIIMCFG_OFFSET, GFAR_MIIMCFG_INIT_VALUE);
 
 	start = get_time_ns();
 	while (!is_timeout(start, 10 * MSECOND)) {
-		if (!(in_be32(priv->phyregs + GFAR_MIIMMIND_OFFSET) &
+		if (!(in_be32(phy->regs + GFAR_MIIMMIND_OFFSET) &
 			GFAR_MIIMIND_BUSY))
 			break;
 	}
 
-	gfar_local_mdio_write(priv->phyregs, priv->phyaddr, GFAR_MIIM_CR,
+	gfar_local_mdio_write(priv->mdiobus, priv->phyaddr, GFAR_MIIM_CR,
 			GFAR_MIIM_CR_RST);
 
 	start = get_time_ns();
 	while (!is_timeout(start, 10 * MSECOND)) {
-		if (!(gfar_local_mdio_read(priv->phyregs, priv->phyaddr,
+		if (!(gfar_local_mdio_read(priv->mdiobus, priv->phyaddr,
 					GFAR_MIIM_CR) & GFAR_MIIM_CR_RST))
 			break;
 	}
@@ -433,13 +454,12 @@ static int gfar_recv(struct eth_device *edev)
 /* Read a MII PHY register. */
 static int gfar_miiphy_read(struct mii_bus *bus, int addr, int reg)
 {
-	struct device_d *dev = bus->parent;
-	struct gfar_private *priv = bus->priv;
+	struct gfar_phy *phy = bus->priv;
 	int ret;
 
-	ret = gfar_local_mdio_read(priv->phyregs, addr, reg);
+	ret = gfar_local_mdio_read(phy->dev->id, addr, reg);
 	if (ret == -EIO)
-		dev_err(dev, "Can't read PHY at address %d\n", addr);
+		dev_err(phy->dev, "Can't read PHY at address %d\n", addr);
 
 	return ret;
 }
@@ -448,15 +468,14 @@ static int gfar_miiphy_read(struct mii_bus *bus, int addr, int reg)
 static int gfar_miiphy_write(struct mii_bus *bus, int addr, int reg,
 				u16 value)
 {
-	struct device_d *dev = bus->parent;
-	struct gfar_private *priv = bus->priv;
+	struct gfar_phy *phy = bus->priv;
 	unsigned short val = value;
 	int ret;
 
-	ret = gfar_local_mdio_write(priv->phyregs, addr, reg, val);
+	ret = gfar_local_mdio_write(phy->dev->id, addr, reg, val);
 
 	if (ret)
-		dev_err(dev, "Can't write PHY at address %d\n", addr);
+		dev_err(phy->dev, "Can't write PHY at address %d\n", addr);
 
 	return 0;
 }
@@ -481,8 +500,12 @@ static int gfar_probe(struct device_d *dev)
 	edev = &priv->edev;
 
 	priv->regs = dev_request_mem_region(dev, 0);
-	priv->phyregs = dev_request_mem_region(dev, 1);
-	priv->phyregs_sgmii = dev_request_mem_region(dev, 2);
+	priv->mdiobus = gfar_info->mdiobus;
+	priv->mdiobus_sgmii = gfar_info->mdiobus_sgmii;
+
+	if (priv->mdiobus >= ARRAY_SIZE(phys) ||
+			priv->mdiobus_sgmii >= ARRAY_SIZE(phys))
+		return -EINVAL;
 
 	priv->phyaddr = gfar_info->phyaddr;
 	priv->tbicr = gfar_info->tbicr;
@@ -512,15 +535,8 @@ static int gfar_probe(struct device_d *dev)
 	udelay(2);
 	clrbits_be32(priv->regs + GFAR_MACCFG1_OFFSET, GFAR_MACCFG1_SOFT_RESET);
 
-	priv->miibus.read = gfar_miiphy_read;
-	priv->miibus.write = gfar_miiphy_write;
-	priv->miibus.priv = priv;
-	priv->miibus.parent = dev;
-
 	gfar_init_phy(edev);
 
-	mdiobus_register(&priv->miibus);
-
 	return eth_register(edev);
 }
 
@@ -529,3 +545,32 @@ static struct driver_d gfar_eth_driver = {
 	.probe = gfar_probe,
 };
 device_platform_driver(gfar_eth_driver);
+
+static int gfar_phy_probe(struct device_d *dev)
+{
+	struct gfar_phy *phy;
+	int ret;
+
+	phy = xzalloc(sizeof(*phy));
+	phy->dev = dev;
+	phy->regs = dev_request_mem_region(dev, 0);
+	if (!phy->regs)
+		return -ENOMEM;
+
+	phy->miibus.read = gfar_miiphy_read;
+	phy->miibus.write = gfar_miiphy_write;
+	phy->miibus.priv = phy;
+	phy->miibus.parent = dev;
+
+	ret = mdiobus_register(&phy->miibus);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static struct driver_d gfar_phy_driver = {
+	.name  = "gfar-phy",
+	.probe = gfar_phy_probe,
+};
+register_driver_macro(coredevice, platform, gfar_phy_driver);
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index b52cc5a..9094506 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -266,10 +266,9 @@ struct rxbd8 {
 struct gfar_private {
 	struct eth_device edev;
 	void __iomem *regs;
-	void __iomem *phyregs;
-	void __iomem *phyregs_sgmii;
+	int mdiobus;
+	int mdiobus_sgmii;
 	struct phy_info *phyinfo;
-	struct mii_bus miibus;
 	volatile struct txbd8 *txbd;
 	volatile struct rxbd8 *rxbd;
 	uint txidx;
-- 
1.8.2.rc2

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From monaka at monami-ya.jp  Sat Jun  1 09:58:25 2013
From: monaka at monami-ya.jp (monaka at monami-ya.jp)
Date: Sat,  1 Jun 2013 22:58:25 +0900
Subject: [PATCH] Enables to build bootm command on generic_x86.
Message-ID: <1370095105-63468-1-git-send-email-monaka@monami-ya.com>

From: Masaki Muranaka <monaka at monami-ya.jp>

I'm not sure but I guess we don't need defined(__I386__) check.
I kept it for now.

Signed-off-by: Masaki Muranaka <monaka at monami-ya.com>
---
 include/image.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/image.h b/include/image.h
index 219419b..0c8a4b1 100644
--- a/include/image.h
+++ b/include/image.h
@@ -89,7 +89,7 @@
 #define IH_ARCH IH_ARCH_PPC
 #elif defined(__ARM__)
 #define IH_ARCH IH_ARCH_ARM
-#elif defined(__I386__) || defined(__x86_64__)
+#elif defined(__I386__) || defined(__x86_64__) || defined(__i386__)
 #define IH_ARCH IH_ARCH_I386
 #elif defined(__mips__)
 #define IH_ARCH IH_ARCH_MIPS
-- 
1.8.3



From monaka at monami-ya.jp  Sat Jun  1 10:05:22 2013
From: monaka at monami-ya.jp (monaka at monami-ya.jp)
Date: Sat,  1 Jun 2013 23:05:22 +0900
Subject: [PATCH] [x86] Avoid build error on "config SPI" is y
Message-ID: <1370095522-63657-1-git-send-email-monaka@monami-ya.com>

From: Masaki Muranaka <monaka at monami-ya.com>

In case he configures with make ARCH=x85 menuconfig,
config SPI will be set to "y". And he will got an error on spi.h.

Signed-off-by: Masaki Muranaka <monaka at monami-ya.com>
---
 arch/x86/include/asm/types.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/x86/include/asm/types.h b/arch/x86/include/asm/types.h
index b0218d2..d473405 100644
--- a/arch/x86/include/asm/types.h
+++ b/arch/x86/include/asm/types.h
@@ -29,12 +29,16 @@ typedef unsigned int __u32;
 typedef __signed__ long long __s64;
 typedef unsigned long long __u64;
 
+typedef signed char s8;
 typedef unsigned char u8;
 
+typedef signed short s16;
 typedef unsigned short u16;
 
+typedef signed int s32;
 typedef unsigned int u32;
 
+typedef signed long long s64;
 typedef unsigned long long u64;
 
 #endif /* __ASSEMBLY__ */
-- 
1.8.3



From monaka at monami-ya.jp  Sat Jun  1 11:56:44 2013
From: monaka at monami-ya.jp (monaka at monami-ya.jp)
Date: Sun,  2 Jun 2013 00:56:44 +0900
Subject: [PATCH] Use FILE structure for stdin/stdout/stderr.
Message-ID: <1370102204-74399-1-git-send-email-monaka@monami-ya.com>

From: Masaki Muranaka <monaka at monami-ya.com>

Signed-off-by: Masaki Muranaka <monaka at monami-ya.com>
---
 common/console.c        |  6 +++---
 common/console_common.c | 19 +++++++++----------
 include/filetype.h      |  2 ++
 include/stdio.h         | 17 +++++++++--------
 4 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/common/console.c b/common/console.c
index a0a06f6..7a8ac4f 100644
--- a/common/console.c
+++ b/common/console.c
@@ -246,13 +246,13 @@ int getc(void)
 }
 EXPORT_SYMBOL(getc);
 
-int fgetc(int fd)
+int fgetc(FILE *file)
 {
 	char c;
 
-	if (!fd)
+	if (file == stdin)
 		return getc();
-	return read(fd, &c, 1);
+	return read(file->no, &c, 1);
 }
 EXPORT_SYMBOL(fgetc);
 
diff --git a/common/console_common.c b/common/console_common.c
index d139d1a..34713f9 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -66,7 +66,7 @@ EXPORT_SYMBOL(vprintf);
 
 #endif /* !CONFIG_CONSOLE_NONE */
 
-int fprintf(int file, const char *fmt, ...)
+int fprintf(FILE *file, const char *fmt, ...)
 {
 	va_list args;
 	char printbuffer[CFG_PBSIZE];
@@ -85,26 +85,25 @@ int fprintf(int file, const char *fmt, ...)
 }
 EXPORT_SYMBOL(fprintf);
 
-int fputs(int fd, const char *s)
+int fputs(FILE *file, const char *s)
 {
-	if (fd == 1)
+	if (file == stdout)
 		return puts(s);
-	else if (fd == 2)
+	else if (file == stderr)
 		return eputs(s);
 	else
-		return write(fd, s, strlen(s));
+		return write(file->no, s, strlen(s));
 }
 EXPORT_SYMBOL(fputs);
 
-int fputc(int fd, char c)
+int fputc(FILE *file, char c)
 {
-	if (fd == 1)
+	if (file == stdout)
 		putchar(c);
-	else if (fd == 2)
+	else if (file == stderr)
 		eputc(c);
 	else
-		return write(fd, &c, 1);
-
+		return write(file->no, &c, 1);
 	return 0;
 }
 EXPORT_SYMBOL(fputc);
diff --git a/include/filetype.h b/include/filetype.h
index ee777ac..c73c64a 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -1,6 +1,8 @@
 #ifndef __FILE_TYPE_H
 #define __FILE_TYPE_H
 
+#include <linux/string.h>
+
 /*
  * List of file types we know
  */
diff --git a/include/stdio.h b/include/stdio.h
index 5c091a8..00d1ed7 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -3,6 +3,7 @@
 
 #include <stdarg.h>
 #include <console.h>
+#include <fs.h>
 
 /*
  * STDIO based functions (can always be used)
@@ -93,15 +94,15 @@ static inline void putchar(char c)
  * FILE based functions
  */
 
-#define stdin		0
-#define stdout		1
-#define stderr		2
+#define stdin		((FILE *)0x10)
+#define stdout		((FILE *)0x11)
+#define stderr		((FILE *)0x12)
 #define MAX_FILES	128
 
-int	fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
-int	fputs(int file, const char *s);
-int	fputc(int file, const char c);
-int	ftstc(int file);
-int	fgetc(int file);
+int	fprintf(FILE *file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
+int	fputs(FILE *file, const char *s);
+int	fputc(FILE *file, const char c);
+int	ftstc(FILE *file);
+int	fgetc(FILE *file);
 
 #endif /* __STDIO_H */
-- 
1.8.3



From monaka at monami-ya.jp  Sat Jun  1 21:08:53 2013
From: monaka at monami-ya.jp (monaka at monami-ya.jp)
Date: Sun,  2 Jun 2013 10:08:53 +0900
Subject: [PATCH] Fix typo.
Message-ID: <1370135333-79633-1-git-send-email-monaka@monami-ya.com>

From: Masaki Muranaka <monaka at monami-ya.com>

---
 include/stdio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/stdio.h b/include/stdio.h
index 5c091a8..0eacdfc 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -70,7 +70,7 @@ static inline int ctrlc (void)
 {
 	return 0;
 }
-#endif /* ARCH_HAS_CTRC */
+#endif /* ARCH_HAS_CTRLC */
 
 #endif
 
-- 
1.8.3



From s.hauer at pengutronix.de  Sun Jun  2 05:19:37 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 2 Jun 2013 11:19:37 +0200
Subject: [PATCH] [x86] Avoid build error on "config SPI" is y
In-Reply-To: <1370095522-63657-1-git-send-email-monaka@monami-ya.com>
References: <1370095522-63657-1-git-send-email-monaka@monami-ya.com>
Message-ID: <20130602091937.GQ32299@pengutronix.de>

On Sat, Jun 01, 2013 at 11:05:22PM +0900, monaka at monami-ya.jp wrote:
> From: Masaki Muranaka <monaka at monami-ya.com>
> 
> In case he configures with make ARCH=x85 menuconfig,
> config SPI will be set to "y". And he will got an error on spi.h.
> 
> Signed-off-by: Masaki Muranaka <monaka at monami-ya.com>

Applied, thanks

Sascha

> ---
>  arch/x86/include/asm/types.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/arch/x86/include/asm/types.h b/arch/x86/include/asm/types.h
> index b0218d2..d473405 100644
> --- a/arch/x86/include/asm/types.h
> +++ b/arch/x86/include/asm/types.h
> @@ -29,12 +29,16 @@ typedef unsigned int __u32;
>  typedef __signed__ long long __s64;
>  typedef unsigned long long __u64;
>  
> +typedef signed char s8;
>  typedef unsigned char u8;
>  
> +typedef signed short s16;
>  typedef unsigned short u16;
>  
> +typedef signed int s32;
>  typedef unsigned int u32;
>  
> +typedef signed long long s64;
>  typedef unsigned long long u64;
>  
>  #endif /* __ASSEMBLY__ */
> -- 
> 1.8.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sun Jun  2 05:21:27 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 2 Jun 2013 11:21:27 +0200
Subject: [PATCH] Enables to build bootm command on generic_x86.
In-Reply-To: <1370095105-63468-1-git-send-email-monaka@monami-ya.com>
References: <1370095105-63468-1-git-send-email-monaka@monami-ya.com>
Message-ID: <20130602092127.GR32299@pengutronix.de>

On Sat, Jun 01, 2013 at 10:58:25PM +0900, monaka at monami-ya.jp wrote:
> From: Masaki Muranaka <monaka at monami-ya.jp>
> 
> I'm not sure but I guess we don't need defined(__I386__) check.
> I kept it for now.
> 
> Signed-off-by: Masaki Muranaka <monaka at monami-ya.com>

Applied, thanks

Sascha


> ---
>  include/image.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/image.h b/include/image.h
> index 219419b..0c8a4b1 100644
> --- a/include/image.h
> +++ b/include/image.h
> @@ -89,7 +89,7 @@
>  #define IH_ARCH IH_ARCH_PPC
>  #elif defined(__ARM__)
>  #define IH_ARCH IH_ARCH_ARM
> -#elif defined(__I386__) || defined(__x86_64__)
> +#elif defined(__I386__) || defined(__x86_64__) || defined(__i386__)
>  #define IH_ARCH IH_ARCH_I386
>  #elif defined(__mips__)
>  #define IH_ARCH IH_ARCH_MIPS
> -- 
> 1.8.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sun Jun  2 05:25:15 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 2 Jun 2013 11:25:15 +0200
Subject: [PATCH 6/6] MIPS: unificate ns16550 debug_ll support code
In-Reply-To: <20130601120748.b43bc182517396a9b492736e@gmail.com>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
 <1370073169-29009-7-git-send-email-antonynpavlov@gmail.com>
 <20130601120748.b43bc182517396a9b492736e@gmail.com>
Message-ID: <20130602092515.GS32299@pengutronix.de>

On Sat, Jun 01, 2013 at 12:07:48PM +0400, antonynpavlov at gmail.com wrote:
> On Sat,  1 Jun 2013 11:52:49 +0400
> Antony Pavlov <antonynpavlov at gmail.com> wrote:
> 
> Sorry, not "unificate" but "unify".

Fixed this while applying.

Thanks
 Sascha

> 
> > This commit moves the C debug_ll code from
> > the MIPS <debug_ll_ns16550.h> header file to
> > the MIPS <asm/debug_ll_ns16550.h> header file,
> > so the C code and the asm code can use the same
> > register address macros.
> > 
> > Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> > ---
> >  arch/mips/include/asm/debug_ll_ns16550.h      |   15 ++++++++++
> >  arch/mips/include/debug_ll_ns16550.h          |   37 -------------------------
> >  arch/mips/mach-malta/include/mach/debug_ll.h  |    2 +-
> >  arch/mips/mach-xburst/include/mach/debug_ll.h |    2 +-
> >  4 files changed, 17 insertions(+), 39 deletions(-)
> >  delete mode 100644 arch/mips/include/debug_ll_ns16550.h
> > 
> > diff --git a/arch/mips/include/asm/debug_ll_ns16550.h b/arch/mips/include/asm/debug_ll_ns16550.h
> > index 5dd1b39..f00f348 100644
> > --- a/arch/mips/include/asm/debug_ll_ns16550.h
> > +++ b/arch/mips/include/asm/debug_ll_ns16550.h
> > @@ -48,6 +48,20 @@
> >  
> >  #define UART_LSR_THRE	0x20	/* Xmit holding register empty */
> >  
> > +#ifndef __ASSEMBLY__
> > +/*
> > + * C macros
> > + */
> > +
> > +#include <asm/io.h>
> > +
> > +static __inline__ void PUTC_LL(char ch)
> > +{
> > +	while (!(__raw_readb((u8 *)DEBUG_LL_UART_ADDR + UART_LSR) & UART_LSR_THRE))
> > +		;
> > +	__raw_writeb(ch, (u8 *)DEBUG_LL_UART_ADDR + UART_THR);
> > +}
> > +#else /* __ASSEMBLY__ */
> >  /*
> >   * Macros for use in assembly language code
> >   */
> > @@ -96,5 +110,6 @@
> >  	debug_ll_ns16550_outc '\n'
> >  #endif /* CONFIG_DEBUG_LL */
> >  .endm
> > +#endif /* __ASSEMBLY__ */
> >  
> >  #endif /* __INCLUDE_MIPS_ASM_DEBUG_LL_NS16550_H__ */
> > diff --git a/arch/mips/include/debug_ll_ns16550.h b/arch/mips/include/debug_ll_ns16550.h
> > deleted file mode 100644
> > index e9c7ecf..0000000
> > --- a/arch/mips/include/debug_ll_ns16550.h
> > +++ /dev/null
> > @@ -1,37 +0,0 @@
> > -/*
> > - * Copyright (C) 2012 Antony Pavlov <antonynpavlov at gmail.com>
> > - *
> > - * This file is part of barebox.
> > - * 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 version 2
> > - * as published by the Free Software Foundation.
> > - *
> > - * 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.
> > - *
> > - */
> > -
> > -/** @file
> > - *  This file contains declaration for early output support
> > - */
> > -#ifndef __INCLUDE_ARCH_DEBUG_LL_NS16550_H__
> > -#define __INCLUDE_ARCH_DEBUG_LL_NS16550_H__
> > -
> > -#include <asm/io.h>
> > -
> > -#define rbr		(0 << DEBUG_LL_UART_SHIFT)
> > -#define lsr		(5 << DEBUG_LL_UART_SHIFT)
> > -
> > -#define LSR_THRE	0x20	/* Xmit holding register empty */
> > -
> > -static __inline__ void PUTC_LL(char ch)
> > -{
> > -	while (!(__raw_readb((u8 *)DEBUG_LL_UART_ADDR + lsr) & LSR_THRE));
> > -	__raw_writeb(ch, (u8 *)DEBUG_LL_UART_ADDR + rbr);
> > -}
> > -
> > -#endif  /* __INCLUDE_ARCH_DEBUG_LL_NS16550_H__ */
> > diff --git a/arch/mips/mach-malta/include/mach/debug_ll.h b/arch/mips/mach-malta/include/mach/debug_ll.h
> > index 3a91c93..3e8b01b 100644
> > --- a/arch/mips/mach-malta/include/mach/debug_ll.h
> > +++ b/arch/mips/mach-malta/include/mach/debug_ll.h
> > @@ -23,6 +23,6 @@
> >  
> >  #include <mach/hardware.h>
> >  
> > -#include <debug_ll_ns16550.h>
> > +#include <asm/debug_ll_ns16550.h>
> >  
> >  #endif  /* __INCLUDE_ARCH_DEBUG_LL_H__ */
> > diff --git a/arch/mips/mach-xburst/include/mach/debug_ll.h b/arch/mips/mach-xburst/include/mach/debug_ll.h
> > index f260e65..6c3c980 100644
> > --- a/arch/mips/mach-xburst/include/mach/debug_ll.h
> > +++ b/arch/mips/mach-xburst/include/mach/debug_ll.h
> > @@ -22,6 +22,6 @@
> >   *  This File contains declaration for early output support
> >   */
> >  #include <board/debug_ll.h>
> > -#include <debug_ll_ns16550.h>
> > +#include <asm/debug_ll_ns16550.h>
> >  
> >  #endif  /* __MACH_XBURST_DEBUG_LL__ */
> > -- 
> > 1.7.10.4
> > 
> 
> 
> -- 
> --?
> Best regards,
> ? Antony Pavlov
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From monaka at monami-ya.jp  Sun Jun  2 08:59:05 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Sun,  2 Jun 2013 21:59:05 +0900
Subject: [PATCH] Remove a redundant line.
Message-ID: <1370177945-36985-1-git-send-email-monaka@monami-ya.com>

Signed-off-by: Masaki Muranaka <monaka at monami-ya.com>
---
 commands/echo.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/commands/echo.c b/commands/echo.c
index 8929234..4dfd870 100644
--- a/commands/echo.c
+++ b/commands/echo.c
@@ -55,7 +55,6 @@ static int do_echo(int argc, char *argv[])
 			break;
 		case 'o':
 			oflags |= O_TRUNC;
-			file = argv[optind + 1];
 			if (optind + 1 < argc)
 				file = argv[optind + 1];
 			else
-- 
1.8.3



From shc_work at mail.ru  Sun Jun  2 09:13:18 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Sun, 02 Jun 2013 17:13:18 +0400
Subject: =?UTF-8?B?UmU6IFtQQVRDSF0gUmVtb3ZlIGEgcmVkdW5kYW50IGxpbmUu?=
In-Reply-To: <1370177945-36985-1-git-send-email-monaka@monami-ya.com>
References: <1370177945-36985-1-git-send-email-monaka@monami-ya.com>
Message-ID: <1370178798.173110869@f56.mail.ru>

> Signed-off-by: Masaki Muranaka <monaka at monami-ya.com>
> ---
>  commands/echo.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/commands/echo.c b/commands/echo.c
> index 8929234..4dfd870 100644
> --- a/commands/echo.c
> +++ b/commands/echo.c
> @@ -55,7 +55,6 @@ static int do_echo(int argc, char *argv[])
>  			break;
>  		case 'o':
>  			oflags |= O_TRUNC;
> -			file = argv[optind + 1];
>  			if (optind + 1 < argc)
>  				file = argv[optind + 1];
>  			else
> -- 

Nice catch. This is a possible crash.

---

From monaka at monami-ya.jp  Sun Jun  2 09:14:09 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Sun,  2 Jun 2013 22:14:09 +0900
Subject: [PATCH] Remove ftstc(). It is declared but not implemented.
Message-ID: <1370178849-37125-1-git-send-email-monaka@monami-ya.com>

---
 include/stdio.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/stdio.h b/include/stdio.h
index 5c091a8..ff2572e 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -101,7 +101,6 @@ static inline void putchar(char c)
 int	fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
 int	fputs(int file, const char *s);
 int	fputc(int file, const char c);
-int	ftstc(int file);
 int	fgetc(int file);
 
 #endif /* __STDIO_H */
-- 
1.8.3



From monaka at monami-ya.jp  Sun Jun  2 09:59:19 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Sun,  2 Jun 2013 22:59:19 +0900
Subject: [PATCH] Provide and use dirent.h.
Message-ID: <1370181559-53032-1-git-send-email-monaka@monami-ya.com>

It is for compatibility with the POSIX standard.
---
 commands/ls.c          |  2 +-
 common/complete.c      |  2 +-
 common/hush.c          |  2 +-
 fs/ramfs.c             |  1 +
 include/dirent.h       | 25 +++++++++++++++++++++++++
 include/fs.h           | 16 +---------------
 lib/glob.c             |  2 +-
 lib/recursive_action.c |  2 +-
 8 files changed, 32 insertions(+), 20 deletions(-)
 create mode 100644 include/dirent.h

diff --git a/commands/ls.c b/commands/ls.c
index f2d9903..2b1b08b 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -19,7 +19,7 @@
 
 #include <common.h>
 #include <command.h>
-#include <fs.h>
+#include <dirent.h>
 #include <linux/stat.h>
 #include <errno.h>
 #include <malloc.h>
diff --git a/common/complete.c b/common/complete.c
index 9206ef0..1fdc320 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -17,7 +17,7 @@
 #include <common.h>
 #include <complete.h>
 #include <xfuncs.h>
-#include <fs.h>
+#include <dirent.h>
 #include <linux/stat.h>
 #include <libgen.h>
 #include <command.h>
diff --git a/common/hush.c b/common/hush.c
index b5e111a..64c0b06 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -114,7 +114,7 @@
 #include <command.h>        /* find_cmd */
 #include <driver.h>
 #include <errno.h>
-#include <fs.h>
+#include <dirent.h>
 #include <libbb.h>
 #include <glob.h>
 #include <getopt.h>
diff --git a/fs/ramfs.c b/fs/ramfs.c
index f45a454..3f9df7c 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -21,6 +21,7 @@
 #include <driver.h>
 #include <init.h>
 #include <malloc.h>
+#include <dirent.h>
 #include <fs.h>
 #include <command.h>
 #include <errno.h>
diff --git a/include/dirent.h b/include/dirent.h
new file mode 100644
index 0000000..2faee78
--- /dev/null
+++ b/include/dirent.h
@@ -0,0 +1,25 @@
+#ifndef BAREBOX_DIRENT_H__
+#define BAREBOX_DIRENT_H__
+
+struct device_d;
+struct fs_driver_d;
+struct node_d;
+
+struct dirent {
+	char d_name[256];
+};
+
+typedef struct dir {
+	struct device_d *dev;
+	struct fs_driver_d *fsdrv;
+	struct node_d *node;
+	struct dirent d;
+	void *priv; /* private data for the fs driver */
+} DIR;
+
+DIR *opendir(const char *pathname);
+struct dirent *readdir(DIR *dir);
+int closedir(DIR *dir);
+
+
+#endif /* BAREBOX_DIRENT_H__ */
diff --git a/include/fs.h b/include/fs.h
index 7c4e461..0984da1 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -10,17 +10,7 @@ struct partition;
 struct node_d;
 struct stat;
 
-struct dirent {
-	char d_name[256];
-};
-
-typedef struct dir {
-	struct device_d *dev;
-	struct fs_driver_d *fsdrv;
-	struct node_d *node;
-	struct dirent d;
-	void *priv; /* private data for the fs driver */
-} DIR;
+#include <dirent.h>
 
 typedef struct filep {
 	struct device_d *dev; /* The device this FILE belongs to              */
@@ -133,10 +123,6 @@ int rmdir (const char *pathname);
 const char *getcwd(void);
 int chdir(const char *pathname);
 
-DIR *opendir(const char *pathname);
-struct dirent *readdir(DIR *dir);
-int closedir(DIR *dir);
-
 int symlink(const char *pathname, const char *newpath);
 int readlink(const char *path, char *buf, size_t bufsiz);
 
diff --git a/lib/glob.c b/lib/glob.c
index 1b0137b..7a522a9 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -17,7 +17,7 @@ Cambridge, MA 02139, USA.  */
 
 #include <common.h>
 #include <errno.h>
-#include <fs.h>
+#include <dirent.h>
 #include <linux/stat.h>
 #include <malloc.h>
 #include <xfuncs.h>
diff --git a/lib/recursive_action.c b/lib/recursive_action.c
index 345d3db..06e60b8 100644
--- a/lib/recursive_action.c
+++ b/lib/recursive_action.c
@@ -9,7 +9,7 @@
 #ifdef __BAREBOX__
 
 #include <common.h>
-#include <fs.h>
+#include <dirent.h>
 #include <linux/stat.h>
 #include <malloc.h>
 #include <libbb.h>
-- 
1.8.3



From monaka at monami-ya.jp  Sun Jun  2 10:53:47 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Sun,  2 Jun 2013 23:53:47 +0900
Subject: [PATCH 1/3] Remove unnesessory malloc.h inclusions.
Message-ID: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>

---
 commands/barebox-update.c | 1 -
 commands/bootm.c          | 1 -
 commands/cat.c            | 1 -
 commands/cp.c             | 1 -
 commands/crc.c            | 1 -
 commands/dfu.c            | 1 -
 commands/edit.c           | 1 -
 commands/exec.c           | 1 -
 commands/global.c         | 1 -
 commands/i2c.c            | 1 -
 commands/insmod.c         | 1 -
 commands/let.c            | 1 -
 commands/linux16.c        | 1 -
 commands/loadxy.c         | 1 -
 commands/ls.c             | 1 -
 commands/md.c             | 1 -
 commands/memcmp.c         | 1 -
 commands/memcpy.c         | 1 -
 commands/meminfo.c        | 1 -
 commands/memset.c         | 1 -
 commands/miitool.c        | 1 -
 commands/mm.c             | 1 -
 commands/mw.c             | 1 -
 commands/nand.c           | 1 -
 commands/nandtest.c       | 1 -
 commands/of_node.c        | 1 -
 commands/oftree.c         | 1 -
 commands/partition.c      | 1 -
 commands/readline.c       | 1 -
 commands/readlink.c       | 1 -
 commands/spi.c            | 1 -
 commands/splash.c         | 1 -
 commands/time.c           | 1 -
 commands/ubiformat.c      | 1 -
 commands/uimage.c         | 1 -
 commands/usbserial.c      | 1 -
 common/binfmt.c           | 1 -
 common/block.c            | 1 -
 common/bootargs.c         | 1 -
 common/console.c          | 1 -
 common/filetype.c         | 1 -
 common/globalvar.c        | 1 -
 common/image.c            | 1 -
 common/menu.c             | 1 -
 common/module.c           | 2 --
 common/oftree.c           | 1 -
 common/partitions.c       | 1 -
 common/resource.c         | 1 -
 48 files changed, 49 deletions(-)

diff --git a/commands/barebox-update.c b/commands/barebox-update.c
index f550572..bb6e108 100644
--- a/commands/barebox-update.c
+++ b/commands/barebox-update.c
@@ -18,7 +18,6 @@
 #include <common.h>
 #include <command.h>
 #include <getopt.h>
-#include <malloc.h>
 #include <errno.h>
 #include <bbu.h>
 #include <fs.h>
diff --git a/commands/bootm.c b/commands/bootm.c
index 5dd1703..d2602b0 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -24,7 +24,6 @@
 #include <driver.h>
 #include <command.h>
 #include <image.h>
-#include <malloc.h>
 #include <environment.h>
 #include <asm/byteorder.h>
 #include <xfuncs.h>
diff --git a/commands/cat.c b/commands/cat.c
index 1c112fc..476e1bb 100644
--- a/commands/cat.c
+++ b/commands/cat.c
@@ -27,7 +27,6 @@
 #include <linux/ctype.h>
 #include <errno.h>
 #include <xfuncs.h>
-#include <malloc.h>
 
 #define BUFSIZE 1024
 
diff --git a/commands/cp.c b/commands/cp.c
index 45f08d8..03369d9 100644
--- a/commands/cp.c
+++ b/commands/cp.c
@@ -27,7 +27,6 @@
 #include <linux/stat.h>
 #include <libbb.h>
 #include <fs.h>
-#include <malloc.h>
 #include <libgen.h>
 #include <getopt.h>
 
diff --git a/commands/crc.c b/commands/crc.c
index a0071b0..78b3eca 100644
--- a/commands/crc.c
+++ b/commands/crc.c
@@ -24,7 +24,6 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <xfuncs.h>
-#include <malloc.h>
 #include <linux/ctype.h>
 
 static int file_crc(char* filename, ulong start, ulong size, ulong *crc,
diff --git a/commands/dfu.c b/commands/dfu.c
index af6573a..b1e54b9 100644
--- a/commands/dfu.c
+++ b/commands/dfu.c
@@ -19,7 +19,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <fs.h>
 #include <xfuncs.h>
diff --git a/commands/edit.c b/commands/edit.c
index 295d0a7..8c72521 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -22,7 +22,6 @@
 
 #include <common.h>
 #include <command.h>
-#include <malloc.h>
 #include <fs.h>
 #include <linux/ctype.h>
 #include <fcntl.h>
diff --git a/commands/exec.c b/commands/exec.c
index bd7d54a..af08f2a 100644
--- a/commands/exec.c
+++ b/commands/exec.c
@@ -23,7 +23,6 @@
 #include <fcntl.h>
 #include <linux/stat.h>
 #include <errno.h>
-#include <malloc.h>
 #include <xfuncs.h>
 
 static int do_exec(int argc, char *argv[])
diff --git a/commands/global.c b/commands/global.c
index 427a231..e3e7a58 100644
--- a/commands/global.c
+++ b/commands/global.c
@@ -17,7 +17,6 @@
  *
  */
 #include <common.h>
-#include <malloc.h>
 #include <command.h>
 #include <globalvar.h>
 #include <environment.h>
diff --git a/commands/i2c.c b/commands/i2c.c
index 626255d..f3ec556 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -18,7 +18,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <i2c/i2c.h>
 
diff --git a/commands/insmod.c b/commands/insmod.c
index f547e9d..3a0dfbc 100644
--- a/commands/insmod.c
+++ b/commands/insmod.c
@@ -3,7 +3,6 @@
 #include <module.h>
 #include <errno.h>
 #include <fs.h>
-#include <malloc.h>
 
 static int do_insmod(int argc, char *argv[])
 {
diff --git a/commands/let.c b/commands/let.c
index 644ede5..cae6c97 100644
--- a/commands/let.c
+++ b/commands/let.c
@@ -20,7 +20,6 @@
 #include <environment.h>
 #include <errno.h>
 #include <init.h>
-#include <malloc.h>
 #include <xfuncs.h>
 #include <math.h>
 
diff --git a/commands/linux16.c b/commands/linux16.c
index 30fa2de..3ce49dc 100644
--- a/commands/linux16.c
+++ b/commands/linux16.c
@@ -25,7 +25,6 @@
 #include <fs.h>
 #include <errno.h>
 #include <getopt.h>
-#include <malloc.h>
 #include <boot.h>
 #include <asm/syslib.h>
 
diff --git a/commands/loadxy.c b/commands/loadxy.c
index 52ecdca..1059512 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -36,7 +36,6 @@
 #include <getopt.h>
 #include <fcntl.h>
 #include <fs.h>
-#include <malloc.h>
 
 #define DEF_FILE	"image.bin"
 
diff --git a/commands/ls.c b/commands/ls.c
index f2d9903..9aa8d41 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -22,7 +22,6 @@
 #include <fs.h>
 #include <linux/stat.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <stringlist.h>
 
diff --git a/commands/md.c b/commands/md.c
index 03c5905..46d17a5 100644
--- a/commands/md.c
+++ b/commands/md.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/memcmp.c b/commands/memcmp.c
index 4a03862..ddb5dbf 100644
--- a/commands/memcmp.c
+++ b/commands/memcmp.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/memcpy.c b/commands/memcpy.c
index 98f099f..939451e 100644
--- a/commands/memcpy.c
+++ b/commands/memcpy.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/meminfo.c b/commands/meminfo.c
index 6e1e8c3..7b2019c 100644
--- a/commands/meminfo.c
+++ b/commands/meminfo.c
@@ -19,7 +19,6 @@
 #include <common.h>
 #include <command.h>
 #include <complete.h>
-#include <malloc.h>
 
 static int do_meminfo(int argc, char *argv[])
 {
diff --git a/commands/memset.c b/commands/memset.c
index 48e55bc..57bce5f 100644
--- a/commands/memset.c
+++ b/commands/memset.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/miitool.c b/commands/miitool.c
index 3a9ac45..495a285 100644
--- a/commands/miitool.c
+++ b/commands/miitool.c
@@ -29,7 +29,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/mm.c b/commands/mm.c
index f51fd27..442f804 100644
--- a/commands/mm.c
+++ b/commands/mm.c
@@ -19,7 +19,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/mw.c b/commands/mw.c
index d7d73a8..01d08ff 100644
--- a/commands/mw.c
+++ b/commands/mw.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/nand.c b/commands/nand.c
index 39fb64e..62b7405 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -19,7 +19,6 @@
 #include <fs.h>
 #include <linux/stat.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <xfuncs.h>
 #include <init.h>
diff --git a/commands/nandtest.c b/commands/nandtest.c
index ba15ecf..9f7cbff 100644
--- a/commands/nandtest.c
+++ b/commands/nandtest.c
@@ -15,7 +15,6 @@
 #include <command.h>
 #include <fs.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <ioctl.h>
 #include <linux/mtd/mtd-abi.h>
diff --git a/commands/of_node.c b/commands/of_node.c
index 0249d97..d9803e6 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -23,7 +23,6 @@
 #include <of.h>
 #include <command.h>
 #include <fs.h>
-#include <malloc.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
diff --git a/commands/oftree.c b/commands/oftree.c
index 468235a..f0f502a 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -29,7 +29,6 @@
 #include <of.h>
 #include <command.h>
 #include <fs.h>
-#include <malloc.h>
 #include <linux/ctype.h>
 #include <linux/err.h>
 #include <asm/byteorder.h>
diff --git a/commands/partition.c b/commands/partition.c
index fdd6041..01ce941 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -31,7 +31,6 @@
 #include <command.h>
 #include <complete.h>
 #include <driver.h>
-#include <malloc.h>
 #include <partition.h>
 #include <errno.h>
 #include <xfuncs.h>
diff --git a/commands/readline.c b/commands/readline.c
index 60670fa..7d13ab2 100644
--- a/commands/readline.c
+++ b/commands/readline.c
@@ -19,7 +19,6 @@
 
 #include <common.h>
 #include <command.h>
-#include <malloc.h>
 #include <xfuncs.h>
 #include <environment.h>
 
diff --git a/commands/readlink.c b/commands/readlink.c
index d2671e0..8f16b31 100644
--- a/commands/readlink.c
+++ b/commands/readlink.c
@@ -25,7 +25,6 @@
 #include <libgen.h>
 #include <environment.h>
 #include <fs.h>
-#include <malloc.h>
 #include <getopt.h>
 
 static int do_readlink(int argc, char *argv[])
diff --git a/commands/spi.c b/commands/spi.c
index 2f6b430..c0da77b 100644
--- a/commands/spi.c
+++ b/commands/spi.c
@@ -8,7 +8,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <spi/spi.h>
 
diff --git a/commands/splash.c b/commands/splash.c
index 0955c01..d69c7b5 100644
--- a/commands/splash.c
+++ b/commands/splash.c
@@ -1,7 +1,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <fb.h>
 #include <gui/image_renderer.h>
diff --git a/commands/time.c b/commands/time.c
index 987c25e..b40bd59 100644
--- a/commands/time.c
+++ b/commands/time.c
@@ -2,7 +2,6 @@
 #include <command.h>
 #include <clock.h>
 #include <asm-generic/div64.h>
-#include <malloc.h>
 
 static int do_time(int argc, char *argv[])
 {
diff --git a/commands/ubiformat.c b/commands/ubiformat.c
index 121816f..d508119 100644
--- a/commands/ubiformat.c
+++ b/commands/ubiformat.c
@@ -37,7 +37,6 @@
 #include <crc.h>
 #include <stdlib.h>
 #include <clock.h>
-#include <malloc.h>
 #include <ioctl.h>
 #include <libbb.h>
 #include <linux/mtd/mtd.h>
diff --git a/commands/uimage.c b/commands/uimage.c
index 345e496..415347c 100644
--- a/commands/uimage.c
+++ b/commands/uimage.c
@@ -4,7 +4,6 @@
 #include <libbb.h>
 #include <fcntl.h>
 #include <fs.h>
-#include <malloc.h>
 #include <errno.h>
 #include <getopt.h>
 
diff --git a/commands/usbserial.c b/commands/usbserial.c
index a884a28..041d7f2 100644
--- a/commands/usbserial.c
+++ b/commands/usbserial.c
@@ -21,7 +21,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <fs.h>
 #include <xfuncs.h>
diff --git a/common/binfmt.c b/common/binfmt.c
index 7dcf5d7..5073549 100644
--- a/common/binfmt.c
+++ b/common/binfmt.c
@@ -7,7 +7,6 @@
 #include <common.h>
 #include <binfmt.h>
 #include <libbb.h>
-#include <malloc.h>
 #include <command.h>
 #include <errno.h>
 
diff --git a/common/block.c b/common/block.c
index 120d659..9855f8f 100644
--- a/common/block.c
+++ b/common/block.c
@@ -18,7 +18,6 @@
  */
 #include <common.h>
 #include <block.h>
-#include <malloc.h>
 #include <linux/err.h>
 #include <linux/list.h>
 #include <dma.h>
diff --git a/common/bootargs.c b/common/bootargs.c
index 6624f72..660f5f5 100644
--- a/common/bootargs.c
+++ b/common/bootargs.c
@@ -18,7 +18,6 @@
  */
 #include <common.h>
 #include <boot.h>
-#include <malloc.h>
 #include <magicvar.h>
 #include <globalvar.h>
 #include <environment.h>
diff --git a/common/console.c b/common/console.c
index a0a06f6..86aecbe 100644
--- a/common/console.c
+++ b/common/console.c
@@ -20,7 +20,6 @@
 #include <config.h>
 #include <common.h>
 #include <stdarg.h>
-#include <malloc.h>
 #include <param.h>
 #include <console.h>
 #include <driver.h>
diff --git a/common/filetype.c b/common/filetype.c
index 1ff3dd2..78f23fc 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -21,7 +21,6 @@
 #include <asm/unaligned.h>
 #include <fcntl.h>
 #include <fs.h>
-#include <malloc.h>
 #include <errno.h>
 
 struct filetype_str {
diff --git a/common/globalvar.c b/common/globalvar.c
index a8aaa72..ebf6be3 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -1,5 +1,4 @@
 #include <common.h>
-#include <malloc.h>
 #include <globalvar.h>
 #include <init.h>
 
diff --git a/common/image.c b/common/image.c
index 9252d5e..ceb216f 100644
--- a/common/image.c
+++ b/common/image.c
@@ -25,7 +25,6 @@
 #include <rtc.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <malloc.h>
 #include <fs.h>
 #else
 #include <time.h>
diff --git a/common/menu.c b/common/menu.c
index a672e59..cb7f684 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -21,7 +21,6 @@
 #include <environment.h>
 #include <init.h>
 #include <menu.h>
-#include <malloc.h>
 #include <xfuncs.h>
 #include <errno.h>
 #include <readkey.h>
diff --git a/common/module.c b/common/module.c
index 109fe5c..50f3a7d 100644
--- a/common/module.c
+++ b/common/module.c
@@ -18,8 +18,6 @@
 #include <errno.h>
 #include <module.h>
 #include <elf.h>
-#include <malloc.h>
-#include <xfuncs.h>
 #include <command.h>
 #include <fs.h>
 #include <kallsyms.h>
diff --git a/common/oftree.c b/common/oftree.c
index 776d301..ae62262 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -4,7 +4,6 @@
 #include <of.h>
 #include <command.h>
 #include <fs.h>
-#include <malloc.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
diff --git a/common/partitions.c b/common/partitions.c
index 683b258..eee3210 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -22,7 +22,6 @@
  * @todo Reliable size detection for BIOS based disks (on x86 only)
  */
 #include <common.h>
-#include <malloc.h>
 #include <errno.h>
 #include <block.h>
 #include <asm/unaligned.h>
diff --git a/common/resource.c b/common/resource.c
index 5795e79..954357e 100644
--- a/common/resource.c
+++ b/common/resource.c
@@ -16,7 +16,6 @@
  * GNU General Public License for more details.
  */
 #include <common.h>
-#include <malloc.h>
 #include <errno.h>
 #include <init.h>
 #include <linux/ioport.h>
-- 
1.8.3



From monaka at monami-ya.jp  Sun Jun  2 10:53:48 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Sun,  2 Jun 2013 23:53:48 +0900
Subject: [PATCH 2/3] Refactor malloc.h.
In-Reply-To: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>
References: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>
Message-ID: <1370184829-66576-2-git-send-email-monaka@monami-ya.com>

 Some functions should be defined in stdlib.h or unistd.h.
---
 include/malloc.h       |  8 +++-----
 include/malloc_isoc.h  | 11 +++++++++++
 include/malloc_posix.h |  8 ++++++++
 include/stdlib.h       |  1 +
 include/unistd.h       |  6 ++++++
 5 files changed, 29 insertions(+), 5 deletions(-)
 create mode 100644 include/malloc_isoc.h
 create mode 100644 include/malloc_posix.h
 create mode 100644 include/unistd.h

diff --git a/include/malloc.h b/include/malloc.h
index 7b9b062..9554597 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,20 +5,18 @@
 
 /* Public routines */
 
-void* malloc(size_t);
-void free(void*);
-void* realloc(void*, size_t);
+#include <malloc_isoc.h>
+#include <malloc_posix.h>
+
 void* memalign(size_t, size_t);
 void* vallocc(size_t);
 void* pvalloc(size_t);
-void* calloc(size_t, size_t);
 void cfree(void*);
 int malloc_trim(size_t);
 size_t malloc_usable_size(void*);
 void malloc_stats(void);
 int mallopt(int, int);
 struct mallinfo mallinfo(void);
-void *sbrk(ptrdiff_t increment);
 
 #endif
 
diff --git a/include/malloc_isoc.h b/include/malloc_isoc.h
new file mode 100644
index 0000000..728cdd9
--- /dev/null
+++ b/include/malloc_isoc.h
@@ -0,0 +1,11 @@
+#ifndef BAREBOX_MALLOC_ISOC_H__
+#define BAREBOX_MALLOC_ISOC_H__
+
+#include <types.h>
+
+void* malloc(size_t);
+void free(void*);
+void* realloc(void*, size_t);
+void* calloc(size_t, size_t);
+
+#endif /* BAREBOX_MALLOC_ISOC_H__ */
diff --git a/include/malloc_posix.h b/include/malloc_posix.h
new file mode 100644
index 0000000..d10675d
--- /dev/null
+++ b/include/malloc_posix.h
@@ -0,0 +1,8 @@
+#ifndef BAREBOX_MALLOC_POSIX_H__
+#define BAREBOX_MALLOC_POSIX_H__
+
+#include <types.h>
+
+void *sbrk(ptrdiff_t increment);
+
+#endif /* BAREBOX_MALLOC_POSIX_H__ */
diff --git a/include/stdlib.h b/include/stdlib.h
index dc72013..0d82bbf 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -12,5 +12,6 @@ void srand(unsigned int seed);
 /* fill a buffer with pseudo-random data */
 void get_random_bytes(char *buf, int len);
 
+#include <malloc_isoc.h>
 
 #endif /* __STDLIB_H */
diff --git a/include/unistd.h b/include/unistd.h
new file mode 100644
index 0000000..a6abfa6
--- /dev/null
+++ b/include/unistd.h
@@ -0,0 +1,6 @@
+#ifndef BAREBOX_UNISTD_H__
+#define BAREBOX_UNISTD_H__
+
+#include <malloc_posix.h>
+
+#endif /* BAREBOX_UNISTD_H__ */
-- 
1.8.3



From monaka at monami-ya.jp  Sun Jun  2 10:53:49 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Sun,  2 Jun 2013 23:53:49 +0900
Subject: [PATCH 3/3] Use stdlib.h instead of malloc.h
In-Reply-To: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>
References: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>
Message-ID: <1370184829-66576-3-git-send-email-monaka@monami-ya.com>

---
 commands/digest.c      | 2 +-
 commands/loadb.c       | 2 +-
 commands/mem.c         | 2 +-
 commands/of_property.c | 2 +-
 common/command.c       | 2 +-
 common/digest.c        | 2 +-
 common/env.c           | 2 +-
 common/environment.c   | 2 +-
 common/hush.c          | 2 +-
 common/password.c      | 3 +--
 common/startup.c       | 2 +-
 common/uimage.c        | 2 +-
 12 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/commands/digest.c b/commands/digest.c
index c9bb132..6470a2e 100644
--- a/commands/digest.c
+++ b/commands/digest.c
@@ -23,7 +23,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <xfuncs.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <digest.h>
 
 static int do_digest(char *algorithm, int argc, char *argv[])
diff --git a/commands/loadb.c b/commands/loadb.c
index a2f3315..d7895c9 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -38,7 +38,7 @@
 #include <getopt.h>
 #include <fs.h>
 #include <fcntl.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 #define XON_CHAR	17
 #define XOFF_CHAR	19
diff --git a/commands/mem.c b/commands/mem.c
index 568050d..1caa92c 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -25,7 +25,7 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/of_property.c b/commands/of_property.c
index 44bb388..1919b3d 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -23,7 +23,7 @@
 #include <of.h>
 #include <command.h>
 #include <fs.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
diff --git a/common/command.c b/common/command.c
index 7f2b777..b3804b8 100644
--- a/common/command.c
+++ b/common/command.c
@@ -24,7 +24,7 @@
 #include <common.h>
 #include <command.h>
 #include <xfuncs.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <environment.h>
 #include <linux/list.h>
 #include <init.h>
diff --git a/common/digest.c b/common/digest.c
index ae414ba..80e8502 100644
--- a/common/digest.c
+++ b/common/digest.c
@@ -18,7 +18,7 @@
 
 #include <common.h>
 #include <digest.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <fs.h>
 #include <fcntl.h>
 #include <linux/stat.h>
diff --git a/common/env.c b/common/env.c
index 33a871f..e8a57f4 100644
--- a/common/env.c
+++ b/common/env.c
@@ -24,7 +24,7 @@
 
 #include <common.h>
 #include <driver.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <xfuncs.h>
 #include <errno.h>
 #include <init.h>
diff --git a/common/environment.c b/common/environment.c
index 78cd45c..c0bd629 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -27,7 +27,7 @@
 #ifdef __BAREBOX__
 #include <common.h>
 #include <command.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/common/hush.c b/common/hush.c
index b5e111a..65a4ec0 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -106,7 +106,7 @@
  * General Public License for more details.
  *
  */
-#include <malloc.h>         /* malloc, free, realloc*/
+#include <stdlib.h>         /* malloc, free, realloc*/
 #include <xfuncs.h>
 #include <linux/ctype.h>    /* isalpha, isdigit */
 #include <common.h>        /* readline */
diff --git a/common/password.c b/common/password.c
index d157a11..830f724 100644
--- a/common/password.c
+++ b/common/password.c
@@ -22,8 +22,7 @@
 #include <fs.h>
 #include <fcntl.h>
 #include <digest.h>
-#include <malloc.h>
-#include <xfuncs.h>
+#include <stdlib.h>
 #include <clock.h>
 
 #if defined(CONFIG_PASSWD_SUM_MD5)
diff --git a/common/startup.c b/common/startup.c
index ff00ca7..d709089 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -28,7 +28,7 @@
 #include <common.h>
 #include <init.h>
 #include <command.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <debug_ll.h>
 #include <fs.h>
 #include <linux/stat.h>
diff --git a/common/uimage.c b/common/uimage.c
index 06f97f0..c9ae311 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -19,7 +19,7 @@
  */
 #include <common.h>
 #include <image.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <libbb.h>
 #include <uncompress.h>
-- 
1.8.3



From monaka at monami-ya.jp  Sun Jun  2 11:01:00 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Mon, 3 Jun 2013 00:01:00 +0900
Subject: [PATCH] Use FILE structure for stdin/stdout/stderr.
In-Reply-To: <1370102204-74399-1-git-send-email-monaka@monami-ya.com>
References: <1370102204-74399-1-git-send-email-monaka@monami-ya.com>
Message-ID: <CAJBvFxOLE6=LnV2aeYJSev3aiimaf9U8Wms7SLFsc-Y_j7SbBQ@mail.gmail.com>

Hello,

This patch has side effects to echo.c.
Please reject it for now. I'm working in progress. I'll re-send soon.

2013/6/2  <monaka at monami-ya.jp>:
> From: Masaki Muranaka <monaka at monami-ya.com>
>
> Signed-off-by: Masaki Muranaka <monaka at monami-ya.com>
> ---
>  common/console.c        |  6 +++---
>  common/console_common.c | 19 +++++++++----------
>  include/filetype.h      |  2 ++
>  include/stdio.h         | 17 +++++++++--------
>  4 files changed, 23 insertions(+), 21 deletions(-)
>
> diff --git a/common/console.c b/common/console.c
> index a0a06f6..7a8ac4f 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -246,13 +246,13 @@ int getc(void)
>  }
>  EXPORT_SYMBOL(getc);
>
> -int fgetc(int fd)
> +int fgetc(FILE *file)
>  {
>         char c;
>
> -       if (!fd)
> +       if (file == stdin)
>                 return getc();
> -       return read(fd, &c, 1);
> +       return read(file->no, &c, 1);
>  }
>  EXPORT_SYMBOL(fgetc);
>
> diff --git a/common/console_common.c b/common/console_common.c
> index d139d1a..34713f9 100644
> --- a/common/console_common.c
> +++ b/common/console_common.c
> @@ -66,7 +66,7 @@ EXPORT_SYMBOL(vprintf);
>
>  #endif /* !CONFIG_CONSOLE_NONE */
>
> -int fprintf(int file, const char *fmt, ...)
> +int fprintf(FILE *file, const char *fmt, ...)
>  {
>         va_list args;
>         char printbuffer[CFG_PBSIZE];
> @@ -85,26 +85,25 @@ int fprintf(int file, const char *fmt, ...)
>  }
>  EXPORT_SYMBOL(fprintf);
>
> -int fputs(int fd, const char *s)
> +int fputs(FILE *file, const char *s)
>  {
> -       if (fd == 1)
> +       if (file == stdout)
>                 return puts(s);
> -       else if (fd == 2)
> +       else if (file == stderr)
>                 return eputs(s);
>         else
> -               return write(fd, s, strlen(s));
> +               return write(file->no, s, strlen(s));
>  }
>  EXPORT_SYMBOL(fputs);
>
> -int fputc(int fd, char c)
> +int fputc(FILE *file, char c)
>  {
> -       if (fd == 1)
> +       if (file == stdout)
>                 putchar(c);
> -       else if (fd == 2)
> +       else if (file == stderr)
>                 eputc(c);
>         else
> -               return write(fd, &c, 1);
> -
> +               return write(file->no, &c, 1);
>         return 0;
>  }
>  EXPORT_SYMBOL(fputc);
> diff --git a/include/filetype.h b/include/filetype.h
> index ee777ac..c73c64a 100644
> --- a/include/filetype.h
> +++ b/include/filetype.h
> @@ -1,6 +1,8 @@
>  #ifndef __FILE_TYPE_H
>  #define __FILE_TYPE_H
>
> +#include <linux/string.h>
> +
>  /*
>   * List of file types we know
>   */
> diff --git a/include/stdio.h b/include/stdio.h
> index 5c091a8..00d1ed7 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -3,6 +3,7 @@
>
>  #include <stdarg.h>
>  #include <console.h>
> +#include <fs.h>
>
>  /*
>   * STDIO based functions (can always be used)
> @@ -93,15 +94,15 @@ static inline void putchar(char c)
>   * FILE based functions
>   */
>
> -#define stdin          0
> -#define stdout         1
> -#define stderr         2
> +#define stdin          ((FILE *)0x10)
> +#define stdout         ((FILE *)0x11)
> +#define stderr         ((FILE *)0x12)
>  #define MAX_FILES      128
>
> -int    fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
> -int    fputs(int file, const char *s);
> -int    fputc(int file, const char c);
> -int    ftstc(int file);
> -int    fgetc(int file);
> +int    fprintf(FILE *file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
> +int    fputs(FILE *file, const char *s);
> +int    fputc(FILE *file, const char c);
> +int    ftstc(FILE *file);
> +int    fgetc(FILE *file);
>
>  #endif /* __STDIO_H */
> --
> 1.8.3
>



-- 
--
Masaki Muranaka
Monami-ya LLC, Japan.


From s.hauer at pengutronix.de  Sun Jun  2 11:44:44 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 2 Jun 2013 17:44:44 +0200
Subject: [PATCH 7/8] ppc 8xxx: core DDR driver functions
In-Reply-To: <1370019244-7873-8-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
 <1370019244-7873-8-git-send-email-renaud.barbier@ge.com>
Message-ID: <20130602154444.GU32299@pengutronix.de>

On Fri, May 31, 2013 at 05:54:03PM +0100, Renaud Barbier wrote:
> This file is imported from U-Boot as is.
> 
> This code provides the 8xxx memory controller core driver interface.
> 
> Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
> ---
>  arch/ppc/ddr-8xxx/main.c |  667 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 667 insertions(+), 0 deletions(-)
>  create mode 100644 arch/ppc/ddr-8xxx/main.c
> 

[...]

> +
> +/*
> + * fsl_ddr_sdram() -- this is the main function to be called by
> + *	initdram() in the board file.
> + *
> + * It returns amount of memory configured in bytes.
> + */
> +phys_size_t fsl_ddr_sdram(void)
> +{

THe behaviour of this function is defined by:

CONFIG_BUFFER_SIZE
CONFIG_CHIP_SELECT_QUAD_CAPABLE
CONFIG_CHIP_SELECTS_PER_CTRL
CONFIG_DDR_ECC
CONFIG_DDR_SPD
CONFIG_DIMM_SLOTS_PER_CTLR
CONFIG_E500MC
CONFIG_E6500
CONFIG_ECC_INIT_VIA_DDRCONTROLLER
CONFIG_FSL_DDR1
CONFIG_FSL_DDR2
CONFIG_FSL_DDR3
CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
CONFIG_FSL_DDR_INTERACTIVE
CONFIG_FSL_SDRAM_TYPE
CONFIG_HWCONFIG
CONFIG_MAX_MEM_MAPPED
CONFIG_MEM_INIT_VALUE
CONFIG_NUM_DDR_CONTROLLERS
CONFIG_PHYS_64BIT
CONFIG_SPD_EEPROM
CONFIG_SYS_DDR_RAW_TIMING
CONFIG_SYS_DIMM_SLOTS_PER_CTLR
CONFIG_SYS_FSL_DDR_VER
CONFIG_SYS_IMMR
CONFIG_SYS_MPC8xxx_DDR2_ADDR
CONFIG_SYS_MPC8xxx_DDR3_ADDR
CONFIG_SYS_MPC8xxx_DDR_ADDR
CONFIG_SYS_NUM_DDR_CTLRS

Some of these a board specific, others are SoC specific, but all are
input parameters to this function. The prototype should really be:

phys_size_t mpc8xxx_setup_ddr(struct mpc8xxx_ddr_params *)

(or maybe mpc8xxx_setup_ddr1/2/3 to be able to let the linker throw away
some unused code)

Code written in CPP rather than C was one of the major reasons why I
originally wrote barebox, so please let's not reintroduce this.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From shc_work at mail.ru  Sun Jun  2 11:47:24 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Sun, 02 Jun 2013 19:47:24 +0400
Subject: =?UTF-8?B?UmU6IFtQQVRDSF0gUmVtb3ZlIGZ0c3RjKCkuIEl0IGlzIGRlY2xhcmVkIGJ1?=
 =?UTF-8?B?dCBub3QgaW1wbGVtZW50ZWQu?=
In-Reply-To: <1370178849-37125-1-git-send-email-monaka@monami-ya.com>
References: <1370178849-37125-1-git-send-email-monaka@monami-ya.com>
Message-ID: <1370188044.845875578@f297.mail.ru>

> ---
>  include/stdio.h | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/include/stdio.h b/include/stdio.h
> index 5c091a8..ff2572e 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -101,7 +101,6 @@ static inline void putchar(char c)
>  int	fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
>  int	fputs(int file, const char *s);
>  int	fputc(int file, const char c);
> -int	ftstc(int file);
>  int	fgetc(int file);
>  
>  #endif /* __STDIO_H */
> -- 

Here (and in some other pathes) is missing Signed-off-by line.
Additionally, I want to focus on the fact that the address of From and Signed-off-by differ.
Git documentation says not to have been used aliases.
So, I think this field should be equal in the future.

---

From chf.fritz at googlemail.com  Sun Jun  2 17:07:02 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Sun, 02 Jun 2013 23:07:02 +0200
Subject: [PATCH v2] omap4-fb: add driver
In-Reply-To: <1365706897.4136.24.camel@mars>
References: <1365057762.3836.18.camel@mars>
 <20130405085917.GK1906@pengutronix.de> <1365372959.20809.6.camel@lovely>
 <20130408071715.GS1568@game.jcrosoft.org>
 <20130409071608.GD1906@pengutronix.de>
 <20130409132917.GX1568@game.jcrosoft.org>  <1365706897.4136.24.camel@mars>
Message-ID: <1370207222.5021.0.camel@lovely>

*ping*

On Thu, 2013-04-11 at 21:01 +0200, Christoph Fritz wrote:
> Hi Jean-Christophe
> 
> On Tue, 2013-04-09 at 15:29 +0200, Jean-Christophe PLAGNIOL-VILLARD
> wrote:
> > On 09:16 Tue 09 Apr     , Sascha Hauer wrote:
> > > On Mon, Apr 08, 2013 at 09:17:15AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > On 00:15 Mon 08 Apr     , Christoph Fritz wrote:
> > > > > This patch adds omap4 display controller support.
> > > > > 
> > > > > +
> > > > > +static inline void fb_write(uint32_t v, void __iomem *addr)
> > > > > +{
> > > > > +	__raw_writel(v, addr);
> > > > > +}
> > > > > +
> > > > > +static inline uint32_t fb_read(void const __iomem *addr)
> > > > > +{
> > > > > +	return __raw_readl(addr);
> > > > > +}
> > > > what is the dif?
> > > 
> > > Maybe Christoph understands what you mean here. I don't
> > those 2 inline as useless
> 
> You want me to purge the "inline" because gcc is smart enough to use
> inlining on its own?
> 
> Or are you noting that using a function here is overkill for only one
> call inside?
> 
> I use functions here because it makes debugging more easy and if you
> have a weird hardware config, here you can easily adapt the read and
> write functions.
> 
> > > > > +
> > > > > +	fbi->regs.dss   = dev_request_mem_region(dev, OMAP4_FB_RESOURCE_DSS);
> > > > > +	fbi->regs.dispc = dev_request_mem_region(dev, OMAP4_FB_RESOURCE_DISPC);
> > > > use named dev_request
> > > 
> > > We don't have such a function.
> > yes we do
> > 
> > dev_request_mem_region_by_name
> 
> Ok
> 
>  Thanks
>   -- Christoph
> 





From monaka at monami-ya.jp  Sun Jun  2 19:02:38 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Mon,  3 Jun 2013 08:02:38 +0900
Subject: [PATCH] Remove ftstc(). It is declared but not implemented.
Message-ID: <1370214158-67194-1-git-send-email-monaka@monami-ya.jp>

Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
---
 include/stdio.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/stdio.h b/include/stdio.h
index 5c091a8..ff2572e 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -101,7 +101,6 @@ static inline void putchar(char c)
 int	fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
 int	fputs(int file, const char *s);
 int	fputc(int file, const char c);
-int	ftstc(int file);
 int	fgetc(int file);
 
 #endif /* __STDIO_H */
-- 
1.8.3



From monaka at monami-ya.jp  Sun Jun  2 19:02:03 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Mon, 3 Jun 2013 08:02:03 +0900
Subject: [PATCH] Remove ftstc(). It is declared but not implemented.
In-Reply-To: <1370188044.845875578@f297.mail.ru>
References: <1370178849-37125-1-git-send-email-monaka@monami-ya.com>
 <1370188044.845875578@f297.mail.ru>
Message-ID: <CAJBvFxMPRRJNEJjeb5XNeEfatN5-XT56knNJioT=ycsN1PP6WQ@mail.gmail.com>

Hello,

It's easy to check by using whois service whether monami-ya.com and
monami-ya.jp are owned by same company...
Ok. I'll use monami-ya.jp in this project. I'm going to resend the patch.
Please inform me when I should fix my environment.

2013/6/3 Alexander Shiyan <shc_work at mail.ru>:
>> ---
>>  include/stdio.h | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/include/stdio.h b/include/stdio.h
>> index 5c091a8..ff2572e 100644
>> --- a/include/stdio.h
>> +++ b/include/stdio.h
>> @@ -101,7 +101,6 @@ static inline void putchar(char c)
>>  int  fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
>>  int  fputs(int file, const char *s);
>>  int  fputc(int file, const char c);
>> -int  ftstc(int file);
>>  int  fgetc(int file);
>>
>>  #endif /* __STDIO_H */
>> --
>
> Here (and in some other pathes) is missing Signed-off-by line.
> Additionally, I want to focus on the fact that the address of From and Signed-off-by differ.
> Git documentation says not to have been used aliases.
> So, I think this field should be equal in the future.
>
> ---



-- 
--
Masaki Muranaka
Monami-ya LLC, Japan.


From s.hauer at pengutronix.de  Mon Jun  3 03:16:26 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Jun 2013 09:16:26 +0200
Subject: [PATCH] Remove ftstc(). It is declared but not implemented.
In-Reply-To: <1370214158-67194-1-git-send-email-monaka@monami-ya.jp>
References: <1370214158-67194-1-git-send-email-monaka@monami-ya.jp>
Message-ID: <20130603071626.GV32299@pengutronix.de>

On Mon, Jun 03, 2013 at 08:02:38AM +0900, Masaki Muranaka wrote:
> Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>

Applied, thanks

Sascha

> ---
>  include/stdio.h | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/include/stdio.h b/include/stdio.h
> index 5c091a8..ff2572e 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -101,7 +101,6 @@ static inline void putchar(char c)
>  int	fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
>  int	fputs(int file, const char *s);
>  int	fputc(int file, const char c);
> -int	ftstc(int file);
>  int	fgetc(int file);
>  
>  #endif /* __STDIO_H */
> -- 
> 1.8.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun  3 03:24:27 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Jun 2013 09:24:27 +0200
Subject: [PATCH 1/3] Remove unnesessory malloc.h inclusions.
In-Reply-To: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>
References: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>
Message-ID: <20130603072427.GW32299@pengutronix.de>

On Sun, Jun 02, 2013 at 11:53:47PM +0900, Masaki Muranaka wrote:
> ---
> diff --git a/common/resource.c b/common/resource.c
> index 5795e79..954357e 100644
> --- a/common/resource.c
> +++ b/common/resource.c
> @@ -16,7 +16,6 @@
>   * GNU General Public License for more details.
>   */
>  #include <common.h>
> -#include <malloc.h>
>  #include <errno.h>
>  #include <init.h>
>  #include <linux/ioport.h>

Applying this patch leads to several compiler warnings:

common/resource.c: In function 'release_region':
common/resource.c:105:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/readline.c: In function 'do_readline':
commands/readline.c:33:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/time.c: In function 'do_time':
commands/time.c:41:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/oftree.c: In function 'do_oftree':
commands/oftree.c:197:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/readlink.c: In function 'do_readlink':
commands/readlink.c:58:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/global.c: In function 'globalvar_set':
commands/global.c:34:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]

So indeed we do not use malloc in these files, but we still use free.
I think you would have to replace the includes with #include <stdlib.h>
rather than removing them completely.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun  3 03:26:04 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Jun 2013 09:26:04 +0200
Subject: [PATCH 2/3] Refactor malloc.h.
In-Reply-To: <1370184829-66576-2-git-send-email-monaka@monami-ya.com>
References: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>
 <1370184829-66576-2-git-send-email-monaka@monami-ya.com>
Message-ID: <20130603072604.GX32299@pengutronix.de>

On Sun, Jun 02, 2013 at 11:53:48PM +0900, Masaki Muranaka wrote:
>  Some functions should be defined in stdlib.h or unistd.h.
> ---
>  include/malloc.h       |  8 +++-----
>  include/malloc_isoc.h  | 11 +++++++++++
>  include/malloc_posix.h |  8 ++++++++
>  include/stdlib.h       |  1 +
>  include/unistd.h       |  6 ++++++
>  5 files changed, 29 insertions(+), 5 deletions(-)
>  create mode 100644 include/malloc_isoc.h
>  create mode 100644 include/malloc_posix.h
>  create mode 100644 include/unistd.h
> 
> diff --git a/include/malloc.h b/include/malloc.h
> index 7b9b062..9554597 100644
> --- a/include/malloc.h
> +++ b/include/malloc.h
> @@ -5,20 +5,18 @@
>  
>  /* Public routines */
>  
> -void* malloc(size_t);
> -void free(void*);
> -void* realloc(void*, size_t);
> +#include <malloc_isoc.h>
> +#include <malloc_posix.h>
> +
>  void* memalign(size_t, size_t);
>  void* vallocc(size_t);
>  void* pvalloc(size_t);
> -void* calloc(size_t, size_t);
>  void cfree(void*);
>  int malloc_trim(size_t);
>  size_t malloc_usable_size(void*);
>  void malloc_stats(void);
>  int mallopt(int, int);
>  struct mallinfo mallinfo(void);
> -void *sbrk(ptrdiff_t increment);

Wouldn't it be nicer to move the prototypes to unistd.h / stdlib.h
instead of adding new files?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun  3 03:26:42 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Jun 2013 09:26:42 +0200
Subject: [PATCH] Remove a redundant line.
In-Reply-To: <1370177945-36985-1-git-send-email-monaka@monami-ya.com>
References: <1370177945-36985-1-git-send-email-monaka@monami-ya.com>
Message-ID: <20130603072642.GY32299@pengutronix.de>

On Sun, Jun 02, 2013 at 09:59:05PM +0900, Masaki Muranaka wrote:
> Signed-off-by: Masaki Muranaka <monaka at monami-ya.com>

Applied, thanks

Sascha

> ---
>  commands/echo.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/commands/echo.c b/commands/echo.c
> index 8929234..4dfd870 100644
> --- a/commands/echo.c
> +++ b/commands/echo.c
> @@ -55,7 +55,6 @@ static int do_echo(int argc, char *argv[])
>  			break;
>  		case 'o':
>  			oflags |= O_TRUNC;
> -			file = argv[optind + 1];
>  			if (optind + 1 < argc)
>  				file = argv[optind + 1];
>  			else
> -- 
> 1.8.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun  3 03:31:32 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Jun 2013 09:31:32 +0200
Subject: [PATCH 3/6] MIPS: rzx50: pbl: use debug_ll
In-Reply-To: <1370073169-29009-4-git-send-email-antonynpavlov@gmail.com>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
 <1370073169-29009-4-git-send-email-antonynpavlov@gmail.com>
Message-ID: <20130603073132.GB26150@pengutronix.de>

On Sat, Jun 01, 2013 at 11:52:46AM +0400, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> ---
>  arch/mips/boards/rzx50/include/board/board_pbl_start.h |    6 ++++++
>  arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h  |    4 ++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/arch/mips/boards/rzx50/include/board/board_pbl_start.h b/arch/mips/boards/rzx50/include/board/board_pbl_start.h
> index cba3e7f..f71641a 100644
> --- a/arch/mips/boards/rzx50/include/board/board_pbl_start.h
> +++ b/arch/mips/boards/rzx50/include/board/board_pbl_start.h
> @@ -18,6 +18,7 @@
>   */
>  
>  #include <asm/pbl_macros.h>
> +#include <mach/debug_ll.h>
>  
>  	.macro	board_pbl_start
>  	.set	push
> @@ -28,6 +29,11 @@
>  	/* CPU/SoC specific setup ... */
>  	/* ... absent */
>  
> +	debug_ll_ns16550_init
> +
> +	debug_ll_ns16550_outc '.'
> +	debug_ll_ns16550_outnl
> +
>  	copy_to_link_location	pbl_start

I had to drop this series beginning from this patch as it breaks
bisectibility. There seem to be some C stuff leaking in to the
assembler. I tried to fix this myself but I wasn't really sure what to
to. Could you update this based on current master?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun  3 03:33:13 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Jun 2013 09:33:13 +0200
Subject: v2013.06.0
Message-ID: <20130603073313.GZ32299@pengutronix.de>

Another month, another release. Here is v2013.06.0.

Sascha

----------------------------------------------------------------
Alexander Shiyan (22):
      Makefile: Create empty <config.h> if this header file is not needed by board
      Remove unused config.h
      ARM: cpuimx51: Use custom padctrl for fec
      ARM: i.MX: Update MX2x iomux definitions
      ARM: i.MX: Update MX51 iomux definitions
      Remove unimplemented usb_driver_unregister declaration
      GPIO: Rename "drivers/gpio.c" to "drivers/gpiolib.c"
      ARM: i.MX: Move GPIO driver to drivers/gpio
      ata: Remove wrong DISK_DRIVE symbol
      ARM: omap: Remove wrong OMAP_CLOCK_ALL symbol
      ARM: netx: Remove references for missing boards
      ARM: imx: Fix incorrect Kconfig symbols for some boards
      ARM: at91 gpio: Fix possible null pointer dereference
      ARM: at91 smc: Fix possible uninitialized variable
      MCI: atmel: Fix possible null pointer dereference
      MCI: imx: Fix possible null pointer dereference
      NAND: imx: Fix memory leak
      ARM: pcm038: Add descriptions for pin-groups
      ARM: pcm038: Add definition for SPI chipselect 0
      ARM: pcm038: Add definition for FEC reset
      ARM: ccmx51js: Add support for USB Host1
      ARM: ccmx51: Another fix SDRAM size detection

Alexandre Belloni (1):
      sama5d3xek: correct rootfs nand partition

Andreas Pretzsch (2):
      ARM i.MX31: cleanup MX31_ prefix: fix leftover IOMUXC_BASE defines
      ARM i.MX31 pcm037: fix erroneous IOMUX GPR setup in pcm037_usb_init()

Antony Pavlov (2):
      ARM: remove unused clkdev.h
      gpio: fix typos

Enrico Scholz (3):
      ARM v7: fix mmu-off operation
      ARM v7: v7_mmu_cache_flush(): do not restore r0-r3 (minor optimization)
      ARM v7: added v7_mmu_cache_invalidate()

Eric B?nard (2):
      nand_base: detect more ONFI flash
      nand_base: sync flash detection functions with linux 3.9's code

Jan Luebbe (10):
      commands: i2c: change 0X to 0x
      mtd: update NAND manufacturer names from the kernel
      commands: the crc command is actually called crc32
      omap: move to common bootsource framework
      beaglebone: remove stray semicolon
      Makefile: drop duplicate definition of cmd_objcopy
      am33xx: add defines for GPIOs
      m33xx-clock: configure PLLs based on oscillator frequency
      m33xx-clock: remove unused code
      defaultenv-2: init: display prompt after running /env/init/*

Jan Weitzel (1):
      ARM: mmu: Use PAGE_ALIGN in dma_free_coherent

Jean-Christophe PLAGNIOL-VILLARD (4):
      highbank: switch to defaultenv-2
      at91sam9m10g45ek: add spi dataflash supprt
      commands/mem.c: drop non used DEVMEM
      qt1070: drop non used buf

Juergen Beisert (7):
      ARM/MXS: add more ROM code related documentation
      MXS/MCI: simplify reset of the MCI device block
      MCI/Core: increase the transmission frequency while card detection
      MCI/Core: honor transmission limits at the card's side
      MCI/MXS: report a better matching error code when the transfer fails
      MCI/MXS: fix signed/unsigned mismatch
      MXS: fix SoC detecting

Lucas Stach (13):
      tegra: switch to proper CPU type
      tegra: unify spelling in Kconfig with Linux kernel
      tegra: introduce Tegra 20 SoC type
      tegra: move default textbase
      tegra: switch to DT only
      tegra: add driver for the clock and reset module
      tegra: add T20 timer driver
      tegra: add T20 power management controller driver
      tegra: add common lowlevel startup
      tegra: add generic debug UART support
      tegra: add generic meminit
      tegra: add GPIO controller driver
      arm: properly init alignment trap bit

Masaki Muranaka (1):
      Avoid build error on "config SPI" is y

Nicolas Pitre (1):
      ARM: fix the memset fix

Sascha Hauer (68):
      param: Add dev member to struct param_d
      param: refactor __dev_add_param
      param: Add integer and boolean parameter helpers
      param: Add ip address convenience function
      net: ksz8864: Use dev_add_param_bool for enable parameter
      net: store ethernet device parameters in device
      netconsole: use dev_add_param_* helpers
      param: remove now unused dev_[gs]et_param_ip
      treewide: Use dev_add_param_int_ro where possible
      mci: Use dev_add_param_int for probe parameter
      ata: Use dev_add_param_bool for probe parameter
      fb: Use dev_add_param_bool for enable parameter
      fb: imxfb: Use dev_add_param_int for alpha parameter
      fb: imx-ipu-fb: Use dev_add_param_int for alpha parameter
      param: pass param to dev_remove_param
      pwm: Use dev_add_param_int for pwm parameters
      ARM: i.MX: iim: Use dev_add_param_bool for parameters
      console: Use dev_add_param_int for baudrate parameter
      mtd: Nand: Use dev_add_param_bool for erasebad parameter
      USB gadget at91: Use dev_add_param_bool for vbus parameter
      ARM: MXS: ocotp: Use dev_add_param_bool for parameter
      memory commands: export common functions
      memory commands: move memory_display to separate file
      Use a common define for RW_BUF_SIZE
      memory commands: cleanup initialization
      memory commands: make rw_buf global
      memory commands: separate into one file per command
      Add memory modify command (mm)
      defaultenv-2: net: use oftree when existing
      of: parse phandles before probing devices
      of: Add of_property_read_string_index()
      of: Allow multiple resources in 'reg' property
      of: read resource names from devicetree
      of: partitions: pass struct cdev as argument
      of: partitions: create bb device for nand flashes
      Add initial pinctrl support
      pinctrl: switch i.MX iomux-v3 support to pinctrl
      pinctrl: move imx-iomux-v2 to drivers/pinctrl/
      pinctrl: move imx-iomux-v1 to drivers/pinctrl/
      mci: imx-esdhc: remove cache snoop register access
      Don't honor initrd load address
      Merge branch 'for-next/atmel'
      Merge branch 'for-next/gpio'
      Merge branch 'for-next/imx'
      Merge branch 'for-next/mci'
      Merge branch 'for-next/memory-commands'
      Merge branch 'for-next/misc'
      Merge branch 'for-next/mtd'
      Merge branch 'for-next/mxs'
      Merge branch 'for-next/of'
      Merge branch 'for-next/omap'
      Merge branch 'for-next/param'
      Merge branch 'for-next/remove-config-h'
      Merge branch 'for-next/tegra'
      ARM: i.MX: Allow disabling SDRAM autodetection
      ARM: i.MX: ccxmx51: detect SDRAM size by board id
      net: dhcp: Fix return value on ctrl-c
      net: dhcp: Fix tftp servername handling
      Merge branch 'pu/dhcp'
      fdt: Fix dt memreserve entry
      ARM: invalidate data caches during early init
      pbl: Fix typo in make causing pbl files to be rebuilt
      ARM: pbl: fix make dependencies
      make: Add barebox_default_env.* to targets
      ARM: zynq: Add cmd to generate zynq image
      ARM: i.MX53 vincell: Fix lowlevel startup
      ARM: pbl: Always call pbl make
      Release v2013.06.0

Steffen Trumtrar (2):
      defaultenv-2: Fix settings entry
      ARM i.MX53: tqma53: fix console entry

Thomas Petazzoni (1):
      scripts: allow lines longer than 80 cols with printf() in checkpatch

Uwe Kleine-K?nig (1):
      bootm: Simplify initrd address handling

Vicente Bergas (1):
      OMAP4: add command to select next boot device priority

 Makefile                                           |  23 +-
 arch/arm/Kconfig                                   |  11 +-
 arch/arm/Makefile                                  |  20 +-
 arch/arm/boards/archosg9/config.h                  |   1 -
 arch/arm/boards/at91sam9m10g45ek/init.c            |  18 +
 arch/arm/boards/at91sam9m10ihd/hw_version.c        |   6 +-
 arch/arm/boards/at91sam9x5ek/hw_version.c          |   6 +-
 arch/arm/boards/avnet-zedboard/config.h            |   4 -
 arch/arm/boards/beagle/config.h                    |  17 -
 arch/arm/boards/beaglebone/config.h                |  17 -
 arch/arm/boards/beaglebone/lowlevel.c              |   2 +-
 arch/arm/boards/ccxmx51/ccxmx51.c                  |  63 ++-
 arch/arm/boards/ccxmx51/ccxmx51.h                  |   1 +
 arch/arm/boards/ccxmx51/ccxmx51js.c                |  15 +
 arch/arm/boards/ccxmx51/config.h                   |  24 -
 arch/arm/boards/ccxmx51/lowlevel.c                 |   4 +-
 arch/arm/boards/chumby_falconwing/config.h         |  17 -
 arch/arm/boards/clep7212/config.h                  |   4 -
 arch/arm/boards/crystalfontz-cfa10036/config.h     |  16 -
 arch/arm/boards/dmo-mx6-realq7/config.h            |   4 -
 arch/arm/boards/edb93xx/config.h                   |   4 -
 arch/arm/boards/efika-mx-smartbook/config.h        |  17 -
 arch/arm/boards/eukrea_cpuimx27/config.h           |  22 -
 arch/arm/boards/eukrea_cpuimx51/config.h           |  20 -
 arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c  |  14 +-
 arch/arm/boards/freescale-mx23-evk/config.h        |  12 -
 arch/arm/boards/freescale-mx28-evk/config.h        |  16 -
 arch/arm/boards/freescale-mx51-pdk/config.h        |  20 -
 arch/arm/boards/freescale-mx53-loco/config.h       |  20 -
 arch/arm/boards/freescale-mx53-smd/config.h        |  20 -
 arch/arm/boards/freescale-mx6-arm2/config.h        |   4 -
 arch/arm/boards/freescale-mx6-sabrelite/config.h   |   4 -
 arch/arm/boards/freescale-mx6-sabresd/config.h     |   4 -
 arch/arm/boards/guf-neso/config.h                  |  22 -
 arch/arm/boards/guf-vincell/config.h               |  24 -
 arch/arm/boards/guf-vincell/lowlevel.c             |   4 +-
 arch/arm/boards/highbank/config.h                  |   5 -
 arch/arm/boards/highbank/env/boot.d/010-ahci-boot  |   1 +
 arch/arm/boards/highbank/env/boot.d/011-ahci       |   1 +
 arch/arm/boards/highbank/env/boot.d/020-mmc-boot   |   1 +
 arch/arm/boards/highbank/env/boot.d/021-mmc        |   1 +
 arch/arm/boards/highbank/env/boot.d/030-net        |   1 +
 arch/arm/boards/highbank/env/boot.d/031-net-eth1   |   1 +
 arch/arm/boards/highbank/env/boot/ahci             |  21 +
 arch/arm/boards/highbank/env/boot/ahci-boot        |  21 +
 arch/arm/boards/highbank/env/boot/mmc              |  21 +
 arch/arm/boards/highbank/env/boot/mmc-boot         |  21 +
 arch/arm/boards/highbank/env/boot/net              |  18 +
 arch/arm/boards/highbank/env/boot/net-eth1         |  18 +
 arch/arm/boards/highbank/env/config                |  33 --
 arch/arm/boards/highbank/env/config-board          |  11 +
 arch/arm/boards/highbank/env/data/oftree           |   4 +
 .../env/{bin/init_board => init/001-dtb-probe}     |   0
 arch/arm/boards/highbank/env/init/automount        |  27 ++
 arch/arm/boards/highbank/env/init/ps1              |   9 +
 arch/arm/boards/imx21ads/config.h                  |  22 -
 arch/arm/boards/imx233-olinuxino/config.h          |  21 -
 arch/arm/boards/imx27ads/config.h                  |  22 -
 arch/arm/boards/karo-tx28/config.h                 |  16 -
 arch/arm/boards/karo-tx51/config.h                 |  17 -
 arch/arm/boards/karo-tx53/config.h                 |  24 -
 arch/arm/boards/mioa701/config.h                   |  22 -
 arch/arm/boards/netx/config.h                      |   4 -
 arch/arm/boards/nhk8815/config.h                   |   1 -
 arch/arm/boards/omap343xdsp/config.h               |  17 -
 arch/arm/boards/omap3evm/config.h                  |  17 -
 arch/arm/boards/panda/config.h                     |   1 -
 arch/arm/boards/pcm037/pcm037.c                    |   6 +-
 arch/arm/boards/pcm038/config.h                    |  22 -
 arch/arm/boards/pcm038/pcm038.c                    |  14 +-
 arch/arm/boards/pcm049/config.h                    |   1 -
 arch/arm/boards/pcm051/config.h                    |  21 -
 arch/arm/boards/phycard-a-l1/config.h              |  18 -
 arch/arm/boards/phycard-a-xl2/config.h             |   1 -
 arch/arm/boards/phycard-i.MX27/config.h            |  22 -
 arch/arm/boards/raspberry-pi/config.h              |   4 -
 arch/arm/boards/sama5d3xek/env/config              |   2 +-
 arch/arm/boards/sama5d3xek/hw_version.c            |   6 +-
 arch/arm/boards/toshiba-ac100/Makefile             |   2 -
 arch/arm/boards/toshiba-ac100/board.c              |   8 -
 arch/arm/boards/toshiba-ac100/config.h             |   5 -
 arch/arm/boards/toshiba-ac100/lowlevel.c           |  10 -
 arch/arm/boards/toshiba-ac100/serial.c             |  39 --
 arch/arm/boards/tqma53/config.h                    |   4 -
 arch/arm/boards/tqma53/env/config-board            |   2 +-
 arch/arm/boards/versatile/config.h                 |   5 -
 arch/arm/boards/vexpress/config.h                  |   5 -
 arch/arm/configs/at91sam9m10g45ek_defconfig        |   4 +-
 arch/arm/configs/phycard_a_l1_defconfig            |   1 -
 arch/arm/configs/toshiba_ac100_defconfig           |   7 +-
 arch/arm/cpu/cache-armv7.S                         |  74 +--
 arch/arm/cpu/cache.c                               |  21 +
 arch/arm/cpu/mmu.c                                 |   7 +-
 arch/arm/cpu/start-pbl.c                           |   2 +
 arch/arm/cpu/start.c                               |   2 +
 arch/arm/dts/tegra20-paz00.dts                     |  12 +
 arch/arm/dts/tegra20.dtsi                          |  41 ++
 arch/arm/include/asm/barebox-arm-head.h            |   2 +-
 arch/arm/include/asm/cache.h                       |   5 +
 arch/arm/lib/memset.S                              |  33 +-
 arch/arm/mach-at91/gpio.c                          |   5 +-
 arch/arm/mach-at91/sam9_smc.c                      |   8 +-
 arch/arm/mach-highbank/Kconfig                     |   1 +
 arch/arm/mach-imx/Kconfig                          |  15 +-
 arch/arm/mach-imx/Makefile                         |  20 +-
 arch/arm/mach-imx/esdctl.c                         |  14 +
 arch/arm/mach-imx/iim.c                            |  65 +--
 arch/arm/mach-imx/include/mach/esdctl.h            |   1 +
 arch/arm/mach-imx/include/mach/imx31-regs.h        |   6 +-
 arch/arm/mach-imx/include/mach/iomux-mx27.h        |   6 -
 arch/arm/mach-imx/include/mach/iomux-mx2x.h        |  12 +-
 arch/arm/mach-imx/include/mach/iomux-mx51.h        |  28 +-
 arch/arm/mach-imx/iomux-v3.c                       | 107 -----
 arch/arm/mach-mxs/imx.c                            |   1 +
 arch/arm/mach-mxs/ocotp.c                          |  34 +-
 arch/arm/mach-netx/Kconfig                         |  16 -
 arch/arm/mach-omap/Kconfig                         |   9 +-
 arch/arm/mach-omap/Makefile                        |   1 +
 arch/arm/mach-omap/am33xx_generic.c                |  10 +-
 arch/arm/mach-omap/boot_order.c                    |  83 ++++
 arch/arm/mach-omap/include/mach/am33xx-clock.h     |  18 +-
 arch/arm/mach-omap/include/mach/am33xx-silicon.h   |   6 +
 arch/arm/mach-omap/include/mach/generic.h          |  13 -
 arch/arm/mach-omap/include/mach/omap4-silicon.h    |  20 +
 arch/arm/mach-omap/omap3_clock.c                   |   6 -
 arch/arm/mach-omap/omap3_generic.c                 |  16 +-
 arch/arm/mach-omap/omap4_generic.c                 |  44 +-
 arch/arm/mach-omap/omap_generic.c                  |  15 +-
 arch/arm/mach-omap/xload.c                         |  26 +-
 arch/arm/mach-tegra/Kconfig                        |  53 ++-
 arch/arm/mach-tegra/Makefile                       |   9 +-
 arch/arm/mach-tegra/clock.c                        |  56 ---
 arch/arm/mach-tegra/include/mach/gpio.h            |   1 +
 arch/arm/mach-tegra/include/mach/iomap.h           |   3 +
 arch/arm/mach-tegra/include/mach/lowlevel.h        | 146 ++++++
 arch/arm/mach-tegra/include/mach/tegra20-car.h     | 179 +++++++
 arch/arm/mach-tegra/include/mach/tegra20-pmc.h     |  67 +++
 arch/arm/mach-tegra/reset.c                        |  39 --
 arch/arm/mach-tegra/tegra20-car.c                  | 120 +++++
 arch/arm/mach-tegra/tegra20-pmc.c                  |  68 +++
 arch/arm/mach-tegra/tegra20-timer.c                | 119 +++++
 arch/arm/mach-tegra/tegra20.c                      |  65 +++
 arch/arm/mach-tegra/tegra_avp_init.c               | 226 +++++++++
 arch/arm/mach-tegra/tegra_maincomplex_init.c       |  46 ++
 arch/arm/mach-zynq/include/mach/clkdev.h           |   6 -
 arch/mips/boards/dlink-dir-320/config.h            |  15 -
 arch/mips/boards/qemu-malta/config.h               |  15 -
 arch/mips/boards/rzx50/config.h                    |  15 -
 arch/sandbox/board/config.h                        |   4 -
 arch/x86/boards/x86_generic/config.h               |  17 -
 arch/x86/include/asm/types.h                       |   4 +
 commands/Kconfig                                   |  54 ++-
 commands/Makefile                                  |   6 +
 commands/bootm.c                                   |   7 +-
 commands/i2c.c                                     |   2 +-
 commands/md.c                                      | 116 +++++
 commands/mem.c                                     | 526 +--------------------
 commands/memcmp.c                                  | 148 ++++++
 commands/memcpy.c                                  | 145 ++++++
 commands/memset.c                                  | 101 ++++
 commands/mm.c                                      | 117 +++++
 commands/mw.c                                      | 104 ++++
 common/Makefile                                    |   3 +
 common/console.c                                   |  26 +-
 common/memory_display.c                            |  64 +++
 defaultenv-2/base/bin/init                         |  12 +-
 defaultenv-2/base/boot/net                         |   7 +-
 defaultenv-2/menu/menu/settings                    |   2 +-
 drivers/Kconfig                                    |   1 +
 drivers/Makefile                                   |   1 +
 drivers/amba/bus.c                                 |   9 +-
 drivers/ata/Kconfig                                |   1 -
 drivers/ata/disk_ata_drive.c                       |  21 +-
 drivers/base/driver.c                              |   3 +
 drivers/gpio/Kconfig                               |  10 +
 drivers/gpio/Makefile                              |   5 +-
 .../arm/mach-imx/gpio.c => drivers/gpio/gpio-imx.c |   0
 drivers/gpio/gpio-tegra.c                          | 214 +++++++++
 drivers/gpio/{gpio.c => gpiolib.c}                 |   0
 drivers/input/qt1070.c                             |   7 +-
 drivers/mci/atmel_mci.c                            |   4 +-
 drivers/mci/imx-esdhc.c                            |   7 -
 drivers/mci/imx.c                                  |   5 +-
 drivers/mci/mci-core.c                             |  55 +--
 drivers/mci/mxs.c                                  |  22 +-
 drivers/mtd/core.c                                 |  13 +-
 drivers/mtd/nand/nand_base.c                       | 421 +++++++++++------
 drivers/mtd/nand/nand_ids.c                        |   4 +-
 drivers/mtd/nand/nand_imx_bbm.c                    |   9 +-
 drivers/net/ksz8864rmn.c                           |  30 +-
 drivers/net/phy/mdio_bus.c                         |   8 +-
 drivers/of/base.c                                  | 133 +++++-
 drivers/of/fdt.c                                   |   3 +-
 drivers/of/partition.c                             |  13 +-
 drivers/pinctrl/Kconfig                            |  28 ++
 drivers/pinctrl/Makefile                           |   4 +
 .../iomux-v1.c => drivers/pinctrl/imx-iomux-v1.c   |   0
 .../iomux-v2.c => drivers/pinctrl/imx-iomux-v2.c   |   0
 drivers/pinctrl/imx-iomux-v3.c                     | 212 +++++++++
 drivers/pinctrl/pinctrl.c                          | 149 ++++++
 drivers/pwm/core.c                                 |  89 ++--
 drivers/usb/core/usb.c                             |  19 +-
 drivers/usb/gadget/at91_udc.c                      |  23 +-
 drivers/video/fb.c                                 |  33 +-
 drivers/video/imx-ipu-fb.c                         |  27 +-
 drivers/video/imx.c                                |  26 +-
 drivers/watchdog/im28wd.c                          |  75 ++-
 include/asm-generic/gpio.h                         |   1 -
 include/ata_drive.h                                |   1 +
 include/common.h                                   |   7 +-
 include/console.h                                  |   2 +
 include/fb.h                                       |   1 +
 include/gpio.h                                     |   2 +-
 include/linux/mtd/bbm.h                            |   2 +
 include/linux/mtd/mtd.h                            |   1 +
 include/linux/mtd/nand.h                           |  20 +-
 include/mci.h                                      |   2 +
 include/net.h                                      |   7 +-
 include/of.h                                       |  10 +-
 include/param.h                                    |  66 ++-
 include/pinctrl.h                                  |  35 ++
 include/usb/usb.h                                  |   1 -
 lib/copy_file.c                                    |   2 -
 lib/parameter.c                                    | 302 ++++++++++--
 net/dhcp.c                                         |  15 +-
 net/eth.c                                          |  40 +-
 net/net.c                                          |  80 ++--
 net/netconsole.c                                   |  50 +-
 scripts/Makefile.build                             |   2 +-
 scripts/checkpatch.pl                              |   2 +-
 230 files changed, 4445 insertions(+), 2516 deletions(-)
 delete mode 100644 arch/arm/boards/archosg9/config.h
 delete mode 100644 arch/arm/boards/avnet-zedboard/config.h
 delete mode 100644 arch/arm/boards/beagle/config.h
 delete mode 100644 arch/arm/boards/beaglebone/config.h
 delete mode 100644 arch/arm/boards/ccxmx51/config.h
 delete mode 100644 arch/arm/boards/chumby_falconwing/config.h
 delete mode 100644 arch/arm/boards/clep7212/config.h
 delete mode 100644 arch/arm/boards/crystalfontz-cfa10036/config.h
 delete mode 100644 arch/arm/boards/dmo-mx6-realq7/config.h
 delete mode 100644 arch/arm/boards/edb93xx/config.h
 delete mode 100644 arch/arm/boards/efika-mx-smartbook/config.h
 delete mode 100644 arch/arm/boards/eukrea_cpuimx27/config.h
 delete mode 100644 arch/arm/boards/eukrea_cpuimx51/config.h
 delete mode 100644 arch/arm/boards/freescale-mx23-evk/config.h
 delete mode 100644 arch/arm/boards/freescale-mx28-evk/config.h
 delete mode 100644 arch/arm/boards/freescale-mx51-pdk/config.h
 delete mode 100644 arch/arm/boards/freescale-mx53-loco/config.h
 delete mode 100644 arch/arm/boards/freescale-mx53-smd/config.h
 delete mode 100644 arch/arm/boards/freescale-mx6-arm2/config.h
 delete mode 100644 arch/arm/boards/freescale-mx6-sabrelite/config.h
 delete mode 100644 arch/arm/boards/freescale-mx6-sabresd/config.h
 delete mode 100644 arch/arm/boards/guf-neso/config.h
 delete mode 100644 arch/arm/boards/guf-vincell/config.h
 delete mode 100644 arch/arm/boards/highbank/config.h
 create mode 120000 arch/arm/boards/highbank/env/boot.d/010-ahci-boot
 create mode 120000 arch/arm/boards/highbank/env/boot.d/011-ahci
 create mode 120000 arch/arm/boards/highbank/env/boot.d/020-mmc-boot
 create mode 120000 arch/arm/boards/highbank/env/boot.d/021-mmc
 create mode 120000 arch/arm/boards/highbank/env/boot.d/030-net
 create mode 120000 arch/arm/boards/highbank/env/boot.d/031-net-eth1
 create mode 100644 arch/arm/boards/highbank/env/boot/ahci
 create mode 100644 arch/arm/boards/highbank/env/boot/ahci-boot
 create mode 100644 arch/arm/boards/highbank/env/boot/mmc
 create mode 100644 arch/arm/boards/highbank/env/boot/mmc-boot
 create mode 100644 arch/arm/boards/highbank/env/boot/net
 create mode 100644 arch/arm/boards/highbank/env/boot/net-eth1
 delete mode 100644 arch/arm/boards/highbank/env/config
 create mode 100644 arch/arm/boards/highbank/env/config-board
 create mode 100644 arch/arm/boards/highbank/env/data/oftree
 rename arch/arm/boards/highbank/env/{bin/init_board => init/001-dtb-probe} (100%)
 create mode 100644 arch/arm/boards/highbank/env/init/automount
 create mode 100644 arch/arm/boards/highbank/env/init/ps1
 delete mode 100644 arch/arm/boards/imx21ads/config.h
 delete mode 100644 arch/arm/boards/imx233-olinuxino/config.h
 delete mode 100644 arch/arm/boards/imx27ads/config.h
 delete mode 100644 arch/arm/boards/karo-tx28/config.h
 delete mode 100644 arch/arm/boards/karo-tx51/config.h
 delete mode 100644 arch/arm/boards/karo-tx53/config.h
 delete mode 100644 arch/arm/boards/mioa701/config.h
 delete mode 100644 arch/arm/boards/netx/config.h
 delete mode 100644 arch/arm/boards/nhk8815/config.h
 delete mode 100644 arch/arm/boards/omap343xdsp/config.h
 delete mode 100644 arch/arm/boards/omap3evm/config.h
 delete mode 100644 arch/arm/boards/panda/config.h
 delete mode 100644 arch/arm/boards/pcm038/config.h
 delete mode 100644 arch/arm/boards/pcm049/config.h
 delete mode 100644 arch/arm/boards/pcm051/config.h
 delete mode 100644 arch/arm/boards/phycard-a-l1/config.h
 delete mode 100644 arch/arm/boards/phycard-a-xl2/config.h
 delete mode 100644 arch/arm/boards/phycard-i.MX27/config.h
 delete mode 100644 arch/arm/boards/raspberry-pi/config.h
 delete mode 100644 arch/arm/boards/toshiba-ac100/config.h
 delete mode 100644 arch/arm/boards/toshiba-ac100/lowlevel.c
 delete mode 100644 arch/arm/boards/toshiba-ac100/serial.c
 delete mode 100644 arch/arm/boards/tqma53/config.h
 delete mode 100644 arch/arm/boards/versatile/config.h
 delete mode 100644 arch/arm/boards/vexpress/config.h
 create mode 100644 arch/arm/dts/tegra20-paz00.dts
 create mode 100644 arch/arm/dts/tegra20.dtsi
 delete mode 100644 arch/arm/mach-imx/iomux-v3.c
 create mode 100644 arch/arm/mach-omap/boot_order.c
 delete mode 100644 arch/arm/mach-tegra/clock.c
 create mode 100644 arch/arm/mach-tegra/include/mach/gpio.h
 create mode 100644 arch/arm/mach-tegra/include/mach/lowlevel.h
 create mode 100644 arch/arm/mach-tegra/include/mach/tegra20-car.h
 create mode 100644 arch/arm/mach-tegra/include/mach/tegra20-pmc.h
 delete mode 100644 arch/arm/mach-tegra/reset.c
 create mode 100644 arch/arm/mach-tegra/tegra20-car.c
 create mode 100644 arch/arm/mach-tegra/tegra20-pmc.c
 create mode 100644 arch/arm/mach-tegra/tegra20-timer.c
 create mode 100644 arch/arm/mach-tegra/tegra20.c
 create mode 100644 arch/arm/mach-tegra/tegra_avp_init.c
 create mode 100644 arch/arm/mach-tegra/tegra_maincomplex_init.c
 delete mode 100644 arch/arm/mach-zynq/include/mach/clkdev.h
 delete mode 100644 arch/mips/boards/dlink-dir-320/config.h
 delete mode 100644 arch/mips/boards/qemu-malta/config.h
 delete mode 100644 arch/mips/boards/rzx50/config.h
 delete mode 100644 arch/sandbox/board/config.h
 delete mode 100644 arch/x86/boards/x86_generic/config.h
 create mode 100644 commands/md.c
 create mode 100644 commands/memcmp.c
 create mode 100644 commands/memcpy.c
 create mode 100644 commands/memset.c
 create mode 100644 commands/mm.c
 create mode 100644 commands/mw.c
 create mode 100644 common/memory_display.c
 rename arch/arm/mach-imx/gpio.c => drivers/gpio/gpio-imx.c (100%)
 create mode 100644 drivers/gpio/gpio-tegra.c
 rename drivers/gpio/{gpio.c => gpiolib.c} (100%)
 create mode 100644 drivers/pinctrl/Kconfig
 create mode 100644 drivers/pinctrl/Makefile
 rename arch/arm/mach-imx/iomux-v1.c => drivers/pinctrl/imx-iomux-v1.c (100%)
 rename arch/arm/mach-imx/iomux-v2.c => drivers/pinctrl/imx-iomux-v2.c (100%)
 create mode 100644 drivers/pinctrl/imx-iomux-v3.c
 create mode 100644 drivers/pinctrl/pinctrl.c
 create mode 100644 include/pinctrl.h
-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun  3 03:37:17 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Jun 2013 09:37:17 +0200
Subject: [PATCH] Fix typo.
In-Reply-To: <1370135333-79633-1-git-send-email-monaka@monami-ya.com>
References: <1370135333-79633-1-git-send-email-monaka@monami-ya.com>
Message-ID: <20130603073717.GA32299@pengutronix.de>

On Sun, Jun 02, 2013 at 10:08:53AM +0900, monaka at monami-ya.jp wrote:
> From: Masaki Muranaka <monaka at monami-ya.com>

Could you resend this with a proper signed-off-by?

Thanks
 Sascha

> 
> ---
>  include/stdio.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/stdio.h b/include/stdio.h
> index 5c091a8..0eacdfc 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -70,7 +70,7 @@ static inline int ctrlc (void)
>  {
>  	return 0;
>  }
> -#endif /* ARCH_HAS_CTRC */
> +#endif /* ARCH_HAS_CTRLC */
>  
>  #endif
>  
> -- 
> 1.8.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun  3 03:37:40 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Jun 2013 09:37:40 +0200
Subject: [PATCH] Provide and use dirent.h.
In-Reply-To: <1370181559-53032-1-git-send-email-monaka@monami-ya.com>
References: <1370181559-53032-1-git-send-email-monaka@monami-ya.com>
Message-ID: <20130603073740.GB32299@pengutronix.de>

On Sun, Jun 02, 2013 at 10:59:19PM +0900, Masaki Muranaka wrote:
> It is for compatibility with the POSIX standard.

This one also lacks a signed-off-by

Sascha

> ---
>  commands/ls.c          |  2 +-
>  common/complete.c      |  2 +-
>  common/hush.c          |  2 +-
>  fs/ramfs.c             |  1 +
>  include/dirent.h       | 25 +++++++++++++++++++++++++
>  include/fs.h           | 16 +---------------
>  lib/glob.c             |  2 +-
>  lib/recursive_action.c |  2 +-
>  8 files changed, 32 insertions(+), 20 deletions(-)
>  create mode 100644 include/dirent.h
> 
> diff --git a/commands/ls.c b/commands/ls.c
> index f2d9903..2b1b08b 100644
> --- a/commands/ls.c
> +++ b/commands/ls.c
> @@ -19,7 +19,7 @@
>  
>  #include <common.h>
>  #include <command.h>
> -#include <fs.h>
> +#include <dirent.h>
>  #include <linux/stat.h>
>  #include <errno.h>
>  #include <malloc.h>
> diff --git a/common/complete.c b/common/complete.c
> index 9206ef0..1fdc320 100644
> --- a/common/complete.c
> +++ b/common/complete.c
> @@ -17,7 +17,7 @@
>  #include <common.h>
>  #include <complete.h>
>  #include <xfuncs.h>
> -#include <fs.h>
> +#include <dirent.h>
>  #include <linux/stat.h>
>  #include <libgen.h>
>  #include <command.h>
> diff --git a/common/hush.c b/common/hush.c
> index b5e111a..64c0b06 100644
> --- a/common/hush.c
> +++ b/common/hush.c
> @@ -114,7 +114,7 @@
>  #include <command.h>        /* find_cmd */
>  #include <driver.h>
>  #include <errno.h>
> -#include <fs.h>
> +#include <dirent.h>
>  #include <libbb.h>
>  #include <glob.h>
>  #include <getopt.h>
> diff --git a/fs/ramfs.c b/fs/ramfs.c
> index f45a454..3f9df7c 100644
> --- a/fs/ramfs.c
> +++ b/fs/ramfs.c
> @@ -21,6 +21,7 @@
>  #include <driver.h>
>  #include <init.h>
>  #include <malloc.h>
> +#include <dirent.h>
>  #include <fs.h>
>  #include <command.h>
>  #include <errno.h>
> diff --git a/include/dirent.h b/include/dirent.h
> new file mode 100644
> index 0000000..2faee78
> --- /dev/null
> +++ b/include/dirent.h
> @@ -0,0 +1,25 @@
> +#ifndef BAREBOX_DIRENT_H__
> +#define BAREBOX_DIRENT_H__
> +
> +struct device_d;
> +struct fs_driver_d;
> +struct node_d;
> +
> +struct dirent {
> +	char d_name[256];
> +};
> +
> +typedef struct dir {
> +	struct device_d *dev;
> +	struct fs_driver_d *fsdrv;
> +	struct node_d *node;
> +	struct dirent d;
> +	void *priv; /* private data for the fs driver */
> +} DIR;
> +
> +DIR *opendir(const char *pathname);
> +struct dirent *readdir(DIR *dir);
> +int closedir(DIR *dir);
> +
> +
> +#endif /* BAREBOX_DIRENT_H__ */
> diff --git a/include/fs.h b/include/fs.h
> index 7c4e461..0984da1 100644
> --- a/include/fs.h
> +++ b/include/fs.h
> @@ -10,17 +10,7 @@ struct partition;
>  struct node_d;
>  struct stat;
>  
> -struct dirent {
> -	char d_name[256];
> -};
> -
> -typedef struct dir {
> -	struct device_d *dev;
> -	struct fs_driver_d *fsdrv;
> -	struct node_d *node;
> -	struct dirent d;
> -	void *priv; /* private data for the fs driver */
> -} DIR;
> +#include <dirent.h>
>  
>  typedef struct filep {
>  	struct device_d *dev; /* The device this FILE belongs to              */
> @@ -133,10 +123,6 @@ int rmdir (const char *pathname);
>  const char *getcwd(void);
>  int chdir(const char *pathname);
>  
> -DIR *opendir(const char *pathname);
> -struct dirent *readdir(DIR *dir);
> -int closedir(DIR *dir);
> -
>  int symlink(const char *pathname, const char *newpath);
>  int readlink(const char *path, char *buf, size_t bufsiz);
>  
> diff --git a/lib/glob.c b/lib/glob.c
> index 1b0137b..7a522a9 100644
> --- a/lib/glob.c
> +++ b/lib/glob.c
> @@ -17,7 +17,7 @@ Cambridge, MA 02139, USA.  */
>  
>  #include <common.h>
>  #include <errno.h>
> -#include <fs.h>
> +#include <dirent.h>
>  #include <linux/stat.h>
>  #include <malloc.h>
>  #include <xfuncs.h>
> diff --git a/lib/recursive_action.c b/lib/recursive_action.c
> index 345d3db..06e60b8 100644
> --- a/lib/recursive_action.c
> +++ b/lib/recursive_action.c
> @@ -9,7 +9,7 @@
>  #ifdef __BAREBOX__
>  
>  #include <common.h>
> -#include <fs.h>
> +#include <dirent.h>
>  #include <linux/stat.h>
>  #include <malloc.h>
>  #include <libbb.h>
> -- 
> 1.8.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From monaka at monami-ya.jp  Mon Jun  3 03:43:54 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Mon,  3 Jun 2013 16:43:54 +0900
Subject: [PATCH] Provide and use dirent.h.
Message-ID: <1370245434-68452-1-git-send-email-monaka@monami-ya.jp>

It is for compatibility with the POSIX standard.

Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
---
 commands/ls.c          |  2 +-
 common/complete.c      |  2 +-
 common/hush.c          |  2 +-
 fs/ramfs.c             |  1 +
 include/dirent.h       | 25 +++++++++++++++++++++++++
 include/fs.h           | 16 +---------------
 lib/glob.c             |  2 +-
 lib/recursive_action.c |  2 +-
 8 files changed, 32 insertions(+), 20 deletions(-)
 create mode 100644 include/dirent.h

diff --git a/commands/ls.c b/commands/ls.c
index f2d9903..2b1b08b 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -19,7 +19,7 @@
 
 #include <common.h>
 #include <command.h>
-#include <fs.h>
+#include <dirent.h>
 #include <linux/stat.h>
 #include <errno.h>
 #include <malloc.h>
diff --git a/common/complete.c b/common/complete.c
index 9206ef0..1fdc320 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -17,7 +17,7 @@
 #include <common.h>
 #include <complete.h>
 #include <xfuncs.h>
-#include <fs.h>
+#include <dirent.h>
 #include <linux/stat.h>
 #include <libgen.h>
 #include <command.h>
diff --git a/common/hush.c b/common/hush.c
index b5e111a..64c0b06 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -114,7 +114,7 @@
 #include <command.h>        /* find_cmd */
 #include <driver.h>
 #include <errno.h>
-#include <fs.h>
+#include <dirent.h>
 #include <libbb.h>
 #include <glob.h>
 #include <getopt.h>
diff --git a/fs/ramfs.c b/fs/ramfs.c
index f45a454..3f9df7c 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -21,6 +21,7 @@
 #include <driver.h>
 #include <init.h>
 #include <malloc.h>
+#include <dirent.h>
 #include <fs.h>
 #include <command.h>
 #include <errno.h>
diff --git a/include/dirent.h b/include/dirent.h
new file mode 100644
index 0000000..2faee78
--- /dev/null
+++ b/include/dirent.h
@@ -0,0 +1,25 @@
+#ifndef BAREBOX_DIRENT_H__
+#define BAREBOX_DIRENT_H__
+
+struct device_d;
+struct fs_driver_d;
+struct node_d;
+
+struct dirent {
+	char d_name[256];
+};
+
+typedef struct dir {
+	struct device_d *dev;
+	struct fs_driver_d *fsdrv;
+	struct node_d *node;
+	struct dirent d;
+	void *priv; /* private data for the fs driver */
+} DIR;
+
+DIR *opendir(const char *pathname);
+struct dirent *readdir(DIR *dir);
+int closedir(DIR *dir);
+
+
+#endif /* BAREBOX_DIRENT_H__ */
diff --git a/include/fs.h b/include/fs.h
index 7c4e461..0984da1 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -10,17 +10,7 @@ struct partition;
 struct node_d;
 struct stat;
 
-struct dirent {
-	char d_name[256];
-};
-
-typedef struct dir {
-	struct device_d *dev;
-	struct fs_driver_d *fsdrv;
-	struct node_d *node;
-	struct dirent d;
-	void *priv; /* private data for the fs driver */
-} DIR;
+#include <dirent.h>
 
 typedef struct filep {
 	struct device_d *dev; /* The device this FILE belongs to              */
@@ -133,10 +123,6 @@ int rmdir (const char *pathname);
 const char *getcwd(void);
 int chdir(const char *pathname);
 
-DIR *opendir(const char *pathname);
-struct dirent *readdir(DIR *dir);
-int closedir(DIR *dir);
-
 int symlink(const char *pathname, const char *newpath);
 int readlink(const char *path, char *buf, size_t bufsiz);
 
diff --git a/lib/glob.c b/lib/glob.c
index 1b0137b..7a522a9 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -17,7 +17,7 @@ Cambridge, MA 02139, USA.  */
 
 #include <common.h>
 #include <errno.h>
-#include <fs.h>
+#include <dirent.h>
 #include <linux/stat.h>
 #include <malloc.h>
 #include <xfuncs.h>
diff --git a/lib/recursive_action.c b/lib/recursive_action.c
index 345d3db..06e60b8 100644
--- a/lib/recursive_action.c
+++ b/lib/recursive_action.c
@@ -9,7 +9,7 @@
 #ifdef __BAREBOX__
 
 #include <common.h>
-#include <fs.h>
+#include <dirent.h>
 #include <linux/stat.h>
 #include <malloc.h>
 #include <libbb.h>
-- 
1.8.3



From monaka at monami-ya.jp  Mon Jun  3 03:45:17 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Mon, 3 Jun 2013 16:45:17 +0900
Subject: [PATCH] Provide and use dirent.h.
In-Reply-To: <20130603073740.GB32299@pengutronix.de>
References: <1370181559-53032-1-git-send-email-monaka@monami-ya.com>
 <20130603073740.GB32299@pengutronix.de>
Message-ID: <CAJBvFxPLF7Kb40R6DNEiNkx5_8CUrr-0jsiMBQge+6NPi57BNw@mail.gmail.com>

Hello, Sascha.
I re-sent it with signed-off-by.

2013/6/3 Sascha Hauer <s.hauer at pengutronix.de>:
> On Sun, Jun 02, 2013 at 10:59:19PM +0900, Masaki Muranaka wrote:
>> It is for compatibility with the POSIX standard.
>
> This one also lacks a signed-off-by
>
> Sascha
>
>> ---
>>  commands/ls.c          |  2 +-
>>  common/complete.c      |  2 +-
>>  common/hush.c          |  2 +-
>>  fs/ramfs.c             |  1 +
>>  include/dirent.h       | 25 +++++++++++++++++++++++++
>>  include/fs.h           | 16 +---------------
>>  lib/glob.c             |  2 +-
>>  lib/recursive_action.c |  2 +-
>>  8 files changed, 32 insertions(+), 20 deletions(-)
>>  create mode 100644 include/dirent.h
>>
>> diff --git a/commands/ls.c b/commands/ls.c
>> index f2d9903..2b1b08b 100644
>> --- a/commands/ls.c
>> +++ b/commands/ls.c
>> @@ -19,7 +19,7 @@
>>
>>  #include <common.h>
>>  #include <command.h>
>> -#include <fs.h>
>> +#include <dirent.h>
>>  #include <linux/stat.h>
>>  #include <errno.h>
>>  #include <malloc.h>
>> diff --git a/common/complete.c b/common/complete.c
>> index 9206ef0..1fdc320 100644
>> --- a/common/complete.c
>> +++ b/common/complete.c
>> @@ -17,7 +17,7 @@
>>  #include <common.h>
>>  #include <complete.h>
>>  #include <xfuncs.h>
>> -#include <fs.h>
>> +#include <dirent.h>
>>  #include <linux/stat.h>
>>  #include <libgen.h>
>>  #include <command.h>
>> diff --git a/common/hush.c b/common/hush.c
>> index b5e111a..64c0b06 100644
>> --- a/common/hush.c
>> +++ b/common/hush.c
>> @@ -114,7 +114,7 @@
>>  #include <command.h>        /* find_cmd */
>>  #include <driver.h>
>>  #include <errno.h>
>> -#include <fs.h>
>> +#include <dirent.h>
>>  #include <libbb.h>
>>  #include <glob.h>
>>  #include <getopt.h>
>> diff --git a/fs/ramfs.c b/fs/ramfs.c
>> index f45a454..3f9df7c 100644
>> --- a/fs/ramfs.c
>> +++ b/fs/ramfs.c
>> @@ -21,6 +21,7 @@
>>  #include <driver.h>
>>  #include <init.h>
>>  #include <malloc.h>
>> +#include <dirent.h>
>>  #include <fs.h>
>>  #include <command.h>
>>  #include <errno.h>
>> diff --git a/include/dirent.h b/include/dirent.h
>> new file mode 100644
>> index 0000000..2faee78
>> --- /dev/null
>> +++ b/include/dirent.h
>> @@ -0,0 +1,25 @@
>> +#ifndef BAREBOX_DIRENT_H__
>> +#define BAREBOX_DIRENT_H__
>> +
>> +struct device_d;
>> +struct fs_driver_d;
>> +struct node_d;
>> +
>> +struct dirent {
>> +     char d_name[256];
>> +};
>> +
>> +typedef struct dir {
>> +     struct device_d *dev;
>> +     struct fs_driver_d *fsdrv;
>> +     struct node_d *node;
>> +     struct dirent d;
>> +     void *priv; /* private data for the fs driver */
>> +} DIR;
>> +
>> +DIR *opendir(const char *pathname);
>> +struct dirent *readdir(DIR *dir);
>> +int closedir(DIR *dir);
>> +
>> +
>> +#endif /* BAREBOX_DIRENT_H__ */
>> diff --git a/include/fs.h b/include/fs.h
>> index 7c4e461..0984da1 100644
>> --- a/include/fs.h
>> +++ b/include/fs.h
>> @@ -10,17 +10,7 @@ struct partition;
>>  struct node_d;
>>  struct stat;
>>
>> -struct dirent {
>> -     char d_name[256];
>> -};
>> -
>> -typedef struct dir {
>> -     struct device_d *dev;
>> -     struct fs_driver_d *fsdrv;
>> -     struct node_d *node;
>> -     struct dirent d;
>> -     void *priv; /* private data for the fs driver */
>> -} DIR;
>> +#include <dirent.h>
>>
>>  typedef struct filep {
>>       struct device_d *dev; /* The device this FILE belongs to              */
>> @@ -133,10 +123,6 @@ int rmdir (const char *pathname);
>>  const char *getcwd(void);
>>  int chdir(const char *pathname);
>>
>> -DIR *opendir(const char *pathname);
>> -struct dirent *readdir(DIR *dir);
>> -int closedir(DIR *dir);
>> -
>>  int symlink(const char *pathname, const char *newpath);
>>  int readlink(const char *path, char *buf, size_t bufsiz);
>>
>> diff --git a/lib/glob.c b/lib/glob.c
>> index 1b0137b..7a522a9 100644
>> --- a/lib/glob.c
>> +++ b/lib/glob.c
>> @@ -17,7 +17,7 @@ Cambridge, MA 02139, USA.  */
>>
>>  #include <common.h>
>>  #include <errno.h>
>> -#include <fs.h>
>> +#include <dirent.h>
>>  #include <linux/stat.h>
>>  #include <malloc.h>
>>  #include <xfuncs.h>
>> diff --git a/lib/recursive_action.c b/lib/recursive_action.c
>> index 345d3db..06e60b8 100644
>> --- a/lib/recursive_action.c
>> +++ b/lib/recursive_action.c
>> @@ -9,7 +9,7 @@
>>  #ifdef __BAREBOX__
>>
>>  #include <common.h>
>> -#include <fs.h>
>> +#include <dirent.h>
>>  #include <linux/stat.h>
>>  #include <malloc.h>
>>  #include <libbb.h>
>> --
>> 1.8.3
>>
>>
>> _______________________________________________
>> barebox mailing list
>> barebox at lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/barebox
>>
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



-- 
--
Masaki Muranaka
Monami-ya LLC, Japan.


From monaka at monami-ya.jp  Mon Jun  3 03:46:33 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Mon,  3 Jun 2013 16:46:33 +0900
Subject: [PATCH] Fix typo.
Message-ID: <1370245593-68520-1-git-send-email-monaka@monami-ya.jp>

This fix is harmless and obvious.

Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
---
 include/stdio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/stdio.h b/include/stdio.h
index 5c091a8..0eacdfc 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -70,7 +70,7 @@ static inline int ctrlc (void)
 {
 	return 0;
 }
-#endif /* ARCH_HAS_CTRC */
+#endif /* ARCH_HAS_CTRLC */
 
 #endif
 
-- 
1.8.3



From antonynpavlov at gmail.com  Mon Jun  3 03:46:25 2013
From: antonynpavlov at gmail.com (antonynpavlov at gmail.com)
Date: Mon, 3 Jun 2013 11:46:25 +0400
Subject: [PATCH 3/6] MIPS: rzx50: pbl: use debug_ll
In-Reply-To: <20130603073132.GB26150@pengutronix.de>
References: <1370073169-29009-1-git-send-email-antonynpavlov@gmail.com>
 <1370073169-29009-4-git-send-email-antonynpavlov@gmail.com>
 <20130603073132.GB26150@pengutronix.de>
Message-ID: <20130603114625.775db202a34aabcd581ff461@gmail.com>

On Mon, 3 Jun 2013 09:31:32 +0200
Sascha Hauer <s.hauer at pengutronix.de> wrote:

> On Sat, Jun 01, 2013 at 11:52:46AM +0400, Antony Pavlov wrote:
> > Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> > ---
> >  arch/mips/boards/rzx50/include/board/board_pbl_start.h |    6 ++++++
> >  arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h  |    4 ++++
> >  2 files changed, 10 insertions(+)
> > 
> > diff --git a/arch/mips/boards/rzx50/include/board/board_pbl_start.h b/arch/mips/boards/rzx50/include/board/board_pbl_start.h
> > index cba3e7f..f71641a 100644
> > --- a/arch/mips/boards/rzx50/include/board/board_pbl_start.h
> > +++ b/arch/mips/boards/rzx50/include/board/board_pbl_start.h
> > @@ -18,6 +18,7 @@
> >   */
> >  
> >  #include <asm/pbl_macros.h>
> > +#include <mach/debug_ll.h>
> >  
> >  	.macro	board_pbl_start
> >  	.set	push
> > @@ -28,6 +29,11 @@
> >  	/* CPU/SoC specific setup ... */
> >  	/* ... absent */
> >  
> > +	debug_ll_ns16550_init
> > +
> > +	debug_ll_ns16550_outc '.'
> > +	debug_ll_ns16550_outnl
> > +
> >  	copy_to_link_location	pbl_start
> 
> I had to drop this series beginning from this patch as it breaks
> bisectibility. There seem to be some C stuff leaking in to the
> assembler.

Yes, I have moved the similar C and asm stuff to one place.

> I tried to fix this myself but I wasn't really sure what to
> to. Could you update this based on current master?

Hmm, I used the 'next' branch as the base for this patches.

I'll update the patches in a few hours.

--?
Best regards,
? Antony Pavlov


From monaka at monami-ya.jp  Mon Jun  3 03:55:29 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Mon, 3 Jun 2013 16:55:29 +0900
Subject: [PATCH 1/3] Remove unnesessory malloc.h inclusions.
In-Reply-To: <20130603072427.GW32299@pengutronix.de>
References: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>
 <20130603072427.GW32299@pengutronix.de>
Message-ID: <CAJBvFxN8nu2CkYMz-y4YJoKMQqu9y9LvkPXMg2Lgpm==7cv5Rw@mail.gmail.com>

Hello Sascha,

Opps sorry. I'll revert includes that causes warnings.

2013/6/3 Sascha Hauer <s.hauer at pengutronix.de>:
> On Sun, Jun 02, 2013 at 11:53:47PM +0900, Masaki Muranaka wrote:
>> ---
>> diff --git a/common/resource.c b/common/resource.c
>> index 5795e79..954357e 100644
>> --- a/common/resource.c
>> +++ b/common/resource.c
>> @@ -16,7 +16,6 @@
>>   * GNU General Public License for more details.
>>   */
>>  #include <common.h>
>> -#include <malloc.h>
>>  #include <errno.h>
>>  #include <init.h>
>>  #include <linux/ioport.h>
>
> Applying this patch leads to several compiler warnings:
>
> common/resource.c: In function 'release_region':
> common/resource.c:105:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
> commands/readline.c: In function 'do_readline':
> commands/readline.c:33:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
> commands/time.c: In function 'do_time':
> commands/time.c:41:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
> commands/oftree.c: In function 'do_oftree':
> commands/oftree.c:197:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
> commands/readlink.c: In function 'do_readlink':
> commands/readlink.c:58:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
> commands/global.c: In function 'globalvar_set':
> commands/global.c:34:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
>
> So indeed we do not use malloc in these files, but we still use free.
> I think you would have to replace the includes with #include <stdlib.h>
> rather than removing them completely.
>
> Sascha
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



--
--
Masaki Muranaka
Monami-ya LLC, Japan.


From monaka at monami-ya.jp  Mon Jun  3 04:02:53 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Mon, 3 Jun 2013 17:02:53 +0900
Subject: [PATCH 2/3] Refactor malloc.h.
In-Reply-To: <20130603072604.GX32299@pengutronix.de>
References: <1370184829-66576-1-git-send-email-monaka@monami-ya.com>
 <1370184829-66576-2-git-send-email-monaka@monami-ya.com>
 <20130603072604.GX32299@pengutronix.de>
Message-ID: <CAJBvFxPc5-O9FL0VsM=LfzdOn4wCyZ89zD+aLJoAa9=86x5kRQ@mail.gmail.com>

Hello,

My wish is to use POSIX/ISO-C-hosted way in commands/ and lib/
They are similar to user-land in Unix.

But I'm not sure if it's better replacing all malloc.h to stdlib.h.
common/, fs/ and some places are equivalent to kernel inside.
There are not always required to confirm to POSIX/ISO-C-hosted.



2013/6/3 Sascha Hauer <s.hauer at pengutronix.de>:
> On Sun, Jun 02, 2013 at 11:53:48PM +0900, Masaki Muranaka wrote:
>>  Some functions should be defined in stdlib.h or unistd.h.
>> ---
>>  include/malloc.h       |  8 +++-----
>>  include/malloc_isoc.h  | 11 +++++++++++
>>  include/malloc_posix.h |  8 ++++++++
>>  include/stdlib.h       |  1 +
>>  include/unistd.h       |  6 ++++++
>>  5 files changed, 29 insertions(+), 5 deletions(-)
>>  create mode 100644 include/malloc_isoc.h
>>  create mode 100644 include/malloc_posix.h
>>  create mode 100644 include/unistd.h
>>
>> diff --git a/include/malloc.h b/include/malloc.h
>> index 7b9b062..9554597 100644
>> --- a/include/malloc.h
>> +++ b/include/malloc.h
>> @@ -5,20 +5,18 @@
>>
>>  /* Public routines */
>>
>> -void* malloc(size_t);
>> -void free(void*);
>> -void* realloc(void*, size_t);
>> +#include <malloc_isoc.h>
>> +#include <malloc_posix.h>
>> +
>>  void* memalign(size_t, size_t);
>>  void* vallocc(size_t);
>>  void* pvalloc(size_t);
>> -void* calloc(size_t, size_t);
>>  void cfree(void*);
>>  int malloc_trim(size_t);
>>  size_t malloc_usable_size(void*);
>>  void malloc_stats(void);
>>  int mallopt(int, int);
>>  struct mallinfo mallinfo(void);
>> -void *sbrk(ptrdiff_t increment);
>
> Wouldn't it be nicer to move the prototypes to unistd.h / stdlib.h
> instead of adding new files?
>
> Sascha
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



-- 
--
Masaki Muranaka
Monami-ya LLC, Japan.


From s.hauer at pengutronix.de  Mon Jun  3 04:08:00 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 3 Jun 2013 10:08:00 +0200
Subject: [PATCH] Fix typo.
In-Reply-To: <1370245593-68520-1-git-send-email-monaka@monami-ya.jp>
References: <1370245593-68520-1-git-send-email-monaka@monami-ya.jp>
Message-ID: <20130603080800.GD32299@pengutronix.de>

On Mon, Jun 03, 2013 at 04:46:33PM +0900, Masaki Muranaka wrote:
> This fix is harmless and obvious.
> 
> Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>

Applied, thanks

Sascha

> ---
>  include/stdio.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/stdio.h b/include/stdio.h
> index 5c091a8..0eacdfc 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -70,7 +70,7 @@ static inline int ctrlc (void)
>  {
>  	return 0;
>  }
> -#endif /* ARCH_HAS_CTRC */
> +#endif /* ARCH_HAS_CTRLC */
>  
>  #endif
>  
> -- 
> 1.8.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From renaud.barbier at ge.com  Mon Jun  3 05:31:50 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Mon, 03 Jun 2013 10:31:50 +0100
Subject: [PATCH] gianfar: prevent resource conflict
In-Reply-To: <20130601092018.GO32299@pengutronix.de>
References: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
 <20130601092018.GO32299@pengutronix.de>
Message-ID: <51AC6286.5030001@ge.com>


>> ---
>>   drivers/net/gianfar.c |   19 ++++++++++++++++++-
>>   1 files changed, 18 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
>> index 96055bd..79113a8 100644
>> --- a/drivers/net/gianfar.c
>> +++ b/drivers/net/gianfar.c
>> @@ -28,6 +28,8 @@
>>   #define RX_BUF_CNT 	PKTBUFSRX
>>   #define BUF_ALIGN	8
>>
>> +static void __iomem *phyregs;
>> +
>>   /*
>>    * Initialize required registers to appropriate values, zeroing
>>    * those we don't care about (unless zero is bad, in which case,
>> @@ -481,8 +483,23 @@ static int gfar_probe(struct device_d *dev)
>>   	edev = &priv->edev;
>>
>>   	priv->regs = dev_request_mem_region(dev, 0);
>> -	priv->phyregs = dev_request_mem_region(dev, 1);
>> +	if (priv->regs == NULL)
>> +		priv->regs = phyregs;
>
> the first resource is for the ethernet registers and no phy registers,
> right?

Indeed

>
>> +
>> +	if (phyregs == NULL) {
>> +		phyregs = dev_request_mem_region(dev, 1);
>> +		if (phyregs == NULL)
>> +			phyregs = priv->regs;
>> +	}
>> +	priv->phyregs = phyregs;
>> +
>>   	priv->phyregs_sgmii = dev_request_mem_region(dev, 2);
>> +	if (priv->phyregs_sgmii == NULL) {
>> +		if (IS_ENABLED(CONFIG_TSECV2))
>> +			priv->phyregs_sgmii = priv->phyregs;
>> +		else
>> +			priv->phyregs_sgmii = priv->regs;
>> +	}
>
> I think you should really register the mdio buses as separate devices
> since it's the mdio buses that are shared between the different
> instances, not the registers. The following may be a starting point
> (untested)
>

Thanks.



From s.hauer at pengutronix.de  Mon Jun  3 06:49:38 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon,  3 Jun 2013 12:49:38 +0200
Subject: [PATCH 2/4] mci: Print more info
In-Reply-To: <1370256580-3113-1-git-send-email-s.hauer@pengutronix.de>
References: <1370256580-3113-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370256580-3113-2-git-send-email-s.hauer@pengutronix.de>

In devinfo for the card also print:

- capabilities for host and card
- current bus width
- current clock

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index fc921e5..86600ec 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1366,6 +1366,16 @@ static unsigned extract_mtd_year(struct mci *mci)
 		return UNSTUFF_BITS(mci->cid, 8, 4) + 1997;
 }
 
+static void mci_print_caps(unsigned caps)
+{
+	printf("  capabilities: %s%s%s%s%s\n",
+		caps & MMC_CAP_4_BIT_DATA ? "4bit " : "",
+		caps & MMC_CAP_8_BIT_DATA ? "8bit " : "",
+		caps & MMC_CAP_SD_HIGHSPEED ? "sd-hs " : "",
+		caps & MMC_CAP_MMC_HIGHSPEED ? "mmc-hs " : "",
+		caps & MMC_CAP_MMC_HIGHSPEED_52MHZ ? "mmc-52MHz " : "");
+}
+
 /**
  * Output some valuable information when the user runs 'devinfo' on an MCI device
  * @param mci MCI device instance
@@ -1373,13 +1383,28 @@ static unsigned extract_mtd_year(struct mci *mci)
 static void mci_info(struct device_d *dev)
 {
 	struct mci *mci = container_of(dev, struct mci, dev);
+	struct mci_host *host = mci->host;
+	int bw;
 
 	if (mci->ready_for_use == 0) {
 		printf(" No information available:\n  MCI card not probed yet\n");
 		return;
 	}
 
-	printf(" Card:\n");
+	printf("Host information:\n");
+	printf("  current clock: %d\n", host->clock);
+
+	if (host->bus_width == MMC_BUS_WIDTH_8)
+		bw = 8;
+	else if (host->bus_width == MMC_BUS_WIDTH_4)
+		bw = 4;
+	else
+		bw = 1;
+
+	printf("  current buswidth: %d\n", bw);
+	mci_print_caps(host->host_caps);
+
+	printf("Card information:\n");
 	if (mci->version < SD_VERSION_SD) {
 		printf("  Attached is a MultiMediaCard (Version: %u.%u)\n",
 			(mci->version >> 4) & 0xf, mci->version & 0xf);
@@ -1396,6 +1421,7 @@ static void mci_info(struct device_d *dev)
 	printf("   CSD: %08X-%08X-%08X-%08X\n", mci->csd[0], mci->csd[1],
 		mci->csd[2], mci->csd[3]);
 	printf("  Max. transfer speed: %u Hz\n", mci->tran_speed);
+	mci_print_caps(mci->card_caps);
 	printf("  Manufacturer ID: %02X\n", extract_mid(mci));
 	printf("  OEM/Application ID: %04X\n", extract_oid(mci));
 	printf("  Product name: '%c%c%c%c%c'\n", mci->cid[0] & 0xff,
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Mon Jun  3 06:49:39 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon,  3 Jun 2013 12:49:39 +0200
Subject: [PATCH 3/4] mci: add mci_caps function
In-Reply-To: <1370256580-3113-1-git-send-email-s.hauer@pengutronix.de>
References: <1370256580-3113-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370256580-3113-3-git-send-email-s.hauer@pengutronix.de>

To let the card caps be card caps and not the intersection between
card caps and host caps.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 86600ec..74aab91 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -66,6 +66,11 @@
  * - Transcend SDHC, 8 GiB (Class 6)
  */
 
+static inline unsigned mci_caps(struct mci *mci)
+{
+	return mci->card_caps & mci->host->host_caps;
+}
+
 /**
  * Call the MMC/SD instance driver to run the command on the MMC/SD card
  * @param mci MCI instance
@@ -900,7 +905,7 @@ static int mci_startup_sd(struct mci *mci)
 	struct mci_cmd cmd;
 	int err;
 
-	if (mci->card_caps & MMC_CAP_4_BIT_DATA) {
+	if (mci_caps(mci) & MMC_CAP_4_BIT_DATA) {
 		dev_dbg(&mci->dev, "Prepare for bus width change\n");
 		mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
 		err = mci_send_cmd(mci, &cmd, NULL);
@@ -920,7 +925,7 @@ static int mci_startup_sd(struct mci *mci)
 		mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
 	}
 	/* if possible, speed up the transfer */
-	if (mci->card_caps & MMC_CAP_SD_HIGHSPEED)
+	if (mci_caps(mci) & MMC_CAP_SD_HIGHSPEED)
 		mci_set_clock(mci, 50000000);
 	else
 		mci_set_clock(mci, 25000000);
@@ -943,7 +948,7 @@ static int mci_startup_mmc(struct mci *mci)
 	};
 
 	/* if possible, speed up the transfer */
-	if (mci->card_caps & MMC_CAP_MMC_HIGHSPEED) {
+	if (mci_caps(mci) & MMC_CAP_MMC_HIGHSPEED) {
 		if (mci->card_caps & MMC_CAP_MMC_HIGHSPEED_52MHZ)
 			mci_set_clock(mci, 52000000);
 		else
@@ -993,7 +998,6 @@ static int mci_startup_mmc(struct mci *mci)
  */
 static int mci_startup(struct mci *mci)
 {
-	struct mci_host *host = mci->host;
 	struct mci_cmd cmd;
 	int err;
 
@@ -1098,9 +1102,6 @@ static int mci_startup(struct mci *mci)
 
 	mci_extract_card_capacity_from_csd(mci);
 
-	/* Restrict card's capabilities by what the host can do */
-	mci->card_caps &= host->host_caps;
-
 	if (IS_SD(mci))
 		err = mci_startup_sd(mci);
 	else
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Mon Jun  3 06:49:40 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon,  3 Jun 2013 12:49:40 +0200
Subject: [PATCH 4/4] mci: Use tran_speed field to fix highspeed MMC card clock
In-Reply-To: <1370256580-3113-1-git-send-email-s.hauer@pengutronix.de>
References: <1370256580-3113-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370256580-3113-4-git-send-email-s.hauer@pengutronix.de>

The tran_speed field as decoded from csd is valid in most cases,
so use it to determine the maximum clock we can support. It is
not valid though for MMC highspeed cards, in this case the
csd contains invalid values and we have to set tran_speed explicitly
to the maximum speed. As the values passed into mci_set_clock are
now based on tran_speed we no longer have to limit the rate to
tran_speed in mci_set_clock.

The (intended) effect of this patch is that highspeed MMC cards are
no longer limited to non highspeed rates.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mci-core.c | 19 ++++++-------------
 include/mci.h          |  2 +-
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 74aab91..6fc9805 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -669,10 +669,6 @@ static void mci_set_clock(struct mci *mci, unsigned clock)
 	if (clock < host->f_min)
 		clock = host->f_min;
 
-	/* check against the limit at the card's side */
-	if (mci->tran_speed != 0 && clock > mci->tran_speed)
-		clock = mci->tran_speed;
-
 	host->clock = clock;	/* the new target frequency */
 	mci_set_ios(mci);
 }
@@ -924,11 +920,8 @@ static int mci_startup_sd(struct mci *mci)
 		}
 		mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
 	}
-	/* if possible, speed up the transfer */
-	if (mci_caps(mci) & MMC_CAP_SD_HIGHSPEED)
-		mci_set_clock(mci, 50000000);
-	else
-		mci_set_clock(mci, 25000000);
+
+	mci_set_clock(mci, mci->tran_speed);
 
 	return 0;
 }
@@ -950,13 +943,13 @@ static int mci_startup_mmc(struct mci *mci)
 	/* if possible, speed up the transfer */
 	if (mci_caps(mci) & MMC_CAP_MMC_HIGHSPEED) {
 		if (mci->card_caps & MMC_CAP_MMC_HIGHSPEED_52MHZ)
-			mci_set_clock(mci, 52000000);
+			mci->tran_speed = 52000000;
 		else
-			mci_set_clock(mci, 26000000);
-	} else {
-		mci_set_clock(mci, 20000000);
+			mci->tran_speed = 26000000;
 	}
 
+	mci_set_clock(mci, mci->tran_speed);
+
 	/*
 	 * Unlike SD, MMC cards dont have a configuration register to notify
 	 * supported bus width. So bus test command should be run to identify
diff --git a/include/mci.h b/include/mci.h
index 3989f46..1ae27f0 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -342,7 +342,7 @@ struct mci {
 	unsigned csd[4];	/**< card's "card specific data register" */
 	unsigned cid[4];	/**< card's "card identification register" */
 	unsigned short rca;	/* FIXME */
-	unsigned tran_speed;	/**< not yet used */
+	unsigned tran_speed;	/**< Maximum transfer speed */
 	/** currently used data block length for read accesses */
 	unsigned read_bl_len;
 	/** currently used data block length for write accesses */
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Mon Jun  3 06:49:37 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon,  3 Jun 2013 12:49:37 +0200
Subject: [PATCH 1/4] mci: rename capabilities flags
Message-ID: <1370256580-3113-1-git-send-email-s.hauer@pengutronix.de>

Use MMC_CAP_ names instead of MMC_MODE_. This makes it more
clear that these are capabilities of host/card and do not refer
to the current mode. These are in line with the Linux Kernel
except for MMC_CAP_MMC_HIGHSPEED_52MHZ which could be fixed
later.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/ccxmx51/ccxmx51js.c                |  4 ++--
 arch/arm/boards/chumby_falconwing/falconwing.c     |  2 +-
 arch/arm/boards/crystalfontz-cfa10036/cfa10036.c   |  2 +-
 arch/arm/boards/dmo-mx6-realq7/board.c             |  2 +-
 arch/arm/boards/freescale-mx23-evk/mx23-evk.c      |  2 +-
 arch/arm/boards/freescale-mx28-evk/mx28-evk.c      |  2 +-
 arch/arm/boards/friendlyarm-mini2440/mini2440.c    |  2 +-
 arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c |  2 +-
 arch/arm/boards/karo-tx28/tx28-stk5.c              |  2 +-
 arch/arm/boards/tqma53/board.c                     |  2 +-
 arch/arm/mach-imx/include/mach/esdhc.h             |  2 +-
 drivers/mci/atmel_mci.c                            |  6 +++---
 drivers/mci/imx-esdhc.c                            |  4 ++--
 drivers/mci/imx.c                                  |  2 +-
 drivers/mci/mci-bcm2835.c                          |  3 ++-
 drivers/mci/mci-core.c                             | 24 +++++++++++-----------
 drivers/mci/omap_hsmmc.c                           |  3 ++-
 drivers/mci/pxamci.c                               |  2 +-
 include/mci.h                                      | 11 +++++-----
 19 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/arch/arm/boards/ccxmx51/ccxmx51js.c b/arch/arm/boards/ccxmx51/ccxmx51js.c
index ae31caf..a8917aa 100644
--- a/arch/arm/boards/ccxmx51/ccxmx51js.c
+++ b/arch/arm/boards/ccxmx51/ccxmx51js.c
@@ -69,13 +69,13 @@ static iomux_v3_cfg_t ccxmx51js_pads[] = {
 static struct esdhc_platform_data sdhc1_pdata = {
 	.cd_type	= ESDHC_CD_NONE,
 	.wp_type	= ESDHC_WP_NONE,
-	.caps		= MMC_MODE_4BIT,
+	.caps		= MMC_CAP_4_BIT_DATA,
 };
 
 static struct esdhc_platform_data sdhc3_pdata = {
 	.cd_type	= ESDHC_CD_NONE,
 	.wp_type	= ESDHC_WP_NONE,
-	.caps		= MMC_MODE_4BIT | MMC_MODE_8BIT,
+	.caps		= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
 };
 
 static struct imxusb_platformdata ccxmx51js_usbhost1_pdata = {
diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c b/arch/arm/boards/chumby_falconwing/falconwing.c
index 720fe32..cb934ee 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -32,7 +32,7 @@
 #include <mach/usb.h>
 
 static struct mxs_mci_platform_data mci_pdata = {
-	.caps = MMC_MODE_4BIT | MMC_MODE_HS | MMC_MODE_HS_52MHz,
+	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED,
 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,	/* fixed to 3.3 V */
 };
 
diff --git a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
index a37b089..9054afa 100644
--- a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
+++ b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
@@ -72,7 +72,7 @@ static const uint32_t cfa10036_pads[] = {
 };
 
 static struct mxs_mci_platform_data mci_pdata = {
-	.caps = MMC_MODE_8BIT,
+	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,	/* fixed to 3.3 V */
 	.f_min = 400 * 1000,
 	.f_max = 25000000,
diff --git a/arch/arm/boards/dmo-mx6-realq7/board.c b/arch/arm/boards/dmo-mx6-realq7/board.c
index 35ef72c..6ea95b9 100644
--- a/arch/arm/boards/dmo-mx6-realq7/board.c
+++ b/arch/arm/boards/dmo-mx6-realq7/board.c
@@ -312,7 +312,7 @@ static const struct spi_board_info realq7_spi_board_info[] = {
 
 static struct esdhc_platform_data realq7_emmc_data = {
 	.cd_type = ESDHC_CD_PERMANENT,
-	.caps = MMC_MODE_8BIT,
+	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
 	.devname = "emmc",
 };
 
diff --git a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
index 76377b1..dddefb2 100644
--- a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
+++ b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
@@ -28,7 +28,7 @@
 #include <mach/usb.h>
 
 static struct mxs_mci_platform_data mci_pdata = {
-	.caps = MMC_MODE_4BIT | MMC_MODE_HS | MMC_MODE_HS_52MHz,
+	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED,
 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,	/* fixed to 3.3 V */
 	.f_min = 400000,
 };
diff --git a/arch/arm/boards/freescale-mx28-evk/mx28-evk.c b/arch/arm/boards/freescale-mx28-evk/mx28-evk.c
index 364b6ee..bb2dbcc 100644
--- a/arch/arm/boards/freescale-mx28-evk/mx28-evk.c
+++ b/arch/arm/boards/freescale-mx28-evk/mx28-evk.c
@@ -136,7 +136,7 @@ static const uint32_t mx28evk_pads[] = {
 };
 
 static struct mxs_mci_platform_data mci_pdata = {
-	.caps = MMC_MODE_8BIT,
+	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,	/* fixed to 3.3 V */
 	.f_min = 400 * 1000,
 	.f_max = 25000000,
diff --git a/arch/arm/boards/friendlyarm-mini2440/mini2440.c b/arch/arm/boards/friendlyarm-mini2440/mini2440.c
index c4b97a2..de07bda 100644
--- a/arch/arm/boards/friendlyarm-mini2440/mini2440.c
+++ b/arch/arm/boards/friendlyarm-mini2440/mini2440.c
@@ -62,7 +62,7 @@ static struct dm9000_platform_data dm9000_data = {
 };
 
 static struct s3c_mci_platform_data mci_data = {
-	.caps = MMC_MODE_4BIT | MMC_MODE_HS | MMC_MODE_HS_52MHz,
+	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED,
 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
 	.gpio_detect = 232,	/* GPG8_GPIO */
 	.detect_invert = 0,
diff --git a/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c b/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c
index 9620e85..116a9ea 100644
--- a/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c
+++ b/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c
@@ -37,7 +37,7 @@
 #include <mach/mci.h>
 
 static struct mxs_mci_platform_data mci_pdata = {
-	.caps = MMC_MODE_4BIT | MMC_MODE_HS | MMC_MODE_HS_52MHz,
+	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED,
 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,	/* fixed to 3.3 V */
 	.f_min = 400000,
 };
diff --git a/arch/arm/boards/karo-tx28/tx28-stk5.c b/arch/arm/boards/karo-tx28/tx28-stk5.c
index a0109d6..8ee8ac2 100644
--- a/arch/arm/boards/karo-tx28/tx28-stk5.c
+++ b/arch/arm/boards/karo-tx28/tx28-stk5.c
@@ -30,7 +30,7 @@
 #include <mach/ocotp.h>
 
 static struct mxs_mci_platform_data mci_pdata = {
-	.caps = MMC_MODE_4BIT,
+	.caps = MMC_CAP_4_BIT_DATA,
 	.voltages = MMC_VDD_32_33 | MMC_VDD_33_34,	/* fixed to 3.3 V */
 	.f_min = 400 * 1000,
 	.f_max = 25000000,
diff --git a/arch/arm/boards/tqma53/board.c b/arch/arm/boards/tqma53/board.c
index 0054a7e..19ad37e 100644
--- a/arch/arm/boards/tqma53/board.c
+++ b/arch/arm/boards/tqma53/board.c
@@ -220,7 +220,7 @@ static struct esdhc_platform_data tqma53_sd2_data = {
 static struct esdhc_platform_data tqma53_sd3_data = {
 	.cd_type = ESDHC_CD_PERMANENT,
 	.wp_type = ESDHC_WP_NONE,
-	.caps = MMC_MODE_8BIT | MMC_MODE_4BIT,
+	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
 };
 
 static int tqma53_devices_init(void)
diff --git a/arch/arm/mach-imx/include/mach/esdhc.h b/arch/arm/mach-imx/include/mach/esdhc.h
index 06863c8..add1691 100644
--- a/arch/arm/mach-imx/include/mach/esdhc.h
+++ b/arch/arm/mach-imx/include/mach/esdhc.h
@@ -32,7 +32,7 @@ enum cd_types {
  * @cd_gpio:	gpio for card_detect interrupt
  * @wp_type:	type of write_protect method (see wp_types enum above)
  * @cd_type:	type of card_detect method (see cd_types enum above)
- * @caps:	supported bus width capabilities (MMC_MODE_4BIT | MMC_MODE_8BIT)
+ * @caps:	supported bus width capabilities (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)
  */
 
 struct esdhc_platform_data {
diff --git a/drivers/mci/atmel_mci.c b/drivers/mci/atmel_mci.c
index b5873f9..dca3813 100644
--- a/drivers/mci/atmel_mci.c
+++ b/drivers/mci/atmel_mci.c
@@ -565,9 +565,9 @@ static int atmci_probe(struct device_d *hw_dev)
 	host->mci.hw_dev = hw_dev;
 
 	if (pd->bus_width >= 4)
-		host->mci.host_caps |= MMC_MODE_4BIT;
+		host->mci.host_caps |= MMC_CAP_4_BIT_DATA;
 	if (pd->bus_width == 8)
-		host->mci.host_caps |= MMC_MODE_8BIT;
+		host->mci.host_caps |= MMC_CAP_8_BIT_DATA;
 	host->slot_b = pd->slot_b;
 
 	host->regs = dev_request_mem_region(hw_dev, 0);
@@ -594,7 +594,7 @@ static int atmci_probe(struct device_d *hw_dev)
 	atmci_get_cap(host);
 
 	if (host->caps.has_highspeed)
-		host->mci.host_caps |= MMC_MODE_HS;
+		host->mci.host_caps |= MMC_CAP_SD_HIGHSPEED;
 
 	if (host->slot_b)
 		host->sdc_reg = ATMCI_SDCSEL_SLOT_B;
diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index 8053b79..8cf3e64 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -540,7 +540,7 @@ static int fsl_esdhc_probe(struct device_d *dev)
 	if (pdata && pdata->caps)
 		mci->host_caps = pdata->caps;
 	else
-		mci->host_caps = MMC_MODE_4BIT;
+		mci->host_caps = MMC_CAP_4_BIT_DATA;
 
 	if (pdata && pdata->devname) {
 		mci->devname = pdata->devname;
@@ -551,7 +551,7 @@ static int fsl_esdhc_probe(struct device_d *dev)
 	}
 
 	if (caps & ESDHC_HOSTCAPBLT_HSS)
-		mci->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
+		mci->host_caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED;
 
 	host->mci.send_cmd = esdhc_send_cmd;
 	host->mci.set_ios = esdhc_set_ios;
diff --git a/drivers/mci/imx.c b/drivers/mci/imx.c
index 2bf48eb..aea78c7 100644
--- a/drivers/mci/imx.c
+++ b/drivers/mci/imx.c
@@ -504,7 +504,7 @@ static int mxcmci_probe(struct device_d *dev)
 	host->mci.send_cmd = mxcmci_request;
 	host->mci.set_ios = mxcmci_set_ios;
 	host->mci.init = mxcmci_init;
-	host->mci.host_caps = MMC_MODE_4BIT;
+	host->mci.host_caps = MMC_CAP_4_BIT_DATA;
 	host->mci.hw_dev = dev;
 
 	host->base = dev_request_mem_region(dev, 0);
diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c
index b76f134..abd38a3 100644
--- a/drivers/mci/mci-bcm2835.c
+++ b/drivers/mci/mci-bcm2835.c
@@ -553,7 +553,8 @@ static int bcm2835_mci_probe(struct device_d *hw_dev)
 		return -EBUSY;
 	}
 
-	host->mci.host_caps |= MMC_MODE_4BIT | MMC_MODE_HS | MMC_MODE_HS_52MHz;
+	host->mci.host_caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED |
+		MMC_CAP_MMC_HIGHSPEED;
 
 	host->mci.voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
 
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index ce568df..fc921e5 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -434,7 +434,7 @@ static int mmc_change_freq(struct mci *mci)
 	if (mci->version < MMC_VERSION_4)
 		return 0;
 
-	mci->card_caps |= MMC_MODE_4BIT;
+	mci->card_caps |= MMC_CAP_4_BIT_DATA;
 
 	err = mci_send_ext_csd(mci, mci->ext_csd);
 	if (err) {
@@ -467,9 +467,9 @@ static int mmc_change_freq(struct mci *mci)
 
 	/* High Speed is set, there are two types: 52MHz and 26MHz */
 	if (cardtype & EXT_CSD_CARD_TYPE_52)
-		mci->card_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
+		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED_52MHZ | MMC_CAP_MMC_HIGHSPEED;
 	else
-		mci->card_caps |= MMC_MODE_HS;
+		mci->card_caps |= MMC_CAP_MMC_HIGHSPEED;
 
 	if (IS_ENABLED(CONFIG_MCI_MMC_BOOT_PARTITIONS) &&
 			mci->ext_csd[EXT_CSD_REV] >= 3 && mci->ext_csd[EXT_CSD_BOOT_MULT]) {
@@ -615,7 +615,7 @@ retry_scr:
 	}
 
 	if (mci->scr[0] & SD_DATA_4BIT)
-		mci->card_caps |= MMC_MODE_4BIT;
+		mci->card_caps |= MMC_CAP_4_BIT_DATA;
 
 	/* If high-speed isn't supported, we return */
 	if (!(__be32_to_cpu(switch_status[3]) & SD_HIGHSPEED_SUPPORTED))
@@ -628,7 +628,7 @@ retry_scr:
 	}
 
 	if ((__be32_to_cpu(switch_status[4]) & 0x0f000000) == 0x01000000)
-		mci->card_caps |= MMC_MODE_HS;
+		mci->card_caps |= MMC_CAP_SD_HIGHSPEED;
 
 	return 0;
 }
@@ -900,7 +900,7 @@ static int mci_startup_sd(struct mci *mci)
 	struct mci_cmd cmd;
 	int err;
 
-	if (mci->card_caps & MMC_MODE_4BIT) {
+	if (mci->card_caps & MMC_CAP_4_BIT_DATA) {
 		dev_dbg(&mci->dev, "Prepare for bus width change\n");
 		mci_setup_cmd(&cmd, MMC_CMD_APP_CMD, mci->rca << 16, MMC_RSP_R1);
 		err = mci_send_cmd(mci, &cmd, NULL);
@@ -920,7 +920,7 @@ static int mci_startup_sd(struct mci *mci)
 		mci_set_bus_width(mci, MMC_BUS_WIDTH_4);
 	}
 	/* if possible, speed up the transfer */
-	if (mci->card_caps & MMC_MODE_HS)
+	if (mci->card_caps & MMC_CAP_SD_HIGHSPEED)
 		mci_set_clock(mci, 50000000);
 	else
 		mci_set_clock(mci, 25000000);
@@ -943,8 +943,8 @@ static int mci_startup_mmc(struct mci *mci)
 	};
 
 	/* if possible, speed up the transfer */
-	if (mci->card_caps & MMC_MODE_HS) {
-		if (mci->card_caps & MMC_MODE_HS_52MHz)
+	if (mci->card_caps & MMC_CAP_MMC_HIGHSPEED) {
+		if (mci->card_caps & MMC_CAP_MMC_HIGHSPEED_52MHZ)
 			mci_set_clock(mci, 52000000);
 		else
 			mci_set_clock(mci, 26000000);
@@ -958,7 +958,7 @@ static int mci_startup_mmc(struct mci *mci)
 	 * the supported bus width or compare the ext csd values of current
 	 * bus width and ext csd values of 1 bit mode read earlier.
 	 */
-	if (host->host_caps & MMC_MODE_8BIT)
+	if (host->host_caps & MMC_CAP_8_BIT_DATA)
 		idx = 1;
 
 	for (; idx >= 0; idx--) {
@@ -1694,10 +1694,10 @@ void mci_of_parse(struct mci_host *host)
 
 	switch (bus_width) {
 	case 8:
-		host->host_caps |= MMC_MODE_8BIT;
+		host->host_caps |= MMC_CAP_8_BIT_DATA;
 		/* Hosts capable of 8-bit transfers can also do 4 bits */
 	case 4:
-		host->host_caps |= MMC_MODE_4BIT;
+		host->host_caps |= MMC_CAP_4_BIT_DATA;
 		break;
 	case 1:
 		break;
diff --git a/drivers/mci/omap_hsmmc.c b/drivers/mci/omap_hsmmc.c
index b379c31..62c79e1 100644
--- a/drivers/mci/omap_hsmmc.c
+++ b/drivers/mci/omap_hsmmc.c
@@ -592,7 +592,8 @@ static int omap_mmc_probe(struct device_d *dev)
 	hsmmc->mci.send_cmd = mmc_send_cmd;
 	hsmmc->mci.set_ios = mmc_set_ios;
 	hsmmc->mci.init = mmc_init_setup;
-	hsmmc->mci.host_caps = MMC_MODE_4BIT | MMC_MODE_HS_52MHz | MMC_MODE_HS;
+	hsmmc->mci.host_caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED |
+		MMC_CAP_MMC_HIGHSPEED;
 	hsmmc->mci.hw_dev = dev;
 
 	hsmmc->iobase = dev_request_mem_region(dev, 0);
diff --git a/drivers/mci/pxamci.c b/drivers/mci/pxamci.c
index c1380d1..5ab88b8 100644
--- a/drivers/mci/pxamci.c
+++ b/drivers/mci/pxamci.c
@@ -343,7 +343,7 @@ static int pxamci_probe(struct device_d *dev)
 	host->mci.init = pxamci_init;
 	host->mci.send_cmd = pxamci_request;
 	host->mci.set_ios = pxamci_set_ios;
-	host->mci.host_caps = MMC_MODE_4BIT;
+	host->mci.host_caps = MMC_CAP_4_BIT_DATA;
 	host->mci.hw_dev = dev;
 	host->mci.voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
 
diff --git a/include/mci.h b/include/mci.h
index bca374a..3989f46 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -44,11 +44,12 @@
 #define MMC_VERSION_3		(MMC_VERSION_MMC | 0x30)
 #define MMC_VERSION_4		(MMC_VERSION_MMC | 0x40)
 
-#define MMC_MODE_HS		0x001
-#define MMC_MODE_HS_52MHz	0x010
-#define MMC_CAP_SPI		0x020
-#define MMC_MODE_4BIT		0x100
-#define MMC_MODE_8BIT		0x200
+#define MMC_CAP_SPI			(1 << 0)
+#define MMC_CAP_4_BIT_DATA		(1 << 1)
+#define MMC_CAP_8_BIT_DATA		(1 << 2)
+#define MMC_CAP_SD_HIGHSPEED		(1 << 3)
+#define MMC_CAP_MMC_HIGHSPEED		(1 << 4)
+#define MMC_CAP_MMC_HIGHSPEED_52MHZ	(1 << 5)
 
 #define SD_DATA_4BIT		0x00040000
 
-- 
1.8.2.rc2



From antonynpavlov at gmail.com  Mon Jun  3 06:53:22 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon,  3 Jun 2013 14:53:22 +0400
Subject: [PATCH v2 0/5] MIPS: rework ns16550 debug_ll
Message-ID: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>

This patch series makes possible easely produce
debug output via ns16550-like UART on very early pbl stage.

v2 patch series is based on the 'master' branch
and it does not break bisectibility.

[PATCH v2 1/5] MIPS: rzx50: prepare for new debug_ll
[PATCH v2 2/5] MIPS: malta: prepare for new debug_ll
[PATCH v2 3/5] MIPS: unify ns16550 debug_ll support code
[PATCH v2 4/5] MIPS: rzx50: pbl: use debug_ll
[PATCH v2 5/5] MIPS: rzx50_defconfig: use UART1 for low-level debug


From antonynpavlov at gmail.com  Mon Jun  3 06:53:24 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon,  3 Jun 2013 14:53:24 +0400
Subject: [PATCH v2 2/5] MIPS: malta: prepare for new debug_ll
In-Reply-To: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
References: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370256807-26755-3-git-send-email-antonynpavlov@gmail.com>

Set fake DEBUG_LL_UART_DIVISOR to use <asm/debug_ll_ns16550.h>.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/mach-malta/include/mach/hardware.h |    1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/mach-malta/include/mach/hardware.h b/arch/mips/mach-malta/include/mach/hardware.h
index 5e8e276..8bd814d 100644
--- a/arch/mips/mach-malta/include/mach/hardware.h
+++ b/arch/mips/mach-malta/include/mach/hardware.h
@@ -20,6 +20,7 @@
 
 #define DEBUG_LL_UART_ADDR	0xb00003f8
 #define DEBUG_LL_UART_SHIFT	0
+#define DEBUG_LL_UART_DIVISOR	1	/* no matter for emulated port */
 
 /*
  * Reset register.
-- 
1.7.10.4



From antonynpavlov at gmail.com  Mon Jun  3 06:53:25 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon,  3 Jun 2013 14:53:25 +0400
Subject: [PATCH v2 3/5] MIPS: unify ns16550 debug_ll support code
In-Reply-To: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
References: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370256807-26755-4-git-send-email-antonynpavlov@gmail.com>

This commit moves the C debug_ll code from
the MIPS <debug_ll_ns16550.h> header file to
the MIPS <asm/debug_ll_ns16550.h> header file,
so the C code and the asm code can use the same
register address macros.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/include/asm/debug_ll_ns16550.h      |   15 ++++++++++
 arch/mips/include/debug_ll_ns16550.h          |   37 -------------------------
 arch/mips/mach-malta/include/mach/debug_ll.h  |    2 +-
 arch/mips/mach-xburst/include/mach/debug_ll.h |    2 +-
 4 files changed, 17 insertions(+), 39 deletions(-)
 delete mode 100644 arch/mips/include/debug_ll_ns16550.h

diff --git a/arch/mips/include/asm/debug_ll_ns16550.h b/arch/mips/include/asm/debug_ll_ns16550.h
index 5dd1b39..f00f348 100644
--- a/arch/mips/include/asm/debug_ll_ns16550.h
+++ b/arch/mips/include/asm/debug_ll_ns16550.h
@@ -48,6 +48,20 @@
 
 #define UART_LSR_THRE	0x20	/* Xmit holding register empty */
 
+#ifndef __ASSEMBLY__
+/*
+ * C macros
+ */
+
+#include <asm/io.h>
+
+static __inline__ void PUTC_LL(char ch)
+{
+	while (!(__raw_readb((u8 *)DEBUG_LL_UART_ADDR + UART_LSR) & UART_LSR_THRE))
+		;
+	__raw_writeb(ch, (u8 *)DEBUG_LL_UART_ADDR + UART_THR);
+}
+#else /* __ASSEMBLY__ */
 /*
  * Macros for use in assembly language code
  */
@@ -96,5 +110,6 @@
 	debug_ll_ns16550_outc '\n'
 #endif /* CONFIG_DEBUG_LL */
 .endm
+#endif /* __ASSEMBLY__ */
 
 #endif /* __INCLUDE_MIPS_ASM_DEBUG_LL_NS16550_H__ */
diff --git a/arch/mips/include/debug_ll_ns16550.h b/arch/mips/include/debug_ll_ns16550.h
deleted file mode 100644
index e9c7ecf..0000000
--- a/arch/mips/include/debug_ll_ns16550.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2012 Antony Pavlov <antonynpavlov at gmail.com>
- *
- * This file is part of barebox.
- * 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 version 2
- * as published by the Free Software Foundation.
- *
- * 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.
- *
- */
-
-/** @file
- *  This file contains declaration for early output support
- */
-#ifndef __INCLUDE_ARCH_DEBUG_LL_NS16550_H__
-#define __INCLUDE_ARCH_DEBUG_LL_NS16550_H__
-
-#include <asm/io.h>
-
-#define rbr		(0 << DEBUG_LL_UART_SHIFT)
-#define lsr		(5 << DEBUG_LL_UART_SHIFT)
-
-#define LSR_THRE	0x20	/* Xmit holding register empty */
-
-static __inline__ void PUTC_LL(char ch)
-{
-	while (!(__raw_readb((u8 *)DEBUG_LL_UART_ADDR + lsr) & LSR_THRE));
-	__raw_writeb(ch, (u8 *)DEBUG_LL_UART_ADDR + rbr);
-}
-
-#endif  /* __INCLUDE_ARCH_DEBUG_LL_NS16550_H__ */
diff --git a/arch/mips/mach-malta/include/mach/debug_ll.h b/arch/mips/mach-malta/include/mach/debug_ll.h
index 3a91c93..3e8b01b 100644
--- a/arch/mips/mach-malta/include/mach/debug_ll.h
+++ b/arch/mips/mach-malta/include/mach/debug_ll.h
@@ -23,6 +23,6 @@
 
 #include <mach/hardware.h>
 
-#include <debug_ll_ns16550.h>
+#include <asm/debug_ll_ns16550.h>
 
 #endif  /* __INCLUDE_ARCH_DEBUG_LL_H__ */
diff --git a/arch/mips/mach-xburst/include/mach/debug_ll.h b/arch/mips/mach-xburst/include/mach/debug_ll.h
index f260e65..6c3c980 100644
--- a/arch/mips/mach-xburst/include/mach/debug_ll.h
+++ b/arch/mips/mach-xburst/include/mach/debug_ll.h
@@ -22,6 +22,6 @@
  *  This File contains declaration for early output support
  */
 #include <board/debug_ll.h>
-#include <debug_ll_ns16550.h>
+#include <asm/debug_ll_ns16550.h>
 
 #endif  /* __MACH_XBURST_DEBUG_LL__ */
-- 
1.7.10.4



From antonynpavlov at gmail.com  Mon Jun  3 06:53:26 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon,  3 Jun 2013 14:53:26 +0400
Subject: [PATCH v2 4/5] MIPS: rzx50: pbl: use debug_ll
In-Reply-To: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
References: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370256807-26755-5-git-send-email-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/boards/rzx50/include/board/board_pbl_start.h |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/mips/boards/rzx50/include/board/board_pbl_start.h b/arch/mips/boards/rzx50/include/board/board_pbl_start.h
index cba3e7f..f71641a 100644
--- a/arch/mips/boards/rzx50/include/board/board_pbl_start.h
+++ b/arch/mips/boards/rzx50/include/board/board_pbl_start.h
@@ -18,6 +18,7 @@
  */
 
 #include <asm/pbl_macros.h>
+#include <mach/debug_ll.h>
 
 	.macro	board_pbl_start
 	.set	push
@@ -28,6 +29,11 @@
 	/* CPU/SoC specific setup ... */
 	/* ... absent */
 
+	debug_ll_ns16550_init
+
+	debug_ll_ns16550_outc '.'
+	debug_ll_ns16550_outnl
+
 	copy_to_link_location	pbl_start
 
 	.set	pop
-- 
1.7.10.4



From antonynpavlov at gmail.com  Mon Jun  3 06:53:27 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon,  3 Jun 2013 14:53:27 +0400
Subject: [PATCH v2 5/5] MIPS: rzx50_defconfig: use UART1 for low-level debug
In-Reply-To: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
References: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370256807-26755-6-git-send-email-antonynpavlov@gmail.com>

By default CONFIG_JZ4750D_DEBUG_LL_UART0 is selected.
This can confuse the Ritmix RZX50 user as the board
has only UART1 connected.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/configs/rzx50_defconfig |    1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/mips/configs/rzx50_defconfig b/arch/mips/configs/rzx50_defconfig
index 5d994c7..7b75909 100644
--- a/arch/mips/configs/rzx50_defconfig
+++ b/arch/mips/configs/rzx50_defconfig
@@ -1,4 +1,5 @@
 CONFIG_MACH_MIPS_XBURST=y
+CONFIG_JZ4750D_DEBUG_LL_UART1=y
 CONFIG_PBL_IMAGE=y
 CONFIG_BAUDRATE=57600
 CONFIG_GLOB=y
-- 
1.7.10.4



From antonynpavlov at gmail.com  Mon Jun  3 06:53:23 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon,  3 Jun 2013 14:53:23 +0400
Subject: [PATCH v2 1/5] MIPS: rzx50: prepare for new debug_ll
In-Reply-To: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
References: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1370256807-26755-2-git-send-email-antonynpavlov@gmail.com>

Set DEBUG_LL_UART_DIVISOR to use <asm/debug_ll_ns16550.h>.

The JZ4755 uses 24 MHz as the main reference frequency (EXCLK).
The UART controller can work on full EXCLK or on EXCLK/2.
Just now we use EXCLK/2 legacy clock setup made by U-Boot.
So set UART controller base frequency to 12 MHz.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h b/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h
index 7bf66b1..2a55dea 100644
--- a/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h
+++ b/arch/mips/mach-xburst/include/mach/debug_ll_jz4750d.h
@@ -34,4 +34,8 @@
 
 #define DEBUG_LL_UART_SHIFT	2
 
+#define DEBUG_LL_UART_CLK	(12000000 / 16)
+#define DEBUG_LL_UART_BPS	CONFIG_BAUDRATE
+#define DEBUG_LL_UART_DIVISOR	(DEBUG_LL_UART_CLK / DEBUG_LL_UART_BPS)
+
 #endif /* __INCLUDE_DEBUG_LL_JZ4750D_H__ */
-- 
1.7.10.4



From alex.aring at gmail.com  Mon Jun  3 19:13:49 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Tue,  4 Jun 2013 01:13:49 +0200
Subject: [PATCH 2/5] common: add ALIGN_DOWN macro
In-Reply-To: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
References: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
Message-ID: <1370301232-12962-3-git-send-email-alex.aring@gmail.com>

Signed-off-by: Alexander Aring <alex.aring at gmail.com>
---
 include/common.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/common.h b/include/common.h
index 293ca49..fc2c8ca 100644
--- a/include/common.h
+++ b/include/common.h
@@ -184,6 +184,7 @@ int run_shell(void);
 
 #define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a) - 1)
 #define __ALIGN_MASK(x, mask)	(((x) + (mask)) & ~(mask))
+#define ALIGN_DOWN(x, a)	((x) & ~((typeof(x))(a) - 1))
 #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
 #define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
 
-- 
1.8.3



From alex.aring at gmail.com  Mon Jun  3 19:13:51 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Tue,  4 Jun 2013 01:13:51 +0200
Subject: [PATCH 4/5] common: add memtest.c  with mem_test routine
In-Reply-To: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
References: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
Message-ID: <1370301232-12962-5-git-send-email-alex.aring@gmail.com>

Add mem_test routine. Useful to detect timing problems if someone
porting a new device to barebox. This test includes a data bus test,
address bus test and integrity check of memory.

This mem_test routine has as parameter start and end address of testing
space. The last parameter can skip the integrity check.

Signed-off-by: Alexander Aring <alex.aring at gmail.com>
---
 common/Makefile   |   1 +
 common/memtest.c  | 313 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/memtest.h |  14 +++
 3 files changed, 328 insertions(+)
 create mode 100644 common/memtest.c
 create mode 100644 include/memtest.h

diff --git a/common/Makefile b/common/Makefile
index 2f0bd34..d18b6c6 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
+obj-$(CONFIG_CMD_MEMTEST) += memtest.o
 obj-y += clock.o
 obj-$(CONFIG_BANNER) += version.o
 obj-$(CONFIG_MEMINFO) += meminfo.o
diff --git a/common/memtest.c b/common/memtest.c
new file mode 100644
index 0000000..22178cf
--- /dev/null
+++ b/common/memtest.c
@@ -0,0 +1,313 @@
+/*
+ * memory_test.c
+ *
+ * Copyright (c) 2013 Alexander Aring <aar at pengutronix.de>, Pengutronix
+ *
+ * (C) Copyright 2000
+ * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
+ *
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+#include <progress.h>
+#include <common.h>
+#include <memory.h>
+#include <types.h>
+#include <sizes.h>
+#include <memtest.h>
+
+static const resource_size_t bitpattern[] = {
+	0x00000001,	/* single bit */
+	0x00000003,	/* two adjacent bits */
+	0x00000007,	/* three adjacent bits */
+	0x0000000F,	/* four adjacent bits */
+	0x00000005,	/* two non-adjacent bits */
+	0x00000015,	/* three non-adjacent bits */
+	0x00000055,	/* four non-adjacent bits */
+	0xAAAAAAAA,	/* alternating 1/0 */
+};
+
+/*
+ * Perform a memory test. The complete test
+ * loops until interrupted by ctrl-c.
+ *
+ * Prameters:
+ * start: start address for memory test.
+ * end: end address of memory test.
+ * bus_only: skip integrity check and do only a address/data bus
+ *	     testing.
+ *
+ * Return value can be -EINVAL for invalid parameter or -EINTR
+ * if memory test was interrupted.
+ */
+int mem_test(resource_size_t _start,
+	       resource_size_t _end, int bus_only)
+{
+	volatile resource_size_t *start, *dummy, val, readback, offset,
+		offset2, pattern, temp, anti_pattern, num_words;
+	int i;
+
+	_start = ALIGN(_start, sizeof(resource_size_t));
+	_end = ALIGN_DOWN(_end, sizeof(resource_size_t)) - 1;
+
+	if (_end <= _start)
+		return -EINVAL;
+
+	start = (resource_size_t *)_start;
+	/*
+	 * Point the dummy to start[1]
+	 */
+	dummy = start + 1;
+	num_words = (_end - _start + 1)/sizeof(resource_size_t);
+
+	printf("Starting data line test.\n");
+
+	/*
+	 * Data line test: write a pattern to the first
+	 * location, write the 1's complement to a 'parking'
+	 * address (changes the state of the data bus so a
+	 * floating bus doen't give a false OK), and then
+	 * read the value back. Note that we read it back
+	 * into a variable because the next time we read it,
+	 * it might be right (been there, tough to explain to
+	 * the quality guys why it prints a failure when the
+	 * "is" and "should be" are obviously the same in the
+	 * error message).
+	 *
+	 * Rather than exhaustively testing, we test some
+	 * patterns by shifting '1' bits through a field of
+	 * '0's and '0' bits through a field of '1's (i.e.
+	 * pattern and ~pattern).
+	 */
+	for (i = 0; i < ARRAY_SIZE(bitpattern)/
+			sizeof(resource_size_t); i++) {
+		val = bitpattern[i];
+
+		for (; val != 0; val <<= 1) {
+			*start = val;
+			/* clear the test data off of the bus */
+			*dummy = ~val;
+			readback = *start;
+			if (readback != val) {
+				printf("FAILURE (data line): "
+					"expected 0x%08x, actual 0x%08x at address 0x%08x.\n",
+					val, readback, (resource_size_t)start);
+				return -EIO;
+			}
+
+			*start = ~val;
+			*dummy = val;
+			readback = *start;
+			if (readback != ~val) {
+				printf("FAILURE (data line): "
+					"Is 0x%08x, should be 0x%08x at address 0x%08x.\n",
+					readback,
+					~val, (resource_size_t)start);
+				return -EIO;
+			}
+		}
+	}
+
+
+	/*
+	 * Based on code whose Original Author and Copyright
+	 * information follows: Copyright (c) 1998 by Michael
+	 * Barr. This software is placed into the public
+	 * domain and may be used for any purpose. However,
+	 * this notice must not be changed or removed and no
+	 * warranty is either expressed or implied by its
+	 * publication or distribution.
+	 */
+
+	/*
+	 * Address line test
+	 *
+	 * Description: Test the address bus wiring in a
+	 *              memory region by performing a walking
+	 *              1's test on the relevant bits of the
+	 *              address and checking for aliasing.
+	 *              This test will find single-bit
+	 *              address failures such as stuck -high,
+	 *              stuck-low, and shorted pins. The base
+	 *              address and size of the region are
+	 *              selected by the caller.
+	 *
+	 * Notes:	For best results, the selected base
+	 *              address should have enough LSB 0's to
+	 *              guarantee single address bit changes.
+	 *              For example, to test a 64-Kbyte
+	 *              region, select a base address on a
+	 *              64-Kbyte boundary. Also, select the
+	 *              region size as a power-of-two if at
+	 *              all possible.
+	 *
+	 * ## NOTE ##	Be sure to specify start and end
+	 *              addresses such that num_words has
+	 *              lots of bits set. For example an
+	 *              address range of 01000000 02000000 is
+	 *              bad while a range of 01000000
+	 *              01ffffff is perfect.
+	 */
+
+	pattern = 0xAAAAAAAA;
+	anti_pattern = 0x55555555;
+
+	/*
+	 * Write the default pattern at each of the
+	 * power-of-two offsets.
+	 */
+	for (offset = 1; offset <= num_words; offset <<= 1)
+		start[offset] = pattern;
+
+	printf("Check for address bits stuck high.\n");
+
+	/*
+	 * Check for address bits stuck high.
+	 */
+	for (offset = 1; offset <= num_words; offset <<= 1) {
+		temp = start[offset];
+		if (temp != pattern) {
+			printf("FAILURE: Address bit "
+					"stuck high @ 0x%08x:"
+					" expected 0x%08x, actual 0x%08x.\n",
+					(resource_size_t)&start[offset],
+					pattern, temp);
+			return -EIO;
+		}
+	}
+
+	printf("Check for address bits stuck "
+			"low or shorted.\n");
+
+	/*
+	 * Check for address bits stuck low or shorted.
+	 */
+	for (offset2 = 1; offset2 <= num_words; offset2 <<= 1) {
+		start[offset2] = anti_pattern;
+
+		for (offset = 1; offset <= num_words; offset <<= 1) {
+			temp = start[offset];
+
+			if ((temp != pattern) &&
+					(offset != offset2)) {
+				printf("FAILURE: Address bit stuck"
+						" low or shorted @"
+						" 0x%08x: expected 0x%08x, actual 0x%08x.\n",
+						(resource_size_t)&start[offset],
+						pattern, temp);
+				return -EIO;
+			}
+		}
+		start[offset2] = pattern;
+	}
+
+	/*
+	 * We tested only the bus if != 0
+	 * leaving here
+	 */
+	if (bus_only)
+		return 0;
+
+	printf("Starting integrity check of physicaly ram.\n"
+			"Filling ram with patterns...\n");
+
+	/*
+	 * Description: Test the integrity of a physical
+	 *		memory device by performing an
+	 *		increment/decrement test over the
+	 *		entire region. In the process every
+	 *		storage bit in the device is tested
+	 *		as a zero and a one. The base address
+	 *		and the size of the region are
+	 *		selected by the caller.
+	 */
+
+	/*
+	 * Fill memory with a known pattern.
+	 */
+	init_progression_bar(num_words);
+	for (offset = 0; offset < num_words; offset++) {
+		/*
+		 * Every 4K we update the progressbar.
+		 */
+		if (!(offset & (SZ_4K - 1))) {
+			if (ctrlc())
+				return -EINTR;
+			show_progress(offset);
+		}
+
+		start[offset] = offset + 1;
+	}
+	show_progress(offset);
+
+	printf("\nCompare written patterns...\n");
+	/*
+	 * Check each location and invert it for the second pass.
+	 */
+	init_progression_bar(num_words - 1);
+	for (offset = 0; offset < num_words; offset++) {
+		if (!(offset & (SZ_4K - 1))) {
+			if (ctrlc())
+				return -EINTR;
+			show_progress(offset);
+		}
+
+		temp = start[offset];
+		if (temp != (offset + 1)) {
+			printf("\nFAILURE (read/write) @ 0x%08x:"
+					" expected 0x%08x, actual 0x%08x.\n",
+					(resource_size_t)&start[offset],
+					(offset + 1), temp);
+			return -EIO;
+		}
+
+		anti_pattern = ~(offset + 1);
+		start[offset] = anti_pattern;
+	}
+	show_progress(offset);
+
+	printf("\nFilling ram with inverted pattern and compare it...\n");
+	/*
+	 * Check each location for the inverted pattern and zero it.
+	 */
+	init_progression_bar(num_words - 1);
+	for (offset = 0; offset < num_words; offset++) {
+		if (!(offset & (SZ_4K - 1))) {
+			if (ctrlc())
+				return -EINTR;
+			show_progress(offset);
+		}
+
+		anti_pattern = ~(offset + 1);
+		temp = start[offset];
+
+		if (temp != anti_pattern) {
+			printf("\nFAILURE (read/write): @ 0x%08x:"
+					" expected 0x%08x, actual 0x%08x.\n",
+					(resource_size_t)&start[offset],
+					anti_pattern, temp);
+			return -EIO;
+		}
+
+		start[offset] = 0;
+	}
+	show_progress(offset);
+
+	/*
+	 * end of progressbar
+	 */
+	printf("\n");
+
+	return 0;
+}
diff --git a/include/memtest.h b/include/memtest.h
new file mode 100644
index 0000000..a337be8
--- /dev/null
+++ b/include/memtest.h
@@ -0,0 +1,14 @@
+#ifndef __MEMTEST_H
+#define __MEMTEST_H
+
+#include <linux/ioport.h>
+
+struct mem_test_resource {
+	struct resource *r;
+	struct list_head list;
+};
+
+int mem_test(resource_size_t _start,
+		resource_size_t _end, int bus_only);
+
+#endif /* __MEMTEST_H */
-- 
1.8.3



From alex.aring at gmail.com  Mon Jun  3 19:13:50 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Tue,  4 Jun 2013 01:13:50 +0200
Subject: [PATCH 3/5] memtest: remove memtest command
In-Reply-To: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
References: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
Message-ID: <1370301232-12962-4-git-send-email-alex.aring@gmail.com>

Remove memtest command.

Signed-off-by: Alexander Aring <alex.aring at gmail.com>
---
 commands/Kconfig   |   9 --
 commands/Makefile  |   1 -
 commands/memtest.c | 351 -----------------------------------------------------
 3 files changed, 361 deletions(-)
 delete mode 100644 commands/memtest.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 6a759ce..add547f 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -561,15 +561,6 @@ config CMD_NANDTEST
 	select PARTITION_NEED_MTD
 	prompt "nandtest"
 
-config CMD_MTEST
-	tristate
-	prompt "mtest"
-
-config CMD_MTEST_ALTERNATIVE
-	bool
-	depends on CMD_MTEST
-	prompt "alternative mtest implementation"
-
 endmenu
 
 menu "video command"
diff --git a/commands/Makefile b/commands/Makefile
index 953ecc2..9d34a56 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -13,7 +13,6 @@ obj-$(CONFIG_CMD_MW)		+= mw.o
 obj-$(CONFIG_CMD_MEMCMP)	+= memcmp.o
 obj-$(CONFIG_CMD_MEMCPY)	+= memcpy.o
 obj-$(CONFIG_CMD_MEMSET)	+= memset.o
-obj-$(CONFIG_CMD_MTEST)		+= memtest.o
 obj-$(CONFIG_CMD_EDIT)		+= edit.o
 obj-$(CONFIG_CMD_EXEC)		+= exec.o
 obj-$(CONFIG_CMD_SLEEP)		+= sleep.o
diff --git a/commands/memtest.c b/commands/memtest.c
deleted file mode 100644
index 2d64d00..0000000
--- a/commands/memtest.c
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
- * mtest - Perform a memory test
- *
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <command.h>
-#include <types.h>
-
-/*
- * Perform a memory test. A more complete alternative test can be
- * configured using CONFIG_CMD_MTEST_ALTERNATIVE. The complete test
- * loops until interrupted by ctrl-c or by a failure of one of the
- * sub-tests.
- */
-#ifdef CONFIG_CMD_MTEST_ALTERNATIVE
-static int mem_test(ulong _start, ulong _end, ulong pattern_unused)
-{
-	vu_long *start = (vu_long *)_start;
-	vu_long *end   = (vu_long *)_end;
-	vu_long *addr;
-	ulong	val;
-	ulong	readback;
-	vu_long	addr_mask;
-	vu_long	offset;
-	vu_long	test_offset;
-	vu_long	pattern;
-	vu_long	temp;
-	vu_long	anti_pattern;
-	vu_long	num_words;
-#ifdef CFG_MEMTEST_SCRATCH
-	vu_long *dummy = (vu_long*)CFG_MEMTEST_SCRATCH;
-#else
-	vu_long *dummy = start;
-#endif
-	int	j;
-	int iterations = 1;
-
-	static const ulong bitpattern[] = {
-		0x00000001,	/* single bit */
-		0x00000003,	/* two adjacent bits */
-		0x00000007,	/* three adjacent bits */
-		0x0000000F,	/* four adjacent bits */
-		0x00000005,	/* two non-adjacent bits */
-		0x00000015,	/* three non-adjacent bits */
-		0x00000055,	/* four non-adjacent bits */
-		0xaaaaaaaa,	/* alternating 1/0 */
-	};
-
-	/* XXX: enforce alignment of start and end? */
-	for (;;) {
-		if (ctrlc()) {
-			putchar ('\n');
-			return 1;
-		}
-
-		printf("Iteration: %6d\r", iterations);
-		iterations++;
-
-		/*
-		 * Data line test: write a pattern to the first
-		 * location, write the 1's complement to a 'parking'
-		 * address (changes the state of the data bus so a
-		 * floating bus doen't give a false OK), and then
-		 * read the value back. Note that we read it back
-		 * into a variable because the next time we read it,
-		 * it might be right (been there, tough to explain to
-		 * the quality guys why it prints a failure when the
-		 * "is" and "should be" are obviously the same in the
-		 * error message).
-		 *
-		 * Rather than exhaustively testing, we test some
-		 * patterns by shifting '1' bits through a field of
-		 * '0's and '0' bits through a field of '1's (i.e.
-		 * pattern and ~pattern).
-		 */
-		addr = start;
-		/* XXX */
-		if (addr == dummy) ++addr;
-		for (j = 0; j < sizeof(bitpattern)/sizeof(bitpattern[0]); j++) {
-		    val = bitpattern[j];
-		    for(; val != 0; val <<= 1) {
-			*addr  = val;
-			*dummy  = ~val; /* clear the test data off of the bus */
-			readback = *addr;
-			if(readback != val) {
-			     printf ("FAILURE (data line): "
-				"expected 0x%08lx, actual 0x%08lx at address 0x%p\n",
-					  val, readback, addr);
-			}
-			*addr  = ~val;
-			*dummy  = val;
-			readback = *addr;
-			if(readback != ~val) {
-			    printf ("FAILURE (data line): "
-				"Is 0x%08lx, should be 0x%08lx at address 0x%p\n",
-					readback, ~val, addr);
-			}
-		    }
-		}
-
-		/*
-		 * Based on code whose Original Author and Copyright
-		 * information follows: Copyright (c) 1998 by Michael
-		 * Barr. This software is placed into the public
-		 * domain and may be used for any purpose. However,
-		 * this notice must not be changed or removed and no
-		 * warranty is either expressed or implied by its
-		 * publication or distribution.
-		 */
-
-		/*
-		 * Address line test
-		 *
-		 * Description: Test the address bus wiring in a
-		 *              memory region by performing a walking
-		 *              1's test on the relevant bits of the
-		 *              address and checking for aliasing.
-		 *              This test will find single-bit
-		 *              address failures such as stuck -high,
-		 *              stuck-low, and shorted pins. The base
-		 *              address and size of the region are
-		 *              selected by the caller.
-		 *
-		 * Notes:	For best results, the selected base
-		 *              address should have enough LSB 0's to
-		 *              guarantee single address bit changes.
-		 *              For example, to test a 64-Kbyte
-		 *              region, select a base address on a
-		 *              64-Kbyte boundary. Also, select the
-		 *              region size as a power-of-two if at
-		 *              all possible.
-		 *
-		 * Returns:     0 if the test succeeds, 1 if the test fails.
-		 *
-		 * ## NOTE ##	Be sure to specify start and end
-		 *              addresses such that addr_mask has
-		 *              lots of bits set. For example an
-		 *              address range of 01000000 02000000 is
-		 *              bad while a range of 01000000
-		 *              01ffffff is perfect.
-		 */
-		addr_mask = ((ulong)end - (ulong)start)/sizeof(vu_long);
-		pattern = (vu_long) 0xaaaaaaaa;
-		anti_pattern = (vu_long) 0x55555555;
-
-		debug("%s:%d: addr mask = 0x%.8lx\n",
-			__FUNCTION__, __LINE__,
-			addr_mask);
-		/*
-		 * Write the default pattern at each of the
-		 * power-of-two offsets.
-		 */
-		for (offset = 1; (offset & addr_mask) != 0; offset <<= 1)
-			start[offset] = pattern;
-
-		/*
-		 * Check for address bits stuck high.
-		 */
-		test_offset = 0;
-		start[test_offset] = anti_pattern;
-
-		for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) {
-		    temp = start[offset];
-		    if (temp != pattern) {
-			printf ("\nFAILURE: Address bit stuck high @ 0x%.8lx:"
-				" expected 0x%.8lx, actual 0x%.8lx\n",
-				(ulong)&start[offset], pattern, temp);
-			return 1;
-		    }
-		}
-		start[test_offset] = pattern;
-
-		/*
-		 * Check for addr bits stuck low or shorted.
-		 */
-		for (test_offset = 1; (test_offset & addr_mask) != 0; test_offset <<= 1) {
-		    start[test_offset] = anti_pattern;
-
-		    for (offset = 1; (offset & addr_mask) != 0; offset <<= 1) {
-			temp = start[offset];
-			if ((temp != pattern) && (offset != test_offset)) {
-			    printf ("\nFAILURE: Address bit stuck low or shorted @"
-				" 0x%.8lx: expected 0x%.8lx, actual 0x%.8lx\n",
-				(ulong)&start[offset], pattern, temp);
-			    return 1;
-			}
-		    }
-		    start[test_offset] = pattern;
-		}
-
-		/*
-		 * Description: Test the integrity of a physical
-		 *		memory device by performing an
-		 *		increment/decrement test over the
-		 *		entire region. In the process every
-		 *		storage bit in the device is tested
-		 *		as a zero and a one. The base address
-		 *		and the size of the region are
-		 *		selected by the caller.
-		 *
-		 * Returns:     0 if the test succeeds, 1 if the test fails.
-		 */
-		num_words = ((ulong)end - (ulong)start)/sizeof(vu_long) + 1;
-
-		/*
-		 * Fill memory with a known pattern.
-		 */
-		for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
-			start[offset] = pattern;
-		}
-
-		/*
-		 * Check each location and invert it for the second pass.
-		 */
-		for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
-		    temp = start[offset];
-		    if (temp != pattern) {
-			printf ("\nFAILURE (read/write) @ 0x%.8lx:"
-				" expected 0x%.8lx, actual 0x%.8lx)\n",
-				(ulong)&start[offset], pattern, temp);
-			return 1;
-		    }
-
-		    anti_pattern = ~pattern;
-		    start[offset] = anti_pattern;
-		}
-
-		/*
-		 * Check each location for the inverted pattern and zero it.
-		 */
-		for (pattern = 1, offset = 0; offset < num_words; pattern++, offset++) {
-		    anti_pattern = ~pattern;
-		    temp = start[offset];
-		    if (temp != anti_pattern) {
-			printf ("\nFAILURE (read/write): @ 0x%.8lx:"
-				" expected 0x%.8lx, actual 0x%.8lx)\n",
-				(ulong)&start[offset], anti_pattern, temp);
-			return 1;
-		    }
-		    start[offset] = 0;
-		}
-	}
-
-}
-#else
-static int mem_test(ulong _start, ulong _end, ulong pattern)
-{
-	vu_long	*addr;
-	vu_long *start = (vu_long *)_start;
-	vu_long *end   = (vu_long *)_end;
-	ulong	val;
-	ulong	readback;
-	ulong	incr;
-	int rcode;
-
-	incr = 1;
-	for (;;) {
-		if (ctrlc()) {
-			putchar('\n');
-			return 1;
-		}
-
-		printf ("\rPattern 0x%08lX  Writing..."
-			"%12s"
-			"\b\b\b\b\b\b\b\b\b\b",
-			pattern, "");
-
-		for (addr=start,val=pattern; addr<end; addr++) {
-			*addr = val;
-			val  += incr;
-		}
-
-		puts ("Reading...");
-
-		for (addr=start,val=pattern; addr<end; addr++) {
-			readback = *addr;
-			if (readback != val) {
-				printf ("\nMem error @ 0x%08X: "
-					"found 0x%08lX, expected 0x%08lX\n",
-					(uint)addr, readback, val);
-				rcode = 1;
-			}
-			val += incr;
-		}
-
-		/*
-		 * Flip the pattern each time to make lots of zeros and
-		 * then, the next time, lots of ones.  We decrement
-		 * the "negative" patterns and increment the "positive"
-		 * patterns to preserve this feature.
-		 */
-		if(pattern & 0x80000000) {
-			pattern = -pattern;	/* complement & increment */
-		}
-		else {
-			pattern = ~pattern;
-		}
-		incr = -incr;
-	}
-	return rcode;
-}
-#endif
-
-static int do_mem_mtest(int argc, char *argv[])
-{
-	ulong start, end, pattern = 0;
-
-	if (argc < 3)
-		return COMMAND_ERROR_USAGE;
-
-	start = simple_strtoul(argv[1], NULL, 0);
-	end = simple_strtoul(argv[2], NULL, 0);
-
-	if (argc > 3)
-		pattern = simple_strtoul(argv[3], NULL, 0);
-
-	printf ("Testing 0x%08x ... 0x%08x:\n", (uint)start, (uint)end);
-	
-	return mem_test(start, end, pattern);
-}
-
-static const __maybe_unused char cmd_mtest_help[] =
-"Usage: <start> <end> "
-#ifdef CONFIG_CMD_MTEST_ALTERNATIVE
-"[pattern]"
-#endif
-"\nsimple RAM read/write test\n";
-
-BAREBOX_CMD_START(mtest)
-	.cmd		= do_mem_mtest,
-	.usage		= "simple RAM test",
-	BAREBOX_CMD_HELP(cmd_mtest_help)
-BAREBOX_CMD_END
-
-- 
1.8.3



From alex.aring at gmail.com  Mon Jun  3 19:13:52 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Tue,  4 Jun 2013 01:13:52 +0200
Subject: [PATCH 5/5] commands: add new memtest command
In-Reply-To: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
References: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
Message-ID: <1370301232-12962-6-git-send-email-alex.aring@gmail.com>

This new memtest can test the whole unused memory. The new memtest
command try to request the whole unused sdram regions on all banks and
run the mem_test routine from common/memtest.c on it.

The memtest command has only two parameters;
  -i	Amount of iterations, default 1, iteration of 0 is endless.
  -b	Set this to skip integrity check.(Do only a fast test for bus lines)

If MMU support is enable, memtest try to run memtest twice. The first with
cache enabled, the second with cache disabled.

Signed-off-by: Alexander Aring <alex.aring at gmail.com>
---
 commands/Kconfig   |  10 +++
 commands/Makefile  |   1 +
 commands/memtest.c | 250 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 261 insertions(+)
 create mode 100644 commands/memtest.c

diff --git a/commands/Kconfig b/commands/Kconfig
index add547f..9135f5d 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -561,6 +561,16 @@ config CMD_NANDTEST
 	select PARTITION_NEED_MTD
 	prompt "nandtest"
 
+config CMD_MEMTEST
+    tristate
+    prompt "memtest"
+       help
+         The memtest command can test the registered barebox memory.
+         During this test barebox memory regions like heap, stack, ...
+	 will be skipped. If the tested architecture has MMU with PTE
+	 flags support, the memtest is running twice with cache enabled
+	 and with cache disabled
+
 endmenu
 
 menu "video command"
diff --git a/commands/Makefile b/commands/Makefile
index 9d34a56..0ae01a5 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -48,6 +48,7 @@ obj-$(CONFIG_CMD_SAVEENV)	+= saveenv.o
 obj-$(CONFIG_CMD_LOADENV)	+= loadenv.o
 obj-$(CONFIG_CMD_NAND)		+= nand.o
 obj-$(CONFIG_CMD_NANDTEST)	+= nandtest.o
+obj-$(CONFIG_CMD_MEMTEST)	+= memtest.o
 obj-$(CONFIG_CMD_TRUE)		+= true.o
 obj-$(CONFIG_CMD_FALSE)		+= false.o
 obj-$(CONFIG_CMD_VERSION)	+= version.o
diff --git a/commands/memtest.c b/commands/memtest.c
new file mode 100644
index 0000000..a67d868
--- /dev/null
+++ b/commands/memtest.c
@@ -0,0 +1,250 @@
+/*
+ * memtest - Perform a memory test
+ *
+ * (C) Copyright 2013
+ * Alexander Aring <aar at pengutronix.de>, Pengutronix
+ *
+ * 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 <command.h>
+#include <getopt.h>
+#include <asm/mmu.h>
+#include <memory.h>
+
+#include <memtest.h>
+
+static int alloc_memtest_region(struct list_head *list,
+		resource_size_t start, resource_size_t size)
+{
+	struct resource *r_new;
+	struct mem_test_resource *r;
+
+	r = xzalloc(sizeof(struct mem_test_resource));
+	r_new = request_sdram_region("memtest", start, size);
+	if (!r_new)
+		return -EINVAL;
+
+	r->r = r_new;
+	list_add_tail(&r->list, list);
+
+	return 0;
+}
+
+static int request_memtest_regions(struct list_head *list)
+{
+	int ret;
+	struct memory_bank *bank;
+	struct resource *r, *r_prev = NULL;
+	resource_size_t start, end, size;
+
+	for_each_memory_bank(bank) {
+		/*
+		 * If we don't have any allocated region on bank,
+		 * we use the whole bank boundary
+		 */
+		if (list_empty(&bank->res->children)) {
+			start = PAGE_ALIGN(bank->res->start);
+			end = PAGE_ALIGN_DOWN(bank->res->end) - 1;
+			size = end - start + 1;
+
+			ret = alloc_memtest_region(list, start, size);
+			if (ret < 0)
+				return ret;
+
+			continue;
+		}
+
+		/*
+		 * We assume that the regions are sorted in this list
+		 * So the first element has start boundary on bank->res->start
+		 * and the last element hast end boundary on bank->res->end
+		 */
+		list_for_each_entry(r, &bank->res->children, sibling) {
+			/*
+			 * Do on head element for bank boundary
+			 */
+			if (r->sibling.prev == &bank->res->children) {
+				/*
+				 * remember last used element
+				 */
+				start = PAGE_ALIGN(bank->res->start);
+				end = PAGE_ALIGN_DOWN(r->start) - 1;
+				size = end - start + 1;
+				r_prev = r;
+				if (start >= end)
+					continue;
+
+				ret = alloc_memtest_region(list, start, size);
+				if (ret < 0)
+					return ret;
+				continue;
+			}
+			/*
+			 * Between used regions
+			 */
+			start = PAGE_ALIGN(r_prev->end);
+			end = PAGE_ALIGN_DOWN(r->start) - 1;
+			size = end - start + 1;
+			r_prev = r;
+			if (start >= end)
+				continue;
+
+			ret = alloc_memtest_region(list, start, size);
+			if (ret < 0)
+				return ret;
+
+			if (list_is_last(&r->sibling, &bank->res->children)) {
+				/*
+				 * Do on head element for bank boundary
+				 */
+				start = PAGE_ALIGN(r->end);
+				end = PAGE_ALIGN_DOWN(bank->res->end) - 1;
+				size = end - start + 1;
+				if (start >= end)
+					continue;
+
+				ret = alloc_memtest_region(list, start, size);
+				if (ret < 0)
+					return ret;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int __do_memtest(struct list_head *memtest_regions,
+		int bus_only, uint32_t cache_flag)
+{
+	struct mem_test_resource *r;
+	int ret;
+
+	list_for_each_entry(r, memtest_regions, list) {
+		printf("Testing memory space: "
+				"0x%08x -> 0x%08x:\n",
+				r->r->start,  r->r->end);
+		remap_range((void *)r->r->start, r->r->end -
+				r->r->start + 1, cache_flag);
+
+		ret = mem_test(r->r->start, r->r->end, bus_only);
+		if (ret < 0)
+			return ret;
+		printf("done.\n\n");
+	}
+
+	return 0;
+}
+
+static int do_memtest(int argc, char *argv[])
+{
+	int bus_only = 0, ret, opt;
+	uint32_t i, max_i = 1, pte_flags_cached, pte_flags_uncached;
+	struct mem_test_resource *r, *r_tmp;
+	struct list_head memtest_used_regions;
+
+	while ((opt = getopt(argc, argv, "i:b")) > 0) {
+		switch (opt) {
+		case 'i':
+			max_i = simple_strtoul(optarg, NULL, 0);
+			break;
+		case 'b':
+			bus_only = 1;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	if (optind > argc)
+		return COMMAND_ERROR_USAGE;
+
+	/*
+	 * Get pte flags for enable and disable cache support on page.
+	 */
+	pte_flags_cached = mmu_get_pte_cached_flags();
+	pte_flags_uncached = mmu_get_pte_uncached_flags();
+
+	INIT_LIST_HEAD(&memtest_used_regions);
+
+	ret = request_memtest_regions(&memtest_used_regions);
+	if (ret < 0)
+		goto out;
+
+	for (i = 1; (i <= max_i) || !max_i; i++) {
+		if (max_i)
+			printf("Start iteration %u of %u.\n", i, max_i);
+		/*
+		 * First try a memtest with caching enabled.
+		 */
+		if (IS_ENABLED(CONFIG_MMU)) {
+			printf("Do memtest with caching enabled.\n");
+			ret = __do_memtest(&memtest_used_regions,
+					bus_only, pte_flags_cached);
+			if (ret < 0)
+				goto out;
+		}
+		/*
+		 * Second try a memtest with caching disabled.
+		 */
+		printf("Do memtest with caching disabled.\n");
+		ret = __do_memtest(&memtest_used_regions,
+				bus_only, pte_flags_uncached);
+		if (ret < 0)
+			goto out;
+	}
+
+out:
+	list_for_each_entry_safe(r, r_tmp, &memtest_used_regions, list) {
+		/*
+		 * Ensure to leave with a cached on non used sdram regions.
+		 */
+		remap_range((void *)r->r->start, r->r->end -
+				r->r->start + 1, pte_flags_cached);
+		release_sdram_region(r->r);
+		free(r);
+	}
+
+	if (ret < 0) {
+		/*
+		 * Set cursor to newline, because mem_test failed at
+		 * drawing of progressbar.
+		 */
+		if (ret == -EINTR)
+			printf("\n");
+
+		printf("Memtest failed.\n");
+		return 1;
+	} else {
+		printf("Memtest successful.\n");
+		return 1;
+	}
+}
+
+static const __maybe_unused char cmd_memtest_help[] =
+"Usage: memtest [OPTION]...\n"
+"memtest related commands\n"
+"	-i	<iterations>	iterations [default=1, endless=0].\n"
+"	-b			perform only a test on buslines.";
+
+BAREBOX_CMD_START(memtest)
+	.cmd		= do_memtest,
+	.usage		= "Memory Test",
+	BAREBOX_CMD_HELP(cmd_memtest_help)
+BAREBOX_CMD_END
-- 
1.8.3



From alex.aring at gmail.com  Mon Jun  3 19:13:48 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Tue,  4 Jun 2013 01:13:48 +0200
Subject: [PATCH 1/5] common: fix codestyle in ALIGN macros
In-Reply-To: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
References: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
Message-ID: <1370301232-12962-2-git-send-email-alex.aring@gmail.com>

Signed-off-by: Alexander Aring <alex.aring at gmail.com>
---
 include/common.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/common.h b/include/common.h
index 59fcd35..293ca49 100644
--- a/include/common.h
+++ b/include/common.h
@@ -182,8 +182,8 @@ int run_shell(void);
 #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
 #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
 
-#define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
-#define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
+#define ALIGN(x, a)		__ALIGN_MASK(x, (typeof(x))(a) - 1)
+#define __ALIGN_MASK(x, mask)	(((x) + (mask)) & ~(mask))
 #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
 #define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
 
-- 
1.8.3



From alex.aring at gmail.com  Mon Jun  3 19:13:47 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Tue,  4 Jun 2013 01:13:47 +0200
Subject: [PATCH/RFC 0/5] Another try for a new memtest implementation
Message-ID: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>

Hi,

this is a new try to get a new memtest implementation into barebox.

I removed the ADDRESS_IN_REGIONS macro, which was a very ugly solution.
The new memtest command used a list and save all unused sdram_regions
of each bank. Then running the mem_test routine on these regions.
After that the memtest command will release the requested sdram_regions.

I removed the start and stop command arguments to make the implementation
easier/understandable and it's not necessary anyway.

Maybe it's better to remove the silent ALIGN and ALIGN_DOWN from the start
and end address in the common mem_test routine, because addresses are already
align.
It is difficult to explain because a end address has the form of 0xXXXXffff
and a ALIGN_DOWN on it with a mask of 3 we have a calculated end address of
0xXXXXfffA which is wrong. (0xXXXXffff - 4) - 1...

Another question is:
Can someone test it with more than one bank, please? :-)

Regards
Alex

Alexander Aring (5):
  common: fix codestyle in ALIGN macros
  common: add ALIGN_DOWN macro
  memtest: remove memtest command
  common: add memtest.c  with mem_test routine
  commands: add new memtest command

 commands/Kconfig   |  17 +-
 commands/Makefile  |   2 +-
 commands/memtest.c | 489 +++++++++++++++++++++--------------------------------
 common/Makefile    |   1 +
 common/memtest.c   | 313 ++++++++++++++++++++++++++++++++++
 include/common.h   |   5 +-
 include/memtest.h  |  14 ++
 7 files changed, 535 insertions(+), 306 deletions(-)
 create mode 100644 common/memtest.c
 create mode 100644 include/memtest.h

-- 
1.8.3



From axel.lin at ingics.com  Mon Jun  3 21:42:21 2013
From: axel.lin at ingics.com (Axel Lin)
Date: Tue, 04 Jun 2013 09:42:21 +0800
Subject: [PATCH] at91: sama5d3: fix off-by-one array boundary checking for
 pdata_i2c
Message-ID: <1370310141.7191.1.camel@phoenix>

i2c_id is used as array subscript, so it's valid value range is
0 ... ARRAY_SIZE -1.

Signed-off-by: Axel Lin <axel.lin at ingics.com>
---
 arch/arm/mach-at91/sama5d3_devices.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-at91/sama5d3_devices.c b/arch/arm/mach-at91/sama5d3_devices.c
index 031168b..e456bd0 100644
--- a/arch/arm/mach-at91/sama5d3_devices.c
+++ b/arch/arm/mach-at91/sama5d3_devices.c
@@ -322,7 +322,7 @@ void at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_de
 {
 	struct i2c_gpio_platform_data *pdata;
 
-	if (i2c_id > ARRAY_SIZE(pdata_i2c))
+	if (i2c_id >= ARRAY_SIZE(pdata_i2c))
 		return;
 
 	i2c_register_board_info(i2c_id, devices, nr_devices);
-- 
1.8.1.2





From axel.lin at ingics.com  Mon Jun  3 21:43:52 2013
From: axel.lin at ingics.com (Axel Lin)
Date: Tue, 04 Jun 2013 09:43:52 +0800
Subject: [PATCH] tegra: fix off-by-one array boundary checking for
 uart_id_to_base
Message-ID: <1370310232.7191.3.camel@phoenix>

id is used as array subscript, so it's valid value range is 0 ... ARRAY_SIZE -1.

Signed-off-by: Axel Lin <axel.lin at ingics.com>
---
 arch/arm/mach-tegra/include/mach/lowlevel.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-tegra/include/mach/lowlevel.h b/arch/arm/mach-tegra/include/mach/lowlevel.h
index b7c01c0..361b12e 100644
--- a/arch/arm/mach-tegra/include/mach/lowlevel.h
+++ b/arch/arm/mach-tegra/include/mach/lowlevel.h
@@ -136,7 +136,7 @@ static inline long tegra20_get_debuguart_base(void)
 		return 0;
 
 	id = (odmdata & T20_ODMDATA_UARTID_MASK) >> T20_ODMDATA_UARTID_SHIFT;
-	if (id > ARRAY_SIZE(uart_id_to_base))
+	if (id >= ARRAY_SIZE(uart_id_to_base))
 		return 0;
 
 	return uart_id_to_base[id];
-- 
1.8.1.2





From s.hauer at pengutronix.de  Tue Jun  4 03:03:48 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 4 Jun 2013 09:03:48 +0200
Subject: [PATCH v2 0/5] MIPS: rework ns16550 debug_ll
In-Reply-To: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
References: <1370256807-26755-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <20130604070348.GG32299@pengutronix.de>

On Mon, Jun 03, 2013 at 02:53:22PM +0400, Antony Pavlov wrote:
> This patch series makes possible easely produce
> debug output via ns16550-like UART on very early pbl stage.
> 
> v2 patch series is based on the 'master' branch
> and it does not break bisectibility.

Thanks for redoing this. Applied.

Sascha

> 
> [PATCH v2 1/5] MIPS: rzx50: prepare for new debug_ll
> [PATCH v2 2/5] MIPS: malta: prepare for new debug_ll
> [PATCH v2 3/5] MIPS: unify ns16550 debug_ll support code
> [PATCH v2 4/5] MIPS: rzx50: pbl: use debug_ll
> [PATCH v2 5/5] MIPS: rzx50_defconfig: use UART1 for low-level debug
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From dev at lynxeye.de  Tue Jun  4 03:29:10 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Tue,  4 Jun 2013 09:29:10 +0200
Subject: [PATCH 2/3] of: import of_property_match_string from Linux
In-Reply-To: <1370330951-3548-1-git-send-email-dev@lynxeye.de>
References: <1370330951-3548-1-git-send-email-dev@lynxeye.de>
Message-ID: <1370330951-3548-2-git-send-email-dev@lynxeye.de>

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 drivers/of/base.c | 37 +++++++++++++++++++++++++++++++++++++
 include/of.h      |  2 ++
 2 files changed, 39 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index b3d012c..912e793 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -683,6 +683,43 @@ int of_property_read_string_index(struct device_node *np, const char *propname,
 EXPORT_SYMBOL_GPL(of_property_read_string_index);
 
 /**
+ * of_property_match_string() - Find string in a list and return index
+ * @np: pointer to node containing string list property
+ * @propname: string list property name
+ * @string: pointer to string to search for in string list
+ *
+ * This function searches a string list property and returns the index
+ * of a specific string value.
+ */
+int of_property_match_string(struct device_node *np, const char *propname,
+			     const char *string)
+{
+	struct property *prop = of_find_property(np, propname);
+	size_t l;
+	int i;
+	const char *p, *end;
+
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+
+	p = prop->value;
+	end = p + prop->length;
+
+	for (i = 0; p < end; i++, p += l) {
+		l = strlen(p) + 1;
+		if (p + l > end)
+			return -EILSEQ;
+		pr_debug("comparing %s with %s\n", string, p);
+		if (strcmp(string, p) == 0)
+			return i; /* Found it; return index */
+	}
+	return -ENODATA;
+}
+EXPORT_SYMBOL_GPL(of_property_match_string);
+
+/**
  * of_modalias_node - Lookup appropriate modalias for a device node
  * @node:	pointer to a device tree node
  * @modalias:	Pointer to buffer that modalias value will be copied into
diff --git a/include/of.h b/include/of.h
index f00d1b4..27fd8da 100644
--- a/include/of.h
+++ b/include/of.h
@@ -172,6 +172,8 @@ int of_property_read_string(struct device_node *np, const char *propname,
 				const char **out_string);
 int of_property_read_string_index(struct device_node *np, const char *propname,
 				  int index, const char **output);
+int of_property_match_string(struct device_node *np, const char *propname,
+			     const char *string);
 int of_set_property(struct device_node *node, const char *p, const void *val, int len,
 		int create);
 struct device_node *of_create_node(struct device_node *root, const char *path);
-- 
1.8.2.1



From dev at lynxeye.de  Tue Jun  4 03:29:11 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Tue,  4 Jun 2013 09:29:11 +0200
Subject: [PATCH 3/3] clk: add clock lookup from devicetree
In-Reply-To: <1370330951-3548-1-git-send-email-dev@lynxeye.de>
References: <1370330951-3548-1-git-send-email-dev@lynxeye.de>
Message-ID: <1370330951-3548-3-git-send-email-dev@lynxeye.de>

Taken from the Linuxkernel with some small adjustments for barebox.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 drivers/clk/clk.c    | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/clkdev.c | 74 +++++++++++++++++++++++++++++++++++++++
 include/linux/clk.h  | 33 ++++++++++++++++++
 3 files changed, 204 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 690a0c6..bad3386 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -16,6 +16,7 @@
  */
 #include <common.h>
 #include <errno.h>
+#include <malloc.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 
@@ -253,6 +254,102 @@ int clk_is_enabled_always(struct clk *clk)
 	return 1;
 }
 
+#ifdef CONFIG_OFTREE
+/**
+ * struct of_clk_provider - Clock provider registration structure
+ * @link: Entry in global list of clock providers
+ * @node: Pointer to device tree node of clock provider
+ * @get: Get clock callback.  Returns NULL or a struct clk for the
+ *       given clock specifier
+ * @data: context pointer to be passed into @get callback
+ */
+struct of_clk_provider {
+	struct list_head link;
+
+	struct device_node *node;
+	struct clk *(*get)(struct of_phandle_args *clkspec, void *data);
+	void *data;
+};
+
+static LIST_HEAD(of_clk_providers);
+
+struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data)
+{
+	struct clk_onecell_data *clk_data = data;
+	unsigned int idx = clkspec->args[0];
+
+	if (idx >= clk_data->clk_num) {
+		pr_err("%s: invalid clock index %d\n", __func__, idx);
+		return ERR_PTR(-EINVAL);
+	}
+
+	return clk_data->clks[idx];
+}
+EXPORT_SYMBOL_GPL(of_clk_src_onecell_get);
+
+/**
+ * of_clk_add_provider() - Register a clock provider for a node
+ * @np: Device node pointer associated with clock provider
+ * @clk_src_get: callback for decoding clock
+ * @data: context pointer for @clk_src_get callback.
+ */
+int of_clk_add_provider(struct device_node *np,
+			struct clk *(*clk_src_get)(struct of_phandle_args *clkspec,
+						   void *data),
+			void *data)
+{
+	struct of_clk_provider *cp;
+
+	cp = kzalloc(sizeof(struct of_clk_provider), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+
+	cp->node = np;
+	cp->data = data;
+	cp->get = clk_src_get;
+
+	list_add(&cp->link, &of_clk_providers);
+	pr_debug("Added clock from %s\n", np->full_name);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_clk_add_provider);
+
+/**
+ * of_clk_del_provider() - Remove a previously registered clock provider
+ * @np: Device node pointer associated with clock provider
+ */
+void of_clk_del_provider(struct device_node *np)
+{
+	struct of_clk_provider *cp;
+
+	list_for_each_entry(cp, &of_clk_providers, link) {
+		if (cp->node == np) {
+			list_del(&cp->link);
+			kfree(cp);
+			break;
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(of_clk_del_provider);
+
+struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
+{
+	struct of_clk_provider *provider;
+	struct clk *clk = ERR_PTR(-ENOENT);
+
+	/* Check if we have such a provider in our array */
+	list_for_each_entry(provider, &of_clk_providers, link) {
+		if (provider->node == clkspec->np)
+			clk = provider->get(clkspec, provider->data);
+		if (!IS_ERR(clk))
+			break;
+	}
+
+	return clk;
+}
+#endif
+
 static void dump_one(struct clk *clk, int verbose, int indent)
 {
 	struct clk *c;
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 256927e..0b91af0 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -19,10 +19,80 @@
 #include <linux/clkdev.h>
 #include <init.h>
 #include <malloc.h>
+#include <of.h>
 #include <stdio.h>
 
 static LIST_HEAD(clocks);
 
+#if defined(CONFIG_OFTREE) && defined(CONFIG_COMMON_CLK)
+struct clk *of_clk_get(struct device_node *np, int index)
+{
+	struct of_phandle_args clkspec;
+	struct clk *clk;
+	int rc;
+
+	if (index < 0)
+		return ERR_PTR(-EINVAL);
+
+	rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index,
+					&clkspec);
+	if (rc)
+		return ERR_PTR(rc);
+
+	clk = of_clk_get_from_provider(&clkspec);
+	return clk;
+}
+EXPORT_SYMBOL(of_clk_get);
+
+/**
+ * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
+ * @np: pointer to clock consumer node
+ * @name: name of consumer's clock input, or NULL for the first clock reference
+ *
+ * This function parses the clocks and clock-names properties,
+ * and uses them to look up the struct clk from the registered list of clock
+ * providers.
+ */
+struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
+{
+	struct clk *clk = ERR_PTR(-ENOENT);
+
+	/* Walk up the tree of devices looking for a clock that matches */
+	while (np) {
+		int index = 0;
+
+		/*
+		 * For named clocks, first look up the name in the
+		 * "clock-names" property.  If it cannot be found, then
+		 * index will be an error code, and of_clk_get() will fail.
+		 */
+		if (name)
+			index = of_property_match_string(np, "clock-names",
+							 name);
+		clk = of_clk_get(np, index);
+		if (!IS_ERR(clk))
+			break;
+		else if (name && index >= 0) {
+			pr_err("ERROR: could not get clock %s:%s(%i)\n",
+				np->full_name, name ? name : "", index);
+			return clk;
+		}
+
+		/*
+		 * No matching clock found on this node.  If the parent node
+		 * has a "clock-ranges" property, then we can try one of its
+		 * clocks.
+		 */
+		np = np->parent;
+		if (np && !of_get_property(np, "clock-ranges", NULL))
+			break;
+	}
+
+	return clk;
+}
+EXPORT_SYMBOL(of_clk_get_by_name);
+#endif
+
 /*
  * Find the correct struct clk for the device and connection ID.
  * We do slightly fuzzy matching here:
@@ -109,6 +179,10 @@ struct clk *clk_get(struct device_d *dev, const char *con_id)
 	if (!IS_ERR(clk))
 		return clk;
 
+	clk = of_clk_get_by_name(dev->device_node, con_id);
+		if (!IS_ERR(clk))
+			return clk;
+
 	return clk_get_sys(dev_id, con_id);
 }
 EXPORT_SYMBOL(clk_get);
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 37a4813..0f7158a 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -11,6 +11,8 @@
 #ifndef __LINUX_CLK_H
 #define __LINUX_CLK_H
 
+#include <linux/err.h>
+
 struct device_d;
 
 /*
@@ -210,4 +212,35 @@ void clk_dump(int verbose);
 
 #endif
 
+struct device_node;
+struct of_phandle_args;
+
+#if defined(CONFIG_OFTREE) && defined(CONFIG_COMMON_CLK)
+int of_clk_add_provider(struct device_node *np,
+			struct clk *(*clk_src_get)(struct of_phandle_args *args,
+						   void *data),
+			void *data);
+void of_clk_del_provider(struct device_node *np);
+
+struct clk_onecell_data {
+	struct clk **clks;
+	unsigned int clk_num;
+};
+struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
+
+struct clk *of_clk_get(struct device_node *np, int index);
+struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
+struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
+#else
+static inline struct clk *of_clk_get(struct device_node *np, int index)
+{
+	return ERR_PTR(-ENOENT);
+}
+static inline struct clk *of_clk_get_by_name(struct device_node *np,
+					     const char *name)
+{
+	return ERR_PTR(-ENOENT);
+}
+#endif
+
 #endif
-- 
1.8.2.1



From dev at lynxeye.de  Tue Jun  4 03:29:19 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Tue,  4 Jun 2013 09:29:19 +0200
Subject: [PATCH 2/6] clk: allow to instanciate clk gate without registering it
In-Reply-To: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
References: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
Message-ID: <1370330963-3610-2-git-send-email-dev@lynxeye.de>

Allows to reuse the clk gate code within other clocks.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 drivers/clk/clk-gate.c | 31 +++++++++++++++++++++++++------
 include/linux/clk.h    |  4 ++++
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index a455094..e4e9967 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -27,6 +27,8 @@ struct clk_gate {
 	const char *parent;
 };
 
+#define to_clk_gate(_clk) container_of(_clk, struct clk_gate, clk)
+
 static int clk_gate_enable(struct clk *clk)
 {
 	struct clk_gate *g = container_of(clk, struct clk_gate, clk);
@@ -68,11 +70,10 @@ struct clk_ops clk_gate_ops = {
 	.is_enabled = clk_gate_is_enabled,
 };
 
-struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
-		u8 shift)
+struct clk *clk_gate_alloc(const char *name, const char *parent,
+		void __iomem *reg, u8 shift)
 {
 	struct clk_gate *g = xzalloc(sizeof(*g));
-	int ret;
 
 	g->parent = parent;
 	g->reg = reg;
@@ -82,11 +83,29 @@ struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 	g->clk.parent_names = &g->parent;
 	g->clk.num_parents = 1;
 
-	ret = clk_register(&g->clk);
+	return &g->clk;
+}
+
+void clk_gate_free(struct clk *clk_gate)
+{
+	struct clk_gate *g = to_clk_gate(clk_gate);
+
+	free(g);
+}
+
+struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
+		u8 shift)
+{
+	struct clk *g;
+	int ret;
+
+	g = clk_gate_alloc(name , parent, reg, shift);
+
+	ret = clk_register(g);
 	if (ret) {
-		free(g);
+		free(to_clk_gate(g));
 		return ERR_PTR(ret);
 	}
 
-	return &g->clk;
+	return g;
 }
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 0f7158a..cf41bd7 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -199,6 +199,10 @@ struct clk *clk_fixed_factor(const char *name,
 		const char *parent, unsigned int mult, unsigned int div);
 struct clk *clk_mux(const char *name, void __iomem *reg,
 		u8 shift, u8 width, const char **parents, u8 num_parents);
+
+struct clk *clk_gate_alloc(const char *name, const char *parent,
+		void __iomem *reg, u8 shift);
+void clk_gate_free(struct clk *clk_gate);
 struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 		u8 shift);
 
-- 
1.8.2.1



From dev at lynxeye.de  Tue Jun  4 03:29:18 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Tue,  4 Jun 2013 09:29:18 +0200
Subject: [PATCH 1/6] tegra: change clocksource driver to be more lowlevel
Message-ID: <1370330963-3610-1-git-send-email-dev@lynxeye.de>

In order to properly bring up the system PLLs we need a reliable
clocksource. To break the circular dependency between the clocksource
and the CAR driver, get the OSC frequency with a lowlevel function.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 arch/arm/mach-tegra/include/mach/lowlevel.h | 23 +++++++++++++++++++++++
 arch/arm/mach-tegra/tegra20-timer.c         | 16 +++-------------
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mach-tegra/include/mach/lowlevel.h b/arch/arm/mach-tegra/include/mach/lowlevel.h
index b7c01c0..071416f 100644
--- a/arch/arm/mach-tegra/include/mach/lowlevel.h
+++ b/arch/arm/mach-tegra/include/mach/lowlevel.h
@@ -142,5 +142,28 @@ static inline long tegra20_get_debuguart_base(void)
 	return uart_id_to_base[id];
 }
 
+#define CRC_OSC_CTRL			0x050
+#define CRC_OSC_CTRL_OSC_FREQ_SHIFT	30
+#define CRC_OSC_CTRL_OSC_FREQ_MASK	(0x3 << CRC_OSC_CTRL_OSC_FREQ_SHIFT)
+
+static inline unsigned int tegra_get_osc_clock(void)
+{
+	u32 osc_ctrl = readl(TEGRA_CLK_RESET_BASE + CRC_OSC_CTRL);
+
+	switch ((osc_ctrl & CRC_OSC_CTRL_OSC_FREQ_MASK) >>
+		CRC_OSC_CTRL_OSC_FREQ_SHIFT) {
+	case 0:
+		return 13000000;
+	case 1:
+		return 19200000;
+	case 2:
+		return 12000000;
+	case 3:
+		return 26000000;
+	default:
+		return 0;
+	}
+}
+
 /* reset vector for the main CPU complex */
 void tegra_maincomplex_entry(void);
diff --git a/arch/arm/mach-tegra/tegra20-timer.c b/arch/arm/mach-tegra/tegra20-timer.c
index aafbfd4..2b32647 100644
--- a/arch/arm/mach-tegra/tegra20-timer.c
+++ b/arch/arm/mach-tegra/tegra20-timer.c
@@ -24,6 +24,7 @@
 #include <init.h>
 #include <io.h>
 #include <linux/clk.h>
+#include <mach/lowlevel.h>
 
 /* register definitions */
 #define TIMERUS_CNTR_1US	0x10
@@ -43,8 +44,6 @@ static struct clocksource cs = {
 
 static int tegra20_timer_probe(struct device_d *dev)
 {
-	struct clk *timer_clk;
-	unsigned long rate;
 	u32 reg;
 
 	/* use only one timer */
@@ -57,22 +56,13 @@ static int tegra20_timer_probe(struct device_d *dev)
 		return -ENODEV;
 	}
 
-	timer_clk = clk_get(dev, NULL);
-	if (!timer_clk) {
-		dev_err(dev, "could not get clock\n");
-		return -ENODEV;
-	}
-
-	clk_enable(timer_clk);
-
 	/*
 	 * calibrate timer to run at 1MHz
 	 * TIMERUS_USEC_CFG selects the scale down factor with bits [0:7]
 	 * representing the divisor and bits [8:15] representing the dividend
 	 * each in n+1 form.
 	 */
-	rate = clk_get_rate(timer_clk);
-	switch (rate) {
+	switch (tegra_get_osc_clock()) {
 	case 12000000:
 		reg = 0x000b;
 		break;
@@ -116,4 +106,4 @@ static int tegra20_timer_init(void)
 {
 	return platform_driver_register(&tegra20_timer_driver);
 }
-coredevice_initcall(tegra20_timer_init);
+core_initcall(tegra20_timer_init);
-- 
1.8.2.1



From dev at lynxeye.de  Tue Jun  4 03:29:09 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Tue,  4 Jun 2013 09:29:09 +0200
Subject: [PATCH 1/3] of: update of_parse_phandle_with_args to latest linux code
Message-ID: <1370330951-3548-1-git-send-email-dev@lynxeye.de>

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 drivers/of/base.c | 168 +++++++++++++++++++++++++++++++-----------------------
 drivers/of/gpio.c |   9 ++-
 include/of.h      |  14 +++--
 3 files changed, 111 insertions(+), 80 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4241e65..b3d012c 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -406,17 +406,19 @@ int of_property_write_u32_array(struct device_node *np,
 }
 
 /**
- * of_parse_phandles_with_args - Find a node pointed by phandle in a list
+ * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
  * @np:		pointer to a device tree node containing a list
  * @list_name:	property name that contains a list
  * @cells_name:	property name that specifies phandles' arguments count
  * @index:	index of a phandle to parse out
- * @out_node:	optional pointer to device_node struct pointer (will be filled)
- * @out_args:	optional pointer to arguments pointer (will be filled)
+ * @out_args:	optional pointer to output arguments structure (will be filled)
  *
  * This function is useful to parse lists of phandles and their arguments.
- * Returns 0 on success and fills out_node and out_args, on error returns
- * appropriate errno value.
+ * Returns 0 on success and fills out_args, on error returns appropriate
+ * errno value.
+ *
+ * Caller is responsible to call of_node_put() on the returned out_args->node
+ * pointer.
  *
  * Example:
  *
@@ -433,92 +435,116 @@ int of_property_write_u32_array(struct device_node *np,
  * }
  *
  * To get a device_node of the `node2' node you may call this:
- * of_parse_phandles_with_args(node3, "list", "#list-cells", 2, &node2, &args);
+ * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
  */
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
-				const char *cells_name, int index,
-				struct device_node **out_node,
-				const void **out_args)
+static int __of_parse_phandle_with_args(const struct device_node *np,
+					const char *list_name,
+					const char *cells_name, int index,
+					struct of_phandle_args *out_args)
 {
-	int ret = -EINVAL;
-	const __be32 *list;
-	const __be32 *list_end;
-	int size;
-	int cur_index = 0;
+	const __be32 *list, *list_end;
+	int rc = 0, size, cur_index = 0;
+	uint32_t count = 0;
 	struct device_node *node = NULL;
-	const void *args = NULL;
+	phandle phandle;
 
+	/* Retrieve the phandle list property */
 	list = of_get_property(np, list_name, &size);
-	if (!list) {
-		ret = -ENOENT;
-		goto err0;
-	}
+	if (!list)
+		return -ENOENT;
 	list_end = list + size / sizeof(*list);
 
+	/* Loop over the phandles until all the requested entry is found */
 	while (list < list_end) {
-		const __be32 *cells;
-		phandle phandle;
+		rc = -EINVAL;
+		count = 0;
 
+		/*
+		 * If phandle is 0, then it is an empty entry with no
+		 * arguments.  Skip forward to the next entry.
+		 */
 		phandle = be32_to_cpup(list++);
-		args = list;
-
-		/* one cell hole in the list = <>; */
-		if (!phandle)
-			goto next;
-
-		node = of_find_node_by_phandle(phandle);
-		if (!node) {
-			pr_debug("%s: could not find phandle %d\n",
-				 np->full_name, phandle);
-			goto err0;
+		if (phandle) {
+			/*
+			 * Find the provider node and parse the #*-cells
+			 * property to determine the argument length
+			 */
+			node = of_find_node_by_phandle(phandle);
+			if (!node) {
+				pr_err("%s: could not find phandle\n",
+					 np->full_name);
+				goto err;
+			}
+			if (of_property_read_u32(node, cells_name, &count)) {
+				pr_err("%s: could not get %s for %s\n",
+					 np->full_name, cells_name,
+					 node->full_name);
+				goto err;
+			}
+
+			/*
+			 * Make sure that the arguments actually fit in the
+			 * remaining property data length
+			 */
+			if (list + count > list_end) {
+				pr_err("%s: arguments longer than property\n",
+					 np->full_name);
+				goto err;
+			}
 		}
 
-		cells = of_get_property(node, cells_name, &size);
-		if (!cells || size != sizeof(*cells)) {
-			pr_debug("%s: could not get %s for %s\n",
-				 np->full_name, cells_name, node->full_name);
-			goto err1;
+		/*
+		 * All of the error cases above bail out of the loop, so at
+		 * this point, the parsing is successful. If the requested
+		 * index matches, then fill the out_args structure and return,
+		 * or return -ENOENT for an empty entry.
+		 */
+		rc = -ENOENT;
+		if (cur_index == index) {
+			if (!phandle)
+				goto err;
+
+			if (out_args) {
+				int i;
+				if (WARN_ON(count > MAX_PHANDLE_ARGS))
+					count = MAX_PHANDLE_ARGS;
+				out_args->np = node;
+				out_args->args_count = count;
+				for (i = 0; i < count; i++)
+					out_args->args[i] = be32_to_cpup(list++);
+			}
+
+			/* Found it! return success */
+			return 0;
 		}
 
-		list += be32_to_cpup(cells);
-		if (list > list_end) {
-			pr_debug("%s: insufficient arguments length\n",
-				 np->full_name);
-			goto err1;
-		}
-next:
-		if (cur_index == index)
-			break;
-
 		node = NULL;
-		args = NULL;
+		list += count;
 		cur_index++;
 	}
 
-	if (!node) {
-		/*
-		 * args w/o node indicates that the loop above has stopped at
-		 * the 'hole' cell. Report this differently.
-		 */
-		if (args)
-			ret = -EEXIST;
-		else
-			ret = -ENOENT;
-		goto err0;
-	}
-
-	if (out_node)
-		*out_node = node;
-	if (out_args)
-		*out_args = args;
+	/*
+	 * Unlock node before returning result; will be one of:
+	 * -ENOENT : index is for empty phandle
+	 * -EINVAL : parsing error on data
+	 * [1..n]  : Number of phandle (count mode; when index = -1)
+	 */
+	rc = index < 0 ? cur_index : -ENOENT;
+ err:
+	return rc;
+}
 
-	return 0;
-err1:
-err0:
-	pr_debug("%s failed with status %d\n", __func__, ret);
-	return ret;
+int of_parse_phandle_with_args(const struct device_node *np,
+				const char *list_name,
+				const char *cells_name, int index,
+				struct of_phandle_args *out_args)
+{
+	if (index < 0)
+		return -EINVAL;
+	return __of_parse_phandle_with_args(np, list_name, cells_name,
+					    index, out_args);
 }
-EXPORT_SYMBOL(of_parse_phandles_with_args);
+EXPORT_SYMBOL(of_parse_phandle_with_args);
 
 /**
  * of_machine_is_compatible - Test root of device tree for a given compatible value
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 83b72c0..cd3e1b7 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -9,17 +9,16 @@ int of_get_named_gpio(struct device_node *np,
                                    const char *propname, int index)
 {
 	int ret;
-	struct device_node *gpio_np;
-	const void *gpio_spec;
+	struct of_phandle_args gpio_spec;
 
-	ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index,
-					  &gpio_np, &gpio_spec);
+	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", index,
+					 &gpio_spec);
 	if (ret) {
 		pr_debug("%s: can't parse gpios property: %d\n", __func__, ret);
 		return -EINVAL;
 	}
 
-	ret = gpio_get_num(gpio_np->device, be32_to_cpup(gpio_spec));
+	ret = gpio_get_num(gpio_spec.np->device, gpio_spec.args[0]);
 	if (ret < 0)
 		return ret;
 
diff --git a/include/of.h b/include/of.h
index 300b706..f00d1b4 100644
--- a/include/of.h
+++ b/include/of.h
@@ -32,6 +32,13 @@ struct device_node {
 	phandle phandle;
 };
 
+#define MAX_PHANDLE_ARGS 8
+struct of_phandle_args {
+	struct device_node *np;
+	int args_count;
+	uint32_t args[MAX_PHANDLE_ARGS];
+};
+
 struct of_device_id {
 	char *compatible;
 	unsigned long data;
@@ -130,10 +137,9 @@ static inline int of_property_write_u32(struct device_node *np,
 const void *of_get_property(const struct device_node *np, const char *name,
 			 int *lenp);
 
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
-				const char *cells_name, int index,
-				struct device_node **out_node,
-				const void **out_args);
+int of_parse_phandle_with_args(const struct device_node *np,
+			       const char *list_name, const char *cells_name,
+			       int index, struct of_phandle_args *out_args);
 
 int of_get_named_gpio(struct device_node *np,
                                    const char *propname, int index);
-- 
1.8.2.1



From dev at lynxeye.de  Tue Jun  4 03:29:20 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Tue,  4 Jun 2013 09:29:20 +0200
Subject: [PATCH 3/6] clk: allow to instanciate clk mux without registering it
In-Reply-To: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
References: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
Message-ID: <1370330963-3610-3-git-send-email-dev@lynxeye.de>

Allows to reuse clk mux code within other clocks.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 drivers/clk/clk-mux.c | 29 ++++++++++++++++++++++++-----
 include/linux/clk.h   |  4 ++++
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index cb5f1a1..47efe12 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -27,6 +27,8 @@ struct clk_mux {
 	int width;
 };
 
+#define to_clk_mux(_clk) container_of(_clk, struct clk_mux, clk)
+
 static int clk_mux_get_parent(struct clk *clk)
 {
 	struct clk_mux *m = container_of(clk, struct clk_mux, clk);
@@ -53,11 +55,10 @@ struct clk_ops clk_mux_ops = {
 	.set_parent = clk_mux_set_parent,
 };
 
-struct clk *clk_mux(const char *name, void __iomem *reg,
+struct clk *clk_mux_alloc(const char *name, void __iomem *reg,
 		u8 shift, u8 width, const char **parents, u8 num_parents)
 {
 	struct clk_mux *m = xzalloc(sizeof(*m));
-	int ret;
 
 	m->reg = reg;
 	m->shift = shift;
@@ -67,11 +68,29 @@ struct clk *clk_mux(const char *name, void __iomem *reg,
 	m->clk.parent_names = parents;
 	m->clk.num_parents = num_parents;
 
-	ret = clk_register(&m->clk);
+	return &m->clk;
+}
+
+void clk_mux_free(struct clk *clk_mux)
+{
+	struct clk_mux *m = to_clk_mux(clk_mux);
+
+	free(m);
+}
+
+struct clk *clk_mux(const char *name, void __iomem *reg,
+		u8 shift, u8 width, const char **parents, u8 num_parents)
+{
+	struct clk *m;
+	int ret;
+
+	m = clk_mux_alloc(name, reg, shift, width, parents, num_parents);
+
+	ret = clk_register(m);
 	if (ret) {
-		free(m);
+		free(to_clk_mux(m));
 		return ERR_PTR(ret);
 	}
 
-	return &m->clk;
+	return m;
 }
diff --git a/include/linux/clk.h b/include/linux/clk.h
index cf41bd7..d5e5b6b 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -197,6 +197,10 @@ struct clk *clk_divider_table(const char *name,
 		const struct clk_div_table *table);
 struct clk *clk_fixed_factor(const char *name,
 		const char *parent, unsigned int mult, unsigned int div);
+
+struct clk *clk_mux_alloc(const char *name, void __iomem *reg,
+		u8 shift, u8 width, const char **parents, u8 num_parents);
+void clk_mux_free(struct clk *clk_mux);
 struct clk *clk_mux(const char *name, void __iomem *reg,
 		u8 shift, u8 width, const char **parents, u8 num_parents);
 
-- 
1.8.2.1



From dev at lynxeye.de  Tue Jun  4 03:29:21 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Tue,  4 Jun 2013 09:29:21 +0200
Subject: [PATCH 4/6] tegra: deduplicate clk defines
In-Reply-To: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
References: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
Message-ID: <1370330963-3610-4-git-send-email-dev@lynxeye.de>

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 arch/arm/mach-tegra/include/mach/tegra20-car.h | 90 +++++++++-----------------
 arch/arm/mach-tegra/tegra_avp_init.c           |  6 +-
 2 files changed, 33 insertions(+), 63 deletions(-)

diff --git a/arch/arm/mach-tegra/include/mach/tegra20-car.h b/arch/arm/mach-tegra/include/mach/tegra20-car.h
index 5669732..54c74c7 100644
--- a/arch/arm/mach-tegra/include/mach/tegra20-car.h
+++ b/arch/arm/mach-tegra/include/mach/tegra20-car.h
@@ -111,68 +111,38 @@
 #define CRC_PLLX_MISC_VCOCON_MASK	(0xf << CRC_PLLX_MISC_VCOCON_SHIFT)
 
 #define CRC_RST_DEV_L_SET		0x300
-#define CRC_RST_DEV_L_SET_CACHE2	(1 << 31)
-#define CRC_RST_DEV_L_SET_VCP		(1 << 29)
-#define CRC_RST_DEV_L_SET_HOST1X	(1 << 28)
-#define CRC_RST_DEV_L_SET_DISP1		(1 << 27)
-#define CRC_RST_DEV_L_SET_DISP2		(1 << 26)
-#define CRC_RST_DEV_L_SET_IDE		(1 << 25)
-#define CRC_RST_DEV_L_SET_3D		(1 << 24)
-#define CRC_RST_DEV_L_SET_ISP		(1 << 23)
-#define CRC_RST_DEV_L_SET_USBD		(1 << 22)
-#define CRC_RST_DEV_L_SET_2D		(1 << 21)
-#define CRC_RST_DEV_L_SET_VI		(1 << 20)
-#define CRC_RST_DEV_L_SET_EPP		(1 << 19)
-#define CRC_RST_DEV_L_SET_I2S2		(1 << 18)
-#define CRC_RST_DEV_L_SET_PWM		(1 << 17)
-#define CRC_RST_DEV_L_SET_TWC		(1 << 16)
-#define CRC_RST_DEV_L_SET_SDMMC4	(1 << 15)
-#define CRC_RST_DEV_L_SET_SDMMC1	(1 << 14)
-#define CRC_RST_DEV_L_SET_NDFLASH	(1 << 13)
-#define CRC_RST_DEV_L_SET_I2C1		(1 << 12)
-#define CRC_RST_DEV_L_SET_I2S1		(1 << 11)
-#define CRC_RST_DEV_L_SET_SPDIF		(1 << 10)
-#define CRC_RST_DEV_L_SET_SDMMC2	(1 << 9)
-#define CRC_RST_DEV_L_SET_GPIO		(1 << 8)
-#define CRC_RST_DEV_L_SET_UART2		(1 << 7)
-#define CRC_RST_DEV_L_SET_UART1		(1 << 6)
-#define CRC_RST_DEV_L_SET_TMR		(1 << 5)
-#define CRC_RST_DEV_L_SET_AC97		(1 << 3)
-#define CRC_RST_DEV_L_SET_SYS		(1 << 2)
-#define CRC_RST_DEV_L_SET_COP		(1 << 1)
-#define CRC_RST_DEV_L_SET_CPU		(1 << 0)
+#define CRC_RST_DEV_L_CACHE2		(1 << 31)
+#define CRC_RST_DEV_L_VCP		(1 << 29)
+#define CRC_RST_DEV_L_HOST1X		(1 << 28)
+#define CRC_RST_DEV_L_DISP1		(1 << 27)
+#define CRC_RST_DEV_L_DISP2		(1 << 26)
+#define CRC_RST_DEV_L_IDE		(1 << 25)
+#define CRC_RST_DEV_L_3D		(1 << 24)
+#define CRC_RST_DEV_L_ISP		(1 << 23)
+#define CRC_RST_DEV_L_USBD		(1 << 22)
+#define CRC_RST_DEV_L_2D		(1 << 21)
+#define CRC_RST_DEV_L_VI		(1 << 20)
+#define CRC_RST_DEV_L_EPP		(1 << 19)
+#define CRC_RST_DEV_L_I2S2		(1 << 18)
+#define CRC_RST_DEV_L_PWM		(1 << 17)
+#define CRC_RST_DEV_L_TWC		(1 << 16)
+#define CRC_RST_DEV_L_SDMMC4		(1 << 15)
+#define CRC_RST_DEV_L_SDMMC1		(1 << 14)
+#define CRC_RST_DEV_L_NDFLASH		(1 << 13)
+#define CRC_RST_DEV_L_I2C1		(1 << 12)
+#define CRC_RST_DEV_L_I2S1		(1 << 11)
+#define CRC_RST_DEV_L_SPDIF		(1 << 10)
+#define CRC_RST_DEV_L_SDMMC2		(1 << 9)
+#define CRC_RST_DEV_L_GPIO		(1 << 8)
+#define CRC_RST_DEV_L_UART2		(1 << 7)
+#define CRC_RST_DEV_L_UART1		(1 << 6)
+#define CRC_RST_DEV_L_TMR		(1 << 5)
+#define CRC_RST_DEV_L_AC97		(1 << 3)
+#define CRC_RST_DEV_L_SYS		(1 << 2)
+#define CRC_RST_DEV_L_COP		(1 << 1)
+#define CRC_RST_DEV_L_CPU		(1 << 0)
 
 #define CRC_RST_DEV_L_CLR		0x304
-#define CRC_RST_DEV_L_CLR_CACHE2	(1 << 31)
-#define CRC_RST_DEV_L_CLR_VCP		(1 << 29)
-#define CRC_RST_DEV_L_CLR_HOST1X	(1 << 28)
-#define CRC_RST_DEV_L_CLR_DISP1		(1 << 27)
-#define CRC_RST_DEV_L_CLR_DISP2		(1 << 26)
-#define CRC_RST_DEV_L_CLR_IDE		(1 << 25)
-#define CRC_RST_DEV_L_CLR_3D		(1 << 24)
-#define CRC_RST_DEV_L_CLR_ISP		(1 << 23)
-#define CRC_RST_DEV_L_CLR_USBD		(1 << 22)
-#define CRC_RST_DEV_L_CLR_2D		(1 << 21)
-#define CRC_RST_DEV_L_CLR_VI		(1 << 20)
-#define CRC_RST_DEV_L_CLR_EPP		(1 << 19)
-#define CRC_RST_DEV_L_CLR_I2S2		(1 << 18)
-#define CRC_RST_DEV_L_CLR_PWM		(1 << 17)
-#define CRC_RST_DEV_L_CLR_TWC		(1 << 16)
-#define CRC_RST_DEV_L_CLR_SDMMC4	(1 << 15)
-#define CRC_RST_DEV_L_CLR_SDMMC1	(1 << 14)
-#define CRC_RST_DEV_L_CLR_NDFLASH	(1 << 13)
-#define CRC_RST_DEV_L_CLR_I2C1		(1 << 12)
-#define CRC_RST_DEV_L_CLR_I2S1		(1 << 11)
-#define CRC_RST_DEV_L_CLR_SPDIF		(1 << 10)
-#define CRC_RST_DEV_L_CLR_SDMMC2	(1 << 9)
-#define CRC_RST_DEV_L_CLR_GPIO		(1 << 8)
-#define CRC_RST_DEV_L_CLR_UART2		(1 << 7)
-#define CRC_RST_DEV_L_CLR_UART1		(1 << 6)
-#define CRC_RST_DEV_L_CLR_TMR		(1 << 5)
-#define CRC_RST_DEV_L_CLR_AC97		(1 << 3)
-#define CRC_RST_DEV_L_CLR_SYS		(1 << 2)
-#define CRC_RST_DEV_L_CLR_COP		(1 << 1)
-#define CRC_RST_DEV_L_CLR_CPU		(1 << 0)
 
 #define CRC_RST_CPU_CMPLX_SET		0x340
 
diff --git a/arch/arm/mach-tegra/tegra_avp_init.c b/arch/arm/mach-tegra/tegra_avp_init.c
index 4823733..5099e91 100644
--- a/arch/arm/mach-tegra/tegra_avp_init.c
+++ b/arch/arm/mach-tegra/tegra_avp_init.c
@@ -54,14 +54,14 @@ static void assert_maincomplex_reset(int num_cores)
 		mask |= 0x1111 << i;
 
 	writel(mask, TEGRA_CLK_RESET_BASE + CRC_RST_CPU_CMPLX_SET);
-	writel(CRC_RST_DEV_L_SET_CPU, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_SET);
+	writel(CRC_RST_DEV_L_CPU, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_SET);
 }
 
 /* release reset state of the first core of the main CPU complex */
 static void deassert_cpu0_reset(void)
 {
 	writel(0x1111, TEGRA_CLK_RESET_BASE + CRC_RST_CPU_CMPLX_CLR);
-	writel(CRC_RST_DEV_L_CLR_CPU, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_CLR);
+	writel(CRC_RST_DEV_L_CPU, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_CLR);
 }
 
 /* stop all internal and external clocks to the main CPU complex */
@@ -220,7 +220,7 @@ void barebox_arm_reset_vector(void)
 	deassert_cpu0_reset();
 
 	/* assert AVP reset to stop execution here */
-	writel(CRC_RST_DEV_L_SET_COP, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_SET);
+	writel(CRC_RST_DEV_L_COP, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_SET);
 
 	unreachable();
 }
-- 
1.8.2.1



From dev at lynxeye.de  Tue Jun  4 03:29:23 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Tue,  4 Jun 2013 09:29:23 +0200
Subject: [PATCH 6/6] tegra: add peripheral clocks
In-Reply-To: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
References: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
Message-ID: <1370330963-3610-6-git-send-email-dev@lynxeye.de>

Only UART clocks are included for now, but the code should cover
other peripherals need too.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 arch/arm/mach-tegra/include/mach/tegra20-car.h |  49 ++++++
 drivers/clk/tegra/Makefile                     |   1 +
 drivers/clk/tegra/clk-periph.c                 | 202 +++++++++++++++++++++++++
 drivers/clk/tegra/clk-tegra20.c                |  28 ++++
 drivers/clk/tegra/clk.h                        |  23 +++
 5 files changed, 303 insertions(+)
 create mode 100644 drivers/clk/tegra/clk-periph.c

diff --git a/arch/arm/mach-tegra/include/mach/tegra20-car.h b/arch/arm/mach-tegra/include/mach/tegra20-car.h
index b770ae3..d4cb238 100644
--- a/arch/arm/mach-tegra/include/mach/tegra20-car.h
+++ b/arch/arm/mach-tegra/include/mach/tegra20-car.h
@@ -146,6 +146,55 @@
 #define CRC_PLLE_BASE			0x0e8
 #define CRC_PLLE_MISC			0x0ec
 
+#define CRC_CLK_SOURCE_I2S1		0x100
+#define CRC_CLK_SOURCE_I2S2		0x104
+#define CRC_CLK_SOURCE_SPDIF_OUT	0x108
+#define CRC_CLK_SOURCE_SPDIF_IN		0x10c
+#define CRC_CLK_SOURCE_PWM		0x110
+#define CRC_CLK_SOURCE_SPI		0x114
+#define CRC_CLK_SOURCE_SBC1		0x134
+#define CRC_CLK_SOURCE_SBC2		0x118
+#define CRC_CLK_SOURCE_SBC3		0x11c
+#define CRC_CLK_SOURCE_SBC4		0x1b4
+#define CRC_CLK_SOURCE_XIO		0x120
+#define CRC_CLK_SOURCE_TWC		0x12c
+#define CRC_CLK_SOURCE_IDE		0x144
+#define CRC_CLK_SOURCE_NDFLASH		0x160
+#define CRC_CLK_SOURCE_VFIR		0x168
+#define CRC_CLK_SOURCE_SDMMC1		0x150
+#define CRC_CLK_SOURCE_SDMMC2		0x154
+#define CRC_CLK_SOURCE_SDMMC3		0x1bc
+#define CRC_CLK_SOURCE_SDMMC4		0x164
+#define CRC_CLK_SOURCE_CVE		0x140
+#define CRC_CLK_SOURCE_TVO		0x188
+#define CRC_CLK_SOURCE_TVDAC		0x194
+#define CRC_CLK_SOURCE_HDMI		0x18c
+#define CRC_CLK_SOURCE_DISP1		0x138
+#define CRC_CLK_SOURCE_DISP2		0x13c
+#define CRC_CLK_SOURCE_CSITE		0x1d4
+#define CRC_CLK_SOURCE_LA		0x1f8
+#define CRC_CLK_SOURCE_OWR		0x1cc
+#define CRC_CLK_SOURCE_NOR		0x1d0
+#define CRC_CLK_SOURCE_MIPI		0x174
+#define CRC_CLK_SOURCE_I2C1		0x124
+#define CRC_CLK_SOURCE_I2C2		0x198
+#define CRC_CLK_SOURCE_I2C3		0x1b8
+#define CRC_CLK_SOURCE_DVC		0x128
+#define CRC_CLK_SOURCE_UARTA		0x178
+#define CRC_CLK_SOURCE_UARTB		0x17c
+#define CRC_CLK_SOURCE_UARTC		0x1a0
+#define CRC_CLK_SOURCE_UARTD		0x1c0
+#define CRC_CLK_SOURCE_UARTE		0x1c4
+#define CRC_CLK_SOURCE_3D		0x158
+#define CRC_CLK_SOURCE_2D		0x15c
+#define CRC_CLK_SOURCE_MPE		0x170
+#define CRC_CLK_SOURCE_EPP		0x16c
+#define CRC_CLK_SOURCE_HOST1X		0x180
+#define CRC_CLK_SOURCE_VDE		0x1c8
+#define CRC_CLK_SOURCE_VI		0x148
+#define CRC_CLK_SOURCE_VI_SENSOR	0x1a8
+#define CRC_CLK_SOURCE_EMC		0x19c
+
 #define CRC_RST_DEV_L_SET		0x300
 #define CRC_RST_DEV_L_CACHE2		(1 << 31)
 #define CRC_RST_DEV_L_VCP		(1 << 29)
diff --git a/drivers/clk/tegra/Makefile b/drivers/clk/tegra/Makefile
index be58c20..e614722 100644
--- a/drivers/clk/tegra/Makefile
+++ b/drivers/clk/tegra/Makefile
@@ -1,5 +1,6 @@
 obj-y	+= clk.o
 obj-y	+= clk-divider.o
+obj-y	+= clk-periph.o
 obj-y	+= clk-pll.o
 obj-y	+= clk-pll-out.o
 
diff --git a/drivers/clk/tegra/clk-periph.c b/drivers/clk/tegra/clk-periph.c
new file mode 100644
index 0000000..e969495
--- /dev/null
+++ b/drivers/clk/tegra/clk-periph.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <io.h>
+#include <malloc.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+#define to_clk_periph(_hw) container_of(_hw, struct tegra_clk_periph, hw)
+
+static int clk_periph_get_parent(struct clk *hw)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->mux->ops->get_parent(periph->mux);
+}
+
+static int clk_periph_set_parent(struct clk *hw, u8 index)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->mux->ops->set_parent(periph->mux, index);
+}
+
+static unsigned long clk_periph_recalc_rate(struct clk *hw,
+					    unsigned long parent_rate)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->div->ops->recalc_rate(periph->div, parent_rate);
+}
+
+static long clk_periph_round_rate(struct clk *hw, unsigned long rate,
+				  unsigned long *prate)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->div->ops->round_rate(periph->div, rate, prate);
+}
+
+static int clk_periph_set_rate(struct clk *hw, unsigned long rate,
+			       unsigned long parent_rate)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->div->ops->set_rate(periph->div, rate, parent_rate);
+}
+
+static int clk_periph_is_enabled(struct clk *hw)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->gate->ops->is_enabled(periph->gate);
+}
+
+static int clk_periph_enable(struct clk *hw)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+	u32 reg;
+
+	reg = readl(periph->rst_reg);
+	reg |= (1 << periph->rst_shift);
+	writel(reg, periph->rst_reg);
+
+	periph->gate->ops->enable(periph->gate);
+
+	udelay(2);
+
+	reg = readl(periph->rst_reg);
+	reg &= ~(1 << periph->rst_shift);
+	writel(reg, periph->rst_reg);
+
+	return 0;
+}
+
+static void clk_periph_disable(struct clk *hw)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+	u32 reg;
+
+	reg = readl(periph->rst_reg);
+	reg |= (1 << periph->rst_shift);
+	writel(reg, periph->rst_reg);
+
+	udelay(2);
+
+	periph->gate->ops->disable(periph->gate);
+}
+
+const struct clk_ops tegra_clk_periph_ops = {
+	.get_parent = clk_periph_get_parent,
+	.set_parent = clk_periph_set_parent,
+	.recalc_rate = clk_periph_recalc_rate,
+	.round_rate = clk_periph_round_rate,
+	.set_rate = clk_periph_set_rate,
+	.is_enabled = clk_periph_is_enabled,
+	.enable = clk_periph_enable,
+	.disable = clk_periph_disable,
+};
+
+const struct clk_ops tegra_clk_periph_nodiv_ops = {
+	.get_parent = clk_periph_get_parent,
+	.set_parent = clk_periph_set_parent,
+	.is_enabled = clk_periph_is_enabled,
+	.enable = clk_periph_enable,
+	.disable = clk_periph_disable,
+};
+
+struct clk *_tegra_clk_register_periph(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags,
+		bool has_div)
+{
+	struct tegra_clk_periph *periph;
+	int ret;
+
+	periph = kzalloc(sizeof(*periph), GFP_KERNEL);
+	if (!periph) {
+		pr_err("%s: could not allocate peripheral clk\n",
+		       __func__);
+		goto out_periph;
+	}
+
+	periph->mux = clk_mux_alloc(NULL, clk_base + reg_offset, 30, 2,
+				    parent_names, num_parents);
+	if (!periph->mux)
+		goto out_mux;
+
+	periph->gate = clk_gate_alloc(NULL, NULL, clk_base + 0x10 +
+				      ((id >> 3) & 0xc), id & 0x1f);
+	if (!periph->gate)
+		goto out_gate;
+
+	if (has_div) {
+		periph->div = tegra_clk_divider_alloc(NULL, NULL, clk_base +
+				reg_offset, 0, TEGRA_DIVIDER_ROUND_UP, 0, 8, 1);
+		if (!periph->div)
+			goto out_div;
+	}
+
+	periph->hw.name = name;
+	periph->hw.ops = has_div ? &tegra_clk_periph_ops :
+				   &tegra_clk_periph_nodiv_ops;
+	periph->hw.parent_names = parent_names;
+	periph->hw.num_parents = num_parents;
+	periph->flags = flags;
+	periph->rst_reg = clk_base + 0x4 + ((id >> 3) & 0xc);
+	periph->rst_shift = id & 0x1f;
+
+	ret = clk_register(&periph->hw);
+	if (ret)
+		goto out_register;
+
+	return &periph->hw;
+
+out_register:
+	tegra_clk_divider_free(periph->div);
+out_div:
+	clk_gate_free(periph->gate);
+out_gate:
+	clk_mux_free(periph->mux);
+out_mux:
+	kfree(periph);
+out_periph:
+	return NULL;
+}
+
+struct clk *tegra_clk_register_periph_nodiv(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags)
+{
+	return _tegra_clk_register_periph(name, parent_names, num_parents,
+					  clk_base, reg_offset, id, flags,
+					  false);
+}
+
+struct clk *tegra_clk_register_periph(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags)
+{
+	return _tegra_clk_register_periph(name, parent_names, num_parents,
+					  clk_base, reg_offset, id, flags,
+					  true);
+}
diff --git a/drivers/clk/tegra/clk-tegra20.c b/drivers/clk/tegra/clk-tegra20.c
index 5f668cb..e70f99a 100644
--- a/drivers/clk/tegra/clk-tegra20.c
+++ b/drivers/clk/tegra/clk-tegra20.c
@@ -275,6 +275,28 @@ static void tegra20_pll_init(void)
 			TEGRA_PLL_HAS_CPCON, pll_u_freq_table);
 }
 
+static const char *mux_pllpcm_clkm[] = {"pll_p", "pll_c", "pll_m", "clk_m"};
+
+static void tegra20_periph_init(void)
+{
+	/* peripheral clocks without a divider */
+	clks[uarta] = tegra_clk_register_periph_nodiv("uarta", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTA, uarta, TEGRA_PERIPH_ON_APB);
+	clks[uartb] = tegra_clk_register_periph_nodiv("uartb", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTB, uartb, TEGRA_PERIPH_ON_APB);
+	clks[uartc] = tegra_clk_register_periph_nodiv("uartc", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTC, uartc, TEGRA_PERIPH_ON_APB);
+	clks[uartd] = tegra_clk_register_periph_nodiv("uartd", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTD, uartd, TEGRA_PERIPH_ON_APB);
+	clks[uarte] = tegra_clk_register_periph_nodiv("uarte", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTE, uarte, TEGRA_PERIPH_ON_APB);
+}
+
 static struct tegra_clk_init_table init_table[] = {
 	{pll_p,		clk_max,	216000000,	1},
 	{pll_p_out1,	clk_max,	28800000,	1},
@@ -283,6 +305,11 @@ static struct tegra_clk_init_table init_table[] = {
 	{pll_p_out4,	clk_max,	24000000,	1},
 	{pll_c,		clk_max,	600000000,	1},
 	{pll_c_out1,	clk_max,	120000000,	1},
+	{uarta,		pll_p,		0,		1},
+	{uartb,		pll_p,		0,		1},
+	{uartc,		pll_p,		0,		1},
+	{uartd,		pll_p,		0,		1},
+	{uarte,		pll_p,		0,		1},
 	{clk_max,	clk_max,	0,		0}, /* sentinel */
 };
 
@@ -294,6 +321,7 @@ static int tegra20_car_probe(struct device_d *dev)
 
 	tegra20_osc_clk_init();
 	tegra20_pll_init();
+	tegra20_periph_init();
 
 	tegra_init_from_table(init_table, clks, clk_max);
 
diff --git a/drivers/clk/tegra/clk.h b/drivers/clk/tegra/clk.h
index 2bc3698..9bb8f1c 100644
--- a/drivers/clk/tegra/clk.h
+++ b/drivers/clk/tegra/clk.h
@@ -115,6 +115,29 @@ struct clk *tegra_clk_register_pll_out(const char *name,
 		const char *parent_name, void __iomem *reg, u8 shift,
 		u8 divider_flags);
 
+/* struct clk-periph - peripheral clock */
+struct tegra_clk_periph {
+	struct clk	hw;
+	struct clk	*gate;
+	struct clk	*mux;
+	struct clk	*div;
+	u8 		flags;
+	u8		rst_shift;
+	void __iomem	*rst_reg;
+};
+
+#define TEGRA_PERIPH_NO_RESET BIT(0)
+#define TEGRA_PERIPH_MANUAL_RESET BIT(1)
+#define TEGRA_PERIPH_ON_APB BIT(2)
+
+struct clk *tegra_clk_register_periph_nodiv(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags);
+
+struct clk *tegra_clk_register_periph(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags);
+
 /* struct clk_init_table - clock initialization table */
 struct tegra_clk_init_table {
 	unsigned int	clk_id;
-- 
1.8.2.1



From dev at lynxeye.de  Tue Jun  4 03:29:22 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Tue,  4 Jun 2013 09:29:22 +0200
Subject: [PATCH 5/6] tegra: add new clock framework driver
In-Reply-To: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
References: <1370330963-3610-1-git-send-email-dev@lynxeye.de>
Message-ID: <1370330963-3610-5-git-send-email-dev@lynxeye.de>

This removes the existing Tegra CAR driver and replaces it with code
ported from the Linux clock framework.

In the current state only the relevant PLLs are supported, but this is
no functional regression from the existing code.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 arch/arm/mach-tegra/Makefile                   |   1 -
 arch/arm/mach-tegra/include/mach/tegra20-car.h |  36 ++
 arch/arm/mach-tegra/tegra20-car.c              | 120 -------
 drivers/clk/Makefile                           |   3 +
 drivers/clk/tegra/Makefile                     |   6 +
 drivers/clk/tegra/clk-divider.c                | 201 +++++++++++
 drivers/clk/tegra/clk-pll-out.c                | 139 ++++++++
 drivers/clk/tegra/clk-pll.c                    | 451 +++++++++++++++++++++++++
 drivers/clk/tegra/clk-tegra20.c                | 326 ++++++++++++++++++
 drivers/clk/tegra/clk.c                        |  57 ++++
 drivers/clk/tegra/clk.h                        | 127 +++++++
 11 files changed, 1346 insertions(+), 121 deletions(-)
 delete mode 100644 arch/arm/mach-tegra/tegra20-car.c
 create mode 100644 drivers/clk/tegra/Makefile
 create mode 100644 drivers/clk/tegra/clk-divider.c
 create mode 100644 drivers/clk/tegra/clk-pll-out.c
 create mode 100644 drivers/clk/tegra/clk-pll.c
 create mode 100644 drivers/clk/tegra/clk-tegra20.c
 create mode 100644 drivers/clk/tegra/clk.c
 create mode 100644 drivers/clk/tegra/clk.h

diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile
index f9c771f..fd6a870 100644
--- a/arch/arm/mach-tegra/Makefile
+++ b/arch/arm/mach-tegra/Makefile
@@ -2,6 +2,5 @@ CFLAGS_tegra_avp_init.o := -mcpu=arm7tdmi -march=armv4t
 lwl-y += tegra_avp_init.o
 lwl-y += tegra_maincomplex_init.o
 obj-y += tegra20.o
-obj-y += tegra20-car.o
 obj-y += tegra20-pmc.o
 obj-y += tegra20-timer.o
diff --git a/arch/arm/mach-tegra/include/mach/tegra20-car.h b/arch/arm/mach-tegra/include/mach/tegra20-car.h
index 54c74c7..b770ae3 100644
--- a/arch/arm/mach-tegra/include/mach/tegra20-car.h
+++ b/arch/arm/mach-tegra/include/mach/tegra20-car.h
@@ -82,6 +82,39 @@
 #define CRC_OSC_CTRL_PLL_REF_DIV_SHIFT	28
 #define CRC_OSC_CTRL_PLL_REF_DIV_MASK	(0x3 << CRC_OSC_CTRL_PLL_REF_DIV_SHIFT)
 
+#define CRC_PLL_BASE_LOCK		27
+#define CRC_PLLE_MISC_LOCK		11
+
+#define CRC_PLL_MISC_LOCK_ENABLE	18
+#define CRC_PLLDU_MISC_LOCK_ENABLE	22
+#define CRC_PLLE_MISC_LOCK_ENABLE	9
+
+#define CRC_PLLS_BASE			0x0f0
+#define CRC_PLLS_MISC			0x0f4
+
+#define CRC_PLLC_BASE			0x080
+#define CRC_PLLC_OUT			0x084
+#define CRC_PLLC_MISC			0x08c
+
+#define CRC_PLLM_BASE			0x090
+#define CRC_PLLM_OUT			0x094
+#define CRC_PLLM_MISC			0x09c
+
+#define CRC_PLLP_BASE			0x0a0
+#define CRC_PLLP_OUTA			0x0a4
+#define CRC_PLLP_OUTB			0x0a8
+#define CRC_PLLP_MISC			0x0ac
+
+#define CRC_PLLA_BASE			0x0b0
+#define CRC_PLLA_OUT			0x0b4
+#define CRC_PLLA_MISC			0x0bc
+
+#define CRC_PLLU_BASE			0x0c0
+#define CRC_PLLU_MISC			0x0cc
+
+#define CRC_PLLD_BASE			0x0d0
+#define CRC_PLLD_MISC			0x0dc
+
 #define CRC_PLLX_BASE			0x0e0
 #define CRC_PLLX_BASE_BYPASS		(1 << 31)
 #define CRC_PLLX_BASE_ENABLE		(1 << 30)
@@ -110,6 +143,9 @@
 #define CRC_PLLX_MISC_VCOCON_SHIFT	0
 #define CRC_PLLX_MISC_VCOCON_MASK	(0xf << CRC_PLLX_MISC_VCOCON_SHIFT)
 
+#define CRC_PLLE_BASE			0x0e8
+#define CRC_PLLE_MISC			0x0ec
+
 #define CRC_RST_DEV_L_SET		0x300
 #define CRC_RST_DEV_L_CACHE2		(1 << 31)
 #define CRC_RST_DEV_L_VCP		(1 << 29)
diff --git a/arch/arm/mach-tegra/tegra20-car.c b/arch/arm/mach-tegra/tegra20-car.c
deleted file mode 100644
index 3af7bdc..0000000
--- a/arch/arm/mach-tegra/tegra20-car.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * @file
- * @brief Device driver for the Tegra 20 clock and reset (CAR) controller
- */
-
-#include <common.h>
-#include <init.h>
-#include <io.h>
-#include <linux/clk.h>
-#include <linux/clkdev.h>
-#include <linux/err.h>
-#include <mach/iomap.h>
-
-#include <mach/tegra20-car.h>
-
-static void __iomem *car_base;
-
-enum tegra20_clks {
-	cpu, ac97 = 3, rtc, timer, uarta, gpio = 8, sdmmc2, i2s1 = 11, i2c1,
-	ndflash, sdmmc1, sdmmc4, twc, pwm, i2s2, epp, gr2d = 21, usbd, isp,
-	gr3d, ide, disp2, disp1, host1x, vcp, cache2 = 31, mem, ahbdma, apbdma,
-	kbc = 36, stat_mon, pmc, fuse, kfuse, sbc1, nor, spi, sbc2, xio, sbc3,
-	dvc, dsi, mipi = 50, hdmi, csi, tvdac, i2c2, uartc, emc = 57, usb2,
-	usb3, mpe, vde, bsea, bsev, speedo, uartd, uarte, i2c3, sbc4, sdmmc3,
-	pex, owr, afi, csite, pcie_xclk, avpucq = 75, la, irama = 84, iramb,
-	iramc, iramd, cram2, audio_2x, clk_d, csus = 92, cdev1, cdev2,
-	uartb = 96, vfir, spdif_in, spdif_out, vi, vi_sensor, tvo, cve,
-	osc, clk_32k, clk_m, sclk, cclk, hclk, pclk, blink, pll_a, pll_a_out0,
-	pll_c, pll_c_out1, pll_d, pll_d_out0, pll_e, pll_m, pll_m_out1,
-	pll_p, pll_p_out1, pll_p_out2, pll_p_out3, pll_p_out4, pll_u,
-	pll_x, audio, pll_ref, twd, clk_max,
-};
-
-static struct clk *clks[clk_max];
-
-static unsigned long get_osc_frequency(void)
-{
-	u32 osc_ctrl = readl(car_base + CRC_OSC_CTRL);
-
-	switch ((osc_ctrl & CRC_OSC_CTRL_OSC_FREQ_MASK) >>
-		CRC_OSC_CTRL_OSC_FREQ_SHIFT) {
-	case 0:
-		return 13000000;
-	case 1:
-		return 19200000;
-	case 2:
-		return 12000000;
-	case 3:
-		return 26000000;
-	default:
-		return 0;
-	}
-}
-
-static unsigned int get_pll_ref_div(void)
-{
-	u32 osc_ctrl = readl(car_base + CRC_OSC_CTRL);
-
-	return 1U << ((osc_ctrl & CRC_OSC_CTRL_PLL_REF_DIV_MASK) >>
-		      CRC_OSC_CTRL_PLL_REF_DIV_SHIFT);
-}
-
-static int tegra20_car_probe(struct device_d *dev)
-{
-	car_base = dev_request_mem_region(dev, 0);
-	if (!car_base)
-		return -EBUSY;
-
-	/* primary clocks */
-	clks[clk_m] = clk_fixed("clk_m", get_osc_frequency());
-	clks[clk_32k] = clk_fixed("clk_32k", 32768);
-
-	clks[pll_ref] = clk_fixed_factor("pll_ref", "clk_m", 1,
-					 get_pll_ref_div());
-
-	/* derived clocks */
-	/* timer is a gate, but as it's enabled by BOOTROM we needn't worry */
-	clks[timer] = clk_fixed_factor("timer", "clk_m", 1, 1);
-
-	/* device to clock links */
-	clkdev_add_physbase(clks[timer], TEGRA_TMR1_BASE, NULL);
-
-	return 0;
-}
-
-static __maybe_unused struct of_device_id tegra20_car_dt_ids[] = {
-	{
-		.compatible = "nvidia,tegra20-car",
-	}, {
-		/* sentinel */
-	}
-};
-
-static struct driver_d tegra20_car_driver = {
-	.probe	= tegra20_car_probe,
-	.name	= "tegra20-car",
-	.of_compatible = DRV_OF_COMPAT(tegra20_car_dt_ids),
-};
-
-static int tegra20_car_init(void)
-{
-	return platform_driver_register(&tegra20_car_driver);
-}
-postcore_initcall(tegra20_car_init);
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 656b859..b19ce91 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -1,3 +1,6 @@
 obj-$(CONFIG_COMMON_CLK)	+= clk.o clk-fixed.o clk-divider.o clk-fixed-factor.o \
 				clk-mux.o clk-gate.o clk-divider-table.o
 obj-$(CONFIG_CLKDEV_LOOKUP)	+= clkdev.o
+
+#SoC specific
+obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
diff --git a/drivers/clk/tegra/Makefile b/drivers/clk/tegra/Makefile
new file mode 100644
index 0000000..be58c20
--- /dev/null
+++ b/drivers/clk/tegra/Makefile
@@ -0,0 +1,6 @@
+obj-y	+= clk.o
+obj-y	+= clk-divider.o
+obj-y	+= clk-pll.o
+obj-y	+= clk-pll-out.o
+
+obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= clk-tegra20.o
\ No newline at end of file
diff --git a/drivers/clk/tegra/clk-divider.c b/drivers/clk/tegra/clk-divider.c
new file mode 100644
index 0000000..0ddd64e
--- /dev/null
+++ b/drivers/clk/tegra/clk-divider.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <io.h>
+#include <malloc.h>
+#include <asm-generic/div64.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+#define pll_out_override(p) (BIT((p->shift - 6)))
+#define div_mask(d) ((1 << (d->width)) - 1)
+#define get_mul(d) (1 << d->frac_width)
+#define get_max_div(d) div_mask(d)
+
+#define PERIPH_CLK_UART_DIV_ENB BIT(24)
+
+#define to_clk_frac_div(_hw) container_of(_hw, struct tegra_clk_frac_div, hw)
+
+static int get_div(struct tegra_clk_frac_div *divider, unsigned long rate,
+		   unsigned long parent_rate)
+{
+	u64 divider_ux1 = parent_rate;
+	u8 flags = divider->flags;
+	int mul;
+
+	if (!rate)
+		return 0;
+
+	mul = get_mul(divider);
+
+	if (!(flags & TEGRA_DIVIDER_INT))
+		divider_ux1 *= mul;
+
+	if (flags & TEGRA_DIVIDER_ROUND_UP)
+		divider_ux1 += rate - 1;
+
+	do_div(divider_ux1, rate);
+
+	if (flags & TEGRA_DIVIDER_INT)
+		divider_ux1 *= mul;
+
+	divider_ux1 -= mul;
+
+	if (divider_ux1 < 0)
+		return 0;
+
+	if (divider_ux1 > get_max_div(divider))
+		return -EINVAL;
+
+	return divider_ux1;
+}
+
+static unsigned long clk_frac_div_recalc_rate(struct clk *hw,
+					     unsigned long parent_rate)
+{
+	struct tegra_clk_frac_div *divider = to_clk_frac_div(hw);
+	u32 reg;
+	int div, mul;
+	u64 rate = parent_rate;
+
+	reg = readl(divider->reg) >> divider->shift;
+	div = reg & div_mask(divider);
+
+	mul = get_mul(divider);
+	div += mul;
+
+	rate *= mul;
+	rate += div - 1;
+	do_div(rate, div);
+
+	return rate;
+}
+
+static long clk_frac_div_round_rate(struct clk *hw, unsigned long rate,
+				   unsigned long *prate)
+{
+	struct tegra_clk_frac_div *divider = to_clk_frac_div(hw);
+	int div, mul;
+	unsigned long output_rate = *prate;
+
+	if (!rate)
+		return output_rate;
+
+	div = get_div(divider, rate, output_rate);
+	if (div < 0)
+		return *prate;
+
+	mul = get_mul(divider);
+
+	return DIV_ROUND_UP(output_rate * mul, div + mul);
+}
+
+static int clk_frac_div_set_rate(struct clk *hw, unsigned long rate,
+				unsigned long parent_rate)
+{
+	struct tegra_clk_frac_div *divider = to_clk_frac_div(hw);
+	int div;
+	u32 val;
+
+	div = get_div(divider, rate, parent_rate);
+	if (div < 0)
+		return div;
+
+	val = readl(divider->reg);
+	val &= ~(div_mask(divider) << divider->shift);
+	val |= div << divider->shift;
+
+	if (divider->flags & TEGRA_DIVIDER_UART) {
+		if (div)
+			val |= PERIPH_CLK_UART_DIV_ENB;
+		else
+			val &= ~PERIPH_CLK_UART_DIV_ENB;
+	}
+
+	if (divider->flags & TEGRA_DIVIDER_FIXED)
+		val |= pll_out_override(divider);
+
+	writel(val, divider->reg);
+
+	return 0;
+}
+
+const struct clk_ops tegra_clk_frac_div_ops = {
+	.recalc_rate = clk_frac_div_recalc_rate,
+	.set_rate = clk_frac_div_set_rate,
+	.round_rate = clk_frac_div_round_rate,
+};
+
+struct clk *tegra_clk_divider_alloc(const char *name, const char *parent_name,
+		void __iomem *reg, unsigned long flags, u8 clk_divider_flags,
+		u8 shift, u8 width, u8 frac_width)
+{
+	struct tegra_clk_frac_div *divider;
+
+	divider = kzalloc(sizeof(*divider), GFP_KERNEL);
+	if (!divider) {
+		pr_err("%s: could not allocate fractional divider clk\n",
+		       __func__);
+		return NULL;
+	}
+
+	divider->parent = parent_name;
+	divider->hw.name = name;
+	divider->hw.ops = &tegra_clk_frac_div_ops;
+	divider->hw.flags = flags;
+	divider->hw.parent_names = divider->parent ? &divider->parent : NULL;
+	divider->hw.num_parents = divider->parent ? 1 : 0;
+
+	divider->reg = reg;
+	divider->shift = shift;
+	divider->width = width;
+	divider->frac_width = frac_width;
+	divider->flags = clk_divider_flags;
+
+	return &divider->hw;
+}
+
+void tegra_clk_divider_free(struct clk *clk_div)
+{
+	struct tegra_clk_frac_div *divider = to_clk_frac_div(clk_div);
+
+	kfree(divider);
+}
+
+struct clk *tegra_clk_register_divider(const char *name,
+		const char *parent_name, void __iomem *reg, unsigned long flags,
+		u8 clk_divider_flags, u8 shift, u8 width, u8 frac_width)
+{
+	struct tegra_clk_frac_div *divider;
+	int ret;
+
+	divider = to_clk_frac_div(tegra_clk_divider_alloc(name, parent_name,
+				  reg, flags, clk_divider_flags, shift, width,
+				  frac_width));
+
+	ret = clk_register(&divider->hw);
+	if (ret) {
+		kfree(divider);
+		return ERR_PTR(ret);
+	}
+
+	return &divider->hw;
+}
diff --git a/drivers/clk/tegra/clk-pll-out.c b/drivers/clk/tegra/clk-pll-out.c
new file mode 100644
index 0000000..52d8473
--- /dev/null
+++ b/drivers/clk/tegra/clk-pll-out.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <io.h>
+#include <malloc.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+#define pll_out_enb(p) (BIT(p->enb_bit_idx))
+#define pll_out_rst(p) (BIT(p->rst_bit_idx))
+
+#define to_clk_pll_out(_hw) container_of(_hw, struct tegra_clk_pll_out, hw)
+
+static int clk_pll_out_is_enabled(struct clk *hw)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+	u32 val = readl(pll_out->reg);
+	int state;
+
+	state = (val & pll_out_enb(pll_out)) ? 1 : 0;
+	if (!(val & (pll_out_rst(pll_out))))
+		state = 0;
+	return state;
+}
+
+static int clk_pll_out_enable(struct clk *hw)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+	u32 val;
+
+	val = readl(pll_out->reg);
+
+	val |= (pll_out_enb(pll_out) | pll_out_rst(pll_out));
+
+	writel(val, pll_out->reg);
+	udelay(2);
+
+	return 0;
+}
+
+static void clk_pll_out_disable(struct clk *hw)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+	u32 val;
+
+	val = readl(pll_out->reg);
+
+	val &= ~(pll_out_enb(pll_out) | pll_out_rst(pll_out));
+
+	writel(val, pll_out->reg);
+	udelay(2);
+}
+
+static unsigned long clk_pll_out_recalc_rate(struct clk *hw,
+					     unsigned long parent_rate)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+
+	return pll_out->div->ops->recalc_rate(pll_out->div, parent_rate);
+}
+
+static long clk_pll_out_round_rate(struct clk *hw, unsigned long rate,
+				   unsigned long *prate)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+
+	return pll_out->div->ops->round_rate(pll_out->div, rate, prate);
+}
+
+static int clk_pll_out_set_rate(struct clk *hw, unsigned long rate,
+				unsigned long parent_rate)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+
+	return pll_out->div->ops->set_rate(pll_out->div, rate, parent_rate);
+}
+
+const struct clk_ops tegra_clk_pll_out_ops = {
+	.is_enabled = clk_pll_out_is_enabled,
+	.enable = clk_pll_out_enable,
+	.disable = clk_pll_out_disable,
+	.recalc_rate = clk_pll_out_recalc_rate,
+	.round_rate = clk_pll_out_round_rate,
+	.set_rate = clk_pll_out_set_rate,
+};
+
+struct clk *tegra_clk_register_pll_out(const char *name,
+		const char *parent_name, void __iomem *reg, u8 shift, u8 divider_flags)
+{
+	struct tegra_clk_pll_out *pll_out;
+	int ret;
+
+	pll_out = kzalloc(sizeof(*pll_out), GFP_KERNEL);
+	if (!pll_out)
+		return NULL;
+
+	pll_out->div = tegra_clk_divider_alloc(NULL, NULL, reg, 0, divider_flags, shift + 8, 8, 1);
+	if (!pll_out->div) {
+		kfree(pll_out);
+		return NULL;
+	}
+
+	pll_out->parent = parent_name;
+	pll_out->hw.name = name;
+	pll_out->hw.ops = &tegra_clk_pll_out_ops;
+	pll_out->hw.parent_names = (pll_out->parent ? &pll_out->parent : NULL);
+	pll_out->hw.num_parents = (pll_out->parent ? 1 : 0);
+
+	pll_out->reg = reg;
+	pll_out->enb_bit_idx = shift + 1;
+	pll_out->rst_bit_idx = shift;
+
+	ret = clk_register(&pll_out->hw);
+	if (ret) {
+		tegra_clk_divider_free(pll_out->div);
+		kfree(pll_out);
+		return ERR_PTR(ret);
+	}
+
+	return &pll_out->hw;
+}
diff --git a/drivers/clk/tegra/clk-pll.c b/drivers/clk/tegra/clk-pll.c
new file mode 100644
index 0000000..f3257c4
--- /dev/null
+++ b/drivers/clk/tegra/clk-pll.c
@@ -0,0 +1,451 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <io.h>
+#include <malloc.h>
+#include <asm-generic/div64.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+#define PLL_BASE_BYPASS		BIT(31)
+#define PLL_BASE_ENABLE		BIT(30)
+#define PLL_BASE_REF_ENABLE	BIT(29)
+#define PLL_BASE_OVERRIDE	BIT(28)
+
+#define PLL_BASE_DIVP_SHIFT	20
+#define PLL_BASE_DIVP_WIDTH	3
+#define PLL_BASE_DIVN_SHIFT	8
+#define PLL_BASE_DIVN_WIDTH	10
+#define PLL_BASE_DIVM_SHIFT	0
+#define PLL_BASE_DIVM_WIDTH	5
+#define PLLU_POST_DIVP_MASK	0x1
+
+#define PLL_MISC_DCCON_SHIFT	20
+#define PLL_MISC_CPCON_SHIFT	8
+#define PLL_MISC_CPCON_WIDTH	4
+#define PLL_MISC_CPCON_MASK	((1 << PLL_MISC_CPCON_WIDTH) - 1)
+#define PLL_MISC_LFCON_SHIFT	4
+#define PLL_MISC_LFCON_WIDTH	4
+#define PLL_MISC_LFCON_MASK	((1 << PLL_MISC_LFCON_WIDTH) - 1)
+#define PLL_MISC_VCOCON_SHIFT	0
+#define PLL_MISC_VCOCON_WIDTH	4
+#define PLL_MISC_VCOCON_MASK	((1 << PLL_MISC_VCOCON_WIDTH) - 1)
+
+#define OUT_OF_TABLE_CPCON	8
+
+#define PMC_PLLP_WB0_OVERRIDE			0xf8
+#define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE	BIT(12)
+#define PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE	BIT(11)
+
+#define PLL_POST_LOCK_DELAY	50
+
+#define PLLDU_LFCON_SET_DIVN	600
+
+#define PLLE_BASE_DIVCML_SHIFT	24
+#define PLLE_BASE_DIVCML_WIDTH	4
+#define PLLE_BASE_DIVP_SHIFT	16
+#define PLLE_BASE_DIVP_WIDTH	7
+#define PLLE_BASE_DIVN_SHIFT	8
+#define PLLE_BASE_DIVN_WIDTH	8
+#define PLLE_BASE_DIVM_SHIFT	0
+#define PLLE_BASE_DIVM_WIDTH	8
+
+#define PLLE_MISC_SETUP_BASE_SHIFT	16
+#define PLLE_MISC_SETUP_BASE_MASK	(0xffff << PLLE_MISC_SETUP_BASE_SHIFT)
+#define PLLE_MISC_LOCK_ENABLE		BIT(9)
+#define PLLE_MISC_READY			BIT(15)
+#define PLLE_MISC_SETUP_EX_SHIFT	2
+#define PLLE_MISC_SETUP_EX_MASK		(3 << PLLE_MISC_SETUP_EX_SHIFT)
+#define PLLE_MISC_SETUP_MASK		(PLLE_MISC_SETUP_BASE_MASK |	\
+					 PLLE_MISC_SETUP_EX_MASK)
+#define PLLE_MISC_SETUP_VALUE		(7 << PLLE_MISC_SETUP_BASE_SHIFT)
+
+#define PLLE_SS_CTRL		0x68
+#define PLLE_SS_DISABLE		(7 << 10)
+
+#define PMC_SATA_PWRGT			0x1ac
+#define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE	BIT(5)
+#define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL	BIT(4)
+
+#define pll_readl(offset, p) readl(p->clk_base + offset)
+#define pll_readl_base(p) pll_readl(p->params->base_reg, p)
+#define pll_readl_misc(p) pll_readl(p->params->misc_reg, p)
+
+#define pll_writel(val, offset, p) writel(val, p->clk_base + offset)
+#define pll_writel_base(val, p) pll_writel(val, p->params->base_reg, p)
+#define pll_writel_misc(val, p) pll_writel(val, p->params->misc_reg, p)
+
+#define mask(w) ((1 << (w)) - 1)
+#define divm_mask(p) mask(p->divm_width)
+#define divn_mask(p) mask(p->divn_width)
+#define divp_mask(p) (p->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :	\
+		      mask(p->divp_width))
+
+#define divm_max(p) (divm_mask(p))
+#define divn_max(p) (divn_mask(p))
+#define divp_max(p) (1 << (divp_mask(p)))
+
+#define to_clk_pll(_hw) container_of(_hw, struct tegra_clk_pll, hw)
+
+static int clk_pll_is_enabled(struct clk *hw)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 val;
+
+	val = pll_readl_base(pll);
+
+	return val & PLL_BASE_ENABLE ? 1 : 0;
+}
+
+static void clk_pll_enable_lock(struct tegra_clk_pll *pll)
+{
+	u32 val;
+
+	if (!(pll->flags & TEGRA_PLL_USE_LOCK))
+		return;
+
+	val = pll_readl_misc(pll);
+	val |= BIT(pll->params->lock_enable_bit_idx);
+	pll_writel_misc(val, pll);
+}
+
+static int clk_pll_wait_for_lock(struct tegra_clk_pll *pll,
+				 void __iomem *lock_addr, u32 lock_bit_idx)
+{
+	int i;
+	u32 val;
+
+	if (!(pll->flags & TEGRA_PLL_USE_LOCK)) {
+		udelay(pll->params->lock_delay);
+		return 0;
+	}
+
+	for (i = 0; i < pll->params->lock_delay; i++) {
+		val = readl(lock_addr);
+		if (val & BIT(lock_bit_idx)) {
+			udelay(PLL_POST_LOCK_DELAY);
+			return 0;
+		}
+		udelay(2); /* timeout = 2 * lock time */
+	}
+
+	pr_err("%s: Timed out waiting for pll %s lock\n", __func__,
+	       pll->hw.name);
+
+	return -1;
+}
+
+static int clk_pll_enable(struct clk *hw)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 val;
+
+	clk_pll_enable_lock(pll);
+
+	val = pll_readl_base(pll);
+	val &= ~PLL_BASE_BYPASS;
+	val |= PLL_BASE_ENABLE;
+	pll_writel_base(val, pll);
+
+	clk_pll_wait_for_lock(pll, pll->clk_base + pll->params->base_reg,
+			      pll->params->lock_bit_idx);
+
+	return 0;
+}
+
+static void clk_pll_disable(struct clk *hw)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 val;
+
+	val = pll_readl_base(pll);
+	val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
+	pll_writel_base(val, pll);
+}
+
+static int _get_table_rate(struct clk *hw,
+			   struct tegra_clk_pll_freq_table *cfg,
+			   unsigned long rate, unsigned long parent_rate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	struct tegra_clk_pll_freq_table *sel;
+
+	for (sel = pll->freq_table; sel->input_rate != 0; sel++)
+		if (sel->input_rate == parent_rate &&
+		    sel->output_rate == rate)
+			break;
+
+	if (sel->input_rate == 0)
+		return -EINVAL;
+
+	BUG_ON(sel->p < 1);
+
+	cfg->input_rate = sel->input_rate;
+	cfg->output_rate = sel->output_rate;
+	cfg->m = sel->m;
+	cfg->n = sel->n;
+	cfg->p = sel->p;
+	cfg->cpcon = sel->cpcon;
+
+	return 0;
+}
+
+static unsigned long clk_pll_recalc_rate(struct clk *hw,
+					 unsigned long parent_rate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 val = pll_readl_base(pll);
+	u32 divn = 0, divm = 0, divp = 0;
+	u64 rate = parent_rate;
+
+	if (val & PLL_BASE_BYPASS)
+		return parent_rate;
+
+	if ((pll->flags & TEGRA_PLL_FIXED) && !(val & PLL_BASE_OVERRIDE)) {
+		struct tegra_clk_pll_freq_table sel;
+		if (_get_table_rate(hw, &sel, pll->fixed_rate, parent_rate)) {
+			pr_err("Clock %s has unknown fixed frequency\n",
+			       hw->name);
+			BUG();
+		}
+		return pll->fixed_rate;
+	}
+
+	divp = (val >> pll->divp_shift) & (divp_mask(pll));
+	if (pll->flags & TEGRA_PLLU)
+		divp ^= 1;
+
+	divn = (val >> pll->divn_shift) & (divn_mask(pll));
+	divm = (val >> pll->divm_shift) & (divm_mask(pll));
+	divm *= (1 << divp);
+
+	rate *= divn;
+	do_div(rate, divm);
+
+	return rate;
+}
+
+static int _calc_rate(struct clk *hw, struct tegra_clk_pll_freq_table *cfg,
+		      unsigned long rate, unsigned long parent_rate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	unsigned long cfreq;
+	u32 p_div = 0;
+
+	switch (parent_rate) {
+	case 12000000:
+	case 26000000:
+		cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000;
+		break;
+	case 13000000:
+		cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000;
+		break;
+	case 16800000:
+	case 19200000:
+		cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000;
+		break;
+	case 9600000:
+	case 28800000:
+		/*
+		 * PLL_P_OUT1 rate is not listed in PLLA table
+		 */
+		cfreq = parent_rate/(parent_rate/1000000);
+		break;
+	default:
+		pr_err("%s Unexpected reference rate %lu\n",
+		       __func__, parent_rate);
+		BUG();
+	}
+
+	/* Raise VCO to guarantee 0.5% accuracy */
+	for (cfg->output_rate = rate; cfg->output_rate < 200 * cfreq;
+	     cfg->output_rate <<= 1)
+		p_div++;
+
+	cfg->p = 1 << p_div;
+	cfg->m = parent_rate / cfreq;
+	cfg->n = cfg->output_rate / cfreq;
+	cfg->cpcon = OUT_OF_TABLE_CPCON;
+
+	if (cfg->m > divm_max(pll) || cfg->n > divn_max(pll) ||
+	    cfg->p > divp_max(pll) || cfg->output_rate > pll->params->vco_max) {
+		pr_err("%s: Failed to set %s rate %lu\n",
+		       __func__, hw->name, rate);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static long clk_pll_round_rate(struct clk *hw, unsigned long rate,
+			unsigned long *prate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	struct tegra_clk_pll_freq_table cfg;
+	u64 output_rate = *prate;
+
+	if (pll->flags & TEGRA_PLL_FIXED)
+		return pll->fixed_rate;
+
+	/* PLLM is used for memory; we do not change rate */
+	if (pll->flags & TEGRA_PLLM)
+		return clk_get_rate(hw);
+
+	if (_get_table_rate(hw, &cfg, rate, *prate) &&
+	    _calc_rate(hw, &cfg, rate, *prate))
+		return -EINVAL;
+
+	output_rate *= cfg.n;
+	do_div(output_rate, cfg.m * cfg.p);
+
+	return output_rate;
+}
+
+static int _program_pll(struct clk *hw, struct tegra_clk_pll_freq_table *cfg,
+			unsigned long rate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 divp, val, old_base;
+	int state;
+
+	divp = __ffs(cfg->p);
+
+	if (pll->flags & TEGRA_PLLU)
+		divp ^= 1;
+
+	old_base = val = pll_readl_base(pll);
+	val &= ~((divm_mask(pll) << pll->divm_shift) |
+		 (divn_mask(pll) << pll->divn_shift) |
+		 (divp_mask(pll) << pll->divp_shift));
+	val |= ((cfg->m << pll->divm_shift) |
+		(cfg->n << pll->divn_shift) |
+		(divp << pll->divp_shift));
+	if (pll->flags & TEGRA_PLL_FIXED)
+		val |= PLL_BASE_OVERRIDE;
+	if (val == old_base) {
+		return 0;
+	}
+
+	state = clk_pll_is_enabled(hw);
+
+	if (state) {
+		clk_pll_disable(hw);
+		val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
+	}
+	pll_writel_base(val, pll);
+
+	if (pll->flags & TEGRA_PLL_HAS_CPCON) {
+		val = pll_readl_misc(pll);
+		val &= ~(PLL_MISC_CPCON_MASK << PLL_MISC_CPCON_SHIFT);
+		val |= cfg->cpcon << PLL_MISC_CPCON_SHIFT;
+		if (pll->flags & TEGRA_PLL_SET_LFCON) {
+			val &= ~(PLL_MISC_LFCON_MASK << PLL_MISC_LFCON_SHIFT);
+			if (cfg->n >= PLLDU_LFCON_SET_DIVN)
+				val |= 0x1 << PLL_MISC_LFCON_SHIFT;
+		} else if (pll->flags & TEGRA_PLL_SET_DCCON) {
+			val &= ~(0x1 << PLL_MISC_DCCON_SHIFT);
+			if (rate >= (pll->params->vco_max >> 1))
+				val |= 0x1 << PLL_MISC_DCCON_SHIFT;
+		}
+		pll_writel_misc(val, pll);
+	}
+
+	if (state)
+		clk_pll_enable(hw);
+
+	return 0;
+}
+
+static int clk_pll_set_rate(struct clk *hw, unsigned long rate,
+			unsigned long parent_rate)
+{
+	struct tegra_clk_pll_freq_table cfg;
+
+	if (_get_table_rate(hw, &cfg, rate, parent_rate) &&
+	    _calc_rate(hw, &cfg, rate, parent_rate))
+		return -EINVAL;
+
+	return _program_pll(hw, &cfg, rate);
+}
+
+const struct clk_ops tegra_clk_pll_ops = {
+	.is_enabled = clk_pll_is_enabled,
+	.enable = clk_pll_enable,
+	.disable = clk_pll_disable,
+	.recalc_rate = clk_pll_recalc_rate,
+	.round_rate = clk_pll_round_rate,
+	.set_rate = clk_pll_set_rate,
+};
+
+static struct clk *_tegra_clk_register_pll(const char *name,
+		const char *parent_name, void __iomem *clk_base,
+		unsigned long flags, unsigned long fixed_rate,
+		struct tegra_clk_pll_params *pll_params, u8 pll_flags,
+		struct tegra_clk_pll_freq_table *freq_table,
+		const struct clk_ops *ops)
+{
+	struct tegra_clk_pll *pll;
+	int ret;
+
+	pll = kzalloc(sizeof(*pll), GFP_KERNEL);
+	if (!pll)
+		return NULL;
+
+	pll->parent = parent_name;
+	pll->hw.name = name;
+	pll->hw.ops = ops;
+	pll->hw.flags = flags;
+	pll->hw.parent_names = (pll->parent ? &pll->parent : NULL);
+	pll->hw.num_parents = (pll->parent ? 1 : 0);
+
+	pll->clk_base = clk_base;
+
+	pll->freq_table = freq_table;
+	pll->params = pll_params;
+	pll->fixed_rate = fixed_rate;
+	pll->flags = pll_flags;
+
+	pll->divp_shift = PLL_BASE_DIVP_SHIFT;
+	pll->divp_width = PLL_BASE_DIVP_WIDTH;
+	pll->divn_shift = PLL_BASE_DIVN_SHIFT;
+	pll->divn_width = PLL_BASE_DIVN_WIDTH;
+	pll->divm_shift = PLL_BASE_DIVM_SHIFT;
+	pll->divm_width = PLL_BASE_DIVM_WIDTH;
+
+	ret = clk_register(&pll->hw);
+	if (ret) {
+		kfree(pll);
+		return ERR_PTR(ret);
+	}
+
+	return &pll->hw;
+}
+
+struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
+		void __iomem *clk_base,
+		unsigned long flags, unsigned long fixed_rate,
+		struct tegra_clk_pll_params *pll_params, u8 pll_flags,
+		struct tegra_clk_pll_freq_table *freq_table)
+{
+	return _tegra_clk_register_pll(name, parent_name, clk_base,
+			flags, fixed_rate, pll_params, pll_flags, freq_table,
+			&tegra_clk_pll_ops);
+}
diff --git a/drivers/clk/tegra/clk-tegra20.c b/drivers/clk/tegra/clk-tegra20.c
new file mode 100644
index 0000000..5f668cb
--- /dev/null
+++ b/drivers/clk/tegra/clk-tegra20.c
@@ -0,0 +1,326 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <io.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <mach/lowlevel.h>
+#include <mach/tegra20-car.h>
+
+#include "clk.h"
+
+static void __iomem *car_base;
+
+enum tegra20_clks {
+	cpu, ac97 = 3, rtc, timer, uarta, uartb, gpio, sdmmc2, i2s1 = 11, i2c1,
+	ndflash, sdmmc1, sdmmc4, twc, pwm, i2s2, epp, gr2d = 21, usbd, isp,
+	gr3d, ide, disp2, disp1, host1x, vcp, cache2 = 31, mem, ahbdma, apbdma,
+	kbc = 36, stat_mon, pmc, fuse, kfuse, sbc1, nor, spi, sbc2, xio, sbc3,
+	dvc, dsi, mipi = 50, hdmi, csi, tvdac, i2c2, uartc, emc = 57, usb2,
+	usb3, mpe, vde, bsea, bsev, speedo, uartd, uarte, i2c3, sbc4, sdmmc3,
+	pex, owr, afi, csite, pcie_xclk, avpucq = 75, la, irama = 84, iramb,
+	iramc, iramd, cram2, audio_2x, clk_d, csus = 92, cdev2, cdev1,
+	vfir = 96, spdif_in, spdif_out, vi, vi_sensor, tvo, cve,
+	osc, clk_32k, clk_m, sclk, cclk, hclk, pclk, blink, pll_a, pll_a_out0,
+	pll_c, pll_c_out1, pll_d, pll_d_out0, pll_e, pll_m, pll_m_out1,
+	pll_p, pll_p_out1, pll_p_out2, pll_p_out3, pll_p_out4, pll_u,
+	pll_x, audio, pll_ref, twd, clk_max,
+};
+
+static struct clk *clks[clk_max];
+static struct clk_onecell_data clk_data;
+
+static unsigned int get_pll_ref_div(void)
+{
+	u32 osc_ctrl = readl(car_base + CRC_OSC_CTRL);
+
+	return 1U << ((osc_ctrl & CRC_OSC_CTRL_PLL_REF_DIV_MASK) >>
+		      CRC_OSC_CTRL_PLL_REF_DIV_SHIFT);
+}
+
+static void tegra20_osc_clk_init(void)
+{
+	clks[clk_m] = clk_fixed("clk_m", tegra_get_osc_clock());
+	clks[clk_32k] = clk_fixed("clk_32k", 32768);
+
+	clks[pll_ref] = clk_fixed_factor("pll_ref", "clk_m", 1,
+					 get_pll_ref_div());
+}
+
+/* PLL frequency tables */
+static struct tegra_clk_pll_freq_table pll_c_freq_table[] = {
+	{ 12000000, 600000000, 600, 12, 1, 8 },
+	{ 13000000, 600000000, 600, 13, 1, 8 },
+	{ 19200000, 600000000, 500, 16, 1, 6 },
+	{ 26000000, 600000000, 600, 26, 1, 8 },
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
+	{ 12000000, 216000000, 432, 12, 2, 8},
+	{ 13000000, 216000000, 432, 13, 2, 8},
+	{ 19200000, 216000000, 90,   4, 2, 1},
+	{ 26000000, 216000000, 432, 26, 2, 8},
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
+	{ 12000000, 666000000, 666, 12, 1, 8},
+	{ 13000000, 666000000, 666, 13, 1, 8},
+	{ 19200000, 666000000, 555, 16, 1, 8},
+	{ 26000000, 666000000, 666, 26, 1, 8},
+	{ 12000000, 600000000, 600, 12, 1, 8},
+	{ 13000000, 600000000, 600, 13, 1, 8},
+	{ 19200000, 600000000, 375, 12, 1, 6},
+	{ 26000000, 600000000, 600, 26, 1, 8},
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
+	/* 1 GHz */
+	{ 12000000, 1000000000, 1000, 12, 1, 12},
+	{ 13000000, 1000000000, 1000, 13, 1, 12},
+	{ 19200000, 1000000000, 625,  12, 1, 8},
+	{ 26000000, 1000000000, 1000, 26, 1, 12},
+
+	/* 912 MHz */
+	{ 12000000, 912000000,  912,  12, 1, 12},
+	{ 13000000, 912000000,  912,  13, 1, 12},
+	{ 19200000, 912000000,  760,  16, 1, 8},
+	{ 26000000, 912000000,  912,  26, 1, 12},
+
+	/* 816 MHz */
+	{ 12000000, 816000000,  816,  12, 1, 12},
+	{ 13000000, 816000000,  816,  13, 1, 12},
+	{ 19200000, 816000000,  680,  16, 1, 8},
+	{ 26000000, 816000000,  816,  26, 1, 12},
+
+	/* 760 MHz */
+	{ 12000000, 760000000,  760,  12, 1, 12},
+	{ 13000000, 760000000,  760,  13, 1, 12},
+	{ 19200000, 760000000,  950,  24, 1, 8},
+	{ 26000000, 760000000,  760,  26, 1, 12},
+
+	/* 750 MHz */
+	{ 12000000, 750000000,  750,  12, 1, 12},
+	{ 13000000, 750000000,  750,  13, 1, 12},
+	{ 19200000, 750000000,  625,  16, 1, 8},
+	{ 26000000, 750000000,  750,  26, 1, 12},
+
+	/* 608 MHz */
+	{ 12000000, 608000000,  608,  12, 1, 12},
+	{ 13000000, 608000000,  608,  13, 1, 12},
+	{ 19200000, 608000000,  380,  12, 1, 8},
+	{ 26000000, 608000000,  608,  26, 1, 12},
+
+	/* 456 MHz */
+	{ 12000000, 456000000,  456,  12, 1, 12},
+	{ 13000000, 456000000,  456,  13, 1, 12},
+	{ 19200000, 456000000,  380,  16, 1, 8},
+	{ 26000000, 456000000,  456,  26, 1, 12},
+
+	/* 312 MHz */
+	{ 12000000, 312000000,  312,  12, 1, 12},
+	{ 13000000, 312000000,  312,  13, 1, 12},
+	{ 19200000, 312000000,  260,  16, 1, 8},
+	{ 26000000, 312000000,  312,  26, 1, 12},
+
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
+	{ 12000000, 480000000, 960, 12, 2, 0},
+	{ 13000000, 480000000, 960, 13, 2, 0},
+	{ 19200000, 480000000, 200, 4,  2, 0},
+	{ 26000000, 480000000, 960, 26, 2, 0},
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+/* PLL parameters */
+static struct tegra_clk_pll_params pll_c_params = {
+	.input_min = 2000000,
+	.input_max = 31000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 20000000,
+	.vco_max = 1400000000,
+	.base_reg = CRC_PLLC_BASE,
+	.misc_reg = CRC_PLLC_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLL_MISC_LOCK_ENABLE,
+	.lock_delay = 300,
+};
+
+static struct tegra_clk_pll_params pll_p_params = {
+	.input_min = 2000000,
+	.input_max = 31000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 20000000,
+	.vco_max = 1400000000,
+	.base_reg = CRC_PLLP_BASE,
+	.misc_reg = CRC_PLLP_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLL_MISC_LOCK_ENABLE,
+	.lock_delay = 300,
+};
+
+static struct tegra_clk_pll_params pll_m_params = {
+	.input_min = 2000000,
+	.input_max = 31000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 20000000,
+	.vco_max = 1200000000,
+	.base_reg = CRC_PLLM_BASE,
+	.misc_reg = CRC_PLLM_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLL_MISC_LOCK_ENABLE,
+	.lock_delay = 300,
+};
+
+static struct tegra_clk_pll_params pll_x_params = {
+	.input_min = 2000000,
+	.input_max = 31000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 20000000,
+	.vco_max = 1200000000,
+	.base_reg = CRC_PLLX_BASE,
+	.misc_reg = CRC_PLLX_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLL_MISC_LOCK_ENABLE,
+	.lock_delay = 300,
+};
+
+static struct tegra_clk_pll_params pll_u_params = {
+	.input_min = 2000000,
+	.input_max = 40000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 48000000,
+	.vco_max = 960000000,
+	.base_reg = CRC_PLLU_BASE,
+	.misc_reg = CRC_PLLU_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLLDU_MISC_LOCK_ENABLE,
+	.lock_delay = 1000,
+};
+
+static void tegra20_pll_init(void)
+{
+	/* PLLC */
+	clks[pll_c] = tegra_clk_register_pll("pll_c", "pll_ref", car_base,
+			0, 0, &pll_c_params, TEGRA_PLL_HAS_CPCON,
+			pll_c_freq_table);
+
+	clks[pll_c_out1] = tegra_clk_register_pll_out("pll_c_out1", "pll_c",
+			car_base + CRC_PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP);
+
+	/* PLLP */
+	clks[pll_p] = tegra_clk_register_pll("pll_p", "pll_ref", car_base,
+			0, 216000000, &pll_p_params, TEGRA_PLL_FIXED |
+			TEGRA_PLL_HAS_CPCON, pll_p_freq_table);
+
+	clks[pll_p_out1] = tegra_clk_register_pll_out("pll_p_out1", "pll_p",
+			car_base + CRC_PLLP_OUTA, 0,
+			TEGRA_DIVIDER_FIXED | TEGRA_DIVIDER_ROUND_UP);
+
+	clks[pll_p_out2] = tegra_clk_register_pll_out("pll_p_out2", "pll_p",
+			car_base + CRC_PLLP_OUTA, 16,
+			TEGRA_DIVIDER_FIXED | TEGRA_DIVIDER_ROUND_UP);
+
+	clks[pll_p_out3] = tegra_clk_register_pll_out("pll_p_out3", "pll_p",
+			car_base + CRC_PLLP_OUTB, 0,
+			TEGRA_DIVIDER_FIXED | TEGRA_DIVIDER_ROUND_UP);
+
+	clks[pll_p_out4] = tegra_clk_register_pll_out("pll_p_out4", "pll_p",
+			car_base + CRC_PLLP_OUTB, 16,
+			TEGRA_DIVIDER_FIXED | TEGRA_DIVIDER_ROUND_UP);
+
+	/* PLLM */
+	clks[pll_m] = tegra_clk_register_pll("pll_m", "pll_ref", car_base,
+			0, 0, &pll_m_params, TEGRA_PLL_HAS_CPCON,
+			pll_m_freq_table);
+
+	clks[pll_m_out1] = tegra_clk_register_pll_out("pll_m_out1", "pll_m",
+			car_base + CRC_PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP);
+
+	/* PLLX */
+	clks[pll_x] = tegra_clk_register_pll("pll_x", "pll_ref", car_base,
+			0, 0, &pll_x_params, TEGRA_PLL_HAS_CPCON,
+			pll_x_freq_table);
+
+	/* PLLU */
+	clks[pll_u] = tegra_clk_register_pll("pll_u", "pll_ref", car_base,
+			0, 0, &pll_u_params, TEGRA_PLLU |
+			TEGRA_PLL_HAS_CPCON, pll_u_freq_table);
+}
+
+static struct tegra_clk_init_table init_table[] = {
+	{pll_p,		clk_max,	216000000,	1},
+	{pll_p_out1,	clk_max,	28800000,	1},
+	{pll_p_out2,	clk_max,	48000000,	1},
+	{pll_p_out3,	clk_max,	72000000,	1},
+	{pll_p_out4,	clk_max,	24000000,	1},
+	{pll_c,		clk_max,	600000000,	1},
+	{pll_c_out1,	clk_max,	120000000,	1},
+	{clk_max,	clk_max,	0,		0}, /* sentinel */
+};
+
+static int tegra20_car_probe(struct device_d *dev)
+{
+	car_base = dev_request_mem_region(dev, 0);
+	if (!car_base)
+		return -EBUSY;
+
+	tegra20_osc_clk_init();
+	tegra20_pll_init();
+
+	tegra_init_from_table(init_table, clks, clk_max);
+
+	clk_data.clks = clks;
+	clk_data.clk_num = ARRAY_SIZE(clks);
+	of_clk_add_provider(dev->device_node, of_clk_src_onecell_get,
+			    &clk_data);
+
+	return 0;
+}
+
+static __maybe_unused struct of_device_id tegra20_car_dt_ids[] = {
+	{
+		.compatible = "nvidia,tegra20-car",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d tegra20_car_driver = {
+	.probe	= tegra20_car_probe,
+	.name	= "tegra20-car",
+	.of_compatible = DRV_OF_COMPAT(tegra20_car_dt_ids),
+};
+
+static int tegra20_car_init(void)
+{
+	return platform_driver_register(&tegra20_car_driver);
+}
+postcore_initcall(tegra20_car_init);
diff --git a/drivers/clk/tegra/clk.c b/drivers/clk/tegra/clk.c
new file mode 100644
index 0000000..f4013e7
--- /dev/null
+++ b/drivers/clk/tegra/clk.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <linux/clk.h>
+
+#include "clk.h"
+
+void tegra_init_from_table(struct tegra_clk_init_table *tbl,
+				  struct clk *clks[], int clk_max)
+{
+	struct clk *clk;
+
+	for (; tbl->clk_id < clk_max; tbl++) {
+		clk = clks[tbl->clk_id];
+		if (!clk)
+			return;
+
+		if (tbl->parent_id < clk_max) {
+			struct clk *parent = clks[tbl->parent_id];
+			if (clk_set_parent(clk, parent)) {
+				pr_err("%s: Failed to set parent %s of %s\n",
+				       __func__, parent->name, clk->name);
+				WARN_ON(1);
+			}
+		}
+
+		if (tbl->rate)
+			if (clk_set_rate(clk, tbl->rate)) {
+				pr_err("%s: Failed to set rate %lu of %s\n",
+				       __func__, tbl->rate, clk->name);
+				WARN_ON(1);
+			}
+
+		if (tbl->state)
+			if (clk_enable(clk)) {
+				pr_err("%s: Failed to enable %s\n", __func__,
+				       clk->name);
+				WARN_ON(1);
+			}
+	}
+}
diff --git a/drivers/clk/tegra/clk.h b/drivers/clk/tegra/clk.h
new file mode 100644
index 0000000..2bc3698
--- /dev/null
+++ b/drivers/clk/tegra/clk.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* struct tegra_clk_frac_div - fractional divider */
+struct tegra_clk_frac_div {
+	struct clk	hw;
+	void __iomem	*reg;
+	u8		flags;
+	u8		shift;
+	u8		width;
+	u8		frac_width;
+	const char	*parent;
+};
+
+#define TEGRA_DIVIDER_ROUND_UP	BIT(0)
+#define TEGRA_DIVIDER_FIXED	BIT(1)
+#define TEGRA_DIVIDER_INT	BIT(2)
+#define TEGRA_DIVIDER_UART	BIT(3)
+
+struct clk *tegra_clk_divider_alloc(const char *name, const char *parent_name,
+		void __iomem *reg, unsigned long flags, u8 clk_divider_flags,
+		u8 shift, u8 width, u8 frac_width);
+
+void tegra_clk_divider_free(struct clk *divider);
+
+struct clk *tegra_clk_register_divider(const char *name,
+		const char *parent_name, void __iomem *reg, unsigned long flags,
+		u8 clk_divider_flags, u8 shift, u8 width, u8 frac_width);
+
+/* struct tegra_clk_pll_freq_table - PLL frequecy table */
+struct tegra_clk_pll_freq_table {
+	unsigned long	input_rate;
+	unsigned long	output_rate;
+	u16		n;
+	u16		m;
+	u8		p;
+	u8		cpcon;
+};
+
+/* struct clk_pll_params - PLL parameters */
+struct tegra_clk_pll_params {
+	unsigned long	input_min;
+	unsigned long	input_max;
+	unsigned long	cf_min;
+	unsigned long	cf_max;
+	unsigned long	vco_min;
+	unsigned long	vco_max;
+
+	u32		base_reg;
+	u32		misc_reg;
+	u32		lock_reg;
+	u8		lock_bit_idx;
+	u8		lock_enable_bit_idx;
+	int		lock_delay;
+};
+
+/* struct tegra_clk_pll - Tegra PLL clock */
+struct tegra_clk_pll {
+	struct clk	hw;
+	void __iomem	*clk_base;
+	u8		flags;
+	unsigned long	fixed_rate;
+	u8		divn_shift;
+	u8		divn_width;
+	u8		divm_shift;
+	u8		divm_width;
+	u8		divp_shift;
+	u8		divp_width;
+	struct tegra_clk_pll_freq_table	*freq_table;
+	struct tegra_clk_pll_params	*params;
+	const char	*parent;
+};
+
+#define TEGRA_PLL_USE_LOCK	BIT(0)
+#define TEGRA_PLL_HAS_CPCON	BIT(1)
+#define TEGRA_PLL_SET_LFCON	BIT(2)
+#define TEGRA_PLL_SET_DCCON	BIT(3)
+#define TEGRA_PLLU		BIT(4)
+#define TEGRA_PLLM		BIT(5)
+#define TEGRA_PLL_FIXED		BIT(6)
+#define TEGRA_PLLE_CONFIGURE	BIT(7)
+
+struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
+		void __iomem *clk_base,
+		unsigned long flags, unsigned long fixed_rate,
+		struct tegra_clk_pll_params *pll_params, u8 pll_flags,
+		struct tegra_clk_pll_freq_table *freq_table);
+
+/* struct tegra_clk_pll_out - PLL output divider */
+struct tegra_clk_pll_out {
+	struct clk	hw;
+	struct clk	*div;
+	void __iomem	*reg;
+	u8		enb_bit_idx;
+	u8		rst_bit_idx;
+	const char	*parent;
+};
+
+struct clk *tegra_clk_register_pll_out(const char *name,
+		const char *parent_name, void __iomem *reg, u8 shift,
+		u8 divider_flags);
+
+/* struct clk_init_table - clock initialization table */
+struct tegra_clk_init_table {
+	unsigned int	clk_id;
+	unsigned int	parent_id;
+	unsigned long	rate;
+	int		state;
+};
+
+void tegra_init_from_table(struct tegra_clk_init_table *tbl,
+		struct clk *clks[], int clk_max);
-- 
1.8.2.1



From s.hauer at pengutronix.de  Tue Jun  4 03:47:17 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue,  4 Jun 2013 09:47:17 +0200
Subject: [PATCH] net: Set mac-address property
Message-ID: <1370332037-10575-1-git-send-email-s.hauer@pengutronix.de>

Linux normally has no idea how to retrieve MAC Addresses, but instead
expects the MAC address in the devicetree. This patch adds the MAC
address to the devicetree for Linux if we find a valid one in barebox.
This mechanism is limited of course to devices barebox has a driver for
and which are probed themselves from the devicetree.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/net.h |  1 +
 net/eth.c     | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/include/net.h b/include/net.h
index fa3c05a..a4cfec7 100644
--- a/include/net.h
+++ b/include/net.h
@@ -52,6 +52,7 @@ struct eth_device {
 
 	struct device_d dev;
 	struct device_d *parent;
+	char *nodepath;
 
 	struct list_head list;
 
diff --git a/net/eth.c b/net/eth.c
index bea7b12..7240b4d 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -273,6 +273,52 @@ static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const ch
 	return 0;
 }
 
+#ifdef CONFIG_OFDEVICE
+static int eth_of_fixup(struct device_node *root)
+{
+	struct eth_device *edev;
+	struct device_node *node;
+	int ret;
+
+	/*
+	 * Add the mac-address property for each network device we
+	 * find a nodepath for and which has a valid mac address.
+	 */
+	list_for_each_entry(edev, &netdev_list, list) {
+		if (!edev->nodepath) {
+			dev_dbg(&edev->dev, "%s: no node to fixup\n", __func__);
+			continue;
+		}
+
+		if (!is_valid_ether_addr(edev->ethaddr)) {
+			dev_dbg(&edev->dev, "%s: no valid mac address, cannot fixup\n",
+					__func__);
+			continue;
+		}
+
+		node = of_find_node_by_path(root, edev->nodepath);
+		if (!node) {
+			dev_dbg(&edev->dev, "%s: fixup node %s not found\n",
+					__func__, edev->nodepath);
+			continue;
+		}
+
+		ret = of_set_property(node, "mac-address", edev->ethaddr, 6, 1);
+		if (ret)
+			pr_err("Setting mac-address property of %s failed with: %s\n",
+					node->full_name, strerror(-ret));
+	}
+
+	return 0;
+}
+
+static int eth_register_of_fixup(void)
+{
+	return of_register_fixup(eth_of_fixup);
+}
+late_initcall(eth_register_of_fixup);
+#endif
+
 int eth_register(struct eth_device *edev)
 {
 	struct device_d *dev = &edev->dev;
@@ -316,6 +362,10 @@ int eth_register(struct eth_device *edev)
 	if (found)
 		register_preset_mac_address(edev, ethaddr);
 
+	if (IS_ENABLED(CONFIG_OFDEVICE) && edev->parent &&
+			edev->parent->device_node)
+		edev->nodepath = xstrdup(edev->parent->device_node->full_name);
+
 	if (!eth_current)
 		eth_current = edev;
 
@@ -328,6 +378,10 @@ void eth_unregister(struct eth_device *edev)
 		eth_current = NULL;
 
 	dev_remove_parameters(&edev->dev);
+
+	if (IS_ENABLED(CONFIG_OFDEVICE) && edev->nodepath)
+		free(edev->nodepath);
+
 	unregister_device(&edev->dev);
 	list_del(&edev->list);
 }
-- 
1.8.2.rc2



From monaka at monami-ya.jp  Tue Jun  4 08:38:31 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Tue,  4 Jun 2013 21:38:31 +0900
Subject: [PATCH 2/3] Refactor malloc.h.
In-Reply-To: <1370349512-75630-1-git-send-email-monaka@monami-ya.jp>
References: <1370349512-75630-1-git-send-email-monaka@monami-ya.jp>
Message-ID: <1370349512-75630-2-git-send-email-monaka@monami-ya.jp>

From: Masaki Muranaka <monaka at monami-ya.com>

 Some functions should be defined in stdlib.h or unistd.h.

Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
---
 include/malloc.h       |  8 +++-----
 include/malloc_isoc.h  | 11 +++++++++++
 include/malloc_posix.h |  8 ++++++++
 include/stdlib.h       |  1 +
 include/unistd.h       |  6 ++++++
 5 files changed, 29 insertions(+), 5 deletions(-)
 create mode 100644 include/malloc_isoc.h
 create mode 100644 include/malloc_posix.h
 create mode 100644 include/unistd.h

diff --git a/include/malloc.h b/include/malloc.h
index 7b9b062..9554597 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,20 +5,18 @@
 
 /* Public routines */
 
-void* malloc(size_t);
-void free(void*);
-void* realloc(void*, size_t);
+#include <malloc_isoc.h>
+#include <malloc_posix.h>
+
 void* memalign(size_t, size_t);
 void* vallocc(size_t);
 void* pvalloc(size_t);
-void* calloc(size_t, size_t);
 void cfree(void*);
 int malloc_trim(size_t);
 size_t malloc_usable_size(void*);
 void malloc_stats(void);
 int mallopt(int, int);
 struct mallinfo mallinfo(void);
-void *sbrk(ptrdiff_t increment);
 
 #endif
 
diff --git a/include/malloc_isoc.h b/include/malloc_isoc.h
new file mode 100644
index 0000000..728cdd9
--- /dev/null
+++ b/include/malloc_isoc.h
@@ -0,0 +1,11 @@
+#ifndef BAREBOX_MALLOC_ISOC_H__
+#define BAREBOX_MALLOC_ISOC_H__
+
+#include <types.h>
+
+void* malloc(size_t);
+void free(void*);
+void* realloc(void*, size_t);
+void* calloc(size_t, size_t);
+
+#endif /* BAREBOX_MALLOC_ISOC_H__ */
diff --git a/include/malloc_posix.h b/include/malloc_posix.h
new file mode 100644
index 0000000..d10675d
--- /dev/null
+++ b/include/malloc_posix.h
@@ -0,0 +1,8 @@
+#ifndef BAREBOX_MALLOC_POSIX_H__
+#define BAREBOX_MALLOC_POSIX_H__
+
+#include <types.h>
+
+void *sbrk(ptrdiff_t increment);
+
+#endif /* BAREBOX_MALLOC_POSIX_H__ */
diff --git a/include/stdlib.h b/include/stdlib.h
index dc72013..0d82bbf 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -12,5 +12,6 @@ void srand(unsigned int seed);
 /* fill a buffer with pseudo-random data */
 void get_random_bytes(char *buf, int len);
 
+#include <malloc_isoc.h>
 
 #endif /* __STDLIB_H */
diff --git a/include/unistd.h b/include/unistd.h
new file mode 100644
index 0000000..a6abfa6
--- /dev/null
+++ b/include/unistd.h
@@ -0,0 +1,6 @@
+#ifndef BAREBOX_UNISTD_H__
+#define BAREBOX_UNISTD_H__
+
+#include <malloc_posix.h>
+
+#endif /* BAREBOX_UNISTD_H__ */
-- 
1.8.3



From monaka at monami-ya.jp  Tue Jun  4 08:38:32 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Tue,  4 Jun 2013 21:38:32 +0900
Subject: [PATCH 3/3] Use stdlib.h instead of malloc.h
In-Reply-To: <1370349512-75630-1-git-send-email-monaka@monami-ya.jp>
References: <1370349512-75630-1-git-send-email-monaka@monami-ya.jp>
Message-ID: <1370349512-75630-3-git-send-email-monaka@monami-ya.jp>

From: Masaki Muranaka <monaka at monami-ya.com>

Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
---
 commands/digest.c      | 2 +-
 commands/loadb.c       | 2 +-
 commands/mem.c         | 2 +-
 commands/of_property.c | 2 +-
 common/command.c       | 2 +-
 common/digest.c        | 2 +-
 common/env.c           | 2 +-
 common/environment.c   | 2 +-
 common/hush.c          | 2 +-
 common/password.c      | 3 +--
 common/startup.c       | 2 +-
 common/uimage.c        | 2 +-
 12 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/commands/digest.c b/commands/digest.c
index c9bb132..6470a2e 100644
--- a/commands/digest.c
+++ b/commands/digest.c
@@ -23,7 +23,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <xfuncs.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <digest.h>
 
 static int do_digest(char *algorithm, int argc, char *argv[])
diff --git a/commands/loadb.c b/commands/loadb.c
index a2f3315..d7895c9 100644
--- a/commands/loadb.c
+++ b/commands/loadb.c
@@ -38,7 +38,7 @@
 #include <getopt.h>
 #include <fs.h>
 #include <fcntl.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 #define XON_CHAR	17
 #define XOFF_CHAR	19
diff --git a/commands/mem.c b/commands/mem.c
index 568050d..1caa92c 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -25,7 +25,7 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/of_property.c b/commands/of_property.c
index 44bb388..1919b3d 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -23,7 +23,7 @@
 #include <of.h>
 #include <command.h>
 #include <fs.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
diff --git a/common/command.c b/common/command.c
index 7f2b777..b3804b8 100644
--- a/common/command.c
+++ b/common/command.c
@@ -24,7 +24,7 @@
 #include <common.h>
 #include <command.h>
 #include <xfuncs.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <environment.h>
 #include <linux/list.h>
 #include <init.h>
diff --git a/common/digest.c b/common/digest.c
index ae414ba..80e8502 100644
--- a/common/digest.c
+++ b/common/digest.c
@@ -18,7 +18,7 @@
 
 #include <common.h>
 #include <digest.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <fs.h>
 #include <fcntl.h>
 #include <linux/stat.h>
diff --git a/common/env.c b/common/env.c
index 33a871f..e8a57f4 100644
--- a/common/env.c
+++ b/common/env.c
@@ -24,7 +24,7 @@
 
 #include <common.h>
 #include <driver.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <xfuncs.h>
 #include <errno.h>
 #include <init.h>
diff --git a/common/environment.c b/common/environment.c
index 78cd45c..c0bd629 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -27,7 +27,7 @@
 #ifdef __BAREBOX__
 #include <common.h>
 #include <command.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/common/hush.c b/common/hush.c
index a3235ba..a7e4571 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -106,7 +106,7 @@
  * General Public License for more details.
  *
  */
-#include <malloc.h>         /* malloc, free, realloc*/
+#include <stdlib.h>         /* malloc, free, realloc*/
 #include <xfuncs.h>
 #include <linux/ctype.h>    /* isalpha, isdigit */
 #include <common.h>        /* readline */
diff --git a/common/password.c b/common/password.c
index d157a11..830f724 100644
--- a/common/password.c
+++ b/common/password.c
@@ -22,8 +22,7 @@
 #include <fs.h>
 #include <fcntl.h>
 #include <digest.h>
-#include <malloc.h>
-#include <xfuncs.h>
+#include <stdlib.h>
 #include <clock.h>
 
 #if defined(CONFIG_PASSWD_SUM_MD5)
diff --git a/common/startup.c b/common/startup.c
index ff00ca7..d709089 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -28,7 +28,7 @@
 #include <common.h>
 #include <init.h>
 #include <command.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <debug_ll.h>
 #include <fs.h>
 #include <linux/stat.h>
diff --git a/common/uimage.c b/common/uimage.c
index 06f97f0..c9ae311 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -19,7 +19,7 @@
  */
 #include <common.h>
 #include <image.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <libbb.h>
 #include <uncompress.h>
-- 
1.8.3



From monaka at monami-ya.jp  Tue Jun  4 08:38:30 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Tue,  4 Jun 2013 21:38:30 +0900
Subject: [PATCH 1/3] Remove unnesessory malloc.h inclusions.
Message-ID: <1370349512-75630-1-git-send-email-monaka@monami-ya.jp>

Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
---
 commands/barebox-update.c | 1 -
 commands/bootm.c          | 1 -
 commands/cat.c            | 1 -
 commands/cp.c             | 1 -
 commands/crc.c            | 1 -
 commands/dfu.c            | 1 -
 commands/edit.c           | 1 -
 commands/exec.c           | 1 -
 commands/global.c         | 1 -
 commands/i2c.c            | 1 -
 commands/insmod.c         | 1 -
 commands/let.c            | 1 -
 commands/linux16.c        | 1 -
 commands/loadxy.c         | 1 -
 commands/ls.c             | 1 -
 commands/md.c             | 1 -
 commands/memcmp.c         | 1 -
 commands/memcpy.c         | 1 -
 commands/meminfo.c        | 1 -
 commands/memset.c         | 1 -
 commands/miitool.c        | 1 -
 commands/mm.c             | 1 -
 commands/mw.c             | 1 -
 commands/nand.c           | 1 -
 commands/nandtest.c       | 1 -
 commands/of_node.c        | 1 -
 commands/oftree.c         | 1 -
 commands/partition.c      | 1 -
 commands/readline.c       | 1 -
 commands/readlink.c       | 1 -
 commands/spi.c            | 1 -
 commands/splash.c         | 1 -
 commands/time.c           | 1 -
 commands/ubiformat.c      | 1 -
 commands/uimage.c         | 1 -
 commands/usbserial.c      | 1 -
 common/console.c          | 1 -
 common/image.c            | 1 -
 38 files changed, 38 deletions(-)

diff --git a/commands/barebox-update.c b/commands/barebox-update.c
index f550572..bb6e108 100644
--- a/commands/barebox-update.c
+++ b/commands/barebox-update.c
@@ -18,7 +18,6 @@
 #include <common.h>
 #include <command.h>
 #include <getopt.h>
-#include <malloc.h>
 #include <errno.h>
 #include <bbu.h>
 #include <fs.h>
diff --git a/commands/bootm.c b/commands/bootm.c
index 6ce2ca9..b47f6ec 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -24,7 +24,6 @@
 #include <driver.h>
 #include <command.h>
 #include <image.h>
-#include <malloc.h>
 #include <environment.h>
 #include <asm/byteorder.h>
 #include <xfuncs.h>
diff --git a/commands/cat.c b/commands/cat.c
index 1c112fc..476e1bb 100644
--- a/commands/cat.c
+++ b/commands/cat.c
@@ -27,7 +27,6 @@
 #include <linux/ctype.h>
 #include <errno.h>
 #include <xfuncs.h>
-#include <malloc.h>
 
 #define BUFSIZE 1024
 
diff --git a/commands/cp.c b/commands/cp.c
index 45f08d8..03369d9 100644
--- a/commands/cp.c
+++ b/commands/cp.c
@@ -27,7 +27,6 @@
 #include <linux/stat.h>
 #include <libbb.h>
 #include <fs.h>
-#include <malloc.h>
 #include <libgen.h>
 #include <getopt.h>
 
diff --git a/commands/crc.c b/commands/crc.c
index a0071b0..78b3eca 100644
--- a/commands/crc.c
+++ b/commands/crc.c
@@ -24,7 +24,6 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <xfuncs.h>
-#include <malloc.h>
 #include <linux/ctype.h>
 
 static int file_crc(char* filename, ulong start, ulong size, ulong *crc,
diff --git a/commands/dfu.c b/commands/dfu.c
index af6573a..b1e54b9 100644
--- a/commands/dfu.c
+++ b/commands/dfu.c
@@ -19,7 +19,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <fs.h>
 #include <xfuncs.h>
diff --git a/commands/edit.c b/commands/edit.c
index 295d0a7..8c72521 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -22,7 +22,6 @@
 
 #include <common.h>
 #include <command.h>
-#include <malloc.h>
 #include <fs.h>
 #include <linux/ctype.h>
 #include <fcntl.h>
diff --git a/commands/exec.c b/commands/exec.c
index bd7d54a..af08f2a 100644
--- a/commands/exec.c
+++ b/commands/exec.c
@@ -23,7 +23,6 @@
 #include <fcntl.h>
 #include <linux/stat.h>
 #include <errno.h>
-#include <malloc.h>
 #include <xfuncs.h>
 
 static int do_exec(int argc, char *argv[])
diff --git a/commands/global.c b/commands/global.c
index 427a231..e3e7a58 100644
--- a/commands/global.c
+++ b/commands/global.c
@@ -17,7 +17,6 @@
  *
  */
 #include <common.h>
-#include <malloc.h>
 #include <command.h>
 #include <globalvar.h>
 #include <environment.h>
diff --git a/commands/i2c.c b/commands/i2c.c
index 626255d..f3ec556 100644
--- a/commands/i2c.c
+++ b/commands/i2c.c
@@ -18,7 +18,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <i2c/i2c.h>
 
diff --git a/commands/insmod.c b/commands/insmod.c
index f547e9d..3a0dfbc 100644
--- a/commands/insmod.c
+++ b/commands/insmod.c
@@ -3,7 +3,6 @@
 #include <module.h>
 #include <errno.h>
 #include <fs.h>
-#include <malloc.h>
 
 static int do_insmod(int argc, char *argv[])
 {
diff --git a/commands/let.c b/commands/let.c
index 644ede5..cae6c97 100644
--- a/commands/let.c
+++ b/commands/let.c
@@ -20,7 +20,6 @@
 #include <environment.h>
 #include <errno.h>
 #include <init.h>
-#include <malloc.h>
 #include <xfuncs.h>
 #include <math.h>
 
diff --git a/commands/linux16.c b/commands/linux16.c
index 30fa2de..3ce49dc 100644
--- a/commands/linux16.c
+++ b/commands/linux16.c
@@ -25,7 +25,6 @@
 #include <fs.h>
 #include <errno.h>
 #include <getopt.h>
-#include <malloc.h>
 #include <boot.h>
 #include <asm/syslib.h>
 
diff --git a/commands/loadxy.c b/commands/loadxy.c
index 52ecdca..1059512 100644
--- a/commands/loadxy.c
+++ b/commands/loadxy.c
@@ -36,7 +36,6 @@
 #include <getopt.h>
 #include <fcntl.h>
 #include <fs.h>
-#include <malloc.h>
 
 #define DEF_FILE	"image.bin"
 
diff --git a/commands/ls.c b/commands/ls.c
index f2d9903..9aa8d41 100644
--- a/commands/ls.c
+++ b/commands/ls.c
@@ -22,7 +22,6 @@
 #include <fs.h>
 #include <linux/stat.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <stringlist.h>
 
diff --git a/commands/md.c b/commands/md.c
index 03c5905..46d17a5 100644
--- a/commands/md.c
+++ b/commands/md.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/memcmp.c b/commands/memcmp.c
index 4a03862..ddb5dbf 100644
--- a/commands/memcmp.c
+++ b/commands/memcmp.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/memcpy.c b/commands/memcpy.c
index 98f099f..939451e 100644
--- a/commands/memcpy.c
+++ b/commands/memcpy.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/meminfo.c b/commands/meminfo.c
index 6e1e8c3..7b2019c 100644
--- a/commands/meminfo.c
+++ b/commands/meminfo.c
@@ -19,7 +19,6 @@
 #include <common.h>
 #include <command.h>
 #include <complete.h>
-#include <malloc.h>
 
 static int do_meminfo(int argc, char *argv[])
 {
diff --git a/commands/memset.c b/commands/memset.c
index 48e55bc..57bce5f 100644
--- a/commands/memset.c
+++ b/commands/memset.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/miitool.c b/commands/miitool.c
index 3a9ac45..495a285 100644
--- a/commands/miitool.c
+++ b/commands/miitool.c
@@ -29,7 +29,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/mm.c b/commands/mm.c
index f51fd27..442f804 100644
--- a/commands/mm.c
+++ b/commands/mm.c
@@ -19,7 +19,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/mw.c b/commands/mw.c
index d7d73a8..01d08ff 100644
--- a/commands/mw.c
+++ b/commands/mw.c
@@ -25,7 +25,6 @@
 #include <command.h>
 #include <init.h>
 #include <driver.h>
-#include <malloc.h>
 #include <errno.h>
 #include <fs.h>
 #include <fcntl.h>
diff --git a/commands/nand.c b/commands/nand.c
index 39fb64e..62b7405 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -19,7 +19,6 @@
 #include <fs.h>
 #include <linux/stat.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <xfuncs.h>
 #include <init.h>
diff --git a/commands/nandtest.c b/commands/nandtest.c
index ba15ecf..9f7cbff 100644
--- a/commands/nandtest.c
+++ b/commands/nandtest.c
@@ -15,7 +15,6 @@
 #include <command.h>
 #include <fs.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <ioctl.h>
 #include <linux/mtd/mtd-abi.h>
diff --git a/commands/of_node.c b/commands/of_node.c
index 0249d97..d9803e6 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -23,7 +23,6 @@
 #include <of.h>
 #include <command.h>
 #include <fs.h>
-#include <malloc.h>
 #include <linux/ctype.h>
 #include <asm/byteorder.h>
 #include <errno.h>
diff --git a/commands/oftree.c b/commands/oftree.c
index 468235a..f0f502a 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -29,7 +29,6 @@
 #include <of.h>
 #include <command.h>
 #include <fs.h>
-#include <malloc.h>
 #include <linux/ctype.h>
 #include <linux/err.h>
 #include <asm/byteorder.h>
diff --git a/commands/partition.c b/commands/partition.c
index fdd6041..01ce941 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -31,7 +31,6 @@
 #include <command.h>
 #include <complete.h>
 #include <driver.h>
-#include <malloc.h>
 #include <partition.h>
 #include <errno.h>
 #include <xfuncs.h>
diff --git a/commands/readline.c b/commands/readline.c
index 60670fa..7d13ab2 100644
--- a/commands/readline.c
+++ b/commands/readline.c
@@ -19,7 +19,6 @@
 
 #include <common.h>
 #include <command.h>
-#include <malloc.h>
 #include <xfuncs.h>
 #include <environment.h>
 
diff --git a/commands/readlink.c b/commands/readlink.c
index d2671e0..8f16b31 100644
--- a/commands/readlink.c
+++ b/commands/readlink.c
@@ -25,7 +25,6 @@
 #include <libgen.h>
 #include <environment.h>
 #include <fs.h>
-#include <malloc.h>
 #include <getopt.h>
 
 static int do_readlink(int argc, char *argv[])
diff --git a/commands/spi.c b/commands/spi.c
index 2f6b430..c0da77b 100644
--- a/commands/spi.c
+++ b/commands/spi.c
@@ -8,7 +8,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <spi/spi.h>
 
diff --git a/commands/splash.c b/commands/splash.c
index 0955c01..d69c7b5 100644
--- a/commands/splash.c
+++ b/commands/splash.c
@@ -1,7 +1,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <fb.h>
 #include <gui/image_renderer.h>
diff --git a/commands/time.c b/commands/time.c
index 987c25e..b40bd59 100644
--- a/commands/time.c
+++ b/commands/time.c
@@ -2,7 +2,6 @@
 #include <command.h>
 #include <clock.h>
 #include <asm-generic/div64.h>
-#include <malloc.h>
 
 static int do_time(int argc, char *argv[])
 {
diff --git a/commands/ubiformat.c b/commands/ubiformat.c
index 121816f..d508119 100644
--- a/commands/ubiformat.c
+++ b/commands/ubiformat.c
@@ -37,7 +37,6 @@
 #include <crc.h>
 #include <stdlib.h>
 #include <clock.h>
-#include <malloc.h>
 #include <ioctl.h>
 #include <libbb.h>
 #include <linux/mtd/mtd.h>
diff --git a/commands/uimage.c b/commands/uimage.c
index 345e496..415347c 100644
--- a/commands/uimage.c
+++ b/commands/uimage.c
@@ -4,7 +4,6 @@
 #include <libbb.h>
 #include <fcntl.h>
 #include <fs.h>
-#include <malloc.h>
 #include <errno.h>
 #include <getopt.h>
 
diff --git a/commands/usbserial.c b/commands/usbserial.c
index a884a28..041d7f2 100644
--- a/commands/usbserial.c
+++ b/commands/usbserial.c
@@ -21,7 +21,6 @@
 #include <common.h>
 #include <command.h>
 #include <errno.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <fs.h>
 #include <xfuncs.h>
diff --git a/common/console.c b/common/console.c
index a0a06f6..86aecbe 100644
--- a/common/console.c
+++ b/common/console.c
@@ -20,7 +20,6 @@
 #include <config.h>
 #include <common.h>
 #include <stdarg.h>
-#include <malloc.h>
 #include <param.h>
 #include <console.h>
 #include <driver.h>
diff --git a/common/image.c b/common/image.c
index 9252d5e..ceb216f 100644
--- a/common/image.c
+++ b/common/image.c
@@ -25,7 +25,6 @@
 #include <rtc.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <malloc.h>
 #include <fs.h>
 #else
 #include <time.h>
-- 
1.8.3



From sfricke at data-modul.com  Tue Jun  4 09:07:57 2013
From: sfricke at data-modul.com (S. Fricke)
Date: Tue,  4 Jun 2013 15:07:57 +0200
Subject: [PATCH V2] ARM i.MX6: set imx6 silicon revision
Message-ID: <1370351277-23582-1-git-send-email-sfricke@data-modul.com>

From: "S. Fricke" <sfricke at data-modul.com>

This is mainly a backport of the imx6_revision function of
arch/arm/mach-imx/mach-imx6q.c in the linux kernel sources.

Signed-off-by: S. Fricke <sfricke at data-modul.com>
---
 arch/arm/mach-imx/imx6.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
index 5c20aa1..1d69ec8 100644
--- a/arch/arm/mach-imx/imx6.c
+++ b/arch/arm/mach-imx/imx6.c
@@ -16,8 +16,11 @@
 #include <io.h>
 #include <sizes.h>
 #include <mach/generic.h>
+#include <mach/revision.h>
 #include <mach/imx6-regs.h>
 
+#define SI_REV 0x260
+
 void imx6_init_lowlevel(void)
 {
 	void __iomem *aips1 = (void *)MX6_AIPS1_ON_BASE_ADDR;
@@ -55,8 +58,31 @@ void imx6_init_lowlevel(void)
 
 static int imx6_init(void)
 {
+	u32 rev;
+	u32 mx6_silicon_revision;
+
 	imx6_boot_save_loc((void *)MX6_SRC_BASE_ADDR);
 
+	rev = readl(MX6_ANATOP_BASE_ADDR + SI_REV);
+	switch (rev & 0xff) {
+	case 0x00:
+		mx6_silicon_revision = IMX_CHIP_REV_1_0;
+		break;
+
+	case 0x01:
+		mx6_silicon_revision = IMX_CHIP_REV_1_1;
+		break;
+
+	case 0x02:
+		mx6_silicon_revision = IMX_CHIP_REV_1_2;
+		break;
+
+	default:
+		mx6_silicon_revision = IMX_CHIP_REV_UNKNOWN;
+	}
+
+	imx_set_silicon_revision("i.MX6", mx6_silicon_revision);
+
 	if (of_get_root_node())
 		return 0;
 
-- 
1.8.3



From s.hauer at pengutronix.de  Tue Jun  4 10:53:27 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 4 Jun 2013 16:53:27 +0200
Subject: [PATCH] OMAP4: Use default clock source for mcbsp
In-Reply-To: <1369741903-24988-2-git-send-email-j.weitzel@phytec.de>
References: <1369741903-24988-2-git-send-email-j.weitzel@phytec.de>
Message-ID: <20130604145327.GJ32299@pengutronix.de>

Hi Jan,

On Tue, May 28, 2013 at 01:51:40PM +0200, Jan Weitzel wrote:
> In omap4_enable_all_clocks we not only enable the mcbsp clocks, but also
> change the source from ABE_24M_FCLK to 24M_FCLK. Revert this and default
> to the reset state.

Can you add a description why this is necessary?

Sascha

> 
> Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
> ---
>  arch/arm/mach-omap/omap4_clock.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/mach-omap/omap4_clock.c b/arch/arm/mach-omap/omap4_clock.c
> index 0621fd3..889d1f9 100644
> --- a/arch/arm/mach-omap/omap4_clock.c
> +++ b/arch/arm/mach-omap/omap4_clock.c
> @@ -253,9 +253,9 @@ void omap4_enable_all_clocks(void)
>  	sr32(CM1_ABE_PDM_CLKCTRL, 0, 32, 0x2);
>  	sr32(CM1_ABE_DMIC_CLKCTRL, 0, 32, 0x2);
>  	sr32(CM1_ABE_MCASP_CLKCTRL, 0, 32, 0x2);
> -	sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x08000002);
> -	sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x08000002);
> -	sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x08000002);
> +	sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x2);
> +	sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x2);
> +	sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x2);
>  	sr32(CM1_ABE_SLIMBUS_CLKCTRL, 0, 32, 0xf02);
>  	sr32(CM1_ABE_TIMER5_CLKCTRL, 0, 32, 0x2);
>  	sr32(CM1_ABE_TIMER6_CLKCTRL, 0, 32, 0x2);
> -- 
> 1.7.0.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From renaud.barbier at ge.com  Tue Jun  4 13:01:29 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 04 Jun 2013 18:01:29 +0100
Subject: [PATCH] gianfar: prevent resource conflict
In-Reply-To: <51AC6286.5030001@ge.com>
References: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
 <20130601092018.GO32299@pengutronix.de> <51AC6286.5030001@ge.com>
Message-ID: <51AE1D69.4050205@ge.com>

Hello Sacha,
I applied your patch and try it on our mpc8544 based board
with a few modification.
This board uses eTSEC1. This means all 3 regions have the same
base address.

I just did the following update to your patch.
It only maps the eTSEC registers and mdio bus registers.

  static int fsl_phy_init(void)
{
          add_generic_device("gfar-phy", 0, NULL, MDIO_BASE_ADDR, 0x1000,
                          IORESOURCE_MEM, NULL);
          return 0;
  }

  coredevice_initcall(fsl_phy_init);

   int fsl_eth_init(int num, struct gfar_info_struct *gf)
  {

          printf("FSL_ETH_INIT: num = %d, 0x%x\n", num - 1,
                          GFAR_BASE_ADDR + (num - 1) * 0x1000);
          add_generic_device("gfar", num - 1, NULL,
                          GFAR_BASE_ADDR + (num - 1) * 0x1000, 0x1000,
                          IORESOURCE_MEM, gf);

           return 0;
   }


I added a few debug messages in request_region and got:

barebox 2013.05.0-00706-g87df6ec-dirty #13 Tue Jun 4 17:17:34 BST 2013

Board: DA923RC

dev_request_mem_region:got resource
request_region:name = gfar-phy0, parent = 1ffa6494
request_region ok: 0xe0024000:0xe0024fff
gfar_phy_probe:phy->regs= e0024000, 0
gfar_phy_probe: id = 0
mdio_bus: miibus0: probed
...
FSL_ETH_INIT: num = 0, 0xe0024000
dev_request_mem_region:got resource
request_region:name = gfar0, parent = 1ffa6494
request_region: 0xe0024000:0xe0024fff conflicts with 0xe0024000:0xe0024fff
gfar_probe:priv->regs 00000000, 0
gfar_halt:regs = 00000000

Even though, two devices have been added, both have the same parent 
iomem and the same region is compared. A conflict is then detected.
When gfar_probe requests its Ethernet register region, NULL is returned.




From antonynpavlov at gmail.com  Wed Jun  5 02:17:45 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Wed,  5 Jun 2013 10:17:45 +0400
Subject: [PATCH] MAKEALL: fix typos
Message-ID: <1370413065-27481-1-git-send-email-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 MAKEALL |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MAKEALL b/MAKEALL
index 18ed862..bf9131a 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -34,7 +34,7 @@ usage() {
 	echo "The cross-compiler can be specify via"
 	echo "    CROSS_COMPILE               default"
 	echo "    CROSS_COMPILE_<arch>        arch default"
-	echo "    CROSS_COMPILE_<target>      deconfig specifc"
+	echo "    CROSS_COMPILE_<target>      defconfig specific"
 	echo ""
 	echo "it will be evaluated in the invert order"
 	echo ""
@@ -70,7 +70,7 @@ stats() {
 	time_diff=$((${time_stop} - ${time_start}))
 	printf "compiled in %4is\n" ${time_diff}
 	if [ ${nb_errors} -gt 0 ] ; then
-		echo "defcongids with warnings or errors: ${nb_errors} (${errors_list} )"
+		echo "defconfigs with warnings or errors: ${nb_errors} (${errors_list} )"
 	fi
 	echo "----------------------------------------------------------"
 
-- 
1.7.10.4



From s.hauer at pengutronix.de  Wed Jun  5 02:34:14 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 08:34:14 +0200
Subject: [PATCH 1/3] Remove unnesessory malloc.h inclusions.
In-Reply-To: <1370349512-75630-1-git-send-email-monaka@monami-ya.jp>
References: <1370349512-75630-1-git-send-email-monaka@monami-ya.jp>
Message-ID: <20130605063414.GL32299@pengutronix.de>

On Tue, Jun 04, 2013 at 09:38:30PM +0900, Masaki Muranaka wrote:
> Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
> ---
>  commands/barebox-update.c | 1 -
>  commands/bootm.c          | 1 -
>  commands/cat.c            | 1 -
>  commands/cp.c             | 1 -
>  commands/crc.c            | 1 -
>  commands/dfu.c            | 1 -
>  commands/edit.c           | 1 -
>  commands/exec.c           | 1 -
>  commands/global.c         | 1 -
>  commands/i2c.c            | 1 -
>  commands/insmod.c         | 1 -
>  commands/let.c            | 1 -
>  commands/linux16.c        | 1 -
>  commands/loadxy.c         | 1 -
>  commands/ls.c             | 1 -
>  commands/md.c             | 1 -
>  commands/memcmp.c         | 1 -
>  commands/memcpy.c         | 1 -
>  commands/meminfo.c        | 1 -
>  commands/memset.c         | 1 -
>  commands/miitool.c        | 1 -
>  commands/mm.c             | 1 -
>  commands/mw.c             | 1 -
>  commands/nand.c           | 1 -
>  commands/nandtest.c       | 1 -
>  commands/of_node.c        | 1 -
>  commands/oftree.c         | 1 -
>  commands/partition.c      | 1 -
>  commands/readline.c       | 1 -
>  commands/readlink.c       | 1 -
>  commands/spi.c            | 1 -
>  commands/splash.c         | 1 -
>  commands/time.c           | 1 -
>  commands/ubiformat.c      | 1 -
>  commands/uimage.c         | 1 -
>  commands/usbserial.c      | 1 -
>  common/console.c          | 1 -
>  common/image.c            | 1 -
>  38 files changed, 38 deletions(-)

This still produces a lot of warnings:

commands/bootm.c:191:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/memcmp.c:125:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/memset.c:82:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/edit.c:175:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
include/stringlist.h:27:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/cp.c:75:4: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/cat.c:78:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/readline.c:33:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/time.c:41:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/global.c:34:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/readlink.c:58:3: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]
commands/oftree.c:197:2: warning: implicit declaration of function 'free' [-Wimplicit-function-declaration]

I think you have to replace it with stdlib.h in these files rather than
removing malloc.h (Of course after the free() prototype has been moved
to stdlib.h)

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun  5 02:38:15 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 08:38:15 +0200
Subject: [PATCH 2/3] Refactor malloc.h.
In-Reply-To: <1370349512-75630-2-git-send-email-monaka@monami-ya.jp>
References: <1370349512-75630-1-git-send-email-monaka@monami-ya.jp>
 <1370349512-75630-2-git-send-email-monaka@monami-ya.jp>
Message-ID: <20130605063815.GM32299@pengutronix.de>

On Tue, Jun 04, 2013 at 09:38:31PM +0900, Masaki Muranaka wrote:
> From: Masaki Muranaka <monaka at monami-ya.com>
> 
>  Some functions should be defined in stdlib.h or unistd.h.
> 
> Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
> ---
>  include/malloc.h       |  8 +++-----
>  include/malloc_isoc.h  | 11 +++++++++++
>  include/malloc_posix.h |  8 ++++++++
>  include/stdlib.h       |  1 +
>  include/unistd.h       |  6 ++++++
>  5 files changed, 29 insertions(+), 5 deletions(-)
>  create mode 100644 include/malloc_isoc.h
>  create mode 100644 include/malloc_posix.h
>  create mode 100644 include/unistd.h
> 
> diff --git a/include/malloc.h b/include/malloc.h
> index 7b9b062..9554597 100644
> --- a/include/malloc.h
> +++ b/include/malloc.h
> @@ -5,20 +5,18 @@
>  
>  /* Public routines */
>  
> -void* malloc(size_t);
> -void free(void*);
> -void* realloc(void*, size_t);
> +#include <malloc_isoc.h>
> +#include <malloc_posix.h>
> +
>  void* memalign(size_t, size_t);
>  void* vallocc(size_t);
>  void* pvalloc(size_t);
> -void* calloc(size_t, size_t);
>  void cfree(void*);
>  int malloc_trim(size_t);
>  size_t malloc_usable_size(void*);
>  void malloc_stats(void);
>  int mallopt(int, int);
>  struct mallinfo mallinfo(void);
> -void *sbrk(ptrdiff_t increment);
>  
>  #endif
>  
> diff --git a/include/malloc_isoc.h b/include/malloc_isoc.h
> new file mode 100644
> index 0000000..728cdd9
> --- /dev/null
> +++ b/include/malloc_isoc.h
> @@ -0,0 +1,11 @@
> +#ifndef BAREBOX_MALLOC_ISOC_H__
> +#define BAREBOX_MALLOC_ISOC_H__
> +
> +#include <types.h>
> +
> +void* malloc(size_t);
> +void free(void*);
> +void* realloc(void*, size_t);
> +void* calloc(size_t, size_t);
> +
> +#endif /* BAREBOX_MALLOC_ISOC_H__ */

I think you can just add these to stdlib.h...

> diff --git a/include/malloc_posix.h b/include/malloc_posix.h
> new file mode 100644
> index 0000000..d10675d
> --- /dev/null
> +++ b/include/malloc_posix.h
> @@ -0,0 +1,8 @@
> +#ifndef BAREBOX_MALLOC_POSIX_H__
> +#define BAREBOX_MALLOC_POSIX_H__
> +
> +#include <types.h>
> +
> +void *sbrk(ptrdiff_t increment);
> +
> +#endif /* BAREBOX_MALLOC_POSIX_H__ */

...and this to unistd.h without introducing extra files.

You're right that in barebox it's often not clear whether some code
belongs to 'kernel' or 'userspace', but in the end it doesn't make
much difference. It's good to have standard functions in their
standard include/ locations.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun  5 02:47:33 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 08:47:33 +0200
Subject: [PATCH 3/3] clk: add clock lookup from devicetree
In-Reply-To: <1370330951-3548-3-git-send-email-dev@lynxeye.de>
References: <1370330951-3548-1-git-send-email-dev@lynxeye.de>
 <1370330951-3548-3-git-send-email-dev@lynxeye.de>
Message-ID: <20130605064733.GN32299@pengutronix.de>

On Tue, Jun 04, 2013 at 09:29:11AM +0200, Lucas Stach wrote:
> Taken from the Linuxkernel with some small adjustments for barebox.
> 
> Signed-off-by: Lucas Stach <dev at lynxeye.de>
> ---
>  drivers/clk/clk.c    | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  drivers/clk/clkdev.c | 74 +++++++++++++++++++++++++++++++++++++++
>  include/linux/clk.h  | 33 ++++++++++++++++++
>  3 files changed, 204 insertions(+)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 690a0c6..bad3386 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -16,6 +16,7 @@
>   */
>  #include <common.h>
>  #include <errno.h>
> +#include <malloc.h>
>  #include <linux/clk.h>
>  #include <linux/err.h>
>  
> @@ -253,6 +254,102 @@ int clk_is_enabled_always(struct clk *clk)
>  	return 1;
>  }
>  
> +#ifdef CONFIG_OFTREE
> +/**
> + * struct of_clk_provider - Clock provider registration structure
> + * @link: Entry in global list of clock providers
> + * @node: Pointer to device tree node of clock provider
> + * @get: Get clock callback.  Returns NULL or a struct clk for the
> + *       given clock specifier
> + * @data: context pointer to be passed into @get callback
> + */
> +struct of_clk_provider {
> +	struct list_head link;
> +
> +	struct device_node *node;
> +	struct clk *(*get)(struct of_phandle_args *clkspec, void *data);
> +	void *data;
> +};
> +
> +static LIST_HEAD(of_clk_providers);
> +
> +struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data)
> +{
> +	struct clk_onecell_data *clk_data = data;
> +	unsigned int idx = clkspec->args[0];
> +
> +	if (idx >= clk_data->clk_num) {
> +		pr_err("%s: invalid clock index %d\n", __func__, idx);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	return clk_data->clks[idx];
> +}
> +EXPORT_SYMBOL_GPL(of_clk_src_onecell_get);
> +
> +/**
> + * of_clk_add_provider() - Register a clock provider for a node
> + * @np: Device node pointer associated with clock provider
> + * @clk_src_get: callback for decoding clock
> + * @data: context pointer for @clk_src_get callback.
> + */
> +int of_clk_add_provider(struct device_node *np,
> +			struct clk *(*clk_src_get)(struct of_phandle_args *clkspec,
> +						   void *data),
> +			void *data)
> +{
> +	struct of_clk_provider *cp;
> +
> +	cp = kzalloc(sizeof(struct of_clk_provider), GFP_KERNEL);
> +	if (!cp)
> +		return -ENOMEM;
> +
> +	cp->node = np;
> +	cp->data = data;
> +	cp->get = clk_src_get;
> +
> +	list_add(&cp->link, &of_clk_providers);
> +	pr_debug("Added clock from %s\n", np->full_name);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(of_clk_add_provider);
> +
> +/**
> + * of_clk_del_provider() - Remove a previously registered clock provider
> + * @np: Device node pointer associated with clock provider
> + */
> +void of_clk_del_provider(struct device_node *np)
> +{
> +	struct of_clk_provider *cp;
> +
> +	list_for_each_entry(cp, &of_clk_providers, link) {
> +		if (cp->node == np) {
> +			list_del(&cp->link);
> +			kfree(cp);
> +			break;
> +		}
> +	}
> +}
> +EXPORT_SYMBOL_GPL(of_clk_del_provider);
> +
> +struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
> +{
> +	struct of_clk_provider *provider;
> +	struct clk *clk = ERR_PTR(-ENOENT);
> +
> +	/* Check if we have such a provider in our array */
> +	list_for_each_entry(provider, &of_clk_providers, link) {
> +		if (provider->node == clkspec->np)
> +			clk = provider->get(clkspec, provider->data);
> +		if (!IS_ERR(clk))
> +			break;
> +	}
> +
> +	return clk;
> +}
> +#endif
> +
>  static void dump_one(struct clk *clk, int verbose, int indent)
>  {
>  	struct clk *c;
> diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
> index 256927e..0b91af0 100644
> --- a/drivers/clk/clkdev.c
> +++ b/drivers/clk/clkdev.c
> @@ -19,10 +19,80 @@
>  #include <linux/clkdev.h>
>  #include <init.h>
>  #include <malloc.h>
> +#include <of.h>
>  #include <stdio.h>
>  
>  static LIST_HEAD(clocks);
>  
> +#if defined(CONFIG_OFTREE) && defined(CONFIG_COMMON_CLK)
> +struct clk *of_clk_get(struct device_node *np, int index)
> +{
> +	struct of_phandle_args clkspec;
> +	struct clk *clk;
> +	int rc;
> +
> +	if (index < 0)
> +		return ERR_PTR(-EINVAL);
> +
> +	rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index,
> +					&clkspec);
> +	if (rc)
> +		return ERR_PTR(rc);
> +
> +	clk = of_clk_get_from_provider(&clkspec);
> +	return clk;
> +}
> +EXPORT_SYMBOL(of_clk_get);
> +
> +/**
> + * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
> + * @np: pointer to clock consumer node
> + * @name: name of consumer's clock input, or NULL for the first clock reference
> + *
> + * This function parses the clocks and clock-names properties,
> + * and uses them to look up the struct clk from the registered list of clock
> + * providers.
> + */
> +struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
> +{
> +	struct clk *clk = ERR_PTR(-ENOENT);
> +
> +	/* Walk up the tree of devices looking for a clock that matches */
> +	while (np) {
> +		int index = 0;
> +
> +		/*
> +		 * For named clocks, first look up the name in the
> +		 * "clock-names" property.  If it cannot be found, then
> +		 * index will be an error code, and of_clk_get() will fail.
> +		 */
> +		if (name)
> +			index = of_property_match_string(np, "clock-names",
> +							 name);
> +		clk = of_clk_get(np, index);
> +		if (!IS_ERR(clk))
> +			break;
> +		else if (name && index >= 0) {
> +			pr_err("ERROR: could not get clock %s:%s(%i)\n",
> +				np->full_name, name ? name : "", index);
> +			return clk;
> +		}
> +
> +		/*
> +		 * No matching clock found on this node.  If the parent node
> +		 * has a "clock-ranges" property, then we can try one of its
> +		 * clocks.
> +		 */
> +		np = np->parent;
> +		if (np && !of_get_property(np, "clock-ranges", NULL))
> +			break;
> +	}
> +
> +	return clk;
> +}
> +EXPORT_SYMBOL(of_clk_get_by_name);
> +#endif
> +
>  /*
>   * Find the correct struct clk for the device and connection ID.
>   * We do slightly fuzzy matching here:
> @@ -109,6 +179,10 @@ struct clk *clk_get(struct device_d *dev, const char *con_id)
>  	if (!IS_ERR(clk))
>  		return clk;
>  
> +	clk = of_clk_get_by_name(dev->device_node, con_id);
> +		if (!IS_ERR(clk))
> +			return clk;
> +
>  	return clk_get_sys(dev_id, con_id);
>  }
>  EXPORT_SYMBOL(clk_get);
> diff --git a/include/linux/clk.h b/include/linux/clk.h
> index 37a4813..0f7158a 100644
> --- a/include/linux/clk.h
> +++ b/include/linux/clk.h
> @@ -11,6 +11,8 @@
>  #ifndef __LINUX_CLK_H
>  #define __LINUX_CLK_H
>  
> +#include <linux/err.h>
> +
>  struct device_d;
>  
>  /*
> @@ -210,4 +212,35 @@ void clk_dump(int verbose);
>  
>  #endif
>  
> +struct device_node;
> +struct of_phandle_args;
> +
> +#if defined(CONFIG_OFTREE) && defined(CONFIG_COMMON_CLK)
> +int of_clk_add_provider(struct device_node *np,
> +			struct clk *(*clk_src_get)(struct of_phandle_args *args,
> +						   void *data),
> +			void *data);
> +void of_clk_del_provider(struct device_node *np);
> +
> +struct clk_onecell_data {
> +	struct clk **clks;
> +	unsigned int clk_num;
> +};
> +struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
> +
> +struct clk *of_clk_get(struct device_node *np, int index);
> +struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
> +struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);

Can we have a CLK_HAVE_OF_PROVIDER Kconfig symbol and a static inline
version of of_clk_get_from_provider if this is not set? On architectures
which do not call of_clk_add_provider this only adds to the binary space
otherwise.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun  5 02:51:18 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 08:51:18 +0200
Subject: [PATCH] MAKEALL: fix typos
In-Reply-To: <1370413065-27481-1-git-send-email-antonynpavlov@gmail.com>
References: <1370413065-27481-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <20130605065118.GO32299@pengutronix.de>

On Wed, Jun 05, 2013 at 10:17:45AM +0400, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> ---
>  MAKEALL |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/MAKEALL b/MAKEALL
> index 18ed862..bf9131a 100755
> --- a/MAKEALL
> +++ b/MAKEALL
> @@ -34,7 +34,7 @@ usage() {
>  	echo "The cross-compiler can be specify via"
>  	echo "    CROSS_COMPILE               default"
>  	echo "    CROSS_COMPILE_<arch>        arch default"
> -	echo "    CROSS_COMPILE_<target>      deconfig specifc"
> +	echo "    CROSS_COMPILE_<target>      defconfig specific"
>  	echo ""
>  	echo "it will be evaluated in the invert order"
>  	echo ""
> @@ -70,7 +70,7 @@ stats() {
>  	time_diff=$((${time_stop} - ${time_start}))
>  	printf "compiled in %4is\n" ${time_diff}
>  	if [ ${nb_errors} -gt 0 ] ; then
> -		echo "defcongids with warnings or errors: ${nb_errors} (${errors_list} )"
> +		echo "defconfigs with warnings or errors: ${nb_errors} (${errors_list} )"
>  	fi
>  	echo "----------------------------------------------------------"
>  
> -- 
> 1.7.10.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun  5 02:52:39 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 08:52:39 +0200
Subject: [PATCH V2] ARM i.MX6: set imx6 silicon revision
In-Reply-To: <1370351277-23582-1-git-send-email-sfricke@data-modul.com>
References: <1370351277-23582-1-git-send-email-sfricke@data-modul.com>
Message-ID: <20130605065239.GP32299@pengutronix.de>

On Tue, Jun 04, 2013 at 03:07:57PM +0200, S. Fricke wrote:
> From: "S. Fricke" <sfricke at data-modul.com>
> 
> This is mainly a backport of the imx6_revision function of
> arch/arm/mach-imx/mach-imx6q.c in the linux kernel sources.
> 
> Signed-off-by: S. Fricke <sfricke at data-modul.com>

Applied, thanks

Sascha

> ---
>  arch/arm/mach-imx/imx6.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
> index 5c20aa1..1d69ec8 100644
> --- a/arch/arm/mach-imx/imx6.c
> +++ b/arch/arm/mach-imx/imx6.c
> @@ -16,8 +16,11 @@
>  #include <io.h>
>  #include <sizes.h>
>  #include <mach/generic.h>
> +#include <mach/revision.h>
>  #include <mach/imx6-regs.h>
>  
> +#define SI_REV 0x260
> +
>  void imx6_init_lowlevel(void)
>  {
>  	void __iomem *aips1 = (void *)MX6_AIPS1_ON_BASE_ADDR;
> @@ -55,8 +58,31 @@ void imx6_init_lowlevel(void)
>  
>  static int imx6_init(void)
>  {
> +	u32 rev;
> +	u32 mx6_silicon_revision;
> +
>  	imx6_boot_save_loc((void *)MX6_SRC_BASE_ADDR);
>  
> +	rev = readl(MX6_ANATOP_BASE_ADDR + SI_REV);
> +	switch (rev & 0xff) {
> +	case 0x00:
> +		mx6_silicon_revision = IMX_CHIP_REV_1_0;
> +		break;
> +
> +	case 0x01:
> +		mx6_silicon_revision = IMX_CHIP_REV_1_1;
> +		break;
> +
> +	case 0x02:
> +		mx6_silicon_revision = IMX_CHIP_REV_1_2;
> +		break;
> +
> +	default:
> +		mx6_silicon_revision = IMX_CHIP_REV_UNKNOWN;
> +	}
> +
> +	imx_set_silicon_revision("i.MX6", mx6_silicon_revision);
> +
>  	if (of_get_root_node())
>  		return 0;
>  
> -- 
> 1.8.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun  5 03:12:11 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 09:12:11 +0200
Subject: [PATCH] gianfar: prevent resource conflict
In-Reply-To: <51AE1D69.4050205@ge.com>
References: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
 <20130601092018.GO32299@pengutronix.de> <51AC6286.5030001@ge.com>
 <51AE1D69.4050205@ge.com>
Message-ID: <20130605071211.GQ32299@pengutronix.de>

On Tue, Jun 04, 2013 at 06:01:29PM +0100, Renaud Barbier wrote:
> Hello Sacha,
> I applied your patch and try it on our mpc8544 based board
> with a few modification.
> This board uses eTSEC1. This means all 3 regions have the same
> base address.

I think I misunderstood the situation. I thought that the mdio register
space is separate from the network interface register space. So in
reality the mdio register space is inside the network register (the
TSEC) space, but one TSEC instance needs the mdio bus from the other
one, right?

If that's the case then it's probably best to register a phy driver for
each phy in a coredevice_initcall like I suggested and then use
dev_get_mem_region in the phy driver instead of dev_request_mem_region.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From antonynpavlov at gmail.com  Wed Jun  5 03:32:51 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Wed,  5 Jun 2013 11:32:51 +0400
Subject: [PATCH] clk: fix warning: no previous prototype for 'clk_is_enabled'
Message-ID: <1370417571-28072-1-git-send-email-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 drivers/clk/clk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 690a0c6..a3def53 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -208,7 +208,7 @@ int clk_register(struct clk *clk)
 	return 0;
 }
 
-int clk_is_enabled(struct clk *clk)
+static int clk_is_enabled(struct clk *clk)
 {
 	int enabled;
 
-- 
1.7.10.4



From renaud.barbier at ge.com  Wed Jun  5 05:05:55 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 05 Jun 2013 10:05:55 +0100
Subject: [PATCH] gianfar: prevent resource conflict
In-Reply-To: <20130605071211.GQ32299@pengutronix.de>
References: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
 <20130601092018.GO32299@pengutronix.de> <51AC6286.5030001@ge.com>
 <51AE1D69.4050205@ge.com> <20130605071211.GQ32299@pengutronix.de>
Message-ID: <51AEFF73.204@ge.com>

On 05/06/2013 08:12, Sascha Hauer wrote:
> On Tue, Jun 04, 2013 at 06:01:29PM +0100, Renaud Barbier wrote:
>> Hello Sacha,
>> I applied your patch and try it on our mpc8544 based board
>> with a few modification.
>> This board uses eTSEC1. This means all 3 regions have the same
>> base address.
>
> I think I misunderstood the situation. I thought that the mdio register
> space is separate from the network interface register space. So in
> reality the mdio register space is inside the network register (the
> TSEC) space, but one TSEC instance needs the mdio bus from the other
> one, right?

Yes.
All eTSEC uses the eTSEC1 region to access the mdio bus for external 
PHYs. Port eTSEC1 3 regions (Ethernet reg, External phy access, TBI 
interface) are in fact just one region.

For eTSEC2, the Ethernet registers and TBI interface are mapped by the 
same region but are not the same as the other port regions.
The same applies for eTSEC3.

For TSEC version 2, the mapping is a bit different.

I will  implement your suggestions below.

>
> If that's the case then it's probably best to register a phy driver for
> each phy in a coredevice_initcall like I suggested and then use
> dev_get_mem_region in the phy driver instead of dev_request_mem_region.
>
> Sascha
>



From J.Weitzel at phytec.de  Wed Jun  5 05:52:42 2013
From: J.Weitzel at phytec.de (Jan Weitzel)
Date: Wed, 05 Jun 2013 11:52:42 +0200
Subject: [PATCH] omap4: set voltage according to mpu freq
In-Reply-To: <20130530093936.GB32299@pengutronix.de>
References: <1369741903-24988-1-git-send-email-j.weitzel@phytec.de>
 <20130530093936.GB32299@pengutronix.de>
Message-ID: <1370425962.3824.1.camel@lws-weitzel>

Am Donnerstag, den 30.05.2013, 11:39 +0200 schrieb Sascha Hauer:
> On Tue, May 28, 2013 at 01:51:39PM +0200, Jan Weitzel wrote:
> > For OMAP4460 omap4_scale_vcores must set the voltage according to mpu freq.
> > 
> > OPP100  700MHz 1210mV
> > OPPTB   920MHz 1320mV
> > OPPNT  1200MHz 1380mV
> > 
> > Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
> > ---
> >  arch/arm/boards/archosg9/lowlevel.c             |    2 +-
> >  arch/arm/boards/panda/lowlevel.c                |    2 +-
> >  arch/arm/boards/pcm049/lowlevel.c               |    2 +-
> >  arch/arm/boards/phycard-a-xl2/lowlevel.c        |    2 +-
> >  arch/arm/mach-omap/include/mach/omap4-silicon.h |    2 +-
> >  arch/arm/mach-omap/omap4_generic.c              |    6 +++---
> >  6 files changed, 8 insertions(+), 8 deletions(-)
> > 
> > diff --git a/arch/arm/boards/archosg9/lowlevel.c b/arch/arm/boards/archosg9/lowlevel.c
> > index 0334693..0fae6da 100644
> > --- a/arch/arm/boards/archosg9/lowlevel.c
> > +++ b/arch/arm/boards/archosg9/lowlevel.c
> > @@ -49,7 +49,7 @@ static noinline void archosg9_init_lowlevel(void)
> >  	set_muxconf_regs();
> >  
> >  	/* Set VCORE1 = 1.3 V, VCORE2 = VCORE3 = 1.21V */
> > -	omap4_scale_vcores(TPS62361_VSEL0_GPIO);
> > +	omap4_scale_vcores(TPS62361_VSEL0_GPIO, 1380);
> >  
> >  	/* Enable all clocks */
> >  	omap4_enable_all_clocks();
> > diff --git a/arch/arm/boards/panda/lowlevel.c b/arch/arm/boards/panda/lowlevel.c
> > index ed1dc6f..591ff2f 100644
> > --- a/arch/arm/boards/panda/lowlevel.c
> > +++ b/arch/arm/boards/panda/lowlevel.c
> > @@ -70,7 +70,7 @@ static void noinline panda_init_lowlevel(void)
> >  	omap4_ddr_init(&ddr_regs_400_mhz_2cs, &core);
> >  
> >  	/* Set VCORE1 = 1.3 V, VCORE2 = VCORE3 = 1.21V */
> > -	omap4_scale_vcores(TPS62361_VSEL0_GPIO);
> > +	omap4_scale_vcores(TPS62361_VSEL0_GPIO, 1210);
> >  }
> >  
> >  void barebox_arm_reset_vector(void)
> > diff --git a/arch/arm/boards/pcm049/lowlevel.c b/arch/arm/boards/pcm049/lowlevel.c
> > index 33519f7..8548868 100644
> > --- a/arch/arm/boards/pcm049/lowlevel.c
> > +++ b/arch/arm/boards/pcm049/lowlevel.c
> > @@ -109,7 +109,7 @@ static void noinline pcm049_init_lowlevel(void)
> >  #endif
> >  
> >  	/* Set VCORE1 = 1.3 V, VCORE2 = VCORE3 = 1.21V */
> > -	omap4_scale_vcores(TPS62361_VSEL0_GPIO);
> > +	omap4_scale_vcores(TPS62361_VSEL0_GPIO, 1320);
> >  
> >  	writel(CM_SYS_CLKSEL_19M2, CM_SYS_CLKSEL);
> >  
> > diff --git a/arch/arm/boards/phycard-a-xl2/lowlevel.c b/arch/arm/boards/phycard-a-xl2/lowlevel.c
> > index 07505ff..3750bae 100644
> > --- a/arch/arm/boards/phycard-a-xl2/lowlevel.c
> > +++ b/arch/arm/boards/phycard-a-xl2/lowlevel.c
> > @@ -58,7 +58,7 @@ static noinline void pcaaxl2_init_lowlevel(void)
> >  	omap4_ddr_init(&ddr_regs_mt42L64M64_25_400_mhz, &core);
> >  
> >  	/* Set VCORE1 = 1.3 V, VCORE2 = VCORE3 = 1.21V */
> > -	omap4_scale_vcores(TPS62361_VSEL0_GPIO);
> > +	omap4_scale_vcores(TPS62361_VSEL0_GPIO, 1320);
> >  
> >  	writel(CM_SYS_CLKSEL_19M2, CM_SYS_CLKSEL);
> >  
> > diff --git a/arch/arm/mach-omap/include/mach/omap4-silicon.h b/arch/arm/mach-omap/include/mach/omap4-silicon.h
> > index 9e82435..5684a38 100644
> > --- a/arch/arm/mach-omap/include/mach/omap4-silicon.h
> > +++ b/arch/arm/mach-omap/include/mach/omap4-silicon.h
> > @@ -211,7 +211,7 @@ struct dpll_param;
> >  void omap4_ddr_init(const struct ddr_regs *, const struct dpll_param *);
> >  void omap4_power_i2c_send(u32);
> >  unsigned int omap4_revision(void);
> > -noinline int omap4_scale_vcores(unsigned vsel0_pin);
> > +noinline int omap4_scale_vcores(unsigned vsel0_pin, unsigned volt_mv);
> >  
> >  #endif
> >  
> > diff --git a/arch/arm/mach-omap/omap4_generic.c b/arch/arm/mach-omap/omap4_generic.c
> > index 38993be..1eeaf30 100644
> > --- a/arch/arm/mach-omap/omap4_generic.c
> > +++ b/arch/arm/mach-omap/omap4_generic.c
> > @@ -511,7 +511,7 @@ static void __iomem *omap4_get_gpio_base(unsigned gpio)
> >  
> >  #define I2C_SLAVE 0x12
> >  
> > -noinline int omap4_scale_vcores(unsigned vsel0_pin)
> > +noinline int omap4_scale_vcores(unsigned vsel0_pin, unsigned volt_mv)
> >  {
> >  	void __iomem *base;
> >  	unsigned int rev = omap4_revision();
> > @@ -529,8 +529,8 @@ noinline int omap4_scale_vcores(unsigned vsel0_pin)
> >  		 * Setup SET1 and SET0 with right values so that kernel
> >  		 * can use either of them based on its needs.
> >  		 */
> > -		omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, 1430);
> > -		omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET1, 1430);
> > +		omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, volt_mv);
> > +		omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET1, volt_mv);
> 
> This adds a parameter volt_mv which is written to some register, but
> only on a omap4460.
> This is all very nonobvious to me. I wonder if this setup could be
> improved somehow to leave a better feeling? How about separating
> omap4430 and omap4460 setup? Then maybe omap4430 wouldn't have to pass
> a meaningles parameter to this function.
The first parameter (gpio) is also meaningles, I send a patch which also
splits omap4_scale_vcores

Jan
> 
> Sascha
> 




From J.Weitzel at phytec.de  Wed Jun  5 06:56:18 2013
From: J.Weitzel at phytec.de (Jan Weitzel)
Date: Wed, 05 Jun 2013 12:56:18 +0200
Subject: [PATCH] OMAP4: Use default clock source for mcbsp
In-Reply-To: <20130604145327.GJ32299@pengutronix.de>
References: <1369741903-24988-2-git-send-email-j.weitzel@phytec.de>
 <20130604145327.GJ32299@pengutronix.de>
Message-ID: <1370429778.3824.7.camel@lws-weitzel>

Am Dienstag, den 04.06.2013, 16:53 +0200 schrieb Sascha Hauer:
> Hi Jan,
> 
> On Tue, May 28, 2013 at 01:51:40PM +0200, Jan Weitzel wrote:
> > In omap4_enable_all_clocks we not only enable the mcbsp clocks, but also
> > change the source from ABE_24M_FCLK to 24M_FCLK. Revert this and default
> > to the reset state.
> 
> Can you add a description why this is necessary?
We had some trouble because the kernel takes the default clock sources
from the registers. There seams to be no reason to change them in the
boot loader. Is clean up a good enough answer?
Could someone test it on pandaboard and ArchosG9? I didn't have
(working) hardware here.

Jan
> 
> Sascha
> 
> > 
> > Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
> > ---
> >  arch/arm/mach-omap/omap4_clock.c |    6 +++---
> >  1 files changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arch/arm/mach-omap/omap4_clock.c b/arch/arm/mach-omap/omap4_clock.c
> > index 0621fd3..889d1f9 100644
> > --- a/arch/arm/mach-omap/omap4_clock.c
> > +++ b/arch/arm/mach-omap/omap4_clock.c
> > @@ -253,9 +253,9 @@ void omap4_enable_all_clocks(void)
> >  	sr32(CM1_ABE_PDM_CLKCTRL, 0, 32, 0x2);
> >  	sr32(CM1_ABE_DMIC_CLKCTRL, 0, 32, 0x2);
> >  	sr32(CM1_ABE_MCASP_CLKCTRL, 0, 32, 0x2);
> > -	sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x08000002);
> > -	sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x08000002);
> > -	sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x08000002);
> > +	sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x2);
> > +	sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x2);
> > +	sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x2);
> >  	sr32(CM1_ABE_SLIMBUS_CLKCTRL, 0, 32, 0xf02);
> >  	sr32(CM1_ABE_TIMER5_CLKCTRL, 0, 32, 0x2);
> >  	sr32(CM1_ABE_TIMER6_CLKCTRL, 0, 32, 0x2);
> > -- 
> > 1.7.0.4
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> > 
> 




From l.stach at pengutronix.de  Wed Jun  5 09:26:08 2013
From: l.stach at pengutronix.de (Lucas Stach)
Date: Wed,  5 Jun 2013 15:26:08 +0200
Subject: [PATCH] Revert "usb: chipidea-imx: Fix usb initialization"
Message-ID: <1370438768-13729-1-git-send-email-l.stach@pengutronix.de>

This breaks HSIC and has no good justification why this would
be needed for ULPI.

This reverts commit 2e7d66f526217f6ff3167e4580aecb9548a0de33.

Signed-off-by: Lucas Stach <l.stach at pengutronix.de>
---
 drivers/usb/imx/chipidea-imx.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 928ebf3..4ee7610 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -148,13 +148,13 @@ static int imx_chipidea_probe(struct device_d *dev)
 	ci->data.post_init = imx_chipidea_port_post_init;
 	ci->data.drvdata = ci;
 
+	imx_chipidea_port_init(ci);
+
 	portsc = readl(base + 0x184);
 	portsc &= ~MXC_EHCI_PORTSC_MASK;
 	portsc |= ci->flags & MXC_EHCI_PORTSC_MASK;
 	writel(portsc, base + 0x184);
 
-	imx_chipidea_port_init(ci);
-
 	if ((ci->flags & MXC_EHCI_PORTSC_MASK) == MXC_EHCI_MODE_ULPI) {
 		dev_dbg(dev, "using ULPI phy\n");
 		if (IS_ENABLED(CONFIG_USB_ULPI)) {
-- 
1.7.10.4



From shc_work at mail.ru  Wed Jun  5 09:33:55 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Wed, 05 Jun 2013 17:33:55 +0400
Subject: =?UTF-8?B?UmU6IFtQQVRDSF0gUmV2ZXJ0ICJ1c2I6IGNoaXBpZGVhLWlteDogRml4IHVz?=
 =?UTF-8?B?YiBpbml0aWFsaXphdGlvbiI=?=
In-Reply-To: <1370438768-13729-1-git-send-email-l.stach@pengutronix.de>
References: <1370438768-13729-1-git-send-email-l.stach@pengutronix.de>
Message-ID: <1370439235.553989759@f166.mail.ru>



> This breaks HSIC and has no good justification why this would
> be needed for ULPI.
> 
> This reverts commit 2e7d66f526217f6ff3167e4580aecb9548a0de33.
> 
> Signed-off-by: Lucas Stach <l.stach at pengutronix.de>
> ---
>  drivers/usb/imx/chipidea-imx.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
> index 928ebf3..4ee7610 100644
> --- a/drivers/usb/imx/chipidea-imx.c
> +++ b/drivers/usb/imx/chipidea-imx.c
> @@ -148,13 +148,13 @@ static int imx_chipidea_probe(struct device_d *dev)
>  	ci->data.post_init = imx_chipidea_port_post_init;
>  	ci->data.drvdata = ci;
>  
> +	imx_chipidea_port_init(ci);
> +
>  	portsc = readl(base + 0x184);
>  	portsc &= ~MXC_EHCI_PORTSC_MASK;
>  	portsc |= ci->flags & MXC_EHCI_PORTSC_MASK;
>  	writel(portsc, base + 0x184);
>  
> -	imx_chipidea_port_init(ci);
> -
>  	if ((ci->flags & MXC_EHCI_PORTSC_MASK) == MXC_EHCI_MODE_ULPI) {
>  		dev_dbg(dev, "using ULPI phy\n");
>  		if (IS_ENABLED(CONFIG_USB_ULPI)) {

This order was be before driver rework. Unfortunately I can not check right now,
but when I test initial version, it was be a proper order, at least for pcm038 (imx27 module).

---

From l.stach at pengutronix.de  Wed Jun  5 11:18:49 2013
From: l.stach at pengutronix.de (Lucas Stach)
Date: Wed, 05 Jun 2013 17:18:49 +0200
Subject: [PATCH 1/5] pinctrl: imx-iomux-v3: only register pinctrl when
 device node is available
In-Reply-To: <1369121895-11282-2-git-send-email-s.hauer@pengutronix.de>
References: <1369121895-11282-1-git-send-email-s.hauer@pengutronix.de>
 <1369121895-11282-2-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370445529.4279.11.camel@weser.hi.pengutronix.de>

This commit isn't included in the 2013.06 release.

I hereby nominate it as a candidate for the v2013.06 stable branch.

Am Dienstag, den 21.05.2013, 09:38 +0200 schrieb Sascha Hauer:
> The pinctrl support is devicetree only, so only register it
> when we actually have a devicetree. Otherwise we crash boards
> using the iomux-v3 from platform code in pinctrl_register().
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  drivers/pinctrl/imx-iomux-v3.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/imx-iomux-v3.c b/drivers/pinctrl/imx-iomux-v3.c
> index 3ff3c15..c867a23 100644
> --- a/drivers/pinctrl/imx-iomux-v3.c
> +++ b/drivers/pinctrl/imx-iomux-v3.c
> @@ -177,7 +177,7 @@ static int imx_iomux_v3_probe(struct device_d *dev)
>  	iomuxv3_base = dev_request_mem_region(dev, 0);
>  	iomuxv3_dev = dev;
>  
> -	if (IS_ENABLED(CONFIG_PINCTRL))
> +	if (IS_ENABLED(CONFIG_PINCTRL) && dev->device_node)
>  		ret = imx_pinctrl_dt(dev, iomuxv3_base);
>  
>  	return ret;

-- 
Pengutronix e.K.                           | Lucas Stach                 |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-5076 |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From s.hauer at pengutronix.de  Wed Jun  5 16:20:31 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 22:20:31 +0200
Subject: [PATCH] Revert "usb: chipidea-imx: Fix usb initialization"
In-Reply-To: <1370439235.553989759@f166.mail.ru>
References: <1370438768-13729-1-git-send-email-l.stach@pengutronix.de>
 <1370439235.553989759@f166.mail.ru>
Message-ID: <20130605202031.GU32299@pengutronix.de>

On Wed, Jun 05, 2013 at 05:33:55PM +0400, Alexander Shiyan wrote:
> 
> 
> > This breaks HSIC and has no good justification why this would
> > be needed for ULPI.
> > 
> > This reverts commit 2e7d66f526217f6ff3167e4580aecb9548a0de33.
> > 
> > Signed-off-by: Lucas Stach <l.stach at pengutronix.de>
> > ---
> >  drivers/usb/imx/chipidea-imx.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
> > index 928ebf3..4ee7610 100644
> > --- a/drivers/usb/imx/chipidea-imx.c
> > +++ b/drivers/usb/imx/chipidea-imx.c
> > @@ -148,13 +148,13 @@ static int imx_chipidea_probe(struct device_d *dev)
> >  	ci->data.post_init = imx_chipidea_port_post_init;
> >  	ci->data.drvdata = ci;
> >  
> > +	imx_chipidea_port_init(ci);
> > +
> >  	portsc = readl(base + 0x184);
> >  	portsc &= ~MXC_EHCI_PORTSC_MASK;
> >  	portsc |= ci->flags & MXC_EHCI_PORTSC_MASK;
> >  	writel(portsc, base + 0x184);
> >  
> > -	imx_chipidea_port_init(ci);
> > -
> >  	if ((ci->flags & MXC_EHCI_PORTSC_MASK) == MXC_EHCI_MODE_ULPI) {
> >  		dev_dbg(dev, "using ULPI phy\n");
> >  		if (IS_ENABLED(CONFIG_USB_ULPI)) {
> 
> This order was be before driver rework. Unfortunately I can not check right now,
> but when I test initial version, it was be a proper order, at least for pcm038 (imx27 module).

I just tried it here on our pcm038 board. With first stage USB2 never
works, no matter if this patch is reverted or not. if I start barebox
second stage it always works.

It helps to try a few more times to detect a phy. The first reads often
return wrong results. The following patch makes USB2 work here.

Sascha

8<-------------------------------------------------------

>From 2d280e354b946a51ae394bcedd476800c8beabf7 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer at pengutronix.de>
Date: Wed, 5 Jun 2013 22:13:05 +0200
Subject: [PATCH] usb: ulpi: Try more often to detect a phy

Some boards need some more tries to successfully detect a phy. This
happens for example on the pcm038. Try up to four times to detect a
phy.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/otg/ulpi.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/otg/ulpi.c
index 19f64e0..e0aa201 100644
--- a/drivers/usb/otg/ulpi.c
+++ b/drivers/usb/otg/ulpi.c
@@ -146,9 +146,9 @@ static struct ulpi_info ulpi_ids[] = {
 	ULPI_INFO(ULPI_ID(0x0424, 0x0006), "SMSC USB331x"),
 };
 
-int ulpi_probe(void __iomem *view)
+static int ulpi_read_id(void __iomem *view, int *vid, int *pid)
 {
-	int i, vid, pid, ret;
+	int i, ret;
 	uint32_t ulpi_id = 0;
 
 	for (i = 0; i < 4; i++) {
@@ -157,20 +157,34 @@ int ulpi_probe(void __iomem *view)
 			return ret;
 		ulpi_id = (ulpi_id << 8) | ret;
 	}
-	vid = ulpi_id & 0xffff;
-	pid = ulpi_id >> 16;
-
-	for (i = 0; i < ARRAY_SIZE(ulpi_ids); i++) {
-		if (ulpi_ids[i].id == ULPI_ID(vid, pid)) {
-			pr_info("Found %s ULPI transceiver (0x%04x:0x%04x).\n",
-			ulpi_ids[i].name, vid, pid);
-			return 0;
+
+	*vid = ulpi_id & 0xffff;
+	*pid = (ulpi_id >> 16) & 0xffff;
+
+	return 0;
+}
+
+int ulpi_probe(void __iomem *view)
+{
+	int i, j, vid, pid, ret;
+
+	for (i = 0; i < 4; i++) {
+		ret = ulpi_read_id(view, &vid, &pid);
+		if (ret)
+			return ret;
+
+		for (j = 0; j < ARRAY_SIZE(ulpi_ids); j++) {
+			if (ulpi_ids[j].id == ULPI_ID(vid, pid)) {
+				pr_info("Found %s ULPI transceiver (0x%04x:0x%04x).\n",
+				ulpi_ids[j].name, vid, pid);
+				return 0;
+			}
 		}
 	}
 
-	pr_err("No ULPI found.\n");
+	pr_err("No ULPI found. vid: 0x%04x pid: 0x%04x\n", vid, pid);
 
-	return -1;
+	return -ENODEV;
 }
 
 int ulpi_set_vbus(void __iomem *view, int on)
-- 
1.8.2.rc2


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun  5 16:33:12 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 22:33:12 +0200
Subject: [PATCH 1/5] pinctrl: imx-iomux-v3: only register pinctrl when
 device node is available
In-Reply-To: <1370445529.4279.11.camel@weser.hi.pengutronix.de>
References: <1369121895-11282-1-git-send-email-s.hauer@pengutronix.de>
 <1369121895-11282-2-git-send-email-s.hauer@pengutronix.de>
 <1370445529.4279.11.camel@weser.hi.pengutronix.de>
Message-ID: <20130605203312.GV32299@pengutronix.de>

On Wed, Jun 05, 2013 at 05:18:49PM +0200, Lucas Stach wrote:
> This commit isn't included in the 2013.06 release.
> 
> I hereby nominate it as a candidate for the v2013.06 stable branch.

Ok, just queued it for stable.

Sascha

> 
> Am Dienstag, den 21.05.2013, 09:38 +0200 schrieb Sascha Hauer:
> > The pinctrl support is devicetree only, so only register it
> > when we actually have a devicetree. Otherwise we crash boards
> > using the iomux-v3 from platform code in pinctrl_register().
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  drivers/pinctrl/imx-iomux-v3.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/pinctrl/imx-iomux-v3.c b/drivers/pinctrl/imx-iomux-v3.c
> > index 3ff3c15..c867a23 100644
> > --- a/drivers/pinctrl/imx-iomux-v3.c
> > +++ b/drivers/pinctrl/imx-iomux-v3.c
> > @@ -177,7 +177,7 @@ static int imx_iomux_v3_probe(struct device_d *dev)
> >  	iomuxv3_base = dev_request_mem_region(dev, 0);
> >  	iomuxv3_dev = dev;
> >  
> > -	if (IS_ENABLED(CONFIG_PINCTRL))
> > +	if (IS_ENABLED(CONFIG_PINCTRL) && dev->device_node)
> >  		ret = imx_pinctrl_dt(dev, iomuxv3_base);
> >  
> >  	return ret;
> 
> -- 
> Pengutronix e.K.                           | Lucas Stach                 |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-5076 |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun  5 16:34:27 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 22:34:27 +0200
Subject: [PATCH] clk: fix warning: no previous prototype for
 'clk_is_enabled'
In-Reply-To: <1370417571-28072-1-git-send-email-antonynpavlov@gmail.com>
References: <1370417571-28072-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <20130605203427.GW32299@pengutronix.de>

On Wed, Jun 05, 2013 at 11:32:51AM +0400, Antony Pavlov wrote:
> Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>

Applied, thanks

Sascha

> ---
>  drivers/clk/clk.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 690a0c6..a3def53 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -208,7 +208,7 @@ int clk_register(struct clk *clk)
>  	return 0;
>  }
>  
> -int clk_is_enabled(struct clk *clk)
> +static int clk_is_enabled(struct clk *clk)
>  {
>  	int enabled;
>  
> -- 
> 1.7.10.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From vicencb at gmail.com  Wed Jun  5 16:50:32 2013
From: vicencb at gmail.com (vj)
Date: Wed, 5 Jun 2013 22:50:32 +0200
Subject: [PATCH] OMAP4: Use default clock source for mcbsp
In-Reply-To: <1370429778.3824.7.camel@lws-weitzel>
References: <1369741903-24988-2-git-send-email-j.weitzel@phytec.de>
 <20130604145327.GJ32299@pengutronix.de>
 <1370429778.3824.7.camel@lws-weitzel>
Message-ID: <CAAMcf8AczuT9Z+6Tn3YzrrBe4KXziiR+D+2tb6RvUxZYb=eugA@mail.gmail.com>

On Wed, Jun 5, 2013 at 12:56 PM, Jan Weitzel <J.Weitzel at phytec.de> wrote:
> Am Dienstag, den 04.06.2013, 16:53 +0200 schrieb Sascha Hauer:
>> Hi Jan,
>>
>> On Tue, May 28, 2013 at 01:51:40PM +0200, Jan Weitzel wrote:
>> > In omap4_enable_all_clocks we not only enable the mcbsp clocks, but also
>> > change the source from ABE_24M_FCLK to 24M_FCLK. Revert this and default
>> > to the reset state.
>>
>> Can you add a description why this is necessary?
> We had some trouble because the kernel takes the default clock sources
> from the registers. There seams to be no reason to change them in the
> boot loader. Is clean up a good enough answer?
> Could someone test it on pandaboard and ArchosG9? I didn't have
> (working) hardware here.
>
I've seen no regressions on ArchosG9.
Regards,
  Vicente.

> Jan
>>
>> Sascha
>>
>> >
>> > Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
>> > ---
>> >  arch/arm/mach-omap/omap4_clock.c |    6 +++---
>> >  1 files changed, 3 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/arch/arm/mach-omap/omap4_clock.c b/arch/arm/mach-omap/omap4_clock.c
>> > index 0621fd3..889d1f9 100644
>> > --- a/arch/arm/mach-omap/omap4_clock.c
>> > +++ b/arch/arm/mach-omap/omap4_clock.c
>> > @@ -253,9 +253,9 @@ void omap4_enable_all_clocks(void)
>> >     sr32(CM1_ABE_PDM_CLKCTRL, 0, 32, 0x2);
>> >     sr32(CM1_ABE_DMIC_CLKCTRL, 0, 32, 0x2);
>> >     sr32(CM1_ABE_MCASP_CLKCTRL, 0, 32, 0x2);
>> > -   sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x08000002);
>> > -   sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x08000002);
>> > -   sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x08000002);
>> > +   sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x2);
>> > +   sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x2);
>> > +   sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x2);
>> >     sr32(CM1_ABE_SLIMBUS_CLKCTRL, 0, 32, 0xf02);
>> >     sr32(CM1_ABE_TIMER5_CLKCTRL, 0, 32, 0x2);
>> >     sr32(CM1_ABE_TIMER6_CLKCTRL, 0, 32, 0x2);
>> > --
>> > 1.7.0.4
>> >
>> >
>> > _______________________________________________
>> > barebox mailing list
>> > barebox at lists.infradead.org
>> > http://lists.infradead.org/mailman/listinfo/barebox
>> >
>>
>
>


From s.hauer at pengutronix.de  Wed Jun  5 17:15:35 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 5 Jun 2013 23:15:35 +0200
Subject: [PATCH/RFC 0/5] Another try for a new memtest implementation
In-Reply-To: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
References: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
Message-ID: <20130605211535.GX32299@pengutronix.de>

Hi Alex,

On Tue, Jun 04, 2013 at 01:13:47AM +0200, Alexander Aring wrote:
> Hi,
> 
> this is a new try to get a new memtest implementation into barebox.
> 
> I removed the ADDRESS_IN_REGIONS macro, which was a very ugly solution.

Indeed, much nicer now.

> The new memtest command used a list and save all unused sdram_regions
> of each bank. Then running the mem_test routine on these regions.
> After that the memtest command will release the requested sdram_regions.
> 
> I removed the start and stop command arguments to make the implementation
> easier/understandable and it's not necessary anyway.

Specifying a region would be nice, but not really necessary.

> 
> Maybe it's better to remove the silent ALIGN and ALIGN_DOWN from the start
> and end address in the common mem_test routine, because addresses are already
> align.
> It is difficult to explain because a end address has the form of 0xXXXXffff
> and a ALIGN_DOWN on it with a mask of 3 we have a calculated end address of
> 0xXXXXfffA which is wrong. (0xXXXXffff - 4) - 1...
> 
> Another question is:
> Can someone test it with more than one bank, please? :-)

I gave it a test on a karo tx25 board which has two memory banks. It
works just like expected :)

Overall this looks really good now. I just applied it to -next.

Thanks
 Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From philipp.zabel at gmail.com  Thu Jun  6 02:32:49 2013
From: philipp.zabel at gmail.com (Philipp Zabel)
Date: Thu,  6 Jun 2013 08:32:49 +0200
Subject: [PATCH] ARM i.MX6: Fix bootsource detection
Message-ID: <1370500369-3657-1-git-send-email-philipp.zabel@gmail.com>

This patch fixes bootsource detection on i.MX6 for serial and i2c boot.
The bootsource_instance is now determined for spi, i2c, and mmc/sd boot.

Signed-off-by: Philipp Zabel <philipp.zabel at gmail.com>
---
 arch/arm/mach-imx/boot.c |   26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index bd0cb84..4d81fd4 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -217,11 +217,13 @@ void imx53_boot_save_loc(void __iomem *src_base)
 void imx6_boot_save_loc(void __iomem *src_base)
 {
 	enum bootsource src = BOOTSOURCE_UNKNOWN;
-	uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2) >> 24;
-	uint32_t cfg1 = readl(src_base + IMX6_SRC_SBMR1) & 0xff;
+	int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
+	uint32_t sbmr1 = readl(src_base + IMX6_SRC_SBMR1);
+	uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
 	uint32_t boot_cfg_4_2_0;
 	int boot_mode;
 
+	/* BMOD[1:0] */
 	boot_mode = (sbmr2 >> 24) & 0x3;
 
 	switch (boot_mode) {
@@ -241,32 +243,42 @@ void imx6_boot_save_loc(void __iomem *src_base)
 
 internal_boot:
 
-	switch (cfg1 >> 4) {
+	/* BOOT_CFG1[7:4] */
+	switch ((sbmr1 >> 4) & 0xf) {
 	case 2:
 		src = BOOTSOURCE_HD;
 		break;
 	case 3:
-		boot_cfg_4_2_0 = (cfg1 >> 16) & 0x7;
+		/* BOOT_CFG4[2:0] */
+		boot_cfg_4_2_0 = (sbmr1 >> 24) & 0x7;
 
-		if (boot_cfg_4_2_0 > 4)
+		if (boot_cfg_4_2_0 > 4) {
 			src = BOOTSOURCE_I2C;
-		else
+			instance = boot_cfg_4_2_0 - 5;
+		} else {
 			src = BOOTSOURCE_SPI;
+			instance = boot_cfg_4_2_0;
+		}
 		break;
 	case 4:
 	case 5:
 	case 6:
 	case 7:
 		src = BOOTSOURCE_MMC;
+
+		/* BOOT_CFG2[4:3] */
+		instance = (sbmr1 >> 11) & 0x3;
 		break;
 	default:
 		break;
 	}
 
-	if (cfg1 & (1 << 7))
+	/* BOOT_CFG1[7:0] */
+	if (sbmr1 & (1 << 7))
 		src = BOOTSOURCE_NAND;
 
 	bootsource_set(src);
+	bootsource_set_instance(instance);
 
 	return;
 }
-- 
1.7.10.4



From antonynpavlov at gmail.com  Thu Jun  6 03:52:45 2013
From: antonynpavlov at gmail.com (antonynpavlov at gmail.com)
Date: Thu, 6 Jun 2013 11:52:45 +0400
Subject: [PATCH/RFC 0/5] Another try for a new memtest implementation
In-Reply-To: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
References: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
Message-ID: <20130606115245.a8add6e7ee99b4354fd9df84@gmail.com>

On Tue,  4 Jun 2013 01:13:47 +0200
Alexander Aring <alex.aring at gmail.com> wrote:

> Hi,
> 
> this is a new try to get a new memtest implementation into barebox.
> 

I have got the new memtest command from the next branch.

Here is my MIPS qemu-malta build log:

  CC      commands/memtest.o
commands/memtest.c: In function `alloc_memtest_region':
commands/memtest.c:39: warning: implicit declaration of function `xzalloc'
commands/memtest.c:39: warning: assignment makes pointer from integer without a cast
commands/memtest.c:42: error: `EINVAL' undeclared (first use in this function)
commands/memtest.c:42: error: (Each undeclared identifier is reported only once
commands/memtest.c:42: error: for each function it appears in.)
commands/memtest.c: In function `request_memtest_regions':
commands/memtest.c:57: warning: implicit declaration of function `container_of'
commands/memtest.c:57: error: syntax error before "typeof"
commands/memtest.c:57: error: syntax error before "typeof"
commands/memtest.c:64: warning: implicit declaration of function `PAGE_ALIGN_DOWN'
commands/memtest.c:71: error: continue statement not within a loop
commands/memtest.c: At top level:
commands/memtest.c:79: error: syntax error before "for"
commands/memtest.c:79: error: syntax error before '->' token
commands/memtest.c:79: warning: type defaults to `int' in declaration of `prefetch'
commands/memtest.c:79: warning: function declaration isn't a prototype
commands/memtest.c:79: error: conflicting types for 'prefetch'
include/linux/list.h:18: error: previous definition of 'prefetch' was here
commands/memtest.c:79: warning: type defaults to `int' in declaration of `r'
commands/memtest.c:79: error: invalid type argument of `->'
commands/memtest.c:79: error: syntax error before "typeof"
commands/memtest.c:88: warning: type defaults to `int' in declaration of `end'
commands/memtest.c:88: error: invalid type argument of `->'
commands/memtest.c:88: error: initializer element is not constant
commands/memtest.c:88: warning: data definition has no type or storage class
commands/memtest.c:89: warning: type defaults to `int' in declaration of `size'
commands/memtest.c:89: error: `start' undeclared here (not in a function)
commands/memtest.c:89: warning: data definition has no type or storage class
commands/memtest.c:90: warning: type defaults to `int' in declaration of `r_prev'
commands/memtest.c:90: error: initializer element is not constant
commands/memtest.c:90: warning: data definition has no type or storage class
commands/memtest.c:91: error: syntax error before "if"
commands/memtest.c:94: warning: type defaults to `int' in declaration of `ret'
commands/memtest.c:94: error: `list' undeclared here (not in a function)
commands/memtest.c:94: error: initializer element is not constant
commands/memtest.c:94: warning: data definition has no type or storage class
commands/memtest.c:95: error: syntax error before "if"
commands/memtest.c:102: warning: type defaults to `int' in declaration of `start'
commands/memtest.c:102: warning: implicit declaration of function `PAGE_ALIGN'
commands/memtest.c:102: error: invalid type argument of `->'
commands/memtest.c:102: error: initializer element is not constant
commands/memtest.c:102: warning: data definition has no type or storage class
commands/memtest.c:103: warning: type defaults to `int' in declaration of `end'
commands/memtest.c:103: error: redefinition of 'end'
commands/memtest.c:88: error: previous definition of 'end' was here
commands/memtest.c:103: error: invalid type argument of `->'
commands/memtest.c:103: error: initializer element is not constant
commands/memtest.c:103: warning: data definition has no type or storage class
commands/memtest.c:104: warning: type defaults to `int' in declaration of `size'
commands/memtest.c:104: error: redefinition of 'size'
commands/memtest.c:89: error: previous definition of 'size' was here
commands/memtest.c:104: error: initializer element is not constant
commands/memtest.c:104: warning: data definition has no type or storage class
commands/memtest.c:105: warning: type defaults to `int' in declaration of `r_prev'
commands/memtest.c:105: error: redefinition of 'r_prev'
commands/memtest.c:90: error: previous definition of 'r_prev' was here
commands/memtest.c:105: error: initializer element is not constant
commands/memtest.c:105: warning: data definition has no type or storage class
commands/memtest.c:106: error: syntax error before "if"
commands/memtest.c:109: warning: type defaults to `int' in declaration of `ret'
commands/memtest.c:109: error: redefinition of 'ret'
commands/memtest.c:94: error: previous definition of 'ret' was here
commands/memtest.c:109: error: initializer element is not constant
commands/memtest.c:109: warning: data definition has no type or storage class
commands/memtest.c:110: error: syntax error before "if"
commands/memtest.c:118: warning: type defaults to `int' in declaration of `end'
commands/memtest.c:118: error: redefinition of 'end'
commands/memtest.c:103: error: previous definition of 'end' was here
commands/memtest.c:118: error: redefinition of 'end'
commands/memtest.c:103: error: previous definition of 'end' was here
commands/memtest.c:118: error: `bank' undeclared here (not in a function)
commands/memtest.c:118: error: initializer element is not constant
commands/memtest.c:118: warning: data definition has no type or storage class
commands/memtest.c:119: warning: type defaults to `int' in declaration of `size'
commands/memtest.c:119: error: redefinition of 'size'
commands/memtest.c:104: error: previous definition of 'size' was here
commands/memtest.c:119: error: redefinition of 'size'
commands/memtest.c:104: error: previous definition of 'size' was here
commands/memtest.c:119: error: initializer element is not constant
commands/memtest.c:119: warning: data definition has no type or storage class
commands/memtest.c:120: error: syntax error before "if"
commands/memtest.c:123: warning: type defaults to `int' in declaration of `ret'
commands/memtest.c:123: error: redefinition of 'ret'
commands/memtest.c:109: error: previous definition of 'ret' was here
commands/memtest.c:123: error: redefinition of 'ret'
commands/memtest.c:109: error: previous definition of 'ret' was here
commands/memtest.c:123: error: initializer element is not constant
commands/memtest.c:123: warning: data definition has no type or storage class
commands/memtest.c:124: error: syntax error before "if"
commands/memtest.c: In function `__do_memtest':
commands/memtest.c:139: error: syntax error before "typeof"
commands/memtest.c:139: error: syntax error before "typeof"
commands/memtest.c:149: warning: implicit declaration of function `printf'
commands/memtest.c: At top level:
commands/memtest.c:152: error: syntax error before "return"
commands/memtest.c: In function `do_memtest':
commands/memtest.c:165: warning: implicit declaration of function `simple_strtoul'
commands/memtest.c:214: error: syntax error before "typeof"
commands/memtest.c:214: error: syntax error before "typeof"
commands/memtest.c:221: warning: implicit declaration of function `free'
commands/memtest.c: At top level:
commands/memtest.c:224: error: syntax error before "if"
commands/memtest.c:232: error: syntax error before string constant
commands/memtest.c:232: warning: type defaults to `int' in declaration of `printf'
commands/memtest.c:232: warning: function declaration isn't a prototype
commands/memtest.c:232: warning: data definition has no type or storage class
make[1]: *** [commands/memtest.o] Error 1
make: *** [commands] Error 2


-- 
--?
Best regards,
? Antony Pavlov


From j.weitzel at phytec.de  Thu Jun  6 08:47:16 2013
From: j.weitzel at phytec.de (Jan Weitzel)
Date: Thu, 6 Jun 2013 14:47:16 +0200
Subject: [PATCH v2] omap4: set voltage according to mpu freq
In-Reply-To: <1370425962.3824.1.camel@lws-weitzel>
References: <1370425962.3824.1.camel@lws-weitzel>
Message-ID: <1370522836-11258-1-git-send-email-j.weitzel@phytec.de>

For OMAP4460 omap4_scale_vcores must set the voltage according to mpu freq.

OPP100  700MHz 1210mV
OPPTB   920MHz 1320mV
OPPNT  1200MHz 1380mV

Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
---
v2: split omap4_scale_vcores

 arch/arm/boards/archosg9/lowlevel.c             |    3 +-
 arch/arm/boards/panda/lowlevel.c                |    7 +-
 arch/arm/boards/pcm049/lowlevel.c               |    9 ++-
 arch/arm/boards/phycard-a-xl2/lowlevel.c        |    9 ++-
 arch/arm/mach-omap/include/mach/omap4-silicon.h |    3 +-
 arch/arm/mach-omap/omap4_generic.c              |   96 +++++++++++++----------
 6 files changed, 74 insertions(+), 53 deletions(-)

diff --git a/arch/arm/boards/archosg9/lowlevel.c b/arch/arm/boards/archosg9/lowlevel.c
index 0334693..49c1541 100644
--- a/arch/arm/boards/archosg9/lowlevel.c
+++ b/arch/arm/boards/archosg9/lowlevel.c
@@ -48,8 +48,7 @@ static noinline void archosg9_init_lowlevel(void)
 
 	set_muxconf_regs();
 
-	/* Set VCORE1 = 1.3 V, VCORE2 = VCORE3 = 1.21V */
-	omap4_scale_vcores(TPS62361_VSEL0_GPIO);
+	omap4460_scale_vcores(TPS62361_VSEL0_GPIO, 1380);
 
 	/* Enable all clocks */
 	omap4_enable_all_clocks();
diff --git a/arch/arm/boards/panda/lowlevel.c b/arch/arm/boards/panda/lowlevel.c
index ed1dc6f..5d3490f 100644
--- a/arch/arm/boards/panda/lowlevel.c
+++ b/arch/arm/boards/panda/lowlevel.c
@@ -52,6 +52,7 @@ static void noinline panda_init_lowlevel(void)
 	struct dpll_param per = OMAP4_PER_DPLL_PARAM_38M4;
 	struct dpll_param abe = OMAP4_ABE_DPLL_PARAM_38M4;
 	struct dpll_param usb = OMAP4_USB_DPLL_PARAM_38M4;
+	unsigned int rev = omap4_revision();
 
 	writel(CM_SYS_CLKSEL_38M4, CM_SYS_CLKSEL);
 
@@ -69,8 +70,10 @@ static void noinline panda_init_lowlevel(void)
 
 	omap4_ddr_init(&ddr_regs_400_mhz_2cs, &core);
 
-	/* Set VCORE1 = 1.3 V, VCORE2 = VCORE3 = 1.21V */
-	omap4_scale_vcores(TPS62361_VSEL0_GPIO);
+	if (rev < OMAP4460_ES1_0)
+		omap4430_scale_vcores();
+	else
+		omap4460_scale_vcores(TPS62361_VSEL0_GPIO, 1210);
 }
 
 void barebox_arm_reset_vector(void)
diff --git a/arch/arm/boards/pcm049/lowlevel.c b/arch/arm/boards/pcm049/lowlevel.c
index c855bff..aa6502d 100644
--- a/arch/arm/boards/pcm049/lowlevel.c
+++ b/arch/arm/boards/pcm049/lowlevel.c
@@ -99,6 +99,7 @@ static void noinline pcm049_init_lowlevel(void)
 	struct dpll_param per = OMAP4_PER_DPLL_PARAM_19M2;
 	struct dpll_param abe = OMAP4_ABE_DPLL_PARAM_19M2;
 	struct dpll_param usb = OMAP4_USB_DPLL_PARAM_19M2;
+	unsigned int rev = omap4_revision();
 
 	set_muxconf_regs();
 
@@ -108,13 +109,15 @@ static void noinline pcm049_init_lowlevel(void)
 	omap4_ddr_init(&ddr_regs_mt42L64M64_25_400_mhz, &core);
 #endif
 
-	/* Set VCORE1 = 1.3 V, VCORE2 = VCORE3 = 1.21V */
-	omap4_scale_vcores(TPS62361_VSEL0_GPIO);
+	if (rev < OMAP4460_ES1_0)
+		omap4430_scale_vcores();
+	else
+		omap4460_scale_vcores(TPS62361_VSEL0_GPIO, 1320);
 
 	writel(CM_SYS_CLKSEL_19M2, CM_SYS_CLKSEL);
 
 	/* Configure all DPLL's */
-	if (omap4_revision() < OMAP4460_ES1_0)
+	if (rev < OMAP4460_ES1_0)
 		omap4_configure_mpu_dpll(&mpu44xx);
 	else
 		omap4_configure_mpu_dpll(&mpu4460);
diff --git a/arch/arm/boards/phycard-a-xl2/lowlevel.c b/arch/arm/boards/phycard-a-xl2/lowlevel.c
index 07505ff..86d7c51 100644
--- a/arch/arm/boards/phycard-a-xl2/lowlevel.c
+++ b/arch/arm/boards/phycard-a-xl2/lowlevel.c
@@ -52,18 +52,21 @@ static noinline void pcaaxl2_init_lowlevel(void)
 	struct dpll_param per = OMAP4_PER_DPLL_PARAM_19M2;
 	struct dpll_param abe = OMAP4_ABE_DPLL_PARAM_19M2;
 	struct dpll_param usb = OMAP4_USB_DPLL_PARAM_19M2;
+	unsigned int rev = omap4_revision();
 
 	set_muxconf_regs();
 
 	omap4_ddr_init(&ddr_regs_mt42L64M64_25_400_mhz, &core);
 
-	/* Set VCORE1 = 1.3 V, VCORE2 = VCORE3 = 1.21V */
-	omap4_scale_vcores(TPS62361_VSEL0_GPIO);
+	if (ref < OMAP4460_ES1_0)
+		omap4430_scale_vcores();
+	else
+		omap4460_scale_vcores(TPS62361_VSEL0_GPIO, 1320);
 
 	writel(CM_SYS_CLKSEL_19M2, CM_SYS_CLKSEL);
 
 	/* Configure all DPLL's at 100% OPP */
-	if (omap4_revision() < OMAP4460_ES1_0)
+	if (rev < OMAP4460_ES1_0)
 		omap4_configure_mpu_dpll(&mpu44xx);
 	else
 		omap4_configure_mpu_dpll(&mpu4460);
diff --git a/arch/arm/mach-omap/include/mach/omap4-silicon.h b/arch/arm/mach-omap/include/mach/omap4-silicon.h
index 9e82435..ba48c30 100644
--- a/arch/arm/mach-omap/include/mach/omap4-silicon.h
+++ b/arch/arm/mach-omap/include/mach/omap4-silicon.h
@@ -211,7 +211,8 @@ struct dpll_param;
 void omap4_ddr_init(const struct ddr_regs *, const struct dpll_param *);
 void omap4_power_i2c_send(u32);
 unsigned int omap4_revision(void);
-noinline int omap4_scale_vcores(unsigned vsel0_pin);
+noinline int omap4430_scale_vcores(void);
+noinline int omap4460_scale_vcores(unsigned vsel0_pin, unsigned volt_mv);
 
 #endif
 
diff --git a/arch/arm/mach-omap/omap4_generic.c b/arch/arm/mach-omap/omap4_generic.c
index 3fd3a54..b5e166d 100644
--- a/arch/arm/mach-omap/omap4_generic.c
+++ b/arch/arm/mach-omap/omap4_generic.c
@@ -514,11 +514,9 @@ static void __iomem *omap4_get_gpio_base(unsigned gpio)
 
 #define I2C_SLAVE 0x12
 
-noinline int omap4_scale_vcores(unsigned vsel0_pin)
+noinline int omap4430_scale_vcores(void)
 {
-	void __iomem *base;
 	unsigned int rev = omap4_revision();
-	u32 val = 0;
 
 	/* For VC bypass only VCOREx_CGF_FORCE  is necessary and
 	 * VCOREx_CFG_VOLTAGE  changes can be discarded
@@ -526,50 +524,16 @@ noinline int omap4_scale_vcores(unsigned vsel0_pin)
 	writel(0, OMAP44XX_PRM_VC_CFG_I2C_MODE);
 	writel(0x6026, OMAP44XX_PRM_VC_CFG_I2C_CLK);
 
-	/* TPS - supplies vdd_mpu on 4460 */
-	if (rev >= OMAP4460_ES1_0) {
-		/*
-		 * Setup SET1 and SET0 with right values so that kernel
-		 * can use either of them based on its needs.
-		 */
-		omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, 1430);
-		omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET1, 1430);
-
-		/*
-		 * Select SET1 in TPS62361:
-		 * VSEL1 is grounded on board. So the following selects
-		 * VSEL1 = 0 and VSEL0 = 1
-		 */
-		base = omap4_get_gpio_base(vsel0_pin);
-
-		val = 1 << (vsel0_pin & GPIO_MASK);
-		writel(val, base + 0x190);
-
-		val =  readl(base + 0x134);
-		val &= ~(1 << (vsel0_pin & GPIO_MASK));
-		writel(val, base + 0x134);
-
-		val = 1 << (vsel0_pin & GPIO_MASK);
-		writel(val, base + 0x194);
-	}
-
-	/* set VCORE1 force VSEL */
-	/*
+	/* set VCORE1 force VSEL
 	 * 4430 : supplies vdd_mpu
 	 * Setting a high voltage for Nitro mode as smart reflex is not enabled.
 	 * We use the maximum possible value in the AVS range because the next
 	 * higher voltage in the discrete range (code >= 0b111010) is way too
 	 * high
-	 *
-	 * 4460 : supplies vdd_core
-	 *
 	 */
-	if (rev < OMAP4460_ES1_0)
-		/* 0x55: i2c addr, 3A: ~ 1430 mvolts*/
-		omap4_power_i2c_send((0x3A55 << 8) | I2C_SLAVE);
-	else
-		/* 0x55: i2c addr, 28: ~ 1200 mvolts*/
-		omap4_power_i2c_send((0x2855 << 8) | I2C_SLAVE);
+
+	/* 0x55: i2c addr, 3A: ~ 1430 mvolts*/
+	omap4_power_i2c_send((0x3A55 << 8) | I2C_SLAVE);
 
 	/* FIXME: set VCORE2 force VSEL, Check the reset value */
 	omap4_power_i2c_send((0x295B << 8) | I2C_SLAVE);
@@ -582,12 +546,60 @@ noinline int omap4_scale_vcores(unsigned vsel0_pin)
 	case OMAP4430_ES2_1:
 		omap4_power_i2c_send((0x2A61 << 8) | I2C_SLAVE);
 		break;
-	/* > OMAP4460_ES1_0 : VCORE3 not connected */
 	}
 
 	return 0;
 }
 
+noinline int omap4460_scale_vcores(unsigned vsel0_pin, unsigned volt_mv)
+{
+	void __iomem *base;
+	u32 val = 0;
+
+	/* For VC bypass only VCOREx_CGF_FORCE  is necessary and
+	 * VCOREx_CFG_VOLTAGE  changes can be discarded
+	 */
+	writel(0, OMAP44XX_PRM_VC_CFG_I2C_MODE);
+	writel(0x6026, OMAP44XX_PRM_VC_CFG_I2C_CLK);
+
+	/* TPS - supplies vdd_mpu on 4460
+	 * Setup SET1 and SET0 with right values so that kernel
+	 * can use either of them based on its needs.
+	 */
+
+	omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, volt_mv);
+	omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET1, volt_mv);
+
+	/*
+	 * Select SET1 in TPS62361:
+	 * VSEL1 is grounded on board. So the following selects
+	 * VSEL1 = 0 and VSEL0 = 1
+	 */
+	base = omap4_get_gpio_base(vsel0_pin);
+
+	val = 1 << (vsel0_pin & GPIO_MASK);
+	writel(val, base + 0x190);
+
+	val =  readl(base + 0x134);
+	val &= ~(1 << (vsel0_pin & GPIO_MASK));
+	writel(val, base + 0x134);
+
+	val = 1 << (vsel0_pin & GPIO_MASK);
+	writel(val, base + 0x194);
+
+	/* set VCORE1 force VSEL
+	 * 4460 : supplies vdd_core
+	 */
+
+	/* 0x55: i2c addr, 28: ~ 1200 mvolts*/
+	omap4_power_i2c_send((0x2855 << 8) | I2C_SLAVE);
+
+	/* FIXME: set VCORE2 force VSEL, Check the reset value */
+	omap4_power_i2c_send((0x295B << 8) | I2C_SLAVE);
+
+	return 0;
+}
+
 void omap4_do_set_mux(u32 base, struct pad_conf_entry const *array, int size)
 {
 	int i;
-- 
1.7.0.4



From menon.nishanth at gmail.com  Thu Jun  6 09:40:46 2013
From: menon.nishanth at gmail.com (menon.nishanth at gmail.com)
Date: Thu, 6 Jun 2013 08:40:46 -0500
Subject: [PATCH v2] omap4: set voltage according to mpu freq
In-Reply-To: <1370522836-11258-1-git-send-email-j.weitzel@phytec.de>
References: <1370425962.3824.1.camel@lws-weitzel>
 <1370522836-11258-1-git-send-email-j.weitzel@phytec.de>
Message-ID: <CAGo_u6rixBCzggcuLAfOLuxgTrzyDhY7ipf2garfTiDb_Ce0WA@mail.gmail.com>

On Thu, Jun 6, 2013 at 7:47 AM, Jan Weitzel <j.weitzel at phytec.de> wrote:
> +noinline int omap4460_scale_vcores(unsigned vsel0_pin, unsigned volt_mv)
> +{
> +       void __iomem *base;
> +       u32 val = 0;
> +
> +       /* For VC bypass only VCOREx_CGF_FORCE  is necessary and
> +        * VCOREx_CFG_VOLTAGE  changes can be discarded
> +        */
> +       writel(0, OMAP44XX_PRM_VC_CFG_I2C_MODE);
> +       writel(0x6026, OMAP44XX_PRM_VC_CFG_I2C_CLK);
> +
> +       /* TPS - supplies vdd_mpu on 4460
> +        * Setup SET1 and SET0 with right values so that kernel
> +        * can use either of them based on its needs.
> +        */
> +
> +       omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, volt_mv);
Just a nitpick - the general rule of TPS+OMAP4460 integration is *NOT*
to program SET0 register. this is intended to be at boot voltage
required to be used when reboot due to s/w controlled or h/w watchdog.
> +       omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET1, volt_mv);
> +
Regards,
Nishanth Menon


From s.hauer at pengutronix.de  Thu Jun  6 10:20:09 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:20:09 +0200
Subject: [PATCH] mfd: stmpe: Add devicetree probe support
Message-ID: <1370528409-3439-1-git-send-email-s.hauer@pengutronix.de>

Our driver matches stmpe-i2c and stmpe-spi. It seems the device
we really support is the stmpe1601, so use this one for matching
the devicetree compatible.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mfd/stmpe-i2c.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
index d87620e..d785430 100644
--- a/drivers/mfd/stmpe-i2c.c
+++ b/drivers/mfd/stmpe-i2c.c
@@ -106,6 +106,25 @@ static struct file_operations stmpe_fops = {
 	.write	= stmpe_write,
 };
 
+static struct stmpe_platform_data *stmpe_of_probe(struct device_d *dev)
+{
+	struct stmpe_platform_data *pdata;
+	struct device_node *node;
+
+	if (!IS_ENABLED(CONFIG_OFDEVICE) || !dev->device_node)
+		return NULL;
+
+	pdata = xzalloc(sizeof(*pdata));
+
+	device_node_for_nach_child(dev->device_node, node) {
+		if (!strcmp(node->name, "stmpe_gpio")) {
+			pdata->blocks |= STMPE_BLOCK_GPIO;
+		}
+	}
+
+	return pdata;
+}
+
 static int stmpe_probe(struct device_d *dev)
 {
 	struct stmpe_platform_data *pdata = dev->platform_data;
@@ -113,8 +132,11 @@ static int stmpe_probe(struct device_d *dev)
 	struct stmpe_client_info *i2c_ci;
 
 	if (!pdata) {
-		dev_dbg(dev, "no platform data\n");
-		return -ENODEV;
+		pdata = stmpe_of_probe(dev);
+		if (!pdata) {
+			dev_dbg(dev, "no platform data\n");
+			return -ENODEV;
+		}
 	}
 
 	stmpe_dev = xzalloc(sizeof(struct stmpe));
@@ -140,9 +162,15 @@ static int stmpe_probe(struct device_d *dev)
 	return 0;
 }
 
+static struct platform_device_id stmpe_i2c_id[] = {
+	{ "stmpe1601", 0 },
+	{ }
+};
+
 static struct driver_d stmpe_driver = {
 	.name  = DRIVERNAME,
 	.probe = stmpe_probe,
+	.id_table = stmpe_i2c_id,
 };
 
 static int stmpe_init(void)
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Thu Jun  6 10:20:20 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:20:20 +0200
Subject: [PATCH] mtd: Align erase_op to eraseblock boundaries
Message-ID: <1370528420-4388-1-git-send-email-s.hauer@pengutronix.de>

Our erase command used to align to eraseblocks when necessary.
This worked well until recently when the m25p80, mtd_dataflash
and cfi flash were added / converted to mtd. This patch aligns
the input to the erase fileoperation to eraseblock boundaries.
Also tested with non uniform flashes with multiple eraseregions.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mtd/core.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index f358098..fe9ec1d 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -98,12 +98,60 @@ static ssize_t mtd_op_write(struct cdev* cdev, const void *buf, size_t _count,
 	return ret ? ret : _count;
 }
 
+static struct mtd_erase_region_info *mtd_find_erase_region(struct mtd_info *mtd, loff_t offset)
+{
+	int i;
+
+	for (i = 0; i < mtd->numeraseregions; i++) {
+		struct mtd_erase_region_info *e = &mtd->eraseregions[i];
+		if (offset > e->offset + e->erasesize * e->numblocks)
+			continue;
+		return e;
+	}
+
+	return NULL;
+}
+
+static int mtd_erase_align(struct mtd_info *mtd, size_t *count, loff_t *offset)
+{
+	struct mtd_erase_region_info *e;
+	loff_t ofs;
+
+	if (mtd->numeraseregions == 0) {
+		ofs = *offset & ~(mtd->erasesize - 1);
+		*count += (*offset - ofs);
+		*count = ALIGN(*count, mtd->erasesize);
+		*offset = ofs;
+		return 0;
+	}
+
+	e = mtd_find_erase_region(mtd, *offset);
+	if (!e)
+		return -EINVAL;
+
+	ofs = *offset & ~(e->erasesize - 1);
+	*count += (*offset - ofs);
+
+	e = mtd_find_erase_region(mtd, *offset + *count);
+	if (!e)
+		return -EINVAL;
+
+	*count = ALIGN(*count, e->erasesize);
+	*offset = ofs;
+
+	return 0;
+}
+
 static int mtd_op_erase(struct cdev *cdev, size_t count, loff_t offset)
 {
 	struct mtd_info *mtd = cdev->priv;
 	struct erase_info erase;
 	int ret;
 
+	ret = mtd_erase_align(mtd, &count, &offset);
+	if (ret)
+		return ret;
+
 	memset(&erase, 0, sizeof(erase));
 	erase.mtd = mtd;
 	erase.addr = offset;
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Thu Jun  6 10:22:38 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:22:38 +0200
Subject: [PATCH 5/6] ata: i.MX sata: Add devicetree probe support
In-Reply-To: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
References: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370528559-15694-5-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/sata-imx.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/ata/sata-imx.c b/drivers/ata/sata-imx.c
index 13bf116..ef7989e 100644
--- a/drivers/ata/sata-imx.c
+++ b/drivers/ata/sata-imx.c
@@ -141,9 +141,22 @@ static struct platform_device_id imx_sata_ids[] = {
 	},
 };
 
+static __maybe_unused struct of_device_id imx_sata_dt_ids[] = {
+	{
+		.compatible = "fsl,imx6q-ahci",
+		.data = (unsigned long)&data_imx6,
+	}, {
+		.compatible = "fsl,imx53-ahci",
+		.data = (unsigned long)&data_imx53,
+	}, {
+		/* sentinel */
+	}
+};
+
 static struct driver_d imx_sata_driver = {
 	.name   = "imx-sata",
 	.probe  = imx_sata_probe,
 	.id_table = imx_sata_ids,
+	.of_compatible = DRV_OF_COMPAT(imx_sata_dt_ids),
 };
 device_platform_driver(imx_sata_driver);
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Thu Jun  6 10:22:35 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:22:35 +0200
Subject: [PATCH 2/6] ata: ahci: only use lba48 on drives which support it
In-Reply-To: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
References: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370528559-15694-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/ahci.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 7def9a0..19d445a 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -224,13 +224,19 @@ static int ahci_rw(struct ata_port *ata, void *rbuf, const void *wbuf,
 	struct ahci_port *ahci = container_of(ata, struct ahci_port, ata);
 	u8 fis[20];
 	int ret;
+	int lba48 = ata_id_has_lba48(ata->id);
 
 	memset(fis, 0, sizeof(fis));
 
 	/* Construct the FIS */
 	fis[0] = 0x27;			/* Host to device FIS. */
 	fis[1] = 1 << 7;		/* Command FIS. */
-	fis[2] = wbuf ? ATA_CMD_WRITE_EXT : ATA_CMD_READ_EXT;	/* Command byte. */
+
+	/* Command byte. */
+	if (lba48)
+		fis[2] = wbuf ? ATA_CMD_WRITE_EXT : ATA_CMD_READ_EXT;
+	else
+		fis[2] = wbuf ? ATA_CMD_WRITE : ATA_CMD_READ;
 
 	while (num_blocks) {
 		int now;
@@ -240,9 +246,14 @@ static int ahci_rw(struct ata_port *ata, void *rbuf, const void *wbuf,
 		fis[4] = (block >> 0) & 0xff;
 		fis[5] = (block >> 8) & 0xff;
 		fis[6] = (block >> 16) & 0xff;
-		fis[7] = 1 << 6; /* device reg: set LBA mode */
-		fis[8] = ((block >> 24) & 0xff);
-		fis[3] = 0xe0; /* features */
+
+		if (lba48) {
+			fis[7] = 1 << 6; /* device reg: set LBA mode */
+			fis[8] = ((block >> 24) & 0xff);
+			fis[3] = 0xe0; /* features */
+		} else {
+			fis[7] = ((block >> 24) & 0xf) | 0xe0;
+		}
 
 		/* Block (sector) count */
 		fis[12] = (now >> 0) & 0xff;
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Thu Jun  6 10:22:37 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:22:37 +0200
Subject: [PATCH 4/6] ata: ahci: Allow 'detect' on hardware device
In-Reply-To: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
References: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370528559-15694-4-git-send-email-s.hauer@pengutronix.de>

Hook the detect callback to the hardware device.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/ahci.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 19d445a..f9cf2d1 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -569,6 +569,20 @@ void ahci_info(struct device_d *dev)
 	ahci_print_info(ahci);
 }
 
+static int ahci_detect(struct device_d *dev)
+{
+	struct ahci_device *ahci = dev->priv;
+	int i;
+
+	for (i = 0; i < ahci->n_ports; i++) {
+		struct ahci_port *ahci_port = &ahci->ports[i];
+
+		ata_port_detect(&ahci_port->ata);
+	}
+
+	return 0;
+}
+
 int ahci_add_host(struct ahci_device *ahci)
 {
 	u8 *mmio = (u8 *)ahci->mmio_base;
@@ -630,6 +644,8 @@ int ahci_add_host(struct ahci_device *ahci)
 	ahci_iowrite(ahci, HOST_CTL, tmp | HOST_IRQ_EN);
 	tmp = ahci_ioread(ahci, HOST_CTL);
 
+	ahci->dev->detect = ahci_detect;
+
 	return 0;
 }
 
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Thu Jun  6 10:22:34 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:22:34 +0200
Subject: [PATCH 1/6] ata: move ATA_ID_ fields and functions to include/
Message-ID: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>

We need ata_id_has_lba48() in another C file, so move
the ATA_ID_* stuff to include/ata_drive.h like in the Linux
Kernel.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/disk_ata_drive.c | 44 --------------------------------------------
 include/ata_drive.h          | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 2cff584..034233d 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -26,41 +26,6 @@
 #include <disks.h>
 #include <dma.h>
 
-#define ata_id_u32(id,n)        \
-        (((uint32_t) (id)[(n) + 1] << 16) | ((uint32_t) (id)[(n)]))
-#define ata_id_u64(id,n)        \
-        ( ((uint64_t) (id)[(n) + 3] << 48) | \
-          ((uint64_t) (id)[(n) + 2] << 32) | \
-          ((uint64_t) (id)[(n) + 1] << 16) | \
-          ((uint64_t) (id)[(n) + 0]) )
-
-#define ata_id_has_lba(id)               ((id)[49] & (1 << 9))
-
-enum {
-	ATA_ID_SERNO		= 10,
-#define ATA_ID_SERNO_LEN 20
-	ATA_ID_FW_REV		= 23,
-#define ATA_ID_FW_REV_LEN 8
-	ATA_ID_PROD		= 27,
-#define ATA_ID_PROD_LEN 40
-	ATA_ID_CAPABILITY	= 49,
-	ATA_ID_FIELD_VALID	= 53,
-	ATA_ID_LBA_CAPACITY	= 60,
-	ATA_ID_MWDMA_MODES	= 63,
-	ATA_ID_PIO_MODES	= 64,
-	ATA_ID_QUEUE_DEPTH	= 75,
-	ATA_ID_MAJOR_VER	= 80,
-	ATA_ID_COMMAND_SET_1	= 82,
-	ATA_ID_COMMAND_SET_2	= 83,
-	ATA_ID_CFSSE		= 84,
-	ATA_ID_CFS_ENABLE_1	= 85,
-	ATA_ID_CFS_ENABLE_2	= 86,
-	ATA_ID_CSF_DEFAULT	= 87,
-	ATA_ID_UDMA_MODES	= 88,
-	ATA_ID_HW_CONFIG	= 93,
-	ATA_ID_LBA_CAPACITY_2	= 100,
-};
-
 static int ata_id_is_valid(const uint16_t *id)
 {
 	if ((id[ATA_ID_FIELD_VALID] & 1) == 0) {
@@ -71,15 +36,6 @@ static int ata_id_is_valid(const uint16_t *id)
 	return 0;
 }
 
-static inline int ata_id_has_lba48(const uint16_t *id)
-{
-	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
-		return 0;
-	if (!ata_id_u64(id, ATA_ID_LBA_CAPACITY_2))
-		return 0;
-	return id[ATA_ID_COMMAND_SET_2] & (1 << 10);
-}
-
 static uint64_t ata_id_n_sectors(uint16_t *id)
 {
 	if (ata_id_has_lba(id)) {
diff --git a/include/ata_drive.h b/include/ata_drive.h
index 049082f..abbafb9 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -55,6 +55,50 @@
 #define ATA_DEVCTL_SOFT_RESET	(1 << 2)
 #define ATA_DEVCTL_INTR_DISABLE	(1 << 1)
 
+#define ata_id_u32(id,n)        \
+        (((uint32_t) (id)[(n) + 1] << 16) | ((uint32_t) (id)[(n)]))
+#define ata_id_u64(id,n)        \
+        ( ((uint64_t) (id)[(n) + 3] << 48) | \
+          ((uint64_t) (id)[(n) + 2] << 32) | \
+          ((uint64_t) (id)[(n) + 1] << 16) | \
+          ((uint64_t) (id)[(n) + 0]) )
+
+#define ata_id_has_lba(id)               ((id)[49] & (1 << 9))
+
+enum {
+	ATA_ID_SERNO		= 10,
+#define ATA_ID_SERNO_LEN 20
+	ATA_ID_FW_REV		= 23,
+#define ATA_ID_FW_REV_LEN 8
+	ATA_ID_PROD		= 27,
+#define ATA_ID_PROD_LEN 40
+	ATA_ID_CAPABILITY	= 49,
+	ATA_ID_FIELD_VALID	= 53,
+	ATA_ID_LBA_CAPACITY	= 60,
+	ATA_ID_MWDMA_MODES	= 63,
+	ATA_ID_PIO_MODES	= 64,
+	ATA_ID_QUEUE_DEPTH	= 75,
+	ATA_ID_MAJOR_VER	= 80,
+	ATA_ID_COMMAND_SET_1	= 82,
+	ATA_ID_COMMAND_SET_2	= 83,
+	ATA_ID_CFSSE		= 84,
+	ATA_ID_CFS_ENABLE_1	= 85,
+	ATA_ID_CFS_ENABLE_2	= 86,
+	ATA_ID_CSF_DEFAULT	= 87,
+	ATA_ID_UDMA_MODES	= 88,
+	ATA_ID_HW_CONFIG	= 93,
+	ATA_ID_LBA_CAPACITY_2	= 100,
+};
+
+static inline int ata_id_has_lba48(const uint16_t *id)
+{
+	if ((id[ATA_ID_COMMAND_SET_2] & 0xC000) != 0x4000)
+		return 0;
+	if (!ata_id_u64(id, ATA_ID_LBA_CAPACITY_2))
+		return 0;
+	return id[ATA_ID_COMMAND_SET_2] & (1 << 10);
+}
+
 /** addresses of each individual IDE drive register */
 struct ata_ioports {
 	void __iomem *cmd_addr;
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Thu Jun  6 10:22:36 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:22:36 +0200
Subject: [PATCH 3/6] ata: implement detect
In-Reply-To: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
References: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370528559-15694-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/disk_ata_drive.c | 24 +++++++++++++++++++-----
 include/ata_drive.h          |  1 +
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 034233d..7669539 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -281,14 +281,10 @@ on_error:
 	return rc;
 }
 
-static int ata_set_probe(struct param_d *param, void *priv)
+int ata_port_detect(struct ata_port *port)
 {
-	struct ata_port *port = priv;
 	int ret;
 
-	if (!port->probe)
-		return 0;
-
 	if (port->initialized) {
 		dev_info(&port->class_dev, "already initialized\n");
 		return 0;
@@ -303,6 +299,23 @@ static int ata_set_probe(struct param_d *param, void *priv)
 	return 0;
 }
 
+static int ata_set_probe(struct param_d *param, void *priv)
+{
+	struct ata_port *port = priv;
+
+	if (!port->probe)
+		return 0;
+
+	return ata_port_detect(port);
+}
+
+static int ata_detect(struct device_d *dev)
+{
+	struct ata_port *port = container_of(dev, struct ata_port, class_dev);
+
+	return ata_port_detect(port);
+}
+
 /**
  * Register an ATA drive behind an IDE like interface
  * @param dev The interface device
@@ -316,6 +329,7 @@ int ata_port_register(struct ata_port *port)
 	port->class_dev.id = DEVICE_ID_DYNAMIC;
 	strcpy(port->class_dev.name, "ata");
 	port->class_dev.parent = port->dev;
+	port->class_dev.detect = ata_detect;
 
 	ret = register_device(&port->class_dev);
 	if (ret)
diff --git a/include/ata_drive.h b/include/ata_drive.h
index abbafb9..9961aea 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -144,6 +144,7 @@ struct ata_port {
 
 int ide_port_register(struct device_d *, struct ata_ioports *);
 int ata_port_register(struct ata_port *port);
+int ata_port_detect(struct ata_port *port);
 
 struct device_d;
 
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Thu Jun  6 10:22:39 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:22:39 +0200
Subject: [PATCH 6/6] ARM: i.MX6: Add sata device to devicetree
In-Reply-To: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
References: <1370528559-15694-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370528559-15694-6-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/dts/imx6qdl.dtsi | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/dts/imx6qdl.dtsi b/arch/arm/dts/imx6qdl.dtsi
index b636002..86084be 100644
--- a/arch/arm/dts/imx6qdl.dtsi
+++ b/arch/arm/dts/imx6qdl.dtsi
@@ -827,6 +827,16 @@
 			};
 		};
 
+		sata: sata at 02200000 {
+			compatible = "fsl,imx6q-ahci";
+			reg = <0x02200000 0x4000>;
+			interrupts = <0 39 0x04>;
+			clocks = <&clks 154 &clks 105 &clks 187>;
+			clock-names = "ipg", "ahb", "per";
+			gprreg = <&gpr>;
+			status = "disabled";
+		};
+
 		ipu1: ipu at 02400000 {
 			#crtc-cells = <1>;
 			compatible = "fsl,imx6q-ipu";
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Thu Jun  6 10:22:53 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:22:53 +0200
Subject: [PATCH 1/2] ARM: i.MX6 RealQ7: switch to imximage
Message-ID: <1370528574-27107-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/dmo-mx6-realq7/Makefile            |  4 +--
 arch/arm/boards/dmo-mx6-realq7/flash-header.imxcfg |  3 ++
 arch/arm/boards/dmo-mx6-realq7/flash_header.c      | 40 ----------------------
 arch/arm/mach-imx/Kconfig                          |  1 +
 4 files changed, 6 insertions(+), 42 deletions(-)
 create mode 100644 arch/arm/boards/dmo-mx6-realq7/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/dmo-mx6-realq7/flash_header.c

diff --git a/arch/arm/boards/dmo-mx6-realq7/Makefile b/arch/arm/boards/dmo-mx6-realq7/Makefile
index e143009..bb6d9d8 100644
--- a/arch/arm/boards/dmo-mx6-realq7/Makefile
+++ b/arch/arm/boards/dmo-mx6-realq7/Makefile
@@ -1,2 +1,2 @@
-obj-y += board.o flash_header.o lowlevel.o
-pbl-y += flash_header.o lowlevel.o
+obj-y += board.o lowlevel.o
+pbl-y += lowlevel.o
diff --git a/arch/arm/boards/dmo-mx6-realq7/flash-header.imxcfg b/arch/arm/boards/dmo-mx6-realq7/flash-header.imxcfg
new file mode 100644
index 0000000..400a870
--- /dev/null
+++ b/arch/arm/boards/dmo-mx6-realq7/flash-header.imxcfg
@@ -0,0 +1,3 @@
+soc imx6
+loadaddr 0x00907000
+dcdofs 0x400
diff --git a/arch/arm/boards/dmo-mx6-realq7/flash_header.c b/arch/arm/boards/dmo-mx6-realq7/flash_header.c
deleted file mode 100644
index 88227a7..0000000
--- a/arch/arm/boards/dmo-mx6-realq7/flash_header.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2011 Marc Kleine-Budde <mkl at pengutronix.de>
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <asm/byteorder.h>
-#include <mach/imx-flash-header.h>
-#include <mach/imx6-regs.h>
-#include <asm/barebox-arm-head.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-#define APP_DEST	0x00907000
-
-struct imx_flash_header_v2 __flash_header_section flash_header = {
-	.header.tag		= IVT_HEADER_TAG,
-	.header.length		= cpu_to_be16(32),
-	.header.version		= IVT_VERSION,
-	.entry			= APP_DEST + 0x2000,
-	.dcd_ptr		= 0,
-	.boot_data_ptr		= APP_DEST + FLASH_HEADER_OFFSET + offsetof(struct imx_flash_header_v2, boot_data),
-	.self			= APP_DEST + FLASH_HEADER_OFFSET,
-
-	.boot_data.start	= APP_DEST,
-	.boot_data.size		= barebox_image_size,
-};
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index a66395c..e500c45 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -533,6 +533,7 @@ config MACH_SABRESD
 
 config MACH_REALQ7
 	bool "DataModul i.MX6Q Real Qseven Board"
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 
 endchoice
-- 
1.8.2.rc2



From s.hauer at pengutronix.de  Thu Jun  6 10:22:54 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu,  6 Jun 2013 16:22:54 +0200
Subject: [PATCH 2/2] ARM: i.MX6 DMO RealQ7: Switch to devicetree
In-Reply-To: <1370528574-27107-1-git-send-email-s.hauer@pengutronix.de>
References: <1370528574-27107-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1370528574-27107-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/dmo-mx6-realq7/board.c | 314 +++--------------------------
 arch/arm/configs/dmo-realq7_defconfig  |   6 +-
 arch/arm/dts/Makefile                  |   3 +-
 arch/arm/dts/imx6q-dmo-realq7.dts      | 354 +++++++++++++++++++++++++++++++++
 4 files changed, 388 insertions(+), 289 deletions(-)
 create mode 100644 arch/arm/dts/imx6q-dmo-realq7.dts

diff --git a/arch/arm/boards/dmo-mx6-realq7/board.c b/arch/arm/boards/dmo-mx6-realq7/board.c
index 35ef72c..b2a27a4 100644
--- a/arch/arm/boards/dmo-mx6-realq7/board.c
+++ b/arch/arm/boards/dmo-mx6-realq7/board.c
@@ -17,206 +17,30 @@
  *
  */
 
-#include <common.h>
-#include <init.h>
-#include <environment.h>
-#include <mach/imx6-regs.h>
-#include <asm/armlinux.h>
-#include <fec.h>
 #include <generated/mach-types.h>
+#include <environment.h>
+#include <bootsource.h>
 #include <partition.h>
-#include <spi/spi.h>
+#include <common.h>
+#include <envfs.h>
 #include <sizes.h>
+#include <init.h>
 #include <gpio.h>
-#include <mci.h>
-#include <bootsource.h>
-#include <mfd/stmpe-i2c.h>
+#include <fec.h>
+
 #include <linux/micrel_phy.h>
+#include <mfd/stmpe-i2c.h>
 
+#include <asm/armlinux.h>
 #include <asm/io.h>
-#include <asm/mmu.h>
 
 #include <mach/devices-imx6.h>
+#include <mach/imx6-regs.h>
 #include <mach/iomux-mx6.h>
 #include <mach/imx6-mmdc.h>
-#include <mach/imx6-regs.h>
 #include <mach/generic.h>
 #include <mach/imx6.h>
 #include <mach/bbu.h>
-#include <mach/spi.h>
-
-static iomux_v3_cfg_t realq7_pads[] = {
-	MX6Q_PAD_SD2_CMD__AUDMUX_AUD4_RXC,
-	MX6Q_PAD_SD2_DAT0__AUDMUX_AUD4_RXD,
-	MX6Q_PAD_SD2_CLK__AUDMUX_AUD4_RXFS,
-	MX6Q_PAD_SD2_DAT2__AUDMUX_AUD4_TXD,
-	MX6Q_PAD_SD2_DAT1__AUDMUX_AUD4_TXFS,
-	MX6Q_PAD_KEY_ROW2__CAN1_RXCAN,
-	MX6Q_PAD_GPIO_7__CAN1_TXCAN,
-	MX6Q_PAD_CSI0_VSYNC__CHEETAH_TRACE_0,
-	MX6Q_PAD_CSI0_DAT4__CHEETAH_TRACE_1,
-	MX6Q_PAD_CSI0_DAT13__CHEETAH_TRACE_10,
-	MX6Q_PAD_CSI0_DAT14__CHEETAH_TRACE_11,
-	MX6Q_PAD_CSI0_DAT15__CHEETAH_TRACE_12,
-	MX6Q_PAD_CSI0_DAT16__CHEETAH_TRACE_13,
-	MX6Q_PAD_CSI0_DAT17__CHEETAH_TRACE_14,
-	MX6Q_PAD_CSI0_DAT18__CHEETAH_TRACE_15,
-	MX6Q_PAD_CSI0_DAT5__CHEETAH_TRACE_2,
-	MX6Q_PAD_CSI0_DAT6__CHEETAH_TRACE_3,
-	MX6Q_PAD_CSI0_DAT7__CHEETAH_TRACE_4,
-	MX6Q_PAD_CSI0_DAT8__CHEETAH_TRACE_5,
-	MX6Q_PAD_CSI0_DAT9__CHEETAH_TRACE_6,
-	MX6Q_PAD_CSI0_DAT10__CHEETAH_TRACE_7,
-	MX6Q_PAD_CSI0_DAT11__CHEETAH_TRACE_8,
-	MX6Q_PAD_CSI0_DAT12__CHEETAH_TRACE_9,
-	MX6Q_PAD_CSI0_DATA_EN__CHEETAH_TRCLK,
-	MX6Q_PAD_CSI0_MCLK__CHEETAH_TRCTL,
-	MX6Q_PAD_EIM_OE__ECSPI2_MISO,
-	MX6Q_PAD_EIM_CS1__ECSPI2_MOSI,
-	MX6Q_PAD_EIM_CS0__ECSPI2_SCLK,
-	MX6Q_PAD_EIM_D24__ECSPI2_SS2,
-	MX6Q_PAD_EIM_D25__ECSPI2_SS3,
-	MX6Q_PAD_SD1_DAT0__ECSPI5_MISO,
-	MX6Q_PAD_SD1_CMD__ECSPI5_MOSI,
-	MX6Q_PAD_SD1_CLK__ECSPI5_SCLK,
-	MX6Q_PAD_SD2_DAT3__GPIO_1_12,
-	MX6Q_PAD_ENET_MDC__ENET_MDC,
-	MX6Q_PAD_ENET_MDIO__ENET_MDIO,
-	/* IOMUXC_SW_PAD_CTL_GRP_DDR_TYPE_RGMII = 0x80000, done in flash_header.c */
-	MX6Q_PAD_RGMII_TD0__ENET_RGMII_TD0,
-	MX6Q_PAD_RGMII_TD1__ENET_RGMII_TD1,
-	MX6Q_PAD_RGMII_TD2__ENET_RGMII_TD2,
-	MX6Q_PAD_RGMII_TD3__ENET_RGMII_TD3,
-	MX6Q_PAD_RGMII_TX_CTL__ENET_RGMII_TX_CTL,
-	MX6Q_PAD_RGMII_TXC__ENET_RGMII_TXC,
-	MX6Q_PAD_ENET_REF_CLK__ENET_TX_CLK,
-	MX6Q_PAD_GPIO_0__GPIO_1_0,
-	MX6Q_PAD_GPIO_2__GPIO_1_2,
-	MX6Q_PAD_ENET_CRS_DV__GPIO_1_25,
-	MX6Q_PAD_ENET_RXD0__GPIO_1_27,
-	MX6Q_PAD_ENET_TX_EN__GPIO_1_28,
-	MX6Q_PAD_GPIO_3__GPIO_1_3,
-	MX6Q_PAD_GPIO_4__GPIO_1_4,
-	MX6Q_PAD_GPIO_5__GPIO_1_5,
-	MX6Q_PAD_GPIO_8__GPIO_1_8,
-	MX6Q_PAD_GPIO_9__GPIO_1_9,
-	MX6Q_PAD_NANDF_D0__GPIO_2_0,
-	MX6Q_PAD_NANDF_D1__GPIO_2_1,
-	MX6Q_PAD_NANDF_D2__GPIO_2_2,
-	MX6Q_PAD_EIM_A17__GPIO_2_21,
-	MX6Q_PAD_EIM_A16__GPIO_2_22,
-	MX6Q_PAD_EIM_LBA__GPIO_2_27,
-	MX6Q_PAD_NANDF_D3__GPIO_2_3,
-	MX6Q_PAD_NANDF_D4__GPIO_2_4,
-	MX6Q_PAD_NANDF_D5__GPIO_2_5,
-	MX6Q_PAD_NANDF_D6__GPIO_2_6,
-	MX6Q_PAD_NANDF_D7__GPIO_2_7,
-	MX6Q_PAD_EIM_DA10__GPIO_3_10,
-	MX6Q_PAD_EIM_DA11__GPIO_3_11,
-	MX6Q_PAD_EIM_DA12__GPIO_3_12,
-	MX6Q_PAD_EIM_DA13__GPIO_3_13,
-	MX6Q_PAD_EIM_DA14__GPIO_3_14,
-	MX6Q_PAD_EIM_DA15__GPIO_3_15,
-	MX6Q_PAD_EIM_D16__GPIO_3_16,
-	MX6Q_PAD_EIM_D18__GPIO_3_18,
-	MX6Q_PAD_EIM_D19__GPIO_3_19,
-	MX6Q_PAD_EIM_D20__GPIO_3_20,
-	MX6Q_PAD_EIM_D23__GPIO_3_23,
-	MX6Q_PAD_EIM_D29__GPIO_3_29,
-	MX6Q_PAD_EIM_D30__GPIO_3_30,
-	MX6Q_PAD_EIM_DA8__GPIO_3_8,
-	MX6Q_PAD_EIM_DA9__GPIO_3_9,
-	MX6Q_PAD_KEY_COL2__GPIO_4_10,
-	MX6Q_PAD_KEY_COL4__GPIO_4_14,
-	MX6Q_PAD_KEY_ROW4__GPIO_4_15,
-	MX6Q_PAD_GPIO_19__GPIO_4_5,
-	MX6Q_PAD_KEY_COL0__GPIO_4_6,
-	MX6Q_PAD_KEY_ROW0__GPIO_4_7,
-	MX6Q_PAD_KEY_COL1__GPIO_4_8,
-	MX6Q_PAD_KEY_ROW1__GPIO_4_9,
-	MX6Q_PAD_EIM_WAIT__GPIO_5_0,
-	MX6Q_PAD_EIM_A25__GPIO_5_2,
-	MX6Q_PAD_EIM_A24__GPIO_5_4,
-	MX6Q_PAD_EIM_BCLK__GPIO_6_31,
-	MX6Q_PAD_SD3_DAT5__GPIO_7_0,
-	MX6Q_PAD_SD3_DAT4__GPIO_7_1,
-	MX6Q_PAD_GPIO_17__GPIO_7_12,
-	MX6Q_PAD_GPIO_18__GPIO_7_13,
-	MX6Q_PAD_SD3_RST__GPIO_7_8,
-	MX6Q_PAD_EIM_D21__I2C1_SCL,
-	MX6Q_PAD_EIM_D28__I2C1_SDA,
-	MX6Q_PAD_EIM_EB2__I2C2_SCL,
-	MX6Q_PAD_KEY_ROW3__I2C2_SDA,
-	MX6Q_PAD_EIM_D17__I2C3_SCL,
-	MX6Q_PAD_GPIO_6__I2C3_SDA,
-	MX6Q_PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK,
-	MX6Q_PAD_DI0_PIN15__IPU1_DI0_PIN15,
-	MX6Q_PAD_DI0_PIN2__IPU1_DI0_PIN2,
-	MX6Q_PAD_DI0_PIN3__IPU1_DI0_PIN3,
-	MX6Q_PAD_DI0_PIN4__IPU1_DI0_PIN4,
-	MX6Q_PAD_DISP0_DAT0__IPU1_DISP0_DAT_0,
-	MX6Q_PAD_DISP0_DAT1__IPU1_DISP0_DAT_1,
-	MX6Q_PAD_DISP0_DAT10__IPU1_DISP0_DAT_10,
-	MX6Q_PAD_DISP0_DAT11__IPU1_DISP0_DAT_11,
-	MX6Q_PAD_DISP0_DAT12__IPU1_DISP0_DAT_12,
-	MX6Q_PAD_DISP0_DAT13__IPU1_DISP0_DAT_13,
-	MX6Q_PAD_DISP0_DAT14__IPU1_DISP0_DAT_14,
-	MX6Q_PAD_DISP0_DAT15__IPU1_DISP0_DAT_15,
-	MX6Q_PAD_DISP0_DAT16__IPU1_DISP0_DAT_16,
-	MX6Q_PAD_DISP0_DAT17__IPU1_DISP0_DAT_17,
-	MX6Q_PAD_DISP0_DAT18__IPU1_DISP0_DAT_18,
-	MX6Q_PAD_DISP0_DAT19__IPU1_DISP0_DAT_19,
-	MX6Q_PAD_DISP0_DAT2__IPU1_DISP0_DAT_2,
-	MX6Q_PAD_DISP0_DAT20__IPU1_DISP0_DAT_20,
-	MX6Q_PAD_DISP0_DAT21__IPU1_DISP0_DAT_21,
-	MX6Q_PAD_DISP0_DAT22__IPU1_DISP0_DAT_22,
-	MX6Q_PAD_DISP0_DAT23__IPU1_DISP0_DAT_23,
-	MX6Q_PAD_DISP0_DAT3__IPU1_DISP0_DAT_3,
-	MX6Q_PAD_DISP0_DAT4__IPU1_DISP0_DAT_4,
-	MX6Q_PAD_DISP0_DAT5__IPU1_DISP0_DAT_5,
-	MX6Q_PAD_DISP0_DAT6__IPU1_DISP0_DAT_6,
-	MX6Q_PAD_DISP0_DAT7__IPU1_DISP0_DAT_7,
-	MX6Q_PAD_DISP0_DAT8__IPU1_DISP0_DAT_8,
-	MX6Q_PAD_DISP0_DAT9__IPU1_DISP0_DAT_9,
-	MX6Q_PAD_SD1_DAT2__PWM2_PWMO,
-	MX6Q_PAD_SD1_DAT1__PWM3_PWMO,
-	MX6Q_PAD_GPIO_16__SJC_DE_B,
-	MX6Q_PAD_KEY_COL3__SPDIF_IN1,
-	MX6Q_PAD_EIM_D22__SPDIF_OUT1,
-	MX6Q_PAD_SD3_DAT6__UART1_RXD,
-	MX6Q_PAD_SD3_DAT7__UART1_TXD,
-	MX6Q_PAD_EIM_D27__UART2_RXD,
-	MX6Q_PAD_EIM_D26__UART2_TXD,
-	MX6Q_PAD_EIM_D31__GPIO_3_31,
-	MX6Q_PAD_SD3_CLK__USDHC3_CLK,
-	MX6Q_PAD_SD3_CMD__USDHC3_CMD,
-	MX6Q_PAD_SD3_DAT0__USDHC3_DAT0,
-	MX6Q_PAD_SD3_DAT1__USDHC3_DAT1,
-	MX6Q_PAD_SD3_DAT2__USDHC3_DAT2,
-	MX6Q_PAD_SD3_DAT3__USDHC3_DAT3,
-	MX6Q_PAD_SD4_CLK__USDHC4_CLK,
-	MX6Q_PAD_SD4_CMD__USDHC4_CMD,
-	MX6Q_PAD_SD4_DAT0__USDHC4_DAT0,
-	MX6Q_PAD_SD4_DAT1__USDHC4_DAT1,
-	MX6Q_PAD_SD4_DAT2__USDHC4_DAT2,
-	MX6Q_PAD_SD4_DAT3__USDHC4_DAT3,
-	MX6Q_PAD_SD4_DAT4__USDHC4_DAT4,
-	MX6Q_PAD_SD4_DAT5__USDHC4_DAT5,
-	MX6Q_PAD_SD4_DAT6__USDHC4_DAT6,
-	MX6Q_PAD_SD4_DAT7__USDHC4_DAT7,
-	MX6Q_PAD_NANDF_ALE__USDHC4_RST,
-	MX6Q_PAD_NANDF_CS1__GPIO_6_14,
-	MX6Q_PAD_NANDF_CS2__GPIO_6_15,
-};
-
-static iomux_v3_cfg_t realq7_pads_enet[] = {
-	MX6Q_PAD_RGMII_RXC__ENET_RGMII_RXC,
-	MX6Q_PAD_RGMII_RD0__ENET_RGMII_RD0,
-	MX6Q_PAD_RGMII_RD1__ENET_RGMII_RD1,
-	MX6Q_PAD_RGMII_RD2__ENET_RGMII_RD2,
-	MX6Q_PAD_RGMII_RD3__ENET_RGMII_RD3,
-	MX6Q_PAD_RGMII_RX_CTL__ENET_RGMII_RX_CTL,
-};
 
 #define RQ7_GPIO_ENET_PHYADD2	IMX_GPIO_NR(6, 30)
 #define RQ7_GPIO_ENET_MODE0	IMX_GPIO_NR(6, 25)
@@ -224,8 +48,6 @@ static iomux_v3_cfg_t realq7_pads_enet[] = {
 #define RQ7_GPIO_ENET_MODE2	IMX_GPIO_NR(6, 28)
 #define RQ7_GPIO_ENET_MODE3	IMX_GPIO_NR(6, 29)
 #define RQ7_GPIO_ENET_EN_CLK125	IMX_GPIO_NR(6, 24)
-#define RQ7_GPIO_SD3_CD		IMX_GPIO_NR(6, 14)
-#define RQ7_GPIO_SD3_WP		IMX_GPIO_NR(6, 15)
 
 static iomux_v3_cfg_t realq7_pads_gpio[] = {
 	MX6Q_PAD_RGMII_RXC__GPIO_6_30,
@@ -257,12 +79,7 @@ static int ksz9031rn_phy_fixup(struct phy_device *dev)
 	return 0;
 }
 
-static struct fec_platform_data fec_info = {
-	.xcv_type = PHY_INTERFACE_MODE_RGMII,
-	.phy_addr = -1,
-};
-
-static void realq7_enet_init(void)
+static int realq7_enet_init(void)
 {
 	mxc_iomux_v3_setup_multiple_pads(realq7_pads_gpio, ARRAY_SIZE(realq7_pads_gpio));
 	gpio_direction_output(RQ7_GPIO_ENET_PHYADD2, 0);
@@ -278,87 +95,18 @@ static void realq7_enet_init(void)
 	gpio_direction_output(25, 1);
 	mdelay(50);
 
-	mxc_iomux_v3_setup_multiple_pads(realq7_pads_enet, ARRAY_SIZE(realq7_pads_enet));
-
 	phy_register_fixup_for_uid(PHY_ID_KSZ9031, MICREL_PHY_ID_MASK,
 					   ksz9031rn_phy_fixup);
 
-	imx6_add_fec(&fec_info);
-}
-
-static int realq7_mem_init(void)
-{
-	arm_add_mem_device("ram0", 0x10000000, SZ_2G);
-
 	return 0;
 }
-mem_initcall(realq7_mem_init);
-
-static int realq7_spi_cs[] = { IMX_GPIO_NR(1, 12), };
-
-static struct spi_imx_master realq7_spi_0_data = {
-	.chipselect = realq7_spi_cs,
-	.num_chipselect = ARRAY_SIZE(realq7_spi_cs),
-};
-
-static const struct spi_board_info realq7_spi_board_info[] = {
-	{
-		.name = "m25p80",
-		.max_speed_hz = 40000000,
-		.bus_num = 4,
-		.chip_select = 0,
-	}
-};
-
-static struct esdhc_platform_data realq7_emmc_data = {
-	.cd_type = ESDHC_CD_PERMANENT,
-	.caps = MMC_MODE_8BIT,
-	.devname = "emmc",
-};
-
-static struct stmpe_platform_data stmpe1_pdata = {
-	.gpio_base = 224,
-	.blocks = STMPE_BLOCK_GPIO,
-};
-
-static struct stmpe_platform_data stmpe2_pdata = {
-	.gpio_base = 240,
-	.blocks = STMPE_BLOCK_GPIO,
-};
-
-static struct i2c_board_info realq7_i2c2_devices[] = {
-	{
-		I2C_BOARD_INFO("stmpe-i2c", 0x40),
-		.platform_data = &stmpe1_pdata,
-	}, {
-		I2C_BOARD_INFO("stmpe-i2c", 0x44),
-		.platform_data = &stmpe2_pdata,
-	},
-};
+fs_initcall(realq7_enet_init);
 
 static int realq7_devices_init(void)
 {
-	imx6_add_mmc2(NULL);
-	imx6_add_mmc3(&realq7_emmc_data);
-
-	realq7_enet_init();
-
-	i2c_register_board_info(1, realq7_i2c2_devices,
-			ARRAY_SIZE(realq7_i2c2_devices));
-
-	imx6_add_i2c0(NULL);
-	imx6_add_i2c1(NULL);
-	imx6_add_i2c2(NULL);
-
-	spi_register_board_info(realq7_spi_board_info,
-			ARRAY_SIZE(realq7_spi_board_info));
-	imx6_add_spi4(&realq7_spi_0_data);
-
-	imx6_add_sata();
-
-	imx6_bbu_internal_spi_i2c_register_handler("spiflash", "/dev/m25p0",
+	imx6_bbu_internal_spi_i2c_register_handler("spiflash", "/dev/m25p0.barebox",
 		BBU_HANDLER_FLAG_DEFAULT, NULL, 0, 0x00907000);
-	imx6_bbu_internal_mmc_register_handler("mmc", "/dev/disk0",
+	imx6_bbu_internal_mmc_register_handler("mmc", "/dev/mmc3.barebox",
 		0, NULL, 0, 0x00907000);
 
 	return 0;
@@ -367,41 +115,33 @@ device_initcall(realq7_devices_init);
 
 static int realq7_env_init(void)
 {
-	char *source_str = NULL;
-
 	switch (bootsource_get()) {
 	case BOOTSOURCE_MMC:
-		if (!IS_ENABLED(CONFIG_MCI_STARTUP))
-			setenv("mci0.probe", "1");
-		devfs_add_partition("disk0", 0, SZ_1M, DEVFS_PARTITION_FIXED, "self0");
-		devfs_add_partition("disk0", SZ_1M, SZ_1M, DEVFS_PARTITION_FIXED, "env0");
-		source_str = "SD/MMC";
-		break;
-	case BOOTSOURCE_SPI:
-		devfs_add_partition("m25p0", 0, SZ_256K, DEVFS_PARTITION_FIXED, "self0");
-		devfs_add_partition("m25p0", SZ_256K, SZ_256K, DEVFS_PARTITION_FIXED, "env0");
-		source_str = "SPI flash";
+		if (!IS_ENABLED(CONFIG_MCI_STARTUP)) {
+			struct device_d *dev = get_device_by_name("mmc3");
+			if (dev)
+				device_detect(dev);
+		}
+		devfs_add_partition("mmc3", 0, SZ_1M, DEVFS_PARTITION_FIXED, "mmc3.barebox");
+		devfs_add_partition("mmc3", SZ_1M, SZ_1M, DEVFS_PARTITION_FIXED, "mmc3.bareboxenv");
+		default_environment_path = "/dev/mmc3.bareboxenv";
 		break;
 	default:
-		printf("unknown Bootsource, no persistent environment\n");
+	case BOOTSOURCE_SPI:
+		devfs_add_partition("m25p0", 0, SZ_256K, DEVFS_PARTITION_FIXED, "m25p0.barebox");
+		devfs_add_partition("m25p0", SZ_256K, SZ_256K, DEVFS_PARTITION_FIXED, "m25p0.bareboxenv");
+		default_environment_path = "/dev/m25p0.bareboxenv";
 		break;
 	}
 
-	if (source_str)
-		printf("Using environment from %s\n", source_str);
-
 	return 0;
 }
 late_initcall(realq7_env_init);
 
 static int realq7_console_init(void)
 {
-	mxc_iomux_v3_setup_multiple_pads(realq7_pads, ARRAY_SIZE(realq7_pads));
-
 	imx6_init_lowlevel();
 
-	imx6_add_uart1();
-
 	return 0;
 }
-console_initcall(realq7_console_init);
+core_initcall(realq7_console_init);
diff --git a/arch/arm/configs/dmo-realq7_defconfig b/arch/arm/configs/dmo-realq7_defconfig
index d063e97..5501683 100644
--- a/arch/arm/configs/dmo-realq7_defconfig
+++ b/arch/arm/configs/dmo-realq7_defconfig
@@ -1,3 +1,5 @@
+CONFIG_BUILTIN_DTB=y
+CONFIG_BUILTIN_DTB_NAME="imx6q-dmo-realq7"
 CONFIG_ARCH_IMX=y
 CONFIG_ARCH_IMX6=y
 CONFIG_MACH_REALQ7=y
@@ -18,6 +20,7 @@ CONFIG_HUSH_FANCY_PROMPT=y
 CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
 CONFIG_MENU=y
+CONFIG_CONSOLE_ACTIVATE_NONE=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/dmo-mx6-realq7/env"
 CONFIG_RESET_SOURCE=y
@@ -50,7 +53,6 @@ CONFIG_CMD_BOOTM_OFTREE_UIMAGE=y
 CONFIG_CMD_RESET=y
 CONFIG_CMD_GO=y
 CONFIG_CMD_OFTREE=y
-CONFIG_CMD_OFTREE_PROBE=y
 CONFIG_CMD_OF_PROPERTY=y
 CONFIG_CMD_OF_NODE=y
 CONFIG_CMD_BAREBOX_UPDATE=y
@@ -64,12 +66,14 @@ CONFIG_CMD_I2C=y
 CONFIG_CMD_SPI=y
 CONFIG_CMD_MIITOOL=y
 CONFIG_CMD_CLK=y
+CONFIG_CMD_DETECT=y
 CONFIG_CMD_WD=y
 CONFIG_NET=y
 CONFIG_NET_DHCP=y
 CONFIG_NET_NFS=y
 CONFIG_NET_PING=y
 CONFIG_NET_RESOLV=y
+CONFIG_OFDEVICE=y
 CONFIG_DRIVER_NET_FEC_IMX=y
 CONFIG_DRIVER_SPI_IMX=y
 CONFIG_I2C=y
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index fa6a330..ebc6459 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1,5 +1,6 @@
 dtb-$(CONFIG_ARCH_IMX51) += imx51-babbage.dtb
-dtb-$(CONFIG_ARCH_IMX6) += imx6q-sabrelite.dtb \
+dtb-$(CONFIG_ARCH_IMX6) += imx6q-dmo-realq7.dtb \
+	imx6q-sabrelite.dtb \
 	imx6q-sabresd.dtb
 
 BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME))
diff --git a/arch/arm/dts/imx6q-dmo-realq7.dts b/arch/arm/dts/imx6q-dmo-realq7.dts
new file mode 100644
index 0000000..a33a700
--- /dev/null
+++ b/arch/arm/dts/imx6q-dmo-realq7.dts
@@ -0,0 +1,354 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+/dts-v1/;
+
+#include "imx6q.dtsi"
+
+/ {
+	model = "Data Modul RealQ7 Board";
+	compatible = "dmo,imx6q-realq7", "fsl,imx6q";
+
+	chosen {
+		linux,stdout-path = "/soc/aips-bus at 02100000/serial at 021e8000";
+	};
+
+	aliases {
+		stmpe0 = &stmpe_1;
+		stmpe1 = &stmpe_2;
+		gpio7 = &stmpe_gpio_1;
+		gpio8 = &stmpe_gpio_2;
+	};
+
+	memory {
+		reg = <0x10000000 0x80000000>;
+	};
+
+	di0 {
+		compatible = "fsl,imx-parallel-display";
+		interface-pix-fmt = "rgb24";
+		crtcs = <&ipu1 0>;
+	};
+
+	regulators {
+		compatible = "simple-bus";
+
+		reg_2p5v: 2p5v {
+			compatible = "regulator-fixed";
+			regulator-name = "2P5V";
+			regulator-min-microvolt = <2500000>;
+			regulator-max-microvolt = <2500000>;
+			regulator-always-on;
+		};
+
+		reg_3p3v: 3p3v {
+			compatible = "regulator-fixed";
+			regulator-name = "3P3V";
+			regulator-min-microvolt = <3300000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-always-on;
+		};
+
+		reg_usb_otg_vbus: usb_otg_vbus {
+			compatible = "regulator-fixed";
+			regulator-name = "usb_otg_vbus";
+			regulator-min-microvolt = <5000000>;
+			regulator-max-microvolt = <5000000>;
+			gpio = <&gpio7 12 0>;
+		};
+
+		reg_usb_host1: usb_host1_en {
+			compatible = "regulator-fixed";
+			regulator-name = "usb_host1_en";
+			regulator-min-microvolt = <3300000>;
+			regulator-max-microvolt = <3300000>;
+			gpio = <&gpio3 31 0>;
+			enable-active-high;
+		};
+	};
+};
+
+&ecspi5 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_ecspi_5_1>;
+	fsl,spi-num-chipselects = <1>;
+	cs-gpios = <&gpio1 12 0>;
+	status = "okay";
+
+	flash: m25p80 at 0 {
+		compatible = "m25p80";
+		spi-max-frequency = <40000000>;
+		reg = <0>;
+	};
+};
+
+&fec {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_enet_1>;
+	phy-mode = "rgmii";
+	phy-reset-gpios = <&gpio3 23 0>;
+	status = "okay";
+};
+
+&i2c2 {
+	status = "okay";
+	clock-frequency = <100000>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c2
+		     &pinctrl_stmpe_1_1
+		     &pinctrl_stmpe_2_1>;
+
+	stmpe_1: stmpe1601 at 40 {
+		compatible = "stmpe1601";
+		reg = <0x40>;
+		interrupts = <30 0>;
+		interrupt-parent = <&gpio3>;
+		stmpe_gpio_1: stmpe_gpio {
+			compatible = "st,stmpe-gpio";
+		};
+	};
+
+	stmpe_2: stmpe1601 at 44 {
+		compatible = "stmpe1601";
+		reg = <0x44>;
+		interrupts = <2 0>;
+		interrupt-parent = <&gpio5>;
+		stmpe_gpio_2: stmpe_gpio {
+			compatible = "st,stmpe-gpio";
+		};
+	};
+
+	temp1: ad7414 at 4c {
+		compatible = "ad7414";
+		reg = <0x4c>;
+	};
+
+	temp2: ad7414 at 4d {
+		compatible = "ad7414";
+		reg = <0x4d>;
+	};
+
+	rtc: m41t62 at 68 {
+		compatible = "m41t62";
+		reg = <0x68>;
+	};
+
+	pmic: pf0100 at 08 {
+		compatible = "pf0100-regulator";
+		reg = <0x08>;
+		interrupt-parent = <&gpio3>;
+		interrupts = <20 8>;
+
+		regulators {
+			reg_vddcore: sw1ab {
+				regulator-min-microvolt = <300000>;
+				regulator-max-microvolt = <1875000>;
+				regulator-always-on;
+			};
+
+			reg_vddsoc: sw1c {
+				regulator-min-microvolt = <300000>;
+				regulator-max-microvolt = <1875000>;
+				regulator-always-on;
+			};
+
+			reg_gen_3v3: sw2 {
+				regulator-min-microvolt = <800000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+			};
+
+			reg_ddr_1v5a: sw3a {
+				regulator-min-microvolt = <400000>;
+				regulator-max-microvolt = <1975000>;
+				regulator-always-on;
+			};
+
+			reg_ddr_1v5b: sw3b {
+				regulator-min-microvolt = <400000>;
+				regulator-max-microvolt = <1975000>;
+				regulator-always-on;
+			};
+
+			reg_ddr_vtt: sw4 {
+				regulator-min-microvolt = <400000>;
+				regulator-max-microvolt = <1975000>;
+				regulator-always-on;
+			};
+
+			reg_5v_600mA: swbst {
+				regulator-min-microvolt = <5000000>;
+				regulator-max-microvolt = <5150000>;
+				regulator-always-on;
+			};
+
+			reg_snvs_3v: vsnvs {
+				regulator-min-microvolt = <1500000>;
+				regulator-max-microvolt = <3000000>;
+				regulator-always-on;
+			};
+
+			reg_vrefddr: vrefddr {
+				regulator-min-microvolt = <750000>;
+				regulator-max-microvolt = <750000>;
+				regulator-always-on;
+			};
+
+			reg_vgen1_1v5: vgen1 {
+				regulator-min-microvolt = <800000>;
+				regulator-max-microvolt = <1550000>;
+				/* not used */
+			};
+
+			reg_vgen2_1v2_eth: vgen2 {
+				regulator-min-microvolt = <800000>;
+				regulator-max-microvolt = <1550000>;
+				regulator-always-on;
+			};
+
+			reg_vgen3_2v8: vgen3 {
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+			};
+
+			reg_vgen4_1v8: vgen4 {
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+			};
+
+			reg_vgen5_1v8_eth: vgen5 {
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+			};
+
+			reg_vgen6_3v3: vgen6 {
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+			};
+		};
+	};
+};
+
+&iomuxc {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_hog>, <&pinctrl_pfuze_1>;
+
+	hog {
+		pinctrl_hog: hoggrp-1 {
+			fsl,pins = <
+				MX6Q_PAD_EIM_A16__GPIO2_IO22 0x80000000
+				MX6Q_PAD_EIM_A17__GPIO2_IO21 0x80000000
+			>;
+		};
+	};
+
+	i2c2 {
+		pinctrl_i2c2: i2c2grp {
+			fsl,pins = <
+				MX6Q_PAD_EIM_EB2__I2C2_SCL 0x4001b8b1
+				MX6Q_PAD_KEY_ROW3__I2C2_SDA 0x4001b8b1
+			>;
+		};
+	};
+
+	uart {
+		pinctrl_uart1_2: uart1grp-2 {
+			fsl,pins = <
+				MX6Q_PAD_SD3_DAT6__UART1_RX_DATA 0x1b0b1
+				MX6Q_PAD_SD3_DAT7__UART1_TX_DATA 0x1b0b1
+			>;
+		};
+	};
+
+	pfuze {
+		pinctrl_pfuze_1: pfuze100grp1 {
+			fsl,pins = <
+				MX6Q_PAD_EIM_D20__GPIO3_IO20 0x198c0
+			>;
+		};
+	};
+
+	stmpe_1 {
+		pinctrl_stmpe_1_1: stmpe1grp-1 {
+			fsl,pins = <
+				MX6Q_PAD_EIM_D30__GPIO3_IO30 0x80000000
+			>;
+		};
+	};
+
+	stmpe_2 {
+		pinctrl_stmpe_2_1: stmpe2grp-1 {
+			fsl,pins = <
+				MX6Q_PAD_EIM_A25__GPIO5_IO02 0x80000000
+			>;
+		};
+	};
+
+	ecspi5 {
+		pinctrl_ecspi_5_1: ecspi5rp-1 {
+			fsl,pins = <
+				MX6Q_PAD_SD1_DAT0__ECSPI5_MISO 0x80000000
+				MX6Q_PAD_SD1_CMD__ECSPI5_MOSI 0x80000000
+				MX6Q_PAD_SD2_DAT3__GPIO1_IO12 0x80000000 /* cs0: m25p80 */
+			>;
+		};
+	};
+};
+
+&sata {
+	status = "okay";
+};
+
+&uart1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_uart1_2>;
+	status = "okay";
+};
+
+&uart2 {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_uart2_1>;
+};
+
+&usbh1 {
+	vbus-supply = <&reg_usb_host1>;
+	status = "okay";
+	disable-over-current;
+};
+
+&usbotg {
+	vbus-supply = <&reg_usb_otg_vbus>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_usbotg_1>;
+	disable-over-current;
+	status = "okay";
+};
+
+&usdhc3 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_usdhc3_2>;
+	vmmc-supply = <&reg_3p3v>;
+	status = "okay";
+};
+
+&usdhc4 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_usdhc4_1>;
+	vmmc-supply = <&reg_3p3v>;
+	non-removable;
+	bus-width = <8>;
+	status = "okay";
+};
-- 
1.8.2.rc2



From afurmanczuk at knowtrek.com  Thu Jun  6 12:03:34 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Thu, 06 Jun 2013 18:03:34 +0200
Subject: how to flash barebox and set root variable?
Message-ID: <51B0B2D6.3030407@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I am quite new to barebox. Before I had little bit experience in u-Boot.

My Barebox version is: barebox 2012.03.0-00162-g3f84abc-dirty (Sep 24
2012 - 10:51:42)

I can mount a Linaro freescale mx53 sd-card setup. I think it has one
Fat8 partion, because Fat32 and Fat16 are not recognized by my barebox
version.

When I boot the uImage, it complains about not setting the "root="
parameter, when I give it as an argument it does not work.

In my u-Boot setup all I need to do was write:

setenv bootcmd "fatload mmc 0:2 0x70800000 uImage;bootm"
setenv bootargs "console=tty0 console=ttymxc0,115200n8
root=/dev/mmcblk0p3 rootfstype=ext4 rootwait ro"

Maybe this is a version isuue? I managed to build the latest kernel
what is the procedure to "flash" the new barebox.bin? Can I use the cp
command for this, or do I need to flash it via OCD? If so what are
good tools in linux to achieve that task?

OK a lot of questions. Most probably already answered, but had not
found google.

Thanks for help and sorry for repeating questions already answered.

Adam
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlGwstYACgkQefEEI87R1DeHaQCgkNvnNfFLBBZszhb8uzAavgAn
vO4AoJZqx1U9LD6IXGmT7RiMbWL5hW/w
=uv5T
-----END PGP SIGNATURE-----


From s.hauer at pengutronix.de  Thu Jun  6 12:21:20 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 6 Jun 2013 18:21:20 +0200
Subject: how to flash barebox and set root variable?
In-Reply-To: <51B0B2D6.3030407@knowtrek.com>
References: <51B0B2D6.3030407@knowtrek.com>
Message-ID: <20130606162120.GA32299@pengutronix.de>

On Thu, Jun 06, 2013 at 06:03:34PM +0200, Adam Furmanczuk wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi,
> 
> I am quite new to barebox. Before I had little bit experience in u-Boot.
> 
> My Barebox version is: barebox 2012.03.0-00162-g3f84abc-dirty (Sep 24
> 2012 - 10:51:42)
> 
> I can mount a Linaro freescale mx53 sd-card setup. I think it has one
> Fat8 partion, because Fat32 and Fat16 are not recognized by my barebox
> version.
> 
> When I boot the uImage, it complains about not setting the "root="
> parameter, when I give it as an argument it does not work.
> 
> In my u-Boot setup all I need to do was write:
> 
> setenv bootcmd "fatload mmc 0:2 0x70800000 uImage;bootm"
> setenv bootargs "console=tty0 console=ttymxc0,115200n8
> root=/dev/mmcblk0p3 rootfstype=ext4 rootwait ro"
> 
> Maybe this is a version isuue? I managed to build the latest kernel
> what is the procedure to "flash" the new barebox.bin? Can I use the cp
> command for this, or do I need to flash it via OCD? If so what are
> good tools in linux to achieve that task?
> 
> OK a lot of questions. Most probably already answered, but had not
> found google.

What board do you have? Is it one supported by barebox or do you have
your own patches?

Generally with i.MX5 you can write the image (barebox.bin in this old
version, barebox-flash-image in more recent versions) directly to a
MMC/SD card, under Linux with:

cat barebox.bin > /dev/sdx

or under barebox:

tftp barebox.bin /dev/mci0

Generally you also always start barebox 2nd stage. So if you have an
older barebox (Or U-Boot) on your board you can:

tftp barebox.bin /dev/ram0
go /dev/ram0

(Similar with U-Boot: tftp $loadaddr barebox.bin; go $loadaddr)

This way you can test barebox without any risk.

What to do next depends on the environment you have. Please send the
output of 'ls -l /env'.

Using a more recent version of barebox probably is a good idea. We
gained a lot of interesting features in the last year.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From alex.aring at gmail.com  Thu Jun  6 13:52:25 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Thu, 6 Jun 2013 19:52:25 +0200
Subject: [PATCH/RFC 0/5] Another try for a new memtest implementation
In-Reply-To: <20130606115245.a8add6e7ee99b4354fd9df84@gmail.com>
References: <1370301232-12962-1-git-send-email-alex.aring@gmail.com>
 <20130606115245.a8add6e7ee99b4354fd9df84@gmail.com>
Message-ID: <20130606175223.GA2892@x61s.8.8.8.8>

Hi Antony,

On Thu, Jun 06, 2013 at 11:52:45AM +0400, antonynpavlov at gmail.com wrote:
> On Tue,  4 Jun 2013 01:13:47 +0200
> Alexander Aring <alex.aring at gmail.com> wrote:
> 
> > Hi,
> > 
> > this is a new try to get a new memtest implementation into barebox.
> > 
> 
> I have got the new memtest command from the next branch.
> 
> Here is my MIPS qemu-malta build log:
> 
>   CC      commands/memtest.o
> commands/memtest.c: In function `alloc_memtest_region':
> commands/memtest.c:39: warning: implicit declaration of function `xzalloc'
> commands/memtest.c:39: warning: assignment makes pointer from integer without a cast

thanks for send this notice. I know why this happend.

We get an include from architecure specific header file "asm/mmu.h" and
some mmu.h in other architecure don't include "inside of arch specific
asm/mmu.h" headers like "malloc.h", "errno.h".

I simple forgot to handle this.

I will send a patch "for-next" to add these header files to memtest.

Regards
Alex


From afurmanczuk at knowtrek.com  Fri Jun  7 01:08:32 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Fri, 07 Jun 2013 07:08:32 +0200
Subject: how to flash barebox and set root variable?
In-Reply-To: <20130606162120.GA32299@pengutronix.de>
References: <51B0B2D6.3030407@knowtrek.com>
 <20130606162120.GA32299@pengutronix.de>
Message-ID: <51B16AD0.4030206@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Sascha,

thank you very much for your help.

> What board do you have? Is it one supported by barebox or do you
> have your own patches?

The board is a imx536 based [1]. The expansion board for this is self
made. We connect RX, TX, Ground to a OCD-Adapter [2] and are able to
communicate with barebox.

My Barebox version is: barebox 2012.03.0-00162-g3f84abc-dirty (Sep 24
2012 - 10:51:42) it was already flashed in nor when we recieved the board.


> What to do next depends on the environment you have. Please send
> the output of 'ls -l /env'.

The module is at my work place, I will post back on monday. I also
post you the config file, which at this stage is still diffucilt for
me to read.

> Using a more recent version of barebox probably is a good idea. We 
> gained a lot of interesting features in the last year.

Exactly, I have seen in 'make menuconfig' when building the latest image.

I try to write barebox.bin to my sd-card on host with:

cat barebox.bin > /dev/sdx

and report back to barebox reaction.


Greetings,

Adam


[1] http://www.in-circuit.de/produkte/icnova-sodimm-cpu-module.html
[2]
http://shop.in-circuit.de/products/Home/Programmieradapter/16/ICprog-OpenOCD

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlGxatAACgkQefEEI87R1DdcrQCfYL5nfs8K4Hsdp6GTuDWHCfXs
khoAoIa0wy08POHDy8SZeLCrhV35iZET
=M7kH
-----END PGP SIGNATURE-----


From s.hauer at pengutronix.de  Fri Jun  7 06:55:05 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 7 Jun 2013 12:55:05 +0200
Subject: how to flash barebox and set root variable?
In-Reply-To: <51B16AD0.4030206@knowtrek.com>
References: <51B0B2D6.3030407@knowtrek.com>
 <20130606162120.GA32299@pengutronix.de>
 <51B16AD0.4030206@knowtrek.com>
Message-ID: <20130607105505.GE32299@pengutronix.de>

On Fri, Jun 07, 2013 at 07:08:32AM +0200, Adam Furmanczuk wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi Sascha,
> 
> thank you very much for your help.
> 
> > What board do you have? Is it one supported by barebox or do you
> > have your own patches?
> 
> The board is a imx536 based [1]. The expansion board for this is self
> made. We connect RX, TX, Ground to a OCD-Adapter [2] and are able to
> communicate with barebox.
> 
> My Barebox version is: barebox 2012.03.0-00162-g3f84abc-dirty (Sep 24
> 2012 - 10:51:42) it was already flashed in nor when we recieved the board.

I see. They should provide the source code for this. I haven't
downloaded the CD images they provide. Do you know whether there
are barebox sources provided on the CDs?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.trumtrar at pengutronix.de  Fri Jun  7 08:41:27 2013
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Fri,  7 Jun 2013 14:41:27 +0200
Subject: [PATCH 0/3] tqma53: fixes for Kconfig and flash_header
Message-ID: <1370608890-13776-1-git-send-email-s.trumtrar@pengutronix.de>

Hi!

Some fixes for the tqma53:
	- rename "tqma53"->"TQMa53" in Kconfig text
	- move RAM size selection to boardspecific submenu
	- update flash_header with Errata settings

Regards,
Steffen


Markus Niebel (3):
  ARM: i.MX53: tqma53: fix board name in Kconfig
  ARM: i.MX53: tqma53: move RAM setting to submenu
  ARM: i.MX53: tqma53: update flash_header

 arch/arm/boards/tqma53/flash_header.c |  9 ++++++---
 arch/arm/mach-imx/Kconfig             | 20 ++++++++++++--------
 2 files changed, 18 insertions(+), 11 deletions(-)

-- 
1.8.2.rc2



From s.trumtrar at pengutronix.de  Fri Jun  7 08:41:28 2013
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Fri,  7 Jun 2013 14:41:28 +0200
Subject: [PATCH 1/3] ARM: i.MX53: tqma53: fix board name in Kconfig
In-Reply-To: <1370608890-13776-1-git-send-email-s.trumtrar@pengutronix.de>
References: <1370608890-13776-1-git-send-email-s.trumtrar@pengutronix.de>
Message-ID: <1370608890-13776-2-git-send-email-s.trumtrar@pengutronix.de>

From: Markus Niebel <Markus.Niebel at tqs.de>

Signed-off-by: Markus Niebel <Markus.Niebel at tqs.de>
Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 arch/arm/mach-imx/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 359b5cd..0e4eb1d 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -54,7 +54,7 @@ config BOARDINFO
 	default "Efika MX smartbook" if MACH_EFIKA_MX_SMARTBOOK
 	default "Garz+Fricke Cupid" if MACH_GUF_CUPID
 	default "Ka-Ro tx25" if MACH_TX25
-	default "TQ tqma53" if MACH_TQMA53
+	default "TQ TQMa53" if MACH_TQMA53
 	default "Ka-Ro tx51" if MACH_TX51
 	default "Freescale i.MX6q armadillo2" if MACH_MX6Q_ARM2
 	default "ConnectCore i.MX51" if MACH_CCMX51
@@ -464,7 +464,7 @@ config MACH_FREESCALE_MX53_SMD
 
 config MACH_TQMA53
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
-	bool "TQ i.MX53 TQMA53"
+	bool "TQ i.MX53 TQMa53"
 
 config MACH_TQMA53_1GB_RAM
 	bool "Use 1GiB of SDRAM"
-- 
1.8.2.rc2



From s.trumtrar at pengutronix.de  Fri Jun  7 08:41:30 2013
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Fri,  7 Jun 2013 14:41:30 +0200
Subject: [PATCH 3/3] ARM: i.MX53: tqma53: update flash_header
In-Reply-To: <1370608890-13776-1-git-send-email-s.trumtrar@pengutronix.de>
References: <1370608890-13776-1-git-send-email-s.trumtrar@pengutronix.de>
Message-ID: <1370608890-13776-4-git-send-email-s.trumtrar@pengutronix.de>

From: Markus Niebel <Markus.Niebel at tqs.de>

Integrate errata fixes for SDCTL settings.

Signed-off-by: Markus Niebel <Markus.Niebel at tqs.de>
Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 arch/arm/boards/tqma53/flash_header.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boards/tqma53/flash_header.c b/arch/arm/boards/tqma53/flash_header.c
index a6bcdad..ea649af 100644
--- a/arch/arm/boards/tqma53/flash_header.c
+++ b/arch/arm/boards/tqma53/flash_header.c
@@ -56,7 +56,8 @@ struct imx_dcd_v2_entry __dcd_entry_section dcd_entry[] = {
 	{ .addr = cpu_to_be32(0x63fd9080), .val = cpu_to_be32(0x013b013c), },
 	{ .addr = cpu_to_be32(0x63fd90f8), .val = cpu_to_be32(0x00000800), },
 #ifdef CONFIG_MACH_TQMA53_1GB_RAM
-	{ .addr = cpu_to_be32(0x63fd9018), .val = cpu_to_be32(0x00001740), },
+	/* sync with u-boot: add WALAT for 4 chip variant */
+	{ .addr = cpu_to_be32(0x63fd9018), .val = cpu_to_be32(0x00011740), },
 	{ .addr = cpu_to_be32(0x63fd9000), .val = cpu_to_be32(0xc3190000), },
 #else
 	{ .addr = cpu_to_be32(0x63fd9018), .val = cpu_to_be32(0x00101740), },
@@ -66,7 +67,8 @@ struct imx_dcd_v2_entry __dcd_entry_section dcd_entry[] = {
 	{ .addr = cpu_to_be32(0x63fd9010), .val = cpu_to_be32(0xb68e8a63), },
 	{ .addr = cpu_to_be32(0x63fd9014), .val = cpu_to_be32(0x01ff00db), },
 	{ .addr = cpu_to_be32(0x63fd902c), .val = cpu_to_be32(0x000026d2), },
-	{ .addr = cpu_to_be32(0x63fd9030), .val = cpu_to_be32(0x009f0e21), },
+	/* Engcm12377 / errata sheet 03/2013 */
+	{ .addr = cpu_to_be32(0x63fd9030), .val = cpu_to_be32(0x009f0e23), },
 	{ .addr = cpu_to_be32(0x63fd9008), .val = cpu_to_be32(0x12273030), },
 	{ .addr = cpu_to_be32(0x63fd9004), .val = cpu_to_be32(0x0002002d), },
 	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00008032), },
@@ -80,7 +82,8 @@ struct imx_dcd_v2_entry __dcd_entry_section dcd_entry[] = {
 	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x05208138), },
 	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x04008048), },
 	{ .addr = cpu_to_be32(0x63fd9020), .val = cpu_to_be32(0x00005800), },
-	{ .addr = cpu_to_be32(0x63fd9040), .val = cpu_to_be32(0x04b80003), },
+	/* prevent reserved value, use default TZQ_CS */
+	{ .addr = cpu_to_be32(0x63fd9040), .val = cpu_to_be32(0x05380003), },
 	{ .addr = cpu_to_be32(0x63fd9058), .val = cpu_to_be32(0x00022227), },
 	{ .addr = cpu_to_be32(0x63fd901C), .val = cpu_to_be32(0x00000000), },
 };
-- 
1.8.2.rc2



From s.trumtrar at pengutronix.de  Fri Jun  7 08:41:29 2013
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Fri,  7 Jun 2013 14:41:29 +0200
Subject: [PATCH 2/3] ARM: i.MX53: tqma53: move RAM setting to submenu
In-Reply-To: <1370608890-13776-1-git-send-email-s.trumtrar@pengutronix.de>
References: <1370608890-13776-1-git-send-email-s.trumtrar@pengutronix.de>
Message-ID: <1370608890-13776-3-git-send-email-s.trumtrar@pengutronix.de>

From: Markus Niebel <Markus.Niebel at tqs.de>

Signed-off-by: Markus Niebel <Markus.Niebel at tqs.de>
Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 arch/arm/mach-imx/Kconfig | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 0e4eb1d..4a8f6b7 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -466,12 +466,6 @@ config MACH_TQMA53
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	bool "TQ i.MX53 TQMa53"
 
-config MACH_TQMA53_1GB_RAM
-	bool "Use 1GiB of SDRAM"
-	depends on MACH_TQMA53
-	help
-	  use 1GiB of SDRAM (512MiB otherwise)
-
 config MACH_TX53
 	bool "Ka-Ro TX53"
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
@@ -592,6 +586,16 @@ endchoice
 
 endif
 
+if MACH_TQMA53
+
+config MACH_TQMA53_1GB_RAM
+	bool "Use 1GiB of SDRAM"
+	depends on MACH_TQMA53
+	help
+	  use 1GiB of SDRAM (512MiB otherwise)
+
+endif
+
 endmenu
 
 menu "i.MX specific settings"
-- 
1.8.2.rc2



From alex.aring at gmail.com  Fri Jun  7 16:58:45 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Fri,  7 Jun 2013 22:58:45 +0200
Subject: [For-next PATCH] memtest: add missing includes
Message-ID: <1370638725-4045-1-git-send-email-alex.aring@gmail.com>

Signed-off-by: Alexander Aring <alex.aring at gmail.com>
---
 commands/memtest.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/commands/memtest.c b/commands/memtest.c
index a67d868..d2a1487 100644
--- a/commands/memtest.c
+++ b/commands/memtest.c
@@ -27,6 +27,9 @@
 #include <getopt.h>
 #include <asm/mmu.h>
 #include <memory.h>
+#include <malloc.h>
+#include <common.h>
+#include <errno.h>
 
 #include <memtest.h>
 
-- 
1.8.3



From s.hauer at pengutronix.de  Sat Jun  8 09:07:30 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 8 Jun 2013 15:07:30 +0200
Subject: [PATCH 0/3] tqma53: fixes for Kconfig and flash_header
In-Reply-To: <1370608890-13776-1-git-send-email-s.trumtrar@pengutronix.de>
References: <1370608890-13776-1-git-send-email-s.trumtrar@pengutronix.de>
Message-ID: <20130608130730.GH32299@pengutronix.de>

On Fri, Jun 07, 2013 at 02:41:27PM +0200, Steffen Trumtrar wrote:
> Hi!
> 
> Some fixes for the tqma53:
> 	- rename "tqma53"->"TQMa53" in Kconfig text
> 	- move RAM size selection to boardspecific submenu
> 	- update flash_header with Errata settings

Applied, thanks

Sascha

> 
> Regards,
> Steffen
> 
> 
> Markus Niebel (3):
>   ARM: i.MX53: tqma53: fix board name in Kconfig
>   ARM: i.MX53: tqma53: move RAM setting to submenu
>   ARM: i.MX53: tqma53: update flash_header
> 
>  arch/arm/boards/tqma53/flash_header.c |  9 ++++++---
>  arch/arm/mach-imx/Kconfig             | 20 ++++++++++++--------
>  2 files changed, 18 insertions(+), 11 deletions(-)
> 
> -- 
> 1.8.2.rc2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sat Jun  8 09:13:15 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 8 Jun 2013 15:13:15 +0200
Subject: [PATCH] OMAP4: Use default clock source for mcbsp
In-Reply-To: <1369741903-24988-2-git-send-email-j.weitzel@phytec.de>
References: <1369741903-24988-2-git-send-email-j.weitzel@phytec.de>
Message-ID: <20130608131315.GC26150@pengutronix.de>

On Tue, May 28, 2013 at 01:51:40PM +0200, Jan Weitzel wrote:
> In omap4_enable_all_clocks we not only enable the mcbsp clocks, but also
> change the source from ABE_24M_FCLK to 24M_FCLK. Revert this and default
> to the reset state.
> 
> Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>

Applied, thanks

Sascha

> ---
>  arch/arm/mach-omap/omap4_clock.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/mach-omap/omap4_clock.c b/arch/arm/mach-omap/omap4_clock.c
> index 0621fd3..889d1f9 100644
> --- a/arch/arm/mach-omap/omap4_clock.c
> +++ b/arch/arm/mach-omap/omap4_clock.c
> @@ -253,9 +253,9 @@ void omap4_enable_all_clocks(void)
>  	sr32(CM1_ABE_PDM_CLKCTRL, 0, 32, 0x2);
>  	sr32(CM1_ABE_DMIC_CLKCTRL, 0, 32, 0x2);
>  	sr32(CM1_ABE_MCASP_CLKCTRL, 0, 32, 0x2);
> -	sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x08000002);
> -	sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x08000002);
> -	sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x08000002);
> +	sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x2);
> +	sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x2);
> +	sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x2);
>  	sr32(CM1_ABE_SLIMBUS_CLKCTRL, 0, 32, 0xf02);
>  	sr32(CM1_ABE_TIMER5_CLKCTRL, 0, 32, 0x2);
>  	sr32(CM1_ABE_TIMER6_CLKCTRL, 0, 32, 0x2);
> -- 
> 1.7.0.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sat Jun  8 09:21:38 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 8 Jun 2013 15:21:38 +0200
Subject: [PATCH v2] omap4: set voltage according to mpu freq
In-Reply-To: <CAGo_u6rixBCzggcuLAfOLuxgTrzyDhY7ipf2garfTiDb_Ce0WA@mail.gmail.com>
References: <1370425962.3824.1.camel@lws-weitzel>
 <1370522836-11258-1-git-send-email-j.weitzel@phytec.de>
 <CAGo_u6rixBCzggcuLAfOLuxgTrzyDhY7ipf2garfTiDb_Ce0WA@mail.gmail.com>
Message-ID: <20130608132138.GI32299@pengutronix.de>

On Thu, Jun 06, 2013 at 08:40:46AM -0500, menon.nishanth at gmail.com wrote:
> On Thu, Jun 6, 2013 at 7:47 AM, Jan Weitzel <j.weitzel at phytec.de> wrote:
> > +noinline int omap4460_scale_vcores(unsigned vsel0_pin, unsigned volt_mv)
> > +{
> > +       void __iomem *base;
> > +       u32 val = 0;
> > +
> > +       /* For VC bypass only VCOREx_CGF_FORCE  is necessary and
> > +        * VCOREx_CFG_VOLTAGE  changes can be discarded
> > +        */
> > +       writel(0, OMAP44XX_PRM_VC_CFG_I2C_MODE);
> > +       writel(0x6026, OMAP44XX_PRM_VC_CFG_I2C_CLK);
> > +
> > +       /* TPS - supplies vdd_mpu on 4460
> > +        * Setup SET1 and SET0 with right values so that kernel
> > +        * can use either of them based on its needs.
> > +        */
> > +
> > +       omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, volt_mv);
> Just a nitpick - the general rule of TPS+OMAP4460 integration is *NOT*
> to program SET0 register. this is intended to be at boot voltage
> required to be used when reboot due to s/w controlled or h/w watchdog.

So this line should simply be removed?

Ok, this line is only moved and not introduced in this patch, so it
should be fine to apply this patch and leave this for a separate patch.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sat Jun  8 09:22:29 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 8 Jun 2013 15:22:29 +0200
Subject: [PATCH] ARM i.MX6: Fix bootsource detection
In-Reply-To: <1370500369-3657-1-git-send-email-philipp.zabel@gmail.com>
References: <1370500369-3657-1-git-send-email-philipp.zabel@gmail.com>
Message-ID: <20130608132229.GJ32299@pengutronix.de>

On Thu, Jun 06, 2013 at 08:32:49AM +0200, Philipp Zabel wrote:
> This patch fixes bootsource detection on i.MX6 for serial and i2c boot.
> The bootsource_instance is now determined for spi, i2c, and mmc/sd boot.
> 
> Signed-off-by: Philipp Zabel <philipp.zabel at gmail.com>

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From shc_work at mail.ru  Sun Jun  9 04:40:08 2013
From: shc_work at mail.ru (Alexander Shiyan)
Date: Sun,  9 Jun 2013 12:40:08 +0400
Subject: [PATCH] ARM: pcm038: Fix partition size definitions
Message-ID: <1370767208-22789-1-git-send-email-shc_work@mail.ru>


Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
---
 arch/arm/boards/pcm038/pcm038.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index 372aea5..49677c2 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -332,22 +332,20 @@ static int pcm038_devices_init(void)
 
 	switch (bootsource_get()) {
 	case BOOTSOURCE_NAND:
-		devfs_add_partition("nand0", 0x00000, 0x80000,
-					DEVFS_PARTITION_FIXED, "self_raw");
+		devfs_add_partition("nand0", 0, SZ_512K,
+				    DEVFS_PARTITION_FIXED, "self_raw");
 		dev_add_bb_dev("self_raw", "self0");
-
-		devfs_add_partition("nand0", 0x80000, 0x100000,
-					DEVFS_PARTITION_FIXED, "env_raw");
+		devfs_add_partition("nand0", SZ_512K, SZ_128K,
+				    DEVFS_PARTITION_FIXED, "env_raw");
 		dev_add_bb_dev("env_raw", "env0");
 		envdev = "NAND";
 		break;
 	default:
-		devfs_add_partition("nor0", 0x00000, 0x80000,
-					DEVFS_PARTITION_FIXED, "self0");
-		devfs_add_partition("nor0", 0x80000, 0x100000,
-					DEVFS_PARTITION_FIXED, "env0");
+		devfs_add_partition("nor0", 0, SZ_512K,
+				    DEVFS_PARTITION_FIXED, "self0");
+		devfs_add_partition("nor0", SZ_512K, SZ_128K,
+				    DEVFS_PARTITION_FIXED, "env0");
 		protect_file("/dev/env0", 1);
-
 		envdev = "NOR";
 	}
 
-- 
1.8.1.5



From shc_work at mail.ru  Sun Jun  9 06:22:41 2013
From: shc_work at mail.ru (Alexander Shiyan)
Date: Sun,  9 Jun 2013 14:22:41 +0400
Subject: [PATCH] ARM: pcm038: Avoid warning if gadget support not compiled in
Message-ID: <1370773361-25588-1-git-send-email-shc_work@mail.ru>


Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
---
 arch/arm/boards/pcm038/pcm038.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index 49677c2..dec5164 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -328,7 +328,8 @@ static int pcm038_devices_init(void)
 	mdelay(1);
 	imx_gpio_mode(PE1_PF_USBOTG_STP);
 
-	imx27_add_usbotg(&pcm038_otg_pdata);
+	if (IS_ENABLED(CONFIG_USB_GADGET_DRIVER_ARC))
+		imx27_add_usbotg(&pcm038_otg_pdata);
 
 	switch (bootsource_get()) {
 	case BOOTSOURCE_NAND:
-- 
1.8.1.5



From shc_work at mail.ru  Sun Jun  9 06:42:43 2013
From: shc_work at mail.ru (Alexander Shiyan)
Date: Sun,  9 Jun 2013 14:42:43 +0400
Subject: [RFC v2] GPIO: i.MX: Rewrite driver for using generic GPIO code
Message-ID: <1370774563-27240-1-git-send-email-shc_work@mail.ru>


Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
---
 arch/arm/Kconfig        |   1 -
 drivers/gpio/Kconfig    |   1 +
 drivers/gpio/gpio-imx.c | 130 ++++++++++++------------------------------------
 3 files changed, 33 insertions(+), 99 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index cfb82b0..06ba6c4 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -72,7 +72,6 @@ config ARCH_HIGHBANK
 
 config ARCH_IMX
 	bool "Freescale iMX-based"
-	select GENERIC_GPIO
 	select GPIOLIB
 	select COMMON_CLK
 	select CLKDEV_LOOKUP
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index e976db4..051af14 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -29,6 +29,7 @@ config GPIO_GENERIC_PLATFORM
 
 config GPIO_IMX
 	def_bool ARCH_IMX
+	select GPIO_GENERIC
 
 config GPIO_PL061
 	bool "PrimeCell PL061 GPIO support"
diff --git a/drivers/gpio/gpio-imx.c b/drivers/gpio/gpio-imx.c
index 1bf4100..53acb18 100644
--- a/drivers/gpio/gpio-imx.c
+++ b/drivers/gpio/gpio-imx.c
@@ -1,6 +1,4 @@
 /*
- *  arch/arm/mach-imx/gpio.c
- *
  *  author: Sascha Hauer
  *  Created: april 20th, 2004
  *  Copyright: Synertronixx GmbH
@@ -20,17 +18,11 @@
  *
  */
 
-#include <common.h>
-#include <errno.h>
-#include <io.h>
-#include <gpio.h>
 #include <init.h>
+#include <common.h>
+#include <malloc.h>
 
-struct imx_gpio_chip {
-	void __iomem *base;
-	struct gpio_chip chip;
-	struct imx_gpio_regs *regs;
-};
+#include <linux/basic_mmio_gpio.h>
 
 struct imx_gpio_regs {
 	unsigned int dr;
@@ -50,104 +42,47 @@ static struct imx_gpio_regs regs_imx31 = {
 	.psr = 0x08,
 };
 
-static void imx_gpio_set_value(struct gpio_chip *chip, unsigned gpio, int value)
-{
-	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
-	void __iomem *base = imxgpio->base;
-	u32 val;
-
-	if (!base)
-		return;
-
-	val = readl(base + imxgpio->regs->dr);
-
-	if (value)
-		val |= 1 << gpio;
-	else
-		val &= ~(1 << gpio);
-
-	writel(val, base + imxgpio->regs->dr);
-}
-
-static int imx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
-{
-	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
-	void __iomem *base = imxgpio->base;
-	u32 val;
-
-	if (!base)
-		return -EINVAL;
-
-	val = readl(base + imxgpio->regs->gdir);
-	val &= ~(1 << gpio);
-	writel(val, base + imxgpio->regs->gdir);
-
-	return 0;
-}
-
-
-static int imx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, int value)
-{
-	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
-	void __iomem *base = imxgpio->base;
-	u32 val;
-
-	gpio_set_value(gpio + chip->base, value);
-
-	val = readl(base + imxgpio->regs->gdir);
-	val |= 1 << gpio;
-	writel(val, base + imxgpio->regs->gdir);
-
-	return 0;
-}
-
-static int imx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
-{
-	struct imx_gpio_chip *imxgpio = container_of(chip, struct imx_gpio_chip, chip);
-	void __iomem *base = imxgpio->base;
-	u32 val;
-
-	val = readl(base + imxgpio->regs->psr);
-
-	return val & (1 << gpio) ? 1 : 0;
-}
-
-static struct gpio_ops imx_gpio_ops = {
-	.direction_input = imx_gpio_direction_input,
-	.direction_output = imx_gpio_direction_output,
-	.get = imx_gpio_get_value,
-	.set = imx_gpio_set_value,
-};
-
 static int imx_gpio_probe(struct device_d *dev)
 {
-	struct imx_gpio_chip *imxgpio;
 	struct imx_gpio_regs *regs;
+	struct bgpio_chip *bgc;
+	void __iomem *base;
 	int ret;
 
 	ret = dev_get_drvdata(dev, (unsigned long *)&regs);
 	if (ret)
 		return ret;
 
-	imxgpio = xzalloc(sizeof(*imxgpio));
-	imxgpio->base = dev_request_mem_region(dev, 0);
-	imxgpio->chip.ops = &imx_gpio_ops;
+	bgc = xzalloc(sizeof(*bgc));
+	if (!bgc)
+		return -ENOMEM;
+
+	base = dev_request_mem_region(dev, 0);
+	if (!base) {
+		ret = -EINVAL;
+		goto out_err;
+	}
+
+	ret = bgpio_init(bgc, dev, 4, base + regs->psr, base + regs->dr, NULL,
+			 base + regs->gdir, NULL, 0);
+	if (ret)
+		goto out_err;
+
 	if (dev->id < 0) {
-		imxgpio->chip.base = of_alias_get_id(dev->device_node, "gpio");
-		if (imxgpio->chip.base < 0)
-			return imxgpio->chip.base;
-		imxgpio->chip.base *= 32;
-	} else {
-		imxgpio->chip.base = dev->id * 32;
+		dev->id = of_alias_get_id(dev->device_node, "gpio");
+		if (dev->id < 0) {
+			ret = dev->id;
+			goto out_err;
+		}
 	}
-	imxgpio->chip.ngpio = 32;
-	imxgpio->chip.dev = dev;
-	imxgpio->regs = regs;
-	gpiochip_add(&imxgpio->chip);
+	bgc->gc.base = dev->id * 32;
+
+	return gpiochip_add(&bgc->gc);
 
-	dev_dbg(dev, "probed gpiochip%d with base %d\n", dev->id, imxgpio->chip.base);
+out_err:
+	free(bgc);
 
-	return 0;
+	return ret;
 }
 
 static __maybe_unused struct of_device_id imx_gpio_dt_ids[] = {
@@ -201,7 +136,6 @@ static struct driver_d imx_gpio_driver = {
 
 static int imx_gpio_add(void)
 {
-	platform_driver_register(&imx_gpio_driver);
-	return 0;
+	return platform_driver_register(&imx_gpio_driver);
 }
 coredevice_initcall(imx_gpio_add);
-- 
1.8.1.5



From s.trumtrar at pengutronix.de  Sun Jun  9 15:43:13 2013
From: s.trumtrar at pengutronix.de (Steffen Trumtrar)
Date: Sun,  9 Jun 2013 21:43:13 +0200
Subject: [PATCH] console: fix new console registration
Message-ID: <1370806993-28524-1-git-send-email-s.trumtrar@pengutronix.de>

The console_register-function gets the baudrate from a kconfig parameter and
sets the console accordingly, if a setbrg function is registered.
Add the missing call to setbrg on the newly registered console to actually
use the baudrate setting.

Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 common/console.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/console.c b/common/console.c
index a0a06f6..abf5322 100644
--- a/common/console.c
+++ b/common/console.c
@@ -147,6 +147,7 @@ int console_register(struct console_device *newcdev)
 		newcdev->baudrate = CONFIG_BAUDRATE;
 		dev_add_param_int(dev, "baudrate", console_baudrate_set,
 			NULL, &newcdev->baudrate, "%u", newcdev);
+		newcdev->setbrg(newcdev, newcdev->baudrate);
 	}
 
 	dev_add_param(dev, "active", console_std_set, NULL, 0);
-- 
1.8.2.rc2



From monaka at monami-ya.jp  Sun Jun  9 23:03:29 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Mon, 10 Jun 2013 12:03:29 +0900
Subject: [PATCH] Remove ftstc(). It is declared but not implemented.
Message-ID: <1370833409-1870-1-git-send-email-monaka@monami-ya.jp>

Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
---
 include/stdio.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/stdio.h b/include/stdio.h
index 5c091a8..ff2572e 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -101,7 +101,6 @@ static inline void putchar(char c)
 int	fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
 int	fputs(int file, const char *s);
 int	fputc(int file, const char c);
-int	ftstc(int file);
 int	fgetc(int file);
 
 #endif /* __STDIO_H */
-- 
1.8.3



From shc_work at mail.ru  Mon Jun 10 03:13:20 2013
From: shc_work at mail.ru (Alexander Shiyan)
Date: Mon, 10 Jun 2013 11:13:20 +0400
Subject: [PATCH 3/3] ARM: ccmx51: Return error if module is not detected
In-Reply-To: <1370848400-10380-1-git-send-email-shc_work@mail.ru>
References: <1370848400-10380-1-git-send-email-shc_work@mail.ru>
Message-ID: <1370848400-10380-3-git-send-email-shc_work@mail.ru>


Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
---
 arch/arm/boards/ccxmx51/ccxmx51.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/ccxmx51/ccxmx51.c b/arch/arm/boards/ccxmx51/ccxmx51.c
index d34759a..e60a101 100644
--- a/arch/arm/boards/ccxmx51/ccxmx51.c
+++ b/arch/arm/boards/ccxmx51/ccxmx51.c
@@ -415,7 +415,8 @@ static int ccxmx51_devices_init(void)
 		printf("Module Serial : %c%d\n", manloc, ((hwid[2] & 0x3f) << 24) | (hwid[3] << 16) | (hwid[4] << 8) | hwid[5]);
 		if ((ccxmx51_id->mem_sz - SZ_128M) > 0)
 			arm_add_mem_device("ram1", MX51_CSD0_BASE_ADDR + SZ_128M, ccxmx51_id->mem_sz - SZ_128M);
-	}
+	} else
+		return -ENOSYS;
 
 	imx51_add_uart1();
 	imx51_add_uart2();
-- 
1.8.1.5



From shc_work at mail.ru  Mon Jun 10 03:13:18 2013
From: shc_work at mail.ru (Alexander Shiyan)
Date: Mon, 10 Jun 2013 11:13:18 +0400
Subject: [PATCH 1/3] ARM: ccmx51: Export available module GPIOs to barebox
 userspace
Message-ID: <1370848400-10380-1-git-send-email-shc_work@mail.ru>

Patch will help to develop user devices connected to module, so
user can operate GPIOs in barebox console.

Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
---
 arch/arm/boards/ccxmx51/ccxmx51.c   | 24 ++++++++++++++++++++++++
 arch/arm/boards/ccxmx51/ccxmx51js.c |  1 -
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/ccxmx51/ccxmx51.c b/arch/arm/boards/ccxmx51/ccxmx51.c
index 7f92043..d34759a 100644
--- a/arch/arm/boards/ccxmx51/ccxmx51.c
+++ b/arch/arm/boards/ccxmx51/ccxmx51.c
@@ -176,6 +176,30 @@ static iomux_v3_cfg_t ccxmx51_pads[] = {
 	MX51_PAD_GPIO1_7__GPIO1_7,
 	/* MMA7455LR IRQ2 (GPIO1.6) */
 	MX51_PAD_GPIO1_6__GPIO1_6,
+	/* User GPIOs */
+	MX51_PAD_GPIO1_0__GPIO1_0,
+	MX51_PAD_GPIO1_1__GPIO1_1,
+	MX51_PAD_GPIO1_8__GPIO1_8,
+	MX51_PAD_DI1_PIN11__GPIO3_0,
+	MX51_PAD_DI1_PIN12__GPIO3_1,
+	MX51_PAD_DI1_PIN13__GPIO3_2,
+	MX51_PAD_DI1_D0_CS__GPIO3_3,
+	MX51_PAD_DI1_D1_CS__GPIO3_4,
+	MX51_PAD_DISPB2_SER_DIN__GPIO3_5,
+	MX51_PAD_DISPB2_SER_DIO__GPIO3_6,
+	MX51_PAD_DISPB2_SER_CLK__GPIO3_7,
+	MX51_PAD_DISPB2_SER_RS__GPIO3_8,
+	MX51_PAD_NANDF_RB1__GPIO3_9,
+	MX51_PAD_NANDF_RB2__GPIO3_10,
+	MX51_PAD_NANDF_RB3__GPIO3_11,
+	MX51_PAD_CSI1_D8__GPIO3_12,
+	MX51_PAD_CSI1_D9__GPIO3_13,
+	MX51_PAD_NANDF_CS1__GPIO3_17,
+	MX51_PAD_NANDF_CS2__GPIO3_18,
+	MX51_PAD_NANDF_CS3__GPIO3_19,
+	MX51_PAD_NANDF_CS4__GPIO3_20,
+	MX51_PAD_NANDF_CS5__GPIO3_21,
+	MX51_PAD_NANDF_CS6__GPIO3_22,
 };
 
 #define CCXMX51_ECSPI1_CS0	IMX_GPIO_NR(4, 24)
diff --git a/arch/arm/boards/ccxmx51/ccxmx51js.c b/arch/arm/boards/ccxmx51/ccxmx51js.c
index ae31caf..7d269c3 100644
--- a/arch/arm/boards/ccxmx51/ccxmx51js.c
+++ b/arch/arm/boards/ccxmx51/ccxmx51js.c
@@ -63,7 +63,6 @@ static iomux_v3_cfg_t ccxmx51js_pads[] = {
 	MX51_PAD_USBH1_DATA5__USBH1_DATA5,
 	MX51_PAD_USBH1_DATA6__USBH1_DATA6,
 	MX51_PAD_USBH1_DATA7__USBH1_DATA7,
-	MX51_PAD_DISPB2_SER_RS__GPIO3_8,	/* Reset */
 };
 
 static struct esdhc_platform_data sdhc1_pdata = {
-- 
1.8.1.5



From shc_work at mail.ru  Mon Jun 10 03:13:19 2013
From: shc_work at mail.ru (Alexander Shiyan)
Date: Mon, 10 Jun 2013 11:13:19 +0400
Subject: [PATCH 2/3] ARM: ccmx51js: Add WP-pin definition for SDHC3
In-Reply-To: <1370848400-10380-1-git-send-email-shc_work@mail.ru>
References: <1370848400-10380-1-git-send-email-shc_work@mail.ru>
Message-ID: <1370848400-10380-2-git-send-email-shc_work@mail.ru>


Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
---
 arch/arm/boards/ccxmx51/ccxmx51js.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boards/ccxmx51/ccxmx51js.c b/arch/arm/boards/ccxmx51/ccxmx51js.c
index 7d269c3..1cf7d53 100644
--- a/arch/arm/boards/ccxmx51/ccxmx51js.c
+++ b/arch/arm/boards/ccxmx51/ccxmx51js.c
@@ -29,7 +29,8 @@
 
 #include "ccxmx51.h"
 
-#define CCXMX51JS_USBHOST1_RESET	IMX_GPIO_NR(3, 8)
+#define CCXMX51JS_USBH1_RESET	IMX_GPIO_NR(3, 8)
+#define CCXMX51JS_SD3_WP	IMX_GPIO_NR(3, 17)
 
 static iomux_v3_cfg_t ccxmx51js_pads[] = {
 	/* SD1 */
@@ -73,7 +74,8 @@ static struct esdhc_platform_data sdhc1_pdata = {
 
 static struct esdhc_platform_data sdhc3_pdata = {
 	.cd_type	= ESDHC_CD_NONE,
-	.wp_type	= ESDHC_WP_NONE,
+	.wp_type	= ESDHC_WP_GPIO,
+	.wp_gpio	= CCXMX51JS_SD3_WP,
 	.caps		= MMC_MODE_4BIT | MMC_MODE_8BIT,
 };
 
@@ -91,9 +93,9 @@ static int ccxmx51js_init(void)
 		imx51_add_mmc2(&sdhc3_pdata);
 	}
 
-	gpio_direction_output(CCXMX51JS_USBHOST1_RESET, 0);
+	gpio_direction_output(CCXMX51JS_USBH1_RESET, 0);
 	mdelay(10);
-	gpio_set_value(CCXMX51JS_USBHOST1_RESET, 1);
+	gpio_set_value(CCXMX51JS_USBH1_RESET, 1);
 	mdelay(10);
 	imx51_add_usbh1(&ccxmx51js_usbhost1_pdata);
 
-- 
1.8.1.5



From afurmanczuk at knowtrek.com  Mon Jun 10 08:24:12 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Mon, 10 Jun 2013 14:24:12 +0200
Subject: how to flash barebox and set root variable?
In-Reply-To: <20130606162120.GA32299@pengutronix.de>
References: <51B0B2D6.3030407@knowtrek.com>
 <20130606162120.GA32299@pengutronix.de>
Message-ID: <51B5C56C.4050801@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Sascha,

> What to do next depends on the environment you have. Please send
> the output of 'ls -l /env'.


that would be:

drwxrwxrwx          0 .
drwxrwxrwx          0 ..
- -rwxrwxrwx       1230 config
drwxrwxrwx          0 bin

contents of /env/bin is:

- -rwxrwxrwx        817 _update_help
- -rwxrwxrwx        447 update_nfs
- -rwxrwxrwx       1362 update
- -rwxrwxrwx        285 mv
- -rwxrwxrwx       3445 boot
- -rwxrwxrwx        590 init
- -rwxrwxrwx         21 hush_hack
- -rwxrwxrwx        571 _boot_help
- -rwxrwxrwx        702 _update

and ls -l /dev prints:

cr-------- 4294967295 zero
crw-------  536870912 ram0
crw-------      11108 defaultenv
crw------- 4294967295 mem
crw-------         64 phy0
crw------- 3616538624 disk0
crw-------    4193792 disk0.0
crw-------   54525952 disk0.1
crw-------    8388608 nor0
crw-------     917504 self0
crw-------     131072 env0
crw-------     917504 nor0.barebox
crw-------     131072 nor0.bareboxenv
crw-------    7340032 nor0.kernel

well, have tried to make an barebox.bin start disk with the cat
barebox.bin > /dev/sdX, but not sure how to proceed to run from sd-card.

On a different try, I copied barebox.bin on a fat12 sd partition and
tried to update on the mounted partion:

update -t barebox -d nor -f barebox.bin

but the syntax is:

type update -t barebox -d <nor|nand> [-m tftp|xmodem|nfs] [-f
imagename] to update barebox into flash

"-m" does not give my disk as source, so I guess I have to get tftp to
work..

> I haven't downloaded the CD images they provide. Do you know
> whether there are barebox sources provided on the CDs?

On CD there is basically buildroot and the config files for barebox I
have attached to this mail.


Just to recall: my problem is that i do not know how to provide
"root=" parameter to my barebox environemnt. I load the zImage by
mounting partition by hand and running "bootm".

Thanks for help, Greetings,

Adam







-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG1xWwACgkQefEEI87R1Df8KwCgnaq0Vx4oEY8dQt4+LWDYhiF9
4rAAoMrMmDFZ1LivOBn2E2byd2MENiHB
=vSZi
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: barebox.mk
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20130610/e732ce52/attachment-0002.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Config.in
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20130610/e732ce52/attachment-0003.ksh>

From plagnioj at jcrosoft.com  Mon Jun 10 08:59:15 2013
From: plagnioj at jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
Date: Mon, 10 Jun 2013 14:59:15 +0200
Subject: [PATCH] console: fix new console registration
In-Reply-To: <1370806993-28524-1-git-send-email-s.trumtrar@pengutronix.de>
References: <1370806993-28524-1-git-send-email-s.trumtrar@pengutronix.de>
Message-ID: <20130610125915.GF27130@game.jcrosoft.org>

On 21:43 Sun 09 Jun     , Steffen Trumtrar wrote:
> The console_register-function gets the baudrate from a kconfig parameter and
> sets the console accordingly, if a setbrg function is registered.
> Add the missing call to setbrg on the newly registered console to actually
> use the baudrate setting.
> 
> Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
> ---
>  common/console.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/common/console.c b/common/console.c
> index a0a06f6..abf5322 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -147,6 +147,7 @@ int console_register(struct console_device *newcdev)
>  		newcdev->baudrate = CONFIG_BAUDRATE;
>  		dev_add_param_int(dev, "baudrate", console_baudrate_set,
>  			NULL, &newcdev->baudrate, "%u", newcdev);
> +		newcdev->setbrg(newcdev, newcdev->baudrate);
this need to be done at the enable not the register

Best Regards,
J.
>  	}
>  
>  	dev_add_param(dev, "active", console_std_set, NULL, 0);
> -- 
> 1.8.2.rc2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


From afurmanczuk at knowtrek.com  Mon Jun 10 13:01:30 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Mon, 10 Jun 2013 19:01:30 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <51B5C56C.4050801@knowtrek.com>
References: <51B0B2D6.3030407@knowtrek.com>
 <20130606162120.GA32299@pengutronix.de> <51B5C56C.4050801@knowtrek.com>
Message-ID: <51B6066A.5020801@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

One thing to add:

I managed to run tftpd-hpa server on my debian box and tried to update
kernel to nor0.kernel. I run:

update -t kernel -d barebox -d nor -m tftp -f barebox.bin

Which gave me output [1], obviously tftp is wrong configured. When I
mount with filesystem tftp and copy with cp I get the files.

Well I did the same with barebox, just to make sure. It also ereased
first and then complained it cannot run tftp (I had probably an
interrupt at my brain to perform that action ;) )

With barebox still in ram I tried to rescue it somehow..

So i copied barebox.bin from my tftp drive. created empty file tftp in
/env/bin and got a promising output [2], i tried to unprotect the nor
flash just to make sure.

Now where there is supposed to be barebox loading, there is nothing :)
My barebox is gone.

Thanks for comments, Greetings,

Adam




[1] barebox output update with tftp:
phy0: Link is up - 100/Full
host 192.168.10.59 is alive
cfi_protect: unprotect 0xf0100000 (size 7340032)


erasing partition /dev/nor0.kernel

	[#################################################################]

flashing barebox.bin to /dev/nor0.kernel

Unknown command 'tftp' - try 'help'



[2] barebox output update with hack:

erasing partition /dev/nor0.barebox

	[#################################################################]

flashing barebox.bin to /dev/nor0.barebox

cfi_protect: protect 0xf0000000 (size 917504)




> Hello Sascha,
> 
>> What to do next depends on the environment you have. Please send 
>> the output of 'ls -l /env'.
> 
> 
> that would be:
> 
> drwxrwxrwx          0 . drwxrwxrwx          0 .. -rwxrwxrwx
> 1230 config drwxrwxrwx          0 bin
> 
> contents of /env/bin is:
> 
> -rwxrwxrwx        817 _update_help -rwxrwxrwx        447
> update_nfs -rwxrwxrwx       1362 update -rwxrwxrwx        285 mv 
> -rwxrwxrwx       3445 boot -rwxrwxrwx        590 init -rwxrwxrwx
> 21 hush_hack -rwxrwxrwx        571 _boot_help -rwxrwxrwx        702
> _update
> 
> and ls -l /dev prints:
> 
> cr-------- 4294967295 zero crw-------  536870912 ram0 crw-------
> 11108 defaultenv crw------- 4294967295 mem crw-------         64
> phy0 crw------- 3616538624 disk0 crw-------    4193792 disk0.0 
> crw-------   54525952 disk0.1 crw-------    8388608 nor0 crw-------
> 917504 self0 crw-------     131072 env0 crw-------     917504
> nor0.barebox crw-------     131072 nor0.bareboxenv crw-------
> 7340032 nor0.kernel
> 
> well, have tried to make an barebox.bin start disk with the cat 
> barebox.bin > /dev/sdX, but not sure how to proceed to run from
> sd-card.
> 
> On a different try, I copied barebox.bin on a fat12 sd partition
> and tried to update on the mounted partion:
> 
> update -t barebox -d nor -f barebox.bin
> 
> but the syntax is:
> 
> type update -t barebox -d <nor|nand> [-m tftp|xmodem|nfs] [-f 
> imagename] to update barebox into flash
> 
> "-m" does not give my disk as source, so I guess I have to get tftp
> to work..
> 
>> I haven't downloaded the CD images they provide. Do you know 
>> whether there are barebox sources provided on the CDs?
> 
> On CD there is basically buildroot and the config files for barebox
> I have attached to this mail.
> 
> 
> Just to recall: my problem is that i do not know how to provide 
> "root=" parameter to my barebox environemnt. I load the zImage by 
> mounting partition by hand and running "bootm".
> 
> Thanks for help, Greetings,
> 
> Adam
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________ barebox mailing
> list barebox at lists.infradead.org 
> http://lists.infradead.org/mailman/listinfo/barebox

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG2BmkACgkQefEEI87R1DeEcgCeJixbOwIsMm82PQcLp2AmAzW5
uDkAoNg84RmdVE/n+4T28rHavEQUXjRx
=5A2e
-----END PGP SIGNATURE-----


From shc_work at mail.ru  Mon Jun 10 13:07:08 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Mon, 10 Jun 2013 21:07:08 +0400
Subject: =?UTF-8?B?UmVbMl06IGhvdyB0byBmbGFzaCBiYXJlYm94IGFuZCBzZXQgcm9vdCB2YXJp?=
 =?UTF-8?B?YWJsZT8gLSBiYXJlYm94IGlzIGdvbmUgOig=?=
In-Reply-To: <51B6066A.5020801@knowtrek.com>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com>
Message-ID: <1370884028.154515180@f150.mail.ru>

> One thing to add:
> 
> I managed to run tftpd-hpa server on my debian box and tried to update
> kernel to nor0.kernel. I run:
...
> flashing barebox.bin to /dev/nor0.kernel
> 
> Unknown command 'tftp' - try 'help'

Seems tftp command is not compiled in.
Ensure that you have CONFIG_CMD_TFTP in your .config.

---

From afurmanczuk at knowtrek.com  Mon Jun 10 13:23:33 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Mon, 10 Jun 2013 19:23:33 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <1370884028.154515180@f150.mail.ru>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
Message-ID: <51B60B95.8020506@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10.06.2013 19:07, Alexander Shiyan wrote:
>> flashing barebox.bin to /dev/nor0.kernel
>>> 
>>> Unknown command 'tftp' - try 'help'
> Seems tftp command is not compiled in. Ensure that you have 
> CONFIG_CMD_TFTP in your .config.

Thanks Alexander,

but my barebox binary is gone :(. Have been a bit careles... I would
need to flash the binary over my OCD USB controller, but do not realy
have a clue how to do this.
I am waiting for support reply for this ICnova iMX536 SODIMM module,
they should give me some steps how to proceed.

Greetings,

Adam
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG2C5UACgkQefEEI87R1DcmMQCgzewtZOLF4TdLAi423jakmXJD
z2MAn2UMQcaanApXDsN1OgG2K/MstNeS
=b4s4
-----END PGP SIGNATURE-----


From s.hauer at pengutronix.de  Mon Jun 10 13:29:01 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 10 Jun 2013 19:29:01 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <51B60B95.8020506@knowtrek.com>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
 <51B60B95.8020506@knowtrek.com>
Message-ID: <20130610172901.GN32299@pengutronix.de>

On Mon, Jun 10, 2013 at 07:23:33PM +0200, Adam Furmanczuk wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 10.06.2013 19:07, Alexander Shiyan wrote:
> >> flashing barebox.bin to /dev/nor0.kernel
> >>> 
> >>> Unknown command 'tftp' - try 'help'
> > Seems tftp command is not compiled in. Ensure that you have 
> > CONFIG_CMD_TFTP in your .config.
> 
> Thanks Alexander,
> 
> but my barebox binary is gone :(. Have been a bit careles... I would
> need to flash the binary over my OCD USB controller, but do not realy
> have a clue how to do this.
> I am waiting for support reply for this ICnova iMX536 SODIMM module,
> they should give me some steps how to proceed.

Connect your board via USB to a host. Do you see a device? If yes,
enable CONFIG_ARCH_IMX_USBLOADER in a recent barebox. After compiling
you will have scripts/imx/imx-usb-loader which you can use to recover
via USB.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From jlu at pengutronix.de  Mon Jun 10 15:31:20 2013
From: jlu at pengutronix.de (Jan Luebbe)
Date: Mon, 10 Jun 2013 21:31:20 +0200
Subject: [PATCH] arm: omap: am33xx: set up SPI devices
Message-ID: <1370892680-13254-1-git-send-email-jlu@pengutronix.de>

Signed-off-by: Jan Luebbe <jlu at pengutronix.de>
---
 arch/arm/mach-omap/include/mach/am33xx-devices.h | 17 +++++++++++++++++
 arch/arm/mach-omap/include/mach/am33xx-silicon.h |  4 ++++
 drivers/spi/Kconfig                              |  2 +-
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap/include/mach/am33xx-devices.h b/arch/arm/mach-omap/include/mach/am33xx-devices.h
index fe9fba9..cea4504 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-devices.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-devices.h
@@ -7,6 +7,7 @@
 #include <mach/devices.h>
 #include <mach/omap_hsmmc.h>
 #include <mach/cpsw.h>
+#include <mach/omap_hsmmc.h>
 
 /* the device numbering is the same as in the TRM memory map (SPRUH73G) */
 
@@ -37,4 +38,20 @@ static inline struct device_d *am33xx_add_cpsw(struct cpsw_platform_data *cpsw_d
 			AM335X_CPSW_BASE, SZ_32K, IORESOURCE_MEM, cpsw_data);
 }
 
+static inline struct device_d *am33xx_add_spi(int id, resource_size_t start)
+{
+	return add_generic_device("omap3_spi", id, NULL, start + 0x100, SZ_4K - 0x100,
+				   IORESOURCE_MEM, NULL);
+}
+
+static inline struct device_d *am33xx_add_spi0(void)
+{
+	return am33xx_add_spi(0, AM33XX_MCSPI0_BASE);
+}
+
+static inline struct device_d *am33xx_add_spi1(void)
+{
+	return am33xx_add_spi(1, AM33XX_MCSPI1_BASE);
+}
+
 #endif /* __MACH_OMAP3_DEVICES_H */
diff --git a/arch/arm/mach-omap/include/mach/am33xx-silicon.h b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
index 9edf4ca..59284af 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-silicon.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
@@ -49,6 +49,10 @@
 #define AM33XX_MMC1_BASE		(AM33XX_L4_PER_BASE + 0x1D8000)
 #define AM33XX_MMCHS2_BASE		0x47810000
 
+/* SPI */
+#define AM33XX_MCSPI0_BASE		(AM33XX_L4_PER_BASE + 0x30000)
+#define AM33XX_MCSPI1_BASE		(AM33XX_L4_PER_BASE + 0x1A0000)
+
 /* DTMTimer0 */
 #define AM33XX_DMTIMER0_BASE		(AM33XX_L4_WKUP_BASE + 0x205000)
 
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index f14e28f..c279c21 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -40,7 +40,7 @@ config DRIVER_SPI_MXS
 
 config DRIVER_SPI_OMAP3
 	bool "OMAP3 McSPI Master driver"
-	depends on ARCH_OMAP3
+	depends on ARCH_OMAP3 || ARCH_AM33XX
 
 endif
 
-- 
1.8.2.rc2



From afurmanczuk at knowtrek.com  Tue Jun 11 04:10:37 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Tue, 11 Jun 2013 10:10:37 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <20130610172901.GN32299@pengutronix.de>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
 <51B60B95.8020506@knowtrek.com> <20130610172901.GN32299@pengutronix.de>
Message-ID: <51B6DB7D.1070208@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10.06.2013 19:29, Sascha Hauer wrote:
> On Mon, Jun 10, 2013 at 07:23:33PM +0200, Adam Furmanczuk wrote:
>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>>> 
>>> On 10.06.2013 19:07, Alexander Shiyan wrote:
>>>>>>> flashing barebox.bin to /dev/nor0.kernel
>>>>>>>>> 
>>>>>>>>> Unknown command 'tftp' - try 'help'
>>>>> Seems tftp command is not compiled in. Ensure that you
>>>>> have CONFIG_CMD_TFTP in your .config.
>>> 
>>> Thanks Alexander,
>>> 
>>> but my barebox binary is gone :(. Have been a bit careles... I 
>>> would need to flash the binary over my OCD USB controller, but 
>>> do not realy have a clue how to do this. I am waiting for 
>>> support reply for this ICnova iMX536 SODIMM module, they
>>> should give me some steps how to proceed.
> Connect your board via USB to a host. Do you see a device? If yes,
>  enable CONFIG_ARCH_IMX_USBLOADER in a recent barebox. After 
> compiling you will have scripts/imx/imx-usb-loader which you can 
> use to recover via USB.

Hi Sascha,

thanks for the advice. I am tommorrow at work. Will perform that steps
and report back.

Thanks,

Adam
- -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG2214ACgkQefEEI87R1DeQxgCgvJoqZjLVZwfEq90BUqXLmv1Y
1OcAoNPZEn7O1QYVl05081VxI0UzxqFQ
=vf6E
- -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG223wACgkQefEEI87R1DfOiQCgwpMHl2gh0vPF5uo9QFCPboRR
zeIAoJUMmLpPjGr93he4NBfJ4dQpC3XP
=zkjp
-----END PGP SIGNATURE-----


From sebastian.hesselbarth at gmail.com  Tue Jun 11 05:33:06 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 11 Jun 2013 11:33:06 +0200
Subject: [PATCH] of: add ranges address translation for default bus
In-Reply-To: <20130519073403.GY32299@pengutronix.de>
References: <1368400146-30443-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130519073403.GY32299@pengutronix.de>
Message-ID: <51B6EED2.3010707@gmail.com>

On 05/19/13 09:34, Sascha Hauer wrote:
> Hi Sebastian,
>
> On Mon, May 13, 2013 at 01:09:06AM +0200, Sebastian Hesselbarth wrote:
>> This patch adds address translation for default bus types. It has been
>> shamelessly ported from Linux device tree address translation with the
>> following exceptions:
>> - only default bus map and translate are supported
>> - of_bus has not been ported
>> - check for #size-cells > 0 has been removed
>>
>> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
>
> I just gave this one a test.
>
> First of all you dropped 1:1 translation, see the attached fixup.
>
> Then, since this code duplicates the majority of drivers/of/address.c,
> would it make sense to move it to the same file in barebox aswell?

Sascha,

coming back to this I am wondering if a full sync of linux' drivers/of
with barebox' drivers/of should be done. IMHO at least for the core
stuff (base/address/fdt) it makes sense, of_* can come later if
required.

I started merging already, and from what I can see we should just remove
the spinlocks and OF_DYNAMIC stuff (but leave of_node_get/_put as stubs)

Sebastian


From s.hauer at pengutronix.de  Tue Jun 11 11:26:14 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Jun 2013 17:26:14 +0200
Subject: [PATCH] ARM: pcm038: Fix partition size definitions
In-Reply-To: <1370767208-22789-1-git-send-email-shc_work@mail.ru>
References: <1370767208-22789-1-git-send-email-shc_work@mail.ru>
Message-ID: <20130611152614.GO32299@pengutronix.de>

On Sun, Jun 09, 2013 at 12:40:08PM +0400, Alexander Shiyan wrote:
> 
> Signed-off-by: Alexander Shiyan <shc_work at mail.ru>

Applied, though I really had liked some hint what was wrong with the
partition sizes.

Sascha

> ---
>  arch/arm/boards/pcm038/pcm038.c | 18 ++++++++----------
>  1 file changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
> index 372aea5..49677c2 100644
> --- a/arch/arm/boards/pcm038/pcm038.c
> +++ b/arch/arm/boards/pcm038/pcm038.c
> @@ -332,22 +332,20 @@ static int pcm038_devices_init(void)
>  
>  	switch (bootsource_get()) {
>  	case BOOTSOURCE_NAND:
> -		devfs_add_partition("nand0", 0x00000, 0x80000,
> -					DEVFS_PARTITION_FIXED, "self_raw");
> +		devfs_add_partition("nand0", 0, SZ_512K,
> +				    DEVFS_PARTITION_FIXED, "self_raw");
>  		dev_add_bb_dev("self_raw", "self0");
> -
> -		devfs_add_partition("nand0", 0x80000, 0x100000,
> -					DEVFS_PARTITION_FIXED, "env_raw");
> +		devfs_add_partition("nand0", SZ_512K, SZ_128K,
> +				    DEVFS_PARTITION_FIXED, "env_raw");
>  		dev_add_bb_dev("env_raw", "env0");
>  		envdev = "NAND";
>  		break;
>  	default:
> -		devfs_add_partition("nor0", 0x00000, 0x80000,
> -					DEVFS_PARTITION_FIXED, "self0");
> -		devfs_add_partition("nor0", 0x80000, 0x100000,
> -					DEVFS_PARTITION_FIXED, "env0");
> +		devfs_add_partition("nor0", 0, SZ_512K,
> +				    DEVFS_PARTITION_FIXED, "self0");
> +		devfs_add_partition("nor0", SZ_512K, SZ_128K,
> +				    DEVFS_PARTITION_FIXED, "env0");
>  		protect_file("/dev/env0", 1);
> -
>  		envdev = "NOR";
>  	}
>  
> -- 
> 1.8.1.5
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Jun 11 11:27:47 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Jun 2013 17:27:47 +0200
Subject: [PATCH] ARM: pcm038: Avoid warning if gadget support not
 compiled in
In-Reply-To: <1370773361-25588-1-git-send-email-shc_work@mail.ru>
References: <1370773361-25588-1-git-send-email-shc_work@mail.ru>
Message-ID: <20130611152747.GP32299@pengutronix.de>

On Sun, Jun 09, 2013 at 02:22:41PM +0400, Alexander Shiyan wrote:
> 
> Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
> ---
>  arch/arm/boards/pcm038/pcm038.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
> index 49677c2..dec5164 100644
> --- a/arch/arm/boards/pcm038/pcm038.c
> +++ b/arch/arm/boards/pcm038/pcm038.c
> @@ -328,7 +328,8 @@ static int pcm038_devices_init(void)
>  	mdelay(1);
>  	imx_gpio_mode(PE1_PF_USBOTG_STP);
>  
> -	imx27_add_usbotg(&pcm038_otg_pdata);
> +	if (IS_ENABLED(CONFIG_USB_GADGET_DRIVER_ARC))
> +		imx27_add_usbotg(&pcm038_otg_pdata);

What warning do you get without this patch?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Jun 11 11:29:08 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Jun 2013 17:29:08 +0200
Subject: [PATCH] Remove ftstc(). It is declared but not implemented.
In-Reply-To: <1370833409-1870-1-git-send-email-monaka@monami-ya.jp>
References: <1370833409-1870-1-git-send-email-monaka@monami-ya.jp>
Message-ID: <20130611152908.GQ32299@pengutronix.de>

On Mon, Jun 10, 2013 at 12:03:29PM +0900, Masaki Muranaka wrote:
> Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>

I applied it already.

Sascha

> ---
>  include/stdio.h | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/include/stdio.h b/include/stdio.h
> index 5c091a8..ff2572e 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -101,7 +101,6 @@ static inline void putchar(char c)
>  int	fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
>  int	fputs(int file, const char *s);
>  int	fputc(int file, const char c);
> -int	ftstc(int file);
>  int	fgetc(int file);
>  
>  #endif /* __STDIO_H */
> -- 
> 1.8.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Jun 11 11:33:05 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 11 Jun 2013 17:33:05 +0200
Subject: [PATCH 1/3] ARM: ccmx51: Export available module GPIOs to
 barebox userspace
In-Reply-To: <1370848400-10380-1-git-send-email-shc_work@mail.ru>
References: <1370848400-10380-1-git-send-email-shc_work@mail.ru>
Message-ID: <20130611153305.GR32299@pengutronix.de>

On Mon, Jun 10, 2013 at 11:13:18AM +0400, Alexander Shiyan wrote:
> Patch will help to develop user devices connected to module, so
> user can operate GPIOs in barebox console.
> 
> Signed-off-by: Alexander Shiyan <shc_work at mail.ru>

Applied, thanks

Sascha

> ---
>  arch/arm/boards/ccxmx51/ccxmx51.c   | 24 ++++++++++++++++++++++++
>  arch/arm/boards/ccxmx51/ccxmx51js.c |  1 -
>  2 files changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/boards/ccxmx51/ccxmx51.c b/arch/arm/boards/ccxmx51/ccxmx51.c
> index 7f92043..d34759a 100644
> --- a/arch/arm/boards/ccxmx51/ccxmx51.c
> +++ b/arch/arm/boards/ccxmx51/ccxmx51.c
> @@ -176,6 +176,30 @@ static iomux_v3_cfg_t ccxmx51_pads[] = {
>  	MX51_PAD_GPIO1_7__GPIO1_7,
>  	/* MMA7455LR IRQ2 (GPIO1.6) */
>  	MX51_PAD_GPIO1_6__GPIO1_6,
> +	/* User GPIOs */
> +	MX51_PAD_GPIO1_0__GPIO1_0,
> +	MX51_PAD_GPIO1_1__GPIO1_1,
> +	MX51_PAD_GPIO1_8__GPIO1_8,
> +	MX51_PAD_DI1_PIN11__GPIO3_0,
> +	MX51_PAD_DI1_PIN12__GPIO3_1,
> +	MX51_PAD_DI1_PIN13__GPIO3_2,
> +	MX51_PAD_DI1_D0_CS__GPIO3_3,
> +	MX51_PAD_DI1_D1_CS__GPIO3_4,
> +	MX51_PAD_DISPB2_SER_DIN__GPIO3_5,
> +	MX51_PAD_DISPB2_SER_DIO__GPIO3_6,
> +	MX51_PAD_DISPB2_SER_CLK__GPIO3_7,
> +	MX51_PAD_DISPB2_SER_RS__GPIO3_8,
> +	MX51_PAD_NANDF_RB1__GPIO3_9,
> +	MX51_PAD_NANDF_RB2__GPIO3_10,
> +	MX51_PAD_NANDF_RB3__GPIO3_11,
> +	MX51_PAD_CSI1_D8__GPIO3_12,
> +	MX51_PAD_CSI1_D9__GPIO3_13,
> +	MX51_PAD_NANDF_CS1__GPIO3_17,
> +	MX51_PAD_NANDF_CS2__GPIO3_18,
> +	MX51_PAD_NANDF_CS3__GPIO3_19,
> +	MX51_PAD_NANDF_CS4__GPIO3_20,
> +	MX51_PAD_NANDF_CS5__GPIO3_21,
> +	MX51_PAD_NANDF_CS6__GPIO3_22,
>  };
>  
>  #define CCXMX51_ECSPI1_CS0	IMX_GPIO_NR(4, 24)
> diff --git a/arch/arm/boards/ccxmx51/ccxmx51js.c b/arch/arm/boards/ccxmx51/ccxmx51js.c
> index ae31caf..7d269c3 100644
> --- a/arch/arm/boards/ccxmx51/ccxmx51js.c
> +++ b/arch/arm/boards/ccxmx51/ccxmx51js.c
> @@ -63,7 +63,6 @@ static iomux_v3_cfg_t ccxmx51js_pads[] = {
>  	MX51_PAD_USBH1_DATA5__USBH1_DATA5,
>  	MX51_PAD_USBH1_DATA6__USBH1_DATA6,
>  	MX51_PAD_USBH1_DATA7__USBH1_DATA7,
> -	MX51_PAD_DISPB2_SER_RS__GPIO3_8,	/* Reset */
>  };
>  
>  static struct esdhc_platform_data sdhc1_pdata = {
> -- 
> 1.8.1.5
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From shc_work at mail.ru  Tue Jun 11 11:54:23 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Tue, 11 Jun 2013 19:54:23 +0400
Subject: =?UTF-8?B?UmVbMl06IFtQQVRDSF0gQVJNOiBwY20wMzg6IEF2b2lkIHdhcm5pbmcgaWYg?=
 =?UTF-8?B?Z2FkZ2V0IHN1cHBvcnQgbm90IGNvbXBpbGVkIGlu?=
In-Reply-To: <20130611152747.GP32299@pengutronix.de>
References: <1370773361-25588-1-git-send-email-shc_work@mail.ru>
 <20130611152747.GP32299@pengutronix.de>
Message-ID: <1370966063.553147631@f314.mail.ru>

> On Sun, Jun 09, 2013 at 02:22:41PM +0400, Alexander Shiyan wrote:
> > 
> > Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
> > ---
> >  arch/arm/boards/pcm038/pcm038.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
> > index 49677c2..dec5164 100644
> > --- a/arch/arm/boards/pcm038/pcm038.c
> > +++ b/arch/arm/boards/pcm038/pcm038.c
> > @@ -328,7 +328,8 @@ static int pcm038_devices_init(void)
> >  	mdelay(1);
> >  	imx_gpio_mode(PE1_PF_USBOTG_STP);
> >  
> > -	imx27_add_usbotg(&pcm038_otg_pdata);
> > +	if (IS_ENABLED(CONFIG_USB_GADGET_DRIVER_ARC))
> > +		imx27_add_usbotg(&pcm038_otg_pdata);
> 
> What warning do you get without this patch?

Runtime warning "No supported role" from chipidea driver.

---

From monaka at monami-ya.jp  Wed Jun 12 01:50:36 2013
From: monaka at monami-ya.jp (Masaki Muranaka)
Date: Wed, 12 Jun 2013 14:50:36 +0900
Subject: [PATCH] Remove ftstc(). It is declared but not implemented.
In-Reply-To: <20130611152908.GQ32299@pengutronix.de>
References: <1370833409-1870-1-git-send-email-monaka@monami-ya.jp>
 <20130611152908.GQ32299@pengutronix.de>
Message-ID: <CAJBvFxOZn_S-vphXiNhyJmMobAonMmjFUOj_vSsaYwvTe4C+MQ@mail.gmail.com>

Hello,

I couldn't find it on master branch at git://git.pengutronix.de/git/barebox.git.
You mean it was applied but not pushed yet?

2013/6/12 Sascha Hauer <s.hauer at pengutronix.de>:
> On Mon, Jun 10, 2013 at 12:03:29PM +0900, Masaki Muranaka wrote:
>> Signed-off-by: Masaki Muranaka <monaka at monami-ya.jp>
>
> I applied it already.
>
> Sascha
>
>> ---
>>  include/stdio.h | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/include/stdio.h b/include/stdio.h
>> index 5c091a8..ff2572e 100644
>> --- a/include/stdio.h
>> +++ b/include/stdio.h
>> @@ -101,7 +101,6 @@ static inline void putchar(char c)
>>  int  fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
>>  int  fputs(int file, const char *s);
>>  int  fputc(int file, const char c);
>> -int  ftstc(int file);
>>  int  fgetc(int file);
>>
>>  #endif /* __STDIO_H */
>> --
>> 1.8.3
>>
>>
>> _______________________________________________
>> barebox mailing list
>> barebox at lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/barebox
>>
>
> --
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



-- 
--
Masaki Muranaka
Monami-ya LLC, Japan.


From afurmanczuk at knowtrek.com  Wed Jun 12 02:12:15 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Wed, 12 Jun 2013 08:12:15 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <20130610172901.GN32299@pengutronix.de>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
 <51B60B95.8020506@knowtrek.com> <20130610172901.GN32299@pengutronix.de>
Message-ID: <51B8113F.2050207@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10.06.2013 19:29, Sascha Hauer wrote:
> On Mon, Jun 10, 2013 at 07:23:33PM +0200, Adam Furmanczuk wrote:
>> On 10.06.2013 19:07, Alexander Shiyan wrote:
>>>> flashing barebox.bin to /dev/nor0.kernel
>>>>> Unknown command 'tftp' - try 'help'
>>> Seems tftp command is not compiled in. Ensure that you have 
>>> CONFIG_CMD_TFTP in your .config.
>> Thanks Alexander,
>> 
>> but my barebox binary is gone . Have been a bit careles... I 
>> would need to flash the binary over my OCD USB controller, but
>> do not realy have a clue how to do this. I am waiting for
>> support reply for this ICnova iMX536 SODIMM module, they should
>> give me some steps how to proceed.
> [...] CONFIG_ARCH_IMX_USBLOADER in a recent barebox. After 
> compiling you will have scripts/imx/imx-usb-loader

Hi Sascha,

I have included the option: CONFIG_ARCH_IMX_USBLOADER=y
then run make clean and then make again, but there is no such file,
tried to search recursively for similar file in barebox top directory
with: find ./ -iname \*usb-loader\*

My barebox version is 2013.06.0.

Greetings,

Adam
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG4ET8ACgkQefEEI87R1DevIACfUbLM6uGz+zbhkDdbrjQocGa5
qBAAoK1WY7dMzIARnpvBlXKSAgIrJ5Cm
=dKAZ
-----END PGP SIGNATURE-----


From J.Weitzel at phytec.de  Wed Jun 12 03:14:39 2013
From: J.Weitzel at phytec.de (Jan Weitzel)
Date: Wed, 12 Jun 2013 09:14:39 +0200
Subject: [PATCH] OMAP4: Use default clock source for mcbsp
In-Reply-To: <20130608131315.GC26150@pengutronix.de>
References: <1369741903-24988-2-git-send-email-j.weitzel@phytec.de>
 <20130608131315.GC26150@pengutronix.de>
Message-ID: <1371021279.4131.1.camel@lws-weitzel>

Am Samstag, den 08.06.2013, 15:13 +0200 schrieb Sascha Hauer:
> On Tue, May 28, 2013 at 01:51:40PM +0200, Jan Weitzel wrote:
> > In omap4_enable_all_clocks we not only enable the mcbsp clocks, but also
> > change the source from ABE_24M_FCLK to 24M_FCLK. Revert this and default
> > to the reset state.
> > 
> > Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
> 
> Applied, thanks
Didn't find it on next or master branch. Is rework needed?

Jan

> Sascha
> 
> > ---
> >  arch/arm/mach-omap/omap4_clock.c |    6 +++---
> >  1 files changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arch/arm/mach-omap/omap4_clock.c b/arch/arm/mach-omap/omap4_clock.c
> > index 0621fd3..889d1f9 100644
> > --- a/arch/arm/mach-omap/omap4_clock.c
> > +++ b/arch/arm/mach-omap/omap4_clock.c
> > @@ -253,9 +253,9 @@ void omap4_enable_all_clocks(void)
> >  	sr32(CM1_ABE_PDM_CLKCTRL, 0, 32, 0x2);
> >  	sr32(CM1_ABE_DMIC_CLKCTRL, 0, 32, 0x2);
> >  	sr32(CM1_ABE_MCASP_CLKCTRL, 0, 32, 0x2);
> > -	sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x08000002);
> > -	sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x08000002);
> > -	sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x08000002);
> > +	sr32(CM1_ABE_MCBSP1_CLKCTRL, 0, 32, 0x2);
> > +	sr32(CM1_ABE_MCBSP2_CLKCTRL, 0, 32, 0x2);
> > +	sr32(CM1_ABE_MCBSP3_CLKCTRL, 0, 32, 0x2);
> >  	sr32(CM1_ABE_SLIMBUS_CLKCTRL, 0, 32, 0xf02);
> >  	sr32(CM1_ABE_TIMER5_CLKCTRL, 0, 32, 0x2);
> >  	sr32(CM1_ABE_TIMER6_CLKCTRL, 0, 32, 0x2);
> > -- 
> > 1.7.0.4
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> > 
> 




From J.Weitzel at phytec.de  Wed Jun 12 03:16:45 2013
From: J.Weitzel at phytec.de (Jan Weitzel)
Date: Wed, 12 Jun 2013 09:16:45 +0200
Subject: [PATCH v2] omap4: set voltage according to mpu freq
In-Reply-To: <20130608132138.GI32299@pengutronix.de>
References: <1370425962.3824.1.camel@lws-weitzel>
 <1370522836-11258-1-git-send-email-j.weitzel@phytec.de>
 <CAGo_u6rixBCzggcuLAfOLuxgTrzyDhY7ipf2garfTiDb_Ce0WA@mail.gmail.com>
 <20130608132138.GI32299@pengutronix.de>
Message-ID: <1371021405.4131.3.camel@lws-weitzel>

Am Samstag, den 08.06.2013, 15:21 +0200 schrieb Sascha Hauer:
> On Thu, Jun 06, 2013 at 08:40:46AM -0500, menon.nishanth at gmail.com wrote:
> > On Thu, Jun 6, 2013 at 7:47 AM, Jan Weitzel <j.weitzel at phytec.de> wrote:
> > > +noinline int omap4460_scale_vcores(unsigned vsel0_pin, unsigned volt_mv)
> > > +{
> > > +       void __iomem *base;
> > > +       u32 val = 0;
> > > +
> > > +       /* For VC bypass only VCOREx_CGF_FORCE  is necessary and
> > > +        * VCOREx_CFG_VOLTAGE  changes can be discarded
> > > +        */
> > > +       writel(0, OMAP44XX_PRM_VC_CFG_I2C_MODE);
> > > +       writel(0x6026, OMAP44XX_PRM_VC_CFG_I2C_CLK);
> > > +
> > > +       /* TPS - supplies vdd_mpu on 4460
> > > +        * Setup SET1 and SET0 with right values so that kernel
> > > +        * can use either of them based on its needs.
> > > +        */
> > > +
> > > +       omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, volt_mv);
> > Just a nitpick - the general rule of TPS+OMAP4460 integration is *NOT*
> > to program SET0 register. this is intended to be at boot voltage
> > required to be used when reboot due to s/w controlled or h/w watchdog.
> 
> So this line should simply be removed?
> 
> Ok, this line is only moved and not introduced in this patch, so it
> should be fine to apply this patch and leave this for a separate patch.
I create a separate patch. I had the problem that our gpio module
(gpio6) goes low due to a reset at init time. Must fix this in kernel.

Jan
> 
> Sascha
> 




From j.weitzel at phytec.de  Wed Jun 12 03:17:44 2013
From: j.weitzel at phytec.de (Jan Weitzel)
Date: Wed, 12 Jun 2013 09:17:44 +0200
Subject: [PATCH] OMAP4 do not set TPS62361_REG_ADDR_SET0
Message-ID: <1371021464-2390-1-git-send-email-j.weitzel@phytec.de>

Don't set SET0 voltage, because it acts as boot voltage for OPP boot.
Take care that the kernel doesn't drive vset gpio to low. This may
happen while reseting the gpio module at initialization, look for
HWMOD_INIT_NO_RESET.

Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
---
 arch/arm/mach-omap/omap4_generic.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-omap/omap4_generic.c b/arch/arm/mach-omap/omap4_generic.c
index 7200393..bf1f1a7 100644
--- a/arch/arm/mach-omap/omap4_generic.c
+++ b/arch/arm/mach-omap/omap4_generic.c
@@ -586,11 +586,10 @@ noinline int omap4460_scale_vcores(unsigned vsel0_pin, unsigned volt_mv)
 	writel(0x6026, OMAP44XX_PRM_VC_CFG_I2C_CLK);
 
 	/* TPS - supplies vdd_mpu on 4460
-	 * Setup SET1 and SET0 with right values so that kernel
-	 * can use either of them based on its needs.
+	 * Setup SET1 and don't touch SET0 it acts as boot voltage
+	 * source after reset.
 	 */
 
-	omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, volt_mv);
 	omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET1, volt_mv);
 
 	/*
-- 
1.7.0.4



From afurmanczuk at knowtrek.com  Wed Jun 12 03:19:48 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Wed, 12 Jun 2013 09:19:48 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <51B8113F.2050207@knowtrek.com>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
 <51B60B95.8020506@knowtrek.com> <20130610172901.GN32299@pengutronix.de>
 <51B8113F.2050207@knowtrek.com>
Message-ID: <51B82114.7080004@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12.06.2013 08:12, Adam Furmanczuk wrote:
> ********* *POCZATEK CZESCI SZYFROWANEJ / PODPISANEJ* *********
> 
> On 10.06.2013 19:29, Sascha Hauer wrote:
>>> On Mon, Jun 10, 2013 at 07:23:33PM +0200, Adam Furmanczuk
>>> wrote:
>>>>> On 10.06.2013 19:07, Alexander Shiyan wrote:
>>>>>>>>> flashing barebox.bin to /dev/nor0.kernel
>>>>>>>>>>> Unknown command 'tftp' - try 'help'
>>>>>>> Seems tftp command is not compiled in. Ensure that you
>>>>>>> have CONFIG_CMD_TFTP in your .config.
>>>>> Thanks Alexander,
>>>>> 
>>>>> but my barebox binary is gone . Have been a bit careles...
>>>>> I would need to flash the binary over my OCD USB
>>>>> controller, but do not realy have a clue how to do this. I
>>>>> am waiting for support reply for this ICnova iMX536 SODIMM
>>>>> module, they should give me some steps how to proceed.
>>> [...] CONFIG_ARCH_IMX_USBLOADER in a recent barebox. After 
>>> compiling you will have scripts/imx/imx-usb-loader
> Hi Sascha,
> 
> I have included the option: CONFIG_ARCH_IMX_USBLOADER=y then run
> make clean and then make again, but there is no such file, tried to
> search recursively for similar file in barebox top directory with:
> find ./ -iname \*usb-loader\*
> 

My bad, i got the latest git snaphot (699-bcc9) and there is
USBLOADER.. have still some issues with compiling it.
There is "memory bank" error [1]. Have seen there was a patch
recently, but do not know the option to enable/disable


Thanks for Help,

Adam

[1]

barebox-699bcc9/drivers/of/base.c:961: undefined reference to
`of_add_memory_bank'
collect2: error: ld returned 1 exit status


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG4IRQACgkQefEEI87R1DdyrACePOugMudNLfCdfdMlsV80V1G2
kdAAoOgUWRJtp0cUMg8V0Fcj4Aie56eB
=07oc
-----END PGP SIGNATURE-----


From s.hauer at pengutronix.de  Wed Jun 12 04:07:47 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Jun 2013 10:07:47 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <51B82114.7080004@knowtrek.com>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
 <51B60B95.8020506@knowtrek.com>
 <20130610172901.GN32299@pengutronix.de>
 <51B8113F.2050207@knowtrek.com> <51B82114.7080004@knowtrek.com>
Message-ID: <20130612080747.GV32299@pengutronix.de>

On Wed, Jun 12, 2013 at 09:19:48AM +0200, Adam Furmanczuk wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 12.06.2013 08:12, Adam Furmanczuk wrote:
> > ********* *POCZATEK CZESCI SZYFROWANEJ / PODPISANEJ* *********
> > 
> > On 10.06.2013 19:29, Sascha Hauer wrote:
> >>> On Mon, Jun 10, 2013 at 07:23:33PM +0200, Adam Furmanczuk
> >>> wrote:
> >>>>> On 10.06.2013 19:07, Alexander Shiyan wrote:
> >>>>>>>>> flashing barebox.bin to /dev/nor0.kernel
> >>>>>>>>>>> Unknown command 'tftp' - try 'help'
> >>>>>>> Seems tftp command is not compiled in. Ensure that you
> >>>>>>> have CONFIG_CMD_TFTP in your .config.
> >>>>> Thanks Alexander,
> >>>>> 
> >>>>> but my barebox binary is gone . Have been a bit careles...
> >>>>> I would need to flash the binary over my OCD USB
> >>>>> controller, but do not realy have a clue how to do this. I
> >>>>> am waiting for support reply for this ICnova iMX536 SODIMM
> >>>>> module, they should give me some steps how to proceed.
> >>> [...] CONFIG_ARCH_IMX_USBLOADER in a recent barebox. After 
> >>> compiling you will have scripts/imx/imx-usb-loader
> > Hi Sascha,
> > 
> > I have included the option: CONFIG_ARCH_IMX_USBLOADER=y then run
> > make clean and then make again, but there is no such file, tried to
> > search recursively for similar file in barebox top directory with:
> > find ./ -iname \*usb-loader\*
> > 
> 
> My bad, i got the latest git snaphot (699-bcc9) and there is
> USBLOADER.. have still some issues with compiling it.
> There is "memory bank" error [1]. Have seen there was a patch
> recently, but do not know the option to enable/disable

When CONFIG_ARCH_IMX_USBLOADER is enabled in your config you can do:

make scripts/imx/

This should build the tool only.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From afurmanczuk at knowtrek.com  Wed Jun 12 04:22:48 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Wed, 12 Jun 2013 10:22:48 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <20130612080747.GV32299@pengutronix.de>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
 <51B60B95.8020506@knowtrek.com> <20130610172901.GN32299@pengutronix.de>
 <51B8113F.2050207@knowtrek.com> <51B82114.7080004@knowtrek.com>
 <20130612080747.GV32299@pengutronix.de>
Message-ID: <51B82FD8.30108@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12.06.2013 10:07, Sascha Hauer wrote:
> On Wed, Jun 12, 2013 at 09:19:48AM +0200, Adam Furmanczuk wrote:
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>> 
>> On 12.06.2013 08:12, Adam Furmanczuk wrote:
>>> ********* *POCZATEK CZESCI SZYFROWANEJ / PODPISANEJ* *********
>>> 
>>> On 10.06.2013 19:29, Sascha Hauer wrote:
>>>>> On Mon, Jun 10, 2013 at 07:23:33PM +0200, Adam Furmanczuk 
>>>>> wrote:
>>>>>>> On 10.06.2013 19:07, Alexander Shiyan wrote:
>>>>>>>>>>> flashing barebox.bin to /dev/nor0.kernel
>>>>>>>>>>>>> Unknown command 'tftp' - try 'help'
>>>>>>>>> Seems tftp command is not compiled in. Ensure that
>>>>>>>>> you have CONFIG_CMD_TFTP in your .config.
>>>>>>> Thanks Alexander,
>>>>>>> 
>>>>>>> but my barebox binary is gone . Have been a bit
>>>>>>> careles... I would need to flash the binary over my OCD
>>>>>>> USB controller, but do not realy have a clue how to do
>>>>>>> this. I am waiting for support reply for this ICnova
>>>>>>> iMX536 SODIMM module, they should give me some steps
>>>>>>> how to proceed.
>>>>> [...] CONFIG_ARCH_IMX_USBLOADER in a recent barebox. After
>>>>>  compiling you will have scripts/imx/imx-usb-loader
>>> Hi Sascha,
>>> 
>>> I have included the option: CONFIG_ARCH_IMX_USBLOADER=y then
>>> run make clean and then make again, but there is no such file,
>>> tried to search recursively for similar file in barebox top
>>> directory with: find ./ -iname \*usb-loader\*
>>> 
>> 
>> My bad, i got the latest git snaphot (699-bcc9) and there is 
>> USBLOADER.. have still some issues with compiling it. There is
>> "memory bank" error [1]. Have seen there was a patch recently,
>> but do not know the option to enable/disable
> 
> When CONFIG_ARCH_IMX_USBLOADER is enabled in your config you can
> do:
> 
> make scripts/imx/
> 
> This should build the tool only.
> 

In the current 699-bcc9 branch i run:

 make ARCH=arm freescale_mx53_loco_defconfig

than i edit the .config by hand and set CONFIG_ARCH_IMX_USBLOADER=y
when running: make scripts/imx

it tells me no goals. nothing to do.

I run gcc on your script file directly, but the libush.h is misssing I
should get it from the MX53 loco project?

Thanks for help,

Adam



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG4L9gACgkQefEEI87R1DfaYACghktQZlZhmJ2hM7QNyX/g3bL7
ebcAoMvwQGN4jzzGEh1U1HpxBOPEwHAq
=dP3D
-----END PGP SIGNATURE-----


From s.hauer at pengutronix.de  Wed Jun 12 04:48:16 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Jun 2013 10:48:16 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <51B82FD8.30108@knowtrek.com>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
 <51B60B95.8020506@knowtrek.com>
 <20130610172901.GN32299@pengutronix.de>
 <51B8113F.2050207@knowtrek.com> <51B82114.7080004@knowtrek.com>
 <20130612080747.GV32299@pengutronix.de>
 <51B82FD8.30108@knowtrek.com>
Message-ID: <20130612084816.GW32299@pengutronix.de>

On Wed, Jun 12, 2013 at 10:22:48AM +0200, Adam Furmanczuk wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 12.06.2013 10:07, Sascha Hauer wrote:
> > On Wed, Jun 12, 2013 at 09:19:48AM +0200, Adam Furmanczuk wrote:
> >> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
> >> 
> >> On 12.06.2013 08:12, Adam Furmanczuk wrote:
> >>> ********* *POCZATEK CZESCI SZYFROWANEJ / PODPISANEJ* *********
> > When CONFIG_ARCH_IMX_USBLOADER is enabled in your config you can
> > do:
> > 
> > make scripts/imx/
> > 
> > This should build the tool only.
> > 
> 
> In the current 699-bcc9 branch i run:
> 
>  make ARCH=arm freescale_mx53_loco_defconfig
> 
> than i edit the .config by hand and set CONFIG_ARCH_IMX_USBLOADER=y
> when running: make scripts/imx
> 
> it tells me no goals. nothing to do.
> 
> I run gcc on your script file directly, but the libush.h is misssing I
> should get it from the MX53 loco project?

You need this from the host. On debian for example the packet is named
libusb-1.0-0-dev.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From afurmanczuk at knowtrek.com  Wed Jun 12 05:02:03 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Wed, 12 Jun 2013 11:02:03 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <20130612084816.GW32299@pengutronix.de>
References: <51B0B2D6.3030407@knowtrek.com> <51B5C56C.4050801@knowtrek.com>
 <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
 <51B60B95.8020506@knowtrek.com> <20130610172901.GN32299@pengutronix.de>
 <51B8113F.2050207@knowtrek.com> <51B82114.7080004@knowtrek.com>
 <20130612080747.GV32299@pengutronix.de> <51B82FD8.30108@knowtrek.com>
 <20130612084816.GW32299@pengutronix.de>
Message-ID: <51B8390B.4090306@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12.06.2013 10:48, Sascha Hauer wrote:
> On Wed, Jun 12, 2013 at 10:22:48AM +0200, Adam Furmanczuk wrote:
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>> 
>> On 12.06.2013 10:07, Sascha Hauer wrote:
>>> On Wed, Jun 12, 2013 at 09:19:48AM +0200, Adam Furmanczuk
>>> wrote:
>>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>>>> 
>>>> On 12.06.2013 08:12, Adam Furmanczuk wrote:
>>>>> ********* *POCZATEK CZESCI SZYFROWANEJ / PODPISANEJ*
>>>>> *********
>>> When CONFIG_ARCH_IMX_USBLOADER is enabled in your config you
>>> can do:
>>> 
>>> make scripts/imx/
>>> 
>>> This should build the tool only.
>>> 
>> 
>> In the current 699-bcc9 branch i run:
>> 
>> make ARCH=arm freescale_mx53_loco_defconfig
>> 
>> than i edit the .config by hand and set
>> CONFIG_ARCH_IMX_USBLOADER=y when running: make scripts/imx
>> 
>> it tells me no goals. nothing to do.
>> 
>> I run gcc on your script file directly, but the libush.h is
>> misssing I should get it from the MX53 loco project?
> 
> You need this from the host. On debian for example the packet is
> named libusb-1.0-0-dev.
> 

OK, I compiled with gcc imx-usb-loader.c -I/usr/include/libusb-1.0/
And had some "undefined reference" errors [1]. Probably have to adjust
some path when running in barebox/scripts/imx/ directory?

I use also debian (wheezy) as host. Details about libusb-dev package [2].

Thanks,

Adam

[1] Error Stack:
/tmp/ccdDFWFp.o: In function `find_imx_dev':
imx-usb-loader.c:(.text+0xd7): undefined reference to
`libusb_get_device_descriptor'
/tmp/ccdDFWFp.o: In function `transfer':
imx-usb-loader.c:(.text+0x54f): undefined reference to
`libusb_bulk_transfer'
imx-usb-loader.c:(.text+0x5d8): undefined reference to
`libusb_control_transfer'
imx-usb-loader.c:(.text+0x668): undefined reference to
`libusb_interrupt_transfer'
/tmp/ccdDFWFp.o: In function `main':
imx-usb-loader.c:(.text+0x2a24): undefined reference to `libusb_init'
imx-usb-loader.c:(.text+0x2a50): undefined reference to
`libusb_get_device_list'
imx-usb-loader.c:(.text+0x2afa): undefined reference to `libusb_open'
imx-usb-loader.c:(.text+0x2b6b): undefined reference to
`libusb_free_device_list'
imx-usb-loader.c:(.text+0x2b85): undefined reference to
`libusb_get_configuration'
imx-usb-loader.c:(.text+0x2b9c): undefined reference to
`libusb_kernel_driver_active'
imx-usb-loader.c:(.text+0x2bb7): undefined reference to
`libusb_detach_kernel_driver'
imx-usb-loader.c:(.text+0x2bce): undefined reference to
`libusb_claim_interface'
imx-usb-loader.c:(.text+0x2cf7): undefined reference to `libusb_close'
imx-usb-loader.c:(.text+0x2d03): undefined reference to `libusb_exit'


[2] aptitude show libusb-1.0-0-dev:

Package: libusb-1.0-0-dev
State: installed
Version: 2:1.0.11-1
[...]


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG4OQsACgkQefEEI87R1DfhRQCdH+d0UtjGMZK2dXUNf4j20h0S
ST0An23GV2UhafnesLqZNXJQ7DkZ5yGR
=hxgi
-----END PGP SIGNATURE-----


From renaud.barbier at ge.com  Wed Jun 12 10:51:37 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 12 Jun 2013 15:51:37 +0100
Subject: [PATCH 7/8] ppc 8xxx: core DDR driver functions
In-Reply-To: <20130602154444.GU32299@pengutronix.de>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
 <1370019244-7873-8-git-send-email-renaud.barbier@ge.com>
 <20130602154444.GU32299@pengutronix.de>
Message-ID: <51B88AF9.3070203@ge.com>

On 02/06/2013 16:44, Sascha Hauer wrote:
> On Fri, May 31, 2013 at 05:54:03PM +0100, Renaud Barbier wrote:
>> This file is imported from U-Boot as is.
>>
>> This code provides the 8xxx memory controller core driver interface.
>>
>> Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
>> ---
>>   arch/ppc/ddr-8xxx/main.c |  667 ++++++++++++++++++++++++++++++++++++++++++++++
>>   1 files changed, 667 insertions(+), 0 deletions(-)
>>   create mode 100644 arch/ppc/ddr-8xxx/main.c
>>
>
> [...]
>
>> +
>> +/*
>> + * fsl_ddr_sdram() -- this is the main function to be called by
>> + *	initdram() in the board file.
>> + *
>> + * It returns amount of memory configured in bytes.
>> + */
>> +phys_size_t fsl_ddr_sdram(void)
>> +{
>
> THe behaviour of this function is defined by:
>
> CONFIG_BUFFER_SIZE
> CONFIG_CHIP_SELECT_QUAD_CAPABLE
> CONFIG_CHIP_SELECTS_PER_CTRL
> CONFIG_DDR_ECC
> CONFIG_DDR_SPD
> CONFIG_DIMM_SLOTS_PER_CTLR
> CONFIG_E500MC
> CONFIG_E6500
> CONFIG_ECC_INIT_VIA_DDRCONTROLLER
> CONFIG_FSL_DDR1
> CONFIG_FSL_DDR2
> CONFIG_FSL_DDR3
> CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
> CONFIG_FSL_DDR_INTERACTIVE
> CONFIG_FSL_SDRAM_TYPE
> CONFIG_HWCONFIG
> CONFIG_MAX_MEM_MAPPED
> CONFIG_MEM_INIT_VALUE
> CONFIG_NUM_DDR_CONTROLLERS
> CONFIG_PHYS_64BIT
> CONFIG_SPD_EEPROM
> CONFIG_SYS_DDR_RAW_TIMING
> CONFIG_SYS_DIMM_SLOTS_PER_CTLR
> CONFIG_SYS_FSL_DDR_VER
> CONFIG_SYS_IMMR
> CONFIG_SYS_MPC8xxx_DDR2_ADDR
> CONFIG_SYS_MPC8xxx_DDR3_ADDR
> CONFIG_SYS_MPC8xxx_DDR_ADDR
> CONFIG_SYS_NUM_DDR_CTLRS
>
> Some of these a board specific, others are SoC specific, but all are
> input parameters to this function. The prototype should really be:
>
> phys_size_t mpc8xxx_setup_ddr(struct mpc8xxx_ddr_params *)

Actually there is already a structure "memctl_options_s" that could be 
either extended or point to a board option structure. It is updated by 
the board specific function: fsl_ddr_board_options.

>
> (or maybe mpc8xxx_setup_ddr1/2/3 to be able to let the linker throw away
> some unused code)
>
> Code written in CPP rather than C was one of the major reasons why I
> originally wrote barebox, so please let's not reintroduce this.
>
> Sascha
>



From s.hauer at pengutronix.de  Wed Jun 12 11:54:01 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 12 Jun 2013 17:54:01 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <51B8390B.4090306@knowtrek.com>
References: <51B6066A.5020801@knowtrek.com> <1370884028.154515180@f150.mail.ru>
 <51B60B95.8020506@knowtrek.com>
 <20130610172901.GN32299@pengutronix.de>
 <51B8113F.2050207@knowtrek.com> <51B82114.7080004@knowtrek.com>
 <20130612080747.GV32299@pengutronix.de>
 <51B82FD8.30108@knowtrek.com>
 <20130612084816.GW32299@pengutronix.de>
 <51B8390B.4090306@knowtrek.com>
Message-ID: <20130612155401.GX32299@pengutronix.de>

On Wed, Jun 12, 2013 at 11:02:03AM +0200, Adam Furmanczuk wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> OK, I compiled with gcc imx-usb-loader.c -I/usr/include/libusb-1.0/
> And had some "undefined reference" errors [1]. Probably have to adjust
> some path when running in barebox/scripts/imx/ directory?
> 
> I use also debian (wheezy) as host. Details about libusb-dev package [2].
> 

Ok, here is exactly what to do:

export ARCH=arm
export CROSS_COMPILE=/path/to/arm-linux-gcc-
make freescale_mx51_babbage_defconfig
make menuconfig
  System Type  --->
    i.MX specific settings  --->
        [*] compile imx-usb-loader
make

This should compile without errors and the imx-usb-loader tool should be
compiled, provided you have the libusb host tool installed.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From shc_work at mail.ru  Wed Jun 12 12:01:02 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Wed, 12 Jun 2013 20:01:02 +0400
Subject: =?UTF-8?B?UmVbMl06IGhvdyB0byBmbGFzaCBiYXJlYm94IGFuZCBzZXQgcm9vdCB2YXJp?=
 =?UTF-8?B?YWJsZT8gLSBiYXJlYm94IGlzIGdvbmUgOig=?=
In-Reply-To: <20130612155401.GX32299@pengutronix.de>
References: <51B6066A.5020801@knowtrek.com> <51B8390B.4090306@knowtrek.com>
 <20130612155401.GX32299@pengutronix.de>
Message-ID: <1371052862.194674258@f327.mail.ru>

> On Wed, Jun 12, 2013 at 11:02:03AM +0200, Adam Furmanczuk wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> > 
> > OK, I compiled with gcc imx-usb-loader.c -I/usr/include/libusb-1.0/
> > And had some "undefined reference" errors [1]. Probably have to adjust
> > some path when running in barebox/scripts/imx/ directory?
> > 
> > I use also debian (wheezy) as host. Details about libusb-dev package [2].
> > 
> 
> Ok, here is exactly what to do:
> 
> export ARCH=arm
> export CROSS_COMPILE=/path/to/arm-linux-gcc-
> make freescale_mx51_babbage_defconfig
> make menuconfig
>   System Type  --->
>     i.MX specific settings  --->
>         [*] compile imx-usb-loader
> make
> 
> This should compile without errors and the imx-usb-loader tool should be
> compiled, provided you have the libusb host tool installed.

Probably some usb-related headers on Adam system placed in non-standard
directories, since tool is not builded or makes some errors.
Maybe we need to use pkg-config for these stuffs?

---

From afurmanczuk at knowtrek.com  Wed Jun 12 12:14:06 2013
From: afurmanczuk at knowtrek.com (Adam Furmanczuk)
Date: Wed, 12 Jun 2013 18:14:06 +0200
Subject: how to flash barebox and set root variable? - barebox is gone :(
In-Reply-To: <1371052862.194674258@f327.mail.ru>
References: <51B6066A.5020801@knowtrek.com> <51B8390B.4090306@knowtrek.com>
 <20130612155401.GX32299@pengutronix.de> <1371052862.194674258@f327.mail.ru>
Message-ID: <51B89E4E.6060804@knowtrek.com>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12.06.2013 18:01, Alexander Shiyan wrote:
>> On Wed, Jun 12, 2013 at 11:02:03AM +0200, Adam Furmanczuk wrote:
>>>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>>>>> 
>>>>> OK, I compiled with gcc imx-usb-loader.c
>>>>> -I/usr/include/libusb-1.0/ And had some "undefined
>>>>> reference" errors [1]. Probably have to adjust some path
>>>>> when running in barebox/scripts/imx/ directory?
>>>>> 
>>>>> I use also debian (wheezy) as host. Details about
>>>>> libusb-dev package [2].
>>>>> 
>>> 
>>> Ok, here is exactly what to do:
>>> 
>>> export ARCH=arm export CROSS_COMPILE=/path/to/arm-linux-gcc- 
>>> make freescale_mx51_babbage_defconfig make menuconfig System
>>> Type  ---> i.MX specific settings  ---> [*] compile
>>> imx-usb-loader make
>>> 
>>> This should compile without errors and the imx-usb-loader tool
>>> should be compiled, provided you have the libusb host tool
>>> installed.
> Probably some usb-related headers on Adam system placed in
> non-standard directories, since tool is not builded or makes some
> errors. Maybe we need to use pkg-config for these stuffs?

Sorry my bad, I forgot to set CROSS_COMPILE flag. I will give it
tomorrow a try and report back.

Greetings,

Adam

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlG4nk0ACgkQefEEI87R1Dd1CwCdHu2Sb2NafGEul5avfVIeXwk7
DoUAoIft+Ik4uyQggfH095o9t1BsceN0
=eAtJ
-----END PGP SIGNATURE-----


From nm at ti.com  Wed Jun 12 14:28:37 2013
From: nm at ti.com (Nishanth Menon)
Date: Wed, 12 Jun 2013 13:28:37 -0500
Subject: [PATCH] OMAP4 do not set TPS62361_REG_ADDR_SET0
In-Reply-To: <1371021464-2390-1-git-send-email-j.weitzel@phytec.de>
References: <1371021464-2390-1-git-send-email-j.weitzel@phytec.de>
Message-ID: <CAGo_u6pP9djhzUZyOLNewL4kDwcY0A_KW1ZmdHVurCwBUxBEEg@mail.gmail.com>

On Wed, Jun 12, 2013 at 2:17 AM, Jan Weitzel <j.weitzel at phytec.de> wrote:
> Don't set SET0 voltage, because it acts as boot voltage for OPP boot.
> Take care that the kernel doesn't drive vset gpio to low. This may
> happen while reseting the gpio module at initialization, look for
> HWMOD_INIT_NO_RESET.
>
> Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
> ---
>  arch/arm/mach-omap/omap4_generic.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm/mach-omap/omap4_generic.c b/arch/arm/mach-omap/omap4_generic.c
> index 7200393..bf1f1a7 100644
> --- a/arch/arm/mach-omap/omap4_generic.c
> +++ b/arch/arm/mach-omap/omap4_generic.c
> @@ -586,11 +586,10 @@ noinline int omap4460_scale_vcores(unsigned vsel0_pin, unsigned volt_mv)
>         writel(0x6026, OMAP44XX_PRM_VC_CFG_I2C_CLK);
>
>         /* TPS - supplies vdd_mpu on 4460
> -        * Setup SET1 and SET0 with right values so that kernel
> -        * can use either of them based on its needs.
> +        * Setup SET1 and don't touch SET0 it acts as boot voltage
> +        * source after reset.
>          */
>
> -       omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, volt_mv);
>         omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET1, volt_mv);
>
>         /*
> --
> 1.7.0.4
Reviewed-by: Nishanth Menon <nm at ti.com>


From chf.fritz at googlemail.com  Wed Jun 12 16:45:46 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Wed, 12 Jun 2013 22:45:46 +0200
Subject: [PATCH v3] omap4-fb: add driver
In-Reply-To: <1370207222.5021.0.camel@lovely>
References: <1365057762.3836.18.camel@mars>
 <20130405085917.GK1906@pengutronix.de> <1365372959.20809.6.camel@lovely>
 <20130408071715.GS1568@game.jcrosoft.org>
 <20130409071608.GD1906@pengutronix.de>
 <20130409132917.GX1568@game.jcrosoft.org>  <1365706897.4136.24.camel@mars>
 <1370207222.5021.0.camel@lovely>
Message-ID: <1371069946.25992.104.camel@mars>

This patch adds omap4 display controller support.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
changes since v2:
	- use dev_request_mem_region_by_name()
---
 arch/arm/mach-omap/Makefile                |    1 +
 arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
 arch/arm/mach-omap/omap4_fb.c              |   27 ++
 drivers/video/Kconfig                      |    8 +
 drivers/video/Makefile                     |    1 +
 drivers/video/omap4.c                      |  507 ++++++++++++++++++++++++++++
 drivers/video/omap4.h                      |  408 ++++++++++++++++++++++
 7 files changed, 998 insertions(+)
 create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
 create mode 100644 arch/arm/mach-omap/omap4_fb.c
 create mode 100644 drivers/video/omap4.c
 create mode 100644 drivers/video/omap4.h

diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 94e42c6..e70ddbd 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
 obj-$(CONFIG_SHELL_NONE) += xload.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
 obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
 obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
 obj-y += gpio.o
diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
new file mode 100644
index 0000000..5c0a54b
--- /dev/null
+++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
@@ -0,0 +1,46 @@
+#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+
+#include <fb.h>
+
+#define OMAP_DSS_LCD_TFT	(1u << 0)
+#define OMAP_DSS_LCD_IVS	(1u << 1)
+#define OMAP_DSS_LCD_IHS	(1u << 2)
+#define OMAP_DSS_LCD_IPC	(1u << 3)
+#define OMAP_DSS_LCD_IEO	(1u << 4)
+#define OMAP_DSS_LCD_RF	(1u << 5)
+#define OMAP_DSS_LCD_ONOFF	(1u << 6)
+
+#define OMAP_DSS_LCD_DATALINES(_l)	((_l) << 10)
+#define OMAP_DSS_LCD_DATALINES_msk	OMAP_DSS_LCD_DATALINES(3u)
+#define OMAP_DSS_LCD_DATALINES_12	OMAP_DSS_LCD_DATALINES(0u)
+#define OMAP_DSS_LCD_DATALINES_16	OMAP_DSS_LCD_DATALINES(1u)
+#define OMAP_DSS_LCD_DATALINES_18	OMAP_DSS_LCD_DATALINES(2u)
+#define OMAP_DSS_LCD_DATALINES_24	OMAP_DSS_LCD_DATALINES(3u)
+
+struct omap4fb_display {
+	struct fb_videomode mode;
+
+	unsigned long config;
+
+	unsigned int power_on_delay;
+	unsigned int power_off_delay;
+};
+
+struct omap4fb_platform_data {
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	unsigned int dss_clk_hz;
+
+	unsigned int bpp;
+
+	struct resource const *screen;
+
+	void (*enable)(int p);
+};
+
+struct device_d;
+struct device_d *omap4_add_display(void *pdata);
+
+#endif	/* H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H */
diff --git a/arch/arm/mach-omap/omap4_fb.c b/arch/arm/mach-omap/omap4_fb.c
new file mode 100644
index 0000000..09a6af3
--- /dev/null
+++ b/arch/arm/mach-omap/omap4_fb.c
@@ -0,0 +1,27 @@
+#include <driver.h>
+#include <common.h>
+#include <linux/ioport.h>
+#include <mach/omap4-fb.h>
+
+static struct resource omap4_fb_resources[] = {
+	{
+		.name	= "omap4_dss",
+		.start	= 0x48040000,
+		.end	= 0x48040000 + 512 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	}, {
+		.name	= "omap4_dispc",
+		.start	= 0x48041000,
+		.end	= 0x48041000 + 3072 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	},
+};
+
+struct device_d *omap4_add_display(void *pdata)
+{
+	return add_generic_device_res("omap4_fb", -1,
+				      omap4_fb_resources,
+				      ARRAY_SIZE(omap4_fb_resources),
+				      pdata);
+}
+EXPORT_SYMBOL(omap4_add_display);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 6d6b08f..9dfa0cd 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -45,6 +45,14 @@ config DRIVER_VIDEO_S3C24XX
 	help
 	  Add support for the S3C244x LCD controller.
 
+config DRIVER_VIDEO_OMAP4
+	bool "OMAP4 framebuffer driver"
+	depends on ARCH_OMAP4
+	help
+	  Add support for the OMAP4 Display Controller.
+	  DSI is unsupported, only DISPC parallel mode on LCD2
+	  is supported.
+
 if DRIVER_VIDEO_S3C24XX
 
 config DRIVER_VIDEO_S3C_VERBOSE
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 7429141..83feebb 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
 obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
 obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
 obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4.o
diff --git a/drivers/video/omap4.c b/drivers/video/omap4.c
new file mode 100644
index 0000000..887a5c0
--- /dev/null
+++ b/drivers/video/omap4.c
@@ -0,0 +1,507 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.com>
+ *   Based on work by Enrico Scholz, sponsored by Phytec
+ *
+ * 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.
+ */
+
+#include <driver.h>
+#include <fb.h>
+#include <errno.h>
+#include <xfuncs.h>
+#include <init.h>
+#include <stdio.h>
+#include <io.h>
+#include <common.h>
+#include <malloc.h>
+#include <common.h>
+#include <clock.h>
+
+#include <mach/omap4-silicon.h>
+#include <mach/omap4-fb.h>
+
+#include "omap4.h"
+
+struct omap4fb_device {
+	struct fb_info info;
+	struct device_d *dev;
+
+	struct omap4fb_display const *cur_display;
+
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	struct {
+		struct omap4_regs_dss __iomem *dss;
+		struct omap4_regs_dispc __iomem *dispc;
+	} regs;
+
+	struct {
+		void __iomem *addr;
+		size_t size;
+	} prealloc_screen;
+
+	struct {
+		uint32_t dispc_control;
+		uint32_t dispc_pol_freq;
+	} shadow;
+
+	struct {
+		unsigned int dss_clk_hz;
+		unsigned int lckd;
+		unsigned int pckd;
+	} divisor;
+
+	void (*enable_fn)(int);
+
+	struct fb_videomode	video_modes[];
+};
+
+static inline void fb_write(uint32_t v, void __iomem *addr)
+{
+	__raw_writel(v, addr);
+}
+
+static inline uint32_t fb_read(void const __iomem *addr)
+{
+	return __raw_readl(addr);
+}
+
+static void omap4fb_enable(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+	struct omap4_regs_dispc __iomem	*dispc = fbi->regs.dispc;
+
+	dev_info(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(1);
+
+	udelay(fbi->cur_display->power_on_delay * 1000u);
+
+	fb_write(fb_read(&dispc->control2) |
+		 DSS_DISPC_CONTROL_LCDENABLE |
+		 1*DSS_DISPC_CONTROL_LCDENABLESIGNAL,
+		 &dispc->control2);
+
+	fb_write(fb_read(&dispc->vid1.attributes) |
+		 DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE,
+		 &dispc->vid1.attributes);
+
+	fb_write(fb_read(&dispc->control2) |
+		 DSS_DISPC_CONTROL_GOLCD,
+		 &dispc->control2);
+}
+
+static void omap4fb_disable(struct fb_info *info)
+{
+	struct omap4fb_device	*fbi =
+		container_of(info, struct omap4fb_device, info);
+	struct omap4_regs_dispc __iomem	*dispc = fbi->regs.dispc;
+
+	dev_info(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	fb_write(fb_read(&dispc->control2) &
+		 ~(DSS_DISPC_CONTROL_LCDENABLE |
+		   DSS_DISPC_CONTROL_LCDENABLESIGNAL),
+		 &dispc->control2);
+
+	fb_write(fb_read(&dispc->vid1.attributes) &
+		 ~(DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE),
+		 &dispc->vid1.attributes);
+
+	if (fbi->prealloc_screen.addr == NULL)
+		/* free frame buffer; but only when screen is not
+		 * preallocated */
+		free(info->screen_base);
+
+	info->screen_base = NULL;
+
+	udelay(fbi->cur_display->power_off_delay * 1000u);
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(0);
+}
+
+static void omap4fb_calc_divisor(struct omap4fb_device *fbi,
+			struct fb_videomode const *mode)
+{
+	unsigned int l, k, t, b;
+
+	b = UINT_MAX;
+	for (l = 1; l < 256; l++) {
+		for (k = 1; k < 256; k++) {
+			t = abs(mode->pixclock * 100 -
+				(fbi->divisor.dss_clk_hz / l / k));
+			if (t <= b) {
+				b = t;
+				fbi->divisor.lckd = l;
+				fbi->divisor.pckd = k;
+			}
+		}
+	}
+}
+
+static unsigned int omap4fb_calc_format(struct fb_info const *info)
+{
+	switch (info->bits_per_pixel) {
+	case 24: return 9;
+	case 32: return 0x8; /* xRGB24-8888 (32-bit container) */
+	default:
+		printf("%s: unsupported bpp %d\n", __func__,
+		       info->bits_per_pixel);
+		return 0;
+	}
+}
+
+struct omap4fb_colors {
+	struct fb_bitfield	red;
+	struct fb_bitfield	green;
+	struct fb_bitfield	blue;
+	struct fb_bitfield	transp;
+};
+
+static struct omap4fb_colors const omap4fb_col[] = {
+	[0] = {
+		.red	= { .length = 0, .offset = 0 },
+	},
+	[1] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+	},
+	[2] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+		.transp	= { .length = 8, .offset = 24 },
+	},
+};
+
+static void omap4fb_fill_shadow(struct omap4fb_device *fbi,
+				struct omap4fb_display const *display)
+{
+	fbi->shadow.dispc_control = 0;
+	fbi->shadow.dispc_pol_freq = 0;
+
+	fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_STNTFT;
+
+	switch (display->config & OMAP_DSS_LCD_DATALINES_msk) {
+	case OMAP_DSS_LCD_DATALINES_12:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_12;
+		break;
+	case OMAP_DSS_LCD_DATALINES_16:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_16;
+		break;
+	case OMAP_DSS_LCD_DATALINES_18:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_18;
+		break;
+	case OMAP_DSS_LCD_DATALINES_24:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_24;
+		break;
+	}
+
+	if (display->config & OMAP_DSS_LCD_IPC)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IPC;
+
+	if (display->config & OMAP_DSS_LCD_IVS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IVS;
+
+	if (display->config & OMAP_DSS_LCD_IHS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IHS;
+
+	if (display->config & OMAP_DSS_LCD_IEO)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IEO;
+
+	if (display->config & OMAP_DSS_LCD_RF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_RF;
+
+	if (display->config & OMAP_DSS_LCD_ONOFF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_ONOFF;
+}
+
+static int omap4fb_activate_var(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+	struct omap4_regs_dispc __iomem	*dispc = fbi->regs.dispc;
+	struct fb_videomode const *mode = info->mode;
+	size_t size = mode->xres * mode->yres * (info->bits_per_pixel / 8);
+	int rc;
+	unsigned int fmt = omap4fb_calc_format(info);
+	struct omap4fb_colors const *cols;
+	size_t i;
+	struct omap4fb_display const *new_display = NULL;
+
+	for (i = 0; i < fbi->num_displays && new_display == NULL; ++i) {
+		if (strcmp(mode->name, fbi->displays[i].mode.name) == 0)
+			new_display = &fbi->displays[i];
+	}
+
+	if (WARN_ON(!new_display)) {
+		dev_err(fbi->dev, "no matching display found for this mode '%s'\n",
+			mode->name);
+		rc = -ENXIO;
+		goto out;
+	}
+
+	if (fbi->prealloc_screen.addr == NULL) {
+		/* case 1: no preallocated screen */
+		free(info->screen_base);
+		info->screen_base = memalign(0x100, size);
+	} else if (fbi->prealloc_screen.size < size) {
+		/* case 2: preallocated screen, but too small */
+		dev_err(fbi->dev,
+			"allocated framebuffer too small (%zu < %zu)\n",
+			fbi->prealloc_screen.size, size);
+		rc = -ENOMEM;
+		goto out;
+	} else {
+		/* case 3: preallocated screen */
+		info->screen_base = fbi->prealloc_screen.addr;
+	}
+
+	omap4fb_fill_shadow(fbi, new_display);
+
+	omap4fb_calc_divisor(fbi, mode);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		cols = &omap4fb_col[1];
+		break;
+	case 32:
+		cols = &omap4fb_col[2];
+		break;
+	default:
+		cols = &omap4fb_col[0];
+	}
+
+	info->red = cols->red;
+	info->green = cols->green;
+	info->blue = cols->blue;
+	info->transp = cols->transp;
+
+	fb_write(fbi->shadow.dispc_control,
+		 &dispc->control2);
+
+	fb_write(fbi->shadow.dispc_pol_freq,
+		 &dispc->pol_freq2);
+
+	fb_write(DSS_DISPC_TIMING_H_HSW(mode->hsync_len - 1) |
+		 DSS_DISPC_TIMING_H_HFP(mode->right_margin - 1) |
+		 DSS_DISPC_TIMING_H_HBP(mode->left_margin - 1),
+		 &dispc->timing_h2);
+
+	fb_write(DSS_DISPC_TIMING_V_VSW(mode->vsync_len - 1) |
+		 DSS_DISPC_TIMING_V_VFP(mode->lower_margin) |
+		 DSS_DISPC_TIMING_V_VBP(mode->upper_margin),
+		 &dispc->timing_v2);
+
+	fb_write(DSS_DISPC_DIVISOR_ENABLE | DSS_DISPC_DIVISOR_LCD(1),
+			&dispc->divisor);
+
+	fb_write(DSS_DISPC_DIVISOR2_LCD(fbi->divisor.lckd) |
+		 DSS_DISPC_DIVISOR2_PCD(fbi->divisor.pckd),
+		 &dispc->divisor2);
+
+	fb_write(DSS_DISPC_SIZE_LCD_PPL(mode->xres - 1) |
+		 DSS_DISPC_SIZE_LCD_LPP(mode->yres - 1),
+		 &dispc->size_lcd2);
+
+	fb_write(0x0000FF00, &dispc->default_color2);
+
+	/* we use VID1 */
+	fb_write((uintptr_t)info->screen_base, &dispc->vid1.ba[0]);
+	fb_write((uintptr_t)info->screen_base, &dispc->vid1.ba[1]);
+
+	fb_write(DSS_DISPC_VIDn_POSITION_VIDPOSX(0) |
+		 DSS_DISPC_VIDn_POSITION_VIDPOSY(0),
+		 &dispc->vid1.position);
+	fb_write(DSS_DISPC_VIDn_SIZE_VIDSIZEX(mode->xres - 1) |
+		 DSS_DISPC_VIDn_SIZE_VIDSIZEY(mode->yres - 1),
+		 &dispc->vid1.size);
+	fb_write(DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(mode->xres - 1) |
+		 DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(mode->yres - 1),
+		 &dispc->vid1.picture_size);
+	fb_write(1, &dispc->vid1.row_inc);
+	fb_write(1, &dispc->vid1.pixel_inc);
+
+	fb_write(0xfff, &dispc->vid_preload[0]);
+
+	fb_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
+			 DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
+			 DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
+			 DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
+			 &dispc->vid1.attributes);
+
+	while (fb_read(&dispc->control2) & DSS_DISPC_CONTROL_GOLCD)
+		;			/* noop */
+
+	fb_write(fb_read(&dispc->control2) |
+		 DSS_DISPC_CONTROL_GOLCD,
+		 &dispc->control2);
+
+	fbi->cur_display = new_display;
+	info->xres = mode->xres;
+	info->yres = mode->yres;
+
+	rc = 0;
+
+out:
+	return rc;
+}
+
+static void omap4fb_reset(struct omap4fb_device const *fbi)
+{
+	struct omap4_regs_dispc __iomem	*dispc = fbi->regs.dispc;
+	struct omap4_regs_dss __iomem *dss = fbi->regs.dss;
+
+	uint32_t	v = fb_read(&dispc->control2);
+
+	/* step 1: stop the LCD controller */
+	if (v & DSS_DISPC_CONTROL_LCDENABLE) {
+		fb_write(v & ~DSS_DISPC_CONTROL_LCDENABLE,
+			 &dispc->control2);
+
+		fb_write(DSS_DISPC_IRQSTATUS_FRAMEDONE2, &dispc->irqstatus);
+
+		while ((fb_read(&dispc->irqstatus) &
+			DSS_DISPC_IRQSTATUS_FRAMEDONE) == 0)
+			;		/* noop */
+	}
+
+	/* step 2: wait for reset done status */
+	while (!(fb_read(&dss->sysstatus) & DSS_DSS_SYSSTATUS_RESETDONE))
+		;			/* noop */
+
+	/* DSS_CTL: set to reset value */
+	fb_write(0, &dss->ctrl);
+}
+
+static struct fb_ops omap4fb_ops = {
+	.fb_enable		= omap4fb_enable,
+	.fb_disable		= omap4fb_disable,
+	.fb_activate_var	= omap4fb_activate_var,
+};
+
+static int omap4fb_probe(struct device_d *dev)
+{
+	struct omap4fb_platform_data const *pdata = dev->platform_data;
+	struct omap4fb_device *fbi;
+	struct fb_info *info;
+	struct omap4_regs_dispc __iomem	*dispc;
+	struct omap4_regs_dss __iomem *dss;
+	int rc;
+	size_t i;
+
+	if (!pdata)
+		return -ENODEV;
+
+	fbi = xzalloc(sizeof *fbi +
+		      pdata->num_displays * sizeof fbi->video_modes[0]);
+	info = &fbi->info;
+
+	fbi->dev = dev;
+
+	/* CM_DSS_CLKSTCTRL (TRM: 935) trigger SW_WKUP */
+	__raw_writel(0x2, 0x4a009100); /* TODO: move this to clockmanagement */
+
+	fbi->regs.dss   = dev_request_mem_region_by_name(dev, "omap4_dss");
+	fbi->regs.dispc = dev_request_mem_region_by_name(dev, "omap4_dispc");
+
+	if (!fbi->regs.dss || !fbi->regs.dispc) {
+		dev_err(dev, "Insufficient register description\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	dispc = fbi->regs.dispc;
+	dss = fbi->regs.dss;
+	dev_info(dev, "HW-Revision 0x%04x 0x%04x\n",
+		fb_read(&dispc->revision),
+		fb_read(&dss->revision));
+
+
+	if (!pdata->dss_clk_hz | !pdata->displays | !pdata->num_displays |
+		!pdata->bpp) {
+		dev_err(dev, "Insufficient omap4fb_platform_data\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	fbi->enable_fn    = pdata->enable;
+	fbi->displays     = pdata->displays;
+	fbi->num_displays = pdata->num_displays;
+	fbi->divisor.dss_clk_hz = pdata->dss_clk_hz;
+
+	for (i = 0; i < pdata->num_displays; ++i)
+		fbi->video_modes[i] = pdata->displays[i].mode;
+
+	info->mode_list = fbi->video_modes;
+	info->num_modes = pdata->num_displays;
+
+	info->priv = fbi;
+	info->fbops = &omap4fb_ops;
+	info->bits_per_pixel = pdata->bpp;
+
+	if (pdata->screen) {
+		fbi->prealloc_screen.addr =
+				(void __iomem *)pdata->screen->start;
+		fbi->prealloc_screen.size = resource_size(pdata->screen);
+	}
+
+	omap4fb_reset(fbi);
+
+	dev_add_param(fbi->dev, "bootargs", NULL, NULL, 0);
+
+	rc = register_framebuffer(info);
+	if (rc < 0) {
+		dev_err(dev, "failed to register framebuffer: %d\n", rc);
+		goto out;
+	}
+
+	rc = 0;
+	dev_info(dev, "registered\n");
+
+out:
+	if (rc < 0)
+		free(fbi);
+
+	return rc;
+}
+
+static struct driver_d omap4fb_driver = {
+	.name	= "omap4_fb",
+	.probe	= omap4fb_probe,
+};
+
+static int omap4fb_init(void)
+{
+	return platform_driver_register(&omap4fb_driver);
+}
+
+device_initcall(omap4fb_init);
diff --git a/drivers/video/omap4.h b/drivers/video/omap4.h
new file mode 100644
index 0000000..b3364a5
--- /dev/null
+++ b/drivers/video/omap4.h
@@ -0,0 +1,408 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.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.
+ */
+
+#ifndef H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+#define H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+
+#include <types.h>
+#include <common.h>
+
+#define OMAP4_RESERVED(_f, _t) \
+	uint32_t const reserved_ ## _f ## _ ## _t[((_t) - (_f)) / 4]
+
+
+/* TRM: 10.1.3.2 DSS Registers */
+struct omap4_regs_dss {
+	uint32_t revision;
+	OMAP4_RESERVED(0x4, 0x14);
+	uint32_t const sysstatus;
+	OMAP4_RESERVED(0x18, 0x40);
+	uint32_t ctrl;
+	OMAP4_RESERVED(0x44, 0x5C);
+	uint32_t const status;
+};
+
+
+struct omap4_regs_dispc_vid {
+	uint32_t ba[2];
+	uint32_t position;
+	uint32_t size;
+	uint32_t attributes;
+	uint32_t buf_threshold;
+	uint32_t const buf_size_status;
+	uint32_t row_inc;
+	uint32_t pixel_inc;
+	uint32_t fir;
+	uint32_t picture_size;
+	uint32_t accu[2];
+	struct {
+		uint32_t h;
+		uint32_t hv;
+	} fir_coef[8];
+	uint32_t conv_coef0;
+	uint32_t conv_coef1;
+	uint32_t conv_coef2;
+	uint32_t conv_coef3;
+	uint32_t conv_coef4;
+};
+
+/* TRM: 10.2.7.3 Display Controller Registers */
+struct omap4_regs_dispc {
+	uint32_t const revision;
+	OMAP4_RESERVED(0x04, 0x10);
+	uint32_t sysconfig;
+	uint32_t const sysstatus;
+	uint32_t irqstatus;
+	uint32_t irqenable;
+	OMAP4_RESERVED(0x20, 0x40);
+	uint32_t control1;
+	uint32_t config1;
+	OMAP4_RESERVED(0x48, 0x4C);
+
+	uint32_t default_color[2];
+	uint32_t trans_color[2];
+
+	uint32_t const line_status;
+	uint32_t line_number;
+	uint32_t timing_h1;
+	uint32_t timing_v1;
+	uint32_t pol_freq1;
+	uint32_t divisor1;
+	uint32_t global_alpha;
+	uint32_t size_tv;
+	uint32_t size_lcd1;
+
+	struct {
+		uint32_t ba[2];
+		uint32_t position;
+		uint32_t size;
+		OMAP4_RESERVED(0x90, 0xA0);
+		uint32_t attributes;
+		uint32_t buf_threshold;
+		uint32_t const buf_size_status;
+		uint32_t row_inc;
+		uint32_t pixel_inc;
+		OMAP4_RESERVED(0xB4, 0xB8);
+		uint32_t table_ba;
+	} gfx;
+
+	struct omap4_regs_dispc_vid vid1;
+	OMAP4_RESERVED(0x144, 0x14C);
+	struct omap4_regs_dispc_vid vid2;
+
+	uint32_t data1_cycle[3];
+
+	uint32_t vid1_fir_coef_v[8];
+	uint32_t vid2_fir_coef_v[8];
+	uint32_t cpr1_coef_r;
+	uint32_t cpr1_coef_g;
+	uint32_t cpr1_coef_b;
+	uint32_t gfx_preload;
+	uint32_t vid_preload[2];
+	uint32_t control2;
+	OMAP4_RESERVED(0x23C, 0x300);
+
+	struct {
+		uint32_t accu[2];
+		uint32_t ba[2];
+		struct {
+			uint32_t h;
+			uint32_t hv;
+		} fir_coef[8];
+		uint32_t fir_coef_v[8];
+		uint32_t attributes;
+		uint32_t conv_coef0;
+		uint32_t conv_coef1;
+		uint32_t conv_coef2;
+		uint32_t conv_coef3;
+		uint32_t conv_coef4;
+		uint32_t const buf_size_status;
+		uint32_t buf_threshold;
+		uint32_t fir;
+		uint32_t picture_size;
+		uint32_t pixel_inc;
+		uint32_t position;
+		uint32_t preload;
+		uint32_t row_inc;
+		uint32_t size;
+	} vid3;
+
+	uint32_t default_color2;
+	uint32_t trans_color2;
+	uint32_t cpr2_coef_b;
+	uint32_t cpr2_coef_g;
+	uint32_t cpr2_coef_r;
+	uint32_t data2_cycle[3];
+	uint32_t size_lcd2;
+	OMAP4_RESERVED(0x3D0, 0x400);
+	uint32_t timing_h2;
+	uint32_t timing_v2;
+	uint32_t pol_freq2;
+	uint32_t divisor2;
+	OMAP4_RESERVED(0x410, 0x500);
+
+	struct {
+		uint32_t accu[2];
+		uint32_t ba[2];
+		struct {
+			uint32_t h;
+			uint32_t hv;
+		} fir_coef[8];
+		uint32_t fir_coef_v[8];
+		uint32_t attributes;
+		uint32_t conv_coef0;
+		uint32_t conv_coef1;
+		uint32_t conv_coef2;
+		uint32_t conv_coef3;
+		uint32_t conv_coef4;
+		uint32_t const buf_size_status;
+		uint32_t buf_threshold;
+		uint32_t fir;
+		uint32_t picture_size;
+		uint32_t pixel_inc;
+		OMAP4_RESERVED(0x59C, 0x5A4);
+		uint32_t row_inc;
+		uint32_t size;
+	} wb;
+
+	OMAP4_RESERVED(0x5AC, 0x600);
+	uint32_t vid1_ba_uv[2];
+	uint32_t vid2_ba_uv[2];
+	uint32_t vid3_ba_uv[2];
+	uint32_t wb_ba_uv[2];
+	uint32_t config2;
+	uint32_t vid1_attributes2;
+	uint32_t vid2_attributes2;
+	uint32_t vid3_attributes2;
+	uint32_t gamma_table0;
+	uint32_t gamma_table1;
+	uint32_t gamma_table2;
+	uint32_t vid1_fir2;
+	uint32_t vid1_accu2[2];
+	struct {
+		uint32_t h2;
+		uint32_t hv2;
+	} vid1_fir_coef[8];
+	uint32_t vid1_fir_coef_v2[8];
+	uint32_t vid2_fir2;
+	uint32_t vid2_accu2[2];
+	struct {
+		uint32_t h2;
+		uint32_t hv2;
+	} vid2_fir_coef[8];
+	uint32_t vid2_fir_coef_v2[8];
+	OMAP4_RESERVED(0x714, 0x724);
+	uint32_t vid3_fir2;
+	uint32_t vid3_accu2[2];
+	struct {
+		uint32_t h2;
+		uint32_t hv2;
+	} vid3_fir_coef[8];
+	uint32_t vid3_fir_coef_v2[8];
+	uint32_t wb_fir2;
+	uint32_t wb_accu2[2];
+	OMAP4_RESERVED(0x79C, 0x7A0);
+	struct {
+		uint32_t h2;
+		uint32_t hv2;
+	} wb_fir_coef[8];
+	uint32_t wb_fir_coef_v2[8];
+	uint32_t global_buffer;
+	uint32_t divisor;
+	OMAP4_RESERVED(0x808, 0x810);
+	uint32_t wb_attributes2;
+};
+
+#define DSS_DISPC_VIDn_POSITION_VIDPOSX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_POSITION_VIDPOSY(_y)		((_y) << 16)
+
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(_x)	((_x) << 0)
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(_y)	((_y) << 16)
+
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEY(_y)		((_y) << 16)
+
+#define DSS_DISPC_SIZE_LCD_PPL(_x)			((_x) << 0)
+#define DSS_DISPC_SIZE_LCD_LPP(_y)			((_y) << 16)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE		(1u << 0)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(_fmt)	((_fmt) << 1)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB12	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(4u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(5u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(6u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16o	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(7u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB24u	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(8u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB24p	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(9u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_YUV2	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(10u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_UYVY	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(11u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(12u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGBA32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(13u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(14u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(_f)	((_f) << 5)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE_NONE \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE_H \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE_V \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(2u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE_HV \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(3u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCOLORCONVENABLE	(1u << 9)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDREPLICATIONENABLE	(1u << 10)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFULLRANGE		(1u << 11)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(_r)	((_r) << 12)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION_0 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION_90 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION_180 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(2u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION_270 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(3u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(_b)	((_b) << 14)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_2x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_4x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(2u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCHANNELOUT	(1u << 16)
+#define DSS_DISPC_VIDn_ATTRIBUTES_SELFREFRESHAUTO	(1u << 17)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFIFOPRELOAD	(1u << 19)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDVERTICALTAPS	(1u << 21)
+#define DSS_DISPC_VIDn_ATTRIBUTES_DOUBLESTRIDE		(1u << 22)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDARBITRATION	(1u << 23)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDSELFREFRESH	(1u << 24)
+#define DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE		(1u << 25)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(_b)  ((_b) << 30)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_PRIMARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_WRITEBACK_MEM \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(3u)
+
+#define DSS_DISPC_CONFIG_PIXELGATED			(1u << 0)
+#define DSS_DISPC_CONFIG_PIXELDATAGATED		(1u << 4)
+#define DSS_DISPC_CONFIG_PIXELCLOCKGATED		(1u << 5)
+#define DSS_DISPC_CONFIG_HSYNCGATED			(1u << 6)
+#define DSS_DISPC_CONFIG_VSYNCGATED			(1u << 7)
+#define DSS_DISPC_CONFIG_ACBIASGATED			(1u << 8)
+#define DSS_DISPC_CONFIG_FUNCGATED			(1u << 9)
+#define DSS_DISPC_CONFIG_TCKLCDENABLE			(1u << 10)
+#define DSS_DISPC_CONFIG_TCKLCDSELECTION		(1u << 11)
+#define DSS_DISPC_CONFIG_CPR				(1u << 15)
+#define DSS_DISPC_CONFIG_FIFOHANDCHECK			(1u << 16)
+#define DSS_DISPC_CONFIG_OUTPUTMODE			(1u << 22)
+#define DSS_DISPC_CONFIG_FIDFIRST			(1u << 23)
+#define DSS_DISPC_CONFIG_COLORCONV			(1u << 24)
+#define DSS_DISPC_CONFIG_FULLRANGE			(1u << 25)
+
+#define DSS_DISPC_CONTROL_LCDENABLE			(1u << 0)
+#define DSS_DISPC_CONTROL_TVENABLE			(1u << 1)
+#define DSS_DISPC_CONTROL_MONOCOLOR			(1u << 2)
+#define DSS_DISPC_CONTROL_STNTFT			(1u << 3)
+#define DSS_DISPC_CONTROL_M8B				(1u << 4)
+#define DSS_DISPC_CONTROL_GOLCD			(1u << 5)
+#define DSS_DISPC_CONTROL_GOTV				(1u << 6)
+#define DSS_DISPC_CONTROL_STDITHERENABLE		(1u << 7)
+
+#define DSS_DISPC_CONTROL_TFTDATALINES(_l)		((_l) << 8)
+#define DSS_DISPC_CONTROL_TFTDATALINES_12 \
+	DSS_DISPC_CONTROL_TFTDATALINES(0u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_16 \
+	DSS_DISPC_CONTROL_TFTDATALINES(1u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_18 \
+	DSS_DISPC_CONTROL_TFTDATALINES(2u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_24 \
+	DSS_DISPC_CONTROL_TFTDATALINES(3u)
+
+#define DSS_DISPC_CONTROL_STALLMODE			(1u << 11)
+#define DSS_DISPC_CONTROL_OVERLAYOPTIMIZATION		(1u << 12)
+#define DSS_DISPC_CONTROL_GPIN0			(1u << 13) /* ro */
+#define DSS_DISPC_CONTROL_GPIN1			(1u << 14) /* ro */
+#define DSS_DISPC_CONTROL_GPOUT0			(1u << 15)
+#define DSS_DISPC_CONTROL_GPOUT1			(1u << 16)
+#define DSS_DISPC_CONTROL_HT(_ht)			((_ht) << 17)
+#define DSS_DISPC_CONTROL_TDMENABLE			(1u << 20)
+#define DSS_DISPC_CONTROL_TDMPARALLELMODE(_pm)		((_pm) << 21)
+#define DSS_DISPC_CONTROL_TDMCYCLEFORMAT(_cf)		((_cf) << 23)
+#define DSS_DISPC_CONTROL_TDMUNUSEDBITS(_ub)		((_ub) << 25)
+#define DSS_DISPC_CONTROL_PCKFREEENABLE		(1u << 27)
+#define DSS_DISPC_CONTROL_LCDENABLESIGNAL		(1u << 28)
+#define DSS_DISPC_CONTROL_LCDENABLEPOL			(1u << 29)
+#define DSS_DISPC_CONTROL_SPATIALTEMPD(_df)		((_df) << 30)
+
+#define DSS_DISPC_POL_FREQ_IVS				(1u << 12)
+#define DSS_DISPC_POL_FREQ_IHS				(1u << 13)
+#define DSS_DISPC_POL_FREQ_IPC				(1u << 14)
+#define DSS_DISPC_POL_FREQ_IEO				(1u << 15)
+#define DSS_DISPC_POL_FREQ_RF				(1u << 16)
+#define DSS_DISPC_POL_FREQ_ONOFF			(1u << 17)
+
+#define DSS_DISPC_TIMING_H_HSW(_hsw)			((_hsw) << 0)
+#define DSS_DISPC_TIMING_H_HFP(_hfp)			((_hfp) << 8)
+#define DSS_DISPC_TIMING_H_HBP(_hbp)			((_hbp) << 20)
+
+#define DSS_DISPC_TIMING_V_VSW(_vsw)			((_vsw) << 0)
+#define DSS_DISPC_TIMING_V_VFP(_vfp)			((_vfp) << 8)
+#define DSS_DISPC_TIMING_V_VBP(_vbp)			((_vbp) << 20)
+
+#define DSS_DISPC_DIVISOR_ENABLE			(1u << 0)
+#define DSS_DISPC_DIVISOR_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_DIVISOR2_PCD(_pcd)			((_pcd) << 0)
+#define DSS_DISPC_DIVISOR2_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE			(1u << 0)
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE2			(1u << 22)
+
+#define DSS_DSS_SYSCONFIG_SOFTRESET			(1u << 1)
+#define DSS_DSS_SYSSTATUS_RESETDONE			(1u << 0)
+
+#define DSS_DSS_CONTROL_DISPC_CLK_SWITCH		(1u << 0)
+#define DSS_DSS_CONTROL_DSI_CLK_SWITCH			(1u << 1)
+
+#define CM_FCLKEN_DSS_EN_DSS1	(1u << 0)
+#define CM_FCLKEN_DSS_EN_DSS2	(1u << 1)
+#define CM_FCLKEN_DSS_EN_TV	(1u << 2)
+
+#define CM_ICLKEN_DSS_EN_DSS	(1u << 0)
+
+
+#undef OMAP4_RESERVED
+
+#endif	/* H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H */
-- 
1.7.10.4





From W.Vanhauwaert at TELEVIC.com  Thu Jun 13 03:09:11 2013
From: W.Vanhauwaert at TELEVIC.com (Vanhauwaert Wouter)
Date: Thu, 13 Jun 2013 09:09:11 +0200
Subject: NAND + imx53, BBT/timings?
Message-ID: <E78BBE677EB9144B8F0A0A29674CD5338ECF0A3DAA@SRV-VS06.TELEVIC.COM>

Hi all,

I'm working on a custom design which has an imx53 and a 1GB NAND flash (Samsung k9k8g08u0d) via an 8 bit bus.
So I added this imx_nand_platform_data structure with a .width=1, .hw_ecc=1 and .flash_bbt=1.
The flash gets detected at startup (also loads the bootloader from it).

nand: Manufacturer ID: 0xec, Chip ID: 0xd3 (Samsung NAND 1GiB 3,3V 8-bit), page size 2048, OOB size:64 
but then
nand: Bad block table not found for chip 0
nand: Bad block table not found for chip 0

etc

and when I do imx_nand_bbm, I get:
Bad eraseblock 0 at 0x00000000
Bad eraseblock 1 at 0x00020000
And for the rest UnCorrectable RS-ECC errors

This is a barenew flash, so I suppose I should find a factory bad block table?
I'm using the barebox 2013.05.1 stable release from git

Grtz,
Wouter


From shc_work at mail.ru  Thu Jun 13 03:19:56 2013
From: shc_work at mail.ru (Alexander Shiyan)
Date: Thu, 13 Jun 2013 11:19:56 +0400
Subject: [PATCH] ARM: ccmx51: Set PMIC SW1 voltage for i.MX51 less than TO3
 only
Message-ID: <1371107996-11771-1-git-send-email-shc_work@mail.ru>

This settings taken from original DIGI U-boot source code.

Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
---
 arch/arm/boards/ccxmx51/ccxmx51.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boards/ccxmx51/ccxmx51.c b/arch/arm/boards/ccxmx51/ccxmx51.c
index 9610e41..b760ca8 100644
--- a/arch/arm/boards/ccxmx51/ccxmx51.c
+++ b/arch/arm/boards/ccxmx51/ccxmx51.c
@@ -256,13 +256,13 @@ static int ccxmx51_power_init(void)
 	val = 0x238033;
 	mc13xxx_reg_write(mc13xxx_dev, MC13892_REG_CHARGE, val);
 
-	/* Set core voltage (SW1) to 1.1V */
-	mc13xxx_reg_read(mc13xxx_dev, MC13892_REG_SW_0, &val);
-	val &= ~0x00001f;
-	val |=  0x000014;
-	mc13xxx_reg_write(mc13xxx_dev, MC13892_REG_SW_0, val);
-
 	if (imx_silicon_revision() < IMX_CHIP_REV_3_0) {
+		/* Set core voltage (SW1) to 1.1V */
+		mc13xxx_reg_read(mc13xxx_dev, MC13892_REG_SW_0, &val);
+		val &= ~0x00001f;
+		val |=  0x000014;
+		mc13xxx_reg_write(mc13xxx_dev, MC13892_REG_SW_0, val);
+
 		/* Setup VCC (SW2) to 1.25 */
 		mc13xxx_reg_read(mc13xxx_dev, MC13892_REG_SW_1, &val);
 		val &= ~0x00001f;
-- 
1.8.1.5



From s.hauer at pengutronix.de  Thu Jun 13 05:25:57 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 13 Jun 2013 11:25:57 +0200
Subject: [PATCH] of: add ranges address translation for default bus
In-Reply-To: <51B6EED2.3010707@gmail.com>
References: <1368400146-30443-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130519073403.GY32299@pengutronix.de>
 <51B6EED2.3010707@gmail.com>
Message-ID: <20130613092557.GC32299@pengutronix.de>

On Tue, Jun 11, 2013 at 11:33:06AM +0200, Sebastian Hesselbarth wrote:
> On 05/19/13 09:34, Sascha Hauer wrote:
> >Hi Sebastian,
> >
> >On Mon, May 13, 2013 at 01:09:06AM +0200, Sebastian Hesselbarth wrote:
> >>This patch adds address translation for default bus types. It has been
> >>shamelessly ported from Linux device tree address translation with the
> >>following exceptions:
> >>- only default bus map and translate are supported
> >>- of_bus has not been ported
> >>- check for #size-cells > 0 has been removed
> >>
> >>Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> >
> >I just gave this one a test.
> >
> >First of all you dropped 1:1 translation, see the attached fixup.
> >
> >Then, since this code duplicates the majority of drivers/of/address.c,
> >would it make sense to move it to the same file in barebox aswell?
> 
> Sascha,
> 
> coming back to this I am wondering if a full sync of linux' drivers/of
> with barebox' drivers/of should be done. IMHO at least for the core
> stuff (base/address/fdt) it makes sense, of_* can come later if
> required.
> 
> I started merging already, and from what I can see we should just remove
> the spinlocks and OF_DYNAMIC stuff (but leave of_node_get/_put as stubs)

Sounds like a plan. Functions existing both in barebox and Linux should
behave the same way. However, if Linux turns out to do something silly
or (for our usecase) too bloated, we shouldn't do the same just because
Linux does it.

I want to keep the Linux list usage in the devicetree, so they won't be
really in sync.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Thu Jun 13 05:38:19 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Thu, 13 Jun 2013 11:38:19 +0200
Subject: [PATCH] of: add ranges address translation for default bus
In-Reply-To: <20130613092557.GC32299@pengutronix.de>
References: <1368400146-30443-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130519073403.GY32299@pengutronix.de> <51B6EED2.3010707@gmail.com>
 <20130613092557.GC32299@pengutronix.de>
Message-ID: <51B9930B.8080609@gmail.com>

On 06/13/13 11:25, Sascha Hauer wrote:
> On Tue, Jun 11, 2013 at 11:33:06AM +0200, Sebastian Hesselbarth wrote:
>> I started merging already, and from what I can see we should just remove
>> the spinlocks and OF_DYNAMIC stuff (but leave of_node_get/_put as stubs)
>
> Sounds like a plan. Functions existing both in barebox and Linux should
> behave the same way. However, if Linux turns out to do something silly
> or (for our usecase) too bloated, we shouldn't do the same just because
> Linux does it.
>
> I want to keep the Linux list usage in the devicetree, so they won't be
> really in sync.

Ok, I started converting and doing it in a clean way is kind of tricky.

First of all, allyesconfig doesn't build - so it is hard to find and
re-build all users of current of_* functions.

If you want to stick with list usage, it will end up with converting
instead of just move current functions out of the way, import Linux
OF, and switch users to that functions.

I will have a look at it, find users/abusers of current API and see
how much we can merge.

You also want to stick with of_set_* and friends within base.c or
move them out to some other source file where all set/modify functions
will sit in?

Sebastian



From plagnioj at jcrosoft.com  Thu Jun 13 06:10:06 2013
From: plagnioj at jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
Date: Thu, 13 Jun 2013 12:10:06 +0200
Subject: [PATCH v3] omap4-fb: add driver
In-Reply-To: <1371069946.25992.104.camel@mars>
References: <1365057762.3836.18.camel@mars>
 <20130405085917.GK1906@pengutronix.de> <1365372959.20809.6.camel@lovely>
 <20130408071715.GS1568@game.jcrosoft.org>
 <20130409071608.GD1906@pengutronix.de>
 <20130409132917.GX1568@game.jcrosoft.org> <1365706897.4136.24.camel@mars>
 <1370207222.5021.0.camel@lovely> <1371069946.25992.104.camel@mars>
Message-ID: <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>


On Jun 12, 2013, at 10:45 PM, Christoph Fritz <chf.fritz at googlemail.com> wrote:

> This patch adds omap4 display controller support.
> 
> Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
> ---
> changes since v2:
> 	- use dev_request_mem_region_by_name()
> ---
> arch/arm/mach-omap/Makefile                |    1 +
> arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
> arch/arm/mach-omap/omap4_fb.c              |   27 ++
> drivers/video/Kconfig                      |    8 +
> drivers/video/Makefile                     |    1 +
> drivers/video/omap4.c                      |  507 ++++++++++++++++++++++++++++
> drivers/video/omap4.h                      |  408 ++++++++++++++++++++++
> 7 files changed, 998 insertions(+)


In linux we does not use the struct for regs and I'll *never* accept this 
so please drop me this. This is a huge nightmare to maintain and hugely easy to
move registers by touching the struct

really DROP IT

Best Regards,
J.
> create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
> create mode 100644 arch/arm/mach-omap/omap4_fb.c
> create mode 100644 drivers/video/omap4.c
> create mode 100644 drivers/video/omap4.h
> 
> diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
> index 94e42c6..e70ddbd 100644
> --- a/arch/arm/mach-omap/Makefile
> +++ b/arch/arm/mach-omap/Makefile
> @@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
> pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
> obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
> obj-$(CONFIG_SHELL_NONE) += xload.o
> +obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
> obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
> obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
> obj-y += gpio.o
> diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
> new file mode 100644
> index 0000000..5c0a54b
> --- /dev/null
> +++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
> @@ -0,0 +1,46 @@
> +#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
> +#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
> +
> +#include <fb.h>
> +
> +#define OMAP_DSS_LCD_TFT	(1u << 0)
> +#define OMAP_DSS_LCD_IVS	(1u << 1)
> +#define OMAP_DSS_LCD_IHS	(1u << 2)
> +#define OMAP_DSS_LCD_IPC	(1u << 3)
> +#define OMAP_DSS_LCD_IEO	(1u << 4)
> +#define OMAP_DSS_LCD_RF	(1u << 5)
> +#define OMAP_DSS_LCD_ONOFF	(1u << 6)
> +
> +#define OMAP_DSS_LCD_DATALINES(_l)	((_l) << 10)
> +#define OMAP_DSS_LCD_DATALINES_msk	OMAP_DSS_LCD_DATALINES(3u)
> +#define OMAP_DSS_LCD_DATALINES_12	OMAP_DSS_LCD_DATALINES(0u)
> +#define OMAP_DSS_LCD_DATALINES_16	OMAP_DSS_LCD_DATALINES(1u)
> +#define OMAP_DSS_LCD_DATALINES_18	OMAP_DSS_LCD_DATALINES(2u)
> +#define OMAP_DSS_LCD_DATALINES_24	OMAP_DSS_LCD_DATALINES(3u)
> +
> +struct omap4fb_display {
> +	struct fb_videomode mode;
> +
> +	unsigned long config;
> +
> +	unsigned int power_on_delay;
> +	unsigned int power_off_delay;
> +};
> +
> +struct omap4fb_platform_data {
> +	struct omap4fb_display const *displays;
> +	size_t num_displays;
> +
> +	unsigned int dss_clk_hz;
> +
> +	unsigned int bpp;
> +
> +	struct resource const *screen;
> +
> +	void (*enable)(int p);
> +};
> +
> +struct device_d;
> +struct device_d *omap4_add_display(void *pdata);
> +
> +#endif	/* H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H */
> diff --git a/arch/arm/mach-omap/omap4_fb.c b/arch/arm/mach-omap/omap4_fb.c
> new file mode 100644
> index 0000000..09a6af3
> --- /dev/null
> +++ b/arch/arm/mach-omap/omap4_fb.c
> @@ -0,0 +1,27 @@
> +#include <driver.h>
> +#include <common.h>
> +#include <linux/ioport.h>
> +#include <mach/omap4-fb.h>
> +
> +static struct resource omap4_fb_resources[] = {
> +	{
> +		.name	= "omap4_dss",
> +		.start	= 0x48040000,
> +		.end	= 0x48040000 + 512 - 1,
> +		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
> +	}, {
> +		.name	= "omap4_dispc",
> +		.start	= 0x48041000,
> +		.end	= 0x48041000 + 3072 - 1,
> +		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
> +	},
> +};
> +
> +struct device_d *omap4_add_display(void *pdata)
> +{
> +	return add_generic_device_res("omap4_fb", -1,
> +				      omap4_fb_resources,
> +				      ARRAY_SIZE(omap4_fb_resources),
> +				      pdata);
> +}
> +EXPORT_SYMBOL(omap4_add_display);
> diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
> index 6d6b08f..9dfa0cd 100644
> --- a/drivers/video/Kconfig
> +++ b/drivers/video/Kconfig
> @@ -45,6 +45,14 @@ config DRIVER_VIDEO_S3C24XX
> 	help
> 	  Add support for the S3C244x LCD controller.
> 
> +config DRIVER_VIDEO_OMAP4
> +	bool "OMAP4 framebuffer driver"
> +	depends on ARCH_OMAP4
> +	help
> +	  Add support for the OMAP4 Display Controller.
> +	  DSI is unsupported, only DISPC parallel mode on LCD2
> +	  is supported.
> +
> if DRIVER_VIDEO_S3C24XX
> 
> config DRIVER_VIDEO_S3C_VERBOSE
> diff --git a/drivers/video/Makefile b/drivers/video/Makefile
> index 7429141..83feebb 100644
> --- a/drivers/video/Makefile
> +++ b/drivers/video/Makefile
> @@ -8,3 +8,4 @@ obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
> obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
> obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
> obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
> +obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4.o
> diff --git a/drivers/video/omap4.c b/drivers/video/omap4.c
> new file mode 100644
> index 0000000..887a5c0
> --- /dev/null
> +++ b/drivers/video/omap4.c
> @@ -0,0 +1,507 @@
> +/*
> + * TI Omap4 Frame Buffer device driver
> + *
> + * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.com>
> + *   Based on work by Enrico Scholz, sponsored by Phytec
> + *
> + * 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.
> + */
> +
> +#include <driver.h>
> +#include <fb.h>
> +#include <errno.h>
> +#include <xfuncs.h>
> +#include <init.h>
> +#include <stdio.h>
> +#include <io.h>
> +#include <common.h>
> +#include <malloc.h>
> +#include <common.h>
> +#include <clock.h>
> +
> +#include <mach/omap4-silicon.h>
> +#include <mach/omap4-fb.h>
> +
> +#include "omap4.h"
> +
> +struct omap4fb_device {
> +	struct fb_info info;
> +	struct device_d *dev;
> +
> +	struct omap4fb_display const *cur_display;
> +
> +	struct omap4fb_display const *displays;
> +	size_t num_displays;
> +
> +	struct {
> +		struct omap4_regs_dss __iomem *dss;
> +		struct omap4_regs_dispc __iomem *dispc;
> +	} regs;
> +
> +	struct {
> +		void __iomem *addr;
> +		size_t size;
> +	} prealloc_screen;
> +
> +	struct {
> +		uint32_t dispc_control;
> +		uint32_t dispc_pol_freq;
> +	} shadow;
> +
> +	struct {
> +		unsigned int dss_clk_hz;
> +		unsigned int lckd;
> +		unsigned int pckd;
> +	} divisor;
> +
> +	void (*enable_fn)(int);
> +
> +	struct fb_videomode	video_modes[];
> +};
> +
> +static inline void fb_write(uint32_t v, void __iomem *addr)
> +{
> +	__raw_writel(v, addr);
> +}
> +
> +static inline uint32_t fb_read(void const __iomem *addr)
> +{
> +	return __raw_readl(addr);
> +}
> +
> +static void omap4fb_enable(struct fb_info *info)
> +{
> +	struct omap4fb_device *fbi =
> +		container_of(info, struct omap4fb_device, info);
> +	struct omap4_regs_dispc __iomem	*dispc = fbi->regs.dispc;
> +
> +	dev_info(fbi->dev, "%s\n", __func__);
> +
> +	if (!fbi->cur_display) {
> +		dev_err(fbi->dev, "no valid mode set\n");
> +		return;
> +	}
> +
> +	if (fbi->enable_fn)
> +		fbi->enable_fn(1);
> +
> +	udelay(fbi->cur_display->power_on_delay * 1000u);
> +
> +	fb_write(fb_read(&dispc->control2) |
> +		 DSS_DISPC_CONTROL_LCDENABLE |
> +		 1*DSS_DISPC_CONTROL_LCDENABLESIGNAL,
> +		 &dispc->control2);
> +
> +	fb_write(fb_read(&dispc->vid1.attributes) |
> +		 DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE,
> +		 &dispc->vid1.attributes);
> +
> +	fb_write(fb_read(&dispc->control2) |
> +		 DSS_DISPC_CONTROL_GOLCD,
> +		 &dispc->control2);
> +}
> +
> +static void omap4fb_disable(struct fb_info *info)
> +{
> +	struct omap4fb_device	*fbi =
> +		container_of(info, struct omap4fb_device, info);
> +	struct omap4_regs_dispc __iomem	*dispc = fbi->regs.dispc;
> +
> +	dev_info(fbi->dev, "%s\n", __func__);
> +
> +	if (!fbi->cur_display) {
> +		dev_err(fbi->dev, "no valid mode set\n");
> +		return;
> +	}
> +
> +	fb_write(fb_read(&dispc->control2) &
> +		 ~(DSS_DISPC_CONTROL_LCDENABLE |
> +		   DSS_DISPC_CONTROL_LCDENABLESIGNAL),
> +		 &dispc->control2);
> +
> +	fb_write(fb_read(&dispc->vid1.attributes) &
> +		 ~(DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE),
> +		 &dispc->vid1.attributes);
> +
> +	if (fbi->prealloc_screen.addr == NULL)
> +		/* free frame buffer; but only when screen is not
> +		 * preallocated */
> +		free(info->screen_base);
> +
> +	info->screen_base = NULL;
> +
> +	udelay(fbi->cur_display->power_off_delay * 1000u);
> +
> +	if (fbi->enable_fn)
> +		fbi->enable_fn(0);
> +}
> +
> +static void omap4fb_calc_divisor(struct omap4fb_device *fbi,
> +			struct fb_videomode const *mode)
> +{
> +	unsigned int l, k, t, b;
> +
> +	b = UINT_MAX;
> +	for (l = 1; l < 256; l++) {
> +		for (k = 1; k < 256; k++) {
> +			t = abs(mode->pixclock * 100 -
> +				(fbi->divisor.dss_clk_hz / l / k));
> +			if (t <= b) {
> +				b = t;
> +				fbi->divisor.lckd = l;
> +				fbi->divisor.pckd = k;
> +			}
> +		}
> +	}
> +}
> +
> +static unsigned int omap4fb_calc_format(struct fb_info const *info)
> +{
> +	switch (info->bits_per_pixel) {
> +	case 24: return 9;
> +	case 32: return 0x8; /* xRGB24-8888 (32-bit container) */
> +	default:
> +		printf("%s: unsupported bpp %d\n", __func__,
> +		       info->bits_per_pixel);
> +		return 0;
> +	}
> +}
> +
> +struct omap4fb_colors {
> +	struct fb_bitfield	red;
> +	struct fb_bitfield	green;
> +	struct fb_bitfield	blue;
> +	struct fb_bitfield	transp;
> +};
> +
> +static struct omap4fb_colors const omap4fb_col[] = {
> +	[0] = {
> +		.red	= { .length = 0, .offset = 0 },
> +	},
> +	[1] = {
> +		.blue	= { .length = 8, .offset = 0 },
> +		.green	= { .length = 8, .offset = 8 },
> +		.red	= { .length = 8, .offset = 16 },
> +	},
> +	[2] = {
> +		.blue	= { .length = 8, .offset = 0 },
> +		.green	= { .length = 8, .offset = 8 },
> +		.red	= { .length = 8, .offset = 16 },
> +		.transp	= { .length = 8, .offset = 24 },
> +	},
> +};
> +
> +static void omap4fb_fill_shadow(struct omap4fb_device *fbi,
> +				struct omap4fb_display const *display)
> +{
> +	fbi->shadow.dispc_control = 0;
> +	fbi->shadow.dispc_pol_freq = 0;
> +
> +	fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_STNTFT;
> +
> +	switch (display->config & OMAP_DSS_LCD_DATALINES_msk) {
> +	case OMAP_DSS_LCD_DATALINES_12:
> +		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_12;
> +		break;
> +	case OMAP_DSS_LCD_DATALINES_16:
> +		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_16;
> +		break;
> +	case OMAP_DSS_LCD_DATALINES_18:
> +		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_18;
> +		break;
> +	case OMAP_DSS_LCD_DATALINES_24:
> +		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_24;
> +		break;
> +	}
> +
> +	if (display->config & OMAP_DSS_LCD_IPC)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IPC;
> +
> +	if (display->config & OMAP_DSS_LCD_IVS)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IVS;
> +
> +	if (display->config & OMAP_DSS_LCD_IHS)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IHS;
> +
> +	if (display->config & OMAP_DSS_LCD_IEO)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IEO;
> +
> +	if (display->config & OMAP_DSS_LCD_RF)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_RF;
> +
> +	if (display->config & OMAP_DSS_LCD_ONOFF)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_ONOFF;
> +}
> +
> +static int omap4fb_activate_var(struct fb_info *info)
> +{
> +	struct omap4fb_device *fbi =
> +		container_of(info, struct omap4fb_device, info);
> +	struct omap4_regs_dispc __iomem	*dispc = fbi->regs.dispc;
> +	struct fb_videomode const *mode = info->mode;
> +	size_t size = mode->xres * mode->yres * (info->bits_per_pixel / 8);
> +	int rc;
> +	unsigned int fmt = omap4fb_calc_format(info);
> +	struct omap4fb_colors const *cols;
> +	size_t i;
> +	struct omap4fb_display const *new_display = NULL;
> +
> +	for (i = 0; i < fbi->num_displays && new_display == NULL; ++i) {
> +		if (strcmp(mode->name, fbi->displays[i].mode.name) == 0)
> +			new_display = &fbi->displays[i];
> +	}
> +
> +	if (WARN_ON(!new_display)) {
> +		dev_err(fbi->dev, "no matching display found for this mode '%s'\n",
> +			mode->name);
> +		rc = -ENXIO;
> +		goto out;
> +	}
> +
> +	if (fbi->prealloc_screen.addr == NULL) {
> +		/* case 1: no preallocated screen */
> +		free(info->screen_base);
> +		info->screen_base = memalign(0x100, size);
> +	} else if (fbi->prealloc_screen.size < size) {
> +		/* case 2: preallocated screen, but too small */
> +		dev_err(fbi->dev,
> +			"allocated framebuffer too small (%zu < %zu)\n",
> +			fbi->prealloc_screen.size, size);
> +		rc = -ENOMEM;
> +		goto out;
> +	} else {
> +		/* case 3: preallocated screen */
> +		info->screen_base = fbi->prealloc_screen.addr;
> +	}
> +
> +	omap4fb_fill_shadow(fbi, new_display);
> +
> +	omap4fb_calc_divisor(fbi, mode);
> +
> +	switch (info->bits_per_pixel) {
> +	case 24:
> +		cols = &omap4fb_col[1];
> +		break;
> +	case 32:
> +		cols = &omap4fb_col[2];
> +		break;
> +	default:
> +		cols = &omap4fb_col[0];
> +	}
> +
> +	info->red = cols->red;
> +	info->green = cols->green;
> +	info->blue = cols->blue;
> +	info->transp = cols->transp;
> +
> +	fb_write(fbi->shadow.dispc_control,
> +		 &dispc->control2);
> +
> +	fb_write(fbi->shadow.dispc_pol_freq,
> +		 &dispc->pol_freq2);
> +
> +	fb_write(DSS_DISPC_TIMING_H_HSW(mode->hsync_len - 1) |
> +		 DSS_DISPC_TIMING_H_HFP(mode->right_margin - 1) |
> +		 DSS_DISPC_TIMING_H_HBP(mode->left_margin - 1),
> +		 &dispc->timing_h2);
> +
> +	fb_write(DSS_DISPC_TIMING_V_VSW(mode->vsync_len - 1) |
> +		 DSS_DISPC_TIMING_V_VFP(mode->lower_margin) |
> +		 DSS_DISPC_TIMING_V_VBP(mode->upper_margin),
> +		 &dispc->timing_v2);
> +
> +	fb_write(DSS_DISPC_DIVISOR_ENABLE | DSS_DISPC_DIVISOR_LCD(1),
> +			&dispc->divisor);
> +
> +	fb_write(DSS_DISPC_DIVISOR2_LCD(fbi->divisor.lckd) |
> +		 DSS_DISPC_DIVISOR2_PCD(fbi->divisor.pckd),
> +		 &dispc->divisor2);
> +
> +	fb_write(DSS_DISPC_SIZE_LCD_PPL(mode->xres - 1) |
> +		 DSS_DISPC_SIZE_LCD_LPP(mode->yres - 1),
> +		 &dispc->size_lcd2);
> +
> +	fb_write(0x0000FF00, &dispc->default_color2);
> +
> +	/* we use VID1 */
> +	fb_write((uintptr_t)info->screen_base, &dispc->vid1.ba[0]);
> +	fb_write((uintptr_t)info->screen_base, &dispc->vid1.ba[1]);
> +
> +	fb_write(DSS_DISPC_VIDn_POSITION_VIDPOSX(0) |
> +		 DSS_DISPC_VIDn_POSITION_VIDPOSY(0),
> +		 &dispc->vid1.position);
> +	fb_write(DSS_DISPC_VIDn_SIZE_VIDSIZEX(mode->xres - 1) |
> +		 DSS_DISPC_VIDn_SIZE_VIDSIZEY(mode->yres - 1),
> +		 &dispc->vid1.size);
> +	fb_write(DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(mode->xres - 1) |
> +		 DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(mode->yres - 1),
> +		 &dispc->vid1.picture_size);
> +	fb_write(1, &dispc->vid1.row_inc);
> +	fb_write(1, &dispc->vid1.pixel_inc);
> +
> +	fb_write(0xfff, &dispc->vid_preload[0]);
> +
> +	fb_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
> +			 DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
> +			 DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
> +			 DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
> +			 &dispc->vid1.attributes);
> +
> +	while (fb_read(&dispc->control2) & DSS_DISPC_CONTROL_GOLCD)
> +		;			/* noop */
> +
> +	fb_write(fb_read(&dispc->control2) |
> +		 DSS_DISPC_CONTROL_GOLCD,
> +		 &dispc->control2);
> +
> +	fbi->cur_display = new_display;
> +	info->xres = mode->xres;
> +	info->yres = mode->yres;
> +
> +	rc = 0;
> +
> +out:
> +	return rc;
> +}
> +
> +static void omap4fb_reset(struct omap4fb_device const *fbi)
> +{
> +	struct omap4_regs_dispc __iomem	*dispc = fbi->regs.dispc;
> +	struct omap4_regs_dss __iomem *dss = fbi->regs.dss;
> +
> +	uint32_t	v = fb_read(&dispc->control2);
> +
> +	/* step 1: stop the LCD controller */
> +	if (v & DSS_DISPC_CONTROL_LCDENABLE) {
> +		fb_write(v & ~DSS_DISPC_CONTROL_LCDENABLE,
> +			 &dispc->control2);
> +
> +		fb_write(DSS_DISPC_IRQSTATUS_FRAMEDONE2, &dispc->irqstatus);
> +
> +		while ((fb_read(&dispc->irqstatus) &
> +			DSS_DISPC_IRQSTATUS_FRAMEDONE) == 0)
> +			;		/* noop */
> +	}
> +
> +	/* step 2: wait for reset done status */
> +	while (!(fb_read(&dss->sysstatus) & DSS_DSS_SYSSTATUS_RESETDONE))
> +		;			/* noop */
> +
> +	/* DSS_CTL: set to reset value */
> +	fb_write(0, &dss->ctrl);
> +}
> +
> +static struct fb_ops omap4fb_ops = {
> +	.fb_enable		= omap4fb_enable,
> +	.fb_disable		= omap4fb_disable,
> +	.fb_activate_var	= omap4fb_activate_var,
> +};
> +
> +static int omap4fb_probe(struct device_d *dev)
> +{
> +	struct omap4fb_platform_data const *pdata = dev->platform_data;
> +	struct omap4fb_device *fbi;
> +	struct fb_info *info;
> +	struct omap4_regs_dispc __iomem	*dispc;
> +	struct omap4_regs_dss __iomem *dss;
> +	int rc;
> +	size_t i;
> +
> +	if (!pdata)
> +		return -ENODEV;
> +
> +	fbi = xzalloc(sizeof *fbi +
> +		      pdata->num_displays * sizeof fbi->video_modes[0]);
> +	info = &fbi->info;
> +
> +	fbi->dev = dev;
> +
> +	/* CM_DSS_CLKSTCTRL (TRM: 935) trigger SW_WKUP */
> +	__raw_writel(0x2, 0x4a009100); /* TODO: move this to clockmanagement */
> +
> +	fbi->regs.dss   = dev_request_mem_region_by_name(dev, "omap4_dss");
> +	fbi->regs.dispc = dev_request_mem_region_by_name(dev, "omap4_dispc");
> +
> +	if (!fbi->regs.dss || !fbi->regs.dispc) {
> +		dev_err(dev, "Insufficient register description\n");
> +		rc = -EINVAL;
> +		goto out;
> +	}
> +
> +	dispc = fbi->regs.dispc;
> +	dss = fbi->regs.dss;
> +	dev_info(dev, "HW-Revision 0x%04x 0x%04x\n",
> +		fb_read(&dispc->revision),
> +		fb_read(&dss->revision));
> +
> +
> +	if (!pdata->dss_clk_hz | !pdata->displays | !pdata->num_displays |
> +		!pdata->bpp) {
> +		dev_err(dev, "Insufficient omap4fb_platform_data\n");
> +		rc = -EINVAL;
> +		goto out;
> +	}
> +
> +	fbi->enable_fn    = pdata->enable;
> +	fbi->displays     = pdata->displays;
> +	fbi->num_displays = pdata->num_displays;
> +	fbi->divisor.dss_clk_hz = pdata->dss_clk_hz;
> +
> +	for (i = 0; i < pdata->num_displays; ++i)
> +		fbi->video_modes[i] = pdata->displays[i].mode;
> +
> +	info->mode_list = fbi->video_modes;
> +	info->num_modes = pdata->num_displays;
> +
> +	info->priv = fbi;
> +	info->fbops = &omap4fb_ops;
> +	info->bits_per_pixel = pdata->bpp;
> +
> +	if (pdata->screen) {
> +		fbi->prealloc_screen.addr =
> +				(void __iomem *)pdata->screen->start;
> +		fbi->prealloc_screen.size = resource_size(pdata->screen);
> +	}
> +
> +	omap4fb_reset(fbi);
> +
> +	dev_add_param(fbi->dev, "bootargs", NULL, NULL, 0);
> +
> +	rc = register_framebuffer(info);
> +	if (rc < 0) {
> +		dev_err(dev, "failed to register framebuffer: %d\n", rc);
> +		goto out;
> +	}
> +
> +	rc = 0;
> +	dev_info(dev, "registered\n");
> +
> +out:
> +	if (rc < 0)
> +		free(fbi);
> +
> +	return rc;
> +}
> +
> +static struct driver_d omap4fb_driver = {
> +	.name	= "omap4_fb",
> +	.probe	= omap4fb_probe,
> +};
> +
> +static int omap4fb_init(void)
> +{
> +	return platform_driver_register(&omap4fb_driver);
> +}
> +
> +device_initcall(omap4fb_init);
> diff --git a/drivers/video/omap4.h b/drivers/video/omap4.h
> new file mode 100644
> index 0000000..b3364a5
> --- /dev/null
> +++ b/drivers/video/omap4.h
> @@ -0,0 +1,408 @@
> +/*
> + * TI Omap4 Frame Buffer device driver
> + *
> + * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.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.
> + */
> +
> +#ifndef H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
> +#define H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
> +
> +#include <types.h>
> +#include <common.h>
> +
> +#define OMAP4_RESERVED(_f, _t) \
> +	uint32_t const reserved_ ## _f ## _ ## _t[((_t) - (_f)) / 4]
> +
> +
> +/* TRM: 10.1.3.2 DSS Registers */
> +struct omap4_regs_dss {
> +	uint32_t revision;
> +	OMAP4_RESERVED(0x4, 0x14);
> +	uint32_t const sysstatus;
> +	OMAP4_RESERVED(0x18, 0x40);
> +	uint32_t ctrl;
> +	OMAP4_RESERVED(0x44, 0x5C);
> +	uint32_t const status;
> +};
> +
> +
> +struct omap4_regs_dispc_vid {
> +	uint32_t ba[2];
> +	uint32_t position;
> +	uint32_t size;
> +	uint32_t attributes;
> +	uint32_t buf_threshold;
> +	uint32_t const buf_size_status;
> +	uint32_t row_inc;
> +	uint32_t pixel_inc;
> +	uint32_t fir;
> +	uint32_t picture_size;
> +	uint32_t accu[2];
> +	struct {
> +		uint32_t h;
> +		uint32_t hv;
> +	} fir_coef[8];
> +	uint32_t conv_coef0;
> +	uint32_t conv_coef1;
> +	uint32_t conv_coef2;
> +	uint32_t conv_coef3;
> +	uint32_t conv_coef4;
> +};
> +
> +/* TRM: 10.2.7.3 Display Controller Registers */
> +struct omap4_regs_dispc {
> +	uint32_t const revision;
> +	OMAP4_RESERVED(0x04, 0x10);
> +	uint32_t sysconfig;
> +	uint32_t const sysstatus;
> +	uint32_t irqstatus;
> +	uint32_t irqenable;
> +	OMAP4_RESERVED(0x20, 0x40);
> +	uint32_t control1;
> +	uint32_t config1;
> +	OMAP4_RESERVED(0x48, 0x4C);
> +
> +	uint32_t default_color[2];
> +	uint32_t trans_color[2];
> +
> +	uint32_t const line_status;
> +	uint32_t line_number;
> +	uint32_t timing_h1;
> +	uint32_t timing_v1;
> +	uint32_t pol_freq1;
> +	uint32_t divisor1;
> +	uint32_t global_alpha;
> +	uint32_t size_tv;
> +	uint32_t size_lcd1;
> +
> +	struct {
> +		uint32_t ba[2];
> +		uint32_t position;
> +		uint32_t size;
> +		OMAP4_RESERVED(0x90, 0xA0);
> +		uint32_t attributes;
> +		uint32_t buf_threshold;
> +		uint32_t const buf_size_status;
> +		uint32_t row_inc;
> +		uint32_t pixel_inc;
> +		OMAP4_RESERVED(0xB4, 0xB8);
> +		uint32_t table_ba;
> +	} gfx;
> +
> +	struct omap4_regs_dispc_vid vid1;
> +	OMAP4_RESERVED(0x144, 0x14C);
> +	struct omap4_regs_dispc_vid vid2;
> +
> +	uint32_t data1_cycle[3];
> +
> +	uint32_t vid1_fir_coef_v[8];
> +	uint32_t vid2_fir_coef_v[8];
> +	uint32_t cpr1_coef_r;
> +	uint32_t cpr1_coef_g;
> +	uint32_t cpr1_coef_b;
> +	uint32_t gfx_preload;
> +	uint32_t vid_preload[2];
> +	uint32_t control2;
> +	OMAP4_RESERVED(0x23C, 0x300);
> +
> +	struct {
> +		uint32_t accu[2];
> +		uint32_t ba[2];
> +		struct {
> +			uint32_t h;
> +			uint32_t hv;
> +		} fir_coef[8];
> +		uint32_t fir_coef_v[8];
> +		uint32_t attributes;
> +		uint32_t conv_coef0;
> +		uint32_t conv_coef1;
> +		uint32_t conv_coef2;
> +		uint32_t conv_coef3;
> +		uint32_t conv_coef4;
> +		uint32_t const buf_size_status;
> +		uint32_t buf_threshold;
> +		uint32_t fir;
> +		uint32_t picture_size;
> +		uint32_t pixel_inc;
> +		uint32_t position;
> +		uint32_t preload;
> +		uint32_t row_inc;
> +		uint32_t size;
> +	} vid3;
> +
> +	uint32_t default_color2;
> +	uint32_t trans_color2;
> +	uint32_t cpr2_coef_b;
> +	uint32_t cpr2_coef_g;
> +	uint32_t cpr2_coef_r;
> +	uint32_t data2_cycle[3];
> +	uint32_t size_lcd2;
> +	OMAP4_RESERVED(0x3D0, 0x400);
> +	uint32_t timing_h2;
> +	uint32_t timing_v2;
> +	uint32_t pol_freq2;
> +	uint32_t divisor2;
> +	OMAP4_RESERVED(0x410, 0x500);
> +
> +	struct {
> +		uint32_t accu[2];
> +		uint32_t ba[2];
> +		struct {
> +			uint32_t h;
> +			uint32_t hv;
> +		} fir_coef[8];
> +		uint32_t fir_coef_v[8];
> +		uint32_t attributes;
> +		uint32_t conv_coef0;
> +		uint32_t conv_coef1;
> +		uint32_t conv_coef2;
> +		uint32_t conv_coef3;
> +		uint32_t conv_coef4;
> +		uint32_t const buf_size_status;
> +		uint32_t buf_threshold;
> +		uint32_t fir;
> +		uint32_t picture_size;
> +		uint32_t pixel_inc;
> +		OMAP4_RESERVED(0x59C, 0x5A4);
> +		uint32_t row_inc;
> +		uint32_t size;
> +	} wb;
> +
> +	OMAP4_RESERVED(0x5AC, 0x600);
> +	uint32_t vid1_ba_uv[2];
> +	uint32_t vid2_ba_uv[2];
> +	uint32_t vid3_ba_uv[2];
> +	uint32_t wb_ba_uv[2];
> +	uint32_t config2;
> +	uint32_t vid1_attributes2;
> +	uint32_t vid2_attributes2;
> +	uint32_t vid3_attributes2;
> +	uint32_t gamma_table0;
> +	uint32_t gamma_table1;
> +	uint32_t gamma_table2;
> +	uint32_t vid1_fir2;
> +	uint32_t vid1_accu2[2];
> +	struct {
> +		uint32_t h2;
> +		uint32_t hv2;
> +	} vid1_fir_coef[8];
> +	uint32_t vid1_fir_coef_v2[8];
> +	uint32_t vid2_fir2;
> +	uint32_t vid2_accu2[2];
> +	struct {
> +		uint32_t h2;
> +		uint32_t hv2;
> +	} vid2_fir_coef[8];
> +	uint32_t vid2_fir_coef_v2[8];
> +	OMAP4_RESERVED(0x714, 0x724);
> +	uint32_t vid3_fir2;
> +	uint32_t vid3_accu2[2];
> +	struct {
> +		uint32_t h2;
> +		uint32_t hv2;
> +	} vid3_fir_coef[8];
> +	uint32_t vid3_fir_coef_v2[8];
> +	uint32_t wb_fir2;
> +	uint32_t wb_accu2[2];
> +	OMAP4_RESERVED(0x79C, 0x7A0);
> +	struct {
> +		uint32_t h2;
> +		uint32_t hv2;
> +	} wb_fir_coef[8];
> +	uint32_t wb_fir_coef_v2[8];
> +	uint32_t global_buffer;
> +	uint32_t divisor;
> +	OMAP4_RESERVED(0x808, 0x810);
> +	uint32_t wb_attributes2;
> +};
> +
> +#define DSS_DISPC_VIDn_POSITION_VIDPOSX(_x)		((_x) << 0)
> +#define DSS_DISPC_VIDn_POSITION_VIDPOSY(_y)		((_y) << 16)
> +
> +#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(_x)	((_x) << 0)
> +#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(_y)	((_y) << 16)
> +
> +#define DSS_DISPC_VIDn_SIZE_VIDSIZEX(_x)		((_x) << 0)
> +#define DSS_DISPC_VIDn_SIZE_VIDSIZEY(_y)		((_y) << 16)
> +
> +#define DSS_DISPC_SIZE_LCD_PPL(_x)			((_x) << 0)
> +#define DSS_DISPC_SIZE_LCD_LPP(_y)			((_y) << 16)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE		(1u << 0)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(_fmt)	((_fmt) << 1)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB12	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(4u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(5u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB16	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(6u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16o	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(7u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB24u	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(8u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB24p	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(9u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_YUV2	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(10u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_UYVY	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(11u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB32	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(12u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGBA32	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(13u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB32	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(14u)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(_f)	((_f) << 5)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE_NONE \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(0u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE_H \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(1u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE_V \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(2u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE_HV \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDRESIZEENABLE(3u)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCOLORCONVENABLE	(1u << 9)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDREPLICATIONENABLE	(1u << 10)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFULLRANGE		(1u << 11)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(_r)	((_r) << 12)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION_0 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(0u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION_90 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(1u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION_180 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(2u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION_270 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDROTATION(3u)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(_b)	((_b) << 14)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_2x128 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(0u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_4x128 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(1u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(2u)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCHANNELOUT	(1u << 16)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_SELFREFRESHAUTO	(1u << 17)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFIFOPRELOAD	(1u << 19)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDVERTICALTAPS	(1u << 21)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_DOUBLESTRIDE		(1u << 22)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDARBITRATION	(1u << 23)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDSELFREFRESH	(1u << 24)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE		(1u << 25)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(_b)  ((_b) << 30)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_PRIMARY_LCD \
> +	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(0u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD \
> +	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(1u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_WRITEBACK_MEM \
> +	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(3u)
> +
> +#define DSS_DISPC_CONFIG_PIXELGATED			(1u << 0)
> +#define DSS_DISPC_CONFIG_PIXELDATAGATED		(1u << 4)
> +#define DSS_DISPC_CONFIG_PIXELCLOCKGATED		(1u << 5)
> +#define DSS_DISPC_CONFIG_HSYNCGATED			(1u << 6)
> +#define DSS_DISPC_CONFIG_VSYNCGATED			(1u << 7)
> +#define DSS_DISPC_CONFIG_ACBIASGATED			(1u << 8)
> +#define DSS_DISPC_CONFIG_FUNCGATED			(1u << 9)
> +#define DSS_DISPC_CONFIG_TCKLCDENABLE			(1u << 10)
> +#define DSS_DISPC_CONFIG_TCKLCDSELECTION		(1u << 11)
> +#define DSS_DISPC_CONFIG_CPR				(1u << 15)
> +#define DSS_DISPC_CONFIG_FIFOHANDCHECK			(1u << 16)
> +#define DSS_DISPC_CONFIG_OUTPUTMODE			(1u << 22)
> +#define DSS_DISPC_CONFIG_FIDFIRST			(1u << 23)
> +#define DSS_DISPC_CONFIG_COLORCONV			(1u << 24)
> +#define DSS_DISPC_CONFIG_FULLRANGE			(1u << 25)
> +
> +#define DSS_DISPC_CONTROL_LCDENABLE			(1u << 0)
> +#define DSS_DISPC_CONTROL_TVENABLE			(1u << 1)
> +#define DSS_DISPC_CONTROL_MONOCOLOR			(1u << 2)
> +#define DSS_DISPC_CONTROL_STNTFT			(1u << 3)
> +#define DSS_DISPC_CONTROL_M8B				(1u << 4)
> +#define DSS_DISPC_CONTROL_GOLCD			(1u << 5)
> +#define DSS_DISPC_CONTROL_GOTV				(1u << 6)
> +#define DSS_DISPC_CONTROL_STDITHERENABLE		(1u << 7)
> +
> +#define DSS_DISPC_CONTROL_TFTDATALINES(_l)		((_l) << 8)
> +#define DSS_DISPC_CONTROL_TFTDATALINES_12 \
> +	DSS_DISPC_CONTROL_TFTDATALINES(0u)
> +#define DSS_DISPC_CONTROL_TFTDATALINES_16 \
> +	DSS_DISPC_CONTROL_TFTDATALINES(1u)
> +#define DSS_DISPC_CONTROL_TFTDATALINES_18 \
> +	DSS_DISPC_CONTROL_TFTDATALINES(2u)
> +#define DSS_DISPC_CONTROL_TFTDATALINES_24 \
> +	DSS_DISPC_CONTROL_TFTDATALINES(3u)
> +
> +#define DSS_DISPC_CONTROL_STALLMODE			(1u << 11)
> +#define DSS_DISPC_CONTROL_OVERLAYOPTIMIZATION		(1u << 12)
> +#define DSS_DISPC_CONTROL_GPIN0			(1u << 13) /* ro */
> +#define DSS_DISPC_CONTROL_GPIN1			(1u << 14) /* ro */
> +#define DSS_DISPC_CONTROL_GPOUT0			(1u << 15)
> +#define DSS_DISPC_CONTROL_GPOUT1			(1u << 16)
> +#define DSS_DISPC_CONTROL_HT(_ht)			((_ht) << 17)
> +#define DSS_DISPC_CONTROL_TDMENABLE			(1u << 20)
> +#define DSS_DISPC_CONTROL_TDMPARALLELMODE(_pm)		((_pm) << 21)
> +#define DSS_DISPC_CONTROL_TDMCYCLEFORMAT(_cf)		((_cf) << 23)
> +#define DSS_DISPC_CONTROL_TDMUNUSEDBITS(_ub)		((_ub) << 25)
> +#define DSS_DISPC_CONTROL_PCKFREEENABLE		(1u << 27)
> +#define DSS_DISPC_CONTROL_LCDENABLESIGNAL		(1u << 28)
> +#define DSS_DISPC_CONTROL_LCDENABLEPOL			(1u << 29)
> +#define DSS_DISPC_CONTROL_SPATIALTEMPD(_df)		((_df) << 30)
> +
> +#define DSS_DISPC_POL_FREQ_IVS				(1u << 12)
> +#define DSS_DISPC_POL_FREQ_IHS				(1u << 13)
> +#define DSS_DISPC_POL_FREQ_IPC				(1u << 14)
> +#define DSS_DISPC_POL_FREQ_IEO				(1u << 15)
> +#define DSS_DISPC_POL_FREQ_RF				(1u << 16)
> +#define DSS_DISPC_POL_FREQ_ONOFF			(1u << 17)
> +
> +#define DSS_DISPC_TIMING_H_HSW(_hsw)			((_hsw) << 0)
> +#define DSS_DISPC_TIMING_H_HFP(_hfp)			((_hfp) << 8)
> +#define DSS_DISPC_TIMING_H_HBP(_hbp)			((_hbp) << 20)
> +
> +#define DSS_DISPC_TIMING_V_VSW(_vsw)			((_vsw) << 0)
> +#define DSS_DISPC_TIMING_V_VFP(_vfp)			((_vfp) << 8)
> +#define DSS_DISPC_TIMING_V_VBP(_vbp)			((_vbp) << 20)
> +
> +#define DSS_DISPC_DIVISOR_ENABLE			(1u << 0)
> +#define DSS_DISPC_DIVISOR_LCD(_lcd)			((_lcd) << 16)
> +
> +#define DSS_DISPC_DIVISOR2_PCD(_pcd)			((_pcd) << 0)
> +#define DSS_DISPC_DIVISOR2_LCD(_lcd)			((_lcd) << 16)
> +
> +#define DSS_DISPC_IRQSTATUS_FRAMEDONE			(1u << 0)
> +#define DSS_DISPC_IRQSTATUS_FRAMEDONE2			(1u << 22)
> +
> +#define DSS_DSS_SYSCONFIG_SOFTRESET			(1u << 1)
> +#define DSS_DSS_SYSSTATUS_RESETDONE			(1u << 0)
> +
> +#define DSS_DSS_CONTROL_DISPC_CLK_SWITCH		(1u << 0)
> +#define DSS_DSS_CONTROL_DSI_CLK_SWITCH			(1u << 1)
> +
> +#define CM_FCLKEN_DSS_EN_DSS1	(1u << 0)
> +#define CM_FCLKEN_DSS_EN_DSS2	(1u << 1)
> +#define CM_FCLKEN_DSS_EN_TV	(1u << 2)
> +
> +#define CM_ICLKEN_DSS_EN_DSS	(1u << 0)
> +
> +
> +#undef OMAP4_RESERVED
> +
> +#endif	/* H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H */
> -- 
> 1.7.10.4
> 
> 
> 



From s.hauer at pengutronix.de  Thu Jun 13 08:48:33 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 13 Jun 2013 14:48:33 +0200
Subject: [PATCH] of: add ranges address translation for default bus
In-Reply-To: <51B9930B.8080609@gmail.com>
References: <1368400146-30443-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130519073403.GY32299@pengutronix.de>
 <51B6EED2.3010707@gmail.com>
 <20130613092557.GC32299@pengutronix.de>
 <51B9930B.8080609@gmail.com>
Message-ID: <20130613124833.GD32299@pengutronix.de>

On Thu, Jun 13, 2013 at 11:38:19AM +0200, Sebastian Hesselbarth wrote:
> On 06/13/13 11:25, Sascha Hauer wrote:
> >On Tue, Jun 11, 2013 at 11:33:06AM +0200, Sebastian Hesselbarth wrote:
> >>I started merging already, and from what I can see we should just remove
> >>the spinlocks and OF_DYNAMIC stuff (but leave of_node_get/_put as stubs)
> >
> >Sounds like a plan. Functions existing both in barebox and Linux should
> >behave the same way. However, if Linux turns out to do something silly
> >or (for our usecase) too bloated, we shouldn't do the same just because
> >Linux does it.
> >
> >I want to keep the Linux list usage in the devicetree, so they won't be
> >really in sync.
> 
> Ok, I started converting and doing it in a clean way is kind of tricky.
> 
> First of all, allyesconfig doesn't build - so it is hard to find and
> re-build all users of current of_* functions.
> 
> If you want to stick with list usage, it will end up with converting
> instead of just move current functions out of the way, import Linux
> OF, and switch users to that functions.
> 
> I will have a look at it, find users/abusers of current API and see
> how much we can merge.
> 
> You also want to stick with of_set_* and friends within base.c or
> move them out to some other source file where all set/modify functions
> will sit in?

I'm fine with moving the set/modify kernel to another file, no problem.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Thu Jun 13 14:50:30 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Thu, 13 Jun 2013 20:50:30 +0200
Subject: [PATCH] of: add ranges address translation for default bus
In-Reply-To: <20130613124833.GD32299@pengutronix.de>
References: <1368400146-30443-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130519073403.GY32299@pengutronix.de> <51B6EED2.3010707@gmail.com>
 <20130613092557.GC32299@pengutronix.de> <51B9930B.8080609@gmail.com>
 <20130613124833.GD32299@pengutronix.de>
Message-ID: <51BA1476.3060309@gmail.com>

On 06/13/13 14:48, Sascha Hauer wrote:
> On Thu, Jun 13, 2013 at 11:38:19AM +0200, Sebastian Hesselbarth wrote:
>> On 06/13/13 11:25, Sascha Hauer wrote:
>>> Sounds like a plan. Functions existing both in barebox and Linux should
>>> behave the same way. However, if Linux turns out to do something silly
>>> or (for our usecase) too bloated, we shouldn't do the same just because
>>> Linux does it.

Sascha,

pushed a branch you can have a first look at to

git://github.com/shesselba/barebox-dove.git of-sync-v1

Started fixing some functions and merged of_find_node_by_something()
functions and corresponding helpers. Also converted some users to
the new helpers. I think it is a good point to send a first patch set.

Sebastian


From chf.fritz at googlemail.com  Thu Jun 13 18:40:39 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Fri, 14 Jun 2013 00:40:39 +0200
Subject: [PATCH v4] omap4-fb: add driver
In-Reply-To: <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
References: <1365057762.3836.18.camel@mars>
 <20130405085917.GK1906@pengutronix.de> <1365372959.20809.6.camel@lovely>
 <20130408071715.GS1568@game.jcrosoft.org>
 <20130409071608.GD1906@pengutronix.de>
 <20130409132917.GX1568@game.jcrosoft.org>  <1365706897.4136.24.camel@mars>
 <1370207222.5021.0.camel@lovely> <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
Message-ID: <1371163239.4055.180.camel@mars>

This patch adds omap4 display controller support.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
changes since v2:
        - use dev_request_mem_region_by_name()
changes since v3:
	- remove register struct
	- use uncached screen_base
---
 arch/arm/mach-omap/Makefile                |    1 +
 arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
 arch/arm/mach-omap/omap4_fb.c              |   27 ++
 drivers/video/Kconfig                      |    8 +
 drivers/video/Makefile                     |    1 +
 drivers/video/omap4.c                      |  505 ++++++++++++++++++++++++++++
 drivers/video/omap4.h                      |  179 ++++++++++
 7 files changed, 767 insertions(+)
 create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
 create mode 100644 arch/arm/mach-omap/omap4_fb.c
 create mode 100644 drivers/video/omap4.c
 create mode 100644 drivers/video/omap4.h

diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 94e42c6..e70ddbd 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
 obj-$(CONFIG_SHELL_NONE) += xload.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
 obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
 obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
 obj-y += gpio.o
diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
new file mode 100644
index 0000000..5c0a54b
--- /dev/null
+++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
@@ -0,0 +1,46 @@
+#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+
+#include <fb.h>
+
+#define OMAP_DSS_LCD_TFT	(1u << 0)
+#define OMAP_DSS_LCD_IVS	(1u << 1)
+#define OMAP_DSS_LCD_IHS	(1u << 2)
+#define OMAP_DSS_LCD_IPC	(1u << 3)
+#define OMAP_DSS_LCD_IEO	(1u << 4)
+#define OMAP_DSS_LCD_RF	(1u << 5)
+#define OMAP_DSS_LCD_ONOFF	(1u << 6)
+
+#define OMAP_DSS_LCD_DATALINES(_l)	((_l) << 10)
+#define OMAP_DSS_LCD_DATALINES_msk	OMAP_DSS_LCD_DATALINES(3u)
+#define OMAP_DSS_LCD_DATALINES_12	OMAP_DSS_LCD_DATALINES(0u)
+#define OMAP_DSS_LCD_DATALINES_16	OMAP_DSS_LCD_DATALINES(1u)
+#define OMAP_DSS_LCD_DATALINES_18	OMAP_DSS_LCD_DATALINES(2u)
+#define OMAP_DSS_LCD_DATALINES_24	OMAP_DSS_LCD_DATALINES(3u)
+
+struct omap4fb_display {
+	struct fb_videomode mode;
+
+	unsigned long config;
+
+	unsigned int power_on_delay;
+	unsigned int power_off_delay;
+};
+
+struct omap4fb_platform_data {
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	unsigned int dss_clk_hz;
+
+	unsigned int bpp;
+
+	struct resource const *screen;
+
+	void (*enable)(int p);
+};
+
+struct device_d;
+struct device_d *omap4_add_display(void *pdata);
+
+#endif	/* H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H */
diff --git a/arch/arm/mach-omap/omap4_fb.c b/arch/arm/mach-omap/omap4_fb.c
new file mode 100644
index 0000000..09a6af3
--- /dev/null
+++ b/arch/arm/mach-omap/omap4_fb.c
@@ -0,0 +1,27 @@
+#include <driver.h>
+#include <common.h>
+#include <linux/ioport.h>
+#include <mach/omap4-fb.h>
+
+static struct resource omap4_fb_resources[] = {
+	{
+		.name	= "omap4_dss",
+		.start	= 0x48040000,
+		.end	= 0x48040000 + 512 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	}, {
+		.name	= "omap4_dispc",
+		.start	= 0x48041000,
+		.end	= 0x48041000 + 3072 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	},
+};
+
+struct device_d *omap4_add_display(void *pdata)
+{
+	return add_generic_device_res("omap4_fb", -1,
+				      omap4_fb_resources,
+				      ARRAY_SIZE(omap4_fb_resources),
+				      pdata);
+}
+EXPORT_SYMBOL(omap4_add_display);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 6d6b08f..9dfa0cd 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -45,6 +45,14 @@ config DRIVER_VIDEO_S3C24XX
 	help
 	  Add support for the S3C244x LCD controller.
 
+config DRIVER_VIDEO_OMAP4
+	bool "OMAP4 framebuffer driver"
+	depends on ARCH_OMAP4
+	help
+	  Add support for the OMAP4 Display Controller.
+	  DSI is unsupported, only DISPC parallel mode on LCD2
+	  is supported.
+
 if DRIVER_VIDEO_S3C24XX
 
 config DRIVER_VIDEO_S3C_VERBOSE
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 7429141..83feebb 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
 obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
 obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
 obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4.o
diff --git a/drivers/video/omap4.c b/drivers/video/omap4.c
new file mode 100644
index 0000000..74b1478
--- /dev/null
+++ b/drivers/video/omap4.c
@@ -0,0 +1,505 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.com>
+ *   Based on work by Enrico Scholz, sponsored by Phytec
+ *
+ * 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.
+ */
+
+#include <driver.h>
+#include <fb.h>
+#include <errno.h>
+#include <xfuncs.h>
+#include <init.h>
+#include <stdio.h>
+#include <io.h>
+#include <common.h>
+#include <malloc.h>
+#include <common.h>
+#include <clock.h>
+
+#include <mach/omap4-silicon.h>
+#include <mach/omap4-fb.h>
+
+#include <asm/mmu.h>
+
+#include "omap4.h"
+
+struct omap4fb_device {
+	struct fb_info info;
+	struct device_d *dev;
+
+	struct omap4fb_display const *cur_display;
+
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	void __iomem *dss;
+	void __iomem *dispc;
+
+	struct {
+		void __iomem *addr;
+		size_t size;
+	} prealloc_screen;
+
+	struct {
+		uint32_t dispc_control;
+		uint32_t dispc_pol_freq;
+	} shadow;
+
+	struct {
+		unsigned int dss_clk_hz;
+		unsigned int lckd;
+		unsigned int pckd;
+	} divisor;
+	size_t dma_size;
+	void (*enable_fn)(int);
+
+	struct fb_videomode	video_modes[];
+};
+
+static void omap4fb_enable(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	dev_info(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(1);
+
+	udelay(fbi->cur_display->power_on_delay * 1000u);
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
+		 DSS_DISPC_CONTROL_LCDENABLE |
+		 DSS_DISPC_CONTROL_LCDENABLESIGNAL,
+		 fbi->dispc, O4_DISPC_CONTROL2);
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_VID1_ATTRIBUTES) |
+		 DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE,
+		 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
+		 DSS_DISPC_CONTROL_GOLCD,
+		 fbi->dispc, O4_DISPC_CONTROL2);
+}
+
+static void omap4fb_disable(struct fb_info *info)
+{
+	struct omap4fb_device	*fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	dev_info(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) &
+		~(DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL),
+		fbi->dispc, O4_DISPC_CONTROL2);
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_VID1_ATTRIBUTES) &
+		 ~(DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE),
+		 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
+
+	if (fbi->prealloc_screen.addr == NULL) {
+		/* free frame buffer; but only when screen is not
+		 * preallocated */
+		if (info->screen_base)
+			dma_free_coherent(info->screen_base, fbi->dma_size);
+	}
+
+	info->screen_base = NULL;
+
+	udelay(fbi->cur_display->power_off_delay * 1000u);
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(0);
+}
+
+static void omap4fb_calc_divisor(struct omap4fb_device *fbi,
+			struct fb_videomode const *mode)
+{
+	unsigned int l, k, t, b;
+
+	b = UINT_MAX;
+	for (l = 1; l < 256; l++) {
+		for (k = 1; k < 256; k++) {
+			t = abs(mode->pixclock * 100 -
+				(fbi->divisor.dss_clk_hz / l / k));
+			if (t <= b) {
+				b = t;
+				fbi->divisor.lckd = l;
+				fbi->divisor.pckd = k;
+			}
+		}
+	}
+}
+
+static unsigned int omap4fb_calc_format(struct fb_info const *info)
+{
+	switch (info->bits_per_pixel) {
+	case 24: return 9;
+	case 32: return 0x8; /* xRGB24-8888 (32-bit container) */
+	default:
+		printf("%s: unsupported bpp %d\n", __func__,
+		       info->bits_per_pixel);
+		return 0;
+	}
+}
+
+struct omap4fb_colors {
+	struct fb_bitfield	red;
+	struct fb_bitfield	green;
+	struct fb_bitfield	blue;
+	struct fb_bitfield	transp;
+};
+
+static struct omap4fb_colors const omap4fb_col[] = {
+	[0] = {
+		.red	= { .length = 0, .offset = 0 },
+	},
+	[1] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+	},
+	[2] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+		.transp	= { .length = 8, .offset = 24 },
+	},
+};
+
+static void omap4fb_fill_shadow(struct omap4fb_device *fbi,
+				struct omap4fb_display const *display)
+{
+	fbi->shadow.dispc_control = 0;
+	fbi->shadow.dispc_pol_freq = 0;
+
+	fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_STNTFT;
+
+	switch (display->config & OMAP_DSS_LCD_DATALINES_msk) {
+	case OMAP_DSS_LCD_DATALINES_12:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_12;
+		break;
+	case OMAP_DSS_LCD_DATALINES_16:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_16;
+		break;
+	case OMAP_DSS_LCD_DATALINES_18:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_18;
+		break;
+	case OMAP_DSS_LCD_DATALINES_24:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_24;
+		break;
+	}
+
+	if (display->config & OMAP_DSS_LCD_IPC)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IPC;
+
+	if (display->config & OMAP_DSS_LCD_IVS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IVS;
+
+	if (display->config & OMAP_DSS_LCD_IHS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IHS;
+
+	if (display->config & OMAP_DSS_LCD_IEO)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IEO;
+
+	if (display->config & OMAP_DSS_LCD_RF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_RF;
+
+	if (display->config & OMAP_DSS_LCD_ONOFF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_ONOFF;
+}
+
+static int omap4fb_activate_var(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+	struct fb_videomode const *mode = info->mode;
+	size_t size = mode->xres * mode->yres * (info->bits_per_pixel / 8);
+	int rc;
+	unsigned int fmt = omap4fb_calc_format(info);
+	struct omap4fb_colors const *cols;
+	size_t i;
+	struct omap4fb_display const *new_display = NULL;
+
+	for (i = 0; i < fbi->num_displays && new_display == NULL; ++i) {
+		if (strcmp(mode->name, fbi->displays[i].mode.name) == 0)
+			new_display = &fbi->displays[i];
+	}
+
+	if (WARN_ON(!new_display)) {
+		dev_err(fbi->dev, "no display found for this mode '%s'\n",
+			mode->name);
+		rc = -ENXIO;
+		goto out;
+	}
+
+	/*Free old screen buf*/
+	if (!fbi->prealloc_screen.addr && info->screen_base)
+		dma_free_coherent(info->screen_base, fbi->dma_size);
+
+	fbi->dma_size = PAGE_ALIGN(size);
+
+	if (fbi->prealloc_screen.addr == NULL) {
+		/* case 1: no preallocated screen */
+		info->screen_base = dma_alloc_coherent(size);
+	} else if (fbi->prealloc_screen.size < fbi->dma_size) {
+		/* case 2: preallocated screen, but too small */
+		dev_err(fbi->dev,
+			"allocated framebuffer too small (%zu < %zu)\n",
+			fbi->prealloc_screen.size, fbi->dma_size);
+		rc = -ENOMEM;
+		goto out;
+	} else {
+		/* case 3: preallocated screen */
+		info->screen_base = fbi->prealloc_screen.addr;
+	}
+
+	omap4fb_fill_shadow(fbi, new_display);
+
+	omap4fb_calc_divisor(fbi, mode);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		cols = &omap4fb_col[1];
+		break;
+	case 32:
+		cols = &omap4fb_col[2];
+		break;
+	default:
+		cols = &omap4fb_col[0];
+	}
+
+	info->red = cols->red;
+	info->green = cols->green;
+	info->blue = cols->blue;
+	info->transp = cols->transp;
+
+	fb_write(fbi->shadow.dispc_control,
+		 fbi->dispc, O4_DISPC_CONTROL2);
+
+	fb_write(fbi->shadow.dispc_pol_freq,
+			fbi->dispc, O4_DISPC_POL_FREQ2);
+
+	fb_write(DSS_DISPC_TIMING_H_HSW(mode->hsync_len - 1) |
+		 DSS_DISPC_TIMING_H_HFP(mode->right_margin - 1) |
+		 DSS_DISPC_TIMING_H_HBP(mode->left_margin - 1),
+		 fbi->dispc, O4_DISPC_TIMING_H2);
+
+	fb_write(DSS_DISPC_TIMING_V_VSW(mode->vsync_len - 1) |
+		 DSS_DISPC_TIMING_V_VFP(mode->lower_margin) |
+		 DSS_DISPC_TIMING_V_VBP(mode->upper_margin),
+		 fbi->dispc, O4_DISPC_TIMING_V2);
+
+	fb_write(DSS_DISPC_DIVISOR_ENABLE | DSS_DISPC_DIVISOR_LCD(1),
+			fbi->dispc, O4_DISPC_DIVISOR);
+
+	fb_write(DSS_DISPC_DIVISOR2_LCD(fbi->divisor.lckd) |
+		 DSS_DISPC_DIVISOR2_PCD(fbi->divisor.pckd),
+		 fbi->dispc, O4_DISPC_DIVISOR2);
+
+	fb_write(DSS_DISPC_SIZE_LCD_PPL(mode->xres - 1) |
+		 DSS_DISPC_SIZE_LCD_LPP(mode->yres - 1),
+		 fbi->dispc, O4_DISPC_SIZE_LCD2);
+
+	fb_write(0x0000ff00, fbi->dispc, O4_DISPC_DEFAULT_COLOR2);
+
+	/* we use VID1 */
+	fb_write((uintptr_t)info->screen_base, fbi->dispc, O4_DISPC_VID1_BA0);
+	fb_write((uintptr_t)info->screen_base, fbi->dispc, O4_DISPC_VID1_BA1);
+
+	fb_write(DSS_DISPC_VIDn_POSITION_VIDPOSX(0) |
+		 DSS_DISPC_VIDn_POSITION_VIDPOSY(0),
+		 fbi->dispc, O4_DISPC_VID1_POSITION);
+	fb_write(DSS_DISPC_VIDn_SIZE_VIDSIZEX(mode->xres - 1) |
+		 DSS_DISPC_VIDn_SIZE_VIDSIZEY(mode->yres - 1),
+		 fbi->dispc, O4_DISPC_VID1_SIZE);
+	fb_write(DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(mode->xres - 1) |
+		 DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(mode->yres - 1),
+		 fbi->dispc, O4_DISPC_VID1_PICTURE_SIZE);
+	fb_write(1, fbi->dispc, O4_DISPC_VID1_ROW_INC);
+	fb_write(1, fbi->dispc, O4_DISPC_VID1_PIXEL_INC);
+
+	fb_write(0xfff, fbi->dispc, O4_DISPC_VID1_PRELOAD);
+
+	fb_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
+			 DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
+			 DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
+			 DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
+			 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
+
+	while (fb_read(fbi->dispc, O4_DISPC_CONTROL2) & DSS_DISPC_CONTROL_GOLCD)
+		;			/* noop */
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
+		 DSS_DISPC_CONTROL_GOLCD,
+		 fbi->dispc, O4_DISPC_CONTROL2);
+
+	fbi->cur_display = new_display;
+	info->xres = mode->xres;
+	info->yres = mode->yres;
+
+	rc = 0;
+
+out:
+	return rc;
+}
+
+static void omap4fb_reset(struct omap4fb_device const *fbi)
+{
+	uint32_t v = fb_read(fbi->dispc, O4_DISPC_CONTROL2);
+
+	/* step 1: stop the LCD controller */
+	if (v & DSS_DISPC_CONTROL_LCDENABLE) {
+		fb_write(v & ~DSS_DISPC_CONTROL_LCDENABLE,
+				fbi->dispc, O4_DISPC_CONTROL2);
+
+		fb_write(DSS_DISPC_IRQSTATUS_FRAMEDONE2, fbi->dispc,
+			O4_DISPC_IRQSTATUS);
+
+		while ((fb_read(fbi->dispc, O4_DISPC_IRQSTATUS) &
+			DSS_DISPC_IRQSTATUS_FRAMEDONE) == 0)
+			;		/* noop */
+	}
+
+	/* step 2: wait for reset done status */
+	while (!(fb_read(fbi->dss, O4_DSS_SYSSTATUS) &
+			DSS_DSS_SYSSTATUS_RESETDONE))
+		;			/* noop */
+
+	/* DSS_CTL: set to reset value */
+	fb_write(0, fbi->dss, O4_DSS_CTRL);
+}
+
+static struct fb_ops omap4fb_ops = {
+	.fb_enable		= omap4fb_enable,
+	.fb_disable		= omap4fb_disable,
+	.fb_activate_var	= omap4fb_activate_var,
+};
+
+static int omap4fb_probe(struct device_d *dev)
+{
+	struct omap4fb_platform_data const *pdata = dev->platform_data;
+	struct omap4fb_device *fbi;
+	struct fb_info *info;
+	int rc;
+	size_t i;
+
+	if (!pdata)
+		return -ENODEV;
+
+	fbi = xzalloc(sizeof *fbi +
+		      pdata->num_displays * sizeof fbi->video_modes[0]);
+	info = &fbi->info;
+
+	fbi->dev = dev;
+
+	/* CM_DSS_CLKSTCTRL (TRM: 935) trigger SW_WKUP */
+	__raw_writel(0x2, 0x4a009100); /* TODO: move this to clockmanagement */
+
+	fbi->dss   = dev_request_mem_region_by_name(dev, "omap4_dss");
+	fbi->dispc = dev_request_mem_region_by_name(dev, "omap4_dispc");
+
+	if (!fbi->dss || !fbi->dispc) {
+		dev_err(dev, "Insufficient register description\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	dev_info(dev, "HW-Revision 0x%04x 0x%04x\n",
+		fb_read(fbi->dss, O4_DISPC_REVISION),
+		fb_read(fbi->dss, O4_DSS_REVISION));
+
+
+	if (!pdata->dss_clk_hz | !pdata->displays | !pdata->num_displays |
+		!pdata->bpp) {
+		dev_err(dev, "Insufficient omap4fb_platform_data\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	fbi->enable_fn    = pdata->enable;
+	fbi->displays     = pdata->displays;
+	fbi->num_displays = pdata->num_displays;
+	fbi->divisor.dss_clk_hz = pdata->dss_clk_hz;
+
+	for (i = 0; i < pdata->num_displays; ++i)
+		fbi->video_modes[i] = pdata->displays[i].mode;
+
+	info->mode_list = fbi->video_modes;
+	info->num_modes = pdata->num_displays;
+
+	info->priv = fbi;
+	info->fbops = &omap4fb_ops;
+	info->bits_per_pixel = pdata->bpp;
+
+	if (pdata->screen) {
+		if (!IS_ALIGNED(pdata->screen->start, PAGE_SIZE) ||
+		    !IS_ALIGNED(resource_size(pdata->screen), PAGE_SIZE)) {
+			dev_err(dev, "screen resource not aligned\n");
+			rc = -EINVAL;
+			goto out;
+		}
+		fbi->prealloc_screen.addr =
+				(void __iomem *)pdata->screen->start;
+		fbi->prealloc_screen.size = resource_size(pdata->screen);
+		remap_range(fbi->prealloc_screen.addr,
+			fbi->prealloc_screen.size,
+			mmu_get_pte_uncached_flags());
+	}
+
+	omap4fb_reset(fbi);
+
+	dev_add_param(fbi->dev, "bootargs", NULL, NULL, 0);
+
+	rc = register_framebuffer(info);
+	if (rc < 0) {
+		dev_err(dev, "failed to register framebuffer: %d\n", rc);
+		goto out;
+	}
+
+	rc = 0;
+	dev_info(dev, "registered\n");
+
+out:
+	if (rc < 0)
+		free(fbi);
+
+	return rc;
+}
+
+static struct driver_d omap4fb_driver = {
+	.name	= "omap4_fb",
+	.probe	= omap4fb_probe,
+};
+
+static int omap4fb_init(void)
+{
+	return platform_driver_register(&omap4fb_driver);
+}
+
+device_initcall(omap4fb_init);
diff --git a/drivers/video/omap4.h b/drivers/video/omap4.h
new file mode 100644
index 0000000..d8b39f9
--- /dev/null
+++ b/drivers/video/omap4.h
@@ -0,0 +1,179 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.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.
+ */
+
+#ifndef H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+#define H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+
+#include <types.h>
+#include <common.h>
+
+#define fb_read(io, reg)		__raw_readl((io)+(reg))
+#define fb_write(val, io, reg)	__raw_writel((val), (io)+(reg))
+
+/* TRM: 10.1.3.2 DSS Registers */
+#define O4_DSS_REVISION	0x0
+#define O4_DSS_SYSSTATUS	0x14
+#define O4_DSS_CTRL		0x40
+#define O4_DSS_STATUS		0x5c
+
+/* TRM: 10.2.7.3 Display Controller Registers */
+#define O4_DISPC_REVISION		0x0
+#define O4_DISPC_IRQSTATUS		0x18
+#define O4_DISPC_CONTROL2		0x238
+#define O4_DISPC_VID1_ATTRIBUTES	0xcc
+#define O4_DISPC_TIMING_H2		0x400
+#define O4_DISPC_TIMING_V2		0x404
+#define O4_DISPC_POL_FREQ2		0x408
+#define O4_DISPC_DIVISOR2		0x40c
+#define O4_DISPC_DEFAULT_COLOR2	0x3ac
+#define O4_DISPC_SIZE_LCD2		0x3cc
+#define O4_DISPC_DIVISOR		0x804
+#define O4_DISPC_VID1_BA0		0xbc
+#define O4_DISPC_VID1_BA1		0xc0
+#define O4_DISPC_VID1_POSITION		0xc4
+#define O4_DISPC_VID1_SIZE		0xc8
+#define O4_DISPC_VID1_PICTURE_SIZE	0xe4
+#define O4_DISPC_VID1_ROW_INC		0xd8
+#define O4_DISPC_VID1_PIXEL_INC	0xdc
+#define O4_DISPC_VID1_PRELOAD		0x230
+
+#define DSS_DISPC_VIDn_POSITION_VIDPOSX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_POSITION_VIDPOSY(_y)		((_y) << 16)
+
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(_x)	((_x) << 0)
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(_y)	((_y) << 16)
+
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEY(_y)		((_y) << 16)
+
+#define DSS_DISPC_SIZE_LCD_PPL(_x)			((_x) << 0)
+#define DSS_DISPC_SIZE_LCD_LPP(_y)			((_y) << 16)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE		(1u << 0)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(_fmt)	((_fmt) << 1)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB12	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(4u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(5u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(6u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16o	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(7u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB24u	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(8u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB24p	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(9u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_YUV2	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(10u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_UYVY	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(11u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(12u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGBA32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(13u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(14u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(_b)	((_b) << 14)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_2x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_4x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(2u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCHANNELOUT	(1u << 16)
+#define DSS_DISPC_VIDn_ATTRIBUTES_SELFREFRESHAUTO	(1u << 17)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFIFOPRELOAD	(1u << 19)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDVERTICALTAPS	(1u << 21)
+#define DSS_DISPC_VIDn_ATTRIBUTES_DOUBLESTRIDE		(1u << 22)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDARBITRATION	(1u << 23)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDSELFREFRESH	(1u << 24)
+#define DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE		(1u << 25)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(_b)  ((_b) << 30)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_PRIMARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_WRITEBACK_MEM \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(3u)
+
+#define DSS_DISPC_CONTROL_LCDENABLE			(1u << 0)
+#define DSS_DISPC_CONTROL_TVENABLE			(1u << 1)
+#define DSS_DISPC_CONTROL_MONOCOLOR			(1u << 2)
+#define DSS_DISPC_CONTROL_STNTFT			(1u << 3)
+#define DSS_DISPC_CONTROL_M8B				(1u << 4)
+#define DSS_DISPC_CONTROL_GOLCD			(1u << 5)
+#define DSS_DISPC_CONTROL_GOTV				(1u << 6)
+#define DSS_DISPC_CONTROL_STDITHERENABLE		(1u << 7)
+
+#define DSS_DISPC_CONTROL_TFTDATALINES(_l)		((_l) << 8)
+#define DSS_DISPC_CONTROL_TFTDATALINES_12 \
+	DSS_DISPC_CONTROL_TFTDATALINES(0u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_16 \
+	DSS_DISPC_CONTROL_TFTDATALINES(1u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_18 \
+	DSS_DISPC_CONTROL_TFTDATALINES(2u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_24 \
+	DSS_DISPC_CONTROL_TFTDATALINES(3u)
+
+#define DSS_DISPC_CONTROL_STALLMODE			(1u << 11)
+#define DSS_DISPC_CONTROL_OVERLAYOPTIMIZATION		(1u << 12)
+#define DSS_DISPC_CONTROL_GPIN0			(1u << 13) /* ro */
+#define DSS_DISPC_CONTROL_GPIN1			(1u << 14) /* ro */
+#define DSS_DISPC_CONTROL_GPOUT0			(1u << 15)
+#define DSS_DISPC_CONTROL_GPOUT1			(1u << 16)
+#define DSS_DISPC_CONTROL_HT(_ht)			((_ht) << 17)
+#define DSS_DISPC_CONTROL_TDMENABLE			(1u << 20)
+#define DSS_DISPC_CONTROL_TDMPARALLELMODE(_pm)		((_pm) << 21)
+#define DSS_DISPC_CONTROL_TDMCYCLEFORMAT(_cf)		((_cf) << 23)
+#define DSS_DISPC_CONTROL_TDMUNUSEDBITS(_ub)		((_ub) << 25)
+#define DSS_DISPC_CONTROL_PCKFREEENABLE		(1u << 27)
+#define DSS_DISPC_CONTROL_LCDENABLESIGNAL		(1u << 28)
+#define DSS_DISPC_CONTROL_LCDENABLEPOL			(1u << 29)
+#define DSS_DISPC_CONTROL_SPATIALTEMPD(_df)		((_df) << 30)
+
+#define DSS_DISPC_POL_FREQ_IVS				(1u << 12)
+#define DSS_DISPC_POL_FREQ_IHS				(1u << 13)
+#define DSS_DISPC_POL_FREQ_IPC				(1u << 14)
+#define DSS_DISPC_POL_FREQ_IEO				(1u << 15)
+#define DSS_DISPC_POL_FREQ_RF				(1u << 16)
+#define DSS_DISPC_POL_FREQ_ONOFF			(1u << 17)
+
+#define DSS_DISPC_TIMING_H_HSW(_hsw)			((_hsw) << 0)
+#define DSS_DISPC_TIMING_H_HFP(_hfp)			((_hfp) << 8)
+#define DSS_DISPC_TIMING_H_HBP(_hbp)			((_hbp) << 20)
+
+#define DSS_DISPC_TIMING_V_VSW(_vsw)			((_vsw) << 0)
+#define DSS_DISPC_TIMING_V_VFP(_vfp)			((_vfp) << 8)
+#define DSS_DISPC_TIMING_V_VBP(_vbp)			((_vbp) << 20)
+
+#define DSS_DISPC_DIVISOR_ENABLE			(1u << 0)
+#define DSS_DISPC_DIVISOR_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_DIVISOR2_PCD(_pcd)			((_pcd) << 0)
+#define DSS_DISPC_DIVISOR2_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE			(1u << 0)
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE2			(1u << 22)
+
+#define DSS_DSS_SYSSTATUS_RESETDONE			(1u << 0)
+
+#endif	/* H_BAREBOX_DRIVER_VIDEO_O4_REGS_H */
-- 
1.7.10.4





From alex.aring at gmail.com  Fri Jun 14 02:29:11 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Fri, 14 Jun 2013 08:29:11 +0200
Subject: [PATCH v4] omap4-fb: add driver
In-Reply-To: <1371163239.4055.180.camel@mars>
References: <20130405085917.GK1906@pengutronix.de>
 <1365372959.20809.6.camel@lovely>
 <20130408071715.GS1568@game.jcrosoft.org>
 <20130409071608.GD1906@pengutronix.de>
 <20130409132917.GX1568@game.jcrosoft.org>
 <1365706897.4136.24.camel@mars> <1370207222.5021.0.camel@lovely>
 <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars>
Message-ID: <20130614062910.GA10743@x61s.8.8.8.8>

Hi,

On Fri, Jun 14, 2013 at 12:40:39AM +0200, Christoph Fritz wrote:
> This patch adds omap4 display controller support.
> 
> Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
> ---
> changes since v2:
>         - use dev_request_mem_region_by_name()
> changes since v3:
> 	- remove register struct
> 	- use uncached screen_base
> ---
>  arch/arm/mach-omap/Makefile                |    1 +
>  arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
>  arch/arm/mach-omap/omap4_fb.c              |   27 ++
>  drivers/video/Kconfig                      |    8 +
>  drivers/video/Makefile                     |    1 +
>  drivers/video/omap4.c                      |  505 ++++++++++++++++++++++++++++
>  drivers/video/omap4.h                      |  179 ++++++++++
>  7 files changed, 767 insertions(+)
>  create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
>  create mode 100644 arch/arm/mach-omap/omap4_fb.c
>  create mode 100644 drivers/video/omap4.c
>  create mode 100644 drivers/video/omap4.h
> 
> diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
> index 94e42c6..e70ddbd 100644
> --- a/arch/arm/mach-omap/Makefile
> +++ b/arch/arm/mach-omap/Makefile
> @@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
>  pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
>  obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
>  obj-$(CONFIG_SHELL_NONE) += xload.o
> +obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
>  obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
>  obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
>  obj-y += gpio.o
> diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
> new file mode 100644
> index 0000000..5c0a54b
> --- /dev/null
> +++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
> @@ -0,0 +1,46 @@

...

> +	fb_write(1, fbi->dispc, O4_DISPC_VID1_PIXEL_INC);
> +
> +	fb_write(0xfff, fbi->dispc, O4_DISPC_VID1_PRELOAD);
> +
> +	fb_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
> +			 DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
> +			 DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
> +			 DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
> +			 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
> +
> +	while (fb_read(fbi->dispc, O4_DISPC_CONTROL2) & DSS_DISPC_CONTROL_GOLCD)
> +		;			/* noop */

For busy waiting on statusbits I would prefer a mechanism like this:

start = get_time_ns();
while (condition) {
...
	if (is_timeout(start, waiting_time)) {
		dev_err(dev, "foo"
		return -ETIMEOUT;
	}
	mdelay(interval);
...
}

I mean it avoid deadlocks in barebox and it's better to start linux
without a display instead of a deadlock in barebox.
On the other hand you need a waiting_time which works with all displays
together. Don't know if there any hardware dependency.

}
> +
> +	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
> +		 DSS_DISPC_CONTROL_GOLCD,
> +		 fbi->dispc, O4_DISPC_CONTROL2);
> +
> +	fbi->cur_display = new_display;
> +	info->xres = mode->xres;
> +	info->yres = mode->yres;
> +
> +	rc = 0;
> +
> +out:
> +	return rc;
> +}

...

> +
> +	omap4fb_reset(fbi);
> +
> +	dev_add_param(fbi->dev, "bootargs", NULL, NULL, 0);
> +
Jean-Christophe PLAGNIOL-VILLARD said why we need this here in the last
mails. I don't saw any answer to this and asking myself... what do this
function?

Regards
Alex


From alex.aring at gmail.com  Fri Jun 14 03:02:15 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Fri, 14 Jun 2013 09:02:15 +0200
Subject: NAND + imx53, BBT/timings?
In-Reply-To: <E78BBE677EB9144B8F0A0A29674CD5338ECF0A3DAA@SRV-VS06.TELEVIC.COM>
References: <E78BBE677EB9144B8F0A0A29674CD5338ECF0A3DAA@SRV-VS06.TELEVIC.COM>
Message-ID: <20130614070213.GA13398@x61s.8.8.8.8>

Hi,

On Thu, Jun 13, 2013 at 09:09:11AM +0200, Vanhauwaert Wouter wrote:
> Hi all,
> 
> I'm working on a custom design which has an imx53 and a 1GB NAND flash (Samsung k9k8g08u0d) via an 8 bit bus.
> So I added this imx_nand_platform_data structure with a .width=1, .hw_ecc=1 and .flash_bbt=1.
> The flash gets detected at startup (also loads the bootloader from it).
> 
> nand: Manufacturer ID: 0xec, Chip ID: 0xd3 (Samsung NAND 1GiB 3,3V 8-bit), page size 2048, OOB size:64 
> but then
> nand: Bad block table not found for chip 0
> nand: Bad block table not found for chip 0
> 
> etc
> 
> and when I do imx_nand_bbm, I get:
> Bad eraseblock 0 at 0x00000000
> Bad eraseblock 1 at 0x00020000
> And for the rest UnCorrectable RS-ECC errors
> 
> This is a barenew flash, so I suppose I should find a factory bad block table?
No, this is a another bad block table. [1] You need to generate the bbt.
Factories only marks block as bad(with an mark pattern).

> I'm using the barebox 2013.05.1 stable release from git
> 

You can "try" to generate a bbt when you generate a nand bad block aware
device, nand command "nand -a", then run "nandtest -t -m /dev/nand#.bb" to fill
this bbt with "current" badblocks.

I don't know if this generates a bbt for you. But give it a try, I think
it should do :/

[1] http://www.linux-mtd.infradead.org/tech/mtdnand/x144.html


From J.Weitzel at phytec.de  Fri Jun 14 03:23:48 2013
From: J.Weitzel at phytec.de (Jan Weitzel)
Date: Fri, 14 Jun 2013 09:23:48 +0200
Subject: [PATCH v4] omap4-fb: add driver
In-Reply-To: <20130614062910.GA10743@x61s.8.8.8.8>
References: <20130405085917.GK1906@pengutronix.de>
 <1365372959.20809.6.camel@lovely> <20130408071715.GS1568@game.jcrosoft.org>
 <20130409071608.GD1906@pengutronix.de>
 <20130409132917.GX1568@game.jcrosoft.org> <1365706897.4136.24.camel@mars>
 <1370207222.5021.0.camel@lovely> <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars> <20130614062910.GA10743@x61s.8.8.8.8>
Message-ID: <1371194628.3655.1.camel@lws-weitzel>

Am Freitag, den 14.06.2013, 08:29 +0200 schrieb Alexander Aring:
> Hi,
> 
> On Fri, Jun 14, 2013 at 12:40:39AM +0200, Christoph Fritz wrote:
> > This patch adds omap4 display controller support.
> > 
> > Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
> > ---
> > changes since v2:
> >         - use dev_request_mem_region_by_name()
> > changes since v3:
> > 	- remove register struct
> > 	- use uncached screen_base
> > ---
> >  arch/arm/mach-omap/Makefile                |    1 +
> >  arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
> >  arch/arm/mach-omap/omap4_fb.c              |   27 ++
> >  drivers/video/Kconfig                      |    8 +
> >  drivers/video/Makefile                     |    1 +
> >  drivers/video/omap4.c                      |  505 ++++++++++++++++++++++++++++
> >  drivers/video/omap4.h                      |  179 ++++++++++
> >  7 files changed, 767 insertions(+)
> >  create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
> >  create mode 100644 arch/arm/mach-omap/omap4_fb.c
> >  create mode 100644 drivers/video/omap4.c
> >  create mode 100644 drivers/video/omap4.h
> > 
> > diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
> > index 94e42c6..e70ddbd 100644
> > --- a/arch/arm/mach-omap/Makefile
> > +++ b/arch/arm/mach-omap/Makefile
> > @@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
> >  pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
> >  obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
> >  obj-$(CONFIG_SHELL_NONE) += xload.o
> > +obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
> >  obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
> >  obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
> >  obj-y += gpio.o
> > diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
> > new file mode 100644
> > index 0000000..5c0a54b
> > --- /dev/null
> > +++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
> > @@ -0,0 +1,46 @@
> 
> ...
> 
> > +	fb_write(1, fbi->dispc, O4_DISPC_VID1_PIXEL_INC);
> > +
> > +	fb_write(0xfff, fbi->dispc, O4_DISPC_VID1_PRELOAD);
> > +
> > +	fb_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
> > +			 DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
> > +			 DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
> > +			 DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
> > +			 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
> > +
> > +	while (fb_read(fbi->dispc, O4_DISPC_CONTROL2) & DSS_DISPC_CONTROL_GOLCD)
> > +		;			/* noop */
> 
> For busy waiting on statusbits I would prefer a mechanism like this:
> 
> start = get_time_ns();
> while (condition) {
> ...
> 	if (is_timeout(start, waiting_time)) {
> 		dev_err(dev, "foo"
> 		return -ETIMEOUT;
> 	}
> 	mdelay(interval);
> ...
> }
There is also a convenience wrapper: wait_on_timeout(timeout, condition)

Jan
> 
> I mean it avoid deadlocks in barebox and it's better to start linux
> without a display instead of a deadlock in barebox.
> On the other hand you need a waiting_time which works with all displays
> together. Don't know if there any hardware dependency.
> 
> }
> > +
> > +	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
> > +		 DSS_DISPC_CONTROL_GOLCD,
> > +		 fbi->dispc, O4_DISPC_CONTROL2);
> > +
> > +	fbi->cur_display = new_display;
> > +	info->xres = mode->xres;
> > +	info->yres = mode->yres;
> > +
> > +	rc = 0;
> > +
> > +out:
> > +	return rc;
> > +}
> 
> ...
> 
> > +
> > +	omap4fb_reset(fbi);
> > +
> > +	dev_add_param(fbi->dev, "bootargs", NULL, NULL, 0);
> > +
> Jean-Christophe PLAGNIOL-VILLARD said why we need this here in the last
> mails. I don't saw any answer to this and asking myself... what do this
> function?
> 
> Regards
> Alex
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox




From chf.fritz at googlemail.com  Fri Jun 14 04:15:42 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Fri, 14 Jun 2013 10:15:42 +0200
Subject: [PATCH v5] omap4-fb: add driver
In-Reply-To: <1371194628.3655.1.camel@lws-weitzel>
References: <20130405085917.GK1906@pengutronix.de>
 <1365372959.20809.6.camel@lovely> <20130408071715.GS1568@game.jcrosoft.org>
 <20130409071608.GD1906@pengutronix.de>
 <20130409132917.GX1568@game.jcrosoft.org> <1365706897.4136.24.camel@mars>
 <1370207222.5021.0.camel@lovely> <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars> <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel>
Message-ID: <1371197742.3873.8.camel@mars>

This patch adds omap4 display controller support.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
changes since v2:
        - use dev_request_mem_region_by_name()
changes since v3:
        - remove register struct
        - use uncached screen_base
changes since v4:
        - remove useless dev_add_param()
        - use wait_on_timeout() instead while-deadlock
---
 arch/arm/mach-omap/Makefile                |    1 +
 arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
 arch/arm/mach-omap/omap4_fb.c              |   27 ++
 drivers/video/Kconfig                      |    8 +
 drivers/video/Makefile                     |    1 +
 drivers/video/omap4.c                      |  527 ++++++++++++++++++++++++++++
 drivers/video/omap4.h                      |  181 ++++++++++
 7 files changed, 791 insertions(+)
 create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
 create mode 100644 arch/arm/mach-omap/omap4_fb.c
 create mode 100644 drivers/video/omap4.c
 create mode 100644 drivers/video/omap4.h

diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 94e42c6..e70ddbd 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
 obj-$(CONFIG_SHELL_NONE) += xload.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
 obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
 obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
 obj-y += gpio.o
diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
new file mode 100644
index 0000000..5c0a54b
--- /dev/null
+++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
@@ -0,0 +1,46 @@
+#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+
+#include <fb.h>
+
+#define OMAP_DSS_LCD_TFT	(1u << 0)
+#define OMAP_DSS_LCD_IVS	(1u << 1)
+#define OMAP_DSS_LCD_IHS	(1u << 2)
+#define OMAP_DSS_LCD_IPC	(1u << 3)
+#define OMAP_DSS_LCD_IEO	(1u << 4)
+#define OMAP_DSS_LCD_RF	(1u << 5)
+#define OMAP_DSS_LCD_ONOFF	(1u << 6)
+
+#define OMAP_DSS_LCD_DATALINES(_l)	((_l) << 10)
+#define OMAP_DSS_LCD_DATALINES_msk	OMAP_DSS_LCD_DATALINES(3u)
+#define OMAP_DSS_LCD_DATALINES_12	OMAP_DSS_LCD_DATALINES(0u)
+#define OMAP_DSS_LCD_DATALINES_16	OMAP_DSS_LCD_DATALINES(1u)
+#define OMAP_DSS_LCD_DATALINES_18	OMAP_DSS_LCD_DATALINES(2u)
+#define OMAP_DSS_LCD_DATALINES_24	OMAP_DSS_LCD_DATALINES(3u)
+
+struct omap4fb_display {
+	struct fb_videomode mode;
+
+	unsigned long config;
+
+	unsigned int power_on_delay;
+	unsigned int power_off_delay;
+};
+
+struct omap4fb_platform_data {
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	unsigned int dss_clk_hz;
+
+	unsigned int bpp;
+
+	struct resource const *screen;
+
+	void (*enable)(int p);
+};
+
+struct device_d;
+struct device_d *omap4_add_display(void *pdata);
+
+#endif	/* H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H */
diff --git a/arch/arm/mach-omap/omap4_fb.c b/arch/arm/mach-omap/omap4_fb.c
new file mode 100644
index 0000000..09a6af3
--- /dev/null
+++ b/arch/arm/mach-omap/omap4_fb.c
@@ -0,0 +1,27 @@
+#include <driver.h>
+#include <common.h>
+#include <linux/ioport.h>
+#include <mach/omap4-fb.h>
+
+static struct resource omap4_fb_resources[] = {
+	{
+		.name	= "omap4_dss",
+		.start	= 0x48040000,
+		.end	= 0x48040000 + 512 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	}, {
+		.name	= "omap4_dispc",
+		.start	= 0x48041000,
+		.end	= 0x48041000 + 3072 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	},
+};
+
+struct device_d *omap4_add_display(void *pdata)
+{
+	return add_generic_device_res("omap4_fb", -1,
+				      omap4_fb_resources,
+				      ARRAY_SIZE(omap4_fb_resources),
+				      pdata);
+}
+EXPORT_SYMBOL(omap4_add_display);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 6d6b08f..9dfa0cd 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -45,6 +45,14 @@ config DRIVER_VIDEO_S3C24XX
 	help
 	  Add support for the S3C244x LCD controller.
 
+config DRIVER_VIDEO_OMAP4
+	bool "OMAP4 framebuffer driver"
+	depends on ARCH_OMAP4
+	help
+	  Add support for the OMAP4 Display Controller.
+	  DSI is unsupported, only DISPC parallel mode on LCD2
+	  is supported.
+
 if DRIVER_VIDEO_S3C24XX
 
 config DRIVER_VIDEO_S3C_VERBOSE
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 7429141..83feebb 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
 obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
 obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
 obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4.o
diff --git a/drivers/video/omap4.c b/drivers/video/omap4.c
new file mode 100644
index 0000000..a7c6253
--- /dev/null
+++ b/drivers/video/omap4.c
@@ -0,0 +1,527 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.com>
+ *   Based on work by Enrico Scholz, sponsored by Phytec
+ *
+ * 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.
+ */
+
+#include <driver.h>
+#include <fb.h>
+#include <errno.h>
+#include <xfuncs.h>
+#include <init.h>
+#include <stdio.h>
+#include <io.h>
+#include <common.h>
+#include <malloc.h>
+#include <common.h>
+#include <clock.h>
+
+#include <mach/omap4-silicon.h>
+#include <mach/omap4-fb.h>
+
+#include <asm/mmu.h>
+
+#include "omap4.h"
+
+struct omap4fb_device {
+	struct fb_info info;
+	struct device_d *dev;
+
+	struct omap4fb_display const *cur_display;
+
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	void __iomem *dss;
+	void __iomem *dispc;
+
+	struct {
+		void __iomem *addr;
+		size_t size;
+	} prealloc_screen;
+
+	struct {
+		uint32_t dispc_control;
+		uint32_t dispc_pol_freq;
+	} shadow;
+
+	struct {
+		unsigned int dss_clk_hz;
+		unsigned int lckd;
+		unsigned int pckd;
+	} divisor;
+	size_t dma_size;
+	void (*enable_fn)(int);
+
+	struct fb_videomode	video_modes[];
+};
+
+static void omap4fb_enable(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	dev_info(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(1);
+
+	udelay(fbi->cur_display->power_on_delay * 1000u);
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
+		 DSS_DISPC_CONTROL_LCDENABLE |
+		 DSS_DISPC_CONTROL_LCDENABLESIGNAL,
+		 fbi->dispc, O4_DISPC_CONTROL2);
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_VID1_ATTRIBUTES) |
+		 DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE,
+		 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
+		 DSS_DISPC_CONTROL_GOLCD,
+		 fbi->dispc, O4_DISPC_CONTROL2);
+}
+
+static void omap4fb_disable(struct fb_info *info)
+{
+	struct omap4fb_device	*fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	dev_info(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) &
+		~(DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL),
+		fbi->dispc, O4_DISPC_CONTROL2);
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_VID1_ATTRIBUTES) &
+		 ~(DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE),
+		 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
+
+	if (fbi->prealloc_screen.addr == NULL) {
+		/* free frame buffer; but only when screen is not
+		 * preallocated */
+		if (info->screen_base)
+			dma_free_coherent(info->screen_base, fbi->dma_size);
+	}
+
+	info->screen_base = NULL;
+
+	udelay(fbi->cur_display->power_off_delay * 1000u);
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(0);
+}
+
+static void omap4fb_calc_divisor(struct omap4fb_device *fbi,
+			struct fb_videomode const *mode)
+{
+	unsigned int l, k, t, b;
+
+	b = UINT_MAX;
+	for (l = 1; l < 256; l++) {
+		for (k = 1; k < 256; k++) {
+			t = abs(mode->pixclock * 100 -
+				(fbi->divisor.dss_clk_hz / l / k));
+			if (t <= b) {
+				b = t;
+				fbi->divisor.lckd = l;
+				fbi->divisor.pckd = k;
+			}
+		}
+	}
+}
+
+static unsigned int omap4fb_calc_format(struct fb_info const *info)
+{
+	switch (info->bits_per_pixel) {
+	case 24: return 9;
+	case 32: return 0x8; /* xRGB24-8888 (32-bit container) */
+	default:
+		printf("%s: unsupported bpp %d\n", __func__,
+		       info->bits_per_pixel);
+		return 0;
+	}
+}
+
+struct omap4fb_colors {
+	struct fb_bitfield	red;
+	struct fb_bitfield	green;
+	struct fb_bitfield	blue;
+	struct fb_bitfield	transp;
+};
+
+static struct omap4fb_colors const omap4fb_col[] = {
+	[0] = {
+		.red	= { .length = 0, .offset = 0 },
+	},
+	[1] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+	},
+	[2] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+		.transp	= { .length = 8, .offset = 24 },
+	},
+};
+
+static void omap4fb_fill_shadow(struct omap4fb_device *fbi,
+				struct omap4fb_display const *display)
+{
+	fbi->shadow.dispc_control = 0;
+	fbi->shadow.dispc_pol_freq = 0;
+
+	fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_STNTFT;
+
+	switch (display->config & OMAP_DSS_LCD_DATALINES_msk) {
+	case OMAP_DSS_LCD_DATALINES_12:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_12;
+		break;
+	case OMAP_DSS_LCD_DATALINES_16:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_16;
+		break;
+	case OMAP_DSS_LCD_DATALINES_18:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_18;
+		break;
+	case OMAP_DSS_LCD_DATALINES_24:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_24;
+		break;
+	}
+
+	if (display->config & OMAP_DSS_LCD_IPC)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IPC;
+
+	if (display->config & OMAP_DSS_LCD_IVS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IVS;
+
+	if (display->config & OMAP_DSS_LCD_IHS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IHS;
+
+	if (display->config & OMAP_DSS_LCD_IEO)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IEO;
+
+	if (display->config & OMAP_DSS_LCD_RF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_RF;
+
+	if (display->config & OMAP_DSS_LCD_ONOFF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_ONOFF;
+}
+
+static int omap4fb_activate_var(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+	struct fb_videomode const *mode = info->mode;
+	size_t size = mode->xres * mode->yres * (info->bits_per_pixel / 8);
+	int rc;
+	unsigned int fmt = omap4fb_calc_format(info);
+	struct omap4fb_colors const *cols;
+	size_t i;
+	struct omap4fb_display const *new_display = NULL;
+
+	for (i = 0; i < fbi->num_displays && new_display == NULL; ++i) {
+		if (strcmp(mode->name, fbi->displays[i].mode.name) == 0)
+			new_display = &fbi->displays[i];
+	}
+
+	if (WARN_ON(!new_display)) {
+		dev_err(fbi->dev, "no display found for this mode '%s'\n",
+			mode->name);
+		rc = -ENXIO;
+		goto out;
+	}
+
+	/*Free old screen buf*/
+	if (!fbi->prealloc_screen.addr && info->screen_base)
+		dma_free_coherent(info->screen_base, fbi->dma_size);
+
+	fbi->dma_size = PAGE_ALIGN(size);
+
+	if (fbi->prealloc_screen.addr == NULL) {
+		/* case 1: no preallocated screen */
+		info->screen_base = dma_alloc_coherent(size);
+	} else if (fbi->prealloc_screen.size < fbi->dma_size) {
+		/* case 2: preallocated screen, but too small */
+		dev_err(fbi->dev,
+			"allocated framebuffer too small (%zu < %zu)\n",
+			fbi->prealloc_screen.size, fbi->dma_size);
+		rc = -ENOMEM;
+		goto out;
+	} else {
+		/* case 3: preallocated screen */
+		info->screen_base = fbi->prealloc_screen.addr;
+	}
+
+	omap4fb_fill_shadow(fbi, new_display);
+
+	omap4fb_calc_divisor(fbi, mode);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		cols = &omap4fb_col[1];
+		break;
+	case 32:
+		cols = &omap4fb_col[2];
+		break;
+	default:
+		cols = &omap4fb_col[0];
+	}
+
+	info->red = cols->red;
+	info->green = cols->green;
+	info->blue = cols->blue;
+	info->transp = cols->transp;
+
+	fb_write(fbi->shadow.dispc_control,
+		 fbi->dispc, O4_DISPC_CONTROL2);
+
+	fb_write(fbi->shadow.dispc_pol_freq,
+			fbi->dispc, O4_DISPC_POL_FREQ2);
+
+	fb_write(DSS_DISPC_TIMING_H_HSW(mode->hsync_len - 1) |
+		 DSS_DISPC_TIMING_H_HFP(mode->right_margin - 1) |
+		 DSS_DISPC_TIMING_H_HBP(mode->left_margin - 1),
+		 fbi->dispc, O4_DISPC_TIMING_H2);
+
+	fb_write(DSS_DISPC_TIMING_V_VSW(mode->vsync_len - 1) |
+		 DSS_DISPC_TIMING_V_VFP(mode->lower_margin) |
+		 DSS_DISPC_TIMING_V_VBP(mode->upper_margin),
+		 fbi->dispc, O4_DISPC_TIMING_V2);
+
+	fb_write(DSS_DISPC_DIVISOR_ENABLE | DSS_DISPC_DIVISOR_LCD(1),
+			fbi->dispc, O4_DISPC_DIVISOR);
+
+	fb_write(DSS_DISPC_DIVISOR2_LCD(fbi->divisor.lckd) |
+		 DSS_DISPC_DIVISOR2_PCD(fbi->divisor.pckd),
+		 fbi->dispc, O4_DISPC_DIVISOR2);
+
+	fb_write(DSS_DISPC_SIZE_LCD_PPL(mode->xres - 1) |
+		 DSS_DISPC_SIZE_LCD_LPP(mode->yres - 1),
+		 fbi->dispc, O4_DISPC_SIZE_LCD2);
+
+	fb_write(0x0000ff00, fbi->dispc, O4_DISPC_DEFAULT_COLOR2);
+
+	/* we use VID1 */
+	fb_write((uintptr_t)info->screen_base, fbi->dispc, O4_DISPC_VID1_BA0);
+	fb_write((uintptr_t)info->screen_base, fbi->dispc, O4_DISPC_VID1_BA1);
+
+	fb_write(DSS_DISPC_VIDn_POSITION_VIDPOSX(0) |
+		 DSS_DISPC_VIDn_POSITION_VIDPOSY(0),
+		 fbi->dispc, O4_DISPC_VID1_POSITION);
+	fb_write(DSS_DISPC_VIDn_SIZE_VIDSIZEX(mode->xres - 1) |
+		 DSS_DISPC_VIDn_SIZE_VIDSIZEY(mode->yres - 1),
+		 fbi->dispc, O4_DISPC_VID1_SIZE);
+	fb_write(DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(mode->xres - 1) |
+		 DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(mode->yres - 1),
+		 fbi->dispc, O4_DISPC_VID1_PICTURE_SIZE);
+	fb_write(1, fbi->dispc, O4_DISPC_VID1_ROW_INC);
+	fb_write(1, fbi->dispc, O4_DISPC_VID1_PIXEL_INC);
+
+	fb_write(0xfff, fbi->dispc, O4_DISPC_VID1_PRELOAD);
+
+	fb_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
+			 DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
+			 DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
+			 DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
+			 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
+
+	rc = wait_on_timeout(O4_TIMEOUT,
+		!(fb_read(fbi->dispc, O4_DISPC_CONTROL2) &
+		DSS_DISPC_CONTROL_GOLCD));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: dispc golcd\n");
+		goto out;
+	}
+
+	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
+		 DSS_DISPC_CONTROL_GOLCD,
+		 fbi->dispc, O4_DISPC_CONTROL2);
+
+	fbi->cur_display = new_display;
+	info->xres = mode->xres;
+	info->yres = mode->yres;
+
+	rc = 0;
+
+out:
+	return rc;
+}
+
+static int omap4fb_reset(struct omap4fb_device const *fbi)
+{
+	uint32_t v = fb_read(fbi->dispc, O4_DISPC_CONTROL2);
+	int rc;
+
+	/* step 1: stop the LCD controller */
+	if (v & DSS_DISPC_CONTROL_LCDENABLE) {
+		fb_write(v & ~DSS_DISPC_CONTROL_LCDENABLE,
+				fbi->dispc, O4_DISPC_CONTROL2);
+
+		fb_write(DSS_DISPC_IRQSTATUS_FRAMEDONE2, fbi->dispc,
+			O4_DISPC_IRQSTATUS);
+
+
+		rc = wait_on_timeout(O4_TIMEOUT,
+			((fb_read(fbi->dispc, O4_DISPC_IRQSTATUS) &
+			DSS_DISPC_IRQSTATUS_FRAMEDONE) != 0));
+
+		if (rc) {
+			dev_err(fbi->dev, "timeout: irqstatus framedone\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	/* step 2: wait for reset done status */
+	rc = wait_on_timeout(O4_TIMEOUT,
+		(fb_read(fbi->dss, O4_DSS_SYSSTATUS) &
+		DSS_DSS_SYSSTATUS_RESETDONE));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: sysstatus resetdone\n");
+		return -ETIMEDOUT;
+	}
+
+	/* DSS_CTL: set to reset value */
+	fb_write(0, fbi->dss, O4_DSS_CTRL);
+
+	return 0;
+}
+
+static struct fb_ops omap4fb_ops = {
+	.fb_enable		= omap4fb_enable,
+	.fb_disable		= omap4fb_disable,
+	.fb_activate_var	= omap4fb_activate_var,
+};
+
+static int omap4fb_probe(struct device_d *dev)
+{
+	struct omap4fb_platform_data const *pdata = dev->platform_data;
+	struct omap4fb_device *fbi;
+	struct fb_info *info;
+	int rc;
+	size_t i;
+
+	if (!pdata)
+		return -ENODEV;
+
+	fbi = xzalloc(sizeof *fbi +
+		      pdata->num_displays * sizeof fbi->video_modes[0]);
+	info = &fbi->info;
+
+	fbi->dev = dev;
+
+	/* CM_DSS_CLKSTCTRL (TRM: 935) trigger SW_WKUP */
+	__raw_writel(0x2, 0x4a009100); /* TODO: move this to clockmanagement */
+
+	fbi->dss   = dev_request_mem_region_by_name(dev, "omap4_dss");
+	fbi->dispc = dev_request_mem_region_by_name(dev, "omap4_dispc");
+
+	if (!fbi->dss || !fbi->dispc) {
+		dev_err(dev, "Insufficient register description\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	dev_info(dev, "HW-Revision 0x%04x 0x%04x\n",
+		fb_read(fbi->dss, O4_DISPC_REVISION),
+		fb_read(fbi->dss, O4_DSS_REVISION));
+
+
+	if (!pdata->dss_clk_hz | !pdata->displays | !pdata->num_displays |
+		!pdata->bpp) {
+		dev_err(dev, "Insufficient omap4fb_platform_data\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	fbi->enable_fn    = pdata->enable;
+	fbi->displays     = pdata->displays;
+	fbi->num_displays = pdata->num_displays;
+	fbi->divisor.dss_clk_hz = pdata->dss_clk_hz;
+
+	for (i = 0; i < pdata->num_displays; ++i)
+		fbi->video_modes[i] = pdata->displays[i].mode;
+
+	info->mode_list = fbi->video_modes;
+	info->num_modes = pdata->num_displays;
+
+	info->priv = fbi;
+	info->fbops = &omap4fb_ops;
+	info->bits_per_pixel = pdata->bpp;
+
+	if (pdata->screen) {
+		if (!IS_ALIGNED(pdata->screen->start, PAGE_SIZE) ||
+		    !IS_ALIGNED(resource_size(pdata->screen), PAGE_SIZE)) {
+			dev_err(dev, "screen resource not aligned\n");
+			rc = -EINVAL;
+			goto out;
+		}
+		fbi->prealloc_screen.addr =
+				(void __iomem *)pdata->screen->start;
+		fbi->prealloc_screen.size = resource_size(pdata->screen);
+		remap_range(fbi->prealloc_screen.addr,
+			fbi->prealloc_screen.size,
+			mmu_get_pte_uncached_flags());
+	}
+
+	rc = omap4fb_reset(fbi);
+	if (rc < 0) {
+		dev_err(dev, "failed to reset: %d\n", rc);
+		goto out;
+	}
+
+	rc = register_framebuffer(info);
+	if (rc < 0) {
+		dev_err(dev, "failed to register framebuffer: %d\n", rc);
+		goto out;
+	}
+
+	rc = 0;
+	dev_info(dev, "registered\n");
+
+out:
+	if (rc < 0)
+		free(fbi);
+
+	return rc;
+}
+
+static struct driver_d omap4fb_driver = {
+	.name	= "omap4_fb",
+	.probe	= omap4fb_probe,
+};
+
+static int omap4fb_init(void)
+{
+	return platform_driver_register(&omap4fb_driver);
+}
+
+device_initcall(omap4fb_init);
diff --git a/drivers/video/omap4.h b/drivers/video/omap4.h
new file mode 100644
index 0000000..5704f7b
--- /dev/null
+++ b/drivers/video/omap4.h
@@ -0,0 +1,181 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.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.
+ */
+
+#ifndef H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+#define H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+
+#include <types.h>
+#include <common.h>
+
+#define O4_TIMEOUT	(128 * USECOND)
+
+#define fb_read(io, reg)		__raw_readl((io)+(reg))
+#define fb_write(val, io, reg)	__raw_writel((val), (io)+(reg))
+
+/* TRM: 10.1.3.2 DSS Registers */
+#define O4_DSS_REVISION	0x0
+#define O4_DSS_SYSSTATUS	0x14
+#define O4_DSS_CTRL		0x40
+#define O4_DSS_STATUS		0x5c
+
+/* TRM: 10.2.7.3 Display Controller Registers */
+#define O4_DISPC_REVISION		0x0
+#define O4_DISPC_IRQSTATUS		0x18
+#define O4_DISPC_CONTROL2		0x238
+#define O4_DISPC_VID1_ATTRIBUTES	0xcc
+#define O4_DISPC_TIMING_H2		0x400
+#define O4_DISPC_TIMING_V2		0x404
+#define O4_DISPC_POL_FREQ2		0x408
+#define O4_DISPC_DIVISOR2		0x40c
+#define O4_DISPC_DEFAULT_COLOR2	0x3ac
+#define O4_DISPC_SIZE_LCD2		0x3cc
+#define O4_DISPC_DIVISOR		0x804
+#define O4_DISPC_VID1_BA0		0xbc
+#define O4_DISPC_VID1_BA1		0xc0
+#define O4_DISPC_VID1_POSITION		0xc4
+#define O4_DISPC_VID1_SIZE		0xc8
+#define O4_DISPC_VID1_PICTURE_SIZE	0xe4
+#define O4_DISPC_VID1_ROW_INC		0xd8
+#define O4_DISPC_VID1_PIXEL_INC	0xdc
+#define O4_DISPC_VID1_PRELOAD		0x230
+
+#define DSS_DISPC_VIDn_POSITION_VIDPOSX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_POSITION_VIDPOSY(_y)		((_y) << 16)
+
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(_x)	((_x) << 0)
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(_y)	((_y) << 16)
+
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEY(_y)		((_y) << 16)
+
+#define DSS_DISPC_SIZE_LCD_PPL(_x)			((_x) << 0)
+#define DSS_DISPC_SIZE_LCD_LPP(_y)			((_y) << 16)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE		(1u << 0)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(_fmt)	((_fmt) << 1)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB12	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(4u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(5u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(6u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16o	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(7u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB24u	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(8u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB24p	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(9u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_YUV2	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(10u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_UYVY	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(11u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(12u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGBA32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(13u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(14u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(_b)	((_b) << 14)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_2x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_4x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(2u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCHANNELOUT	(1u << 16)
+#define DSS_DISPC_VIDn_ATTRIBUTES_SELFREFRESHAUTO	(1u << 17)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFIFOPRELOAD	(1u << 19)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDVERTICALTAPS	(1u << 21)
+#define DSS_DISPC_VIDn_ATTRIBUTES_DOUBLESTRIDE		(1u << 22)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDARBITRATION	(1u << 23)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDSELFREFRESH	(1u << 24)
+#define DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE		(1u << 25)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(_b)  ((_b) << 30)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_PRIMARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_WRITEBACK_MEM \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(3u)
+
+#define DSS_DISPC_CONTROL_LCDENABLE			(1u << 0)
+#define DSS_DISPC_CONTROL_TVENABLE			(1u << 1)
+#define DSS_DISPC_CONTROL_MONOCOLOR			(1u << 2)
+#define DSS_DISPC_CONTROL_STNTFT			(1u << 3)
+#define DSS_DISPC_CONTROL_M8B				(1u << 4)
+#define DSS_DISPC_CONTROL_GOLCD			(1u << 5)
+#define DSS_DISPC_CONTROL_GOTV				(1u << 6)
+#define DSS_DISPC_CONTROL_STDITHERENABLE		(1u << 7)
+
+#define DSS_DISPC_CONTROL_TFTDATALINES(_l)		((_l) << 8)
+#define DSS_DISPC_CONTROL_TFTDATALINES_12 \
+	DSS_DISPC_CONTROL_TFTDATALINES(0u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_16 \
+	DSS_DISPC_CONTROL_TFTDATALINES(1u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_18 \
+	DSS_DISPC_CONTROL_TFTDATALINES(2u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_24 \
+	DSS_DISPC_CONTROL_TFTDATALINES(3u)
+
+#define DSS_DISPC_CONTROL_STALLMODE			(1u << 11)
+#define DSS_DISPC_CONTROL_OVERLAYOPTIMIZATION		(1u << 12)
+#define DSS_DISPC_CONTROL_GPIN0			(1u << 13) /* ro */
+#define DSS_DISPC_CONTROL_GPIN1			(1u << 14) /* ro */
+#define DSS_DISPC_CONTROL_GPOUT0			(1u << 15)
+#define DSS_DISPC_CONTROL_GPOUT1			(1u << 16)
+#define DSS_DISPC_CONTROL_HT(_ht)			((_ht) << 17)
+#define DSS_DISPC_CONTROL_TDMENABLE			(1u << 20)
+#define DSS_DISPC_CONTROL_TDMPARALLELMODE(_pm)		((_pm) << 21)
+#define DSS_DISPC_CONTROL_TDMCYCLEFORMAT(_cf)		((_cf) << 23)
+#define DSS_DISPC_CONTROL_TDMUNUSEDBITS(_ub)		((_ub) << 25)
+#define DSS_DISPC_CONTROL_PCKFREEENABLE		(1u << 27)
+#define DSS_DISPC_CONTROL_LCDENABLESIGNAL		(1u << 28)
+#define DSS_DISPC_CONTROL_LCDENABLEPOL			(1u << 29)
+#define DSS_DISPC_CONTROL_SPATIALTEMPD(_df)		((_df) << 30)
+
+#define DSS_DISPC_POL_FREQ_IVS				(1u << 12)
+#define DSS_DISPC_POL_FREQ_IHS				(1u << 13)
+#define DSS_DISPC_POL_FREQ_IPC				(1u << 14)
+#define DSS_DISPC_POL_FREQ_IEO				(1u << 15)
+#define DSS_DISPC_POL_FREQ_RF				(1u << 16)
+#define DSS_DISPC_POL_FREQ_ONOFF			(1u << 17)
+
+#define DSS_DISPC_TIMING_H_HSW(_hsw)			((_hsw) << 0)
+#define DSS_DISPC_TIMING_H_HFP(_hfp)			((_hfp) << 8)
+#define DSS_DISPC_TIMING_H_HBP(_hbp)			((_hbp) << 20)
+
+#define DSS_DISPC_TIMING_V_VSW(_vsw)			((_vsw) << 0)
+#define DSS_DISPC_TIMING_V_VFP(_vfp)			((_vfp) << 8)
+#define DSS_DISPC_TIMING_V_VBP(_vbp)			((_vbp) << 20)
+
+#define DSS_DISPC_DIVISOR_ENABLE			(1u << 0)
+#define DSS_DISPC_DIVISOR_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_DIVISOR2_PCD(_pcd)			((_pcd) << 0)
+#define DSS_DISPC_DIVISOR2_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE			(1u << 0)
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE2			(1u << 22)
+
+#define DSS_DSS_SYSSTATUS_RESETDONE			(1u << 0)
+
+#endif	/* H_BAREBOX_DRIVER_VIDEO_O4_REGS_H */
-- 
1.7.10.4





From t.gamez at phytec.de  Fri Jun 14 05:12:53 2013
From: t.gamez at phytec.de (Teresa Gamez)
Date: Fri, 14 Jun 2013 11:12:53 +0200
Subject: [PATCH] arm: omap: am33xx: set up SPI devices
In-Reply-To: <1370892680-13254-1-git-send-email-jlu@pengutronix.de>
References: <1370892680-13254-1-git-send-email-jlu@pengutronix.de>
Message-ID: <51BADE95.9090007@phytec.de>

Hello Jan,

Am 10.06.2013 21:31, schrieb Jan Luebbe:
> Signed-off-by: Jan Luebbe <jlu at pengutronix.de>
> ---
>   arch/arm/mach-omap/include/mach/am33xx-devices.h | 17 +++++++++++++++++
>   arch/arm/mach-omap/include/mach/am33xx-silicon.h |  4 ++++
>   drivers/spi/Kconfig                              |  2 +-
>   3 files changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/mach-omap/include/mach/am33xx-devices.h b/arch/arm/mach-omap/include/mach/am33xx-devices.h
> index fe9fba9..cea4504 100644
> --- a/arch/arm/mach-omap/include/mach/am33xx-devices.h
> +++ b/arch/arm/mach-omap/include/mach/am33xx-devices.h
> @@ -7,6 +7,7 @@
>   #include <mach/devices.h>
>   #include <mach/omap_hsmmc.h>
>   #include <mach/cpsw.h>
> +#include <mach/omap_hsmmc.h>

this header has been already included just two lines before.

Regards,
Teresa


>   
>   /* the device numbering is the same as in the TRM memory map (SPRUH73G) */
>   
> @@ -37,4 +38,20 @@ static inline struct device_d *am33xx_add_cpsw(struct cpsw_platform_data *cpsw_d
>   			AM335X_CPSW_BASE, SZ_32K, IORESOURCE_MEM, cpsw_data);
>   }
>   
> +static inline struct device_d *am33xx_add_spi(int id, resource_size_t start)
> +{
> +	return add_generic_device("omap3_spi", id, NULL, start + 0x100, SZ_4K - 0x100,
> +				   IORESOURCE_MEM, NULL);
> +}
> +
> +static inline struct device_d *am33xx_add_spi0(void)
> +{
> +	return am33xx_add_spi(0, AM33XX_MCSPI0_BASE);
> +}
> +
> +static inline struct device_d *am33xx_add_spi1(void)
> +{
> +	return am33xx_add_spi(1, AM33XX_MCSPI1_BASE);
> +}
> +
>   #endif /* __MACH_OMAP3_DEVICES_H */
> diff --git a/arch/arm/mach-omap/include/mach/am33xx-silicon.h b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
> index 9edf4ca..59284af 100644
> --- a/arch/arm/mach-omap/include/mach/am33xx-silicon.h
> +++ b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
> @@ -49,6 +49,10 @@
>   #define AM33XX_MMC1_BASE		(AM33XX_L4_PER_BASE + 0x1D8000)
>   #define AM33XX_MMCHS2_BASE		0x47810000
>   
> +/* SPI */
> +#define AM33XX_MCSPI0_BASE		(AM33XX_L4_PER_BASE + 0x30000)
> +#define AM33XX_MCSPI1_BASE		(AM33XX_L4_PER_BASE + 0x1A0000)
> +
>   /* DTMTimer0 */
>   #define AM33XX_DMTIMER0_BASE		(AM33XX_L4_WKUP_BASE + 0x205000)
>   
> diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
> index f14e28f..c279c21 100644
> --- a/drivers/spi/Kconfig
> +++ b/drivers/spi/Kconfig
> @@ -40,7 +40,7 @@ config DRIVER_SPI_MXS
>   
>   config DRIVER_SPI_OMAP3
>   	bool "OMAP3 McSPI Master driver"
> -	depends on ARCH_OMAP3
> +	depends on ARCH_OMAP3 || ARCH_AM33XX
>   
>   endif
>   



From plagnioj at jcrosoft.com  Fri Jun 14 07:43:12 2013
From: plagnioj at jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
Date: Fri, 14 Jun 2013 13:43:12 +0200
Subject: [PATCH v5] omap4-fb: add driver
In-Reply-To: <1371197742.3873.8.camel@mars>
References: <20130409071608.GD1906@pengutronix.de>
 <20130409132917.GX1568@game.jcrosoft.org>
 <1365706897.4136.24.camel@mars> <1370207222.5021.0.camel@lovely>
 <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars>
 <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel>
 <1371197742.3873.8.camel@mars>
Message-ID: <20130614114312.GG27130@game.jcrosoft.org>

On 10:15 Fri 14 Jun     , Christoph Fritz wrote:
> This patch adds omap4 display controller support.
> 
> Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
> ---
> changes since v2:
>         - use dev_request_mem_region_by_name()
> changes since v3:
>         - remove register struct
>         - use uncached screen_base
> changes since v4:
>         - remove useless dev_add_param()
>         - use wait_on_timeout() instead while-deadlock
> ---
>  arch/arm/mach-omap/Makefile                |    1 +
>  arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
>  arch/arm/mach-omap/omap4_fb.c              |   27 ++

Sasha will device but for me this is 2 patches

1 for the driver
1 for the mach-omap
>  drivers/video/Kconfig                      |    8 +
>  drivers/video/Makefile                     |    1 +
>  drivers/video/omap4.c                      |  527 ++++++++++++++++++++++++++++
>  drivers/video/omap4.h                      |  181 ++++++++++
>  7 files changed, 791 insertions(+)
>  create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
>  create mode 100644 arch/arm/mach-omap/omap4_fb.c
>  create mode 100644 drivers/video/omap4.c
>  create mode 100644 drivers/video/omap4.h
> 
> diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
> index 94e42c6..e70ddbd 100644
> --- a/arch/arm/mach-omap/Makefile
> +++ b/arch/arm/mach-omap/Makefile
> @@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
>  pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
>  obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
>  obj-$(CONFIG_SHELL_NONE) += xload.o
> +obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
>  obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
>  obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
>  obj-y += gpio.o
> diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
> new file mode 100644
> index 0000000..5c0a54b
> --- /dev/null
> +++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
> @@ -0,0 +1,46 @@
> +#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
> +#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
> +
> +#include <fb.h>
> +
> +#define OMAP_DSS_LCD_TFT	(1u << 0)
> +#define OMAP_DSS_LCD_IVS	(1u << 1)
> +#define OMAP_DSS_LCD_IHS	(1u << 2)
> +#define OMAP_DSS_LCD_IPC	(1u << 3)
> +#define OMAP_DSS_LCD_IEO	(1u << 4)
> +#define OMAP_DSS_LCD_RF	(1u << 5)
> +#define OMAP_DSS_LCD_ONOFF	(1u << 6)
> +
> +#define OMAP_DSS_LCD_DATALINES(_l)	((_l) << 10)
> +#define OMAP_DSS_LCD_DATALINES_msk	OMAP_DSS_LCD_DATALINES(3u)
> +#define OMAP_DSS_LCD_DATALINES_12	OMAP_DSS_LCD_DATALINES(0u)
> +#define OMAP_DSS_LCD_DATALINES_16	OMAP_DSS_LCD_DATALINES(1u)
> +#define OMAP_DSS_LCD_DATALINES_18	OMAP_DSS_LCD_DATALINES(2u)
> +#define OMAP_DSS_LCD_DATALINES_24	OMAP_DSS_LCD_DATALINES(3u)
> +
> +struct omap4fb_display {
> +	struct fb_videomode mode;
> +
> +	unsigned long config;
> +
> +	unsigned int power_on_delay;
> +	unsigned int power_off_delay;
> +};
> +
> +struct omap4fb_platform_data {
> +	struct omap4fb_display const *displays;
> +	size_t num_displays;
> +
> +	unsigned int dss_clk_hz;
> +
> +	unsigned int bpp;
> +
> +	struct resource const *screen;
> +
> +	void (*enable)(int p);
> +};
> +
> +struct device_d;
> +struct device_d *omap4_add_display(void *pdata);
> +
> +#endif	/* H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H */
> diff --git a/arch/arm/mach-omap/omap4_fb.c b/arch/arm/mach-omap/omap4_fb.c
> new file mode 100644
> index 0000000..09a6af3
> --- /dev/null
> +++ b/arch/arm/mach-omap/omap4_fb.c
> @@ -0,0 +1,27 @@
> +#include <driver.h>
> +#include <common.h>
> +#include <linux/ioport.h>
> +#include <mach/omap4-fb.h>
> +
> +static struct resource omap4_fb_resources[] = {
> +	{
> +		.name	= "omap4_dss",
> +		.start	= 0x48040000,
> +		.end	= 0x48040000 + 512 - 1,
> +		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
> +	}, {
> +		.name	= "omap4_dispc",
> +		.start	= 0x48041000,
> +		.end	= 0x48041000 + 3072 - 1,
> +		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
> +	},
> +};
> +
> +struct device_d *omap4_add_display(void *pdata)
> +{
> +	return add_generic_device_res("omap4_fb", -1,
> +				      omap4_fb_resources,
> +				      ARRAY_SIZE(omap4_fb_resources),
> +				      pdata);
> +}
> +EXPORT_SYMBOL(omap4_add_display);
> diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
> index 6d6b08f..9dfa0cd 100644
> --- a/drivers/video/Kconfig
> +++ b/drivers/video/Kconfig
> @@ -45,6 +45,14 @@ config DRIVER_VIDEO_S3C24XX
>  	help
>  	  Add support for the S3C244x LCD controller.
>  
> +config DRIVER_VIDEO_OMAP4
> +	bool "OMAP4 framebuffer driver"
> +	depends on ARCH_OMAP4
> +	help
> +	  Add support for the OMAP4 Display Controller.
> +	  DSI is unsupported, only DISPC parallel mode on LCD2
> +	  is supported.
> +
>  if DRIVER_VIDEO_S3C24XX
>  
>  config DRIVER_VIDEO_S3C_VERBOSE
> diff --git a/drivers/video/Makefile b/drivers/video/Makefile
> index 7429141..83feebb 100644
> --- a/drivers/video/Makefile
> +++ b/drivers/video/Makefile
> @@ -8,3 +8,4 @@ obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
>  obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
>  obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
>  obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
> +obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4.o
> diff --git a/drivers/video/omap4.c b/drivers/video/omap4.c
> new file mode 100644
> index 0000000..a7c6253
> --- /dev/null
> +++ b/drivers/video/omap4.c
> @@ -0,0 +1,527 @@
> +/*
> + * TI Omap4 Frame Buffer device driver
> + *
> + * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.com>
> + *   Based on work by Enrico Scholz, sponsored by Phytec
> + *
> + * 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.
> + */
> +
> +#include <driver.h>
> +#include <fb.h>
> +#include <errno.h>
> +#include <xfuncs.h>
> +#include <init.h>
> +#include <stdio.h>
> +#include <io.h>
> +#include <common.h>
> +#include <malloc.h>
> +#include <common.h>
> +#include <clock.h>
> +
> +#include <mach/omap4-silicon.h>
> +#include <mach/omap4-fb.h>
> +
> +#include <asm/mmu.h>
> +
> +#include "omap4.h"
> +
> +struct omap4fb_device {
> +	struct fb_info info;
> +	struct device_d *dev;
> +
> +	struct omap4fb_display const *cur_display;
> +
> +	struct omap4fb_display const *displays;
> +	size_t num_displays;
> +
> +	void __iomem *dss;
> +	void __iomem *dispc;
> +
> +	struct {
> +		void __iomem *addr;
> +		size_t size;
> +	} prealloc_screen;
> +
> +	struct {
> +		uint32_t dispc_control;
> +		uint32_t dispc_pol_freq;
> +	} shadow;
> +
> +	struct {
> +		unsigned int dss_clk_hz;
> +		unsigned int lckd;
> +		unsigned int pckd;
> +	} divisor;
> +	size_t dma_size;
> +	void (*enable_fn)(int);
> +
> +	struct fb_videomode	video_modes[];
> +};
> +
> +static void omap4fb_enable(struct fb_info *info)
> +{
> +	struct omap4fb_device *fbi =
> +		container_of(info, struct omap4fb_device, info);
> +
> +	dev_info(fbi->dev, "%s\n", __func__);
dev_dbg

no need verbose for nornal operation
> +
> +	if (!fbi->cur_display) {
> +		dev_err(fbi->dev, "no valid mode set\n");
> +		return;
> +	}
> +
> +	if (fbi->enable_fn)
> +		fbi->enable_fn(1);
> +
> +	udelay(fbi->cur_display->power_on_delay * 1000u);
> +
> +	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
> +		 DSS_DISPC_CONTROL_LCDENABLE |
> +		 DSS_DISPC_CONTROL_LCDENABLESIGNAL,
> +		 fbi->dispc, O4_DISPC_CONTROL2);
> +
> +	fb_write(fb_read(fbi->dispc, O4_DISPC_VID1_ATTRIBUTES) |
> +		 DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE,
> +		 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
> +
> +	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
> +		 DSS_DISPC_CONTROL_GOLCD,
> +		 fbi->dispc, O4_DISPC_CONTROL2);
> +}
> +
> +static void omap4fb_disable(struct fb_info *info)
> +{
> +	struct omap4fb_device	*fbi =
> +		container_of(info, struct omap4fb_device, info);
> +
> +	dev_info(fbi->dev, "%s\n", __func__);
ditto
> +
> +	if (!fbi->cur_display) {
> +		dev_err(fbi->dev, "no valid mode set\n");
> +		return;
> +	}
> +
> +	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) &
> +		~(DSS_DISPC_CONTROL_LCDENABLE |
> +		DSS_DISPC_CONTROL_LCDENABLESIGNAL),
> +		fbi->dispc, O4_DISPC_CONTROL2);
> +
> +	fb_write(fb_read(fbi->dispc, O4_DISPC_VID1_ATTRIBUTES) &
> +		 ~(DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE),
> +		 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
> +
> +	if (fbi->prealloc_screen.addr == NULL) {
> +		/* free frame buffer; but only when screen is not
> +		 * preallocated */
> +		if (info->screen_base)
> +			dma_free_coherent(info->screen_base, fbi->dma_size);
> +	}
> +
> +	info->screen_base = NULL;
> +
> +	udelay(fbi->cur_display->power_off_delay * 1000u);
> +
> +	if (fbi->enable_fn)
> +		fbi->enable_fn(0);
> +}
> +
> +static void omap4fb_calc_divisor(struct omap4fb_device *fbi,
> +			struct fb_videomode const *mode)
> +{
> +	unsigned int l, k, t, b;
> +
> +	b = UINT_MAX;
> +	for (l = 1; l < 256; l++) {
> +		for (k = 1; k < 256; k++) {
> +			t = abs(mode->pixclock * 100 -
> +				(fbi->divisor.dss_clk_hz / l / k));
> +			if (t <= b) {
> +				b = t;
> +				fbi->divisor.lckd = l;
> +				fbi->divisor.pckd = k;
> +			}
> +		}
> +	}
> +}
> +
> +static unsigned int omap4fb_calc_format(struct fb_info const *info)
> +{
> +	switch (info->bits_per_pixel) {
> +	case 24: return 9;
	case x:
		return
> +	case 32: return 0x8; /* xRGB24-8888 (32-bit container) */
> +	default:
> +		printf("%s: unsupported bpp %d\n", __func__,
dev_err
> +		       info->bits_per_pixel);
> +		return 0;
> +	}
> +}
> +
> +struct omap4fb_colors {
> +	struct fb_bitfield	red;
> +	struct fb_bitfield	green;
> +	struct fb_bitfield	blue;
> +	struct fb_bitfield	transp;
> +};
> +
> +static struct omap4fb_colors const omap4fb_col[] = {
> +	[0] = {
> +		.red	= { .length = 0, .offset = 0 },
> +	},
> +	[1] = {
> +		.blue	= { .length = 8, .offset = 0 },
> +		.green	= { .length = 8, .offset = 8 },
> +		.red	= { .length = 8, .offset = 16 },
> +	},
> +	[2] = {
> +		.blue	= { .length = 8, .offset = 0 },
> +		.green	= { .length = 8, .offset = 8 },
> +		.red	= { .length = 8, .offset = 16 },
> +		.transp	= { .length = 8, .offset = 24 },
> +	},
> +};
> +
> +static void omap4fb_fill_shadow(struct omap4fb_device *fbi,
> +				struct omap4fb_display const *display)
> +{
> +	fbi->shadow.dispc_control = 0;
> +	fbi->shadow.dispc_pol_freq = 0;
> +
> +	fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_STNTFT;
> +
> +	switch (display->config & OMAP_DSS_LCD_DATALINES_msk) {
> +	case OMAP_DSS_LCD_DATALINES_12:
> +		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_12;
> +		break;
> +	case OMAP_DSS_LCD_DATALINES_16:
> +		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_16;
> +		break;
> +	case OMAP_DSS_LCD_DATALINES_18:
> +		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_18;
> +		break;
> +	case OMAP_DSS_LCD_DATALINES_24:
> +		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_24;
> +		break;
> +	}
> +
> +	if (display->config & OMAP_DSS_LCD_IPC)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IPC;
> +
> +	if (display->config & OMAP_DSS_LCD_IVS)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IVS;
> +
> +	if (display->config & OMAP_DSS_LCD_IHS)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IHS;
> +
> +	if (display->config & OMAP_DSS_LCD_IEO)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IEO;
> +
> +	if (display->config & OMAP_DSS_LCD_RF)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_RF;
> +
> +	if (display->config & OMAP_DSS_LCD_ONOFF)
> +		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_ONOFF;
> +}
> +
> +static int omap4fb_activate_var(struct fb_info *info)
> +{
> +	struct omap4fb_device *fbi =
> +		container_of(info, struct omap4fb_device, info);
> +	struct fb_videomode const *mode = info->mode;
> +	size_t size = mode->xres * mode->yres * (info->bits_per_pixel / 8);
> +	int rc;
> +	unsigned int fmt = omap4fb_calc_format(info);
> +	struct omap4fb_colors const *cols;
> +	size_t i;
> +	struct omap4fb_display const *new_display = NULL;
> +
> +	for (i = 0; i < fbi->num_displays && new_display == NULL; ++i) {
> +		if (strcmp(mode->name, fbi->displays[i].mode.name) == 0)
> +			new_display = &fbi->displays[i];
> +	}
do this search in a function and return
> +
> +	if (WARN_ON(!new_display)) {
> +		dev_err(fbi->dev, "no display found for this mode '%s'\n",
> +			mode->name);
> +		rc = -ENXIO;
> +		goto out;
> +	}
> +
> +	/*Free old screen buf*/
> +	if (!fbi->prealloc_screen.addr && info->screen_base)
> +		dma_free_coherent(info->screen_base, fbi->dma_size);
> +
> +	fbi->dma_size = PAGE_ALIGN(size);
> +
> +	if (fbi->prealloc_screen.addr == NULL) {
consistant !xxx
> +		/* case 1: no preallocated screen */
> +		info->screen_base = dma_alloc_coherent(size);
> +	} else if (fbi->prealloc_screen.size < fbi->dma_size) {
> +		/* case 2: preallocated screen, but too small */
> +		dev_err(fbi->dev,
> +			"allocated framebuffer too small (%zu < %zu)\n",
> +			fbi->prealloc_screen.size, fbi->dma_size);
> +		rc = -ENOMEM;
> +		goto out;
> +	} else {
> +		/* case 3: preallocated screen */
> +		info->screen_base = fbi->prealloc_screen.addr;
> +	}
> +
> +	omap4fb_fill_shadow(fbi, new_display);
> +
> +	omap4fb_calc_divisor(fbi, mode);
> +
> +	switch (info->bits_per_pixel) {
> +	case 24:
> +		cols = &omap4fb_col[1];
> +		break;
> +	case 32:
> +		cols = &omap4fb_col[2];
> +		break;
> +	default:
> +		cols = &omap4fb_col[0];
> +	}
> +
> +	info->red = cols->red;
> +	info->green = cols->green;
> +	info->blue = cols->blue;
> +	info->transp = cols->transp;
> +
> +	fb_write(fbi->shadow.dispc_control,
> +		 fbi->dispc, O4_DISPC_CONTROL2);
> +
> +	fb_write(fbi->shadow.dispc_pol_freq,
> +			fbi->dispc, O4_DISPC_POL_FREQ2);
> +
> +	fb_write(DSS_DISPC_TIMING_H_HSW(mode->hsync_len - 1) |
> +		 DSS_DISPC_TIMING_H_HFP(mode->right_margin - 1) |
> +		 DSS_DISPC_TIMING_H_HBP(mode->left_margin - 1),
> +		 fbi->dispc, O4_DISPC_TIMING_H2);
> +
> +	fb_write(DSS_DISPC_TIMING_V_VSW(mode->vsync_len - 1) |
> +		 DSS_DISPC_TIMING_V_VFP(mode->lower_margin) |
> +		 DSS_DISPC_TIMING_V_VBP(mode->upper_margin),
> +		 fbi->dispc, O4_DISPC_TIMING_V2);
> +
> +	fb_write(DSS_DISPC_DIVISOR_ENABLE | DSS_DISPC_DIVISOR_LCD(1),
> +			fbi->dispc, O4_DISPC_DIVISOR);
> +
> +	fb_write(DSS_DISPC_DIVISOR2_LCD(fbi->divisor.lckd) |
> +		 DSS_DISPC_DIVISOR2_PCD(fbi->divisor.pckd),
> +		 fbi->dispc, O4_DISPC_DIVISOR2);
> +
> +	fb_write(DSS_DISPC_SIZE_LCD_PPL(mode->xres - 1) |
> +		 DSS_DISPC_SIZE_LCD_LPP(mode->yres - 1),
> +		 fbi->dispc, O4_DISPC_SIZE_LCD2);
> +
> +	fb_write(0x0000ff00, fbi->dispc, O4_DISPC_DEFAULT_COLOR2);
> +
> +	/* we use VID1 */
> +	fb_write((uintptr_t)info->screen_base, fbi->dispc, O4_DISPC_VID1_BA0);
> +	fb_write((uintptr_t)info->screen_base, fbi->dispc, O4_DISPC_VID1_BA1);
> +
> +	fb_write(DSS_DISPC_VIDn_POSITION_VIDPOSX(0) |
> +		 DSS_DISPC_VIDn_POSITION_VIDPOSY(0),
> +		 fbi->dispc, O4_DISPC_VID1_POSITION);
> +	fb_write(DSS_DISPC_VIDn_SIZE_VIDSIZEX(mode->xres - 1) |
> +		 DSS_DISPC_VIDn_SIZE_VIDSIZEY(mode->yres - 1),
> +		 fbi->dispc, O4_DISPC_VID1_SIZE);
> +	fb_write(DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(mode->xres - 1) |
> +		 DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(mode->yres - 1),
> +		 fbi->dispc, O4_DISPC_VID1_PICTURE_SIZE);
> +	fb_write(1, fbi->dispc, O4_DISPC_VID1_ROW_INC);
> +	fb_write(1, fbi->dispc, O4_DISPC_VID1_PIXEL_INC);
> +
> +	fb_write(0xfff, fbi->dispc, O4_DISPC_VID1_PRELOAD);
> +
> +	fb_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
> +			 DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
> +			 DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
> +			 DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
> +			 fbi->dispc, O4_DISPC_VID1_ATTRIBUTES);
> +
> +	rc = wait_on_timeout(O4_TIMEOUT,
> +		!(fb_read(fbi->dispc, O4_DISPC_CONTROL2) &
> +		DSS_DISPC_CONTROL_GOLCD));
> +
> +	if (rc) {
> +		dev_err(fbi->dev, "timeout: dispc golcd\n");
> +		goto out;
> +	}
> +
> +	fb_write(fb_read(fbi->dispc, O4_DISPC_CONTROL2) |
> +		 DSS_DISPC_CONTROL_GOLCD,
> +		 fbi->dispc, O4_DISPC_CONTROL2);
> +
> +	fbi->cur_display = new_display;
> +	info->xres = mode->xres;
> +	info->yres = mode->yres;
> +
> +	rc = 0;
> +
> +out:
> +	return rc;
> +}
> +
> +static int omap4fb_reset(struct omap4fb_device const *fbi)
> +{
> +	uint32_t v = fb_read(fbi->dispc, O4_DISPC_CONTROL2);
> +	int rc;
> +
> +	/* step 1: stop the LCD controller */
> +	if (v & DSS_DISPC_CONTROL_LCDENABLE) {
> +		fb_write(v & ~DSS_DISPC_CONTROL_LCDENABLE,
> +				fbi->dispc, O4_DISPC_CONTROL2);
> +
> +		fb_write(DSS_DISPC_IRQSTATUS_FRAMEDONE2, fbi->dispc,
> +			O4_DISPC_IRQSTATUS);
> +
> +
> +		rc = wait_on_timeout(O4_TIMEOUT,
> +			((fb_read(fbi->dispc, O4_DISPC_IRQSTATUS) &
> +			DSS_DISPC_IRQSTATUS_FRAMEDONE) != 0));
> +
> +		if (rc) {
> +			dev_err(fbi->dev, "timeout: irqstatus framedone\n");
> +			return -ETIMEDOUT;
> +		}
> +	}
> +
> +	/* step 2: wait for reset done status */
> +	rc = wait_on_timeout(O4_TIMEOUT,
> +		(fb_read(fbi->dss, O4_DSS_SYSSTATUS) &
> +		DSS_DSS_SYSSTATUS_RESETDONE));
> +
> +	if (rc) {
> +		dev_err(fbi->dev, "timeout: sysstatus resetdone\n");
> +		return -ETIMEDOUT;
> +	}
> +
> +	/* DSS_CTL: set to reset value */
> +	fb_write(0, fbi->dss, O4_DSS_CTRL);
> +
> +	return 0;
> +}
> +
> +static struct fb_ops omap4fb_ops = {
> +	.fb_enable		= omap4fb_enable,
> +	.fb_disable		= omap4fb_disable,
> +	.fb_activate_var	= omap4fb_activate_var,
> +};
> +
> +static int omap4fb_probe(struct device_d *dev)
> +{
> +	struct omap4fb_platform_data const *pdata = dev->platform_data;
> +	struct omap4fb_device *fbi;
> +	struct fb_info *info;
> +	int rc;
> +	size_t i;
> +
> +	if (!pdata)
> +		return -ENODEV;
> +
> +	fbi = xzalloc(sizeof *fbi +
> +		      pdata->num_displays * sizeof fbi->video_modes[0]);
> +	info = &fbi->info;
> +
> +	fbi->dev = dev;
> +
> +	/* CM_DSS_CLKSTCTRL (TRM: 935) trigger SW_WKUP */
> +	__raw_writel(0x2, 0x4a009100); /* TODO: move this to clockmanagement */
> +
> +	fbi->dss   = dev_request_mem_region_by_name(dev, "omap4_dss");
> +	fbi->dispc = dev_request_mem_region_by_name(dev, "omap4_dispc");
> +
> +	if (!fbi->dss || !fbi->dispc) {
> +		dev_err(dev, "Insufficient register description\n");
> +		rc = -EINVAL;
> +		goto out;
> +	}
> +
> +	dev_info(dev, "HW-Revision 0x%04x 0x%04x\n",
> +		fb_read(fbi->dss, O4_DISPC_REVISION),
> +		fb_read(fbi->dss, O4_DSS_REVISION));
> +
> +
drop one line
> +	if (!pdata->dss_clk_hz | !pdata->displays | !pdata->num_displays |
> +		!pdata->bpp) {
> +		dev_err(dev, "Insufficient omap4fb_platform_data\n");
> +		rc = -EINVAL;
> +		goto out;
> +	}
> +
> +	fbi->enable_fn    = pdata->enable;
> +	fbi->displays     = pdata->displays;
> +	fbi->num_displays = pdata->num_displays;
> +	fbi->divisor.dss_clk_hz = pdata->dss_clk_hz;
> +
> +	for (i = 0; i < pdata->num_displays; ++i)
> +		fbi->video_modes[i] = pdata->displays[i].mode;
> +
> +	info->mode_list = fbi->video_modes;
> +	info->num_modes = pdata->num_displays;
> +
> +	info->priv = fbi;
> +	info->fbops = &omap4fb_ops;
> +	info->bits_per_pixel = pdata->bpp;
> +
> +	if (pdata->screen) {
> +		if (!IS_ALIGNED(pdata->screen->start, PAGE_SIZE) ||
> +		    !IS_ALIGNED(resource_size(pdata->screen), PAGE_SIZE)) {
> +			dev_err(dev, "screen resource not aligned\n");
> +			rc = -EINVAL;
> +			goto out;
> +		}
> +		fbi->prealloc_screen.addr =
> +				(void __iomem *)pdata->screen->start;
> +		fbi->prealloc_screen.size = resource_size(pdata->screen);
> +		remap_range(fbi->prealloc_screen.addr,
> +			fbi->prealloc_screen.size,
> +			mmu_get_pte_uncached_flags());
> +	}
> +
> +	rc = omap4fb_reset(fbi);
> +	if (rc < 0) {
> +		dev_err(dev, "failed to reset: %d\n", rc);
> +		goto out;
> +	}
> +
> +	rc = register_framebuffer(info);
> +	if (rc < 0) {
> +		dev_err(dev, "failed to register framebuffer: %d\n", rc);
> +		goto out;
> +	}
> +
> +	rc = 0;
> +	dev_info(dev, "registered\n");
> +
> +out:
> +	if (rc < 0)
> +		free(fbi);
> +
> +	return rc;
> +}
> +
> +static struct driver_d omap4fb_driver = {
> +	.name	= "omap4_fb",
> +	.probe	= omap4fb_probe,
> +};
> +
> +static int omap4fb_init(void)
> +{
> +	return platform_driver_register(&omap4fb_driver);
> +}
> +
> +device_initcall(omap4fb_init);
> diff --git a/drivers/video/omap4.h b/drivers/video/omap4.h
> new file mode 100644
> index 0000000..5704f7b
> --- /dev/null
> +++ b/drivers/video/omap4.h
> @@ -0,0 +1,181 @@
> +/*
> + * TI Omap4 Frame Buffer device driver
> + *
> + * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.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.
> + */
> +
> +#ifndef H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
> +#define H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
> +
> +#include <types.h>
> +#include <common.h>
> +
> +#define O4_TIMEOUT	(128 * USECOND)
> +
> +#define fb_read(io, reg)		__raw_readl((io)+(reg))
> +#define fb_write(val, io, reg)	__raw_writel((val), (io)+(reg))
fb_read is too much generic

better to use 2 macro for both resources and pass the fbi struct
> +
> +/* TRM: 10.1.3.2 DSS Registers */
> +#define O4_DSS_REVISION	0x0
> +#define O4_DSS_SYSSTATUS	0x14
> +#define O4_DSS_CTRL		0x40
> +#define O4_DSS_STATUS		0x5c
> +
> +/* TRM: 10.2.7.3 Display Controller Registers */
> +#define O4_DISPC_REVISION		0x0
> +#define O4_DISPC_IRQSTATUS		0x18
> +#define O4_DISPC_CONTROL2		0x238
> +#define O4_DISPC_VID1_ATTRIBUTES	0xcc
> +#define O4_DISPC_TIMING_H2		0x400
> +#define O4_DISPC_TIMING_V2		0x404
> +#define O4_DISPC_POL_FREQ2		0x408
> +#define O4_DISPC_DIVISOR2		0x40c
> +#define O4_DISPC_DEFAULT_COLOR2	0x3ac
> +#define O4_DISPC_SIZE_LCD2		0x3cc
> +#define O4_DISPC_DIVISOR		0x804
> +#define O4_DISPC_VID1_BA0		0xbc
> +#define O4_DISPC_VID1_BA1		0xc0
> +#define O4_DISPC_VID1_POSITION		0xc4
> +#define O4_DISPC_VID1_SIZE		0xc8
> +#define O4_DISPC_VID1_PICTURE_SIZE	0xe4
> +#define O4_DISPC_VID1_ROW_INC		0xd8
> +#define O4_DISPC_VID1_PIXEL_INC	0xdc
> +#define O4_DISPC_VID1_PRELOAD		0x230
> +
> +#define DSS_DISPC_VIDn_POSITION_VIDPOSX(_x)		((_x) << 0)
> +#define DSS_DISPC_VIDn_POSITION_VIDPOSY(_y)		((_y) << 16)
> +
> +#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(_x)	((_x) << 0)
> +#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(_y)	((_y) << 16)
> +
> +#define DSS_DISPC_VIDn_SIZE_VIDSIZEX(_x)		((_x) << 0)
> +#define DSS_DISPC_VIDn_SIZE_VIDSIZEY(_y)		((_y) << 16)
> +
> +#define DSS_DISPC_SIZE_LCD_PPL(_x)			((_x) << 0)
> +#define DSS_DISPC_SIZE_LCD_LPP(_y)			((_y) << 16)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE		(1u << 0)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(_fmt)	((_fmt) << 1)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB12	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(4u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(5u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB16	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(6u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16o	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(7u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB24u	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(8u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB24p	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(9u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_YUV2	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(10u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_UYVY	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(11u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB32	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(12u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGBA32	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(13u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB32	\
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(14u)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(_b)	((_b) << 14)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_2x128 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(0u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_4x128 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(1u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 \
> +	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(2u)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCHANNELOUT	(1u << 16)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_SELFREFRESHAUTO	(1u << 17)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFIFOPRELOAD	(1u << 19)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDVERTICALTAPS	(1u << 21)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_DOUBLESTRIDE		(1u << 22)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDARBITRATION	(1u << 23)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_VIDSELFREFRESH	(1u << 24)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE		(1u << 25)
> +
> +#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(_b)  ((_b) << 30)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_PRIMARY_LCD \
> +	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(0u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD \
> +	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(1u)
> +#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_WRITEBACK_MEM \
> +	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(3u)
> +
> +#define DSS_DISPC_CONTROL_LCDENABLE			(1u << 0)
> +#define DSS_DISPC_CONTROL_TVENABLE			(1u << 1)
> +#define DSS_DISPC_CONTROL_MONOCOLOR			(1u << 2)
> +#define DSS_DISPC_CONTROL_STNTFT			(1u << 3)
> +#define DSS_DISPC_CONTROL_M8B				(1u << 4)
> +#define DSS_DISPC_CONTROL_GOLCD			(1u << 5)
> +#define DSS_DISPC_CONTROL_GOTV				(1u << 6)
> +#define DSS_DISPC_CONTROL_STDITHERENABLE		(1u << 7)
> +
> +#define DSS_DISPC_CONTROL_TFTDATALINES(_l)		((_l) << 8)
> +#define DSS_DISPC_CONTROL_TFTDATALINES_12 \
> +	DSS_DISPC_CONTROL_TFTDATALINES(0u)
> +#define DSS_DISPC_CONTROL_TFTDATALINES_16 \
> +	DSS_DISPC_CONTROL_TFTDATALINES(1u)
> +#define DSS_DISPC_CONTROL_TFTDATALINES_18 \
> +	DSS_DISPC_CONTROL_TFTDATALINES(2u)
> +#define DSS_DISPC_CONTROL_TFTDATALINES_24 \
> +	DSS_DISPC_CONTROL_TFTDATALINES(3u)
> +
> +#define DSS_DISPC_CONTROL_STALLMODE			(1u << 11)
> +#define DSS_DISPC_CONTROL_OVERLAYOPTIMIZATION		(1u << 12)
> +#define DSS_DISPC_CONTROL_GPIN0			(1u << 13) /* ro */
> +#define DSS_DISPC_CONTROL_GPIN1			(1u << 14) /* ro */
> +#define DSS_DISPC_CONTROL_GPOUT0			(1u << 15)
> +#define DSS_DISPC_CONTROL_GPOUT1			(1u << 16)
> +#define DSS_DISPC_CONTROL_HT(_ht)			((_ht) << 17)
> +#define DSS_DISPC_CONTROL_TDMENABLE			(1u << 20)
> +#define DSS_DISPC_CONTROL_TDMPARALLELMODE(_pm)		((_pm) << 21)
> +#define DSS_DISPC_CONTROL_TDMCYCLEFORMAT(_cf)		((_cf) << 23)
> +#define DSS_DISPC_CONTROL_TDMUNUSEDBITS(_ub)		((_ub) << 25)
> +#define DSS_DISPC_CONTROL_PCKFREEENABLE		(1u << 27)
> +#define DSS_DISPC_CONTROL_LCDENABLESIGNAL		(1u << 28)
> +#define DSS_DISPC_CONTROL_LCDENABLEPOL			(1u << 29)
> +#define DSS_DISPC_CONTROL_SPATIALTEMPD(_df)		((_df) << 30)
> +
> +#define DSS_DISPC_POL_FREQ_IVS				(1u << 12)
> +#define DSS_DISPC_POL_FREQ_IHS				(1u << 13)
> +#define DSS_DISPC_POL_FREQ_IPC				(1u << 14)
> +#define DSS_DISPC_POL_FREQ_IEO				(1u << 15)
> +#define DSS_DISPC_POL_FREQ_RF				(1u << 16)
> +#define DSS_DISPC_POL_FREQ_ONOFF			(1u << 17)
> +
> +#define DSS_DISPC_TIMING_H_HSW(_hsw)			((_hsw) << 0)
> +#define DSS_DISPC_TIMING_H_HFP(_hfp)			((_hfp) << 8)
> +#define DSS_DISPC_TIMING_H_HBP(_hbp)			((_hbp) << 20)
> +
> +#define DSS_DISPC_TIMING_V_VSW(_vsw)			((_vsw) << 0)
> +#define DSS_DISPC_TIMING_V_VFP(_vfp)			((_vfp) << 8)
> +#define DSS_DISPC_TIMING_V_VBP(_vbp)			((_vbp) << 20)
> +
> +#define DSS_DISPC_DIVISOR_ENABLE			(1u << 0)
> +#define DSS_DISPC_DIVISOR_LCD(_lcd)			((_lcd) << 16)
> +
> +#define DSS_DISPC_DIVISOR2_PCD(_pcd)			((_pcd) << 0)
> +#define DSS_DISPC_DIVISOR2_LCD(_lcd)			((_lcd) << 16)
> +
> +#define DSS_DISPC_IRQSTATUS_FRAMEDONE			(1u << 0)
> +#define DSS_DISPC_IRQSTATUS_FRAMEDONE2			(1u << 22)
> +
> +#define DSS_DSS_SYSSTATUS_RESETDONE			(1u << 0)
> +
> +#endif	/* H_BAREBOX_DRIVER_VIDEO_O4_REGS_H */
> -- 
> 1.7.10.4
> 
> 
> 


From chf.fritz at googlemail.com  Fri Jun 14 11:11:02 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Fri, 14 Jun 2013 17:11:02 +0200
Subject: [PATCH v6] omap4-fb: add driver
In-Reply-To: <20130614114312.GG27130@game.jcrosoft.org>
References: <20130409071608.GD1906@pengutronix.de>
 <20130409132917.GX1568@game.jcrosoft.org> <1365706897.4136.24.camel@mars>
 <1370207222.5021.0.camel@lovely> <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars> <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel> <1371197742.3873.8.camel@mars>
 <20130614114312.GG27130@game.jcrosoft.org>
Message-ID: <1371222662.28854.15.camel@mars>

This patch adds omap4 display controller support.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
changes since v2:
        - use dev_request_mem_region_by_name()
changes since v3:
        - remove register struct
        - use uncached screen_base
changes since v4:
        - remove useless dev_add_param()
        - use wait_on_timeout() instead while-deadlock
changes since v5:
	- use dev_dbg() and dev_err(), be less verbose
	- fix coding-style issues
	- add omap4fb_find_display_by_name()
	- add additional read/write macros
---
 arch/arm/mach-omap/Makefile                |    1 +
 arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
 arch/arm/mach-omap/omap4_fb.c              |   27 ++
 drivers/video/Kconfig                      |    8 +
 drivers/video/Makefile                     |    1 +
 drivers/video/omap4.c                      |  526 ++++++++++++++++++++++++++++
 drivers/video/omap4.h                      |  187 ++++++++++
 7 files changed, 796 insertions(+)
 create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
 create mode 100644 arch/arm/mach-omap/omap4_fb.c
 create mode 100644 drivers/video/omap4.c
 create mode 100644 drivers/video/omap4.h

diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 94e42c6..e70ddbd 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
 obj-$(CONFIG_SHELL_NONE) += xload.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
 obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
 obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
 obj-y += gpio.o
diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
new file mode 100644
index 0000000..5c0a54b
--- /dev/null
+++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
@@ -0,0 +1,46 @@
+#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+
+#include <fb.h>
+
+#define OMAP_DSS_LCD_TFT	(1u << 0)
+#define OMAP_DSS_LCD_IVS	(1u << 1)
+#define OMAP_DSS_LCD_IHS	(1u << 2)
+#define OMAP_DSS_LCD_IPC	(1u << 3)
+#define OMAP_DSS_LCD_IEO	(1u << 4)
+#define OMAP_DSS_LCD_RF	(1u << 5)
+#define OMAP_DSS_LCD_ONOFF	(1u << 6)
+
+#define OMAP_DSS_LCD_DATALINES(_l)	((_l) << 10)
+#define OMAP_DSS_LCD_DATALINES_msk	OMAP_DSS_LCD_DATALINES(3u)
+#define OMAP_DSS_LCD_DATALINES_12	OMAP_DSS_LCD_DATALINES(0u)
+#define OMAP_DSS_LCD_DATALINES_16	OMAP_DSS_LCD_DATALINES(1u)
+#define OMAP_DSS_LCD_DATALINES_18	OMAP_DSS_LCD_DATALINES(2u)
+#define OMAP_DSS_LCD_DATALINES_24	OMAP_DSS_LCD_DATALINES(3u)
+
+struct omap4fb_display {
+	struct fb_videomode mode;
+
+	unsigned long config;
+
+	unsigned int power_on_delay;
+	unsigned int power_off_delay;
+};
+
+struct omap4fb_platform_data {
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	unsigned int dss_clk_hz;
+
+	unsigned int bpp;
+
+	struct resource const *screen;
+
+	void (*enable)(int p);
+};
+
+struct device_d;
+struct device_d *omap4_add_display(void *pdata);
+
+#endif	/* H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H */
diff --git a/arch/arm/mach-omap/omap4_fb.c b/arch/arm/mach-omap/omap4_fb.c
new file mode 100644
index 0000000..09a6af3
--- /dev/null
+++ b/arch/arm/mach-omap/omap4_fb.c
@@ -0,0 +1,27 @@
+#include <driver.h>
+#include <common.h>
+#include <linux/ioport.h>
+#include <mach/omap4-fb.h>
+
+static struct resource omap4_fb_resources[] = {
+	{
+		.name	= "omap4_dss",
+		.start	= 0x48040000,
+		.end	= 0x48040000 + 512 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	}, {
+		.name	= "omap4_dispc",
+		.start	= 0x48041000,
+		.end	= 0x48041000 + 3072 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	},
+};
+
+struct device_d *omap4_add_display(void *pdata)
+{
+	return add_generic_device_res("omap4_fb", -1,
+				      omap4_fb_resources,
+				      ARRAY_SIZE(omap4_fb_resources),
+				      pdata);
+}
+EXPORT_SYMBOL(omap4_add_display);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 6d6b08f..9dfa0cd 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -45,6 +45,14 @@ config DRIVER_VIDEO_S3C24XX
 	help
 	  Add support for the S3C244x LCD controller.
 
+config DRIVER_VIDEO_OMAP4
+	bool "OMAP4 framebuffer driver"
+	depends on ARCH_OMAP4
+	help
+	  Add support for the OMAP4 Display Controller.
+	  DSI is unsupported, only DISPC parallel mode on LCD2
+	  is supported.
+
 if DRIVER_VIDEO_S3C24XX
 
 config DRIVER_VIDEO_S3C_VERBOSE
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 7429141..83feebb 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
 obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
 obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
 obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4.o
diff --git a/drivers/video/omap4.c b/drivers/video/omap4.c
new file mode 100644
index 0000000..afdee44
--- /dev/null
+++ b/drivers/video/omap4.c
@@ -0,0 +1,526 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.com>
+ *   Based on work by Enrico Scholz, sponsored by Phytec
+ *
+ * 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.
+ */
+
+#include <driver.h>
+#include <fb.h>
+#include <errno.h>
+#include <xfuncs.h>
+#include <init.h>
+#include <stdio.h>
+#include <io.h>
+#include <common.h>
+#include <malloc.h>
+#include <common.h>
+#include <clock.h>
+
+#include <mach/omap4-silicon.h>
+#include <mach/omap4-fb.h>
+
+#include <asm/mmu.h>
+
+#include "omap4.h"
+
+struct omap4fb_device {
+	struct fb_info info;
+	struct device_d *dev;
+
+	struct omap4fb_display const *cur_display;
+
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	void __iomem *dss;
+	void __iomem *dispc;
+
+	struct {
+		void __iomem *addr;
+		size_t size;
+	} prealloc_screen;
+
+	struct {
+		uint32_t dispc_control;
+		uint32_t dispc_pol_freq;
+	} shadow;
+
+	struct {
+		unsigned int dss_clk_hz;
+		unsigned int lckd;
+		unsigned int pckd;
+	} divisor;
+	size_t dma_size;
+	void (*enable_fn)(int);
+
+	struct fb_videomode	video_modes[];
+};
+
+static void omap4fb_enable(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	dev_dbg(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(1);
+
+	udelay(fbi->cur_display->power_on_delay * 1000u);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL, O4_DISPC_CONTROL2);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_VID1_ATTRIBUTES) |
+		DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE, O4_DISPC_VID1_ATTRIBUTES);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_GOLCD, O4_DISPC_CONTROL2);
+}
+
+static void omap4fb_disable(struct fb_info *info)
+{
+	struct omap4fb_device	*fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	dev_dbg(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) &
+		~(DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL), O4_DISPC_CONTROL2);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_VID1_ATTRIBUTES) &
+		~(DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE),
+		O4_DISPC_VID1_ATTRIBUTES);
+
+	if (fbi->prealloc_screen.addr == NULL) {
+		/* free frame buffer; but only when screen is not
+		* preallocated */
+		if (info->screen_base)
+			dma_free_coherent(info->screen_base, fbi->dma_size);
+	}
+
+	info->screen_base = NULL;
+
+	udelay(fbi->cur_display->power_off_delay * 1000u);
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(0);
+}
+
+static void omap4fb_calc_divisor(struct omap4fb_device *fbi,
+			struct fb_videomode const *mode)
+{
+	unsigned int l, k, t, b;
+
+	b = UINT_MAX;
+	for (l = 1; l < 256; l++) {
+		for (k = 1; k < 256; k++) {
+			t = abs(mode->pixclock * 100 -
+				(fbi->divisor.dss_clk_hz / l / k));
+			if (t <= b) {
+				b = t;
+				fbi->divisor.lckd = l;
+				fbi->divisor.pckd = k;
+			}
+		}
+	}
+}
+
+static unsigned int omap4fb_calc_format(struct fb_info const *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		return 9;
+	case 32:
+		return 0x8; /* xRGB24-8888 (32-bit container) */
+	default:
+		dev_err(fbi->dev, "%s: unsupported bpp %d\n", __func__,
+			info->bits_per_pixel);
+		return 0;
+	}
+}
+
+struct omap4fb_colors {
+	struct fb_bitfield	red;
+	struct fb_bitfield	green;
+	struct fb_bitfield	blue;
+	struct fb_bitfield	transp;
+};
+
+static struct omap4fb_colors const omap4fb_col[] = {
+	[0] = {
+		.red	= { .length = 0, .offset = 0 },
+	},
+	[1] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+	},
+	[2] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+		.transp	= { .length = 8, .offset = 24 },
+	},
+};
+
+static void omap4fb_fill_shadow(struct omap4fb_device *fbi,
+				struct omap4fb_display const *display)
+{
+	fbi->shadow.dispc_control = 0;
+	fbi->shadow.dispc_pol_freq = 0;
+
+	fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_STNTFT;
+
+	switch (display->config & OMAP_DSS_LCD_DATALINES_msk) {
+	case OMAP_DSS_LCD_DATALINES_12:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_12;
+		break;
+	case OMAP_DSS_LCD_DATALINES_16:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_16;
+		break;
+	case OMAP_DSS_LCD_DATALINES_18:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_18;
+		break;
+	case OMAP_DSS_LCD_DATALINES_24:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_24;
+		break;
+	}
+
+	if (display->config & OMAP_DSS_LCD_IPC)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IPC;
+
+	if (display->config & OMAP_DSS_LCD_IVS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IVS;
+
+	if (display->config & OMAP_DSS_LCD_IHS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IHS;
+
+	if (display->config & OMAP_DSS_LCD_IEO)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IEO;
+
+	if (display->config & OMAP_DSS_LCD_RF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_RF;
+
+	if (display->config & OMAP_DSS_LCD_ONOFF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_ONOFF;
+}
+
+static int omap4fb_find_display_by_name(struct omap4fb_device *fbi,
+		const char *name)
+{
+	int i;
+
+	for (i = 0; i < fbi->num_displays; ++i) {
+		if (strcmp(name, fbi->displays[i].mode.name) == 0)
+			return i;
+	}
+	return -ENXIO;
+}
+
+static int omap4fb_activate_var(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+	struct fb_videomode const *mode = info->mode;
+	size_t size = mode->xres * mode->yres * (info->bits_per_pixel / 8);
+	int rc;
+	unsigned int fmt = omap4fb_calc_format(info);
+	struct omap4fb_colors const *cols;
+	struct omap4fb_display const *new_display = NULL;
+
+	rc = omap4fb_find_display_by_name(fbi, mode->name);
+	if (rc < 0) {
+		dev_err(fbi->dev, "no display found for this mode '%s'\n",
+			mode->name);
+		goto out;
+	}
+	new_display = &fbi->displays[rc];
+
+	/*Free old screen buf*/
+	if (!fbi->prealloc_screen.addr && info->screen_base)
+		dma_free_coherent(info->screen_base, fbi->dma_size);
+
+	fbi->dma_size = PAGE_ALIGN(size);
+
+	if (!fbi->prealloc_screen.addr) {
+		/* case 1: no preallocated screen */
+		info->screen_base = dma_alloc_coherent(size);
+	} else if (fbi->prealloc_screen.size < fbi->dma_size) {
+		/* case 2: preallocated screen, but too small */
+		dev_err(fbi->dev,
+			"allocated framebuffer too small (%zu < %zu)\n",
+			fbi->prealloc_screen.size, fbi->dma_size);
+		rc = -ENOMEM;
+		goto out;
+	} else {
+		/* case 3: preallocated screen */
+		info->screen_base = fbi->prealloc_screen.addr;
+	}
+
+	omap4fb_fill_shadow(fbi, new_display);
+
+	omap4fb_calc_divisor(fbi, mode);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		cols = &omap4fb_col[1];
+		break;
+	case 32:
+		cols = &omap4fb_col[2];
+		break;
+	default:
+		cols = &omap4fb_col[0];
+	}
+
+	info->red = cols->red;
+	info->green = cols->green;
+	info->blue = cols->blue;
+	info->transp = cols->transp;
+
+	o4_dispc_write(fbi->shadow.dispc_control, O4_DISPC_CONTROL2);
+
+	o4_dispc_write(fbi->shadow.dispc_pol_freq, O4_DISPC_POL_FREQ2);
+
+	o4_dispc_write(DSS_DISPC_TIMING_H_HSW(mode->hsync_len - 1) |
+		DSS_DISPC_TIMING_H_HFP(mode->right_margin - 1) |
+		DSS_DISPC_TIMING_H_HBP(mode->left_margin - 1),
+		O4_DISPC_TIMING_H2);
+
+	o4_dispc_write(DSS_DISPC_TIMING_V_VSW(mode->vsync_len - 1) |
+		DSS_DISPC_TIMING_V_VFP(mode->lower_margin) |
+		DSS_DISPC_TIMING_V_VBP(mode->upper_margin), O4_DISPC_TIMING_V2);
+
+	o4_dispc_write(DSS_DISPC_DIVISOR_ENABLE | DSS_DISPC_DIVISOR_LCD(1),
+		O4_DISPC_DIVISOR);
+
+	o4_dispc_write(DSS_DISPC_DIVISOR2_LCD(fbi->divisor.lckd) |
+		DSS_DISPC_DIVISOR2_PCD(fbi->divisor.pckd), O4_DISPC_DIVISOR2);
+
+	o4_dispc_write(DSS_DISPC_SIZE_LCD_PPL(mode->xres - 1) |
+		DSS_DISPC_SIZE_LCD_LPP(mode->yres - 1), O4_DISPC_SIZE_LCD2);
+
+	o4_dispc_write(0x0000ff00, O4_DISPC_DEFAULT_COLOR2);
+
+	/* we use VID1 */
+	o4_dispc_write((uintptr_t)info->screen_base, O4_DISPC_VID1_BA0);
+	o4_dispc_write((uintptr_t)info->screen_base, O4_DISPC_VID1_BA1);
+
+	o4_dispc_write(DSS_DISPC_VIDn_POSITION_VIDPOSX(0) |
+		DSS_DISPC_VIDn_POSITION_VIDPOSY(0), O4_DISPC_VID1_POSITION);
+	o4_dispc_write(DSS_DISPC_VIDn_SIZE_VIDSIZEX(mode->xres - 1) |
+		DSS_DISPC_VIDn_SIZE_VIDSIZEY(mode->yres - 1),
+		O4_DISPC_VID1_SIZE);
+	o4_dispc_write(DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(mode->xres - 1) |
+		DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(mode->yres - 1),
+		O4_DISPC_VID1_PICTURE_SIZE);
+	o4_dispc_write(1, O4_DISPC_VID1_ROW_INC);
+	o4_dispc_write(1, O4_DISPC_VID1_PIXEL_INC);
+
+	o4_dispc_write(0xfff, O4_DISPC_VID1_PRELOAD);
+
+	o4_dispc_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
+		DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
+		DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
+		DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
+		O4_DISPC_VID1_ATTRIBUTES);
+
+	rc = wait_on_timeout(O4_TIMEOUT,
+		!(o4_dispc_read(O4_DISPC_CONTROL2) &
+		DSS_DISPC_CONTROL_GOLCD));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: dispc golcd\n");
+		goto out;
+	}
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_GOLCD, O4_DISPC_CONTROL2);
+
+	fbi->cur_display = new_display;
+	info->xres = mode->xres;
+	info->yres = mode->yres;
+
+	rc = 0;
+
+out:
+	return rc;
+}
+
+static int omap4fb_reset(struct omap4fb_device const *fbi)
+{
+	uint32_t v = o4_dispc_read(O4_DISPC_CONTROL2);
+	int rc;
+
+	/* step 1: stop the LCD controller */
+	if (v & DSS_DISPC_CONTROL_LCDENABLE) {
+		o4_dispc_write(v & ~DSS_DISPC_CONTROL_LCDENABLE,
+			O4_DISPC_CONTROL2);
+
+		o4_dispc_write(DSS_DISPC_IRQSTATUS_FRAMEDONE2,
+			O4_DISPC_IRQSTATUS);
+
+		rc = wait_on_timeout(O4_TIMEOUT,
+			((o4_dispc_read(O4_DISPC_IRQSTATUS) &
+			DSS_DISPC_IRQSTATUS_FRAMEDONE) != 0));
+
+		if (rc) {
+			dev_err(fbi->dev, "timeout: irqstatus framedone\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	/* step 2: wait for reset done status */
+	rc = wait_on_timeout(O4_TIMEOUT,
+		(o4_dss_read(O4_DSS_SYSSTATUS) &
+		DSS_DSS_SYSSTATUS_RESETDONE));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: sysstatus resetdone\n");
+		return -ETIMEDOUT;
+	}
+
+	/* DSS_CTL: set to reset value */
+	o4_dss_write(0, O4_DSS_CTRL);
+
+	return 0;
+}
+
+static struct fb_ops omap4fb_ops = {
+	.fb_enable		= omap4fb_enable,
+	.fb_disable		= omap4fb_disable,
+	.fb_activate_var	= omap4fb_activate_var,
+};
+
+static int omap4fb_probe(struct device_d *dev)
+{
+	struct omap4fb_platform_data const *pdata = dev->platform_data;
+	struct omap4fb_device *fbi;
+	struct fb_info *info;
+	int rc;
+	size_t i;
+
+	if (!pdata)
+		return -ENODEV;
+
+	fbi = xzalloc(sizeof *fbi +
+		pdata->num_displays * sizeof fbi->video_modes[0]);
+	info = &fbi->info;
+
+	fbi->dev = dev;
+
+	/* CM_DSS_CLKSTCTRL (TRM: 935) trigger SW_WKUP */
+	__raw_writel(0x2, 0x4a009100); /* TODO: move this to clockmanagement */
+
+	fbi->dss   = dev_request_mem_region_by_name(dev, "omap4_dss");
+	fbi->dispc = dev_request_mem_region_by_name(dev, "omap4_dispc");
+
+	if (!fbi->dss || !fbi->dispc) {
+		dev_err(dev, "Insufficient register description\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	dev_info(dev, "HW-Revision 0x%04x 0x%04x\n",
+		o4_dss_read(O4_DISPC_REVISION),
+		o4_dss_read(O4_DSS_REVISION));
+
+	if (!pdata->dss_clk_hz | !pdata->displays | !pdata->num_displays |
+		!pdata->bpp) {
+		dev_err(dev, "Insufficient omap4fb_platform_data\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	fbi->enable_fn    = pdata->enable;
+	fbi->displays     = pdata->displays;
+	fbi->num_displays = pdata->num_displays;
+	fbi->divisor.dss_clk_hz = pdata->dss_clk_hz;
+
+	for (i = 0; i < pdata->num_displays; ++i)
+		fbi->video_modes[i] = pdata->displays[i].mode;
+
+	info->mode_list = fbi->video_modes;
+	info->num_modes = pdata->num_displays;
+
+	info->priv = fbi;
+	info->fbops = &omap4fb_ops;
+	info->bits_per_pixel = pdata->bpp;
+
+	if (pdata->screen) {
+		if (!IS_ALIGNED(pdata->screen->start, PAGE_SIZE) ||
+			!IS_ALIGNED(resource_size(pdata->screen), PAGE_SIZE)) {
+			dev_err(dev, "screen resource not aligned\n");
+			rc = -EINVAL;
+			goto out;
+		}
+		fbi->prealloc_screen.addr =
+				(void __iomem *)pdata->screen->start;
+		fbi->prealloc_screen.size = resource_size(pdata->screen);
+		remap_range(fbi->prealloc_screen.addr,
+			fbi->prealloc_screen.size,
+			mmu_get_pte_uncached_flags());
+	}
+
+	rc = omap4fb_reset(fbi);
+	if (rc < 0) {
+		dev_err(dev, "failed to reset: %d\n", rc);
+		goto out;
+	}
+
+	rc = register_framebuffer(info);
+	if (rc < 0) {
+		dev_err(dev, "failed to register framebuffer: %d\n", rc);
+		goto out;
+	}
+
+	rc = 0;
+	dev_info(dev, "registered\n");
+
+out:
+	if (rc < 0)
+		free(fbi);
+
+	return rc;
+}
+
+static struct driver_d omap4fb_driver = {
+	.name	= "omap4_fb",
+	.probe	= omap4fb_probe,
+};
+
+static int omap4fb_init(void)
+{
+	return platform_driver_register(&omap4fb_driver);
+}
+
+device_initcall(omap4fb_init);
diff --git a/drivers/video/omap4.h b/drivers/video/omap4.h
new file mode 100644
index 0000000..4328a6c
--- /dev/null
+++ b/drivers/video/omap4.h
@@ -0,0 +1,187 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.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.
+ */
+
+#ifndef H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+#define H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+
+#include <types.h>
+#include <common.h>
+
+#define O4_TIMEOUT	(128 * USECOND)
+
+#define _o4fb_read(io, reg)		__raw_readl((io)+(reg))
+#define _o4fb_write(val, io, reg)	__raw_writel((val), (io)+(reg))
+
+/* TRM: 10.1.3.2 DSS Registers */
+#define O4_DSS_REVISION	0x0
+#define O4_DSS_SYSSTATUS	0x14
+#define O4_DSS_CTRL		0x40
+#define O4_DSS_STATUS		0x5c
+
+#define o4_dss_read(reg)		_o4fb_read(fbi->dss, reg)
+#define o4_dss_write(val, reg)		_o4fb_write(val, fbi->dss, reg)
+
+/* TRM: 10.2.7.3 Display Controller Registers */
+#define O4_DISPC_REVISION		0x0
+#define O4_DISPC_IRQSTATUS		0x18
+#define O4_DISPC_VID1_BA0		0xbc
+#define O4_DISPC_VID1_BA1		0xc0
+#define O4_DISPC_VID1_POSITION		0xc4
+#define O4_DISPC_VID1_SIZE		0xc8
+#define O4_DISPC_VID1_ATTRIBUTES	0xcc
+#define O4_DISPC_VID1_ROW_INC		0xd8
+#define O4_DISPC_VID1_PIXEL_INC	0xdc
+#define O4_DISPC_VID1_PICTURE_SIZE	0xe4
+#define O4_DISPC_VID1_PRELOAD		0x230
+#define O4_DISPC_CONTROL2		0x238
+#define O4_DISPC_DEFAULT_COLOR2	0x3ac
+#define O4_DISPC_SIZE_LCD2		0x3cc
+#define O4_DISPC_TIMING_H2		0x400
+#define O4_DISPC_TIMING_V2		0x404
+#define O4_DISPC_POL_FREQ2		0x408
+#define O4_DISPC_DIVISOR2		0x40c
+#define O4_DISPC_DIVISOR		0x804
+
+#define o4_dispc_read(reg)		_o4fb_read(fbi->dispc, reg)
+#define o4_dispc_write(val, reg)	_o4fb_write(val, fbi->dispc, reg)
+
+#define DSS_DISPC_VIDn_POSITION_VIDPOSX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_POSITION_VIDPOSY(_y)		((_y) << 16)
+
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(_x)	((_x) << 0)
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(_y)	((_y) << 16)
+
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEY(_y)		((_y) << 16)
+
+#define DSS_DISPC_SIZE_LCD_PPL(_x)			((_x) << 0)
+#define DSS_DISPC_SIZE_LCD_LPP(_y)			((_y) << 16)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE		(1u << 0)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(_fmt)	((_fmt) << 1)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB12	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(4u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(5u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(6u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16o	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(7u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB24u	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(8u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB24p	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(9u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_YUV2	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(10u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_UYVY	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(11u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(12u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGBA32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(13u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(14u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(_b)	((_b) << 14)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_2x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_4x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(2u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCHANNELOUT	(1u << 16)
+#define DSS_DISPC_VIDn_ATTRIBUTES_SELFREFRESHAUTO	(1u << 17)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFIFOPRELOAD	(1u << 19)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDVERTICALTAPS	(1u << 21)
+#define DSS_DISPC_VIDn_ATTRIBUTES_DOUBLESTRIDE		(1u << 22)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDARBITRATION	(1u << 23)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDSELFREFRESH	(1u << 24)
+#define DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE		(1u << 25)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(_b)  ((_b) << 30)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_PRIMARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_WRITEBACK_MEM \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(3u)
+
+#define DSS_DISPC_CONTROL_LCDENABLE			(1u << 0)
+#define DSS_DISPC_CONTROL_TVENABLE			(1u << 1)
+#define DSS_DISPC_CONTROL_MONOCOLOR			(1u << 2)
+#define DSS_DISPC_CONTROL_STNTFT			(1u << 3)
+#define DSS_DISPC_CONTROL_M8B				(1u << 4)
+#define DSS_DISPC_CONTROL_GOLCD			(1u << 5)
+#define DSS_DISPC_CONTROL_GOTV				(1u << 6)
+#define DSS_DISPC_CONTROL_STDITHERENABLE		(1u << 7)
+
+#define DSS_DISPC_CONTROL_TFTDATALINES(_l)		((_l) << 8)
+#define DSS_DISPC_CONTROL_TFTDATALINES_12 \
+	DSS_DISPC_CONTROL_TFTDATALINES(0u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_16 \
+	DSS_DISPC_CONTROL_TFTDATALINES(1u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_18 \
+	DSS_DISPC_CONTROL_TFTDATALINES(2u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_24 \
+	DSS_DISPC_CONTROL_TFTDATALINES(3u)
+
+#define DSS_DISPC_CONTROL_STALLMODE			(1u << 11)
+#define DSS_DISPC_CONTROL_OVERLAYOPTIMIZATION		(1u << 12)
+#define DSS_DISPC_CONTROL_GPIN0			(1u << 13) /* ro */
+#define DSS_DISPC_CONTROL_GPIN1			(1u << 14) /* ro */
+#define DSS_DISPC_CONTROL_GPOUT0			(1u << 15)
+#define DSS_DISPC_CONTROL_GPOUT1			(1u << 16)
+#define DSS_DISPC_CONTROL_HT(_ht)			((_ht) << 17)
+#define DSS_DISPC_CONTROL_TDMENABLE			(1u << 20)
+#define DSS_DISPC_CONTROL_TDMPARALLELMODE(_pm)		((_pm) << 21)
+#define DSS_DISPC_CONTROL_TDMCYCLEFORMAT(_cf)		((_cf) << 23)
+#define DSS_DISPC_CONTROL_TDMUNUSEDBITS(_ub)		((_ub) << 25)
+#define DSS_DISPC_CONTROL_PCKFREEENABLE		(1u << 27)
+#define DSS_DISPC_CONTROL_LCDENABLESIGNAL		(1u << 28)
+#define DSS_DISPC_CONTROL_LCDENABLEPOL			(1u << 29)
+#define DSS_DISPC_CONTROL_SPATIALTEMPD(_df)		((_df) << 30)
+
+#define DSS_DISPC_POL_FREQ_IVS				(1u << 12)
+#define DSS_DISPC_POL_FREQ_IHS				(1u << 13)
+#define DSS_DISPC_POL_FREQ_IPC				(1u << 14)
+#define DSS_DISPC_POL_FREQ_IEO				(1u << 15)
+#define DSS_DISPC_POL_FREQ_RF				(1u << 16)
+#define DSS_DISPC_POL_FREQ_ONOFF			(1u << 17)
+
+#define DSS_DISPC_TIMING_H_HSW(_hsw)			((_hsw) << 0)
+#define DSS_DISPC_TIMING_H_HFP(_hfp)			((_hfp) << 8)
+#define DSS_DISPC_TIMING_H_HBP(_hbp)			((_hbp) << 20)
+
+#define DSS_DISPC_TIMING_V_VSW(_vsw)			((_vsw) << 0)
+#define DSS_DISPC_TIMING_V_VFP(_vfp)			((_vfp) << 8)
+#define DSS_DISPC_TIMING_V_VBP(_vbp)			((_vbp) << 20)
+
+#define DSS_DISPC_DIVISOR_ENABLE			(1u << 0)
+#define DSS_DISPC_DIVISOR_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_DIVISOR2_PCD(_pcd)			((_pcd) << 0)
+#define DSS_DISPC_DIVISOR2_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE			(1u << 0)
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE2			(1u << 22)
+
+#define DSS_DSS_SYSSTATUS_RESETDONE			(1u << 0)
+
+#endif	/* H_BAREBOX_DRIVER_VIDEO_O4_REGS_H */
-- 
1.7.10.4




From shc_work at mail.ru  Sat Jun 15 09:42:04 2013
From: shc_work at mail.ru (Alexander Shiyan)
Date: Sat, 15 Jun 2013 17:42:04 +0400
Subject: [PATCH] ARM: pcm038: Add setup for MC13783 IRQ pin
Message-ID: <1371303724-27020-1-git-send-email-shc_work@mail.ru>

Kernel does not have pinctrl driver for i.MX27 yet. When we using DT,
this cause to unable setup pins to desired function. This patch adds
a setup for MC13783 IRQ pin to avoid this issue.

Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
---
 arch/arm/boards/pcm038/pcm038.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index dec5164..f6a3e17 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -46,9 +46,10 @@
 
 #include "pll.h"
 
+#define PCM038_GPIO_PMIC_IRQ	(GPIO_PORTB + 23)
 #define PCM038_GPIO_FEC_RST	(GPIO_PORTC + 30)
-#define PCM038_GPIO_SPI_CS0	(GPIO_PORTD + 28)
 #define PCM970_GPIO_SPI_CS1	(GPIO_PORTD + 27)
+#define PCM038_GPIO_SPI_CS0	(GPIO_PORTD + 28)
 #define PCM038_GPIO_OTG_STP	(GPIO_PORTE + 1)
 
 static struct fec_platform_data fec_info = {
@@ -225,7 +226,6 @@ static int pcm038_devices_init(void)
 		PD15_AOUT_FEC_COL,
 		PD16_AIN_FEC_TX_ER,
 		PF23_AIN_FEC_TX_EN,
-		PCM038_GPIO_FEC_RST | GPIO_GPIO | GPIO_OUT,
 		/* UART1 */
 		PE12_PF_UART1_TXD,
 		PE13_PF_UART1_RXD,
@@ -236,10 +236,6 @@ static int pcm038_devices_init(void)
 		PD29_PF_CSPI1_SCLK,
 		PD30_PF_CSPI1_MISO,
 		PD31_PF_CSPI1_MOSI,
-		PCM038_GPIO_SPI_CS0 | GPIO_GPIO | GPIO_OUT,
-#ifdef CONFIG_MACH_PCM970_BASEBOARD
-		PCM970_GPIO_SPI_CS1 | GPIO_GPIO | GPIO_OUT,
-#endif
 		/* Display */
 		PA5_PF_LSCLK,
 		PA6_PF_LD0,
@@ -287,6 +283,13 @@ static int pcm038_devices_init(void)
 		/* I2C2 */
 		PC5_PF_I2C2_SDA,
 		PC6_PF_I2C2_SCL,
+		/* Misc */
+		PCM038_GPIO_FEC_RST | GPIO_GPIO | GPIO_OUT,
+		PCM038_GPIO_SPI_CS0 | GPIO_GPIO | GPIO_OUT,
+#ifdef CONFIG_MACH_PCM970_BASEBOARD
+		PCM970_GPIO_SPI_CS1 | GPIO_GPIO | GPIO_OUT,
+#endif
+		PCM038_GPIO_PMIC_IRQ | GPIO_GPIO | GPIO_IN,
 	};
 
 	/* configure 16 bit nor flash on cs0 */
-- 
1.8.1.5



From jlu at pengutronix.de  Mon Jun 17 03:12:25 2013
From: jlu at pengutronix.de (Jan =?ISO-8859-1?Q?L=FCbbe?=)
Date: Mon, 17 Jun 2013 09:12:25 +0200
Subject: [PATCH] arm: omap: am33xx: set up SPI devices
In-Reply-To: <51BADE95.9090007@phytec.de>
References: <1370892680-13254-1-git-send-email-jlu@pengutronix.de>
 <51BADE95.9090007@phytec.de>
Message-ID: <1371453145.4168.1.camel@coredoba.hi.pengutronix.de>

On Fri, 2013-06-14 at 11:12 +0200, Teresa Gamez wrote:
> Am 10.06.2013 21:31, schrieb Jan Luebbe:
> > Signed-off-by: Jan Luebbe <jlu at pengutronix.de>
> > ---
> >   arch/arm/mach-omap/include/mach/am33xx-devices.h | 17 +++++++++++++++++
> >   arch/arm/mach-omap/include/mach/am33xx-silicon.h |  4 ++++
> >   drivers/spi/Kconfig                              |  2 +-
> >   3 files changed, 22 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/arm/mach-omap/include/mach/am33xx-devices.h b/arch/arm/mach-omap/include/mach/am33xx-devices.h
> > index fe9fba9..cea4504 100644
> > --- a/arch/arm/mach-omap/include/mach/am33xx-devices.h
> > +++ b/arch/arm/mach-omap/include/mach/am33xx-devices.h
> > @@ -7,6 +7,7 @@
> >   #include <mach/devices.h>
> >   #include <mach/omap_hsmmc.h>
> >   #include <mach/cpsw.h>
> > +#include <mach/omap_hsmmc.h>
> 
> this header has been already included just two lines before.

Oh, this must have slipped in while rebasing. Sascha, could you drop
this if the rest is acceptable?

Regards,
Jan
-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From s.hauer at pengutronix.de  Mon Jun 17 03:12:25 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 09:12:25 +0200
Subject: [PATCH] ARM: pcm038: Avoid warning if gadget support not
 compiled in
In-Reply-To: <1370966063.553147631@f314.mail.ru>
References: <1370773361-25588-1-git-send-email-shc_work@mail.ru>
 <20130611152747.GP32299@pengutronix.de>
 <1370966063.553147631@f314.mail.ru>
Message-ID: <20130617071225.GG32299@pengutronix.de>

On Tue, Jun 11, 2013 at 07:54:23PM +0400, Alexander Shiyan wrote:
> > On Sun, Jun 09, 2013 at 02:22:41PM +0400, Alexander Shiyan wrote:
> > > 
> > > Signed-off-by: Alexander Shiyan <shc_work at mail.ru>
> > > ---
> > >  arch/arm/boards/pcm038/pcm038.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
> > > index 49677c2..dec5164 100644
> > > --- a/arch/arm/boards/pcm038/pcm038.c
> > > +++ b/arch/arm/boards/pcm038/pcm038.c
> > > @@ -328,7 +328,8 @@ static int pcm038_devices_init(void)
> > >  	mdelay(1);
> > >  	imx_gpio_mode(PE1_PF_USBOTG_STP);
> > >  
> > > -	imx27_add_usbotg(&pcm038_otg_pdata);
> > > +	if (IS_ENABLED(CONFIG_USB_GADGET_DRIVER_ARC))
> > > +		imx27_add_usbotg(&pcm038_otg_pdata);
> > 
> > What warning do you get without this patch?
> 
> Runtime warning "No supported role" from chipidea driver.

Applied now, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 17 03:14:51 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 09:14:51 +0200
Subject: [PATCH] OMAP4: Use default clock source for mcbsp
In-Reply-To: <1371021279.4131.1.camel@lws-weitzel>
References: <1369741903-24988-2-git-send-email-j.weitzel@phytec.de>
 <20130608131315.GC26150@pengutronix.de>
 <1371021279.4131.1.camel@lws-weitzel>
Message-ID: <20130617071451.GH32299@pengutronix.de>

On Wed, Jun 12, 2013 at 09:14:39AM +0200, Jan Weitzel wrote:
> Am Samstag, den 08.06.2013, 15:13 +0200 schrieb Sascha Hauer:
> > On Tue, May 28, 2013 at 01:51:40PM +0200, Jan Weitzel wrote:
> > > In omap4_enable_all_clocks we not only enable the mcbsp clocks, but also
> > > change the source from ABE_24M_FCLK to 24M_FCLK. Revert this and default
> > > to the reset state.
> > > 
> > > Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
> > 
> > Applied, thanks
> Didn't find it on next or master branch. Is rework needed?

Look again, it should be there now.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 17 03:16:28 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 09:16:28 +0200
Subject: [PATCH] ARM: ccmx51: Set PMIC SW1 voltage for i.MX51 less than
 TO3 only
In-Reply-To: <1371107996-11771-1-git-send-email-shc_work@mail.ru>
References: <1371107996-11771-1-git-send-email-shc_work@mail.ru>
Message-ID: <20130617071628.GI32299@pengutronix.de>

On Thu, Jun 13, 2013 at 11:19:56AM +0400, Alexander Shiyan wrote:
> This settings taken from original DIGI U-boot source code.
> 
> Signed-off-by: Alexander Shiyan <shc_work at mail.ru>

Applied, thanks

Sascha

> ---
>  arch/arm/boards/ccxmx51/ccxmx51.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm/boards/ccxmx51/ccxmx51.c b/arch/arm/boards/ccxmx51/ccxmx51.c
> index 9610e41..b760ca8 100644
> --- a/arch/arm/boards/ccxmx51/ccxmx51.c
> +++ b/arch/arm/boards/ccxmx51/ccxmx51.c
> @@ -256,13 +256,13 @@ static int ccxmx51_power_init(void)
>  	val = 0x238033;
>  	mc13xxx_reg_write(mc13xxx_dev, MC13892_REG_CHARGE, val);
>  
> -	/* Set core voltage (SW1) to 1.1V */
> -	mc13xxx_reg_read(mc13xxx_dev, MC13892_REG_SW_0, &val);
> -	val &= ~0x00001f;
> -	val |=  0x000014;
> -	mc13xxx_reg_write(mc13xxx_dev, MC13892_REG_SW_0, val);
> -
>  	if (imx_silicon_revision() < IMX_CHIP_REV_3_0) {
> +		/* Set core voltage (SW1) to 1.1V */
> +		mc13xxx_reg_read(mc13xxx_dev, MC13892_REG_SW_0, &val);
> +		val &= ~0x00001f;
> +		val |=  0x000014;
> +		mc13xxx_reg_write(mc13xxx_dev, MC13892_REG_SW_0, val);
> +
>  		/* Setup VCC (SW2) to 1.25 */
>  		mc13xxx_reg_read(mc13xxx_dev, MC13892_REG_SW_1, &val);
>  		val &= ~0x00001f;
> -- 
> 1.8.1.5
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 17 03:36:47 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 09:36:47 +0200
Subject: [PATCH v6] omap4-fb: add driver
In-Reply-To: <1371222662.28854.15.camel@mars>
References: <1365706897.4136.24.camel@mars> <1370207222.5021.0.camel@lovely>
 <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars>
 <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel>
 <1371197742.3873.8.camel@mars>
 <20130614114312.GG27130@game.jcrosoft.org>
 <1371222662.28854.15.camel@mars>
Message-ID: <20130617073647.GJ32299@pengutronix.de>

Hi Christoph,

Some small comments, then we shoulf be good to go.

On Fri, Jun 14, 2013 at 05:11:02PM +0200, Christoph Fritz wrote:
> This patch adds omap4 display controller support.
> 
> index 94e42c6..e70ddbd 100644
> --- a/arch/arm/mach-omap/Makefile
> +++ b/arch/arm/mach-omap/Makefile
> @@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
>  pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
>  obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
>  obj-$(CONFIG_SHELL_NONE) += xload.o
> +obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o

Please compile this in unconditionally. Otherwise board using this have
to add a dependency on CONFIG_DRIVER_VIDEO_OMAP4 aswell.

> +struct device_d *omap4_add_display(void *pdata)

Let this function take a struct omap4fb_platform_data *. This makes it
more clear how to call it.

> +static void omap4fb_enable(struct fb_info *info)
> +{
> +	struct omap4fb_device *fbi =
> +		container_of(info, struct omap4fb_device, info);

You could add a static inline to_omap4fb function. It's less error prone
and the above would fit into a single line.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 17 03:47:24 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 09:47:24 +0200
Subject: [PATCH] of: add ranges address translation for default bus
In-Reply-To: <51BA1476.3060309@gmail.com>
References: <1368400146-30443-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130519073403.GY32299@pengutronix.de>
 <51B6EED2.3010707@gmail.com>
 <20130613092557.GC32299@pengutronix.de>
 <51B9930B.8080609@gmail.com>
 <20130613124833.GD32299@pengutronix.de>
 <51BA1476.3060309@gmail.com>
Message-ID: <20130617074724.GK32299@pengutronix.de>

On Thu, Jun 13, 2013 at 08:50:30PM +0200, Sebastian Hesselbarth wrote:
> On 06/13/13 14:48, Sascha Hauer wrote:
> >On Thu, Jun 13, 2013 at 11:38:19AM +0200, Sebastian Hesselbarth wrote:
> >>On 06/13/13 11:25, Sascha Hauer wrote:
> >>>Sounds like a plan. Functions existing both in barebox and Linux should
> >>>behave the same way. However, if Linux turns out to do something silly
> >>>or (for our usecase) too bloated, we shouldn't do the same just because
> >>>Linux does it.
> 
> Sascha,
> 
> pushed a branch you can have a first look at to
> 
> git://github.com/shesselba/barebox-dove.git of-sync-v1

I had a quick look at this branch. It has some really good stuff in it.
You should post it for a closer review if you consider it ready.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 17 03:50:38 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 09:50:38 +0200
Subject: [PATCH] arm: omap: am33xx: set up SPI devices
In-Reply-To: <1371453145.4168.1.camel@coredoba.hi.pengutronix.de>
References: <1370892680-13254-1-git-send-email-jlu@pengutronix.de>
 <51BADE95.9090007@phytec.de>
 <1371453145.4168.1.camel@coredoba.hi.pengutronix.de>
Message-ID: <20130617075038.GL32299@pengutronix.de>

On Mon, Jun 17, 2013 at 09:12:25AM +0200, Jan L?bbe wrote:
> On Fri, 2013-06-14 at 11:12 +0200, Teresa Gamez wrote:
> > Am 10.06.2013 21:31, schrieb Jan Luebbe:
> > > Signed-off-by: Jan Luebbe <jlu at pengutronix.de>
> > > ---
> > >   arch/arm/mach-omap/include/mach/am33xx-devices.h | 17 +++++++++++++++++
> > >   arch/arm/mach-omap/include/mach/am33xx-silicon.h |  4 ++++
> > >   drivers/spi/Kconfig                              |  2 +-
> > >   3 files changed, 22 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/arch/arm/mach-omap/include/mach/am33xx-devices.h b/arch/arm/mach-omap/include/mach/am33xx-devices.h
> > > index fe9fba9..cea4504 100644
> > > --- a/arch/arm/mach-omap/include/mach/am33xx-devices.h
> > > +++ b/arch/arm/mach-omap/include/mach/am33xx-devices.h
> > > @@ -7,6 +7,7 @@
> > >   #include <mach/devices.h>
> > >   #include <mach/omap_hsmmc.h>
> > >   #include <mach/cpsw.h>
> > > +#include <mach/omap_hsmmc.h>
> > 
> > this header has been already included just two lines before.
> 
> Oh, this must have slipped in while rebasing. Sascha, could you drop
> this if the rest is acceptable?

Applied and dropped the duplicate include.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From J.Weitzel at phytec.de  Mon Jun 17 04:00:29 2013
From: J.Weitzel at phytec.de (Jan Weitzel)
Date: Mon, 17 Jun 2013 10:00:29 +0200
Subject: [PATCH] OMAP4: Use default clock source for mcbsp
In-Reply-To: <20130617071451.GH32299@pengutronix.de>
References: <1369741903-24988-2-git-send-email-j.weitzel@phytec.de>
 <20130608131315.GC26150@pengutronix.de>
 <1371021279.4131.1.camel@lws-weitzel>
 <20130617071451.GH32299@pengutronix.de>
Message-ID: <1371456029.5079.0.camel@lws-weitzel>

Am Montag, den 17.06.2013, 09:14 +0200 schrieb Sascha Hauer:
> On Wed, Jun 12, 2013 at 09:14:39AM +0200, Jan Weitzel wrote:
> > Am Samstag, den 08.06.2013, 15:13 +0200 schrieb Sascha Hauer:
> > > On Tue, May 28, 2013 at 01:51:40PM +0200, Jan Weitzel wrote:
> > > > In omap4_enable_all_clocks we not only enable the mcbsp clocks, but also
> > > > change the source from ABE_24M_FCLK to 24M_FCLK. Revert this and default
> > > > to the reset state.
> > > > 
> > > > Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
> > > 
> > > Applied, thanks
> > Didn't find it on next or master branch. Is rework needed?
> 
> Look again, it should be there now.
Thanks :)
Jan

> 
> Sascha
> 




From s.hauer at pengutronix.de  Mon Jun 17 04:19:35 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 10:19:35 +0200
Subject: [PATCH] ARM: pcm038: Add setup for MC13783 IRQ pin
In-Reply-To: <1371303724-27020-1-git-send-email-shc_work@mail.ru>
References: <1371303724-27020-1-git-send-email-shc_work@mail.ru>
Message-ID: <20130617081935.GO32299@pengutronix.de>

On Sat, Jun 15, 2013 at 05:42:04PM +0400, Alexander Shiyan wrote:
> Kernel does not have pinctrl driver for i.MX27 yet. When we using DT,
> this cause to unable setup pins to desired function. This patch adds
> a setup for MC13783 IRQ pin to avoid this issue.
> 
> Signed-off-by: Alexander Shiyan <shc_work at mail.ru>

Applied, thanks

Sascha

> ---
>  arch/arm/boards/pcm038/pcm038.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
> index dec5164..f6a3e17 100644
> --- a/arch/arm/boards/pcm038/pcm038.c
> +++ b/arch/arm/boards/pcm038/pcm038.c
> @@ -46,9 +46,10 @@
>  
>  #include "pll.h"
>  
> +#define PCM038_GPIO_PMIC_IRQ	(GPIO_PORTB + 23)
>  #define PCM038_GPIO_FEC_RST	(GPIO_PORTC + 30)
> -#define PCM038_GPIO_SPI_CS0	(GPIO_PORTD + 28)
>  #define PCM970_GPIO_SPI_CS1	(GPIO_PORTD + 27)
> +#define PCM038_GPIO_SPI_CS0	(GPIO_PORTD + 28)
>  #define PCM038_GPIO_OTG_STP	(GPIO_PORTE + 1)
>  
>  static struct fec_platform_data fec_info = {
> @@ -225,7 +226,6 @@ static int pcm038_devices_init(void)
>  		PD15_AOUT_FEC_COL,
>  		PD16_AIN_FEC_TX_ER,
>  		PF23_AIN_FEC_TX_EN,
> -		PCM038_GPIO_FEC_RST | GPIO_GPIO | GPIO_OUT,
>  		/* UART1 */
>  		PE12_PF_UART1_TXD,
>  		PE13_PF_UART1_RXD,
> @@ -236,10 +236,6 @@ static int pcm038_devices_init(void)
>  		PD29_PF_CSPI1_SCLK,
>  		PD30_PF_CSPI1_MISO,
>  		PD31_PF_CSPI1_MOSI,
> -		PCM038_GPIO_SPI_CS0 | GPIO_GPIO | GPIO_OUT,
> -#ifdef CONFIG_MACH_PCM970_BASEBOARD
> -		PCM970_GPIO_SPI_CS1 | GPIO_GPIO | GPIO_OUT,
> -#endif
>  		/* Display */
>  		PA5_PF_LSCLK,
>  		PA6_PF_LD0,
> @@ -287,6 +283,13 @@ static int pcm038_devices_init(void)
>  		/* I2C2 */
>  		PC5_PF_I2C2_SDA,
>  		PC6_PF_I2C2_SCL,
> +		/* Misc */
> +		PCM038_GPIO_FEC_RST | GPIO_GPIO | GPIO_OUT,
> +		PCM038_GPIO_SPI_CS0 | GPIO_GPIO | GPIO_OUT,
> +#ifdef CONFIG_MACH_PCM970_BASEBOARD
> +		PCM970_GPIO_SPI_CS1 | GPIO_GPIO | GPIO_OUT,
> +#endif
> +		PCM038_GPIO_PMIC_IRQ | GPIO_GPIO | GPIO_IN,
>  	};
>  
>  	/* configure 16 bit nor flash on cs0 */
> -- 
> 1.8.1.5
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 17 04:59:14 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 10:59:14 +0200
Subject: [PATCH 2/4] ata: Add detect callback for hardware device
In-Reply-To: <1371459556-24073-1-git-send-email-s.hauer@pengutronix.de>
References: <1371459556-24073-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371459556-24073-2-git-send-email-s.hauer@pengutronix.de>

To be able to use the 'detect' command on hardware devices.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/disk_ata_drive.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 4ad7564..4c82797 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -360,6 +360,13 @@ static int ata_detect(struct device_d *dev)
 	return ata_port_detect(port);
 }
 
+static int ata_detect_hw(struct device_d *dev)
+{
+	struct ata_port *port = dev->priv;
+
+	return ata_port_detect(port);
+}
+
 /**
  * Register an ATA drive behind an IDE like interface
  * @param dev The interface device
@@ -379,6 +386,9 @@ int ata_port_register(struct ata_port *port)
 	if (ret)
 		return ret;
 
+	port->dev->priv = port;
+	port->dev->detect = ata_detect_hw;
+
 	dev_add_param_bool(&port->class_dev, "probe", ata_set_probe,
 			NULL, &port->probe, port);
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 04:59:13 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 10:59:13 +0200
Subject: [PATCH 1/4] ata: implement detect callback
Message-ID: <1371459556-24073-1-git-send-email-s.hauer@pengutronix.de>

This makes it possible to use the 'detect' command for ata devices.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/disk_ata_drive.c | 24 +++++++++++++++++++-----
 include/ata_drive.h          |  1 +
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 2cff584..4ad7564 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -325,14 +325,10 @@ on_error:
 	return rc;
 }
 
-static int ata_set_probe(struct param_d *param, void *priv)
+int ata_port_detect(struct ata_port *port)
 {
-	struct ata_port *port = priv;
 	int ret;
 
-	if (!port->probe)
-		return 0;
-
 	if (port->initialized) {
 		dev_info(&port->class_dev, "already initialized\n");
 		return 0;
@@ -347,6 +343,23 @@ static int ata_set_probe(struct param_d *param, void *priv)
 	return 0;
 }
 
+static int ata_set_probe(struct param_d *param, void *priv)
+{
+	struct ata_port *port = priv;
+
+	if (!port->probe)
+		return 0;
+
+	return ata_port_detect(port);
+}
+
+static int ata_detect(struct device_d *dev)
+{
+	struct ata_port *port = container_of(dev, struct ata_port, class_dev);
+
+	return ata_port_detect(port);
+}
+
 /**
  * Register an ATA drive behind an IDE like interface
  * @param dev The interface device
@@ -360,6 +373,7 @@ int ata_port_register(struct ata_port *port)
 	port->class_dev.id = DEVICE_ID_DYNAMIC;
 	strcpy(port->class_dev.name, "ata");
 	port->class_dev.parent = port->dev;
+	port->class_dev.detect = ata_detect;
 
 	ret = register_device(&port->class_dev);
 	if (ret)
diff --git a/include/ata_drive.h b/include/ata_drive.h
index 049082f..fcb3a3c 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -100,6 +100,7 @@ struct ata_port {
 
 int ide_port_register(struct device_d *, struct ata_ioports *);
 int ata_port_register(struct ata_port *port);
+int ata_port_detect(struct ata_port *port);
 
 struct device_d;
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 04:59:16 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 10:59:16 +0200
Subject: [PATCH 4/4] ata: i.MX pata: Add devicetree probe support
In-Reply-To: <1371459556-24073-1-git-send-email-s.hauer@pengutronix.de>
References: <1371459556-24073-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371459556-24073-4-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/pata-imx.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/ata/pata-imx.c b/drivers/ata/pata-imx.c
index 5d44883..1cff856 100644
--- a/drivers/ata/pata-imx.c
+++ b/drivers/ata/pata-imx.c
@@ -152,6 +152,7 @@ static int imx_pata_probe(struct device_d *dev)
 	struct clk *clk;
 	void __iomem *base;
 	int ret;
+	const char *devname;
 
 	io = xzalloc(sizeof(struct ata_ioports));
 	base = dev_request_mem_region(dev, 0);
@@ -172,7 +173,13 @@ static int imx_pata_probe(struct device_d *dev)
 
 	pata_imx_set_bus_timing(base, clk_get_rate(clk), 4);
 
-	ret= ide_port_register(dev, io);
+	if (IS_ENABLED(CONFIG_OFDEVICE)) {
+		devname = of_alias_get(dev->device_node);
+		if (devname)
+			devname = xstrdup(devname);
+	}
+
+	ret = ide_port_register(dev, io, devname);
 	if (ret) {
 		dev_err(dev, "Cannot register IDE interface: %s\n",
 				strerror(-ret));
@@ -190,8 +197,15 @@ out_free:
 	return ret;
 }
 
+static __maybe_unused struct of_device_id imx_pata_dt_ids[] = {
+	{
+		.compatible = "fsl,imx27-pata",
+	},
+};
+
 static struct driver_d imx_pata_driver = {
 	.name   = "imx-pata",
 	.probe  = imx_pata_probe,
+	.of_compatible = DRV_OF_COMPAT(imx_pata_dt_ids),
 };
 device_platform_driver(imx_pata_driver);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 04:59:15 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 10:59:15 +0200
Subject: [PATCH 3/4] ata: ide: Allow to set the devicename
In-Reply-To: <1371459556-24073-1-git-send-email-s.hauer@pengutronix.de>
References: <1371459556-24073-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371459556-24073-3-git-send-email-s.hauer@pengutronix.de>

To get persistent devicenames under /dev/ allow to set the
devicename from the driver instead of using "ata" unconditionally.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/disk_ata_drive.c    | 14 +++++++++-----
 drivers/ata/ide-sff.c           |  3 ++-
 drivers/ata/intf_platform_ide.c |  2 +-
 include/ata_drive.h             |  3 ++-
 4 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 4c82797..a25c75e 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -298,12 +298,16 @@ static int ata_port_init(struct ata_port *port)
 #ifdef DEBUG
 	ata_dump_id(port->id);
 #endif
-	rc = cdev_find_free_index("ata");
-	if (rc == -1)
-		pr_err("Cannot find a free index for the disk node\n");
+	if (port->devname) {
+		port->blk.cdev.name = xstrdup(port->devname);
+	} else {
+		rc = cdev_find_free_index("ata");
+		if (rc == -1)
+			pr_err("Cannot find a free index for the disk node\n");
+		port->blk.cdev.name = asprintf("ata%d", rc);
+	}
 
 	port->blk.num_blocks = ata_id_n_sectors(port->id);
-	port->blk.cdev.name = asprintf("ata%d", rc);
 	port->blk.blockbits = SECTOR_SHIFT;
 
 	rc = blockdevice_register(&port->blk);
@@ -378,7 +382,7 @@ int ata_port_register(struct ata_port *port)
 	int ret;
 
 	port->class_dev.id = DEVICE_ID_DYNAMIC;
-	strcpy(port->class_dev.name, "ata");
+
 	port->class_dev.parent = port->dev;
 	port->class_dev.detect = ata_detect;
 
diff --git a/drivers/ata/ide-sff.c b/drivers/ata/ide-sff.c
index 632b0e5..ef55357 100644
--- a/drivers/ata/ide-sff.c
+++ b/drivers/ata/ide-sff.c
@@ -324,7 +324,7 @@ static struct ata_port_operations ide_ops = {
 	.reset = ide_reset,
 };
 
-int ide_port_register(struct device_d *dev, struct ata_ioports *io)
+int ide_port_register(struct device_d *dev, struct ata_ioports *io, const char *devname)
 {
 	struct ide_port *ide;
 	int ret;
@@ -334,6 +334,7 @@ int ide_port_register(struct device_d *dev, struct ata_ioports *io)
 	ide->io = io;
 	ide->port.ops = &ide_ops;
 	ide->port.dev = dev;
+	ide->port.devname = devname;
 
 	ret = ata_port_register(&ide->port);
 
diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
index 0b56eb4..455ac28 100644
--- a/drivers/ata/intf_platform_ide.c
+++ b/drivers/ata/intf_platform_ide.c
@@ -95,7 +95,7 @@ static int platform_ide_probe(struct device_d *dev)
 	io->reset = pdata->reset;
 	io->dataif_be = pdata->dataif_be;
 
-	rc = ide_port_register(dev, io);
+	rc = ide_port_register(dev, io, NULL);
 	if (rc != 0) {
 		dev_err(dev, "Cannot register IDE interface\n");
 		free(io);
diff --git a/include/ata_drive.h b/include/ata_drive.h
index fcb3a3c..2499e62 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -91,6 +91,7 @@ struct ata_port {
 	struct ata_port_operations *ops;
 	struct device_d *dev;
 	struct device_d class_dev;
+	const char *devname;
 	void *drvdata;
 	struct block_device blk;
 	uint16_t *id;
@@ -98,7 +99,7 @@ struct ata_port {
 	int probe;
 };
 
-int ide_port_register(struct device_d *, struct ata_ioports *);
+int ide_port_register(struct device_d *, struct ata_ioports *, const char *);
 int ata_port_register(struct ata_port *port);
 int ata_port_detect(struct ata_port *port);
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 05:17:53 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 11:17:53 +0200
Subject: [PATCH 3/3] ARM: i.MX51 efikasb: call imx51_lowlevel_init from
 lowlevel init
In-Reply-To: <1371460673-14284-1-git-send-email-s.hauer@pengutronix.de>
References: <1371460673-14284-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371460673-14284-3-git-send-email-s.hauer@pengutronix.de>

Adjusting the PLLs when MMU/caching is already enabled seems to be
unstable on the Smartbook, so do it during early init.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/efika-mx-smartbook/board.c    | 5 -----
 arch/arm/boards/efika-mx-smartbook/lowlevel.c | 3 +++
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boards/efika-mx-smartbook/board.c b/arch/arm/boards/efika-mx-smartbook/board.c
index e9b6062..98f9dcd 100644
--- a/arch/arm/boards/efika-mx-smartbook/board.c
+++ b/arch/arm/boards/efika-mx-smartbook/board.c
@@ -270,11 +270,6 @@ static void efikamx_power_init(void)
 	mc13xxx_reg_write(mc, MC13892_REG_SW_2, val);
 	udelay(50);
 
-	/* Raise the core frequency to 800MHz */
-	console_flush();
-	imx51_init_lowlevel(800);
-	clock_notifier_call_chain();
-
 	/* Set switchers in Auto in NORMAL mode & STANDBY mode */
 	/* Setup the switcher mode for SW1 & SW2*/
 	mc13xxx_reg_read(mc, MC13892_REG_SW_4, &val);
diff --git a/arch/arm/boards/efika-mx-smartbook/lowlevel.c b/arch/arm/boards/efika-mx-smartbook/lowlevel.c
index 3e6a0ee..11abc93 100644
--- a/arch/arm/boards/efika-mx-smartbook/lowlevel.c
+++ b/arch/arm/boards/efika-mx-smartbook/lowlevel.c
@@ -1,9 +1,12 @@
 #include <common.h>
 #include <mach/esdctl.h>
 #include <asm/barebox-arm-head.h>
+#include <mach/imx5.h>
 
 void __naked barebox_arm_reset_vector(void)
 {
 	arm_cpu_lowlevel_init();
+	arm_setup_stack(0x20000000 - 16);
+	imx51_init_lowlevel(800);
 	imx51_barebox_entry(0);
 }
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 05:17:51 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 11:17:51 +0200
Subject: [PATCH 1/3] ARM: i.MX51: Use IIM for detecting silicon revision
Message-ID: <1371460673-14284-1-git-send-email-s.hauer@pengutronix.de>

The IROM is located at physical address 0x0, so reading the
silicon revision from it leads to a NULL pointer dereference
if done too late when the MMU is already enabled. Use the IIM
instead which is also done in the Kernel. This limits the silicon
revisions to 2.0 and 3.0, but I assume the earlier versions are
not seen in the wild anyway.

This also moves the call to imx_set_silicon_revision() out of
imx51_silicon_revision() so that imx51_silicon_revision() can be called
in early init context.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/imx51.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

diff --git a/arch/arm/mach-imx/imx51.c b/arch/arm/mach-imx/imx51.c
index fdf2374..c9f88f5 100644
--- a/arch/arm/mach-imx/imx51.c
+++ b/arch/arm/mach-imx/imx51.c
@@ -22,40 +22,28 @@
 #include <mach/clock-imx51_53.h>
 #include <mach/generic.h>
 
-#define SI_REV 0x48
+#define IIM_SREV 0x24
 
 static int imx51_silicon_revision(void)
 {
-	void __iomem *rom = MX51_IROM_BASE_ADDR;
-	u32 mx51_silicon_revision;
-	u32 rev;
+	void __iomem *iim_base = IOMEM(MX51_IIM_BASE_ADDR);
+	u32 rev = readl(iim_base + IIM_SREV) & 0xff;
 
-	rev = readl(rom + SI_REV);
 	switch (rev) {
-	case 0x1:
-		mx51_silicon_revision = IMX_CHIP_REV_1_0;
-		break;
-	case 0x2:
-		mx51_silicon_revision = IMX_CHIP_REV_1_1;
-		break;
+	case 0x0:
+		return IMX_CHIP_REV_2_0;
 	case 0x10:
-		mx51_silicon_revision = IMX_CHIP_REV_2_0;
-		break;
-	case 0x20:
-		mx51_silicon_revision = IMX_CHIP_REV_3_0;
-		break;
+		return IMX_CHIP_REV_3_0;
 	default:
-		mx51_silicon_revision = 0;
+		return IMX_CHIP_REV_UNKNOWN;
 	}
 
-	imx_set_silicon_revision("i.MX51", mx51_silicon_revision);
-
 	return 0;
 }
 
 static int imx51_init(void)
 {
-	imx51_silicon_revision();
+	imx_set_silicon_revision("i.MX51", imx51_silicon_revision());
 	imx51_boot_save_loc((void *)MX51_SRC_BASE_ADDR);
 
 	if (of_get_root_node())
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 05:17:52 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 11:17:52 +0200
Subject: [PATCH 2/3] ARM: i.MX51: Make imx51_init_lowlevel callable from early
 init
In-Reply-To: <1371460673-14284-1-git-send-email-s.hauer@pengutronix.de>
References: <1371460673-14284-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371460673-14284-2-git-send-email-s.hauer@pengutronix.de>

imx_silicon_revision() can't be used from early init context, so
use imx51_silicon_revision() instead.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/Makefile | 1 +
 arch/arm/mach-imx/imx51.c  | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
index 72125e7..db74d4e 100644
--- a/arch/arm/mach-imx/Makefile
+++ b/arch/arm/mach-imx/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_ARCH_IMX27) += imx27.o clk-imx27.o
 obj-$(CONFIG_ARCH_IMX31) += imx31.o clk-imx31.o
 obj-$(CONFIG_ARCH_IMX35) += imx35.o clk-imx35.o
 obj-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o clk-imx5.o
+pbl-$(CONFIG_ARCH_IMX51) += imx51.o imx5.o
 obj-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o clk-imx5.o esdctl-v4.o
 pbl-$(CONFIG_ARCH_IMX53) += imx53.o imx5.o esdctl-v4.o
 obj-$(CONFIG_ARCH_IMX6) += imx6.o usb-imx6.o clk-imx6.o
diff --git a/arch/arm/mach-imx/imx51.c b/arch/arm/mach-imx/imx51.c
index c9f88f5..c75534e 100644
--- a/arch/arm/mach-imx/imx51.c
+++ b/arch/arm/mach-imx/imx51.c
@@ -137,7 +137,7 @@ void imx51_init_lowlevel(unsigned int cpufreq_mhz)
 {
 	void __iomem *ccm = (void __iomem *)MX51_CCM_BASE_ADDR;
 	u32 r;
-	int rev = imx_silicon_revision();
+	int rev = imx51_silicon_revision();
 
 	imx5_init_lowlevel();
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 05:31:44 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 11:31:44 +0200
Subject: [PATCH 2/2] gpio: i.MX: initialize earlier
In-Reply-To: <1371461504-18782-1-git-send-email-s.hauer@pengutronix.de>
References: <1371461504-18782-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371461504-18782-2-git-send-email-s.hauer@pengutronix.de>

The i.MX gpio driver doesn't have dependencies, so initialize
it in a core_initcall to have the gpio functions available earlier.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/gpio/gpio-imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-imx.c b/drivers/gpio/gpio-imx.c
index 1bf4100..063a81c 100644
--- a/drivers/gpio/gpio-imx.c
+++ b/drivers/gpio/gpio-imx.c
@@ -204,4 +204,4 @@ static int imx_gpio_add(void)
 	platform_driver_register(&imx_gpio_driver);
 	return 0;
 }
-coredevice_initcall(imx_gpio_add);
+core_initcall(imx_gpio_add);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 05:31:43 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 11:31:43 +0200
Subject: [PATCH 1/2] ARM: i.MX: Make timer available earlier
Message-ID: <1371461504-18782-1-git-send-email-s.hauer@pengutronix.de>

This moves the CCM drivers to core_initcall since this has no dependencies.
This way we can be sure that the clock for the clocksource is available in
at postcore_initcall time.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/clk-imx1.c    | 2 +-
 arch/arm/mach-imx/clk-imx21.c   | 2 +-
 arch/arm/mach-imx/clk-imx25.c   | 2 +-
 arch/arm/mach-imx/clk-imx27.c   | 2 +-
 arch/arm/mach-imx/clk-imx31.c   | 2 +-
 arch/arm/mach-imx/clk-imx35.c   | 2 +-
 arch/arm/mach-imx/clk-imx5.c    | 4 ++--
 arch/arm/mach-imx/clk-imx6.c    | 2 +-
 arch/arm/mach-imx/clocksource.c | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/arm/mach-imx/clk-imx1.c b/arch/arm/mach-imx/clk-imx1.c
index 0d04a92..6fcd6fa 100644
--- a/arch/arm/mach-imx/clk-imx1.c
+++ b/arch/arm/mach-imx/clk-imx1.c
@@ -114,4 +114,4 @@ static int imx1_ccm_init(void)
 {
 	return platform_driver_register(&imx1_ccm_driver);
 }
-postcore_initcall(imx1_ccm_init);
+core_initcall(imx1_ccm_init);
diff --git a/arch/arm/mach-imx/clk-imx21.c b/arch/arm/mach-imx/clk-imx21.c
index 6e91424..295ef3a 100644
--- a/arch/arm/mach-imx/clk-imx21.c
+++ b/arch/arm/mach-imx/clk-imx21.c
@@ -189,4 +189,4 @@ static int imx21_ccm_init(void)
 {
 	return platform_driver_register(&imx21_ccm_driver);
 }
-postcore_initcall(imx21_ccm_init);
+core_initcall(imx21_ccm_init);
diff --git a/arch/arm/mach-imx/clk-imx25.c b/arch/arm/mach-imx/clk-imx25.c
index 95b105d..9817990 100644
--- a/arch/arm/mach-imx/clk-imx25.c
+++ b/arch/arm/mach-imx/clk-imx25.c
@@ -174,4 +174,4 @@ static int imx25_ccm_init(void)
 {
 	return platform_driver_register(&imx25_ccm_driver);
 }
-postcore_initcall(imx25_ccm_init);
+core_initcall(imx25_ccm_init);
diff --git a/arch/arm/mach-imx/clk-imx27.c b/arch/arm/mach-imx/clk-imx27.c
index e221928..6fd3cd6 100644
--- a/arch/arm/mach-imx/clk-imx27.c
+++ b/arch/arm/mach-imx/clk-imx27.c
@@ -229,4 +229,4 @@ static int imx27_ccm_init(void)
 {
 	return platform_driver_register(&imx27_ccm_driver);
 }
-postcore_initcall(imx27_ccm_init);
+core_initcall(imx27_ccm_init);
diff --git a/arch/arm/mach-imx/clk-imx31.c b/arch/arm/mach-imx/clk-imx31.c
index aa1b652..4935595 100644
--- a/arch/arm/mach-imx/clk-imx31.c
+++ b/arch/arm/mach-imx/clk-imx31.c
@@ -139,4 +139,4 @@ static int imx31_ccm_init(void)
 {
 	return platform_driver_register(&imx31_ccm_driver);
 }
-postcore_initcall(imx31_ccm_init);
+core_initcall(imx31_ccm_init);
diff --git a/arch/arm/mach-imx/clk-imx35.c b/arch/arm/mach-imx/clk-imx35.c
index f50c07d..6ea4577 100644
--- a/arch/arm/mach-imx/clk-imx35.c
+++ b/arch/arm/mach-imx/clk-imx35.c
@@ -192,4 +192,4 @@ static int imx35_ccm_init(void)
 {
 	return platform_driver_register(&imx35_ccm_driver);
 }
-postcore_initcall(imx35_ccm_init);
+core_initcall(imx35_ccm_init);
diff --git a/arch/arm/mach-imx/clk-imx5.c b/arch/arm/mach-imx/clk-imx5.c
index 8b5bffd..8c7ed1c 100644
--- a/arch/arm/mach-imx/clk-imx5.c
+++ b/arch/arm/mach-imx/clk-imx5.c
@@ -253,7 +253,7 @@ static int imx51_ccm_init(void)
 {
 	return platform_driver_register(&imx51_ccm_driver);
 }
-postcore_initcall(imx51_ccm_init);
+core_initcall(imx51_ccm_init);
 #endif
 
 #ifdef CONFIG_ARCH_IMX53
@@ -316,5 +316,5 @@ static int imx53_ccm_init(void)
 {
 	return platform_driver_register(&imx53_ccm_driver);
 }
-postcore_initcall(imx53_ccm_init);
+core_initcall(imx53_ccm_init);
 #endif
diff --git a/arch/arm/mach-imx/clk-imx6.c b/arch/arm/mach-imx/clk-imx6.c
index 5c84df2..3061779 100644
--- a/arch/arm/mach-imx/clk-imx6.c
+++ b/arch/arm/mach-imx/clk-imx6.c
@@ -337,4 +337,4 @@ static int imx6_ccm_init(void)
 {
 	return platform_driver_register(&imx6_ccm_driver);
 }
-postcore_initcall(imx6_ccm_init);
+core_initcall(imx6_ccm_init);
diff --git a/arch/arm/mach-imx/clocksource.c b/arch/arm/mach-imx/clocksource.c
index e18685e..c04af63 100644
--- a/arch/arm/mach-imx/clocksource.c
+++ b/arch/arm/mach-imx/clocksource.c
@@ -165,4 +165,4 @@ static int imx_gpt_init(void)
 {
 	return platform_driver_register(&imx_gpt_driver);
 }
-coredevice_initcall(imx_gpt_init);
+postcore_initcall(imx_gpt_init);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 05:36:56 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 11:36:56 +0200
Subject: [PATCH 3/3] ARM: i.MX51: Add pata alias
In-Reply-To: <1371461816-18004-1-git-send-email-s.hauer@pengutronix.de>
References: <1371461816-18004-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371461816-18004-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/dts/imx51.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/imx51.dtsi b/arch/arm/dts/imx51.dtsi
index 310614b..1a71ec9 100644
--- a/arch/arm/dts/imx51.dtsi
+++ b/arch/arm/dts/imx51.dtsi
@@ -26,6 +26,7 @@
 		mmc1 = &esdhc2;
 		mmc2 = &esdhc3;
 		mmc3 = &esdhc4;
+		pata0 = &pata;
 	};
 
 	tzic: tz-interrupt-controller at e0000000 {
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 05:36:55 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 11:36:55 +0200
Subject: [PATCH 2/3] ARM: i.MX51: Add usbmisc devicetree node
In-Reply-To: <1371461816-18004-1-git-send-email-s.hauer@pengutronix.de>
References: <1371461816-18004-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371461816-18004-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/dts/imx51.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/dts/imx51.dtsi b/arch/arm/dts/imx51.dtsi
index fcbc8be..310614b 100644
--- a/arch/arm/dts/imx51.dtsi
+++ b/arch/arm/dts/imx51.dtsi
@@ -183,6 +183,7 @@
 				compatible = "fsl,imx51-usb", "fsl,imx27-usb";
 				reg = <0x73f80000 0x0200>;
 				interrupts = <18>;
+				fsl,usbmisc = <&usbmisc 0>;
 				status = "disabled";
 			};
 
@@ -190,6 +191,7 @@
 				compatible = "fsl,imx51-usb", "fsl,imx27-usb";
 				reg = <0x73f80200 0x0200>;
 				interrupts = <14>;
+				fsl,usbmisc = <&usbmisc 1>;
 				status = "disabled";
 			};
 
@@ -197,6 +199,7 @@
 				compatible = "fsl,imx51-usb", "fsl,imx27-usb";
 				reg = <0x73f80400 0x0200>;
 				interrupts = <16>;
+				fsl,usbmisc = <&usbmisc 2>;
 				status = "disabled";
 			};
 
@@ -207,6 +210,12 @@
 				status = "disabled";
 			};
 
+			usbmisc: usbmisc at 73f80800 {
+				#index-cells = <1>;
+				compatible = "fsl,imx51-usbmisc";
+				reg = <0x73f80800 0x0200>;
+			};
+
 			gpio1: gpio at 73f84000 {
 				compatible = "fsl,imx51-gpio", "fsl,imx35-gpio";
 				reg = <0x73f84000 0x4000>;
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 05:36:54 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 11:36:54 +0200
Subject: [PATCH 1/3] ARM: i.MX51: Add USBH1 and USBH2 pinmux entries
Message-ID: <1371461816-18004-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/dts/imx51.dtsi | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/arch/arm/dts/imx51.dtsi b/arch/arm/dts/imx51.dtsi
index a900287..fcbc8be 100644
--- a/arch/arm/dts/imx51.dtsi
+++ b/arch/arm/dts/imx51.dtsi
@@ -537,6 +537,45 @@
 					};
 				};
 
+				usbh1 {
+					pinctrl_usbh1_1: usbh1grp-1 {
+						fsl,pins = <
+							MX51_PAD_USBH1_DATA0__USBH1_DATA0 0x1e5
+							MX51_PAD_USBH1_DATA1__USBH1_DATA1 0x1e5
+							MX51_PAD_USBH1_DATA2__USBH1_DATA2 0x1e5
+							MX51_PAD_USBH1_DATA3__USBH1_DATA3 0x1e5
+							MX51_PAD_USBH1_DATA4__USBH1_DATA4 0x1e5
+							MX51_PAD_USBH1_DATA5__USBH1_DATA5 0x1e5
+							MX51_PAD_USBH1_DATA6__USBH1_DATA6 0x1e5
+							MX51_PAD_USBH1_DATA7__USBH1_DATA7 0x1e5
+							MX51_PAD_USBH1_CLK__USBH1_CLK 0x1e5
+							MX51_PAD_USBH1_DIR__USBH1_DIR 0x1e5
+							MX51_PAD_USBH1_NXT__USBH1_NXT 0x1e5
+							MX51_PAD_USBH1_STP__USBH1_STP 0x1e5
+						>;
+					};
+				};
+
+
+				usbh2 {
+					pinctrl_usbh2_1: usbh2grp-1 {
+						fsl,pins = <
+							MX51_PAD_EIM_D16__USBH2_DATA0 0x1e5
+							MX51_PAD_EIM_D17__USBH2_DATA1 0x1e5
+							MX51_PAD_EIM_D18__USBH2_DATA2 0x1e5
+							MX51_PAD_EIM_D19__USBH2_DATA3 0x1e5
+							MX51_PAD_EIM_D20__USBH2_DATA4 0x1e5
+							MX51_PAD_EIM_D21__USBH2_DATA5 0x1e5
+							MX51_PAD_EIM_D22__USBH2_DATA6 0x1e5
+							MX51_PAD_EIM_D23__USBH2_DATA7 0x1e5
+							MX51_PAD_EIM_A24__USBH2_CLK 0x1e5
+							MX51_PAD_EIM_A25__USBH2_DIR 0x1e5
+							MX51_PAD_EIM_A27__USBH2_NXT 0x1e5
+							MX51_PAD_EIM_A26__USBH2_STP 0x1e5
+						>;
+					};
+				};
+
 				kpp {
 					pinctrl_kpp_1: kppgrp-1 {
 						fsl,pins = <
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Mon Jun 17 06:23:41 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Mon, 17 Jun 2013 12:23:41 +0200
Subject: [PATCH] of: add ranges address translation for default bus
In-Reply-To: <20130617074724.GK32299@pengutronix.de>
References: <1368400146-30443-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130519073403.GY32299@pengutronix.de> <51B6EED2.3010707@gmail.com>
 <20130613092557.GC32299@pengutronix.de> <51B9930B.8080609@gmail.com>
 <20130613124833.GD32299@pengutronix.de> <51BA1476.3060309@gmail.com>
 <20130617074724.GK32299@pengutronix.de>
Message-ID: <51BEE3AD.20406@gmail.com>

On 06/17/2013 09:47 AM, Sascha Hauer wrote:
> On Thu, Jun 13, 2013 at 08:50:30PM +0200, Sebastian Hesselbarth wrote:
>> On 06/13/13 14:48, Sascha Hauer wrote:
>>> On Thu, Jun 13, 2013 at 11:38:19AM +0200, Sebastian Hesselbarth wrote:
>>>> On 06/13/13 11:25, Sascha Hauer wrote:
>>>>> Sounds like a plan. Functions existing both in barebox and Linux should
>>>>> behave the same way. However, if Linux turns out to do something silly
>>>>> or (for our usecase) too bloated, we shouldn't do the same just because
>>>>> Linux does it.
>> pushed a branch you can have a first look at to
>>
>> git://github.com/shesselba/barebox-dove.git of-sync-v1
>
> I had a quick look at this branch. It has some really good stuff in it.
> You should post it for a closer review if you consider it ready.

Ok, I've had another round of patches in branch of-sync-part2-v1. I will
merge both and either send an RFC or merge in some clean-ups. I didn't
provide stubs for !CONFIG_OF at some places.

It is already kind of huge patch, so I prefer sending it before more
stuff gets in. Currently, it is more or less fully merged with Linux OF
API wrt base.c.

Next would be to move code that should have been in common/oftree.c in
the first place (of_add_initrd, of_print_nodes, ...), move out stuff to
of/device.c and of/address.c.

I haven't looked into barebox' driver/device backend but realized that
struct resource is attached to the device_node. Maybe it should also
move to some other struct (device_d) ?

Sebastian


From s.hauer at pengutronix.de  Mon Jun 17 06:23:54 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 12:23:54 +0200
Subject: [PATCH] ARM: i.MX51: Adjust IPG_CLK_DIVR to 6:1
Message-ID: <1371464634-31149-1-git-send-email-s.hauer@pengutronix.de>

The same value as used in Mainline and Freescale U-Boot. This might
increase the stability of i.MX51 boards. The 5:1 ratio we have in barebox
probably goes back to copy/paste from the i.MX53 code.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/imx51.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx51.c b/arch/arm/mach-imx/imx51.c
index c75534e..0771f94 100644
--- a/arch/arm/mach-imx/imx51.c
+++ b/arch/arm/mach-imx/imx51.c
@@ -196,7 +196,7 @@ void imx51_init_lowlevel(unsigned int cpufreq_mhz)
 	imx5_setup_pll_216((void __iomem *)MX51_PLL3_BASE_ADDR);
 
 	/* Set the platform clock dividers */
-	writel(0x00000124, MX51_ARM_BASE_ADDR + 0x14);
+	writel(0x00000125, MX51_ARM_BASE_ADDR + 0x14);
 
 	/* Run at Full speed */
 	writel(0x0, ccm + MX5_CCM_CACRR);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 17 06:40:55 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 17 Jun 2013 12:40:55 +0200
Subject: [PATCH] of: add ranges address translation for default bus
In-Reply-To: <51BEE3AD.20406@gmail.com>
References: <1368400146-30443-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130519073403.GY32299@pengutronix.de>
 <51B6EED2.3010707@gmail.com>
 <20130613092557.GC32299@pengutronix.de>
 <51B9930B.8080609@gmail.com>
 <20130613124833.GD32299@pengutronix.de>
 <51BA1476.3060309@gmail.com>
 <20130617074724.GK32299@pengutronix.de> <51BEE3AD.20406@gmail.com>
Message-ID: <20130617104055.GQ32299@pengutronix.de>

On Mon, Jun 17, 2013 at 12:23:41PM +0200, Sebastian Hesselbarth wrote:
> On 06/17/2013 09:47 AM, Sascha Hauer wrote:
> >On Thu, Jun 13, 2013 at 08:50:30PM +0200, Sebastian Hesselbarth wrote:
> >>On 06/13/13 14:48, Sascha Hauer wrote:
> >>>On Thu, Jun 13, 2013 at 11:38:19AM +0200, Sebastian Hesselbarth wrote:
> >>>>On 06/13/13 11:25, Sascha Hauer wrote:
> >>>>>Sounds like a plan. Functions existing both in barebox and Linux should
> >>>>>behave the same way. However, if Linux turns out to do something silly
> >>>>>or (for our usecase) too bloated, we shouldn't do the same just because
> >>>>>Linux does it.
> >>pushed a branch you can have a first look at to
> >>
> >>git://github.com/shesselba/barebox-dove.git of-sync-v1
> >
> >I had a quick look at this branch. It has some really good stuff in it.
> >You should post it for a closer review if you consider it ready.
> 
> Ok, I've had another round of patches in branch of-sync-part2-v1. I will
> merge both and either send an RFC or merge in some clean-ups. I didn't
> provide stubs for !CONFIG_OF at some places.
> 
> It is already kind of huge patch, so I prefer sending it before more
> stuff gets in. Currently, it is more or less fully merged with Linux OF
> API wrt base.c.
> 
> Next would be to move code that should have been in common/oftree.c in
> the first place (of_add_initrd, of_print_nodes, ...), move out stuff to
> of/device.c and of/address.c.
> 
> I haven't looked into barebox' driver/device backend but realized that
> struct resource is attached to the device_node. Maybe it should also
> move to some other struct (device_d) ?

It already is attached to struct device_d. It should be easy to drop the
reference in struct device_node. I don't know why struct device_node has
the resources in it anyway, probably this happened during development
and I never thought about it again.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From plagnioj at jcrosoft.com  Mon Jun 17 12:17:42 2013
From: plagnioj at jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
Date: Mon, 17 Jun 2013 18:17:42 +0200
Subject: [PATCH v6] omap4-fb: add driver
In-Reply-To: <20130617073647.GJ32299@pengutronix.de>
References: <1370207222.5021.0.camel@lovely> <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars>
 <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel>
 <1371197742.3873.8.camel@mars>
 <20130614114312.GG27130@game.jcrosoft.org>
 <1371222662.28854.15.camel@mars>
 <20130617073647.GJ32299@pengutronix.de>
Message-ID: <20130617161742.GH27130@game.jcrosoft.org>

On 09:36 Mon 17 Jun     , Sascha Hauer wrote:
> Hi Christoph,
> 
> Some small comments, then we shoulf be good to go.
> 
> On Fri, Jun 14, 2013 at 05:11:02PM +0200, Christoph Fritz wrote:
> > This patch adds omap4 display controller support.
> > 
> > index 94e42c6..e70ddbd 100644
> > --- a/arch/arm/mach-omap/Makefile
> > +++ b/arch/arm/mach-omap/Makefile
> > @@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
> >  pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
> >  obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
> >  obj-$(CONFIG_SHELL_NONE) += xload.o
> > +obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
> 
> Please compile this in unconditionally. Otherwise board using this have
> to add a dependency on CONFIG_DRIVER_VIDEO_OMAP4 aswell.

if you have an inline for the fonction no need
as this will do the trick too

the mach-omap and the driver should be splittted and IIRC the omap fb is not
only for omap 4

I add Tomi to this patch from TI

> 
> > +struct device_d *omap4_add_display(void *pdata)
> 
> Let this function take a struct omap4fb_platform_data *. This makes it
> more clear how to call it.
and check the prototype by gcc
> 
> > +static void omap4fb_enable(struct fb_info *info)
> > +{
> > +	struct omap4fb_device *fbi =
> > +		container_of(info, struct omap4fb_device, info);
> 
> You could add a static inline to_omap4fb function. It's less error prone
> and the above would fit into a single line.
> 
> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From chf.fritz at googlemail.com  Mon Jun 17 12:18:00 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Mon, 17 Jun 2013 18:18:00 +0200
Subject: [PATCH v6] omap4-fb: add driver
In-Reply-To: <20130614114312.GG27130@game.jcrosoft.org>
References: <20130409132917.GX1568@game.jcrosoft.org>
 <1365706897.4136.24.camel@mars> <1370207222.5021.0.camel@lovely>
 <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars>
 <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel>
 <1371197742.3873.8.camel@mars>
 <20130614114312.GG27130@game.jcrosoft.org>
Message-ID: <20130617161800.GI27130@game.jcrosoft.org>

This patch adds omap4 display controller support.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
changes since v2:
        - use dev_request_mem_region_by_name()
changes since v3:
        - remove register struct
        - use uncached screen_base
changes since v4:
        - remove useless dev_add_param()
        - use wait_on_timeout() instead while-deadlock
changes since v5:
	- use dev_dbg() and dev_err(), be less verbose
	- fix coding-style issues
	- add omap4fb_find_display_by_name()
	- add additional read/write macros
---
 arch/arm/mach-omap/Makefile                |    1 +
 arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
 arch/arm/mach-omap/omap4_fb.c              |   27 ++
 drivers/video/Kconfig                      |    8 +
 drivers/video/Makefile                     |    1 +
 drivers/video/omap4.c                      |  526 ++++++++++++++++++++++++++++
 drivers/video/omap4.h                      |  187 ++++++++++
 7 files changed, 796 insertions(+)
 create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
 create mode 100644 arch/arm/mach-omap/omap4_fb.c
 create mode 100644 drivers/video/omap4.c
 create mode 100644 drivers/video/omap4.h

diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 94e42c6..e70ddbd 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
 obj-$(CONFIG_SHELL_NONE) += xload.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
 obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
 obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
 obj-y += gpio.o
diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
new file mode 100644
index 0000000..5c0a54b
--- /dev/null
+++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
@@ -0,0 +1,46 @@
+#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+
+#include <fb.h>
+
+#define OMAP_DSS_LCD_TFT	(1u << 0)
+#define OMAP_DSS_LCD_IVS	(1u << 1)
+#define OMAP_DSS_LCD_IHS	(1u << 2)
+#define OMAP_DSS_LCD_IPC	(1u << 3)
+#define OMAP_DSS_LCD_IEO	(1u << 4)
+#define OMAP_DSS_LCD_RF	(1u << 5)
+#define OMAP_DSS_LCD_ONOFF	(1u << 6)
+
+#define OMAP_DSS_LCD_DATALINES(_l)	((_l) << 10)
+#define OMAP_DSS_LCD_DATALINES_msk	OMAP_DSS_LCD_DATALINES(3u)
+#define OMAP_DSS_LCD_DATALINES_12	OMAP_DSS_LCD_DATALINES(0u)
+#define OMAP_DSS_LCD_DATALINES_16	OMAP_DSS_LCD_DATALINES(1u)
+#define OMAP_DSS_LCD_DATALINES_18	OMAP_DSS_LCD_DATALINES(2u)
+#define OMAP_DSS_LCD_DATALINES_24	OMAP_DSS_LCD_DATALINES(3u)
+
+struct omap4fb_display {
+	struct fb_videomode mode;
+
+	unsigned long config;
+
+	unsigned int power_on_delay;
+	unsigned int power_off_delay;
+};
+
+struct omap4fb_platform_data {
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	unsigned int dss_clk_hz;
+
+	unsigned int bpp;
+
+	struct resource const *screen;
+
+	void (*enable)(int p);
+};
+
+struct device_d;
+struct device_d *omap4_add_display(void *pdata);
+
+#endif	/* H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H */
diff --git a/arch/arm/mach-omap/omap4_fb.c b/arch/arm/mach-omap/omap4_fb.c
new file mode 100644
index 0000000..09a6af3
--- /dev/null
+++ b/arch/arm/mach-omap/omap4_fb.c
@@ -0,0 +1,27 @@
+#include <driver.h>
+#include <common.h>
+#include <linux/ioport.h>
+#include <mach/omap4-fb.h>
+
+static struct resource omap4_fb_resources[] = {
+	{
+		.name	= "omap4_dss",
+		.start	= 0x48040000,
+		.end	= 0x48040000 + 512 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	}, {
+		.name	= "omap4_dispc",
+		.start	= 0x48041000,
+		.end	= 0x48041000 + 3072 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	},
+};
+
+struct device_d *omap4_add_display(void *pdata)
+{
+	return add_generic_device_res("omap4_fb", -1,
+				      omap4_fb_resources,
+				      ARRAY_SIZE(omap4_fb_resources),
+				      pdata);
+}
+EXPORT_SYMBOL(omap4_add_display);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 6d6b08f..9dfa0cd 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -45,6 +45,14 @@ config DRIVER_VIDEO_S3C24XX
 	help
 	  Add support for the S3C244x LCD controller.
 
+config DRIVER_VIDEO_OMAP4
+	bool "OMAP4 framebuffer driver"
+	depends on ARCH_OMAP4
+	help
+	  Add support for the OMAP4 Display Controller.
+	  DSI is unsupported, only DISPC parallel mode on LCD2
+	  is supported.
+
 if DRIVER_VIDEO_S3C24XX
 
 config DRIVER_VIDEO_S3C_VERBOSE
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 7429141..83feebb 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
 obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
 obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
 obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4.o
diff --git a/drivers/video/omap4.c b/drivers/video/omap4.c
new file mode 100644
index 0000000..afdee44
--- /dev/null
+++ b/drivers/video/omap4.c
@@ -0,0 +1,526 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.com>
+ *   Based on work by Enrico Scholz, sponsored by Phytec
+ *
+ * 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.
+ */
+
+#include <driver.h>
+#include <fb.h>
+#include <errno.h>
+#include <xfuncs.h>
+#include <init.h>
+#include <stdio.h>
+#include <io.h>
+#include <common.h>
+#include <malloc.h>
+#include <common.h>
+#include <clock.h>
+
+#include <mach/omap4-silicon.h>
+#include <mach/omap4-fb.h>
+
+#include <asm/mmu.h>
+
+#include "omap4.h"
+
+struct omap4fb_device {
+	struct fb_info info;
+	struct device_d *dev;
+
+	struct omap4fb_display const *cur_display;
+
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	void __iomem *dss;
+	void __iomem *dispc;
+
+	struct {
+		void __iomem *addr;
+		size_t size;
+	} prealloc_screen;
+
+	struct {
+		uint32_t dispc_control;
+		uint32_t dispc_pol_freq;
+	} shadow;
+
+	struct {
+		unsigned int dss_clk_hz;
+		unsigned int lckd;
+		unsigned int pckd;
+	} divisor;
+	size_t dma_size;
+	void (*enable_fn)(int);
+
+	struct fb_videomode	video_modes[];
+};
+
+static void omap4fb_enable(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	dev_dbg(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(1);
+
+	udelay(fbi->cur_display->power_on_delay * 1000u);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL, O4_DISPC_CONTROL2);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_VID1_ATTRIBUTES) |
+		DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE, O4_DISPC_VID1_ATTRIBUTES);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_GOLCD, O4_DISPC_CONTROL2);
+}
+
+static void omap4fb_disable(struct fb_info *info)
+{
+	struct omap4fb_device	*fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	dev_dbg(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) &
+		~(DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL), O4_DISPC_CONTROL2);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_VID1_ATTRIBUTES) &
+		~(DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE),
+		O4_DISPC_VID1_ATTRIBUTES);
+
+	if (fbi->prealloc_screen.addr == NULL) {
+		/* free frame buffer; but only when screen is not
+		* preallocated */
+		if (info->screen_base)
+			dma_free_coherent(info->screen_base, fbi->dma_size);
+	}
+
+	info->screen_base = NULL;
+
+	udelay(fbi->cur_display->power_off_delay * 1000u);
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(0);
+}
+
+static void omap4fb_calc_divisor(struct omap4fb_device *fbi,
+			struct fb_videomode const *mode)
+{
+	unsigned int l, k, t, b;
+
+	b = UINT_MAX;
+	for (l = 1; l < 256; l++) {
+		for (k = 1; k < 256; k++) {
+			t = abs(mode->pixclock * 100 -
+				(fbi->divisor.dss_clk_hz / l / k));
+			if (t <= b) {
+				b = t;
+				fbi->divisor.lckd = l;
+				fbi->divisor.pckd = k;
+			}
+		}
+	}
+}
+
+static unsigned int omap4fb_calc_format(struct fb_info const *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		return 9;
+	case 32:
+		return 0x8; /* xRGB24-8888 (32-bit container) */
+	default:
+		dev_err(fbi->dev, "%s: unsupported bpp %d\n", __func__,
+			info->bits_per_pixel);
+		return 0;
+	}
+}
+
+struct omap4fb_colors {
+	struct fb_bitfield	red;
+	struct fb_bitfield	green;
+	struct fb_bitfield	blue;
+	struct fb_bitfield	transp;
+};
+
+static struct omap4fb_colors const omap4fb_col[] = {
+	[0] = {
+		.red	= { .length = 0, .offset = 0 },
+	},
+	[1] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+	},
+	[2] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+		.transp	= { .length = 8, .offset = 24 },
+	},
+};
+
+static void omap4fb_fill_shadow(struct omap4fb_device *fbi,
+				struct omap4fb_display const *display)
+{
+	fbi->shadow.dispc_control = 0;
+	fbi->shadow.dispc_pol_freq = 0;
+
+	fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_STNTFT;
+
+	switch (display->config & OMAP_DSS_LCD_DATALINES_msk) {
+	case OMAP_DSS_LCD_DATALINES_12:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_12;
+		break;
+	case OMAP_DSS_LCD_DATALINES_16:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_16;
+		break;
+	case OMAP_DSS_LCD_DATALINES_18:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_18;
+		break;
+	case OMAP_DSS_LCD_DATALINES_24:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_24;
+		break;
+	}
+
+	if (display->config & OMAP_DSS_LCD_IPC)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IPC;
+
+	if (display->config & OMAP_DSS_LCD_IVS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IVS;
+
+	if (display->config & OMAP_DSS_LCD_IHS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IHS;
+
+	if (display->config & OMAP_DSS_LCD_IEO)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IEO;
+
+	if (display->config & OMAP_DSS_LCD_RF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_RF;
+
+	if (display->config & OMAP_DSS_LCD_ONOFF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_ONOFF;
+}
+
+static int omap4fb_find_display_by_name(struct omap4fb_device *fbi,
+		const char *name)
+{
+	int i;
+
+	for (i = 0; i < fbi->num_displays; ++i) {
+		if (strcmp(name, fbi->displays[i].mode.name) == 0)
+			return i;
+	}
+	return -ENXIO;
+}
+
+static int omap4fb_activate_var(struct fb_info *info)
+{
+	struct omap4fb_device *fbi =
+		container_of(info, struct omap4fb_device, info);
+	struct fb_videomode const *mode = info->mode;
+	size_t size = mode->xres * mode->yres * (info->bits_per_pixel / 8);
+	int rc;
+	unsigned int fmt = omap4fb_calc_format(info);
+	struct omap4fb_colors const *cols;
+	struct omap4fb_display const *new_display = NULL;
+
+	rc = omap4fb_find_display_by_name(fbi, mode->name);
+	if (rc < 0) {
+		dev_err(fbi->dev, "no display found for this mode '%s'\n",
+			mode->name);
+		goto out;
+	}
+	new_display = &fbi->displays[rc];
+
+	/*Free old screen buf*/
+	if (!fbi->prealloc_screen.addr && info->screen_base)
+		dma_free_coherent(info->screen_base, fbi->dma_size);
+
+	fbi->dma_size = PAGE_ALIGN(size);
+
+	if (!fbi->prealloc_screen.addr) {
+		/* case 1: no preallocated screen */
+		info->screen_base = dma_alloc_coherent(size);
+	} else if (fbi->prealloc_screen.size < fbi->dma_size) {
+		/* case 2: preallocated screen, but too small */
+		dev_err(fbi->dev,
+			"allocated framebuffer too small (%zu < %zu)\n",
+			fbi->prealloc_screen.size, fbi->dma_size);
+		rc = -ENOMEM;
+		goto out;
+	} else {
+		/* case 3: preallocated screen */
+		info->screen_base = fbi->prealloc_screen.addr;
+	}
+
+	omap4fb_fill_shadow(fbi, new_display);
+
+	omap4fb_calc_divisor(fbi, mode);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		cols = &omap4fb_col[1];
+		break;
+	case 32:
+		cols = &omap4fb_col[2];
+		break;
+	default:
+		cols = &omap4fb_col[0];
+	}
+
+	info->red = cols->red;
+	info->green = cols->green;
+	info->blue = cols->blue;
+	info->transp = cols->transp;
+
+	o4_dispc_write(fbi->shadow.dispc_control, O4_DISPC_CONTROL2);
+
+	o4_dispc_write(fbi->shadow.dispc_pol_freq, O4_DISPC_POL_FREQ2);
+
+	o4_dispc_write(DSS_DISPC_TIMING_H_HSW(mode->hsync_len - 1) |
+		DSS_DISPC_TIMING_H_HFP(mode->right_margin - 1) |
+		DSS_DISPC_TIMING_H_HBP(mode->left_margin - 1),
+		O4_DISPC_TIMING_H2);
+
+	o4_dispc_write(DSS_DISPC_TIMING_V_VSW(mode->vsync_len - 1) |
+		DSS_DISPC_TIMING_V_VFP(mode->lower_margin) |
+		DSS_DISPC_TIMING_V_VBP(mode->upper_margin), O4_DISPC_TIMING_V2);
+
+	o4_dispc_write(DSS_DISPC_DIVISOR_ENABLE | DSS_DISPC_DIVISOR_LCD(1),
+		O4_DISPC_DIVISOR);
+
+	o4_dispc_write(DSS_DISPC_DIVISOR2_LCD(fbi->divisor.lckd) |
+		DSS_DISPC_DIVISOR2_PCD(fbi->divisor.pckd), O4_DISPC_DIVISOR2);
+
+	o4_dispc_write(DSS_DISPC_SIZE_LCD_PPL(mode->xres - 1) |
+		DSS_DISPC_SIZE_LCD_LPP(mode->yres - 1), O4_DISPC_SIZE_LCD2);
+
+	o4_dispc_write(0x0000ff00, O4_DISPC_DEFAULT_COLOR2);
+
+	/* we use VID1 */
+	o4_dispc_write((uintptr_t)info->screen_base, O4_DISPC_VID1_BA0);
+	o4_dispc_write((uintptr_t)info->screen_base, O4_DISPC_VID1_BA1);
+
+	o4_dispc_write(DSS_DISPC_VIDn_POSITION_VIDPOSX(0) |
+		DSS_DISPC_VIDn_POSITION_VIDPOSY(0), O4_DISPC_VID1_POSITION);
+	o4_dispc_write(DSS_DISPC_VIDn_SIZE_VIDSIZEX(mode->xres - 1) |
+		DSS_DISPC_VIDn_SIZE_VIDSIZEY(mode->yres - 1),
+		O4_DISPC_VID1_SIZE);
+	o4_dispc_write(DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(mode->xres - 1) |
+		DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(mode->yres - 1),
+		O4_DISPC_VID1_PICTURE_SIZE);
+	o4_dispc_write(1, O4_DISPC_VID1_ROW_INC);
+	o4_dispc_write(1, O4_DISPC_VID1_PIXEL_INC);
+
+	o4_dispc_write(0xfff, O4_DISPC_VID1_PRELOAD);
+
+	o4_dispc_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
+		DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
+		DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
+		DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
+		O4_DISPC_VID1_ATTRIBUTES);
+
+	rc = wait_on_timeout(O4_TIMEOUT,
+		!(o4_dispc_read(O4_DISPC_CONTROL2) &
+		DSS_DISPC_CONTROL_GOLCD));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: dispc golcd\n");
+		goto out;
+	}
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_GOLCD, O4_DISPC_CONTROL2);
+
+	fbi->cur_display = new_display;
+	info->xres = mode->xres;
+	info->yres = mode->yres;
+
+	rc = 0;
+
+out:
+	return rc;
+}
+
+static int omap4fb_reset(struct omap4fb_device const *fbi)
+{
+	uint32_t v = o4_dispc_read(O4_DISPC_CONTROL2);
+	int rc;
+
+	/* step 1: stop the LCD controller */
+	if (v & DSS_DISPC_CONTROL_LCDENABLE) {
+		o4_dispc_write(v & ~DSS_DISPC_CONTROL_LCDENABLE,
+			O4_DISPC_CONTROL2);
+
+		o4_dispc_write(DSS_DISPC_IRQSTATUS_FRAMEDONE2,
+			O4_DISPC_IRQSTATUS);
+
+		rc = wait_on_timeout(O4_TIMEOUT,
+			((o4_dispc_read(O4_DISPC_IRQSTATUS) &
+			DSS_DISPC_IRQSTATUS_FRAMEDONE) != 0));
+
+		if (rc) {
+			dev_err(fbi->dev, "timeout: irqstatus framedone\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	/* step 2: wait for reset done status */
+	rc = wait_on_timeout(O4_TIMEOUT,
+		(o4_dss_read(O4_DSS_SYSSTATUS) &
+		DSS_DSS_SYSSTATUS_RESETDONE));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: sysstatus resetdone\n");
+		return -ETIMEDOUT;
+	}
+
+	/* DSS_CTL: set to reset value */
+	o4_dss_write(0, O4_DSS_CTRL);
+
+	return 0;
+}
+
+static struct fb_ops omap4fb_ops = {
+	.fb_enable		= omap4fb_enable,
+	.fb_disable		= omap4fb_disable,
+	.fb_activate_var	= omap4fb_activate_var,
+};
+
+static int omap4fb_probe(struct device_d *dev)
+{
+	struct omap4fb_platform_data const *pdata = dev->platform_data;
+	struct omap4fb_device *fbi;
+	struct fb_info *info;
+	int rc;
+	size_t i;
+
+	if (!pdata)
+		return -ENODEV;
+
+	fbi = xzalloc(sizeof *fbi +
+		pdata->num_displays * sizeof fbi->video_modes[0]);
+	info = &fbi->info;
+
+	fbi->dev = dev;
+
+	/* CM_DSS_CLKSTCTRL (TRM: 935) trigger SW_WKUP */
+	__raw_writel(0x2, 0x4a009100); /* TODO: move this to clockmanagement */
+
+	fbi->dss   = dev_request_mem_region_by_name(dev, "omap4_dss");
+	fbi->dispc = dev_request_mem_region_by_name(dev, "omap4_dispc");
+
+	if (!fbi->dss || !fbi->dispc) {
+		dev_err(dev, "Insufficient register description\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	dev_info(dev, "HW-Revision 0x%04x 0x%04x\n",
+		o4_dss_read(O4_DISPC_REVISION),
+		o4_dss_read(O4_DSS_REVISION));
+
+	if (!pdata->dss_clk_hz | !pdata->displays | !pdata->num_displays |
+		!pdata->bpp) {
+		dev_err(dev, "Insufficient omap4fb_platform_data\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	fbi->enable_fn    = pdata->enable;
+	fbi->displays     = pdata->displays;
+	fbi->num_displays = pdata->num_displays;
+	fbi->divisor.dss_clk_hz = pdata->dss_clk_hz;
+
+	for (i = 0; i < pdata->num_displays; ++i)
+		fbi->video_modes[i] = pdata->displays[i].mode;
+
+	info->mode_list = fbi->video_modes;
+	info->num_modes = pdata->num_displays;
+
+	info->priv = fbi;
+	info->fbops = &omap4fb_ops;
+	info->bits_per_pixel = pdata->bpp;
+
+	if (pdata->screen) {
+		if (!IS_ALIGNED(pdata->screen->start, PAGE_SIZE) ||
+			!IS_ALIGNED(resource_size(pdata->screen), PAGE_SIZE)) {
+			dev_err(dev, "screen resource not aligned\n");
+			rc = -EINVAL;
+			goto out;
+		}
+		fbi->prealloc_screen.addr =
+				(void __iomem *)pdata->screen->start;
+		fbi->prealloc_screen.size = resource_size(pdata->screen);
+		remap_range(fbi->prealloc_screen.addr,
+			fbi->prealloc_screen.size,
+			mmu_get_pte_uncached_flags());
+	}
+
+	rc = omap4fb_reset(fbi);
+	if (rc < 0) {
+		dev_err(dev, "failed to reset: %d\n", rc);
+		goto out;
+	}
+
+	rc = register_framebuffer(info);
+	if (rc < 0) {
+		dev_err(dev, "failed to register framebuffer: %d\n", rc);
+		goto out;
+	}
+
+	rc = 0;
+	dev_info(dev, "registered\n");
+
+out:
+	if (rc < 0)
+		free(fbi);
+
+	return rc;
+}
+
+static struct driver_d omap4fb_driver = {
+	.name	= "omap4_fb",
+	.probe	= omap4fb_probe,
+};
+
+static int omap4fb_init(void)
+{
+	return platform_driver_register(&omap4fb_driver);
+}
+
+device_initcall(omap4fb_init);
diff --git a/drivers/video/omap4.h b/drivers/video/omap4.h
new file mode 100644
index 0000000..4328a6c
--- /dev/null
+++ b/drivers/video/omap4.h
@@ -0,0 +1,187 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.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.
+ */
+
+#ifndef H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+#define H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+
+#include <types.h>
+#include <common.h>
+
+#define O4_TIMEOUT	(128 * USECOND)
+
+#define _o4fb_read(io, reg)		__raw_readl((io)+(reg))
+#define _o4fb_write(val, io, reg)	__raw_writel((val), (io)+(reg))
+
+/* TRM: 10.1.3.2 DSS Registers */
+#define O4_DSS_REVISION	0x0
+#define O4_DSS_SYSSTATUS	0x14
+#define O4_DSS_CTRL		0x40
+#define O4_DSS_STATUS		0x5c
+
+#define o4_dss_read(reg)		_o4fb_read(fbi->dss, reg)
+#define o4_dss_write(val, reg)		_o4fb_write(val, fbi->dss, reg)
+
+/* TRM: 10.2.7.3 Display Controller Registers */
+#define O4_DISPC_REVISION		0x0
+#define O4_DISPC_IRQSTATUS		0x18
+#define O4_DISPC_VID1_BA0		0xbc
+#define O4_DISPC_VID1_BA1		0xc0
+#define O4_DISPC_VID1_POSITION		0xc4
+#define O4_DISPC_VID1_SIZE		0xc8
+#define O4_DISPC_VID1_ATTRIBUTES	0xcc
+#define O4_DISPC_VID1_ROW_INC		0xd8
+#define O4_DISPC_VID1_PIXEL_INC	0xdc
+#define O4_DISPC_VID1_PICTURE_SIZE	0xe4
+#define O4_DISPC_VID1_PRELOAD		0x230
+#define O4_DISPC_CONTROL2		0x238
+#define O4_DISPC_DEFAULT_COLOR2	0x3ac
+#define O4_DISPC_SIZE_LCD2		0x3cc
+#define O4_DISPC_TIMING_H2		0x400
+#define O4_DISPC_TIMING_V2		0x404
+#define O4_DISPC_POL_FREQ2		0x408
+#define O4_DISPC_DIVISOR2		0x40c
+#define O4_DISPC_DIVISOR		0x804
+
+#define o4_dispc_read(reg)		_o4fb_read(fbi->dispc, reg)
+#define o4_dispc_write(val, reg)	_o4fb_write(val, fbi->dispc, reg)
+
+#define DSS_DISPC_VIDn_POSITION_VIDPOSX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_POSITION_VIDPOSY(_y)		((_y) << 16)
+
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(_x)	((_x) << 0)
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(_y)	((_y) << 16)
+
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEY(_y)		((_y) << 16)
+
+#define DSS_DISPC_SIZE_LCD_PPL(_x)			((_x) << 0)
+#define DSS_DISPC_SIZE_LCD_LPP(_y)			((_y) << 16)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE		(1u << 0)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(_fmt)	((_fmt) << 1)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB12	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(4u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(5u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(6u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16o	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(7u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB24u	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(8u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB24p	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(9u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_YUV2	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(10u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_UYVY	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(11u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(12u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGBA32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(13u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(14u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(_b)	((_b) << 14)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_2x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_4x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(2u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCHANNELOUT	(1u << 16)
+#define DSS_DISPC_VIDn_ATTRIBUTES_SELFREFRESHAUTO	(1u << 17)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFIFOPRELOAD	(1u << 19)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDVERTICALTAPS	(1u << 21)
+#define DSS_DISPC_VIDn_ATTRIBUTES_DOUBLESTRIDE		(1u << 22)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDARBITRATION	(1u << 23)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDSELFREFRESH	(1u << 24)
+#define DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE		(1u << 25)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(_b)  ((_b) << 30)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_PRIMARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_WRITEBACK_MEM \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(3u)
+
+#define DSS_DISPC_CONTROL_LCDENABLE			(1u << 0)
+#define DSS_DISPC_CONTROL_TVENABLE			(1u << 1)
+#define DSS_DISPC_CONTROL_MONOCOLOR			(1u << 2)
+#define DSS_DISPC_CONTROL_STNTFT			(1u << 3)
+#define DSS_DISPC_CONTROL_M8B				(1u << 4)
+#define DSS_DISPC_CONTROL_GOLCD			(1u << 5)
+#define DSS_DISPC_CONTROL_GOTV				(1u << 6)
+#define DSS_DISPC_CONTROL_STDITHERENABLE		(1u << 7)
+
+#define DSS_DISPC_CONTROL_TFTDATALINES(_l)		((_l) << 8)
+#define DSS_DISPC_CONTROL_TFTDATALINES_12 \
+	DSS_DISPC_CONTROL_TFTDATALINES(0u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_16 \
+	DSS_DISPC_CONTROL_TFTDATALINES(1u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_18 \
+	DSS_DISPC_CONTROL_TFTDATALINES(2u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_24 \
+	DSS_DISPC_CONTROL_TFTDATALINES(3u)
+
+#define DSS_DISPC_CONTROL_STALLMODE			(1u << 11)
+#define DSS_DISPC_CONTROL_OVERLAYOPTIMIZATION		(1u << 12)
+#define DSS_DISPC_CONTROL_GPIN0			(1u << 13) /* ro */
+#define DSS_DISPC_CONTROL_GPIN1			(1u << 14) /* ro */
+#define DSS_DISPC_CONTROL_GPOUT0			(1u << 15)
+#define DSS_DISPC_CONTROL_GPOUT1			(1u << 16)
+#define DSS_DISPC_CONTROL_HT(_ht)			((_ht) << 17)
+#define DSS_DISPC_CONTROL_TDMENABLE			(1u << 20)
+#define DSS_DISPC_CONTROL_TDMPARALLELMODE(_pm)		((_pm) << 21)
+#define DSS_DISPC_CONTROL_TDMCYCLEFORMAT(_cf)		((_cf) << 23)
+#define DSS_DISPC_CONTROL_TDMUNUSEDBITS(_ub)		((_ub) << 25)
+#define DSS_DISPC_CONTROL_PCKFREEENABLE		(1u << 27)
+#define DSS_DISPC_CONTROL_LCDENABLESIGNAL		(1u << 28)
+#define DSS_DISPC_CONTROL_LCDENABLEPOL			(1u << 29)
+#define DSS_DISPC_CONTROL_SPATIALTEMPD(_df)		((_df) << 30)
+
+#define DSS_DISPC_POL_FREQ_IVS				(1u << 12)
+#define DSS_DISPC_POL_FREQ_IHS				(1u << 13)
+#define DSS_DISPC_POL_FREQ_IPC				(1u << 14)
+#define DSS_DISPC_POL_FREQ_IEO				(1u << 15)
+#define DSS_DISPC_POL_FREQ_RF				(1u << 16)
+#define DSS_DISPC_POL_FREQ_ONOFF			(1u << 17)
+
+#define DSS_DISPC_TIMING_H_HSW(_hsw)			((_hsw) << 0)
+#define DSS_DISPC_TIMING_H_HFP(_hfp)			((_hfp) << 8)
+#define DSS_DISPC_TIMING_H_HBP(_hbp)			((_hbp) << 20)
+
+#define DSS_DISPC_TIMING_V_VSW(_vsw)			((_vsw) << 0)
+#define DSS_DISPC_TIMING_V_VFP(_vfp)			((_vfp) << 8)
+#define DSS_DISPC_TIMING_V_VBP(_vbp)			((_vbp) << 20)
+
+#define DSS_DISPC_DIVISOR_ENABLE			(1u << 0)
+#define DSS_DISPC_DIVISOR_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_DIVISOR2_PCD(_pcd)			((_pcd) << 0)
+#define DSS_DISPC_DIVISOR2_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE			(1u << 0)
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE2			(1u << 22)
+
+#define DSS_DSS_SYSSTATUS_RESETDONE			(1u << 0)
+
+#endif	/* H_BAREBOX_DRIVER_VIDEO_O4_REGS_H */
-- 
1.7.10.4




From antonynpavlov at gmail.com  Mon Jun 17 12:35:17 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon, 17 Jun 2013 20:35:17 +0400
Subject: [PATCH 0/3] MIPS pbl fixes
Message-ID: <1371486920-4614-1-git-send-email-antonynpavlov@gmail.com>

[PATCH 1/3] MIPS: pbl: remove extra LONGSIZE definition
[PATCH 2/3] MIPS: pbl: use generated label in ADR macro
[PATCH 3/3] MIPS: pbl: remove extra copyrights


From antonynpavlov at gmail.com  Mon Jun 17 12:35:18 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon, 17 Jun 2013 20:35:18 +0400
Subject: [PATCH 1/3] MIPS: pbl: remove extra LONGSIZE definition
In-Reply-To: <1371486920-4614-1-git-send-email-antonynpavlov@gmail.com>
References: <1371486920-4614-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1371486920-4614-2-git-send-email-antonynpavlov@gmail.com>

We already have the LONGSIZE macro definition in <asm/asm.h>.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/include/asm/pbl_macros.h |    2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/mips/include/asm/pbl_macros.h b/arch/mips/include/asm/pbl_macros.h
index c32a229..6a48ca4 100644
--- a/arch/mips/include/asm/pbl_macros.h
+++ b/arch/mips/include/asm/pbl_macros.h
@@ -48,8 +48,6 @@ _pc:	addiu	\rd, ra, \label - _pc		# label is assumed to be
 	.set	pop
 	.endm
 
-#define LONGSIZE	4
-
 	.macro	copy_to_link_location start_addr
 	.set	push
 	.set	noreorder
-- 
1.7.10.4



From antonynpavlov at gmail.com  Mon Jun 17 12:35:20 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon, 17 Jun 2013 20:35:20 +0400
Subject: [PATCH 3/3] MIPS: pbl: remove extra copyrights
In-Reply-To: <1371486920-4614-1-git-send-email-antonynpavlov@gmail.com>
References: <1371486920-4614-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1371486920-4614-4-git-send-email-antonynpavlov@gmail.com>

Remove Shinya Kuribayashi's copyright on the ADR macro
in start-pbl.S as we don't define this macro in
this file or even use it where.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/boot/start-pbl.S |    1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/mips/boot/start-pbl.S b/arch/mips/boot/start-pbl.S
index 702e291..b6d127a 100644
--- a/arch/mips/boot/start-pbl.S
+++ b/arch/mips/boot/start-pbl.S
@@ -2,7 +2,6 @@
  * Startup Code for MIPS CPU
  *
  * Copyright (C) 2011, 2012 Antony Pavlov <antonynpavlov at gmail.com>
- * ADR macro copyrighted (C) 2009 by Shinya Kuribayashi <skuribay at pobox.com>
  *
  * This file is part of barebox.
  * See file CREDITS for list of people who contributed to this project.
-- 
1.7.10.4



From antonynpavlov at gmail.com  Mon Jun 17 12:35:19 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon, 17 Jun 2013 20:35:19 +0400
Subject: [PATCH 2/3] MIPS: pbl: use generated label in ADR macro
In-Reply-To: <1371486920-4614-1-git-send-email-antonynpavlov@gmail.com>
References: <1371486920-4614-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1371486920-4614-3-git-send-email-antonynpavlov@gmail.com>

The generated label usage make possible
to use the ADR macro many times.

If we don't use a generated label and we try
to use the ADR macro second time then we get

   Error: symbol `_pc' is already defined

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/include/asm/pbl_macros.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/mips/include/asm/pbl_macros.h b/arch/mips/include/asm/pbl_macros.h
index 6a48ca4..3971b61 100644
--- a/arch/mips/include/asm/pbl_macros.h
+++ b/arch/mips/include/asm/pbl_macros.h
@@ -41,9 +41,9 @@
 	.set	push
 	.set	noreorder
 	move	\temp, ra			# preserve ra beforehand
-	bal	_pc
+	bal	255f
 	 nop
-_pc:	addiu	\rd, ra, \label - _pc		# label is assumed to be
+255:	addiu	\rd, ra, \label - 255b		# label is assumed to be
 	move	ra, \temp			# within pc +/- 32KB
 	.set	pop
 	.endm
-- 
1.7.10.4



From alex.aring at gmail.com  Mon Jun 17 14:45:48 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Mon, 17 Jun 2013 20:45:48 +0200
Subject: [PATCH v6] omap4-fb: add driver
In-Reply-To: <1371222662.28854.15.camel@mars>
References: <1365706897.4136.24.camel@mars> <1370207222.5021.0.camel@lovely>
 <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars>
 <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel>
 <1371197742.3873.8.camel@mars>
 <20130614114312.GG27130@game.jcrosoft.org>
 <1371222662.28854.15.camel@mars>
Message-ID: <20130617184511.GA1698@x61s.8.8.8.8>

Hi,

only a very small nitpick.

On Fri, Jun 14, 2013 at 05:11:02PM +0200, Christoph Fritz wrote:
> This patch adds omap4 display controller support.
> 
> Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
> ---
> changes since v2:
>         - use dev_request_mem_region_by_name()
> changes since v3:
>         - remove register struct
>         - use uncached screen_base
> changes since v4:
>         - remove useless dev_add_param()
>         - use wait_on_timeout() instead while-deadlock
> changes since v5:
> 	- use dev_dbg() and dev_err(), be less verbose
> 	- fix coding-style issues
> 	- add omap4fb_find_display_by_name()
> 	- add additional read/write macros
> ---
>  arch/arm/mach-omap/Makefile                |    1 +
>  arch/arm/mach-omap/include/mach/omap4-fb.h |   46 +++
>  arch/arm/mach-omap/omap4_fb.c              |   27 ++
>  drivers/video/Kconfig                      |    8 +
>  drivers/video/Makefile                     |    1 +
>  drivers/video/omap4.c                      |  526 ++++++++++++++++++++++++++++
>  drivers/video/omap4.h                      |  187 ++++++++++
>  7 files changed, 796 insertions(+)
>  create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
>  create mode 100644 arch/arm/mach-omap/omap4_fb.c
>  create mode 100644 drivers/video/omap4.c
>  create mode 100644 drivers/video/omap4.h
> 
> diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
> index 94e42c6..e70ddbd 100644
> --- a/arch/arm/mach-omap/Makefile
> +++ b/arch/arm/mach-omap/Makefile
> @@ -28,6 +28,7 @@ obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
>  pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
>  obj-$(CONFIG_OMAP_GPMC) += gpmc.o devices-gpmc-nand.o
>  obj-$(CONFIG_SHELL_NONE) += xload.o
> +obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4_fb.o
>  obj-$(CONFIG_I2C_TWL6030) += omap4_twl6030_mmc.o
>  obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
>  obj-y += gpio.o
> diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
> new file mode 100644
> index 0000000..5c0a54b
> --- /dev/null
> +++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
> @@ -0,0 +1,46 @@
> +#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
> +#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
> +
> +#include <fb.h>
> +
> +#define OMAP_DSS_LCD_TFT	(1u << 0)
> +#define OMAP_DSS_LCD_IVS	(1u << 1)

...

> +
> +	if (!pdata)
> +		return -ENODEV;
> +

In my opinion this is a false errno for this case. But better is to drop
this check completely. It's only a check that a programmer doesn't set a
pdata which is very unlikely.

I think there was another patches on this list to remove something like
this.

Regards
Alex


From s.hauer at pengutronix.de  Tue Jun 18 03:17:48 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Jun 2013 09:17:48 +0200
Subject: [PATCH 0/3] MIPS pbl fixes
In-Reply-To: <1371486920-4614-1-git-send-email-antonynpavlov@gmail.com>
References: <1371486920-4614-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <20130618071748.GS32299@pengutronix.de>

On Mon, Jun 17, 2013 at 08:35:17PM +0400, Antony Pavlov wrote:
> [PATCH 1/3] MIPS: pbl: remove extra LONGSIZE definition
> [PATCH 2/3] MIPS: pbl: use generated label in ADR macro
> [PATCH 3/3] MIPS: pbl: remove extra copyrights

Applied all, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From tomi.valkeinen at ti.com  Tue Jun 18 03:41:29 2013
From: tomi.valkeinen at ti.com (Tomi Valkeinen)
Date: Tue, 18 Jun 2013 10:41:29 +0300
Subject: [PATCH v6] omap4-fb: add driver
In-Reply-To: <20130617161800.GI27130@game.jcrosoft.org>
References: <20130409132917.GX1568@game.jcrosoft.org>
 <1365706897.4136.24.camel@mars> <1370207222.5021.0.camel@lovely>
 <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars> <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel> <1371197742.3873.8.camel@mars>
 <20130614114312.GG27130@game.jcrosoft.org>
 <20130617161800.GI27130@game.jcrosoft.org>
Message-ID: <51C00F29.1060601@ti.com>

Hi,

On 17/06/13 19:18, Christoph Fritz wrote:
> This patch adds omap4 display controller support.

I haven't been following the discussions about this patch, so maybe
these have been covered:

OMAP2/3/4/5 all have very similar DSS. Why did you go for omap_4_-fb
driver, not omap-fb driver?

> +config DRIVER_VIDEO_OMAP4
> +	bool "OMAP4 framebuffer driver"
> +	depends on ARCH_OMAP4
> +	help
> +	  Add support for the OMAP4 Display Controller.
> +	  DSI is unsupported, only DISPC parallel mode on LCD2
> +	  is supported.
> +

Also HDMI, RFBI and VENC seem to be unsupported. The DISPC parallel mode
you mention is MIPI DPI.

Supporting only the DPI output is "easy", do you have plans to support
the other outputs and external encoders used in many boards? That may
require a more generic approach, with multiple display "entities" in the
pipeline. Not that the first version should support that, but I just
wanted to mention it so that you don't design the driver in too
non-generic manner.

 Tomi


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20130618/0e4aad13/attachment-0001.sig>

From chf.fritz at googlemail.com  Tue Jun 18 04:09:55 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Tue, 18 Jun 2013 10:09:55 +0200
Subject: [PATCH v6] omap4-fb: add driver
In-Reply-To: <51C00F29.1060601@ti.com>
References: <20130409132917.GX1568@game.jcrosoft.org>
 <1365706897.4136.24.camel@mars> <1370207222.5021.0.camel@lovely>
 <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars> <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel> <1371197742.3873.8.camel@mars>
 <20130614114312.GG27130@game.jcrosoft.org>
 <20130617161800.GI27130@game.jcrosoft.org>  <51C00F29.1060601@ti.com>
Message-ID: <1371542995.4055.12.camel@mars>

Hi Tomi

On Tue, 2013-06-18 at 10:41 +0300, Tomi Valkeinen wrote:
> On 17/06/13 19:18, Christoph Fritz wrote:
> > This patch adds omap4 display controller support.
> 
> I haven't been following the discussions about this patch, so maybe
> these have been covered:
> 
> OMAP2/3/4/5 all have very similar DSS. Why did you go for omap_4_-fb
> driver, not omap-fb driver?

I'm currently only having an omap4 board here. But I could rename the
driver to the more generic name "omap-fb" and explain in the KCONFIG
that it currently only covers omap4 devices.

So we could go from there up to all other OMAP devices. Okay?

> > +config DRIVER_VIDEO_OMAP4
> > +	bool "OMAP4 framebuffer driver"
> > +	depends on ARCH_OMAP4
> > +	help
> > +	  Add support for the OMAP4 Display Controller.
> > +	  DSI is unsupported, only DISPC parallel mode on LCD2
> > +	  is supported.
> > +
> 
> Also HDMI, RFBI and VENC seem to be unsupported. The DISPC parallel mode
> you mention is MIPI DPI.
> 
> Supporting only the DPI output is "easy", do you have plans to support
> the other outputs and external encoders used in many boards?

No, at present I have no intention to do so.

>  That may
> require a more generic approach, with multiple display "entities" in the
> pipeline. Not that the first version should support that, but I just
> wanted to mention it so that you don't design the driver in too
> non-generic manner.

 Thanks
  -- Christoph




From chf.fritz at googlemail.com  Tue Jun 18 04:47:52 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Tue, 18 Jun 2013 10:47:52 +0200
Subject: [PATCH v7] omap4-fb: add driver
In-Reply-To: <20130617073647.GJ32299@pengutronix.de>
References: <1365706897.4136.24.camel@mars> <1370207222.5021.0.camel@lovely>
 <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars> <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel> <1371197742.3873.8.camel@mars>
 <20130614114312.GG27130@game.jcrosoft.org> <1371222662.28854.15.camel@mars>
 <20130617073647.GJ32299@pengutronix.de>
Message-ID: <1371545272.4055.16.camel@mars>

This patch adds omap4 display controller support.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
changes since v2:
        - use dev_request_mem_region_by_name()
changes since v3:
        - remove register struct
        - use uncached screen_base
changes since v4:
        - remove useless dev_add_param()
        - use wait_on_timeout() instead while-deadlock
changes since v5:
        - use dev_dbg() and dev_err(), be less verbose
        - fix coding-style issues
        - add omap4fb_find_display_by_name()
        - add additional read/write macros
changes since v6:
	- add inline function to_omap4fb()
	- use 'struct omap4fb_platform_data *' as argument of omap4_add_display()
	- remove platform data check from omap4fb_probe()
	- compile omap4_fb.o unconditionally of CONFIG_DRIVER_VIDEO_OMAP4
---
 arch/arm/mach-omap/Makefile                |    1 +
 arch/arm/mach-omap/include/mach/omap4-fb.h |   47 +++
 arch/arm/mach-omap/omap4_fb.c              |   27 ++
 drivers/video/Kconfig                      |    8 +
 drivers/video/Makefile                     |    1 +
 drivers/video/omap4.c                      |  524 ++++++++++++++++++++++++++++
 drivers/video/omap4.h                      |  187 ++++++++++
 7 files changed, 795 insertions(+)
 create mode 100644 arch/arm/mach-omap/include/mach/omap4-fb.h
 create mode 100644 arch/arm/mach-omap/omap4_fb.c
 create mode 100644 drivers/video/omap4.c
 create mode 100644 drivers/video/omap4.h

diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 94e42c6..965b16a 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_ARCH_OMAP3) += omap3_core.o omap3_generic.o auxcr.o
 pbl-$(CONFIG_ARCH_OMAP3) += omap3_core.o omap3_generic.o auxcr.o
 obj-$(CONFIG_ARCH_OMAP4) += omap4_generic.o omap4_clock.o
 pbl-$(CONFIG_ARCH_OMAP4) += omap4_generic.o omap4_clock.o
+obj-$(CONFIG_ARCH_OMAP4) += omap4_fb.o
 obj-$(CONFIG_ARCH_AM33XX) += am33xx_generic.o am33xx_clock.o am33xx_mux.o
 obj-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
 pbl-$(CONFIG_OMAP3_CLOCK_CONFIG) += omap3_clock.o
diff --git a/arch/arm/mach-omap/include/mach/omap4-fb.h b/arch/arm/mach-omap/include/mach/omap4-fb.h
new file mode 100644
index 0000000..2db4ac6
--- /dev/null
+++ b/arch/arm/mach-omap/include/mach/omap4-fb.h
@@ -0,0 +1,47 @@
+#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+
+#include <fb.h>
+
+#define OMAP_DSS_LCD_TFT	(1u << 0)
+#define OMAP_DSS_LCD_IVS	(1u << 1)
+#define OMAP_DSS_LCD_IHS	(1u << 2)
+#define OMAP_DSS_LCD_IPC	(1u << 3)
+#define OMAP_DSS_LCD_IEO	(1u << 4)
+#define OMAP_DSS_LCD_RF	(1u << 5)
+#define OMAP_DSS_LCD_ONOFF	(1u << 6)
+
+#define OMAP_DSS_LCD_DATALINES(_l)	((_l) << 10)
+#define OMAP_DSS_LCD_DATALINES_msk	OMAP_DSS_LCD_DATALINES(3u)
+#define OMAP_DSS_LCD_DATALINES_12	OMAP_DSS_LCD_DATALINES(0u)
+#define OMAP_DSS_LCD_DATALINES_16	OMAP_DSS_LCD_DATALINES(1u)
+#define OMAP_DSS_LCD_DATALINES_18	OMAP_DSS_LCD_DATALINES(2u)
+#define OMAP_DSS_LCD_DATALINES_24	OMAP_DSS_LCD_DATALINES(3u)
+
+struct omap4fb_display {
+	struct fb_videomode mode;
+
+	unsigned long config;
+
+	unsigned int power_on_delay;
+	unsigned int power_off_delay;
+};
+
+struct omap4fb_platform_data {
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	unsigned int dss_clk_hz;
+
+	unsigned int bpp;
+
+	struct resource const *screen;
+
+	void (*enable)(int p);
+};
+
+struct device_d;
+struct device_d *omap4_add_display(struct omap4fb_platform_data *o4_pdata);
+
+
+#endif	/* H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H */
diff --git a/arch/arm/mach-omap/omap4_fb.c b/arch/arm/mach-omap/omap4_fb.c
new file mode 100644
index 0000000..a6bc898
--- /dev/null
+++ b/arch/arm/mach-omap/omap4_fb.c
@@ -0,0 +1,27 @@
+#include <driver.h>
+#include <common.h>
+#include <linux/ioport.h>
+#include <mach/omap4-fb.h>
+
+static struct resource omap4_fb_resources[] = {
+	{
+		.name	= "omap4_dss",
+		.start	= 0x48040000,
+		.end	= 0x48040000 + 512 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	}, {
+		.name	= "omap4_dispc",
+		.start	= 0x48041000,
+		.end	= 0x48041000 + 3072 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	},
+};
+
+struct device_d *omap4_add_display(struct omap4fb_platform_data *o4_pdata)
+{
+	return add_generic_device_res("omap4_fb", -1,
+				      omap4_fb_resources,
+				      ARRAY_SIZE(omap4_fb_resources),
+				      o4_pdata);
+}
+EXPORT_SYMBOL(omap4_add_display);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 6d6b08f..9dfa0cd 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -45,6 +45,14 @@ config DRIVER_VIDEO_S3C24XX
 	help
 	  Add support for the S3C244x LCD controller.
 
+config DRIVER_VIDEO_OMAP4
+	bool "OMAP4 framebuffer driver"
+	depends on ARCH_OMAP4
+	help
+	  Add support for the OMAP4 Display Controller.
+	  DSI is unsupported, only DISPC parallel mode on LCD2
+	  is supported.
+
 if DRIVER_VIDEO_S3C24XX
 
 config DRIVER_VIDEO_S3C_VERBOSE
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 7429141..83feebb 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
 obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
 obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
 obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP4) += omap4.o
diff --git a/drivers/video/omap4.c b/drivers/video/omap4.c
new file mode 100644
index 0000000..389edce
--- /dev/null
+++ b/drivers/video/omap4.c
@@ -0,0 +1,524 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.com>
+ *   Based on work by Enrico Scholz, sponsored by Phytec
+ *
+ * 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.
+ */
+
+#include <driver.h>
+#include <fb.h>
+#include <errno.h>
+#include <xfuncs.h>
+#include <init.h>
+#include <stdio.h>
+#include <io.h>
+#include <common.h>
+#include <malloc.h>
+#include <common.h>
+#include <clock.h>
+
+#include <mach/omap4-silicon.h>
+#include <mach/omap4-fb.h>
+
+#include <asm/mmu.h>
+
+#include "omap4.h"
+
+struct omap4fb_device {
+	struct fb_info info;
+	struct device_d *dev;
+
+	struct omap4fb_display const *cur_display;
+
+	struct omap4fb_display const *displays;
+	size_t num_displays;
+
+	void __iomem *dss;
+	void __iomem *dispc;
+
+	struct {
+		void __iomem *addr;
+		size_t size;
+	} prealloc_screen;
+
+	struct {
+		uint32_t dispc_control;
+		uint32_t dispc_pol_freq;
+	} shadow;
+
+	struct {
+		unsigned int dss_clk_hz;
+		unsigned int lckd;
+		unsigned int pckd;
+	} divisor;
+	size_t dma_size;
+	void (*enable_fn)(int);
+
+	struct fb_videomode	video_modes[];
+};
+
+static inline struct omap4fb_device *to_omap4fb(const struct fb_info *info)
+{
+	return container_of(info, struct omap4fb_device, info);
+}
+
+static void omap4fb_enable(struct fb_info *info)
+{
+	struct omap4fb_device *fbi = to_omap4fb(info);
+
+	dev_dbg(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(1);
+
+	udelay(fbi->cur_display->power_on_delay * 1000u);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL, O4_DISPC_CONTROL2);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_VID1_ATTRIBUTES) |
+		DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE, O4_DISPC_VID1_ATTRIBUTES);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_GOLCD, O4_DISPC_CONTROL2);
+}
+
+static void omap4fb_disable(struct fb_info *info)
+{
+	struct omap4fb_device *fbi = to_omap4fb(info);
+
+	dev_dbg(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) &
+		~(DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL), O4_DISPC_CONTROL2);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_VID1_ATTRIBUTES) &
+		~(DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE),
+		O4_DISPC_VID1_ATTRIBUTES);
+
+	if (fbi->prealloc_screen.addr == NULL) {
+		/* free frame buffer; but only when screen is not
+		* preallocated */
+		if (info->screen_base)
+			dma_free_coherent(info->screen_base, fbi->dma_size);
+	}
+
+	info->screen_base = NULL;
+
+	udelay(fbi->cur_display->power_off_delay * 1000u);
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(0);
+}
+
+static void omap4fb_calc_divisor(struct omap4fb_device *fbi,
+			struct fb_videomode const *mode)
+{
+	unsigned int l, k, t, b;
+
+	b = UINT_MAX;
+	for (l = 1; l < 256; l++) {
+		for (k = 1; k < 256; k++) {
+			t = abs(mode->pixclock * 100 -
+				(fbi->divisor.dss_clk_hz / l / k));
+			if (t <= b) {
+				b = t;
+				fbi->divisor.lckd = l;
+				fbi->divisor.pckd = k;
+			}
+		}
+	}
+}
+
+static unsigned int omap4fb_calc_format(struct fb_info const *info)
+{
+	struct omap4fb_device *fbi = to_omap4fb(info);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		return 9;
+	case 32:
+		return 0x8; /* xRGB24-8888 (32-bit container) */
+	default:
+		dev_err(fbi->dev, "%s: unsupported bpp %d\n", __func__,
+			info->bits_per_pixel);
+		return 0;
+	}
+}
+
+struct omap4fb_colors {
+	struct fb_bitfield	red;
+	struct fb_bitfield	green;
+	struct fb_bitfield	blue;
+	struct fb_bitfield	transp;
+};
+
+static struct omap4fb_colors const omap4fb_col[] = {
+	[0] = {
+		.red	= { .length = 0, .offset = 0 },
+	},
+	[1] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+	},
+	[2] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+		.transp	= { .length = 8, .offset = 24 },
+	},
+};
+
+static void omap4fb_fill_shadow(struct omap4fb_device *fbi,
+				struct omap4fb_display const *display)
+{
+	fbi->shadow.dispc_control = 0;
+	fbi->shadow.dispc_pol_freq = 0;
+
+	fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_STNTFT;
+
+	switch (display->config & OMAP_DSS_LCD_DATALINES_msk) {
+	case OMAP_DSS_LCD_DATALINES_12:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_12;
+		break;
+	case OMAP_DSS_LCD_DATALINES_16:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_16;
+		break;
+	case OMAP_DSS_LCD_DATALINES_18:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_18;
+		break;
+	case OMAP_DSS_LCD_DATALINES_24:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_24;
+		break;
+	}
+
+	if (display->config & OMAP_DSS_LCD_IPC)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IPC;
+
+	if (display->config & OMAP_DSS_LCD_IVS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IVS;
+
+	if (display->config & OMAP_DSS_LCD_IHS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IHS;
+
+	if (display->config & OMAP_DSS_LCD_IEO)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IEO;
+
+	if (display->config & OMAP_DSS_LCD_RF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_RF;
+
+	if (display->config & OMAP_DSS_LCD_ONOFF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_ONOFF;
+}
+
+static int omap4fb_find_display_by_name(struct omap4fb_device *fbi,
+		const char *name)
+{
+	int i;
+
+	for (i = 0; i < fbi->num_displays; ++i) {
+		if (strcmp(name, fbi->displays[i].mode.name) == 0)
+			return i;
+	}
+	return -ENXIO;
+}
+
+static int omap4fb_activate_var(struct fb_info *info)
+{
+	struct omap4fb_device *fbi = to_omap4fb(info);
+	struct fb_videomode const *mode = info->mode;
+	size_t size = mode->xres * mode->yres * (info->bits_per_pixel / 8);
+	int rc;
+	unsigned int fmt = omap4fb_calc_format(info);
+	struct omap4fb_colors const *cols;
+	struct omap4fb_display const *new_display = NULL;
+
+	rc = omap4fb_find_display_by_name(fbi, mode->name);
+	if (rc < 0) {
+		dev_err(fbi->dev, "no display found for this mode '%s'\n",
+			mode->name);
+		goto out;
+	}
+	new_display = &fbi->displays[rc];
+
+	/*Free old screen buf*/
+	if (!fbi->prealloc_screen.addr && info->screen_base)
+		dma_free_coherent(info->screen_base, fbi->dma_size);
+
+	fbi->dma_size = PAGE_ALIGN(size);
+
+	if (!fbi->prealloc_screen.addr) {
+		/* case 1: no preallocated screen */
+		info->screen_base = dma_alloc_coherent(size);
+	} else if (fbi->prealloc_screen.size < fbi->dma_size) {
+		/* case 2: preallocated screen, but too small */
+		dev_err(fbi->dev,
+			"allocated framebuffer too small (%zu < %zu)\n",
+			fbi->prealloc_screen.size, fbi->dma_size);
+		rc = -ENOMEM;
+		goto out;
+	} else {
+		/* case 3: preallocated screen */
+		info->screen_base = fbi->prealloc_screen.addr;
+	}
+
+	omap4fb_fill_shadow(fbi, new_display);
+
+	omap4fb_calc_divisor(fbi, mode);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		cols = &omap4fb_col[1];
+		break;
+	case 32:
+		cols = &omap4fb_col[2];
+		break;
+	default:
+		cols = &omap4fb_col[0];
+	}
+
+	info->red = cols->red;
+	info->green = cols->green;
+	info->blue = cols->blue;
+	info->transp = cols->transp;
+
+	o4_dispc_write(fbi->shadow.dispc_control, O4_DISPC_CONTROL2);
+
+	o4_dispc_write(fbi->shadow.dispc_pol_freq, O4_DISPC_POL_FREQ2);
+
+	o4_dispc_write(DSS_DISPC_TIMING_H_HSW(mode->hsync_len - 1) |
+		DSS_DISPC_TIMING_H_HFP(mode->right_margin - 1) |
+		DSS_DISPC_TIMING_H_HBP(mode->left_margin - 1),
+		O4_DISPC_TIMING_H2);
+
+	o4_dispc_write(DSS_DISPC_TIMING_V_VSW(mode->vsync_len - 1) |
+		DSS_DISPC_TIMING_V_VFP(mode->lower_margin) |
+		DSS_DISPC_TIMING_V_VBP(mode->upper_margin), O4_DISPC_TIMING_V2);
+
+	o4_dispc_write(DSS_DISPC_DIVISOR_ENABLE | DSS_DISPC_DIVISOR_LCD(1),
+		O4_DISPC_DIVISOR);
+
+	o4_dispc_write(DSS_DISPC_DIVISOR2_LCD(fbi->divisor.lckd) |
+		DSS_DISPC_DIVISOR2_PCD(fbi->divisor.pckd), O4_DISPC_DIVISOR2);
+
+	o4_dispc_write(DSS_DISPC_SIZE_LCD_PPL(mode->xres - 1) |
+		DSS_DISPC_SIZE_LCD_LPP(mode->yres - 1), O4_DISPC_SIZE_LCD2);
+
+	o4_dispc_write(0x0000ff00, O4_DISPC_DEFAULT_COLOR2);
+
+	/* we use VID1 */
+	o4_dispc_write((uintptr_t)info->screen_base, O4_DISPC_VID1_BA0);
+	o4_dispc_write((uintptr_t)info->screen_base, O4_DISPC_VID1_BA1);
+
+	o4_dispc_write(DSS_DISPC_VIDn_POSITION_VIDPOSX(0) |
+		DSS_DISPC_VIDn_POSITION_VIDPOSY(0), O4_DISPC_VID1_POSITION);
+	o4_dispc_write(DSS_DISPC_VIDn_SIZE_VIDSIZEX(mode->xres - 1) |
+		DSS_DISPC_VIDn_SIZE_VIDSIZEY(mode->yres - 1),
+		O4_DISPC_VID1_SIZE);
+	o4_dispc_write(DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(mode->xres - 1) |
+		DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(mode->yres - 1),
+		O4_DISPC_VID1_PICTURE_SIZE);
+	o4_dispc_write(1, O4_DISPC_VID1_ROW_INC);
+	o4_dispc_write(1, O4_DISPC_VID1_PIXEL_INC);
+
+	o4_dispc_write(0xfff, O4_DISPC_VID1_PRELOAD);
+
+	o4_dispc_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
+		DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
+		DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
+		DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
+		O4_DISPC_VID1_ATTRIBUTES);
+
+	rc = wait_on_timeout(O4_TIMEOUT,
+		!(o4_dispc_read(O4_DISPC_CONTROL2) &
+		DSS_DISPC_CONTROL_GOLCD));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: dispc golcd\n");
+		goto out;
+	}
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_GOLCD, O4_DISPC_CONTROL2);
+
+	fbi->cur_display = new_display;
+	info->xres = mode->xres;
+	info->yres = mode->yres;
+
+	rc = 0;
+
+out:
+	return rc;
+}
+
+static int omap4fb_reset(struct omap4fb_device const *fbi)
+{
+	uint32_t v = o4_dispc_read(O4_DISPC_CONTROL2);
+	int rc;
+
+	/* step 1: stop the LCD controller */
+	if (v & DSS_DISPC_CONTROL_LCDENABLE) {
+		o4_dispc_write(v & ~DSS_DISPC_CONTROL_LCDENABLE,
+			O4_DISPC_CONTROL2);
+
+		o4_dispc_write(DSS_DISPC_IRQSTATUS_FRAMEDONE2,
+			O4_DISPC_IRQSTATUS);
+
+		rc = wait_on_timeout(O4_TIMEOUT,
+			((o4_dispc_read(O4_DISPC_IRQSTATUS) &
+			DSS_DISPC_IRQSTATUS_FRAMEDONE) != 0));
+
+		if (rc) {
+			dev_err(fbi->dev, "timeout: irqstatus framedone\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	/* step 2: wait for reset done status */
+	rc = wait_on_timeout(O4_TIMEOUT,
+		(o4_dss_read(O4_DSS_SYSSTATUS) &
+		DSS_DSS_SYSSTATUS_RESETDONE));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: sysstatus resetdone\n");
+		return -ETIMEDOUT;
+	}
+
+	/* DSS_CTL: set to reset value */
+	o4_dss_write(0, O4_DSS_CTRL);
+
+	return 0;
+}
+
+static struct fb_ops omap4fb_ops = {
+	.fb_enable		= omap4fb_enable,
+	.fb_disable		= omap4fb_disable,
+	.fb_activate_var	= omap4fb_activate_var,
+};
+
+static int omap4fb_probe(struct device_d *dev)
+{
+	struct omap4fb_platform_data const *pdata = dev->platform_data;
+	struct omap4fb_device *fbi;
+	struct fb_info *info;
+	int rc;
+	size_t i;
+
+	fbi = xzalloc(sizeof *fbi +
+		pdata->num_displays * sizeof fbi->video_modes[0]);
+	info = &fbi->info;
+
+	fbi->dev = dev;
+
+	/* CM_DSS_CLKSTCTRL (TRM: 935) trigger SW_WKUP */
+	__raw_writel(0x2, 0x4a009100); /* TODO: move this to clockmanagement */
+
+	fbi->dss   = dev_request_mem_region_by_name(dev, "omap4_dss");
+	fbi->dispc = dev_request_mem_region_by_name(dev, "omap4_dispc");
+
+	if (!fbi->dss || !fbi->dispc) {
+		dev_err(dev, "Insufficient register description\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	dev_info(dev, "HW-Revision 0x%04x 0x%04x\n",
+		o4_dss_read(O4_DISPC_REVISION),
+		o4_dss_read(O4_DSS_REVISION));
+
+	if (!pdata->dss_clk_hz | !pdata->displays | !pdata->num_displays |
+		!pdata->bpp) {
+		dev_err(dev, "Insufficient omap4fb_platform_data\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	fbi->enable_fn    = pdata->enable;
+	fbi->displays     = pdata->displays;
+	fbi->num_displays = pdata->num_displays;
+	fbi->divisor.dss_clk_hz = pdata->dss_clk_hz;
+
+	for (i = 0; i < pdata->num_displays; ++i)
+		fbi->video_modes[i] = pdata->displays[i].mode;
+
+	info->mode_list = fbi->video_modes;
+	info->num_modes = pdata->num_displays;
+
+	info->priv = fbi;
+	info->fbops = &omap4fb_ops;
+	info->bits_per_pixel = pdata->bpp;
+
+	if (pdata->screen) {
+		if (!IS_ALIGNED(pdata->screen->start, PAGE_SIZE) ||
+			!IS_ALIGNED(resource_size(pdata->screen), PAGE_SIZE)) {
+			dev_err(dev, "screen resource not aligned\n");
+			rc = -EINVAL;
+			goto out;
+		}
+		fbi->prealloc_screen.addr =
+				(void __iomem *)pdata->screen->start;
+		fbi->prealloc_screen.size = resource_size(pdata->screen);
+		remap_range(fbi->prealloc_screen.addr,
+			fbi->prealloc_screen.size,
+			mmu_get_pte_uncached_flags());
+	}
+
+	rc = omap4fb_reset(fbi);
+	if (rc < 0) {
+		dev_err(dev, "failed to reset: %d\n", rc);
+		goto out;
+	}
+
+	rc = register_framebuffer(info);
+	if (rc < 0) {
+		dev_err(dev, "failed to register framebuffer: %d\n", rc);
+		goto out;
+	}
+
+	rc = 0;
+	dev_info(dev, "registered\n");
+
+out:
+	if (rc < 0)
+		free(fbi);
+
+	return rc;
+}
+
+static struct driver_d omap4fb_driver = {
+	.name	= "omap4_fb",
+	.probe	= omap4fb_probe,
+};
+
+static int omap4fb_init(void)
+{
+	return platform_driver_register(&omap4fb_driver);
+}
+
+device_initcall(omap4fb_init);
diff --git a/drivers/video/omap4.h b/drivers/video/omap4.h
new file mode 100644
index 0000000..4328a6c
--- /dev/null
+++ b/drivers/video/omap4.h
@@ -0,0 +1,187 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.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.
+ */
+
+#ifndef H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+#define H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+
+#include <types.h>
+#include <common.h>
+
+#define O4_TIMEOUT	(128 * USECOND)
+
+#define _o4fb_read(io, reg)		__raw_readl((io)+(reg))
+#define _o4fb_write(val, io, reg)	__raw_writel((val), (io)+(reg))
+
+/* TRM: 10.1.3.2 DSS Registers */
+#define O4_DSS_REVISION	0x0
+#define O4_DSS_SYSSTATUS	0x14
+#define O4_DSS_CTRL		0x40
+#define O4_DSS_STATUS		0x5c
+
+#define o4_dss_read(reg)		_o4fb_read(fbi->dss, reg)
+#define o4_dss_write(val, reg)		_o4fb_write(val, fbi->dss, reg)
+
+/* TRM: 10.2.7.3 Display Controller Registers */
+#define O4_DISPC_REVISION		0x0
+#define O4_DISPC_IRQSTATUS		0x18
+#define O4_DISPC_VID1_BA0		0xbc
+#define O4_DISPC_VID1_BA1		0xc0
+#define O4_DISPC_VID1_POSITION		0xc4
+#define O4_DISPC_VID1_SIZE		0xc8
+#define O4_DISPC_VID1_ATTRIBUTES	0xcc
+#define O4_DISPC_VID1_ROW_INC		0xd8
+#define O4_DISPC_VID1_PIXEL_INC	0xdc
+#define O4_DISPC_VID1_PICTURE_SIZE	0xe4
+#define O4_DISPC_VID1_PRELOAD		0x230
+#define O4_DISPC_CONTROL2		0x238
+#define O4_DISPC_DEFAULT_COLOR2	0x3ac
+#define O4_DISPC_SIZE_LCD2		0x3cc
+#define O4_DISPC_TIMING_H2		0x400
+#define O4_DISPC_TIMING_V2		0x404
+#define O4_DISPC_POL_FREQ2		0x408
+#define O4_DISPC_DIVISOR2		0x40c
+#define O4_DISPC_DIVISOR		0x804
+
+#define o4_dispc_read(reg)		_o4fb_read(fbi->dispc, reg)
+#define o4_dispc_write(val, reg)	_o4fb_write(val, fbi->dispc, reg)
+
+#define DSS_DISPC_VIDn_POSITION_VIDPOSX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_POSITION_VIDPOSY(_y)		((_y) << 16)
+
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(_x)	((_x) << 0)
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(_y)	((_y) << 16)
+
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEY(_y)		((_y) << 16)
+
+#define DSS_DISPC_SIZE_LCD_PPL(_x)			((_x) << 0)
+#define DSS_DISPC_SIZE_LCD_LPP(_y)			((_y) << 16)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE		(1u << 0)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(_fmt)	((_fmt) << 1)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB12	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(4u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(5u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(6u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16o	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(7u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB24u	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(8u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB24p	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(9u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_YUV2	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(10u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_UYVY	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(11u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(12u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGBA32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(13u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(14u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(_b)	((_b) << 14)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_2x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_4x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(2u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCHANNELOUT	(1u << 16)
+#define DSS_DISPC_VIDn_ATTRIBUTES_SELFREFRESHAUTO	(1u << 17)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFIFOPRELOAD	(1u << 19)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDVERTICALTAPS	(1u << 21)
+#define DSS_DISPC_VIDn_ATTRIBUTES_DOUBLESTRIDE		(1u << 22)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDARBITRATION	(1u << 23)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDSELFREFRESH	(1u << 24)
+#define DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE		(1u << 25)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(_b)  ((_b) << 30)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_PRIMARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_WRITEBACK_MEM \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(3u)
+
+#define DSS_DISPC_CONTROL_LCDENABLE			(1u << 0)
+#define DSS_DISPC_CONTROL_TVENABLE			(1u << 1)
+#define DSS_DISPC_CONTROL_MONOCOLOR			(1u << 2)
+#define DSS_DISPC_CONTROL_STNTFT			(1u << 3)
+#define DSS_DISPC_CONTROL_M8B				(1u << 4)
+#define DSS_DISPC_CONTROL_GOLCD			(1u << 5)
+#define DSS_DISPC_CONTROL_GOTV				(1u << 6)
+#define DSS_DISPC_CONTROL_STDITHERENABLE		(1u << 7)
+
+#define DSS_DISPC_CONTROL_TFTDATALINES(_l)		((_l) << 8)
+#define DSS_DISPC_CONTROL_TFTDATALINES_12 \
+	DSS_DISPC_CONTROL_TFTDATALINES(0u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_16 \
+	DSS_DISPC_CONTROL_TFTDATALINES(1u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_18 \
+	DSS_DISPC_CONTROL_TFTDATALINES(2u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_24 \
+	DSS_DISPC_CONTROL_TFTDATALINES(3u)
+
+#define DSS_DISPC_CONTROL_STALLMODE			(1u << 11)
+#define DSS_DISPC_CONTROL_OVERLAYOPTIMIZATION		(1u << 12)
+#define DSS_DISPC_CONTROL_GPIN0			(1u << 13) /* ro */
+#define DSS_DISPC_CONTROL_GPIN1			(1u << 14) /* ro */
+#define DSS_DISPC_CONTROL_GPOUT0			(1u << 15)
+#define DSS_DISPC_CONTROL_GPOUT1			(1u << 16)
+#define DSS_DISPC_CONTROL_HT(_ht)			((_ht) << 17)
+#define DSS_DISPC_CONTROL_TDMENABLE			(1u << 20)
+#define DSS_DISPC_CONTROL_TDMPARALLELMODE(_pm)		((_pm) << 21)
+#define DSS_DISPC_CONTROL_TDMCYCLEFORMAT(_cf)		((_cf) << 23)
+#define DSS_DISPC_CONTROL_TDMUNUSEDBITS(_ub)		((_ub) << 25)
+#define DSS_DISPC_CONTROL_PCKFREEENABLE		(1u << 27)
+#define DSS_DISPC_CONTROL_LCDENABLESIGNAL		(1u << 28)
+#define DSS_DISPC_CONTROL_LCDENABLEPOL			(1u << 29)
+#define DSS_DISPC_CONTROL_SPATIALTEMPD(_df)		((_df) << 30)
+
+#define DSS_DISPC_POL_FREQ_IVS				(1u << 12)
+#define DSS_DISPC_POL_FREQ_IHS				(1u << 13)
+#define DSS_DISPC_POL_FREQ_IPC				(1u << 14)
+#define DSS_DISPC_POL_FREQ_IEO				(1u << 15)
+#define DSS_DISPC_POL_FREQ_RF				(1u << 16)
+#define DSS_DISPC_POL_FREQ_ONOFF			(1u << 17)
+
+#define DSS_DISPC_TIMING_H_HSW(_hsw)			((_hsw) << 0)
+#define DSS_DISPC_TIMING_H_HFP(_hfp)			((_hfp) << 8)
+#define DSS_DISPC_TIMING_H_HBP(_hbp)			((_hbp) << 20)
+
+#define DSS_DISPC_TIMING_V_VSW(_vsw)			((_vsw) << 0)
+#define DSS_DISPC_TIMING_V_VFP(_vfp)			((_vfp) << 8)
+#define DSS_DISPC_TIMING_V_VBP(_vbp)			((_vbp) << 20)
+
+#define DSS_DISPC_DIVISOR_ENABLE			(1u << 0)
+#define DSS_DISPC_DIVISOR_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_DIVISOR2_PCD(_pcd)			((_pcd) << 0)
+#define DSS_DISPC_DIVISOR2_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE			(1u << 0)
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE2			(1u << 22)
+
+#define DSS_DSS_SYSSTATUS_RESETDONE			(1u << 0)
+
+#endif	/* H_BAREBOX_DRIVER_VIDEO_O4_REGS_H */
-- 
1.7.10.4





From tomi.valkeinen at ti.com  Tue Jun 18 05:59:30 2013
From: tomi.valkeinen at ti.com (Tomi Valkeinen)
Date: Tue, 18 Jun 2013 12:59:30 +0300
Subject: [PATCH v6] omap4-fb: add driver
In-Reply-To: <1371542995.4055.12.camel@mars>
References: <20130409132917.GX1568@game.jcrosoft.org>
 <1365706897.4136.24.camel@mars> <1370207222.5021.0.camel@lovely>
 <1371069946.25992.104.camel@mars>
 <B2329465-02EF-41CF-8B29-5C7A8BDFB349@jcrosoft.com>
 <1371163239.4055.180.camel@mars> <20130614062910.GA10743@x61s.8.8.8.8>
 <1371194628.3655.1.camel@lws-weitzel> <1371197742.3873.8.camel@mars>
 <20130614114312.GG27130@game.jcrosoft.org>
 <20130617161800.GI27130@game.jcrosoft.org> <51C00F29.1060601@ti.com>
 <1371542995.4055.12.camel@mars>
Message-ID: <51C02F82.6040406@ti.com>

On 18/06/13 11:09, Christoph Fritz wrote:
> Hi Tomi
> 
> On Tue, 2013-06-18 at 10:41 +0300, Tomi Valkeinen wrote:
>> On 17/06/13 19:18, Christoph Fritz wrote:
>>> This patch adds omap4 display controller support.
>>
>> I haven't been following the discussions about this patch, so maybe
>> these have been covered:
>>
>> OMAP2/3/4/5 all have very similar DSS. Why did you go for omap_4_-fb
>> driver, not omap-fb driver?
> 
> I'm currently only having an omap4 board here. But I could rename the
> driver to the more generic name "omap-fb" and explain in the KCONFIG
> that it currently only covers omap4 devices.
> 
> So we could go from there up to all other OMAP devices. Okay?

That sounds good to me.

 Tomi


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20130618/85f87a3d/attachment.sig>

From t.gamez at phytec.de  Tue Jun 18 07:25:44 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Tue, 18 Jun 2013 13:25:44 +0200
Subject: [PATCH 0/3] More AM33xx SPI patches
Message-ID: <1371554747-9052-1-git-send-email-t.gamez@phytec.de>

This patches are based on Jan L?bbes 

arm: omap: am33xx: set up SPI devices

patch which I haven't found in next yet.

Teresa

Teresa G?mez (3):
  ARM: OMAP: AM33xx: Add muxing function for spi0
  omap3_spi: Add CS check for AM33xx
  ARM: OMAP: pcm051: Add spi flash support

 arch/arm/boards/pcm051/board.c               |   41 ++++++++++++++++++++++++++
 arch/arm/boards/pcm051/env/init/mtdparts-nor |   12 +++++++
 arch/arm/configs/pcm051_defconfig            |    3 +-
 arch/arm/mach-omap/am33xx_mux.c              |    5 +++
 arch/arm/mach-omap/include/mach/am33xx-mux.h |    1 +
 drivers/spi/omap3_spi.c                      |   20 +++++++++++--
 6 files changed, 78 insertions(+), 4 deletions(-)
 create mode 100644 arch/arm/boards/pcm051/env/init/mtdparts-nor



From t.gamez at phytec.de  Tue Jun 18 07:25:46 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Tue, 18 Jun 2013 13:25:46 +0200
Subject: [PATCH 2/3] omap3_spi: Add CS check for AM33xx
In-Reply-To: <1371554747-9052-1-git-send-email-t.gamez@phytec.de>
References: <1371554747-9052-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371554747-9052-3-git-send-email-t.gamez@phytec.de>

AM33xx has only 2 McSPI busses and 2 CS for each bus.
Added comment and the check.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 drivers/spi/omap3_spi.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index e6581df..1eb0e6a 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -326,11 +326,17 @@ static int omap3_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
 static int omap3_spi_setup(struct spi_device *spi)
 {
 	struct spi_master *master = spi->master;
+	int is_not_valid;
 
-	if (((master->bus_num == 1) && (spi->chip_select > 3)) ||
+	if (IS_ENABLED(CONFIG_ARCH_OMAP3))
+		is_not_valid = ((master->bus_num == 1) && (spi->chip_select > 3)) ||
 			((master->bus_num == 2) && (spi->chip_select > 1)) ||
 			((master->bus_num == 3) && (spi->chip_select > 1)) ||
-			((master->bus_num == 4) && (spi->chip_select > 0))) {
+			((master->bus_num == 4) && (spi->chip_select > 0));
+	else
+		is_not_valid = (spi->chip_select > 1);
+
+	if (is_not_valid) {
 		printf("SPI error: unsupported chip select %i \
 			on bus %i\n", spi->chip_select, master->bus_num);
 		return -EINVAL;
@@ -368,12 +374,20 @@ static int omap3_spi_probe(struct device_d *dev)
 	 * McSPI3 has 2 CS (bus 3, cs 0 - 1)
 	 * McSPI4 has 1 CS (bus 4, cs 0)
 	 *
+	 * AM335x McSPI has 2 busses with 2 chip selects:
+	 * McSPI0 has 2 CS (bus 0, cs 0 - 1)
+	 * McSPI1 has 2 CS (bus 1, cs 0 - 1)
+	 *
 	 * The board code has to make sure that it does not use
 	 * invalid buses or chip selects.
 	 */
 
 	master->bus_num = dev->id;
-	master->num_chipselect = 4;
+
+	if (IS_ENABLED(CONFIG_ARCH_OMAP3))
+		master->num_chipselect = 4;
+	else
+		master->num_chipselect = 2;
 	master->setup = omap3_spi_setup;
 	master->transfer = omap3_spi_transfer;
 
-- 
1.7.0.4



From t.gamez at phytec.de  Tue Jun 18 07:25:45 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Tue, 18 Jun 2013 13:25:45 +0200
Subject: [PATCH 1/3] ARM: OMAP: AM33xx: Add muxing function for spi0
In-Reply-To: <1371554747-9052-1-git-send-email-t.gamez@phytec.de>
References: <1371554747-9052-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371554747-9052-2-git-send-email-t.gamez@phytec.de>

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 arch/arm/mach-omap/am33xx_mux.c              |    5 +++++
 arch/arm/mach-omap/include/mach/am33xx-mux.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap/am33xx_mux.c b/arch/arm/mach-omap/am33xx_mux.c
index 424d120..abc8586 100644
--- a/arch/arm/mach-omap/am33xx_mux.c
+++ b/arch/arm/mach-omap/am33xx_mux.c
@@ -314,3 +314,8 @@ void am33xx_enable_mmc0_pin_mux(void)
 {
 	configure_module_pin_mux(mmc0_pin_mux);
 }
+
+void am33xx_enable_spi0_pin_mux(void)
+{
+	configure_module_pin_mux(spi0_pin_mux);
+}
diff --git a/arch/arm/mach-omap/include/mach/am33xx-mux.h b/arch/arm/mach-omap/include/mach/am33xx-mux.h
index 44b93bd..d6b19dd 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-mux.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-mux.h
@@ -256,5 +256,6 @@ extern void am33xx_enable_i2c2_pin_mux(void);
 extern void am33xx_enable_uart0_pin_mux(void);
 extern void am33xx_enable_uart2_pin_mux(void);
 extern void am33xx_enable_mmc0_pin_mux(void);
+extern void am33xx_enable_spi0_pin_mux(void);
 
 #endif /*__AM33XX_MUX_H__ */
-- 
1.7.0.4



From t.gamez at phytec.de  Tue Jun 18 07:25:47 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Tue, 18 Jun 2013 13:25:47 +0200
Subject: [PATCH 3/3] ARM: OMAP: pcm051: Add spi flash support
In-Reply-To: <1371554747-9052-1-git-send-email-t.gamez@phytec.de>
References: <1371554747-9052-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371554747-9052-4-git-send-email-t.gamez@phytec.de>

Add support for w25q64 SPI NOR flash.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 arch/arm/boards/pcm051/board.c               |   41 ++++++++++++++++++++++++++
 arch/arm/boards/pcm051/env/init/mtdparts-nor |   12 +++++++
 arch/arm/configs/pcm051_defconfig            |    3 +-
 3 files changed, 55 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/boards/pcm051/env/init/mtdparts-nor

diff --git a/arch/arm/boards/pcm051/board.c b/arch/arm/boards/pcm051/board.c
index 8754ba5..c390c45 100644
--- a/arch/arm/boards/pcm051/board.c
+++ b/arch/arm/boards/pcm051/board.c
@@ -26,6 +26,8 @@
 #include <mach/am33xx-devices.h>
 #include <mach/am33xx-mux.h>
 #include <mach/am33xx-silicon.h>
+#include <spi/spi.h>
+#include <spi/flash.h>
 
 #include "mux.h"
 
@@ -52,12 +54,51 @@ static int pcm051_mem_init(void)
 }
 mem_initcall(pcm051_mem_init);
 
+static struct flash_platform_data pcm051_spi_flash = {
+	.name	= "nor",
+	.type	= "w25q64",
+};
+
+/*
+* SPI Flash works at 80Mhz however the SPI controller runs with 48MHz.
+* So setup Max speed to be less than the controller speed.
+*/
+static struct spi_board_info pcm051_spi_board_info[] = {
+	{
+		.name		= "m25p80",
+		.platform_data	= &pcm051_spi_flash,
+		.max_speed_hz	= 24000000,
+		.bus_num	= 0,
+		.chip_select	= 0,
+	},
+};
+
+static void pcm051_spi_init(void)
+{
+	int ret;
+
+	am33xx_enable_spi0_pin_mux();
+
+	ret = spi_register_board_info(pcm051_spi_board_info,
+					ARRAY_SIZE(pcm051_spi_board_info));
+	am33xx_add_spi0();
+}
+
 static int pcm051_devices_init(void)
 {
 	pcm051_enable_mmc0_pin_mux();
 
 	am33xx_add_mmc0(NULL);
 
+	pcm051_spi_init();
+
+	devfs_add_partition("nor0", 0x00000, SZ_128K,
+					DEVFS_PARTITION_FIXED, "xload");
+	devfs_add_partition("nor0", SZ_128K, SZ_256K,
+					DEVFS_PARTITION_FIXED, "self0");
+	devfs_add_partition("nor0", SZ_128K + SZ_256K, SZ_128K,
+					DEVFS_PARTITION_FIXED, "env0");
+
 	armlinux_set_bootparams((void *)(AM33XX_DRAM_ADDR_SPACE_START + 0x100));
 	armlinux_set_architecture(MACH_TYPE_PCM051);
 
diff --git a/arch/arm/boards/pcm051/env/init/mtdparts-nor b/arch/arm/boards/pcm051/env/init/mtdparts-nor
new file mode 100644
index 0000000..91aa847
--- /dev/null
+++ b/arch/arm/boards/pcm051/env/init/mtdparts-nor
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+if [ "$1" = menu ]; then
+	init-menu-add-entry "$0" "NOR partitions"
+	exit
+fi
+
+mtdparts="128k(nor0.xload),512k(nor0.barebox),128k(nor0.bareboxenv),4M(nor0.kernel),-(nor0.root)"
+kernelname="spi_flash"
+
+mtdparts-add -d nor0 -k ${kernelname} -p ${mtdparts}
+
diff --git a/arch/arm/configs/pcm051_defconfig b/arch/arm/configs/pcm051_defconfig
index 4da0ed4..90c2b50 100644
--- a/arch/arm/configs/pcm051_defconfig
+++ b/arch/arm/configs/pcm051_defconfig
@@ -44,8 +44,9 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_UNCOMPRESS=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SERIAL_NS16550_OMAP_EXTENSIONS=y
-# CONFIG_SPI is not set
+CONFIG_DRIVER_SPI_OMAP3=y
 CONFIG_MTD=y
+CONFIG_MTD_M25P80=y
 CONFIG_NAND=y
 CONFIG_USB=y
 CONFIG_MCI=y
-- 
1.7.0.4



From alex.aring at gmail.com  Tue Jun 18 08:11:14 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Tue, 18 Jun 2013 14:11:14 +0200
Subject: [PATCH 3/3] ARM: OMAP: pcm051: Add spi flash support
In-Reply-To: <1371554747-9052-4-git-send-email-t.gamez@phytec.de>
References: <1371554747-9052-1-git-send-email-t.gamez@phytec.de>
 <1371554747-9052-4-git-send-email-t.gamez@phytec.de>
Message-ID: <20130618121113.GB7885@x61s.8.8.8.8>

Hi,

On Tue, Jun 18, 2013 at 01:25:47PM +0200, Teresa G?mez wrote:
> Add support for w25q64 SPI NOR flash.
> 
> Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
> ---
>  arch/arm/boards/pcm051/board.c               |   41 ++++++++++++++++++++++++++
>  arch/arm/boards/pcm051/env/init/mtdparts-nor |   12 +++++++
>  arch/arm/configs/pcm051_defconfig            |    3 +-
>  3 files changed, 55 insertions(+), 1 deletions(-)
>  create mode 100644 arch/arm/boards/pcm051/env/init/mtdparts-nor
> 
> diff --git a/arch/arm/boards/pcm051/board.c b/arch/arm/boards/pcm051/board.c
> index 8754ba5..c390c45 100644
> --- a/arch/arm/boards/pcm051/board.c
> +++ b/arch/arm/boards/pcm051/board.c
> @@ -26,6 +26,8 @@
>  #include <mach/am33xx-devices.h>
>  #include <mach/am33xx-mux.h>
>  #include <mach/am33xx-silicon.h>
> +#include <spi/spi.h>
> +#include <spi/flash.h>
>  
>  #include "mux.h"
>  
> @@ -52,12 +54,51 @@ static int pcm051_mem_init(void)
>  }
>  mem_initcall(pcm051_mem_init);
>  
> +static struct flash_platform_data pcm051_spi_flash = {
> +	.name	= "nor",
> +	.type	= "w25q64",
> +};
> +
> +/*
> +* SPI Flash works at 80Mhz however the SPI controller runs with 48MHz.
> +* So setup Max speed to be less than the controller speed.
> +*/
> +static struct spi_board_info pcm051_spi_board_info[] = {
> +	{
> +		.name		= "m25p80",
> +		.platform_data	= &pcm051_spi_flash,
> +		.max_speed_hz	= 24000000,
> +		.bus_num	= 0,
> +		.chip_select	= 0,
> +	},
> +};
> +
> +static void pcm051_spi_init(void)
> +{
> +	int ret;
> +
> +	am33xx_enable_spi0_pin_mux();
> +
> +	ret = spi_register_board_info(pcm051_spi_board_info,
> +					ARRAY_SIZE(pcm051_spi_board_info));
> +	am33xx_add_spi0();
> +}
> +
>  static int pcm051_devices_init(void)
>  {
>  	pcm051_enable_mmc0_pin_mux();
>  
>  	am33xx_add_mmc0(NULL);
>  
> +	pcm051_spi_init();
> +
> +	devfs_add_partition("nor0", 0x00000, SZ_128K,
> +					DEVFS_PARTITION_FIXED, "xload");
> +	devfs_add_partition("nor0", SZ_128K, SZ_256K,
> +					DEVFS_PARTITION_FIXED, "self0");

I think this size need to be to SZ_512K or...

> +	devfs_add_partition("nor0", SZ_128K + SZ_256K, SZ_128K,
> +					DEVFS_PARTITION_FIXED, "env0");
> +
>  	armlinux_set_bootparams((void *)(AM33XX_DRAM_ADDR_SPACE_START + 0x100));
>  	armlinux_set_architecture(MACH_TYPE_PCM051);
>  
> diff --git a/arch/arm/boards/pcm051/env/init/mtdparts-nor b/arch/arm/boards/pcm051/env/init/mtdparts-nor
> new file mode 100644
> index 0000000..91aa847
> --- /dev/null
> +++ b/arch/arm/boards/pcm051/env/init/mtdparts-nor
> @@ -0,0 +1,12 @@
> +#!/bin/sh
> +
> +if [ "$1" = menu ]; then
> +	init-menu-add-entry "$0" "NOR partitions"
> +	exit
> +fi
> +
> +mtdparts="128k(nor0.xload),512k(nor0.barebox),128k(nor0.bareboxenv),4M(nor0.kernel),-(nor0.root)"

... 512k(nor0.barebox) to 256k(nor0.barebox).

Regards
Alex


From jlu at pengutronix.de  Tue Jun 18 08:50:50 2013
From: jlu at pengutronix.de (Jan Luebbe)
Date: Tue, 18 Jun 2013 14:50:50 +0200
Subject: [PATCH] devfs-core: introduce devfs_append_partition
Message-ID: <1371559850-21867-1-git-send-email-jlu@pengutronix.de>

This simplifies board code for partition setup by keeping track of the
offset.

Signed-off-by: Jan Luebbe <jlu at pengutronix.de>
---
 fs/devfs-core.c  | 9 +++++++++
 include/driver.h | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 262e0a2..f7d79ff 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -267,6 +267,15 @@ int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
 	return 0;
 }
 
+int devfs_append_partition(const char *devname, loff_t *offset, loff_t size,
+		int flags, const char *name)
+{
+	int ret;
+	ret = devfs_add_partition(devname, *offset, size, flags, name);
+	*offset += size;
+	return ret;
+}
+
 int devfs_del_partition(const char *name)
 {
 	struct cdev *cdev;
diff --git a/include/driver.h b/include/driver.h
index 716f792..3f4f7b9 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -463,6 +463,8 @@ int cdev_erase(struct cdev *cdev, size_t count, loff_t offset);
 
 int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
 		int flags, const char *name);
+int devfs_append_partition(const char *devname, loff_t *offset, loff_t size,
+		int flags, const char *name);
 int devfs_del_partition(const char *name);
 
 #define DRV_OF_COMPAT(compat) \
-- 
1.8.3.1



From W.Vanhauwaert at TELEVIC.com  Tue Jun 18 08:59:57 2013
From: W.Vanhauwaert at TELEVIC.com (Vanhauwaert Wouter)
Date: Tue, 18 Jun 2013 14:59:57 +0200
Subject: Barebox fails to boot 1/40 boots...
Message-ID: <E78BBE677EB9144B8F0A0A29674CD5338ED01639D6@SRV-VS06.TELEVIC.COM>

Hello all,

I have this issue with our custom design (IMX53, NAND, DDR3)

Everything goes well most of the time, but now and then  the system does not boot and halts during initialization... 
To be more specific, the function on which the system blocks is 'setup_c()' in arch/arm/cpu/start-pbl.c

What can I do more to debug this? This function is completely in assembler...

Grtz,
Wouter




From l.stach at pengutronix.de  Tue Jun 18 09:13:09 2013
From: l.stach at pengutronix.de (Lucas Stach)
Date: Tue, 18 Jun 2013 15:13:09 +0200
Subject: Barebox fails to boot 1/40 boots...
In-Reply-To: <E78BBE677EB9144B8F0A0A29674CD5338ED01639D6@SRV-VS06.TELEVIC.COM>
References: <E78BBE677EB9144B8F0A0A29674CD5338ED01639D6@SRV-VS06.TELEVIC.COM>
Message-ID: <1371561189.10579.3.camel@weser.hi.pengutronix.de>

Am Dienstag, den 18.06.2013, 14:59 +0200 schrieb Vanhauwaert Wouter:
> Hello all,
> 
> I have this issue with our custom design (IMX53, NAND, DDR3)
> 
> Everything goes well most of the time, but now and then  the system does not boot and halts during initialization... 
> To be more specific, the function on which the system blocks is 'setup_c()' in arch/arm/cpu/start-pbl.c
> 
> What can I do more to debug this? This function is completely in assembler...
> 
> Grtz,
> Wouter
> 

First of all: what barebox version are you running?

System crash in setup_c() smells suspiciously like the unclean cache
issue which was fixed with the 2013.05.1 release.

Regards,
Lucas
-- 
Pengutronix e.K.                           | Lucas Stach                 |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-5076 |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From t.gamez at phytec.de  Tue Jun 18 09:15:45 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Tue, 18 Jun 2013 15:15:45 +0200
Subject: [PATCHv2 1/3] ARM: OMAP: AM33xx: Add muxing function for spi0
Message-ID: <1371561347-3530-1-git-send-email-t.gamez@phytec.de>

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 arch/arm/mach-omap/am33xx_mux.c              |    5 +++++
 arch/arm/mach-omap/include/mach/am33xx-mux.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap/am33xx_mux.c b/arch/arm/mach-omap/am33xx_mux.c
index 424d120..abc8586 100644
--- a/arch/arm/mach-omap/am33xx_mux.c
+++ b/arch/arm/mach-omap/am33xx_mux.c
@@ -314,3 +314,8 @@ void am33xx_enable_mmc0_pin_mux(void)
 {
 	configure_module_pin_mux(mmc0_pin_mux);
 }
+
+void am33xx_enable_spi0_pin_mux(void)
+{
+	configure_module_pin_mux(spi0_pin_mux);
+}
diff --git a/arch/arm/mach-omap/include/mach/am33xx-mux.h b/arch/arm/mach-omap/include/mach/am33xx-mux.h
index 44b93bd..d6b19dd 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-mux.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-mux.h
@@ -256,5 +256,6 @@ extern void am33xx_enable_i2c2_pin_mux(void);
 extern void am33xx_enable_uart0_pin_mux(void);
 extern void am33xx_enable_uart2_pin_mux(void);
 extern void am33xx_enable_mmc0_pin_mux(void);
+extern void am33xx_enable_spi0_pin_mux(void);
 
 #endif /*__AM33XX_MUX_H__ */
-- 
1.7.0.4



From t.gamez at phytec.de  Tue Jun 18 09:15:46 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Tue, 18 Jun 2013 15:15:46 +0200
Subject: [PATCHv2 2/3] omap3_spi: Add CS check for AM33xx
In-Reply-To: <1371561347-3530-1-git-send-email-t.gamez@phytec.de>
References: <1371561347-3530-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371561347-3530-2-git-send-email-t.gamez@phytec.de>

AM33xx has only 2 McSPI busses and 2 CS for each bus.
Added comment and the check.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 drivers/spi/omap3_spi.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index e6581df..1eb0e6a 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -326,11 +326,17 @@ static int omap3_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
 static int omap3_spi_setup(struct spi_device *spi)
 {
 	struct spi_master *master = spi->master;
+	int is_not_valid;
 
-	if (((master->bus_num == 1) && (spi->chip_select > 3)) ||
+	if (IS_ENABLED(CONFIG_ARCH_OMAP3))
+		is_not_valid = ((master->bus_num == 1) && (spi->chip_select > 3)) ||
 			((master->bus_num == 2) && (spi->chip_select > 1)) ||
 			((master->bus_num == 3) && (spi->chip_select > 1)) ||
-			((master->bus_num == 4) && (spi->chip_select > 0))) {
+			((master->bus_num == 4) && (spi->chip_select > 0));
+	else
+		is_not_valid = (spi->chip_select > 1);
+
+	if (is_not_valid) {
 		printf("SPI error: unsupported chip select %i \
 			on bus %i\n", spi->chip_select, master->bus_num);
 		return -EINVAL;
@@ -368,12 +374,20 @@ static int omap3_spi_probe(struct device_d *dev)
 	 * McSPI3 has 2 CS (bus 3, cs 0 - 1)
 	 * McSPI4 has 1 CS (bus 4, cs 0)
 	 *
+	 * AM335x McSPI has 2 busses with 2 chip selects:
+	 * McSPI0 has 2 CS (bus 0, cs 0 - 1)
+	 * McSPI1 has 2 CS (bus 1, cs 0 - 1)
+	 *
 	 * The board code has to make sure that it does not use
 	 * invalid buses or chip selects.
 	 */
 
 	master->bus_num = dev->id;
-	master->num_chipselect = 4;
+
+	if (IS_ENABLED(CONFIG_ARCH_OMAP3))
+		master->num_chipselect = 4;
+	else
+		master->num_chipselect = 2;
 	master->setup = omap3_spi_setup;
 	master->transfer = omap3_spi_transfer;
 
-- 
1.7.0.4



From t.gamez at phytec.de  Tue Jun 18 09:15:47 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Tue, 18 Jun 2013 15:15:47 +0200
Subject: [PATCHv2 3/3] ARM: OMAP: pcm051: Add spi flash support
In-Reply-To: <1371561347-3530-1-git-send-email-t.gamez@phytec.de>
References: <1371561347-3530-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371561347-3530-3-git-send-email-t.gamez@phytec.de>

Add support for w25q64 SPI NOR flash.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
changes since v2: 
	- changed partition size to 512kb
	- added spi-nor boot option
 
arch/arm/boards/pcm051/board.c               |   41 ++++++++++++++++++++++++++
 arch/arm/boards/pcm051/env/boot/spi-nor      |   12 +++++++
 arch/arm/boards/pcm051/env/init/mtdparts-nor |   12 +++++++
 arch/arm/configs/pcm051_defconfig            |    3 +-
 4 files changed, 67 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/boards/pcm051/env/boot/spi-nor
 create mode 100644 arch/arm/boards/pcm051/env/init/mtdparts-nor

diff --git a/arch/arm/boards/pcm051/board.c b/arch/arm/boards/pcm051/board.c
index 8754ba5..f0eaa01 100644
--- a/arch/arm/boards/pcm051/board.c
+++ b/arch/arm/boards/pcm051/board.c
@@ -26,6 +26,8 @@
 #include <mach/am33xx-devices.h>
 #include <mach/am33xx-mux.h>
 #include <mach/am33xx-silicon.h>
+#include <spi/spi.h>
+#include <spi/flash.h>
 
 #include "mux.h"
 
@@ -52,12 +54,51 @@ static int pcm051_mem_init(void)
 }
 mem_initcall(pcm051_mem_init);
 
+static struct flash_platform_data pcm051_spi_flash = {
+	.name	= "nor",
+	.type	= "w25q64",
+};
+
+/*
+* SPI Flash works at 80Mhz however the SPI controller runs with 48MHz.
+* So setup Max speed to be less than the controller speed.
+*/
+static struct spi_board_info pcm051_spi_board_info[] = {
+	{
+		.name		= "m25p80",
+		.platform_data	= &pcm051_spi_flash,
+		.max_speed_hz	= 24000000,
+		.bus_num	= 0,
+		.chip_select	= 0,
+	},
+};
+
+static void pcm051_spi_init(void)
+{
+	int ret;
+
+	am33xx_enable_spi0_pin_mux();
+
+	ret = spi_register_board_info(pcm051_spi_board_info,
+					ARRAY_SIZE(pcm051_spi_board_info));
+	am33xx_add_spi0();
+}
+
 static int pcm051_devices_init(void)
 {
 	pcm051_enable_mmc0_pin_mux();
 
 	am33xx_add_mmc0(NULL);
 
+	pcm051_spi_init();
+
+	devfs_add_partition("nor0", 0x00000, SZ_128K,
+					DEVFS_PARTITION_FIXED, "xload");
+	devfs_add_partition("nor0", SZ_128K, SZ_512K,
+					DEVFS_PARTITION_FIXED, "self0");
+	devfs_add_partition("nor0", SZ_128K + SZ_512K, SZ_128K,
+					DEVFS_PARTITION_FIXED, "env0");
+
 	armlinux_set_bootparams((void *)(AM33XX_DRAM_ADDR_SPACE_START + 0x100));
 	armlinux_set_architecture(MACH_TYPE_PCM051);
 
diff --git a/arch/arm/boards/pcm051/env/boot/spi-nor b/arch/arm/boards/pcm051/env/boot/spi-nor
new file mode 100644
index 0000000..d5f77c8
--- /dev/null
+++ b/arch/arm/boards/pcm051/env/boot/spi-nor
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+if [ "$1" = menu ]; then
+        boot-menu-add-entry "$0" "SPI NOR Flash"
+        exit
+fi
+
+global.bootm.image="/dev/nor0.kernel"
+
+# Use rootfs form SD-Card for now as rootfs partition < 4MB
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
+
diff --git a/arch/arm/boards/pcm051/env/init/mtdparts-nor b/arch/arm/boards/pcm051/env/init/mtdparts-nor
new file mode 100644
index 0000000..91aa847
--- /dev/null
+++ b/arch/arm/boards/pcm051/env/init/mtdparts-nor
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+if [ "$1" = menu ]; then
+	init-menu-add-entry "$0" "NOR partitions"
+	exit
+fi
+
+mtdparts="128k(nor0.xload),512k(nor0.barebox),128k(nor0.bareboxenv),4M(nor0.kernel),-(nor0.root)"
+kernelname="spi_flash"
+
+mtdparts-add -d nor0 -k ${kernelname} -p ${mtdparts}
+
diff --git a/arch/arm/configs/pcm051_defconfig b/arch/arm/configs/pcm051_defconfig
index 4da0ed4..90c2b50 100644
--- a/arch/arm/configs/pcm051_defconfig
+++ b/arch/arm/configs/pcm051_defconfig
@@ -44,8 +44,9 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_UNCOMPRESS=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SERIAL_NS16550_OMAP_EXTENSIONS=y
-# CONFIG_SPI is not set
+CONFIG_DRIVER_SPI_OMAP3=y
 CONFIG_MTD=y
+CONFIG_MTD_M25P80=y
 CONFIG_NAND=y
 CONFIG_USB=y
 CONFIG_MCI=y
-- 
1.7.0.4



From jlu at pengutronix.de  Tue Jun 18 09:19:50 2013
From: jlu at pengutronix.de (Jan =?ISO-8859-1?Q?L=FCbbe?=)
Date: Tue, 18 Jun 2013 15:19:50 +0200
Subject: [PATCHv2 2/3] omap3_spi: Add CS check for AM33xx
In-Reply-To: <1371561347-3530-2-git-send-email-t.gamez@phytec.de>
References: <1371561347-3530-1-git-send-email-t.gamez@phytec.de>
 <1371561347-3530-2-git-send-email-t.gamez@phytec.de>
Message-ID: <1371561590.4168.67.camel@coredoba.hi.pengutronix.de>

On Tue, 2013-06-18 at 15:15 +0200, Teresa G?mez wrote:
> AM33xx has only 2 McSPI busses and 2 CS for each bus.
> Added comment and the check.
> 
> Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
> ---
>  drivers/spi/omap3_spi.c |   20 +++++++++++++++++---
>  1 files changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
> index e6581df..1eb0e6a 100644
> --- a/drivers/spi/omap3_spi.c
> +++ b/drivers/spi/omap3_spi.c
> @@ -326,11 +326,17 @@ static int omap3_spi_transfer(struct spi_device *spi, struct spi_message *mesg)
>  static int omap3_spi_setup(struct spi_device *spi)
>  {
>  	struct spi_master *master = spi->master;
> +	int is_not_valid;
>  
> -	if (((master->bus_num == 1) && (spi->chip_select > 3)) ||
> +	if (IS_ENABLED(CONFIG_ARCH_OMAP3))
> +		is_not_valid = ((master->bus_num == 1) && (spi->chip_select > 3)) ||
>  			((master->bus_num == 2) && (spi->chip_select > 1)) ||
>  			((master->bus_num == 3) && (spi->chip_select > 1)) ||
> -			((master->bus_num == 4) && (spi->chip_select > 0))) {
> +			((master->bus_num == 4) && (spi->chip_select > 0));
> +	else
> +		is_not_valid = (spi->chip_select > 1);
> +
> +	if (is_not_valid) {
>  		printf("SPI error: unsupported chip select %i \
>  			on bus %i\n", spi->chip_select, master->bus_num);
>  		return -EINVAL;
> @@ -368,12 +374,20 @@ static int omap3_spi_probe(struct device_d *dev)
>  	 * McSPI3 has 2 CS (bus 3, cs 0 - 1)
>  	 * McSPI4 has 1 CS (bus 4, cs 0)
>  	 *
> +	 * AM335x McSPI has 2 busses with 2 chip selects:
> +	 * McSPI0 has 2 CS (bus 0, cs 0 - 1)
> +	 * McSPI1 has 2 CS (bus 1, cs 0 - 1)
> +	 *
>  	 * The board code has to make sure that it does not use
>  	 * invalid buses or chip selects.
>  	 */
>  
>  	master->bus_num = dev->id;
> -	master->num_chipselect = 4;
> +
> +	if (IS_ENABLED(CONFIG_ARCH_OMAP3))
> +		master->num_chipselect = 4;
> +	else
> +		master->num_chipselect = 2;
>  	master->setup = omap3_spi_setup;
>  	master->transfer = omap3_spi_transfer;

By now, I think we should just drop the CS/bus checks in the driver. We
don't need to protect against wrong device setup from the board file of
later from DT.

Regards,
Jan


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From W.Vanhauwaert at TELEVIC.com  Tue Jun 18 09:20:27 2013
From: W.Vanhauwaert at TELEVIC.com (Vanhauwaert Wouter)
Date: Tue, 18 Jun 2013 15:20:27 +0200
Subject: Barebox fails to boot 1/40 boots...
In-Reply-To: <1371561189.10579.3.camel@weser.hi.pengutronix.de>
References: <E78BBE677EB9144B8F0A0A29674CD5338ED01639D6@SRV-VS06.TELEVIC.COM>
 <1371561189.10579.3.camel@weser.hi.pengutronix.de>
Message-ID: <E78BBE677EB9144B8F0A0A29674CD5338ED0163A0C@SRV-VS06.TELEVIC.COM>

>  -----Original Message-----
> From: Lucas Stach [mailto:l.stach at pengutronix.de]
> Sent: dinsdag 18 juni 2013 15:13
> To: Vanhauwaert Wouter
> Cc: barebox at lists.infradead.org
> Subject: Re: Barebox fails to boot 1/40 boots...
> 
> Am Dienstag, den 18.06.2013, 14:59 +0200 schrieb Vanhauwaert Wouter:
> > Hello all,
> >
> > I have this issue with our custom design (IMX53, NAND, DDR3)
> >
> > Everything goes well most of the time, but now and then  the system does not
> boot and halts during initialization...
> > To be more specific, the function on which the system blocks is
> > 'setup_c()' in arch/arm/cpu/start-pbl.c
> >
> > What can I do more to debug this? This function is completely in assembler...
> >
> > Grtz,
> > Wouter
> >
> 
> First of all: what barebox version are you running?
> 
> System crash in setup_c() smells suspiciously like the unclean cache issue which
> was fixed with the 2013.05.1 release.
> 

I'm using stable/v2013.05


From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:46 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:46 +0200
Subject: [PATCH 01/22] lib: string: import case-insensitive string compare
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-2-git-send-email-sebastian.hesselbarth@gmail.com>

This imports strnicmp, strcasecmp, and strncasecmp from Linux to barebox.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 include/linux/string.h |    9 +++++++
 lib/string.c           |   60 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/include/linux/string.h b/include/linux/string.h
index afd0aa6..658264c 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -53,6 +53,15 @@ extern int strcmp(const char *,const char *);
 #ifndef __HAVE_ARCH_STRNCMP
 extern int strncmp(const char *,const char *,__kernel_size_t);
 #endif
+#ifndef __HAVE_ARCH_STRNICMP
+extern int strnicmp(const char *, const char *, __kernel_size_t);
+#endif
+#ifndef __HAVE_ARCH_STRCASECMP
+extern int strcasecmp(const char *s1, const char *s2);
+#endif
+#ifndef __HAVE_ARCH_STRNCASECMP
+extern int strncasecmp(const char *s1, const char *s2, size_t n);
+#endif
 #ifndef __HAVE_ARCH_STRCHR
 extern char * _strchr(const char *,int);
 #endif
diff --git a/lib/string.c b/lib/string.c
index db4f2ae..f544b23 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -22,6 +22,66 @@
 
 char * ___strtok;
 
+#ifndef __HAVE_ARCH_STRNICMP
+/**
+ * strnicmp - Case insensitive, length-limited string comparison
+ * @s1: One string
+ * @s2: The other string
+ * @len: the maximum number of characters to compare
+ */
+int strnicmp(const char *s1, const char *s2, size_t len)
+{
+	/* Yes, Virginia, it had better be unsigned */
+	unsigned char c1, c2;
+
+	if (!len)
+		return 0;
+
+	do {
+		c1 = *s1++;
+		c2 = *s2++;
+		if (!c1 || !c2)
+			break;
+		if (c1 == c2)
+			continue;
+		c1 = tolower(c1);
+		c2 = tolower(c2);
+		if (c1 != c2)
+			break;
+	} while (--len);
+	return (int)c1 - (int)c2;
+}
+EXPORT_SYMBOL(strnicmp);
+#endif
+
+#ifndef __HAVE_ARCH_STRCASECMP
+int strcasecmp(const char *s1, const char *s2)
+{
+	int c1, c2;
+
+	do {
+		c1 = tolower(*s1++);
+		c2 = tolower(*s2++);
+	} while (c1 == c2 && c1 != 0);
+	return c1 - c2;
+}
+EXPORT_SYMBOL(strcasecmp);
+#endif
+
+#ifndef __HAVE_ARCH_STRNCASECMP
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+	int c1, c2;
+
+	do {
+		c1 = tolower(*s1++);
+		c2 = tolower(*s2++);
+	} while ((--n > 0) && c1 == c2 && c1 != 0);
+	return c1 - c2;
+}
+EXPORT_SYMBOL(strncasecmp);
+#endif
+
 #ifndef __HAVE_ARCH_STRCPY
 /**
  * strcpy - Copy a %NUL terminated string
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:47 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:47 +0200
Subject: [PATCH 02/22] OF: base: bail out early on missing matches for
 of_match_node
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-3-git-send-email-sebastian.hesselbarth@gmail.com>

of_match_node checks for compatiblity between a set of matches and a
node. Neither the matches nor node pointer are checked for validity.
This adds the required checks to of_match_node.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4241e65..ab0f4cd 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -321,6 +321,9 @@ EXPORT_SYMBOL(of_device_is_compatible);
 const struct of_device_id *of_match_node(const struct of_device_id *matches,
 					 const struct device_node *node)
 {
+	if (!matches || !node)
+		return NULL;
+
 	while (matches->compatible) {
 		if (of_device_is_compatible(node, matches->compatible) == 1)
 			return matches;
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:45 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:45 +0200
Subject: [PATCH 00/22] Barebox OF API fixes, sync, and cleanup
Message-ID: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>

This is a quite large patch set to make Barebox OF API more behave
like Linux OF API. Also, it prepares Barebox to reuse Linux OF address
handling and drivers/of/of_* helpers soon.

The patch set is roughly divided into 5 sections:

(1) Patch 1 introduces case-insensitive string compare functions that will
    be used later during import of Linux OF API functions.

(2) Patches 2 and 3 fix some bugs in existing OF API functions.

(3) Patches 4-8 synchronize existing OF API functions with Linux OF API
    counterparts.

(4) Patches 9-18 import API functions from Linux OF API or introduce new
    functions based on existing Barebox OF API functions.

(5) Patches 19-22 convert to new API functions and remove now obsolete
    functions. Further, it cleans up existing OF include, by providing
    OFTREE prototypes and !OFTREE bogus stubs.

I have tested the patch set with both CONFIG_OFTREE set and not set.

The patch set applied to barebox/next can also be found at
git://github.com/shesselba/barebox-dove.git  barebox-of-sync-v1

Sebastian Hesselbarth (22):
  lib: string: import case-insensitive string compare
  OF: base: bail out early on missing matches for of_match_node
  OF: base: also update property length on of_property_write_u32
  OF: base: export of_alias_scan
  OF: base: convert strcmp to default string compare functions
  OF: base: sync of_find_property with linux OF API
  OF: base: sync of_find_node_by_path with linux OF API
  OF: base: rename of_node_disabled to of_device_is_available
  OF: base: import of_find_node_by_name from Linux OF API
  OF: base: import of_find_compatible_node from Linux OF API
  OF: base: import of_find_matching_node_and_match from Linux OF API
  OF: base: import of_find_node_with_property from Linux OF API
  OF: base: import parent/child functions from Linux OF API
  OF: base: import of_property_read_* helpers from Linux OF API
  OF: base: import of_parse_phandle from Linux OF API
  OF: base: import parse phandle functions from Linux OF API
  OF: base: introduce property write for bool, u8, u16, and u64
  OF: base: import property iterators from Linux OF API
  OF: base: remove of_tree_for_each_node from public API
  OF: base: remove of_find_child_by_name
  OF: base: convert and remove device_node_for_nach_child
  OF: base: cleanup base function include

 arch/arm/boards/at91sam9x5ek/hw_version.c |   10 +-
 arch/arm/boards/highbank/init.c           |   20 +-
 arch/ppc/mach-mpc5xxx/cpu.c               |    4 +-
 commands/of_node.c                        |    2 +-
 commands/of_property.c                    |   12 +-
 commands/oftree.c                         |   11 +-
 common/oftree.c                           |    2 +-
 drivers/i2c/i2c.c                         |    2 +-
 drivers/mfd/stmpe-i2c.c                   |    7 +-
 drivers/of/base.c                         | 1234 +++++++++++++++++++++++------
 drivers/of/fdt.c                          |   14 +-
 drivers/of/gpio.c                         |    9 +-
 drivers/of/of_net.c                       |    6 +-
 drivers/of/partition.c                    |    2 +-
 drivers/pinctrl/pinctrl.c                 |    4 +-
 drivers/spi/spi.c                         |   12 +-
 drivers/usb/imx/chipidea-imx.c            |   14 +-
 include/linux/string.h                    |    9 +
 include/of.h                              |  616 ++++++++++++--
 lib/string.c                              |   60 ++
 net/eth.c                                 |    2 +-
 21 files changed, 1624 insertions(+), 428 deletions(-)
---
Cc: barebox at lists.infradead.org
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:49 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:49 +0200
Subject: [PATCH 04/22] OF: base: export of_alias_scan
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-5-git-send-email-sebastian.hesselbarth@gmail.com>

To prepare clean-up of OF API, we need to export of_alias_scan.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |    3 ++-
 include/of.h      |   31 ++++++++++++++++++-------------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 616b93d..f3ed836 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -135,7 +135,7 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
  * the global lookup table with the properties.  It returns the
  * number of alias_prop found, or error code in error case.
  */
-static void of_alias_scan(void)
+void of_alias_scan(void)
 {
 	struct property *pp;
 	struct alias_prop *app, *tmp;
@@ -187,6 +187,7 @@ static void of_alias_scan(void)
 		of_alias_add(ap, np, id, start, len);
 	}
 }
+EXPORT_SYMBOL(of_alias_scan);
 
 /**
  * of_alias_get_id - Get alias id for the given device_node
diff --git a/include/of.h b/include/of.h
index 300b706..8a69793 100644
--- a/include/of.h
+++ b/include/of.h
@@ -178,10 +178,11 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
 struct cdev;
 
 #ifdef CONFIG_OFTREE
-int of_parse_partitions(struct cdev *cdev, struct device_node *node);
+extern void of_alias_scan(void);
+extern int of_alias_get_id(struct device_node *np, const char *stem);
+extern const char *of_alias_get(struct device_node *np);
 
-int of_alias_get_id(struct device_node *np, const char *stem);
-const char *of_alias_get(struct device_node *np);
+int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
 void *of_flatten_dtb(struct device_node *node);
@@ -196,16 +197,6 @@ static inline int of_parse_partitions(struct cdev *cdev,
 	return -EINVAL;
 }
 
-static inline int of_alias_get_id(struct device_node *np, const char *stem)
-{
-	return -ENOENT;
-}
-
-static inline const char *of_alias_get(struct device_node *np)
-{
-	return NULL;
-}
-
 static inline int of_device_is_stdout_path(struct device_d *dev)
 {
 	return 0;
@@ -230,6 +221,20 @@ static inline struct device_node *of_get_root_node(void)
 {
 	return NULL;
 }
+
+static inline void of_alias_scan(void)
+{
+}
+
+static inline int of_alias_get_id(struct device_node *np, const char *stem)
+{
+	return -ENOSYS;
+}
+
+static inline const char *of_alias_get(struct device_node *np)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:48 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:48 +0200
Subject: [PATCH 03/22] OF: base: also update property length on
 of_property_write_u32
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-4-git-send-email-sebastian.hesselbarth@gmail.com>

Current implementation of of_property_write_u32 does free old property
values and allocates new values depending on the size passed. While
copying the new values to the property, corresponding length is not
set. This makes of_property_write_u32 set the length of the new property
values and also adds a API header describing the function.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index ab0f4cd..616b93d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -383,6 +383,21 @@ int of_property_read_u32_array(const struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(of_property_read_u32_array);
 
+/**
+ * of_property_write_u32_array - Write an array of u32 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np:		device node to which the property value is to be written.
+ * @propname:	name of the property to be written.
+ * @values:	pointer to array elements to write.
+ * @sz:		number of array elements to write.
+ *
+ * Search for a property in a device node and write 32-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
 int of_property_write_u32_array(struct device_node *np,
 				const char *propname, const u32 *values,
 				size_t sz)
@@ -397,14 +412,15 @@ int of_property_write_u32_array(struct device_node *np,
 
 	free(prop->value);
 
-	prop->value = malloc(sizeof(__be32) * sz);
+	prop->length = sizeof(*val) * sz;
+	prop->value = malloc(prop->length);
 	if (!prop->value)
 		return -ENOMEM;
 
 	val = prop->value;
-
 	while (sz--)
 		*val++ = cpu_to_be32(*values++);
+
 	return 0;
 }
 
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:53 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:53 +0200
Subject: [PATCH 08/22] OF: base: rename of_node_disabled to
 of_device_is_available
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-9-git-send-email-sebastian.hesselbarth@gmail.com>

According to ePAPR 1.1 spec, device tree nodes status can be either
"okay", "disabled", "fail", or "fail-sss". Barebox already has a function
to check for "disabled" nodes, while Linux checks for "okay" or "ok".
To synchronize Barebox and Linux OF APIs, rename of_node_disabled to
of_device_is_available and check for "okay" instead of "disabled" as it
also makes "fail"ed devices unavailable.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   26 ++++++++++++++++++++------
 include/of.h      |    6 ++++++
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 34793b3..827a1db 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -717,17 +717,31 @@ int of_set_root_node(struct device_node *node)
 	return 0;
 }
 
-static int of_node_disabled(struct device_node *node)
+/**
+ *  of_device_is_available - check if a device is available for use
+ *
+ *  @device: Node to check for availability
+ *
+ *  Returns 1 if the status property is absent or set to "okay" or "ok",
+ *  0 otherwise
+ */
+int of_device_is_available(const struct device_node *device)
 {
-	struct property *p;
+	const char *status;
+	int statlen;
+
+	status = of_get_property(device, "status", &statlen);
+	if (status == NULL)
+		return 1;
 
-	p = of_find_property(node, "status", NULL);
-	if (p) {
-		if (!strcmp("disabled", p->value))
+	if (statlen > 0) {
+		if (!strcmp(status, "okay") || !strcmp(status, "ok"))
 			return 1;
 	}
+
 	return 0;
 }
+EXPORT_SYMBOL(of_device_is_available);
 
 void of_print_nodes(struct device_node *node, int indent)
 {
@@ -921,7 +935,7 @@ static struct device_d *add_of_device(struct device_node *node,
 {
 	const struct property *cp;
 
-	if (of_node_disabled(node))
+	if (!of_device_is_available(node))
 		return NULL;
 
 	cp = of_get_property(node, "compatible", NULL);
diff --git a/include/of.h b/include/of.h
index 871f5e9..340fb83 100644
--- a/include/of.h
+++ b/include/of.h
@@ -183,6 +183,7 @@ extern struct property *of_find_property(const struct device_node *np,
 					const char *name, int *lenp);
 
 extern struct device_node *of_find_node_by_path(const char *path);
+extern int of_device_is_available(const struct device_node *device);
 
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -240,6 +241,11 @@ static inline struct device_node *of_find_node_by_path(const char *path)
 	return NULL;
 }
 
+static inline int of_device_is_available(const struct device_node *device)
+{
+	return 0;
+}
+
 static inline void of_alias_scan(void)
 {
 }
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:52 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:52 +0200
Subject: [PATCH 07/22] OF: base: sync of_find_node_by_path with linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-8-git-send-email-sebastian.hesselbarth@gmail.com>

Barebox of_find_node_by_path requires a node to be passed as start node
to start searching. Linux OF API does not pass this node and no current
user of it in barebox is passing anything else than the root node.
Therefore, the device_node argument is removed and all current users of
that function are updated to reflect the API change.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 arch/arm/boards/highbank/init.c |    4 ++--
 arch/ppc/mach-mpc5xxx/cpu.c     |    4 ++--
 commands/of_node.c              |    2 +-
 commands/of_property.c          |   10 ++--------
 commands/oftree.c               |   11 +----------
 common/oftree.c                 |    2 +-
 drivers/of/base.c               |   22 ++++++++++------------
 include/of.h                    |    9 +++++++--
 net/eth.c                       |    2 +-
 9 files changed, 27 insertions(+), 39 deletions(-)

diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index d4a5c5a..1aa713b 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -53,7 +53,7 @@ static int hb_fixup(struct device_node *root)
 	if ((opp_table[0] >> 16) != HB_OPP_VERSION)
 		return 0;
 
-	node = of_find_node_by_path(root, "/cpus/cpu at 0");
+	node = of_find_node_by_path("/cpus/cpu at 0");
 	if (!node)
 		return 0;
 
@@ -89,7 +89,7 @@ static int highbank_mem_init(void)
 
 	of_set_root_node(root);
 
-	np = of_find_node_by_path(root, "/memory");
+	np = of_find_node_by_path("/memory");
 	if (!np) {
 		pr_warn("no memory node use default configuration\n");
 		goto not_found;
diff --git a/arch/ppc/mach-mpc5xxx/cpu.c b/arch/ppc/mach-mpc5xxx/cpu.c
index 99f16eb..0ece4a9 100644
--- a/arch/ppc/mach-mpc5xxx/cpu.c
+++ b/arch/ppc/mach-mpc5xxx/cpu.c
@@ -83,7 +83,7 @@ static int of_mpc5200_fixup(struct device_node *root)
 
 	int div = in_8((void*)CFG_MBAR + 0x204) & 0x0020 ? 8 : 4;
 
-	node = of_find_node_by_path(root, "/cpus/PowerPC,5200 at 0");
+	node = of_find_node_by_path("/cpus/PowerPC,5200 at 0");
 	if (!node)
 		return -EINVAL;
 
@@ -91,7 +91,7 @@ static int of_mpc5200_fixup(struct device_node *root)
 	of_property_write_u32(node, "bus-frequency", get_bus_clock());
 	of_property_write_u32(node, "clock-frequency", get_cpu_clock());
 
-	node = of_find_node_by_path(root, "/soc5200 at f0000000");
+	node = of_find_node_by_path("/soc5200 at f0000000");
 	if (!node)
 		return -EINVAL;
 
diff --git a/commands/of_node.c b/commands/of_node.c
index 0249d97..e60ef66 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -81,7 +81,7 @@ static int do_of_node(int argc, char *argv[])
 		if (!path)
 			return COMMAND_ERROR_USAGE;
 
-		node = of_find_node_by_path(root, path);
+		node = of_find_node_by_path(path);
 		if (!node) {
 			printf("Cannot find nodepath %s\n", path);
 			return -ENOENT;
diff --git a/commands/of_property.c b/commands/of_property.c
index d1a9a17..8ffe30b 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -175,7 +175,7 @@ static int do_of_property(int argc, char *argv[])
 	int set = 0;
 	int ret;
 	char *path = NULL, *propname = NULL;
-	struct device_node *root, *node = NULL;
+	struct device_node *node = NULL;
 	struct property *pp = NULL;
 
 	while ((opt = getopt(argc, argv, "ds")) > 0) {
@@ -194,15 +194,9 @@ static int do_of_property(int argc, char *argv[])
 	if (optind == argc)
 		return COMMAND_ERROR_USAGE;
 
-	root = of_get_root_node();
-	if (!root) {
-		printf("root node not set\n");
-		return -ENOENT;
-	}
-
 	if (optind < argc) {
 		path = argv[optind];
-		node = of_find_node_by_path(root, path);
+		node = of_find_node_by_path(path);
 		if (!node) {
 			printf("Cannot find nodepath %s\n", path);
 			return -ENOENT;
diff --git a/commands/oftree.c b/commands/oftree.c
index 468235a..9149517 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -164,16 +164,7 @@ static int do_oftree(int argc, char *argv[])
 			of_print_nodes(root, 0);
 			of_free(root);
 		} else {
-			struct device_node *root, *n;
-
-			root = of_get_root_node();
-			if (!root) {
-				ret = -ENOENT;
-				goto out;
-			}
-
-			n = of_find_node_by_path(root, node);
-
+			struct device_node *n = of_find_node_by_path(node);
 			if (!n) {
 				ret = -ENOENT;
 				goto out;
diff --git a/common/oftree.c b/common/oftree.c
index 475d418..aff4c28 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -100,7 +100,7 @@ void of_print_property(const void *data, int len)
 
 void of_print_cmdline(struct device_node *root)
 {
-	struct device_node *node = of_find_node_by_path(root, "/chosen");
+	struct device_node *node = of_find_node_by_path("/chosen");
 	const char *cmdline;
 
 	if (!node) {
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 85199b6..34793b3 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -153,7 +153,7 @@ void of_alias_scan(void)
 	if (!root_node)
 		return;
 
-	of_aliases = of_find_node_by_path(root_node, "/aliases");
+	of_aliases = of_find_node_by_path("/aliases");
 	if (!of_aliases)
 		return;
 
@@ -170,7 +170,7 @@ void of_alias_scan(void)
 		    !of_prop_cmp(pp->name, "linux,phandle"))
 			continue;
 
-		np = of_find_node_by_path(root_node, pp->value);
+		np = of_find_node_by_path(pp->value);
 		if (!np)
 			continue;
 
@@ -557,18 +557,16 @@ EXPORT_SYMBOL(of_machine_is_compatible);
 
 /**
  *	of_find_node_by_path - Find a node matching a full OF path
- *	@root:	The root node of this tree
  *	@path:	The full path to match
  *
- *	Returns a node pointer with refcount incremented, use
- *	of_node_put() on it when done.
+ *	Returns a pointer to the node found or NULL.
  */
-struct device_node *of_find_node_by_path(struct device_node *root, const char *path)
+struct device_node *of_find_node_by_path(const char *path)
 {
 	char *slash, *p, *freep;
-	struct device_node *dn = root;
+	struct device_node *dn = root_node;
 
-	if (*path != '/')
+	if (!dn || !path || *path != '/')
 		return NULL;
 
 	path++;
@@ -1156,12 +1154,12 @@ int of_probe(void)
 	if(!root_node)
 		return -ENODEV;
 
-	of_chosen = of_find_node_by_path(root_node, "/chosen");
+	of_chosen = of_find_node_by_path("/chosen");
 	of_property_read_string(root_node, "model", &of_model);
 
 	__of_parse_phandles(root_node);
 
-	memory = of_find_node_by_path(root_node, "/memory");
+	memory = of_find_node_by_path("/memory");
 	if (memory)
 		of_add_memory(memory, false);
 
@@ -1234,8 +1232,8 @@ int of_device_is_stdout_path(struct device_d *dev)
 	name = of_get_property(of_chosen, "linux,stdout-path", NULL);
 	if (name == NULL)
 		return 0;
-	dn = of_find_node_by_path(root_node, name);
 
+	dn = of_find_node_by_path(name);
 	if (!dn)
 		return 0;
 
@@ -1264,7 +1262,7 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 	struct device_node *chosen;
 	__be32 buf[2];
 
-	chosen = of_find_node_by_path(root, "/chosen");
+	chosen = of_find_node_by_path("/chosen");
 	if (!chosen)
 		return -EINVAL;
 
diff --git a/include/of.h b/include/of.h
index 7ebde62..871f5e9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -67,8 +67,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 int of_n_addr_cells(struct device_node *np);
 int of_n_size_cells(struct device_node *np);
 
-struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
-
 struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
 
 struct fdt_header *fdt_get_tree(void);
@@ -184,6 +182,8 @@ struct cdev;
 extern struct property *of_find_property(const struct device_node *np,
 					const char *name, int *lenp);
 
+extern struct device_node *of_find_node_by_path(const char *path);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -235,6 +235,11 @@ static inline struct property *of_find_property(const struct device_node *np,
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_by_path(const char *path)
+{
+	return NULL;
+}
+
 static inline void of_alias_scan(void)
 {
 }
diff --git a/net/eth.c b/net/eth.c
index 7240b4d..09b3bd5 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -296,7 +296,7 @@ static int eth_of_fixup(struct device_node *root)
 			continue;
 		}
 
-		node = of_find_node_by_path(root, edev->nodepath);
+		node = of_find_node_by_path(edev->nodepath);
 		if (!node) {
 			dev_dbg(&edev->dev, "%s: fixup node %s not found\n",
 					__func__, edev->nodepath);
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:54 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:54 +0200
Subject: [PATCH 09/22] OF: base: import of_find_node_by_name from Linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-10-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_find_node_by_name and corresponding for_each_node_by_name
helper from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   26 ++++++++++++++++++++++++++
 include/of.h      |   12 ++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 827a1db..85358d9 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -312,6 +312,32 @@ int of_device_is_compatible(const struct device_node *device,
 EXPORT_SYMBOL(of_device_is_compatible);
 
 /**
+ *	of_find_node_by_name - Find a node by its "name" property
+ *	@from:	The node to start searching from or NULL, the node
+ *		you pass will not be searched, only the next one
+ *		will; typically, you pass what the previous call
+ *		returned.
+ *	@name:	The name string to match against
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_by_name(struct device_node *from,
+	const char *name)
+{
+	struct device_node *np;
+
+	if (!from)
+		from = root_node;
+
+	of_tree_for_each_node(np, from)
+		if (np->name && !of_node_cmp(np->name, name))
+			return np;
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_node_by_name);
+
+/**
  * of_match_node - Tell if an device_node has a matching of_match structure
  *      @matches:       array of of device match structures to search in
  *      @node:          the of device structure to match against
diff --git a/include/of.h b/include/of.h
index 340fb83..d1503de 100644
--- a/include/of.h
+++ b/include/of.h
@@ -182,6 +182,8 @@ struct cdev;
 extern struct property *of_find_property(const struct device_node *np,
 					const char *name, int *lenp);
 
+extern struct device_node *of_find_node_by_name(struct device_node *from,
+	const char *name);
 extern struct device_node *of_find_node_by_path(const char *path);
 extern int of_device_is_available(const struct device_node *device);
 
@@ -241,6 +243,12 @@ static inline struct device_node *of_find_node_by_path(const char *path)
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_by_name(struct device_node *from,
+	const char *name)
+{
+	return NULL;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -261,4 +269,8 @@ static inline const char *of_alias_get(struct device_node *np)
 }
 #endif
 
+#define for_each_node_by_name(dn, name) \
+	for (dn = of_find_node_by_name(NULL, name); dn; \
+	     dn = of_find_node_by_name(dn, name))
+
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:50 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:50 +0200
Subject: [PATCH 05/22] OF: base: convert strcmp to default string compare
 functions
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-6-git-send-email-sebastian.hesselbarth@gmail.com>

Barebox compares compatible, node names, and property names with strcmp.
Linux by default compares compatible and node names with strcasecmp. To
avoid inconsitencies between Barebox and Linux dts files, we convert to
these default string compare functions.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   25 +++++++++++++------------
 include/of.h      |    5 +++++
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index f3ed836..1c9ef58 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -104,14 +104,15 @@ static void of_bus_count_cells(struct device_node *dev,
 
 struct property *of_find_property(const struct device_node *node, const char *name)
 {
-	struct property *p;
+	struct property *pp;
 
 	if (!node)
 		return NULL;
 
-	list_for_each_entry(p, &node->properties, list)
-		if (!strcmp(p->name, name))
-			return p;
+	list_for_each_entry(pp, &node->properties, list)
+		if (of_prop_cmp(pp->name, name) == 0)
+			return pp;
+
 	return NULL;
 }
 EXPORT_SYMBOL(of_find_property);
@@ -160,9 +161,9 @@ void of_alias_scan(void)
 		int id, len;
 
 		/* Skip those we do not want to proceed */
-		if (!strcmp(pp->name, "name") ||
-		    !strcmp(pp->name, "phandle") ||
-		    !strcmp(pp->name, "linux,phandle"))
+		if (!of_prop_cmp(pp->name, "name") ||
+		    !of_prop_cmp(pp->name, "phandle") ||
+		    !of_prop_cmp(pp->name, "linux,phandle"))
 			continue;
 
 		np = of_find_node_by_path(root_node, pp->value);
@@ -203,7 +204,7 @@ int of_alias_get_id(struct device_node *np, const char *stem)
 	int id = -ENODEV;
 
 	list_for_each_entry(app, &aliases_lookup, link) {
-		if (strcmp(app->stem, stem) != 0)
+		if (of_node_cmp(app->stem, stem) != 0)
 			continue;
 
 		if (np == app->np) {
@@ -221,7 +222,7 @@ const char *of_alias_get(struct device_node *np)
 	struct property *pp;
 
 	list_for_each_entry(pp, &of_aliases->properties, list) {
-		if (!strcmp(np->full_name, pp->value))
+		if (!of_node_cmp(np->full_name, pp->value))
 			return pp->name;
 	}
 
@@ -301,7 +302,7 @@ int of_device_is_compatible(const struct device_node *device,
 	if (cp == NULL)
 		return 0;
 	while (cplen > 0) {
-		if (strcmp(cp, compat) == 0)
+		if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
 			return 1;
 		l = strlen(cp) + 1;
 		cp += l;
@@ -958,7 +959,7 @@ int of_add_memory(struct device_node *node, bool dump)
 	if (ret)
 		return -ENXIO;
 
-	if (strcmp(device_type, "memory"))
+	if (of_node_cmp(device_type, "memory"))
 		return -ENXIO;
 
 	of_bus_count_cells(node, &na, &nc);
@@ -1177,7 +1178,7 @@ struct device_node *of_find_child_by_name(struct device_node *node, const char *
 	struct device_node *_n;
 
 	device_node_for_nach_child(node, _n)
-		if (!strcmp(_n->name, name))
+		if (!of_node_cmp(_n->name, name))
 			return _n;
 
 	return NULL;
diff --git a/include/of.h b/include/of.h
index 8a69793..a91a4c9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -5,6 +5,11 @@
 #include <errno.h>
 #include <asm/byteorder.h>
 
+/* Default string compare functions */
+#define of_compat_cmp(s1, s2, l)	strcasecmp((s1), (s2))
+#define of_prop_cmp(s1, s2)		strcmp((s1), (s2))
+#define of_node_cmp(s1, s2)		strcasecmp((s1), (s2))
+
 #define OF_BAD_ADDR      ((u64)-1)
 
 typedef u32 phandle;
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:55 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:55 +0200
Subject: [PATCH 10/22] OF: base: import of_find_compatible_node from Linux OF
 API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-11-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_find_compatible_node and corresponding for_each_compatible_node
helper from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   30 ++++++++++++++++++++++++++++++
 include/of.h      |   13 +++++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 85358d9..50a3c22 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -338,6 +338,36 @@ struct device_node *of_find_node_by_name(struct device_node *from,
 EXPORT_SYMBOL(of_find_node_by_name);
 
 /**
+ *	of_find_compatible_node - Find a node based on type and one of the
+ *                                tokens in its "compatible" property
+ *	@from:		The node to start searching from or NULL, the node
+ *			you pass will not be searched, only the next one
+ *			will; typically, you pass what the previous call
+ *			returned.
+ *	@type:		The type string to match "device_type" or NULL to ignore
+ *                      (currently always ignored in barebox)
+ *	@compatible:	The string to match to one of the tokens in the device
+ *			"compatible" list.
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_compatible_node(struct device_node *from,
+	const char *type, const char *compatible)
+{
+	struct device_node *np;
+
+	if (!from)
+		from = root_node;
+
+	of_tree_for_each_node(np, from)
+		if (of_device_is_compatible(np, compatible))
+			return np;
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_compatible_node);
+
+/**
  * of_match_node - Tell if an device_node has a matching of_match structure
  *      @matches:       array of of device match structures to search in
  *      @node:          the of device structure to match against
diff --git a/include/of.h b/include/of.h
index d1503de..e170e2b 100644
--- a/include/of.h
+++ b/include/of.h
@@ -185,6 +185,8 @@ extern struct property *of_find_property(const struct device_node *np,
 extern struct device_node *of_find_node_by_name(struct device_node *from,
 	const char *name);
 extern struct device_node *of_find_node_by_path(const char *path);
+extern struct device_node *of_find_compatible_node(struct device_node *from,
+	const char *type, const char *compat);
 extern int of_device_is_available(const struct device_node *device);
 
 extern void of_alias_scan(void);
@@ -249,6 +251,14 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
 	return NULL;
 }
 
+static inline struct device_node *of_find_compatible_node(
+						struct device_node *from,
+						const char *type,
+						const char *compat)
+{
+	return NULL;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -272,5 +282,8 @@ static inline const char *of_alias_get(struct device_node *np)
 #define for_each_node_by_name(dn, name) \
 	for (dn = of_find_node_by_name(NULL, name); dn; \
 	     dn = of_find_node_by_name(dn, name))
+#define for_each_compatible_node(dn, type, compatible) \
+	for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
+	     dn = of_find_compatible_node(dn, type, compatible))
 
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:56 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:56 +0200
Subject: [PATCH 11/22] OF: base: import of_find_matching_node_and_match from
 Linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-12-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_find_matching_node_and_match and corresponding helpers
from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   37 +++++++++++++++++++++++++++++++++++++
 include/of.h      |   24 ++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 50a3c22..218cb5a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -389,6 +389,43 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
 	return NULL;
 }
 
+/**
+ *	of_find_matching_node_and_match - Find a node based on an of_device_id
+ *					  match table.
+ *	@from:		The node to start searching from or NULL, the node
+ *			you pass will not be searched, only the next one
+ *			will; typically, you pass what the previous call
+ *			returned.
+ *	@matches:	array of of device match structures to search in
+ *	@match		Updated to point at the matches entry which matched
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_matching_node_and_match(struct device_node *from,
+					const struct of_device_id *matches,
+					const struct of_device_id **match)
+{
+	struct device_node *np;
+
+	if (match)
+		*match = NULL;
+
+	if (!from)
+		from = root_node;
+
+	of_tree_for_each_node(np, from) {
+		const struct of_device_id *m = of_match_node(matches, np);
+		if (m) {
+			if (match)
+				*match = m;
+			return np;
+		}
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_matching_node_and_match);
+
 int of_match(struct device_d *dev, struct driver_d *drv)
 {
 	const struct of_device_id *id;
diff --git a/include/of.h b/include/of.h
index e170e2b..c21e73d 100644
--- a/include/of.h
+++ b/include/of.h
@@ -187,6 +187,10 @@ extern struct device_node *of_find_node_by_name(struct device_node *from,
 extern struct device_node *of_find_node_by_path(const char *path);
 extern struct device_node *of_find_compatible_node(struct device_node *from,
 	const char *type, const char *compat);
+extern struct device_node *of_find_matching_node_and_match(
+	struct device_node *from,
+	const struct of_device_id *matches,
+	const struct of_device_id **match);
 extern int of_device_is_available(const struct device_node *device);
 
 extern void of_alias_scan(void);
@@ -259,6 +263,14 @@ static inline struct device_node *of_find_compatible_node(
 	return NULL;
 }
 
+static inline struct device_node *of_find_matching_node_and_match(
+					struct device_node *from,
+					const struct of_device_id *matches,
+					const struct of_device_id **match)
+{
+	return NULL;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -285,5 +297,17 @@ static inline const char *of_alias_get(struct device_node *np)
 #define for_each_compatible_node(dn, type, compatible) \
 	for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
 	     dn = of_find_compatible_node(dn, type, compatible))
+static inline struct device_node *of_find_matching_node(
+	struct device_node *from,
+	const struct of_device_id *matches)
+{
+	return of_find_matching_node_and_match(from, matches, NULL);
+}
+#define for_each_matching_node(dn, matches) \
+	for (dn = of_find_matching_node(NULL, matches); dn; \
+	     dn = of_find_matching_node(dn, matches))
+#define for_each_matching_node_and_match(dn, matches, match) \
+	for (dn = of_find_matching_node_and_match(NULL, matches, match); \
+	     dn; dn = of_find_matching_node_and_match(dn, matches, match))
 
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:57 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:57 +0200
Subject: [PATCH 12/22] OF: base: import of_find_node_with_property from Linux
 OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-13-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_find_node_with_property and corresponding helpers
from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   26 ++++++++++++++++++++++++++
 include/of.h      |   11 +++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 218cb5a..148f832 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -368,6 +368,32 @@ struct device_node *of_find_compatible_node(struct device_node *from,
 EXPORT_SYMBOL(of_find_compatible_node);
 
 /**
+ *	of_find_node_with_property - Find a node which has a property with
+ *                                   the given name.
+ *	@from:		The node to start searching from or NULL, the node
+ *			you pass will not be searched, only the next one
+ *			will; typically, you pass what the previous call
+ *			returned.
+ *	@prop_name:	The name of the property to look for.
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_with_property(struct device_node *from,
+	const char *prop_name)
+{
+	struct device_node *np;
+
+	of_tree_for_each_node(np, from) {
+		struct property *pp = of_find_property(np, prop_name, NULL);
+		if (pp)
+			return np;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_node_with_property);
+
+/**
  * of_match_node - Tell if an device_node has a matching of_match structure
  *      @matches:       array of of device match structures to search in
  *      @node:          the of device structure to match against
diff --git a/include/of.h b/include/of.h
index c21e73d..208b00b 100644
--- a/include/of.h
+++ b/include/of.h
@@ -191,6 +191,8 @@ extern struct device_node *of_find_matching_node_and_match(
 	struct device_node *from,
 	const struct of_device_id *matches,
 	const struct of_device_id **match);
+extern struct device_node *of_find_node_with_property(
+	struct device_node *from, const char *prop_name);
 extern int of_device_is_available(const struct device_node *device);
 
 extern void of_alias_scan(void);
@@ -271,6 +273,12 @@ static inline struct device_node *of_find_matching_node_and_match(
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_with_property(
+			struct device_node *from, const char *prop_name)
+{
+	return NULL;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -309,5 +317,8 @@ static inline struct device_node *of_find_matching_node(
 #define for_each_matching_node_and_match(dn, matches, match) \
 	for (dn = of_find_matching_node_and_match(NULL, matches, match); \
 	     dn; dn = of_find_matching_node_and_match(dn, matches, match))
+#define for_each_node_with_property(dn, prop_name) \
+	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
+	     dn = of_find_node_with_property(dn, prop_name))
 
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:51 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:51 +0200
Subject: [PATCH 06/22] OF: base: sync of_find_property with linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-7-git-send-email-sebastian.hesselbarth@gmail.com>

To start synchronizing OF API of barebox with linux OF API, this adds
a length pointer to of_find_property. Also all current users of that
function are updated to reflect the API change.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 commands/of_property.c         |    2 +-
 drivers/of/base.c              |   38 ++++++++++++++++++--------------------
 drivers/of/fdt.c               |    5 ++++-
 drivers/of/of_net.c            |    6 +++---
 drivers/pinctrl/pinctrl.c      |    4 ++--
 drivers/spi/spi.c              |   10 +++++-----
 drivers/usb/imx/chipidea-imx.c |    3 ++-
 include/of.h                   |   12 ++++++++++--
 8 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/commands/of_property.c b/commands/of_property.c
index 44bb388..d1a9a17 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -212,7 +212,7 @@ static int do_of_property(int argc, char *argv[])
 	if (optind + 1 < argc) {
 		propname = argv[optind + 1];
 
-		pp = of_find_property(node, propname);
+		pp = of_find_property(node, propname, NULL);
 		if (!set && !pp) {
 			printf("Cannot find property %s\n", propname);
 			return -ENOENT;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1c9ef58..85199b6 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -102,16 +102,20 @@ static void of_bus_count_cells(struct device_node *dev,
 	of_bus_default_count_cells(dev, addrc, sizec);
 }
 
-struct property *of_find_property(const struct device_node *node, const char *name)
+struct property *of_find_property(const struct device_node *np,
+				  const char *name, int *lenp)
 {
 	struct property *pp;
 
-	if (!node)
+	if (!np)
 		return NULL;
 
-	list_for_each_entry(pp, &node->properties, list)
-		if (of_prop_cmp(pp->name, name) == 0)
+	list_for_each_entry(pp, &np->properties, list)
+		if (of_prop_cmp(pp->name, name) == 0) {
+			if (lenp)
+				*lenp = pp->length;
 			return pp;
+		}
 
 	return NULL;
 }
@@ -242,7 +246,7 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr)
 			return addr;
 
 		node = node->parent;
-		p = of_find_property(node, "ranges");
+		p = of_find_property(node, "ranges", NULL);
 		if (!p && node->parent)
 			return OF_BAD_ADDR;
 		of_bus_count_cells(node, &na, &nc);
@@ -277,13 +281,7 @@ EXPORT_SYMBOL(of_find_node_by_phandle);
 const void *of_get_property(const struct device_node *np, const char *name,
 			 int *lenp)
 {
-	struct property *pp = of_find_property(np, name);
-
-	if (!pp)
-		return NULL;
-
-	if (lenp)
-		*lenp = pp->length;
+	struct property *pp = of_find_property(np, name, lenp);
 
 	return pp ? pp->value : NULL;
 }
@@ -368,7 +366,7 @@ int of_property_read_u32_array(const struct device_node *np,
 			       const char *propname, u32 *out_values,
 			       size_t sz)
 {
-	struct property *prop = of_find_property(np, propname);
+	struct property *prop = of_find_property(np, propname, NULL);
 	const __be32 *val;
 
 	if (!prop)
@@ -404,7 +402,7 @@ int of_property_write_u32_array(struct device_node *np,
 				const char *propname, const u32 *values,
 				size_t sz)
 {
-	struct property *prop = of_find_property(np, propname);
+	struct property *prop = of_find_property(np, propname, NULL);
 	__be32 *val;
 
 	if (!prop)
@@ -619,7 +617,7 @@ EXPORT_SYMBOL(of_find_node_by_path);
 int of_property_read_string(struct device_node *np, const char *propname,
 				const char **out_string)
 {
-	struct property *prop = of_find_property(np, propname);
+	struct property *prop = of_find_property(np, propname, NULL);
 	if (!prop)
 		return -EINVAL;
 	if (!prop->value)
@@ -652,7 +650,7 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
 int of_property_read_string_index(struct device_node *np, const char *propname,
 				  int index, const char **output)
 {
-	struct property *prop = of_find_property(np, propname);
+	struct property *prop = of_find_property(np, propname, NULL);
 	int i = 0;
 	size_t l = 0, total = 0;
 	const char *p;
@@ -725,7 +723,7 @@ static int of_node_disabled(struct device_node *node)
 {
 	struct property *p;
 
-	p = of_find_property(node, "status");
+	p = of_find_property(node, "status", NULL);
 	if (p) {
 		if (!strcmp("disabled", p->value))
 			return 1;
@@ -833,7 +831,7 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
 	if (!np)
 		return -ENOENT;
 
-	pp = of_find_property(np, name);
+	pp = of_find_property(np, name, NULL);
 	if (pp) {
 		void *data;
 
@@ -1278,11 +1276,11 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 	} else {
 		struct property *pp;
 
-		pp = of_find_property(chosen, "linux,initrd-start");
+		pp = of_find_property(chosen, "linux,initrd-start", NULL);
 		if (pp)
 			of_delete_property(pp);
 
-		pp = of_find_property(chosen, "linux,initrd-end");
+		pp = of_find_property(chosen, "linux,initrd-end", NULL);
 		if (pp)
 			of_delete_property(pp);
 	}
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a3ec576..a76396e 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -178,7 +178,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
 				goto err;
 			}
 
-			if (merge && (p = of_find_property(node, name))) {
+			p = NULL;
+			if (merge)
+				p = of_find_property(node, name, NULL);
+			if (merge && p) {
 				free(p->value);
 				p->value = xzalloc(len);
 				memcpy(p->value, nodep, len);
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index de93fbc..2bf05e2 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -76,15 +76,15 @@ const void *of_get_mac_address(struct device_node *np)
 {
 	struct property *pp;
 
-	pp = of_find_property(np, "mac-address");
+	pp = of_find_property(np, "mac-address", NULL);
 	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
 		return pp->value;
 
-	pp = of_find_property(np, "local-mac-address");
+	pp = of_find_property(np, "local-mac-address", NULL);
 	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
 		return pp->value;
 
-	pp = of_find_property(np, "address");
+	pp = of_find_property(np, "address", NULL);
 	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
 		return pp->value;
 
diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index fa979a1..7c797d3 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -64,14 +64,14 @@ int pinctrl_select_state(struct device_d *dev, const char *name)
 	if (!np)
 		return 0;
 
-	if (!of_find_property(np, "pinctrl-0"))
+	if (!of_find_property(np, "pinctrl-0", NULL))
 		return 0;
 
 	/* For each defined state ID */
 	for (state = 0; ; state++) {
 		/* Retrieve the pinctrl-* property */
 		propname = asprintf("pinctrl-%d", state);
-		prop = of_find_property(np, propname);
+		prop = of_find_property(np, propname, NULL);
 		free(propname);
 
 		if (!prop) {
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index f460a7a..eebf64c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -112,17 +112,17 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
 		chip.name = xstrdup(n->name);
 		chip.bus_num = master->bus_num;
 		/* Mode (clock phase/polarity/etc.) */
-		if (of_find_property(n, "spi-cpha"))
+		if (of_find_property(n, "spi-cpha", NULL))
 			chip.mode |= SPI_CPHA;
-		if (of_find_property(n, "spi-cpol"))
+		if (of_find_property(n, "spi-cpol", NULL))
 			chip.mode |= SPI_CPOL;
-		if (of_find_property(n, "spi-cs-high"))
+		if (of_find_property(n, "spi-cs-high", NULL))
 			chip.mode |= SPI_CS_HIGH;
-		if (of_find_property(n, "spi-3wire"))
+		if (of_find_property(n, "spi-3wire", NULL))
 			chip.mode |= SPI_3WIRE;
 		of_property_read_u32(n, "spi-max-frequency",
 				&chip.max_speed_hz);
-		reg = of_find_property(n, "reg");
+		reg = of_find_property(n, "reg", NULL);
 		if (!reg)
 			continue;
 		chip.chip_select = of_read_number(reg->value, 1);
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 4ee7610..32b05aa 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -108,7 +108,8 @@ static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
 		return -EINVAL;
 	}
 
-	if (of_find_property(ci->dev->device_node, "disable-over-current"))
+	if (of_find_property(ci->dev->device_node,
+				"disable-over-current"), NULL)
 		ci->flags |= MXC_EHCI_DISABLE_OVERCURRENT;
 
 	return 0;
diff --git a/include/of.h b/include/of.h
index a91a4c9..7ebde62 100644
--- a/include/of.h
+++ b/include/of.h
@@ -67,8 +67,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 int of_n_addr_cells(struct device_node *np);
 int of_n_size_cells(struct device_node *np);
 
-struct property *of_find_property(const struct device_node *node, const char *name);
-
 struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
 
 struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
@@ -183,6 +181,9 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
 struct cdev;
 
 #ifdef CONFIG_OFTREE
+extern struct property *of_find_property(const struct device_node *np,
+					const char *name, int *lenp);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -227,6 +228,13 @@ static inline struct device_node *of_get_root_node(void)
 	return NULL;
 }
 
+static inline struct property *of_find_property(const struct device_node *np,
+						const char *name,
+						int *lenp)
+{
+	return NULL;
+}
+
 static inline void of_alias_scan(void)
 {
 }
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:30:00 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:30:00 +0200
Subject: [PATCH 15/22] OF: base: import of_parse_phandle from Linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-16-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_parse_phandle from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   23 +++++++++++++++++++++++
 include/of.h      |   10 ++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4689f3e..e729a65 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -839,6 +839,29 @@ int of_property_write_u32_array(struct device_node *np,
 }
 
 /**
+ * of_parse_phandle - Resolve a phandle property to a device_node pointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ *         the table
+ *
+ * Returns the device_node pointer found or NULL.
+ */
+struct device_node *of_parse_phandle(const struct device_node *np,
+				     const char *phandle_name, int index)
+{
+	const __be32 *phandle;
+	int size;
+
+	phandle = of_get_property(np, phandle_name, &size);
+	if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
+		return NULL;
+
+	return of_find_node_by_phandle(be32_to_cpup(phandle + index));
+}
+EXPORT_SYMBOL(of_parse_phandle);
+
+/**
  * of_parse_phandles_with_args - Find a node pointed by phandle in a list
  * @np:		pointer to a device tree node containing a list
  * @list_name:	property name that contains a list
diff --git a/include/of.h b/include/of.h
index d782eaf..81df5a6 100644
--- a/include/of.h
+++ b/include/of.h
@@ -214,6 +214,10 @@ extern int of_property_match_string(struct device_node *np,
 extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 
+extern struct device_node *of_parse_phandle(const struct device_node *np,
+					    const char *phandle_name,
+					    int index);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -342,6 +346,12 @@ static inline int of_property_count_strings(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline struct device_node *of_parse_phandle(const struct device_node *np,
+					    const char *phandle_name, int index)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_find_node_by_path(const char *path)
 {
 	return NULL;
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:58 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:58 +0200
Subject: [PATCH 13/22] OF: base: import parent/child functions from Linux OF
 API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-14-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_get_parent, of_get_next_child, of_get_next_available_child,
and of_get_child_by_name and corresponding helpers from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h      |   49 +++++++++++++++++++++++++++++++++
 2 files changed, 127 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 148f832..17364ea 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -862,6 +862,84 @@ int of_device_is_available(const struct device_node *device)
 }
 EXPORT_SYMBOL(of_device_is_available);
 
+/**
+ *	of_get_parent - Get a node's parent if any
+ *	@node:	Node to get parent
+ *
+ *	Returns a pointer to the parent node or NULL if already at root.
+ */
+struct device_node *of_get_parent(const struct device_node *node)
+{
+	if (!node)
+		return NULL;
+
+	return (node == root_node) ? NULL : node->parent;
+}
+EXPORT_SYMBOL(of_get_parent);
+
+/**
+ *	of_get_next_child - Iterate a node childs
+ *	@node:	parent node
+ *	@prev:	previous child of the parent node, or NULL to get first
+ *
+ *	Returns a pointer to the next child or NULL.
+ */
+struct device_node *of_get_next_child(const struct device_node *node,
+	struct device_node *prev)
+{
+	if (!node)
+		return NULL;
+
+	if (!prev)
+		return list_prepare_entry(prev, &node->children, parent_list);
+
+	list_for_each_entry_continue(prev, &node->children, parent_list)
+		return prev;
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_get_next_child);
+
+/**
+ *	of_get_next_available_child - Find the next available child node
+ *	@node:	parent node
+ *	@prev:	previous child of the parent node, or NULL to get first
+ *
+ *      This function is like of_get_next_child(), except that it
+ *      automatically skips any disabled nodes (i.e. status = "disabled").
+ */
+struct device_node *of_get_next_available_child(const struct device_node *node,
+	struct device_node *prev)
+{
+	for_each_child_of_node(node, prev)
+		if (of_device_is_available(prev))
+			return prev;
+	return NULL;
+}
+EXPORT_SYMBOL(of_get_next_available_child);
+
+/**
+ *	of_get_child_by_name - Find the child node by name for a given parent
+ *	@node:	parent node
+ *	@name:	child name to look for.
+ *
+ *      This function looks for child node for given matching name
+ *
+ *	Returns a node pointer if found or NULL.
+ */
+struct device_node *of_get_child_by_name(const struct device_node *node,
+				const char *name)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(node, child)
+		if (child->name && (of_node_cmp(child->name, name) == 0))
+			return child;
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_get_child_by_name);
+
 void of_print_nodes(struct device_node *node, int indent)
 {
 	struct device_node *n;
diff --git a/include/of.h b/include/of.h
index 208b00b..c69b9ad 100644
--- a/include/of.h
+++ b/include/of.h
@@ -195,6 +195,14 @@ extern struct device_node *of_find_node_with_property(
 	struct device_node *from, const char *prop_name);
 extern int of_device_is_available(const struct device_node *device);
 
+extern struct device_node *of_get_parent(const struct device_node *node);
+extern struct device_node *of_get_next_child(const struct device_node *node,
+					     struct device_node *prev);
+extern struct device_node *of_get_next_available_child(
+	const struct device_node *node, struct device_node *prev);
+extern struct device_node *of_get_child_by_name(const struct device_node *node,
+					const char *name);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -239,6 +247,29 @@ static inline struct device_node *of_get_root_node(void)
 	return NULL;
 }
 
+static inline struct device_node *of_get_parent(const struct device_node *node)
+{
+	return NULL;
+}
+
+static inline struct device_node *of_get_next_child(
+		const struct device_node *node, struct device_node *prev)
+{
+	return NULL;
+}
+
+static inline struct device_node *of_get_next_available_child(
+		const struct device_node *node, struct device_node *prev)
+{
+	return NULL;
+}
+
+static inline struct device_node *of_get_child_by_name(
+			const struct device_node *node, const char *name)
+{
+	return NULL;
+}
+
 static inline struct property *of_find_property(const struct device_node *np,
 						const char *name,
 						int *lenp)
@@ -321,4 +352,22 @@ static inline struct device_node *of_find_matching_node(
 	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
 	     dn = of_find_node_with_property(dn, prop_name))
 
+#define for_each_child_of_node(parent, child) \
+	for (child = of_get_next_child(parent, NULL); child != NULL; \
+	     child = of_get_next_child(parent, child))
+#define for_each_available_child_of_node(parent, child) \
+	for (child = of_get_next_available_child(parent, NULL); child != NULL; \
+	     child = of_get_next_available_child(parent, child))
+
+static inline int of_get_child_count(const struct device_node *np)
+{
+	struct device_node *child;
+	int num = 0;
+
+	for_each_child_of_node(np, child)
+		num++;
+
+	return num;
+}
+
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:30:03 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:30:03 +0200
Subject: [PATCH 18/22] OF: base: import property iterators from Linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-19-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_prop_next_u32, of_prop_next_string, and the corresponding
for_property_for_each_ helpers from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   41 +++++++++++++++++++++++++++++++++++++++++
 include/of.h      |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4c6f2f4..489fa89 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -797,6 +797,47 @@ int of_property_count_strings(struct device_node *np, const char *propname)
 }
 EXPORT_SYMBOL_GPL(of_property_count_strings);
 
+const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
+			u32 *pu)
+{
+	const void *curv = cur;
+
+	if (!prop)
+		return NULL;
+
+	if (!cur) {
+		curv = prop->value;
+		goto out_val;
+	}
+
+	curv += sizeof(*cur);
+	if (curv >= prop->value + prop->length)
+		return NULL;
+
+out_val:
+	*pu = be32_to_cpup(curv);
+	return curv;
+}
+EXPORT_SYMBOL_GPL(of_prop_next_u32);
+
+const char *of_prop_next_string(struct property *prop, const char *cur)
+{
+	const void *curv = cur;
+
+	if (!prop)
+		return NULL;
+
+	if (!cur)
+		return prop->value;
+
+	curv += strlen(cur) + 1;
+	if (curv >= prop->value + prop->length)
+		return NULL;
+
+	return curv;
+}
+EXPORT_SYMBOL_GPL(of_prop_next_string);
+
 /**
  * of_property_write_bool - Create/Delete empty (bool) property.
  *
diff --git a/include/of.h b/include/of.h
index 53a135a..0306742 100644
--- a/include/of.h
+++ b/include/of.h
@@ -205,6 +205,10 @@ extern int of_property_match_string(struct device_node *np,
 extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 
+extern const __be32 *of_prop_next_u32(struct property *prop,
+				const __be32 *cur, u32 *pu);
+extern const char *of_prop_next_string(struct property *prop, const char *cur);
+
 extern int of_property_write_bool(struct device_node *np,
 				const char *propname, const bool value);
 extern int of_property_write_u8_array(struct device_node *np,
@@ -357,6 +361,18 @@ static inline int of_property_count_strings(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline const __be32 *of_prop_next_u32(struct property *prop,
+					const __be32 *cur, u32 *pu)
+{
+	return 0;
+}
+
+static inline const char *of_prop_next_string(struct property *prop,
+					const char *cur)
+{
+	return NULL;
+}
+
 static inline int of_property_write_bool(struct device_node *np,
 				const char *propname, const bool value)
 {
@@ -536,6 +552,33 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+/*
+ * struct property *prop;
+ * const __be32 *p;
+ * u32 u;
+ *
+ * of_property_for_each_u32(np, "propname", prop, p, u)
+ *         printk("U32 value: %x\n", u);
+ */
+#define of_property_for_each_u32(np, propname, prop, p, u)	\
+	for (prop = of_find_property(np, propname, NULL),	\
+		p = of_prop_next_u32(prop, NULL, &u);		\
+		p;						\
+		p = of_prop_next_u32(prop, p, &u))
+
+/*
+ * struct property *prop;
+ * const char *s;
+ *
+ * of_property_for_each_string(np, "propname", prop, s)
+ *         printk("String value: %s\n", s);
+ */
+#define of_property_for_each_string(np, propname, prop, s)	\
+	for (prop = of_find_property(np, propname, NULL),	\
+		s = of_prop_next_string(prop, NULL);		\
+		s;						\
+		s = of_prop_next_string(prop, s))
+
 static inline int of_property_write_u8(struct device_node *np,
 				       const char *propname, u8 value)
 {
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:30:04 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:30:04 +0200
Subject: [PATCH 19/22] OF: base: remove of_tree_for_each_node from public API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-20-git-send-email-sebastian.hesselbarth@gmail.com>

This patch converts users of of_tree_for_each_node to recently added
for_eacg_compatible_node helper. Also of_tree_for_each_node is removed
from public OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 arch/arm/boards/at91sam9x5ek/hw_version.c |   10 +++-------
 arch/arm/boards/highbank/init.c           |   16 ++++++----------
 drivers/of/base.c                         |    8 ++++++++
 include/of.h                              |    8 --------
 4 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 91af331..426bd35 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -234,13 +234,9 @@ static int cm_cogent_fixup(struct device_node *root)
 	int ret;
 	struct device_node *node;
 
-	of_tree_for_each_node(node, root) {
-		struct device_node *slotnode;
-
-		if (!of_device_is_compatible(node, "atmel,hsmci"))
-			continue;
-
-		slotnode = of_find_child_by_name(node, "slot");
+	for_each_compatible_node(node, NULL, "atmel,hsmci") {
+		struct device_node *slotnode =
+			of_find_child_by_name(node, "slot");
 		if (!slotnode)
 			continue;
 
diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index 1aa713b..46ecc88 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -35,19 +35,15 @@ static int hb_fixup(struct device_node *root)
 	__be32 latency;
 
 	if (!(reg & HB_PWRDOM_STAT_SATA)) {
-		of_tree_for_each_node(node, root) {
-			if (of_device_is_compatible(node, "calxeda,hb-ahci"))
-				of_set_property(node, "status", "disabled",
-						sizeof("disabled"), 1);
-		}
+		for_each_compatible_node(node, NULL, "calxeda,hb-ahci")
+			of_set_property(node, "status", "disabled",
+					sizeof("disabled"), 1);
 	}
 
 	if (!(reg & HB_PWRDOM_STAT_EMMC)) {
-		of_tree_for_each_node(node, root) {
-			if (of_device_is_compatible(node, "calxeda,hb-sdhci"))
-				of_set_property(node, "status", "disabled",
-						sizeof("disabled"), 1);
-		}
+		for_each_compatible_node(node, NULL, "calxeda,hb-sdhci")
+			of_set_property(node, "status", "disabled",
+					sizeof("disabled"), 1);
 	}
 
 	if ((opp_table[0] >> 16) != HB_OPP_VERSION)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 489fa89..94a5c61 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -28,6 +28,14 @@
 #include <linux/amba/bus.h>
 #include <linux/err.h>
 
+/*
+ * Iterate over all nodes of a tree. As a devicetree does not
+ * have a dedicated list head, the start node (usually the root
+ * node) will not be iterated over.
+ */
+#define of_tree_for_each_node(node, root) \
+	list_for_each_entry(node, &root->list, list)
+
 /**
  * struct alias_prop - Alias property in 'aliases' node
  * @link:	List node to link the structure in aliases_lookup list
diff --git a/include/of.h b/include/of.h
index 0306742..0797dbe 100644
--- a/include/of.h
+++ b/include/of.h
@@ -85,14 +85,6 @@ int of_modalias_node(struct device_node *node, char *modalias, int len);
 #define device_node_for_nach_child(node, child) \
 	list_for_each_entry(child, &node->children, parent_list)
 
-/*
- * Iterate over all nodes of a tree. As a devicetree does not
- * have a dedicated list head, the start node (usually the root
- * node) will not be iterated over.
- */
-#define of_tree_for_each_node(node, root) \
-	list_for_each_entry(node, &root->list, list)
-
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:29:59 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:29:59 +0200
Subject: [PATCH 14/22] OF: base: import of_property_read_* helpers from Linux
 OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-15-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_property_read_* helpers from Linux OF API to allow
to read all kinds of properties.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |  387 +++++++++++++++++++++++++++++++++++++++++------------
 include/of.h      |  132 ++++++++++++++++--
 2 files changed, 420 insertions(+), 99 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 17364ea..4689f3e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -467,12 +467,137 @@ int of_match(struct device_d *dev, struct driver_d *drv)
 EXPORT_SYMBOL(of_match);
 
 /**
+ * of_find_property_value_of_size
+ *
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @len:	requested length of property value
+ *
+ * Search for a property in a device node and valid the requested size.
+ * Returns the property value on success, -EINVAL if the property does not
+ *  exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ */
+static void *of_find_property_value_of_size(const struct device_node *np,
+			const char *propname, u32 len)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+
+	if (!prop)
+		return ERR_PTR(-EINVAL);
+	if (!prop->value)
+		return ERR_PTR(-ENODATA);
+	if (len > prop->length)
+		return ERR_PTR(-EOVERFLOW);
+
+	return prop->value;
+}
+
+/**
+ * of_property_read_u32_index - Find and read a u32 from a multi-value property.
+ *
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @index:	index of the u32 in the list of values
+ * @out_value:	pointer to return value, modified only if no error.
+ *
+ * Search for a property in a device node and read nth 32-bit value from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * The out_value is modified only if a valid u32 value can be decoded.
+ */
+int of_property_read_u32_index(const struct device_node *np,
+				       const char *propname,
+				       u32 index, u32 *out_value)
+{
+	const u32 *val = of_find_property_value_of_size(np, propname,
+					((index + 1) * sizeof(*out_value)));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	*out_value = be32_to_cpup(((__be32 *)val) + index);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u32_index);
+
+/**
+ * of_property_read_u8_array - Find and read an array of u8 from a property.
+ *
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @out_value:	pointer to return value, modified only if return value is 0.
+ * @sz:		number of array elements to read
+ *
+ * Search for a property in a device node and read 8-bit value(s) from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * dts entry of array should be like:
+ *	property = /bits/ 8 <0x50 0x60 0x70>;
+ *
+ * The out_value is modified only if a valid u8 value can be decoded.
+ */
+int of_property_read_u8_array(const struct device_node *np,
+			const char *propname, u8 *out_values, size_t sz)
+{
+	const u8 *val = of_find_property_value_of_size(np, propname,
+						(sz * sizeof(*out_values)));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	while (sz--)
+		*out_values++ = *val++;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u8_array);
+
+/**
+ * of_property_read_u16_array - Find and read an array of u16 from a property.
+ *
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @out_value:	pointer to return value, modified only if return value is 0.
+ * @sz:		number of array elements to read
+ *
+ * Search for a property in a device node and read 16-bit value(s) from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * dts entry of array should be like:
+ *	property = /bits/ 16 <0x5000 0x6000 0x7000>;
+ *
+ * The out_value is modified only if a valid u16 value can be decoded.
+ */
+int of_property_read_u16_array(const struct device_node *np,
+			const char *propname, u16 *out_values, size_t sz)
+{
+	const __be16 *val = of_find_property_value_of_size(np, propname,
+						(sz * sizeof(*out_values)));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	while (sz--)
+		*out_values++ = be16_to_cpup(val++);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u16_array);
+
+/**
  * of_property_read_u32_array - Find and read an array of 32 bit integers
  * from a property.
  *
  * @np:		device node from which the property value is to be read.
  * @propname:	name of the property to be searched.
  * @out_value:	pointer to return value, modified only if return value is 0.
+ * @sz:		number of array elements to read
  *
  * Search for a property in a device node and read 32-bit value(s) from
  * it. Returns 0 on success, -EINVAL if the property does not exist,
@@ -485,22 +610,192 @@ int of_property_read_u32_array(const struct device_node *np,
 			       const char *propname, u32 *out_values,
 			       size_t sz)
 {
+	const __be32 *val = of_find_property_value_of_size(np, propname,
+						(sz * sizeof(*out_values)));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	while (sz--)
+		*out_values++ = be32_to_cpup(val++);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+
+/**
+ * of_property_read_u64 - Find and read a 64 bit integer from a property
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @out_value:	pointer to return value, modified only if return value is 0.
+ *
+ * Search for a property in a device node and read a 64-bit value from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * The out_value is modified only if a valid u64 value can be decoded.
+ */
+int of_property_read_u64(const struct device_node *np, const char *propname,
+			 u64 *out_value)
+{
+	const __be32 *val = of_find_property_value_of_size(np, propname,
+						sizeof(*out_value));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	*out_value = of_read_number(val, 2);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u64);
+
+/**
+ * of_property_read_string - Find and read a string from a property
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @out_string:	pointer to null terminated return string, modified only if
+ *		return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy). Returns 0 on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string(struct device_node *np, const char *propname,
+				const char **out_string)
+{
 	struct property *prop = of_find_property(np, propname, NULL);
-	const __be32 *val;
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+	if (strnlen(prop->value, prop->length) >= prop->length)
+		return -EILSEQ;
+	*out_string = prop->value;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_string);
+
+/**
+ * of_property_read_string_index - Find and read a string from a multiple
+ * strings property.
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @index:	index of the string in the list of strings
+ * @out_string:	pointer to null terminated return string, modified only if
+ *		return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy) in the list of strings
+ * contained in that property.
+ * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
+ * property does not have a value, and -EILSEQ if the string is not
+ * null-terminated within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string_index(struct device_node *np, const char *propname,
+				  int index, const char **output)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	int i = 0;
+	size_t l = 0, total = 0;
+	const char *p;
 
 	if (!prop)
 		return -EINVAL;
 	if (!prop->value)
 		return -ENODATA;
-	if ((sz * sizeof(*out_values)) > prop->length)
-		return -EOVERFLOW;
+	if (strnlen(prop->value, prop->length) >= prop->length)
+		return -EILSEQ;
 
-	val = prop->value;
-	while (sz--)
-		*out_values++ = be32_to_cpup(val++);
-	return 0;
+	p = prop->value;
+
+	for (i = 0; total < prop->length; total += l, p += l) {
+		l = strlen(p) + 1;
+		if (i++ == index) {
+			*output = p;
+			return 0;
+		}
+	}
+	return -ENODATA;
 }
-EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+EXPORT_SYMBOL_GPL(of_property_read_string_index);
+
+/**
+ * of_property_match_string() - Find string in a list and return index
+ * @np: pointer to node containing string list property
+ * @propname: string list property name
+ * @string: pointer to string to search for in string list
+ *
+ * This function searches a string list property and returns the index
+ * of a specific string value.
+ */
+int of_property_match_string(struct device_node *np, const char *propname,
+			     const char *string)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	size_t l;
+	int i;
+	const char *p, *end;
+
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+
+	p = prop->value;
+	end = p + prop->length;
+
+	for (i = 0; p < end; i++, p += l) {
+		l = strlen(p) + 1;
+		if (p + l > end)
+			return -EILSEQ;
+		pr_debug("comparing %s with %s\n", string, p);
+		if (strcmp(string, p) == 0)
+			return i; /* Found it; return index */
+	}
+	return -ENODATA;
+}
+EXPORT_SYMBOL_GPL(of_property_match_string);
+
+/**
+ * of_property_count_strings - Find and return the number of strings from a
+ * multiple strings property.
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ *
+ * Search for a property in a device tree node and retrieve the number of null
+ * terminated string contain in it. Returns the number of strings on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ */
+int of_property_count_strings(struct device_node *np, const char *propname)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	int i = 0;
+	size_t l = 0, total = 0;
+	const char *p;
+
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+	if (strnlen(prop->value, prop->length) >= prop->length)
+		return -EILSEQ;
+
+	p = prop->value;
+
+	for (i = 0; total < prop->length; total += l, p += l, i++)
+		l = strlen(p) + 1;
+
+	return i;
+}
+EXPORT_SYMBOL_GPL(of_property_count_strings);
 
 /**
  * of_property_write_u32_array - Write an array of u32 to a property. If
@@ -717,82 +1012,6 @@ out:
 EXPORT_SYMBOL(of_find_node_by_path);
 
 /**
- * of_property_read_string - Find and read a string from a property
- * @np:		device node from which the property value is to be read.
- * @propname:	name of the property to be searched.
- * @out_string:	pointer to null terminated return string, modified only if
- *		return value is 0.
- *
- * Search for a property in a device tree node and retrieve a null
- * terminated string value (pointer to data, not a copy). Returns 0 on
- * success, -EINVAL if the property does not exist, -ENODATA if property
- * does not have a value, and -EILSEQ if the string is not null-terminated
- * within the length of the property data.
- *
- * The out_string pointer is modified only if a valid string can be decoded.
- */
-int of_property_read_string(struct device_node *np, const char *propname,
-				const char **out_string)
-{
-	struct property *prop = of_find_property(np, propname, NULL);
-	if (!prop)
-		return -EINVAL;
-	if (!prop->value)
-		return -ENODATA;
-	if (strnlen(prop->value, prop->length) >= prop->length)
-		return -EILSEQ;
-	*out_string = prop->value;
-	return 0;
-}
-EXPORT_SYMBOL_GPL(of_property_read_string);
-
-/**
- * of_property_read_string_index - Find and read a string from a multiple
- * strings property.
- * @np:		device node from which the property value is to be read.
- * @propname:	name of the property to be searched.
- * @index:	index of the string in the list of strings
- * @out_string:	pointer to null terminated return string, modified only if
- *		return value is 0.
- *
- * Search for a property in a device tree node and retrieve a null
- * terminated string value (pointer to data, not a copy) in the list of strings
- * contained in that property.
- * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
- * property does not have a value, and -EILSEQ if the string is not
- * null-terminated within the length of the property data.
- *
- * The out_string pointer is modified only if a valid string can be decoded.
- */
-int of_property_read_string_index(struct device_node *np, const char *propname,
-				  int index, const char **output)
-{
-	struct property *prop = of_find_property(np, propname, NULL);
-	int i = 0;
-	size_t l = 0, total = 0;
-	const char *p;
-
-	if (!prop)
-		return -EINVAL;
-	if (!prop->value)
-		return -ENODATA;
-	if (strnlen(prop->value, prop->length) >= prop->length)
-		return -EILSEQ;
-
-	p = prop->value;
-
-	for (i = 0; total < prop->length; total += l, p += l) {
-		l = strlen(p) + 1;
-		if (i++ == index) {
-			*output = p;
-			return 0;
-		}
-	}
-	return -ENODATA;
-}
-EXPORT_SYMBOL_GPL(of_property_read_string_index);
-
-/**
  * of_modalias_node - Lookup appropriate modalias for a device node
  * @node:	pointer to a device tree node
  * @modalias:	Pointer to buffer that modalias value will be copied into
diff --git a/include/of.h b/include/of.h
index c69b9ad..d782eaf 100644
--- a/include/of.h
+++ b/include/of.h
@@ -106,17 +106,6 @@ static inline void of_write_number(void *__cell, u64 val, int size)
 	}
 }
 
-int of_property_read_u32_array(const struct device_node *np,
-			       const char *propname, u32 *out_values,
-			       size_t sz);
-
-static inline int of_property_read_u32(const struct device_node *np,
-				       const char *propname,
-				       u32 *out_value)
-{
-	return of_property_read_u32_array(np, propname, out_value, 1);
-}
-
 int of_property_write_u32_array(struct device_node *np,
 				const char *propname, const u32 *values,
 				size_t sz);
@@ -163,10 +152,6 @@ struct property *of_new_property(struct device_node *node, const char *name,
 		const void *data, int len);
 void of_delete_property(struct property *pp);
 
-int of_property_read_string(struct device_node *np, const char *propname,
-				const char **out_string);
-int of_property_read_string_index(struct device_node *np, const char *propname,
-				  int index, const char **output);
 int of_set_property(struct device_node *node, const char *p, const void *val, int len,
 		int create);
 struct device_node *of_create_node(struct device_node *root, const char *path);
@@ -203,6 +188,32 @@ extern struct device_node *of_get_next_available_child(
 extern struct device_node *of_get_child_by_name(const struct device_node *node,
 					const char *name);
 
+extern int of_property_read_u32_index(const struct device_node *np,
+				       const char *propname,
+				       u32 index, u32 *out_value);
+extern int of_property_read_u8_array(const struct device_node *np,
+			const char *propname, u8 *out_values, size_t sz);
+extern int of_property_read_u16_array(const struct device_node *np,
+			const char *propname, u16 *out_values, size_t sz);
+extern int of_property_read_u32_array(const struct device_node *np,
+				      const char *propname,
+				      u32 *out_values,
+				      size_t sz);
+extern int of_property_read_u64(const struct device_node *np,
+				const char *propname, u64 *out_value);
+
+extern int of_property_read_string(struct device_node *np,
+				   const char *propname,
+				   const char **out_string);
+extern int of_property_read_string_index(struct device_node *np,
+					 const char *propname,
+					 int index, const char **output);
+extern int of_property_match_string(struct device_node *np,
+				    const char *propname,
+				    const char *string);
+extern int of_property_count_strings(struct device_node *np,
+				     const char *propname);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -277,6 +288,60 @@ static inline struct property *of_find_property(const struct device_node *np,
 	return NULL;
 }
 
+static inline int of_property_read_u32_index(const struct device_node *np,
+				const char *propname, u32 index, u32 *out_value)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_u8_array(const struct device_node *np,
+				const char *propname, u8 *out_values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_u16_array(const struct device_node *np,
+			const char *propname, u16 *out_values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_u32_array(const struct device_node *np,
+			const char *propname, u32 *out_values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_u64(const struct device_node *np,
+				const char *propname, u64 *out_value)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_string(struct device_node *np,
+				const char *propname, const char **out_string)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_string_index(struct device_node *np,
+			 const char *propname, int index, const char **output)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_match_string(struct device_node *np,
+				const char *propname, const char *string)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_count_strings(struct device_node *np,
+					const char *propname)
+{
+	return -ENOSYS;
+}
+
 static inline struct device_node *of_find_node_by_path(const char *path)
 {
 	return NULL;
@@ -370,4 +435,41 @@ static inline int of_get_child_count(const struct device_node *np)
 	return num;
 }
 
+/**
+ * of_property_read_bool - Findfrom a property
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ *
+ * Search for a property in a device node.
+ * Returns true if the property exist false otherwise.
+ */
+static inline bool of_property_read_bool(const struct device_node *np,
+					 const char *propname)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+
+	return prop ? true : false;
+}
+
+static inline int of_property_read_u8(const struct device_node *np,
+				       const char *propname,
+				       u8 *out_value)
+{
+	return of_property_read_u8_array(np, propname, out_value, 1);
+}
+
+static inline int of_property_read_u16(const struct device_node *np,
+				       const char *propname,
+				       u16 *out_value)
+{
+	return of_property_read_u16_array(np, propname, out_value, 1);
+}
+
+static inline int of_property_read_u32(const struct device_node *np,
+				       const char *propname,
+				       u32 *out_value)
+{
+	return of_property_read_u32_array(np, propname, out_value, 1);
+}
+
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:30:06 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:30:06 +0200
Subject: [PATCH 21/22] OF: base: convert and remove device_node_for_nach_child
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-22-git-send-email-sebastian.hesselbarth@gmail.com>

Remove device_node_for_nach_child and convert users to corresponding
imported OF API functions.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/i2c/i2c.c       |    2 +-
 drivers/mfd/stmpe-i2c.c |    7 ++-----
 drivers/of/partition.c  |    2 +-
 drivers/spi/spi.c       |    2 +-
 include/of.h            |    3 ---
 5 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index b63d946..3e09547 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -278,7 +278,7 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 	if (!IS_ENABLED(CONFIG_OFDEVICE) || !adap->dev.device_node)
 		return;
 
-	device_node_for_nach_child(adap->dev.device_node, n) {
+	for_each_child_of_node(adap->dev.device_node, n) {
 		struct i2c_board_info info = {};
 		struct i2c_client *result;
 		const __be32 *addr;
diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
index d785430..c505bc1 100644
--- a/drivers/mfd/stmpe-i2c.c
+++ b/drivers/mfd/stmpe-i2c.c
@@ -116,11 +116,8 @@ static struct stmpe_platform_data *stmpe_of_probe(struct device_d *dev)
 
 	pdata = xzalloc(sizeof(*pdata));
 
-	device_node_for_nach_child(dev->device_node, node) {
-		if (!strcmp(node->name, "stmpe_gpio")) {
-			pdata->blocks |= STMPE_BLOCK_GPIO;
-		}
-	}
+	if (of_get_child_by_name(dev->device_node, "stmpe_gpio"))
+		pdata->blocks |= STMPE_BLOCK_GPIO;
 
 	return pdata;
 }
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 2d70cf5..e4b7d1e 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -29,7 +29,7 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node)
 	const char *partname;
 	char *filename;
 
-	device_node_for_nach_child(node, n) {
+	for_each_child_of_node(node, n) {
 		const __be32 *reg;
 		unsigned long offset, size;
 		const char *name;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index eebf64c..5d4dfd6 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -107,7 +107,7 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
 	struct spi_board_info chip;
 	struct property *reg;
 
-	device_node_for_nach_child(node, n) {
+	for_each_child_of_node(node, n) {
 		memset(&chip, 0, sizeof(chip));
 		chip.name = xstrdup(n->name);
 		chip.bus_num = master->bus_num;
diff --git a/include/of.h b/include/of.h
index b4e18b9..4cf4313 100644
--- a/include/of.h
+++ b/include/of.h
@@ -80,9 +80,6 @@ struct fdt_header *of_get_fixed_tree(struct device_node *node);
 
 int of_modalias_node(struct device_node *node, char *modalias, int len);
 
-#define device_node_for_nach_child(node, child) \
-	list_for_each_entry(child, &node->children, parent_list)
-
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:30:05 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:30:05 +0200
Subject: [PATCH 20/22] OF: base: remove of_find_child_by_name
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-21-git-send-email-sebastian.hesselbarth@gmail.com>

With of_get_child_by_name from Linux API, we can now convert and remove
of_find_child_by_name.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 arch/arm/boards/at91sam9x5ek/hw_version.c |    2 +-
 drivers/of/base.c                         |   15 ++-------------
 drivers/of/fdt.c                          |    9 +++++----
 include/of.h                              |    2 --
 4 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 426bd35..1207a3e 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -236,7 +236,7 @@ static int cm_cogent_fixup(struct device_node *root)
 
 	for_each_compatible_node(node, NULL, "atmel,hsmci") {
 		struct device_node *slotnode =
-			of_find_child_by_name(node, "slot");
+			of_get_child_by_name(node, "slot");
 		if (!slotnode)
 			continue;
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 94a5c61..a59a1b1 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1269,7 +1269,7 @@ struct device_node *of_find_node_by_path(const char *path)
 		if (slash)
 			*slash = 0;
 
-		dn = of_find_child_by_name(dn, p);
+		dn = of_get_child_by_name(dn, p);
 		if (!dn)
 			goto out;
 
@@ -1873,17 +1873,6 @@ int of_probe(void)
 	return 0;
 }
 
-struct device_node *of_find_child_by_name(struct device_node *node, const char *name)
-{
-	struct device_node *_n;
-
-	device_node_for_nach_child(node, _n)
-		if (!of_node_cmp(_n->name, name))
-			return _n;
-
-	return NULL;
-}
-
 /**
  * of_create_node - create a new node including its parents
  * @path - the nodepath to create
@@ -1908,7 +1897,7 @@ struct device_node *of_create_node(struct device_node *root, const char *path)
 		if (slash)
 			*slash = 0;
 
-		tmp = of_find_child_by_name(dn, p);
+		tmp = of_get_child_by_name(dn, p);
 		if (tmp)
 			dn = tmp;
 		else
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a76396e..afaa4e0 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -61,7 +61,7 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
 	int  len;		/* length of the property */
 	const struct fdt_property *fdt_prop;
 	const char *pathp, *name;
-	struct device_node *node = NULL, *n;
+	struct device_node *node = NULL;
 	struct property *p;
 	uint32_t dt_struct;
 	struct fdt_node_header *fnh;
@@ -135,9 +135,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
 			if (!node) {
 				node = root;
 			} else {
-				if (merge && (n = of_find_child_by_name(node, pathp)))
-					node = n;
-				else
+				if (merge)
+					node = of_get_child_by_name(node,
+								    pathp);
+				if (!merge || !node)
 					node = of_new_node(node, pathp);
 			}
 
diff --git a/include/of.h b/include/of.h
index 0797dbe..b4e18b9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -74,8 +74,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 int of_n_addr_cells(struct device_node *np);
 int of_n_size_cells(struct device_node *np);
 
-struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
-
 struct fdt_header *fdt_get_tree(void);
 
 struct fdt_header *of_get_fixed_tree(struct device_node *node);
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:30:07 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:30:07 +0200
Subject: [PATCH 22/22] OF: base: cleanup base function include
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-23-git-send-email-sebastian.hesselbarth@gmail.com>

This cleans up include/of.h by moving some function prototypes below
CONFIG_OFTREE and provide bogus stubs for !CONFIG_OFTREE.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 include/of.h |  138 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 109 insertions(+), 29 deletions(-)

diff --git a/include/of.h b/include/of.h
index 4cf4313..798f17a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -71,15 +71,10 @@ int of_match(struct device_d *dev, struct driver_d *drv);
 int of_add_initrd(struct device_node *root, resource_size_t start,
 		resource_size_t end);
 
-int of_n_addr_cells(struct device_node *np);
-int of_n_size_cells(struct device_node *np);
-
 struct fdt_header *fdt_get_tree(void);
 
 struct fdt_header *of_get_fixed_tree(struct device_node *node);
 
-int of_modalias_node(struct device_node *node, char *modalias, int len);
-
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
@@ -100,21 +95,12 @@ static inline void of_write_number(void *__cell, u64 val, int size)
 	}
 }
 
-const void *of_get_property(const struct device_node *np, const char *name,
-			 int *lenp);
-
 int of_get_named_gpio(struct device_node *np,
                                    const char *propname, int index);
 
-struct device_node *of_find_node_by_phandle(phandle phandle);
 void of_print_property(const void *data, int len);
 void of_print_cmdline(struct device_node *root);
 
-int of_device_is_compatible(const struct device_node *device,
-		const char *compat);
-
-int of_machine_is_compatible(const char *compat);
-
 u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
 
 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
@@ -123,39 +109,49 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
 void of_print_nodes(struct device_node *node, int indent);
 int of_probe(void);
 int of_parse_dtb(struct fdt_header *fdt);
-void of_free(struct device_node *node);
 struct device_node *of_unflatten_dtb(struct device_node *root, void *fdt);
-struct device_node *of_new_node(struct device_node *parent, const char *name);
-struct property *of_new_property(struct device_node *node, const char *name,
-		const void *data, int len);
-void of_delete_property(struct property *pp);
-
-int of_set_property(struct device_node *node, const char *p, const void *val, int len,
-		int create);
-struct device_node *of_create_node(struct device_node *root, const char *path);
-
-int of_set_root_node(struct device_node *);
-
-const struct of_device_id *of_match_node(const struct of_device_id *matches,
-					 const struct device_node *node);
 
 struct cdev;
 
 #ifdef CONFIG_OFTREE
+extern int of_n_addr_cells(struct device_node *np);
+extern int of_n_size_cells(struct device_node *np);
+
 extern struct property *of_find_property(const struct device_node *np,
 					const char *name, int *lenp);
+extern const void *of_get_property(const struct device_node *np,
+				const char *name, int *lenp);
+
+extern int of_set_property(struct device_node *node, const char *p,
+			const void *val, int len, int create);
+extern struct property *of_new_property(struct device_node *node,
+				const char *name, const void *data, int len);
+extern void of_delete_property(struct property *pp);
 
 extern struct device_node *of_find_node_by_name(struct device_node *from,
 	const char *name);
 extern struct device_node *of_find_node_by_path(const char *path);
+extern struct device_node *of_find_node_by_phandle(phandle phandle);
 extern struct device_node *of_find_compatible_node(struct device_node *from,
 	const char *type, const char *compat);
+extern const struct of_device_id *of_match_node(
+	const struct of_device_id *matches, const struct device_node *node);
 extern struct device_node *of_find_matching_node_and_match(
 	struct device_node *from,
 	const struct of_device_id *matches,
 	const struct of_device_id **match);
 extern struct device_node *of_find_node_with_property(
 	struct device_node *from, const char *prop_name);
+
+extern struct device_node *of_new_node(struct device_node *parent,
+				const char *name);
+extern struct device_node *of_create_node(struct device_node *root,
+					const char *path);
+extern void of_free(struct device_node *node);
+
+extern int of_machine_is_compatible(const char *compat);
+extern int of_device_is_compatible(const struct device_node *device,
+		const char *compat);
 extern int of_device_is_available(const struct device_node *device);
 
 extern struct device_node *of_get_parent(const struct device_node *node);
@@ -223,6 +219,10 @@ extern int of_count_phandle_with_args(const struct device_node *np,
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
+extern int of_modalias_node(struct device_node *node, char *modalias, int len);
+
+extern struct device_node *of_get_root_node(void);
+extern int of_set_root_node(struct device_node *node);
 
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
@@ -231,7 +231,6 @@ void *of_flatten_dtb(struct device_node *node);
 int of_add_memory(struct device_node *node, bool dump);
 void of_add_memory_bank(struct device_node *node, bool dump, int r,
 		u64 base, u64 size);
-struct device_node *of_get_root_node(void);
 #else
 static inline int of_parse_partitions(struct cdev *cdev,
 					  struct device_node *node)
@@ -264,6 +263,21 @@ static inline struct device_node *of_get_root_node(void)
 	return NULL;
 }
 
+static inline int of_set_root_node(struct device_node *node)
+{
+	return -ENOSYS;
+}
+
+static inline int of_n_addr_cells(struct device_node *np)
+{
+	return 0;
+}
+
+static inline int of_n_size_cells(struct device_node *np)
+{
+	return 0;
+}
+
 static inline struct device_node *of_get_parent(const struct device_node *node)
 {
 	return NULL;
@@ -294,6 +308,28 @@ static inline struct property *of_find_property(const struct device_node *np,
 	return NULL;
 }
 
+static inline const void *of_get_property(const struct device_node *np,
+				const char *name, int *lenp)
+{
+	return NULL;
+}
+
+static inline int of_set_property(struct device_node *node, const char *p,
+			const void *val, int len, int create)
+{
+	return -ENOSYS;
+}
+
+static inline struct property *of_new_property(struct device_node *node,
+				const char *name, const void *data, int len)
+{
+	return NULL;
+}
+
+static inline void of_delete_property(struct property *pp)
+{
+}
+
 static inline int of_property_read_u32_index(const struct device_node *np,
 				const char *propname, u32 index, u32 *out_value)
 {
@@ -420,6 +456,11 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_by_phandle(phandle phandle)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_find_compatible_node(
 						struct device_node *from,
 						const char *type,
@@ -428,6 +469,12 @@ static inline struct device_node *of_find_compatible_node(
 	return NULL;
 }
 
+static inline const struct of_device_id *of_match_node(
+	const struct of_device_id *matches, const struct device_node *node)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_find_matching_node_and_match(
 					struct device_node *from,
 					const struct of_device_id *matches,
@@ -442,6 +489,33 @@ static inline struct device_node *of_find_node_with_property(
 	return NULL;
 }
 
+static inline struct device_node *of_new_node(struct device_node *parent,
+				const char *name)
+{
+	return NULL;
+}
+
+static inline struct device_node *of_create_node(struct device_node *root,
+					const char *path)
+{
+	return NULL;
+}
+
+static inline void of_free(struct device_node *node)
+{
+}
+
+static inline int of_machine_is_compatible(const char *compat)
+{
+	return 0;
+}
+
+static inline int of_device_is_compatible(const struct device_node *device,
+		const char *compat)
+{
+	return 0;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -460,6 +534,12 @@ static inline const char *of_alias_get(struct device_node *np)
 {
 	return NULL;
 }
+
+static inline int of_modalias_node(struct device_node *node, char *modalias,
+				int len)
+{
+	return -ENOSYS;
+}
 #endif
 
 #define for_each_node_by_name(dn, name) \
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:30:01 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:30:01 +0200
Subject: [PATCH 16/22] OF: base: import parse phandle functions from Linux OF
 API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-17-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_parse_phandle_with_args and of_count_phandle_with_args
from Linux OF API. The slightly different of_parse_phandles_with_args
is removed and all users are converted to reflect the API change.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c              |  188 +++++++++++++++++++++++++---------------
 drivers/of/gpio.c              |    9 +-
 drivers/usb/imx/chipidea-imx.c |   11 +--
 include/of.h                   |   30 ++++++-
 4 files changed, 151 insertions(+), 87 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index e729a65..a3a9aac 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -862,17 +862,16 @@ struct device_node *of_parse_phandle(const struct device_node *np,
 EXPORT_SYMBOL(of_parse_phandle);
 
 /**
- * of_parse_phandles_with_args - Find a node pointed by phandle in a list
+ * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
  * @np:		pointer to a device tree node containing a list
  * @list_name:	property name that contains a list
  * @cells_name:	property name that specifies phandles' arguments count
  * @index:	index of a phandle to parse out
- * @out_node:	optional pointer to device_node struct pointer (will be filled)
- * @out_args:	optional pointer to arguments pointer (will be filled)
+ * @out_args:	optional pointer to output arguments structure (will be filled)
  *
  * This function is useful to parse lists of phandles and their arguments.
- * Returns 0 on success and fills out_node and out_args, on error returns
- * appropriate errno value.
+ * Returns 0 on success and fills out_args, on error returns appropriate
+ * errno value.
  *
  * Example:
  *
@@ -889,92 +888,139 @@ EXPORT_SYMBOL(of_parse_phandle);
  * }
  *
  * To get a device_node of the `node2' node you may call this:
- * of_parse_phandles_with_args(node3, "list", "#list-cells", 2, &node2, &args);
+ * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
  */
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
-				const char *cells_name, int index,
-				struct device_node **out_node,
-				const void **out_args)
-{
-	int ret = -EINVAL;
-	const __be32 *list;
-	const __be32 *list_end;
-	int size;
-	int cur_index = 0;
+static int __of_parse_phandle_with_args(const struct device_node *np,
+					const char *list_name,
+					const char *cells_name, int index,
+					struct of_phandle_args *out_args)
+{
+	const __be32 *list, *list_end;
+	int rc = 0, size, cur_index = 0;
+	uint32_t count = 0;
 	struct device_node *node = NULL;
-	const void *args = NULL;
+	phandle phandle;
 
+	/* Retrieve the phandle list property */
 	list = of_get_property(np, list_name, &size);
-	if (!list) {
-		ret = -ENOENT;
-		goto err0;
-	}
+	if (!list)
+		return -ENOENT;
 	list_end = list + size / sizeof(*list);
 
+	/* Loop over the phandles until all the requested entry is found */
 	while (list < list_end) {
-		const __be32 *cells;
-		phandle phandle;
+		rc = -EINVAL;
+		count = 0;
 
+		/*
+		 * If phandle is 0, then it is an empty entry with no
+		 * arguments.  Skip forward to the next entry.
+		 */
 		phandle = be32_to_cpup(list++);
-		args = list;
-
-		/* one cell hole in the list = <>; */
-		if (!phandle)
-			goto next;
-
-		node = of_find_node_by_phandle(phandle);
-		if (!node) {
-			pr_debug("%s: could not find phandle %d\n",
-				 np->full_name, phandle);
-			goto err0;
+		if (phandle) {
+			/*
+			 * Find the provider node and parse the #*-cells
+			 * property to determine the argument length
+			 */
+			node = of_find_node_by_phandle(phandle);
+			if (!node) {
+				pr_err("%s: could not find phandle\n",
+					 np->full_name);
+				goto err;
+			}
+			if (of_property_read_u32(node, cells_name, &count)) {
+				pr_err("%s: could not get %s for %s\n",
+					 np->full_name, cells_name,
+					 node->full_name);
+				goto err;
+			}
+
+			/*
+			 * Make sure that the arguments actually fit in the
+			 * remaining property data length
+			 */
+			if (list + count > list_end) {
+				pr_err("%s: arguments longer than property\n",
+					 np->full_name);
+				goto err;
+			}
 		}
 
-		cells = of_get_property(node, cells_name, &size);
-		if (!cells || size != sizeof(*cells)) {
-			pr_debug("%s: could not get %s for %s\n",
-				 np->full_name, cells_name, node->full_name);
-			goto err1;
-		}
-
-		list += be32_to_cpup(cells);
-		if (list > list_end) {
-			pr_debug("%s: insufficient arguments length\n",
-				 np->full_name);
-			goto err1;
+		/*
+		 * All of the error cases above bail out of the loop, so at
+		 * this point, the parsing is successful. If the requested
+		 * index matches, then fill the out_args structure and return,
+		 * or return -ENOENT for an empty entry.
+		 */
+		rc = -ENOENT;
+		if (cur_index == index) {
+			if (!phandle)
+				goto err;
+
+			if (out_args) {
+				int i;
+				if (WARN_ON(count > MAX_PHANDLE_ARGS))
+					count = MAX_PHANDLE_ARGS;
+				out_args->np = node;
+				out_args->args_count = count;
+				for (i = 0; i < count; i++)
+					out_args->args[i] =
+						be32_to_cpup(list++);
+			}
+
+			/* Found it! return success */
+			return 0;
 		}
-next:
-		if (cur_index == index)
-			break;
 
 		node = NULL;
-		args = NULL;
+		list += count;
 		cur_index++;
 	}
 
-	if (!node) {
-		/*
-		 * args w/o node indicates that the loop above has stopped at
-		 * the 'hole' cell. Report this differently.
-		 */
-		if (args)
-			ret = -EEXIST;
-		else
-			ret = -ENOENT;
-		goto err0;
-	}
+	/*
+	 * Unlock node before returning result; will be one of:
+	 * -ENOENT : index is for empty phandle
+	 * -EINVAL : parsing error on data
+	 * [1..n]  : Number of phandle (count mode; when index = -1)
+	 */
+	rc = index < 0 ? cur_index : -ENOENT;
+ err:
+	return rc;
+}
 
-	if (out_node)
-		*out_node = node;
-	if (out_args)
-		*out_args = args;
+int of_parse_phandle_with_args(const struct device_node *np,
+		const char *list_name, const char *cells_name, int index,
+		struct of_phandle_args *out_args)
+{
+	if (index < 0)
+		return -EINVAL;
+	return __of_parse_phandle_with_args(np, list_name, cells_name,
+					index, out_args);
+}
+EXPORT_SYMBOL(of_parse_phandle_with_args);
 
-	return 0;
-err1:
-err0:
-	pr_debug("%s failed with status %d\n", __func__, ret);
-	return ret;
+/**
+ * of_count_phandle_with_args() - Find the number of phandles references in a property
+ * @np:		pointer to a device tree node containing a list
+ * @list_name:	property name that contains a list
+ * @cells_name:	property name that specifies phandles' arguments count
+ *
+ * Returns the number of phandle + argument tuples within a property. It
+ * is a typical pattern to encode a list of phandle and variable
+ * arguments into a single property. The number of arguments is encoded
+ * by a property in the phandle-target node. For example, a gpios
+ * property would contain a list of GPIO specifies consisting of a
+ * phandle and 1 or more arguments. The number of arguments are
+ * determined by the #gpio-cells property in the node pointed to by the
+ * phandle.
+ */
+int of_count_phandle_with_args(const struct device_node *np,
+			const char *list_name, const char *cells_name)
+{
+	return __of_parse_phandle_with_args(np, list_name, cells_name,
+					-1, NULL);
 }
-EXPORT_SYMBOL(of_parse_phandles_with_args);
+EXPORT_SYMBOL(of_count_phandle_with_args);
 
 /**
  * of_machine_is_compatible - Test root of device tree for a given compatible value
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 83b72c0..87b9c0c 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -9,17 +9,16 @@ int of_get_named_gpio(struct device_node *np,
                                    const char *propname, int index)
 {
 	int ret;
-	struct device_node *gpio_np;
-	const void *gpio_spec;
+	struct of_phandle_args out_args;
 
-	ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index,
-					  &gpio_np, &gpio_spec);
+	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
+					index, &out_args);
 	if (ret) {
 		pr_debug("%s: can't parse gpios property: %d\n", __func__, ret);
 		return -EINVAL;
 	}
 
-	ret = gpio_get_num(gpio_np->device, be32_to_cpup(gpio_spec));
+	ret = gpio_get_num(out_args.np->device, outargs.args[0]);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 32b05aa..ee7c010 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -62,16 +62,15 @@ static int imx_chipidea_port_post_init(void *drvdata)
 
 static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
 {
-	const void *out_args;
-	struct device_node *usbmisc_np;
+	struct of_phandle_args out_args;
 	enum usb_dr_mode mode;
 	enum usb_phy_interface phymode;
 
-	of_parse_phandles_with_args(ci->dev->device_node, "fsl,usbmisc",
-			"#index-cells", 0, &usbmisc_np, &out_args);
-
-	ci->portno = be32_to_cpup(out_args);
+	if (of_parse_phandle_with_args(ci->dev->device_node, "fsl,usbmisc",
+					"#index-cells", 0, &out_args))
+		return -ENODEV;
 
+	ci->portno = out_args.args[0];
 	ci->flags = MXC_EHCI_MODE_UTMI_8BIT;
 
 	mode = of_usb_get_dr_mode(ci->dev->device_node, NULL);
diff --git a/include/of.h b/include/of.h
index 81df5a6..51ecf4d 100644
--- a/include/of.h
+++ b/include/of.h
@@ -42,6 +42,13 @@ struct of_device_id {
 	unsigned long data;
 };
 
+#define MAX_PHANDLE_ARGS 8
+struct of_phandle_args {
+	struct device_node *np;
+	int args_count;
+	uint32_t args[MAX_PHANDLE_ARGS];
+};
+
 #define OF_MAX_RESERVE_MAP	16
 struct of_reserve_map {
 	uint64_t start[OF_MAX_RESERVE_MAP];
@@ -120,11 +127,6 @@ static inline int of_property_write_u32(struct device_node *np,
 const void *of_get_property(const struct device_node *np, const char *name,
 			 int *lenp);
 
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
-				const char *cells_name, int index,
-				struct device_node **out_node,
-				const void **out_args);
-
 int of_get_named_gpio(struct device_node *np,
                                    const char *propname, int index);
 
@@ -217,6 +219,11 @@ extern int of_property_count_strings(struct device_node *np,
 extern struct device_node *of_parse_phandle(const struct device_node *np,
 					    const char *phandle_name,
 					    int index);
+extern int of_parse_phandle_with_args(const struct device_node *np,
+	const char *list_name, const char *cells_name, int index,
+	struct of_phandle_args *out_args);
+extern int of_count_phandle_with_args(const struct device_node *np,
+	const char *list_name, const char *cells_name);
 
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -352,6 +359,19 @@ static inline struct device_node *of_parse_phandle(const struct device_node *np,
 	return NULL;
 }
 
+static inline int of_parse_phandle_with_args(const struct device_node *np,
+		const char *list_name, const char *cells_name, int index,
+		struct of_phandle_args *out_args)
+{
+	return -ENOSYS;
+}
+
+static inline int of_count_phandle_with_args(const struct device_node *np,
+				const char *list_name, const char *cells_name)
+{
+	return -ENOSYS;
+}
+
 static inline struct device_node *of_find_node_by_path(const char *path)
 {
 	return NULL;
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 18 13:30:02 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 19:30:02 +0200
Subject: [PATCH 17/22] OF: base: introduce property write for bool, u8, u16,
 and u64
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371576607-8090-18-git-send-email-sebastian.hesselbarth@gmail.com>

This adds functions to set an array of or a single value for bool,
u8, u16, and u64 properties.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |  156 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h      |   82 ++++++++++++++++++++++++----
 2 files changed, 227 insertions(+), 11 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index a3a9aac..4c6f2f4 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -798,6 +798,119 @@ int of_property_count_strings(struct device_node *np, const char *propname)
 EXPORT_SYMBOL_GPL(of_property_count_strings);
 
 /**
+ * of_property_write_bool - Create/Delete empty (bool) property.
+ *
+ * @np:		device node from which the property is to be set.
+ * @propname:	name of the property to be set.
+ *
+ * Search for a property in a device node and create or delete the property.
+ * If the property already exists and write value is false, the property is
+ * deleted. If write value is true and the property does not exist, it is
+ * created. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_bool(struct device_node *np, const char *propname,
+			   const bool value)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+
+	if (!value) {
+		if (prop)
+			of_delete_property(prop);
+		return 0;
+	}
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	return 0;
+}
+
+/**
+ * of_property_write_u8_array - Write an array of u8 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np:		device node to which the property value is to be written.
+ * @propname:	name of the property to be written.
+ * @values:	pointer to array elements to write.
+ * @sz:		number of array elements to write.
+ *
+ * Search for a property in a device node and write 8-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u8_array(struct device_node *np,
+			       const char *propname, const u8 *values,
+			       size_t sz)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	u8 *val;
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	free(prop->value);
+
+	prop->length = sizeof(*val) * sz;
+	prop->value = malloc(prop->length);
+	if (!prop->value)
+		return -ENOMEM;
+
+	val = prop->value;
+	while (sz--)
+		*val++ = *values++;
+
+	return 0;
+}
+
+/**
+ * of_property_write_u16_array - Write an array of u16 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np:		device node to which the property value is to be written.
+ * @propname:	name of the property to be written.
+ * @values:	pointer to array elements to write.
+ * @sz:		number of array elements to write.
+ *
+ * Search for a property in a device node and write 16-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u16_array(struct device_node *np,
+				const char *propname, const u16 *values,
+				size_t sz)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	__be16 *val;
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	free(prop->value);
+
+	prop->length = sizeof(*val) * sz;
+	prop->value = malloc(prop->length);
+	if (!prop->value)
+		return -ENOMEM;
+
+	val = prop->value;
+	while (sz--)
+		*val++ = cpu_to_be16(*values++);
+
+	return 0;
+}
+
+/**
  * of_property_write_u32_array - Write an array of u32 to a property. If
  * the property does not exist, it will be created and appended to the given
  * device node.
@@ -839,6 +952,49 @@ int of_property_write_u32_array(struct device_node *np,
 }
 
 /**
+ * of_property_write_u64_array - Write an array of u64 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np:		device node to which the property value is to be written.
+ * @propname:	name of the property to be written.
+ * @values:	pointer to array elements to write.
+ * @sz:		number of array elements to write.
+ *
+ * Search for a property in a device node and write 64-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u64_array(struct device_node *np,
+				const char *propname, const u64 *values,
+				size_t sz)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	__be32 *val;
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	free(prop->value);
+
+	prop->length = 2 * sizeof(*val) * sz;
+	prop->value = malloc(prop->length);
+	if (!prop->value)
+		return -ENOMEM;
+
+	val = prop->value;
+	while (sz--) {
+		of_write_number(val, *values++, 2);
+		val += 2;
+	}
+
+	return 0;
+}
+
+/**
  * of_parse_phandle - Resolve a phandle property to a device_node pointer
  * @np: Pointer to device node holding phandle property
  * @phandle_name: Name of property holding a phandle value
diff --git a/include/of.h b/include/of.h
index 51ecf4d..53a135a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -113,17 +113,6 @@ static inline void of_write_number(void *__cell, u64 val, int size)
 	}
 }
 
-int of_property_write_u32_array(struct device_node *np,
-				const char *propname, const u32 *values,
-				size_t sz);
-
-static inline int of_property_write_u32(struct device_node *np,
-					const char *propname,
-					u32 value)
-{
-	return of_property_write_u32_array(np, propname, &value, 1);
-}
-
 const void *of_get_property(const struct device_node *np, const char *name,
 			 int *lenp);
 
@@ -216,6 +205,21 @@ extern int of_property_match_string(struct device_node *np,
 extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 
+extern int of_property_write_bool(struct device_node *np,
+				const char *propname, const bool value);
+extern int of_property_write_u8_array(struct device_node *np,
+				const char *propname, const u8 *values,
+				size_t sz);
+extern int of_property_write_u16_array(struct device_node *np,
+				const char *propname, const u16 *values,
+				size_t sz);
+extern int of_property_write_u32_array(struct device_node *np,
+				const char *propname, const u32 *values,
+				size_t sz);
+extern int of_property_write_u64_array(struct device_node *np,
+				const char *propname, const u64 *values,
+				size_t sz);
+
 extern struct device_node *of_parse_phandle(const struct device_node *np,
 					    const char *phandle_name,
 					    int index);
@@ -353,6 +357,36 @@ static inline int of_property_count_strings(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline int of_property_write_bool(struct device_node *np,
+				const char *propname, const bool value)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_write_u8_array(struct device_node *np,
+			const char *propname, const u8 *values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_write_u16_array(struct device_node *np,
+			const char *propname, const u16 *values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_write_u32_array(struct device_node *np,
+			const char *propname, const u32 *values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_write_u64_array(struct device_node *np,
+			const char *propname, const u64 *values, size_t sz)
+{
+	return -ENOSYS;
+}
+
 static inline struct device_node *of_parse_phandle(const struct device_node *np,
 					    const char *phandle_name, int index)
 {
@@ -502,4 +536,30 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+static inline int of_property_write_u8(struct device_node *np,
+				       const char *propname, u8 value)
+{
+	return of_property_write_u8_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u16(struct device_node *np,
+					const char *propname, u16 value)
+{
+	return of_property_write_u16_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u32(struct device_node *np,
+					const char *propname,
+					u32 value)
+{
+	return of_property_write_u32_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u64(struct device_node *np,
+					const char *propname,
+					u64 value)
+{
+	return of_property_write_u64_array(np, propname, &value, 1);
+}
+
 #endif /* __OF_H */
-- 
1.7.2.5



From s.hauer at pengutronix.de  Tue Jun 18 15:25:04 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Jun 2013 21:25:04 +0200
Subject: Barebox fails to boot 1/40 boots...
In-Reply-To: <E78BBE677EB9144B8F0A0A29674CD5338ED01639D6@SRV-VS06.TELEVIC.COM>
References: <E78BBE677EB9144B8F0A0A29674CD5338ED01639D6@SRV-VS06.TELEVIC.COM>
Message-ID: <20130618192504.GX32299@pengutronix.de>

On Tue, Jun 18, 2013 at 02:59:57PM +0200, Vanhauwaert Wouter wrote:
> Hello all,
> 
> I have this issue with our custom design (IMX53, NAND, DDR3)
> 
> Everything goes well most of the time, but now and then  the system does not boot and halts during initialization... 
> To be more specific, the function on which the system blocks is 'setup_c()' in arch/arm/cpu/start-pbl.c
> 
> What can I do more to debug this? This function is completely in assembler...

What makes you sure barebox stops there? Do you have DEBUG_LL enabled or
do you use a JTAG debugger?

Does this happen in first stage boot only or also when you chainload
barebox from an already running barebox?

You could try calling imx53_init_lowlevel_early from
barebox_arm_reset_vector(). This *could* make a difference.

Since you are using v2013.05-stable you should have the following
patches, but maybe it's worth rechecking.

76820df ARM: invalidate data caches during early init
f9d7582 ARM v7: added v7_mmu_cache_invalidate()
ee5f859 ARM v7: v7_mmu_cache_flush(): do not restore r0-r3 (minor optimization)
eb7d85c arm: properly init alignment trap bit
7904d90 ARM v7: fix mmu-off operation
9af1150 ARM: fix the memset fix

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Jun 18 16:13:03 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Jun 2013 22:13:03 +0200
Subject: [PATCH 07/22] OF: base: sync of_find_node_by_path with linux OF
 API
In-Reply-To: <1371576607-8090-8-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371576607-8090-8-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130618201303.GA32299@pengutronix.de>

On Tue, Jun 18, 2013 at 07:29:52PM +0200, Sebastian Hesselbarth wrote:
> Barebox of_find_node_by_path requires a node to be passed as start node
> to start searching. Linux OF API does not pass this node and no current
> user of it in barebox is passing anything else than the root node.
> Therefore, the device_node argument is removed and all current users of
> that function are updated to reflect the API change.

This is a patch I'm not quite happy with. devicetree is such a nice data
structure that it can be useful for other purposes than just a
singular tree for describing the hardware layout.

Maybe we should rename the current implementatiion to
of_find_node_by_path_from() and add a of_find_node_by_path() which calls
this with root_node as first argument?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Jun 18 16:18:00 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Jun 2013 22:18:00 +0200
Subject: [PATCH 13/22] OF: base: import parent/child functions from Linux
 OF API
In-Reply-To: <1371576607-8090-14-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371576607-8090-14-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130618201800.GB32299@pengutronix.de>

On Tue, Jun 18, 2013 at 07:29:58PM +0200, Sebastian Hesselbarth wrote:
> This imports of_get_parent, of_get_next_child, of_get_next_available_child,
> and of_get_child_by_name and corresponding helpers from Linux OF API.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: barebox at lists.infradead.org
> ---
>  drivers/of/base.c |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/of.h      |   49 +++++++++++++++++++++++++++++++++
>  2 files changed, 127 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 148f832..17364ea 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -862,6 +862,84 @@ int of_device_is_available(const struct device_node *device)
>  }
>  EXPORT_SYMBOL(of_device_is_available);
>  
> +/**
> + *	of_get_parent - Get a node's parent if any
> + *	@node:	Node to get parent
> + *
> + *	Returns a pointer to the parent node or NULL if already at root.
> + */
> +struct device_node *of_get_parent(const struct device_node *node)
> +{
> +	if (!node)
> +		return NULL;
> +
> +	return (node == root_node) ? NULL : node->parent;

parent should be NULL for the root_node, so it should be safe to remove
this additional check. This is also in the sense of making multiple
devicetrees possible.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Tue Jun 18 16:19:39 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 22:19:39 +0200
Subject: [PATCH 07/22] OF: base: sync of_find_node_by_path with linux
 OF API
In-Reply-To: <20130618201303.GA32299@pengutronix.de>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371576607-8090-8-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130618201303.GA32299@pengutronix.de>
Message-ID: <51C0C0DB.1040508@gmail.com>

On 06/18/2013 10:13 PM, Sascha Hauer wrote:
> On Tue, Jun 18, 2013 at 07:29:52PM +0200, Sebastian Hesselbarth wrote:
>> Barebox of_find_node_by_path requires a node to be passed as start node
>> to start searching. Linux OF API does not pass this node and no current
>> user of it in barebox is passing anything else than the root node.
>> Therefore, the device_node argument is removed and all current users of
>> that function are updated to reflect the API change.
>
> This is a patch I'm not quite happy with. devicetree is such a nice data
> structure that it can be useful for other purposes than just a
> singular tree for describing the hardware layout.
>
> Maybe we should rename the current implementatiion to
> of_find_node_by_path_from() and add a of_find_node_by_path() which calls
> this with root_node as first argument?

Agree, I droped a similar patch removing root node passing from
of_print_cmdline() because I realized that root_node is only for the
installed device tree.

Will have in mind for a v2.

Sebastian



From s.hauer at pengutronix.de  Tue Jun 18 16:29:31 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 18 Jun 2013 22:29:31 +0200
Subject: [PATCH 13/22] OF: base: import parent/child functions from Linux
 OF API
In-Reply-To: <1371576607-8090-14-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371576607-8090-14-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130618202931.GC32299@pengutronix.de>

On Tue, Jun 18, 2013 at 07:29:58PM +0200, Sebastian Hesselbarth wrote:
> This imports of_get_parent, of_get_next_child, of_get_next_available_child,
> and of_get_child_by_name and corresponding helpers from Linux OF API.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: barebox at lists.infradead.org
> ---
>  drivers/of/base.c |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  include/of.h      |   49 +++++++++++++++++++++++++++++++++
>  2 files changed, 127 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 148f832..17364ea 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -862,6 +862,84 @@ int of_device_is_available(const struct device_node *device)
>  }
>  EXPORT_SYMBOL(of_device_is_available);
>  
> +/**
> + *	of_get_parent - Get a node's parent if any
> + *	@node:	Node to get parent
> + *
> + *	Returns a pointer to the parent node or NULL if already at root.
> + */
> +struct device_node *of_get_parent(const struct device_node *node)
> +{
> +	if (!node)
> +		return NULL;
> +
> +	return (node == root_node) ? NULL : node->parent;
> +}
> +EXPORT_SYMBOL(of_get_parent);
> +
> +/**
> + *	of_get_next_child - Iterate a node childs
> + *	@node:	parent node
> + *	@prev:	previous child of the parent node, or NULL to get first
> + *
> + *	Returns a pointer to the next child or NULL.
> + */
> +struct device_node *of_get_next_child(const struct device_node *node,
> +	struct device_node *prev)
> +{
> +	if (!node)
> +		return NULL;
> +
> +	if (!prev)
> +		return list_prepare_entry(prev, &node->children, parent_list);
> +
> +	list_for_each_entry_continue(prev, &node->children, parent_list)
> +		return prev;
> +
> +	return NULL;
> +}
> +EXPORT_SYMBOL(of_get_next_child);
> +
> +/**
> + *	of_get_next_available_child - Find the next available child node
> + *	@node:	parent node
> + *	@prev:	previous child of the parent node, or NULL to get first
> + *
> + *      This function is like of_get_next_child(), except that it
> + *      automatically skips any disabled nodes (i.e. status = "disabled").
> + */
> +struct device_node *of_get_next_available_child(const struct device_node *node,
> +	struct device_node *prev)
> +{
> +	for_each_child_of_node(node, prev)
> +		if (of_device_is_available(prev))
> +			return prev;
> +	return NULL;
> +}
> +EXPORT_SYMBOL(of_get_next_available_child);
> +
> +/**
> + *	of_get_child_by_name - Find the child node by name for a given parent
> + *	@node:	parent node
> + *	@name:	child name to look for.
> + *
> + *      This function looks for child node for given matching name
> + *
> + *	Returns a node pointer if found or NULL.
> + */
> +struct device_node *of_get_child_by_name(const struct device_node *node,
> +				const char *name)
> +{
> +	struct device_node *child;
> +
> +	for_each_child_of_node(node, child)
> +		if (child->name && (of_node_cmp(child->name, name) == 0))
> +			return child;
> +
> +	return NULL;
> +}
> +EXPORT_SYMBOL(of_get_child_by_name);
> +
>  void of_print_nodes(struct device_node *node, int indent)
>  {
>  	struct device_node *n;
> diff --git a/include/of.h b/include/of.h
> index 208b00b..c69b9ad 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -195,6 +195,14 @@ extern struct device_node *of_find_node_with_property(
>  	struct device_node *from, const char *prop_name);
>  extern int of_device_is_available(const struct device_node *device);
>  
> +extern struct device_node *of_get_parent(const struct device_node *node);
> +extern struct device_node *of_get_next_child(const struct device_node *node,
> +					     struct device_node *prev);
> +extern struct device_node *of_get_next_available_child(
> +	const struct device_node *node, struct device_node *prev);
> +extern struct device_node *of_get_child_by_name(const struct device_node *node,
> +					const char *name);
> +
>  extern void of_alias_scan(void);
>  extern int of_alias_get_id(struct device_node *np, const char *stem);
>  extern const char *of_alias_get(struct device_node *np);
> @@ -239,6 +247,29 @@ static inline struct device_node *of_get_root_node(void)
>  	return NULL;
>  }
>  
> +static inline struct device_node *of_get_parent(const struct device_node *node)
> +{
> +	return NULL;
> +}
> +
> +static inline struct device_node *of_get_next_child(
> +		const struct device_node *node, struct device_node *prev)
> +{
> +	return NULL;
> +}
> +
> +static inline struct device_node *of_get_next_available_child(
> +		const struct device_node *node, struct device_node *prev)
> +{
> +	return NULL;
> +}
> +
> +static inline struct device_node *of_get_child_by_name(
> +			const struct device_node *node, const char *name)
> +{
> +	return NULL;
> +}
> +
>  static inline struct property *of_find_property(const struct device_node *np,
>  						const char *name,
>  						int *lenp)
> @@ -321,4 +352,22 @@ static inline struct device_node *of_find_matching_node(
>  	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
>  	     dn = of_find_node_with_property(dn, prop_name))
>  
> +#define for_each_child_of_node(parent, child) \
> +	for (child = of_get_next_child(parent, NULL); child != NULL; \
> +	     child = of_get_next_child(parent, child))

Why don't we just rename the original list iteration #define?

I think we shouldn't generate worse code just for the sake of being in
sync with Linux.

I wonder why the Linux implementation doesn't use the Linux list
implementation...

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Tue Jun 18 16:34:36 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 18 Jun 2013 22:34:36 +0200
Subject: [PATCH 13/22] OF: base: import parent/child functions from Linux
 OF API
In-Reply-To: <20130618202931.GC32299@pengutronix.de>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371576607-8090-14-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130618202931.GC32299@pengutronix.de>
Message-ID: <51C0C45C.80004@gmail.com>

On 06/18/2013 10:29 PM, Sascha Hauer wrote:
> On Tue, Jun 18, 2013 at 07:29:58PM +0200, Sebastian Hesselbarth wrote:
>> This imports of_get_parent, of_get_next_child, of_get_next_available_child,
>> and of_get_child_by_name and corresponding helpers from Linux OF API.
>>
>> Signed-off-by: Sebastian Hesselbarth<sebastian.hesselbarth at gmail.com>
>> ---
[...]
>> +#define for_each_child_of_node(parent, child) \
>> +	for (child = of_get_next_child(parent, NULL); child != NULL; \
>> +	     child = of_get_next_child(parent, child))
>
> Why don't we just rename the original list iteration #define?
>
> I think we shouldn't generate worse code just for the sake of being in
> sync with Linux.

Agree, reworking this will take some days as I will not be able to
get back to it soon. Rebasing that 22 patches beast is time-consuming ;)

> I wonder why the Linux implementation doesn't use the Linux list
> implementation...

Maybe you should also raise that question on devtree-discuss?

Sebastian


From s.hauer at pengutronix.de  Wed Jun 19 01:38:27 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 07:38:27 +0200
Subject: [PATCH] devfs-core: introduce devfs_append_partition
In-Reply-To: <1371559850-21867-1-git-send-email-jlu@pengutronix.de>
References: <1371559850-21867-1-git-send-email-jlu@pengutronix.de>
Message-ID: <20130619053827.GF32299@pengutronix.de>

On Tue, Jun 18, 2013 at 02:50:50PM +0200, Jan Luebbe wrote:
> This simplifies board code for partition setup by keeping track of the
> offset.
> 
> Signed-off-by: Jan Luebbe <jlu at pengutronix.de>

Good idea. There seem to be some bugs in this area. I'm fine with the
patch when some users are converted to this.

Sascha

> ---
>  fs/devfs-core.c  | 9 +++++++++
>  include/driver.h | 2 ++
>  2 files changed, 11 insertions(+)
> 
> diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> index 262e0a2..f7d79ff 100644
> --- a/fs/devfs-core.c
> +++ b/fs/devfs-core.c
> @@ -267,6 +267,15 @@ int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
>  	return 0;
>  }
>  
> +int devfs_append_partition(const char *devname, loff_t *offset, loff_t size,
> +		int flags, const char *name)
> +{
> +	int ret;
> +	ret = devfs_add_partition(devname, *offset, size, flags, name);
> +	*offset += size;
> +	return ret;
> +}
> +
>  int devfs_del_partition(const char *name)
>  {
>  	struct cdev *cdev;
> diff --git a/include/driver.h b/include/driver.h
> index 716f792..3f4f7b9 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -463,6 +463,8 @@ int cdev_erase(struct cdev *cdev, size_t count, loff_t offset);
>  
>  int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
>  		int flags, const char *name);
> +int devfs_append_partition(const char *devname, loff_t *offset, loff_t size,
> +		int flags, const char *name);
>  int devfs_del_partition(const char *name);
>  
>  #define DRV_OF_COMPAT(compat) \
> -- 
> 1.8.3.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From shc_work at mail.ru  Wed Jun 19 02:03:13 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Wed, 19 Jun 2013 10:03:13 +0400
Subject: =?UTF-8?B?UmVbMl06IFtQQVRDSF0gZGV2ZnMtY29yZTogaW50cm9kdWNlIGRldmZzX2Fw?=
 =?UTF-8?B?cGVuZF9wYXJ0aXRpb24=?=
In-Reply-To: <20130619053827.GF32299@pengutronix.de>
References: <1371559850-21867-1-git-send-email-jlu@pengutronix.de>
 <20130619053827.GF32299@pengutronix.de>
Message-ID: <1371621793.699357681@f89.mail.ru>

> On Tue, Jun 18, 2013 at 02:50:50PM +0200, Jan Luebbe wrote:
> > This simplifies board code for partition setup by keeping track of the
> > offset.
> > 
> > Signed-off-by: Jan Luebbe <jlu at pengutronix.de>
> 
> Good idea. There seem to be some bugs in this area. I'm fine with the
> patch when some users are converted to this.

But lets make static variable "offset", setup it in devfs_add_partition and
just add "size" in the devfs_append_partition.
Otherwise I do not see any difference between "add" and "append".

> > ---
> >  fs/devfs-core.c  | 9 +++++++++
> >  include/driver.h | 2 ++
> >  2 files changed, 11 insertions(+)
> > 
> > diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> > index 262e0a2..f7d79ff 100644
> > --- a/fs/devfs-core.c
> > +++ b/fs/devfs-core.c
> > @@ -267,6 +267,15 @@ int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
> >  	return 0;
> >  }
> >  
> > +int devfs_append_partition(const char *devname, loff_t *offset, loff_t size,
> > +		int flags, const char *name)
> > +{
> > +	int ret;
> > +	ret = devfs_add_partition(devname, *offset, size, flags, name);
> > +	*offset += size;
> > +	return ret;
> > +}
> > +
> >  int devfs_del_partition(const char *name)
> >  {
> >  	struct cdev *cdev;
> > diff --git a/include/driver.h b/include/driver.h
> > index 716f792..3f4f7b9 100644
> > --- a/include/driver.h
> > +++ b/include/driver.h
> > @@ -463,6 +463,8 @@ int cdev_erase(struct cdev *cdev, size_t count, loff_t offset);
> >  
> >  int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
> >  		int flags, const char *name);
> > +int devfs_append_partition(const char *devname, loff_t *offset, loff_t size,
> > +		int flags, const char *name);
> >  int devfs_del_partition(const char *name);
> >  
> >  #define DRV_OF_COMPAT(compat) \

---

From jlu at pengutronix.de  Wed Jun 19 02:32:48 2013
From: jlu at pengutronix.de (Jan =?ISO-8859-1?Q?L=FCbbe?=)
Date: Wed, 19 Jun 2013 08:32:48 +0200
Subject: [PATCH] devfs-core: introduce devfs_append_partition
In-Reply-To: <1371621793.699357681@f89.mail.ru>
References: <1371559850-21867-1-git-send-email-jlu@pengutronix.de>
 <20130619053827.GF32299@pengutronix.de> <1371621793.699357681@f89.mail.ru>
Message-ID: <1371623568.4168.71.camel@coredoba.hi.pengutronix.de>

On Wed, 2013-06-19 at 10:03 +0400, Alexander Shiyan wrote:
> > On Tue, Jun 18, 2013 at 02:50:50PM +0200, Jan Luebbe wrote:
> > > This simplifies board code for partition setup by keeping track of the
> > > offset.
> > > 
> > > Signed-off-by: Jan Luebbe <jlu at pengutronix.de>
> > 
> > Good idea. There seem to be some bugs in this area. I'm fine with the
> > patch when some users are converted to this.
> 
> But lets make static variable "offset", setup it in devfs_add_partition and
> just add "size" in the devfs_append_partition.
> Otherwise I do not see any difference between "add" and "append".

I'd prefer to have the state where it's obvious to the caller and not in
a static variable somewhere else. :)

Regards,
Jan
-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



From W.Vanhauwaert at TELEVIC.com  Wed Jun 19 02:59:36 2013
From: W.Vanhauwaert at TELEVIC.com (Vanhauwaert Wouter)
Date: Wed, 19 Jun 2013 08:59:36 +0200
Subject: Barebox fails to boot 1/40 boots...
In-Reply-To: <20130618192504.GX32299@pengutronix.de>
References: <E78BBE677EB9144B8F0A0A29674CD5338ED01639D6@SRV-VS06.TELEVIC.COM>
 <20130618192504.GX32299@pengutronix.de>
Message-ID: <E78BBE677EB9144B8F0A0A29674CD5338ED0163C71@SRV-VS06.TELEVIC.COM>



> -----Original Message-----
> From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
> Sent: dinsdag 18 juni 2013 21:25
> To: Vanhauwaert Wouter
> Cc: barebox at lists.infradead.org
> Subject: Re: Barebox fails to boot 1/40 boots...
> 
> On Tue, Jun 18, 2013 at 02:59:57PM +0200, Vanhauwaert Wouter wrote:
> > Hello all,
> >
> > I have this issue with our custom design (IMX53, NAND, DDR3)
> >
> > Everything goes well most of the time, but now and then  the system does not
> boot and halts during initialization...
> > To be more specific, the function on which the system blocks is
> > 'setup_c()' in arch/arm/cpu/start-pbl.c
> >
> > What can I do more to debug this? This function is completely in assembler...
> 
> What makes you sure barebox stops there? Do you have DEBUG_LL enabled or
> do you use a JTAG debugger?
> 

Because these are real on/off tests (with which I mean with a relais which switches on/off every 10 seconds or so, a cold restart) I did not have the ability to test it with a debugger.
What I did was changing the LDO voltage from 1.2V to 1.3V and measure this with a scoop. When I put the adjustment right before this setup_c(), it goes well all the time (even when the board is blocked), 
when I put it after this setup_c(), it doesn't  get through when the board is blocked. So my assumption is it blocks in this function.

> Does this happen in first stage boot only or also when you chainload barebox
> from an already running barebox?

This is in a first stage boot...

> 
> You could try calling imx53_init_lowlevel_early from
> barebox_arm_reset_vector(). This *could* make a difference.
> 
> Since you are using v2013.05-stable you should have the following patches, but
> maybe it's worth rechecking.
> 
> 76820df ARM: invalidate data caches during early init
> f9d7582 ARM v7: added v7_mmu_cache_invalidate()
> ee5f859 ARM v7: v7_mmu_cache_flush(): do not restore r0-r3 (minor
> optimization) eb7d85c arm: properly init alignment trap bit
> 7904d90 ARM v7: fix mmu-off operation
> 9af1150 ARM: fix the memset fix
> 

I'll check

Grtz,
Wouter



From t.gamez at phytec.de  Wed Jun 19 03:09:44 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Wed, 19 Jun 2013 09:09:44 +0200
Subject: [PATCHv3 3/4] omap3_spi: Set the correct CS number for AM33xx
In-Reply-To: <1371625785-27704-1-git-send-email-t.gamez@phytec.de>
References: <1371625785-27704-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371625785-27704-3-git-send-email-t.gamez@phytec.de>

Changed the number of CS for AM33xx boards to 2.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
changes since v3:
        - splitted the former "omap3_spi: Add CS check for AM335x"
          patch into two
	- Set correct number of CS here

 drivers/spi/omap3_spi.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index 508e2d9..1a92565 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -359,16 +359,24 @@ static int omap3_spi_probe(struct device_d *dev)
 	 * McSPI3 has 2 CS (bus 3, cs 0 - 1)
 	 * McSPI4 has 1 CS (bus 4, cs 0)
 	 *
+	 * AM335x McSPI has 2 busses with 2 chip selects:
+	 * McSPI0 has 2 CS (bus 0, cs 0 - 1)
+	 * McSPI1 has 2 CS (bus 1, cs 0 - 1)
+	 *
 	 * The board code has to make sure that it does not use
 	 * invalid buses or chip selects.
 	 */
 
 	master->bus_num = dev->id;
-	master->num_chipselect = 4;
+
+	if (IS_ENABLED(CONFIG_ARCH_OMAP3))
+		master->num_chipselect = 4;
+	else
+		master->num_chipselect = 2;
 	master->setup = omap3_spi_setup;
 	master->transfer = omap3_spi_transfer;
 
-	omap3_master->regs = dev_request_mem_region(dev, 0);;
+	omap3_master->regs = dev_request_mem_region(dev, 0);
 
 	spi_reset(master);
 
-- 
1.7.0.4



From t.gamez at phytec.de  Wed Jun 19 03:09:42 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Wed, 19 Jun 2013 09:09:42 +0200
Subject: [PATCHv3 1/4] ARM: OMAP: AM33xx: Add muxing function for spi0
Message-ID: <1371625785-27704-1-git-send-email-t.gamez@phytec.de>

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 arch/arm/mach-omap/am33xx_mux.c              |    5 +++++
 arch/arm/mach-omap/include/mach/am33xx-mux.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap/am33xx_mux.c b/arch/arm/mach-omap/am33xx_mux.c
index 424d120..abc8586 100644
--- a/arch/arm/mach-omap/am33xx_mux.c
+++ b/arch/arm/mach-omap/am33xx_mux.c
@@ -314,3 +314,8 @@ void am33xx_enable_mmc0_pin_mux(void)
 {
 	configure_module_pin_mux(mmc0_pin_mux);
 }
+
+void am33xx_enable_spi0_pin_mux(void)
+{
+	configure_module_pin_mux(spi0_pin_mux);
+}
diff --git a/arch/arm/mach-omap/include/mach/am33xx-mux.h b/arch/arm/mach-omap/include/mach/am33xx-mux.h
index 44b93bd..d6b19dd 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-mux.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-mux.h
@@ -256,5 +256,6 @@ extern void am33xx_enable_i2c2_pin_mux(void);
 extern void am33xx_enable_uart0_pin_mux(void);
 extern void am33xx_enable_uart2_pin_mux(void);
 extern void am33xx_enable_mmc0_pin_mux(void);
+extern void am33xx_enable_spi0_pin_mux(void);
 
 #endif /*__AM33XX_MUX_H__ */
-- 
1.7.0.4



From t.gamez at phytec.de  Wed Jun 19 03:09:43 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Wed, 19 Jun 2013 09:09:43 +0200
Subject: [PATCHv3 2/4] omap3_spi: Remove CS check in driver
In-Reply-To: <1371625785-27704-1-git-send-email-t.gamez@phytec.de>
References: <1371625785-27704-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371625785-27704-2-git-send-email-t.gamez@phytec.de>

Board file or DT has to take care that the correct
chip select and bus values are used.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
changes since v3:
	- splitted the former "omap3_spi: Add CS check for AM335x"
	  patch into two
	- removed the SPI check here

 drivers/spi/omap3_spi.c |    9 ---------
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/omap3_spi.c b/drivers/spi/omap3_spi.c
index e6581df..508e2d9 100644
--- a/drivers/spi/omap3_spi.c
+++ b/drivers/spi/omap3_spi.c
@@ -327,15 +327,6 @@ static int omap3_spi_setup(struct spi_device *spi)
 {
 	struct spi_master *master = spi->master;
 
-	if (((master->bus_num == 1) && (spi->chip_select > 3)) ||
-			((master->bus_num == 2) && (spi->chip_select > 1)) ||
-			((master->bus_num == 3) && (spi->chip_select > 1)) ||
-			((master->bus_num == 4) && (spi->chip_select > 0))) {
-		printf("SPI error: unsupported chip select %i \
-			on bus %i\n", spi->chip_select, master->bus_num);
-		return -EINVAL;
-	}
-
 	if (spi->max_speed_hz > OMAP3_MCSPI_MAX_FREQ) {
 		printf("SPI error: unsupported frequency %i Hz. \
 			Max frequency is 48 Mhz\n", spi->max_speed_hz);
-- 
1.7.0.4



From t.gamez at phytec.de  Wed Jun 19 03:09:45 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Wed, 19 Jun 2013 09:09:45 +0200
Subject: [PATCHv3 4/4] ARM: OMAP: pcm051: Add spi flash support
In-Reply-To: <1371625785-27704-1-git-send-email-t.gamez@phytec.de>
References: <1371625785-27704-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371625785-27704-4-git-send-email-t.gamez@phytec.de>

Add support for w25q64 SPI NOR flash.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
changes since v2: 
	- changed partition size to 512kb
	- added spi-nor boot option

 arch/arm/boards/pcm051/board.c               |   41 ++++++++++++++++++++++++++
 arch/arm/boards/pcm051/env/boot/spi-nor      |   12 +++++++
 arch/arm/boards/pcm051/env/init/mtdparts-nor |   12 +++++++
 arch/arm/configs/pcm051_defconfig            |    3 +-
 4 files changed, 67 insertions(+), 1 deletions(-)
 create mode 100644 arch/arm/boards/pcm051/env/boot/spi-nor
 create mode 100644 arch/arm/boards/pcm051/env/init/mtdparts-nor

diff --git a/arch/arm/boards/pcm051/board.c b/arch/arm/boards/pcm051/board.c
index 8754ba5..f0eaa01 100644
--- a/arch/arm/boards/pcm051/board.c
+++ b/arch/arm/boards/pcm051/board.c
@@ -26,6 +26,8 @@
 #include <mach/am33xx-devices.h>
 #include <mach/am33xx-mux.h>
 #include <mach/am33xx-silicon.h>
+#include <spi/spi.h>
+#include <spi/flash.h>
 
 #include "mux.h"
 
@@ -52,12 +54,51 @@ static int pcm051_mem_init(void)
 }
 mem_initcall(pcm051_mem_init);
 
+static struct flash_platform_data pcm051_spi_flash = {
+	.name	= "nor",
+	.type	= "w25q64",
+};
+
+/*
+* SPI Flash works at 80Mhz however the SPI controller runs with 48MHz.
+* So setup Max speed to be less than the controller speed.
+*/
+static struct spi_board_info pcm051_spi_board_info[] = {
+	{
+		.name		= "m25p80",
+		.platform_data	= &pcm051_spi_flash,
+		.max_speed_hz	= 24000000,
+		.bus_num	= 0,
+		.chip_select	= 0,
+	},
+};
+
+static void pcm051_spi_init(void)
+{
+	int ret;
+
+	am33xx_enable_spi0_pin_mux();
+
+	ret = spi_register_board_info(pcm051_spi_board_info,
+					ARRAY_SIZE(pcm051_spi_board_info));
+	am33xx_add_spi0();
+}
+
 static int pcm051_devices_init(void)
 {
 	pcm051_enable_mmc0_pin_mux();
 
 	am33xx_add_mmc0(NULL);
 
+	pcm051_spi_init();
+
+	devfs_add_partition("nor0", 0x00000, SZ_128K,
+					DEVFS_PARTITION_FIXED, "xload");
+	devfs_add_partition("nor0", SZ_128K, SZ_512K,
+					DEVFS_PARTITION_FIXED, "self0");
+	devfs_add_partition("nor0", SZ_128K + SZ_512K, SZ_128K,
+					DEVFS_PARTITION_FIXED, "env0");
+
 	armlinux_set_bootparams((void *)(AM33XX_DRAM_ADDR_SPACE_START + 0x100));
 	armlinux_set_architecture(MACH_TYPE_PCM051);
 
diff --git a/arch/arm/boards/pcm051/env/boot/spi-nor b/arch/arm/boards/pcm051/env/boot/spi-nor
new file mode 100644
index 0000000..d5f77c8
--- /dev/null
+++ b/arch/arm/boards/pcm051/env/boot/spi-nor
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+if [ "$1" = menu ]; then
+        boot-menu-add-entry "$0" "SPI NOR Flash"
+        exit
+fi
+
+global.bootm.image="/dev/nor0.kernel"
+
+# Use rootfs form SD-Card for now as rootfs partition < 4MB
+global.linux.bootargs.dyn.root="root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
+
diff --git a/arch/arm/boards/pcm051/env/init/mtdparts-nor b/arch/arm/boards/pcm051/env/init/mtdparts-nor
new file mode 100644
index 0000000..91aa847
--- /dev/null
+++ b/arch/arm/boards/pcm051/env/init/mtdparts-nor
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+if [ "$1" = menu ]; then
+	init-menu-add-entry "$0" "NOR partitions"
+	exit
+fi
+
+mtdparts="128k(nor0.xload),512k(nor0.barebox),128k(nor0.bareboxenv),4M(nor0.kernel),-(nor0.root)"
+kernelname="spi_flash"
+
+mtdparts-add -d nor0 -k ${kernelname} -p ${mtdparts}
+
diff --git a/arch/arm/configs/pcm051_defconfig b/arch/arm/configs/pcm051_defconfig
index 4da0ed4..90c2b50 100644
--- a/arch/arm/configs/pcm051_defconfig
+++ b/arch/arm/configs/pcm051_defconfig
@@ -44,8 +44,9 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_UNCOMPRESS=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SERIAL_NS16550_OMAP_EXTENSIONS=y
-# CONFIG_SPI is not set
+CONFIG_DRIVER_SPI_OMAP3=y
 CONFIG_MTD=y
+CONFIG_MTD_M25P80=y
 CONFIG_NAND=y
 CONFIG_USB=y
 CONFIG_MCI=y
-- 
1.7.0.4



From t.gamez at phytec.de  Wed Jun 19 03:11:22 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Wed, 19 Jun 2013 09:11:22 +0200
Subject: [PATCH] ARM: AM33xx: pcm051: Add network support
Message-ID: <1371625882-28767-1-git-send-email-t.gamez@phytec.de>

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 arch/arm/boards/pcm051/board.c    |   28 ++++++++++++++++++++++++++++
 arch/arm/configs/pcm051_defconfig |    5 +++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boards/pcm051/board.c b/arch/arm/boards/pcm051/board.c
index f0eaa01..0ad8cb4 100644
--- a/arch/arm/boards/pcm051/board.c
+++ b/arch/arm/boards/pcm051/board.c
@@ -19,13 +19,17 @@
 
 #include <common.h>
 #include <init.h>
+#include <io.h>
 #include <sizes.h>
 #include <ns16550.h>
 #include <asm/armlinux.h>
 #include <generated/mach-types.h>
+#include <linux/phy.h>
 #include <mach/am33xx-devices.h>
+#include <mach/am33xx-generic.h>
 #include <mach/am33xx-mux.h>
 #include <mach/am33xx-silicon.h>
+#include <mach/cpsw.h>
 #include <spi/spi.h>
 #include <spi/flash.h>
 
@@ -73,6 +77,18 @@ static struct spi_board_info pcm051_spi_board_info[] = {
 	},
 };
 
+static struct cpsw_slave_data cpsw_slaves[] = {
+	{
+		.phy_id		= 0,
+		.phy_if		= PHY_INTERFACE_MODE_RMII,
+	},
+};
+
+static struct cpsw_platform_data cpsw_data = {
+	.slave_data	= cpsw_slaves,
+	.num_slaves	= ARRAY_SIZE(cpsw_slaves),
+};
+
 static void pcm051_spi_init(void)
 {
 	int ret;
@@ -84,6 +100,17 @@ static void pcm051_spi_init(void)
 	am33xx_add_spi0();
 }
 
+static void pcm051_eth_init(void)
+{
+	am33xx_register_ethaddr(0, 0);
+
+	writel(0x49, AM33XX_MAC_MII_SEL);
+
+	am33xx_enable_rmii1_pin_mux();
+
+	am33xx_add_cpsw(&cpsw_data);
+}
+
 static int pcm051_devices_init(void)
 {
 	pcm051_enable_mmc0_pin_mux();
@@ -91,6 +118,7 @@ static int pcm051_devices_init(void)
 	am33xx_add_mmc0(NULL);
 
 	pcm051_spi_init();
+	pcm051_eth_init();
 
 	devfs_add_partition("nor0", 0x00000, SZ_128K,
 					DEVFS_PARTITION_FIXED, "xload");
diff --git a/arch/arm/configs/pcm051_defconfig b/arch/arm/configs/pcm051_defconfig
index 90c2b50..804ca14 100644
--- a/arch/arm/configs/pcm051_defconfig
+++ b/arch/arm/configs/pcm051_defconfig
@@ -42,8 +42,13 @@ CONFIG_CMD_TIMEOUT=y
 CONFIG_CMD_PARTITION=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_UNCOMPRESS=y
+CONFIG_NET=y
+CONFIG_NET_DHCP=y
+CONFIG_NET_NFS=y
+CONFIG_NET_PING=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SERIAL_NS16550_OMAP_EXTENSIONS=y
+CONFIG_DRIVER_NET_CPSW=y
 CONFIG_DRIVER_SPI_OMAP3=y
 CONFIG_MTD=y
 CONFIG_MTD_M25P80=y
-- 
1.7.0.4



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:31 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:31 +0200
Subject: [PATCH v2 02/22] OF: base: bail out early on missing matches for
 of_match_node
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-3-git-send-email-sebastian.hesselbarth@gmail.com>

of_match_node checks for compatiblity between a set of matches and a
node. Neither the matches nor node pointer are checked for validity.
This adds the required checks to of_match_node.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 4241e65..ab0f4cd 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -321,6 +321,9 @@ EXPORT_SYMBOL(of_device_is_compatible);
 const struct of_device_id *of_match_node(const struct of_device_id *matches,
 					 const struct device_node *node)
 {
+	if (!matches || !node)
+		return NULL;
+
 	while (matches->compatible) {
 		if (of_device_is_compatible(node, matches->compatible) == 1)
 			return matches;
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:38 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:38 +0200
Subject: [PATCH v2 09/22] OF: base: import of_find_node_by_name from Linux OF
 API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-10-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_find_node_by_name and corresponding for_each_node_by_name
helper from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   26 ++++++++++++++++++++++++++
 include/of.h      |   12 ++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 2176251..d736bef 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -312,6 +312,32 @@ int of_device_is_compatible(const struct device_node *device,
 EXPORT_SYMBOL(of_device_is_compatible);
 
 /**
+ *	of_find_node_by_name - Find a node by its "name" property
+ *	@from:	The node to start searching from or NULL, the node
+ *		you pass will not be searched, only the next one
+ *		will; typically, you pass what the previous call
+ *		returned.
+ *	@name:	The name string to match against
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_by_name(struct device_node *from,
+	const char *name)
+{
+	struct device_node *np;
+
+	if (!from)
+		from = root_node;
+
+	of_tree_for_each_node(np, from)
+		if (np->name && !of_node_cmp(np->name, name))
+			return np;
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_node_by_name);
+
+/**
  * of_match_node - Tell if an device_node has a matching of_match structure
  *      @matches:       array of of device match structures to search in
  *      @node:          the of device structure to match against
diff --git a/include/of.h b/include/of.h
index 56b7be1..8cbfe7a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -182,6 +182,8 @@ struct cdev;
 extern struct property *of_find_property(const struct device_node *np,
 					const char *name, int *lenp);
 
+extern struct device_node *of_find_node_by_name(struct device_node *from,
+	const char *name);
 extern struct device_node *of_find_node_by_path_from(struct device_node *from,
 						const char *path);
 extern struct device_node *of_find_node_by_path(const char *path);
@@ -249,6 +251,12 @@ static inline struct device_node *of_find_node_by_path(const char *path)
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_by_name(struct device_node *from,
+	const char *name)
+{
+	return NULL;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -269,4 +277,8 @@ static inline const char *of_alias_get(struct device_node *np)
 }
 #endif
 
+#define for_each_node_by_name(dn, name) \
+	for (dn = of_find_node_by_name(NULL, name); dn; \
+	     dn = of_find_node_by_name(dn, name))
+
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:30 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:30 +0200
Subject: [PATCH v2 01/22] lib: string: import case-insensitive string compare
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-2-git-send-email-sebastian.hesselbarth@gmail.com>

This imports strnicmp, strcasecmp, and strncasecmp from Linux to barebox.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 include/linux/string.h |    9 +++++++
 lib/string.c           |   60 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/include/linux/string.h b/include/linux/string.h
index afd0aa6..658264c 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -53,6 +53,15 @@ extern int strcmp(const char *,const char *);
 #ifndef __HAVE_ARCH_STRNCMP
 extern int strncmp(const char *,const char *,__kernel_size_t);
 #endif
+#ifndef __HAVE_ARCH_STRNICMP
+extern int strnicmp(const char *, const char *, __kernel_size_t);
+#endif
+#ifndef __HAVE_ARCH_STRCASECMP
+extern int strcasecmp(const char *s1, const char *s2);
+#endif
+#ifndef __HAVE_ARCH_STRNCASECMP
+extern int strncasecmp(const char *s1, const char *s2, size_t n);
+#endif
 #ifndef __HAVE_ARCH_STRCHR
 extern char * _strchr(const char *,int);
 #endif
diff --git a/lib/string.c b/lib/string.c
index db4f2ae..f544b23 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -22,6 +22,66 @@
 
 char * ___strtok;
 
+#ifndef __HAVE_ARCH_STRNICMP
+/**
+ * strnicmp - Case insensitive, length-limited string comparison
+ * @s1: One string
+ * @s2: The other string
+ * @len: the maximum number of characters to compare
+ */
+int strnicmp(const char *s1, const char *s2, size_t len)
+{
+	/* Yes, Virginia, it had better be unsigned */
+	unsigned char c1, c2;
+
+	if (!len)
+		return 0;
+
+	do {
+		c1 = *s1++;
+		c2 = *s2++;
+		if (!c1 || !c2)
+			break;
+		if (c1 == c2)
+			continue;
+		c1 = tolower(c1);
+		c2 = tolower(c2);
+		if (c1 != c2)
+			break;
+	} while (--len);
+	return (int)c1 - (int)c2;
+}
+EXPORT_SYMBOL(strnicmp);
+#endif
+
+#ifndef __HAVE_ARCH_STRCASECMP
+int strcasecmp(const char *s1, const char *s2)
+{
+	int c1, c2;
+
+	do {
+		c1 = tolower(*s1++);
+		c2 = tolower(*s2++);
+	} while (c1 == c2 && c1 != 0);
+	return c1 - c2;
+}
+EXPORT_SYMBOL(strcasecmp);
+#endif
+
+#ifndef __HAVE_ARCH_STRNCASECMP
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+	int c1, c2;
+
+	do {
+		c1 = tolower(*s1++);
+		c2 = tolower(*s2++);
+	} while ((--n > 0) && c1 == c2 && c1 != 0);
+	return c1 - c2;
+}
+EXPORT_SYMBOL(strncasecmp);
+#endif
+
 #ifndef __HAVE_ARCH_STRCPY
 /**
  * strcpy - Copy a %NUL terminated string
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:32 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:32 +0200
Subject: [PATCH v2 03/22] OF: base: also update property length on
 of_property_write_u32
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-4-git-send-email-sebastian.hesselbarth@gmail.com>

Current implementation of of_property_write_u32 does free old property
values and allocates new values depending on the size passed. While
copying the new values to the property, corresponding length is not
set. This makes of_property_write_u32 set the length of the new property
values and also adds a API header describing the function.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index ab0f4cd..616b93d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -383,6 +383,21 @@ int of_property_read_u32_array(const struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(of_property_read_u32_array);
 
+/**
+ * of_property_write_u32_array - Write an array of u32 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np:		device node to which the property value is to be written.
+ * @propname:	name of the property to be written.
+ * @values:	pointer to array elements to write.
+ * @sz:		number of array elements to write.
+ *
+ * Search for a property in a device node and write 32-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
 int of_property_write_u32_array(struct device_node *np,
 				const char *propname, const u32 *values,
 				size_t sz)
@@ -397,14 +412,15 @@ int of_property_write_u32_array(struct device_node *np,
 
 	free(prop->value);
 
-	prop->value = malloc(sizeof(__be32) * sz);
+	prop->length = sizeof(*val) * sz;
+	prop->value = malloc(prop->length);
 	if (!prop->value)
 		return -ENOMEM;
 
 	val = prop->value;
-
 	while (sz--)
 		*val++ = cpu_to_be32(*values++);
+
 	return 0;
 }
 
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:29 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:29 +0200
Subject: [PATCH v2 00/22] Barebox OF API fixes, sync, and cleanup
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-1-git-send-email-sebastian.hesselbarth@gmail.com>

This is a quite large patch set to make Barebox OF API more behave
like Linux OF API. Also, it prepares Barebox to reuse Linux OF address
handling and drivers/of/of_* helpers soon.

The patch set is roughly divided into 5 sections:

(1) Patch 1 introduces case-insensitive string compare functions that will
    be used later during import of Linux OF API functions.

(2) Patches 2 and 3 fix some bugs in existing OF API functions.

(3) Patches 4-8 synchronize existing OF API functions with Linux OF API
    counterparts.

(4) Patches 9-18 import API functions from Linux OF API or introduce new
    functions based on existing Barebox OF API functions.

(5) Patches 19-22 convert to new API functions and remove now obsolete
    functions. Further, it cleans up existing OF include, by providing
    OFTREE prototypes and !OFTREE bogus stubs.

v2 of this patch set takes care of comments made by Sascha Hauer with
respect to Patches 7 and 13. A detailed changelog is given in the
respective patches. Unfortunately, I have to resend the whole patch
set, although only 2 patches really changed as the following patches
need to be rebased on to that changes.

Also, this v2 is only compile-tested for CONFIG_OFTREE set and not set.

The v2 patch set applied to barebox/next can also be found at
git://github.com/shesselba/barebox-dove.git barebox-of-sync-v2

Sebastian Hesselbarth (22):
  lib: string: import case-insensitive string compare
  OF: base: bail out early on missing matches for of_match_node
  OF: base: also update property length on of_property_write_u32
  OF: base: export of_alias_scan
  OF: base: convert strcmp to default string compare functions
  OF: base: sync of_find_property with linux OF API
  OF: base: sync of_find_node_by_path with linux OF API
  OF: base: rename of_node_disabled to of_device_is_available
  OF: base: import of_find_node_by_name from Linux OF API
  OF: base: import of_find_compatible_node from Linux OF API
  OF: base: import of_find_matching_node_and_match from Linux OF API
  OF: base: import of_find_node_with_property from Linux OF API
  OF: base: import parent/child functions from Linux OF API
  OF: base: import of_property_read_* helpers from Linux OF API
  OF: base: import of_parse_phandle from Linux OF API
  OF: base: import parse phandle functions from Linux OF API
  OF: base: introduce property write for bool, u8, u16, and u64
  OF: base: import property iterators from Linux OF API
  OF: base: remove of_tree_for_each_node from public API
  OF: base: remove of_find_child_by_name
  OF: base: convert and remove device_node_for_nach_child
  OF: base: cleanup base function include

 arch/arm/boards/at91sam9x5ek/hw_version.c |   10 +-
 arch/arm/boards/highbank/init.c           |   20 +-
 arch/ppc/mach-mpc5xxx/cpu.c               |    4 +-
 commands/of_node.c                        |    2 +-
 commands/of_property.c                    |   12 +-
 commands/oftree.c                         |   11 +-
 common/oftree.c                           |    2 +-
 drivers/i2c/i2c.c                         |    2 +-
 drivers/mfd/stmpe-i2c.c                   |    7 +-
 drivers/of/base.c                         | 1244 +++++++++++++++++++++++------
 drivers/of/fdt.c                          |   14 +-
 drivers/of/gpio.c                         |    9 +-
 drivers/of/of_net.c                       |    6 +-
 drivers/of/partition.c                    |    2 +-
 drivers/pinctrl/pinctrl.c                 |    4 +-
 drivers/spi/spi.c                         |   12 +-
 drivers/usb/imx/chipidea-imx.c            |   14 +-
 include/linux/string.h                    |    9 +
 include/of.h                              |  616 ++++++++++++--
 lib/string.c                              |   60 ++
 net/eth.c                                 |    2 +-
 21 files changed, 1645 insertions(+), 417 deletions(-)
---
Cc: barebox at lists.infradead.org
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:34 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:34 +0200
Subject: [PATCH v2 05/22] OF: base: convert strcmp to default string compare
 functions
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-6-git-send-email-sebastian.hesselbarth@gmail.com>

Barebox compares compatible, node names, and property names with strcmp.
Linux by default compares compatible and node names with strcasecmp. To
avoid inconsitencies between Barebox and Linux dts files, we convert to
these default string compare functions.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   25 +++++++++++++------------
 include/of.h      |    5 +++++
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index f3ed836..1c9ef58 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -104,14 +104,15 @@ static void of_bus_count_cells(struct device_node *dev,
 
 struct property *of_find_property(const struct device_node *node, const char *name)
 {
-	struct property *p;
+	struct property *pp;
 
 	if (!node)
 		return NULL;
 
-	list_for_each_entry(p, &node->properties, list)
-		if (!strcmp(p->name, name))
-			return p;
+	list_for_each_entry(pp, &node->properties, list)
+		if (of_prop_cmp(pp->name, name) == 0)
+			return pp;
+
 	return NULL;
 }
 EXPORT_SYMBOL(of_find_property);
@@ -160,9 +161,9 @@ void of_alias_scan(void)
 		int id, len;
 
 		/* Skip those we do not want to proceed */
-		if (!strcmp(pp->name, "name") ||
-		    !strcmp(pp->name, "phandle") ||
-		    !strcmp(pp->name, "linux,phandle"))
+		if (!of_prop_cmp(pp->name, "name") ||
+		    !of_prop_cmp(pp->name, "phandle") ||
+		    !of_prop_cmp(pp->name, "linux,phandle"))
 			continue;
 
 		np = of_find_node_by_path(root_node, pp->value);
@@ -203,7 +204,7 @@ int of_alias_get_id(struct device_node *np, const char *stem)
 	int id = -ENODEV;
 
 	list_for_each_entry(app, &aliases_lookup, link) {
-		if (strcmp(app->stem, stem) != 0)
+		if (of_node_cmp(app->stem, stem) != 0)
 			continue;
 
 		if (np == app->np) {
@@ -221,7 +222,7 @@ const char *of_alias_get(struct device_node *np)
 	struct property *pp;
 
 	list_for_each_entry(pp, &of_aliases->properties, list) {
-		if (!strcmp(np->full_name, pp->value))
+		if (!of_node_cmp(np->full_name, pp->value))
 			return pp->name;
 	}
 
@@ -301,7 +302,7 @@ int of_device_is_compatible(const struct device_node *device,
 	if (cp == NULL)
 		return 0;
 	while (cplen > 0) {
-		if (strcmp(cp, compat) == 0)
+		if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
 			return 1;
 		l = strlen(cp) + 1;
 		cp += l;
@@ -958,7 +959,7 @@ int of_add_memory(struct device_node *node, bool dump)
 	if (ret)
 		return -ENXIO;
 
-	if (strcmp(device_type, "memory"))
+	if (of_node_cmp(device_type, "memory"))
 		return -ENXIO;
 
 	of_bus_count_cells(node, &na, &nc);
@@ -1177,7 +1178,7 @@ struct device_node *of_find_child_by_name(struct device_node *node, const char *
 	struct device_node *_n;
 
 	device_node_for_nach_child(node, _n)
-		if (!strcmp(_n->name, name))
+		if (!of_node_cmp(_n->name, name))
 			return _n;
 
 	return NULL;
diff --git a/include/of.h b/include/of.h
index 8a69793..a91a4c9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -5,6 +5,11 @@
 #include <errno.h>
 #include <asm/byteorder.h>
 
+/* Default string compare functions */
+#define of_compat_cmp(s1, s2, l)	strcasecmp((s1), (s2))
+#define of_prop_cmp(s1, s2)		strcmp((s1), (s2))
+#define of_node_cmp(s1, s2)		strcasecmp((s1), (s2))
+
 #define OF_BAD_ADDR      ((u64)-1)
 
 typedef u32 phandle;
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:35 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:35 +0200
Subject: [PATCH v2 06/22] OF: base: sync of_find_property with linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-7-git-send-email-sebastian.hesselbarth@gmail.com>

To start synchronizing OF API of barebox with linux OF API, this adds
a length pointer to of_find_property. Also all current users of that
function are updated to reflect the API change.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 commands/of_property.c         |    2 +-
 drivers/of/base.c              |   38 ++++++++++++++++++--------------------
 drivers/of/fdt.c               |    5 ++++-
 drivers/of/of_net.c            |    6 +++---
 drivers/pinctrl/pinctrl.c      |    4 ++--
 drivers/spi/spi.c              |   10 +++++-----
 drivers/usb/imx/chipidea-imx.c |    3 ++-
 include/of.h                   |   12 ++++++++++--
 8 files changed, 45 insertions(+), 35 deletions(-)

diff --git a/commands/of_property.c b/commands/of_property.c
index 44bb388..d1a9a17 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -212,7 +212,7 @@ static int do_of_property(int argc, char *argv[])
 	if (optind + 1 < argc) {
 		propname = argv[optind + 1];
 
-		pp = of_find_property(node, propname);
+		pp = of_find_property(node, propname, NULL);
 		if (!set && !pp) {
 			printf("Cannot find property %s\n", propname);
 			return -ENOENT;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1c9ef58..85199b6 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -102,16 +102,20 @@ static void of_bus_count_cells(struct device_node *dev,
 	of_bus_default_count_cells(dev, addrc, sizec);
 }
 
-struct property *of_find_property(const struct device_node *node, const char *name)
+struct property *of_find_property(const struct device_node *np,
+				  const char *name, int *lenp)
 {
 	struct property *pp;
 
-	if (!node)
+	if (!np)
 		return NULL;
 
-	list_for_each_entry(pp, &node->properties, list)
-		if (of_prop_cmp(pp->name, name) == 0)
+	list_for_each_entry(pp, &np->properties, list)
+		if (of_prop_cmp(pp->name, name) == 0) {
+			if (lenp)
+				*lenp = pp->length;
 			return pp;
+		}
 
 	return NULL;
 }
@@ -242,7 +246,7 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr)
 			return addr;
 
 		node = node->parent;
-		p = of_find_property(node, "ranges");
+		p = of_find_property(node, "ranges", NULL);
 		if (!p && node->parent)
 			return OF_BAD_ADDR;
 		of_bus_count_cells(node, &na, &nc);
@@ -277,13 +281,7 @@ EXPORT_SYMBOL(of_find_node_by_phandle);
 const void *of_get_property(const struct device_node *np, const char *name,
 			 int *lenp)
 {
-	struct property *pp = of_find_property(np, name);
-
-	if (!pp)
-		return NULL;
-
-	if (lenp)
-		*lenp = pp->length;
+	struct property *pp = of_find_property(np, name, lenp);
 
 	return pp ? pp->value : NULL;
 }
@@ -368,7 +366,7 @@ int of_property_read_u32_array(const struct device_node *np,
 			       const char *propname, u32 *out_values,
 			       size_t sz)
 {
-	struct property *prop = of_find_property(np, propname);
+	struct property *prop = of_find_property(np, propname, NULL);
 	const __be32 *val;
 
 	if (!prop)
@@ -404,7 +402,7 @@ int of_property_write_u32_array(struct device_node *np,
 				const char *propname, const u32 *values,
 				size_t sz)
 {
-	struct property *prop = of_find_property(np, propname);
+	struct property *prop = of_find_property(np, propname, NULL);
 	__be32 *val;
 
 	if (!prop)
@@ -619,7 +617,7 @@ EXPORT_SYMBOL(of_find_node_by_path);
 int of_property_read_string(struct device_node *np, const char *propname,
 				const char **out_string)
 {
-	struct property *prop = of_find_property(np, propname);
+	struct property *prop = of_find_property(np, propname, NULL);
 	if (!prop)
 		return -EINVAL;
 	if (!prop->value)
@@ -652,7 +650,7 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
 int of_property_read_string_index(struct device_node *np, const char *propname,
 				  int index, const char **output)
 {
-	struct property *prop = of_find_property(np, propname);
+	struct property *prop = of_find_property(np, propname, NULL);
 	int i = 0;
 	size_t l = 0, total = 0;
 	const char *p;
@@ -725,7 +723,7 @@ static int of_node_disabled(struct device_node *node)
 {
 	struct property *p;
 
-	p = of_find_property(node, "status");
+	p = of_find_property(node, "status", NULL);
 	if (p) {
 		if (!strcmp("disabled", p->value))
 			return 1;
@@ -833,7 +831,7 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
 	if (!np)
 		return -ENOENT;
 
-	pp = of_find_property(np, name);
+	pp = of_find_property(np, name, NULL);
 	if (pp) {
 		void *data;
 
@@ -1278,11 +1276,11 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 	} else {
 		struct property *pp;
 
-		pp = of_find_property(chosen, "linux,initrd-start");
+		pp = of_find_property(chosen, "linux,initrd-start", NULL);
 		if (pp)
 			of_delete_property(pp);
 
-		pp = of_find_property(chosen, "linux,initrd-end");
+		pp = of_find_property(chosen, "linux,initrd-end", NULL);
 		if (pp)
 			of_delete_property(pp);
 	}
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a3ec576..a76396e 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -178,7 +178,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
 				goto err;
 			}
 
-			if (merge && (p = of_find_property(node, name))) {
+			p = NULL;
+			if (merge)
+				p = of_find_property(node, name, NULL);
+			if (merge && p) {
 				free(p->value);
 				p->value = xzalloc(len);
 				memcpy(p->value, nodep, len);
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index de93fbc..2bf05e2 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -76,15 +76,15 @@ const void *of_get_mac_address(struct device_node *np)
 {
 	struct property *pp;
 
-	pp = of_find_property(np, "mac-address");
+	pp = of_find_property(np, "mac-address", NULL);
 	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
 		return pp->value;
 
-	pp = of_find_property(np, "local-mac-address");
+	pp = of_find_property(np, "local-mac-address", NULL);
 	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
 		return pp->value;
 
-	pp = of_find_property(np, "address");
+	pp = of_find_property(np, "address", NULL);
 	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
 		return pp->value;
 
diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index fa979a1..7c797d3 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -64,14 +64,14 @@ int pinctrl_select_state(struct device_d *dev, const char *name)
 	if (!np)
 		return 0;
 
-	if (!of_find_property(np, "pinctrl-0"))
+	if (!of_find_property(np, "pinctrl-0", NULL))
 		return 0;
 
 	/* For each defined state ID */
 	for (state = 0; ; state++) {
 		/* Retrieve the pinctrl-* property */
 		propname = asprintf("pinctrl-%d", state);
-		prop = of_find_property(np, propname);
+		prop = of_find_property(np, propname, NULL);
 		free(propname);
 
 		if (!prop) {
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index f460a7a..eebf64c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -112,17 +112,17 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
 		chip.name = xstrdup(n->name);
 		chip.bus_num = master->bus_num;
 		/* Mode (clock phase/polarity/etc.) */
-		if (of_find_property(n, "spi-cpha"))
+		if (of_find_property(n, "spi-cpha", NULL))
 			chip.mode |= SPI_CPHA;
-		if (of_find_property(n, "spi-cpol"))
+		if (of_find_property(n, "spi-cpol", NULL))
 			chip.mode |= SPI_CPOL;
-		if (of_find_property(n, "spi-cs-high"))
+		if (of_find_property(n, "spi-cs-high", NULL))
 			chip.mode |= SPI_CS_HIGH;
-		if (of_find_property(n, "spi-3wire"))
+		if (of_find_property(n, "spi-3wire", NULL))
 			chip.mode |= SPI_3WIRE;
 		of_property_read_u32(n, "spi-max-frequency",
 				&chip.max_speed_hz);
-		reg = of_find_property(n, "reg");
+		reg = of_find_property(n, "reg", NULL);
 		if (!reg)
 			continue;
 		chip.chip_select = of_read_number(reg->value, 1);
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 4ee7610..32b05aa 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -108,7 +108,8 @@ static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
 		return -EINVAL;
 	}
 
-	if (of_find_property(ci->dev->device_node, "disable-over-current"))
+	if (of_find_property(ci->dev->device_node,
+				"disable-over-current"), NULL)
 		ci->flags |= MXC_EHCI_DISABLE_OVERCURRENT;
 
 	return 0;
diff --git a/include/of.h b/include/of.h
index a91a4c9..7ebde62 100644
--- a/include/of.h
+++ b/include/of.h
@@ -67,8 +67,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 int of_n_addr_cells(struct device_node *np);
 int of_n_size_cells(struct device_node *np);
 
-struct property *of_find_property(const struct device_node *node, const char *name);
-
 struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
 
 struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
@@ -183,6 +181,9 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
 struct cdev;
 
 #ifdef CONFIG_OFTREE
+extern struct property *of_find_property(const struct device_node *np,
+					const char *name, int *lenp);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -227,6 +228,13 @@ static inline struct device_node *of_get_root_node(void)
 	return NULL;
 }
 
+static inline struct property *of_find_property(const struct device_node *np,
+						const char *name,
+						int *lenp)
+{
+	return NULL;
+}
+
 static inline void of_alias_scan(void)
 {
 }
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:36 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:36 +0200
Subject: [PATCH v2 07/22] OF: base: sync of_find_node_by_path with linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-8-git-send-email-sebastian.hesselbarth@gmail.com>

Barebox of_find_node_by_path requires a node to be passed as start node
to start searching. Linux OF API does not pass this node and no current
user of it in barebox is passing anything else than the root node.
Therefore, we rename current function to of_find_node_by_path_from and
introduce a Linux OF API compatible of_find_node_by_path that always
passes the current root_node. Also, all current users of that function
are updated to reflect the API change.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org

Changelog:
v1->v2:
- rename current of_find_node_by_path to of_find_node_by_path_from
  (Suggested by Sascha Hauer)
- implement of_find_node_by_path with root_node passed to above
  (Suggested by Sascha Hauer)
---
 arch/arm/boards/highbank/init.c |    4 +-
 arch/ppc/mach-mpc5xxx/cpu.c     |    4 +-
 commands/of_node.c              |    2 +-
 commands/of_property.c          |   10 +-------
 commands/oftree.c               |   11 +---------
 common/oftree.c                 |    2 +-
 drivers/of/base.c               |   43 ++++++++++++++++++++++++--------------
 include/of.h                    |   17 +++++++++++++-
 net/eth.c                       |    2 +-
 9 files changed, 52 insertions(+), 43 deletions(-)

diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index d4a5c5a..1aa713b 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -53,7 +53,7 @@ static int hb_fixup(struct device_node *root)
 	if ((opp_table[0] >> 16) != HB_OPP_VERSION)
 		return 0;
 
-	node = of_find_node_by_path(root, "/cpus/cpu at 0");
+	node = of_find_node_by_path("/cpus/cpu at 0");
 	if (!node)
 		return 0;
 
@@ -89,7 +89,7 @@ static int highbank_mem_init(void)
 
 	of_set_root_node(root);
 
-	np = of_find_node_by_path(root, "/memory");
+	np = of_find_node_by_path("/memory");
 	if (!np) {
 		pr_warn("no memory node use default configuration\n");
 		goto not_found;
diff --git a/arch/ppc/mach-mpc5xxx/cpu.c b/arch/ppc/mach-mpc5xxx/cpu.c
index 99f16eb..0ece4a9 100644
--- a/arch/ppc/mach-mpc5xxx/cpu.c
+++ b/arch/ppc/mach-mpc5xxx/cpu.c
@@ -83,7 +83,7 @@ static int of_mpc5200_fixup(struct device_node *root)
 
 	int div = in_8((void*)CFG_MBAR + 0x204) & 0x0020 ? 8 : 4;
 
-	node = of_find_node_by_path(root, "/cpus/PowerPC,5200 at 0");
+	node = of_find_node_by_path("/cpus/PowerPC,5200 at 0");
 	if (!node)
 		return -EINVAL;
 
@@ -91,7 +91,7 @@ static int of_mpc5200_fixup(struct device_node *root)
 	of_property_write_u32(node, "bus-frequency", get_bus_clock());
 	of_property_write_u32(node, "clock-frequency", get_cpu_clock());
 
-	node = of_find_node_by_path(root, "/soc5200 at f0000000");
+	node = of_find_node_by_path("/soc5200 at f0000000");
 	if (!node)
 		return -EINVAL;
 
diff --git a/commands/of_node.c b/commands/of_node.c
index 0249d97..e60ef66 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -81,7 +81,7 @@ static int do_of_node(int argc, char *argv[])
 		if (!path)
 			return COMMAND_ERROR_USAGE;
 
-		node = of_find_node_by_path(root, path);
+		node = of_find_node_by_path(path);
 		if (!node) {
 			printf("Cannot find nodepath %s\n", path);
 			return -ENOENT;
diff --git a/commands/of_property.c b/commands/of_property.c
index d1a9a17..8ffe30b 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -175,7 +175,7 @@ static int do_of_property(int argc, char *argv[])
 	int set = 0;
 	int ret;
 	char *path = NULL, *propname = NULL;
-	struct device_node *root, *node = NULL;
+	struct device_node *node = NULL;
 	struct property *pp = NULL;
 
 	while ((opt = getopt(argc, argv, "ds")) > 0) {
@@ -194,15 +194,9 @@ static int do_of_property(int argc, char *argv[])
 	if (optind == argc)
 		return COMMAND_ERROR_USAGE;
 
-	root = of_get_root_node();
-	if (!root) {
-		printf("root node not set\n");
-		return -ENOENT;
-	}
-
 	if (optind < argc) {
 		path = argv[optind];
-		node = of_find_node_by_path(root, path);
+		node = of_find_node_by_path(path);
 		if (!node) {
 			printf("Cannot find nodepath %s\n", path);
 			return -ENOENT;
diff --git a/commands/oftree.c b/commands/oftree.c
index 468235a..9149517 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -164,16 +164,7 @@ static int do_oftree(int argc, char *argv[])
 			of_print_nodes(root, 0);
 			of_free(root);
 		} else {
-			struct device_node *root, *n;
-
-			root = of_get_root_node();
-			if (!root) {
-				ret = -ENOENT;
-				goto out;
-			}
-
-			n = of_find_node_by_path(root, node);
-
+			struct device_node *n = of_find_node_by_path(node);
 			if (!n) {
 				ret = -ENOENT;
 				goto out;
diff --git a/common/oftree.c b/common/oftree.c
index 475d418..aff4c28 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -100,7 +100,7 @@ void of_print_property(const void *data, int len)
 
 void of_print_cmdline(struct device_node *root)
 {
-	struct device_node *node = of_find_node_by_path(root, "/chosen");
+	struct device_node *node = of_find_node_by_path("/chosen");
 	const char *cmdline;
 
 	if (!node) {
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 85199b6..f822f8d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -153,7 +153,7 @@ void of_alias_scan(void)
 	if (!root_node)
 		return;
 
-	of_aliases = of_find_node_by_path(root_node, "/aliases");
+	of_aliases = of_find_node_by_path("/aliases");
 	if (!of_aliases)
 		return;
 
@@ -170,7 +170,7 @@ void of_alias_scan(void)
 		    !of_prop_cmp(pp->name, "linux,phandle"))
 			continue;
 
-		np = of_find_node_by_path(root_node, pp->value);
+		np = of_find_node_by_path(pp->value);
 		if (!np)
 			continue;
 
@@ -556,19 +556,18 @@ int of_machine_is_compatible(const char *compat)
 EXPORT_SYMBOL(of_machine_is_compatible);
 
 /**
- *	of_find_node_by_path - Find a node matching a full OF path
- *	@root:	The root node of this tree
+ *	of_find_node_by_path_from - Find a node matching a full OF path
+ *      relative to a given root node.
  *	@path:	The full path to match
  *
- *	Returns a node pointer with refcount incremented, use
- *	of_node_put() on it when done.
+ *	Returns a pointer to the node found or NULL.
  */
-struct device_node *of_find_node_by_path(struct device_node *root, const char *path)
+struct device_node *of_find_node_by_path_from(struct device_node *from,
+					const char *path)
 {
 	char *slash, *p, *freep;
-	struct device_node *dn = root;
 
-	if (*path != '/')
+	if (!from || !path || *path != '/')
 		return NULL;
 
 	path++;
@@ -583,8 +582,8 @@ struct device_node *of_find_node_by_path(struct device_node *root, const char *p
 		if (slash)
 			*slash = 0;
 
-		dn = of_find_child_by_name(dn, p);
-		if (!dn)
+		from = of_get_child_by_name(from, p);
+		if (!from)
 			goto out;
 
 		if (!slash)
@@ -595,7 +594,19 @@ struct device_node *of_find_node_by_path(struct device_node *root, const char *p
 out:
 	free(freep);
 
-	return dn;
+	return from;
+}
+EXPORT_SYMBOL(of_find_node_by_path_from);
+
+/**
+ *	of_find_node_by_path - Find a node matching a full OF path
+ *	@path:	The full path to match
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_by_path(const char *path)
+{
+	return of_find_node_by_path_from(root_node, path);
 }
 EXPORT_SYMBOL(of_find_node_by_path);
 
@@ -1156,12 +1167,12 @@ int of_probe(void)
 	if(!root_node)
 		return -ENODEV;
 
-	of_chosen = of_find_node_by_path(root_node, "/chosen");
+	of_chosen = of_find_node_by_path("/chosen");
 	of_property_read_string(root_node, "model", &of_model);
 
 	__of_parse_phandles(root_node);
 
-	memory = of_find_node_by_path(root_node, "/memory");
+	memory = of_find_node_by_path("/memory");
 	if (memory)
 		of_add_memory(memory, false);
 
@@ -1234,8 +1245,8 @@ int of_device_is_stdout_path(struct device_d *dev)
 	name = of_get_property(of_chosen, "linux,stdout-path", NULL);
 	if (name == NULL)
 		return 0;
-	dn = of_find_node_by_path(root_node, name);
 
+	dn = of_find_node_by_path(name);
 	if (!dn)
 		return 0;
 
@@ -1264,7 +1275,7 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 	struct device_node *chosen;
 	__be32 buf[2];
 
-	chosen = of_find_node_by_path(root, "/chosen");
+	chosen = of_find_node_by_path("/chosen");
 	if (!chosen)
 		return -EINVAL;
 
diff --git a/include/of.h b/include/of.h
index 7ebde62..a56587f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -67,8 +67,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 int of_n_addr_cells(struct device_node *np);
 int of_n_size_cells(struct device_node *np);
 
-struct device_node *of_find_node_by_path(struct device_node *root, const char *path);
-
 struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
 
 struct fdt_header *fdt_get_tree(void);
@@ -184,6 +182,10 @@ struct cdev;
 extern struct property *of_find_property(const struct device_node *np,
 					const char *name, int *lenp);
 
+extern struct device_node *of_find_node_by_path_from(struct device_node *from,
+						const char *path);
+extern struct device_node *of_find_node_by_path(const char *path);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -235,6 +237,17 @@ static inline struct property *of_find_property(const struct device_node *np,
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_by_path_from(
+	struct device_node *from, const char *path)
+{
+	return NULL;
+}
+
+static inline struct device_node *of_find_node_by_path(const char *path)
+{
+	return NULL;
+}
+
 static inline void of_alias_scan(void)
 {
 }
diff --git a/net/eth.c b/net/eth.c
index 7240b4d..09b3bd5 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -296,7 +296,7 @@ static int eth_of_fixup(struct device_node *root)
 			continue;
 		}
 
-		node = of_find_node_by_path(root, edev->nodepath);
+		node = of_find_node_by_path(edev->nodepath);
 		if (!node) {
 			dev_dbg(&edev->dev, "%s: fixup node %s not found\n",
 					__func__, edev->nodepath);
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:33 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:33 +0200
Subject: [PATCH v2 04/22] OF: base: export of_alias_scan
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-5-git-send-email-sebastian.hesselbarth@gmail.com>

To prepare clean-up of OF API, we need to export of_alias_scan.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |    3 ++-
 include/of.h      |   31 ++++++++++++++++++-------------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 616b93d..f3ed836 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -135,7 +135,7 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
  * the global lookup table with the properties.  It returns the
  * number of alias_prop found, or error code in error case.
  */
-static void of_alias_scan(void)
+void of_alias_scan(void)
 {
 	struct property *pp;
 	struct alias_prop *app, *tmp;
@@ -187,6 +187,7 @@ static void of_alias_scan(void)
 		of_alias_add(ap, np, id, start, len);
 	}
 }
+EXPORT_SYMBOL(of_alias_scan);
 
 /**
  * of_alias_get_id - Get alias id for the given device_node
diff --git a/include/of.h b/include/of.h
index 300b706..8a69793 100644
--- a/include/of.h
+++ b/include/of.h
@@ -178,10 +178,11 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
 struct cdev;
 
 #ifdef CONFIG_OFTREE
-int of_parse_partitions(struct cdev *cdev, struct device_node *node);
+extern void of_alias_scan(void);
+extern int of_alias_get_id(struct device_node *np, const char *stem);
+extern const char *of_alias_get(struct device_node *np);
 
-int of_alias_get_id(struct device_node *np, const char *stem);
-const char *of_alias_get(struct device_node *np);
+int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
 void *of_flatten_dtb(struct device_node *node);
@@ -196,16 +197,6 @@ static inline int of_parse_partitions(struct cdev *cdev,
 	return -EINVAL;
 }
 
-static inline int of_alias_get_id(struct device_node *np, const char *stem)
-{
-	return -ENOENT;
-}
-
-static inline const char *of_alias_get(struct device_node *np)
-{
-	return NULL;
-}
-
 static inline int of_device_is_stdout_path(struct device_d *dev)
 {
 	return 0;
@@ -230,6 +221,20 @@ static inline struct device_node *of_get_root_node(void)
 {
 	return NULL;
 }
+
+static inline void of_alias_scan(void)
+{
+}
+
+static inline int of_alias_get_id(struct device_node *np, const char *stem)
+{
+	return -ENOSYS;
+}
+
+static inline const char *of_alias_get(struct device_node *np)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:40 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:40 +0200
Subject: [PATCH v2 11/22] OF: base: import of_find_matching_node_and_match
 from Linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-12-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_find_matching_node_and_match and corresponding helpers
from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   37 +++++++++++++++++++++++++++++++++++++
 include/of.h      |   24 ++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 50a4df0..38d6789 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -389,6 +389,43 @@ const struct of_device_id *of_match_node(const struct of_device_id *matches,
 	return NULL;
 }
 
+/**
+ *	of_find_matching_node_and_match - Find a node based on an of_device_id
+ *					  match table.
+ *	@from:		The node to start searching from or NULL, the node
+ *			you pass will not be searched, only the next one
+ *			will; typically, you pass what the previous call
+ *			returned.
+ *	@matches:	array of of device match structures to search in
+ *	@match		Updated to point at the matches entry which matched
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_matching_node_and_match(struct device_node *from,
+					const struct of_device_id *matches,
+					const struct of_device_id **match)
+{
+	struct device_node *np;
+
+	if (match)
+		*match = NULL;
+
+	if (!from)
+		from = root_node;
+
+	of_tree_for_each_node(np, from) {
+		const struct of_device_id *m = of_match_node(matches, np);
+		if (m) {
+			if (match)
+				*match = m;
+			return np;
+		}
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_matching_node_and_match);
+
 int of_match(struct device_d *dev, struct driver_d *drv)
 {
 	const struct of_device_id *id;
diff --git a/include/of.h b/include/of.h
index b334e3a..a33ccfa 100644
--- a/include/of.h
+++ b/include/of.h
@@ -189,6 +189,10 @@ extern struct device_node *of_find_node_by_path_from(struct device_node *from,
 extern struct device_node *of_find_node_by_path(const char *path);
 extern struct device_node *of_find_compatible_node(struct device_node *from,
 	const char *type, const char *compat);
+extern struct device_node *of_find_matching_node_and_match(
+	struct device_node *from,
+	const struct of_device_id *matches,
+	const struct of_device_id **match);
 extern int of_device_is_available(const struct device_node *device);
 
 extern void of_alias_scan(void);
@@ -267,6 +271,14 @@ static inline struct device_node *of_find_compatible_node(
 	return NULL;
 }
 
+static inline struct device_node *of_find_matching_node_and_match(
+					struct device_node *from,
+					const struct of_device_id *matches,
+					const struct of_device_id **match)
+{
+	return NULL;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -293,5 +305,17 @@ static inline const char *of_alias_get(struct device_node *np)
 #define for_each_compatible_node(dn, type, compatible) \
 	for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
 	     dn = of_find_compatible_node(dn, type, compatible))
+static inline struct device_node *of_find_matching_node(
+	struct device_node *from,
+	const struct of_device_id *matches)
+{
+	return of_find_matching_node_and_match(from, matches, NULL);
+}
+#define for_each_matching_node(dn, matches) \
+	for (dn = of_find_matching_node(NULL, matches); dn; \
+	     dn = of_find_matching_node(dn, matches))
+#define for_each_matching_node_and_match(dn, matches, match) \
+	for (dn = of_find_matching_node_and_match(NULL, matches, match); \
+	     dn; dn = of_find_matching_node_and_match(dn, matches, match))
 
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:41 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:41 +0200
Subject: [PATCH v2 12/22] OF: base: import of_find_node_with_property from
 Linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-13-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_find_node_with_property and corresponding helpers
from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   26 ++++++++++++++++++++++++++
 include/of.h      |   11 +++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 38d6789..39eddb2 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -368,6 +368,32 @@ struct device_node *of_find_compatible_node(struct device_node *from,
 EXPORT_SYMBOL(of_find_compatible_node);
 
 /**
+ *	of_find_node_with_property - Find a node which has a property with
+ *                                   the given name.
+ *	@from:		The node to start searching from or NULL, the node
+ *			you pass will not be searched, only the next one
+ *			will; typically, you pass what the previous call
+ *			returned.
+ *	@prop_name:	The name of the property to look for.
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_node_with_property(struct device_node *from,
+	const char *prop_name)
+{
+	struct device_node *np;
+
+	of_tree_for_each_node(np, from) {
+		struct property *pp = of_find_property(np, prop_name, NULL);
+		if (pp)
+			return np;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_node_with_property);
+
+/**
  * of_match_node - Tell if an device_node has a matching of_match structure
  *      @matches:       array of of device match structures to search in
  *      @node:          the of device structure to match against
diff --git a/include/of.h b/include/of.h
index a33ccfa..f508435 100644
--- a/include/of.h
+++ b/include/of.h
@@ -193,6 +193,8 @@ extern struct device_node *of_find_matching_node_and_match(
 	struct device_node *from,
 	const struct of_device_id *matches,
 	const struct of_device_id **match);
+extern struct device_node *of_find_node_with_property(
+	struct device_node *from, const char *prop_name);
 extern int of_device_is_available(const struct device_node *device);
 
 extern void of_alias_scan(void);
@@ -279,6 +281,12 @@ static inline struct device_node *of_find_matching_node_and_match(
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_with_property(
+			struct device_node *from, const char *prop_name)
+{
+	return NULL;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -317,5 +325,8 @@ static inline struct device_node *of_find_matching_node(
 #define for_each_matching_node_and_match(dn, matches, match) \
 	for (dn = of_find_matching_node_and_match(NULL, matches, match); \
 	     dn; dn = of_find_matching_node_and_match(dn, matches, match))
+#define for_each_node_with_property(dn, prop_name) \
+	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
+	     dn = of_find_node_with_property(dn, prop_name))
 
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:37 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:37 +0200
Subject: [PATCH v2 08/22] OF: base: rename of_node_disabled to
 of_device_is_available
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-9-git-send-email-sebastian.hesselbarth@gmail.com>

According to ePAPR 1.1 spec, device tree nodes status can be either
"okay", "disabled", "fail", or "fail-sss". Barebox already has a function
to check for "disabled" nodes, while Linux checks for "okay" or "ok".
To synchronize Barebox and Linux OF APIs, rename of_node_disabled to
of_device_is_available and check for "okay" instead of "disabled" as it
also makes "fail"ed devices unavailable.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   26 ++++++++++++++++++++------
 include/of.h      |    6 ++++++
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index f822f8d..2176251 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -730,17 +730,31 @@ int of_set_root_node(struct device_node *node)
 	return 0;
 }
 
-static int of_node_disabled(struct device_node *node)
+/**
+ *  of_device_is_available - check if a device is available for use
+ *
+ *  @device: Node to check for availability
+ *
+ *  Returns 1 if the status property is absent or set to "okay" or "ok",
+ *  0 otherwise
+ */
+int of_device_is_available(const struct device_node *device)
 {
-	struct property *p;
+	const char *status;
+	int statlen;
+
+	status = of_get_property(device, "status", &statlen);
+	if (status == NULL)
+		return 1;
 
-	p = of_find_property(node, "status", NULL);
-	if (p) {
-		if (!strcmp("disabled", p->value))
+	if (statlen > 0) {
+		if (!strcmp(status, "okay") || !strcmp(status, "ok"))
 			return 1;
 	}
+
 	return 0;
 }
+EXPORT_SYMBOL(of_device_is_available);
 
 void of_print_nodes(struct device_node *node, int indent)
 {
@@ -934,7 +948,7 @@ static struct device_d *add_of_device(struct device_node *node,
 {
 	const struct property *cp;
 
-	if (of_node_disabled(node))
+	if (!of_device_is_available(node))
 		return NULL;
 
 	cp = of_get_property(node, "compatible", NULL);
diff --git a/include/of.h b/include/of.h
index a56587f..56b7be1 100644
--- a/include/of.h
+++ b/include/of.h
@@ -185,6 +185,7 @@ extern struct property *of_find_property(const struct device_node *np,
 extern struct device_node *of_find_node_by_path_from(struct device_node *from,
 						const char *path);
 extern struct device_node *of_find_node_by_path(const char *path);
+extern int of_device_is_available(const struct device_node *device);
 
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -248,6 +249,11 @@ static inline struct device_node *of_find_node_by_path(const char *path)
 	return NULL;
 }
 
+static inline int of_device_is_available(const struct device_node *device)
+{
+	return 0;
+}
+
 static inline void of_alias_scan(void)
 {
 }
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:39 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:39 +0200
Subject: [PATCH v2 10/22] OF: base: import of_find_compatible_node from Linux
 OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-11-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_find_compatible_node and corresponding for_each_compatible_node
helper from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   30 ++++++++++++++++++++++++++++++
 include/of.h      |   13 +++++++++++++
 2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index d736bef..50a4df0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -338,6 +338,36 @@ struct device_node *of_find_node_by_name(struct device_node *from,
 EXPORT_SYMBOL(of_find_node_by_name);
 
 /**
+ *	of_find_compatible_node - Find a node based on type and one of the
+ *                                tokens in its "compatible" property
+ *	@from:		The node to start searching from or NULL, the node
+ *			you pass will not be searched, only the next one
+ *			will; typically, you pass what the previous call
+ *			returned.
+ *	@type:		The type string to match "device_type" or NULL to ignore
+ *                      (currently always ignored in barebox)
+ *	@compatible:	The string to match to one of the tokens in the device
+ *			"compatible" list.
+ *
+ *	Returns a pointer to the node found or NULL.
+ */
+struct device_node *of_find_compatible_node(struct device_node *from,
+	const char *type, const char *compatible)
+{
+	struct device_node *np;
+
+	if (!from)
+		from = root_node;
+
+	of_tree_for_each_node(np, from)
+		if (of_device_is_compatible(np, compatible))
+			return np;
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_compatible_node);
+
+/**
  * of_match_node - Tell if an device_node has a matching of_match structure
  *      @matches:       array of of device match structures to search in
  *      @node:          the of device structure to match against
diff --git a/include/of.h b/include/of.h
index 8cbfe7a..b334e3a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -187,6 +187,8 @@ extern struct device_node *of_find_node_by_name(struct device_node *from,
 extern struct device_node *of_find_node_by_path_from(struct device_node *from,
 						const char *path);
 extern struct device_node *of_find_node_by_path(const char *path);
+extern struct device_node *of_find_compatible_node(struct device_node *from,
+	const char *type, const char *compat);
 extern int of_device_is_available(const struct device_node *device);
 
 extern void of_alias_scan(void);
@@ -257,6 +259,14 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
 	return NULL;
 }
 
+static inline struct device_node *of_find_compatible_node(
+						struct device_node *from,
+						const char *type,
+						const char *compat)
+{
+	return NULL;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -280,5 +290,8 @@ static inline const char *of_alias_get(struct device_node *np)
 #define for_each_node_by_name(dn, name) \
 	for (dn = of_find_node_by_name(NULL, name); dn; \
 	     dn = of_find_node_by_name(dn, name))
+#define for_each_compatible_node(dn, type, compatible) \
+	for (dn = of_find_compatible_node(NULL, type, compatible); dn; \
+	     dn = of_find_compatible_node(dn, type, compatible))
 
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:49 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:49 +0200
Subject: [PATCH v2 20/22] OF: base: remove of_find_child_by_name
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-21-git-send-email-sebastian.hesselbarth@gmail.com>

With of_get_child_by_name from Linux API, we can now convert and remove
of_find_child_by_name.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 arch/arm/boards/at91sam9x5ek/hw_version.c |    2 +-
 drivers/of/base.c                         |   13 +------------
 drivers/of/fdt.c                          |    9 +++++----
 include/of.h                              |    2 --
 4 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 426bd35..1207a3e 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -236,7 +236,7 @@ static int cm_cogent_fixup(struct device_node *root)
 
 	for_each_compatible_node(node, NULL, "atmel,hsmci") {
 		struct device_node *slotnode =
-			of_find_child_by_name(node, "slot");
+			of_get_child_by_name(node, "slot");
 		if (!slotnode)
 			continue;
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index c8497f4..1b351ee 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1905,17 +1905,6 @@ int of_probe(void)
 	return 0;
 }
 
-struct device_node *of_find_child_by_name(struct device_node *node, const char *name)
-{
-	struct device_node *_n;
-
-	device_node_for_nach_child(node, _n)
-		if (!of_node_cmp(_n->name, name))
-			return _n;
-
-	return NULL;
-}
-
 /**
  * of_create_node - create a new node including its parents
  * @path - the nodepath to create
@@ -1940,7 +1929,7 @@ struct device_node *of_create_node(struct device_node *root, const char *path)
 		if (slash)
 			*slash = 0;
 
-		tmp = of_find_child_by_name(dn, p);
+		tmp = of_get_child_by_name(dn, p);
 		if (tmp)
 			dn = tmp;
 		else
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index a76396e..afaa4e0 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -61,7 +61,7 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
 	int  len;		/* length of the property */
 	const struct fdt_property *fdt_prop;
 	const char *pathp, *name;
-	struct device_node *node = NULL, *n;
+	struct device_node *node = NULL;
 	struct property *p;
 	uint32_t dt_struct;
 	struct fdt_node_header *fnh;
@@ -135,9 +135,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
 			if (!node) {
 				node = root;
 			} else {
-				if (merge && (n = of_find_child_by_name(node, pathp)))
-					node = n;
-				else
+				if (merge)
+					node = of_get_child_by_name(node,
+								    pathp);
+				if (!merge || !node)
 					node = of_new_node(node, pathp);
 			}
 
diff --git a/include/of.h b/include/of.h
index 2ef00be..c3bcabe 100644
--- a/include/of.h
+++ b/include/of.h
@@ -74,8 +74,6 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
 int of_n_addr_cells(struct device_node *np);
 int of_n_size_cells(struct device_node *np);
 
-struct device_node *of_find_child_by_name(struct device_node *node, const char *name);
-
 struct fdt_header *fdt_get_tree(void);
 
 struct fdt_header *of_get_fixed_tree(struct device_node *node);
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:47 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:47 +0200
Subject: [PATCH v2 18/22] OF: base: import property iterators from Linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-19-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_prop_next_u32, of_prop_next_string, and the corresponding
for_property_for_each_ helpers from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   41 +++++++++++++++++++++++++++++++++++++++++
 include/of.h      |   43 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index bf73acb..3e7a488 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -797,6 +797,47 @@ int of_property_count_strings(struct device_node *np, const char *propname)
 }
 EXPORT_SYMBOL_GPL(of_property_count_strings);
 
+const __be32 *of_prop_next_u32(struct property *prop, const __be32 *cur,
+			u32 *pu)
+{
+	const void *curv = cur;
+
+	if (!prop)
+		return NULL;
+
+	if (!cur) {
+		curv = prop->value;
+		goto out_val;
+	}
+
+	curv += sizeof(*cur);
+	if (curv >= prop->value + prop->length)
+		return NULL;
+
+out_val:
+	*pu = be32_to_cpup(curv);
+	return curv;
+}
+EXPORT_SYMBOL_GPL(of_prop_next_u32);
+
+const char *of_prop_next_string(struct property *prop, const char *cur)
+{
+	const void *curv = cur;
+
+	if (!prop)
+		return NULL;
+
+	if (!cur)
+		return prop->value;
+
+	curv += strlen(cur) + 1;
+	if (curv >= prop->value + prop->length)
+		return NULL;
+
+	return curv;
+}
+EXPORT_SYMBOL_GPL(of_prop_next_string);
+
 /**
  * of_property_write_bool - Create/Delete empty (bool) property.
  *
diff --git a/include/of.h b/include/of.h
index 6abd906..30b5be5 100644
--- a/include/of.h
+++ b/include/of.h
@@ -207,6 +207,10 @@ extern int of_property_match_string(struct device_node *np,
 extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 
+extern const __be32 *of_prop_next_u32(struct property *prop,
+				const __be32 *cur, u32 *pu);
+extern const char *of_prop_next_string(struct property *prop, const char *cur);
+
 extern int of_property_write_bool(struct device_node *np,
 				const char *propname, const bool value);
 extern int of_property_write_u8_array(struct device_node *np,
@@ -363,6 +367,18 @@ static inline int of_property_count_strings(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline const __be32 *of_prop_next_u32(struct property *prop,
+					const __be32 *cur, u32 *pu)
+{
+	return 0;
+}
+
+static inline const char *of_prop_next_string(struct property *prop,
+					const char *cur)
+{
+	return NULL;
+}
+
 static inline int of_property_write_bool(struct device_node *np,
 				const char *propname, const bool value)
 {
@@ -536,6 +552,33 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+/*
+ * struct property *prop;
+ * const __be32 *p;
+ * u32 u;
+ *
+ * of_property_for_each_u32(np, "propname", prop, p, u)
+ *         printk("U32 value: %x\n", u);
+ */
+#define of_property_for_each_u32(np, propname, prop, p, u)	\
+	for (prop = of_find_property(np, propname, NULL),	\
+		p = of_prop_next_u32(prop, NULL, &u);		\
+		p;						\
+		p = of_prop_next_u32(prop, p, &u))
+
+/*
+ * struct property *prop;
+ * const char *s;
+ *
+ * of_property_for_each_string(np, "propname", prop, s)
+ *         printk("String value: %s\n", s);
+ */
+#define of_property_for_each_string(np, propname, prop, s)	\
+	for (prop = of_find_property(np, propname, NULL),	\
+		s = of_prop_next_string(prop, NULL);		\
+		s;						\
+		s = of_prop_next_string(prop, s))
+
 static inline int of_property_write_u8(struct device_node *np,
 				       const char *propname, u8 value)
 {
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:44 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:44 +0200
Subject: [PATCH v2 15/22] OF: base: import of_parse_phandle from Linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-16-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_parse_phandle from Linux OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   23 +++++++++++++++++++++++
 include/of.h      |   10 ++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index d58ba4d..486758b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -839,6 +839,29 @@ int of_property_write_u32_array(struct device_node *np,
 }
 
 /**
+ * of_parse_phandle - Resolve a phandle property to a device_node pointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ *         the table
+ *
+ * Returns the device_node pointer found or NULL.
+ */
+struct device_node *of_parse_phandle(const struct device_node *np,
+				     const char *phandle_name, int index)
+{
+	const __be32 *phandle;
+	int size;
+
+	phandle = of_get_property(np, phandle_name, &size);
+	if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
+		return NULL;
+
+	return of_find_node_by_phandle(be32_to_cpup(phandle + index));
+}
+EXPORT_SYMBOL(of_parse_phandle);
+
+/**
  * of_parse_phandles_with_args - Find a node pointed by phandle in a list
  * @np:		pointer to a device tree node containing a list
  * @list_name:	property name that contains a list
diff --git a/include/of.h b/include/of.h
index d94527d..4f5470a 100644
--- a/include/of.h
+++ b/include/of.h
@@ -216,6 +216,10 @@ extern int of_property_match_string(struct device_node *np,
 extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 
+extern struct device_node *of_parse_phandle(const struct device_node *np,
+					    const char *phandle_name,
+					    int index);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -348,6 +352,12 @@ static inline int of_property_count_strings(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline struct device_node *of_parse_phandle(const struct device_node *np,
+					    const char *phandle_name, int index)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_find_node_by_path_from(
 	struct device_node *from, const char *path)
 {
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:46 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:46 +0200
Subject: [PATCH v2 17/22] OF: base: introduce property write for bool, u8, u16,
 and u64
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-18-git-send-email-sebastian.hesselbarth@gmail.com>

This adds functions to set an array of or a single value for bool,
u8, u16, and u64 properties.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |  156 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h      |   82 ++++++++++++++++++++++++----
 2 files changed, 227 insertions(+), 11 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1c385c8..bf73acb 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -798,6 +798,119 @@ int of_property_count_strings(struct device_node *np, const char *propname)
 EXPORT_SYMBOL_GPL(of_property_count_strings);
 
 /**
+ * of_property_write_bool - Create/Delete empty (bool) property.
+ *
+ * @np:		device node from which the property is to be set.
+ * @propname:	name of the property to be set.
+ *
+ * Search for a property in a device node and create or delete the property.
+ * If the property already exists and write value is false, the property is
+ * deleted. If write value is true and the property does not exist, it is
+ * created. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_bool(struct device_node *np, const char *propname,
+			   const bool value)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+
+	if (!value) {
+		if (prop)
+			of_delete_property(prop);
+		return 0;
+	}
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	return 0;
+}
+
+/**
+ * of_property_write_u8_array - Write an array of u8 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np:		device node to which the property value is to be written.
+ * @propname:	name of the property to be written.
+ * @values:	pointer to array elements to write.
+ * @sz:		number of array elements to write.
+ *
+ * Search for a property in a device node and write 8-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u8_array(struct device_node *np,
+			       const char *propname, const u8 *values,
+			       size_t sz)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	u8 *val;
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	free(prop->value);
+
+	prop->length = sizeof(*val) * sz;
+	prop->value = malloc(prop->length);
+	if (!prop->value)
+		return -ENOMEM;
+
+	val = prop->value;
+	while (sz--)
+		*val++ = *values++;
+
+	return 0;
+}
+
+/**
+ * of_property_write_u16_array - Write an array of u16 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np:		device node to which the property value is to be written.
+ * @propname:	name of the property to be written.
+ * @values:	pointer to array elements to write.
+ * @sz:		number of array elements to write.
+ *
+ * Search for a property in a device node and write 16-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u16_array(struct device_node *np,
+				const char *propname, const u16 *values,
+				size_t sz)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	__be16 *val;
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	free(prop->value);
+
+	prop->length = sizeof(*val) * sz;
+	prop->value = malloc(prop->length);
+	if (!prop->value)
+		return -ENOMEM;
+
+	val = prop->value;
+	while (sz--)
+		*val++ = cpu_to_be16(*values++);
+
+	return 0;
+}
+
+/**
  * of_property_write_u32_array - Write an array of u32 to a property. If
  * the property does not exist, it will be created and appended to the given
  * device node.
@@ -839,6 +952,49 @@ int of_property_write_u32_array(struct device_node *np,
 }
 
 /**
+ * of_property_write_u64_array - Write an array of u64 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np:		device node to which the property value is to be written.
+ * @propname:	name of the property to be written.
+ * @values:	pointer to array elements to write.
+ * @sz:		number of array elements to write.
+ *
+ * Search for a property in a device node and write 64-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
+int of_property_write_u64_array(struct device_node *np,
+				const char *propname, const u64 *values,
+				size_t sz)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	__be32 *val;
+
+	if (!prop)
+		prop = of_new_property(np, propname, NULL, 0);
+	if (!prop)
+		return -ENOMEM;
+
+	free(prop->value);
+
+	prop->length = 2 * sizeof(*val) * sz;
+	prop->value = malloc(prop->length);
+	if (!prop->value)
+		return -ENOMEM;
+
+	val = prop->value;
+	while (sz--) {
+		of_write_number(val, *values++, 2);
+		val += 2;
+	}
+
+	return 0;
+}
+
+/**
  * of_parse_phandle - Resolve a phandle property to a device_node pointer
  * @np: Pointer to device node holding phandle property
  * @phandle_name: Name of property holding a phandle value
diff --git a/include/of.h b/include/of.h
index e03bd40..6abd906 100644
--- a/include/of.h
+++ b/include/of.h
@@ -113,17 +113,6 @@ static inline void of_write_number(void *__cell, u64 val, int size)
 	}
 }
 
-int of_property_write_u32_array(struct device_node *np,
-				const char *propname, const u32 *values,
-				size_t sz);
-
-static inline int of_property_write_u32(struct device_node *np,
-					const char *propname,
-					u32 value)
-{
-	return of_property_write_u32_array(np, propname, &value, 1);
-}
-
 const void *of_get_property(const struct device_node *np, const char *name,
 			 int *lenp);
 
@@ -218,6 +207,21 @@ extern int of_property_match_string(struct device_node *np,
 extern int of_property_count_strings(struct device_node *np,
 				     const char *propname);
 
+extern int of_property_write_bool(struct device_node *np,
+				const char *propname, const bool value);
+extern int of_property_write_u8_array(struct device_node *np,
+				const char *propname, const u8 *values,
+				size_t sz);
+extern int of_property_write_u16_array(struct device_node *np,
+				const char *propname, const u16 *values,
+				size_t sz);
+extern int of_property_write_u32_array(struct device_node *np,
+				const char *propname, const u32 *values,
+				size_t sz);
+extern int of_property_write_u64_array(struct device_node *np,
+				const char *propname, const u64 *values,
+				size_t sz);
+
 extern struct device_node *of_parse_phandle(const struct device_node *np,
 					    const char *phandle_name,
 					    int index);
@@ -359,6 +363,36 @@ static inline int of_property_count_strings(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline int of_property_write_bool(struct device_node *np,
+				const char *propname, const bool value)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_write_u8_array(struct device_node *np,
+			const char *propname, const u8 *values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_write_u16_array(struct device_node *np,
+			const char *propname, const u16 *values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_write_u32_array(struct device_node *np,
+			const char *propname, const u32 *values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_write_u64_array(struct device_node *np,
+			const char *propname, const u64 *values, size_t sz)
+{
+	return -ENOSYS;
+}
+
 static inline struct device_node *of_parse_phandle(const struct device_node *np,
 					    const char *phandle_name, int index)
 {
@@ -502,4 +536,30 @@ static inline int of_property_read_u32(const struct device_node *np,
 	return of_property_read_u32_array(np, propname, out_value, 1);
 }
 
+static inline int of_property_write_u8(struct device_node *np,
+				       const char *propname, u8 value)
+{
+	return of_property_write_u8_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u16(struct device_node *np,
+					const char *propname, u16 value)
+{
+	return of_property_write_u16_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u32(struct device_node *np,
+					const char *propname,
+					u32 value)
+{
+	return of_property_write_u32_array(np, propname, &value, 1);
+}
+
+static inline int of_property_write_u64(struct device_node *np,
+					const char *propname,
+					u64 value)
+{
+	return of_property_write_u64_array(np, propname, &value, 1);
+}
+
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:50 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:50 +0200
Subject: [PATCH v2 21/22] OF: base: convert and remove
 device_node_for_nach_child
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-22-git-send-email-sebastian.hesselbarth@gmail.com>

Remove device_node_for_nach_child and convert users to corresponding
imported OF API functions.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/i2c/i2c.c       |    2 +-
 drivers/mfd/stmpe-i2c.c |    7 ++-----
 drivers/of/partition.c  |    2 +-
 drivers/spi/spi.c       |    2 +-
 include/of.h            |    3 ---
 5 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index b63d946..3e09547 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -278,7 +278,7 @@ void of_i2c_register_devices(struct i2c_adapter *adap)
 	if (!IS_ENABLED(CONFIG_OFDEVICE) || !adap->dev.device_node)
 		return;
 
-	device_node_for_nach_child(adap->dev.device_node, n) {
+	for_each_child_of_node(adap->dev.device_node, n) {
 		struct i2c_board_info info = {};
 		struct i2c_client *result;
 		const __be32 *addr;
diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
index d785430..c505bc1 100644
--- a/drivers/mfd/stmpe-i2c.c
+++ b/drivers/mfd/stmpe-i2c.c
@@ -116,11 +116,8 @@ static struct stmpe_platform_data *stmpe_of_probe(struct device_d *dev)
 
 	pdata = xzalloc(sizeof(*pdata));
 
-	device_node_for_nach_child(dev->device_node, node) {
-		if (!strcmp(node->name, "stmpe_gpio")) {
-			pdata->blocks |= STMPE_BLOCK_GPIO;
-		}
-	}
+	if (of_get_child_by_name(dev->device_node, "stmpe_gpio"))
+		pdata->blocks |= STMPE_BLOCK_GPIO;
 
 	return pdata;
 }
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 2d70cf5..e4b7d1e 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -29,7 +29,7 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node)
 	const char *partname;
 	char *filename;
 
-	device_node_for_nach_child(node, n) {
+	for_each_child_of_node(node, n) {
 		const __be32 *reg;
 		unsigned long offset, size;
 		const char *name;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index eebf64c..5d4dfd6 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -107,7 +107,7 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
 	struct spi_board_info chip;
 	struct property *reg;
 
-	device_node_for_nach_child(node, n) {
+	for_each_child_of_node(node, n) {
 		memset(&chip, 0, sizeof(chip));
 		chip.name = xstrdup(n->name);
 		chip.bus_num = master->bus_num;
diff --git a/include/of.h b/include/of.h
index c3bcabe..c61d002 100644
--- a/include/of.h
+++ b/include/of.h
@@ -80,9 +80,6 @@ struct fdt_header *of_get_fixed_tree(struct device_node *node);
 
 int of_modalias_node(struct device_node *node, char *modalias, int len);
 
-#define device_node_for_nach_child(node, child) \
-	list_for_each_entry(child, &node->children, parent_list)
-
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:42 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:42 +0200
Subject: [PATCH v2 13/22] OF: base: import parent/child functions from Linux
 OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-14-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_get_parent, of_get_next_available_child, and
of_get_child_by_name and corresponding helpers from Linux OF API.
of_get_next_child is not imported but implemented as list iterator
instead. Also, of_get_child_count and of_get_available_child_count
are introduced.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org

Changelog:
v1->v2:
- make of_get_parent return node->parent also for root_node
  (Suggested by Sascha Hauer)
- use list iterator instead of of_get_next_child
  (Suggested by Sascha Hauer)
- move of_get_child_count to base.c to avoid compile warnings
- introduce of_get_available_child_count
---
 drivers/of/base.c |   97 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h      |   41 ++++++++++++++++++++++
 2 files changed, 138 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 39eddb2..ee0496d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -875,6 +875,103 @@ int of_device_is_available(const struct device_node *device)
 }
 EXPORT_SYMBOL(of_device_is_available);
 
+/**
+ *	of_get_parent - Get a node's parent if any
+ *	@node:	Node to get parent
+ *
+ *	Returns a pointer to the parent node or NULL if already at root.
+ */
+struct device_node *of_get_parent(const struct device_node *node)
+{
+	return (!node) ? NULL : node->parent;
+}
+EXPORT_SYMBOL(of_get_parent);
+
+/**
+ *	of_get_next_available_child - Find the next available child node
+ *	@node:	parent node
+ *	@prev:	previous child of the parent node, or NULL to get first
+ *
+ *      This function is like of_get_next_child(), except that it
+ *      automatically skips any disabled nodes (i.e. status = "disabled").
+ */
+struct device_node *of_get_next_available_child(const struct device_node *node,
+	struct device_node *prev)
+{
+	for_each_child_of_node(node, prev)
+		if (of_device_is_available(prev))
+			return prev;
+	return NULL;
+}
+EXPORT_SYMBOL(of_get_next_available_child);
+
+/**
+ *	of_get_child_count - Count child nodes of given parent node
+ *	@parent:	parent node
+ *
+ *      Returns the number of child nodes or -EINVAL on NULL parent node.
+ */
+int of_get_child_count(const struct device_node *parent)
+{
+	struct device_node *child;
+	int num = 0;
+
+	if (!parent)
+		return -EINVAL;
+
+	for_each_child_of_node(parent, child)
+		num++;
+
+	return num;
+}
+EXPORT_SYMBOL(of_get_child_count);
+
+/**
+ *	of_get_available_child_count - Count available child nodes of given
+ *      parent node
+ *	@parent:	parent node
+ *
+ *      Returns the number of available child nodes or -EINVAL on NULL parent
+ *      node.
+ */
+int of_get_available_child_count(const struct device_node *parent)
+{
+	struct device_node *child;
+	int num = 0;
+
+	if (!parent)
+		return -EINVAL;
+
+	for_each_child_of_node(parent, child)
+		if (of_device_is_available(child))
+			num++;
+
+	return num;
+}
+EXPORT_SYMBOL(of_get_available_child_count);
+
+/**
+ *	of_get_child_by_name - Find the child node by name for a given parent
+ *	@node:	parent node
+ *	@name:	child name to look for.
+ *
+ *      This function looks for child node for given matching name
+ *
+ *	Returns a node pointer if found or NULL.
+ */
+struct device_node *of_get_child_by_name(const struct device_node *node,
+				const char *name)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(node, child)
+		if (child->name && (of_node_cmp(child->name, name) == 0))
+			return child;
+
+	return NULL;
+}
+EXPORT_SYMBOL(of_get_child_by_name);
+
 void of_print_nodes(struct device_node *node, int indent)
 {
 	struct device_node *n;
diff --git a/include/of.h b/include/of.h
index f508435..917466f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -197,6 +197,14 @@ extern struct device_node *of_find_node_with_property(
 	struct device_node *from, const char *prop_name);
 extern int of_device_is_available(const struct device_node *device);
 
+extern struct device_node *of_get_parent(const struct device_node *node);
+extern struct device_node *of_get_next_available_child(
+	const struct device_node *node, struct device_node *prev);
+extern int of_get_child_count(const struct device_node *parent);
+extern int of_get_available_child_count(const struct device_node *parent);
+extern struct device_node *of_get_child_by_name(const struct device_node *node,
+					const char *name);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -241,6 +249,33 @@ static inline struct device_node *of_get_root_node(void)
 	return NULL;
 }
 
+static inline struct device_node *of_get_parent(const struct device_node *node)
+{
+	return NULL;
+}
+
+static inline struct device_node *of_get_next_available_child(
+		const struct device_node *node, struct device_node *prev)
+{
+	return NULL;
+}
+
+static inline int of_get_child_count(const struct device_node *parent)
+{
+	return -ENOSYS;
+}
+
+static inline int of_get_available_child_count(const struct device_node *parent)
+{
+	return -ENOSYS;
+}
+
+static inline struct device_node *of_get_child_by_name(
+			const struct device_node *node, const char *name)
+{
+	return NULL;
+}
+
 static inline struct property *of_find_property(const struct device_node *np,
 						const char *name,
 						int *lenp)
@@ -329,4 +364,10 @@ static inline struct device_node *of_find_matching_node(
 	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
 	     dn = of_find_node_with_property(dn, prop_name))
 
+#define for_each_child_of_node(parent, child) \
+	list_for_each_entry(child, &parent->children, parent_list)
+#define for_each_available_child_of_node(parent, child) \
+	for (child = of_get_next_available_child(parent, NULL); child != NULL; \
+	     child = of_get_next_available_child(parent, child))
+
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:51 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:51 +0200
Subject: [PATCH v2 22/22] OF: base: cleanup base function include
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-23-git-send-email-sebastian.hesselbarth@gmail.com>

This cleans up include/of.h by moving some function prototypes below
CONFIG_OFTREE and provide bogus stubs for !CONFIG_OFTREE.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 include/of.h |  138 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 109 insertions(+), 29 deletions(-)

diff --git a/include/of.h b/include/of.h
index c61d002..b392ca9 100644
--- a/include/of.h
+++ b/include/of.h
@@ -71,15 +71,10 @@ int of_match(struct device_d *dev, struct driver_d *drv);
 int of_add_initrd(struct device_node *root, resource_size_t start,
 		resource_size_t end);
 
-int of_n_addr_cells(struct device_node *np);
-int of_n_size_cells(struct device_node *np);
-
 struct fdt_header *fdt_get_tree(void);
 
 struct fdt_header *of_get_fixed_tree(struct device_node *node);
 
-int of_modalias_node(struct device_node *node, char *modalias, int len);
-
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
@@ -100,21 +95,12 @@ static inline void of_write_number(void *__cell, u64 val, int size)
 	}
 }
 
-const void *of_get_property(const struct device_node *np, const char *name,
-			 int *lenp);
-
 int of_get_named_gpio(struct device_node *np,
                                    const char *propname, int index);
 
-struct device_node *of_find_node_by_phandle(phandle phandle);
 void of_print_property(const void *data, int len);
 void of_print_cmdline(struct device_node *root);
 
-int of_device_is_compatible(const struct device_node *device,
-		const char *compat);
-
-int of_machine_is_compatible(const char *compat);
-
 u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
 
 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
@@ -123,41 +109,51 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
 void of_print_nodes(struct device_node *node, int indent);
 int of_probe(void);
 int of_parse_dtb(struct fdt_header *fdt);
-void of_free(struct device_node *node);
 struct device_node *of_unflatten_dtb(struct device_node *root, void *fdt);
-struct device_node *of_new_node(struct device_node *parent, const char *name);
-struct property *of_new_property(struct device_node *node, const char *name,
-		const void *data, int len);
-void of_delete_property(struct property *pp);
-
-int of_set_property(struct device_node *node, const char *p, const void *val, int len,
-		int create);
-struct device_node *of_create_node(struct device_node *root, const char *path);
-
-int of_set_root_node(struct device_node *);
-
-const struct of_device_id *of_match_node(const struct of_device_id *matches,
-					 const struct device_node *node);
 
 struct cdev;
 
 #ifdef CONFIG_OFTREE
+extern int of_n_addr_cells(struct device_node *np);
+extern int of_n_size_cells(struct device_node *np);
+
 extern struct property *of_find_property(const struct device_node *np,
 					const char *name, int *lenp);
+extern const void *of_get_property(const struct device_node *np,
+				const char *name, int *lenp);
+
+extern int of_set_property(struct device_node *node, const char *p,
+			const void *val, int len, int create);
+extern struct property *of_new_property(struct device_node *node,
+				const char *name, const void *data, int len);
+extern void of_delete_property(struct property *pp);
 
 extern struct device_node *of_find_node_by_name(struct device_node *from,
 	const char *name);
 extern struct device_node *of_find_node_by_path_from(struct device_node *from,
 						const char *path);
 extern struct device_node *of_find_node_by_path(const char *path);
+extern struct device_node *of_find_node_by_phandle(phandle phandle);
 extern struct device_node *of_find_compatible_node(struct device_node *from,
 	const char *type, const char *compat);
+extern const struct of_device_id *of_match_node(
+	const struct of_device_id *matches, const struct device_node *node);
 extern struct device_node *of_find_matching_node_and_match(
 	struct device_node *from,
 	const struct of_device_id *matches,
 	const struct of_device_id **match);
 extern struct device_node *of_find_node_with_property(
 	struct device_node *from, const char *prop_name);
+
+extern struct device_node *of_new_node(struct device_node *parent,
+				const char *name);
+extern struct device_node *of_create_node(struct device_node *root,
+					const char *path);
+extern void of_free(struct device_node *node);
+
+extern int of_machine_is_compatible(const char *compat);
+extern int of_device_is_compatible(const struct device_node *device,
+		const char *compat);
 extern int of_device_is_available(const struct device_node *device);
 
 extern struct device_node *of_get_parent(const struct device_node *node);
@@ -225,6 +221,10 @@ extern int of_count_phandle_with_args(const struct device_node *np,
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
+extern int of_modalias_node(struct device_node *node, char *modalias, int len);
+
+extern struct device_node *of_get_root_node(void);
+extern int of_set_root_node(struct device_node *node);
 
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
@@ -233,7 +233,6 @@ void *of_flatten_dtb(struct device_node *node);
 int of_add_memory(struct device_node *node, bool dump);
 void of_add_memory_bank(struct device_node *node, bool dump, int r,
 		u64 base, u64 size);
-struct device_node *of_get_root_node(void);
 #else
 static inline int of_parse_partitions(struct cdev *cdev,
 					  struct device_node *node)
@@ -266,6 +265,21 @@ static inline struct device_node *of_get_root_node(void)
 	return NULL;
 }
 
+static inline int of_set_root_node(struct device_node *node)
+{
+	return -ENOSYS;
+}
+
+static inline int of_n_addr_cells(struct device_node *np)
+{
+	return 0;
+}
+
+static inline int of_n_size_cells(struct device_node *np)
+{
+	return 0;
+}
+
 static inline struct device_node *of_get_parent(const struct device_node *node)
 {
 	return NULL;
@@ -300,6 +314,28 @@ static inline struct property *of_find_property(const struct device_node *np,
 	return NULL;
 }
 
+static inline const void *of_get_property(const struct device_node *np,
+				const char *name, int *lenp)
+{
+	return NULL;
+}
+
+static inline int of_set_property(struct device_node *node, const char *p,
+			const void *val, int len, int create)
+{
+	return -ENOSYS;
+}
+
+static inline struct property *of_new_property(struct device_node *node,
+				const char *name, const void *data, int len)
+{
+	return NULL;
+}
+
+static inline void of_delete_property(struct property *pp)
+{
+}
+
 static inline int of_property_read_u32_index(const struct device_node *np,
 				const char *propname, u32 index, u32 *out_value)
 {
@@ -432,6 +468,11 @@ static inline struct device_node *of_find_node_by_name(struct device_node *from,
 	return NULL;
 }
 
+static inline struct device_node *of_find_node_by_phandle(phandle phandle)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_find_compatible_node(
 						struct device_node *from,
 						const char *type,
@@ -440,6 +481,12 @@ static inline struct device_node *of_find_compatible_node(
 	return NULL;
 }
 
+static inline const struct of_device_id *of_match_node(
+	const struct of_device_id *matches, const struct device_node *node)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_find_matching_node_and_match(
 					struct device_node *from,
 					const struct of_device_id *matches,
@@ -454,6 +501,33 @@ static inline struct device_node *of_find_node_with_property(
 	return NULL;
 }
 
+static inline struct device_node *of_new_node(struct device_node *parent,
+				const char *name)
+{
+	return NULL;
+}
+
+static inline struct device_node *of_create_node(struct device_node *root,
+					const char *path)
+{
+	return NULL;
+}
+
+static inline void of_free(struct device_node *node)
+{
+}
+
+static inline int of_machine_is_compatible(const char *compat)
+{
+	return 0;
+}
+
+static inline int of_device_is_compatible(const struct device_node *device,
+		const char *compat)
+{
+	return 0;
+}
+
 static inline int of_device_is_available(const struct device_node *device)
 {
 	return 0;
@@ -472,6 +546,12 @@ static inline const char *of_alias_get(struct device_node *np)
 {
 	return NULL;
 }
+
+static inline int of_modalias_node(struct device_node *node, char *modalias,
+				int len)
+{
+	return -ENOSYS;
+}
 #endif
 
 #define for_each_node_by_name(dn, name) \
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:43 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:43 +0200
Subject: [PATCH v2 14/22] OF: base: import of_property_read_* helpers from
 Linux OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-15-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_property_read_* helpers from Linux OF API to allow
to read all kinds of properties.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |  387 +++++++++++++++++++++++++++++++++++++++++------------
 include/of.h      |  132 ++++++++++++++++--
 2 files changed, 420 insertions(+), 99 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index ee0496d..d58ba4d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -467,12 +467,137 @@ int of_match(struct device_d *dev, struct driver_d *drv)
 EXPORT_SYMBOL(of_match);
 
 /**
+ * of_find_property_value_of_size
+ *
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @len:	requested length of property value
+ *
+ * Search for a property in a device node and valid the requested size.
+ * Returns the property value on success, -EINVAL if the property does not
+ *  exist, -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ */
+static void *of_find_property_value_of_size(const struct device_node *np,
+			const char *propname, u32 len)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+
+	if (!prop)
+		return ERR_PTR(-EINVAL);
+	if (!prop->value)
+		return ERR_PTR(-ENODATA);
+	if (len > prop->length)
+		return ERR_PTR(-EOVERFLOW);
+
+	return prop->value;
+}
+
+/**
+ * of_property_read_u32_index - Find and read a u32 from a multi-value property.
+ *
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @index:	index of the u32 in the list of values
+ * @out_value:	pointer to return value, modified only if no error.
+ *
+ * Search for a property in a device node and read nth 32-bit value from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * The out_value is modified only if a valid u32 value can be decoded.
+ */
+int of_property_read_u32_index(const struct device_node *np,
+				       const char *propname,
+				       u32 index, u32 *out_value)
+{
+	const u32 *val = of_find_property_value_of_size(np, propname,
+					((index + 1) * sizeof(*out_value)));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	*out_value = be32_to_cpup(((__be32 *)val) + index);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u32_index);
+
+/**
+ * of_property_read_u8_array - Find and read an array of u8 from a property.
+ *
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @out_value:	pointer to return value, modified only if return value is 0.
+ * @sz:		number of array elements to read
+ *
+ * Search for a property in a device node and read 8-bit value(s) from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * dts entry of array should be like:
+ *	property = /bits/ 8 <0x50 0x60 0x70>;
+ *
+ * The out_value is modified only if a valid u8 value can be decoded.
+ */
+int of_property_read_u8_array(const struct device_node *np,
+			const char *propname, u8 *out_values, size_t sz)
+{
+	const u8 *val = of_find_property_value_of_size(np, propname,
+						(sz * sizeof(*out_values)));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	while (sz--)
+		*out_values++ = *val++;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u8_array);
+
+/**
+ * of_property_read_u16_array - Find and read an array of u16 from a property.
+ *
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @out_value:	pointer to return value, modified only if return value is 0.
+ * @sz:		number of array elements to read
+ *
+ * Search for a property in a device node and read 16-bit value(s) from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * dts entry of array should be like:
+ *	property = /bits/ 16 <0x5000 0x6000 0x7000>;
+ *
+ * The out_value is modified only if a valid u16 value can be decoded.
+ */
+int of_property_read_u16_array(const struct device_node *np,
+			const char *propname, u16 *out_values, size_t sz)
+{
+	const __be16 *val = of_find_property_value_of_size(np, propname,
+						(sz * sizeof(*out_values)));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	while (sz--)
+		*out_values++ = be16_to_cpup(val++);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u16_array);
+
+/**
  * of_property_read_u32_array - Find and read an array of 32 bit integers
  * from a property.
  *
  * @np:		device node from which the property value is to be read.
  * @propname:	name of the property to be searched.
  * @out_value:	pointer to return value, modified only if return value is 0.
+ * @sz:		number of array elements to read
  *
  * Search for a property in a device node and read 32-bit value(s) from
  * it. Returns 0 on success, -EINVAL if the property does not exist,
@@ -485,22 +610,192 @@ int of_property_read_u32_array(const struct device_node *np,
 			       const char *propname, u32 *out_values,
 			       size_t sz)
 {
+	const __be32 *val = of_find_property_value_of_size(np, propname,
+						(sz * sizeof(*out_values)));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	while (sz--)
+		*out_values++ = be32_to_cpup(val++);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+
+/**
+ * of_property_read_u64 - Find and read a 64 bit integer from a property
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @out_value:	pointer to return value, modified only if return value is 0.
+ *
+ * Search for a property in a device node and read a 64-bit value from
+ * it. Returns 0 on success, -EINVAL if the property does not exist,
+ * -ENODATA if property does not have a value, and -EOVERFLOW if the
+ * property data isn't large enough.
+ *
+ * The out_value is modified only if a valid u64 value can be decoded.
+ */
+int of_property_read_u64(const struct device_node *np, const char *propname,
+			 u64 *out_value)
+{
+	const __be32 *val = of_find_property_value_of_size(np, propname,
+						sizeof(*out_value));
+
+	if (IS_ERR(val))
+		return PTR_ERR(val);
+
+	*out_value = of_read_number(val, 2);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u64);
+
+/**
+ * of_property_read_string - Find and read a string from a property
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @out_string:	pointer to null terminated return string, modified only if
+ *		return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy). Returns 0 on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string(struct device_node *np, const char *propname,
+				const char **out_string)
+{
 	struct property *prop = of_find_property(np, propname, NULL);
-	const __be32 *val;
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+	if (strnlen(prop->value, prop->length) >= prop->length)
+		return -EILSEQ;
+	*out_string = prop->value;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_string);
+
+/**
+ * of_property_read_string_index - Find and read a string from a multiple
+ * strings property.
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ * @index:	index of the string in the list of strings
+ * @out_string:	pointer to null terminated return string, modified only if
+ *		return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy) in the list of strings
+ * contained in that property.
+ * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
+ * property does not have a value, and -EILSEQ if the string is not
+ * null-terminated within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string_index(struct device_node *np, const char *propname,
+				  int index, const char **output)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	int i = 0;
+	size_t l = 0, total = 0;
+	const char *p;
 
 	if (!prop)
 		return -EINVAL;
 	if (!prop->value)
 		return -ENODATA;
-	if ((sz * sizeof(*out_values)) > prop->length)
-		return -EOVERFLOW;
+	if (strnlen(prop->value, prop->length) >= prop->length)
+		return -EILSEQ;
 
-	val = prop->value;
-	while (sz--)
-		*out_values++ = be32_to_cpup(val++);
-	return 0;
+	p = prop->value;
+
+	for (i = 0; total < prop->length; total += l, p += l) {
+		l = strlen(p) + 1;
+		if (i++ == index) {
+			*output = p;
+			return 0;
+		}
+	}
+	return -ENODATA;
 }
-EXPORT_SYMBOL_GPL(of_property_read_u32_array);
+EXPORT_SYMBOL_GPL(of_property_read_string_index);
+
+/**
+ * of_property_match_string() - Find string in a list and return index
+ * @np: pointer to node containing string list property
+ * @propname: string list property name
+ * @string: pointer to string to search for in string list
+ *
+ * This function searches a string list property and returns the index
+ * of a specific string value.
+ */
+int of_property_match_string(struct device_node *np, const char *propname,
+			     const char *string)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	size_t l;
+	int i;
+	const char *p, *end;
+
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+
+	p = prop->value;
+	end = p + prop->length;
+
+	for (i = 0; p < end; i++, p += l) {
+		l = strlen(p) + 1;
+		if (p + l > end)
+			return -EILSEQ;
+		pr_debug("comparing %s with %s\n", string, p);
+		if (strcmp(string, p) == 0)
+			return i; /* Found it; return index */
+	}
+	return -ENODATA;
+}
+EXPORT_SYMBOL_GPL(of_property_match_string);
+
+/**
+ * of_property_count_strings - Find and return the number of strings from a
+ * multiple strings property.
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ *
+ * Search for a property in a device tree node and retrieve the number of null
+ * terminated string contain in it. Returns the number of strings on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ */
+int of_property_count_strings(struct device_node *np, const char *propname)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+	int i = 0;
+	size_t l = 0, total = 0;
+	const char *p;
+
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+	if (strnlen(prop->value, prop->length) >= prop->length)
+		return -EILSEQ;
+
+	p = prop->value;
+
+	for (i = 0; total < prop->length; total += l, p += l, i++)
+		l = strlen(p) + 1;
+
+	return i;
+}
+EXPORT_SYMBOL_GPL(of_property_count_strings);
 
 /**
  * of_property_write_u32_array - Write an array of u32 to a property. If
@@ -730,82 +1025,6 @@ struct device_node *of_find_node_by_path(const char *path)
 EXPORT_SYMBOL(of_find_node_by_path);
 
 /**
- * of_property_read_string - Find and read a string from a property
- * @np:		device node from which the property value is to be read.
- * @propname:	name of the property to be searched.
- * @out_string:	pointer to null terminated return string, modified only if
- *		return value is 0.
- *
- * Search for a property in a device tree node and retrieve a null
- * terminated string value (pointer to data, not a copy). Returns 0 on
- * success, -EINVAL if the property does not exist, -ENODATA if property
- * does not have a value, and -EILSEQ if the string is not null-terminated
- * within the length of the property data.
- *
- * The out_string pointer is modified only if a valid string can be decoded.
- */
-int of_property_read_string(struct device_node *np, const char *propname,
-				const char **out_string)
-{
-	struct property *prop = of_find_property(np, propname, NULL);
-	if (!prop)
-		return -EINVAL;
-	if (!prop->value)
-		return -ENODATA;
-	if (strnlen(prop->value, prop->length) >= prop->length)
-		return -EILSEQ;
-	*out_string = prop->value;
-	return 0;
-}
-EXPORT_SYMBOL_GPL(of_property_read_string);
-
-/**
- * of_property_read_string_index - Find and read a string from a multiple
- * strings property.
- * @np:		device node from which the property value is to be read.
- * @propname:	name of the property to be searched.
- * @index:	index of the string in the list of strings
- * @out_string:	pointer to null terminated return string, modified only if
- *		return value is 0.
- *
- * Search for a property in a device tree node and retrieve a null
- * terminated string value (pointer to data, not a copy) in the list of strings
- * contained in that property.
- * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
- * property does not have a value, and -EILSEQ if the string is not
- * null-terminated within the length of the property data.
- *
- * The out_string pointer is modified only if a valid string can be decoded.
- */
-int of_property_read_string_index(struct device_node *np, const char *propname,
-				  int index, const char **output)
-{
-	struct property *prop = of_find_property(np, propname, NULL);
-	int i = 0;
-	size_t l = 0, total = 0;
-	const char *p;
-
-	if (!prop)
-		return -EINVAL;
-	if (!prop->value)
-		return -ENODATA;
-	if (strnlen(prop->value, prop->length) >= prop->length)
-		return -EILSEQ;
-
-	p = prop->value;
-
-	for (i = 0; total < prop->length; total += l, p += l) {
-		l = strlen(p) + 1;
-		if (i++ == index) {
-			*output = p;
-			return 0;
-		}
-	}
-	return -ENODATA;
-}
-EXPORT_SYMBOL_GPL(of_property_read_string_index);
-
-/**
  * of_modalias_node - Lookup appropriate modalias for a device node
  * @node:	pointer to a device tree node
  * @modalias:	Pointer to buffer that modalias value will be copied into
diff --git a/include/of.h b/include/of.h
index 917466f..d94527d 100644
--- a/include/of.h
+++ b/include/of.h
@@ -106,17 +106,6 @@ static inline void of_write_number(void *__cell, u64 val, int size)
 	}
 }
 
-int of_property_read_u32_array(const struct device_node *np,
-			       const char *propname, u32 *out_values,
-			       size_t sz);
-
-static inline int of_property_read_u32(const struct device_node *np,
-				       const char *propname,
-				       u32 *out_value)
-{
-	return of_property_read_u32_array(np, propname, out_value, 1);
-}
-
 int of_property_write_u32_array(struct device_node *np,
 				const char *propname, const u32 *values,
 				size_t sz);
@@ -163,10 +152,6 @@ struct property *of_new_property(struct device_node *node, const char *name,
 		const void *data, int len);
 void of_delete_property(struct property *pp);
 
-int of_property_read_string(struct device_node *np, const char *propname,
-				const char **out_string);
-int of_property_read_string_index(struct device_node *np, const char *propname,
-				  int index, const char **output);
 int of_set_property(struct device_node *node, const char *p, const void *val, int len,
 		int create);
 struct device_node *of_create_node(struct device_node *root, const char *path);
@@ -205,6 +190,32 @@ extern int of_get_available_child_count(const struct device_node *parent);
 extern struct device_node *of_get_child_by_name(const struct device_node *node,
 					const char *name);
 
+extern int of_property_read_u32_index(const struct device_node *np,
+				       const char *propname,
+				       u32 index, u32 *out_value);
+extern int of_property_read_u8_array(const struct device_node *np,
+			const char *propname, u8 *out_values, size_t sz);
+extern int of_property_read_u16_array(const struct device_node *np,
+			const char *propname, u16 *out_values, size_t sz);
+extern int of_property_read_u32_array(const struct device_node *np,
+				      const char *propname,
+				      u32 *out_values,
+				      size_t sz);
+extern int of_property_read_u64(const struct device_node *np,
+				const char *propname, u64 *out_value);
+
+extern int of_property_read_string(struct device_node *np,
+				   const char *propname,
+				   const char **out_string);
+extern int of_property_read_string_index(struct device_node *np,
+					 const char *propname,
+					 int index, const char **output);
+extern int of_property_match_string(struct device_node *np,
+				    const char *propname,
+				    const char *string);
+extern int of_property_count_strings(struct device_node *np,
+				     const char *propname);
+
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
@@ -283,6 +294,60 @@ static inline struct property *of_find_property(const struct device_node *np,
 	return NULL;
 }
 
+static inline int of_property_read_u32_index(const struct device_node *np,
+				const char *propname, u32 index, u32 *out_value)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_u8_array(const struct device_node *np,
+				const char *propname, u8 *out_values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_u16_array(const struct device_node *np,
+			const char *propname, u16 *out_values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_u32_array(const struct device_node *np,
+			const char *propname, u32 *out_values, size_t sz)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_u64(const struct device_node *np,
+				const char *propname, u64 *out_value)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_string(struct device_node *np,
+				const char *propname, const char **out_string)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_read_string_index(struct device_node *np,
+			 const char *propname, int index, const char **output)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_match_string(struct device_node *np,
+				const char *propname, const char *string)
+{
+	return -ENOSYS;
+}
+
+static inline int of_property_count_strings(struct device_node *np,
+					const char *propname)
+{
+	return -ENOSYS;
+}
+
 static inline struct device_node *of_find_node_by_path_from(
 	struct device_node *from, const char *path)
 {
@@ -370,4 +435,41 @@ static inline struct device_node *of_find_matching_node(
 	for (child = of_get_next_available_child(parent, NULL); child != NULL; \
 	     child = of_get_next_available_child(parent, child))
 
+/**
+ * of_property_read_bool - Findfrom a property
+ * @np:		device node from which the property value is to be read.
+ * @propname:	name of the property to be searched.
+ *
+ * Search for a property in a device node.
+ * Returns true if the property exist false otherwise.
+ */
+static inline bool of_property_read_bool(const struct device_node *np,
+					 const char *propname)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+
+	return prop ? true : false;
+}
+
+static inline int of_property_read_u8(const struct device_node *np,
+				       const char *propname,
+				       u8 *out_value)
+{
+	return of_property_read_u8_array(np, propname, out_value, 1);
+}
+
+static inline int of_property_read_u16(const struct device_node *np,
+				       const char *propname,
+				       u16 *out_value)
+{
+	return of_property_read_u16_array(np, propname, out_value, 1);
+}
+
+static inline int of_property_read_u32(const struct device_node *np,
+				       const char *propname,
+				       u32 *out_value)
+{
+	return of_property_read_u32_array(np, propname, out_value, 1);
+}
+
 #endif /* __OF_H */
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:48 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:48 +0200
Subject: [PATCH v2 19/22] OF: base: remove of_tree_for_each_node from public
 API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-20-git-send-email-sebastian.hesselbarth@gmail.com>

This patch converts users of of_tree_for_each_node to recently added
for_eacg_compatible_node helper. Also of_tree_for_each_node is removed
from public OF API.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 arch/arm/boards/at91sam9x5ek/hw_version.c |   10 +++-------
 arch/arm/boards/highbank/init.c           |   16 ++++++----------
 drivers/of/base.c                         |    8 ++++++++
 include/of.h                              |    8 --------
 4 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 91af331..426bd35 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -234,13 +234,9 @@ static int cm_cogent_fixup(struct device_node *root)
 	int ret;
 	struct device_node *node;
 
-	of_tree_for_each_node(node, root) {
-		struct device_node *slotnode;
-
-		if (!of_device_is_compatible(node, "atmel,hsmci"))
-			continue;
-
-		slotnode = of_find_child_by_name(node, "slot");
+	for_each_compatible_node(node, NULL, "atmel,hsmci") {
+		struct device_node *slotnode =
+			of_find_child_by_name(node, "slot");
 		if (!slotnode)
 			continue;
 
diff --git a/arch/arm/boards/highbank/init.c b/arch/arm/boards/highbank/init.c
index 1aa713b..46ecc88 100644
--- a/arch/arm/boards/highbank/init.c
+++ b/arch/arm/boards/highbank/init.c
@@ -35,19 +35,15 @@ static int hb_fixup(struct device_node *root)
 	__be32 latency;
 
 	if (!(reg & HB_PWRDOM_STAT_SATA)) {
-		of_tree_for_each_node(node, root) {
-			if (of_device_is_compatible(node, "calxeda,hb-ahci"))
-				of_set_property(node, "status", "disabled",
-						sizeof("disabled"), 1);
-		}
+		for_each_compatible_node(node, NULL, "calxeda,hb-ahci")
+			of_set_property(node, "status", "disabled",
+					sizeof("disabled"), 1);
 	}
 
 	if (!(reg & HB_PWRDOM_STAT_EMMC)) {
-		of_tree_for_each_node(node, root) {
-			if (of_device_is_compatible(node, "calxeda,hb-sdhci"))
-				of_set_property(node, "status", "disabled",
-						sizeof("disabled"), 1);
-		}
+		for_each_compatible_node(node, NULL, "calxeda,hb-sdhci")
+			of_set_property(node, "status", "disabled",
+					sizeof("disabled"), 1);
 	}
 
 	if ((opp_table[0] >> 16) != HB_OPP_VERSION)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3e7a488..c8497f4 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -28,6 +28,14 @@
 #include <linux/amba/bus.h>
 #include <linux/err.h>
 
+/*
+ * Iterate over all nodes of a tree. As a devicetree does not
+ * have a dedicated list head, the start node (usually the root
+ * node) will not be iterated over.
+ */
+#define of_tree_for_each_node(node, root) \
+	list_for_each_entry(node, &root->list, list)
+
 /**
  * struct alias_prop - Alias property in 'aliases' node
  * @link:	List node to link the structure in aliases_lookup list
diff --git a/include/of.h b/include/of.h
index 30b5be5..2ef00be 100644
--- a/include/of.h
+++ b/include/of.h
@@ -85,14 +85,6 @@ int of_modalias_node(struct device_node *node, char *modalias, int len);
 #define device_node_for_nach_child(node, child) \
 	list_for_each_entry(child, &node->children, parent_list)
 
-/*
- * Iterate over all nodes of a tree. As a devicetree does not
- * have a dedicated list head, the start node (usually the root
- * node) will not be iterated over.
- */
-#define of_tree_for_each_node(node, root) \
-	list_for_each_entry(node, &root->list, list)
-
 /* Helper to read a big number; size is in cells (not bytes) */
 static inline u64 of_read_number(const __be32 *cell, int size)
 {
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Wed Jun 19 05:09:45 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 19 Jun 2013 11:09:45 +0200
Subject: [PATCH v2 16/22] OF: base: import parse phandle functions from Linux
 OF API
In-Reply-To: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371632991-1504-17-git-send-email-sebastian.hesselbarth@gmail.com>

This imports of_parse_phandle_with_args and of_count_phandle_with_args
from Linux OF API. The slightly different of_parse_phandles_with_args
is removed and all users are converted to reflect the API change.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c              |  188 +++++++++++++++++++++++++---------------
 drivers/of/gpio.c              |    9 +-
 drivers/usb/imx/chipidea-imx.c |   11 +--
 include/of.h                   |   30 ++++++-
 4 files changed, 151 insertions(+), 87 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 486758b..1c385c8 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -862,17 +862,16 @@ struct device_node *of_parse_phandle(const struct device_node *np,
 EXPORT_SYMBOL(of_parse_phandle);
 
 /**
- * of_parse_phandles_with_args - Find a node pointed by phandle in a list
+ * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
  * @np:		pointer to a device tree node containing a list
  * @list_name:	property name that contains a list
  * @cells_name:	property name that specifies phandles' arguments count
  * @index:	index of a phandle to parse out
- * @out_node:	optional pointer to device_node struct pointer (will be filled)
- * @out_args:	optional pointer to arguments pointer (will be filled)
+ * @out_args:	optional pointer to output arguments structure (will be filled)
  *
  * This function is useful to parse lists of phandles and their arguments.
- * Returns 0 on success and fills out_node and out_args, on error returns
- * appropriate errno value.
+ * Returns 0 on success and fills out_args, on error returns appropriate
+ * errno value.
  *
  * Example:
  *
@@ -889,92 +888,139 @@ EXPORT_SYMBOL(of_parse_phandle);
  * }
  *
  * To get a device_node of the `node2' node you may call this:
- * of_parse_phandles_with_args(node3, "list", "#list-cells", 2, &node2, &args);
+ * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
  */
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
-				const char *cells_name, int index,
-				struct device_node **out_node,
-				const void **out_args)
-{
-	int ret = -EINVAL;
-	const __be32 *list;
-	const __be32 *list_end;
-	int size;
-	int cur_index = 0;
+static int __of_parse_phandle_with_args(const struct device_node *np,
+					const char *list_name,
+					const char *cells_name, int index,
+					struct of_phandle_args *out_args)
+{
+	const __be32 *list, *list_end;
+	int rc = 0, size, cur_index = 0;
+	uint32_t count = 0;
 	struct device_node *node = NULL;
-	const void *args = NULL;
+	phandle phandle;
 
+	/* Retrieve the phandle list property */
 	list = of_get_property(np, list_name, &size);
-	if (!list) {
-		ret = -ENOENT;
-		goto err0;
-	}
+	if (!list)
+		return -ENOENT;
 	list_end = list + size / sizeof(*list);
 
+	/* Loop over the phandles until all the requested entry is found */
 	while (list < list_end) {
-		const __be32 *cells;
-		phandle phandle;
+		rc = -EINVAL;
+		count = 0;
 
+		/*
+		 * If phandle is 0, then it is an empty entry with no
+		 * arguments.  Skip forward to the next entry.
+		 */
 		phandle = be32_to_cpup(list++);
-		args = list;
-
-		/* one cell hole in the list = <>; */
-		if (!phandle)
-			goto next;
-
-		node = of_find_node_by_phandle(phandle);
-		if (!node) {
-			pr_debug("%s: could not find phandle %d\n",
-				 np->full_name, phandle);
-			goto err0;
+		if (phandle) {
+			/*
+			 * Find the provider node and parse the #*-cells
+			 * property to determine the argument length
+			 */
+			node = of_find_node_by_phandle(phandle);
+			if (!node) {
+				pr_err("%s: could not find phandle\n",
+					 np->full_name);
+				goto err;
+			}
+			if (of_property_read_u32(node, cells_name, &count)) {
+				pr_err("%s: could not get %s for %s\n",
+					 np->full_name, cells_name,
+					 node->full_name);
+				goto err;
+			}
+
+			/*
+			 * Make sure that the arguments actually fit in the
+			 * remaining property data length
+			 */
+			if (list + count > list_end) {
+				pr_err("%s: arguments longer than property\n",
+					 np->full_name);
+				goto err;
+			}
 		}
 
-		cells = of_get_property(node, cells_name, &size);
-		if (!cells || size != sizeof(*cells)) {
-			pr_debug("%s: could not get %s for %s\n",
-				 np->full_name, cells_name, node->full_name);
-			goto err1;
-		}
-
-		list += be32_to_cpup(cells);
-		if (list > list_end) {
-			pr_debug("%s: insufficient arguments length\n",
-				 np->full_name);
-			goto err1;
+		/*
+		 * All of the error cases above bail out of the loop, so at
+		 * this point, the parsing is successful. If the requested
+		 * index matches, then fill the out_args structure and return,
+		 * or return -ENOENT for an empty entry.
+		 */
+		rc = -ENOENT;
+		if (cur_index == index) {
+			if (!phandle)
+				goto err;
+
+			if (out_args) {
+				int i;
+				if (WARN_ON(count > MAX_PHANDLE_ARGS))
+					count = MAX_PHANDLE_ARGS;
+				out_args->np = node;
+				out_args->args_count = count;
+				for (i = 0; i < count; i++)
+					out_args->args[i] =
+						be32_to_cpup(list++);
+			}
+
+			/* Found it! return success */
+			return 0;
 		}
-next:
-		if (cur_index == index)
-			break;
 
 		node = NULL;
-		args = NULL;
+		list += count;
 		cur_index++;
 	}
 
-	if (!node) {
-		/*
-		 * args w/o node indicates that the loop above has stopped at
-		 * the 'hole' cell. Report this differently.
-		 */
-		if (args)
-			ret = -EEXIST;
-		else
-			ret = -ENOENT;
-		goto err0;
-	}
+	/*
+	 * Unlock node before returning result; will be one of:
+	 * -ENOENT : index is for empty phandle
+	 * -EINVAL : parsing error on data
+	 * [1..n]  : Number of phandle (count mode; when index = -1)
+	 */
+	rc = index < 0 ? cur_index : -ENOENT;
+ err:
+	return rc;
+}
 
-	if (out_node)
-		*out_node = node;
-	if (out_args)
-		*out_args = args;
+int of_parse_phandle_with_args(const struct device_node *np,
+		const char *list_name, const char *cells_name, int index,
+		struct of_phandle_args *out_args)
+{
+	if (index < 0)
+		return -EINVAL;
+	return __of_parse_phandle_with_args(np, list_name, cells_name,
+					index, out_args);
+}
+EXPORT_SYMBOL(of_parse_phandle_with_args);
 
-	return 0;
-err1:
-err0:
-	pr_debug("%s failed with status %d\n", __func__, ret);
-	return ret;
+/**
+ * of_count_phandle_with_args() - Find the number of phandles references in a property
+ * @np:		pointer to a device tree node containing a list
+ * @list_name:	property name that contains a list
+ * @cells_name:	property name that specifies phandles' arguments count
+ *
+ * Returns the number of phandle + argument tuples within a property. It
+ * is a typical pattern to encode a list of phandle and variable
+ * arguments into a single property. The number of arguments is encoded
+ * by a property in the phandle-target node. For example, a gpios
+ * property would contain a list of GPIO specifies consisting of a
+ * phandle and 1 or more arguments. The number of arguments are
+ * determined by the #gpio-cells property in the node pointed to by the
+ * phandle.
+ */
+int of_count_phandle_with_args(const struct device_node *np,
+			const char *list_name, const char *cells_name)
+{
+	return __of_parse_phandle_with_args(np, list_name, cells_name,
+					-1, NULL);
 }
-EXPORT_SYMBOL(of_parse_phandles_with_args);
+EXPORT_SYMBOL(of_count_phandle_with_args);
 
 /**
  * of_machine_is_compatible - Test root of device tree for a given compatible value
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 83b72c0..87b9c0c 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -9,17 +9,16 @@ int of_get_named_gpio(struct device_node *np,
                                    const char *propname, int index)
 {
 	int ret;
-	struct device_node *gpio_np;
-	const void *gpio_spec;
+	struct of_phandle_args out_args;
 
-	ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index,
-					  &gpio_np, &gpio_spec);
+	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
+					index, &out_args);
 	if (ret) {
 		pr_debug("%s: can't parse gpios property: %d\n", __func__, ret);
 		return -EINVAL;
 	}
 
-	ret = gpio_get_num(gpio_np->device, be32_to_cpup(gpio_spec));
+	ret = gpio_get_num(out_args.np->device, outargs.args[0]);
 	if (ret < 0)
 		return ret;
 
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 32b05aa..ee7c010 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -62,16 +62,15 @@ static int imx_chipidea_port_post_init(void *drvdata)
 
 static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
 {
-	const void *out_args;
-	struct device_node *usbmisc_np;
+	struct of_phandle_args out_args;
 	enum usb_dr_mode mode;
 	enum usb_phy_interface phymode;
 
-	of_parse_phandles_with_args(ci->dev->device_node, "fsl,usbmisc",
-			"#index-cells", 0, &usbmisc_np, &out_args);
-
-	ci->portno = be32_to_cpup(out_args);
+	if (of_parse_phandle_with_args(ci->dev->device_node, "fsl,usbmisc",
+					"#index-cells", 0, &out_args))
+		return -ENODEV;
 
+	ci->portno = out_args.args[0];
 	ci->flags = MXC_EHCI_MODE_UTMI_8BIT;
 
 	mode = of_usb_get_dr_mode(ci->dev->device_node, NULL);
diff --git a/include/of.h b/include/of.h
index 4f5470a..e03bd40 100644
--- a/include/of.h
+++ b/include/of.h
@@ -42,6 +42,13 @@ struct of_device_id {
 	unsigned long data;
 };
 
+#define MAX_PHANDLE_ARGS 8
+struct of_phandle_args {
+	struct device_node *np;
+	int args_count;
+	uint32_t args[MAX_PHANDLE_ARGS];
+};
+
 #define OF_MAX_RESERVE_MAP	16
 struct of_reserve_map {
 	uint64_t start[OF_MAX_RESERVE_MAP];
@@ -120,11 +127,6 @@ static inline int of_property_write_u32(struct device_node *np,
 const void *of_get_property(const struct device_node *np, const char *name,
 			 int *lenp);
 
-int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
-				const char *cells_name, int index,
-				struct device_node **out_node,
-				const void **out_args);
-
 int of_get_named_gpio(struct device_node *np,
                                    const char *propname, int index);
 
@@ -219,6 +221,11 @@ extern int of_property_count_strings(struct device_node *np,
 extern struct device_node *of_parse_phandle(const struct device_node *np,
 					    const char *phandle_name,
 					    int index);
+extern int of_parse_phandle_with_args(const struct device_node *np,
+	const char *list_name, const char *cells_name, int index,
+	struct of_phandle_args *out_args);
+extern int of_count_phandle_with_args(const struct device_node *np,
+	const char *list_name, const char *cells_name);
 
 extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
@@ -358,6 +365,19 @@ static inline struct device_node *of_parse_phandle(const struct device_node *np,
 	return NULL;
 }
 
+static inline int of_parse_phandle_with_args(const struct device_node *np,
+		const char *list_name, const char *cells_name, int index,
+		struct of_phandle_args *out_args)
+{
+	return -ENOSYS;
+}
+
+static inline int of_count_phandle_with_args(const struct device_node *np,
+				const char *list_name, const char *cells_name)
+{
+	return -ENOSYS;
+}
+
 static inline struct device_node *of_find_node_by_path_from(
 	struct device_node *from, const char *path)
 {
-- 
1.7.2.5



From linux at rempel-privat.de  Wed Jun 19 05:11:25 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Wed, 19 Jun 2013 11:11:25 +0200
Subject: [PATCH 0/8] low level initialisation for ar2313
Message-ID: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>

this patch set add low level initialisation for Atheros ar2313
and board based on this chip - Netgear wg102.

Antony Pavlov (2):
  MIPS: pbl: add mips_barebox_10h asm macro
  MIPS: mach-ar231x: enable DEBUG_LL

Oleksij Rempel (6):
  MIPS: pbl: add pbl_sleep macro
  MIPS: pbl: add pbl_probe_mem macro
  MIPS: mach-ar231x: add lowlevel init pbl macros
  MIPS: netgear-wg102: add pbl support
  MIPS: netgear-wg102: add debug_ll
  netgear-wg102: pbl, add extra check for mem config

 arch/mips/Kconfig                                  |   1 +
 .../netgear-wg102/include/board/board_pbl_start.h  |  77 +++++++++
 .../boards/netgear-wg102/include/board/debug_ll.h  |  33 ++++
 arch/mips/include/asm/pbl_macros.h                 |  38 +++++
 arch/mips/mach-ar231x/Kconfig                      |   2 +
 arch/mips/mach-ar231x/include/mach/debug_ll.h      |  27 ++++
 arch/mips/mach-ar231x/include/mach/pbl_macros.h    | 177 +++++++++++++++++++++
 7 files changed, 355 insertions(+)
 create mode 100644 arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
 create mode 100644 arch/mips/boards/netgear-wg102/include/board/debug_ll.h
 create mode 100644 arch/mips/mach-ar231x/include/mach/debug_ll.h
 create mode 100644 arch/mips/mach-ar231x/include/mach/pbl_macros.h

-- 
1.8.1.2



From linux at rempel-privat.de  Wed Jun 19 05:11:33 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Wed, 19 Jun 2013 11:11:33 +0200
Subject: [PATCH 8/8] netgear-wg102: pbl, add extra check for mem config
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <1371633093-23179-9-git-send-email-linux@rempel-privat.de>

if E0 flag is not set, sdram is defenetly not configured.

Signed-off-by: Oleksij Rempel <linux at rempel-privat.de>
---
 arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h b/arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
index 4deae06..d74d2c2 100644
--- a/arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
+++ b/arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
@@ -18,6 +18,7 @@
 
 #include <asm/pbl_macros.h>
 #include <mach/pbl_macros.h>
+#include <mach/ar2312_regs.h>
 
 #include <mach/debug_ll.h>
 
@@ -40,10 +41,17 @@
 	/* check if SDRAM is already configured,
 	 * if yes, we are probably starting
 	 * as second stage loader and can skip configuration */
+	la	t0, KSEG1 | AR2312_MEM_CFG1
+	lw	t1, 0(t0)
+	and	t0, t1, MEM_CFG1_E0
+	beq	zero, t0, 1f
+	 nop
+
 	pbl_probe_mem t0, t1, KSEG1
 	beq t0, t1, sdram_configured
 	 nop
 
+1:
 	/* start SDRAM configuration */
 	pbl_ar2312_x16_sdram
 
-- 
1.8.1.2



From linux at rempel-privat.de  Wed Jun 19 05:11:27 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Wed, 19 Jun 2013 11:11:27 +0200
Subject: [PATCH 2/8] MIPS: pbl: add pbl_sleep macro
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <1371633093-23179-3-git-send-email-linux@rempel-privat.de>

Signed-off-by: Oleksij Rempel <linux at rempel-privat.de>
---
 arch/mips/include/asm/pbl_macros.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/mips/include/asm/pbl_macros.h b/arch/mips/include/asm/pbl_macros.h
index a3f970c..cfca117 100644
--- a/arch/mips/include/asm/pbl_macros.h
+++ b/arch/mips/include/asm/pbl_macros.h
@@ -28,6 +28,16 @@
 #include <generated/compile.h>
 #include <generated/utsrelease.h>
 
+	.macro	pbl_sleep reg count
+	.set push
+	.set noreorder
+	li	\reg, \count
+1:
+	bgtz	\reg, 1b
+	 addi	\reg, -1
+	.set	pop
+	.endm
+
 	/*
 	 * ADR macro instruction (inspired by ARM)
 	 *
-- 
1.8.1.2



From linux at rempel-privat.de  Wed Jun 19 05:11:26 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Wed, 19 Jun 2013 11:11:26 +0200
Subject: [PATCH 1/8] MIPS: pbl: add mips_barebox_10h asm macro
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <1371633093-23179-2-git-send-email-linux@rempel-privat.de>

From: Antony Pavlov <antonynpavlov at gmail.com>

The mips_barebox_10h macro inserts at offset 0x10
of the barebox image the string 'barebox ' followed
by compile time version mark.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/include/asm/pbl_macros.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/mips/include/asm/pbl_macros.h b/arch/mips/include/asm/pbl_macros.h
index 3971b61..a3f970c 100644
--- a/arch/mips/include/asm/pbl_macros.h
+++ b/arch/mips/include/asm/pbl_macros.h
@@ -97,6 +97,22 @@ copy_loop_exit:
 	.set	pop
 	.endm
 
+	.macro	mips_barebox_10h
+	.set	push
+	.set	noreorder
+
+	b	1f
+	 nop
+
+	.org	0x10
+	.ascii	"barebox " UTS_RELEASE " " UTS_VERSION
+	.byte	0
+
+	.align	4
+1:
+	.set	pop
+	.endm
+
 	/*
 	 * Dominic Sweetman, See MIPS Run, Morgan Kaufmann, 2nd edition, 2006
 	 *
-- 
1.8.1.2



From linux at rempel-privat.de  Wed Jun 19 05:11:28 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Wed, 19 Jun 2013 11:11:28 +0200
Subject: [PATCH 3/8] MIPS: pbl: add pbl_probe_mem macro
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <1371633093-23179-4-git-send-email-linux@rempel-privat.de>

Signed-off-by: Oleksij Rempel <linux at rempel-privat.de>
---
 arch/mips/include/asm/pbl_macros.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/mips/include/asm/pbl_macros.h b/arch/mips/include/asm/pbl_macros.h
index cfca117..22d41b8 100644
--- a/arch/mips/include/asm/pbl_macros.h
+++ b/arch/mips/include/asm/pbl_macros.h
@@ -38,6 +38,18 @@
 	.set	pop
 	.endm
 
+	.macro	pbl_probe_mem ret1 ret2 addr
+	.set	push
+	.set	noreorder
+	la	\ret1, \addr
+	sw	zero, 0(\ret1)
+	li	\ret2, 0x12345678
+	sw	\ret2, 0(\ret1)
+	lw	\ret2, 0(\ret1)
+	li	\ret1, 0x12345678
+	.set	pop
+	.endm
+
 	/*
 	 * ADR macro instruction (inspired by ARM)
 	 *
-- 
1.8.1.2



From linux at rempel-privat.de  Wed Jun 19 05:11:30 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Wed, 19 Jun 2013 11:11:30 +0200
Subject: [PATCH 5/8] MIPS: netgear-wg102: add pbl support
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <1371633093-23179-6-git-send-email-linux@rempel-privat.de>

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
Signed-off-by: Oleksij Rempel <linux at rempel-privat.de>
---
 .../netgear-wg102/include/board/board_pbl_start.h  | 69 ++++++++++++++++++++++
 arch/mips/mach-ar231x/Kconfig                      |  2 +
 2 files changed, 71 insertions(+)
 create mode 100644 arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h

diff --git a/arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h b/arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
new file mode 100644
index 0000000..4deae06
--- /dev/null
+++ b/arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2013 Antony Pavlov <antonynpavlov at gmail.com>
+ * Copyright (C) 2013 Oleksij Rempel <linux at rempel-privat.de>
+ *
+ * This file is part of barebox.
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+#include <asm/pbl_macros.h>
+#include <mach/pbl_macros.h>
+
+#include <mach/debug_ll.h>
+
+	.macro	board_pbl_start
+	.set	push
+	.set	noreorder
+
+	mips_barebox_10h
+
+	mips_disable_interrupts
+
+	pbl_ar2312_pll
+
+	pbl_ar2312_rst_uart0
+	debug_ll_ns16550_init
+
+	debug_ll_ns16550_outc 'a'
+	debug_ll_ns16550_outnl
+
+	/* check if SDRAM is already configured,
+	 * if yes, we are probably starting
+	 * as second stage loader and can skip configuration */
+	pbl_probe_mem t0, t1, KSEG1
+	beq t0, t1, sdram_configured
+	 nop
+
+	/* start SDRAM configuration */
+	pbl_ar2312_x16_sdram
+
+	/* check one more time. if some thing wrong,
+	 * we don't need to continue */
+	pbl_probe_mem t0, t1, KSEG1
+	beq t0, t1, sdram_configured
+	 nop
+	debug_ll_ns16550_outc '#'
+	debug_ll_ns16550_outnl
+
+1:
+	b	1b /* dead end */
+	 nop
+
+sdram_configured:
+	debug_ll_ns16550_outc 'b'
+	debug_ll_ns16550_outnl
+
+	copy_to_link_location	pbl_start
+
+	.set	pop
+	.endm
diff --git a/arch/mips/mach-ar231x/Kconfig b/arch/mips/mach-ar231x/Kconfig
index 1c6a12f..3f338ea 100644
--- a/arch/mips/mach-ar231x/Kconfig
+++ b/arch/mips/mach-ar231x/Kconfig
@@ -9,6 +9,8 @@ choice
 
 config BOARD_NETGEAR_WG102
 	bool "Netgear WG102"
+	select HAVE_PBL_IMAGE
+	select HAVE_IMAGE_COMPRESSION
 
 endchoice
 
-- 
1.8.1.2



From linux at rempel-privat.de  Wed Jun 19 05:11:31 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Wed, 19 Jun 2013 11:11:31 +0200
Subject: [PATCH 6/8] MIPS: netgear-wg102: add debug_ll
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <1371633093-23179-7-git-send-email-linux@rempel-privat.de>

Signed-off-by: Oleksij Rempel <linux at rempel-privat.de>
---
 .../boards/netgear-wg102/include/board/debug_ll.h  | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 arch/mips/boards/netgear-wg102/include/board/debug_ll.h

diff --git a/arch/mips/boards/netgear-wg102/include/board/debug_ll.h b/arch/mips/boards/netgear-wg102/include/board/debug_ll.h
new file mode 100644
index 0000000..2725032
--- /dev/null
+++ b/arch/mips/boards/netgear-wg102/include/board/debug_ll.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2013 Oleksij Rempel <linux at rempel-privat.de>
+ *
+ * This file is part of barebox.
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+/** @file
+ *  This File contains declaration for early output support
+ */
+#ifndef __NETGEAR_WG102_DEBUG_LL_H__
+#define __NETGEAR_WG102_DEBUG_LL_H__
+
+#include <mach/ar2312_regs.h>
+
+#define DEBUG_LL_UART_ADDR	KSEG1ADDR(AR2312_UART0)
+#define DEBUG_LL_UART_SHIFT	AR2312_UART_SHIFT
+
+#define DEBUG_LL_UART_CLK   (45000000 / 16)
+#define DEBUG_LL_UART_BPS   CONFIG_BAUDRATE
+#define DEBUG_LL_UART_DIVISOR   (DEBUG_LL_UART_CLK / DEBUG_LL_UART_BPS)
+
+#endif /* __NETGEAR_WG102_DEBUG_LL_H__ */
-- 
1.8.1.2



From linux at rempel-privat.de  Wed Jun 19 05:11:32 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Wed, 19 Jun 2013 11:11:32 +0200
Subject: [PATCH 7/8] MIPS: mach-ar231x: enable DEBUG_LL
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <1371633093-23179-8-git-send-email-linux@rempel-privat.de>

From: Antony Pavlov <antonynpavlov at gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/Kconfig                             |  1 +
 arch/mips/mach-ar231x/include/mach/debug_ll.h | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 arch/mips/mach-ar231x/include/mach/debug_ll.h

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 2e44619..6179fd8 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -52,6 +52,7 @@ config MACH_MIPS_AR231X
 	select SYS_SUPPORTS_BIG_ENDIAN
 	select CSRC_R4K_LIB
 	select DRIVER_SERIAL_NS16550
+	select HAS_DEBUG_LL
 
 config MACH_MIPS_BCM47XX
 	bool "Broadcom BCM47xx-based boards"
diff --git a/arch/mips/mach-ar231x/include/mach/debug_ll.h b/arch/mips/mach-ar231x/include/mach/debug_ll.h
new file mode 100644
index 0000000..5ab7f9a
--- /dev/null
+++ b/arch/mips/mach-ar231x/include/mach/debug_ll.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2013 Antony Pavlov <antonynpavlov at gmail.com>
+ *
+ * This file is part of barebox.
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+#ifndef __MACH_AR231X_DEBUG_LL__
+#define __MACH_AR231X_DEBUG_LL__
+
+/** @file
+ *  This File contains declaration for early output support
+ */
+#include <board/debug_ll.h>
+#include <asm/debug_ll_ns16550.h>
+
+#endif /* __MACH_AR231X_DEBUG_LL__ */
-- 
1.8.1.2



From linux at rempel-privat.de  Wed Jun 19 05:11:29 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Wed, 19 Jun 2013 11:11:29 +0200
Subject: [PATCH 4/8] MIPS: mach-ar231x: add lowlevel init pbl macros
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <1371633093-23179-5-git-send-email-linux@rempel-privat.de>

Signed-off-by: Oleksij Rempel <linux at rempel-privat.de>
Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/mach-ar231x/include/mach/pbl_macros.h | 177 ++++++++++++++++++++++++
 1 file changed, 177 insertions(+)
 create mode 100644 arch/mips/mach-ar231x/include/mach/pbl_macros.h

diff --git a/arch/mips/mach-ar231x/include/mach/pbl_macros.h b/arch/mips/mach-ar231x/include/mach/pbl_macros.h
new file mode 100644
index 0000000..cb72dbe
--- /dev/null
+++ b/arch/mips/mach-ar231x/include/mach/pbl_macros.h
@@ -0,0 +1,177 @@
+#ifndef __ASM_MACH_AR2312_PBL_MACROS_H
+#define __ASM_MACH_AR2312_PBL_MACROS_H
+
+#include <asm/regdef.h>
+#include <mach/ar2312_regs.h>
+
+.macro	pbl_ar2312_pll
+	.set	push
+	.set	noreorder
+
+	mfc0	k0, CP0_STATUS
+	li	k1, ST0_NMI
+	and	k1, k1, k0
+	bnez	k1, pllskip
+	 nop
+
+	/* Clear any prior AHB errors by reading both addr registers */
+	li	t0, KSEG1 | AR2312_PROCADDR
+	lw	zero, 0(t0)
+	li	t0, KSEG1 | AR2312_DMAADDR
+	lw	zero, 0(t0)
+
+	pbl_sleep	t2, 4000
+
+	li	t0, KSEG1 | AR2312_CLOCKCTL2
+	lw	t1, (t0)
+	bgez	t1, pllskip	/* upper bit guaranteed non-0 at reset */
+	 nop
+
+	/* For Viper 0xbc003064 register has to be programmed with 0x91000 to
+	 * get 180Mhz Processor clock
+	 * Set /2 clocking and turn OFF AR2312_CLOCKCTL2_STATUS_PLL_BYPASS.
+	 * Processor RESETs at this point; the CLOCKCTL registers retain
+	 * their new values across the reset.
+	 */
+
+	li	t0, KSEG1 | AR2312_CLOCKCTL1
+	li	t1, AR2313_CLOCKCTL1_SELECTION
+	sw	t1, (t0)
+
+	li	t0, KSEG1 | AR2312_CLOCKCTL2
+	li	t1, AR2312_CLOCKCTL2_WANT_RESET
+	sw	t1, (t0)	/* reset CPU */
+1:	b	1b		/* NOTREACHED */
+	 nop
+pllskip:
+
+	.set	pop
+.endm
+
+.macro	pbl_ar2312_rst_uart0
+	.set	push
+	.set	noreorder
+
+	li	a0, KSEG1 | AR2312_RESET
+	lw	t0, 0(a0)
+	and	t0, ~AR2312_RESET_APB
+	or	t0, AR2312_RESET_UART0
+	sw	t0, 0(a0)
+	lw	zero, 0(a0)	/* flush */
+
+	and	t0, ~AR2312_RESET_UART0
+	sw	t0, 0(a0)
+	lw	zero, 0(a0)	/* flush */
+
+1:	/* Use internal clocking */
+	li	a0, KSEG1 | AR2312_CLOCKCTL0
+	lw	t0, 0(a0)
+	and	t0, ~AR2312_CLOCKCTL_UART0
+	sw	t0, 0(a0)
+
+	.set	pop
+.endm
+
+.macro	pbl_ar2312_x16_sdram
+	.set	push
+	.set	noreorder
+
+	li	a0, KSEG1 | AR2312_MEM_CFG0
+	li	a1, KSEG1 | AR2312_MEM_CFG1
+	li	a2, KSEG1 | AR2312_MEM_REF
+
+	li	a3, MEM_CFG1_E0 | (MEM_CFG1_AC_128 << MEM_CFG1_AC0_S)
+
+	/* Set the I and M bits to issue an SDRAM nop */
+	ori	t0, a3, MEM_CFG1_M | MEM_CFG1_I
+	sw	t0, 0(a1)	/* AR2312_MEM_CFG1 */
+
+	pbl_sleep	t2, 50
+
+	/* Reset the M bit to issue an SDRAM PRE-ALL */
+	ori	t0, a3, MEM_CFG1_I
+	sw	t0, 0(a1)	/* AR2312_MEM_CFG1 */
+	sync
+
+	/* Generate a refresh every 16 clocks (spec says 10) */
+	li	t0, 16		/* very fast refresh for now */
+	sw	t0, 0(a2)	/* AR2312_MEM_REF */
+
+	pbl_sleep	t2, 5
+
+	/* Set command write mode, and read SDRAM */
+	ori	t0, a3, MEM_CFG1_M
+	sw	t0, 0(a1)	/* AR2312_MEM_CFG1 */
+	sync
+
+	li	t0, KSEG1 | AR2312_SDRAM0
+	or	t0, 0x23000	/* 16bit burst */
+	lw	zero, 0(t0)
+
+	/* Program configuration register */
+	li	t0, MEM_CFG0_C | MEM_CFG0_C2 | MEM_CFG0_R1 | \
+			MEM_CFG0_B0 | MEM_CFG0_X
+	sw	t0, 0(a0)	/* AR2312_MEM_CFG0 */
+	sync
+
+	li	t0, AR2312_SDRAM_MEMORY_REFRESH_VALUE
+	sw	t0, 0(a2)	/* AR2312_MEM_REF */
+	sync
+
+	/* Clear I and M and set cfg1 to the normal operational value */
+	sw	a3, 0(a1)	/* AR2312_MEM_CFG1 */
+	sync
+
+	pbl_sleep	t2, 10
+
+	/* Now we need to set size of RAM to prevent some wired errors.
+	 * Since I do not have access to any board with two SDRAM chips, or
+	 * any was registered in the wild - we will support only one. */
+	/* So, lets find the beef */
+	li	a0, KSEG1 | AR2312_MEM_CFG1
+	li	a1, KSEG1 | AR2312_SDRAM0
+	li	a2, 0xdeadbeef
+	li	t0, 0x200000
+	li	t1, MEM_CFG1_AC_2
+
+	/* We will write some magic word to the beginning of RAM,
+	 * and see if it appears somewhere else. If yes, we made
+	 * a travel around the world. */
+
+	/* But first of all save original state of the first RAM word. */
+	lw	a3, 0(a1)
+	sw	a2, 0(a1)
+
+find_the_beef:
+	or	t2, a1, t0
+	lw	t3, 0(t2)
+	beq	a2, t3, 1f
+	 nop
+	sll	t0, 1
+	add	t1, 1
+	/* we should have some limit here. */
+	blt	t1, MEM_CFG1_AC_64, find_the_beef
+	 nop
+	b	make_beefsteak
+	 nop
+
+	/* additional paranoid check */
+1:
+	sw	zero, 0(a1)
+	lw	t3, 0(t2)
+	bne	zero, t3, find_the_beef
+	 nop
+
+make_beefsteak:
+	/* create new config for AR2312_MEM_CFG1 and overwrite it */
+	sll	t1, MEM_CFG1_AC0_S
+	or	t2, t1, MEM_CFG1_E0
+	sw	t2, 0(a0)	/* AR2312_MEM_CFG1 */
+
+	/* restore original state of the first RAM word */
+	sw	a3, 0(a1)
+
+	.set	pop
+.endm
+
+#endif /* __ASM_MACH_AR2312_PBL_MACROS_H */
-- 
1.8.1.2



From chf.fritz at googlemail.com  Wed Jun 19 05:33:15 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Wed, 19 Jun 2013 11:33:15 +0200
Subject: [PATCH 1/2] omap-fb: add driver
Message-ID: <1371634395.4111.54.camel@mars>

This patch adds omap display controller support. Currently only
OMAP4 DSS is supported.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
 drivers/video/Kconfig  |    8 +
 drivers/video/Makefile |    1 +
 drivers/video/omap.c   |  524 ++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/video/omap.h   |  187 +++++++++++++++++
 4 files changed, 720 insertions(+)
 create mode 100644 drivers/video/omap.c
 create mode 100644 drivers/video/omap.h

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 6d6b08f..0639d9c 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -45,6 +45,14 @@ config DRIVER_VIDEO_S3C24XX
 	help
 	  Add support for the S3C244x LCD controller.
 
+config DRIVER_VIDEO_OMAP
+	bool "OMAP framebuffer driver"
+	depends on ARCH_OMAP4
+	help
+	  Add support for OMAP Display Controller. Currently this
+	  driver only supports OMAP4 SoCs in DISPC parallel mode on
+	  LCD2 (MIPI DPI).
+
 if DRIVER_VIDEO_S3C24XX
 
 config DRIVER_VIDEO_S3C_VERBOSE
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 7429141..67169d1 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_DRIVER_VIDEO_IMX_IPU) += imx-ipu-fb.o
 obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
 obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
 obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
+obj-$(CONFIG_DRIVER_VIDEO_OMAP) += omap.o
diff --git a/drivers/video/omap.c b/drivers/video/omap.c
new file mode 100644
index 0000000..487aca6
--- /dev/null
+++ b/drivers/video/omap.c
@@ -0,0 +1,524 @@
+/*
+ * TI Omap Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.com>
+ *   Based on work by Enrico Scholz, sponsored by Phytec
+ *
+ * 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.
+ */
+
+#include <driver.h>
+#include <fb.h>
+#include <errno.h>
+#include <xfuncs.h>
+#include <init.h>
+#include <stdio.h>
+#include <io.h>
+#include <common.h>
+#include <malloc.h>
+#include <common.h>
+#include <clock.h>
+
+#include <mach/omap4-silicon.h>
+#include <mach/omap-fb.h>
+
+#include <asm/mmu.h>
+
+#include "omap.h"
+
+struct omapfb_device {
+	struct fb_info info;
+	struct device_d *dev;
+
+	struct omapfb_display const *cur_display;
+
+	struct omapfb_display const *displays;
+	size_t num_displays;
+
+	void __iomem *dss;
+	void __iomem *dispc;
+
+	struct {
+		void __iomem *addr;
+		size_t size;
+	} prealloc_screen;
+
+	struct {
+		uint32_t dispc_control;
+		uint32_t dispc_pol_freq;
+	} shadow;
+
+	struct {
+		unsigned int dss_clk_hz;
+		unsigned int lckd;
+		unsigned int pckd;
+	} divisor;
+	size_t dma_size;
+	void (*enable_fn)(int);
+
+	struct fb_videomode	video_modes[];
+};
+
+static inline struct omapfb_device *to_omapfb(const struct fb_info *info)
+{
+	return container_of(info, struct omapfb_device, info);
+}
+
+static void omapfb_enable(struct fb_info *info)
+{
+	struct omapfb_device *fbi = to_omapfb(info);
+
+	dev_dbg(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(1);
+
+	udelay(fbi->cur_display->power_on_delay * 1000u);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL, O4_DISPC_CONTROL2);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_VID1_ATTRIBUTES) |
+		DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE, O4_DISPC_VID1_ATTRIBUTES);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_GOLCD, O4_DISPC_CONTROL2);
+}
+
+static void omapfb_disable(struct fb_info *info)
+{
+	struct omapfb_device *fbi = to_omapfb(info);
+
+	dev_dbg(fbi->dev, "%s\n", __func__);
+
+	if (!fbi->cur_display) {
+		dev_err(fbi->dev, "no valid mode set\n");
+		return;
+	}
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) &
+		~(DSS_DISPC_CONTROL_LCDENABLE |
+		DSS_DISPC_CONTROL_LCDENABLESIGNAL), O4_DISPC_CONTROL2);
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_VID1_ATTRIBUTES) &
+		~(DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE),
+		O4_DISPC_VID1_ATTRIBUTES);
+
+	if (fbi->prealloc_screen.addr == NULL) {
+		/* free frame buffer; but only when screen is not
+		* preallocated */
+		if (info->screen_base)
+			dma_free_coherent(info->screen_base, fbi->dma_size);
+	}
+
+	info->screen_base = NULL;
+
+	udelay(fbi->cur_display->power_off_delay * 1000u);
+
+	if (fbi->enable_fn)
+		fbi->enable_fn(0);
+}
+
+static void omapfb_calc_divisor(struct omapfb_device *fbi,
+			struct fb_videomode const *mode)
+{
+	unsigned int l, k, t, b;
+
+	b = UINT_MAX;
+	for (l = 1; l < 256; l++) {
+		for (k = 1; k < 256; k++) {
+			t = abs(mode->pixclock * 100 -
+				(fbi->divisor.dss_clk_hz / l / k));
+			if (t <= b) {
+				b = t;
+				fbi->divisor.lckd = l;
+				fbi->divisor.pckd = k;
+			}
+		}
+	}
+}
+
+static unsigned int omapfb_calc_format(struct fb_info const *info)
+{
+	struct omapfb_device *fbi = to_omapfb(info);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		return 9;
+	case 32:
+		return 0x8; /* xRGB24-8888 (32-bit container) */
+	default:
+		dev_err(fbi->dev, "%s: unsupported bpp %d\n", __func__,
+			info->bits_per_pixel);
+		return 0;
+	}
+}
+
+struct omapfb_colors {
+	struct fb_bitfield	red;
+	struct fb_bitfield	green;
+	struct fb_bitfield	blue;
+	struct fb_bitfield	transp;
+};
+
+static struct omapfb_colors const omapfb_col[] = {
+	[0] = {
+		.red	= { .length = 0, .offset = 0 },
+	},
+	[1] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+	},
+	[2] = {
+		.blue	= { .length = 8, .offset = 0 },
+		.green	= { .length = 8, .offset = 8 },
+		.red	= { .length = 8, .offset = 16 },
+		.transp	= { .length = 8, .offset = 24 },
+	},
+};
+
+static void omapfb_fill_shadow(struct omapfb_device *fbi,
+				struct omapfb_display const *display)
+{
+	fbi->shadow.dispc_control = 0;
+	fbi->shadow.dispc_pol_freq = 0;
+
+	fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_STNTFT;
+
+	switch (display->config & OMAP_DSS_LCD_DATALINES_msk) {
+	case OMAP_DSS_LCD_DATALINES_12:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_12;
+		break;
+	case OMAP_DSS_LCD_DATALINES_16:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_16;
+		break;
+	case OMAP_DSS_LCD_DATALINES_18:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_18;
+		break;
+	case OMAP_DSS_LCD_DATALINES_24:
+		fbi->shadow.dispc_control |= DSS_DISPC_CONTROL_TFTDATALINES_24;
+		break;
+	}
+
+	if (display->config & OMAP_DSS_LCD_IPC)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IPC;
+
+	if (display->config & OMAP_DSS_LCD_IVS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IVS;
+
+	if (display->config & OMAP_DSS_LCD_IHS)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IHS;
+
+	if (display->config & OMAP_DSS_LCD_IEO)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_IEO;
+
+	if (display->config & OMAP_DSS_LCD_RF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_RF;
+
+	if (display->config & OMAP_DSS_LCD_ONOFF)
+		fbi->shadow.dispc_pol_freq |= DSS_DISPC_POL_FREQ_ONOFF;
+}
+
+static int omapfb_find_display_by_name(struct omapfb_device *fbi,
+		const char *name)
+{
+	int i;
+
+	for (i = 0; i < fbi->num_displays; ++i) {
+		if (strcmp(name, fbi->displays[i].mode.name) == 0)
+			return i;
+	}
+	return -ENXIO;
+}
+
+static int omapfb_activate_var(struct fb_info *info)
+{
+	struct omapfb_device *fbi = to_omapfb(info);
+	struct fb_videomode const *mode = info->mode;
+	size_t size = mode->xres * mode->yres * (info->bits_per_pixel / 8);
+	int rc;
+	unsigned int fmt = omapfb_calc_format(info);
+	struct omapfb_colors const *cols;
+	struct omapfb_display const *new_display = NULL;
+
+	rc = omapfb_find_display_by_name(fbi, mode->name);
+	if (rc < 0) {
+		dev_err(fbi->dev, "no display found for this mode '%s'\n",
+			mode->name);
+		goto out;
+	}
+	new_display = &fbi->displays[rc];
+
+	/*Free old screen buf*/
+	if (!fbi->prealloc_screen.addr && info->screen_base)
+		dma_free_coherent(info->screen_base, fbi->dma_size);
+
+	fbi->dma_size = PAGE_ALIGN(size);
+
+	if (!fbi->prealloc_screen.addr) {
+		/* case 1: no preallocated screen */
+		info->screen_base = dma_alloc_coherent(size);
+	} else if (fbi->prealloc_screen.size < fbi->dma_size) {
+		/* case 2: preallocated screen, but too small */
+		dev_err(fbi->dev,
+			"allocated framebuffer too small (%zu < %zu)\n",
+			fbi->prealloc_screen.size, fbi->dma_size);
+		rc = -ENOMEM;
+		goto out;
+	} else {
+		/* case 3: preallocated screen */
+		info->screen_base = fbi->prealloc_screen.addr;
+	}
+
+	omapfb_fill_shadow(fbi, new_display);
+
+	omapfb_calc_divisor(fbi, mode);
+
+	switch (info->bits_per_pixel) {
+	case 24:
+		cols = &omapfb_col[1];
+		break;
+	case 32:
+		cols = &omapfb_col[2];
+		break;
+	default:
+		cols = &omapfb_col[0];
+	}
+
+	info->red = cols->red;
+	info->green = cols->green;
+	info->blue = cols->blue;
+	info->transp = cols->transp;
+
+	o4_dispc_write(fbi->shadow.dispc_control, O4_DISPC_CONTROL2);
+
+	o4_dispc_write(fbi->shadow.dispc_pol_freq, O4_DISPC_POL_FREQ2);
+
+	o4_dispc_write(DSS_DISPC_TIMING_H_HSW(mode->hsync_len - 1) |
+		DSS_DISPC_TIMING_H_HFP(mode->right_margin - 1) |
+		DSS_DISPC_TIMING_H_HBP(mode->left_margin - 1),
+		O4_DISPC_TIMING_H2);
+
+	o4_dispc_write(DSS_DISPC_TIMING_V_VSW(mode->vsync_len - 1) |
+		DSS_DISPC_TIMING_V_VFP(mode->lower_margin) |
+		DSS_DISPC_TIMING_V_VBP(mode->upper_margin), O4_DISPC_TIMING_V2);
+
+	o4_dispc_write(DSS_DISPC_DIVISOR_ENABLE | DSS_DISPC_DIVISOR_LCD(1),
+		O4_DISPC_DIVISOR);
+
+	o4_dispc_write(DSS_DISPC_DIVISOR2_LCD(fbi->divisor.lckd) |
+		DSS_DISPC_DIVISOR2_PCD(fbi->divisor.pckd), O4_DISPC_DIVISOR2);
+
+	o4_dispc_write(DSS_DISPC_SIZE_LCD_PPL(mode->xres - 1) |
+		DSS_DISPC_SIZE_LCD_LPP(mode->yres - 1), O4_DISPC_SIZE_LCD2);
+
+	o4_dispc_write(0x0000ff00, O4_DISPC_DEFAULT_COLOR2);
+
+	/* we use VID1 */
+	o4_dispc_write((uintptr_t)info->screen_base, O4_DISPC_VID1_BA0);
+	o4_dispc_write((uintptr_t)info->screen_base, O4_DISPC_VID1_BA1);
+
+	o4_dispc_write(DSS_DISPC_VIDn_POSITION_VIDPOSX(0) |
+		DSS_DISPC_VIDn_POSITION_VIDPOSY(0), O4_DISPC_VID1_POSITION);
+	o4_dispc_write(DSS_DISPC_VIDn_SIZE_VIDSIZEX(mode->xres - 1) |
+		DSS_DISPC_VIDn_SIZE_VIDSIZEY(mode->yres - 1),
+		O4_DISPC_VID1_SIZE);
+	o4_dispc_write(DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(mode->xres - 1) |
+		DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(mode->yres - 1),
+		O4_DISPC_VID1_PICTURE_SIZE);
+	o4_dispc_write(1, O4_DISPC_VID1_ROW_INC);
+	o4_dispc_write(1, O4_DISPC_VID1_PIXEL_INC);
+
+	o4_dispc_write(0xfff, O4_DISPC_VID1_PRELOAD);
+
+	o4_dispc_write(DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(fmt) |
+		DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 |
+		DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE |
+		DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD,
+		O4_DISPC_VID1_ATTRIBUTES);
+
+	rc = wait_on_timeout(OFB_TIMEOUT,
+		!(o4_dispc_read(O4_DISPC_CONTROL2) &
+		DSS_DISPC_CONTROL_GOLCD));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: dispc golcd\n");
+		goto out;
+	}
+
+	o4_dispc_write(o4_dispc_read(O4_DISPC_CONTROL2) |
+		DSS_DISPC_CONTROL_GOLCD, O4_DISPC_CONTROL2);
+
+	fbi->cur_display = new_display;
+	info->xres = mode->xres;
+	info->yres = mode->yres;
+
+	rc = 0;
+
+out:
+	return rc;
+}
+
+static int omapfb_reset(struct omapfb_device const *fbi)
+{
+	uint32_t v = o4_dispc_read(O4_DISPC_CONTROL2);
+	int rc;
+
+	/* step 1: stop the LCD controller */
+	if (v & DSS_DISPC_CONTROL_LCDENABLE) {
+		o4_dispc_write(v & ~DSS_DISPC_CONTROL_LCDENABLE,
+			O4_DISPC_CONTROL2);
+
+		o4_dispc_write(DSS_DISPC_IRQSTATUS_FRAMEDONE2,
+			O4_DISPC_IRQSTATUS);
+
+		rc = wait_on_timeout(OFB_TIMEOUT,
+			((o4_dispc_read(O4_DISPC_IRQSTATUS) &
+			DSS_DISPC_IRQSTATUS_FRAMEDONE) != 0));
+
+		if (rc) {
+			dev_err(fbi->dev, "timeout: irqstatus framedone\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	/* step 2: wait for reset done status */
+	rc = wait_on_timeout(OFB_TIMEOUT,
+		(o4_dss_read(O4_DSS_SYSSTATUS) &
+		DSS_DSS_SYSSTATUS_RESETDONE));
+
+	if (rc) {
+		dev_err(fbi->dev, "timeout: sysstatus resetdone\n");
+		return -ETIMEDOUT;
+	}
+
+	/* DSS_CTL: set to reset value */
+	o4_dss_write(0, O4_DSS_CTRL);
+
+	return 0;
+}
+
+static struct fb_ops omapfb_ops = {
+	.fb_enable		= omapfb_enable,
+	.fb_disable		= omapfb_disable,
+	.fb_activate_var	= omapfb_activate_var,
+};
+
+static int omapfb_probe(struct device_d *dev)
+{
+	struct omapfb_platform_data const *pdata = dev->platform_data;
+	struct omapfb_device *fbi;
+	struct fb_info *info;
+	int rc;
+	size_t i;
+
+	fbi = xzalloc(sizeof *fbi +
+		pdata->num_displays * sizeof fbi->video_modes[0]);
+	info = &fbi->info;
+
+	fbi->dev = dev;
+
+	/* CM_DSS_CLKSTCTRL (TRM: 935) trigger SW_WKUP */
+	__raw_writel(0x2, 0x4a009100); /* TODO: move this to clockmanagement */
+
+	fbi->dss   = dev_request_mem_region_by_name(dev, "omap4_dss");
+	fbi->dispc = dev_request_mem_region_by_name(dev, "omap4_dispc");
+
+	if (!fbi->dss || !fbi->dispc) {
+		dev_err(dev, "Insufficient register description\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	dev_info(dev, "HW-Revision 0x%04x 0x%04x\n",
+		o4_dss_read(O4_DISPC_REVISION),
+		o4_dss_read(O4_DSS_REVISION));
+
+	if (!pdata->dss_clk_hz | !pdata->displays | !pdata->num_displays |
+		!pdata->bpp) {
+		dev_err(dev, "Insufficient omapfb_platform_data\n");
+		rc = -EINVAL;
+		goto out;
+	}
+
+	fbi->enable_fn    = pdata->enable;
+	fbi->displays     = pdata->displays;
+	fbi->num_displays = pdata->num_displays;
+	fbi->divisor.dss_clk_hz = pdata->dss_clk_hz;
+
+	for (i = 0; i < pdata->num_displays; ++i)
+		fbi->video_modes[i] = pdata->displays[i].mode;
+
+	info->mode_list = fbi->video_modes;
+	info->num_modes = pdata->num_displays;
+
+	info->priv = fbi;
+	info->fbops = &omapfb_ops;
+	info->bits_per_pixel = pdata->bpp;
+
+	if (pdata->screen) {
+		if (!IS_ALIGNED(pdata->screen->start, PAGE_SIZE) ||
+			!IS_ALIGNED(resource_size(pdata->screen), PAGE_SIZE)) {
+			dev_err(dev, "screen resource not aligned\n");
+			rc = -EINVAL;
+			goto out;
+		}
+		fbi->prealloc_screen.addr =
+				(void __iomem *)pdata->screen->start;
+		fbi->prealloc_screen.size = resource_size(pdata->screen);
+		remap_range(fbi->prealloc_screen.addr,
+			fbi->prealloc_screen.size,
+			mmu_get_pte_uncached_flags());
+	}
+
+	rc = omapfb_reset(fbi);
+	if (rc < 0) {
+		dev_err(dev, "failed to reset: %d\n", rc);
+		goto out;
+	}
+
+	rc = register_framebuffer(info);
+	if (rc < 0) {
+		dev_err(dev, "failed to register framebuffer: %d\n", rc);
+		goto out;
+	}
+
+	rc = 0;
+	dev_info(dev, "registered\n");
+
+out:
+	if (rc < 0)
+		free(fbi);
+
+	return rc;
+}
+
+static struct driver_d omapfb_driver = {
+	.name	= "omap_fb",
+	.probe	= omapfb_probe,
+};
+
+static int omapfb_init(void)
+{
+	return platform_driver_register(&omapfb_driver);
+}
+
+device_initcall(omapfb_init);
diff --git a/drivers/video/omap.h b/drivers/video/omap.h
new file mode 100644
index 0000000..ac9e1ce
--- /dev/null
+++ b/drivers/video/omap.h
@@ -0,0 +1,187 @@
+/*
+ * TI Omap4 Frame Buffer device driver
+ *
+ * Copyright (C) 2013 Christoph Fritz <chf.fritz at googlemail.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.
+ */
+
+#ifndef H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+#define H_BAREBOX_DRIVER_VIDEO_OMAP4_REGS_H
+
+#include <types.h>
+#include <common.h>
+
+#define OFB_TIMEOUT	(128 * USECOND)
+
+#define _ofb_read(io, reg)		__raw_readl((io)+(reg))
+#define _ofb_write(val, io, reg)	__raw_writel((val), (io)+(reg))
+
+/* TRM: 10.1.3.2 DSS Registers */
+#define O4_DSS_REVISION	0x0
+#define O4_DSS_SYSSTATUS	0x14
+#define O4_DSS_CTRL		0x40
+#define O4_DSS_STATUS		0x5c
+
+#define o4_dss_read(reg)		_ofb_read(fbi->dss, reg)
+#define o4_dss_write(val, reg)		_ofb_write(val, fbi->dss, reg)
+
+/* TRM: 10.2.7.3 Display Controller Registers */
+#define O4_DISPC_REVISION		0x0
+#define O4_DISPC_IRQSTATUS		0x18
+#define O4_DISPC_VID1_BA0		0xbc
+#define O4_DISPC_VID1_BA1		0xc0
+#define O4_DISPC_VID1_POSITION		0xc4
+#define O4_DISPC_VID1_SIZE		0xc8
+#define O4_DISPC_VID1_ATTRIBUTES	0xcc
+#define O4_DISPC_VID1_ROW_INC		0xd8
+#define O4_DISPC_VID1_PIXEL_INC	0xdc
+#define O4_DISPC_VID1_PICTURE_SIZE	0xe4
+#define O4_DISPC_VID1_PRELOAD		0x230
+#define O4_DISPC_CONTROL2		0x238
+#define O4_DISPC_DEFAULT_COLOR2	0x3ac
+#define O4_DISPC_SIZE_LCD2		0x3cc
+#define O4_DISPC_TIMING_H2		0x400
+#define O4_DISPC_TIMING_V2		0x404
+#define O4_DISPC_POL_FREQ2		0x408
+#define O4_DISPC_DIVISOR2		0x40c
+#define O4_DISPC_DIVISOR		0x804
+
+#define o4_dispc_read(reg)		_ofb_read(fbi->dispc, reg)
+#define o4_dispc_write(val, reg)	_ofb_write(val, fbi->dispc, reg)
+
+#define DSS_DISPC_VIDn_POSITION_VIDPOSX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_POSITION_VIDPOSY(_y)		((_y) << 16)
+
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEX(_x)	((_x) << 0)
+#define DSS_DISPC_VIDn_PICTURE_SIZE_VIDORGSIZEY(_y)	((_y) << 16)
+
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEX(_x)		((_x) << 0)
+#define DSS_DISPC_VIDn_SIZE_VIDSIZEY(_y)		((_y) << 16)
+
+#define DSS_DISPC_SIZE_LCD_PPL(_x)			((_x) << 0)
+#define DSS_DISPC_SIZE_LCD_LPP(_y)			((_y) << 16)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDENABLE		(1u << 0)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(_fmt)	((_fmt) << 1)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB12	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(4u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(5u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB16	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(6u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB16o	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(7u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB24u	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(8u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGB24p	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(9u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_YUV2	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(10u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_UYVY	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(11u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_ARGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(12u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_RGBA32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(13u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT_xRGB32	\
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDFORMAT(14u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(_b)	((_b) << 14)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_2x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_4x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE_8x128 \
+	DSS_DISPC_VIDn_ATTRIBUTES_VIDBURSTSIZE(2u)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDCHANNELOUT	(1u << 16)
+#define DSS_DISPC_VIDn_ATTRIBUTES_SELFREFRESHAUTO	(1u << 17)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDFIFOPRELOAD	(1u << 19)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDVERTICALTAPS	(1u << 21)
+#define DSS_DISPC_VIDn_ATTRIBUTES_DOUBLESTRIDE		(1u << 22)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDARBITRATION	(1u << 23)
+#define DSS_DISPC_VIDn_ATTRIBUTES_VIDSELFREFRESH	(1u << 24)
+#define DSS_DISPC_VIDn_ATTRIBUTES_ZORDERENABLE		(1u << 25)
+
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(_b)  ((_b) << 30)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_PRIMARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(0u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_SECONDARY_LCD \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(1u)
+#define DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2_WRITEBACK_MEM \
+	DSS_DISPC_VIDn_ATTRIBUTES_CHANNELOUT2(3u)
+
+#define DSS_DISPC_CONTROL_LCDENABLE			(1u << 0)
+#define DSS_DISPC_CONTROL_TVENABLE			(1u << 1)
+#define DSS_DISPC_CONTROL_MONOCOLOR			(1u << 2)
+#define DSS_DISPC_CONTROL_STNTFT			(1u << 3)
+#define DSS_DISPC_CONTROL_M8B				(1u << 4)
+#define DSS_DISPC_CONTROL_GOLCD			(1u << 5)
+#define DSS_DISPC_CONTROL_GOTV				(1u << 6)
+#define DSS_DISPC_CONTROL_STDITHERENABLE		(1u << 7)
+
+#define DSS_DISPC_CONTROL_TFTDATALINES(_l)		((_l) << 8)
+#define DSS_DISPC_CONTROL_TFTDATALINES_12 \
+	DSS_DISPC_CONTROL_TFTDATALINES(0u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_16 \
+	DSS_DISPC_CONTROL_TFTDATALINES(1u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_18 \
+	DSS_DISPC_CONTROL_TFTDATALINES(2u)
+#define DSS_DISPC_CONTROL_TFTDATALINES_24 \
+	DSS_DISPC_CONTROL_TFTDATALINES(3u)
+
+#define DSS_DISPC_CONTROL_STALLMODE			(1u << 11)
+#define DSS_DISPC_CONTROL_OVERLAYOPTIMIZATION		(1u << 12)
+#define DSS_DISPC_CONTROL_GPIN0			(1u << 13) /* ro */
+#define DSS_DISPC_CONTROL_GPIN1			(1u << 14) /* ro */
+#define DSS_DISPC_CONTROL_GPOUT0			(1u << 15)
+#define DSS_DISPC_CONTROL_GPOUT1			(1u << 16)
+#define DSS_DISPC_CONTROL_HT(_ht)			((_ht) << 17)
+#define DSS_DISPC_CONTROL_TDMENABLE			(1u << 20)
+#define DSS_DISPC_CONTROL_TDMPARALLELMODE(_pm)		((_pm) << 21)
+#define DSS_DISPC_CONTROL_TDMCYCLEFORMAT(_cf)		((_cf) << 23)
+#define DSS_DISPC_CONTROL_TDMUNUSEDBITS(_ub)		((_ub) << 25)
+#define DSS_DISPC_CONTROL_PCKFREEENABLE		(1u << 27)
+#define DSS_DISPC_CONTROL_LCDENABLESIGNAL		(1u << 28)
+#define DSS_DISPC_CONTROL_LCDENABLEPOL			(1u << 29)
+#define DSS_DISPC_CONTROL_SPATIALTEMPD(_df)		((_df) << 30)
+
+#define DSS_DISPC_POL_FREQ_IVS				(1u << 12)
+#define DSS_DISPC_POL_FREQ_IHS				(1u << 13)
+#define DSS_DISPC_POL_FREQ_IPC				(1u << 14)
+#define DSS_DISPC_POL_FREQ_IEO				(1u << 15)
+#define DSS_DISPC_POL_FREQ_RF				(1u << 16)
+#define DSS_DISPC_POL_FREQ_ONOFF			(1u << 17)
+
+#define DSS_DISPC_TIMING_H_HSW(_hsw)			((_hsw) << 0)
+#define DSS_DISPC_TIMING_H_HFP(_hfp)			((_hfp) << 8)
+#define DSS_DISPC_TIMING_H_HBP(_hbp)			((_hbp) << 20)
+
+#define DSS_DISPC_TIMING_V_VSW(_vsw)			((_vsw) << 0)
+#define DSS_DISPC_TIMING_V_VFP(_vfp)			((_vfp) << 8)
+#define DSS_DISPC_TIMING_V_VBP(_vbp)			((_vbp) << 20)
+
+#define DSS_DISPC_DIVISOR_ENABLE			(1u << 0)
+#define DSS_DISPC_DIVISOR_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_DIVISOR2_PCD(_pcd)			((_pcd) << 0)
+#define DSS_DISPC_DIVISOR2_LCD(_lcd)			((_lcd) << 16)
+
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE			(1u << 0)
+#define DSS_DISPC_IRQSTATUS_FRAMEDONE2			(1u << 22)
+
+#define DSS_DSS_SYSSTATUS_RESETDONE			(1u << 0)
+
+#endif	/* H_BAREBOX_DRIVER_VIDEO_O4_REGS_H */
-- 
1.7.10.4





From chf.fritz at googlemail.com  Wed Jun 19 05:39:41 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Wed, 19 Jun 2013 11:39:41 +0200
Subject: [PATCH 2/2] ARM omap-fb: add board helper code
In-Reply-To: <1371634395.4111.54.camel@mars>
References: <1371634395.4111.54.camel@mars>
Message-ID: <1371634781.28361.0.camel@mars>

This patch adds OMAP machine dependent framebuffer code so that
board files can make use of driver omap-fb.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
 arch/arm/mach-omap/Makefile               |    2 +-
 arch/arm/mach-omap/include/mach/omap-fb.h |   47 +++++++++++++++++++++++++++++
 arch/arm/mach-omap/omap_fb.c              |   34 +++++++++++++++++++++
 3 files changed, 82 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-omap/include/mach/omap-fb.h
 create mode 100644 arch/arm/mach-omap/omap_fb.c

diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index 94e42c6..bc5daab 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -15,7 +15,7 @@
 # GNU General Public License for more details.
 #
 #
-obj-$(CONFIG_ARCH_OMAP) += syslib.o omap_devices.o
+obj-$(CONFIG_ARCH_OMAP) += syslib.o omap_devices.o omap_fb.o
 pbl-$(CONFIG_ARCH_OMAP) += syslib.o
 obj-$(CONFIG_OMAP_CLOCK_SOURCE_S32K) += s32k_clksource.o
 obj-$(CONFIG_OMAP_CLOCK_SOURCE_DMTIMER0) += dmtimer0.o
diff --git a/arch/arm/mach-omap/include/mach/omap-fb.h b/arch/arm/mach-omap/include/mach/omap-fb.h
new file mode 100644
index 0000000..f68dc1a
--- /dev/null
+++ b/arch/arm/mach-omap/include/mach/omap-fb.h
@@ -0,0 +1,47 @@
+#ifndef H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+#define H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H
+
+#include <fb.h>
+
+#define OMAP_DSS_LCD_TFT	(1u << 0)
+#define OMAP_DSS_LCD_IVS	(1u << 1)
+#define OMAP_DSS_LCD_IHS	(1u << 2)
+#define OMAP_DSS_LCD_IPC	(1u << 3)
+#define OMAP_DSS_LCD_IEO	(1u << 4)
+#define OMAP_DSS_LCD_RF	(1u << 5)
+#define OMAP_DSS_LCD_ONOFF	(1u << 6)
+
+#define OMAP_DSS_LCD_DATALINES(_l)	((_l) << 10)
+#define OMAP_DSS_LCD_DATALINES_msk	OMAP_DSS_LCD_DATALINES(3u)
+#define OMAP_DSS_LCD_DATALINES_12	OMAP_DSS_LCD_DATALINES(0u)
+#define OMAP_DSS_LCD_DATALINES_16	OMAP_DSS_LCD_DATALINES(1u)
+#define OMAP_DSS_LCD_DATALINES_18	OMAP_DSS_LCD_DATALINES(2u)
+#define OMAP_DSS_LCD_DATALINES_24	OMAP_DSS_LCD_DATALINES(3u)
+
+struct omapfb_display {
+	struct fb_videomode mode;
+
+	unsigned long config;
+
+	unsigned int power_on_delay;
+	unsigned int power_off_delay;
+};
+
+struct omapfb_platform_data {
+	struct omapfb_display const *displays;
+	size_t num_displays;
+
+	unsigned int dss_clk_hz;
+
+	unsigned int bpp;
+
+	struct resource const *screen;
+
+	void (*enable)(int p);
+};
+
+struct device_d;
+struct device_d *omap_add_display(struct omapfb_platform_data *o_pdata);
+
+
+#endif	/* H_BAREBOX_ARCH_ARM_MACH_OMAP_MACH_FB4_H */
diff --git a/arch/arm/mach-omap/omap_fb.c b/arch/arm/mach-omap/omap_fb.c
new file mode 100644
index 0000000..ae318d8
--- /dev/null
+++ b/arch/arm/mach-omap/omap_fb.c
@@ -0,0 +1,34 @@
+#include <driver.h>
+#include <common.h>
+#include <linux/ioport.h>
+#include <mach/omap-fb.h>
+
+#if defined(CONFIG_DRIVER_VIDEO_OMAP)
+static struct resource omapfb_resources[] = {
+	{
+		.name	= "omap4_dss",
+		.start	= 0x48040000,
+		.end	= 0x48040000 + 512 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	}, {
+		.name	= "omap4_dispc",
+		.start	= 0x48041000,
+		.end	= 0x48041000 + 3072 - 1,
+		.flags	= IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+	},
+};
+
+struct device_d *omap_add_display(struct omapfb_platform_data *o_pdata)
+{
+	return add_generic_device_res("omap_fb", -1,
+				      omapfb_resources,
+				      ARRAY_SIZE(omapfb_resources),
+				      o_pdata);
+}
+#else
+struct device_d *omap_add_display(struct omapfb_platform_data *o_pdata)
+{
+	return NULL;
+}
+#endif
+EXPORT_SYMBOL(omap_add_display);
-- 
1.7.10.4





From W.Vanhauwaert at TELEVIC.com  Wed Jun 19 08:12:42 2013
From: W.Vanhauwaert at TELEVIC.com (Vanhauwaert Wouter)
Date: Wed, 19 Jun 2013 14:12:42 +0200
Subject: Boot imx53 from spi nor flash
Message-ID: <E78BBE677EB9144B8F0A0A29674CD5338ED0163EE6@SRV-VS06.TELEVIC.COM>

I want to be able to boot my imx53 from spi nor flash, but am a bit lost on how to accomplish this.
How do I have to configure my boot source? Do I have to add this 0x400 offset to the image? Any reference?

Grtz,
Wouter


From s.hauer at pengutronix.de  Wed Jun 19 08:18:18 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 14:18:18 +0200
Subject: Boot imx53 from spi nor flash
In-Reply-To: <E78BBE677EB9144B8F0A0A29674CD5338ED0163EE6@SRV-VS06.TELEVIC.COM>
References: <E78BBE677EB9144B8F0A0A29674CD5338ED0163EE6@SRV-VS06.TELEVIC.COM>
Message-ID: <20130619121818.GG32299@pengutronix.de>

On Wed, Jun 19, 2013 at 02:12:42PM +0200, Vanhauwaert Wouter wrote:
> I want to be able to boot my imx53 from spi nor flash, but am a bit lost on how to accomplish this.
> How do I have to configure my boot source? Do I have to add this 0x400 offset to the image? Any reference?

If an image boots from SD/MMC it should also boot from SPI NOR flash.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 19 15:51:49 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 21:51:49 +0200
Subject: [PATCHv3 1/4] ARM: OMAP: AM33xx: Add muxing function for spi0
In-Reply-To: <1371625785-27704-1-git-send-email-t.gamez@phytec.de>
References: <1371625785-27704-1-git-send-email-t.gamez@phytec.de>
Message-ID: <20130619195149.GK32299@pengutronix.de>

On Wed, Jun 19, 2013 at 09:09:42AM +0200, Teresa G?mez wrote:
> Signed-off-by: Teresa G?mez <t.gamez at phytec.de>

Applied all, 

Thanks
 Sascha

> ---
>  arch/arm/mach-omap/am33xx_mux.c              |    5 +++++
>  arch/arm/mach-omap/include/mach/am33xx-mux.h |    1 +
>  2 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/mach-omap/am33xx_mux.c b/arch/arm/mach-omap/am33xx_mux.c
> index 424d120..abc8586 100644
> --- a/arch/arm/mach-omap/am33xx_mux.c
> +++ b/arch/arm/mach-omap/am33xx_mux.c
> @@ -314,3 +314,8 @@ void am33xx_enable_mmc0_pin_mux(void)
>  {
>  	configure_module_pin_mux(mmc0_pin_mux);
>  }
> +
> +void am33xx_enable_spi0_pin_mux(void)
> +{
> +	configure_module_pin_mux(spi0_pin_mux);
> +}
> diff --git a/arch/arm/mach-omap/include/mach/am33xx-mux.h b/arch/arm/mach-omap/include/mach/am33xx-mux.h
> index 44b93bd..d6b19dd 100644
> --- a/arch/arm/mach-omap/include/mach/am33xx-mux.h
> +++ b/arch/arm/mach-omap/include/mach/am33xx-mux.h
> @@ -256,5 +256,6 @@ extern void am33xx_enable_i2c2_pin_mux(void);
>  extern void am33xx_enable_uart0_pin_mux(void);
>  extern void am33xx_enable_uart2_pin_mux(void);
>  extern void am33xx_enable_mmc0_pin_mux(void);
> +extern void am33xx_enable_spi0_pin_mux(void);
>  
>  #endif /*__AM33XX_MUX_H__ */
> -- 
> 1.7.0.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 19 15:52:20 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 21:52:20 +0200
Subject: [PATCH] ARM: AM33xx: pcm051: Add network support
In-Reply-To: <1371625882-28767-1-git-send-email-t.gamez@phytec.de>
References: <1371625882-28767-1-git-send-email-t.gamez@phytec.de>
Message-ID: <20130619195220.GL32299@pengutronix.de>

On Wed, Jun 19, 2013 at 09:11:22AM +0200, Teresa G?mez wrote:
> Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
> ---

Also applied.

Thanks
 Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 19 16:53:39 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 22:53:39 +0200
Subject: Some small menu updates
Message-ID: <1371675222-25433-1-git-send-email-s.hauer@pengutronix.de>


Some minor fixes to the menu code.

Sascha

----------------------------------------------------------------
Sascha Hauer (3):
      menu: Align entries
      Fix gotoXY argument order
      menu: Make action callback optional

 common/menu.c     | 15 ++++++++-------
 include/readkey.h |  2 +-
 2 files changed, 9 insertions(+), 8 deletions(-)



From s.hauer at pengutronix.de  Wed Jun 19 16:53:41 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 22:53:41 +0200
Subject: [PATCH 2/3] Fix gotoXY argument order
In-Reply-To: <1371675222-25433-1-git-send-email-s.hauer@pengutronix.de>
References: <1371675222-25433-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371675222-25433-3-git-send-email-s.hauer@pengutronix.de>

gotoXY has the argument order (y, x). Change this so that usage of this
function feels more natural.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/menu.c     | 10 +++++-----
 include/readkey.h |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/common/menu.c b/common/menu.c
index 1f0ffec..d516db4 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -164,7 +164,7 @@ static void __print_entry(const char *str)
 static void print_menu_entry(struct menu *m, struct menu_entry *me,
 			     int selected)
 {
-	gotoXY(me->num + 1, 3);
+	gotoXY(3, me->num + 1);
 
 	if (me->type == MENU_ENTRY_BOX) {
 		if (me->box_state)
@@ -234,7 +234,7 @@ static void print_menu(struct menu *m)
 	struct menu_entry *me;
 
 	clear();
-	gotoXY(1, 2);
+	gotoXY(2, 1);
 	if(m->display) {
 		__print_entry(m->display);
 	} else {
@@ -269,7 +269,7 @@ int menu_show(struct menu *m)
 
 	countdown = m->auto_select;
 	if (m->auto_select >= 0) {
-		gotoXY(m->nb_entries + 2, 3);
+		gotoXY(3, m->nb_entries + 2);
 		if (!m->auto_display) {
 			printf("Auto Select in");
 		} else {
@@ -293,10 +293,10 @@ int menu_show(struct menu *m)
 		}
 	}
 
-	gotoXY(m->nb_entries + 2, 3);
+	gotoXY(3, m->nb_entries + 2);
 	printf("%*c", auto_display_len + 4, ' ');
 
-	gotoXY(m->selected->num + 1, 3);
+	gotoXY(3, m->selected->num + 1);
 
 	do {
 		struct menu_entry *old_selected = m->selected;
diff --git a/include/readkey.h b/include/readkey.h
index f134846..2793f3f 100644
--- a/include/readkey.h
+++ b/include/readkey.h
@@ -28,7 +28,7 @@
 
 #define printf_reverse(fmt,args...)	printf("\e[7m" fmt "\e[m",##args)
 #define puts_reverse(fmt)		puts("\e[7m" fmt "\e[m")
-#define gotoXY(row, col)		printf("\e[%d;%dH", row, col)
+#define gotoXY(row, col)		printf("\e[%d;%dH", col, row)
 #define clear()				puts("\e[2J")
 
 int read_key(void);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 19 16:53:40 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 22:53:40 +0200
Subject: [PATCH 1/3] menu: Align entries
In-Reply-To: <1371675222-25433-1-git-send-email-s.hauer@pengutronix.de>
References: <1371675222-25433-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371675222-25433-2-git-send-email-s.hauer@pengutronix.de>

More than 9 menu entries in are single menu are not aligned anymore, like
this:

8 entry8
9 entry9
10 entry10

Use %2d in the printf format specifier to align more than 9 entries.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/menu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/menu.c b/common/menu.c
index a672e59..1f0ffec 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -175,7 +175,7 @@ static void print_menu_entry(struct menu *m, struct menu_entry *me,
 		puts("   ");
 	}
 
-	printf(" %d: ", me->num);
+	printf(" %2d: ", me->num);
 	if (selected)
 		puts("\e[7m");
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 19 16:53:42 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 22:53:42 +0200
Subject: [PATCH 3/3] menu: Make action callback optional
In-Reply-To: <1371675222-25433-1-git-send-email-s.hauer@pengutronix.de>
References: <1371675222-25433-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371675222-25433-4-git-send-email-s.hauer@pengutronix.de>

Someone calling menu_show might only be interested in the entry the user
selected without having something in the action callback. Make it optional.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/menu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/menu.c b/common/menu.c
index d516db4..ef56190 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -361,7 +361,8 @@ int menu_show(struct menu *m)
 				break;
 			clear();
 			gotoXY(1,1);
-			m->selected->action(m, m->selected);
+			if (m->selected->action)
+				m->selected->action(m, m->selected);
 			if (m->selected->non_re_ent)
 				return m->selected->num;
 			else
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 19 16:58:33 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 22:58:33 +0200
Subject: [PATCH] bootm: factor out code to make it usable from C
Message-ID: <1371675513-6246-1-git-send-email-s.hauer@pengutronix.de>

Much of the bootm code is implemented in the command itself. Move
it to a common place to be able to call it from C aswell.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/Kconfig |   1 +
 commands/bootm.c | 281 +--------------------------------------------------
 common/Kconfig   |   3 +
 common/Makefile  |   1 +
 common/bootm.c   | 303 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/boot.h   |   8 ++
 6 files changed, 321 insertions(+), 276 deletions(-)
 create mode 100644 common/bootm.c

diff --git a/commands/Kconfig b/commands/Kconfig
index a62ed98..384643b 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -420,6 +420,7 @@ menu "booting"
 config CMD_BOOTM
 	tristate
 	default y
+	select BOOTM
 	select CRC32
 	select UIMAGE
 	select UNCOMPRESS
diff --git a/commands/bootm.c b/commands/bootm.c
index 6ce2ca9..97a6698 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -46,172 +46,11 @@
 #include <magicvar.h>
 #include <asm-generic/memory_layout.h>
 
-static LIST_HEAD(handler_list);
-
 /*
  * Additional oftree size for the fixed tree
  */
 #define OFTREE_SIZE_INCREASE	0x8000
 
-int register_image_handler(struct image_handler *handler)
-{
-	list_add_tail(&handler->list, &handler_list);
-	return 0;
-}
-
-#define UIMAGE_SOME_ADDRESS (UIMAGE_INVALID_ADDRESS - 1)
-
-static int bootm_open_os_uimage(struct image_data *data)
-{
-	int ret;
-
-	data->os = uimage_open(data->os_file);
-	if (!data->os)
-		return -EINVAL;
-
-	if (data->verify) {
-		ret = uimage_verify(data->os);
-		if (ret) {
-			printf("Checking data crc failed with %s\n",
-					strerror(-ret));
-			uimage_close(data->os);
-			return ret;
-		}
-	}
-
-	uimage_print_contents(data->os);
-
-	if (data->os->header.ih_arch != IH_ARCH) {
-		printf("Unsupported Architecture 0x%x\n",
-		       data->os->header.ih_arch);
-		uimage_close(data->os);
-		return -EINVAL;
-	}
-
-	if (data->os_address == UIMAGE_SOME_ADDRESS)
-		data->os_address = data->os->header.ih_load;
-
-	if (data->os_address != UIMAGE_INVALID_ADDRESS) {
-		data->os_res = uimage_load_to_sdram(data->os, 0,
-				data->os_address);
-		if (!data->os_res) {
-			uimage_close(data->os);
-			return -ENOMEM;
-		}
-	}
-
-	return 0;
-}
-
-static int bootm_open_initrd_uimage(struct image_data *data)
-{
-	int ret;
-
-	if (!data->initrd_file)
-		return 0;
-
-	if (strcmp(data->os_file, data->initrd_file)) {
-		data->initrd = uimage_open(data->initrd_file);
-		if (!data->initrd)
-			return -EINVAL;
-
-		if (data->verify) {
-			ret = uimage_verify(data->initrd);
-			if (ret) {
-				printf("Checking data crc failed with %s\n",
-					strerror(-ret));
-			}
-		}
-		uimage_print_contents(data->initrd);
-	} else {
-		data->initrd = data->os;
-	}
-
-	return 0;
-}
-
-#ifdef CONFIG_OFTREE
-static int bootm_open_oftree(struct image_data *data, const char *oftree, int num)
-{
-	enum filetype ft;
-	struct fdt_header *fdt;
-	size_t size;
-
-	printf("Loading devicetree from '%s'\n", oftree);
-
-	ft = file_name_detect_type(oftree);
-	if ((int)ft < 0) {
-		printf("failed to open %s: %s\n", oftree, strerror(-(int)ft));
-		return ft;
-	}
-
-	if (ft == filetype_uimage) {
-#ifdef CONFIG_CMD_BOOTM_OFTREE_UIMAGE
-		struct uimage_handle *of_handle;
-		int release = 0;
-
-		if (!strcmp(data->os_file, oftree)) {
-			of_handle = data->os;
-		} else if (!strcmp(data->initrd_file, oftree)) {
-			of_handle = data->initrd;
-		} else {
-			of_handle = uimage_open(oftree);
-			if (!of_handle)
-				return -ENODEV;
-			uimage_print_contents(of_handle);
-			release = 1;
-		}
-
-		fdt = uimage_load_to_buf(of_handle, num, &size);
-
-		if (release)
-			uimage_close(of_handle);
-#else
-		return -EINVAL;
-#endif
-	} else {
-		fdt = read_file(oftree, &size);
-		if (!fdt) {
-			perror("open");
-			return -ENODEV;
-		}
-	}
-
-	ft = file_detect_type(fdt, size);
-	if (ft != filetype_oftree) {
-		printf("%s is not an oftree but %s\n", oftree,
-				file_type_to_string(ft));
-	}
-
-	data->of_root_node = of_unflatten_dtb(NULL, fdt);
-	if (!data->of_root_node) {
-		pr_err("unable to unflatten devicetree\n");
-		return -EINVAL;
-	}
-
-	free(fdt);
-
-	return 0;
-}
-#endif
-
-static struct image_handler *bootm_find_handler(enum filetype filetype,
-		struct image_data *data)
-{
-	struct image_handler *handler;
-
-	list_for_each_entry(handler, &handler_list, list) {
-		if (filetype != filetype_uimage &&
-				handler->filetype == filetype)
-			return handler;
-		if  (filetype == filetype_uimage &&
-				handler->ih_os == data->os->header.ih_os)
-			return handler;
-	}
-
-	return NULL;
-}
-
 static char *bootm_image_name_and_no(const char *name, int *no)
 {
 	char *at, *ret;
@@ -244,12 +83,9 @@ static char *bootm_image_name_and_no(const char *name, int *no)
 static int do_bootm(int argc, char *argv[])
 {
 	int opt;
-	struct image_handler *handler;
 	struct image_data data;
 	int ret = 1;
-	enum filetype os_type, initrd_type = filetype_unknown;
 	const char *oftree = NULL, *initrd_file = NULL, *os_file = NULL;
-	int fallback = 0;
 
 	memset(&data, 0, sizeof(struct image_data));
 
@@ -289,7 +125,7 @@ static int do_bootm(int argc, char *argv[])
 			oftree = optarg;
 			break;
 		case 'f':
-			fallback = 1;
+			data.force = 1;
 			break;
 		default:
 			break;
@@ -311,124 +147,17 @@ static int do_bootm(int argc, char *argv[])
 		oftree = NULL;
 
 	data.os_file = bootm_image_name_and_no(os_file, &data.os_num);
+	data.oftree_file = bootm_image_name_and_no(oftree, &data.oftree_num);
+	data.initrd_file = bootm_image_name_and_no(initrd_file, &data.initrd_num);
 
-	os_type = file_name_detect_type(data.os_file);
-	if ((int)os_type < 0) {
-		printf("could not open %s: %s\n", data.os_file,
-				strerror(-os_type));
-		goto err_out;
-	}
-
-	if (!fallback && os_type == filetype_unknown) {
-		printf("Unknown OS filetype (try -f)\n");
-		goto err_out;
-	}
-
-	if (os_type == filetype_uimage) {
-		ret = bootm_open_os_uimage(&data);
-		if (ret) {
-			printf("loading os image failed with %s\n",
-					strerror(-ret));
-			goto err_out;
-		}
-	}
-
-	if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD) && initrd_file) {
-		data.initrd_file = bootm_image_name_and_no(initrd_file, &data.initrd_num);
-
-		initrd_type = file_name_detect_type(data.initrd_file);
-		if ((int)initrd_type < 0) {
-			printf("could not open %s: %s\n", data.initrd_file,
-					strerror(-initrd_type));
-			goto err_out;
-		}
-		if (initrd_type == filetype_uimage) {
-			ret = bootm_open_initrd_uimage(&data);
-			if (ret) {
-				printf("loading initrd failed with %s\n",
-						strerror(-ret));
-				goto err_out;
-			}
-		}
-	}
-
-	printf("\nLoading OS %s '%s'", file_type_to_string(os_type),
-			data.os_file);
-	if (os_type == filetype_uimage &&
-			data.os->header.ih_type == IH_TYPE_MULTI)
-		printf(", multifile image %d", data.os_num);
-	printf("\n");
-
-	if (bootm_verbose(&data)) {
-		if (data.os_res)
-			printf("OS image is at 0x%08x-0x%08x\n",
-					data.os_res->start,
-					data.os_res->end);
-		else
-			printf("OS image not yet relocated\n");
-
-		if (data.initrd_file) {
-			printf("Loading initrd %s '%s'",
-					file_type_to_string(initrd_type),
-					data.initrd_file);
-			if (initrd_type == filetype_uimage &&
-					data.initrd->header.ih_type == IH_TYPE_MULTI)
-				printf(", multifile image %d", data.initrd_num);
-			printf("\n");
-			if (data.initrd_res)
-				printf("initrd is at 0x%08x-0x%08x\n",
-					data.initrd_res->start,
-					data.initrd_res->end);
-			else
-				printf("initrd image not yet relocated\n");
-		}
-	}
-
-#ifdef CONFIG_OFTREE
-	if (oftree) {
-		int oftree_num;
-
-		oftree = bootm_image_name_and_no(oftree, &oftree_num);
-
-		ret = bootm_open_oftree(&data, oftree, oftree_num);
-		if (ret)
-			goto err_out;
-	} else {
-		data.of_root_node = of_get_root_node();
-		if (data.of_root_node)
-			printf("using internal devicetree\n");
-	}
-#endif
-	if (data.os_address == UIMAGE_SOME_ADDRESS)
-		data.os_address = UIMAGE_INVALID_ADDRESS;
-
-	handler = bootm_find_handler(os_type, &data);
-	if (!handler) {
-		printf("no image handler found for image type %s\n",
-			file_type_to_string(os_type));
-		if (os_type == filetype_uimage)
-			printf("and os type: %d\n", data.os->header.ih_os);
-		goto err_out;
-	}
-
-	if (bootm_verbose(&data))
-		printf("Passing control to %s handler\n", handler->name);
-
-	ret = handler->bootm(&data);
+	ret = bootm_boot(&data);
 
 	printf("handler failed with %s\n", strerror(-ret));
 
 err_out:
 	free(data.initrd_file);
 	free(data.os_file);
-	if (data.os_res)
-		release_sdram_region(data.os_res);
-	if (data.initrd_res)
-		release_sdram_region(data.initrd_res);
-	if (data.initrd && data.initrd != data.os)
-		uimage_close(data.initrd);
-	if (data.os)
-		uimage_close(data.os);
+
 	return 1;
 }
 
diff --git a/common/Kconfig b/common/Kconfig
index 4cfbe4e..8a82320 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -31,6 +31,9 @@ config ENV_HANDLING
 config GENERIC_GPIO
 	bool
 
+config BOOTM
+	bool
+
 config BLOCK
 	bool
 
diff --git a/common/Makefile b/common/Makefile
index 2f0bd34..34eb7e4 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_MODULES) += module.o
 obj-$(CONFIG_FLEXIBLE_BOOTARGS) += bootargs.o
 obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
 obj-y += bootsource.o
+obj-$(CONFIG_BOOTM) += bootm.o
 extra-$(CONFIG_MODULES) += module.lds
 extra-y += barebox_default_env barebox_default_env.h
 
diff --git a/common/bootm.c b/common/bootm.c
new file mode 100644
index 0000000..1987a09
--- /dev/null
+++ b/common/bootm.c
@@ -0,0 +1,303 @@
+/*
+ * 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.
+ *
+ */
+
+#include <common.h>
+#include <boot.h>
+#include <fs.h>
+#include <malloc.h>
+#include <memory.h>
+
+static LIST_HEAD(handler_list);
+
+int register_image_handler(struct image_handler *handler)
+{
+	list_add_tail(&handler->list, &handler_list);
+
+	return 0;
+}
+
+static struct image_handler *bootm_find_handler(enum filetype filetype,
+		struct image_data *data)
+{
+	struct image_handler *handler;
+
+	list_for_each_entry(handler, &handler_list, list) {
+		if (filetype != filetype_uimage &&
+				handler->filetype == filetype)
+			return handler;
+		if  (filetype == filetype_uimage &&
+				handler->ih_os == data->os->header.ih_os)
+			return handler;
+	}
+
+	return NULL;
+}
+
+static int bootm_open_os_uimage(struct image_data *data)
+{
+	int ret;
+
+	data->os = uimage_open(data->os_file);
+	if (!data->os)
+		return -EINVAL;
+
+	if (data->verify) {
+		ret = uimage_verify(data->os);
+		if (ret) {
+			printf("Checking data crc failed with %s\n",
+					strerror(-ret));
+			uimage_close(data->os);
+			return ret;
+		}
+	}
+
+	uimage_print_contents(data->os);
+
+	if (data->os->header.ih_arch != IH_ARCH) {
+		printf("Unsupported Architecture 0x%x\n",
+		       data->os->header.ih_arch);
+		uimage_close(data->os);
+		return -EINVAL;
+	}
+
+	if (data->os_address == UIMAGE_SOME_ADDRESS)
+		data->os_address = data->os->header.ih_load;
+
+	if (data->os_address != UIMAGE_INVALID_ADDRESS) {
+		data->os_res = uimage_load_to_sdram(data->os, 0,
+				data->os_address);
+		if (!data->os_res) {
+			uimage_close(data->os);
+			return -ENOMEM;
+		}
+	}
+
+	return 0;
+}
+
+static int bootm_open_initrd_uimage(struct image_data *data)
+{
+	int ret;
+
+	if (!data->initrd_file)
+		return 0;
+
+	if (strcmp(data->os_file, data->initrd_file)) {
+		data->initrd = uimage_open(data->initrd_file);
+		if (!data->initrd)
+			return -EINVAL;
+
+		if (data->verify) {
+			ret = uimage_verify(data->initrd);
+			if (ret) {
+				printf("Checking data crc failed with %s\n",
+					strerror(-ret));
+			}
+		}
+		uimage_print_contents(data->initrd);
+	} else {
+		data->initrd = data->os;
+	}
+
+	return 0;
+}
+
+static int bootm_open_oftree(struct image_data *data, const char *oftree, int num)
+{
+	enum filetype ft;
+	struct fdt_header *fdt;
+	size_t size;
+
+	printf("Loading devicetree from '%s'\n", oftree);
+
+	ft = file_name_detect_type(oftree);
+	if ((int)ft < 0) {
+		printf("failed to open %s: %s\n", oftree, strerror(-(int)ft));
+		return ft;
+	}
+
+	if (ft == filetype_uimage) {
+#ifdef CONFIG_CMD_BOOTM_OFTREE_UIMAGE
+		struct uimage_handle *of_handle;
+		int release = 0;
+
+		if (!strcmp(data->os_file, oftree)) {
+			of_handle = data->os;
+		} else if (!strcmp(data->initrd_file, oftree)) {
+			of_handle = data->initrd;
+		} else {
+			of_handle = uimage_open(oftree);
+			if (!of_handle)
+				return -ENODEV;
+			uimage_print_contents(of_handle);
+			release = 1;
+		}
+
+		fdt = uimage_load_to_buf(of_handle, num, &size);
+
+		if (release)
+			uimage_close(of_handle);
+#else
+		return -EINVAL;
+#endif
+	} else {
+		fdt = read_file(oftree, &size);
+		if (!fdt) {
+			perror("open");
+			return -ENODEV;
+		}
+	}
+
+	ft = file_detect_type(fdt, size);
+	if (ft != filetype_oftree) {
+		printf("%s is not an oftree but %s\n", oftree,
+				file_type_to_string(ft));
+	}
+
+	data->of_root_node = of_unflatten_dtb(NULL, fdt);
+	if (!data->of_root_node) {
+		pr_err("unable to unflatten devicetree\n");
+		return -EINVAL;
+	}
+
+	free(fdt);
+
+	return 0;
+}
+
+static void bootm_print_info(struct image_data *data)
+{
+	if (data->os_res)
+		printf("OS image is at 0x%08x-0x%08x\n",
+				data->os_res->start,
+				data->os_res->end);
+	else
+		printf("OS image not yet relocated\n");
+
+	if (data->initrd_file) {
+		enum filetype initrd_type = file_name_detect_type(data->initrd_file);
+
+		printf("Loading initrd %s '%s'",
+				file_type_to_string(initrd_type),
+				data->initrd_file);
+		if (initrd_type == filetype_uimage &&
+				data->initrd->header.ih_type == IH_TYPE_MULTI)
+			printf(", multifile image %d", data->initrd_num);
+		printf("\n");
+		if (data->initrd_res)
+			printf("initrd is at 0x%08x-0x%08x\n",
+				data->initrd_res->start,
+				data->initrd_res->end);
+		else
+			printf("initrd image not yet relocated\n");
+	}
+}
+
+int bootm_boot(struct image_data *data)
+{
+	struct image_handler *handler;
+	int ret;
+	enum filetype os_type, initrd_type = filetype_unknown;
+
+	os_type = file_name_detect_type(data->os_file);
+	if ((int)os_type < 0) {
+		printf("could not open %s: %s\n", data->os_file,
+				strerror(-os_type));
+		ret = (int)os_type;
+		goto err_out;
+	}
+
+	if (!data->force && os_type == filetype_unknown) {
+		printf("Unknown OS filetype (try -f)\n");
+		ret = -EINVAL;
+		goto err_out;
+	}
+
+	if (os_type == filetype_uimage) {
+		ret = bootm_open_os_uimage(data);
+		if (ret) {
+			printf("loading os image failed with %s\n",
+					strerror(-ret));
+			goto err_out;
+		}
+	}
+
+	if (IS_ENABLED(CONFIG_CMD_BOOTM_INITRD) && data->initrd_file) {
+
+		initrd_type = file_name_detect_type(data->initrd_file);
+		if ((int)initrd_type < 0) {
+			printf("could not open %s: %s\n", data->initrd_file,
+					strerror(-initrd_type));
+			ret = (int)initrd_type;
+			goto err_out;
+		}
+		if (initrd_type == filetype_uimage) {
+			ret = bootm_open_initrd_uimage(data);
+			if (ret) {
+				printf("loading initrd failed with %s\n",
+						strerror(-ret));
+				goto err_out;
+			}
+		}
+	}
+
+	printf("\nLoading OS %s '%s'", file_type_to_string(os_type),
+			data->os_file);
+	if (os_type == filetype_uimage &&
+			data->os->header.ih_type == IH_TYPE_MULTI)
+		printf(", multifile image %d", data->os_num);
+	printf("\n");
+
+	if (IS_ENABLED(CONFIG_OFTREE)) {
+		if (data->oftree_file) {
+			ret = bootm_open_oftree(data, data->oftree_file, data->oftree_num);
+			if (ret)
+				goto err_out;
+		} else {
+			data->of_root_node = of_get_root_node();
+			if (data->of_root_node)
+				printf("using internal devicetree\n");
+		}
+	}
+
+	if (data->os_address == UIMAGE_SOME_ADDRESS)
+		data->os_address = UIMAGE_INVALID_ADDRESS;
+
+	handler = bootm_find_handler(os_type, data);
+	if (!handler) {
+		printf("no image handler found for image type %s\n",
+			file_type_to_string(os_type));
+		if (os_type == filetype_uimage)
+			printf("and os type: %d\n", data->os->header.ih_os);
+		ret = -ENODEV;
+		goto err_out;
+	}
+
+	if (bootm_verbose(data)) {
+		bootm_print_info(data);
+		printf("Passing control to %s handler\n", handler->name);
+	}
+
+	ret = handler->bootm(data);
+err_out:
+	if (data->os_res)
+		release_sdram_region(data->os_res);
+	if (data->initrd_res)
+		release_sdram_region(data->initrd_res);
+	if (data->initrd && data->initrd != data->os)
+		uimage_close(data->initrd);
+	if (data->os)
+		uimage_close(data->os);
+
+	return ret;
+}
diff --git a/include/boot.h b/include/boot.h
index 971a403..ccce8e1 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -41,11 +41,15 @@ struct image_data {
 
 	unsigned long initrd_address;
 
+	char *oftree_file;
+	int oftree_num;
+
 	struct device_node *of_root_node;
 	struct fdt_header *oftree;
 
 	int verify;
 	int verbose;
+	int force;
 };
 
 struct image_handler {
@@ -88,4 +92,8 @@ static inline int linux_bootargs_overwrite(const char *bootargs)
 }
 #endif
 
+#define UIMAGE_SOME_ADDRESS (UIMAGE_INVALID_ADDRESS - 1)
+
+int bootm_boot(struct image_data *);
+
 #endif /* __BOOT_H */
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 19 16:58:48 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 22:58:48 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not pass size
Message-ID: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>

Some tftp servers (for example netkit-tftp) do not pass the filesize.
Add a workaround for read_file which reads the file into a temporary
file which then is copied to a buffer.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 fs/fs.c      | 18 ++++++++++++++++++
 fs/tftp.c    |  5 ++++-
 include/fs.h |  2 ++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/fs/fs.c b/fs/fs.c
index dc3a6e3..7046f2c 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size)
 	int fd;
 	struct stat s;
 	void *buf = NULL;
+	const char *tmpfile = "/.read_file_tmp";
+	int ret;
 
+again:
 	if (stat(filename, &s))
 		return NULL;
 
+	if (s.st_size == FILESIZE_MAX) {
+		ret = copy_file(filename, tmpfile, 0);
+		if (ret)
+			return NULL;
+		filename = tmpfile;
+		goto again;
+	}
+
 	buf = xzalloc(s.st_size + 1);
 
 	fd = open(filename, O_RDONLY);
@@ -56,12 +67,19 @@ void *read_file(const char *filename, size_t *size)
 	if (size)
 		*size = s.st_size;
 
+	if (filename == tmpfile)
+		unlink(tmpfile);
+
 	return buf;
 
 err_out1:
 	close(fd);
 err_out:
 	free(buf);
+
+	if (filename == tmpfile)
+		unlink(tmpfile);
+
 	return NULL;
 }
 
diff --git a/fs/tftp.c b/fs/tftp.c
index 98cbb37..1c37acf 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -597,7 +597,10 @@ static int tftp_stat(struct device_d *dev, const char *filename, struct stat *s)
 		return PTR_ERR(priv);
 
 	s->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
-	s->st_size = priv->filesize;
+	if (priv->filesize)
+		s->st_size = priv->filesize;
+	else
+		s->st_size = FILESIZE_MAX;
 
 	tftp_do_close(priv);
 
diff --git a/include/fs.h b/include/fs.h
index 8ff7300..fa6a8da 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -147,6 +147,8 @@ int protect(int fd, size_t count, unsigned long offset, int prot);
 int protect_file(const char *file, int prot);
 void *memmap(int fd, int flags);
 
+#define FILESIZE_MAX	((size_t)-1)
+
 #define PROT_READ	1
 #define PROT_WRITE	2
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 19 17:00:29 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 19 Jun 2013 23:00:29 +0200
Subject: [PATCH] partitions: dos: fix memory leak in nt disk signature
Message-ID: <1371675629-7147-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/partitions/dos.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index b9f31c3..29f1375 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -107,6 +107,8 @@ static int dos_get_disk_signature(struct param_d *p, void *_priv)
 
 	priv->signature = le32_to_cpup((__le32 *)(buf + 0x1b8));
 
+	free(buf);
+
 	return 0;
 }
 
-- 
1.8.3.1



From alex.aring at gmail.com  Wed Jun 19 17:32:40 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Wed, 19 Jun 2013 23:32:40 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <20130619213239.GA3707@x61s.8.8.8.8>

Hi Sascha,

only a very small hint.

On Wed, Jun 19, 2013 at 10:58:48PM +0200, Sascha Hauer wrote:
> Some tftp servers (for example netkit-tftp) do not pass the filesize.
> Add a workaround for read_file which reads the file into a temporary
> file which then is copied to a buffer.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  fs/fs.c      | 18 ++++++++++++++++++
>  fs/tftp.c    |  5 ++++-
>  include/fs.h |  2 ++
>  3 files changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/fs.c b/fs/fs.c
> index dc3a6e3..7046f2c 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size)
>  	int fd;

...

>  
>  	tftp_do_close(priv);
>  
> diff --git a/include/fs.h b/include/fs.h
> index 8ff7300..fa6a8da 100644
> --- a/include/fs.h
> +++ b/include/fs.h
> @@ -147,6 +147,8 @@ int protect(int fd, size_t count, unsigned long offset, int prot);
>  int protect_file(const char *file, int prot);
>  void *memmap(int fd, int flags);
>  
> +#define FILESIZE_MAX	((size_t)-1)

The type of st_size in struct stat is loff_t. I check this and
((size_t)-1) is different than ((loff_t)-1), so I think we need to cast
to loff_t. Maybe it's better to use a define from limits.h, but we don't
have some header file like this.



From alex.aring at gmail.com  Wed Jun 19 17:57:01 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Wed, 19 Jun 2013 23:57:01 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <20130619213239.GA3707@x61s.8.8.8.8>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
 <20130619213239.GA3707@x61s.8.8.8.8>
Message-ID: <20130619215700.GA2135@x61s.8.8.8.8>

Hi,

On Wed, Jun 19, 2013 at 11:32:39PM +0200, Alexander Aring wrote:
> Hi Sascha,
> 
> only a very small hint.
> 
> On Wed, Jun 19, 2013 at 10:58:48PM +0200, Sascha Hauer wrote:
> > Some tftp servers (for example netkit-tftp) do not pass the filesize.
> > Add a workaround for read_file which reads the file into a temporary
> > file which then is copied to a buffer.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  fs/fs.c      | 18 ++++++++++++++++++
> >  fs/tftp.c    |  5 ++++-
> >  include/fs.h |  2 ++
> >  3 files changed, 24 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/fs.c b/fs/fs.c
> > index dc3a6e3..7046f2c 100644
> > --- a/fs/fs.c
> > +++ b/fs/fs.c
> > @@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size)
> >  	int fd;
> 
> ...
> 
> >  
> >  	tftp_do_close(priv);
> >  
> > diff --git a/include/fs.h b/include/fs.h
> > index 8ff7300..fa6a8da 100644
> > --- a/include/fs.h
> > +++ b/include/fs.h
> > @@ -147,6 +147,8 @@ int protect(int fd, size_t count, unsigned long offset, int prot);
> >  int protect_file(const char *file, int prot);
> >  void *memmap(int fd, int flags);
> >  
> > +#define FILESIZE_MAX	((size_t)-1)
> 
> The type of st_size in struct stat is loff_t. I check this and
> ((size_t)-1) is different than ((loff_t)-1), so I think we need to cast
> to loff_t. Maybe it's better to use a define from limits.h, but we don't
> have some header file like this.
> 

ah, I see it now. The fs layer use size_t instead of loff_t. Sorry for
the noise.

Regards
Alex


From s.hauer at pengutronix.de  Thu Jun 20 02:42:17 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:42:17 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <20130619215700.GA2135@x61s.8.8.8.8>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
 <20130619213239.GA3707@x61s.8.8.8.8>
 <20130619215700.GA2135@x61s.8.8.8.8>
Message-ID: <20130620064217.GN32299@pengutronix.de>

On Wed, Jun 19, 2013 at 11:57:01PM +0200, Alexander Aring wrote:
> Hi,
> 
> On Wed, Jun 19, 2013 at 11:32:39PM +0200, Alexander Aring wrote:
> > Hi Sascha,
> > 
> > only a very small hint.
> > 
> > On Wed, Jun 19, 2013 at 10:58:48PM +0200, Sascha Hauer wrote:
> > > Some tftp servers (for example netkit-tftp) do not pass the filesize.
> > > Add a workaround for read_file which reads the file into a temporary
> > > file which then is copied to a buffer.
> > > 
> > > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > > ---
> > >  fs/fs.c      | 18 ++++++++++++++++++
> > >  fs/tftp.c    |  5 ++++-
> > >  include/fs.h |  2 ++
> > >  3 files changed, 24 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/fs/fs.c b/fs/fs.c
> > > index dc3a6e3..7046f2c 100644
> > > --- a/fs/fs.c
> > > +++ b/fs/fs.c
> > > @@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size)
> > >  	int fd;
> > 
> > ...
> > 
> > >  
> > >  	tftp_do_close(priv);
> > >  
> > > diff --git a/include/fs.h b/include/fs.h
> > > index 8ff7300..fa6a8da 100644
> > > --- a/include/fs.h
> > > +++ b/include/fs.h
> > > @@ -147,6 +147,8 @@ int protect(int fd, size_t count, unsigned long offset, int prot);
> > >  int protect_file(const char *file, int prot);
> > >  void *memmap(int fd, int flags);
> > >  
> > > +#define FILESIZE_MAX	((size_t)-1)
> > 
> > The type of st_size in struct stat is loff_t. I check this and
> > ((size_t)-1) is different than ((loff_t)-1), so I think we need to cast
> > to loff_t. Maybe it's better to use a define from limits.h, but we don't
> > have some header file like this.
> > 
> 
> ah, I see it now. The fs layer use size_t instead of loff_t. Sorry for
> the noise.

No no, you were right. This indeed has to be a loff_t. Where did you
find that the fs layer uses size_t? It should do so only for the length
arguments of read/write and friends.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 20 02:54:15 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:15 +0200
Subject: [PATCH 11/17] serial: auart: Use clk support
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-12-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/serial/serial_auart.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/serial/serial_auart.c b/drivers/serial/serial_auart.c
index a69e65b..98f7c75 100644
--- a/drivers/serial/serial_auart.c
+++ b/drivers/serial/serial_auart.c
@@ -42,6 +42,8 @@
 #include <io.h>
 #include <malloc.h>
 #include <notifier.h>
+#include <linux/clk.h>
+#include <linux/err.h>
 
 #include <mach/clock.h>
 #include <mach/mxs.h>
@@ -92,6 +94,7 @@ struct auart_priv {
 	int baudrate;
 	struct notifier_block notify;
 	void __iomem *base;
+	struct clk *clk;
 };
 
 static void auart_serial_putc(struct console_device *cdev, char c)
@@ -143,7 +146,7 @@ static int auart_serial_setbaudrate(struct console_device *cdev, int new_baudrat
 	writel(0x0, priv->base + HW_UARTAPP_CTRL2);
 
 	/* Calculate and set baudrate */
-	quot = (imx_get_xclk() * 32) / new_baudrate;
+	quot = (clk_get_rate(priv->clk) * 32) / new_baudrate;
 	reg = BF_UARTAPP_LINECTRL_BAUD_DIVFRAC(quot & 0x3F) |
 		BF_UARTAPP_LINECTRL_BAUD_DIVINT(quot >> 6) |
 		BF_UARTAPP_LINECTRL_WLEN(3) |
@@ -194,6 +197,9 @@ static int auart_serial_probe(struct device_d *dev)
 
 	dev->priv = priv;
 	priv->base = dev_request_mem_region(dev, 0);
+	priv->clk = clk_get(dev, NULL);
+	if (IS_ERR(priv->clk))
+		return PTR_ERR(priv->clk);
 
 	auart_serial_init_port(priv);
 	auart_serial_setbaudrate(cdev, CONFIG_BAUDRATE);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:07 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:07 +0200
Subject: [PATCH 03/17] clk: add prototype for clk_is_enabled
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-4-git-send-email-s.hauer@pengutronix.de>

On MXS we need to poll the busy bit when changing a clock rate, but only
when the parent clocks are enabled. This exposes the already present
function clk_is_enabled which is suitable for this job.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/clk/clk.c   | 2 +-
 include/linux/clk.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index a3def53..690a0c6 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -208,7 +208,7 @@ int clk_register(struct clk *clk)
 	return 0;
 }
 
-static int clk_is_enabled(struct clk *clk)
+int clk_is_enabled(struct clk *clk)
 {
 	int enabled;
 
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 718faa0..38832ba 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -216,6 +216,7 @@ struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 		u8 shift);
 struct clk *clk_gate_inverted(const char *name, const char *parent, void __iomem *reg,
 		u8 shift);
+int clk_is_enabled(struct clk *clk);
 
 int clk_is_enabled_always(struct clk *clk);
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:18 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:18 +0200
Subject: [PATCH 14/17] ARM: MXS: octotp: switch to clk support
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-15-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-mxs/ocotp.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-mxs/ocotp.c b/arch/arm/mach-mxs/ocotp.c
index dd98446..6bfa3e2 100644
--- a/arch/arm/mach-mxs/ocotp.c
+++ b/arch/arm/mach-mxs/ocotp.c
@@ -21,11 +21,12 @@
 #include <malloc.h>
 #include <io.h>
 #include <clock.h>
+#include <linux/clk.h>
+#include <linux/err.h>
 
 #include <mach/generic.h>
 #include <mach/ocotp.h>
 #include <mach/imx-regs.h>
-#include <mach/clock-imx28.h>
 #include <mach/power.h>
 
 #define DRIVERNAME "ocotp"
@@ -45,6 +46,7 @@ struct ocotp_priv {
 	struct cdev cdev;
 	void __iomem *base;
 	unsigned int write_enable;
+	struct clk *clk;
 };
 
 static int mxs_ocotp_wait_busy(struct ocotp_priv *priv)
@@ -131,10 +133,10 @@ static ssize_t mxs_ocotp_cdev_write(struct cdev *cdev, const void *buf, size_t c
 		work_buf[offset - aligned_offset + i] |= ((u8 *)buf)[i];
 
 	/* prepare system for OTP write */
-	old_hclk = imx_get_hclk();
+	old_hclk = clk_get_rate(priv->clk);
 	old_vddio = imx_get_vddio();
 
-	imx_set_hclk(24000000);
+	clk_set_rate(priv->clk, 24000000);
 	imx_set_vddio(2800000);
 
 	writel(OCOTP_CTRL_RD_BANK_OPEN, base + OCOTP_CTRL + BIT_CLR);
@@ -162,7 +164,7 @@ static ssize_t mxs_ocotp_cdev_write(struct cdev *cdev, const void *buf, size_t c
 
 restore_system:
 	imx_set_vddio(old_vddio);
-	imx_set_hclk(old_hclk);
+	clk_set_rate(priv->clk, old_hclk);
 free_mem:
 	free(work_buf);
 
@@ -180,6 +182,9 @@ static int mxs_ocotp_probe(struct device_d *dev)
 	struct ocotp_priv *priv = xzalloc(sizeof (*priv));
 
 	priv->base = dev_request_mem_region(dev, 0);
+	priv->clk = clk_get(dev, NULL);
+	if (IS_ERR(priv->clk))
+		return PTR_ERR(priv->clk);
 	priv->cdev.dev = dev;
 	priv->cdev.ops = &mxs_ocotp_ops;
 	priv->cdev.priv = priv;
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:06 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:06 +0200
Subject: [PATCH 02/17] clk: gate: Add inverted gate support
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-3-git-send-email-s.hauer@pengutronix.de>

This adds support for gates which need 0 to enable.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/clk/clk-gate.c | 37 +++++++++++++++++++++++++++++++++----
 include/linux/clk.h    |  2 ++
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index a455094..f632d85 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -25,6 +25,8 @@ struct clk_gate {
 	void __iomem *reg;
 	int shift;
 	const char *parent;
+#define CLK_GATE_INVERTED	(1 << 0)
+	unsigned flags;
 };
 
 static int clk_gate_enable(struct clk *clk)
@@ -33,7 +35,12 @@ static int clk_gate_enable(struct clk *clk)
 	u32 val;
 
 	val = readl(g->reg);
-	val |= 1 << g->shift;
+
+	if (g->flags & CLK_GATE_INVERTED)
+		val &= ~(1 << g->shift);
+	else
+		val |= 1 << g->shift;
+
 	writel(val, g->reg);
 
 	return 0;
@@ -45,7 +52,12 @@ static void clk_gate_disable(struct clk *clk)
 	u32 val;
 
 	val = readl(g->reg);
-	val &= ~(1 << g->shift);
+
+	if (g->flags & CLK_GATE_INVERTED)
+		val |= 1 << g->shift;
+	else
+		val &= ~(1 << g->shift);
+
 	writel(val, g->reg);
 }
 
@@ -57,9 +69,9 @@ static int clk_gate_is_enabled(struct clk *clk)
 	val = readl(g->reg);
 
 	if (val & (1 << g->shift))
-		return 1;
+		return g->flags & CLK_GATE_INVERTED ? 0 : 1;
 	else
-		return 0;
+		return g->flags & CLK_GATE_INVERTED ? 1 : 0;
 }
 
 struct clk_ops clk_gate_ops = {
@@ -90,3 +102,20 @@ struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 
 	return &g->clk;
 }
+
+struct clk *clk_gate_inverted(const char *name, const char *parent,
+		void __iomem *reg, u8 shift)
+{
+	struct clk *clk;
+	struct clk_gate *g;
+
+	clk = clk_gate(name, parent, reg, shift);
+	if (IS_ERR(clk))
+		return clk;
+
+	g = container_of(clk, struct clk_gate, clk);
+
+	g->flags = CLK_GATE_INVERTED;
+
+	return clk;
+}
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 9c41cb8..718faa0 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -214,6 +214,8 @@ struct clk *clk_mux(const char *name, void __iomem *reg,
 		u8 shift, u8 width, const char **parents, u8 num_parents);
 struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 		u8 shift);
+struct clk *clk_gate_inverted(const char *name, const char *parent, void __iomem *reg,
+		u8 shift);
 
 int clk_is_enabled_always(struct clk *clk);
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:13 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:13 +0200
Subject: [PATCH 09/17] mci: mxs: use common clk API
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-10-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mxs.c | 60 ++++++++++++++++++-------------------------------------
 1 file changed, 19 insertions(+), 41 deletions(-)

diff --git a/drivers/mci/mxs.c b/drivers/mci/mxs.c
index cb2911a..023f922 100644
--- a/drivers/mci/mxs.c
+++ b/drivers/mci/mxs.c
@@ -36,6 +36,8 @@
 #include <errno.h>
 #include <clock.h>
 #include <io.h>
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <asm/bitops.h>
 #include <mach/mxs.h>
 #include <mach/imx-regs.h>
@@ -49,8 +51,8 @@
 struct mxs_mci_host {
 	struct mci_host	host;
 	void __iomem	*regs;
+	struct clk	*clk;
 	unsigned	clock;	/* current clock speed in Hz ("0" if disabled) */
-	unsigned	index;
 #ifdef CONFIG_MCI_INFO
 	unsigned	f_min;
 	unsigned	f_max;
@@ -61,16 +63,6 @@ struct mxs_mci_host {
 #define to_mxs_mci(mxs) container_of(mxs, struct mxs_mci_host, host)
 
 /**
- * Get the SSP clock rate
- * @param hw_dev Host interface device instance
- * @return Unit's clock in [Hz]
- */
-static unsigned mxs_mci_get_unit_clock(struct mxs_mci_host *mxs_mci)
-{
-	return imx_get_sspclk(mxs_mci->index);
-}
-
-/**
  * Get MCI cards response if defined for the type of command
  * @param hw_dev Host interface device instance
  * @param cmd Command description
@@ -430,7 +422,7 @@ static unsigned mxs_mci_setup_clock_speed(struct mxs_mci_host *mxs_mci, unsigned
 		return 0;
 	}
 
-	ssp = mxs_mci_get_unit_clock(mxs_mci);
+	ssp = clk_get_rate(mxs_mci->clk);
 
 	for (div = 2; div < 255; div += 2) {
 		rate = DIV_ROUND_CLOSEST(DIV_ROUND_CLOSEST(ssp, nc), div);
@@ -558,6 +550,7 @@ static int mxs_mci_probe(struct device_d *hw_dev)
 	struct mxs_mci_platform_data *pd = hw_dev->platform_data;
 	struct mxs_mci_host *mxs_mci;
 	struct mci_host *host;
+	unsigned long rate;
 
 	if (hw_dev->platform_data == NULL) {
 		dev_err(hw_dev, "Missing platform data\n");
@@ -578,44 +571,29 @@ static int mxs_mci_probe(struct device_d *hw_dev)
 	host->voltages = pd->voltages;
 	host->host_caps = pd->caps;
 
-#ifdef CONFIG_ARCH_IMX23
-	mxs_mci->index = 0;	/* there is only one clock for all */
-#endif
-#ifdef CONFIG_ARCH_IMX28
-	/* one dedicated clock per unit */
-	switch (hw_dev->resource[0].start) {
-	case IMX_SSP0_BASE:
-		mxs_mci->index = 0;
-		break;
-	case IMX_SSP1_BASE:
-		mxs_mci->index = 1;
-		break;
-	case IMX_SSP2_BASE:
-		mxs_mci->index = 2;
-		break;
-	case IMX_SSP3_BASE:
-		mxs_mci->index = 3;
-		break;
-	default:
-		pr_debug("Unknown SSP unit at address 0x%p\n", mxs_mci->regs);
-		return 0;
-	}
-#endif
+	mxs_mci->clk = clk_get(hw_dev, NULL);
+	if (IS_ERR(mxs_mci->clk))
+		return PTR_ERR(mxs_mci->clk);
+
+	clk_enable(mxs_mci->clk);
+
+	rate = clk_get_rate(mxs_mci->clk);
+
 	if (pd->f_min == 0) {
-		host->f_min = mxs_mci_get_unit_clock(mxs_mci) / 254 / 256;
+		host->f_min = rate / 254 / 256;
 		dev_dbg(hw_dev, "Min. frequency is %u Hz\n", host->f_min);
 	} else {
 		host->f_min = pd->f_min;
-		dev_dbg(hw_dev, "Min. frequency is %u Hz, could be %u Hz\n",
-			host->f_min, mxs_mci_get_unit_clock(mxs_mci) / 254 / 256);
+		dev_dbg(hw_dev, "Min. frequency is %u Hz, could be %lu Hz\n",
+			host->f_min, rate / 254 / 256);
 	}
 	if (pd->f_max == 0) {
-		host->f_max = mxs_mci_get_unit_clock(mxs_mci) / 2 / 1;
+		host->f_max = rate / 2 / 1;
 		dev_dbg(hw_dev, "Max. frequency is %u Hz\n", host->f_max);
 	} else {
 		host->f_max =  pd->f_max;
-		dev_dbg(hw_dev, "Max. frequency is %u Hz, could be %u Hz\n",
-			host->f_max, mxs_mci_get_unit_clock(mxs_mci) / 2 / 1);
+		dev_dbg(hw_dev, "Max. frequency is %u Hz, could be %lu Hz\n",
+			host->f_max, rate / 2 / 1);
 	}
 
 	if (IS_ENABLED(CONFIG_MCI_INFO)) {
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:04 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:04 +0200
Subject: [PATCH] convert MXS to common clk
Message-ID: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>

The following series converts the MXS subarchitecture to the common clk
stuff. Tested on i.MX28, but not yet on i.MX23.

Sascha

The following changes since commit 7c3603a199873319cbff82fe07a887ccf3452b9b:

  partitions: dos: fix memory leak in nt disk signature (2013-06-19 22:59:55 +0200)

are available in the git repository at:

  git://git.pengutronix.de/git/barebox.git pu/mxs-clk

for you to fetch changes up to 76eedb251df34bbd18c326984722f5cdfde3e730:

  ARM: MXS: remove old clock support (2013-06-20 08:49:57 +0200)

----------------------------------------------------------------
Sascha Hauer (17):
      clk: divider: Add onebased divider support
      clk: gate: Add inverted gate support
      clk: add prototype for clk_is_enabled
      ARM: MXS: Add MXS specific clk types
      ARM: MXS: add clk drivers
      ARM: MXS: remove board specific clock setups
      mci: mxs: Use dev_*
      net: fec: Use clk API unconditionally
      mci: mxs: use common clk API
      mtd: gpmi-nand: switch to clk support
      serial: auart: Use clk support
      serial: stm: Use clk support
      spi: mxs: Use clk support
      ARM: MXS: octotp: switch to clk support
      ARM: MXS: remove imx_enable_enetclk
      video: stm: switch to clk support
      ARM: MXS: remove old clock support

 arch/arm/Kconfig                                   |   2 +
 arch/arm/boards/chumby_falconwing/falconwing.c     |   3 -
 arch/arm/boards/crystalfontz-cfa10036/cfa10036.c   |   5 -
 arch/arm/boards/freescale-mx23-evk/mx23-evk.c      |   3 -
 arch/arm/boards/freescale-mx28-evk/mx28-evk.c      |   9 -
 arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c |   6 -
 arch/arm/boards/karo-tx28/tx28-stk5.c              |   6 -
 arch/arm/mach-mxs/Makefile                         |   5 +-
 arch/arm/mach-mxs/imx.c                            |  16 -
 arch/arm/mach-mxs/imx_lcd_clk.c                    | 150 -------
 arch/arm/mach-mxs/include/mach/clock-imx23.h       |  30 --
 arch/arm/mach-mxs/include/mach/clock-imx28.h       |  33 --
 arch/arm/mach-mxs/include/mach/clock.h             |   7 -
 arch/arm/mach-mxs/ocotp.c                          |  13 +-
 arch/arm/mach-mxs/soc-imx23.c                      |   9 +
 arch/arm/mach-mxs/soc-imx28.c                      |   9 +
 arch/arm/mach-mxs/speed-imx23.c                    | 315 ---------------
 arch/arm/mach-mxs/speed-imx28.c                    | 432 ---------------------
 drivers/clk/Makefile                               |   2 +
 drivers/clk/clk-divider.c                          |  44 ++-
 drivers/clk/clk-gate.c                             |  37 +-
 drivers/clk/clk.c                                  |   2 +-
 drivers/clk/mxs/Makefile                           |   5 +
 drivers/clk/mxs/clk-div.c                          | 112 ++++++
 drivers/clk/mxs/clk-frac.c                         | 136 +++++++
 drivers/clk/mxs/clk-imx23.c                        | 156 ++++++++
 drivers/clk/mxs/clk-imx28.c                        | 195 ++++++++++
 drivers/clk/mxs/clk-lcdif.c                        |  75 ++++
 drivers/clk/mxs/clk-pll.c                          | 117 ++++++
 drivers/clk/mxs/clk-ref.c                          | 152 ++++++++
 drivers/clk/mxs/clk.h                              |  52 +++
 drivers/mci/mxs.c                                  |  93 ++---
 drivers/mtd/nand/nand_mxs.c                        |  11 +-
 drivers/net/fec_imx.c                              |  31 +-
 drivers/serial/serial_auart.c                      |   8 +-
 drivers/serial/stm-serial.c                        |   8 +-
 drivers/spi/mxs_spi.c                              |   6 +-
 drivers/video/stm.c                                |   9 +-
 include/linux/clk.h                                |  18 +
 39 files changed, 1198 insertions(+), 1124 deletions(-)
 delete mode 100644 arch/arm/mach-mxs/imx_lcd_clk.c
 delete mode 100644 arch/arm/mach-mxs/include/mach/clock-imx23.h
 delete mode 100644 arch/arm/mach-mxs/include/mach/clock-imx28.h
 delete mode 100644 arch/arm/mach-mxs/speed-imx23.c
 delete mode 100644 arch/arm/mach-mxs/speed-imx28.c
 create mode 100644 drivers/clk/mxs/Makefile
 create mode 100644 drivers/clk/mxs/clk-div.c
 create mode 100644 drivers/clk/mxs/clk-frac.c
 create mode 100644 drivers/clk/mxs/clk-imx23.c
 create mode 100644 drivers/clk/mxs/clk-imx28.c
 create mode 100644 drivers/clk/mxs/clk-lcdif.c
 create mode 100644 drivers/clk/mxs/clk-pll.c
 create mode 100644 drivers/clk/mxs/clk-ref.c
 create mode 100644 drivers/clk/mxs/clk.h


From s.hauer at pengutronix.de  Thu Jun 20 02:54:05 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:05 +0200
Subject: [PATCH 01/17] clk: divider: Add onebased divider support
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-2-git-send-email-s.hauer@pengutronix.de>

In some dividers the register value matches the divider value. This
patch adds support for them.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/clk/clk-divider.c | 44 ++++++++++++++++++++++++++++++++------------
 include/linux/clk.h       | 15 +++++++++++++++
 2 files changed, 47 insertions(+), 12 deletions(-)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index 58a7ea5..3bf8105 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -20,13 +20,12 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 
-struct clk_divider {
-	struct clk clk;
-	u8 shift;
-	u8 width;
-	void __iomem *reg;
-	const char *parent;
-};
+static unsigned int clk_divider_maxdiv(struct clk_divider *div)
+{
+	if (div->flags & CLK_DIVIDER_ONE_BASED)
+                return (1 << div->width) - 1;
+	return 1 << div->width;
+}
 
 static int clk_divider_set_rate(struct clk *clk, unsigned long rate,
 		unsigned long parent_rate)
@@ -40,11 +39,11 @@ static int clk_divider_set_rate(struct clk *clk, unsigned long rate,
 		rate = 1;
 
 	divval = DIV_ROUND_UP(parent_rate, rate);
+	if (divval > clk_divider_maxdiv(div))
+		divval = clk_divider_maxdiv(div);
 
-	if (divval > (1 << div->width))
-		divval = 1 << (div->width);
-
-	divval--;
+	if (!(div->flags & CLK_DIVIDER_ONE_BASED))
+		divval--;
 
 	val = readl(div->reg);
 	val &= ~(((1 << div->width) - 1) << div->shift);
@@ -63,7 +62,12 @@ static unsigned long clk_divider_recalc_rate(struct clk *clk,
 	val = readl(div->reg) >> div->shift;
 	val &= (1 << div->width) - 1;
 
-	val++;
+	if (div->flags & CLK_DIVIDER_ONE_BASED) {
+		if (!val)
+			val++;
+	} else {
+		val++;
+	}
 
 	return parent_rate / val;
 }
@@ -96,3 +100,19 @@ struct clk *clk_divider(const char *name, const char *parent,
 
 	return &div->clk;
 }
+
+struct clk *clk_divider_one_based(const char *name, const char *parent,
+		void __iomem *reg, u8 shift, u8 width)
+{
+	struct clk_divider *div;
+	struct clk *clk;
+
+	clk = clk_divider(name, parent, reg, shift, width);
+	if (IS_ERR(clk))
+		return clk;
+
+	div = container_of(clk, struct clk_divider, clk);
+	div->flags |= CLK_DIVIDER_ONE_BASED;
+
+	return clk;
+}
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 37a4813..9c41cb8 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -188,8 +188,23 @@ struct clk_div_table {
 };
 
 struct clk *clk_fixed(const char *name, int rate);
+
+struct clk_divider {
+	struct clk clk;
+	u8 shift;
+	u8 width;
+	void __iomem *reg;
+	const char *parent;
+#define CLK_DIVIDER_ONE_BASED	(1 << 0)
+	unsigned flags;
+};
+
+extern struct clk_ops clk_divider_ops;
+
 struct clk *clk_divider(const char *name, const char *parent,
 		void __iomem *reg, u8 shift, u8 width);
+struct clk *clk_divider_one_based(const char *name, const char *parent,
+		void __iomem *reg, u8 shift, u8 width);
 struct clk *clk_divider_table(const char *name,
 		const char *parent, void __iomem *reg, u8 shift, u8 width,
 		const struct clk_div_table *table);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:19 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:19 +0200
Subject: [PATCH 15/17] ARM: MXS: remove imx_enable_enetclk
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-16-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx28-evk/mx28-evk.c | 1 -
 arch/arm/boards/karo-tx28/tx28-stk5.c         | 1 -
 2 files changed, 2 deletions(-)

diff --git a/arch/arm/boards/freescale-mx28-evk/mx28-evk.c b/arch/arm/boards/freescale-mx28-evk/mx28-evk.c
index bc28463..06f75e5 100644
--- a/arch/arm/boards/freescale-mx28-evk/mx28-evk.c
+++ b/arch/arm/boards/freescale-mx28-evk/mx28-evk.c
@@ -266,7 +266,6 @@ static int mx28_evk_devices_init(void)
 			IORESOURCE_MEM, NULL);
 	mx28_evk_get_ethaddr(); /* must be after registering ocotp */
 
-	imx_enable_enetclk();
 	mx28_evk_fec_reset();
 	add_generic_device("imx28-fec", 0, NULL, IMX_FEC0_BASE, 0x4000,
 			   IORESOURCE_MEM, &fec_info);
diff --git a/arch/arm/boards/karo-tx28/tx28-stk5.c b/arch/arm/boards/karo-tx28/tx28-stk5.c
index ae633b8..b969e4b 100644
--- a/arch/arm/boards/karo-tx28/tx28-stk5.c
+++ b/arch/arm/boards/karo-tx28/tx28-stk5.c
@@ -387,7 +387,6 @@ void base_board_init(void)
 
 	tx28_get_ethaddr();
 
-	imx_enable_enetclk();
 	add_generic_device("imx28-fec", 0, NULL, IMX_FEC0_BASE, 0x4000,
 			   IORESOURCE_MEM, &fec_info);
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:10 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:10 +0200
Subject: [PATCH 06/17] ARM: MXS: remove board specific clock setups
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-7-git-send-email-s.hauer@pengutronix.de>

Some boards have board specific special clock setups. These are now
done in the SoC specific clock drivers.

It is assumed that most board specific clock setup is done based on
copy/paste from U-Boot. The generalized clock setup differs from
some boards:

- ioclk are adjusted to 480MHz
- ssp clocks are adjusted to 96MHz
- enet out clock is enabled

Some boards adjusted the ioclk to 320MHz and the ssp clock to 160MHz.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/chumby_falconwing/falconwing.c     | 3 ---
 arch/arm/boards/crystalfontz-cfa10036/cfa10036.c   | 5 -----
 arch/arm/boards/freescale-mx23-evk/mx23-evk.c      | 3 ---
 arch/arm/boards/freescale-mx28-evk/mx28-evk.c      | 8 --------
 arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c | 6 ------
 arch/arm/boards/karo-tx28/tx28-stk5.c              | 5 -----
 6 files changed, 30 deletions(-)

diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c b/arch/arm/boards/chumby_falconwing/falconwing.c
index 720fe32..ab73be6 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -290,9 +290,6 @@ static int falconwing_devices_init(void)
 	for (i = 0; i < ARRAY_SIZE(pad_setup); i++)
 		imx_gpio_mode(pad_setup[i]);
 
-	imx_set_ioclk(480000000); /* enable IOCLK to run at the PLL frequency */
-	/* run the SSP unit clock at 100,000 kHz */
-	imx_set_sspclk(0, 100000000, 1);
 	add_generic_device("mxs_mci", 0, NULL, IMX_SSP1_BASE, 0x2000,
 			   IORESOURCE_MEM, &mci_pdata);
 	add_generic_device("stmfb", 0, NULL, IMX_FB_BASE, 4096,
diff --git a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
index a37b089..56a695f 100644
--- a/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
+++ b/arch/arm/boards/crystalfontz-cfa10036/cfa10036.c
@@ -122,11 +122,6 @@ static int cfa10036_devices_init(void)
 	for (i = 0; i < ARRAY_SIZE(cfa10036_pads); i++)
 		imx_gpio_mode(cfa10036_pads[i]);
 
-	/* enable IOCLK0 to run at the PLL frequency */
-	imx_set_ioclk(0, 480000000);
-	/* run the SSP unit clock at 100 MHz */
-	imx_set_sspclk(0, 100000000, 1);
-
 	armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_CFA10036);
 
diff --git a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
index 76377b1..9f63814 100644
--- a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
+++ b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
@@ -109,9 +109,6 @@ static int mx23_evk_devices_init(void)
 	armlinux_set_bootparams((void*)IMX_MEMORY_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_MX23EVK);
 
-	imx_set_ioclk(480000000); /* enable IOCLK to run at the PLL frequency */
-	imx_set_sspclk(0, 100000000, 1);
-
 	add_generic_device("mxs_mci", DEVICE_ID_DYNAMIC, NULL, IMX_SSP1_BASE,
 					0x8000, IORESOURCE_MEM, &mci_pdata);
 
diff --git a/arch/arm/boards/freescale-mx28-evk/mx28-evk.c b/arch/arm/boards/freescale-mx28-evk/mx28-evk.c
index 364b6ee..bc28463 100644
--- a/arch/arm/boards/freescale-mx28-evk/mx28-evk.c
+++ b/arch/arm/boards/freescale-mx28-evk/mx28-evk.c
@@ -253,14 +253,6 @@ static int mx28_evk_devices_init(void)
 	for (i = 0; i < ARRAY_SIZE(mx28evk_pads); i++)
 		imx_gpio_mode(mx28evk_pads[i]);
 
-	/* enable IOCLK0 to run at the PLL frequency */
-	imx_set_ioclk(0, 480000000);
-	imx_set_ioclk(1, 320000000);
-	/* run the SSP unit clock at 100 MHz */
-	imx_set_sspclk(0, 100000000, 1);
-	/* run the SSP unit 2 clock at 160Mhz */
-	imx_set_sspclk(2, 160000000, 1);
-
 	armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_MX28EVK);
 
diff --git a/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c b/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c
index 9620e85..ca6c5da 100644
--- a/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c
+++ b/arch/arm/boards/imx233-olinuxino/imx23-olinuxino.c
@@ -124,12 +124,6 @@ static int imx23_olinuxino_devices_init(void)
 	armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_IMX233_OLINUXINO);
 
-	/* enable IOCLK to run at the PLL frequency */
-	imx_set_ioclk(480000000);
-
-	/* run the SSP unit clock at 100,000 kHz */
-	imx_set_sspclk(0, 100000000, 1);
-
 	add_generic_device("mxs_mci", DEVICE_ID_DYNAMIC, NULL, IMX_SSP1_BASE,
 					0x8000, IORESOURCE_MEM, &mci_pdata);
 
diff --git a/arch/arm/boards/karo-tx28/tx28-stk5.c b/arch/arm/boards/karo-tx28/tx28-stk5.c
index a0109d6..ae633b8 100644
--- a/arch/arm/boards/karo-tx28/tx28-stk5.c
+++ b/arch/arm/boards/karo-tx28/tx28-stk5.c
@@ -371,11 +371,6 @@ void base_board_init(void)
 	for (i = 0; i < ARRAY_SIZE(tx28_starterkit_pad_setup); i++)
 		imx_gpio_mode(tx28_starterkit_pad_setup[i]);
 
-	/* enable IOCLK0 to run at the PLL frequency */
-	imx_set_ioclk(0, 480000000);
-	/* run the SSP unit clock at 100 MHz */
-	imx_set_sspclk(0, 100000000, 1);
-
 	add_generic_device("mxs_mci", 0, NULL, IMX_SSP0_BASE, 0x2000,
 			   IORESOURCE_MEM, &mci_pdata);
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:14 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:14 +0200
Subject: [PATCH 10/17] mtd: gpmi-nand: switch to clk support
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-11-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mtd/nand/nand_mxs.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index dd43a95..56d5ecf 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -21,6 +21,8 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/types.h>
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <common.h>
 #include <malloc.h>
 #include <errno.h>
@@ -140,6 +142,7 @@
 struct mxs_nand_info {
 	struct nand_chip	nand_chip;
 	void __iomem		*io_base;
+	struct clk		*clk;
 	struct mtd_info		mtd;
 	u32		version;
 
@@ -1147,8 +1150,6 @@ int mxs_nand_hw_init(struct mxs_nand_info *info)
 	/* Init the DMA controller. */
 	mxs_dma_init();
 
-	imx_enable_nandclk();
-
 	/* Reset the GPMI block. */
 	ret = mxs_reset_block(gpmi_regs + GPMI_CTRL0, 0);
 	if (ret)
@@ -1200,6 +1201,12 @@ static int mxs_nand_probe(struct device_d *dev)
 	/* XXX: Remove u-boot specific access pointers and use io_base instead? */
 	nand_info->io_base = dev_request_mem_region(dev, 0);
 
+	nand_info->clk = clk_get(dev, NULL);
+	if (IS_ERR(nand_info->clk))
+		return PTR_ERR(nand_info->clk);
+
+	clk_enable(nand_info->clk);
+
 	err = mxs_nand_alloc_buffers(nand_info);
 	if (err)
 		goto err1;
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:11 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:11 +0200
Subject: [PATCH 07/17] mci: mxs: Use dev_*
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-8-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mci/mxs.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/drivers/mci/mxs.c b/drivers/mci/mxs.c
index e6f40eb..cb2911a 100644
--- a/drivers/mci/mxs.c
+++ b/drivers/mci/mxs.c
@@ -116,22 +116,22 @@ static void mxs_mci_finish_request(struct mxs_mci_host *mxs_mci)
  * @param status HW_SSP_STATUS's content
  * @return 0 if no error, negative values else
  */
-static int mxs_mci_get_cmd_error(unsigned status)
+static int mxs_mci_get_cmd_error(struct mxs_mci_host *mxs_mci, unsigned status)
 {
 	if (status & SSP_STATUS_ERROR)
-		pr_debug("Status Reg reports %08X\n", status);
+		dev_dbg(mxs_mci->host.hw_dev, "Status Reg reports %08X\n", status);
 
 	if (status & SSP_STATUS_TIMEOUT) {
-		pr_debug("CMD timeout\n");
+		dev_dbg(mxs_mci->host.hw_dev, "CMD timeout\n");
 		return -ETIMEDOUT;
 	} else if (status & SSP_STATUS_RESP_TIMEOUT) {
-		pr_debug("RESP timeout\n");
+		dev_dbg(mxs_mci->host.hw_dev, "RESP timeout\n");
 		return -ETIMEDOUT;
 	} else if (status & SSP_STATUS_RESP_CRC_ERR) {
-		pr_debug("CMD crc error\n");
+		dev_dbg(mxs_mci->host.hw_dev, "CMD crc error\n");
 		return -EILSEQ;
 	} else if (status & SSP_STATUS_RESP_ERR) {
-		pr_debug("RESP error\n");
+		dev_dbg(mxs_mci->host.hw_dev, "RESP error\n");
 		return -EIO;
 	}
 
@@ -168,7 +168,8 @@ static int mxs_mci_read_data(struct mxs_mci_host *mxs_mci, void *buffer, unsigne
 	uint32_t *p = buffer;
 
 	if (length & 0x3) {
-		pr_debug("Cannot read data sizes not multiple of 4 (request for %u detected)\n",
+		dev_dbg(mxs_mci->host.hw_dev,
+				"Cannot read data sizes not multiple of 4 (request for %u detected)\n",
 				length);
 		return -EINVAL;
 	}
@@ -206,7 +207,8 @@ static int mxs_mci_write_data(struct mxs_mci_host *mxs_mci, const void *buffer,
 	const uint32_t *p = buffer;
 
 	if (length & 0x3) {
-		pr_debug("Cannot write data sizes not multiple of 4 (request for %u detected)\n",
+		dev_dbg(mxs_mci->host.hw_dev,
+				"Cannot write data sizes not multiple of 4 (request for %u detected)\n",
 				length);
 		return -EINVAL;
 	}
@@ -320,7 +322,7 @@ static int mxs_mci_std_cmds(struct mxs_mci_host *mxs_mci, struct mci_cmd *cmd)
 	if (cmd->resp_type & MMC_RSP_PRESENT)
 		mxs_mci_get_cards_response(mxs_mci, cmd);
 
-	return mxs_mci_get_cmd_error(readl(mxs_mci->regs + HW_SSP_STATUS));
+	return mxs_mci_get_cmd_error(mxs_mci, readl(mxs_mci->regs + HW_SSP_STATUS));
 }
 
 /**
@@ -385,7 +387,7 @@ static int mxs_mci_adtc(struct mxs_mci_host *mxs_mci, struct mci_cmd *cmd,
 
 	err = mxs_mci_transfer_data(mxs_mci, data);
 	if (err != 0) {
-		pr_debug(" Transfering data failed\n");
+		dev_dbg(mxs_mci->host.hw_dev, "Transfering data failed with %d\n", err);
 		return err;
 	}
 
@@ -436,7 +438,7 @@ static unsigned mxs_mci_setup_clock_speed(struct mxs_mci_host *mxs_mci, unsigned
 			break;
 	}
 	if (div >= 255) {
-		pr_warning("Cannot set clock to %d Hz\n", nc);
+		dev_warn(mxs_mci->host.hw_dev, "Cannot set clock to %d Hz\n", nc);
 		return 0;
 	}
 
@@ -531,7 +533,8 @@ static void mxs_mci_set_ios(struct mci_host *host, struct mci_ios *ios)
 	}
 
 	mxs_mci->clock = mxs_mci_setup_clock_speed(mxs_mci, ios->clock);
-	pr_debug("IO settings: frequency=%u Hz\n", mxs_mci->clock);
+
+	dev_dbg(host->hw_dev, "IO settings: frequency=%u Hz\n", mxs_mci->clock);
 }
 
 /* ----------------------------------------------------------------------- */
@@ -557,7 +560,7 @@ static int mxs_mci_probe(struct device_d *hw_dev)
 	struct mci_host *host;
 
 	if (hw_dev->platform_data == NULL) {
-		pr_err("Missing platform data\n");
+		dev_err(hw_dev, "Missing platform data\n");
 		return -EINVAL;
 	}
 
@@ -600,18 +603,18 @@ static int mxs_mci_probe(struct device_d *hw_dev)
 #endif
 	if (pd->f_min == 0) {
 		host->f_min = mxs_mci_get_unit_clock(mxs_mci) / 254 / 256;
-		pr_debug("Min. frequency is %u Hz\n", host->f_min);
+		dev_dbg(hw_dev, "Min. frequency is %u Hz\n", host->f_min);
 	} else {
 		host->f_min = pd->f_min;
-		pr_debug("Min. frequency is %u Hz, could be %u Hz\n",
+		dev_dbg(hw_dev, "Min. frequency is %u Hz, could be %u Hz\n",
 			host->f_min, mxs_mci_get_unit_clock(mxs_mci) / 254 / 256);
 	}
 	if (pd->f_max == 0) {
 		host->f_max = mxs_mci_get_unit_clock(mxs_mci) / 2 / 1;
-		pr_debug("Max. frequency is %u Hz\n", host->f_max);
+		dev_dbg(hw_dev, "Max. frequency is %u Hz\n", host->f_max);
 	} else {
 		host->f_max =  pd->f_max;
-		pr_debug("Max. frequency is %u Hz, could be %u Hz\n",
+		dev_dbg(hw_dev, "Max. frequency is %u Hz, could be %u Hz\n",
 			host->f_max, mxs_mci_get_unit_clock(mxs_mci) / 2 / 1);
 	}
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:17 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:17 +0200
Subject: [PATCH 13/17] spi: mxs: Use clk support
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-14-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/spi/mxs_spi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
index e15f2c2..8dfd6d5 100644
--- a/drivers/spi/mxs_spi.c
+++ b/drivers/spi/mxs_spi.c
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include <io.h>
 #include <linux/clk.h>
+#include <linux/err.h>
 #include <asm/mmu.h>
 #include <mach/generic.h>
 #include <mach/imx-regs.h>
@@ -52,7 +53,7 @@ static inline struct mxs_spi *to_mxs(struct spi_master *master)
 static void imx_set_ssp_busclock(struct spi_master *master, uint32_t freq)
 {
 	struct mxs_spi *mxs = to_mxs(master);
-	const uint32_t sspclk = imx_get_sspclk(master->bus_num);
+	const uint32_t sspclk = clk_get_rate(mxs->clk);
 	uint32_t val;
 	uint32_t divide, rate, tgtclk;
 
@@ -266,6 +267,9 @@ static int mxs_spi_probe(struct device_d *dev)
 	mxs->mode = SPI_CPOL | SPI_CPHA;
 
 	mxs->regs = dev_request_mem_region(dev, 0);
+	mxs->clk = clk_get(dev, NULL);
+	if (IS_ERR(mxs->clk))
+		return PTR_ERR(mxs->clk);
 
 	spi_register_master(master);
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:16 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:16 +0200
Subject: [PATCH 12/17] serial: stm: Use clk support
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-13-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/serial/stm-serial.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/serial/stm-serial.c b/drivers/serial/stm-serial.c
index a1bb733..0d7484f 100644
--- a/drivers/serial/stm-serial.c
+++ b/drivers/serial/stm-serial.c
@@ -29,6 +29,8 @@
 #include <gpio.h>
 #include <io.h>
 #include <malloc.h>
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <mach/imx-regs.h>
 #include <mach/clock.h>
 
@@ -56,6 +58,7 @@ struct stm_priv {
 	int baudrate;
 	struct notifier_block notify;
 	void __iomem *base;
+	struct clk *clk;
 };
 
 static void stm_serial_putc(struct console_device *cdev, char c)
@@ -107,7 +110,7 @@ static int stm_serial_setbaudrate(struct console_device *cdev, int new_baudrate)
 	writel(0, priv->base + UARTDBGCR);
 
 	/* Calculate and set baudrate */
-	quot = (imx_get_xclk() * 4) / new_baudrate;
+	quot = (clk_get_rate(priv->clk) * 4) / new_baudrate;
 	writel(quot & 0x3f, priv->base + UARTDBGFBRD);
 	writel(quot >> 6, priv->base + UARTDBGIBRD);
 
@@ -160,6 +163,9 @@ static int stm_serial_probe(struct device_d *dev)
 
 	dev->priv = priv;
 	priv->base = dev_request_mem_region(dev, 0);
+	priv->clk = clk_get(dev, NULL);
+	if (IS_ERR(priv->clk))
+		return PTR_ERR(priv->clk);
 
 	stm_serial_init_port(priv);
 	stm_serial_setbaudrate(cdev, CONFIG_BAUDRATE);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:20 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:20 +0200
Subject: [PATCH 16/17] video: stm: switch to clk support
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-17-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/video/stm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/video/stm.c b/drivers/video/stm.c
index 606e39a..d5212f8 100644
--- a/drivers/video/stm.c
+++ b/drivers/video/stm.c
@@ -24,8 +24,9 @@
 #include <errno.h>
 #include <xfuncs.h>
 #include <io.h>
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <mach/imx-regs.h>
-#include <mach/clock.h>
 #include <mach/fb.h>
 
 #define HW_LCDIF_CTRL 0x00
@@ -144,6 +145,7 @@ struct imxfb_info {
 	struct fb_info info;
 	struct device_d *hw_dev;
 	struct imx_fb_platformdata *pdata;
+	struct clk *clk;
 };
 
 /* the RGB565 true colour mode */
@@ -327,7 +329,7 @@ static int stmfb_activate_var(struct fb_info *fb_info)
 
 	/** @todo ensure HCLK is active at this point of time! */
 
-	size = imx_set_lcdifclk(PICOS2KHZ(mode->pixclock) * 1000);
+	size = clk_set_rate(fbi->clk, PICOS2KHZ(mode->pixclock) * 1000);
 	if (size == 0) {
 		dev_dbg(fbi->hw_dev, "Unable to set a valid pixel clock\n");
 		return -EINVAL;
@@ -490,6 +492,9 @@ static int stmfb_probe(struct device_d *hw_dev)
 	fbi.hw_dev = hw_dev;
 	fbi.base = dev_request_mem_region(hw_dev, 0);
 	fbi.pdata = pdata;
+	fbi.clk = clk_get(hw_dev, NULL);
+	if (IS_ERR(fbi.clk))
+		return PTR_ERR(fbi.clk);
 
 	/* add runtime video info */
 	fbi.info.mode_list = pdata->mode_list;
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:08 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:08 +0200
Subject: [PATCH 04/17] ARM: MXS: Add MXS specific clk types
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-5-git-send-email-s.hauer@pengutronix.de>

MXS needs some special MXS specific clock types:

- pll
- ref (fractional divider)
- busy divider (divider with additional busy bit to poll on a rate change)
- lcdif (Combined clock out of a fractional divider, a divider and a gate.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/Kconfig            |   2 +
 drivers/clk/Makefile        |   2 +
 drivers/clk/mxs/Makefile    |   2 +
 drivers/clk/mxs/clk-div.c   | 112 ++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk-frac.c  | 136 +++++++++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk-lcdif.c |  75 ++++++++++++++++++++++
 drivers/clk/mxs/clk-pll.c   | 117 ++++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk-ref.c   | 152 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk.h       |  52 +++++++++++++++
 9 files changed, 650 insertions(+)
 create mode 100644 drivers/clk/mxs/Makefile
 create mode 100644 drivers/clk/mxs/clk-div.c
 create mode 100644 drivers/clk/mxs/clk-frac.c
 create mode 100644 drivers/clk/mxs/clk-lcdif.c
 create mode 100644 drivers/clk/mxs/clk-pll.c
 create mode 100644 drivers/clk/mxs/clk-ref.c
 create mode 100644 drivers/clk/mxs/clk.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index cfb82b0..af5d8cd 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -88,6 +88,8 @@ config ARCH_MVEBU
 config ARCH_MXS
 	bool "Freescale i.MX23/28 (mxs) based"
 	select GENERIC_GPIO
+	select COMMON_CLK
+	select CLKDEV_LOOKUP
 
 config ARCH_NETX
 	bool "Hilscher NetX based"
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 656b859..d6c923d 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -1,3 +1,5 @@
 obj-$(CONFIG_COMMON_CLK)	+= clk.o clk-fixed.o clk-divider.o clk-fixed-factor.o \
 				clk-mux.o clk-gate.o clk-divider-table.o
 obj-$(CONFIG_CLKDEV_LOOKUP)	+= clkdev.o
+
+obj-$(CONFIG_ARCH_MXS)		+= mxs/
diff --git a/drivers/clk/mxs/Makefile b/drivers/clk/mxs/Makefile
new file mode 100644
index 0000000..8b1173d
--- /dev/null
+++ b/drivers/clk/mxs/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_ARCH_MXS) += clk-ref.o clk-pll.o clk-frac.o clk-div.o
+obj-$(CONFIG_DRIVER_VIDEO_STM) += clk-lcdif.o
diff --git a/drivers/clk/mxs/clk-div.c b/drivers/clk/mxs/clk-div.c
new file mode 100644
index 0000000..e8dae25
--- /dev/null
+++ b/drivers/clk/mxs/clk-div.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <common.h>
+#include <io.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+/**
+ * struct clk_div - mxs integer divider clock
+ * @divider: the parent class
+ * @ops: pointer to clk_ops of parent class
+ * @reg: register address
+ * @busy: busy bit shift
+ *
+ * The mxs divider clock is a subclass of basic clk_divider with an
+ * addtional busy bit.
+ */
+struct clk_div {
+	struct clk_divider divider;
+	const char *parent;
+	const struct clk_ops *ops;
+	void __iomem *reg;
+	u8 busy;
+};
+
+static inline struct clk_div *to_clk_div(struct clk *clk)
+{
+	struct clk_divider *divider = container_of(clk, struct clk_divider, clk);
+
+	return container_of(divider, struct clk_div, divider);
+}
+
+static unsigned long clk_div_recalc_rate(struct clk *clk,
+					 unsigned long parent_rate)
+{
+	struct clk_div *div = to_clk_div(clk);
+
+	return div->ops->recalc_rate(&div->divider.clk, parent_rate);
+}
+
+static long clk_div_round_rate(struct clk *clk, unsigned long rate,
+			       unsigned long *prate)
+{
+	struct clk_div *div = to_clk_div(clk);
+
+	return div->ops->round_rate(&div->divider.clk, rate, prate);
+}
+
+static int clk_div_set_rate(struct clk *clk, unsigned long rate,
+			    unsigned long parent_rate)
+{
+	struct clk_div *div = to_clk_div(clk);
+	int ret;
+
+	ret = div->ops->set_rate(&div->divider.clk, rate, parent_rate);
+	if (ret)
+		return ret;
+
+	if (clk_is_enabled(clk))
+		while (readl(div->reg) & 1 << div->busy);
+
+	return 0;
+}
+
+static struct clk_ops clk_div_ops = {
+	.recalc_rate = clk_div_recalc_rate,
+	.round_rate = clk_div_round_rate,
+	.set_rate = clk_div_set_rate,
+};
+
+struct clk *mxs_clk_div(const char *name, const char *parent_name,
+			void __iomem *reg, u8 shift, u8 width, u8 busy)
+{
+	struct clk_div *div;
+	int ret;
+
+	div = xzalloc(sizeof(*div));
+	if (!div)
+		return ERR_PTR(-ENOMEM);
+
+	div->parent = parent_name;
+	div->divider.clk.name = name;
+	div->divider.clk.ops = &clk_div_ops;
+	div->divider.clk.parent_names = &div->parent;
+	div->divider.clk.num_parents = 1;
+
+	div->reg = reg;
+	div->busy = busy;
+
+	div->divider.reg = reg;
+	div->divider.shift = shift;
+	div->divider.width = width;
+	div->divider.flags = CLK_DIVIDER_ONE_BASED;
+	div->ops = &clk_divider_ops;
+
+	ret = clk_register(&div->divider.clk);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return &div->divider.clk;
+}
diff --git a/drivers/clk/mxs/clk-frac.c b/drivers/clk/mxs/clk-frac.c
new file mode 100644
index 0000000..7aa8504
--- /dev/null
+++ b/drivers/clk/mxs/clk-frac.c
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <common.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <io.h>
+#include <asm-generic/div64.h>
+
+#include "clk.h"
+
+/**
+ * struct clk_frac - mxs fractional divider clock
+ * @hw: clk_hw for the fractional divider clock
+ * @reg: register address
+ * @shift: the divider bit shift
+ * @width: the divider bit width
+ * @busy: busy bit shift
+ *
+ * The clock is an adjustable fractional divider with a busy bit to wait
+ * when the divider is adjusted.
+ */
+struct clk_frac {
+	struct clk clk;
+	const char *parent;
+	void __iomem *reg;
+	u8 shift;
+	u8 width;
+	u8 busy;
+};
+
+#define to_clk_frac(_hw) container_of(_hw, struct clk_frac, clk)
+
+static unsigned long clk_frac_recalc_rate(struct clk *clk,
+					  unsigned long parent_rate)
+{
+	struct clk_frac *frac = to_clk_frac(clk);
+	u32 div;
+
+	div = readl(frac->reg) >> frac->shift;
+	div &= (1 << frac->width) - 1;
+
+	return (parent_rate >> frac->width) * div;
+}
+
+static long clk_frac_round_rate(struct clk *clk, unsigned long rate,
+				unsigned long *prate)
+{
+	struct clk_frac *frac = to_clk_frac(clk);
+	unsigned long parent_rate = *prate;
+	u32 div;
+	u64 tmp;
+
+	if (rate > parent_rate)
+		return -EINVAL;
+
+	tmp = rate;
+	tmp <<= frac->width;
+	do_div(tmp, parent_rate);
+	div = tmp;
+
+	if (!div)
+		return -EINVAL;
+
+	return (parent_rate >> frac->width) * div;
+}
+
+static int clk_frac_set_rate(struct clk *clk, unsigned long rate,
+			     unsigned long parent_rate)
+{
+	struct clk_frac *frac = to_clk_frac(clk);
+	u32 div, val;
+	u64 tmp;
+
+	if (rate > parent_rate)
+		return -EINVAL;
+
+	tmp = rate;
+	tmp <<= frac->width;
+	do_div(tmp, parent_rate);
+	div = tmp;
+
+	if (!div)
+		return -EINVAL;
+
+	val = readl(frac->reg);
+	val &= ~(((1 << frac->width) - 1) << frac->shift);
+	val |= div << frac->shift;
+	writel(val, frac->reg);
+
+	if (clk_is_enabled(clk))
+		while (readl(frac->reg) & 1 << frac->busy);
+
+	return 0;
+}
+
+static struct clk_ops clk_frac_ops = {
+	.recalc_rate = clk_frac_recalc_rate,
+	.round_rate = clk_frac_round_rate,
+	.set_rate = clk_frac_set_rate,
+};
+
+struct clk *mxs_clk_frac(const char *name, const char *parent_name,
+			 void __iomem *reg, u8 shift, u8 width, u8 busy)
+{
+	struct clk_frac *frac;
+	int ret;
+
+	frac = kzalloc(sizeof(*frac), GFP_KERNEL);
+	if (!frac)
+		return ERR_PTR(-ENOMEM);
+
+	frac->parent = parent_name;
+	frac->clk.name = name;
+	frac->clk.ops = &clk_frac_ops;
+	frac->clk.parent_names = &frac->parent;
+	frac->clk.num_parents = 1;
+
+	frac->reg = reg;
+	frac->shift = shift;
+	frac->width = width;
+
+	ret = clk_register(&frac->clk);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return &frac->clk;
+}
diff --git a/drivers/clk/mxs/clk-lcdif.c b/drivers/clk/mxs/clk-lcdif.c
new file mode 100644
index 0000000..86dfe89
--- /dev/null
+++ b/drivers/clk/mxs/clk-lcdif.c
@@ -0,0 +1,75 @@
+#include <common.h>
+#include <io.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+struct clk_lcdif {
+	struct clk clk;
+
+	struct clk *frac, *div, *gate;
+	const char *parent;
+};
+
+#define to_clk_lcdif(_hw) container_of(_hw, struct clk_lcdif, clk)
+
+static int clk_lcdif_set_rate(struct clk *clk, unsigned long rate,
+			    unsigned long unused)
+{
+	struct clk_lcdif *lcdif = to_clk_lcdif(clk);
+	unsigned long frac, div, best_div = 1;
+	int delta, best_delta = 0x7fffffff;
+	unsigned long frate, rrate, best_frate;
+	unsigned long parent_rate = clk_get_rate(clk_get_parent(lcdif->frac));
+
+	best_frate = parent_rate;
+
+	for (frac = 18; frac < 35; frac++) {
+		frate = (parent_rate / frac) * 18;
+		div = frate / rate;
+		if (!div)
+			div = 1;
+		rrate = frate / div;
+		delta = rate - rrate;
+		if (abs(delta) < abs(best_delta)) {
+			best_frate = frate;
+			best_div = div;
+			best_delta = delta;
+		}
+	}
+
+	clk_set_rate(lcdif->frac, best_frate);
+	best_frate = clk_get_rate(lcdif->frac);
+	clk_set_rate(lcdif->div, (best_frate + best_div) / best_div);
+
+	return 0;
+}
+
+static const struct clk_ops clk_lcdif_ops = {
+	.set_rate	= clk_lcdif_set_rate,
+};
+
+struct clk *mxs_clk_lcdif(const char *name, struct clk *frac, struct clk *div,
+			  struct clk *gate)
+{
+	struct clk_lcdif *lcdif;
+	int ret;
+
+	lcdif = xzalloc(sizeof(*lcdif));
+
+	lcdif->parent = gate->name;
+	lcdif->frac = frac;
+	lcdif->div = div;
+	lcdif->gate = gate;
+	lcdif->clk.name = name;
+	lcdif->clk.ops = &clk_lcdif_ops;
+	lcdif->clk.parent_names = &lcdif->parent;
+	lcdif->clk.num_parents = 1;
+
+	ret = clk_register(&lcdif->clk);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return &lcdif->clk;
+}
diff --git a/drivers/clk/mxs/clk-pll.c b/drivers/clk/mxs/clk-pll.c
new file mode 100644
index 0000000..89fd6b5
--- /dev/null
+++ b/drivers/clk/mxs/clk-pll.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <common.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <io.h>
+
+#include "clk.h"
+
+#define SET	0x4
+#define CLR	0x8
+
+/**
+ * struct clk_pll - mxs pll clock
+ * @hw: clk_hw for the pll
+ * @base: base address of the pll
+ * @power: the shift of power bit
+ * @rate: the clock rate of the pll
+ *
+ * The mxs pll is a fixed rate clock with power and gate control,
+ * and the shift of gate bit is always 31.
+ */
+struct clk_pll {
+	struct clk clk;
+	const char *parent;
+	void __iomem *base;
+	u8 power;
+	unsigned long rate;
+};
+
+#define to_clk_pll(_hw) container_of(_hw, struct clk_pll, clk)
+
+static int clk_pll_enable(struct clk *clk)
+{
+	struct clk_pll *pll = to_clk_pll(clk);
+
+	writel(1 << pll->power, pll->base + SET);
+
+	udelay(10);
+
+	writel(1 << 31, pll->base + CLR);
+
+	return 0;
+}
+
+static void clk_pll_disable(struct clk *clk)
+{
+	struct clk_pll *pll = to_clk_pll(clk);
+
+	writel(1 << 31, pll->base + SET);
+
+	writel(1 << pll->power, pll->base + CLR);
+}
+
+static int clk_pll_is_enabled(struct clk *clk)
+{
+	struct clk_pll *pll = to_clk_pll(clk);
+	u32 val;
+
+	val = readl(pll->base);
+
+	if (val & (1 << 31))
+		return 0;
+	else
+		return 1;
+}
+
+static unsigned long clk_pll_recalc_rate(struct clk *clk,
+					 unsigned long parent_rate)
+{
+	struct clk_pll *pll = to_clk_pll(clk);
+
+	return pll->rate;
+}
+
+static const struct clk_ops clk_pll_ops = {
+	.enable = clk_pll_enable,
+	.disable = clk_pll_disable,
+	.recalc_rate = clk_pll_recalc_rate,
+	.is_enabled = clk_pll_is_enabled,
+};
+
+struct clk *mxs_clk_pll(const char *name, const char *parent_name,
+			void __iomem *base, u8 power, unsigned long rate)
+{
+	struct clk_pll *pll;
+	int ret;
+
+	pll = xzalloc(sizeof(*pll));
+	if (!pll)
+		return ERR_PTR(-ENOMEM);
+
+	pll->parent = parent_name;
+	pll->clk.name = name;
+	pll->clk.ops = &clk_pll_ops;
+	pll->clk.parent_names = &pll->parent;
+	pll->clk.num_parents = 1;
+
+	pll->base = base;
+	pll->rate = rate;
+	pll->power = power;
+
+	ret = clk_register(&pll->clk);
+	if (ret)
+		ERR_PTR(ret);
+
+	return &pll->clk;
+}
diff --git a/drivers/clk/mxs/clk-ref.c b/drivers/clk/mxs/clk-ref.c
new file mode 100644
index 0000000..d62ebfc
--- /dev/null
+++ b/drivers/clk/mxs/clk-ref.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <common.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <io.h>
+#include <asm-generic/div64.h>
+
+#include "clk.h"
+
+/**
+ * struct clk_ref - mxs reference clock
+ * @hw: clk_hw for the reference clock
+ * @reg: register address
+ * @idx: the index of the reference clock within the same register
+ *
+ * The mxs reference clock sources from pll.  Every 4 reference clocks share
+ * one register space, and @idx is used to identify them.  Each reference
+ * clock has a gate control and a fractional * divider.  The rate is calculated
+ * as pll rate  * (18 / FRAC), where FRAC = 18 ~ 35.
+ */
+struct clk_ref {
+	struct clk clk;
+	const char *parent;
+	void __iomem *reg;
+	u8 idx;
+};
+
+#define to_clk_ref(_hw) container_of(_hw, struct clk_ref, clk)
+
+#define SET	0x4
+#define CLR	0x8
+
+static int clk_ref_enable(struct clk *clk)
+{
+	struct clk_ref *ref = to_clk_ref(clk);
+
+	writel(1 << ((ref->idx + 1) * 8 - 1), ref->reg + CLR);
+
+	return 0;
+}
+
+static void clk_ref_disable(struct clk *clk)
+{
+	struct clk_ref *ref = to_clk_ref(clk);
+
+	writel(1 << ((ref->idx + 1) * 8 - 1), ref->reg + SET);
+}
+
+static unsigned long clk_ref_recalc_rate(struct clk *clk,
+					 unsigned long parent_rate)
+{
+	struct clk_ref *ref = to_clk_ref(clk);
+	u64 tmp = parent_rate;
+	u8 frac = (readl(ref->reg) >> (ref->idx * 8)) & 0x3f;
+
+	tmp *= 18;
+	do_div(tmp, frac);
+
+	return tmp;
+}
+
+static long clk_ref_round_rate(struct clk *clk, unsigned long rate,
+			       unsigned long *prate)
+{
+	unsigned long parent_rate = *prate;
+	u64 tmp = parent_rate;
+	u32 frac;
+
+	tmp = tmp * 18 + rate / 2;
+	do_div(tmp, rate);
+	frac = tmp;
+
+	if (frac < 18)
+		frac = 18;
+	else if (frac > 35)
+		frac = 35;
+
+	tmp = parent_rate;
+	tmp *= 18;
+	do_div(tmp, frac);
+
+	return tmp;
+}
+
+static int clk_ref_set_rate(struct clk *clk, unsigned long rate,
+			    unsigned long parent_rate)
+{
+	struct clk_ref *ref = to_clk_ref(clk);
+	u64 tmp = parent_rate;
+	u32 val;
+	u32 frac, shift = ref->idx * 8;
+
+	tmp = tmp * 18 + rate / 2;
+	do_div(tmp, rate);
+	frac = tmp;
+
+	if (frac < 18)
+		frac = 18;
+	else if (frac > 35)
+		frac = 35;
+
+	val = readl(ref->reg);
+	val &= ~(0x3f << shift);
+	val |= frac << shift;
+	writel(val, ref->reg);
+
+	return 0;
+}
+
+static const struct clk_ops clk_ref_ops = {
+	.enable		= clk_ref_enable,
+	.disable	= clk_ref_disable,
+	.recalc_rate	= clk_ref_recalc_rate,
+	.round_rate	= clk_ref_round_rate,
+	.set_rate	= clk_ref_set_rate,
+};
+
+struct clk *mxs_clk_ref(const char *name, const char *parent_name,
+			void __iomem *reg, u8 idx)
+{
+	struct clk_ref *ref;
+	int ret;
+
+	ref = xzalloc(sizeof(*ref));
+	if (!ref)
+		return ERR_PTR(-ENOMEM);
+
+	ref->parent = parent_name;
+	ref->clk.name = name;
+	ref->clk.ops = &clk_ref_ops;
+	ref->clk.parent_names = &ref->parent;
+	ref->clk.num_parents = 1;
+
+	ref->reg = reg;
+	ref->idx = idx;
+
+	ret = clk_register(&ref->clk);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return &ref->clk;
+}
diff --git a/drivers/clk/mxs/clk.h b/drivers/clk/mxs/clk.h
new file mode 100644
index 0000000..b4fcfa0
--- /dev/null
+++ b/drivers/clk/mxs/clk.h
@@ -0,0 +1,52 @@
+#ifndef __MXS_CLK_H
+#define __MXS_CLK_H
+
+int mxs_clk_wait(void __iomem *reg, u8 shift);
+
+struct clk *mxs_clk_pll(const char *name, const char *parent_name,
+			void __iomem *base, u8 power, unsigned long rate);
+
+struct clk *mxs_clk_ref(const char *name, const char *parent_name,
+			void __iomem *reg, u8 idx);
+
+struct clk *mxs_clk_div(const char *name, const char *parent_name,
+			void __iomem *reg, u8 shift, u8 width, u8 busy);
+
+struct clk *mxs_clk_frac(const char *name, const char *parent_name,
+			 void __iomem *reg, u8 shift, u8 width, u8 busy);
+
+#ifdef CONFIG_DRIVER_VIDEO_STM
+struct clk *mxs_clk_lcdif(const char *name, struct clk *frac, struct clk *div,
+			  struct clk *gate);
+#else
+static inline struct clk *mxs_clk_lcdif(const char *name, struct clk *frac, struct clk *div,
+			  struct clk *gate)
+{
+	return ERR_PTR(-ENOSYS);
+}
+#endif
+
+static inline struct clk *mxs_clk_fixed(const char *name, int rate)
+{
+	return clk_fixed(name, rate);
+}
+
+static inline struct clk *mxs_clk_gate(const char *name,
+			const char *parent_name, void __iomem *reg, u8 shift)
+{
+	return clk_gate_inverted(name, parent_name, reg, shift);
+}
+
+static inline struct clk *mxs_clk_mux(const char *name, void __iomem *reg,
+		u8 shift, u8 width, const char **parent_names, int num_parents)
+{
+	return clk_mux(name, reg, shift, width, parent_names, num_parents);
+}
+
+static inline struct clk *mxs_clk_fixed_factor(const char *name,
+		const char *parent_name, unsigned int mult, unsigned int div)
+{
+	return clk_fixed_factor(name, parent_name, mult, div);
+}
+
+#endif /* __MXS_CLK_H */
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:12 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:12 +0200
Subject: [PATCH 08/17] net: fec: Use clk API unconditionally
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-9-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/net/fec_imx.c | 31 +++++++++----------------------
 1 file changed, 9 insertions(+), 22 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index 1346c91..2f31352 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -45,19 +45,6 @@ struct fec_frame {
 	uint8_t head[16];	/* MAC header(6 + 6 + 2) + 2(aligned) */
 };
 
-#ifdef CONFIG_COMMON_CLK
-static inline unsigned long fec_clk_get_rate(struct fec_priv *fec)
-{
-	return clk_get_rate(fec->clk);
-}
-#else
-static inline unsigned long fec_clk_get_rate(struct fec_priv *fec)
-{
-	return imx_get_fecclk();
-}
-#endif
-
-
 /*
  * MII-interface related functions
  */
@@ -69,7 +56,7 @@ static int fec_miibus_read(struct mii_bus *bus, int phyAddr, int regAddr)
 	uint32_t phy;		/* convenient holder for the PHY */
 	uint64_t start;
 
-	writel(((fec_clk_get_rate(fec) >> 20) / 5) << 1,
+	writel(((clk_get_rate(fec->clk) >> 20) / 5) << 1,
 			fec->regs + FEC_MII_SPEED);
 	/*
 	 * reading from any PHY's register is done by properly
@@ -112,7 +99,7 @@ static int fec_miibus_write(struct mii_bus *bus, int phyAddr,
 	uint32_t phy;		/* convenient holder for the PHY */
 	uint64_t start;
 
-	writel(((fec_clk_get_rate(fec) >> 20) / 5) << 1,
+	writel(((clk_get_rate(fec->clk) >> 20) / 5) << 1,
 			fec->regs + FEC_MII_SPEED);
 
 	reg = regAddr << FEC_MII_DATA_RA_SHIFT;
@@ -305,7 +292,7 @@ static int fec_init(struct eth_device *dev)
 	 * Set MII_SPEED = (1/(mii_speed * 2)) * System Clock
 	 * and do not drop the Preamble.
 	 */
-	writel(((fec_clk_get_rate(fec) >> 20) / 5) << 1,
+	writel(((clk_get_rate(fec->clk) >> 20) / 5) << 1,
 			fec->regs + FEC_MII_SPEED);
 
 	if (fec->interface == PHY_INTERFACE_MODE_RMII) {
@@ -674,14 +661,14 @@ static int fec_probe(struct device_d *dev)
 	edev->set_ethaddr = fec_set_hwaddr;
 	edev->parent = dev;
 
-	if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-		fec->clk = clk_get(dev, NULL);
-		if (IS_ERR(fec->clk)) {
-			ret = PTR_ERR(fec->clk);
-			goto err_free;
-		}
+	fec->clk = clk_get(dev, NULL);
+	if (IS_ERR(fec->clk)) {
+		ret = PTR_ERR(fec->clk);
+		goto err_free;
 	}
 
+	clk_enable(fec->clk);
+
 	fec->regs = dev_request_mem_region(dev, 0);
 
 	/* Reset chip. */
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:09 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:09 +0200
Subject: [PATCH 05/17] ARM: MXS: add clk drivers
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-6-git-send-email-s.hauer@pengutronix.de>

This adds support for the i.MX23 and i.MX28 clock modules. This mostly is
a copy from the kernel.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-mxs/soc-imx23.c |   9 ++
 arch/arm/mach-mxs/soc-imx28.c |   9 ++
 drivers/clk/mxs/Makefile      |   3 +
 drivers/clk/mxs/clk-imx23.c   | 156 +++++++++++++++++++++++++++++++++
 drivers/clk/mxs/clk-imx28.c   | 195 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 372 insertions(+)
 create mode 100644 drivers/clk/mxs/clk-imx23.c
 create mode 100644 drivers/clk/mxs/clk-imx28.c

diff --git a/arch/arm/mach-mxs/soc-imx23.c b/arch/arm/mach-mxs/soc-imx23.c
index 6819b3c..4e45064 100644
--- a/arch/arm/mach-mxs/soc-imx23.c
+++ b/arch/arm/mach-mxs/soc-imx23.c
@@ -35,3 +35,12 @@ void __noreturn reset_cpu(unsigned long addr)
 	/*NOTREACHED*/
 }
 EXPORT_SYMBOL(reset_cpu);
+
+static int imx23_devices_init(void)
+{
+
+	add_generic_device("imx23-clkctrl", 0, NULL, IMX_CCM_BASE, 0x100, IORESOURCE_MEM, NULL);
+
+	return 0;
+}
+postcore_initcall(imx23_devices_init);
diff --git a/arch/arm/mach-mxs/soc-imx28.c b/arch/arm/mach-mxs/soc-imx28.c
index ed931af..426f8ac 100644
--- a/arch/arm/mach-mxs/soc-imx28.c
+++ b/arch/arm/mach-mxs/soc-imx28.c
@@ -53,3 +53,12 @@ static int imx28_init(void)
 	return 0;
 }
 postcore_initcall(imx28_init);
+
+static int imx28_devices_init(void)
+{
+
+	add_generic_device("imx28-clkctrl", 0, NULL, IMX_CCM_BASE, 0x100, IORESOURCE_MEM, NULL);
+
+	return 0;
+}
+postcore_initcall(imx28_devices_init);
diff --git a/drivers/clk/mxs/Makefile b/drivers/clk/mxs/Makefile
index 8b1173d..fb4e5db 100644
--- a/drivers/clk/mxs/Makefile
+++ b/drivers/clk/mxs/Makefile
@@ -1,2 +1,5 @@
 obj-$(CONFIG_ARCH_MXS) += clk-ref.o clk-pll.o clk-frac.o clk-div.o
 obj-$(CONFIG_DRIVER_VIDEO_STM) += clk-lcdif.o
+
+obj-$(CONFIG_ARCH_IMX23) += clk-imx23.o
+obj-$(CONFIG_ARCH_IMX28) += clk-imx28.o
diff --git a/drivers/clk/mxs/clk-imx23.c b/drivers/clk/mxs/clk-imx23.c
new file mode 100644
index 0000000..4b15350
--- /dev/null
+++ b/drivers/clk/mxs/clk-imx23.c
@@ -0,0 +1,156 @@
+/*
+ *  Copyright (C) 2008 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+#include <linux/clk.h>
+#include <io.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <mach/imx-regs.h>
+
+#include "clk.h"
+
+#define PLLCTRL0		(regs + 0x0000)
+#define CPU			(regs + 0x0020)
+#define HBUS			(regs + 0x0030)
+#define XBUS			(regs + 0x0040)
+#define XTAL			(regs + 0x0050)
+#define PIX			(regs + 0x0060)
+#define SSP			(regs + 0x0070)
+#define GPMI			(regs + 0x0080)
+#define SPDIF			(regs + 0x0090)
+#define EMI			(regs + 0x00a0)
+#define SAIF			(regs + 0x00c0)
+#define TV			(regs + 0x00d0)
+#define ETM			(regs + 0x00e0)
+#define FRAC			(regs + 0x00f0)
+#define CLKSEQ			(regs + 0x0110)
+
+static const char *sel_pll[]  = { "pll", "ref_xtal", };
+static const char *sel_cpu[]  = { "ref_cpu", "ref_xtal", };
+static const char *sel_pix[]  = { "ref_pix", "ref_xtal", };
+static const char *sel_io[]   = { "ref_io", "ref_xtal", };
+static const char *cpu_sels[] = { "cpu_pll", "cpu_xtal", };
+static const char *emi_sels[] = { "emi_pll", "emi_xtal", };
+
+enum imx23_clk {
+	ref_xtal, pll, ref_cpu, ref_emi, ref_pix, ref_io, saif_sel,
+	lcdif_sel, gpmi_sel, ssp_sel, emi_sel, cpu, etm_sel, cpu_pll,
+	cpu_xtal, hbus, xbus, lcdif_div, ssp_div, gpmi_div, emi_pll,
+	emi_xtal, etm_div, saif_div, clk32k_div, rtc, adc, spdif_div,
+	clk32k, dri, pwm, filt, uart, ssp, gpmi, spdif, emi, saif,
+	lcdif, etm, usb, usb_phy, lcdif_comp,
+	clk_max
+};
+
+static struct clk *clks[clk_max];
+
+int __init mx23_clocks_init(void __iomem *regs)
+{
+	clks[ref_xtal] = mxs_clk_fixed("ref_xtal", 24000000);
+	clks[pll] = mxs_clk_pll("pll", "ref_xtal", PLLCTRL0, 16, 480000000);
+	clks[ref_cpu] = mxs_clk_ref("ref_cpu", "pll", FRAC, 0);
+	clks[ref_emi] = mxs_clk_ref("ref_emi", "pll", FRAC, 1);
+	clks[ref_pix] = mxs_clk_ref("ref_pix", "pll", FRAC, 2);
+	clks[ref_io] = mxs_clk_ref("ref_io", "pll", FRAC, 3);
+	clks[saif_sel] = mxs_clk_mux("saif_sel", CLKSEQ, 0, 1, sel_pll, ARRAY_SIZE(sel_pll));
+	clks[lcdif_sel] = mxs_clk_mux("lcdif_sel", CLKSEQ, 1, 1, sel_pix, ARRAY_SIZE(sel_pix));
+	clks[gpmi_sel] = mxs_clk_mux("gpmi_sel", CLKSEQ, 4, 1, sel_io, ARRAY_SIZE(sel_io));
+	clks[ssp_sel] = mxs_clk_mux("ssp_sel", CLKSEQ, 5, 1, sel_io, ARRAY_SIZE(sel_io));
+	clks[emi_sel] = mxs_clk_mux("emi_sel", CLKSEQ, 6, 1, emi_sels, ARRAY_SIZE(emi_sels));
+	clks[cpu] = mxs_clk_mux("cpu", CLKSEQ, 7, 1, cpu_sels, ARRAY_SIZE(cpu_sels));
+	clks[etm_sel] = mxs_clk_mux("etm_sel", CLKSEQ, 8, 1, sel_cpu, ARRAY_SIZE(sel_cpu));
+	clks[cpu_pll] = mxs_clk_div("cpu_pll", "ref_cpu", CPU, 0, 6, 28);
+	clks[cpu_xtal] = mxs_clk_div("cpu_xtal", "ref_xtal", CPU, 16, 10, 29);
+	clks[hbus] = mxs_clk_div("hbus", "cpu", HBUS, 0, 5, 29);
+	clks[xbus] = mxs_clk_div("xbus", "ref_xtal", XBUS, 0, 10, 31);
+	clks[lcdif_div] = mxs_clk_div("lcdif_div", "lcdif_sel", PIX, 0, 12, 29);
+	clks[ssp_div] = mxs_clk_div("ssp_div", "ssp_sel", SSP, 0, 9, 29);
+	clks[gpmi_div] = mxs_clk_div("gpmi_div", "gpmi_sel", GPMI, 0, 10, 29);
+	clks[emi_pll] = mxs_clk_div("emi_pll", "ref_emi", EMI, 0, 6, 28);
+	clks[emi_xtal] = mxs_clk_div("emi_xtal", "ref_xtal", EMI, 8, 4, 29);
+	clks[etm_div] = mxs_clk_div("etm_div", "etm_sel", ETM, 0, 6, 29);
+	clks[saif_div] = mxs_clk_frac("saif_div", "saif_sel", SAIF, 0, 16, 29);
+	clks[clk32k_div] = mxs_clk_fixed_factor("clk32k_div", "ref_xtal", 1, 750);
+	clks[rtc] = mxs_clk_fixed_factor("rtc", "ref_xtal", 1, 768);
+	clks[adc] = mxs_clk_fixed_factor("adc", "clk32k", 1, 16);
+	clks[spdif_div] = mxs_clk_fixed_factor("spdif_div", "pll", 1, 4);
+	clks[clk32k] = mxs_clk_gate("clk32k", "clk32k_div", XTAL, 26);
+	clks[dri] = mxs_clk_gate("dri", "ref_xtal", XTAL, 28);
+	clks[pwm] = mxs_clk_gate("pwm", "ref_xtal", XTAL, 29);
+	clks[filt] = mxs_clk_gate("filt", "ref_xtal", XTAL, 30);
+	clks[uart] = mxs_clk_gate("uart", "ref_xtal", XTAL, 31);
+	clks[ssp] = mxs_clk_gate("ssp", "ssp_div", SSP, 31);
+	clks[gpmi] = mxs_clk_gate("gpmi", "gpmi_div", GPMI, 31);
+	clks[spdif] = mxs_clk_gate("spdif", "spdif_div", SPDIF, 31);
+	clks[emi] = mxs_clk_gate("emi", "emi_sel", EMI, 31);
+	clks[saif] = mxs_clk_gate("saif", "saif_div", SAIF, 31);
+	clks[lcdif] = mxs_clk_gate("lcdif", "lcdif_div", PIX, 31);
+	clks[etm] = mxs_clk_gate("etm", "etm_div", ETM, 31);
+	clks[lcdif_comp] = mxs_clk_lcdif("lcdif_comp", clks[ref_pix],
+			clks[lcdif_div], clks[lcdif]);
+
+	clk_set_rate(clks[ref_io], 480000000);
+	clk_set_parent(clks[ssp_sel], clks[ref_io]);
+	clk_set_rate(clks[ssp_div], 96000000);
+	clk_set_parent(clks[lcdif_sel], clks[ref_pix]);
+
+	clkdev_add_physbase(clks[ssp], IMX_SSP1_BASE, NULL);
+	clkdev_add_physbase(clks[ssp], IMX_SSP2_BASE, NULL);
+	clkdev_add_physbase(clks[xbus], IMX_DBGUART_BASE, NULL);
+	clkdev_add_physbase(clks[hbus], IMX_OCOTP_BASE, NULL);
+	clkdev_add_physbase(clks[uart], IMX_UART1_BASE, NULL);
+	clkdev_add_physbase(clks[uart], IMX_UART2_BASE, NULL);
+	clkdev_add_physbase(clks[gpmi], MXS_GPMI_BASE, NULL);
+	if (IS_ENABLED(CONFIG_DRIVER_VIDEO_STM))
+		clkdev_add_physbase(clks[lcdif_comp], IMX_FB_BASE, NULL);
+
+	return 0;
+}
+
+static int imx23_ccm_probe(struct device_d *dev)
+{
+	void __iomem *regs;
+
+	regs = dev_request_mem_region(dev, 0);
+
+	mx23_clocks_init(regs);
+
+	return 0;
+}
+
+static __maybe_unused struct of_device_id imx23_ccm_dt_ids[] = {
+	{
+		.compatible = "fsl,imx23-clkctrl",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d imx23_ccm_driver = {
+	.probe	= imx23_ccm_probe,
+	.name	= "imx23-clkctrl",
+	.of_compatible = DRV_OF_COMPAT(imx23_ccm_dt_ids),
+};
+
+static int imx23_ccm_init(void)
+{
+	return platform_driver_register(&imx23_ccm_driver);
+}
+postcore_initcall(imx23_ccm_init);
diff --git a/drivers/clk/mxs/clk-imx28.c b/drivers/clk/mxs/clk-imx28.c
new file mode 100644
index 0000000..0350aff
--- /dev/null
+++ b/drivers/clk/mxs/clk-imx28.c
@@ -0,0 +1,195 @@
+/*
+ *  Copyright (C) 2008 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * 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.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+#include <linux/clk.h>
+#include <io.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <mach/imx-regs.h>
+
+#include "clk.h"
+
+#define PLL0CTRL0		(regs + 0x0000)
+#define PLL1CTRL0		(regs + 0x0020)
+#define PLL2CTRL0		(regs + 0x0040)
+#define CPU			(regs + 0x0050)
+#define HBUS			(regs + 0x0060)
+#define XBUS			(regs + 0x0070)
+#define XTAL			(regs + 0x0080)
+#define SSP0			(regs + 0x0090)
+#define SSP1			(regs + 0x00a0)
+#define SSP2			(regs + 0x00b0)
+#define SSP3			(regs + 0x00c0)
+#define GPMI			(regs + 0x00d0)
+#define SPDIF			(regs + 0x00e0)
+#define EMI			(regs + 0x00f0)
+#define SAIF0			(regs + 0x0100)
+#define SAIF1			(regs + 0x0110)
+#define LCDIF			(regs + 0x0120)
+#define ETM			(regs + 0x0130)
+#define ENET			(regs + 0x0140)
+#define FLEXCAN			(regs + 0x0160)
+#define FRAC0			(regs + 0x01b0)
+#define FRAC1			(regs + 0x01c0)
+#define CLKSEQ			(regs + 0x01d0)
+
+static const char *sel_cpu[]  = { "ref_cpu", "ref_xtal", };
+static const char *sel_io0[]  = { "ref_io0", "ref_xtal", };
+static const char *sel_io1[]  = { "ref_io1", "ref_xtal", };
+static const char *sel_pix[]  = { "ref_pix", "ref_xtal", };
+static const char *sel_gpmi[] = { "ref_gpmi", "ref_xtal", };
+static const char *cpu_sels[] = { "cpu_pll", "cpu_xtal", };
+static const char *emi_sels[] = { "emi_pll", "emi_xtal", };
+static const char *ptp_sels[] = { "ref_xtal", "pll0", };
+
+enum imx28_clk {
+	ref_xtal, pll0, pll1, pll2, ref_cpu, ref_emi, ref_io0, ref_io1,
+	ref_pix, ref_hsadc, ref_gpmi, saif0_sel, saif1_sel, gpmi_sel,
+	ssp0_sel, ssp1_sel, ssp2_sel, ssp3_sel, emi_sel, etm_sel,
+	lcdif_sel, cpu, ptp_sel, cpu_pll, cpu_xtal, hbus, xbus,
+	ssp0_div, ssp1_div, ssp2_div, ssp3_div, gpmi_div, emi_pll,
+	emi_xtal, lcdif_div, etm_div, ptp, saif0_div, saif1_div,
+	clk32k_div, rtc, lradc, spdif_div, clk32k, pwm, uart, ssp0,
+	ssp1, ssp2, ssp3, gpmi, spdif, emi, saif0, saif1, lcdif, etm,
+	fec, can0, can1, usb0, usb1, usb0_phy, usb1_phy, enet_out,
+	lcdif_comp, clk_max
+};
+
+static struct clk *clks[clk_max];
+
+int __init mx28_clocks_init(void __iomem *regs)
+{
+	clks[ref_xtal] = clk_fixed("ref_xtal", 24000000);
+	clks[pll0] = mxs_clk_pll("pll0", "ref_xtal", PLL0CTRL0, 17, 480000000);
+	clks[pll1] = mxs_clk_pll("pll1", "ref_xtal", PLL1CTRL0, 17, 480000000);
+	clks[pll2] = mxs_clk_pll("pll2", "ref_xtal", PLL2CTRL0, 23, 50000000);
+	clks[ref_cpu] = mxs_clk_ref("ref_cpu", "pll0", FRAC0, 0);
+	clks[ref_emi] = mxs_clk_ref("ref_emi", "pll0", FRAC0, 1);
+	clks[ref_io1] = mxs_clk_ref("ref_io1", "pll0", FRAC0, 2);
+	clks[ref_io0] = mxs_clk_ref("ref_io0", "pll0", FRAC0, 3);
+	clks[ref_pix] = mxs_clk_ref("ref_pix", "pll0", FRAC1, 0);
+	clks[ref_hsadc] = mxs_clk_ref("ref_hsadc", "pll0", FRAC1, 1);
+	clks[ref_gpmi] = mxs_clk_ref("ref_gpmi", "pll0", FRAC1, 2);
+	clks[gpmi_sel] = mxs_clk_mux("gpmi_sel", CLKSEQ, 2, 1, sel_gpmi, ARRAY_SIZE(sel_gpmi));
+	clks[ssp0_sel] = mxs_clk_mux("ssp0_sel", CLKSEQ, 3, 1, sel_io0, ARRAY_SIZE(sel_io0));
+	clks[ssp1_sel] = mxs_clk_mux("ssp1_sel", CLKSEQ, 4, 1, sel_io0, ARRAY_SIZE(sel_io0));
+	clks[ssp2_sel] = mxs_clk_mux("ssp2_sel", CLKSEQ, 5, 1, sel_io1, ARRAY_SIZE(sel_io1));
+	clks[ssp3_sel] = mxs_clk_mux("ssp3_sel", CLKSEQ, 6, 1, sel_io1, ARRAY_SIZE(sel_io1));
+	clks[emi_sel] = mxs_clk_mux("emi_sel", CLKSEQ, 7, 1, emi_sels, ARRAY_SIZE(emi_sels));
+	clks[etm_sel] = mxs_clk_mux("etm_sel", CLKSEQ, 8, 1, sel_cpu, ARRAY_SIZE(sel_cpu));
+	clks[lcdif_sel] = mxs_clk_mux("lcdif_sel", CLKSEQ, 14, 1, sel_pix, ARRAY_SIZE(sel_pix));
+	clks[cpu] = mxs_clk_mux("cpu", CLKSEQ, 18, 1, cpu_sels, ARRAY_SIZE(cpu_sels));
+	clks[ptp_sel] = mxs_clk_mux("ptp_sel", ENET, 19, 1, ptp_sels, ARRAY_SIZE(ptp_sels));
+	clks[cpu_pll] = mxs_clk_div("cpu_pll", "ref_cpu", CPU, 0, 6, 28);
+	clks[cpu_xtal] = mxs_clk_div("cpu_xtal", "ref_xtal", CPU, 16, 10, 29);
+	clks[hbus] = mxs_clk_div("hbus", "cpu", HBUS, 0, 5, 31);
+	clks[xbus] = mxs_clk_div("xbus", "ref_xtal", XBUS, 0, 10, 31);
+	clks[ssp0_div] = mxs_clk_div("ssp0_div", "ssp0_sel", SSP0, 0, 9, 29);
+	clks[ssp1_div] = mxs_clk_div("ssp1_div", "ssp1_sel", SSP1, 0, 9, 29);
+	clks[ssp2_div] = mxs_clk_div("ssp2_div", "ssp2_sel", SSP2, 0, 9, 29);
+	clks[ssp3_div] = mxs_clk_div("ssp3_div", "ssp3_sel", SSP3, 0, 9, 29);
+	clks[gpmi_div] = mxs_clk_div("gpmi_div", "gpmi_sel", GPMI, 0, 10, 29);
+	clks[emi_pll] = mxs_clk_div("emi_pll", "ref_emi", EMI, 0, 6, 28);
+	clks[emi_xtal] = mxs_clk_div("emi_xtal", "ref_xtal", EMI, 8, 4, 29);
+	clks[lcdif_div] = mxs_clk_div("lcdif_div", "lcdif_sel", LCDIF, 0, 13, 29);
+	clks[etm_div] = mxs_clk_div("etm_div", "etm_sel", ETM, 0, 7, 29);
+	clks[clk32k_div] = mxs_clk_fixed_factor("clk32k_div", "ref_xtal", 1, 750);
+	clks[rtc] = mxs_clk_fixed_factor("rtc", "ref_xtal", 1, 768);
+	clks[lradc] = mxs_clk_fixed_factor("lradc", "clk32k", 1, 16);
+	clks[clk32k] = mxs_clk_gate("clk32k", "clk32k_div", XTAL, 26);
+	clks[pwm] = mxs_clk_gate("pwm", "ref_xtal", XTAL, 29);
+	clks[uart] = mxs_clk_gate("uart", "ref_xtal", XTAL, 31);
+	clks[ssp0] = mxs_clk_gate("ssp0", "ssp0_div", SSP0, 31);
+	clks[ssp1] = mxs_clk_gate("ssp1", "ssp1_div", SSP1, 31);
+	clks[ssp2] = mxs_clk_gate("ssp2", "ssp2_div", SSP2, 31);
+	clks[ssp3] = mxs_clk_gate("ssp3", "ssp3_div", SSP3, 31);
+	clks[gpmi] = mxs_clk_gate("gpmi", "gpmi_div", GPMI, 31);
+	clks[emi] = mxs_clk_gate("emi", "emi_sel", EMI, 31);
+	clks[lcdif] = mxs_clk_gate("lcdif", "lcdif_div", LCDIF, 31);
+	clks[etm] = mxs_clk_gate("etm", "etm_div", ETM, 31);
+	clks[fec] = mxs_clk_gate("fec", "hbus", ENET, 30);
+	clks[usb0_phy] = mxs_clk_gate("usb0_phy", "pll0", PLL0CTRL0, 18);
+	clks[usb1_phy] = mxs_clk_gate("usb1_phy", "pll1", PLL1CTRL0, 18);
+	clks[enet_out] = clk_gate("enet_out", "pll2", ENET, 18);
+	clks[lcdif_comp] = mxs_clk_lcdif("lcdif_comp", clks[ref_pix],
+			clks[lcdif_div], clks[lcdif]);
+
+	clk_set_rate(clks[ref_io0], 480000000);
+	clk_set_rate(clks[ref_io1], 480000000);
+	clk_set_parent(clks[ssp0_sel], clks[ref_io0]);
+	clk_set_parent(clks[ssp1_sel], clks[ref_io0]);
+	clk_set_parent(clks[ssp2_sel], clks[ref_io1]);
+	clk_set_parent(clks[ssp3_sel], clks[ref_io1]);
+	clk_set_rate(clks[ssp0_div], 96000000);
+	clk_set_rate(clks[ssp1_div], 96000000);
+	clk_set_rate(clks[ssp2_div], 96000000);
+	clk_set_rate(clks[ssp3_div], 96000000);
+	clk_set_parent(clks[lcdif_sel], clks[ref_pix]);
+	clk_enable(clks[enet_out]);
+
+	clkdev_add_physbase(clks[ssp0], IMX_SSP0_BASE, NULL);
+	clkdev_add_physbase(clks[ssp1], IMX_SSP1_BASE, NULL);
+	clkdev_add_physbase(clks[ssp2], IMX_SSP2_BASE, NULL);
+	clkdev_add_physbase(clks[ssp3], IMX_SSP3_BASE, NULL);
+	clkdev_add_physbase(clks[fec], IMX_FEC0_BASE, NULL);
+	clkdev_add_physbase(clks[xbus], IMX_DBGUART_BASE, NULL);
+	clkdev_add_physbase(clks[hbus], IMX_OCOTP_BASE, NULL);
+	clkdev_add_physbase(clks[uart], IMX_UART0_BASE, NULL);
+	clkdev_add_physbase(clks[uart], IMX_UART1_BASE, NULL);
+	clkdev_add_physbase(clks[uart], IMX_UART2_BASE, NULL);
+	clkdev_add_physbase(clks[uart], IMX_UART3_BASE, NULL);
+	clkdev_add_physbase(clks[uart], IMX_UART4_BASE, NULL);
+	clkdev_add_physbase(clks[gpmi], MXS_GPMI_BASE, NULL);
+	if (IS_ENABLED(CONFIG_DRIVER_VIDEO_STM))
+		clkdev_add_physbase(clks[lcdif_comp], IMX_FB_BASE, NULL);
+
+	return 0;
+}
+
+static int imx28_ccm_probe(struct device_d *dev)
+{
+	void __iomem *regs;
+
+	regs = dev_request_mem_region(dev, 0);
+
+	mx28_clocks_init(regs);
+
+	return 0;
+}
+
+static __maybe_unused struct of_device_id imx28_ccm_dt_ids[] = {
+	{
+		.compatible = "fsl,imx28-clkctrl",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d imx28_ccm_driver = {
+	.probe	= imx28_ccm_probe,
+	.name	= "imx28-clkctrl",
+	.of_compatible = DRV_OF_COMPAT(imx28_ccm_dt_ids),
+};
+
+static int imx28_ccm_init(void)
+{
+	return platform_driver_register(&imx28_ccm_driver);
+}
+postcore_initcall(imx28_ccm_init);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 02:54:21 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 08:54:21 +0200
Subject: [PATCH 17/17] ARM: MXS: remove old clock support
In-Reply-To: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371711261-10039-18-git-send-email-s.hauer@pengutronix.de>

The old MXS clock support is now unused and can be removed.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-mxs/Makefile                   |   5 +-
 arch/arm/mach-mxs/imx.c                      |  16 -
 arch/arm/mach-mxs/imx_lcd_clk.c              | 150 ----------
 arch/arm/mach-mxs/include/mach/clock-imx23.h |  30 --
 arch/arm/mach-mxs/include/mach/clock-imx28.h |  33 --
 arch/arm/mach-mxs/include/mach/clock.h       |   7 -
 arch/arm/mach-mxs/speed-imx23.c              | 315 -------------------
 arch/arm/mach-mxs/speed-imx28.c              | 432 ---------------------------
 8 files changed, 2 insertions(+), 986 deletions(-)
 delete mode 100644 arch/arm/mach-mxs/imx_lcd_clk.c
 delete mode 100644 arch/arm/mach-mxs/include/mach/clock-imx23.h
 delete mode 100644 arch/arm/mach-mxs/include/mach/clock-imx28.h
 delete mode 100644 arch/arm/mach-mxs/speed-imx23.c
 delete mode 100644 arch/arm/mach-mxs/speed-imx28.c

diff --git a/arch/arm/mach-mxs/Makefile b/arch/arm/mach-mxs/Makefile
index fe93096..a183987 100644
--- a/arch/arm/mach-mxs/Makefile
+++ b/arch/arm/mach-mxs/Makefile
@@ -1,6 +1,5 @@
 obj-y += imx.o iomux-imx.o power.o common.o
-obj-$(CONFIG_DRIVER_VIDEO_STM) += imx_lcd_clk.o
-obj-$(CONFIG_ARCH_IMX23) += speed-imx23.o clocksource-imx23.o usb-imx23.o soc-imx23.o
-obj-$(CONFIG_ARCH_IMX28) += speed-imx28.o clocksource-imx28.o usb-imx28.o soc-imx28.o
+obj-$(CONFIG_ARCH_IMX23) += clocksource-imx23.o usb-imx23.o soc-imx23.o
+obj-$(CONFIG_ARCH_IMX28) += clocksource-imx28.o usb-imx28.o soc-imx28.o
 obj-$(CONFIG_MXS_OCOTP) += ocotp.o
 obj-$(CONFIG_MXS_CMD_BCB) += bcb.o
diff --git a/arch/arm/mach-mxs/imx.c b/arch/arm/mach-mxs/imx.c
index 5acce93..9f195e4 100644
--- a/arch/arm/mach-mxs/imx.c
+++ b/arch/arm/mach-mxs/imx.c
@@ -45,22 +45,6 @@ static int imx_reset_usb_bootstrap(void)
 }
 device_initcall(imx_reset_usb_bootstrap);
 
-extern void imx_dump_clocks(void);
-
-static int do_clocks(int argc, char *argv[])
-{
-	imx_dump_clocks();
-
-	return 0;
-}
-
-BAREBOX_CMD_START(dump_clocks)
-	.cmd		= do_clocks,
-	.usage		= "show clock frequencies",
-	BAREBOX_CMD_COMPLETE(empty_complete)
-BAREBOX_CMD_END
-
-
 static int __silicon_revision = SILICON_REVISION_UNKNOWN;
 
 int silicon_revision_get(void)
diff --git a/arch/arm/mach-mxs/imx_lcd_clk.c b/arch/arm/mach-mxs/imx_lcd_clk.c
deleted file mode 100644
index 455dfcb..0000000
--- a/arch/arm/mach-mxs/imx_lcd_clk.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * (C) Copyright 2010 Juergen Beisert - Pengutronix <kernel at pengutronix.de>
- *
- * 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.
- */
-
-#include <common.h>
-#include <init.h>
-#include <mach/imx-regs.h>
-#include <mach/clock.h>
-#include <io.h>
-
-#ifdef CONFIG_ARCH_IMX23
-
-# define HW_CLKCTRL_DIS_LCDIF 0x060
-#  define CLKCTRL_DIS_LCDIF_GATE (1 << 31)
-#  define CLKCTRL_DIS_LCDIF_BUSY (1 << 29)
-#  define MASK_DIS_LCDIF_DIV 0xfff
-#  define SET_DIS_LCDIF_DIV(x) ((x) & MASK_DIS_LCDIF_DIV)
-#  define GET_DIS_LCDIF_DIV(x) ((x) & MASK_DIS_LCDIF_DIV)
-
-# define HW_CLKCTRL_FRAC 0xf0
-#  define MASK_PIXFRAC 0x3f
-#  define GET_PIXFRAC(x) (((x) >> 16) & MASK_PIXFRAC)
-#  define SET_PIXFRAC(x) (((x) & MASK_PIXFRAC) << 16)
-#  define CLKCTRL_FRAC_CLKGATEPIX (1 << 23)
-
-# define HW_CLKCTRL_CLKSEQ 0x110
-#  define CLKCTRL_CLKSEQ_BYPASS_DIS_LCDIF (1 << 1)
-
-#endif
-
-#ifdef CONFIG_ARCH_IMX28
-
-# define HW_CLKCTRL_DIS_LCDIF 0x120
-#  define CLKCTRL_DIS_LCDIF_GATE (1 << 31)
-#  define CLKCTRL_DIS_LCDIF_BUSY (1 << 29)
-#  define MASK_DIS_LCDIF_DIV 0x1fff
-#  define SET_DIS_LCDIF_DIV(x) ((x) & MASK_DIS_LCDIF_DIV)
-#  define GET_DIS_LCDIF_DIV(x) ((x) & MASK_DIS_LCDIF_DIV)
-
-/* note: On i.MX28 this is called 'FRAC1' */
-# define HW_CLKCTRL_FRAC 0x1c0
-#  define MASK_PIXFRAC 0x3f
-#  define GET_PIXFRAC(x) ((x) & MASK_PIXFRAC)
-#  define SET_PIXFRAC(x) ((x) & MASK_PIXFRAC)
-#  define CLKCTRL_FRAC_CLKGATEPIX (1 << 7)
-
-# define HW_CLKCTRL_CLKSEQ 0x1d0
-#  define CLKCTRL_CLKSEQ_BYPASS_DIS_LCDIF (1 << 14)
-
-#endif
-
-unsigned imx_get_lcdifclk(void)
-{
-	unsigned rate = (imx_get_mpllclk() / 1000) * 18U;
-	unsigned div;
-
-	div = GET_PIXFRAC(readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC));
-	if (div != 0U) {
-		rate /= div;
-		div = GET_DIS_LCDIF_DIV(readl(IMX_CCM_BASE +
-							HW_CLKCTRL_DIS_LCDIF));
-		if (div != 0U)
-			rate /= div;
-		else
-			pr_debug("LCDIF clock has divisor 0!\n");
-	} else
-		pr_debug("LCDIF clock has frac divisor 0!\n");
-
-	return rate * 1000;
-}
-
-/*
- * The source of the pixel clock can be the external 24 MHz crystal or the
- * internal PLL running at 480 MHz. In order to support at least VGA sized
- * displays/resolutions this routine forces the PLL as the clock source.
- */
-unsigned imx_set_lcdifclk(unsigned nc)
-{
-	unsigned frac, best_frac = 0, div, best_div = 0, result;
-	int delta, best_delta = 0xffffff;
-	unsigned i, parent_rate = imx_get_mpllclk() / 1000;
-	uint32_t reg;
-
-#define SH_DIV(NOM, DEN, LSH) ((((NOM) / (DEN)) << (LSH)) + \
-			DIV_ROUND_CLOSEST(((NOM) % (DEN)) << (LSH), DEN))
-#define SHIFT 4
-
-	nc /= 1000;
-	nc <<= SHIFT;
-
-	for (frac = 18; frac <= 35; ++frac) {
-		for (div = 1; div <= 255; ++div) {
-			result = DIV_ROUND_CLOSEST(parent_rate *
-						SH_DIV(18U, frac, SHIFT), div);
-			delta = nc - result;
-			if (abs(delta) < abs(best_delta)) {
-				best_delta = delta;
-				best_frac = frac;
-				best_div = div;
-			}
-		}
-	}
-
-	if (best_delta == 0xffffff) {
-		pr_debug("Unable to match the pixelclock\n");
-		return 0;
-	}
-
-	pr_debug("Programming PFD=%u,DIV=%u ref_pix=%u MHz PIXCLK=%u kHz\n",
-			best_frac, best_div, 480 * 18 / best_frac,
-			480000 * 18 / best_frac / best_div);
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC);
-	reg &= ~SET_PIXFRAC(MASK_PIXFRAC);
-	reg |= SET_PIXFRAC(best_frac);
-	writel(reg, IMX_CCM_BASE + HW_CLKCTRL_FRAC);
-	writel(reg & ~CLKCTRL_FRAC_CLKGATEPIX, IMX_CCM_BASE + HW_CLKCTRL_FRAC);
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_DIS_LCDIF) & ~MASK_DIS_LCDIF_DIV;
-	reg &= ~CLKCTRL_DIS_LCDIF_GATE;
-	reg |= SET_DIS_LCDIF_DIV(best_div);
-	writel(reg, IMX_CCM_BASE + HW_CLKCTRL_DIS_LCDIF);
-
-	/* Wait for divider update */
-	for (i = 0; i < 10000; i++) {
-		if (!(readl(IMX_CCM_BASE + HW_CLKCTRL_DIS_LCDIF) &
-						CLKCTRL_DIS_LCDIF_BUSY))
-			break;
-	}
-
-	if (i >= 10000) {
-		pr_debug("Setting LCD clock failed\n");
-		return 0;
-	}
-
-	writel(CLKCTRL_CLKSEQ_BYPASS_DIS_LCDIF,
-		IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ + BIT_CLR);
-
-	return imx_get_lcdifclk();
-}
diff --git a/arch/arm/mach-mxs/include/mach/clock-imx23.h b/arch/arm/mach-mxs/include/mach/clock-imx23.h
deleted file mode 100644
index 6507792..0000000
--- a/arch/arm/mach-mxs/include/mach/clock-imx23.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef MACH_CLOCK_IMX23_H
-# define MACH_CLOCK_IMX23_H
-
-unsigned imx_get_mpllclk(void);
-unsigned imx_get_emiclk(void);
-unsigned imx_get_ioclk(void);
-unsigned imx_get_armclk(void);
-unsigned imx_get_hclk(void);
-unsigned imx_set_hclk(unsigned);
-unsigned imx_get_xclk(void);
-unsigned imx_get_sspclk(unsigned);
-unsigned imx_set_sspclk(unsigned, unsigned, int);
-unsigned imx_set_ioclk(unsigned);
-unsigned imx_set_lcdifclk(unsigned);
-unsigned imx_get_lcdifclk(void);
-void imx_enable_nandclk(void);
-
-#endif /* MACH_CLOCK_IMX23_H */
diff --git a/arch/arm/mach-mxs/include/mach/clock-imx28.h b/arch/arm/mach-mxs/include/mach/clock-imx28.h
deleted file mode 100644
index 0604f0a..0000000
--- a/arch/arm/mach-mxs/include/mach/clock-imx28.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef MACH_CLOCK_IMX28_H
-#define MACH_CLOCK_IMX28_H
-
-unsigned imx_get_mpllclk(void);
-unsigned imx_get_emiclk(void);
-unsigned imx_get_ioclk(unsigned);
-unsigned imx_get_armclk(void);
-unsigned imx_get_hclk(void);
-unsigned imx_set_hclk(unsigned);
-unsigned imx_get_xclk(void);
-unsigned imx_get_sspclk(unsigned);
-unsigned imx_set_sspclk(unsigned, unsigned, int);
-unsigned imx_set_ioclk(unsigned, unsigned);
-unsigned imx_set_lcdifclk(unsigned);
-unsigned imx_get_lcdifclk(void);
-unsigned imx_get_fecclk(void);
-void imx_enable_enetclk(void);
-void imx_enable_nandclk(void);
-
-#endif /* MACH_CLOCK_IMX28_H */
-
diff --git a/arch/arm/mach-mxs/include/mach/clock.h b/arch/arm/mach-mxs/include/mach/clock.h
index 367297b..adbc330 100644
--- a/arch/arm/mach-mxs/include/mach/clock.h
+++ b/arch/arm/mach-mxs/include/mach/clock.h
@@ -16,11 +16,4 @@
 #ifndef __MACH_CLOCK_H
 # define __MACH_CLOCK_H
 
-#if defined CONFIG_ARCH_IMX23
-# include <mach/clock-imx23.h>
-#endif
-#if defined CONFIG_ARCH_IMX28
-# include <mach/clock-imx28.h>
-#endif
-
 #endif /* __MACH_CLOCK_H */
diff --git a/arch/arm/mach-mxs/speed-imx23.c b/arch/arm/mach-mxs/speed-imx23.c
deleted file mode 100644
index 14885d5..0000000
--- a/arch/arm/mach-mxs/speed-imx23.c
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * (C) Copyright 2010 Juergen Beisert - Pengutronix
- *
- * This code is based partially on code of:
- *
- * (c) 2008 Embedded Alley Solutions, Inc.
- * (C) Copyright 2009-2010 Freescale Semiconductor, Inc.
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <init.h>
-#include <io.h>
-#include <mach/imx-regs.h>
-#include <mach/generic.h>
-#include <mach/clock.h>
-
-#define HW_CLKCTRL_PLLCTRL0 0x000
-#define HW_CLKCTRL_PLLCTRL1 0x010
-#define HW_CLKCTRL_CPU 0x20
-# define GET_CPU_XTAL_DIV(x) (((x) >> 16) & 0x3ff)
-# define GET_CPU_PLL_DIV(x) ((x) & 0x3f)
-#define HW_CLKCTRL_HBUS 0x30
-#define HW_CLKCTRL_XBUS 0x40
-#define HW_CLKCTRL_XTAL 0x050
-#define HW_CLKCTRL_PIX 0x060
-/* note: no set/clear register! */
-#define HW_CLKCTRL_SSP 0x070
-/* note: no set/clear register! */
-# define CLKCTRL_SSP_CLKGATE (1 << 31)
-# define CLKCTRL_SSP_BUSY (1 << 29)
-# define CLKCTRL_SSP_DIV_MASK 0x1ff
-# define GET_SSP_DIV(x) ((x) & CLKCTRL_SSP_DIV_MASK)
-# define SET_SSP_DIV(x) ((x) & CLKCTRL_SSP_DIV_MASK)
-#define HW_CLKCTRL_GPMI 0x080
-# define CLKCTRL_GPMI_CLKGATE (1 << 31)
-# define CLKCTRL_GPMI_DIV_MASK 0x3ff
-/* note: no set/clear register! */
-#define HW_CLKCTRL_SPDIF 0x090
-/* note: no set/clear register! */
-#define HW_CLKCTRL_EMI	0xa0
-/* note: no set/clear register! */
-# define CLKCTRL_EMI_CLKGATE (1 << 31)
-# define GET_EMI_XTAL_DIV(x) (((x) >> 8) & 0xf)
-# define GET_EMI_PLL_DIV(x) ((x) & 0x3f)
-#define HW_CLKCTRL_SAIF 0x0c0
-#define HW_CLKCTRL_TV 0x0d0
-#define HW_CLKCTRL_ETM 0x0e0
-#define HW_CLKCTRL_FRAC 0xf0
-# define CLKCTRL_FRAC_CLKGATEIO (1 << 31)
-# define GET_IOFRAC(x) (((x) >> 24) & 0x3f)
-# define SET_IOFRAC(x) (((x) & 0x3f) << 24)
-# define CLKCTRL_FRAC_CLKGATEPIX (1 << 23)
-# define GET_PIXFRAC(x) (((x) >> 16) & 0x3f)
-# define CLKCTRL_FRAC_CLKGATEEMI (1 << 15)
-# define GET_EMIFRAC(x) (((x) >> 8) & 0x3f)
-# define CLKCTRL_FRAC_CLKGATECPU (1 << 7)
-# define GET_CPUFRAC(x) ((x) & 0x3f)
-#define HW_CLKCTRL_FRAC1 0x100
-#define HW_CLKCTRL_CLKSEQ 0x110
-# define CLKCTRL_CLKSEQ_BYPASS_ETM (1 << 8)
-# define CLKCTRL_CLKSEQ_BYPASS_CPU (1 << 7)
-# define CLKCTRL_CLKSEQ_BYPASS_EMI (1 << 6)
-# define CLKCTRL_CLKSEQ_BYPASS_SSP (1 << 5)
-# define CLKCTRL_CLKSEQ_BYPASS_GPMI (1 << 4)
-#define HW_CLKCTRL_RESET 0x120
-#define HW_CLKCTRL_STATUS 0x130
-#define HW_CLKCTRL_VERSION 0x140
-
-unsigned imx_get_mpllclk(void)
-{
-	/* the main PLL runs at 480 MHz */
-	return 480000000;
-}
-
-unsigned imx_get_xtalclk(void)
-{
-	/* the external reference runs at 24 MHz */
-	return 24000000;
-}
-
-/* used for the SDRAM controller */
-unsigned imx_get_emiclk(void)
-{
-	uint32_t reg;
-	unsigned rate;
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_EMI) & CLKCTRL_EMI_CLKGATE)
-		return 0U;	/* clock is off */
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ) & CLKCTRL_CLKSEQ_BYPASS_EMI)
-		return imx_get_xtalclk() / GET_EMI_XTAL_DIV(readl(IMX_CCM_BASE + HW_CLKCTRL_EMI));
-
-	rate = imx_get_mpllclk() / 1000;
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC);
-	if (!(reg & CLKCTRL_FRAC_CLKGATEEMI)) {
-		rate *= 18U;
-		rate /= GET_EMIFRAC(reg);
-	}
-
-	return (rate / GET_EMI_PLL_DIV(readl(IMX_CCM_BASE + HW_CLKCTRL_EMI)))
-			* 1000;
-}
-
-/*
- * Source of ssp, gpmi, ir
- */
-unsigned imx_get_ioclk(void)
-{
-	uint32_t reg;
-	unsigned rate = imx_get_mpllclk() / 1000;
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC);
-	if (reg & CLKCTRL_FRAC_CLKGATEIO)
-		return 0U;	/* clock is off */
-
-	rate *= 18U;
-	rate /= GET_IOFRAC(reg);
-	return rate * 1000;
-}
-
-/**
- * Setup a new frequency to the IOCLK domain.
- * @param nc New frequency in [Hz]
- *
- * The FRAC divider for the IOCLK must be between 18 (* 18/18) and 35 (* 18/35)
- */
-unsigned imx_set_ioclk(unsigned nc)
-{
-	uint32_t reg;
-	unsigned div;
-
-	nc /= 1000;
-	div = (imx_get_mpllclk() / 1000) * 18;
-	div = DIV_ROUND_CLOSEST(div, nc);
-	if (div > 0x3f)
-		div = 0x3f;
-	/* mask the current settings */
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC) & ~(SET_IOFRAC(0x3f));
-	writel(reg | SET_IOFRAC(div), IMX_CCM_BASE + HW_CLKCTRL_FRAC);
-	/* enable the IO clock at its new frequency */
-	writel(CLKCTRL_FRAC_CLKGATEIO, IMX_CCM_BASE + HW_CLKCTRL_FRAC + 8);
-
-	return imx_get_ioclk();
-}
-
-/* this is CPU core clock */
-unsigned imx_get_armclk(void)
-{
-	uint32_t reg;
-	unsigned rate;
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ) & CLKCTRL_CLKSEQ_BYPASS_CPU)
-		return imx_get_xtalclk() / GET_CPU_XTAL_DIV(readl(IMX_CCM_BASE + HW_CLKCTRL_CPU));
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC);
-	if (reg & CLKCTRL_FRAC_CLKGATECPU)
-		return 0U;	/* should not possible, shouldn't it? */
-
-	rate = imx_get_mpllclk() / 1000;
-	rate *= 18U;
-	rate /= GET_CPUFRAC(reg);
-
-	return (rate / GET_CPU_PLL_DIV(readl(IMX_CCM_BASE + HW_CLKCTRL_CPU)))
-			* 1000;
-}
-
-/* this is the AHB and APBH bus clock */
-unsigned imx_get_hclk(void)
-{
-	unsigned rate = imx_get_armclk() / 1000;
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & 0x20) {
-		rate *= readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & 0x1f;
-		rate = DIV_ROUND_UP(rate, 32);
-	} else
-		rate = DIV_ROUND_UP(rate,
-			readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & 0x1f);
-	return rate * 1000;
-}
-
-unsigned imx_set_hclk(unsigned nc)
-{
-	unsigned root_rate = imx_get_armclk();
-	unsigned reg, div;
-
-	div = DIV_ROUND_UP(root_rate, nc);
-	if ((div == 0) || (div >= 32))
-		return 0;
-
-	if ((root_rate < nc) && (root_rate == 64000000))
-		div = 3;
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & ~0x3f;
-	writel(reg | div, IMX_CCM_BASE + HW_CLKCTRL_HBUS);
-
-	while (readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & (1 << 31))
-		;
-
-	return imx_get_hclk();
-}
-
-/*
- * Source of UART, debug UART, audio, PWM, dri, timer, digctl
- */
-unsigned imx_get_xclk(void)
-{
-	unsigned rate = imx_get_xtalclk();	/* runs from the 24 MHz crystal reference */
-
-	return rate / (readl(IMX_CCM_BASE + HW_CLKCTRL_XBUS) & 0x3ff);
-}
-
-/* 'index' gets ignored on i.MX23 */
-unsigned imx_get_sspclk(unsigned index)
-{
-	unsigned rate;
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_SSP) & CLKCTRL_SSP_CLKGATE)
-		return 0U;	/* clock is off */
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ) & CLKCTRL_CLKSEQ_BYPASS_SSP)
-		rate = imx_get_xtalclk();
-	else
-		rate = imx_get_ioclk();
-
-	return rate / GET_SSP_DIV(readl(IMX_CCM_BASE + HW_CLKCTRL_SSP));
-}
-
-/**
- * @param index Unit index (ignored on i.MX23)
- * @param nc New frequency in [Hz]
- * @param high != 0 if ioclk should be the source
- * @return The new possible frequency in [kHz]
- */
-unsigned imx_set_sspclk(unsigned index, unsigned nc, int high)
-{
-	uint32_t reg;
-	unsigned ssp_div;
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_SSP) & ~CLKCTRL_SSP_CLKGATE;
-	/* Datasheet says: Do not change the DIV setting if the clock is off */
-	writel(reg, IMX_CCM_BASE + HW_CLKCTRL_SSP);
-	/* Wait while clock is gated */
-	while (readl(IMX_CCM_BASE + HW_CLKCTRL_SSP) & CLKCTRL_SSP_CLKGATE)
-		;
-
-	if (high)
-		ssp_div = imx_get_ioclk();
-	else
-		ssp_div = imx_get_xtalclk();
-
-	if (nc > ssp_div) {
-		printf("Cannot setup SSP unit clock to %u Hz, base clock is only %u Hz\n", nc, ssp_div);
-		ssp_div = 1U;
-	} else {
-		ssp_div = DIV_ROUND_UP(ssp_div, nc);
-		if (ssp_div > CLKCTRL_SSP_DIV_MASK)
-			ssp_div = CLKCTRL_SSP_DIV_MASK;
-	}
-
-	/* Set new divider value */
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_SSP) & ~CLKCTRL_SSP_DIV_MASK;
-	writel(reg | SET_SSP_DIV(ssp_div), IMX_CCM_BASE + HW_CLKCTRL_SSP);
-
-	/* Wait until new divider value is set */
-	while (readl(IMX_CCM_BASE + HW_CLKCTRL_SSP) & CLKCTRL_SSP_BUSY)
-		;
-
-	if (high)
-		/* switch to ioclock */
-		writel(CLKCTRL_CLKSEQ_BYPASS_SSP, IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ + 8);
-	else
-		/* switch to 24 MHz crystal */
-		writel(CLKCTRL_CLKSEQ_BYPASS_SSP, IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ + 4);
-
-	return imx_get_sspclk(index);
-}
-
-void imx_enable_nandclk(void)
-{
-	uint32_t reg;
-
-	/* Clear bypass bit; refman says clear, but fsl-code does set. Hooray! */
-	writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
-		IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ + BIT_SET);
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_GPMI) & ~CLKCTRL_GPMI_CLKGATE;
-	writel(reg, IMX_CCM_BASE + HW_CLKCTRL_GPMI);
-	udelay(1000);
-	/* Initialize DIV to 1 */
-	reg &= ~CLKCTRL_GPMI_DIV_MASK;
-	reg |= 1;
-	writel(reg, IMX_CCM_BASE + HW_CLKCTRL_GPMI);
-}
-
-void imx_dump_clocks(void)
-{
-	printf("mpll:    %10u kHz\n", imx_get_mpllclk() / 1000);
-	printf("arm:     %10u kHz\n", imx_get_armclk() / 1000);
-	printf("ioclk:   %10u kHz\n", imx_get_ioclk() / 1000);
-	printf("emiclk:  %10u kHz\n", imx_get_emiclk() / 1000);
-	printf("hclk:    %10u kHz\n", imx_get_hclk() / 1000);
-	printf("xclk:    %10u kHz\n", imx_get_xclk() / 1000);
-	printf("ssp:     %10u kHz\n", imx_get_sspclk(0) / 1000);
-}
diff --git a/arch/arm/mach-mxs/speed-imx28.c b/arch/arm/mach-mxs/speed-imx28.c
deleted file mode 100644
index 2cab42d..0000000
--- a/arch/arm/mach-mxs/speed-imx28.c
+++ /dev/null
@@ -1,432 +0,0 @@
-/*
- * (C) Copyright 2010 Juergen Beisert - Pengutronix <kernel at pengutronix.de>
- *
- * This code is based partially on code that has:
- *
- * (c) 2008 Embedded Alley Solutions, Inc.
- * (C) Copyright 2009-2010 Freescale Semiconductor, Inc.
- *
- * 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.
- */
-#include <common.h>
-#include <init.h>
-#include <io.h>
-#include <mach/imx-regs.h>
-#include <mach/generic.h>
-#include <mach/clock.h>
-
-#define HW_CLKCTRL_PLL0CTRL0 0x000
-#define HW_CLKCTRL_PLL0CTRL1 0x010
-#define HW_CLKCTRL_PLL1CTRL0 0x020
-#define HW_CLKCTRL_PLL1CTRL1 0x030
-#define HW_CLKCTRL_PLL2CTRL0 0x040
-# define CLKCTRL_PLL2CTRL0_CLKGATE (1 << 31)
-# define CLKCTRL_PLL2CTRL0_POWER (1 << 23)
-#define HW_CLKCTRL_CPU 0x50
-# define GET_CPU_XTAL_DIV(x) (((x) >> 16) & 0x3ff)
-# define GET_CPU_PLL_DIV(x) ((x) & 0x3f)
-#define HW_CLKCTRL_HBUS 0x60
-#define HW_CLKCTRL_XBUS 0x70
-#define HW_CLKCTRL_XTAL 0x080
-#define HW_CLKCTRL_SSP0 0x090
-#define HW_CLKCTRL_SSP1 0x0a0
-#define HW_CLKCTRL_SSP2 0x0b0
-#define HW_CLKCTRL_SSP3 0x0c0
-/* note: no set/clear register! */
-# define CLKCTRL_SSP_CLKGATE (1 << 31)
-# define CLKCTRL_SSP_BUSY (1 << 29)
-# define CLKCTRL_SSP_DIV_FRAC_EN (1 << 9)
-# define CLKCTRL_SSP_DIV_MASK 0x1ff
-# define GET_SSP_DIV(x) ((x) & CLKCTRL_SSP_DIV_MASK)
-# define SET_SSP_DIV(x) ((x) & CLKCTRL_SSP_DIV_MASK)
-#define HW_CLKCTRL_GPMI 0x0d0
-# define CLKCTRL_GPMI_CLKGATE (1 << 31)
-# define CLKCTRL_GPMI_DIV_MASK 0x3ff
-/* note: no set/clear register! */
-#define HW_CLKCTRL_SPDIF 0x0e0
-/* note: no set/clear register! */
-#define HW_CLKCTRL_EMI	0xf0
-/* note: no set/clear register! */
-# define CLKCTRL_EMI_CLKGATE (1 << 31)
-# define GET_EMI_XTAL_DIV(x) (((x) >> 8) & 0xf)
-# define GET_EMI_PLL_DIV(x) ((x) & 0x3f)
-#define HW_CLKCTRL_SAIF0 0x100
-#define HW_CLKCTRL_SAIF1 0x110
-#define HW_CLKCTRL_DIS_LCDIF 0x120
-# define CLKCTRL_DIS_LCDIF_GATE (1 << 31)
-# define CLKCTRL_DIS_LCDIF_BUSY (1 << 29)
-# define SET_DIS_LCDIF_DIV(x) ((x) & 0x1fff)
-# define GET_DIS_LCDIF_DIV(x) ((x) & 0x1fff)
-#define HW_CLKCTRL_ETM 0x130
-#define HW_CLKCTRL_ENET 0x140
-# define SET_CLKCTRL_ENET_DIV(x) (((x) & 0x3f) << 21)
-# define SET_CLKCTRL_ENET_SEL(x) (((x) & 0x3) << 19)
-# define CLKCTRL_ENET_CLK_OUT_EN (1 << 18)
-#define HW_CLKCTRL_HSADC 0x150
-#define HW_CLKCTRL_FLEXCAN 0x160
-#define HW_CLKCTRL_FRAC0 0x1b0
-# define CLKCTRL_FRAC_CLKGATEIO0 (1 << 31)
-# define GET_IO0FRAC(x) (((x) >> 24) & 0x3f)
-# define SET_IO0FRAC(x) (((x) & 0x3f) << 24)
-# define CLKCTRL_FRAC_CLKGATEIO1 (1 << 23)
-# define GET_IO1FRAC(x) (((x) >> 16) & 0x3f)
-# define SET_IO1FRAC(x) (((x) & 0x3f) << 16)
-# define CLKCTRL_FRAC_CLKGATEEMI (1 << 15)
-# define GET_EMIFRAC(x) (((x) >> 8) & 0x3f)
-# define CLKCTRL_FRAC_CLKGATECPU (1 << 7)
-# define GET_CPUFRAC(x) ((x) & 0x3f)
-#define HW_CLKCTRL_FRAC1 0x1c0
-# define CLKCTRL_FRAC_CLKGATEGPMI (1 << 23)
-# define GET_GPMIFRAC(x) (((x) >> 16) & 0x3f)
-# define CLKCTRL_FRAC_CLKGATEHSADC (1 << 15)
-# define GET_HSADCFRAC(x) (((x) >> 8) & 0x3f)
-# define CLKCTRL_FRAC_CLKGATEPIX (1 << 7)
-# define GET_PIXFRAC(x) ((x) & 0x3f)
-# define SET_PIXFRAC(x) ((x) & 0x3f)
-#define HW_CLKCTRL_CLKSEQ 0x1d0
-# define CLKCTRL_CLKSEQ_BYPASS_CPU (1 << 18)
-# define CLKCTRL_CLKSEQ_BYPASS_DIS_LCDIF (1 << 14)
-# define CLKCTRL_CLKSEQ_BYPASS_ETM (1 << 8)
-# define CLKCTRL_CLKSEQ_BYPASS_EMI (1 << 7)
-# define CLKCTRL_CLKSEQ_BYPASS_SSP3 (1 << 6)
-# define CLKCTRL_CLKSEQ_BYPASS_SSP2 (1 << 5)
-# define CLKCTRL_CLKSEQ_BYPASS_SSP1 (1 << 4)
-# define CLKCTRL_CLKSEQ_BYPASS_SSP0 (1 << 3)
-# define CLKCTRL_CLKSEQ_BYPASS_GPMI (1 << 2)
-# define CLKCTRL_CLKSEQ_BYPASS_SAIF1 (1 << 1)
-# define CLKCTRL_CLKSEQ_BYPASS_SAIF0 (1 << 0)
-#define HW_CLKCTRL_RESET 0x1e0
-#define HW_CLKCTRL_STATUS 0x1f0
-#define HW_CLKCTRL_VERSION 0x200
-
-unsigned imx_get_mpllclk(void)
-{
-	/* the main PLL runs at 480 MHz */
-	return 480000000;
-}
-
-unsigned imx_get_xtalclk(void)
-{
-	/* the external reference runs at 24 MHz */
-	return 24000000;
-}
-
-unsigned imx_get_fecclk(void)
-{
-	return imx_get_hclk();
-}
-
-
-/* used for the SDRAM controller */
-unsigned imx_get_emiclk(void)
-{
-	uint32_t reg;
-	unsigned rate;
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_EMI) & CLKCTRL_EMI_CLKGATE)
-		return 0;	/* clock is off */
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ) & CLKCTRL_CLKSEQ_BYPASS_EMI)
-		return imx_get_xtalclk() /
-			GET_EMI_XTAL_DIV(readl(IMX_CCM_BASE + HW_CLKCTRL_EMI));
-
-	rate = imx_get_mpllclk() / 1000;
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC0);
-	if (!(reg & CLKCTRL_FRAC_CLKGATEEMI)) {
-		rate *= 18;
-		rate /= GET_EMIFRAC(reg);
-	}
-
-	return (rate / GET_EMI_PLL_DIV(readl(IMX_CCM_BASE + HW_CLKCTRL_EMI)))
-				* 1000;
-}
-
-/*
- * Source of ssp, gpmi, ir
- * @param index 0 or 1 for ioclk0 or ioclock1
- */
-unsigned imx_get_ioclk(unsigned index)
-{
-	uint32_t reg;
-	unsigned rate = imx_get_mpllclk() / 1000;
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC0);
-	switch (index) {
-	case 0:
-		if (reg & CLKCTRL_FRAC_CLKGATEIO0)
-			return 0;	/* clock is off */
-
-		rate *= 18;
-		rate /= GET_IO0FRAC(reg);
-		break;
-	case 1:
-		if (reg & CLKCTRL_FRAC_CLKGATEIO1)
-			return 0;	/* clock is off */
-
-		rate *= 18;
-		rate /= GET_IO1FRAC(reg);
-		break;
-	}
-
-	return rate * 1000;
-}
-
-/**
- * Setup a new frequency to the IOCLK domain.
- * @param index 0 or 1 for ioclk0 or ioclock1
- * @param nc New frequency in [Hz]
- *
- * The FRAC divider for the IOCLK must be between 18 (* 18/18) and 35 (* 18/35)
- *
- * ioclock0 is the shared clock source of SSP0/SSP1, ioclock1 the shared clock
- * source of SSP2/SSP3
- */
-unsigned imx_set_ioclk(unsigned index, unsigned nc)
-{
-	uint32_t reg;
-	unsigned div;
-
-	nc /= 1000;
-	div = (imx_get_mpllclk() / 1000) * 18;
-	div = DIV_ROUND_CLOSEST(div, nc);
-	if (div > 0x3f)
-		div = 0x3f;
-
-	switch (index) {
-	case 0:
-		reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC0) &
-				~(SET_IO0FRAC(0x3f));
-		/* mask the current settings */
-		writel(reg | SET_IO0FRAC(div), IMX_CCM_BASE + HW_CLKCTRL_FRAC0);
-		/* enable the IO clock at its new frequency */
-		writel(CLKCTRL_FRAC_CLKGATEIO0,
-				IMX_CCM_BASE + HW_CLKCTRL_FRAC0 + BIT_CLR);
-		break;
-	case 1:
-		reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC0) &
-				~(SET_IO1FRAC(0x3f));
-		/* mask the current settings */
-		writel(reg | SET_IO1FRAC(div), IMX_CCM_BASE + HW_CLKCTRL_FRAC0);
-		/* enable the IO clock at its new frequency */
-		writel(CLKCTRL_FRAC_CLKGATEIO1,
-				IMX_CCM_BASE + HW_CLKCTRL_FRAC0 + BIT_CLR);
-		break;
-	}
-
-	return imx_get_ioclk(index);
-}
-
-/* this is CPU core clock */
-unsigned imx_get_armclk(void)
-{
-	uint32_t reg;
-	unsigned rate;
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ) & CLKCTRL_CLKSEQ_BYPASS_CPU)
-		return imx_get_xtalclk() /
-			GET_CPU_XTAL_DIV(readl(IMX_CCM_BASE + HW_CLKCTRL_CPU));
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_FRAC0);
-	if (reg & CLKCTRL_FRAC_CLKGATECPU)
-		return 0;	/* should not possible, shouldn't it? */
-
-	rate = (imx_get_mpllclk() / 1000) * 18;
-	rate /= GET_CPUFRAC(reg);
-
-	return (rate / GET_CPU_PLL_DIV(readl(IMX_CCM_BASE + HW_CLKCTRL_CPU)))
-			* 1000;
-}
-
-/* this is the AHB and APBH bus clock */
-unsigned imx_get_hclk(void)
-{
-	unsigned rate = imx_get_armclk() / 1000;
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & 0x20) {
-		rate *= readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & 0x1f;
-		rate = DIV_ROUND_UP(rate, 32);
-	} else
-		rate = DIV_ROUND_UP(rate,
-			readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & 0x1f);
-	return rate * 1000;
-}
-
-unsigned imx_set_hclk(unsigned nc)
-{
-	unsigned root_rate = imx_get_armclk();
-	unsigned reg, div;
-
-	div = DIV_ROUND_UP(root_rate, nc);
-	if ((div == 0) || (div >= 32))
-		return 0;
-
-	if ((root_rate < nc) && (root_rate == 64000000))
-		div = 3;
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & ~0x3f;
-	writel(reg | div, IMX_CCM_BASE + HW_CLKCTRL_HBUS);
-
-	while (readl(IMX_CCM_BASE + HW_CLKCTRL_HBUS) & (1 << 31))
-		;
-
-	return imx_get_hclk();
-}
-
-/*
- * Source of UART, debug UART, audio, PWM, dri, timer, digctl
- */
-unsigned imx_get_xclk(void)
-{
-	/* runs from the 24 MHz crystal reference */
-	unsigned rate = imx_get_xtalclk();
-
-	return rate / (readl(IMX_CCM_BASE + HW_CLKCTRL_XBUS) & 0x3ff);
-}
-
-/**
- * @param index The SSP unit (0...3)
- */
-unsigned imx_get_sspclk(unsigned index)
-{
-	unsigned rate, offset, shift, ioclk_index;
-
-	if (index > 3) {
-		pr_debug("Unknown SSP unit: %u\n", index);
-		return 0;
-	}
-
-	ioclk_index = index >> 1;
-
-	offset = HW_CLKCTRL_SSP0 + (0x10 * index);
-	shift = CLKCTRL_CLKSEQ_BYPASS_SSP0 << index;
-
-	if (readl(IMX_CCM_BASE + offset) & CLKCTRL_SSP_CLKGATE)
-		return 0;	/* clock is off */
-
-	if (readl(IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ) & shift)
-		rate = imx_get_xtalclk();
-	else
-		rate = imx_get_ioclk(ioclk_index);
-
-	return rate / GET_SSP_DIV(readl(IMX_CCM_BASE + offset));
-}
-
-/**
- * @param index The SSP unit (0...3)
- * @param nc New frequency in [Hz]
- * @param high != 0 if ioclk should be the source
- * @return The new possible frequency
- */
-unsigned imx_set_sspclk(unsigned index, unsigned nc, int high)
-{
-	uint32_t reg;
-	unsigned ssp_div, offset, shift, ioclk_index;
-
-	if (index > 3) {
-		pr_debug("Unknown SSP unit: %u\n", index);
-		return 0;
-	}
-
-	ioclk_index = index >> 1;
-
-	offset = HW_CLKCTRL_SSP0 + (0x10 * index);
-	shift = CLKCTRL_CLKSEQ_BYPASS_SSP0 << index;
-
-	reg = readl(IMX_CCM_BASE + offset) & ~CLKCTRL_SSP_CLKGATE;
-	/* Datasheet says: Do not change the DIV setting if the clock is off */
-	writel(reg, IMX_CCM_BASE + offset);
-	/* Wait while clock is gated */
-	while (readl(IMX_CCM_BASE + offset) & CLKCTRL_SSP_CLKGATE)
-		;
-
-	if (high)
-		ssp_div = imx_get_ioclk(ioclk_index);
-	else
-		ssp_div = imx_get_xtalclk();
-
-	if (nc > ssp_div) {
-		printf("Cannot setup SSP unit clock to %u kHz, base clock is "
-						"only %u kHz\n", nc, ssp_div);
-		ssp_div = 1;
-	} else {
-		ssp_div = DIV_ROUND_UP(ssp_div, nc);
-		if (ssp_div > CLKCTRL_SSP_DIV_MASK)
-			ssp_div = CLKCTRL_SSP_DIV_MASK;
-	}
-
-	/* Set new divider value */
-	reg = readl(IMX_CCM_BASE + offset) & ~CLKCTRL_SSP_DIV_MASK;
-	writel(reg | SET_SSP_DIV(ssp_div), IMX_CCM_BASE + offset);
-
-	/* Wait until new divider value is set */
-	while (readl(IMX_CCM_BASE + offset) & CLKCTRL_SSP_BUSY)
-		;
-
-	if (high)
-		/* switch to ioclock */
-		writel(shift, IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ + BIT_CLR);
-	else
-		/* switch to 24 MHz crystal */
-		writel(shift, IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ + BIT_SET);
-
-	return imx_get_sspclk(index);
-}
-
-void imx_enable_enetclk(void)
-{
-	uint32_t reg;
-
-	/* wake up main enet PLL */
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_PLL2CTRL0);
-	if (!(reg & CLKCTRL_PLL2CTRL0_POWER)) {
-		reg |= CLKCTRL_PLL2CTRL0_POWER;
-		writel(reg, IMX_CCM_BASE + HW_CLKCTRL_PLL2CTRL0);
-		udelay(50);	/* wait until this PLL locks */
-	}
-	reg &= ~CLKCTRL_PLL2CTRL0_CLKGATE;
-	writel(reg, IMX_CCM_BASE + HW_CLKCTRL_PLL2CTRL0);
-
-	writel(SET_CLKCTRL_ENET_DIV(1) | SET_CLKCTRL_ENET_SEL(0) |
-		CLKCTRL_ENET_CLK_OUT_EN, /* FIXME may be platform specific */
-		IMX_CCM_BASE + HW_CLKCTRL_ENET);
-}
-
-void imx_enable_nandclk(void)
-{
-	uint32_t reg;
-
-	/* Clear bypass bit; refman says clear, but fsl-code does set. Hooray! */
-	writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
-		IMX_CCM_BASE + HW_CLKCTRL_CLKSEQ + BIT_SET);
-
-	reg = readl(IMX_CCM_BASE + HW_CLKCTRL_GPMI) & ~CLKCTRL_GPMI_CLKGATE;
-	writel(reg, IMX_CCM_BASE + HW_CLKCTRL_GPMI);
-	udelay(1000);
-	/* Initialize DIV to 1 */
-	reg &= ~CLKCTRL_GPMI_DIV_MASK;
-	reg |= 1;
-	writel(reg, IMX_CCM_BASE + HW_CLKCTRL_GPMI);
-}
-
-void imx_dump_clocks(void)
-{
-	printf("mpll:    %10u kHz\n", imx_get_mpllclk() / 1000);
-	printf("arm:     %10u kHz\n", imx_get_armclk() / 1000);
-	printf("ioclk0:  %10u kHz\n", imx_get_ioclk(0) / 1000);
-	printf("ioclk1:  %10u kHz\n", imx_get_ioclk(1) / 1000);
-	printf("emiclk:  %10u kHz\n", imx_get_emiclk() / 1000);
-	printf("hclk:    %10u kHz\n", imx_get_hclk() / 1000);
-	printf("xclk:    %10u kHz\n", imx_get_xclk() / 1000);
-	printf("ssp0:    %10u kHz\n", imx_get_sspclk(0) / 1000);
-	printf("ssp1:    %10u kHz\n", imx_get_sspclk(1) / 1000);
-	printf("ssp2:    %10u kHz\n", imx_get_sspclk(2) / 1000);
-	printf("ssp3:    %10u kHz\n", imx_get_sspclk(3) / 1000);
-}
-- 
1.8.3.1



From alex.aring at gmail.com  Thu Jun 20 03:28:44 2013
From: alex.aring at gmail.com (Alexander Aring)
Date: Thu, 20 Jun 2013 09:28:44 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <20130620064217.GN32299@pengutronix.de>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
 <20130619213239.GA3707@x61s.8.8.8.8>
 <20130619215700.GA2135@x61s.8.8.8.8>
 <20130620064217.GN32299@pengutronix.de>
Message-ID: <20130620072843.GA2086@x61s>

Hi Sascha,

On Thu, Jun 20, 2013 at 08:42:17AM +0200, Sascha Hauer wrote:
> On Wed, Jun 19, 2013 at 11:57:01PM +0200, Alexander Aring wrote:
> > Hi,
> > 
> > On Wed, Jun 19, 2013 at 11:32:39PM +0200, Alexander Aring wrote:
> > > Hi Sascha,
> > > 
> > > only a very small hint.
> > > 
> > > On Wed, Jun 19, 2013 at 10:58:48PM +0200, Sascha Hauer wrote:
> > > > Some tftp servers (for example netkit-tftp) do not pass the filesize.
> > > > Add a workaround for read_file which reads the file into a temporary
> > > > file which then is copied to a buffer.
> > > > 
> > > > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > > > ---
> > > >  fs/fs.c      | 18 ++++++++++++++++++
> > > >  fs/tftp.c    |  5 ++++-
> > > >  include/fs.h |  2 ++
> > > >  3 files changed, 24 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/fs/fs.c b/fs/fs.c
> > > > index dc3a6e3..7046f2c 100644
> > > > --- a/fs/fs.c
> > > > +++ b/fs/fs.c
> > > > @@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size)
> > > >  	int fd;
> > > 
> > > ...
> > > 
> > > >  
> > > >  	tftp_do_close(priv);
> > > >  
> > > > diff --git a/include/fs.h b/include/fs.h
> > > > index 8ff7300..fa6a8da 100644
> > > > --- a/include/fs.h
> > > > +++ b/include/fs.h
> > > > @@ -147,6 +147,8 @@ int protect(int fd, size_t count, unsigned long offset, int prot);
> > > >  int protect_file(const char *file, int prot);
> > > >  void *memmap(int fd, int flags);
> > > >  
> > > > +#define FILESIZE_MAX	((size_t)-1)
> > > 
> > > The type of st_size in struct stat is loff_t. I check this and
> > > ((size_t)-1) is different than ((loff_t)-1), so I think we need to cast
> > > to loff_t. Maybe it's better to use a define from limits.h, but we don't
> > > have some header file like this.
> > > 
> > 
> > ah, I see it now. The fs layer use size_t instead of loff_t. Sorry for
> > the noise.
> 
> No no, you were right. This indeed has to be a loff_t. Where did you
> find that the fs layer uses size_t? It should do so only for the length
> arguments of read/write and friends.
> 

In function read_file :). The parameter size should be changed to
loff_t instead of size_t, because we make "*size = s.st_size;".



The point is, that a file can be greater than 4GB, but we _can't_
read/write a "block" from a file that is greather than 4GB.

But in this function we do "read(fd, buf, s.st_size) < s.st_size", this
need to be in small (max) 4GB pieces(if necessary). In other words, we
can't use s.st_size here if the file is greater than ((size_t)-1).

I don't think if we need something like this, because we never handle
files which are greater than 4GB.

That's my point of view. This example is only for a 32Bit architecture.

Regards
Alex


From s.hauer at pengutronix.de  Thu Jun 20 04:12:28 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 10:12:28 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <20130620072843.GA2086@x61s>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
 <20130619213239.GA3707@x61s.8.8.8.8>
 <20130619215700.GA2135@x61s.8.8.8.8>
 <20130620064217.GN32299@pengutronix.de>
 <20130620072843.GA2086@x61s>
Message-ID: <20130620081228.GP32299@pengutronix.de>

On Thu, Jun 20, 2013 at 09:28:44AM +0200, Alexander Aring wrote:
> Hi Sascha,
> 
> > 
> > No no, you were right. This indeed has to be a loff_t. Where did you
> > find that the fs layer uses size_t? It should do so only for the length
> > arguments of read/write and friends.
> > 
> 
> In function read_file :). The parameter size should be changed to
> loff_t instead of size_t, because we make "*size = s.st_size;".
> 
> 
> 
> The point is, that a file can be greater than 4GB, but we _can't_
> read/write a "block" from a file that is greather than 4GB.
> 
> But in this function we do "read(fd, buf, s.st_size) < s.st_size", this
> need to be in small (max) 4GB pieces(if necessary). In other words, we
> can't use s.st_size here if the file is greater than ((size_t)-1).
> 
> I don't think if we need something like this, because we never handle
> files which are greater than 4GB.
> 
> That's my point of view. This example is only for a 32Bit architecture.

Ok, so read_file is broken for files > 4GiB. I think we can live with
this for a while ;)

BTW the maximum memory size the tlsf allocator can handle is 1GiB, we
have to overcome this first.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 20 04:33:58 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 10:33:58 +0200
Subject: [PATCH v2 16/22] OF: base: import parse phandle functions from
 Linux OF API
In-Reply-To: <1371632991-1504-17-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371632991-1504-17-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130620083358.GQ32299@pengutronix.de>

Hi Sebastian,

> diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
> index 83b72c0..87b9c0c 100644
> --- a/drivers/of/gpio.c
> +++ b/drivers/of/gpio.c
> @@ -9,17 +9,16 @@ int of_get_named_gpio(struct device_node *np,
>                                     const char *propname, int index)
>  {
>  	int ret;
> -	struct device_node *gpio_np;
> -	const void *gpio_spec;
> +	struct of_phandle_args out_args;
>  
> -	ret = of_parse_phandles_with_args(np, propname, "#gpio-cells", index,
> -					  &gpio_np, &gpio_spec);
> +	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
> +					index, &out_args);
>  	if (ret) {
>  		pr_debug("%s: can't parse gpios property: %d\n", __func__, ret);
>  		return -EINVAL;
>  	}
>  
> -	ret = gpio_get_num(gpio_np->device, be32_to_cpup(gpio_spec));
> +	ret = gpio_get_num(out_args.np->device, outargs.args[0]);

Typo: s/outargs/out_args/

(No need to resend atm)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 20 04:57:43 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 10:57:43 +0200
Subject: [PATCH v2 06/22] OF: base: sync of_find_property with linux OF API
In-Reply-To: <1371632991-1504-7-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371632991-1504-7-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130620085743.GR32299@pengutronix.de>

On Wed, Jun 19, 2013 at 11:09:35AM +0200, Sebastian Hesselbarth wrote:
> To start synchronizing OF API of barebox with linux OF API, this adds
> a length pointer to of_find_property. Also all current users of that
> function are updated to reflect the API change.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: barebox at lists.infradead.org
> ---
>  commands/of_property.c         |    2 +-
>  drivers/of/base.c              |   38 ++++++++++++++++++--------------------
>  drivers/of/fdt.c               |    5 ++++-
>  drivers/of/of_net.c            |    6 +++---
>  drivers/pinctrl/pinctrl.c      |    4 ++--
>  drivers/spi/spi.c              |   10 +++++-----
>  drivers/usb/imx/chipidea-imx.c |    3 ++-
>  include/of.h                   |   12 ++++++++++--
>  8 files changed, 45 insertions(+), 35 deletions(-)
> 
> diff --git a/commands/of_property.c b/commands/of_property.c
> index 44bb388..d1a9a17 100644
> --- a/commands/of_property.c
> +++ b/commands/of_property.c
> @@ -212,7 +212,7 @@ static int do_of_property(int argc, char *argv[])
>  	if (optind + 1 < argc) {
>  		propname = argv[optind + 1];
>  
> -		pp = of_find_property(node, propname);
> +		pp = of_find_property(node, propname, NULL);
>  		if (!set && !pp) {
>  			printf("Cannot find property %s\n", propname);
>  			return -ENOENT;
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 1c9ef58..85199b6 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -102,16 +102,20 @@ static void of_bus_count_cells(struct device_node *dev,
>  	of_bus_default_count_cells(dev, addrc, sizec);
>  }
>  
> -struct property *of_find_property(const struct device_node *node, const char *name)
> +struct property *of_find_property(const struct device_node *np,
> +				  const char *name, int *lenp)
>  {
>  	struct property *pp;
>  
> -	if (!node)
> +	if (!np)
>  		return NULL;
>  
> -	list_for_each_entry(pp, &node->properties, list)
> -		if (of_prop_cmp(pp->name, name) == 0)
> +	list_for_each_entry(pp, &np->properties, list)
> +		if (of_prop_cmp(pp->name, name) == 0) {
> +			if (lenp)
> +				*lenp = pp->length;
>  			return pp;
> +		}
>  
>  	return NULL;
>  }
> @@ -242,7 +246,7 @@ u64 of_translate_address(struct device_node *node, const __be32 *in_addr)
>  			return addr;
>  
>  		node = node->parent;
> -		p = of_find_property(node, "ranges");
> +		p = of_find_property(node, "ranges", NULL);
>  		if (!p && node->parent)
>  			return OF_BAD_ADDR;
>  		of_bus_count_cells(node, &na, &nc);
> @@ -277,13 +281,7 @@ EXPORT_SYMBOL(of_find_node_by_phandle);
>  const void *of_get_property(const struct device_node *np, const char *name,
>  			 int *lenp)
>  {
> -	struct property *pp = of_find_property(np, name);
> -
> -	if (!pp)
> -		return NULL;
> -
> -	if (lenp)
> -		*lenp = pp->length;
> +	struct property *pp = of_find_property(np, name, lenp);
>  
>  	return pp ? pp->value : NULL;
>  }
> @@ -368,7 +366,7 @@ int of_property_read_u32_array(const struct device_node *np,
>  			       const char *propname, u32 *out_values,
>  			       size_t sz)
>  {
> -	struct property *prop = of_find_property(np, propname);
> +	struct property *prop = of_find_property(np, propname, NULL);
>  	const __be32 *val;
>  
>  	if (!prop)
> @@ -404,7 +402,7 @@ int of_property_write_u32_array(struct device_node *np,
>  				const char *propname, const u32 *values,
>  				size_t sz)
>  {
> -	struct property *prop = of_find_property(np, propname);
> +	struct property *prop = of_find_property(np, propname, NULL);
>  	__be32 *val;
>  
>  	if (!prop)
> @@ -619,7 +617,7 @@ EXPORT_SYMBOL(of_find_node_by_path);
>  int of_property_read_string(struct device_node *np, const char *propname,
>  				const char **out_string)
>  {
> -	struct property *prop = of_find_property(np, propname);
> +	struct property *prop = of_find_property(np, propname, NULL);
>  	if (!prop)
>  		return -EINVAL;
>  	if (!prop->value)
> @@ -652,7 +650,7 @@ EXPORT_SYMBOL_GPL(of_property_read_string);
>  int of_property_read_string_index(struct device_node *np, const char *propname,
>  				  int index, const char **output)
>  {
> -	struct property *prop = of_find_property(np, propname);
> +	struct property *prop = of_find_property(np, propname, NULL);
>  	int i = 0;
>  	size_t l = 0, total = 0;
>  	const char *p;
> @@ -725,7 +723,7 @@ static int of_node_disabled(struct device_node *node)
>  {
>  	struct property *p;
>  
> -	p = of_find_property(node, "status");
> +	p = of_find_property(node, "status", NULL);
>  	if (p) {
>  		if (!strcmp("disabled", p->value))
>  			return 1;
> @@ -833,7 +831,7 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
>  	if (!np)
>  		return -ENOENT;
>  
> -	pp = of_find_property(np, name);
> +	pp = of_find_property(np, name, NULL);
>  	if (pp) {
>  		void *data;
>  
> @@ -1278,11 +1276,11 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
>  	} else {
>  		struct property *pp;
>  
> -		pp = of_find_property(chosen, "linux,initrd-start");
> +		pp = of_find_property(chosen, "linux,initrd-start", NULL);
>  		if (pp)
>  			of_delete_property(pp);
>  
> -		pp = of_find_property(chosen, "linux,initrd-end");
> +		pp = of_find_property(chosen, "linux,initrd-end", NULL);
>  		if (pp)
>  			of_delete_property(pp);
>  	}
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index a3ec576..a76396e 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -178,7 +178,10 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
>  				goto err;
>  			}
>  
> -			if (merge && (p = of_find_property(node, name))) {
> +			p = NULL;
> +			if (merge)
> +				p = of_find_property(node, name, NULL);
> +			if (merge && p) {
>  				free(p->value);
>  				p->value = xzalloc(len);
>  				memcpy(p->value, nodep, len);
> diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
> index de93fbc..2bf05e2 100644
> --- a/drivers/of/of_net.c
> +++ b/drivers/of/of_net.c
> @@ -76,15 +76,15 @@ const void *of_get_mac_address(struct device_node *np)
>  {
>  	struct property *pp;
>  
> -	pp = of_find_property(np, "mac-address");
> +	pp = of_find_property(np, "mac-address", NULL);
>  	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
>  		return pp->value;
>  
> -	pp = of_find_property(np, "local-mac-address");
> +	pp = of_find_property(np, "local-mac-address", NULL);
>  	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
>  		return pp->value;
>  
> -	pp = of_find_property(np, "address");
> +	pp = of_find_property(np, "address", NULL);
>  	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
>  		return pp->value;
>  
> diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
> index fa979a1..7c797d3 100644
> --- a/drivers/pinctrl/pinctrl.c
> +++ b/drivers/pinctrl/pinctrl.c
> @@ -64,14 +64,14 @@ int pinctrl_select_state(struct device_d *dev, const char *name)
>  	if (!np)
>  		return 0;
>  
> -	if (!of_find_property(np, "pinctrl-0"))
> +	if (!of_find_property(np, "pinctrl-0", NULL))
>  		return 0;
>  
>  	/* For each defined state ID */
>  	for (state = 0; ; state++) {
>  		/* Retrieve the pinctrl-* property */
>  		propname = asprintf("pinctrl-%d", state);
> -		prop = of_find_property(np, propname);
> +		prop = of_find_property(np, propname, NULL);
>  		free(propname);
>  
>  		if (!prop) {
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index f460a7a..eebf64c 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -112,17 +112,17 @@ void spi_of_register_slaves(struct spi_master *master, struct device_node *node)
>  		chip.name = xstrdup(n->name);
>  		chip.bus_num = master->bus_num;
>  		/* Mode (clock phase/polarity/etc.) */
> -		if (of_find_property(n, "spi-cpha"))
> +		if (of_find_property(n, "spi-cpha", NULL))
>  			chip.mode |= SPI_CPHA;
> -		if (of_find_property(n, "spi-cpol"))
> +		if (of_find_property(n, "spi-cpol", NULL))
>  			chip.mode |= SPI_CPOL;
> -		if (of_find_property(n, "spi-cs-high"))
> +		if (of_find_property(n, "spi-cs-high", NULL))
>  			chip.mode |= SPI_CS_HIGH;
> -		if (of_find_property(n, "spi-3wire"))
> +		if (of_find_property(n, "spi-3wire", NULL))
>  			chip.mode |= SPI_3WIRE;
>  		of_property_read_u32(n, "spi-max-frequency",
>  				&chip.max_speed_hz);
> -		reg = of_find_property(n, "reg");
> +		reg = of_find_property(n, "reg", NULL);
>  		if (!reg)
>  			continue;
>  		chip.chip_select = of_read_number(reg->value, 1);
> diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
> index 4ee7610..32b05aa 100644
> --- a/drivers/usb/imx/chipidea-imx.c
> +++ b/drivers/usb/imx/chipidea-imx.c
> @@ -108,7 +108,8 @@ static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
>  		return -EINVAL;
>  	}
>  
> -	if (of_find_property(ci->dev->device_node, "disable-over-current"))
> +	if (of_find_property(ci->dev->device_node,
> +				"disable-over-current"), NULL)

This needs to be:

+     if (of_find_property(ci->dev->device_node,
+                             "disable-over-current", NULL))

(I'll fix this up while applying if there's no other showstopper for this
series)

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 20 05:04:06 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 11:04:06 +0200
Subject: [PATCH v2 01/22] lib: string: import case-insensitive string
 compare
In-Reply-To: <1371632991-1504-2-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371632991-1504-2-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130620090406.GS32299@pengutronix.de>

This patch needs the following before it to not break ppc compilation.

Sascha


>From 1a8c27b7ad29bfa5f868db15e11da8e6bdc7d01f Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer at pengutronix.de>
Date: Thu, 20 Jun 2013 11:02:09 +0200
Subject: [PATCH] ppc: remove strcasecmp/strncasecmp prototypes

ppc does not implement these, so remove the prototypes and use
the ones from include/linux/string.h

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/ppc/include/asm/string.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/ppc/include/asm/string.h b/arch/ppc/include/asm/string.h
index d912a6b..33d143f 100644
--- a/arch/ppc/include/asm/string.h
+++ b/arch/ppc/include/asm/string.h
@@ -13,8 +13,6 @@
 #define __HAVE_ARCH_MEMCMP
 #define __HAVE_ARCH_MEMCHR
 
-extern int strcasecmp(const char *, const char *);
-extern int strncasecmp(const char *, const char *, int);
 extern char * strcpy(char *,const char *);
 extern char * strncpy(char *,const char *, __kernel_size_t);
 extern __kernel_size_t strlen(const char *);
-- 
1.8.3.1


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 20 05:18:20 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 11:18:20 +0200
Subject: [PATCH v2 00/22] Barebox OF API fixes, sync, and cleanup
In-Reply-To: <1371632991-1504-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371576607-8090-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371632991-1504-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130620091820.GT32299@pengutronix.de>

On Wed, Jun 19, 2013 at 11:09:29AM +0200, Sebastian Hesselbarth wrote:
> This is a quite large patch set to make Barebox OF API more behave
> like Linux OF API. Also, it prepares Barebox to reuse Linux OF address
> handling and drivers/of/of_* helpers soon.
> 
> The patch set is roughly divided into 5 sections:
> 
> (1) Patch 1 introduces case-insensitive string compare functions that will
>     be used later during import of Linux OF API functions.
> 
> (2) Patches 2 and 3 fix some bugs in existing OF API functions.
> 
> (3) Patches 4-8 synchronize existing OF API functions with Linux OF API
>     counterparts.
> 
> (4) Patches 9-18 import API functions from Linux OF API or introduce new
>     functions based on existing Barebox OF API functions.
> 
> (5) Patches 19-22 convert to new API functions and remove now obsolete
>     functions. Further, it cleans up existing OF include, by providing
>     OFTREE prototypes and !OFTREE bogus stubs.
> 
> v2 of this patch set takes care of comments made by Sascha Hauer with
> respect to Patches 7 and 13. A detailed changelog is given in the
> respective patches. Unfortunately, I have to resend the whole patch
> set, although only 2 patches really changed as the following patches
> need to be rebased on to that changes.
> 
> Also, this v2 is only compile-tested for CONFIG_OFTREE set and not set.
> 
> The v2 patch set applied to barebox/next can also be found at
> git://github.com/shesselba/barebox-dove.git barebox-of-sync-v2

I gave this series a test. With the fixes I mentioned the series
compiles on all boards. I did runtime tests on a few oftree enabled
boards, everything seems to work smoothly.

I think we are good to go for this series.

Good work, thanks.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From J.Weitzel at phytec.de  Thu Jun 20 07:15:31 2013
From: J.Weitzel at phytec.de (Jan Weitzel)
Date: Thu, 20 Jun 2013 13:15:31 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371726931.3466.3.camel@lws-weitzel>

Am Mittwoch, den 19.06.2013, 22:58 +0200 schrieb Sascha Hauer:
> Some tftp servers (for example netkit-tftp) do not pass the filesize.
> Add a workaround for read_file which reads the file into a temporary
> file which then is copied to a buffer.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  fs/fs.c      | 18 ++++++++++++++++++
>  fs/tftp.c    |  5 ++++-
>  include/fs.h |  2 ++
>  3 files changed, 24 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/fs.c b/fs/fs.c
> index dc3a6e3..7046f2c 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size)
>  	int fd;
>  	struct stat s;
>  	void *buf = NULL;
> +	const char *tmpfile = "/.read_file_tmp";
> +	int ret;
>  
> +again:
>  	if (stat(filename, &s))
>  		return NULL;
>  
> +	if (s.st_size == FILESIZE_MAX) {
> +		ret = copy_file(filename, tmpfile, 0);
> +		if (ret)
> +			return NULL;
> +		filename = tmpfile;
> +		goto again;
> +	}
> +
>  	buf = xzalloc(s.st_size + 1);
>  
>  	fd = open(filename, O_RDONLY);
> @@ -56,12 +67,19 @@ void *read_file(const char *filename, size_t *size)
>  	if (size)
>  		*size = s.st_size;
>  
> +	if (filename == tmpfile)
> +		unlink(tmpfile);
> +
>  	return buf;
>  
>  err_out1:
>  	close(fd);
>  err_out:
>  	free(buf);
> +
> +	if (filename == tmpfile)
> +		unlink(tmpfile);
> +
>  	return NULL;
>  }
>  
> diff --git a/fs/tftp.c b/fs/tftp.c
> index 98cbb37..1c37acf 100644
> --- a/fs/tftp.c
> +++ b/fs/tftp.c
> @@ -597,7 +597,10 @@ static int tftp_stat(struct device_d *dev, const char *filename, struct stat *s)
>  		return PTR_ERR(priv);
>  
>  	s->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
> -	s->st_size = priv->filesize;
> +	if (priv->filesize)
> +		s->st_size = priv->filesize;
> +	else
> +		s->st_size = FILESIZE_MAX;
Maybe we can determine the size here? Commands like "ls -l" and
"ubiformat" asks about the filesize via stat. I'm not sure how much
overheat it will be.

Jan
>  
>  	tftp_do_close(priv);
>  
> diff --git a/include/fs.h b/include/fs.h
> index 8ff7300..fa6a8da 100644
> --- a/include/fs.h
> +++ b/include/fs.h
> @@ -147,6 +147,8 @@ int protect(int fd, size_t count, unsigned long offset, int prot);
>  int protect_file(const char *file, int prot);
>  void *memmap(int fd, int flags);
>  
> +#define FILESIZE_MAX	((size_t)-1)
> +
>  #define PROT_READ	1
>  #define PROT_WRITE	2
>  




From t.gamez at phytec.de  Thu Jun 20 08:50:27 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Thu, 20 Jun 2013 14:50:27 +0200
Subject: [PATCH 0/3] I2C support for AM33xx
Message-ID: <1371732630-27966-1-git-send-email-t.gamez@phytec.de>

This series, does some cleanup in the i2c-omap
driver and adds i2c support for AM33xx.

This should be applied on top of the 
	commit 9738361e32f908e433cb4a5a42ada13b83fedfcb

	ARM: AM33xx: pcm051: Add network support
patch.

Teresa G?mez (3):
  i2c-omap: cleanup cpu_is functions
  ARM: AM33xx: Add i2c support for AM33xx
  ARM: OMAP: pcm051: Add i2c0 and at24 eeprom support

 arch/arm/boards/pcm051/board.c                   |   18 +++
 arch/arm/configs/pcm051_defconfig                |    4 +
 arch/arm/mach-omap/include/mach/am33xx-devices.h |   15 ++
 arch/arm/mach-omap/include/mach/am33xx-silicon.h |    5 +
 arch/arm/mach-omap/include/mach/generic.h        |    6 +
 drivers/i2c/busses/i2c-omap.c                    |  169 ++++++++--------------
 6 files changed, 112 insertions(+), 105 deletions(-)



From t.gamez at phytec.de  Thu Jun 20 08:50:30 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Thu, 20 Jun 2013 14:50:30 +0200
Subject: [PATCH 3/3] ARM: OMAP: pcm051: Add i2c0 and at24 eeprom support
In-Reply-To: <1371732630-27966-1-git-send-email-t.gamez@phytec.de>
References: <1371732630-27966-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371732630-27966-4-git-send-email-t.gamez@phytec.de>

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 arch/arm/boards/pcm051/board.c    |   18 ++++++++++++++++++
 arch/arm/configs/pcm051_defconfig |    4 ++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boards/pcm051/board.c b/arch/arm/boards/pcm051/board.c
index 0ad8cb4..eea5ebb 100644
--- a/arch/arm/boards/pcm051/board.c
+++ b/arch/arm/boards/pcm051/board.c
@@ -32,6 +32,8 @@
 #include <mach/cpsw.h>
 #include <spi/spi.h>
 #include <spi/flash.h>
+#include <i2c/i2c.h>
+#include <i2c/at24.h>
 
 #include "mux.h"
 
@@ -89,6 +91,12 @@ static struct cpsw_platform_data cpsw_data = {
 	.num_slaves	= ARRAY_SIZE(cpsw_slaves),
 };
 
+static struct i2c_board_info i2c0_devices[] = {
+	{
+		I2C_BOARD_INFO("24c32", 0x52),
+	},
+};
+
 static void pcm051_spi_init(void)
 {
 	int ret;
@@ -111,6 +119,15 @@ static void pcm051_eth_init(void)
 	am33xx_add_cpsw(&cpsw_data);
 }
 
+static void pcm051_i2c_init(void)
+{
+	am33xx_enable_i2c0_pin_mux();
+
+	i2c_register_board_info(0, i2c0_devices, ARRAY_SIZE(i2c0_devices));
+
+	am33xx_add_i2c0(NULL);
+}
+
 static int pcm051_devices_init(void)
 {
 	pcm051_enable_mmc0_pin_mux();
@@ -119,6 +136,7 @@ static int pcm051_devices_init(void)
 
 	pcm051_spi_init();
 	pcm051_eth_init();
+	pcm051_i2c_init();
 
 	devfs_add_partition("nor0", 0x00000, SZ_128K,
 					DEVFS_PARTITION_FIXED, "xload");
diff --git a/arch/arm/configs/pcm051_defconfig b/arch/arm/configs/pcm051_defconfig
index 804ca14..8de3714 100644
--- a/arch/arm/configs/pcm051_defconfig
+++ b/arch/arm/configs/pcm051_defconfig
@@ -42,6 +42,7 @@ CONFIG_CMD_TIMEOUT=y
 CONFIG_CMD_PARTITION=y
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_UNCOMPRESS=y
+CONFIG_CMD_I2C=y
 CONFIG_NET=y
 CONFIG_NET_DHCP=y
 CONFIG_NET_NFS=y
@@ -50,6 +51,8 @@ CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SERIAL_NS16550_OMAP_EXTENSIONS=y
 CONFIG_DRIVER_NET_CPSW=y
 CONFIG_DRIVER_SPI_OMAP3=y
+CONFIG_I2C=y
+CONFIG_I2C_OMAP=y
 CONFIG_MTD=y
 CONFIG_MTD_M25P80=y
 CONFIG_NAND=y
@@ -57,6 +60,7 @@ CONFIG_USB=y
 CONFIG_MCI=y
 CONFIG_MCI_STARTUP=y
 CONFIG_MCI_OMAP_HSMMC=y
+CONFIG_EEPROM_AT24=y
 CONFIG_FS_FAT=y
 CONFIG_FS_FAT_WRITE=y
 CONFIG_FS_FAT_LFN=y
-- 
1.7.0.4



From t.gamez at phytec.de  Thu Jun 20 08:50:29 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Thu, 20 Jun 2013 14:50:29 +0200
Subject: [PATCH 2/3] ARM: AM33xx: Add i2c support for AM33xx
In-Reply-To: <1371732630-27966-1-git-send-email-t.gamez@phytec.de>
References: <1371732630-27966-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371732630-27966-3-git-send-email-t.gamez@phytec.de>

Added device register functions and cpu_is_am33xx()
function.
Adapted the i2c-omap driver. AM335x has a lower
clock rate and the timeout of polling the isr function
had to be increased.

Based on a patch from Shravan Kumar <shravan.k at phytec.in>.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 arch/arm/mach-omap/include/mach/am33xx-devices.h |   15 +++++++++++++++
 arch/arm/mach-omap/include/mach/am33xx-silicon.h |    5 +++++
 arch/arm/mach-omap/include/mach/generic.h        |    6 ++++++
 drivers/i2c/busses/i2c-omap.c                    |   14 +++++++++-----
 4 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-omap/include/mach/am33xx-devices.h b/arch/arm/mach-omap/include/mach/am33xx-devices.h
index 7da4b99..822caab 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-devices.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-devices.h
@@ -53,4 +53,19 @@ static inline struct device_d *am33xx_add_spi1(void)
 	return am33xx_add_spi(1, AM33XX_MCSPI1_BASE);
 }
 
+static inline struct device_d *am33xx_add_i2c0(void *pdata)
+{
+	return omap_add_i2c(0, AM33XX_I2C0_BASE, pdata);
+}
+
+static inline struct device_d *am33xx_add_i2c1(void *pdata)
+{
+	return omap_add_i2c(1, AM33XX_I2C1_BASE, pdata);
+}
+
+static inline struct device_d *am33xx_add_i2c2(void *pdata)
+{
+	return omap_add_i2c(2, AM33XX_I2C2_BASE, pdata);
+}
+
 #endif /* __MACH_OMAP3_DEVICES_H */
diff --git a/arch/arm/mach-omap/include/mach/am33xx-silicon.h b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
index 59284af..8a7bd16 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-silicon.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-silicon.h
@@ -41,6 +41,11 @@
 #define AM33XX_DRAM_ADDR_SPACE_START	0x80000000
 #define AM33XX_DRAM_ADDR_SPACE_END	0xC0000000
 
+/* I2C */
+#define AM33XX_I2C0_BASE	(AM33XX_L4_WKUP_BASE + 0x20B000)
+#define AM33XX_I2C1_BASE	(AM33XX_L4_PER_BASE + 0x02A000)
+#define AM33XX_I2C2_BASE	(AM33XX_L4_PER_BASE + 0x19C000)
+
 /* GPMC */
 #define AM33XX_GPMC_BASE		0x50000000
 
diff --git a/arch/arm/mach-omap/include/mach/generic.h b/arch/arm/mach-omap/include/mach/generic.h
index 5a10a54..178c21f 100644
--- a/arch/arm/mach-omap/include/mach/generic.h
+++ b/arch/arm/mach-omap/include/mach/generic.h
@@ -27,4 +27,10 @@
 #define cpu_is_omap4xxx()	(0)
 #endif
 
+#ifdef CONFIG_ARCH_AM33XX
+#define cpu_is_am33xx()		(1)
+#else
+#define cpu_is_am33xx()		(0)
+#endif
+
 #endif
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index ecb33ea..19d54ee 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -245,7 +245,7 @@ static inline u16 omap_i2c_read_reg(struct omap_i2c_struct *i2c_omap, int reg)
 
 static void omap_i2c_unidle(struct omap_i2c_struct *i2c_omap)
 {
-	if (cpu_is_omap34xx()) {
+	if (cpu_is_omap34xx() || cpu_is_am33xx()) {
 		omap_i2c_write_reg(i2c_omap, OMAP_I2C_CON_REG, 0);
 		omap_i2c_write_reg(i2c_omap, OMAP_I2C_PSC_REG, i2c_omap->pscstate);
 		omap_i2c_write_reg(i2c_omap, OMAP_I2C_SCLL_REG, i2c_omap->scllstate);
@@ -353,7 +353,11 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 		internal_clk = 9600;
 	else
 		internal_clk = 4000;
-	fclk_rate = 96000000 / 1000;
+
+	if (cpu_is_am33xx())
+		fclk_rate = 48000;
+	else
+		fclk_rate = 96000;
 
 	/* Compute prescaler divisor */
 	psc = fclk_rate / internal_clk;
@@ -410,7 +414,7 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 			OMAP_I2C_IE_AL)  | ((i2c_omap->fifo_size) ?
 				(OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0);
 	omap_i2c_write_reg(i2c_omap, OMAP_I2C_IE_REG, i2c_omap->iestate);
-	if (cpu_is_omap34xx()) {
+	if (cpu_is_omap34xx() || cpu_is_am33xx()) {
 		i2c_omap->pscstate = psc;
 		i2c_omap->scllstate = scll;
 		i2c_omap->sclhstate = sclh;
@@ -665,7 +669,7 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adapter,
 	ret = omap_i2c_isr(i2c_omap);
 	while (ret){
 		ret = omap_i2c_isr(i2c_omap);
-		if (is_timeout(start, MSECOND)) {
+		if (is_timeout(start, 50 * MSECOND)) {
 				dev_err(&adapter->dev,
 				"timed out on polling for "
 				"open i2c message handling\n");
@@ -743,7 +747,7 @@ i2c_omap_probe(struct device_d *pdev)
 		goto err_free_mem;
 	}
 
-	if (cpu_is_omap4xxx()) {
+	if (cpu_is_omap4xxx() || cpu_is_am33xx()) {
 		i2c_omap->regs = (u8 *)omap4_reg_map;
 		i2c_omap->reg_shift = 0;
 	} else {
-- 
1.7.0.4



From t.gamez at phytec.de  Thu Jun 20 08:50:28 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Thu, 20 Jun 2013 14:50:28 +0200
Subject: [PATCH 1/3] i2c-omap: cleanup cpu_is functions
In-Reply-To: <1371732630-27966-1-git-send-email-t.gamez@phytec.de>
References: <1371732630-27966-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371732630-27966-2-git-send-email-t.gamez@phytec.de>

cpu_is_omap2430() is set when CONFIG_ARCH_OMAP is enabled.
This fits for all OMAP/AM33xx boards supported in barebox.
Cleaned up all conditions that use the cpu_is_omap2430().
Also removed some unused defines.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 drivers/i2c/busses/i2c-omap.c |  159 +++++++++++++++--------------------------
 1 files changed, 57 insertions(+), 102 deletions(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 503443f..ecb33ea 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -24,10 +24,6 @@
  * GNU General Public License for more details.
  */
 
-
-/* #include <linux/delay.h> */
-
-
 #include <clock.h>
 #include <common.h>
 #include <driver.h>
@@ -44,12 +40,6 @@
 #include <mach/generic.h>
 #include <mach/omap3-clock.h>
 
-#define OMAP_I2C_SIZE		0x3f
-#define OMAP1_I2C_BASE		0xfffb3800
-#define OMAP2_I2C_BASE1		0x48070000
-#define OMAP2_I2C_BASE2		0x48072000
-#define OMAP2_I2C_BASE3		0x48060000
-
 /* This will be the driver name */
 #define DRIVER_NAME "i2c-omap"
 
@@ -141,7 +131,6 @@
 #define SYSC_IDLEMODE_SMART		0x2
 #define SYSC_CLOCKACTIVITY_FCLK		0x2
 
-
 struct omap_i2c_struct {
 	void 			*base;
 	u8			*regs;
@@ -352,63 +341,51 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 	}
 	omap_i2c_write_reg(i2c_omap, OMAP_I2C_CON_REG, 0);
 
-	/* omap1 handling is missing here */
-
-	if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap4xxx()) {
-
-		/*
-		 * HSI2C controller internal clk rate should be 19.2 Mhz for
-		 * HS and for all modes on 2430. On 34xx we can use lower rate
-		 * to get longer filter period for better noise suppression.
-		 * The filter is iclk (fclk for HS) period.
-		 */
-		if (i2c_omap->speed > 400 || cpu_is_omap2430())
-			internal_clk = 19200;
-		else if (i2c_omap->speed > 100)
-			internal_clk = 9600;
-		else
-			internal_clk = 4000;
-		fclk_rate = 96000000 / 1000;
-
-		/* Compute prescaler divisor */
-		psc = fclk_rate / internal_clk;
-		psc = psc - 1;
-
-		/* If configured for High Speed */
-		if (i2c_omap->speed > 400) {
-			unsigned long scl;
-
-			/* For first phase of HS mode */
-			scl = internal_clk / 400;
-			fsscll = scl - (scl / 3) - 7;
-			fssclh = (scl / 3) - 5;
-
-			/* For second phase of HS mode */
-			scl = fclk_rate / i2c_omap->speed;
-			hsscll = scl - (scl / 3) - 7;
-			hssclh = (scl / 3) - 5;
-		} else if (i2c_omap->speed > 100) {
-			unsigned long scl;
-
-			/* Fast mode */
-			scl = internal_clk / i2c_omap->speed;
-			fsscll = scl - (scl / 3) - 7;
-			fssclh = (scl / 3) - 5;
-		} else {
-			/* Standard mode */
-			fsscll = internal_clk / (i2c_omap->speed * 2) - 7;
-			fssclh = internal_clk / (i2c_omap->speed * 2) - 5;
-		}
-		scll = (hsscll << OMAP_I2C_SCLL_HSSCLL) | fsscll;
-		sclh = (hssclh << OMAP_I2C_SCLH_HSSCLH) | fssclh;
+	/*
+	 * HSI2C controller internal clk rate should be 19.2 Mhz for
+	 * HS and for all modes on 2430. On 34xx we can use lower rate
+	 * to get longer filter period for better noise suppression.
+	 * The filter is iclk (fclk for HS) period.
+	 */
+	if (i2c_omap->speed > 400)
+		internal_clk = 19200;
+	else if (i2c_omap->speed > 100)
+		internal_clk = 9600;
+	else
+		internal_clk = 4000;
+	fclk_rate = 96000000 / 1000;
+
+	/* Compute prescaler divisor */
+	psc = fclk_rate / internal_clk;
+	psc = psc - 1;
+
+	/* If configured for High Speed */
+	if (i2c_omap->speed > 400) {
+		unsigned long scl;
+
+		/* For first phase of HS mode */
+		scl = internal_clk / 400;
+		fsscll = scl - (scl / 3) - 7;
+		fssclh = (scl / 3) - 5;
+
+		/* For second phase of HS mode */
+		scl = fclk_rate / i2c_omap->speed;
+		hsscll = scl - (scl / 3) - 7;
+		hssclh = (scl / 3) - 5;
+	} else if (i2c_omap->speed > 100) {
+		unsigned long scl;
+
+		/* Fast mode */
+		scl = internal_clk / i2c_omap->speed;
+		fsscll = scl - (scl / 3) - 7;
+		fssclh = (scl / 3) - 5;
 	} else {
-		/* Program desired operating rate */
-		fclk_rate /= (psc + 1) * 1000;
-		if (psc > 2)
-			psc = 2;
-		scll = fclk_rate / (i2c_omap->speed * 2) - 7 + psc;
-		sclh = fclk_rate / (i2c_omap->speed * 2) - 7 + psc;
+		/* Standard mode */
+		fsscll = internal_clk / (i2c_omap->speed * 2) - 7;
+		fssclh = internal_clk / (i2c_omap->speed * 2) - 5;
 	}
+	scll = (hsscll << OMAP_I2C_SCLL_HSSCLL) | fsscll;
+	sclh = (hssclh << OMAP_I2C_SCLH_HSSCLH) | fssclh;
 
 	/* Setup clock prescaler to obtain approx 12MHz I2C module clock: */
 	omap_i2c_write_reg(i2c_omap, OMAP_I2C_PSC_REG, psc);
@@ -525,15 +502,6 @@ complete:
 				if (dev->buf_len) {
 					*dev->buf++ = w;
 					dev->buf_len--;
-					/* Data reg from 2430 is 8 bit wide */
-					if (!cpu_is_omap2430() &&
-							!cpu_is_omap34xx() &&
-							!cpu_is_omap4xxx()) {
-						if (dev->buf_len) {
-							*dev->buf++ = w >> 8;
-							dev->buf_len--;
-						}
-					}
 				} else {
 					if (stat & OMAP_I2C_STAT_RRDY)
 						dev_err(&dev->adapter.dev,
@@ -566,15 +534,6 @@ complete:
 				if (dev->buf_len) {
 					w = *dev->buf++;
 					dev->buf_len--;
-					/* Data reg from  2430 is 8 bit wide */
-					if (!cpu_is_omap2430() &&
-							!cpu_is_omap34xx() &&
-							!cpu_is_omap4xxx()) {
-						if (dev->buf_len) {
-							w |= *dev->buf++ << 8;
-							dev->buf_len--;
-						}
-					}
 				} else {
 					if (stat & OMAP_I2C_STAT_XRDY)
 						dev_err(&dev->adapter.dev,
@@ -776,6 +735,7 @@ i2c_omap_probe(struct device_d *pdev)
 	/* struct i2c_platform_data *pdata; */
 	int r;
 	u32 speed = 0;
+	u16 s;
 
 	i2c_omap = kzalloc(sizeof(struct omap_i2c_struct), GFP_KERNEL);
 	if (!i2c_omap) {
@@ -802,28 +762,23 @@ i2c_omap_probe(struct device_d *pdev)
 	omap_i2c_unidle(i2c_omap);
 
 	i2c_omap->rev = omap_i2c_read_reg(i2c_omap, OMAP_I2C_REV_REG) & 0xff;
-	/* i2c_omap->base = OMAP2_I2C_BASE3; */
-
-	if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap4xxx()) {
-		u16 s;
 
-		/* Set up the fifo size - Get total size */
-		s = (omap_i2c_read_reg(i2c_omap, OMAP_I2C_BUFSTAT_REG) >> 14) & 0x3;
-		i2c_omap->fifo_size = 0x8 << s;
+	/* Set up the fifo size - Get total size */
+	s = (omap_i2c_read_reg(i2c_omap, OMAP_I2C_BUFSTAT_REG) >> 14) & 0x3;
+	i2c_omap->fifo_size = 0x8 << s;
 
-		/*
-		 * Set up notification threshold as half the total available
-		 * size. This is to ensure that we can handle the status on int
-		 * call back latencies.
-		 */
+	/*
+	 * Set up notification threshold as half the total available
+	 * size. This is to ensure that we can handle the status on int
+	 * call back latencies.
+	 */
 
-		i2c_omap->fifo_size = (i2c_omap->fifo_size / 2);
+	i2c_omap->fifo_size = (i2c_omap->fifo_size / 2);
 
-		if (i2c_omap->rev >= OMAP_I2C_REV_ON_4430)
-			i2c_omap->b_hw = 0; /* Disable hardware fixes */
-		else
-			i2c_omap->b_hw = 1; /* Enable hardware fixes */
-	}
+	if (i2c_omap->rev >= OMAP_I2C_REV_ON_4430)
+		i2c_omap->b_hw = 0; /* Disable hardware fixes */
+	else
+		i2c_omap->b_hw = 1; /* Enable hardware fixes */
 
 	/* reset ASAP, clearing any IRQs */
 	omap_i2c_init(i2c_omap);
-- 
1.7.0.4



From s.hauer at pengutronix.de  Thu Jun 20 10:00:54 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:00:54 +0200
Subject: [PATCH 3/3] ata: Make 'already initialized' a debug message
In-Reply-To: <1371736854-7543-1-git-send-email-s.hauer@pengutronix.de>
References: <1371736854-7543-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371736854-7543-4-git-send-email-s.hauer@pengutronix.de>

This is only interesting for the debug case.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/disk_ata_drive.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index e96d98d..ee1709e 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -290,7 +290,7 @@ int ata_port_detect(struct ata_port *port)
 	int ret;
 
 	if (port->initialized) {
-		dev_info(&port->class_dev, "already initialized\n");
+		dev_dbg(&port->class_dev, "already initialized\n");
 		return 0;
 	}
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 10:00:53 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:00:53 +0200
Subject: [PATCH 2/3] ata: pata-imx: implement detect callback for hardware
 device
In-Reply-To: <1371736854-7543-1-git-send-email-s.hauer@pengutronix.de>
References: <1371736854-7543-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371736854-7543-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/pata-imx.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/ata/pata-imx.c b/drivers/ata/pata-imx.c
index aed6df1..93809c2 100644
--- a/drivers/ata/pata-imx.c
+++ b/drivers/ata/pata-imx.c
@@ -146,6 +146,13 @@ static void imx_pata_setup_port(void *reg_base, void *alt_base,
 	}
 }
 
+static int pata_imx_detect(struct device_d *dev)
+{
+	struct ide_port *ide = dev->priv;
+
+	return ata_port_detect(&ide->port);
+}
+
 static int imx_pata_probe(struct device_d *dev)
 {
 	struct ide_port *ide;
@@ -182,6 +189,9 @@ static int imx_pata_probe(struct device_d *dev)
 	ide->port.dev = dev;
 	ide->port.devname = devname;
 
+	dev->priv = ide;
+	dev->detect = pata_imx_detect;
+
 	ret = ide_port_register(ide);
 	if (ret) {
 		dev_err(dev, "Cannot register IDE interface: %s\n",
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 10:00:51 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:00:51 +0200
Subject: [PATCH] more ata patches
Message-ID: <1371736854-7543-1-git-send-email-s.hauer@pengutronix.de>

Another attempt to implement the detect callback for the imx pata
hardware device. I had to drop the previous attempt as it turned
out to be incompatible with ahci.

Sascha

----------------------------------------------------------------
Sascha Hauer (3):
      ata: ide: embed ata_ioports into struct ide_port and export it
      ata: pata-imx: implement detect callback for hardware device
      ata: Make 'already initialized' a debug message

 drivers/ata/disk_ata_drive.c    |  2 +-
 drivers/ata/ide-sff.c           | 60 ++++++++++++++++-------------------------
 drivers/ata/intf_platform_ide.c | 14 +++++-----
 drivers/ata/pata-imx.c          | 23 ++++++++++++----
 include/ata_drive.h             |  7 ++++-
 5 files changed, 55 insertions(+), 51 deletions(-)


From s.hauer at pengutronix.de  Thu Jun 20 10:00:52 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:00:52 +0200
Subject: [PATCH 1/3] ata: ide: embed ata_ioports into struct ide_port and
 export it
In-Reply-To: <1371736854-7543-1-git-send-email-s.hauer@pengutronix.de>
References: <1371736854-7543-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371736854-7543-2-git-send-email-s.hauer@pengutronix.de>

Embedding struct ata_ioports into struct ide_port saves us an allocation.
Making it available to client drivers is necessary to give them access
to struct ata_port which is needed in the next patch.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/ata/ide-sff.c           | 60 ++++++++++++++++-------------------------
 drivers/ata/intf_platform_ide.c | 14 +++++-----
 drivers/ata/pata-imx.c          | 13 +++++----
 include/ata_drive.h             |  7 ++++-
 4 files changed, 44 insertions(+), 50 deletions(-)

diff --git a/drivers/ata/ide-sff.c b/drivers/ata/ide-sff.c
index ef55357..0e8b744 100644
--- a/drivers/ata/ide-sff.c
+++ b/drivers/ata/ide-sff.c
@@ -8,14 +8,6 @@
 /* max timeout for a rotating disk in [ms] */
 #define MAX_TIMEOUT 5000
 
-/**
- * Collection of data we need to know about this drive
- */
-struct ide_port {
-	struct ata_ioports *io;	/**< register file */
-	struct ata_port port;
-};
-
 #define to_ata_drive_access(x) container_of((x), struct ide_port, port)
 
 #define DISK_MASTER 0
@@ -28,7 +20,7 @@ struct ide_port {
  */
 static uint8_t ata_rd_status(struct ide_port *ide)
 {
-	return readb(ide->io->status_addr);
+	return readb(ide->io.status_addr);
 }
 
 /**
@@ -90,12 +82,12 @@ static int ata_set_lba_sector(struct ide_port *ide, unsigned drive, uint64_t num
 	if (num > 0x0FFFFFFF || drive > 1)
 		return -EINVAL;
 
-	writeb(0xA0 | LBA_FLAG | drive << 4 | num >> 24, ide->io->device_addr);
-	writeb(0x00, ide->io->error_addr);
-	writeb(0x01, ide->io->nsect_addr);
-	writeb(num, ide->io->lbal_addr);	/* 0 ... 7 */
-	writeb(num >> 8, ide->io->lbam_addr); /* 8 ... 15 */
-	writeb(num >> 16, ide->io->lbah_addr); /* 16 ... 23 */
+	writeb(0xA0 | LBA_FLAG | drive << 4 | num >> 24, ide->io.device_addr);
+	writeb(0x00, ide->io.error_addr);
+	writeb(0x01, ide->io.nsect_addr);
+	writeb(num, ide->io.lbal_addr);	/* 0 ... 7 */
+	writeb(num >> 8, ide->io.lbam_addr); /* 8 ... 15 */
+	writeb(num >> 16, ide->io.lbah_addr); /* 16 ... 23 */
 
 	return 0;
 }
@@ -114,7 +106,7 @@ static int ata_wr_cmd(struct ide_port *ide, uint8_t cmd)
 	if (rc != 0)
 		return rc;
 
-	writeb(cmd, ide->io->command_addr);
+	writeb(cmd, ide->io.command_addr);
 	return 0;
 }
 
@@ -125,7 +117,7 @@ static int ata_wr_cmd(struct ide_port *ide, uint8_t cmd)
  */
 static void ata_wr_dev_ctrl(struct ide_port *ide, uint8_t val)
 {
-	writeb(val, ide->io->ctl_addr);
+	writeb(val, ide->io.ctl_addr);
 }
 
 /**
@@ -138,12 +130,12 @@ static void ata_rd_sector(struct ide_port *ide, void *buf)
 	unsigned u = SECTOR_SIZE / sizeof(uint16_t);
 	uint16_t *b = buf;
 
-	if (ide->io->dataif_be) {
+	if (ide->io.dataif_be) {
 		for (; u > 0; u--)
-			*b++ = be16_to_cpu(readw(ide->io->data_addr));
+			*b++ = be16_to_cpu(readw(ide->io.data_addr));
 	} else {
 		for (; u > 0; u--)
-			*b++ = le16_to_cpu(readw(ide->io->data_addr));
+			*b++ = le16_to_cpu(readw(ide->io.data_addr));
 	}
 }
 
@@ -157,12 +149,12 @@ static void ata_wr_sector(struct ide_port *ide, const void *buf)
 	unsigned u = SECTOR_SIZE / sizeof(uint16_t);
 	const uint16_t *b = buf;
 
-	if (ide->io->dataif_be) {
+	if (ide->io.dataif_be) {
 		for (; u > 0; u--)
-			writew(cpu_to_be16(*b++), ide->io->data_addr);
+			writew(cpu_to_be16(*b++), ide->io.data_addr);
 	} else {
 		for (; u > 0; u--)
-			writew(cpu_to_le16(*b++), ide->io->data_addr);
+			writew(cpu_to_le16(*b++), ide->io.data_addr);
 	}
 }
 
@@ -176,10 +168,10 @@ static int ide_read_id(struct ata_port *port, void *buf)
 	struct ide_port *ide = to_ata_drive_access(port);
 	int rc;
 
-	writeb(0xA0, ide->io->device_addr);	/* FIXME drive */
-	writeb(0x00, ide->io->lbal_addr);
-	writeb(0x00, ide->io->lbam_addr);
-	writeb(0x00, ide->io->lbah_addr);
+	writeb(0xA0, ide->io.device_addr);	/* FIXME drive */
+	writeb(0x00, ide->io.lbal_addr);
+	writeb(0x00, ide->io.lbam_addr);
+	writeb(0x00, ide->io.lbah_addr);
 
 	rc = ata_wr_cmd(ide, ATA_CMD_ID_ATA);
 	if (rc != 0)
@@ -201,11 +193,11 @@ static int ide_reset(struct ata_port *port)
 	uint8_t reg;
 
 	/* try a hard reset first (if available) */
-	if (ide->io->reset != NULL) {
+	if (ide->io.reset != NULL) {
 		pr_debug("%s: Resetting drive...\n", __func__);
-		ide->io->reset(1);
+		ide->io.reset(1);
 		rc = ata_wait_busy(ide, 500);
-		ide->io->reset(0);
+		ide->io.reset(0);
 		if (rc == 0) {
 			rc = ata_wait_ready(ide, MAX_TIMEOUT);
 			if (rc != 0)
@@ -324,17 +316,11 @@ static struct ata_port_operations ide_ops = {
 	.reset = ide_reset,
 };
 
-int ide_port_register(struct device_d *dev, struct ata_ioports *io, const char *devname)
+int ide_port_register(struct ide_port *ide)
 {
-	struct ide_port *ide;
 	int ret;
 
-	ide = xzalloc(sizeof(*ide));
-
-	ide->io = io;
 	ide->port.ops = &ide_ops;
-	ide->port.dev = dev;
-	ide->port.devname = devname;
 
 	ret = ata_port_register(&ide->port);
 
diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
index 455ac28..8ae0f05 100644
--- a/drivers/ata/intf_platform_ide.c
+++ b/drivers/ata/intf_platform_ide.c
@@ -80,7 +80,7 @@ static int platform_ide_probe(struct device_d *dev)
 {
 	int rc;
 	struct ide_port_info *pdata = dev->platform_data;
-	struct ata_ioports *io;
+	struct ide_port *ide;
 	void *reg_base, *alt_base;
 
 	if (pdata == NULL) {
@@ -88,17 +88,17 @@ static int platform_ide_probe(struct device_d *dev)
 		return -EINVAL;
 	}
 
-	io = xzalloc(sizeof(struct ata_ioports));
+	ide = xzalloc(sizeof(*ide));
 	reg_base = dev_request_mem_region(dev, 0);
 	alt_base = dev_request_mem_region(dev, 1);
-	platform_ide_setup_port(reg_base, alt_base, io, pdata->ioport_shift);
-	io->reset = pdata->reset;
-	io->dataif_be = pdata->dataif_be;
+	platform_ide_setup_port(reg_base, alt_base, &ide->io, pdata->ioport_shift);
+	ide->io.reset = pdata->reset;
+	ide->io.dataif_be = pdata->dataif_be;
 
-	rc = ide_port_register(dev, io, NULL);
+	rc = ide_port_register(ide);
 	if (rc != 0) {
 		dev_err(dev, "Cannot register IDE interface\n");
-		free(io);
+		free(ide);
 	}
 
 	return rc;
diff --git a/drivers/ata/pata-imx.c b/drivers/ata/pata-imx.c
index 78f2aa5..aed6df1 100644
--- a/drivers/ata/pata-imx.c
+++ b/drivers/ata/pata-imx.c
@@ -148,13 +148,13 @@ static void imx_pata_setup_port(void *reg_base, void *alt_base,
 
 static int imx_pata_probe(struct device_d *dev)
 {
-	struct ata_ioports *io;
+	struct ide_port *ide;
 	struct clk *clk;
 	void __iomem *base;
 	int ret;
 	const char *devname = NULL;
 
-	io = xzalloc(sizeof(struct ata_ioports));
+	ide = xzalloc(sizeof(*ide));
 	base = dev_request_mem_region(dev, 0);
 
 	clk = clk_get(dev, NULL);
@@ -164,7 +164,7 @@ static int imx_pata_probe(struct device_d *dev)
 	}
 
 	imx_pata_setup_port(base + PATA_IMX_DRIVE_DATA,
-			base + PATA_IMX_DRIVE_CONTROL, io, 2);
+			base + PATA_IMX_DRIVE_CONTROL, &ide->io, 2);
 
 	/* deassert resets */
 	writel(PATA_IMX_ATA_CTRL_FIFO_RST_B |
@@ -179,7 +179,10 @@ static int imx_pata_probe(struct device_d *dev)
 			devname = xstrdup(devname);
 	}
 
-	ret = ide_port_register(dev, io, devname);
+	ide->port.dev = dev;
+	ide->port.devname = devname;
+
+	ret = ide_port_register(ide);
 	if (ret) {
 		dev_err(dev, "Cannot register IDE interface: %s\n",
 				strerror(-ret));
@@ -192,7 +195,7 @@ out_free_clk:
 	clk_put(clk);
 
 out_free:
-	free(io);
+	free(ide);
 
 	return ret;
 }
diff --git a/include/ata_drive.h b/include/ata_drive.h
index 818247a..6d6cca4 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -143,7 +143,12 @@ struct ata_port {
 	int probe;
 };
 
-int ide_port_register(struct device_d *, struct ata_ioports *, const char *);
+struct ide_port {
+	struct ata_ioports io;	/**< register file */
+	struct ata_port port;
+};
+
+int ide_port_register(struct ide_port *ide);
 int ata_port_register(struct ata_port *port);
 int ata_port_detect(struct ata_port *port);
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 10:05:25 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:05:25 +0200
Subject: [PATCH 4/4] usb: ehci: implement detect callback
In-Reply-To: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>
References: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371737125-18820-5-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/host/ehci-hcd.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 7c389aa..840aa1a 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -847,6 +847,13 @@ submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
 	return -1;
 }
 
+static int ehci_detect(struct device_d *dev)
+{
+	struct ehci_priv *ehci = dev->priv;
+
+	return usb_host_detect(&ehci->host, 0);
+}
+
 int ehci_register(struct device_d *dev, struct ehci_data *data)
 {
 	struct usb_host *host;
@@ -882,6 +889,8 @@ int ehci_register(struct device_d *dev, struct ehci_data *data)
 		ehci_reset(ehci);
 	}
 
+	dev->detect = ehci_detect;
+
 	usb_register_host(host);
 
 	reg = HC_VERSION(ehci_readl(&ehci->hccr->cr_capbase));
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 10:05:21 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:05:21 +0200
Subject: [PATCH] usb: implement detect callback
Message-ID: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>


The following prepares to implement the detect callback for USB
and finally implements it in the ehci driver.

With this series all frameworks in barebox supporting on-demand-probing
support the new 'detect' command.

Sascha

----------------------------------------------------------------
Sascha Hauer (4):
      usb: rename USB devices to reflect bus structure
      usb: move scanned status into core
      usb: implement a usb_host_detect to scan individual USB hosts
      usb: ehci: implement detect callback

 commands/usb.c              | 10 +++-------
 drivers/usb/core/usb.c      | 47 +++++++++++++++++++++++++++++++++++----------
 drivers/usb/host/ehci-hcd.c |  9 +++++++++
 include/usb/usb.h           |  5 ++++-
 4 files changed, 53 insertions(+), 18 deletions(-)


From s.hauer at pengutronix.de  Thu Jun 20 10:05:22 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:05:22 +0200
Subject: [PATCH 1/4] usb: rename USB devices to reflect bus structure
In-Reply-To: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>
References: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371737125-18820-2-git-send-email-s.hauer@pengutronix.de>

This renames the USB devices to reflect the bus structure.
The base name for a USB device is usb<devno>. For each child
device we add a -<parent-port-no>. This makes it more easy
to identify devices.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/core/usb.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 9a0723a..e232111 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -431,14 +431,22 @@ static int usb_new_device(struct usb_device *dev)
 	if (dev->descriptor->iSerialNumber)
 		usb_string(dev, dev->descriptor->iSerialNumber,
 			   dev->serial, sizeof(dev->serial));
+
+	if (parent) {
+		sprintf(dev->dev.name, "%s-%d", parent->dev.name, port);
+	} else {
+		sprintf(dev->dev.name, "usb%d", dev->host->busnum);
+	}
+
+	dev->dev.id = DEVICE_ID_SINGLE;
+
+	register_device(&dev->dev);
+
 	/* now prode if the device is a hub */
 	usb_hub_probe(dev, 0);
 
-	sprintf(dev->dev.name, "usb%d-%d", dev->host->busnum, dev->devnum);
-
 	print_usb_device(dev);
 
-	register_device(&dev->dev);
 	dev_add_param_int_ro(&dev->dev, "iManufacturer",
 			dev->descriptor->iManufacturer, "%d");
 	dev_add_param_int_ro(&dev->dev, "iProduct",
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 10:05:24 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:05:24 +0200
Subject: [PATCH 3/4] usb: implement a usb_host_detect to scan individual USB
 hosts
In-Reply-To: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>
References: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371737125-18820-4-git-send-email-s.hauer@pengutronix.de>

Currently we can only (re)scan all USB hosts. Add a function to
scan individual hosts. This is useful for implementing the detect
callback in the next patch.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/core/usb.c | 38 +++++++++++++++++++++++++-------------
 include/usb/usb.h      |  3 +++
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 07175dc..36fc736 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -488,20 +488,18 @@ static struct usb_device *usb_alloc_new_device(void)
 	return usbdev;
 }
 
-static int scanned;
-
-void usb_rescan(int force)
+int usb_host_detect(struct usb_host *host, int force)
 {
 	struct usb_device *dev, *tmp;
-	struct usb_host *host;
 	int ret;
 
-	if (scanned && !force)
-		return;
-
-	scanned = 1;
+	if (host->scanned && !force)
+		return -EBUSY;
 
 	list_for_each_entry_safe(dev, tmp, &usb_device_list, list) {
+		if (dev->host != host)
+			continue;
+
 		list_del(&dev->list);
 		unregister_device(&dev->dev);
 		if (dev->hub)
@@ -511,17 +509,31 @@ void usb_rescan(int force)
 		free(dev);
 	}
 
+	ret = host->init(host);
+	if (ret)
+		return ret;
+
+	dev = usb_alloc_new_device();
+	dev->host = host;
+	usb_new_device(dev);
+
+	host->scanned = 1;
+
+	return 0;
+}
+
+void usb_rescan(int force)
+{
+	struct usb_host *host;
+	int ret;
+
 	printf("USB: scanning bus for devices...\n");
 	dev_index = 0;
 
 	list_for_each_entry(host, &host_list, list) {
-		ret = host->init(host);
+		ret = usb_host_detect(host, force);
 		if (ret)
 			continue;
-
-		dev = usb_alloc_new_device();
-		dev->host = host;
-		usb_new_device(dev);
 	}
 
 	printf("%d USB Device(s) found\n", dev_index);
diff --git a/include/usb/usb.h b/include/usb/usb.h
index 2e1498c..95fb6f3 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -211,10 +211,13 @@ struct usb_host {
 	struct list_head list;
 
 	int busnum;
+	int scanned;
 };
 
 int usb_register_host(struct usb_host *);
 
+int usb_host_detect(struct usb_host *host, int force);
+
 /* Defines */
 #define USB_UHCI_VEND_ID	0x8086
 #define USB_UHCI_DEV_ID		0x7112
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 10:05:23 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:05:23 +0200
Subject: [PATCH 2/4] usb: move scanned status into core
In-Reply-To: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>
References: <1371737125-18820-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1371737125-18820-3-git-send-email-s.hauer@pengutronix.de>

A command should not be interested in the internal USB core state, so
move the state handling into the core.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/usb.c         | 10 +++-------
 drivers/usb/core/usb.c |  9 ++++++++-
 include/usb/usb.h      |  2 +-
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/commands/usb.c b/commands/usb.c
index e503065..9aee430 100644
--- a/commands/usb.c
+++ b/commands/usb.c
@@ -22,24 +22,20 @@
 #include <usb/usb.h>
 #include <getopt.h>
 
-static int scanned;
-
 static int do_usb(int argc, char *argv[])
 {
 	int opt;
+	int force = 0;
 
 	while ((opt = getopt(argc, argv, "f")) > 0) {
 		switch (opt) {
 		case 'f':
-			scanned = 0;
+			force = 1;
 			break;
 		}
 	}
 
-	if (!scanned) {
-		usb_rescan();
-		scanned = 1;
-	}
+	usb_rescan(force);
 
 	return 0;
 }
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index e232111..07175dc 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -488,12 +488,19 @@ static struct usb_device *usb_alloc_new_device(void)
 	return usbdev;
 }
 
-void usb_rescan(void)
+static int scanned;
+
+void usb_rescan(int force)
 {
 	struct usb_device *dev, *tmp;
 	struct usb_host *host;
 	int ret;
 
+	if (scanned && !force)
+		return;
+
+	scanned = 1;
+
 	list_for_each_entry_safe(dev, tmp, &usb_device_list, list) {
 		list_del(&dev->list);
 		unregister_device(&dev->dev);
diff --git a/include/usb/usb.h b/include/usb/usb.h
index da0090e..2e1498c 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -248,7 +248,7 @@ int usb_clear_halt(struct usb_device *dev, int pipe);
 int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
 int usb_set_interface(struct usb_device *dev, int interface, int alternate);
 
-void usb_rescan(void);
+void usb_rescan(int force);
 
 /* big endian -> little endian conversion */
 /* some CPUs are already little endian e.g. the ARM920T */
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 10:06:05 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 16:06:05 +0200
Subject: [PATCH] detect command: Add -a option to detect all devices
Message-ID: <1371737165-1313-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/detect.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/commands/detect.c b/commands/detect.c
index 0010a17..fbce4eb 100644
--- a/commands/detect.c
+++ b/commands/detect.c
@@ -28,8 +28,9 @@ static int do_detect(int argc, char *argv[])
 	int opt, i, ret;
 	int option_list = 0;
 	int option_error = 0;
+	int option_all = 0;
 
-	while ((opt = getopt(argc, argv, "el")) > 0) {
+	while ((opt = getopt(argc, argv, "ela")) > 0) {
 		switch (opt) {
 		case 'l':
 			option_list = 1;
@@ -37,6 +38,11 @@ static int do_detect(int argc, char *argv[])
 		case 'e':
 			option_error = 1;
 			break;
+		case 'a':
+			option_all = 1;
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
 		}
 	}
 
@@ -48,6 +54,15 @@ static int do_detect(int argc, char *argv[])
 		return 0;
 	}
 
+	if (option_all) {
+		for_each_device(dev) {
+			ret = device_detect(dev);
+			if (ret && ret != -ENOSYS && option_error)
+				return ret;
+		}
+		return 0;
+	}
+
 	if (argc == optind)
 		return COMMAND_ERROR_USAGE;
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Thu Jun 20 11:24:28 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 20 Jun 2013 17:24:28 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <1371726931.3466.3.camel@lws-weitzel>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
 <1371726931.3466.3.camel@lws-weitzel>
Message-ID: <20130620152428.GU32299@pengutronix.de>

On Thu, Jun 20, 2013 at 01:15:31PM +0200, Jan Weitzel wrote:
> Am Mittwoch, den 19.06.2013, 22:58 +0200 schrieb Sascha Hauer:
> > Some tftp servers (for example netkit-tftp) do not pass the filesize.
> > Add a workaround for read_file which reads the file into a temporary
> > file which then is copied to a buffer.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  fs/fs.c      | 18 ++++++++++++++++++
> >  fs/tftp.c    |  5 ++++-
> >  include/fs.h |  2 ++
> >  3 files changed, 24 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/fs.c b/fs/fs.c
> > index dc3a6e3..7046f2c 100644
> > --- a/fs/fs.c
> > +++ b/fs/fs.c
> > @@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size)
> >  	int fd;
> >  	struct stat s;
> >  	void *buf = NULL;
> > +	const char *tmpfile = "/.read_file_tmp";
> > +	int ret;
> >  
> > +again:
> >  	if (stat(filename, &s))
> >  		return NULL;
> >  
> > +	if (s.st_size == FILESIZE_MAX) {
> > +		ret = copy_file(filename, tmpfile, 0);
> > +		if (ret)
> > +			return NULL;
> > +		filename = tmpfile;
> > +		goto again;
> > +	}
> > +
> >  	buf = xzalloc(s.st_size + 1);
> >  
> >  	fd = open(filename, O_RDONLY);
> > @@ -56,12 +67,19 @@ void *read_file(const char *filename, size_t *size)
> >  	if (size)
> >  		*size = s.st_size;
> >  
> > +	if (filename == tmpfile)
> > +		unlink(tmpfile);
> > +
> >  	return buf;
> >  
> >  err_out1:
> >  	close(fd);
> >  err_out:
> >  	free(buf);
> > +
> > +	if (filename == tmpfile)
> > +		unlink(tmpfile);
> > +
> >  	return NULL;
> >  }
> >  
> > diff --git a/fs/tftp.c b/fs/tftp.c
> > index 98cbb37..1c37acf 100644
> > --- a/fs/tftp.c
> > +++ b/fs/tftp.c
> > @@ -597,7 +597,10 @@ static int tftp_stat(struct device_d *dev, const char *filename, struct stat *s)
> >  		return PTR_ERR(priv);
> >  
> >  	s->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
> > -	s->st_size = priv->filesize;
> > +	if (priv->filesize)
> > +		s->st_size = priv->filesize;
> > +	else
> > +		s->st_size = FILESIZE_MAX;
> Maybe we can determine the size here? Commands like "ls -l" and
> "ubiformat" asks about the filesize via stat. I'm not sure how much
> overheat it will be.

How do you want to do that? You would have to transfer the whole file
first and see how big it is. That works for small files we expect to fit
into memory like the ones read_file normally is called with. If you want
to transfer a rootfs image it might happen that it's bigger than the
available memory.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Fri Jun 21 01:30:17 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 21 Jun 2013 07:30:17 +0200
Subject: [PATCH 0/8] low level initialisation for ar2313
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <20130621053017.GW32299@pengutronix.de>

Hi Oleksij, Antony,

I'm fine with this series. Antony, do you have comments?

Sascha

On Wed, Jun 19, 2013 at 11:11:25AM +0200, Oleksij Rempel wrote:
> this patch set add low level initialisation for Atheros ar2313
> and board based on this chip - Netgear wg102.
> 
> Antony Pavlov (2):
>   MIPS: pbl: add mips_barebox_10h asm macro
>   MIPS: mach-ar231x: enable DEBUG_LL
> 
> Oleksij Rempel (6):
>   MIPS: pbl: add pbl_sleep macro
>   MIPS: pbl: add pbl_probe_mem macro
>   MIPS: mach-ar231x: add lowlevel init pbl macros
>   MIPS: netgear-wg102: add pbl support
>   MIPS: netgear-wg102: add debug_ll
>   netgear-wg102: pbl, add extra check for mem config
> 
>  arch/mips/Kconfig                                  |   1 +
>  .../netgear-wg102/include/board/board_pbl_start.h  |  77 +++++++++
>  .../boards/netgear-wg102/include/board/debug_ll.h  |  33 ++++
>  arch/mips/include/asm/pbl_macros.h                 |  38 +++++
>  arch/mips/mach-ar231x/Kconfig                      |   2 +
>  arch/mips/mach-ar231x/include/mach/debug_ll.h      |  27 ++++
>  arch/mips/mach-ar231x/include/mach/pbl_macros.h    | 177 +++++++++++++++++++++
>  7 files changed, 355 insertions(+)
>  create mode 100644 arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
>  create mode 100644 arch/mips/boards/netgear-wg102/include/board/debug_ll.h
>  create mode 100644 arch/mips/mach-ar231x/include/mach/debug_ll.h
>  create mode 100644 arch/mips/mach-ar231x/include/mach/pbl_macros.h
> 
> -- 
> 1.8.1.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Fri Jun 21 01:39:56 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 21 Jun 2013 07:39:56 +0200
Subject: [PATCH 2/3] ARM: AM33xx: Add i2c support for AM33xx
In-Reply-To: <1371732630-27966-3-git-send-email-t.gamez@phytec.de>
References: <1371732630-27966-1-git-send-email-t.gamez@phytec.de>
 <1371732630-27966-3-git-send-email-t.gamez@phytec.de>
Message-ID: <20130621053956.GX32299@pengutronix.de>

Hi Teresa,

On Thu, Jun 20, 2013 at 02:50:29PM +0200, Teresa G?mez wrote:
>  static void omap_i2c_unidle(struct omap_i2c_struct *i2c_omap)
>  {
> -	if (cpu_is_omap34xx()) {
> +	if (cpu_is_omap34xx() || cpu_is_am33xx()) {

Applied for now, but please consider converting this driver to use
id_table and a sane set of driver data. All these cpu_is_* do not scale
anymore for this driver.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From antonynpavlov at gmail.com  Fri Jun 21 02:25:25 2013
From: antonynpavlov at gmail.com (antonynpavlov at gmail.com)
Date: Fri, 21 Jun 2013 10:25:25 +0400
Subject: [PATCH 0/8] low level initialisation for ar2313
In-Reply-To: <20130621053017.GW32299@pengutronix.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
 <20130621053017.GW32299@pengutronix.de>
Message-ID: <20130621102525.8cdf578379630c9ff8d6052a@gmail.com>

On Fri, 21 Jun 2013 07:30:17 +0200
Sascha Hauer <s.hauer at pengutronix.de> wrote:

> Hi Oleksij, Antony,
> 
> I'm fine with this series. Antony, do you have comments?

The series looks good!

But in the last minute I made a small fix for the "MIPS: pbl: add pbl_sleep macro" patch.

It's a shame, but generated label inside assembly macros are not "local" (at least I have not found how to make them local in my toolchain). 

As the user of the pbl_sleep can use generated label "1" (this label already used in pbl_sleep), there can be some painful side effects, e.g. 

1:                    // user's generated label

   ...                // some user code

   pbl_sleep t1 100

   ...                // another user code

   b 1b               // jump to the back label "1"


Inside the pbl_sleep macro we have one more "1" label, so the jump instruction of the
example transfer control not to the user's label "1" but to label "1" inside pbl_sleep. 

So I propose a ad-hoc solution.

--- a/arch/mips/include/asm/pbl_macros.h
+++ b/arch/mips/include/asm/pbl_macros.h
@@ -32,8 +32,8 @@
        .set push
        .set noreorder
        li      \reg, \count
-1:
-       bgtz    \reg, 1b
+254:
+       bgtz    \reg, 254b
         addi   \reg, -1
        .set    pop
        .endm

The programmers are lazy (at least many of them), they like short names "1", "2"
and "254" is very long name, so the conflict is not expected.
To prevent conflicts like this we can make a convention "don't use generated labels 200-255 in you assembler pbl code". 

Is there a need for series/patch reposting for fixing the issue?

> On Wed, Jun 19, 2013 at 11:11:25AM +0200, Oleksij Rempel wrote:
> > this patch set add low level initialisation for Atheros ar2313
> > and board based on this chip - Netgear wg102.
> > 
> > Antony Pavlov (2):
> >   MIPS: pbl: add mips_barebox_10h asm macro
> >   MIPS: mach-ar231x: enable DEBUG_LL
> > 
> > Oleksij Rempel (6):
> >   MIPS: pbl: add pbl_sleep macro
> >   MIPS: pbl: add pbl_probe_mem macro
> >   MIPS: mach-ar231x: add lowlevel init pbl macros
> >   MIPS: netgear-wg102: add pbl support
> >   MIPS: netgear-wg102: add debug_ll
> >   netgear-wg102: pbl, add extra check for mem config
> > 
> >  arch/mips/Kconfig                                  |   1 +
> >  .../netgear-wg102/include/board/board_pbl_start.h  |  77 +++++++++
> >  .../boards/netgear-wg102/include/board/debug_ll.h  |  33 ++++
> >  arch/mips/include/asm/pbl_macros.h                 |  38 +++++
> >  arch/mips/mach-ar231x/Kconfig                      |   2 +
> >  arch/mips/mach-ar231x/include/mach/debug_ll.h      |  27 ++++
> >  arch/mips/mach-ar231x/include/mach/pbl_macros.h    | 177 +++++++++++++++++++++
> >  7 files changed, 355 insertions(+)
> >  create mode 100644 arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
> >  create mode 100644 arch/mips/boards/netgear-wg102/include/board/debug_ll.h
> >  create mode 100644 arch/mips/mach-ar231x/include/mach/debug_ll.h
> >  create mode 100644 arch/mips/mach-ar231x/include/mach/pbl_macros.h
> > 
> > -- 
> > 1.8.1.2
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


-- 
--?
Best regards,
? Antony Pavlov


From linux at rempel-privat.de  Fri Jun 21 02:44:56 2013
From: linux at rempel-privat.de (Oleksij Rempel)
Date: Fri, 21 Jun 2013 08:44:56 +0200
Subject: [PATCH 2/8 v2] MIPS: pbl: add pbl_sleep macro
In-Reply-To: <1371633093-23179-3-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-3-git-send-email-linux@rempel-privat.de>
Message-ID: <1371797096-11927-1-git-send-email-linux@rempel-privat.de>

Signed-off-by: Oleksij Rempel <linux at rempel-privat.de>
---
 arch/mips/include/asm/pbl_macros.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/mips/include/asm/pbl_macros.h b/arch/mips/include/asm/pbl_macros.h
index a3f970c..fde9434 100644
--- a/arch/mips/include/asm/pbl_macros.h
+++ b/arch/mips/include/asm/pbl_macros.h
@@ -28,6 +28,16 @@
 #include <generated/compile.h>
 #include <generated/utsrelease.h>
 
+	.macro	pbl_sleep reg count
+	.set push
+	.set noreorder
+	li	\reg, \count
+254:
+	bgtz	\reg, 254b
+	 addi	\reg, -1
+	.set	pop
+	.endm
+
 	/*
 	 * ADR macro instruction (inspired by ARM)
 	 *
-- 
1.8.1.2



From J.Weitzel at phytec.de  Fri Jun 21 03:03:31 2013
From: J.Weitzel at phytec.de (Jan Weitzel)
Date: Fri, 21 Jun 2013 09:03:31 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <20130620152428.GU32299@pengutronix.de>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
 <1371726931.3466.3.camel@lws-weitzel>
 <20130620152428.GU32299@pengutronix.de>
Message-ID: <1371798211.2957.6.camel@lws-weitzel>

Am Donnerstag, den 20.06.2013, 17:24 +0200 schrieb Sascha Hauer:
> On Thu, Jun 20, 2013 at 01:15:31PM +0200, Jan Weitzel wrote:
> > Am Mittwoch, den 19.06.2013, 22:58 +0200 schrieb Sascha Hauer:
> > > Some tftp servers (for example netkit-tftp) do not pass the filesize.
> > > Add a workaround for read_file which reads the file into a temporary
> > > file which then is copied to a buffer.
> > > 
> > > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > > ---
> > >  fs/fs.c      | 18 ++++++++++++++++++
> > >  fs/tftp.c    |  5 ++++-
> > >  include/fs.h |  2 ++
> > >  3 files changed, 24 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/fs/fs.c b/fs/fs.c
> > > index dc3a6e3..7046f2c 100644
> > > --- a/fs/fs.c
> > > +++ b/fs/fs.c
> > > @@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size)
> > >  	int fd;
> > >  	struct stat s;
> > >  	void *buf = NULL;
> > > +	const char *tmpfile = "/.read_file_tmp";
> > > +	int ret;
> > >  
> > > +again:
> > >  	if (stat(filename, &s))
> > >  		return NULL;
> > >  
> > > +	if (s.st_size == FILESIZE_MAX) {
> > > +		ret = copy_file(filename, tmpfile, 0);
> > > +		if (ret)
> > > +			return NULL;
> > > +		filename = tmpfile;
> > > +		goto again;
> > > +	}
> > > +
> > >  	buf = xzalloc(s.st_size + 1);
> > >  
> > >  	fd = open(filename, O_RDONLY);
> > > @@ -56,12 +67,19 @@ void *read_file(const char *filename, size_t *size)
> > >  	if (size)
> > >  		*size = s.st_size;
> > >  
> > > +	if (filename == tmpfile)
> > > +		unlink(tmpfile);
> > > +
> > >  	return buf;
> > >  
> > >  err_out1:
> > >  	close(fd);
> > >  err_out:
> > >  	free(buf);
> > > +
> > > +	if (filename == tmpfile)
> > > +		unlink(tmpfile);
> > > +
> > >  	return NULL;
> > >  }
> > >  
> > > diff --git a/fs/tftp.c b/fs/tftp.c
> > > index 98cbb37..1c37acf 100644
> > > --- a/fs/tftp.c
> > > +++ b/fs/tftp.c
> > > @@ -597,7 +597,10 @@ static int tftp_stat(struct device_d *dev, const char *filename, struct stat *s)
> > >  		return PTR_ERR(priv);
> > >  
> > >  	s->st_mode = S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO;
> > > -	s->st_size = priv->filesize;
> > > +	if (priv->filesize)
> > > +		s->st_size = priv->filesize;
> > > +	else
> > > +		s->st_size = FILESIZE_MAX;
> > Maybe we can determine the size here? Commands like "ls -l" and
> > "ubiformat" asks about the filesize via stat. I'm not sure how much
> > overheat it will be.
> 
> How do you want to do that? You would have to transfer the whole file
> first and see how big it is. That works for small files we expect to fit
> into memory like the ones read_file normally is called with. If you want
> to transfer a rootfs image it might happen that it's bigger than the
> available memory.
That's a good point. I didn't see a way for big files. But setting the
st_size to FILESIZE_MAX can cause trouble in other commands. ubiformat
only blames that is doesn't fit to eraseblock boundaries. ll -l shows a
really big size. What do you think about handle it complete in read_file
if size == 0?

Jan
> 
> Sascha
> 




From s.hauer at pengutronix.de  Fri Jun 21 03:10:38 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 21 Jun 2013 09:10:38 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <1371798211.2957.6.camel@lws-weitzel>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
 <1371726931.3466.3.camel@lws-weitzel>
 <20130620152428.GU32299@pengutronix.de>
 <1371798211.2957.6.camel@lws-weitzel>
Message-ID: <20130621071038.GA32299@pengutronix.de>

On Fri, Jun 21, 2013 at 09:03:31AM +0200, Jan Weitzel wrote:
> Am Donnerstag, den 20.06.2013, 17:24 +0200 schrieb Sascha Hauer:
> > 
> > How do you want to do that? You would have to transfer the whole file
> > first and see how big it is. That works for small files we expect to fit
> > into memory like the ones read_file normally is called with. If you want
> > to transfer a rootfs image it might happen that it's bigger than the
> > available memory.
> That's a good point. I didn't see a way for big files. But setting the
> st_size to FILESIZE_MAX can cause trouble in other commands. ubiformat
> only blames that is doesn't fit to eraseblock boundaries.

Have you tried it?

> ll -l shows a
> really big size.

You'll never see this. Listing directories is not implemented in the
tftp protocol.

> What do you think about handle it complete in read_file
> if size == 0?

Maybe. What happens if the file is really 0 bytes big?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Fri Jun 21 03:23:19 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 21 Jun 2013 09:23:19 +0200
Subject: [PATCH 0/8] low level initialisation for ar2313
In-Reply-To: <20130621102525.8cdf578379630c9ff8d6052a@gmail.com>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
 <20130621053017.GW32299@pengutronix.de>
 <20130621102525.8cdf578379630c9ff8d6052a@gmail.com>
Message-ID: <20130621072319.GB32299@pengutronix.de>

On Fri, Jun 21, 2013 at 10:25:25AM +0400, antonynpavlov at gmail.com wrote:
> On Fri, 21 Jun 2013 07:30:17 +0200
> Sascha Hauer <s.hauer at pengutronix.de> wrote:
> 
> > Hi Oleksij, Antony,
> > 
> > I'm fine with this series. Antony, do you have comments?
> 
> The series looks good!
> 
> But in the last minute I made a small fix for the "MIPS: pbl: add pbl_sleep macro" patch.
> 
> It's a shame, but generated label inside assembly macros are not "local" (at least I have not found how to make them local in my toolchain). 
> 
> As the user of the pbl_sleep can use generated label "1" (this label already used in pbl_sleep), there can be some painful side effects, e.g. 
> 
> 1:                    // user's generated label
> 
>    ...                // some user code
> 
>    pbl_sleep t1 100
> 
>    ...                // another user code
> 
>    b 1b               // jump to the back label "1"
> 
> 
> Inside the pbl_sleep macro we have one more "1" label, so the jump instruction of the
> example transfer control not to the user's label "1" but to label "1" inside pbl_sleep. 
> 
> So I propose a ad-hoc solution.
> 
> --- a/arch/mips/include/asm/pbl_macros.h
> +++ b/arch/mips/include/asm/pbl_macros.h
> @@ -32,8 +32,8 @@
>         .set push
>         .set noreorder
>         li      \reg, \count
> -1:
> -       bgtz    \reg, 1b
> +254:
> +       bgtz    \reg, 254b
>          addi   \reg, -1
>         .set    pop
>         .endm

Yeah, I noticed the same problem some time ago and came up with the same
solution. I'm not aware of a better way to do this.

> 
> The programmers are lazy (at least many of them), they like short names "1", "2"
> and "254" is very long name, so the conflict is not expected.
> To prevent conflicts like this we can make a convention "don't use generated labels 200-255 in you assembler pbl code". 
> 
> Is there a need for series/patch reposting for fixing the issue?

Yes, please post what you want me to apply on -next.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From antonynpavlov at gmail.com  Fri Jun 21 03:34:37 2013
From: antonynpavlov at gmail.com (antonynpavlov at gmail.com)
Date: Fri, 21 Jun 2013 11:34:37 +0400
Subject: [PATCH 0/8] low level initialisation for ar2313
In-Reply-To: <20130621072319.GB32299@pengutronix.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
 <20130621053017.GW32299@pengutronix.de>
 <20130621102525.8cdf578379630c9ff8d6052a@gmail.com>
 <20130621072319.GB32299@pengutronix.de>
Message-ID: <20130621113437.e71ee33309f59c91d718fb50@gmail.com>

On Fri, 21 Jun 2013 09:23:19 +0200
Sascha Hauer <s.hauer at pengutronix.de> wrote:

> On Fri, Jun 21, 2013 at 10:25:25AM +0400, antonynpavlov at gmail.com wrote:
> > On Fri, 21 Jun 2013 07:30:17 +0200
> > Sascha Hauer <s.hauer at pengutronix.de> wrote:
> > 
> > > Hi Oleksij, Antony,
> > > 
> > > I'm fine with this series. Antony, do you have comments?
> > 
> > The series looks good!
> > 
> > But in the last minute I made a small fix for the "MIPS: pbl: add pbl_sleep macro" patch.
> > 
> > It's a shame, but generated label inside assembly macros are not "local" (at least I have not found how to make them local in my toolchain). 
> > 
> > As the user of the pbl_sleep can use generated label "1" (this label already used in pbl_sleep), there can be some painful side effects, e.g. 
> > 
> > 1:                    // user's generated label
> > 
> >    ...                // some user code
> > 
> >    pbl_sleep t1 100
> > 
> >    ...                // another user code
> > 
> >    b 1b               // jump to the back label "1"
> > 
> > 
> > Inside the pbl_sleep macro we have one more "1" label, so the jump instruction of the
> > example transfer control not to the user's label "1" but to label "1" inside pbl_sleep. 
> > 
> > So I propose a ad-hoc solution.
> > 
> > --- a/arch/mips/include/asm/pbl_macros.h
> > +++ b/arch/mips/include/asm/pbl_macros.h
> > @@ -32,8 +32,8 @@
> >         .set push
> >         .set noreorder
> >         li      \reg, \count
> > -1:
> > -       bgtz    \reg, 1b
> > +254:
> > +       bgtz    \reg, 254b
> >          addi   \reg, -1
> >         .set    pop
> >         .endm
> 
> Yeah, I noticed the same problem some time ago and came up with the same
> solution. I'm not aware of a better way to do this.
> 
> > 
> > The programmers are lazy (at least many of them), they like short names "1", "2"
> > and "254" is very long name, so the conflict is not expected.
> > To prevent conflicts like this we can make a convention "don't use generated labels 200-255 in you assembler pbl code". 
> > 
> > Is there a need for series/patch reposting for fixing the issue?
> 
> Yes, please post what you want me to apply on -next.

Oleksij have reposted the fixed patch: "[PATCH 2/8 v2] MIPS: pbl: add pbl_sleep macro"

> 
> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


-- 
--?
Best regards,
? Antony Pavlov


From J.Weitzel at phytec.de  Fri Jun 21 03:46:41 2013
From: J.Weitzel at phytec.de (Jan Weitzel)
Date: Fri, 21 Jun 2013 09:46:41 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <20130621071038.GA32299@pengutronix.de>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
 <1371726931.3466.3.camel@lws-weitzel>
 <20130620152428.GU32299@pengutronix.de>
 <1371798211.2957.6.camel@lws-weitzel>
 <20130621071038.GA32299@pengutronix.de>
Message-ID: <1371800801.2957.12.camel@lws-weitzel>

Am Freitag, den 21.06.2013, 09:10 +0200 schrieb Sascha Hauer:
> On Fri, Jun 21, 2013 at 09:03:31AM +0200, Jan Weitzel wrote:
> > Am Donnerstag, den 20.06.2013, 17:24 +0200 schrieb Sascha Hauer:
> > > 
> > > How do you want to do that? You would have to transfer the whole file
> > > first and see how big it is. That works for small files we expect to fit
> > > into memory like the ones read_file normally is called with. If you want
> > > to transfer a rootfs image it might happen that it's bigger than the
> > > available memory.
> > That's a good point. I didn't see a way for big files. But setting the
> > st_size to FILESIZE_MAX can cause trouble in other commands. ubiformat
> > only blames that is doesn't fit to eraseblock boundaries.
> 
> Have you tried it?
Yes, with a v2013.03.0 based barebox. Without the patch ubiformat -f
erase the ubi volume and "writes" a image of size 0.
The patched version stumbles over:

 if (st_size % mtd->eb_size) {
                sys_errmsg("file \"%s\" (size %lld bytes) is not
multiple of "
                           "eraseblock size (%d bytes)",

> 
> > ll -l shows a
> > really big size.
> 
> You'll never see this. Listing directories is not implemented in the
> tftp protocol.
> 
I got this with automount:
barebox at Phytec phyCORE pcm049:/  ls -l /mnt/tftp/weitzel/root.ubi
100Mbps full duplex link detected
T -rwxrwxrwx 4294967295 /mnt/tftp/weitzel/root.ubi

Without the patch it was 
-rwxrwxrwx          0 /mnt/tftp/weitzel/root.ubi

> > What do you think about handle it complete in read_file
> > if size == 0?
> 
> Maybe. What happens if the file is really 0 bytes big?
copy_file and unlinking will be the cost for this special case. We
should avoid a goto again loop ;)

Jan
> 
> Sascha
> 




From s.hauer at pengutronix.de  Fri Jun 21 04:21:30 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 21 Jun 2013 10:21:30 +0200
Subject: [PATCH] read_file: Make it work on tftp servers which do not
 pass size
In-Reply-To: <1371800801.2957.12.camel@lws-weitzel>
References: <1371675528-6380-1-git-send-email-s.hauer@pengutronix.de>
 <1371726931.3466.3.camel@lws-weitzel>
 <20130620152428.GU32299@pengutronix.de>
 <1371798211.2957.6.camel@lws-weitzel>
 <20130621071038.GA32299@pengutronix.de>
 <1371800801.2957.12.camel@lws-weitzel>
Message-ID: <20130621082130.GC32299@pengutronix.de>

On Fri, Jun 21, 2013 at 09:46:41AM +0200, Jan Weitzel wrote:
> Am Freitag, den 21.06.2013, 09:10 +0200 schrieb Sascha Hauer:
> > On Fri, Jun 21, 2013 at 09:03:31AM +0200, Jan Weitzel wrote:
> > > Am Donnerstag, den 20.06.2013, 17:24 +0200 schrieb Sascha Hauer:
> > > > 
> > > > How do you want to do that? You would have to transfer the whole file
> > > > first and see how big it is. That works for small files we expect to fit
> > > > into memory like the ones read_file normally is called with. If you want
> > > > to transfer a rootfs image it might happen that it's bigger than the
> > > > available memory.
> > > That's a good point. I didn't see a way for big files. But setting the
> > > st_size to FILESIZE_MAX can cause trouble in other commands. ubiformat
> > > only blames that is doesn't fit to eraseblock boundaries.
> > 
> > Have you tried it?
> Yes, with a v2013.03.0 based barebox. Without the patch ubiformat -f
> erase the ubi volume and "writes" a image of size 0.

I assume it does so even when the image is not of size 0, right?
That sounds broken.

Aynway, you are beginning to convince me that 0 might be a better
choice.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From j.weitzel at phytec.de  Fri Jun 21 04:24:02 2013
From: j.weitzel at phytec.de (Jan Weitzel)
Date: Fri, 21 Jun 2013 10:24:02 +0200
Subject: [PATCH v2] OMAP4 do not set TPS62361_REG_ADDR_SET0
In-Reply-To: <CAGo_u6pP9djhzUZyOLNewL4kDwcY0A_KW1ZmdHVurCwBUxBEEg@mail.gmail.com>
References: <CAGo_u6pP9djhzUZyOLNewL4kDwcY0A_KW1ZmdHVurCwBUxBEEg@mail.gmail.com>
Message-ID: <1371803042-1179-1-git-send-email-j.weitzel@phytec.de>

Don't set SET0 voltage, because it acts as boot voltage for OPP boot.
Take care that the kernel doesn't drive vset gpio to low. This may
happen while reseting the gpio module at initialization, look for
HWMOD_INIT_NO_RESET.

Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
Reviewed-by: Nishanth Menon <nm at ti.com>
---
on top of 88796b1
v2: add Reviewed-by

 arch/arm/mach-omap/omap4_generic.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-omap/omap4_generic.c b/arch/arm/mach-omap/omap4_generic.c
index 7200393..bf1f1a7 100644
--- a/arch/arm/mach-omap/omap4_generic.c
+++ b/arch/arm/mach-omap/omap4_generic.c
@@ -586,11 +586,10 @@ noinline int omap4460_scale_vcores(unsigned vsel0_pin, unsigned volt_mv)
 	writel(0x6026, OMAP44XX_PRM_VC_CFG_I2C_CLK);
 
 	/* TPS - supplies vdd_mpu on 4460
-	 * Setup SET1 and SET0 with right values so that kernel
-	 * can use either of them based on its needs.
+	 * Setup SET1 and don't touch SET0 it acts as boot voltage
+	 * source after reset.
 	 */
 
-	omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET0, volt_mv);
 	omap4_do_scale_tps62361(TPS62361_REG_ADDR_SET1, volt_mv);
 
 	/*
-- 
1.7.0.4



From s.hauer at pengutronix.de  Fri Jun 21 03:27:02 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 21 Jun 2013 09:27:02 +0200
Subject: [PATCH] kconfig: sync to linux v3.10-rc6
Message-ID: <1371799622-31012-1-git-send-email-s.hauer@pengutronix.de>

This brings us some new features like directly jumping to search results.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 scripts/kconfig/.gitignore                 |    2 -
 scripts/kconfig/Makefile                   |   69 +-
 scripts/kconfig/check.sh                   |    2 +-
 scripts/kconfig/conf.c                     |   66 +-
 scripts/kconfig/confdata.c                 |  188 ++-
 scripts/kconfig/expr.c                     |   10 +-
 scripts/kconfig/expr.h                     |   11 +
 scripts/kconfig/gconf.c                    |   13 +-
 scripts/kconfig/kconfig_load.c             |   35 -
 scripts/kconfig/lex.zconf.c_shipped        | 2430 ----------------------------
 scripts/kconfig/list.h                     |  131 ++
 scripts/kconfig/lkc.h                      |   14 +-
 scripts/kconfig/lkc_proto.h                |    6 +-
 scripts/kconfig/lxdialog/check-lxdialog.sh |   15 +-
 scripts/kconfig/lxdialog/checklist.c       |    4 +
 scripts/kconfig/lxdialog/dialog.h          |   21 +-
 scripts/kconfig/lxdialog/inputbox.c        |  125 +-
 scripts/kconfig/lxdialog/menubox.c         |   33 +-
 scripts/kconfig/lxdialog/textbox.c         |  178 +-
 scripts/kconfig/lxdialog/util.c            |   56 +-
 scripts/kconfig/lxdialog/yesno.c           |    4 +
 scripts/kconfig/mconf.c                    |  270 +++-
 scripts/kconfig/menu.c                     |  103 +-
 scripts/kconfig/merge_config.sh            |  150 ++
 scripts/kconfig/nconf.c                    |  348 ++--
 scripts/kconfig/nconf.gui.c                |   10 +-
 scripts/kconfig/qconf.cc                   |    1 +
 scripts/kconfig/streamline_config.pl       |  293 +++-
 scripts/kconfig/symbol.c                   |   21 +-
 scripts/kconfig/util.c                     |   23 +-
 scripts/kconfig/zconf.l                    |    8 +-
 scripts/kconfig/zconf.lex.c_shipped        |    8 +-
 scripts/kconfig/zconf.tab.c_shipped        |   13 +-
 33 files changed, 1604 insertions(+), 3057 deletions(-)
 delete mode 100644 scripts/kconfig/kconfig_load.c
 delete mode 100644 scripts/kconfig/lex.zconf.c_shipped
 create mode 100644 scripts/kconfig/list.h
 create mode 100755 scripts/kconfig/merge_config.sh

diff --git a/scripts/kconfig/.gitignore b/scripts/kconfig/.gitignore
index 9cd5120..be603c4 100644
--- a/scripts/kconfig/.gitignore
+++ b/scripts/kconfig/.gitignore
@@ -2,13 +2,11 @@
 # Generated files
 #
 config*
-lex.*.c
 *.lex.c
 *.tab.c
 *.tab.h
 zconf.hash.c
 *.moc
-lkc_defs.h
 gconf.glade.h
 *.pot
 *.mo
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index ba573fe..844bc9d 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -11,6 +11,9 @@ else
 Kconfig := Kconfig
 endif
 
+# We need this, in case the user has it in its environment
+unexport CONFIG_
+
 xconfig: $(obj)/qconf
 	$< $(Kconfig)
 
@@ -50,9 +53,8 @@ localyesconfig localmodconfig: $(obj)/streamline_config.pl $(obj)/conf
 
 # Create new linux.pot file
 # Adjust charset to UTF-8 in .po file to accept UTF-8 in Kconfig files
-# The symlink is used to repair a deficiency in arch/um
 update-po-config: $(obj)/kxgettext $(obj)/gconf.glade.h
-	$(Q)echo "  GEN config"
+	$(Q)echo "  GEN     config.pot"
 	$(Q)xgettext --default-domain=linux                         \
 	    --add-comments --keyword=_ --keyword=N_                 \
 	    --from-code=UTF-8                                       \
@@ -60,16 +62,16 @@ update-po-config: $(obj)/kxgettext $(obj)/gconf.glade.h
 	    --directory=$(srctree) --directory=$(objtree)           \
 	    --output $(obj)/config.pot
 	$(Q)sed -i s/CHARSET/UTF-8/ $(obj)/config.pot
-	$(Q)ln -fs Kconfig.x86 arch/um/Kconfig
-	$(Q)(for i in `ls $(srctree)/arch/*/Kconfig`;    \
+	$(Q)(for i in `ls $(srctree)/arch/*/Kconfig      \
+	    $(srctree)/arch/*/um/Kconfig`;               \
 	    do                                           \
-		echo "  GEN $$i";                        \
+		echo "  GEN     $$i";                    \
 		$(obj)/kxgettext $$i                     \
 		     >> $(obj)/config.pot;               \
 	    done )
+	$(Q)echo "  GEN     linux.pot"
 	$(Q)msguniq --sort-by-file --to-code=UTF-8 $(obj)/config.pot \
 	    --output $(obj)/linux.pot
-	$(Q)rm -f $(srctree)/arch/um/Kconfig
 	$(Q)rm -f $(obj)/config.pot
 
 PHONY += allnoconfig allyesconfig allmodconfig alldefconfig randconfig
@@ -77,11 +79,17 @@ PHONY += allnoconfig allyesconfig allmodconfig alldefconfig randconfig
 allnoconfig allyesconfig allmodconfig alldefconfig randconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
-PHONY += listnewconfig oldnoconfig savedefconfig defconfig
+PHONY += listnewconfig olddefconfig oldnoconfig savedefconfig defconfig
 
-listnewconfig oldnoconfig: $(obj)/conf
+listnewconfig olddefconfig: $(obj)/conf
 	$< --$@ $(Kconfig)
 
+# oldnoconfig is an alias of olddefconfig, because people already are dependent
+# on its behavior(sets new symbols to their default value but not 'n') with the
+# counter-intuitive name.
+oldnoconfig: $(obj)/conf
+	$< --olddefconfig $(Kconfig)
+
 savedefconfig: $(obj)/conf
 	$< --$@=defconfig $(Kconfig)
 
@@ -115,7 +123,7 @@ help:
 	@echo  '  alldefconfig    - New config with all symbols set to default'
 	@echo  '  randconfig	  - New config with random answer to all options'
 	@echo  '  listnewconfig   - List new options'
-	@echo  '  oldnoconfig     - Same as silentoldconfig but set new symbols to n (unset)'
+	@echo  '  olddefconfig	  - Same as silentoldconfig but sets new symbols to their default value'
 
 # lxdialog stuff
 check-lxdialog  := $(srctree)/$(src)/lxdialog/check-lxdialog.sh
@@ -211,7 +219,9 @@ HOSTCFLAGS_gconf.o	= `pkg-config --cflags gtk+-2.0 gmodule-2.0 libglade-2.0` \
 
 HOSTLOADLIBES_mconf   = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC))
 
-HOSTLOADLIBES_nconf	= -lmenu -lpanel -lncurses
+HOSTLOADLIBES_nconf	= $(shell \
+				pkg-config --libs menu panel ncurses 2>/dev/null \
+				|| echo "-lmenu -lpanel -lncurses"  )
 $(obj)/qconf.o: $(obj)/.tmp_qtcheck
 
 ifeq ($(qconf-target),1)
@@ -235,12 +245,12 @@ $(obj)/.tmp_qtcheck:
 	        if [ -f $$d/include/qconfig.h ]; then dir=$$d; break; fi; \
 	      done; \
 	      if [ -z "$$dir" ]; then \
-	        echo "*"; \
-	        echo "* Unable to find any QT installation. Please make sure that"; \
-	        echo "* the QT4 or QT3 development package is correctly installed and"; \
-	        echo "* either qmake can be found or install pkg-config or set"; \
-	        echo "* the QTDIR environment variable to the correct location."; \
-	        echo "*"; \
+	        echo >&2 "*"; \
+	        echo >&2 "* Unable to find any QT installation. Please make sure that"; \
+	        echo >&2 "* the QT4 or QT3 development package is correctly installed and"; \
+	        echo >&2 "* either qmake can be found or install pkg-config or set"; \
+	        echo >&2 "* the QTDIR environment variable to the correct location."; \
+	        echo >&2 "*"; \
 	        false; \
 	      fi; \
 	      libpath=$$dir/lib; lib=qt; osdir=""; \
@@ -261,8 +271,8 @@ $(obj)/.tmp_qtcheck:
 	else \
 	  cflags="\$$(shell pkg-config QtCore QtGui Qt3Support --cflags)"; \
 	  libs="\$$(shell pkg-config QtCore QtGui Qt3Support --libs)"; \
-	  binpath="\$$(shell pkg-config QtCore --variable=prefix)"; \
-	  moc="$$binpath/bin/moc"; \
+	  moc="\$$(shell pkg-config QtCore --variable=moc_location)"; \
+	  [ -n "$$moc" ] || moc="\$$(shell pkg-config QtCore --variable=prefix)/bin/moc"; \
 	fi; \
 	echo "KC_QT_CFLAGS=$$cflags" > $@; \
 	echo "KC_QT_LIBS=$$libs" >> $@; \
@@ -280,17 +290,17 @@ $(obj)/.tmp_gtkcheck:
 		if `pkg-config --atleast-version=2.0.0 gtk+-2.0`; then			\
 			touch $@;								\
 		else									\
-			echo "*"; 							\
-			echo "* GTK+ is present but version >= 2.0.0 is required.";	\
-			echo "*";							\
+			echo >&2 "*"; 							\
+			echo >&2 "* GTK+ is present but version >= 2.0.0 is required.";	\
+			echo >&2 "*";							\
 			false;								\
 		fi									\
 	else										\
-		echo "*"; 								\
-		echo "* Unable to find the GTK+ installation. Please make sure that"; 	\
-		echo "* the GTK+ 2.0 development package is correctly installed..."; 	\
-		echo "* You need gtk+-2.0, glib-2.0 and libglade-2.0."; 		\
-		echo "*"; 								\
+		echo >&2 "*"; 								\
+		echo >&2 "* Unable to find the GTK+ installation. Please make sure that"; 	\
+		echo >&2 "* the GTK+ 2.0 development package is correctly installed..."; 	\
+		echo >&2 "* You need gtk+-2.0, glib-2.0 and libglade-2.0."; 		\
+		echo >&2 "*"; 								\
 		false;									\
 	fi
 endif
@@ -299,8 +309,11 @@ $(obj)/zconf.tab.o: $(obj)/zconf.lex.c $(obj)/zconf.hash.c
 
 $(obj)/qconf.o: $(obj)/qconf.moc
 
-$(obj)/%.moc: $(src)/%.h
-	$(KC_QT_MOC) -i $< -o $@
+quiet_cmd_moc = MOC     $@
+      cmd_moc = $(KC_QT_MOC) -i $< -o $@
+
+$(obj)/%.moc: $(src)/%.h $(obj)/.tmp_qtcheck
+	$(call cmd,moc)
 
 # Extract gconf menu items for I18N support
 $(obj)/gconf.glade.h: $(obj)/gconf.glade
diff --git a/scripts/kconfig/check.sh b/scripts/kconfig/check.sh
index fa59cbf..854d9c7 100755
--- a/scripts/kconfig/check.sh
+++ b/scripts/kconfig/check.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Needed for systems without gettext
-$* -xc -o /dev/null - > /dev/null 2>&1 << EOF
+$* -x c -o /dev/null - > /dev/null 2>&1 << EOF
 #include <libintl.h>
 int main()
 {
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index f208f90..bde5b95 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -13,6 +13,7 @@
 #include <getopt.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+#include <errno.h>
 
 #include "lkc.h"
 
@@ -32,10 +33,11 @@ enum input_mode {
 	defconfig,
 	savedefconfig,
 	listnewconfig,
-	oldnoconfig,
+	olddefconfig,
 } input_mode = oldaskconfig;
 
 static int indent = 1;
+static int tty_stdio;
 static int valid_stdin = 1;
 static int sync_kconfig;
 static int conf_cnt;
@@ -108,6 +110,8 @@ static int conf_askvalue(struct symbol *sym, const char *def)
 	case oldaskconfig:
 		fflush(stdout);
 		xfgets(line, 128, stdin);
+		if (!tty_stdio)
+			printf("\n");
 		return 1;
 	default:
 		break;
@@ -365,7 +369,7 @@ static void conf(struct menu *menu)
 		case P_MENU:
 			if ((input_mode == silentoldconfig ||
 			     input_mode == listnewconfig ||
-			     input_mode == oldnoconfig) &&
+			     input_mode == olddefconfig) &&
 			    rootEntry != menu) {
 				check_conf(menu);
 				return;
@@ -429,7 +433,7 @@ static void check_conf(struct menu *menu)
 				if (sym->name && !sym_is_choice_value(sym)) {
 					printf("%s%s\n", CONFIG_, sym->name);
 				}
-			} else if (input_mode != oldnoconfig) {
+			} else if (input_mode != olddefconfig) {
 				if (!conf_cnt++)
 					printf(_("*\n* Restart config...\n*\n"));
 				rootEntry = menu_get_parent_menu(menu);
@@ -454,7 +458,13 @@ static struct option long_opts[] = {
 	{"alldefconfig",    no_argument,       NULL, alldefconfig},
 	{"randconfig",      no_argument,       NULL, randconfig},
 	{"listnewconfig",   no_argument,       NULL, listnewconfig},
-	{"oldnoconfig",     no_argument,       NULL, oldnoconfig},
+	{"olddefconfig",    no_argument,       NULL, olddefconfig},
+	/*
+	 * oldnoconfig is an alias of olddefconfig, because people already
+	 * are dependent on its behavior(sets new symbols to their default
+	 * value but not 'n') with the counter-intuitive name.
+	 */
+	{"oldnoconfig",     no_argument,       NULL, olddefconfig},
 	{NULL, 0, NULL, 0}
 };
 
@@ -467,7 +477,8 @@ static void conf_usage(const char *progname)
 	printf("  --oldaskconfig          Start a new configuration using a line-oriented program\n");
 	printf("  --oldconfig             Update a configuration using a provided .config as base\n");
 	printf("  --silentoldconfig       Same as oldconfig, but quietly, additionally update deps\n");
-	printf("  --oldnoconfig           Same as silentoldconfig but set new symbols to no\n");
+	printf("  --olddefconfig          Same as silentoldconfig but sets new symbols to their default value\n");
+	printf("  --oldnoconfig           An alias of olddefconfig\n");
 	printf("  --defconfig <file>      New config with default defined in <file>\n");
 	printf("  --savedefconfig <file>  Save the minimal current configuration to <file>\n");
 	printf("  --allnoconfig           New config where all options are answered with no\n");
@@ -488,6 +499,8 @@ int main(int ac, char **av)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
+	tty_stdio = isatty(0) && isatty(1) && isatty(2);
+
 	while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
 		input_mode = (enum input_mode)opt;
 		switch (opt) {
@@ -502,14 +515,23 @@ int main(int ac, char **av)
 		{
 			struct timeval now;
 			unsigned int seed;
+			char *seed_env;
 
 			/*
 			 * Use microseconds derived seed,
 			 * compensate for systems where it may be zero
 			 */
 			gettimeofday(&now, NULL);
-
 			seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1));
+
+			seed_env = getenv("KCONFIG_SEED");
+			if( seed_env && *seed_env ) {
+				char *endp;
+				int tmp = (int)strtol(seed_env, &endp, 10);
+				if (*endp == '\0') {
+					seed = tmp;
+				}
+			}
 			srand(seed);
 			break;
 		}
@@ -520,7 +542,7 @@ int main(int ac, char **av)
 		case allmodconfig:
 		case alldefconfig:
 		case listnewconfig:
-		case oldnoconfig:
+		case olddefconfig:
 			break;
 		case '?':
 			conf_usage(progname);
@@ -565,7 +587,7 @@ int main(int ac, char **av)
 	case oldaskconfig:
 	case oldconfig:
 	case listnewconfig:
-	case oldnoconfig:
+	case olddefconfig:
 		conf_read(NULL);
 		break;
 	case allnoconfig:
@@ -574,8 +596,15 @@ int main(int ac, char **av)
 	case alldefconfig:
 	case randconfig:
 		name = getenv("KCONFIG_ALLCONFIG");
-		if (name && !stat(name, &tmpstat)) {
-			conf_read_simple(name, S_DEF_USER);
+		if (!name)
+			break;
+		if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) {
+			if (conf_read_simple(name, S_DEF_USER)) {
+				fprintf(stderr,
+					_("*** Can't read seed configuration \"%s\"!\n"),
+					name);
+				exit(1);
+			}
 			break;
 		}
 		switch (input_mode) {
@@ -586,10 +615,13 @@ int main(int ac, char **av)
 		case randconfig:	name = "allrandom.config"; break;
 		default: break;
 		}
-		if (!stat(name, &tmpstat))
-			conf_read_simple(name, S_DEF_USER);
-		else if (!stat("all.config", &tmpstat))
-			conf_read_simple("all.config", S_DEF_USER);
+		if (conf_read_simple(name, S_DEF_USER) &&
+		    conf_read_simple("all.config", S_DEF_USER)) {
+			fprintf(stderr,
+				_("*** KCONFIG_ALLCONFIG set, but no \"%s\" or \"all.config\" file found\n"),
+				name);
+			exit(1);
+		}
 		break;
 	default:
 		break;
@@ -604,7 +636,7 @@ int main(int ac, char **av)
 				return 1;
 			}
 		}
-		valid_stdin = isatty(0) && isatty(1) && isatty(2);
+		valid_stdin = tty_stdio;
 	}
 
 	switch (input_mode) {
@@ -635,7 +667,7 @@ int main(int ac, char **av)
 		/* fall through */
 	case oldconfig:
 	case listnewconfig:
-	case oldnoconfig:
+	case olddefconfig:
 	case silentoldconfig:
 		/* Update until a loop caused no more changes */
 		do {
@@ -643,7 +675,7 @@ int main(int ac, char **av)
 			check_conf(&rootmenu);
 		} while (conf_cnt &&
 			 (input_mode != listnewconfig &&
-			  input_mode != oldnoconfig));
+			  input_mode != olddefconfig));
 		break;
 	}
 
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 5a58965..43eda40 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -182,10 +182,66 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
 	return 0;
 }
 
+#define LINE_GROWTH 16
+static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
+{
+	char *nline;
+	size_t new_size = slen + 1;
+	if (new_size > *n) {
+		new_size += LINE_GROWTH - 1;
+		new_size *= 2;
+		nline = realloc(*lineptr, new_size);
+		if (!nline)
+			return -1;
+
+		*lineptr = nline;
+		*n = new_size;
+	}
+
+	(*lineptr)[slen] = c;
+
+	return 0;
+}
+
+static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream)
+{
+	char *line = *lineptr;
+	size_t slen = 0;
+
+	for (;;) {
+		int c = getc(stream);
+
+		switch (c) {
+		case '\n':
+			if (add_byte(c, &line, slen, n) < 0)
+				goto e_out;
+			slen++;
+			/* fall through */
+		case EOF:
+			if (add_byte('\0', &line, slen, n) < 0)
+				goto e_out;
+			*lineptr = line;
+			if (slen == 0)
+				return -1;
+			return slen;
+		default:
+			if (add_byte(c, &line, slen, n) < 0)
+				goto e_out;
+			slen++;
+		}
+	}
+
+e_out:
+	line[slen-1] = '\0';
+	*lineptr = line;
+	return -1;
+}
+
 int conf_read_simple(const char *name, int def)
 {
 	FILE *in = NULL;
-	char line[1024];
+	char   *line = NULL;
+	size_t  line_asize = 0;
 	char *p, *p2;
 	struct symbol *sym;
 	int i, def_flags;
@@ -247,7 +303,7 @@ load:
 		}
 	}
 
-	while (fgets(line, sizeof(line), in)) {
+	while (compat_getline(&line, &line_asize, in) != -1) {
 		conf_lineno++;
 		sym = NULL;
 		if (line[0] == '#') {
@@ -335,6 +391,7 @@ setsym:
 			cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri);
 		}
 	}
+	free(line);
 	fclose(in);
 
 	if (modules_sym)
@@ -344,10 +401,8 @@ setsym:
 
 int conf_read(const char *name)
 {
-	struct symbol *sym, *choice_sym;
-	struct property *prop;
-	struct expr *e;
-	int i, flags;
+	struct symbol *sym;
+	int i;
 
 	sym_set_change_count(0);
 
@@ -357,7 +412,7 @@ int conf_read(const char *name)
 	for_all_symbols(i, sym) {
 		sym_calc_value(sym);
 		if (sym_is_choice(sym) || (sym->flags & SYMBOL_AUTO))
-			goto sym_ok;
+			continue;
 		if (sym_has_value(sym) && (sym->flags & SYMBOL_WRITE)) {
 			/* check that calculated value agrees with saved value */
 			switch (sym->type) {
@@ -366,30 +421,18 @@ int conf_read(const char *name)
 				if (sym->def[S_DEF_USER].tri != sym_get_tristate_value(sym))
 					break;
 				if (!sym_is_choice(sym))
-					goto sym_ok;
+					continue;
 				/* fall through */
 			default:
 				if (!strcmp(sym->curr.val, sym->def[S_DEF_USER].val))
-					goto sym_ok;
+					continue;
 				break;
 			}
 		} else if (!sym_has_value(sym) && !(sym->flags & SYMBOL_WRITE))
 			/* no previous value and not saved */
-			goto sym_ok;
+			continue;
 		conf_unsaved++;
 		/* maybe print value in verbose mode... */
-	sym_ok:
-		if (!sym_is_choice(sym))
-			continue;
-		/* The choice symbol only has a set value (and thus is not new)
-		 * if all its visible childs have values.
-		 */
-		prop = sym_get_choice_prop(sym);
-		flags = sym->flags;
-		expr_list_for_each_sym(prop->expr, e, choice_sym)
-			if (choice_sym->visible != no)
-				flags &= choice_sym->flags;
-		sym->flags &= flags | ~SYMBOL_DEF_USER;
 	}
 
 	for_all_symbols(i, sym) {
@@ -464,7 +507,7 @@ kconfig_print_comment(FILE *fp, const char *value, void *arg)
 		fprintf(fp, "#");
 		if (l) {
 			fprintf(fp, " ");
-			fwrite(p, l, 1, fp);
+			xfwrite(p, l, 1, fp);
 			p += l;
 		}
 		fprintf(fp, "\n");
@@ -537,7 +580,7 @@ header_print_comment(FILE *fp, const char *value, void *arg)
 		fprintf(fp, " *");
 		if (l) {
 			fprintf(fp, " ");
-			fwrite(p, l, 1, fp);
+			xfwrite(p, l, 1, fp);
 			p += l;
 		}
 		fprintf(fp, "\n");
@@ -554,35 +597,6 @@ static struct conf_printer header_printer_cb =
 };
 
 /*
- * Generate the __enabled_CONFIG_* and __enabled_CONFIG_*_MODULE macros for
- * use by the IS_{ENABLED,BUILTIN,MODULE} macros. The _MODULE variant is
- * generated even for booleans so that the IS_ENABLED() macro works.
- */
-static void
-header_print__enabled_symbol(FILE *fp, struct symbol *sym, const char *value, void *arg)
-{
-
-	switch (sym->type) {
-	case S_BOOLEAN:
-	case S_TRISTATE: {
-		fprintf(fp, "#define __enabled_" CONFIG_ "%s %d\n",
-		    sym->name, (*value == 'y'));
-		fprintf(fp, "#define __enabled_" CONFIG_ "%s_MODULE %d\n",
-		    sym->name, (*value == 'm'));
-		break;
-	}
-	default:
-		break;
-	}
-}
-
-static struct conf_printer header__enabled_printer_cb =
-{
-	.print_symbol = header_print__enabled_symbol,
-	.print_comment = header_print_comment,
-};
-
-/*
  * Tristate printer
  *
  * This printer is used when generating the `include/config/tristate.conf' file.
@@ -963,16 +977,11 @@ int conf_write_autoconf(void)
 	conf_write_heading(out_h, &header_printer_cb, NULL);
 
 	for_all_symbols(i, sym) {
-		if (!sym->name)
-			continue;
-
 		sym_calc_value(sym);
-
-		conf_write_symbol(out_h, sym, &header__enabled_printer_cb, NULL);
-
-		if (!(sym->flags & SYMBOL_WRITE))
+		if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
 			continue;
 
+		/* write symbol to auto.conf, tristate and header files */
 		conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
 
 		conf_write_symbol(tristate, sym, &tristate_printer_cb, (void *)1);
@@ -1097,10 +1106,54 @@ static void set_all_choice_values(struct symbol *csym)
 void conf_set_all_new_symbols(enum conf_def_mode mode)
 {
 	struct symbol *sym, *csym;
-	int i, cnt;
+	int i, cnt, pby, pty, ptm;	/* pby: probability of boolean  = y
+					 * pty: probability of tristate = y
+					 * ptm: probability of tristate = m
+					 */
+
+	pby = 50; pty = ptm = 33; /* can't go as the default in switch-case
+				   * below, otherwise gcc whines about
+				   * -Wmaybe-uninitialized */
+	if (mode == def_random) {
+		int n, p[3];
+		char *env = getenv("KCONFIG_PROBABILITY");
+		n = 0;
+		while( env && *env ) {
+			char *endp;
+			int tmp = strtol( env, &endp, 10 );
+			if( tmp >= 0 && tmp <= 100 ) {
+				p[n++] = tmp;
+			} else {
+				errno = ERANGE;
+				perror( "KCONFIG_PROBABILITY" );
+				exit( 1 );
+			}
+			env = (*endp == ':') ? endp+1 : endp;
+			if( n >=3 ) {
+				break;
+			}
+		}
+		switch( n ) {
+		case 1:
+			pby = p[0]; ptm = pby/2; pty = pby-ptm;
+			break;
+		case 2:
+			pty = p[0]; ptm = p[1]; pby = pty + ptm;
+			break;
+		case 3:
+			pby = p[0]; pty = p[1]; ptm = p[2];
+			break;
+		}
+
+		if( pty+ptm > 100 ) {
+			errno = ERANGE;
+			perror( "KCONFIG_PROBABILITY" );
+			exit( 1 );
+		}
+	}
 
 	for_all_symbols(i, sym) {
-		if (sym_has_value(sym))
+		if (sym_has_value(sym) || (sym->flags & SYMBOL_VALID))
 			continue;
 		switch (sym_get_type(sym)) {
 		case S_BOOLEAN:
@@ -1116,8 +1169,15 @@ void conf_set_all_new_symbols(enum conf_def_mode mode)
 				sym->def[S_DEF_USER].tri = no;
 				break;
 			case def_random:
-				cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2;
-				sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt);
+				sym->def[S_DEF_USER].tri = no;
+				cnt = rand() % 100;
+				if (sym->type == S_TRISTATE) {
+					if (cnt < pty)
+						sym->def[S_DEF_USER].tri = yes;
+					else if (cnt < (pty+ptm))
+						sym->def[S_DEF_USER].tri = mod;
+				} else if (cnt < pby)
+					sym->def[S_DEF_USER].tri = yes;
 				break;
 			default:
 				continue;
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 290ce41..d662652 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -13,7 +13,7 @@
 
 struct expr *expr_alloc_symbol(struct symbol *sym)
 {
-	struct expr *e = calloc(1, sizeof(*e));
+	struct expr *e = xcalloc(1, sizeof(*e));
 	e->type = E_SYMBOL;
 	e->left.sym = sym;
 	return e;
@@ -21,7 +21,7 @@ struct expr *expr_alloc_symbol(struct symbol *sym)
 
 struct expr *expr_alloc_one(enum expr_type type, struct expr *ce)
 {
-	struct expr *e = calloc(1, sizeof(*e));
+	struct expr *e = xcalloc(1, sizeof(*e));
 	e->type = type;
 	e->left.expr = ce;
 	return e;
@@ -29,7 +29,7 @@ struct expr *expr_alloc_one(enum expr_type type, struct expr *ce)
 
 struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2)
 {
-	struct expr *e = calloc(1, sizeof(*e));
+	struct expr *e = xcalloc(1, sizeof(*e));
 	e->type = type;
 	e->left.expr = e1;
 	e->right.expr = e2;
@@ -38,7 +38,7 @@ struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e
 
 struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2)
 {
-	struct expr *e = calloc(1, sizeof(*e));
+	struct expr *e = xcalloc(1, sizeof(*e));
 	e->type = type;
 	e->left.sym = s1;
 	e->right.sym = s2;
@@ -66,7 +66,7 @@ struct expr *expr_copy(const struct expr *org)
 	if (!org)
 		return NULL;
 
-	e = malloc(sizeof(*org));
+	e = xmalloc(sizeof(*org));
 	memcpy(e, org, sizeof(*org));
 	switch (org->type) {
 	case E_SYMBOL:
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 80fce57..cdd4860 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -10,7 +10,9 @@
 extern "C" {
 #endif
 
+#include <assert.h>
 #include <stdio.h>
+#include "list.h"
 #ifndef __cplusplus
 #include <stdbool.h>
 #endif
@@ -172,6 +174,15 @@ struct menu {
 #define MENU_CHANGED		0x0001
 #define MENU_ROOT		0x0002
 
+struct jump_key {
+	struct list_head entries;
+	size_t offset;
+	struct menu *target;
+	int index;
+};
+
+#define JUMP_NB			9
+
 extern struct file *file_list;
 extern struct file *current_file;
 struct file *lookup_file(const char *name);
diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c
index 9f44380..f2bee70 100644
--- a/scripts/kconfig/gconf.c
+++ b/scripts/kconfig/gconf.c
@@ -10,6 +10,7 @@
 #  include <config.h>
 #endif
 
+#include <stdlib.h>
 #include "lkc.h"
 #include "images.c"
 
@@ -22,7 +23,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <time.h>
-#include <stdlib.h>
 
 //#define DEBUG
 
@@ -683,7 +683,7 @@ void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data)
 	dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
 					GTK_DIALOG_DESTROY_WITH_PARENT,
 					GTK_MESSAGE_INFO,
-					GTK_BUTTONS_CLOSE, intro_text);
+					GTK_BUTTONS_CLOSE, "%s", intro_text);
 	g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
 				 G_CALLBACK(gtk_widget_destroy),
 				 GTK_OBJECT(dialog));
@@ -701,7 +701,7 @@ void on_about1_activate(GtkMenuItem * menuitem, gpointer user_data)
 	dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
 					GTK_DIALOG_DESTROY_WITH_PARENT,
 					GTK_MESSAGE_INFO,
-					GTK_BUTTONS_CLOSE, about_text);
+					GTK_BUTTONS_CLOSE, "%s", about_text);
 	g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
 				 G_CALLBACK(gtk_widget_destroy),
 				 GTK_OBJECT(dialog));
@@ -720,7 +720,7 @@ void on_license1_activate(GtkMenuItem * menuitem, gpointer user_data)
 	dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
 					GTK_DIALOG_DESTROY_WITH_PARENT,
 					GTK_MESSAGE_INFO,
-					GTK_BUTTONS_CLOSE, license_text);
+					GTK_BUTTONS_CLOSE, "%s", license_text);
 	g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
 				 G_CALLBACK(gtk_widget_destroy),
 				 GTK_OBJECT(dialog));
@@ -830,7 +830,7 @@ static void renderer_edited(GtkCellRendererText * cell,
 static void change_sym_value(struct menu *menu, gint col)
 {
 	struct symbol *sym = menu->sym;
-	tristate oldval, newval;
+	tristate newval;
 
 	if (!sym)
 		return;
@@ -847,7 +847,6 @@ static void change_sym_value(struct menu *menu, gint col)
 	switch (sym_get_type(sym)) {
 	case S_BOOLEAN:
 	case S_TRISTATE:
-		oldval = sym_get_tristate_value(sym);
 		if (!sym_tristate_within_range(sym, newval))
 			newval = yes;
 		sym_set_tristate_value(sym, newval);
@@ -1278,7 +1277,6 @@ static void update_tree(struct menu *src, GtkTreeIter * dst)
 	gboolean valid;
 	GtkTreeIter *sibling;
 	struct symbol *sym;
-	struct property *prop;
 	struct menu *menu1, *menu2;
 
 	if (src == &rootmenu)
@@ -1287,7 +1285,6 @@ static void update_tree(struct menu *src, GtkTreeIter * dst)
 	valid = gtk_tree_model_iter_children(model2, child2, dst);
 	for (child1 = src->list; child1; child1 = child1->next) {
 
-		prop = child1->prompt;
 		sym = child1->sym;
 
 	      reparse:
diff --git a/scripts/kconfig/kconfig_load.c b/scripts/kconfig/kconfig_load.c
deleted file mode 100644
index dbdcaad..0000000
diff --git a/scripts/kconfig/lex.zconf.c_shipped b/scripts/kconfig/lex.zconf.c_shipped
deleted file mode 100644
index 3c11bed..0000000
diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h
new file mode 100644
index 0000000..685d80e
--- /dev/null
+++ b/scripts/kconfig/list.h
@@ -0,0 +1,131 @@
+#ifndef LIST_H
+#define LIST_H
+
+/*
+ * Copied from include/linux/...
+ */
+
+#undef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr:        the pointer to the member.
+ * @type:       the type of the container struct this is embedded in.
+ * @member:     the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({                      \
+	const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+	(type *)( (char *)__mptr - offsetof(type,member) );})
+
+
+struct list_head {
+	struct list_head *next, *prev;
+};
+
+
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
+
+#define LIST_HEAD(name) \
+	struct list_head name = LIST_HEAD_INIT(name)
+
+/**
+ * list_entry - get the struct for this entry
+ * @ptr:	the &struct list_head pointer.
+ * @type:	the type of the struct this is embedded in.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_entry(ptr, type, member) \
+	container_of(ptr, type, member)
+
+/**
+ * list_for_each_entry	-	iterate over list of given type
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_for_each_entry(pos, head, member)				\
+	for (pos = list_entry((head)->next, typeof(*pos), member);	\
+	     &pos->member != (head); 	\
+	     pos = list_entry(pos->member.next, typeof(*pos), member))
+
+/**
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
+ * @pos:	the type * to use as a loop cursor.
+ * @n:		another type * to use as temporary storage
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ */
+#define list_for_each_entry_safe(pos, n, head, member)			\
+	for (pos = list_entry((head)->next, typeof(*pos), member),	\
+		n = list_entry(pos->member.next, typeof(*pos), member);	\
+	     &pos->member != (head);					\
+	     pos = n, n = list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * list_empty - tests whether a list is empty
+ * @head: the list to test.
+ */
+static inline int list_empty(const struct list_head *head)
+{
+	return head->next == head;
+}
+
+/*
+ * Insert a new entry between two known consecutive entries.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_add(struct list_head *_new,
+			      struct list_head *prev,
+			      struct list_head *next)
+{
+	next->prev = _new;
+	_new->next = next;
+	_new->prev = prev;
+	prev->next = _new;
+}
+
+/**
+ * list_add_tail - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it before
+ *
+ * Insert a new entry before the specified head.
+ * This is useful for implementing queues.
+ */
+static inline void list_add_tail(struct list_head *_new, struct list_head *head)
+{
+	__list_add(_new, head->prev, head);
+}
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void __list_del(struct list_head *prev, struct list_head *next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+#define LIST_POISON1  ((void *) 0x00100100)
+#define LIST_POISON2  ((void *) 0x00200200)
+/**
+ * list_del - deletes entry from list.
+ * @entry: the element to delete from the list.
+ * Note: list_empty() on entry does not return true after this, the entry is
+ * in an undefined state.
+ */
+static inline void list_del(struct list_head *entry)
+{
+	__list_del(entry->prev, entry->next);
+	entry->next = (struct list_head*)LIST_POISON1;
+	entry->prev = (struct list_head*)LIST_POISON2;
+}
+#endif
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index b633bdb..f8aee5f 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -39,6 +39,12 @@ extern "C" {
 #ifndef CONFIG_
 #define CONFIG_ "CONFIG_"
 #endif
+static inline const char *CONFIG_prefix(void)
+{
+	return getenv( "CONFIG_" ) ?: CONFIG_;
+}
+#undef CONFIG_
+#define CONFIG_ CONFIG_prefix()
 
 #define TF_COMMAND	0x0001
 #define TF_PARAM	0x0002
@@ -90,8 +96,10 @@ struct conf_printer {
 /* confdata.c and expr.c */
 static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
 {
-	if (fwrite(str, len, count, out) < count)
-		fprintf(stderr, "\nError in writing or end of file.\n");
+	assert(len != 0);
+
+	if (fwrite(str, len, count, out) != count)
+		fprintf(stderr, "Error in writing or end of file.\n");
 }
 
 /* menu.c */
@@ -114,6 +122,8 @@ void menu_set_type(int type);
 /* util.c */
 struct file *file_lookup(const char *name);
 int file_write_dep(const char *name);
+void *xmalloc(size_t size);
+void *xcalloc(size_t nmemb, size_t size);
 
 struct gstr {
 	size_t len;
diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h
index 47fe9c3..ef1a738 100644
--- a/scripts/kconfig/lkc_proto.h
+++ b/scripts/kconfig/lkc_proto.h
@@ -21,8 +21,10 @@ P(menu_get_root_menu,struct menu *,(struct menu *menu));
 P(menu_get_parent_menu,struct menu *,(struct menu *menu));
 P(menu_has_help,bool,(struct menu *menu));
 P(menu_get_help,const char *,(struct menu *menu));
-P(get_symbol_str, void, (struct gstr *r, struct symbol *sym));
-P(get_relations_str, struct gstr, (struct symbol **sym_arr));
+P(get_symbol_str, void, (struct gstr *r, struct symbol *sym, struct list_head
+			 *head));
+P(get_relations_str, struct gstr, (struct symbol **sym_arr, struct list_head
+				   *head));
 P(menu_get_ext_help,void,(struct menu *menu, struct gstr *help));
 
 /* symbol.c */
diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh
index 82cc3a8..9d2a4c5 100644
--- a/scripts/kconfig/lxdialog/check-lxdialog.sh
+++ b/scripts/kconfig/lxdialog/check-lxdialog.sh
@@ -4,7 +4,9 @@
 # What library to link
 ldflags()
 {
-	for ext in so a dylib ; do
+	pkg-config --libs ncursesw 2>/dev/null && exit
+	pkg-config --libs ncurses 2>/dev/null && exit
+	for ext in so a dll.a dylib ; do
 		for lib in ncursesw ncurses curses ; do
 			$cc -print-file-name=lib${lib}.${ext} | grep -q /
 			if [ $? -eq 0 ]; then
@@ -19,12 +21,13 @@ ldflags()
 # Where is ncurses.h?
 ccflags()
 {
-	if [ -f /usr/include/ncurses/ncurses.h ]; then
+	if [ -f /usr/include/ncursesw/curses.h ]; then
+		echo '-I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"'
+		echo ' -DNCURSES_WIDECHAR=1'
+	elif [ -f /usr/include/ncurses/ncurses.h ]; then
 		echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
 	elif [ -f /usr/include/ncurses/curses.h ]; then
-		echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"'
-	elif [ -f /usr/include/ncursesw/curses.h ]; then
-		echo '-I/usr/include/ncursesw -DCURSES_LOC="<ncursesw/curses.h>"'
+		echo '-I/usr/include/ncurses -DCURSES_LOC="<curses.h>"'
 	elif [ -f /usr/include/ncurses.h ]; then
 		echo '-DCURSES_LOC="<ncurses.h>"'
 	else
@@ -38,7 +41,7 @@ trap "rm -f $tmp" 0 1 2 3 15
 
 # Check if we can link to ncurses
 check() {
-        $cc -xc - -o $tmp 2>/dev/null <<'EOF'
+        $cc -x c - -o $tmp 2>/dev/null <<'EOF'
 #include CURSES_LOC
 main() {}
 EOF
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index 14bb341..a2eb80f 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -15,6 +15,10 @@
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include "dialog.h"
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h
index 3c61d71..1099337 100644
--- a/scripts/kconfig/lxdialog/dialog.h
+++ b/scripts/kconfig/lxdialog/dialog.h
@@ -12,6 +12,10 @@
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <sys/types.h>
@@ -102,8 +106,14 @@ struct dialog_color {
 	int hl;		/* highlight this item */
 };
 
+struct subtitle_list {
+	struct subtitle_list *next;
+	const char *text;
+};
+
 struct dialog_info {
 	const char *backtitle;
+	struct subtitle_list *subtitles;
 	struct dialog_color screen;
 	struct dialog_color shadow;
 	struct dialog_color dialog;
@@ -140,6 +150,7 @@ struct dialog_info {
  */
 extern struct dialog_info dlg;
 extern char dialog_input_result[];
+extern int saved_x, saved_y;		/* Needed in signal handler in mconf.c */
 
 /*
  * Function prototypes
@@ -191,6 +202,7 @@ int on_key_resize(void);
 
 int init_dialog(const char *backtitle);
 void set_dialog_backtitle(const char *backtitle);
+void set_dialog_subtitles(struct subtitle_list *subtitles);
 void end_dialog(int x, int y);
 void attr_clear(WINDOW * win, int height, int width, chtype attr);
 void dialog_clear(void);
@@ -205,12 +217,17 @@ int first_alpha(const char *string, const char *exempt);
 int dialog_yesno(const char *title, const char *prompt, int height, int width);
 int dialog_msgbox(const char *title, const char *prompt, int height,
 		  int width, int pause);
-int dialog_textbox(const char *title, const char *file, int height, int width);
+
+
+typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void
+			       *_data);
+int dialog_textbox(const char *title, char *tbuf, int initial_height,
+		   int initial_width, int *keys, int *_vscroll, int *_hscroll,
+		   update_text_fn update_text, void *data);
 int dialog_menu(const char *title, const char *prompt,
 		const void *selected, int *s_scroll);
 int dialog_checklist(const char *title, const char *prompt, int height,
 		     int width, int list_height);
-extern char dialog_input_result[];
 int dialog_inputbox(const char *title, const char *prompt, int height,
 		    int width, const char *init);
 
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index 1564a28..21404a0 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -13,6 +13,10 @@
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include "dialog.h"
@@ -41,7 +45,8 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
                     const char *init)
 {
 	int i, x, y, box_y, box_x, box_width;
-	int input_x = 0, scroll = 0, key = 0, button = -1;
+	int input_x = 0, key = 0, button = -1;
+	int show_x, len, pos;
 	char *instr = dialog_input_result;
 	WINDOW *dialog;
 
@@ -93,14 +98,17 @@ do_resize:
 	wmove(dialog, box_y, box_x);
 	wattrset(dialog, dlg.inputbox.atr);
 
-	input_x = strlen(instr);
+	len = strlen(instr);
+	pos = len;
 
-	if (input_x >= box_width) {
-		scroll = input_x - box_width + 1;
+	if (len >= box_width) {
+		show_x = len - box_width + 1;
 		input_x = box_width - 1;
 		for (i = 0; i < box_width - 1; i++)
-			waddch(dialog, instr[scroll + i]);
+			waddch(dialog, instr[show_x + i]);
 	} else {
+		show_x = 0;
+		input_x = len;
 		waddstr(dialog, instr);
 	}
 
@@ -117,45 +125,104 @@ do_resize:
 			case KEY_UP:
 			case KEY_DOWN:
 				break;
-			case KEY_LEFT:
-				continue;
-			case KEY_RIGHT:
-				continue;
 			case KEY_BACKSPACE:
 			case 127:
-				if (input_x || scroll) {
+				if (pos) {
 					wattrset(dialog, dlg.inputbox.atr);
-					if (!input_x) {
-						scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
-						wmove(dialog, box_y, box_x);
-						for (i = 0; i < box_width; i++)
-							waddch(dialog,
-							       instr[scroll + input_x + i] ?
-							       instr[scroll + input_x + i] : ' ');
-						input_x = strlen(instr) - scroll;
+					if (input_x == 0) {
+						show_x--;
 					} else
 						input_x--;
-					instr[scroll + input_x] = '\0';
-					mvwaddch(dialog, box_y, input_x + box_x, ' ');
+
+					if (pos < len) {
+						for (i = pos - 1; i < len; i++) {
+							instr[i] = instr[i+1];
+						}
+					}
+
+					pos--;
+					len--;
+					instr[len] = '\0';
+					wmove(dialog, box_y, box_x);
+					for (i = 0; i < box_width; i++) {
+						if (!instr[show_x + i]) {
+							waddch(dialog, ' ');
+							break;
+						}
+						waddch(dialog, instr[show_x + i]);
+					}
 					wmove(dialog, box_y, input_x + box_x);
 					wrefresh(dialog);
 				}
 				continue;
+			case KEY_LEFT:
+				if (pos > 0) {
+					if (input_x > 0) {
+						wmove(dialog, box_y, --input_x + box_x);
+					} else if (input_x == 0) {
+						show_x--;
+						wmove(dialog, box_y, box_x);
+						for (i = 0; i < box_width; i++) {
+							if (!instr[show_x + i]) {
+								waddch(dialog, ' ');
+								break;
+							}
+							waddch(dialog, instr[show_x + i]);
+						}
+						wmove(dialog, box_y, box_x);
+					}
+					pos--;
+				}
+				continue;
+			case KEY_RIGHT:
+				if (pos < len) {
+					if (input_x < box_width - 1) {
+						wmove(dialog, box_y, ++input_x + box_x);
+					} else if (input_x == box_width - 1) {
+						show_x++;
+						wmove(dialog, box_y, box_x);
+						for (i = 0; i < box_width; i++) {
+							if (!instr[show_x + i]) {
+								waddch(dialog, ' ');
+								break;
+							}
+							waddch(dialog, instr[show_x + i]);
+						}
+						wmove(dialog, box_y, input_x + box_x);
+					}
+					pos++;
+				}
+				continue;
 			default:
 				if (key < 0x100 && isprint(key)) {
-					if (scroll + input_x < MAX_LEN) {
+					if (len < MAX_LEN) {
 						wattrset(dialog, dlg.inputbox.atr);
-						instr[scroll + input_x] = key;
-						instr[scroll + input_x + 1] = '\0';
+						if (pos < len) {
+							for (i = len; i > pos; i--)
+								instr[i] = instr[i-1];
+							instr[pos] = key;
+						} else {
+							instr[len] = key;
+						}
+						pos++;
+						len++;
+						instr[len] = '\0';
+
 						if (input_x == box_width - 1) {
-							scroll++;
-							wmove(dialog, box_y, box_x);
-							for (i = 0; i < box_width - 1; i++)
-								waddch(dialog, instr [scroll + i]);
+							show_x++;
 						} else {
-							wmove(dialog, box_y, input_x++ + box_x);
-							waddch(dialog, key);
+							input_x++;
+						}
+
+						wmove(dialog, box_y, box_x);
+						for (i = 0; i < box_width; i++) {
+							if (!instr[show_x + i]) {
+								waddch(dialog, ' ');
+								break;
+							}
+							waddch(dialog, instr[show_x + i]);
 						}
+						wmove(dialog, box_y, input_x + box_x);
 						wrefresh(dialog);
 					} else
 						flash();	/* Alarm user about overflow */
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index b0d9a5c..38cd69c 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -13,6 +13,10 @@
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 /*
@@ -22,7 +26,7 @@
  *
  *    *)  A bugfix for the Page-Down problem
  *
- *    *)  Formerly when I used Page Down and Page Up, the cursor would be set 
+ *    *)  Formerly when I used Page Down and Page Up, the cursor would be set
  *        to the first position in the menu box.  Now lxdialog is a bit
  *        smarter and works more like other menu systems (just have a look at
  *        it).
@@ -150,12 +154,14 @@ static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
  */
 static void print_buttons(WINDOW * win, int height, int width, int selected)
 {
-	int x = width / 2 - 16;
+	int x = width / 2 - 28;
 	int y = height - 2;
 
 	print_button(win, gettext("Select"), y, x, selected == 0);
 	print_button(win, gettext(" Exit "), y, x + 12, selected == 1);
 	print_button(win, gettext(" Help "), y, x + 24, selected == 2);
+	print_button(win, gettext(" Save "), y, x + 36, selected == 3);
+	print_button(win, gettext(" Load "), y, x + 48, selected == 4);
 
 	wmove(win, y, x + 1 + 12 * selected);
 	wrefresh(win);
@@ -297,10 +303,11 @@ do_resize:
 				}
 		}
 
-		if (i < max_choice ||
-		    key == KEY_UP || key == KEY_DOWN ||
-		    key == '-' || key == '+' ||
-		    key == KEY_PPAGE || key == KEY_NPAGE) {
+		if (item_count() != 0 &&
+		    (i < max_choice ||
+		     key == KEY_UP || key == KEY_DOWN ||
+		     key == '-' || key == '+' ||
+		     key == KEY_PPAGE || key == KEY_NPAGE)) {
 			/* Remove highligt of current item */
 			print_item(scroll + choice, choice, FALSE);
 
@@ -368,7 +375,7 @@ do_resize:
 		case TAB:
 		case KEY_RIGHT:
 			button = ((key == KEY_LEFT ? --button : ++button) < 0)
-			    ? 2 : (button > 2 ? 0 : button);
+			    ? 4 : (button > 4 ? 0 : button);
 
 			print_buttons(dialog, height, width, button);
 			wrefresh(menu);
@@ -395,17 +402,17 @@ do_resize:
 				return 2;
 			case 's':
 			case 'y':
-				return 3;
+				return 5;
 			case 'n':
-				return 4;
+				return 6;
 			case 'm':
-				return 5;
+				return 7;
 			case ' ':
-				return 6;
+				return 8;
 			case '/':
-				return 7;
+				return 9;
 			case 'z':
-				return 8;
+				return 10;
 			case '\n':
 				return button;
 			}
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index 3ef8c4f..a48bb93 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -13,28 +13,34 @@
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include "dialog.h"
 
 static void back_lines(int n);
-static void print_page(WINDOW * win, int height, int width);
-static void print_line(WINDOW * win, int row, int width);
+static void print_page(WINDOW *win, int height, int width, update_text_fn
+		       update_text, void *data);
+static void print_line(WINDOW *win, int row, int width);
 static char *get_line(void);
 static void print_position(WINDOW * win);
 
 static int hscroll;
 static int begin_reached, end_reached, page_length;
-static const char *buf;
-static const char *page;
+static char *buf;
+static char *page;
 
 /*
  * refresh window content
  */
 static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
-							  int cur_y, int cur_x)
+			     int cur_y, int cur_x, update_text_fn update_text,
+			     void *data)
 {
-	print_page(box, boxh, boxw);
+	print_page(box, boxh, boxw, update_text, data);
 	print_position(dialog);
 	wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
 	wrefresh(dialog);
@@ -43,14 +49,18 @@ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
 
 /*
  * Display text from a file in a dialog box.
+ *
+ * keys is a null-terminated array
+ * update_text() may not add or remove any '\n' or '\0' in tbuf
  */
-int dialog_textbox(const char *title, const char *tbuf,
-		   int initial_height, int initial_width)
+int dialog_textbox(const char *title, char *tbuf, int initial_height,
+		   int initial_width, int *keys, int *_vscroll, int *_hscroll,
+		   update_text_fn update_text, void *data)
 {
 	int i, x, y, cur_x, cur_y, key = 0;
 	int height, width, boxh, boxw;
-	int passed_end;
 	WINDOW *dialog, *box;
+	bool done = false;
 
 	begin_reached = 1;
 	end_reached = 0;
@@ -59,6 +69,15 @@ int dialog_textbox(const char *title, const char *tbuf,
 	buf = tbuf;
 	page = buf;	/* page is pointer to start of page to be displayed */
 
+	if (_vscroll && *_vscroll) {
+		begin_reached = 0;
+
+		for (i = 0; i < *_vscroll; i++)
+			get_line();
+	}
+	if (_hscroll)
+		hscroll = *_hscroll;
+
 do_resize:
 	getmaxyx(stdscr, height, width);
 	if (height < 8 || width < 8)
@@ -116,25 +135,28 @@ do_resize:
 
 	/* Print first page of text */
 	attr_clear(box, boxh, boxw, dlg.dialog.atr);
-	refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
+	refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x, update_text,
+			 data);
 
-	while ((key != KEY_ESC) && (key != '\n')) {
+	while (!done) {
 		key = wgetch(dialog);
 		switch (key) {
 		case 'E':	/* Exit */
 		case 'e':
 		case 'X':
 		case 'x':
-			delwin(box);
-			delwin(dialog);
-			return 0;
+		case 'q':
+		case '\n':
+			done = true;
+			break;
 		case 'g':	/* First page */
 		case KEY_HOME:
 			if (!begin_reached) {
 				begin_reached = 1;
 				page = buf;
 				refresh_text_box(dialog, box, boxh, boxw,
-						 cur_y, cur_x);
+						 cur_y, cur_x, update_text,
+						 data);
 			}
 			break;
 		case 'G':	/* Last page */
@@ -144,78 +166,48 @@ do_resize:
 			/* point to last char in buf */
 			page = buf + strlen(buf);
 			back_lines(boxh);
-			refresh_text_box(dialog, box, boxh, boxw,
-					 cur_y, cur_x);
+			refresh_text_box(dialog, box, boxh, boxw, cur_y,
+					 cur_x, update_text, data);
 			break;
 		case 'K':	/* Previous line */
 		case 'k':
 		case KEY_UP:
-			if (!begin_reached) {
-				back_lines(page_length + 1);
-
-				/* We don't call print_page() here but use
-				 * scrolling to ensure faster screen update.
-				 * However, 'end_reached' and 'page_length'
-				 * should still be updated, and 'page' should
-				 * point to start of next page. This is done
-				 * by calling get_line() in the following
-				 * 'for' loop. */
-				scrollok(box, TRUE);
-				wscrl(box, -1);	/* Scroll box region down one line */
-				scrollok(box, FALSE);
-				page_length = 0;
-				passed_end = 0;
-				for (i = 0; i < boxh; i++) {
-					if (!i) {
-						/* print first line of page */
-						print_line(box, 0, boxw);
-						wnoutrefresh(box);
-					} else
-						/* Called to update 'end_reached' and 'page' */
-						get_line();
-					if (!passed_end)
-						page_length++;
-					if (end_reached && !passed_end)
-						passed_end = 1;
-				}
+			if (begin_reached)
+				break;
 
-				print_position(dialog);
-				wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
-				wrefresh(dialog);
-			}
+			back_lines(page_length + 1);
+			refresh_text_box(dialog, box, boxh, boxw, cur_y,
+					 cur_x, update_text, data);
 			break;
 		case 'B':	/* Previous page */
 		case 'b':
+		case 'u':
 		case KEY_PPAGE:
 			if (begin_reached)
 				break;
 			back_lines(page_length + boxh);
-			refresh_text_box(dialog, box, boxh, boxw,
-					 cur_y, cur_x);
+			refresh_text_box(dialog, box, boxh, boxw, cur_y,
+					 cur_x, update_text, data);
 			break;
 		case 'J':	/* Next line */
 		case 'j':
 		case KEY_DOWN:
-			if (!end_reached) {
-				begin_reached = 0;
-				scrollok(box, TRUE);
-				scroll(box);	/* Scroll box region up one line */
-				scrollok(box, FALSE);
-				print_line(box, boxh - 1, boxw);
-				wnoutrefresh(box);
-				print_position(dialog);
-				wmove(dialog, cur_y, cur_x);	/* Restore cursor position */
-				wrefresh(dialog);
-			}
+			if (end_reached)
+				break;
+
+			back_lines(page_length - 1);
+			refresh_text_box(dialog, box, boxh, boxw, cur_y,
+					 cur_x, update_text, data);
 			break;
 		case KEY_NPAGE:	/* Next page */
 		case ' ':
+		case 'd':
 			if (end_reached)
 				break;
 
 			begin_reached = 0;
-			refresh_text_box(dialog, box, boxh, boxw,
-					 cur_y, cur_x);
+			refresh_text_box(dialog, box, boxh, boxw, cur_y,
+					 cur_x, update_text, data);
 			break;
 		case '0':	/* Beginning of line */
 		case 'H':	/* Scroll left */
@@ -230,8 +222,8 @@ do_resize:
 				hscroll--;
 			/* Reprint current page to scroll horizontally */
 			back_lines(page_length);
-			refresh_text_box(dialog, box, boxh, boxw,
-					 cur_y, cur_x);
+			refresh_text_box(dialog, box, boxh, boxw, cur_y,
+					 cur_x, update_text, data);
 			break;
 		case 'L':	/* Scroll right */
 		case 'l':
@@ -241,11 +233,12 @@ do_resize:
 			hscroll++;
 			/* Reprint current page to scroll horizontally */
 			back_lines(page_length);
-			refresh_text_box(dialog, box, boxh, boxw,
-					 cur_y, cur_x);
+			refresh_text_box(dialog, box, boxh, boxw, cur_y,
+					 cur_x, update_text, data);
 			break;
 		case KEY_ESC:
-			key = on_key_esc(dialog);
+			if (on_key_esc(dialog) == KEY_ESC)
+				done = true;
 			break;
 		case KEY_RESIZE:
 			back_lines(height);
@@ -253,11 +246,31 @@ do_resize:
 			delwin(dialog);
 			on_key_resize();
 			goto do_resize;
+		default:
+			for (i = 0; keys[i]; i++) {
+				if (key == keys[i]) {
+					done = true;
+					break;
+				}
+			}
 		}
 	}
 	delwin(box);
 	delwin(dialog);
-	return key;		/* ESC pressed */
+	if (_vscroll) {
+		const char *s;
+
+		s = buf;
+		*_vscroll = 0;
+		back_lines(page_length);
+		while (s < page && (s = strchr(s, '\n'))) {
+			(*_vscroll)++;
+			s++;
+		}
+	}
+	if (_hscroll)
+		*_hscroll = hscroll;
+	return key;
 }
 
 /*
@@ -294,12 +307,23 @@ static void back_lines(int n)
 }
 
 /*
- * Print a new page of text. Called by dialog_textbox().
+ * Print a new page of text.
  */
-static void print_page(WINDOW * win, int height, int width)
+static void print_page(WINDOW *win, int height, int width, update_text_fn
+		       update_text, void *data)
 {
 	int i, passed_end = 0;
 
+	if (update_text) {
+		char *end;
+
+		for (i = 0; i < height; i++)
+			get_line();
+		end = page;
+		back_lines(height);
+		update_text(buf, page - buf, end - buf, data);
+	}
+
 	page_length = 0;
 	for (i = 0; i < height; i++) {
 		print_line(win, i, width);
@@ -312,7 +336,7 @@ static void print_page(WINDOW * win, int height, int width)
 }
 
 /*
- * Print a new line of text. Called by dialog_textbox() and print_page().
+ * Print a new line of text.
  */
 static void print_line(WINDOW * win, int row, int width)
 {
@@ -350,10 +374,8 @@ static char *get_line(void)
 	end_reached = 0;
 	while (*page != '\n') {
 		if (*page == '\0') {
-			if (!end_reached) {
-				end_reached = 1;
-				break;
-			}
+			end_reached = 1;
+			break;
 		} else if (i < MAX_LEN)
 			line[i++] = *(page++);
 		else {
@@ -366,7 +388,7 @@ static char *get_line(void)
 	if (i <= MAX_LEN)
 		line[i] = '\0';
 	if (!end_reached)
-		page++;		/* move pass '\n' */
+		page++;		/* move past '\n' */
 
 	return line;
 }
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index 891d302..a0e97c2 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -13,12 +13,19 @@
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <stdarg.h>
 
 #include "dialog.h"
 
+/* Needed in signal handler in mconf.c */
+int saved_x, saved_y;
+
 struct dialog_info dlg;
 
 static void set_mono_theme(void)
@@ -250,12 +257,48 @@ void dialog_clear(void)
 	attr_clear(stdscr, LINES, COLS, dlg.screen.atr);
 	/* Display background title if it exists ... - SLH */
 	if (dlg.backtitle != NULL) {
-		int i;
+		int i, len = 0, skip = 0;
+		struct subtitle_list *pos;
 
 		wattrset(stdscr, dlg.screen.atr);
 		mvwaddstr(stdscr, 0, 1, (char *)dlg.backtitle);
+
+		for (pos = dlg.subtitles; pos != NULL; pos = pos->next) {
+			/* 3 is for the arrow and spaces */
+			len += strlen(pos->text) + 3;
+		}
+
 		wmove(stdscr, 1, 1);
-		for (i = 1; i < COLS - 1; i++)
+		if (len > COLS - 2) {
+			const char *ellipsis = "[...] ";
+			waddstr(stdscr, ellipsis);
+			skip = len - (COLS - 2 - strlen(ellipsis));
+		}
+
+		for (pos = dlg.subtitles; pos != NULL; pos = pos->next) {
+			if (skip == 0)
+				waddch(stdscr, ACS_RARROW);
+			else
+				skip--;
+
+			if (skip == 0)
+				waddch(stdscr, ' ');
+			else
+				skip--;
+
+			if (skip < strlen(pos->text)) {
+				waddstr(stdscr, pos->text + skip);
+				skip = 0;
+			} else
+				skip -= strlen(pos->text);
+
+			if (skip == 0)
+				waddch(stdscr, ' ');
+			else
+				skip--;
+		}
+
+		for (i = len + 1; i < COLS - 1; i++)
 			waddch(stdscr, ACS_HLINE);
 	}
 	wnoutrefresh(stdscr);
@@ -269,6 +312,10 @@ int init_dialog(const char *backtitle)
 	int height, width;
 
 	initscr();		/* Init curses */
+
+	/* Get current cursor position for signal handler in mconf.c */
+	getyx(stdscr, saved_y, saved_x);
+
 	getmaxyx(stdscr, height, width);
 	if (height < 19 || width < 80) {
 		endwin();
@@ -291,6 +338,11 @@ void set_dialog_backtitle(const char *backtitle)
 	dlg.backtitle = backtitle;
 }
 
+void set_dialog_subtitles(struct subtitle_list *subtitles)
+{
+	dlg.subtitles = subtitles;
+}
+
 /*
  * End using dialog functions.
  */
diff --git a/scripts/kconfig/lxdialog/yesno.c b/scripts/kconfig/lxdialog/yesno.c
index adbfcd9..4e6e809 100644
--- a/scripts/kconfig/lxdialog/yesno.c
+++ b/scripts/kconfig/lxdialog/yesno.c
@@ -13,6 +13,10 @@
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include "dialog.h"
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 19e200d..a69cbd7 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -105,10 +105,10 @@ static const char mconf_readme[] = N_(
 "Text Box    (Help Window)\n"
 "--------\n"
 "o  Use the cursor keys to scroll up/down/left/right.  The VI editor\n"
-"   keys h,j,k,l function here as do <SPACE BAR> and <B> for those\n"
-"   who are familiar with less and lynx.\n"
+"   keys h,j,k,l function here as do <u>, <d>, <SPACE BAR> and <B> for \n"
+"   those who are familiar with less and lynx.\n"
 "\n"
-"o  Press <E>, <X>, <Enter> or <Esc><Esc> to exit.\n"
+"o  Press <E>, <X>, <q>, <Enter> or <Esc><Esc> to exit.\n"
 "\n"
 "\n"
 "Alternate Configuration Files\n"
@@ -236,16 +236,19 @@ search_help[] = N_(
 	"Result:\n"
 	"-----------------------------------------------------------------\n"
 	"Symbol: FOO [=m]\n"
+	"Type  : tristate\n"
 	"Prompt: Foo bus is used to drive the bar HW\n"
-	"Defined at drivers/pci/Kconfig:47\n"
-	"Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
-	"Location:\n"
-	"  -> Bus options (PCI, PCMCIA, EISA, MCA, ISA)\n"
-	"    -> PCI support (PCI [=y])\n"
-	"      -> PCI access mode (<choice> [=y])\n"
-	"Selects: LIBCRC32\n"
-	"Selected by: BAR\n"
+	"  Defined at drivers/pci/Kconfig:47\n"
+	"  Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
+	"  Location:\n"
+	"    -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
+	"      -> PCI support (PCI [=y])\n"
+	"(1)     -> PCI access mode (<choice> [=y])\n"
+	"  Selects: LIBCRC32\n"
+	"  Selected by: BAR\n"
 	"-----------------------------------------------------------------\n"
+	"o The line 'Type:' shows the type of the configuration option for\n"
+	"  this symbol (boolean, tristate, string, ...)\n"
 	"o The line 'Prompt:' shows the text used in the menu structure for\n"
 	"  this symbol\n"
 	"o The 'Defined at' line tell at what file / line number the symbol\n"
@@ -254,8 +257,12 @@ search_help[] = N_(
 	"  this symbol to be visible in the menu (selectable)\n"
 	"o The 'Location:' lines tell where in the menu structure this symbol\n"
 	"  is located\n"
-	"    A location followed by a [=y] indicate that this is a selectable\n"
-	"    menu item - and current value is displayed inside brackets.\n"
+	"    A location followed by a [=y] indicates that this is a\n"
+	"    selectable menu item - and the current value is displayed inside\n"
+	"    brackets.\n"
+	"    Press the key in the (#) prefix to jump directly to that\n"
+	"    location. You will be returned to the current search results\n"
+	"    after exiting this new menu.\n"
 	"o The 'Selects:' line tell what symbol will be automatically\n"
 	"  selected if this symbol is selected (y or m)\n"
 	"o The 'Selected by' line tell what symbol has selected this symbol\n"
@@ -273,13 +280,16 @@ static struct menu *current_menu;
 static int child_count;
 static int single_menu_mode;
 static int show_all_options;
-static int saved_x, saved_y;
+static int save_and_exit;
 
-static void conf(struct menu *menu);
+static void conf(struct menu *menu, struct menu *active_menu);
 static void conf_choice(struct menu *menu);
 static void conf_string(struct menu *menu);
 static void conf_load(void);
 static void conf_save(void);
+static int show_textbox_ext(const char *title, char *text, int r, int c,
+			    int *keys, int *vscroll, int *hscroll,
+			    update_text_fn update_text, void *data);
 static void show_textbox(const char *title, const char *text, int r, int c);
 static void show_helptext(const char *title, const char *text);
 static void show_help(struct menu *menu);
@@ -301,18 +311,103 @@ static void set_config_filename(const char *config_filename)
 		filename[sizeof(filename)-1] = '\0';
 }
 
+struct subtitle_part {
+	struct list_head entries;
+	const char *text;
+};
+static LIST_HEAD(trail);
+
+static struct subtitle_list *subtitles;
+static void set_subtitle(void)
+{
+	struct subtitle_part *sp;
+	struct subtitle_list *pos, *tmp;
+
+	for (pos = subtitles; pos != NULL; pos = tmp) {
+		tmp = pos->next;
+		free(pos);
+	}
+
+	subtitles = NULL;
+	list_for_each_entry(sp, &trail, entries) {
+		if (sp->text) {
+			if (pos) {
+				pos->next = xcalloc(sizeof(*pos), 1);
+				pos = pos->next;
+			} else {
+				subtitles = pos = xcalloc(sizeof(*pos), 1);
+			}
+			pos->text = sp->text;
+		}
+	}
+
+	set_dialog_subtitles(subtitles);
+}
+
+static void reset_subtitle(void)
+{
+	struct subtitle_list *pos, *tmp;
+
+	for (pos = subtitles; pos != NULL; pos = tmp) {
+		tmp = pos->next;
+		free(pos);
+	}
+	subtitles = NULL;
+	set_dialog_subtitles(subtitles);
+}
+
+struct search_data {
+	struct list_head *head;
+	struct menu **targets;
+	int *keys;
+};
+
+static void update_text(char *buf, size_t start, size_t end, void *_data)
+{
+	struct search_data *data = _data;
+	struct jump_key *pos;
+	int k = 0;
+
+	list_for_each_entry(pos, data->head, entries) {
+		if (pos->offset >= start && pos->offset < end) {
+			char header[4];
+
+			if (k < JUMP_NB) {
+				int key = '0' + (pos->index % JUMP_NB) + 1;
+
+				sprintf(header, "(%c)", key);
+				data->keys[k] = key;
+				data->targets[k] = pos->target;
+				k++;
+			} else {
+				sprintf(header, "   ");
+			}
+
+			memcpy(buf + pos->offset, header, sizeof(header) - 1);
+		}
+	}
+	data->keys[k] = 0;
+}
 
 static void search_conf(void)
 {
 	struct symbol **sym_arr;
 	struct gstr res;
+	struct gstr title;
 	char *dialog_input;
-	int dres;
+	int dres, vscroll = 0, hscroll = 0;
+	bool again;
+	struct gstr sttext;
+	struct subtitle_part stpart;
+
+	title = str_new();
+	str_printf( &title, _("Enter %s (sub)string to search for "
+			      "(with or without \"%s\")"), CONFIG_, CONFIG_);
+
 again:
 	dialog_clear();
 	dres = dialog_inputbox(_("Search Configuration Parameter"),
-			      _("Enter " CONFIG_ " (sub)string to search for "
-				"(with or without \"" CONFIG_ "\")"),
+			      str_get(&title),
 			      10, 75, "");
 	switch (dres) {
 	case 0:
@@ -321,6 +416,7 @@ again:
 		show_helptext(_("Search Configuration"), search_help);
 		goto again;
 	default:
+		str_free(&title);
 		return;
 	}
 
@@ -329,11 +425,43 @@ again:
 	if (strncasecmp(dialog_input_result, CONFIG_, strlen(CONFIG_)) == 0)
 		dialog_input += strlen(CONFIG_);
 
+	sttext = str_new();
+	str_printf(&sttext, "Search (%s)", dialog_input_result);
+	stpart.text = str_get(&sttext);
+	list_add_tail(&stpart.entries, &trail);
+
 	sym_arr = sym_re_search(dialog_input);
-	res = get_relations_str(sym_arr);
+	do {
+		LIST_HEAD(head);
+		struct menu *targets[JUMP_NB];
+		int keys[JUMP_NB + 1], i;
+		struct search_data data = {
+			.head = &head,
+			.targets = targets,
+			.keys = keys,
+		};
+		struct jump_key *pos, *tmp;
+
+		res = get_relations_str(sym_arr, &head);
+		set_subtitle();
+		dres = show_textbox_ext(_("Search Results"), (char *)
+					str_get(&res), 0, 0, keys, &vscroll,
+					&hscroll, &update_text, (void *)
+					&data);
+		again = false;
+		for (i = 0; i < JUMP_NB && keys[i]; i++)
+			if (dres == keys[i]) {
+				conf(targets[i]->parent, targets[i]);
+				again = true;
+			}
+		str_free(&res);
+		list_for_each_entry_safe(pos, tmp, &head, entries)
+			free(pos);
+	} while (again);
 	free(sym_arr);
-	show_textbox(_("Search Results"), str_get(&res), 0, 0);
-	str_free(&res);
+	str_free(&title);
+	list_del(trail.prev);
+	str_free(&sttext);
 }
 
 static void build_conf(struct menu *menu)
@@ -514,40 +642,40 @@ conf_childs:
 	indent -= doint;
 }
 
-static void conf(struct menu *menu)
+static void conf(struct menu *menu, struct menu *active_menu)
 {
 	struct menu *submenu;
 	const char *prompt = menu_get_prompt(menu);
+	struct subtitle_part stpart;
 	struct symbol *sym;
-	struct menu *active_menu = NULL;
 	int res;
 	int s_scroll = 0;
 
+	if (menu != &rootmenu)
+		stpart.text = menu_get_prompt(menu);
+	else
+		stpart.text = NULL;
+	list_add_tail(&stpart.entries, &trail);
+
 	while (1) {
 		item_reset();
 		current_menu = menu;
 		build_conf(menu);
 		if (!child_count)
 			break;
-		if (menu == &rootmenu) {
-			item_make("--- ");
-			item_set_tag(':');
-			item_make(_("    Load an Alternate Configuration File"));
-			item_set_tag('L');
-			item_make(_("    Save an Alternate Configuration File"));
-			item_set_tag('S');
-		}
+		set_subtitle();
 		dialog_clear();
 		res = dialog_menu(prompt ? _(prompt) : _("Main Menu"),
 				  _(menu_instructions),
 				  active_menu, &s_scroll);
 		if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
 			break;
-		if (!item_activate_selected())
-			continue;
-		if (!item_tag())
-			continue;
-
+		if (item_count() != 0) {
+			if (!item_activate_selected())
+				continue;
+			if (!item_tag())
+				continue;
+		}
 		submenu = item_data();
 		active_menu = item_data();
 		if (submenu)
@@ -562,32 +690,36 @@ static void conf(struct menu *menu)
 				if (single_menu_mode)
 					submenu->data = (void *) (long) !submenu->data;
 				else
-					conf(submenu);
+					conf(submenu, NULL);
 				break;
 			case 't':
 				if (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)
 					conf_choice(submenu);
 				else if (submenu->prompt->type == P_MENU)
-					conf(submenu);
+					conf(submenu, NULL);
 				break;
 			case 's':
 				conf_string(submenu);
 				break;
-			case 'L':
-				conf_load();
-				break;
-			case 'S':
-				conf_save();
-				break;
 			}
 			break;
 		case 2:
 			if (sym)
 				show_help(submenu);
-			else
+			else {
+				reset_subtitle();
 				show_helptext(_("README"), _(mconf_readme));
+			}
 			break;
 		case 3:
+			reset_subtitle();
+			conf_save();
+			break;
+		case 4:
+			reset_subtitle();
+			conf_load();
+			break;
+		case 5:
 			if (item_is_tag('t')) {
 				if (sym_set_tristate_value(sym, yes))
 					break;
@@ -595,34 +727,45 @@ static void conf(struct menu *menu)
 					show_textbox(NULL, setmod_text, 6, 74);
 			}
 			break;
-		case 4:
+		case 6:
 			if (item_is_tag('t'))
 				sym_set_tristate_value(sym, no);
 			break;
-		case 5:
+		case 7:
 			if (item_is_tag('t'))
 				sym_set_tristate_value(sym, mod);
 			break;
-		case 6:
+		case 8:
 			if (item_is_tag('t'))
 				sym_toggle_tristate_value(sym);
 			else if (item_is_tag('m'))
-				conf(submenu);
+				conf(submenu, NULL);
 			break;
-		case 7:
+		case 9:
 			search_conf();
 			break;
-		case 8:
+		case 10:
 			show_all_options = !show_all_options;
 			break;
 		}
 	}
+
+	list_del(trail.prev);
 }
 
-static void show_textbox(const char *title, const char *text, int r, int c)
+static int show_textbox_ext(const char *title, char *text, int r, int c, int
+			    *keys, int *vscroll, int *hscroll, update_text_fn
+			    update_text, void *data)
 {
 	dialog_clear();
-	dialog_textbox(title, text, r, c);
+	return dialog_textbox(title, text, r, c, keys, vscroll, hscroll,
+			      update_text, data);
+}
+
+static void show_textbox(const char *title, const char *text, int r, int c)
+{
+	show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL,
+			 NULL, NULL);
 }
 
 static void show_helptext(const char *title, const char *text)
@@ -630,6 +773,17 @@ static void show_helptext(const char *title, const char *text)
 	show_textbox(title, text, 0, 0);
 }
 
+static void conf_message_callback(const char *fmt, va_list ap)
+{
+	char buf[PATH_MAX+1];
+
+	vsnprintf(buf, sizeof(buf), fmt, ap);
+	if (save_and_exit)
+		printf("%s", buf);
+	else
+		show_textbox(NULL, buf, 6, 60);
+}
+
 static void show_help(struct menu *menu)
 {
 	struct gstr help = str_new();
@@ -798,6 +952,8 @@ static int handle_exit(void)
 {
 	int res;
 
+	save_and_exit = 1;
+	reset_subtitle();
 	dialog_clear();
 	if (conf_get_changed())
 		res = dialog_yesno(NULL,
@@ -830,6 +986,8 @@ static int handle_exit(void)
 		fprintf(stderr, _("\n\n"
 				  "Your configuration changes were NOT saved."
 				  "\n\n"));
+		if (res != KEY_ESC)
+			res = 0;
 	}
 
 	return res;
@@ -860,9 +1018,6 @@ int main(int ac, char **av)
 			single_menu_mode = 1;
 	}
 
-	initscr();
-
-	getyx(stdscr, saved_y, saved_x);
 	if (init_dialog(NULL)) {
 		fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
 		fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
@@ -870,8 +1025,9 @@ int main(int ac, char **av)
 	}
 
 	set_config_filename(conf_get_configname());
+	conf_set_message_callback(conf_message_callback);
 	do {
-		conf(&rootmenu);
+		conf(&rootmenu, NULL);
 		res = handle_exit();
 	} while (res == KEY_ESC);
 
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 8c2a97e..fd3f018 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -48,7 +48,7 @@ void menu_add_entry(struct symbol *sym)
 {
 	struct menu *menu;
 
-	menu = malloc(sizeof(*menu));
+	menu = xmalloc(sizeof(*menu));
 	memset(menu, 0, sizeof(*menu));
 	menu->sym = sym;
 	menu->parent = current_menu;
@@ -146,11 +146,24 @@ struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *e
 			struct menu *menu = current_entry;
 
 			while ((menu = menu->parent) != NULL) {
+				struct expr *dup_expr;
+
 				if (!menu->visibility)
 					continue;
+				/*
+				 * Do not add a reference to the
+				 * menu's visibility expression but
+				 * use a copy of it.  Otherwise the
+				 * expression reduction functions
+				 * will modify expressions that have
+				 * multiple references which can
+				 * cause unwanted side effects.
+				 */
+				dup_expr = expr_copy(menu->visibility);
+
 				prop->visible.expr
 					= expr_alloc_and(prop->visible.expr,
-							 menu->visibility);
+							 dup_expr);
 			}
 		}
 
@@ -507,27 +520,53 @@ const char *menu_get_help(struct menu *menu)
 		return "";
 }
 
-static void get_prompt_str(struct gstr *r, struct property *prop)
+static void get_prompt_str(struct gstr *r, struct property *prop,
+			   struct list_head *head)
 {
 	int i, j;
-	struct menu *submenu[8], *menu;
+	struct menu *submenu[8], *menu, *location = NULL;
+	struct jump_key *jump;
 
 	str_printf(r, _("Prompt: %s\n"), _(prop->text));
-	str_printf(r, _("  Defined at %s:%d\n"), prop->menu->file->name,
-		prop->menu->lineno);
-	if (!expr_is_yes(prop->visible.expr)) {
-		str_append(r, _("  Depends on: "));
-		expr_gstr_print(prop->visible.expr, r);
-		str_append(r, "\n");
-	}
 	menu = prop->menu->parent;
-	for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent)
+	for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) {
+		bool accessible = menu_is_visible(menu);
+
 		submenu[i++] = menu;
+		if (location == NULL && accessible)
+			location = menu;
+	}
+	if (head && location) {
+		jump = xmalloc(sizeof(struct jump_key));
+
+		if (menu_is_visible(prop->menu)) {
+			/*
+			 * There is not enough room to put the hint at the
+			 * beginning of the "Prompt" line. Put the hint on the
+			 * last "Location" line even when it would belong on
+			 * the former.
+			 */
+			jump->target = prop->menu;
+		} else
+			jump->target = location;
+
+		if (list_empty(head))
+			jump->index = 0;
+		else
+			jump->index = list_entry(head->prev, struct jump_key,
+						 entries)->index + 1;
+
+		list_add_tail(&jump->entries, head);
+	}
+
 	if (i > 0) {
 		str_printf(r, _("  Location:\n"));
 		for (j = 4; --i >= 0; j += 2) {
 			menu = submenu[i];
-			str_printf(r, "%*c-> %s", j, ' ', _(menu_get_prompt(menu)));
+			if (head && location && menu == location)
+				jump->offset = r->len - 1;
+			str_printf(r, "%*c-> %s", j, ' ',
+				   _(menu_get_prompt(menu)));
 			if (menu->sym) {
 				str_printf(r, " (%s [=%s])", menu->sym->name ?
 					menu->sym->name : _("<choice>"),
@@ -538,7 +577,23 @@ static void get_prompt_str(struct gstr *r, struct property *prop)
 	}
 }
 
-void get_symbol_str(struct gstr *r, struct symbol *sym)
+/*
+ * get peoperty of type P_SYMBOL
+ */
+static struct property *get_symbol_prop(struct symbol *sym)
+{
+	struct property *prop = NULL;
+
+	for_all_properties(sym, prop, P_SYMBOL)
+		break;
+	return prop;
+}
+
+/*
+ * head is optional and may be NULL
+ */
+void get_symbol_str(struct gstr *r, struct symbol *sym,
+		    struct list_head *head)
 {
 	bool hit;
 	struct property *prop;
@@ -557,7 +612,19 @@ void get_symbol_str(struct gstr *r, struct symbol *sym)
 		}
 	}
 	for_all_prompts(sym, prop)
-		get_prompt_str(r, prop);
+		get_prompt_str(r, prop, head);
+
+	prop = get_symbol_prop(sym);
+	if (prop) {
+		str_printf(r, _("  Defined at %s:%d\n"), prop->menu->file->name,
+			prop->menu->lineno);
+		if (!expr_is_yes(prop->visible.expr)) {
+			str_append(r, _("  Depends on: "));
+			expr_gstr_print(prop->visible.expr, r);
+			str_append(r, "\n");
+		}
+	}
+
 	hit = false;
 	for_all_properties(sym, prop, P_SELECT) {
 		if (!hit) {
@@ -577,14 +644,14 @@ void get_symbol_str(struct gstr *r, struct symbol *sym)
 	str_append(r, "\n\n");
 }
 
-struct gstr get_relations_str(struct symbol **sym_arr)
+struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head)
 {
 	struct symbol *sym;
 	struct gstr res = str_new();
 	int i;
 
 	for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
-		get_symbol_str(&res, sym);
+		get_symbol_str(&res, sym, head);
 	if (!i)
 		str_append(&res, _("No matches found.\n"));
 	return res;
@@ -603,5 +670,5 @@ void menu_get_ext_help(struct menu *menu, struct gstr *help)
 	}
 	str_printf(help, "%s\n", _(help_text));
 	if (sym)
-		get_symbol_str(help, sym);
+		get_symbol_str(help, sym, NULL);
 }
diff --git a/scripts/kconfig/merge_config.sh b/scripts/kconfig/merge_config.sh
new file mode 100755
index 0000000..81b0c61
--- /dev/null
+++ b/scripts/kconfig/merge_config.sh
@@ -0,0 +1,150 @@
+#!/bin/sh
+#  merge_config.sh - Takes a list of config fragment values, and merges
+#  them one by one. Provides warnings on overridden values, and specified
+#  values that did not make it to the resulting .config file (due to missed
+#  dependencies or config symbol removal).
+#
+#  Portions reused from kconf_check and generate_cfg:
+#  http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/kconf_check
+#  http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/generate_cfg
+#
+#  Copyright (c) 2009-2010 Wind River Systems, Inc.
+#  Copyright 2011 Linaro
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License version 2 as
+#  published by the Free Software Foundation.
+#
+#  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.
+
+clean_up() {
+	rm -f $TMP_FILE
+	exit
+}
+trap clean_up HUP INT TERM
+
+usage() {
+	echo "Usage: $0 [OPTIONS] [CONFIG [...]]"
+	echo "  -h    display this help text"
+	echo "  -m    only merge the fragments, do not execute the make command"
+	echo "  -n    use allnoconfig instead of alldefconfig"
+	echo "  -r    list redundant entries when merging fragments"
+	echo "  -O    dir to put generated output files"
+}
+
+MAKE=true
+ALLTARGET=alldefconfig
+WARNREDUN=false
+OUTPUT=.
+
+while true; do
+	case $1 in
+	"-n")
+		ALLTARGET=allnoconfig
+		shift
+		continue
+		;;
+	"-m")
+		MAKE=false
+		shift
+		continue
+		;;
+	"-h")
+		usage
+		exit
+		;;
+	"-r")
+		WARNREDUN=true
+		shift
+		continue
+		;;
+	"-O")
+		if [ -d $2 ];then
+			OUTPUT=$(echo $2 | sed 's/\/*$//')
+		else
+			echo "output directory $2 does not exist" 1>&2
+			exit 1
+		fi
+		shift 2
+		continue
+		;;
+	*)
+		break
+		;;
+	esac
+done
+
+INITFILE=$1
+shift;
+
+MERGE_LIST=$*
+SED_CONFIG_EXP="s/^\(# \)\{0,1\}\(CONFIG_[a-zA-Z0-9_]*\)[= ].*/\2/p"
+TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX)
+
+echo "Using $INITFILE as base"
+cat $INITFILE > $TMP_FILE
+
+# Merge files, printing warnings on overrided values
+for MERGE_FILE in $MERGE_LIST ; do
+	echo "Merging $MERGE_FILE"
+	CFG_LIST=$(sed -n "$SED_CONFIG_EXP" $MERGE_FILE)
+
+	for CFG in $CFG_LIST ; do
+		grep -q -w $CFG $TMP_FILE
+		if [ $? -eq 0 ] ; then
+			PREV_VAL=$(grep -w $CFG $TMP_FILE)
+			NEW_VAL=$(grep -w $CFG $MERGE_FILE)
+			if [ "x$PREV_VAL" != "x$NEW_VAL" ] ; then
+			echo Value of $CFG is redefined by fragment $MERGE_FILE:
+			echo Previous  value: $PREV_VAL
+			echo New value:       $NEW_VAL
+			echo
+			elif [ "$WARNREDUN" = "true" ]; then
+			echo Value of $CFG is redundant by fragment $MERGE_FILE:
+			fi
+			sed -i "/$CFG[ =]/d" $TMP_FILE
+		fi
+	done
+	cat $MERGE_FILE >> $TMP_FILE
+done
+
+if [ "$MAKE" = "false" ]; then
+	cp $TMP_FILE $OUTPUT/.config
+	echo "#"
+	echo "# merged configuration written to $OUTPUT/.config (needs make)"
+	echo "#"
+	clean_up
+	exit
+fi
+
+# If we have an output dir, setup the O= argument, otherwise leave
+# it blank, since O=. will create an unnecessary ./source softlink
+OUTPUT_ARG=""
+if [ "$OUTPUT" != "." ] ; then
+	OUTPUT_ARG="O=$OUTPUT"
+fi
+
+
+# Use the merged file as the starting point for:
+# alldefconfig: Fills in any missing symbols with Kconfig default
+# allnoconfig: Fills in any missing symbols with # CONFIG_* is not set
+make KCONFIG_ALLCONFIG=$TMP_FILE $OUTPUT_ARG $ALLTARGET
+
+
+# Check all specified config values took (might have missed-dependency issues)
+for CFG in $(sed -n "$SED_CONFIG_EXP" $TMP_FILE); do
+
+	REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE)
+	ACTUAL_VAL=$(grep -w -e "$CFG" $OUTPUT/.config)
+	if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then
+		echo "Value requested for $CFG not in final .config"
+		echo "Requested value:  $REQUESTED_VAL"
+		echo "Actual value:     $ACTUAL_VAL"
+		echo ""
+	fi
+done
+
+clean_up
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index 73070cb..dbf31ed 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -7,215 +7,208 @@
  */
 #define _GNU_SOURCE
 #include <string.h>
+#include <stdlib.h>
 
 #include "lkc.h"
 #include "nconf.h"
 #include <ctype.h>
 
-static const char nconf_readme[] = N_(
-"Overview\n"
-"--------\n"
-"This interface let you select features and parameters for the build.\n"
-"Features can either be built-in, modularized, or ignored. Parameters\n"
-"must be entered in as decimal or hexadecimal numbers or text.\n"
+static const char nconf_global_help[] = N_(
+"Help windows\n"
+"------------\n"
+"o  Global help:  Unless in a data entry window, pressing <F1> will give \n"
+"   you the global help window, which you are just reading.\n"
 "\n"
-"Menu items beginning with following braces represent features that\n"
-"  [ ] can be built in or removed\n"
-"  < > can be built in, modularized or removed\n"
-"  { } can be built in or modularized (selected by other feature)\n"
-"  - - are selected by other feature,\n"
-"  XXX cannot be selected. Use Symbol Info to find out why,\n"
-"while *, M or whitespace inside braces means to build in, build as\n"
-"a module or to exclude the feature respectively.\n"
+"o  A short version of the global help is available by pressing <F3>.\n"
 "\n"
-"To change any of these features, highlight it with the cursor\n"
-"keys and press <Y> to build it in, <M> to make it a module or\n"
-"<N> to removed it.  You may also press the <Space Bar> to cycle\n"
-"through the available options (ie. Y->N->M->Y).\n"
+"o  Local help:  To get help related to the current menu entry, use any\n"
+"   of <?> <h>, or if in a data entry window then press <F1>.\n"
 "\n"
-"Some additional keyboard hints:\n"
 "\n"
-"Menus\n"
-"----------\n"
-"o  Use the Up/Down arrow keys (cursor keys) to highlight the item\n"
-"   you wish to change use <Enter> or <Space>. Goto submenu by \n"
-"   pressing <Enter> of <right-arrow>. Use <Esc> or <left-arrow> to go back.\n"
-"   Submenus are designated by \"--->\".\n"
-"\n"
-"   Searching: pressing '/' triggers interactive search mode.\n"
-"              nconfig performs a case insensitive search for the string\n"
-"              in the menu prompts (no regex support).\n"
-"              Pressing the up/down keys highlights the previous/next\n"
-"              matching item. Backspace removes one character from the\n"
-"              match string. Pressing either '/' again or ESC exits\n"
-"              search mode. All other keys behave normally.\n"
+"Menu entries\n"
+"------------\n"
+"This interface lets you select features and parameters for the kernel\n"
+"build.  Kernel features can either be built-in, modularized, or removed.\n"
+"Parameters must be entered as text or decimal or hexadecimal numbers.\n"
 "\n"
-"   You may also use the <PAGE UP> and <PAGE DOWN> keys to scroll\n"
-"   unseen options into view.\n"
+"Menu entries beginning with following braces represent features that\n"
+"  [ ]  can be built in or removed\n"
+"  < >  can be built in, modularized or removed\n"
+"  { }  can be built in or modularized, are selected by another feature\n"
+"  - -  are selected by another feature\n"
+"  XXX  cannot be selected.  Symbol Info <F2> tells you why.\n"
+"*, M or whitespace inside braces means to build in, build as a module\n"
+"or to exclude the feature respectively.\n"
 "\n"
-"o  To exit a menu use the just press <ESC> <F5> <F8> or <left-arrow>.\n"
+"To change any of these features, highlight it with the movement keys\n"
+"listed below and press <y> to build it in, <m> to make it a module or\n"
+"<n> to remove it.  You may press the <Space> key to cycle through the\n"
+"available options.\n"
 "\n"
-"o  To get help with an item, press <F1>\n"
-"   Shortcut: Press <h> or <?>.\n"
+"A trailing \"--->\" designates a submenu.\n"
 "\n"
 "\n"
-"Radiolists  (Choice lists)\n"
-"-----------\n"
-"o  Use the cursor keys to select the option you wish to set and press\n"
-"   <S> or the <SPACE BAR>.\n"
+"Menu navigation keys\n"
+"----------------------------------------------------------------------\n"
+"Linewise up                 <Up>\n"
+"Linewise down               <Down>\n"
+"Pagewise up                 <Page Up>\n"
+"Pagewise down               <Page Down>\n"
+"First entry                 <Home>\n"
+"Last entry                  <End>\n"
+"Enter a submenu             <Right>  <Enter>\n"
+"Go back to parent menu      <Left>   <Esc>  <F5>\n"
+"Close a help window         <Enter>  <Esc>  <F5>\n"
+"Close entry window, apply   <Enter>\n"
+"Close entry window, forget  <Esc>  <F5>\n"
+"Start incremental, case-insensitive search for STRING in menu entries,\n"
+"    no regex support, STRING is displayed in upper left corner\n"
+"                            </>STRING\n"
+"    Remove last character   <Backspace>\n"
+"    Jump to next hit        <Down>\n"
+"    Jump to previous hit    <Up>\n"
+"Exit menu search mode       </>  <Esc>\n"
+"Search for configuration variables with or without leading CONFIG_\n"
+"                            <F8>RegExpr<Enter>\n"
+"Verbose search help         <F8><F1>\n"
+"----------------------------------------------------------------------\n"
 "\n"
-"   Shortcut: Press the first letter of the option you wish to set then\n"
-"             press <S> or <SPACE BAR>.\n"
+"Unless in a data entry window, key <1> may be used instead of <F1>,\n"
+"<2> instead of <F2>, etc.\n"
 "\n"
-"o  To see available help for the item, press <F1>\n"
-"   Shortcut: Press <H> or <?>.\n"
 "\n"
+"Radiolist (Choice list)\n"
+"-----------------------\n"
+"Use the movement keys listed above to select the option you wish to set\n"
+"and press <Space>.\n"
 "\n"
-"Data Entry\n"
-"-----------\n"
-"o  Enter the requested information and press <ENTER>\n"
-"   If you are entering hexadecimal values, it is not necessary to\n"
-"   add the '0x' prefix to the entry.\n"
 "\n"
-"o  For help, press <F1>.\n"
+"Data entry\n"
+"----------\n"
+"Enter the requested information and press <Enter>.  Hexadecimal values\n"
+"may be entered without the \"0x\" prefix.\n"
 "\n"
 "\n"
-"Text Box    (Help Window)\n"
-"--------\n"
-"o  Use the cursor keys to scroll up/down/left/right.  The VI editor\n"
-"   keys h,j,k,l function here as do <SPACE BAR> for those\n"
-"   who are familiar with less and lynx.\n"
+"Text Box (Help Window)\n"
+"----------------------\n"
+"Use movement keys as listed in table above.\n"
 "\n"
-"o  Press <Enter>, <F1>, <F5>, <F7> or <Esc> to exit.\n"
+"Press any of <Enter> <Esc> <q> <F5> <F9> to exit.\n"
 "\n"
 "\n"
-"Alternate Configuration Files\n"
+"Alternate configuration files\n"
 "-----------------------------\n"
-"nconfig supports the use of alternate configuration files for\n"
-"those who, for various reasons, find it necessary to switch\n"
-"between different configurations.\n"
+"nconfig supports switching between different configurations.\n"
+"Press <F6> to save your current configuration.  Press <F7> and enter\n"
+"a file name to load a previously saved configuration.\n"
 "\n"
-"At the end of the main menu you will find two options.  One is\n"
-"for saving the current configuration to a file of your choosing.\n"
-"The other option is for loading a previously saved alternate\n"
-"configuration.\n"
 "\n"
-"Even if you don't use alternate configuration files, but you\n"
-"find during a nconfig session that you have completely messed\n"
-"up your settings, you may use the \"Load Alternate...\" option to\n"
-"restore your previously saved settings from \".config\" without\n"
-"restarting nconfig.\n"
+"Terminal configuration\n"
+"----------------------\n"
+"If you use nconfig in a xterm window, make sure your TERM environment\n"
+"variable specifies a terminal configuration which supports at least\n"
+"16 colors.  Otherwise nconfig will look rather bad.\n"
 "\n"
-"Other information\n"
-"-----------------\n"
-"If you use nconfig in an XTERM window make sure you have your\n"
-"$TERM variable set to point to a xterm definition which supports color.\n"
-"Otherwise, nconfig will look rather bad.  nconfig will not\n"
-"display correctly in a RXVT window because rxvt displays only one\n"
-"intensity of color, bright.\n"
+"If the \"stty size\" command reports the current terminalsize correctly,\n"
+"nconfig will adapt to sizes larger than the traditional 80x25 \"standard\"\n"
+"and display longer menus properly.\n"
 "\n"
-"nconfig will display larger menus on screens or xterms which are\n"
-"set to display more than the standard 25 row by 80 column geometry.\n"
-"In order for this to work, the \"stty size\" command must be able to\n"
-"display the screen's current row and column geometry.  I STRONGLY\n"
-"RECOMMEND that you make sure you do NOT have the shell variables\n"
-"LINES and COLUMNS exported into your environment.  Some distributions\n"
-"export those variables via /etc/profile.  Some ncurses programs can\n"
-"become confused when those variables (LINES & COLUMNS) don't reflect\n"
-"the true screen size.\n"
 "\n"
-"Optional personality available\n"
-"------------------------------\n"
-"If you prefer to have all of the options listed in a single menu, rather\n"
-"than the default multimenu hierarchy, run the nconfig with NCONFIG_MODE\n"
-"environment variable set to single_menu. Example:\n"
+"Single menu mode\n"
+"----------------\n"
+"If you prefer to have all of the menu entries listed in a single menu,\n"
+"rather than the default multimenu hierarchy, run nconfig with\n"
+"NCONFIG_MODE environment variable set to single_menu.  Example:\n"
 "\n"
 "make NCONFIG_MODE=single_menu nconfig\n"
 "\n"
-"<Enter> will then unroll the appropriate category, or enfold it if it\n"
-"is already unrolled.\n"
+"<Enter> will then unfold the appropriate category, or fold it if it\n"
+"is already unfolded.  Folded menu entries will be designated by a\n"
+"leading \"++>\" and unfolded entries by a leading \"-->\".\n"
 "\n"
-"Note that this mode can eventually be a little more CPU expensive\n"
-"(especially with a larger number of unrolled categories) than the\n"
-"default mode.\n"
+"Note that this mode can eventually be a little more CPU expensive than\n"
+"the default mode, especially with a larger number of unfolded submenus.\n"
 "\n"),
 menu_no_f_instructions[] = N_(
-" You do not have function keys support. Please follow the\n"
-" following instructions:\n"
-" Arrow keys navigate the menu.\n"
-" <Enter> or <right-arrow> selects submenus --->.\n"
-" Capital Letters are hotkeys.\n"
-" Pressing <Y> includes, <N> excludes, <M> modularizes features.\n"
-" Pressing SpaceBar toggles between the above options.\n"
-" Press <Esc> or <left-arrow> to go back one menu,\n"
-" <?> or <h> for Help, </> for Search.\n"
-" <1> is interchangeable with <F1>, <2> with <F2>, etc.\n"
-" Legend: [*] built-in  [ ] excluded  <M> module  < > module capable.\n"
-" <Esc> always leaves the current window.\n"),
+"Legend:  [*] built-in  [ ] excluded  <M> module  < > module capable.\n"
+"Submenus are designated by a trailing \"--->\".\n"
+"\n"
+"Use the following keys to navigate the menus:\n"
+"Move up or down with <Up> and <Down>.\n"
+"Enter a submenu with <Enter> or <Right>.\n"
+"Exit a submenu to its parent menu with <Esc> or <Left>.\n"
+"Pressing <y> includes, <n> excludes, <m> modularizes features.\n"
+"Pressing <Space> cycles through the available options.\n"
+"To search for menu entries press </>.\n"
+"<Esc> always leaves the current window.\n"
+"\n"
+"You do not have function keys support.\n"
+"Press <1> instead of <F1>, <2> instead of <F2>, etc.\n"
+"For verbose global help use key <1>.\n"
+"For help related to the current menu entry press <?> or <h>.\n"),
 menu_instructions[] = N_(
-" Arrow keys navigate the menu.\n"
-" <Enter> or <right-arrow> selects submenus --->.\n"
-" Capital Letters are hotkeys.\n"
-" Pressing <Y> includes, <N> excludes, <M> modularizes features.\n"
-" Pressing SpaceBar toggles between the above options\n"
-" Press <Esc>, <F5> or <left-arrow> to go back one menu,\n"
-" <?>, <F1> or <h> for Help, </> for Search.\n"
-" <1> is interchangeable with <F1>, <2> with <F2>, etc.\n"
-" Legend: [*] built-in  [ ] excluded  <M> module  < > module capable.\n"
-" <Esc> always leaves the current window\n"),
+"Legend:  [*] built-in  [ ] excluded  <M> module  < > module capable.\n"
+"Submenus are designated by a trailing \"--->\".\n"
+"\n"
+"Use the following keys to navigate the menus:\n"
+"Move up or down with <Up> or <Down>.\n"
+"Enter a submenu with <Enter> or <Right>.\n"
+"Exit a submenu to its parent menu with <Esc> or <Left>.\n"
+"Pressing <y> includes, <n> excludes, <m> modularizes features.\n"
+"Pressing <Space> cycles through the available options.\n"
+"To search for menu entries press </>.\n"
+"<Esc> always leaves the current window.\n"
+"\n"
+"Pressing <1> may be used instead of <F1>, <2> instead of <F2>, etc.\n"
+"For verbose global help press <F1>.\n"
+"For help related to the current menu entry press <?> or <h>.\n"),
 radiolist_instructions[] = N_(
-" Use the arrow keys to navigate this window or\n"
-" press the hotkey of the item you wish to select\n"
-" followed by the <SPACE BAR>.\n"
-" Press <?>, <F1> or <h> for additional information about this option.\n"),
+"Press <Up>, <Down>, <Home> or <End> to navigate a radiolist, select\n"
+"with <Space>.\n"
+"For help related to the current entry press <?> or <h>.\n"
+"For global help press <F1>.\n"),
 inputbox_instructions_int[] = N_(
 "Please enter a decimal value.\n"
 "Fractions will not be accepted.\n"
-"Press <RETURN> to accept, <ESC> to cancel."),
+"Press <Enter> to apply, <Esc> to cancel."),
 inputbox_instructions_hex[] = N_(
 "Please enter a hexadecimal value.\n"
-"Press <RETURN> to accept, <ESC> to cancel."),
+"Press <Enter> to apply, <Esc> to cancel."),
 inputbox_instructions_string[] = N_(
 "Please enter a string value.\n"
-"Press <RETURN> to accept, <ESC> to cancel."),
+"Press <Enter> to apply, <Esc> to cancel."),
 setmod_text[] = N_(
-"This feature depends on another which\n"
-"has been configured as a module.\n"
-"As a result, this feature will be built as a module."),
+"This feature depends on another feature which has been configured as a\n"
+"module.  As a result, the current feature will be built as a module too."),
 load_config_text[] = N_(
 "Enter the name of the configuration file you wish to load.\n"
-"Accept the name shown to restore the configuration you\n"
-"last retrieved.  Leave blank to abort."),
+"Accept the name shown to restore the configuration you last\n"
+"retrieved.  Leave empty to abort."),
 load_config_help[] = N_(
-"\n"
 "For various reasons, one may wish to keep several different\n"
 "configurations available on a single machine.\n"
 "\n"
 "If you have saved a previous configuration in a file other than the\n"
-"default one, entering its name here will allow you to modify that\n"
-"configuration.\n"
+"default one, entering its name here will allow you to load and modify\n"
+"that configuration.\n"
 "\n"
-"If you are uncertain, then you have probably never used alternate\n"
-"configuration files.  You should therefor leave this blank to abort.\n"),
+"Leave empty to abort.\n"),
 save_config_text[] = N_(
 "Enter a filename to which this configuration should be saved\n"
-"as an alternate.  Leave blank to abort."),
+"as an alternate.  Leave empty to abort."),
 save_config_help[] = N_(
-"\n"
-"For various reasons, one may wish to keep different configurations\n"
-"available on a single machine.\n"
+"For various reasons, one may wish to keep several different\n"
+"configurations available on a single machine.\n"
 "\n"
 "Entering a file name here will allow you to later retrieve, modify\n"
 "and use the current configuration as an alternate to whatever\n"
 "configuration options you have selected at that time.\n"
 "\n"
-"If you are uncertain what all this means then you should probably\n"
-"leave this blank.\n"),
+"Leave empty to abort.\n"),
 search_help[] = N_(
-"\n"
-"Search for symbols and display their relations. Regular expressions\n"
-"are allowed.\n"
-"Example: search for \"^FOO\"\n"
+"Search for symbols (configuration variable names CONFIG_*) and display\n"
+"their relations.  Regular expressions are supported.\n"
+"Example:  Search for \"^FOO\".\n"
 "Result:\n"
 "-----------------------------------------------------------------\n"
 "Symbol: FOO [ = m]\n"
@@ -223,32 +216,32 @@ search_help[] = N_(
 "Defined at drivers/pci/Kconfig:47\n"
 "Depends on: X86_LOCAL_APIC && X86_IO_APIC || IA64\n"
 "Location:\n"
-"  -> Bus options (PCI, PCMCIA, EISA, MCA, ISA)\n"
+"  -> Bus options (PCI, PCMCIA, EISA, ISA)\n"
 "    -> PCI support (PCI [ = y])\n"
 "      -> PCI access mode (<choice> [ = y])\n"
 "Selects: LIBCRC32\n"
 "Selected by: BAR\n"
 "-----------------------------------------------------------------\n"
-"o The line 'Prompt:' shows the text used in the menu structure for\n"
-"  this symbol\n"
-"o The 'Defined at' line tell at what file / line number the symbol\n"
-"  is defined\n"
-"o The 'Depends on:' line tell what symbols needs to be defined for\n"
-"  this symbol to be visible in the menu (selectable)\n"
-"o The 'Location:' lines tell where in the menu structure this symbol\n"
-"  is located\n"
-"    A location followed by a [ = y] indicate that this is a selectable\n"
-"    menu item - and current value is displayed inside brackets.\n"
-"o The 'Selects:' line tell what symbol will be automatically\n"
-"  selected if this symbol is selected (y or m)\n"
-"o The 'Selected by' line tell what symbol has selected this symbol\n"
+"o  The line 'Prompt:' shows the text displayed for this symbol in\n"
+"   the menu hierarchy.\n"
+"o  The 'Defined at' line tells at what file / line number the symbol is\n"
+"   defined.\n"
+"o  The 'Depends on:' line lists symbols that need to be defined for\n"
+"   this symbol to be visible and selectable in the menu.\n"
+"o  The 'Location:' lines tell, where in the menu structure this symbol\n"
+"   is located.  A location followed by a [ = y] indicates that this is\n"
+"   a selectable menu item, and the current value is displayed inside\n"
+"   brackets.\n"
+"o  The 'Selects:' line tells, what symbol will be automatically selected\n"
+"   if this symbol is selected (y or m).\n"
+"o  The 'Selected by' line tells what symbol has selected this symbol.\n"
 "\n"
 "Only relevant lines are shown.\n"
 "\n\n"
 "Search examples:\n"
-"Examples: USB  => find all symbols containing USB\n"
-"          ^USB => find all symbols starting with USB\n"
-"          USB$ => find all symbols ending with USB\n"
+"USB  => find all symbols containing USB\n"
+"^USB => find all symbols starting with USB\n"
+"USB$ => find all symbols ending with USB\n"
 "\n");
 
 struct mitem {
@@ -319,19 +312,19 @@ struct function_keys function_keys[] = {
 	},
 	{
 		.key_str = "F2",
-		.func = "Sym Info",
+		.func = "SymInfo",
 		.key = F_SYMBOL,
 		.handler = handle_f2,
 	},
 	{
 		.key_str = "F3",
-		.func = "Insts",
+		.func = "Help 2",
 		.key = F_INSTS,
 		.handler = handle_f3,
 	},
 	{
 		.key_str = "F4",
-		.func = "Config",
+		.func = "ShowAll",
 		.key = F_CONF,
 		.handler = handle_f4,
 	},
@@ -355,7 +348,7 @@ struct function_keys function_keys[] = {
 	},
 	{
 		.key_str = "F8",
-		.func = "Sym Search",
+		.func = "SymSearch",
 		.key = F_SEARCH,
 		.handler = handle_f8,
 	},
@@ -392,7 +385,7 @@ static void print_function_line(void)
 static void handle_f1(int *key, struct menu *current_item)
 {
 	show_scroll_win(main_window,
-			_("README"), _(nconf_readme));
+			_("Global help"), _(nconf_global_help));
 	return;
 }
 
@@ -407,7 +400,7 @@ static void handle_f2(int *key, struct menu *current_item)
 static void handle_f3(int *key, struct menu *current_item)
 {
 	show_scroll_win(main_window,
-			_("Instructions"),
+			_("Short help"),
 			_(current_instructions));
 	return;
 }
@@ -696,13 +689,18 @@ static void search_conf(void)
 {
 	struct symbol **sym_arr;
 	struct gstr res;
+	struct gstr title;
 	char *dialog_input;
 	int dres;
+
+	title = str_new();
+	str_printf( &title, _("Enter %s (sub)string to search for "
+			      "(with or without \"%s\")"), CONFIG_, CONFIG_);
+
 again:
 	dres = dialog_inputbox(main_window,
 			_("Search Configuration Parameter"),
-			_("Enter " CONFIG_ " (sub)string to search for "
-				"(with or without \"" CONFIG_ "\")"),
+			str_get(&title),
 			"", &dialog_input_result, &dialog_input_result_len);
 	switch (dres) {
 	case 0:
@@ -712,6 +710,7 @@ again:
 				_("Search Configuration"), search_help);
 		goto again;
 	default:
+		str_free(&title);
 		return;
 	}
 
@@ -721,11 +720,12 @@ again:
 		dialog_input += strlen(CONFIG_);
 
 	sym_arr = sym_re_search(dialog_input);
-	res = get_relations_str(sym_arr);
+	res = get_relations_str(sym_arr, NULL);
 	free(sym_arr);
 	show_scroll_win(main_window,
 			_("Search Results"), str_get(&res));
 	str_free(&res);
+	str_free(&title);
 }
 
 
@@ -1503,7 +1503,11 @@ int main(int ac, char **av)
 	}
 
 	notimeout(stdscr, FALSE);
+#if NCURSES_REENTRANT
+	set_escdelay(1);
+#else
 	ESCDELAY = 1;
+#endif
 
 	/* set btns menu */
 	curses_menu = new_menu(curses_menu_items);
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
index 3b18dd8..9f8c44e 100644
--- a/scripts/kconfig/nconf.gui.c
+++ b/scripts/kconfig/nconf.gui.c
@@ -48,7 +48,7 @@ static void set_normal_colors(void)
 	init_pair(INPUT_FIELD, -1, -1);
 
 	init_pair(FUNCTION_HIGHLIGHT, -1, -1);
-	init_pair(FUNCTION_TEXT, COLOR_BLUE, -1);
+	init_pair(FUNCTION_TEXT, COLOR_YELLOW, -1);
 }
 
 /* available attributes:
@@ -604,9 +604,11 @@ void show_scroll_win(WINDOW *main_window,
 		switch (res) {
 		case KEY_NPAGE:
 		case ' ':
+		case 'd':
 			start_y += text_lines-2;
 			break;
 		case KEY_PPAGE:
+		case 'u':
 			start_y -= text_lines+2;
 			break;
 		case KEY_HOME:
@@ -632,10 +634,10 @@ void show_scroll_win(WINDOW *main_window,
 			start_x++;
 			break;
 		}
-		if (res == 10 || res == 27 || res == 'q'
-		    || res == KEY_F(F_BACK) || res == KEY_F(F_EXIT)) {
+		if (res == 10 || res == 27 || res == 'q' ||
+			res == KEY_F(F_HELP) || res == KEY_F(F_BACK) ||
+			res == KEY_F(F_EXIT))
 			break;
-		}
 		if (start_y < 0)
 			start_y = 0;
 		if (start_y >= total_lines-text_lines)
diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
index df274fe..1500c38 100644
--- a/scripts/kconfig/qconf.cc
+++ b/scripts/kconfig/qconf.cc
@@ -6,6 +6,7 @@
 #include <qglobal.h>
 
 #if QT_VERSION < 0x040000
+#include <stddef.h>
 #include <qmainwindow.h>
 #include <qvbox.h>
 #include <qvaluelist.h>
diff --git a/scripts/kconfig/streamline_config.pl b/scripts/kconfig/streamline_config.pl
index ec7afce..060694f 100644
--- a/scripts/kconfig/streamline_config.pl
+++ b/scripts/kconfig/streamline_config.pl
@@ -45,6 +45,16 @@
 use strict;
 use Getopt::Long;
 
+# set the environment variable LOCALMODCONFIG_DEBUG to get
+# debug output.
+my $debugprint = 0;
+$debugprint = 1 if (defined($ENV{LOCALMODCONFIG_DEBUG}));
+
+sub dprint {
+    return if (!$debugprint);
+    print STDERR @_;
+}
+
 my $config = ".config";
 
 my $uname = `uname -r`;
@@ -90,7 +100,7 @@ my @searchconfigs = (
 	},
 );
 
-sub find_config {
+sub read_config {
     foreach my $conf (@searchconfigs) {
 	my $file = $conf->{"file"};
 
@@ -105,13 +115,15 @@ sub find_config {
 
 	print STDERR "using config: '$file'\n";
 
-	open(CIN, "$exec $file |") || die "Failed to run $exec $file";
-	return;
+	open(my $infile, '-|', "$exec $file") || die "Failed to run $exec $file";
+	my @x = <$infile>;
+	close $infile;
+	return @x;
     }
     die "No config file found";
 }
 
-find_config;
+my @config_file = read_config;
 
 # Parse options
 my $localmodconfig = 0;
@@ -121,7 +133,7 @@ GetOptions("localmodconfig" => \$localmodconfig,
 	   "localyesconfig" => \$localyesconfig);
 
 # Get the build source and top level Kconfig file (passed in)
-my $ksource = $ARGV[0];
+my $ksource = ($ARGV[0] ? $ARGV[0] : '.');
 my $kconfig = $ARGV[1];
 my $lsmod_file = $ENV{'LSMOD'};
 
@@ -144,7 +156,6 @@ sub read_kconfig {
 
     my $state = "NONE";
     my $config;
-    my @kconfigs;
 
     my $cont = 0;
     my $line;
@@ -159,8 +170,8 @@ sub read_kconfig {
 	$source =~ s/\$$env/$ENV{$env}/;
     }
 
-    open(KIN, "$source") || die "Can't open $kconfig";
-    while (<KIN>) {
+    open(my $kinfile, '<', $source) || die "Can't open $kconfig";
+    while (<$kinfile>) {
 	chomp;
 
 	# Make sure that lines ending with \ continue
@@ -178,7 +189,13 @@ sub read_kconfig {
 
 	# collect any Kconfig sources
 	if (/^source\s*"(.*)"/) {
-	    $kconfigs[$#kconfigs+1] = $1;
+	    my $kconfig = $1;
+	    # prevent reading twice.
+	    if (!defined($read_kconfigs{$kconfig})) {
+		$read_kconfigs{$kconfig} = 1;
+		read_kconfig($kconfig);
+	    }
+	    next;
 	}
 
 	# configs found
@@ -186,6 +203,7 @@ sub read_kconfig {
 	    $state = "NEW";
 	    $config = $2;
 
+	    # Add depends for 'if' nesting
 	    for (my $i = 0; $i < $iflevel; $i++) {
 		if ($i) {
 		    $depends{$config} .= " " . $ifdeps[$i];
@@ -204,10 +222,11 @@ sub read_kconfig {
 
 	# Get the configs that select this config
 	} elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) {
-	    if (defined($selects{$1})) {
-		$selects{$1} .= " " . $config;
+	    my $conf = $1;
+	    if (defined($selects{$conf})) {
+		$selects{$conf} .= " " . $config;
 	    } else {
-		$selects{$1} = $config;
+		$selects{$conf} = $config;
 	    }
 
 	# configs without prompts must be selected
@@ -235,48 +254,70 @@ sub read_kconfig {
 	    $state = "NONE";
 	}
     }
-    close(KIN);
-
-    # read in any configs that were found.
-    foreach $kconfig (@kconfigs) {
-	if (!defined($read_kconfigs{$kconfig})) {
-	    $read_kconfigs{$kconfig} = 1;
-	    read_kconfig($kconfig);
-	}
-    }
+    close($kinfile);
 }
 
 if ($kconfig) {
     read_kconfig($kconfig);
 }
 
+# Makefiles can use variables to define their dependencies
+sub convert_vars {
+    my ($line, %vars) = @_;
+
+    my $process = "";
+
+    while ($line =~ s/^(.*?)(\$\((.*?)\))//) {
+	my $start = $1;
+	my $variable = $2;
+	my $var = $3;
+
+	if (defined($vars{$var})) {
+	    $process .= $start . $vars{$var};
+	} else {
+	    $process .= $start . $variable;
+	}
+    }
+
+    $process .= $line;
+
+    return $process;
+}
+
 # Read all Makefiles to map the configs to the objects
 foreach my $makefile (@makefiles) {
 
-    my $cont = 0;
+    my $line = "";
+    my %make_vars;
+
+    open(my $infile, '<', $makefile) || die "Can't open $makefile";
+    while (<$infile>) {
+	# if this line ends with a backslash, continue
+	chomp;
+	if (/^(.*)\\$/) {
+	    $line .= $1;
+	    next;
+	}
+
+	$line .= $_;
+	$_ = $line;
+	$line = "";
 
-    open(MIN,$makefile) || die "Can't open $makefile";
-    while (<MIN>) {
 	my $objs;
 
-	# is this a line after a line with a backslash?
-	if ($cont && /(\S.*)$/) {
-	    $objs = $1;
-	}
-	$cont = 0;
+	# Convert variables in a line (could define configs)
+	$_ = convert_vars($_, %make_vars);
 
 	# collect objects after obj-$(CONFIG_FOO_BAR)
 	if (/obj-\$\((CONFIG_[^\)]*)\)\s*[+:]?=\s*(.*)/) {
 	    $var = $1;
 	    $objs = $2;
+
+	# check if variables are set
+	} elsif (/^\s*(\S+)\s*[:]?=\s*(.*\S)/) {
+	    $make_vars{$1} = $2;
 	}
 	if (defined($objs)) {
-	    # test if the line ends with a backslash
-	    if ($objs =~ m,(.*)\\$,) {
-		$objs = $1;
-		$cont = 1;
-	    }
-
 	    foreach my $obj (split /\s+/,$objs) {
 		$obj =~ s/-/_/g;
 		if ($obj =~ /(.*)\.o$/) {
@@ -297,10 +338,11 @@ foreach my $makefile (@makefiles) {
 	    }
 	}
     }
-    close(MIN);
+    close($infile);
 }
 
 my %modules;
+my $linfile;
 
 if (defined($lsmod_file)) {
     if ( ! -f $lsmod_file) {
@@ -310,13 +352,10 @@ if (defined($lsmod_file)) {
 		die "$lsmod_file not found";
 	}
     }
-    if ( -x $lsmod_file) {
-	# the file is executable, run it
-	open(LIN, "$lsmod_file|");
-    } else {
-	# Just read the contents
-	open(LIN, "$lsmod_file");
-    }
+
+    my $otype = ( -x $lsmod_file) ? '-|' : '<';
+    open($linfile, $otype, $lsmod_file);
+
 } else {
 
     # see what modules are loaded on this system
@@ -333,25 +372,36 @@ if (defined($lsmod_file)) {
 	$lsmod = "lsmod";
     }
 
-    open(LIN,"$lsmod|") || die "Can not call lsmod with $lsmod";
+    open($linfile, '-|', $lsmod) || die "Can not call lsmod with $lsmod";
 }
 
-while (<LIN>) {
+while (<$linfile>) {
 	next if (/^Module/);  # Skip the first line.
 	if (/^(\S+)/) {
 		$modules{$1} = 1;
 	}
 }
-close (LIN);
+close ($linfile);
 
 # add to the configs hash all configs that are needed to enable
-# a loaded module.
+# a loaded module. This is a direct obj-${CONFIG_FOO} += bar.o
+# where we know we need bar.o so we add FOO to the list.
 my %configs;
 foreach my $module (keys(%modules)) {
     if (defined($objects{$module})) {
 	my @arr = @{$objects{$module}};
 	foreach my $conf (@arr) {
 	    $configs{$conf} = $module;
+	    dprint "$conf added by direct ($module)\n";
+	    if ($debugprint) {
+		my $c=$conf;
+		$c =~ s/^CONFIG_//;
+		if (defined($depends{$c})) {
+		    dprint " deps = $depends{$c}\n";
+		} else {
+		    dprint " no deps\n";
+		}
+	    }
 	}
     } else {
 	# Most likely, someone has a custom (binary?) module loaded.
@@ -359,9 +409,24 @@ foreach my $module (keys(%modules)) {
     }
 }
 
+# Read the current config, and see what is enabled. We want to
+# ignore configs that we would not enable anyway.
+
+my %orig_configs;
 my $valid = "A-Za-z_0-9";
+
+foreach my $line (@config_file) {
+    $_ = $line;
+
+    if (/(CONFIG_[$valid]*)=(m|y)/) {
+	$orig_configs{$1} = $2;
+    }
+}
+
 my $repeat = 1;
 
+my $depconfig;
+
 #
 # Note, we do not care about operands (like: &&, ||, !) we want to add any
 # config that is in the depend list of another config. This script does
@@ -370,7 +435,7 @@ my $repeat = 1;
 # to keep on. If A was on in the original config, B would not have been
 # and B would not be turned on by this script.
 #
-sub parse_config_dep_select
+sub parse_config_depends
 {
     my ($p) = @_;
 
@@ -381,10 +446,16 @@ sub parse_config_dep_select
 
 	    $p =~ s/^[^$valid]*[$valid]+//;
 
+	    # We only need to process if the depend config is a module
+	    if (!defined($orig_configs{$conf}) || !$orig_configs{conf} eq "m") {
+		next;
+	    }
+
 	    if (!defined($configs{$conf})) {
 		# We must make sure that this config has its
 		# dependencies met.
 		$repeat = 1; # do again
+		dprint "$conf selected by depend $depconfig\n";
 		$configs{$conf} = 1;
 	    }
 	} else {
@@ -393,31 +464,132 @@ sub parse_config_dep_select
     }
 }
 
-while ($repeat) {
-    $repeat = 0;
+# Select is treated a bit differently than depends. We call this
+# when a config has no prompt and requires another config to be
+# selected. We use to just select all configs that selected this
+# config, but found that that can balloon into enabling hundreds
+# of configs that we do not care about.
+#
+# The idea is we look at all the configs that select it. If one
+# is already in our list of configs to enable, then there's nothing
+# else to do. If there isn't, we pick the first config that was
+# enabled in the orignal config and use that.
+sub parse_config_selects
+{
+    my ($config, $p) = @_;
 
-    foreach my $config (keys %configs) {
-	$config =~ s/^CONFIG_//;
+    my $next_config;
+
+    while ($p =~ /[$valid]/) {
+
+	if ($p =~ /^[^$valid]*([$valid]+)/) {
+	    my $conf = "CONFIG_" . $1;
+
+	    $p =~ s/^[^$valid]*[$valid]+//;
+
+	    # Make sure that this config exists in the current .config file
+	    if (!defined($orig_configs{$conf})) {
+		dprint "$conf not set for $config select\n";
+		next;
+	    }
 
-	if (defined($depends{$config})) {
-	    # This config has dependencies. Make sure they are also included
-	    parse_config_dep_select $depends{$config};
+	    # Check if something other than a module selects this config
+	    if (defined($orig_configs{$conf}) && $orig_configs{$conf} ne "m") {
+		dprint "$conf (non module) selects config, we are good\n";
+		# we are good with this
+		return;
+	    }
+	    if (defined($configs{$conf})) {
+		dprint "$conf selects $config so we are good\n";
+		# A set config selects this config, we are good
+		return;
+	    }
+	    # Set this config to be selected
+	    if (!defined($next_config)) {
+		$next_config = $conf;
+	    }
+	} else {
+	    die "this should never happen";
 	}
+    }
 
-	if (defined($prompts{$config}) || !defined($selects{$config})) {
-	    next;
+    # If no possible config selected this, then something happened.
+    if (!defined($next_config)) {
+	print STDERR "WARNING: $config is required, but nothing in the\n";
+	print STDERR "  current config selects it.\n";
+	return;
+    }
+
+    # If we are here, then we found no config that is set and
+    # selects this config. Repeat.
+    $repeat = 1;
+    # Make this config need to be selected
+    $configs{$next_config} = 1;
+    dprint "$next_config selected by select $config\n";
+}
+
+my %process_selects;
+
+# loop through all configs, select their dependencies.
+sub loop_depend {
+    $repeat = 1;
+
+    while ($repeat) {
+	$repeat = 0;
+
+      forloop:
+	foreach my $config (keys %configs) {
+
+	    # If this config is not a module, we do not need to process it
+	    if (defined($orig_configs{$config}) && $orig_configs{$config} ne "m") {
+		next forloop;
+	    }
+
+	    $config =~ s/^CONFIG_//;
+	    $depconfig = $config;
+
+	    if (defined($depends{$config})) {
+		# This config has dependencies. Make sure they are also included
+		parse_config_depends $depends{$config};
+	    }
+
+	    # If the config has no prompt, then we need to check if a config
+	    # that is enabled selected it. Or if we need to enable one.
+	    if (!defined($prompts{$config}) && defined($selects{$config})) {
+		$process_selects{$config} = 1;
+	    }
 	}
+    }
+}
+
+sub loop_select {
+
+    foreach my $config (keys %process_selects) {
+	$config =~ s/^CONFIG_//;
+
+	dprint "Process select $config\n";
 
 	# config has no prompt and must be selected.
-	parse_config_dep_select $selects{$config};
+	parse_config_selects $config, $selects{$config};
     }
 }
 
+while ($repeat) {
+    # Get the first set of configs and their dependencies.
+    loop_depend;
+
+    $repeat = 0;
+
+    # Now we need to see if we have to check selects;
+    loop_select;
+}
+
 my %setconfigs;
 
 # Finally, read the .config file and turn off any module enabled that
 # we could not find a reason to keep enabled.
-while(<CIN>) {
+foreach my $line (@config_file) {
+    $_ = $line;
 
     if (/CONFIG_IKCONFIG/) {
 	if (/# CONFIG_IKCONFIG is not set/) {
@@ -435,6 +607,8 @@ while(<CIN>) {
 	if (defined($configs{$1})) {
 	    if ($localyesconfig) {
 	        $setconfigs{$1} = 'y';
+		print "$1=y\n";
+		next;
 	    } else {
 	        $setconfigs{$1} = $2;
 	    }
@@ -445,7 +619,6 @@ while(<CIN>) {
     }
     print;
 }
-close(CIN);
 
 # Integrity check, make sure all modules that we want enabled do
 # indeed have their configs set.
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 071f00c..ecc5aa5 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -262,11 +262,18 @@ static struct symbol *sym_calc_choice(struct symbol *sym)
 	struct symbol *def_sym;
 	struct property *prop;
 	struct expr *e;
+	int flags;
 
 	/* first calculate all choice values' visibilities */
+	flags = sym->flags;
 	prop = sym_get_choice_prop(sym);
-	expr_list_for_each_sym(prop->expr, e, def_sym)
+	expr_list_for_each_sym(prop->expr, e, def_sym) {
 		sym_calc_visibility(def_sym);
+		if (def_sym->visible != no)
+			flags &= def_sym->flags;
+	}
+
+	sym->flags &= flags | ~SYMBOL_DEF_USER;
 
 	/* is the user choice visible? */
 	def_sym = sym->def[S_DEF_USER].val;
@@ -649,11 +656,11 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
 	size = strlen(newval) + 1;
 	if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) {
 		size += 2;
-		sym->def[S_DEF_USER].val = val = malloc(size);
+		sym->def[S_DEF_USER].val = val = xmalloc(size);
 		*val++ = '0';
 		*val++ = 'x';
 	} else if (!oldval || strcmp(oldval, newval))
-		sym->def[S_DEF_USER].val = val = malloc(size);
+		sym->def[S_DEF_USER].val = val = xmalloc(size);
 	else
 		return true;
 
@@ -805,7 +812,7 @@ struct symbol *sym_lookup(const char *name, int flags)
 		hash = 0;
 	}
 
-	symbol = malloc(sizeof(*symbol));
+	symbol = xmalloc(sizeof(*symbol));
 	memset(symbol, 0, sizeof(*symbol));
 	symbol->name = new_name;
 	symbol->type = S_UNKNOWN;
@@ -856,7 +863,7 @@ const char *sym_expand_string_value(const char *in)
 	size_t reslen;
 
 	reslen = strlen(in) + 1;
-	res = malloc(reslen);
+	res = xmalloc(reslen);
 	res[0] = '\0';
 
 	while ((src = strchr(in, '$'))) {
@@ -914,7 +921,7 @@ const char *sym_escape_string_value(const char *in)
 		p++;
 	}
 
-	res = malloc(reslen);
+	res = xmalloc(reslen);
 	res[0] = '\0';
 
 	strcat(res, "\"");
@@ -1221,7 +1228,7 @@ struct property *prop_alloc(enum prop_type type, struct symbol *sym)
 	struct property *prop;
 	struct property **propp;
 
-	prop = malloc(sizeof(*prop));
+	prop = xmalloc(sizeof(*prop));
 	memset(prop, 0, sizeof(*prop));
 	prop->type = type;
 	prop->sym = sym;
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index d0b8b23..6e7fbf1 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -23,7 +23,7 @@ struct file *file_lookup(const char *name)
 		}
 	}
 
-	file = malloc(sizeof(*file));
+	file = xmalloc(sizeof(*file));
 	memset(file, 0, sizeof(*file));
 	file->name = file_name;
 	file->next = file_list;
@@ -81,7 +81,7 @@ int file_write_dep(const char *name)
 struct gstr str_new(void)
 {
 	struct gstr gs;
-	gs.s = malloc(sizeof(char) * 64);
+	gs.s = xmalloc(sizeof(char) * 64);
 	gs.len = 64;
 	gs.max_width = 0;
 	strcpy(gs.s, "\0");
@@ -138,3 +138,22 @@ const char *str_get(struct gstr *gs)
 	return gs->s;
 }
 
+void *xmalloc(size_t size)
+{
+	void *p = malloc(size);
+	if (p)
+		return p;
+	fprintf(stderr, "Out of memory.\n");
+	exit(1);
+}
+
+void *xcalloc(size_t nmemb, size_t size)
+{
+	void *p = calloc(nmemb, size);
+	if (p)
+		return p;
+	fprintf(stderr, "Out of memory.\n");
+	exit(1);
+}
+
+
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 00f9d3a..6555a47 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -40,7 +40,7 @@ static void zconf_endfile(void);
 
 static void new_string(void)
 {
-	text = malloc(START_STRSIZE);
+	text = xmalloc(START_STRSIZE);
 	text_asize = START_STRSIZE;
 	text_size = 0;
 	*text = 0;
@@ -62,7 +62,7 @@ static void append_string(const char *str, int size)
 
 static void alloc_string(const char *str, int size)
 {
-	text = malloc(size + 1);
+	text = xmalloc(size + 1);
 	memcpy(text, str, size);
 	text[size] = 0;
 }
@@ -288,7 +288,7 @@ void zconf_initscan(const char *name)
 		exit(1);
 	}
 
-	current_buf = malloc(sizeof(*current_buf));
+	current_buf = xmalloc(sizeof(*current_buf));
 	memset(current_buf, 0, sizeof(*current_buf));
 
 	current_file = file_lookup(name);
@@ -299,7 +299,7 @@ void zconf_nextfile(const char *name)
 {
 	struct file *iter;
 	struct file *file = file_lookup(name);
-	struct buffer *buf = malloc(sizeof(*buf));
+	struct buffer *buf = xmalloc(sizeof(*buf));
 	memset(buf, 0, sizeof(*buf));
 
 	current_buf->state = YY_CURRENT_BUFFER;
diff --git a/scripts/kconfig/zconf.lex.c_shipped b/scripts/kconfig/zconf.lex.c_shipped
index c32b1a4..a0521aa 100644
--- a/scripts/kconfig/zconf.lex.c_shipped
+++ b/scripts/kconfig/zconf.lex.c_shipped
@@ -802,7 +802,7 @@ static void zconf_endfile(void);
 
 static void new_string(void)
 {
-	text = malloc(START_STRSIZE);
+	text = xmalloc(START_STRSIZE);
 	text_asize = START_STRSIZE;
 	text_size = 0;
 	*text = 0;
@@ -824,7 +824,7 @@ static void append_string(const char *str, int size)
 
 static void alloc_string(const char *str, int size)
 {
-	text = malloc(size + 1);
+	text = xmalloc(size + 1);
 	memcpy(text, str, size);
 	text[size] = 0;
 }
@@ -2343,7 +2343,7 @@ void zconf_initscan(const char *name)
 		exit(1);
 	}
 
-	current_buf = malloc(sizeof(*current_buf));
+	current_buf = xmalloc(sizeof(*current_buf));
 	memset(current_buf, 0, sizeof(*current_buf));
 
 	current_file = file_lookup(name);
@@ -2354,7 +2354,7 @@ void zconf_nextfile(const char *name)
 {
 	struct file *iter;
 	struct file *file = file_lookup(name);
-	struct buffer *buf = malloc(sizeof(*buf));
+	struct buffer *buf = xmalloc(sizeof(*buf));
 	memset(buf, 0, sizeof(*buf));
 
 	current_buf->state = YY_CURRENT_BUFFER;
diff --git a/scripts/kconfig/zconf.tab.c_shipped b/scripts/kconfig/zconf.tab.c_shipped
index 877acaf..aacc199 100644
--- a/scripts/kconfig/zconf.tab.c_shipped
+++ b/scripts/kconfig/zconf.tab.c_shipped
@@ -1,19 +1,22 @@
 /* A Bison parser, made by GNU Bison 2.4.3.  */
 
 /* Skeleton implementation for Bison's Yacc-like parsers in C
-   
+
       Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
    2009, 2010 Free Software Foundation, Inc.
-   
+
    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 3 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. */
+   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, see <http://www.gnu.org/licenses/>.  */
 
 /* As a special exception, you may create a larger work that contains
    part or all of the Bison parser skeleton and distribute that work
@@ -24,7 +27,7 @@
    special exception, which will cause the skeleton and the resulting
    Bison output files to be licensed under the GNU General Public
    License without this special exception.
-   
+
    This special exception was added by the Free Software Foundation in
    version 2.2 of Bison.  */
 
-- 
1.8.3.1



From chf.fritz at googlemail.com  Fri Jun 21 05:53:30 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Fri, 21 Jun 2013 11:53:30 +0200
Subject: [PATCH 0/2] OMAP: Boot from UBI
Message-ID: <1371808410.3949.13.camel@mars>

This small set of patches adds boot from UBI support on OMAP SoCs:
MLO attaches UBI, loads barebox from within a static volume and
goes up from there.
The benefit: NAND wearleveling is also done for barebox.

A NAND layout can now look like this:

       +------------+-->0x00000000-> xload start   (MLO copy on 1st block)
       |            |
       |            |-->0x0001FFFF-> xload end
       |            |-->0x00020000-> xload1 start   (MLO backup copy on 2rd)
       |            |
       |            |-->0x0003FFFF-> xload1 end
       |            |-->0x00040000-> xload2 start   (MLO backup copy on 3rd)
       |            |
       |            |-->0x0005FFFF-> xload2 end
       |            |-->0x00060000-> xload3 start   (MLO backup copy on 4rd)
       |            |
       |            |-->0x0007FFFF-> xload3 end
       |            |-->0x00080000-> ubi start
       |            |
       |            |
       |            |     UBI-Volumes:
       |            |           - barebox_0 [1M]
       |            |           - bareboxenv_0 [512k]
       |            |           - kernel_0 [6M]
       |            |           - oftree_0 [512k]
       |            |           - bmp_0 [2M]
       |            |           - root [-]
       |            |
       |            |
       +------------+-->0x0FFFFFFF-> root end

Next step (ToDo) is to decrease boot-time because it takes nearly
six secounds to get to a fully featured barebox-prompt. Possible
solutions are:

 - use UBI Fastmap to decrease scan time
 - only scan UBI once and transfer gained data to next boot stage:
   MLO (scans UBI) -> Barebox (gets data) -> Kernel (gets data)

---
Christoph Fritz (2):
  ARM OMAP: MLO: add support for loading Barebox from UBI
  ARM OMAP: add support for loading Environment from UBI

 arch/arm/mach-omap/Kconfig |   44 +++++++++++++++++++++++++
 arch/arm/mach-omap/xload.c |   76 ++++++++++++++++++++++++++++++++++++++++++--
 common/Kconfig             |   34 ++++++++++++++++++++
 common/startup.c           |   17 ++++++++++
 4 files changed, 169 insertions(+), 2 deletions(-)

-- 
1.7.10.4




From chf.fritz at googlemail.com  Fri Jun 21 05:55:21 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Fri, 21 Jun 2013 11:55:21 +0200
Subject: [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox from UBI
In-Reply-To: <1371808410.3949.13.camel@mars>
References: <1371808410.3949.13.camel@mars>
Message-ID: <1371808521.3949.14.camel@mars>

This patch adds support to OMAP MLO to load a secound
stage bootloader from a static UBI volume.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
 arch/arm/mach-omap/Kconfig |   44 +++++++++++++++++++++++++
 arch/arm/mach-omap/xload.c |   76 ++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 118 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index 236a165..e08524e 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -213,6 +213,50 @@ choice
 
 endchoice
 
+config BB_IN_UBI
+	bool "Load Barebox from an UBI static volume"
+	depends on ARCH_OMAP3
+	depends on UBI
+	depends on OMAP_BUILD_IFT
+	help
+	  Say Y here if you would like to make the MLO load barebox
+	  from an UBI volume if bootsource is NAND.
+
+if BB_IN_UBI
+
+menu "Configure Loading Barebox from UBI"
+
+config BB_IN_UBI_PARTITION_START
+	hex
+	default 0x00080000
+	prompt "Offset size where partition begins"
+	help
+	  Start of mtd partition which holdes UBI volumes for barebox and
+	  barebox-environment. This value depends on your board partition
+	  layout. Default offset is 512k.
+
+config BB_IN_UBI_PARTITION_SIZE
+	hex
+	default 0xff80000
+	prompt "Length of partition"
+	help
+	  Size of mtd partition which holdes UBI volumes for barebox and
+	  barebox-environment. This value depends on your board partition
+	  layout. Default length is set to 255.5MB.
+
+config BB_IN_UBI_VOLNAME
+	string
+	default "ubi0.barebox_0"
+	prompt "Name of UBI static volume holding Barebox"
+	help
+	  Name of UBI static volume holding Barebox inside the mtd
+	  partition. This string value depends on your UBI volume name
+	  configuration scheme. Default string is "ubi0.barebox_0".
+
+endmenu
+
+endif
+
 endif
 
 config MACH_OMAP_ADVANCED_MUX
diff --git a/arch/arm/mach-omap/xload.c b/arch/arm/mach-omap/xload.c
index 3cce3f2..6c51c55 100644
--- a/arch/arm/mach-omap/xload.c
+++ b/arch/arm/mach-omap/xload.c
@@ -9,6 +9,10 @@
 #include <fcntl.h>
 #include <sizes.h>
 #include <filetype.h>
+#include <mtd/ubi-user.h>
+#include <mtd/ubi-media.h>
+#include <linux/mtd/mtd-abi.h>
+#include <asm-generic/ioctl.h>
 
 static void *read_image_head(const char *name)
 {
@@ -82,6 +86,69 @@ static void *omap_xload_boot_nand(int offset)
 	return to;
 }
 
+static void *omap_xload_boot_ubi_nand(void)
+{
+	void *to = NULL;
+#ifdef CONFIG_BB_IN_UBI
+	void *header;
+	int ret;
+	struct cdev *cdev;
+	struct mtd_info_user user;
+	int size;
+
+	devfs_add_partition("nand0", CONFIG_BB_IN_UBI_PARTITION_START,
+		CONFIG_BB_IN_UBI_PARTITION_SIZE, DEVFS_PARTITION_FIXED, "u");
+	dev_add_bb_dev("u", "bbu");
+
+	cdev = cdev_open("u", O_RDONLY);
+	if (!cdev) {
+		printf("cdev_open failed\n");
+		return NULL;
+	}
+
+	ret = cdev_ioctl(cdev, MEMGETINFO, &user);
+	if (!ret)
+		ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0);
+	else {
+		printf("failed to attach: %s\n", strerror(-ret));
+		cdev_close(cdev);
+		return NULL;
+	}
+
+	cdev_close(cdev);
+
+	header = read_image_head(CONFIG_BB_IN_UBI_VOLNAME);
+	if (header == NULL) {
+		printf("failed to read image head\n");
+		return NULL;
+	}
+
+	size = get_image_size(header);
+	if (!size) {
+		printf("failed to get image size\n");
+		return NULL;
+	}
+
+	to = xmalloc(size);
+
+	cdev = cdev_open(CONFIG_BB_IN_UBI_VOLNAME, O_RDONLY);
+	if (!cdev) {
+		printf("cdev_open failed\n");
+		return NULL;
+	}
+
+	if (cdev_read(cdev, to, size, 0, 0) < 0) {
+		printf("cdev_read failed\n");
+		cdev_close(cdev);
+		return NULL;
+        }
+
+	cdev_close(cdev);
+
+#endif
+	return to;
+}
+
 static void *omap_xload_boot_mmc(void)
 {
 	int ret;
@@ -180,8 +247,13 @@ static __noreturn int omap_xload(void)
 			printf("booting from USB not enabled\n");
 		}
 	case BOOTSOURCE_NAND:
-		printf("booting from NAND\n");
-		func = omap_xload_boot_nand(SZ_128K);
+		if (IS_ENABLED(CONFIG_BB_IN_UBI)) {
+			printf("booting from UBI static volume\n");
+			func = omap_xload_boot_ubi_nand();
+		} else {
+			printf("booting from NAND\n");
+			func = omap_xload_boot_nand(SZ_128K);
+		}
 		break;
 	case BOOTSOURCE_SPI:
 		printf("booting from SPI\n");
-- 
1.7.10.4




From chf.fritz at googlemail.com  Fri Jun 21 05:55:56 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Fri, 21 Jun 2013 11:55:56 +0200
Subject: [PATCH 2/2] ARM OMAP: add support for loading Environment from UBI
In-Reply-To: <1371808410.3949.13.camel@mars>
References: <1371808410.3949.13.camel@mars>
Message-ID: <1371808556.3949.15.camel@mars>

This patch adds support to load environment from a static
UBI volume.

Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
---
 common/Kconfig   |   34 ++++++++++++++++++++++++++++++++++
 common/startup.c |   17 +++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index d36ed13..058eb21 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -103,6 +103,40 @@ config MEMINFO
 config ENVIRONMENT_VARIABLES
 	bool "environment variables support"
 
+config ENVIRONMENT_IN_UBI
+	bool "Load Environment from an UBI static volume"
+	depends on UBI
+	depends on ENV_HANDLING
+	help
+	  Say Y here if you would like to attach UBI and load
+	  the environment from an UBI volume.
+
+if ENVIRONMENT_IN_UBI
+
+menu "Configure Loading Environment from UBI"
+
+config ENV_IN_UBI_PARTITION
+	string
+	default "/dev/root"
+	prompt "Filepath of mtd partition holding UBI volumes"
+	help
+	  Filepath of mtd partition holding UBI static volume with Barebox
+	  environment inside.  This value depends on your board partition
+	  layout. Default string value is "/dev/root".
+
+config ENV_IN_UBI_VOLNAME
+	string
+	default "/dev/ubi0.bareboxenv_0"
+	prompt "Filepath of UBI static volume holding environment"
+	help
+	  Filepath of UBI static volume holding Barebox environment inside the
+	  partition. This string value depends on your UBI volume name
+	  configuration scheme. Default string is "/dev/ubi0.bareboxenv_0".
+
+endmenu
+
+endif
+
 menu "memory layout"
 
 source "pbl/Kconfig"
diff --git a/common/startup.c b/common/startup.c
index ff00ca7..01c0e1d 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -117,6 +117,23 @@ void __noreturn start_barebox(void)
 	if (IS_ENABLED(CONFIG_ENV_HANDLING)) {
 		int ret;
 
+		if (IS_ENABLED(CONFIG_ENVIRONMENT_IN_UBI)) {
+#ifdef CONFIG_ENVIRONMENT_IN_UBI
+			char s[PATH_MAX + 32];
+			sprintf(s, "%s%s ", "ubiattach ",
+				CONFIG_ENV_IN_UBI_PARTITION);
+			ret = run_command(s, 0);
+			if (ret) {
+				sprintf(s, "%s%s ", "unable to ubiattach ",
+					CONFIG_ENV_IN_UBI_PARTITION);
+				pr_err(s);
+			} else {
+				default_environment_path =
+					CONFIG_ENV_IN_UBI_VOLNAME;
+			}
+#endif
+		}
+
 		ret = envfs_load(default_environment_path, "/env", 0);
 
 		if (ret && IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT)) {
-- 
1.7.10.4




From jbe at pengutronix.de  Fri Jun 21 08:14:25 2013
From: jbe at pengutronix.de (=?iso-8859-15?q?J=FCrgen_Beisert?=)
Date: Fri, 21 Jun 2013 14:14:25 +0200
Subject: [PATCH 04/17] ARM: MXS: Add MXS specific clk types
In-Reply-To: <1371711261-10039-5-git-send-email-s.hauer@pengutronix.de>
References: <1371711261-10039-1-git-send-email-s.hauer@pengutronix.de>
 <1371711261-10039-5-git-send-email-s.hauer@pengutronix.de>
Message-ID: <201306211414.25514.jbe@pengutronix.de>

With the following patch on top of [PATCH 04/17]:

diff --git a/drivers/clk/mxs/clk-ref.c b/drivers/clk/mxs/clk-ref.c
index d62ebfc..7ff5527 100644
--- a/drivers/clk/mxs/clk-ref.c
+++ b/drivers/clk/mxs/clk-ref.c
@@ -40,6 +40,17 @@ struct clk_ref {
 #define SET	0x4
 #define CLR	0x8
 
+static int clk_ref_is_enabled(struct clk *clk)
+{
+	struct clk_ref *ref = to_clk_ref(clk);
+	u32 reg = readl(ref->reg);
+
+	if (reg & 1 << ((ref->idx + 1) * 8 - 1))
+		return 0;
+
+	return 1;
+}
+
 static int clk_ref_enable(struct clk *clk)
 {
 	struct clk_ref *ref = to_clk_ref(clk);
@@ -118,6 +129,7 @@ static int clk_ref_set_rate(struct clk *clk, unsigned long rate,
 }
 
 static const struct clk_ops clk_ref_ops = {
+	.is_enabled	= clk_ref_is_enabled,
 	.enable		= clk_ref_enable,
 	.disable	= clk_ref_disable,
 	.recalc_rate	= clk_ref_recalc_rate,

...I get the expected output at runtime (e.g. CPU and EMI clocks get
reported as 'enabled'):

luma:/ clk_dump
ref_xtal (rate 24000000, enabled)
    pll (rate 480000000, enabled)
        ref_cpu (rate 454736842, enabled) <---------
            cpu_pll (rate 454736842, enabled)
                cpu (rate 454736842, enabled)
                    hbus (rate 151578947, enabled)
        ref_emi (rate 261818181, enabled) <---------
            emi_pll (rate 130909090, enabled)
                emi_sel (rate 130909090, enabled)
                    emi (rate 130909090, enabled)
        ref_pix (rate 480000000, disabled)
            lcdif_sel (rate 480000000, disabled)
                lcdif_div (rate 480000000, disabled)
                    lcdif (rate 480000000, disabled)
        ref_io (rate 480000000, enabled)
            ssp_sel (rate 480000000, enabled)
                ssp_div (rate 96000000, enabled)
                    ssp (rate 96000000, enabled)
        spdif_div (rate 120000000, enabled)
            spdif (rate 120000000, disabled)
    saif_sel (rate 24000000, enabled)
        saif_div (rate 366, enabled)
            saif (rate 366, disabled)
    gpmi_sel (rate 24000000, enabled)
        gpmi_div (rate 24000000, enabled)
            gpmi (rate 24000000, disabled)
    etm_sel (rate 24000000, enabled)
        etm_div (rate 24000000, enabled)
            etm (rate 24000000, disabled)
    cpu_xtal (rate 24000000, enabled)
    xbus (rate 24000000, enabled)
    emi_xtal (rate 24000000, enabled)
    clk32k_div (rate 32000, enabled)
        clk32k (rate 32000, enabled)
            adc (rate 2000, enabled)
    rtc (rate 31250, enabled)
    dri (rate 24000000, disabled)
    pwm (rate 24000000, disabled)
    filt (rate 24000000, disabled)
    uart (rate 24000000, enabled)

jbe

-- 
Pengutronix e.K. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| Juergen Beisert ? ? ? ? ? ? |
Linux Solutions for Science and Industry ? ? ?| Phone: +49-5121-206917-5128 |
Peiner Str. 6-8, 31137 Hildesheim, Germany ? ?| Fax: ? +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 ? ? ? ? ? ? ?| http://www.pengutronix.de/ ?|


From t.gamez at phytec.de  Fri Jun 21 08:50:18 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Fri, 21 Jun 2013 14:50:18 +0200
Subject: [PATCH 1/2] i2c-omap: Remove cpu_is functions completely
Message-ID: <1371819019-13596-1-git-send-email-t.gamez@phytec.de>

This patch removes the call of the cpu_is_* functions completely
and uses id_tables instead.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 drivers/i2c/busses/i2c-omap.c |   89 +++++++++++++++++++++++++++++++----------
 1 files changed, 67 insertions(+), 22 deletions(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 19d54ee..b2a74c0 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -131,10 +131,17 @@
 #define SYSC_IDLEMODE_SMART		0x2
 #define SYSC_CLOCKACTIVITY_FCLK		0x2
 
+/* i2c driver flags from kernel */
+#define OMAP_I2C_FLAG_RESET_REGS_POSTIDLE	BIT(3)
+#define OMAP_I2C_FLAG_BUS_SHIFT_NONE		0
+#define OMAP_I2C_FLAG_BUS_SHIFT_1		BIT(7)
+#define OMAP_I2C_FLAG_BUS_SHIFT_2		BIT(8)
+#define OMAP_I2C_FLAG_BUS_SHIFT__SHIFT		7
+
 struct omap_i2c_struct {
 	void 			*base;
-	u8			*regs;
 	u8			reg_shift;
+	struct omap_i2c_driver_data	*data;
 	struct resource		*ioarea;
 	u32			speed;		/* Speed of bus in Khz */
 	u16			cmd_err;
@@ -230,22 +237,50 @@ static const u8 omap4_reg_map[] = {
 	[OMAP_I2C_IRQENABLE_CLR] = 0x30,
 };
 
+struct omap_i2c_driver_data {
+	u32		flags;
+	u32		fclk_rate;
+	u8		*regs;
+};
+
+static struct omap_i2c_driver_data omap3_data = {
+	.flags =	OMAP_I2C_FLAG_RESET_REGS_POSTIDLE |
+			OMAP_I2C_FLAG_BUS_SHIFT_2,
+	.fclk_rate =	48000,
+	.regs =		(u8 *) reg_map,
+};
+
+static struct omap_i2c_driver_data omap4_data = {
+	.flags =	OMAP_I2C_FLAG_BUS_SHIFT_NONE,
+	.fclk_rate =	96000,
+	.regs =		(u8 *) omap4_reg_map,
+};
+
+static struct omap_i2c_driver_data am33xx_data = {
+	.flags =	OMAP_I2C_FLAG_RESET_REGS_POSTIDLE |
+			OMAP_I2C_FLAG_BUS_SHIFT_NONE,
+	.fclk_rate =	96000,
+	.regs =		(u8 *) omap4_reg_map,
+};
+
 static inline void omap_i2c_write_reg(struct omap_i2c_struct *i2c_omap,
 				      int reg, u16 val)
 {
 	__raw_writew(val, i2c_omap->base +
-			(i2c_omap->regs[reg] << i2c_omap->reg_shift));
+			(i2c_omap->data->regs[reg] << i2c_omap->reg_shift));
 }
 
 static inline u16 omap_i2c_read_reg(struct omap_i2c_struct *i2c_omap, int reg)
 {
 	return __raw_readw(i2c_omap->base +
-			(i2c_omap->regs[reg] << i2c_omap->reg_shift));
+			(i2c_omap->data->regs[reg] << i2c_omap->reg_shift));
 }
 
 static void omap_i2c_unidle(struct omap_i2c_struct *i2c_omap)
 {
-	if (cpu_is_omap34xx() || cpu_is_am33xx()) {
+	struct omap_i2c_driver_data *i2c_data = i2c_omap->data;
+
+	if (i2c_data->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) {
 		omap_i2c_write_reg(i2c_omap, OMAP_I2C_CON_REG, 0);
 		omap_i2c_write_reg(i2c_omap, OMAP_I2C_PSC_REG, i2c_omap->pscstate);
 		omap_i2c_write_reg(i2c_omap, OMAP_I2C_SCLL_REG, i2c_omap->scllstate);
@@ -288,9 +323,8 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 	u16 psc = 0, scll = 0, sclh = 0, buf = 0;
 	u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0;
 	uint64_t start;
-
-	unsigned long fclk_rate = 12000000;
 	unsigned long internal_clk = 0;
+	struct omap_i2c_driver_data *i2c_data = i2c_omap->data;
 
 	if (i2c_omap->rev >= OMAP_I2C_REV_2) {
 		/* Disable I2C controller before soft reset */
@@ -354,13 +388,8 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 	else
 		internal_clk = 4000;
 
-	if (cpu_is_am33xx())
-		fclk_rate = 48000;
-	else
-		fclk_rate = 96000;
-
 	/* Compute prescaler divisor */
-	psc = fclk_rate / internal_clk;
+	psc = i2c_data->fclk_rate / internal_clk;
 	psc = psc - 1;
 
 	/* If configured for High Speed */
@@ -373,7 +402,7 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 		fssclh = (scl / 3) - 5;
 
 		/* For second phase of HS mode */
-		scl = fclk_rate / i2c_omap->speed;
+		scl = i2c_data->fclk_rate / i2c_omap->speed;
 		hsscll = scl - (scl / 3) - 7;
 		hssclh = (scl / 3) - 5;
 	} else if (i2c_omap->speed > 100) {
@@ -414,7 +443,7 @@ static int omap_i2c_init(struct omap_i2c_struct *i2c_omap)
 			OMAP_I2C_IE_AL)  | ((i2c_omap->fifo_size) ?
 				(OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0);
 	omap_i2c_write_reg(i2c_omap, OMAP_I2C_IE_REG, i2c_omap->iestate);
-	if (cpu_is_omap34xx() || cpu_is_am33xx()) {
+	if (i2c_data->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) {
 		i2c_omap->pscstate = psc;
 		i2c_omap->scllstate = scll;
 		i2c_omap->sclhstate = sclh;
@@ -736,7 +765,7 @@ static int __init
 i2c_omap_probe(struct device_d *pdev)
 {
 	struct omap_i2c_struct	*i2c_omap;
-	/* struct i2c_platform_data *pdata; */
+	struct omap_i2c_driver_data *i2c_data;
 	int r;
 	u32 speed = 0;
 	u16 s;
@@ -747,13 +776,13 @@ i2c_omap_probe(struct device_d *pdev)
 		goto err_free_mem;
 	}
 
-	if (cpu_is_omap4xxx() || cpu_is_am33xx()) {
-		i2c_omap->regs = (u8 *)omap4_reg_map;
-		i2c_omap->reg_shift = 0;
-	} else {
-		i2c_omap->regs = (u8 *)reg_map;
-		i2c_omap->reg_shift = 2;
-	}
+	r = dev_get_drvdata(pdev, (unsigned long *)&i2c_data);
+	if (r)
+		return r;
+
+	i2c_omap->data = i2c_data;
+	i2c_omap->reg_shift = (i2c_data->flags >>
+					OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3;
 
 	if (pdev->platform_data != NULL)
 		speed = *(u32 *)pdev->platform_data;
@@ -815,9 +844,25 @@ err_free_mem:
 	return r;
 }
 
+static struct platform_device_id omap_i2c_ids[] = {
+	 {
+		.name = "i2c-omap3",
+		.driver_data = (unsigned long)&omap3_data,
+	}, {
+		.name = "i2c-omap4",
+		.driver_data = (unsigned long)&omap4_data,
+	}, {
+		.name = "i2c-am33xx",
+		.driver_data = (unsigned long)&am33xx_data,
+	}, {
+		/* sentinel */
+	},
+};
+
 static struct driver_d omap_i2c_driver = {
 	.probe		= i2c_omap_probe,
 	.name		= DRIVER_NAME,
+	.id_table	= omap_i2c_ids,
 };
 device_platform_driver(omap_i2c_driver);
 
-- 
1.7.0.4



From t.gamez at phytec.de  Fri Jun 21 08:50:19 2013
From: t.gamez at phytec.de (=?UTF-8?q?Teresa=20G=C3=A1mez?=)
Date: Fri, 21 Jun 2013 14:50:19 +0200
Subject: [PATCH 2/2] ARCH: OMAP: Apply i2c-omap id_tables to device register
 functions
In-Reply-To: <1371819019-13596-1-git-send-email-t.gamez@phytec.de>
References: <1371819019-13596-1-git-send-email-t.gamez@phytec.de>
Message-ID: <1371819019-13596-2-git-send-email-t.gamez@phytec.de>

Remove omap_add_i2c() and use the id_table names to register the
devices.

Signed-off-by: Teresa G?mez <t.gamez at phytec.de>
---
 arch/arm/mach-omap/include/mach/am33xx-devices.h |    9 ++++++---
 arch/arm/mach-omap/include/mach/devices.h        |    2 --
 arch/arm/mach-omap/include/mach/omap3-devices.h  |    9 ++++++---
 arch/arm/mach-omap/include/mach/omap4-devices.h  |   12 ++++++++----
 arch/arm/mach-omap/omap_devices.c                |    6 ------
 5 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/arch/arm/mach-omap/include/mach/am33xx-devices.h b/arch/arm/mach-omap/include/mach/am33xx-devices.h
index 822caab..6a4d901 100644
--- a/arch/arm/mach-omap/include/mach/am33xx-devices.h
+++ b/arch/arm/mach-omap/include/mach/am33xx-devices.h
@@ -55,17 +55,20 @@ static inline struct device_d *am33xx_add_spi1(void)
 
 static inline struct device_d *am33xx_add_i2c0(void *pdata)
 {
-	return omap_add_i2c(0, AM33XX_I2C0_BASE, pdata);
+	return add_generic_device("i2c-am33xx", 0, NULL, AM33XX_I2C0_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *am33xx_add_i2c1(void *pdata)
 {
-	return omap_add_i2c(1, AM33XX_I2C1_BASE, pdata);
+	return add_generic_device("i2c-am33xx", 1, NULL, AM33XX_I2C1_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *am33xx_add_i2c2(void *pdata)
 {
-	return omap_add_i2c(2, AM33XX_I2C2_BASE, pdata);
+	return add_generic_device("i2c-am33xx", 2, NULL, AM33XX_I2C2_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 #endif /* __MACH_OMAP3_DEVICES_H */
diff --git a/arch/arm/mach-omap/include/mach/devices.h b/arch/arm/mach-omap/include/mach/devices.h
index adae01b..537213f 100644
--- a/arch/arm/mach-omap/include/mach/devices.h
+++ b/arch/arm/mach-omap/include/mach/devices.h
@@ -9,6 +9,4 @@ void omap_add_sram0(resource_size_t base, resource_size_t size);
 
 struct device_d *omap_add_uart(int id, unsigned long base);
 
-struct device_d *omap_add_i2c(int id, unsigned long base, void *pdata);
-
 #endif /* __MACH_OMAP_DEVICES_H */
diff --git a/arch/arm/mach-omap/include/mach/omap3-devices.h b/arch/arm/mach-omap/include/mach/omap3-devices.h
index de67ea0..0809e95 100644
--- a/arch/arm/mach-omap/include/mach/omap3-devices.h
+++ b/arch/arm/mach-omap/include/mach/omap3-devices.h
@@ -77,17 +77,20 @@ static inline struct device_d *omap3_add_mmc3(struct omap_hsmmc_platform_data *p
 
 static inline struct device_d *omap3_add_i2c1(void *pdata)
 {
-	return omap_add_i2c(0, OMAP3_I2C1_BASE, pdata);
+	return add_generic_device("i2c-omap3", 0, NULL, OMAP3_I2C1_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap3_add_i2c2(void *pdata)
 {
-	return omap_add_i2c(1, OMAP3_I2C2_BASE, pdata);
+	return add_generic_device("i2c-omap3", 1, NULL, OMAP3_I2C2_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap3_add_i2c3(void *pdata)
 {
-	return omap_add_i2c(2, OMAP3_I2C3_BASE, pdata);
+	return add_generic_device("i2c-omap3", 2, NULL, OMAP3_I2C3_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap3_add_ehci(void *pdata)
diff --git a/arch/arm/mach-omap/include/mach/omap4-devices.h b/arch/arm/mach-omap/include/mach/omap4-devices.h
index 561d9ce..76c9789 100644
--- a/arch/arm/mach-omap/include/mach/omap4-devices.h
+++ b/arch/arm/mach-omap/include/mach/omap4-devices.h
@@ -60,22 +60,26 @@ static inline struct device_d *omap44xx_add_mmc5(struct omap_hsmmc_platform_data
 
 static inline struct device_d *omap44xx_add_i2c1(void *pdata)
 {
-	return omap_add_i2c(0, OMAP44XX_I2C1_BASE, pdata);
+	return add_generic_device("i2c-omap4", 0, NULL, OMAP44XX_I2C1_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap44xx_add_i2c2(void *pdata)
 {
-	return omap_add_i2c(1, OMAP44XX_I2C2_BASE, pdata);
+	return add_generic_device("i2c-omap4", 1, NULL, OMAP44XX_I2C2_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap44xx_add_i2c3(void *pdata)
 {
-	return omap_add_i2c(2, OMAP44XX_I2C3_BASE, pdata);
+	return add_generic_device("i2c-omap4", 2, NULL, OMAP44XX_I2C3_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap44xx_add_i2c4(void *pdata)
 {
-	return omap_add_i2c(3, OMAP44XX_I2C4_BASE, pdata);
+	return add_generic_device("i2c-omap4", 3, NULL, OMAP44XX_I2C4_BASE,
+			SZ_4K, IORESOURCE_MEM, pdata);
 }
 
 static inline struct device_d *omap44xx_add_ehci(void *pdata)
diff --git a/arch/arm/mach-omap/omap_devices.c b/arch/arm/mach-omap/omap_devices.c
index 056cba5..30cfdd0 100644
--- a/arch/arm/mach-omap/omap_devices.c
+++ b/arch/arm/mach-omap/omap_devices.c
@@ -24,9 +24,3 @@ struct device_d *omap_add_uart(int id, unsigned long base)
 	return add_ns16550_device(id, base, 1024,
 			IORESOURCE_MEM_8BIT, &serial_plat);
 }
-
-struct device_d *omap_add_i2c(int id, unsigned long base, void *pdata)
-{
-	return add_generic_device("i2c-omap", id, NULL, base, SZ_4K,
-			   IORESOURCE_MEM, pdata);
-}
-- 
1.7.0.4



From j.weitzel at phytec.de  Fri Jun 21 09:47:42 2013
From: j.weitzel at phytec.de (Jan Weitzel)
Date: Fri, 21 Jun 2013 15:47:42 +0200
Subject: [PATCH] OMAP4: fix omap4_bootsource regression
Message-ID: <1371822462-30513-1-git-send-email-j.weitzel@phytec.de>

commit d7a913469c34553e96c887f8a9934bacd794e81c breaks boot source detection
for pcm049. The tracing vectors shows all tested boot sources, so order is
important. By not returning but overwriting src we effectively reversed the
order if more than one flag is set.

Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
---
 arch/arm/mach-omap/omap4_generic.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap/omap4_generic.c b/arch/arm/mach-omap/omap4_generic.c
index bf1f1a7..4878aec 100644
--- a/arch/arm/mach-omap/omap4_generic.c
+++ b/arch/arm/mach-omap/omap4_generic.c
@@ -508,9 +508,9 @@ static int omap4_bootsource(void)
 
 	if (bootsrc & (1 << 5))
 		src = BOOTSOURCE_MMC;
-	if (bootsrc & (1 << 3))
+	else if (bootsrc & (1 << 3))
 		src = BOOTSOURCE_NAND;
-	if (bootsrc & (1<<20))
+	else if (bootsrc & (1<<20))
 		src = BOOTSOURCE_USB;
 	bootsource_set(src);
 	bootsource_set_instance(0);
-- 
1.7.0.4



From sebastian.hesselbarth at gmail.com  Fri Jun 21 11:15:15 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 21 Jun 2013 17:15:15 +0200
Subject: [PATCH 0/3] OF: base: cleanup and allow empty properties
Message-ID: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>

This patch set cleans Barebox OF API with respect to properies by using
internal functions for creating/deleting properties instead of
allocating/freeing in different places.

Also, with the consolidated property handling, we can now add a bogus
property value pointer to distinguish empty/boolean properties from
non-existing properties.

The patch set is based on the latest OF API patches sent some days
ago with Sascha Hauers fixes applied.

Sebastian Hesselbarth (3):
  OF: base: add sanity checks to of_new/delete_property
  OF: base: use of_delete_property where applicable
  OF: base: add empty property value pointer

 drivers/of/base.c |  107 ++++++++++++++++++++++++-----------------------------
 1 files changed, 48 insertions(+), 59 deletions(-)

---
Cc: barebox at lists.infradead.org
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Fri Jun 21 11:15:16 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 21 Jun 2013 17:15:16 +0200
Subject: [PATCH 1/3] OF: base: add sanity checks to of_new/delete_property
In-Reply-To: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371827718-7928-2-git-send-email-sebastian.hesselbarth@gmail.com>

This adds some sanity checks to of_new_property and of_delete_property.
Also, data passed to of_new_property is only copied if non-NULL.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1b351ee..bcfd73a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1527,21 +1527,37 @@ struct property *of_new_property(struct device_node *node, const char *name,
 	struct property *prop;
 
 	prop = xzalloc(sizeof(*prop));
+	if (!prop)
+		return NULL;
 
 	prop->name = strdup(name);
+	if (!prop->name)
+		goto bail_out;
+
 	prop->length = len;
 	if (len) {
 		prop->value = xzalloc(len);
-		memcpy(prop->value, data, len);
+		if (!prop->value)
+			goto bail_out;
 	}
 
+	if (len && data)
+		memcpy(prop->value, data, len);
+
 	list_add_tail(&prop->list, &node->properties);
 
 	return prop;
+
+bail_out:
+	of_delete_property(prop);
+	return NULL;
 }
 
 void of_delete_property(struct property *pp)
 {
+	if (!pp)
+		return;
+
 	list_del(&pp->list);
 
 	free(pp->name);
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Fri Jun 21 11:15:17 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 21 Jun 2013 17:15:17 +0200
Subject: [PATCH 2/3] OF: base: use of_delete_property where applicable
In-Reply-To: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371827718-7928-3-git-send-email-sebastian.hesselbarth@gmail.com>

This patch makes OF API use of_delete_property where applicable instead
of freeing allocated data in different places.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   83 ++++++++++++++++------------------------------------
 1 files changed, 26 insertions(+), 57 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index bcfd73a..7926d5d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -899,16 +899,11 @@ int of_property_write_u8_array(struct device_node *np,
 	struct property *prop = of_find_property(np, propname, NULL);
 	u8 *val;
 
-	if (!prop)
-		prop = of_new_property(np, propname, NULL, 0);
-	if (!prop)
-		return -ENOMEM;
-
-	free(prop->value);
+	if (prop)
+		of_delete_property(prop);
 
-	prop->length = sizeof(*val) * sz;
-	prop->value = malloc(prop->length);
-	if (!prop->value)
+	prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
+	if (!prop)
 		return -ENOMEM;
 
 	val = prop->value;
@@ -940,18 +935,13 @@ int of_property_write_u16_array(struct device_node *np,
 	struct property *prop = of_find_property(np, propname, NULL);
 	__be16 *val;
 
-	if (!prop)
-		prop = of_new_property(np, propname, NULL, 0);
+	if (prop)
+		of_delete_property(prop);
+		
+	prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
 	if (!prop)
 		return -ENOMEM;
 
-	free(prop->value);
-
-	prop->length = sizeof(*val) * sz;
-	prop->value = malloc(prop->length);
-	if (!prop->value)
-		return -ENOMEM;
-
 	val = prop->value;
 	while (sz--)
 		*val++ = cpu_to_be16(*values++);
@@ -981,16 +971,11 @@ int of_property_write_u32_array(struct device_node *np,
 	struct property *prop = of_find_property(np, propname, NULL);
 	__be32 *val;
 
-	if (!prop)
-		prop = of_new_property(np, propname, NULL, 0);
-	if (!prop)
-		return -ENOMEM;
-
-	free(prop->value);
+	if (prop)
+		of_delete_property(prop);
 
-	prop->length = sizeof(*val) * sz;
-	prop->value = malloc(prop->length);
-	if (!prop->value)
+	prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
+	if (!prop)
 		return -ENOMEM;
 
 	val = prop->value;
@@ -1022,16 +1007,11 @@ int of_property_write_u64_array(struct device_node *np,
 	struct property *prop = of_find_property(np, propname, NULL);
 	__be32 *val;
 
-	if (!prop)
-		prop = of_new_property(np, propname, NULL, 0);
-	if (!prop)
-		return -ENOMEM;
-
-	free(prop->value);
+	if (prop)
+		of_delete_property(prop);
 
-	prop->length = 2 * sizeof(*val) * sz;
-	prop->value = malloc(prop->length);
-	if (!prop->value)
+	prop = of_new_property(np, propname, NULL, 2 * sizeof(*val) * sz);
+	if (!prop)
 		return -ENOMEM;
 
 	val = prop->value;
@@ -1576,26 +1556,19 @@ void of_delete_property(struct property *pp)
 int of_set_property(struct device_node *np, const char *name, const void *val, int len,
 		int create)
 {
-	struct property *pp;
+	struct property *pp = of_find_property(np, name, NULL);
 
 	if (!np)
 		return -ENOENT;
 
-	pp = of_find_property(np, name, NULL);
-	if (pp) {
-		void *data;
-
-		free(pp->value);
-		data = xzalloc(len);
-		memcpy(data, val, len);
-		pp->value = data;
-		pp->length = len;
-	} else {
-		if (!create)
-			return -ENOENT;
+	if (!pp && !create)
+		return -ENOENT;
+		
+	of_delete_property(pp);
 
-		pp = of_new_property(np, name, val, len);
-	}
+	pp = of_new_property(np, name, val, len);
+	if (!pp)
+		return -ENOMEM;
 
 	return 0;
 }
@@ -1819,12 +1792,8 @@ void of_free(struct device_node *node)
 	if (!node)
 		return;
 
-	list_for_each_entry_safe(p, pt, &node->properties, list) {
-		list_del(&p->list);
-		free(p->name);
-		free(p->value);
-		free(p);
-	}
+	list_for_each_entry_safe(p, pt, &node->properties, list)
+		of_delete_property(p);
 
 	list_for_each_entry_safe(n, nt, &node->children, parent_list) {
 		of_free(n);
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Fri Jun 21 11:15:18 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 21 Jun 2013 17:15:18 +0200
Subject: [PATCH 3/3] OF: base: add empty property value pointer
In-Reply-To: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1371827718-7928-4-git-send-email-sebastian.hesselbarth@gmail.com>

Since property values can be empty, we need property value pointer to
be non-NULL to distinguish those properties from non-existing properties.
This adds a static u32 to which empty properties set their value pointer.
Also, the value memory is only freed, if property length is not zero.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 7926d5d..a100a17 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1501,6 +1501,8 @@ struct device_node *of_new_node(struct device_node *parent, const char *name)
 	return node;
 }
 
+static u32 empty_prop_value;
+
 struct property *of_new_property(struct device_node *node, const char *name,
 		const void *data, int len)
 {
@@ -1515,6 +1517,7 @@ struct property *of_new_property(struct device_node *node, const char *name,
 		goto bail_out;
 
 	prop->length = len;
+	prop->value = &empty_prop_value;
 	if (len) {
 		prop->value = xzalloc(len);
 		if (!prop->value)
@@ -1541,7 +1544,8 @@ void of_delete_property(struct property *pp)
 	list_del(&pp->list);
 
 	free(pp->name);
-	free(pp->value);
+	if (pp->length)
+		free(pp->value);
 	free(pp);
 }
 
-- 
1.7.2.5



From s.hauer at pengutronix.de  Fri Jun 21 11:48:40 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Fri, 21 Jun 2013 17:48:40 +0200
Subject: [PATCH 0/8] low level initialisation for ar2313
In-Reply-To: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
Message-ID: <20130621154840.GF32299@pengutronix.de>

On Wed, Jun 19, 2013 at 11:11:25AM +0200, Oleksij Rempel wrote:
> this patch set add low level initialisation for Atheros ar2313
> and board based on this chip - Netgear wg102.
> 
> Antony Pavlov (2):
>   MIPS: pbl: add mips_barebox_10h asm macro
>   MIPS: mach-ar231x: enable DEBUG_LL
> 
> Oleksij Rempel (6):
>   MIPS: pbl: add pbl_sleep macro
>   MIPS: pbl: add pbl_probe_mem macro
>   MIPS: mach-ar231x: add lowlevel init pbl macros
>   MIPS: netgear-wg102: add pbl support
>   MIPS: netgear-wg102: add debug_ll
>   netgear-wg102: pbl, add extra check for mem config

Applied, thanks

Sascha

> 
>  arch/mips/Kconfig                                  |   1 +
>  .../netgear-wg102/include/board/board_pbl_start.h  |  77 +++++++++
>  .../boards/netgear-wg102/include/board/debug_ll.h  |  33 ++++
>  arch/mips/include/asm/pbl_macros.h                 |  38 +++++
>  arch/mips/mach-ar231x/Kconfig                      |   2 +
>  arch/mips/mach-ar231x/include/mach/debug_ll.h      |  27 ++++
>  arch/mips/mach-ar231x/include/mach/pbl_macros.h    | 177 +++++++++++++++++++++
>  7 files changed, 355 insertions(+)
>  create mode 100644 arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
>  create mode 100644 arch/mips/boards/netgear-wg102/include/board/debug_ll.h
>  create mode 100644 arch/mips/mach-ar231x/include/mach/debug_ll.h
>  create mode 100644 arch/mips/mach-ar231x/include/mach/pbl_macros.h
> 
> -- 
> 1.8.1.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From antonynpavlov at gmail.com  Fri Jun 21 12:37:45 2013
From: antonynpavlov at gmail.com (antonynpavlov at gmail.com)
Date: Fri, 21 Jun 2013 20:37:45 +0400
Subject: [PATCH 0/8] low level initialisation for ar2313
In-Reply-To: <20130621154840.GF32299@pengutronix.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
 <20130621154840.GF32299@pengutronix.de>
Message-ID: <20130621203745.932331ebb1544b8246d480d2@gmail.com>

On Fri, 21 Jun 2013 17:48:40 +0200
Sascha Hauer <s.hauer at pengutronix.de> wrote:

Well done, Oleksij! Congratulations!

Thanks, Sascha!

Now we have in the next branch THE FIRST PUBLICLY AVAILABLE FULLY SUPPORTED "HARDWARE" MIPS-based BOARD!

> On Wed, Jun 19, 2013 at 11:11:25AM +0200, Oleksij Rempel wrote:
> > this patch set add low level initialisation for Atheros ar2313
> > and board based on this chip - Netgear wg102.
> > 
> > Antony Pavlov (2):
> >   MIPS: pbl: add mips_barebox_10h asm macro
> >   MIPS: mach-ar231x: enable DEBUG_LL
> > 
> > Oleksij Rempel (6):
> >   MIPS: pbl: add pbl_sleep macro
> >   MIPS: pbl: add pbl_probe_mem macro
> >   MIPS: mach-ar231x: add lowlevel init pbl macros
> >   MIPS: netgear-wg102: add pbl support
> >   MIPS: netgear-wg102: add debug_ll
> >   netgear-wg102: pbl, add extra check for mem config
> 
> Applied, thanks
> 
> Sascha
> 
> > 
> >  arch/mips/Kconfig                                  |   1 +
> >  .../netgear-wg102/include/board/board_pbl_start.h  |  77 +++++++++
> >  .../boards/netgear-wg102/include/board/debug_ll.h  |  33 ++++
> >  arch/mips/include/asm/pbl_macros.h                 |  38 +++++
> >  arch/mips/mach-ar231x/Kconfig                      |   2 +
> >  arch/mips/mach-ar231x/include/mach/debug_ll.h      |  27 ++++
> >  arch/mips/mach-ar231x/include/mach/pbl_macros.h    | 177 +++++++++++++++++++++
> >  7 files changed, 355 insertions(+)
> >  create mode 100644 arch/mips/boards/netgear-wg102/include/board/board_pbl_start.h
> >  create mode 100644 arch/mips/boards/netgear-wg102/include/board/debug_ll.h
> >  create mode 100644 arch/mips/mach-ar231x/include/mach/debug_ll.h
> >  create mode 100644 arch/mips/mach-ar231x/include/mach/pbl_macros.h
> > 
> > -- 
> > 1.8.1.2
> > 
> > 
> > _______________________________________________
> > barebox mailing list
> > barebox at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
--?
Best regards,
? Antony Pavlov


From s.hauer at pengutronix.de  Sun Jun 23 14:24:04 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 20:24:04 +0200
Subject: [PATCH 1/3] OF: base: add sanity checks to of_new/delete_property
In-Reply-To: <1371827718-7928-2-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371827718-7928-2-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130623182404.GI32299@pengutronix.de>

On Fri, Jun 21, 2013 at 05:15:16PM +0200, Sebastian Hesselbarth wrote:
> This adds some sanity checks to of_new_property and of_delete_property.
> Also, data passed to of_new_property is only copied if non-NULL.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: barebox at lists.infradead.org
> ---
>  drivers/of/base.c |   18 +++++++++++++++++-
>  1 files changed, 17 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 1b351ee..bcfd73a 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1527,21 +1527,37 @@ struct property *of_new_property(struct device_node *node, const char *name,
>  	struct property *prop;
>  
>  	prop = xzalloc(sizeof(*prop));
> +	if (!prop)
> +		return NULL;

xzalloc always returns valid memory. It's return-mem-or-panic.

>  
>  	prop->name = strdup(name);
> +	if (!prop->name)
> +		goto bail_out;
> +
>  	prop->length = len;
>  	if (len) {
>  		prop->value = xzalloc(len);
> -		memcpy(prop->value, data, len);
> +		if (!prop->value)
> +			goto bail_out;

ditto.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sun Jun 23 14:33:24 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 20:33:24 +0200
Subject: [PATCH 3/3] OF: base: add empty property value pointer
In-Reply-To: <1371827718-7928-4-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371827718-7928-4-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130623183324.GJ32299@pengutronix.de>

On Fri, Jun 21, 2013 at 05:15:18PM +0200, Sebastian Hesselbarth wrote:
> Since property values can be empty, we need property value pointer to
> be non-NULL to distinguish those properties from non-existing properties.
> This adds a static u32 to which empty properties set their value pointer.
> Also, the value memory is only freed, if property length is not zero.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: barebox at lists.infradead.org
> ---
>  drivers/of/base.c |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 7926d5d..a100a17 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1501,6 +1501,8 @@ struct device_node *of_new_node(struct device_node *parent, const char *name)
>  	return node;
>  }
>  
> +static u32 empty_prop_value;
> +
>  struct property *of_new_property(struct device_node *node, const char *name,
>  		const void *data, int len)
>  {
> @@ -1515,6 +1517,7 @@ struct property *of_new_property(struct device_node *node, const char *name,
>  		goto bail_out;
>  
>  	prop->length = len;
> +	prop->value = &empty_prop_value;

This at least breaks of_set_property() and of_free(). Both unconditionally
do a free(pp->value).

Why do we need this anyway? We can always call of_find_property() to see
if a property exists.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sun Jun 23 14:37:26 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 20:37:26 +0200
Subject: [PATCH 1/2] i2c-omap: Remove cpu_is functions completely
In-Reply-To: <1371819019-13596-1-git-send-email-t.gamez@phytec.de>
References: <1371819019-13596-1-git-send-email-t.gamez@phytec.de>
Message-ID: <20130623183726.GK32299@pengutronix.de>

On Fri, Jun 21, 2013 at 02:50:18PM +0200, Teresa G?mez wrote:
> This patch removes the call of the cpu_is_* functions completely
> and uses id_tables instead.
> 
> Signed-off-by: Teresa G?mez <t.gamez at phytec.de>

Nice, thanks ;)

Applied both and squashed into a single commit. Otherwise we don't have
i2c support after the first patch.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sun Jun 23 14:42:17 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 20:42:17 +0200
Subject: [PATCH 0/8] low level initialisation for ar2313
In-Reply-To: <20130621203745.932331ebb1544b8246d480d2@gmail.com>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
 <20130621154840.GF32299@pengutronix.de>
 <20130621203745.932331ebb1544b8246d480d2@gmail.com>
Message-ID: <20130623184217.GL32299@pengutronix.de>

On Fri, Jun 21, 2013 at 08:37:45PM +0400, antonynpavlov at gmail.com wrote:
> On Fri, 21 Jun 2013 17:48:40 +0200
> Sascha Hauer <s.hauer at pengutronix.de> wrote:
> 
> Well done, Oleksij! Congratulations!
> 
> Thanks, Sascha!
> 
> Now we have in the next branch THE FIRST PUBLICLY AVAILABLE FULLY SUPPORTED "HARDWARE" MIPS-based BOARD!

Hurray \o/

What about the dlink 320? Does it only work 2nd stage?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sun Jun 23 14:52:06 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 20:52:06 +0200
Subject: [PATCH v2] OMAP4 do not set TPS62361_REG_ADDR_SET0
In-Reply-To: <1371803042-1179-1-git-send-email-j.weitzel@phytec.de>
References: <CAGo_u6pP9djhzUZyOLNewL4kDwcY0A_KW1ZmdHVurCwBUxBEEg@mail.gmail.com>
 <1371803042-1179-1-git-send-email-j.weitzel@phytec.de>
Message-ID: <20130623185206.GN32299@pengutronix.de>

On Fri, Jun 21, 2013 at 10:24:02AM +0200, Jan Weitzel wrote:
> Don't set SET0 voltage, because it acts as boot voltage for OPP boot.
> Take care that the kernel doesn't drive vset gpio to low. This may
> happen while reseting the gpio module at initialization, look for
> HWMOD_INIT_NO_RESET.
> 
> Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
> Reviewed-by: Nishanth Menon <nm at ti.com>

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From antonynpavlov at gmail.com  Sun Jun 23 15:16:11 2013
From: antonynpavlov at gmail.com (antonynpavlov at gmail.com)
Date: Sun, 23 Jun 2013 23:16:11 +0400
Subject: [PATCH 0/8] low level initialisation for ar2313
In-Reply-To: <20130623184217.GL32299@pengutronix.de>
References: <1371633093-23179-1-git-send-email-linux@rempel-privat.de>
 <20130621154840.GF32299@pengutronix.de>
 <20130621203745.932331ebb1544b8246d480d2@gmail.com>
 <20130623184217.GL32299@pengutronix.de>
Message-ID: <20130623231611.45358b0e316e65de6bc77010@gmail.com>

On Sun, 23 Jun 2013 20:42:17 +0200
Sascha Hauer <s.hauer at pengutronix.de> wrote:

> On Fri, Jun 21, 2013 at 08:37:45PM +0400, antonynpavlov at gmail.com wrote:
> > On Fri, 21 Jun 2013 17:48:40 +0200
> > Sascha Hauer <s.hauer at pengutronix.de> wrote:
> > 
> > Well done, Oleksij! Congratulations!
> > 
> > Thanks, Sascha!
> > 
> > Now we have in the next branch THE FIRST PUBLICLY AVAILABLE FULLY SUPPORTED "HARDWARE" MIPS-based BOARD!
> 
> Hurray \o/
> 
> What about the dlink 320? Does it only work 2nd stage?

Alas it works only 2nd stage.

I have a Ingenic JZ4770-based tablet with barebox only firmware. I made the 1st stage loader as a very very dirty hack, but it works! It is time to clean it...


> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


-- 
--?
Best regards,
? Antony Pavlov


From s.hauer at pengutronix.de  Sun Jun 23 15:30:57 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 21:30:57 +0200
Subject: [PATCH] OMAP4: fix omap4_bootsource regression
In-Reply-To: <1371822462-30513-1-git-send-email-j.weitzel@phytec.de>
References: <1371822462-30513-1-git-send-email-j.weitzel@phytec.de>
Message-ID: <20130623193057.GP32299@pengutronix.de>

On Fri, Jun 21, 2013 at 03:47:42PM +0200, Jan Weitzel wrote:
> commit d7a913469c34553e96c887f8a9934bacd794e81c breaks boot source detection
> for pcm049. The tracing vectors shows all tested boot sources, so order is
> important. By not returning but overwriting src we effectively reversed the
> order if more than one flag is set.
> 
> Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>

Applied to master and stable/v2013.06

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sun Jun 23 15:44:50 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 21:44:50 +0200
Subject: [PATCH] debug patches
Message-ID: <1372016693-30160-1-git-send-email-s.hauer@pengutronix.de>

This removed the mostly nonfunctional *_NOISE kconfig options and
instead adds an option for tracing initcalls. Also we make the i.MX
early debug UART configurable via Kconfig.

Sascha

----------------------------------------------------------------
Sascha Hauer (3):
      remove unused debug Kconfig options
      ARM: i.MX: Make debug UART selectable from Kconfig
      startup: Add initcall tracing debug option

 arch/arm/mach-imx/include/mach/debug_ll.h |  31 ++++++--
 commands/partition.c                      |   4 --
 common/Kconfig                            | 114 +++++++++++++++++++++++++-----
 common/startup.c                          |   4 ++
 drivers/net/smc91111.c                    |   4 --
 drivers/net/smc911x.c                     |   4 --
 6 files changed, 125 insertions(+), 36 deletions(-)


From s.hauer at pengutronix.de  Sun Jun 23 15:44:53 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 21:44:53 +0200
Subject: [PATCH 3/3] startup: Add initcall tracing debug option
In-Reply-To: <1372016693-30160-1-git-send-email-s.hauer@pengutronix.de>
References: <1372016693-30160-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372016693-30160-4-git-send-email-s.hauer@pengutronix.de>

Being able to trace initcall is very useful when trying to
find out where startup hangs. This adds a kconfig option for
it to make it easier to access.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/Kconfig   | 4 ++++
 common/startup.c | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/common/Kconfig b/common/Kconfig
index 6a72267..1d9def9 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -710,6 +710,10 @@ config DEBUG_IMX_UART_PORT
 	  Choose UART port on which kernel low-level debug messages
 	  should be output.
 
+config DEBUG_INITCALLS
+	bool "Trace initcalls"
+	help
+	  If enabled this will print initcall traces.
 endmenu
 
 config HAS_DEBUG_LL
diff --git a/common/startup.c b/common/startup.c
index ff00ca7..9b33a92 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -21,6 +21,10 @@
  *
  */
 
+#ifdef CONFIG_DEBUG_INITCALLS
+#define DEBUG
+#endif
+
 /**
  * @file
  * @brief Main entry into the C part of barebox
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 15:44:52 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 21:44:52 +0200
Subject: [PATCH 2/3] ARM: i.MX: Make debug UART selectable from Kconfig
In-Reply-To: <1372016693-30160-1-git-send-email-s.hauer@pengutronix.de>
References: <1372016693-30160-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372016693-30160-3-git-send-email-s.hauer@pengutronix.de>

To make early debugging on i.MX a bit simpler. This uses a similar
magic than the kernel does.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/include/mach/debug_ll.h | 31 +++++++++--
 common/Kconfig                            | 92 +++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-imx/include/mach/debug_ll.h b/arch/arm/mach-imx/include/mach/debug_ll.h
index cb6dd03..0bb28ee 100644
--- a/arch/arm/mach-imx/include/mach/debug_ll.h
+++ b/arch/arm/mach-imx/include/mach/debug_ll.h
@@ -13,13 +13,31 @@
 #include <mach/imx53-regs.h>
 #include <mach/imx6-regs.h>
 
-/* #define IMX_DEBUG_LL_UART_BASE MXxy_UARTx_BASE_ADDR */
-
-#ifndef IMX_DEBUG_LL_UART_BASE
-#warning define IMX_DEBUG_LL_UART_BASE properly for debug_ll
-#define IMX_DEBUG_LL_UART_BASE 0
+#ifdef CONFIG_DEBUG_IMX1_UART
+#define IMX_DEBUG_SOC MX1
+#elif defined CONFIG_DEBUG_IMX21_UART
+#define IMX_DEBUG_SOC MX21
+#elif defined CONFIG_DEBUG_IMX25_UART
+#define IMX_DEBUG_SOC MX25
+#elif defined CONFIG_DEBUG_IMX27_UART
+#define IMX_DEBUG_SOC MX27
+#elif defined CONFIG_DEBUG_IMX31_UART
+#define IMX_DEBUG_SOC MX31
+#elif defined CONFIG_DEBUG_IMX35_UART
+#define IMX_DEBUG_SOC MX35
+#elif defined CONFIG_DEBUG_IMX51_UART
+#define IMX_DEBUG_SOC MX51
+#elif defined CONFIG_DEBUG_IMX53_UART
+#define IMX_DEBUG_SOC MX53
+#elif defined CONFIG_DEBUG_IMX6Q_UART
+#define IMX_DEBUG_SOC MX6
+#else
+#error "unknown i.MX debug uart soc type"
 #endif
 
+#define __IMX_UART_BASE(soc, num) soc##_UART##num##_BASE_ADDR
+#define IMX_UART_BASE(soc, num) __IMX_UART_BASE(soc, num)
+
 #define URTX0		0x40		/* Transmitter Register */
 
 #define UCR1		0x80		/* Control Register 1 */
@@ -30,7 +48,8 @@
 
 static inline void PUTC_LL(int c)
 {
-	void __iomem *base = (void *)IMX_DEBUG_LL_UART_BASE;
+	void __iomem *base = (void *)IMX_UART_BASE(IMX_DEBUG_SOC,
+			CONFIG_DEBUG_IMX_UART_PORT);
 
 	if (!base)
 		return;
diff --git a/common/Kconfig b/common/Kconfig
index d7e2ebd..6a72267 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -618,6 +618,98 @@ config DEBUG_LL
 	  This requires SoC specific support. Most SoCs require the debug UART to be
 	  initialized by a debugger or first stage bootloader.
 
+choice
+	prompt "Kernel low-level debugging port"
+	depends on DEBUG_LL
+
+config DEBUG_IMX1_UART
+	bool "i.MX1 Debug UART"
+	depends on ARCH_IMX1
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX1.
+
+config DEBUG_IMX21_UART
+	bool "i.MX21 Debug UART"
+	depends on ARCH_IMX21
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX21.
+
+config DEBUG_IMX25_UART
+	bool "i.MX25 Debug UART"
+	depends on ARCH_IMX25
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX25.
+
+config DEBUG_IMX27_UART
+	bool "i.MX27 Debug UART"
+	depends on ARCH_IMX1
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX27.
+
+config DEBUG_IMX31_UART
+	bool "i.MX31 Debug UART"
+	depends on ARCH_IMX31
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX31.
+
+config DEBUG_IMX35_UART
+	bool "i.MX35 Debug UART"
+	depends on ARCH_IMX35
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX35.
+
+config DEBUG_IMX51_UART
+	bool "i.MX51 Debug UART"
+	depends on ARCH_IMX51
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX51.
+
+config DEBUG_IMX53_UART
+	bool "i.MX53 Debug UART"
+	depends on ARCH_IMX53
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX53.
+
+config DEBUG_IMX6Q_UART
+	bool "i.MX6Q Debug UART"
+	depends on ARCH_IMX6Q
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX6Q.
+
+config DEBUG_IMX6SL_UART
+	bool "i.MX6SL Debug UART"
+	depends on ARCH_IMX6SL
+	help
+	  Say Y here if you want kernel low-level debugging support
+	  on i.MX6SL.
+
+endchoice
+
+config DEBUG_IMX_UART_PORT
+	int "i.MX Debug UART Port Selection" if DEBUG_IMX1_UART || \
+						DEBUG_IMX25_UART || \
+						DEBUG_IMX21_IMX27_UART || \
+						DEBUG_IMX31_UART || \
+						DEBUG_IMX35_UART || \
+						DEBUG_IMX51_UART || \
+						DEBUG_IMX53_UART || \
+						DEBUG_IMX6Q_UART || \
+						DEBUG_IMX6SL_UART
+	default 1
+	depends on ARCH_IMX
+	help
+	  Choose UART port on which kernel low-level debug messages
+	  should be output.
+
 endmenu
 
 config HAS_DEBUG_LL
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 15:44:51 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 21:44:51 +0200
Subject: [PATCH 1/3] remove unused debug Kconfig options
In-Reply-To: <1372016693-30160-1-git-send-email-s.hauer@pengutronix.de>
References: <1372016693-30160-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372016693-30160-2-git-send-email-s.hauer@pengutronix.de>

ENABLE_DEVICE_NOISE is used only in two network drivers and is
otherwise unused. ENABLE_FLASH_NOISE is completely unused.
ENABLE_PARTITION_NOISE enables DEBUG in the partition command,
but this code has no debug messages at all.

Remove all this.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/partition.c   |  4 ----
 common/Kconfig         | 18 ------------------
 drivers/net/smc91111.c |  4 ----
 drivers/net/smc911x.c  |  4 ----
 4 files changed, 30 deletions(-)

diff --git a/commands/partition.c b/commands/partition.c
index fdd6041..6f8d634 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -23,10 +23,6 @@
  * @brief partition handling and addpart and delpart command
  */
 
-#ifdef CONFIG_ENABLE_PARTITION_NOISE
-# define DEBUG
-#endif
-
 #include <common.h>
 #include <command.h>
 #include <complete.h>
diff --git a/common/Kconfig b/common/Kconfig
index 4cfbe4e..d7e2ebd 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -609,24 +609,6 @@ config DEBUG_INFO
 	help
 	  Enable build of barebox with -g.
 
-config ENABLE_FLASH_NOISE
-	bool
-	prompt "verbose flash handling"
-	help
-	  Enable this to get noisy flash handling routines
-
-config ENABLE_PARTITION_NOISE
-	bool
-	prompt "verbose partition handling"
-	help
-	  Enable this to get noisy partition handling routines
-
-config ENABLE_DEVICE_NOISE
-	bool
-	prompt "verbose device handling"
-	help
-	  Enable this to get noisy device handling routines
-
 config DEBUG_LL
 	bool
 	depends on HAS_DEBUG_LL
diff --git a/drivers/net/smc91111.c b/drivers/net/smc91111.c
index 48183dd..b868cbf 100644
--- a/drivers/net/smc91111.c
+++ b/drivers/net/smc91111.c
@@ -55,10 +55,6 @@
  .	03/16/01  Daris A Nevil	   Modified smc9194.c for use with LAN91C111
  ----------------------------------------------------------------------------*/
 
-#ifdef CONFIG_ENABLE_DEVICE_NOISE
-# define DEBUG
-#endif
-
 #include <common.h>
 
 #include <command.h>
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 3b94779..e0d78d0 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -18,10 +18,6 @@
  *
  */
 
-#ifdef CONFIG_ENABLE_DEVICE_NOISE
-# define DEBUG
-#endif
-
 #include <common.h>
 
 #include <command.h>
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 16:02:54 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 22:02:54 +0200
Subject: [PATCH] remove empty board config.h files
Message-ID: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>

This removes several empty board config.h files. The boards which
do not have a config.h are then added to a newly created
arch/arm/boards/Makefile. This prepares the build system for
multiple board support.

Jean-Christophe, I'd like to get rid of the remaining config.h
files. The bulk of the remaining ones are at91 and most of
them contain a single define for AT91_MAIN_CLK. Could you work
on this? I could do it myself but I'm sure you have your own
idea how this should be accomplished.

Sascha

----------------------------------------------------------------
Sascha Hauer (3):
      ARM: Marvell boards: remove empty config.h files
      ARM: i.MX boards: remove empty config.h files
      ARM: Turn most board directories into regular build directories

 arch/arm/Makefile                                | 78 +++---------------------
 arch/arm/boards/Makefile                         | 68 +++++++++++++++++++++
 arch/arm/boards/eukrea_cpuimx25/config.h         | 23 -------
 arch/arm/boards/eukrea_cpuimx35/config.h         | 19 ------
 arch/arm/boards/freescale-mx25-3-stack/config.h  | 27 --------
 arch/arm/boards/freescale-mx35-3-stack/config.h  | 24 --------
 arch/arm/boards/globalscale-guruplug/config.h    |  4 --
 arch/arm/boards/globalscale-mirabox/config.h     |  4 --
 arch/arm/boards/guf-cupid/config.h               | 27 --------
 arch/arm/boards/karo-tx25/config.h               | 27 --------
 arch/arm/boards/marvell-armada-xp-gp/config.h    |  4 --
 arch/arm/boards/pcm037/config.h                  | 31 ----------
 arch/arm/boards/pcm043/config.h                  | 27 --------
 arch/arm/boards/plathome-openblocks-ax3/config.h |  4 --
 arch/arm/boards/scb9328/config.h                 | 26 --------
 15 files changed, 77 insertions(+), 316 deletions(-)
 create mode 100644 arch/arm/boards/Makefile
 delete mode 100644 arch/arm/boards/eukrea_cpuimx25/config.h
 delete mode 100644 arch/arm/boards/eukrea_cpuimx35/config.h
 delete mode 100644 arch/arm/boards/freescale-mx25-3-stack/config.h
 delete mode 100644 arch/arm/boards/freescale-mx35-3-stack/config.h
 delete mode 100644 arch/arm/boards/globalscale-guruplug/config.h
 delete mode 100644 arch/arm/boards/globalscale-mirabox/config.h
 delete mode 100644 arch/arm/boards/guf-cupid/config.h
 delete mode 100644 arch/arm/boards/karo-tx25/config.h
 delete mode 100644 arch/arm/boards/marvell-armada-xp-gp/config.h
 delete mode 100644 arch/arm/boards/pcm037/config.h
 delete mode 100644 arch/arm/boards/pcm043/config.h
 delete mode 100644 arch/arm/boards/plathome-openblocks-ax3/config.h
 delete mode 100644 arch/arm/boards/scb9328/config.h


From s.hauer at pengutronix.de  Sun Jun 23 16:02:56 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 22:02:56 +0200
Subject: [PATCH 2/3] ARM: i.MX boards: remove empty config.h files
In-Reply-To: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>
References: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372017777-787-3-git-send-email-s.hauer@pengutronix.de>

config.h is automatically generated if not existing, so remove
the empty files and files which only have unused defines.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/eukrea_cpuimx25/config.h        | 23 ------------------
 arch/arm/boards/eukrea_cpuimx35/config.h        | 19 ---------------
 arch/arm/boards/freescale-mx25-3-stack/config.h | 27 ---------------------
 arch/arm/boards/freescale-mx35-3-stack/config.h | 24 -------------------
 arch/arm/boards/guf-cupid/config.h              | 27 ---------------------
 arch/arm/boards/karo-tx25/config.h              | 27 ---------------------
 arch/arm/boards/pcm037/config.h                 | 31 -------------------------
 arch/arm/boards/pcm043/config.h                 | 27 ---------------------
 arch/arm/boards/scb9328/config.h                | 26 ---------------------
 9 files changed, 231 deletions(-)
 delete mode 100644 arch/arm/boards/eukrea_cpuimx25/config.h
 delete mode 100644 arch/arm/boards/eukrea_cpuimx35/config.h
 delete mode 100644 arch/arm/boards/freescale-mx25-3-stack/config.h
 delete mode 100644 arch/arm/boards/freescale-mx35-3-stack/config.h
 delete mode 100644 arch/arm/boards/guf-cupid/config.h
 delete mode 100644 arch/arm/boards/karo-tx25/config.h
 delete mode 100644 arch/arm/boards/pcm037/config.h
 delete mode 100644 arch/arm/boards/pcm043/config.h
 delete mode 100644 arch/arm/boards/scb9328/config.h

diff --git a/arch/arm/boards/eukrea_cpuimx25/config.h b/arch/arm/boards/eukrea_cpuimx25/config.h
deleted file mode 100644
index 12ec627..0000000
--- a/arch/arm/boards/eukrea_cpuimx25/config.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * (c) 2010 Eukrea Electromatique, Eric B?nard <eric at eukrea.com>
- *
- * 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.
- *
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-#define CONFIG_MX25_HCLK_FREQ	24000000
-
-#endif
-
-/* nothing to do here yet */
diff --git a/arch/arm/boards/eukrea_cpuimx35/config.h b/arch/arm/boards/eukrea_cpuimx35/config.h
deleted file mode 100644
index 070b314..0000000
--- a/arch/arm/boards/eukrea_cpuimx35/config.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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.
- *
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-#define CONFIG_MX35_HCLK_FREQ        24000000
-
-#endif	/* __CONFIG_H */
diff --git a/arch/arm/boards/freescale-mx25-3-stack/config.h b/arch/arm/boards/freescale-mx25-3-stack/config.h
deleted file mode 100644
index f5d05be..0000000
--- a/arch/arm/boards/freescale-mx25-3-stack/config.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * (C) Copyright 2007 Juergen Beisert <jbe at pengutronix.de>
- *
- * 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.
- *
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-/*
- * Definitions related to passing arguments to kernel.
- */
-
-#define CONFIG_MX25_HCLK_FREQ	24000000
-
-#endif
-
-/* nothing to do here yet */
diff --git a/arch/arm/boards/freescale-mx35-3-stack/config.h b/arch/arm/boards/freescale-mx35-3-stack/config.h
deleted file mode 100644
index 39832d9..0000000
--- a/arch/arm/boards/freescale-mx35-3-stack/config.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.
- *
- */
-
-/**
- * @file
- * @brief Global defintions for the Freescale i.MX35 3-stack board
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-#define CONFIG_MX35_HCLK_FREQ        24000000
-
-#endif	/* __CONFIG_H */
diff --git a/arch/arm/boards/guf-cupid/config.h b/arch/arm/boards/guf-cupid/config.h
deleted file mode 100644
index 501a44d..0000000
--- a/arch/arm/boards/guf-cupid/config.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * (C) Copyright 2007 Juergen Beisert <jbe at pengutronix.de>
- *
- * 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.
- *
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-/*
- * Definitions related to passing arguments to kernel.
- */
-
-#define CONFIG_MX35_HCLK_FREQ	24000000
-
-#endif
-
-/* nothing to do here yet */
diff --git a/arch/arm/boards/karo-tx25/config.h b/arch/arm/boards/karo-tx25/config.h
deleted file mode 100644
index 4cbb4f6..0000000
--- a/arch/arm/boards/karo-tx25/config.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * (C) Copyright 2011 Sascha Hauer <s.hauer at pengutronix.de>
- *
- * 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.
- *
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-/*
- * Definitions related to passing arguments to kernel.
- */
-
-#define CONFIG_MX25_HCLK_FREQ	24000000
-
-#endif
-
-/* nothing to do here yet */
diff --git a/arch/arm/boards/pcm037/config.h b/arch/arm/boards/pcm037/config.h
deleted file mode 100644
index ca62df6..0000000
--- a/arch/arm/boards/pcm037/config.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * (C) Copyright 2007 Juergen Beisert <jbe at pengutronix.de>
- *
- * 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.
- *
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-/*
- * Definitions related to passing arguments to kernel.
- */
-
-/* #define CONFIG_SYSPLL_CLK_FREQ	26000000 */
-
-/* FIXME */
-#define CONFIG_MX31_HCLK_FREQ	26000000
-#define CONFIG_MX31_CLK32	32000
-
-#endif
-
-/* nothing to do here yet */
diff --git a/arch/arm/boards/pcm043/config.h b/arch/arm/boards/pcm043/config.h
deleted file mode 100644
index 501a44d..0000000
--- a/arch/arm/boards/pcm043/config.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * (C) Copyright 2007 Juergen Beisert <jbe at pengutronix.de>
- *
- * 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.
- *
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-/*
- * Definitions related to passing arguments to kernel.
- */
-
-#define CONFIG_MX35_HCLK_FREQ	24000000
-
-#endif
-
-/* nothing to do here yet */
diff --git a/arch/arm/boards/scb9328/config.h b/arch/arm/boards/scb9328/config.h
deleted file mode 100644
index e825482..0000000
--- a/arch/arm/boards/scb9328/config.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2003 ETC s.r.o.
- *
- * 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.
- *
- *
- * Written by Peter Figuli <peposh at etc.sk>, 2003.
- *
- * 2003/13/06 Initial MP10 Support copied from wepep250
- */
-
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-#define CONFIG_SYSPLL_CLK_FREQ 16000000
-
-#endif	/* __CONFIG_H */
-
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 16:02:57 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 22:02:57 +0200
Subject: [PATCH 3/3] ARM: Turn most board directories into regular build
 directories
In-Reply-To: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>
References: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372017777-787-4-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/Makefile        | 78 ++++++------------------------------------------
 arch/arm/boards/Makefile | 68 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+), 69 deletions(-)
 create mode 100644 arch/arm/boards/Makefile

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 32bdd65..2f0f16e 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -69,13 +69,19 @@ machine-$(CONFIG_ARCH_VEXPRESS)		:= vexpress
 machine-$(CONFIG_ARCH_TEGRA)		:= tegra
 machine-$(CONFIG_ARCH_ZYNQ)		:= zynq
 
+
 # Board directory name.  This list is sorted alphanumerically
 # by CONFIG_* macro name.
-
+#
+# DO NOT ADD NEW ENTRIES TO THIS LIST!
+# Add to arch/arm/boards/Makefile instead.
+#
+# These are here only because they have a board specific config.h.
+# TODO: Get rid of board specific config.h and move these to
+# arch/arm/boards/Makefile aswell.
 board-$(CONFIG_MACH_A9M2410)			+= a9m2410
 board-$(CONFIG_MACH_A9M2440)			+= a9m2440
 board-$(CONFIG_MACH_ANIMEO_IP)			+= animeo_ip
-board-$(CONFIG_MACH_ARCHOSG9)			+= archosg9
 board-$(CONFIG_MACH_AT91RM9200EK)		+= at91rm9200ek
 board-$(CONFIG_MACH_AT91SAM9260EK)		+= at91sam9260ek
 board-$(CONFIG_MACH_AT91SAM9261EK)		+= at91sam9261ek
@@ -86,93 +92,27 @@ board-$(CONFIG_MACH_AT91SAM9M10G45EK)		+= at91sam9m10g45ek
 board-$(CONFIG_MACH_AT91SAM9M10IHD)		+= at91sam9m10ihd
 board-$(CONFIG_MACH_AT91SAM9N12EK)		+= at91sam9n12ek
 board-$(CONFIG_MACH_AT91SAM9X5EK)		+= at91sam9x5ek
-board-$(CONFIG_MACH_BEAGLE)			+= beagle
-board-$(CONFIG_MACH_BEAGLEBONE)			+= beaglebone
-board-$(CONFIG_MACH_CCMX51)			+= ccxmx51
-board-$(CONFIG_MACH_CFA10036)			+= crystalfontz-cfa10036
-board-$(CONFIG_MACH_CHUMBY)			+= chumby_falconwing
-board-$(CONFIG_MACH_CLEP7212)			+= clep7212
 board-$(CONFIG_MACH_DSS11)			+= dss11
-board-$(CONFIG_MACH_EDB93012)			+= edb93xx
-board-$(CONFIG_MACH_EDB9301)			+= edb93xx
-board-$(CONFIG_MACH_EDB9302A)			+= edb93xx
-board-$(CONFIG_MACH_EDB9302)			+= edb93xx
-board-$(CONFIG_MACH_EDB9307A)			+= edb93xx
-board-$(CONFIG_MACH_EDB9307)			+= edb93xx
-board-$(CONFIG_MACH_EDB9315A)			+= edb93xx
-board-$(CONFIG_MACH_EDB9315)			+= edb93xx
-board-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK)		+= efika-mx-smartbook
-board-$(CONFIG_MACH_EUKREA_CPUIMX25)		+= eukrea_cpuimx25
-board-$(CONFIG_MACH_EUKREA_CPUIMX27)		+= eukrea_cpuimx27
-board-$(CONFIG_MACH_EUKREA_CPUIMX35)		+= eukrea_cpuimx35
-board-$(CONFIG_MACH_EUKREA_CPUIMX51SD)		+= eukrea_cpuimx51
-board-$(CONFIG_MACH_FREESCALE_MX25_3STACK)	+= freescale-mx25-3-stack
-board-$(CONFIG_MACH_FREESCALE_MX35_3STACK)	+= freescale-mx35-3-stack
-board-$(CONFIG_MACH_FREESCALE_MX51_PDK)		+= freescale-mx51-pdk
-board-$(CONFIG_MACH_FREESCALE_MX53_LOCO)	+= freescale-mx53-loco
-board-$(CONFIG_MACH_FREESCALE_MX53_SMD)		+= freescale-mx53-smd
 board-$(CONFIG_MACH_GE863)			+= telit-evk-pro3
-board-$(CONFIG_MACH_GLOBALSCALE_GURUPLUG)       += globalscale-guruplug
-board-$(CONFIG_MACH_GLOBALSCALE_MIRABOX)        += globalscale-mirabox
-board-$(CONFIG_MACH_GUF_CUPID)			+= guf-cupid
-board-$(CONFIG_MACH_GUF_VINCELL)		+= guf-vincell
-board-$(CONFIG_MACH_HIGHBANK)			+= highbank
-board-$(CONFIG_MACH_IMX21ADS)			+= imx21ads
-board-$(CONFIG_MACH_IMX233_OLINUXINO)		+= imx233-olinuxino
-board-$(CONFIG_MACH_IMX27ADS)			+= imx27ads
-board-$(CONFIG_MACH_MARVELL_ARMADA_XP_GP)	+= marvell-armada-xp-gp
 board-$(CONFIG_MACH_MINI2440)			+= friendlyarm-mini2440
 board-$(CONFIG_MACH_MINI6410)			+= friendlyarm-mini6410
-board-$(CONFIG_MACH_MIOA701)			+= mioa701
 board-$(CONFIG_MACH_MMCCPU)			+= mmccpu
-board-$(CONFIG_MACH_MX23EVK)			+= freescale-mx23-evk
-board-$(CONFIG_MACH_MX28EVK)			+= freescale-mx28-evk
-board-$(CONFIG_MACH_MX6Q_ARM2)			+= freescale-mx6-arm2
-board-$(CONFIG_MACH_NESO)			+= guf-neso
-board-$(CONFIG_MACH_NOMADIK_8815NHK)		+= nhk8815
-board-$(CONFIG_MACH_NXDB500)			+= netx
-board-$(CONFIG_MACH_OMAP343xSDP)		+= omap343xdsp
-board-$(CONFIG_MACH_OMAP3EVM)			+= omap3evm
-board-$(CONFIG_MACH_PANDA)			+= panda
-board-$(CONFIG_MACH_PCA100)			+= phycard-i.MX27
-board-$(CONFIG_MACH_PCAAL1)			+= phycard-a-l1
-board-$(CONFIG_MACH_PCAAXL2)			+= phycard-a-xl2
 board-$(CONFIG_MACH_PCM027)			+= pcm027
-board-$(CONFIG_MACH_PCM037)			+= pcm037
-board-$(CONFIG_MACH_PCM038)			+= pcm038
-board-$(CONFIG_MACH_PCM043)			+= pcm043
-board-$(CONFIG_MACH_PCM049)			+= pcm049
-board-$(CONFIG_MACH_PCM051)			+= pcm051
-board-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3)	+= plathome-openblocks-ax3
 board-$(CONFIG_MACH_PM9261)			+= pm9261
 board-$(CONFIG_MACH_PM9263)			+= pm9263
 board-$(CONFIG_MACH_PM9G45)			+= pm9g45
 board-$(CONFIG_MACH_QIL_A9260)			+= qil-a926x
 board-$(CONFIG_MACH_QIL_A9G20)			+= qil-a926x
-board-$(CONFIG_MACH_REALQ7)			+= dmo-mx6-realq7
-board-$(CONFIG_MACH_RPI)			+= raspberry-pi
-board-$(CONFIG_MACH_SABRELITE)			+= freescale-mx6-sabrelite
-board-$(CONFIG_MACH_SABRESD)			+= freescale-mx6-sabresd
 board-$(CONFIG_MACH_SAMA5D3XEK)			+= sama5d3xek
-board-$(CONFIG_MACH_SCB9328)			+= scb9328
 board-$(CONFIG_MACH_SOLIDRUN_CUBOX)		+= solidrun-cubox
 board-$(CONFIG_MACH_TINY210)			+= friendlyarm-tiny210
 board-$(CONFIG_MACH_TINY6410)			+= friendlyarm-tiny6410
 board-$(CONFIG_MACH_TNY_A9260)			+= tny-a926x
 board-$(CONFIG_MACH_TNY_A9263)			+= tny-a926x
 board-$(CONFIG_MACH_TNY_A9G20)			+= tny-a926x
-board-$(CONFIG_MACH_TOSHIBA_AC100)		+= toshiba-ac100
-board-$(CONFIG_MACH_TQMA53)			+= tqma53
-board-$(CONFIG_MACH_TX25)			+= karo-tx25
-board-$(CONFIG_MACH_TX28)			+= karo-tx28
-board-$(CONFIG_MACH_TX51)			+= karo-tx51
-board-$(CONFIG_MACH_TX53)			+= karo-tx53
 board-$(CONFIG_MACH_USB_A9260)			+= usb-a926x
 board-$(CONFIG_MACH_USB_A9263)			+= usb-a926x
 board-$(CONFIG_MACH_USB_A9G20)			+= usb-a926x
-board-$(CONFIG_MACH_VERSATILEPB)		+= versatile
-board-$(CONFIG_MACH_VEXPRESS)			+= vexpress
-board-$(CONFIG_MACH_ZEDBOARD)			+= avnet-zedboard
 
 machdirs := $(patsubst %,arch/arm/mach-%/,$(machine-y))
 
@@ -325,7 +265,7 @@ else
 MACH :=
 endif
 
-common-y += $(BOARD) $(MACH)
+common-y += $(BOARD) arch/arm/boards/ $(MACH)
 common-y += arch/arm/lib/ arch/arm/cpu/
 
 common-$(CONFIG_BUILTIN_DTB) += arch/arm/dts/
diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
new file mode 100644
index 0000000..6d1e98d
--- /dev/null
+++ b/arch/arm/boards/Makefile
@@ -0,0 +1,68 @@
+# keep sorted by CONFIG_* macro name.
+obj-$(CONFIG_MACH_ARCHOSG9)			+= archosg9/
+obj-$(CONFIG_MACH_BEAGLE)			+= beagle/
+obj-$(CONFIG_MACH_BEAGLEBONE)			+= beaglebone/
+obj-$(CONFIG_MACH_CCMX51)			+= ccxmx51/
+obj-$(CONFIG_MACH_CFA10036)			+= crystalfontz-cfa10036/
+obj-$(CONFIG_MACH_CHUMBY)			+= chumby_falconwing/
+obj-$(CONFIG_MACH_CLEP7212)			+= clep7212/
+obj-$(CONFIG_MACH_EDB93012)			+= edb93xx/
+obj-$(CONFIG_MACH_EDB9301)			+= edb93xx/
+obj-$(CONFIG_MACH_EDB9302A)			+= edb93xx/
+obj-$(CONFIG_MACH_EDB9302)			+= edb93xx/
+obj-$(CONFIG_MACH_EDB9307A)			+= edb93xx/
+obj-$(CONFIG_MACH_EDB9307)			+= edb93xx/
+obj-$(CONFIG_MACH_EDB9315A)			+= edb93xx/
+obj-$(CONFIG_MACH_EDB9315)			+= edb93xx/
+obj-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK)		+= efika-mx-smartbook/
+obj-$(CONFIG_MACH_EUKREA_CPUIMX25)		+= eukrea_cpuimx25/
+obj-$(CONFIG_MACH_EUKREA_CPUIMX27)		+= eukrea_cpuimx27/
+obj-$(CONFIG_MACH_EUKREA_CPUIMX35)		+= eukrea_cpuimx35/
+obj-$(CONFIG_MACH_EUKREA_CPUIMX51SD)		+= eukrea_cpuimx51/
+obj-$(CONFIG_MACH_FREESCALE_MX25_3STACK)	+= freescale-mx25-3-stack/
+obj-$(CONFIG_MACH_FREESCALE_MX35_3STACK)	+= freescale-mx35-3-stack/
+obj-$(CONFIG_MACH_FREESCALE_MX51_PDK)		+= freescale-mx51-pdk/
+obj-$(CONFIG_MACH_FREESCALE_MX53_LOCO)		+= freescale-mx53-loco/
+obj-$(CONFIG_MACH_FREESCALE_MX53_SMD)		+= freescale-mx53-smd/
+obj-$(CONFIG_MACH_GLOBALSCALE_GURUPLUG)		+= globalscale-guruplug/
+obj-$(CONFIG_MACH_GLOBALSCALE_MIRABOX)		+= globalscale-mirabox/
+obj-$(CONFIG_MACH_GUF_CUPID)			+= guf-cupid/
+obj-$(CONFIG_MACH_GUF_VINCELL)			+= guf-vincell/
+obj-$(CONFIG_MACH_HIGHBANK)			+= highbank/
+obj-$(CONFIG_MACH_IMX21ADS)			+= imx21ads/
+obj-$(CONFIG_MACH_IMX233_OLINUXINO)		+= imx233-olinuxino/
+obj-$(CONFIG_MACH_IMX27ADS)			+= imx27ads/
+obj-$(CONFIG_MACH_MARVELL_ARMADA_XP_GP)		+= marvell-armada-xp-gp/
+obj-$(CONFIG_MACH_MIOA701)			+= mioa701/
+obj-$(CONFIG_MACH_MX23EVK)			+= freescale-mx23-evk/
+obj-$(CONFIG_MACH_MX28EVK)			+= freescale-mx28-evk/
+obj-$(CONFIG_MACH_MX6Q_ARM2)			+= freescale-mx6-arm2/
+obj-$(CONFIG_MACH_NESO)				+= guf-neso/
+obj-$(CONFIG_MACH_NOMADIK_8815NHK)		+= nhk8815/
+obj-$(CONFIG_MACH_NXDB500)			+= netx/
+obj-$(CONFIG_MACH_OMAP343xSDP)			+= omap343xdsp/
+obj-$(CONFIG_MACH_OMAP3EVM)			+= omap3evm/
+obj-$(CONFIG_MACH_PANDA)			+= panda/
+obj-$(CONFIG_MACH_PCA100)			+= phycard-i.MX27/
+obj-$(CONFIG_MACH_PCAAL1)			+= phycard-a-l1/
+obj-$(CONFIG_MACH_PCAAXL2)			+= phycard-a-xl2/
+obj-$(CONFIG_MACH_PCM037)			+= pcm037/
+obj-$(CONFIG_MACH_PCM038)			+= pcm038/
+obj-$(CONFIG_MACH_PCM043)			+= pcm043/
+obj-$(CONFIG_MACH_PCM049)			+= pcm049/
+obj-$(CONFIG_MACH_PCM051)			+= pcm051/
+obj-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3)	+= plathome-openblocks-ax3/
+obj-$(CONFIG_MACH_REALQ7)			+= dmo-mx6-realq7/
+obj-$(CONFIG_MACH_RPI)				+= raspberry-pi/
+obj-$(CONFIG_MACH_SABRELITE)			+= freescale-mx6-sabrelite/
+obj-$(CONFIG_MACH_SABRESD)			+= freescale-mx6-sabresd/
+obj-$(CONFIG_MACH_SCB9328)			+= scb9328/
+obj-$(CONFIG_MACH_TOSHIBA_AC100)		+= toshiba-ac100/
+obj-$(CONFIG_MACH_TQMA53)			+= tqma53/
+obj-$(CONFIG_MACH_TX25)				+= karo-tx25/
+obj-$(CONFIG_MACH_TX28)				+= karo-tx28/
+obj-$(CONFIG_MACH_TX51)				+= karo-tx51/
+obj-$(CONFIG_MACH_TX53)				+= karo-tx53/
+obj-$(CONFIG_MACH_VERSATILEPB)			+= versatile/
+obj-$(CONFIG_MACH_VEXPRESS)			+= vexpress/
+obj-$(CONFIG_MACH_ZEDBOARD)			+= avnet-zedboard/
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 16:02:55 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 22:02:55 +0200
Subject: [PATCH 1/3] ARM: Marvell boards: remove empty config.h files
In-Reply-To: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>
References: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372017777-787-2-git-send-email-s.hauer@pengutronix.de>

config.h is automatically generated if not existing, so remove
the empty files.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/globalscale-guruplug/config.h    | 4 ----
 arch/arm/boards/globalscale-mirabox/config.h     | 4 ----
 arch/arm/boards/marvell-armada-xp-gp/config.h    | 4 ----
 arch/arm/boards/plathome-openblocks-ax3/config.h | 4 ----
 4 files changed, 16 deletions(-)
 delete mode 100644 arch/arm/boards/globalscale-guruplug/config.h
 delete mode 100644 arch/arm/boards/globalscale-mirabox/config.h
 delete mode 100644 arch/arm/boards/marvell-armada-xp-gp/config.h
 delete mode 100644 arch/arm/boards/plathome-openblocks-ax3/config.h

diff --git a/arch/arm/boards/globalscale-guruplug/config.h b/arch/arm/boards/globalscale-guruplug/config.h
deleted file mode 100644
index ca15136..0000000
--- a/arch/arm/boards/globalscale-guruplug/config.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-#endif	/* __CONFIG_H */
diff --git a/arch/arm/boards/globalscale-mirabox/config.h b/arch/arm/boards/globalscale-mirabox/config.h
deleted file mode 100644
index ca15136..0000000
--- a/arch/arm/boards/globalscale-mirabox/config.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-#endif	/* __CONFIG_H */
diff --git a/arch/arm/boards/marvell-armada-xp-gp/config.h b/arch/arm/boards/marvell-armada-xp-gp/config.h
deleted file mode 100644
index ca15136..0000000
--- a/arch/arm/boards/marvell-armada-xp-gp/config.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-#endif	/* __CONFIG_H */
diff --git a/arch/arm/boards/plathome-openblocks-ax3/config.h b/arch/arm/boards/plathome-openblocks-ax3/config.h
deleted file mode 100644
index ca15136..0000000
--- a/arch/arm/boards/plathome-openblocks-ax3/config.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef __CONFIG_H
-#define __CONFIG_H
-
-#endif	/* __CONFIG_H */
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 16:04:44 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 22:04:44 +0200
Subject: [PATCH] add function to get boardinfo string
Message-ID: <1372017884-28116-1-git-send-email-s.hauer@pengutronix.de>

When using devicetrees the boardinfo (or model) can be obtained
from the devicetree. Add a function to get the boardinfo so that
we have a chance to add information from the devicetree.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/misc.c                 | 12 ++++++++++++
 common/version.c              | 10 +---------
 include/common.h              |  2 ++
 lib/process_escape_sequence.c |  2 +-
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/common/misc.c b/common/misc.c
index e9fdacc..414c909 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -125,3 +125,15 @@ EXPORT_SYMBOL(perror);
 
 void (*do_execute)(void *func, int argc, char *argv[]);
 EXPORT_SYMBOL(do_execute);
+
+const char *barebox_boardinfo(void)
+{
+	const char *boardinfo;
+
+	boardinfo = of_get_model();
+	if (!boardinfo)
+		boardinfo = CONFIG_BOARDINFO;
+
+	return boardinfo;
+}
+EXPORT_SYMBOL(barebox_boardinfo);
diff --git a/common/version.c b/common/version.c
index d33f4d0..e21dbbe 100644
--- a/common/version.c
+++ b/common/version.c
@@ -1,7 +1,6 @@
 #include <common.h>
 #include <generated/compile.h>
 #include <generated/utsrelease.h>
-#include <of.h>
 
 const char version_string[] =
 	"barebox " UTS_RELEASE " " UTS_VERSION "\n";
@@ -9,13 +8,6 @@ EXPORT_SYMBOL(version_string);
 
 void barebox_banner (void)
 {
-	const char *board;
-
-	board = of_get_model();
-
-	if (!board)
-		board = CONFIG_BOARDINFO;
-
 	pr_info("\n\n%s\n\n", version_string);
-	pr_info("Board: %s\n", board);
+	pr_info("Board: %s\n", barebox_boardinfo());
 }
diff --git a/include/common.h b/include/common.h
index 59fcd35..88af931 100644
--- a/include/common.h
+++ b/include/common.h
@@ -233,6 +233,8 @@ void barebox_banner(void);
 static inline void barebox_banner(void) {}
 #endif
 
+const char *barebox_boardinfo(void);
+
 #define IOMEM(addr)	((void __force __iomem *)(addr))
 
 #define DIV_ROUND_UP(n,d)	(((n) + (d) - 1) / (d))
diff --git a/lib/process_escape_sequence.c b/lib/process_escape_sequence.c
index 7cc3898..612976b 100644
--- a/lib/process_escape_sequence.c
+++ b/lib/process_escape_sequence.c
@@ -54,7 +54,7 @@ int process_escape_sequence(const char *source, char *dest, int destlen)
 				dest[i++] = 0x1b;
 				break;
 			case 'h':
-				i += snprintf(dest + i, destlen - i, "%s", CONFIG_BOARDINFO);
+				i += snprintf(dest + i, destlen - i, "%s", barebox_boardinfo());
 				break;
 			case 'w':
 				i += snprintf(dest + i, destlen - i, "%s", getcwd());
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Sun Jun 23 16:11:39 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Sun, 23 Jun 2013 22:11:39 +0200
Subject: [PATCH 3/3] OF: base: add empty property value pointer
In-Reply-To: <20130623183324.GJ32299@pengutronix.de>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371827718-7928-4-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130623183324.GJ32299@pengutronix.de>
Message-ID: <51C7567B.20008@gmail.com>

On 06/23/2013 08:33 PM, Sascha Hauer wrote:
> On Fri, Jun 21, 2013 at 05:15:18PM +0200, Sebastian Hesselbarth wrote:
>> Since property values can be empty, we need property value pointer to
>> be non-NULL to distinguish those properties from non-existing properties.
>> This adds a static u32 to which empty properties set their value pointer.
>> Also, the value memory is only freed, if property length is not zero.
>>
>> Signed-off-by: Sebastian Hesselbarth<sebastian.hesselbarth at gmail.com>
>> ---
>> Cc: barebox at lists.infradead.org
>> ---
>>   drivers/of/base.c |    6 +++++-
>>   1 files changed, 5 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/of/base.c b/drivers/of/base.c
>> index 7926d5d..a100a17 100644
>> --- a/drivers/of/base.c
>> +++ b/drivers/of/base.c
>> @@ -1501,6 +1501,8 @@ struct device_node *of_new_node(struct device_node *parent, const char *name)
>>   	return node;
>>   }
>>
>> +static u32 empty_prop_value;
>> +
>>   struct property *of_new_property(struct device_node *node, const char *name,
>>   		const void *data, int len)
>>   {
>> @@ -1515,6 +1517,7 @@ struct property *of_new_property(struct device_node *node, const char *name,
>>   		goto bail_out;
>>
>>   	prop->length = len;
>> +	prop->value =&empty_prop_value;
>
> This at least breaks of_set_property() and of_free(). Both unconditionally
> do a free(pp->value).

Sascha,

this is patch 3/3, the two functions above are taken care of patch 2/3.

> Why do we need this anyway? We can always call of_find_property() to see
> if a property exists.

Actually, I was preparing to import drivers/of/address.c from linux.
of_translate_one uses of_get_property on "ranges". This returns
the property's value pointer instead of the property itself, which
is NULL for an empty ranges property. Now that you point it out,
using of_find_property is also an option.

Nevertheless, patches 1 (with your comments applied) and 2 seem
sensible to me. Patch 3 is an option to keep it in sync with Linux
OF API behavior but is optional.

Sebastian


From s.hauer at pengutronix.de  Sun Jun 23 16:26:19 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 22:26:19 +0200
Subject: [PATCH 3/3] OF: base: add empty property value pointer
In-Reply-To: <51C7567B.20008@gmail.com>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371827718-7928-4-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130623183324.GJ32299@pengutronix.de> <51C7567B.20008@gmail.com>
Message-ID: <20130623202619.GS32299@pengutronix.de>

On Sun, Jun 23, 2013 at 10:11:39PM +0200, Sebastian Hesselbarth wrote:
> On 06/23/2013 08:33 PM, Sascha Hauer wrote:
> >On Fri, Jun 21, 2013 at 05:15:18PM +0200, Sebastian Hesselbarth wrote:
> >>Since property values can be empty, we need property value pointer to
> >>be non-NULL to distinguish those properties from non-existing properties.
> >>This adds a static u32 to which empty properties set their value pointer.
> >>Also, the value memory is only freed, if property length is not zero.
> >>
> >>Signed-off-by: Sebastian Hesselbarth<sebastian.hesselbarth at gmail.com>
> >>---
> >>Cc: barebox at lists.infradead.org
> >>---
> >>  drivers/of/base.c |    6 +++++-
> >>  1 files changed, 5 insertions(+), 1 deletions(-)
> >>
> >>diff --git a/drivers/of/base.c b/drivers/of/base.c
> >>index 7926d5d..a100a17 100644
> >>--- a/drivers/of/base.c
> >>+++ b/drivers/of/base.c
> >>@@ -1501,6 +1501,8 @@ struct device_node *of_new_node(struct device_node *parent, const char *name)
> >>  	return node;
> >>  }
> >>
> >>+static u32 empty_prop_value;
> >>+
> >>  struct property *of_new_property(struct device_node *node, const char *name,
> >>  		const void *data, int len)
> >>  {
> >>@@ -1515,6 +1517,7 @@ struct property *of_new_property(struct device_node *node, const char *name,
> >>  		goto bail_out;
> >>
> >>  	prop->length = len;
> >>+	prop->value =&empty_prop_value;
> >
> >This at least breaks of_set_property() and of_free(). Both unconditionally
> >do a free(pp->value).
> 
> Sascha,
> 
> this is patch 3/3, the two functions above are taken care of patch 2/3.

Ah, sorry, I missed that.

> 
> >Why do we need this anyway? We can always call of_find_property() to see
> >if a property exists.
> 
> Actually, I was preparing to import drivers/of/address.c from linux.
> of_translate_one uses of_get_property on "ranges". This returns
> the property's value pointer instead of the property itself, which
> is NULL for an empty ranges property. Now that you point it out,
> using of_find_property is also an option.
> 
> Nevertheless, patches 1 (with your comments applied) and 2 seem
> sensible to me. Patch 3 is an option to keep it in sync with Linux
> OF API behavior but is optional.

How about allocating zero length property values with malloc(0)? This
makes them less special.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sun Jun 23 16:27:33 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 22:27:33 +0200
Subject: [PATCH 1/2] ARM: scb9328: remove dead code
Message-ID: <1372019254-23540-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/scb9328/lowlevel_init.S | 51 ---------------------------------
 1 file changed, 51 deletions(-)

diff --git a/arch/arm/boards/scb9328/lowlevel_init.S b/arch/arm/boards/scb9328/lowlevel_init.S
index d7afa21..4250c95 100644
--- a/arch/arm/boards/scb9328/lowlevel_init.S
+++ b/arch/arm/boards/scb9328/lowlevel_init.S
@@ -15,61 +15,10 @@
 #include <mach/imx1-regs.h>
 #include <asm/barebox-arm-head.h>
 
-#define CPU200
-
-#ifdef CPU200
 #define CFG_MPCTL0_VAL 0x00321431
-#else
-#define CFG_MPCTL0_VAL 0x040e200e
-#endif
-
-#define BUS72
-
-#ifdef BUS72
 #define CFG_SPCTL0_VAL 0x04002400
-#endif
-
-#ifdef BUS96
-#define CFG_SPCTL0_VAL 0x04001800
-#endif
-
-#ifdef BUS64
-#define CFG_SPCTL0_VAL 0x08001800
-#endif
-
-/* Das ist der BCLK Divider, der aus der System PLL
-   BCLK und HCLK erzeugt:
-   31 | xxxx xxxx xxxx xxxx xx10 11xx xxxx xxxx | 0
-   0x2f008403 : 192MHz/2=96MHz, 144MHz/2=72MHz PRESC=1->BCLKDIV=2
-   0x2f008803 : 192MHz/3=64MHz, 240MHz/3=80MHz PRESC=1->BCLKDIV=2
-   0x2f001003 : 192MHz/5=38,4MHz
-   0x2f000003 : 64MHz/1
-   Bit 22: SPLL Restart
-   Bit 21: MPLL Restart */
-
-#ifdef BUS64
-#define CFG_CSCR_VAL 0x2f030003
-#endif
-
-#ifdef BUS72
 #define CFG_CSCR_VAL 0x2f030403
-#endif
-/* Bit[0:3] contain PERCLK1DIV for UART 1
-   0x000b00b ->b<- -> 192MHz/12=16MHz
-   0x000b00b ->8<- -> 144MHz/09=16MHz
-   0x000b00b ->3<- -> 64MHz/4=16MHz */
-
-#ifdef BUS96
-#define CFG_PCDR_VAL 0x000b00b5
-#endif
-
-#ifdef BUS64
-#define CFG_PCDR_VAL 0x000b00b3
-#endif
-
-#ifdef BUS72
 #define CFG_PCDR_VAL 0x000b00b8
-#endif
 
 #define writel(val, reg) \
 	ldr		r0,	=reg;	\
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 16:27:34 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 22:27:34 +0200
Subject: [PATCH 2/2] ARM: imx27ads: remove dead code
In-Reply-To: <1372019254-23540-1-git-send-email-s.hauer@pengutronix.de>
References: <1372019254-23540-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372019254-23540-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/imx27ads/lowlevel_init.S | 67 +-------------------------------
 1 file changed, 2 insertions(+), 65 deletions(-)

diff --git a/arch/arm/boards/imx27ads/lowlevel_init.S b/arch/arm/boards/imx27ads/lowlevel_init.S
index ce276a9..465f3eb 100644
--- a/arch/arm/boards/imx27ads/lowlevel_init.S
+++ b/arch/arm/boards/imx27ads/lowlevel_init.S
@@ -15,7 +15,7 @@
 
 #define CRM_PLL_PCTL_PARAM(pd, fd, fi, fn)  (((pd-1)<<26) + ((fd-1)<<16) + (fi<<10) + (fn<<0))
 
-.macro sdram_init_sha
+.macro sdram_init
 	/*
 	 * DDR on CSD0
 	 */
@@ -49,69 +49,6 @@
 	writel(0x82226080, 0xD8001000)
 .endm
 
-.macro sdram_init_mx27_manual
-	/*
-	 * sdram init sequence, as defined in 18.5.4 of the i.MX27 reference manual
-	 */
-1:
-	ldr r2, =ESD_ESDCTL0		/* base address of registers */
-	ldr r3, =PRE_ALL_CMD		/* SMODE=001 */
-	str r3,(r2,#0x0)		/* put CSD0 in precharge command mode */
-	ldr r4, =SDRAM_CSD0		/* CSD0 precharge address (A10=1) */
-	str r1,(r4,#0x0)		/* precharge CSD0 all banks */
-	ldr r3, =AUTO_REF_CMD		/* SMODE=010 */
-	str r3,(r2,#0x0)		/* put array 0 in auto-refresh mode */
-	ldr r4, =SDRAM_CSD0_BASE	/* CSD0 base address */
-	ldr r6,=0x7			/* load loop counter */
-1:	ldr r5,(r4,#0x0)		/* run auto-refresh cycle to array 0 */
-	subs r6,r6,#1			/* decrease counter value */
-	bne 1b
-	ldr r3, =SET_MODE_REG_CMD	/* SMODE=011 */
-	str r3,(r2,#0x0)		/* setup CSD0 for mode register write */
-	ldr r3, =MODE_REG_VAL0		/* array 0 mode register value */
-	ldrb r5,(r3,#0x0)		/* New mode register value on address bus */
-	ldr r3, =NORMAL_MODE		/* SMODE=000 */
-	str r3,(r2,#0x0)		/* setup CSD0 for normal operation */
-
-ESD_ESDCTL0		.long 0xD8001000 // system/external device dependent data
-SDRAM_CSD0		.long 0x00000000 // system/external device dependent data
-SDRAM_CSD0_BASE		.long 0x00000000 // system/external device dependent data
-PRE_ALL_CMD		.long 0x00000000 // system/external device dependent data (SMODE=001)
-AUTO_REF_CMD		.long 0x00000000 // system/external device dependent data (SMODE=010)
-SET_MODE_REG_CMD	.long 0x00000000 // system/external device dependent data (SMODE=011)
-MODE_REG_VAL0		.long 0x00000000 // system/external device dependent data
-NORMAL_MODE		.long 0x00000000 // system/external device dependent data (SMODE=000)
-.endm
-
-.macro sdram_init_barebox
-	/* configure 16 bit nor flash on cs0 */
-	writel(0x0000CC03, 0xd8002000)
-	writel(0xa0330D01, 0xd8002004)
-	writel(0x00220800, 0xd8002008)
-
-	/* ddr on csd0 - initial reset */
-	writel(0x00000008, 0xD8001010)
-
-	/* configure ddr on csd0 - wait 5000 cycles */
-	writel(0x00000004, 0xD8001010)
-	writel(0x006ac73a, 0xD8001004)
-	writel(0x92100000, 0xD8001000)
-	writel(0x12344321, 0xA0000f00)
-	writel(0xa2100000, 0xD8001000)
-	writel(0x12344321, 0xA0000000)
-	writel(0x12344321, 0xA0000000)
-	writel(0xb2100000, 0xD8001000)
-	ldr		r0, =0xA0000033
-	mov		r1, #0xda
-	strb		r1, [r0]
-	ldr		r0, =0xA1000000
-	mov		r1, #0xff
-	strb		r1, [r0]
-	writel(0x82226080, 0xD8001000)
-	writel(0xDEADBEEF, 0xA0000000)
-	writel(0x0000000c, 0xD8001010)
-.endm
-
 .globl barebox_arm_reset_vector
 barebox_arm_reset_vector:
 
@@ -169,7 +106,7 @@ barebox_arm_reset_vector:
 
 	b imx27_barebox_entry
 1:
-	sdram_init_sha
+	sdram_init
 
 	b imx27_barebox_entry
 
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Sun Jun 23 16:29:23 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Sun, 23 Jun 2013 22:29:23 +0200
Subject: [PATCH 3/3] OF: base: add empty property value pointer
In-Reply-To: <20130623202619.GS32299@pengutronix.de>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1371827718-7928-4-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130623183324.GJ32299@pengutronix.de> <51C7567B.20008@gmail.com>
 <20130623202619.GS32299@pengutronix.de>
Message-ID: <51C75AA3.8080202@gmail.com>

On 06/23/2013 10:26 PM, Sascha Hauer wrote:
> On Sun, Jun 23, 2013 at 10:11:39PM +0200, Sebastian Hesselbarth wrote:
>> On 06/23/2013 08:33 PM, Sascha Hauer wrote:
>>> Why do we need this anyway? We can always call of_find_property() to see
>>> if a property exists.
>>
>> Actually, I was preparing to import drivers/of/address.c from linux.
>> of_translate_one uses of_get_property on "ranges". This returns
>> the property's value pointer instead of the property itself, which
>> is NULL for an empty ranges property. Now that you point it out,
>> using of_find_property is also an option.
>>
>> Nevertheless, patches 1 (with your comments applied) and 2 seem
>> sensible to me. Patch 3 is an option to keep it in sync with Linux
>> OF API behavior but is optional.
>
> How about allocating zero length property values with malloc(0)? This
> makes them less special.

Agree, I will update the patch set and send a v2 hopefully soon.

Sebastian



From s.hauer at pengutronix.de  Sun Jun 23 17:05:34 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:05:34 +0200
Subject: [PATCH 8/8] ARM: i.MX51 vincell: Switch to imximage
In-Reply-To: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
References: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372021534-25470-8-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/guf-vincell/Makefile            |  2 +-
 arch/arm/boards/guf-vincell/flash-header.imxcfg |  3 ++
 arch/arm/boards/guf-vincell/flash_header.c      | 41 -------------------------
 arch/arm/mach-imx/Kconfig                       |  1 +
 4 files changed, 5 insertions(+), 42 deletions(-)
 create mode 100644 arch/arm/boards/guf-vincell/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/guf-vincell/flash_header.c

diff --git a/arch/arm/boards/guf-vincell/Makefile b/arch/arm/boards/guf-vincell/Makefile
index aa30b7f..01c7a25 100644
--- a/arch/arm/boards/guf-vincell/Makefile
+++ b/arch/arm/boards/guf-vincell/Makefile
@@ -1,2 +1,2 @@
 obj-y += board.o
-lwl-y += flash_header.o lowlevel.o
+lwl-y += lowlevel.o
diff --git a/arch/arm/boards/guf-vincell/flash-header.imxcfg b/arch/arm/boards/guf-vincell/flash-header.imxcfg
new file mode 100644
index 0000000..bb0c318
--- /dev/null
+++ b/arch/arm/boards/guf-vincell/flash-header.imxcfg
@@ -0,0 +1,3 @@
+soc imx53
+loadaddr 0xf8020000
+dcdofs 0x400
diff --git a/arch/arm/boards/guf-vincell/flash_header.c b/arch/arm/boards/guf-vincell/flash_header.c
deleted file mode 100644
index df480d2..0000000
--- a/arch/arm/boards/guf-vincell/flash_header.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2011 Marc Kleine-Budde <mkl at pengutronix.de>
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <sizes.h>
-#include <asm/byteorder.h>
-#include <asm/barebox-arm-head.h>
-#include <mach/imx-flash-header.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-#define APP_DEST	0xf8020000
-
-struct imx_flash_header_v2 __flash_header_section flash_header = {
-	.header.tag		= IVT_HEADER_TAG,
-	.header.length		= cpu_to_be16(32),
-	.header.version		= IVT_VERSION,
-
-	.entry			= APP_DEST + 0x1000,
-	.dcd_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header_v2, dcd),
-	.boot_data_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header_v2, boot_data),
-	.self			= APP_DEST + 0x400,
-
-	.boot_data.start	= APP_DEST,
-	.boot_data.size		= DCD_BAREBOX_SIZE,
-};
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index f334b17..a601c9d 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -496,6 +496,7 @@ config MACH_TX53
 
 config MACH_GUF_VINCELL
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	bool "Garz-Fricke Vincell"
 
 endchoice
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:05:33 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:05:33 +0200
Subject: [PATCH 7/8] ARM: i.MX51 karo-tx51: Switch to imximage
In-Reply-To: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
References: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372021534-25470-7-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/karo-tx51/Makefile            |  1 -
 arch/arm/boards/karo-tx51/flash-header.imxcfg | 13 +++++++
 arch/arm/boards/karo-tx51/flash_header.c      | 52 ---------------------------
 arch/arm/mach-imx/Kconfig                     |  1 +
 4 files changed, 14 insertions(+), 53 deletions(-)
 create mode 100644 arch/arm/boards/karo-tx51/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/karo-tx51/flash_header.c

diff --git a/arch/arm/boards/karo-tx51/Makefile b/arch/arm/boards/karo-tx51/Makefile
index 988abea..5afc8e2 100644
--- a/arch/arm/boards/karo-tx51/Makefile
+++ b/arch/arm/boards/karo-tx51/Makefile
@@ -1,3 +1,2 @@
 obj-y += tx51.o
-lwl-$(CONFIG_ARCH_IMX_INTERNAL_BOOT) += flash_header.o
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/karo-tx51/flash-header.imxcfg b/arch/arm/boards/karo-tx51/flash-header.imxcfg
new file mode 100644
index 0000000..ebb7c4f
--- /dev/null
+++ b/arch/arm/boards/karo-tx51/flash-header.imxcfg
@@ -0,0 +1,13 @@
+soc imx51
+loadaddr 0x90000000
+dcdofs 0x400
+wm 32 0x83fd9000 0x80000000
+wm 32 0x83fd9014 0x04008008
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x00338018
+wm 32 0x83fd9000 0xb2220000
+wm 32 0x83fd9004 0xb08564a9
+wm 32 0x83fd9034 0x20020000
+wm 32 0x83fd9010 0x000a0080
+wm 32 0x83fd9014 0x00000000
diff --git a/arch/arm/boards/karo-tx51/flash_header.c b/arch/arm/boards/karo-tx51/flash_header.c
deleted file mode 100644
index e949bd7..0000000
--- a/arch/arm/boards/karo-tx51/flash_header.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright (C) 2012 Christian Kapeller, <christian.kapeller at cmotion.eu>
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <asm/barebox-arm-head.h>
-#include <mach/imx-flash-header.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-struct imx_dcd_entry __dcd_entry_section dcd_entry[] = {
-    { .ptr_type = 4, .addr = 0x83fd9000, .val = 0x80000000, },
-    { .ptr_type = 4, .addr = 0x83fd9014, .val = 0x04008008, },
-    { .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008010, },
-    { .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008010, },
-    { .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00338018, },
-    { .ptr_type = 4, .addr = 0x83fd9000, .val = 0xb2220000, },
-    { .ptr_type = 4, .addr = 0x83fd9004, .val = 0xb08564a9, },
-    { .ptr_type = 4, .addr = 0x83fd9034, .val = 0x20020000, },
-    { .ptr_type = 4, .addr = 0x83fd9010, .val = 0x000a0080, },
-    { .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00000000, },
-};
-
-#define APP_DEST	0x90000000
-
-struct imx_flash_header __flash_header_section flash_header = {
-	.app_code_jump_vector	= APP_DEST + 0x1000,
-	.app_code_barker	= APP_CODE_BARKER,
-	.app_code_csf		= 0,
-	.dcd_ptr_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd),
-	.super_root_key		= 0,
-	.dcd			= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd_barker),
-	.app_dest		= APP_DEST,
-	.dcd_barker		= DCD_BARKER,
-	.dcd_block_len		= sizeof (dcd_entry),
-};
-
-unsigned long __image_len_section barebox_len = DCD_BAREBOX_SIZE;
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index bd7ee7f..f334b17 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -434,6 +434,7 @@ config MACH_EUKREA_CPUIMX51SD
 
 config MACH_TX51
 	bool "Ka-Ro TX51"
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	help
 	  Say Y here if you are using the Ka-Ro tx51 board
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:05:27 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:05:27 +0200
Subject: [PATCH 1/8] ARM: i.MX53 SMD: Switch to imximage
Message-ID: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx53-smd/Makefile        |   1 -
 .../boards/freescale-mx53-smd/flash-header.imxcfg  |  54 +++++++++++
 arch/arm/boards/freescale-mx53-smd/flash_header.c  | 102 ---------------------
 arch/arm/mach-imx/Kconfig                          |   1 +
 4 files changed, 55 insertions(+), 103 deletions(-)
 create mode 100644 arch/arm/boards/freescale-mx53-smd/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/freescale-mx53-smd/flash_header.c

diff --git a/arch/arm/boards/freescale-mx53-smd/Makefile b/arch/arm/boards/freescale-mx53-smd/Makefile
index d44f697..01c7a25 100644
--- a/arch/arm/boards/freescale-mx53-smd/Makefile
+++ b/arch/arm/boards/freescale-mx53-smd/Makefile
@@ -1,3 +1,2 @@
 obj-y += board.o
-lwl-y += flash_header.o
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/freescale-mx53-smd/flash-header.imxcfg b/arch/arm/boards/freescale-mx53-smd/flash-header.imxcfg
new file mode 100644
index 0000000..95bcd19
--- /dev/null
+++ b/arch/arm/boards/freescale-mx53-smd/flash-header.imxcfg
@@ -0,0 +1,54 @@
+loadaddr 0x70000000
+soc imx53
+dcdofs 0x400
+wm 32 0x53fa8554 0x00300000
+wm 32 0x53fa8558 0x00300040
+wm 32 0x53fa8560 0x00300000
+wm 32 0x53fa8564 0x00300040
+wm 32 0x53fa8568 0x00300040
+wm 32 0x53fa8570 0x00300000
+wm 32 0x53fa8574 0x00300000
+wm 32 0x53fa8578 0x00300000
+wm 32 0x53fa857c 0x00300040
+wm 32 0x53fa8580 0x00300040
+wm 32 0x53fa8584 0x00300000
+wm 32 0x53fa8588 0x00300000
+wm 32 0x53fa8590 0x00300040
+wm 32 0x53fa8594 0x00300000
+wm 32 0x53fa86f0 0x00300000
+wm 32 0x53fa86f4 0x00000000
+wm 32 0x53fa86fc 0x00000000
+wm 32 0x53fa8714 0x00000000
+wm 32 0x53fa8718 0x00300000
+wm 32 0x53fa871c 0x00300000
+wm 32 0x53fa8720 0x00300000
+wm 32 0x53fa8724 0x04000000
+wm 32 0x53fa8728 0x00300000
+wm 32 0x53fa872c 0x00300000
+wm 32 0x63fd9088 0x35343535
+wm 32 0x63fd9090 0x4d444c44
+wm 32 0x63fd907c 0x01370138
+wm 32 0x63fd9080 0x013b013c
+wm 32 0x63fd9018 0x00011740
+wm 32 0x63fd9000 0xc3190000
+wm 32 0x63fd900c 0x9f5152e3
+wm 32 0x63fd9010 0xb68e8a63
+wm 32 0x63fd9014 0x01ff00db
+wm 32 0x63fd902c 0x000026d2
+wm 32 0x63fd9030 0x009f0e21
+wm 32 0x63fd9008 0x12273030
+wm 32 0x63fd9004 0x0002002d
+wm 32 0x63fd901c 0x00008032
+wm 32 0x63fd901c 0x00008033
+wm 32 0x63fd901c 0x00028031
+wm 32 0x63fd901c 0x052080b0
+wm 32 0x63fd901c 0x04008040
+wm 32 0x63fd901c 0x0000803a
+wm 32 0x63fd901c 0x0000803b
+wm 32 0x63fd901c 0x00028039
+wm 32 0x63fd901c 0x05208138
+wm 32 0x63fd901c 0x04008048
+wm 32 0x63fd9020 0x00005800
+wm 32 0x63fd9040 0x04b80003
+wm 32 0x63fd9058 0x00022227
+wm 32 0x63fd901c 0x00000000
diff --git a/arch/arm/boards/freescale-mx53-smd/flash_header.c b/arch/arm/boards/freescale-mx53-smd/flash_header.c
deleted file mode 100644
index c2ab255..0000000
--- a/arch/arm/boards/freescale-mx53-smd/flash_header.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2011 Marc Kleine-Budde <mkl at pengutronix.de>
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <asm/byteorder.h>
-#include <mach/imx-flash-header.h>
-#include <asm/barebox-arm-head.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-struct imx_dcd_v2_entry __dcd_entry_section dcd_entry[] = {
-	{ .addr = cpu_to_be32(0x53fa8554), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8558), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8560), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8564), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8568), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8570), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8574), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8578), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa857c), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8580), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8584), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8588), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8590), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8594), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa86f0), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa86f4), .val = cpu_to_be32(0x00000000), },
-	{ .addr = cpu_to_be32(0x53fa86fc), .val = cpu_to_be32(0x00000000), },
-	{ .addr = cpu_to_be32(0x53fa8714), .val = cpu_to_be32(0x00000000), },
-	{ .addr = cpu_to_be32(0x53fa8718), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa871c), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8720), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8724), .val = cpu_to_be32(0x04000000), },
-	{ .addr = cpu_to_be32(0x53fa8728), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa872c), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x63fd9088), .val = cpu_to_be32(0x35343535), },
-	{ .addr = cpu_to_be32(0x63fd9090), .val = cpu_to_be32(0x4d444c44), },
-	{ .addr = cpu_to_be32(0x63fd907c), .val = cpu_to_be32(0x01370138), },
-	{ .addr = cpu_to_be32(0x63fd9080), .val = cpu_to_be32(0x013b013c), },
-	{ .addr = cpu_to_be32(0x63fd9018), .val = cpu_to_be32(0x00011740), },
-	{ .addr = cpu_to_be32(0x63fd9000), .val = cpu_to_be32(0xc3190000), },
-	{ .addr = cpu_to_be32(0x63fd900c), .val = cpu_to_be32(0x9f5152e3), },
-	{ .addr = cpu_to_be32(0x63fd9010), .val = cpu_to_be32(0xb68e8a63), },
-	{ .addr = cpu_to_be32(0x63fd9014), .val = cpu_to_be32(0x01ff00db), },
-	{ .addr = cpu_to_be32(0x63fd902c), .val = cpu_to_be32(0x000026d2), },
-	{ .addr = cpu_to_be32(0x63fd9030), .val = cpu_to_be32(0x009f0e21), },
-	{ .addr = cpu_to_be32(0x63fd9008), .val = cpu_to_be32(0x12273030), },
-	{ .addr = cpu_to_be32(0x63fd9004), .val = cpu_to_be32(0x0002002d), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00008032), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00008033), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00028031), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x052080b0), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x04008040), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x0000803a), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x0000803b), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00028039), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x05208138), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x04008048), },
-	{ .addr = cpu_to_be32(0x63fd9020), .val = cpu_to_be32(0x00005800), },
-	{ .addr = cpu_to_be32(0x63fd9040), .val = cpu_to_be32(0x04b80003), },
-	{ .addr = cpu_to_be32(0x63fd9058), .val = cpu_to_be32(0x00022227), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00000000), },
-};
-
-#define APP_DEST	0x70000000
-
-struct imx_flash_header_v2 __flash_header_section flash_header = {
-	.header.tag		= IVT_HEADER_TAG,
-	.header.length		= cpu_to_be16(32),
-	.header.version		= IVT_VERSION,
-
-	.entry			= APP_DEST + 0x1000,
-	.dcd_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header_v2, dcd),
-	.boot_data_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header_v2, boot_data),
-	.self			= APP_DEST + 0x400,
-
-	.boot_data.start	= APP_DEST,
-	.boot_data.size		= DCD_BAREBOX_SIZE,
-
-	.dcd.header.tag		= DCD_HEADER_TAG,
-	.dcd.header.length	= cpu_to_be16(sizeof(struct imx_dcd) + sizeof(dcd_entry)),
-	.dcd.header.version	= DCD_VERSION,
-
-	.dcd.command.tag	= DCD_COMMAND_WRITE_TAG,
-	.dcd.command.length	= cpu_to_be16(sizeof(struct imx_dcd_command) + sizeof(dcd_entry)),
-	.dcd.command.param	= DCD_COMMAND_WRITE_PARAM,
-};
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index b13fa99..b7282bb 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -477,6 +477,7 @@ config MACH_FREESCALE_MX53_LOCO
 	bool "Freescale i.MX53 LOCO"
 
 config MACH_FREESCALE_MX53_SMD
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	bool "Freescale i.MX53 SMD"
 
 config MACH_TQMA53
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:05:32 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:05:32 +0200
Subject: [PATCH 6/8] ARM: i.MX51 ccxmx51: Switch to imximage
In-Reply-To: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
References: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372021534-25470-6-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/ccxmx51/Makefile            |  1 -
 arch/arm/boards/ccxmx51/flash-header.imxcfg | 60 +++++++++++++++++++++
 arch/arm/boards/ccxmx51/flash_header.c      | 84 -----------------------------
 arch/arm/mach-imx/Kconfig                   |  1 +
 4 files changed, 61 insertions(+), 85 deletions(-)
 create mode 100644 arch/arm/boards/ccxmx51/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/ccxmx51/flash_header.c

diff --git a/arch/arm/boards/ccxmx51/Makefile b/arch/arm/boards/ccxmx51/Makefile
index 422c919..6ba98b1 100644
--- a/arch/arm/boards/ccxmx51/Makefile
+++ b/arch/arm/boards/ccxmx51/Makefile
@@ -1,4 +1,3 @@
 obj-y					+= ccxmx51.o
-lwl-y				+= flash_header.o
 lwl-y				+= lowlevel.o
 obj-$(CONFIG_MACH_CCMX51_BASEBOARD)	+= ccxmx51js.o
diff --git a/arch/arm/boards/ccxmx51/flash-header.imxcfg b/arch/arm/boards/ccxmx51/flash-header.imxcfg
new file mode 100644
index 0000000..251c4c1
--- /dev/null
+++ b/arch/arm/boards/ccxmx51/flash-header.imxcfg
@@ -0,0 +1,60 @@
+soc imx51
+loadaddr 0x90000000
+dcdofs 0x400
+wm 32 0x73fa88a0 0x00000200
+wm 32 0x73fa850c 0x000020c5
+wm 32 0x73fa8510 0x000020c5
+wm 32 0x73fa883c 0x00000002
+wm 32 0x73fa8848 0x00000002
+wm 32 0x73fa84b8 0x000000e7
+wm 32 0x73fa84bc 0x00000045
+wm 32 0x73fa84c0 0x00000045
+wm 32 0x73fa84c4 0x00000045
+wm 32 0x73fa84c8 0x00000045
+wm 32 0x73fa8820 0x00000000
+wm 32 0x73fa84a4 0x00000003
+wm 32 0x73fa84a8 0x00000003
+wm 32 0x73fa84ac 0x000000e3
+wm 32 0x73fa84b0 0x000000e3
+wm 32 0x73fa84b4 0x000000e3
+wm 32 0x73fa84cc 0x000000e3
+wm 32 0x73fa84d0 0x000000e2
+wm 32 0x73fa882c 0x00000004
+wm 32 0x73fa88a4 0x00000004
+wm 32 0x73fa88ac 0x00000004
+wm 32 0x73fa88b8 0x00000004
+wm 32 0x83fd9000 0x82a20000
+wm 32 0x83fd9008 0x82a20000
+wm 32 0x83fd9010 0x000ad0d0
+wm 32 0x83fd9004 0x3f3584ab
+wm 32 0x83fd900c 0x3f3584ab
+wm 32 0x83fd9014 0x04008008
+wm 32 0x83fd9014 0x0000801a
+wm 32 0x83fd9014 0x0000801b
+wm 32 0x83fd9014 0x00448019
+wm 32 0x83fd9014 0x07328018
+wm 32 0x83fd9014 0x04008008
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x06328018
+wm 32 0x83fd9014 0x03808019
+wm 32 0x83fd9014 0x00408019
+wm 32 0x83fd9014 0x00008000
+wm 32 0x83fd9014 0x0400800c
+wm 32 0x83fd9014 0x0000801e
+wm 32 0x83fd9014 0x0000801f
+wm 32 0x83fd9014 0x0000801d
+wm 32 0x83fd9014 0x0732801c
+wm 32 0x83fd9014 0x0400800c
+wm 32 0x83fd9014 0x00008014
+wm 32 0x83fd9014 0x00008014
+wm 32 0x83fd9014 0x0632801c
+wm 32 0x83fd9014 0x0380801d
+wm 32 0x83fd9014 0x0040801d
+wm 32 0x83fd9014 0x00008004
+wm 32 0x83fd9000 0xb2a20000
+wm 32 0x83fd9008 0xb2a20000
+wm 32 0x83fd9010 0x000ad6d0
+wm 32 0x83fd9034 0x90000000
+wm 32 0x83fd9014 0x00000000
+
diff --git a/arch/arm/boards/ccxmx51/flash_header.c b/arch/arm/boards/ccxmx51/flash_header.c
deleted file mode 100644
index c148eea..0000000
--- a/arch/arm/boards/ccxmx51/flash_header.c
+++ /dev/null
@@ -1,84 +0,0 @@
-#include <common.h>
-#include <mach/imx-flash-header.h>
-#include <asm/barebox-arm-head.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-struct imx_dcd_entry __dcd_entry_section dcd_entry[] = {
-	{ .ptr_type = 4, .addr = 0x73fa88a0, .val = 0x00000200, },
-	{ .ptr_type = 4, .addr = 0x73fa850c, .val = 0x000020c5, },
-	{ .ptr_type = 4, .addr = 0x73fa8510, .val = 0x000020c5, },
-	{ .ptr_type = 4, .addr = 0x73fa883c, .val = 0x00000002, },
-	{ .ptr_type = 4, .addr = 0x73fa8848, .val = 0x00000002, },
-	{ .ptr_type = 4, .addr = 0x73fa84b8, .val = 0x000000e7, },
-	{ .ptr_type = 4, .addr = 0x73fa84bc, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa84c0, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa84c4, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa84c8, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa8820, .val = 0x00000000, },
-	{ .ptr_type = 4, .addr = 0x73fa84a4, .val = 0x00000003, },
-	{ .ptr_type = 4, .addr = 0x73fa84a8, .val = 0x00000003, },
-	{ .ptr_type = 4, .addr = 0x73fa84ac, .val = 0x000000e3, },
-	{ .ptr_type = 4, .addr = 0x73fa84b0, .val = 0x000000e3, },
-	{ .ptr_type = 4, .addr = 0x73fa84b4, .val = 0x000000e3, },
-	{ .ptr_type = 4, .addr = 0x73fa84cc, .val = 0x000000e3, },
-	{ .ptr_type = 4, .addr = 0x73fa84d0, .val = 0x000000e2, },
-	{ .ptr_type = 4, .addr = 0x73fa882c, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x73fa88a4, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x73fa88ac, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x73fa88b8, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x83fd9000, .val = 0x82a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9008, .val = 0x82a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9010, .val = 0x000ad0d0, },
-	{ .ptr_type = 4, .addr = 0x83fd9004, .val = 0x3f3584ab, },
-	{ .ptr_type = 4, .addr = 0x83fd900c, .val = 0x3f3584ab, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x04008008, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801a, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801b, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00448019, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x07328018, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x04008008, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008010, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008010, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x06328018, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x03808019, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00408019, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008000, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0400800c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801e, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801f, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801d, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0732801c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0400800c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008014, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008014, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0632801c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0380801d, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0040801d, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008004, },
-	{ .ptr_type = 4, .addr = 0x83fd9000, .val = 0xb2a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9008, .val = 0xb2a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9010, .val = 0x000ad6d0, },
-	{ .ptr_type = 4, .addr = 0x83fd9034, .val = 0x90000000, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00000000, },
-};
-
-#define APP_DEST	0x90000000
-
-struct imx_flash_header __flash_header_section flash_header = {
-	.app_code_jump_vector	= APP_DEST + 0x1000,
-	.app_code_barker	= APP_CODE_BARKER,
-	.app_code_csf		= 0,
-	.dcd_ptr_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd),
-	.super_root_key		= 0,
-	.dcd			= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd_barker),
-	.app_dest		= APP_DEST,
-	.dcd_barker		= DCD_BARKER,
-	.dcd_block_len		= sizeof (dcd_entry),
-};
-
-unsigned long __image_len_section barebox_len = DCD_BAREBOX_SIZE;
-
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index a6364c7..bd7ee7f 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -443,6 +443,7 @@ config MACH_CCMX51
 	select SPI
 	select DRIVER_SPI_IMX
 	select MFD_MC13XXX
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	help
 	  Say Y here if you are using Digi ConnectCore (W)i-i.MX51
 	  equipped with a Freescale i.MX51 Processor
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:05:31 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:05:31 +0200
Subject: [PATCH 5/8] ARM: i.MX51 Efika SB: Switch to imximage
In-Reply-To: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
References: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372021534-25470-5-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/efika-mx-smartbook/Makefile        |  4 +-
 arch/arm/boards/efika-mx-smartbook/board.c         |  8 ++-
 arch/arm/boards/efika-mx-smartbook/dcd-data.h      | 56 ---------------------
 .../boards/efika-mx-smartbook/flash-header.imxcfg  | 57 ++++++++++++++++++++++
 arch/arm/boards/efika-mx-smartbook/flash_header.c  | 29 -----------
 arch/arm/mach-imx/Kconfig                          |  1 +
 6 files changed, 63 insertions(+), 92 deletions(-)
 delete mode 100644 arch/arm/boards/efika-mx-smartbook/dcd-data.h
 create mode 100644 arch/arm/boards/efika-mx-smartbook/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/efika-mx-smartbook/flash_header.c

diff --git a/arch/arm/boards/efika-mx-smartbook/Makefile b/arch/arm/boards/efika-mx-smartbook/Makefile
index a2c3104..c21540b 100644
--- a/arch/arm/boards/efika-mx-smartbook/Makefile
+++ b/arch/arm/boards/efika-mx-smartbook/Makefile
@@ -1,3 +1,3 @@
-obj-y += board.o
+obj-y += board.o flash-header.o
 lwl-y += lowlevel.o
-lwl-y += flash_header.o
+extra-y += flash-header.S flash-header.dcd
diff --git a/arch/arm/boards/efika-mx-smartbook/board.c b/arch/arm/boards/efika-mx-smartbook/board.c
index e9b6062..f4f60d4 100644
--- a/arch/arm/boards/efika-mx-smartbook/board.c
+++ b/arch/arm/boards/efika-mx-smartbook/board.c
@@ -424,9 +424,7 @@ static struct gpio_led leds[] = {
 	},
 };
 
-#define DCD_NAME static struct imx_dcd_entry dcd_entry
-
-#include "dcd-data.h"
+extern char flash_header_start[], flash_header_end[];
 
 static int efikamx_devices_init(void)
 {
@@ -467,8 +465,8 @@ static int efikamx_devices_init(void)
 	writew(0x0, MX51_WDOG_BASE_ADDR + 0x8);
 
 	imx51_bbu_internal_mmc_register_handler("mmc", "/dev/mmc_left",
-			BBU_HANDLER_FLAG_DEFAULT, dcd_entry, sizeof(dcd_entry),
-			0);
+			BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_start,
+			flash_header_end - flash_header_start, 0);
 
 	armlinux_set_bootparams((void *)0x90000100);
 	armlinux_set_architecture(2370);
diff --git a/arch/arm/boards/efika-mx-smartbook/dcd-data.h b/arch/arm/boards/efika-mx-smartbook/dcd-data.h
deleted file mode 100644
index 6795e19..0000000
--- a/arch/arm/boards/efika-mx-smartbook/dcd-data.h
+++ /dev/null
@@ -1,56 +0,0 @@
-DCD_NAME[] = {
-	{ .ptr_type = 4, .addr = 0x73fa88a0, .val = 0x00000000, },
-	{ .ptr_type = 4, .addr = 0x73fa850c, .val = 0x000020c5, },
-	{ .ptr_type = 4, .addr = 0x73fa8510, .val = 0x000020c5, },
-	{ .ptr_type = 4, .addr = 0x73fa883c, .val = 0x00000005, },
-	{ .ptr_type = 4, .addr = 0x73fa8848, .val = 0x00000005, },
-	{ .ptr_type = 4, .addr = 0x73fa84b8, .val = 0x000000e7, },
-	{ .ptr_type = 4, .addr = 0x73fa84bc, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa84c0, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa84c4, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa84c8, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa8820, .val = 0x00000000, },
-	{ .ptr_type = 4, .addr = 0x73fa84a4, .val = 0x00000005, },
-	{ .ptr_type = 4, .addr = 0x73fa84a8, .val = 0x00000005, },
-	{ .ptr_type = 4, .addr = 0x73fa84ac, .val = 0x000000e5, },
-	{ .ptr_type = 4, .addr = 0x73fa84b0, .val = 0x000000e5, },
-	{ .ptr_type = 4, .addr = 0x73fa84b4, .val = 0x000000e5, },
-	{ .ptr_type = 4, .addr = 0x73fa84cc, .val = 0x000000e5, },
-	{ .ptr_type = 4, .addr = 0x73fa84d0, .val = 0x000000e4, },
-	{ .ptr_type = 4, .addr = 0x73fa882c, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x73fa88a4, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x73fa88ac, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x73fa88b8, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x83fd9000, .val = 0x82a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9008, .val = 0x82a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9010, .val = 0xcaaaf6d0, },
-	{ .ptr_type = 4, .addr = 0x83fd9004, .val = 0x333574aa, },
-	{ .ptr_type = 4, .addr = 0x83fd900c, .val = 0x333574aa, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x04008008, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801a, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801b, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00448019, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x07328018, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x04008008, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008010, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008010, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x06328018, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x03808019, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008000, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0400800c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801e, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801f, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801d, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0732801c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0400800c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008014, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008014, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0632801c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0380801d, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008004, },
-	{ .ptr_type = 4, .addr = 0x83fd9000, .val = 0xb2a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9008, .val = 0xb2a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9010, .val = 0x000ad6d0, },
-	{ .ptr_type = 4, .addr = 0x83fd9034, .val = 0x90000000, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00000000, },
-};
diff --git a/arch/arm/boards/efika-mx-smartbook/flash-header.imxcfg b/arch/arm/boards/efika-mx-smartbook/flash-header.imxcfg
new file mode 100644
index 0000000..53875ed
--- /dev/null
+++ b/arch/arm/boards/efika-mx-smartbook/flash-header.imxcfg
@@ -0,0 +1,57 @@
+soc imx51
+loadaddr 0x90000000
+dcdofs 0x400
+wm 32 0x73fa88a0 0x00000000
+wm 32 0x73fa850c 0x000020c5
+wm 32 0x73fa8510 0x000020c5
+wm 32 0x73fa883c 0x00000005
+wm 32 0x73fa8848 0x00000005
+wm 32 0x73fa84b8 0x000000e7
+wm 32 0x73fa84bc 0x00000045
+wm 32 0x73fa84c0 0x00000045
+wm 32 0x73fa84c4 0x00000045
+wm 32 0x73fa84c8 0x00000045
+wm 32 0x73fa8820 0x00000000
+wm 32 0x73fa84a4 0x00000005
+wm 32 0x73fa84a8 0x00000005
+wm 32 0x73fa84ac 0x000000e5
+wm 32 0x73fa84b0 0x000000e5
+wm 32 0x73fa84b4 0x000000e5
+wm 32 0x73fa84cc 0x000000e5
+wm 32 0x73fa84d0 0x000000e4
+wm 32 0x73fa882c 0x00000004
+wm 32 0x73fa88a4 0x00000004
+wm 32 0x73fa88ac 0x00000004
+wm 32 0x73fa88b8 0x00000004
+wm 32 0x83fd9000 0x82a20000
+wm 32 0x83fd9008 0x82a20000
+wm 32 0x83fd9010 0xcaaaf6d0
+wm 32 0x83fd9004 0x333574aa
+wm 32 0x83fd900c 0x333574aa
+wm 32 0x83fd9014 0x04008008
+wm 32 0x83fd9014 0x0000801a
+wm 32 0x83fd9014 0x0000801b
+wm 32 0x83fd9014 0x00448019
+wm 32 0x83fd9014 0x07328018
+wm 32 0x83fd9014 0x04008008
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x06328018
+wm 32 0x83fd9014 0x03808019
+wm 32 0x83fd9014 0x00008000
+wm 32 0x83fd9014 0x0400800c
+wm 32 0x83fd9014 0x0000801e
+wm 32 0x83fd9014 0x0000801f
+wm 32 0x83fd9014 0x0000801d
+wm 32 0x83fd9014 0x0732801c
+wm 32 0x83fd9014 0x0400800c
+wm 32 0x83fd9014 0x00008014
+wm 32 0x83fd9014 0x00008014
+wm 32 0x83fd9014 0x0632801c
+wm 32 0x83fd9014 0x0380801d
+wm 32 0x83fd9014 0x00008004
+wm 32 0x83fd9000 0xb2a20000
+wm 32 0x83fd9008 0xb2a20000
+wm 32 0x83fd9010 0x000ad6d0
+wm 32 0x83fd9034 0x90000000
+wm 32 0x83fd9014 0x00000000
diff --git a/arch/arm/boards/efika-mx-smartbook/flash_header.c b/arch/arm/boards/efika-mx-smartbook/flash_header.c
deleted file mode 100644
index f3f1e4b..0000000
--- a/arch/arm/boards/efika-mx-smartbook/flash_header.c
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <common.h>
-#include <mach/imx-flash-header.h>
-#include <asm/barebox-arm-head.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-#define DCD_NAME struct imx_dcd_entry __dcd_entry_section dcd_entry
-
-#include "dcd-data.h"
-
-#define APP_DEST	0x90000000
-
-struct imx_flash_header __flash_header_section flash_header = {
-	.app_code_jump_vector	= APP_DEST + 0x1000,
-	.app_code_barker	= APP_CODE_BARKER,
-	.app_code_csf		= 0,
-	.dcd_ptr_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd),
-	.super_root_key		= 0,
-	.dcd			= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd_barker),
-	.app_dest		= APP_DEST,
-	.dcd_barker		= DCD_BARKER,
-	.dcd_block_len		= sizeof (dcd_entry),
-};
-
-unsigned long __image_len_section barebox_len = DCD_BAREBOX_SIZE;
-
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index c2d6348..a6364c7 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -457,6 +457,7 @@ config MACH_CCMX51_BASEBOARD
 
 config MACH_EFIKA_MX_SMARTBOOK
 	bool "Efika MX smartbook"
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	help
 	  Choose this to compile barebox for the Efika MX Smartbook
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:05:30 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:05:30 +0200
Subject: [PATCH 4/8] ARM: i.MX6 sabresd: Switch to imximage
In-Reply-To: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
References: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372021534-25470-4-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx6-sabresd/Makefile     |   1 -
 .../freescale-mx6-sabresd/flash-header.imxcfg      | 128 +++++++++++++++
 .../boards/freescale-mx6-sabresd/flash_header.c    | 178 ---------------------
 arch/arm/mach-imx/Kconfig                          |   1 +
 4 files changed, 129 insertions(+), 179 deletions(-)
 create mode 100644 arch/arm/boards/freescale-mx6-sabresd/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/freescale-mx6-sabresd/flash_header.c

diff --git a/arch/arm/boards/freescale-mx6-sabresd/Makefile b/arch/arm/boards/freescale-mx6-sabresd/Makefile
index d44f697..01c7a25 100644
--- a/arch/arm/boards/freescale-mx6-sabresd/Makefile
+++ b/arch/arm/boards/freescale-mx6-sabresd/Makefile
@@ -1,3 +1,2 @@
 obj-y += board.o
-lwl-y += flash_header.o
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/freescale-mx6-sabresd/flash-header.imxcfg b/arch/arm/boards/freescale-mx6-sabresd/flash-header.imxcfg
new file mode 100644
index 0000000..21f217c
--- /dev/null
+++ b/arch/arm/boards/freescale-mx6-sabresd/flash-header.imxcfg
@@ -0,0 +1,128 @@
+loadaddr 0x10000000
+soc imx6
+dcdofs 0x400
+wm 32 0x20e05a8 0x00000030
+wm 32 0x20e05b0 0x00000030
+wm 32 0x20e0524 0x00000030
+wm 32 0x20e051c 0x00000030
+
+wm 32 0x20e0518 0x00000030
+wm 32 0x20e050c 0x00000030
+wm 32 0x20e05b8 0x00000030
+wm 32 0x20e05c0 0x00000030
+
+wm 32 0x20e05ac 0x00020030
+wm 32 0x20e05b4 0x00020030
+wm 32 0x20e0528 0x00020030
+wm 32 0x20e0520 0x00020030
+
+wm 32 0x20e0514 0x00020030
+wm 32 0x20e0510 0x00020030
+wm 32 0x20e05bc 0x00020030
+wm 32 0x20e05c4 0x00020030
+
+wm 32 0x20e056c 0x00020030
+wm 32 0x20e0578 0x00020030
+wm 32 0x20e0588 0x00020030
+wm 32 0x20e0594 0x00020030
+
+wm 32 0x20e057c 0x00020030
+wm 32 0x20e0590 0x00003000
+wm 32 0x20e0598 0x00003000
+wm 32 0x20e058c 0x00000000
+
+wm 32 0x20e059c 0x00003030
+wm 32 0x20e05a0 0x00003030
+wm 32 0x20e0784 0x00000030
+wm 32 0x20e0788 0x00000030
+
+wm 32 0x20e0794 0x00000030
+wm 32 0x20e079c 0x00000030
+wm 32 0x20e07a0 0x00000030
+wm 32 0x20e07a4 0x00000030
+
+wm 32 0x20e07a8 0x00000030
+wm 32 0x20e0748 0x00000030
+wm 32 0x20e074c 0x00000030
+wm 32 0x20e0750 0x00020000
+
+wm 32 0x20e0758 0x00000000
+wm 32 0x20e0774 0x00020000
+wm 32 0x20e078c 0x00000030
+wm 32 0x20e0798 0x000C0000
+
+wm 32 0x21b081c 0x33333333
+wm 32 0x21b0820 0x33333333
+wm 32 0x21b0824 0x33333333
+wm 32 0x21b0828 0x33333333
+
+wm 32 0x21b481c 0x33333333
+wm 32 0x21b4820 0x33333333
+wm 32 0x21b4824 0x33333333
+wm 32 0x21b4828 0x33333333
+
+wm 32 0x21b0018 0x00081740
+
+wm 32 0x21b001c 0x00008000
+wm 32 0x21b000c 0x555A7975
+wm 32 0x21b0010 0xFF538E64
+wm 32 0x21b0014 0x01FF00DB
+wm 32 0x21b002c 0x000026D2
+
+wm 32 0x21b0030 0x005B0E21
+wm 32 0x21b0008 0x09444040
+wm 32 0x21b0004 0x00025576
+wm 32 0x21b0040 0x00000027
+wm 32 0x21b0000 0x831A0000
+
+wm 32 0x21b001c 0x04088032
+wm 32 0x21b001c 0x0408803A
+wm 32 0x21b001c 0x00008033
+wm 32 0x21b001c 0x0000803B
+wm 32 0x21b001c 0x00428031
+wm 32 0x21b001c 0x00428039
+wm 32 0x21b001c 0x09408030
+wm 32 0x21b001c 0x09408038
+
+wm 32 0x21b001c 0x04008040
+wm 32 0x21b001c 0x04008048
+wm 32 0x21b0800 0xA1380003
+wm 32 0x21b4800 0xA1380003
+wm 32 0x21b0020 0x00005800
+wm 32 0x21b0818 0x00022227
+wm 32 0x21b4818 0x00022227
+
+wm 32 0x21b083c 0x434B0350
+wm 32 0x21b0840 0x034C0359
+wm 32 0x21b483c 0x434B0350
+wm 32 0x21b4840 0x03650348
+wm 32 0x21b0848 0x4436383B
+wm 32 0x21b4848 0x39393341
+wm 32 0x21b0850 0x35373933
+wm 32 0x21b4850 0x48254A36
+
+wm 32 0x21b080c 0x001F001F
+wm 32 0x21b0810 0x001F001F
+
+wm 32 0x21b480c 0x00440044
+wm 32 0x21b4810 0x00440044
+
+wm 32 0x21b08b8 0x00000800
+wm 32 0x21b48b8 0x00000800
+
+wm 32 0x21b001c 0x00000000
+wm 32 0x21b0404 0x00011006
+
+wm 32 0x020c4068 0x00c03f3f
+wm 32 0x020c406c 0x0030fc03
+wm 32 0x020c4070 0x0fffc000
+wm 32 0x020c4074 0x3ff00000
+wm 32 0x020c4078 0x00fff300
+wm 32 0x020c407c 0x0f0000c3
+wm 32 0x020c4080 0x000003ff
+
+# enable AXI cache for VDOA/VPU/IPU
+wm 32 0x20e0010 0xf00000cf
+# set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7
+wm 32 0x20e0018 0x007f007f
+wm 32 0x20e001c 0x007f007f
diff --git a/arch/arm/boards/freescale-mx6-sabresd/flash_header.c b/arch/arm/boards/freescale-mx6-sabresd/flash_header.c
deleted file mode 100644
index 61d482b..0000000
--- a/arch/arm/boards/freescale-mx6-sabresd/flash_header.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 2011 Marc Kleine-Budde <mkl at pengutronix.de>
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <asm/byteorder.h>
-#include <mach/imx-flash-header.h>
-#include <mach/imx6-regs.h>
-#include <asm/barebox-arm-head.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-#define DCD(a, v) { .addr = cpu_to_be32(a), .val = cpu_to_be32(v), }
-
-struct imx_dcd_v2_entry __dcd_entry_section dcd_entry[] = {
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5a8, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5b0, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x524, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x51c, 0x00000030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x518, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x50c, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5b8, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5c0, 0x00000030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5ac, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5b4, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x528, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x520, 0x00020030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x514, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x510, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5bc, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5c4, 0x00020030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x56c, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x578, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x588, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x594, 0x00020030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x57c, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x590, 0x00003000),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x598, 0x00003000),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x58c, 0x00000000),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x59c, 0x00003030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5a0, 0x00003030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x784, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x788, 0x00000030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x794, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x79c, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x7a0, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x7a4, 0x00000030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x7a8, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x748, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x74c, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x750, 0x00020000),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x758, 0x00000000),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x774, 0x00020000),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x78c, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x798, 0x000C0000),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x81c, 0x33333333),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x820, 0x33333333),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x824, 0x33333333),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x828, 0x33333333),
-
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x81c, 0x33333333),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x820, 0x33333333),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x824, 0x33333333),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x828, 0x33333333),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x018, 0x00081740),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00008000),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x00c, 0x555A7975),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x010, 0xFF538E64),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x014, 0x01FF00DB),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x02c, 0x000026D2),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x030, 0x005B0E21),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x008, 0x09444040),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x004, 0x00025576),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x040, 0x00000027),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x000, 0x831A0000),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x04088032),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x0408803A),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00008033),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x0000803B),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00428031),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00428039),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x09408030),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x09408038),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x04008040),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x04008048),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x800, 0xA1380003),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x800, 0xA1380003),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x020, 0x00005800),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x818, 0x00022227),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x818, 0x00022227),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x83c, 0x434B0350),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x840, 0x034C0359),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x83c, 0x434B0350),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x840, 0x03650348),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x848, 0x4436383B),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x848, 0x39393341),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x850, 0x35373933),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x850, 0x48254A36),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x80c, 0x001F001F),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x810, 0x001F001F),
-
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x80c, 0x00440044),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x810, 0x00440044),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x8b8, 0x00000800),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x8b8, 0x00000800),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00000000),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x404, 0x00011006),
-
-	DCD(MX6_CCM_BASE_ADDR + 0x068, 0x00c03f3f),
-	DCD(MX6_CCM_BASE_ADDR + 0x06c, 0x0030fc03),
-	DCD(MX6_CCM_BASE_ADDR + 0x070, 0x0fffc000),
-	DCD(MX6_CCM_BASE_ADDR + 0x074, 0x3ff00000),
-	DCD(MX6_CCM_BASE_ADDR + 0x078, 0x00fff300),
-	DCD(MX6_CCM_BASE_ADDR + 0x07c, 0x0f0000c3),
-	DCD(MX6_CCM_BASE_ADDR + 0x080, 0x000003ff),
-
-	/* enable AXI cache for VDOA/VPU/IPU */
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x010, 0xf00000cf),
-	/* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x018, 0x007f007f),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x01c, 0x007f007f),
-};
-
-#define APP_DEST	CONFIG_TEXT_BASE
-
-struct imx_flash_header_v2 __flash_header_section flash_header = {
-	.header.tag		= IVT_HEADER_TAG,
-	.header.length		= cpu_to_be16(32),
-	.header.version		= IVT_VERSION,
-	.entry			= (u32)_stext,
-	.dcd_ptr		= APP_DEST + FLASH_HEADER_OFFSET + offsetof(struct imx_flash_header_v2, dcd),
-	.boot_data_ptr		= APP_DEST + FLASH_HEADER_OFFSET + offsetof(struct imx_flash_header_v2, boot_data),
-	.self			= APP_DEST + FLASH_HEADER_OFFSET,
-
-	.boot_data.start	= APP_DEST,
-	.boot_data.size		= barebox_image_size,
-
-	.dcd.header.tag		= DCD_HEADER_TAG,
-	.dcd.header.length	= cpu_to_be16(sizeof(struct imx_dcd) + sizeof(dcd_entry)),
-	.dcd.header.version	= DCD_VERSION,
-
-	.dcd.command.tag	= DCD_COMMAND_WRITE_TAG,
-	.dcd.command.length	= cpu_to_be16(sizeof(struct imx_dcd_command) + sizeof(dcd_entry)),
-	.dcd.command.param	= DCD_COMMAND_WRITE_PARAM,
-};
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 11fd095..c2d6348 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -526,6 +526,7 @@ config MACH_SABRELITE
 	bool "Freescale i.MX6 Sabre Lite"
 
 config MACH_SABRESD
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	bool "Freescale i.MX6 SabreSD"
 
 config MACH_REALQ7
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:05:29 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:05:29 +0200
Subject: [PATCH 3/8] ARM: i.MX6 sabrelite: Switch to imximage
In-Reply-To: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
References: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372021534-25470-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx6-sabrelite/Makefile   |   1 -
 .../freescale-mx6-sabrelite/flash-header.imxcfg    | 128 +++++++++++++++
 .../boards/freescale-mx6-sabrelite/flash_header.c  | 178 ---------------------
 arch/arm/mach-imx/Kconfig                          |   1 +
 4 files changed, 129 insertions(+), 179 deletions(-)
 create mode 100644 arch/arm/boards/freescale-mx6-sabrelite/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/freescale-mx6-sabrelite/flash_header.c

diff --git a/arch/arm/boards/freescale-mx6-sabrelite/Makefile b/arch/arm/boards/freescale-mx6-sabrelite/Makefile
index d44f697..01c7a25 100644
--- a/arch/arm/boards/freescale-mx6-sabrelite/Makefile
+++ b/arch/arm/boards/freescale-mx6-sabrelite/Makefile
@@ -1,3 +1,2 @@
 obj-y += board.o
-lwl-y += flash_header.o
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/freescale-mx6-sabrelite/flash-header.imxcfg b/arch/arm/boards/freescale-mx6-sabrelite/flash-header.imxcfg
new file mode 100644
index 0000000..21f217c
--- /dev/null
+++ b/arch/arm/boards/freescale-mx6-sabrelite/flash-header.imxcfg
@@ -0,0 +1,128 @@
+loadaddr 0x10000000
+soc imx6
+dcdofs 0x400
+wm 32 0x20e05a8 0x00000030
+wm 32 0x20e05b0 0x00000030
+wm 32 0x20e0524 0x00000030
+wm 32 0x20e051c 0x00000030
+
+wm 32 0x20e0518 0x00000030
+wm 32 0x20e050c 0x00000030
+wm 32 0x20e05b8 0x00000030
+wm 32 0x20e05c0 0x00000030
+
+wm 32 0x20e05ac 0x00020030
+wm 32 0x20e05b4 0x00020030
+wm 32 0x20e0528 0x00020030
+wm 32 0x20e0520 0x00020030
+
+wm 32 0x20e0514 0x00020030
+wm 32 0x20e0510 0x00020030
+wm 32 0x20e05bc 0x00020030
+wm 32 0x20e05c4 0x00020030
+
+wm 32 0x20e056c 0x00020030
+wm 32 0x20e0578 0x00020030
+wm 32 0x20e0588 0x00020030
+wm 32 0x20e0594 0x00020030
+
+wm 32 0x20e057c 0x00020030
+wm 32 0x20e0590 0x00003000
+wm 32 0x20e0598 0x00003000
+wm 32 0x20e058c 0x00000000
+
+wm 32 0x20e059c 0x00003030
+wm 32 0x20e05a0 0x00003030
+wm 32 0x20e0784 0x00000030
+wm 32 0x20e0788 0x00000030
+
+wm 32 0x20e0794 0x00000030
+wm 32 0x20e079c 0x00000030
+wm 32 0x20e07a0 0x00000030
+wm 32 0x20e07a4 0x00000030
+
+wm 32 0x20e07a8 0x00000030
+wm 32 0x20e0748 0x00000030
+wm 32 0x20e074c 0x00000030
+wm 32 0x20e0750 0x00020000
+
+wm 32 0x20e0758 0x00000000
+wm 32 0x20e0774 0x00020000
+wm 32 0x20e078c 0x00000030
+wm 32 0x20e0798 0x000C0000
+
+wm 32 0x21b081c 0x33333333
+wm 32 0x21b0820 0x33333333
+wm 32 0x21b0824 0x33333333
+wm 32 0x21b0828 0x33333333
+
+wm 32 0x21b481c 0x33333333
+wm 32 0x21b4820 0x33333333
+wm 32 0x21b4824 0x33333333
+wm 32 0x21b4828 0x33333333
+
+wm 32 0x21b0018 0x00081740
+
+wm 32 0x21b001c 0x00008000
+wm 32 0x21b000c 0x555A7975
+wm 32 0x21b0010 0xFF538E64
+wm 32 0x21b0014 0x01FF00DB
+wm 32 0x21b002c 0x000026D2
+
+wm 32 0x21b0030 0x005B0E21
+wm 32 0x21b0008 0x09444040
+wm 32 0x21b0004 0x00025576
+wm 32 0x21b0040 0x00000027
+wm 32 0x21b0000 0x831A0000
+
+wm 32 0x21b001c 0x04088032
+wm 32 0x21b001c 0x0408803A
+wm 32 0x21b001c 0x00008033
+wm 32 0x21b001c 0x0000803B
+wm 32 0x21b001c 0x00428031
+wm 32 0x21b001c 0x00428039
+wm 32 0x21b001c 0x09408030
+wm 32 0x21b001c 0x09408038
+
+wm 32 0x21b001c 0x04008040
+wm 32 0x21b001c 0x04008048
+wm 32 0x21b0800 0xA1380003
+wm 32 0x21b4800 0xA1380003
+wm 32 0x21b0020 0x00005800
+wm 32 0x21b0818 0x00022227
+wm 32 0x21b4818 0x00022227
+
+wm 32 0x21b083c 0x434B0350
+wm 32 0x21b0840 0x034C0359
+wm 32 0x21b483c 0x434B0350
+wm 32 0x21b4840 0x03650348
+wm 32 0x21b0848 0x4436383B
+wm 32 0x21b4848 0x39393341
+wm 32 0x21b0850 0x35373933
+wm 32 0x21b4850 0x48254A36
+
+wm 32 0x21b080c 0x001F001F
+wm 32 0x21b0810 0x001F001F
+
+wm 32 0x21b480c 0x00440044
+wm 32 0x21b4810 0x00440044
+
+wm 32 0x21b08b8 0x00000800
+wm 32 0x21b48b8 0x00000800
+
+wm 32 0x21b001c 0x00000000
+wm 32 0x21b0404 0x00011006
+
+wm 32 0x020c4068 0x00c03f3f
+wm 32 0x020c406c 0x0030fc03
+wm 32 0x020c4070 0x0fffc000
+wm 32 0x020c4074 0x3ff00000
+wm 32 0x020c4078 0x00fff300
+wm 32 0x020c407c 0x0f0000c3
+wm 32 0x020c4080 0x000003ff
+
+# enable AXI cache for VDOA/VPU/IPU
+wm 32 0x20e0010 0xf00000cf
+# set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7
+wm 32 0x20e0018 0x007f007f
+wm 32 0x20e001c 0x007f007f
diff --git a/arch/arm/boards/freescale-mx6-sabrelite/flash_header.c b/arch/arm/boards/freescale-mx6-sabrelite/flash_header.c
deleted file mode 100644
index 61d482b..0000000
--- a/arch/arm/boards/freescale-mx6-sabrelite/flash_header.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (C) 2011 Marc Kleine-Budde <mkl at pengutronix.de>
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <asm/byteorder.h>
-#include <mach/imx-flash-header.h>
-#include <mach/imx6-regs.h>
-#include <asm/barebox-arm-head.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-#define DCD(a, v) { .addr = cpu_to_be32(a), .val = cpu_to_be32(v), }
-
-struct imx_dcd_v2_entry __dcd_entry_section dcd_entry[] = {
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5a8, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5b0, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x524, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x51c, 0x00000030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x518, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x50c, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5b8, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5c0, 0x00000030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5ac, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5b4, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x528, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x520, 0x00020030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x514, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x510, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5bc, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5c4, 0x00020030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x56c, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x578, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x588, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x594, 0x00020030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x57c, 0x00020030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x590, 0x00003000),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x598, 0x00003000),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x58c, 0x00000000),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x59c, 0x00003030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x5a0, 0x00003030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x784, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x788, 0x00000030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x794, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x79c, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x7a0, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x7a4, 0x00000030),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x7a8, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x748, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x74c, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x750, 0x00020000),
-
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x758, 0x00000000),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x774, 0x00020000),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x78c, 0x00000030),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x798, 0x000C0000),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x81c, 0x33333333),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x820, 0x33333333),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x824, 0x33333333),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x828, 0x33333333),
-
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x81c, 0x33333333),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x820, 0x33333333),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x824, 0x33333333),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x828, 0x33333333),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x018, 0x00081740),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00008000),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x00c, 0x555A7975),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x010, 0xFF538E64),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x014, 0x01FF00DB),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x02c, 0x000026D2),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x030, 0x005B0E21),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x008, 0x09444040),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x004, 0x00025576),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x040, 0x00000027),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x000, 0x831A0000),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x04088032),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x0408803A),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00008033),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x0000803B),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00428031),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00428039),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x09408030),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x09408038),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x04008040),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x04008048),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x800, 0xA1380003),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x800, 0xA1380003),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x020, 0x00005800),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x818, 0x00022227),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x818, 0x00022227),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x83c, 0x434B0350),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x840, 0x034C0359),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x83c, 0x434B0350),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x840, 0x03650348),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x848, 0x4436383B),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x848, 0x39393341),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x850, 0x35373933),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x850, 0x48254A36),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x80c, 0x001F001F),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x810, 0x001F001F),
-
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x80c, 0x00440044),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x810, 0x00440044),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x8b8, 0x00000800),
-	DCD(MX6_MMDC_P1_BASE_ADDR + 0x8b8, 0x00000800),
-
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x01c, 0x00000000),
-	DCD(MX6_MMDC_P0_BASE_ADDR + 0x404, 0x00011006),
-
-	DCD(MX6_CCM_BASE_ADDR + 0x068, 0x00c03f3f),
-	DCD(MX6_CCM_BASE_ADDR + 0x06c, 0x0030fc03),
-	DCD(MX6_CCM_BASE_ADDR + 0x070, 0x0fffc000),
-	DCD(MX6_CCM_BASE_ADDR + 0x074, 0x3ff00000),
-	DCD(MX6_CCM_BASE_ADDR + 0x078, 0x00fff300),
-	DCD(MX6_CCM_BASE_ADDR + 0x07c, 0x0f0000c3),
-	DCD(MX6_CCM_BASE_ADDR + 0x080, 0x000003ff),
-
-	/* enable AXI cache for VDOA/VPU/IPU */
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x010, 0xf00000cf),
-	/* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x018, 0x007f007f),
-	DCD(MX6_IOMUXC_BASE_ADDR + 0x01c, 0x007f007f),
-};
-
-#define APP_DEST	CONFIG_TEXT_BASE
-
-struct imx_flash_header_v2 __flash_header_section flash_header = {
-	.header.tag		= IVT_HEADER_TAG,
-	.header.length		= cpu_to_be16(32),
-	.header.version		= IVT_VERSION,
-	.entry			= (u32)_stext,
-	.dcd_ptr		= APP_DEST + FLASH_HEADER_OFFSET + offsetof(struct imx_flash_header_v2, dcd),
-	.boot_data_ptr		= APP_DEST + FLASH_HEADER_OFFSET + offsetof(struct imx_flash_header_v2, boot_data),
-	.self			= APP_DEST + FLASH_HEADER_OFFSET,
-
-	.boot_data.start	= APP_DEST,
-	.boot_data.size		= barebox_image_size,
-
-	.dcd.header.tag		= DCD_HEADER_TAG,
-	.dcd.header.length	= cpu_to_be16(sizeof(struct imx_dcd) + sizeof(dcd_entry)),
-	.dcd.header.version	= DCD_VERSION,
-
-	.dcd.command.tag	= DCD_COMMAND_WRITE_TAG,
-	.dcd.command.length	= cpu_to_be16(sizeof(struct imx_dcd_command) + sizeof(dcd_entry)),
-	.dcd.command.param	= DCD_COMMAND_WRITE_PARAM,
-};
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 1269a08..11fd095 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -522,6 +522,7 @@ config MACH_MX6Q_ARM2
 
 config MACH_SABRELITE
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	bool "Freescale i.MX6 Sabre Lite"
 
 config MACH_SABRESD
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:05:28 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:05:28 +0200
Subject: [PATCH 2/8] ARM: i.MX53 loco: Switch to imximage
In-Reply-To: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
References: <1372021534-25470-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372021534-25470-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx53-loco/Makefile       |  4 +-
 arch/arm/boards/freescale-mx53-loco/board.c        |  7 ++-
 arch/arm/boards/freescale-mx53-loco/dcd-data.h     | 54 ----------------------
 .../boards/freescale-mx53-loco/flash-header.imxcfg | 54 ++++++++++++++++++++++
 arch/arm/boards/freescale-mx53-loco/flash_header.c | 52 ---------------------
 arch/arm/mach-imx/Kconfig                          |  1 +
 6 files changed, 60 insertions(+), 112 deletions(-)
 delete mode 100644 arch/arm/boards/freescale-mx53-loco/dcd-data.h
 create mode 100644 arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/freescale-mx53-loco/flash_header.c

diff --git a/arch/arm/boards/freescale-mx53-loco/Makefile b/arch/arm/boards/freescale-mx53-loco/Makefile
index d44f697..f1baae2 100644
--- a/arch/arm/boards/freescale-mx53-loco/Makefile
+++ b/arch/arm/boards/freescale-mx53-loco/Makefile
@@ -1,3 +1,3 @@
-obj-y += board.o
-lwl-y += flash_header.o
+obj-y += board.o flash-header.o
+extra-y += flash-header.S flash-header.dcd
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c
index e041de6..82ff2d1 100644
--- a/arch/arm/boards/freescale-mx53-loco/board.c
+++ b/arch/arm/boards/freescale-mx53-loco/board.c
@@ -170,9 +170,7 @@ static void loco_ehci_init(void)
 	add_generic_usb_ehci_device(1, MX53_OTG_BASE_ADDR + 0x200, NULL);
 }
 
-#define DCD_NAME static struct imx_dcd_v2_entry dcd_entry
-
-#include "dcd-data.h"
+extern char flash_header_start[], flash_header_end[];
 
 static int loco_devices_init(void)
 {
@@ -194,7 +192,8 @@ static int loco_devices_init(void)
 	armlinux_set_architecture(MACH_TYPE_MX53_LOCO);
 
 	imx53_bbu_internal_mmc_register_handler("mmc", "/dev/disk0",
-		BBU_HANDLER_FLAG_DEFAULT, dcd_entry, sizeof(dcd_entry), 0);
+		BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_start,
+		flash_header_end - flash_header_start, 0);
 
 	return 0;
 }
diff --git a/arch/arm/boards/freescale-mx53-loco/dcd-data.h b/arch/arm/boards/freescale-mx53-loco/dcd-data.h
deleted file mode 100644
index 9f95fb4..0000000
--- a/arch/arm/boards/freescale-mx53-loco/dcd-data.h
+++ /dev/null
@@ -1,54 +0,0 @@
-
-DCD_NAME[] = {
-	{ .addr = cpu_to_be32(0x53fa8554), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8558), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8560), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8564), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8568), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8570), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8574), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8578), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa857c), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8580), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8584), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8588), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8590), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8594), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa86f0), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa86f4), .val = cpu_to_be32(0x00000000), },
-	{ .addr = cpu_to_be32(0x53fa86fc), .val = cpu_to_be32(0x00000000), },
-	{ .addr = cpu_to_be32(0x53fa8714), .val = cpu_to_be32(0x00000000), },
-	{ .addr = cpu_to_be32(0x53fa8718), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa871c), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8720), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8724), .val = cpu_to_be32(0x04000000), },
-	{ .addr = cpu_to_be32(0x53fa8728), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa872c), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x63fd9088), .val = cpu_to_be32(0x35343535), },
-	{ .addr = cpu_to_be32(0x63fd9090), .val = cpu_to_be32(0x4d444c44), },
-	{ .addr = cpu_to_be32(0x63fd907c), .val = cpu_to_be32(0x01370138), },
-	{ .addr = cpu_to_be32(0x63fd9080), .val = cpu_to_be32(0x013b013c), },
-	{ .addr = cpu_to_be32(0x63fd9018), .val = cpu_to_be32(0x00011740), },
-	{ .addr = cpu_to_be32(0x63fd9000), .val = cpu_to_be32(0xc3190000), },
-	{ .addr = cpu_to_be32(0x63fd900c), .val = cpu_to_be32(0x9f5152e3), },
-	{ .addr = cpu_to_be32(0x63fd9010), .val = cpu_to_be32(0xb68e8a63), },
-	{ .addr = cpu_to_be32(0x63fd9014), .val = cpu_to_be32(0x01ff00db), },
-	{ .addr = cpu_to_be32(0x63fd902c), .val = cpu_to_be32(0x000026d2), },
-	{ .addr = cpu_to_be32(0x63fd9030), .val = cpu_to_be32(0x009f0e21), },
-	{ .addr = cpu_to_be32(0x63fd9008), .val = cpu_to_be32(0x12273030), },
-	{ .addr = cpu_to_be32(0x63fd9004), .val = cpu_to_be32(0x0002002d), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00008032), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00008033), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00028031), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x052080b0), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x04008040), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x0000803a), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x0000803b), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00028039), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x05208138), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x04008048), },
-	{ .addr = cpu_to_be32(0x63fd9020), .val = cpu_to_be32(0x00005800), },
-	{ .addr = cpu_to_be32(0x63fd9040), .val = cpu_to_be32(0x04b80003), },
-	{ .addr = cpu_to_be32(0x63fd9058), .val = cpu_to_be32(0x00022227), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00000000), },
-};
diff --git a/arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg b/arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg
new file mode 100644
index 0000000..95bcd19
--- /dev/null
+++ b/arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg
@@ -0,0 +1,54 @@
+loadaddr 0x70000000
+soc imx53
+dcdofs 0x400
+wm 32 0x53fa8554 0x00300000
+wm 32 0x53fa8558 0x00300040
+wm 32 0x53fa8560 0x00300000
+wm 32 0x53fa8564 0x00300040
+wm 32 0x53fa8568 0x00300040
+wm 32 0x53fa8570 0x00300000
+wm 32 0x53fa8574 0x00300000
+wm 32 0x53fa8578 0x00300000
+wm 32 0x53fa857c 0x00300040
+wm 32 0x53fa8580 0x00300040
+wm 32 0x53fa8584 0x00300000
+wm 32 0x53fa8588 0x00300000
+wm 32 0x53fa8590 0x00300040
+wm 32 0x53fa8594 0x00300000
+wm 32 0x53fa86f0 0x00300000
+wm 32 0x53fa86f4 0x00000000
+wm 32 0x53fa86fc 0x00000000
+wm 32 0x53fa8714 0x00000000
+wm 32 0x53fa8718 0x00300000
+wm 32 0x53fa871c 0x00300000
+wm 32 0x53fa8720 0x00300000
+wm 32 0x53fa8724 0x04000000
+wm 32 0x53fa8728 0x00300000
+wm 32 0x53fa872c 0x00300000
+wm 32 0x63fd9088 0x35343535
+wm 32 0x63fd9090 0x4d444c44
+wm 32 0x63fd907c 0x01370138
+wm 32 0x63fd9080 0x013b013c
+wm 32 0x63fd9018 0x00011740
+wm 32 0x63fd9000 0xc3190000
+wm 32 0x63fd900c 0x9f5152e3
+wm 32 0x63fd9010 0xb68e8a63
+wm 32 0x63fd9014 0x01ff00db
+wm 32 0x63fd902c 0x000026d2
+wm 32 0x63fd9030 0x009f0e21
+wm 32 0x63fd9008 0x12273030
+wm 32 0x63fd9004 0x0002002d
+wm 32 0x63fd901c 0x00008032
+wm 32 0x63fd901c 0x00008033
+wm 32 0x63fd901c 0x00028031
+wm 32 0x63fd901c 0x052080b0
+wm 32 0x63fd901c 0x04008040
+wm 32 0x63fd901c 0x0000803a
+wm 32 0x63fd901c 0x0000803b
+wm 32 0x63fd901c 0x00028039
+wm 32 0x63fd901c 0x05208138
+wm 32 0x63fd901c 0x04008048
+wm 32 0x63fd9020 0x00005800
+wm 32 0x63fd9040 0x04b80003
+wm 32 0x63fd9058 0x00022227
+wm 32 0x63fd901c 0x00000000
diff --git a/arch/arm/boards/freescale-mx53-loco/flash_header.c b/arch/arm/boards/freescale-mx53-loco/flash_header.c
deleted file mode 100644
index dc1162b..0000000
--- a/arch/arm/boards/freescale-mx53-loco/flash_header.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2011 Marc Kleine-Budde <mkl at pengutronix.de>
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <asm/byteorder.h>
-#include <mach/imx-flash-header.h>
-#include <asm/barebox-arm-head.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-#define DCD_NAME struct imx_dcd_v2_entry __dcd_entry_section dcd_entry
-
-#include "dcd-data.h"
-
-#define APP_DEST	0x70000000
-
-struct imx_flash_header_v2 __flash_header_section flash_header = {
-	.header.tag		= IVT_HEADER_TAG,
-	.header.length		= cpu_to_be16(32),
-	.header.version		= IVT_VERSION,
-
-	.entry			= APP_DEST + 0x1000,
-	.dcd_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header_v2, dcd),
-	.boot_data_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header_v2, boot_data),
-	.self			= APP_DEST + 0x400,
-
-	.boot_data.start	= APP_DEST,
-	.boot_data.size		= DCD_BAREBOX_SIZE,
-
-	.dcd.header.tag		= DCD_HEADER_TAG,
-	.dcd.header.length	= cpu_to_be16(sizeof(struct imx_dcd) + sizeof(dcd_entry)),
-	.dcd.header.version	= DCD_VERSION,
-
-	.dcd.command.tag	= DCD_COMMAND_WRITE_TAG,
-	.dcd.command.length	= cpu_to_be16(sizeof(struct imx_dcd_command) + sizeof(dcd_entry)),
-	.dcd.command.param	= DCD_COMMAND_WRITE_PARAM,
-};
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index b7282bb..1269a08 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -474,6 +474,7 @@ choice
 
 config MACH_FREESCALE_MX53_LOCO
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	bool "Freescale i.MX53 LOCO"
 
 config MACH_FREESCALE_MX53_SMD
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:40:49 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:40:49 +0200
Subject: [PATCH 1/3] ARM: i.MX: rename initcall functions
Message-ID: <1372023651-13725-1-git-send-email-s.hauer@pengutronix.de>

Some boards use function names locally which we introduce as
global functions in the next patch. Rename them to avoid
'static declaration follows non-static declaration' errors.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx25-3-stack/3stack.c | 4 ++--
 arch/arm/boards/pcm037/pcm037.c                 | 4 ++--
 arch/arm/boards/pcm043/pcm043.c                 | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boards/freescale-mx25-3-stack/3stack.c b/arch/arm/boards/freescale-mx25-3-stack/3stack.c
index ea4d4ba..6620a86 100644
--- a/arch/arm/boards/freescale-mx25-3-stack/3stack.c
+++ b/arch/arm/boards/freescale-mx25-3-stack/3stack.c
@@ -186,7 +186,7 @@ static int imx25_3ds_fec_init(void)
 }
 late_initcall(imx25_3ds_fec_init);
 
-static int imx25_devices_init(void)
+static int imx25_3ds_devices_init(void)
 {
 #ifdef CONFIG_USB
 	/* USB does not work yet. Don't know why. Maybe
@@ -222,7 +222,7 @@ static int imx25_devices_init(void)
 	return 0;
 }
 
-device_initcall(imx25_devices_init);
+device_initcall(imx25_3ds_devices_init);
 
 static iomux_v3_cfg_t imx25_pads[] = {
 	MX25_PAD_FEC_MDC__FEC_MDC,
diff --git a/arch/arm/boards/pcm037/pcm037.c b/arch/arm/boards/pcm037/pcm037.c
index 9361a9d..de83c99 100644
--- a/arch/arm/boards/pcm037/pcm037.c
+++ b/arch/arm/boards/pcm037/pcm037.c
@@ -146,7 +146,7 @@ static struct smc911x_plat smsc9217_pdata = {
 	.flags = SMC911X_FORCE_INTERNAL_PHY,
 };
 
-static int imx31_devices_init(void)
+static int pcm037_devices_init(void)
 {
 	/* CS0: Nor Flash */
 	imx31_setup_weimcs(0, 0x0000cf03, 0x10000d03, 0x00720900);
@@ -202,7 +202,7 @@ static int imx31_devices_init(void)
 	return 0;
 }
 
-device_initcall(imx31_devices_init);
+device_initcall(pcm037_devices_init);
 
 static unsigned int pcm037_iomux[] = {
 	/* UART1 */
diff --git a/arch/arm/boards/pcm043/pcm043.c b/arch/arm/boards/pcm043/pcm043.c
index b2726df..68b7864 100644
--- a/arch/arm/boards/pcm043/pcm043.c
+++ b/arch/arm/boards/pcm043/pcm043.c
@@ -113,7 +113,7 @@ struct gpio_led led0 = {
 	.gpio = 1 * 32 + 6,
 };
 
-static int imx35_devices_init(void)
+static int pcm043_devices_init(void)
 {
 	uint32_t reg;
 	char *envstr;
@@ -173,7 +173,7 @@ static int imx35_devices_init(void)
 	return 0;
 }
 
-device_initcall(imx35_devices_init);
+device_initcall(pcm043_devices_init);
 
 static iomux_v3_cfg_t pcm043_pads[] = {
 	MX35_PAD_FEC_TX_CLK__FEC_TX_CLK,
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:40:50 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:40:50 +0200
Subject: [PATCH 2/3] ARM: i.MX: centralize i.MX startup
In-Reply-To: <1372023651-13725-1-git-send-email-s.hauer@pengutronix.de>
References: <1372023651-13725-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372023651-13725-2-git-send-email-s.hauer@pengutronix.de>

Each i.MX SoC has its own SoC initcall. To ease multi SoC support
move it to a single initcall.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/imx.c                  | 55 ++++++++++++++++++++++++++++++++
 arch/arm/mach-imx/imx1.c                 | 12 +++++--
 arch/arm/mach-imx/imx21.c                |  9 ++++--
 arch/arm/mach-imx/imx25.c                |  8 +++--
 arch/arm/mach-imx/imx27.c                |  9 ++++--
 arch/arm/mach-imx/imx31.c                |  9 ++++--
 arch/arm/mach-imx/imx35.c                | 14 ++++----
 arch/arm/mach-imx/imx51.c                |  9 +++---
 arch/arm/mach-imx/imx53.c                |  8 +++--
 arch/arm/mach-imx/imx6.c                 | 10 +++---
 arch/arm/mach-imx/include/mach/generic.h | 20 ++++++++++++
 11 files changed, 134 insertions(+), 29 deletions(-)

diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
index d36f3d9..d6e30a8 100644
--- a/arch/arm/mach-imx/imx.c
+++ b/arch/arm/mach-imx/imx.c
@@ -12,7 +12,9 @@
  */
 
 #include <common.h>
+#include <init.h>
 #include <mach/revision.h>
+#include <mach/generic.h>
 
 static int __imx_silicon_revision = IMX_CHIP_REV_UNKNOWN;
 
@@ -29,3 +31,56 @@ void imx_set_silicon_revision(const char *soc, int revision)
 			(revision >> 4) & 0xf,
 			revision & 0xf);
 }
+
+static int imx_init(void)
+{
+	int ret;
+
+	if (cpu_is_mx1())
+		ret = imx1_init();
+	else if (cpu_is_mx21())
+		ret = imx21_init();
+	else if (cpu_is_mx25())
+		ret = imx25_init();
+	else if (cpu_is_mx27())
+		ret = imx27_init();
+	else if (cpu_is_mx31())
+		ret = imx31_init();
+	else if (cpu_is_mx35())
+		ret = imx35_init();
+	else if (cpu_is_mx51())
+		ret = imx51_init();
+	else if (cpu_is_mx53())
+		ret = imx53_init();
+	else if (cpu_is_mx6())
+		ret = imx6_init();
+	else
+		return -EINVAL;
+
+	if (of_get_root_node())
+		return ret;
+
+	if (cpu_is_mx1())
+		ret = imx1_devices_init();
+	else if (cpu_is_mx21())
+		ret = imx21_devices_init();
+	else if (cpu_is_mx25())
+		ret = imx25_devices_init();
+	else if (cpu_is_mx27())
+		ret = imx27_devices_init();
+	else if (cpu_is_mx31())
+		ret = imx31_devices_init();
+	else if (cpu_is_mx35())
+		ret = imx35_devices_init();
+	else if (cpu_is_mx51())
+		ret = imx51_devices_init();
+	else if (cpu_is_mx53())
+		ret = imx53_devices_init();
+	else if (cpu_is_mx6())
+		ret = imx6_devices_init();
+	else
+		return -EINVAL;
+
+	return ret;
+}
+postcore_initcall(imx_init);
diff --git a/arch/arm/mach-imx/imx1.c b/arch/arm/mach-imx/imx1.c
index 588ac02..ecd71b8 100644
--- a/arch/arm/mach-imx/imx1.c
+++ b/arch/arm/mach-imx/imx1.c
@@ -17,6 +17,7 @@
 #include <mach/imx1-regs.h>
 #include <mach/weim.h>
 #include <mach/iomux-v1.h>
+#include <mach/generic.h>
 #include <reset_source.h>
 
 #define MX1_RSR MX1_SCM_BASE_ADDR
@@ -51,11 +52,17 @@ void imx1_setup_eimcs(size_t cs, unsigned upper, unsigned lower)
 
 #include <mach/esdctl.h>
 
-static int imx1_init(void)
+int imx1_init(void)
 {
-	imx_iomuxv1_init((void *)MX1_GPIO1_BASE_ADDR);
 	imx1_detect_reset_source();
 
+	return 0;
+}
+
+int imx1_devices_init(void)
+{
+	imx_iomuxv1_init((void *)MX1_GPIO1_BASE_ADDR);
+
 	add_generic_device("imx1-ccm", 0, NULL, MX1_CCM_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
 	add_generic_device("imx1-gpt", 0, NULL, MX1_TIM1_BASE_ADDR, 0x100, IORESOURCE_MEM, NULL);
 	add_generic_device("imx1-gpio", 0, NULL, MX1_GPIO1_BASE_ADDR, 0x100, IORESOURCE_MEM, NULL);
@@ -67,4 +74,3 @@ static int imx1_init(void)
 
 	return 0;
 }
-postcore_initcall(imx1_init);
diff --git a/arch/arm/mach-imx/imx21.c b/arch/arm/mach-imx/imx21.c
index 91cd4bd..ca074dd 100644
--- a/arch/arm/mach-imx/imx21.c
+++ b/arch/arm/mach-imx/imx21.c
@@ -17,6 +17,7 @@
 #include <mach/imx21-regs.h>
 #include <mach/weim.h>
 #include <mach/iomux-v1.h>
+#include <mach/generic.h>
 
 void imx21_setup_eimcs(size_t cs, unsigned upper, unsigned lower)
 {
@@ -24,7 +25,12 @@ void imx21_setup_eimcs(size_t cs, unsigned upper, unsigned lower)
 	writel(lower, MX21_EIM_BASE_ADDR + 4 + cs * 8);
 }
 
-static int imx21_init(void)
+int imx21_init(void)
+{
+	return 0;
+}
+
+int imx21_devices_init(void)
 {
 	imx_iomuxv1_init((void *)MX21_GPIO1_BASE_ADDR);
 
@@ -40,4 +46,3 @@ static int imx21_init(void)
 
 	return 0;
 }
-postcore_initcall(imx21_init);
diff --git a/arch/arm/mach-imx/imx25.c b/arch/arm/mach-imx/imx25.c
index 63e91a5..1d94419 100644
--- a/arch/arm/mach-imx/imx25.c
+++ b/arch/arm/mach-imx/imx25.c
@@ -53,10 +53,15 @@ u64 imx_uid(void)
 	return uid;
 }
 
-static int imx25_init(void)
+int imx25_init(void)
 {
 	imx25_boot_save_loc((void *)MX25_CCM_BASE_ADDR);
 
+	return 0;
+}
+
+int imx25_devices_init(void)
+{
 	add_generic_device("imx_iim", 0, NULL, MX25_IIM_BASE_ADDR, SZ_4K,
 			IORESOURCE_MEM, NULL);
 
@@ -72,4 +77,3 @@ static int imx25_init(void)
 
 	return 0;
 }
-postcore_initcall(imx25_init);
diff --git a/arch/arm/mach-imx/imx27.c b/arch/arm/mach-imx/imx27.c
index 45436be..e0f4765 100644
--- a/arch/arm/mach-imx/imx27.c
+++ b/arch/arm/mach-imx/imx27.c
@@ -20,6 +20,7 @@
 #include <mach/generic.h>
 #include <init.h>
 #include <io.h>
+#include <mach/generic.h>
 
 static int imx27_silicon_revision(void)
 {
@@ -96,11 +97,16 @@ static void imx27_init_max(void)
 	writel(val, max_base + MAX_SLAVE_PORT2_OFFSET + MAX_SLAVE_AMPR_OFFSET);
 }
 
-static int imx27_init(void)
+int imx27_init(void)
 {
 	imx27_silicon_revision();
 	imx27_boot_save_loc((void *)MX27_SYSCTRL_BASE_ADDR);
 
+	return 0;
+}
+
+int imx27_devices_init(void)
+{
 	imx_iomuxv1_init((void *)MX27_GPIO1_BASE_ADDR);
 
 	add_generic_device("imx_iim", DEVICE_ID_SINGLE, NULL,
@@ -124,4 +130,3 @@ static int imx27_init(void)
 
 	return 0;
 }
-postcore_initcall(imx27_init);
diff --git a/arch/arm/mach-imx/imx31.c b/arch/arm/mach-imx/imx31.c
index f0954b5..eb0c415 100644
--- a/arch/arm/mach-imx/imx31.c
+++ b/arch/arm/mach-imx/imx31.c
@@ -17,6 +17,7 @@
 #include <io.h>
 #include <mach/imx31-regs.h>
 #include <mach/weim.h>
+#include <mach/generic.h>
 
 void imx31_setup_weimcs(size_t cs, unsigned upper, unsigned lower,
 		unsigned additional)
@@ -26,7 +27,12 @@ void imx31_setup_weimcs(size_t cs, unsigned upper, unsigned lower,
 	writel(additional, MX31_WEIM_BASE_ADDR + (cs * 0x10) + 0x8);
 }
 
-static int imx31_init(void)
+int imx31_init(void)
+{
+	return 0;
+}
+
+int imx31_devices_init(void)
 {
 	add_generic_device("imx_iim", 0, NULL, MX31_IIM_BASE_ADDR, SZ_4K,
 			IORESOURCE_MEM, NULL);
@@ -43,4 +49,3 @@ static int imx31_init(void)
 
 	return 0;
 }
-postcore_initcall(imx31_init);
diff --git a/arch/arm/mach-imx/imx35.c b/arch/arm/mach-imx/imx35.c
index 92f6964..14ddba3 100644
--- a/arch/arm/mach-imx/imx35.c
+++ b/arch/arm/mach-imx/imx35.c
@@ -49,20 +49,19 @@ static void imx35_silicon_revision(void)
 
 #define L2_MEM_VAL 0x10
 
-static int imx35_l2_fix(void)
+int imx35_init(void)
 {
 	writel(0x515, MX35_CLKCTL_BASE_ADDR + L2_MEM_VAL);
 
-	return 0;
-}
-core_initcall(imx35_l2_fix);
-
-static int imx35_init(void)
-{
 	imx35_silicon_revision();
 
 	imx35_boot_save_loc((void *)MX35_CCM_BASE_ADDR);
 
+	return 0;
+}
+
+int imx35_devices_init(void)
+{
 	add_generic_device("imx_iim", 0, NULL, MX35_IIM_BASE_ADDR, SZ_4K,
 			IORESOURCE_MEM, NULL);
 
@@ -77,4 +76,3 @@ static int imx35_init(void)
 
 	return 0;
 }
-postcore_initcall(imx35_init);
diff --git a/arch/arm/mach-imx/imx51.c b/arch/arm/mach-imx/imx51.c
index fdf2374..7795b5b 100644
--- a/arch/arm/mach-imx/imx51.c
+++ b/arch/arm/mach-imx/imx51.c
@@ -53,14 +53,16 @@ static int imx51_silicon_revision(void)
 	return 0;
 }
 
-static int imx51_init(void)
+int imx51_init(void)
 {
 	imx51_silicon_revision();
 	imx51_boot_save_loc((void *)MX51_SRC_BASE_ADDR);
 
-	if (of_get_root_node())
-		return 0;
+	return 0;
+}
 
+int imx51_devices_init(void)
+{
 	add_generic_device("imx_iim", 0, NULL, MX51_IIM_BASE_ADDR, SZ_4K,
 			IORESOURCE_MEM, NULL);
 
@@ -77,7 +79,6 @@ static int imx51_init(void)
 
 	return 0;
 }
-postcore_initcall(imx51_init);
 
 /*
  * Saves the boot source media into the $bootsource environment variable
diff --git a/arch/arm/mach-imx/imx53.c b/arch/arm/mach-imx/imx53.c
index 193406f..3e1b7fc 100644
--- a/arch/arm/mach-imx/imx53.c
+++ b/arch/arm/mach-imx/imx53.c
@@ -50,11 +50,16 @@ static int imx53_silicon_revision(void)
 	return 0;
 }
 
-static int imx53_init(void)
+int imx53_init(void)
 {
 	imx53_silicon_revision();
 	imx53_boot_save_loc((void *)MX53_SRC_BASE_ADDR);
 
+	return 0;
+}
+
+int imx53_devices_init(void)
+{
 	add_generic_device("imx_iim", 0, NULL, MX53_IIM_BASE_ADDR, SZ_4K,
 			IORESOURCE_MEM, NULL);
 
@@ -73,7 +78,6 @@ static int imx53_init(void)
 
 	return 0;
 }
-postcore_initcall(imx53_init);
 
 void imx53_init_lowlevel_early(unsigned int cpufreq_mhz)
 {
diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
index 5c20aa1..b6914ae 100644
--- a/arch/arm/mach-imx/imx6.c
+++ b/arch/arm/mach-imx/imx6.c
@@ -17,6 +17,7 @@
 #include <sizes.h>
 #include <mach/generic.h>
 #include <mach/imx6-regs.h>
+#include <mach/generic.h>
 
 void imx6_init_lowlevel(void)
 {
@@ -53,13 +54,15 @@ void imx6_init_lowlevel(void)
 	writel(0xffffffff, 0x020c4080);
 }
 
-static int imx6_init(void)
+int imx6_init(void)
 {
 	imx6_boot_save_loc((void *)MX6_SRC_BASE_ADDR);
 
-	if (of_get_root_node())
-		return 0;
+	return 0;
+}
 
+int imx6_devices_init(void)
+{
 	add_generic_device("imx-iomuxv3", 0, NULL, MX6_IOMUXC_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
 	add_generic_device("imx6-ccm", 0, NULL, MX6_CCM_BASE_ADDR, 0x4000, IORESOURCE_MEM, NULL);
 	add_generic_device("imx31-gpt", 0, NULL, MX6_GPT_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
@@ -75,4 +78,3 @@ static int imx6_init(void)
 
 	return 0;
 }
-postcore_initcall(imx6_init);
diff --git a/arch/arm/mach-imx/include/mach/generic.h b/arch/arm/mach-imx/include/mach/generic.h
index 9958cb2..0c5dc8a 100644
--- a/arch/arm/mach-imx/include/mach/generic.h
+++ b/arch/arm/mach-imx/include/mach/generic.h
@@ -13,6 +13,26 @@ void imx51_boot_save_loc(void __iomem *src_base);
 void imx53_boot_save_loc(void __iomem *src_base);
 void imx6_boot_save_loc(void __iomem *src_base);
 
+int imx1_init(void);
+int imx21_init(void);
+int imx25_init(void);
+int imx27_init(void);
+int imx31_init(void);
+int imx35_init(void);
+int imx51_init(void);
+int imx53_init(void);
+int imx6_init(void);
+
+int imx1_devices_init(void);
+int imx21_devices_init(void);
+int imx25_devices_init(void);
+int imx27_devices_init(void);
+int imx31_devices_init(void);
+int imx35_devices_init(void);
+int imx51_devices_init(void);
+int imx53_devices_init(void);
+int imx6_devices_init(void);
+
 /* There's a off-by-one betweem the gpio bank number and the gpiochip */
 /* range e.g. GPIO_1_5 is gpio 5 under linux */
 #define IMX_GPIO_NR(bank, nr)		(((bank) - 1) * 32 + (nr))
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sun Jun 23 17:40:51 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sun, 23 Jun 2013 23:40:51 +0200
Subject: [PATCH 3/3] ARM: i.MX: adopt cpu_is_* for multiple SoCs
In-Reply-To: <1372023651-13725-1-git-send-email-s.hauer@pengutronix.de>
References: <1372023651-13725-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372023651-13725-3-git-send-email-s.hauer@pengutronix.de>

This makes cpu_is_* functions when necessary for upcoming multisoc
support. When only one SoC type is compiled in cpu_is_* still expand
to static values.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/imx.c                  |  36 ++++++++++-
 arch/arm/mach-imx/include/mach/generic.h | 102 +++++++++++++++++++++++++------
 2 files changed, 119 insertions(+), 19 deletions(-)

diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
index d6e30a8..6e80bd6 100644
--- a/arch/arm/mach-imx/imx.c
+++ b/arch/arm/mach-imx/imx.c
@@ -32,9 +32,43 @@ void imx_set_silicon_revision(const char *soc, int revision)
 			revision & 0xf);
 }
 
+unsigned int __imx_cpu_type;
+
+static int imx_soc_from_dt(void)
+{
+	if (of_machine_is_compatible("fsl,imx1"))
+		return IMX_CPU_IMX1;
+	if (of_machine_is_compatible("fsl,imx21"))
+		return IMX_CPU_IMX21;
+	if (of_machine_is_compatible("fsl,imx25"))
+		return IMX_CPU_IMX25;
+	if (of_machine_is_compatible("fsl,imx27"))
+		return IMX_CPU_IMX27;
+	if (of_machine_is_compatible("fsl,imx31"))
+		return IMX_CPU_IMX31;
+	if (of_machine_is_compatible("fsl,imx35"))
+		return IMX_CPU_IMX35;
+	if (of_machine_is_compatible("fsl,imx51"))
+		return IMX_CPU_IMX51;
+	if (of_machine_is_compatible("fsl,imx53"))
+		return IMX_CPU_IMX53;
+	if (of_machine_is_compatible("fsl,imx6"))
+		return IMX_CPU_IMX6;
+
+	return 0;
+}
+
 static int imx_init(void)
 {
 	int ret;
+	struct device_node *root;
+
+	root = of_get_root_node();
+	if (root) {
+		__imx_cpu_type = imx_soc_from_dt();
+		if (!__imx_cpu_type)
+			hang();
+	}
 
 	if (cpu_is_mx1())
 		ret = imx1_init();
@@ -57,7 +91,7 @@ static int imx_init(void)
 	else
 		return -EINVAL;
 
-	if (of_get_root_node())
+	if (root)
 		return ret;
 
 	if (cpu_is_mx1())
diff --git a/arch/arm/mach-imx/include/mach/generic.h b/arch/arm/mach-imx/include/mach/generic.h
index 0c5dc8a..506b1da 100644
--- a/arch/arm/mach-imx/include/mach/generic.h
+++ b/arch/arm/mach-imx/include/mach/generic.h
@@ -37,58 +37,124 @@ int imx6_devices_init(void);
 /* range e.g. GPIO_1_5 is gpio 5 under linux */
 #define IMX_GPIO_NR(bank, nr)		(((bank) - 1) * 32 + (nr))
 
+#define IMX_CPU_IMX1	1
+#define IMX_CPU_IMX21	21
+#define IMX_CPU_IMX25	25
+#define IMX_CPU_IMX27	27
+#define IMX_CPU_IMX31	31
+#define IMX_CPU_IMX35	35
+#define IMX_CPU_IMX51	51
+#define IMX_CPU_IMX53	53
+#define IMX_CPU_IMX6	6
+
+extern unsigned int __imx_cpu_type;
+
 #ifdef CONFIG_ARCH_IMX1
-#define cpu_is_mx1()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX1
+# endif
+# define cpu_is_mx1()		(imx_cpu_type == IMX_CPU_IMX1)
 #else
-#define cpu_is_mx1()	(0)
+# define cpu_is_mx1()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX21
-#define cpu_is_mx21()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX21
+# endif
+# define cpu_is_mx21()		(imx_cpu_type == IMX_CPU_IMX21)
 #else
-#define cpu_is_mx21()	(0)
+# define cpu_is_mx21()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX25
-#define cpu_is_mx25()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX25
+# endif
+# define cpu_is_mx25()		(imx_cpu_type == IMX_CPU_IMX25)
 #else
-#define cpu_is_mx25()	(0)
+# define cpu_is_mx25()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX27
-#define cpu_is_mx27()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX27
+# endif
+# define cpu_is_mx27()		(imx_cpu_type == IMX_CPU_IMX27)
 #else
-#define cpu_is_mx27()	(0)
+# define cpu_is_mx27()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX31
-#define cpu_is_mx31()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX31
+# endif
+# define cpu_is_mx31()		(imx_cpu_type == IMX_CPU_IMX31)
 #else
-#define cpu_is_mx31()	(0)
+# define cpu_is_mx31()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX35
-#define cpu_is_mx35()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX35
+# endif
+# define cpu_is_mx35()		(imx_cpu_type == IMX_CPU_IMX35)
 #else
-#define cpu_is_mx35()	(0)
+# define cpu_is_mx35()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX51
-#define cpu_is_mx51()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX51
+# endif
+# define cpu_is_mx51()		(imx_cpu_type == IMX_CPU_IMX51)
 #else
-#define cpu_is_mx51()	(0)
+# define cpu_is_mx51()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX53
-#define cpu_is_mx53()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX53
+# endif
+# define cpu_is_mx53()		(imx_cpu_type == IMX_CPU_IMX53)
 #else
-#define cpu_is_mx53()	(0)
+# define cpu_is_mx53()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX6
-#define cpu_is_mx6()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX6
+# endif
+# define cpu_is_mx6()		(imx_cpu_type == IMX_CPU_IMX6)
 #else
-#define cpu_is_mx6()	(0)
+# define cpu_is_mx6()		(0)
 #endif
 
 #define cpu_is_mx23()	(0)
-- 
1.8.3.1



From j.weitzel at phytec.de  Mon Jun 24 03:30:45 2013
From: j.weitzel at phytec.de (Jan Weitzel)
Date: Mon, 24 Jun 2013 09:30:45 +0200
Subject: [PATCH] ubiformat: check file size
Message-ID: <1372059045-18113-1-git-send-email-j.weitzel@phytec.de>

If size of a flash image file is 0 ubiformat silently formats the volume.
Check size and abort if size == 0. This may be the case if an empty or tftp
mounted file is used.

Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
---
 commands/ubiformat.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/commands/ubiformat.c b/commands/ubiformat.c
index 121816f..5b4e572 100644
--- a/commands/ubiformat.c
+++ b/commands/ubiformat.c
@@ -325,6 +325,11 @@ static int flash_image(const struct mtd_dev_info *mtd,
 		goto out_close;
 	}
 
+	if (st_size == 0) {
+		sys_errmsg("file \"%s\" has size 0 bytes", args.image);
+		goto out_close;
+	}
+
 	verbose(args.verbose, "will write %d eraseblocks", img_ebs);
 	divisor = img_ebs;
 	for (eb = 0; eb < mtd->eb_cnt; eb++) {
-- 
1.7.0.4



From plagnioj at jcrosoft.com  Mon Jun 24 04:39:08 2013
From: plagnioj at jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
Date: Mon, 24 Jun 2013 10:39:08 +0200
Subject: [PATCH 3/3] ARM: Turn most board directories into regular
 build directories
In-Reply-To: <1372017777-787-4-git-send-email-s.hauer@pengutronix.de>
References: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>
 <1372017777-787-4-git-send-email-s.hauer@pengutronix.de>
Message-ID: <20130624083908.GJ27130@game.jcrosoft.org>

On 22:02 Sun 23 Jun     , Sascha Hauer wrote:
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Why you did not move all of them?

Best Regards,
J.
> ---
>  arch/arm/Makefile        | 78 ++++++------------------------------------------
>  arch/arm/boards/Makefile | 68 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 77 insertions(+), 69 deletions(-)
>  create mode 100644 arch/arm/boards/Makefile
> 
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 32bdd65..2f0f16e 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -69,13 +69,19 @@ machine-$(CONFIG_ARCH_VEXPRESS)		:= vexpress
>  machine-$(CONFIG_ARCH_TEGRA)		:= tegra
>  machine-$(CONFIG_ARCH_ZYNQ)		:= zynq
>  
> +
>  # Board directory name.  This list is sorted alphanumerically
>  # by CONFIG_* macro name.
> -
> +#
> +# DO NOT ADD NEW ENTRIES TO THIS LIST!
> +# Add to arch/arm/boards/Makefile instead.
> +#
> +# These are here only because they have a board specific config.h.
> +# TODO: Get rid of board specific config.h and move these to
> +# arch/arm/boards/Makefile aswell.
>  board-$(CONFIG_MACH_A9M2410)			+= a9m2410
>  board-$(CONFIG_MACH_A9M2440)			+= a9m2440
>  board-$(CONFIG_MACH_ANIMEO_IP)			+= animeo_ip
> -board-$(CONFIG_MACH_ARCHOSG9)			+= archosg9
>  board-$(CONFIG_MACH_AT91RM9200EK)		+= at91rm9200ek
>  board-$(CONFIG_MACH_AT91SAM9260EK)		+= at91sam9260ek
>  board-$(CONFIG_MACH_AT91SAM9261EK)		+= at91sam9261ek
> @@ -86,93 +92,27 @@ board-$(CONFIG_MACH_AT91SAM9M10G45EK)		+= at91sam9m10g45ek
>  board-$(CONFIG_MACH_AT91SAM9M10IHD)		+= at91sam9m10ihd
>  board-$(CONFIG_MACH_AT91SAM9N12EK)		+= at91sam9n12ek
>  board-$(CONFIG_MACH_AT91SAM9X5EK)		+= at91sam9x5ek
> -board-$(CONFIG_MACH_BEAGLE)			+= beagle
> -board-$(CONFIG_MACH_BEAGLEBONE)			+= beaglebone
> -board-$(CONFIG_MACH_CCMX51)			+= ccxmx51
> -board-$(CONFIG_MACH_CFA10036)			+= crystalfontz-cfa10036
> -board-$(CONFIG_MACH_CHUMBY)			+= chumby_falconwing
> -board-$(CONFIG_MACH_CLEP7212)			+= clep7212
>  board-$(CONFIG_MACH_DSS11)			+= dss11
> -board-$(CONFIG_MACH_EDB93012)			+= edb93xx
> -board-$(CONFIG_MACH_EDB9301)			+= edb93xx
> -board-$(CONFIG_MACH_EDB9302A)			+= edb93xx
> -board-$(CONFIG_MACH_EDB9302)			+= edb93xx
> -board-$(CONFIG_MACH_EDB9307A)			+= edb93xx
> -board-$(CONFIG_MACH_EDB9307)			+= edb93xx
> -board-$(CONFIG_MACH_EDB9315A)			+= edb93xx
> -board-$(CONFIG_MACH_EDB9315)			+= edb93xx
> -board-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK)		+= efika-mx-smartbook
> -board-$(CONFIG_MACH_EUKREA_CPUIMX25)		+= eukrea_cpuimx25
> -board-$(CONFIG_MACH_EUKREA_CPUIMX27)		+= eukrea_cpuimx27
> -board-$(CONFIG_MACH_EUKREA_CPUIMX35)		+= eukrea_cpuimx35
> -board-$(CONFIG_MACH_EUKREA_CPUIMX51SD)		+= eukrea_cpuimx51
> -board-$(CONFIG_MACH_FREESCALE_MX25_3STACK)	+= freescale-mx25-3-stack
> -board-$(CONFIG_MACH_FREESCALE_MX35_3STACK)	+= freescale-mx35-3-stack
> -board-$(CONFIG_MACH_FREESCALE_MX51_PDK)		+= freescale-mx51-pdk
> -board-$(CONFIG_MACH_FREESCALE_MX53_LOCO)	+= freescale-mx53-loco
> -board-$(CONFIG_MACH_FREESCALE_MX53_SMD)		+= freescale-mx53-smd
>  board-$(CONFIG_MACH_GE863)			+= telit-evk-pro3
> -board-$(CONFIG_MACH_GLOBALSCALE_GURUPLUG)       += globalscale-guruplug
> -board-$(CONFIG_MACH_GLOBALSCALE_MIRABOX)        += globalscale-mirabox
> -board-$(CONFIG_MACH_GUF_CUPID)			+= guf-cupid
> -board-$(CONFIG_MACH_GUF_VINCELL)		+= guf-vincell
> -board-$(CONFIG_MACH_HIGHBANK)			+= highbank
> -board-$(CONFIG_MACH_IMX21ADS)			+= imx21ads
> -board-$(CONFIG_MACH_IMX233_OLINUXINO)		+= imx233-olinuxino
> -board-$(CONFIG_MACH_IMX27ADS)			+= imx27ads
> -board-$(CONFIG_MACH_MARVELL_ARMADA_XP_GP)	+= marvell-armada-xp-gp
>  board-$(CONFIG_MACH_MINI2440)			+= friendlyarm-mini2440
>  board-$(CONFIG_MACH_MINI6410)			+= friendlyarm-mini6410
> -board-$(CONFIG_MACH_MIOA701)			+= mioa701
>  board-$(CONFIG_MACH_MMCCPU)			+= mmccpu
> -board-$(CONFIG_MACH_MX23EVK)			+= freescale-mx23-evk
> -board-$(CONFIG_MACH_MX28EVK)			+= freescale-mx28-evk
> -board-$(CONFIG_MACH_MX6Q_ARM2)			+= freescale-mx6-arm2
> -board-$(CONFIG_MACH_NESO)			+= guf-neso
> -board-$(CONFIG_MACH_NOMADIK_8815NHK)		+= nhk8815
> -board-$(CONFIG_MACH_NXDB500)			+= netx
> -board-$(CONFIG_MACH_OMAP343xSDP)		+= omap343xdsp
> -board-$(CONFIG_MACH_OMAP3EVM)			+= omap3evm
> -board-$(CONFIG_MACH_PANDA)			+= panda
> -board-$(CONFIG_MACH_PCA100)			+= phycard-i.MX27
> -board-$(CONFIG_MACH_PCAAL1)			+= phycard-a-l1
> -board-$(CONFIG_MACH_PCAAXL2)			+= phycard-a-xl2
>  board-$(CONFIG_MACH_PCM027)			+= pcm027
> -board-$(CONFIG_MACH_PCM037)			+= pcm037
> -board-$(CONFIG_MACH_PCM038)			+= pcm038
> -board-$(CONFIG_MACH_PCM043)			+= pcm043
> -board-$(CONFIG_MACH_PCM049)			+= pcm049
> -board-$(CONFIG_MACH_PCM051)			+= pcm051
> -board-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3)	+= plathome-openblocks-ax3
>  board-$(CONFIG_MACH_PM9261)			+= pm9261
>  board-$(CONFIG_MACH_PM9263)			+= pm9263
>  board-$(CONFIG_MACH_PM9G45)			+= pm9g45
>  board-$(CONFIG_MACH_QIL_A9260)			+= qil-a926x
>  board-$(CONFIG_MACH_QIL_A9G20)			+= qil-a926x
> -board-$(CONFIG_MACH_REALQ7)			+= dmo-mx6-realq7
> -board-$(CONFIG_MACH_RPI)			+= raspberry-pi
> -board-$(CONFIG_MACH_SABRELITE)			+= freescale-mx6-sabrelite
> -board-$(CONFIG_MACH_SABRESD)			+= freescale-mx6-sabresd
>  board-$(CONFIG_MACH_SAMA5D3XEK)			+= sama5d3xek
> -board-$(CONFIG_MACH_SCB9328)			+= scb9328
>  board-$(CONFIG_MACH_SOLIDRUN_CUBOX)		+= solidrun-cubox
>  board-$(CONFIG_MACH_TINY210)			+= friendlyarm-tiny210
>  board-$(CONFIG_MACH_TINY6410)			+= friendlyarm-tiny6410
>  board-$(CONFIG_MACH_TNY_A9260)			+= tny-a926x
>  board-$(CONFIG_MACH_TNY_A9263)			+= tny-a926x
>  board-$(CONFIG_MACH_TNY_A9G20)			+= tny-a926x
> -board-$(CONFIG_MACH_TOSHIBA_AC100)		+= toshiba-ac100
> -board-$(CONFIG_MACH_TQMA53)			+= tqma53
> -board-$(CONFIG_MACH_TX25)			+= karo-tx25
> -board-$(CONFIG_MACH_TX28)			+= karo-tx28
> -board-$(CONFIG_MACH_TX51)			+= karo-tx51
> -board-$(CONFIG_MACH_TX53)			+= karo-tx53
>  board-$(CONFIG_MACH_USB_A9260)			+= usb-a926x
>  board-$(CONFIG_MACH_USB_A9263)			+= usb-a926x
>  board-$(CONFIG_MACH_USB_A9G20)			+= usb-a926x
> -board-$(CONFIG_MACH_VERSATILEPB)		+= versatile
> -board-$(CONFIG_MACH_VEXPRESS)			+= vexpress
> -board-$(CONFIG_MACH_ZEDBOARD)			+= avnet-zedboard
>  
>  machdirs := $(patsubst %,arch/arm/mach-%/,$(machine-y))
>  
> @@ -325,7 +265,7 @@ else
>  MACH :=
>  endif
>  
> -common-y += $(BOARD) $(MACH)
> +common-y += $(BOARD) arch/arm/boards/ $(MACH)
>  common-y += arch/arm/lib/ arch/arm/cpu/
>  
>  common-$(CONFIG_BUILTIN_DTB) += arch/arm/dts/
> diff --git a/arch/arm/boards/Makefile b/arch/arm/boards/Makefile
> new file mode 100644
> index 0000000..6d1e98d
> --- /dev/null
> +++ b/arch/arm/boards/Makefile
> @@ -0,0 +1,68 @@
> +# keep sorted by CONFIG_* macro name.
> +obj-$(CONFIG_MACH_ARCHOSG9)			+= archosg9/
> +obj-$(CONFIG_MACH_BEAGLE)			+= beagle/
> +obj-$(CONFIG_MACH_BEAGLEBONE)			+= beaglebone/
> +obj-$(CONFIG_MACH_CCMX51)			+= ccxmx51/
> +obj-$(CONFIG_MACH_CFA10036)			+= crystalfontz-cfa10036/
> +obj-$(CONFIG_MACH_CHUMBY)			+= chumby_falconwing/
> +obj-$(CONFIG_MACH_CLEP7212)			+= clep7212/
> +obj-$(CONFIG_MACH_EDB93012)			+= edb93xx/
> +obj-$(CONFIG_MACH_EDB9301)			+= edb93xx/
> +obj-$(CONFIG_MACH_EDB9302A)			+= edb93xx/
> +obj-$(CONFIG_MACH_EDB9302)			+= edb93xx/
> +obj-$(CONFIG_MACH_EDB9307A)			+= edb93xx/
> +obj-$(CONFIG_MACH_EDB9307)			+= edb93xx/
> +obj-$(CONFIG_MACH_EDB9315A)			+= edb93xx/
> +obj-$(CONFIG_MACH_EDB9315)			+= edb93xx/
> +obj-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK)		+= efika-mx-smartbook/
> +obj-$(CONFIG_MACH_EUKREA_CPUIMX25)		+= eukrea_cpuimx25/
> +obj-$(CONFIG_MACH_EUKREA_CPUIMX27)		+= eukrea_cpuimx27/
> +obj-$(CONFIG_MACH_EUKREA_CPUIMX35)		+= eukrea_cpuimx35/
> +obj-$(CONFIG_MACH_EUKREA_CPUIMX51SD)		+= eukrea_cpuimx51/
> +obj-$(CONFIG_MACH_FREESCALE_MX25_3STACK)	+= freescale-mx25-3-stack/
> +obj-$(CONFIG_MACH_FREESCALE_MX35_3STACK)	+= freescale-mx35-3-stack/
> +obj-$(CONFIG_MACH_FREESCALE_MX51_PDK)		+= freescale-mx51-pdk/
> +obj-$(CONFIG_MACH_FREESCALE_MX53_LOCO)		+= freescale-mx53-loco/
> +obj-$(CONFIG_MACH_FREESCALE_MX53_SMD)		+= freescale-mx53-smd/
> +obj-$(CONFIG_MACH_GLOBALSCALE_GURUPLUG)		+= globalscale-guruplug/
> +obj-$(CONFIG_MACH_GLOBALSCALE_MIRABOX)		+= globalscale-mirabox/
> +obj-$(CONFIG_MACH_GUF_CUPID)			+= guf-cupid/
> +obj-$(CONFIG_MACH_GUF_VINCELL)			+= guf-vincell/
> +obj-$(CONFIG_MACH_HIGHBANK)			+= highbank/
> +obj-$(CONFIG_MACH_IMX21ADS)			+= imx21ads/
> +obj-$(CONFIG_MACH_IMX233_OLINUXINO)		+= imx233-olinuxino/
> +obj-$(CONFIG_MACH_IMX27ADS)			+= imx27ads/
> +obj-$(CONFIG_MACH_MARVELL_ARMADA_XP_GP)		+= marvell-armada-xp-gp/
> +obj-$(CONFIG_MACH_MIOA701)			+= mioa701/
> +obj-$(CONFIG_MACH_MX23EVK)			+= freescale-mx23-evk/
> +obj-$(CONFIG_MACH_MX28EVK)			+= freescale-mx28-evk/
> +obj-$(CONFIG_MACH_MX6Q_ARM2)			+= freescale-mx6-arm2/
> +obj-$(CONFIG_MACH_NESO)				+= guf-neso/
> +obj-$(CONFIG_MACH_NOMADIK_8815NHK)		+= nhk8815/
> +obj-$(CONFIG_MACH_NXDB500)			+= netx/
> +obj-$(CONFIG_MACH_OMAP343xSDP)			+= omap343xdsp/
> +obj-$(CONFIG_MACH_OMAP3EVM)			+= omap3evm/
> +obj-$(CONFIG_MACH_PANDA)			+= panda/
> +obj-$(CONFIG_MACH_PCA100)			+= phycard-i.MX27/
> +obj-$(CONFIG_MACH_PCAAL1)			+= phycard-a-l1/
> +obj-$(CONFIG_MACH_PCAAXL2)			+= phycard-a-xl2/
> +obj-$(CONFIG_MACH_PCM037)			+= pcm037/
> +obj-$(CONFIG_MACH_PCM038)			+= pcm038/
> +obj-$(CONFIG_MACH_PCM043)			+= pcm043/
> +obj-$(CONFIG_MACH_PCM049)			+= pcm049/
> +obj-$(CONFIG_MACH_PCM051)			+= pcm051/
> +obj-$(CONFIG_MACH_PLATHOME_OPENBLOCKS_AX3)	+= plathome-openblocks-ax3/
> +obj-$(CONFIG_MACH_REALQ7)			+= dmo-mx6-realq7/
> +obj-$(CONFIG_MACH_RPI)				+= raspberry-pi/
> +obj-$(CONFIG_MACH_SABRELITE)			+= freescale-mx6-sabrelite/
> +obj-$(CONFIG_MACH_SABRESD)			+= freescale-mx6-sabresd/
> +obj-$(CONFIG_MACH_SCB9328)			+= scb9328/
> +obj-$(CONFIG_MACH_TOSHIBA_AC100)		+= toshiba-ac100/
> +obj-$(CONFIG_MACH_TQMA53)			+= tqma53/
> +obj-$(CONFIG_MACH_TX25)				+= karo-tx25/
> +obj-$(CONFIG_MACH_TX28)				+= karo-tx28/
> +obj-$(CONFIG_MACH_TX51)				+= karo-tx51/
> +obj-$(CONFIG_MACH_TX53)				+= karo-tx53/
> +obj-$(CONFIG_MACH_VERSATILEPB)			+= versatile/
> +obj-$(CONFIG_MACH_VEXPRESS)			+= vexpress/
> +obj-$(CONFIG_MACH_ZEDBOARD)			+= avnet-zedboard/
> -- 
> 1.8.3.1
> 


From s.hauer at pengutronix.de  Mon Jun 24 05:20:38 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 11:20:38 +0200
Subject: [PATCH 3/3] ARM: Turn most board directories into regular build
 directories
In-Reply-To: <20130624083908.GJ27130@game.jcrosoft.org>
References: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>
 <1372017777-787-4-git-send-email-s.hauer@pengutronix.de>
 <20130624083908.GJ27130@game.jcrosoft.org>
Message-ID: <20130624092038.GT32299@pengutronix.de>

On Mon, Jun 24, 2013 at 10:39:08AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 22:02 Sun 23 Jun     , Sascha Hauer wrote:
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> 
> Why you did not move all of them?

Because they have a board specific config.h file which is not
found when $(BOARD) is empty.

Quoting my introductory mail:

> Jean-Christophe, I'd like to get rid of the remaining config.h
> files. The bulk of the remaining ones are at91 and most of
> them contain a single define for AT91_MAIN_CLK. Could you work
> on this? I could do it myself but I'm sure you have your own
> idea how this should be accomplished.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Mon Jun 24 06:49:20 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Mon, 24 Jun 2013 12:49:20 +0200
Subject: [PATCH v2 1/2] OF: base: add sanity checks to of_new/delete_property
In-Reply-To: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372070961-10132-1-git-send-email-sebastian.hesselbarth@gmail.com>

This adds some sanity checks to of_new_property and of_delete_property.
Also, value pointer is always allocated even with zero length to allow
empty properties to be distinguished from non-existing properties.
Finally, data passed to of_new_property is only copied if non-NULL.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Note: Patch 3 of the former patch set has been dropped in favour of zero
length allocation here.

Changelog:
v1->v2:
- remove unneccesary NULL checks after xzalloc (Suggested by Sascha Hauer)
- allocate zero length value pointer (Suggested by Sascha Hauer)

Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1b351ee..e65cf85 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1527,13 +1527,17 @@ struct property *of_new_property(struct device_node *node, const char *name,
 	struct property *prop;
 
 	prop = xzalloc(sizeof(*prop));
-
 	prop->name = strdup(name);
+	if (!prop->name) {
+		free(prop);
+		return NULL;
+	}
+
 	prop->length = len;
-	if (len) {
-		prop->value = xzalloc(len);
+	prop->value = xzalloc(len);
+
+	if (data)
 		memcpy(prop->value, data, len);
-	}
 
 	list_add_tail(&prop->list, &node->properties);
 
@@ -1542,6 +1546,9 @@ struct property *of_new_property(struct device_node *node, const char *name,
 
 void of_delete_property(struct property *pp)
 {
+	if (!pp)
+		return;
+
 	list_del(&pp->list);
 
 	free(pp->name);
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Mon Jun 24 06:49:21 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Mon, 24 Jun 2013 12:49:21 +0200
Subject: [PATCH v2 2/2] OF: base: use of_delete_property where applicable
In-Reply-To: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372070961-10132-2-git-send-email-sebastian.hesselbarth@gmail.com>

This patch makes OF API use of_delete_property where applicable instead
of freeing allocated data in different places.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Changelog:
v1->v2:
- remove offending whitespace lines

Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   81 ++++++++++++++++------------------------------------
 1 files changed, 25 insertions(+), 56 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index e65cf85..63ff647 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -899,16 +899,11 @@ int of_property_write_u8_array(struct device_node *np,
 	struct property *prop = of_find_property(np, propname, NULL);
 	u8 *val;
 
-	if (!prop)
-		prop = of_new_property(np, propname, NULL, 0);
-	if (!prop)
-		return -ENOMEM;
-
-	free(prop->value);
+	if (prop)
+		of_delete_property(prop);
 
-	prop->length = sizeof(*val) * sz;
-	prop->value = malloc(prop->length);
-	if (!prop->value)
+	prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
+	if (!prop)
 		return -ENOMEM;
 
 	val = prop->value;
@@ -940,16 +935,11 @@ int of_property_write_u16_array(struct device_node *np,
 	struct property *prop = of_find_property(np, propname, NULL);
 	__be16 *val;
 
-	if (!prop)
-		prop = of_new_property(np, propname, NULL, 0);
-	if (!prop)
-		return -ENOMEM;
-
-	free(prop->value);
+	if (prop)
+		of_delete_property(prop);
 
-	prop->length = sizeof(*val) * sz;
-	prop->value = malloc(prop->length);
-	if (!prop->value)
+	prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
+	if (!prop)
 		return -ENOMEM;
 
 	val = prop->value;
@@ -981,16 +971,11 @@ int of_property_write_u32_array(struct device_node *np,
 	struct property *prop = of_find_property(np, propname, NULL);
 	__be32 *val;
 
-	if (!prop)
-		prop = of_new_property(np, propname, NULL, 0);
-	if (!prop)
-		return -ENOMEM;
+	if (prop)
+		of_delete_property(prop);
 
-	free(prop->value);
-
-	prop->length = sizeof(*val) * sz;
-	prop->value = malloc(prop->length);
-	if (!prop->value)
+	prop = of_new_property(np, propname, NULL, sizeof(*val) * sz);
+	if (!prop)
 		return -ENOMEM;
 
 	val = prop->value;
@@ -1022,16 +1007,11 @@ int of_property_write_u64_array(struct device_node *np,
 	struct property *prop = of_find_property(np, propname, NULL);
 	__be32 *val;
 
-	if (!prop)
-		prop = of_new_property(np, propname, NULL, 0);
-	if (!prop)
-		return -ENOMEM;
+	if (prop)
+		of_delete_property(prop);
 
-	free(prop->value);
-
-	prop->length = 2 * sizeof(*val) * sz;
-	prop->value = malloc(prop->length);
-	if (!prop->value)
+	prop = of_new_property(np, propname, NULL, 2 * sizeof(*val) * sz);
+	if (!prop)
 		return -ENOMEM;
 
 	val = prop->value;
@@ -1567,26 +1547,19 @@ void of_delete_property(struct property *pp)
 int of_set_property(struct device_node *np, const char *name, const void *val, int len,
 		int create)
 {
-	struct property *pp;
+	struct property *pp = of_find_property(np, name, NULL);
 
 	if (!np)
 		return -ENOENT;
 
-	pp = of_find_property(np, name, NULL);
-	if (pp) {
-		void *data;
+	if (!pp && !create)
+		return -ENOENT;
 
-		free(pp->value);
-		data = xzalloc(len);
-		memcpy(data, val, len);
-		pp->value = data;
-		pp->length = len;
-	} else {
-		if (!create)
-			return -ENOENT;
+	of_delete_property(pp);
 
-		pp = of_new_property(np, name, val, len);
-	}
+	pp = of_new_property(np, name, val, len);
+	if (!pp)
+		return -ENOMEM;
 
 	return 0;
 }
@@ -1810,12 +1783,8 @@ void of_free(struct device_node *node)
 	if (!node)
 		return;
 
-	list_for_each_entry_safe(p, pt, &node->properties, list) {
-		list_del(&p->list);
-		free(p->name);
-		free(p->value);
-		free(p);
-	}
+	list_for_each_entry_safe(p, pt, &node->properties, list)
+		of_delete_property(p);
 
 	list_for_each_entry_safe(n, nt, &node->children, parent_list) {
 		of_free(n);
-- 
1.7.2.5



From s.hauer at pengutronix.de  Mon Jun 24 07:07:19 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 13:07:19 +0200
Subject: [PATCH 3/3] ARM: i.MX53: Do not register platform devices with
 devicetree probe
In-Reply-To: <1372072039-22759-1-git-send-email-s.hauer@pengutronix.de>
References: <1372072039-22759-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372072039-22759-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/imx53.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/mach-imx/imx53.c b/arch/arm/mach-imx/imx53.c
index 193406f..baafe74 100644
--- a/arch/arm/mach-imx/imx53.c
+++ b/arch/arm/mach-imx/imx53.c
@@ -55,6 +55,9 @@ static int imx53_init(void)
 	imx53_silicon_revision();
 	imx53_boot_save_loc((void *)MX53_SRC_BASE_ADDR);
 
+	if (of_get_root_node())
+		return 0;
+
 	add_generic_device("imx_iim", 0, NULL, MX53_IIM_BASE_ADDR, SZ_4K,
 			IORESOURCE_MEM, NULL);
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 24 07:07:18 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 13:07:18 +0200
Subject: [PATCH 2/3] ARM: i.MX53 LOCO: Switch to devicetree probing
In-Reply-To: <1372072039-22759-1-git-send-email-s.hauer@pengutronix.de>
References: <1372072039-22759-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372072039-22759-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx53-loco/board.c    | 201 ++++------------
 arch/arm/configs/freescale_mx53_loco_defconfig |  11 +-
 arch/arm/dts/Makefile                          |   1 +
 arch/arm/dts/imx53-qsb.dts                     | 314 +++++++++++++++++++++++++
 4 files changed, 364 insertions(+), 163 deletions(-)
 create mode 100644 arch/arm/dts/imx53-qsb.dts

diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c
index e041de6..2f51128 100644
--- a/arch/arm/boards/freescale-mx53-loco/board.c
+++ b/arch/arm/boards/freescale-mx53-loco/board.c
@@ -14,99 +14,30 @@
  *
  */
 
-#include <common.h>
 #include <environment.h>
-#include <fcntl.h>
-#include <fec.h>
-#include <fs.h>
-#include <init.h>
-#include <nand.h>
-#include <net.h>
 #include <partition.h>
+#include <common.h>
 #include <sizes.h>
+#include <gpio.h>
+#include <init.h>
+#include <fs.h>
+#include <io.h>
+
+#include <mfd/mc34708.h>
+#include <i2c/i2c.h>
+
+#include <asm/armlinux.h>
+#include <asm/mmu.h>
 
 #include <generated/mach-types.h>
 
+#include <mach/imx-flash-header.h>
 #include <mach/imx53-regs.h>
-#include <mach/iomux-mx53.h>
-#include <mach/devices-imx53.h>
+#include <mach/revision.h>
 #include <mach/generic.h>
-#include <mach/gpio.h>
-#include <mach/imx-nand.h>
-#include <mach/iim.h>
 #include <mach/imx5.h>
-#include <mach/revision.h>
 #include <mach/bbu.h>
-#include <mach/imx-flash-header.h>
-
-#include <i2c/i2c.h>
-#include <mfd/mc34708.h>
-
-#include <asm/armlinux.h>
-#include <io.h>
-#include <asm/mmu.h>
-
-static struct fec_platform_data fec_info = {
-	.xcv_type = PHY_INTERFACE_MODE_RMII,
-};
-
-static iomux_v3_cfg_t loco_pads[] = {
-	/* UART1 */
-	MX53_PAD_CSI0_DAT10__UART1_TXD_MUX,
-	MX53_PAD_CSI0_DAT11__UART1_RXD_MUX,
-
-	/* FEC */
-	MX53_PAD_FEC_MDC__FEC_MDC,
-	MX53_PAD_FEC_MDIO__FEC_MDIO,
-	MX53_PAD_FEC_REF_CLK__FEC_TX_CLK,
-	MX53_PAD_FEC_RX_ER__FEC_RX_ER,
-	MX53_PAD_FEC_CRS_DV__FEC_RX_DV,
-	MX53_PAD_FEC_RXD1__FEC_RDATA_1,
-	MX53_PAD_FEC_RXD0__FEC_RDATA_0,
-	MX53_PAD_FEC_TX_EN__FEC_TX_EN,
-	MX53_PAD_FEC_TXD1__FEC_TDATA_1,
-	MX53_PAD_FEC_TXD0__FEC_TDATA_0,
-	/* FEC_nRST */
-	MX53_PAD_PATA_DA_0__GPIO7_6,
-
-	/* SD1 */
-	MX53_PAD_SD1_CMD__ESDHC1_CMD,
-	MX53_PAD_SD1_CLK__ESDHC1_CLK,
-	MX53_PAD_SD1_DATA0__ESDHC1_DAT0,
-	MX53_PAD_SD1_DATA1__ESDHC1_DAT1,
-	MX53_PAD_SD1_DATA2__ESDHC1_DAT2,
-	MX53_PAD_SD1_DATA3__ESDHC1_DAT3,
-	/* SD1_CD */
-	MX53_PAD_EIM_DA13__GPIO3_13,
-
-	/* SD3 */
-	MX53_PAD_PATA_DATA8__ESDHC3_DAT0,
-	MX53_PAD_PATA_DATA9__ESDHC3_DAT1,
-	MX53_PAD_PATA_DATA10__ESDHC3_DAT2,
-	MX53_PAD_PATA_DATA11__ESDHC3_DAT3,
-	MX53_PAD_PATA_DATA0__ESDHC3_DAT4,
-	MX53_PAD_PATA_DATA1__ESDHC3_DAT5,
-	MX53_PAD_PATA_DATA2__ESDHC3_DAT6,
-	MX53_PAD_PATA_DATA3__ESDHC3_DAT7,
-	MX53_PAD_PATA_IORDY__ESDHC3_CLK,
-	MX53_PAD_PATA_RESET_B__ESDHC3_CMD,
-	/* SD3_CD */
-	MX53_PAD_EIM_DA11__GPIO3_11,
-	/* SD3_WP */
-	MX53_PAD_EIM_DA12__GPIO3_12,
-
-	/* I2C0 */
-	MX53_PAD_CSI0_DAT8__I2C1_SDA,
-	MX53_PAD_CSI0_DAT9__I2C1_SCL,
-
-	MX53_PAD_PATA_DA_2__GPIO7_8,
-};
-
-static struct i2c_board_info i2c_devices[] = {
-	{
-		I2C_BOARD_INFO("mc34708-i2c", 0x08),
-	},
-};
+#include <mach/iim.h>
 
 /*
  * Revision to be passed to kernel. The kernel provided
@@ -142,106 +73,60 @@ static void loco_fec_reset(void)
 	gpio_set_value(LOCO_FEC_PHY_RST, 1);
 }
 
-#define LOCO_SD3_CD			IMX_GPIO_NR(3, 11)
-#define LOCO_SD3_WP			IMX_GPIO_NR(3, 12)
-#define LOCO_SD1_CD			IMX_GPIO_NR(3, 13)
 #define MX53_LOCO_USB_PWREN		IMX_GPIO_NR(7, 8)
 
-static struct esdhc_platform_data loco_sd1_data = {
-	.cd_gpio = LOCO_SD1_CD,
-	.cd_type = ESDHC_CD_GPIO,
-	.wp_type = ESDHC_WP_NONE,
-};
+#define DCD_NAME static struct imx_dcd_v2_entry dcd_entry
 
-static struct esdhc_platform_data loco_sd3_data = {
-	.cd_gpio = LOCO_SD3_CD,
-	.wp_gpio = LOCO_SD3_WP,
-	.cd_type = ESDHC_CD_GPIO,
-	.wp_type = ESDHC_WP_GPIO,
-};
+#include "dcd-data.h"
 
-static void loco_ehci_init(void)
+static int loco_late_init(void)
 {
-	/* USB PWR enable */
-	gpio_direction_output(MX53_LOCO_USB_PWREN, 0);
-	gpio_set_value(MX53_LOCO_USB_PWREN, 1);
+	struct device_d *dev = get_device_by_name("mmc0");
+	struct mc34708 *mc34708;
+	int rev;
 
-	writel(0, MX53_OTG_BASE_ADDR + 0x384); /* setup portsc */
-	add_generic_usb_ehci_device(1, MX53_OTG_BASE_ADDR + 0x200, NULL);
-}
+	if (dev)
+		device_detect(dev);
 
-#define DCD_NAME static struct imx_dcd_v2_entry dcd_entry
+	devfs_add_partition("mmc0", 0x40000, 0x20000, DEVFS_PARTITION_FIXED, "env0");
 
-#include "dcd-data.h"
+	mc34708 = mc34708_get();
+	if (mc34708) {
+		/* get the board revision from fuse */
+		rev = readl(MX53_IIM_BASE_ADDR + 0x878);
+		set_board_rev(rev);
+		printf("MCIMX53-START-R board 1.0 rev %c\n", (rev == 1) ? 'A' : 'B' );
+		armlinux_set_revision(loco_system_rev);
+	} else {
+		/* so we have a DA9053 based board */
+		printf("MCIMX53-START board 1.0\n");
+		armlinux_set_revision(loco_system_rev);
+		return 0;
+	}
 
-static int loco_devices_init(void)
-{
+	/* USB PWR enable */
+	gpio_direction_output(MX53_LOCO_USB_PWREN, 0);
+	gpio_set_value(MX53_LOCO_USB_PWREN, 1);
 
-	imx53_iim_register_fec_ethaddr();
 	loco_fec_reset();
-	imx53_add_fec(&fec_info);
-	imx53_add_mmc0(&loco_sd1_data);
-	imx53_add_mmc2(&loco_sd3_data);
-	i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
-	imx53_add_i2c0(NULL);
-
-	if (IS_ENABLED(CONFIG_USB_EHCI))
-		loco_ehci_init();
 
 	set_silicon_rev(imx_silicon_revision());
 
 	armlinux_set_bootparams((void *)0x70000100);
 	armlinux_set_architecture(MACH_TYPE_MX53_LOCO);
 
-	imx53_bbu_internal_mmc_register_handler("mmc", "/dev/disk0",
+	imx53_bbu_internal_mmc_register_handler("mmc", "/dev/mmc0",
 		BBU_HANDLER_FLAG_DEFAULT, dcd_entry, sizeof(dcd_entry), 0);
 
-	return 0;
-}
-
-device_initcall(loco_devices_init);
-
-static int loco_part_init(void)
-{
-	devfs_add_partition("disk0", 0x00000, 0x40000, DEVFS_PARTITION_FIXED, "self0");
-	devfs_add_partition("disk0", 0x40000, 0x20000, DEVFS_PARTITION_FIXED, "env0");
 
 	return 0;
 }
-late_initcall(loco_part_init);
+late_initcall(loco_late_init);
 
-static int loco_console_init(void)
+static int loco_core_init(void)
 {
-	mxc_iomux_v3_setup_multiple_pads(loco_pads, ARRAY_SIZE(loco_pads));
-
 	imx53_init_lowlevel(1000);
 
-	imx53_add_uart0();
-	return 0;
-}
-
-console_initcall(loco_console_init);
-
-static int loco_pmic_init(void)
-{
-	struct mc34708 *mc34708;
-	int rev;
-
-	mc34708 = mc34708_get();
-	if (!mc34708) {
-		/* so we have a DA9053 based board */
-		printf("MCIMX53-START board 1.0\n");
-		armlinux_set_revision(loco_system_rev);
-		return 0;
-	}
-
-	/* get the board revision from fuse */
-	rev = readl(MX53_IIM_BASE_ADDR + 0x878);
-	set_board_rev(rev);
-	printf("MCIMX53-START-R board 1.0 rev %c\n", (rev == 1) ? 'A' : 'B' );
-	armlinux_set_revision(loco_system_rev);
-
 	return 0;
 }
-
-late_initcall(loco_pmic_init);
+core_initcall(loco_core_init);
diff --git a/arch/arm/configs/freescale_mx53_loco_defconfig b/arch/arm/configs/freescale_mx53_loco_defconfig
index fb6fcf8..e45863c 100644
--- a/arch/arm/configs/freescale_mx53_loco_defconfig
+++ b/arch/arm/configs/freescale_mx53_loco_defconfig
@@ -1,3 +1,5 @@
+CONFIG_BUILTIN_DTB=y
+CONFIG_BUILTIN_DTB_NAME="imx53-qsb"
 CONFIG_ARCH_IMX=y
 CONFIG_ARCH_IMX53=y
 CONFIG_IMX_IIM=y
@@ -8,8 +10,7 @@ CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
 CONFIG_PBL_IMAGE=y
 CONFIG_MMU=y
-CONFIG_TEXT_BASE=0x7ff00000
-CONFIG_MALLOC_SIZE=0x2000000
+CONFIG_MALLOC_SIZE=0x0
 CONFIG_MALLOC_TLSF=y
 CONFIG_KALLSYMS=y
 CONFIG_LONGHELP=y
@@ -17,6 +18,7 @@ CONFIG_HUSH_FANCY_PROMPT=y
 CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
 CONFIG_MENU=y
+CONFIG_CONSOLE_ACTIVATE_NONE=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/freescale-mx53-loco/env/"
 CONFIG_RESET_SOURCE=y
@@ -31,9 +33,7 @@ CONFIG_CMD_READLINE=y
 CONFIG_CMD_MENU=y
 CONFIG_CMD_MENU_MANAGEMENT=y
 CONFIG_CMD_TIME=y
-CONFIG_CMD_DIRNAME=y
 CONFIG_CMD_LN=y
-CONFIG_CMD_READLINK=y
 CONFIG_CMD_TFTP=y
 CONFIG_CMD_FILETYPE=y
 CONFIG_CMD_ECHO_E=y
@@ -62,11 +62,13 @@ CONFIG_CMD_UNCOMPRESS=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MIITOOL=y
 CONFIG_CMD_CLK=y
+CONFIG_CMD_DETECT=y
 CONFIG_CMD_WD=y
 CONFIG_NET=y
 CONFIG_NET_DHCP=y
 CONFIG_NET_PING=y
 CONFIG_NET_NETCONSOLE=y
+CONFIG_OFDEVICE=y
 CONFIG_SMSC_PHY=y
 CONFIG_DRIVER_NET_FEC_IMX=y
 # CONFIG_SPI is not set
@@ -77,7 +79,6 @@ CONFIG_USB=y
 CONFIG_USB_EHCI=y
 CONFIG_USB_STORAGE=y
 CONFIG_MCI=y
-CONFIG_MCI_STARTUP=y
 CONFIG_MCI_IMX_ESDHC=y
 CONFIG_MFD_MC34708=y
 CONFIG_WATCHDOG=y
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index fa6a330..f22cc2b 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1,4 +1,5 @@
 dtb-$(CONFIG_ARCH_IMX51) += imx51-babbage.dtb
+dtb-$(CONFIG_ARCH_IMX53) += imx53-qsb.dtb
 dtb-$(CONFIG_ARCH_IMX6) += imx6q-sabrelite.dtb \
 	imx6q-sabresd.dtb
 
diff --git a/arch/arm/dts/imx53-qsb.dts b/arch/arm/dts/imx53-qsb.dts
new file mode 100644
index 0000000..1dfb48b
--- /dev/null
+++ b/arch/arm/dts/imx53-qsb.dts
@@ -0,0 +1,314 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/dts-v1/;
+#include "imx53.dtsi"
+
+/ {
+	model = "Freescale i.MX53 Quick Start Board";
+	compatible = "fsl,imx53-qsb", "fsl,imx53";
+
+	chosen {
+		linux,stdout-path = "/soc/aips at 50000000/serial at 53fbc000";
+	};
+
+	memory {
+		reg = <0x70000000 0x40000000>;
+	};
+
+	display at di0 {
+		compatible = "fsl,imx-parallel-display";
+		crtcs = <&ipu 0>;
+		interface-pix-fmt = "rgb565";
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_ipu_disp0_1>;
+		status = "disabled";
+		display-timings {
+			claawvga {
+				native-mode;
+				clock-frequency = <27000000>;
+				hactive = <800>;
+				vactive = <480>;
+				hback-porch = <40>;
+				hfront-porch = <60>;
+				vback-porch = <10>;
+				vfront-porch = <10>;
+				hsync-len = <20>;
+				vsync-len = <10>;
+				hsync-active = <0>;
+				vsync-active = <0>;
+				de-active = <1>;
+				pixelclk-active = <0>;
+			};
+		};
+	};
+
+	gpio-keys {
+		compatible = "gpio-keys";
+
+		power {
+			label = "Power Button";
+			gpios = <&gpio1 8 0>;
+			linux,code = <116>; /* KEY_POWER */
+			gpio-key,wakeup;
+		};
+
+		volume-up {
+			label = "Volume Up";
+			gpios = <&gpio2 14 0>;
+			linux,code = <115>; /* KEY_VOLUMEUP */
+		};
+
+		volume-down {
+			label = "Volume Down";
+			gpios = <&gpio2 15 0>;
+			linux,code = <114>; /* KEY_VOLUMEDOWN */
+		};
+	};
+
+	leds {
+		compatible = "gpio-leds";
+		pinctrl-names = "default";
+		pinctrl-0 = <&led_pin_gpio7_7>;
+
+		user {
+			label = "Heartbeat";
+			gpios = <&gpio7 7 0>;
+			linux,default-trigger = "heartbeat";
+		};
+	};
+
+	regulators {
+		compatible = "simple-bus";
+
+		reg_3p2v: 3p2v {
+			compatible = "regulator-fixed";
+			regulator-name = "3P2V";
+			regulator-min-microvolt = <3200000>;
+			regulator-max-microvolt = <3200000>;
+			regulator-always-on;
+		};
+	};
+
+	sound {
+		compatible = "fsl,imx53-qsb-sgtl5000",
+			     "fsl,imx-audio-sgtl5000";
+		model = "imx53-qsb-sgtl5000";
+		ssi-controller = <&ssi2>;
+		audio-codec = <&sgtl5000>;
+		audio-routing =
+			"MIC_IN", "Mic Jack",
+			"Mic Jack", "Mic Bias",
+			"Headphone Jack", "HP_OUT";
+		mux-int-port = <2>;
+		mux-ext-port = <5>;
+	};
+};
+
+&esdhc1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_esdhc1_1>;
+	cd-gpios = <&gpio3 13 0>;
+	status = "okay";
+};
+
+&ssi2 {
+	fsl,mode = "i2s-slave";
+	status = "okay";
+};
+
+&esdhc3 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_esdhc3_1>;
+	cd-gpios = <&gpio3 11 0>;
+	wp-gpios = <&gpio3 12 0>;
+	status = "okay";
+};
+
+&iim {
+	barebox,provide-mac-address = <&fec 1 9>;
+};
+
+&iomuxc {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_hog>;
+
+	hog {
+		pinctrl_hog: hoggrp {
+			fsl,pins = <
+				MX53_PAD_GPIO_0__CCM_SSI_EXT1_CLK 0x80000000
+				MX53_PAD_GPIO_8__GPIO1_8          0x80000000
+				MX53_PAD_PATA_DATA14__GPIO2_14    0x80000000
+				MX53_PAD_PATA_DATA15__GPIO2_15    0x80000000
+				MX53_PAD_EIM_DA11__GPIO3_11       0x80000000
+				MX53_PAD_EIM_DA12__GPIO3_12       0x80000000
+				MX53_PAD_EIM_DA13__GPIO3_13       0x80000000
+				MX53_PAD_PATA_DA_0__GPIO7_6       0x80000000
+				MX53_PAD_GPIO_16__GPIO7_11        0x80000000
+			>;
+		};
+
+		led_pin_gpio7_7: led_gpio7_7 at 0 {
+			fsl,pins = <
+				MX53_PAD_PATA_DA_1__GPIO7_7 0x80000000
+			>;
+		};
+	};
+
+};
+
+&uart1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_uart1_1>;
+	status = "okay";
+};
+
+&i2c2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c2_1>;
+	status = "okay";
+
+	sgtl5000: codec at 0a {
+		compatible = "fsl,sgtl5000";
+		reg = <0x0a>;
+		VDDA-supply = <&reg_3p2v>;
+		VDDIO-supply = <&reg_3p2v>;
+		clocks = <&clks 150>;
+	};
+};
+
+&i2c1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c1_1>;
+	status = "okay";
+
+	accelerometer: mma8450 at 1c {
+		compatible = "fsl,mma8450";
+		reg = <0x1c>;
+	};
+
+	pmic: dialog at 48 {
+		compatible = "dlg,da9053-aa", "dlg,da9052";
+		reg = <0x48>;
+		interrupt-parent = <&gpio7>;
+		interrupts = <11 0x8>; /* low-level active IRQ at GPIO7_11 */
+
+		regulators {
+			buck1_reg: buck1 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <2075000>;
+				regulator-always-on;
+			};
+
+			buck2_reg: buck2 {
+				regulator-min-microvolt = <500000>;
+				regulator-max-microvolt = <2075000>;
+				regulator-always-on;
+			};
+
+			buck3_reg: buck3 {
+				regulator-min-microvolt = <925000>;
+				regulator-max-microvolt = <2500000>;
+				regulator-always-on;
+			};
+
+			buck4_reg: buck4 {
+				regulator-min-microvolt = <925000>;
+				regulator-max-microvolt = <2500000>;
+				regulator-always-on;
+			};
+
+			ldo1_reg: ldo1 {
+				regulator-min-microvolt = <600000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			ldo2_reg: ldo2 {
+				regulator-min-microvolt = <600000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-always-on;
+			};
+
+			ldo3_reg: ldo3 {
+				regulator-min-microvolt = <600000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-always-on;
+			};
+
+			ldo4_reg: ldo4 {
+				regulator-min-microvolt = <1725000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+			};
+
+			ldo5_reg: ldo5 {
+				regulator-min-microvolt = <1725000>;
+				regulator-max-microvolt = <3300000>;
+				regulator-always-on;
+			};
+
+			ldo6_reg: ldo6 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <3600000>;
+				regulator-always-on;
+			};
+
+			ldo7_reg: ldo7 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <3600000>;
+				regulator-always-on;
+			};
+
+			ldo8_reg: ldo8 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <3600000>;
+				regulator-always-on;
+			};
+
+			ldo9_reg: ldo9 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <3600000>;
+				regulator-always-on;
+			};
+
+			ldo10_reg: ldo10 {
+				regulator-min-microvolt = <1250000>;
+				regulator-max-microvolt = <3650000>;
+				regulator-always-on;
+			};
+		};
+	};
+};
+
+&audmux {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_audmux_1>;
+	status = "okay";
+};
+
+&fec {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_fec_1>;
+	phy-mode = "rmii";
+	phy-reset-gpios = <&gpio7 6 0>;
+	status = "okay";
+};
+
+&usbh1 {
+       status = "okay";
+};
+
+&usbotg {
+       status = "okay";
+};
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 24 07:07:17 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 13:07:17 +0200
Subject: [PATCH 1/3] ARM: i.MX53: Add devicetree files
Message-ID: <1372072039-22759-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/dts/imx53-pinfunc.h | 1189 ++++++++++++++++++++++++++++++++++++++++++
 arch/arm/dts/imx53.dtsi      | 1092 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 2281 insertions(+)
 create mode 100644 arch/arm/dts/imx53-pinfunc.h
 create mode 100644 arch/arm/dts/imx53.dtsi

diff --git a/arch/arm/dts/imx53-pinfunc.h b/arch/arm/dts/imx53-pinfunc.h
new file mode 100644
index 0000000..aec406b
--- /dev/null
+++ b/arch/arm/dts/imx53-pinfunc.h
@@ -0,0 +1,1189 @@
+/*
+ * Copyright 2013 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef __DTS_IMX53_PINFUNC_H
+#define __DTS_IMX53_PINFUNC_H
+
+/*
+ * The pin function ID is a tuple of
+ * <mux_reg conf_reg input_reg mux_mode input_val>
+ */
+#define MX53_PAD_GPIO_19__KPP_COL_5				0x020 0x348 0x840 0x0 0x0
+#define MX53_PAD_GPIO_19__GPIO4_5				0x020 0x348 0x000 0x1 0x0
+#define MX53_PAD_GPIO_19__CCM_CLKO				0x020 0x348 0x000 0x2 0x0
+#define MX53_PAD_GPIO_19__SPDIF_OUT1				0x020 0x348 0x000 0x3 0x0
+#define MX53_PAD_GPIO_19__RTC_CE_RTC_EXT_TRIG2			0x020 0x348 0x000 0x4 0x0
+#define MX53_PAD_GPIO_19__ECSPI1_RDY				0x020 0x348 0x000 0x5 0x0
+#define MX53_PAD_GPIO_19__FEC_TDATA_3				0x020 0x348 0x000 0x6 0x0
+#define MX53_PAD_GPIO_19__SRC_INT_BOOT				0x020 0x348 0x000 0x7 0x0
+#define MX53_PAD_KEY_COL0__KPP_COL_0				0x024 0x34c 0x000 0x0 0x0
+#define MX53_PAD_KEY_COL0__GPIO4_6				0x024 0x34c 0x000 0x1 0x0
+#define MX53_PAD_KEY_COL0__AUDMUX_AUD5_TXC			0x024 0x34c 0x758 0x2 0x0
+#define MX53_PAD_KEY_COL0__UART4_TXD_MUX			0x024 0x34c 0x000 0x4 0x0
+#define MX53_PAD_KEY_COL0__ECSPI1_SCLK				0x024 0x34c 0x79c 0x5 0x0
+#define MX53_PAD_KEY_COL0__FEC_RDATA_3				0x024 0x34c 0x000 0x6 0x0
+#define MX53_PAD_KEY_COL0__SRC_ANY_PU_RST			0x024 0x34c 0x000 0x7 0x0
+#define MX53_PAD_KEY_ROW0__KPP_ROW_0				0x028 0x350 0x000 0x0 0x0
+#define MX53_PAD_KEY_ROW0__GPIO4_7				0x028 0x350 0x000 0x1 0x0
+#define MX53_PAD_KEY_ROW0__AUDMUX_AUD5_TXD			0x028 0x350 0x74c 0x2 0x0
+#define MX53_PAD_KEY_ROW0__UART4_RXD_MUX			0x028 0x350 0x890 0x4 0x1
+#define MX53_PAD_KEY_ROW0__ECSPI1_MOSI				0x028 0x350 0x7a4 0x5 0x0
+#define MX53_PAD_KEY_ROW0__FEC_TX_ER				0x028 0x350 0x000 0x6 0x0
+#define MX53_PAD_KEY_COL1__KPP_COL_1				0x02c 0x354 0x000 0x0 0x0
+#define MX53_PAD_KEY_COL1__GPIO4_8				0x02c 0x354 0x000 0x1 0x0
+#define MX53_PAD_KEY_COL1__AUDMUX_AUD5_TXFS			0x02c 0x354 0x75c 0x2 0x0
+#define MX53_PAD_KEY_COL1__UART5_TXD_MUX			0x02c 0x354 0x000 0x4 0x0
+#define MX53_PAD_KEY_COL1__ECSPI1_MISO				0x02c 0x354 0x7a0 0x5 0x0
+#define MX53_PAD_KEY_COL1__FEC_RX_CLK				0x02c 0x354 0x808 0x6 0x0
+#define MX53_PAD_KEY_COL1__USBPHY1_TXREADY			0x02c 0x354 0x000 0x7 0x0
+#define MX53_PAD_KEY_ROW1__KPP_ROW_1				0x030 0x358 0x000 0x0 0x0
+#define MX53_PAD_KEY_ROW1__GPIO4_9				0x030 0x358 0x000 0x1 0x0
+#define MX53_PAD_KEY_ROW1__AUDMUX_AUD5_RXD			0x030 0x358 0x748 0x2 0x0
+#define MX53_PAD_KEY_ROW1__UART5_RXD_MUX			0x030 0x358 0x898 0x4 0x1
+#define MX53_PAD_KEY_ROW1__ECSPI1_SS0				0x030 0x358 0x7a8 0x5 0x0
+#define MX53_PAD_KEY_ROW1__FEC_COL				0x030 0x358 0x800 0x6 0x0
+#define MX53_PAD_KEY_ROW1__USBPHY1_RXVALID			0x030 0x358 0x000 0x7 0x0
+#define MX53_PAD_KEY_COL2__KPP_COL_2				0x034 0x35c 0x000 0x0 0x0
+#define MX53_PAD_KEY_COL2__GPIO4_10				0x034 0x35c 0x000 0x1 0x0
+#define MX53_PAD_KEY_COL2__CAN1_TXCAN				0x034 0x35c 0x000 0x2 0x0
+#define MX53_PAD_KEY_COL2__FEC_MDIO				0x034 0x35c 0x804 0x4 0x0
+#define MX53_PAD_KEY_COL2__ECSPI1_SS1				0x034 0x35c 0x7ac 0x5 0x0
+#define MX53_PAD_KEY_COL2__FEC_RDATA_2				0x034 0x35c 0x000 0x6 0x0
+#define MX53_PAD_KEY_COL2__USBPHY1_RXACTIVE			0x034 0x35c 0x000 0x7 0x0
+#define MX53_PAD_KEY_ROW2__KPP_ROW_2				0x038 0x360 0x000 0x0 0x0
+#define MX53_PAD_KEY_ROW2__GPIO4_11				0x038 0x360 0x000 0x1 0x0
+#define MX53_PAD_KEY_ROW2__CAN1_RXCAN				0x038 0x360 0x760 0x2 0x0
+#define MX53_PAD_KEY_ROW2__FEC_MDC				0x038 0x360 0x000 0x4 0x0
+#define MX53_PAD_KEY_ROW2__ECSPI1_SS2				0x038 0x360 0x7b0 0x5 0x0
+#define MX53_PAD_KEY_ROW2__FEC_TDATA_2				0x038 0x360 0x000 0x6 0x0
+#define MX53_PAD_KEY_ROW2__USBPHY1_RXERROR			0x038 0x360 0x000 0x7 0x0
+#define MX53_PAD_KEY_COL3__KPP_COL_3				0x03c 0x364 0x000 0x0 0x0
+#define MX53_PAD_KEY_COL3__GPIO4_12				0x03c 0x364 0x000 0x1 0x0
+#define MX53_PAD_KEY_COL3__USBOH3_H2_DP				0x03c 0x364 0x000 0x2 0x0
+#define MX53_PAD_KEY_COL3__SPDIF_IN1				0x03c 0x364 0x870 0x3 0x0
+#define MX53_PAD_KEY_COL3__I2C2_SCL				0x03c 0x364 0x81c 0x4 0x0
+#define MX53_PAD_KEY_COL3__ECSPI1_SS3				0x03c 0x364 0x7b4 0x5 0x0
+#define MX53_PAD_KEY_COL3__FEC_CRS				0x03c 0x364 0x000 0x6 0x0
+#define MX53_PAD_KEY_COL3__USBPHY1_SIECLOCK			0x03c 0x364 0x000 0x7 0x0
+#define MX53_PAD_KEY_ROW3__KPP_ROW_3				0x040 0x368 0x000 0x0 0x0
+#define MX53_PAD_KEY_ROW3__GPIO4_13				0x040 0x368 0x000 0x1 0x0
+#define MX53_PAD_KEY_ROW3__USBOH3_H2_DM				0x040 0x368 0x000 0x2 0x0
+#define MX53_PAD_KEY_ROW3__CCM_ASRC_EXT_CLK			0x040 0x368 0x768 0x3 0x0
+#define MX53_PAD_KEY_ROW3__I2C2_SDA				0x040 0x368 0x820 0x4 0x0
+#define MX53_PAD_KEY_ROW3__OSC32K_32K_OUT			0x040 0x368 0x000 0x5 0x0
+#define MX53_PAD_KEY_ROW3__CCM_PLL4_BYP				0x040 0x368 0x77c 0x6 0x0
+#define MX53_PAD_KEY_ROW3__USBPHY1_LINESTATE_0			0x040 0x368 0x000 0x7 0x0
+#define MX53_PAD_KEY_COL4__KPP_COL_4				0x044 0x36c 0x000 0x0 0x0
+#define MX53_PAD_KEY_COL4__GPIO4_14				0x044 0x36c 0x000 0x1 0x0
+#define MX53_PAD_KEY_COL4__CAN2_TXCAN				0x044 0x36c 0x000 0x2 0x0
+#define MX53_PAD_KEY_COL4__IPU_SISG_4				0x044 0x36c 0x000 0x3 0x0
+#define MX53_PAD_KEY_COL4__UART5_RTS				0x044 0x36c 0x894 0x4 0x0
+#define MX53_PAD_KEY_COL4__USBOH3_USBOTG_OC			0x044 0x36c 0x89c 0x5 0x0
+#define MX53_PAD_KEY_COL4__USBPHY1_LINESTATE_1			0x044 0x36c 0x000 0x7 0x0
+#define MX53_PAD_KEY_ROW4__KPP_ROW_4				0x048 0x370 0x000 0x0 0x0
+#define MX53_PAD_KEY_ROW4__GPIO4_15				0x048 0x370 0x000 0x1 0x0
+#define MX53_PAD_KEY_ROW4__CAN2_RXCAN				0x048 0x370 0x764 0x2 0x0
+#define MX53_PAD_KEY_ROW4__IPU_SISG_5				0x048 0x370 0x000 0x3 0x0
+#define MX53_PAD_KEY_ROW4__UART5_CTS				0x048 0x370 0x000 0x4 0x0
+#define MX53_PAD_KEY_ROW4__USBOH3_USBOTG_PWR			0x048 0x370 0x000 0x5 0x0
+#define MX53_PAD_KEY_ROW4__USBPHY1_VBUSVALID			0x048 0x370 0x000 0x7 0x0
+#define MX53_PAD_DI0_DISP_CLK__IPU_DI0_DISP_CLK			0x04c 0x378 0x000 0x0 0x0
+#define MX53_PAD_DI0_DISP_CLK__GPIO4_16				0x04c 0x378 0x000 0x1 0x0
+#define MX53_PAD_DI0_DISP_CLK__USBOH3_USBH2_DIR			0x04c 0x378 0x000 0x2 0x0
+#define MX53_PAD_DI0_DISP_CLK__SDMA_DEBUG_CORE_STATE_0		0x04c 0x378 0x000 0x5 0x0
+#define MX53_PAD_DI0_DISP_CLK__EMI_EMI_DEBUG_0			0x04c 0x378 0x000 0x6 0x0
+#define MX53_PAD_DI0_DISP_CLK__USBPHY1_AVALID			0x04c 0x378 0x000 0x7 0x0
+#define MX53_PAD_DI0_PIN15__IPU_DI0_PIN15			0x050 0x37c 0x000 0x0 0x0
+#define MX53_PAD_DI0_PIN15__GPIO4_17				0x050 0x37c 0x000 0x1 0x0
+#define MX53_PAD_DI0_PIN15__AUDMUX_AUD6_TXC			0x050 0x37c 0x000 0x2 0x0
+#define MX53_PAD_DI0_PIN15__SDMA_DEBUG_CORE_STATE_1		0x050 0x37c 0x000 0x5 0x0
+#define MX53_PAD_DI0_PIN15__EMI_EMI_DEBUG_1			0x050 0x37c 0x000 0x6 0x0
+#define MX53_PAD_DI0_PIN15__USBPHY1_BVALID			0x050 0x37c 0x000 0x7 0x0
+#define MX53_PAD_DI0_PIN2__IPU_DI0_PIN2				0x054 0x380 0x000 0x0 0x0
+#define MX53_PAD_DI0_PIN2__GPIO4_18				0x054 0x380 0x000 0x1 0x0
+#define MX53_PAD_DI0_PIN2__AUDMUX_AUD6_TXD			0x054 0x380 0x000 0x2 0x0
+#define MX53_PAD_DI0_PIN2__SDMA_DEBUG_CORE_STATE_2		0x054 0x380 0x000 0x5 0x0
+#define MX53_PAD_DI0_PIN2__EMI_EMI_DEBUG_2			0x054 0x380 0x000 0x6 0x0
+#define MX53_PAD_DI0_PIN2__USBPHY1_ENDSESSION			0x054 0x380 0x000 0x7 0x0
+#define MX53_PAD_DI0_PIN3__IPU_DI0_PIN3				0x058 0x384 0x000 0x0 0x0
+#define MX53_PAD_DI0_PIN3__GPIO4_19				0x058 0x384 0x000 0x1 0x0
+#define MX53_PAD_DI0_PIN3__AUDMUX_AUD6_TXFS			0x058 0x384 0x000 0x2 0x0
+#define MX53_PAD_DI0_PIN3__SDMA_DEBUG_CORE_STATE_3		0x058 0x384 0x000 0x5 0x0
+#define MX53_PAD_DI0_PIN3__EMI_EMI_DEBUG_3			0x058 0x384 0x000 0x6 0x0
+#define MX53_PAD_DI0_PIN3__USBPHY1_IDDIG			0x058 0x384 0x000 0x7 0x0
+#define MX53_PAD_DI0_PIN4__IPU_DI0_PIN4				0x05c 0x388 0x000 0x0 0x0
+#define MX53_PAD_DI0_PIN4__GPIO4_20				0x05c 0x388 0x000 0x1 0x0
+#define MX53_PAD_DI0_PIN4__AUDMUX_AUD6_RXD			0x05c 0x388 0x000 0x2 0x0
+#define MX53_PAD_DI0_PIN4__ESDHC1_WP				0x05c 0x388 0x7fc 0x3 0x0
+#define MX53_PAD_DI0_PIN4__SDMA_DEBUG_YIELD			0x05c 0x388 0x000 0x5 0x0
+#define MX53_PAD_DI0_PIN4__EMI_EMI_DEBUG_4			0x05c 0x388 0x000 0x6 0x0
+#define MX53_PAD_DI0_PIN4__USBPHY1_HOSTDISCONNECT		0x05c 0x388 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT0__IPU_DISP0_DAT_0			0x060 0x38c 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT0__GPIO4_21				0x060 0x38c 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT0__CSPI_SCLK				0x060 0x38c 0x780 0x2 0x0
+#define MX53_PAD_DISP0_DAT0__USBOH3_USBH2_DATA_0		0x060 0x38c 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT0__SDMA_DEBUG_CORE_RUN		0x060 0x38c 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT0__EMI_EMI_DEBUG_5			0x060 0x38c 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT0__USBPHY2_TXREADY			0x060 0x38c 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT1__IPU_DISP0_DAT_1			0x064 0x390 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT1__GPIO4_22				0x064 0x390 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT1__CSPI_MOSI				0x064 0x390 0x788 0x2 0x0
+#define MX53_PAD_DISP0_DAT1__USBOH3_USBH2_DATA_1		0x064 0x390 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT1__SDMA_DEBUG_EVENT_CHANNEL_SEL	0x064 0x390 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT1__EMI_EMI_DEBUG_6			0x064 0x390 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT1__USBPHY2_RXVALID			0x064 0x390 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT2__IPU_DISP0_DAT_2			0x068 0x394 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT2__GPIO4_23				0x068 0x394 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT2__CSPI_MISO				0x068 0x394 0x784 0x2 0x0
+#define MX53_PAD_DISP0_DAT2__USBOH3_USBH2_DATA_2		0x068 0x394 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT2__SDMA_DEBUG_MODE			0x068 0x394 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT2__EMI_EMI_DEBUG_7			0x068 0x394 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT2__USBPHY2_RXACTIVE			0x068 0x394 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT3__IPU_DISP0_DAT_3			0x06c 0x398 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT3__GPIO4_24				0x06c 0x398 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT3__CSPI_SS0				0x06c 0x398 0x78c 0x2 0x0
+#define MX53_PAD_DISP0_DAT3__USBOH3_USBH2_DATA_3		0x06c 0x398 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT3__SDMA_DEBUG_BUS_ERROR		0x06c 0x398 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT3__EMI_EMI_DEBUG_8			0x06c 0x398 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT3__USBPHY2_RXERROR			0x06c 0x398 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT4__IPU_DISP0_DAT_4			0x070 0x39c 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT4__GPIO4_25				0x070 0x39c 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT4__CSPI_SS1				0x070 0x39c 0x790 0x2 0x0
+#define MX53_PAD_DISP0_DAT4__USBOH3_USBH2_DATA_4		0x070 0x39c 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT4__SDMA_DEBUG_BUS_RWB			0x070 0x39c 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT4__EMI_EMI_DEBUG_9			0x070 0x39c 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT4__USBPHY2_SIECLOCK			0x070 0x39c 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT5__IPU_DISP0_DAT_5			0x074 0x3a0 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT5__GPIO4_26				0x074 0x3a0 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT5__CSPI_SS2				0x074 0x3a0 0x794 0x2 0x0
+#define MX53_PAD_DISP0_DAT5__USBOH3_USBH2_DATA_5		0x074 0x3a0 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT5__SDMA_DEBUG_MATCHED_DMBUS		0x074 0x3a0 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT5__EMI_EMI_DEBUG_10			0x074 0x3a0 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT5__USBPHY2_LINESTATE_0		0x074 0x3a0 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT6__IPU_DISP0_DAT_6			0x078 0x3a4 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT6__GPIO4_27				0x078 0x3a4 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT6__CSPI_SS3				0x078 0x3a4 0x798 0x2 0x0
+#define MX53_PAD_DISP0_DAT6__USBOH3_USBH2_DATA_6		0x078 0x3a4 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT6__SDMA_DEBUG_RTBUFFER_WRITE		0x078 0x3a4 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT6__EMI_EMI_DEBUG_11			0x078 0x3a4 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT6__USBPHY2_LINESTATE_1		0x078 0x3a4 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT7__IPU_DISP0_DAT_7			0x07c 0x3a8 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT7__GPIO4_28				0x07c 0x3a8 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT7__CSPI_RDY				0x07c 0x3a8 0x000 0x2 0x0
+#define MX53_PAD_DISP0_DAT7__USBOH3_USBH2_DATA_7		0x07c 0x3a8 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT7__SDMA_DEBUG_EVENT_CHANNEL_0		0x07c 0x3a8 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT7__EMI_EMI_DEBUG_12			0x07c 0x3a8 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT7__USBPHY2_VBUSVALID			0x07c 0x3a8 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT8__IPU_DISP0_DAT_8			0x080 0x3ac 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT8__GPIO4_29				0x080 0x3ac 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT8__PWM1_PWMO				0x080 0x3ac 0x000 0x2 0x0
+#define MX53_PAD_DISP0_DAT8__WDOG1_WDOG_B			0x080 0x3ac 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT8__SDMA_DEBUG_EVENT_CHANNEL_1		0x080 0x3ac 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT8__EMI_EMI_DEBUG_13			0x080 0x3ac 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT8__USBPHY2_AVALID			0x080 0x3ac 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT9__IPU_DISP0_DAT_9			0x084 0x3b0 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT9__GPIO4_30				0x084 0x3b0 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT9__PWM2_PWMO				0x084 0x3b0 0x000 0x2 0x0
+#define MX53_PAD_DISP0_DAT9__WDOG2_WDOG_B			0x084 0x3b0 0x000 0x3 0x0
+#define MX53_PAD_DISP0_DAT9__SDMA_DEBUG_EVENT_CHANNEL_2		0x084 0x3b0 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT9__EMI_EMI_DEBUG_14			0x084 0x3b0 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT9__USBPHY2_VSTATUS_0			0x084 0x3b0 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT10__IPU_DISP0_DAT_10			0x088 0x3b4 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT10__GPIO4_31				0x088 0x3b4 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT10__USBOH3_USBH2_STP			0x088 0x3b4 0x000 0x2 0x0
+#define MX53_PAD_DISP0_DAT10__SDMA_DEBUG_EVENT_CHANNEL_3	0x088 0x3b4 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT10__EMI_EMI_DEBUG_15			0x088 0x3b4 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT10__USBPHY2_VSTATUS_1			0x088 0x3b4 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT11__IPU_DISP0_DAT_11			0x08c 0x3b8 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT11__GPIO5_5				0x08c 0x3b8 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT11__USBOH3_USBH2_NXT			0x08c 0x3b8 0x000 0x2 0x0
+#define MX53_PAD_DISP0_DAT11__SDMA_DEBUG_EVENT_CHANNEL_4	0x08c 0x3b8 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT11__EMI_EMI_DEBUG_16			0x08c 0x3b8 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT11__USBPHY2_VSTATUS_2			0x08c 0x3b8 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT12__IPU_DISP0_DAT_12			0x090 0x3bc 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT12__GPIO5_6				0x090 0x3bc 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT12__USBOH3_USBH2_CLK			0x090 0x3bc 0x000 0x2 0x0
+#define MX53_PAD_DISP0_DAT12__SDMA_DEBUG_EVENT_CHANNEL_5	0x090 0x3bc 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT12__EMI_EMI_DEBUG_17			0x090 0x3bc 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT12__USBPHY2_VSTATUS_3			0x090 0x3bc 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT13__IPU_DISP0_DAT_13			0x094 0x3c0 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT13__GPIO5_7				0x094 0x3c0 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT13__AUDMUX_AUD5_RXFS			0x094 0x3c0 0x754 0x3 0x0
+#define MX53_PAD_DISP0_DAT13__SDMA_DEBUG_EVT_CHN_LINES_0	0x094 0x3c0 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT13__EMI_EMI_DEBUG_18			0x094 0x3c0 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT13__USBPHY2_VSTATUS_4			0x094 0x3c0 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT14__IPU_DISP0_DAT_14			0x098 0x3c4 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT14__GPIO5_8				0x098 0x3c4 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT14__AUDMUX_AUD5_RXC			0x098 0x3c4 0x750 0x3 0x0
+#define MX53_PAD_DISP0_DAT14__SDMA_DEBUG_EVT_CHN_LINES_1	0x098 0x3c4 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT14__EMI_EMI_DEBUG_19			0x098 0x3c4 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT14__USBPHY2_VSTATUS_5			0x098 0x3c4 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT15__IPU_DISP0_DAT_15			0x09c 0x3c8 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT15__GPIO5_9				0x09c 0x3c8 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT15__ECSPI1_SS1			0x09c 0x3c8 0x7ac 0x2 0x1
+#define MX53_PAD_DISP0_DAT15__ECSPI2_SS1			0x09c 0x3c8 0x7c8 0x3 0x0
+#define MX53_PAD_DISP0_DAT15__SDMA_DEBUG_EVT_CHN_LINES_2	0x09c 0x3c8 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT15__EMI_EMI_DEBUG_20			0x09c 0x3c8 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT15__USBPHY2_VSTATUS_6			0x09c 0x3c8 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT16__IPU_DISP0_DAT_16			0x0a0 0x3cc 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT16__GPIO5_10				0x0a0 0x3cc 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT16__ECSPI2_MOSI			0x0a0 0x3cc 0x7c0 0x2 0x0
+#define MX53_PAD_DISP0_DAT16__AUDMUX_AUD5_TXC			0x0a0 0x3cc 0x758 0x3 0x1
+#define MX53_PAD_DISP0_DAT16__SDMA_EXT_EVENT_0			0x0a0 0x3cc 0x868 0x4 0x0
+#define MX53_PAD_DISP0_DAT16__SDMA_DEBUG_EVT_CHN_LINES_3	0x0a0 0x3cc 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT16__EMI_EMI_DEBUG_21			0x0a0 0x3cc 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT16__USBPHY2_VSTATUS_7			0x0a0 0x3cc 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT17__IPU_DISP0_DAT_17			0x0a4 0x3d0 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT17__GPIO5_11				0x0a4 0x3d0 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT17__ECSPI2_MISO			0x0a4 0x3d0 0x7bc 0x2 0x0
+#define MX53_PAD_DISP0_DAT17__AUDMUX_AUD5_TXD			0x0a4 0x3d0 0x74c 0x3 0x1
+#define MX53_PAD_DISP0_DAT17__SDMA_EXT_EVENT_1			0x0a4 0x3d0 0x86c 0x4 0x0
+#define MX53_PAD_DISP0_DAT17__SDMA_DEBUG_EVT_CHN_LINES_4	0x0a4 0x3d0 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT17__EMI_EMI_DEBUG_22			0x0a4 0x3d0 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT18__IPU_DISP0_DAT_18			0x0a8 0x3d4 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT18__GPIO5_12				0x0a8 0x3d4 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT18__ECSPI2_SS0			0x0a8 0x3d4 0x7c4 0x2 0x0
+#define MX53_PAD_DISP0_DAT18__AUDMUX_AUD5_TXFS			0x0a8 0x3d4 0x75c 0x3 0x1
+#define MX53_PAD_DISP0_DAT18__AUDMUX_AUD4_RXFS			0x0a8 0x3d4 0x73c 0x4 0x0
+#define MX53_PAD_DISP0_DAT18__SDMA_DEBUG_EVT_CHN_LINES_5	0x0a8 0x3d4 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT18__EMI_EMI_DEBUG_23			0x0a8 0x3d4 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT18__EMI_WEIM_CS_2			0x0a8 0x3d4 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT19__IPU_DISP0_DAT_19			0x0ac 0x3d8 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT19__GPIO5_13				0x0ac 0x3d8 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT19__ECSPI2_SCLK			0x0ac 0x3d8 0x7b8 0x2 0x0
+#define MX53_PAD_DISP0_DAT19__AUDMUX_AUD5_RXD			0x0ac 0x3d8 0x748 0x3 0x1
+#define MX53_PAD_DISP0_DAT19__AUDMUX_AUD4_RXC			0x0ac 0x3d8 0x738 0x4 0x0
+#define MX53_PAD_DISP0_DAT19__SDMA_DEBUG_EVT_CHN_LINES_6	0x0ac 0x3d8 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT19__EMI_EMI_DEBUG_24			0x0ac 0x3d8 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT19__EMI_WEIM_CS_3			0x0ac 0x3d8 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT20__IPU_DISP0_DAT_20			0x0b0 0x3dc 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT20__GPIO5_14				0x0b0 0x3dc 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT20__ECSPI1_SCLK			0x0b0 0x3dc 0x79c 0x2 0x1
+#define MX53_PAD_DISP0_DAT20__AUDMUX_AUD4_TXC			0x0b0 0x3dc 0x740 0x3 0x0
+#define MX53_PAD_DISP0_DAT20__SDMA_DEBUG_EVT_CHN_LINES_7	0x0b0 0x3dc 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT20__EMI_EMI_DEBUG_25			0x0b0 0x3dc 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT20__SATA_PHY_TDI			0x0b0 0x3dc 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT21__IPU_DISP0_DAT_21			0x0b4 0x3e0 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT21__GPIO5_15				0x0b4 0x3e0 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT21__ECSPI1_MOSI			0x0b4 0x3e0 0x7a4 0x2 0x1
+#define MX53_PAD_DISP0_DAT21__AUDMUX_AUD4_TXD			0x0b4 0x3e0 0x734 0x3 0x0
+#define MX53_PAD_DISP0_DAT21__SDMA_DEBUG_BUS_DEVICE_0		0x0b4 0x3e0 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT21__EMI_EMI_DEBUG_26			0x0b4 0x3e0 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT21__SATA_PHY_TDO			0x0b4 0x3e0 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT22__IPU_DISP0_DAT_22			0x0b8 0x3e4 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT22__GPIO5_16				0x0b8 0x3e4 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT22__ECSPI1_MISO			0x0b8 0x3e4 0x7a0 0x2 0x1
+#define MX53_PAD_DISP0_DAT22__AUDMUX_AUD4_TXFS			0x0b8 0x3e4 0x744 0x3 0x0
+#define MX53_PAD_DISP0_DAT22__SDMA_DEBUG_BUS_DEVICE_1		0x0b8 0x3e4 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT22__EMI_EMI_DEBUG_27			0x0b8 0x3e4 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT22__SATA_PHY_TCK			0x0b8 0x3e4 0x000 0x7 0x0
+#define MX53_PAD_DISP0_DAT23__IPU_DISP0_DAT_23			0x0bc 0x3e8 0x000 0x0 0x0
+#define MX53_PAD_DISP0_DAT23__GPIO5_17				0x0bc 0x3e8 0x000 0x1 0x0
+#define MX53_PAD_DISP0_DAT23__ECSPI1_SS0			0x0bc 0x3e8 0x7a8 0x2 0x1
+#define MX53_PAD_DISP0_DAT23__AUDMUX_AUD4_RXD			0x0bc 0x3e8 0x730 0x3 0x0
+#define MX53_PAD_DISP0_DAT23__SDMA_DEBUG_BUS_DEVICE_2		0x0bc 0x3e8 0x000 0x5 0x0
+#define MX53_PAD_DISP0_DAT23__EMI_EMI_DEBUG_28			0x0bc 0x3e8 0x000 0x6 0x0
+#define MX53_PAD_DISP0_DAT23__SATA_PHY_TMS			0x0bc 0x3e8 0x000 0x7 0x0
+#define MX53_PAD_CSI0_PIXCLK__IPU_CSI0_PIXCLK			0x0c0 0x3ec 0x000 0x0 0x0
+#define MX53_PAD_CSI0_PIXCLK__GPIO5_18				0x0c0 0x3ec 0x000 0x1 0x0
+#define MX53_PAD_CSI0_PIXCLK__SDMA_DEBUG_PC_0			0x0c0 0x3ec 0x000 0x5 0x0
+#define MX53_PAD_CSI0_PIXCLK__EMI_EMI_DEBUG_29			0x0c0 0x3ec 0x000 0x6 0x0
+#define MX53_PAD_CSI0_MCLK__IPU_CSI0_HSYNC			0x0c4 0x3f0 0x000 0x0 0x0
+#define MX53_PAD_CSI0_MCLK__GPIO5_19				0x0c4 0x3f0 0x000 0x1 0x0
+#define MX53_PAD_CSI0_MCLK__CCM_CSI0_MCLK			0x0c4 0x3f0 0x000 0x2 0x0
+#define MX53_PAD_CSI0_MCLK__SDMA_DEBUG_PC_1			0x0c4 0x3f0 0x000 0x5 0x0
+#define MX53_PAD_CSI0_MCLK__EMI_EMI_DEBUG_30			0x0c4 0x3f0 0x000 0x6 0x0
+#define MX53_PAD_CSI0_MCLK__TPIU_TRCTL				0x0c4 0x3f0 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DATA_EN__IPU_CSI0_DATA_EN			0x0c8 0x3f4 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DATA_EN__GPIO5_20				0x0c8 0x3f4 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DATA_EN__SDMA_DEBUG_PC_2			0x0c8 0x3f4 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DATA_EN__EMI_EMI_DEBUG_31			0x0c8 0x3f4 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DATA_EN__TPIU_TRCLK			0x0c8 0x3f4 0x000 0x7 0x0
+#define MX53_PAD_CSI0_VSYNC__IPU_CSI0_VSYNC			0x0cc 0x3f8 0x000 0x0 0x0
+#define MX53_PAD_CSI0_VSYNC__GPIO5_21				0x0cc 0x3f8 0x000 0x1 0x0
+#define MX53_PAD_CSI0_VSYNC__SDMA_DEBUG_PC_3			0x0cc 0x3f8 0x000 0x5 0x0
+#define MX53_PAD_CSI0_VSYNC__EMI_EMI_DEBUG_32			0x0cc 0x3f8 0x000 0x6 0x0
+#define MX53_PAD_CSI0_VSYNC__TPIU_TRACE_0			0x0cc 0x3f8 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT4__IPU_CSI0_D_4			0x0d0 0x3fc 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT4__GPIO5_22				0x0d0 0x3fc 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT4__KPP_COL_5				0x0d0 0x3fc 0x840 0x2 0x1
+#define MX53_PAD_CSI0_DAT4__ECSPI1_SCLK				0x0d0 0x3fc 0x79c 0x3 0x2
+#define MX53_PAD_CSI0_DAT4__USBOH3_USBH3_STP			0x0d0 0x3fc 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT4__AUDMUX_AUD3_TXC			0x0d0 0x3fc 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT4__EMI_EMI_DEBUG_33			0x0d0 0x3fc 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT4__TPIU_TRACE_1			0x0d0 0x3fc 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT5__IPU_CSI0_D_5			0x0d4 0x400 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT5__GPIO5_23				0x0d4 0x400 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT5__KPP_ROW_5				0x0d4 0x400 0x84c 0x2 0x0
+#define MX53_PAD_CSI0_DAT5__ECSPI1_MOSI				0x0d4 0x400 0x7a4 0x3 0x2
+#define MX53_PAD_CSI0_DAT5__USBOH3_USBH3_NXT			0x0d4 0x400 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT5__AUDMUX_AUD3_TXD			0x0d4 0x400 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT5__EMI_EMI_DEBUG_34			0x0d4 0x400 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT5__TPIU_TRACE_2			0x0d4 0x400 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT6__IPU_CSI0_D_6			0x0d8 0x404 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT6__GPIO5_24				0x0d8 0x404 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT6__KPP_COL_6				0x0d8 0x404 0x844 0x2 0x0
+#define MX53_PAD_CSI0_DAT6__ECSPI1_MISO				0x0d8 0x404 0x7a0 0x3 0x2
+#define MX53_PAD_CSI0_DAT6__USBOH3_USBH3_CLK			0x0d8 0x404 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT6__AUDMUX_AUD3_TXFS			0x0d8 0x404 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT6__EMI_EMI_DEBUG_35			0x0d8 0x404 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT6__TPIU_TRACE_3			0x0d8 0x404 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT7__IPU_CSI0_D_7			0x0dc 0x408 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT7__GPIO5_25				0x0dc 0x408 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT7__KPP_ROW_6				0x0dc 0x408 0x850 0x2 0x0
+#define MX53_PAD_CSI0_DAT7__ECSPI1_SS0				0x0dc 0x408 0x7a8 0x3 0x2
+#define MX53_PAD_CSI0_DAT7__USBOH3_USBH3_DIR			0x0dc 0x408 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT7__AUDMUX_AUD3_RXD			0x0dc 0x408 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT7__EMI_EMI_DEBUG_36			0x0dc 0x408 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT7__TPIU_TRACE_4			0x0dc 0x408 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT8__IPU_CSI0_D_8			0x0e0 0x40c 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT8__GPIO5_26				0x0e0 0x40c 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT8__KPP_COL_7				0x0e0 0x40c 0x848 0x2 0x0
+#define MX53_PAD_CSI0_DAT8__ECSPI2_SCLK				0x0e0 0x40c 0x7b8 0x3 0x1
+#define MX53_PAD_CSI0_DAT8__USBOH3_USBH3_OC			0x0e0 0x40c 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT8__I2C1_SDA				0x0e0 0x40c 0x818 0x5 0x0
+#define MX53_PAD_CSI0_DAT8__EMI_EMI_DEBUG_37			0x0e0 0x40c 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT8__TPIU_TRACE_5			0x0e0 0x40c 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT9__IPU_CSI0_D_9			0x0e4 0x410 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT9__GPIO5_27				0x0e4 0x410 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT9__KPP_ROW_7				0x0e4 0x410 0x854 0x2 0x0
+#define MX53_PAD_CSI0_DAT9__ECSPI2_MOSI				0x0e4 0x410 0x7c0 0x3 0x1
+#define MX53_PAD_CSI0_DAT9__USBOH3_USBH3_PWR			0x0e4 0x410 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT9__I2C1_SCL				0x0e4 0x410 0x814 0x5 0x0
+#define MX53_PAD_CSI0_DAT9__EMI_EMI_DEBUG_38			0x0e4 0x410 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT9__TPIU_TRACE_6			0x0e4 0x410 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT10__IPU_CSI0_D_10			0x0e8 0x414 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT10__GPIO5_28				0x0e8 0x414 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT10__UART1_TXD_MUX			0x0e8 0x414 0x000 0x2 0x0
+#define MX53_PAD_CSI0_DAT10__ECSPI2_MISO			0x0e8 0x414 0x7bc 0x3 0x1
+#define MX53_PAD_CSI0_DAT10__AUDMUX_AUD3_RXC			0x0e8 0x414 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT10__SDMA_DEBUG_PC_4			0x0e8 0x414 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT10__EMI_EMI_DEBUG_39			0x0e8 0x414 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT10__TPIU_TRACE_7			0x0e8 0x414 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT11__IPU_CSI0_D_11			0x0ec 0x418 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT11__GPIO5_29				0x0ec 0x418 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT11__UART1_RXD_MUX			0x0ec 0x418 0x878 0x2 0x1
+#define MX53_PAD_CSI0_DAT11__ECSPI2_SS0				0x0ec 0x418 0x7c4 0x3 0x1
+#define MX53_PAD_CSI0_DAT11__AUDMUX_AUD3_RXFS			0x0ec 0x418 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT11__SDMA_DEBUG_PC_5			0x0ec 0x418 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT11__EMI_EMI_DEBUG_40			0x0ec 0x418 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT11__TPIU_TRACE_8			0x0ec 0x418 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT12__IPU_CSI0_D_12			0x0f0 0x41c 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT12__GPIO5_30				0x0f0 0x41c 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT12__UART4_TXD_MUX			0x0f0 0x41c 0x000 0x2 0x0
+#define MX53_PAD_CSI0_DAT12__USBOH3_USBH3_DATA_0		0x0f0 0x41c 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT12__SDMA_DEBUG_PC_6			0x0f0 0x41c 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT12__EMI_EMI_DEBUG_41			0x0f0 0x41c 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT12__TPIU_TRACE_9			0x0f0 0x41c 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT13__IPU_CSI0_D_13			0x0f4 0x420 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT13__GPIO5_31				0x0f4 0x420 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT13__UART4_RXD_MUX			0x0f4 0x420 0x890 0x2 0x3
+#define MX53_PAD_CSI0_DAT13__USBOH3_USBH3_DATA_1		0x0f4 0x420 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT13__SDMA_DEBUG_PC_7			0x0f4 0x420 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT13__EMI_EMI_DEBUG_42			0x0f4 0x420 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT13__TPIU_TRACE_10			0x0f4 0x420 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT14__IPU_CSI0_D_14			0x0f8 0x424 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT14__GPIO6_0				0x0f8 0x424 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT14__UART5_TXD_MUX			0x0f8 0x424 0x000 0x2 0x0
+#define MX53_PAD_CSI0_DAT14__USBOH3_USBH3_DATA_2		0x0f8 0x424 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT14__SDMA_DEBUG_PC_8			0x0f8 0x424 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT14__EMI_EMI_DEBUG_43			0x0f8 0x424 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT14__TPIU_TRACE_11			0x0f8 0x424 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT15__IPU_CSI0_D_15			0x0fc 0x428 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT15__GPIO6_1				0x0fc 0x428 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT15__UART5_RXD_MUX			0x0fc 0x428 0x898 0x2 0x3
+#define MX53_PAD_CSI0_DAT15__USBOH3_USBH3_DATA_3		0x0fc 0x428 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT15__SDMA_DEBUG_PC_9			0x0fc 0x428 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT15__EMI_EMI_DEBUG_44			0x0fc 0x428 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT15__TPIU_TRACE_12			0x0fc 0x428 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT16__IPU_CSI0_D_16			0x100 0x42c 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT16__GPIO6_2				0x100 0x42c 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT16__UART4_RTS				0x100 0x42c 0x88c 0x2 0x0
+#define MX53_PAD_CSI0_DAT16__USBOH3_USBH3_DATA_4		0x100 0x42c 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT16__SDMA_DEBUG_PC_10			0x100 0x42c 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT16__EMI_EMI_DEBUG_45			0x100 0x42c 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT16__TPIU_TRACE_13			0x100 0x42c 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT17__IPU_CSI0_D_17			0x104 0x430 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT17__GPIO6_3				0x104 0x430 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT17__UART4_CTS				0x104 0x430 0x000 0x2 0x0
+#define MX53_PAD_CSI0_DAT17__USBOH3_USBH3_DATA_5		0x104 0x430 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT17__SDMA_DEBUG_PC_11			0x104 0x430 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT17__EMI_EMI_DEBUG_46			0x104 0x430 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT17__TPIU_TRACE_14			0x104 0x430 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT18__IPU_CSI0_D_18			0x108 0x434 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT18__GPIO6_4				0x108 0x434 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT18__UART5_RTS				0x108 0x434 0x894 0x2 0x2
+#define MX53_PAD_CSI0_DAT18__USBOH3_USBH3_DATA_6		0x108 0x434 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT18__SDMA_DEBUG_PC_12			0x108 0x434 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT18__EMI_EMI_DEBUG_47			0x108 0x434 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT18__TPIU_TRACE_15			0x108 0x434 0x000 0x7 0x0
+#define MX53_PAD_CSI0_DAT19__IPU_CSI0_D_19			0x10c 0x438 0x000 0x0 0x0
+#define MX53_PAD_CSI0_DAT19__GPIO6_5				0x10c 0x438 0x000 0x1 0x0
+#define MX53_PAD_CSI0_DAT19__UART5_CTS				0x10c 0x438 0x000 0x2 0x0
+#define MX53_PAD_CSI0_DAT19__USBOH3_USBH3_DATA_7		0x10c 0x438 0x000 0x4 0x0
+#define MX53_PAD_CSI0_DAT19__SDMA_DEBUG_PC_13			0x10c 0x438 0x000 0x5 0x0
+#define MX53_PAD_CSI0_DAT19__EMI_EMI_DEBUG_48			0x10c 0x438 0x000 0x6 0x0
+#define MX53_PAD_CSI0_DAT19__USBPHY2_BISTOK			0x10c 0x438 0x000 0x7 0x0
+#define MX53_PAD_EIM_A25__EMI_WEIM_A_25				0x110 0x458 0x000 0x0 0x0
+#define MX53_PAD_EIM_A25__GPIO5_2				0x110 0x458 0x000 0x1 0x0
+#define MX53_PAD_EIM_A25__ECSPI2_RDY				0x110 0x458 0x000 0x2 0x0
+#define MX53_PAD_EIM_A25__IPU_DI1_PIN12				0x110 0x458 0x000 0x3 0x0
+#define MX53_PAD_EIM_A25__CSPI_SS1				0x110 0x458 0x790 0x4 0x1
+#define MX53_PAD_EIM_A25__IPU_DI0_D1_CS				0x110 0x458 0x000 0x6 0x0
+#define MX53_PAD_EIM_A25__USBPHY1_BISTOK			0x110 0x458 0x000 0x7 0x0
+#define MX53_PAD_EIM_EB2__EMI_WEIM_EB_2				0x114 0x45c 0x000 0x0 0x0
+#define MX53_PAD_EIM_EB2__GPIO2_30				0x114 0x45c 0x000 0x1 0x0
+#define MX53_PAD_EIM_EB2__CCM_DI1_EXT_CLK			0x114 0x45c 0x76c 0x2 0x0
+#define MX53_PAD_EIM_EB2__IPU_SER_DISP1_CS			0x114 0x45c 0x000 0x3 0x0
+#define MX53_PAD_EIM_EB2__ECSPI1_SS0				0x114 0x45c 0x7a8 0x4 0x3
+#define MX53_PAD_EIM_EB2__I2C2_SCL				0x114 0x45c 0x81c 0x5 0x1
+#define MX53_PAD_EIM_D16__EMI_WEIM_D_16				0x118 0x460 0x000 0x0 0x0
+#define MX53_PAD_EIM_D16__GPIO3_16				0x118 0x460 0x000 0x1 0x0
+#define MX53_PAD_EIM_D16__IPU_DI0_PIN5				0x118 0x460 0x000 0x2 0x0
+#define MX53_PAD_EIM_D16__IPU_DISPB1_SER_CLK			0x118 0x460 0x000 0x3 0x0
+#define MX53_PAD_EIM_D16__ECSPI1_SCLK				0x118 0x460 0x79c 0x4 0x3
+#define MX53_PAD_EIM_D16__I2C2_SDA				0x118 0x460 0x820 0x5 0x1
+#define MX53_PAD_EIM_D17__EMI_WEIM_D_17				0x11c 0x464 0x000 0x0 0x0
+#define MX53_PAD_EIM_D17__GPIO3_17				0x11c 0x464 0x000 0x1 0x0
+#define MX53_PAD_EIM_D17__IPU_DI0_PIN6				0x11c 0x464 0x000 0x2 0x0
+#define MX53_PAD_EIM_D17__IPU_DISPB1_SER_DIN			0x11c 0x464 0x830 0x3 0x0
+#define MX53_PAD_EIM_D17__ECSPI1_MISO				0x11c 0x464 0x7a0 0x4 0x3
+#define MX53_PAD_EIM_D17__I2C3_SCL				0x11c 0x464 0x824 0x5 0x0
+#define MX53_PAD_EIM_D18__EMI_WEIM_D_18				0x120 0x468 0x000 0x0 0x0
+#define MX53_PAD_EIM_D18__GPIO3_18				0x120 0x468 0x000 0x1 0x0
+#define MX53_PAD_EIM_D18__IPU_DI0_PIN7				0x120 0x468 0x000 0x2 0x0
+#define MX53_PAD_EIM_D18__IPU_DISPB1_SER_DIO			0x120 0x468 0x830 0x3 0x1
+#define MX53_PAD_EIM_D18__ECSPI1_MOSI				0x120 0x468 0x7a4 0x4 0x3
+#define MX53_PAD_EIM_D18__I2C3_SDA				0x120 0x468 0x828 0x5 0x0
+#define MX53_PAD_EIM_D18__IPU_DI1_D0_CS				0x120 0x468 0x000 0x6 0x0
+#define MX53_PAD_EIM_D19__EMI_WEIM_D_19				0x124 0x46c 0x000 0x0 0x0
+#define MX53_PAD_EIM_D19__GPIO3_19				0x124 0x46c 0x000 0x1 0x0
+#define MX53_PAD_EIM_D19__IPU_DI0_PIN8				0x124 0x46c 0x000 0x2 0x0
+#define MX53_PAD_EIM_D19__IPU_DISPB1_SER_RS			0x124 0x46c 0x000 0x3 0x0
+#define MX53_PAD_EIM_D19__ECSPI1_SS1				0x124 0x46c 0x7ac 0x4 0x2
+#define MX53_PAD_EIM_D19__EPIT1_EPITO				0x124 0x46c 0x000 0x5 0x0
+#define MX53_PAD_EIM_D19__UART1_CTS				0x124 0x46c 0x000 0x6 0x0
+#define MX53_PAD_EIM_D19__USBOH3_USBH2_OC			0x124 0x46c 0x8a4 0x7 0x0
+#define MX53_PAD_EIM_D20__EMI_WEIM_D_20				0x128 0x470 0x000 0x0 0x0
+#define MX53_PAD_EIM_D20__GPIO3_20				0x128 0x470 0x000 0x1 0x0
+#define MX53_PAD_EIM_D20__IPU_DI0_PIN16				0x128 0x470 0x000 0x2 0x0
+#define MX53_PAD_EIM_D20__IPU_SER_DISP0_CS			0x128 0x470 0x000 0x3 0x0
+#define MX53_PAD_EIM_D20__CSPI_SS0				0x128 0x470 0x78c 0x4 0x1
+#define MX53_PAD_EIM_D20__EPIT2_EPITO				0x128 0x470 0x000 0x5 0x0
+#define MX53_PAD_EIM_D20__UART1_RTS				0x128 0x470 0x874 0x6 0x1
+#define MX53_PAD_EIM_D20__USBOH3_USBH2_PWR			0x128 0x470 0x000 0x7 0x0
+#define MX53_PAD_EIM_D21__EMI_WEIM_D_21				0x12c 0x474 0x000 0x0 0x0
+#define MX53_PAD_EIM_D21__GPIO3_21				0x12c 0x474 0x000 0x1 0x0
+#define MX53_PAD_EIM_D21__IPU_DI0_PIN17				0x12c 0x474 0x000 0x2 0x0
+#define MX53_PAD_EIM_D21__IPU_DISPB0_SER_CLK			0x12c 0x474 0x000 0x3 0x0
+#define MX53_PAD_EIM_D21__CSPI_SCLK				0x12c 0x474 0x780 0x4 0x1
+#define MX53_PAD_EIM_D21__I2C1_SCL				0x12c 0x474 0x814 0x5 0x1
+#define MX53_PAD_EIM_D21__USBOH3_USBOTG_OC			0x12c 0x474 0x89c 0x6 0x1
+#define MX53_PAD_EIM_D22__EMI_WEIM_D_22				0x130 0x478 0x000 0x0 0x0
+#define MX53_PAD_EIM_D22__GPIO3_22				0x130 0x478 0x000 0x1 0x0
+#define MX53_PAD_EIM_D22__IPU_DI0_PIN1				0x130 0x478 0x000 0x2 0x0
+#define MX53_PAD_EIM_D22__IPU_DISPB0_SER_DIN			0x130 0x478 0x82c 0x3 0x0
+#define MX53_PAD_EIM_D22__CSPI_MISO				0x130 0x478 0x784 0x4 0x1
+#define MX53_PAD_EIM_D22__USBOH3_USBOTG_PWR			0x130 0x478 0x000 0x6 0x0
+#define MX53_PAD_EIM_D23__EMI_WEIM_D_23				0x134 0x47c 0x000 0x0 0x0
+#define MX53_PAD_EIM_D23__GPIO3_23				0x134 0x47c 0x000 0x1 0x0
+#define MX53_PAD_EIM_D23__UART3_CTS				0x134 0x47c 0x000 0x2 0x0
+#define MX53_PAD_EIM_D23__UART1_DCD				0x134 0x47c 0x000 0x3 0x0
+#define MX53_PAD_EIM_D23__IPU_DI0_D0_CS				0x134 0x47c 0x000 0x4 0x0
+#define MX53_PAD_EIM_D23__IPU_DI1_PIN2				0x134 0x47c 0x000 0x5 0x0
+#define MX53_PAD_EIM_D23__IPU_CSI1_DATA_EN			0x134 0x47c 0x834 0x6 0x0
+#define MX53_PAD_EIM_D23__IPU_DI1_PIN14				0x134 0x47c 0x000 0x7 0x0
+#define MX53_PAD_EIM_EB3__EMI_WEIM_EB_3				0x138 0x480 0x000 0x0 0x0
+#define MX53_PAD_EIM_EB3__GPIO2_31				0x138 0x480 0x000 0x1 0x0
+#define MX53_PAD_EIM_EB3__UART3_RTS				0x138 0x480 0x884 0x2 0x1
+#define MX53_PAD_EIM_EB3__UART1_RI				0x138 0x480 0x000 0x3 0x0
+#define MX53_PAD_EIM_EB3__IPU_DI1_PIN3				0x138 0x480 0x000 0x5 0x0
+#define MX53_PAD_EIM_EB3__IPU_CSI1_HSYNC			0x138 0x480 0x838 0x6 0x0
+#define MX53_PAD_EIM_EB3__IPU_DI1_PIN16				0x138 0x480 0x000 0x7 0x0
+#define MX53_PAD_EIM_D24__EMI_WEIM_D_24				0x13c 0x484 0x000 0x0 0x0
+#define MX53_PAD_EIM_D24__GPIO3_24				0x13c 0x484 0x000 0x1 0x0
+#define MX53_PAD_EIM_D24__UART3_TXD_MUX				0x13c 0x484 0x000 0x2 0x0
+#define MX53_PAD_EIM_D24__ECSPI1_SS2				0x13c 0x484 0x7b0 0x3 0x1
+#define MX53_PAD_EIM_D24__CSPI_SS2				0x13c 0x484 0x794 0x4 0x1
+#define MX53_PAD_EIM_D24__AUDMUX_AUD5_RXFS			0x13c 0x484 0x754 0x5 0x1
+#define MX53_PAD_EIM_D24__ECSPI2_SS2				0x13c 0x484 0x000 0x6 0x0
+#define MX53_PAD_EIM_D24__UART1_DTR				0x13c 0x484 0x000 0x7 0x0
+#define MX53_PAD_EIM_D25__EMI_WEIM_D_25				0x140 0x488 0x000 0x0 0x0
+#define MX53_PAD_EIM_D25__GPIO3_25				0x140 0x488 0x000 0x1 0x0
+#define MX53_PAD_EIM_D25__UART3_RXD_MUX				0x140 0x488 0x888 0x2 0x1
+#define MX53_PAD_EIM_D25__ECSPI1_SS3				0x140 0x488 0x7b4 0x3 0x1
+#define MX53_PAD_EIM_D25__CSPI_SS3				0x140 0x488 0x798 0x4 0x1
+#define MX53_PAD_EIM_D25__AUDMUX_AUD5_RXC			0x140 0x488 0x750 0x5 0x1
+#define MX53_PAD_EIM_D25__ECSPI2_SS3				0x140 0x488 0x000 0x6 0x0
+#define MX53_PAD_EIM_D25__UART1_DSR				0x140 0x488 0x000 0x7 0x0
+#define MX53_PAD_EIM_D26__EMI_WEIM_D_26				0x144 0x48c 0x000 0x0 0x0
+#define MX53_PAD_EIM_D26__GPIO3_26				0x144 0x48c 0x000 0x1 0x0
+#define MX53_PAD_EIM_D26__UART2_TXD_MUX				0x144 0x48c 0x000 0x2 0x0
+#define MX53_PAD_EIM_D26__FIRI_RXD				0x144 0x48c 0x80c 0x3 0x0
+#define MX53_PAD_EIM_D26__IPU_CSI0_D_1				0x144 0x48c 0x000 0x4 0x0
+#define MX53_PAD_EIM_D26__IPU_DI1_PIN11				0x144 0x48c 0x000 0x5 0x0
+#define MX53_PAD_EIM_D26__IPU_SISG_2				0x144 0x48c 0x000 0x6 0x0
+#define MX53_PAD_EIM_D26__IPU_DISP1_DAT_22			0x144 0x48c 0x000 0x7 0x0
+#define MX53_PAD_EIM_D27__EMI_WEIM_D_27				0x148 0x490 0x000 0x0 0x0
+#define MX53_PAD_EIM_D27__GPIO3_27				0x148 0x490 0x000 0x1 0x0
+#define MX53_PAD_EIM_D27__UART2_RXD_MUX				0x148 0x490 0x880 0x2 0x1
+#define MX53_PAD_EIM_D27__FIRI_TXD				0x148 0x490 0x000 0x3 0x0
+#define MX53_PAD_EIM_D27__IPU_CSI0_D_0				0x148 0x490 0x000 0x4 0x0
+#define MX53_PAD_EIM_D27__IPU_DI1_PIN13				0x148 0x490 0x000 0x5 0x0
+#define MX53_PAD_EIM_D27__IPU_SISG_3				0x148 0x490 0x000 0x6 0x0
+#define MX53_PAD_EIM_D27__IPU_DISP1_DAT_23			0x148 0x490 0x000 0x7 0x0
+#define MX53_PAD_EIM_D28__EMI_WEIM_D_28				0x14c 0x494 0x000 0x0 0x0
+#define MX53_PAD_EIM_D28__GPIO3_28				0x14c 0x494 0x000 0x1 0x0
+#define MX53_PAD_EIM_D28__UART2_CTS				0x14c 0x494 0x000 0x2 0x0
+#define MX53_PAD_EIM_D28__IPU_DISPB0_SER_DIO			0x14c 0x494 0x82c 0x3 0x1
+#define MX53_PAD_EIM_D28__CSPI_MOSI				0x14c 0x494 0x788 0x4 0x1
+#define MX53_PAD_EIM_D28__I2C1_SDA				0x14c 0x494 0x818 0x5 0x1
+#define MX53_PAD_EIM_D28__IPU_EXT_TRIG				0x14c 0x494 0x000 0x6 0x0
+#define MX53_PAD_EIM_D28__IPU_DI0_PIN13				0x14c 0x494 0x000 0x7 0x0
+#define MX53_PAD_EIM_D29__EMI_WEIM_D_29				0x150 0x498 0x000 0x0 0x0
+#define MX53_PAD_EIM_D29__GPIO3_29				0x150 0x498 0x000 0x1 0x0
+#define MX53_PAD_EIM_D29__UART2_RTS				0x150 0x498 0x87c 0x2 0x1
+#define MX53_PAD_EIM_D29__IPU_DISPB0_SER_RS			0x150 0x498 0x000 0x3 0x0
+#define MX53_PAD_EIM_D29__CSPI_SS0				0x150 0x498 0x78c 0x4 0x2
+#define MX53_PAD_EIM_D29__IPU_DI1_PIN15				0x150 0x498 0x000 0x5 0x0
+#define MX53_PAD_EIM_D29__IPU_CSI1_VSYNC			0x150 0x498 0x83c 0x6 0x0
+#define MX53_PAD_EIM_D29__IPU_DI0_PIN14				0x150 0x498 0x000 0x7 0x0
+#define MX53_PAD_EIM_D30__EMI_WEIM_D_30				0x154 0x49c 0x000 0x0 0x0
+#define MX53_PAD_EIM_D30__GPIO3_30				0x154 0x49c 0x000 0x1 0x0
+#define MX53_PAD_EIM_D30__UART3_CTS				0x154 0x49c 0x000 0x2 0x0
+#define MX53_PAD_EIM_D30__IPU_CSI0_D_3				0x154 0x49c 0x000 0x3 0x0
+#define MX53_PAD_EIM_D30__IPU_DI0_PIN11				0x154 0x49c 0x000 0x4 0x0
+#define MX53_PAD_EIM_D30__IPU_DISP1_DAT_21			0x154 0x49c 0x000 0x5 0x0
+#define MX53_PAD_EIM_D30__USBOH3_USBH1_OC			0x154 0x49c 0x8a0 0x6 0x0
+#define MX53_PAD_EIM_D30__USBOH3_USBH2_OC			0x154 0x49c 0x8a4 0x7 0x1
+#define MX53_PAD_EIM_D31__EMI_WEIM_D_31				0x158 0x4a0 0x000 0x0 0x0
+#define MX53_PAD_EIM_D31__GPIO3_31				0x158 0x4a0 0x000 0x1 0x0
+#define MX53_PAD_EIM_D31__UART3_RTS				0x158 0x4a0 0x884 0x2 0x3
+#define MX53_PAD_EIM_D31__IPU_CSI0_D_2				0x158 0x4a0 0x000 0x3 0x0
+#define MX53_PAD_EIM_D31__IPU_DI0_PIN12				0x158 0x4a0 0x000 0x4 0x0
+#define MX53_PAD_EIM_D31__IPU_DISP1_DAT_20			0x158 0x4a0 0x000 0x5 0x0
+#define MX53_PAD_EIM_D31__USBOH3_USBH1_PWR			0x158 0x4a0 0x000 0x6 0x0
+#define MX53_PAD_EIM_D31__USBOH3_USBH2_PWR			0x158 0x4a0 0x000 0x7 0x0
+#define MX53_PAD_EIM_A24__EMI_WEIM_A_24				0x15c 0x4a8 0x000 0x0 0x0
+#define MX53_PAD_EIM_A24__GPIO5_4				0x15c 0x4a8 0x000 0x1 0x0
+#define MX53_PAD_EIM_A24__IPU_DISP1_DAT_19			0x15c 0x4a8 0x000 0x2 0x0
+#define MX53_PAD_EIM_A24__IPU_CSI1_D_19				0x15c 0x4a8 0x000 0x3 0x0
+#define MX53_PAD_EIM_A24__IPU_SISG_2				0x15c 0x4a8 0x000 0x6 0x0
+#define MX53_PAD_EIM_A24__USBPHY2_BVALID			0x15c 0x4a8 0x000 0x7 0x0
+#define MX53_PAD_EIM_A23__EMI_WEIM_A_23				0x160 0x4ac 0x000 0x0 0x0
+#define MX53_PAD_EIM_A23__GPIO6_6				0x160 0x4ac 0x000 0x1 0x0
+#define MX53_PAD_EIM_A23__IPU_DISP1_DAT_18			0x160 0x4ac 0x000 0x2 0x0
+#define MX53_PAD_EIM_A23__IPU_CSI1_D_18				0x160 0x4ac 0x000 0x3 0x0
+#define MX53_PAD_EIM_A23__IPU_SISG_3				0x160 0x4ac 0x000 0x6 0x0
+#define MX53_PAD_EIM_A23__USBPHY2_ENDSESSION			0x160 0x4ac 0x000 0x7 0x0
+#define MX53_PAD_EIM_A22__EMI_WEIM_A_22				0x164 0x4b0 0x000 0x0 0x0
+#define MX53_PAD_EIM_A22__GPIO2_16				0x164 0x4b0 0x000 0x1 0x0
+#define MX53_PAD_EIM_A22__IPU_DISP1_DAT_17			0x164 0x4b0 0x000 0x2 0x0
+#define MX53_PAD_EIM_A22__IPU_CSI1_D_17				0x164 0x4b0 0x000 0x3 0x0
+#define MX53_PAD_EIM_A22__SRC_BT_CFG1_7				0x164 0x4b0 0x000 0x7 0x0
+#define MX53_PAD_EIM_A21__EMI_WEIM_A_21				0x168 0x4b4 0x000 0x0 0x0
+#define MX53_PAD_EIM_A21__GPIO2_17				0x168 0x4b4 0x000 0x1 0x0
+#define MX53_PAD_EIM_A21__IPU_DISP1_DAT_16			0x168 0x4b4 0x000 0x2 0x0
+#define MX53_PAD_EIM_A21__IPU_CSI1_D_16				0x168 0x4b4 0x000 0x3 0x0
+#define MX53_PAD_EIM_A21__SRC_BT_CFG1_6				0x168 0x4b4 0x000 0x7 0x0
+#define MX53_PAD_EIM_A20__EMI_WEIM_A_20				0x16c 0x4b8 0x000 0x0 0x0
+#define MX53_PAD_EIM_A20__GPIO2_18				0x16c 0x4b8 0x000 0x1 0x0
+#define MX53_PAD_EIM_A20__IPU_DISP1_DAT_15			0x16c 0x4b8 0x000 0x2 0x0
+#define MX53_PAD_EIM_A20__IPU_CSI1_D_15				0x16c 0x4b8 0x000 0x3 0x0
+#define MX53_PAD_EIM_A20__SRC_BT_CFG1_5				0x16c 0x4b8 0x000 0x7 0x0
+#define MX53_PAD_EIM_A19__EMI_WEIM_A_19				0x170 0x4bc 0x000 0x0 0x0
+#define MX53_PAD_EIM_A19__GPIO2_19				0x170 0x4bc 0x000 0x1 0x0
+#define MX53_PAD_EIM_A19__IPU_DISP1_DAT_14			0x170 0x4bc 0x000 0x2 0x0
+#define MX53_PAD_EIM_A19__IPU_CSI1_D_14				0x170 0x4bc 0x000 0x3 0x0
+#define MX53_PAD_EIM_A19__SRC_BT_CFG1_4				0x170 0x4bc 0x000 0x7 0x0
+#define MX53_PAD_EIM_A18__EMI_WEIM_A_18				0x174 0x4c0 0x000 0x0 0x0
+#define MX53_PAD_EIM_A18__GPIO2_20				0x174 0x4c0 0x000 0x1 0x0
+#define MX53_PAD_EIM_A18__IPU_DISP1_DAT_13			0x174 0x4c0 0x000 0x2 0x0
+#define MX53_PAD_EIM_A18__IPU_CSI1_D_13				0x174 0x4c0 0x000 0x3 0x0
+#define MX53_PAD_EIM_A18__SRC_BT_CFG1_3				0x174 0x4c0 0x000 0x7 0x0
+#define MX53_PAD_EIM_A17__EMI_WEIM_A_17				0x178 0x4c4 0x000 0x0 0x0
+#define MX53_PAD_EIM_A17__GPIO2_21				0x178 0x4c4 0x000 0x1 0x0
+#define MX53_PAD_EIM_A17__IPU_DISP1_DAT_12			0x178 0x4c4 0x000 0x2 0x0
+#define MX53_PAD_EIM_A17__IPU_CSI1_D_12				0x178 0x4c4 0x000 0x3 0x0
+#define MX53_PAD_EIM_A17__SRC_BT_CFG1_2				0x178 0x4c4 0x000 0x7 0x0
+#define MX53_PAD_EIM_A16__EMI_WEIM_A_16				0x17c 0x4c8 0x000 0x0 0x0
+#define MX53_PAD_EIM_A16__GPIO2_22				0x17c 0x4c8 0x000 0x1 0x0
+#define MX53_PAD_EIM_A16__IPU_DI1_DISP_CLK			0x17c 0x4c8 0x000 0x2 0x0
+#define MX53_PAD_EIM_A16__IPU_CSI1_PIXCLK			0x17c 0x4c8 0x000 0x3 0x0
+#define MX53_PAD_EIM_A16__SRC_BT_CFG1_1				0x17c 0x4c8 0x000 0x7 0x0
+#define MX53_PAD_EIM_CS0__EMI_WEIM_CS_0				0x180 0x4cc 0x000 0x0 0x0
+#define MX53_PAD_EIM_CS0__GPIO2_23				0x180 0x4cc 0x000 0x1 0x0
+#define MX53_PAD_EIM_CS0__ECSPI2_SCLK				0x180 0x4cc 0x7b8 0x2 0x2
+#define MX53_PAD_EIM_CS0__IPU_DI1_PIN5				0x180 0x4cc 0x000 0x3 0x0
+#define MX53_PAD_EIM_CS1__EMI_WEIM_CS_1				0x184 0x4d0 0x000 0x0 0x0
+#define MX53_PAD_EIM_CS1__GPIO2_24				0x184 0x4d0 0x000 0x1 0x0
+#define MX53_PAD_EIM_CS1__ECSPI2_MOSI				0x184 0x4d0 0x7c0 0x2 0x2
+#define MX53_PAD_EIM_CS1__IPU_DI1_PIN6				0x184 0x4d0 0x000 0x3 0x0
+#define MX53_PAD_EIM_OE__EMI_WEIM_OE				0x188 0x4d4 0x000 0x0 0x0
+#define MX53_PAD_EIM_OE__GPIO2_25				0x188 0x4d4 0x000 0x1 0x0
+#define MX53_PAD_EIM_OE__ECSPI2_MISO				0x188 0x4d4 0x7bc 0x2 0x2
+#define MX53_PAD_EIM_OE__IPU_DI1_PIN7				0x188 0x4d4 0x000 0x3 0x0
+#define MX53_PAD_EIM_OE__USBPHY2_IDDIG				0x188 0x4d4 0x000 0x7 0x0
+#define MX53_PAD_EIM_RW__EMI_WEIM_RW				0x18c 0x4d8 0x000 0x0 0x0
+#define MX53_PAD_EIM_RW__GPIO2_26				0x18c 0x4d8 0x000 0x1 0x0
+#define MX53_PAD_EIM_RW__ECSPI2_SS0				0x18c 0x4d8 0x7c4 0x2 0x2
+#define MX53_PAD_EIM_RW__IPU_DI1_PIN8				0x18c 0x4d8 0x000 0x3 0x0
+#define MX53_PAD_EIM_RW__USBPHY2_HOSTDISCONNECT			0x18c 0x4d8 0x000 0x7 0x0
+#define MX53_PAD_EIM_LBA__EMI_WEIM_LBA				0x190 0x4dc 0x000 0x0 0x0
+#define MX53_PAD_EIM_LBA__GPIO2_27				0x190 0x4dc 0x000 0x1 0x0
+#define MX53_PAD_EIM_LBA__ECSPI2_SS1				0x190 0x4dc 0x7c8 0x2 0x1
+#define MX53_PAD_EIM_LBA__IPU_DI1_PIN17				0x190 0x4dc 0x000 0x3 0x0
+#define MX53_PAD_EIM_LBA__SRC_BT_CFG1_0				0x190 0x4dc 0x000 0x7 0x0
+#define MX53_PAD_EIM_EB0__EMI_WEIM_EB_0				0x194 0x4e4 0x000 0x0 0x0
+#define MX53_PAD_EIM_EB0__GPIO2_28				0x194 0x4e4 0x000 0x1 0x0
+#define MX53_PAD_EIM_EB0__IPU_DISP1_DAT_11			0x194 0x4e4 0x000 0x3 0x0
+#define MX53_PAD_EIM_EB0__IPU_CSI1_D_11				0x194 0x4e4 0x000 0x4 0x0
+#define MX53_PAD_EIM_EB0__GPC_PMIC_RDY				0x194 0x4e4 0x810 0x5 0x0
+#define MX53_PAD_EIM_EB0__SRC_BT_CFG2_7				0x194 0x4e4 0x000 0x7 0x0
+#define MX53_PAD_EIM_EB1__EMI_WEIM_EB_1				0x198 0x4e8 0x000 0x0 0x0
+#define MX53_PAD_EIM_EB1__GPIO2_29				0x198 0x4e8 0x000 0x1 0x0
+#define MX53_PAD_EIM_EB1__IPU_DISP1_DAT_10			0x198 0x4e8 0x000 0x3 0x0
+#define MX53_PAD_EIM_EB1__IPU_CSI1_D_10				0x198 0x4e8 0x000 0x4 0x0
+#define MX53_PAD_EIM_EB1__SRC_BT_CFG2_6				0x198 0x4e8 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA0__EMI_NAND_WEIM_DA_0			0x19c 0x4ec 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA0__GPIO3_0				0x19c 0x4ec 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA0__IPU_DISP1_DAT_9			0x19c 0x4ec 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA0__IPU_CSI1_D_9				0x19c 0x4ec 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA0__SRC_BT_CFG2_5				0x19c 0x4ec 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA1__EMI_NAND_WEIM_DA_1			0x1a0 0x4f0 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA1__GPIO3_1				0x1a0 0x4f0 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA1__IPU_DISP1_DAT_8			0x1a0 0x4f0 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA1__IPU_CSI1_D_8				0x1a0 0x4f0 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA1__SRC_BT_CFG2_4				0x1a0 0x4f0 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA2__EMI_NAND_WEIM_DA_2			0x1a4 0x4f4 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA2__GPIO3_2				0x1a4 0x4f4 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA2__IPU_DISP1_DAT_7			0x1a4 0x4f4 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA2__IPU_CSI1_D_7				0x1a4 0x4f4 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA2__SRC_BT_CFG2_3				0x1a4 0x4f4 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA3__EMI_NAND_WEIM_DA_3			0x1a8 0x4f8 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA3__GPIO3_3				0x1a8 0x4f8 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA3__IPU_DISP1_DAT_6			0x1a8 0x4f8 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA3__IPU_CSI1_D_6				0x1a8 0x4f8 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA3__SRC_BT_CFG2_2				0x1a8 0x4f8 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA4__EMI_NAND_WEIM_DA_4			0x1ac 0x4fc 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA4__GPIO3_4				0x1ac 0x4fc 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA4__IPU_DISP1_DAT_5			0x1ac 0x4fc 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA4__IPU_CSI1_D_5				0x1ac 0x4fc 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA4__SRC_BT_CFG3_7				0x1ac 0x4fc 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA5__EMI_NAND_WEIM_DA_5			0x1b0 0x500 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA5__GPIO3_5				0x1b0 0x500 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA5__IPU_DISP1_DAT_4			0x1b0 0x500 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA5__IPU_CSI1_D_4				0x1b0 0x500 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA5__SRC_BT_CFG3_6				0x1b0 0x500 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA6__EMI_NAND_WEIM_DA_6			0x1b4 0x504 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA6__GPIO3_6				0x1b4 0x504 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA6__IPU_DISP1_DAT_3			0x1b4 0x504 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA6__IPU_CSI1_D_3				0x1b4 0x504 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA6__SRC_BT_CFG3_5				0x1b4 0x504 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA7__EMI_NAND_WEIM_DA_7			0x1b8 0x508 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA7__GPIO3_7				0x1b8 0x508 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA7__IPU_DISP1_DAT_2			0x1b8 0x508 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA7__IPU_CSI1_D_2				0x1b8 0x508 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA7__SRC_BT_CFG3_4				0x1b8 0x508 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA8__EMI_NAND_WEIM_DA_8			0x1bc 0x50c 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA8__GPIO3_8				0x1bc 0x50c 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA8__IPU_DISP1_DAT_1			0x1bc 0x50c 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA8__IPU_CSI1_D_1				0x1bc 0x50c 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA8__SRC_BT_CFG3_3				0x1bc 0x50c 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA9__EMI_NAND_WEIM_DA_9			0x1c0 0x510 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA9__GPIO3_9				0x1c0 0x510 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA9__IPU_DISP1_DAT_0			0x1c0 0x510 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA9__IPU_CSI1_D_0				0x1c0 0x510 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA9__SRC_BT_CFG3_2				0x1c0 0x510 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA10__EMI_NAND_WEIM_DA_10			0x1c4 0x514 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA10__GPIO3_10				0x1c4 0x514 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA10__IPU_DI1_PIN15			0x1c4 0x514 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA10__IPU_CSI1_DATA_EN			0x1c4 0x514 0x834 0x4 0x1
+#define MX53_PAD_EIM_DA10__SRC_BT_CFG3_1			0x1c4 0x514 0x000 0x7 0x0
+#define MX53_PAD_EIM_DA11__EMI_NAND_WEIM_DA_11			0x1c8 0x518 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA11__GPIO3_11				0x1c8 0x518 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA11__IPU_DI1_PIN2				0x1c8 0x518 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA11__IPU_CSI1_HSYNC			0x1c8 0x518 0x838 0x4 0x1
+#define MX53_PAD_EIM_DA12__EMI_NAND_WEIM_DA_12			0x1cc 0x51c 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA12__GPIO3_12				0x1cc 0x51c 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA12__IPU_DI1_PIN3				0x1cc 0x51c 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA12__IPU_CSI1_VSYNC			0x1cc 0x51c 0x83c 0x4 0x1
+#define MX53_PAD_EIM_DA13__EMI_NAND_WEIM_DA_13			0x1d0 0x520 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA13__GPIO3_13				0x1d0 0x520 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA13__IPU_DI1_D0_CS			0x1d0 0x520 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA13__CCM_DI1_EXT_CLK			0x1d0 0x520 0x76c 0x4 0x1
+#define MX53_PAD_EIM_DA14__EMI_NAND_WEIM_DA_14			0x1d4 0x524 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA14__GPIO3_14				0x1d4 0x524 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA14__IPU_DI1_D1_CS			0x1d4 0x524 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA14__CCM_DI0_EXT_CLK			0x1d4 0x524 0x000 0x4 0x0
+#define MX53_PAD_EIM_DA15__EMI_NAND_WEIM_DA_15			0x1d8 0x528 0x000 0x0 0x0
+#define MX53_PAD_EIM_DA15__GPIO3_15				0x1d8 0x528 0x000 0x1 0x0
+#define MX53_PAD_EIM_DA15__IPU_DI1_PIN1				0x1d8 0x528 0x000 0x3 0x0
+#define MX53_PAD_EIM_DA15__IPU_DI1_PIN4				0x1d8 0x528 0x000 0x4 0x0
+#define MX53_PAD_NANDF_WE_B__EMI_NANDF_WE_B			0x1dc 0x52c 0x000 0x0 0x0
+#define MX53_PAD_NANDF_WE_B__GPIO6_12				0x1dc 0x52c 0x000 0x1 0x0
+#define MX53_PAD_NANDF_RE_B__EMI_NANDF_RE_B			0x1e0 0x530 0x000 0x0 0x0
+#define MX53_PAD_NANDF_RE_B__GPIO6_13				0x1e0 0x530 0x000 0x1 0x0
+#define MX53_PAD_EIM_WAIT__EMI_WEIM_WAIT			0x1e4 0x534 0x000 0x0 0x0
+#define MX53_PAD_EIM_WAIT__GPIO5_0				0x1e4 0x534 0x000 0x1 0x0
+#define MX53_PAD_EIM_WAIT__EMI_WEIM_DTACK_B			0x1e4 0x534 0x000 0x2 0x0
+#define MX53_PAD_LVDS1_TX3_P__GPIO6_22				0x1ec 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS1_TX3_P__LDB_LVDS1_TX3			0x1ec 0x000 0x000 0x1 0x0
+#define MX53_PAD_LVDS1_TX2_P__GPIO6_24				0x1f0 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS1_TX2_P__LDB_LVDS1_TX2			0x1f0 0x000 0x000 0x1 0x0
+#define MX53_PAD_LVDS1_CLK_P__GPIO6_26				0x1f4 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS1_CLK_P__LDB_LVDS1_CLK			0x1f4 0x000 0x000 0x1 0x0
+#define MX53_PAD_LVDS1_TX1_P__GPIO6_28				0x1f8 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS1_TX1_P__LDB_LVDS1_TX1			0x1f8 0x000 0x000 0x1 0x0
+#define MX53_PAD_LVDS1_TX0_P__GPIO6_30				0x1fc 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS1_TX0_P__LDB_LVDS1_TX0			0x1fc 0x000 0x000 0x1 0x0
+#define MX53_PAD_LVDS0_TX3_P__GPIO7_22				0x200 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS0_TX3_P__LDB_LVDS0_TX3			0x200 0x000 0x000 0x1 0x0
+#define MX53_PAD_LVDS0_CLK_P__GPIO7_24				0x204 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS0_CLK_P__LDB_LVDS0_CLK			0x204 0x000 0x000 0x1 0x0
+#define MX53_PAD_LVDS0_TX2_P__GPIO7_26				0x208 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS0_TX2_P__LDB_LVDS0_TX2			0x208 0x000 0x000 0x1 0x0
+#define MX53_PAD_LVDS0_TX1_P__GPIO7_28				0x20c 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS0_TX1_P__LDB_LVDS0_TX1			0x20c 0x000 0x000 0x1 0x0
+#define MX53_PAD_LVDS0_TX0_P__GPIO7_30				0x210 0x000 0x000 0x0 0x0
+#define MX53_PAD_LVDS0_TX0_P__LDB_LVDS0_TX0			0x210 0x000 0x000 0x1 0x0
+#define MX53_PAD_GPIO_10__GPIO4_0				0x214 0x540 0x000 0x0 0x0
+#define MX53_PAD_GPIO_10__OSC32k_32K_OUT			0x214 0x540 0x000 0x1 0x0
+#define MX53_PAD_GPIO_11__GPIO4_1				0x218 0x544 0x000 0x0 0x0
+#define MX53_PAD_GPIO_12__GPIO4_2				0x21c 0x548 0x000 0x0 0x0
+#define MX53_PAD_GPIO_13__GPIO4_3				0x220 0x54c 0x000 0x0 0x0
+#define MX53_PAD_GPIO_14__GPIO4_4				0x224 0x550 0x000 0x0 0x0
+#define MX53_PAD_NANDF_CLE__EMI_NANDF_CLE			0x228 0x5a0 0x000 0x0 0x0
+#define MX53_PAD_NANDF_CLE__GPIO6_7				0x228 0x5a0 0x000 0x1 0x0
+#define MX53_PAD_NANDF_CLE__USBPHY1_VSTATUS_0			0x228 0x5a0 0x000 0x7 0x0
+#define MX53_PAD_NANDF_ALE__EMI_NANDF_ALE			0x22c 0x5a4 0x000 0x0 0x0
+#define MX53_PAD_NANDF_ALE__GPIO6_8				0x22c 0x5a4 0x000 0x1 0x0
+#define MX53_PAD_NANDF_ALE__USBPHY1_VSTATUS_1			0x22c 0x5a4 0x000 0x7 0x0
+#define MX53_PAD_NANDF_WP_B__EMI_NANDF_WP_B			0x230 0x5a8 0x000 0x0 0x0
+#define MX53_PAD_NANDF_WP_B__GPIO6_9				0x230 0x5a8 0x000 0x1 0x0
+#define MX53_PAD_NANDF_WP_B__USBPHY1_VSTATUS_2			0x230 0x5a8 0x000 0x7 0x0
+#define MX53_PAD_NANDF_RB0__EMI_NANDF_RB_0			0x234 0x5ac 0x000 0x0 0x0
+#define MX53_PAD_NANDF_RB0__GPIO6_10				0x234 0x5ac 0x000 0x1 0x0
+#define MX53_PAD_NANDF_RB0__USBPHY1_VSTATUS_3			0x234 0x5ac 0x000 0x7 0x0
+#define MX53_PAD_NANDF_CS0__EMI_NANDF_CS_0			0x238 0x5b0 0x000 0x0 0x0
+#define MX53_PAD_NANDF_CS0__GPIO6_11				0x238 0x5b0 0x000 0x1 0x0
+#define MX53_PAD_NANDF_CS0__USBPHY1_VSTATUS_4			0x238 0x5b0 0x000 0x7 0x0
+#define MX53_PAD_NANDF_CS1__EMI_NANDF_CS_1			0x23c 0x5b4 0x000 0x0 0x0
+#define MX53_PAD_NANDF_CS1__GPIO6_14				0x23c 0x5b4 0x000 0x1 0x0
+#define MX53_PAD_NANDF_CS1__MLB_MLBCLK				0x23c 0x5b4 0x858 0x6 0x0
+#define MX53_PAD_NANDF_CS1__USBPHY1_VSTATUS_5			0x23c 0x5b4 0x000 0x7 0x0
+#define MX53_PAD_NANDF_CS2__EMI_NANDF_CS_2			0x240 0x5b8 0x000 0x0 0x0
+#define MX53_PAD_NANDF_CS2__GPIO6_15				0x240 0x5b8 0x000 0x1 0x0
+#define MX53_PAD_NANDF_CS2__IPU_SISG_0				0x240 0x5b8 0x000 0x2 0x0
+#define MX53_PAD_NANDF_CS2__ESAI1_TX0				0x240 0x5b8 0x7e4 0x3 0x0
+#define MX53_PAD_NANDF_CS2__EMI_WEIM_CRE			0x240 0x5b8 0x000 0x4 0x0
+#define MX53_PAD_NANDF_CS2__CCM_CSI0_MCLK			0x240 0x5b8 0x000 0x5 0x0
+#define MX53_PAD_NANDF_CS2__MLB_MLBSIG				0x240 0x5b8 0x860 0x6 0x0
+#define MX53_PAD_NANDF_CS2__USBPHY1_VSTATUS_6			0x240 0x5b8 0x000 0x7 0x0
+#define MX53_PAD_NANDF_CS3__EMI_NANDF_CS_3			0x244 0x5bc 0x000 0x0 0x0
+#define MX53_PAD_NANDF_CS3__GPIO6_16				0x244 0x5bc 0x000 0x1 0x0
+#define MX53_PAD_NANDF_CS3__IPU_SISG_1				0x244 0x5bc 0x000 0x2 0x0
+#define MX53_PAD_NANDF_CS3__ESAI1_TX1				0x244 0x5bc 0x7e8 0x3 0x0
+#define MX53_PAD_NANDF_CS3__EMI_WEIM_A_26			0x244 0x5bc 0x000 0x4 0x0
+#define MX53_PAD_NANDF_CS3__MLB_MLBDAT				0x244 0x5bc 0x85c 0x6 0x0
+#define MX53_PAD_NANDF_CS3__USBPHY1_VSTATUS_7			0x244 0x5bc 0x000 0x7 0x0
+#define MX53_PAD_FEC_MDIO__FEC_MDIO				0x248 0x5c4 0x804 0x0 0x1
+#define MX53_PAD_FEC_MDIO__GPIO1_22				0x248 0x5c4 0x000 0x1 0x0
+#define MX53_PAD_FEC_MDIO__ESAI1_SCKR				0x248 0x5c4 0x7dc 0x2 0x0
+#define MX53_PAD_FEC_MDIO__FEC_COL				0x248 0x5c4 0x800 0x3 0x1
+#define MX53_PAD_FEC_MDIO__RTC_CE_RTC_PS2			0x248 0x5c4 0x000 0x4 0x0
+#define MX53_PAD_FEC_MDIO__SDMA_DEBUG_BUS_DEVICE_3		0x248 0x5c4 0x000 0x5 0x0
+#define MX53_PAD_FEC_MDIO__EMI_EMI_DEBUG_49			0x248 0x5c4 0x000 0x6 0x0
+#define MX53_PAD_FEC_REF_CLK__FEC_TX_CLK			0x24c 0x5c8 0x000 0x0 0x0
+#define MX53_PAD_FEC_REF_CLK__GPIO1_23				0x24c 0x5c8 0x000 0x1 0x0
+#define MX53_PAD_FEC_REF_CLK__ESAI1_FSR				0x24c 0x5c8 0x7cc 0x2 0x0
+#define MX53_PAD_FEC_REF_CLK__SDMA_DEBUG_BUS_DEVICE_4		0x24c 0x5c8 0x000 0x5 0x0
+#define MX53_PAD_FEC_REF_CLK__EMI_EMI_DEBUG_50			0x24c 0x5c8 0x000 0x6 0x0
+#define MX53_PAD_FEC_RX_ER__FEC_RX_ER				0x250 0x5cc 0x000 0x0 0x0
+#define MX53_PAD_FEC_RX_ER__GPIO1_24				0x250 0x5cc 0x000 0x1 0x0
+#define MX53_PAD_FEC_RX_ER__ESAI1_HCKR				0x250 0x5cc 0x7d4 0x2 0x0
+#define MX53_PAD_FEC_RX_ER__FEC_RX_CLK				0x250 0x5cc 0x808 0x3 0x1
+#define MX53_PAD_FEC_RX_ER__RTC_CE_RTC_PS3			0x250 0x5cc 0x000 0x4 0x0
+#define MX53_PAD_FEC_CRS_DV__FEC_RX_DV				0x254 0x5d0 0x000 0x0 0x0
+#define MX53_PAD_FEC_CRS_DV__GPIO1_25				0x254 0x5d0 0x000 0x1 0x0
+#define MX53_PAD_FEC_CRS_DV__ESAI1_SCKT				0x254 0x5d0 0x7e0 0x2 0x0
+#define MX53_PAD_FEC_RXD1__FEC_RDATA_1				0x258 0x5d4 0x000 0x0 0x0
+#define MX53_PAD_FEC_RXD1__GPIO1_26				0x258 0x5d4 0x000 0x1 0x0
+#define MX53_PAD_FEC_RXD1__ESAI1_FST				0x258 0x5d4 0x7d0 0x2 0x0
+#define MX53_PAD_FEC_RXD1__MLB_MLBSIG				0x258 0x5d4 0x860 0x3 0x1
+#define MX53_PAD_FEC_RXD1__RTC_CE_RTC_PS1			0x258 0x5d4 0x000 0x4 0x0
+#define MX53_PAD_FEC_RXD0__FEC_RDATA_0				0x25c 0x5d8 0x000 0x0 0x0
+#define MX53_PAD_FEC_RXD0__GPIO1_27				0x25c 0x5d8 0x000 0x1 0x0
+#define MX53_PAD_FEC_RXD0__ESAI1_HCKT				0x25c 0x5d8 0x7d8 0x2 0x0
+#define MX53_PAD_FEC_RXD0__OSC32k_32K_OUT			0x25c 0x5d8 0x000 0x3 0x0
+#define MX53_PAD_FEC_TX_EN__FEC_TX_EN				0x260 0x5dc 0x000 0x0 0x0
+#define MX53_PAD_FEC_TX_EN__GPIO1_28				0x260 0x5dc 0x000 0x1 0x0
+#define MX53_PAD_FEC_TX_EN__ESAI1_TX3_RX2			0x260 0x5dc 0x7f0 0x2 0x0
+#define MX53_PAD_FEC_TXD1__FEC_TDATA_1				0x264 0x5e0 0x000 0x0 0x0
+#define MX53_PAD_FEC_TXD1__GPIO1_29				0x264 0x5e0 0x000 0x1 0x0
+#define MX53_PAD_FEC_TXD1__ESAI1_TX2_RX3			0x264 0x5e0 0x7ec 0x2 0x0
+#define MX53_PAD_FEC_TXD1__MLB_MLBCLK				0x264 0x5e0 0x858 0x3 0x1
+#define MX53_PAD_FEC_TXD1__RTC_CE_RTC_PRSC_CLK			0x264 0x5e0 0x000 0x4 0x0
+#define MX53_PAD_FEC_TXD0__FEC_TDATA_0				0x268 0x5e4 0x000 0x0 0x0
+#define MX53_PAD_FEC_TXD0__GPIO1_30				0x268 0x5e4 0x000 0x1 0x0
+#define MX53_PAD_FEC_TXD0__ESAI1_TX4_RX1			0x268 0x5e4 0x7f4 0x2 0x0
+#define MX53_PAD_FEC_TXD0__USBPHY2_DATAOUT_0			0x268 0x5e4 0x000 0x7 0x0
+#define MX53_PAD_FEC_MDC__FEC_MDC				0x26c 0x5e8 0x000 0x0 0x0
+#define MX53_PAD_FEC_MDC__GPIO1_31				0x26c 0x5e8 0x000 0x1 0x0
+#define MX53_PAD_FEC_MDC__ESAI1_TX5_RX0				0x26c 0x5e8 0x7f8 0x2 0x0
+#define MX53_PAD_FEC_MDC__MLB_MLBDAT				0x26c 0x5e8 0x85c 0x3 0x1
+#define MX53_PAD_FEC_MDC__RTC_CE_RTC_ALARM1_TRIG		0x26c 0x5e8 0x000 0x4 0x0
+#define MX53_PAD_FEC_MDC__USBPHY2_DATAOUT_1			0x26c 0x5e8 0x000 0x7 0x0
+#define MX53_PAD_PATA_DIOW__PATA_DIOW				0x270 0x5f0 0x000 0x0 0x0
+#define MX53_PAD_PATA_DIOW__GPIO6_17				0x270 0x5f0 0x000 0x1 0x0
+#define MX53_PAD_PATA_DIOW__UART1_TXD_MUX			0x270 0x5f0 0x000 0x3 0x0
+#define MX53_PAD_PATA_DIOW__USBPHY2_DATAOUT_2			0x270 0x5f0 0x000 0x7 0x0
+#define MX53_PAD_PATA_DMACK__PATA_DMACK				0x274 0x5f4 0x000 0x0 0x0
+#define MX53_PAD_PATA_DMACK__GPIO6_18				0x274 0x5f4 0x000 0x1 0x0
+#define MX53_PAD_PATA_DMACK__UART1_RXD_MUX			0x274 0x5f4 0x878 0x3 0x3
+#define MX53_PAD_PATA_DMACK__USBPHY2_DATAOUT_3			0x274 0x5f4 0x000 0x7 0x0
+#define MX53_PAD_PATA_DMARQ__PATA_DMARQ				0x278 0x5f8 0x000 0x0 0x0
+#define MX53_PAD_PATA_DMARQ__GPIO7_0				0x278 0x5f8 0x000 0x1 0x0
+#define MX53_PAD_PATA_DMARQ__UART2_TXD_MUX			0x278 0x5f8 0x000 0x3 0x0
+#define MX53_PAD_PATA_DMARQ__CCM_CCM_OUT_0			0x278 0x5f8 0x000 0x5 0x0
+#define MX53_PAD_PATA_DMARQ__USBPHY2_DATAOUT_4			0x278 0x5f8 0x000 0x7 0x0
+#define MX53_PAD_PATA_BUFFER_EN__PATA_BUFFER_EN			0x27c 0x5fc 0x000 0x0 0x0
+#define MX53_PAD_PATA_BUFFER_EN__GPIO7_1			0x27c 0x5fc 0x000 0x1 0x0
+#define MX53_PAD_PATA_BUFFER_EN__UART2_RXD_MUX			0x27c 0x5fc 0x880 0x3 0x3
+#define MX53_PAD_PATA_BUFFER_EN__CCM_CCM_OUT_1			0x27c 0x5fc 0x000 0x5 0x0
+#define MX53_PAD_PATA_BUFFER_EN__USBPHY2_DATAOUT_5		0x27c 0x5fc 0x000 0x7 0x0
+#define MX53_PAD_PATA_INTRQ__PATA_INTRQ				0x280 0x600 0x000 0x0 0x0
+#define MX53_PAD_PATA_INTRQ__GPIO7_2				0x280 0x600 0x000 0x1 0x0
+#define MX53_PAD_PATA_INTRQ__UART2_CTS				0x280 0x600 0x000 0x3 0x0
+#define MX53_PAD_PATA_INTRQ__CAN1_TXCAN				0x280 0x600 0x000 0x4 0x0
+#define MX53_PAD_PATA_INTRQ__CCM_CCM_OUT_2			0x280 0x600 0x000 0x5 0x0
+#define MX53_PAD_PATA_INTRQ__USBPHY2_DATAOUT_6			0x280 0x600 0x000 0x7 0x0
+#define MX53_PAD_PATA_DIOR__PATA_DIOR				0x284 0x604 0x000 0x0 0x0
+#define MX53_PAD_PATA_DIOR__GPIO7_3				0x284 0x604 0x000 0x1 0x0
+#define MX53_PAD_PATA_DIOR__UART2_RTS				0x284 0x604 0x87c 0x3 0x3
+#define MX53_PAD_PATA_DIOR__CAN1_RXCAN				0x284 0x604 0x760 0x4 0x1
+#define MX53_PAD_PATA_DIOR__USBPHY2_DATAOUT_7			0x284 0x604 0x000 0x7 0x0
+#define MX53_PAD_PATA_RESET_B__PATA_PATA_RESET_B		0x288 0x608 0x000 0x0 0x0
+#define MX53_PAD_PATA_RESET_B__GPIO7_4				0x288 0x608 0x000 0x1 0x0
+#define MX53_PAD_PATA_RESET_B__ESDHC3_CMD			0x288 0x608 0x000 0x2 0x0
+#define MX53_PAD_PATA_RESET_B__UART1_CTS			0x288 0x608 0x000 0x3 0x0
+#define MX53_PAD_PATA_RESET_B__CAN2_TXCAN			0x288 0x608 0x000 0x4 0x0
+#define MX53_PAD_PATA_RESET_B__USBPHY1_DATAOUT_0		0x288 0x608 0x000 0x7 0x0
+#define MX53_PAD_PATA_IORDY__PATA_IORDY				0x28c 0x60c 0x000 0x0 0x0
+#define MX53_PAD_PATA_IORDY__GPIO7_5				0x28c 0x60c 0x000 0x1 0x0
+#define MX53_PAD_PATA_IORDY__ESDHC3_CLK				0x28c 0x60c 0x000 0x2 0x0
+#define MX53_PAD_PATA_IORDY__UART1_RTS				0x28c 0x60c 0x874 0x3 0x3
+#define MX53_PAD_PATA_IORDY__CAN2_RXCAN				0x28c 0x60c 0x764 0x4 0x1
+#define MX53_PAD_PATA_IORDY__USBPHY1_DATAOUT_1			0x28c 0x60c 0x000 0x7 0x0
+#define MX53_PAD_PATA_DA_0__PATA_DA_0				0x290 0x610 0x000 0x0 0x0
+#define MX53_PAD_PATA_DA_0__GPIO7_6				0x290 0x610 0x000 0x1 0x0
+#define MX53_PAD_PATA_DA_0__ESDHC3_RST				0x290 0x610 0x000 0x2 0x0
+#define MX53_PAD_PATA_DA_0__OWIRE_LINE				0x290 0x610 0x864 0x4 0x0
+#define MX53_PAD_PATA_DA_0__USBPHY1_DATAOUT_2			0x290 0x610 0x000 0x7 0x0
+#define MX53_PAD_PATA_DA_1__PATA_DA_1				0x294 0x614 0x000 0x0 0x0
+#define MX53_PAD_PATA_DA_1__GPIO7_7				0x294 0x614 0x000 0x1 0x0
+#define MX53_PAD_PATA_DA_1__ESDHC4_CMD				0x294 0x614 0x000 0x2 0x0
+#define MX53_PAD_PATA_DA_1__UART3_CTS				0x294 0x614 0x000 0x4 0x0
+#define MX53_PAD_PATA_DA_1__USBPHY1_DATAOUT_3			0x294 0x614 0x000 0x7 0x0
+#define MX53_PAD_PATA_DA_2__PATA_DA_2				0x298 0x618 0x000 0x0 0x0
+#define MX53_PAD_PATA_DA_2__GPIO7_8				0x298 0x618 0x000 0x1 0x0
+#define MX53_PAD_PATA_DA_2__ESDHC4_CLK				0x298 0x618 0x000 0x2 0x0
+#define MX53_PAD_PATA_DA_2__UART3_RTS				0x298 0x618 0x884 0x4 0x5
+#define MX53_PAD_PATA_DA_2__USBPHY1_DATAOUT_4			0x298 0x618 0x000 0x7 0x0
+#define MX53_PAD_PATA_CS_0__PATA_CS_0				0x29c 0x61c 0x000 0x0 0x0
+#define MX53_PAD_PATA_CS_0__GPIO7_9				0x29c 0x61c 0x000 0x1 0x0
+#define MX53_PAD_PATA_CS_0__UART3_TXD_MUX			0x29c 0x61c 0x000 0x4 0x0
+#define MX53_PAD_PATA_CS_0__USBPHY1_DATAOUT_5			0x29c 0x61c 0x000 0x7 0x0
+#define MX53_PAD_PATA_CS_1__PATA_CS_1				0x2a0 0x620 0x000 0x0 0x0
+#define MX53_PAD_PATA_CS_1__GPIO7_10				0x2a0 0x620 0x000 0x1 0x0
+#define MX53_PAD_PATA_CS_1__UART3_RXD_MUX			0x2a0 0x620 0x888 0x4 0x3
+#define MX53_PAD_PATA_CS_1__USBPHY1_DATAOUT_6			0x2a0 0x620 0x000 0x7 0x0
+#define MX53_PAD_PATA_DATA0__PATA_DATA_0			0x2a4 0x628 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA0__GPIO2_0				0x2a4 0x628 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA0__EMI_NANDF_D_0			0x2a4 0x628 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA0__ESDHC3_DAT4			0x2a4 0x628 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA0__GPU3d_GPU_DEBUG_OUT_0		0x2a4 0x628 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA0__IPU_DIAG_BUS_0			0x2a4 0x628 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA0__USBPHY1_DATAOUT_7			0x2a4 0x628 0x000 0x7 0x0
+#define MX53_PAD_PATA_DATA1__PATA_DATA_1			0x2a8 0x62c 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA1__GPIO2_1				0x2a8 0x62c 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA1__EMI_NANDF_D_1			0x2a8 0x62c 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA1__ESDHC3_DAT5			0x2a8 0x62c 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA1__GPU3d_GPU_DEBUG_OUT_1		0x2a8 0x62c 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA1__IPU_DIAG_BUS_1			0x2a8 0x62c 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA2__PATA_DATA_2			0x2ac 0x630 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA2__GPIO2_2				0x2ac 0x630 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA2__EMI_NANDF_D_2			0x2ac 0x630 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA2__ESDHC3_DAT6			0x2ac 0x630 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA2__GPU3d_GPU_DEBUG_OUT_2		0x2ac 0x630 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA2__IPU_DIAG_BUS_2			0x2ac 0x630 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA3__PATA_DATA_3			0x2b0 0x634 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA3__GPIO2_3				0x2b0 0x634 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA3__EMI_NANDF_D_3			0x2b0 0x634 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA3__ESDHC3_DAT7			0x2b0 0x634 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA3__GPU3d_GPU_DEBUG_OUT_3		0x2b0 0x634 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA3__IPU_DIAG_BUS_3			0x2b0 0x634 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA4__PATA_DATA_4			0x2b4 0x638 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA4__GPIO2_4				0x2b4 0x638 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA4__EMI_NANDF_D_4			0x2b4 0x638 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA4__ESDHC4_DAT4			0x2b4 0x638 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA4__GPU3d_GPU_DEBUG_OUT_4		0x2b4 0x638 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA4__IPU_DIAG_BUS_4			0x2b4 0x638 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA5__PATA_DATA_5			0x2b8 0x63c 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA5__GPIO2_5				0x2b8 0x63c 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA5__EMI_NANDF_D_5			0x2b8 0x63c 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA5__ESDHC4_DAT5			0x2b8 0x63c 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA5__GPU3d_GPU_DEBUG_OUT_5		0x2b8 0x63c 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA5__IPU_DIAG_BUS_5			0x2b8 0x63c 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA6__PATA_DATA_6			0x2bc 0x640 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA6__GPIO2_6				0x2bc 0x640 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA6__EMI_NANDF_D_6			0x2bc 0x640 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA6__ESDHC4_DAT6			0x2bc 0x640 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA6__GPU3d_GPU_DEBUG_OUT_6		0x2bc 0x640 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA6__IPU_DIAG_BUS_6			0x2bc 0x640 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA7__PATA_DATA_7			0x2c0 0x644 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA7__GPIO2_7				0x2c0 0x644 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA7__EMI_NANDF_D_7			0x2c0 0x644 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA7__ESDHC4_DAT7			0x2c0 0x644 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA7__GPU3d_GPU_DEBUG_OUT_7		0x2c0 0x644 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA7__IPU_DIAG_BUS_7			0x2c0 0x644 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA8__PATA_DATA_8			0x2c4 0x648 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA8__GPIO2_8				0x2c4 0x648 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA8__ESDHC1_DAT4			0x2c4 0x648 0x000 0x2 0x0
+#define MX53_PAD_PATA_DATA8__EMI_NANDF_D_8			0x2c4 0x648 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA8__ESDHC3_DAT0			0x2c4 0x648 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA8__GPU3d_GPU_DEBUG_OUT_8		0x2c4 0x648 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA8__IPU_DIAG_BUS_8			0x2c4 0x648 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA9__PATA_DATA_9			0x2c8 0x64c 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA9__GPIO2_9				0x2c8 0x64c 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA9__ESDHC1_DAT5			0x2c8 0x64c 0x000 0x2 0x0
+#define MX53_PAD_PATA_DATA9__EMI_NANDF_D_9			0x2c8 0x64c 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA9__ESDHC3_DAT1			0x2c8 0x64c 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA9__GPU3d_GPU_DEBUG_OUT_9		0x2c8 0x64c 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA9__IPU_DIAG_BUS_9			0x2c8 0x64c 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA10__PATA_DATA_10			0x2cc 0x650 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA10__GPIO2_10				0x2cc 0x650 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA10__ESDHC1_DAT6			0x2cc 0x650 0x000 0x2 0x0
+#define MX53_PAD_PATA_DATA10__EMI_NANDF_D_10			0x2cc 0x650 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA10__ESDHC3_DAT2			0x2cc 0x650 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA10__GPU3d_GPU_DEBUG_OUT_10		0x2cc 0x650 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA10__IPU_DIAG_BUS_10			0x2cc 0x650 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA11__PATA_DATA_11			0x2d0 0x654 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA11__GPIO2_11				0x2d0 0x654 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA11__ESDHC1_DAT7			0x2d0 0x654 0x000 0x2 0x0
+#define MX53_PAD_PATA_DATA11__EMI_NANDF_D_11			0x2d0 0x654 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA11__ESDHC3_DAT3			0x2d0 0x654 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA11__GPU3d_GPU_DEBUG_OUT_11		0x2d0 0x654 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA11__IPU_DIAG_BUS_11			0x2d0 0x654 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA12__PATA_DATA_12			0x2d4 0x658 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA12__GPIO2_12				0x2d4 0x658 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA12__ESDHC2_DAT4			0x2d4 0x658 0x000 0x2 0x0
+#define MX53_PAD_PATA_DATA12__EMI_NANDF_D_12			0x2d4 0x658 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA12__ESDHC4_DAT0			0x2d4 0x658 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA12__GPU3d_GPU_DEBUG_OUT_12		0x2d4 0x658 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA12__IPU_DIAG_BUS_12			0x2d4 0x658 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA13__PATA_DATA_13			0x2d8 0x65c 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA13__GPIO2_13				0x2d8 0x65c 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA13__ESDHC2_DAT5			0x2d8 0x65c 0x000 0x2 0x0
+#define MX53_PAD_PATA_DATA13__EMI_NANDF_D_13			0x2d8 0x65c 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA13__ESDHC4_DAT1			0x2d8 0x65c 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA13__GPU3d_GPU_DEBUG_OUT_13		0x2d8 0x65c 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA13__IPU_DIAG_BUS_13			0x2d8 0x65c 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA14__PATA_DATA_14			0x2dc 0x660 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA14__GPIO2_14				0x2dc 0x660 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA14__ESDHC2_DAT6			0x2dc 0x660 0x000 0x2 0x0
+#define MX53_PAD_PATA_DATA14__EMI_NANDF_D_14			0x2dc 0x660 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA14__ESDHC4_DAT2			0x2dc 0x660 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA14__GPU3d_GPU_DEBUG_OUT_14		0x2dc 0x660 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA14__IPU_DIAG_BUS_14			0x2dc 0x660 0x000 0x6 0x0
+#define MX53_PAD_PATA_DATA15__PATA_DATA_15			0x2e0 0x664 0x000 0x0 0x0
+#define MX53_PAD_PATA_DATA15__GPIO2_15				0x2e0 0x664 0x000 0x1 0x0
+#define MX53_PAD_PATA_DATA15__ESDHC2_DAT7			0x2e0 0x664 0x000 0x2 0x0
+#define MX53_PAD_PATA_DATA15__EMI_NANDF_D_15			0x2e0 0x664 0x000 0x3 0x0
+#define MX53_PAD_PATA_DATA15__ESDHC4_DAT3			0x2e0 0x664 0x000 0x4 0x0
+#define MX53_PAD_PATA_DATA15__GPU3d_GPU_DEBUG_OUT_15		0x2e0 0x664 0x000 0x5 0x0
+#define MX53_PAD_PATA_DATA15__IPU_DIAG_BUS_15			0x2e0 0x664 0x000 0x6 0x0
+#define MX53_PAD_SD1_DATA0__ESDHC1_DAT0				0x2e4 0x66c 0x000 0x0 0x0
+#define MX53_PAD_SD1_DATA0__GPIO1_16				0x2e4 0x66c 0x000 0x1 0x0
+#define MX53_PAD_SD1_DATA0__GPT_CAPIN1				0x2e4 0x66c 0x000 0x3 0x0
+#define MX53_PAD_SD1_DATA0__CSPI_MISO				0x2e4 0x66c 0x784 0x5 0x2
+#define MX53_PAD_SD1_DATA0__CCM_PLL3_BYP			0x2e4 0x66c 0x778 0x7 0x0
+#define MX53_PAD_SD1_DATA1__ESDHC1_DAT1				0x2e8 0x670 0x000 0x0 0x0
+#define MX53_PAD_SD1_DATA1__GPIO1_17				0x2e8 0x670 0x000 0x1 0x0
+#define MX53_PAD_SD1_DATA1__GPT_CAPIN2				0x2e8 0x670 0x000 0x3 0x0
+#define MX53_PAD_SD1_DATA1__CSPI_SS0				0x2e8 0x670 0x78c 0x5 0x3
+#define MX53_PAD_SD1_DATA1__CCM_PLL4_BYP			0x2e8 0x670 0x77c 0x7 0x1
+#define MX53_PAD_SD1_CMD__ESDHC1_CMD				0x2ec 0x674 0x000 0x0 0x0
+#define MX53_PAD_SD1_CMD__GPIO1_18				0x2ec 0x674 0x000 0x1 0x0
+#define MX53_PAD_SD1_CMD__GPT_CMPOUT1				0x2ec 0x674 0x000 0x3 0x0
+#define MX53_PAD_SD1_CMD__CSPI_MOSI				0x2ec 0x674 0x788 0x5 0x2
+#define MX53_PAD_SD1_CMD__CCM_PLL1_BYP				0x2ec 0x674 0x770 0x7 0x0
+#define MX53_PAD_SD1_DATA2__ESDHC1_DAT2				0x2f0 0x678 0x000 0x0 0x0
+#define MX53_PAD_SD1_DATA2__GPIO1_19				0x2f0 0x678 0x000 0x1 0x0
+#define MX53_PAD_SD1_DATA2__GPT_CMPOUT2				0x2f0 0x678 0x000 0x2 0x0
+#define MX53_PAD_SD1_DATA2__PWM2_PWMO				0x2f0 0x678 0x000 0x3 0x0
+#define MX53_PAD_SD1_DATA2__WDOG1_WDOG_B			0x2f0 0x678 0x000 0x4 0x0
+#define MX53_PAD_SD1_DATA2__CSPI_SS1				0x2f0 0x678 0x790 0x5 0x2
+#define MX53_PAD_SD1_DATA2__WDOG1_WDOG_RST_B_DEB		0x2f0 0x678 0x000 0x6 0x0
+#define MX53_PAD_SD1_DATA2__CCM_PLL2_BYP			0x2f0 0x678 0x774 0x7 0x0
+#define MX53_PAD_SD1_CLK__ESDHC1_CLK				0x2f4 0x67c 0x000 0x0 0x0
+#define MX53_PAD_SD1_CLK__GPIO1_20				0x2f4 0x67c 0x000 0x1 0x0
+#define MX53_PAD_SD1_CLK__OSC32k_32K_OUT			0x2f4 0x67c 0x000 0x2 0x0
+#define MX53_PAD_SD1_CLK__GPT_CLKIN				0x2f4 0x67c 0x000 0x3 0x0
+#define MX53_PAD_SD1_CLK__CSPI_SCLK				0x2f4 0x67c 0x780 0x5 0x2
+#define MX53_PAD_SD1_CLK__SATA_PHY_DTB_0			0x2f4 0x67c 0x000 0x7 0x0
+#define MX53_PAD_SD1_DATA3__ESDHC1_DAT3				0x2f8 0x680 0x000 0x0 0x0
+#define MX53_PAD_SD1_DATA3__GPIO1_21				0x2f8 0x680 0x000 0x1 0x0
+#define MX53_PAD_SD1_DATA3__GPT_CMPOUT3				0x2f8 0x680 0x000 0x2 0x0
+#define MX53_PAD_SD1_DATA3__PWM1_PWMO				0x2f8 0x680 0x000 0x3 0x0
+#define MX53_PAD_SD1_DATA3__WDOG2_WDOG_B			0x2f8 0x680 0x000 0x4 0x0
+#define MX53_PAD_SD1_DATA3__CSPI_SS2				0x2f8 0x680 0x794 0x5 0x2
+#define MX53_PAD_SD1_DATA3__WDOG2_WDOG_RST_B_DEB		0x2f8 0x680 0x000 0x6 0x0
+#define MX53_PAD_SD1_DATA3__SATA_PHY_DTB_1			0x2f8 0x680 0x000 0x7 0x0
+#define MX53_PAD_SD2_CLK__ESDHC2_CLK				0x2fc 0x688 0x000 0x0 0x0
+#define MX53_PAD_SD2_CLK__GPIO1_10				0x2fc 0x688 0x000 0x1 0x0
+#define MX53_PAD_SD2_CLK__KPP_COL_5				0x2fc 0x688 0x840 0x2 0x2
+#define MX53_PAD_SD2_CLK__AUDMUX_AUD4_RXFS			0x2fc 0x688 0x73c 0x3 0x1
+#define MX53_PAD_SD2_CLK__CSPI_SCLK				0x2fc 0x688 0x780 0x5 0x3
+#define MX53_PAD_SD2_CLK__SCC_RANDOM_V				0x2fc 0x688 0x000 0x7 0x0
+#define MX53_PAD_SD2_CMD__ESDHC2_CMD				0x300 0x68c 0x000 0x0 0x0
+#define MX53_PAD_SD2_CMD__GPIO1_11				0x300 0x68c 0x000 0x1 0x0
+#define MX53_PAD_SD2_CMD__KPP_ROW_5				0x300 0x68c 0x84c 0x2 0x1
+#define MX53_PAD_SD2_CMD__AUDMUX_AUD4_RXC			0x300 0x68c 0x738 0x3 0x1
+#define MX53_PAD_SD2_CMD__CSPI_MOSI				0x300 0x68c 0x788 0x5 0x3
+#define MX53_PAD_SD2_CMD__SCC_RANDOM				0x300 0x68c 0x000 0x7 0x0
+#define MX53_PAD_SD2_DATA3__ESDHC2_DAT3				0x304 0x690 0x000 0x0 0x0
+#define MX53_PAD_SD2_DATA3__GPIO1_12				0x304 0x690 0x000 0x1 0x0
+#define MX53_PAD_SD2_DATA3__KPP_COL_6				0x304 0x690 0x844 0x2 0x1
+#define MX53_PAD_SD2_DATA3__AUDMUX_AUD4_TXC			0x304 0x690 0x740 0x3 0x1
+#define MX53_PAD_SD2_DATA3__CSPI_SS2				0x304 0x690 0x794 0x5 0x3
+#define MX53_PAD_SD2_DATA3__SJC_DONE				0x304 0x690 0x000 0x7 0x0
+#define MX53_PAD_SD2_DATA2__ESDHC2_DAT2				0x308 0x694 0x000 0x0 0x0
+#define MX53_PAD_SD2_DATA2__GPIO1_13				0x308 0x694 0x000 0x1 0x0
+#define MX53_PAD_SD2_DATA2__KPP_ROW_6				0x308 0x694 0x850 0x2 0x1
+#define MX53_PAD_SD2_DATA2__AUDMUX_AUD4_TXD			0x308 0x694 0x734 0x3 0x1
+#define MX53_PAD_SD2_DATA2__CSPI_SS1				0x308 0x694 0x790 0x5 0x3
+#define MX53_PAD_SD2_DATA2__SJC_FAIL				0x308 0x694 0x000 0x7 0x0
+#define MX53_PAD_SD2_DATA1__ESDHC2_DAT1				0x30c 0x698 0x000 0x0 0x0
+#define MX53_PAD_SD2_DATA1__GPIO1_14				0x30c 0x698 0x000 0x1 0x0
+#define MX53_PAD_SD2_DATA1__KPP_COL_7				0x30c 0x698 0x848 0x2 0x1
+#define MX53_PAD_SD2_DATA1__AUDMUX_AUD4_TXFS			0x30c 0x698 0x744 0x3 0x1
+#define MX53_PAD_SD2_DATA1__CSPI_SS0				0x30c 0x698 0x78c 0x5 0x4
+#define MX53_PAD_SD2_DATA1__RTIC_SEC_VIO			0x30c 0x698 0x000 0x7 0x0
+#define MX53_PAD_SD2_DATA0__ESDHC2_DAT0				0x310 0x69c 0x000 0x0 0x0
+#define MX53_PAD_SD2_DATA0__GPIO1_15				0x310 0x69c 0x000 0x1 0x0
+#define MX53_PAD_SD2_DATA0__KPP_ROW_7				0x310 0x69c 0x854 0x2 0x1
+#define MX53_PAD_SD2_DATA0__AUDMUX_AUD4_RXD			0x310 0x69c 0x730 0x3 0x1
+#define MX53_PAD_SD2_DATA0__CSPI_MISO				0x310 0x69c 0x784 0x5 0x3
+#define MX53_PAD_SD2_DATA0__RTIC_DONE_INT			0x310 0x69c 0x000 0x7 0x0
+#define MX53_PAD_GPIO_0__CCM_CLKO				0x314 0x6a4 0x000 0x0 0x0
+#define MX53_PAD_GPIO_0__GPIO1_0				0x314 0x6a4 0x000 0x1 0x0
+#define MX53_PAD_GPIO_0__KPP_COL_5				0x314 0x6a4 0x840 0x2 0x3
+#define MX53_PAD_GPIO_0__CCM_SSI_EXT1_CLK			0x314 0x6a4 0x000 0x3 0x0
+#define MX53_PAD_GPIO_0__EPIT1_EPITO				0x314 0x6a4 0x000 0x4 0x0
+#define MX53_PAD_GPIO_0__SRTC_ALARM_DEB				0x314 0x6a4 0x000 0x5 0x0
+#define MX53_PAD_GPIO_0__USBOH3_USBH1_PWR			0x314 0x6a4 0x000 0x6 0x0
+#define MX53_PAD_GPIO_0__CSU_TD					0x314 0x6a4 0x000 0x7 0x0
+#define MX53_PAD_GPIO_1__ESAI1_SCKR				0x318 0x6a8 0x7dc 0x0 0x1
+#define MX53_PAD_GPIO_1__GPIO1_1				0x318 0x6a8 0x000 0x1 0x0
+#define MX53_PAD_GPIO_1__KPP_ROW_5				0x318 0x6a8 0x84c 0x2 0x2
+#define MX53_PAD_GPIO_1__CCM_SSI_EXT2_CLK			0x318 0x6a8 0x000 0x3 0x0
+#define MX53_PAD_GPIO_1__PWM2_PWMO				0x318 0x6a8 0x000 0x4 0x0
+#define MX53_PAD_GPIO_1__WDOG2_WDOG_B				0x318 0x6a8 0x000 0x5 0x0
+#define MX53_PAD_GPIO_1__ESDHC1_CD				0x318 0x6a8 0x000 0x6 0x0
+#define MX53_PAD_GPIO_1__SRC_TESTER_ACK				0x318 0x6a8 0x000 0x7 0x0
+#define MX53_PAD_GPIO_9__ESAI1_FSR				0x31c 0x6ac 0x7cc 0x0 0x1
+#define MX53_PAD_GPIO_9__GPIO1_9				0x31c 0x6ac 0x000 0x1 0x0
+#define MX53_PAD_GPIO_9__KPP_COL_6				0x31c 0x6ac 0x844 0x2 0x2
+#define MX53_PAD_GPIO_9__CCM_REF_EN_B				0x31c 0x6ac 0x000 0x3 0x0
+#define MX53_PAD_GPIO_9__PWM1_PWMO				0x31c 0x6ac 0x000 0x4 0x0
+#define MX53_PAD_GPIO_9__WDOG1_WDOG_B				0x31c 0x6ac 0x000 0x5 0x0
+#define MX53_PAD_GPIO_9__ESDHC1_WP				0x31c 0x6ac 0x7fc 0x6 0x1
+#define MX53_PAD_GPIO_9__SCC_FAIL_STATE				0x31c 0x6ac 0x000 0x7 0x0
+#define MX53_PAD_GPIO_3__ESAI1_HCKR				0x320 0x6b0 0x7d4 0x0 0x1
+#define MX53_PAD_GPIO_3__GPIO1_3				0x320 0x6b0 0x000 0x1 0x0
+#define MX53_PAD_GPIO_3__I2C3_SCL				0x320 0x6b0 0x824 0x2 0x1
+#define MX53_PAD_GPIO_3__DPLLIP1_TOG_EN				0x320 0x6b0 0x000 0x3 0x0
+#define MX53_PAD_GPIO_3__CCM_CLKO2				0x320 0x6b0 0x000 0x4 0x0
+#define MX53_PAD_GPIO_3__OBSERVE_MUX_OBSRV_INT_OUT0		0x320 0x6b0 0x000 0x5 0x0
+#define MX53_PAD_GPIO_3__USBOH3_USBH1_OC			0x320 0x6b0 0x8a0 0x6 0x1
+#define MX53_PAD_GPIO_3__MLB_MLBCLK				0x320 0x6b0 0x858 0x7 0x2
+#define MX53_PAD_GPIO_6__ESAI1_SCKT				0x324 0x6b4 0x7e0 0x0 0x1
+#define MX53_PAD_GPIO_6__GPIO1_6				0x324 0x6b4 0x000 0x1 0x0
+#define MX53_PAD_GPIO_6__I2C3_SDA				0x324 0x6b4 0x828 0x2 0x1
+#define MX53_PAD_GPIO_6__CCM_CCM_OUT_0				0x324 0x6b4 0x000 0x3 0x0
+#define MX53_PAD_GPIO_6__CSU_CSU_INT_DEB			0x324 0x6b4 0x000 0x4 0x0
+#define MX53_PAD_GPIO_6__OBSERVE_MUX_OBSRV_INT_OUT1		0x324 0x6b4 0x000 0x5 0x0
+#define MX53_PAD_GPIO_6__ESDHC2_LCTL				0x324 0x6b4 0x000 0x6 0x0
+#define MX53_PAD_GPIO_6__MLB_MLBSIG				0x324 0x6b4 0x860 0x7 0x2
+#define MX53_PAD_GPIO_2__ESAI1_FST				0x328 0x6b8 0x7d0 0x0 0x1
+#define MX53_PAD_GPIO_2__GPIO1_2				0x328 0x6b8 0x000 0x1 0x0
+#define MX53_PAD_GPIO_2__KPP_ROW_6				0x328 0x6b8 0x850 0x2 0x2
+#define MX53_PAD_GPIO_2__CCM_CCM_OUT_1				0x328 0x6b8 0x000 0x3 0x0
+#define MX53_PAD_GPIO_2__CSU_CSU_ALARM_AUT_0			0x328 0x6b8 0x000 0x4 0x0
+#define MX53_PAD_GPIO_2__OBSERVE_MUX_OBSRV_INT_OUT2		0x328 0x6b8 0x000 0x5 0x0
+#define MX53_PAD_GPIO_2__ESDHC2_WP				0x328 0x6b8 0x000 0x6 0x0
+#define MX53_PAD_GPIO_2__MLB_MLBDAT				0x328 0x6b8 0x85c 0x7 0x2
+#define MX53_PAD_GPIO_4__ESAI1_HCKT				0x32c 0x6bc 0x7d8 0x0 0x1
+#define MX53_PAD_GPIO_4__GPIO1_4				0x32c 0x6bc 0x000 0x1 0x0
+#define MX53_PAD_GPIO_4__KPP_COL_7				0x32c 0x6bc 0x848 0x2 0x2
+#define MX53_PAD_GPIO_4__CCM_CCM_OUT_2				0x32c 0x6bc 0x000 0x3 0x0
+#define MX53_PAD_GPIO_4__CSU_CSU_ALARM_AUT_1			0x32c 0x6bc 0x000 0x4 0x0
+#define MX53_PAD_GPIO_4__OBSERVE_MUX_OBSRV_INT_OUT3		0x32c 0x6bc 0x000 0x5 0x0
+#define MX53_PAD_GPIO_4__ESDHC2_CD				0x32c 0x6bc 0x000 0x6 0x0
+#define MX53_PAD_GPIO_4__SCC_SEC_STATE				0x32c 0x6bc 0x000 0x7 0x0
+#define MX53_PAD_GPIO_5__ESAI1_TX2_RX3				0x330 0x6c0 0x7ec 0x0 0x1
+#define MX53_PAD_GPIO_5__GPIO1_5				0x330 0x6c0 0x000 0x1 0x0
+#define MX53_PAD_GPIO_5__KPP_ROW_7				0x330 0x6c0 0x854 0x2 0x2
+#define MX53_PAD_GPIO_5__CCM_CLKO				0x330 0x6c0 0x000 0x3 0x0
+#define MX53_PAD_GPIO_5__CSU_CSU_ALARM_AUT_2			0x330 0x6c0 0x000 0x4 0x0
+#define MX53_PAD_GPIO_5__OBSERVE_MUX_OBSRV_INT_OUT4		0x330 0x6c0 0x000 0x5 0x0
+#define MX53_PAD_GPIO_5__I2C3_SCL				0x330 0x6c0 0x824 0x6 0x2
+#define MX53_PAD_GPIO_5__CCM_PLL1_BYP				0x330 0x6c0 0x770 0x7 0x1
+#define MX53_PAD_GPIO_7__ESAI1_TX4_RX1				0x334 0x6c4 0x7f4 0x0 0x1
+#define MX53_PAD_GPIO_7__GPIO1_7				0x334 0x6c4 0x000 0x1 0x0
+#define MX53_PAD_GPIO_7__EPIT1_EPITO				0x334 0x6c4 0x000 0x2 0x0
+#define MX53_PAD_GPIO_7__CAN1_TXCAN				0x334 0x6c4 0x000 0x3 0x0
+#define MX53_PAD_GPIO_7__UART2_TXD_MUX				0x334 0x6c4 0x000 0x4 0x0
+#define MX53_PAD_GPIO_7__FIRI_RXD				0x334 0x6c4 0x80c 0x5 0x1
+#define MX53_PAD_GPIO_7__SPDIF_PLOCK				0x334 0x6c4 0x000 0x6 0x0
+#define MX53_PAD_GPIO_7__CCM_PLL2_BYP				0x334 0x6c4 0x774 0x7 0x1
+#define MX53_PAD_GPIO_8__ESAI1_TX5_RX0				0x338 0x6c8 0x7f8 0x0 0x1
+#define MX53_PAD_GPIO_8__GPIO1_8				0x338 0x6c8 0x000 0x1 0x0
+#define MX53_PAD_GPIO_8__EPIT2_EPITO				0x338 0x6c8 0x000 0x2 0x0
+#define MX53_PAD_GPIO_8__CAN1_RXCAN				0x338 0x6c8 0x760 0x3 0x2
+#define MX53_PAD_GPIO_8__UART2_RXD_MUX				0x338 0x6c8 0x880 0x4 0x5
+#define MX53_PAD_GPIO_8__FIRI_TXD				0x338 0x6c8 0x000 0x5 0x0
+#define MX53_PAD_GPIO_8__SPDIF_SRCLK				0x338 0x6c8 0x000 0x6 0x0
+#define MX53_PAD_GPIO_8__CCM_PLL3_BYP				0x338 0x6c8 0x778 0x7 0x1
+#define MX53_PAD_GPIO_16__ESAI1_TX3_RX2				0x33c 0x6cc 0x7f0 0x0 0x1
+#define MX53_PAD_GPIO_16__GPIO7_11				0x33c 0x6cc 0x000 0x1 0x0
+#define MX53_PAD_GPIO_16__TZIC_PWRFAIL_INT			0x33c 0x6cc 0x000 0x2 0x0
+#define MX53_PAD_GPIO_16__RTC_CE_RTC_EXT_TRIG1			0x33c 0x6cc 0x000 0x4 0x0
+#define MX53_PAD_GPIO_16__SPDIF_IN1				0x33c 0x6cc 0x870 0x5 0x1
+#define MX53_PAD_GPIO_16__I2C3_SDA				0x33c 0x6cc 0x828 0x6 0x2
+#define MX53_PAD_GPIO_16__SJC_DE_B				0x33c 0x6cc 0x000 0x7 0x0
+#define MX53_PAD_GPIO_17__ESAI1_TX0				0x340 0x6d0 0x7e4 0x0 0x1
+#define MX53_PAD_GPIO_17__GPIO7_12				0x340 0x6d0 0x000 0x1 0x0
+#define MX53_PAD_GPIO_17__SDMA_EXT_EVENT_0			0x340 0x6d0 0x868 0x2 0x1
+#define MX53_PAD_GPIO_17__GPC_PMIC_RDY				0x340 0x6d0 0x810 0x3 0x1
+#define MX53_PAD_GPIO_17__RTC_CE_RTC_FSV_TRIG			0x340 0x6d0 0x000 0x4 0x0
+#define MX53_PAD_GPIO_17__SPDIF_OUT1				0x340 0x6d0 0x000 0x5 0x0
+#define MX53_PAD_GPIO_17__IPU_SNOOP2				0x340 0x6d0 0x000 0x6 0x0
+#define MX53_PAD_GPIO_17__SJC_JTAG_ACT				0x340 0x6d0 0x000 0x7 0x0
+#define MX53_PAD_GPIO_18__ESAI1_TX1				0x344 0x6d4 0x7e8 0x0 0x1
+#define MX53_PAD_GPIO_18__GPIO7_13				0x344 0x6d4 0x000 0x1 0x0
+#define MX53_PAD_GPIO_18__SDMA_EXT_EVENT_1			0x344 0x6d4 0x86c 0x2 0x1
+#define MX53_PAD_GPIO_18__OWIRE_LINE				0x344 0x6d4 0x864 0x3 0x1
+#define MX53_PAD_GPIO_18__RTC_CE_RTC_ALARM2_TRIG		0x344 0x6d4 0x000 0x4 0x0
+#define MX53_PAD_GPIO_18__CCM_ASRC_EXT_CLK			0x344 0x6d4 0x768 0x5 0x1
+#define MX53_PAD_GPIO_18__ESDHC1_LCTL				0x344 0x6d4 0x000 0x6 0x0
+#define MX53_PAD_GPIO_18__SRC_SYSTEM_RST			0x344 0x6d4 0x000 0x7 0x0
+
+#endif /* __DTS_IMX53_PINFUNC_H */
diff --git a/arch/arm/dts/imx53.dtsi b/arch/arm/dts/imx53.dtsi
new file mode 100644
index 0000000..5c8608b
--- /dev/null
+++ b/arch/arm/dts/imx53.dtsi
@@ -0,0 +1,1092 @@
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ * Copyright 2011 Linaro Ltd.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include "skeleton.dtsi"
+#include "imx53-pinfunc.h"
+
+/ {
+	aliases {
+		serial0 = &uart1;
+		serial1 = &uart2;
+		serial2 = &uart3;
+		serial3 = &uart4;
+		serial4 = &uart5;
+		gpio0 = &gpio1;
+		gpio1 = &gpio2;
+		gpio2 = &gpio3;
+		gpio3 = &gpio4;
+		gpio4 = &gpio5;
+		gpio5 = &gpio6;
+		gpio6 = &gpio7;
+		mmc0 = &esdhc1;
+		mmc1 = &esdhc2;
+		mmc2 = &esdhc3;
+		mmc3 = &esdhc4;
+		i2c0 = &i2c1;
+		i2c1 = &i2c2;
+		i2c2 = &i2c3;
+	};
+
+	tzic: tz-interrupt-controller at 0fffc000 {
+		compatible = "fsl,imx53-tzic", "fsl,tzic";
+		interrupt-controller;
+		#interrupt-cells = <1>;
+		reg = <0x0fffc000 0x4000>;
+	};
+
+	clocks {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		ckil {
+			compatible = "fsl,imx-ckil", "fixed-clock";
+			clock-frequency = <32768>;
+		};
+
+		ckih1 {
+			compatible = "fsl,imx-ckih1", "fixed-clock";
+			clock-frequency = <22579200>;
+		};
+
+		ckih2 {
+			compatible = "fsl,imx-ckih2", "fixed-clock";
+			clock-frequency = <0>;
+		};
+
+		osc {
+			compatible = "fsl,imx-osc", "fixed-clock";
+			clock-frequency = <24000000>;
+		};
+	};
+
+	soc {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "simple-bus";
+		interrupt-parent = <&tzic>;
+		ranges;
+
+		ipu: ipu at 18000000 {
+			#crtc-cells = <1>;
+			compatible = "fsl,imx53-ipu";
+			reg = <0x18000000 0x080000000>;
+			interrupts = <11 10>;
+			clocks = <&clks 59>, <&clks 110>, <&clks 61>;
+			clock-names = "bus", "di0", "di1";
+			resets = <&src 2>;
+		};
+
+		aips at 50000000 { /* AIPS1 */
+			compatible = "fsl,aips-bus", "simple-bus";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			reg = <0x50000000 0x10000000>;
+			ranges;
+
+			spba at 50000000 {
+				compatible = "fsl,spba-bus", "simple-bus";
+				#address-cells = <1>;
+				#size-cells = <1>;
+				reg = <0x50000000 0x40000>;
+				ranges;
+
+				esdhc1: esdhc at 50004000 {
+					compatible = "fsl,imx53-esdhc";
+					reg = <0x50004000 0x4000>;
+					interrupts = <1>;
+					clocks = <&clks 44>, <&clks 0>, <&clks 71>;
+					clock-names = "ipg", "ahb", "per";
+					bus-width = <4>;
+					status = "disabled";
+				};
+
+				esdhc2: esdhc at 50008000 {
+					compatible = "fsl,imx53-esdhc";
+					reg = <0x50008000 0x4000>;
+					interrupts = <2>;
+					clocks = <&clks 45>, <&clks 0>, <&clks 72>;
+					clock-names = "ipg", "ahb", "per";
+					bus-width = <4>;
+					status = "disabled";
+				};
+
+				uart3: serial at 5000c000 {
+					compatible = "fsl,imx53-uart", "fsl,imx21-uart";
+					reg = <0x5000c000 0x4000>;
+					interrupts = <33>;
+					clocks = <&clks 32>, <&clks 33>;
+					clock-names = "ipg", "per";
+					status = "disabled";
+				};
+
+				ecspi1: ecspi at 50010000 {
+					#address-cells = <1>;
+					#size-cells = <0>;
+					compatible = "fsl,imx53-ecspi", "fsl,imx51-ecspi";
+					reg = <0x50010000 0x4000>;
+					interrupts = <36>;
+					clocks = <&clks 51>, <&clks 52>;
+					clock-names = "ipg", "per";
+					status = "disabled";
+				};
+
+				ssi2: ssi at 50014000 {
+					compatible = "fsl,imx53-ssi", "fsl,imx21-ssi";
+					reg = <0x50014000 0x4000>;
+					interrupts = <30>;
+					clocks = <&clks 49>;
+					fsl,fifo-depth = <15>;
+					fsl,ssi-dma-events = <25 24 23 22>; /* TX0 RX0 TX1 RX1 */
+					status = "disabled";
+				};
+
+				esdhc3: esdhc at 50020000 {
+					compatible = "fsl,imx53-esdhc";
+					reg = <0x50020000 0x4000>;
+					interrupts = <3>;
+					clocks = <&clks 46>, <&clks 0>, <&clks 73>;
+					clock-names = "ipg", "ahb", "per";
+					bus-width = <4>;
+					status = "disabled";
+				};
+
+				esdhc4: esdhc at 50024000 {
+					compatible = "fsl,imx53-esdhc";
+					reg = <0x50024000 0x4000>;
+					interrupts = <4>;
+					clocks = <&clks 47>, <&clks 0>, <&clks 74>;
+					clock-names = "ipg", "ahb", "per";
+					bus-width = <4>;
+					status = "disabled";
+				};
+			};
+
+			usbphy0: usbphy at 0 {
+				compatible = "usb-nop-xceiv";
+				clocks = <&clks 124>;
+				clock-names = "main_clk";
+				status = "okay";
+			};
+
+			usbphy1: usbphy at 1 {
+				compatible = "usb-nop-xceiv";
+				clocks = <&clks 125>;
+				clock-names = "main_clk";
+				status = "okay";
+			};
+
+			usbotg: usb at 53f80000 {
+				compatible = "fsl,imx53-usb", "fsl,imx27-usb";
+				reg = <0x53f80000 0x0200>;
+				interrupts = <18>;
+				clocks = <&clks 108>;
+				fsl,usbmisc = <&usbmisc 0>;
+				fsl,usbphy = <&usbphy0>;
+				status = "disabled";
+			};
+
+			usbh1: usb at 53f80200 {
+				compatible = "fsl,imx53-usb", "fsl,imx27-usb";
+				reg = <0x53f80200 0x0200>;
+				interrupts = <14>;
+				clocks = <&clks 108>;
+				fsl,usbmisc = <&usbmisc 1>;
+				fsl,usbphy = <&usbphy1>;
+				status = "disabled";
+			};
+
+			usbh2: usb at 53f80400 {
+				compatible = "fsl,imx53-usb", "fsl,imx27-usb";
+				reg = <0x53f80400 0x0200>;
+				interrupts = <16>;
+				clocks = <&clks 108>;
+				fsl,usbmisc = <&usbmisc 2>;
+				status = "disabled";
+			};
+
+			usbh3: usb at 53f80600 {
+				compatible = "fsl,imx53-usb", "fsl,imx27-usb";
+				reg = <0x53f80600 0x0200>;
+				interrupts = <17>;
+				clocks = <&clks 108>;
+				fsl,usbmisc = <&usbmisc 3>;
+				status = "disabled";
+			};
+
+			usbmisc: usbmisc at 53f80800 {
+				#index-cells = <1>;
+				compatible = "fsl,imx53-usbmisc";
+				reg = <0x53f80800 0x200>;
+				clocks = <&clks 108>;
+			};
+
+			gpio1: gpio at 53f84000 {
+				compatible = "fsl,imx53-gpio", "fsl,imx35-gpio";
+				reg = <0x53f84000 0x4000>;
+				interrupts = <50 51>;
+				gpio-controller;
+				#gpio-cells = <2>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+			};
+
+			gpio2: gpio at 53f88000 {
+				compatible = "fsl,imx53-gpio", "fsl,imx35-gpio";
+				reg = <0x53f88000 0x4000>;
+				interrupts = <52 53>;
+				gpio-controller;
+				#gpio-cells = <2>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+			};
+
+			gpio3: gpio at 53f8c000 {
+				compatible = "fsl,imx53-gpio", "fsl,imx35-gpio";
+				reg = <0x53f8c000 0x4000>;
+				interrupts = <54 55>;
+				gpio-controller;
+				#gpio-cells = <2>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+			};
+
+			gpio4: gpio at 53f90000 {
+				compatible = "fsl,imx53-gpio", "fsl,imx35-gpio";
+				reg = <0x53f90000 0x4000>;
+				interrupts = <56 57>;
+				gpio-controller;
+				#gpio-cells = <2>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+			};
+
+			wdog1: wdog at 53f98000 {
+				compatible = "fsl,imx53-wdt", "fsl,imx21-wdt";
+				reg = <0x53f98000 0x4000>;
+				interrupts = <58>;
+				clocks = <&clks 0>;
+			};
+
+			wdog2: wdog at 53f9c000 {
+				compatible = "fsl,imx53-wdt", "fsl,imx21-wdt";
+				reg = <0x53f9c000 0x4000>;
+				interrupts = <59>;
+				clocks = <&clks 0>;
+				status = "disabled";
+			};
+
+			gpt: timer at 53fa0000 {
+				compatible = "fsl,imx53-gpt", "fsl,imx31-gpt";
+				reg = <0x53fa0000 0x4000>;
+				interrupts = <39>;
+				clocks = <&clks 36>, <&clks 41>;
+				clock-names = "ipg", "per";
+			};
+
+			iomuxc: iomuxc at 53fa8000 {
+				compatible = "fsl,imx53-iomuxc";
+				reg = <0x53fa8000 0x4000>;
+
+				audmux {
+					pinctrl_audmux_1: audmuxgrp-1 {
+						fsl,pins = <
+							MX53_PAD_KEY_COL0__AUDMUX_AUD5_TXC  0x80000000
+							MX53_PAD_KEY_ROW0__AUDMUX_AUD5_TXD  0x80000000
+							MX53_PAD_KEY_COL1__AUDMUX_AUD5_TXFS 0x80000000
+							MX53_PAD_KEY_ROW1__AUDMUX_AUD5_RXD  0x80000000
+						>;
+					};
+
+					pinctrl_audmux_2: audmuxgrp-2 {
+						fsl,pins = <
+							MX53_PAD_SD2_DATA3__AUDMUX_AUD4_TXC	0x80000000
+							MX53_PAD_SD2_DATA2__AUDMUX_AUD4_TXD	0x80000000
+							MX53_PAD_SD2_DATA1__AUDMUX_AUD4_TXFS	0x80000000
+							MX53_PAD_SD2_DATA0__AUDMUX_AUD4_RXD	0x80000000
+						>;
+					};
+
+					pinctrl_audmux_3: audmuxgrp-3 {
+						fsl,pins = <
+							MX53_PAD_CSI0_DAT4__AUDMUX_AUD3_TXC	0x80000000
+							MX53_PAD_CSI0_DAT5__AUDMUX_AUD3_TXD	0x80000000
+							MX53_PAD_CSI0_DAT6__AUDMUX_AUD3_TXFS	0x80000000
+							MX53_PAD_CSI0_DAT7__AUDMUX_AUD3_RXD	0x80000000
+						>;
+					};
+				};
+
+				fec {
+					pinctrl_fec_1: fecgrp-1 {
+						fsl,pins = <
+							MX53_PAD_FEC_MDC__FEC_MDC	 0x80000000
+							MX53_PAD_FEC_MDIO__FEC_MDIO	 0x80000000
+							MX53_PAD_FEC_REF_CLK__FEC_TX_CLK 0x80000000
+							MX53_PAD_FEC_RX_ER__FEC_RX_ER    0x80000000
+							MX53_PAD_FEC_CRS_DV__FEC_RX_DV   0x80000000
+							MX53_PAD_FEC_RXD1__FEC_RDATA_1   0x80000000
+							MX53_PAD_FEC_RXD0__FEC_RDATA_0   0x80000000
+							MX53_PAD_FEC_TX_EN__FEC_TX_EN    0x80000000
+							MX53_PAD_FEC_TXD1__FEC_TDATA_1   0x80000000
+							MX53_PAD_FEC_TXD0__FEC_TDATA_0   0x80000000
+						>;
+					};
+
+					pinctrl_fec_2: fecgrp-2 {
+						fsl,pins = <
+							MX53_PAD_FEC_MDC__FEC_MDC	 0x80000000
+							MX53_PAD_FEC_MDIO__FEC_MDIO	 0x80000000
+							MX53_PAD_FEC_REF_CLK__FEC_TX_CLK 0x80000000
+							MX53_PAD_FEC_RX_ER__FEC_RX_ER    0x80000000
+							MX53_PAD_FEC_CRS_DV__FEC_RX_DV   0x80000000
+							MX53_PAD_FEC_RXD1__FEC_RDATA_1   0x80000000
+							MX53_PAD_FEC_RXD0__FEC_RDATA_0   0x80000000
+							MX53_PAD_FEC_TX_EN__FEC_TX_EN    0x80000000
+							MX53_PAD_FEC_TXD1__FEC_TDATA_1   0x80000000
+							MX53_PAD_FEC_TXD0__FEC_TDATA_0   0x80000000
+							MX53_PAD_KEY_ROW1__FEC_COL	 0x80000000
+							MX53_PAD_KEY_COL3__FEC_CRS	 0x80000000
+							MX53_PAD_KEY_COL2__FEC_RDATA_2	 0x80000000
+							MX53_PAD_KEY_COL0__FEC_RDATA_3	 0x80000000
+							MX53_PAD_KEY_COL1__FEC_RX_CLK	 0x80000000
+							MX53_PAD_KEY_ROW2__FEC_TDATA_2	 0x80000000
+							MX53_PAD_GPIO_19__FEC_TDATA_3	 0x80000000
+							MX53_PAD_KEY_ROW0__FEC_TX_ER	 0x80000000
+						>;
+					};
+				};
+
+				csi {
+					pinctrl_csi_1: csigrp-1 {
+						fsl,pins = <
+							MX53_PAD_CSI0_DATA_EN__IPU_CSI0_DATA_EN 0x1d5
+							MX53_PAD_CSI0_VSYNC__IPU_CSI0_VSYNC     0x1d5
+							MX53_PAD_CSI0_MCLK__IPU_CSI0_HSYNC      0x1d5
+							MX53_PAD_CSI0_PIXCLK__IPU_CSI0_PIXCLK   0x1d5
+							MX53_PAD_CSI0_DAT19__IPU_CSI0_D_19      0x1d5
+							MX53_PAD_CSI0_DAT18__IPU_CSI0_D_18      0x1d5
+							MX53_PAD_CSI0_DAT17__IPU_CSI0_D_17      0x1d5
+							MX53_PAD_CSI0_DAT16__IPU_CSI0_D_16      0x1d5
+							MX53_PAD_CSI0_DAT15__IPU_CSI0_D_15      0x1d5
+							MX53_PAD_CSI0_DAT14__IPU_CSI0_D_14      0x1d5
+							MX53_PAD_CSI0_DAT13__IPU_CSI0_D_13      0x1d5
+							MX53_PAD_CSI0_DAT12__IPU_CSI0_D_12      0x1d5
+							MX53_PAD_CSI0_DAT11__IPU_CSI0_D_11      0x1d5
+							MX53_PAD_CSI0_DAT10__IPU_CSI0_D_10      0x1d5
+							MX53_PAD_CSI0_DAT9__IPU_CSI0_D_9	0x1d5
+							MX53_PAD_CSI0_DAT8__IPU_CSI0_D_8	0x1d5
+							MX53_PAD_CSI0_DAT7__IPU_CSI0_D_7	0x1d5
+							MX53_PAD_CSI0_DAT6__IPU_CSI0_D_6	0x1d5
+							MX53_PAD_CSI0_DAT5__IPU_CSI0_D_5	0x1d5
+							MX53_PAD_CSI0_DAT4__IPU_CSI0_D_4	0x1d5
+							MX53_PAD_CSI0_PIXCLK__IPU_CSI0_PIXCLK   0x1d5
+						>;
+					};
+
+					pinctrl_csi_2: csigrp-2 {
+						fsl,pins = <
+							MX53_PAD_CSI0_VSYNC__IPU_CSI0_VSYNC	0x1d5
+							MX53_PAD_CSI0_MCLK__IPU_CSI0_HSYNC	0x1d5
+							MX53_PAD_CSI0_PIXCLK__IPU_CSI0_PIXCLK	0x1d5
+							MX53_PAD_CSI0_DAT19__IPU_CSI0_D_19	0x1d5
+							MX53_PAD_CSI0_DAT18__IPU_CSI0_D_18	0x1d5
+							MX53_PAD_CSI0_DAT17__IPU_CSI0_D_17	0x1d5
+							MX53_PAD_CSI0_DAT16__IPU_CSI0_D_16	0x1d5
+							MX53_PAD_CSI0_DAT15__IPU_CSI0_D_15	0x1d5
+							MX53_PAD_CSI0_DAT14__IPU_CSI0_D_14	0x1d5
+							MX53_PAD_CSI0_DAT13__IPU_CSI0_D_13	0x1d5
+							MX53_PAD_CSI0_DAT12__IPU_CSI0_D_12	0x1d5
+						>;
+					};
+				};
+
+				cspi {
+					pinctrl_cspi_1: cspigrp-1 {
+						fsl,pins = <
+							MX53_PAD_SD1_DATA0__CSPI_MISO 0x1d5
+							MX53_PAD_SD1_CMD__CSPI_MOSI   0x1d5
+							MX53_PAD_SD1_CLK__CSPI_SCLK   0x1d5
+						>;
+					};
+
+					pinctrl_cspi_2: cspigrp-2 {
+						fsl,pins = <
+							MX53_PAD_EIM_D22__CSPI_MISO 0x1d5
+							MX53_PAD_EIM_D28__CSPI_MOSI 0x1d5
+							MX53_PAD_EIM_D21__CSPI_SCLK 0x1d5
+						>;
+					};
+				};
+
+				ecspi1 {
+					pinctrl_ecspi1_1: ecspi1grp-1 {
+						fsl,pins = <
+							MX53_PAD_EIM_D16__ECSPI1_SCLK 0x80000000
+							MX53_PAD_EIM_D17__ECSPI1_MISO 0x80000000
+							MX53_PAD_EIM_D18__ECSPI1_MOSI 0x80000000
+						>;
+					};
+
+					pinctrl_ecspi1_2: ecspi1grp-2 {
+						fsl,pins = <
+							MX53_PAD_GPIO_19__ECSPI1_RDY	0x80000000
+							MX53_PAD_EIM_EB2__ECSPI1_SS0	0x80000000
+							MX53_PAD_EIM_D16__ECSPI1_SCLK	0x80000000
+							MX53_PAD_EIM_D17__ECSPI1_MISO	0x80000000
+							MX53_PAD_EIM_D18__ECSPI1_MOSI	0x80000000
+							MX53_PAD_EIM_D19__ECSPI1_SS1	0x80000000
+						>;
+					};
+				};
+
+				ecspi2 {
+					pinctrl_ecspi2_1: ecspi2grp-1 {
+						fsl,pins = <
+							MX53_PAD_EIM_OE__ECSPI2_MISO  0x80000000
+							MX53_PAD_EIM_CS1__ECSPI2_MOSI 0x80000000
+							MX53_PAD_EIM_CS0__ECSPI2_SCLK 0x80000000
+						>;
+					};
+				};
+
+				esdhc1 {
+					pinctrl_esdhc1_1: esdhc1grp-1 {
+						fsl,pins = <
+							MX53_PAD_SD1_DATA0__ESDHC1_DAT0 0x1d5
+							MX53_PAD_SD1_DATA1__ESDHC1_DAT1 0x1d5
+							MX53_PAD_SD1_DATA2__ESDHC1_DAT2 0x1d5
+							MX53_PAD_SD1_DATA3__ESDHC1_DAT3 0x1d5
+							MX53_PAD_SD1_CMD__ESDHC1_CMD	0x1d5
+							MX53_PAD_SD1_CLK__ESDHC1_CLK	0x1d5
+						>;
+					};
+
+					pinctrl_esdhc1_2: esdhc1grp-2 {
+						fsl,pins = <
+							MX53_PAD_SD1_DATA0__ESDHC1_DAT0   0x1d5
+							MX53_PAD_SD1_DATA1__ESDHC1_DAT1   0x1d5
+							MX53_PAD_SD1_DATA2__ESDHC1_DAT2   0x1d5
+							MX53_PAD_SD1_DATA3__ESDHC1_DAT3   0x1d5
+							MX53_PAD_PATA_DATA8__ESDHC1_DAT4  0x1d5
+							MX53_PAD_PATA_DATA9__ESDHC1_DAT5  0x1d5
+							MX53_PAD_PATA_DATA10__ESDHC1_DAT6 0x1d5
+							MX53_PAD_PATA_DATA11__ESDHC1_DAT7 0x1d5
+							MX53_PAD_SD1_CMD__ESDHC1_CMD	  0x1d5
+							MX53_PAD_SD1_CLK__ESDHC1_CLK	  0x1d5
+						>;
+					};
+				};
+
+				esdhc2 {
+					pinctrl_esdhc2_1: esdhc2grp-1 {
+						fsl,pins = <
+							MX53_PAD_SD2_CMD__ESDHC2_CMD	0x1d5
+							MX53_PAD_SD2_CLK__ESDHC2_CLK	0x1d5
+							MX53_PAD_SD2_DATA0__ESDHC2_DAT0 0x1d5
+							MX53_PAD_SD2_DATA1__ESDHC2_DAT1 0x1d5
+							MX53_PAD_SD2_DATA2__ESDHC2_DAT2 0x1d5
+							MX53_PAD_SD2_DATA3__ESDHC2_DAT3 0x1d5
+						>;
+					};
+				};
+
+				esdhc3 {
+					pinctrl_esdhc3_1: esdhc3grp-1 {
+						fsl,pins = <
+							MX53_PAD_PATA_DATA8__ESDHC3_DAT0  0x1d5
+							MX53_PAD_PATA_DATA9__ESDHC3_DAT1  0x1d5
+							MX53_PAD_PATA_DATA10__ESDHC3_DAT2 0x1d5
+							MX53_PAD_PATA_DATA11__ESDHC3_DAT3 0x1d5
+							MX53_PAD_PATA_DATA0__ESDHC3_DAT4  0x1d5
+							MX53_PAD_PATA_DATA1__ESDHC3_DAT5  0x1d5
+							MX53_PAD_PATA_DATA2__ESDHC3_DAT6  0x1d5
+							MX53_PAD_PATA_DATA3__ESDHC3_DAT7  0x1d5
+							MX53_PAD_PATA_RESET_B__ESDHC3_CMD 0x1d5
+							MX53_PAD_PATA_IORDY__ESDHC3_CLK   0x1d5
+						>;
+					};
+				};
+
+				can1 {
+					pinctrl_can1_1: can1grp-1 {
+						fsl,pins = <
+							MX53_PAD_PATA_INTRQ__CAN1_TXCAN 0x80000000
+							MX53_PAD_PATA_DIOR__CAN1_RXCAN  0x80000000
+						>;
+					};
+
+					pinctrl_can1_2: can1grp-2 {
+						fsl,pins = <
+							MX53_PAD_KEY_COL2__CAN1_TXCAN 0x80000000
+							MX53_PAD_KEY_ROW2__CAN1_RXCAN 0x80000000
+						>;
+					};
+
+					pinctrl_can1_3: can1grp-3 {
+						fsl,pins = <
+							MX53_PAD_GPIO_7__CAN1_TXCAN	0x80000000
+							MX53_PAD_GPIO_8__CAN1_RXCAN	0x80000000
+						>;
+					};
+				};
+
+				can2 {
+					pinctrl_can2_1: can2grp-1 {
+						fsl,pins = <
+							MX53_PAD_KEY_COL4__CAN2_TXCAN 0x80000000
+							MX53_PAD_KEY_ROW4__CAN2_RXCAN 0x80000000
+						>;
+					};
+				};
+
+				i2c1 {
+					pinctrl_i2c1_1: i2c1grp-1 {
+						fsl,pins = <
+							MX53_PAD_CSI0_DAT8__I2C1_SDA 0xc0000000
+							MX53_PAD_CSI0_DAT9__I2C1_SCL 0xc0000000
+						>;
+					};
+
+					pinctrl_i2c1_2: i2c1grp-2 {
+						fsl,pins = <
+							MX53_PAD_EIM_D21__I2C1_SCL	0xc0000000
+							MX53_PAD_EIM_D28__I2C1_SDA	0xc0000000
+						>;
+					};
+				};
+
+				i2c2 {
+					pinctrl_i2c2_1: i2c2grp-1 {
+						fsl,pins = <
+							MX53_PAD_KEY_ROW3__I2C2_SDA 0xc0000000
+							MX53_PAD_KEY_COL3__I2C2_SCL 0xc0000000
+						>;
+					};
+
+					pinctrl_i2c2_2: i2c2grp-2 {
+						fsl,pins = <
+							MX53_PAD_EIM_D16__I2C2_SDA	0xc0000000
+							MX53_PAD_EIM_EB2__I2C2_SCL	0xc0000000
+						>;
+					};
+				};
+
+				i2c3 {
+					pinctrl_i2c3_1: i2c3grp-1 {
+						fsl,pins = <
+							MX53_PAD_GPIO_6__I2C3_SDA 0xc0000000
+							MX53_PAD_GPIO_5__I2C3_SCL 0xc0000000
+						>;
+					};
+				};
+
+				ipu_disp0 {
+					pinctrl_ipu_disp0_1: ipudisp0grp-1 {
+						fsl,pins = <
+						MX53_PAD_DI0_DISP_CLK__IPU_DI0_DISP_CLK	0x5
+						MX53_PAD_DI0_PIN15__IPU_DI0_PIN15		0x5
+						MX53_PAD_DI0_PIN2__IPU_DI0_PIN2		0x5
+						MX53_PAD_DI0_PIN3__IPU_DI0_PIN3 		0x5
+						MX53_PAD_DISP0_DAT0__IPU_DISP0_DAT_0		0x5
+						MX53_PAD_DISP0_DAT1__IPU_DISP0_DAT_1		0x5
+						MX53_PAD_DISP0_DAT2__IPU_DISP0_DAT_2		0x5
+						MX53_PAD_DISP0_DAT3__IPU_DISP0_DAT_3		0x5
+						MX53_PAD_DISP0_DAT4__IPU_DISP0_DAT_4		0x5
+						MX53_PAD_DISP0_DAT5__IPU_DISP0_DAT_5		0x5
+						MX53_PAD_DISP0_DAT6__IPU_DISP0_DAT_6		0x5
+						MX53_PAD_DISP0_DAT7__IPU_DISP0_DAT_7		0x5
+						MX53_PAD_DISP0_DAT8__IPU_DISP0_DAT_8		0x5
+						MX53_PAD_DISP0_DAT9__IPU_DISP0_DAT_9		0x5
+						MX53_PAD_DISP0_DAT10__IPU_DISP0_DAT_10		0x5
+						MX53_PAD_DISP0_DAT11__IPU_DISP0_DAT_11		0x5
+						MX53_PAD_DISP0_DAT12__IPU_DISP0_DAT_12		0x5
+						MX53_PAD_DISP0_DAT13__IPU_DISP0_DAT_13		0x5
+						MX53_PAD_DISP0_DAT14__IPU_DISP0_DAT_14		0x5
+						MX53_PAD_DISP0_DAT15__IPU_DISP0_DAT_15		0x5
+						MX53_PAD_DISP0_DAT16__IPU_DISP0_DAT_16		0x5
+						MX53_PAD_DISP0_DAT17__IPU_DISP0_DAT_17		0x5
+						MX53_PAD_DISP0_DAT18__IPU_DISP0_DAT_18		0x5
+						MX53_PAD_DISP0_DAT19__IPU_DISP0_DAT_19		0x5
+						MX53_PAD_DISP0_DAT20__IPU_DISP0_DAT_20		0x5
+						MX53_PAD_DISP0_DAT21__IPU_DISP0_DAT_21		0x5
+						MX53_PAD_DISP0_DAT22__IPU_DISP0_DAT_22		0x5
+						MX53_PAD_DISP0_DAT23__IPU_DISP0_DAT_23		0x5
+						>;
+					};
+				};
+
+				ipu_disp1 {
+					pinctrl_ipu_disp1_1: ipudisp1grp-1 {
+						fsl,pins = <
+							MX53_PAD_EIM_DA9__IPU_DISP1_DAT_0	0x5
+							MX53_PAD_EIM_DA8__IPU_DISP1_DAT_1	0x5
+							MX53_PAD_EIM_DA7__IPU_DISP1_DAT_2	0x5
+							MX53_PAD_EIM_DA6__IPU_DISP1_DAT_3	0x5
+							MX53_PAD_EIM_DA5__IPU_DISP1_DAT_4	0x5
+							MX53_PAD_EIM_DA4__IPU_DISP1_DAT_5	0x5
+							MX53_PAD_EIM_DA3__IPU_DISP1_DAT_6	0x5
+							MX53_PAD_EIM_DA2__IPU_DISP1_DAT_7	0x5
+							MX53_PAD_EIM_DA1__IPU_DISP1_DAT_8	0x5
+							MX53_PAD_EIM_DA0__IPU_DISP1_DAT_9	0x5
+							MX53_PAD_EIM_EB1__IPU_DISP1_DAT_10	0x5
+							MX53_PAD_EIM_EB0__IPU_DISP1_DAT_11	0x5
+							MX53_PAD_EIM_A17__IPU_DISP1_DAT_12	0x5
+							MX53_PAD_EIM_A18__IPU_DISP1_DAT_13	0x5
+							MX53_PAD_EIM_A19__IPU_DISP1_DAT_14	0x5
+							MX53_PAD_EIM_A20__IPU_DISP1_DAT_15	0x5
+							MX53_PAD_EIM_A21__IPU_DISP1_DAT_16	0x5
+							MX53_PAD_EIM_A22__IPU_DISP1_DAT_17	0x5
+							MX53_PAD_EIM_A23__IPU_DISP1_DAT_18	0x5
+							MX53_PAD_EIM_A24__IPU_DISP1_DAT_19	0x5
+							MX53_PAD_EIM_D31__IPU_DISP1_DAT_20	0x5
+							MX53_PAD_EIM_D30__IPU_DISP1_DAT_21	0x5
+							MX53_PAD_EIM_D26__IPU_DISP1_DAT_22	0x5
+							MX53_PAD_EIM_D27__IPU_DISP1_DAT_23	0x5
+							MX53_PAD_EIM_A16__IPU_DI1_DISP_CLK	0x5
+							MX53_PAD_EIM_DA13__IPU_DI1_D0_CS	0x5
+							MX53_PAD_EIM_DA14__IPU_DI1_D1_CS	0x5
+							MX53_PAD_EIM_DA15__IPU_DI1_PIN1		0x5
+							MX53_PAD_EIM_DA11__IPU_DI1_PIN2		0x5
+							MX53_PAD_EIM_DA12__IPU_DI1_PIN3		0x5
+							MX53_PAD_EIM_A25__IPU_DI1_PIN12		0x5
+							MX53_PAD_EIM_DA10__IPU_DI1_PIN15	0x5
+						>;
+					};
+				};
+
+				ipu_disp2 {
+					pinctrl_ipu_disp2_1: ipudisp2grp-1 {
+						fsl,pins = <
+							MX53_PAD_LVDS0_TX0_P__LDB_LVDS0_TX0	0x80000000
+							MX53_PAD_LVDS0_TX1_P__LDB_LVDS0_TX1	0x80000000
+							MX53_PAD_LVDS0_TX2_P__LDB_LVDS0_TX2	0x80000000
+							MX53_PAD_LVDS0_TX3_P__LDB_LVDS0_TX3	0x80000000
+							MX53_PAD_LVDS0_CLK_P__LDB_LVDS0_CLK	0x80000000
+							MX53_PAD_LVDS1_TX0_P__LDB_LVDS1_TX0	0x80000000
+							MX53_PAD_LVDS1_TX1_P__LDB_LVDS1_TX1	0x80000000
+							MX53_PAD_LVDS1_TX2_P__LDB_LVDS1_TX2	0x80000000
+							MX53_PAD_LVDS1_TX3_P__LDB_LVDS1_TX3	0x80000000
+							MX53_PAD_LVDS1_CLK_P__LDB_LVDS1_CLK	0x80000000
+						>;
+					};
+				};
+
+				nand {
+					pinctrl_nand_1: nandgrp-1 {
+						fsl,pins = <
+							MX53_PAD_NANDF_WE_B__EMI_NANDF_WE_B	0x4
+							MX53_PAD_NANDF_RE_B__EMI_NANDF_RE_B	0x4
+							MX53_PAD_NANDF_CLE__EMI_NANDF_CLE	0x4
+							MX53_PAD_NANDF_ALE__EMI_NANDF_ALE	0x4
+							MX53_PAD_NANDF_WP_B__EMI_NANDF_WP_B	0xe0
+							MX53_PAD_NANDF_RB0__EMI_NANDF_RB_0	0xe0
+							MX53_PAD_NANDF_CS0__EMI_NANDF_CS_0	0x4
+							MX53_PAD_PATA_DATA0__EMI_NANDF_D_0	0xa4
+							MX53_PAD_PATA_DATA1__EMI_NANDF_D_1	0xa4
+							MX53_PAD_PATA_DATA2__EMI_NANDF_D_2	0xa4
+							MX53_PAD_PATA_DATA3__EMI_NANDF_D_3	0xa4
+							MX53_PAD_PATA_DATA4__EMI_NANDF_D_4	0xa4
+							MX53_PAD_PATA_DATA5__EMI_NANDF_D_5	0xa4
+							MX53_PAD_PATA_DATA6__EMI_NANDF_D_6	0xa4
+							MX53_PAD_PATA_DATA7__EMI_NANDF_D_7	0xa4
+						>;
+					};
+				};
+
+				owire {
+					pinctrl_owire_1: owiregrp-1 {
+						fsl,pins = <
+							MX53_PAD_GPIO_18__OWIRE_LINE 0x80000000
+						>;
+					};
+				};
+
+				pwm1 {
+					pinctrl_pwm1_1: pwm1grp-1 {
+						fsl,pins = <
+							MX53_PAD_DISP0_DAT8__PWM1_PWMO	0x5
+						>;
+					};
+				};
+
+				pwm2 {
+					pinctrl_pwm2_1: pwm2grp-1 {
+						fsl,pins = <
+							MX53_PAD_GPIO_1__PWM2_PWMO	0x80000000
+						>;
+					};
+				};
+
+				uart1 {
+					pinctrl_uart1_1: uart1grp-1 {
+						fsl,pins = <
+							MX53_PAD_CSI0_DAT10__UART1_TXD_MUX 0x1c5
+							MX53_PAD_CSI0_DAT11__UART1_RXD_MUX 0x1c5
+						>;
+					};
+
+					pinctrl_uart1_2: uart1grp-2 {
+						fsl,pins = <
+							MX53_PAD_PATA_DIOW__UART1_TXD_MUX  0x1c5
+							MX53_PAD_PATA_DMACK__UART1_RXD_MUX 0x1c5
+						>;
+					};
+
+					pinctrl_uart1_3: uart1grp-3 {
+						fsl,pins = <
+							MX53_PAD_PATA_RESET_B__UART1_CTS 0x1c5
+							MX53_PAD_PATA_IORDY__UART1_RTS	 0x1c5
+						>;
+					};
+				};
+
+				uart2 {
+					pinctrl_uart2_1: uart2grp-1 {
+						fsl,pins = <
+							MX53_PAD_PATA_BUFFER_EN__UART2_RXD_MUX 0x1c5
+							MX53_PAD_PATA_DMARQ__UART2_TXD_MUX     0x1c5
+						>;
+					};
+
+					pinctrl_uart2_2: uart2grp-2 {
+						fsl,pins = <
+							MX53_PAD_PATA_BUFFER_EN__UART2_RXD_MUX	0x1c5
+							MX53_PAD_PATA_DMARQ__UART2_TXD_MUX	0x1c5
+							MX53_PAD_PATA_DIOR__UART2_RTS		0x1c5
+							MX53_PAD_PATA_INTRQ__UART2_CTS		0x1c5
+						>;
+					};
+				};
+
+				uart3 {
+					pinctrl_uart3_1: uart3grp-1 {
+						fsl,pins = <
+							MX53_PAD_PATA_CS_0__UART3_TXD_MUX 0x1c5
+							MX53_PAD_PATA_CS_1__UART3_RXD_MUX 0x1c5
+							MX53_PAD_PATA_DA_1__UART3_CTS	  0x1c5
+							MX53_PAD_PATA_DA_2__UART3_RTS	  0x1c5
+						>;
+					};
+
+					pinctrl_uart3_2: uart3grp-2 {
+						fsl,pins = <
+							MX53_PAD_PATA_CS_0__UART3_TXD_MUX 0x1c5
+							MX53_PAD_PATA_CS_1__UART3_RXD_MUX 0x1c5
+						>;
+					};
+
+				};
+
+				uart4 {
+					pinctrl_uart4_1: uart4grp-1 {
+						fsl,pins = <
+							MX53_PAD_KEY_COL0__UART4_TXD_MUX 0x1c5
+							MX53_PAD_KEY_ROW0__UART4_RXD_MUX 0x1c5
+						>;
+					};
+				};
+
+				uart5 {
+					pinctrl_uart5_1: uart5grp-1 {
+						fsl,pins = <
+							MX53_PAD_KEY_COL1__UART5_TXD_MUX 0x1c5
+							MX53_PAD_KEY_ROW1__UART5_RXD_MUX 0x1c5
+						>;
+					};
+				};
+			};
+
+			gpr: iomuxc-gpr at 53fa8000 {
+				compatible = "fsl,imx53-iomuxc-gpr", "syscon";
+				reg = <0x53fa8000 0xc>;
+			};
+
+			ldb: ldb at 53fa8008 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				compatible = "fsl,imx53-ldb";
+				reg = <0x53fa8008 0x4>;
+				gpr = <&gpr>;
+				clocks = <&clks 122>, <&clks 120>,
+					 <&clks 115>, <&clks 116>,
+					 <&clks 123>, <&clks 85>;
+				clock-names = "di0_pll", "di1_pll",
+					      "di0_sel", "di1_sel",
+					      "di0", "di1";
+				status = "disabled";
+
+				lvds-channel at 0 {
+					reg = <0>;
+					crtcs = <&ipu 0>;
+					status = "disabled";
+				};
+
+				lvds-channel at 1 {
+					reg = <1>;
+					crtcs = <&ipu 1>;
+					status = "disabled";
+				};
+			};
+
+			pwm1: pwm at 53fb4000 {
+				#pwm-cells = <2>;
+				compatible = "fsl,imx53-pwm", "fsl,imx27-pwm";
+				reg = <0x53fb4000 0x4000>;
+				clocks = <&clks 37>, <&clks 38>;
+				clock-names = "ipg", "per";
+				interrupts = <61>;
+			};
+
+			pwm2: pwm at 53fb8000 {
+				#pwm-cells = <2>;
+				compatible = "fsl,imx53-pwm", "fsl,imx27-pwm";
+				reg = <0x53fb8000 0x4000>;
+				clocks = <&clks 39>, <&clks 40>;
+				clock-names = "ipg", "per";
+				interrupts = <94>;
+			};
+
+			uart1: serial at 53fbc000 {
+				compatible = "fsl,imx53-uart", "fsl,imx21-uart";
+				reg = <0x53fbc000 0x4000>;
+				interrupts = <31>;
+				clocks = <&clks 28>, <&clks 29>;
+				clock-names = "ipg", "per";
+				status = "disabled";
+			};
+
+			uart2: serial at 53fc0000 {
+				compatible = "fsl,imx53-uart", "fsl,imx21-uart";
+				reg = <0x53fc0000 0x4000>;
+				interrupts = <32>;
+				clocks = <&clks 30>, <&clks 31>;
+				clock-names = "ipg", "per";
+				status = "disabled";
+			};
+
+			can1: can at 53fc8000 {
+				compatible = "fsl,imx53-flexcan", "fsl,p1010-flexcan";
+				reg = <0x53fc8000 0x4000>;
+				interrupts = <82>;
+				clocks = <&clks 158>, <&clks 157>;
+				clock-names = "ipg", "per";
+				status = "disabled";
+			};
+
+			can2: can at 53fcc000 {
+				compatible = "fsl,imx53-flexcan", "fsl,p1010-flexcan";
+				reg = <0x53fcc000 0x4000>;
+				interrupts = <83>;
+				clocks = <&clks 87>, <&clks 86>;
+				clock-names = "ipg", "per";
+				status = "disabled";
+			};
+
+			src: src at 53fd0000 {
+				compatible = "fsl,imx53-src", "fsl,imx51-src";
+				reg = <0x53fd0000 0x4000>;
+				#reset-cells = <1>;
+			};
+
+			clks: ccm at 53fd4000{
+				compatible = "fsl,imx53-ccm";
+				reg = <0x53fd4000 0x4000>;
+				interrupts = <0 71 0x04 0 72 0x04>;
+				#clock-cells = <1>;
+			};
+
+			gpio5: gpio at 53fdc000 {
+				compatible = "fsl,imx53-gpio", "fsl,imx35-gpio";
+				reg = <0x53fdc000 0x4000>;
+				interrupts = <103 104>;
+				gpio-controller;
+				#gpio-cells = <2>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+			};
+
+			gpio6: gpio at 53fe0000 {
+				compatible = "fsl,imx53-gpio", "fsl,imx35-gpio";
+				reg = <0x53fe0000 0x4000>;
+				interrupts = <105 106>;
+				gpio-controller;
+				#gpio-cells = <2>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+			};
+
+			gpio7: gpio at 53fe4000 {
+				compatible = "fsl,imx53-gpio", "fsl,imx35-gpio";
+				reg = <0x53fe4000 0x4000>;
+				interrupts = <107 108>;
+				gpio-controller;
+				#gpio-cells = <2>;
+				interrupt-controller;
+				#interrupt-cells = <2>;
+			};
+
+			i2c3: i2c at 53fec000 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				compatible = "fsl,imx53-i2c", "fsl,imx21-i2c";
+				reg = <0x53fec000 0x4000>;
+				interrupts = <64>;
+				clocks = <&clks 88>;
+				status = "disabled";
+			};
+
+			uart4: serial at 53ff0000 {
+				compatible = "fsl,imx53-uart", "fsl,imx21-uart";
+				reg = <0x53ff0000 0x4000>;
+				interrupts = <13>;
+				clocks = <&clks 65>, <&clks 66>;
+				clock-names = "ipg", "per";
+				status = "disabled";
+			};
+		};
+
+		aips at 60000000 {	/* AIPS2 */
+			compatible = "fsl,aips-bus", "simple-bus";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			reg = <0x60000000 0x10000000>;
+			ranges;
+
+			iim: iim at 63f98000 {
+				compatible = "fsl,imx53-iim", "fsl,imx-iim";
+				reg = <0x63f98000 0x4000>;
+				interrupts = <69>;
+				clocks = <&clks 107>;
+			};
+
+			uart5: serial at 63f90000 {
+				compatible = "fsl,imx53-uart", "fsl,imx21-uart";
+				reg = <0x63f90000 0x4000>;
+				interrupts = <86>;
+				clocks = <&clks 67>, <&clks 68>;
+				clock-names = "ipg", "per";
+				status = "disabled";
+			};
+
+			owire: owire at 63fa4000 {
+				compatible = "fsl,imx53-owire", "fsl,imx21-owire";
+				reg = <0x63fa4000 0x4000>;
+				clocks = <&clks 159>;
+				status = "disabled";
+			};
+
+			ecspi2: ecspi at 63fac000 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				compatible = "fsl,imx53-ecspi", "fsl,imx51-ecspi";
+				reg = <0x63fac000 0x4000>;
+				interrupts = <37>;
+				clocks = <&clks 53>, <&clks 54>;
+				clock-names = "ipg", "per";
+				status = "disabled";
+			};
+
+			sdma: sdma at 63fb0000 {
+				compatible = "fsl,imx53-sdma", "fsl,imx35-sdma";
+				reg = <0x63fb0000 0x4000>;
+				interrupts = <6>;
+				clocks = <&clks 56>, <&clks 56>;
+				clock-names = "ipg", "ahb";
+				fsl,sdma-ram-script-name = "imx/sdma/sdma-imx53.bin";
+			};
+
+			cspi: cspi at 63fc0000 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				compatible = "fsl,imx53-cspi", "fsl,imx35-cspi";
+				reg = <0x63fc0000 0x4000>;
+				interrupts = <38>;
+				clocks = <&clks 55>, <&clks 55>;
+				clock-names = "ipg", "per";
+				status = "disabled";
+			};
+
+			i2c2: i2c at 63fc4000 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				compatible = "fsl,imx53-i2c", "fsl,imx21-i2c";
+				reg = <0x63fc4000 0x4000>;
+				interrupts = <63>;
+				clocks = <&clks 35>;
+				status = "disabled";
+			};
+
+			i2c1: i2c at 63fc8000 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				compatible = "fsl,imx53-i2c", "fsl,imx21-i2c";
+				reg = <0x63fc8000 0x4000>;
+				interrupts = <62>;
+				clocks = <&clks 34>;
+				status = "disabled";
+			};
+
+			ssi1: ssi at 63fcc000 {
+				compatible = "fsl,imx53-ssi", "fsl,imx21-ssi";
+				reg = <0x63fcc000 0x4000>;
+				interrupts = <29>;
+				clocks = <&clks 48>;
+				fsl,fifo-depth = <15>;
+				fsl,ssi-dma-events = <29 28 27 26>; /* TX0 RX0 TX1 RX1 */
+				status = "disabled";
+			};
+
+			audmux: audmux at 63fd0000 {
+				compatible = "fsl,imx53-audmux", "fsl,imx31-audmux";
+				reg = <0x63fd0000 0x4000>;
+				status = "disabled";
+			};
+
+			nfc: nand at 63fdb000 {
+				compatible = "fsl,imx53-nand";
+				reg = <0x63fdb000 0x1000 0xf7ff0000 0x10000>;
+				interrupts = <8>;
+				clocks = <&clks 60>;
+				status = "disabled";
+			};
+
+			ssi3: ssi at 63fe8000 {
+				compatible = "fsl,imx53-ssi", "fsl,imx21-ssi";
+				reg = <0x63fe8000 0x4000>;
+				interrupts = <96>;
+				clocks = <&clks 50>;
+				fsl,fifo-depth = <15>;
+				fsl,ssi-dma-events = <47 46 45 44>; /* TX0 RX0 TX1 RX1 */
+				status = "disabled";
+			};
+
+			fec: ethernet at 63fec000 {
+				compatible = "fsl,imx53-fec", "fsl,imx25-fec";
+				reg = <0x63fec000 0x4000>;
+				interrupts = <87>;
+				clocks = <&clks 42>, <&clks 42>, <&clks 42>;
+				clock-names = "ipg", "ahb", "ptp";
+				status = "disabled";
+			};
+
+			tve: tve at 63ff0000 {
+				compatible = "fsl,imx53-tve";
+				reg = <0x63ff0000 0x1000>;
+				interrupts = <92>;
+				clocks = <&clks 69>, <&clks 116>;
+				clock-names = "tve", "di_sel";
+				crtcs = <&ipu 1>;
+				status = "disabled";
+			};
+		};
+	};
+};
-- 
1.8.3.1



From j.weitzel at phytec.de  Mon Jun 24 08:08:42 2013
From: j.weitzel at phytec.de (Jan Weitzel)
Date: Mon, 24 Jun 2013 14:08:42 +0200
Subject: [PATCH] nand_base: fix chipsize for multi LUN nands
Message-ID: <1372075722-9872-1-git-send-email-j.weitzel@phytec.de>

Chipsize didn't take number of LUNs into account. Sync chipsize calculation
to kernel commit 63795755
Tested with MT29F8G16ADBDAH4 on OMAP4

Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
---
 drivers/mtd/nand/nand_base.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 8c14112..1969aff 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1117,7 +1117,8 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
 	mtd->writesize = le32_to_cpu(p->byte_per_page);
 	mtd->erasesize = le32_to_cpu(p->pages_per_block) * mtd->writesize;
 	mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page);
-	chip->chipsize = (uint64_t)le32_to_cpu(p->blocks_per_lun) * mtd->erasesize;
+	chip->chipsize = le32_to_cpu(p->blocks_per_lun);
+	chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count;
 	*busw = 0;
 	if (le16_to_cpu(p->features) & 1)
 		*busw = NAND_BUSWIDTH_16;
-- 
1.7.0.4



From hiroki.nishimoto.if at gmail.com  Mon Jun 24 08:18:49 2013
From: hiroki.nishimoto.if at gmail.com (NISHIMOTO Hiroki)
Date: Mon, 24 Jun 2013 21:18:49 +0900
Subject: [PATCH] ns16550: add device tree support
Message-ID: <51C83929.70001@gmail.com>

This patch adds device tree support for serial_ns16550 driver.

Tested with pcduino (allwinner a10).

Signed-off-by: NISHIMOTO Hiroki <hiroki.nishimoto.if at gmail.com>
---
 .../devicetree/bindings/serial/ns16550_serial.txt  | 34 ++++++++++++++
 drivers/serial/serial_ns16550.c                    | 53 ++++++++++++++++++++--
 2 files changed, 84 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/serial/ns16550_serial.txt

diff --git a/Documentation/devicetree/bindings/serial/ns16550_serial.txt b/Documentation/devicetree/bindings/serial/ns16550_serial.txt
new file mode 100644
index 0000000..848f949
--- /dev/null
+++ b/Documentation/devicetree/bindings/serial/ns16550_serial.txt
@@ -0,0 +1,34 @@
+* NS16550 UART
+
+Required properties:
+- compatible : "ns16550_serial"
+- reg : offset and length of the register set for the device.
+
+
+Optional properties:
+- clock-frequency : the input clock frequency for the UART.
+- reg-shift : quantity to shift the register offsets by.  If this property is
+  not present then the register offsets are not shifted.
+- reg-io-width : the size (in bytes) of the IO accesses that should be
+  performed on the device.  If this property is not present then single byte
+  accesses are used.
+- disable-fifo : 
+	0: enable tx/rx fifo (default value)
+	1: disable tx/rx fifo 
+- console-stdin : activate stdin on this console.
+- console-stdout : activate stdout on this console.
+- console-stderr : activate stderr on this console.
+
+Example:
+
+	serial at 0x01c28000 {
+		compatible = "ns16550_serial";
+		reg = <0x01c28000 0x400>;
+		clock-frequency = <24000000>;
+		reg-shift = <2>;
+		reg-io-width = <4>;
+		disable-fifo = <0>;
+		console-stdin;
+		console-stdout;
+		console-stderr;
+	};
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index b7913aa..bed9640 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -57,7 +57,7 @@ static uint32_t ns16550_read(struct console_device *cdev, uint32_t off)
 {
 	struct device_d *dev = cdev->dev;
 	struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
-	int width = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
+	int width = plat->flags & IORESOURCE_MEM_TYPE_MASK;
 
 	off <<= plat->shift;
 
@@ -87,7 +87,7 @@ static void ns16550_write(struct console_device *cdev, uint32_t val,
 {
 	struct device_d *dev = cdev->dev;
 	struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
-	int width = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
+	int width = plat->flags & IORESOURCE_MEM_TYPE_MASK;
 
 	off <<= plat->shift;
 
@@ -234,8 +234,46 @@ static int ns16550_probe(struct device_d *dev)
 	struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
 
 	/* we do expect platform specific data */
-	if (plat == NULL)
+	if (!plat && !dev->device_node)
 		return -EINVAL;
+
+	if (dev->device_node) {
+		unsigned int width, fifo;
+		struct device_node *node = dev->device_node;
+
+		plat = xzalloc(sizeof(*plat));
+		
+		of_property_read_u32(node, "clock-frequency", &plat->clock);
+		of_property_read_u32(node, "reg-shift", &plat->shift);
+
+		if (!of_property_read_u32(node, "disable-fifo", &fifo) && fifo == 1)
+			plat->flags |= NS16650_FLAG_DISABLE_FIFO;
+
+		if (!of_property_read_u32(node, "reg-io-width", &width)) {
+			switch (width) {
+			case 1:
+				plat->flags |= IORESOURCE_MEM_8BIT;
+				break;
+			case 2:
+				plat->flags |= IORESOURCE_MEM_16BIT;
+				break;
+			case 4:
+				plat->flags |= IORESOURCE_MEM_32BIT;
+				break;
+			}
+		}
+
+		if (of_find_property(node, "console-stdin"))
+			plat->f_caps |= CONSOLE_STDIN;
+		if (of_find_property(node, "console-stdout"))
+			plat->f_caps |= CONSOLE_STDOUT;
+		if (of_find_property(node, "console-stderr"))
+			plat->f_caps |= CONSOLE_STDERR;
+		
+		dev->platform_data = plat;
+	} else 
+		plat->flags = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
+
 	dev->priv = dev_request_mem_region(dev, 0);
 
 	cdev = xzalloc(sizeof(*cdev));
@@ -255,11 +293,20 @@ static int ns16550_probe(struct device_d *dev)
 	return console_register(cdev);
 }
 
+static struct of_device_id ns16550_serial_dt_ids[] = {
+	{ 
+		.compatible = "ns16550_serial",
+	}, {
+		/* sentinel */ 
+	},
+};
+
 /**
  * @brief Driver registration structure
  */
 static struct driver_d ns16550_serial_driver = {
 	.name = "ns16550_serial",
 	.probe = ns16550_probe,
+	.of_compatible = DRV_OF_COMPAT(ns16550_serial_dt_ids),
 };
 console_platform_driver(ns16550_serial_driver);
-- 
1.8.1.2



From shc_work at mail.ru  Mon Jun 24 08:25:26 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Mon, 24 Jun 2013 16:25:26 +0400
Subject: =?UTF-8?B?UmU6IFtQQVRDSF0gbnMxNjU1MDogYWRkIGRldmljZSB0cmVlIHN1cHBvcnQ=?=
In-Reply-To: <51C83929.70001@gmail.com>
References: <51C83929.70001@gmail.com>
Message-ID: <1372076726.78973270@f192.mail.ru>

> This patch adds device tree support for serial_ns16550 driver.
> 
> Tested with pcduino (allwinner a10).

Is we have mach-sunxi support in barebox already?
Do you have custom patches for support this subarch?
Thanks.

---

From hiroki.nishimoto.if at gmail.com  Mon Jun 24 08:36:16 2013
From: hiroki.nishimoto.if at gmail.com (NISHIMOTO Hiroki)
Date: Mon, 24 Jun 2013 21:36:16 +0900
Subject: [PATCH] ns16550: add device tree support
In-Reply-To: <1372076726.78973270@f192.mail.ru>
References: <51C83929.70001@gmail.com> <1372076726.78973270@f192.mail.ru>
Message-ID: <51C83D40.5090004@gmail.com>

> Is we have mach-sunxi support in barebox already?
> Do you have custom patches for support this subarch?

As far as I know, mach-sunxi is not supported yet.
Currently only serial/clocksource are working on my local environment.


From chf.fritz at googlemail.com  Mon Jun 24 09:32:30 2013
From: chf.fritz at googlemail.com (Christoph Fritz)
Date: Mon, 24 Jun 2013 15:32:30 +0200
Subject: [PATCH 1/2] omap-fb: add driver
In-Reply-To: <1371634395.4111.54.camel@mars>
References: <1371634395.4111.54.camel@mars>
Message-ID: <1372080750.6281.4.camel@mars>

On Wed, 2013-06-19 at 11:33 +0200, Christoph Fritz wrote:
> This patch adds omap display controller support. Currently only
> OMAP4 DSS is supported.

Any objections here?

These are the changes in the review-process so far:

changes since v2:
        - use dev_request_mem_region_by_name()
changes since v3:
        - remove register struct
        - use uncached screen_base
changes since v4:
        - remove useless dev_add_param()
        - use wait_on_timeout() instead while-deadlock
changes since v5:
        - use dev_dbg() and dev_err(), be less verbose
        - fix coding-style issues
        - add omap4fb_find_display_by_name()
        - add additional read/write macros
changes since v6:
	- split driver into two commits
	- rename driver to "omap-fb"

 Thanks
  -- Christoph



From sebastian.hesselbarth at gmail.com  Mon Jun 24 11:03:09 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Mon, 24 Jun 2013 17:03:09 +0200
Subject: [PATCH] ns16550: add device tree support
In-Reply-To: <51C83929.70001@gmail.com>
References: <51C83929.70001@gmail.com>
Message-ID: <51C85FAD.5090002@gmail.com>

On 06/24/13 14:18, NISHIMOTO Hiroki wrote:
> This patch adds device tree support for serial_ns16550 driver.
>
> Tested with pcduino (allwinner a10).
>
> Signed-off-by: NISHIMOTO Hiroki <hiroki.nishimoto.if at gmail.com>
> ---
>   .../devicetree/bindings/serial/ns16550_serial.txt  | 34 ++++++++++++++
>   drivers/serial/serial_ns16550.c                    | 53 ++++++++++++++++++++--
>   2 files changed, 84 insertions(+), 3 deletions(-)
>   create mode 100644 Documentation/devicetree/bindings/serial/ns16550_serial.txt
>
> diff --git a/Documentation/devicetree/bindings/serial/ns16550_serial.txt b/Documentation/devicetree/bindings/serial/ns16550_serial.txt
> new file mode 100644
> index 0000000..848f949
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/serial/ns16550_serial.txt
> @@ -0,0 +1,34 @@
> +* NS16550 UART
> +
> +Required properties:
> +- compatible : "ns16550_serial"

Hiroki,

as stated in Documentation/devicetree/bindings/README, barebox uses the 
same bindings as "the kernel" which is Linux I guess. Linux already has
a binding for ns16550 compatible serial.

I suggest to use that binding as a reference although it is not
documented but needs to be stripped from its source code.

> +- reg : offset and length of the register set for the device.
> +
> +
> +Optional properties:
> +- clock-frequency : the input clock frequency for the UART.
> +- reg-shift : quantity to shift the register offsets by.  If this property is
> +  not present then the register offsets are not shifted.
> +- reg-io-width : the size (in bytes) of the IO accesses that should be
> +  performed on the device.  If this property is not present then single byte
> +  accesses are used.
> +- disable-fifo :
> +	0: enable tx/rx fifo (default value)
> +	1: disable tx/rx fifo
> +- console-stdin : activate stdin on this console.
> +- console-stdout : activate stdout on this console.
> +- console-stderr : activate stderr on this console.

ePAPR specification already defines stdout-path and stdin-path.
Moreover, barebox has of_device_is_stdout_path to check if a device is
referenced by stdout-path property.

Sebastian



From hiroki.nishimoto.if at gmail.com  Mon Jun 24 11:18:52 2013
From: hiroki.nishimoto.if at gmail.com (NISHIMOTO Hiroki)
Date: Tue, 25 Jun 2013 00:18:52 +0900
Subject: [PATCH] ns16550: add device tree support
In-Reply-To: <51C85FAD.5090002@gmail.com>
References: <51C83929.70001@gmail.com> <51C85FAD.5090002@gmail.com>
Message-ID: <51C8635C.4030702@gmail.com>

Sebastian,

Thanks for your reviwing.
I will re-send as v2.

NISHIMOTO Hiroki


> On 06/24/13 14:18, NISHIMOTO Hiroki wrote:
>> This patch adds device tree support for serial_ns16550 driver.
>>
>> Tested with pcduino (allwinner a10).
>>
>> Signed-off-by: NISHIMOTO Hiroki <hiroki.nishimoto.if at gmail.com>
>> ---
>>   .../devicetree/bindings/serial/ns16550_serial.txt  | 34 ++++++++++++++
>>   drivers/serial/serial_ns16550.c                    | 53 ++++++++++++++++++++--
>>   2 files changed, 84 insertions(+), 3 deletions(-)
>>   create mode 100644 Documentation/devicetree/bindings/serial/ns16550_serial.txt
>>
>> diff --git a/Documentation/devicetree/bindings/serial/ns16550_serial.txt b/Documentation/devicetree/bindings/serial/ns16550_serial.txt
>> new file mode 100644
>> index 0000000..848f949
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/serial/ns16550_serial.txt
>> @@ -0,0 +1,34 @@
>> +* NS16550 UART
>> +
>> +Required properties:
>> +- compatible : "ns16550_serial"
> 
> Hiroki,
> 
> as stated in Documentation/devicetree/bindings/README, barebox uses the same bindings as "the kernel" which is Linux I guess. Linux already has
> a binding for ns16550 compatible serial.
> 
> I suggest to use that binding as a reference although it is not
> documented but needs to be stripped from its source code.
> 
>> +- reg : offset and length of the register set for the device.
>> +
>> +
>> +Optional properties:
>> +- clock-frequency : the input clock frequency for the UART.
>> +- reg-shift : quantity to shift the register offsets by.  If this property is
>> +  not present then the register offsets are not shifted.
>> +- reg-io-width : the size (in bytes) of the IO accesses that should be
>> +  performed on the device.  If this property is not present then single byte
>> +  accesses are used.
>> +- disable-fifo :
>> +    0: enable tx/rx fifo (default value)
>> +    1: disable tx/rx fifo
>> +- console-stdin : activate stdin on this console.
>> +- console-stdout : activate stdout on this console.
>> +- console-stderr : activate stderr on this console.
> 
> ePAPR specification already defines stdout-path and stdin-path.
> Moreover, barebox has of_device_is_stdout_path to check if a device is
> referenced by stdout-path property.
> 
> Sebastian
> 



From s.hauer at pengutronix.de  Mon Jun 24 13:00:41 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 19:00:41 +0200
Subject: [PATCH 3/4] ARM: i.MX51 efikasb: add flash environment support
In-Reply-To: <1372093242-11699-1-git-send-email-s.hauer@pengutronix.de>
References: <1372093242-11699-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372093242-11699-3-git-send-email-s.hauer@pengutronix.de>

The Efikasb has a m25p80 SPI NOR flash. Add support for putting
the environment on it.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/efika-mx-smartbook/board.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/efika-mx-smartbook/board.c b/arch/arm/boards/efika-mx-smartbook/board.c
index 98f9dcd..58600e3 100644
--- a/arch/arm/boards/efika-mx-smartbook/board.c
+++ b/arch/arm/boards/efika-mx-smartbook/board.c
@@ -475,11 +475,20 @@ device_initcall(efikamx_devices_init);
 
 static int efikamx_part_init(void)
 {
-	if (bootsource_get() == BOOTSOURCE_MMC) {
+	enum bootsource bootsource = bootsource_get();
+
+	switch (bootsource) {
+	case BOOTSOURCE_MMC:
 		devfs_add_partition("mmc_left", 0x00000, 0x80000,
 				DEVFS_PARTITION_FIXED, "self0");
 		devfs_add_partition("mmc_left", 0x80000, 0x80000,
 				DEVFS_PARTITION_FIXED, "env0");
+		break;
+	case BOOTSOURCE_SPI:
+	default:
+		devfs_add_partition("m25p0", 0x80000, 0x20000,
+				DEVFS_PARTITION_FIXED, "env0");
+		break;
 	}
 
 	return 0;
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 24 13:00:40 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 19:00:40 +0200
Subject: [PATCH 2/4] usb: i.MX chipidea: probe ULPI phys later
In-Reply-To: <1372093242-11699-1-git-send-email-s.hauer@pengutronix.de>
References: <1372093242-11699-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372093242-11699-2-git-send-email-s.hauer@pengutronix.de>

Probe ULPI phys during USB initialization and not during driver
probe. This lowers the pressure to have the necessary board specific
setup in place early.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/imx/chipidea-imx.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index 2006649..13e29ac 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -26,6 +26,7 @@
 
 struct imx_chipidea {
 	struct device_d *dev;
+	void __iomem *base;
 	struct ehci_data data;
 	unsigned long flags;
 	enum imx_usb_mode mode;
@@ -38,6 +39,19 @@ static int imx_chipidea_port_init(void *drvdata)
 	struct imx_chipidea *ci = drvdata;
 	int ret;
 
+	if ((ci->flags & MXC_EHCI_PORTSC_MASK) == MXC_EHCI_MODE_ULPI) {
+		dev_dbg(ci->dev, "using ULPI phy\n");
+		if (IS_ENABLED(CONFIG_USB_ULPI)) {
+			ret = ulpi_setup(ci->base + 0x170, 1);
+		} else {
+			dev_err(ci->dev, "no ULPI support available\n");
+			ret = -ENODEV;
+		}
+
+		if (ret)
+			return ret;
+	}
+
 	ret = imx_usbmisc_port_init(ci->portno, ci->flags);
 	if (ret)
 		dev_err(ci->dev, "misc init failed: %s\n", strerror(-ret));
@@ -144,30 +158,17 @@ static int imx_chipidea_probe(struct device_d *dev)
 	if (!base)
 		return -ENODEV;
 
+	ci->base = base;
+
 	ci->data.init = imx_chipidea_port_init;
 	ci->data.post_init = imx_chipidea_port_post_init;
 	ci->data.drvdata = ci;
 
-	imx_chipidea_port_init(ci);
-
 	portsc = readl(base + 0x184);
 	portsc &= ~MXC_EHCI_PORTSC_MASK;
 	portsc |= ci->flags & MXC_EHCI_PORTSC_MASK;
 	writel(portsc, base + 0x184);
 
-	if ((ci->flags & MXC_EHCI_PORTSC_MASK) == MXC_EHCI_MODE_ULPI) {
-		dev_dbg(dev, "using ULPI phy\n");
-		if (IS_ENABLED(CONFIG_USB_ULPI)) {
-			ret = ulpi_setup(base + 0x170, 1);
-		} else {
-			dev_err(dev, "no ULPI support available\n");
-			ret = -ENODEV;
-		}
-
-		if (ret)
-			return ret;
-	}
-
 	ci->data.hccr = base + 0x100;
 	ci->data.hcor = base + 0x140;
 	ci->data.flags = EHCI_HAS_TT;
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 24 13:00:42 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 19:00:42 +0200
Subject: [PATCH 4/4] ARM: i.MX51 efikasb: Switch to devicetree probing
In-Reply-To: <1372093242-11699-1-git-send-email-s.hauer@pengutronix.de>
References: <1372093242-11699-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372093242-11699-4-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/efika-mx-smartbook/board.c    | 301 +++--------------------
 arch/arm/configs/efika-mx-smartbook_defconfig |  13 +-
 arch/arm/dts/Makefile                         |   3 +-
 arch/arm/dts/imx51-genesi-efika-sb.dts        | 328 ++++++++++++++++++++++++++
 drivers/usb/host/ehci-hcd.c                   |   6 +-
 5 files changed, 370 insertions(+), 281 deletions(-)
 create mode 100644 arch/arm/dts/imx51-genesi-efika-sb.dts

diff --git a/arch/arm/boards/efika-mx-smartbook/board.c b/arch/arm/boards/efika-mx-smartbook/board.c
index 58600e3..bea61ce 100644
--- a/arch/arm/boards/efika-mx-smartbook/board.c
+++ b/arch/arm/boards/efika-mx-smartbook/board.c
@@ -13,42 +13,31 @@
  *
  */
 
-#include <common.h>
-#include <bootsource.h>
-#include <net.h>
-#include <init.h>
 #include <environment.h>
-#include <mach/gpio.h>
-#include <asm/armlinux.h>
+#include <bootsource.h>
 #include <partition.h>
-#include <notifier.h>
-#include <fs.h>
-#include <led.h>
+#include <common.h>
 #include <fcntl.h>
-#include <nand.h>
-#include <usb/ulpi.h>
-#include <usb/chipidea-imx.h>
+#include <gpio.h>
+#include <init.h>
+#include <led.h>
+#include <fs.h>
+#include <io.h>
+
 #include <spi/spi.h>
 #include <mfd/mc13xxx.h>
 #include <mfd/mc13892.h>
-#include <asm/io.h>
-#include <asm/mmu.h>
-#include <mach/imx-nand.h>
-#include <mach/spi.h>
+
+#include <asm/armlinux.h>
+
+#include <mach/imx-flash-header.h>
+#include <mach/devices-imx51.h>
+#include <mach/imx51-regs.h>
+#include <mach/iomux-mx51.h>
+#include <mach/revision.h>
 #include <mach/generic.h>
 #include <mach/imx5.h>
 #include <mach/bbu.h>
-#include <mach/iomux-mx51.h>
-#include <mach/imx51-regs.h>
-#include <mach/devices-imx51.h>
-#include <mach/imx-flash-header.h>
-#include <mach/revision.h>
-
-#define GPIO_EFIKA_SDHC1_WP	IMX_GPIO_NR(1, 1)
-#define GPIO_EFIKAMX_SDHC1_CD	IMX_GPIO_NR(1, 0)
-#define GPIO_EFIKASB_SDHC1_CD	IMX_GPIO_NR(2, 27)
-#define GPIO_EFIKASB_SDHC2_CD	IMX_GPIO_NR(1, 8)
-#define GPIO_EFIKASB_SDHC2_WP	IMX_GPIO_NR(1, 7)
 
 #define GPIO_BACKLIGHT_POWER	IMX_GPIO_NR(4, 12)
 #define GPIO_BACKLIGHT_PWM	IMX_GPIO_NR(1, 2)
@@ -63,128 +52,6 @@
 #define GPIO_HUB_RESET		IMX_GPIO_NR(1, 5)
 #define GPIO_SMSC3317_RESET	IMX_GPIO_NR(2, 9)
 
-static iomux_v3_cfg_t efika_pads[] = {
-	/* ECSPI1 */
-	MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI,
-	MX51_PAD_CSPI1_MISO__ECSPI1_MISO,
-	MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK,
-	MX51_PAD_CSPI1_SS0__GPIO4_24,
-	MX51_PAD_CSPI1_SS1__GPIO4_25,
-	MX51_PAD_GPIO1_6__GPIO1_6,
-
-	/* ESDHC1 */
-	MX51_PAD_SD1_CMD__SD1_CMD,
-	MX51_PAD_SD1_CLK__SD1_CLK,
-	MX51_PAD_SD1_DATA0__SD1_DATA0,
-	MX51_PAD_SD1_DATA1__SD1_DATA1,
-	MX51_PAD_SD1_DATA2__SD1_DATA2,
-	MX51_PAD_SD1_DATA3__SD1_DATA3,
-	MX51_PAD_GPIO1_1__GPIO1_1,
-
-	/* USB HOST1 */
-	MX51_PAD_USBH1_CLK__USBH1_CLK,
-	MX51_PAD_USBH1_DIR__USBH1_DIR,
-	MX51_PAD_USBH1_NXT__USBH1_NXT,
-	MX51_PAD_USBH1_DATA0__USBH1_DATA0,
-	MX51_PAD_USBH1_DATA1__USBH1_DATA1,
-	MX51_PAD_USBH1_DATA2__USBH1_DATA2,
-	MX51_PAD_USBH1_DATA3__USBH1_DATA3,
-	MX51_PAD_USBH1_DATA4__USBH1_DATA4,
-	MX51_PAD_USBH1_DATA5__USBH1_DATA5,
-	MX51_PAD_USBH1_DATA6__USBH1_DATA6,
-	MX51_PAD_USBH1_DATA7__USBH1_DATA7,
-	MX51_PAD_USBH1_STP__GPIO1_27,
-	MX51_PAD_EIM_A16__GPIO2_10,
-
-	/* USB HOST2 */
-	MX51_PAD_EIM_D27__GPIO2_9,
-	MX51_PAD_GPIO1_5__GPIO1_5,
-	MX51_PAD_EIM_D16__USBH2_DATA0,
-	MX51_PAD_EIM_D17__USBH2_DATA1,
-	MX51_PAD_EIM_D18__USBH2_DATA2,
-	MX51_PAD_EIM_D19__USBH2_DATA3,
-	MX51_PAD_EIM_D20__USBH2_DATA4,
-	MX51_PAD_EIM_D21__USBH2_DATA5,
-	MX51_PAD_EIM_D22__USBH2_DATA6,
-	MX51_PAD_EIM_D23__USBH2_DATA7,
-	MX51_PAD_EIM_A24__USBH2_CLK,
-	MX51_PAD_EIM_A25__USBH2_DIR,
-	MX51_PAD_EIM_A26__GPIO2_20,
-	MX51_PAD_EIM_A27__USBH2_NXT,
-
-	/* PATA */
-	MX51_PAD_NANDF_WE_B__PATA_DIOW,
-	MX51_PAD_NANDF_RE_B__PATA_DIOR,
-	MX51_PAD_NANDF_ALE__PATA_BUFFER_EN,
-	MX51_PAD_NANDF_CLE__PATA_RESET_B,
-	MX51_PAD_NANDF_WP_B__PATA_DMACK,
-	MX51_PAD_NANDF_RB0__PATA_DMARQ,
-	MX51_PAD_NANDF_RB1__PATA_IORDY,
-	MX51_PAD_GPIO_NAND__PATA_INTRQ,
-	MX51_PAD_NANDF_CS2__PATA_CS_0,
-	MX51_PAD_NANDF_CS3__PATA_CS_1,
-	MX51_PAD_NANDF_CS4__PATA_DA_0,
-	MX51_PAD_NANDF_CS5__PATA_DA_1,
-	MX51_PAD_NANDF_CS6__PATA_DA_2,
-	MX51_PAD_NANDF_D15__PATA_DATA15,
-	MX51_PAD_NANDF_D14__PATA_DATA14,
-	MX51_PAD_NANDF_D13__PATA_DATA13,
-	MX51_PAD_NANDF_D12__PATA_DATA12,
-	MX51_PAD_NANDF_D11__PATA_DATA11,
-	MX51_PAD_NANDF_D10__PATA_DATA10,
-	MX51_PAD_NANDF_D9__PATA_DATA9,
-	MX51_PAD_NANDF_D8__PATA_DATA8,
-	MX51_PAD_NANDF_D7__PATA_DATA7,
-	MX51_PAD_NANDF_D6__PATA_DATA6,
-	MX51_PAD_NANDF_D5__PATA_DATA5,
-	MX51_PAD_NANDF_D4__PATA_DATA4,
-	MX51_PAD_NANDF_D3__PATA_DATA3,
-	MX51_PAD_NANDF_D2__PATA_DATA2,
-	MX51_PAD_NANDF_D1__PATA_DATA1,
-	MX51_PAD_NANDF_D0__PATA_DATA0,
-
-	MX51_PAD_EIM_A22__GPIO2_16, /* WLAN enable (1 = on) */
-	MX51_PAD_EIM_A17__GPIO2_11,
-
-	/* I2C2 */
-	MX51_PAD_KEY_COL4__I2C2_SCL,
-	MX51_PAD_KEY_COL5__I2C2_SDA,
-
-	MX51_PAD_GPIO1_2__GPIO1_2, /* Backlight (should be pwm) (1 = on) */
-	MX51_PAD_CSI2_D19__GPIO4_12, /* Backlight power (0 = on) */
-
-	MX51_PAD_DISPB2_SER_CLK__GPIO3_7, /* LVDS power (1 = on) */
-	MX51_PAD_DISPB2_SER_DIN__GPIO3_5, /* LVDS reset (1 = reset) */
-	MX51_PAD_CSI1_D8__GPIO3_12, /* LVDS enable (1 = enable) */
-	MX51_PAD_CSI1_D9__GPIO3_13, /* LCD enable (1 = on) */
-
-	MX51_PAD_DI1_PIN12__GPIO3_1, /* WLAN switch (0 = on) */
-
-	MX51_PAD_GPIO1_4__WDOG1_WDOG_B,
-};
-
-static iomux_v3_cfg_t efikasb_pads[] = {
-	/* LEDs */
-	MX51_PAD_EIM_CS0__GPIO2_25,
-	MX51_PAD_GPIO1_3__GPIO1_3,
-
-	/* ESHC2 */
-	MX51_PAD_SD2_CMD__SD2_CMD,
-	MX51_PAD_SD2_CLK__SD2_CLK,
-	MX51_PAD_SD2_DATA0__SD2_DATA0,
-	MX51_PAD_SD2_DATA1__SD2_DATA1,
-	MX51_PAD_SD2_DATA2__SD2_DATA2,
-	MX51_PAD_SD2_DATA3__SD2_DATA3,
-	MX51_PAD_GPIO1_7__GPIO1_7,
-	MX51_PAD_GPIO1_8__GPIO1_8,
-
-	MX51_PAD_EIM_CS2__GPIO2_27,
-};
-
-static iomux_v3_cfg_t efikamx_pads[] = {
-	MX51_PAD_GPIO1_0__GPIO1_0,
-};
-
 /*
  * Generally this should work on the Efika MX smarttop aswell,
  * but I do not have the hardware to test it, so hardcode this
@@ -195,36 +62,7 @@ static inline int machine_is_efikasb(void)
 	return 1;
 }
 
-static int efikamx_mem_init(void)
-{
-	arm_add_mem_device("ram0", 0x90000000, SZ_512M);
-
-	return 0;
-}
-mem_initcall(efikamx_mem_init);
-
-static int spi_0_cs[] = { IMX_GPIO_NR(4, 24), IMX_GPIO_NR(4, 25) };
-
-static struct spi_imx_master spi_0_data = {
-	.chipselect = spi_0_cs,
-	.num_chipselect = ARRAY_SIZE(spi_0_cs),
-};
-
-static const struct spi_board_info efikamx_spi_board_info[] = {
-	{
-		.name = "mc13xxx-spi",
-		.max_speed_hz = 30 * 1000 * 1000,
-		.bus_num = 0,
-		.chip_select = 0,
-	}, {
-		.name = "m25p80",
-		.chip_select = 1,
-		.max_speed_hz = 20 * 1000 * 1000,
-		.bus_num = 0,
-	},
-};
-
-static void efikamx_power_init(void)
+static int efikamx_power_init(void)
 {
 	unsigned int val;
 	struct mc13xxx *mc;
@@ -232,7 +70,7 @@ static void efikamx_power_init(void)
 	mc = mc13xxx_get();
 	if (!mc) {
 		printf("could not get mc13892\n");
-		return;
+		return -ENODEV;
 	}
 
 	/* Write needed to Power Gate 2 register */
@@ -338,35 +176,10 @@ static void efikamx_power_init(void)
 	mc13xxx_reg_write(mc, MC13892_REG_POWER_CTL2, val);
 
 	udelay(2500);
-}
 
-static struct esdhc_platform_data efikasb_sd2_data = {
-	.cd_gpio = GPIO_EFIKASB_SDHC2_CD,
-	.wp_gpio = GPIO_EFIKASB_SDHC2_WP,
-	.cd_type = ESDHC_CD_GPIO,
-	.wp_type = ESDHC_WP_GPIO,
-	.devname = "mmc_left",
-};
-
-static struct esdhc_platform_data efikamx_sd1_data = {
-	.cd_gpio = GPIO_EFIKAMX_SDHC1_CD,
-	.wp_gpio = GPIO_EFIKA_SDHC1_WP,
-	.cd_type = ESDHC_CD_GPIO,
-	.wp_type = ESDHC_WP_GPIO,
-};
-
-static struct esdhc_platform_data efikasb_sd1_data = {
-	.cd_gpio = GPIO_EFIKASB_SDHC1_CD,
-	.wp_gpio = GPIO_EFIKA_SDHC1_WP,
-	.cd_type = ESDHC_CD_GPIO,
-	.wp_type = ESDHC_WP_GPIO,
-	.devname = "mmc_back",
-};
-
-struct imxusb_platformdata efikamx_usbh1_pdata = {
-	.flags = MXC_EHCI_MODE_ULPI | MXC_EHCI_INTERFACE_DIFF_UNI,
-	.mode = IMX_USB_MODE_HOST,
-};
+	return 0;
+}
+late_initcall(efikamx_power_init);
 
 static int efikamx_usb_init(void)
 {
@@ -395,18 +208,9 @@ static int efikamx_usb_init(void)
 		mxc_iomux_v3_setup_pad(MX51_PAD_EIM_A26__USBH2_STP);
 	}
 
-	imx51_add_usbh1(&efikamx_usbh1_pdata);
-
-	/*
-	 * At least for the EfikaSB these do not seem to be interesting.
-	 * The external ports are all connected to host1.
-	 *
-	 * imx51_add_usbotg(pdata);
-	 * imx51_add_usbh2(pdate);
-	 */
-
 	return 0;
 }
+console_initcall(efikamx_usb_init);
 
 static struct gpio_led leds[] = {
 	{
@@ -423,42 +227,16 @@ static struct gpio_led leds[] = {
 
 #include "dcd-data.h"
 
-static int efikamx_devices_init(void)
+static int efikamx_late_init(void)
 {
+	enum bootsource bootsource;
 	int i;
 
-	mxc_iomux_v3_setup_multiple_pads(efika_pads, ARRAY_SIZE(efika_pads));
-	if (machine_is_efikasb()) {
-		gpio_direction_output(GPIO_BACKLIGHT_POWER, 1);
-		mxc_iomux_v3_setup_multiple_pads(efikasb_pads,
-				ARRAY_SIZE(efikasb_pads));
-	} else {
-		mxc_iomux_v3_setup_multiple_pads(efikamx_pads,
-				ARRAY_SIZE(efikamx_pads));
-	}
-
-	spi_register_board_info(efikamx_spi_board_info,
-			ARRAY_SIZE(efikamx_spi_board_info));
-	imx51_add_spi0(&spi_0_data);
-
-	efikamx_power_init();
-
-	if (machine_is_efikasb())
-		imx51_add_mmc0(&efikasb_sd1_data);
-	else
-		imx51_add_mmc0(&efikamx_sd1_data);
-
-	imx51_add_mmc1(&efikasb_sd2_data);
+	gpio_direction_output(GPIO_BACKLIGHT_POWER, 1);
 
 	for (i = 0; i < ARRAY_SIZE(leds); i++)
 		led_gpio_register(&leds[i]);
 
-	imx51_add_i2c1(NULL);
-
-	efikamx_usb_init();
-
-	imx51_add_pata();
-
 	writew(0x0, MX51_WDOG_BASE_ADDR + 0x8);
 
 	imx51_bbu_internal_mmc_register_handler("mmc", "/dev/mmc_left",
@@ -469,13 +247,7 @@ static int efikamx_devices_init(void)
 	armlinux_set_architecture(2370);
 	armlinux_set_revision(0x5100 | imx_silicon_revision());
 
-	return 0;
-}
-device_initcall(efikamx_devices_init);
-
-static int efikamx_part_init(void)
-{
-	enum bootsource bootsource = bootsource_get();
+	bootsource = bootsource_get();
 
 	switch (bootsource) {
 	case BOOTSOURCE_MMC:
@@ -493,23 +265,4 @@ static int efikamx_part_init(void)
 
 	return 0;
 }
-late_initcall(efikamx_part_init);
-
-static iomux_v3_cfg_t efika_uart_pads[] = {
-	/* UART */
-	MX51_PAD_UART1_RXD__UART1_RXD,
-	MX51_PAD_UART1_TXD__UART1_TXD,
-	MX51_PAD_UART1_RTS__UART1_RTS,
-	MX51_PAD_UART1_CTS__UART1_CTS,
-};
-
-static int efikamx_console_init(void)
-{
-	mxc_iomux_v3_setup_multiple_pads(efika_uart_pads,
-			ARRAY_SIZE(efika_uart_pads));
-
-	imx51_add_uart0();
-
-	return 0;
-}
-console_initcall(efikamx_console_init);
+late_initcall(efikamx_late_init);
diff --git a/arch/arm/configs/efika-mx-smartbook_defconfig b/arch/arm/configs/efika-mx-smartbook_defconfig
index 2ef33b4..8e14466 100644
--- a/arch/arm/configs/efika-mx-smartbook_defconfig
+++ b/arch/arm/configs/efika-mx-smartbook_defconfig
@@ -1,3 +1,5 @@
+CONFIG_BUILTIN_DTB=y
+CONFIG_BUILTIN_DTB_NAME="imx51-genesi-efika-sb"
 CONFIG_ARCH_IMX=y
 CONFIG_ARCH_IMX51=y
 CONFIG_MACH_EFIKA_MX_SMARTBOOK=y
@@ -30,9 +32,7 @@ CONFIG_CMD_READLINE=y
 CONFIG_CMD_MENU=y
 CONFIG_CMD_MENU_MANAGEMENT=y
 CONFIG_CMD_TIME=y
-CONFIG_CMD_DIRNAME=y
 CONFIG_CMD_LN=y
-CONFIG_CMD_READLINK=y
 CONFIG_CMD_TFTP=y
 CONFIG_CMD_FILETYPE=y
 CONFIG_CMD_ECHO_E=y
@@ -52,7 +52,8 @@ CONFIG_CMD_UIMAGE=y
 CONFIG_CMD_RESET=y
 CONFIG_CMD_GO=y
 CONFIG_CMD_OFTREE=y
-CONFIG_CMD_OFTREE_PROBE=y
+CONFIG_CMD_OF_PROPERTY=y
+CONFIG_CMD_OF_NODE=y
 CONFIG_CMD_BAREBOX_UPDATE=y
 CONFIG_CMD_TIMEOUT=y
 CONFIG_CMD_PARTITION=y
@@ -66,6 +67,7 @@ CONFIG_CMD_LED=y
 CONFIG_CMD_LED_TRIGGER=y
 CONFIG_CMD_MIITOOL=y
 CONFIG_CMD_CLK=y
+CONFIG_CMD_DETECT=y
 CONFIG_CMD_WD=y
 CONFIG_NET=y
 CONFIG_NET_DHCP=y
@@ -73,16 +75,17 @@ CONFIG_NET_NFS=y
 CONFIG_NET_PING=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_RESOLV=y
+CONFIG_OFDEVICE=y
 CONFIG_NET_USB=y
 CONFIG_NET_USB_ASIX=y
 CONFIG_NET_USB_SMSC95XX=y
 CONFIG_DRIVER_SPI_IMX=y
 CONFIG_I2C=y
 CONFIG_I2C_IMX=y
-CONFIG_DRIVER_CFI=y
-CONFIG_CFI_BUFFER_WRITE=y
 CONFIG_MTD=y
 CONFIG_MTD_M25P80=y
+CONFIG_DRIVER_CFI=y
+CONFIG_CFI_BUFFER_WRITE=y
 CONFIG_DISK_INTF_PLATFORM_IDE=y
 CONFIG_DISK_PATA_IMX=y
 CONFIG_USB=y
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index bfca4c5..b271618 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1,4 +1,5 @@
-dtb-$(CONFIG_ARCH_IMX51) += imx51-babbage.dtb
+dtb-$(CONFIG_ARCH_IMX51) += imx51-babbage.dtb \
+	imx51-genesi-efika-sb.dtb
 dtb-$(CONFIG_ARCH_IMX53) += imx53-qsb.dtb
 dtb-$(CONFIG_ARCH_IMX6) += imx6q-dmo-realq7.dtb \
 	imx6q-sabrelite.dtb \
diff --git a/arch/arm/dts/imx51-genesi-efika-sb.dts b/arch/arm/dts/imx51-genesi-efika-sb.dts
new file mode 100644
index 0000000..dc92b2a
--- /dev/null
+++ b/arch/arm/dts/imx51-genesi-efika-sb.dts
@@ -0,0 +1,328 @@
+/*
+ * Copyright 2012 Sascha Hauer, Pengutronix <s.hauer at pengutronix.de>
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+/dts-v1/;
+#include "imx51.dtsi"
+
+/ {
+	model = "Genesi Efika MX Smartbook";
+	compatible = "genesi,imx51-sb", "fsl,imx51";
+
+	chosen {
+		linux,stdout-path = "/soc/aips at 70000000/serial at 73fbc000";
+	};
+
+	memory {
+		reg = <0x90000000 0x20000000>;
+	};
+
+	leds {
+		compatible = "gpio-leds";
+
+		mail {
+			label = "mail";
+			gpios = <&gpio1 3 1>;
+			linux,default-trigger = "heartbeat";
+		};
+
+		white {
+			label = "white";
+			gpios = <&gpio2 25 0>;
+			linux,default-trigger = "none";
+		};
+	};
+
+	gpio-keys {
+		compatible = "gpio-keys";
+
+		power {
+			label = "Power";
+			gpios = <&gpio2 31 0>;
+			linux,code = <116>; /* KEY_POWER */
+			gpio-key,wakeup;
+		};
+
+		lid {
+			label = "Lid";
+			gpios = <&gpio3 14 0>;
+			linux,input-type = <5>; /* EV_SW */
+			linux,code = <0>; /* SW_LID */
+			debounce-interval = <1>;
+			gpio-key,wakeup;
+		};
+	};
+
+	sound {
+		compatible = "fsl,imx51-efikasb-sgtl5000",
+			     "fsl,imx-audio-sgtl5000";
+		model = "imx51-efikasb-sgtl5000";
+		ssi-controller = <&ssi1>;
+		audio-codec = <&sgtl5000>;
+		audio-routing =
+			"Headphone Jack", "HP_OUT";
+		mux-int-port = <1>;
+		mux-ext-port = <3>;
+	};
+
+	backlight {
+		compatible = "pwm-backlight";
+		pwms = <&pwm1 0 78770>;
+		brightness-levels = <0 4 8 16 32 64 128 255>;
+		default-brightness-level = <6>;
+        };
+};
+
+&ssi1 {
+	fsl,mode = "i2s-slave";
+	status = "okay";
+};
+
+&iomuxc {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_hog>;
+
+	hog {
+		pinctrl_hog: hoggrp {
+			fsl,pins = <
+				MX51_PAD_EIM_DTACK__GPIO2_31 0x800000c0		/* Power button */
+				MX51_PAD_EIM_A16__GPIO2_10  0x80000000		/* WLAN reset */
+				MX51_PAD_EIM_A22__GPIO2_16 0x80000000		/* WLAN power */
+				MX51_PAD_CSI2_D13__GPIO4_10 0x80000000		/* WWAN power? */
+				MX51_PAD_DI1_PIN12__GPIO3_1 0x80000000		/* WLAN switch */
+				MX51_PAD_EIM_A17__GPIO2_11  0x80000000		/* Bluetooth power */
+				MX51_PAD_EIM_A23__GPIO2_17 0x80000000		/* Audio amp enable, 1 = on */
+				MX51_PAD_GPIO1_6__REF_EN_B 0x80000000		/* PMIC interrupt */
+				MX51_PAD_DI1_PIN11__GPIO3_0 0x80000000		/* Battery low */
+				MX51_PAD_CSI2_PIXCLK__GPIO4_15 0x80000000	/* Power good */
+				MX51_PAD_CSI1_VSYNC__GPIO3_14 0x80000000	/* Lid switch, 0 = closed */
+				MX51_PAD_CSPI1_SS0__GPIO4_24 0x85
+				MX51_PAD_CSPI1_SS1__GPIO4_25 0x85
+				MX51_PAD_CSI1_D8__GPIO3_12 0x80000000		/* LVDS enable, 1 = on */
+				MX51_PAD_GPIO1_2__GPIO1_2 0x80000000		/* Backlight PWM */
+				MX51_PAD_CSI2_D19__GPIO4_12 0x80000000		/* Backlight power, 0 = on */
+				MX51_PAD_DISPB2_SER_DIO__GPIO3_6 0x80000000	/* LVDS reset, 1 = reset */
+				MX51_PAD_DISPB2_SER_DIN__GPIO3_5 0x80000000	/* LVDS reset (1 = reset) */
+				MX51_PAD_DISPB2_SER_CLK__GPIO3_7 0x80000000	/* LVDS power, 1 = on */
+				MX51_PAD_CSI1_D9__GPIO3_13 0x80000000		/* LCD enable (1 = on */
+				MX51_PAD_NANDF_CS0__GPIO3_16 0x80000000		/* Camera power, 0 = on */
+				MX51_PAD_GPIO1_5__GPIO1_5 0x80000000		/* USB hub reset, 0 = reset */
+				MX51_PAD_EIM_D27__GPIO2_9  0x80000000		/* USB phy reset, 0 = reset */
+				MX51_PAD_DISPB2_SER_DIO__GPIO3_6 0x80000000	/* Battery, 0 = inserted */
+				MX51_PAD_GPIO1_3__GPIO1_3 0x80000000		/* Alarm LED, 0 = on */
+				MX51_PAD_EIM_CS0__GPIO2_25 0x80000000		/* Caps LED, 1 = on */
+				MX51_PAD_CSPI1_RDY__GPIO4_26 0x80000000		/* Audio clk enable */
+				MX51_PAD_EIM_A26__GPIO2_20 0x80000000
+				MX51_PAD_USBH1_STP__GPIO1_27 0x80000000
+			>;
+		};
+	};
+};
+
+&uart1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_uart1_1>;
+	status = "okay";
+};
+
+&i2c2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c2_1>;
+	clock-frequency = <100000>;
+	status = "okay";
+
+	sgtl5000: codec at 0a {
+		compatible = "fsl,sgtl5000";
+		reg = <0x0a>;
+		clock-frequency = <12288000>;
+		VDDA-supply = <&vdig_reg>;
+		VDDD-supply = <&vdig_reg>;
+		VDDIO-supply = <&vvideo_reg>;
+	};
+
+	battery: battery at 0b {
+		compatible = "sbs,sbs-battery";
+		reg = <0x0b>;
+		sbs,battery-detect-gpios = <&gpio3 6 1>;
+	};
+
+	lvds: mtl017 at 3a {
+		compatible = "mtl017";
+		reg = <0x3a>;
+		crtcs = <&ipu 1>;
+		edid-i2c = <&i2c2>;
+		interface-pix-fmt = "rgb565";
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_ipu_disp1_1>;
+	};
+};
+
+&esdhc1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_esdhc1_1>;
+	cd-gpios = <&gpio2 27 0>;
+	wp-gpios = <&gpio1 1 0>;
+	status = "okay";
+};
+
+&esdhc2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_esdhc2_1>;
+	cd-gpios = <&gpio1 8 0>;
+	wp-gpios = <&gpio1 7 0>;
+	status = "okay";
+};
+
+&ecspi1 {
+	fsl,spi-num-chipselects = <1>;
+	cs-gpios = <&gpio4 23 0>;
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_ecspi1_1>;
+	fsl,spi-num-chipselects = <2>;
+	cs-gpios = <&gpio4 24 0>, <&gpio4 25 0>;
+	status = "okay";
+
+	pmic: mc13892 at 0 {
+		compatible = "fsl,mc13892";
+		spi-max-frequency = <20000000>;
+		reg = <0>;
+		spi-cs-high;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		interrupt-parent = <&gpio1>;
+		interrupts = <6 0x4>;
+
+		regulators {
+			sw1_reg: sw1 {
+				regulator-min-microvolt = <600000>;
+				regulator-max-microvolt = <1375000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			sw2_reg: sw2 {
+				regulator-min-microvolt = <900000>;
+				regulator-max-microvolt = <1850000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			sw3_reg: sw3 {
+				regulator-min-microvolt = <1100000>;
+				regulator-max-microvolt = <1850000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			sw4_reg: sw4 {
+				regulator-min-microvolt = <1100000>;
+				regulator-max-microvolt = <1850000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			vpll_reg: vpll {
+				regulator-min-microvolt = <1050000>;
+				regulator-max-microvolt = <1800000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			vdig_reg: vdig {
+				regulator-min-microvolt = <1650000>;
+				regulator-max-microvolt = <1650000>;
+			};
+
+			vsd_reg: vsd {
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <3150000>;
+			};
+
+			vusb2_reg: vusb2 {
+				regulator-min-microvolt = <2400000>;
+				regulator-max-microvolt = <2775000>;
+				regulator-boot-on;
+				regulator-always-on;
+			};
+
+			vvideo_reg: vvideo {
+				regulator-min-microvolt = <2775000>;
+				regulator-max-microvolt = <2775000>;
+			};
+
+			vaudio_reg: vaudio {
+				regulator-min-microvolt = <2300000>;
+				regulator-max-microvolt = <3000000>;
+			};
+
+			vcam_reg: vcam {
+				regulator-min-microvolt = <2500000>;
+				regulator-max-microvolt = <3000000>;
+			};
+
+			vgen1_reg: vgen1 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <1200000>;
+			};
+
+			vgen2_reg: vgen2 {
+				regulator-min-microvolt = <1200000>;
+				regulator-max-microvolt = <3150000>;
+				regulator-always-on;
+			};
+
+			vgen3_reg: vgen3 {
+				regulator-min-microvolt = <1800000>;
+				regulator-max-microvolt = <2900000>;
+				regulator-always-on;
+			};
+		};
+	};
+
+	flash: m25p80 {
+		compatible = "sst,sst25vf032b", "m25p80";
+		spi-max-frequency = <15000000>;
+		reg = <1>;
+	};
+};
+
+&audmux {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_audmux_1>;
+	status = "okay";
+};
+
+&pata {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_pata_1>;
+	status = "okay";
+};
+
+&usbotg {
+	barebox,phy_type = "utmi_wide";
+	phy_type = "ulpi";
+	status = "okay";
+};
+
+&usbh1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_usbh1_1>;
+	barebox,phy_type = "ulpi";
+	phy_type = "ulpi";
+	status = "okay";
+};
+
+&usbh2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_usbh2_1>;
+	barebox,phy_type = "ulpi";
+	phy_type = "ulpi";
+	status = "okay";
+};
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 6a459b9..f44f836 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -27,6 +27,7 @@
 #include <xfuncs.h>
 #include <clock.h>
 #include <errno.h>
+#include <of.h>
 #include <usb/ehci.h>
 #include <asm/mmu.h>
 
@@ -439,10 +440,13 @@ static inline int min3(int a, int b, int c)
  * boards.
  * See http://lists.infradead.org/pipermail/linux-arm-kernel/2011-January/037341.html
  */
-void ehci_powerup_fixup(struct ehci_priv *ehci)
+static void ehci_powerup_fixup(struct ehci_priv *ehci)
 {
 	void *viewport = (void *)ehci->hcor + 0x30;
 
+	if (!of_machine_is_compatible("genesi,imx51-sb"))
+		return;
+
 	ulpi_write(ULPI_OTG_CHRG_VBUS, ULPI_OTGCTL + ULPI_REG_SET,
 			viewport);
 }
-- 
1.8.3.1



From s.hauer at pengutronix.de  Mon Jun 24 13:00:39 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 19:00:39 +0200
Subject: [PATCH 1/4] usb: ehci: Fixup efika hack for devicetree
Message-ID: <1372093242-11699-1-git-send-email-s.hauer@pengutronix.de>

We used to distinguish which USB port to fixup by pdev->id. This
is < 0 for devicetree probed devices all the time, so this won't
work anymore once we switch to devicetree. Do the fixup on every
port instead, it doesn't hurt.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/host/ehci-hcd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 840aa1a..6a459b9 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -443,9 +443,8 @@ void ehci_powerup_fixup(struct ehci_priv *ehci)
 {
 	void *viewport = (void *)ehci->hcor + 0x30;
 
-	if (ehci->dev->id > 0)
-		ulpi_write(ULPI_OTG_CHRG_VBUS, ULPI_OTGCTL + ULPI_REG_SET,
-				viewport);
+	ulpi_write(ULPI_OTG_CHRG_VBUS, ULPI_OTGCTL + ULPI_REG_SET,
+			viewport);
 }
 #else
 static inline void ehci_powerup_fixup(struct ehci_priv *ehci)
-- 
1.8.3.1



From antonynpavlov at gmail.com  Mon Jun 24 15:10:09 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon, 24 Jun 2013 23:10:09 +0400
Subject: [PATCH 0/3] MIPS: pbl: add nmon MIPS nano-monitor
Message-ID: <1372101012-11666-1-git-send-email-antonynpavlov@gmail.com>

nmon is a tiny monitor (<1200 bytes) program
for the MIPS processors.
It can operate with NO working RAM at all!
It uses only the processor registers and NS16550-compatible
UART port for operation, so it can be used for a memory
controller setup code debugging.

With no changes nmon should work on different MIPS
processors as it uses only common MIPS-I instructions.

[PATCH 1/3] MIPS: pbl: add nmon MIPS nano-monitor
[PATCH 2/3] MIPS: qemu-malta: rework debug_ll.h
[PATCH 3/3] MIPS: qemu-malta: add nmon


From antonynpavlov at gmail.com  Mon Jun 24 15:10:10 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon, 24 Jun 2013 23:10:10 +0400
Subject: [PATCH 1/3] MIPS: pbl: add nmon MIPS nano-monitor
In-Reply-To: <1372101012-11666-1-git-send-email-antonynpavlov@gmail.com>
References: <1372101012-11666-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1372101012-11666-2-git-send-email-antonynpavlov@gmail.com>

nmon is a tiny monitor (<1200 bytes) program
for the MIPS processors.
It can operate with NO working RAM at all!
It uses only the processor registers and NS16550-compatible
UART port for operation, so it can be used for a memory
controller setup code debugging.

With no changes nmon should work on different MIPS
processors as it uses only common MIPS-I instructions.

nmon is inspired by mmon, MIPS VR4300 Mini-monitor.

mmon is copyrighted 1996, 2003 by Eric Smith.
Also Alexander Voropay must be noted for his work
on qemu & YAMON mmon adaptations made in 2006 and 2007.

See http://www.brouhaha.com/~eric/software/mmon/
for mmon details.

The mmon's features missed in nmon:

 * batch memory dumps;
 * byte and 16-bit half-words dumps and stores;
 * fill memory;
 * load S-records (this function make sense only
 if RAM works properly).

nmon has only 4 commands:
 q - quit to barebox
 d <addr> - read 32-bit word from <addr> address
 w <addr> <val> - write 32-bit word <val> to <addr>
 g <addr> - jump to <addr>

Addresses and data must be given in hexadecimal.
Everything (including hex digits 'a'..'f') must
be in lower case.

EXAMPLE: change value of word with address 0xa0000000

nmon> d a0000000
00000000
nmon> w a0000000 12345678
nmon> d a0000000
12345678
nmon>

There is no error checking of any kind. If you
give an invalid address you will probably get
an exception which will hang the board and you
will have to press the reset button.

You can interrupt current command (e.g. you have
made error in input <addr> value) by pressing
the <ESC> key.

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/Kconfig                        |   46 +++++
 arch/mips/include/asm/debug_ll_ns16550.h |  100 ++++++++++-
 arch/mips/include/asm/pbl_nmon.h         |  270 ++++++++++++++++++++++++++++++
 3 files changed, 410 insertions(+), 6 deletions(-)
 create mode 100644 arch/mips/include/asm/pbl_nmon.h

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 6179fd8..b2452c7 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -245,6 +245,52 @@ config CMD_MIPS_CPUINFO
 	  Say yes here to get a cpuinfo command to show some
 	  information about the cpu model.
 
+config HAS_NMON
+	bool
+
+config NMON
+	bool "nmon"
+	depends on HAS_NMON
+	depends on DEBUG_LL
+	help
+	  Say yes here to add the nmon to pbl.
+	  nmon -- nano-monitor program for the MIPS processors.
+	  It can operate with NO working RAM, using only
+	  the processor registers.
+
+config NMON_USER_START
+	bool "'press any key to start nmon' dialog"
+	depends on NMON
+	help
+	  Say yes here to get the 'press any key to start nmon'
+	  dialog on start.
+
+config NMON_1S_DELAY
+	prompt "number of delay loops for 1s time interval"
+	depends on NMON_USER_START
+	hex
+	default 0x400000
+	help
+	nmon uses a very simple delay loop for time measurement.
+	The delay is CPU-dependent or even board-dependent.
+	The NMON_1S_DELAY parameter specify delay loop count
+	for near 1 second time interval.
+
+config NMON_USER_START_DELAY
+	prompt "'press any key to start nmon' dialog delay"
+	depends on NMON_USER_START
+	hex
+	default 3
+	help
+	  Select the delay interval for nmon 'press any key to start nmon' dialog.
+
+config NMON_HELP
+	bool "nmon help message"
+	depends on NMON
+	help
+	  Say yes here to get the nmon commands message on
+	  every nmon start.
+
 endmenu
 
 source common/Kconfig
diff --git a/arch/mips/include/asm/debug_ll_ns16550.h b/arch/mips/include/asm/debug_ll_ns16550.h
index f00f348..f36010c 100644
--- a/arch/mips/include/asm/debug_ll_ns16550.h
+++ b/arch/mips/include/asm/debug_ll_ns16550.h
@@ -38,6 +38,7 @@
 #endif /* CONFIG_DEBUG_LL */
 
 #define UART_THR	(0x0 << DEBUG_LL_UART_SHIFT)
+#define UART_RBR	(0x0 << DEBUG_LL_UART_SHIFT)
 #define UART_DLL	(0x0 << DEBUG_LL_UART_SHIFT)
 #define UART_DLM	(0x1 << DEBUG_LL_UART_SHIFT)
 #define UART_LCR	(0x3 << DEBUG_LL_UART_SHIFT)
@@ -46,6 +47,7 @@
 #define UART_LCR_W	0x07		/* Set UART to 8,N,2 & DLAB = 0 */
 #define UART_LCR_DLAB	0x87	/* Set UART to 8,N,2 & DLAB = 1 */
 
+#define UART_LSR_DR     0x01    /* UART received data present */
 #define UART_LSR_THRE	0x20	/* Xmit holding register empty */
 
 #ifndef __ASSEMBLY__
@@ -86,18 +88,30 @@ static __inline__ void PUTC_LL(char ch)
 /*
  * output a character in a0
  */
-.macro	debug_ll_ns16550_outc chr
+.macro	debug_ll_ns16550_outc_a0
 #ifdef CONFIG_DEBUG_LL
-	li	a0, \chr
+	.set	push
+	.set	reorder
+
 	la	t0, DEBUG_LL_UART_ADDR
 
-1:	lbu	t1, UART_LSR(t0)	/* get line status */
-	nop
+201:	lbu	t1, UART_LSR(t0)	/* get line status */
 	andi	t1, t1, UART_LSR_THRE	/* check for transmitter empty */
-	beqz	t1, 1b			/* try again */
-	 nop
+	beqz	t1, 201b			/* try again */
 
 	sb	a0, UART_THR(t0)	/* write the character */
+
+	.set	pop
+#endif /* CONFIG_DEBUG_LL */
+.endm
+
+/*
+ * output a character
+ */
+.macro	debug_ll_ns16550_outc chr
+#ifdef CONFIG_DEBUG_LL
+	li	a0, \chr
+	debug_ll_ns16550_outc_a0
 #endif /* CONFIG_DEBUG_LL */
 .endm
 
@@ -110,6 +124,80 @@ static __inline__ void PUTC_LL(char ch)
 	debug_ll_ns16550_outc '\n'
 #endif /* CONFIG_DEBUG_LL */
 .endm
+
+/*
+ * output a 32-bit value in hex
+ */
+.macro debug_ll_ns16550_outhexw
+#ifdef CONFIG_DEBUG_LL
+	.set	push
+	.set	reorder
+
+	move	t6, a0
+	li		t5, 32
+
+202:
+	addi	t5, t5, -4
+	srlv	a0, t6, t5
+
+	/* output one hex digit */
+	andi	a0, a0, 15
+	blt	a0, 10, 203f
+
+	addi	a0, a0, ('a' - '9' - 1)
+
+203:
+	addi	a0, a0, '0'
+
+	debug_ll_ns16550_outc_a0
+
+	bgtz	t5, 202b
+
+	.set	pop
+#endif /* CONFIG_DEBUG_LL */
+.endm
+
+/*
+ * check character in input buffer
+ * return value:
+ *  v0 = 0   no character in input buffer
+ *  v0 != 0  character in input buffer
+ */
+.macro	debug_ll_ns16550_check_char
+#ifdef CONFIG_DEBUG_LL
+	.set	push
+	.set	reorder
+
+	la      t0, DEBUG_LL_UART_ADDR
+
+	/* get line status and check for data present */
+	lbu	t1, UART_LSR(t0)
+	andi	v0, t1, UART_LSR_DR
+
+	.set	pop
+#endif /* CONFIG_DEBUG_LL */
+.endm
+
+/*
+ * get character to v0
+ */
+.macro	debug_ll_ns16550_getc
+#ifdef CONFIG_DEBUG_LL
+	.set	push
+	.set	reorder
+
+204:
+	debug_ll_ns16550_check_char
+
+	/* try again */
+	beqz	v0, 204b
+
+	/* read a character */
+	lbu	v0, UART_RBR(t0)
+
+	.set	pop
+#endif /* CONFIG_DEBUG_LL */
+.endm
 #endif /* __ASSEMBLY__ */
 
 #endif /* __INCLUDE_MIPS_ASM_DEBUG_LL_NS16550_H__ */
diff --git a/arch/mips/include/asm/pbl_nmon.h b/arch/mips/include/asm/pbl_nmon.h
new file mode 100644
index 0000000..e7baa4c
--- /dev/null
+++ b/arch/mips/include/asm/pbl_nmon.h
@@ -0,0 +1,270 @@
+/*
+ * nano-monitor for MIPS CPU
+ *
+ * Copyright (C) 2013 Antony Pavlov <antonynpavlov at gmail.com>
+ *
+ * This file is part of barebox.
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+#include <board/debug_ll.h>
+#include <asm/debug_ll_ns16550.h>
+
+#define CODE_ESC	0x1b
+
+/*
+ * Delay slot warning!
+ *
+ * NMON was made with code portability in mind.
+ * So it uses '.set reorder' directives allowing
+ * assembler to insert necessary 'nop' instructions
+ * into delay slots (after branch instruction) and
+ * into load delay slot (after memory load instruction
+ * on very old R2000/R3000 processors).
+ */
+
+	.macro	nmon_outs msg
+	.set	push
+	.set	reorder
+
+	ADR	a1, \msg, t1
+
+	bal	_nmon_outs
+
+	.set	pop
+	.endm
+
+
+	.macro	mips_nmon
+	.set	push
+	.set	reorder
+
+#ifdef CONFIG_NMON
+#ifdef CONFIG_NMON_USER_START
+
+#if CONFIG_NMON_USER_START_DELAY < 1
+#error CONFIG_NMON_USER_START_DELAY must be >= 1!
+#endif
+
+	nmon_outs	msg_nmon_press_any_key
+
+	li	s0, CONFIG_NMON_USER_START_DELAY
+	move	s1, s0
+
+1:
+	li	a0, '.'
+	bal	_nmon_outc_a0
+	addi	s1, s1, -1
+	bnez	s1, 1b
+
+	move	s1, s0
+
+nmon_wait_user:
+	pbl_sleep s2, CONFIG_NMON_1S_DELAY
+
+	nmon_outs	msg_bsp
+
+	debug_ll_ns16550_check_char
+
+	bnez	v0, 3f
+
+	addi	s1, s1, -1
+	bnez	s1, nmon_wait_user
+
+	nmon_outs	msg_skipping_nmon
+
+	b	nmon_exit
+
+msg_nmon_press_any_key:
+	.asciz "\r\npress any key to start nmon\r\n"
+
+	.align	4
+3:
+	/* get received char from ns16550's buffer */
+	debug_ll_ns16550_getc
+#endif /* CONFIG_NMON_USER_START */
+
+nmon_main_help:
+#ifdef CONFIG_NMON_HELP
+	nmon_outs	msg_nmon_help
+#endif /* CONFIG_NMON_HELP */
+
+nmon_main:
+	nmon_outs	msg_prompt
+
+	debug_ll_ns16550_getc
+
+	/* prepare a0 for debug_ll_ns16550_outc_a0 */
+	move	a0, v0
+
+	li	v1, 'q'
+	bne	v0, v1, 3f
+
+	bal	_nmon_outc_a0
+
+	b	nmon_exit
+
+3:
+	li	v1, 'd'
+	beq	v0, v1, nmon_cmd_d
+
+	li	v1, 'w'
+	beq	v0, v1, nmon_cmd_w
+
+	li	v1, 'g'
+	beq	v0, v1, nmon_cmd_g
+
+	b	nmon_main_help
+
+nmon_cmd_d:
+	bal	_nmon_outc_a0
+
+	li	a0, ' '
+	bal	_nmon_outc_a0
+
+	bal	_nmon_gethexw
+
+	nmon_outs	msg_nl
+
+	lw	a0, (v0)
+	debug_ll_ns16550_outhexw
+
+	b	nmon_main
+
+nmon_cmd_w:
+	bal	_nmon_outc_a0
+
+	li	a0, ' '
+	bal	_nmon_outc_a0
+	bal	_nmon_gethexw
+	move	s0, v0
+
+	li	a0, ' '
+	bal	_nmon_outc_a0
+	bal	_nmon_gethexw
+
+	sw	v0, (s0)
+	b	nmon_main
+
+nmon_cmd_g:
+	bal	_nmon_outc_a0
+
+	li	a0, ' '
+	bal	_nmon_outc_a0
+
+	bal	_nmon_gethexw
+
+	nmon_outs	msg_nl
+
+	jal	v0
+	b	nmon_main
+
+_nmon_outc_a0:
+	debug_ll_ns16550_outc_a0
+	jr	ra
+
+_nmon_outs:
+	lbu	a0, 0(a1)
+	addi	a1, a1, 1
+	beqz	a0, _nmon_jr_ra_exit
+
+	debug_ll_ns16550_outc_a0
+
+	b	_nmon_outs
+
+_nmon_gethexw:
+
+	li	t3, 8
+	li	t2, 0
+
+_get_hex_digit:
+	debug_ll_ns16550_getc
+
+	li	v1, CODE_ESC
+	beq	v0, v1, nmon_main
+
+	li	v1, '0'
+	bge	v0, v1, 0f
+	b	_get_hex_digit
+
+0:
+	li	v1, '9'
+	ble	v0, v1, 9f
+
+	li	v1, 'f'
+	ble	v0, v1, 1f
+	b	_get_hex_digit
+
+1:
+	li	v1, 'a'
+	bge	v0, v1, 8f
+
+	b	_get_hex_digit
+
+8: /* v0 \in {'a', 'b' ... 'f'} */
+	sub	a3, v0, v1
+	addi	a3, 0xa
+	b	0f
+
+9: /* v0 \in {'0', '1' ... '9'} */
+	li	a3, '0'
+	sub	a3, v0, a3
+
+0:	move	a0, v0
+	debug_ll_ns16550_outc_a0
+
+	sll	t2, t2, 4
+	or	t2, t2, a3
+	sub	t3, t3, 1
+
+	beqz	t3, 0f
+
+	b	_get_hex_digit
+
+0:
+	move	v0, t2
+
+_nmon_jr_ra_exit:
+	jr	ra
+
+msg_prompt:
+	.asciz "\r\nnmon> "
+
+msg_nl:
+	.asciz "\r\n"
+
+msg_bsp:
+	.asciz "\b \b"
+
+msg_skipping_nmon:
+	.asciz "skipping nmon..."
+
+#ifdef CONFIG_NMON_HELP
+msg_nmon_help:
+	.ascii "\r\n\r\nnmon commands:\r\n"
+	.ascii " q - quit\r\n"
+	.ascii " d <addr> - read 32-bit word from <addr>\r\n"
+	.ascii " w <addr> <val> - write 32-bit word to <addr>\r\n"
+	.ascii " g <addr> - jump to <addr>\r\n"
+	.asciz "   use <ESC> key to interrupt current command\r\n"
+#endif /* CONFIG_NMON_HELP */
+
+	.align	4
+
+nmon_exit:
+
+	nmon_outs	msg_nl
+
+#endif /* CONFIG_NMON */
+	.set	pop
+	.endm
-- 
1.7.10.4



From antonynpavlov at gmail.com  Mon Jun 24 15:10:12 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon, 24 Jun 2013 23:10:12 +0400
Subject: [PATCH 3/3] MIPS: qemu-malta: add nmon
In-Reply-To: <1372101012-11666-1-git-send-email-antonynpavlov@gmail.com>
References: <1372101012-11666-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1372101012-11666-4-git-send-email-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 arch/mips/boards/qemu-malta/include/board/board_pbl_start.h |    3 +++
 arch/mips/mach-malta/Kconfig                                |    1 +
 2 files changed, 4 insertions(+)

diff --git a/arch/mips/boards/qemu-malta/include/board/board_pbl_start.h b/arch/mips/boards/qemu-malta/include/board/board_pbl_start.h
index 5b06770..bcd9789 100644
--- a/arch/mips/boards/qemu-malta/include/board/board_pbl_start.h
+++ b/arch/mips/boards/qemu-malta/include/board/board_pbl_start.h
@@ -18,6 +18,7 @@
  */
 
 #include <asm/pbl_macros.h>
+#include <asm/pbl_nmon.h>
 
 	.macro	board_pbl_start
 	.set	push
@@ -28,6 +29,8 @@
 	/* cpu specific setup ... */
 	/* ... absent */
 
+	mips_nmon
+
 	copy_to_link_location	pbl_start
 
 	.set	pop
diff --git a/arch/mips/mach-malta/Kconfig b/arch/mips/mach-malta/Kconfig
index 1d291dc..67763f8 100644
--- a/arch/mips/mach-malta/Kconfig
+++ b/arch/mips/mach-malta/Kconfig
@@ -11,6 +11,7 @@ config BOARD_QEMU_MALTA
 	bool "qemu malta"
 	select HAVE_PBL_IMAGE
 	select HAVE_IMAGE_COMPRESSION
+	select HAS_NMON
 
 endchoice
 
-- 
1.7.10.4



From antonynpavlov at gmail.com  Mon Jun 24 15:10:11 2013
From: antonynpavlov at gmail.com (Antony Pavlov)
Date: Mon, 24 Jun 2013 23:10:11 +0400
Subject: [PATCH 2/3] MIPS: qemu-malta: rework debug_ll.h
In-Reply-To: <1372101012-11666-1-git-send-email-antonynpavlov@gmail.com>
References: <1372101012-11666-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <1372101012-11666-3-git-send-email-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 .../boards/qemu-malta/include/board/debug_ll.h     |   27 ++++++++++++++++++++
 arch/mips/boards/qemu-malta/init.c                 |    2 +-
 arch/mips/mach-malta/include/mach/debug_ll.h       |    9 +++----
 arch/mips/mach-malta/include/mach/hardware.h       |    4 +--
 4 files changed, 33 insertions(+), 9 deletions(-)
 create mode 100644 arch/mips/boards/qemu-malta/include/board/debug_ll.h

diff --git a/arch/mips/boards/qemu-malta/include/board/debug_ll.h b/arch/mips/boards/qemu-malta/include/board/debug_ll.h
new file mode 100644
index 0000000..1e56040
--- /dev/null
+++ b/arch/mips/boards/qemu-malta/include/board/debug_ll.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2013 Antony Pavlov <antonynpavlov at gmail.com>
+ *
+ * This file is part of barebox.
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+#ifndef __INCLUDE_BOARD_DEBUG_LL_QEMU_MALTA_H__
+#define __INCLUDE_BOARD_DEBUG_LL_QEMU_MALTA_H__
+
+#include <mach/hardware.h>
+
+#define DEBUG_LL_UART_ADDR	MALTA_PIIX4_UART0
+#define DEBUG_LL_UART_SHIFT	0
+#define DEBUG_LL_UART_DIVISOR 1843200 /* no matter for emulated port */
+
+#endif /* __INCLUDE_BOARD_DEBUG_LL_QEMU_MALTA_H__ */
diff --git a/arch/mips/boards/qemu-malta/init.c b/arch/mips/boards/qemu-malta/init.c
index db26b3b..f77fcad 100644
--- a/arch/mips/boards/qemu-malta/init.c
+++ b/arch/mips/boards/qemu-malta/init.c
@@ -44,7 +44,7 @@ static struct NS16550_plat serial_plat = {
 static int malta_console_init(void)
 {
 	/* Register the serial port */
-	add_ns16550_device(DEVICE_ID_DYNAMIC, DEBUG_LL_UART_ADDR, 8,
+	add_ns16550_device(DEVICE_ID_DYNAMIC, MALTA_PIIX4_UART0, 8,
 			IORESOURCE_MEM_8BIT, &serial_plat);
 
 	return 0;
diff --git a/arch/mips/mach-malta/include/mach/debug_ll.h b/arch/mips/mach-malta/include/mach/debug_ll.h
index 3e8b01b..c9e89bc 100644
--- a/arch/mips/mach-malta/include/mach/debug_ll.h
+++ b/arch/mips/mach-malta/include/mach/debug_ll.h
@@ -18,11 +18,10 @@
 /** @file
  *  This File contains declaration for early output support
  */
-#ifndef __INCLUDE_ARCH_DEBUG_LL_H__
-#define   __INCLUDE_ARCH_DEBUG_LL_H__
-
-#include <mach/hardware.h>
+#ifndef __MACH_MALTA_DEBUG_LL_H__
+#define __MACH_MALTA_DEBUG_LL_H__
 
+#include <board/debug_ll.h>
 #include <asm/debug_ll_ns16550.h>
 
-#endif  /* __INCLUDE_ARCH_DEBUG_LL_H__ */
+#endif /* __MACH_MALTA_DEBUG_LL_H__ */
diff --git a/arch/mips/mach-malta/include/mach/hardware.h b/arch/mips/mach-malta/include/mach/hardware.h
index 8bd814d..affb4ea 100644
--- a/arch/mips/mach-malta/include/mach/hardware.h
+++ b/arch/mips/mach-malta/include/mach/hardware.h
@@ -18,9 +18,7 @@
 #ifndef __INCLUDE_ARCH_HARDWARE_H__
 #define   __INCLUDE_ARCH_HARDWARE_H__
 
-#define DEBUG_LL_UART_ADDR	0xb00003f8
-#define DEBUG_LL_UART_SHIFT	0
-#define DEBUG_LL_UART_DIVISOR	1	/* no matter for emulated port */
+#define MALTA_PIIX4_UART0	0xb00003f8
 
 /*
  * Reset register.
-- 
1.7.10.4



From s.hauer at pengutronix.de  Mon Jun 24 15:40:14 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 21:40:14 +0200
Subject: [PATCH v2 1/2] OF: base: add sanity checks to
 of_new/delete_property
In-Reply-To: <1372070961-10132-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1371827718-7928-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372070961-10132-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130624194014.GU32299@pengutronix.de>

On Mon, Jun 24, 2013 at 12:49:20PM +0200, Sebastian Hesselbarth wrote:
> This adds some sanity checks to of_new_property and of_delete_property.
> Also, value pointer is always allocated even with zero length to allow
> empty properties to be distinguished from non-existing properties.
> Finally, data passed to of_new_property is only copied if non-NULL.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>

Applied both.

Thanks
 Sascha

> ---
> Note: Patch 3 of the former patch set has been dropped in favour of zero
> length allocation here.
> 
> Changelog:
> v1->v2:
> - remove unneccesary NULL checks after xzalloc (Suggested by Sascha Hauer)
> - allocate zero length value pointer (Suggested by Sascha Hauer)
> 
> Cc: barebox at lists.infradead.org
> ---
>  drivers/of/base.c |   15 +++++++++++----
>  1 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 1b351ee..e65cf85 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1527,13 +1527,17 @@ struct property *of_new_property(struct device_node *node, const char *name,
>  	struct property *prop;
>  
>  	prop = xzalloc(sizeof(*prop));
> -
>  	prop->name = strdup(name);
> +	if (!prop->name) {
> +		free(prop);
> +		return NULL;
> +	}
> +
>  	prop->length = len;
> -	if (len) {
> -		prop->value = xzalloc(len);
> +	prop->value = xzalloc(len);
> +
> +	if (data)
>  		memcpy(prop->value, data, len);
> -	}
>  
>  	list_add_tail(&prop->list, &node->properties);
>  
> @@ -1542,6 +1546,9 @@ struct property *of_new_property(struct device_node *node, const char *name,
>  
>  void of_delete_property(struct property *pp)
>  {
> +	if (!pp)
> +		return;
> +
>  	list_del(&pp->list);
>  
>  	free(pp->name);
> -- 
> 1.7.2.5
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 24 15:44:05 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 21:44:05 +0200
Subject: [PATCH] ubiformat: check file size
In-Reply-To: <1372059045-18113-1-git-send-email-j.weitzel@phytec.de>
References: <1372059045-18113-1-git-send-email-j.weitzel@phytec.de>
Message-ID: <20130624194405.GW32299@pengutronix.de>

On Mon, Jun 24, 2013 at 09:30:45AM +0200, Jan Weitzel wrote:
> If size of a flash image file is 0 ubiformat silently formats the volume.
> Check size and abort if size == 0. This may be the case if an empty or tftp
> mounted file is used.
> 
> Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>

Applied, thanks

Sascha

> ---
>  commands/ubiformat.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/commands/ubiformat.c b/commands/ubiformat.c
> index 121816f..5b4e572 100644
> --- a/commands/ubiformat.c
> +++ b/commands/ubiformat.c
> @@ -325,6 +325,11 @@ static int flash_image(const struct mtd_dev_info *mtd,
>  		goto out_close;
>  	}
>  
> +	if (st_size == 0) {
> +		sys_errmsg("file \"%s\" has size 0 bytes", args.image);
> +		goto out_close;
> +	}
> +
>  	verbose(args.verbose, "will write %d eraseblocks", img_ebs);
>  	divisor = img_ebs;
>  	for (eb = 0; eb < mtd->eb_cnt; eb++) {
> -- 
> 1.7.0.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 24 15:45:20 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 21:45:20 +0200
Subject: [PATCH] nand_base: fix chipsize for multi LUN nands
In-Reply-To: <1372075722-9872-1-git-send-email-j.weitzel@phytec.de>
References: <1372075722-9872-1-git-send-email-j.weitzel@phytec.de>
Message-ID: <20130624194520.GX32299@pengutronix.de>

On Mon, Jun 24, 2013 at 02:08:42PM +0200, Jan Weitzel wrote:
> Chipsize didn't take number of LUNs into account. Sync chipsize calculation
> to kernel commit 63795755
> Tested with MT29F8G16ADBDAH4 on OMAP4
> 
> Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>

Applied, thanks

Sascha

> ---
>  drivers/mtd/nand/nand_base.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index 8c14112..1969aff 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -1117,7 +1117,8 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
>  	mtd->writesize = le32_to_cpu(p->byte_per_page);
>  	mtd->erasesize = le32_to_cpu(p->pages_per_block) * mtd->writesize;
>  	mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page);
> -	chip->chipsize = (uint64_t)le32_to_cpu(p->blocks_per_lun) * mtd->erasesize;
> +	chip->chipsize = le32_to_cpu(p->blocks_per_lun);
> +	chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count;
>  	*busw = 0;
>  	if (le16_to_cpu(p->features) & 1)
>  		*busw = NAND_BUSWIDTH_16;
> -- 
> 1.7.0.4
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Mon Jun 24 15:50:21 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Mon, 24 Jun 2013 21:50:21 +0200
Subject: [PATCH 1/2] omap-fb: add driver
In-Reply-To: <1372080750.6281.4.camel@mars>
References: <1371634395.4111.54.camel@mars>
 <1372080750.6281.4.camel@mars>
Message-ID: <20130624195021.GY32299@pengutronix.de>

On Mon, Jun 24, 2013 at 03:32:30PM +0200, Christoph Fritz wrote:
> On Wed, 2013-06-19 at 11:33 +0200, Christoph Fritz wrote:
> > This patch adds omap display controller support. Currently only
> > OMAP4 DSS is supported.
> 
> Any objections here?

Oh, sorry, I missed this last version. Applied now

Thanks
 Sascha

> 
> These are the changes in the review-process so far:
> 
> changes since v2:
>         - use dev_request_mem_region_by_name()
> changes since v3:
>         - remove register struct
>         - use uncached screen_base
> changes since v4:
>         - remove useless dev_add_param()
>         - use wait_on_timeout() instead while-deadlock
> changes since v5:
>         - use dev_dbg() and dev_err(), be less verbose
>         - fix coding-style issues
>         - add omap4fb_find_display_by_name()
>         - add additional read/write macros
> changes since v6:
> 	- split driver into two commits
> 	- rename driver to "omap-fb"
> 
>  Thanks
>   -- Christoph
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Jun 25 00:22:58 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 06:22:58 +0200
Subject: [PATCH 1/2] ARM OMAP: MLO: add support for loading Barebox from
 UBI
In-Reply-To: <1371808521.3949.14.camel@mars>
References: <1371808410.3949.13.camel@mars>
 <1371808521.3949.14.camel@mars>
Message-ID: <20130625042258.GF14308@pengutronix.de>

Hi Christoph,

On Fri, Jun 21, 2013 at 11:55:21AM +0200, Christoph Fritz wrote:
> This patch adds support to OMAP MLO to load a secound
> stage bootloader from a static UBI volume.
> 
> Signed-off-by: Christoph Fritz <chf.fritz at googlemail.com>
> ---
>  arch/arm/mach-omap/Kconfig |   44 +++++++++++++++++++++++++
>  arch/arm/mach-omap/xload.c |   76 ++++++++++++++++++++++++++++++++++++++++++--
>  2 files changed, 118 insertions(+), 2 deletions(-)
> 
> +static void *omap_xload_boot_ubi_nand(void)
> +{
> +	void *to = NULL;
> +#ifdef CONFIG_BB_IN_UBI

You shouldn't need this ifdef

> +	void *header;
> +	int ret;
> +	struct cdev *cdev;
> +	struct mtd_info_user user;
> +	int size;
> +
> +	devfs_add_partition("nand0", CONFIG_BB_IN_UBI_PARTITION_START,
> +		CONFIG_BB_IN_UBI_PARTITION_SIZE, DEVFS_PARTITION_FIXED, "u");

I don't like putting these in kconfig. Ideally these should be passed by
the board code.

> +
> +	cdev = cdev_open(CONFIG_BB_IN_UBI_VOLNAME, O_RDONLY);
> +	if (!cdev) {
> +		printf("cdev_open failed\n");

Such error messages should always print the return value if possible.

> +		return NULL;
> +	}
> +
> +	if (cdev_read(cdev, to, size, 0, 0) < 0) {
> +		printf("cdev_read failed\n");

ditto.

> +		cdev_close(cdev);
> +		return NULL;
> +        }
> +
> +	cdev_close(cdev);
> +
> +#endif
> +	return to;
> +}
> +
>  static void *omap_xload_boot_mmc(void)
>  {
>  	int ret;
> @@ -180,8 +247,13 @@ static __noreturn int omap_xload(void)
>  			printf("booting from USB not enabled\n");
>  		}
>  	case BOOTSOURCE_NAND:
> -		printf("booting from NAND\n");
> -		func = omap_xload_boot_nand(SZ_128K);
> +		if (IS_ENABLED(CONFIG_BB_IN_UBI)) {
> +			printf("booting from UBI static volume\n");
> +			func = omap_xload_boot_ubi_nand();

You could check for filetype_ubi here instead of making this a
compiletime decision.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Jun 25 01:26:44 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 07:26:44 +0200
Subject: [PATCH 2/2] ARM OMAP: add support for loading Environment from UBI
In-Reply-To: <1371808556.3949.15.camel@mars>
References: <1371808410.3949.13.camel@mars>
 <1371808556.3949.15.camel@mars>
Message-ID: <20130625052644.GG14308@pengutronix.de>

On Fri, Jun 21, 2013 at 11:55:56AM +0200, Christoph Fritz wrote:
> This patch adds support to load environment from a static
> UBI volume.
> 
>  	if (IS_ENABLED(CONFIG_ENV_HANDLING)) {
>  		int ret;
>  
> +		if (IS_ENABLED(CONFIG_ENVIRONMENT_IN_UBI)) {
> +#ifdef CONFIG_ENVIRONMENT_IN_UBI
> +			char s[PATH_MAX + 32];
> +			sprintf(s, "%s%s ", "ubiattach ",
> +				CONFIG_ENV_IN_UBI_PARTITION);
> +			ret = run_command(s, 0);
> +			if (ret) {
> +				sprintf(s, "%s%s ", "unable to ubiattach ",
> +					CONFIG_ENV_IN_UBI_PARTITION);
> +				pr_err(s);
> +			} else {
> +				default_environment_path =
> +					CONFIG_ENV_IN_UBI_VOLNAME;
> +			}
> +#endif

You shouldn't need the ifdef here aswell. Also this should be a helper
function called from board code rather than something in generic code.
You can also hardcode the volume name in board code, I don't think this
needs to be configurable.

Configurability of stuff like environment position always has a problem.
If it wasn't you who compiled a particular binary (or it even was you
and you can't remember), you don't know how the binary behaves. For
everything you hardcode the version printout in barebox will exactly
tell you the behaviour.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:38 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:38 +0200
Subject: [PATCH 0/9] OF: address and device related sync and cleanup
Message-ID: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>

This patch set comprises a quite unsorted bunch of patches to further
improve and cleanup OF API. With address and device related functions,
two more API sets of Linux OF API are imported and modified to match
barebox driver core.

With above API improvements, device and resource pointer are removed
from struct device_node. Futher, of_translate_address, of_probe, and
of_add_memory are converted to recently introduced OF API.

At last, of_free is renamed to of_delete_node, which gives a better
impression of what the function is doing.

Sebastian Hesselbarth (9):
  OF: import address related functions from Linux OF API
  OF: convert of_translate_address to new API
  OF: base: move OF_ROOT_NODE_ defines to local OF code
  OF: import bus/device related functions from Linux OF API
  OF: base: use of_platform_populate for probing
  OF: base: remove dead device related functions
  OF: remove device and resource pointer from struct device_node
  OF: base: convert of_add_memory to OF API
  OF: base: rename of_free to of_delete_node

 commands/of_node.c    |    2 +-
 commands/oftree.c     |    4 +-
 drivers/of/Makefile   |    2 +-
 drivers/of/address.c  |  437 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/of/base.c     |  339 +++++---------------------------------
 drivers/of/fdt.c      |    2 +-
 drivers/of/gpio.c     |    6 +-
 drivers/of/platform.c |  294 +++++++++++++++++++++++++++++++++
 include/of.h          |   30 +++-
 include/of_address.h  |   72 ++++++++
 10 files changed, 879 insertions(+), 309 deletions(-)
 create mode 100644 drivers/of/address.c
 create mode 100644 drivers/of/platform.c
 create mode 100644 include/of_address.h

---
Cc: barebox at lists.infradead.org
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:44 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:44 +0200
Subject: [PATCH 6/9] OF: base: remove dead device related functions
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372152047-28134-7-git-send-email-sebastian.hesselbarth@gmail.com>

With recent conversion to of_platfrom_populate_some functions are now
dead code and can be removed.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |  183 -----------------------------------------------------
 1 files changed, 0 insertions(+), 183 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index eb9ac84..9d63127 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1543,94 +1543,6 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
 	return 0;
 }
 
-static struct device_d *add_of_amba_device(struct device_node *node)
-{
-	struct amba_device *dev;
-	char *name, *at;
-
-	dev = xzalloc(sizeof(*dev));
-
-	name = xstrdup(node->name);
-	at = strchr(name, '@');
-	if (at) {
-		*at = 0;
-		snprintf(dev->dev.name, MAX_DRIVER_NAME, "%s.%s", at + 1, name);
-	} else {
-		strncpy(dev->dev.name, node->name, MAX_DRIVER_NAME);
-	}
-
-	dev->dev.id = DEVICE_ID_SINGLE;
-	memcpy(&dev->res, &node->resource[0], sizeof(struct resource));
-	dev->dev.resource = node->resource;
-	dev->dev.num_resources = 1;
-	dev->dev.device_node = node;
-	node->device = &dev->dev;
-
-	of_property_read_u32(node, "arm,primecell-periphid", &dev->periphid);
-
-	debug("register device 0x%08x\n", node->resource[0].start);
-
-	amba_device_add(dev);
-
-	free(name);
-
-	return &dev->dev;
-}
-
-static struct device_d *add_of_platform_device(struct device_node *node,
-		struct device_d *parent)
-{
-	struct device_d *dev;
-	char *name, *at;
-
-	dev = xzalloc(sizeof(*dev));
-
-	dev->parent = parent;
-
-	name = xstrdup(node->name);
-	at = strchr(name, '@');
-	if (at) {
-		*at = 0;
-		snprintf(dev->name, MAX_DRIVER_NAME, "%s.%s", at + 1, name);
-	} else {
-		strncpy(dev->name, node->name, MAX_DRIVER_NAME);
-	}
-
-	dev->id = DEVICE_ID_SINGLE;
-	dev->resource = node->resource;
-	dev->num_resources = node->num_resource;
-	dev->device_node = node;
-	node->device = dev;
-
-	debug("register device 0x%08x\n", node->resource[0].start);
-
-	platform_device_register(dev);
-
-	free(name);
-
-	return dev;
-}
-
-static struct device_d *add_of_device(struct device_node *node,
-		struct device_d *parent)
-{
-	const struct property *cp;
-
-	if (!of_device_is_available(node))
-		return NULL;
-
-	cp = of_get_property(node, "compatible", NULL);
-	if (!cp)
-		return NULL;
-
-	if (IS_ENABLED(CONFIG_ARM_AMBA) &&
-	    of_device_is_compatible(node, "arm,primecell") == 1)
-		return add_of_amba_device(node);
-	else
-		return add_of_platform_device(node, parent);
-}
-EXPORT_SYMBOL(add_of_device);
-
 static u64 dt_mem_next_cell(int s, const __be32 **cellp)
 {
 	const __be32 *p = *cellp;
@@ -1678,82 +1590,6 @@ int of_add_memory(struct device_node *node, bool dump)
 	return 0;
 }
 
-static struct device_d *add_of_device_resource(struct device_node *node,
-		struct device_d *parent)
-{
-	u64 address = 0, size;
-	struct resource *res, *resp;
-	struct device_d *dev;
-	const __be32 *endp, *reg;
-	const char *resname;
-	int na, nc, n_resources;
-	int ret, len, index;
-
-	reg = of_get_property(node, "reg", &len);
-	if (!reg)
-		return add_of_device(node, parent);
-
-	of_bus_count_cells(node, &na, &nc);
-
-	n_resources = (len / sizeof(__be32)) / (na + nc);
-
-	res = resp = xzalloc(sizeof(*res) * n_resources);
-
-	endp = reg + (len / sizeof(__be32));
-
-	index = 0;
-
-	while ((endp - reg) >= (na + nc)) {
-		address = of_translate_address(node, reg);
-		if (address == OF_BAD_ADDR) {
-			ret =  -EINVAL;
-			goto err_free;
-		}
-
-		reg += na;
-		size = dt_mem_next_cell(nc, &reg);
-
-		resp->start = address;
-		resp->end = address + size - 1;
-		resname = NULL;
-		of_property_read_string_index(node, "reg-names", index, &resname);
-		if (resname)
-			resp->name = xstrdup(resname);
-		resp->flags = IORESOURCE_MEM;
-		resp++;
-		index++;
-        }
-
-	/*
-	 * A device may already be registered as platform_device.
-	 * Instead of registering the same device again, just
-	 * add this node to the existing device.
-	 */
-	for_each_device(dev) {
-		if (!dev->resource)
-			continue;
-		if (dev->resource->start == res->start &&
-				dev->resource->end == res->end) {
-			debug("connecting %s to %s\n", node->name, dev_name(dev));
-			node->device = dev;
-			dev->device_node = node;
-			node->resource = dev->resource;
-			ret = 0;
-			goto err_free;
-		}
-	}
-
-	node->resource = res;
-	node->num_resource = n_resources;
-
-	return add_of_device(node, parent);
-
-err_free:
-	free(res);
-
-	return NULL;
-}
-
 void of_free(struct device_node *node)
 {
 	struct device_node *n, *nt;
@@ -1787,25 +1623,6 @@ void of_free(struct device_node *node)
 		of_set_root_node(NULL);
 }
 
-static void __of_probe(struct device_node *node,
-		const struct of_device_id *matches,
-		struct device_d *parent)
-{
-	struct device_node *n;
-	struct device_d *dev;
-
-	if (node->device)
-		return;
-
-	dev = add_of_device_resource(node, parent);
-
-	if (!of_match_node(matches, node))
-		return;
-
-	list_for_each_entry(n, &node->children, parent_list)
-		__of_probe(n, matches, dev);
-}
-
 static void __of_parse_phandles(struct device_node *node)
 {
 	struct device_node *n;
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:43 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:43 +0200
Subject: [PATCH 5/9] OF: base: use of_platform_populate for probing
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372152047-28134-6-git-send-email-sebastian.hesselbarth@gmail.com>

With recent bus/device related functions in OF API, we can now
convert to use of_platform_populate.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 429f924..eb9ac84 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1840,7 +1840,7 @@ const struct of_device_id of_default_bus_match_table[] = {
 
 int of_probe(void)
 {
-	struct device_node *memory, *n;
+	struct device_node *memory;
 
 	if(!root_node)
 		return -ENODEV;
@@ -1854,8 +1854,7 @@ int of_probe(void)
 	if (memory)
 		of_add_memory(memory, false);
 
-	list_for_each_entry(n, &root_node->children, parent_list)
-		__of_probe(n, of_default_bus_match_table, NULL);
+	of_platform_populate(root_node, of_default_bus_match_table, NULL);
 
 	return 0;
 }
-- 
1.7.2.5



From s.hauer at pengutronix.de  Tue Jun 25 05:20:45 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:45 +0200
Subject: [PATCH 05/12] imx-image: fix path to imx-image binary
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-6-git-send-email-s.hauer@pengutronix.de>

$(obj) doesn't necessarily contain the toplevel object path. Use
$(objtree) for this.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 scripts/Makefile.lib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0b56dcc..307412f 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -329,4 +329,4 @@ $(obj)/%.S: $(obj)/%.dcd
 	$(call cmd,imximage_S_dcd)
 
 quiet_cmd_imx_image = IMX-IMG $@
-      cmd_imx_image = $(obj)/scripts/imx/imx-image -b -c $(CFG_$(@F)) -f $< -o $@
+      cmd_imx_image = $(objtree)/scripts/imx/imx-image -b -c $(CFG_$(@F)) -f $< -o $@
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 05:20:47 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:47 +0200
Subject: [PATCH 07/12] ARM: i.MX: Add multi images support Makefile
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-8-git-send-email-s.hauer@pengutronix.de>

This adds images/Makefile.imx which will contain the i.MX
specific image generation snippets.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 images/Makefile     |  2 ++
 images/Makefile.imx | 10 ++++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 images/Makefile.imx

diff --git a/images/Makefile b/images/Makefile
index fe1f77d..925a987 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -106,6 +106,8 @@ $(obj)/%.img: $(obj)/$$(FILE_$$(@F))
 	$(Q)if [ -z $(FILE_$(@F)) ]; then echo "FILE_$(@F) empty!"; false; fi
 	$(call if_changed,shipped)
 
+include $(srctree)/images/Makefile.imx
+
 targets += $(image-y) pbl.lds barebox.x barebox.z
 targets += $(patsubst %,%.pblx,$(pblx-y))
 targets += $(patsubst %,%.pblb,$(pblx-y))
diff --git a/images/Makefile.imx b/images/Makefile.imx
new file mode 100644
index 0000000..cd7b610
--- /dev/null
+++ b/images/Makefile.imx
@@ -0,0 +1,10 @@
+#
+# barebox image generation Makefile for i.MX images
+#
+
+# %.imximg - convert into i.MX image
+# ----------------------------------------------------------------
+$(obj)/%.imximg: $(obj)/% FORCE
+	$(call if_changed,imx_image)
+
+board = $(srctree)/arch/$(ARCH)/boards
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:47 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:47 +0200
Subject: [PATCH 9/9] OF: base: rename of_free to of_delete_node
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372152047-28134-10-git-send-email-sebastian.hesselbarth@gmail.com>

of_free is misleading about the actual purpose of the function. There is
already a of_create_node counterpart, so rename of_free to of_create_node
and update all users accordingly.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 commands/of_node.c |    2 +-
 commands/oftree.c  |    4 +-
 drivers/of/base.c  |   65 +++++++++++++++++++++++++--------------------------
 drivers/of/fdt.c   |    2 +-
 include/of.h       |    4 +-
 5 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/commands/of_node.c b/commands/of_node.c
index e60ef66..b1894b1 100644
--- a/commands/of_node.c
+++ b/commands/of_node.c
@@ -87,7 +87,7 @@ static int do_of_node(int argc, char *argv[])
 			return -ENOENT;
 		}
 
-		of_free(node);
+		of_delete_node(node);
 	}
 
 	return 0;
diff --git a/commands/oftree.c b/commands/oftree.c
index 9149517..00e54dc 100644
--- a/commands/oftree.c
+++ b/commands/oftree.c
@@ -86,7 +86,7 @@ static int do_oftree(int argc, char *argv[])
 		struct device_node *root = of_get_root_node();
 
 		if (root)
-			of_free(root);
+			of_delete_node(root);
 
 		return 0;
 	}
@@ -162,7 +162,7 @@ static int do_oftree(int argc, char *argv[])
 				goto out;
 			}
 			of_print_nodes(root, 0);
-			of_free(root);
+			of_delete_node(root);
 		} else {
 			struct device_node *n = of_find_node_by_path(node);
 			if (!n) {
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 6fc962d..d077335 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1549,39 +1549,6 @@ int of_add_memory(struct device_node *node, bool dump)
 	return 0;
 }
 
-void of_free(struct device_node *node)
-{
-	struct device_node *n, *nt;
-	struct property *p, *pt;
-	struct device_d *dev;
-
-	if (!node)
-		return;
-
-	list_for_each_entry_safe(p, pt, &node->properties, list)
-		of_delete_property(p);
-
-	list_for_each_entry_safe(n, nt, &node->children, parent_list) {
-		of_free(n);
-	}
-
-	if (node->parent) {
-		list_del(&node->parent_list);
-		list_del(&node->list);
-	}
-
-	dev = of_find_device_by_node(node);
-	if (dev)
-		dev->device_node = NULL;
-
-	free(node->name);
-	free(node->full_name);
-	free(node);
-
-	if (node == root_node)
-		of_set_root_node(NULL);
-}
-
 static void __of_parse_phandles(struct device_node *node)
 {
 	struct device_node *n;
@@ -1679,6 +1646,38 @@ out:
 	return dn;
 }
 
+void of_delete_node(struct device_node *node)
+{
+	struct device_node *n, *nt;
+	struct property *p, *pt;
+	struct device_d *dev;
+
+	if (!node)
+		return;
+
+	list_for_each_entry_safe(p, pt, &node->properties, list)
+		of_delete_property(p);
+
+	list_for_each_entry_safe(n, nt, &node->children, parent_list)
+		of_delete_node(n);
+
+	if (node->parent) {
+		list_del(&node->parent_list);
+		list_del(&node->list);
+	}
+
+	dev = of_find_device_by_node(node);
+	if (dev)
+		dev->device_node = NULL;
+
+	free(node->name);
+	free(node->full_name);
+	free(node);
+
+	if (node == root_node)
+		of_set_root_node(NULL);
+}
+
 int of_device_is_stdout_path(struct device_d *dev)
 {
 	struct device_node *dn;
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index afaa4e0..76d6bb1 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -211,7 +211,7 @@ struct device_node *of_unflatten_dtb(struct device_node *root, void *infdt)
 		}
 	}
 err:
-	of_free(root);
+	of_delete_node(root);
 
 	return ERR_PTR(ret);
 }
diff --git a/include/of.h b/include/of.h
index 0298189..e832a78 100644
--- a/include/of.h
+++ b/include/of.h
@@ -142,7 +142,7 @@ extern struct device_node *of_new_node(struct device_node *parent,
 				const char *name);
 extern struct device_node *of_create_node(struct device_node *root,
 					const char *path);
-extern void of_free(struct device_node *node);
+extern void of_delete_node(struct device_node *node);
 
 extern int of_machine_is_compatible(const char *compat);
 extern int of_device_is_compatible(const struct device_node *device,
@@ -511,7 +511,7 @@ static inline struct device_node *of_create_node(struct device_node *root,
 	return NULL;
 }
 
-static inline void of_free(struct device_node *node)
+static inline void of_delete_node(struct device_node *node)
 {
 }
 
-- 
1.7.2.5



From s.hauer at pengutronix.de  Tue Jun 25 05:20:44 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:44 +0200
Subject: [PATCH 04/12] ARM: Add image end section
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-5-git-send-email-s.hauer@pengutronix.de>

In the upcoming multi image build process we will cat images together.
To find the concatenated image we need to reliably find the end of the
current binary. This adds a dummy section at the end of a pbl binary.
Its only purpose is to mark the end of the image. The multi image
patches will add something to this section so that it doesn't get
discarded by the linker.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/lib/pbl.lds.S         | 8 +++++++-
 arch/arm/lib/runtime-offset.S  | 3 +++
 include/asm-generic/sections.h | 1 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S
index d3ec2f8..1eae829 100644
--- a/arch/arm/lib/pbl.lds.S
+++ b/arch/arm/lib/pbl.lds.S
@@ -86,6 +86,12 @@ SECTIONS
 	}
 	__piggydata_end = .;
 
-	_barebox_image_size = __piggydata_end - (TEXT_BASE - SZ_2M);
+	. = ALIGN(4);
+	.image_end : {
+		KEEP(*(.image_end))
+	}
+	__image_end = .;
+
+	_barebox_image_size = __image_end - (TEXT_BASE - SZ_2M);
 	_barebox_pbl_size = __bss_start - (TEXT_BASE - SZ_2M);
 }
diff --git a/arch/arm/lib/runtime-offset.S b/arch/arm/lib/runtime-offset.S
index 15bf414..f10c4c8 100644
--- a/arch/arm/lib/runtime-offset.S
+++ b/arch/arm/lib/runtime-offset.S
@@ -42,6 +42,9 @@ ld_var_entry __dynsym_end
 ld_var_entry _barebox_image_size
 ld_var_entry __bss_start
 ld_var_entry __bss_stop
+#ifdef __PBL__
+ld_var_entry __image_end
+#endif
 
 1:
 	ldr r1, =__ld_var_base
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 5492aa4..984f8b6 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -6,6 +6,7 @@ extern char __bss_start[], __bss_stop[];
 extern char _sdata[], _edata[];
 extern char __bare_init_start[], __bare_init_end[];
 extern char _end[];
+extern char __image_end[];
 extern void *_barebox_image_size;
 extern void *_barebox_bare_init_size;
 extern void *_barebox_pbl_size;
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:42 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:42 +0200
Subject: [PATCH 4/9] OF: import bus/device related functions from Linux OF API
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372152047-28134-5-git-send-email-sebastian.hesselbarth@gmail.com>

This imports some bus and device related functions from Linux OF API
with some modifcations for Barebox.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/Makefile   |    2 +-
 drivers/of/platform.c |  294 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h          |   18 +++
 3 files changed, 313 insertions(+), 1 deletions(-)
 create mode 100644 drivers/of/platform.c

diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index b8add0b..186074e 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,4 +1,4 @@
-obj-y += address.o base.o fdt.o
+obj-y += address.o base.o fdt.o platform.o
 obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o
 obj-$(CONFIG_GPIOLIB) += gpio.o
 obj-y += partition.o
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
new file mode 100644
index 0000000..450d770
--- /dev/null
+++ b/drivers/of/platform.c
@@ -0,0 +1,294 @@
+/*
+ * platform.c - bus/device related devicetree functions
+ *
+ * Copyright (c) 2012 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ *
+ * based on Linux devicetree support
+ *
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+#include <common.h>
+#include <malloc.h>
+#include <of.h>
+#include <of_address.h>
+#include <linux/amba/bus.h>
+
+/**
+ * of_find_device_by_node - Find the platform_device associated with a node
+ * @np: Pointer to device tree node
+ *
+ * Returns platform_device pointer, or NULL if not found
+ */
+struct device_d *of_find_device_by_node(struct device_node *np)
+{
+        struct device_d *dev;
+
+	for_each_device(dev)
+		if (dev->device_node == np)
+			return dev;
+        return NULL;
+}
+EXPORT_SYMBOL(of_find_device_by_node);
+
+/**
+ * of_device_make_bus_id - Use the device node data to assign a unique name
+ * @dev: pointer to device structure that is linked to a device tree node
+ *
+ * This routine will first try using either the dcr-reg or the reg property
+ * value to derive a unique name.  As a last resort it will use the node
+ * name followed by a unique number.
+ */
+static void of_device_make_bus_id(struct device_d *dev)
+{
+	static int bus_no_reg_magic;
+	struct device_node *np = dev->device_node;
+	const __be32 *reg, *addrp;
+	u64 addr;
+	char *name, *at;
+
+	name = xstrdup(np->name);
+	at = strchr(name, '@');
+	if (at)
+		*at = '\0';
+
+#ifdef CONFIG_PPC_DCR
+	/*
+	 * If it's a DCR based device, use 'd' for native DCRs
+	 * and 'D' for MMIO DCRs.
+	 */
+	reg = of_get_property(np, "dcr-reg", NULL);
+	if (reg) {
+#ifdef CONFIG_PPC_DCR_NATIVE
+		snprintf(dev->name, MAX_DRIVER_NAME, "d%x.%s", *reg, name);
+#else /* CONFIG_PPC_DCR_NATIVE */
+		u64 addr = of_translate_dcr_address(np, *reg, NULL);
+		if (addr != OF_BAD_ADDR) {
+			snprintf(dev->name, MAX_DRIVER_NAME, "D%llx.%s",
+				(unsigned long long)addr, name);
+			free(name);
+			return;
+		}
+#endif /* !CONFIG_PPC_DCR_NATIVE */
+	}
+#endif /* CONFIG_PPC_DCR */
+
+	/*
+	 * For MMIO, get the physical address
+	 */
+	reg = of_get_property(np, "reg", NULL);
+	if (reg) {
+		if (of_can_translate_address(np)) {
+			addr = of_translate_address(np, reg);
+		} else {
+			addrp = of_get_address(np, 0, NULL, NULL);
+			if (addrp)
+				addr = of_read_number(addrp, 1);
+			else
+				addr = OF_BAD_ADDR;
+		}
+		if (addr != OF_BAD_ADDR) {
+			snprintf(dev->name, MAX_DRIVER_NAME, "%llx.%s",
+				(unsigned long long)addr, name);
+			free(name);
+			return;
+		}
+	}
+
+	/*
+	 * No BusID, use the node name and add a globally incremented counter
+	 */
+	snprintf(dev->name, MAX_DRIVER_NAME, "%s.%d", name, bus_no_reg_magic++);
+	free(name);
+}
+
+/**
+ * of_platform_device_create - Alloc, initialize and register an of_device
+ * @np: pointer to node to create device for
+ * @parent: device model parent device.
+ *
+ * Returns pointer to created platform device, or NULL if a device was not
+ * registered. Unavailable devices will not get registered.
+ */
+static struct device_d *of_platform_device_create(struct device_node *np,
+						struct device_d *parent)
+{
+	struct device_d *dev;
+	struct resource *res, temp_res;
+	int i, ret, num_reg = 0;
+
+	if (!of_device_is_available(np))
+		return NULL;
+
+	dev = xzalloc(sizeof(*dev));
+
+	/* setup generic device info */
+	dev->id = DEVICE_ID_SINGLE;
+	dev->device_node = np;
+	dev->parent = parent;
+	of_device_make_bus_id(dev);
+
+	/* count the io resources */
+	if (of_can_translate_address(np))
+		while (of_address_to_resource(np, num_reg, &temp_res) == 0)
+			num_reg++;
+
+	/* Populate the resource table */
+	if (num_reg) {
+		res = xzalloc(sizeof(*res) * num_reg);
+
+		dev->num_resources = num_reg;
+		dev->resource = res;
+		for (i = 0; i < num_reg; i++, res++) {
+			ret = of_address_to_resource(np, i, res);
+			if (ret)
+				goto err_free;
+		}
+	}
+
+	debug("register device 0x%08x\n", (num_reg) ? dev->resource[0].start : (-1));
+
+	ret = platform_device_register(dev);
+	if (ret)
+		goto err_free;
+
+	return dev;
+
+err_free:
+	free(dev);
+	return NULL;
+}
+
+#ifdef CONFIG_ARM_AMBA
+static struct device_d *of_amba_device_create(struct device_node *np)
+{
+	struct amba_device *dev;
+	int ret;
+
+	debug("Creating amba device %s\n", np->full_name);
+
+	if (!of_device_is_available(np))
+		return NULL;
+
+	dev = xzalloc(sizeof(*dev));
+
+	/* setup generic device info */
+	dev->dev.id = DEVICE_ID_SINGLE;
+	dev->dev.device_node = np;
+	of_device_make_bus_id(&dev->dev);
+
+	ret = of_address_to_resource(np, 0, &dev->res);
+	if (ret)
+		goto amba_err_free;
+
+	dev->dev.resource = &dev->res;
+	dev->dev.num_resources = 1;
+
+	/* Allow the HW Peripheral ID to be overridden */
+	of_property_read_u32(np, "arm,primecell-periphid", &dev->periphid);
+
+	debug("register device 0x%08x\n", dev->dev.resource[0].start);
+
+	ret = amba_device_add(dev);
+	if (ret)
+		goto amba_err_free;
+
+	return &dev->dev;
+
+amba_err_free:
+	free(dev);
+	return NULL;
+}
+#else /* CONFIG_ARM_AMBA */
+static inline struct amba_device *of_amba_device_create(struct device_node *np)
+{
+	return NULL;
+}
+#endif /* CONFIG_ARM_AMBA */
+
+/**
+ * of_platform_bus_create() - Create a device for a node and its children.
+ * @bus: device node of the bus to instantiate
+ * @matches: match table for bus nodes
+ * @parent: parent for new device, or NULL for top level.
+ *
+ * Creates a platform_device for the provided device_node, and optionally
+ * recursively create devices for all the child nodes.
+ */
+static int of_platform_bus_create(struct device_node *bus,
+				const struct of_device_id *matches,
+				struct device_d *parent)
+{
+	struct device_node *child;
+	struct device_d *dev;
+	int rc = 0;
+
+	/* Make sure it has a compatible property */
+	if (!of_get_property(bus, "compatible", NULL)) {
+		pr_debug("%s() - skipping %s, no compatible prop\n",
+			__func__, bus->full_name);
+		return 0;
+	}
+
+	if (of_device_is_compatible(bus, "arm,primecell")) {
+		of_amba_device_create(bus);
+		return 0;
+	}
+
+	dev = of_platform_device_create(bus, parent);
+	if (!dev || !of_match_node(matches, bus))
+		return 0;
+
+	for_each_child_of_node(bus, child) {
+		pr_debug("   create child: %s\n", child->full_name);
+		rc = of_platform_bus_create(child, matches, dev);
+		if (rc)
+			break;
+	}
+	return rc;
+}
+
+/**
+ * of_platform_populate() - Populate platform_devices from device tree data
+ * @root: parent of the first level to probe or NULL for the root of the tree
+ * @matches: match table, NULL to use the default
+ * @lookup: auxdata table for matching id and platform_data with device nodes
+ * @parent: parent to hook devices from, NULL for toplevel
+ *
+ * This function walks the device tree given by @root node and creates devices
+ * from nodes.  It requires all device nodes to have a 'compatible' property,
+ * and it is suitable for creating devices which are children of the root
+ * node.
+ *
+ * Returns 0 on success, < 0 on failure.
+ */
+int of_platform_populate(struct device_node *root,
+			const struct of_device_id *matches,
+			struct device_d *parent)
+{
+	struct device_node *child;
+	int rc = 0;
+
+	if (!root)
+		root = of_find_node_by_path("/");
+	if (!root)
+		return -EINVAL;
+
+	for_each_child_of_node(root, child) {
+		rc = of_platform_bus_create(child, matches, parent);
+		if (rc)
+			break;
+	}
+
+	return rc;
+}
+EXPORT_SYMBOL_GPL(of_platform_populate);
diff --git a/include/of.h b/include/of.h
index 8cab797..f1f555f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -61,6 +61,7 @@ struct of_reserve_map *of_get_reserve_map(void);
 void of_clean_reserve_map(void);
 void fdt_add_reserve_map(void *fdt);
 
+struct device_d;
 struct driver_d;
 
 int of_fix_tree(struct device_node *);
@@ -221,6 +222,11 @@ extern int of_modalias_node(struct device_node *node, char *modalias, int len);
 extern struct device_node *of_get_root_node(void);
 extern int of_set_root_node(struct device_node *node);
 
+extern int of_platform_populate(struct device_node *root,
+				const struct of_device_id *matches,
+				struct device_d *parent);
+extern struct device_d *of_find_device_by_node(struct device_node *np);
+
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
@@ -547,6 +553,18 @@ static inline int of_modalias_node(struct device_node *node, char *modalias,
 {
 	return -ENOSYS;
 }
+
+static inline int of_platform_populate(struct device_node *root,
+				const struct of_device_id *matches,
+				struct device_d *parent)
+{
+	return -ENOSYS;
+}
+
+static inline struct device_d *of_find_device_by_node(struct device_node *np)
+{
+	return NULL;
+}
 #endif
 
 #define for_each_node_by_name(dn, name) \
-- 
1.7.2.5



From s.hauer at pengutronix.de  Tue Jun 25 05:20:43 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:43 +0200
Subject: [PATCH 03/12] ARM: build dtbs unconditionally
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-4-git-send-email-s.hauer@pengutronix.de>

The upcoming multi image support will need devicetree binary
blobs even when there is no builtin dtb. Kust descend into
arch/arm/dts unconditionally. arch/arm/dts/Makefile will act
as necessary depending on the options.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 32bdd65..3cdd670 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -328,7 +328,7 @@ endif
 common-y += $(BOARD) $(MACH)
 common-y += arch/arm/lib/ arch/arm/cpu/
 
-common-$(CONFIG_BUILTIN_DTB) += arch/arm/dts/
+common-y += arch/arm/dts/
 
 lds-y	:= arch/arm/lib/barebox.lds
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 05:20:48 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:48 +0200
Subject: [PATCH 08/12] ARM: i.MX27 pcm038: switch to multi image
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-9-git-send-email-s.hauer@pengutronix.de>

This also converts the Phytec phyCORE i.MX27 aka pcm038 to use
image compression. The image will be named

barebox-phytec-phycore-imx27.img

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/pcm038/lowlevel.c | 4 +++-
 arch/arm/mach-imx/Kconfig         | 1 +
 images/Makefile.imx               | 5 +++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boards/pcm038/lowlevel.c b/arch/arm/boards/pcm038/lowlevel.c
index 0ea2939..a3b2d13 100644
--- a/arch/arm/boards/pcm038/lowlevel.c
+++ b/arch/arm/boards/pcm038/lowlevel.c
@@ -33,11 +33,13 @@
 
 #define ESDCTL0_VAL (ESDCTL0_SDE | ESDCTL0_ROW13 | ESDCTL0_COL10)
 
-void __bare_init __naked barebox_arm_reset_vector(void)
+ENTRY_FUNCTION(start_imx27_pcm038)(void)
 {
 	uint32_t r;
 	int i;
 
+	__barebox_arm_head();
+
 	arm_cpu_lowlevel_init();
 
 	/* ahb lite ip interface */
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index d58682b..b80e885 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -330,6 +330,7 @@ config MACH_PCM038
 	select DRIVER_SPI_IMX
 	select MFD_MC13XXX
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select HAVE_PBL_MULTI_IMAGES
 	help
 	  Say Y here if you are using Phytec's phyCORE-i.MX27 (pcm038) equipped
 	  with a Freescale i.MX27 Processor
diff --git a/images/Makefile.imx b/images/Makefile.imx
index cd7b610..6334729 100644
--- a/images/Makefile.imx
+++ b/images/Makefile.imx
@@ -8,3 +8,8 @@ $(obj)/%.imximg: $(obj)/% FORCE
 	$(call if_changed,imx_image)
 
 board = $(srctree)/arch/$(ARCH)/boards
+
+# ----------------------- i.MX27 based boards ---------------------------
+pblx-$(CONFIG_MACH_PCM038) += start_imx27_pcm038
+FILE_barebox-phytec-phycore-imx27.img = start_imx27_pcm038.pblx
+image-$(CONFIG_MACH_PCM038) += barebox-phytec-phycore-imx27.img
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 05:20:41 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:41 +0200
Subject: [PATCH 01/12] ARM: split barebox_arm_head in two separate functions
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-2-git-send-email-s.hauer@pengutronix.de>

This adds a new function __barebox_arm_head() which defines an
the regular barebox ARM header, but which jumps to the end of
the function so that this can be embedded into another function.
barebox_arm_head() now just uses it and jumps to barebox_arm_reset_vector
just like it did before.

This makes it possible to define board specific entry points.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/include/asm/barebox-arm-head.h | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/arch/arm/include/asm/barebox-arm-head.h b/arch/arm/include/asm/barebox-arm-head.h
index 9a8cc87..af7164a 100644
--- a/arch/arm/include/asm/barebox-arm-head.h
+++ b/arch/arm/include/asm/barebox-arm-head.h
@@ -43,7 +43,7 @@ static inline void arm_cpu_lowlevel_init(void)
 #ifdef CONFIG_HAVE_MACH_ARM_HEAD
 #include <mach/barebox-arm-head.h>
 #else
-static inline void barebox_arm_head(void)
+static inline void __barebox_arm_head(void)
 {
 	__asm__ __volatile__ (
 #ifdef CONFIG_THUMB2_BAREBOX
@@ -52,12 +52,12 @@ static inline void barebox_arm_head(void)
 		"bx r9\n"
 		".thumb\n"
 		"1:\n"
-		"bl barebox_arm_reset_vector\n"
+		"bl 2f\n"
 		".rept 10\n"
 		"1: b 1b\n"
 		".endr\n"
 #else
-		"b barebox_arm_reset_vector\n"
+		"b 2f\n"
 		"1: b 1b\n"
 		"1: b 1b\n"
 		"1: b 1b\n"
@@ -74,6 +74,14 @@ static inline void barebox_arm_head(void)
 		".rept 8\n"
 		".word 0x55555555\n"
 		".endr\n"
+		"2:\n"
+	);
+}
+static inline void barebox_arm_head(void)
+{
+	__barebox_arm_head();
+	__asm__ __volatile__ (
+		"b barebox_arm_reset_vector\n"
 	);
 }
 #endif
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:39 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:39 +0200
Subject: [PATCH 1/9] OF: import address related functions from Linux OF API
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372152047-28134-2-git-send-email-sebastian.hesselbarth@gmail.com>

This imports drivers/of/address.c from Linux with some minor modifications.
of_translate_address is not yet enabled and PCI and ISA related bus translations
have not been imported. Also, a corresponding include header is created with
prototypes and non-OF function stubs.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/Makefile  |    2 +-
 drivers/of/address.c |  431 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/of_address.h |   64 ++++++++
 3 files changed, 496 insertions(+), 1 deletions(-)
 create mode 100644 drivers/of/address.c
 create mode 100644 include/of_address.h

diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index c81bbec..b8add0b 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,4 +1,4 @@
-obj-y += base.o fdt.o
+obj-y += address.o base.o fdt.o
 obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o
 obj-$(CONFIG_GPIOLIB) += gpio.o
 obj-y += partition.o
diff --git a/drivers/of/address.c b/drivers/of/address.c
new file mode 100644
index 0000000..3e5387a
--- /dev/null
+++ b/drivers/of/address.c
@@ -0,0 +1,431 @@
+/*
+ * address.c - address related devicetree functions
+ *
+ * Copyright (c) 2012 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ *
+ * based on Linux devicetree support
+ *
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+#include <common.h>
+#include <of.h>
+#include <of_address.h>
+
+/* Max address size we deal with */
+#define OF_MAX_ADDR_CELLS	4
+#define OF_CHECK_ADDR_COUNT(na)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS)
+#define OF_CHECK_COUNTS(na, ns)	(OF_CHECK_ADDR_COUNT(na) && (ns) > 0)
+
+/* Debug utility */
+#ifdef DEBUG
+static void of_dump_addr(const char *s, const __be32 *addr, int na)
+{
+	printk(KERN_DEBUG "%s", s);
+	while (na--)
+		printk(" %08x", be32_to_cpu(*(addr++)));
+	printk("\n");
+}
+#else
+static void of_dump_addr(const char *s, const __be32 *addr, int na) { }
+#endif
+
+/* Callbacks for bus specific translators */
+struct of_bus {
+	const char	*name;
+	const char	*addresses;
+	int		(*match)(struct device_node *parent);
+	void		(*count_cells)(struct device_node *child,
+				       int *addrc, int *sizec);
+	u64		(*map)(__be32 *addr, const __be32 *range,
+				int na, int ns, int pna);
+	int		(*translate)(__be32 *addr, u64 offset, int na);
+	unsigned int	(*get_flags)(const __be32 *addr);
+};
+
+/*
+ * Default translator (generic bus)
+ */
+
+static void of_bus_default_count_cells(struct device_node *dev,
+				       int *addrc, int *sizec)
+{
+	if (addrc)
+		*addrc = of_n_addr_cells(dev);
+	if (sizec)
+		*sizec = of_n_size_cells(dev);
+}
+
+static u64 of_bus_default_map(__be32 *addr, const __be32 *range,
+		int na, int ns, int pna)
+{
+	u64 cp, s, da;
+
+	cp = of_read_number(range, na);
+	s  = of_read_number(range + na + pna, ns);
+	da = of_read_number(addr, na);
+
+	pr_debug("OF: default map, cp=%llx, s=%llx, da=%llx\n",
+		 (unsigned long long)cp, (unsigned long long)s,
+		 (unsigned long long)da);
+
+	/*
+	 * If the number of address cells is larger than 2 we assume the
+	 * mapping doesn't specify a physical address. Rather, the address
+	 * specifies an identifier that must match exactly.
+	 */
+	if (na > 2 && memcmp(range, addr, na * 4) != 0)
+		return OF_BAD_ADDR;
+
+	if (da < cp || da >= (cp + s))
+		return OF_BAD_ADDR;
+	return da - cp;
+}
+
+static int of_bus_default_translate(__be32 *addr, u64 offset, int na)
+{
+	u64 a = of_read_number(addr, na);
+	memset(addr, 0, na * 4);
+	a += offset;
+	if (na > 1)
+		addr[na - 2] = cpu_to_be32(a >> 32);
+	addr[na - 1] = cpu_to_be32(a & 0xffffffffu);
+
+	return 0;
+}
+
+static unsigned int of_bus_default_get_flags(const __be32 *addr)
+{
+	return IORESOURCE_MEM;
+}
+
+/*
+ * Array of bus specific translators
+ */
+
+static struct of_bus of_busses[] = {
+	/* Default */
+	{
+		.name = "default",
+		.addresses = "reg",
+		.match = NULL,
+		.count_cells = of_bus_default_count_cells,
+		.map = of_bus_default_map,
+		.translate = of_bus_default_translate,
+		.get_flags = of_bus_default_get_flags,
+	},
+};
+
+static struct of_bus *of_match_bus(struct device_node *np)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(of_busses); i++)
+		if (!of_busses[i].match || of_busses[i].match(np))
+			return &of_busses[i];
+	BUG();
+	return NULL;
+}
+
+static int of_translate_one(struct device_node *parent, struct of_bus *bus,
+			    struct of_bus *pbus, __be32 *addr,
+			    int na, int ns, int pna, const char *rprop)
+{
+	const __be32 *ranges;
+	unsigned int rlen;
+	int rone;
+	u64 offset = OF_BAD_ADDR;
+
+	/* Normally, an absence of a "ranges" property means we are
+	 * crossing a non-translatable boundary, and thus the addresses
+	 * below the current not cannot be converted to CPU physical ones.
+	 * Unfortunately, while this is very clear in the spec, it's not
+	 * what Apple understood, and they do have things like /uni-n or
+	 * /ht nodes with no "ranges" property and a lot of perfectly
+	 * useable mapped devices below them. Thus we treat the absence of
+	 * "ranges" as equivalent to an empty "ranges" property which means
+	 * a 1:1 translation at that level. It's up to the caller not to try
+	 * to translate addresses that aren't supposed to be translated in
+	 * the first place. --BenH.
+	 *
+	 * As far as we know, this damage only exists on Apple machines, so
+	 * This code is only enabled on powerpc. --gcl
+	 */
+	ranges = of_get_property(parent, rprop, &rlen);
+#if !defined(CONFIG_PPC)
+	if (ranges == NULL) {
+		pr_err("OF: no ranges; cannot translate\n");
+		return 1;
+	}
+#endif /* !defined(CONFIG_PPC) */
+	if (ranges == NULL || rlen == 0) {
+		offset = of_read_number(addr, na);
+		memset(addr, 0, pna * 4);
+		pr_debug("OF: empty ranges; 1:1 translation\n");
+		goto finish;
+	}
+
+	pr_debug("OF: walking ranges...\n");
+
+	/* Now walk through the ranges */
+	rlen /= 4;
+	rone = na + pna + ns;
+	for (; rlen >= rone; rlen -= rone, ranges += rone) {
+		offset = bus->map(addr, ranges, na, ns, pna);
+		if (offset != OF_BAD_ADDR)
+			break;
+	}
+	if (offset == OF_BAD_ADDR) {
+		pr_debug("OF: not found !\n");
+		return 1;
+	}
+	memcpy(addr, ranges + na, 4 * pna);
+
+ finish:
+	of_dump_addr("OF: parent translation for:", addr, pna);
+	pr_debug("OF: with offset: %llx\n", (unsigned long long)offset);
+
+	/* Translate it into parent bus space */
+	return pbus->translate(addr, offset, pna);
+}
+
+/*
+ * Translate an address from the device-tree into a CPU physical address,
+ * this walks up the tree and applies the various bus mappings on the
+ * way.
+ *
+ * Note: We consider that crossing any level with #size-cells == 0 to mean
+ * that translation is impossible (that is we are not dealing with a value
+ * that can be mapped to a cpu physical address). This is not really specified
+ * that way, but this is traditionally the way IBM at least do things
+ */
+static u64 __of_translate_address(struct device_node *dev,
+				  const __be32 *in_addr, const char *rprop)
+{
+	struct device_node *parent = NULL;
+	struct of_bus *bus, *pbus;
+	__be32 addr[OF_MAX_ADDR_CELLS];
+	int na, ns, pna, pns;
+	u64 result = OF_BAD_ADDR;
+
+	pr_debug("OF: ** translation for device %s **\n", dev->full_name);
+
+	/* Get parent & match bus type */
+	parent = of_get_parent(dev);
+	if (parent == NULL)
+		return OF_BAD_ADDR;
+	bus = of_match_bus(parent);
+
+	/* Count address cells & copy address locally */
+	bus->count_cells(dev, &na, &ns);
+	if (!OF_CHECK_COUNTS(na, ns)) {
+		printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
+		       dev->full_name);
+		return OF_BAD_ADDR;
+	}
+	memcpy(addr, in_addr, na * 4);
+
+	pr_debug("OF: bus is %s (na=%d, ns=%d) on %s\n",
+	    bus->name, na, ns, parent->full_name);
+	of_dump_addr("OF: translating address:", addr, na);
+
+	/* Translate */
+	for (;;) {
+		/* Switch to parent bus */
+		dev = parent;
+		parent = of_get_parent(dev);
+
+		/* If root, we have finished */
+		if (parent == NULL) {
+			pr_debug("OF: reached root node\n");
+			result = of_read_number(addr, na);
+			break;
+		}
+
+		/* Get new parent bus and counts */
+		pbus = of_match_bus(parent);
+		pbus->count_cells(dev, &pna, &pns);
+		if (!OF_CHECK_COUNTS(pna, pns)) {
+			printk(KERN_ERR "prom_parse: Bad cell count for %s\n",
+			       dev->full_name);
+			break;
+		}
+
+		pr_debug("OF: parent bus is %s (na=%d, ns=%d) on %s\n",
+		    pbus->name, pna, pns, parent->full_name);
+
+		/* Apply bus translation */
+		if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop))
+			break;
+
+		/* Complete the move up one level */
+		na = pna;
+		ns = pns;
+		bus = pbus;
+
+		of_dump_addr("OF: one level translation:", addr, na);
+	}
+
+	return result;
+}
+
+u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr)
+{
+	return __of_translate_address(dev, in_addr, "dma-ranges");
+}
+EXPORT_SYMBOL(of_translate_dma_address);
+
+bool of_can_translate_address(struct device_node *dev)
+{
+	struct device_node *parent;
+	struct of_bus *bus;
+	int na, ns;
+
+	parent = of_get_parent(dev);
+	if (parent == NULL)
+		return false;
+
+	bus = of_match_bus(parent);
+	bus->count_cells(dev, &na, &ns);
+
+	return OF_CHECK_COUNTS(na, ns);
+}
+EXPORT_SYMBOL(of_can_translate_address);
+
+const __be32 *of_get_address(struct device_node *dev, int index, u64 *size,
+		    unsigned int *flags)
+{
+	const __be32 *prop;
+	unsigned int psize;
+	struct device_node *parent;
+	struct of_bus *bus;
+	int onesize, i, na, ns;
+
+	/* Get parent & match bus type */
+	parent = of_get_parent(dev);
+	if (parent == NULL)
+		return NULL;
+	bus = of_match_bus(parent);
+	bus->count_cells(dev, &na, &ns);
+	if (!OF_CHECK_ADDR_COUNT(na))
+		return NULL;
+
+	/* Get "reg" or "assigned-addresses" property */
+	prop = of_get_property(dev, bus->addresses, &psize);
+	if (prop == NULL)
+		return NULL;
+	psize /= 4;
+
+	onesize = na + ns;
+	for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
+		if (i == index) {
+			if (size)
+				*size = of_read_number(prop + na, ns);
+			if (flags)
+				*flags = bus->get_flags(prop);
+			return prop;
+		}
+	return NULL;
+}
+EXPORT_SYMBOL(of_get_address);
+
+static int __of_address_to_resource(struct device_node *dev,
+		const __be32 *addrp, u64 size, unsigned int flags,
+		const char *name, struct resource *r)
+{
+	u64 taddr;
+
+	if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
+		return -EINVAL;
+	taddr = of_translate_address(dev, addrp);
+	if (taddr == OF_BAD_ADDR)
+		return -EINVAL;
+	memset(r, 0, sizeof(struct resource));
+	if (flags & IORESOURCE_IO) {
+		unsigned long port;
+		port = pci_address_to_pio(taddr);
+		if (port == (unsigned long)-1)
+			return -EINVAL;
+		r->start = port;
+		r->end = port + size - 1;
+	} else {
+		r->start = taddr;
+		r->end = taddr + size - 1;
+	}
+	r->flags = flags;
+	r->name = name ? name : dev->full_name;
+
+	return 0;
+}
+
+/**
+ * of_address_to_resource - Translate device tree address and return as resource
+ *
+ * Note that if your address is a PIO address, the conversion will fail if
+ * the physical address can't be internally converted to an IO token with
+ * pci_address_to_pio(), that is because it's either called to early or it
+ * can't be matched to any host bridge IO space
+ */
+int of_address_to_resource(struct device_node *dev, int index,
+			   struct resource *r)
+{
+	const __be32	*addrp;
+	u64		size;
+	unsigned int	flags;
+	const char	*name = NULL;
+
+	addrp = of_get_address(dev, index, &size, &flags);
+	if (addrp == NULL)
+		return -EINVAL;
+
+	/* Get optional "reg-names" property to add a name to a resource */
+	of_property_read_string_index(dev, "reg-names",	index, &name);
+
+	return __of_address_to_resource(dev, addrp, size, flags, name, r);
+}
+EXPORT_SYMBOL_GPL(of_address_to_resource);
+
+struct device_node *of_find_matching_node_by_address(struct device_node *from,
+					const struct of_device_id *matches,
+					u64 base_address)
+{
+	struct device_node *dn = of_find_matching_node(from, matches);
+	struct resource res;
+
+	while (dn) {
+		if (of_address_to_resource(dn, 0, &res))
+			continue;
+		if (res.start == base_address)
+			return dn;
+		dn = of_find_matching_node(dn, matches);
+	}
+
+	return NULL;
+}
+
+/**
+ * of_iomap - Maps the memory mapped IO for a given device_node
+ * @device:	the device whose io range will be mapped
+ * @index:	index of the io range
+ *
+ * Returns a pointer to the mapped memory
+ */
+void __iomem *of_iomap(struct device_node *np, int index)
+{
+	struct resource res;
+
+	if (of_address_to_resource(np, index, &res))
+		return NULL;
+
+	return IOMEM(res.start);
+}
+EXPORT_SYMBOL(of_iomap);
diff --git a/include/of_address.h b/include/of_address.h
new file mode 100644
index 0000000..a82e2e5
--- /dev/null
+++ b/include/of_address.h
@@ -0,0 +1,64 @@
+#ifndef __OF_ADDRESS_H
+#define __OF_ADDRESS_H
+
+#include <common.h>
+#include <of.h>
+
+#ifndef pci_address_to_pio
+static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
+#endif
+
+#ifdef CONFIG_OFTREE
+
+extern u64 of_translate_dma_address(struct device_node *dev,
+				const __be32 *in_addr);
+extern bool of_can_translate_address(struct device_node *dev);
+extern const __be32 *of_get_address(struct device_node *dev, int index,
+				u64 *size, unsigned int *flags);
+extern int of_address_to_resource(struct device_node *dev, int index,
+				struct resource *r);
+extern struct device_node *of_find_matching_node_by_address(
+	struct device_node *from, const struct of_device_id *matches,
+	u64 base_address);
+extern void __iomem *of_iomap(struct device_node *np, int index);
+
+#else /* CONFIG_OFTREE */
+
+static inline u64 of_translate_dma_address(struct device_node *dev,
+				const __be32 *in_addr)
+{
+	return OF_BAD_ADDR;
+}
+
+static inline bool of_can_translate_address(struct device_node *dev)
+{
+	return false;
+}
+
+static inline const __be32 *of_get_address(struct device_node *dev, int index,
+				u64 *size, unsigned int *flags)
+{
+	return 0;
+}
+
+static inline int of_address_to_resource(struct device_node *dev, int index,
+				struct resource *r)
+{
+	return -ENOSYS;
+}
+
+static inline struct device_node *of_find_matching_node_by_address(
+	struct device_node *from, const struct of_device_id *matches,
+	u64 base_address)
+{
+	return NULL;
+}
+
+static inline void __iomem *of_iomap(struct device_node *np, int index)
+{
+	return NULL;
+}
+
+#endif /* CONFIG_OFTREE */
+
+#endif /* __OF_ADDRESS_H */
-- 
1.7.2.5



From s.hauer at pengutronix.de  Tue Jun 25 05:20:40 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:40 +0200
Subject: [PATCH] barebox multi image support
Message-ID: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>

This series adds support for generating multiple images from a single
barebox binary. This helps when for example boards come with different
SDRAM setups. Instead of having a config for each SDRAM setup we only
have a single configuration, but generate multiple images from it.

The basic idea behind this is using a PBL. As of now the PBL on ARM
has a single entrypoint: barebox_arm_entry. With multi image support
instead we have many entrypoints in the PBL. The correct one will
be chosen by the linker when generating a particular image. The PBLs
can also contain a devicetree which is passed to the regular barebox
image. This opens up the way to a true multi board barebox.

Additionally each PBL/barebox combination can be encapsulated into a
SoC specific image so that the different requirements for the boards
booting a image can be met.

This series adds the make infrastructure and converts a few boards
over to use it.

Sascha

----------------------------------------------------------------
Sascha Hauer (12):
      ARM: split barebox_arm_head in two separate functions
      ARM: pbl: move linker script to lib
      ARM: build dtbs unconditionally
      ARM: Add image end section
      imx-image: fix path to imx-image binary
      Add multi images support
      ARM: i.MX: Add multi images support Makefile
      ARM: i.MX27 pcm038: switch to multi image
      ARM: i.MX53 loco: Switch to imximage
      ARM: i.MX53 loco: Switch to multi image support
      ARM: dmo realq7: switch to multi image support
      ARM: i.MX51 babbage: switch to multi image support

 Makefile                                           |   8 ++
 arch/arm/Makefile                                  |   2 +-
 arch/arm/boards/dmo-mx6-realq7/lowlevel.c          |  12 +-
 arch/arm/boards/freescale-mx51-pdk/lowlevel.c      |  14 ++-
 arch/arm/boards/freescale-mx53-loco/Makefile       |   4 +-
 arch/arm/boards/freescale-mx53-loco/board.c        |   8 +-
 arch/arm/boards/freescale-mx53-loco/dcd-data.h     |  54 ---------
 .../boards/freescale-mx53-loco/flash-header.imxcfg |  54 +++++++++
 arch/arm/boards/freescale-mx53-loco/flash_header.c |  52 ---------
 arch/arm/boards/freescale-mx53-loco/lowlevel.c     |  14 ++-
 arch/arm/boards/pcm038/lowlevel.c                  |   4 +-
 arch/arm/cpu/Makefile                              |   4 +-
 arch/arm/cpu/start-images.c                        |  49 ++++++++
 arch/arm/cpu/uncompress.c                          | 108 ++++++++++++++++++
 arch/arm/dts/Makefile                              |   4 +
 arch/arm/include/asm/barebox-arm-head.h            |  14 ++-
 arch/arm/include/asm/barebox-arm.h                 |   4 +
 arch/arm/{pbl/zbarebox.lds.S => lib/pbl.lds.S}     |   9 +-
 arch/arm/lib/runtime-offset.S                      |   3 +
 arch/arm/mach-imx/Kconfig                          |   7 +-
 arch/arm/pbl/Makefile                              |   5 +-
 images/Makefile                                    | 124 +++++++++++++++++++++
 images/Makefile.imx                                |  36 ++++++
 include/asm-generic/sections.h                     |   1 +
 pbl/Kconfig                                        |  16 +++
 scripts/Makefile.lib                               |   2 +-
 26 files changed, 481 insertions(+), 131 deletions(-)
 delete mode 100644 arch/arm/boards/freescale-mx53-loco/dcd-data.h
 create mode 100644 arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/freescale-mx53-loco/flash_header.c
 create mode 100644 arch/arm/cpu/start-images.c
 create mode 100644 arch/arm/cpu/uncompress.c
 rename arch/arm/{pbl/zbarebox.lds.S => lib/pbl.lds.S} (93%)
 create mode 100644 images/Makefile
 create mode 100644 images/Makefile.imx


From s.hauer at pengutronix.de  Tue Jun 25 05:20:52 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:52 +0200
Subject: [PATCH 12/12] ARM: i.MX51 babbage: switch to multi image support
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-13-git-send-email-s.hauer@pengutronix.de>

The image will be named:

barebox-freescale-imx51-babbage.img

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx51-pdk/lowlevel.c | 14 ++++++++++++--
 arch/arm/dts/Makefile                         |  1 +
 arch/arm/mach-imx/Kconfig                     |  2 +-
 images/Makefile.imx                           |  7 +++++++
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boards/freescale-mx51-pdk/lowlevel.c b/arch/arm/boards/freescale-mx51-pdk/lowlevel.c
index 3e6a0ee..8c1acb4 100644
--- a/arch/arm/boards/freescale-mx51-pdk/lowlevel.c
+++ b/arch/arm/boards/freescale-mx51-pdk/lowlevel.c
@@ -1,9 +1,19 @@
 #include <common.h>
 #include <mach/esdctl.h>
 #include <asm/barebox-arm-head.h>
+#include <asm/barebox-arm.h>
 
-void __naked barebox_arm_reset_vector(void)
+extern char __dtb_imx51_babbage_start[];
+
+ENTRY_FUNCTION(start_imx51_babbage)(void)
 {
+	uint32_t fdt;
+
+	__barebox_arm_head();
+
 	arm_cpu_lowlevel_init();
-	imx51_barebox_entry(0);
+
+	fdt = (uint32_t)__dtb_imx51_babbage_start - get_runtime_offset();
+
+	imx51_barebox_entry(fdt);
 }
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 2fdd2e7..df0e360 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -8,6 +8,7 @@ dtb-$(CONFIG_ARCH_IMX6) += imx6q-dmo-realq7.dtb \
 BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME))
 obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB).dtb.o
 
+pbl-$(CONFIG_MACH_FREESCALE_MX51_PDK) += imx51-babbage.dtb.o
 pbl-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += imx53-qsb.dtb.o
 pbl-$(CONFIG_MACH_REALQ7) += imx6q-dmo-realq7.dtb.o
 
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 9927a3d..a57e276 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -425,7 +425,7 @@ choice
 
 config MACH_FREESCALE_MX51_PDK
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
-	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
+	select HAVE_PBL_MULTI_IMAGES
 	bool "Freescale i.MX51 PDK"
 
 config MACH_EUKREA_CPUIMX51SD
diff --git a/images/Makefile.imx b/images/Makefile.imx
index 11c4160..72e8cde 100644
--- a/images/Makefile.imx
+++ b/images/Makefile.imx
@@ -14,6 +14,13 @@ pblx-$(CONFIG_MACH_PCM038) += start_imx27_pcm038
 FILE_barebox-phytec-phycore-imx27.img = start_imx27_pcm038.pblx
 image-$(CONFIG_MACH_PCM038) += barebox-phytec-phycore-imx27.img
 
+# ----------------------- i.MX51 based boards ---------------------------
+pblx-$(CONFIG_MACH_FREESCALE_MX51_PDK) += start_imx51_babbage
+CFG_start_imx51_babbage.pblx.imximg = $(board)/freescale-mx51-pdk/flash-header.imxcfg
+imximage-$(CONFIG_MACH_FREESCALE_MX51_PDK) += start_imx51_babbage.pblx.imximg
+FILE_barebox-freescale-imx51-babbage.img = start_imx51_babbage.pblx.imximg
+image-$(CONFIG_MACH_FREESCALE_MX51_PDK) += barebox-freescale-imx51-babbage.img
+
 # ----------------------- i.MX53 based boards ---------------------------
 pblx-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += start_imx53_loco
 CFG_start_imx53_loco.pblx.imximg = $(board)/freescale-mx53-loco/flash-header.imxcfg
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:41 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:41 +0200
Subject: [PATCH 3/9] OF: base: move OF_ROOT_NODE_ defines to local OF code
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372152047-28134-4-git-send-email-sebastian.hesselbarth@gmail.com>

OF_ROOT_NODE_* defines should not be used outside of base.c. Move them
to drivers/of/base.c to ensure they will not be used elsewhere.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |    3 +++
 include/of.h      |    3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 2778230..429f924 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -64,6 +64,9 @@ struct device_node *root_node;
 
 struct device_node *of_aliases;
 
+#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
+#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
+
 int of_n_addr_cells(struct device_node *np)
 {
 	const __be32 *ip;
diff --git a/include/of.h b/include/of.h
index e091326..8cab797 100644
--- a/include/of.h
+++ b/include/of.h
@@ -101,9 +101,6 @@ int of_get_named_gpio(struct device_node *np,
 void of_print_property(const void *data, int len);
 void of_print_cmdline(struct device_node *root);
 
-#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
-#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
-
 void of_print_nodes(struct device_node *node, int indent);
 int of_probe(void);
 int of_parse_dtb(struct fdt_header *fdt);
-- 
1.7.2.5



From s.hauer at pengutronix.de  Tue Jun 25 05:20:42 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:42 +0200
Subject: [PATCH 02/12] ARM: pbl: move linker script to lib
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-3-git-send-email-s.hauer@pengutronix.de>

Since the pbl linker script can be reused by the upcoming multi image
build process move it to a common place. Also remove ENTRY() from the
linker script and instead add the -e option to the linker. This makes
the entrypoint configurable.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/lib/pbl.lds.S      | 91 ++++++++++++++++++++++++++++++++++++++++++++
 arch/arm/pbl/Makefile       |  5 ++-
 arch/arm/pbl/zbarebox.lds.S | 92 ---------------------------------------------
 3 files changed, 95 insertions(+), 93 deletions(-)
 create mode 100644 arch/arm/lib/pbl.lds.S
 delete mode 100644 arch/arm/pbl/zbarebox.lds.S

diff --git a/arch/arm/lib/pbl.lds.S b/arch/arm/lib/pbl.lds.S
new file mode 100644
index 0000000..d3ec2f8
--- /dev/null
+++ b/arch/arm/lib/pbl.lds.S
@@ -0,0 +1,91 @@
+/*
+ * (C) Copyright 2012 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ *
+ * 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 <sizes.h>
+#include <asm-generic/barebox.lds.h>
+#include <asm-generic/memory_layout.h>
+
+OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
+OUTPUT_ARCH(arm)
+SECTIONS
+{
+#ifdef CONFIG_PBL_RELOCATABLE
+	. = 0x0;
+#else
+	. = TEXT_BASE - SZ_2M;
+#endif
+
+	PRE_IMAGE
+
+	. = ALIGN(4);
+	.text      :
+	{
+		_stext = .;
+		_text = .;
+		*(.text_head_entry*)
+		__bare_init_start = .;
+		*(.text_bare_init*)
+		__bare_init_end = .;
+		*(.text*)
+	}
+
+	/* Discard unwind if enable in barebox */
+	/DISCARD/ : { *(.ARM.ex*) }
+
+	BAREBOX_BARE_INIT_SIZE
+
+	. = ALIGN(4);
+	.rodata : { *(.rodata*) }
+
+	_etext = .;			/* End of text and rodata section */
+
+	. = ALIGN(4);
+	.data : { *(.data*) }
+
+	.rel.dyn : {
+		__rel_dyn_start = .;
+		*(.rel*)
+		__rel_dyn_end = .;
+	}
+
+	.dynsym : {
+		__dynsym_start = .;
+		*(.dynsym)
+		__dynsym_end = .;
+	}
+
+	. = ALIGN(4);
+	__bss_start = .;
+	.bss : { *(.bss*) }
+	__bss_stop = .;
+	_end = .;
+
+	. = ALIGN(4);
+	__piggydata_start = .;
+	.piggydata : {
+		*(.piggydata)
+	}
+	__piggydata_end = .;
+
+	_barebox_image_size = __piggydata_end - (TEXT_BASE - SZ_2M);
+	_barebox_pbl_size = __bss_start - (TEXT_BASE - SZ_2M);
+}
diff --git a/arch/arm/pbl/Makefile b/arch/arm/pbl/Makefile
index 3f50f77..8923a70 100644
--- a/arch/arm/pbl/Makefile
+++ b/arch/arm/pbl/Makefile
@@ -29,9 +29,12 @@ endif
 zbarebox-common := $(barebox-pbl-common) $(obj)/$(piggy_o)
 zbarebox-lds := $(obj)/zbarebox.lds
 
+$(zbarebox-lds): $(obj)/../lib/pbl.lds.S FORCE
+	$(call if_changed_dep,cpp_lds_S)
+
 quiet_cmd_zbarebox__ ?= LD      $@
       cmd_zbarebox__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_zbarebox) -o $@ \
-      -T $(zbarebox-lds)                                           \
+      -e pbl_start -T $(zbarebox-lds)                              \
       --start-group $(zbarebox-common) --end-group                 \
       $(filter-out $(zbarebox-lds) $(zbarebox-common) FORCE ,$^)
 
diff --git a/arch/arm/pbl/zbarebox.lds.S b/arch/arm/pbl/zbarebox.lds.S
deleted file mode 100644
index 6b23bbe..0000000
--- a/arch/arm/pbl/zbarebox.lds.S
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * (C) Copyright 2012 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
- *
- * 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 <sizes.h>
-#include <asm-generic/barebox.lds.h>
-#include <asm-generic/memory_layout.h>
-
-OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
-OUTPUT_ARCH(arm)
-ENTRY(pbl_start)
-SECTIONS
-{
-#ifdef CONFIG_PBL_RELOCATABLE
-	. = 0x0;
-#else
-	. = TEXT_BASE - SZ_2M;
-#endif
-
-	PRE_IMAGE
-
-	. = ALIGN(4);
-	.text      :
-	{
-		_stext = .;
-		_text = .;
-		*(.text_head_entry*)
-		__bare_init_start = .;
-		*(.text_bare_init*)
-		__bare_init_end = .;
-		*(.text*)
-	}
-
-	/* Discard unwind if enable in barebox */
-	/DISCARD/ : { *(.ARM.ex*) }
-
-	BAREBOX_BARE_INIT_SIZE
-
-	. = ALIGN(4);
-	.rodata : { *(.rodata*) }
-
-	_etext = .;			/* End of text and rodata section */
-
-	. = ALIGN(4);
-	.data : { *(.data*) }
-
-	.rel.dyn : {
-		__rel_dyn_start = .;
-		*(.rel*)
-		__rel_dyn_end = .;
-	}
-
-	.dynsym : {
-		__dynsym_start = .;
-		*(.dynsym)
-		__dynsym_end = .;
-	}
-
-	. = ALIGN(4);
-	__bss_start = .;
-	.bss : { *(.bss*) }
-	__bss_stop = .;
-	_end = .;
-
-	. = ALIGN(4);
-	__piggydata_start = .;
-	.piggydata : {
-		*(.piggydata)
-	}
-	__piggydata_end = .;
-
-	_barebox_image_size = __piggydata_end - (TEXT_BASE - SZ_2M);
-	_barebox_pbl_size = __bss_start - (TEXT_BASE - SZ_2M);
-}
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 05:20:46 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:46 +0200
Subject: [PATCH 06/12] Add multi images support
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-7-git-send-email-s.hauer@pengutronix.de>

This adds the make infrastructure to build multiple SoC or
board specific images from a single barebox binary.

The basic idea is that we no longer have a single pbl, but instead
multiple pbls, one per image if necessary. Each pbl is defined
by its entry function so that each pbl can do exactly what a given
board needs. Additionally the pbls together with a self extracting
barebox binary can be encapsulated in specific image formats.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 Makefile                           |   8 +++
 arch/arm/cpu/Makefile              |   4 +-
 arch/arm/cpu/start-images.c        |  49 +++++++++++++++
 arch/arm/cpu/uncompress.c          | 108 ++++++++++++++++++++++++++++++++
 arch/arm/include/asm/barebox-arm.h |   4 ++
 arch/arm/mach-imx/Kconfig          |   1 +
 images/Makefile                    | 122 +++++++++++++++++++++++++++++++++++++
 pbl/Kconfig                        |  16 +++++
 8 files changed, 311 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/cpu/start-images.c
 create mode 100644 arch/arm/cpu/uncompress.c
 create mode 100644 images/Makefile

diff --git a/Makefile b/Makefile
index 32c46fd..d82e795 100644
--- a/Makefile
+++ b/Makefile
@@ -481,7 +481,14 @@ export KBUILD_BINARY ?= barebox.bin
 barebox-flash-image: $(KBUILD_IMAGE) FORCE
 	$(call if_changed,ln)
 
+images images/%.s: barebox.bin FORCE
+	$(Q)$(MAKE) $(build)=images $@
+
+ifdef CONFIG_PBL_MULTI_IMAGES
+all: $(KBUILD_DTBS) barebox.bin images
+else
 all: barebox-flash-image $(KBUILD_DTBS)
+endif
 
 common-$(CONFIG_PBL_IMAGE)	+= pbl/
 
@@ -987,6 +994,7 @@ clean-dirs      := $(addprefix _clean_,$(srctree) $(barebox-alldirs))
 
 PHONY += $(clean-dirs) clean archclean
 $(clean-dirs):
+	$(Q)$(MAKE) $(clean)=images
 	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
 
 clean: archclean $(clean-dirs)
diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
index c442b35..d99577b 100644
--- a/arch/arm/cpu/Makefile
+++ b/arch/arm/cpu/Makefile
@@ -21,7 +21,9 @@ obj-$(CONFIG_CPU_32v7) += cache-armv7.o
 pbl-$(CONFIG_CPU_32v7) += cache-armv7.o
 obj-$(CONFIG_CACHE_L2X0) += cache-l2x0.o
 
-pbl-y += start-pbl.o setupc.o
+pbl-y += setupc.o
+pbl-$(CONFIG_PBL_SINGLE_IMAGE) += start-pbl.o
+pbl-$(CONFIG_PBL_MULTI_IMAGES) += start-images.o uncompress.o
 
 obj-y += common.o
 pbl-y += common.o
diff --git a/arch/arm/cpu/start-images.c b/arch/arm/cpu/start-images.c
new file mode 100644
index 0000000..d48d245
--- /dev/null
+++ b/arch/arm/cpu/start-images.c
@@ -0,0 +1,49 @@
+/*
+ * start-pbl.c
+ *
+ * Copyright (c) 2010-2012 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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 <init.h>
+#include <sizes.h>
+#include <pbl.h>
+#include <asm/barebox-arm.h>
+#include <asm/barebox-arm-head.h>
+#include <asm-generic/memory_layout.h>
+#include <asm/sections.h>
+#include <asm/pgtable.h>
+#include <debug_ll.h>
+
+void __naked __noreturn barebox_arm_entry(uint32_t membase, uint32_t memsize,
+		uint32_t boarddata)
+{
+	unsigned long barebox_base;
+	void __noreturn (*barebox)(uint32_t, uint32_t, uint32_t);
+
+	barebox_base = ld_var(__image_end) - get_runtime_offset() + 4;
+
+	if (IS_ENABLED(CONFIG_THUMB2_BAREBOX))
+		barebox = (void *)(barebox_base + 1);
+	else
+		barebox = (void *)barebox_base;
+
+	barebox(membase, memsize, boarddata);
+}
diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
new file mode 100644
index 0000000..b401f8e
--- /dev/null
+++ b/arch/arm/cpu/uncompress.c
@@ -0,0 +1,108 @@
+/*
+ * uncompress.c - uncompressor code for self extracing pbl image
+ *
+ * Copyright (c) 2010-2013 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ * Copyright (c) 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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 <init.h>
+#include <sizes.h>
+#include <pbl.h>
+#include <asm/barebox-arm.h>
+#include <asm/barebox-arm-head.h>
+#include <asm-generic/memory_layout.h>
+#include <asm/sections.h>
+#include <asm/pgtable.h>
+#include <asm/cache.h>
+
+#include <debug_ll.h>
+
+#include "mmu-early.h"
+
+unsigned long free_mem_ptr;
+unsigned long free_mem_end_ptr;
+
+static int __attribute__((__used__))
+	__attribute__((__section__(".image_end")))
+	__image_end_dummy = 0xdeadbeef;
+
+static void noinline uncompress(uint32_t membase,
+		uint32_t memsize, uint32_t boarddata)
+{
+	uint32_t offset;
+	uint32_t pg_len;
+	void __noreturn (*barebox)(uint32_t, uint32_t, uint32_t);
+	uint32_t endmem = membase + memsize;
+	unsigned long barebox_base;
+	uint32_t *ptr;
+	void *pg_start;
+
+	endmem -= STACK_SIZE; /* stack */
+
+	if (IS_ENABLED(CONFIG_PBL_RELOCATABLE))
+		relocate_to_current_adr();
+
+	/* Get offset between linked address and runtime address */
+	offset = get_runtime_offset();
+
+	if (IS_ENABLED(CONFIG_RELOCATABLE))
+		barebox_base = arm_barebox_image_place(membase + memsize);
+	else
+		barebox_base = TEXT_BASE;
+
+	setup_c();
+
+	if (IS_ENABLED(CONFIG_MMU_EARLY)) {
+		endmem &= ~0x3fff;
+		endmem -= SZ_16K; /* ttb */
+		mmu_early_enable(membase, memsize, endmem);
+	}
+
+	endmem -= SZ_128K; /* early malloc */
+	free_mem_ptr = endmem;
+	free_mem_end_ptr = free_mem_ptr + SZ_128K;
+
+	ptr = (void *)__image_end;
+	pg_start = ptr + 1;
+	pg_len = *(ptr);
+
+	pbl_barebox_uncompress((void*)barebox_base, pg_start, pg_len);
+
+	arm_early_mmu_cache_flush();
+	flush_icache();
+
+	if (IS_ENABLED(CONFIG_THUMB2_BAREBOX))
+		barebox = (void *)(barebox_base + 1);
+	else
+		barebox = (void *)barebox_base;
+
+	barebox(membase, memsize, boarddata);
+}
+
+/*
+ * Generic second stage pbl uncompressor entry
+ */
+ENTRY_FUNCTION(start_uncompress)(uint32_t membase, uint32_t memsize,
+		uint32_t boarddata)
+{
+	arm_setup_stack(membase + memsize - 16);
+
+	uncompress(membase, memsize, boarddata);
+}
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index cd8decf..226e000 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -77,4 +77,8 @@ static inline unsigned long arm_barebox_image_place(unsigned long endmem)
 	return endmem;
 }
 
+#define ENTRY_FUNCTION(name)  \
+	void __naked __section(.text_head_entry_##name) \
+		name
+
 #endif	/* _BAREBOX_ARM_H_ */
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 644c05e..d58682b 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -67,6 +67,7 @@ config BOARDINFO
 choice
 	prompt "Select boot mode"
 	depends on !ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
+	depends on !HAVE_PBL_MULTI_IMAGES
 	help
 	  i.MX processors support two different boot modes. With the internal
 	  boot mode the boot medium contains a header describing the image to
diff --git a/images/Makefile b/images/Makefile
new file mode 100644
index 0000000..fe1f77d
--- /dev/null
+++ b/images/Makefile
@@ -0,0 +1,122 @@
+#
+# barebox image generation Makefile
+#
+# This Makefile generates multiple images from a common barebox image
+# and different pbl (pre bootloader) images. Optionally the result is
+# encapsulated in SoC (or SoC boot type) specific image formats.
+#
+# The basic idea here is that we generate a single barebox main binary. This
+# is compressed and prepended with a self extractor, generated as barebox.x.
+# barebox.x is then prepended with different board specific pbls. The pbls
+# are generally named after their entrypoints. So a pcm038 specific pbl will
+# generate the following files:
+#
+# start_imx27_pcm038.pbl - The ELF file, linked with the entrypoint start_imx27_pcm038
+# start_imx27_pcm038.pblb - The raw binary of the above.
+# start_imx27_pcm038.pblx - The pblb appended with barebox.x
+# start_imx27_pcm038.pbl.map - The linker map file
+# start_imx27_pcm038.pbl.s - the disassembled ELF, generated with:
+#                            make images/start_imx27_pcm038.pbl.s
+#
+# Example Makefile snippets for the i.MX51 babbage board (for readability in opposite
+# order):
+#
+## image-$(CONFIG_MACH_FREESCALE_MX51_PDK) += barebox-imx51-babbage.img
+#
+# For CONFIG_MACH_FREESCALE_MX51_PDK build barebox-imx51-babbage.img
+#
+## FILE_barebox-imx51-babbage.img = start_imx51_babbage.pblx.imximg
+#
+# barebox-imx51-babbage.img should be generated (copied) from
+# start_imx51_babbage.pblx.imximg. This copy process is only done so that we
+# can generate images with a sane name. So what we really need for this
+# board is a i.MX specific image, a .imximg
+#
+## imximage-$(CONFIG_MACH_FREESCALE_MX51_PDK) += start_imx51_babbage.pblx.imximg
+## CFG_start_imx51_babbage.pblx.imximg = $(board)/freescale-mx51-pdk/flash-header.imxcfg
+#
+# The .imximg can be generated from a .pblx using a rule specified in Makefile.imx.
+# The configfile needed for this image is specified with CFG_<filename> = <configfile>
+#
+## pblx-$(CONFIG_MACH_FREESCALE_MX51_PDK) += start_imx51_babbage
+#
+# For this image we need a pblx (self extracting barebox binary) with
+# start_imx51_babbage as entrypoint. start_imx51_babbage will be used
+# both as entrypoint and as filename
+#
+
+quiet_cmd_objcopy_bin = OBJCOPYB $@
+      cmd_objcopy_bin = $(OBJCOPY) -O binary $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
+
+pbl-lds := $(obj)/pbl.lds
+extra-y += $(pbl-lds)
+
+$(pbl-lds): $(obj)/../arch/$(ARCH)/lib/pbl.lds.S FORCE
+	$(call if_changed_dep,cpp_lds_S)
+
+quiet_cmd_elf__ ?= LD      $@
+      cmd_elf__ ?= $(LD) $(LDFLAGS) -static --gc-sections -pie		\
+		-e $(2) -Map $@.map $(LDFLAGS_$(@F)) -o $@		\
+		-T $(pbl-lds)						\
+		--start-group $(barebox-pbl-common) --end-group
+
+PBL_CPPFLAGS	+= -fdata-sections -ffunction-sections
+
+$(obj)/%.pbl: $(pbl-lds) $(barebox-pbl-common) FORCE
+	$(call if_changed,elf__,$(*F))
+
+$(obj)/%.pblb: $(obj)/%.pbl FORCE
+	$(call if_changed,objcopy_bin,$(*F))
+
+quiet_cmd_pblx ?= PBLX    $@
+      cmd_pblx ?= cat $(obj)/$(patsubst %.pblx,%.pblb,$(2)) > $@; \
+		  $(call size_append, $(obj)/barebox.x) >> $@; \
+		  cat $(obj)/barebox.x >> $@
+
+$(obj)/%.pblx: $(obj)/%.pblb $(obj)/barebox.x FORCE
+	$(call if_changed,pblx,$(@F))
+
+$(obj)/%.s: $(obj)/% FORCE
+	$(call if_changed,disasm)
+
+suffix_$(CONFIG_IMAGE_COMPRESSION_GZIP) = gzip
+suffix_$(CONFIG_IMAGE_COMPRESSION_LZO)  = lzo
+suffix_$(CONFIG_IMAGE_COMPRESSION_NONE) = shipped
+
+# barebox.z - compressed barebox binary
+# ----------------------------------------------------------------
+$(obj)/barebox.z: $(obj)/../barebox.bin FORCE
+	$(call if_changed,$(suffix_y))
+
+quiet_cmd_selfextract = COMP    $@
+      cmd_selfextract = cat $(obj)/start_uncompress.pblb > $@; \
+			$(call size_append, $<) >> $@; \
+			cat $< >> $@
+
+pblx-y += start_uncompress
+# barebox.x - self extracting barebox binary
+# ----------------------------------------------------------------
+$(obj)/barebox.x: $(obj)/barebox.z $(obj)/start_uncompress.pblb FORCE
+	$(call if_changed,selfextract)
+
+# %.img - create a copy from another file
+# ----------------------------------------------------------------
+.SECONDEXPANSION:
+$(obj)/%.img: $(obj)/$$(FILE_$$(@F))
+	$(Q)if [ -z $(FILE_$(@F)) ]; then echo "FILE_$(@F) empty!"; false; fi
+	$(call if_changed,shipped)
+
+targets += $(image-y) pbl.lds barebox.x barebox.z
+targets += $(patsubst %,%.pblx,$(pblx-y))
+targets += $(patsubst %,%.pblb,$(pblx-y))
+targets += $(patsubst %,%.pbl,$(pblx-y))
+targets += $(patsubst %,%.s,$(pblx-y))
+targets += $(imximage-y)
+
+SECONDARY: $(addprefix $(obj)/,$(targets))
+
+images: $(addprefix $(obj)/, $(image-y)) FORCE
+	@echo "images built:\n" $(patsubst %,%\\n,$(image-y))
+
+clean-files := *.pbl *.pblb *.pblx *.map start_*.imximg *.img barebox.z
+clean-files += pbl.lds
diff --git a/pbl/Kconfig b/pbl/Kconfig
index 5c7f62e..a37c976 100644
--- a/pbl/Kconfig
+++ b/pbl/Kconfig
@@ -1,6 +1,9 @@
 config HAVE_PBL_IMAGE
 	bool
 
+config HAVE_PBL_MULTI_IMAGES
+	bool
+
 config HAVE_IMAGE_COMPRESSION
 	bool
 
@@ -8,6 +11,19 @@ config PBL_IMAGE
 	bool "Pre-Bootloader image"
 	depends on HAVE_PBL_IMAGE
 
+config PBL_MULTI_IMAGES
+	bool
+	select PBL_IMAGE
+	select PBL_RELOCATABLE
+	depends on HAVE_PBL_MULTI_IMAGES
+	default y
+
+config PBL_SINGLE_IMAGE
+	bool
+	depends on PBL_IMAGE
+	depends on !HAVE_PBL_MULTI_IMAGES
+	default y
+
 config PBL_FORCE_PIGGYDATA_COPY
 	bool
 	help
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 05:20:51 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:51 +0200
Subject: [PATCH 11/12] ARM: dmo realq7: switch to multi image support
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-12-git-send-email-s.hauer@pengutronix.de>

The image will be named after the official name of this board:

barebox-datamodul-edm-qmx6.img

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/dmo-mx6-realq7/lowlevel.c | 12 ++++++++++--
 arch/arm/dts/Makefile                     |  1 +
 arch/arm/mach-imx/Kconfig                 |  2 +-
 images/Makefile.imx                       |  7 +++++++
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boards/dmo-mx6-realq7/lowlevel.c b/arch/arm/boards/dmo-mx6-realq7/lowlevel.c
index ebcf76f..240116d 100644
--- a/arch/arm/boards/dmo-mx6-realq7/lowlevel.c
+++ b/arch/arm/boards/dmo-mx6-realq7/lowlevel.c
@@ -138,8 +138,14 @@ static void sdram_init(void)
 	writel(0x00000001, 0x021e8080);
 }
 
-void __naked barebox_arm_reset_vector(void)
+extern char __dtb_imx6q_dmo_realq7_start[];
+
+ENTRY_FUNCTION(start_imx6_realq7)(void)
 {
+	uint32_t fdt;
+
+	__barebox_arm_head();
+
 	arm_cpu_lowlevel_init();
 
 	arm_setup_stack(0x00940000 - 8);
@@ -151,5 +157,7 @@ void __naked barebox_arm_reset_vector(void)
 		mmdc_do_dqs_calibration();
 	}
 
-	barebox_arm_entry(0x10000000, SZ_2G, 0);
+	fdt = (uint32_t)__dtb_imx6q_dmo_realq7_start - get_runtime_offset();
+
+	barebox_arm_entry(0x10000000, SZ_2G, fdt);
 }
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 19a1985..2fdd2e7 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -9,6 +9,7 @@ BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME))
 obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB).dtb.o
 
 pbl-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += imx53-qsb.dtb.o
+pbl-$(CONFIG_MACH_REALQ7) += imx6q-dmo-realq7.dtb.o
 
 .SECONDARY: $(obj)/$(BUILTIN_DTB).dtb.S
 
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 6560798..9927a3d 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -530,8 +530,8 @@ config MACH_SABRESD
 
 config MACH_REALQ7
 	bool "DataModul i.MX6Q Real Qseven Board"
-	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select HAVE_PBL_MULTI_IMAGES
 
 endchoice
 
diff --git a/images/Makefile.imx b/images/Makefile.imx
index 3a5b5f1..11c4160 100644
--- a/images/Makefile.imx
+++ b/images/Makefile.imx
@@ -20,3 +20,10 @@ CFG_start_imx53_loco.pblx.imximg = $(board)/freescale-mx53-loco/flash-header.imx
 imximage-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += start_imx53_loco.pblx.imximg
 FILE_barebox-freescale-imx53-loco.img = start_imx53_loco.pblx.imximg
 image-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += barebox-freescale-imx53-loco.img
+
+# ----------------------- i.MX6 based boards ---------------------------
+pblx-$(CONFIG_MACH_REALQ7) += start_imx6_realq7
+CFG_start_imx6_realq7.pblx.imximg = $(board)/dmo-mx6-realq7/flash-header.imxcfg
+imximage-$(CONFIG_MACH_REALQ7) += start_imx6_realq7.pblx.imximg
+FILE_barebox-datamodul-edm-qmx6.img = start_imx6_realq7.pblx.imximg
+image-$(CONFIG_MACH_REALQ7) += barebox-datamodul-edm-qmx6.img
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:40 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:40 +0200
Subject: [PATCH 2/9] OF: convert of_translate_address to new API
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372152047-28134-3-git-send-email-sebastian.hesselbarth@gmail.com>

This converts existing of_translate_address to recently added API. In
contrast to existing behavior, the new function honors ranges properties
properly. It now allows reg properties to be set as offset with respect
to the correspoding parent node.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/address.c |    6 ++++++
 drivers/of/base.c    |   26 +-------------------------
 include/of.h         |    2 --
 include/of_address.h |    8 ++++++++
 4 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 3e5387a..4cacdb1 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -278,6 +278,12 @@ static u64 __of_translate_address(struct device_node *dev,
 	return result;
 }
 
+u64 of_translate_address(struct device_node *dev, const __be32 *in_addr)
+{
+	return __of_translate_address(dev, in_addr, "ranges");
+}
+EXPORT_SYMBOL(of_translate_address);
+
 u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr)
 {
 	return __of_translate_address(dev, in_addr, "dma-ranges");
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 63ff647..2778230 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -19,6 +19,7 @@
  */
 #include <common.h>
 #include <of.h>
+#include <of_address.h>
 #include <errno.h>
 #include <malloc.h>
 #include <init.h>
@@ -242,31 +243,6 @@ const char *of_alias_get(struct device_node *np)
 }
 EXPORT_SYMBOL_GPL(of_alias_get);
 
-u64 of_translate_address(struct device_node *node, const __be32 *in_addr)
-{
-	struct property *p;
-	u64 addr = be32_to_cpu(*in_addr);
-
-	while (1) {
-		int na, nc;
-
-		if (!node->parent)
-			return addr;
-
-		node = node->parent;
-		p = of_find_property(node, "ranges", NULL);
-		if (!p && node->parent)
-			return OF_BAD_ADDR;
-		of_bus_count_cells(node, &na, &nc);
-		if (na != 1 || nc != 1) {
-			printk("%s: #size-cells != 1 or #address-cells != 1 "
-					"currently not supported\n", node->name);
-			return OF_BAD_ADDR;
-		}
-	}
-}
-EXPORT_SYMBOL(of_translate_address);
-
 /*
  * of_find_node_by_phandle - Find a node given a phandle
  * @handle:    phandle of the node to find
diff --git a/include/of.h b/include/of.h
index b392ca9..e091326 100644
--- a/include/of.h
+++ b/include/of.h
@@ -101,8 +101,6 @@ int of_get_named_gpio(struct device_node *np,
 void of_print_property(const void *data, int len);
 void of_print_cmdline(struct device_node *root);
 
-u64 of_translate_address(struct device_node *node, const __be32 *in_addr);
-
 #define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
 #define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
 
diff --git a/include/of_address.h b/include/of_address.h
index a82e2e5..9022ab7 100644
--- a/include/of_address.h
+++ b/include/of_address.h
@@ -10,6 +10,8 @@ static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
 
 #ifdef CONFIG_OFTREE
 
+extern u64 of_translate_address(struct device_node *dev,
+				const __be32 *in_addr);
 extern u64 of_translate_dma_address(struct device_node *dev,
 				const __be32 *in_addr);
 extern bool of_can_translate_address(struct device_node *dev);
@@ -24,6 +26,12 @@ extern void __iomem *of_iomap(struct device_node *np, int index);
 
 #else /* CONFIG_OFTREE */
 
+static inline u64 of_translate_address(struct device_node *dev,
+				const __be32 *in_addr)
+{
+	return OF_BAD_ADDR;
+}
+
 static inline u64 of_translate_dma_address(struct device_node *dev,
 				const __be32 *in_addr)
 {
-- 
1.7.2.5



From s.hauer at pengutronix.de  Tue Jun 25 05:20:49 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:49 +0200
Subject: [PATCH 09/12] ARM: i.MX53 loco: Switch to imximage
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-10-git-send-email-s.hauer@pengutronix.de>

Use the imximage tool to generate an imximage instead of the linker
based process.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx53-loco/Makefile       |  4 +-
 arch/arm/boards/freescale-mx53-loco/board.c        |  8 ++--
 arch/arm/boards/freescale-mx53-loco/dcd-data.h     | 54 ----------------------
 .../boards/freescale-mx53-loco/flash-header.imxcfg | 54 ++++++++++++++++++++++
 arch/arm/boards/freescale-mx53-loco/flash_header.c | 52 ---------------------
 arch/arm/mach-imx/Kconfig                          |  1 +
 6 files changed, 60 insertions(+), 113 deletions(-)
 delete mode 100644 arch/arm/boards/freescale-mx53-loco/dcd-data.h
 create mode 100644 arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg
 delete mode 100644 arch/arm/boards/freescale-mx53-loco/flash_header.c

diff --git a/arch/arm/boards/freescale-mx53-loco/Makefile b/arch/arm/boards/freescale-mx53-loco/Makefile
index d44f697..f1baae2 100644
--- a/arch/arm/boards/freescale-mx53-loco/Makefile
+++ b/arch/arm/boards/freescale-mx53-loco/Makefile
@@ -1,3 +1,3 @@
-obj-y += board.o
-lwl-y += flash_header.o
+obj-y += board.o flash-header.o
+extra-y += flash-header.S flash-header.dcd
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c
index 2f51128..0e3955f 100644
--- a/arch/arm/boards/freescale-mx53-loco/board.c
+++ b/arch/arm/boards/freescale-mx53-loco/board.c
@@ -75,9 +75,7 @@ static void loco_fec_reset(void)
 
 #define MX53_LOCO_USB_PWREN		IMX_GPIO_NR(7, 8)
 
-#define DCD_NAME static struct imx_dcd_v2_entry dcd_entry
-
-#include "dcd-data.h"
+extern char flash_header_start[], flash_header_end[];
 
 static int loco_late_init(void)
 {
@@ -116,8 +114,8 @@ static int loco_late_init(void)
 	armlinux_set_architecture(MACH_TYPE_MX53_LOCO);
 
 	imx53_bbu_internal_mmc_register_handler("mmc", "/dev/mmc0",
-		BBU_HANDLER_FLAG_DEFAULT, dcd_entry, sizeof(dcd_entry), 0);
-
+		BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_start,
+		flash_header_end - flash_header_start, 0);
 
 	return 0;
 }
diff --git a/arch/arm/boards/freescale-mx53-loco/dcd-data.h b/arch/arm/boards/freescale-mx53-loco/dcd-data.h
deleted file mode 100644
index 9f95fb4..0000000
--- a/arch/arm/boards/freescale-mx53-loco/dcd-data.h
+++ /dev/null
@@ -1,54 +0,0 @@
-
-DCD_NAME[] = {
-	{ .addr = cpu_to_be32(0x53fa8554), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8558), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8560), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8564), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8568), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8570), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8574), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8578), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa857c), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8580), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8584), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8588), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8590), .val = cpu_to_be32(0x00300040), },
-	{ .addr = cpu_to_be32(0x53fa8594), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa86f0), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa86f4), .val = cpu_to_be32(0x00000000), },
-	{ .addr = cpu_to_be32(0x53fa86fc), .val = cpu_to_be32(0x00000000), },
-	{ .addr = cpu_to_be32(0x53fa8714), .val = cpu_to_be32(0x00000000), },
-	{ .addr = cpu_to_be32(0x53fa8718), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa871c), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8720), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa8724), .val = cpu_to_be32(0x04000000), },
-	{ .addr = cpu_to_be32(0x53fa8728), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x53fa872c), .val = cpu_to_be32(0x00300000), },
-	{ .addr = cpu_to_be32(0x63fd9088), .val = cpu_to_be32(0x35343535), },
-	{ .addr = cpu_to_be32(0x63fd9090), .val = cpu_to_be32(0x4d444c44), },
-	{ .addr = cpu_to_be32(0x63fd907c), .val = cpu_to_be32(0x01370138), },
-	{ .addr = cpu_to_be32(0x63fd9080), .val = cpu_to_be32(0x013b013c), },
-	{ .addr = cpu_to_be32(0x63fd9018), .val = cpu_to_be32(0x00011740), },
-	{ .addr = cpu_to_be32(0x63fd9000), .val = cpu_to_be32(0xc3190000), },
-	{ .addr = cpu_to_be32(0x63fd900c), .val = cpu_to_be32(0x9f5152e3), },
-	{ .addr = cpu_to_be32(0x63fd9010), .val = cpu_to_be32(0xb68e8a63), },
-	{ .addr = cpu_to_be32(0x63fd9014), .val = cpu_to_be32(0x01ff00db), },
-	{ .addr = cpu_to_be32(0x63fd902c), .val = cpu_to_be32(0x000026d2), },
-	{ .addr = cpu_to_be32(0x63fd9030), .val = cpu_to_be32(0x009f0e21), },
-	{ .addr = cpu_to_be32(0x63fd9008), .val = cpu_to_be32(0x12273030), },
-	{ .addr = cpu_to_be32(0x63fd9004), .val = cpu_to_be32(0x0002002d), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00008032), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00008033), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00028031), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x052080b0), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x04008040), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x0000803a), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x0000803b), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00028039), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x05208138), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x04008048), },
-	{ .addr = cpu_to_be32(0x63fd9020), .val = cpu_to_be32(0x00005800), },
-	{ .addr = cpu_to_be32(0x63fd9040), .val = cpu_to_be32(0x04b80003), },
-	{ .addr = cpu_to_be32(0x63fd9058), .val = cpu_to_be32(0x00022227), },
-	{ .addr = cpu_to_be32(0x63fd901c), .val = cpu_to_be32(0x00000000), },
-};
diff --git a/arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg b/arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg
new file mode 100644
index 0000000..95bcd19
--- /dev/null
+++ b/arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg
@@ -0,0 +1,54 @@
+loadaddr 0x70000000
+soc imx53
+dcdofs 0x400
+wm 32 0x53fa8554 0x00300000
+wm 32 0x53fa8558 0x00300040
+wm 32 0x53fa8560 0x00300000
+wm 32 0x53fa8564 0x00300040
+wm 32 0x53fa8568 0x00300040
+wm 32 0x53fa8570 0x00300000
+wm 32 0x53fa8574 0x00300000
+wm 32 0x53fa8578 0x00300000
+wm 32 0x53fa857c 0x00300040
+wm 32 0x53fa8580 0x00300040
+wm 32 0x53fa8584 0x00300000
+wm 32 0x53fa8588 0x00300000
+wm 32 0x53fa8590 0x00300040
+wm 32 0x53fa8594 0x00300000
+wm 32 0x53fa86f0 0x00300000
+wm 32 0x53fa86f4 0x00000000
+wm 32 0x53fa86fc 0x00000000
+wm 32 0x53fa8714 0x00000000
+wm 32 0x53fa8718 0x00300000
+wm 32 0x53fa871c 0x00300000
+wm 32 0x53fa8720 0x00300000
+wm 32 0x53fa8724 0x04000000
+wm 32 0x53fa8728 0x00300000
+wm 32 0x53fa872c 0x00300000
+wm 32 0x63fd9088 0x35343535
+wm 32 0x63fd9090 0x4d444c44
+wm 32 0x63fd907c 0x01370138
+wm 32 0x63fd9080 0x013b013c
+wm 32 0x63fd9018 0x00011740
+wm 32 0x63fd9000 0xc3190000
+wm 32 0x63fd900c 0x9f5152e3
+wm 32 0x63fd9010 0xb68e8a63
+wm 32 0x63fd9014 0x01ff00db
+wm 32 0x63fd902c 0x000026d2
+wm 32 0x63fd9030 0x009f0e21
+wm 32 0x63fd9008 0x12273030
+wm 32 0x63fd9004 0x0002002d
+wm 32 0x63fd901c 0x00008032
+wm 32 0x63fd901c 0x00008033
+wm 32 0x63fd901c 0x00028031
+wm 32 0x63fd901c 0x052080b0
+wm 32 0x63fd901c 0x04008040
+wm 32 0x63fd901c 0x0000803a
+wm 32 0x63fd901c 0x0000803b
+wm 32 0x63fd901c 0x00028039
+wm 32 0x63fd901c 0x05208138
+wm 32 0x63fd901c 0x04008048
+wm 32 0x63fd9020 0x00005800
+wm 32 0x63fd9040 0x04b80003
+wm 32 0x63fd9058 0x00022227
+wm 32 0x63fd901c 0x00000000
diff --git a/arch/arm/boards/freescale-mx53-loco/flash_header.c b/arch/arm/boards/freescale-mx53-loco/flash_header.c
deleted file mode 100644
index dc1162b..0000000
--- a/arch/arm/boards/freescale-mx53-loco/flash_header.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2011 Marc Kleine-Budde <mkl at pengutronix.de>
- *
- * 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.
- *
- */
-
-#include <common.h>
-#include <asm/byteorder.h>
-#include <mach/imx-flash-header.h>
-#include <asm/barebox-arm-head.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-#define DCD_NAME struct imx_dcd_v2_entry __dcd_entry_section dcd_entry
-
-#include "dcd-data.h"
-
-#define APP_DEST	0x70000000
-
-struct imx_flash_header_v2 __flash_header_section flash_header = {
-	.header.tag		= IVT_HEADER_TAG,
-	.header.length		= cpu_to_be16(32),
-	.header.version		= IVT_VERSION,
-
-	.entry			= APP_DEST + 0x1000,
-	.dcd_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header_v2, dcd),
-	.boot_data_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header_v2, boot_data),
-	.self			= APP_DEST + 0x400,
-
-	.boot_data.start	= APP_DEST,
-	.boot_data.size		= DCD_BAREBOX_SIZE,
-
-	.dcd.header.tag		= DCD_HEADER_TAG,
-	.dcd.header.length	= cpu_to_be16(sizeof(struct imx_dcd) + sizeof(dcd_entry)),
-	.dcd.header.version	= DCD_VERSION,
-
-	.dcd.command.tag	= DCD_COMMAND_WRITE_TAG,
-	.dcd.command.length	= cpu_to_be16(sizeof(struct imx_dcd_command) + sizeof(dcd_entry)),
-	.dcd.command.param	= DCD_COMMAND_WRITE_PARAM,
-};
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index b80e885..4f9ef3e 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -476,6 +476,7 @@ choice
 
 config MACH_FREESCALE_MX53_LOCO
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
 	bool "Freescale i.MX53 LOCO"
 
 config MACH_FREESCALE_MX53_SMD
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 05:26:49 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:26:49 +0200
Subject: [PATCH] barebox multi image support
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <20130625092649.GG32299@pengutronix.de>

On Tue, Jun 25, 2013 at 11:20:40AM +0200, Sascha Hauer wrote:
> This series adds support for generating multiple images from a single
> barebox binary. This helps when for example boards come with different
> SDRAM setups. Instead of having a config for each SDRAM setup we only
> have a single configuration, but generate multiple images from it.
> 
> The basic idea behind this is using a PBL. As of now the PBL on ARM
> has a single entrypoint: barebox_arm_entry.

s/barebox_arm_entry/barebox_arm_reset_vector/

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Jun 25 05:20:50 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 11:20:50 +0200
Subject: [PATCH 10/12] ARM: i.MX53 loco: Switch to multi image support
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372152052-5463-11-git-send-email-s.hauer@pengutronix.de>

This converts the Freescale i.MX53 loco aka qsb board to
multi image. The image will be named:

barebox-freescale-imx53-loco.img

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx53-loco/lowlevel.c | 14 ++++++++++++--
 arch/arm/dts/Makefile                          |  2 ++
 arch/arm/mach-imx/Kconfig                      |  2 +-
 images/Makefile.imx                            |  7 +++++++
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boards/freescale-mx53-loco/lowlevel.c b/arch/arm/boards/freescale-mx53-loco/lowlevel.c
index 60c28f7..d920524 100644
--- a/arch/arm/boards/freescale-mx53-loco/lowlevel.c
+++ b/arch/arm/boards/freescale-mx53-loco/lowlevel.c
@@ -1,9 +1,19 @@
 #include <common.h>
 #include <mach/esdctl.h>
 #include <asm/barebox-arm-head.h>
+#include <asm/barebox-arm.h>
 
-void __naked barebox_arm_reset_vector(void)
+extern char __dtb_imx53_qsb_start[];
+
+ENTRY_FUNCTION(start_imx53_loco)(void)
 {
+	uint32_t fdt;
+
+	__barebox_arm_head();
+
 	arm_cpu_lowlevel_init();
-	imx53_barebox_entry(0);
+
+	fdt = (uint32_t)__dtb_imx53_qsb_start - get_runtime_offset();
+
+	imx53_barebox_entry(fdt);
 }
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index b271618..19a1985 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -8,6 +8,8 @@ dtb-$(CONFIG_ARCH_IMX6) += imx6q-dmo-realq7.dtb \
 BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME))
 obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB).dtb.o
 
+pbl-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += imx53-qsb.dtb.o
+
 .SECONDARY: $(obj)/$(BUILTIN_DTB).dtb.S
 
 targets += dtbs
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 4f9ef3e..6560798 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -476,7 +476,7 @@ choice
 
 config MACH_FREESCALE_MX53_LOCO
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
-	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
+	select HAVE_PBL_MULTI_IMAGES
 	bool "Freescale i.MX53 LOCO"
 
 config MACH_FREESCALE_MX53_SMD
diff --git a/images/Makefile.imx b/images/Makefile.imx
index 6334729..3a5b5f1 100644
--- a/images/Makefile.imx
+++ b/images/Makefile.imx
@@ -13,3 +13,10 @@ board = $(srctree)/arch/$(ARCH)/boards
 pblx-$(CONFIG_MACH_PCM038) += start_imx27_pcm038
 FILE_barebox-phytec-phycore-imx27.img = start_imx27_pcm038.pblx
 image-$(CONFIG_MACH_PCM038) += barebox-phytec-phycore-imx27.img
+
+# ----------------------- i.MX53 based boards ---------------------------
+pblx-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += start_imx53_loco
+CFG_start_imx53_loco.pblx.imximg = $(board)/freescale-mx53-loco/flash-header.imxcfg
+imximage-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += start_imx53_loco.pblx.imximg
+FILE_barebox-freescale-imx53-loco.img = start_imx53_loco.pblx.imximg
+image-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += barebox-freescale-imx53-loco.img
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:46 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:46 +0200
Subject: [PATCH 8/9] OF: base: convert of_add_memory to OF API
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372152047-28134-9-git-send-email-sebastian.hesselbarth@gmail.com>

Convert of_add_memory parsing to make use of of_address_to_resource
instead of parsing memory ranges itself. This makes some functions
dead code which are also removed.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   57 +++++++---------------------------------------------
 1 files changed, 8 insertions(+), 49 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 0244281..6fc962d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -99,21 +99,6 @@ int of_n_size_cells(struct device_node *np)
 }
 EXPORT_SYMBOL(of_n_size_cells);
 
-static void of_bus_default_count_cells(struct device_node *dev,
-				       int *addrc, int *sizec)
-{
-	if (addrc)
-		*addrc = of_n_addr_cells(dev);
-	if (sizec)
-		*sizec = of_n_size_cells(dev);
-}
-
-static void of_bus_count_cells(struct device_node *dev,
-			int *addrc, int *sizec)
-{
-	of_bus_default_count_cells(dev, addrc, sizec);
-}
-
 struct property *of_find_property(const struct device_node *np,
 				  const char *name, int *lenp)
 {
@@ -1543,48 +1528,22 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
 	return 0;
 }
 
-static u64 dt_mem_next_cell(int s, const __be32 **cellp)
-{
-	const __be32 *p = *cellp;
-
-	*cellp = p + s;
-	return of_read_number(p, s);
-}
-
 int of_add_memory(struct device_node *node, bool dump)
 {
-	int na, nc;
-	const __be32 *reg, *endp;
-	int len, r = 0, ret;
 	const char *device_type;
+	struct resource res;
+	int n = 0, ret;
 
 	ret = of_property_read_string(node, "device_type", &device_type);
-	if (ret)
+	if (ret || of_node_cmp(device_type, "memory"))
 		return -ENXIO;
 
-	if (of_node_cmp(device_type, "memory"))
-		return -ENXIO;
-
-	of_bus_count_cells(node, &na, &nc);
-
-	reg = of_get_property(node, "reg", &len);
-	if (!reg)
-		return -EINVAL;
-
-	endp = reg + (len / sizeof(__be32));
-
-	while ((endp - reg) >= (na + nc)) {
-		u64 base, size;
-
-		base = dt_mem_next_cell(na, &reg);
-		size = dt_mem_next_cell(nc, &reg);
-
-		if (size == 0)
+	while (of_address_to_resource(node, n, &res)) {
+		if (!resource_size(&res))
 			continue;
-
-		of_add_memory_bank(node, dump, r, base, size);
-
-		r++;
+		of_add_memory_bank(node, dump, n,
+				res.start, resource_size(&res));
+		n++;
 	}
 
 	return 0;
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Tue Jun 25 05:20:45 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 11:20:45 +0200
Subject: [PATCH 7/9] OF: remove device and resource pointer from struct
 device_node
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372152047-28134-8-git-send-email-sebastian.hesselbarth@gmail.com>

struct device_node has its own resources and a pointer to associated
device_d. With recent platform related OF code, we can convert the
only user of it and remove those pointers from struct device_node.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |    8 ++++----
 drivers/of/gpio.c |    6 +++++-
 include/of.h      |    3 ---
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 9d63127..0244281 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1594,6 +1594,7 @@ void of_free(struct device_node *node)
 {
 	struct device_node *n, *nt;
 	struct property *p, *pt;
+	struct device_d *dev;
 
 	if (!node)
 		return;
@@ -1610,10 +1611,9 @@ void of_free(struct device_node *node)
 		list_del(&node->list);
 	}
 
-	if (node->device)
-		node->device->device_node = NULL;
-	else
-		free(node->resource);
+	dev = of_find_device_by_node(node);
+	if (dev)
+		dev->device_node = NULL;
 
 	free(node->name);
 	free(node->full_name);
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 41e91ec..7f6d99c 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -10,6 +10,10 @@ int of_get_named_gpio(struct device_node *np,
 {
 	int ret;
 	struct of_phandle_args out_args;
+	struct device_d *dev = of_find_device_by_node(np);
+
+	if (!dev)
+		return -EINVAL;
 
 	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
 					index, &out_args);
@@ -18,7 +22,7 @@ int of_get_named_gpio(struct device_node *np,
 		return -EINVAL;
 	}
 
-	ret = gpio_get_num(out_args.np->device, out_args.args[0]);
+	ret = gpio_get_num(dev, out_args.args[0]);
 	if (ret < 0)
 		return ret;
 
diff --git a/include/of.h b/include/of.h
index f1f555f..0298189 100644
--- a/include/of.h
+++ b/include/of.h
@@ -30,9 +30,6 @@ struct device_node {
 	struct list_head children;
 	struct list_head parent_list;
 	struct list_head list;
-	struct resource *resource;
-	int num_resource;
-	struct device_d *device;
 	struct list_head phandles;
 	phandle phandle;
 };
-- 
1.7.2.5



From renaud.barbier at ge.com  Tue Jun 25 06:45:31 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 11:45:31 +0100
Subject: [PATCH 2/8] ppc asm: DDR headers
In-Reply-To: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372157137-7602-3-git-send-email-renaud.barbier@ge.com>

Definitions and structures have been added to record DIMM parameters
and configure memory options.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/include/asm/fsl_ddr_dimm_params.h |   60 +++++++++++++
 arch/ppc/include/asm/fsl_ddr_sdram.h       |  131 +++++++++++++++++++++++++++-
 2 files changed, 187 insertions(+), 4 deletions(-)
 create mode 100644 arch/ppc/include/asm/fsl_ddr_dimm_params.h

diff --git a/arch/ppc/include/asm/fsl_ddr_dimm_params.h b/arch/ppc/include/asm/fsl_ddr_dimm_params.h
new file mode 100644
index 0000000..73c239b
--- /dev/null
+++ b/arch/ppc/include/asm/fsl_ddr_dimm_params.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#ifndef DDR2_DIMM_PARAMS_H
+#define DDR2_DIMM_PARAMS_H
+
+#define EDC_ECC		2
+
+/* Parameters for a DDR2 dimm computed from the SPD */
+struct dimm_params_s {
+	char mpart[19];
+	uint32_t n_ranks;
+	uint64_t rank_density;
+	uint64_t capacity;
+	uint32_t data_width;
+	uint32_t primary_sdram_width;
+	uint32_t ec_sdram_width;
+	uint32_t registered_dimm;
+	uint32_t n_row_addr;
+	uint32_t n_col_addr;
+	uint32_t edc_config;		/* 0 = none, 1 = parity, 2 = ECC */
+	uint32_t n_banks_per_sdram_device;
+	uint32_t burst_lengths_bitmask;	/* BL=4 bit 2, BL=8 = bit 3 */
+	uint32_t row_density;
+	uint64_t base_address;
+	/* SDRAM clock periods */
+	uint32_t tCKmin_X_ps;
+	uint32_t tCKmin_X_minus_1_ps;
+	uint32_t tCKmin_X_minus_2_ps;
+	uint32_t tCKmax_ps;
+	/* SPD-defined CAS latencies */
+	uint32_t caslat_X;
+	uint32_t caslat_X_minus_1;
+	uint32_t caslat_X_minus_2;
+	uint32_t caslat_lowest_derated;
+	/* basic timing parameters */
+	uint32_t tRCD_ps;
+	uint32_t tRP_ps;
+	uint32_t tRAS_ps;
+	uint32_t tWR_ps;	/* maximum = 63750 ps */
+	uint32_t tWTR_ps;	/* maximum = 63750 ps */
+	uint32_t tRFC_ps;	/* max = 255 ns + 256 ns + .75 ns = 511750 ps */
+	uint32_t tRRD_ps;	/* maximum = 63750 ps */
+	uint32_t tRC_ps;	/* maximum = 254 ns + .75 ns = 254750 ps */
+	uint32_t refresh_rate_ps;
+	uint32_t tIS_ps;	/* byte 32, spd->ca_setup */
+	uint32_t tIH_ps;	/* byte 33, spd->ca_hold */
+	uint32_t tDS_ps;	/* byte 34, spd->data_setup */
+	uint32_t tDH_ps;	/* byte 35, spd->data_hold */
+	uint32_t tRTP_ps;	/* byte 38, spd->trtp */
+	uint32_t tDQSQ_max_ps;	/* byte 44, spd->tdqsq */
+	uint32_t tQHS_ps;	/* byte 45, spd->tqhs */
+};
+
+#endif
diff --git a/arch/ppc/include/asm/fsl_ddr_sdram.h b/arch/ppc/include/asm/fsl_ddr_sdram.h
index ef793c9..444bcbc 100644
--- a/arch/ppc/include/asm/fsl_ddr_sdram.h
+++ b/arch/ppc/include/asm/fsl_ddr_sdram.h
@@ -10,9 +10,40 @@
 #ifndef FSL_DDR_MEMCTL_H
 #define FSL_DDR_MEMCTL_H
 
-/*
- * DDR_SDRAM_CFG - DDR SDRAM Control Configuration
- */
+#include <ddr_spd.h>
+
+/* Basic DDR Technology. */
+#define SDRAM_TYPE_DDR1    2
+#define SDRAM_TYPE_DDR2    3
+#define SDRAM_TYPE_LPDDR1  6
+#define SDRAM_TYPE_DDR3    7
+
+#define DDR_BL4	4
+#define DDR_BL8	8
+
+#define DDR2_RTT_OFF		0
+#define DDR2_RTT_75_OHM		1
+#define DDR2_RTT_150_OHM	2
+#define DDR2_RTT_50_OHM		3
+
+#if defined(CONFIG_FSL_DDR2)
+#define FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR	(3)
+typedef struct ddr2_spd_eeprom_s generic_spd_eeprom_t;
+#define FSL_SDRAM_TYPE	SDRAM_TYPE_DDR2
+#endif
+
+#define FSL_DDR_ODT_NEVER		0x0
+#define FSL_DDR_ODT_CS			0x1
+#define FSL_DDR_ODT_ALL_OTHER_CS	0x2
+#define FSL_DDR_ODT_OTHER_DIMM		0x3
+#define FSL_DDR_ODT_ALL			0x4
+#define FSL_DDR_ODT_SAME_DIMM		0x5
+#define FSL_DDR_ODT_CS_AND_OTHER_DIMM	0x6
+#define FSL_DDR_ODT_OTHER_CS_ONSAMEDIMM	0x7
+
+#define SDRAM_CS_CONFIG_EN		0x80000000
+
+/* DDR_SDRAM_CFG - DDR SDRAM Control Configuration */
 #define SDRAM_CFG_MEM_EN		0x80000000
 #define SDRAM_CFG_SREN			0x40000000
 #define SDRAM_CFG_ECC_EN		0x20000000
@@ -23,11 +54,103 @@
 #define SDRAM_CFG_SDRAM_TYPE_SHIFT	24
 #define SDRAM_CFG_DYN_PWR		0x00200000
 #define SDRAM_CFG_32_BE			0x00080000
+#define SDRAM_CFG_16_BE			0x00100000
 #define SDRAM_CFG_8_BE			0x00040000
 #define SDRAM_CFG_NCAP			0x00020000
 #define SDRAM_CFG_2T_EN			0x00008000
 #define SDRAM_CFG_BI			0x00000001
 
-extern phys_size_t fixed_sdram(void);
+#define SDRAM_CFG2_D_INIT		0x00000010
+#define SDRAM_CFG2_ODT_CFG_MASK		0x00600000
+#define SDRAM_CFG2_ODT_NEVER		0
+#define SDRAM_CFG2_ODT_ONLY_WRITE	1
+#define SDRAM_CFG2_ODT_ONLY_READ	2
+#define SDRAM_CFG2_ODT_ALWAYS		3
+
+#define MAX_CHIP_SELECTS_PER_CTRL	4
+#define MAX_DIMM_SLOTS_PER_CTLR		4
+
+/*
+ * Memory controller characteristics and I2C parameters to
+ * read the SPD data.
+ */
+struct ddr_board_info_s {
+	uint32_t fsl_ddr_ver;
+	void __iomem *ddr_base;
+	uint32_t cs_per_ctrl;
+	uint32_t dimm_slots_per_ctrl;
+	uint32_t i2c_bus;
+	uint32_t i2c_slave;
+	uint32_t i2c_speed;
+	void __iomem *i2c_base;
+	uint8_t *spd_i2c_addr;
+};
 
+/*
+ * Generalized parameters for memory controller configuration,
+ * might be a little specific to the FSL memory controller
+ */
+struct memctl_options_s {
+	struct ddr_board_info_s *board_info;
+	uint32_t sdram_type;
+	/*
+	 * Memory organization parameters
+	 *
+	 * if DIMM is present in the system
+	 * where DIMMs are with respect to chip select
+	 * where chip selects are with respect to memory boundaries
+	 */
+	uint32_t registered_dimm_en;
+	/* Options local to a Chip Select */
+	struct cs_local_opts_s {
+		uint32_t auto_precharge;
+		uint32_t odt_rd_cfg;
+		uint32_t odt_wr_cfg;
+		uint32_t odt_rtt_norm;
+		uint32_t odt_rtt_wr;
+	} cs_local_opts[MAX_CHIP_SELECTS_PER_CTRL];
+	/* DLL reset disable */
+	uint32_t dll_rst_dis;
+	/* Operational mode parameters */
+	uint32_t ECC_mode;
+	uint32_t ECC_init_using_memctl;
+	uint32_t data_init;
+	/* Use DQS? maybe only with DDR2? */
+	uint32_t DQS_config;
+	uint32_t self_refresh_in_sleep;
+	uint32_t dynamic_power;
+	uint32_t data_bus_width;
+	uint32_t burst_length;
+	/* Global Timing Parameters */
+	uint32_t cas_latency_override;
+	uint32_t cas_latency_override_value;
+	uint32_t use_derated_caslat;
+	uint32_t additive_latency_override;
+	uint32_t additive_latency_override_value;
+	uint32_t clk_adjust;
+	uint32_t cpo_override;
+	uint32_t write_data_delay;
+	uint32_t half_strength_driver_enable;
+	uint32_t twoT_en;
+	uint32_t bstopre;
+	uint32_t tCKE_clock_pulse_width_ps;
+	uint32_t tFAW_window_four_activates_ps;
+	/* Rtt impedance */
+	uint32_t rtt_override;
+	uint32_t rtt_override_value;
+	/* Automatic self refresh */
+	uint32_t auto_self_refresh_en;
+	/* read-to-write turnaround */
+	uint32_t trwt_override;
+	uint32_t trwt;
+	/* Powerdon timings. */
+	uint32_t txp;
+	uint32_t taxpd;
+	uint32_t txard;
+	/* Load mode cycle time */
+	uint32_t tmrd;
+};
+
+extern phys_size_t fsl_ddr_sdram(void);
+extern phys_size_t fixed_sdram(void);
 #endif
-- 
1.7.1



From renaud.barbier at ge.com  Tue Jun 25 06:45:29 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 11:45:29 +0100
Subject: [PATCH v2 0/8] DDR2 memory initialisaion
In-Reply-To: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>

This patch set adds memory initialisation through SPD data for
Freescale CPUs such as the mpc8544. It is based on U-Boot tree id
a71d45d706a5b51c34

Support for DDR1, DDR3 and memory interleaving has been removed as
the code is aimed at the GEIP DA923RC board. Support for this
board will be submitted after approval of these patches by the
barebox community.

In addition, early I2C read access has been added so that the SPD
data can be retrieved from the I2C eeprom.

Renaud Barbier (8):
  common: DDR2 SPD checksum.
  ppc asm: DDR headers
  ppc 8xxx: DDR headers
  ppc 8xxx: DIMM parameters calculation
  ppc 8xxx: DDR utility and memory options
  ppx 8xxx: DDR registers value calculation
  ppc 8xxx: core DDR driver functions
  ppc 85xx: early I2C support

 arch/ppc/ddr-8xxx/common_timing_params.h     |   44 +++
 arch/ppc/ddr-8xxx/ctrl_regs.c                |  425 ++++++++++++++++++++++++++
 arch/ppc/ddr-8xxx/ddr.h                      |  105 +++++++
 arch/ppc/ddr-8xxx/ddr2_dimm_params.c         |  303 ++++++++++++++++++
 arch/ppc/ddr-8xxx/ddr2_setctrl.c             |   58 ++++
 arch/ppc/ddr-8xxx/lc_common_dimm_params.c    |  214 +++++++++++++
 arch/ppc/ddr-8xxx/main.c                     |  238 ++++++++++++++
 arch/ppc/ddr-8xxx/options.c                  |  111 +++++++
 arch/ppc/ddr-8xxx/util.c                     |  100 ++++++
 arch/ppc/include/asm/fsl_ddr_dimm_params.h   |   60 ++++
 arch/ppc/include/asm/fsl_ddr_sdram.h         |  131 ++++++++-
 arch/ppc/mach-mpc85xx/fsl_i2c.c              |  253 +++++++++++++++
 arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h |   18 ++
 common/Makefile                              |    1 +
 common/ddr_spd.c                             |   39 +++
 include/ddr_spd.h                            |  135 ++++++++
 16 files changed, 2231 insertions(+), 4 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/common_timing_params.h
 create mode 100644 arch/ppc/ddr-8xxx/ctrl_regs.c
 create mode 100644 arch/ppc/ddr-8xxx/ddr.h
 create mode 100644 arch/ppc/ddr-8xxx/ddr2_dimm_params.c
 create mode 100644 arch/ppc/ddr-8xxx/ddr2_setctrl.c
 create mode 100644 arch/ppc/ddr-8xxx/lc_common_dimm_params.c
 create mode 100644 arch/ppc/ddr-8xxx/main.c
 create mode 100644 arch/ppc/ddr-8xxx/options.c
 create mode 100644 arch/ppc/ddr-8xxx/util.c
 create mode 100644 arch/ppc/include/asm/fsl_ddr_dimm_params.h
 create mode 100644 arch/ppc/mach-mpc85xx/fsl_i2c.c
 create mode 100644 arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h
 create mode 100644 common/ddr_spd.c
 create mode 100644 include/ddr_spd.h



From renaud.barbier at ge.com  Tue Jun 25 06:45:32 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 11:45:32 +0100
Subject: [PATCH 3/8] ppc 8xxx: DDR headers
In-Reply-To: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372157137-7602-4-git-send-email-renaud.barbier@ge.com>

Structures are defined to record the common DIMM parameters
and memory options on a per DIMM basis.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/common_timing_params.h |   44 ++++++++++++
 arch/ppc/ddr-8xxx/ddr.h                  |  105 ++++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/common_timing_params.h
 create mode 100644 arch/ppc/ddr-8xxx/ddr.h

diff --git a/arch/ppc/ddr-8xxx/common_timing_params.h b/arch/ppc/ddr-8xxx/common_timing_params.h
new file mode 100644
index 0000000..b262193
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/common_timing_params.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#ifndef COMMON_TIMING_PARAMS_H
+#define COMMON_TIMING_PARAMS_H
+
+struct common_timing_params_s {
+	uint32_t tCKmin_X_ps;
+	uint32_t tCKmax_ps;
+	uint32_t tCKmax_max_ps;
+	uint32_t tRCD_ps;
+	uint32_t tRP_ps;
+	uint32_t tRAS_ps;
+	uint32_t tWR_ps;	/* maximum = 63750 ps */
+	uint32_t tWTR_ps;	/* maximum = 63750 ps */
+	uint32_t tRFC_ps;	/* maximum = 255 ns + 256 ns + .75 ns
+					   = 511750 ps */
+	uint32_t tRRD_ps;	/* maximum = 63750 ps */
+	uint32_t tRC_ps;	/* maximum = 254 ns + .75 ns = 254750 ps */
+	uint32_t refresh_rate_ps;
+	uint32_t tIS_ps;	/* byte 32, spd->ca_setup */
+	uint32_t tIH_ps;	/* byte 33, spd->ca_hold */
+	uint32_t tDS_ps;	/* byte 34, spd->data_setup */
+	uint32_t tDH_ps;	/* byte 35, spd->data_hold */
+	uint32_t tRTP_ps;	/* byte 38, spd->trtp */
+	uint32_t tDQSQ_max_ps;	/* byte 44, spd->tdqsq */
+	uint32_t tQHS_ps;	/* byte 45, spd->tqhs */
+	uint32_t ndimms_present;
+	uint32_t lowest_common_SPD_caslat;
+	uint32_t highest_common_derated_caslat;
+	uint32_t additive_latency;
+	uint32_t all_DIMMs_burst_lengths_bitmask;
+	uint32_t all_DIMMs_registered;
+	uint32_t all_DIMMs_ECC_capable;
+	uint64_t total_mem;
+	uint64_t base_address;
+};
+
+#endif
diff --git a/arch/ppc/ddr-8xxx/ddr.h b/arch/ppc/ddr-8xxx/ddr.h
new file mode 100644
index 0000000..6574500
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/ddr.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2013 GE Intelligent Platforms, Inc
+ * Copyright 2008-2011 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#ifndef FSL_DDR_MAIN_H
+#define FSL_DDR_MAIN_H
+
+#include <asm/fsl_ddr_sdram.h>
+#include <asm/fsl_ddr_dimm_params.h>
+#include <mach/fsl_i2c.h>
+#include <mach/clock.h>
+#include "common_timing_params.h"
+
+#ifdef CONFIG_MPC85xx
+#include <mach/immap_85xx.h>
+#endif
+
+/* Record of computed register values. */
+struct fsl_ddr_cfg_regs_s {
+	struct {
+		uint32_t bnds;
+		uint32_t config;
+		uint32_t config_2;
+	} cs[MAX_CHIP_SELECTS_PER_CTRL];
+	uint32_t timing_cfg_3;
+	uint32_t timing_cfg_0;
+	uint32_t timing_cfg_1;
+	uint32_t timing_cfg_2;
+	uint32_t ddr_sdram_cfg;
+	uint32_t ddr_sdram_cfg_2;
+	uint32_t ddr_sdram_mode;
+	uint32_t ddr_sdram_mode_2;
+	uint32_t ddr_sdram_mode_3;
+	uint32_t ddr_sdram_mode_4;
+	uint32_t ddr_sdram_mode_5;
+	uint32_t ddr_sdram_mode_6;
+	uint32_t ddr_sdram_mode_7;
+	uint32_t ddr_sdram_mode_8;
+	uint32_t ddr_sdram_md_cntl;
+	uint32_t ddr_sdram_interval;
+	uint32_t ddr_data_init;
+	uint32_t ddr_sdram_clk_cntl;
+	uint32_t ddr_init_addr;
+	uint32_t ddr_init_ext_addr;
+	uint32_t err_disable;
+	uint32_t err_int_en;
+	uint32_t debug[32];
+};
+
+/*
+ * Data Structures
+ *
+ * All data structures have to be on the stack
+ */
+struct fsl_ddr_info_s {
+	generic_spd_eeprom_t
+	spd_installed_dimms[MAX_DIMM_SLOTS_PER_CTLR];
+	struct dimm_params_s
+		dimm_params[MAX_DIMM_SLOTS_PER_CTLR];
+	struct memctl_options_s memctl_opts;
+	struct common_timing_params_s common_timing_params;
+	struct fsl_ddr_cfg_regs_s fsl_ddr_config_reg;
+	struct ddr_board_info_s board_info;
+};
+
+uint32_t mclk_to_picos(uint32_t mclk);
+uint32_t get_memory_clk_period_ps(void);
+uint32_t picos_to_mclk(uint32_t picos);
+uint32_t check_fsl_memctl_config_regs(const struct fsl_ddr_cfg_regs_s *ddr);
+uint64_t fsl_ddr_compute(struct fsl_ddr_info_s *pinfo);
+uint32_t compute_fsl_memctl_config_regs(
+		const struct memctl_options_s *popts,
+		struct fsl_ddr_cfg_regs_s *ddr,
+		const struct common_timing_params_s *common_dimm,
+		const struct dimm_params_s *dimm_parameters,
+		uint32_t dbw_capacity_adjust);
+uint32_t compute_dimm_parameters(
+		const generic_spd_eeprom_t *spdin,
+		struct dimm_params_s *pdimm);
+uint32_t compute_lowest_common_dimm_parameters(
+		const struct dimm_params_s *dimm_params,
+		struct common_timing_params_s *outpdimm,
+		uint32_t number_of_dimms);
+uint32_t populate_memctl_options(
+		int all_DIMMs_registered,
+		struct memctl_options_s *popts,
+		struct dimm_params_s *pdimm);
+int fsl_ddr_set_lawbar(
+		const struct common_timing_params_s *memctl_common_params,
+		uint32_t memctl_interleaved);
+int fsl_ddr_get_spd(
+		generic_spd_eeprom_t *ctrl_dimms_spd,
+		struct ddr_board_info_s *binfo);
+int fsl_ddr_set_memctl_regs(
+		const struct fsl_ddr_info_s *info);
+void fsl_ddr_board_options(
+		struct memctl_options_s *popts,
+		struct dimm_params_s *pdimm);
+void fsl_ddr_board_info(struct ddr_board_info_s *info);
+#endif
-- 
1.7.1



From renaud.barbier at ge.com  Tue Jun 25 06:45:30 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 11:45:30 +0100
Subject: [PATCH 1/8] common: DDR2 SPD checksum.
In-Reply-To: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372157137-7602-2-git-send-email-renaud.barbier@ge.com>

This commit adds support to calculate the DDR2 SPD checksum as per
JEDEC standard No 21-C Appendix X (revision 1.2)

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 common/Makefile   |    1 +
 common/ddr_spd.c  |   39 +++++++++++++++
 include/ddr_spd.h |  135 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 175 insertions(+), 0 deletions(-)
 create mode 100644 common/ddr_spd.c
 create mode 100644 include/ddr_spd.h

diff --git a/common/Makefile b/common/Makefile
index 2f0bd34..fc23421 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_CMD_LOADS)		+= s_record.o
 obj-$(CONFIG_OFTREE)		+= oftree.o
 
 obj-y += memory.o
+obj-$(CONFIG_DDR_SPD)  += ddr_spd.o
 obj-y += memory_display.o
 obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
diff --git a/common/ddr_spd.c b/common/ddr_spd.c
new file mode 100644
index 0000000..fbea5c0
--- /dev/null
+++ b/common/ddr_spd.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <ddr_spd.h>
+
+uint32_t ddr2_spd_check(const struct ddr2_spd_eeprom_s *spd)
+{
+	uint32_t i, cksum = 0;
+	const uint8_t *buf = (const uint8_t *)spd;
+	uint8_t rev, spd_cksum;
+
+	rev = spd->spd_rev;
+	spd_cksum = spd->cksum;
+
+	/* Rev 1.2 or less supported by this code */
+	if (rev >= 0x20)
+		goto error;
+
+	/*
+	 * The checksum is calculated on the first 64 bytes
+	 * of the SPD as per JEDEC specification.
+	 */
+	for (i = 0; i < 63; i++)
+		cksum += *buf++;
+	cksum &= 0xFF;
+
+	if (cksum != spd_cksum)
+		goto error;
+
+	return 0;
+error:
+	return 1;
+}
diff --git a/include/ddr_spd.h b/include/ddr_spd.h
new file mode 100644
index 0000000..10fd8cf
--- /dev/null
+++ b/include/ddr_spd.h
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#ifndef _DDR_SPD_H_
+#define _DDR_SPD_H_
+
+/*
+ * Format from "JEDEC Appendix X: Serial Presence Detects for DDR2 SDRAM",
+ * SPD Revision 1.2
+ */
+struct ddr2_spd_eeprom_s {
+	uint8_t info_size;   /*  0 # bytes written into serial memory */
+	uint8_t chip_size;   /*  1 Total # bytes of SPD memory device */
+	uint8_t mem_type;    /*  2 Fundamental memory type */
+	uint8_t nrow_addr;   /*  3 # of Row Addresses on this assembly */
+	uint8_t ncol_addr;   /*  4 # of Column Addrs on this assembly */
+	uint8_t mod_ranks;   /*  5 Number of DIMM Ranks */
+	uint8_t dataw;       /*  6 Module Data Width */
+	uint8_t res_7;       /*  7 Reserved */
+	uint8_t voltage;     /*  8 Voltage intf std of this assembly */
+	uint8_t clk_cycle;   /*  9 SDRAM Cycle time @ CL=X */
+	uint8_t clk_access;  /* 10 SDRAM Access from Clk @ CL=X (tAC) */
+	uint8_t config;      /* 11 DIMM Configuration type */
+	uint8_t refresh;     /* 12 Refresh Rate/Type */
+	uint8_t primw;       /* 13 Primary SDRAM Width */
+	uint8_t ecw;         /* 14 Error Checking SDRAM width */
+	uint8_t res_15;      /* 15 Reserved */
+	uint8_t burstl;      /* 16 Burst Lengths Supported */
+	uint8_t nbanks;      /* 17 # of Banks on Each SDRAM Device */
+	uint8_t cas_lat;     /* 18 CAS# Latencies Supported */
+	uint8_t mech_char;   /* 19 DIMM Mechanical Characteristics */
+	uint8_t dimm_type;   /* 20 DIMM type information */
+	uint8_t mod_attr;    /* 21 SDRAM Module Attributes */
+	uint8_t dev_attr;    /* 22 SDRAM Device Attributes */
+	uint8_t clk_cycle2;  /* 23 Min SDRAM Cycle time @ CL=X-1 */
+	uint8_t clk_access2; /* 24 SDRAM Access from Clk @ CL=X-1 (tAC) */
+	uint8_t clk_cycle3;  /* 25 Min SDRAM Cycle time @ CL=X-2 */
+	uint8_t clk_access3; /* 26 Max Access from Clk @ CL=X-2 (tAC) */
+	uint8_t trp;         /* 27 Min Row Precharge Time (tRP)*/
+	uint8_t trrd;        /* 28 Min Row Active to Row Active (tRRD) */
+	uint8_t trcd;        /* 29 Min RAS to CAS Delay (tRCD) */
+	uint8_t tras;        /* 30 Minimum RAS Pulse Width (tRAS) */
+	uint8_t rank_dens;   /* 31 Density of each rank on module */
+	uint8_t ca_setup;    /* 32 Addr+Cmd Setup Time Before Clk (tIS) */
+	uint8_t ca_hold;     /* 33 Addr+Cmd Hold Time After Clk (tIH) */
+	uint8_t data_setup;  /* 34 Data Input Setup Time Before Strobe
+					(tDS) */
+	uint8_t data_hold;   /* 35 Data Input Hold Time
+					After Strobe (tDH) */
+	uint8_t twr;         /* 36 Write Recovery time tWR */
+	uint8_t twtr;        /* 37 Int write to read delay tWTR */
+	uint8_t trtp;        /* 38 Int read to precharge delay tRTP */
+	uint8_t mem_probe;   /* 39 Mem analysis probe characteristics */
+	uint8_t trctrfc_ext; /* 40 Extensions to trc and trfc */
+	uint8_t trc;         /* 41 Min Active to Auto refresh time tRC */
+	uint8_t trfc;        /* 42 Min Auto to Active period tRFC */
+	uint8_t tckmax;      /* 43 Max device cycle time tCKmax */
+	uint8_t tdqsq;       /* 44 Max DQS to DQ skew (tDQSQ max) */
+	uint8_t tqhs;        /* 45 Max Read DataHold skew (tQHS) */
+	uint8_t pll_relock;  /* 46 PLL Relock time */
+	uint8_t Tcasemax;    /* 47 Tcasemax */
+	uint8_t psiTAdram;   /* 48 Thermal Resistance of DRAM Package
+					from Top (Case) to Ambient
+					(Psi T-A DRAM) */
+	uint8_t dt0_mode;    /* 49 DRAM Case Temperature Rise from
+					Ambient due to Activate-Precharge/Mode
+					Bits (DT0/Mode Bits) */
+	uint8_t dt2n_dt2q;   /* 50 DRAM Case Temperature Rise from
+					Ambient due to Precharge/Quiet Standby
+					(DT2N/DT2Q) */
+	uint8_t dt2p;        /* 51 DRAM Case Temperature Rise from
+					Ambient due to Precharge Power-Down
+					(DT2P) */
+	uint8_t dt3n;        /* 52 DRAM Case Temperature Rise from
+					Ambient due to Active Standby (DT3N) */
+	uint8_t dt3pfast;    /* 53 DRAM Case Temperature Rise from
+					Ambient due to Active Power-Down with
+					Fast PDN Exit (DT3Pfast) */
+	uint8_t dt3pslow;    /* 54 DRAM Case Temperature Rise from
+					Ambient due to Active Power-Down with
+					Slow PDN Exit (DT3Pslow) */
+	uint8_t dt4r_dt4r4w; /* 55 DRAM Case Temperature Rise from
+					Ambient due to Page Open Burst
+					Read/DT4R4W Mode Bit
+					(DT4R/DT4R4W Mode Bit) */
+	uint8_t dt5b;        /* 56 DRAM Case Temperature Rise from
+					Ambient due to Burst Refresh (DT5B) */
+	uint8_t dt7;         /* 57 DRAM Case Temperature Rise from
+					Ambient due to Bank Interleave Reads
+					with Auto-Precharge (DT7) */
+	uint8_t psiTApll;    /* 58 Thermal Resistance of PLL Package
+					form Top (Case) to Ambient
+					(Psi T-A PLL) */
+	uint8_t psiTAreg;    /* 59 Thermal Reisitance of Register
+					Package from Top (Case) to Ambient
+					(Psi T-A Register) */
+	uint8_t dtpllactive; /* 60 PLL Case Temperature Rise from
+					Ambient due to PLL Active
+					(DT PLL Active) */
+	uint8_t dtregact;    /* 61 Register Case Temperature Rise from
+					Ambient due to Register Active/Mode
+					Bit (DT Register Active/Mode Bit) */
+	uint8_t spd_rev;     /* 62 SPD Data Revision Code */
+	uint8_t cksum;       /* 63 Checksum for bytes 0-62 */
+	uint8_t mid[8];      /* 64 Mfr's JEDEC ID code per JEP-106 */
+	uint8_t mloc;        /* 72 Manufacturing Location */
+	uint8_t mpart[18];   /* 73 Manufacturer's Part Number */
+	uint8_t rev[2];      /* 91 Revision Code */
+	uint8_t mdate[2];    /* 93 Manufacturing Date */
+	uint8_t sernum[4];   /* 95 Assembly Serial Number */
+	uint8_t mspec[27];   /* 99-127 Manufacturer Specific Data */
+
+};
+
+extern uint32_t ddr2_spd_check(const struct ddr2_spd_eeprom_s *spd);
+
+/* * Byte 2 Fundamental Memory Types. */
+#define SPD_MEMTYPE_DDR2	(0x08)
+
+/* DIMM Type for DDR2 SPD (according to v1.3) */
+#define DDR2_SPD_DIMMTYPE_RDIMM		(0x01)
+#define DDR2_SPD_DIMMTYPE_UDIMM		(0x02)
+#define DDR2_SPD_DIMMTYPE_SO_DIMM	(0x04)
+#define DDR2_SPD_DIMMTYPE_72B_SO_CDIMM	(0x06)
+#define DDR2_SPD_DIMMTYPE_72B_SO_RDIMM	(0x07)
+#define DDR2_SPD_DIMMTYPE_MICRO_DIMM	(0x08)
+#define DDR2_SPD_DIMMTYPE_MINI_RDIMM	(0x10)
+#define DDR2_SPD_DIMMTYPE_MINI_UDIMM	(0x20)
+
+#endif /* _DDR_SPD_H_ */
-- 
1.7.1



From renaud.barbier at ge.com  Tue Jun 25 06:45:33 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 11:45:33 +0100
Subject: [PATCH 4/8] ppc 8xxx: DIMM parameters calculation
In-Reply-To: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372157137-7602-5-git-send-email-renaud.barbier@ge.com>

This code calculates the DIMM characteritics i.e DIMM
organization parameters and timings for DDR2 memory based on
SPD data.

It also provides a function to find out the lowest common DIMM
parameters to be used for all DIMMs.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/ddr2_dimm_params.c      |  303 +++++++++++++++++++++++++++++
 arch/ppc/ddr-8xxx/lc_common_dimm_params.c |  214 ++++++++++++++++++++
 2 files changed, 517 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/ddr2_dimm_params.c
 create mode 100644 arch/ppc/ddr-8xxx/lc_common_dimm_params.c

diff --git a/arch/ppc/ddr-8xxx/ddr2_dimm_params.c b/arch/ppc/ddr-8xxx/ddr2_dimm_params.c
new file mode 100644
index 0000000..f04d826
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/ddr2_dimm_params.c
@@ -0,0 +1,303 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <asm/fsl_ddr_sdram.h>
+#include "ddr.h"
+/*
+ * Calculate the Density of each Physical Rank.
+ * Returned size is in bytes.
+ *
+ * Table comes from Byte 31 of JEDEC SPD Spec.
+ *
+ *		DDR II
+ *	Bit	Size	Size
+ *	---	-----
+ *	7 high	512MB
+ *	6	256MB
+ *	5	128MB
+ *	4	 16GB
+ *	3	  8GB
+ *	2	  4GB
+ *	1	  2GB
+ *	0 low	  1GB
+ *
+ * Reorder Table to be linear by stripping the bottom
+ * 2 or 5 bits off and shifting them up to the top.
+ *
+ */
+static uint64_t compute_ranksize(uint32_t mem_type, unsigned char row_dens)
+{
+	uint64_t bsize;
+
+	bsize = ((row_dens >> 5) | ((row_dens & 31) << 3));
+	bsize <<= 27ULL;
+
+	return bsize;
+}
+
+/*
+ * Convert a two-nibble BCD value into a cycle time.
+ * While the spec calls for nano-seconds, picos are returned.
+ */
+static uint32_t convert_bcd_tenths_to_cycle_time_ps(uint32_t spd_val)
+{
+	uint32_t tenths_ps[16] = {
+		0,
+		100,
+		200,
+		300,
+		400,
+		500,
+		600,
+		700,
+		800,
+		900,
+		250,
+		330,
+		660,
+		750,
+		0,
+		0
+	};
+	uint32_t whole_ns = (spd_val & 0xF0) >> 4;
+	uint32_t tenth_ns = spd_val & 0x0F;
+	uint32_t ps = (whole_ns * 1000) + tenths_ps[tenth_ns];
+
+	return ps;
+}
+
+static uint32_t convert_bcd_hundredths_to_cycle_time_ps(uint32_t spd_val)
+{
+	uint32_t tenth_ns = (spd_val & 0xF0) >> 4;
+	uint32_t hundredth_ns = spd_val & 0x0F;
+	uint32_t ps = (tenth_ns * 100) + (hundredth_ns * 10);
+
+	return ps;
+}
+
+static uint32_t byte40_table_ps[8] = {
+	0,
+	250,
+	330,
+	500,
+	660,
+	750,
+	0,
+	0
+};
+
+static uint32_t
+compute_trfc_ps_from_spd(unsigned char trctrfc_ext, unsigned char trfc)
+{
+	uint32_t trfc_ps;
+
+	trfc_ps = (((trctrfc_ext & 0x1) * 256) + trfc) * 1000;
+	trfc_ps += byte40_table_ps[(trctrfc_ext >> 1) & 0x7];
+
+	return trfc_ps;
+}
+
+static uint32_t
+compute_trc_ps_from_spd(unsigned char trctrfc_ext, unsigned char trc)
+{
+	uint32_t trc_ps;
+
+	trc_ps = (trc * 1000);
+	trc_ps += byte40_table_ps[(trctrfc_ext >> 4) & 0x7];
+
+	return trc_ps;
+}
+
+/*
+ * Determine Refresh Rate.
+ * Table from SPD Spec, Byte 12, converted to picoseconds and
+ * filled in with "default" normal values.
+ */
+static uint32_t determine_refresh_rate_ps(const uint32_t spd_refresh)
+{
+	uint32_t refresh_time_ps[8] = {
+		15625000,	/* 0 Normal    1.00x */
+		3900000,	/* 1 Reduced    .25x */
+		7800000,	/* 2 Extended   .50x */
+		31300000,	/* 3 Extended  2.00x */
+		62500000,	/* 4 Extended  4.00x */
+		125000000,	/* 5 Extended  8.00x */
+		15625000,	/* 6 Normal    1.00x  filler */
+		15625000,	/* 7 Normal    1.00x  filler */
+	};
+
+	return refresh_time_ps[spd_refresh & 0x7];
+}
+
+/*
+ * The purpose of this function is to compute a suitable
+ * CAS latency given the DRAM clock period. The SPD only
+ * defines at most 3 CAS latencies. Typically the slower in
+ * frequency the DIMM runs at, the shorter its CAS latency can.
+ * be. If the DIMM is operating at a sufficiently low frequency,
+ * it may be able to run at a CAS latency shorter than the
+ * shortest SPD-defined CAS latency.
+ *
+ * If a CAS latency is not found, 0 is returned.
+ *
+ * Do this by finding in the standard speed table the longest
+ * tCKmin that doesn't exceed the value of mclk_ps (tCK).
+ *
+ * An assumption made is that the SDRAM device allows the
+ * CL to be programmed for a value that is lower than those
+ * advertised by the SPD. This is not always the case,
+ * as those modes not defined in the SPD are optional.
+ *
+ * CAS latency de-rating based upon values JEDEC Standard No. 79-2C
+ * Table 40, "DDR2 SDRAM standard speed bins and tCK, tRCD, tRP, tRAS,
+ * and tRC for corresponding bin"
+ *
+ * ordinal 2, ddr2_speed_bins[1] contains tCK for CL=3
+ * Not certain if any good value exists for CL=2
+ */
+			  /* CL2  CL3   CL4   CL5   CL6   CL7 */
+uint16_t ddr2_speed_bins[] = { 0, 5000, 3750, 3000, 2500, 1875 };
+
+uint32_t compute_derated_DDR2_CAS_latency(uint32_t mclk_ps)
+{
+	const uint32_t num_speed_bins = ARRAY_SIZE(ddr2_speed_bins);
+	uint32_t lowest_tCKmin_found = 0, lowest_tCKmin_CL = 0, i, x;
+
+	for (i = 0; i < num_speed_bins; i++) {
+		x = ddr2_speed_bins[i];
+		if (x && (x <= mclk_ps) && (x >= lowest_tCKmin_found)) {
+			lowest_tCKmin_found = x;
+			lowest_tCKmin_CL = i + 2;
+		}
+	}
+
+	return lowest_tCKmin_CL;
+}
+
+/*
+ * compute_dimm_parameters for DDR2 SPD
+ *
+ * Compute DIMM parameters based upon the SPD information in SPD.
+ * Writes the results to the dimm_params_s structure pointed by pdimm.
+ */
+uint32_t
+compute_dimm_parameters(const generic_spd_eeprom_t *spdin,
+		struct dimm_params_s *pdimm)
+{
+	const struct ddr2_spd_eeprom_s *spd = spdin;
+	uint32_t retval;
+
+	if (!spd->mem_type) {
+		memset(pdimm, 0, sizeof(struct dimm_params_s));
+		goto error;
+	}
+
+	if (spd->mem_type != SPD_MEMTYPE_DDR2)
+		goto error;
+
+	retval = ddr2_spd_check(spd);
+	if (retval)
+		goto spd_err;
+
+	/*
+	 * The part name in ASCII in the SPD EEPROM is not null terminated.
+	 * Guarantee null termination here by presetting all bytes to 0
+	 * and copying the part name in ASCII from the SPD onto it
+	 */
+	memset(pdimm->mpart, 0, sizeof(pdimm->mpart));
+	memcpy(pdimm->mpart, spd->mpart, sizeof(pdimm->mpart) - 1);
+
+	/* DIMM organization parameters */
+	pdimm->n_ranks = (spd->mod_ranks & 0x7) + 1;
+	pdimm->rank_density = compute_ranksize(spd->mem_type, spd->rank_dens);
+	pdimm->capacity = pdimm->n_ranks * pdimm->rank_density;
+	pdimm->data_width = spd->dataw;
+	pdimm->primary_sdram_width = spd->primw;
+	pdimm->ec_sdram_width = spd->ecw;
+
+	/* These are all the types defined by the JEDEC DDR2 SPD 1.3 spec */
+	switch (spd->dimm_type) {
+	case DDR2_SPD_DIMMTYPE_RDIMM:
+	case DDR2_SPD_DIMMTYPE_72B_SO_RDIMM:
+	case DDR2_SPD_DIMMTYPE_MINI_RDIMM:
+		/* Registered/buffered DIMMs */
+		pdimm->registered_dimm = 1;
+		break;
+
+	case DDR2_SPD_DIMMTYPE_UDIMM:
+	case DDR2_SPD_DIMMTYPE_SO_DIMM:
+	case DDR2_SPD_DIMMTYPE_MICRO_DIMM:
+	case DDR2_SPD_DIMMTYPE_MINI_UDIMM:
+		/* Unbuffered DIMMs */
+		pdimm->registered_dimm = 0;
+		break;
+
+	case DDR2_SPD_DIMMTYPE_72B_SO_CDIMM:
+	default:
+		goto error;
+	}
+
+	pdimm->n_row_addr = spd->nrow_addr;
+	pdimm->n_col_addr = spd->ncol_addr;
+	pdimm->n_banks_per_sdram_device = spd->nbanks;
+	pdimm->edc_config = spd->config;
+	pdimm->burst_lengths_bitmask = spd->burstl;
+	pdimm->row_density = spd->rank_dens;
+
+	/*
+	 * Calculate the Maximum Data Rate based on the Minimum Cycle time.
+	 * The SPD clk_cycle field (tCKmin) is measured in tenths of
+	 * nanoseconds and represented as BCD.
+	 */
+	pdimm->tCKmin_X_ps
+	    = convert_bcd_tenths_to_cycle_time_ps(spd->clk_cycle);
+	pdimm->tCKmin_X_minus_1_ps
+	    = convert_bcd_tenths_to_cycle_time_ps(spd->clk_cycle2);
+	pdimm->tCKmin_X_minus_2_ps
+	    = convert_bcd_tenths_to_cycle_time_ps(spd->clk_cycle3);
+	pdimm->tCKmax_ps = convert_bcd_tenths_to_cycle_time_ps(spd->tckmax);
+
+	/*
+	 * Compute CAS latencies defined by SPD
+	 * The SPD caslat_X should have at least 1 and at most 3 bits set.
+	 *
+	 * If cas_lat after masking is 0, the __ilog2 function returns
+	 * 255 into the variable. This behavior is abused once.
+	 */
+	pdimm->caslat_X = __ilog2(spd->cas_lat);
+	pdimm->caslat_X_minus_1 = __ilog2(spd->cas_lat
+					  & ~(1 << pdimm->caslat_X));
+	pdimm->caslat_X_minus_2 = __ilog2(spd->cas_lat & ~(1 << pdimm->caslat_X)
+					  & ~(1 << pdimm->caslat_X_minus_1));
+	pdimm->caslat_lowest_derated
+	    = compute_derated_DDR2_CAS_latency(get_memory_clk_period_ps());
+	pdimm->tRCD_ps = spd->trcd * 250;
+	pdimm->tRP_ps = spd->trp * 250;
+	pdimm->tRAS_ps = spd->tras * 1000;
+	pdimm->tWR_ps = spd->twr * 250;
+	pdimm->tWTR_ps = spd->twtr * 250;
+	pdimm->tRFC_ps = compute_trfc_ps_from_spd(spd->trctrfc_ext, spd->trfc);
+	pdimm->tRRD_ps = spd->trrd * 250;
+	pdimm->tRC_ps = compute_trc_ps_from_spd(spd->trctrfc_ext, spd->trc);
+	pdimm->refresh_rate_ps = determine_refresh_rate_ps(spd->refresh);
+	pdimm->tIS_ps = convert_bcd_hundredths_to_cycle_time_ps(spd->ca_setup);
+	pdimm->tIH_ps = convert_bcd_hundredths_to_cycle_time_ps(spd->ca_hold);
+	pdimm->tDS_ps
+	    = convert_bcd_hundredths_to_cycle_time_ps(spd->data_setup);
+	pdimm->tDH_ps = convert_bcd_hundredths_to_cycle_time_ps(spd->data_hold);
+	pdimm->tRTP_ps = spd->trtp * 250;
+	pdimm->tDQSQ_max_ps = spd->tdqsq * 10;
+	pdimm->tQHS_ps = spd->tqhs * 10;
+
+	return 0;
+error:
+	return 1;
+spd_err:
+	return 2;
+}
diff --git a/arch/ppc/ddr-8xxx/lc_common_dimm_params.c b/arch/ppc/ddr-8xxx/lc_common_dimm_params.c
new file mode 100644
index 0000000..a1addb0
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/lc_common_dimm_params.c
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2008-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <config.h>
+#include <asm/fsl_ddr_sdram.h>
+
+#include "ddr.h"
+
+static unsigned int common_burst_length(
+		const struct dimm_params_s *dimm_params,
+		const unsigned int number_of_dimms)
+{
+	unsigned int i, temp;
+
+	temp = 0xff;
+	for (i = 0; i < number_of_dimms; i++)
+		if (dimm_params[i].n_ranks)
+			temp &= dimm_params[i].burst_lengths_bitmask;
+
+	return temp;
+}
+
+/* Compute a CAS latency suitable for all DIMMs */
+static unsigned int compute_lowest_caslat(
+		const struct dimm_params_s *dimm_params,
+		const unsigned int number_of_dimms)
+{
+	uint32_t temp1, temp2, i, not_ok, lowest_good_caslat,
+		 tCKmin_X_minus_1_ps, tCKmin_X_minus_2_ps;
+	const unsigned int mclk_ps = get_memory_clk_period_ps();
+
+	/*
+	 * Step 1: find CAS latency common to all DIMMs using bitwise
+	 * operation.
+	 */
+	temp1 = 0xFF;
+	for (i = 0; i < number_of_dimms; i++)
+		if (dimm_params[i].n_ranks) {
+			temp2 = 0;
+			temp2 |= 1 << dimm_params[i].caslat_X;
+			temp2 |= 1 << dimm_params[i].caslat_X_minus_1;
+			temp2 |= 1 << dimm_params[i].caslat_X_minus_2;
+			/*
+			 * FIXME: If there was no entry for X-2 (X-1) in
+			 * the SPD, then caslat_X_minus_2
+			 * (caslat_X_minus_1) contains either 255 or
+			 * 0xFFFFFFFF because that's what the __ilog2
+			 * function returns for an input of 0.
+			 * On 32-bit PowerPC, left shift counts with bit
+			 * 26 set (that the value of 255 or 0xFFFFFFFF
+			 * will have), cause the destination register to
+			 * be 0. That is why this works.
+			 */
+			temp1 &= temp2;
+		}
+
+	/*
+	 * Step 2: check each common CAS latency against tCK of each
+	 * DIMM's SPD.
+	 */
+	lowest_good_caslat = 0;
+	temp2 = 0;
+	while (temp1) {
+		not_ok = 0;
+		temp2 = __ilog2(temp1);
+
+		for (i = 0; i < number_of_dimms; i++) {
+			if (!dimm_params[i].n_ranks)
+				continue;
+
+			if (dimm_params[i].caslat_X == temp2) {
+				if (mclk_ps >= dimm_params[i].tCKmin_X_ps)
+					continue;
+				else
+					not_ok++;
+			}
+
+			if (dimm_params[i].caslat_X_minus_1 == temp2) {
+				tCKmin_X_minus_1_ps =
+					dimm_params[i].tCKmin_X_minus_1_ps;
+				if (mclk_ps >= tCKmin_X_minus_1_ps)
+					continue;
+				else
+					not_ok++;
+			}
+
+			if (dimm_params[i].caslat_X_minus_2 == temp2) {
+				tCKmin_X_minus_2_ps
+					= dimm_params[i].tCKmin_X_minus_2_ps;
+				if (mclk_ps >= tCKmin_X_minus_2_ps)
+					continue;
+				else
+					not_ok++;
+			}
+		}
+
+		if (!not_ok)
+			lowest_good_caslat = temp2;
+
+		temp1 &= ~(1 << temp2);
+	}
+	return lowest_good_caslat;
+}
+
+/*
+ * compute_lowest_common_dimm_parameters()
+ *
+ * Determine the worst-case DIMM timing parameters from the set of DIMMs
+ * whose parameters have been computed into the array pointed to
+ * by dimm_params.
+ */
+unsigned int
+compute_lowest_common_dimm_parameters(const struct dimm_params_s *dimm,
+				      struct common_timing_params_s *out,
+				      const unsigned int number_of_dimms)
+{
+	const uint32_t mclk_ps = get_memory_clk_period_ps();
+	uint32_t temp1, i;
+	struct common_timing_params_s tmp = {0};
+
+	tmp.tCKmax_ps = 0xFFFFFFFF;
+	temp1 = 0;
+	for (i = 0; i < number_of_dimms; i++) {
+		if (dimm[i].n_ranks == 0) {
+			temp1++;
+			continue;
+		}
+
+		/*
+		 * Find minimum tCKmax_ps to find fastest slow speed,
+		 * i.e., this is the slowest the whole system can go.
+		 */
+		tmp.tCKmax_ps = min(tmp.tCKmax_ps, dimm[i].tCKmax_ps);
+
+		/* Find maximum value to determine slowest speed, delay, etc */
+		tmp.tCKmin_X_ps = max(tmp.tCKmin_X_ps, dimm[i].tCKmin_X_ps);
+		tmp.tCKmax_max_ps = max(tmp.tCKmax_max_ps, dimm[i].tCKmax_ps);
+		tmp.tRCD_ps = max(tmp.tRCD_ps, dimm[i].tRCD_ps);
+		tmp.tRP_ps = max(tmp.tRP_ps, dimm[i].tRP_ps);
+		tmp.tRAS_ps = max(tmp.tRAS_ps, dimm[i].tRAS_ps);
+		tmp.tWR_ps = max(tmp.tWR_ps, dimm[i].tWR_ps);
+		tmp.tWTR_ps = max(tmp.tWTR_ps, dimm[i].tWTR_ps);
+		tmp.tRFC_ps = max(tmp.tRFC_ps, dimm[i].tRFC_ps);
+		tmp.tRRD_ps = max(tmp.tRRD_ps, dimm[i].tRRD_ps);
+		tmp.tRC_ps = max(tmp.tRC_ps, dimm[i].tRC_ps);
+		tmp.tIS_ps = max(tmp.tIS_ps, dimm[i].tIS_ps);
+		tmp.tIH_ps = max(tmp.tIH_ps, dimm[i].tIH_ps);
+		tmp.tDS_ps = max(tmp.tDS_ps, dimm[i].tDS_ps);
+		tmp.tDH_ps = max(tmp.tDH_ps, dimm[i].tDH_ps);
+		tmp.tRTP_ps = max(tmp.tRTP_ps, dimm[i].tRTP_ps);
+		tmp.tQHS_ps = max(tmp.tQHS_ps, dimm[i].tQHS_ps);
+		tmp.refresh_rate_ps = max(tmp.refresh_rate_ps,
+				dimm[i].refresh_rate_ps);
+		/* Find maximum tDQSQ_max_ps to find slowest timing. */
+		tmp.tDQSQ_max_ps = max(tmp.tDQSQ_max_ps, dimm[i].tDQSQ_max_ps);
+	}
+	tmp.ndimms_present = number_of_dimms - temp1;
+
+	if (temp1 == number_of_dimms)
+		return 0;
+
+	temp1 = common_burst_length(dimm, number_of_dimms);
+	tmp.all_DIMMs_burst_lengths_bitmask = temp1;
+	tmp.all_DIMMs_registered = 0;
+
+	tmp.lowest_common_SPD_caslat = compute_lowest_caslat(dimm,
+			number_of_dimms);
+	/*
+	 * Compute a common 'de-rated' CAS latency.
+	 *
+	 * The strategy here is to find the *highest* de-rated cas latency
+	 * with the assumption that all of the DIMMs will support a de-rated
+	 * CAS latency higher than or equal to their lowest de-rated value.
+	 */
+	temp1 = 0;
+	for (i = 0; i < number_of_dimms; i++)
+		temp1 = max(temp1, dimm[i].caslat_lowest_derated);
+	tmp.highest_common_derated_caslat = temp1;
+
+	temp1 = 1;
+	for (i = 0; i < number_of_dimms; i++)
+		if (dimm[i].n_ranks &&
+		    !(dimm[i].edc_config & EDC_ECC)) {
+			temp1 = 0;
+			break;
+		}
+	tmp.all_DIMMs_ECC_capable = temp1;
+
+	if (mclk_ps > tmp.tCKmax_max_ps)
+		return 1;
+
+	/*
+	 * AL must be less or equal to tRCD. Typically, AL would
+	 * be AL = tRCD - 1;
+	 *
+	 * When ODT read or write is enabled the sum of CAS latency +
+	 * additive latency must be at least 3 cycles.
+	 *
+	 */
+	if ((tmp.lowest_common_SPD_caslat < 4) && (picos_to_mclk(tmp.tRCD_ps) >
+				tmp.lowest_common_SPD_caslat))
+		tmp.additive_latency = picos_to_mclk(tmp.tRCD_ps) -
+			tmp.lowest_common_SPD_caslat;
+
+	memcpy(out, &tmp, sizeof(struct common_timing_params_s));
+
+	return 0;
+}
-- 
1.7.1



From renaud.barbier at ge.com  Tue Jun 25 06:45:34 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 11:45:34 +0100
Subject: [PATCH 5/8] ppc 8xxx: DDR utility and memory options
In-Reply-To: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372157137-7602-6-git-send-email-renaud.barbier@ge.com>

This commit adds functions to calculate clock cycles, configure the
LAW registers and populate board memory options.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/options.c |  111 +++++++++++++++++++++++++++++++++++++++++++
 arch/ppc/ddr-8xxx/util.c    |  100 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 211 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/options.c
 create mode 100644 arch/ppc/ddr-8xxx/util.c

diff --git a/arch/ppc/ddr-8xxx/options.c b/arch/ppc/ddr-8xxx/options.c
new file mode 100644
index 0000000..22b621f
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/options.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2008, 2010-2012 Freescale Semiconductor, Inc.
+ *
+ * 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.
+ */
+
+#include <common.h>
+#include <asm/fsl_ddr_sdram.h>
+#include "ddr.h"
+
+uint32_t populate_memctl_options(int all_DIMMs_registered,
+		struct memctl_options_s *popts,
+		struct dimm_params_s *pdimm)
+{
+	const struct ddr_board_info_s *binfo = popts->board_info;
+	uint32_t i;
+
+	for (i = 0; i < binfo->cs_per_ctrl; i++) {
+		popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
+		popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_ALL;
+		popts->cs_local_opts[i].odt_rtt_norm = DDR2_RTT_50_OHM;
+		popts->cs_local_opts[i].odt_rtt_wr = DDR2_RTT_OFF;
+		popts->cs_local_opts[i].auto_precharge = 0;
+	}
+
+	/* Memory Organization Parameters */
+	popts->registered_dimm_en = all_DIMMs_registered;
+	popts->ECC_mode = 0;		  /* 0 = disabled, 1 = enabled */
+	popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
+
+	/* Choose DQS config - 1 for DDR2 */
+	popts->DQS_config = 1;
+
+	/* Choose self-refresh during sleep. */
+	popts->self_refresh_in_sleep = 1;
+
+	/* Choose dynamic power management mode. */
+	popts->dynamic_power = 0;
+
+	/*
+	 * check first dimm for primary sdram width
+	 * assuming all dimms are similar
+	 * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
+	 */
+	if (pdimm->n_ranks != 0) {
+		if ((pdimm->data_width >= 64) && (pdimm->data_width <= 72))
+			popts->data_bus_width = 0;
+		else if ((pdimm->data_width >= 32) ||
+			(pdimm->data_width <= 40))
+			popts->data_bus_width = 1;
+		else
+			panic("data width %u is invalid!\n",
+					pdimm->data_width);
+	}
+
+	/* Must be a burst length of 4 for DD2 */
+	popts->burst_length = DDR_BL4;
+	/* Decide whether to use the computed de-rated latency */
+	popts->use_derated_caslat = 0;
+
+	/*
+	 * 2T_EN setting
+	 *
+	 * Factors to consider for 2T_EN:
+	 *	- number of DIMMs installed
+	 *	- number of components, number of active ranks
+	 *	- how much time you want to spend playing around
+	 */
+	popts->twoT_en = 0;
+
+	/*
+	 * Default BSTTOPRE precharge interval
+	 *
+	 * Set the parameter to 0 for global auto precharge in
+	 * the board options function.
+	 */
+	popts->bstopre = 0x100;
+
+	/* Minimum CKE pulse width -- tCKE(MIN) */
+	popts->tCKE_clock_pulse_width_ps
+		= mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
+
+	/*
+	 * Window for four activates -- tFAW
+	 *
+	 * Set according to specification for the memory used.
+	 * The default value below would work for x4/x8 wide memory.
+	 *
+	 */
+	popts->tFAW_window_four_activates_ps = 37500;
+
+	/*
+	 * Default powerdown exit timings.
+	 * Set according to specifications for the memory used in
+	 * the board options function.
+	 */
+	popts->txard = 3;
+	popts->txp = 3;
+	popts->taxpd = 11;
+
+	/* Default value for load mode cycle time */
+	popts->tmrd = 2;
+
+	/* Specific board override parameters. */
+	fsl_ddr_board_options(popts, pdimm);
+
+	return 0;
+}
diff --git a/arch/ppc/ddr-8xxx/util.c b/arch/ppc/ddr-8xxx/util.c
new file mode 100644
index 0000000..626b5f3
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/util.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2008-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <asm/fsl_law.h>
+#include <asm-generic/div64.h>
+#include <mach/clock.h>
+#include "ddr.h"
+
+#define ULL_2E12 2000000000000ULL
+#define UL_5POW12 244140625UL
+#define UL_2POW13 (1UL << 13)
+#define ULL_8FS 0xFFFFFFFFULL
+
+/*
+ * Round up mclk_ps to nearest 1 ps in memory controller code
+ * if the error is 0.5ps or more.
+ *
+ * If an imprecise data rate is too high due to rounding error
+ * propagation, compute a suitably rounded mclk_ps to compute
+ * a working memory controller configuration.
+ */
+uint32_t get_memory_clk_period_ps(void)
+{
+	uint32_t result, data_rate = fsl_get_ddr_freq(0);
+	/* Round to nearest 10ps, being careful about 64-bit multiply/divide */
+	uint64_t rem, mclk_ps = ULL_2E12;
+
+	/* Now perform the big divide, the result fits in 32-bits */
+	rem = do_div(mclk_ps, data_rate);
+	if (rem >= (data_rate >> 1))
+		result = mclk_ps + 1;
+	else
+		result = mclk_ps;
+
+	return result;
+}
+
+/* Convert picoseconds into DRAM clock cycles (rounding up if needed). */
+uint32_t picos_to_mclk(uint32_t picos)
+{
+	uint64_t clks, clks_rem;
+	uint32_t data_rate = fsl_get_ddr_freq(0);
+
+	if (!picos)
+		return 0;
+
+	/* First multiply the time by the data rate (32x32 => 64) */
+	clks = picos * (uint64_t)data_rate;
+	/*
+	 * Now divide by 5^12 and track the 32-bit remainder, then divide
+	 * by 2*(2^12) using shifts (and updating the remainder).
+	 */
+	clks_rem = do_div(clks, UL_5POW12);
+	clks_rem += (clks & (UL_2POW13 - 1)) * UL_5POW12;
+	clks >>= 13;
+
+	/* If we had a remainder greater than the 1ps error, then round up */
+	if (clks_rem > data_rate)
+		clks++;
+
+	if (clks > ULL_8FS)
+		clks = ULL_8FS;
+
+	return (uint32_t)clks;
+}
+
+uint32_t mclk_to_picos(unsigned int mclk)
+{
+	return get_memory_clk_period_ps() * mclk;
+}
+
+int fsl_ddr_set_lawbar(
+		const struct common_timing_params_s *params,
+		uint32_t law_memctl)
+{
+	uint64_t base = params->base_address;
+	uint64_t size = params->total_mem;
+
+	if (!params->ndimms_present)
+		goto out;
+
+	if (base >= MAX_MEM_MAPPED)
+		goto error;
+
+	if ((base + size) >= MAX_MEM_MAPPED)
+		size = MAX_MEM_MAPPED - base;
+
+	if (fsl_set_ddr_laws(base, size, law_memctl) < 0)
+		goto error;
+out:
+	return 0;
+error:
+	return 1;
+}
-- 
1.7.1



From renaud.barbier at ge.com  Tue Jun 25 06:45:35 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 11:45:35 +0100
Subject: [PATCH 6/8] ppx 8xxx: DDR registers value calculation
In-Reply-To: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372157137-7602-7-git-send-email-renaud.barbier@ge.com>

The functions in this file calculate and store the value for each
register of the memory controller.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/ctrl_regs.c |  425 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 425 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/ctrl_regs.c

diff --git a/arch/ppc/ddr-8xxx/ctrl_regs.c b/arch/ppc/ddr-8xxx/ctrl_regs.c
new file mode 100644
index 0000000..3f8ecf7
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/ctrl_regs.c
@@ -0,0 +1,425 @@
+/*
+ * Copyright 2008-2012 Freescale Semiconductor, Inc.
+ *
+ * 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.
+ */
+
+/*
+ * Generic driver for Freescale DDR2 memory controller.
+ * Based on code from spd_sdram.c
+ * Author: James Yang [at freescale.com]
+ */
+
+#include <common.h>
+#include <asm/fsl_ddr_sdram.h>
+#include "ddr.h"
+
+static void set_csn_config(int dimm_number, int i,
+			   struct fsl_ddr_cfg_regs_s *ddr,
+			   const struct memctl_options_s *popts,
+			   const struct dimm_params_s *dimm)
+{
+	uint32_t cs_n_en = 0, ap_n_en = 0, odt_rd_cfg = 0, odt_wr_cfg = 0,
+		 ba_bits_cs_n = 0, row_bits_cs_n = 0, col_bits_cs_n = 0,
+		 n_banks_per_sdram_device;
+	int go_config = 0;
+
+	switch (i) {
+	case 0:
+		if (dimm[dimm_number].n_ranks > 0)
+			go_config = 1;
+		break;
+	case 1:
+		if ((dimm_number == 0 && dimm[0].n_ranks > 1) ||
+		    (dimm_number == 1 && dimm[1].n_ranks > 0))
+			go_config = 1;
+		break;
+	case 2:
+		if ((dimm_number == 0 && dimm[0].n_ranks > 2) ||
+		    (dimm_number >= 1 && dimm[dimm_number].n_ranks > 0))
+			go_config = 1;
+		break;
+	case 3:
+		if ((dimm_number == 0 && dimm[0].n_ranks > 3) ||
+		    (dimm_number == 1 && dimm[1].n_ranks > 1) ||
+		    (dimm_number == 3 && dimm[3].n_ranks > 0))
+			go_config = 1;
+		break;
+	default:
+		break;
+	}
+
+	if (go_config) {
+		/* Chip Select enable */
+		cs_n_en = 1;
+		/* CSn auto-precharge enable */
+		ap_n_en = popts->cs_local_opts[i].auto_precharge;
+		/* ODT for reads configuration */
+		odt_rd_cfg = popts->cs_local_opts[i].odt_rd_cfg;
+		/* ODT for writes configuration */
+		odt_wr_cfg = popts->cs_local_opts[i].odt_wr_cfg;
+		/* Num of bank bits for SDRAM on CSn */
+		n_banks_per_sdram_device =
+			dimm[dimm_number].n_banks_per_sdram_device;
+		ba_bits_cs_n = __ilog2(n_banks_per_sdram_device) - 2;
+		/* Num of row bits for SDRAM on CSn */
+		row_bits_cs_n = dimm[dimm_number].n_row_addr - 12;
+		/* Num of ocl bits for SDRAM on CSn */
+		col_bits_cs_n = dimm[dimm_number].n_col_addr - 8;
+	}
+
+	ddr->cs[i].config = (((cs_n_en & 0x1) << 31)
+			     | ((ap_n_en & 0x1) << 23)
+			     | ((odt_rd_cfg & 0x7) << 20)
+			     | ((odt_wr_cfg & 0x7) << 16)
+			     | ((ba_bits_cs_n & 0x3) << 14)
+			     | ((row_bits_cs_n & 0x7) << 8)
+			     | ((col_bits_cs_n & 0x7) << 0));
+}
+
+static void set_timing_cfg_0(struct fsl_ddr_cfg_regs_s *ddr,
+			     const struct memctl_options_s *popts)
+{
+	uint32_t trwt_mclk = 0;
+
+	if (popts->trwt_override)
+		trwt_mclk = popts->trwt;
+
+	ddr->timing_cfg_0 = (((trwt_mclk & 0x3) << 30)
+			     | ((popts->txard & 0x7) << 20)
+			     | ((popts->txp & 0xF) << 16)
+			     | ((popts->taxpd & 0xf) << 8)
+			     | ((popts->tmrd & 0xf) << 0));
+}
+
+static void set_timing_cfg_3(struct fsl_ddr_cfg_regs_s *ddr,
+			     const struct common_timing_params_s *dimm,
+			     uint32_t cas_latency)
+{
+	uint32_t ext_pretoact, ext_acttopre, ext_acttorw, ext_refrec;
+
+	ext_pretoact = picos_to_mclk(dimm->tRP_ps) >> 4;
+	ext_acttopre = picos_to_mclk(dimm->tRAS_ps) >> 4;
+	ext_acttorw = picos_to_mclk(dimm->tRCD_ps) >> 4;
+	cas_latency = ((cas_latency << 1) - 1) >> 4;
+	ext_refrec = (picos_to_mclk(dimm->tRFC_ps) - 8) >> 4;
+
+	ddr->timing_cfg_3 = (((ext_pretoact & 0x1) << 28)
+			     | ((ext_acttopre & 0x2) << 24)
+			     | ((ext_acttorw & 0x1) << 22)
+			     | ((ext_refrec & 0x1F) << 16)
+			     | ((cas_latency & 0x3) << 12));
+}
+
+static void set_timing_cfg_1(struct fsl_ddr_cfg_regs_s *ddr,
+			     const struct common_timing_params_s *dimm,
+			     uint32_t cas_latency)
+{
+	uint32_t pretoact_mclk, acttopre_mclk, acttorw_mclk, refrec_ctrl,
+		 wrrec_mclk, acttoact_mclk, wrtord_mclk;
+	/* DDR_SDRAM_MODE doesn't support 9,11,13,15 */
+	static const u8 wrrec_table[] = {
+		1, 2, 3, 4, 5, 6, 7, 8, 10, 10, 12, 12, 14, 14, 0, 0
+	};
+
+	pretoact_mclk = picos_to_mclk(dimm->tRP_ps);
+	acttopre_mclk = picos_to_mclk(dimm->tRAS_ps);
+	acttorw_mclk = picos_to_mclk(dimm->tRCD_ps);
+
+	/*
+	 * Translate CAS Latency to a DDR controller field value:
+	 *
+	 *      CAS Lat DDR II  Ctrl
+	 *      Clocks  SPD Bit Value
+	 *      ------- ------- ------
+	 *      1.0             0001
+	 *      1.5             0010
+	 *      2.0     2       0011
+	 *      2.5             0100
+	 *      3.0     3       0101
+	 *      3.5             0110
+	 *      4.0     4       0111
+	 *      4.5             1000
+	 *      5.0     5       1001
+	 */
+	cas_latency = (cas_latency << 1) - 1;
+	refrec_ctrl = picos_to_mclk(dimm->tRFC_ps) - 8;
+	acttoact_mclk = picos_to_mclk(dimm->tRRD_ps);
+
+	wrrec_mclk = picos_to_mclk(dimm->tWR_ps);
+	if (wrrec_mclk <= 16)
+		wrrec_mclk = wrrec_table[wrrec_mclk - 1];
+
+	wrtord_mclk = picos_to_mclk(dimm->tWTR_ps);
+	if (wrtord_mclk < 2)
+		wrtord_mclk = 2;
+
+	ddr->timing_cfg_1 = (((pretoact_mclk & 0x0F) << 28)
+			     | ((acttopre_mclk & 0x0F) << 24)
+			     | ((acttorw_mclk & 0xF) << 20)
+			     | ((cas_latency & 0xF) << 16)
+			     | ((refrec_ctrl & 0xF) << 12)
+			     | ((wrrec_mclk & 0x0F) << 8)
+			     | ((acttoact_mclk & 0x0F) << 4)
+			     | ((wrtord_mclk & 0x0F) << 0));
+}
+
+static void set_timing_cfg_2(struct fsl_ddr_cfg_regs_s *ddr,
+			     const struct memctl_options_s *popts,
+			     const struct common_timing_params_s *dimm,
+			     uint32_t cas_latency, uint32_t additive_latency)
+{
+	uint32_t cpo, rd_to_pre, wr_data_delay, cke_pls, four_act;
+
+	cpo = popts->cpo_override;
+	rd_to_pre = picos_to_mclk(dimm->tRTP_ps);
+	if (rd_to_pre < 2)
+		rd_to_pre = 2;
+
+	if (additive_latency)
+		rd_to_pre += additive_latency;
+
+	wr_data_delay = popts->write_data_delay;
+	cke_pls = picos_to_mclk(popts->tCKE_clock_pulse_width_ps);
+	four_act = picos_to_mclk(popts->tFAW_window_four_activates_ps);
+
+	ddr->timing_cfg_2 = (((additive_latency & 0xf) << 28)
+			     | ((cpo & 0x1f) << 23)
+			     | (((cas_latency - 1) & 0xf) << 19)
+			     | ((rd_to_pre & 7) << 13)
+			     | ((wr_data_delay & 7) << 10)
+			     | ((cke_pls & 0x7) << 6)
+			     | ((four_act & 0x3f) << 0));
+}
+
+static void set_ddr_sdram_cfg(struct fsl_ddr_cfg_regs_s *ddr,
+			      const struct memctl_options_s *popts,
+			      const struct common_timing_params_s *dimm)
+{
+	uint32_t mem_en, sren, ecc_en, sdram_type, dyn_pwr, dbw, twoT_en, hse;
+
+	mem_en = 1;
+	sren = popts->self_refresh_in_sleep;
+	if (dimm->all_DIMMs_ECC_capable)
+		ecc_en = popts->ECC_mode;
+	else
+		ecc_en = 0;
+
+	if (popts->sdram_type)
+		sdram_type = popts->sdram_type;
+	else
+		sdram_type = FSL_SDRAM_TYPE;
+
+	twoT_en = popts->twoT_en;
+	dyn_pwr = popts->dynamic_power;
+	dbw = popts->data_bus_width;
+	hse = popts->half_strength_driver_enable;
+
+	ddr->ddr_sdram_cfg = (((mem_en & 0x1) << 31)
+			      | ((sren & 0x1) << 30)
+			      | ((ecc_en & 0x1) << 29)
+			      | ((sdram_type & 0x7) << 24)
+			      | ((dyn_pwr & 0x1) << 21)
+			      | ((dbw & 0x3) << 19)
+			      | ((twoT_en & 0x1) << 15)
+			      | ((hse & 0x1) << 3));
+}
+
+static void set_ddr_sdram_cfg_2(struct fsl_ddr_cfg_regs_s *ddr,
+				const struct memctl_options_s *popts)
+{
+	struct ddr_board_info_s *bi = popts->board_info;
+	uint32_t i, dll_rst_dis, dqs_cfg, odt_cfg = 0, num_pr, d_init = 0;
+
+	dll_rst_dis = popts->dll_rst_dis;
+	dqs_cfg = popts->DQS_config;
+
+	/*
+	 * Check for On-Die Termination options and
+	 * assert ODT only during reads to DRAM.
+	 */
+	for (i = 0; i < bi->cs_per_ctrl; i++)
+		if (popts->cs_local_opts[i].odt_rd_cfg ||
+				popts->cs_local_opts[i].odt_wr_cfg) {
+			odt_cfg = SDRAM_CFG2_ODT_ONLY_READ;
+			break;
+		}
+
+	/* Default number of posted refresh */
+	num_pr = 1;
+
+	if (popts->ECC_init_using_memctl) {
+		d_init = 1;
+		ddr->ddr_data_init = popts->data_init;
+	}
+
+	ddr->ddr_sdram_cfg_2 = (((dll_rst_dis & 0x1) << 29)
+				| ((dqs_cfg & 0x3) << 26)
+				| ((odt_cfg & 0x3) << 21)
+				| ((num_pr & 0xf) << 12)
+				| ((d_init & 0x1) << 4));
+}
+
+static void
+set_ddr_sdram_interval(struct fsl_ddr_cfg_regs_s *ddr,
+		const struct memctl_options_s *popts,
+		const struct common_timing_params_s *dimm)
+{
+	uint32_t refint, bstopre;
+
+	refint = picos_to_mclk(dimm->refresh_rate_ps);
+	/* Precharge interval */
+	bstopre = popts->bstopre;
+
+	ddr->ddr_sdram_interval = (((refint & 0xFFFF) << 16)
+				   | ((bstopre & 0x3FFF) << 0));
+}
+
+static void set_ddr_sdram_mode(struct fsl_ddr_cfg_regs_s *ddr,
+			       const struct memctl_options_s *popts,
+			       const struct common_timing_params_s *dimm,
+			       uint32_t cas_latency,
+			       uint32_t additive_latency)
+{
+	uint16_t esdmode, sdmode;
+	uint32_t dqs_en, rtt, al, wr, bl;
+	const uint32_t mclk_ps = get_memory_clk_period_ps();
+
+	/* DQS# Enable: 0=enable, 1=disable */
+	dqs_en = !popts->DQS_config;
+	/* Posted CAS# additive latency (AL) */
+	al = additive_latency;
+	/* Internal Termination Resistor */
+	if (popts->rtt_override)
+		rtt = popts->rtt_override_value;
+	else
+		rtt = popts->cs_local_opts[0].odt_rtt_norm;
+
+	/*
+	 * Extended SDRAM mode.
+	 * The variable also selects:
+	 * - OCD set to exit mode
+	 * - all outputs bit i.e DQ, DQS, RDQS output enabled
+	 * - RDQS ball disabled
+	 * - DQS ball enabled
+	 * - DLL enabled
+	 * - Output drive strength: full strength.
+	 */
+	esdmode = (((dqs_en & 0x1) << 10)
+		   | ((rtt & 0x2) << 5)
+		   | ((al & 0x7) << 3)
+		   | ((rtt & 0x1) << 2));
+
+	/* Write recovery */
+	wr = (dimm->tWR_ps + mclk_ps - 1) / (mclk_ps - 1);
+
+	switch (popts->burst_length) {
+	case DDR_BL4:
+		bl = 2;
+		break;
+	case DDR_BL8:
+		bl = 3;
+		break;
+	default:
+		bl = 2;
+		break;
+	}
+
+	/* SDRAM mode
+	 * The variable also selects:
+	 * - power down mode: fast exit (normal)
+	 * - DLL reset disabled.
+	 * - burst type: sequential
+	 */
+	sdmode = (((wr & 0x7) << 9)
+		  | ((cas_latency & 0x7) << 4)
+		  | ((bl & 0x7) << 0));
+
+	ddr->ddr_sdram_mode = (((esdmode & 0xFFFF) << 16)
+			       | ((sdmode & 0xFFFF) << 0));
+}
+
+uint32_t check_fsl_memctl_config_regs(const struct fsl_ddr_cfg_regs_s *ddr)
+{
+	/*
+	 * DDR_SDRAM_CFG[RD_EN] and DDR_SDRAM_CFG[2T_EN should not
+	 * be set at the same time.
+	 */
+	if ((ddr->ddr_sdram_cfg & 0x10000000) &&
+			(ddr->ddr_sdram_cfg & 0x00008000))
+		return 1;
+
+	return 0;
+}
+
+uint32_t
+compute_fsl_memctl_config_regs(const struct memctl_options_s *popts,
+			       struct fsl_ddr_cfg_regs_s *ddr,
+			       const struct common_timing_params_s *dimm,
+			       const struct dimm_params_s *dimmp,
+			       uint32_t dbw_cap_adj)
+{
+	struct ddr_board_info_s *binfo = popts->board_info;
+	uint32_t cas_latency, additive_latency, i, cs_per_dimm,
+		 dimm_number;
+	uint64_t ea, sa, rank_density;
+
+	if (dimm == NULL)
+		return 1;
+
+	memset(ddr, 0, sizeof(struct fsl_ddr_cfg_regs_s));
+
+	/* Process overrides first.  */
+	if (popts->cas_latency_override)
+		cas_latency = popts->cas_latency_override_value;
+	else
+		cas_latency =  dimm->lowest_common_SPD_caslat;
+
+	if (popts->additive_latency_override)
+		additive_latency = popts->additive_latency_override_value;
+	else
+		additive_latency = dimm->additive_latency;
+
+	/* Chip Select Memory Bounds (CSn_BNDS) */
+	for (i = 0; i < binfo->cs_per_ctrl; i++) {
+		cs_per_dimm = binfo->cs_per_ctrl / binfo->dimm_slots_per_ctrl;
+		dimm_number = i / cs_per_dimm;
+		rank_density =
+			dimmp[dimm_number].rank_density >> dbw_cap_adj;
+
+		if (dimmp[dimm_number].n_ranks == 0)
+			continue;
+
+		sa = dimmp[dimm_number].base_address;
+		ea = sa + rank_density - 1;
+		if (dimmp[dimm_number].n_ranks > (i % cs_per_dimm)) {
+			sa += (i % cs_per_dimm) * rank_density;
+			ea += (i % cs_per_dimm) * rank_density;
+		} else {
+			sa = 0;
+			ea = 0;
+		}
+		sa >>= 24;
+		ea >>= 24;
+
+		ddr->cs[i].bnds = (((sa & 0xFFF) << 16) | ((ea & 0xFFF) << 0));
+		set_csn_config(dimm_number, i, ddr, popts, dimmp);
+	}
+
+	set_timing_cfg_0(ddr, popts);
+	set_timing_cfg_3(ddr, dimm, cas_latency);
+	set_timing_cfg_1(ddr, dimm, cas_latency);
+	set_timing_cfg_2(ddr, popts, dimm, cas_latency, additive_latency);
+	set_ddr_sdram_cfg(ddr, popts, dimm);
+	set_ddr_sdram_cfg_2(ddr, popts);
+	set_ddr_sdram_mode(ddr, popts, dimm, cas_latency, additive_latency);
+	set_ddr_sdram_interval(ddr, popts, dimm);
+
+	ddr->ddr_data_init = popts->data_init;
+	ddr->ddr_sdram_clk_cntl = (popts->clk_adjust & 0xF) << 23;
+
+	return check_fsl_memctl_config_regs(ddr);
+}
-- 
1.7.1



From renaud.barbier at ge.com  Tue Jun 25 06:45:37 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 11:45:37 +0100
Subject: [PATCH 8/8] ppc 85xx: early I2C support
In-Reply-To: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372157137-7602-9-git-send-email-renaud.barbier@ge.com>

Early I2C support is introduced to read SPD data from memory
modules prior to the loading of the I2C driver.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/mach-mpc85xx/fsl_i2c.c              |  253 ++++++++++++++++++++++++++
 arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h |   18 ++
 2 files changed, 271 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/mach-mpc85xx/fsl_i2c.c
 create mode 100644 arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h

diff --git a/arch/ppc/mach-mpc85xx/fsl_i2c.c b/arch/ppc/mach-mpc85xx/fsl_i2c.c
new file mode 100644
index 0000000..51fcc64
--- /dev/null
+++ b/arch/ppc/mach-mpc85xx/fsl_i2c.c
@@ -0,0 +1,253 @@
+/*
+ * Copyright 2013 GE Intelligent Platforms, Inc
+ * Copyright 2006,2009 Freescale Semiconductor, Inc.
+ *
+ * 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.
+ *
+ * Early I2C support functions to read SPD data or board
+ * information.
+ * Based on U-Boot drivers/i2c/fsl_i2c.c
+ */
+#include <common.h>
+#include <i2c/i2c.h>
+#include <mach/clock.h>
+#include <mach/immap_85xx.h>
+#include <mach/early_udelay.h>
+
+/* FSL I2C registers */
+#define FSL_I2C_ADR	0x00
+#define FSL_I2C_FDR	0x04
+#define FSL_I2C_CR	0x08
+#define FSL_I2C_SR	0x0C
+#define FSL_I2C_DR	0x10
+#define FSL_I2C_DFSRR	0x14
+
+/* Bits of FSL I2C registers */
+#define I2C_SR_RXAK	0x01
+#define I2C_SR_MIF	0x02
+#define I2C_SR_MAL	0x10
+#define I2C_SR_MBB	0x20
+#define I2C_SR_MCF	0x80
+#define I2C_CR_RSTA	0x04
+#define I2C_CR_TXAK	0x08
+#define I2C_CR_MTX	0x10
+#define I2C_CR_MSTA	0x20
+#define I2C_CR_MEN	0x80
+
+/*
+ * Set the I2C bus speed for a given I2C device
+ *
+ * parameters:
+ * - i2c: the I2C base address.
+ * - i2c_clk: I2C bus clock frequency.
+ * - speed: the desired speed of the bus.
+ *
+ * The I2C device must be stopped before calling this function.
+ *
+ * The return value is the actual bus speed that is set.
+ */
+static uint32_t fsl_set_i2c_bus_speed(const void __iomem *i2c,
+		uint32_t i2c_clk, uint32_t speed)
+{
+	uint8_t dfsr, fdr = 0x31; /* Default if no FDR found */
+	uint16_t a, b, ga, gb, bin_gb, bin_ga, divider;
+	uint32_t c_div, est_div;
+
+	divider = min((uint16_t)(i2c_clk / speed), (uint16_t) -1);
+	/* Condition 1: dfsr <= 50/T */
+	dfsr = (5 * (i2c_clk / 1000)) / 100000;
+	if (!dfsr)
+		dfsr = 1;
+	est_div = ~0;
+
+	/*
+	 * Bus speed is calculated as per Freescale AN2919.
+	 * a, b and dfsr matches identifiers A,B and C as in the
+	 * application note.
+	 */
+	for (ga = 0x4, a = 10; a <= 30; ga++, a += 2) {
+		for (gb = 0; gb < 8; gb++) {
+			b = 16 << gb;
+			c_div = b * (a + (((3 * dfsr) / b) * 2));
+
+			if ((c_div > divider) && (c_div < est_div)) {
+				est_div = c_div;
+				bin_gb = gb << 2;
+				bin_ga = (ga & 0x3) | ((ga & 0x4) << 3);
+				fdr = bin_gb | bin_ga;
+				speed = i2c_clk / est_div;
+			}
+		}
+		if (a == 20)
+			a += 2;
+		if (a == 24)
+			a += 4;
+	}
+	writeb(dfsr, i2c + FSL_I2C_DFSRR);	/* set default filter */
+	writeb(fdr, i2c + FSL_I2C_FDR);		/* set bus speed */
+
+	return speed;
+}
+
+void fsl_i2c_init(void __iomem *i2c, int speed, int slaveadd)
+{
+	uint32_t i2c_clk;
+
+	i2c_clk =  fsl_get_i2c_freq();
+	writeb(0, i2c + FSL_I2C_CR);
+	early_udelay(5);
+
+	fsl_set_i2c_bus_speed(i2c, i2c_clk, speed);
+	writeb(slaveadd << 1, i2c + FSL_I2C_ADR);
+	writeb(0x0, i2c + FSL_I2C_SR);
+	writeb(I2C_CR_MEN, i2c + FSL_I2C_CR);
+}
+
+static uint32_t fsl_usec2ticks(uint32_t usec)
+{
+	ulong ticks;
+
+	if (usec < 1000) {
+		ticks = (usec * (fsl_get_timebase_clock() / 1000));
+		ticks = (ticks + 500) / 1000;
+	} else {
+		ticks = (usec / 10);
+		ticks *= (fsl_get_timebase_clock() / 100000);
+	}
+
+	return ticks;
+}
+
+static int fsl_i2c_wait4bus(void __iomem *i2c)
+{
+	uint64_t timeval = get_ticks();
+	const uint64_t timeout = fsl_usec2ticks(20000);
+
+	while (readb(i2c + FSL_I2C_SR) & I2C_SR_MBB)
+		if ((get_ticks() - timeval) > timeout)
+			return -1;
+
+	return 0;
+}
+
+void fsl_i2c_stop(void __iomem *i2c)
+{
+	writeb(I2C_CR_MEN, i2c + FSL_I2C_CR);
+}
+
+static int fsl_i2c_wait(void __iomem *i2c, int write)
+{
+	const uint64_t timeout = fsl_usec2ticks(100000);
+	uint64_t timeval = get_ticks();
+	int csr;
+
+	do {
+		csr = readb(i2c + FSL_I2C_SR);
+		if (csr & I2C_SR_MIF)
+			break;
+	} while ((get_ticks() - timeval) < timeout);
+
+	if ((get_ticks() - timeval) > timeout)
+		goto error;
+
+	csr = readb(i2c + FSL_I2C_SR);
+	writeb(0x0, i2c + FSL_I2C_SR);
+
+	if (csr & I2C_SR_MAL)
+		goto error;
+
+	if (!(csr & I2C_SR_MCF))
+		goto error;
+
+	if (write == 0 && (csr & I2C_SR_RXAK))
+		goto error;
+
+	return 0;
+error:
+	return -1;
+}
+
+static int __i2c_write(void __iomem *i2c, uint8_t *data, int length)
+{
+	int i;
+
+	for (i = 0; i < length; i++) {
+		writeb(data[i], i2c + FSL_I2C_DR);
+		if (fsl_i2c_wait(i2c, 0) < 0)
+			break;
+	}
+
+	return i;
+}
+
+static int __i2c_read(void __iomem *i2c, uint8_t *data, int length)
+{
+	int i;
+	uint8_t val = I2C_CR_MEN | I2C_CR_MSTA;
+
+	if (length == 1)
+		writeb(val | I2C_CR_TXAK, i2c + FSL_I2C_CR);
+	else
+		writeb(val, i2c + FSL_I2C_CR);
+
+	readb(i2c + FSL_I2C_DR);
+	for (i = 0; i < length; i++) {
+		if (fsl_i2c_wait(i2c, 1) < 0)
+			break;
+
+		/* Generate ack on last next to last byte */
+		if (i == length - 2)
+			writeb(val | I2C_CR_TXAK, i2c + FSL_I2C_CR);
+		/* Do not generate stop on last byte */
+		if (i == length - 1)
+			writeb(val | I2C_CR_MTX, i2c + FSL_I2C_CR);
+
+		data[i] = readb(i2c + FSL_I2C_DR);
+	}
+
+	return i;
+}
+
+static int
+fsl_i2c_write_addr(void __iomem *i2c, uint8_t dev, uint8_t dir, int rsta)
+{
+	uint8_t val = I2C_CR_MEN | I2C_CR_MSTA | I2C_CR_MTX;
+
+	if (rsta)
+		val |= I2C_CR_RSTA;
+	writeb(val, i2c + FSL_I2C_CR);
+	writeb((dev << 1) | dir, i2c + FSL_I2C_DR);
+
+	if (fsl_i2c_wait(i2c, 0) < 0)
+		return 0;
+
+	return 1;
+}
+
+int fsl_i2c_read(void __iomem *i2c, uint8_t dev, uint addr, int alen,
+			uint8_t *data, int length)
+{
+	int i = -1;
+	uint8_t *a = (uint8_t *)&addr;
+
+	if (alen && (fsl_i2c_wait4bus(i2c) >= 0) &&
+		(fsl_i2c_write_addr(i2c, dev, 0, 0) != 0) &&
+		(__i2c_write(i2c, &a[4 - alen], alen) == alen))
+		i = 0;
+
+	if (length && fsl_i2c_write_addr(i2c, dev, 1, 1) != 0)
+		i = __i2c_read(i2c, data, length);
+
+	if (i == length)
+		return 0;
+
+	return -1;
+}
diff --git a/arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h b/arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h
new file mode 100644
index 0000000..acf4cc7
--- /dev/null
+++ b/arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2013 GE Intelligent Platforms, Inc
+ *
+ * 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.
+ */
+void fsl_i2c_init(void __iomem *i2c, int speed, int slaveadd);
+int fsl_i2c_read(void __iomem *i2c, uint8_t dev, uint addr, int alen,
+		uint8_t *data, int length);
+void fsl_i2c_stop(void __iomem *i2c);
+
-- 
1.7.1



From renaud.barbier at ge.com  Tue Jun 25 06:45:36 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 11:45:36 +0100
Subject: [PATCH 7/8] ppc 8xxx: core DDR driver functions
In-Reply-To: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372157137-7602-8-git-send-email-renaud.barbier@ge.com>

These files are the driver interface to handle the memory
initialisation from reading the SPD data to writing the memory
controller registers.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/ddr2_setctrl.c |   58 +++++++++
 arch/ppc/ddr-8xxx/main.c         |  238 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 296 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/ddr2_setctrl.c
 create mode 100644 arch/ppc/ddr-8xxx/main.c

diff --git a/arch/ppc/ddr-8xxx/ddr2_setctrl.c b/arch/ppc/ddr-8xxx/ddr2_setctrl.c
new file mode 100644
index 0000000..14571b0
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/ddr2_setctrl.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <config.h>
+#include <asm/io.h>
+#include <asm/fsl_ddr_sdram.h>
+#include <mach/early_udelay.h>
+#include "ddr.h"
+
+int fsl_ddr_set_memctl_regs(const struct fsl_ddr_info_s *info)
+{
+	uint32_t i;
+	void __iomem *ddr;
+	const struct fsl_ddr_cfg_regs_s *regs;
+
+	regs = &info->fsl_ddr_config_reg;
+	ddr = info->board_info.ddr_base;
+
+	if (in_be32(ddr + DDR_OFF(SDRAM_CFG)) & SDRAM_CFG_MEM_EN)
+		return 0;
+
+	for (i = 0; i < info->board_info.cs_per_ctrl; i++) {
+		out_be32(ddr + DDR_OFF(CS0_BNDS) + (i << 3), regs->cs[i].bnds);
+		out_be32(ddr + DDR_OFF(CS0_CONFIG) + (i << 2),
+				regs->cs[i].config);
+	}
+
+	out_be32(ddr + DDR_OFF(TIMING_CFG_3), regs->timing_cfg_3);
+	out_be32(ddr + DDR_OFF(TIMING_CFG_0), regs->timing_cfg_0);
+	out_be32(ddr + DDR_OFF(TIMING_CFG_1), regs->timing_cfg_1);
+	out_be32(ddr + DDR_OFF(TIMING_CFG_2), regs->timing_cfg_2);
+	out_be32(ddr + DDR_OFF(SDRAM_CFG_2), regs->ddr_sdram_cfg_2);
+	out_be32(ddr + DDR_OFF(SDRAM_MODE), regs->ddr_sdram_mode);
+	out_be32(ddr + DDR_OFF(SDRAM_MODE_2), regs->ddr_sdram_mode_2);
+	out_be32(ddr + DDR_OFF(SDRAM_MD_CNTL), regs->ddr_sdram_md_cntl);
+	out_be32(ddr + DDR_OFF(SDRAM_INTERVAL), regs->ddr_sdram_interval);
+	out_be32(ddr + DDR_OFF(SDRAM_DATA_INIT), regs->ddr_data_init);
+	out_be32(ddr + DDR_OFF(SDRAM_CLK_CNTL), regs->ddr_sdram_clk_cntl);
+	out_be32(ddr + DDR_OFF(SDRAM_INIT_ADDR), regs->ddr_init_addr);
+	out_be32(ddr + DDR_OFF(SDRAM_INIT_ADDR_EXT), regs->ddr_init_ext_addr);
+
+	early_udelay(200);
+	asm volatile("sync;isync");
+
+	out_be32(ddr + DDR_OFF(SDRAM_CFG), regs->ddr_sdram_cfg);
+
+	/* Poll DDR_SDRAM_CFG_2[D_INIT] bit until auto-data init is done.  */
+	while (in_be32(ddr + DDR_OFF(SDRAM_CFG_2)) & SDRAM_CFG2_D_INIT)
+		early_udelay(10000);
+
+	return 0;
+}
diff --git a/arch/ppc/ddr-8xxx/main.c b/arch/ppc/ddr-8xxx/main.c
new file mode 100644
index 0000000..6e4a02d
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/main.c
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2008-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+/*
+ * Generic driver for Freescale DDR2 memory controller.
+ * Based on code from spd_sdram.c
+ * Author: James Yang [at freescale.com]
+ */
+
+#include <common.h>
+#include <config.h>
+#include <asm/fsl_law.h>
+#include "ddr.h"
+
+static int get_spd(generic_spd_eeprom_t *spd,
+		      struct ddr_board_info_s *bi, u8 i2c_address)
+{
+	int ret;
+
+	fsl_i2c_init(bi->i2c_base, bi->i2c_speed, bi->i2c_slave);
+	ret = fsl_i2c_read(bi->i2c_base, i2c_address, 0, 1, (uchar *) spd,
+			sizeof(generic_spd_eeprom_t));
+	fsl_i2c_stop(bi->i2c_base);
+
+	return ret;
+}
+
+int fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
+		struct ddr_board_info_s *binfo)
+{
+	uint32_t i;
+	uint8_t i2c_address;
+
+	for (i = 0; i < binfo->dimm_slots_per_ctrl; i++) {
+		if (binfo->spd_i2c_addr == NULL)
+			goto error;
+		i2c_address = binfo->spd_i2c_addr[i];
+		if (get_spd(&(ctrl_dimms_spd[i]), binfo, i2c_address))
+				goto error;
+	}
+
+	return 0;
+error:
+	return 1;
+}
+
+static uint64_t step_assign_addresses(struct fsl_ddr_info_s *pinfo,
+		uint32_t dbw_cap_adj)
+{
+	uint64_t total_mem, current_mem_base, total_ctlr_mem, cap;
+	uint32_t ndimm, dw, j, found = 0;
+
+	ndimm = pinfo->board_info.dimm_slots_per_ctrl;
+	/*
+	 * If a reduced data width is requested, but the SPD
+	 * specifies a physically wider device, adjust the
+	 * computed dimm capacities accordingly before
+	 * assigning addresses.
+	 */
+	switch (pinfo->memctl_opts.data_bus_width) {
+	case 2:
+		/* 16-bit */
+		for (j = 0; j < ndimm; j++) {
+			if (!pinfo->dimm_params[j].n_ranks)
+				continue;
+			dw = pinfo->dimm_params[j].primary_sdram_width;
+			if ((dw == 72 || dw == 64)) {
+				dbw_cap_adj = 2;
+				break;
+			} else if ((dw == 40 || dw == 32)) {
+				dbw_cap_adj = 1;
+				break;
+			}
+		}
+		break;
+	case 1:
+		/* 32-bit */
+		for (j = 0; j < ndimm; j++) {
+			dw = pinfo->dimm_params[j].data_width;
+			if (pinfo->dimm_params[j].n_ranks
+			    && (dw == 72 || dw == 64)) {
+				/*
+				 * FIXME: can't really do it
+				 * like this because this just
+				 * further reduces the memory
+				 */
+				found = 1;
+				break;
+			}
+		}
+		if (found)
+			dbw_cap_adj = 1;
+		break;
+	case 0:
+		/* 64-bit */
+		break;
+	default:
+		return 1;
+	}
+
+	current_mem_base = 0ull;
+	total_mem = 0;
+	total_ctlr_mem = 0;
+	pinfo->common_timing_params.base_address = current_mem_base;
+
+	for (j = 0; j < ndimm; j++) {
+		cap = pinfo->dimm_params[j].capacity >> dbw_cap_adj;
+		pinfo->dimm_params[j].base_address = current_mem_base;
+		current_mem_base += cap;
+		total_ctlr_mem += cap;
+
+	}
+
+	pinfo->common_timing_params.total_mem = total_ctlr_mem;
+	total_mem += total_ctlr_mem;
+
+	return total_mem;
+}
+
+static uint32_t retrieve_max_size(struct fsl_ddr_cfg_regs_s *ddr_reg,
+				uint32_t ncs)
+{
+	uint32_t max_end = 0, end, i;
+
+	for (i = 0; i < ncs; i++)
+		if (ddr_reg->cs[i].config & 0x80000000) {
+			end = ddr_reg->cs[i].bnds & 0xFFF;
+			if (end > max_end)
+				max_end = end;
+		}
+
+	return max_end;
+}
+
+static uint32_t compute_dimm_param(struct fsl_ddr_info_s *pinfo, uint32_t ndimm)
+{
+	struct dimm_params_s *pdimm;
+	generic_spd_eeprom_t *spd;
+	uint32_t i, retval;
+
+	for (i = 0; i < ndimm; i++) {
+		spd = &(pinfo->spd_installed_dimms[i]);
+		pdimm = &(pinfo->dimm_params[i]);
+
+		retval = compute_dimm_parameters(spd, pdimm);
+
+		if (retval == 2) /* Fatal error */
+			return 1;
+	}
+
+	return 0;
+}
+
+uint64_t fsl_ddr_compute(struct fsl_ddr_info_s *pinfo)
+{
+	uint64_t total_mem = 0;
+	uint32_t ncs, ndimm, max_end = 0;
+	struct fsl_ddr_cfg_regs_s *ddr_reg;
+	struct common_timing_params_s *timing_params;
+	/* data bus width capacity adjust shift amount */
+	uint32_t dbw_capacity_adjust;
+
+	ddr_reg = &pinfo->fsl_ddr_config_reg;
+	timing_params = &pinfo->common_timing_params;
+	ncs = pinfo->board_info.cs_per_ctrl;
+	ndimm = pinfo->board_info.dimm_slots_per_ctrl;
+	dbw_capacity_adjust = 0;
+	pinfo->memctl_opts.board_info = &pinfo->board_info;
+
+	/* STEP 1:  Gather all DIMM SPD data */
+	if (fsl_ddr_get_spd(pinfo->spd_installed_dimms,
+			pinfo->memctl_opts.board_info))
+		return 0;
+
+	/* STEP 2:  Compute DIMM parameters from SPD data */
+	if (compute_dimm_param(pinfo, ndimm))
+		return 0;
+
+	/*
+	 * STEP 3: Compute a common set of timing parameters
+	 * suitable for all of the DIMMs on each memory controller
+	 */
+	compute_lowest_common_dimm_parameters(pinfo->dimm_params,
+			timing_params, ndimm);
+
+	/* STEP 4:  Gather configuration requirements from user */
+	populate_memctl_options(timing_params->all_DIMMs_registered,
+			&pinfo->memctl_opts,
+			pinfo->dimm_params);
+
+	/* STEP 5:  Assign addresses to chip selects */
+	total_mem = step_assign_addresses(pinfo, dbw_capacity_adjust);
+
+	/* STEP 6:  compute controller register values */
+	if (timing_params->ndimms_present == 0)
+		memset(ddr_reg, 0, sizeof(struct fsl_ddr_cfg_regs_s));
+
+	compute_fsl_memctl_config_regs(&pinfo->memctl_opts,
+				       ddr_reg, timing_params,
+				       pinfo->dimm_params,
+				       dbw_capacity_adjust);
+
+	max_end = retrieve_max_size(ddr_reg, ncs);
+	total_mem = 1 + (((uint64_t)max_end << 24ULL) | 0xFFFFFFULL);
+
+	return total_mem;
+}
+
+/*
+ * fsl_ddr_sdram():
+ * This is the main function to initialize the memory.
+ *
+ * It returns amount of memory configured in bytes.
+ */
+phys_size_t fsl_ddr_sdram(void)
+{
+	uint64_t total_memory;
+	struct fsl_ddr_info_s info;
+
+	memset(&info, 0, sizeof(struct fsl_ddr_info_s));
+	/* Gather board information on the  memory controller and I2C bus. */
+	fsl_ddr_board_info(&info.board_info);
+
+	total_memory = fsl_ddr_compute(&info);
+
+	if (info.common_timing_params.ndimms_present == 0)
+		return 0;
+
+	fsl_ddr_set_memctl_regs(&info);
+	fsl_ddr_set_lawbar(&info.common_timing_params, LAW_TRGT_IF_DDR_1);
+
+	return total_memory;
+}
-- 
1.7.1



From sebastian.hesselbarth at gmail.com  Tue Jun 25 08:55:37 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 14:55:37 +0200
Subject: [PATCH 4/9] OF: import bus/device related functions from Linux
 OF API
In-Reply-To: <1372152047-28134-5-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-5-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <51C99349.1010207@gmail.com>

On 06/25/13 11:20, Sebastian Hesselbarth wrote:
> This imports some bus and device related functions from Linux OF API
> with some modifcations for Barebox.
>
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: barebox at lists.infradead.org
> ---
>   drivers/of/Makefile   |    2 +-
>   drivers/of/platform.c |  294 +++++++++++++++++++++++++++++++++++++++++++++++++
>   include/of.h          |   18 +++
>   3 files changed, 313 insertions(+), 1 deletions(-)
>   create mode 100644 drivers/of/platform.c
[...]
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> new file mode 100644
> index 0000000..450d770
> --- /dev/null
> +++ b/drivers/of/platform.c
> @@ -0,0 +1,294 @@
> +/*
> + * platform.c - bus/device related devicetree functions
> + *
> + * Copyright (c) 2012 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
> + *
> + * based on Linux devicetree support
> + *
> + * 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 version 2
> + * as published by the Free Software Foundation.
> + *
> + * 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.
> + */
[...]
> +/**
> + * of_platform_device_create - Alloc, initialize and register an of_device
> + * @np: pointer to node to create device for
> + * @parent: device model parent device.
> + *
> + * Returns pointer to created platform device, or NULL if a device was not
> + * registered. Unavailable devices will not get registered.
> + */
> +static struct device_d *of_platform_device_create(struct device_node *np,
> +						struct device_d *parent)
> +{
> +	struct device_d *dev;
> +	struct resource *res, temp_res;
> +	int i, ret, num_reg = 0;
> +
> +	if (!of_device_is_available(np))
> +		return NULL;
> +
> +	dev = xzalloc(sizeof(*dev));
> +
> +	/* setup generic device info */
> +	dev->id = DEVICE_ID_SINGLE;
> +	dev->device_node = np;
> +	dev->parent = parent;
> +	of_device_make_bus_id(dev);
> +
> +	/* count the io resources */
> +	if (of_can_translate_address(np))
> +		while (of_address_to_resource(np, num_reg, &temp_res) == 0)
> +			num_reg++;
> +
> +	/* Populate the resource table */
> +	if (num_reg) {
> +		res = xzalloc(sizeof(*res) * num_reg);
> +
> +		dev->num_resources = num_reg;
> +		dev->resource = res;
> +		for (i = 0; i < num_reg; i++, res++) {
> +			ret = of_address_to_resource(np, i, res);
> +			if (ret)
> +				goto err_free;
> +		}
> +	}
> +
> +	debug("register device 0x%08x\n", (num_reg) ? dev->resource[0].start : (-1));
> +
> +	ret = platform_device_register(dev);
> +	if (ret)
> +		goto err_free;
> +
> +	return dev;
> +
> +err_free:
> +	free(dev);
> +	return NULL;
> +}

of_platform_device_create is missing a check for already existing
devices. I have added a check that tries to match all mem resources
of the node with existing devices.

[...]
> +/**
> + * of_platform_populate() - Populate platform_devices from device tree data
> + * @root: parent of the first level to probe or NULL for the root of the tree
> + * @matches: match table, NULL to use the default
> + * @lookup: auxdata table for matching id and platform_data with device nodes

Removed the line above, as lookup auxdata is not used on barebox.

Sebastian


From renaud.barbier at ge.com  Tue Jun 25 09:09:58 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 14:09:58 +0100
Subject: [PATCH v2 0/2] gianfar: prevent resource conflict
In-Reply-To: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
References: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372165800-18759-1-git-send-email-renaud.barbier@ge.com>

This patch v2 avoids resource conflicts between the gianfar port
instances by substituting dev_request_mem_region for
dev_get_mem_region.

In addition, it separates the MDIO buses from their Ethernet device
by creating MDIO bus devices to access the external bus and TBI
interfaces.

This patch is tested on the P2020RDB for which there are 3 MDIO buses:
- The main MDIO bus "gfar-mdio", linked to port eTSEC1 is used to
  connect external PHYs for all ports and map the internal TBI
  interface of eTSEC1.
- The MDIO buses "gfar-tpiphy" map TBI interface registers on all
  remaining ports.

Renaud Barbier (2):
  ppc: gianfar MDIO buses
  P2020RDB: update build configuration

 arch/ppc/boards/freescale-p2020rdb/p2020rdb.c |   13 ++-
 arch/ppc/configs/p2020rdb_defconfig           |    4 +-
 arch/ppc/mach-mpc85xx/eth-devices.c           |   44 +++++---
 arch/ppc/mach-mpc85xx/include/mach/gianfar.h  |    4 +
 drivers/net/gianfar.c                         |  146 +++++++++++++++++++------
 drivers/net/gianfar.h                         |   13 ++-
 6 files changed, 165 insertions(+), 59 deletions(-)



From renaud.barbier at ge.com  Tue Jun 25 09:10:00 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 14:10:00 +0100
Subject: [PATCH 2/2] P2020RDB: update build configuration
In-Reply-To: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
References: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372165800-18759-3-git-send-email-renaud.barbier@ge.com>

Update the P2020RDB build configuration to enable useful development
commands.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/configs/p2020rdb_defconfig |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/arch/ppc/configs/p2020rdb_defconfig b/arch/ppc/configs/p2020rdb_defconfig
index 7690327..0f77903 100644
--- a/arch/ppc/configs/p2020rdb_defconfig
+++ b/arch/ppc/configs/p2020rdb_defconfig
@@ -24,9 +24,11 @@ CONFIG_RELOCATABLE=y
 CONFIG_DRIVER_NET_GIANFAR=y
 CONFIG_NET=y
 CONFIG_NET_PING=y
+CONFIG_FS_TFTP=y
 CONFIG_NET_TFTP=y
+CONFIG_CMD_TFTP=y
 CONFIG_PING=y
-CONFIG_TFTP=y
 CONFIG_I2C=y
 CONFIG_I2C_IMX=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_MIITOOL=y
-- 
1.7.1



From renaud.barbier at ge.com  Tue Jun 25 09:09:59 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Tue, 25 Jun 2013 14:09:59 +0100
Subject: [PATCH 1/2] ppc: gianfar MDIO buses
In-Reply-To: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
References: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372165800-18759-2-git-send-email-renaud.barbier@ge.com>

This commit creates MDIO bus devices to separate the MDIO bus
abstraction from the Ethernet device initialisation.

It also updates the configuration of the P2020RDB ports.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/boards/freescale-p2020rdb/p2020rdb.c |   13 ++-
 arch/ppc/mach-mpc85xx/eth-devices.c           |   44 +++++---
 arch/ppc/mach-mpc85xx/include/mach/gianfar.h  |    4 +
 drivers/net/gianfar.c                         |  146 +++++++++++++++++++------
 drivers/net/gianfar.h                         |   13 ++-
 5 files changed, 162 insertions(+), 58 deletions(-)

diff --git a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
index edb9bcd..6426bd3 100644
--- a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
+++ b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
@@ -59,12 +59,19 @@
 #define SYSCLK_50	50000000
 #define SYSCLK_100	100000000
 
-/* Ethernet. Use eTSEC3 */
+/* Define attributes for eTSEC2 and eTSEC3 */
 static struct gfar_info_struct gfar_info[] = {
 	{
+		.phyaddr = 0,
+		.tbiana = 0x1a0,
+		.tbicr = 0x9140,
+		.mdiobus_tbi = 1,
+	},
+	{
 		.phyaddr = 1,
 		.tbiana = 0,
 		.tbicr = 0,
+		.mdiobus_tbi = 2,
 	},
 };
 
@@ -82,8 +89,8 @@ static int devices_init(void)
 	add_generic_device("i2c-fsl", 1, NULL, I2C2_BASE_ADDR,
 			0x100, IORESOURCE_MEM, &i2cplat);
 
-	/* eTSEC3 */
-	fsl_eth_init(3, &gfar_info[0]);
+	fsl_eth_init(2, &gfar_info[0]);
+	fsl_eth_init(3, &gfar_info[1]);
 
 	devfs_add_partition("nor0", 0xf80000, 0x80000, DEVFS_PARTITION_FIXED,
 			    "self0");
diff --git a/arch/ppc/mach-mpc85xx/eth-devices.c b/arch/ppc/mach-mpc85xx/eth-devices.c
index c6e8f36..611a578 100644
--- a/arch/ppc/mach-mpc85xx/eth-devices.c
+++ b/arch/ppc/mach-mpc85xx/eth-devices.c
@@ -22,28 +22,40 @@
 
 #include <common.h>
 #include <driver.h>
+#include <init.h>
 #include <mach/immap_85xx.h>
 #include <mach/gianfar.h>
 
-int fsl_eth_init(int num, struct gfar_info_struct *gf)
+static int fsl_phy_init(void)
 {
-	struct resource *res;
+	int i;
+	void __iomem *base  = IOMEM(GFAR_BASE_ADDR + GFAR_TBIPA_OFFSET);
+
+	/*
+	 * The TBI address must be initialised to enable the PHY to
+	 * link up after the MDIO reset.
+	 */
+	out_be32(base, GFAR_TBIPA_END);
+	/* All ports access external PHYs via the "gfar-mdio" device */
+	add_generic_device("gfar-mdio", 0, NULL, MDIO_BASE_ADDR,
+			0x1000, IORESOURCE_MEM, NULL);
 
-	res = xzalloc(3 * sizeof(struct resource));
-	/* TSEC interface registers */
-	res[0].start = GFAR_BASE_ADDR + ((num - 1) * 0x1000);
-	res[0].end = res[0].start + 0x1000 - 1;
-	res[0].flags = IORESOURCE_MEM;
-	/* External PHY access always through eTSEC1 */
-	res[1].start = MDIO_BASE_ADDR;
-	res[1].end = res[1].start + 0x1000 - 1;
-	res[1].flags = IORESOURCE_MEM;
-	/* Access to TBI/RTBI interface. */
-	res[2].start = MDIO_BASE_ADDR + ((num - 1) * 0x1000);
-	res[2].end = res[2].start + 0x1000 - 1;
-	res[2].flags = IORESOURCE_MEM;
+	for (i = 1; i < 3; i++) {
+		out_be32(base + (i * 0x1000), GFAR_TBIPA_END - i);
+		/* Use "gfar-tbiphy" devices to access internal PHY. */
+		add_generic_device("gfar-tbiphy", i, NULL,
+				MDIO_BASE_ADDR + (i * 0x1000),
+				0x1000, IORESOURCE_MEM, NULL);
+	}
+	return 0;
+}
 
-	add_generic_device_res("gfar", DEVICE_ID_DYNAMIC, res, 3, gf);
+coredevice_initcall(fsl_phy_init);
 
+int fsl_eth_init(int num, struct gfar_info_struct *gf)
+{
+	add_generic_device("gfar", DEVICE_ID_DYNAMIC, NULL,
+			GFAR_BASE_ADDR + ((num - 1) * 0x1000), 0x1000,
+			IORESOURCE_MEM, gf);
 	return 0;
 }
diff --git a/arch/ppc/mach-mpc85xx/include/mach/gianfar.h b/arch/ppc/mach-mpc85xx/include/mach/gianfar.h
index ae31638..6a7b9e9 100644
--- a/arch/ppc/mach-mpc85xx/include/mach/gianfar.h
+++ b/arch/ppc/mach-mpc85xx/include/mach/gianfar.h
@@ -22,10 +22,14 @@
  * Platform data for the Motorola Triple Speed Ethernet Controller
  */
 
+#define GFAR_TBIPA_OFFSET       0x030   /* TBI PHY address */
+#define GFAR_TBIPA_END		0x1f    /* Last valid PHY address */
+
 struct gfar_info_struct {
 	unsigned int phyaddr;
 	unsigned int tbiana;
 	unsigned int tbicr;
+	unsigned int mdiobus_tbi;
 };
 
 int fsl_eth_init(int num, struct gfar_info_struct *gf);
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index 96055bd..f944c6c 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -184,10 +184,11 @@ static int gfar_open(struct eth_device *edev)
 {
 	int ix;
 	struct gfar_private *priv = edev->priv;
+	struct gfar_phy *phy = priv->gfar_mdio;
 	void __iomem *regs = priv->regs;
 	int ret;
 
-	ret = phy_device_connect(edev, &priv->miibus, priv->phyaddr,
+	ret = phy_device_connect(edev, &phy->miibus, priv->phyaddr,
 				 gfar_adjust_link, 0, PHY_INTERFACE_MODE_NA);
 	if (ret)
 		return ret;
@@ -305,44 +306,51 @@ static uint gfar_local_mdio_read(void __iomem *phyregs, uint phyid, uint regnum)
 
 static void gfar_configure_serdes(struct gfar_private *priv)
 {
-	gfar_local_mdio_write(priv->phyregs_sgmii,
+	struct gfar_phy *phy = priv->gfar_tbi;
+
+	gfar_local_mdio_write(phy->regs,
 			in_be32(priv->regs + GFAR_TBIPA_OFFSET), GFAR_TBI_ANA,
 			priv->tbiana);
-	gfar_local_mdio_write(priv->phyregs_sgmii,
+	gfar_local_mdio_write(phy->regs,
 			in_be32(priv->regs + GFAR_TBIPA_OFFSET),
 			GFAR_TBI_TBICON, GFAR_TBICON_CLK_SELECT);
-	gfar_local_mdio_write(priv->phyregs_sgmii,
+	gfar_local_mdio_write(phy->regs,
 			in_be32(priv->regs + GFAR_TBIPA_OFFSET), GFAR_TBI_CR,
 			priv->tbicr);
 }
 
-/* Reset the internal and external PHYs. */
-static void gfar_init_phy(struct eth_device *dev)
+static int gfar_bus_reset(struct mii_bus *bus)
 {
-	struct gfar_private *priv = dev->priv;
-	void __iomem *regs = priv->regs;
+	struct gfar_phy *phy = bus->priv;
 	uint64_t start;
 
-	/* Assign a Physical address to the TBI */
-	out_be32(regs + GFAR_TBIPA_OFFSET, GFAR_TBIPA_VALUE);
-
 	/* Reset MII (due to new addresses) */
-	out_be32(priv->phyregs + GFAR_MIIMCFG_OFFSET, GFAR_MIIMCFG_RESET);
-	out_be32(priv->phyregs + GFAR_MIIMCFG_OFFSET, GFAR_MIIMCFG_INIT_VALUE);
+	out_be32(phy->regs + GFAR_MIIMCFG_OFFSET, GFAR_MIIMCFG_RESET);
+	out_be32(phy->regs + GFAR_MIIMCFG_OFFSET, GFAR_MIIMCFG_INIT_VALUE);
 
 	start = get_time_ns();
 	while (!is_timeout(start, 10 * MSECOND)) {
-		if (!(in_be32(priv->phyregs + GFAR_MIIMMIND_OFFSET) &
+		if (!(in_be32(phy->regs + GFAR_MIIMMIND_OFFSET) &
 			GFAR_MIIMIND_BUSY))
 			break;
 	}
+	return 0;
+}
 
-	gfar_local_mdio_write(priv->phyregs, priv->phyaddr, GFAR_MIIM_CR,
+/* Reset the external PHYs. */
+static void gfar_init_phy(struct eth_device *dev)
+{
+	struct gfar_private *priv = dev->priv;
+	struct gfar_phy *phy = priv->gfar_mdio;
+	void __iomem *regs = priv->regs;
+	uint64_t start;
+
+	gfar_local_mdio_write(phy->regs, priv->phyaddr, GFAR_MIIM_CR,
 			GFAR_MIIM_CR_RST);
 
 	start = get_time_ns();
 	while (!is_timeout(start, 10 * MSECOND)) {
-		if (!(gfar_local_mdio_read(priv->phyregs, priv->phyaddr,
+		if (!(gfar_local_mdio_read(phy->regs, priv->phyaddr,
 					GFAR_MIIM_CR) & GFAR_MIIM_CR_RST))
 			break;
 	}
@@ -433,13 +441,12 @@ static int gfar_recv(struct eth_device *edev)
 /* Read a MII PHY register. */
 static int gfar_miiphy_read(struct mii_bus *bus, int addr, int reg)
 {
-	struct device_d *dev = bus->parent;
-	struct gfar_private *priv = bus->priv;
+	struct gfar_phy *phy = bus->priv;
 	int ret;
 
-	ret = gfar_local_mdio_read(priv->phyregs, addr, reg);
+	ret = gfar_local_mdio_read(phy->regs, addr, reg);
 	if (ret == -EIO)
-		dev_err(dev, "Can't read PHY at address %d\n", addr);
+		dev_err(phy->dev, "Can't read PHY at address %d\n", addr);
 
 	return ret;
 }
@@ -448,15 +455,14 @@ static int gfar_miiphy_read(struct mii_bus *bus, int addr, int reg)
 static int gfar_miiphy_write(struct mii_bus *bus, int addr, int reg,
 				u16 value)
 {
-	struct device_d *dev = bus->parent;
-	struct gfar_private *priv = bus->priv;
+	struct gfar_phy *phy = bus->priv;
 	unsigned short val = value;
 	int ret;
 
-	ret = gfar_local_mdio_write(priv->phyregs, addr, reg, val);
+	ret = gfar_local_mdio_write(phy->regs, addr, reg, val);
 
 	if (ret)
-		dev_err(dev, "Can't write PHY at address %d\n", addr);
+		dev_err(phy->dev, "Can't write PHY at address %d\n", addr);
 
 	return 0;
 }
@@ -470,7 +476,9 @@ static int gfar_probe(struct device_d *dev)
 	struct gfar_info_struct *gfar_info = dev->platform_data;
 	struct eth_device *edev;
 	struct gfar_private *priv;
+	struct device_d *mdev;
 	size_t size;
+	char devname[16];
 	char *p;
 
 	priv = xzalloc(sizeof(struct gfar_private));
@@ -480,14 +488,28 @@ static int gfar_probe(struct device_d *dev)
 
 	edev = &priv->edev;
 
-	priv->regs = dev_request_mem_region(dev, 0);
-	priv->phyregs = dev_request_mem_region(dev, 1);
-	priv->phyregs_sgmii = dev_request_mem_region(dev, 2);
-
+	priv->mdiobus_tbi = gfar_info->mdiobus_tbi;
+	priv->regs = dev_get_mem_region(dev, 0);
 	priv->phyaddr = gfar_info->phyaddr;
 	priv->tbicr = gfar_info->tbicr;
 	priv->tbiana = gfar_info->tbiana;
 
+	mdev = get_device_by_name("gfar-mdio0");
+	if (mdev == NULL) {
+		pr_err("gfar-mdio0 was not found\n");
+		return -ENODEV;
+	}
+	priv->gfar_mdio = mdev->priv;
+
+	if (priv->mdiobus_tbi != 0) {
+		sprintf(devname, "%s%d", "gfar-tbiphy", priv->mdiobus_tbi);
+		mdev = get_device_by_name(devname);
+		if (mdev == NULL) {
+			pr_err("%s was not found\n", devname);
+			return -ENODEV;
+		}
+	}
+	priv->gfar_tbi = mdev->priv;
 	/*
 	 * Allocate descriptors 64-bit aligned. Descriptors
 	 * are 8 bytes in size.
@@ -512,15 +534,8 @@ static int gfar_probe(struct device_d *dev)
 	udelay(2);
 	clrbits_be32(priv->regs + GFAR_MACCFG1_OFFSET, GFAR_MACCFG1_SOFT_RESET);
 
-	priv->miibus.read = gfar_miiphy_read;
-	priv->miibus.write = gfar_miiphy_write;
-	priv->miibus.priv = priv;
-	priv->miibus.parent = dev;
-
 	gfar_init_phy(edev);
 
-	mdiobus_register(&priv->miibus);
-
 	return eth_register(edev);
 }
 
@@ -529,3 +544,64 @@ static struct driver_d gfar_eth_driver = {
 	.probe = gfar_probe,
 };
 device_platform_driver(gfar_eth_driver);
+
+static int gfar_phy_probe(struct device_d *dev)
+{
+	struct gfar_phy *phy;
+	int ret;
+
+	phy = xzalloc(sizeof(*phy));
+	phy->dev = dev;
+	phy->regs = dev_get_mem_region(dev, 0);
+	if (!phy->regs)
+		return -ENOMEM;
+
+	phy->miibus.read = gfar_miiphy_read;
+	phy->miibus.write = gfar_miiphy_write;
+	phy->miibus.priv = phy;
+	phy->miibus.reset = gfar_bus_reset;
+	phy->miibus.parent = dev;
+	dev->priv = phy;
+
+	ret = mdiobus_register(&phy->miibus);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static struct driver_d gfar_phy_driver = {
+	.name  = "gfar-mdio",
+	.probe = gfar_phy_probe,
+};
+register_driver_macro(coredevice, platform, gfar_phy_driver);
+
+static int gfar_tbiphy_probe(struct device_d *dev)
+{
+	struct gfar_phy *phy;
+	int ret;
+
+	phy = xzalloc(sizeof(*phy));
+	phy->dev = dev;
+	phy->regs = dev_get_mem_region(dev, 0);
+	if (!phy->regs)
+		return -ENOMEM;
+
+	phy->miibus.read = gfar_miiphy_read;
+	phy->miibus.write = gfar_miiphy_write;
+	phy->miibus.priv = phy;
+	phy->miibus.parent = dev;
+	dev->priv = phy;
+
+	ret = mdiobus_register(&phy->miibus);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static struct driver_d gfar_tbiphy_driver = {
+	.name  = "gfar-tbiphy",
+	.probe = gfar_tbiphy_probe,
+};
+register_driver_macro(coredevice, platform, gfar_tbiphy_driver);
diff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h
index b52cc5a..1aac479 100644
--- a/drivers/net/gianfar.h
+++ b/drivers/net/gianfar.h
@@ -205,7 +205,6 @@ struct rxbd8 {
 #define GFAR_ECNTRL_OFFSET	0x020	/* Ethernet Control */
 #define GFAR_MINFLR_OFFSET	0x024	/* Minimum Frame Length */
 #define GFAR_DMACTRL_OFFSET	0x02c	/* DMA Control */
-#define GFAR_TBIPA_OFFSET	0x030	/* TBI PHY address */
 
 /* eTSEC transmit control and status register */
 #define GFAR_TSTAT_OFFSET	0x104	/* transmit status register */
@@ -263,13 +262,19 @@ struct rxbd8 {
 #define GFAR_ATTR_OFFSET	0xbf8	/* Default Attribute Register */
 #define GFAR_ATTRELI_OFFSET	0xbfc	/* Default Attribute Extract Len/Idx */
 
+struct gfar_phy {
+	void __iomem *regs;
+	struct device_d *dev;
+	struct mii_bus miibus;
+};
+
 struct gfar_private {
 	struct eth_device edev;
 	void __iomem *regs;
-	void __iomem *phyregs;
-	void __iomem *phyregs_sgmii;
+	int mdiobus_tbi;
+	struct gfar_phy *gfar_mdio;
+	struct gfar_phy *gfar_tbi;
 	struct phy_info *phyinfo;
-	struct mii_bus miibus;
 	volatile struct txbd8 *txbd;
 	volatile struct rxbd8 *rxbd;
 	uint txidx;
-- 
1.7.1



From s.hauer at pengutronix.de  Tue Jun 25 10:00:51 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 16:00:51 +0200
Subject: [PATCH] usb: gadget: fsl: Fix registering from chipidea driver
Message-ID: <1372168851-28501-1-git-send-email-s.hauer@pengutronix.de>

The fsl gadget driver wants to configure the portsc register
with information from platform_data. When registered from the
chipidea driver there is no platform_data. Fix the resulting
crash by not derefencing platform_data when NULL. In this
case the PORTSC register is not touched, it will have been
configured by the chipidea driver in this case.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/usb/gadget/fsl_udc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc.c b/drivers/usb/gadget/fsl_udc.c
index 81715f9..993c7eb 100644
--- a/drivers/usb/gadget/fsl_udc.c
+++ b/drivers/usb/gadget/fsl_udc.c
@@ -625,10 +625,13 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	case FSL_USB2_PHY_SERIAL:
 		portctrl |= PORTSCX_PTS_FSLS;
 		break;
+	case FSL_USB2_PHY_NONE:
+		break;
 	default:
 		return -EINVAL;
 	}
-	writel(portctrl, &dr_regs->portsc1);
+	if (udc->phy_mode != FSL_USB2_PHY_NONE)
+		writel(portctrl, &dr_regs->portsc1);
 
 	/* Stop and reset the usb controller */
 	tmp = readl(&dr_regs->usbcmd);
@@ -2077,7 +2080,10 @@ static int struct_udc_setup(struct fsl_udc *udc,
 	struct fsl_usb2_platform_data *pdata = dev->platform_data;
 	size_t size;
 
-	udc->phy_mode = pdata->phy_mode;
+	if (pdata)
+		udc->phy_mode = pdata->phy_mode;
+	else
+		udc->phy_mode = FSL_USB2_PHY_NONE;
 
 	udc->eps = kzalloc(sizeof(struct fsl_ep) * udc->max_ep, GFP_KERNEL);
 	if (!udc->eps) {
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 10:01:09 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 16:01:09 +0200
Subject: [PATCH 1/2] imx-usb-loader: Add i.MX6 Solo/DualLite support
Message-ID: <1372168870-3005-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 scripts/imx/imx-usb-loader.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/scripts/imx/imx-usb-loader.c b/scripts/imx/imx-usb-loader.c
index d58b1da..7ccfc99 100644
--- a/scripts/imx/imx-usb-loader.c
+++ b/scripts/imx/imx-usb-loader.c
@@ -92,7 +92,14 @@ struct mach_id imx_ids[] = {
 	}, {
 		.vid = 0x15a2,
 		.pid = 0x0054,
-		.name = "i.MX6",
+		.name = "i.MX6q",
+		.header_type = HDR_MX53,
+		.mode = MODE_HID,
+		.max_transfer = 1024,
+	},  {
+		.vid = 0x15a2,
+		.pid = 0x0061,
+		.name = "i.MX6dl/s",
 		.header_type = HDR_MX53,
 		.mode = MODE_HID,
 		.max_transfer = 1024,
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 10:01:10 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 16:01:10 +0200
Subject: [PATCH 2/2] pinctrl: imx-iomux-v3: Add imx6dl compatible entry
In-Reply-To: <1372168870-3005-1-git-send-email-s.hauer@pengutronix.de>
References: <1372168870-3005-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372168870-3005-2-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/pinctrl/imx-iomux-v3.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pinctrl/imx-iomux-v3.c b/drivers/pinctrl/imx-iomux-v3.c
index c867a23..1223c02 100644
--- a/drivers/pinctrl/imx-iomux-v3.c
+++ b/drivers/pinctrl/imx-iomux-v3.c
@@ -194,6 +194,8 @@ static __maybe_unused struct of_device_id imx_iomux_v3_dt_ids[] = {
 		.compatible = "fsl,imx53-iomuxc",
 	}, {
 		.compatible = "fsl,imx6q-iomuxc",
+	},  {
+		.compatible = "fsl,imx6dl-iomuxc",
 	}, {
 		/* sentinel */
 	}
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 10:05:40 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 16:05:40 +0200
Subject: [PATCH] ARM: i.MX6: Add cputype detection
Message-ID: <1372169140-9918-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/mach-imx/imx6.c              | 16 +++++++++++++++-
 arch/arm/mach-imx/include/mach/imx6.h | 31 +++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx6.c b/arch/arm/mach-imx/imx6.c
index 9e7dd7a..ed1edd7 100644
--- a/arch/arm/mach-imx/imx6.c
+++ b/arch/arm/mach-imx/imx6.c
@@ -15,6 +15,7 @@
 #include <common.h>
 #include <io.h>
 #include <sizes.h>
+#include <mach/imx6.h>
 #include <mach/generic.h>
 #include <mach/revision.h>
 #include <mach/imx6-regs.h>
@@ -59,6 +60,7 @@ void imx6_init_lowlevel(void)
 
 int imx6_init(void)
 {
+	const char *cputypestr;
 	u32 rev;
 	u32 mx6_silicon_revision;
 
@@ -82,7 +84,19 @@ int imx6_init(void)
 		mx6_silicon_revision = IMX_CHIP_REV_UNKNOWN;
 	}
 
-	imx_set_silicon_revision("i.MX6", mx6_silicon_revision);
+	switch (imx6_cpu_type()) {
+	case IMX6_CPUTYPE_IMX6Q:
+		cputypestr = "i.MX6 Dual/Quad";
+		break;
+	case IMX6_CPUTYPE_IMX6DL:
+		cputypestr = "i.MX6 Solo/DualLite";
+		break;
+	default:
+		cputypestr = "unknown i.MX6";
+		break;
+	}
+
+	imx_set_silicon_revision(cputypestr, mx6_silicon_revision);
 
 	return 0;
 }
diff --git a/arch/arm/mach-imx/include/mach/imx6.h b/arch/arm/mach-imx/include/mach/imx6.h
index 518cf98..4b2b1c7 100644
--- a/arch/arm/mach-imx/include/mach/imx6.h
+++ b/arch/arm/mach-imx/include/mach/imx6.h
@@ -1,6 +1,37 @@
 #ifndef __MACH_IMX6_H
 #define __MACH_IMX6_H
 
+#include <io.h>
+#include <mach/generic.h>
+#include <mach/imx6-regs.h>
+
 void imx6_init_lowlevel(void);
 
+#define IMX6_ANATOP_SI_REV 0x260
+
+#define IMX6_CPUTYPE_IMX6Q	0x63
+#define IMX6_CPUTYPE_IMX6DL	0x61
+
+static inline int imx6_cpu_type(void)
+{
+	uint32_t val;
+
+	if (!cpu_is_mx6())
+		return 0;
+
+	val = readl(MX6_ANATOP_BASE_ADDR + IMX6_ANATOP_SI_REV);
+
+	return (val >> 16) & 0xff;
+}
+
+static inline int cpu_is_mx6q(void)
+{
+	return imx6_cpu_type() == IMX6_CPUTYPE_IMX6Q;
+}
+
+static inline int cpu_is_mx6dl(void)
+{
+	return imx6_cpu_type() == IMX6_CPUTYPE_IMX6DL;
+}
+
 #endif /* __MACH_IMX6_H */
-- 
1.8.3.1



From philipp.zabel at gmail.com  Tue Jun 25 12:23:20 2013
From: philipp.zabel at gmail.com (Philipp Zabel)
Date: Tue, 25 Jun 2013 18:23:20 +0200
Subject: [PATCH] ARM: gk802: Add support for Zealz GK802
Message-ID: <1372177400-13502-1-git-send-email-philipp.zabel@gmail.com>

From: Philipp Zabel <ph5 at flow.hitronhub.home>

Add basic support for the GK802 'QUAD CORE Mini PC', which seems to be
loosely based on the Freescale i.MX6Q HDMI dongle reference design.
It is supposedly identical to the Hiapad Hi802.

Signed-off-by: Philipp Zabel <philipp.zabel at gmail.com>
---
 arch/arm/Makefile                         |   1 +
 arch/arm/boards/gk802/Makefile            |   3 +
 arch/arm/boards/gk802/board.c             |  72 +++++++++++++++
 arch/arm/boards/gk802/env/config-board    |   7 ++
 arch/arm/boards/gk802/flash-header.imxcfg |  96 +++++++++++++++++++
 arch/arm/boards/gk802/lowlevel.c          |  10 ++
 arch/arm/configs/gk802_defconfig          |  82 ++++++++++++++++
 arch/arm/dts/Makefile                     |   2 +-
 arch/arm/dts/imx6q-gk802.dts              | 149 ++++++++++++++++++++++++++++++
 arch/arm/mach-imx/Kconfig                 |   7 ++
 10 files changed, 428 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/boards/gk802/Makefile
 create mode 100644 arch/arm/boards/gk802/board.c
 create mode 100644 arch/arm/boards/gk802/env/config-board
 create mode 100644 arch/arm/boards/gk802/flash-header.imxcfg
 create mode 100644 arch/arm/boards/gk802/lowlevel.c
 create mode 100644 arch/arm/configs/gk802_defconfig
 create mode 100644 arch/arm/dts/imx6q-gk802.dts

diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 32bdd65..8e6520e 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -173,6 +173,7 @@ board-$(CONFIG_MACH_USB_A9G20)			+= usb-a926x
 board-$(CONFIG_MACH_VERSATILEPB)		+= versatile
 board-$(CONFIG_MACH_VEXPRESS)			+= vexpress
 board-$(CONFIG_MACH_ZEDBOARD)			+= avnet-zedboard
+board-$(CONFIG_MACH_GK802)			+= gk802
 
 machdirs := $(patsubst %,arch/arm/mach-%/,$(machine-y))
 
diff --git a/arch/arm/boards/gk802/Makefile b/arch/arm/boards/gk802/Makefile
new file mode 100644
index 0000000..f1baae2
--- /dev/null
+++ b/arch/arm/boards/gk802/Makefile
@@ -0,0 +1,3 @@
+obj-y += board.o flash-header.o
+extra-y += flash-header.S flash-header.dcd
+lwl-y += lowlevel.o
diff --git a/arch/arm/boards/gk802/board.c b/arch/arm/boards/gk802/board.c
new file mode 100644
index 0000000..59ae12c
--- /dev/null
+++ b/arch/arm/boards/gk802/board.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2013 Philipp Zabel
+ *
+ * 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.
+ */
+
+#include <asm/armlinux.h>
+#include <asm/io.h>
+#include <bootsource.h>
+#include <common.h>
+#include <environment.h>
+#include <gpio.h>
+#include <init.h>
+#include <mach/generic.h>
+#include <mach/imx6-regs.h>
+#include <mach/imx6.h>
+#include <mfd/imx6q-iomuxc-gpr.h>
+#include <sizes.h>
+
+#define GK802_GPIO_RECOVERY_BTN	IMX_GPIO_NR(3, 16)	/* recovery button */
+#define GK802_GPIO_RTL8192_PDN	IMX_GPIO_NR(2, 0)	/* RTL8192CU powerdown */
+
+static int gk802_mem_init(void)
+{
+	arm_add_mem_device("ram0", 0x10000000, SZ_1G);
+
+	return 0;
+}
+mem_initcall(gk802_mem_init);
+
+static int gk802_devices_init(void)
+{
+	/* Keep RTL8192CU disabled */
+	gpio_direction_output(GK802_GPIO_RTL8192_PDN, 1);
+
+	return 0;
+}
+device_initcall(gk802_devices_init);
+
+static int gk802_env_init(void)
+{
+	gpio_direction_input(GK802_GPIO_RECOVERY_BTN);
+	setenv("recovery", gpio_get_value(GK802_GPIO_RECOVERY_BTN) ? "0" : "1");
+
+	if (bootsource_get() == BOOTSOURCE_MMC &&
+	    bootsource_get_instance() == 3) {
+		if (!IS_ENABLED(CONFIG_MCI_STARTUP))
+			setenv("mmc3.probe", "1");
+		devfs_add_partition("mmc3", 0x00000, SZ_512K, DEVFS_PARTITION_FIXED, "self0");
+		devfs_add_partition("mmc3", SZ_512K, SZ_512K, DEVFS_PARTITION_FIXED, "env0");
+	}
+
+	return 0;
+}
+late_initcall(gk802_env_init);
+
+static int gk802_core_init(void)
+{
+	imx6_init_lowlevel();
+
+	return 0;
+}
+core_initcall(gk802_core_init);
+
diff --git a/arch/arm/boards/gk802/env/config-board b/arch/arm/boards/gk802/env/config-board
new file mode 100644
index 0000000..99540e9
--- /dev/null
+++ b/arch/arm/boards/gk802/env/config-board
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+# board defaults, do not change in running system. Change /env/config
+# instead
+
+global.hostname=gk802
+global.linux.bootargs.base="console=ttymxc3,115200"
diff --git a/arch/arm/boards/gk802/flash-header.imxcfg b/arch/arm/boards/gk802/flash-header.imxcfg
new file mode 100644
index 0000000..9638b02
--- /dev/null
+++ b/arch/arm/boards/gk802/flash-header.imxcfg
@@ -0,0 +1,96 @@
+loadaddr 0x10000000
+soc imx6
+dcdofs 0x400
+wm 32 0x020e05a8 0x00000030
+wm 32 0x020e05b0 0x00000030
+wm 32 0x020e0524 0x00000030
+wm 32 0x020e051c 0x00000030
+wm 32 0x020e0518 0x00000030
+wm 32 0x020e050c 0x00000030
+wm 32 0x020e05b8 0x00000030
+wm 32 0x020e05c0 0x00000030
+wm 32 0x020e05ac 0x00020030
+wm 32 0x020e05b4 0x00020030
+wm 32 0x020e0528 0x00020030
+wm 32 0x020e0520 0x00020030
+wm 32 0x020e0514 0x00020030
+wm 32 0x020e0510 0x00020030
+wm 32 0x020e05bc 0x00020030
+wm 32 0x020e05c4 0x00020030
+wm 32 0x020e056c 0x00020030
+wm 32 0x020e0578 0x00020030
+wm 32 0x020e0588 0x00020030
+wm 32 0x020e0594 0x00020030
+wm 32 0x020e057c 0x00020030
+wm 32 0x020e0590 0x00003000
+wm 32 0x020e0598 0x00003000
+wm 32 0x020e058c 0x00000000
+wm 32 0x020e059c 0x00003030
+wm 32 0x020e05a0 0x00003030
+wm 32 0x020e0784 0x00000030
+wm 32 0x020e0788 0x00000030
+wm 32 0x020e0794 0x00000030
+wm 32 0x020e079c 0x00000030
+wm 32 0x020e07a0 0x00000030
+wm 32 0x020e07a4 0x00000030
+wm 32 0x020e07a8 0x00000030
+wm 32 0x020e0748 0x00000030
+wm 32 0x020e074c 0x00000030
+wm 32 0x020e0750 0x00020000
+wm 32 0x020e0758 0x00000000
+wm 32 0x020e0774 0x00020000
+wm 32 0x020e078c 0x00000030
+wm 32 0x020e0798 0x000c0000
+wm 32 0x021b081c 0x33333333
+wm 32 0x021b0820 0x33333333
+wm 32 0x021b0824 0x33333333
+wm 32 0x021b0828 0x33333333
+wm 32 0x021b481c 0x33333333
+wm 32 0x021b4820 0x33333333
+wm 32 0x021b4824 0x33333333
+wm 32 0x021b4828 0x33333333
+wm 32 0x021b0018 0x00081740
+wm 32 0x021b001c 0x00008000
+wm 32 0x021b000c 0x555a7975
+wm 32 0x021b0010 0xff538e64
+wm 32 0x021b0014 0x01ff00db
+wm 32 0x021b002c 0x000026d2
+wm 32 0x021b0030 0x005b0e21
+wm 32 0x021b0008 0x09444040
+wm 32 0x021b0004 0x00025576
+wm 32 0x021b0040 0x00000027
+wm 32 0x021b0000 0x831a0000
+wm 32 0x021b001c 0x04088032
+wm 32 0x021b001c 0x0408803a
+wm 32 0x021b001c 0x00008033
+wm 32 0x021b001c 0x0000803b
+wm 32 0x021b001c 0x00428031
+wm 32 0x021b001c 0x00428039
+wm 32 0x021b001c 0x09408030
+wm 32 0x021b001c 0x09408038
+wm 32 0x021b001c 0x04008040
+wm 32 0x021b001c 0x04008048
+wm 32 0x021b0800 0xa1380003
+wm 32 0x021b4800 0xa1380003
+wm 32 0x021b0020 0x00005800
+wm 32 0x021b0818 0x00000007
+wm 32 0x021b4818 0x00000007
+wm 32 0x021b083c 0x427b030a
+wm 32 0x021b0840 0x02740269
+wm 32 0x021b483c 0x43100313
+wm 32 0x021b4840 0x027d024d
+wm 32 0x021b0848 0x46384240
+wm 32 0x021b4848 0x4442414a
+wm 32 0x021b0850 0x45444645
+wm 32 0x021b4850 0x4a354946
+wm 32 0x021b080c 0x001f001f
+wm 32 0x021b0810 0x001f001f
+wm 32 0x021b480c 0x00440044
+wm 32 0x021b4810 0x00440044
+wm 32 0x021b08b8 0x00000800
+wm 32 0x021b48b8 0x00000800
+wm 32 0x021b001c 0x00000000
+wm 32 0x021b0404 0x00011006
+wm 32 0x020e0010 0xf00000ff
+wm 32 0x020e0018 0x007f007f
+wm 32 0x020e001c 0x007f007f
diff --git a/arch/arm/boards/gk802/lowlevel.c b/arch/arm/boards/gk802/lowlevel.c
new file mode 100644
index 0000000..aec46fd
--- /dev/null
+++ b/arch/arm/boards/gk802/lowlevel.c
@@ -0,0 +1,10 @@
+#include <common.h>
+#include <sizes.h>
+#include <asm/barebox-arm-head.h>
+#include <asm/barebox-arm.h>
+
+void __naked barebox_arm_reset_vector(void)
+{
+	arm_cpu_lowlevel_init();
+	barebox_arm_entry(0x10000000, SZ_1G, 0);
+}
diff --git a/arch/arm/configs/gk802_defconfig b/arch/arm/configs/gk802_defconfig
new file mode 100644
index 0000000..9191079
--- /dev/null
+++ b/arch/arm/configs/gk802_defconfig
@@ -0,0 +1,82 @@
+CONFIG_BUILTIN_DTB=y
+CONFIG_BUILTIN_DTB_NAME="imx6q-gk802"
+CONFIG_ARCH_IMX=y
+CONFIG_ARCH_IMX6=y
+CONFIG_MACH_GK802=y
+CONFIG_IMX_IIM=y
+CONFIG_IMX_IIM_FUSE_BLOW=y
+CONFIG_THUMB2_BAREBOX=y
+CONFIG_CMD_ARM_MMUINFO=y
+CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
+CONFIG_ARM_UNWIND=y
+CONFIG_BAREBOX_UPDATE=y
+CONFIG_MMU=y
+CONFIG_MALLOC_SIZE=0x4000000
+CONFIG_MALLOC_TLSF=y
+CONFIG_KALLSYMS=y
+CONFIG_LONGHELP=y
+CONFIG_HUSH_FANCY_PROMPT=y
+CONFIG_CMDLINE_EDITING=y
+CONFIG_AUTO_COMPLETE=y
+CONFIG_MENU=y
+CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
+CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/gk802/env"
+CONFIG_CMD_EDIT=y
+CONFIG_CMD_SLEEP=y
+CONFIG_CMD_MSLEEP=y
+CONFIG_CMD_SAVEENV=y
+CONFIG_CMD_EXPORT=y
+CONFIG_CMD_READLINE=y
+CONFIG_CMD_MENU=y
+CONFIG_CMD_MENU_MANAGEMENT=y
+CONFIG_CMD_TIME=y
+CONFIG_CMD_BASENAME=y
+CONFIG_CMD_DIRNAME=y
+CONFIG_CMD_ECHO_E=y
+CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_IOMEM=y
+CONFIG_CMD_CRC=y
+CONFIG_CMD_CRC_CMP=y
+CONFIG_CMD_MD5SUM=y
+# CONFIG_CMD_FLASH is not set
+CONFIG_CMD_BOOTM_SHOW_TYPE=y
+CONFIG_CMD_BOOTM_VERBOSE=y
+CONFIG_CMD_BOOTM_INITRD=y
+CONFIG_CMD_BOOTM_OFTREE=y
+CONFIG_CMD_BOOTM_OFTREE_UIMAGE=y
+CONFIG_CMD_BOOTM_AIMAGE=y
+# CONFIG_CMD_BOOTZ is not set
+# CONFIG_CMD_BOOTU is not set
+CONFIG_CMD_RESET=y
+CONFIG_CMD_GO=y
+CONFIG_CMD_OFTREE=y
+CONFIG_CMD_OF_PROPERTY=y
+CONFIG_CMD_OF_NODE=y
+CONFIG_CMD_BAREBOX_UPDATE=y
+CONFIG_CMD_TIMEOUT=y
+CONFIG_CMD_PARTITION=y
+CONFIG_CMD_MAGICVAR=y
+CONFIG_CMD_MAGICVAR_HELP=y
+CONFIG_CMD_GPIO=y
+CONFIG_CMD_UNCOMPRESS=y
+CONFIG_CMD_I2C=y
+CONFIG_CMD_CLK=y
+CONFIG_CMD_DETECT=y
+CONFIG_OFDEVICE=y
+CONFIG_I2C=y
+CONFIG_I2C_IMX=y
+CONFIG_USB=y
+CONFIG_USB_IMX_CHIPIDEA=y
+CONFIG_USB_IMX_PHY=y
+CONFIG_USB_EHCI=y
+CONFIG_USB_STORAGE=y
+CONFIG_MCI=y
+CONFIG_MCI_IMX_ESDHC=y
+CONFIG_WATCHDOG=y
+CONFIG_WATCHDOG_IMX=y
+CONFIG_GPIO_GENERIC=y
+CONFIG_GPIO_GENERIC_PLATFORM=y
+CONFIG_FS_EXT4=y
+CONFIG_FS_FAT=y
+CONFIG_FS_FAT_LFN=y
+CONFIG_LZO_DECOMPRESS=y
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index fa6a330..305ddac 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1,6 +1,6 @@
 dtb-$(CONFIG_ARCH_IMX51) += imx51-babbage.dtb
 dtb-$(CONFIG_ARCH_IMX6) += imx6q-sabrelite.dtb \
-	imx6q-sabresd.dtb
+	imx6q-sabresd.dtb imx6q-gk802.dtb
 
 BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME))
 obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB).dtb.o
diff --git a/arch/arm/dts/imx6q-gk802.dts b/arch/arm/dts/imx6q-gk802.dts
new file mode 100644
index 0000000..4458217
--- /dev/null
+++ b/arch/arm/dts/imx6q-gk802.dts
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2013 Philipp Zabel
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2.  This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+/dts-v1/;
+#include "imx6q.dtsi"
+
+/ {
+	model = "Zealz GK802";
+	compatible = "zealz,gk802", "fsl,imx6q";
+
+	chosen {
+		linux,stdout-path = "/soc/aips-bus at 02100000/serial at 021f0000";
+	};
+
+	memory {
+		reg = <0x10000000 0x40000000>;
+	};
+
+	regulators {
+		compatible = "simple-bus";
+
+		reg_3p3v: 3p3v {
+			compatible = "regulator-fixed";
+			regulator-name = "3P3V";
+			regulator-min-microvolt = <3300000>;
+			regulator-max-microvolt = <3300000>;
+			regulator-always-on;
+		};
+	};
+
+	gpio-keys {
+		compatible = "gpio-keys";
+
+		recovery-button {
+			label = "recovery";
+			gpios = <&gpio3 16 1>;
+			linux,code = <0x198>; /* KEY_RESTART */
+			gpio-key,wakeup;
+		};
+	};
+};
+
+/* Internal I2C */
+&i2c2 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c2_gk802>;
+	clock-frequency = <100000>;
+	status = "okay";
+
+	/* SDMC DM2016 1024 bit EEPROM + 128 bit OTP */
+	eeprom: dm2016 at 51 {
+		compatible = "sdmc,dm2016";
+		reg = <0x51>;
+	};
+};
+
+/* External I2C via HDMI */
+&i2c3 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_i2c3_gk802>;
+	clock-frequency = <100000>;
+	status = "okay";
+};
+
+&iomuxc {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_hog>;
+
+	hog {
+		pinctrl_hog: hoggrp {
+			fsl,pins = <
+				/* Recovery button, active-low */
+				MX6Q_PAD_EIM_D16__GPIO3_IO16  0x100b1
+				/* RTL8192CU enable GPIO, active-low */
+				MX6Q_PAD_NANDF_D0__GPIO2_IO00 0x1b0b0
+			>;
+		};
+	};
+
+	i2c2 {
+		pinctrl_i2c2_gk802: i2c2grp-1 {
+			fsl,pins = <
+				MX6Q_PAD_KEY_COL3__I2C2_SCL 0x4001b8b1
+				MX6Q_PAD_KEY_ROW3__I2C2_SDA 0x4001b8b1
+			>;
+		};
+	};
+
+	i2c3 {
+		pinctrl_i2c3_gk802: i2c3grp-1 {
+			fsl,pins = <
+				MX6Q_PAD_GPIO_5__I2C3_SCL  0x4001b8b1
+				MX6Q_PAD_GPIO_16__I2C3_SDA 0x4001b8b1
+			>;
+		};
+	};
+};
+
+&uart2 {
+	status = "okay";
+};
+
+&uart4 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_uart4_1>;
+	status = "okay";
+};
+
+/* External USB-A port (USBOTG) */
+&usbotg {
+	phy-mode = "utmi";
+	dr_mode = "host";
+	barebox,phy_type = "utmi";
+	disable-over-current;
+	status = "okay";
+};
+
+/* Internal USB port (USBH1), connected to RTL8192CU */
+&usbh1 {
+	phy-mode = "utmi";
+	dr_mode = "host";
+	barebox,phy_type = "utmi";
+	disable-over-current;
+	status = "okay";
+};
+
+/* External microSD */
+&usdhc3 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_usdhc3_2>;
+	bus-width = <4>;
+	cd-gpios = <&gpio6 11 0>;
+	vmmc-supply = <&reg_3p3v>;
+	status = "okay";
+};
+
+/* Internal microSD */
+&usdhc4 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&pinctrl_usdhc4_2>;
+	bus-width = <4>;
+	vmmc-supply = <&reg_3p3v>;
+	status = "okay";
+};
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index b13fa99..9cc1b23 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -32,6 +32,7 @@ config ARCH_TEXT_BASE
 	default 0x97f00000 if MACH_EFIKA_MX_SMARTBOOK
 	default 0x17800000 if MACH_SABRESD
 	default 0x4fc00000 if MACH_REALQ7
+	default 0x4fc00000 if MACH_GK802
 
 config BOARDINFO
 	default "Eukrea CPUIMX25" if MACH_EUKREA_CPUIMX25
@@ -63,6 +64,7 @@ config BOARDINFO
 	default "Garz+Fricke Vincell" if MACH_GUF_VINCELL
 	default "SabreSD" if MACH_SABRESD
 	default "DataModul i.MX6Q Real Qseven" if MACH_REALQ7
+	default "Zealz GK802" if MACH_GK802
 
 choice
 	prompt "Select boot mode"
@@ -529,6 +531,11 @@ config MACH_REALQ7
 	bool "DataModul i.MX6Q Real Qseven Board"
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 
+config MACH_GK802
+	bool "Zealz GK802 Mini PC"
+	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select ARCH_IMX_INTERNAL_BOOT_USE_IMXIMAGE
+
 endchoice
 
 endif
-- 
1.8.3.1



From s.hauer at pengutronix.de  Tue Jun 25 15:36:27 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 21:36:27 +0200
Subject: [PATCH 0/3] MIPS: pbl: add nmon MIPS nano-monitor
In-Reply-To: <1372101012-11666-1-git-send-email-antonynpavlov@gmail.com>
References: <1372101012-11666-1-git-send-email-antonynpavlov@gmail.com>
Message-ID: <20130625193627.GK32299@pengutronix.de>

On Mon, Jun 24, 2013 at 11:10:09PM +0400, Antony Pavlov wrote:
> nmon is a tiny monitor (<1200 bytes) program
> for the MIPS processors.
> It can operate with NO working RAM at all!
> It uses only the processor registers and NS16550-compatible
> UART port for operation, so it can be used for a memory
> controller setup code debugging.
> 
> With no changes nmon should work on different MIPS
> processors as it uses only common MIPS-I instructions.
> 
> [PATCH 1/3] MIPS: pbl: add nmon MIPS nano-monitor
> [PATCH 2/3] MIPS: qemu-malta: rework debug_ll.h
> [PATCH 3/3] MIPS: qemu-malta: add nmon

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Tue Jun 25 15:48:47 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Tue, 25 Jun 2013 21:48:47 +0200
Subject: [PATCH 8/9] OF: base: convert of_add_memory to OF API
In-Reply-To: <1372152047-28134-9-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-9-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130625194847.GL32299@pengutronix.de>

On Tue, Jun 25, 2013 at 11:20:46AM +0200, Sebastian Hesselbarth wrote:
> Convert of_add_memory parsing to make use of of_address_to_resource
> instead of parsing memory ranges itself. This makes some functions
> dead code which are also removed.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>

Haven't investigated further yet, but this one breaks my loco board
with:

mmu: Error: Can't request SDRAM region for ttb
prefetch abort
pc : [<00000004>]    lr : [<7ff20563>]
sp : 8fffff30  ip : 7ff20563  fp : 8fff4000
r10: 8fff4000  r9 : 00000000  r8 : 000298ec
r7 : 20000000  r6 : 7ff43e74  r5 : 7ff37824  r4 : 7ff37824
r3 : 7ff205a1  r2 : 00000000  r1 : ffffffff  r0 : 00000000
Flags: nzCv  IRQs off  FIQs off  Mode SVC_32
[<7ff20563>] (__mmu_cache_on+0xb/0x10) from [<7ff202d3>] (mmu_init+0x7b/0x1f4)
[<7ff202d3>] (mmu_init+0x7b/0x1f4) from [<7ff049f3>] (start_barebox+0x17/0xc4)
[<7ff049f3>] (start_barebox+0x17/0xc4) from [<7ff1ff09>] (__start+0x51/0x5c)
[<7ff1ff09>] (__start+0x51/0x5c) from [<7ff00005>] (__bare_init_start+0x1/0xc)

It looks like the memory cannot be found anymore.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Tue Jun 25 15:57:42 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 21:57:42 +0200
Subject: [PATCH 8/9] OF: base: convert of_add_memory to OF API
In-Reply-To: <20130625194847.GL32299@pengutronix.de>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-9-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130625194847.GL32299@pengutronix.de>
Message-ID: <51C9F636.6080805@gmail.com>

On 06/25/2013 09:48 PM, Sascha Hauer wrote:
> On Tue, Jun 25, 2013 at 11:20:46AM +0200, Sebastian Hesselbarth wrote:
>> Convert of_add_memory parsing to make use of of_address_to_resource
>> instead of parsing memory ranges itself. This makes some functions
>> dead code which are also removed.
>>
>> Signed-off-by: Sebastian Hesselbarth<sebastian.hesselbarth at gmail.com>
>
> Haven't investigated further yet, but this one breaks my loco board
> with:
>
> mmu: Error: Can't request SDRAM region for ttb
> prefetch abort
> pc : [<00000004>]    lr : [<7ff20563>]
> sp : 8fffff30  ip : 7ff20563  fp : 8fff4000
> r10: 8fff4000  r9 : 00000000  r8 : 000298ec
> r7 : 20000000  r6 : 7ff43e74  r5 : 7ff37824  r4 : 7ff37824
> r3 : 7ff205a1  r2 : 00000000  r1 : ffffffff  r0 : 00000000
> Flags: nzCv  IRQs off  FIQs off  Mode SVC_32
> [<7ff20563>] (__mmu_cache_on+0xb/0x10) from [<7ff202d3>] (mmu_init+0x7b/0x1f4)
> [<7ff202d3>] (mmu_init+0x7b/0x1f4) from [<7ff049f3>] (start_barebox+0x17/0xc4)
> [<7ff049f3>] (start_barebox+0x17/0xc4) from [<7ff1ff09>] (__start+0x51/0x5c)
> [<7ff1ff09>] (__start+0x51/0x5c) from [<7ff00005>] (__bare_init_start+0x1/0xc)
>
> It looks like the memory cannot be found anymore.

Ok, I just reworked Marvell Dove to boot from DT. I will have a look at
loco code to get an impression of how of_add_memory should be called
and add that to Dove. Maybe I can reproduce it there too.

Sebastian


From sebastian.hesselbarth at gmail.com  Tue Jun 25 17:38:41 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Tue, 25 Jun 2013 23:38:41 +0200
Subject: [PATCH 8/9] OF: base: convert of_add_memory to OF API
In-Reply-To: <20130625194847.GL32299@pengutronix.de>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-9-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130625194847.GL32299@pengutronix.de>
Message-ID: <51CA0DE1.30605@gmail.com>

On 06/25/2013 09:48 PM, Sascha Hauer wrote:
> On Tue, Jun 25, 2013 at 11:20:46AM +0200, Sebastian Hesselbarth wrote:
>> Convert of_add_memory parsing to make use of of_address_to_resource
>> instead of parsing memory ranges itself. This makes some functions
>> dead code which are also removed.
>>
>> Signed-off-by: Sebastian Hesselbarth<sebastian.hesselbarth at gmail.com>
>
> Haven't investigated further yet, but this one breaks my loco board
> with:

The check on the return value from of_address_to_resource in the while
loop is wrong and should be

while (!of_address_to_resource(...))

I'll update for a v2.

Sebastian



From s.hauer at pengutronix.de  Wed Jun 26 01:27:41 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 07:27:41 +0200
Subject: [PATCH] barebox multi image support
In-Reply-To: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372224463-13629-1-git-send-email-s.hauer@pengutronix.de>

Two patches missing in this series.

Sascha



From s.hauer at pengutronix.de  Wed Jun 26 01:27:42 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 07:27:42 +0200
Subject: [PATCH 1/2] ARM: Allow to pass a devicetree via boarddata
In-Reply-To: <1372224463-13629-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
 <1372224463-13629-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372224463-13629-2-git-send-email-s.hauer@pengutronix.de>

Addionally to having a builtin DTB provide the possibility for
the board to provide a dtb via boarddata.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/cpu/Makefile              |  2 +-
 arch/arm/cpu/dtb.c                 | 22 ++++++++++++++++++++--
 arch/arm/cpu/start.c               | 20 ++++++++++++++++++++
 arch/arm/include/asm/barebox-arm.h |  2 ++
 4 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
index c442b35..99973ae 100644
--- a/arch/arm/cpu/Makefile
+++ b/arch/arm/cpu/Makefile
@@ -8,7 +8,7 @@ obj-y += start.o setupc.o
 #
 obj-$(CONFIG_CMD_ARM_CPUINFO) += cpuinfo.o
 obj-$(CONFIG_CMD_ARM_MMUINFO) += mmuinfo.o
-obj-$(CONFIG_BUILTIN_DTB) += dtb.o
+obj-$(CONFIG_OFDEVICE) += dtb.o
 obj-$(CONFIG_MMU) += mmu.o cache.o mmu-early.o
 pbl-$(CONFIG_MMU) += cache.o mmu-early.o
 obj-$(CONFIG_CPU_32v4T) += cache-armv4.o
diff --git a/arch/arm/cpu/dtb.c b/arch/arm/cpu/dtb.c
index 10b73bd..a5881dd 100644
--- a/arch/arm/cpu/dtb.c
+++ b/arch/arm/cpu/dtb.c
@@ -17,20 +17,38 @@
 #include <common.h>
 #include <init.h>
 #include <of.h>
+#include <asm/barebox-arm.h>
 
 extern char __dtb_start[];
 
 static int of_arm_init(void)
 {
 	struct device_node *root;
+	void *fdt;
 
+	/* See if we already have a dtb */
 	root = of_get_root_node();
 	if (root)
 		return 0;
 
-	root = of_unflatten_dtb(NULL, __dtb_start);
-	if (root) {
+	/* See if we are provided a dtb in boarddata */
+	fdt = barebox_arm_boot_dtb();
+	if (fdt)
+		pr_debug("using boarddata provided DTB\n");
+
+	/* Next see if we have a builtin dtb */
+	if (!fdt && IS_ENABLED(CONFIG_BUILTIN_DTB)) {
+		fdt = __dtb_start;
 		pr_debug("using internal DTB\n");
+	}
+
+	if (!fdt) {
+		pr_debug("No DTB found\n");
+		return 0;
+	}
+
+	root = of_unflatten_dtb(NULL, fdt);
+	if (root) {
 		of_set_root_node(root);
 		if (IS_ENABLED(CONFIG_OFDEVICE))
 			of_probe();
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 5a3c629..1f397ec 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -24,6 +24,7 @@
 #include <asm/barebox-arm-head.h>
 #include <asm-generic/memory_layout.h>
 #include <asm/sections.h>
+#include <asm/unaligned.h>
 #include <asm/cache.h>
 #include <memory.h>
 
@@ -40,6 +41,13 @@ unsigned long barebox_arm_boarddata(void)
 	return barebox_boarddata;
 }
 
+static void *barebox_boot_dtb;
+
+void *barebox_arm_boot_dtb(void)
+{
+	return barebox_boot_dtb;
+}
+
 static noinline __noreturn void __start(uint32_t membase, uint32_t memsize,
 		uint32_t boarddata)
 {
@@ -66,6 +74,18 @@ static noinline __noreturn void __start(uint32_t membase, uint32_t memsize,
 			mmu_early_enable(membase, memsize, endmem);
 	}
 
+	/*
+	 * If boarddata is a pointer inside valid memory and contains a
+	 * FDT magic then use it as later to probe devices
+	 */
+	if (boarddata > membase && boarddata < membase + memsize &&
+			get_unaligned_be32((void *)boarddata) == FDT_MAGIC) {
+		uint32_t totalsize = get_unaligned_be32((void *)boarddata + 4);
+		endmem -= ALIGN(totalsize, 64);
+		barebox_boot_dtb = (void *)endmem;
+		memcpy(barebox_boot_dtb, (void *)boarddata, totalsize);
+	}
+
 	if ((unsigned long)_text > membase + memsize ||
 			(unsigned long)_text < membase)
 		/*
diff --git a/arch/arm/include/asm/barebox-arm.h b/arch/arm/include/asm/barebox-arm.h
index cd8decf..ddcafd1 100644
--- a/arch/arm/include/asm/barebox-arm.h
+++ b/arch/arm/include/asm/barebox-arm.h
@@ -54,6 +54,8 @@ static inline void arm_fixup_vectors(void)
 }
 #endif
 
+void *barebox_arm_boot_dtb(void);
+
 /*
  * For relocatable binaries find a suitable start address for the
  * relocated binary. Beginning at the memory end substract the reserved
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 01:27:43 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 07:27:43 +0200
Subject: [PATCH 2/2] ARM: dts: Add .S files as secondary target
In-Reply-To: <1372224463-13629-1-git-send-email-s.hauer@pengutronix.de>
References: <1372152052-5463-1-git-send-email-s.hauer@pengutronix.de>
 <1372224463-13629-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372224463-13629-3-git-send-email-s.hauer@pengutronix.de>

Oherwise they get removed during build and trigger a rebuild of
the image.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/dts/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index b271618..678f910 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -9,6 +9,7 @@ BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME))
 obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB).dtb.o
 
 .SECONDARY: $(obj)/$(BUILTIN_DTB).dtb.S
+.SECONDARY: $(patsubst %,$(obj)/%.S,$(dtb-y))
 
 targets += dtbs
 targets += $(dtb-y)
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 02:11:53 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 08:11:53 +0200
Subject: [PATCH 4/9] OF: import bus/device related functions from Linux
 OF API
In-Reply-To: <1372152047-28134-5-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-5-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130626061153.GM32299@pengutronix.de>

On Tue, Jun 25, 2013 at 11:20:42AM +0200, Sebastian Hesselbarth wrote:
> +struct device_d *of_find_device_by_node(struct device_node *np)
> +{
> +        struct device_d *dev;
> +
> +	for_each_device(dev)
> +		if (dev->device_node == np)
> +			return dev;
> +        return NULL;
> +}

There's some whitespace damage in this function.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 26 02:26:11 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 08:26:11 +0200
Subject: [PATCH 1/8] common: DDR2 SPD checksum.
In-Reply-To: <1372157137-7602-2-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
 <1372157137-7602-2-git-send-email-renaud.barbier@ge.com>
Message-ID: <20130626062611.GN32299@pengutronix.de>

Hi Renaud,

On Tue, Jun 25, 2013 at 11:45:30AM +0100, Renaud Barbier wrote:
> This commit adds support to calculate the DDR2 SPD checksum as per
> JEDEC standard No 21-C Appendix X (revision 1.2)

This code is from U-Boot. Please say so in the commit message, possibly
also which commit you used. Also for the other patches. Wolfgang once
complained about not doing so for code we used from U-Boot.

> +uint32_t ddr2_spd_check(const struct ddr2_spd_eeprom_s *spd)

The function name is a poor choice as it doesn't give a clue about its
return value. Does it return 'Yes, the check failed" or "Yes, the check
is ok"?. Please rename to something like ddr2_spd_checksum_ok.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 26 02:34:01 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 08:34:01 +0200
Subject: [PATCH v2 0/8] DDR2 memory initialisaion
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1370019244-7873-1-git-send-email-renaud.barbier@ge.com>
 <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <20130626063401.GO32299@pengutronix.de>

Hi Renaud,

On Tue, Jun 25, 2013 at 11:45:29AM +0100, Renaud Barbier wrote:
> This patch set adds memory initialisation through SPD data for
> Freescale CPUs such as the mpc8544. It is based on U-Boot tree id
> a71d45d706a5b51c34
> 
> Support for DDR1, DDR3 and memory interleaving has been removed as
> the code is aimed at the GEIP DA923RC board. Support for this
> board will be submitted after approval of these patches by the
> barebox community.
> 
> In addition, early I2C read access has been added so that the SPD
> data can be retrieved from the I2C eeprom.

This code won't win beauty prices. However, since my main concern
of having lots of board specific defines in common code are resolved
and this code only touches architecture stuff I should be fine with
it.

There's still a lot of room for improvements. I could probably review
this code to death, but I think we both have better things to do ;)

So let's go for it with the little comment fixed I made inline.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 26 02:44:53 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 08:44:53 +0200
Subject: [PATCH 1/2] ppc: gianfar MDIO buses
In-Reply-To: <1372165800-18759-2-git-send-email-renaud.barbier@ge.com>
References: <1369926935-24159-1-git-send-email-renaud.barbier@ge.com>
 <1372165800-18759-2-git-send-email-renaud.barbier@ge.com>
Message-ID: <20130626064453.GP32299@pengutronix.de>

On Tue, Jun 25, 2013 at 02:09:59PM +0100, Renaud Barbier wrote:
> This commit creates MDIO bus devices to separate the MDIO bus
> abstraction from the Ethernet device initialisation.
> 
> It also updates the configuration of the P2020RDB ports.
> 
> Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From plagnioj at jcrosoft.com  Wed Jun 26 03:11:34 2013
From: plagnioj at jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
Date: Wed, 26 Jun 2013 09:11:34 +0200
Subject: [PATCH 3/3] ARM: Turn most board directories into regular
 build directories
In-Reply-To: <20130624092038.GT32299@pengutronix.de>
References: <1372017777-787-1-git-send-email-s.hauer@pengutronix.de>
 <1372017777-787-4-git-send-email-s.hauer@pengutronix.de>
 <20130624083908.GJ27130@game.jcrosoft.org>
 <20130624092038.GT32299@pengutronix.de>
Message-ID: <20130626071134.GK27130@game.jcrosoft.org>

On 11:20 Mon 24 Jun     , Sascha Hauer wrote:
> On Mon, Jun 24, 2013 at 10:39:08AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 22:02 Sun 23 Jun     , Sascha Hauer wrote:
> > > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > 
> > Why you did not move all of them?
> 
> Because they have a board specific config.h file which is not
> found when $(BOARD) is empty.
> 
> Quoting my introductory mail:
> 
> > Jean-Christophe, I'd like to get rid of the remaining config.h
> > files. The bulk of the remaining ones are at91 and most of
> > them contain a single define for AT91_MAIN_CLK. Could you work
> > on this? I could do it myself but I'm sure you have your own
> > idea how this should be accomplished.

ok was not yet fully recovered

I need to cleanup this I agree

will do so

Best Regards,
J.
> 
> Sascha
> 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Wed Jun 26 03:33:14 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 09:33:14 +0200
Subject: [PATCH 2/4] ARM: i.MX51 efikasb: detect environment device
In-Reply-To: <1372231996-1042-1-git-send-email-s.hauer@pengutronix.de>
References: <1372231996-1042-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372231996-1042-3-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/efika-mx-smartbook/board.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/boards/efika-mx-smartbook/board.c b/arch/arm/boards/efika-mx-smartbook/board.c
index 11f222e..0e6694b 100644
--- a/arch/arm/boards/efika-mx-smartbook/board.c
+++ b/arch/arm/boards/efika-mx-smartbook/board.c
@@ -252,6 +252,8 @@ static int efikamx_late_init(void)
 
 	switch (bootsource) {
 	case BOOTSOURCE_MMC:
+		device_detect_by_name("mmc1");
+
 		devfs_add_partition("mmc1", 0x00000, 0x80000,
 				DEVFS_PARTITION_FIXED, "self0");
 		devfs_add_partition("mmc1", 0x80000, 0x80000,
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 03:33:15 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 09:33:15 +0200
Subject: [PATCH 3/4] ARM: i.MX51 babbage: detect environment device
In-Reply-To: <1372231996-1042-1-git-send-email-s.hauer@pengutronix.de>
References: <1372231996-1042-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372231996-1042-4-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx51-pdk/board.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index 6807796..fc7e175 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -181,6 +181,8 @@ device_initcall(f3s_devices_init);
 
 static int f3s_part_init(void)
 {
+	device_detect_by_name("mmc0");
+
 	devfs_add_partition("mmc0", 0x00000, 0x40000, DEVFS_PARTITION_FIXED, "self0");
 	devfs_add_partition("mmc0", 0x40000, 0x20000, DEVFS_PARTITION_FIXED, "env0");
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 03:33:12 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 09:33:12 +0200
Subject: [PATCH] detect environment device on some boards
Message-ID: <1372231996-1042-1-git-send-email-s.hauer@pengutronix.de>

Using 'detect' on the environment device allows us to disable
CONFIG_MCI_STARTUP. This speeds up the startup since unnecessary
SD/MMC cards are no longer probed.

Sascha

----------------------------------------------------------------
Sascha Hauer (4):
      driver: implement device_detect_by_name function
      ARM: i.MX51 efikasb: detect environment device
      ARM: i.MX51 babbage: detect environment device
      ARM: i.MX: use device_detect_by_name where applicable

 arch/arm/boards/dmo-mx6-realq7/board.c      |  6 +-----
 arch/arm/boards/efika-mx-smartbook/board.c  |  2 ++
 arch/arm/boards/freescale-mx51-pdk/board.c  |  2 ++
 arch/arm/boards/freescale-mx53-loco/board.c |  4 +---
 drivers/base/driver.c                       | 10 ++++++++++
 include/driver.h                            |  1 +
 6 files changed, 17 insertions(+), 8 deletions(-)


From s.hauer at pengutronix.de  Wed Jun 26 03:33:13 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 09:33:13 +0200
Subject: [PATCH 1/4] driver: implement device_detect_by_name function
In-Reply-To: <1372231996-1042-1-git-send-email-s.hauer@pengutronix.de>
References: <1372231996-1042-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372231996-1042-2-git-send-email-s.hauer@pengutronix.de>

It becomes a common pattern for boards to find a device and
call device_detect on it. Add a convenience wrapper for it.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/base/driver.c | 10 ++++++++++
 include/driver.h      |  1 +
 2 files changed, 11 insertions(+)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 810d001..16b7f06 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -100,6 +100,16 @@ int device_detect(struct device_d *dev)
 	return dev->detect(dev);
 }
 
+int device_detect_by_name(const char *devname)
+{
+	struct device_d *dev = get_device_by_name(devname);
+
+	if (!dev)
+		return -ENODEV;
+
+	return device_detect(dev);
+}
+
 static int match(struct driver_d *drv, struct device_d *dev)
 {
 	int ret;
diff --git a/include/driver.h b/include/driver.h
index 8b3af4d..b18318f 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -159,6 +159,7 @@ int device_probe(struct device_d *dev);
 
 /* detect devices attached to this device (cards, disks,...) */
 int device_detect(struct device_d *dev);
+int device_detect_by_name(const char *devname);
 
 /* Unregister a device. This function can fail, e.g. when the device
  * has children.
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 03:33:16 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 09:33:16 +0200
Subject: [PATCH 4/4] ARM: i.MX: use device_detect_by_name where applicable
In-Reply-To: <1372231996-1042-1-git-send-email-s.hauer@pengutronix.de>
References: <1372231996-1042-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372231996-1042-5-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/dmo-mx6-realq7/board.c      | 6 +-----
 arch/arm/boards/freescale-mx53-loco/board.c | 4 +---
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boards/dmo-mx6-realq7/board.c b/arch/arm/boards/dmo-mx6-realq7/board.c
index b2a27a4..7983b88 100644
--- a/arch/arm/boards/dmo-mx6-realq7/board.c
+++ b/arch/arm/boards/dmo-mx6-realq7/board.c
@@ -117,11 +117,7 @@ static int realq7_env_init(void)
 {
 	switch (bootsource_get()) {
 	case BOOTSOURCE_MMC:
-		if (!IS_ENABLED(CONFIG_MCI_STARTUP)) {
-			struct device_d *dev = get_device_by_name("mmc3");
-			if (dev)
-				device_detect(dev);
-		}
+		device_detect_by_name("mmc3");
 		devfs_add_partition("mmc3", 0, SZ_1M, DEVFS_PARTITION_FIXED, "mmc3.barebox");
 		devfs_add_partition("mmc3", SZ_1M, SZ_1M, DEVFS_PARTITION_FIXED, "mmc3.bareboxenv");
 		default_environment_path = "/dev/mmc3.bareboxenv";
diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c
index 2f51128..aaf5db4 100644
--- a/arch/arm/boards/freescale-mx53-loco/board.c
+++ b/arch/arm/boards/freescale-mx53-loco/board.c
@@ -81,12 +81,10 @@ static void loco_fec_reset(void)
 
 static int loco_late_init(void)
 {
-	struct device_d *dev = get_device_by_name("mmc0");
 	struct mc34708 *mc34708;
 	int rev;
 
-	if (dev)
-		device_detect(dev);
+	device_detect_by_name("mmc0");
 
 	devfs_add_partition("mmc0", 0x40000, 0x20000, DEVFS_PARTITION_FIXED, "env0");
 
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 04:00:52 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:52 +0200
Subject: [PATCH 06/11] ARM: i.MX53 loco: prepare multiboard support
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-7-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx53-loco/board.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c
index 446b7f3..3c8842c 100644
--- a/arch/arm/boards/freescale-mx53-loco/board.c
+++ b/arch/arm/boards/freescale-mx53-loco/board.c
@@ -83,6 +83,9 @@ static int loco_late_init(void)
 	struct mc34708 *mc34708;
 	int rev;
 
+	if (!of_machine_is_compatible("fsl,imx53-qsb"))
+		return 0;
+
 	device_detect_by_name("mmc0");
 
 	devfs_add_partition("mmc0", 0x40000, 0x20000, DEVFS_PARTITION_FIXED, "env0");
@@ -120,10 +123,13 @@ static int loco_late_init(void)
 }
 late_initcall(loco_late_init);
 
-static int loco_core_init(void)
+static int loco_postcore_init(void)
 {
+	if (!of_machine_is_compatible("fsl,imx53-qsb"))
+		return 0;
+
 	imx53_init_lowlevel(1000);
 
 	return 0;
 }
-core_initcall(loco_core_init);
+postcore_initcall(loco_postcore_init);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 04:00:57 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:57 +0200
Subject: [PATCH 11/11] ARM: Add a imx_v7_defconfig
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-12-git-send-email-s.hauer@pengutronix.de>

This is a nearly full-blown config for the v7 i.MX (i.MX51, i.MX53 and
i.MX6).

currently the following images are built:

 barebox-imx51-babbage.img
 barebox-imx53-loco.img
 barebox-imx6-realq7.img
 barebox-genesi-efikasb.img

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/imx_v7_defconfig | 131 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 arch/arm/configs/imx_v7_defconfig

diff --git a/arch/arm/configs/imx_v7_defconfig b/arch/arm/configs/imx_v7_defconfig
new file mode 100644
index 0000000..e088c2c
--- /dev/null
+++ b/arch/arm/configs/imx_v7_defconfig
@@ -0,0 +1,131 @@
+CONFIG_ARCH_IMX=y
+CONFIG_IMX_MULTI_BOARDS=y
+CONFIG_MACH_EFIKA_MX_SMARTBOOK=y
+CONFIG_MACH_FREESCALE_MX51_PDK=y
+CONFIG_MACH_FREESCALE_MX53_LOCO=y
+CONFIG_MACH_REALQ7=y
+CONFIG_IMX_IIM=y
+CONFIG_IMX_IIM_FUSE_BLOW=y
+CONFIG_THUMB2_BAREBOX=y
+CONFIG_CMD_ARM_MMUINFO=y
+CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
+CONFIG_ARM_UNWIND=y
+CONFIG_MMU=y
+CONFIG_TEXT_BASE=0x0
+CONFIG_MALLOC_SIZE=0x0
+CONFIG_MALLOC_TLSF=y
+CONFIG_KALLSYMS=y
+CONFIG_RELOCATABLE=y
+CONFIG_LONGHELP=y
+CONFIG_HUSH_FANCY_PROMPT=y
+CONFIG_CMDLINE_EDITING=y
+CONFIG_AUTO_COMPLETE=y
+CONFIG_MENU=y
+CONFIG_CONSOLE_ACTIVATE_NONE=y
+CONFIG_PARTITION_DISK_EFI=y
+CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
+CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/freescale-mx51-pdk/env/"
+CONFIG_RESET_SOURCE=y
+CONFIG_CMD_EDIT=y
+CONFIG_CMD_SLEEP=y
+CONFIG_CMD_MSLEEP=y
+CONFIG_CMD_SAVEENV=y
+CONFIG_CMD_EXPORT=y
+CONFIG_CMD_PRINTENV=y
+CONFIG_CMD_READLINE=y
+CONFIG_CMD_LET=y
+CONFIG_CMD_MENU=y
+CONFIG_CMD_MENU_MANAGEMENT=y
+CONFIG_CMD_TIME=y
+CONFIG_CMD_LN=y
+CONFIG_CMD_TFTP=y
+CONFIG_CMD_FILETYPE=y
+CONFIG_CMD_ECHO_E=y
+CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_IOMEM=y
+CONFIG_CMD_MM=y
+CONFIG_CMD_CRC=y
+CONFIG_CMD_CRC_CMP=y
+CONFIG_CMD_MD5SUM=y
+CONFIG_CMD_FLASH=y
+CONFIG_CMD_BOOTM_SHOW_TYPE=y
+CONFIG_CMD_BOOTM_VERBOSE=y
+CONFIG_CMD_BOOTM_INITRD=y
+CONFIG_CMD_BOOTM_OFTREE=y
+CONFIG_CMD_BOOTM_OFTREE_UIMAGE=y
+CONFIG_CMD_UIMAGE=y
+# CONFIG_CMD_BOOTU is not set
+CONFIG_CMD_RESET=y
+CONFIG_CMD_GO=y
+CONFIG_CMD_OFTREE=y
+CONFIG_CMD_OF_PROPERTY=y
+CONFIG_CMD_OF_NODE=y
+CONFIG_CMD_MEMTEST=y
+CONFIG_CMD_BAREBOX_UPDATE=y
+CONFIG_CMD_TIMEOUT=y
+CONFIG_CMD_PARTITION=y
+CONFIG_CMD_MAGICVAR=y
+CONFIG_CMD_MAGICVAR_HELP=y
+CONFIG_CMD_GPIO=y
+CONFIG_CMD_UNCOMPRESS=y
+CONFIG_CMD_I2C=y
+CONFIG_CMD_SPI=y
+CONFIG_CMD_LED=y
+CONFIG_CMD_LED_TRIGGER=y
+CONFIG_CMD_MIITOOL=y
+CONFIG_CMD_CLK=y
+CONFIG_CMD_DETECT=y
+CONFIG_CMD_WD=y
+CONFIG_NET=y
+CONFIG_NET_DHCP=y
+CONFIG_NET_PING=y
+CONFIG_NET_NETCONSOLE=y
+CONFIG_NET_RESOLV=y
+CONFIG_OFDEVICE=y
+CONFIG_DRIVER_NET_FEC_IMX=y
+CONFIG_NET_USB=y
+CONFIG_NET_USB_ASIX=y
+CONFIG_NET_USB_SMSC95XX=y
+CONFIG_DRIVER_SPI_IMX=y
+CONFIG_I2C=y
+CONFIG_I2C_IMX=y
+CONFIG_MTD=y
+CONFIG_MTD_RAW_DEVICE=y
+CONFIG_MTD_DATAFLASH=y
+CONFIG_MTD_M25P80=y
+CONFIG_MTD_SST25L=y
+CONFIG_DISK_AHCI=y
+CONFIG_DISK_AHCI_IMX=y
+CONFIG_DISK_INTF_PLATFORM_IDE=y
+CONFIG_DISK_PATA_IMX=y
+CONFIG_USB=y
+CONFIG_USB_IMX_CHIPIDEA=y
+CONFIG_USB_EHCI=y
+CONFIG_USB_ULPI=y
+CONFIG_USB_STORAGE=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_GADGET_DFU=y
+CONFIG_MCI=y
+CONFIG_MCI_MMC_BOOT_PARTITIONS=y
+CONFIG_MCI_IMX_ESDHC=y
+CONFIG_MFD_MC13XXX=y
+CONFIG_MFD_MC34704=y
+CONFIG_MFD_MC34708=y
+CONFIG_MFD_MC9SDZ60=y
+CONFIG_MFD_STMPE=y
+CONFIG_LED=y
+CONFIG_LED_GPIO=y
+CONFIG_LED_TRIGGERS=y
+CONFIG_EEPROM_AT25=y
+CONFIG_EEPROM_AT24=y
+CONFIG_KEYBOARD_GPIO=y
+CONFIG_WATCHDOG=y
+CONFIG_WATCHDOG_IMX=y
+CONFIG_GPIO_STMPE=y
+CONFIG_FS_EXT4=y
+CONFIG_FS_TFTP=y
+CONFIG_FS_NFS=y
+CONFIG_FS_FAT=y
+CONFIG_FS_FAT_WRITE=y
+CONFIG_FS_FAT_LFN=y
+CONFIG_LZO_DECOMPRESS=y
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 04:00:54 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:54 +0200
Subject: [PATCH 08/11] ARM: i.MX6 realq7: prepare multiboard support
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-9-git-send-email-s.hauer@pengutronix.de>

Protect initcalls with the corrent of compatible.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/dmo-mx6-realq7/board.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boards/dmo-mx6-realq7/board.c b/arch/arm/boards/dmo-mx6-realq7/board.c
index 7983b88..9cf6c31 100644
--- a/arch/arm/boards/dmo-mx6-realq7/board.c
+++ b/arch/arm/boards/dmo-mx6-realq7/board.c
@@ -81,6 +81,9 @@ static int ksz9031rn_phy_fixup(struct phy_device *dev)
 
 static int realq7_enet_init(void)
 {
+	if (!of_machine_is_compatible("dmo,imx6q-realq7"))
+		return 0;
+
 	mxc_iomux_v3_setup_multiple_pads(realq7_pads_gpio, ARRAY_SIZE(realq7_pads_gpio));
 	gpio_direction_output(RQ7_GPIO_ENET_PHYADD2, 0);
 	gpio_direction_output(RQ7_GPIO_ENET_MODE0, 1);
@@ -102,19 +105,16 @@ static int realq7_enet_init(void)
 }
 fs_initcall(realq7_enet_init);
 
-static int realq7_devices_init(void)
+static int realq7_env_init(void)
 {
+	if (!of_machine_is_compatible("dmo,imx6q-realq7"))
+		return 0;
+
 	imx6_bbu_internal_spi_i2c_register_handler("spiflash", "/dev/m25p0.barebox",
 		BBU_HANDLER_FLAG_DEFAULT, NULL, 0, 0x00907000);
 	imx6_bbu_internal_mmc_register_handler("mmc", "/dev/mmc3.barebox",
 		0, NULL, 0, 0x00907000);
 
-	return 0;
-}
-device_initcall(realq7_devices_init);
-
-static int realq7_env_init(void)
-{
 	switch (bootsource_get()) {
 	case BOOTSOURCE_MMC:
 		device_detect_by_name("mmc3");
@@ -136,8 +136,11 @@ late_initcall(realq7_env_init);
 
 static int realq7_console_init(void)
 {
+	if (!of_machine_is_compatible("dmo,imx6q-realq7"))
+		return 0;
+
 	imx6_init_lowlevel();
 
 	return 0;
 }
-core_initcall(realq7_console_init);
+postcore_initcall(realq7_console_init);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 04:00:49 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:49 +0200
Subject: [PATCH 03/11] ARM: i.MX51 babbage: prepare for multiboard support
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-4-git-send-email-s.hauer@pengutronix.de>

Merge two initcalls to one and add a protector for the board type.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx51-pdk/board.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index 3906e47..2e7be85 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -160,8 +160,11 @@ static void babbage_power_init(void)
 extern char flash_header_imx51_babbage_start[];
 extern char flash_header_imx51_babbage_end[];
 
-static int f3s_devices_init(void)
+static int imx51_babbage_late_init(void)
 {
+	if (!of_machine_is_compatible("fsl,imx51-babbage"))
+		return 0;
+
 	babbage_power_init();
 
 	console_flush();
@@ -175,13 +178,6 @@ static int f3s_devices_init(void)
 		BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_imx51_babbage_start,
 		flash_header_imx51_babbage_end - flash_header_imx51_babbage_start, 0);
 
-	return 0;
-}
-
-device_initcall(f3s_devices_init);
-
-static int f3s_part_init(void)
-{
 	device_detect_by_name("mmc0");
 
 	devfs_add_partition("mmc0", 0x00000, 0x40000, DEVFS_PARTITION_FIXED, "self0");
@@ -189,4 +185,4 @@ static int f3s_part_init(void)
 
 	return 0;
 }
-late_initcall(f3s_part_init);
+late_initcall(imx51_babbage_late_init);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 04:00:55 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:55 +0200
Subject: [PATCH 09/11] ARM: i.MX6 realq7: switch to multiboard
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-10-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/dmo-realq7_defconfig |  2 +-
 arch/arm/mach-imx/Kconfig             | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm/configs/dmo-realq7_defconfig b/arch/arm/configs/dmo-realq7_defconfig
index 1339391..ab8aa43 100644
--- a/arch/arm/configs/dmo-realq7_defconfig
+++ b/arch/arm/configs/dmo-realq7_defconfig
@@ -1,5 +1,5 @@
 CONFIG_ARCH_IMX=y
-CONFIG_ARCH_IMX6=y
+CONFIG_IMX_MULTI_BOARDS=y
 CONFIG_MACH_REALQ7=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index ed9ae3d..ccdebca 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -230,6 +230,12 @@ config MACH_FREESCALE_MX53_LOCO
 	bool "Freescale i.MX53 LOCO"
 	select ARCH_IMX53
 
+config MACH_REALQ7
+	bool "DataModul i.MX6Q Real Qseven Board"
+	select ARCH_IMX6
+	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select HAVE_PBL_MULTI_IMAGES
+
 endif
 
 # ----------------------------------------------------------
@@ -477,12 +483,6 @@ config MACH_SABRESD
 	bool "Freescale i.MX6 SabreSD"
 	select ARCH_IMX6
 
-config MACH_REALQ7
-	bool "DataModul i.MX6Q Real Qseven Board"
-	select ARCH_IMX6
-	select HAVE_DEFAULT_ENVIRONMENT_NEW
-	select HAVE_PBL_MULTI_IMAGES
-
 endchoice
 
 # ----------------------------------------------------------
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Wed Jun 26 04:23:59 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 26 Jun 2013 10:23:59 +0200
Subject: [PATCH 4/9] OF: import bus/device related functions from Linux
 OF API
In-Reply-To: <20130626061153.GM32299@pengutronix.de>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-5-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130626061153.GM32299@pengutronix.de>
Message-ID: <51CAA51F.1040908@gmail.com>

On 06/26/13 08:11, Sascha Hauer wrote:
> On Tue, Jun 25, 2013 at 11:20:42AM +0200, Sebastian Hesselbarth wrote:
>> +struct device_d *of_find_device_by_node(struct device_node *np)
>> +{
>> +        struct device_d *dev;
>> +
>> +	for_each_device(dev)
>> +		if (dev->device_node == np)
>> +			return dev;
>> +        return NULL;
>> +}
>
> There's some whitespace damage in this function.

True, and again I am wondering why my pre-commit checkpatch hook didn't
catch it.

Queued for v2.

Sebastian


From s.hauer at pengutronix.de  Wed Jun 26 04:35:14 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:35:14 +0200
Subject: [PATCH] mfd: mc34708: provide static inline wrapper
Message-ID: <1372235714-5568-1-git-send-email-s.hauer@pengutronix.de>

If the driver is disabled provide a static inline wrapper for
mc34708_get() to prevent linker errors.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/mfd/mc34708.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/mfd/mc34708.h b/include/mfd/mc34708.h
index f384c62..541c47f 100644
--- a/include/mfd/mc34708.h
+++ b/include/mfd/mc34708.h
@@ -93,7 +93,14 @@ struct mc34708 {
 	unsigned int		revision;
 };
 
-extern struct mc34708 *mc34708_get(void);
+#ifdef CONFIG_MFD_MC34708
+struct mc34708 *mc34708_get(void);
+#else
+static inline struct mc34708 *mc34708_get(void)
+{
+	return NULL;
+}
+#endif
 
 extern int mc34708_reg_read(struct mc34708 *mc34708, enum mc34708_reg reg, u32 *val);
 extern int mc34708_reg_write(struct mc34708 *mc34708, enum mc34708_reg reg, u32 val);
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 04:00:56 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:56 +0200
Subject: [PATCH 10/11] ARM: i.MX51 efikasb: switch to multiboard support
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-11-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/efika-mx-smartbook/Makefile        |  5 +-
 arch/arm/boards/efika-mx-smartbook/board.c         | 17 +++++--
 arch/arm/boards/efika-mx-smartbook/dcd-data.h      | 56 ---------------------
 .../flash-header-imx51-genesi-efikasb.imxcfg       | 57 ++++++++++++++++++++++
 arch/arm/boards/efika-mx-smartbook/flash_header.c  | 29 -----------
 arch/arm/boards/efika-mx-smartbook/lowlevel.c      | 14 +++++-
 arch/arm/configs/efika-mx-smartbook_defconfig      |  1 +
 arch/arm/dts/Makefile                              |  1 +
 arch/arm/mach-imx/Kconfig                          | 15 +++---
 images/Makefile.imx                                |  6 +++
 10 files changed, 100 insertions(+), 101 deletions(-)
 delete mode 100644 arch/arm/boards/efika-mx-smartbook/dcd-data.h
 create mode 100644 arch/arm/boards/efika-mx-smartbook/flash-header-imx51-genesi-efikasb.imxcfg
 delete mode 100644 arch/arm/boards/efika-mx-smartbook/flash_header.c

diff --git a/arch/arm/boards/efika-mx-smartbook/Makefile b/arch/arm/boards/efika-mx-smartbook/Makefile
index a2c3104..a022d6d 100644
--- a/arch/arm/boards/efika-mx-smartbook/Makefile
+++ b/arch/arm/boards/efika-mx-smartbook/Makefile
@@ -1,3 +1,4 @@
-obj-y += board.o
+obj-y += board.o flash-header-imx51-genesi-efikasb.o
 lwl-y += lowlevel.o
-lwl-y += flash_header.o
+extra-y += flash-header-imx51-genesi-efikasb.S
+extra-y += flash-header-imx51-genesi-efikasb.dcd
diff --git a/arch/arm/boards/efika-mx-smartbook/board.c b/arch/arm/boards/efika-mx-smartbook/board.c
index 0e6694b..1735c3e 100644
--- a/arch/arm/boards/efika-mx-smartbook/board.c
+++ b/arch/arm/boards/efika-mx-smartbook/board.c
@@ -182,6 +182,9 @@ static int efikamx_power_init(void)
 
 static int efikamx_usb_init(void)
 {
+	if (!of_machine_is_compatible("genesi,imx51-sb"))
+		return 0;
+
 	gpio_direction_output(GPIO_BLUETOOTH, 0);
 	gpio_direction_output(GPIO_WIFI_ENABLE, 1);
 	gpio_direction_output(GPIO_WIFI_RESET, 0);
@@ -222,15 +225,17 @@ static struct gpio_led leds[] = {
 	},
 };
 
-#define DCD_NAME static struct imx_dcd_entry dcd_entry
-
-#include "dcd-data.h"
+extern char flash_header_imx51_genesi_efikasb_start[];
+extern char flash_header_imx51_genesi_efikasb_end[];
 
 static int efikamx_late_init(void)
 {
 	enum bootsource bootsource;
 	int i;
 
+	if (!of_machine_is_compatible("genesi,imx51-sb"))
+		return 0;
+
 	efikamx_power_init();
 
 	gpio_direction_output(GPIO_BACKLIGHT_POWER, 1);
@@ -241,8 +246,10 @@ static int efikamx_late_init(void)
 	writew(0x0, MX51_WDOG_BASE_ADDR + 0x8);
 
 	imx51_bbu_internal_mmc_register_handler("mmc", "/dev/mmc1",
-			BBU_HANDLER_FLAG_DEFAULT, dcd_entry, sizeof(dcd_entry),
-			0);
+			BBU_HANDLER_FLAG_DEFAULT,
+			(void *)flash_header_imx51_genesi_efikasb_start,
+			flash_header_imx51_genesi_efikasb_end -
+			flash_header_imx51_genesi_efikasb_start, 0);
 
 	armlinux_set_bootparams((void *)0x90000100);
 	armlinux_set_architecture(2370);
diff --git a/arch/arm/boards/efika-mx-smartbook/dcd-data.h b/arch/arm/boards/efika-mx-smartbook/dcd-data.h
deleted file mode 100644
index 6795e19..0000000
--- a/arch/arm/boards/efika-mx-smartbook/dcd-data.h
+++ /dev/null
@@ -1,56 +0,0 @@
-DCD_NAME[] = {
-	{ .ptr_type = 4, .addr = 0x73fa88a0, .val = 0x00000000, },
-	{ .ptr_type = 4, .addr = 0x73fa850c, .val = 0x000020c5, },
-	{ .ptr_type = 4, .addr = 0x73fa8510, .val = 0x000020c5, },
-	{ .ptr_type = 4, .addr = 0x73fa883c, .val = 0x00000005, },
-	{ .ptr_type = 4, .addr = 0x73fa8848, .val = 0x00000005, },
-	{ .ptr_type = 4, .addr = 0x73fa84b8, .val = 0x000000e7, },
-	{ .ptr_type = 4, .addr = 0x73fa84bc, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa84c0, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa84c4, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa84c8, .val = 0x00000045, },
-	{ .ptr_type = 4, .addr = 0x73fa8820, .val = 0x00000000, },
-	{ .ptr_type = 4, .addr = 0x73fa84a4, .val = 0x00000005, },
-	{ .ptr_type = 4, .addr = 0x73fa84a8, .val = 0x00000005, },
-	{ .ptr_type = 4, .addr = 0x73fa84ac, .val = 0x000000e5, },
-	{ .ptr_type = 4, .addr = 0x73fa84b0, .val = 0x000000e5, },
-	{ .ptr_type = 4, .addr = 0x73fa84b4, .val = 0x000000e5, },
-	{ .ptr_type = 4, .addr = 0x73fa84cc, .val = 0x000000e5, },
-	{ .ptr_type = 4, .addr = 0x73fa84d0, .val = 0x000000e4, },
-	{ .ptr_type = 4, .addr = 0x73fa882c, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x73fa88a4, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x73fa88ac, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x73fa88b8, .val = 0x00000004, },
-	{ .ptr_type = 4, .addr = 0x83fd9000, .val = 0x82a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9008, .val = 0x82a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9010, .val = 0xcaaaf6d0, },
-	{ .ptr_type = 4, .addr = 0x83fd9004, .val = 0x333574aa, },
-	{ .ptr_type = 4, .addr = 0x83fd900c, .val = 0x333574aa, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x04008008, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801a, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801b, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00448019, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x07328018, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x04008008, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008010, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008010, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x06328018, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x03808019, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008000, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0400800c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801e, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801f, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0000801d, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0732801c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0400800c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008014, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008014, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0632801c, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x0380801d, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00008004, },
-	{ .ptr_type = 4, .addr = 0x83fd9000, .val = 0xb2a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9008, .val = 0xb2a20000, },
-	{ .ptr_type = 4, .addr = 0x83fd9010, .val = 0x000ad6d0, },
-	{ .ptr_type = 4, .addr = 0x83fd9034, .val = 0x90000000, },
-	{ .ptr_type = 4, .addr = 0x83fd9014, .val = 0x00000000, },
-};
diff --git a/arch/arm/boards/efika-mx-smartbook/flash-header-imx51-genesi-efikasb.imxcfg b/arch/arm/boards/efika-mx-smartbook/flash-header-imx51-genesi-efikasb.imxcfg
new file mode 100644
index 0000000..53875ed
--- /dev/null
+++ b/arch/arm/boards/efika-mx-smartbook/flash-header-imx51-genesi-efikasb.imxcfg
@@ -0,0 +1,57 @@
+soc imx51
+loadaddr 0x90000000
+dcdofs 0x400
+wm 32 0x73fa88a0 0x00000000
+wm 32 0x73fa850c 0x000020c5
+wm 32 0x73fa8510 0x000020c5
+wm 32 0x73fa883c 0x00000005
+wm 32 0x73fa8848 0x00000005
+wm 32 0x73fa84b8 0x000000e7
+wm 32 0x73fa84bc 0x00000045
+wm 32 0x73fa84c0 0x00000045
+wm 32 0x73fa84c4 0x00000045
+wm 32 0x73fa84c8 0x00000045
+wm 32 0x73fa8820 0x00000000
+wm 32 0x73fa84a4 0x00000005
+wm 32 0x73fa84a8 0x00000005
+wm 32 0x73fa84ac 0x000000e5
+wm 32 0x73fa84b0 0x000000e5
+wm 32 0x73fa84b4 0x000000e5
+wm 32 0x73fa84cc 0x000000e5
+wm 32 0x73fa84d0 0x000000e4
+wm 32 0x73fa882c 0x00000004
+wm 32 0x73fa88a4 0x00000004
+wm 32 0x73fa88ac 0x00000004
+wm 32 0x73fa88b8 0x00000004
+wm 32 0x83fd9000 0x82a20000
+wm 32 0x83fd9008 0x82a20000
+wm 32 0x83fd9010 0xcaaaf6d0
+wm 32 0x83fd9004 0x333574aa
+wm 32 0x83fd900c 0x333574aa
+wm 32 0x83fd9014 0x04008008
+wm 32 0x83fd9014 0x0000801a
+wm 32 0x83fd9014 0x0000801b
+wm 32 0x83fd9014 0x00448019
+wm 32 0x83fd9014 0x07328018
+wm 32 0x83fd9014 0x04008008
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x06328018
+wm 32 0x83fd9014 0x03808019
+wm 32 0x83fd9014 0x00008000
+wm 32 0x83fd9014 0x0400800c
+wm 32 0x83fd9014 0x0000801e
+wm 32 0x83fd9014 0x0000801f
+wm 32 0x83fd9014 0x0000801d
+wm 32 0x83fd9014 0x0732801c
+wm 32 0x83fd9014 0x0400800c
+wm 32 0x83fd9014 0x00008014
+wm 32 0x83fd9014 0x00008014
+wm 32 0x83fd9014 0x0632801c
+wm 32 0x83fd9014 0x0380801d
+wm 32 0x83fd9014 0x00008004
+wm 32 0x83fd9000 0xb2a20000
+wm 32 0x83fd9008 0xb2a20000
+wm 32 0x83fd9010 0x000ad6d0
+wm 32 0x83fd9034 0x90000000
+wm 32 0x83fd9014 0x00000000
diff --git a/arch/arm/boards/efika-mx-smartbook/flash_header.c b/arch/arm/boards/efika-mx-smartbook/flash_header.c
deleted file mode 100644
index f3f1e4b..0000000
--- a/arch/arm/boards/efika-mx-smartbook/flash_header.c
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <common.h>
-#include <mach/imx-flash-header.h>
-#include <asm/barebox-arm-head.h>
-
-void __naked __flash_header_start go(void)
-{
-	barebox_arm_head();
-}
-
-#define DCD_NAME struct imx_dcd_entry __dcd_entry_section dcd_entry
-
-#include "dcd-data.h"
-
-#define APP_DEST	0x90000000
-
-struct imx_flash_header __flash_header_section flash_header = {
-	.app_code_jump_vector	= APP_DEST + 0x1000,
-	.app_code_barker	= APP_CODE_BARKER,
-	.app_code_csf		= 0,
-	.dcd_ptr_ptr		= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd),
-	.super_root_key		= 0,
-	.dcd			= APP_DEST + 0x400 + offsetof(struct imx_flash_header, dcd_barker),
-	.app_dest		= APP_DEST,
-	.dcd_barker		= DCD_BARKER,
-	.dcd_block_len		= sizeof (dcd_entry),
-};
-
-unsigned long __image_len_section barebox_len = DCD_BAREBOX_SIZE;
-
diff --git a/arch/arm/boards/efika-mx-smartbook/lowlevel.c b/arch/arm/boards/efika-mx-smartbook/lowlevel.c
index 11abc93..5a56861 100644
--- a/arch/arm/boards/efika-mx-smartbook/lowlevel.c
+++ b/arch/arm/boards/efika-mx-smartbook/lowlevel.c
@@ -1,12 +1,22 @@
 #include <common.h>
 #include <mach/esdctl.h>
 #include <asm/barebox-arm-head.h>
+#include <asm/barebox-arm.h>
 #include <mach/imx5.h>
 
-void __naked barebox_arm_reset_vector(void)
+extern char __dtb_imx51_genesi_efika_sb_start[];
+
+ENTRY_FUNCTION(start_imx51_genesi_efikasb)(void)
 {
+	uint32_t fdt;
+
+	__barebox_arm_head();
+
 	arm_cpu_lowlevel_init();
 	arm_setup_stack(0x20000000 - 16);
 	imx51_init_lowlevel(800);
-	imx51_barebox_entry(0);
+
+	fdt = (uint32_t)__dtb_imx51_genesi_efika_sb_start - get_runtime_offset();
+
+	imx51_barebox_entry(fdt);
 }
diff --git a/arch/arm/configs/efika-mx-smartbook_defconfig b/arch/arm/configs/efika-mx-smartbook_defconfig
index 8e14466..f436d0d 100644
--- a/arch/arm/configs/efika-mx-smartbook_defconfig
+++ b/arch/arm/configs/efika-mx-smartbook_defconfig
@@ -1,3 +1,4 @@
+CONFIG_IMX_MULTI_BOARDS=y
 CONFIG_BUILTIN_DTB=y
 CONFIG_BUILTIN_DTB_NAME="imx51-genesi-efika-sb"
 CONFIG_ARCH_IMX=y
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 1158f41..63956e9 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -8,6 +8,7 @@ dtb-$(CONFIG_ARCH_IMX6) += imx6q-dmo-realq7.dtb \
 BUILTIN_DTB := $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_NAME))
 obj-$(CONFIG_BUILTIN_DTB) += $(BUILTIN_DTB).dtb.o
 
+pbl-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK) += imx51-genesi-efika-sb.dtb.o
 pbl-$(CONFIG_MACH_FREESCALE_MX51_PDK) += imx51-babbage.dtb.o
 pbl-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += imx53-qsb.dtb.o
 pbl-$(CONFIG_MACH_REALQ7) += imx6q-dmo-realq7.dtb.o
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index ccdebca..869b150 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -222,6 +222,14 @@ config IMX_MULTI_BOARDS
 
 if IMX_MULTI_BOARDS
 
+config MACH_EFIKA_MX_SMARTBOOK
+	bool "Efika MX smartbook"
+	select ARCH_IMX51
+	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select HAVE_PBL_MULTI_IMAGES
+	help
+	  Choose this to compile barebox for the Efika MX Smartbook
+
 config MACH_FREESCALE_MX51_PDK
 	bool "Freescale i.MX51 PDK"
 	select ARCH_IMX51
@@ -436,13 +444,6 @@ config MACH_CCMX51_BASEBOARD
 	  This adds board specific devices that can be found on Digi
 	  evaluation board for CCMX51 module.
 
-config MACH_EFIKA_MX_SMARTBOOK
-	bool "Efika MX smartbook"
-	select ARCH_IMX51
-	select HAVE_DEFAULT_ENVIRONMENT_NEW
-	help
-	  Choose this to compile barebox for the Efika MX Smartbook
-
 # ----------------------------------------------------------
 
 comment "i.MX53 Boards"
diff --git a/images/Makefile.imx b/images/Makefile.imx
index 002e73b..788800e 100644
--- a/images/Makefile.imx
+++ b/images/Makefile.imx
@@ -21,6 +21,12 @@ imximage-$(CONFIG_MACH_FREESCALE_MX51_PDK) += start_imx51_babbage.pblx.imximg
 FILE_barebox-freescale-imx51-babbage.img = start_imx51_babbage.pblx.imximg
 image-$(CONFIG_MACH_FREESCALE_MX51_PDK) += barebox-freescale-imx51-babbage.img
 
+pblx-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK) += start_imx51_genesi_efikasb
+CFG_start_imx51_genesi_efikasb.pblx.imximg = $(board)/efika-mx-smartbook/flash-header-imx51-genesi-efikasb.imxcfg
+imximage-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK) += start_imx51_genesi_efikasb.pblx.imximg
+FILE_barebox-genesi-efikasb.img = start_imx51_genesi_efikasb.pblx.imximg
+image-$(CONFIG_MACH_EFIKA_MX_SMARTBOOK) += barebox-genesi-efikasb.img
+
 # ----------------------- i.MX53 based boards ---------------------------
 pblx-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += start_imx53_loco
 CFG_start_imx53_loco.pblx.imximg = $(board)/freescale-mx53-loco/flash-header-imx53-loco.imxcfg
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 04:00:48 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:48 +0200
Subject: [PATCH 02/11] ARM: i.MX51 babbage: add board name to flash header file
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-3-git-send-email-s.hauer@pengutronix.de>

This is necessary because the C name for the flash header matches
the filename. For multiple board support we have to make the name
unique to prevent linker errors.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx51-pdk/Makefile        |  4 +-
 arch/arm/boards/freescale-mx51-pdk/board.c         |  7 +--
 .../flash-header-imx51-babbage.imxcfg              | 59 ++++++++++++++++++++++
 .../boards/freescale-mx51-pdk/flash-header.imxcfg  | 59 ----------------------
 images/Makefile.imx                                |  2 +-
 5 files changed, 66 insertions(+), 65 deletions(-)
 create mode 100644 arch/arm/boards/freescale-mx51-pdk/flash-header-imx51-babbage.imxcfg
 delete mode 100644 arch/arm/boards/freescale-mx51-pdk/flash-header.imxcfg

diff --git a/arch/arm/boards/freescale-mx51-pdk/Makefile b/arch/arm/boards/freescale-mx51-pdk/Makefile
index f1baae2..0c06778 100644
--- a/arch/arm/boards/freescale-mx51-pdk/Makefile
+++ b/arch/arm/boards/freescale-mx51-pdk/Makefile
@@ -1,3 +1,3 @@
-obj-y += board.o flash-header.o
-extra-y += flash-header.S flash-header.dcd
+obj-y += board.o flash-header-imx51-babbage.o
+extra-y += flash-header-imx51-babbage.S flash-header-imx51-babbage.dcd
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index fc7e175..3906e47 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -157,7 +157,8 @@ static void babbage_power_init(void)
 	mdelay(50);
 }
 
-extern char flash_header_start[], flash_header_end[];
+extern char flash_header_imx51_babbage_start[];
+extern char flash_header_imx51_babbage_end[];
 
 static int f3s_devices_init(void)
 {
@@ -171,8 +172,8 @@ static int f3s_devices_init(void)
 	armlinux_set_architecture(MACH_TYPE_MX51_BABBAGE);
 
 	imx51_bbu_internal_mmc_register_handler("mmc", "/dev/mmc0",
-		BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_start,
-		flash_header_end - flash_header_start, 0);
+		BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_imx51_babbage_start,
+		flash_header_imx51_babbage_end - flash_header_imx51_babbage_start, 0);
 
 	return 0;
 }
diff --git a/arch/arm/boards/freescale-mx51-pdk/flash-header-imx51-babbage.imxcfg b/arch/arm/boards/freescale-mx51-pdk/flash-header-imx51-babbage.imxcfg
new file mode 100644
index 0000000..bac6816
--- /dev/null
+++ b/arch/arm/boards/freescale-mx51-pdk/flash-header-imx51-babbage.imxcfg
@@ -0,0 +1,59 @@
+loadaddr 0x90000000
+soc imx51
+dcdofs 0x400
+wm 32 0x73fa88a0 0x00000200
+wm 32 0x73fa850c 0x000020c5
+wm 32 0x73fa8510 0x000020c5
+wm 32 0x73fa883c 0x00000002
+wm 32 0x73fa8848 0x00000002
+wm 32 0x73fa84b8 0x000000e7
+wm 32 0x73fa84bc 0x00000045
+wm 32 0x73fa84c0 0x00000045
+wm 32 0x73fa84c4 0x00000045
+wm 32 0x73fa84c8 0x00000045
+wm 32 0x73fa8820 0x00000000
+wm 32 0x73fa84a4 0x00000003
+wm 32 0x73fa84a8 0x00000003
+wm 32 0x73fa84ac 0x000000e3
+wm 32 0x73fa84b0 0x000000e3
+wm 32 0x73fa84b4 0x000000e3
+wm 32 0x73fa84cc 0x000000e3
+wm 32 0x73fa84d0 0x000000e2
+wm 32 0x73fa882c 0x00000004
+wm 32 0x73fa88a4 0x00000004
+wm 32 0x73fa88ac 0x00000004
+wm 32 0x73fa88b8 0x00000004
+wm 32 0x83fd9000 0x82a20000
+wm 32 0x83fd9008 0x82a20000
+wm 32 0x83fd9010 0x000ad0d0
+wm 32 0x83fd9004 0x3f3584ab
+wm 32 0x83fd900c 0x3f3584ab
+wm 32 0x83fd9014 0x04008008
+wm 32 0x83fd9014 0x0000801a
+wm 32 0x83fd9014 0x0000801b
+wm 32 0x83fd9014 0x00448019
+wm 32 0x83fd9014 0x07328018
+wm 32 0x83fd9014 0x04008008
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x00008010
+wm 32 0x83fd9014 0x06328018
+wm 32 0x83fd9014 0x03808019
+wm 32 0x83fd9014 0x00408019
+wm 32 0x83fd9014 0x00008000
+wm 32 0x83fd9014 0x0400800c
+wm 32 0x83fd9014 0x0000801e
+wm 32 0x83fd9014 0x0000801f
+wm 32 0x83fd9014 0x0000801d
+wm 32 0x83fd9014 0x0732801c
+wm 32 0x83fd9014 0x0400800c
+wm 32 0x83fd9014 0x00008014
+wm 32 0x83fd9014 0x00008014
+wm 32 0x83fd9014 0x0632801c
+wm 32 0x83fd9014 0x0380801d
+wm 32 0x83fd9014 0x0040801d
+wm 32 0x83fd9014 0x00008004
+wm 32 0x83fd9000 0xb2a20000
+wm 32 0x83fd9008 0xb2a20000
+wm 32 0x83fd9010 0x000ad6d0
+wm 32 0x83fd9034 0x90000000
+wm 32 0x83fd9014 0x00000000
diff --git a/arch/arm/boards/freescale-mx51-pdk/flash-header.imxcfg b/arch/arm/boards/freescale-mx51-pdk/flash-header.imxcfg
deleted file mode 100644
index bac6816..0000000
--- a/arch/arm/boards/freescale-mx51-pdk/flash-header.imxcfg
+++ /dev/null
@@ -1,59 +0,0 @@
-loadaddr 0x90000000
-soc imx51
-dcdofs 0x400
-wm 32 0x73fa88a0 0x00000200
-wm 32 0x73fa850c 0x000020c5
-wm 32 0x73fa8510 0x000020c5
-wm 32 0x73fa883c 0x00000002
-wm 32 0x73fa8848 0x00000002
-wm 32 0x73fa84b8 0x000000e7
-wm 32 0x73fa84bc 0x00000045
-wm 32 0x73fa84c0 0x00000045
-wm 32 0x73fa84c4 0x00000045
-wm 32 0x73fa84c8 0x00000045
-wm 32 0x73fa8820 0x00000000
-wm 32 0x73fa84a4 0x00000003
-wm 32 0x73fa84a8 0x00000003
-wm 32 0x73fa84ac 0x000000e3
-wm 32 0x73fa84b0 0x000000e3
-wm 32 0x73fa84b4 0x000000e3
-wm 32 0x73fa84cc 0x000000e3
-wm 32 0x73fa84d0 0x000000e2
-wm 32 0x73fa882c 0x00000004
-wm 32 0x73fa88a4 0x00000004
-wm 32 0x73fa88ac 0x00000004
-wm 32 0x73fa88b8 0x00000004
-wm 32 0x83fd9000 0x82a20000
-wm 32 0x83fd9008 0x82a20000
-wm 32 0x83fd9010 0x000ad0d0
-wm 32 0x83fd9004 0x3f3584ab
-wm 32 0x83fd900c 0x3f3584ab
-wm 32 0x83fd9014 0x04008008
-wm 32 0x83fd9014 0x0000801a
-wm 32 0x83fd9014 0x0000801b
-wm 32 0x83fd9014 0x00448019
-wm 32 0x83fd9014 0x07328018
-wm 32 0x83fd9014 0x04008008
-wm 32 0x83fd9014 0x00008010
-wm 32 0x83fd9014 0x00008010
-wm 32 0x83fd9014 0x06328018
-wm 32 0x83fd9014 0x03808019
-wm 32 0x83fd9014 0x00408019
-wm 32 0x83fd9014 0x00008000
-wm 32 0x83fd9014 0x0400800c
-wm 32 0x83fd9014 0x0000801e
-wm 32 0x83fd9014 0x0000801f
-wm 32 0x83fd9014 0x0000801d
-wm 32 0x83fd9014 0x0732801c
-wm 32 0x83fd9014 0x0400800c
-wm 32 0x83fd9014 0x00008014
-wm 32 0x83fd9014 0x00008014
-wm 32 0x83fd9014 0x0632801c
-wm 32 0x83fd9014 0x0380801d
-wm 32 0x83fd9014 0x0040801d
-wm 32 0x83fd9014 0x00008004
-wm 32 0x83fd9000 0xb2a20000
-wm 32 0x83fd9008 0xb2a20000
-wm 32 0x83fd9010 0x000ad6d0
-wm 32 0x83fd9034 0x90000000
-wm 32 0x83fd9014 0x00000000
diff --git a/images/Makefile.imx b/images/Makefile.imx
index 72e8cde..d13be84 100644
--- a/images/Makefile.imx
+++ b/images/Makefile.imx
@@ -16,7 +16,7 @@ image-$(CONFIG_MACH_PCM038) += barebox-phytec-phycore-imx27.img
 
 # ----------------------- i.MX51 based boards ---------------------------
 pblx-$(CONFIG_MACH_FREESCALE_MX51_PDK) += start_imx51_babbage
-CFG_start_imx51_babbage.pblx.imximg = $(board)/freescale-mx51-pdk/flash-header.imxcfg
+CFG_start_imx51_babbage.pblx.imximg = $(board)/freescale-mx51-pdk/flash-header-imx51-babbage.imxcfg
 imximage-$(CONFIG_MACH_FREESCALE_MX51_PDK) += start_imx51_babbage.pblx.imximg
 FILE_barebox-freescale-imx51-babbage.img = start_imx51_babbage.pblx.imximg
 image-$(CONFIG_MACH_FREESCALE_MX51_PDK) += barebox-freescale-imx51-babbage.img
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 04:00:51 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:51 +0200
Subject: [PATCH 05/11] ARM: i.MX53 loco: add board name to flash header file
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-6-git-send-email-s.hauer@pengutronix.de>

This is necessary because the C name for the flash header matches
the filename. For multiple board support we have to make the name
unique to prevent linker errors.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/freescale-mx53-loco/Makefile       |  4 +-
 arch/arm/boards/freescale-mx53-loco/board.c        |  7 +--
 .../flash-header-imx53-loco.imxcfg                 | 54 ++++++++++++++++++++++
 .../boards/freescale-mx53-loco/flash-header.imxcfg | 54 ----------------------
 images/Makefile.imx                                |  2 +-
 5 files changed, 61 insertions(+), 60 deletions(-)
 create mode 100644 arch/arm/boards/freescale-mx53-loco/flash-header-imx53-loco.imxcfg
 delete mode 100644 arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg

diff --git a/arch/arm/boards/freescale-mx53-loco/Makefile b/arch/arm/boards/freescale-mx53-loco/Makefile
index f1baae2..68fbe3a 100644
--- a/arch/arm/boards/freescale-mx53-loco/Makefile
+++ b/arch/arm/boards/freescale-mx53-loco/Makefile
@@ -1,3 +1,3 @@
-obj-y += board.o flash-header.o
-extra-y += flash-header.S flash-header.dcd
+obj-y += board.o flash-header-imx53-loco.o
+extra-y += flash-header-imx53-loco.S flash-header-imx53-loco.dcd
 lwl-y += lowlevel.o
diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c
index dd4251d..446b7f3 100644
--- a/arch/arm/boards/freescale-mx53-loco/board.c
+++ b/arch/arm/boards/freescale-mx53-loco/board.c
@@ -75,7 +75,8 @@ static void loco_fec_reset(void)
 
 #define MX53_LOCO_USB_PWREN		IMX_GPIO_NR(7, 8)
 
-extern char flash_header_start[], flash_header_end[];
+extern char flash_header_imx53_loco_start[];
+extern char flash_header_imx53_loco_end[];
 
 static int loco_late_init(void)
 {
@@ -112,8 +113,8 @@ static int loco_late_init(void)
 	armlinux_set_architecture(MACH_TYPE_MX53_LOCO);
 
 	imx53_bbu_internal_mmc_register_handler("mmc", "/dev/mmc0",
-		BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_start,
-		flash_header_end - flash_header_start, 0);
+		BBU_HANDLER_FLAG_DEFAULT, (void *)flash_header_imx53_loco_start,
+		flash_header_imx53_loco_end - flash_header_imx53_loco_start, 0);
 
 	return 0;
 }
diff --git a/arch/arm/boards/freescale-mx53-loco/flash-header-imx53-loco.imxcfg b/arch/arm/boards/freescale-mx53-loco/flash-header-imx53-loco.imxcfg
new file mode 100644
index 0000000..95bcd19
--- /dev/null
+++ b/arch/arm/boards/freescale-mx53-loco/flash-header-imx53-loco.imxcfg
@@ -0,0 +1,54 @@
+loadaddr 0x70000000
+soc imx53
+dcdofs 0x400
+wm 32 0x53fa8554 0x00300000
+wm 32 0x53fa8558 0x00300040
+wm 32 0x53fa8560 0x00300000
+wm 32 0x53fa8564 0x00300040
+wm 32 0x53fa8568 0x00300040
+wm 32 0x53fa8570 0x00300000
+wm 32 0x53fa8574 0x00300000
+wm 32 0x53fa8578 0x00300000
+wm 32 0x53fa857c 0x00300040
+wm 32 0x53fa8580 0x00300040
+wm 32 0x53fa8584 0x00300000
+wm 32 0x53fa8588 0x00300000
+wm 32 0x53fa8590 0x00300040
+wm 32 0x53fa8594 0x00300000
+wm 32 0x53fa86f0 0x00300000
+wm 32 0x53fa86f4 0x00000000
+wm 32 0x53fa86fc 0x00000000
+wm 32 0x53fa8714 0x00000000
+wm 32 0x53fa8718 0x00300000
+wm 32 0x53fa871c 0x00300000
+wm 32 0x53fa8720 0x00300000
+wm 32 0x53fa8724 0x04000000
+wm 32 0x53fa8728 0x00300000
+wm 32 0x53fa872c 0x00300000
+wm 32 0x63fd9088 0x35343535
+wm 32 0x63fd9090 0x4d444c44
+wm 32 0x63fd907c 0x01370138
+wm 32 0x63fd9080 0x013b013c
+wm 32 0x63fd9018 0x00011740
+wm 32 0x63fd9000 0xc3190000
+wm 32 0x63fd900c 0x9f5152e3
+wm 32 0x63fd9010 0xb68e8a63
+wm 32 0x63fd9014 0x01ff00db
+wm 32 0x63fd902c 0x000026d2
+wm 32 0x63fd9030 0x009f0e21
+wm 32 0x63fd9008 0x12273030
+wm 32 0x63fd9004 0x0002002d
+wm 32 0x63fd901c 0x00008032
+wm 32 0x63fd901c 0x00008033
+wm 32 0x63fd901c 0x00028031
+wm 32 0x63fd901c 0x052080b0
+wm 32 0x63fd901c 0x04008040
+wm 32 0x63fd901c 0x0000803a
+wm 32 0x63fd901c 0x0000803b
+wm 32 0x63fd901c 0x00028039
+wm 32 0x63fd901c 0x05208138
+wm 32 0x63fd901c 0x04008048
+wm 32 0x63fd9020 0x00005800
+wm 32 0x63fd9040 0x04b80003
+wm 32 0x63fd9058 0x00022227
+wm 32 0x63fd901c 0x00000000
diff --git a/arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg b/arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg
deleted file mode 100644
index 95bcd19..0000000
--- a/arch/arm/boards/freescale-mx53-loco/flash-header.imxcfg
+++ /dev/null
@@ -1,54 +0,0 @@
-loadaddr 0x70000000
-soc imx53
-dcdofs 0x400
-wm 32 0x53fa8554 0x00300000
-wm 32 0x53fa8558 0x00300040
-wm 32 0x53fa8560 0x00300000
-wm 32 0x53fa8564 0x00300040
-wm 32 0x53fa8568 0x00300040
-wm 32 0x53fa8570 0x00300000
-wm 32 0x53fa8574 0x00300000
-wm 32 0x53fa8578 0x00300000
-wm 32 0x53fa857c 0x00300040
-wm 32 0x53fa8580 0x00300040
-wm 32 0x53fa8584 0x00300000
-wm 32 0x53fa8588 0x00300000
-wm 32 0x53fa8590 0x00300040
-wm 32 0x53fa8594 0x00300000
-wm 32 0x53fa86f0 0x00300000
-wm 32 0x53fa86f4 0x00000000
-wm 32 0x53fa86fc 0x00000000
-wm 32 0x53fa8714 0x00000000
-wm 32 0x53fa8718 0x00300000
-wm 32 0x53fa871c 0x00300000
-wm 32 0x53fa8720 0x00300000
-wm 32 0x53fa8724 0x04000000
-wm 32 0x53fa8728 0x00300000
-wm 32 0x53fa872c 0x00300000
-wm 32 0x63fd9088 0x35343535
-wm 32 0x63fd9090 0x4d444c44
-wm 32 0x63fd907c 0x01370138
-wm 32 0x63fd9080 0x013b013c
-wm 32 0x63fd9018 0x00011740
-wm 32 0x63fd9000 0xc3190000
-wm 32 0x63fd900c 0x9f5152e3
-wm 32 0x63fd9010 0xb68e8a63
-wm 32 0x63fd9014 0x01ff00db
-wm 32 0x63fd902c 0x000026d2
-wm 32 0x63fd9030 0x009f0e21
-wm 32 0x63fd9008 0x12273030
-wm 32 0x63fd9004 0x0002002d
-wm 32 0x63fd901c 0x00008032
-wm 32 0x63fd901c 0x00008033
-wm 32 0x63fd901c 0x00028031
-wm 32 0x63fd901c 0x052080b0
-wm 32 0x63fd901c 0x04008040
-wm 32 0x63fd901c 0x0000803a
-wm 32 0x63fd901c 0x0000803b
-wm 32 0x63fd901c 0x00028039
-wm 32 0x63fd901c 0x05208138
-wm 32 0x63fd901c 0x04008048
-wm 32 0x63fd9020 0x00005800
-wm 32 0x63fd9040 0x04b80003
-wm 32 0x63fd9058 0x00022227
-wm 32 0x63fd901c 0x00000000
diff --git a/images/Makefile.imx b/images/Makefile.imx
index d13be84..002e73b 100644
--- a/images/Makefile.imx
+++ b/images/Makefile.imx
@@ -23,7 +23,7 @@ image-$(CONFIG_MACH_FREESCALE_MX51_PDK) += barebox-freescale-imx51-babbage.img
 
 # ----------------------- i.MX53 based boards ---------------------------
 pblx-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += start_imx53_loco
-CFG_start_imx53_loco.pblx.imximg = $(board)/freescale-mx53-loco/flash-header.imxcfg
+CFG_start_imx53_loco.pblx.imximg = $(board)/freescale-mx53-loco/flash-header-imx53-loco.imxcfg
 imximage-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += start_imx53_loco.pblx.imximg
 FILE_barebox-freescale-imx53-loco.img = start_imx53_loco.pblx.imximg
 image-$(CONFIG_MACH_FREESCALE_MX53_LOCO) += barebox-freescale-imx53-loco.img
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Wed Jun 26 04:43:28 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 26 Jun 2013 10:43:28 +0200
Subject: [PATCH v2 4/9] OF: import bus/device related functions from Linux OF
 API
In-Reply-To: <1372152047-28134-5-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-5-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372236208-17069-1-git-send-email-sebastian.hesselbarth@gmail.com>

This imports some bus and device related functions from Linux OF API
with some modifcations for Barebox.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Changelog:
v1->v2:
- check for existing devices on of_platform_device_create
- remove auxdata lookup from doxygen header
- fix whitespace damage (Reported by Sascha Hauer)

Cc: barebox at lists.infradead.org
Cc: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/of/Makefile   |    2 +-
 drivers/of/platform.c |  320 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/of.h          |   18 +++
 3 files changed, 339 insertions(+), 1 deletions(-)
 create mode 100644 drivers/of/platform.c

diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index b8add0b..186074e 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -1,4 +1,4 @@
-obj-y += address.o base.o fdt.o
+obj-y += address.o base.o fdt.o platform.o
 obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o
 obj-$(CONFIG_GPIOLIB) += gpio.o
 obj-y += partition.o
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
new file mode 100644
index 0000000..0d87ef4
--- /dev/null
+++ b/drivers/of/platform.c
@@ -0,0 +1,320 @@
+/*
+ * platform.c - bus/device related devicetree functions
+ *
+ * Copyright (c) 2012 Sascha Hauer <s.hauer at pengutronix.de>, Pengutronix
+ *
+ * based on Linux devicetree support
+ *
+ * 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 version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ */
+#include <common.h>
+#include <malloc.h>
+#include <of.h>
+#include <of_address.h>
+#include <linux/amba/bus.h>
+
+/**
+ * of_find_device_by_node - Find the platform_device associated with a node
+ * @np: Pointer to device tree node
+ *
+ * Returns platform_device pointer, or NULL if not found
+ */
+struct device_d *of_find_device_by_node(struct device_node *np)
+{
+	struct device_d *dev;
+	for_each_device(dev)
+		if (dev->device_node == np)
+			return dev;
+	return NULL;
+}
+EXPORT_SYMBOL(of_find_device_by_node);
+
+/**
+ * of_device_make_bus_id - Use the device node data to assign a unique name
+ * @dev: pointer to device structure that is linked to a device tree node
+ *
+ * This routine will first try using either the dcr-reg or the reg property
+ * value to derive a unique name.  As a last resort it will use the node
+ * name followed by a unique number.
+ */
+static void of_device_make_bus_id(struct device_d *dev)
+{
+	static int bus_no_reg_magic;
+	struct device_node *np = dev->device_node;
+	const __be32 *reg, *addrp;
+	u64 addr;
+	char *name, *at;
+
+	name = xstrdup(np->name);
+	at = strchr(name, '@');
+	if (at)
+		*at = '\0';
+
+#ifdef CONFIG_PPC_DCR
+	/*
+	 * If it's a DCR based device, use 'd' for native DCRs
+	 * and 'D' for MMIO DCRs.
+	 */
+	reg = of_get_property(np, "dcr-reg", NULL);
+	if (reg) {
+#ifdef CONFIG_PPC_DCR_NATIVE
+		snprintf(dev->name, MAX_DRIVER_NAME, "d%x.%s", *reg, name);
+#else /* CONFIG_PPC_DCR_NATIVE */
+		u64 addr = of_translate_dcr_address(np, *reg, NULL);
+		if (addr != OF_BAD_ADDR) {
+			snprintf(dev->name, MAX_DRIVER_NAME, "D%llx.%s",
+				(unsigned long long)addr, name);
+			free(name);
+			return;
+		}
+#endif /* !CONFIG_PPC_DCR_NATIVE */
+	}
+#endif /* CONFIG_PPC_DCR */
+
+	/*
+	 * For MMIO, get the physical address
+	 */
+	reg = of_get_property(np, "reg", NULL);
+	if (reg) {
+		if (of_can_translate_address(np)) {
+			addr = of_translate_address(np, reg);
+		} else {
+			addrp = of_get_address(np, 0, NULL, NULL);
+			if (addrp)
+				addr = of_read_number(addrp, 1);
+			else
+				addr = OF_BAD_ADDR;
+		}
+		if (addr != OF_BAD_ADDR) {
+			snprintf(dev->name, MAX_DRIVER_NAME, "%llx.%s",
+				(unsigned long long)addr, name);
+			free(name);
+			return;
+		}
+	}
+
+	/*
+	 * No BusID, use the node name and add a globally incremented counter
+	 */
+	snprintf(dev->name, MAX_DRIVER_NAME, "%s.%d", name, bus_no_reg_magic++);
+	free(name);
+}
+
+/**
+ * of_platform_device_create - Alloc, initialize and register an of_device
+ * @np: pointer to node to create device for
+ * @parent: device model parent device.
+ *
+ * Returns pointer to created platform device, or NULL if a device was not
+ * registered. Unavailable devices will not get registered.
+ */
+static struct device_d *of_platform_device_create(struct device_node *np,
+						struct device_d *parent)
+{
+	struct device_d *dev;
+	struct resource *res = NULL, temp_res;
+	int i, j, ret, num_reg = 0, match;
+
+	if (!of_device_is_available(np))
+		return NULL;
+
+	/* count the io resources */
+	if (of_can_translate_address(np))
+		while (of_address_to_resource(np, num_reg, &temp_res) == 0)
+			num_reg++;
+
+	/* Populate the resource table */
+	if (num_reg) {
+		res = xzalloc(sizeof(*res) * num_reg);
+		for (i = 0; i < num_reg; i++) {
+			ret = of_address_to_resource(np, i, &res[i]);
+			if (ret) {
+				free(res);
+				return NULL;
+			}
+		}
+
+		/*
+		 * A device may already be registered as platform_device.
+		 * Instead of registering the same device again, just
+		 * add this node to the existing device.
+		 */
+		for_each_device(dev) {
+			if (!dev->resource)
+				continue;
+
+			for (i = 0, match = 0; i < num_reg; i++)
+				for (j = 0; j < dev->num_resources; j++)
+					if (dev->resource[j].start ==
+						res[i].start &&
+					    dev->resource[j].end ==
+						res[i].end) {
+						match++;
+						break;
+					}
+
+			/* check if all address resources match */
+			if (match == num_reg) {
+				debug("connecting %s to %s\n",
+					np->name, dev_name(dev));
+				dev->device_node = np;
+				free(res);
+				return dev;
+			}
+		}
+	}
+
+	debug("register device 0x%08x\n", (num_reg) ? dev->resource[0].start : (-1));
+
+	/* setup generic device info */
+	dev = xzalloc(sizeof(*dev));
+	dev->id = DEVICE_ID_SINGLE;
+	dev->device_node = np;
+	dev->parent = parent;
+	dev->resource = res;
+	dev->num_resources = num_reg;
+	of_device_make_bus_id(dev);
+
+	ret = platform_device_register(dev);
+	if (!ret)
+		return dev;
+
+	free(dev);
+	if (num_reg)
+		free(res);
+	return NULL;
+}
+
+#ifdef CONFIG_ARM_AMBA
+static struct device_d *of_amba_device_create(struct device_node *np)
+{
+	struct amba_device *dev;
+	int ret;
+
+	debug("Creating amba device %s\n", np->full_name);
+
+	if (!of_device_is_available(np))
+		return NULL;
+
+	dev = xzalloc(sizeof(*dev));
+
+	/* setup generic device info */
+	dev->dev.id = DEVICE_ID_SINGLE;
+	dev->dev.device_node = np;
+	of_device_make_bus_id(&dev->dev);
+
+	ret = of_address_to_resource(np, 0, &dev->res);
+	if (ret)
+		goto amba_err_free;
+
+	dev->dev.resource = &dev->res;
+	dev->dev.num_resources = 1;
+
+	/* Allow the HW Peripheral ID to be overridden */
+	of_property_read_u32(np, "arm,primecell-periphid", &dev->periphid);
+
+	debug("register device 0x%08x\n", dev->dev.resource[0].start);
+
+	ret = amba_device_add(dev);
+	if (ret)
+		goto amba_err_free;
+
+	return &dev->dev;
+
+amba_err_free:
+	free(dev);
+	return NULL;
+}
+#else /* CONFIG_ARM_AMBA */
+static inline struct amba_device *of_amba_device_create(struct device_node *np)
+{
+	return NULL;
+}
+#endif /* CONFIG_ARM_AMBA */
+
+/**
+ * of_platform_bus_create() - Create a device for a node and its children.
+ * @bus: device node of the bus to instantiate
+ * @matches: match table for bus nodes
+ * @parent: parent for new device, or NULL for top level.
+ *
+ * Creates a platform_device for the provided device_node, and optionally
+ * recursively create devices for all the child nodes.
+ */
+static int of_platform_bus_create(struct device_node *bus,
+				const struct of_device_id *matches,
+				struct device_d *parent)
+{
+	struct device_node *child;
+	struct device_d *dev;
+	int rc = 0;
+
+	/* Make sure it has a compatible property */
+	if (!of_get_property(bus, "compatible", NULL)) {
+		pr_debug("%s() - skipping %s, no compatible prop\n",
+			__func__, bus->full_name);
+		return 0;
+	}
+
+	if (of_device_is_compatible(bus, "arm,primecell")) {
+		of_amba_device_create(bus);
+		return 0;
+	}
+
+	dev = of_platform_device_create(bus, parent);
+	if (!dev || !of_match_node(matches, bus))
+		return 0;
+
+	for_each_child_of_node(bus, child) {
+		pr_debug("   create child: %s\n", child->full_name);
+		rc = of_platform_bus_create(child, matches, dev);
+		if (rc)
+			break;
+	}
+	return rc;
+}
+
+/**
+ * of_platform_populate() - Populate platform_devices from device tree data
+ * @root: parent of the first level to probe or NULL for the root of the tree
+ * @matches: match table, NULL to use the default
+ * @parent: parent to hook devices from, NULL for toplevel
+ *
+ * This function walks the device tree given by @root node and creates devices
+ * from nodes.  It requires all device nodes to have a 'compatible' property,
+ * and it is suitable for creating devices which are children of the root
+ * node.
+ *
+ * Returns 0 on success, < 0 on failure.
+ */
+int of_platform_populate(struct device_node *root,
+			const struct of_device_id *matches,
+			struct device_d *parent)
+{
+	struct device_node *child;
+	int rc = 0;
+
+	if (!root)
+		root = of_find_node_by_path("/");
+	if (!root)
+		return -EINVAL;
+
+	for_each_child_of_node(root, child) {
+		rc = of_platform_bus_create(child, matches, parent);
+		if (rc)
+			break;
+	}
+
+	return rc;
+}
+EXPORT_SYMBOL_GPL(of_platform_populate);
diff --git a/include/of.h b/include/of.h
index 8cab797..f1f555f 100644
--- a/include/of.h
+++ b/include/of.h
@@ -61,6 +61,7 @@ struct of_reserve_map *of_get_reserve_map(void);
 void of_clean_reserve_map(void);
 void fdt_add_reserve_map(void *fdt);
 
+struct device_d;
 struct driver_d;
 
 int of_fix_tree(struct device_node *);
@@ -221,6 +222,11 @@ extern int of_modalias_node(struct device_node *node, char *modalias, int len);
 extern struct device_node *of_get_root_node(void);
 extern int of_set_root_node(struct device_node *node);
 
+extern int of_platform_populate(struct device_node *root,
+				const struct of_device_id *matches,
+				struct device_d *parent);
+extern struct device_d *of_find_device_by_node(struct device_node *np);
+
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
@@ -547,6 +553,18 @@ static inline int of_modalias_node(struct device_node *node, char *modalias,
 {
 	return -ENOSYS;
 }
+
+static inline int of_platform_populate(struct device_node *root,
+				const struct of_device_id *matches,
+				struct device_d *parent)
+{
+	return -ENOSYS;
+}
+
+static inline struct device_d *of_find_device_by_node(struct device_node *np)
+{
+	return NULL;
+}
 #endif
 
 #define for_each_node_by_name(dn, name) \
-- 
1.7.2.5



From s.hauer at pengutronix.de  Wed Jun 26 04:00:50 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:50 +0200
Subject: [PATCH 04/11] ARM: i.MX51 babbage: Move over to multiboard
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-5-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/freescale_mx51_babbage_defconfig |  2 +-
 arch/arm/mach-imx/Kconfig                         | 21 ++++++++++++++-------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/arch/arm/configs/freescale_mx51_babbage_defconfig b/arch/arm/configs/freescale_mx51_babbage_defconfig
index 27f3ae8..b45b897 100644
--- a/arch/arm/configs/freescale_mx51_babbage_defconfig
+++ b/arch/arm/configs/freescale_mx51_babbage_defconfig
@@ -1,5 +1,5 @@
 CONFIG_ARCH_IMX=y
-CONFIG_ARCH_IMX51=y
+CONFIG_IMX_MULTI_BOARDS=y
 CONFIG_MACH_FREESCALE_MX51_PDK=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index ac2e9b8..f530e89 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -48,7 +48,6 @@ config BOARDINFO
 	default "Phytec phyCORE-i.MX35" if MACH_PCM043
 	default "Synertronixx scb9328" if MACH_SCB9328
 	default "Garz+Fricke Neso" if MACH_NESO
-	default "Freescale i.MX51 PDK" if MACH_FREESCALE_MX51_PDK
 	default "Freescale i.MX53 LOCO" if MACH_FREESCALE_MX53_LOCO
 	default "Freescale i.MX53 SMD" if MACH_FREESCALE_MX53_SMD
 	default "Efika MX smartbook" if MACH_EFIKA_MX_SMARTBOOK
@@ -63,6 +62,7 @@ config BOARDINFO
 	default "Garz+Fricke Vincell" if MACH_GUF_VINCELL
 	default "SabreSD" if MACH_SABRESD
 	default "DataModul i.MX6Q Real Qseven" if MACH_REALQ7
+	default "unused" if IMX_MULTI_BOARDS
 
 choice
 	prompt "Select boot mode"
@@ -216,10 +216,23 @@ config ARCH_IMX6
 	select CPU_V7
 	select PINCTRL_IMX_IOMUX_V3
 
+config IMX_MULTI_BOARDS
+	bool "Allow multiple boards to be selected"
+	select HAVE_DEFAULT_ENVIRONMENT_NEW
+	select HAVE_PBL_MULTI_IMAGES
+
+if IMX_MULTI_BOARDS
+
+config MACH_FREESCALE_MX51_PDK
+	bool "Freescale i.MX51 PDK"
+	select ARCH_IMX51
+endif
+
 # ----------------------------------------------------------
 
 choice
 	prompt "Select Board"
+	depends on !IMX_MULTI_BOARDS
 
 comment "i.MX1 Boards"
 
@@ -381,12 +394,6 @@ config MACH_GUF_CUPID
 
 comment "i.MX51 Boards"
 
-config MACH_FREESCALE_MX51_PDK
-	bool "Freescale i.MX51 PDK"
-	select ARCH_IMX51
-	select HAVE_DEFAULT_ENVIRONMENT_NEW
-	select HAVE_PBL_MULTI_IMAGES
-
 config MACH_EUKREA_CPUIMX51SD
 	bool "Ka-Ro TX51"
 	select ARCH_IMX51
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Wed Jun 26 04:43:38 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Wed, 26 Jun 2013 10:43:38 +0200
Subject: [PATCH v2 8/9] OF: base: convert of_add_memory to OF API
In-Reply-To: <1372152047-28134-9-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-9-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372236218-17103-1-git-send-email-sebastian.hesselbarth@gmail.com>

Convert of_add_memory parsing to make use of of_address_to_resource
instead of parsing memory ranges itself. This makes some functions
dead code which are also removed.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Changelog:
v1->v2:
- fix check for return value of of_address_to_resource (Reported by
  Sascha Hauer)

Cc: barebox at lists.infradead.org
Cc: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/of/base.c |   57 +++++++---------------------------------------------
 1 files changed, 8 insertions(+), 49 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 0244281..1cf7a5f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -99,21 +99,6 @@ int of_n_size_cells(struct device_node *np)
 }
 EXPORT_SYMBOL(of_n_size_cells);
 
-static void of_bus_default_count_cells(struct device_node *dev,
-				       int *addrc, int *sizec)
-{
-	if (addrc)
-		*addrc = of_n_addr_cells(dev);
-	if (sizec)
-		*sizec = of_n_size_cells(dev);
-}
-
-static void of_bus_count_cells(struct device_node *dev,
-			int *addrc, int *sizec)
-{
-	of_bus_default_count_cells(dev, addrc, sizec);
-}
-
 struct property *of_find_property(const struct device_node *np,
 				  const char *name, int *lenp)
 {
@@ -1543,48 +1528,22 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
 	return 0;
 }
 
-static u64 dt_mem_next_cell(int s, const __be32 **cellp)
-{
-	const __be32 *p = *cellp;
-
-	*cellp = p + s;
-	return of_read_number(p, s);
-}
-
 int of_add_memory(struct device_node *node, bool dump)
 {
-	int na, nc;
-	const __be32 *reg, *endp;
-	int len, r = 0, ret;
 	const char *device_type;
+	struct resource res;
+	int n = 0, ret;
 
 	ret = of_property_read_string(node, "device_type", &device_type);
-	if (ret)
+	if (ret || of_node_cmp(device_type, "memory"))
 		return -ENXIO;
 
-	if (of_node_cmp(device_type, "memory"))
-		return -ENXIO;
-
-	of_bus_count_cells(node, &na, &nc);
-
-	reg = of_get_property(node, "reg", &len);
-	if (!reg)
-		return -EINVAL;
-
-	endp = reg + (len / sizeof(__be32));
-
-	while ((endp - reg) >= (na + nc)) {
-		u64 base, size;
-
-		base = dt_mem_next_cell(na, &reg);
-		size = dt_mem_next_cell(nc, &reg);
-
-		if (size == 0)
+	while (!of_address_to_resource(node, n, &res)) {
+		if (!resource_size(&res))
 			continue;
-
-		of_add_memory_bank(node, dump, r, base, size);
-
-		r++;
+		of_add_memory_bank(node, dump, n,
+				res.start, resource_size(&res));
+		n++;
 	}
 
 	return 0;
-- 
1.7.2.5



From s.hauer at pengutronix.de  Wed Jun 26 04:00:53 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:53 +0200
Subject: [PATCH 07/11] ARM: i.MX53 loco: Move over to multiboard
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-8-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/freescale_mx53_loco_defconfig |  2 +-
 arch/arm/mach-imx/Kconfig                      | 12 +++++-------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/arch/arm/configs/freescale_mx53_loco_defconfig b/arch/arm/configs/freescale_mx53_loco_defconfig
index b2b4c79..dbf4f4e 100644
--- a/arch/arm/configs/freescale_mx53_loco_defconfig
+++ b/arch/arm/configs/freescale_mx53_loco_defconfig
@@ -1,5 +1,5 @@
 CONFIG_ARCH_IMX=y
-CONFIG_ARCH_IMX53=y
+CONFIG_IMX_MULTI_BOARDS=y
 CONFIG_MACH_FREESCALE_MX53_LOCO=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index f530e89..ed9ae3d 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -48,7 +48,6 @@ config BOARDINFO
 	default "Phytec phyCORE-i.MX35" if MACH_PCM043
 	default "Synertronixx scb9328" if MACH_SCB9328
 	default "Garz+Fricke Neso" if MACH_NESO
-	default "Freescale i.MX53 LOCO" if MACH_FREESCALE_MX53_LOCO
 	default "Freescale i.MX53 SMD" if MACH_FREESCALE_MX53_SMD
 	default "Efika MX smartbook" if MACH_EFIKA_MX_SMARTBOOK
 	default "Garz+Fricke Cupid" if MACH_GUF_CUPID
@@ -226,6 +225,11 @@ if IMX_MULTI_BOARDS
 config MACH_FREESCALE_MX51_PDK
 	bool "Freescale i.MX51 PDK"
 	select ARCH_IMX51
+
+config MACH_FREESCALE_MX53_LOCO
+	bool "Freescale i.MX53 LOCO"
+	select ARCH_IMX53
+
 endif
 
 # ----------------------------------------------------------
@@ -437,12 +441,6 @@ config MACH_EFIKA_MX_SMARTBOOK
 
 comment "i.MX53 Boards"
 
-config MACH_FREESCALE_MX53_LOCO
-	bool "Freescale i.MX53 LOCO"
-	select ARCH_IMX53
-	select HAVE_DEFAULT_ENVIRONMENT_NEW
-	select HAVE_PBL_MULTI_IMAGES
-
 config MACH_FREESCALE_MX53_SMD
 	bool "Freescale i.MX53 SMD"
 	select ARCH_IMX53
-- 
1.8.3.1



From s.hauer at pengutronix.de  Wed Jun 26 04:00:46 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:46 +0200
Subject: [PATCH] Multi board support
Message-ID: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>

Following multi image support we now get multi board support.

With this series it's possible to build a barebox binary for multiple
boards. At the end of this series a new imx_v7_defconfig is added
which currently builds:

 barebox-freescale-imx51-babbage.img
 barebox-genesi-efikasb.img
 barebox-freescale-imx53-loco.img
 barebox-datamodul-edm-qmx6.img

All are simply PBL/imximage wrappers around the same base binary. This
finally brings together the various pieces like relocatable binary support,
devicetree support, multiple cpu support and regular driver support for
core SoC devices.

Sascha

----------------------------------------------------------------
Sascha Hauer (11):
      ARM: i.MX: select SoC from board
      ARM: i.MX51 babbage: add board name to flash header file
      ARM: i.MX51 babbage: prepare for multiboard support
      ARM: i.MX51 babbage: Move over to multiboard
      ARM: i.MX53 loco: add board name to flash header file
      ARM: i.MX53 loco: prepare multiboard support
      ARM: i.MX53 loco: Move over to multiboard
      ARM: i.MX6 realq7: prepare multiboard support
      ARM: i.MX6 realq7: switch to multiboard
      ARM: i.MX51 efikasb: switch to multiboard support
      ARM: Add a imx_v7_defconfig

 arch/arm/boards/dmo-mx6-realq7/board.c             |  19 +-
 arch/arm/boards/efika-mx-smartbook/Makefile        |   5 +-
 arch/arm/boards/efika-mx-smartbook/board.c         |  17 +-
 arch/arm/boards/efika-mx-smartbook/dcd-data.h      |  56 ------
 .../flash-header-imx51-genesi-efikasb.imxcfg       |  57 ++++++
 arch/arm/boards/efika-mx-smartbook/flash_header.c  |  29 ---
 arch/arm/boards/efika-mx-smartbook/lowlevel.c      |  14 +-
 arch/arm/boards/freescale-mx51-pdk/Makefile        |   4 +-
 arch/arm/boards/freescale-mx51-pdk/board.c         |  21 +-
 ...er.imxcfg => flash-header-imx51-babbage.imxcfg} |   0
 arch/arm/boards/freescale-mx53-loco/Makefile       |   4 +-
 arch/arm/boards/freescale-mx53-loco/board.c        |  17 +-
 ...eader.imxcfg => flash-header-imx53-loco.imxcfg} |   0
 arch/arm/configs/dmo-realq7_defconfig              |   2 +-
 arch/arm/configs/efika-mx-smartbook_defconfig      |   1 +
 arch/arm/configs/eukrea_cpuimx25_defconfig         |   1 +
 arch/arm/configs/eukrea_cpuimx27_defconfig         |   1 +
 arch/arm/configs/eukrea_cpuimx35_defconfig         |   1 +
 arch/arm/configs/freescale-mx6-arm2_defconfig      |   1 +
 arch/arm/configs/freescale_mx51_babbage_defconfig  |   3 +-
 arch/arm/configs/freescale_mx53_loco_defconfig     |   3 +-
 arch/arm/configs/imx_v7_defconfig                  | 131 +++++++++++++
 arch/arm/configs/mx21ads_defconfig                 |   1 +
 arch/arm/configs/pcm037_defconfig                  |   1 +
 arch/arm/dts/Makefile                              |   1 +
 arch/arm/mach-imx/Kconfig                          | 215 +++++++++------------
 images/Makefile.imx                                |  10 +-
 27 files changed, 366 insertions(+), 249 deletions(-)
 delete mode 100644 arch/arm/boards/efika-mx-smartbook/dcd-data.h
 create mode 100644 arch/arm/boards/efika-mx-smartbook/flash-header-imx51-genesi-efikasb.imxcfg
 delete mode 100644 arch/arm/boards/efika-mx-smartbook/flash_header.c
 rename arch/arm/boards/freescale-mx51-pdk/{flash-header.imxcfg => flash-header-imx51-babbage.imxcfg} (100%)
 rename arch/arm/boards/freescale-mx53-loco/{flash-header.imxcfg => flash-header-imx53-loco.imxcfg} (100%)
 create mode 100644 arch/arm/configs/imx_v7_defconfig



From s.hauer at pengutronix.de  Wed Jun 26 04:00:47 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Wed, 26 Jun 2013 10:00:47 +0200
Subject: [PATCH 01/11] ARM: i.MX: select SoC from board
In-Reply-To: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372233657-19455-2-git-send-email-s.hauer@pengutronix.de>

In principle we could build barebox for multiple i.MX SoCs, so
select the correct SoC from the board selection.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/configs/eukrea_cpuimx25_defconfig        |   1 +
 arch/arm/configs/eukrea_cpuimx27_defconfig        |   1 +
 arch/arm/configs/eukrea_cpuimx35_defconfig        |   1 +
 arch/arm/configs/freescale-mx6-arm2_defconfig     |   1 +
 arch/arm/configs/freescale_mx51_babbage_defconfig |   1 +
 arch/arm/configs/freescale_mx53_loco_defconfig    |   1 +
 arch/arm/configs/mx21ads_defconfig                |   1 +
 arch/arm/configs/pcm037_defconfig                 |   1 +
 arch/arm/mach-imx/Kconfig                         | 169 +++++++++-------------
 9 files changed, 76 insertions(+), 101 deletions(-)

diff --git a/arch/arm/configs/eukrea_cpuimx25_defconfig b/arch/arm/configs/eukrea_cpuimx25_defconfig
index c3537aa..4f8a95c 100644
--- a/arch/arm/configs/eukrea_cpuimx25_defconfig
+++ b/arch/arm/configs/eukrea_cpuimx25_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARCH_IMX=y
 CONFIG_ARCH_IMX25=y
+CONFIG_MACH_EUKREA_CPUIMX25=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
 CONFIG_AEABI=y
diff --git a/arch/arm/configs/eukrea_cpuimx27_defconfig b/arch/arm/configs/eukrea_cpuimx27_defconfig
index bbcd454..97b4291 100644
--- a/arch/arm/configs/eukrea_cpuimx27_defconfig
+++ b/arch/arm/configs/eukrea_cpuimx27_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARCH_IMX=y
 CONFIG_ARCH_IMX27=y
+CONFIG_MACH_EUKREA_CPUIMX27=y
 CONFIG_IMX_CLKO=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_MMU=y
diff --git a/arch/arm/configs/eukrea_cpuimx35_defconfig b/arch/arm/configs/eukrea_cpuimx35_defconfig
index f85e9a2..88e1e3d 100644
--- a/arch/arm/configs/eukrea_cpuimx35_defconfig
+++ b/arch/arm/configs/eukrea_cpuimx35_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_IMX=y
 CONFIG_CACHE_L2X0=y
 CONFIG_ARCH_IMX35=y
+CONFIG_MACH_EUKREA_CPUIMX35=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
 CONFIG_AEABI=y
diff --git a/arch/arm/configs/freescale-mx6-arm2_defconfig b/arch/arm/configs/freescale-mx6-arm2_defconfig
index d2812e4..6982e0c 100644
--- a/arch/arm/configs/freescale-mx6-arm2_defconfig
+++ b/arch/arm/configs/freescale-mx6-arm2_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARCH_IMX=y
 CONFIG_ARCH_IMX6=y
+CONFIG_MACH_MX6Q_ARM2=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
 CONFIG_AEABI=y
diff --git a/arch/arm/configs/freescale_mx51_babbage_defconfig b/arch/arm/configs/freescale_mx51_babbage_defconfig
index d382dc8..27f3ae8 100644
--- a/arch/arm/configs/freescale_mx51_babbage_defconfig
+++ b/arch/arm/configs/freescale_mx51_babbage_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARCH_IMX=y
 CONFIG_ARCH_IMX51=y
+CONFIG_MACH_FREESCALE_MX51_PDK=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
 CONFIG_THUMB2_BAREBOX=y
diff --git a/arch/arm/configs/freescale_mx53_loco_defconfig b/arch/arm/configs/freescale_mx53_loco_defconfig
index f502f5e..b2b4c79 100644
--- a/arch/arm/configs/freescale_mx53_loco_defconfig
+++ b/arch/arm/configs/freescale_mx53_loco_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARCH_IMX=y
 CONFIG_ARCH_IMX53=y
+CONFIG_MACH_FREESCALE_MX53_LOCO=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
 CONFIG_THUMB2_BAREBOX=y
diff --git a/arch/arm/configs/mx21ads_defconfig b/arch/arm/configs/mx21ads_defconfig
index dbc2962..13c005b 100644
--- a/arch/arm/configs/mx21ads_defconfig
+++ b/arch/arm/configs/mx21ads_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARCH_IMX=y
 CONFIG_ARCH_IMX21=y
+CONFIG_MACH_IMX21ADS=y
 CONFIG_IMX_CLKO=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_TEXT_BASE=0xc3000000
diff --git a/arch/arm/configs/pcm037_defconfig b/arch/arm/configs/pcm037_defconfig
index 7c630a5..1a75701 100644
--- a/arch/arm/configs/pcm037_defconfig
+++ b/arch/arm/configs/pcm037_defconfig
@@ -1,6 +1,7 @@
 CONFIG_ARCH_IMX=y
 CONFIG_CACHE_L2X0=y
 CONFIG_ARCH_IMX31=y
+CONFIG_MACH_PCM037=y
 CONFIG_IMX_IIM=y
 CONFIG_IMX_IIM_FUSE_BLOW=y
 CONFIG_AEABI=y
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index d9291bb..ac2e9b8 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -165,112 +165,98 @@ config BAREBOX_UPDATE_IMX_EXTERNAL_NAND
 
 comment "Freescale i.MX System-on-Chip"
 
-choice
-	prompt "Freescale i.MX Processor"
-
 config ARCH_IMX1
-	bool "i.MX1"
+	bool
 	select CPU_ARM920T
 	select PINCTRL_IMX_IOMUX_V1
 
 config ARCH_IMX21
-	bool "i.MX21"
+	bool
 	select CPU_ARM926T
 	select PINCTRL_IMX_IOMUX_V1
 
 config ARCH_IMX25
-	bool "i.MX25"
+	bool
 	select CPU_ARM926T
 	select ARCH_HAS_FEC_IMX
 	select PINCTRL_IMX_IOMUX_V3
 
 config ARCH_IMX27
-	bool "i.MX27"
+	bool
 	select CPU_ARM926T
 	select ARCH_HAS_FEC_IMX
 	select PINCTRL_IMX_IOMUX_V1
 
 config ARCH_IMX31
 	select CPU_V6
-	bool "i.MX31"
+	bool
 	select PINCTRL_IMX_IOMUX_V2
 
 config ARCH_IMX35
-	bool "i.MX35"
+	bool
 	select CPU_V6
 	select ARCH_HAS_FEC_IMX
 	select PINCTRL_IMX_IOMUX_V3
 
 config ARCH_IMX51
-	bool "i.MX51"
+	bool
 	select CPU_V7
 	select ARCH_HAS_FEC_IMX
 	select PINCTRL_IMX_IOMUX_V3
 
 config ARCH_IMX53
-	bool "i.MX53"
+	bool
 	select CPU_V7
 	select ARCH_HAS_FEC_IMX
 	select PINCTRL_IMX_IOMUX_V3
 
 config ARCH_IMX6
-	bool "i.MX6"
+	bool
 	select ARCH_HAS_FEC_IMX
 	select CPU_V7
 	select PINCTRL_IMX_IOMUX_V3
 
-endchoice
-
 # ----------------------------------------------------------
 
-if ARCH_IMX1
-
 choice
-	prompt "i.MX1 Board Type"
+	prompt "Select Board"
+
+comment "i.MX1 Boards"
 
 config MACH_SCB9328
 	bool "Synertronixx scb9328"
+	select ARCH_IMX1
 	select HAS_DM9000
 	help
 	  Say Y here if you are using the Synertronixx scb9328 board
 
-endchoice
-
-endif
-
 # ----------------------------------------------------------
 
-if ARCH_IMX21
-
-choice
-	prompt "i.MX21 Board Type"
+comment "i.MX21 Boards"
 
 config MACH_IMX21ADS
 	bool "Freescale i.MX21ADS"
+	select ARCH_IMX21
 	select HAS_CS8900
 	help
 	  Say Y here if you are using the Freescale i.MX21ads board equipped
 	  with a Freescale i.MX21 Processor
 
-endchoice
-
-endif
 
 # ----------------------------------------------------------
 
-if ARCH_IMX25
-
-choice
-	prompt "i.MX25 Board Type"
+comment "i.MX25 Boards"
 
 config MACH_EUKREA_CPUIMX25
 	bool "Eukrea CPUIMX25"
+	select ARCH_IMX25
 	help
 	  Say Y here if you are using the Eukrea Electromatique's CPUIMX25
 	  equipped with a Freescale i.MX25 Processor
 
 config MACH_FREESCALE_MX25_3STACK
 	bool "Freescale MX25 3stack"
+	select ARCH_IMX25
 	select I2C
 	select MFD_MC34704
 	help
@@ -279,41 +265,39 @@ config MACH_FREESCALE_MX25_3STACK
 
 config MACH_TX25
 	bool "Ka-Ro TX25"
+	select ARCH_IMX25
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	help
 	  Say Y here if you are using the Ka-Ro tx25 board
 
-endchoice
-
-endif
-
 # ----------------------------------------------------------
 
-if ARCH_IMX27
-
-choice
-	prompt "i.MX27 Board Type"
+comment "i.MX27 Boards"
 
 config MACH_EUKREA_CPUIMX27
 	bool "EUKREA CPUIMX27"
+	select ARCH_IMX27
 	help
 	  Say Y here if you are using Eukrea's CPUIMX27 equipped
 	  with a Freescale i.MX27 Processor
 
 config MACH_IMX27ADS
 	bool "Freescale i.MX27ADS"
+	select ARCH_IMX27
 	help
 	  Say Y here if you are using the Freescale i.MX27ads board equipped
 	  with a Freescale i.MX27 Processor
 
 config MACH_PCA100
 	bool "phyCard-i.MX27"
+	select ARCH_IMX27
 	help
 	  Say Y here if you are using Phytec's phyCard-i.MX27 (pca100) equipped
 	  with a Freescale i.MX27 Processor
 
 config MACH_PCM038
 	bool "phyCORE-i.MX27"
+	select ARCH_IMX27
 	select IMX_IIM
 	select SPI
 	select DRIVER_SPI_IMX
@@ -334,23 +318,18 @@ config MACH_PCM970_BASEBOARD
 
 config MACH_NESO
 	bool "Garz+Fricke Neso"
+	select ARCH_IMX27
 	help
 	  Say Y here if you are using the Garz+Fricke Neso board equipped
 	  with a Freescale i.MX27 Processor
 
-endchoice
-
-endif
-
 # ----------------------------------------------------------
 
-if ARCH_IMX31
-
-choice
-	prompt "i.MX31 Board Type"
+comment "i.MX31 Boards"
 
 config MACH_PCM037
 	bool "phyCORE-i.MX31"
+	select ARCH_IMX31
 	select USB_ULPI if USB
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	select ARCH_HAS_L2X0
@@ -358,19 +337,13 @@ config MACH_PCM037
 	  Say Y here if you are using Phytec's phyCORE-i.MX31 (pcm037) equipped
 	  with a Freescale i.MX31 Processor
 
-endchoice
-
-endif
-
 # ----------------------------------------------------------
 
-if ARCH_IMX35
-
-choice
-	prompt "i.MX35 Board Type"
+comment "i.MX35 Boards"
 
 config MACH_EUKREA_CPUIMX35
 	bool "EUKREA CPUIMX35"
+	select ARCH_IMX35
 	select ARCH_HAS_L2X0
 	help
 	  Say Y here if you are using Eukrea's CPUIMX35 equipped
@@ -378,6 +351,7 @@ config MACH_EUKREA_CPUIMX35
 
 config MACH_FREESCALE_MX35_3STACK
 	bool "Freescale MX35 3stack"
+	select ARCH_IMX35
 	select I2C
 	select I2C_IMX
 	select MFD_MC13XXX
@@ -388,6 +362,7 @@ config MACH_FREESCALE_MX35_3STACK
 
 config MACH_PCM043
 	bool "phyCORE-i.MX35"
+	select ARCH_IMX35
 	select ARCH_HAS_L2X0
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	help
@@ -396,40 +371,38 @@ config MACH_PCM043
 
 config MACH_GUF_CUPID
 	bool "Garz+Fricke Cupid"
+	select ARCH_IMX35
 	select ARCH_HAS_L2X0
 	help
 	  Say Y here if you are using the Garz+Fricke Neso board equipped
 	  with a Freescale i.MX35 Processor
 
-endchoice
-
-endif
-
 # ----------------------------------------------------------
 
-if ARCH_IMX51
-
-choice
-	prompt "i.MX51 Board Type"
+comment "i.MX51 Boards"
 
 config MACH_FREESCALE_MX51_PDK
+	bool "Freescale i.MX51 PDK"
+	select ARCH_IMX51
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	select HAVE_PBL_MULTI_IMAGES
-	bool "Freescale i.MX51 PDK"
 
 config MACH_EUKREA_CPUIMX51SD
-	bool "EUKREA CPUIMX51"
+	bool "Ka-Ro TX51"
+	select ARCH_IMX51
 	help
 	  Say Y here if you are using Eukrea's CPUIMX51 equipped
 	  with a Freescale i.MX51 Processor
 
 config MACH_TX51
 	bool "Ka-Ro TX51"
+	select ARCH_IMX51
 	help
 	  Say Y here if you are using the Ka-Ro tx51 board
 
 config MACH_CCMX51
 	bool "ConnectCore i.MX51"
+	select ARCH_IMX51
 	select IMX_IIM
 	select SPI
 	select DRIVER_SPI_IMX
@@ -448,84 +421,65 @@ config MACH_CCMX51_BASEBOARD
 
 config MACH_EFIKA_MX_SMARTBOOK
 	bool "Efika MX smartbook"
+	select ARCH_IMX51
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	help
 	  Choose this to compile barebox for the Efika MX Smartbook
 
-endchoice
-
-endif
-
 # ----------------------------------------------------------
 
-if ARCH_IMX53
-
-choice
-	prompt "i.MX53 Board Type"
+comment "i.MX53 Boards"
 
 config MACH_FREESCALE_MX53_LOCO
+	bool "Freescale i.MX53 LOCO"
+	select ARCH_IMX53
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	select HAVE_PBL_MULTI_IMAGES
-	bool "Freescale i.MX53 LOCO"
 
 config MACH_FREESCALE_MX53_SMD
 	bool "Freescale i.MX53 SMD"
+	select ARCH_IMX53
 
 config MACH_TQMA53
-	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	bool "TQ i.MX53 TQMa53"
+	select ARCH_IMX53
+	select HAVE_DEFAULT_ENVIRONMENT_NEW
 
 config MACH_TX53
 	bool "Ka-Ro TX53"
+	select ARCH_IMX53
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	help
 	  Say Y here if you are using the Ka-Ro tx53 board
 
 config MACH_GUF_VINCELL
-	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	bool "Garz-Fricke Vincell"
+	select ARCH_IMX53
+	select HAVE_DEFAULT_ENVIRONMENT_NEW
 
-endchoice
-
-if MACH_TX53
-
-choice
-	prompt "TX53 board revision"
-config TX53_REV_1011
-	bool "1011"
-config TX53_REV_XX30
-	bool "8030 / 1030"
-
-endchoice
-
-endif
-
-endif
-
-if ARCH_IMX6
-
-choice
-	prompt "i.MX6 Board Type"
+comment "i.MX6 Boards"
 
 config MACH_MX6Q_ARM2
 	bool "Freescale i.MX6q Armadillo2"
+	select ARCH_IMX6
 
 config MACH_SABRELITE
-	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	bool "Freescale i.MX6 Sabre Lite"
+	select ARCH_IMX6
+	select HAVE_DEFAULT_ENVIRONMENT_NEW
 
 config MACH_SABRESD
 	bool "Freescale i.MX6 SabreSD"
+	select ARCH_IMX6
 
 config MACH_REALQ7
 	bool "DataModul i.MX6Q Real Qseven Board"
+	select ARCH_IMX6
 	select HAVE_DEFAULT_ENVIRONMENT_NEW
 	select HAVE_PBL_MULTI_IMAGES
 
 endchoice
 
-endif
-
 # ----------------------------------------------------------
 
 menu "Board specific settings"
@@ -607,6 +561,19 @@ config MACH_TQMA53_1GB_RAM
 
 endif
 
+if MACH_TX53
+
+choice
+	prompt "TX53 board revision"
+config TX53_REV_1011
+	bool "1011"
+config TX53_REV_XX30
+	bool "8030 / 1030"
+
+endchoice
+
+endif
+
 endmenu
 
 menu "i.MX specific settings"
-- 
1.8.3.1



From renaud.barbier at ge.com  Wed Jun 26 13:33:39 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 26 Jun 2013 18:33:39 +0100
Subject: [PATCH v3 0/8] DDR2 memory initialisation
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372268027-15271-1-git-send-email-renaud.barbier@ge.com>

This patch set addresses the following issues from the version v2.

It renames the function ddr2_spd_check to a more meaningful name.
All commits acknowledge that the base of the source code is thanks
to the U-Boot community.

Renaud Barbier (8):
  common: DDR2 SPD checksum.
  ppc asm: DDR headers
  ppc 8xxx: DDR headers
  ppc 8xxx: DIMM parameters calculation
  ppc 8xxx: DDR utility and memory options
  ppx 8xxx: DDR registers value calculation
  ppc 8xxx: core DDR driver functions
  ppc 85xx: early I2C support

 arch/ppc/ddr-8xxx/common_timing_params.h     |   44 +++
 arch/ppc/ddr-8xxx/ctrl_regs.c                |  425 ++++++++++++++++++++++++++
 arch/ppc/ddr-8xxx/ddr.h                      |  105 +++++++
 arch/ppc/ddr-8xxx/ddr2_dimm_params.c         |  303 ++++++++++++++++++
 arch/ppc/ddr-8xxx/ddr2_setctrl.c             |   58 ++++
 arch/ppc/ddr-8xxx/lc_common_dimm_params.c    |  214 +++++++++++++
 arch/ppc/ddr-8xxx/main.c                     |  238 ++++++++++++++
 arch/ppc/ddr-8xxx/options.c                  |  111 +++++++
 arch/ppc/ddr-8xxx/util.c                     |  100 ++++++
 arch/ppc/include/asm/fsl_ddr_dimm_params.h   |   60 ++++
 arch/ppc/include/asm/fsl_ddr_sdram.h         |  131 ++++++++-
 arch/ppc/mach-mpc85xx/fsl_i2c.c              |  253 +++++++++++++++
 arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h |   18 ++
 common/Makefile                              |    1 +
 common/ddr_spd.c                             |   39 +++
 include/ddr_spd.h                            |  135 ++++++++
 16 files changed, 2231 insertions(+), 4 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/common_timing_params.h
 create mode 100644 arch/ppc/ddr-8xxx/ctrl_regs.c
 create mode 100644 arch/ppc/ddr-8xxx/ddr.h
 create mode 100644 arch/ppc/ddr-8xxx/ddr2_dimm_params.c
 create mode 100644 arch/ppc/ddr-8xxx/ddr2_setctrl.c
 create mode 100644 arch/ppc/ddr-8xxx/lc_common_dimm_params.c
 create mode 100644 arch/ppc/ddr-8xxx/main.c
 create mode 100644 arch/ppc/ddr-8xxx/options.c
 create mode 100644 arch/ppc/ddr-8xxx/util.c
 create mode 100644 arch/ppc/include/asm/fsl_ddr_dimm_params.h
 create mode 100644 arch/ppc/mach-mpc85xx/fsl_i2c.c
 create mode 100644 arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h
 create mode 100644 common/ddr_spd.c
 create mode 100644 include/ddr_spd.h



From renaud.barbier at ge.com  Wed Jun 26 13:33:41 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 26 Jun 2013 18:33:41 +0100
Subject: [PATCH 2/8] ppc asm: DDR headers
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372268027-15271-3-git-send-email-renaud.barbier@ge.com>

Definitions and structures have been added to record DIMM parameters
and configure memory options.

The code is based on the equivalent files in the directory
arch/powerpc/include/asm from U-boot version git-a71d45d.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/include/asm/fsl_ddr_dimm_params.h |   60 +++++++++++++
 arch/ppc/include/asm/fsl_ddr_sdram.h       |  131 +++++++++++++++++++++++++++-
 2 files changed, 187 insertions(+), 4 deletions(-)
 create mode 100644 arch/ppc/include/asm/fsl_ddr_dimm_params.h

diff --git a/arch/ppc/include/asm/fsl_ddr_dimm_params.h b/arch/ppc/include/asm/fsl_ddr_dimm_params.h
new file mode 100644
index 0000000..73c239b
--- /dev/null
+++ b/arch/ppc/include/asm/fsl_ddr_dimm_params.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#ifndef DDR2_DIMM_PARAMS_H
+#define DDR2_DIMM_PARAMS_H
+
+#define EDC_ECC		2
+
+/* Parameters for a DDR2 dimm computed from the SPD */
+struct dimm_params_s {
+	char mpart[19];
+	uint32_t n_ranks;
+	uint64_t rank_density;
+	uint64_t capacity;
+	uint32_t data_width;
+	uint32_t primary_sdram_width;
+	uint32_t ec_sdram_width;
+	uint32_t registered_dimm;
+	uint32_t n_row_addr;
+	uint32_t n_col_addr;
+	uint32_t edc_config;		/* 0 = none, 1 = parity, 2 = ECC */
+	uint32_t n_banks_per_sdram_device;
+	uint32_t burst_lengths_bitmask;	/* BL=4 bit 2, BL=8 = bit 3 */
+	uint32_t row_density;
+	uint64_t base_address;
+	/* SDRAM clock periods */
+	uint32_t tCKmin_X_ps;
+	uint32_t tCKmin_X_minus_1_ps;
+	uint32_t tCKmin_X_minus_2_ps;
+	uint32_t tCKmax_ps;
+	/* SPD-defined CAS latencies */
+	uint32_t caslat_X;
+	uint32_t caslat_X_minus_1;
+	uint32_t caslat_X_minus_2;
+	uint32_t caslat_lowest_derated;
+	/* basic timing parameters */
+	uint32_t tRCD_ps;
+	uint32_t tRP_ps;
+	uint32_t tRAS_ps;
+	uint32_t tWR_ps;	/* maximum = 63750 ps */
+	uint32_t tWTR_ps;	/* maximum = 63750 ps */
+	uint32_t tRFC_ps;	/* max = 255 ns + 256 ns + .75 ns = 511750 ps */
+	uint32_t tRRD_ps;	/* maximum = 63750 ps */
+	uint32_t tRC_ps;	/* maximum = 254 ns + .75 ns = 254750 ps */
+	uint32_t refresh_rate_ps;
+	uint32_t tIS_ps;	/* byte 32, spd->ca_setup */
+	uint32_t tIH_ps;	/* byte 33, spd->ca_hold */
+	uint32_t tDS_ps;	/* byte 34, spd->data_setup */
+	uint32_t tDH_ps;	/* byte 35, spd->data_hold */
+	uint32_t tRTP_ps;	/* byte 38, spd->trtp */
+	uint32_t tDQSQ_max_ps;	/* byte 44, spd->tdqsq */
+	uint32_t tQHS_ps;	/* byte 45, spd->tqhs */
+};
+
+#endif
diff --git a/arch/ppc/include/asm/fsl_ddr_sdram.h b/arch/ppc/include/asm/fsl_ddr_sdram.h
index ef793c9..444bcbc 100644
--- a/arch/ppc/include/asm/fsl_ddr_sdram.h
+++ b/arch/ppc/include/asm/fsl_ddr_sdram.h
@@ -10,9 +10,40 @@
 #ifndef FSL_DDR_MEMCTL_H
 #define FSL_DDR_MEMCTL_H
 
-/*
- * DDR_SDRAM_CFG - DDR SDRAM Control Configuration
- */
+#include <ddr_spd.h>
+
+/* Basic DDR Technology. */
+#define SDRAM_TYPE_DDR1    2
+#define SDRAM_TYPE_DDR2    3
+#define SDRAM_TYPE_LPDDR1  6
+#define SDRAM_TYPE_DDR3    7
+
+#define DDR_BL4	4
+#define DDR_BL8	8
+
+#define DDR2_RTT_OFF		0
+#define DDR2_RTT_75_OHM		1
+#define DDR2_RTT_150_OHM	2
+#define DDR2_RTT_50_OHM		3
+
+#if defined(CONFIG_FSL_DDR2)
+#define FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR	(3)
+typedef struct ddr2_spd_eeprom_s generic_spd_eeprom_t;
+#define FSL_SDRAM_TYPE	SDRAM_TYPE_DDR2
+#endif
+
+#define FSL_DDR_ODT_NEVER		0x0
+#define FSL_DDR_ODT_CS			0x1
+#define FSL_DDR_ODT_ALL_OTHER_CS	0x2
+#define FSL_DDR_ODT_OTHER_DIMM		0x3
+#define FSL_DDR_ODT_ALL			0x4
+#define FSL_DDR_ODT_SAME_DIMM		0x5
+#define FSL_DDR_ODT_CS_AND_OTHER_DIMM	0x6
+#define FSL_DDR_ODT_OTHER_CS_ONSAMEDIMM	0x7
+
+#define SDRAM_CS_CONFIG_EN		0x80000000
+
+/* DDR_SDRAM_CFG - DDR SDRAM Control Configuration */
 #define SDRAM_CFG_MEM_EN		0x80000000
 #define SDRAM_CFG_SREN			0x40000000
 #define SDRAM_CFG_ECC_EN		0x20000000
@@ -23,11 +54,103 @@
 #define SDRAM_CFG_SDRAM_TYPE_SHIFT	24
 #define SDRAM_CFG_DYN_PWR		0x00200000
 #define SDRAM_CFG_32_BE			0x00080000
+#define SDRAM_CFG_16_BE			0x00100000
 #define SDRAM_CFG_8_BE			0x00040000
 #define SDRAM_CFG_NCAP			0x00020000
 #define SDRAM_CFG_2T_EN			0x00008000
 #define SDRAM_CFG_BI			0x00000001
 
-extern phys_size_t fixed_sdram(void);
+#define SDRAM_CFG2_D_INIT		0x00000010
+#define SDRAM_CFG2_ODT_CFG_MASK		0x00600000
+#define SDRAM_CFG2_ODT_NEVER		0
+#define SDRAM_CFG2_ODT_ONLY_WRITE	1
+#define SDRAM_CFG2_ODT_ONLY_READ	2
+#define SDRAM_CFG2_ODT_ALWAYS		3
+
+#define MAX_CHIP_SELECTS_PER_CTRL	4
+#define MAX_DIMM_SLOTS_PER_CTLR		4
+
+/*
+ * Memory controller characteristics and I2C parameters to
+ * read the SPD data.
+ */
+struct ddr_board_info_s {
+	uint32_t fsl_ddr_ver;
+	void __iomem *ddr_base;
+	uint32_t cs_per_ctrl;
+	uint32_t dimm_slots_per_ctrl;
+	uint32_t i2c_bus;
+	uint32_t i2c_slave;
+	uint32_t i2c_speed;
+	void __iomem *i2c_base;
+	uint8_t *spd_i2c_addr;
+};
 
+/*
+ * Generalized parameters for memory controller configuration,
+ * might be a little specific to the FSL memory controller
+ */
+struct memctl_options_s {
+	struct ddr_board_info_s *board_info;
+	uint32_t sdram_type;
+	/*
+	 * Memory organization parameters
+	 *
+	 * if DIMM is present in the system
+	 * where DIMMs are with respect to chip select
+	 * where chip selects are with respect to memory boundaries
+	 */
+	uint32_t registered_dimm_en;
+	/* Options local to a Chip Select */
+	struct cs_local_opts_s {
+		uint32_t auto_precharge;
+		uint32_t odt_rd_cfg;
+		uint32_t odt_wr_cfg;
+		uint32_t odt_rtt_norm;
+		uint32_t odt_rtt_wr;
+	} cs_local_opts[MAX_CHIP_SELECTS_PER_CTRL];
+	/* DLL reset disable */
+	uint32_t dll_rst_dis;
+	/* Operational mode parameters */
+	uint32_t ECC_mode;
+	uint32_t ECC_init_using_memctl;
+	uint32_t data_init;
+	/* Use DQS? maybe only with DDR2? */
+	uint32_t DQS_config;
+	uint32_t self_refresh_in_sleep;
+	uint32_t dynamic_power;
+	uint32_t data_bus_width;
+	uint32_t burst_length;
+	/* Global Timing Parameters */
+	uint32_t cas_latency_override;
+	uint32_t cas_latency_override_value;
+	uint32_t use_derated_caslat;
+	uint32_t additive_latency_override;
+	uint32_t additive_latency_override_value;
+	uint32_t clk_adjust;
+	uint32_t cpo_override;
+	uint32_t write_data_delay;
+	uint32_t half_strength_driver_enable;
+	uint32_t twoT_en;
+	uint32_t bstopre;
+	uint32_t tCKE_clock_pulse_width_ps;
+	uint32_t tFAW_window_four_activates_ps;
+	/* Rtt impedance */
+	uint32_t rtt_override;
+	uint32_t rtt_override_value;
+	/* Automatic self refresh */
+	uint32_t auto_self_refresh_en;
+	/* read-to-write turnaround */
+	uint32_t trwt_override;
+	uint32_t trwt;
+	/* Powerdon timings. */
+	uint32_t txp;
+	uint32_t taxpd;
+	uint32_t txard;
+	/* Load mode cycle time */
+	uint32_t tmrd;
+};
+
+extern phys_size_t fsl_ddr_sdram(void);
+extern phys_size_t fixed_sdram(void);
 #endif
-- 
1.7.1



From renaud.barbier at ge.com  Wed Jun 26 13:33:40 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 26 Jun 2013 18:33:40 +0100
Subject: [PATCH 1/8] common: DDR2 SPD checksum.
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372268027-15271-2-git-send-email-renaud.barbier@ge.com>

The code calculates the DDR2 SPD checksum as per JEDEC standard
No 21-C Appendix X (revision 1.2)

The code is based on the equivalent files from U-Boot version
git-a71d45d.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 common/Makefile   |    1 +
 common/ddr_spd.c  |   39 +++++++++++++++
 include/ddr_spd.h |  135 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 175 insertions(+), 0 deletions(-)
 create mode 100644 common/ddr_spd.c
 create mode 100644 include/ddr_spd.h

diff --git a/common/Makefile b/common/Makefile
index 2f0bd34..fc23421 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_CMD_LOADS)		+= s_record.o
 obj-$(CONFIG_OFTREE)		+= oftree.o
 
 obj-y += memory.o
+obj-$(CONFIG_DDR_SPD)  += ddr_spd.o
 obj-y += memory_display.o
 obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_TLSF) += tlsf_malloc.o
diff --git a/common/ddr_spd.c b/common/ddr_spd.c
new file mode 100644
index 0000000..c8b73ff
--- /dev/null
+++ b/common/ddr_spd.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <ddr_spd.h>
+
+uint32_t ddr2_spd_checksum_pass(const struct ddr2_spd_eeprom_s *spd)
+{
+	uint32_t i, cksum = 0;
+	const uint8_t *buf = (const uint8_t *)spd;
+	uint8_t rev, spd_cksum;
+
+	rev = spd->spd_rev;
+	spd_cksum = spd->cksum;
+
+	/* Rev 1.X or less supported by this code */
+	if (rev >= 0x20)
+		goto error;
+
+	/*
+	 * The checksum is calculated on the first 64 bytes
+	 * of the SPD as per JEDEC specification.
+	 */
+	for (i = 0; i < 63; i++)
+		cksum += *buf++;
+	cksum &= 0xFF;
+
+	if (cksum != spd_cksum)
+		goto error;
+
+	return 0;
+error:
+	return 1;
+}
diff --git a/include/ddr_spd.h b/include/ddr_spd.h
new file mode 100644
index 0000000..c8762a2
--- /dev/null
+++ b/include/ddr_spd.h
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#ifndef _DDR_SPD_H_
+#define _DDR_SPD_H_
+
+/*
+ * Format from "JEDEC Appendix X: Serial Presence Detects for DDR2 SDRAM",
+ * SPD Revision 1.2
+ */
+struct ddr2_spd_eeprom_s {
+	uint8_t info_size;   /*  0 # bytes written into serial memory */
+	uint8_t chip_size;   /*  1 Total # bytes of SPD memory device */
+	uint8_t mem_type;    /*  2 Fundamental memory type */
+	uint8_t nrow_addr;   /*  3 # of Row Addresses on this assembly */
+	uint8_t ncol_addr;   /*  4 # of Column Addrs on this assembly */
+	uint8_t mod_ranks;   /*  5 Number of DIMM Ranks */
+	uint8_t dataw;       /*  6 Module Data Width */
+	uint8_t res_7;       /*  7 Reserved */
+	uint8_t voltage;     /*  8 Voltage intf std of this assembly */
+	uint8_t clk_cycle;   /*  9 SDRAM Cycle time @ CL=X */
+	uint8_t clk_access;  /* 10 SDRAM Access from Clk @ CL=X (tAC) */
+	uint8_t config;      /* 11 DIMM Configuration type */
+	uint8_t refresh;     /* 12 Refresh Rate/Type */
+	uint8_t primw;       /* 13 Primary SDRAM Width */
+	uint8_t ecw;         /* 14 Error Checking SDRAM width */
+	uint8_t res_15;      /* 15 Reserved */
+	uint8_t burstl;      /* 16 Burst Lengths Supported */
+	uint8_t nbanks;      /* 17 # of Banks on Each SDRAM Device */
+	uint8_t cas_lat;     /* 18 CAS# Latencies Supported */
+	uint8_t mech_char;   /* 19 DIMM Mechanical Characteristics */
+	uint8_t dimm_type;   /* 20 DIMM type information */
+	uint8_t mod_attr;    /* 21 SDRAM Module Attributes */
+	uint8_t dev_attr;    /* 22 SDRAM Device Attributes */
+	uint8_t clk_cycle2;  /* 23 Min SDRAM Cycle time @ CL=X-1 */
+	uint8_t clk_access2; /* 24 SDRAM Access from Clk @ CL=X-1 (tAC) */
+	uint8_t clk_cycle3;  /* 25 Min SDRAM Cycle time @ CL=X-2 */
+	uint8_t clk_access3; /* 26 Max Access from Clk @ CL=X-2 (tAC) */
+	uint8_t trp;         /* 27 Min Row Precharge Time (tRP)*/
+	uint8_t trrd;        /* 28 Min Row Active to Row Active (tRRD) */
+	uint8_t trcd;        /* 29 Min RAS to CAS Delay (tRCD) */
+	uint8_t tras;        /* 30 Minimum RAS Pulse Width (tRAS) */
+	uint8_t rank_dens;   /* 31 Density of each rank on module */
+	uint8_t ca_setup;    /* 32 Addr+Cmd Setup Time Before Clk (tIS) */
+	uint8_t ca_hold;     /* 33 Addr+Cmd Hold Time After Clk (tIH) */
+	uint8_t data_setup;  /* 34 Data Input Setup Time Before Strobe
+					(tDS) */
+	uint8_t data_hold;   /* 35 Data Input Hold Time
+					After Strobe (tDH) */
+	uint8_t twr;         /* 36 Write Recovery time tWR */
+	uint8_t twtr;        /* 37 Int write to read delay tWTR */
+	uint8_t trtp;        /* 38 Int read to precharge delay tRTP */
+	uint8_t mem_probe;   /* 39 Mem analysis probe characteristics */
+	uint8_t trctrfc_ext; /* 40 Extensions to trc and trfc */
+	uint8_t trc;         /* 41 Min Active to Auto refresh time tRC */
+	uint8_t trfc;        /* 42 Min Auto to Active period tRFC */
+	uint8_t tckmax;      /* 43 Max device cycle time tCKmax */
+	uint8_t tdqsq;       /* 44 Max DQS to DQ skew (tDQSQ max) */
+	uint8_t tqhs;        /* 45 Max Read DataHold skew (tQHS) */
+	uint8_t pll_relock;  /* 46 PLL Relock time */
+	uint8_t Tcasemax;    /* 47 Tcasemax */
+	uint8_t psiTAdram;   /* 48 Thermal Resistance of DRAM Package
+					from Top (Case) to Ambient
+					(Psi T-A DRAM) */
+	uint8_t dt0_mode;    /* 49 DRAM Case Temperature Rise from
+					Ambient due to Activate-Precharge/Mode
+					Bits (DT0/Mode Bits) */
+	uint8_t dt2n_dt2q;   /* 50 DRAM Case Temperature Rise from
+					Ambient due to Precharge/Quiet Standby
+					(DT2N/DT2Q) */
+	uint8_t dt2p;        /* 51 DRAM Case Temperature Rise from
+					Ambient due to Precharge Power-Down
+					(DT2P) */
+	uint8_t dt3n;        /* 52 DRAM Case Temperature Rise from
+					Ambient due to Active Standby (DT3N) */
+	uint8_t dt3pfast;    /* 53 DRAM Case Temperature Rise from
+					Ambient due to Active Power-Down with
+					Fast PDN Exit (DT3Pfast) */
+	uint8_t dt3pslow;    /* 54 DRAM Case Temperature Rise from
+					Ambient due to Active Power-Down with
+					Slow PDN Exit (DT3Pslow) */
+	uint8_t dt4r_dt4r4w; /* 55 DRAM Case Temperature Rise from
+					Ambient due to Page Open Burst
+					Read/DT4R4W Mode Bit
+					(DT4R/DT4R4W Mode Bit) */
+	uint8_t dt5b;        /* 56 DRAM Case Temperature Rise from
+					Ambient due to Burst Refresh (DT5B) */
+	uint8_t dt7;         /* 57 DRAM Case Temperature Rise from
+					Ambient due to Bank Interleave Reads
+					with Auto-Precharge (DT7) */
+	uint8_t psiTApll;    /* 58 Thermal Resistance of PLL Package
+					form Top (Case) to Ambient
+					(Psi T-A PLL) */
+	uint8_t psiTAreg;    /* 59 Thermal Reisitance of Register
+					Package from Top (Case) to Ambient
+					(Psi T-A Register) */
+	uint8_t dtpllactive; /* 60 PLL Case Temperature Rise from
+					Ambient due to PLL Active
+					(DT PLL Active) */
+	uint8_t dtregact;    /* 61 Register Case Temperature Rise from
+					Ambient due to Register Active/Mode
+					Bit (DT Register Active/Mode Bit) */
+	uint8_t spd_rev;     /* 62 SPD Data Revision Code */
+	uint8_t cksum;       /* 63 Checksum for bytes 0-62 */
+	uint8_t mid[8];      /* 64 Mfr's JEDEC ID code per JEP-106 */
+	uint8_t mloc;        /* 72 Manufacturing Location */
+	uint8_t mpart[18];   /* 73 Manufacturer's Part Number */
+	uint8_t rev[2];      /* 91 Revision Code */
+	uint8_t mdate[2];    /* 93 Manufacturing Date */
+	uint8_t sernum[4];   /* 95 Assembly Serial Number */
+	uint8_t mspec[27];   /* 99-127 Manufacturer Specific Data */
+
+};
+
+extern uint32_t ddr2_spd_checksum_pass(const struct ddr2_spd_eeprom_s *spd);
+
+/* * Byte 2 Fundamental Memory Types. */
+#define SPD_MEMTYPE_DDR2	(0x08)
+
+/* DIMM Type for DDR2 SPD (according to v1.3) */
+#define DDR2_SPD_DIMMTYPE_RDIMM		(0x01)
+#define DDR2_SPD_DIMMTYPE_UDIMM		(0x02)
+#define DDR2_SPD_DIMMTYPE_SO_DIMM	(0x04)
+#define DDR2_SPD_DIMMTYPE_72B_SO_CDIMM	(0x06)
+#define DDR2_SPD_DIMMTYPE_72B_SO_RDIMM	(0x07)
+#define DDR2_SPD_DIMMTYPE_MICRO_DIMM	(0x08)
+#define DDR2_SPD_DIMMTYPE_MINI_RDIMM	(0x10)
+#define DDR2_SPD_DIMMTYPE_MINI_UDIMM	(0x20)
+
+#endif /* _DDR_SPD_H_ */
-- 
1.7.1



From renaud.barbier at ge.com  Wed Jun 26 13:33:42 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 26 Jun 2013 18:33:42 +0100
Subject: [PATCH 3/8] ppc 8xxx: DDR headers
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372268027-15271-4-git-send-email-renaud.barbier@ge.com>

Structures are defined to record the common DIMM parameters
and memory options on a per DIMM basis.

This code is based on the equivalent files in directory
arch/powerpc/cpu/mpc8xxx/ddr from U-Boot version git-a71d45d.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/common_timing_params.h |   44 ++++++++++++
 arch/ppc/ddr-8xxx/ddr.h                  |  105 ++++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/common_timing_params.h
 create mode 100644 arch/ppc/ddr-8xxx/ddr.h

diff --git a/arch/ppc/ddr-8xxx/common_timing_params.h b/arch/ppc/ddr-8xxx/common_timing_params.h
new file mode 100644
index 0000000..b262193
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/common_timing_params.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#ifndef COMMON_TIMING_PARAMS_H
+#define COMMON_TIMING_PARAMS_H
+
+struct common_timing_params_s {
+	uint32_t tCKmin_X_ps;
+	uint32_t tCKmax_ps;
+	uint32_t tCKmax_max_ps;
+	uint32_t tRCD_ps;
+	uint32_t tRP_ps;
+	uint32_t tRAS_ps;
+	uint32_t tWR_ps;	/* maximum = 63750 ps */
+	uint32_t tWTR_ps;	/* maximum = 63750 ps */
+	uint32_t tRFC_ps;	/* maximum = 255 ns + 256 ns + .75 ns
+					   = 511750 ps */
+	uint32_t tRRD_ps;	/* maximum = 63750 ps */
+	uint32_t tRC_ps;	/* maximum = 254 ns + .75 ns = 254750 ps */
+	uint32_t refresh_rate_ps;
+	uint32_t tIS_ps;	/* byte 32, spd->ca_setup */
+	uint32_t tIH_ps;	/* byte 33, spd->ca_hold */
+	uint32_t tDS_ps;	/* byte 34, spd->data_setup */
+	uint32_t tDH_ps;	/* byte 35, spd->data_hold */
+	uint32_t tRTP_ps;	/* byte 38, spd->trtp */
+	uint32_t tDQSQ_max_ps;	/* byte 44, spd->tdqsq */
+	uint32_t tQHS_ps;	/* byte 45, spd->tqhs */
+	uint32_t ndimms_present;
+	uint32_t lowest_common_SPD_caslat;
+	uint32_t highest_common_derated_caslat;
+	uint32_t additive_latency;
+	uint32_t all_DIMMs_burst_lengths_bitmask;
+	uint32_t all_DIMMs_registered;
+	uint32_t all_DIMMs_ECC_capable;
+	uint64_t total_mem;
+	uint64_t base_address;
+};
+
+#endif
diff --git a/arch/ppc/ddr-8xxx/ddr.h b/arch/ppc/ddr-8xxx/ddr.h
new file mode 100644
index 0000000..6574500
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/ddr.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2013 GE Intelligent Platforms, Inc
+ * Copyright 2008-2011 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#ifndef FSL_DDR_MAIN_H
+#define FSL_DDR_MAIN_H
+
+#include <asm/fsl_ddr_sdram.h>
+#include <asm/fsl_ddr_dimm_params.h>
+#include <mach/fsl_i2c.h>
+#include <mach/clock.h>
+#include "common_timing_params.h"
+
+#ifdef CONFIG_MPC85xx
+#include <mach/immap_85xx.h>
+#endif
+
+/* Record of computed register values. */
+struct fsl_ddr_cfg_regs_s {
+	struct {
+		uint32_t bnds;
+		uint32_t config;
+		uint32_t config_2;
+	} cs[MAX_CHIP_SELECTS_PER_CTRL];
+	uint32_t timing_cfg_3;
+	uint32_t timing_cfg_0;
+	uint32_t timing_cfg_1;
+	uint32_t timing_cfg_2;
+	uint32_t ddr_sdram_cfg;
+	uint32_t ddr_sdram_cfg_2;
+	uint32_t ddr_sdram_mode;
+	uint32_t ddr_sdram_mode_2;
+	uint32_t ddr_sdram_mode_3;
+	uint32_t ddr_sdram_mode_4;
+	uint32_t ddr_sdram_mode_5;
+	uint32_t ddr_sdram_mode_6;
+	uint32_t ddr_sdram_mode_7;
+	uint32_t ddr_sdram_mode_8;
+	uint32_t ddr_sdram_md_cntl;
+	uint32_t ddr_sdram_interval;
+	uint32_t ddr_data_init;
+	uint32_t ddr_sdram_clk_cntl;
+	uint32_t ddr_init_addr;
+	uint32_t ddr_init_ext_addr;
+	uint32_t err_disable;
+	uint32_t err_int_en;
+	uint32_t debug[32];
+};
+
+/*
+ * Data Structures
+ *
+ * All data structures have to be on the stack
+ */
+struct fsl_ddr_info_s {
+	generic_spd_eeprom_t
+	spd_installed_dimms[MAX_DIMM_SLOTS_PER_CTLR];
+	struct dimm_params_s
+		dimm_params[MAX_DIMM_SLOTS_PER_CTLR];
+	struct memctl_options_s memctl_opts;
+	struct common_timing_params_s common_timing_params;
+	struct fsl_ddr_cfg_regs_s fsl_ddr_config_reg;
+	struct ddr_board_info_s board_info;
+};
+
+uint32_t mclk_to_picos(uint32_t mclk);
+uint32_t get_memory_clk_period_ps(void);
+uint32_t picos_to_mclk(uint32_t picos);
+uint32_t check_fsl_memctl_config_regs(const struct fsl_ddr_cfg_regs_s *ddr);
+uint64_t fsl_ddr_compute(struct fsl_ddr_info_s *pinfo);
+uint32_t compute_fsl_memctl_config_regs(
+		const struct memctl_options_s *popts,
+		struct fsl_ddr_cfg_regs_s *ddr,
+		const struct common_timing_params_s *common_dimm,
+		const struct dimm_params_s *dimm_parameters,
+		uint32_t dbw_capacity_adjust);
+uint32_t compute_dimm_parameters(
+		const generic_spd_eeprom_t *spdin,
+		struct dimm_params_s *pdimm);
+uint32_t compute_lowest_common_dimm_parameters(
+		const struct dimm_params_s *dimm_params,
+		struct common_timing_params_s *outpdimm,
+		uint32_t number_of_dimms);
+uint32_t populate_memctl_options(
+		int all_DIMMs_registered,
+		struct memctl_options_s *popts,
+		struct dimm_params_s *pdimm);
+int fsl_ddr_set_lawbar(
+		const struct common_timing_params_s *memctl_common_params,
+		uint32_t memctl_interleaved);
+int fsl_ddr_get_spd(
+		generic_spd_eeprom_t *ctrl_dimms_spd,
+		struct ddr_board_info_s *binfo);
+int fsl_ddr_set_memctl_regs(
+		const struct fsl_ddr_info_s *info);
+void fsl_ddr_board_options(
+		struct memctl_options_s *popts,
+		struct dimm_params_s *pdimm);
+void fsl_ddr_board_info(struct ddr_board_info_s *info);
+#endif
-- 
1.7.1



From renaud.barbier at ge.com  Wed Jun 26 13:33:44 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 26 Jun 2013 18:33:44 +0100
Subject: [PATCH 5/8] ppc 8xxx: DDR utility and memory options
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372268027-15271-6-git-send-email-renaud.barbier@ge.com>

This commit adds functions to calculate clock cycles, configure the
LAW registers and populate board memory options.

This code is based on the equivalent files in directory
arch/powerpc/cpu/mpc8xxx/ddr from U-Boot version git-a71d45d.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/options.c |  111 +++++++++++++++++++++++++++++++++++++++++++
 arch/ppc/ddr-8xxx/util.c    |  100 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 211 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/options.c
 create mode 100644 arch/ppc/ddr-8xxx/util.c

diff --git a/arch/ppc/ddr-8xxx/options.c b/arch/ppc/ddr-8xxx/options.c
new file mode 100644
index 0000000..22b621f
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/options.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2008, 2010-2012 Freescale Semiconductor, Inc.
+ *
+ * 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.
+ */
+
+#include <common.h>
+#include <asm/fsl_ddr_sdram.h>
+#include "ddr.h"
+
+uint32_t populate_memctl_options(int all_DIMMs_registered,
+		struct memctl_options_s *popts,
+		struct dimm_params_s *pdimm)
+{
+	const struct ddr_board_info_s *binfo = popts->board_info;
+	uint32_t i;
+
+	for (i = 0; i < binfo->cs_per_ctrl; i++) {
+		popts->cs_local_opts[i].odt_rd_cfg = FSL_DDR_ODT_NEVER;
+		popts->cs_local_opts[i].odt_wr_cfg = FSL_DDR_ODT_ALL;
+		popts->cs_local_opts[i].odt_rtt_norm = DDR2_RTT_50_OHM;
+		popts->cs_local_opts[i].odt_rtt_wr = DDR2_RTT_OFF;
+		popts->cs_local_opts[i].auto_precharge = 0;
+	}
+
+	/* Memory Organization Parameters */
+	popts->registered_dimm_en = all_DIMMs_registered;
+	popts->ECC_mode = 0;		  /* 0 = disabled, 1 = enabled */
+	popts->ECC_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
+
+	/* Choose DQS config - 1 for DDR2 */
+	popts->DQS_config = 1;
+
+	/* Choose self-refresh during sleep. */
+	popts->self_refresh_in_sleep = 1;
+
+	/* Choose dynamic power management mode. */
+	popts->dynamic_power = 0;
+
+	/*
+	 * check first dimm for primary sdram width
+	 * assuming all dimms are similar
+	 * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
+	 */
+	if (pdimm->n_ranks != 0) {
+		if ((pdimm->data_width >= 64) && (pdimm->data_width <= 72))
+			popts->data_bus_width = 0;
+		else if ((pdimm->data_width >= 32) ||
+			(pdimm->data_width <= 40))
+			popts->data_bus_width = 1;
+		else
+			panic("data width %u is invalid!\n",
+					pdimm->data_width);
+	}
+
+	/* Must be a burst length of 4 for DD2 */
+	popts->burst_length = DDR_BL4;
+	/* Decide whether to use the computed de-rated latency */
+	popts->use_derated_caslat = 0;
+
+	/*
+	 * 2T_EN setting
+	 *
+	 * Factors to consider for 2T_EN:
+	 *	- number of DIMMs installed
+	 *	- number of components, number of active ranks
+	 *	- how much time you want to spend playing around
+	 */
+	popts->twoT_en = 0;
+
+	/*
+	 * Default BSTTOPRE precharge interval
+	 *
+	 * Set the parameter to 0 for global auto precharge in
+	 * the board options function.
+	 */
+	popts->bstopre = 0x100;
+
+	/* Minimum CKE pulse width -- tCKE(MIN) */
+	popts->tCKE_clock_pulse_width_ps
+		= mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
+
+	/*
+	 * Window for four activates -- tFAW
+	 *
+	 * Set according to specification for the memory used.
+	 * The default value below would work for x4/x8 wide memory.
+	 *
+	 */
+	popts->tFAW_window_four_activates_ps = 37500;
+
+	/*
+	 * Default powerdown exit timings.
+	 * Set according to specifications for the memory used in
+	 * the board options function.
+	 */
+	popts->txard = 3;
+	popts->txp = 3;
+	popts->taxpd = 11;
+
+	/* Default value for load mode cycle time */
+	popts->tmrd = 2;
+
+	/* Specific board override parameters. */
+	fsl_ddr_board_options(popts, pdimm);
+
+	return 0;
+}
diff --git a/arch/ppc/ddr-8xxx/util.c b/arch/ppc/ddr-8xxx/util.c
new file mode 100644
index 0000000..626b5f3
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/util.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2008-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <asm/fsl_law.h>
+#include <asm-generic/div64.h>
+#include <mach/clock.h>
+#include "ddr.h"
+
+#define ULL_2E12 2000000000000ULL
+#define UL_5POW12 244140625UL
+#define UL_2POW13 (1UL << 13)
+#define ULL_8FS 0xFFFFFFFFULL
+
+/*
+ * Round up mclk_ps to nearest 1 ps in memory controller code
+ * if the error is 0.5ps or more.
+ *
+ * If an imprecise data rate is too high due to rounding error
+ * propagation, compute a suitably rounded mclk_ps to compute
+ * a working memory controller configuration.
+ */
+uint32_t get_memory_clk_period_ps(void)
+{
+	uint32_t result, data_rate = fsl_get_ddr_freq(0);
+	/* Round to nearest 10ps, being careful about 64-bit multiply/divide */
+	uint64_t rem, mclk_ps = ULL_2E12;
+
+	/* Now perform the big divide, the result fits in 32-bits */
+	rem = do_div(mclk_ps, data_rate);
+	if (rem >= (data_rate >> 1))
+		result = mclk_ps + 1;
+	else
+		result = mclk_ps;
+
+	return result;
+}
+
+/* Convert picoseconds into DRAM clock cycles (rounding up if needed). */
+uint32_t picos_to_mclk(uint32_t picos)
+{
+	uint64_t clks, clks_rem;
+	uint32_t data_rate = fsl_get_ddr_freq(0);
+
+	if (!picos)
+		return 0;
+
+	/* First multiply the time by the data rate (32x32 => 64) */
+	clks = picos * (uint64_t)data_rate;
+	/*
+	 * Now divide by 5^12 and track the 32-bit remainder, then divide
+	 * by 2*(2^12) using shifts (and updating the remainder).
+	 */
+	clks_rem = do_div(clks, UL_5POW12);
+	clks_rem += (clks & (UL_2POW13 - 1)) * UL_5POW12;
+	clks >>= 13;
+
+	/* If we had a remainder greater than the 1ps error, then round up */
+	if (clks_rem > data_rate)
+		clks++;
+
+	if (clks > ULL_8FS)
+		clks = ULL_8FS;
+
+	return (uint32_t)clks;
+}
+
+uint32_t mclk_to_picos(unsigned int mclk)
+{
+	return get_memory_clk_period_ps() * mclk;
+}
+
+int fsl_ddr_set_lawbar(
+		const struct common_timing_params_s *params,
+		uint32_t law_memctl)
+{
+	uint64_t base = params->base_address;
+	uint64_t size = params->total_mem;
+
+	if (!params->ndimms_present)
+		goto out;
+
+	if (base >= MAX_MEM_MAPPED)
+		goto error;
+
+	if ((base + size) >= MAX_MEM_MAPPED)
+		size = MAX_MEM_MAPPED - base;
+
+	if (fsl_set_ddr_laws(base, size, law_memctl) < 0)
+		goto error;
+out:
+	return 0;
+error:
+	return 1;
+}
-- 
1.7.1



From renaud.barbier at ge.com  Wed Jun 26 13:33:43 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 26 Jun 2013 18:33:43 +0100
Subject: [PATCH 4/8] ppc 8xxx: DIMM parameters calculation
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372268027-15271-5-git-send-email-renaud.barbier@ge.com>

This code calculates the DIMM characteritics i.e DIMM
organization parameters and timings for DDR2 memory based on
SPD data.

It also provides a function to find out the lowest common DIMM
parameters to be used for all DIMMs.

This code is based on the equivalent files in directory
arch/powerpc/cpu/mpc8xxx/ddr from U-Boot version git-a71d45d.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/ddr2_dimm_params.c      |  303 +++++++++++++++++++++++++++++
 arch/ppc/ddr-8xxx/lc_common_dimm_params.c |  214 ++++++++++++++++++++
 2 files changed, 517 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/ddr2_dimm_params.c
 create mode 100644 arch/ppc/ddr-8xxx/lc_common_dimm_params.c

diff --git a/arch/ppc/ddr-8xxx/ddr2_dimm_params.c b/arch/ppc/ddr-8xxx/ddr2_dimm_params.c
new file mode 100644
index 0000000..b36a888
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/ddr2_dimm_params.c
@@ -0,0 +1,303 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <asm/fsl_ddr_sdram.h>
+#include "ddr.h"
+/*
+ * Calculate the Density of each Physical Rank.
+ * Returned size is in bytes.
+ *
+ * Table comes from Byte 31 of JEDEC SPD Spec.
+ *
+ *		DDR II
+ *	Bit	Size	Size
+ *	---	-----
+ *	7 high	512MB
+ *	6	256MB
+ *	5	128MB
+ *	4	 16GB
+ *	3	  8GB
+ *	2	  4GB
+ *	1	  2GB
+ *	0 low	  1GB
+ *
+ * Reorder Table to be linear by stripping the bottom
+ * 2 or 5 bits off and shifting them up to the top.
+ *
+ */
+static uint64_t compute_ranksize(uint32_t mem_type, unsigned char row_dens)
+{
+	uint64_t bsize;
+
+	bsize = ((row_dens >> 5) | ((row_dens & 31) << 3));
+	bsize <<= 27ULL;
+
+	return bsize;
+}
+
+/*
+ * Convert a two-nibble BCD value into a cycle time.
+ * While the spec calls for nano-seconds, picos are returned.
+ */
+static uint32_t convert_bcd_tenths_to_cycle_time_ps(uint32_t spd_val)
+{
+	uint32_t tenths_ps[16] = {
+		0,
+		100,
+		200,
+		300,
+		400,
+		500,
+		600,
+		700,
+		800,
+		900,
+		250,
+		330,
+		660,
+		750,
+		0,
+		0
+	};
+	uint32_t whole_ns = (spd_val & 0xF0) >> 4;
+	uint32_t tenth_ns = spd_val & 0x0F;
+	uint32_t ps = (whole_ns * 1000) + tenths_ps[tenth_ns];
+
+	return ps;
+}
+
+static uint32_t convert_bcd_hundredths_to_cycle_time_ps(uint32_t spd_val)
+{
+	uint32_t tenth_ns = (spd_val & 0xF0) >> 4;
+	uint32_t hundredth_ns = spd_val & 0x0F;
+	uint32_t ps = (tenth_ns * 100) + (hundredth_ns * 10);
+
+	return ps;
+}
+
+static uint32_t byte40_table_ps[8] = {
+	0,
+	250,
+	330,
+	500,
+	660,
+	750,
+	0,
+	0
+};
+
+static uint32_t
+compute_trfc_ps_from_spd(unsigned char trctrfc_ext, unsigned char trfc)
+{
+	uint32_t trfc_ps;
+
+	trfc_ps = (((trctrfc_ext & 0x1) * 256) + trfc) * 1000;
+	trfc_ps += byte40_table_ps[(trctrfc_ext >> 1) & 0x7];
+
+	return trfc_ps;
+}
+
+static uint32_t
+compute_trc_ps_from_spd(unsigned char trctrfc_ext, unsigned char trc)
+{
+	uint32_t trc_ps;
+
+	trc_ps = (trc * 1000);
+	trc_ps += byte40_table_ps[(trctrfc_ext >> 4) & 0x7];
+
+	return trc_ps;
+}
+
+/*
+ * Determine Refresh Rate.
+ * Table from SPD Spec, Byte 12, converted to picoseconds and
+ * filled in with "default" normal values.
+ */
+static uint32_t determine_refresh_rate_ps(const uint32_t spd_refresh)
+{
+	uint32_t refresh_time_ps[8] = {
+		15625000,	/* 0 Normal    1.00x */
+		3900000,	/* 1 Reduced    .25x */
+		7800000,	/* 2 Extended   .50x */
+		31300000,	/* 3 Extended  2.00x */
+		62500000,	/* 4 Extended  4.00x */
+		125000000,	/* 5 Extended  8.00x */
+		15625000,	/* 6 Normal    1.00x  filler */
+		15625000,	/* 7 Normal    1.00x  filler */
+	};
+
+	return refresh_time_ps[spd_refresh & 0x7];
+}
+
+/*
+ * The purpose of this function is to compute a suitable
+ * CAS latency given the DRAM clock period. The SPD only
+ * defines at most 3 CAS latencies. Typically the slower in
+ * frequency the DIMM runs at, the shorter its CAS latency can.
+ * be. If the DIMM is operating at a sufficiently low frequency,
+ * it may be able to run at a CAS latency shorter than the
+ * shortest SPD-defined CAS latency.
+ *
+ * If a CAS latency is not found, 0 is returned.
+ *
+ * Do this by finding in the standard speed table the longest
+ * tCKmin that doesn't exceed the value of mclk_ps (tCK).
+ *
+ * An assumption made is that the SDRAM device allows the
+ * CL to be programmed for a value that is lower than those
+ * advertised by the SPD. This is not always the case,
+ * as those modes not defined in the SPD are optional.
+ *
+ * CAS latency de-rating based upon values JEDEC Standard No. 79-2C
+ * Table 40, "DDR2 SDRAM standard speed bins and tCK, tRCD, tRP, tRAS,
+ * and tRC for corresponding bin"
+ *
+ * ordinal 2, ddr2_speed_bins[1] contains tCK for CL=3
+ * Not certain if any good value exists for CL=2
+ */
+			  /* CL2  CL3   CL4   CL5   CL6   CL7 */
+uint16_t ddr2_speed_bins[] = { 0, 5000, 3750, 3000, 2500, 1875 };
+
+uint32_t compute_derated_DDR2_CAS_latency(uint32_t mclk_ps)
+{
+	const uint32_t num_speed_bins = ARRAY_SIZE(ddr2_speed_bins);
+	uint32_t lowest_tCKmin_found = 0, lowest_tCKmin_CL = 0, i, x;
+
+	for (i = 0; i < num_speed_bins; i++) {
+		x = ddr2_speed_bins[i];
+		if (x && (x <= mclk_ps) && (x >= lowest_tCKmin_found)) {
+			lowest_tCKmin_found = x;
+			lowest_tCKmin_CL = i + 2;
+		}
+	}
+
+	return lowest_tCKmin_CL;
+}
+
+/*
+ * compute_dimm_parameters for DDR2 SPD
+ *
+ * Compute DIMM parameters based upon the SPD information in SPD.
+ * Writes the results to the dimm_params_s structure pointed by pdimm.
+ */
+uint32_t
+compute_dimm_parameters(const generic_spd_eeprom_t *spdin,
+		struct dimm_params_s *pdimm)
+{
+	const struct ddr2_spd_eeprom_s *spd = spdin;
+	uint32_t retval;
+
+	if (!spd->mem_type) {
+		memset(pdimm, 0, sizeof(struct dimm_params_s));
+		goto error;
+	}
+
+	if (spd->mem_type != SPD_MEMTYPE_DDR2)
+		goto error;
+
+	retval = ddr2_spd_checksum_pass(spd);
+	if (retval)
+		goto spd_err;
+
+	/*
+	 * The part name in ASCII in the SPD EEPROM is not null terminated.
+	 * Guarantee null termination here by presetting all bytes to 0
+	 * and copying the part name in ASCII from the SPD onto it
+	 */
+	memset(pdimm->mpart, 0, sizeof(pdimm->mpart));
+	memcpy(pdimm->mpart, spd->mpart, sizeof(pdimm->mpart) - 1);
+
+	/* DIMM organization parameters */
+	pdimm->n_ranks = (spd->mod_ranks & 0x7) + 1;
+	pdimm->rank_density = compute_ranksize(spd->mem_type, spd->rank_dens);
+	pdimm->capacity = pdimm->n_ranks * pdimm->rank_density;
+	pdimm->data_width = spd->dataw;
+	pdimm->primary_sdram_width = spd->primw;
+	pdimm->ec_sdram_width = spd->ecw;
+
+	/* These are all the types defined by the JEDEC DDR2 SPD 1.3 spec */
+	switch (spd->dimm_type) {
+	case DDR2_SPD_DIMMTYPE_RDIMM:
+	case DDR2_SPD_DIMMTYPE_72B_SO_RDIMM:
+	case DDR2_SPD_DIMMTYPE_MINI_RDIMM:
+		/* Registered/buffered DIMMs */
+		pdimm->registered_dimm = 1;
+		break;
+
+	case DDR2_SPD_DIMMTYPE_UDIMM:
+	case DDR2_SPD_DIMMTYPE_SO_DIMM:
+	case DDR2_SPD_DIMMTYPE_MICRO_DIMM:
+	case DDR2_SPD_DIMMTYPE_MINI_UDIMM:
+		/* Unbuffered DIMMs */
+		pdimm->registered_dimm = 0;
+		break;
+
+	case DDR2_SPD_DIMMTYPE_72B_SO_CDIMM:
+	default:
+		goto error;
+	}
+
+	pdimm->n_row_addr = spd->nrow_addr;
+	pdimm->n_col_addr = spd->ncol_addr;
+	pdimm->n_banks_per_sdram_device = spd->nbanks;
+	pdimm->edc_config = spd->config;
+	pdimm->burst_lengths_bitmask = spd->burstl;
+	pdimm->row_density = spd->rank_dens;
+
+	/*
+	 * Calculate the Maximum Data Rate based on the Minimum Cycle time.
+	 * The SPD clk_cycle field (tCKmin) is measured in tenths of
+	 * nanoseconds and represented as BCD.
+	 */
+	pdimm->tCKmin_X_ps
+	    = convert_bcd_tenths_to_cycle_time_ps(spd->clk_cycle);
+	pdimm->tCKmin_X_minus_1_ps
+	    = convert_bcd_tenths_to_cycle_time_ps(spd->clk_cycle2);
+	pdimm->tCKmin_X_minus_2_ps
+	    = convert_bcd_tenths_to_cycle_time_ps(spd->clk_cycle3);
+	pdimm->tCKmax_ps = convert_bcd_tenths_to_cycle_time_ps(spd->tckmax);
+
+	/*
+	 * Compute CAS latencies defined by SPD
+	 * The SPD caslat_X should have at least 1 and at most 3 bits set.
+	 *
+	 * If cas_lat after masking is 0, the __ilog2 function returns
+	 * 255 into the variable. This behavior is abused once.
+	 */
+	pdimm->caslat_X = __ilog2(spd->cas_lat);
+	pdimm->caslat_X_minus_1 = __ilog2(spd->cas_lat
+					  & ~(1 << pdimm->caslat_X));
+	pdimm->caslat_X_minus_2 = __ilog2(spd->cas_lat & ~(1 << pdimm->caslat_X)
+					  & ~(1 << pdimm->caslat_X_minus_1));
+	pdimm->caslat_lowest_derated
+	    = compute_derated_DDR2_CAS_latency(get_memory_clk_period_ps());
+	pdimm->tRCD_ps = spd->trcd * 250;
+	pdimm->tRP_ps = spd->trp * 250;
+	pdimm->tRAS_ps = spd->tras * 1000;
+	pdimm->tWR_ps = spd->twr * 250;
+	pdimm->tWTR_ps = spd->twtr * 250;
+	pdimm->tRFC_ps = compute_trfc_ps_from_spd(spd->trctrfc_ext, spd->trfc);
+	pdimm->tRRD_ps = spd->trrd * 250;
+	pdimm->tRC_ps = compute_trc_ps_from_spd(spd->trctrfc_ext, spd->trc);
+	pdimm->refresh_rate_ps = determine_refresh_rate_ps(spd->refresh);
+	pdimm->tIS_ps = convert_bcd_hundredths_to_cycle_time_ps(spd->ca_setup);
+	pdimm->tIH_ps = convert_bcd_hundredths_to_cycle_time_ps(spd->ca_hold);
+	pdimm->tDS_ps
+	    = convert_bcd_hundredths_to_cycle_time_ps(spd->data_setup);
+	pdimm->tDH_ps = convert_bcd_hundredths_to_cycle_time_ps(spd->data_hold);
+	pdimm->tRTP_ps = spd->trtp * 250;
+	pdimm->tDQSQ_max_ps = spd->tdqsq * 10;
+	pdimm->tQHS_ps = spd->tqhs * 10;
+
+	return 0;
+error:
+	return 1;
+spd_err:
+	return 2;
+}
diff --git a/arch/ppc/ddr-8xxx/lc_common_dimm_params.c b/arch/ppc/ddr-8xxx/lc_common_dimm_params.c
new file mode 100644
index 0000000..a1addb0
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/lc_common_dimm_params.c
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2008-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <config.h>
+#include <asm/fsl_ddr_sdram.h>
+
+#include "ddr.h"
+
+static unsigned int common_burst_length(
+		const struct dimm_params_s *dimm_params,
+		const unsigned int number_of_dimms)
+{
+	unsigned int i, temp;
+
+	temp = 0xff;
+	for (i = 0; i < number_of_dimms; i++)
+		if (dimm_params[i].n_ranks)
+			temp &= dimm_params[i].burst_lengths_bitmask;
+
+	return temp;
+}
+
+/* Compute a CAS latency suitable for all DIMMs */
+static unsigned int compute_lowest_caslat(
+		const struct dimm_params_s *dimm_params,
+		const unsigned int number_of_dimms)
+{
+	uint32_t temp1, temp2, i, not_ok, lowest_good_caslat,
+		 tCKmin_X_minus_1_ps, tCKmin_X_minus_2_ps;
+	const unsigned int mclk_ps = get_memory_clk_period_ps();
+
+	/*
+	 * Step 1: find CAS latency common to all DIMMs using bitwise
+	 * operation.
+	 */
+	temp1 = 0xFF;
+	for (i = 0; i < number_of_dimms; i++)
+		if (dimm_params[i].n_ranks) {
+			temp2 = 0;
+			temp2 |= 1 << dimm_params[i].caslat_X;
+			temp2 |= 1 << dimm_params[i].caslat_X_minus_1;
+			temp2 |= 1 << dimm_params[i].caslat_X_minus_2;
+			/*
+			 * FIXME: If there was no entry for X-2 (X-1) in
+			 * the SPD, then caslat_X_minus_2
+			 * (caslat_X_minus_1) contains either 255 or
+			 * 0xFFFFFFFF because that's what the __ilog2
+			 * function returns for an input of 0.
+			 * On 32-bit PowerPC, left shift counts with bit
+			 * 26 set (that the value of 255 or 0xFFFFFFFF
+			 * will have), cause the destination register to
+			 * be 0. That is why this works.
+			 */
+			temp1 &= temp2;
+		}
+
+	/*
+	 * Step 2: check each common CAS latency against tCK of each
+	 * DIMM's SPD.
+	 */
+	lowest_good_caslat = 0;
+	temp2 = 0;
+	while (temp1) {
+		not_ok = 0;
+		temp2 = __ilog2(temp1);
+
+		for (i = 0; i < number_of_dimms; i++) {
+			if (!dimm_params[i].n_ranks)
+				continue;
+
+			if (dimm_params[i].caslat_X == temp2) {
+				if (mclk_ps >= dimm_params[i].tCKmin_X_ps)
+					continue;
+				else
+					not_ok++;
+			}
+
+			if (dimm_params[i].caslat_X_minus_1 == temp2) {
+				tCKmin_X_minus_1_ps =
+					dimm_params[i].tCKmin_X_minus_1_ps;
+				if (mclk_ps >= tCKmin_X_minus_1_ps)
+					continue;
+				else
+					not_ok++;
+			}
+
+			if (dimm_params[i].caslat_X_minus_2 == temp2) {
+				tCKmin_X_minus_2_ps
+					= dimm_params[i].tCKmin_X_minus_2_ps;
+				if (mclk_ps >= tCKmin_X_minus_2_ps)
+					continue;
+				else
+					not_ok++;
+			}
+		}
+
+		if (!not_ok)
+			lowest_good_caslat = temp2;
+
+		temp1 &= ~(1 << temp2);
+	}
+	return lowest_good_caslat;
+}
+
+/*
+ * compute_lowest_common_dimm_parameters()
+ *
+ * Determine the worst-case DIMM timing parameters from the set of DIMMs
+ * whose parameters have been computed into the array pointed to
+ * by dimm_params.
+ */
+unsigned int
+compute_lowest_common_dimm_parameters(const struct dimm_params_s *dimm,
+				      struct common_timing_params_s *out,
+				      const unsigned int number_of_dimms)
+{
+	const uint32_t mclk_ps = get_memory_clk_period_ps();
+	uint32_t temp1, i;
+	struct common_timing_params_s tmp = {0};
+
+	tmp.tCKmax_ps = 0xFFFFFFFF;
+	temp1 = 0;
+	for (i = 0; i < number_of_dimms; i++) {
+		if (dimm[i].n_ranks == 0) {
+			temp1++;
+			continue;
+		}
+
+		/*
+		 * Find minimum tCKmax_ps to find fastest slow speed,
+		 * i.e., this is the slowest the whole system can go.
+		 */
+		tmp.tCKmax_ps = min(tmp.tCKmax_ps, dimm[i].tCKmax_ps);
+
+		/* Find maximum value to determine slowest speed, delay, etc */
+		tmp.tCKmin_X_ps = max(tmp.tCKmin_X_ps, dimm[i].tCKmin_X_ps);
+		tmp.tCKmax_max_ps = max(tmp.tCKmax_max_ps, dimm[i].tCKmax_ps);
+		tmp.tRCD_ps = max(tmp.tRCD_ps, dimm[i].tRCD_ps);
+		tmp.tRP_ps = max(tmp.tRP_ps, dimm[i].tRP_ps);
+		tmp.tRAS_ps = max(tmp.tRAS_ps, dimm[i].tRAS_ps);
+		tmp.tWR_ps = max(tmp.tWR_ps, dimm[i].tWR_ps);
+		tmp.tWTR_ps = max(tmp.tWTR_ps, dimm[i].tWTR_ps);
+		tmp.tRFC_ps = max(tmp.tRFC_ps, dimm[i].tRFC_ps);
+		tmp.tRRD_ps = max(tmp.tRRD_ps, dimm[i].tRRD_ps);
+		tmp.tRC_ps = max(tmp.tRC_ps, dimm[i].tRC_ps);
+		tmp.tIS_ps = max(tmp.tIS_ps, dimm[i].tIS_ps);
+		tmp.tIH_ps = max(tmp.tIH_ps, dimm[i].tIH_ps);
+		tmp.tDS_ps = max(tmp.tDS_ps, dimm[i].tDS_ps);
+		tmp.tDH_ps = max(tmp.tDH_ps, dimm[i].tDH_ps);
+		tmp.tRTP_ps = max(tmp.tRTP_ps, dimm[i].tRTP_ps);
+		tmp.tQHS_ps = max(tmp.tQHS_ps, dimm[i].tQHS_ps);
+		tmp.refresh_rate_ps = max(tmp.refresh_rate_ps,
+				dimm[i].refresh_rate_ps);
+		/* Find maximum tDQSQ_max_ps to find slowest timing. */
+		tmp.tDQSQ_max_ps = max(tmp.tDQSQ_max_ps, dimm[i].tDQSQ_max_ps);
+	}
+	tmp.ndimms_present = number_of_dimms - temp1;
+
+	if (temp1 == number_of_dimms)
+		return 0;
+
+	temp1 = common_burst_length(dimm, number_of_dimms);
+	tmp.all_DIMMs_burst_lengths_bitmask = temp1;
+	tmp.all_DIMMs_registered = 0;
+
+	tmp.lowest_common_SPD_caslat = compute_lowest_caslat(dimm,
+			number_of_dimms);
+	/*
+	 * Compute a common 'de-rated' CAS latency.
+	 *
+	 * The strategy here is to find the *highest* de-rated cas latency
+	 * with the assumption that all of the DIMMs will support a de-rated
+	 * CAS latency higher than or equal to their lowest de-rated value.
+	 */
+	temp1 = 0;
+	for (i = 0; i < number_of_dimms; i++)
+		temp1 = max(temp1, dimm[i].caslat_lowest_derated);
+	tmp.highest_common_derated_caslat = temp1;
+
+	temp1 = 1;
+	for (i = 0; i < number_of_dimms; i++)
+		if (dimm[i].n_ranks &&
+		    !(dimm[i].edc_config & EDC_ECC)) {
+			temp1 = 0;
+			break;
+		}
+	tmp.all_DIMMs_ECC_capable = temp1;
+
+	if (mclk_ps > tmp.tCKmax_max_ps)
+		return 1;
+
+	/*
+	 * AL must be less or equal to tRCD. Typically, AL would
+	 * be AL = tRCD - 1;
+	 *
+	 * When ODT read or write is enabled the sum of CAS latency +
+	 * additive latency must be at least 3 cycles.
+	 *
+	 */
+	if ((tmp.lowest_common_SPD_caslat < 4) && (picos_to_mclk(tmp.tRCD_ps) >
+				tmp.lowest_common_SPD_caslat))
+		tmp.additive_latency = picos_to_mclk(tmp.tRCD_ps) -
+			tmp.lowest_common_SPD_caslat;
+
+	memcpy(out, &tmp, sizeof(struct common_timing_params_s));
+
+	return 0;
+}
-- 
1.7.1



From renaud.barbier at ge.com  Wed Jun 26 13:33:45 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 26 Jun 2013 18:33:45 +0100
Subject: [PATCH 6/8] ppx 8xxx: DDR registers value calculation
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372268027-15271-7-git-send-email-renaud.barbier@ge.com>

The functions in this file calculate and store the value for each
register of the memory controller.

This code is based on the equivalent file in directory
arch/powerpc/cpu/mpc8xxx/ddr from U-Boot version git-a71d45d.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/ctrl_regs.c |  425 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 425 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/ctrl_regs.c

diff --git a/arch/ppc/ddr-8xxx/ctrl_regs.c b/arch/ppc/ddr-8xxx/ctrl_regs.c
new file mode 100644
index 0000000..3f8ecf7
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/ctrl_regs.c
@@ -0,0 +1,425 @@
+/*
+ * Copyright 2008-2012 Freescale Semiconductor, Inc.
+ *
+ * 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.
+ */
+
+/*
+ * Generic driver for Freescale DDR2 memory controller.
+ * Based on code from spd_sdram.c
+ * Author: James Yang [at freescale.com]
+ */
+
+#include <common.h>
+#include <asm/fsl_ddr_sdram.h>
+#include "ddr.h"
+
+static void set_csn_config(int dimm_number, int i,
+			   struct fsl_ddr_cfg_regs_s *ddr,
+			   const struct memctl_options_s *popts,
+			   const struct dimm_params_s *dimm)
+{
+	uint32_t cs_n_en = 0, ap_n_en = 0, odt_rd_cfg = 0, odt_wr_cfg = 0,
+		 ba_bits_cs_n = 0, row_bits_cs_n = 0, col_bits_cs_n = 0,
+		 n_banks_per_sdram_device;
+	int go_config = 0;
+
+	switch (i) {
+	case 0:
+		if (dimm[dimm_number].n_ranks > 0)
+			go_config = 1;
+		break;
+	case 1:
+		if ((dimm_number == 0 && dimm[0].n_ranks > 1) ||
+		    (dimm_number == 1 && dimm[1].n_ranks > 0))
+			go_config = 1;
+		break;
+	case 2:
+		if ((dimm_number == 0 && dimm[0].n_ranks > 2) ||
+		    (dimm_number >= 1 && dimm[dimm_number].n_ranks > 0))
+			go_config = 1;
+		break;
+	case 3:
+		if ((dimm_number == 0 && dimm[0].n_ranks > 3) ||
+		    (dimm_number == 1 && dimm[1].n_ranks > 1) ||
+		    (dimm_number == 3 && dimm[3].n_ranks > 0))
+			go_config = 1;
+		break;
+	default:
+		break;
+	}
+
+	if (go_config) {
+		/* Chip Select enable */
+		cs_n_en = 1;
+		/* CSn auto-precharge enable */
+		ap_n_en = popts->cs_local_opts[i].auto_precharge;
+		/* ODT for reads configuration */
+		odt_rd_cfg = popts->cs_local_opts[i].odt_rd_cfg;
+		/* ODT for writes configuration */
+		odt_wr_cfg = popts->cs_local_opts[i].odt_wr_cfg;
+		/* Num of bank bits for SDRAM on CSn */
+		n_banks_per_sdram_device =
+			dimm[dimm_number].n_banks_per_sdram_device;
+		ba_bits_cs_n = __ilog2(n_banks_per_sdram_device) - 2;
+		/* Num of row bits for SDRAM on CSn */
+		row_bits_cs_n = dimm[dimm_number].n_row_addr - 12;
+		/* Num of ocl bits for SDRAM on CSn */
+		col_bits_cs_n = dimm[dimm_number].n_col_addr - 8;
+	}
+
+	ddr->cs[i].config = (((cs_n_en & 0x1) << 31)
+			     | ((ap_n_en & 0x1) << 23)
+			     | ((odt_rd_cfg & 0x7) << 20)
+			     | ((odt_wr_cfg & 0x7) << 16)
+			     | ((ba_bits_cs_n & 0x3) << 14)
+			     | ((row_bits_cs_n & 0x7) << 8)
+			     | ((col_bits_cs_n & 0x7) << 0));
+}
+
+static void set_timing_cfg_0(struct fsl_ddr_cfg_regs_s *ddr,
+			     const struct memctl_options_s *popts)
+{
+	uint32_t trwt_mclk = 0;
+
+	if (popts->trwt_override)
+		trwt_mclk = popts->trwt;
+
+	ddr->timing_cfg_0 = (((trwt_mclk & 0x3) << 30)
+			     | ((popts->txard & 0x7) << 20)
+			     | ((popts->txp & 0xF) << 16)
+			     | ((popts->taxpd & 0xf) << 8)
+			     | ((popts->tmrd & 0xf) << 0));
+}
+
+static void set_timing_cfg_3(struct fsl_ddr_cfg_regs_s *ddr,
+			     const struct common_timing_params_s *dimm,
+			     uint32_t cas_latency)
+{
+	uint32_t ext_pretoact, ext_acttopre, ext_acttorw, ext_refrec;
+
+	ext_pretoact = picos_to_mclk(dimm->tRP_ps) >> 4;
+	ext_acttopre = picos_to_mclk(dimm->tRAS_ps) >> 4;
+	ext_acttorw = picos_to_mclk(dimm->tRCD_ps) >> 4;
+	cas_latency = ((cas_latency << 1) - 1) >> 4;
+	ext_refrec = (picos_to_mclk(dimm->tRFC_ps) - 8) >> 4;
+
+	ddr->timing_cfg_3 = (((ext_pretoact & 0x1) << 28)
+			     | ((ext_acttopre & 0x2) << 24)
+			     | ((ext_acttorw & 0x1) << 22)
+			     | ((ext_refrec & 0x1F) << 16)
+			     | ((cas_latency & 0x3) << 12));
+}
+
+static void set_timing_cfg_1(struct fsl_ddr_cfg_regs_s *ddr,
+			     const struct common_timing_params_s *dimm,
+			     uint32_t cas_latency)
+{
+	uint32_t pretoact_mclk, acttopre_mclk, acttorw_mclk, refrec_ctrl,
+		 wrrec_mclk, acttoact_mclk, wrtord_mclk;
+	/* DDR_SDRAM_MODE doesn't support 9,11,13,15 */
+	static const u8 wrrec_table[] = {
+		1, 2, 3, 4, 5, 6, 7, 8, 10, 10, 12, 12, 14, 14, 0, 0
+	};
+
+	pretoact_mclk = picos_to_mclk(dimm->tRP_ps);
+	acttopre_mclk = picos_to_mclk(dimm->tRAS_ps);
+	acttorw_mclk = picos_to_mclk(dimm->tRCD_ps);
+
+	/*
+	 * Translate CAS Latency to a DDR controller field value:
+	 *
+	 *      CAS Lat DDR II  Ctrl
+	 *      Clocks  SPD Bit Value
+	 *      ------- ------- ------
+	 *      1.0             0001
+	 *      1.5             0010
+	 *      2.0     2       0011
+	 *      2.5             0100
+	 *      3.0     3       0101
+	 *      3.5             0110
+	 *      4.0     4       0111
+	 *      4.5             1000
+	 *      5.0     5       1001
+	 */
+	cas_latency = (cas_latency << 1) - 1;
+	refrec_ctrl = picos_to_mclk(dimm->tRFC_ps) - 8;
+	acttoact_mclk = picos_to_mclk(dimm->tRRD_ps);
+
+	wrrec_mclk = picos_to_mclk(dimm->tWR_ps);
+	if (wrrec_mclk <= 16)
+		wrrec_mclk = wrrec_table[wrrec_mclk - 1];
+
+	wrtord_mclk = picos_to_mclk(dimm->tWTR_ps);
+	if (wrtord_mclk < 2)
+		wrtord_mclk = 2;
+
+	ddr->timing_cfg_1 = (((pretoact_mclk & 0x0F) << 28)
+			     | ((acttopre_mclk & 0x0F) << 24)
+			     | ((acttorw_mclk & 0xF) << 20)
+			     | ((cas_latency & 0xF) << 16)
+			     | ((refrec_ctrl & 0xF) << 12)
+			     | ((wrrec_mclk & 0x0F) << 8)
+			     | ((acttoact_mclk & 0x0F) << 4)
+			     | ((wrtord_mclk & 0x0F) << 0));
+}
+
+static void set_timing_cfg_2(struct fsl_ddr_cfg_regs_s *ddr,
+			     const struct memctl_options_s *popts,
+			     const struct common_timing_params_s *dimm,
+			     uint32_t cas_latency, uint32_t additive_latency)
+{
+	uint32_t cpo, rd_to_pre, wr_data_delay, cke_pls, four_act;
+
+	cpo = popts->cpo_override;
+	rd_to_pre = picos_to_mclk(dimm->tRTP_ps);
+	if (rd_to_pre < 2)
+		rd_to_pre = 2;
+
+	if (additive_latency)
+		rd_to_pre += additive_latency;
+
+	wr_data_delay = popts->write_data_delay;
+	cke_pls = picos_to_mclk(popts->tCKE_clock_pulse_width_ps);
+	four_act = picos_to_mclk(popts->tFAW_window_four_activates_ps);
+
+	ddr->timing_cfg_2 = (((additive_latency & 0xf) << 28)
+			     | ((cpo & 0x1f) << 23)
+			     | (((cas_latency - 1) & 0xf) << 19)
+			     | ((rd_to_pre & 7) << 13)
+			     | ((wr_data_delay & 7) << 10)
+			     | ((cke_pls & 0x7) << 6)
+			     | ((four_act & 0x3f) << 0));
+}
+
+static void set_ddr_sdram_cfg(struct fsl_ddr_cfg_regs_s *ddr,
+			      const struct memctl_options_s *popts,
+			      const struct common_timing_params_s *dimm)
+{
+	uint32_t mem_en, sren, ecc_en, sdram_type, dyn_pwr, dbw, twoT_en, hse;
+
+	mem_en = 1;
+	sren = popts->self_refresh_in_sleep;
+	if (dimm->all_DIMMs_ECC_capable)
+		ecc_en = popts->ECC_mode;
+	else
+		ecc_en = 0;
+
+	if (popts->sdram_type)
+		sdram_type = popts->sdram_type;
+	else
+		sdram_type = FSL_SDRAM_TYPE;
+
+	twoT_en = popts->twoT_en;
+	dyn_pwr = popts->dynamic_power;
+	dbw = popts->data_bus_width;
+	hse = popts->half_strength_driver_enable;
+
+	ddr->ddr_sdram_cfg = (((mem_en & 0x1) << 31)
+			      | ((sren & 0x1) << 30)
+			      | ((ecc_en & 0x1) << 29)
+			      | ((sdram_type & 0x7) << 24)
+			      | ((dyn_pwr & 0x1) << 21)
+			      | ((dbw & 0x3) << 19)
+			      | ((twoT_en & 0x1) << 15)
+			      | ((hse & 0x1) << 3));
+}
+
+static void set_ddr_sdram_cfg_2(struct fsl_ddr_cfg_regs_s *ddr,
+				const struct memctl_options_s *popts)
+{
+	struct ddr_board_info_s *bi = popts->board_info;
+	uint32_t i, dll_rst_dis, dqs_cfg, odt_cfg = 0, num_pr, d_init = 0;
+
+	dll_rst_dis = popts->dll_rst_dis;
+	dqs_cfg = popts->DQS_config;
+
+	/*
+	 * Check for On-Die Termination options and
+	 * assert ODT only during reads to DRAM.
+	 */
+	for (i = 0; i < bi->cs_per_ctrl; i++)
+		if (popts->cs_local_opts[i].odt_rd_cfg ||
+				popts->cs_local_opts[i].odt_wr_cfg) {
+			odt_cfg = SDRAM_CFG2_ODT_ONLY_READ;
+			break;
+		}
+
+	/* Default number of posted refresh */
+	num_pr = 1;
+
+	if (popts->ECC_init_using_memctl) {
+		d_init = 1;
+		ddr->ddr_data_init = popts->data_init;
+	}
+
+	ddr->ddr_sdram_cfg_2 = (((dll_rst_dis & 0x1) << 29)
+				| ((dqs_cfg & 0x3) << 26)
+				| ((odt_cfg & 0x3) << 21)
+				| ((num_pr & 0xf) << 12)
+				| ((d_init & 0x1) << 4));
+}
+
+static void
+set_ddr_sdram_interval(struct fsl_ddr_cfg_regs_s *ddr,
+		const struct memctl_options_s *popts,
+		const struct common_timing_params_s *dimm)
+{
+	uint32_t refint, bstopre;
+
+	refint = picos_to_mclk(dimm->refresh_rate_ps);
+	/* Precharge interval */
+	bstopre = popts->bstopre;
+
+	ddr->ddr_sdram_interval = (((refint & 0xFFFF) << 16)
+				   | ((bstopre & 0x3FFF) << 0));
+}
+
+static void set_ddr_sdram_mode(struct fsl_ddr_cfg_regs_s *ddr,
+			       const struct memctl_options_s *popts,
+			       const struct common_timing_params_s *dimm,
+			       uint32_t cas_latency,
+			       uint32_t additive_latency)
+{
+	uint16_t esdmode, sdmode;
+	uint32_t dqs_en, rtt, al, wr, bl;
+	const uint32_t mclk_ps = get_memory_clk_period_ps();
+
+	/* DQS# Enable: 0=enable, 1=disable */
+	dqs_en = !popts->DQS_config;
+	/* Posted CAS# additive latency (AL) */
+	al = additive_latency;
+	/* Internal Termination Resistor */
+	if (popts->rtt_override)
+		rtt = popts->rtt_override_value;
+	else
+		rtt = popts->cs_local_opts[0].odt_rtt_norm;
+
+	/*
+	 * Extended SDRAM mode.
+	 * The variable also selects:
+	 * - OCD set to exit mode
+	 * - all outputs bit i.e DQ, DQS, RDQS output enabled
+	 * - RDQS ball disabled
+	 * - DQS ball enabled
+	 * - DLL enabled
+	 * - Output drive strength: full strength.
+	 */
+	esdmode = (((dqs_en & 0x1) << 10)
+		   | ((rtt & 0x2) << 5)
+		   | ((al & 0x7) << 3)
+		   | ((rtt & 0x1) << 2));
+
+	/* Write recovery */
+	wr = (dimm->tWR_ps + mclk_ps - 1) / (mclk_ps - 1);
+
+	switch (popts->burst_length) {
+	case DDR_BL4:
+		bl = 2;
+		break;
+	case DDR_BL8:
+		bl = 3;
+		break;
+	default:
+		bl = 2;
+		break;
+	}
+
+	/* SDRAM mode
+	 * The variable also selects:
+	 * - power down mode: fast exit (normal)
+	 * - DLL reset disabled.
+	 * - burst type: sequential
+	 */
+	sdmode = (((wr & 0x7) << 9)
+		  | ((cas_latency & 0x7) << 4)
+		  | ((bl & 0x7) << 0));
+
+	ddr->ddr_sdram_mode = (((esdmode & 0xFFFF) << 16)
+			       | ((sdmode & 0xFFFF) << 0));
+}
+
+uint32_t check_fsl_memctl_config_regs(const struct fsl_ddr_cfg_regs_s *ddr)
+{
+	/*
+	 * DDR_SDRAM_CFG[RD_EN] and DDR_SDRAM_CFG[2T_EN should not
+	 * be set at the same time.
+	 */
+	if ((ddr->ddr_sdram_cfg & 0x10000000) &&
+			(ddr->ddr_sdram_cfg & 0x00008000))
+		return 1;
+
+	return 0;
+}
+
+uint32_t
+compute_fsl_memctl_config_regs(const struct memctl_options_s *popts,
+			       struct fsl_ddr_cfg_regs_s *ddr,
+			       const struct common_timing_params_s *dimm,
+			       const struct dimm_params_s *dimmp,
+			       uint32_t dbw_cap_adj)
+{
+	struct ddr_board_info_s *binfo = popts->board_info;
+	uint32_t cas_latency, additive_latency, i, cs_per_dimm,
+		 dimm_number;
+	uint64_t ea, sa, rank_density;
+
+	if (dimm == NULL)
+		return 1;
+
+	memset(ddr, 0, sizeof(struct fsl_ddr_cfg_regs_s));
+
+	/* Process overrides first.  */
+	if (popts->cas_latency_override)
+		cas_latency = popts->cas_latency_override_value;
+	else
+		cas_latency =  dimm->lowest_common_SPD_caslat;
+
+	if (popts->additive_latency_override)
+		additive_latency = popts->additive_latency_override_value;
+	else
+		additive_latency = dimm->additive_latency;
+
+	/* Chip Select Memory Bounds (CSn_BNDS) */
+	for (i = 0; i < binfo->cs_per_ctrl; i++) {
+		cs_per_dimm = binfo->cs_per_ctrl / binfo->dimm_slots_per_ctrl;
+		dimm_number = i / cs_per_dimm;
+		rank_density =
+			dimmp[dimm_number].rank_density >> dbw_cap_adj;
+
+		if (dimmp[dimm_number].n_ranks == 0)
+			continue;
+
+		sa = dimmp[dimm_number].base_address;
+		ea = sa + rank_density - 1;
+		if (dimmp[dimm_number].n_ranks > (i % cs_per_dimm)) {
+			sa += (i % cs_per_dimm) * rank_density;
+			ea += (i % cs_per_dimm) * rank_density;
+		} else {
+			sa = 0;
+			ea = 0;
+		}
+		sa >>= 24;
+		ea >>= 24;
+
+		ddr->cs[i].bnds = (((sa & 0xFFF) << 16) | ((ea & 0xFFF) << 0));
+		set_csn_config(dimm_number, i, ddr, popts, dimmp);
+	}
+
+	set_timing_cfg_0(ddr, popts);
+	set_timing_cfg_3(ddr, dimm, cas_latency);
+	set_timing_cfg_1(ddr, dimm, cas_latency);
+	set_timing_cfg_2(ddr, popts, dimm, cas_latency, additive_latency);
+	set_ddr_sdram_cfg(ddr, popts, dimm);
+	set_ddr_sdram_cfg_2(ddr, popts);
+	set_ddr_sdram_mode(ddr, popts, dimm, cas_latency, additive_latency);
+	set_ddr_sdram_interval(ddr, popts, dimm);
+
+	ddr->ddr_data_init = popts->data_init;
+	ddr->ddr_sdram_clk_cntl = (popts->clk_adjust & 0xF) << 23;
+
+	return check_fsl_memctl_config_regs(ddr);
+}
-- 
1.7.1



From renaud.barbier at ge.com  Wed Jun 26 13:33:46 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 26 Jun 2013 18:33:46 +0100
Subject: [PATCH 7/8] ppc 8xxx: core DDR driver functions
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372268027-15271-8-git-send-email-renaud.barbier@ge.com>

These files are the driver interface to handle the memory
initialisation from reading the SPD data to writing the memory
controller registers.

This code is based on the equivalent files main.c in directory
arch/powerpc/cpu/mpc8xxx/ddr and ddr-gen2.c in directory
arch/powerpc/cpu/mpc85xx. Both are from U-Boot version git-a71d45d.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/ddr-8xxx/ddr2_setctrl.c |   58 +++++++++
 arch/ppc/ddr-8xxx/main.c         |  238 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 296 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/ddr-8xxx/ddr2_setctrl.c
 create mode 100644 arch/ppc/ddr-8xxx/main.c

diff --git a/arch/ppc/ddr-8xxx/ddr2_setctrl.c b/arch/ppc/ddr-8xxx/ddr2_setctrl.c
new file mode 100644
index 0000000..14571b0
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/ddr2_setctrl.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2008 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <config.h>
+#include <asm/io.h>
+#include <asm/fsl_ddr_sdram.h>
+#include <mach/early_udelay.h>
+#include "ddr.h"
+
+int fsl_ddr_set_memctl_regs(const struct fsl_ddr_info_s *info)
+{
+	uint32_t i;
+	void __iomem *ddr;
+	const struct fsl_ddr_cfg_regs_s *regs;
+
+	regs = &info->fsl_ddr_config_reg;
+	ddr = info->board_info.ddr_base;
+
+	if (in_be32(ddr + DDR_OFF(SDRAM_CFG)) & SDRAM_CFG_MEM_EN)
+		return 0;
+
+	for (i = 0; i < info->board_info.cs_per_ctrl; i++) {
+		out_be32(ddr + DDR_OFF(CS0_BNDS) + (i << 3), regs->cs[i].bnds);
+		out_be32(ddr + DDR_OFF(CS0_CONFIG) + (i << 2),
+				regs->cs[i].config);
+	}
+
+	out_be32(ddr + DDR_OFF(TIMING_CFG_3), regs->timing_cfg_3);
+	out_be32(ddr + DDR_OFF(TIMING_CFG_0), regs->timing_cfg_0);
+	out_be32(ddr + DDR_OFF(TIMING_CFG_1), regs->timing_cfg_1);
+	out_be32(ddr + DDR_OFF(TIMING_CFG_2), regs->timing_cfg_2);
+	out_be32(ddr + DDR_OFF(SDRAM_CFG_2), regs->ddr_sdram_cfg_2);
+	out_be32(ddr + DDR_OFF(SDRAM_MODE), regs->ddr_sdram_mode);
+	out_be32(ddr + DDR_OFF(SDRAM_MODE_2), regs->ddr_sdram_mode_2);
+	out_be32(ddr + DDR_OFF(SDRAM_MD_CNTL), regs->ddr_sdram_md_cntl);
+	out_be32(ddr + DDR_OFF(SDRAM_INTERVAL), regs->ddr_sdram_interval);
+	out_be32(ddr + DDR_OFF(SDRAM_DATA_INIT), regs->ddr_data_init);
+	out_be32(ddr + DDR_OFF(SDRAM_CLK_CNTL), regs->ddr_sdram_clk_cntl);
+	out_be32(ddr + DDR_OFF(SDRAM_INIT_ADDR), regs->ddr_init_addr);
+	out_be32(ddr + DDR_OFF(SDRAM_INIT_ADDR_EXT), regs->ddr_init_ext_addr);
+
+	early_udelay(200);
+	asm volatile("sync;isync");
+
+	out_be32(ddr + DDR_OFF(SDRAM_CFG), regs->ddr_sdram_cfg);
+
+	/* Poll DDR_SDRAM_CFG_2[D_INIT] bit until auto-data init is done.  */
+	while (in_be32(ddr + DDR_OFF(SDRAM_CFG_2)) & SDRAM_CFG2_D_INIT)
+		early_udelay(10000);
+
+	return 0;
+}
diff --git a/arch/ppc/ddr-8xxx/main.c b/arch/ppc/ddr-8xxx/main.c
new file mode 100644
index 0000000..6e4a02d
--- /dev/null
+++ b/arch/ppc/ddr-8xxx/main.c
@@ -0,0 +1,238 @@
+/*
+ * Copyright 2008-2012 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+/*
+ * Generic driver for Freescale DDR2 memory controller.
+ * Based on code from spd_sdram.c
+ * Author: James Yang [at freescale.com]
+ */
+
+#include <common.h>
+#include <config.h>
+#include <asm/fsl_law.h>
+#include "ddr.h"
+
+static int get_spd(generic_spd_eeprom_t *spd,
+		      struct ddr_board_info_s *bi, u8 i2c_address)
+{
+	int ret;
+
+	fsl_i2c_init(bi->i2c_base, bi->i2c_speed, bi->i2c_slave);
+	ret = fsl_i2c_read(bi->i2c_base, i2c_address, 0, 1, (uchar *) spd,
+			sizeof(generic_spd_eeprom_t));
+	fsl_i2c_stop(bi->i2c_base);
+
+	return ret;
+}
+
+int fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
+		struct ddr_board_info_s *binfo)
+{
+	uint32_t i;
+	uint8_t i2c_address;
+
+	for (i = 0; i < binfo->dimm_slots_per_ctrl; i++) {
+		if (binfo->spd_i2c_addr == NULL)
+			goto error;
+		i2c_address = binfo->spd_i2c_addr[i];
+		if (get_spd(&(ctrl_dimms_spd[i]), binfo, i2c_address))
+				goto error;
+	}
+
+	return 0;
+error:
+	return 1;
+}
+
+static uint64_t step_assign_addresses(struct fsl_ddr_info_s *pinfo,
+		uint32_t dbw_cap_adj)
+{
+	uint64_t total_mem, current_mem_base, total_ctlr_mem, cap;
+	uint32_t ndimm, dw, j, found = 0;
+
+	ndimm = pinfo->board_info.dimm_slots_per_ctrl;
+	/*
+	 * If a reduced data width is requested, but the SPD
+	 * specifies a physically wider device, adjust the
+	 * computed dimm capacities accordingly before
+	 * assigning addresses.
+	 */
+	switch (pinfo->memctl_opts.data_bus_width) {
+	case 2:
+		/* 16-bit */
+		for (j = 0; j < ndimm; j++) {
+			if (!pinfo->dimm_params[j].n_ranks)
+				continue;
+			dw = pinfo->dimm_params[j].primary_sdram_width;
+			if ((dw == 72 || dw == 64)) {
+				dbw_cap_adj = 2;
+				break;
+			} else if ((dw == 40 || dw == 32)) {
+				dbw_cap_adj = 1;
+				break;
+			}
+		}
+		break;
+	case 1:
+		/* 32-bit */
+		for (j = 0; j < ndimm; j++) {
+			dw = pinfo->dimm_params[j].data_width;
+			if (pinfo->dimm_params[j].n_ranks
+			    && (dw == 72 || dw == 64)) {
+				/*
+				 * FIXME: can't really do it
+				 * like this because this just
+				 * further reduces the memory
+				 */
+				found = 1;
+				break;
+			}
+		}
+		if (found)
+			dbw_cap_adj = 1;
+		break;
+	case 0:
+		/* 64-bit */
+		break;
+	default:
+		return 1;
+	}
+
+	current_mem_base = 0ull;
+	total_mem = 0;
+	total_ctlr_mem = 0;
+	pinfo->common_timing_params.base_address = current_mem_base;
+
+	for (j = 0; j < ndimm; j++) {
+		cap = pinfo->dimm_params[j].capacity >> dbw_cap_adj;
+		pinfo->dimm_params[j].base_address = current_mem_base;
+		current_mem_base += cap;
+		total_ctlr_mem += cap;
+
+	}
+
+	pinfo->common_timing_params.total_mem = total_ctlr_mem;
+	total_mem += total_ctlr_mem;
+
+	return total_mem;
+}
+
+static uint32_t retrieve_max_size(struct fsl_ddr_cfg_regs_s *ddr_reg,
+				uint32_t ncs)
+{
+	uint32_t max_end = 0, end, i;
+
+	for (i = 0; i < ncs; i++)
+		if (ddr_reg->cs[i].config & 0x80000000) {
+			end = ddr_reg->cs[i].bnds & 0xFFF;
+			if (end > max_end)
+				max_end = end;
+		}
+
+	return max_end;
+}
+
+static uint32_t compute_dimm_param(struct fsl_ddr_info_s *pinfo, uint32_t ndimm)
+{
+	struct dimm_params_s *pdimm;
+	generic_spd_eeprom_t *spd;
+	uint32_t i, retval;
+
+	for (i = 0; i < ndimm; i++) {
+		spd = &(pinfo->spd_installed_dimms[i]);
+		pdimm = &(pinfo->dimm_params[i]);
+
+		retval = compute_dimm_parameters(spd, pdimm);
+
+		if (retval == 2) /* Fatal error */
+			return 1;
+	}
+
+	return 0;
+}
+
+uint64_t fsl_ddr_compute(struct fsl_ddr_info_s *pinfo)
+{
+	uint64_t total_mem = 0;
+	uint32_t ncs, ndimm, max_end = 0;
+	struct fsl_ddr_cfg_regs_s *ddr_reg;
+	struct common_timing_params_s *timing_params;
+	/* data bus width capacity adjust shift amount */
+	uint32_t dbw_capacity_adjust;
+
+	ddr_reg = &pinfo->fsl_ddr_config_reg;
+	timing_params = &pinfo->common_timing_params;
+	ncs = pinfo->board_info.cs_per_ctrl;
+	ndimm = pinfo->board_info.dimm_slots_per_ctrl;
+	dbw_capacity_adjust = 0;
+	pinfo->memctl_opts.board_info = &pinfo->board_info;
+
+	/* STEP 1:  Gather all DIMM SPD data */
+	if (fsl_ddr_get_spd(pinfo->spd_installed_dimms,
+			pinfo->memctl_opts.board_info))
+		return 0;
+
+	/* STEP 2:  Compute DIMM parameters from SPD data */
+	if (compute_dimm_param(pinfo, ndimm))
+		return 0;
+
+	/*
+	 * STEP 3: Compute a common set of timing parameters
+	 * suitable for all of the DIMMs on each memory controller
+	 */
+	compute_lowest_common_dimm_parameters(pinfo->dimm_params,
+			timing_params, ndimm);
+
+	/* STEP 4:  Gather configuration requirements from user */
+	populate_memctl_options(timing_params->all_DIMMs_registered,
+			&pinfo->memctl_opts,
+			pinfo->dimm_params);
+
+	/* STEP 5:  Assign addresses to chip selects */
+	total_mem = step_assign_addresses(pinfo, dbw_capacity_adjust);
+
+	/* STEP 6:  compute controller register values */
+	if (timing_params->ndimms_present == 0)
+		memset(ddr_reg, 0, sizeof(struct fsl_ddr_cfg_regs_s));
+
+	compute_fsl_memctl_config_regs(&pinfo->memctl_opts,
+				       ddr_reg, timing_params,
+				       pinfo->dimm_params,
+				       dbw_capacity_adjust);
+
+	max_end = retrieve_max_size(ddr_reg, ncs);
+	total_mem = 1 + (((uint64_t)max_end << 24ULL) | 0xFFFFFFULL);
+
+	return total_mem;
+}
+
+/*
+ * fsl_ddr_sdram():
+ * This is the main function to initialize the memory.
+ *
+ * It returns amount of memory configured in bytes.
+ */
+phys_size_t fsl_ddr_sdram(void)
+{
+	uint64_t total_memory;
+	struct fsl_ddr_info_s info;
+
+	memset(&info, 0, sizeof(struct fsl_ddr_info_s));
+	/* Gather board information on the  memory controller and I2C bus. */
+	fsl_ddr_board_info(&info.board_info);
+
+	total_memory = fsl_ddr_compute(&info);
+
+	if (info.common_timing_params.ndimms_present == 0)
+		return 0;
+
+	fsl_ddr_set_memctl_regs(&info);
+	fsl_ddr_set_lawbar(&info.common_timing_params, LAW_TRGT_IF_DDR_1);
+
+	return total_memory;
+}
-- 
1.7.1



From renaud.barbier at ge.com  Wed Jun 26 13:33:47 2013
From: renaud.barbier at ge.com (Renaud Barbier)
Date: Wed, 26 Jun 2013 18:33:47 +0100
Subject: [PATCH 8/8] ppc 85xx: early I2C support
In-Reply-To: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <1372268027-15271-9-git-send-email-renaud.barbier@ge.com>

Early I2C support is introduced to read SPD data from memory
modules prior to the loading of the I2C driver.

This code is based on the equivalent file fsl_i2c.c in directory
drivers/i2c from U-Boot version git-a71d45d.

Signed-off-by: Renaud Barbier <renaud.barbier at ge.com>
---
 arch/ppc/mach-mpc85xx/fsl_i2c.c              |  253 ++++++++++++++++++++++++++
 arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h |   18 ++
 2 files changed, 271 insertions(+), 0 deletions(-)
 create mode 100644 arch/ppc/mach-mpc85xx/fsl_i2c.c
 create mode 100644 arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h

diff --git a/arch/ppc/mach-mpc85xx/fsl_i2c.c b/arch/ppc/mach-mpc85xx/fsl_i2c.c
new file mode 100644
index 0000000..51fcc64
--- /dev/null
+++ b/arch/ppc/mach-mpc85xx/fsl_i2c.c
@@ -0,0 +1,253 @@
+/*
+ * Copyright 2013 GE Intelligent Platforms, Inc
+ * Copyright 2006,2009 Freescale Semiconductor, Inc.
+ *
+ * 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.
+ *
+ * Early I2C support functions to read SPD data or board
+ * information.
+ * Based on U-Boot drivers/i2c/fsl_i2c.c
+ */
+#include <common.h>
+#include <i2c/i2c.h>
+#include <mach/clock.h>
+#include <mach/immap_85xx.h>
+#include <mach/early_udelay.h>
+
+/* FSL I2C registers */
+#define FSL_I2C_ADR	0x00
+#define FSL_I2C_FDR	0x04
+#define FSL_I2C_CR	0x08
+#define FSL_I2C_SR	0x0C
+#define FSL_I2C_DR	0x10
+#define FSL_I2C_DFSRR	0x14
+
+/* Bits of FSL I2C registers */
+#define I2C_SR_RXAK	0x01
+#define I2C_SR_MIF	0x02
+#define I2C_SR_MAL	0x10
+#define I2C_SR_MBB	0x20
+#define I2C_SR_MCF	0x80
+#define I2C_CR_RSTA	0x04
+#define I2C_CR_TXAK	0x08
+#define I2C_CR_MTX	0x10
+#define I2C_CR_MSTA	0x20
+#define I2C_CR_MEN	0x80
+
+/*
+ * Set the I2C bus speed for a given I2C device
+ *
+ * parameters:
+ * - i2c: the I2C base address.
+ * - i2c_clk: I2C bus clock frequency.
+ * - speed: the desired speed of the bus.
+ *
+ * The I2C device must be stopped before calling this function.
+ *
+ * The return value is the actual bus speed that is set.
+ */
+static uint32_t fsl_set_i2c_bus_speed(const void __iomem *i2c,
+		uint32_t i2c_clk, uint32_t speed)
+{
+	uint8_t dfsr, fdr = 0x31; /* Default if no FDR found */
+	uint16_t a, b, ga, gb, bin_gb, bin_ga, divider;
+	uint32_t c_div, est_div;
+
+	divider = min((uint16_t)(i2c_clk / speed), (uint16_t) -1);
+	/* Condition 1: dfsr <= 50/T */
+	dfsr = (5 * (i2c_clk / 1000)) / 100000;
+	if (!dfsr)
+		dfsr = 1;
+	est_div = ~0;
+
+	/*
+	 * Bus speed is calculated as per Freescale AN2919.
+	 * a, b and dfsr matches identifiers A,B and C as in the
+	 * application note.
+	 */
+	for (ga = 0x4, a = 10; a <= 30; ga++, a += 2) {
+		for (gb = 0; gb < 8; gb++) {
+			b = 16 << gb;
+			c_div = b * (a + (((3 * dfsr) / b) * 2));
+
+			if ((c_div > divider) && (c_div < est_div)) {
+				est_div = c_div;
+				bin_gb = gb << 2;
+				bin_ga = (ga & 0x3) | ((ga & 0x4) << 3);
+				fdr = bin_gb | bin_ga;
+				speed = i2c_clk / est_div;
+			}
+		}
+		if (a == 20)
+			a += 2;
+		if (a == 24)
+			a += 4;
+	}
+	writeb(dfsr, i2c + FSL_I2C_DFSRR);	/* set default filter */
+	writeb(fdr, i2c + FSL_I2C_FDR);		/* set bus speed */
+
+	return speed;
+}
+
+void fsl_i2c_init(void __iomem *i2c, int speed, int slaveadd)
+{
+	uint32_t i2c_clk;
+
+	i2c_clk =  fsl_get_i2c_freq();
+	writeb(0, i2c + FSL_I2C_CR);
+	early_udelay(5);
+
+	fsl_set_i2c_bus_speed(i2c, i2c_clk, speed);
+	writeb(slaveadd << 1, i2c + FSL_I2C_ADR);
+	writeb(0x0, i2c + FSL_I2C_SR);
+	writeb(I2C_CR_MEN, i2c + FSL_I2C_CR);
+}
+
+static uint32_t fsl_usec2ticks(uint32_t usec)
+{
+	ulong ticks;
+
+	if (usec < 1000) {
+		ticks = (usec * (fsl_get_timebase_clock() / 1000));
+		ticks = (ticks + 500) / 1000;
+	} else {
+		ticks = (usec / 10);
+		ticks *= (fsl_get_timebase_clock() / 100000);
+	}
+
+	return ticks;
+}
+
+static int fsl_i2c_wait4bus(void __iomem *i2c)
+{
+	uint64_t timeval = get_ticks();
+	const uint64_t timeout = fsl_usec2ticks(20000);
+
+	while (readb(i2c + FSL_I2C_SR) & I2C_SR_MBB)
+		if ((get_ticks() - timeval) > timeout)
+			return -1;
+
+	return 0;
+}
+
+void fsl_i2c_stop(void __iomem *i2c)
+{
+	writeb(I2C_CR_MEN, i2c + FSL_I2C_CR);
+}
+
+static int fsl_i2c_wait(void __iomem *i2c, int write)
+{
+	const uint64_t timeout = fsl_usec2ticks(100000);
+	uint64_t timeval = get_ticks();
+	int csr;
+
+	do {
+		csr = readb(i2c + FSL_I2C_SR);
+		if (csr & I2C_SR_MIF)
+			break;
+	} while ((get_ticks() - timeval) < timeout);
+
+	if ((get_ticks() - timeval) > timeout)
+		goto error;
+
+	csr = readb(i2c + FSL_I2C_SR);
+	writeb(0x0, i2c + FSL_I2C_SR);
+
+	if (csr & I2C_SR_MAL)
+		goto error;
+
+	if (!(csr & I2C_SR_MCF))
+		goto error;
+
+	if (write == 0 && (csr & I2C_SR_RXAK))
+		goto error;
+
+	return 0;
+error:
+	return -1;
+}
+
+static int __i2c_write(void __iomem *i2c, uint8_t *data, int length)
+{
+	int i;
+
+	for (i = 0; i < length; i++) {
+		writeb(data[i], i2c + FSL_I2C_DR);
+		if (fsl_i2c_wait(i2c, 0) < 0)
+			break;
+	}
+
+	return i;
+}
+
+static int __i2c_read(void __iomem *i2c, uint8_t *data, int length)
+{
+	int i;
+	uint8_t val = I2C_CR_MEN | I2C_CR_MSTA;
+
+	if (length == 1)
+		writeb(val | I2C_CR_TXAK, i2c + FSL_I2C_CR);
+	else
+		writeb(val, i2c + FSL_I2C_CR);
+
+	readb(i2c + FSL_I2C_DR);
+	for (i = 0; i < length; i++) {
+		if (fsl_i2c_wait(i2c, 1) < 0)
+			break;
+
+		/* Generate ack on last next to last byte */
+		if (i == length - 2)
+			writeb(val | I2C_CR_TXAK, i2c + FSL_I2C_CR);
+		/* Do not generate stop on last byte */
+		if (i == length - 1)
+			writeb(val | I2C_CR_MTX, i2c + FSL_I2C_CR);
+
+		data[i] = readb(i2c + FSL_I2C_DR);
+	}
+
+	return i;
+}
+
+static int
+fsl_i2c_write_addr(void __iomem *i2c, uint8_t dev, uint8_t dir, int rsta)
+{
+	uint8_t val = I2C_CR_MEN | I2C_CR_MSTA | I2C_CR_MTX;
+
+	if (rsta)
+		val |= I2C_CR_RSTA;
+	writeb(val, i2c + FSL_I2C_CR);
+	writeb((dev << 1) | dir, i2c + FSL_I2C_DR);
+
+	if (fsl_i2c_wait(i2c, 0) < 0)
+		return 0;
+
+	return 1;
+}
+
+int fsl_i2c_read(void __iomem *i2c, uint8_t dev, uint addr, int alen,
+			uint8_t *data, int length)
+{
+	int i = -1;
+	uint8_t *a = (uint8_t *)&addr;
+
+	if (alen && (fsl_i2c_wait4bus(i2c) >= 0) &&
+		(fsl_i2c_write_addr(i2c, dev, 0, 0) != 0) &&
+		(__i2c_write(i2c, &a[4 - alen], alen) == alen))
+		i = 0;
+
+	if (length && fsl_i2c_write_addr(i2c, dev, 1, 1) != 0)
+		i = __i2c_read(i2c, data, length);
+
+	if (i == length)
+		return 0;
+
+	return -1;
+}
diff --git a/arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h b/arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h
new file mode 100644
index 0000000..acf4cc7
--- /dev/null
+++ b/arch/ppc/mach-mpc85xx/include/mach/fsl_i2c.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2013 GE Intelligent Platforms, Inc
+ *
+ * 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.
+ */
+void fsl_i2c_init(void __iomem *i2c, int speed, int slaveadd);
+int fsl_i2c_read(void __iomem *i2c, uint8_t dev, uint addr, int alen,
+		uint8_t *data, int length);
+void fsl_i2c_stop(void __iomem *i2c);
+
-- 
1.7.1



From shc_work at mail.ru  Wed Jun 26 13:57:06 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Wed, 26 Jun 2013 21:57:06 +0400
Subject: =?UTF-8?B?UmU6IFtQQVRDSF0gbWZkOiBtYzM0NzA4OiBwcm92aWRlIHN0YXRpYyBpbmxp?=
 =?UTF-8?B?bmUgd3JhcHBlcg==?=
In-Reply-To: <1372235714-5568-1-git-send-email-s.hauer@pengutronix.de>
References: <1372235714-5568-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <1372269426.799780740@f180.mail.ru>

> If the driver is disabled provide a static inline wrapper for
> mc34708_get() to prevent linker errors.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  include/mfd/mc34708.h | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/include/mfd/mc34708.h b/include/mfd/mc34708.h
> index f384c62..541c47f 100644
> --- a/include/mfd/mc34708.h
> +++ b/include/mfd/mc34708.h
> @@ -93,7 +93,14 @@ struct mc34708 {
>  	unsigned int		revision;
>  };
>  
> -extern struct mc34708 *mc34708_get(void);
> +#ifdef CONFIG_MFD_MC34708
> +struct mc34708 *mc34708_get(void);
> +#else
> +static inline struct mc34708 *mc34708_get(void)
> +{
> +	return NULL;
> +}
> +#endif
>  
>  extern int mc34708_reg_read(struct mc34708 *mc34708, enum mc34708_reg reg, u32 *val);
>  extern int mc34708_reg_write(struct mc34708 *mc34708, enum mc34708_reg reg, u32 val);
> -- 

Please apply this to master.
I want to merge all m13xxx same as in kernel.
If I get time, of course. :)

---

From s.hauer at pengutronix.de  Thu Jun 27 02:37:08 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Jun 2013 08:37:08 +0200
Subject: [PATCH] mfd: mc34708: provide static inline wrapper
In-Reply-To: <1372269426.799780740@f180.mail.ru>
References: <1372235714-5568-1-git-send-email-s.hauer@pengutronix.de>
 <1372269426.799780740@f180.mail.ru>
Message-ID: <20130627063708.GC516@pengutronix.de>

On Wed, Jun 26, 2013 at 09:57:06PM +0400, Alexander Shiyan wrote:
> > If the driver is disabled provide a static inline wrapper for
> > mc34708_get() to prevent linker errors.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > ---
> >  include/mfd/mc34708.h | 9 ++++++++-
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/include/mfd/mc34708.h b/include/mfd/mc34708.h
> > index f384c62..541c47f 100644
> > --- a/include/mfd/mc34708.h
> > +++ b/include/mfd/mc34708.h
> > @@ -93,7 +93,14 @@ struct mc34708 {
> >  	unsigned int		revision;
> >  };
> >  
> > -extern struct mc34708 *mc34708_get(void);
> > +#ifdef CONFIG_MFD_MC34708
> > +struct mc34708 *mc34708_get(void);
> > +#else
> > +static inline struct mc34708 *mc34708_get(void)
> > +{
> > +	return NULL;
> > +}
> > +#endif
> >  
> >  extern int mc34708_reg_read(struct mc34708 *mc34708, enum mc34708_reg reg, u32 *val);
> >  extern int mc34708_reg_write(struct mc34708 *mc34708, enum mc34708_reg reg, u32 val);
> > -- 
> 
> Please apply this to master.
> I want to merge all m13xxx same as in kernel.
> If I get time, of course. :)

That's nicem but why should I apply it to master now? It will be there
anyway in a week.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Thu Jun 27 02:39:29 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Jun 2013 08:39:29 +0200
Subject: [PATCH v3 0/8] DDR2 memory initialisation
In-Reply-To: <1372268027-15271-1-git-send-email-renaud.barbier@ge.com>
References: <1372157137-7602-1-git-send-email-renaud.barbier@ge.com>
 <1372268027-15271-1-git-send-email-renaud.barbier@ge.com>
Message-ID: <20130627063929.GD516@pengutronix.de>

On Wed, Jun 26, 2013 at 06:33:39PM +0100, Renaud Barbier wrote:
> This patch set addresses the following issues from the version v2.
> 
> It renames the function ddr2_spd_check to a more meaningful name.
> All commits acknowledge that the base of the source code is thanks
> to the U-Boot community.

Applied, thanks

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From shc_work at mail.ru  Thu Jun 27 02:51:11 2013
From: shc_work at mail.ru (=?UTF-8?B?QWxleGFuZGVyIFNoaXlhbg==?=)
Date: Thu, 27 Jun 2013 10:51:11 +0400
Subject: =?UTF-8?B?UmVbMl06IFtQQVRDSF0gbWZkOiBtYzM0NzA4OiBwcm92aWRlIHN0YXRpYyBp?=
 =?UTF-8?B?bmxpbmUgd3JhcHBlcg==?=
In-Reply-To: <20130627063708.GC516@pengutronix.de>
References: <1372235714-5568-1-git-send-email-s.hauer@pengutronix.de>
 <1372269426.799780740@f180.mail.ru>
 <20130627063708.GC516@pengutronix.de>
Message-ID: <1372315871.448673693@f281.mail.ru>

> On Wed, Jun 26, 2013 at 09:57:06PM +0400, Alexander Shiyan wrote:
> > > If the driver is disabled provide a static inline wrapper for
> > > mc34708_get() to prevent linker errors.
> > > 
> > > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > > ---
...
> > Please apply this to master.
> > I want to merge all m13xxx same as in kernel.
> > If I get time, of course. :)
> 
> That's nicem but why should I apply it to master now? It will be there
> anyway in a week.

Well, let it be so, since we have as a lot of other changes.
Thanks.

---

From s.hauer at pengutronix.de  Thu Jun 27 02:51:18 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Jun 2013 08:51:18 +0200
Subject: [PATCH 0/9] OF: address and device related sync and cleanup
In-Reply-To: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130627065118.GA10414@pengutronix.de>

On Tue, Jun 25, 2013 at 11:20:38AM +0200, Sebastian Hesselbarth wrote:
> This patch set comprises a quite unsorted bunch of patches to further
> improve and cleanup OF API. With address and device related functions,
> two more API sets of Linux OF API are imported and modified to match
> barebox driver core.
> 
> With above API improvements, device and resource pointer are removed
> from struct device_node. Futher, of_translate_address, of_probe, and
> of_add_memory are converted to recently introduced OF API.
> 
> At last, of_free is renamed to of_delete_node, which gives a better
> impression of what the function is doing.
> 
> Sebastian Hesselbarth (9):
>   OF: import address related functions from Linux OF API
>   OF: convert of_translate_address to new API
>   OF: base: move OF_ROOT_NODE_ defines to local OF code
>   OF: import bus/device related functions from Linux OF API
>   OF: base: use of_platform_populate for probing
>   OF: base: remove dead device related functions
>   OF: remove device and resource pointer from struct device_node
>   OF: base: convert of_add_memory to OF API
>   OF: base: rename of_free to of_delete_node

Applied this series with the change that I removed the dead code
ifdeffed with CONFIG_PPC_DCR.

Thanks
 Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From plagnioj at jcrosoft.com  Thu Jun 27 03:03:26 2013
From: plagnioj at jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
Date: Thu, 27 Jun 2013 09:03:26 +0200
Subject: [PATCH 08/11] ARM: i.MX6 realq7: prepare multiboard support
In-Reply-To: <1372233657-19455-9-git-send-email-s.hauer@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
 <1372233657-19455-9-git-send-email-s.hauer@pengutronix.de>
Message-ID: <20130627070326.GL27130@game.jcrosoft.org>

On 10:00 Wed 26 Jun     , Sascha Hauer wrote:
> Protect initcalls with the corrent of compatible.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  arch/arm/boards/dmo-mx6-realq7/board.c | 19 +++++++++++--------
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/arm/boards/dmo-mx6-realq7/board.c b/arch/arm/boards/dmo-mx6-realq7/board.c
> index 7983b88..9cf6c31 100644
> --- a/arch/arm/boards/dmo-mx6-realq7/board.c
> +++ b/arch/arm/boards/dmo-mx6-realq7/board.c
> @@ -81,6 +81,9 @@ static int ksz9031rn_phy_fixup(struct phy_device *dev)
>  
>  static int realq7_enet_init(void)
>  {
> +	if (!of_machine_is_compatible("dmo,imx6q-realq7"))
> +		return 0;
> +
>  	mxc_iomux_v3_setup_multiple_pads(realq7_pads_gpio, ARRAY_SIZE(realq7_pads_gpio));
>  	gpio_direction_output(RQ7_GPIO_ENET_PHYADD2, 0);
>  	gpio_direction_output(RQ7_GPIO_ENET_MODE0, 1);
> @@ -102,19 +105,16 @@ static int realq7_enet_init(void)
>  }
>  fs_initcall(realq7_enet_init);
>  
> -static int realq7_devices_init(void)
> +static int realq7_env_init(void)
>  {
> +	if (!of_machine_is_compatible("dmo,imx6q-realq7"))
> +		return 0;
> +
>  	imx6_bbu_internal_spi_i2c_register_handler("spiflash", "/dev/m25p0.barebox",
>  		BBU_HANDLER_FLAG_DEFAULT, NULL, 0, 0x00907000);
>  	imx6_bbu_internal_mmc_register_handler("mmc", "/dev/mmc3.barebox",
>  		0, NULL, 0, 0x00907000);
>  
> -	return 0;
> -}
> -device_initcall(realq7_devices_init);
> -
> -static int realq7_env_init(void)
> -{
>  	switch (bootsource_get()) {
>  	case BOOTSOURCE_MMC:
>  		device_detect_by_name("mmc3");
> @@ -136,8 +136,11 @@ late_initcall(realq7_env_init);
>  
>  static int realq7_console_init(void)
>  {
> +	if (!of_machine_is_compatible("dmo,imx6q-realq7"))
> +		return 0;
> +
>  	imx6_init_lowlevel();
>  
>  	return 0;
>  }
> -core_initcall(realq7_console_init);
> +postcore_initcall(realq7_console_init);

I really don't like those if (!of_mac......

can we have a struct os is the kernel?

It will help me on at91 to cleanup the at91 to move to empty board.h
and will allow to not be of only

Best Regards,
J.
> -- 
> 1.8.3.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


From sebastian.hesselbarth at gmail.com  Thu Jun 27 03:50:10 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Thu, 27 Jun 2013 09:50:10 +0200
Subject: [PATCH 0/9] OF: address and device related sync and cleanup
In-Reply-To: <20130627065118.GA10414@pengutronix.de>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130627065118.GA10414@pengutronix.de>
Message-ID: <51CBEEB2.5090209@gmail.com>

On 06/27/13 08:51, Sascha Hauer wrote:
> On Tue, Jun 25, 2013 at 11:20:38AM +0200, Sebastian Hesselbarth wrote:
>> This patch set comprises a quite unsorted bunch of patches to further
>> improve and cleanup OF API. With address and device related functions,
>> two more API sets of Linux OF API are imported and modified to match
>> barebox driver core.
>>
>> With above API improvements, device and resource pointer are removed
>> from struct device_node. Futher, of_translate_address, of_probe, and
>> of_add_memory are converted to recently introduced OF API.
>>
>> At last, of_free is renamed to of_delete_node, which gives a better
>> impression of what the function is doing.
>>
>> Sebastian Hesselbarth (9):
>>    OF: import address related functions from Linux OF API
>>    OF: convert of_translate_address to new API
>>    OF: base: move OF_ROOT_NODE_ defines to local OF code
>>    OF: import bus/device related functions from Linux OF API
>>    OF: base: use of_platform_populate for probing
>>    OF: base: remove dead device related functions
>>    OF: remove device and resource pointer from struct device_node
>>    OF: base: convert of_add_memory to OF API
>>    OF: base: rename of_free to of_delete_node
>
> Applied this series with the change that I removed the dead code
> ifdeffed with CONFIG_PPC_DCR.

Ok, great! Next patch sets will be focused on actually using the
DT improvements. I have an SPI driver for MACH_MVEBU ready and
running, and I am working on importing generic SDHCI from Linux.

Sebastian



From s.hauer at pengutronix.de  Thu Jun 27 04:58:16 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Jun 2013 10:58:16 +0200
Subject: [PATCH 0/9] OF: address and device related sync and cleanup
In-Reply-To: <51CBEEB2.5090209@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130627065118.GA10414@pengutronix.de>
 <51CBEEB2.5090209@gmail.com>
Message-ID: <20130627085816.GF516@pengutronix.de>

On Thu, Jun 27, 2013 at 09:50:10AM +0200, Sebastian Hesselbarth wrote:
> On 06/27/13 08:51, Sascha Hauer wrote:
> >On Tue, Jun 25, 2013 at 11:20:38AM +0200, Sebastian Hesselbarth wrote:
> >>This patch set comprises a quite unsorted bunch of patches to further
> >>improve and cleanup OF API. With address and device related functions,
> >>two more API sets of Linux OF API are imported and modified to match
> >>barebox driver core.
> >>
> >>With above API improvements, device and resource pointer are removed
> >>from struct device_node. Futher, of_translate_address, of_probe, and
> >>of_add_memory are converted to recently introduced OF API.
> >>
> >>At last, of_free is renamed to of_delete_node, which gives a better
> >>impression of what the function is doing.
> >>
> >>Sebastian Hesselbarth (9):
> >>   OF: import address related functions from Linux OF API
> >>   OF: convert of_translate_address to new API
> >>   OF: base: move OF_ROOT_NODE_ defines to local OF code
> >>   OF: import bus/device related functions from Linux OF API
> >>   OF: base: use of_platform_populate for probing
> >>   OF: base: remove dead device related functions
> >>   OF: remove device and resource pointer from struct device_node
> >>   OF: base: convert of_add_memory to OF API
> >>   OF: base: rename of_free to of_delete_node
> >
> >Applied this series with the change that I removed the dead code
> >ifdeffed with CONFIG_PPC_DCR.
> 
> Ok, great! Next patch sets will be focused on actually using the
> DT improvements. I have an SPI driver for MACH_MVEBU ready and
> running, and I am working on importing generic SDHCI from Linux.

The sdhc driver in Linux is a big piece of shit which uses the wrong
abstraction model. This is shown by the fact that 32bits are not enough
to abstract the quirks. Even with all these quirks the i.MX part of this
driver has to implement driver logic in the register access functions.
That just insane. I'm not really looking forward to add this driver
to barebox.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Thu Jun 27 05:00:46 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Thu, 27 Jun 2013 11:00:46 +0200
Subject: [PATCH 0/9] OF: address and device related sync and cleanup
In-Reply-To: <20130627085816.GF516@pengutronix.de>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130627065118.GA10414@pengutronix.de> <51CBEEB2.5090209@gmail.com>
 <20130627085816.GF516@pengutronix.de>
Message-ID: <51CBFF3E.6090306@gmail.com>

On 06/27/13 10:58, Sascha Hauer wrote:
> On Thu, Jun 27, 2013 at 09:50:10AM +0200, Sebastian Hesselbarth wrote:
>> On 06/27/13 08:51, Sascha Hauer wrote:
>>> Applied this series with the change that I removed the dead code
>>> ifdeffed with CONFIG_PPC_DCR.
>>
>> Ok, great! Next patch sets will be focused on actually using the
>> DT improvements. I have an SPI driver for MACH_MVEBU ready and
>> running, and I am working on importing generic SDHCI from Linux.
>
> The sdhc driver in Linux is a big piece of shit which uses the wrong
> abstraction model. This is shown by the fact that 32bits are not enough
> to abstract the quirks. Even with all these quirks the i.MX part of this
> driver has to implement driver logic in the register access functions.
> That just insane. I'm not really looking forward to add this driver
> to barebox.

Ok, fair enough. Then I'll be adding the required callbacks to Dove
SDHCI driver directly based on current barebox i.MX driver.

Sebastian



From s.hauer at pengutronix.de  Thu Jun 27 06:06:40 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Jun 2013 12:06:40 +0200
Subject: [PATCH] ARM: Marvell boards: Fix out of tree compilation
Message-ID: <1372327600-24715-1-git-send-email-s.hauer@pengutronix.de>

The Marvell boards accidently add a .c instead of a .o file
to the targets. This has the side effect of breaking out of tree
compilation.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 arch/arm/boards/globalscale-mirabox/Makefile | 2 +-
 arch/arm/boards/solidrun-cubox/Makefile      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/globalscale-mirabox/Makefile b/arch/arm/boards/globalscale-mirabox/Makefile
index 9320510..dcfc293 100644
--- a/arch/arm/boards/globalscale-mirabox/Makefile
+++ b/arch/arm/boards/globalscale-mirabox/Makefile
@@ -1 +1 @@
-obj-y += board.c
+obj-y += board.o
diff --git a/arch/arm/boards/solidrun-cubox/Makefile b/arch/arm/boards/solidrun-cubox/Makefile
index 9320510..dcfc293 100644
--- a/arch/arm/boards/solidrun-cubox/Makefile
+++ b/arch/arm/boards/solidrun-cubox/Makefile
@@ -1 +1 @@
-obj-y += board.c
+obj-y += board.o
-- 
1.8.3.1



From sebastian.hesselbarth at gmail.com  Thu Jun 27 13:39:20 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Thu, 27 Jun 2013 19:39:20 +0200
Subject: [PATCH] clocksource: fix Marvell timer read-back value
Message-ID: <1372354760-31955-1-git-send-email-sebastian.hesselbarth@gmail.com>

Clocksource read callback expects incrementing timer values, while
internal timer on Marvell SoCs counts backwards. Fix value returned
by Marvell MVEBU and Orion clocksource drivers.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Cc: barebox at lists.infradead.org
---
 drivers/clocksource/mvebu.c |    2 +-
 drivers/clocksource/orion.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/mvebu.c b/drivers/clocksource/mvebu.c
index 1a9d573..6e5ceba 100644
--- a/drivers/clocksource/mvebu.c
+++ b/drivers/clocksource/mvebu.c
@@ -42,7 +42,7 @@ static __iomem void *timer_base;
 
 uint64_t mvebu_clocksource_read(void)
 {
-	return __raw_readl(timer_base + TIMER0_VAL_OFF);
+	return 0 - __raw_readl(timer_base + TIMER0_VAL_OFF);
 }
 
 static struct clocksource cs = {
diff --git a/drivers/clocksource/orion.c b/drivers/clocksource/orion.c
index d27477a..6902c72 100644
--- a/drivers/clocksource/orion.c
+++ b/drivers/clocksource/orion.c
@@ -34,7 +34,7 @@ static __iomem void *timer_base;
 
 static uint64_t orion_clocksource_read(void)
 {
-	return __raw_readl(timer_base + TIMER0_VAL);
+	return 0 - __raw_readl(timer_base + TIMER0_VAL);
 }
 
 static struct clocksource clksrc = {
-- 
1.7.2.5



From s.hauer at pengutronix.de  Thu Jun 27 14:19:23 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Jun 2013 20:19:23 +0200
Subject: [PATCH 0/9] OF: address and device related sync and cleanup
In-Reply-To: <51CBFF3E.6090306@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130627065118.GA10414@pengutronix.de>
 <51CBEEB2.5090209@gmail.com> <20130627085816.GF516@pengutronix.de>
 <51CBFF3E.6090306@gmail.com>
Message-ID: <20130627181923.GH516@pengutronix.de>

On Thu, Jun 27, 2013 at 11:00:46AM +0200, Sebastian Hesselbarth wrote:
> On 06/27/13 10:58, Sascha Hauer wrote:
> >On Thu, Jun 27, 2013 at 09:50:10AM +0200, Sebastian Hesselbarth wrote:
> >>On 06/27/13 08:51, Sascha Hauer wrote:
> >>>Applied this series with the change that I removed the dead code
> >>>ifdeffed with CONFIG_PPC_DCR.
> >>
> >>Ok, great! Next patch sets will be focused on actually using the
> >>DT improvements. I have an SPI driver for MACH_MVEBU ready and
> >>running, and I am working on importing generic SDHCI from Linux.
> >
> >The sdhc driver in Linux is a big piece of shit which uses the wrong
> >abstraction model. This is shown by the fact that 32bits are not enough
> >to abstract the quirks. Even with all these quirks the i.MX part of this
> >driver has to implement driver logic in the register access functions.
> >That just insane. I'm not really looking forward to add this driver
> >to barebox.
> 
> Ok, fair enough. Then I'll be adding the required callbacks to Dove
> SDHCI driver directly based on current barebox i.MX driver.

I think for the SDHC a library approach would be good: Add a new driver
and share common code/helper functions. I recently factored out the
register defines as a start so that these can be shared.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Thu Jun 27 14:27:47 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Thu, 27 Jun 2013 20:27:47 +0200
Subject: [PATCH 0/9] OF: address and device related sync and cleanup
In-Reply-To: <20130627181923.GH516@pengutronix.de>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130627065118.GA10414@pengutronix.de> <51CBEEB2.5090209@gmail.com>
 <20130627085816.GF516@pengutronix.de> <51CBFF3E.6090306@gmail.com>
 <20130627181923.GH516@pengutronix.de>
Message-ID: <51CC8423.301@gmail.com>

On 06/27/13 20:19, Sascha Hauer wrote:
> On Thu, Jun 27, 2013 at 11:00:46AM +0200, Sebastian Hesselbarth wrote:
>> On 06/27/13 10:58, Sascha Hauer wrote:
>>> On Thu, Jun 27, 2013 at 09:50:10AM +0200, Sebastian Hesselbarth wrote:
>>>> On 06/27/13 08:51, Sascha Hauer wrote:
>>>>> Applied this series with the change that I removed the dead code
>>>>> ifdeffed with CONFIG_PPC_DCR.
>>>>
>>>> Ok, great! Next patch sets will be focused on actually using the
>>>> DT improvements. I have an SPI driver for MACH_MVEBU ready and
>>>> running, and I am working on importing generic SDHCI from Linux.
>>>
>>> The sdhc driver in Linux is a big piece of shit which uses the wrong
>>> abstraction model. This is shown by the fact that 32bits are not enough
>>> to abstract the quirks. Even with all these quirks the i.MX part of this
>>> driver has to implement driver logic in the register access functions.
>>> That just insane. I'm not really looking forward to add this driver
>>> to barebox.
>>
>> Ok, fair enough. Then I'll be adding the required callbacks to Dove
>> SDHCI driver directly based on current barebox i.MX driver.
>
> I think for the SDHC a library approach would be good: Add a new driver
> and share common code/helper functions. I recently factored out the
> register defines as a start so that these can be shared.

Yeah, I just working at SDHCI driver for Dove and wonder if I start
to wrap my brain around readl/writel or go with readb/w/l as it is
supposed to be.

As soon as I got some valid responses back from the usdcard, I have
another look at sdhci.h and a generic approach.

Sebastian



From s.hauer at pengutronix.de  Thu Jun 27 14:32:17 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Thu, 27 Jun 2013 20:32:17 +0200
Subject: [PATCH 08/11] ARM: i.MX6 realq7: prepare multiboard support
In-Reply-To: <20130627070326.GL27130@game.jcrosoft.org>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
 <1372233657-19455-9-git-send-email-s.hauer@pengutronix.de>
 <20130627070326.GL27130@game.jcrosoft.org>
Message-ID: <20130627183217.GI516@pengutronix.de>

On Thu, Jun 27, 2013 at 09:03:26AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 10:00 Wed 26 Jun     , Sascha Hauer wrote:
> >  	return 0;
> >  }
> > -core_initcall(realq7_console_init);
> > +postcore_initcall(realq7_console_init);
> 
> I really don't like those if (!of_mac......

As discussed on IRQ I don't like it either...

> 
> can we have a struct os is the kernel?

...but my experiments with a struct also were not very promising.

I'm open for patches. For now I think the compatible matching is
good enough, but it should be worked on before we have hundreds
of initcalls like this.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From plagnioj at jcrosoft.com  Fri Jun 28 03:40:40 2013
From: plagnioj at jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
Date: Fri, 28 Jun 2013 09:40:40 +0200
Subject: [PATCH 08/11] ARM: i.MX6 realq7: prepare multiboard support
In-Reply-To: <20130627183217.GI516@pengutronix.de>
References: <1372233657-19455-1-git-send-email-s.hauer@pengutronix.de>
 <1372233657-19455-9-git-send-email-s.hauer@pengutronix.de>
 <20130627070326.GL27130@game.jcrosoft.org>
 <20130627183217.GI516@pengutronix.de>
Message-ID: <20130628074040.GM27130@game.jcrosoft.org>

On 20:32 Thu 27 Jun     , Sascha Hauer wrote:
> On Thu, Jun 27, 2013 at 09:03:26AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 10:00 Wed 26 Jun     , Sascha Hauer wrote:
> > >  	return 0;
> > >  }
> > > -core_initcall(realq7_console_init);
> > > +postcore_initcall(realq7_console_init);
> > 
> > I really don't like those if (!of_mac......
> 
> As discussed on IRQ I don't like it either...
IRQ ;)
> 
> > 
> > can we have a struct os is the kernel?
> 
> ...but my experiments with a struct also were not very promising.
> 
> I'm open for patches. For now I think the compatible matching is
> good enough, but it should be worked on before we have hundreds
> of initcalls like this.
as discuss on IRC I do prefer the struct like we have today on ARM Kernel

with something like this

struct machine {
	const char *of_compatible;
	u32 machine_id;
	int (*pure)(void);
	int (*mem)(void);
	int (*console)(void);
	int (*device)(void);
	int (*late)(void);
};

I did it on at91 soc it's clean and speed the boot vs if xxx

I do agree this will requiere some work but this will have the advantage to not be only of related

so arch or board that are not OF can still use it

Best Regards,
J.


From plagnioj at jcrosoft.com  Fri Jun 28 09:52:02 2013
From: plagnioj at jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
Date: Fri, 28 Jun 2013 15:52:02 +0200
Subject: [PATCH] ARM: Marvell boards: Fix out of tree compilation
In-Reply-To: <1372327600-24715-1-git-send-email-s.hauer@pengutronix.de>
References: <1372327600-24715-1-git-send-email-s.hauer@pengutronix.de>
Message-ID: <20130628135202.GA23449@game.jcrosoft.org>

On 12:06 Thu 27 Jun     , Sascha Hauer wrote:
> The Marvell boards accidently add a .c instead of a .o file
> to the targets. This has the side effect of breaking out of tree
> compilation.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>

Best Regards,
J.
> ---
>  arch/arm/boards/globalscale-mirabox/Makefile | 2 +-
>  arch/arm/boards/solidrun-cubox/Makefile      | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/boards/globalscale-mirabox/Makefile b/arch/arm/boards/globalscale-mirabox/Makefile
> index 9320510..dcfc293 100644
> --- a/arch/arm/boards/globalscale-mirabox/Makefile
> +++ b/arch/arm/boards/globalscale-mirabox/Makefile
> @@ -1 +1 @@
> -obj-y += board.c
> +obj-y += board.o
> diff --git a/arch/arm/boards/solidrun-cubox/Makefile b/arch/arm/boards/solidrun-cubox/Makefile
> index 9320510..dcfc293 100644
> --- a/arch/arm/boards/solidrun-cubox/Makefile
> +++ b/arch/arm/boards/solidrun-cubox/Makefile
> @@ -1 +1 @@
> -obj-y += board.c
> +obj-y += board.o
> -- 
> 1.8.3.1
> 


From sebastian.hesselbarth at gmail.com  Fri Jun 28 14:25:43 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 28 Jun 2013 20:25:43 +0200
Subject: [PATCH 2/6] clocksource: orion: add DT support
In-Reply-To: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372443947-12599-3-git-send-email-sebastian.hesselbarth@gmail.com>

This adds device tree support to orion timer and also converts clk_get
to clk_lookup to find TCLK without device name reference.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Cc: barebox at lists.infradead.org
---
 drivers/clocksource/orion.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/drivers/clocksource/orion.c b/drivers/clocksource/orion.c
index e3db845..ed71fa4 100644
--- a/drivers/clocksource/orion.c
+++ b/drivers/clocksource/orion.c
@@ -49,7 +49,7 @@ static int orion_timer_probe(struct device_d *dev)
 	uint32_t val;
 
 	timer_base = dev_request_mem_region(dev, 0);
-	tclk = clk_get(dev, "tclk");
+	tclk = clk_lookup("tclk");
 
 	/* setup TIMER0 as free-running clock source */
 	__raw_writel(~0, timer_base + TIMER0_VAL);
@@ -64,9 +64,15 @@ static int orion_timer_probe(struct device_d *dev)
 	return 0;
 }
 
+static struct of_device_id orion_timer_dt_ids[] = {
+	{ .compatible = "marvell,orion-timer", },
+	{ }
+};
+
 static struct driver_d orion_timer_driver = {
 	.name = "orion-timer",
 	.probe = orion_timer_probe,
+	.of_compatible = DRV_OF_COMPAT(orion_timer_dt_ids),
 };
 
 static int orion_timer_init(void)
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Fri Jun 28 14:25:42 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 28 Jun 2013 20:25:42 +0200
Subject: [PATCH 1/6] ARM: mvebu: move soc_init to core_initcall
In-Reply-To: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372443947-12599-2-git-send-email-sebastian.hesselbarth@gmail.com>

Clocks need to be accessed early for DT support, so move soc_init to
core_initcall instead of postcore_initcall.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Cc: barebox at lists.infradead.org
---
 arch/arm/mach-mvebu/armada-370-xp.c |    2 +-
 arch/arm/mach-mvebu/dove.c          |    2 +-
 arch/arm/mach-mvebu/kirkwood.c      |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-mvebu/armada-370-xp.c b/arch/arm/mach-mvebu/armada-370-xp.c
index 2cdc3b0..1d64861 100644
--- a/arch/arm/mach-mvebu/armada-370-xp.c
+++ b/arch/arm/mach-mvebu/armada-370-xp.c
@@ -109,7 +109,7 @@ static int armada_370_xp_init_soc(void)
 	armada_370_xp_add_uart();
 	return 0;
 }
-postcore_initcall(armada_370_xp_init_soc);
+core_initcall(armada_370_xp_init_soc);
 
 void __noreturn reset_cpu(unsigned long addr)
 {
diff --git a/arch/arm/mach-mvebu/dove.c b/arch/arm/mach-mvebu/dove.c
index 6e8e113..ee63917 100644
--- a/arch/arm/mach-mvebu/dove.c
+++ b/arch/arm/mach-mvebu/dove.c
@@ -132,7 +132,7 @@ static int dove_init_soc(void)
 
 	return 0;
 }
-postcore_initcall(dove_init_soc);
+core_initcall(dove_init_soc);
 
 void __noreturn reset_cpu(unsigned long addr)
 {
diff --git a/arch/arm/mach-mvebu/kirkwood.c b/arch/arm/mach-mvebu/kirkwood.c
index 3e16f41..9e43dae 100644
--- a/arch/arm/mach-mvebu/kirkwood.c
+++ b/arch/arm/mach-mvebu/kirkwood.c
@@ -95,7 +95,7 @@ static int kirkwood_init_soc(void)
 
 	return 0;
 }
-postcore_initcall(kirkwood_init_soc);
+core_initcall(kirkwood_init_soc);
 
 void __noreturn reset_cpu(unsigned long addr)
 {
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Fri Jun 28 14:25:44 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 28 Jun 2013 20:25:44 +0200
Subject: [PATCH 3/6] clocksource: mvebu: add DT support
In-Reply-To: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372443947-12599-4-git-send-email-sebastian.hesselbarth@gmail.com>

This adds device tree support to mvebu timer and also converts clk_get
to clk_lookup to find TCLK without device name reference.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Cc: barebox at lists.infradead.org
---
 drivers/clocksource/mvebu.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/mvebu.c b/drivers/clocksource/mvebu.c
index 8bedd99..93b0b61 100644
--- a/drivers/clocksource/mvebu.c
+++ b/drivers/clocksource/mvebu.c
@@ -57,8 +57,7 @@ static int mvebu_timer_probe(struct device_d *dev)
 	u32 val;
 
 	timer_base = dev_request_mem_region(dev, 0);
-
-	tclk = clk_get(dev, "tclk");
+	tclk = clk_lookup("tclk");
 
 	val = __raw_readl(timer_base + TIMER_CTRL_OFF);
 	val &= ~TIMER0_25MHZ;
@@ -78,9 +77,15 @@ static int mvebu_timer_probe(struct device_d *dev)
 	return 0;
 }
 
+static struct of_device_id mvebu_timer_dt_ids[] = {
+	{ .compatible = "marvell,armada-370-xp-timer", },
+	{ }
+};
+
 static struct driver_d mvebu_timer_driver = {
 	.name = "mvebu-timer",
 	.probe = mvebu_timer_probe,
+	.of_compatible = DRV_OF_COMPAT(mvebu_timer_dt_ids),
 };
 
 static int mvebu_timer_init(void)
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Fri Jun 28 14:25:41 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 28 Jun 2013 20:25:41 +0200
Subject: [PATCH 0/6] ARM: mvebu: DT support, SPI driver, and Dove DT
Message-ID: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>

This patch set is a first attempt to bring full DT support to Marvell
MVEBU SoCs. It also introduces a driver for the SPI controller found
on these SoCs with special treatment of additional functions for Dove
and Armada 370/XP SoCs.

First, current soc_init is moved from postcore initcall to core initcall,
to allow clocks to be accessed early. Then DT support is added for both
clocksource drivers found on Orion and Armada 370/XP SoCs, respectively.
Third, a DT-only SPI driver is added to allow access to SPI devices found
on boards comprising Marvell SoCs.

The last two patches extend SolidRun CuBox defconfig with a bunch of
options for future drivers and debug commands and import DTS files from
Linux with an additional node for the timer.

The patch set depends on the MVEBU/Orion clocksource callback patch sent
earlier.

Sebastian Hesselbarth (6):
  ARM: mvebu: move soc_init to core_initcall
  clocksource: orion: add DT support
  clocksource: mvebu: add DT support
  spi: add Marvell MVEBU SoC SPI driver
  ARM: mvebu: add more options to SolidRun CuBox defconfig
  ARM: mvebu: import DT files for Dove SoC and SolidRun CuBox

 arch/arm/configs/solidrun_cubox_defconfig |   71 ++++++
 arch/arm/dts/dove-cubox.dts               |  154 ++++++++++++
 arch/arm/dts/dove.dtsi                    |  285 ++++++++++++++++++++++
 arch/arm/mach-mvebu/armada-370-xp.c       |    2 +-
 arch/arm/mach-mvebu/dove.c                |    2 +-
 arch/arm/mach-mvebu/kirkwood.c            |    2 +-
 drivers/clocksource/mvebu.c               |    9 +-
 drivers/clocksource/orion.c               |    8 +-
 drivers/spi/Kconfig                       |    4 +
 drivers/spi/Makefile                      |    1 +
 drivers/spi/mvebu_spi.c                   |  378 +++++++++++++++++++++++++++++
 11 files changed, 910 insertions(+), 6 deletions(-)
 create mode 100644 arch/arm/dts/dove-cubox.dts
 create mode 100644 arch/arm/dts/dove.dtsi
 create mode 100644 drivers/spi/mvebu_spi.c

---
Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Cc: barebox at lists.infradead.org
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Fri Jun 28 14:25:46 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 28 Jun 2013 20:25:46 +0200
Subject: [PATCH 5/6] ARM: mvebu: add more options to SolidRun CuBox defconfig
In-Reply-To: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372443947-12599-6-git-send-email-sebastian.hesselbarth@gmail.com>

This patch updates SolidRun CuBox defconfig to more commands also valueable
for debug. Also, all future driver subsystems are enabled to ease driver
development.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Cc: barebox at lists.infradead.org
---
 arch/arm/configs/solidrun_cubox_defconfig |   71 +++++++++++++++++++++++++++++
 1 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/arch/arm/configs/solidrun_cubox_defconfig b/arch/arm/configs/solidrun_cubox_defconfig
index 1a27d81..c900243 100644
--- a/arch/arm/configs/solidrun_cubox_defconfig
+++ b/arch/arm/configs/solidrun_cubox_defconfig
@@ -1,9 +1,80 @@
+CONFIG_BUILTIN_DTB=y
+CONFIG_BUILTIN_DTB_NAME="dove-cubox"
 CONFIG_ARCH_MVEBU=y
 CONFIG_ARCH_DOVE=y
 CONFIG_AEABI=y
+CONFIG_CMD_ARM_MMUINFO=y
+CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
+CONFIG_LONGHELP=y
+CONFIG_CMDLINE_EDITING=y
+CONFIG_AUTO_COMPLETE=y
 CONFIG_DEBUG_LL=y
+CONFIG_CMD_EDIT=y
+CONFIG_CMD_SLEEP=y
+CONFIG_CMD_MSLEEP=y
+CONFIG_CMD_SAVEENV=y
+CONFIG_CMD_EXPORT=y
+CONFIG_CMD_PRINTENV=y
+CONFIG_CMD_READLINE=y
+CONFIG_CMD_LET=y
+CONFIG_CMD_TIME=y
+CONFIG_CMD_GLOBAL=y
+CONFIG_CMD_AUTOMOUNT=y
+CONFIG_CMD_BASENAME=y
+CONFIG_CMD_DIRNAME=y
+CONFIG_CMD_LN=y
+CONFIG_CMD_READLINK=y
+CONFIG_CMD_FILETYPE=y
+CONFIG_CMD_ECHO_E=y
 CONFIG_CMD_LOADY=y
 CONFIG_CMD_LOADS=y
+CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_IOMEM=y
+CONFIG_CMD_MD5SUM=y
+CONFIG_CMD_SHA1SUM=y
+CONFIG_CMD_SHA256SUM=y
+CONFIG_CMD_SHA224SUM=y
+CONFIG_CMD_BOOTM_SHOW_TYPE=y
+CONFIG_CMD_BOOTM_VERBOSE=y
+CONFIG_CMD_BOOTM_INITRD=y
+CONFIG_CMD_BOOTM_OFTREE=y
+CONFIG_CMD_BOOTM_OFTREE_UIMAGE=y
+CONFIG_CMD_UIMAGE=y
 CONFIG_CMD_RESET=y
+CONFIG_CMD_GO=y
+CONFIG_CMD_OFTREE=y
+CONFIG_CMD_OF_PROPERTY=y
+CONFIG_CMD_OF_NODE=y
+CONFIG_CMD_TIMEOUT=y
+CONFIG_CMD_PARTITION=y
+CONFIG_CMD_UNCOMPRESS=y
+CONFIG_CMD_I2C=y
+CONFIG_CMD_SPI=y
+CONFIG_CMD_LED=y
+CONFIG_CMD_LED_TRIGGER=y
 CONFIG_CMD_CLK=y
+CONFIG_CMD_DETECT=y
+CONFIG_CMD_WD=y
+CONFIG_OFDEVICE=y
 CONFIG_DRIVER_SERIAL_NS16550=y
+CONFIG_DRIVER_SPI_MVEBU=y
+CONFIG_I2C=y
+CONFIG_MTD=y
+CONFIG_MTD_M25P80=y
+CONFIG_DISK_AHCI=y
+CONFIG_USB=y
+CONFIG_USB_EHCI=y
+CONFIG_USB_STORAGE=y
+CONFIG_MCI=y
+CONFIG_MCI_STARTUP=y
+CONFIG_MCI_MMC_BOOT_PARTITIONS=y
+CONFIG_LED=y
+CONFIG_LED_TRIGGERS=y
+CONFIG_WATCHDOG=y
+CONFIG_FS_CRAMFS=y
+CONFIG_FS_EXT4=y
+CONFIG_FS_FAT=y
+CONFIG_FS_FAT_WRITE=y
+CONFIG_FS_FAT_LFN=y
+CONFIG_BZLIB=y
+CONFIG_LZO_DECOMPRESS=y
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Fri Jun 28 14:25:45 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 28 Jun 2013 20:25:45 +0200
Subject: [PATCH 4/6] spi: add Marvell MVEBU SoC SPI driver
In-Reply-To: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372443947-12599-5-git-send-email-sebastian.hesselbarth@gmail.com>

This adds support for the SPI controller found on Marvell MVEBU SoCs
(Dove, Kirkwood, Discovery Innovation, and Armada 370/XP). Current driver
is DT only. Compatible strings are provided for Orion (common denominator),
Armada 370/XP and Dove SoCs.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Cc: barebox at lists.infradead.org
---
 drivers/spi/Kconfig     |    4 +
 drivers/spi/Makefile    |    1 +
 drivers/spi/mvebu_spi.c |  378 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 383 insertions(+), 0 deletions(-)
 create mode 100644 drivers/spi/mvebu_spi.c

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index c279c21..422693c 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -38,6 +38,10 @@ config DRIVER_SPI_MXS
 	depends on ARCH_IMX23 || ARCH_IMX28
 	depends on SPI
 
+config DRIVER_SPI_MVEBU
+	bool "Marvell MVEBU SoC SPI master driver"
+	depends on ARCH_ARMADA_370 || ARCH_ARMADA_XP || ARCH_DOVE || ARCH_KIRKWOOD
+
 config DRIVER_SPI_OMAP3
 	bool "OMAP3 McSPI Master driver"
 	depends on ARCH_OMAP3 || ARCH_AM33XX
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 642b7ec..1036f8f 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -1,5 +1,6 @@
 obj-$(CONFIG_SPI) += spi.o
 obj-$(CONFIG_DRIVER_SPI_IMX) += imx_spi.o
+obj-$(CONFIG_DRIVER_SPI_MVEBU) += mvebu_spi.o
 obj-$(CONFIG_DRIVER_SPI_MXS) += mxs_spi.o
 obj-$(CONFIG_DRIVER_SPI_ALTERA) += altera_spi.o
 obj-$(CONFIG_DRIVER_SPI_ATMEL) += atmel_spi.o
diff --git a/drivers/spi/mvebu_spi.c b/drivers/spi/mvebu_spi.c
new file mode 100644
index 0000000..200523d
--- /dev/null
+++ b/drivers/spi/mvebu_spi.c
@@ -0,0 +1,378 @@
+/*
+ * Marvell MVEBU SoC SPI controller
+ *  compatible with Dove, Kirkwood, MV78x00, Armada 370/XP
+ *
+ * Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
+ *
+ * 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.
+ */
+
+#include <common.h>
+#include <driver.h>
+#include <errno.h>
+#include <init.h>
+#include <io.h>
+#include <malloc.h>
+#include <spi/spi.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#define SPI_IF_CTRL		0x00
+#define  IF_CS_NUM(x)		((x) << 2)
+#define  IF_CS_NUM_MASK		IF_CS_NUM(7)
+#define  IF_READ_READY		BIT(1)
+#define  IF_CS_ENABLE		BIT(0)
+#define SPI_IF_CONFIG		0x04
+#define  IF_CLK_DIV(x)		((x) << 11)
+#define  IF_CLK_DIV_MASK	(0x7 << 11)
+#define  IF_FAST_READ		BIT(10)
+#define  IF_ADDRESS_LEN_4BYTE	(3 << 8)
+#define  IF_ADDRESS_LEN_3BYTE	(2 << 8)
+#define  IF_ADDRESS_LEN_2BYTE	(1 << 8)
+#define  IF_ADDRESS_LEN_1BYTE	(0 << 8)
+#define  IF_CLK_PRESCALE_POW8	BIT(7)
+#define  IF_CLK_PRESCALE_POW4	BIT(6)
+#define  IF_TRANSFER_2BYTE	BIT(5)
+#define  IF_CLK_PRESCALE_POW2	BIT(4)
+#define  IF_CLK_PRESCALE(x)	((x) & 0x0f)
+#define  IF_CLK_PRE_PRESCALE(x)	(((((x) & 0xc) << 1) | ((x) & 0x1)) << 4)
+#define  IF_CLK_PRESCALE_MASK	(IF_CLK_PRESCALE(7) | IF_CLK_PRE_PRESCALE(7))
+#define SPI_DATA_OUT		0x08
+#define SPI_DATA_IN		0x0c
+#define SPI_INT_CAUSE		0x10
+#define SPI_INT_MASK		0x14
+#define  INT_READ_READY		BIT(0)
+
+#define SPI_SPI_MAX_CS	8
+
+struct mvebu_spi {
+	struct spi_master master;
+	void __iomem *base;
+	struct clk *clk;
+	bool data16;
+	int (*set_baudrate)(struct mvebu_spi *p, u32 speed);
+};
+
+#define priv_from_spi_device(s)	\
+	container_of(s->master, struct mvebu_spi, master);
+
+static inline int mvebu_spi_set_cs(struct mvebu_spi *p, u8 cs, u8 mode, bool en)
+{
+	u32 val;
+
+	/*
+	 * Only Armada 370/XP support up to 8 CS signals, for the
+	 * others this register bits are read-only
+	 */
+	if (cs > SPI_SPI_MAX_CS)
+		return -EINVAL;
+
+	if (mode & SPI_CS_HIGH)
+		en = !en;
+
+	val = IF_CS_NUM(cs);
+	if (en)
+		val |= IF_CS_ENABLE;
+
+	writel(val, p->base + SPI_IF_CTRL);
+
+	return 0;
+}
+
+static int mvebu_spi_set_transfer_size(struct mvebu_spi *p, int size)
+{
+	u32 val;
+
+	if (size != 8 && size != 16)
+		return -EINVAL;
+
+	p->data16 = (size == 16);
+
+	val = readl(p->base + SPI_IF_CONFIG) & ~IF_TRANSFER_2BYTE;
+	if (p->data16)
+		val |= IF_TRANSFER_2BYTE;
+	writel(val, p->base + SPI_IF_CONFIG);
+	
+	return 0;
+}
+
+static int mvebu_spi_set_baudrate(struct mvebu_spi *p, u32 speed)
+{
+	u32 pscl, val;
+
+	/* standard prescaler values: 1,2,4,6,...,30 */
+	pscl = DIV_ROUND_UP(clk_get_rate(p->clk), speed);
+	pscl = roundup(pscl, 2);
+
+	debug("%s: clk = %lu, speed = %u, pscl = %d\n",
+		__func__, clk_get_rate(p->clk), speed, pscl);
+
+	if (pscl > 30)
+		return -EINVAL;
+
+	val = readl(p->base + SPI_IF_CONFIG) & ~(IF_CLK_PRESCALE_MASK);
+	val |= IF_CLK_PRESCALE_POW2 | IF_CLK_PRESCALE(pscl/2);
+	writel(val, p->base + SPI_IF_CONFIG);
+
+	return 0;
+}
+
+#if defined(ARCH_ARMADA_370) || defined(ARCH_ARMADA_XP) 
+static int armada_370_xp_spi_set_baudrate(struct mvebu_spi *p, u32 speed)
+{
+	u32 pscl, pdiv, rate, val;
+
+	/* prescaler values: 1,2,3,...,15 */
+	pscl = DIV_ROUND_UP(clk_get_rate(p->clk), speed);
+
+	/* additional prescaler divider: 1, 2, 4, 8, 16, 32, 64, 128 */
+	pdiv = 0; rate = pscl;
+	while (rate > 15 && pdiv <= 7) {
+		rate /= 2;
+		pdiv++;
+	}
+
+	debug("%s: clk = %lu, speed = %u, pscl = %d, pdiv = %d\n",
+		__func__, clk_get_rate(p->clk), speed, pscl, pdiv);
+
+	if (rate > 15 || pdiv > 7)
+		return -EINVAL;
+
+	val = readl(p->base + SPI_IF_CONFIG) & ~(IF_CLK_PRESCALE_MASK);
+	val |= IF_CLK_PRE_PRESCALE(pdiv) | IF_CLK_PRESCALE(pscl);
+	writel(val, p->base + SPI_IF_CONFIG);
+
+	return 0;
+}
+#endif
+
+#if defined(ARCH_DOVE)
+static int dove_spi_set_baudrate(struct mvebu_spi *p, u32 speed)
+{
+	u32 pscl, sdiv, rate, val;
+
+	/* prescaler values: 1,2,3,...,15 and 1,2,4,6,...,30 */
+	pscl = DIV_ROUND_UP(clk_get_rate(p->clk), speed);
+	if (pscl > 15)
+		pscl = roundup(pscl, 2);
+
+	/* additional sclk divider: 1, 2, 4, 8, 16 */
+	sdiv = 0; rate = pscl;
+	while (rate > 30 && sdiv <= 4) {
+		rate /= 2;
+		sdiv++;
+	}
+
+	debug("%s: clk = %lu, speed = %u, pscl = %d, sdiv = %d\n",
+		__func__, clk_get_rate(p->clk), speed, pscl, sdiv);
+
+	if (rate > 30 || sdiv > 4)
+		return -EINVAL;
+
+	val = readl(p->base + SPI_IF_CONFIG) &
+		~(IF_CLK_DIV_MASK | IF_CLK_PRESCALE_MASK);
+
+	val |= IF_CLK_DIV(sdiv);
+	if (pscl > 15)
+		val |= IF_CLK_PRESCALE_POW2 | IF_CLK_PRESCALE(pscl/2);
+	else
+		val |= IF_CLK_PRESCALE(pscl);
+	writel(val, p->base + SPI_IF_CONFIG);
+
+	return 0;
+}
+#endif
+
+static int mvebu_spi_set_mode(struct mvebu_spi *p, u8 mode)
+{
+	/*
+	 * From public datasheets of Orion SoCs, it is unclear
+	 * if the SPI controller supports setting CPOL/CPHA.
+	 * Dove has an SCK_INV but as with the other SoCs, it
+	 * is tagged with "Must be 1".
+	 *
+	 * For now, we just bail out if device requests any
+	 * other mode than SPI_MODE0.
+	 */
+
+	if ((mode & (SPI_CPOL|SPI_CPHA)) == SPI_MODE_0)
+		return 0;
+
+	pr_err("%s: unsupported SPI mode %02x\n", __func__, mode);
+
+	return -EINVAL;
+}
+
+static int mvebu_spi_setup(struct spi_device *spi)
+{
+	int ret;
+	struct mvebu_spi *priv = priv_from_spi_device(spi);
+
+	debug("%s: mode %02x, bits_per_word = %d, speed = %d\n",
+		__func__, spi->mode, spi->bits_per_word, spi->max_speed_hz);
+
+	ret = mvebu_spi_set_cs(priv, spi->chip_select, spi->mode, false);
+	if (ret)
+		return ret;
+	ret = mvebu_spi_set_mode(priv, spi->mode);
+	if (ret)
+		return ret;
+	ret = mvebu_spi_set_transfer_size(priv, spi->bits_per_word);
+	if (ret)
+		return ret;
+
+	return priv->set_baudrate(priv, spi->max_speed_hz);
+}
+
+static inline int mvebu_spi_wait_for_read_ready(struct mvebu_spi *p)
+{
+	int timeout = 100;
+	while ((readl(p->base + SPI_IF_CTRL) & IF_READ_READY) == 0 &&
+		timeout--)
+		udelay(1);
+	if (timeout < 0)
+		return -EIO;
+	return 0;
+}
+
+static int mvebu_spi_do_transfer(struct spi_device *spi,
+				 struct spi_transfer *t)
+{
+	const u8 *txdata = t->tx_buf;
+	u8 *rxdata = t->rx_buf;
+	int ret = 0, n, inc;
+	struct mvebu_spi *priv = priv_from_spi_device(spi);
+
+	if (t->bits_per_word)
+		ret = mvebu_spi_set_transfer_size(priv, spi->bits_per_word);
+	if (ret)
+		return ret;
+
+	if (t->speed_hz)
+		ret = priv->set_baudrate(priv, t->speed_hz);
+	if (ret)
+		return ret;
+
+	inc = (priv->data16) ? 2 : 1;
+	for (n = 0; n < t->len; n += inc) {
+		u32 data = 0;
+
+		if (txdata)
+			data = *txdata++;
+		if (txdata && priv->data16)
+			data |= (*txdata++ << 8);
+
+		writel(data, priv->base + SPI_DATA_OUT);
+
+		ret = mvebu_spi_wait_for_read_ready(priv);
+		if (ret) {
+			dev_err(&spi->dev, "timeout reading from device %s\n",
+				dev_name(&spi->dev));
+			return ret;
+		}
+
+		data = readl(priv->base + SPI_DATA_IN);
+
+		if (rxdata)
+			*rxdata++ = (data & 0xff);
+		if (rxdata && priv->data16)
+			*rxdata++ = (data >> 8) & 0xff;
+	}
+
+	return 0;
+}
+
+static int mvebu_spi_transfer(struct spi_device *spi, struct spi_message *msg)
+{
+	struct spi_transfer *t;
+	int ret;
+	struct mvebu_spi *priv = priv_from_spi_device(spi);
+
+	ret = mvebu_spi_set_cs(priv, spi->chip_select, spi->mode, true);
+	if (ret)
+		return ret;
+
+	msg->actual_length = 0;
+
+	list_for_each_entry(t, &msg->transfers, transfer_list) {
+		ret = mvebu_spi_do_transfer(spi, t);
+		if (ret)
+			break;
+		msg->actual_length += t->len;
+	}
+
+	ret = mvebu_spi_set_cs(priv, spi->chip_select, spi->mode, false);
+	if (ret)
+		return ret;
+
+	return ret;
+}
+
+static struct of_device_id mvebu_spi_dt_ids[] = {
+	{ .compatible = "marvell,orion-spi",
+	  .data = (unsigned long)&mvebu_spi_set_baudrate },
+#if defined(ARCH_ARMADA_370) || defined(ARCH_ARMADA_XP) 
+	{ .compatible = "marvell,armada-370-xp-spi",
+	  .data = (unsigned long)&armada_370_xp_spi_set_baudrate },
+#endif
+#if defined(ARCH_DOVE)
+	{ .compatible = "marvell,dove-spi",
+	  .data = (unsigned long)&dove_spi_set_baudrate },
+#endif
+	{ }
+};
+
+static int mvebu_spi_probe(struct device_d *dev)
+{
+	struct spi_master *master;
+	struct mvebu_spi *priv;
+	const struct of_device_id *match;
+	int ret = 0;
+
+	match = of_match_node(mvebu_spi_dt_ids, dev->device_node);
+	if (!match)
+		return -EINVAL;
+
+	priv = xzalloc(sizeof(*priv));
+	priv->base = dev_request_mem_region(dev, 0);
+	priv->set_baudrate = (void *)match->data;
+	priv->clk = clk_lookup("tclk");
+	if (IS_ERR(priv->clk)) {
+		ret = PTR_ERR(priv->clk);
+		goto err_free;
+	}
+
+	master = &priv->master;
+	master->dev = dev;
+	master->bus_num = dev->id;
+	master->setup = mvebu_spi_setup;
+	master->transfer = mvebu_spi_transfer;
+	master->num_chipselect = 1;
+
+	if (dev->device_node)
+		spi_of_register_slaves(master, dev->device_node);
+
+	ret = spi_register_master(master);
+	if (!ret)
+		return 0;
+
+err_free:
+	free(priv);
+
+	return ret;
+}
+
+static struct driver_d mvebu_spi_driver = {
+	.name  = "mvebu-spi",
+	.probe = mvebu_spi_probe,
+	.of_compatible = DRV_OF_COMPAT(mvebu_spi_dt_ids),
+};
+device_platform_driver(mvebu_spi_driver);
-- 
1.7.2.5



From sebastian.hesselbarth at gmail.com  Fri Jun 28 14:25:47 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Fri, 28 Jun 2013 20:25:47 +0200
Subject: [PATCH 6/6] ARM: mvebu: import DT files for Dove SoC and SolidRun
 CuBox
In-Reply-To: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <1372443947-12599-7-git-send-email-sebastian.hesselbarth@gmail.com>

This imports dove.dtsi and dove-cubox.dts from Linux kernel with timer
node added.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Cc: barebox at lists.infradead.org
---
 arch/arm/dts/dove-cubox.dts |  154 +++++++++++++++++++++++
 arch/arm/dts/dove.dtsi      |  285 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 439 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/dts/dove-cubox.dts
 create mode 100644 arch/arm/dts/dove.dtsi

diff --git a/arch/arm/dts/dove-cubox.dts b/arch/arm/dts/dove-cubox.dts
new file mode 100644
index 0000000..b7dc243
--- /dev/null
+++ b/arch/arm/dts/dove-cubox.dts
@@ -0,0 +1,154 @@
+/dts-v1/;
+
+/include/ "dove.dtsi"
+
+/ {
+	compatible = "solidrun,cubox", "marvell,dove";
+	model = "SolidRun CuBox";
+
+	memory {
+		device_type = "memory";
+		reg = <0x00000000 0x3f000000>;
+	};
+
+	chosen {
+		bootargs = "console=ttyS0,115200n8 earlyprintk";
+	};
+
+	leds {
+		compatible = "gpio-leds";
+		pinctrl-0 = <&pmx_gpio_18>;
+		pinctrl-names = "default";
+
+		power {
+			label = "Power";
+			gpios = <&gpio0 18 1>;
+			linux,default-trigger = "default-on";
+		};
+	};
+
+	regulators {
+		compatible = "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		usb_power: regulator at 1 {
+			compatible = "regulator-fixed";
+			reg = <1>;
+			regulator-name = "USB Power";
+			regulator-min-microvolt = <5000000>;
+			regulator-max-microvolt = <5000000>;
+			enable-active-high;
+			regulator-always-on;
+			regulator-boot-on;
+			gpio = <&gpio0 1 0>;
+		};
+	};
+
+	clocks {
+		/* 25MHz reference crystal */
+		ref25: oscillator {
+			compatible = "fixed-clock";
+			#clock-cells = <0>;
+			clock-frequency = <25000000>;
+		};
+	};
+
+	video-card {
+		compatible = "marvell,dove-video-card";
+		reg = <0x3f000000 0x1000000>;
+		marvell,external-encoder = <&tda19988>;
+	};
+};
+
+&uart0 { status = "okay"; };
+&sata0 { status = "okay"; };
+
+&lcd0 {
+	status = "okay";
+	clocks = <&si5351 0>;
+};
+
+&i2c0 {
+	status = "okay";
+	clock-frequency = <400000>;
+
+	si5351: clock-generator {
+		compatible = "silabs,si5351a-msop";
+		reg = <0x60>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		#clock-cells = <1>;
+
+		/* connect xtal input to 25MHz reference */
+		clocks = <&ref25>;
+
+		/* connect xtal input as source of pll0 and pll1 */
+		silabs,pll-source = <0 0>, <1 0>;
+
+		clkout0 {
+			reg = <0>;
+			silabs,drive-strength = <8>;
+			silabs,multisynth-source = <0>;
+			silabs,clock-source = <0>;
+			silabs,pll-master;
+		};
+
+		clkout1 {
+			reg = <1>;
+			silabs,drive-strength = <8>;
+			silabs,multisynth-source = <1>;
+			silabs,clock-source = <0>;
+			silabs,pll-master;
+		};
+
+		clkout2 {
+			reg = <2>;
+			silabs,multisynth-source = <1>;
+			silabs,clock-source = <0>;
+		};
+	};
+
+	tda19988: hdmi-encoder at 70 {
+		compatible = "nxp,tda1998x";
+		reg = <0x70>;
+	};
+};
+
+&sdio0 {
+	status = "okay";
+        bus-width = <4>;
+	/* sdio0 card detect is connected to wrong pin on CuBox */
+	cd-gpios = <&gpio0 12 1>;
+};
+
+&spi0 {
+	status = "okay";
+
+	/* spi0.0: 4M Flash Winbond W25Q32BV */
+	spi-flash at 0 {
+		compatible = "winbond,w25q32", "m25p80";
+		spi-max-frequency = <20000000>;
+		reg = <0>;
+	};
+};
+
+&pinctrl {
+	pinctrl-0 = <&pmx_gpio_1 &pmx_gpio_12>;
+	pinctrl-names = "default";
+
+	pmx_gpio_1: pmx-gpio-1 {
+		marvell,pins = "mpp1";
+		marvell,function = "gpio";
+	};
+
+	pmx_gpio_12: pmx-gpio-12 {
+		marvell,pins = "mpp12";
+		marvell,function = "gpio";
+	};
+
+	pmx_gpio_18: pmx-gpio-18 {
+		marvell,pins = "mpp18";
+		marvell,function = "gpio";
+	};
+};
diff --git a/arch/arm/dts/dove.dtsi b/arch/arm/dts/dove.dtsi
new file mode 100644
index 0000000..98b7e29
--- /dev/null
+++ b/arch/arm/dts/dove.dtsi
@@ -0,0 +1,285 @@
+/include/ "skeleton.dtsi"
+
+/ {
+	compatible = "marvell,dove";
+	model = "Marvell Armada 88AP510 SoC";
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	aliases {
+		gpio0 = &gpio0;
+		gpio1 = &gpio1;
+		gpio2 = &gpio2;
+	};
+
+	soc at f1000000 {
+		compatible = "simple-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		interrupt-parent = <&intc>;
+
+		ranges = <0xc8000000 0xc8000000 0x0100000   /* CESA SRAM   1M */
+		          0xe0000000 0xe0000000 0x8000000   /* PCIe0 Mem 128M */
+		          0xe8000000 0xe8000000 0x8000000   /* PCIe1 Mem 128M */
+		          0xf0000000 0xf0000000 0x0100000   /* ScratchPad  1M */
+		          0x00000000 0xf1000000 0x1000000   /* SB/NB regs 16M */
+		          0xf2000000 0xf2000000 0x0100000   /* PCIe0 I/O   1M */
+		          0xf2100000 0xf2100000 0x0100000   /* PCIe0 I/O   1M */
+		          0xf8000000 0xf8000000 0x8000000>; /* BootROM   128M */
+
+		l2: l2-cache {
+			compatible = "marvell,tauros2-cache";
+			marvell,tauros2-cache-features = <0>;
+		};
+
+		timer: timer at 20300 {
+			compatible = "marvell,orion-timer";
+                        reg = <0x20300 0x30>;
+		};
+
+		intc: interrupt-controller at 20204 {
+			compatible = "marvell,orion-intc";
+			interrupt-controller;
+			#interrupt-cells = <1>;
+			reg = <0x20204 0x04>, <0x20214 0x04>;
+		};
+
+		core_clk: core-clocks at d0214 {
+			compatible = "marvell,dove-core-clock";
+			reg = <0xd0214 0x4>;
+			#clock-cells = <1>;
+		};
+
+		gate_clk: clock-gating-control at d0038 {
+			compatible = "marvell,dove-gating-clock";
+			reg = <0xd0038 0x4>;
+			clocks = <&core_clk 0>;
+			#clock-cells = <1>;
+		};
+
+		thermal: thermal at d001c {
+			compatible = "marvell,dove-thermal";
+			reg = <0xd001c 0x0c>, <0xd005c 0x08>;
+		};
+
+		uart0: serial at 12000 {
+			compatible = "ns16550a";
+			reg = <0x12000 0x100>;
+			reg-shift = <2>;
+			interrupts = <7>;
+			clocks = <&core_clk 0>;
+			status = "disabled";
+		};
+
+		uart1: serial at 12100 {
+			compatible = "ns16550a";
+			reg = <0x12100 0x100>;
+			reg-shift = <2>;
+			interrupts = <8>;
+			clocks = <&core_clk 0>;
+			status = "disabled";
+		};
+
+		uart2: serial at 12200 {
+			compatible = "ns16550a";
+			reg = <0x12000 0x100>;
+			reg-shift = <2>;
+			interrupts = <9>;
+			clocks = <&core_clk 0>;
+			status = "disabled";
+		};
+
+		uart3: serial at 12300 {
+			compatible = "ns16550a";
+			reg = <0x12100 0x100>;
+			reg-shift = <2>;
+			interrupts = <10>;
+			clocks = <&core_clk 0>;
+			status = "disabled";
+		};
+
+		gpio0: gpio at d0400 {
+			compatible = "marvell,orion-gpio";
+			#gpio-cells = <2>;
+			gpio-controller;
+			reg = <0xd0400 0x20>;
+			ngpios = <32>;
+			interrupt-controller;
+			#interrupt-cells = <2>;
+			interrupts = <12>, <13>, <14>, <60>;
+		};
+
+		gpio1: gpio at d0420 {
+			compatible = "marvell,orion-gpio";
+			#gpio-cells = <2>;
+			gpio-controller;
+			reg = <0xd0420 0x20>;
+			ngpios = <32>;
+			interrupt-controller;
+			#interrupt-cells = <2>;
+			interrupts = <61>;
+		};
+
+		gpio2: gpio at e8400 {
+			compatible = "marvell,orion-gpio";
+			#gpio-cells = <2>;
+			gpio-controller;
+			reg = <0xe8400 0x0c>;
+			ngpios = <8>;
+		};
+
+		pinctrl: pinctrl at d0200 {
+			compatible = "marvell,dove-pinctrl";
+			reg = <0xd0200 0x10>;
+			clocks = <&gate_clk 22>;
+		};
+
+		spi0: spi at 10600 {
+			compatible = "marvell,orion-spi";
+			#address-cells = <1>;
+			#size-cells = <0>;
+			cell-index = <0>;
+			interrupts = <6>;
+			reg = <0x10600 0x28>;
+			clocks = <&core_clk 0>;
+			status = "disabled";
+		};
+
+		spi1: spi at 14600 {
+			compatible = "marvell,dove-spi";
+			#address-cells = <1>;
+			#size-cells = <0>;
+			cell-index = <1>;
+			interrupts = <5>;
+			reg = <0x14600 0x28>;
+			clocks = <&core_clk 0>;
+			status = "disabled";
+		};
+
+		i2c0: i2c at 11000 {
+			compatible = "marvell,mv64xxx-i2c";
+			reg = <0x11000 0x20>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			interrupts = <11>;
+			clock-frequency = <400000>;
+			timeout-ms = <1000>;
+			clocks = <&core_clk 0>;
+			status = "disabled";
+		};
+
+		ehci0: usb-host at 50000 {
+			compatible = "marvell,orion-ehci";
+			reg = <0x50000 0x1000>;
+			interrupts = <24>;
+			clocks = <&gate_clk 0>;
+			status = "okay";
+		};
+
+		ehci1: usb-host at 51000 {
+			compatible = "marvell,orion-ehci";
+			reg = <0x51000 0x1000>;
+			interrupts = <25>;
+			clocks = <&gate_clk 1>;
+			status = "okay";
+		};
+
+		sdio0: sdio at 92000 {
+			compatible = "marvell,dove-sdhci";
+			reg = <0x92000 0x100>;
+			interrupts = <35>, <37>;
+			clocks = <&gate_clk 8>;
+			status = "disabled";
+		};
+
+		sdio1: sdio at 90000 {
+			compatible = "marvell,dove-sdhci";
+			reg = <0x90000 0x100>;
+			interrupts = <36>, <38>;
+			clocks = <&gate_clk 9>;
+			status = "disabled";
+		};
+
+		sata0: sata at a0000 {
+			compatible = "marvell,orion-sata";
+			reg = <0xa0000 0x2400>;
+			interrupts = <62>;
+			clocks = <&gate_clk 3>;
+			nr-ports = <1>;
+			status = "disabled";
+		};
+
+		rtc at d8500 {
+			compatible = "marvell,orion-rtc";
+			reg = <0xd8500 0x20>;
+		};
+
+		crypto: crypto at 30000 {
+			compatible = "marvell,orion-crypto";
+			reg = <0x30000 0x10000>,
+			      <0xc8000000 0x800>;
+			reg-names = "regs", "sram";
+			interrupts = <31>;
+			clocks = <&gate_clk 15>;
+			status = "okay";
+		};
+
+		xor0: dma-engine at 60800 {
+			compatible = "marvell,orion-xor";
+			reg = <0x60800 0x100
+			       0x60a00 0x100>;
+			clocks = <&gate_clk 23>;
+			status = "okay";
+
+			channel0 {
+				interrupts = <39>;
+				dmacap,memcpy;
+				dmacap,xor;
+			};
+
+			channel1 {
+				interrupts = <40>;
+				dmacap,memset;
+				dmacap,memcpy;
+				dmacap,xor;
+			};
+		};
+
+		xor1: dma-engine at 60900 {
+			compatible = "marvell,orion-xor";
+			reg = <0x60900 0x100
+			       0x60b00 0x100>;
+			clocks = <&gate_clk 24>;
+			status = "okay";
+
+			channel0 {
+				interrupts = <42>;
+				dmacap,memcpy;
+				dmacap,xor;
+			};
+
+			channel1 {
+				interrupts = <43>;
+				dmacap,memset;
+				dmacap,memcpy;
+				dmacap,xor;
+			};
+		};
+		
+		lcd0: lcd-controller at 820000 {
+			compatible = "marvell,dove-lcd";
+			reg = <0x820000 0x200>;
+			interrupts = <47>;
+			clocks = <0>;
+			status = "disabled";
+		};
+		
+		lcd1: lcd-controller at 810000 {
+			compatible = "marvell,dove-lcd";
+			reg = <0x810000 0x200>;
+			interrupts = <46>;
+			clocks = <0>;
+			status = "disabled";
+		};
+	};
+};
-- 
1.7.2.5



From dev at lynxeye.de  Fri Jun 28 18:09:50 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Sat, 29 Jun 2013 00:09:50 +0200
Subject: [PATCH] Split Multimage Makefile rule in explicit and implicit parts
Message-ID: <1372457390-20162-1-git-send-email-dev@lynxeye.de>

Fixes build with make version >=3.82

Frome the make 3.82 NEWS file:
* WARNING: Backward-incompatibility!
  In previous versions of make it was acceptable to list one or more explicit
  targets followed by one or more pattern targets in the same rule and it
  worked "as expected".  However, this was not documented as acceptable and if
  you listed any explicit targets AFTER the pattern targets, the entire rule
  would be mis-parsed.  This release removes this ability completely: make
  will generate an error message if you mix explicit and pattern targets in
  the same rule.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
Feel free to squash this into the offending commit.
---
 Makefile | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index d82e795..811b658 100644
--- a/Makefile
+++ b/Makefile
@@ -481,7 +481,9 @@ export KBUILD_BINARY ?= barebox.bin
 barebox-flash-image: $(KBUILD_IMAGE) FORCE
 	$(call if_changed,ln)
 
-images images/%.s: barebox.bin FORCE
+images: barebox.bin FORCE
+	$(Q)$(MAKE) $(build)=images $@
+images/%.s: barebox.bin FORCE
 	$(Q)$(MAKE) $(build)=images $@
 
 ifdef CONFIG_PBL_MULTI_IMAGES
-- 
1.8.3.1



From s.hauer at pengutronix.de  Sat Jun 29 04:43:25 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 29 Jun 2013 10:43:25 +0200
Subject: [PATCH] clocksource: fix Marvell timer read-back value
In-Reply-To: <1372354760-31955-1-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372354760-31955-1-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130629084325.GM516@pengutronix.de>

On Thu, Jun 27, 2013 at 07:39:20PM +0200, Sebastian Hesselbarth wrote:
> Clocksource read callback expects incrementing timer values, while
> internal timer on Marvell SoCs counts backwards. Fix value returned
> by Marvell MVEBU and Orion clocksource drivers.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sat Jun 29 04:49:53 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 29 Jun 2013 10:49:53 +0200
Subject: [PATCH 2/6] clocksource: orion: add DT support
In-Reply-To: <1372443947-12599-3-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372443947-12599-3-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130629084953.GN516@pengutronix.de>

On Fri, Jun 28, 2013 at 08:25:43PM +0200, Sebastian Hesselbarth wrote:
> This adds device tree support to orion timer and also converts clk_get
> to clk_lookup to find TCLK without device name reference.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
> Cc: barebox at lists.infradead.org
> ---
>  drivers/clocksource/orion.c |    8 +++++++-
>  1 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/clocksource/orion.c b/drivers/clocksource/orion.c
> index e3db845..ed71fa4 100644
> --- a/drivers/clocksource/orion.c
> +++ b/drivers/clocksource/orion.c
> @@ -49,7 +49,7 @@ static int orion_timer_probe(struct device_d *dev)
>  	uint32_t val;
>  
>  	timer_base = dev_request_mem_region(dev, 0);
> -	tclk = clk_get(dev, "tclk");
> +	tclk = clk_lookup("tclk");

Please don't do this. I don't know how it is done in the kernel
for orion atm, but you could for example help yourself with
clkdev_add_physbase until the clocks can be properly looked up from
the devicetree.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sat Jun 29 05:00:59 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 29 Jun 2013 11:00:59 +0200
Subject: [PATCH 4/6] spi: add Marvell MVEBU SoC SPI driver
In-Reply-To: <1372443947-12599-5-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372443947-12599-5-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130629090059.GO516@pengutronix.de>

On Fri, Jun 28, 2013 at 08:25:45PM +0200, Sebastian Hesselbarth wrote:
> This adds support for the SPI controller found on Marvell MVEBU SoCs
> (Dove, Kirkwood, Discovery Innovation, and Armada 370/XP). Current driver
> is DT only. Compatible strings are provided for Orion (common denominator),
> Armada 370/XP and Dove SoCs.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>

Mostly good, some minor stuff inline.

> +static int mvebu_spi_set_transfer_size(struct mvebu_spi *p, int size)
> +{
> +	u32 val;
> +
> +	if (size != 8 && size != 16)
> +		return -EINVAL;
> +
> +	p->data16 = (size == 16);
> +
> +	val = readl(p->base + SPI_IF_CONFIG) & ~IF_TRANSFER_2BYTE;
> +	if (p->data16)
> +		val |= IF_TRANSFER_2BYTE;
> +	writel(val, p->base + SPI_IF_CONFIG);
> +	

Trailing whitespaces here and elsewhere.

> +	return 0;
> +}
> +
> +static int mvebu_spi_set_baudrate(struct mvebu_spi *p, u32 speed)
> +{
> +	u32 pscl, val;
> +
> +	/* standard prescaler values: 1,2,4,6,...,30 */
> +	pscl = DIV_ROUND_UP(clk_get_rate(p->clk), speed);
> +	pscl = roundup(pscl, 2);
> +
> +	debug("%s: clk = %lu, speed = %u, pscl = %d\n",
> +		__func__, clk_get_rate(p->clk), speed, pscl);

Please use dev_dbg and friends in drivers.

> +	int ret = 0;
> +
> +	match = of_match_node(mvebu_spi_dt_ids, dev->device_node);
> +	if (!match)
> +		return -EINVAL;
> +
> +	priv = xzalloc(sizeof(*priv));
> +	priv->base = dev_request_mem_region(dev, 0);

Please check priv->base for validity. I know, most other drivers also
don't do it, but at least new drivers should.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sat Jun 29 05:17:41 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 29 Jun 2013 11:17:41 +0200
Subject: [PATCH 6/6] ARM: mvebu: import DT files for Dove SoC and
 SolidRun CuBox
In-Reply-To: <1372443947-12599-7-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372443947-12599-7-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130629091741.GP516@pengutronix.de>

On Fri, Jun 28, 2013 at 08:25:47PM +0200, Sebastian Hesselbarth wrote:
> This imports dove.dtsi and dove-cubox.dts from Linux kernel with timer
> node added.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
> Cc: barebox at lists.infradead.org
> ---
>  arch/arm/dts/dove-cubox.dts |  154 +++++++++++++++++++++++
>  arch/arm/dts/dove.dtsi      |  285 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 439 insertions(+), 0 deletions(-)
>  create mode 100644 arch/arm/dts/dove-cubox.dts
>  create mode 100644 arch/arm/dts/dove.dtsi
> 
> diff --git a/arch/arm/dts/dove-cubox.dts b/arch/arm/dts/dove-cubox.dts
> new file mode 100644
> index 0000000..b7dc243
> --- /dev/null
> +++ b/arch/arm/dts/dove-cubox.dts
> @@ -0,0 +1,154 @@
> +/dts-v1/;
> +
> +/include/ "dove.dtsi"
> +
> +/ {
> +	compatible = "solidrun,cubox", "marvell,dove";
> +	model = "SolidRun CuBox";
> +
> +	memory {
> +		device_type = "memory";
> +		reg = <0x00000000 0x3f000000>;
> +	};
> +
> +	chosen {
> +		bootargs = "console=ttyS0,115200n8 earlyprintk";
> +	};

I would add a linux,stdoutpath property here. Then you can switch to
CONFIG_CONSOLE_ACTIVATE_NONE in the defconfig and enable multiple uarts
in the dts without risking that the first one to be activated is not the
console port.

> +
> +&sdio0 {
> +	status = "okay";
> +        bus-width = <4>;

Use tab here.

> +		};
> +		
> +		lcd0: lcd-controller at 820000 {
> +			compatible = "marvell,dove-lcd";
> +			reg = <0x820000 0x200>;
> +			interrupts = <47>;
> +			clocks = <0>;
> +			status = "disabled";
> +		};
> +		

Trailing whitespaces.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sat Jun 29 10:22:40 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 29 Jun 2013 16:22:40 +0200
Subject: [PATCH 5/9] OF: base: use of_platform_populate for probing
In-Reply-To: <1372152047-28134-6-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-6-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130629142240.GB10414@pengutronix.de>

On Tue, Jun 25, 2013 at 11:20:43AM +0200, Sebastian Hesselbarth wrote:
> With recent bus/device related functions in OF API, we can now
> convert to use of_platform_populate.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: barebox at lists.infradead.org
> ---
>  drivers/of/base.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 429f924..eb9ac84 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1840,7 +1840,7 @@ const struct of_device_id of_default_bus_match_table[] = {
>  
>  int of_probe(void)
>  {
> -	struct device_node *memory, *n;
> +	struct device_node *memory;
>  
>  	if(!root_node)
>  		return -ENODEV;
> @@ -1854,8 +1854,7 @@ int of_probe(void)
>  	if (memory)
>  		of_add_memory(memory, false);
>  
> -	list_for_each_entry(n, &root_node->children, parent_list)
> -		__of_probe(n, of_default_bus_match_table, NULL);
> +	of_platform_populate(root_node, of_default_bus_match_table, NULL);

This patch breaks the SPI chip select gpios on my efikasb. Problem is
that of_get_named_gpio depends on the device pointer in struct
device_node which of_platform_populate doesn't set. A quick test adding
the pointer in of_platform_device_create fixed this.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sat Jun 29 10:28:57 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 29 Jun 2013 16:28:57 +0200
Subject: [PATCH 7/9] OF: remove device and resource pointer from struct
 device_node
In-Reply-To: <1372152047-28134-8-git-send-email-sebastian.hesselbarth@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-8-git-send-email-sebastian.hesselbarth@gmail.com>
Message-ID: <20130629142857.GC10414@pengutronix.de>

On Tue, Jun 25, 2013 at 11:20:45AM +0200, Sebastian Hesselbarth wrote:
> diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
> index 41e91ec..7f6d99c 100644
> --- a/drivers/of/gpio.c
> +++ b/drivers/of/gpio.c
> @@ -10,6 +10,10 @@ int of_get_named_gpio(struct device_node *np,
>  {
>  	int ret;
>  	struct of_phandle_args out_args;
> +	struct device_d *dev = of_find_device_by_node(np);
> +
> +	if (!dev)
> +		return -EINVAL;
>  
>  	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
>  					index, &out_args);
> @@ -18,7 +22,7 @@ int of_get_named_gpio(struct device_node *np,
>  		return -EINVAL;
>  	}
>  
> -	ret = gpio_get_num(out_args.np->device, out_args.args[0]);
> +	ret = gpio_get_num(dev, out_args.args[0]);

This doesn't work. What gpio_get_num needs is the device pointer from
the gpio device, not from the device from the node we pass to this
function. You would have to use of_find_device_by_node(out_args.np) here
I guess.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From s.hauer at pengutronix.de  Sat Jun 29 10:31:46 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 29 Jun 2013 16:31:46 +0200
Subject: [PATCH 7/9] OF: remove device and resource pointer from struct
 device_node
In-Reply-To: <20130629142857.GC10414@pengutronix.de>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-8-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130629142857.GC10414@pengutronix.de>
Message-ID: <20130629143146.GD10414@pengutronix.de>

On Sat, Jun 29, 2013 at 04:28:57PM +0200, Sascha Hauer wrote:
> On Tue, Jun 25, 2013 at 11:20:45AM +0200, Sebastian Hesselbarth wrote:
> > diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
> > index 41e91ec..7f6d99c 100644
> > --- a/drivers/of/gpio.c
> > +++ b/drivers/of/gpio.c
> > @@ -10,6 +10,10 @@ int of_get_named_gpio(struct device_node *np,
> >  {
> >  	int ret;
> >  	struct of_phandle_args out_args;
> > +	struct device_d *dev = of_find_device_by_node(np);
> > +
> > +	if (!dev)
> > +		return -EINVAL;
> >  
> >  	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
> >  					index, &out_args);
> > @@ -18,7 +22,7 @@ int of_get_named_gpio(struct device_node *np,
> >  		return -EINVAL;
> >  	}
> >  
> > -	ret = gpio_get_num(out_args.np->device, out_args.args[0]);
> > +	ret = gpio_get_num(dev, out_args.args[0]);
> 
> This doesn't work. What gpio_get_num needs is the device pointer from
> the gpio device, not from the device from the node we pass to this
> function. You would have to use of_find_device_by_node(out_args.np) here
> I guess.

Apart from this of_find_device_by_node() only works on platform_devices,
so this will break calling of_get_named_gpio on i2c gpio expanders.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From sebastian.hesselbarth at gmail.com  Sat Jun 29 12:00:01 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Sat, 29 Jun 2013 18:00:01 +0200
Subject: [PATCH 2/6] clocksource: orion: add DT support
In-Reply-To: <20130629084953.GN516@pengutronix.de>
References: <1372443947-12599-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372443947-12599-3-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130629084953.GN516@pengutronix.de>
Message-ID: <51CF0481.8010907@gmail.com>

On 06/29/2013 10:49 AM, Sascha Hauer wrote:
> On Fri, Jun 28, 2013 at 08:25:43PM +0200, Sebastian Hesselbarth wrote:
>> This adds device tree support to orion timer and also converts clk_get
>> to clk_lookup to find TCLK without device name reference.
>>
>> Signed-off-by: Sebastian Hesselbarth<sebastian.hesselbarth at gmail.com>
>> ---
>> Cc: Thomas Petazzoni<thomas.petazzoni at free-electrons.com>
>> Cc: barebox at lists.infradead.org
>> ---
>>   drivers/clocksource/orion.c |    8 +++++++-
>>   1 files changed, 7 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/clocksource/orion.c b/drivers/clocksource/orion.c
>> index e3db845..ed71fa4 100644
>> --- a/drivers/clocksource/orion.c
>> +++ b/drivers/clocksource/orion.c
>> @@ -49,7 +49,7 @@ static int orion_timer_probe(struct device_d *dev)
>>   	uint32_t val;
>>
>>   	timer_base = dev_request_mem_region(dev, 0);
>> -	tclk = clk_get(dev, "tclk");
>> +	tclk = clk_lookup("tclk");
>
> Please don't do this. I don't know how it is done in the kernel
> for orion atm, but you could for example help yourself with
> clkdev_add_physbase until the clocks can be properly looked up from
> the devicetree.

Ok, clock provider for MVEBU barebox is still missing. But in the
meantime, I will use clkdev_add_physbase or any equivalent workaround
until full clock provider will be available.

Sebastian



From sebastian.hesselbarth at gmail.com  Sat Jun 29 12:03:44 2013
From: sebastian.hesselbarth at gmail.com (Sebastian Hesselbarth)
Date: Sat, 29 Jun 2013 18:03:44 +0200
Subject: [PATCH 7/9] OF: remove device and resource pointer from struct
 device_node
In-Reply-To: <20130629143146.GD10414@pengutronix.de>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-8-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130629142857.GC10414@pengutronix.de>
 <20130629143146.GD10414@pengutronix.de>
Message-ID: <51CF0560.2050902@gmail.com>

On 06/29/2013 04:31 PM, Sascha Hauer wrote:
> On Sat, Jun 29, 2013 at 04:28:57PM +0200, Sascha Hauer wrote:
>> On Tue, Jun 25, 2013 at 11:20:45AM +0200, Sebastian Hesselbarth wrote:
>>> diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
>>> index 41e91ec..7f6d99c 100644
>>> --- a/drivers/of/gpio.c
>>> +++ b/drivers/of/gpio.c
>>> @@ -10,6 +10,10 @@ int of_get_named_gpio(struct device_node *np,
>>>   {
>>>   	int ret;
>>>   	struct of_phandle_args out_args;
>>> +	struct device_d *dev = of_find_device_by_node(np);
>>> +
>>> +	if (!dev)
>>> +		return -EINVAL;
>>>
>>>   	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
>>>   					index,&out_args);
>>> @@ -18,7 +22,7 @@ int of_get_named_gpio(struct device_node *np,
>>>   		return -EINVAL;
>>>   	}
>>>
>>> -	ret = gpio_get_num(out_args.np->device, out_args.args[0]);
>>> +	ret = gpio_get_num(dev, out_args.args[0]);
>>
>> This doesn't work. What gpio_get_num needs is the device pointer from
>> the gpio device, not from the device from the node we pass to this
>> function. You would have to use of_find_device_by_node(out_args.np) here
>> I guess.
>
> Apart from this of_find_device_by_node() only works on platform_devices,
> so this will break calling of_get_named_gpio on i2c gpio expanders.

Ok, to work on this I would have to have something to test with. MVEBU
DT is still at a very early stage. So for now, I guess removing the
device pointer is a bit early? I will also have to have a close look
into i2c core what makes those devices special here.

Sebastian



From s.hauer at pengutronix.de  Sat Jun 29 12:09:57 2013
From: s.hauer at pengutronix.de (Sascha Hauer)
Date: Sat, 29 Jun 2013 18:09:57 +0200
Subject: [PATCH 7/9] OF: remove device and resource pointer from struct
 device_node
In-Reply-To: <51CF0560.2050902@gmail.com>
References: <1372152047-28134-1-git-send-email-sebastian.hesselbarth@gmail.com>
 <1372152047-28134-8-git-send-email-sebastian.hesselbarth@gmail.com>
 <20130629142857.GC10414@pengutronix.de>
 <20130629143146.GD10414@pengutronix.de>
 <51CF0560.2050902@gmail.com>
Message-ID: <20130629160957.GR516@pengutronix.de>

On Sat, Jun 29, 2013 at 06:03:44PM +0200, Sebastian Hesselbarth wrote:
> On 06/29/2013 04:31 PM, Sascha Hauer wrote:
> >On Sat, Jun 29, 2013 at 04:28:57PM +0200, Sascha Hauer wrote:
> >>On Tue, Jun 25, 2013 at 11:20:45AM +0200, Sebastian Hesselbarth wrote:
> >>>diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
> >>>index 41e91ec..7f6d99c 100644
> >>>--- a/drivers/of/gpio.c
> >>>+++ b/drivers/of/gpio.c
> >>>@@ -10,6 +10,10 @@ int of_get_named_gpio(struct device_node *np,
> >>>  {
> >>>  	int ret;
> >>>  	struct of_phandle_args out_args;
> >>>+	struct device_d *dev = of_find_device_by_node(np);
> >>>+
> >>>+	if (!dev)
> >>>+		return -EINVAL;
> >>>
> >>>  	ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
> >>>  					index,&out_args);
> >>>@@ -18,7 +22,7 @@ int of_get_named_gpio(struct device_node *np,
> >>>  		return -EINVAL;
> >>>  	}
> >>>
> >>>-	ret = gpio_get_num(out_args.np->device, out_args.args[0]);
> >>>+	ret = gpio_get_num(dev, out_args.args[0]);
> >>
> >>This doesn't work. What gpio_get_num needs is the device pointer from
> >>the gpio device, not from the device from the node we pass to this
> >>function. You would have to use of_find_device_by_node(out_args.np) here
> >>I guess.
> >
> >Apart from this of_find_device_by_node() only works on platform_devices,
> >so this will break calling of_get_named_gpio on i2c gpio expanders.
> 
> Ok, to work on this I would have to have something to test with. MVEBU
> DT is still at a very early stage. So for now, I guess removing the
> device pointer is a bit early?

Probably, yes. I think the solution would be to adjust gpio_get_num() so
that it takes a device_node as argument instead of a device.

> I will also have to have a close look
> into i2c core what makes those devices special here.

I may be wrong here. In the kernel of_find_device_by_node() works only
for platform_devices, but since you do for_each_device(), it should work
for i2c devices in barebox aswell.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


From dev at lynxeye.de  Sun Jun 30 17:08:44 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Sun, 30 Jun 2013 23:08:44 +0200
Subject: [PATCH v2 2/7] tegra: change clocksource driver to be more lowlevel
In-Reply-To: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
References: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
Message-ID: <1372626529-23443-2-git-send-email-dev@lynxeye.de>

In order to properly bring up the system PLLs we need a reliable
clocksource. To break the circular dependency between the clocksource
and the CAR driver, get the OSC frequency with a lowlevel function.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 arch/arm/mach-tegra/include/mach/lowlevel.h | 23 +++++++++++++++++++++++
 arch/arm/mach-tegra/tegra20-timer.c         | 16 +++-------------
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mach-tegra/include/mach/lowlevel.h b/arch/arm/mach-tegra/include/mach/lowlevel.h
index b7c01c0..071416f 100644
--- a/arch/arm/mach-tegra/include/mach/lowlevel.h
+++ b/arch/arm/mach-tegra/include/mach/lowlevel.h
@@ -142,5 +142,28 @@ static inline long tegra20_get_debuguart_base(void)
 	return uart_id_to_base[id];
 }
 
+#define CRC_OSC_CTRL			0x050
+#define CRC_OSC_CTRL_OSC_FREQ_SHIFT	30
+#define CRC_OSC_CTRL_OSC_FREQ_MASK	(0x3 << CRC_OSC_CTRL_OSC_FREQ_SHIFT)
+
+static inline unsigned int tegra_get_osc_clock(void)
+{
+	u32 osc_ctrl = readl(TEGRA_CLK_RESET_BASE + CRC_OSC_CTRL);
+
+	switch ((osc_ctrl & CRC_OSC_CTRL_OSC_FREQ_MASK) >>
+		CRC_OSC_CTRL_OSC_FREQ_SHIFT) {
+	case 0:
+		return 13000000;
+	case 1:
+		return 19200000;
+	case 2:
+		return 12000000;
+	case 3:
+		return 26000000;
+	default:
+		return 0;
+	}
+}
+
 /* reset vector for the main CPU complex */
 void tegra_maincomplex_entry(void);
diff --git a/arch/arm/mach-tegra/tegra20-timer.c b/arch/arm/mach-tegra/tegra20-timer.c
index aafbfd4..2b32647 100644
--- a/arch/arm/mach-tegra/tegra20-timer.c
+++ b/arch/arm/mach-tegra/tegra20-timer.c
@@ -24,6 +24,7 @@
 #include <init.h>
 #include <io.h>
 #include <linux/clk.h>
+#include <mach/lowlevel.h>
 
 /* register definitions */
 #define TIMERUS_CNTR_1US	0x10
@@ -43,8 +44,6 @@ static struct clocksource cs = {
 
 static int tegra20_timer_probe(struct device_d *dev)
 {
-	struct clk *timer_clk;
-	unsigned long rate;
 	u32 reg;
 
 	/* use only one timer */
@@ -57,22 +56,13 @@ static int tegra20_timer_probe(struct device_d *dev)
 		return -ENODEV;
 	}
 
-	timer_clk = clk_get(dev, NULL);
-	if (!timer_clk) {
-		dev_err(dev, "could not get clock\n");
-		return -ENODEV;
-	}
-
-	clk_enable(timer_clk);
-
 	/*
 	 * calibrate timer to run at 1MHz
 	 * TIMERUS_USEC_CFG selects the scale down factor with bits [0:7]
 	 * representing the divisor and bits [8:15] representing the dividend
 	 * each in n+1 form.
 	 */
-	rate = clk_get_rate(timer_clk);
-	switch (rate) {
+	switch (tegra_get_osc_clock()) {
 	case 12000000:
 		reg = 0x000b;
 		break;
@@ -116,4 +106,4 @@ static int tegra20_timer_init(void)
 {
 	return platform_driver_register(&tegra20_timer_driver);
 }
-coredevice_initcall(tegra20_timer_init);
+core_initcall(tegra20_timer_init);
-- 
1.8.3.1



From dev at lynxeye.de  Sun Jun 30 17:08:46 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Sun, 30 Jun 2013 23:08:46 +0200
Subject: [PATCH v2 4/7] clk: allow to instanciate clk mux without registering
 it
In-Reply-To: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
References: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
Message-ID: <1372626529-23443-4-git-send-email-dev@lynxeye.de>

Allows to reuse clk mux code within other clocks.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 drivers/clk/clk-mux.c | 29 ++++++++++++++++++++++++-----
 include/linux/clk.h   |  4 ++++
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/clk-mux.c b/drivers/clk/clk-mux.c
index cb5f1a1..47efe12 100644
--- a/drivers/clk/clk-mux.c
+++ b/drivers/clk/clk-mux.c
@@ -27,6 +27,8 @@ struct clk_mux {
 	int width;
 };
 
+#define to_clk_mux(_clk) container_of(_clk, struct clk_mux, clk)
+
 static int clk_mux_get_parent(struct clk *clk)
 {
 	struct clk_mux *m = container_of(clk, struct clk_mux, clk);
@@ -53,11 +55,10 @@ struct clk_ops clk_mux_ops = {
 	.set_parent = clk_mux_set_parent,
 };
 
-struct clk *clk_mux(const char *name, void __iomem *reg,
+struct clk *clk_mux_alloc(const char *name, void __iomem *reg,
 		u8 shift, u8 width, const char **parents, u8 num_parents)
 {
 	struct clk_mux *m = xzalloc(sizeof(*m));
-	int ret;
 
 	m->reg = reg;
 	m->shift = shift;
@@ -67,11 +68,29 @@ struct clk *clk_mux(const char *name, void __iomem *reg,
 	m->clk.parent_names = parents;
 	m->clk.num_parents = num_parents;
 
-	ret = clk_register(&m->clk);
+	return &m->clk;
+}
+
+void clk_mux_free(struct clk *clk_mux)
+{
+	struct clk_mux *m = to_clk_mux(clk_mux);
+
+	free(m);
+}
+
+struct clk *clk_mux(const char *name, void __iomem *reg,
+		u8 shift, u8 width, const char **parents, u8 num_parents)
+{
+	struct clk *m;
+	int ret;
+
+	m = clk_mux_alloc(name, reg, shift, width, parents, num_parents);
+
+	ret = clk_register(m);
 	if (ret) {
-		free(m);
+		free(to_clk_mux(m));
 		return ERR_PTR(ret);
 	}
 
-	return &m->clk;
+	return m;
 }
diff --git a/include/linux/clk.h b/include/linux/clk.h
index cc4f114..0a565ef 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -212,6 +212,10 @@ struct clk *clk_divider_table(const char *name,
 		const struct clk_div_table *table);
 struct clk *clk_fixed_factor(const char *name,
 		const char *parent, unsigned int mult, unsigned int div);
+
+struct clk *clk_mux_alloc(const char *name, void __iomem *reg,
+		u8 shift, u8 width, const char **parents, u8 num_parents);
+void clk_mux_free(struct clk *clk_mux);
 struct clk *clk_mux(const char *name, void __iomem *reg,
 		u8 shift, u8 width, const char **parents, u8 num_parents);
 
-- 
1.8.3.1



From dev at lynxeye.de  Sun Jun 30 17:08:45 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Sun, 30 Jun 2013 23:08:45 +0200
Subject: [PATCH v2 3/7] clk: allow to instanciate clk gate without registering
 it
In-Reply-To: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
References: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
Message-ID: <1372626529-23443-3-git-send-email-dev@lynxeye.de>

Allows to reuse the clk gate code within other clocks.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 drivers/clk/clk-gate.c | 31 +++++++++++++++++++++++++------
 include/linux/clk.h    |  4 ++++
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index f632d85..f33effd 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -29,6 +29,8 @@ struct clk_gate {
 	unsigned flags;
 };
 
+#define to_clk_gate(_clk) container_of(_clk, struct clk_gate, clk)
+
 static int clk_gate_enable(struct clk *clk)
 {
 	struct clk_gate *g = container_of(clk, struct clk_gate, clk);
@@ -80,11 +82,10 @@ struct clk_ops clk_gate_ops = {
 	.is_enabled = clk_gate_is_enabled,
 };
 
-struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
-		u8 shift)
+struct clk *clk_gate_alloc(const char *name, const char *parent,
+		void __iomem *reg, u8 shift)
 {
 	struct clk_gate *g = xzalloc(sizeof(*g));
-	int ret;
 
 	g->parent = parent;
 	g->reg = reg;
@@ -94,13 +95,31 @@ struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 	g->clk.parent_names = &g->parent;
 	g->clk.num_parents = 1;
 
-	ret = clk_register(&g->clk);
+	return &g->clk;
+}
+
+void clk_gate_free(struct clk *clk_gate)
+{
+	struct clk_gate *g = to_clk_gate(clk_gate);
+
+	free(g);
+}
+
+struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
+		u8 shift)
+{
+	struct clk *g;
+	int ret;
+
+	g = clk_gate_alloc(name , parent, reg, shift);
+
+	ret = clk_register(g);
 	if (ret) {
-		free(g);
+		free(to_clk_gate(g));
 		return ERR_PTR(ret);
 	}
 
-	return &g->clk;
+	return g;
 }
 
 struct clk *clk_gate_inverted(const char *name, const char *parent,
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 1cb661e..cc4f114 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -214,6 +214,10 @@ struct clk *clk_fixed_factor(const char *name,
 		const char *parent, unsigned int mult, unsigned int div);
 struct clk *clk_mux(const char *name, void __iomem *reg,
 		u8 shift, u8 width, const char **parents, u8 num_parents);
+
+struct clk *clk_gate_alloc(const char *name, const char *parent,
+		void __iomem *reg, u8 shift);
+void clk_gate_free(struct clk *clk_gate);
 struct clk *clk_gate(const char *name, const char *parent, void __iomem *reg,
 		u8 shift);
 struct clk *clk_gate_inverted(const char *name, const char *parent, void __iomem *reg,
-- 
1.8.3.1



From dev at lynxeye.de  Sun Jun 30 17:08:47 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Sun, 30 Jun 2013 23:08:47 +0200
Subject: [PATCH v2 5/7] tegra: deduplicate clk defines
In-Reply-To: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
References: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
Message-ID: <1372626529-23443-5-git-send-email-dev@lynxeye.de>

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 arch/arm/mach-tegra/include/mach/tegra20-car.h | 90 +++++++++-----------------
 arch/arm/mach-tegra/tegra_avp_init.c           |  6 +-
 2 files changed, 33 insertions(+), 63 deletions(-)

diff --git a/arch/arm/mach-tegra/include/mach/tegra20-car.h b/arch/arm/mach-tegra/include/mach/tegra20-car.h
index 5669732..54c74c7 100644
--- a/arch/arm/mach-tegra/include/mach/tegra20-car.h
+++ b/arch/arm/mach-tegra/include/mach/tegra20-car.h
@@ -111,68 +111,38 @@
 #define CRC_PLLX_MISC_VCOCON_MASK	(0xf << CRC_PLLX_MISC_VCOCON_SHIFT)
 
 #define CRC_RST_DEV_L_SET		0x300
-#define CRC_RST_DEV_L_SET_CACHE2	(1 << 31)
-#define CRC_RST_DEV_L_SET_VCP		(1 << 29)
-#define CRC_RST_DEV_L_SET_HOST1X	(1 << 28)
-#define CRC_RST_DEV_L_SET_DISP1		(1 << 27)
-#define CRC_RST_DEV_L_SET_DISP2		(1 << 26)
-#define CRC_RST_DEV_L_SET_IDE		(1 << 25)
-#define CRC_RST_DEV_L_SET_3D		(1 << 24)
-#define CRC_RST_DEV_L_SET_ISP		(1 << 23)
-#define CRC_RST_DEV_L_SET_USBD		(1 << 22)
-#define CRC_RST_DEV_L_SET_2D		(1 << 21)
-#define CRC_RST_DEV_L_SET_VI		(1 << 20)
-#define CRC_RST_DEV_L_SET_EPP		(1 << 19)
-#define CRC_RST_DEV_L_SET_I2S2		(1 << 18)
-#define CRC_RST_DEV_L_SET_PWM		(1 << 17)
-#define CRC_RST_DEV_L_SET_TWC		(1 << 16)
-#define CRC_RST_DEV_L_SET_SDMMC4	(1 << 15)
-#define CRC_RST_DEV_L_SET_SDMMC1	(1 << 14)
-#define CRC_RST_DEV_L_SET_NDFLASH	(1 << 13)
-#define CRC_RST_DEV_L_SET_I2C1		(1 << 12)
-#define CRC_RST_DEV_L_SET_I2S1		(1 << 11)
-#define CRC_RST_DEV_L_SET_SPDIF		(1 << 10)
-#define CRC_RST_DEV_L_SET_SDMMC2	(1 << 9)
-#define CRC_RST_DEV_L_SET_GPIO		(1 << 8)
-#define CRC_RST_DEV_L_SET_UART2		(1 << 7)
-#define CRC_RST_DEV_L_SET_UART1		(1 << 6)
-#define CRC_RST_DEV_L_SET_TMR		(1 << 5)
-#define CRC_RST_DEV_L_SET_AC97		(1 << 3)
-#define CRC_RST_DEV_L_SET_SYS		(1 << 2)
-#define CRC_RST_DEV_L_SET_COP		(1 << 1)
-#define CRC_RST_DEV_L_SET_CPU		(1 << 0)
+#define CRC_RST_DEV_L_CACHE2		(1 << 31)
+#define CRC_RST_DEV_L_VCP		(1 << 29)
+#define CRC_RST_DEV_L_HOST1X		(1 << 28)
+#define CRC_RST_DEV_L_DISP1		(1 << 27)
+#define CRC_RST_DEV_L_DISP2		(1 << 26)
+#define CRC_RST_DEV_L_IDE		(1 << 25)
+#define CRC_RST_DEV_L_3D		(1 << 24)
+#define CRC_RST_DEV_L_ISP		(1 << 23)
+#define CRC_RST_DEV_L_USBD		(1 << 22)
+#define CRC_RST_DEV_L_2D		(1 << 21)
+#define CRC_RST_DEV_L_VI		(1 << 20)
+#define CRC_RST_DEV_L_EPP		(1 << 19)
+#define CRC_RST_DEV_L_I2S2		(1 << 18)
+#define CRC_RST_DEV_L_PWM		(1 << 17)
+#define CRC_RST_DEV_L_TWC		(1 << 16)
+#define CRC_RST_DEV_L_SDMMC4		(1 << 15)
+#define CRC_RST_DEV_L_SDMMC1		(1 << 14)
+#define CRC_RST_DEV_L_NDFLASH		(1 << 13)
+#define CRC_RST_DEV_L_I2C1		(1 << 12)
+#define CRC_RST_DEV_L_I2S1		(1 << 11)
+#define CRC_RST_DEV_L_SPDIF		(1 << 10)
+#define CRC_RST_DEV_L_SDMMC2		(1 << 9)
+#define CRC_RST_DEV_L_GPIO		(1 << 8)
+#define CRC_RST_DEV_L_UART2		(1 << 7)
+#define CRC_RST_DEV_L_UART1		(1 << 6)
+#define CRC_RST_DEV_L_TMR		(1 << 5)
+#define CRC_RST_DEV_L_AC97		(1 << 3)
+#define CRC_RST_DEV_L_SYS		(1 << 2)
+#define CRC_RST_DEV_L_COP		(1 << 1)
+#define CRC_RST_DEV_L_CPU		(1 << 0)
 
 #define CRC_RST_DEV_L_CLR		0x304
-#define CRC_RST_DEV_L_CLR_CACHE2	(1 << 31)
-#define CRC_RST_DEV_L_CLR_VCP		(1 << 29)
-#define CRC_RST_DEV_L_CLR_HOST1X	(1 << 28)
-#define CRC_RST_DEV_L_CLR_DISP1		(1 << 27)
-#define CRC_RST_DEV_L_CLR_DISP2		(1 << 26)
-#define CRC_RST_DEV_L_CLR_IDE		(1 << 25)
-#define CRC_RST_DEV_L_CLR_3D		(1 << 24)
-#define CRC_RST_DEV_L_CLR_ISP		(1 << 23)
-#define CRC_RST_DEV_L_CLR_USBD		(1 << 22)
-#define CRC_RST_DEV_L_CLR_2D		(1 << 21)
-#define CRC_RST_DEV_L_CLR_VI		(1 << 20)
-#define CRC_RST_DEV_L_CLR_EPP		(1 << 19)
-#define CRC_RST_DEV_L_CLR_I2S2		(1 << 18)
-#define CRC_RST_DEV_L_CLR_PWM		(1 << 17)
-#define CRC_RST_DEV_L_CLR_TWC		(1 << 16)
-#define CRC_RST_DEV_L_CLR_SDMMC4	(1 << 15)
-#define CRC_RST_DEV_L_CLR_SDMMC1	(1 << 14)
-#define CRC_RST_DEV_L_CLR_NDFLASH	(1 << 13)
-#define CRC_RST_DEV_L_CLR_I2C1		(1 << 12)
-#define CRC_RST_DEV_L_CLR_I2S1		(1 << 11)
-#define CRC_RST_DEV_L_CLR_SPDIF		(1 << 10)
-#define CRC_RST_DEV_L_CLR_SDMMC2	(1 << 9)
-#define CRC_RST_DEV_L_CLR_GPIO		(1 << 8)
-#define CRC_RST_DEV_L_CLR_UART2		(1 << 7)
-#define CRC_RST_DEV_L_CLR_UART1		(1 << 6)
-#define CRC_RST_DEV_L_CLR_TMR		(1 << 5)
-#define CRC_RST_DEV_L_CLR_AC97		(1 << 3)
-#define CRC_RST_DEV_L_CLR_SYS		(1 << 2)
-#define CRC_RST_DEV_L_CLR_COP		(1 << 1)
-#define CRC_RST_DEV_L_CLR_CPU		(1 << 0)
 
 #define CRC_RST_CPU_CMPLX_SET		0x340
 
diff --git a/arch/arm/mach-tegra/tegra_avp_init.c b/arch/arm/mach-tegra/tegra_avp_init.c
index 4823733..5099e91 100644
--- a/arch/arm/mach-tegra/tegra_avp_init.c
+++ b/arch/arm/mach-tegra/tegra_avp_init.c
@@ -54,14 +54,14 @@ static void assert_maincomplex_reset(int num_cores)
 		mask |= 0x1111 << i;
 
 	writel(mask, TEGRA_CLK_RESET_BASE + CRC_RST_CPU_CMPLX_SET);
-	writel(CRC_RST_DEV_L_SET_CPU, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_SET);
+	writel(CRC_RST_DEV_L_CPU, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_SET);
 }
 
 /* release reset state of the first core of the main CPU complex */
 static void deassert_cpu0_reset(void)
 {
 	writel(0x1111, TEGRA_CLK_RESET_BASE + CRC_RST_CPU_CMPLX_CLR);
-	writel(CRC_RST_DEV_L_CLR_CPU, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_CLR);
+	writel(CRC_RST_DEV_L_CPU, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_CLR);
 }
 
 /* stop all internal and external clocks to the main CPU complex */
@@ -220,7 +220,7 @@ void barebox_arm_reset_vector(void)
 	deassert_cpu0_reset();
 
 	/* assert AVP reset to stop execution here */
-	writel(CRC_RST_DEV_L_SET_COP, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_SET);
+	writel(CRC_RST_DEV_L_COP, TEGRA_CLK_RESET_BASE + CRC_RST_DEV_L_SET);
 
 	unreachable();
 }
-- 
1.8.3.1



From dev at lynxeye.de  Sun Jun 30 17:08:43 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Sun, 30 Jun 2013 23:08:43 +0200
Subject: [PATCH v2 1/7] clk: add clock lookup from devicetree
Message-ID: <1372626529-23443-1-git-send-email-dev@lynxeye.de>

Taken from the Linuxkernel with some small adjustments for barebox.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
v2: introduce new Kconfig symbol COMMON_CLK_OF_PROVIDER to avoid
    increased binary size for systems not using OF clk.
---
 drivers/clk/Kconfig  |  5 +++
 drivers/clk/clk.c    | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/clk/clkdev.c | 74 +++++++++++++++++++++++++++++++++++++++
 include/linux/clk.h  | 33 ++++++++++++++++++
 4 files changed, 209 insertions(+)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 4589128..a00e539 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -4,3 +4,8 @@ config CLKDEV_LOOKUP
 
 config COMMON_CLK
 	bool
+
+config COMMON_CLK_OF_PROVIDER
+	bool
+	help
+	 Clock driver provides OF-Tree based clock lookup.
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 690a0c6..7ec3d93 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -16,6 +16,7 @@
  */
 #include <common.h>
 #include <errno.h>
+#include <malloc.h>
 #include <linux/clk.h>
 #include <linux/err.h>
 
@@ -253,6 +254,102 @@ int clk_is_enabled_always(struct clk *clk)
 	return 1;
 }
 
+#if defined(CONFIG_OFTREE) && defined(CONFIG_COMMON_CLK_OF_PROVIDER)
+/**
+ * struct of_clk_provider - Clock provider registration structure
+ * @link: Entry in global list of clock providers
+ * @node: Pointer to device tree node of clock provider
+ * @get: Get clock callback.  Returns NULL or a struct clk for the
+ *       given clock specifier
+ * @data: context pointer to be passed into @get callback
+ */
+struct of_clk_provider {
+	struct list_head link;
+
+	struct device_node *node;
+	struct clk *(*get)(struct of_phandle_args *clkspec, void *data);
+	void *data;
+};
+
+static LIST_HEAD(of_clk_providers);
+
+struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data)
+{
+	struct clk_onecell_data *clk_data = data;
+	unsigned int idx = clkspec->args[0];
+
+	if (idx >= clk_data->clk_num) {
+		pr_err("%s: invalid clock index %d\n", __func__, idx);
+		return ERR_PTR(-EINVAL);
+	}
+
+	return clk_data->clks[idx];
+}
+EXPORT_SYMBOL_GPL(of_clk_src_onecell_get);
+
+/**
+ * of_clk_add_provider() - Register a clock provider for a node
+ * @np: Device node pointer associated with clock provider
+ * @clk_src_get: callback for decoding clock
+ * @data: context pointer for @clk_src_get callback.
+ */
+int of_clk_add_provider(struct device_node *np,
+			struct clk *(*clk_src_get)(struct of_phandle_args *clkspec,
+						   void *data),
+			void *data)
+{
+	struct of_clk_provider *cp;
+
+	cp = kzalloc(sizeof(struct of_clk_provider), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+
+	cp->node = np;
+	cp->data = data;
+	cp->get = clk_src_get;
+
+	list_add(&cp->link, &of_clk_providers);
+	pr_debug("Added clock from %s\n", np->full_name);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_clk_add_provider);
+
+/**
+ * of_clk_del_provider() - Remove a previously registered clock provider
+ * @np: Device node pointer associated with clock provider
+ */
+void of_clk_del_provider(struct device_node *np)
+{
+	struct of_clk_provider *cp;
+
+	list_for_each_entry(cp, &of_clk_providers, link) {
+		if (cp->node == np) {
+			list_del(&cp->link);
+			kfree(cp);
+			break;
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(of_clk_del_provider);
+
+struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
+{
+	struct of_clk_provider *provider;
+	struct clk *clk = ERR_PTR(-ENOENT);
+
+	/* Check if we have such a provider in our array */
+	list_for_each_entry(provider, &of_clk_providers, link) {
+		if (provider->node == clkspec->np)
+			clk = provider->get(clkspec, provider->data);
+		if (!IS_ERR(clk))
+			break;
+	}
+
+	return clk;
+}
+#endif
+
 static void dump_one(struct clk *clk, int verbose, int indent)
 {
 	struct clk *c;
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 256927e..66cd832 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -19,10 +19,80 @@
 #include <linux/clkdev.h>
 #include <init.h>
 #include <malloc.h>
+#include <of.h>
 #include <stdio.h>
 
 static LIST_HEAD(clocks);
 
+#if defined(CONFIG_OFTREE) && defined(CONFIG_COMMON_CLK_OF_PROVIDER)
+struct clk *of_clk_get(struct device_node *np, int index)
+{
+	struct of_phandle_args clkspec;
+	struct clk *clk;
+	int rc;
+
+	if (index < 0)
+		return ERR_PTR(-EINVAL);
+
+	rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", index,
+					&clkspec);
+	if (rc)
+		return ERR_PTR(rc);
+
+	clk = of_clk_get_from_provider(&clkspec);
+	return clk;
+}
+EXPORT_SYMBOL(of_clk_get);
+
+/**
+ * of_clk_get_by_name() - Parse and lookup a clock referenced by a device node
+ * @np: pointer to clock consumer node
+ * @name: name of consumer's clock input, or NULL for the first clock reference
+ *
+ * This function parses the clocks and clock-names properties,
+ * and uses them to look up the struct clk from the registered list of clock
+ * providers.
+ */
+struct clk *of_clk_get_by_name(struct device_node *np, const char *name)
+{
+	struct clk *clk = ERR_PTR(-ENOENT);
+
+	/* Walk up the tree of devices looking for a clock that matches */
+	while (np) {
+		int index = 0;
+
+		/*
+		 * For named clocks, first look up the name in the
+		 * "clock-names" property.  If it cannot be found, then
+		 * index will be an error code, and of_clk_get() will fail.
+		 */
+		if (name)
+			index = of_property_match_string(np, "clock-names",
+							 name);
+		clk = of_clk_get(np, index);
+		if (!IS_ERR(clk))
+			break;
+		else if (name && index >= 0) {
+			pr_err("ERROR: could not get clock %s:%s(%i)\n",
+				np->full_name, name ? name : "", index);
+			return clk;
+		}
+
+		/*
+		 * No matching clock found on this node.  If the parent node
+		 * has a "clock-ranges" property, then we can try one of its
+		 * clocks.
+		 */
+		np = np->parent;
+		if (np && !of_get_property(np, "clock-ranges", NULL))
+			break;
+	}
+
+	return clk;
+}
+EXPORT_SYMBOL(of_clk_get_by_name);
+#endif
+
 /*
  * Find the correct struct clk for the device and connection ID.
  * We do slightly fuzzy matching here:
@@ -109,6 +179,10 @@ struct clk *clk_get(struct device_d *dev, const char *con_id)
 	if (!IS_ERR(clk))
 		return clk;
 
+	clk = of_clk_get_by_name(dev->device_node, con_id);
+		if (!IS_ERR(clk))
+			return clk;
+
 	return clk_get_sys(dev_id, con_id);
 }
 EXPORT_SYMBOL(clk_get);
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 38832ba..1cb661e 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -11,6 +11,8 @@
 #ifndef __LINUX_CLK_H
 #define __LINUX_CLK_H
 
+#include <linux/err.h>
+
 struct device_d;
 
 /*
@@ -228,4 +230,35 @@ void clk_dump(int verbose);
 
 #endif
 
+struct device_node;
+struct of_phandle_args;
+
+#if defined(CONFIG_OFTREE) && defined(CONFIG_COMMON_CLK_OF_PROVIDER)
+int of_clk_add_provider(struct device_node *np,
+			struct clk *(*clk_src_get)(struct of_phandle_args *args,
+						   void *data),
+			void *data);
+void of_clk_del_provider(struct device_node *np);
+
+struct clk_onecell_data {
+	struct clk **clks;
+	unsigned int clk_num;
+};
+struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
+
+struct clk *of_clk_get(struct device_node *np, int index);
+struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
+struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
+#else
+static inline struct clk *of_clk_get(struct device_node *np, int index)
+{
+	return ERR_PTR(-ENOENT);
+}
+static inline struct clk *of_clk_get_by_name(struct device_node *np,
+					     const char *name)
+{
+	return ERR_PTR(-ENOENT);
+}
+#endif
+
 #endif
-- 
1.8.3.1



From dev at lynxeye.de  Sun Jun 30 17:08:49 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Sun, 30 Jun 2013 23:08:49 +0200
Subject: [PATCH v2 7/7] tegra: add peripheral clocks
In-Reply-To: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
References: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
Message-ID: <1372626529-23443-7-git-send-email-dev@lynxeye.de>

Only UART clocks are included for now, but the code should cover
other peripherals needs, too.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 arch/arm/mach-tegra/include/mach/tegra20-car.h |  49 ++++++
 drivers/clk/tegra/Makefile                     |   1 +
 drivers/clk/tegra/clk-periph.c                 | 202 +++++++++++++++++++++++++
 drivers/clk/tegra/clk-tegra20.c                |  28 ++++
 drivers/clk/tegra/clk.h                        |  23 +++
 5 files changed, 303 insertions(+)
 create mode 100644 drivers/clk/tegra/clk-periph.c

diff --git a/arch/arm/mach-tegra/include/mach/tegra20-car.h b/arch/arm/mach-tegra/include/mach/tegra20-car.h
index b770ae3..d4cb238 100644
--- a/arch/arm/mach-tegra/include/mach/tegra20-car.h
+++ b/arch/arm/mach-tegra/include/mach/tegra20-car.h
@@ -146,6 +146,55 @@
 #define CRC_PLLE_BASE			0x0e8
 #define CRC_PLLE_MISC			0x0ec
 
+#define CRC_CLK_SOURCE_I2S1		0x100
+#define CRC_CLK_SOURCE_I2S2		0x104
+#define CRC_CLK_SOURCE_SPDIF_OUT	0x108
+#define CRC_CLK_SOURCE_SPDIF_IN		0x10c
+#define CRC_CLK_SOURCE_PWM		0x110
+#define CRC_CLK_SOURCE_SPI		0x114
+#define CRC_CLK_SOURCE_SBC1		0x134
+#define CRC_CLK_SOURCE_SBC2		0x118
+#define CRC_CLK_SOURCE_SBC3		0x11c
+#define CRC_CLK_SOURCE_SBC4		0x1b4
+#define CRC_CLK_SOURCE_XIO		0x120
+#define CRC_CLK_SOURCE_TWC		0x12c
+#define CRC_CLK_SOURCE_IDE		0x144
+#define CRC_CLK_SOURCE_NDFLASH		0x160
+#define CRC_CLK_SOURCE_VFIR		0x168
+#define CRC_CLK_SOURCE_SDMMC1		0x150
+#define CRC_CLK_SOURCE_SDMMC2		0x154
+#define CRC_CLK_SOURCE_SDMMC3		0x1bc
+#define CRC_CLK_SOURCE_SDMMC4		0x164
+#define CRC_CLK_SOURCE_CVE		0x140
+#define CRC_CLK_SOURCE_TVO		0x188
+#define CRC_CLK_SOURCE_TVDAC		0x194
+#define CRC_CLK_SOURCE_HDMI		0x18c
+#define CRC_CLK_SOURCE_DISP1		0x138
+#define CRC_CLK_SOURCE_DISP2		0x13c
+#define CRC_CLK_SOURCE_CSITE		0x1d4
+#define CRC_CLK_SOURCE_LA		0x1f8
+#define CRC_CLK_SOURCE_OWR		0x1cc
+#define CRC_CLK_SOURCE_NOR		0x1d0
+#define CRC_CLK_SOURCE_MIPI		0x174
+#define CRC_CLK_SOURCE_I2C1		0x124
+#define CRC_CLK_SOURCE_I2C2		0x198
+#define CRC_CLK_SOURCE_I2C3		0x1b8
+#define CRC_CLK_SOURCE_DVC		0x128
+#define CRC_CLK_SOURCE_UARTA		0x178
+#define CRC_CLK_SOURCE_UARTB		0x17c
+#define CRC_CLK_SOURCE_UARTC		0x1a0
+#define CRC_CLK_SOURCE_UARTD		0x1c0
+#define CRC_CLK_SOURCE_UARTE		0x1c4
+#define CRC_CLK_SOURCE_3D		0x158
+#define CRC_CLK_SOURCE_2D		0x15c
+#define CRC_CLK_SOURCE_MPE		0x170
+#define CRC_CLK_SOURCE_EPP		0x16c
+#define CRC_CLK_SOURCE_HOST1X		0x180
+#define CRC_CLK_SOURCE_VDE		0x1c8
+#define CRC_CLK_SOURCE_VI		0x148
+#define CRC_CLK_SOURCE_VI_SENSOR	0x1a8
+#define CRC_CLK_SOURCE_EMC		0x19c
+
 #define CRC_RST_DEV_L_SET		0x300
 #define CRC_RST_DEV_L_CACHE2		(1 << 31)
 #define CRC_RST_DEV_L_VCP		(1 << 29)
diff --git a/drivers/clk/tegra/Makefile b/drivers/clk/tegra/Makefile
index be58c20..e614722 100644
--- a/drivers/clk/tegra/Makefile
+++ b/drivers/clk/tegra/Makefile
@@ -1,5 +1,6 @@
 obj-y	+= clk.o
 obj-y	+= clk-divider.o
+obj-y	+= clk-periph.o
 obj-y	+= clk-pll.o
 obj-y	+= clk-pll-out.o
 
diff --git a/drivers/clk/tegra/clk-periph.c b/drivers/clk/tegra/clk-periph.c
new file mode 100644
index 0000000..e969495
--- /dev/null
+++ b/drivers/clk/tegra/clk-periph.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <io.h>
+#include <malloc.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+#define to_clk_periph(_hw) container_of(_hw, struct tegra_clk_periph, hw)
+
+static int clk_periph_get_parent(struct clk *hw)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->mux->ops->get_parent(periph->mux);
+}
+
+static int clk_periph_set_parent(struct clk *hw, u8 index)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->mux->ops->set_parent(periph->mux, index);
+}
+
+static unsigned long clk_periph_recalc_rate(struct clk *hw,
+					    unsigned long parent_rate)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->div->ops->recalc_rate(periph->div, parent_rate);
+}
+
+static long clk_periph_round_rate(struct clk *hw, unsigned long rate,
+				  unsigned long *prate)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->div->ops->round_rate(periph->div, rate, prate);
+}
+
+static int clk_periph_set_rate(struct clk *hw, unsigned long rate,
+			       unsigned long parent_rate)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->div->ops->set_rate(periph->div, rate, parent_rate);
+}
+
+static int clk_periph_is_enabled(struct clk *hw)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+
+	return periph->gate->ops->is_enabled(periph->gate);
+}
+
+static int clk_periph_enable(struct clk *hw)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+	u32 reg;
+
+	reg = readl(periph->rst_reg);
+	reg |= (1 << periph->rst_shift);
+	writel(reg, periph->rst_reg);
+
+	periph->gate->ops->enable(periph->gate);
+
+	udelay(2);
+
+	reg = readl(periph->rst_reg);
+	reg &= ~(1 << periph->rst_shift);
+	writel(reg, periph->rst_reg);
+
+	return 0;
+}
+
+static void clk_periph_disable(struct clk *hw)
+{
+	struct tegra_clk_periph *periph = to_clk_periph(hw);
+	u32 reg;
+
+	reg = readl(periph->rst_reg);
+	reg |= (1 << periph->rst_shift);
+	writel(reg, periph->rst_reg);
+
+	udelay(2);
+
+	periph->gate->ops->disable(periph->gate);
+}
+
+const struct clk_ops tegra_clk_periph_ops = {
+	.get_parent = clk_periph_get_parent,
+	.set_parent = clk_periph_set_parent,
+	.recalc_rate = clk_periph_recalc_rate,
+	.round_rate = clk_periph_round_rate,
+	.set_rate = clk_periph_set_rate,
+	.is_enabled = clk_periph_is_enabled,
+	.enable = clk_periph_enable,
+	.disable = clk_periph_disable,
+};
+
+const struct clk_ops tegra_clk_periph_nodiv_ops = {
+	.get_parent = clk_periph_get_parent,
+	.set_parent = clk_periph_set_parent,
+	.is_enabled = clk_periph_is_enabled,
+	.enable = clk_periph_enable,
+	.disable = clk_periph_disable,
+};
+
+struct clk *_tegra_clk_register_periph(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags,
+		bool has_div)
+{
+	struct tegra_clk_periph *periph;
+	int ret;
+
+	periph = kzalloc(sizeof(*periph), GFP_KERNEL);
+	if (!periph) {
+		pr_err("%s: could not allocate peripheral clk\n",
+		       __func__);
+		goto out_periph;
+	}
+
+	periph->mux = clk_mux_alloc(NULL, clk_base + reg_offset, 30, 2,
+				    parent_names, num_parents);
+	if (!periph->mux)
+		goto out_mux;
+
+	periph->gate = clk_gate_alloc(NULL, NULL, clk_base + 0x10 +
+				      ((id >> 3) & 0xc), id & 0x1f);
+	if (!periph->gate)
+		goto out_gate;
+
+	if (has_div) {
+		periph->div = tegra_clk_divider_alloc(NULL, NULL, clk_base +
+				reg_offset, 0, TEGRA_DIVIDER_ROUND_UP, 0, 8, 1);
+		if (!periph->div)
+			goto out_div;
+	}
+
+	periph->hw.name = name;
+	periph->hw.ops = has_div ? &tegra_clk_periph_ops :
+				   &tegra_clk_periph_nodiv_ops;
+	periph->hw.parent_names = parent_names;
+	periph->hw.num_parents = num_parents;
+	periph->flags = flags;
+	periph->rst_reg = clk_base + 0x4 + ((id >> 3) & 0xc);
+	periph->rst_shift = id & 0x1f;
+
+	ret = clk_register(&periph->hw);
+	if (ret)
+		goto out_register;
+
+	return &periph->hw;
+
+out_register:
+	tegra_clk_divider_free(periph->div);
+out_div:
+	clk_gate_free(periph->gate);
+out_gate:
+	clk_mux_free(periph->mux);
+out_mux:
+	kfree(periph);
+out_periph:
+	return NULL;
+}
+
+struct clk *tegra_clk_register_periph_nodiv(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags)
+{
+	return _tegra_clk_register_periph(name, parent_names, num_parents,
+					  clk_base, reg_offset, id, flags,
+					  false);
+}
+
+struct clk *tegra_clk_register_periph(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags)
+{
+	return _tegra_clk_register_periph(name, parent_names, num_parents,
+					  clk_base, reg_offset, id, flags,
+					  true);
+}
diff --git a/drivers/clk/tegra/clk-tegra20.c b/drivers/clk/tegra/clk-tegra20.c
index 5f668cb..e70f99a 100644
--- a/drivers/clk/tegra/clk-tegra20.c
+++ b/drivers/clk/tegra/clk-tegra20.c
@@ -275,6 +275,28 @@ static void tegra20_pll_init(void)
 			TEGRA_PLL_HAS_CPCON, pll_u_freq_table);
 }
 
+static const char *mux_pllpcm_clkm[] = {"pll_p", "pll_c", "pll_m", "clk_m"};
+
+static void tegra20_periph_init(void)
+{
+	/* peripheral clocks without a divider */
+	clks[uarta] = tegra_clk_register_periph_nodiv("uarta", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTA, uarta, TEGRA_PERIPH_ON_APB);
+	clks[uartb] = tegra_clk_register_periph_nodiv("uartb", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTB, uartb, TEGRA_PERIPH_ON_APB);
+	clks[uartc] = tegra_clk_register_periph_nodiv("uartc", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTC, uartc, TEGRA_PERIPH_ON_APB);
+	clks[uartd] = tegra_clk_register_periph_nodiv("uartd", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTD, uartd, TEGRA_PERIPH_ON_APB);
+	clks[uarte] = tegra_clk_register_periph_nodiv("uarte", mux_pllpcm_clkm,
+			ARRAY_SIZE(mux_pllpcm_clkm), car_base,
+			CRC_CLK_SOURCE_UARTE, uarte, TEGRA_PERIPH_ON_APB);
+}
+
 static struct tegra_clk_init_table init_table[] = {
 	{pll_p,		clk_max,	216000000,	1},
 	{pll_p_out1,	clk_max,	28800000,	1},
@@ -283,6 +305,11 @@ static struct tegra_clk_init_table init_table[] = {
 	{pll_p_out4,	clk_max,	24000000,	1},
 	{pll_c,		clk_max,	600000000,	1},
 	{pll_c_out1,	clk_max,	120000000,	1},
+	{uarta,		pll_p,		0,		1},
+	{uartb,		pll_p,		0,		1},
+	{uartc,		pll_p,		0,		1},
+	{uartd,		pll_p,		0,		1},
+	{uarte,		pll_p,		0,		1},
 	{clk_max,	clk_max,	0,		0}, /* sentinel */
 };
 
@@ -294,6 +321,7 @@ static int tegra20_car_probe(struct device_d *dev)
 
 	tegra20_osc_clk_init();
 	tegra20_pll_init();
+	tegra20_periph_init();
 
 	tegra_init_from_table(init_table, clks, clk_max);
 
diff --git a/drivers/clk/tegra/clk.h b/drivers/clk/tegra/clk.h
index 2bc3698..9bb8f1c 100644
--- a/drivers/clk/tegra/clk.h
+++ b/drivers/clk/tegra/clk.h
@@ -115,6 +115,29 @@ struct clk *tegra_clk_register_pll_out(const char *name,
 		const char *parent_name, void __iomem *reg, u8 shift,
 		u8 divider_flags);
 
+/* struct clk-periph - peripheral clock */
+struct tegra_clk_periph {
+	struct clk	hw;
+	struct clk	*gate;
+	struct clk	*mux;
+	struct clk	*div;
+	u8 		flags;
+	u8		rst_shift;
+	void __iomem	*rst_reg;
+};
+
+#define TEGRA_PERIPH_NO_RESET BIT(0)
+#define TEGRA_PERIPH_MANUAL_RESET BIT(1)
+#define TEGRA_PERIPH_ON_APB BIT(2)
+
+struct clk *tegra_clk_register_periph_nodiv(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags);
+
+struct clk *tegra_clk_register_periph(const char *name,
+		const char **parent_names, int num_parents,
+		void __iomem *clk_base, u32 reg_offset, u8 id, u8 flags);
+
 /* struct clk_init_table - clock initialization table */
 struct tegra_clk_init_table {
 	unsigned int	clk_id;
-- 
1.8.3.1



From dev at lynxeye.de  Sun Jun 30 17:08:48 2013
From: dev at lynxeye.de (Lucas Stach)
Date: Sun, 30 Jun 2013 23:08:48 +0200
Subject: [PATCH v2 6/7] tegra: add new clock framework driver
In-Reply-To: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
References: <1372626529-23443-1-git-send-email-dev@lynxeye.de>
Message-ID: <1372626529-23443-6-git-send-email-dev@lynxeye.de>

This removes the existing Tegra CAR driver and replaces it with code
ported from the Linux clock framework.

In the current state only the relevant PLLs are supported, but this is
no functional regression from the existing code.

Signed-off-by: Lucas Stach <dev at lynxeye.de>
---
 arch/arm/Kconfig                               |   1 +
 arch/arm/mach-tegra/Makefile                   |   1 -
 arch/arm/mach-tegra/include/mach/tegra20-car.h |  36 ++
 arch/arm/mach-tegra/tegra20-car.c              | 120 -------
 drivers/clk/Makefile                           |   1 +
 drivers/clk/tegra/Makefile                     |   6 +
 drivers/clk/tegra/clk-divider.c                | 201 +++++++++++
 drivers/clk/tegra/clk-pll-out.c                | 139 ++++++++
 drivers/clk/tegra/clk-pll.c                    | 451 +++++++++++++++++++++++++
 drivers/clk/tegra/clk-tegra20.c                | 326 ++++++++++++++++++
 drivers/clk/tegra/clk.c                        |  57 ++++
 drivers/clk/tegra/clk.h                        | 127 +++++++
 12 files changed, 1345 insertions(+), 121 deletions(-)
 delete mode 100644 arch/arm/mach-tegra/tegra20-car.c
 create mode 100644 drivers/clk/tegra/Makefile
 create mode 100644 drivers/clk/tegra/clk-divider.c
 create mode 100644 drivers/clk/tegra/clk-pll-out.c
 create mode 100644 drivers/clk/tegra/clk-pll.c
 create mode 100644 drivers/clk/tegra/clk-tegra20.c
 create mode 100644 drivers/clk/tegra/clk.c
 create mode 100644 drivers/clk/tegra/clk.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index af5d8cd..e7d8cdd 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -149,6 +149,7 @@ config ARCH_TEGRA
 	select HAS_DEBUG_LL
 	select BUILTIN_DTB
 	select COMMON_CLK
+	select COMMON_CLK_OF_PROVIDER
 	select CLKDEV_LOOKUP
 	select GPIOLIB
 	select GPIO_TEGRA
diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile
index f9c771f..fd6a870 100644
--- a/arch/arm/mach-tegra/Makefile
+++ b/arch/arm/mach-tegra/Makefile
@@ -2,6 +2,5 @@ CFLAGS_tegra_avp_init.o := -mcpu=arm7tdmi -march=armv4t
 lwl-y += tegra_avp_init.o
 lwl-y += tegra_maincomplex_init.o
 obj-y += tegra20.o
-obj-y += tegra20-car.o
 obj-y += tegra20-pmc.o
 obj-y += tegra20-timer.o
diff --git a/arch/arm/mach-tegra/include/mach/tegra20-car.h b/arch/arm/mach-tegra/include/mach/tegra20-car.h
index 54c74c7..b770ae3 100644
--- a/arch/arm/mach-tegra/include/mach/tegra20-car.h
+++ b/arch/arm/mach-tegra/include/mach/tegra20-car.h
@@ -82,6 +82,39 @@
 #define CRC_OSC_CTRL_PLL_REF_DIV_SHIFT	28
 #define CRC_OSC_CTRL_PLL_REF_DIV_MASK	(0x3 << CRC_OSC_CTRL_PLL_REF_DIV_SHIFT)
 
+#define CRC_PLL_BASE_LOCK		27
+#define CRC_PLLE_MISC_LOCK		11
+
+#define CRC_PLL_MISC_LOCK_ENABLE	18
+#define CRC_PLLDU_MISC_LOCK_ENABLE	22
+#define CRC_PLLE_MISC_LOCK_ENABLE	9
+
+#define CRC_PLLS_BASE			0x0f0
+#define CRC_PLLS_MISC			0x0f4
+
+#define CRC_PLLC_BASE			0x080
+#define CRC_PLLC_OUT			0x084
+#define CRC_PLLC_MISC			0x08c
+
+#define CRC_PLLM_BASE			0x090
+#define CRC_PLLM_OUT			0x094
+#define CRC_PLLM_MISC			0x09c
+
+#define CRC_PLLP_BASE			0x0a0
+#define CRC_PLLP_OUTA			0x0a4
+#define CRC_PLLP_OUTB			0x0a8
+#define CRC_PLLP_MISC			0x0ac
+
+#define CRC_PLLA_BASE			0x0b0
+#define CRC_PLLA_OUT			0x0b4
+#define CRC_PLLA_MISC			0x0bc
+
+#define CRC_PLLU_BASE			0x0c0
+#define CRC_PLLU_MISC			0x0cc
+
+#define CRC_PLLD_BASE			0x0d0
+#define CRC_PLLD_MISC			0x0dc
+
 #define CRC_PLLX_BASE			0x0e0
 #define CRC_PLLX_BASE_BYPASS		(1 << 31)
 #define CRC_PLLX_BASE_ENABLE		(1 << 30)
@@ -110,6 +143,9 @@
 #define CRC_PLLX_MISC_VCOCON_SHIFT	0
 #define CRC_PLLX_MISC_VCOCON_MASK	(0xf << CRC_PLLX_MISC_VCOCON_SHIFT)
 
+#define CRC_PLLE_BASE			0x0e8
+#define CRC_PLLE_MISC			0x0ec
+
 #define CRC_RST_DEV_L_SET		0x300
 #define CRC_RST_DEV_L_CACHE2		(1 << 31)
 #define CRC_RST_DEV_L_VCP		(1 << 29)
diff --git a/arch/arm/mach-tegra/tegra20-car.c b/arch/arm/mach-tegra/tegra20-car.c
deleted file mode 100644
index 3af7bdc..0000000
--- a/arch/arm/mach-tegra/tegra20-car.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * @file
- * @brief Device driver for the Tegra 20 clock and reset (CAR) controller
- */
-
-#include <common.h>
-#include <init.h>
-#include <io.h>
-#include <linux/clk.h>
-#include <linux/clkdev.h>
-#include <linux/err.h>
-#include <mach/iomap.h>
-
-#include <mach/tegra20-car.h>
-
-static void __iomem *car_base;
-
-enum tegra20_clks {
-	cpu, ac97 = 3, rtc, timer, uarta, gpio = 8, sdmmc2, i2s1 = 11, i2c1,
-	ndflash, sdmmc1, sdmmc4, twc, pwm, i2s2, epp, gr2d = 21, usbd, isp,
-	gr3d, ide, disp2, disp1, host1x, vcp, cache2 = 31, mem, ahbdma, apbdma,
-	kbc = 36, stat_mon, pmc, fuse, kfuse, sbc1, nor, spi, sbc2, xio, sbc3,
-	dvc, dsi, mipi = 50, hdmi, csi, tvdac, i2c2, uartc, emc = 57, usb2,
-	usb3, mpe, vde, bsea, bsev, speedo, uartd, uarte, i2c3, sbc4, sdmmc3,
-	pex, owr, afi, csite, pcie_xclk, avpucq = 75, la, irama = 84, iramb,
-	iramc, iramd, cram2, audio_2x, clk_d, csus = 92, cdev1, cdev2,
-	uartb = 96, vfir, spdif_in, spdif_out, vi, vi_sensor, tvo, cve,
-	osc, clk_32k, clk_m, sclk, cclk, hclk, pclk, blink, pll_a, pll_a_out0,
-	pll_c, pll_c_out1, pll_d, pll_d_out0, pll_e, pll_m, pll_m_out1,
-	pll_p, pll_p_out1, pll_p_out2, pll_p_out3, pll_p_out4, pll_u,
-	pll_x, audio, pll_ref, twd, clk_max,
-};
-
-static struct clk *clks[clk_max];
-
-static unsigned long get_osc_frequency(void)
-{
-	u32 osc_ctrl = readl(car_base + CRC_OSC_CTRL);
-
-	switch ((osc_ctrl & CRC_OSC_CTRL_OSC_FREQ_MASK) >>
-		CRC_OSC_CTRL_OSC_FREQ_SHIFT) {
-	case 0:
-		return 13000000;
-	case 1:
-		return 19200000;
-	case 2:
-		return 12000000;
-	case 3:
-		return 26000000;
-	default:
-		return 0;
-	}
-}
-
-static unsigned int get_pll_ref_div(void)
-{
-	u32 osc_ctrl = readl(car_base + CRC_OSC_CTRL);
-
-	return 1U << ((osc_ctrl & CRC_OSC_CTRL_PLL_REF_DIV_MASK) >>
-		      CRC_OSC_CTRL_PLL_REF_DIV_SHIFT);
-}
-
-static int tegra20_car_probe(struct device_d *dev)
-{
-	car_base = dev_request_mem_region(dev, 0);
-	if (!car_base)
-		return -EBUSY;
-
-	/* primary clocks */
-	clks[clk_m] = clk_fixed("clk_m", get_osc_frequency());
-	clks[clk_32k] = clk_fixed("clk_32k", 32768);
-
-	clks[pll_ref] = clk_fixed_factor("pll_ref", "clk_m", 1,
-					 get_pll_ref_div());
-
-	/* derived clocks */
-	/* timer is a gate, but as it's enabled by BOOTROM we needn't worry */
-	clks[timer] = clk_fixed_factor("timer", "clk_m", 1, 1);
-
-	/* device to clock links */
-	clkdev_add_physbase(clks[timer], TEGRA_TMR1_BASE, NULL);
-
-	return 0;
-}
-
-static __maybe_unused struct of_device_id tegra20_car_dt_ids[] = {
-	{
-		.compatible = "nvidia,tegra20-car",
-	}, {
-		/* sentinel */
-	}
-};
-
-static struct driver_d tegra20_car_driver = {
-	.probe	= tegra20_car_probe,
-	.name	= "tegra20-car",
-	.of_compatible = DRV_OF_COMPAT(tegra20_car_dt_ids),
-};
-
-static int tegra20_car_init(void)
-{
-	return platform_driver_register(&tegra20_car_driver);
-}
-postcore_initcall(tegra20_car_init);
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index d6c923d..fb426c0 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_COMMON_CLK)	+= clk.o clk-fixed.o clk-divider.o clk-fixed-factor.o \
 obj-$(CONFIG_CLKDEV_LOOKUP)	+= clkdev.o
 
 obj-$(CONFIG_ARCH_MXS)		+= mxs/
+obj-$(CONFIG_ARCH_TEGRA)	+= tegra/
diff --git a/drivers/clk/tegra/Makefile b/drivers/clk/tegra/Makefile
new file mode 100644
index 0000000..be58c20
--- /dev/null
+++ b/drivers/clk/tegra/Makefile
@@ -0,0 +1,6 @@
+obj-y	+= clk.o
+obj-y	+= clk-divider.o
+obj-y	+= clk-pll.o
+obj-y	+= clk-pll-out.o
+
+obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= clk-tegra20.o
\ No newline at end of file
diff --git a/drivers/clk/tegra/clk-divider.c b/drivers/clk/tegra/clk-divider.c
new file mode 100644
index 0000000..0ddd64e
--- /dev/null
+++ b/drivers/clk/tegra/clk-divider.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <io.h>
+#include <malloc.h>
+#include <asm-generic/div64.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+#define pll_out_override(p) (BIT((p->shift - 6)))
+#define div_mask(d) ((1 << (d->width)) - 1)
+#define get_mul(d) (1 << d->frac_width)
+#define get_max_div(d) div_mask(d)
+
+#define PERIPH_CLK_UART_DIV_ENB BIT(24)
+
+#define to_clk_frac_div(_hw) container_of(_hw, struct tegra_clk_frac_div, hw)
+
+static int get_div(struct tegra_clk_frac_div *divider, unsigned long rate,
+		   unsigned long parent_rate)
+{
+	u64 divider_ux1 = parent_rate;
+	u8 flags = divider->flags;
+	int mul;
+
+	if (!rate)
+		return 0;
+
+	mul = get_mul(divider);
+
+	if (!(flags & TEGRA_DIVIDER_INT))
+		divider_ux1 *= mul;
+
+	if (flags & TEGRA_DIVIDER_ROUND_UP)
+		divider_ux1 += rate - 1;
+
+	do_div(divider_ux1, rate);
+
+	if (flags & TEGRA_DIVIDER_INT)
+		divider_ux1 *= mul;
+
+	divider_ux1 -= mul;
+
+	if (divider_ux1 < 0)
+		return 0;
+
+	if (divider_ux1 > get_max_div(divider))
+		return -EINVAL;
+
+	return divider_ux1;
+}
+
+static unsigned long clk_frac_div_recalc_rate(struct clk *hw,
+					     unsigned long parent_rate)
+{
+	struct tegra_clk_frac_div *divider = to_clk_frac_div(hw);
+	u32 reg;
+	int div, mul;
+	u64 rate = parent_rate;
+
+	reg = readl(divider->reg) >> divider->shift;
+	div = reg & div_mask(divider);
+
+	mul = get_mul(divider);
+	div += mul;
+
+	rate *= mul;
+	rate += div - 1;
+	do_div(rate, div);
+
+	return rate;
+}
+
+static long clk_frac_div_round_rate(struct clk *hw, unsigned long rate,
+				   unsigned long *prate)
+{
+	struct tegra_clk_frac_div *divider = to_clk_frac_div(hw);
+	int div, mul;
+	unsigned long output_rate = *prate;
+
+	if (!rate)
+		return output_rate;
+
+	div = get_div(divider, rate, output_rate);
+	if (div < 0)
+		return *prate;
+
+	mul = get_mul(divider);
+
+	return DIV_ROUND_UP(output_rate * mul, div + mul);
+}
+
+static int clk_frac_div_set_rate(struct clk *hw, unsigned long rate,
+				unsigned long parent_rate)
+{
+	struct tegra_clk_frac_div *divider = to_clk_frac_div(hw);
+	int div;
+	u32 val;
+
+	div = get_div(divider, rate, parent_rate);
+	if (div < 0)
+		return div;
+
+	val = readl(divider->reg);
+	val &= ~(div_mask(divider) << divider->shift);
+	val |= div << divider->shift;
+
+	if (divider->flags & TEGRA_DIVIDER_UART) {
+		if (div)
+			val |= PERIPH_CLK_UART_DIV_ENB;
+		else
+			val &= ~PERIPH_CLK_UART_DIV_ENB;
+	}
+
+	if (divider->flags & TEGRA_DIVIDER_FIXED)
+		val |= pll_out_override(divider);
+
+	writel(val, divider->reg);
+
+	return 0;
+}
+
+const struct clk_ops tegra_clk_frac_div_ops = {
+	.recalc_rate = clk_frac_div_recalc_rate,
+	.set_rate = clk_frac_div_set_rate,
+	.round_rate = clk_frac_div_round_rate,
+};
+
+struct clk *tegra_clk_divider_alloc(const char *name, const char *parent_name,
+		void __iomem *reg, unsigned long flags, u8 clk_divider_flags,
+		u8 shift, u8 width, u8 frac_width)
+{
+	struct tegra_clk_frac_div *divider;
+
+	divider = kzalloc(sizeof(*divider), GFP_KERNEL);
+	if (!divider) {
+		pr_err("%s: could not allocate fractional divider clk\n",
+		       __func__);
+		return NULL;
+	}
+
+	divider->parent = parent_name;
+	divider->hw.name = name;
+	divider->hw.ops = &tegra_clk_frac_div_ops;
+	divider->hw.flags = flags;
+	divider->hw.parent_names = divider->parent ? &divider->parent : NULL;
+	divider->hw.num_parents = divider->parent ? 1 : 0;
+
+	divider->reg = reg;
+	divider->shift = shift;
+	divider->width = width;
+	divider->frac_width = frac_width;
+	divider->flags = clk_divider_flags;
+
+	return &divider->hw;
+}
+
+void tegra_clk_divider_free(struct clk *clk_div)
+{
+	struct tegra_clk_frac_div *divider = to_clk_frac_div(clk_div);
+
+	kfree(divider);
+}
+
+struct clk *tegra_clk_register_divider(const char *name,
+		const char *parent_name, void __iomem *reg, unsigned long flags,
+		u8 clk_divider_flags, u8 shift, u8 width, u8 frac_width)
+{
+	struct tegra_clk_frac_div *divider;
+	int ret;
+
+	divider = to_clk_frac_div(tegra_clk_divider_alloc(name, parent_name,
+				  reg, flags, clk_divider_flags, shift, width,
+				  frac_width));
+
+	ret = clk_register(&divider->hw);
+	if (ret) {
+		kfree(divider);
+		return ERR_PTR(ret);
+	}
+
+	return &divider->hw;
+}
diff --git a/drivers/clk/tegra/clk-pll-out.c b/drivers/clk/tegra/clk-pll-out.c
new file mode 100644
index 0000000..52d8473
--- /dev/null
+++ b/drivers/clk/tegra/clk-pll-out.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <io.h>
+#include <malloc.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+#define pll_out_enb(p) (BIT(p->enb_bit_idx))
+#define pll_out_rst(p) (BIT(p->rst_bit_idx))
+
+#define to_clk_pll_out(_hw) container_of(_hw, struct tegra_clk_pll_out, hw)
+
+static int clk_pll_out_is_enabled(struct clk *hw)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+	u32 val = readl(pll_out->reg);
+	int state;
+
+	state = (val & pll_out_enb(pll_out)) ? 1 : 0;
+	if (!(val & (pll_out_rst(pll_out))))
+		state = 0;
+	return state;
+}
+
+static int clk_pll_out_enable(struct clk *hw)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+	u32 val;
+
+	val = readl(pll_out->reg);
+
+	val |= (pll_out_enb(pll_out) | pll_out_rst(pll_out));
+
+	writel(val, pll_out->reg);
+	udelay(2);
+
+	return 0;
+}
+
+static void clk_pll_out_disable(struct clk *hw)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+	u32 val;
+
+	val = readl(pll_out->reg);
+
+	val &= ~(pll_out_enb(pll_out) | pll_out_rst(pll_out));
+
+	writel(val, pll_out->reg);
+	udelay(2);
+}
+
+static unsigned long clk_pll_out_recalc_rate(struct clk *hw,
+					     unsigned long parent_rate)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+
+	return pll_out->div->ops->recalc_rate(pll_out->div, parent_rate);
+}
+
+static long clk_pll_out_round_rate(struct clk *hw, unsigned long rate,
+				   unsigned long *prate)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+
+	return pll_out->div->ops->round_rate(pll_out->div, rate, prate);
+}
+
+static int clk_pll_out_set_rate(struct clk *hw, unsigned long rate,
+				unsigned long parent_rate)
+{
+	struct tegra_clk_pll_out *pll_out = to_clk_pll_out(hw);
+
+	return pll_out->div->ops->set_rate(pll_out->div, rate, parent_rate);
+}
+
+const struct clk_ops tegra_clk_pll_out_ops = {
+	.is_enabled = clk_pll_out_is_enabled,
+	.enable = clk_pll_out_enable,
+	.disable = clk_pll_out_disable,
+	.recalc_rate = clk_pll_out_recalc_rate,
+	.round_rate = clk_pll_out_round_rate,
+	.set_rate = clk_pll_out_set_rate,
+};
+
+struct clk *tegra_clk_register_pll_out(const char *name,
+		const char *parent_name, void __iomem *reg, u8 shift, u8 divider_flags)
+{
+	struct tegra_clk_pll_out *pll_out;
+	int ret;
+
+	pll_out = kzalloc(sizeof(*pll_out), GFP_KERNEL);
+	if (!pll_out)
+		return NULL;
+
+	pll_out->div = tegra_clk_divider_alloc(NULL, NULL, reg, 0, divider_flags, shift + 8, 8, 1);
+	if (!pll_out->div) {
+		kfree(pll_out);
+		return NULL;
+	}
+
+	pll_out->parent = parent_name;
+	pll_out->hw.name = name;
+	pll_out->hw.ops = &tegra_clk_pll_out_ops;
+	pll_out->hw.parent_names = (pll_out->parent ? &pll_out->parent : NULL);
+	pll_out->hw.num_parents = (pll_out->parent ? 1 : 0);
+
+	pll_out->reg = reg;
+	pll_out->enb_bit_idx = shift + 1;
+	pll_out->rst_bit_idx = shift;
+
+	ret = clk_register(&pll_out->hw);
+	if (ret) {
+		tegra_clk_divider_free(pll_out->div);
+		kfree(pll_out);
+		return ERR_PTR(ret);
+	}
+
+	return &pll_out->hw;
+}
diff --git a/drivers/clk/tegra/clk-pll.c b/drivers/clk/tegra/clk-pll.c
new file mode 100644
index 0000000..f3257c4
--- /dev/null
+++ b/drivers/clk/tegra/clk-pll.c
@@ -0,0 +1,451 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <io.h>
+#include <malloc.h>
+#include <asm-generic/div64.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+#include "clk.h"
+
+#define PLL_BASE_BYPASS		BIT(31)
+#define PLL_BASE_ENABLE		BIT(30)
+#define PLL_BASE_REF_ENABLE	BIT(29)
+#define PLL_BASE_OVERRIDE	BIT(28)
+
+#define PLL_BASE_DIVP_SHIFT	20
+#define PLL_BASE_DIVP_WIDTH	3
+#define PLL_BASE_DIVN_SHIFT	8
+#define PLL_BASE_DIVN_WIDTH	10
+#define PLL_BASE_DIVM_SHIFT	0
+#define PLL_BASE_DIVM_WIDTH	5
+#define PLLU_POST_DIVP_MASK	0x1
+
+#define PLL_MISC_DCCON_SHIFT	20
+#define PLL_MISC_CPCON_SHIFT	8
+#define PLL_MISC_CPCON_WIDTH	4
+#define PLL_MISC_CPCON_MASK	((1 << PLL_MISC_CPCON_WIDTH) - 1)
+#define PLL_MISC_LFCON_SHIFT	4
+#define PLL_MISC_LFCON_WIDTH	4
+#define PLL_MISC_LFCON_MASK	((1 << PLL_MISC_LFCON_WIDTH) - 1)
+#define PLL_MISC_VCOCON_SHIFT	0
+#define PLL_MISC_VCOCON_WIDTH	4
+#define PLL_MISC_VCOCON_MASK	((1 << PLL_MISC_VCOCON_WIDTH) - 1)
+
+#define OUT_OF_TABLE_CPCON	8
+
+#define PMC_PLLP_WB0_OVERRIDE			0xf8
+#define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE	BIT(12)
+#define PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE	BIT(11)
+
+#define PLL_POST_LOCK_DELAY	50
+
+#define PLLDU_LFCON_SET_DIVN	600
+
+#define PLLE_BASE_DIVCML_SHIFT	24
+#define PLLE_BASE_DIVCML_WIDTH	4
+#define PLLE_BASE_DIVP_SHIFT	16
+#define PLLE_BASE_DIVP_WIDTH	7
+#define PLLE_BASE_DIVN_SHIFT	8
+#define PLLE_BASE_DIVN_WIDTH	8
+#define PLLE_BASE_DIVM_SHIFT	0
+#define PLLE_BASE_DIVM_WIDTH	8
+
+#define PLLE_MISC_SETUP_BASE_SHIFT	16
+#define PLLE_MISC_SETUP_BASE_MASK	(0xffff << PLLE_MISC_SETUP_BASE_SHIFT)
+#define PLLE_MISC_LOCK_ENABLE		BIT(9)
+#define PLLE_MISC_READY			BIT(15)
+#define PLLE_MISC_SETUP_EX_SHIFT	2
+#define PLLE_MISC_SETUP_EX_MASK		(3 << PLLE_MISC_SETUP_EX_SHIFT)
+#define PLLE_MISC_SETUP_MASK		(PLLE_MISC_SETUP_BASE_MASK |	\
+					 PLLE_MISC_SETUP_EX_MASK)
+#define PLLE_MISC_SETUP_VALUE		(7 << PLLE_MISC_SETUP_BASE_SHIFT)
+
+#define PLLE_SS_CTRL		0x68
+#define PLLE_SS_DISABLE		(7 << 10)
+
+#define PMC_SATA_PWRGT			0x1ac
+#define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE	BIT(5)
+#define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL	BIT(4)
+
+#define pll_readl(offset, p) readl(p->clk_base + offset)
+#define pll_readl_base(p) pll_readl(p->params->base_reg, p)
+#define pll_readl_misc(p) pll_readl(p->params->misc_reg, p)
+
+#define pll_writel(val, offset, p) writel(val, p->clk_base + offset)
+#define pll_writel_base(val, p) pll_writel(val, p->params->base_reg, p)
+#define pll_writel_misc(val, p) pll_writel(val, p->params->misc_reg, p)
+
+#define mask(w) ((1 << (w)) - 1)
+#define divm_mask(p) mask(p->divm_width)
+#define divn_mask(p) mask(p->divn_width)
+#define divp_mask(p) (p->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :	\
+		      mask(p->divp_width))
+
+#define divm_max(p) (divm_mask(p))
+#define divn_max(p) (divn_mask(p))
+#define divp_max(p) (1 << (divp_mask(p)))
+
+#define to_clk_pll(_hw) container_of(_hw, struct tegra_clk_pll, hw)
+
+static int clk_pll_is_enabled(struct clk *hw)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 val;
+
+	val = pll_readl_base(pll);
+
+	return val & PLL_BASE_ENABLE ? 1 : 0;
+}
+
+static void clk_pll_enable_lock(struct tegra_clk_pll *pll)
+{
+	u32 val;
+
+	if (!(pll->flags & TEGRA_PLL_USE_LOCK))
+		return;
+
+	val = pll_readl_misc(pll);
+	val |= BIT(pll->params->lock_enable_bit_idx);
+	pll_writel_misc(val, pll);
+}
+
+static int clk_pll_wait_for_lock(struct tegra_clk_pll *pll,
+				 void __iomem *lock_addr, u32 lock_bit_idx)
+{
+	int i;
+	u32 val;
+
+	if (!(pll->flags & TEGRA_PLL_USE_LOCK)) {
+		udelay(pll->params->lock_delay);
+		return 0;
+	}
+
+	for (i = 0; i < pll->params->lock_delay; i++) {
+		val = readl(lock_addr);
+		if (val & BIT(lock_bit_idx)) {
+			udelay(PLL_POST_LOCK_DELAY);
+			return 0;
+		}
+		udelay(2); /* timeout = 2 * lock time */
+	}
+
+	pr_err("%s: Timed out waiting for pll %s lock\n", __func__,
+	       pll->hw.name);
+
+	return -1;
+}
+
+static int clk_pll_enable(struct clk *hw)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 val;
+
+	clk_pll_enable_lock(pll);
+
+	val = pll_readl_base(pll);
+	val &= ~PLL_BASE_BYPASS;
+	val |= PLL_BASE_ENABLE;
+	pll_writel_base(val, pll);
+
+	clk_pll_wait_for_lock(pll, pll->clk_base + pll->params->base_reg,
+			      pll->params->lock_bit_idx);
+
+	return 0;
+}
+
+static void clk_pll_disable(struct clk *hw)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 val;
+
+	val = pll_readl_base(pll);
+	val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
+	pll_writel_base(val, pll);
+}
+
+static int _get_table_rate(struct clk *hw,
+			   struct tegra_clk_pll_freq_table *cfg,
+			   unsigned long rate, unsigned long parent_rate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	struct tegra_clk_pll_freq_table *sel;
+
+	for (sel = pll->freq_table; sel->input_rate != 0; sel++)
+		if (sel->input_rate == parent_rate &&
+		    sel->output_rate == rate)
+			break;
+
+	if (sel->input_rate == 0)
+		return -EINVAL;
+
+	BUG_ON(sel->p < 1);
+
+	cfg->input_rate = sel->input_rate;
+	cfg->output_rate = sel->output_rate;
+	cfg->m = sel->m;
+	cfg->n = sel->n;
+	cfg->p = sel->p;
+	cfg->cpcon = sel->cpcon;
+
+	return 0;
+}
+
+static unsigned long clk_pll_recalc_rate(struct clk *hw,
+					 unsigned long parent_rate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 val = pll_readl_base(pll);
+	u32 divn = 0, divm = 0, divp = 0;
+	u64 rate = parent_rate;
+
+	if (val & PLL_BASE_BYPASS)
+		return parent_rate;
+
+	if ((pll->flags & TEGRA_PLL_FIXED) && !(val & PLL_BASE_OVERRIDE)) {
+		struct tegra_clk_pll_freq_table sel;
+		if (_get_table_rate(hw, &sel, pll->fixed_rate, parent_rate)) {
+			pr_err("Clock %s has unknown fixed frequency\n",
+			       hw->name);
+			BUG();
+		}
+		return pll->fixed_rate;
+	}
+
+	divp = (val >> pll->divp_shift) & (divp_mask(pll));
+	if (pll->flags & TEGRA_PLLU)
+		divp ^= 1;
+
+	divn = (val >> pll->divn_shift) & (divn_mask(pll));
+	divm = (val >> pll->divm_shift) & (divm_mask(pll));
+	divm *= (1 << divp);
+
+	rate *= divn;
+	do_div(rate, divm);
+
+	return rate;
+}
+
+static int _calc_rate(struct clk *hw, struct tegra_clk_pll_freq_table *cfg,
+		      unsigned long rate, unsigned long parent_rate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	unsigned long cfreq;
+	u32 p_div = 0;
+
+	switch (parent_rate) {
+	case 12000000:
+	case 26000000:
+		cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000;
+		break;
+	case 13000000:
+		cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000;
+		break;
+	case 16800000:
+	case 19200000:
+		cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000;
+		break;
+	case 9600000:
+	case 28800000:
+		/*
+		 * PLL_P_OUT1 rate is not listed in PLLA table
+		 */
+		cfreq = parent_rate/(parent_rate/1000000);
+		break;
+	default:
+		pr_err("%s Unexpected reference rate %lu\n",
+		       __func__, parent_rate);
+		BUG();
+	}
+
+	/* Raise VCO to guarantee 0.5% accuracy */
+	for (cfg->output_rate = rate; cfg->output_rate < 200 * cfreq;
+	     cfg->output_rate <<= 1)
+		p_div++;
+
+	cfg->p = 1 << p_div;
+	cfg->m = parent_rate / cfreq;
+	cfg->n = cfg->output_rate / cfreq;
+	cfg->cpcon = OUT_OF_TABLE_CPCON;
+
+	if (cfg->m > divm_max(pll) || cfg->n > divn_max(pll) ||
+	    cfg->p > divp_max(pll) || cfg->output_rate > pll->params->vco_max) {
+		pr_err("%s: Failed to set %s rate %lu\n",
+		       __func__, hw->name, rate);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static long clk_pll_round_rate(struct clk *hw, unsigned long rate,
+			unsigned long *prate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	struct tegra_clk_pll_freq_table cfg;
+	u64 output_rate = *prate;
+
+	if (pll->flags & TEGRA_PLL_FIXED)
+		return pll->fixed_rate;
+
+	/* PLLM is used for memory; we do not change rate */
+	if (pll->flags & TEGRA_PLLM)
+		return clk_get_rate(hw);
+
+	if (_get_table_rate(hw, &cfg, rate, *prate) &&
+	    _calc_rate(hw, &cfg, rate, *prate))
+		return -EINVAL;
+
+	output_rate *= cfg.n;
+	do_div(output_rate, cfg.m * cfg.p);
+
+	return output_rate;
+}
+
+static int _program_pll(struct clk *hw, struct tegra_clk_pll_freq_table *cfg,
+			unsigned long rate)
+{
+	struct tegra_clk_pll *pll = to_clk_pll(hw);
+	u32 divp, val, old_base;
+	int state;
+
+	divp = __ffs(cfg->p);
+
+	if (pll->flags & TEGRA_PLLU)
+		divp ^= 1;
+
+	old_base = val = pll_readl_base(pll);
+	val &= ~((divm_mask(pll) << pll->divm_shift) |
+		 (divn_mask(pll) << pll->divn_shift) |
+		 (divp_mask(pll) << pll->divp_shift));
+	val |= ((cfg->m << pll->divm_shift) |
+		(cfg->n << pll->divn_shift) |
+		(divp << pll->divp_shift));
+	if (pll->flags & TEGRA_PLL_FIXED)
+		val |= PLL_BASE_OVERRIDE;
+	if (val == old_base) {
+		return 0;
+	}
+
+	state = clk_pll_is_enabled(hw);
+
+	if (state) {
+		clk_pll_disable(hw);
+		val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
+	}
+	pll_writel_base(val, pll);
+
+	if (pll->flags & TEGRA_PLL_HAS_CPCON) {
+		val = pll_readl_misc(pll);
+		val &= ~(PLL_MISC_CPCON_MASK << PLL_MISC_CPCON_SHIFT);
+		val |= cfg->cpcon << PLL_MISC_CPCON_SHIFT;
+		if (pll->flags & TEGRA_PLL_SET_LFCON) {
+			val &= ~(PLL_MISC_LFCON_MASK << PLL_MISC_LFCON_SHIFT);
+			if (cfg->n >= PLLDU_LFCON_SET_DIVN)
+				val |= 0x1 << PLL_MISC_LFCON_SHIFT;
+		} else if (pll->flags & TEGRA_PLL_SET_DCCON) {
+			val &= ~(0x1 << PLL_MISC_DCCON_SHIFT);
+			if (rate >= (pll->params->vco_max >> 1))
+				val |= 0x1 << PLL_MISC_DCCON_SHIFT;
+		}
+		pll_writel_misc(val, pll);
+	}
+
+	if (state)
+		clk_pll_enable(hw);
+
+	return 0;
+}
+
+static int clk_pll_set_rate(struct clk *hw, unsigned long rate,
+			unsigned long parent_rate)
+{
+	struct tegra_clk_pll_freq_table cfg;
+
+	if (_get_table_rate(hw, &cfg, rate, parent_rate) &&
+	    _calc_rate(hw, &cfg, rate, parent_rate))
+		return -EINVAL;
+
+	return _program_pll(hw, &cfg, rate);
+}
+
+const struct clk_ops tegra_clk_pll_ops = {
+	.is_enabled = clk_pll_is_enabled,
+	.enable = clk_pll_enable,
+	.disable = clk_pll_disable,
+	.recalc_rate = clk_pll_recalc_rate,
+	.round_rate = clk_pll_round_rate,
+	.set_rate = clk_pll_set_rate,
+};
+
+static struct clk *_tegra_clk_register_pll(const char *name,
+		const char *parent_name, void __iomem *clk_base,
+		unsigned long flags, unsigned long fixed_rate,
+		struct tegra_clk_pll_params *pll_params, u8 pll_flags,
+		struct tegra_clk_pll_freq_table *freq_table,
+		const struct clk_ops *ops)
+{
+	struct tegra_clk_pll *pll;
+	int ret;
+
+	pll = kzalloc(sizeof(*pll), GFP_KERNEL);
+	if (!pll)
+		return NULL;
+
+	pll->parent = parent_name;
+	pll->hw.name = name;
+	pll->hw.ops = ops;
+	pll->hw.flags = flags;
+	pll->hw.parent_names = (pll->parent ? &pll->parent : NULL);
+	pll->hw.num_parents = (pll->parent ? 1 : 0);
+
+	pll->clk_base = clk_base;
+
+	pll->freq_table = freq_table;
+	pll->params = pll_params;
+	pll->fixed_rate = fixed_rate;
+	pll->flags = pll_flags;
+
+	pll->divp_shift = PLL_BASE_DIVP_SHIFT;
+	pll->divp_width = PLL_BASE_DIVP_WIDTH;
+	pll->divn_shift = PLL_BASE_DIVN_SHIFT;
+	pll->divn_width = PLL_BASE_DIVN_WIDTH;
+	pll->divm_shift = PLL_BASE_DIVM_SHIFT;
+	pll->divm_width = PLL_BASE_DIVM_WIDTH;
+
+	ret = clk_register(&pll->hw);
+	if (ret) {
+		kfree(pll);
+		return ERR_PTR(ret);
+	}
+
+	return &pll->hw;
+}
+
+struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
+		void __iomem *clk_base,
+		unsigned long flags, unsigned long fixed_rate,
+		struct tegra_clk_pll_params *pll_params, u8 pll_flags,
+		struct tegra_clk_pll_freq_table *freq_table)
+{
+	return _tegra_clk_register_pll(name, parent_name, clk_base,
+			flags, fixed_rate, pll_params, pll_flags, freq_table,
+			&tegra_clk_pll_ops);
+}
diff --git a/drivers/clk/tegra/clk-tegra20.c b/drivers/clk/tegra/clk-tegra20.c
new file mode 100644
index 0000000..5f668cb
--- /dev/null
+++ b/drivers/clk/tegra/clk-tegra20.c
@@ -0,0 +1,326 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <init.h>
+#include <io.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <mach/lowlevel.h>
+#include <mach/tegra20-car.h>
+
+#include "clk.h"
+
+static void __iomem *car_base;
+
+enum tegra20_clks {
+	cpu, ac97 = 3, rtc, timer, uarta, uartb, gpio, sdmmc2, i2s1 = 11, i2c1,
+	ndflash, sdmmc1, sdmmc4, twc, pwm, i2s2, epp, gr2d = 21, usbd, isp,
+	gr3d, ide, disp2, disp1, host1x, vcp, cache2 = 31, mem, ahbdma, apbdma,
+	kbc = 36, stat_mon, pmc, fuse, kfuse, sbc1, nor, spi, sbc2, xio, sbc3,
+	dvc, dsi, mipi = 50, hdmi, csi, tvdac, i2c2, uartc, emc = 57, usb2,
+	usb3, mpe, vde, bsea, bsev, speedo, uartd, uarte, i2c3, sbc4, sdmmc3,
+	pex, owr, afi, csite, pcie_xclk, avpucq = 75, la, irama = 84, iramb,
+	iramc, iramd, cram2, audio_2x, clk_d, csus = 92, cdev2, cdev1,
+	vfir = 96, spdif_in, spdif_out, vi, vi_sensor, tvo, cve,
+	osc, clk_32k, clk_m, sclk, cclk, hclk, pclk, blink, pll_a, pll_a_out0,
+	pll_c, pll_c_out1, pll_d, pll_d_out0, pll_e, pll_m, pll_m_out1,
+	pll_p, pll_p_out1, pll_p_out2, pll_p_out3, pll_p_out4, pll_u,
+	pll_x, audio, pll_ref, twd, clk_max,
+};
+
+static struct clk *clks[clk_max];
+static struct clk_onecell_data clk_data;
+
+static unsigned int get_pll_ref_div(void)
+{
+	u32 osc_ctrl = readl(car_base + CRC_OSC_CTRL);
+
+	return 1U << ((osc_ctrl & CRC_OSC_CTRL_PLL_REF_DIV_MASK) >>
+		      CRC_OSC_CTRL_PLL_REF_DIV_SHIFT);
+}
+
+static void tegra20_osc_clk_init(void)
+{
+	clks[clk_m] = clk_fixed("clk_m", tegra_get_osc_clock());
+	clks[clk_32k] = clk_fixed("clk_32k", 32768);
+
+	clks[pll_ref] = clk_fixed_factor("pll_ref", "clk_m", 1,
+					 get_pll_ref_div());
+}
+
+/* PLL frequency tables */
+static struct tegra_clk_pll_freq_table pll_c_freq_table[] = {
+	{ 12000000, 600000000, 600, 12, 1, 8 },
+	{ 13000000, 600000000, 600, 13, 1, 8 },
+	{ 19200000, 600000000, 500, 16, 1, 6 },
+	{ 26000000, 600000000, 600, 26, 1, 8 },
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
+	{ 12000000, 216000000, 432, 12, 2, 8},
+	{ 13000000, 216000000, 432, 13, 2, 8},
+	{ 19200000, 216000000, 90,   4, 2, 1},
+	{ 26000000, 216000000, 432, 26, 2, 8},
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
+	{ 12000000, 666000000, 666, 12, 1, 8},
+	{ 13000000, 666000000, 666, 13, 1, 8},
+	{ 19200000, 666000000, 555, 16, 1, 8},
+	{ 26000000, 666000000, 666, 26, 1, 8},
+	{ 12000000, 600000000, 600, 12, 1, 8},
+	{ 13000000, 600000000, 600, 13, 1, 8},
+	{ 19200000, 600000000, 375, 12, 1, 6},
+	{ 26000000, 600000000, 600, 26, 1, 8},
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
+	/* 1 GHz */
+	{ 12000000, 1000000000, 1000, 12, 1, 12},
+	{ 13000000, 1000000000, 1000, 13, 1, 12},
+	{ 19200000, 1000000000, 625,  12, 1, 8},
+	{ 26000000, 1000000000, 1000, 26, 1, 12},
+
+	/* 912 MHz */
+	{ 12000000, 912000000,  912,  12, 1, 12},
+	{ 13000000, 912000000,  912,  13, 1, 12},
+	{ 19200000, 912000000,  760,  16, 1, 8},
+	{ 26000000, 912000000,  912,  26, 1, 12},
+
+	/* 816 MHz */
+	{ 12000000, 816000000,  816,  12, 1, 12},
+	{ 13000000, 816000000,  816,  13, 1, 12},
+	{ 19200000, 816000000,  680,  16, 1, 8},
+	{ 26000000, 816000000,  816,  26, 1, 12},
+
+	/* 760 MHz */
+	{ 12000000, 760000000,  760,  12, 1, 12},
+	{ 13000000, 760000000,  760,  13, 1, 12},
+	{ 19200000, 760000000,  950,  24, 1, 8},
+	{ 26000000, 760000000,  760,  26, 1, 12},
+
+	/* 750 MHz */
+	{ 12000000, 750000000,  750,  12, 1, 12},
+	{ 13000000, 750000000,  750,  13, 1, 12},
+	{ 19200000, 750000000,  625,  16, 1, 8},
+	{ 26000000, 750000000,  750,  26, 1, 12},
+
+	/* 608 MHz */
+	{ 12000000, 608000000,  608,  12, 1, 12},
+	{ 13000000, 608000000,  608,  13, 1, 12},
+	{ 19200000, 608000000,  380,  12, 1, 8},
+	{ 26000000, 608000000,  608,  26, 1, 12},
+
+	/* 456 MHz */
+	{ 12000000, 456000000,  456,  12, 1, 12},
+	{ 13000000, 456000000,  456,  13, 1, 12},
+	{ 19200000, 456000000,  380,  16, 1, 8},
+	{ 26000000, 456000000,  456,  26, 1, 12},
+
+	/* 312 MHz */
+	{ 12000000, 312000000,  312,  12, 1, 12},
+	{ 13000000, 312000000,  312,  13, 1, 12},
+	{ 19200000, 312000000,  260,  16, 1, 8},
+	{ 26000000, 312000000,  312,  26, 1, 12},
+
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
+	{ 12000000, 480000000, 960, 12, 2, 0},
+	{ 13000000, 480000000, 960, 13, 2, 0},
+	{ 19200000, 480000000, 200, 4,  2, 0},
+	{ 26000000, 480000000, 960, 26, 2, 0},
+	{ 0, 0, 0, 0, 0, 0 },
+};
+
+/* PLL parameters */
+static struct tegra_clk_pll_params pll_c_params = {
+	.input_min = 2000000,
+	.input_max = 31000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 20000000,
+	.vco_max = 1400000000,
+	.base_reg = CRC_PLLC_BASE,
+	.misc_reg = CRC_PLLC_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLL_MISC_LOCK_ENABLE,
+	.lock_delay = 300,
+};
+
+static struct tegra_clk_pll_params pll_p_params = {
+	.input_min = 2000000,
+	.input_max = 31000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 20000000,
+	.vco_max = 1400000000,
+	.base_reg = CRC_PLLP_BASE,
+	.misc_reg = CRC_PLLP_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLL_MISC_LOCK_ENABLE,
+	.lock_delay = 300,
+};
+
+static struct tegra_clk_pll_params pll_m_params = {
+	.input_min = 2000000,
+	.input_max = 31000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 20000000,
+	.vco_max = 1200000000,
+	.base_reg = CRC_PLLM_BASE,
+	.misc_reg = CRC_PLLM_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLL_MISC_LOCK_ENABLE,
+	.lock_delay = 300,
+};
+
+static struct tegra_clk_pll_params pll_x_params = {
+	.input_min = 2000000,
+	.input_max = 31000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 20000000,
+	.vco_max = 1200000000,
+	.base_reg = CRC_PLLX_BASE,
+	.misc_reg = CRC_PLLX_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLL_MISC_LOCK_ENABLE,
+	.lock_delay = 300,
+};
+
+static struct tegra_clk_pll_params pll_u_params = {
+	.input_min = 2000000,
+	.input_max = 40000000,
+	.cf_min = 1000000,
+	.cf_max = 6000000,
+	.vco_min = 48000000,
+	.vco_max = 960000000,
+	.base_reg = CRC_PLLU_BASE,
+	.misc_reg = CRC_PLLU_MISC,
+	.lock_bit_idx = CRC_PLL_BASE_LOCK,
+	.lock_enable_bit_idx = CRC_PLLDU_MISC_LOCK_ENABLE,
+	.lock_delay = 1000,
+};
+
+static void tegra20_pll_init(void)
+{
+	/* PLLC */
+	clks[pll_c] = tegra_clk_register_pll("pll_c", "pll_ref", car_base,
+			0, 0, &pll_c_params, TEGRA_PLL_HAS_CPCON,
+			pll_c_freq_table);
+
+	clks[pll_c_out1] = tegra_clk_register_pll_out("pll_c_out1", "pll_c",
+			car_base + CRC_PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP);
+
+	/* PLLP */
+	clks[pll_p] = tegra_clk_register_pll("pll_p", "pll_ref", car_base,
+			0, 216000000, &pll_p_params, TEGRA_PLL_FIXED |
+			TEGRA_PLL_HAS_CPCON, pll_p_freq_table);
+
+	clks[pll_p_out1] = tegra_clk_register_pll_out("pll_p_out1", "pll_p",
+			car_base + CRC_PLLP_OUTA, 0,
+			TEGRA_DIVIDER_FIXED | TEGRA_DIVIDER_ROUND_UP);
+
+	clks[pll_p_out2] = tegra_clk_register_pll_out("pll_p_out2", "pll_p",
+			car_base + CRC_PLLP_OUTA, 16,
+			TEGRA_DIVIDER_FIXED | TEGRA_DIVIDER_ROUND_UP);
+
+	clks[pll_p_out3] = tegra_clk_register_pll_out("pll_p_out3", "pll_p",
+			car_base + CRC_PLLP_OUTB, 0,
+			TEGRA_DIVIDER_FIXED | TEGRA_DIVIDER_ROUND_UP);
+
+	clks[pll_p_out4] = tegra_clk_register_pll_out("pll_p_out4", "pll_p",
+			car_base + CRC_PLLP_OUTB, 16,
+			TEGRA_DIVIDER_FIXED | TEGRA_DIVIDER_ROUND_UP);
+
+	/* PLLM */
+	clks[pll_m] = tegra_clk_register_pll("pll_m", "pll_ref", car_base,
+			0, 0, &pll_m_params, TEGRA_PLL_HAS_CPCON,
+			pll_m_freq_table);
+
+	clks[pll_m_out1] = tegra_clk_register_pll_out("pll_m_out1", "pll_m",
+			car_base + CRC_PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP);
+
+	/* PLLX */
+	clks[pll_x] = tegra_clk_register_pll("pll_x", "pll_ref", car_base,
+			0, 0, &pll_x_params, TEGRA_PLL_HAS_CPCON,
+			pll_x_freq_table);
+
+	/* PLLU */
+	clks[pll_u] = tegra_clk_register_pll("pll_u", "pll_ref", car_base,
+			0, 0, &pll_u_params, TEGRA_PLLU |
+			TEGRA_PLL_HAS_CPCON, pll_u_freq_table);
+}
+
+static struct tegra_clk_init_table init_table[] = {
+	{pll_p,		clk_max,	216000000,	1},
+	{pll_p_out1,	clk_max,	28800000,	1},
+	{pll_p_out2,	clk_max,	48000000,	1},
+	{pll_p_out3,	clk_max,	72000000,	1},
+	{pll_p_out4,	clk_max,	24000000,	1},
+	{pll_c,		clk_max,	600000000,	1},
+	{pll_c_out1,	clk_max,	120000000,	1},
+	{clk_max,	clk_max,	0,		0}, /* sentinel */
+};
+
+static int tegra20_car_probe(struct device_d *dev)
+{
+	car_base = dev_request_mem_region(dev, 0);
+	if (!car_base)
+		return -EBUSY;
+
+	tegra20_osc_clk_init();
+	tegra20_pll_init();
+
+	tegra_init_from_table(init_table, clks, clk_max);
+
+	clk_data.clks = clks;
+	clk_data.clk_num = ARRAY_SIZE(clks);
+	of_clk_add_provider(dev->device_node, of_clk_src_onecell_get,
+			    &clk_data);
+
+	return 0;
+}
+
+static __maybe_unused struct of_device_id tegra20_car_dt_ids[] = {
+	{
+		.compatible = "nvidia,tegra20-car",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d tegra20_car_driver = {
+	.probe	= tegra20_car_probe,
+	.name	= "tegra20-car",
+	.of_compatible = DRV_OF_COMPAT(tegra20_car_dt_ids),
+};
+
+static int tegra20_car_init(void)
+{
+	return platform_driver_register(&tegra20_car_driver);
+}
+postcore_initcall(tegra20_car_init);
diff --git a/drivers/clk/tegra/clk.c b/drivers/clk/tegra/clk.c
new file mode 100644
index 0000000..f4013e7
--- /dev/null
+++ b/drivers/clk/tegra/clk.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common.h>
+#include <linux/clk.h>
+
+#include "clk.h"
+
+void tegra_init_from_table(struct tegra_clk_init_table *tbl,
+				  struct clk *clks[], int clk_max)
+{
+	struct clk *clk;
+
+	for (; tbl->clk_id < clk_max; tbl++) {
+		clk = clks[tbl->clk_id];
+		if (!clk)
+			return;
+
+		if (tbl->parent_id < clk_max) {
+			struct clk *parent = clks[tbl->parent_id];
+			if (clk_set_parent(clk, parent)) {
+				pr_err("%s: Failed to set parent %s of %s\n",
+				       __func__, parent->name, clk->name);
+				WARN_ON(1);
+			}
+		}
+
+		if (tbl->rate)
+			if (clk_set_rate(clk, tbl->rate)) {
+				pr_err("%s: Failed to set rate %lu of %s\n",
+				       __func__, tbl->rate, clk->name);
+				WARN_ON(1);
+			}
+
+		if (tbl->state)
+			if (clk_enable(clk)) {
+				pr_err("%s: Failed to enable %s\n", __func__,
+				       clk->name);
+				WARN_ON(1);
+			}
+	}
+}
diff --git a/drivers/clk/tegra/clk.h b/drivers/clk/tegra/clk.h
new file mode 100644
index 0000000..2bc3698
--- /dev/null
+++ b/drivers/clk/tegra/clk.h
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2013 Lucas Stach <l.stach at pengutronix.de>
+ *
+ * Based on the Linux Tegra clock code
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/* struct tegra_clk_frac_div - fractional divider */
+struct tegra_clk_frac_div {
+	struct clk	hw;
+	void __iomem	*reg;
+	u8		flags;
+	u8		shift;
+	u8		width;
+	u8		frac_width;
+	const char	*parent;
+};
+
+#define TEGRA_DIVIDER_ROUND_UP	BIT(0)
+#define TEGRA_DIVIDER_FIXED	BIT(1)
+#define TEGRA_DIVIDER_INT	BIT(2)
+#define TEGRA_DIVIDER_UART	BIT(3)
+
+struct clk *tegra_clk_divider_alloc(const char *name, const char *parent_name,
+		void __iomem *reg, unsigned long flags, u8 clk_divider_flags,
+		u8 shift, u8 width, u8 frac_width);
+
+void tegra_clk_divider_free(struct clk *divider);
+
+struct clk *tegra_clk_register_divider(const char *name,
+		const char *parent_name, void __iomem *reg, unsigned long flags,
+		u8 clk_divider_flags, u8 shift, u8 width, u8 frac_width);
+
+/* struct tegra_clk_pll_freq_table - PLL frequecy table */
+struct tegra_clk_pll_freq_table {
+	unsigned long	input_rate;
+	unsigned long	output_rate;
+	u16		n;
+	u16		m;
+	u8		p;
+	u8		cpcon;
+};
+
+/* struct clk_pll_params - PLL parameters */
+struct tegra_clk_pll_params {
+	unsigned long	input_min;
+	unsigned long	input_max;
+	unsigned long	cf_min;
+	unsigned long	cf_max;
+	unsigned long	vco_min;
+	unsigned long	vco_max;
+
+	u32		base_reg;
+	u32		misc_reg;
+	u32		lock_reg;
+	u8		lock_bit_idx;
+	u8		lock_enable_bit_idx;
+	int		lock_delay;
+};
+
+/* struct tegra_clk_pll - Tegra PLL clock */
+struct tegra_clk_pll {
+	struct clk	hw;
+	void __iomem	*clk_base;
+	u8		flags;
+	unsigned long	fixed_rate;
+	u8		divn_shift;
+	u8		divn_width;
+	u8		divm_shift;
+	u8		divm_width;
+	u8		divp_shift;
+	u8		divp_width;
+	struct tegra_clk_pll_freq_table	*freq_table;
+	struct tegra_clk_pll_params	*params;
+	const char	*parent;
+};
+
+#define TEGRA_PLL_USE_LOCK	BIT(0)
+#define TEGRA_PLL_HAS_CPCON	BIT(1)
+#define TEGRA_PLL_SET_LFCON	BIT(2)
+#define TEGRA_PLL_SET_DCCON	BIT(3)
+#define TEGRA_PLLU		BIT(4)
+#define TEGRA_PLLM		BIT(5)
+#define TEGRA_PLL_FIXED		BIT(6)
+#define TEGRA_PLLE_CONFIGURE	BIT(7)
+
+struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
+		void __iomem *clk_base,
+		unsigned long flags, unsigned long fixed_rate,
+		struct tegra_clk_pll_params *pll_params, u8 pll_flags,
+		struct tegra_clk_pll_freq_table *freq_table);
+
+/* struct tegra_clk_pll_out - PLL output divider */
+struct tegra_clk_pll_out {
+	struct clk	hw;
+	struct clk	*div;
+	void __iomem	*reg;
+	u8		enb_bit_idx;
+	u8		rst_bit_idx;
+	const char	*parent;
+};
+
+struct clk *tegra_clk_register_pll_out(const char *name,
+		const char *parent_name, void __iomem *reg, u8 shift,
+		u8 divider_flags);
+
+/* struct clk_init_table - clock initialization table */
+struct tegra_clk_init_table {
+	unsigned int	clk_id;
+	unsigned int	parent_id;
+	unsigned long	rate;
+	int		state;
+};
+
+void tegra_init_from_table(struct tegra_clk_init_table *tbl,
+		struct clk *clks[], int clk_max);
-- 
1.8.3.1



