All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 00/10] IDE code cleanup
@ 2012-10-07 15:56 Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 01/10] remove CONFIG_SC3 from cmd_ide.c Pavel Herrmann
                   ` (10 more replies)
  0 siblings, 11 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

This series tries to remove all SoC-specific and board-specific code from
cmd_ide. Whenever an existing hook is present, it is used instead, when no
appropriate hook is present, one is created (either as a hook call or by
using the weak alias technique). The aim of this series is to prepare for
DM conversion, where most of the cmd_ide code will create a new universal
IDE driver, and all hooks and overrides will be provided in its platform data.

note: this series has not been tested on the actual hardware


Pavel Herrmann (10):
  remove CONFIG_SC3 from cmd_ide.c
  split mpc8xx hooks from cmd_ide.c
  split IVM power hooks from cmd_ide.c
  change all versions of input_data() and output_data() to global weak
    aliases
  split CPC45 board-specific IDE functions from cmd_ide.c
  make ide_led() a weak alias
  move CPC45 ide_led to the same file as other IDE hooks
  split AU1X00 specific code from cmd_ide.c
  split PCS440EP specific code from cmd_ide.c
  remove unnecessary includes from cmd_ide.c

 arch/mips/cpu/mips32/au1x00/Makefile     |   2 +-
 arch/mips/cpu/mips32/au1x00/au1x00_ide.c |  33 +++
 arch/powerpc/lib/Makefile                |   1 +
 arch/powerpc/lib/ide.c                   | 207 +++++++++++++
 arch/powerpc/lib/ide.h                   |  31 ++
 board/cpc45/Makefile                     |   2 +-
 board/cpc45/cpc45.c                      |  15 -
 board/cpc45/ide.c                        | 145 +++++++++
 board/esd/cpci750/ide.c                  |   1 -
 board/ivm/ivm.c                          |  46 +++
 board/linkstation/ide.c                  |   1 -
 board/pcs440ep/pcs440ep.c                |  57 +++-
 common/cmd_ide.c                         | 484 +++++--------------------------
 include/configs/CPC45.h                  |   1 +
 include/configs/ICU862.h                 |   1 +
 include/configs/IVML24.h                 |   2 +
 include/configs/IVMS8.h                  |   2 +
 include/configs/KUP4K.h                  |   1 +
 include/configs/KUP4X.h                  |   1 +
 include/configs/MBX.h                    |   1 +
 include/configs/NETTA.h                  |   1 +
 include/configs/NSCU.h                   |   1 +
 include/configs/R360MPI.h                |   1 +
 include/configs/RPXClassic.h             |   1 +
 include/configs/RPXlite.h                |   1 +
 include/configs/RPXlite_DW.h             |   1 +
 include/configs/RRvision.h               |   1 +
 include/configs/SPD823TS.h               |   2 +
 include/configs/TK885D.h                 |   1 +
 include/configs/TQM823L.h                |   1 +
 include/configs/TQM823M.h                |   1 +
 include/configs/TQM850L.h                |   1 +
 include/configs/TQM850M.h                |   1 +
 include/configs/TQM855L.h                |   1 +
 include/configs/TQM855M.h                |   1 +
 include/configs/TQM860L.h                |   1 +
 include/configs/TQM860M.h                |   1 +
 include/configs/TQM862L.h                |   1 +
 include/configs/TQM862M.h                |   1 +
 include/configs/TQM866M.h                |   1 +
 include/configs/TQM885D.h                |   1 +
 include/configs/atc.h                    |   1 +
 include/configs/c2mon.h                  |   1 +
 include/configs/lwmon.h                  |   1 +
 include/configs/quantum.h                |   1 +
 include/configs/svm_sc8xx.h              |   2 +
 include/configs/uc100.h                  |   1 +
 include/configs/virtlab2.h               |   1 +
 include/ide.h                            |  19 ++
 49 files changed, 650 insertions(+), 433 deletions(-)
 create mode 100644 arch/mips/cpu/mips32/au1x00/au1x00_ide.c
 create mode 100644 arch/powerpc/lib/ide.c
 create mode 100644 arch/powerpc/lib/ide.h
 create mode 100644 board/cpc45/ide.c

-- 
1.7.12

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

* [U-Boot] [PATCH 01/10] remove CONFIG_SC3 from cmd_ide.c
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-17 15:02   ` [U-Boot] [U-Boot,01/10] " Tom Rini
  2012-10-07 15:56 ` [U-Boot] [PATCH 02/10] split mpc8xx hooks " Pavel Herrmann
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

There is no difference in codepath with CONFIG_SC3 enabled, so just remove it

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 common/cmd_ide.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 6e1e568..4b94e23 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -400,9 +400,6 @@ void ide_init(void)
 	unsigned char c;
 	int i, bus;
 
-#if defined(CONFIG_SC3)
-	unsigned int ata_reset_time = ATA_RESET_TIME;
-#endif
 #ifdef CONFIG_IDE_8xx_PCCARD
 	extern int pcmcia_on(void);
 	extern int ide_devices_found;	/* Initialized in check_ide_device() */
@@ -502,11 +499,7 @@ void ide_init(void)
 
 			c = ide_inb(dev, ATA_STATUS);
 			i++;
-#if defined(CONFIG_SC3)
-			if (i > (ata_reset_time * 100)) {
-#else
 			if (i > (ATA_RESET_TIME * 100)) {
-#endif
 				puts("** Timeout **\n");
 				/* LED's off */
 				ide_led((LED_IDE1 | LED_IDE2), 0);
-- 
1.7.12

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

* [U-Boot] [PATCH 02/10] split mpc8xx hooks from cmd_ide.c
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 01/10] remove CONFIG_SC3 from cmd_ide.c Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-07 18:09   ` Marek Vasut
                     ` (2 more replies)
  2012-10-07 15:56 ` [U-Boot] [PATCH 03/10] split IVM power " Pavel Herrmann
                   ` (8 subsequent siblings)
  10 siblings, 3 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

move most of mpc8xx hooks from cmd_ide.c into ide_preinit() and newly created
ide_init_postreset() (invoked after calling ide_reset after ide_preinit),
some cleanup to make checkpatch happy, enable IDE init hooks in configs of
affected boards.
Confusingly, these hooks are used by more than just mpc8xx-based boards, and
therefore are placed in arch/ppc/lib/

note: checkpatch still emits warnings about using volatile

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 arch/powerpc/lib/Makefile    |   1 +
 arch/powerpc/lib/ide.c       | 207 +++++++++++++++++++++++++++++++++++++++++++
 arch/powerpc/lib/ide.h       |  31 +++++++
 common/cmd_ide.c             | 190 ++-------------------------------------
 include/configs/CPC45.h      |   1 +
 include/configs/ICU862.h     |   1 +
 include/configs/IVML24.h     |   2 +
 include/configs/IVMS8.h      |   2 +
 include/configs/KUP4K.h      |   1 +
 include/configs/KUP4X.h      |   1 +
 include/configs/MBX.h        |   1 +
 include/configs/NETTA.h      |   1 +
 include/configs/NSCU.h       |   1 +
 include/configs/R360MPI.h    |   1 +
 include/configs/RPXClassic.h |   1 +
 include/configs/RPXlite.h    |   1 +
 include/configs/RPXlite_DW.h |   1 +
 include/configs/RRvision.h   |   1 +
 include/configs/SPD823TS.h   |   2 +
 include/configs/TK885D.h     |   1 +
 include/configs/TQM823L.h    |   1 +
 include/configs/TQM823M.h    |   1 +
 include/configs/TQM850L.h    |   1 +
 include/configs/TQM850M.h    |   1 +
 include/configs/TQM855L.h    |   1 +
 include/configs/TQM855M.h    |   1 +
 include/configs/TQM860L.h    |   1 +
 include/configs/TQM860M.h    |   1 +
 include/configs/TQM862L.h    |   1 +
 include/configs/TQM862M.h    |   1 +
 include/configs/TQM866M.h    |   1 +
 include/configs/TQM885D.h    |   1 +
 include/configs/atc.h        |   1 +
 include/configs/c2mon.h      |   1 +
 include/configs/lwmon.h      |   1 +
 include/configs/quantum.h    |   1 +
 include/configs/svm_sc8xx.h  |   2 +
 include/configs/uc100.h      |   1 +
 include/configs/virtlab2.h   |   1 +
 include/ide.h                |   8 ++
 40 files changed, 293 insertions(+), 183 deletions(-)
 create mode 100644 arch/powerpc/lib/ide.c
 create mode 100644 arch/powerpc/lib/ide.h

diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 965f9ea..808021c 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -50,6 +50,7 @@ COBJS-y	+= cache.o
 COBJS-y	+= extable.o
 COBJS-y	+= interrupts.o
 COBJS-$(CONFIG_CMD_KGDB) += kgdb.o
+COBJS-${CONFIG_CMD_IDE} += ide.o
 COBJS-y	+= time.o
 
 # Workaround for local bus unaligned access problems
diff --git a/arch/powerpc/lib/ide.c b/arch/powerpc/lib/ide.c
new file mode 100644
index 0000000..5319eb1
--- /dev/null
+++ b/arch/powerpc/lib/ide.c
@@ -0,0 +1,207 @@
+/*
+ * (C) Copyright 2000-2011
+ * 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.
+ *
+ * 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
+ *
+ */
+
+/* Code taken from cmd_ide.c */
+#include <common.h>
+#include <ata.h>
+#include "ide.h"
+
+#ifdef CONFIG_IDE_8xx_DIRECT
+#include <mpc8xx.h>
+#include <pcmcia.h>
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Timings for IDE Interface
+ *
+ * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk
+ * 70	   165	    30	   PIO-Mode 0, [ns]
+ *  4	     9	     2		       [Cycles]
+ * 50	   125	    20	   PIO-Mode 1, [ns]
+ *  3	     7	     2		       [Cycles]
+ * 30	   100	    15	   PIO-Mode 2, [ns]
+ *  2	     6	     1		       [Cycles]
+ * 30	    80	    10	   PIO-Mode 3, [ns]
+ *  2	     5	     1		       [Cycles]
+ * 25	    70	    10	   PIO-Mode 4, [ns]
+ *  2	     4	     1		       [Cycles]
+ */
+
+static const pio_config_t pio_config_ns[IDE_MAX_PIO_MODE+1] = {
+    /*  Setup  Length  Hold  */
+	{ 70,	165,	30 },		/* PIO-Mode 0, [ns]	*/
+	{ 50,	125,	20 },		/* PIO-Mode 1, [ns]	*/
+	{ 30,	101,	15 },		/* PIO-Mode 2, [ns]	*/
+	{ 30,	 80,	10 },		/* PIO-Mode 3, [ns]	*/
+	{ 25,	 70,	10 },		/* PIO-Mode 4, [ns]	*/
+};
+
+static pio_config_t pio_config_clk[IDE_MAX_PIO_MODE+1];
+
+#ifndef CONFIG_SYS_PIO_MODE
+#define CONFIG_SYS_PIO_MODE	0	/* use a relaxed default */
+#endif
+static int pio_mode = CONFIG_SYS_PIO_MODE;
+
+/* Make clock cycles and always round up */
+
+#define PCMCIA_MK_CLKS(t, T) (((t) * (T) + 999U) / 1000U)
+
+static void set_pcmcia_timing(int pmode)
+{
+	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
+	volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
+	ulong timings;
+
+	debug("Set timing for PIO Mode %d\n", pmode);
+
+	timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold)
+		| PCMCIA_SST(pio_config_clk[pmode].t_setup)
+		| PCMCIA_SL(pio_config_clk[pmode].t_length);
+
+	/*
+	 * IDE 0
+	 */
+	pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0;
+#if (CONFIG_SYS_PCMCIA_POR0 != 0)
+	pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0 | timings;
+#else
+	pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0;
+#endif
+	debug("PBR0: %08x  POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0);
+
+	pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1;
+#if (CONFIG_SYS_PCMCIA_POR1 != 0)
+	pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1 | timings;
+#else
+	pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1;
+#endif
+	debug("PBR1: %08x  POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1);
+
+	pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2;
+#if (CONFIG_SYS_PCMCIA_POR2 != 0)
+	pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2 | timings;
+#else
+	pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2;
+#endif
+	debug("PBR2: %08x  POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2);
+
+	pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3;
+#if (CONFIG_SYS_PCMCIA_POR3 != 0)
+	pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3 | timings;
+#else
+	pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3;
+#endif
+	debug("PBR3: %08x  POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3);
+
+	/*
+	 * IDE 1
+	 */
+	pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4;
+#if (CONFIG_SYS_PCMCIA_POR4 != 0)
+	pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4 | timings;
+#else
+	pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4;
+#endif
+	debug("PBR4: %08x  POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4);
+
+	pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5;
+#if (CONFIG_SYS_PCMCIA_POR5 != 0)
+	pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5 | timings;
+#else
+	pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5;
+#endif
+	debug("PBR5: %08x  POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5);
+
+	pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6;
+#if (CONFIG_SYS_PCMCIA_POR6 != 0)
+	pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6 | timings;
+#else
+	pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6;
+#endif
+	debug("PBR6: %08x  POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6);
+
+	pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7;
+#if (CONFIG_SYS_PCMCIA_POR7 != 0)
+	pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7 | timings;
+#else
+	pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7;
+#endif
+	debug("PBR7: %08x  POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);
+
+}
+
+
+int ide_preinit(void)
+{
+	int i;
+	/* Initialize PIO timing tables */
+	for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) {
+		pio_config_clk[i].t_setup =
+			PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk);
+		pio_config_clk[i].t_length =
+			PCMCIA_MK_CLKS(pio_config_ns[i].t_length, gd->bus_clk);
+		pio_config_clk[i].t_hold =
+			PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk);
+		debug("PIO Mode %d: setup=%2d ns/%d clk" "  len=%3d ns/%d clk"
+			"  hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup,
+			pio_config_clk[i].t_setup, pio_config_ns[i].t_length,
+			pio_config_clk[i].t_length, pio_config_ns[i].t_hold,
+			pio_config_clk[i].t_hold);
+	}
+
+	return 0;
+}
+
+int ide_init_postreset(void)
+{
+	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
+	volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
+
+	/* PCMCIA / IDE initialization for common mem space */
+	pcmp->pcmc_pgcrb = 0;
+
+	/* start in PIO mode 0 - most relaxed timings */
+	pio_mode = 0;
+	set_pcmcia_timing(pio_mode);
+	return 0;
+}
+#endif /* CONFIG_IDE_8xx_DIRECT */
+
+
+
+#ifdef CONFIG_IDE_8xx_PCCARD
+
+int ide_preinit(void)
+{
+	ide_devices_found = 0;
+	/* initialize the PCMCIA IDE adapter card */
+	pcmcia_on();
+	if (!ide_devices_found)
+		return 1;
+	udelay(1000000);/* 1 s */
+	return 0;
+}
+#endif
+
+
diff --git a/arch/powerpc/lib/ide.h b/arch/powerpc/lib/ide.h
new file mode 100644
index 0000000..9e80702
--- /dev/null
+++ b/arch/powerpc/lib/ide.h
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2012
+ * Pavel Herrmann <morpheus.ibis@gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _MPC8XX_IDE_H_
+#define _MPC8XX_IDE_H_ 1
+
+#ifdef CONFIG_IDE_8xx_PCCARD
+int pcmcia_on(void);
+extern int ide_devices_found;
+#endif
+#endif
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 4b94e23..93a328c 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -53,10 +53,6 @@
 # include <status_led.h>
 #endif
 
-#ifdef CONFIG_IDE_8xx_DIRECT
-DECLARE_GLOBAL_DATA_PTR;
-#endif
-
 #ifdef __PPC__
 # define EIEIO		__asm__ volatile ("eieio")
 # define SYNC		__asm__ volatile ("sync")
@@ -65,45 +61,6 @@ DECLARE_GLOBAL_DATA_PTR;
 # define SYNC		/* nothing */
 #endif
 
-#ifdef CONFIG_IDE_8xx_DIRECT
-/* Timings for IDE Interface
- *
- * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk
- * 70	   165	    30	   PIO-Mode 0, [ns]
- *  4	     9	     2		       [Cycles]
- * 50	   125	    20	   PIO-Mode 1, [ns]
- *  3	     7	     2		       [Cycles]
- * 30	   100	    15	   PIO-Mode 2, [ns]
- *  2	     6	     1		       [Cycles]
- * 30	    80	    10	   PIO-Mode 3, [ns]
- *  2	     5	     1		       [Cycles]
- * 25	    70	    10	   PIO-Mode 4, [ns]
- *  2	     4	     1		       [Cycles]
- */
-
-const static pio_config_t pio_config_ns [IDE_MAX_PIO_MODE+1] =
-{
-    /*	Setup  Length  Hold  */
-	{ 70,	165,	30 },		/* PIO-Mode 0, [ns]	*/
-	{ 50,	125,	20 },		/* PIO-Mode 1, [ns]	*/
-	{ 30,	101,	15 },		/* PIO-Mode 2, [ns]	*/
-	{ 30,	 80,	10 },		/* PIO-Mode 3, [ns]	*/
-	{ 25,	 70,	10 },		/* PIO-Mode 4, [ns]	*/
-};
-
-static pio_config_t pio_config_clk [IDE_MAX_PIO_MODE+1];
-
-#ifndef	CONFIG_SYS_PIO_MODE
-#define	CONFIG_SYS_PIO_MODE	0		/* use a relaxed default */
-#endif
-static int pio_mode = CONFIG_SYS_PIO_MODE;
-
-/* Make clock cycles and always round up */
-
-#define PCMCIA_MK_CLKS( t, T ) (( (t) * (T) + 999U ) / 1000U )
-
-#endif /* CONFIG_IDE_8xx_DIRECT */
-
 /* ------------------------------------------------------------------------- */
 
 /* Current I/O Device	*/
@@ -166,10 +123,6 @@ ulong atapi_read (int device, lbaint_t blknr, ulong blkcnt, void *buffer);
 #endif
 
 
-#ifdef CONFIG_IDE_8xx_DIRECT
-static void set_pcmcia_timing (int pmode);
-#endif
-
 /* ------------------------------------------------------------------------- */
 
 int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
@@ -392,22 +345,14 @@ inline int ide_set_piomode(int pio_mode)
 
 void ide_init(void)
 {
-
-#ifdef CONFIG_IDE_8xx_DIRECT
-	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
-	volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
-#endif
 	unsigned char c;
 	int i, bus;
 
 #ifdef CONFIG_IDE_8xx_PCCARD
-	extern int pcmcia_on(void);
 	extern int ide_devices_found;	/* Initialized in check_ide_device() */
 #endif /* CONFIG_IDE_8xx_PCCARD */
 
 #ifdef CONFIG_IDE_PREINIT
-	extern int ide_preinit(void);
-
 	WATCHDOG_RESET();
 
 	if (ide_preinit()) {
@@ -416,40 +361,8 @@ void ide_init(void)
 	}
 #endif /* CONFIG_IDE_PREINIT */
 
-#ifdef CONFIG_IDE_8xx_PCCARD
-	extern int pcmcia_on(void);
-	extern int ide_devices_found;	/* Initialized in check_ide_device() */
-
 	WATCHDOG_RESET();
 
-	ide_devices_found = 0;
-	/* initialize the PCMCIA IDE adapter card */
-	pcmcia_on();
-	if (!ide_devices_found)
-		return;
-	udelay(1000000);	/* 1 s */
-#endif /* CONFIG_IDE_8xx_PCCARD */
-
-	WATCHDOG_RESET();
-
-#ifdef CONFIG_IDE_8xx_DIRECT
-	/* Initialize PIO timing tables */
-	for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) {
-		pio_config_clk[i].t_setup =
-			PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk);
-		pio_config_clk[i].t_length =
-			PCMCIA_MK_CLKS(pio_config_ns[i].t_length,
-				       gd->bus_clk);
-		pio_config_clk[i].t_hold =
-			PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk);
-		debug("PIO Mode %d: setup=%2d ns/%d clk" "  len=%3d ns/%d clk"
-		      "  hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup,
-		      pio_config_clk[i].t_setup, pio_config_ns[i].t_length,
-		      pio_config_clk[i].t_length, pio_config_ns[i].t_hold,
-		      pio_config_clk[i].t_hold);
-	}
-#endif /* CONFIG_IDE_8xx_DIRECT */
-
 	/*
 	 * Reset the IDE just to be sure.
 	 * Light LED's to show
@@ -459,14 +372,14 @@ void ide_init(void)
 	/* ATAPI Drives seems to need a proper IDE Reset */
 	ide_reset();
 
-#ifdef CONFIG_IDE_8xx_DIRECT
-	/* PCMCIA / IDE initialization for common mem space */
-	pcmp->pcmc_pgcrb = 0;
+#ifdef CONFIG_IDE_INIT_POSTRESET
+	WATCHDOG_RESET();
 
-	/* start in PIO mode 0 - most relaxed timings */
-	pio_mode = 0;
-	set_pcmcia_timing(pio_mode);
-#endif /* CONFIG_IDE_8xx_DIRECT */
+	if (ide_init_postreset()) {
+		puts("ide_preinit_postreset failed\n");
+		return;
+	}
+#endif /* CONFIG_IDE_INIT_POSTRESET */
 
 	/*
 	 * Wait for IDE to get ready.
@@ -568,95 +481,6 @@ block_dev_desc_t *ide_get_dev(int dev)
 }
 #endif
 
-
-#ifdef CONFIG_IDE_8xx_DIRECT
-
-static void set_pcmcia_timing(int pmode)
-{
-	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
-	volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
-	ulong timings;
-
-	debug("Set timing for PIO Mode %d\n", pmode);
-
-	timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold)
-		| PCMCIA_SST(pio_config_clk[pmode].t_setup)
-		| PCMCIA_SL(pio_config_clk[pmode].t_length);
-
-	/*
-	 * IDE 0
-	 */
-	pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0;
-	pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0
-#if (CONFIG_SYS_PCMCIA_POR0 != 0)
-		| timings
-#endif
-		;
-	debug("PBR0: %08x  POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0);
-
-	pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1;
-	pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1
-#if (CONFIG_SYS_PCMCIA_POR1 != 0)
-		| timings
-#endif
-		;
-	debug("PBR1: %08x  POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1);
-
-	pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2;
-	pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2
-#if (CONFIG_SYS_PCMCIA_POR2 != 0)
-		| timings
-#endif
-		;
-	debug("PBR2: %08x  POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2);
-
-	pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3;
-	pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3
-#if (CONFIG_SYS_PCMCIA_POR3 != 0)
-		| timings
-#endif
-		;
-	debug("PBR3: %08x  POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3);
-
-	/*
-	 * IDE 1
-	 */
-	pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4;
-	pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4
-#if (CONFIG_SYS_PCMCIA_POR4 != 0)
-		| timings
-#endif
-		;
-	debug("PBR4: %08x  POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4);
-
-	pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5;
-	pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5
-#if (CONFIG_SYS_PCMCIA_POR5 != 0)
-		| timings
-#endif
-		;
-	debug("PBR5: %08x  POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5);
-
-	pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6;
-	pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6
-#if (CONFIG_SYS_PCMCIA_POR6 != 0)
-		| timings
-#endif
-		;
-	debug("PBR6: %08x  POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6);
-
-	pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7;
-	pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7
-#if (CONFIG_SYS_PCMCIA_POR7 != 0)
-		| timings
-#endif
-		;
-	debug("PBR7: %08x  POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);
-
-}
-
-#endif /* CONFIG_IDE_8xx_DIRECT */
-
 /* ------------------------------------------------------------------------- */
 
 /* We only need to swap data if we are running on a big endian cpu. */
diff --git a/include/configs/CPC45.h b/include/configs/CPC45.h
index fc226f1..e102c36 100644
--- a/include/configs/CPC45.h
+++ b/include/configs/CPC45.h
@@ -480,6 +480,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/ICU862.h b/include/configs/ICU862.h
index 81f219c..b58b6f6 100644
--- a/include/configs/ICU862.h
+++ b/include/configs/ICU862.h
@@ -349,6 +349,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/IVML24.h b/include/configs/IVML24.h
index f98a66b..092fcf0 100644
--- a/include/configs/IVML24.h
+++ b/include/configs/IVML24.h
@@ -318,6 +318,8 @@
  * IDE/ATA stuff
  *-----------------------------------------------------------------------
  */
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
+#define CONFIG_IDE_INIT_POSTRESET	1	/* Use postreset IDE hook */
 #define CONFIG_IDE_8xx_DIRECT	1	/* PCMCIA interface required	*/
 #define CONFIG_IDE_RESET	1	/* reset for ide supported	*/
 
diff --git a/include/configs/IVMS8.h b/include/configs/IVMS8.h
index d6e9b23..38837ca 100644
--- a/include/configs/IVMS8.h
+++ b/include/configs/IVMS8.h
@@ -312,6 +312,8 @@
  * IDE/ATA stuff
  *-----------------------------------------------------------------------
  */
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
+#define CONFIG_IDE_INIT_POSTRESET	1	/* Use postreset IDE hook */
 #define CONFIG_IDE_8xx_DIRECT	1	/* PCMCIA interface required	*/
 #define CONFIG_IDE_RESET	1	/* reset for ide supported	*/
 
diff --git a/include/configs/KUP4K.h b/include/configs/KUP4K.h
index c0035e6..dae9b8c 100644
--- a/include/configs/KUP4K.h
+++ b/include/configs/KUP4K.h
@@ -353,6 +353,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/KUP4X.h b/include/configs/KUP4X.h
index 5084ccc..cceee96 100644
--- a/include/configs/KUP4X.h
+++ b/include/configs/KUP4X.h
@@ -366,6 +366,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/MBX.h b/include/configs/MBX.h
index e8d0cd7..7145cc4 100644
--- a/include/configs/MBX.h
+++ b/include/configs/MBX.h
@@ -276,6 +276,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/NETTA.h b/include/configs/NETTA.h
index 604938d..074e01f 100644
--- a/include/configs/NETTA.h
+++ b/include/configs/NETTA.h
@@ -629,6 +629,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/NSCU.h b/include/configs/NSCU.h
index 9f462f4..f4184fc 100644
--- a/include/configs/NSCU.h
+++ b/include/configs/NSCU.h
@@ -318,6 +318,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/R360MPI.h b/include/configs/R360MPI.h
index 9befacb..868a0b8 100644
--- a/include/configs/R360MPI.h
+++ b/include/configs/R360MPI.h
@@ -329,6 +329,7 @@
  */
 
 #if 1
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/RPXClassic.h b/include/configs/RPXClassic.h
index b215c2d..3595200 100644
--- a/include/configs/RPXClassic.h
+++ b/include/configs/RPXClassic.h
@@ -314,6 +314,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/RPXlite.h b/include/configs/RPXlite.h
index 8ffb014..563abea 100644
--- a/include/configs/RPXlite.h
+++ b/include/configs/RPXlite.h
@@ -249,6 +249,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/RPXlite_DW.h b/include/configs/RPXlite_DW.h
index f8bcf0f..67ab1e9 100644
--- a/include/configs/RPXlite_DW.h
+++ b/include/configs/RPXlite_DW.h
@@ -335,6 +335,7 @@
  * IDE/ATA stuff (Supports IDE harddisk on PCMCIA Adapter)
  *-----------------------------------------------------------------------
  */
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/RRvision.h b/include/configs/RRvision.h
index 671d521..e2b22f0 100644
--- a/include/configs/RRvision.h
+++ b/include/configs/RRvision.h
@@ -329,6 +329,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/SPD823TS.h b/include/configs/SPD823TS.h
index cffeb11..72ea217 100644
--- a/include/configs/SPD823TS.h
+++ b/include/configs/SPD823TS.h
@@ -303,6 +303,8 @@
  * IDE/ATA stuff
  *-----------------------------------------------------------------------
  */
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
+#define CONFIG_IDE_INIT_POSTRESET	1	/* Use postreset IDE hook */
 #define CONFIG_IDE_8xx_DIRECT	1	/* PCMCIA interface required	*/
 #define CONFIG_IDE_LED		1	/* LED   for ide supported	*/
 #define CONFIG_IDE_RESET	1	/* reset for ide supported	*/
diff --git a/include/configs/TK885D.h b/include/configs/TK885D.h
index 4176c7f..623cb66 100644
--- a/include/configs/TK885D.h
+++ b/include/configs/TK885D.h
@@ -343,6 +343,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/TQM823L.h b/include/configs/TQM823L.h
index a01b4a6..9fac5d1 100644
--- a/include/configs/TQM823L.h
+++ b/include/configs/TQM823L.h
@@ -335,6 +335,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM823M.h b/include/configs/TQM823M.h
index 1da4acd..932f158 100644
--- a/include/configs/TQM823M.h
+++ b/include/configs/TQM823M.h
@@ -331,6 +331,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM850L.h b/include/configs/TQM850L.h
index 1c054f0..eb08de2 100644
--- a/include/configs/TQM850L.h
+++ b/include/configs/TQM850L.h
@@ -320,6 +320,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM850M.h b/include/configs/TQM850M.h
index 46066df..bf3a76c 100644
--- a/include/configs/TQM850M.h
+++ b/include/configs/TQM850M.h
@@ -322,6 +322,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM855L.h b/include/configs/TQM855L.h
index dd2da94..43dd643 100644
--- a/include/configs/TQM855L.h
+++ b/include/configs/TQM855L.h
@@ -324,6 +324,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM855M.h b/include/configs/TQM855M.h
index 95bc4d9..e7fd2db 100644
--- a/include/configs/TQM855M.h
+++ b/include/configs/TQM855M.h
@@ -359,6 +359,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM860L.h b/include/configs/TQM860L.h
index 487666c..81e1b91 100644
--- a/include/configs/TQM860L.h
+++ b/include/configs/TQM860L.h
@@ -323,6 +323,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM860M.h b/include/configs/TQM860M.h
index e8b77ea..ed496a1 100644
--- a/include/configs/TQM860M.h
+++ b/include/configs/TQM860M.h
@@ -324,6 +324,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM862L.h b/include/configs/TQM862L.h
index 334b7ec..1559336 100644
--- a/include/configs/TQM862L.h
+++ b/include/configs/TQM862L.h
@@ -327,6 +327,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM862M.h b/include/configs/TQM862M.h
index 1e2ad40..61dcf62 100644
--- a/include/configs/TQM862M.h
+++ b/include/configs/TQM862M.h
@@ -328,6 +328,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM866M.h b/include/configs/TQM866M.h
index a13c16a..7d0ae99 100644
--- a/include/configs/TQM866M.h
+++ b/include/configs/TQM866M.h
@@ -356,6 +356,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/TQM885D.h b/include/configs/TQM885D.h
index 7df76fb..7941631 100644
--- a/include/configs/TQM885D.h
+++ b/include/configs/TQM885D.h
@@ -341,6 +341,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/atc.h b/include/configs/atc.h
index 75f950b..538a167 100644
--- a/include/configs/atc.h
+++ b/include/configs/atc.h
@@ -482,6 +482,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/c2mon.h b/include/configs/c2mon.h
index 566c42b..41ff008 100644
--- a/include/configs/c2mon.h
+++ b/include/configs/c2mon.h
@@ -302,6 +302,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/lwmon.h b/include/configs/lwmon.h
index 1d89176..1856e8d 100644
--- a/include/configs/lwmon.h
+++ b/include/configs/lwmon.h
@@ -495,6 +495,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/quantum.h b/include/configs/quantum.h
index 4f24651..072bd9c 100644
--- a/include/configs/quantum.h
+++ b/include/configs/quantum.h
@@ -317,6 +317,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/svm_sc8xx.h b/include/configs/svm_sc8xx.h
index 91686d6..2b24997 100644
--- a/include/configs/svm_sc8xx.h
+++ b/include/configs/svm_sc8xx.h
@@ -359,6 +359,8 @@
 
 #undef	CONFIG_IDE_8xx_PCCARD		/* Use IDE with PC Card	Adapter	*/
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
+#define CONFIG_IDE_INIT_POSTRESET	1	/* Use postreset IDE hook */
 #define	CONFIG_IDE_8xx_DIRECT	1	/* Direct IDE    not supported	*/
 #undef	CONFIG_IDE_LED			/* LED   for ide not supported	*/
 #undef	CONFIG_IDE_RESET		/* reset for ide not supported	*/
diff --git a/include/configs/uc100.h b/include/configs/uc100.h
index 8c8fb5a..450c98b 100644
--- a/include/configs/uc100.h
+++ b/include/configs/uc100.h
@@ -331,6 +331,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/virtlab2.h b/include/configs/virtlab2.h
index 4bb96cc..c2c0d1d 100644
--- a/include/configs/virtlab2.h
+++ b/include/configs/virtlab2.h
@@ -329,6 +329,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/ide.h b/include/ide.h
index 8ecc9dd..3bae40d 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -54,6 +54,14 @@ void ide_init(void);
 ulong ide_read(int device, lbaint_t blknr, ulong blkcnt, void *buffer);
 ulong ide_write(int device, lbaint_t blknr, ulong blkcnt, const void *buffer);
 
+#ifdef CONFIG_IDE_PREINIT
+int ide_preinit(void);
+#endif
+
+#ifdef CONFIG_IDE_INIT_POSTRESET
+int ide_init_postreset(void);
+#endif
+
 #if defined(CONFIG_OF_IDE_FIXUP)
 int ide_device_present(int dev);
 #endif
-- 
1.7.12

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

* [U-Boot] [PATCH 03/10] split IVM power hooks from cmd_ide.c
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 01/10] remove CONFIG_SC3 from cmd_ide.c Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 02/10] split mpc8xx hooks " Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 04/10] change all versions of input_data() and output_data() to global weak aliases Pavel Herrmann
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

Move power control code from ide_reset() into IVM-specific IDE reset code.

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 board/ivm/ivm.c  | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 common/cmd_ide.c | 48 ------------------------------------------------
 2 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/board/ivm/ivm.c b/board/ivm/ivm.c
index 71d64d4..ab29479 100644
--- a/board/ivm/ivm.c
+++ b/board/ivm/ivm.c
@@ -333,13 +333,59 @@ void show_boot_progress (int status)
 void ide_set_reset (int on)
 {
 	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
+	int i;
 
 	/*
 	 * Configure PC for IDE Reset Pin
 	 */
 	if (on) {		/* assert RESET */
 		immr->im_ioport.iop_pcdat &= ~(CONFIG_SYS_PC_IDE_RESET);
+
+#ifdef CONFIG_SYS_PB_12V_ENABLE
+		/* 12V Enable output OFF */
+		immr->im_cpm.cp_pbdat &= ~(CONFIG_SYS_PB_12V_ENABLE);
+
+		immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_12V_ENABLE);
+		immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_12V_ENABLE);
+		immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_12V_ENABLE;
+
+		/* wait 500 ms for the voltage to stabilize */
+		for (i = 0; i < 500; ++i)
+			udelay(1000);
+#endif /* CONFIG_SYS_PB_12V_ENABLE */
 	} else {		/* release RESET */
+#ifdef CONFIG_SYS_PB_12V_ENABLE
+		/* 12V Enable output ON */
+		immr->im_cpm.cp_pbdat |= CONFIG_SYS_PB_12V_ENABLE;
+#endif /* CONFIG_SYS_PB_12V_ENABLE */
+
+#ifdef CONFIG_SYS_PB_IDE_MOTOR
+		/* configure IDE Motor voltage monitor pin as input */
+		immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_IDE_MOTOR);
+		immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_IDE_MOTOR);
+		immr->im_cpm.cp_pbdir &= ~(CONFIG_SYS_PB_IDE_MOTOR);
+
+/* wait up to 1 s for the motor voltage to stabilize */
+		for (i = 0; i < 1000; ++i) {
+			if ((immr->im_cpm.cp_pbdat
+					& CONFIG_SYS_PB_IDE_MOTOR) != 0)
+				break;
+			udelay(1000);
+		}
+
+		if (i == 1000) {	/* Timeout */
+			printf("\nWarning: 5V for IDE Motor missing\n");
+#ifdef CONFIG_STATUS_LED
+#ifdef STATUS_LED_YELLOW
+			status_led_set(STATUS_LED_YELLOW, STATUS_LED_ON);
+#endif
+#ifdef STATUS_LED_GREEN
+			status_led_set(STATUS_LED_GREEN, STATUS_LED_OFF);
+#endif
+#endif /* CONFIG_STATUS_LED */
+		}
+#endif /* CONFIG_SYS_PB_IDE_MOTOR */
+
 		immr->im_ioport.iop_pcdat |= CONFIG_SYS_PC_IDE_RESET;
 	}
 
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 93a328c..2604809 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -1170,9 +1170,6 @@ extern void ide_set_reset(int idereset);
 
 static void ide_reset(void)
 {
-#if defined(CONFIG_SYS_PB_12V_ENABLE) || defined(CONFIG_SYS_PB_IDE_MOTOR)
-	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
-#endif
 	int i;
 
 	curr_device = -1;
@@ -1188,51 +1185,6 @@ static void ide_reset(void)
 
 	WATCHDOG_RESET();
 
-#ifdef CONFIG_SYS_PB_12V_ENABLE
-	/* 12V Enable output OFF */
-	immr->im_cpm.cp_pbdat &= ~(CONFIG_SYS_PB_12V_ENABLE);
-
-	immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_12V_ENABLE);
-	immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_12V_ENABLE);
-	immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_12V_ENABLE;
-
-	/* wait 500 ms for the voltage to stabilize */
-	for (i = 0; i < 500; ++i)
-		udelay(1000);
-
-	/* 12V Enable output ON */
-	immr->im_cpm.cp_pbdat |= CONFIG_SYS_PB_12V_ENABLE;
-#endif /* CONFIG_SYS_PB_12V_ENABLE */
-
-#ifdef CONFIG_SYS_PB_IDE_MOTOR
-	/* configure IDE Motor voltage monitor pin as input */
-	immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_IDE_MOTOR);
-	immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_IDE_MOTOR);
-	immr->im_cpm.cp_pbdir &= ~(CONFIG_SYS_PB_IDE_MOTOR);
-
-	/* wait up to 1 s for the motor voltage to stabilize */
-	for (i = 0; i < 1000; ++i) {
-		if ((immr->im_cpm.cp_pbdat & CONFIG_SYS_PB_IDE_MOTOR) != 0) {
-			break;
-		}
-		udelay(1000);
-	}
-
-	if (i == 1000) {	/* Timeout */
-		printf("\nWarning: 5V for IDE Motor missing\n");
-#ifdef CONFIG_STATUS_LED
-#ifdef STATUS_LED_YELLOW
-		status_led_set(STATUS_LED_YELLOW, STATUS_LED_ON);
-#endif
-#ifdef STATUS_LED_GREEN
-		status_led_set(STATUS_LED_GREEN, STATUS_LED_OFF);
-#endif
-#endif /* CONFIG_STATUS_LED */
-	}
-#endif /* CONFIG_SYS_PB_IDE_MOTOR */
-
-	WATCHDOG_RESET();
-
 	/* de-assert RESET signal */
 	ide_set_reset(0);
 
-- 
1.7.12

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

* [U-Boot] [PATCH 04/10] change all versions of input_data() and output_data() to global weak aliases
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
                   ` (2 preceding siblings ...)
  2012-10-07 15:56 ` [U-Boot] [PATCH 03/10] split IVM power " Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-07 18:14   ` Marek Vasut
  2012-10-09 17:04   ` [U-Boot] [PATCH v2 " Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 05/10] split CPC45 board-specific IDE functions from cmd_ide.c Pavel Herrmann
                   ` (6 subsequent siblings)
  10 siblings, 2 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

