1
2
3
4
5
6
7
8
9#include <common.h>
10#include <ata.h>
11#include "ide.h"
12
13#ifdef CONFIG_IDE_8xx_DIRECT
14#include <mpc8xx.h>
15#include <pcmcia.h>
16DECLARE_GLOBAL_DATA_PTR;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33static const pio_config_t pio_config_ns[IDE_MAX_PIO_MODE+1] = {
34
35 { 70, 165, 30 },
36 { 50, 125, 20 },
37 { 30, 101, 15 },
38 { 30, 80, 10 },
39 { 25, 70, 10 },
40};
41
42static pio_config_t pio_config_clk[IDE_MAX_PIO_MODE+1];
43
44#ifndef CONFIG_SYS_PIO_MODE
45#define CONFIG_SYS_PIO_MODE 0
46#endif
47static int pio_mode = CONFIG_SYS_PIO_MODE;
48
49
50
51#define PCMCIA_MK_CLKS(t, T) (((t) * (T) + 999U) / 1000U)
52
53static void set_pcmcia_timing(int pmode)
54{
55 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
56 volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
57 ulong timings;
58
59 debug("Set timing for PIO Mode %d\n", pmode);
60
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);
64
65
66
67
68 pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0;
69#if (CONFIG_SYS_PCMCIA_POR0 != 0)
70 pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0 | timings;
71#else
72 pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0;
73#endif
74 debug("PBR0: %08x POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0);
75
76 pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1;
77#if (CONFIG_SYS_PCMCIA_POR1 != 0)
78 pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1 | timings;
79#else
80 pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1;
81#endif
82 debug("PBR1: %08x POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1);
83
84 pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2;
85#if (CONFIG_SYS_PCMCIA_POR2 != 0)
86 pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2 | timings;
87#else
88 pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2;
89#endif
90 debug("PBR2: %08x POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2);
91
92 pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3;
93#if (CONFIG_SYS_PCMCIA_POR3 != 0)
94 pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3 | timings;
95#else
96 pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3;
97#endif
98 debug("PBR3: %08x POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3);
99
100
101
102
103 pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4;
104#if (CONFIG_SYS_PCMCIA_POR4 != 0)
105 pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4 | timings;
106#else
107 pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4;
108#endif
109 debug("PBR4: %08x POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4);
110
111 pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5;
112#if (CONFIG_SYS_PCMCIA_POR5 != 0)
113 pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5 | timings;
114#else
115 pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5;
116#endif
117 debug("PBR5: %08x POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5);
118
119 pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6;
120#if (CONFIG_SYS_PCMCIA_POR6 != 0)
121 pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6 | timings;
122#else
123 pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6;
124#endif
125 debug("PBR6: %08x POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6);
126
127 pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7;
128#if (CONFIG_SYS_PCMCIA_POR7 != 0)
129 pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7 | timings;
130#else
131 pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7;
132#endif
133 debug("PBR7: %08x POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7);
134
135}
136
137int ide_preinit(void)
138{
139 int i;
140
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);
153 }
154
155 return 0;
156}
157
158int ide_init_postreset(void)
159{
160 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
161 volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia);
162
163
164 pcmp->pcmc_pgcrb = 0;
165
166
167 pio_mode = 0;
168 set_pcmcia_timing(pio_mode);
169 return 0;
170}
171#endif
172
173#ifdef CONFIG_IDE_8xx_PCCARD
174int ide_preinit(void)
175{
176 ide_devices_found = 0;
177
178 pcmcia_on();
179 if (!ide_devices_found)
180 return 1;
181 udelay(1000000);
182 return 0;
183}
184#endif
185