blob: 859cbe057520e8397168d71fccfbaac6632b56ae [file] [log] [blame]
Wolfgang Denk50440e72006-07-10 23:07:28 +02001/* -------------------------------------------------------------------- */
2/* TQM8xxL Boards by TQ Components */
3/* SC8xx Boards by SinoVee Microsystems */
4/* -------------------------------------------------------------------- */
5#include <common.h>
Marek Vasut03e36812011-10-05 02:51:55 +00006#include <asm/io.h>
Wolfgang Denk31560d12006-07-21 15:24:56 +02007#ifdef CONFIG_8xx
Wolfgang Denk50440e72006-07-10 23:07:28 +02008#include <mpc8xx.h>
Wolfgang Denk31560d12006-07-21 15:24:56 +02009#endif
Wolfgang Denk50440e72006-07-10 23:07:28 +020010#include <pcmcia.h>
11
12#undef CONFIG_PCMCIA
13
Jon Loeliger82ecaad2007-07-09 17:39:42 -050014#if defined(CONFIG_CMD_PCMCIA)
Wolfgang Denk50440e72006-07-10 23:07:28 +020015#define CONFIG_PCMCIA
16#endif
17
Jon Loeliger82ecaad2007-07-09 17:39:42 -050018#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
Wolfgang Denk50440e72006-07-10 23:07:28 +020019#define CONFIG_PCMCIA
20#endif
21
22#if defined(CONFIG_PCMCIA) \
23 && (defined(CONFIG_TQM8xxL) || defined(CONFIG_SVM_SC8xx))
24
25#if defined(CONFIG_VIRTLAB2)
26#define PCMCIA_BOARD_MSG "Virtlab2"
27#elif defined(CONFIG_TQM8xxL)
28#define PCMCIA_BOARD_MSG "TQM8xxL"
29#elif defined(CONFIG_SVM_SC8xx)
30#define PCMCIA_BOARD_MSG "SC8xx"
31#endif
32
33#if defined(CONFIG_NSCU)
34
Marek Vasut03e36812011-10-05 02:51:55 +000035static inline void power_config(int slot) {}
36static inline void power_off(int slot) {}
37static inline void power_on_5_0(int slot) {}
38static inline void power_on_3_3(int slot) {}
Wolfgang Denk50440e72006-07-10 23:07:28 +020039
Wolfgang Denk50440e72006-07-10 23:07:28 +020040#elif defined(CONFIG_VIRTLAB2)
41
Marek Vasut03e36812011-10-05 02:51:55 +000042static inline void power_config(int slot) {}
43
Wolfgang Denk50440e72006-07-10 23:07:28 +020044static inline void power_off(int slot)
45{
Marek Vasut03e36812011-10-05 02:51:55 +000046 out_be32(PCMCIA_CTRL, 0);
Wolfgang Denk50440e72006-07-10 23:07:28 +020047}
48
49static inline void power_on_5_0(int slot)
50{
Marek Vasut03e36812011-10-05 02:51:55 +000051 /* Enable 5V Vccout */
52 out_be32(PCMCIA_CTRL, 2);
Wolfgang Denk50440e72006-07-10 23:07:28 +020053}
54
55static inline void power_on_3_3(int slot)
56{
Marek Vasut03e36812011-10-05 02:51:55 +000057 /* Enable 3.3V Vccout */
58 out_be32(PCMCIA_CTRL, 1);
Wolfgang Denk50440e72006-07-10 23:07:28 +020059}
60
61#else
62
63static inline void power_config(int slot)
64{
Marek Vasut03e36812011-10-05 02:51:55 +000065 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Wolfgang Denk50440e72006-07-10 23:07:28 +020066 /*
Marek Vasut03e36812011-10-05 02:51:55 +000067 * Configure Port C pins for
68 * 5 Volts Enable and 3 Volts enable
69 */
70 clrbits_be16(&immap->im_ioport.iop_pcpar, 0x0002 | 0x0004);
71 clrbits_be16(&immap->im_ioport.iop_pcso, 0x0002 | 0x0004);
Wolfgang Denk50440e72006-07-10 23:07:28 +020072}
73
74static inline void power_off(int slot)
75{
Marek Vasut03e36812011-10-05 02:51:55 +000076 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
77 clrbits_be16(&immap->im_ioport.iop_pcdat, 0x0002 | 0x0004);
Wolfgang Denk50440e72006-07-10 23:07:28 +020078}
79
80static inline void power_on_5_0(int slot)
81{
Marek Vasut03e36812011-10-05 02:51:55 +000082 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
83 setbits_be16(&immap->im_ioport.iop_pcdat, 0x0004);
84 setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
Wolfgang Denk50440e72006-07-10 23:07:28 +020085}
86
87static inline void power_on_3_3(int slot)
88{
Marek Vasut03e36812011-10-05 02:51:55 +000089 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
90 setbits_be16(&immap->im_ioport.iop_pcdat, 0x0002);
91 setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
Wolfgang Denk50440e72006-07-10 23:07:28 +020092}
93
Marek Vasut03e36812011-10-05 02:51:55 +000094#endif
95
96/*
97 * Function to retrieve the PIPR register, used for debuging purposes.
98 */
99static inline uint32_t debug_get_pipr(void)
100{
101 uint32_t pipr = 0;
102#ifdef DEBUG
103 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
104 pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
Wolfgang Denk50440e72006-07-10 23:07:28 +0200105#endif
Marek Vasut03e36812011-10-05 02:51:55 +0000106 return pipr;
107}
108
Wolfgang Denk50440e72006-07-10 23:07:28 +0200109
Wolfgang Denk50440e72006-07-10 23:07:28 +0200110static inline int check_card_is_absent(int slot)
111{
Marek Vasut03e36812011-10-05 02:51:55 +0000112 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
113 uint32_t pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
114 return pipr & (0x18000000 >> (slot << 4));
Wolfgang Denk50440e72006-07-10 23:07:28 +0200115}
Wolfgang Denk50440e72006-07-10 23:07:28 +0200116
117#ifdef NSCU_OE_INV
118#define NSCU_GCRX_CXOE 0
119#else
120#define NSCU_GCRX_CXOE __MY_PCMCIA_GCRX_CXOE
121#endif
122
123int pcmcia_hardware_enable(int slot)
124{
Marek Vasut03e36812011-10-05 02:51:55 +0000125 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200126 uint reg, mask;
127
Marek Vasut03e36812011-10-05 02:51:55 +0000128 debug("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
Wolfgang Denk50440e72006-07-10 23:07:28 +0200129
130 udelay(10000);
131
132 /*
Marek Vasut03e36812011-10-05 02:51:55 +0000133 * Configure SIUMCR to enable PCMCIA port B
134 * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
135 */
Wolfgang Denk50440e72006-07-10 23:07:28 +0200136
Marek Vasut03e36812011-10-05 02:51:55 +0000137 /* Set DBGC to 00 */
138 clrbits_be32(&immap->im_siu_conf.sc_siumcr, SIUMCR_DBGC11);
139
140 /* Clear interrupt state, and disable interrupts */
141 out_be32(&immap->im_pcmcia.pcmc_pscr, PCMCIA_MASK(slot));
142 clrbits_be32(&immap->im_pcmcia.pcmc_per, PCMCIA_MASK(slot));
Wolfgang Denk50440e72006-07-10 23:07:28 +0200143
144 /*
Marek Vasut03e36812011-10-05 02:51:55 +0000145 * Disable interrupts, DMA, and PCMCIA buffers
146 * (isolate the interface) and assert RESET signal
147 */
148 debug("Disable PCMCIA buffers and assert RESET\n");
Wolfgang Denk50440e72006-07-10 23:07:28 +0200149 reg = 0;
150 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
151 reg |= NSCU_GCRX_CXOE;
152
153 PCMCIA_PGCRX(slot) = reg;
154 udelay(500);
155
156 power_config(slot);
157 power_off(slot);
158
159 /*
160 * Make sure there is a card in the slot, then configure the interface.
161 */
162 udelay(10000);
Marek Vasut03e36812011-10-05 02:51:55 +0000163 reg = debug_get_pipr();
164 debug("[%d] %s: PIPR(%p)=0x%x\n", __LINE__, __FUNCTION__,
165 &immap->im_pcmcia.pcmc_pipr, reg);
Wolfgang Denkba940932006-07-19 13:50:38 +0200166
Wolfgang Denk50440e72006-07-10 23:07:28 +0200167 if (check_card_is_absent(slot)) {
168 printf (" No Card found\n");
169 return (1);
170 }
171
172 /*
Marek Vasut03e36812011-10-05 02:51:55 +0000173 * Power On.
174 */
Wolfgang Denk50440e72006-07-10 23:07:28 +0200175 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
Marek Vasut03e36812011-10-05 02:51:55 +0000176 reg = in_be32(&immap->im_pcmcia.pcmc_pipr);
Wolfgang Denk50440e72006-07-10 23:07:28 +0200177 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
178 reg,
Marek Vasut03e36812011-10-05 02:51:55 +0000179 (reg & PCMCIA_VS1(slot)) ? "n" : "ff",
180 (reg & PCMCIA_VS2(slot)) ? "n" : "ff");
Wolfgang Denkba940932006-07-19 13:50:38 +0200181
Wolfgang Denk50440e72006-07-10 23:07:28 +0200182 if ((reg & mask) == mask) {
183 power_on_5_0(slot);
184 puts (" 5.0V card found: ");
185 } else {
186 power_on_3_3(slot);
187 puts (" 3.3V card found: ");
188 }
189
190#if 0
191 /* VCC switch error flag, PCMCIA slot INPACK_ pin */
192 cp->cp_pbdir &= ~(0x0020 | 0x0010);
193 cp->cp_pbpar &= ~(0x0020 | 0x0010);
194 udelay(500000);
195#endif
196
197 udelay(1000);
Marek Vasut03e36812011-10-05 02:51:55 +0000198 debug("Enable PCMCIA buffers and stop RESET\n");
Wolfgang Denk50440e72006-07-10 23:07:28 +0200199 reg = PCMCIA_PGCRX(slot);
200 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
201 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
202 reg &= ~NSCU_GCRX_CXOE;
Wolfgang Denkba940932006-07-19 13:50:38 +0200203
Wolfgang Denk50440e72006-07-10 23:07:28 +0200204 PCMCIA_PGCRX(slot) = reg;
205
206 udelay(250000); /* some cards need >150 ms to come up :-( */
207
Marek Vasut03e36812011-10-05 02:51:55 +0000208 debug("# hardware_enable done\n");
Wolfgang Denk50440e72006-07-10 23:07:28 +0200209
210 return (0);
211}
212
213
Jon Loeliger82ecaad2007-07-09 17:39:42 -0500214#if defined(CONFIG_CMD_PCMCIA)
Wolfgang Denk50440e72006-07-10 23:07:28 +0200215int pcmcia_hardware_disable(int slot)
216{
Wolfgang Denk50440e72006-07-10 23:07:28 +0200217 u_long reg;
218
Marek Vasut03e36812011-10-05 02:51:55 +0000219 debug("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
Wolfgang Denk50440e72006-07-10 23:07:28 +0200220
221 /* remove all power */
222 power_off(slot);
223
Marek Vasut03e36812011-10-05 02:51:55 +0000224 debug("Disable PCMCIA buffers and assert RESET\n");
Wolfgang Denk50440e72006-07-10 23:07:28 +0200225 reg = 0;
226 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
227 reg |= NSCU_GCRX_CXOE; /* active low */
228
229 PCMCIA_PGCRX(slot) = reg;
230
231 udelay(10000);
232
233 return (0);
234}
Jon Loeliger30c2f242007-07-10 11:13:21 -0500235#endif
Wolfgang Denk50440e72006-07-10 23:07:28 +0200236
237int pcmcia_voltage_set(int slot, int vcc, int vpp)
238{
239#ifndef CONFIG_NSCU
Wolfgang Denk31560d12006-07-21 15:24:56 +0200240 u_long reg;
Marek Vasut03e36812011-10-05 02:51:55 +0000241 uint32_t pipr = 0;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200242
Marek Vasut03e36812011-10-05 02:51:55 +0000243 debug("voltage_set: " PCMCIA_BOARD_MSG
Wolfgang Denk50440e72006-07-10 23:07:28 +0200244 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
245 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
246
247 /*
Marek Vasut03e36812011-10-05 02:51:55 +0000248 * Disable PCMCIA buffers (isolate the interface)
249 * and assert RESET signal
250 */
251 debug("Disable PCMCIA buffers and assert RESET\n");
Wolfgang Denk50440e72006-07-10 23:07:28 +0200252 reg = PCMCIA_PGCRX(slot);
253 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
254 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
255 reg |= NSCU_GCRX_CXOE; /* active low */
Wolfgang Denkba940932006-07-19 13:50:38 +0200256
Wolfgang Denk50440e72006-07-10 23:07:28 +0200257 PCMCIA_PGCRX(slot) = reg;
258 udelay(500);
259
Marek Vasut03e36812011-10-05 02:51:55 +0000260 debug("PCMCIA power OFF\n");
Wolfgang Denk50440e72006-07-10 23:07:28 +0200261 power_config(slot);
262 power_off(slot);
263
264 switch(vcc) {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200265 case 0: break;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200266 case 33: power_on_3_3(slot); break;
267 case 50: power_on_5_0(slot); break;
Wolfgang Denka1be4762008-05-20 16:00:29 +0200268 default: goto done;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200269 }
270
271 /* Checking supported voltages */
Marek Vasut03e36812011-10-05 02:51:55 +0000272 pipr = debug_get_pipr();
273 debug("PIPR: 0x%x --> %s\n", pipr,
274 (pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
Wolfgang Denk50440e72006-07-10 23:07:28 +0200275
276 if (vcc)
277 debug("PCMCIA powered at %sV\n", (vcc == 50) ? "5.0" : "3.3");
278 else
279 debug("PCMCIA powered down\n");
280
281done:
282 debug("Enable PCMCIA buffers and stop RESET\n");
283 reg = PCMCIA_PGCRX(slot);
284 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
285 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
286 reg &= ~NSCU_GCRX_CXOE; /* active low */
287
288 PCMCIA_PGCRX(slot) = reg;
289 udelay(500);
290
291 debug("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", slot+'A');
292#endif /* CONFIG_NSCU */
Marek Vasut03e36812011-10-05 02:51:55 +0000293 return 0;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200294}
295
296#endif /* CONFIG_PCMCIA && (CONFIG_TQM8xxL || CONFIG_SVM_SC8xx) */