This changes input_data() and friends from static function to global symbols
under weak alias, to enable board specific overrides (and therefore get rid of
board-specific code in cmd_ide.c)
Also declare ide_bus_offset in the header file, so other files can use
ATA_CURR_BASE as well.

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 board/esd/cpci750/ide.c   |  1 -
 board/linkstation/ide.c   |  1 -
 board/pcs440ep/pcs440ep.c |  1 -
 common/cmd_ide.c          | 57 ++++++++++++++++++++++++++++++-----------------
 include/ide.h             | 11 +++++++++
 5 files changed, 48 insertions(+), 23 deletions(-)

diff --git a/board/esd/cpci750/ide.c b/board/esd/cpci750/ide.c
index aa001df..4ef10e7 100644
--- a/board/esd/cpci750/ide.c
+++ b/board/esd/cpci750/ide.c
@@ -30,7 +30,6 @@
 #include <ide.h>
 #include <pci.h>
 
-extern ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS];
 int cpci_hd_type;
 
 int ata_device(int dev)
diff --git a/board/linkstation/ide.c b/board/linkstation/ide.c
index f3e3fce..541c958 100644
--- a/board/linkstation/ide.c
+++ b/board/linkstation/ide.c
@@ -37,7 +37,6 @@
 #define IT8212_PCI_IdeBusSkewCONTROL	0x4c
 #define IT8212_PCI_IdeDrivingCURRENT	0x42
 
