2 * (C) Copyright 2000-2011
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 /* Code taken from cmd_ide.c */
30 #ifdef CONFIG_IDE_8xx_DIRECT
33 DECLARE_GLOBAL_DATA_PTR
;
35 /* Timings for IDE Interface
37 * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk
38 * 70 165 30 PIO-Mode 0, [ns]
40 * 50 125 20 PIO-Mode 1, [ns]
42 * 30 100 15 PIO-Mode 2, [ns]
44 * 30 80 10 PIO-Mode 3, [ns]
46 * 25 70 10 PIO-Mode 4, [ns]
50 static const pio_config_t pio_config_ns
[IDE_MAX_PIO_MODE
+1] = {
51 /* Setup Length Hold */
52 { 70, 165, 30 }, /* PIO-Mode 0, [ns] */
53 { 50, 125, 20 }, /* PIO-Mode 1, [ns] */
54 { 30, 101, 15 }, /* PIO-Mode 2, [ns] */
55 { 30, 80, 10 }, /* PIO-Mode 3, [ns] */
56 { 25, 70, 10 }, /* PIO-Mode 4, [ns] */
59 static pio_config_t pio_config_clk
[IDE_MAX_PIO_MODE
+1];
61 #ifndef CONFIG_SYS_PIO_MODE
62 #define CONFIG_SYS_PIO_MODE 0 /* use a relaxed default */
64 static int pio_mode
= CONFIG_SYS_PIO_MODE
;
66 /* Make clock cycles and always round up */
68 #define PCMCIA_MK_CLKS(t, T) (((t) * (T) + 999U) / 1000U)
70 static void set_pcmcia_timing(int pmode
)
72 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
73 volatile pcmconf8xx_t
*pcmp
= &(immr
->im_pcmcia
);
76 debug("Set timing for PIO Mode %d\n", pmode
);
78 timings
= PCMCIA_SHT(pio_config_clk
[pmode
].t_hold
)
79 | PCMCIA_SST(pio_config_clk
[pmode
].t_setup
)
80 | PCMCIA_SL(pio_config_clk
[pmode
].t_length
);
85 pcmp
->pcmc_pbr0
= CONFIG_SYS_PCMCIA_PBR0
;
86 #if (CONFIG_SYS_PCMCIA_POR0 != 0)
87 pcmp
->pcmc_por0
= CONFIG_SYS_PCMCIA_POR0
| timings
;
89 pcmp
->pcmc_por0
= CONFIG_SYS_PCMCIA_POR0
;
91 debug("PBR0: %08x POR0: %08x\n", pcmp
->pcmc_pbr0
, pcmp
->pcmc_por0
);
93 pcmp
->pcmc_pbr1
= CONFIG_SYS_PCMCIA_PBR1
;
94 #if (CONFIG_SYS_PCMCIA_POR1 != 0)
95 pcmp
->pcmc_por1
= CONFIG_SYS_PCMCIA_POR1
| timings
;
97 pcmp
->pcmc_por1
= CONFIG_SYS_PCMCIA_POR1
;
99 debug("PBR1: %08x POR1: %08x\n", pcmp
->pcmc_pbr1
, pcmp
->pcmc_por1
);
101 pcmp
->pcmc_pbr2
= CONFIG_SYS_PCMCIA_PBR2
;
102 #if (CONFIG_SYS_PCMCIA_POR2 != 0)
103 pcmp
->pcmc_por2
= CONFIG_SYS_PCMCIA_POR2
| timings
;
105 pcmp
->pcmc_por2
= CONFIG_SYS_PCMCIA_POR2
;
107 debug("PBR2: %08x POR2: %08x\n", pcmp
->pcmc_pbr2
, pcmp
->pcmc_por2
);
109 pcmp
->pcmc_pbr3
= CONFIG_SYS_PCMCIA_PBR3
;
110 #if (CONFIG_SYS_PCMCIA_POR3 != 0)
111 pcmp
->pcmc_por3
= CONFIG_SYS_PCMCIA_POR3
| timings
;
113 pcmp
->pcmc_por3
= CONFIG_SYS_PCMCIA_POR3
;
115 debug("PBR3: %08x POR3: %08x\n", pcmp
->pcmc_pbr3
, pcmp
->pcmc_por3
);
120 pcmp
->pcmc_pbr4
= CONFIG_SYS_PCMCIA_PBR4
;
121 #if (CONFIG_SYS_PCMCIA_POR4 != 0)
122 pcmp
->pcmc_por4
= CONFIG_SYS_PCMCIA_POR4
| timings
;
124 pcmp
->pcmc_por4
= CONFIG_SYS_PCMCIA_POR4
;
126 debug("PBR4: %08x POR4: %08x\n", pcmp
->pcmc_pbr4
, pcmp
->pcmc_por4
);
128 pcmp
->pcmc_pbr5
= CONFIG_SYS_PCMCIA_PBR5
;
129 #if (CONFIG_SYS_PCMCIA_POR5 != 0)
130 pcmp
->pcmc_por5
= CONFIG_SYS_PCMCIA_POR5
| timings
;
132 pcmp
->pcmc_por5
= CONFIG_SYS_PCMCIA_POR5
;
134 debug("PBR5: %08x POR5: %08x\n", pcmp
->pcmc_pbr5
, pcmp
->pcmc_por5
);
136 pcmp
->pcmc_pbr6
= CONFIG_SYS_PCMCIA_PBR6
;
137 #if (CONFIG_SYS_PCMCIA_POR6 != 0)
138 pcmp
->pcmc_por6
= CONFIG_SYS_PCMCIA_POR6
| timings
;
140 pcmp
->pcmc_por6
= CONFIG_SYS_PCMCIA_POR6
;
142 debug("PBR6: %08x POR6: %08x\n", pcmp
->pcmc_pbr6
, pcmp
->pcmc_por6
);
144 pcmp
->pcmc_pbr7
= CONFIG_SYS_PCMCIA_PBR7
;
145 #if (CONFIG_SYS_PCMCIA_POR7 != 0)
146 pcmp
->pcmc_por7
= CONFIG_SYS_PCMCIA_POR7
| timings
;
148 pcmp
->pcmc_por7
= CONFIG_SYS_PCMCIA_POR7
;
150 debug("PBR7: %08x POR7: %08x\n", pcmp
->pcmc_pbr7
, pcmp
->pcmc_por7
);
154 int ide_preinit(void)
157 /* Initialize PIO timing tables */
158 for (i
= 0; i
<= IDE_MAX_PIO_MODE
; ++i
) {
159 pio_config_clk
[i
].t_setup
=
160 PCMCIA_MK_CLKS(pio_config_ns
[i
].t_setup
, gd
->bus_clk
);
161 pio_config_clk
[i
].t_length
=
162 PCMCIA_MK_CLKS(pio_config_ns
[i
].t_length
, gd
->bus_clk
);
163 pio_config_clk
[i
].t_hold
=
164 PCMCIA_MK_CLKS(pio_config_ns
[i
].t_hold
, gd
->bus_clk
);
165 debug("PIO Mode %d: setup=%2d ns/%d clk" " len=%3d ns/%d clk"
166 " hold=%2d ns/%d clk\n", i
, pio_config_ns
[i
].t_setup
,
167 pio_config_clk
[i
].t_setup
, pio_config_ns
[i
].t_length
,
168 pio_config_clk
[i
].t_length
, pio_config_ns
[i
].t_hold
,
169 pio_config_clk
[i
].t_hold
);
175 int ide_init_postreset(void)
177 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
178 volatile pcmconf8xx_t
*pcmp
= &(immr
->im_pcmcia
);
180 /* PCMCIA / IDE initialization for common mem space */
181 pcmp
->pcmc_pgcrb
= 0;
183 /* start in PIO mode 0 - most relaxed timings */
185 set_pcmcia_timing(pio_mode
);
188 #endif /* CONFIG_IDE_8xx_DIRECT */
190 #ifdef CONFIG_IDE_8xx_PCCARD
191 int ide_preinit(void)
193 ide_devices_found
= 0;
194 /* initialize the PCMCIA IDE adapter card */
196 if (!ide_devices_found
)
198 udelay(1000000);/* 1 s */