2 * (C) Copyright 2000-2011
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
8 /* Code taken from cmd_ide.c */
13 #ifdef CONFIG_IDE_8xx_DIRECT
16 DECLARE_GLOBAL_DATA_PTR;
18 /* Timings for IDE Interface
20 * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk
21 * 70 165 30 PIO-Mode 0, [ns]
23 * 50 125 20 PIO-Mode 1, [ns]
25 * 30 100 15 PIO-Mode 2, [ns]
27 * 30 80 10 PIO-Mode 3, [ns]
29 * 25 70 10 PIO-Mode 4, [ns]
33 static const pio_config_t pio_config_ns[IDE_MAX_PIO_MODE+1] = {
34 /* Setup Length Hold */
35 { 70, 165, 30 }, /* PIO-Mode 0, [ns] */
36 { 50, 125, 20 }, /* PIO-Mode 1, [ns] */
37 { 30, 101, 15 }, /* PIO-Mode 2, [ns] */
38 { 30, 80, 10 }, /* PIO-Mode 3, [ns] */
39 { 25, 70, 10 }, /* PIO-Mode 4, [ns] */
42 static pio_config_t pio_config_clk[IDE_MAX_PIO_MODE+1];
44 #ifndef CONFIG_SYS_PIO_MODE
45 #define CONFIG_SYS_PIO_MODE 0 /* use a relaxed default */
47 static int pio_mode = CONFIG_SYS_PIO_MODE;
49 /* Make clock cycles and always round up */
51 #define PCMCIA_MK_CLKS(t, T) (((t) * (T) + 999U) / 1000U)
53 static void set_pcmcia_timing(int pmode)
55 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
56 volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
59 debug("Set timing for PIO Mode %d\n", pmode);
61 timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold)
62 | PCMCIA_SST(pio_config_clk[pmode].t_setup)
63 | PCMCIA_SL(pio_config_clk[pmode].t_length);
68 pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0;
69 #if (CONFIG_SYS_PCMCIA_POR0 != 0)
70 pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0 | timings;
72 pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0;
74 debug("PBR0: %08x POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0);
76 pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1;
77 #if (CONFIG_SYS_PCMCIA_POR1 != 0)
78 pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1 | timings;
80 pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1;
82 debug("PBR1: %08x POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1);
84 pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2;
85 #if (CONFIG_SYS_PCMCIA_POR2 != 0)
86 pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2 | timings;
88 pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2;
90 debug("PBR2: %08x POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2);
92 pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3;
93 #if (CONFIG_SYS_PCMCIA_POR3 != 0)
94 pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3 | timings;
96 pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3;
98 debug("PBR3: %08x POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3);
103 pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4;
104 #if (CONFIG_SYS_PCMCIA_POR4 != 0)
105 pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4 | timings;
107 pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4;
109 debug("PBR4: %08x POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4);
111 pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5;
112 #if (CONFIG_SYS_PCMCIA_POR5 != 0)
113 pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5 | timings;
115 pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5;
117 debug("PBR5: %08x POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5);
119 pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6;
120 #if (CONFIG_SYS_PCMCIA_POR6 != 0)
121 pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6 | timings;
123 pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6;
125 debug("PBR6: %08x POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6);
127 pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7;
128 #if (CONFIG_SYS_PCMCIA_POR7 != 0)
129 pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7 | timings;
131 pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7;
133 debug("PBR7: %08x POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);
137 int ide_preinit(void)
140 /* Initialize PIO timing tables */
141 for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) {
142 pio_config_clk[i].t_setup =
143 PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk);
144 pio_config_clk[i].t_length =
145 PCMCIA_MK_CLKS(pio_config_ns[i].t_length, gd->bus_clk);
146 pio_config_clk[i].t_hold =
147 PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk);
148 debug("PIO Mode %d: setup=%2d ns/%d clk" " len=%3d ns/%d clk"
149 " hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup,
150 pio_config_clk[i].t_setup, pio_config_ns[i].t_length,
151 pio_config_clk[i].t_length, pio_config_ns[i].t_hold,
152 pio_config_clk[i].t_hold);
158 int ide_init_postreset(void)
160 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
161 volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
163 /* PCMCIA / IDE initialization for common mem space */
164 pcmp->pcmc_pgcrb = 0;
166 /* start in PIO mode 0 - most relaxed timings */
168 set_pcmcia_timing(pio_mode);
171 #endif /* CONFIG_IDE_8xx_DIRECT */
173 #ifdef CONFIG_IDE_8xx_PCCARD
174 int ide_preinit(void)
176 ide_devices_found = 0;
177 /* initialize the PCMCIA IDE adapter card */
179 if (!ide_devices_found)
181 udelay(1000000);/* 1 s */