-extern ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS];
 extern struct pci_controller hose;
 
 int ide_preinit (void)
diff --git a/board/pcs440ep/pcs440ep.c b/board/pcs440ep/pcs440ep.c
index 746a54c..52da053 100644
--- a/board/pcs440ep/pcs440ep.c
+++ b/board/pcs440ep/pcs440ep.c
@@ -672,7 +672,6 @@ U_BOOT_CMD(
  * ( bus per_addr 20 -30 is connectsd on CF bus A10-A0)
  * These values are shifted
  */
-extern ulong *ide_bus_offset;
 void inline ide_outb(int dev, int port, unsigned char val)
 {
 	debug ("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 2604809..93371fd 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -109,8 +109,6 @@ static uchar ide_wait  (int dev, ulong t);
 
 #define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */
 
-static void input_data(int dev, ulong *sect_buf, int words);
-static void output_data(int dev, const ulong *sect_buf, int words);
 static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
 
 #ifndef CONFIG_SYS_ATA_PORT_ADDR
@@ -483,13 +481,25 @@ block_dev_desc_t *ide_get_dev(int dev)
 
 /* ------------------------------------------------------------------------- */
 
+void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+	__attribute__ ((weak, alias("__ide_input_swap_data")));
+
+void ide_input_data(int dev, ulong *sect_buf, int words)
+	__attribute__ ((weak, alias("__ide_input_data")));
+
+void ide_output_data(int dev, const ulong *sect_buf, int words)
+	__attribute__ ((weak, alias("__ide_output_data")));
+
 /* We only need to swap data if we are running on a big endian cpu. */
 /* But Au1x00 cpu:s already swaps data in big endian mode! */
 #if defined(__LITTLE_ENDIAN) || \
    (defined(CONFIG_SOC_AU1X00) && !defined(CONFIG_GTH2))
-#define input_swap_data(x,y,z) input_data(x,y,z)
+void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
+{
+	ide_input_data(dev, sect_buf, words);
+}
 #else
-static void input_swap_data(int dev, ulong *sect_buf, int words)
+void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 {
 #if defined(CONFIG_CPC45)
 	uchar i;
@@ -532,7 +542,7 @@ static void input_swap_data(int dev, ulong *sect_buf, int words)
 
 
 #if defined(CONFIG_IDE_SWAP_IO)
-static void output_data(int dev, const ulong *sect_buf, int words)
+void __ide_output_data(int dev, const ulong *sect_buf, int words)
 {
 #if defined(CONFIG_CPC45)
 	uchar *dbuf;
@@ -575,7 +585,7 @@ static void output_data(int dev, const ulong *sect_buf, int words)
 #endif
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
-static void output_data(int dev, const ulong *sect_buf, int words)
+void __ide_output_data(int dev, const ulong *sect_buf, int words)
 {
 #if defined(CONFIG_IDE_AHB)
 	ide_write_data(dev, sect_buf, words);
@@ -586,7 +596,7 @@ static void output_data(int dev, const ulong *sect_buf, int words)
 #endif /* CONFIG_IDE_SWAP_IO */
 
 #if defined(CONFIG_IDE_SWAP_IO)
-static void input_data(int dev, ulong *sect_buf, int words)
+void __ide_input_data(int dev, ulong *sect_buf, int words)
 {
 #if defined(CONFIG_CPC45)
 	uchar *dbuf;
@@ -635,7 +645,7 @@ static void input_data(int dev, ulong *sect_buf, int words)
 #endif
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
-static void input_data(int dev, ulong *sect_buf, int words)
+void __ide_input_data(int dev, ulong *sect_buf, int words)
 {
 #if defined(CONFIG_IDE_AHB)
 	ide_read_data(dev, sect_buf, words);
@@ -745,7 +755,7 @@ static void ide_ident(block_dev_desc_t *dev_desc)
 		return;
 #endif
 
-	input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
+	ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
 
 	ident_cpy((unsigned char *) dev_desc->revision, iop.fw_rev,
 		  sizeof(dev_desc->revision));
@@ -1007,7 +1017,7 @@ ulong ide_read(int device, lbaint_t blknr, ulong blkcnt, void *buffer)
 			break;
 		}
 
-		input_data(device, buffer, ATA_SECTORWORDS);
+		ide_input_data(device, buffer, ATA_SECTORWORDS);
 		(void) ide_inb(device, ATA_STATUS);	/* clear IRQ */
 
 		++n;
@@ -1100,7 +1110,7 @@ ulong ide_write(int device, lbaint_t blknr, ulong blkcnt, const void *buffer)
 			goto WR_OUT;
 		}
 
-		output_data(device, buffer, ATA_SECTORWORDS);
+		ide_output_data(device, buffer, ATA_SECTORWORDS);
 		c = ide_inb(device, ATA_STATUS);	/* clear IRQ */
 		++n;
 		++blknr;
@@ -1233,10 +1243,17 @@ int ide_device_present(int dev)
  * ATAPI Support
  */
 
+void ide_input_data_shorts(int dev, ushort *sect_buf, int words)
+	__attribute__ ((weak, alias("__ide_input_data_shorts")));
+
+void ide_output_data_shorts(int dev, ushort *sect_buf, int words)
+	__attribute__ ((weak, alias("__ide_output_data_shorts")));
+
+
 #if defined(CONFIG_IDE_SWAP_IO)
 /* since ATAPI may use commands with not 4 bytes alligned length
  * we have our own transfer functions, 2 bytes alligned */
-static void output_data_shorts(int dev, ushort *sect_buf, int shorts)
+void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
 #if defined(CONFIG_CPC45)
 	uchar *dbuf;
@@ -1268,7 +1285,7 @@ static void output_data_shorts(int dev, ushort *sect_buf, int shorts)
 #endif
 }
 
-static void input_data_shorts(int dev, ushort *sect_buf, int shorts)
+void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
 #if defined(CONFIG_CPC45)
 	uchar *dbuf;
@@ -1301,12 +1318,12 @@ static void input_data_shorts(int dev, ushort *sect_buf, int shorts)
 }
 
 #else  /* ! CONFIG_IDE_SWAP_IO */
-static void output_data_shorts(int dev, ushort *sect_buf, int shorts)
+void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
 	outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
 }
 
-static void input_data_shorts(int dev, ushort *sect_buf, int shorts)
+void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
 	insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
 }
@@ -1385,7 +1402,7 @@ unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
 	}
 
 	/* write command block */
-	output_data_shorts(device, (unsigned short *) ccb, ccblen / 2);
+	ide_output_data_shorts(device, (unsigned short *) ccb, ccblen / 2);
 
 	/* ATAPI Command written wait for completition */
 	udelay(5000);		/* device must set bsy */
@@ -1436,12 +1453,12 @@ unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
 		/* ok now decide if it is an in or output */
 		if ((ide_inb(device, ATA_SECT_CNT) & 0x02) == 0) {
 			debug("Write to device\n");
-			output_data_shorts(device, (unsigned short *) buffer,
-					   n);
+			ide_output_data_shorts(device,
+				(unsigned short *) buffer, n);
 		} else {
 			debug("Read from device @ %p shorts %d\n", buffer, n);
-			input_data_shorts(device, (unsigned short *) buffer,
-					  n);
+			ide_input_data_shorts(device,
+				(unsigned short *) buffer, n);
 		}
 	}
 	udelay(5000);		/* seems that some CD ROMs need this... */
diff --git a/include/ide.h b/include/ide.h
index 3bae40d..53cd8fb 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -27,6 +27,7 @@
 #define	IDE_BUS(dev)	(dev >> 1)
 
 #define	ATA_CURR_BASE(dev)	(CONFIG_SYS_ATA_BASE_ADDR+ide_bus_offset[IDE_BUS(dev)])
+extern ulong ide_bus_offset[];
 
 #ifdef CONFIG_IDE_LED
 
@@ -72,4 +73,14 @@ void ide_write_register(int dev, unsigned int port, unsigned char val);
 void ide_read_data(int dev, ulong *sect_buf, int words);
 void ide_write_data(int dev, ulong *sect_buf, int words);
 #endif
+
+/*
+ * I/O function overrides
+ */
+void ide_input_swap_data(int dev, ulong *sect_buf, int words);
+void ide_input_data(int dev, ulong *sect_buf, int words);
+void ide_output_data(int dev, const ulong *sect_buf, int words);
+void ide_input_data_shorts(int dev, ushort *sect_buf, int words);
+void ide_output_data_shorts(int dev, ushort *sect_buf, int words);
+
 #endif /* _IDE_H */
-- 
1.7.12

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

* [U-Boot] [PATCH 05/10] split CPC45 board-specific IDE functions from cmd_ide.c
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
                   ` (3 preceding siblings ...)
  2012-10-07 15:56 ` [U-Boot] [PATCH 04/10] change all versions of input_data() and output_data() to global weak aliases Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-07 18:20   ` Marek Vasut
  2012-10-07 15:56 ` [U-Boot] [PATCH 06/10] make ide_led() a weak alias Pavel Herrmann
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

Move input_data() and friends to board/cpc45/ide.c, as overrides for weak
aliases in cmd_ide.c

note: checkpatch emits warnings about using volatile

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 board/cpc45/Makefile |   2 +-
 board/cpc45/ide.c    | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++
 common/cmd_ide.c     |  91 ------------------------------------
 3 files changed, 131 insertions(+), 92 deletions(-)
 create mode 100644 board/cpc45/ide.c

diff --git a/board/cpc45/Makefile b/board/cpc45/Makefile
index 5c6b78f..ac1d174 100644
--- a/board/cpc45/Makefile
+++ b/board/cpc45/Makefile
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(BOARD).o
 
-COBJS	= $(BOARD).o flash.o plx9030.o pd67290.o
+COBJS	= $(BOARD).o flash.o plx9030.o pd67290.o ide.o
 
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS))
diff --git a/board/cpc45/ide.c b/board/cpc45/ide.c
new file mode 100644
index 0000000..7b7237b
--- /dev/null
+++ b/board/cpc45/ide.c
@@ -0,0 +1,130 @@
+/*
+ * (C) Copyright 2001
+ * Rob Taylor, Flying Pig Systems. robt at flyingpig.com.
+ *
+ * (C) Copyright 2000-2011
+ * 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.
+ *
+ * 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 <ide.h>
+#include <ata.h>
+
+#define EIEIO		__asm__ volatile ("eieio")
+#define SYNC		__asm__ volatile ("sync")
+
+void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+{
+	uchar i;
+	volatile uchar *pbuf_even =
+		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
+	volatile uchar *pbuf_odd =
+		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
+	ushort *dbuf = (ushort *) sect_buf;
+
+	while (words--) {
+		for (i = 0; i < 2; i++) {
+			*(((uchar *) (dbuf)) + 1) = *pbuf_even;
+			*(uchar *) dbuf = *pbuf_odd;
+			dbuf += 1;
+		}
+	}
+}
+
+void ide_input_data(int dev, ulong *sect_buf, int words)
+{
+	uchar *dbuf;
+	volatile uchar *pbuf_even;
+	volatile uchar *pbuf_odd;
+
+	pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
+	pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
+	dbuf = (uchar *) sect_buf;
+	while (words--) {
+		*dbuf++ = *pbuf_even;
+		EIEIO;
+		SYNC;
+		*dbuf++ = *pbuf_odd;
+		EIEIO;
+		SYNC;
+		*dbuf++ = *pbuf_even;
+		EIEIO;
+		SYNC;
+		*dbuf++ = *pbuf_odd;
+		EIEIO;
+		SYNC;
+	}
+}
+
+void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
+{
+	uchar *dbuf;
+	volatile uchar *pbuf_even;
+	volatile uchar *pbuf_odd;
+
+	pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
+	pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
+	dbuf = (uchar *) sect_buf;
+	while (shorts--) {
+		EIEIO;
+		*dbuf++ = *pbuf_even;
+		EIEIO;
+		*dbuf++ = *pbuf_odd;
+	}
+}
+
+void ide_output_data(int dev, const ulong *sect_buf, int words)
+{
+	uchar *dbuf;
+	volatile uchar *pbuf_even;
+	volatile uchar *pbuf_odd;
+
+	pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
+	pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
+	dbuf = (uchar *) sect_buf;
+	while (words--) {
+		EIEIO;
+		*pbuf_even = *dbuf++;
+		EIEIO;
+		*pbuf_odd = *dbuf++;
+		EIEIO;
+		*pbuf_even = *dbuf++;
+		EIEIO;
+		*pbuf_odd = *dbuf++;
+	}
+}
+
+void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
+{
+	uchar *dbuf;
+	volatile uchar *pbuf_even;
+	volatile uchar *pbuf_odd;
+
+	pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
+	pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
+	dbuf = (uchar *) sect_buf;
+	while (shorts--) {
+		EIEIO;
+		*pbuf_even = *dbuf++;
+		EIEIO;
+		*pbuf_odd = *dbuf++;
+	}
+}
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 93371fd..89849d5 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -501,22 +501,6 @@ void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 #else
 void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 {
-#if defined(CONFIG_CPC45)
-	uchar i;
-	volatile uchar *pbuf_even =
-		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
-	volatile uchar *pbuf_odd =
-		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
-	ushort *dbuf = (ushort *) sect_buf;
-
-	while (words--) {
-		for (i = 0; i < 2; i++) {
-			*(((uchar *) (dbuf)) + 1) = *pbuf_even;
-			*(uchar *) dbuf = *pbuf_odd;
-			dbuf += 1;
-		}
-	}
-#else
 	volatile ushort *pbuf =
 		(ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
 	ushort *dbuf = (ushort *) sect_buf;
@@ -536,7 +520,6 @@ void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 		*dbuf++ = ld_le16(pbuf);
 #endif /* !MIPS */
 	}
-#endif
 }
 #endif /* __LITTLE_ENDIAN || CONFIG_AU1X00 */
 
@@ -544,25 +527,6 @@ void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 #if defined(CONFIG_IDE_SWAP_IO)
 void __ide_output_data(int dev, const ulong *sect_buf, int words)
 {
-#if defined(CONFIG_CPC45)
-	uchar *dbuf;
-	volatile uchar *pbuf_even;
-	volatile uchar *pbuf_odd;
-
-	pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
-	pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
-	dbuf = (uchar *) sect_buf;
-	while (words--) {
-		EIEIO;
-		*pbuf_even = *dbuf++;
-		EIEIO;
-		*pbuf_odd = *dbuf++;
-		EIEIO;
-		*pbuf_even = *dbuf++;
-		EIEIO;
-		*pbuf_odd = *dbuf++;
-	}
-#else
 	ushort *dbuf;
 	volatile ushort *pbuf;
 
@@ -582,7 +546,6 @@ void __ide_output_data(int dev, const ulong *sect_buf, int words)
 		*pbuf = *dbuf++;
 #endif
 	}
-#endif
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
 void __ide_output_data(int dev, const ulong *sect_buf, int words)
