Fixed tools/env utilities
[u-boot-openmoko/mini2440.git] / drivers / pcmcia / tqm8xx_pcmcia.c
blob132c7a5169b649e59a255b5265a34e4f0eff345d
1 /* -------------------------------------------------------------------- */
2 /* TQM8xxL Boards by TQ Components */
3 /* SC8xx Boards by SinoVee Microsystems */
4 /* -------------------------------------------------------------------- */
5 #include <common.h>
6 #ifdef CONFIG_8xx
7 #include <mpc8xx.h>
8 #endif
9 #include <pcmcia.h>
11 #undef CONFIG_PCMCIA
13 #if defined(CONFIG_CMD_PCMCIA)
14 #define CONFIG_PCMCIA
15 #endif
17 #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
18 #define CONFIG_PCMCIA
19 #endif
21 #if defined(CONFIG_PCMCIA) \
22 && (defined(CONFIG_TQM8xxL) || defined(CONFIG_SVM_SC8xx))
24 #if defined(CONFIG_VIRTLAB2)
25 #define PCMCIA_BOARD_MSG "Virtlab2"
26 #elif defined(CONFIG_TQM8xxL)
27 #define PCMCIA_BOARD_MSG "TQM8xxL"
28 #elif defined(CONFIG_SVM_SC8xx)
29 #define PCMCIA_BOARD_MSG "SC8xx"
30 #endif
32 #if defined(CONFIG_NSCU)
34 #define power_config(slot) do {} while (0)
35 #define power_off(slot) do {} while (0)
36 #define power_on_5_0(slot) do {} while (0)
37 #define power_on_3_3(slot) do {} while (0)
39 #elif defined(CONFIG_HMI10)
41 static inline void power_config(int slot)
43 volatile immap_t *immap = (immap_t *)CFG_IMMR;
45 * Configure Port B pins for
46 * 5 Volts Enable and 3 Volts enable
48 immap->im_cpm.cp_pbpar &= ~(0x00000300);
51 static inline void power_off(int slot)
53 volatile immap_t *immap = (immap_t *)CFG_IMMR;
54 /* remove all power */
55 immap->im_cpm.cp_pbdat |= 0x00000300;
58 static inline void power_on_5_0(int slot)
60 volatile immap_t *immap = (immap_t *)CFG_IMMR;
61 immap->im_cpm.cp_pbdat &= ~(0x0000100);
62 immap->im_cpm.cp_pbdir |= 0x00000300;
65 static inline void power_on_3_3(int slot)
67 volatile immap_t *immap = (immap_t *)CFG_IMMR;
68 immap->im_cpm.cp_pbdat &= ~(0x0000200);
69 immap->im_cpm.cp_pbdir |= 0x00000300;
72 #elif defined(CONFIG_VIRTLAB2)
74 #define power_config(slot) do {} while (0)
75 static inline void power_off(int slot)
77 volatile unsigned char *powerctl =
78 (volatile unsigned char *)PCMCIA_CTRL;
79 *powerctl = 0;
82 static inline void power_on_5_0(int slot)
84 volatile unsigned char *powerctl =
85 (volatile unsigned char *)PCMCIA_CTRL;
86 *powerctl = 2; /* Enable 5V Vccout */
89 static inline void power_on_3_3(int slot)
91 volatile unsigned char *powerctl =
92 (volatile unsigned char *)PCMCIA_CTRL;
93 *powerctl = 1; /* Enable 3.3V Vccout */
96 #else
98 static inline void power_config(int slot)
100 volatile immap_t *immap = (immap_t *)CFG_IMMR;
102 * Configure Port C pins for
103 * 5 Volts Enable and 3 Volts enable
105 immap->im_ioport.iop_pcpar &= ~(0x0002 | 0x0004);
106 immap->im_ioport.iop_pcso &= ~(0x0002 | 0x0004);
109 static inline void power_off(int slot)
111 volatile immap_t *immap = (immap_t *)CFG_IMMR;
112 immap->im_ioport.iop_pcdat &= ~(0x0002 | 0x0004);
115 static inline void power_on_5_0(int slot)
117 volatile immap_t *immap = (immap_t *)CFG_IMMR;
118 immap->im_ioport.iop_pcdat |= 0x0004;
119 immap->im_ioport.iop_pcdir |= (0x0002 | 0x0004);
122 static inline void power_on_3_3(int slot)
124 volatile immap_t *immap = (immap_t *)CFG_IMMR;
125 immap->im_ioport.iop_pcdat |= 0x0002;
126 immap->im_ioport.iop_pcdir |= (0x0002 | 0x0004);
129 #endif
131 #ifdef CONFIG_HMI10
132 static inline int check_card_is_absent(int slot)
134 volatile pcmconf8xx_t *pcmp =
135 (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
136 return pcmp->pcmc_pipr & (0x10000000 >> (slot << 4));
138 #else
139 static inline int check_card_is_absent(int slot)
141 volatile pcmconf8xx_t *pcmp =
142 (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
143 return pcmp->pcmc_pipr & (0x18000000 >> (slot << 4));
145 #endif
147 #ifdef NSCU_OE_INV
148 #define NSCU_GCRX_CXOE 0
149 #else
150 #define NSCU_GCRX_CXOE __MY_PCMCIA_GCRX_CXOE
151 #endif
153 int pcmcia_hardware_enable(int slot)
155 volatile pcmconf8xx_t *pcmp =
156 (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
157 volatile sysconf8xx_t *sysp =
158 (sysconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_siu_conf));
159 uint reg, mask;
161 debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
163 udelay(10000);
166 * Configure SIUMCR to enable PCMCIA port B
167 * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
169 sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
171 /* clear interrupt state, and disable interrupts */
172 pcmp->pcmc_pscr = PCMCIA_MASK(slot);
173 pcmp->pcmc_per &= ~PCMCIA_MASK(slot);
176 * Disable interrupts, DMA, and PCMCIA buffers
177 * (isolate the interface) and assert RESET signal
179 debug ("Disable PCMCIA buffers and assert RESET\n");
180 reg = 0;
181 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
182 reg |= NSCU_GCRX_CXOE;
184 PCMCIA_PGCRX(slot) = reg;
185 udelay(500);
187 power_config(slot);
188 power_off(slot);
191 * Make sure there is a card in the slot, then configure the interface.
193 udelay(10000);
194 debug ("[%d] %s: PIPR(%p)=0x%x\n", __LINE__,__FUNCTION__,
195 &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
197 if (check_card_is_absent(slot)) {
198 printf (" No Card found\n");
199 return (1);
203 * Power On.
205 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
206 reg = pcmp->pcmc_pipr;
207 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
208 reg,
209 (reg&PCMCIA_VS1(slot))?"n":"ff",
210 (reg&PCMCIA_VS2(slot))?"n":"ff");
212 if ((reg & mask) == mask) {
213 power_on_5_0(slot);
214 puts (" 5.0V card found: ");
215 } else {
216 power_on_3_3(slot);
217 puts (" 3.3V card found: ");
220 #if 0
221 /* VCC switch error flag, PCMCIA slot INPACK_ pin */
222 cp->cp_pbdir &= ~(0x0020 | 0x0010);
223 cp->cp_pbpar &= ~(0x0020 | 0x0010);
224 udelay(500000);
225 #endif
227 udelay(1000);
228 debug ("Enable PCMCIA buffers and stop RESET\n");
229 reg = PCMCIA_PGCRX(slot);
230 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
231 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
232 reg &= ~NSCU_GCRX_CXOE;
234 PCMCIA_PGCRX(slot) = reg;
236 udelay(250000); /* some cards need >150 ms to come up :-( */
238 debug ("# hardware_enable done\n");
240 return (0);
244 #if defined(CONFIG_CMD_PCMCIA)
245 int pcmcia_hardware_disable(int slot)
247 u_long reg;
249 debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
252 /* remove all power */
253 power_off(slot);
255 debug ("Disable PCMCIA buffers and assert RESET\n");
256 reg = 0;
257 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
258 reg |= NSCU_GCRX_CXOE; /* active low */
260 PCMCIA_PGCRX(slot) = reg;
262 udelay(10000);
264 return (0);
266 #endif
268 int pcmcia_voltage_set(int slot, int vcc, int vpp)
270 #ifndef CONFIG_NSCU
271 u_long reg;
272 # ifdef DEBUG
273 volatile pcmconf8xx_t *pcmp =
274 (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
275 # endif
277 debug ("voltage_set: " PCMCIA_BOARD_MSG
278 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
279 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
282 * Disable PCMCIA buffers (isolate the interface)
283 * and assert RESET signal
285 debug ("Disable PCMCIA buffers and assert RESET\n");
286 reg = PCMCIA_PGCRX(slot);
287 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
288 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
289 reg |= NSCU_GCRX_CXOE; /* active low */
291 PCMCIA_PGCRX(slot) = reg;
292 udelay(500);
294 debug ("PCMCIA power OFF\n");
295 power_config(slot);
296 power_off(slot);
298 switch(vcc) {
299 case 0: break;
300 case 33: power_on_3_3(slot); break;
301 case 50: power_on_5_0(slot); break;
302 default: goto done;
305 /* Checking supported voltages */
307 debug("PIPR: 0x%x --> %s\n", pcmp->pcmc_pipr,
308 (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
310 if (vcc)
311 debug("PCMCIA powered at %sV\n", (vcc == 50) ? "5.0" : "3.3");
312 else
313 debug("PCMCIA powered down\n");
315 done:
316 debug("Enable PCMCIA buffers and stop RESET\n");
317 reg = PCMCIA_PGCRX(slot);
318 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
319 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
320 reg &= ~NSCU_GCRX_CXOE; /* active low */
322 PCMCIA_PGCRX(slot) = reg;
323 udelay(500);
325 debug("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", slot+'A');
326 #endif /* CONFIG_NSCU */
327 return (0);
330 #endif /* CONFIG_PCMCIA && (CONFIG_TQM8xxL || CONFIG_SVM_SC8xx) */