@@ -598,29 +561,6 @@ void __ide_output_data(int dev, const ulong *sect_buf, int words)
 #if defined(CONFIG_IDE_SWAP_IO)
 void __ide_input_data(int dev, ulong *sect_buf, int words)
 {
-#if defined(CONFIG_CPC45)
-	uchar *dbuf;
-	volatile uchar *pbuf_even;
-	volatile uchar *pbuf_odd;
-
-	pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
-	pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
-	dbuf = (uchar *) sect_buf;
-	while (words--) {
-		*dbuf++ = *pbuf_even;
-		EIEIO;
-		SYNC;
-		*dbuf++ = *pbuf_odd;
-		EIEIO;
-		SYNC;
-		*dbuf++ = *pbuf_even;
-		EIEIO;
-		SYNC;
-		*dbuf++ = *pbuf_odd;
-		EIEIO;
-		SYNC;
-	}
-#else
 	ushort *dbuf;
 	volatile ushort *pbuf;
 
@@ -642,7 +582,6 @@ void __ide_input_data(int dev, ulong *sect_buf, int words)
 		*dbuf++ = *pbuf;
 #endif
 	}
-#endif
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
 void __ide_input_data(int dev, ulong *sect_buf, int words)
@@ -1255,20 +1194,6 @@ void ide_output_data_shorts(int dev, ushort *sect_buf, int words)
  * we have our own transfer functions, 2 bytes alligned */
 void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
-#if defined(CONFIG_CPC45)
-	uchar *dbuf;
-	volatile uchar *pbuf_even;
-	volatile uchar *pbuf_odd;
-
-	pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
-	pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
-	while (shorts--) {
-		EIEIO;
-		*pbuf_even = *dbuf++;
-		EIEIO;
-		*pbuf_odd = *dbuf++;
-	}
-#else
 	ushort *dbuf;
 	volatile ushort *pbuf;
 
@@ -1282,25 +1207,10 @@ void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 		EIEIO;
 		*pbuf = *dbuf++;
 	}
-#endif
 }
 
 void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
-#if defined(CONFIG_CPC45)
-	uchar *dbuf;
-	volatile uchar *pbuf_even;
-	volatile uchar *pbuf_odd;
-
-	pbuf_even = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
-	pbuf_odd = (uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
-	while (shorts--) {
-		EIEIO;
-		*dbuf++ = *pbuf_even;
-		EIEIO;
-		*dbuf++ = *pbuf_odd;
-	}
-#else
 	ushort *dbuf;
 	volatile ushort *pbuf;
 
@@ -1314,7 +1224,6 @@ void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 		EIEIO;
 		*dbuf++ = *pbuf;
 	}
-#endif
 }
 
 #else  /* ! CONFIG_IDE_SWAP_IO */
-- 
1.7.12

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

* [U-Boot] [PATCH 06/10] make ide_led() a weak alias
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
                   ` (4 preceding siblings ...)
  2012-10-07 15:56 ` [U-Boot] [PATCH 05/10] split CPC45 board-specific IDE functions from cmd_ide.c Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 07/10] move CPC45 ide_led to the same file as other IDE hooks Pavel Herrmann
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

Make ide_led() a weak alias instead of global/local function/empty macro
based on CONFIG_IDE_LED value and/or board-specific CONFIGs, to get rid of
board-specific code in cmd_ide.c
Define dummy values to get rid of compoler errors in case where ide_led()
used to be an empty macro

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 common/cmd_ide.c | 63 ++++++++++++++++++++++++--------------------------------
 1 file changed, 27 insertions(+), 36 deletions(-)

diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 89849d5..2f3b077 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -81,19 +81,6 @@ static int ide_bus_ok[CONFIG_SYS_IDE_MAXBUS];
 block_dev_desc_t ide_dev_desc[CONFIG_SYS_IDE_MAXDEVICE];
 /* ------------------------------------------------------------------------- */
 
-#ifdef CONFIG_IDE_LED
-# if !defined(CONFIG_BMS2003)	&& \
-     !defined(CONFIG_CPC45)	&& \
-     !defined(CONFIG_KUP4K) && \
-     !defined(CONFIG_KUP4X)
-static void  ide_led   (uchar led, uchar status);
-#else
-extern void  ide_led   (uchar led, uchar status);
-#endif
-#else
-#define ide_led(a,b)	/* dummy */
-#endif
-
 #ifdef CONFIG_IDE_RESET
 static void  ide_reset (void);
 #else
@@ -290,6 +277,33 @@ int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 
 /* ------------------------------------------------------------------------- */
 
+void __ide_led(uchar led, uchar status)
+{
+#if defined(CONFIG_IDE_LED) && defined(PER8_BASE) /* required by LED_PORT */
+	static uchar led_buffer;	/* Buffer for current LED status */
+
+	uchar *led_port = LED_PORT;
+
+	if (status)		/* switch LED on        */
+		led_buffer |= led;
+	else			/* switch LED off       */
+		led_buffer &= ~led;
+
+	*led_port = led_buffer;
+#endif
+}
+
+void ide_led(uchar led, uchar status)
+	__attribute__ ((weak, alias("__ide_led")));
+
+#ifndef CONFIG_IDE_LED	/* define LED macros, they are not used anyways */
+# define DEVICE_LED(x) 0
+# define LED_IDE1 1
+# define LED_IDE2 2
+#endif
+
+/* ------------------------------------------------------------------------- */
+
 inline void __ide_outb(int dev, int port, unsigned char val)
 {
 	debug("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
@@ -442,9 +456,7 @@ void ide_init(void)
 
 	curr_device = -1;
 	for (i = 0; i < CONFIG_SYS_IDE_MAXDEVICE; ++i) {
-#ifdef CONFIG_IDE_LED
 		int led = (IDE_BUS(i) == 0) ? LED_IDE1 : LED_IDE2;
-#endif
 		ide_dev_desc[i].type = DEV_TYPE_UNKNOWN;
 		ide_dev_desc[i].if_type = IF_TYPE_IDE;
 		ide_dev_desc[i].dev = i;
@@ -1146,27 +1158,6 @@ static void ide_reset(void)
 
 /* ------------------------------------------------------------------------- */
 
-#if defined(CONFIG_IDE_LED)	&& \
-   !defined(CONFIG_CPC45)	&& \
-   !defined(CONFIG_KUP4K)	&& \
-   !defined(CONFIG_KUP4X)
-
-static uchar led_buffer;	/* Buffer for current LED status        */
-
-static void ide_led(uchar led, uchar status)
-{
-	uchar *led_port = LED_PORT;
-
-	if (status)		/* switch LED on        */
-		led_buffer |= led;
-	else			/* switch LED off       */
-		led_buffer &= ~led;
-
-	*led_port = led_buffer;
-}
-
-#endif /* CONFIG_IDE_LED */
-
 #if defined(CONFIG_OF_IDE_FIXUP)
 int ide_device_present(int dev)
 {
-- 
1.7.12

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

* [U-Boot] [PATCH 07/10] move CPC45 ide_led to the same file as other IDE hooks
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
                   ` (5 preceding siblings ...)
  2012-10-07 15:56 ` [U-Boot] [PATCH 06/10] make ide_led() a weak alias Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-07 18:21   ` Marek Vasut
  2012-10-09 17:06   ` [U-Boot] [PATCH v2 " Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 08/10] split AU1X00 specific code from cmd_ide.c Pavel Herrmann
                   ` (3 subsequent siblings)
  10 siblings, 2 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

Keep all IDE-related hooks and overrides in a single file, to avoid confusion.

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 board/cpc45/cpc45.c | 15 ---------------
 board/cpc45/ide.c   | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/board/cpc45/cpc45.c b/board/cpc45/cpc45.c
index 1178822..2200806 100644
--- a/board/cpc45/cpc45.c
+++ b/board/cpc45/cpc45.c
@@ -260,21 +260,6 @@ int pcmcia_init(void)
 
 #endif
 
-# ifdef CONFIG_IDE_LED
-void ide_led (uchar led, uchar status)
-{
-	u_char  val;
-	/* We have one PCMCIA slot and use LED H4 for the IDE Interface */
-	val = readb(BCSR_BASE + 0x04);
-	if (status) {				/* led on */
-		val |= B_CTRL_LED0;
-	} else {
-		val &= ~B_CTRL_LED0;
-	}
-	writeb(val, BCSR_BASE + 0x04);
-}
-# endif
-
 int board_eth_init(bd_t *bis)
 {
 	return pci_eth_init(bis);
diff --git a/board/cpc45/ide.c b/board/cpc45/ide.c
index 7b7237b..aafe127 100644
--- a/board/cpc45/ide.c
+++ b/board/cpc45/ide.c
@@ -27,6 +27,7 @@
 #include <common.h>
 #include <ide.h>
 #include <ata.h>
+#include <asm/io.h>
 
 #define EIEIO		__asm__ volatile ("eieio")
 #define SYNC		__asm__ volatile ("sync")
@@ -128,3 +129,17 @@ void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 		*pbuf_odd = *dbuf++;
 	}
 }
+
+void ide_led(uchar led, uchar status)
+{
+	u_char	val;
+	/* We have one PCMCIA slot and use LED H4 for the IDE Interface */
+	val = readb(BCSR_BASE + 0x04);
+	if (status) {				/* led on */
+		val |= B_CTRL_LED0;
+	} else {
+		val &= ~B_CTRL_LED0;
+	}
+	writeb(val, BCSR_BASE + 0x04);
+}
+
-- 
1.7.12

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

* [U-Boot] [PATCH 08/10] split AU1X00 specific code from cmd_ide.c
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
                   ` (6 preceding siblings ...)
  2012-10-07 15:56 ` [U-Boot] [PATCH 07/10] move CPC45 ide_led to the same file as other IDE hooks Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-08 23:38   ` Tom Rini
  2012-10-09 17:10   ` [U-Boot] [PATCH v2 " Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 09/10] split PCS440EP " Pavel Herrmann
                   ` (2 subsequent siblings)
  10 siblings, 2 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

Move special case of ide_swap_read() for AU1X00 SoC into SoC-specific directory.

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 arch/mips/cpu/mips32/au1x00/Makefile     |  2 +-
 arch/mips/cpu/mips32/au1x00/au1x00_ide.c | 33 ++++++++++++++++++++++++++++++++
 common/cmd_ide.c                         |  6 ++----
 3 files changed, 36 insertions(+), 5 deletions(-)
 create mode 100644 arch/mips/cpu/mips32/au1x00/au1x00_ide.c

diff --git a/arch/mips/cpu/mips32/au1x00/Makefile b/arch/mips/cpu/mips32/au1x00/Makefile
index dc58475..b9f895d 100644
--- a/arch/mips/cpu/mips32/au1x00/Makefile
+++ b/arch/mips/cpu/mips32/au1x00/Makefile
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(SOC).o
 
-COBJS	= au1x00_eth.o au1x00_serial.o au1x00_usb_ohci.o
+COBJS	= au1x00_eth.o au1x00_serial.o au1x00_usb_ohci.o au1x00_ide.o
 
 SRCS	:= $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS))
diff --git a/arch/mips/cpu/mips32/au1x00/au1x00_ide.c b/arch/mips/cpu/mips32/au1x00/au1x00_ide.c
new file mode 100644
index 0000000..337dd45
--- /dev/null
+++ b/arch/mips/cpu/mips32/au1x00/au1x00_ide.c
@@ -0,0 +1,33 @@
+/*
+ * (C) Copyright 2000-2011
+ * 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.
+ *
+ * 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 <ide.h>
+
+/* AU1X00 swaps data in big-endian mode, enforce little-endian function */
+#ifndef CONFIG_GTH2 /* GTH2 board behaves as it should */
+void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+{
+	ide_input_data(dev, sect_buf, words);
+}
+
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 2f3b077..7c8f866 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -503,9 +503,7 @@ void ide_output_data(int dev, const ulong *sect_buf, int words)
 	__attribute__ ((weak, alias("__ide_output_data")));
 
 /* We only need to swap data if we are running on a big endian cpu. */
-/* But Au1x00 cpu:s already swaps data in big endian mode! */
-#if defined(__LITTLE_ENDIAN) || \
-   (defined(CONFIG_SOC_AU1X00) && !defined(CONFIG_GTH2))
+#if defined(__LITTLE_ENDIAN)
 void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 {
 	ide_input_data(dev, sect_buf, words);
@@ -533,7 +531,7 @@ void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 #endif /* !MIPS */
 	}
 }
-#endif /* __LITTLE_ENDIAN || CONFIG_AU1X00 */
+#endif /* __LITTLE_ENDIAN */
 
 
 #if defined(CONFIG_IDE_SWAP_IO)
-- 
1.7.12

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

* [U-Boot] [PATCH 09/10] split PCS440EP specific code from cmd_ide.c
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
                   ` (7 preceding siblings ...)
  2012-10-07 15:56 ` [U-Boot] [PATCH 08/10] split AU1X00 specific code from cmd_ide.c Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-07 15:56 ` [U-Boot] [PATCH 10/10] remove unnecessary includes " Pavel Herrmann
  2012-10-07 18:23 ` [U-Boot] [PATCH 00/10] IDE code cleanup Marek Vasut
  10 siblings, 0 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

Move specific ide_input_data and friends to board-specific file.

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 board/pcs440ep/pcs440ep.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
 common/cmd_ide.c          | 18 ---------------
 2 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/board/pcs440ep/pcs440ep.c b/board/pcs440ep/pcs440ep.c
index 52da053..f8345dd 100644
--- a/board/pcs440ep/pcs440ep.c
+++ b/board/pcs440ep/pcs440ep.c
@@ -32,6 +32,7 @@
 #include <sha1.h>
 #include <asm/io.h>
 #include <net.h>
+#include <ata.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -713,3 +714,58 @@ void ide_set_reset (int idereset)
 	udelay (10000);
 }
 #endif /* defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
+
+
+/* this is motly the same as it should, causing a little code duplication */
+#if defined(CONFIG_CMD_IDE)
+#define EIEIO		__asm__ volatile ("eieio")
+
+void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+{
+	volatile ushort *pbuf =
+		(ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+	ushort *dbuf = (ushort *) sect_buf;
+
+	debug("in input swap data base for read is %lx\n",
+		(unsigned long) pbuf);
+
+	while (words--) {
+		*dbuf++ = *pbuf;
+		*dbuf++ = *pbuf;
+	}
+}
+
+void ide_output_data(int dev, const ulong *sect_buf, int words)
+{
+	ushort *dbuf;
+	volatile ushort *pbuf;
+
+	pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+	dbuf = (ushort *) sect_buf;
+	while (words--) {
+		EIEIO;
+		*pbuf = ld_le16(dbuf++);
+		EIEIO;
+		*pbuf = ld_le16(dbuf++);
+	}
+}
+
+void ide_input_data(int dev, ulong *sect_buf, int words)
+{
+	ushort *dbuf;
+	volatile ushort *pbuf;
+
+	pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
+	dbuf = (ushort *) sect_buf;
+
+	debug("in input data base for read is %lx\n", (unsigned long) pbuf);
+
+	while (words--) {
+		EIEIO;
+		*dbuf++ = ld_le16(pbuf);
+		EIEIO;
+		*dbuf++ = ld_le16(pbuf);
+	}
+}
+
+#endif
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 7c8f866..4f3ff54 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -522,9 +522,6 @@ void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 #ifdef __MIPS__
 		*dbuf++ = swab16p((u16 *) pbuf);
 		*dbuf++ = swab16p((u16 *) pbuf);
-#elif defined(CONFIG_PCS440EP)
-		*dbuf++ = *pbuf;
-		*dbuf++ = *pbuf;
 #else
 		*dbuf++ = ld_le16(pbuf);
 		*dbuf++ = ld_le16(pbuf);
@@ -543,18 +540,10 @@ void __ide_output_data(int dev, const ulong *sect_buf, int words)
 	pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
 	dbuf = (ushort *) sect_buf;
 	while (words--) {
-#if defined(CONFIG_PCS440EP)
-		/* not tested, because CF was write protected */
-		EIEIO;
-		*pbuf = ld_le16(dbuf++);
-		EIEIO;
-		*pbuf = ld_le16(dbuf++);
-#else
 		EIEIO;
 		*pbuf = *dbuf++;
 		EIEIO;
 		*pbuf = *dbuf++;
-#endif
 	}
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
@@ -580,17 +569,10 @@ void __ide_input_data(int dev, ulong *sect_buf, int words)
 	debug("in input data base for read is %lx\n", (unsigned long) pbuf);
 
 	while (words--) {
-#if defined(CONFIG_PCS440EP)
-		EIEIO;
-		*dbuf++ = ld_le16(pbuf);
-		EIEIO;
-		*dbuf++ = ld_le16(pbuf);
-#else
 		EIEIO;
 		*dbuf++ = *pbuf;
 		EIEIO;
 		*dbuf++ = *pbuf;
-#endif
 	}
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
-- 
1.7.12

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

* [U-Boot] [PATCH 10/10] remove unnecessary includes from cmd_ide.c
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
                   ` (8 preceding siblings ...)
  2012-10-07 15:56 ` [U-Boot] [PATCH 09/10] split PCS440EP " Pavel Herrmann
@ 2012-10-07 15:56 ` Pavel Herrmann
  2012-10-07 18:23 ` [U-Boot] [PATCH 00/10] IDE code cleanup Marek Vasut
  10 siblings, 0 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-07 15:56 UTC (permalink / raw)
  To: u-boot

mpc8xx and mpc5xxx specific includes in cmd_ide.c are not required, remove them.

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
 common/cmd_ide.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 4f3ff54..891ce21 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -38,14 +38,6 @@
 # include <pcmcia.h>
 #endif
 
-#ifdef CONFIG_8xx
-# include <mpc8xx.h>
-#endif
-
-#ifdef CONFIG_MPC5xxx
-#include <mpc5xxx.h>
-#endif
-
 #include <ide.h>
 #include <ata.h>
 
-- 
1.7.12

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

* [U-Boot] [PATCH 02/10] split mpc8xx hooks from cmd_ide.c
  2012-10-07 15:56 ` [U-Boot] [PATCH 02/10] split mpc8xx hooks " Pavel Herrmann
@ 2012-10-07 18:09   ` Marek Vasut
  2012-10-07 18:09   ` Marek Vasut
  2012-10-09 17:01   ` [U-Boot] [PATCH v2 " Pavel Herrmann
  2 siblings, 0 replies; 28+ messages in thread
From: Marek Vasut @ 2012-10-07 18:09 UTC (permalink / raw)
  To: u-boot

Dear Pavel Herrmann,

> move most of mpc8xx hooks from cmd_ide.c into ide_preinit() and newly
> created ide_init_postreset() (invoked after calling ide_reset after
> ide_preinit), some cleanup to make checkpatch happy, enable IDE init hooks
> in configs of affected boards.
> Confusingly, these hooks are used by more than just mpc8xx-based boards,
> and therefore are placed in arch/ppc/lib/
> 
> note: checkpatch still emits warnings about using volatile
[...]

> +
> +

Too many spaces -- one space too much.

> +int ide_preinit(void)
> +{
> +	int i;
> +	/* Initialize PIO timing tables */
> +	for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) {
> +		pio_config_clk[i].t_setup =
> +			PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk);
> +		pio_config_clk[i].t_length =
> +			PCMCIA_MK_CLKS(pio_config_ns[i].t_length, gd->bus_clk);
> +		pio_config_clk[i].t_hold =
> +			PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk);
> +		debug("PIO Mode %d: setup=%2d ns/%d clk" "  len=%3d ns/%d clk"
> +			"  hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup,
> +			pio_config_clk[i].t_setup, pio_config_ns[i].t_length,
> +			pio_config_clk[i].t_length, pio_config_ns[i].t_hold,
> +			pio_config_clk[i].t_hold);
> +	}
> +
> +	return 0;
> +}
> +
> +int ide_init_postreset(void)
> +{
> +	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
> +	volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
> +
> +	/* PCMCIA / IDE initialization for common mem space */
> +	pcmp->pcmc_pgcrb = 0;
> +
> +	/* start in PIO mode 0 - most relaxed timings */
> +	pio_mode = 0;
> +	set_pcmcia_timing(pio_mode);
> +	return 0;
> +}
> +#endif /* CONFIG_IDE_8xx_DIRECT */
> +
> +
> +

DTTO

> +#ifdef CONFIG_IDE_8xx_PCCARD
> +
> +int ide_preinit(void)
> +{
> +	ide_devices_found = 0;
> +	/* initialize the PCMCIA IDE adapter card */
> +	pcmcia_on();
> +	if (!ide_devices_found)
> +		return 1;
> +	udelay(1000000);/* 1 s */
> +	return 0;
> +}
> +#endif
> +
> +

Trailing newlines

> diff --git a/arch/powerpc/lib/ide.h b/arch/powerpc/lib/ide.h
> new file mode 100644
> index 0000000..9e80702
> --- /dev/null
> +++ b/arch/powerpc/lib/ide.h
> @@ -0,0 +1,31 @@
> +/*
> + * (C) Copyright 2012
> + * Pavel Herrmann <morpheus.ibis@gmail.com>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#ifndef _MPC8XX_IDE_H_
> +#define _MPC8XX_IDE_H_ 1
> +
> +#ifdef CONFIG_IDE_8xx_PCCARD
> +int pcmcia_on(void);
> +extern int ide_devices_found;

Why is this needed? Where was this before ? Is include/pcmcia.h not good?

> +#endif
> +#endif

[...]

> diff --git a/include/configs/ICU862.h b/include/configs/ICU862.h
> index 81f219c..b58b6f6 100644
> --- a/include/configs/ICU862.h
> +++ b/include/configs/ICU862.h
> @@ -349,6 +349,7 @@
>   *-----------------------------------------------------------------------
>   */
> 
> +#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */

Do you need this defined to a particular value or is having this defined enough?

>  #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	

[...]

> diff --git a/include/ide.h b/include/ide.h
> index 8ecc9dd..3bae40d 100644
> --- a/include/ide.h
> +++ b/include/ide.h
> @@ -54,6 +54,14 @@ void ide_init(void);
>  ulong ide_read(int device, lbaint_t blknr, ulong blkcnt, void *buffer);
>  ulong ide_write(int device, lbaint_t blknr, ulong blkcnt, const void
> *buffer);
> 
> +#ifdef CONFIG_IDE_PREINIT
> +int ide_preinit(void);
> +#endif
> +
> +#ifdef CONFIG_IDE_INIT_POSTRESET
> +int ide_init_postreset(void);
> +#endif
> +
>  #if defined(CONFIG_OF_IDE_FIXUP)
>  int ide_device_present(int dev);
>  #endif

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

* [U-Boot] [PATCH 02/10] split mpc8xx hooks from cmd_ide.c
  2012-10-07 15:56 ` [U-Boot] [PATCH 02/10] split mpc8xx hooks " Pavel Herrmann
  2012-10-07 18:09   ` Marek Vasut
@ 2012-10-07 18:09   ` Marek Vasut
  2012-10-09 17:01   ` [U-Boot] [PATCH v2 " Pavel Herrmann
  2 siblings, 0 replies; 28+ messages in thread
From: Marek Vasut @ 2012-10-07 18:09 UTC (permalink / raw)
  To: u-boot

Dear Pavel Herrmann,

> move most of mpc8xx hooks from cmd_ide.c into ide_preinit() and newly
> created ide_init_postreset() (invoked after calling ide_reset after
> ide_preinit), some cleanup to make checkpatch happy, enable IDE init hooks
> in configs of affected boards.
> Confusingly, these hooks are used by more than just mpc8xx-based boards,
> and therefore are placed in arch/ppc/lib/
> 
> note: checkpatch still emits warnings about using volatile
> 
> Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> ---

[...]

> --- a/include/ide.h
> +++ b/include/ide.h
> @@ -54,6 +54,14 @@ void ide_init(void);
>  ulong ide_read(int device, lbaint_t blknr, ulong blkcnt, void *buffer);
>  ulong ide_write(int device, lbaint_t blknr, ulong blkcnt, const void
> *buffer);
> 
> +#ifdef CONFIG_IDE_PREINIT

Is there some documentation for these new config variables?

> +int ide_preinit(void);
> +#endif
> +
> +#ifdef CONFIG_IDE_INIT_POSTRESET
> +int ide_init_postreset(void);
> +#endif
> +
>  #if defined(CONFIG_OF_IDE_FIXUP)
>  int ide_device_present(int dev);
>  #endif

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

* [U-Boot] [PATCH 04/10] change all versions of input_data() and output_data() to global weak aliases
  2012-10-07 15:56 ` [U-Boot] [PATCH 04/10] change all versions of input_data() and output_data() to global weak aliases Pavel Herrmann
@ 2012-10-07 18:14   ` Marek Vasut
  2012-10-09 13:42     ` Pavel Herrmann
  2012-10-09 17:04   ` [U-Boot] [PATCH v2 " Pavel Herrmann
  1 sibling, 1 reply; 28+ messages in thread
From: Marek Vasut @ 2012-10-07 18:14 UTC (permalink / raw)
  To: u-boot

Dear Pavel Herrmann,

> This changes input_data() and friends from static function to global
> symbols under weak alias, to enable board specific overrides (and
> therefore get rid of board-specific code in cmd_ide.c)
> Also declare ide_bus_offset in the header file, so other files can use
> ATA_CURR_BASE as well.
> 
> Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> ---
[...]


> +void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> +	__attribute__ ((weak, alias("__ide_input_swap_data")));

#include <linux/compiler.h>

__weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
{
   ... body ...
}

Works just fine ;-)

[...]

> +/*
> + * I/O function overrides
> + */
> +void ide_input_swap_data(int dev, ulong *sect_buf, int words);
> +void ide_input_data(int dev, ulong *sect_buf, int words);
> +void ide_output_data(int dev, const ulong *sect_buf, int words);
> +void ide_input_data_shorts(int dev, ushort *sect_buf, int words);
> +void ide_output_data_shorts(int dev, ushort *sect_buf, int words);

Shorts ... you mean like pants ? :-p

I'd say it's supposed to be "short", like u16 ;-)

> +
>  #endif /* _IDE_H */

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

* [U-Boot] [PATCH 05/10] split CPC45 board-specific IDE functions from cmd_ide.c
  2012-10-07 15:56 ` [U-Boot] [PATCH 05/10] split CPC45 board-specific IDE functions from cmd_ide.c Pavel Herrmann
@ 2012-10-07 18:20   ` Marek Vasut
  2012-10-09 13:38     ` Pavel Herrmann
  0 siblings, 1 reply; 28+ messages in thread
From: Marek Vasut @ 2012-10-07 18:20 UTC (permalink / raw)
  To: u-boot

Dear Pavel Herrmann,

> Move input_data() and friends to board/cpc45/ide.c, as overrides for weak
> aliases in cmd_ide.c
> 
> note: checkpatch emits warnings about using volatile
> 
> Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> ---
>  board/cpc45/Makefile |   2 +-
>  board/cpc45/ide.c    | 130
> +++++++++++++++++++++++++++++++++++++++++++++++++++ common/cmd_ide.c     |
>  91 ------------------------------------
>  3 files changed, 131 insertions(+), 92 deletions(-)
>  create mode 100644 board/cpc45/ide.c
> 
> diff --git a/board/cpc45/Makefile b/board/cpc45/Makefile
> index 5c6b78f..ac1d174 100644
> --- a/board/cpc45/Makefile
> +++ b/board/cpc45/Makefile
> @@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
> 
>  LIB	= $(obj)lib$(BOARD).o
> 
> -COBJS	= $(BOARD).o flash.o plx9030.o pd67290.o
> +COBJS	= $(BOARD).o flash.o plx9030.o pd67290.o ide.o
> 
>  SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
>  OBJS	:= $(addprefix $(obj),$(COBJS))
> diff --git a/board/cpc45/ide.c b/board/cpc45/ide.c
> new file mode 100644
> index 0000000..7b7237b
> --- /dev/null
> +++ b/board/cpc45/ide.c
> @@ -0,0 +1,130 @@
> +/*
> + * (C) Copyright 2001
> + * Rob Taylor, Flying Pig Systems. robt at flyingpig.com.
> + *
> + * (C) Copyright 2000-2011
> + * 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.
> + *
> + * 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 <ide.h>
> +#include <ata.h>
> +
> +#define EIEIO		__asm__ volatile ("eieio")
> +#define SYNC		__asm__ volatile ("sync")

Make it asm, not __asm__

> +
> +void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> +{
> +	uchar i;
> +	volatile uchar *pbuf_even =
> +		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
> +	volatile uchar *pbuf_odd =
> +		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
> +	ushort *dbuf = (ushort *) sect_buf;

What's this, some kind of __swab16() ?

> +	while (words--) {
> +		for (i = 0; i < 2; i++) {
> +			*(((uchar *) (dbuf)) + 1) = *pbuf_even;
> +			*(uchar *) dbuf = *pbuf_odd;
> +			dbuf += 1;
> +		}
> +	}
> +}
[...]

I'm not reviewing this any further ... this is some ancient code, right?

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

* [U-Boot] [PATCH 07/10] move CPC45 ide_led to the same file as other IDE hooks
  2012-10-07 15:56 ` [U-Boot] [PATCH 07/10] move CPC45 ide_led to the same file as other IDE hooks Pavel Herrmann
@ 2012-10-07 18:21   ` Marek Vasut
  2012-10-09 17:06   ` [U-Boot] [PATCH v2 " Pavel Herrmann
  1 sibling, 0 replies; 28+ messages in thread
From: Marek Vasut @ 2012-10-07 18:21 UTC (permalink / raw)
  To: u-boot

Dear Pavel Herrmann,

> Keep all IDE-related hooks and overrides in a single file, to avoid
> confusion.
> 
> Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> ---
[...]

> +
> +void ide_led(uchar led, uchar status)
> +{
> +	u_char	val;
> +	/* We have one PCMCIA slot and use LED H4 for the IDE Interface */
> +	val = readb(BCSR_BASE + 0x04);
> +	if (status) {				/* led on */
> +		val |= B_CTRL_LED0;
> +	} else {
> +		val &= ~B_CTRL_LED0;
> +	}

Remove these {} for conditions with single line expression

> +	writeb(val, BCSR_BASE + 0x04);
> +}
> +

Best regards,
Marek Vasut

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

* [U-Boot] [PATCH 00/10] IDE code cleanup
  2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
                   ` (9 preceding siblings ...)
  2012-10-07 15:56 ` [U-Boot] [PATCH 10/10] remove unnecessary includes " Pavel Herrmann
@ 2012-10-07 18:23 ` Marek Vasut
  10 siblings, 0 replies; 28+ messages in thread
From: Marek Vasut @ 2012-10-07 18:23 UTC (permalink / raw)
  To: u-boot

Dear Pavel Herrmann,

> This series tries to remove all SoC-specific and board-specific code from
> cmd_ide. Whenever an existing hook is present, it is used instead, when no
> appropriate hook is present, one is created (either as a hook call or by
> using the weak alias technique). The aim of this series is to prepare for
> DM conversion, where most of the cmd_ide code will create a new universal
> IDE driver, and all hooks and overrides will be provided in its platform
> data.
> 
> note: this series has not been tested on the actual hardware
[...]

All in all, it looks mostly good

Best regards,
Marek Vasut

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

* [U-Boot] [PATCH 08/10] split AU1X00 specific code from cmd_ide.c
  2012-10-07 15:56 ` [U-Boot] [PATCH 08/10] split AU1X00 specific code from cmd_ide.c Pavel Herrmann
@ 2012-10-08 23:38   ` Tom Rini
  2012-10-09 13:35     ` Pavel Herrmann
  2012-10-09 17:10   ` [U-Boot] [PATCH v2 " Pavel Herrmann
  1 sibling, 1 reply; 28+ messages in thread
From: Tom Rini @ 2012-10-08 23:38 UTC (permalink / raw)
  To: u-boot

On Sun, Oct 07, 2012 at 05:56:12PM +0200, Pavel Herrmann wrote:

> Move special case of ide_swap_read() for AU1X00 SoC into SoC-specific
> directory.
> 
> Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>

Two problems:

> diff --git a/arch/mips/cpu/mips32/au1x00/au1x00_ide.c b/arch/mips/cpu/mips32/au1x00/au1x00_ide.c
[snip]
> +#ifndef CONFIG_GTH2 /* GTH2 board behaves as it should */
> +void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> +{
> +	ide_input_data(dev, sect_buf, words);
> +}
> +
> diff --git a/common/cmd_ide.c b/common/cmd_ide.c

That won't compile :)

Second, re-base on top of next where the gth2 board is gone, this will
make things simpiler.

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

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

* [U-Boot] [PATCH 08/10] split AU1X00 specific code from cmd_ide.c
  2012-10-08 23:38   ` Tom Rini
@ 2012-10-09 13:35     ` Pavel Herrmann
  0 siblings, 0 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-09 13:35 UTC (permalink / raw)
  To: u-boot

On Monday 08 of October 2012 16:38:46 Tom Rini wrote:
> On Sun, Oct 07, 2012 at 05:56:12PM +0200, Pavel Herrmann wrote:
> > Move special case of ide_swap_read() for AU1X00 SoC into SoC-specific
> > directory.
> > 
> > Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> 
> Two problems:
> > diff --git a/arch/mips/cpu/mips32/au1x00/au1x00_ide.c
> > b/arch/mips/cpu/mips32/au1x00/au1x00_ide.c
> [snip]
> 
> > +#ifndef CONFIG_GTH2 /* GTH2 board behaves as it should */
> > +void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> > +{
> > +	ide_input_data(dev, sect_buf, words);
> > +}
> > +
> > diff --git a/common/cmd_ide.c b/common/cmd_ide.c
> 
> That won't compile :)

sorry, my bad, i only compile tested on ppc, this is missing a header and 
endif

> Second, re-base on top of next where the gth2 board is gone, this will
> make things simpiler.

done, will send V2 after MAKEALL -a powerpc finishes, just to be sure

cheers
Pavel Herrmann

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

* [U-Boot] [PATCH 05/10] split CPC45 board-specific IDE functions from cmd_ide.c
  2012-10-07 18:20   ` Marek Vasut
@ 2012-10-09 13:38     ` Pavel Herrmann
  2012-10-09 17:13       ` Marek Vasut
  0 siblings, 1 reply; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-09 13:38 UTC (permalink / raw)
  To: u-boot

On Sunday 07 of October 2012 20:20:08 Marek Vasut wrote:
> Dear Pavel Herrmann,
> 
> > Move input_data() and friends to board/cpc45/ide.c, as overrides for weak
> > aliases in cmd_ide.c
> > 
> > note: checkpatch emits warnings about using volatile
> > 
> > Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> > ---
> > 
> >  board/cpc45/Makefile |   2 +-
> >  board/cpc45/ide.c    | 130
> > 
> > +++++++++++++++++++++++++++++++++++++++++++++++++++ common/cmd_ide.c     |
> > 
> >  91 ------------------------------------
> >  3 files changed, 131 insertions(+), 92 deletions(-)
> >  create mode 100644 board/cpc45/ide.c
> > 
> > diff --git a/board/cpc45/Makefile b/board/cpc45/Makefile
> > index 5c6b78f..ac1d174 100644
> > --- a/board/cpc45/Makefile
> > +++ b/board/cpc45/Makefile
> > @@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
> > 
> >  LIB	= $(obj)lib$(BOARD).o
> > 
> > -COBJS	= $(BOARD).o flash.o plx9030.o pd67290.o
> > +COBJS	= $(BOARD).o flash.o plx9030.o pd67290.o ide.o
> > 
> >  SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
> >  OBJS	:= $(addprefix $(obj),$(COBJS))
> > 
> > diff --git a/board/cpc45/ide.c b/board/cpc45/ide.c
> > new file mode 100644
> > index 0000000..7b7237b
> > --- /dev/null
> > +++ b/board/cpc45/ide.c
> > @@ -0,0 +1,130 @@
> > +/*
> > + * (C) Copyright 2001
> > + * Rob Taylor, Flying Pig Systems. robt at flyingpig.com.
> > + *
> > + * (C) Copyright 2000-2011
> > + * 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.
> > + *
> > + * 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 <ide.h>
> > +#include <ata.h>
> > +
> > +#define EIEIO		__asm__ volatile ("eieio")
> > +#define SYNC		__asm__ volatile ("sync")
> 
> Make it asm, not __asm__
> 
> > +
> > +void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> > +{
> > +	uchar i;
> > +	volatile uchar *pbuf_even =
> > +		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
> > +	volatile uchar *pbuf_odd =
> > +		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
> > +	ushort *dbuf = (ushort *) sect_buf;
> 
> What's this, some kind of __swab16() ?

more probably this is a hack for strange wiring on the board

> > +	while (words--) {
> > +		for (i = 0; i < 2; i++) {
> > +			*(((uchar *) (dbuf)) + 1) = *pbuf_even;
> > +			*(uchar *) dbuf = *pbuf_odd;
> > +			dbuf += 1;
> > +		}
> > +	}
> > +}
> 
> [...]
> 
> I'm not reviewing this any further ... this is some ancient code, right?

yes, this series is mostly cut-and-paste cleanup of old code, changes were 
made only when checkpatch didnt approve.

Pavel Herrmann

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

* [U-Boot] [PATCH 04/10] change all versions of input_data() and output_data() to global weak aliases
  2012-10-07 18:14   ` Marek Vasut
@ 2012-10-09 13:42     ` Pavel Herrmann
  2012-10-09 17:13       ` Marek Vasut
  0 siblings, 1 reply; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-09 13:42 UTC (permalink / raw)
  To: u-boot

On Sunday 07 of October 2012 20:14:23 Marek Vasut wrote:
> Dear Pavel Herrmann,
> 
> > This changes input_data() and friends from static function to global
> > symbols under weak alias, to enable board specific overrides (and
> > therefore get rid of board-specific code in cmd_ide.c)
> > Also declare ide_bus_offset in the header file, so other files can use
> > ATA_CURR_BASE as well.
> > 
> > Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> > ---
> 
> [...]
> 
> > +void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> > +	__attribute__ ((weak, alias("__ide_input_swap_data")));
> 
> #include <linux/compiler.h>
> 
> __weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> {
>    ... body ...
> }
> 
> Works just fine ;-)
> 
> [...]
> 
> > +/*
> > + * I/O function overrides
> > + */
> > +void ide_input_swap_data(int dev, ulong *sect_buf, int words);
> > +void ide_input_data(int dev, ulong *sect_buf, int words);
> > +void ide_output_data(int dev, const ulong *sect_buf, int words);
> > +void ide_input_data_shorts(int dev, ushort *sect_buf, int words);
> > +void ide_output_data_shorts(int dev, ushort *sect_buf, int words);
> 
> Shorts ... you mean like pants ? :-p
> 
> I'd say it's supposed to be "short", like u16 ;-)

the code says "shorts", as in "multiple of u16", rather than "pants".

Pavel Herrmann

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

* [U-Boot] [PATCH v2 02/10] split mpc8xx hooks from cmd_ide.c
  2012-10-07 15:56 ` [U-Boot] [PATCH 02/10] split mpc8xx hooks " Pavel Herrmann
  2012-10-07 18:09   ` Marek Vasut
  2012-10-07 18:09   ` Marek Vasut
@ 2012-10-09 17:01   ` Pavel Herrmann
  2 siblings, 0 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-09 17:01 UTC (permalink / raw)
  To: u-boot

move most of mpc8xx hooks from cmd_ide.c into ide_preinit() and newly created
ide_init_postreset() (invoked after calling ide_reset after ide_preinit),
some cleanup to make checkpatch happy, enable IDE init hooks in configs of
affected boards.
confusingly, these hooks are used by more than just mpc8xx-based boards, and
therefore are placed in arch/ppc/lib/

note: checkpatch still emits warnings about using volatile

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
Changes for v2:
 style fixes

 arch/powerpc/lib/Makefile    |   1 +
 arch/powerpc/lib/ide.c       | 201 +++++++++++++++++++++++++++++++++++++++++++
 arch/powerpc/lib/ide.h       |  31 +++++++
 common/cmd_ide.c             | 190 ++--------------------------------------
 include/configs/CPC45.h      |   1 +
 include/configs/ICU862.h     |   1 +
 include/configs/IVML24.h     |   2 +
 include/configs/IVMS8.h      |   2 +
 include/configs/KUP4K.h      |   1 +
 include/configs/KUP4X.h      |   1 +
 include/configs/MBX.h        |   1 +
 include/configs/NETTA.h      |   1 +
 include/configs/NSCU.h       |   1 +
 include/configs/R360MPI.h    |   1 +
 include/configs/RPXClassic.h |   1 +
 include/configs/RPXlite.h    |   1 +
 include/configs/RPXlite_DW.h |   1 +
 include/configs/RRvision.h   |   1 +
 include/configs/SPD823TS.h   |   2 +
 include/configs/TK885D.h     |   1 +
 include/configs/TQM823L.h    |   1 +
 include/configs/TQM823M.h    |   1 +
 include/configs/TQM850L.h    |   1 +
 include/configs/TQM850M.h    |   1 +
 include/configs/TQM855L.h    |   1 +
 include/configs/TQM855M.h    |   1 +
 include/configs/TQM860L.h    |   1 +
 include/configs/TQM860M.h    |   1 +
 include/configs/TQM862L.h    |   1 +
 include/configs/TQM862M.h    |   1 +
 include/configs/TQM866M.h    |   1 +
 include/configs/TQM885D.h    |   1 +
 include/configs/atc.h        |   1 +
 include/configs/c2mon.h      |   1 +
 include/configs/lwmon.h      |   1 +
 include/configs/quantum.h    |   1 +
 include/configs/svm_sc8xx.h  |   2 +
 include/configs/uc100.h      |   1 +
 include/configs/virtlab2.h   |   1 +
 include/ide.h                |   8 ++
 40 files changed, 287 insertions(+), 183 deletions(-)
 create mode 100644 arch/powerpc/lib/ide.c
 create mode 100644 arch/powerpc/lib/ide.h

diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile
index 965f9ea..808021c 100644
--- a/arch/powerpc/lib/Makefile
+++ b/arch/powerpc/lib/Makefile
@@ -50,6 +50,7 @@ COBJS-y	+= cache.o
 COBJS-y	+= extable.o
 COBJS-y	+= interrupts.o
 COBJS-$(CONFIG_CMD_KGDB) += kgdb.o
+COBJS-${CONFIG_CMD_IDE} += ide.o
 COBJS-y	+= time.o
 
 # Workaround for local bus unaligned access problems
diff --git a/arch/powerpc/lib/ide.c b/arch/powerpc/lib/ide.c
new file mode 100644
index 0000000..139a94a
--- /dev/null
+++ b/arch/powerpc/lib/ide.c
@@ -0,0 +1,201 @@
+/*
+ * (C) Copyright 2000-2011
+ * 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.
+ *
+ * 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
+ *
+ */
+
+/* Code taken from cmd_ide.c */
+#include <common.h>
+#include <ata.h>
+#include "ide.h"
+
+#ifdef CONFIG_IDE_8xx_DIRECT
+#include <mpc8xx.h>
+#include <pcmcia.h>
+DECLARE_GLOBAL_DATA_PTR;
+
+/* Timings for IDE Interface
+ *
+ * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk
+ * 70	   165	    30	   PIO-Mode 0, [ns]
+ *  4	     9	     2		       [Cycles]
+ * 50	   125	    20	   PIO-Mode 1, [ns]
+ *  3	     7	     2		       [Cycles]
+ * 30	   100	    15	   PIO-Mode 2, [ns]
+ *  2	     6	     1		       [Cycles]
+ * 30	    80	    10	   PIO-Mode 3, [ns]
+ *  2	     5	     1		       [Cycles]
+ * 25	    70	    10	   PIO-Mode 4, [ns]
+ *  2	     4	     1		       [Cycles]
+ */
+
+static const pio_config_t pio_config_ns[IDE_MAX_PIO_MODE+1] = {
+    /*  Setup  Length  Hold  */
+	{ 70,	165,	30 },		/* PIO-Mode 0, [ns]	*/
+	{ 50,	125,	20 },		/* PIO-Mode 1, [ns]	*/
+	{ 30,	101,	15 },		/* PIO-Mode 2, [ns]	*/
+	{ 30,	 80,	10 },		/* PIO-Mode 3, [ns]	*/
+	{ 25,	 70,	10 },		/* PIO-Mode 4, [ns]	*/
+};
+
+static pio_config_t pio_config_clk[IDE_MAX_PIO_MODE+1];
+
+#ifndef CONFIG_SYS_PIO_MODE
+#define CONFIG_SYS_PIO_MODE	0	/* use a relaxed default */
+#endif
+static int pio_mode = CONFIG_SYS_PIO_MODE;
+
+/* Make clock cycles and always round up */
+
+#define PCMCIA_MK_CLKS(t, T) (((t) * (T) + 999U) / 1000U)
+
+static void set_pcmcia_timing(int pmode)
+{
+	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
+	volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
+	ulong timings;
+
+	debug("Set timing for PIO Mode %d\n", pmode);
+
+	timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold)
+		| PCMCIA_SST(pio_config_clk[pmode].t_setup)
+		| PCMCIA_SL(pio_config_clk[pmode].t_length);
+
+	/*
+	 * IDE 0
+	 */
+	pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0;
+#if (CONFIG_SYS_PCMCIA_POR0 != 0)
+	pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0 | timings;
+#else
+	pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0;
+#endif
+	debug("PBR0: %08x  POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0);
+
+	pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1;
+#if (CONFIG_SYS_PCMCIA_POR1 != 0)
+	pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1 | timings;
+#else
+	pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1;
+#endif
+	debug("PBR1: %08x  POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1);
+
+	pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2;
+#if (CONFIG_SYS_PCMCIA_POR2 != 0)
+	pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2 | timings;
+#else
+	pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2;
+#endif
+	debug("PBR2: %08x  POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2);
+
+	pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3;
+#if (CONFIG_SYS_PCMCIA_POR3 != 0)
+	pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3 | timings;
+#else
+	pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3;
+#endif
+	debug("PBR3: %08x  POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3);
+
+	/*
+	 * IDE 1
+	 */
+	pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4;
+#if (CONFIG_SYS_PCMCIA_POR4 != 0)
+	pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4 | timings;
+#else
+	pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4;
+#endif
+	debug("PBR4: %08x  POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4);
+
+	pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5;
+#if (CONFIG_SYS_PCMCIA_POR5 != 0)
+	pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5 | timings;
+#else
+	pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5;
+#endif
+	debug("PBR5: %08x  POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5);
+
+	pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6;
+#if (CONFIG_SYS_PCMCIA_POR6 != 0)
+	pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6 | timings;
+#else
+	pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6;
+#endif
+	debug("PBR6: %08x  POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6);
+
+	pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7;
+#if (CONFIG_SYS_PCMCIA_POR7 != 0)
+	pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7 | timings;
+#else
+	pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7;
+#endif
+	debug("PBR7: %08x  POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);
+
+}
+
+int ide_preinit(void)
+{
+	int i;
+	/* Initialize PIO timing tables */
+	for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) {
+		pio_config_clk[i].t_setup =
+			PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk);
+		pio_config_clk[i].t_length =
+			PCMCIA_MK_CLKS(pio_config_ns[i].t_length, gd->bus_clk);
+		pio_config_clk[i].t_hold =
+			PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk);
+		debug("PIO Mode %d: setup=%2d ns/%d clk" "  len=%3d ns/%d clk"
+			"  hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup,
+			pio_config_clk[i].t_setup, pio_config_ns[i].t_length,
+			pio_config_clk[i].t_length, pio_config_ns[i].t_hold,
+			pio_config_clk[i].t_hold);
+	}
+
+	return 0;
+}
+
+int ide_init_postreset(void)
+{
+	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
+	volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
+
+	/* PCMCIA / IDE initialization for common mem space */
+	pcmp->pcmc_pgcrb = 0;
+
+	/* start in PIO mode 0 - most relaxed timings */
+	pio_mode = 0;
+	set_pcmcia_timing(pio_mode);
+	return 0;
+}
+#endif /* CONFIG_IDE_8xx_DIRECT */
+
+#ifdef CONFIG_IDE_8xx_PCCARD
+int ide_preinit(void)
+{
+	ide_devices_found = 0;
+	/* initialize the PCMCIA IDE adapter card */
+	pcmcia_on();
+	if (!ide_devices_found)
+		return 1;
+	udelay(1000000);/* 1 s */
+	return 0;
+}
+#endif
diff --git a/arch/powerpc/lib/ide.h b/arch/powerpc/lib/ide.h
new file mode 100644
index 0000000..9e80702
--- /dev/null
+++ b/arch/powerpc/lib/ide.h
@@ -0,0 +1,31 @@
+/*
+ * (C) Copyright 2012
+ * Pavel Herrmann <morpheus.ibis@gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#ifndef _MPC8XX_IDE_H_
+#define _MPC8XX_IDE_H_ 1
+
+#ifdef CONFIG_IDE_8xx_PCCARD
+int pcmcia_on(void);
+extern int ide_devices_found;
+#endif
+#endif
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 11e9eac..9bbdc5d 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -53,10 +53,6 @@
 # include <status_led.h>
 #endif
 
-#ifdef CONFIG_IDE_8xx_DIRECT
-DECLARE_GLOBAL_DATA_PTR;
-#endif
-
 #ifdef __PPC__
 # define EIEIO		__asm__ volatile ("eieio")
 # define SYNC		__asm__ volatile ("sync")
@@ -65,45 +61,6 @@ DECLARE_GLOBAL_DATA_PTR;
 # define SYNC		/* nothing */
 #endif
 
-#ifdef CONFIG_IDE_8xx_DIRECT
-/* Timings for IDE Interface
- *
- * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk
- * 70	   165	    30	   PIO-Mode 0, [ns]
- *  4	     9	     2		       [Cycles]
- * 50	   125	    20	   PIO-Mode 1, [ns]
- *  3	     7	     2		       [Cycles]
- * 30	   100	    15	   PIO-Mode 2, [ns]
- *  2	     6	     1		       [Cycles]
- * 30	    80	    10	   PIO-Mode 3, [ns]
- *  2	     5	     1		       [Cycles]
- * 25	    70	    10	   PIO-Mode 4, [ns]
- *  2	     4	     1		       [Cycles]
- */
-
-const static pio_config_t pio_config_ns [IDE_MAX_PIO_MODE+1] =
-{
-    /*	Setup  Length  Hold  */
-	{ 70,	165,	30 },		/* PIO-Mode 0, [ns]	*/
-	{ 50,	125,	20 },		/* PIO-Mode 1, [ns]	*/
-	{ 30,	101,	15 },		/* PIO-Mode 2, [ns]	*/
-	{ 30,	 80,	10 },		/* PIO-Mode 3, [ns]	*/
-	{ 25,	 70,	10 },		/* PIO-Mode 4, [ns]	*/
-};
-
-static pio_config_t pio_config_clk [IDE_MAX_PIO_MODE+1];
-
-#ifndef	CONFIG_SYS_PIO_MODE
-#define	CONFIG_SYS_PIO_MODE	0		/* use a relaxed default */
-#endif
-static int pio_mode = CONFIG_SYS_PIO_MODE;
-
-/* Make clock cycles and always round up */
-
-#define PCMCIA_MK_CLKS( t, T ) (( (t) * (T) + 999U ) / 1000U )
-
-#endif /* CONFIG_IDE_8xx_DIRECT */
-
 /* ------------------------------------------------------------------------- */
 
 /* Current I/O Device	*/
@@ -166,10 +123,6 @@ ulong atapi_read (int device, lbaint_t blknr, ulong blkcnt, void *buffer);
 #endif
 
 
-#ifdef CONFIG_IDE_8xx_DIRECT
-static void set_pcmcia_timing (int pmode);
-#endif
-
 /* ------------------------------------------------------------------------- */
 
 int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
@@ -392,22 +345,14 @@ inline int ide_set_piomode(int pio_mode)
 
 void ide_init(void)
 {
-
-#ifdef CONFIG_IDE_8xx_DIRECT
-	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
-	volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
-#endif
 	unsigned char c;
 	int i, bus;
 
 #ifdef CONFIG_IDE_8xx_PCCARD
-	extern int pcmcia_on(void);
 	extern int ide_devices_found;	/* Initialized in check_ide_device() */
 #endif /* CONFIG_IDE_8xx_PCCARD */
 
 #ifdef CONFIG_IDE_PREINIT
-	extern int ide_preinit(void);
-
 	WATCHDOG_RESET();
 
 	if (ide_preinit()) {
@@ -416,40 +361,8 @@ void ide_init(void)
 	}
 #endif /* CONFIG_IDE_PREINIT */
 
-#ifdef CONFIG_IDE_8xx_PCCARD
-	extern int pcmcia_on(void);
-	extern int ide_devices_found;	/* Initialized in check_ide_device() */
-
 	WATCHDOG_RESET();
 
-	ide_devices_found = 0;
-	/* initialize the PCMCIA IDE adapter card */
-	pcmcia_on();
-	if (!ide_devices_found)
-		return;
-	udelay(1000000);	/* 1 s */
-#endif /* CONFIG_IDE_8xx_PCCARD */
-
-	WATCHDOG_RESET();
-
-#ifdef CONFIG_IDE_8xx_DIRECT
-	/* Initialize PIO timing tables */
-	for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) {
-		pio_config_clk[i].t_setup =
-			PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk);
-		pio_config_clk[i].t_length =
-			PCMCIA_MK_CLKS(pio_config_ns[i].t_length,
-				       gd->bus_clk);
-		pio_config_clk[i].t_hold =
-			PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk);
-		debug("PIO Mode %d: setup=%2d ns/%d clk" "  len=%3d ns/%d clk"
-		      "  hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup,
-		      pio_config_clk[i].t_setup, pio_config_ns[i].t_length,
-		      pio_config_clk[i].t_length, pio_config_ns[i].t_hold,
-		      pio_config_clk[i].t_hold);
-	}
-#endif /* CONFIG_IDE_8xx_DIRECT */
-
 	/*
 	 * Reset the IDE just to be sure.
 	 * Light LED's to show
@@ -459,14 +372,14 @@ void ide_init(void)
 	/* ATAPI Drives seems to need a proper IDE Reset */
 	ide_reset();
 
-#ifdef CONFIG_IDE_8xx_DIRECT
-	/* PCMCIA / IDE initialization for common mem space */
-	pcmp->pcmc_pgcrb = 0;
+#ifdef CONFIG_IDE_INIT_POSTRESET
+	WATCHDOG_RESET();
 
-	/* start in PIO mode 0 - most relaxed timings */
-	pio_mode = 0;
-	set_pcmcia_timing(pio_mode);
-#endif /* CONFIG_IDE_8xx_DIRECT */
+	if (ide_init_postreset()) {
+		puts("ide_preinit_postreset failed\n");
+		return;
+	}
+#endif /* CONFIG_IDE_INIT_POSTRESET */
 
 	/*
 	 * Wait for IDE to get ready.
@@ -568,95 +481,6 @@ block_dev_desc_t *ide_get_dev(int dev)
 }
 #endif
 
-
-#ifdef CONFIG_IDE_8xx_DIRECT
-
-static void set_pcmcia_timing(int pmode)
-{
-	volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
-	volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
-	ulong timings;
-
-	debug("Set timing for PIO Mode %d\n", pmode);
-
-	timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold)
-		| PCMCIA_SST(pio_config_clk[pmode].t_setup)
-		| PCMCIA_SL(pio_config_clk[pmode].t_length);
-
-	/*
-	 * IDE 0
-	 */
-	pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0;
-	pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0
-#if (CONFIG_SYS_PCMCIA_POR0 != 0)
-		| timings
-#endif
-		;
-	debug("PBR0: %08x  POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0);
-
-	pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1;
-	pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1
-#if (CONFIG_SYS_PCMCIA_POR1 != 0)
-		| timings
-#endif
-		;
-	debug("PBR1: %08x  POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1);
-
-	pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2;
-	pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2
-#if (CONFIG_SYS_PCMCIA_POR2 != 0)
-		| timings
-#endif
-		;
-	debug("PBR2: %08x  POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2);
-
-	pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3;
-	pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3
-#if (CONFIG_SYS_PCMCIA_POR3 != 0)
-		| timings
-#endif
-		;
-	debug("PBR3: %08x  POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3);
-
-	/*
-	 * IDE 1
-	 */
-	pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4;
-	pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4
-#if (CONFIG_SYS_PCMCIA_POR4 != 0)
-		| timings
-#endif
-		;
-	debug("PBR4: %08x  POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4);
-
-	pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5;
-	pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5
-#if (CONFIG_SYS_PCMCIA_POR5 != 0)
-		| timings
-#endif
-		;
-	debug("PBR5: %08x  POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5);
-
-	pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6;
-	pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6
-#if (CONFIG_SYS_PCMCIA_POR6 != 0)
-		| timings
-#endif
-		;
-	debug("PBR6: %08x  POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6);
-
-	pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7;
-	pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7
-#if (CONFIG_SYS_PCMCIA_POR7 != 0)
-		| timings
-#endif
-		;
-	debug("PBR7: %08x  POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);
-
-}
-
-#endif /* CONFIG_IDE_8xx_DIRECT */
-
 /* ------------------------------------------------------------------------- */
 
 /* We only need to swap data if we are running on a big endian cpu. */
diff --git a/include/configs/CPC45.h b/include/configs/CPC45.h
index fc226f1..e102c36 100644
--- a/include/configs/CPC45.h
+++ b/include/configs/CPC45.h
@@ -480,6 +480,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/ICU862.h b/include/configs/ICU862.h
index 81f219c..b58b6f6 100644
--- a/include/configs/ICU862.h
+++ b/include/configs/ICU862.h
@@ -349,6 +349,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/IVML24.h b/include/configs/IVML24.h
index f98a66b..092fcf0 100644
--- a/include/configs/IVML24.h
+++ b/include/configs/IVML24.h
@@ -318,6 +318,8 @@
  * IDE/ATA stuff
  *-----------------------------------------------------------------------
  */
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
+#define CONFIG_IDE_INIT_POSTRESET	1	/* Use postreset IDE hook */
 #define CONFIG_IDE_8xx_DIRECT	1	/* PCMCIA interface required	*/
 #define CONFIG_IDE_RESET	1	/* reset for ide supported	*/
 
diff --git a/include/configs/IVMS8.h b/include/configs/IVMS8.h
index d6e9b23..38837ca 100644
--- a/include/configs/IVMS8.h
+++ b/include/configs/IVMS8.h
@@ -312,6 +312,8 @@
  * IDE/ATA stuff
  *-----------------------------------------------------------------------
  */
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
+#define CONFIG_IDE_INIT_POSTRESET	1	/* Use postreset IDE hook */
 #define CONFIG_IDE_8xx_DIRECT	1	/* PCMCIA interface required	*/
 #define CONFIG_IDE_RESET	1	/* reset for ide supported	*/
 
diff --git a/include/configs/KUP4K.h b/include/configs/KUP4K.h
index c0035e6..dae9b8c 100644
--- a/include/configs/KUP4K.h
+++ b/include/configs/KUP4K.h
@@ -353,6 +353,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/KUP4X.h b/include/configs/KUP4X.h
index 5084ccc..cceee96 100644
--- a/include/configs/KUP4X.h
+++ b/include/configs/KUP4X.h
@@ -366,6 +366,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/MBX.h b/include/configs/MBX.h
index e8d0cd7..7145cc4 100644
--- a/include/configs/MBX.h
+++ b/include/configs/MBX.h
@@ -276,6 +276,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/NETTA.h b/include/configs/NETTA.h
index 604938d..074e01f 100644
--- a/include/configs/NETTA.h
+++ b/include/configs/NETTA.h
@@ -629,6 +629,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/NSCU.h b/include/configs/NSCU.h
index 9f462f4..f4184fc 100644
--- a/include/configs/NSCU.h
+++ b/include/configs/NSCU.h
@@ -318,6 +318,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/R360MPI.h b/include/configs/R360MPI.h
index 9befacb..868a0b8 100644
--- a/include/configs/R360MPI.h
+++ b/include/configs/R360MPI.h
@@ -329,6 +329,7 @@
  */
 
 #if 1
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/RPXClassic.h b/include/configs/RPXClassic.h
index b215c2d..3595200 100644
--- a/include/configs/RPXClassic.h
+++ b/include/configs/RPXClassic.h
@@ -314,6 +314,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/RPXlite.h b/include/configs/RPXlite.h
index 8ffb014..563abea 100644
--- a/include/configs/RPXlite.h
+++ b/include/configs/RPXlite.h
@@ -249,6 +249,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/RPXlite_DW.h b/include/configs/RPXlite_DW.h
index f8bcf0f..67ab1e9 100644
--- a/include/configs/RPXlite_DW.h
+++ b/include/configs/RPXlite_DW.h
@@ -335,6 +335,7 @@
  * IDE/ATA stuff (Supports IDE harddisk on PCMCIA Adapter)
  *-----------------------------------------------------------------------
  */
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/RRvision.h b/include/configs/RRvision.h
index 671d521..e2b22f0 100644
--- a/include/configs/RRvision.h
+++ b/include/configs/RRvision.h
@@ -329,6 +329,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/SPD823TS.h b/include/configs/SPD823TS.h
index cffeb11..72ea217 100644
--- a/include/configs/SPD823TS.h
+++ b/include/configs/SPD823TS.h
@@ -303,6 +303,8 @@
  * IDE/ATA stuff
  *-----------------------------------------------------------------------
  */
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
+#define CONFIG_IDE_INIT_POSTRESET	1	/* Use postreset IDE hook */
 #define CONFIG_IDE_8xx_DIRECT	1	/* PCMCIA interface required	*/
 #define CONFIG_IDE_LED		1	/* LED   for ide supported	*/
 #define CONFIG_IDE_RESET	1	/* reset for ide supported	*/
diff --git a/include/configs/TK885D.h b/include/configs/TK885D.h
index 4176c7f..623cb66 100644
--- a/include/configs/TK885D.h
+++ b/include/configs/TK885D.h
@@ -343,6 +343,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/TQM823L.h b/include/configs/TQM823L.h
index a01b4a6..9fac5d1 100644
--- a/include/configs/TQM823L.h
+++ b/include/configs/TQM823L.h
@@ -335,6 +335,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM823M.h b/include/configs/TQM823M.h
index 1da4acd..932f158 100644
--- a/include/configs/TQM823M.h
+++ b/include/configs/TQM823M.h
@@ -331,6 +331,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM850L.h b/include/configs/TQM850L.h
index 1c054f0..eb08de2 100644
--- a/include/configs/TQM850L.h
+++ b/include/configs/TQM850L.h
@@ -320,6 +320,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM850M.h b/include/configs/TQM850M.h
index 46066df..bf3a76c 100644
--- a/include/configs/TQM850M.h
+++ b/include/configs/TQM850M.h
@@ -322,6 +322,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM855L.h b/include/configs/TQM855L.h
index dd2da94..43dd643 100644
--- a/include/configs/TQM855L.h
+++ b/include/configs/TQM855L.h
@@ -324,6 +324,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM855M.h b/include/configs/TQM855M.h
index 95bc4d9..e7fd2db 100644
--- a/include/configs/TQM855M.h
+++ b/include/configs/TQM855M.h
@@ -359,6 +359,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM860L.h b/include/configs/TQM860L.h
index 487666c..81e1b91 100644
--- a/include/configs/TQM860L.h
+++ b/include/configs/TQM860L.h
@@ -323,6 +323,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM860M.h b/include/configs/TQM860M.h
index e8b77ea..ed496a1 100644
--- a/include/configs/TQM860M.h
+++ b/include/configs/TQM860M.h
@@ -324,6 +324,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM862L.h b/include/configs/TQM862L.h
index 334b7ec..1559336 100644
--- a/include/configs/TQM862L.h
+++ b/include/configs/TQM862L.h
@@ -327,6 +327,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM862M.h b/include/configs/TQM862M.h
index 1e2ad40..61dcf62 100644
--- a/include/configs/TQM862M.h
+++ b/include/configs/TQM862M.h
@@ -328,6 +328,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/TQM866M.h b/include/configs/TQM866M.h
index a13c16a..7d0ae99 100644
--- a/include/configs/TQM866M.h
+++ b/include/configs/TQM866M.h
@@ -356,6 +356,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/TQM885D.h b/include/configs/TQM885D.h
index 7df76fb..7941631 100644
--- a/include/configs/TQM885D.h
+++ b/include/configs/TQM885D.h
@@ -341,6 +341,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/atc.h b/include/configs/atc.h
index 75f950b..538a167 100644
--- a/include/configs/atc.h
+++ b/include/configs/atc.h
@@ -482,6 +482,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/c2mon.h b/include/configs/c2mon.h
index 566c42b..41ff008 100644
--- a/include/configs/c2mon.h
+++ b/include/configs/c2mon.h
@@ -302,6 +302,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/lwmon.h b/include/configs/lwmon.h
index ab86053..df49781 100644
--- a/include/configs/lwmon.h
+++ b/include/configs/lwmon.h
@@ -494,6 +494,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/quantum.h b/include/configs/quantum.h
index 4f24651..072bd9c 100644
--- a/include/configs/quantum.h
+++ b/include/configs/quantum.h
@@ -317,6 +317,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card Adapter */
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE	 not supported	*/
diff --git a/include/configs/svm_sc8xx.h b/include/configs/svm_sc8xx.h
index 91686d6..2b24997 100644
--- a/include/configs/svm_sc8xx.h
+++ b/include/configs/svm_sc8xx.h
@@ -359,6 +359,8 @@
 
 #undef	CONFIG_IDE_8xx_PCCARD		/* Use IDE with PC Card	Adapter	*/
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
+#define CONFIG_IDE_INIT_POSTRESET	1	/* Use postreset IDE hook */
 #define	CONFIG_IDE_8xx_DIRECT	1	/* Direct IDE    not supported	*/
 #undef	CONFIG_IDE_LED			/* LED   for ide not supported	*/
 #undef	CONFIG_IDE_RESET		/* reset for ide not supported	*/
diff --git a/include/configs/uc100.h b/include/configs/uc100.h
index 8c8fb5a..450c98b 100644
--- a/include/configs/uc100.h
+++ b/include/configs/uc100.h
@@ -331,6 +331,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/configs/virtlab2.h b/include/configs/virtlab2.h
index 4bb96cc..c2c0d1d 100644
--- a/include/configs/virtlab2.h
+++ b/include/configs/virtlab2.h
@@ -329,6 +329,7 @@
  *-----------------------------------------------------------------------
  */
 
+#define CONFIG_IDE_PREINIT	1	/* Use preinit IDE hook */
 #define	CONFIG_IDE_8xx_PCCARD	1	/* Use IDE with PC Card	Adapter	*/
 
 #undef	CONFIG_IDE_8xx_DIRECT		/* Direct IDE    not supported	*/
diff --git a/include/ide.h b/include/ide.h
index 385e909..f9f1951 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -54,6 +54,14 @@ void ide_init(void);
 ulong ide_read(int device, lbaint_t blknr, ulong blkcnt, void *buffer);
 ulong ide_write(int device, lbaint_t blknr, ulong blkcnt, const void *buffer);
 
+#ifdef CONFIG_IDE_PREINIT
+int ide_preinit(void);
+#endif
+
+#ifdef CONFIG_IDE_INIT_POSTRESET
+int ide_init_postreset(void);
+#endif
+
 #if defined(CONFIG_OF_IDE_FIXUP)
 int ide_device_present(int dev);
 #endif
-- 
1.7.12

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

* [U-Boot] [PATCH v2 04/10] change all versions of input_data() and output_data() to global weak aliases
  2012-10-07 15:56 ` [U-Boot] [PATCH 04/10] change all versions of input_data() and output_data() to global weak aliases Pavel Herrmann
  2012-10-07 18:14   ` Marek Vasut
@ 2012-10-09 17:04   ` Pavel Herrmann
  1 sibling, 0 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-09 17:04 UTC (permalink / raw)
  To: u-boot

This changes input_data() and friends from static function to global symbols
under weak alias, to enable board specific overrides (and therefore get rid of
board-specific code in cmd_ide.c)
Also declare ide_bus_offset in the header file, so other files can use
ATA_CURR_BASE as well.

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
Changes for v2:
 rebase on top of next
 use "shorts" as a count parameter for the short-aligned I/O calls

 board/esd/cpci750/ide.c   |  1 -
 board/linkstation/ide.c   |  1 -
 board/pcs440ep/pcs440ep.c |  1 -
 common/cmd_ide.c          | 57 ++++++++++++++++++++++++++++++-----------------
 include/ide.h             | 11 +++++++++
 5 files changed, 48 insertions(+), 23 deletions(-)

diff --git a/board/esd/cpci750/ide.c b/board/esd/cpci750/ide.c
index aa001df..4ef10e7 100644
--- a/board/esd/cpci750/ide.c
+++ b/board/esd/cpci750/ide.c
@@ -30,7 +30,6 @@
 #include <ide.h>
 #include <pci.h>
 
-extern ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS];
 int cpci_hd_type;
 
 int ata_device(int dev)
diff --git a/board/linkstation/ide.c b/board/linkstation/ide.c
index f3e3fce..541c958 100644
--- a/board/linkstation/ide.c
+++ b/board/linkstation/ide.c
@@ -37,7 +37,6 @@
 #define IT8212_PCI_IdeBusSkewCONTROL	0x4c
 #define IT8212_PCI_IdeDrivingCURRENT	0x42
 
-extern ulong ide_bus_offset[CONFIG_SYS_IDE_MAXBUS];
 extern struct pci_controller hose;
 
 int ide_preinit (void)
diff --git a/board/pcs440ep/pcs440ep.c b/board/pcs440ep/pcs440ep.c
index 746a54c..52da053 100644
--- a/board/pcs440ep/pcs440ep.c
+++ b/board/pcs440ep/pcs440ep.c
@@ -672,7 +672,6 @@ U_BOOT_CMD(
  * ( bus per_addr 20 -30 is connectsd on CF bus A10-A0)
  * These values are shifted
  */
-extern ulong *ide_bus_offset;
 void inline ide_outb(int dev, int port, unsigned char val)
 {
 	debug ("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 6b4813e..b9feb80 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -109,8 +109,6 @@ static uchar ide_wait  (int dev, ulong t);
 
 #define IDE_SPIN_UP_TIME_OUT 5000 /* 5 sec spin-up timeout */
 
-static void input_data(int dev, ulong *sect_buf, int words);
-static void output_data(int dev, const ulong *sect_buf, int words);
 static void ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len);
 
 #ifndef CONFIG_SYS_ATA_PORT_ADDR
@@ -483,12 +481,24 @@ block_dev_desc_t *ide_get_dev(int dev)
 
 /* ------------------------------------------------------------------------- */
 
+void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+	__attribute__ ((weak, alias("__ide_input_swap_data")));
+
+void ide_input_data(int dev, ulong *sect_buf, int words)
+	__attribute__ ((weak, alias("__ide_input_data")));
+
+void ide_output_data(int dev, const ulong *sect_buf, int words)
+	__attribute__ ((weak, alias("__ide_output_data")));
+
 /* We only need to swap data if we are running on a big endian cpu. */
 /* But Au1x00 cpu:s already swaps data in big endian mode! */
 #if defined(__LITTLE_ENDIAN) || defined(CONFIG_SOC_AU1X00)
-#define input_swap_data(x,y,z) input_data(x,y,z)
+void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
+{
+	ide_input_data(dev, sect_buf, words);
+}
 #else
-static void input_swap_data(int dev, ulong *sect_buf, int words)
+void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 {
 #if defined(CONFIG_CPC45)
 	uchar i;
@@ -531,7 +541,7 @@ static void input_swap_data(int dev, ulong *sect_buf, int words)
 
 
 #if defined(CONFIG_IDE_SWAP_IO)
-static void output_data(int dev, const ulong *sect_buf, int words)
+void __ide_output_data(int dev, const ulong *sect_buf, int words)
 {
 #if defined(CONFIG_CPC45)
 	uchar *dbuf;
@@ -574,7 +584,7 @@ static void output_data(int dev, const ulong *sect_buf, int words)
 #endif
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
-static void output_data(int dev, const ulong *sect_buf, int words)
+void __ide_output_data(int dev, const ulong *sect_buf, int words)
 {
 #if defined(CONFIG_IDE_AHB)
 	ide_write_data(dev, sect_buf, words);
@@ -585,7 +595,7 @@ static void output_data(int dev, const ulong *sect_buf, int words)
 #endif /* CONFIG_IDE_SWAP_IO */
 
 #if defined(CONFIG_IDE_SWAP_IO)
-static void input_data(int dev, ulong *sect_buf, int words)
+void __ide_input_data(int dev, ulong *sect_buf, int words)
 {
 #if defined(CONFIG_CPC45)
 	uchar *dbuf;
@@ -634,7 +644,7 @@ static void input_data(int dev, ulong *sect_buf, int words)
 #endif
 }
 #else  /* ! CONFIG_IDE_SWAP_IO */
-static void input_data(int dev, ulong *sect_buf, int words)
+void __ide_input_data(int dev, ulong *sect_buf, int words)
 {
 #if defined(CONFIG_IDE_AHB)
 	ide_read_data(dev, sect_buf, words);
@@ -744,7 +754,7 @@ static void ide_ident(block_dev_desc_t *dev_desc)
 		return;
 #endif
 
-	input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
+	ide_input_swap_data(device, (ulong *)&iop, ATA_SECTORWORDS);
 
 	ident_cpy((unsigned char *) dev_desc->revision, iop.fw_rev,
 		  sizeof(dev_desc->revision));
@@ -1006,7 +1016,7 @@ ulong ide_read(int device, lbaint_t blknr, ulong blkcnt, void *buffer)
 			break;
 		}
 
-		input_data(device, buffer, ATA_SECTORWORDS);
+		ide_input_data(device, buffer, ATA_SECTORWORDS);
 		(void) ide_inb(device, ATA_STATUS);	/* clear IRQ */
 
 		++n;
@@ -1099,7 +1109,7 @@ ulong ide_write(int device, lbaint_t blknr, ulong blkcnt, const void *buffer)
 			goto WR_OUT;
 		}
 
-		output_data(device, buffer, ATA_SECTORWORDS);
+		ide_output_data(device, buffer, ATA_SECTORWORDS);
 		c = ide_inb(device, ATA_STATUS);	/* clear IRQ */
 		++n;
 		++blknr;
@@ -1232,10 +1242,17 @@ int ide_device_present(int dev)
  * ATAPI Support
  */
 
+void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
+	__attribute__ ((weak, alias("__ide_input_data_shorts")));
+
+void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
+	__attribute__ ((weak, alias("__ide_output_data_shorts")));
+
+
 #if defined(CONFIG_IDE_SWAP_IO)
 /* since ATAPI may use commands with not 4 bytes alligned length
  * we have our own transfer functions, 2 bytes alligned */
-static void output_data_shorts(int dev, ushort *sect_buf, int shorts)
+void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
 #if defined(CONFIG_CPC45)
 	uchar *dbuf;
@@ -1267,7 +1284,7 @@ static void output_data_shorts(int dev, ushort *sect_buf, int shorts)
 #endif
 }
 
-static void input_data_shorts(int dev, ushort *sect_buf, int shorts)
+void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
 #if defined(CONFIG_CPC45)
 	uchar *dbuf;
@@ -1300,12 +1317,12 @@ static void input_data_shorts(int dev, ushort *sect_buf, int shorts)
 }
 
 #else  /* ! CONFIG_IDE_SWAP_IO */
-static void output_data_shorts(int dev, ushort *sect_buf, int shorts)
+void __ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
 	outsw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
 }
 
-static void input_data_shorts(int dev, ushort *sect_buf, int shorts)
+void __ide_input_data_shorts(int dev, ushort *sect_buf, int shorts)
 {
 	insw(ATA_CURR_BASE(dev) + ATA_DATA_REG, sect_buf, shorts);
 }
@@ -1384,7 +1401,7 @@ unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
 	}
 
 	/* write command block */
-	output_data_shorts(device, (unsigned short *) ccb, ccblen / 2);
+	ide_output_data_shorts(device, (unsigned short *) ccb, ccblen / 2);
 
 	/* ATAPI Command written wait for completition */
 	udelay(5000);		/* device must set bsy */
@@ -1435,12 +1452,12 @@ unsigned char atapi_issue(int device, unsigned char *ccb, int ccblen,
 		/* ok now decide if it is an in or output */
 		if ((ide_inb(device, ATA_SECT_CNT) & 0x02) == 0) {
 			debug("Write to device\n");
-			output_data_shorts(device, (unsigned short *) buffer,
-					   n);
+			ide_output_data_shorts(device,
+				(unsigned short *) buffer, n);
 		} else {
 			debug("Read from device @ %p shorts %d\n", buffer, n);
-			input_data_shorts(device, (unsigned short *) buffer,
-					  n);
+			ide_input_data_shorts(device,
+				(unsigned short *) buffer, n);
 		}
 	}
 	udelay(5000);		/* seems that some CD ROMs need this... */
diff --git a/include/ide.h b/include/ide.h
index f9f1951..44a86a7 100644
--- a/include/ide.h
+++ b/include/ide.h
@@ -27,6 +27,7 @@
 #define IDE_BUS(dev)	(dev / (CONFIG_SYS_IDE_MAXDEVICE / CONFIG_SYS_IDE_MAXBUS))
 
 #define	ATA_CURR_BASE(dev)	(CONFIG_SYS_ATA_BASE_ADDR+ide_bus_offset[IDE_BUS(dev)])
+extern ulong ide_bus_offset[];
 
 #ifdef CONFIG_IDE_LED
 
@@ -72,4 +73,14 @@ void ide_write_register(int dev, unsigned int port, unsigned char val);
 void ide_read_data(int dev, ulong *sect_buf, int words);
 void ide_write_data(int dev, ulong *sect_buf, int words);
 #endif
+
+/*
+ * I/O function overrides
+ */
+void ide_input_swap_data(int dev, ulong *sect_buf, int words);
+void ide_input_data(int dev, ulong *sect_buf, int words);
+void ide_output_data(int dev, const ulong *sect_buf, int words);
+void ide_input_data_shorts(int dev, ushort *sect_buf, int shorts);
+void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts);
+
 #endif /* _IDE_H */
-- 
1.7.12

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

* [U-Boot] [PATCH v2 07/10] move CPC45 ide_led to the same file as other IDE hooks
  2012-10-07 15:56 ` [U-Boot] [PATCH 07/10] move CPC45 ide_led to the same file as other IDE hooks Pavel Herrmann
  2012-10-07 18:21   ` Marek Vasut
@ 2012-10-09 17:06   ` Pavel Herrmann
  1 sibling, 0 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-09 17:06 UTC (permalink / raw)
  To: u-boot

Keep all IDE-related hooks and overrides in a single file, to avoid confusion

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
Changes for v2:
 style fixes

 board/cpc45/cpc45.c | 15 ---------------
 board/cpc45/ide.c   | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/board/cpc45/cpc45.c b/board/cpc45/cpc45.c
index 1178822..2200806 100644
--- a/board/cpc45/cpc45.c
+++ b/board/cpc45/cpc45.c
@@ -260,21 +260,6 @@ int pcmcia_init(void)
 
 #endif
 
-# ifdef CONFIG_IDE_LED
-void ide_led (uchar led, uchar status)
-{
-	u_char  val;
-	/* We have one PCMCIA slot and use LED H4 for the IDE Interface */
-	val = readb(BCSR_BASE + 0x04);
-	if (status) {				/* led on */
-		val |= B_CTRL_LED0;
-	} else {
-		val &= ~B_CTRL_LED0;
-	}
-	writeb(val, BCSR_BASE + 0x04);
-}
-# endif
-
 int board_eth_init(bd_t *bis)
 {
 	return pci_eth_init(bis);
diff --git a/board/cpc45/ide.c b/board/cpc45/ide.c
index 7b7237b..03be59f 100644
--- a/board/cpc45/ide.c
+++ b/board/cpc45/ide.c
@@ -27,6 +27,7 @@
 #include <common.h>
 #include <ide.h>
 #include <ata.h>
+#include <asm/io.h>
 
 #define EIEIO		__asm__ volatile ("eieio")
 #define SYNC		__asm__ volatile ("sync")
@@ -128,3 +129,17 @@ void ide_output_data_shorts(int dev, ushort *sect_buf, int shorts)
 		*pbuf_odd = *dbuf++;
 	}
 }
+
+void ide_led(uchar led, uchar status)
+{
+	u_char	val;
+	/* We have one PCMCIA slot and use LED H4 for the IDE Interface */
+	val = readb(BCSR_BASE + 0x04);
+	if (status)				/* led on */
+		val |= B_CTRL_LED0;
+	else
+		val &= ~B_CTRL_LED0;
+
+	writeb(val, BCSR_BASE + 0x04);
+}
+
-- 
1.7.12

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

* [U-Boot] [PATCH v2 08/10] split AU1X00 specific code from cmd_ide.c
  2012-10-07 15:56 ` [U-Boot] [PATCH 08/10] split AU1X00 specific code from cmd_ide.c Pavel Herrmann
  2012-10-08 23:38   ` Tom Rini
@ 2012-10-09 17:10   ` Pavel Herrmann
  1 sibling, 0 replies; 28+ messages in thread
From: Pavel Herrmann @ 2012-10-09 17:10 UTC (permalink / raw)
  To: u-boot

move special case of ide_swap_read() for AU1X00 SoC into SoC-specific directory.

Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
---
Changes for v2:
 rebase on top of next
 include missing <common.h> to fix compilation

 arch/mips/cpu/mips32/au1x00/Makefile     |  2 +-
 arch/mips/cpu/mips32/au1x00/au1x00_ide.c | 32 ++++++++++++++++++++++++++++++++
 common/cmd_ide.c                         |  5 ++---
 3 files changed, 35 insertions(+), 4 deletions(-)
 create mode 100644 arch/mips/cpu/mips32/au1x00/au1x00_ide.c

diff --git a/arch/mips/cpu/mips32/au1x00/Makefile b/arch/mips/cpu/mips32/au1x00/Makefile
index dc58475..b9f895d 100644
--- a/arch/mips/cpu/mips32/au1x00/Makefile
+++ b/arch/mips/cpu/mips32/au1x00/Makefile
@@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(SOC).o
 
-COBJS	= au1x00_eth.o au1x00_serial.o au1x00_usb_ohci.o
+COBJS	= au1x00_eth.o au1x00_serial.o au1x00_usb_ohci.o au1x00_ide.o
 
 SRCS	:= $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS))
diff --git a/arch/mips/cpu/mips32/au1x00/au1x00_ide.c b/arch/mips/cpu/mips32/au1x00/au1x00_ide.c
new file mode 100644
index 0000000..932cdfb
--- /dev/null
+++ b/arch/mips/cpu/mips32/au1x00/au1x00_ide.c
@@ -0,0 +1,32 @@
+/*
+ * (C) Copyright 2000-2011
+ * 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.
+ *
+ * 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 <ide.h>
+
+/* AU1X00 swaps data in big-endian mode, enforce little-endian function */
+void ide_input_swap_data(int dev, ulong *sect_buf, int words)
+{
+	ide_input_data(dev, sect_buf, words);
+}
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 7eb19cf..5b46e3c 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -503,8 +503,7 @@ void ide_output_data(int dev, const ulong *sect_buf, int words)
 	__attribute__ ((weak, alias("__ide_output_data")));
 
 /* We only need to swap data if we are running on a big endian cpu. */
-/* But Au1x00 cpu:s already swaps data in big endian mode! */
-#if defined(__LITTLE_ENDIAN) || defined(CONFIG_SOC_AU1X00)
+#if defined(__LITTLE_ENDIAN)
 void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 {
 	ide_input_data(dev, sect_buf, words);
@@ -532,7 +531,7 @@ void __ide_input_swap_data(int dev, ulong *sect_buf, int words)
 #endif /* !MIPS */
 	}
 }
-#endif /* __LITTLE_ENDIAN || CONFIG_AU1X00 */
+#endif /* __LITTLE_ENDIAN */
 
 
 #if defined(CONFIG_IDE_SWAP_IO)
-- 
1.7.12

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

* [U-Boot] [PATCH 04/10] change all versions of input_data() and output_data() to global weak aliases
  2012-10-09 13:42     ` Pavel Herrmann
@ 2012-10-09 17:13       ` Marek Vasut
  0 siblings, 0 replies; 28+ messages in thread
From: Marek Vasut @ 2012-10-09 17:13 UTC (permalink / raw)
  To: u-boot

Dear Pavel Herrmann,

> On Sunday 07 of October 2012 20:14:23 Marek Vasut wrote:
> > Dear Pavel Herrmann,
> > 
> > > This changes input_data() and friends from static function to global
> > > symbols under weak alias, to enable board specific overrides (and
> > > therefore get rid of board-specific code in cmd_ide.c)
> > > Also declare ide_bus_offset in the header file, so other files can use
> > > ATA_CURR_BASE as well.
> > > 
> > > Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> > > ---
> > 
> > [...]
> > 
> > > +void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> > > +	__attribute__ ((weak, alias("__ide_input_swap_data")));
> > 
> > #include <linux/compiler.h>
> > 
> > __weak void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> > {
> > 
> >    ... body ...
> > 
> > }
> > 
> > Works just fine ;-)
> > 
> > [...]
> > 
> > > +/*
> > > + * I/O function overrides
> > > + */
> > > +void ide_input_swap_data(int dev, ulong *sect_buf, int words);
> > > +void ide_input_data(int dev, ulong *sect_buf, int words);
> > > +void ide_output_data(int dev, const ulong *sect_buf, int words);
> > > +void ide_input_data_shorts(int dev, ushort *sect_buf, int words);
> > > +void ide_output_data_shorts(int dev, ushort *sect_buf, int words);
> > 
> > Shorts ... you mean like pants ? :-p
> > 
> > I'd say it's supposed to be "short", like u16 ;-)
> 
> the code says "shorts", as in "multiple of u16", rather than "pants".

Hm, ide_input_data_u16 is good, no ?

Best regards,
Marek Vasut

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

* [U-Boot] [PATCH 05/10] split CPC45 board-specific IDE functions from cmd_ide.c
  2012-10-09 13:38     ` Pavel Herrmann
@ 2012-10-09 17:13       ` Marek Vasut
  0 siblings, 0 replies; 28+ messages in thread
From: Marek Vasut @ 2012-10-09 17:13 UTC (permalink / raw)
  To: u-boot

Dear Pavel Herrmann,

> On Sunday 07 of October 2012 20:20:08 Marek Vasut wrote:
> > Dear Pavel Herrmann,
> > 
> > > Move input_data() and friends to board/cpc45/ide.c, as overrides for
> > > weak aliases in cmd_ide.c
> > > 
> > > note: checkpatch emits warnings about using volatile
> > > 
> > > Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>
> > > ---
> > > 
> > >  board/cpc45/Makefile |   2 +-
> > >  board/cpc45/ide.c    | 130
> > > 
> > > +++++++++++++++++++++++++++++++++++++++++++++++++++ common/cmd_ide.c   
> > >  |
> > > 
> > >  91 ------------------------------------
> > >  3 files changed, 131 insertions(+), 92 deletions(-)
> > >  create mode 100644 board/cpc45/ide.c
> > > 
> > > diff --git a/board/cpc45/Makefile b/board/cpc45/Makefile
> > > index 5c6b78f..ac1d174 100644
> > > --- a/board/cpc45/Makefile
> > > +++ b/board/cpc45/Makefile
> > > @@ -25,7 +25,7 @@ include $(TOPDIR)/config.mk
> > > 
> > >  LIB	= $(obj)lib$(BOARD).o
> > > 
> > > -COBJS	= $(BOARD).o flash.o plx9030.o pd67290.o
> > > +COBJS	= $(BOARD).o flash.o plx9030.o pd67290.o ide.o
> > > 
> > >  SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
> > >  OBJS	:= $(addprefix $(obj),$(COBJS))
> > > 
> > > diff --git a/board/cpc45/ide.c b/board/cpc45/ide.c
> > > new file mode 100644
> > > index 0000000..7b7237b
> > > --- /dev/null
> > > +++ b/board/cpc45/ide.c
> > > @@ -0,0 +1,130 @@
> > > +/*
> > > + * (C) Copyright 2001
> > > + * Rob Taylor, Flying Pig Systems. robt at flyingpig.com.
> > > + *
> > > + * (C) Copyright 2000-2011
> > > + * 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.
> > > + *
> > > + * 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 <ide.h>
> > > +#include <ata.h>
> > > +
> > > +#define EIEIO		__asm__ volatile ("eieio")
> > > +#define SYNC		__asm__ volatile ("sync")
> > 
> > Make it asm, not __asm__
> > 
> > > +
> > > +void ide_input_swap_data(int dev, ulong *sect_buf, int words)
> > > +{
> > > +	uchar i;
> > > +	volatile uchar *pbuf_even =
> > > +		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_EVEN);
> > > +	volatile uchar *pbuf_odd =
> > > +		(uchar *) (ATA_CURR_BASE(dev) + ATA_DATA_ODD);
> > > +	ushort *dbuf = (ushort *) sect_buf;
> > 
> > What's this, some kind of __swab16() ?
> 
> more probably this is a hack for strange wiring on the board

That much I see myself ... but the goo below does the same thing as swab16(), 
doesn't it ?

> > > +	while (words--) {
> > > +		for (i = 0; i < 2; i++) {
> > > +			*(((uchar *) (dbuf)) + 1) = *pbuf_even;
> > > +			*(uchar *) dbuf = *pbuf_odd;
> > > +			dbuf += 1;
> > > +		}
> > > +	}
> > > +}
> > 
> > [...]
> > 
> > I'm not reviewing this any further ... this is some ancient code, right?
> 
> yes, this series is mostly cut-and-paste cleanup of old code, changes were
> made only when checkpatch didnt approve.
> 
> Pavel Herrmann

Best regards,
Marek Vasut

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

* [U-Boot] [U-Boot,01/10] remove CONFIG_SC3 from cmd_ide.c
  2012-10-07 15:56 ` [U-Boot] [PATCH 01/10] remove CONFIG_SC3 from cmd_ide.c Pavel Herrmann
@ 2012-10-17 15:02   ` Tom Rini
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Rini @ 2012-10-17 15:02 UTC (permalink / raw)
  To: u-boot

On Sun, Oct 07, 2012 at 05:56:05AM -0000, Pavel Herrmann wrote:

> There is no difference in codepath with CONFIG_SC3 enabled, so just remove it
> 
> Signed-off-by: Pavel Herrmann <morpheus.ibis@gmail.com>

This, and the rest of the series (with v2 for 2, 4, 7 and 8) has been
applied to u-boot/master, thanks!

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

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

end of thread, other threads:[~2012-10-17 15:02 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-07 15:56 [U-Boot] [PATCH 00/10] IDE code cleanup Pavel Herrmann
2012-10-07 15:56 ` [U-Boot] [PATCH 01/10] remove CONFIG_SC3 from cmd_ide.c Pavel Herrmann
2012-10-17 15:02   ` [U-Boot] [U-Boot,01/10] " Tom Rini
2012-10-07 15:56 ` [U-Boot] [PATCH 02/10] split mpc8xx hooks " Pavel Herrmann
2012-10-07 18:09   ` Marek Vasut
2012-10-07 18:09   ` Marek Vasut
2012-10-09 17:01   ` [U-Boot] [PATCH v2 " Pavel Herrmann
2012-10-07 15:56 ` [U-Boot] [PATCH 03/10] split IVM power " Pavel Herrmann
2012-10-07 15:56 ` [U-Boot] [PATCH 04/10] change all versions of input_data() and output_data() to global weak aliases Pavel Herrmann
2012-10-07 18:14   ` Marek Vasut
2012-10-09 13:42     ` Pavel Herrmann
2012-10-09 17:13       ` Marek Vasut
2012-10-09 17:04   ` [U-Boot] [PATCH v2 " Pavel Herrmann
2012-10-07 15:56 ` [U-Boot] [PATCH 05/10] split CPC45 board-specific IDE functions from cmd_ide.c Pavel Herrmann
2012-10-07 18:20   ` Marek Vasut
2012-10-09 13:38     ` Pavel Herrmann
2012-10-09 17:13       ` Marek Vasut
2012-10-07 15:56 ` [U-Boot] [PATCH 06/10] make ide_led() a weak alias Pavel Herrmann
2012-10-07 15:56 ` [U-Boot] [PATCH 07/10] move CPC45 ide_led to the same file as other IDE hooks Pavel Herrmann
2012-10-07 18:21   ` Marek Vasut
2012-10-09 17:06   ` [U-Boot] [PATCH v2 " Pavel Herrmann
2012-10-07 15:56 ` [U-Boot] [PATCH 08/10] split AU1X00 specific code from cmd_ide.c Pavel Herrmann
2012-10-08 23:38   ` Tom Rini
2012-10-09 13:35     ` Pavel Herrmann
2012-10-09 17:10   ` [U-Boot] [PATCH v2 " Pavel Herrmann
2012-10-07 15:56 ` [U-Boot] [PATCH 09/10] split PCS440EP " Pavel Herrmann
2012-10-07 15:56 ` [U-Boot] [PATCH 10/10] remove unnecessary includes " Pavel Herrmann
2012-10-07 18:23 ` [U-Boot] [PATCH 00/10] IDE code cleanup Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.