blob: 8b7447853bf7de655dfdcc62bec75cc1f82e0d4f [file] [log] [blame]
Wolfgang Denk9d407992006-07-10 23:07:28 +02001/* -------------------------------------------------------------------- */
2/* TQM8xxL Boards by TQ Components */
3/* SC8xx Boards by SinoVee Microsystems */
4/* -------------------------------------------------------------------- */
5#include <common.h>
Marek Vasut6e967032011-10-05 02:51:55 +00006#include <asm/io.h>
Wolfgang Denk966083e2006-07-21 15:24:56 +02007#ifdef CONFIG_8xx
Wolfgang Denk9d407992006-07-10 23:07:28 +02008#include <mpc8xx.h>
Wolfgang Denk966083e2006-07-21 15:24:56 +02009#endif
Wolfgang Denk9d407992006-07-10 23:07:28 +020010#include <pcmcia.h>
11
12#undef CONFIG_PCMCIA
13
Jon Loeligercb51c0b2007-07-09 17:39:42 -050014#if defined(CONFIG_CMD_PCMCIA)
Wolfgang Denk9d407992006-07-10 23:07:28 +020015#define CONFIG_PCMCIA
16#endif
17
Jon Loeligercb51c0b2007-07-09 17:39:42 -050018#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
Wolfgang Denk9d407992006-07-10 23:07:28 +020019#define CONFIG_PCMCIA
20#endif
21
22#if defined(CONFIG_PCMCIA) \
Masahiro Yamadad1a4aaf2014-08-06 12:59:52 +090023 && defined(CONFIG_TQM8xxL)
Wolfgang Denk9d407992006-07-10 23:07:28 +020024
25#if defined(CONFIG_VIRTLAB2)
26#define PCMCIA_BOARD_MSG "Virtlab2"
27#elif defined(CONFIG_TQM8xxL)
28#define PCMCIA_BOARD_MSG "TQM8xxL"
Wolfgang Denk9d407992006-07-10 23:07:28 +020029#endif
30
31#if defined(CONFIG_NSCU)
32
Marek Vasut6e967032011-10-05 02:51:55 +000033static inline void power_config(int slot) {}
34static inline void power_off(int slot) {}
35static inline void power_on_5_0(int slot) {}
36static inline void power_on_3_3(int slot) {}
Wolfgang Denk9d407992006-07-10 23:07:28 +020037
Wolfgang Denk9d407992006-07-10 23:07:28 +020038#elif defined(CONFIG_VIRTLAB2)
39
Marek Vasut6e967032011-10-05 02:51:55 +000040static inline void power_config(int slot) {}
41
Wolfgang Denk9d407992006-07-10 23:07:28 +020042static inline void power_off(int slot)
43{
Marek Vasut3ebafbf2011-10-21 14:17:24 +000044 volatile unsigned __iomem *addr;
45 addr = (volatile unsigned __iomem *)PCMCIA_CTRL;
46
47 out_be32(addr, 0);
Wolfgang Denk9d407992006-07-10 23:07:28 +020048}
49
50static inline void power_on_5_0(int slot)
51{
Marek Vasut3ebafbf2011-10-21 14:17:24 +000052 volatile unsigned __iomem *addr;
53 addr = (volatile unsigned __iomem *)PCMCIA_CTRL;
54
Marek Vasut6e967032011-10-05 02:51:55 +000055 /* Enable 5V Vccout */
Marek Vasut3ebafbf2011-10-21 14:17:24 +000056 out_be32(addr, 2);
Wolfgang Denk9d407992006-07-10 23:07:28 +020057}
58
59static inline void power_on_3_3(int slot)
60{
Marek Vasut3ebafbf2011-10-21 14:17:24 +000061 volatile unsigned __iomem *addr;
62 addr = (volatile unsigned __iomem *)PCMCIA_CTRL;
63
Marek Vasut6e967032011-10-05 02:51:55 +000064 /* Enable 3.3V Vccout */
Marek Vasut3ebafbf2011-10-21 14:17:24 +000065 out_be32(addr, 1);
Wolfgang Denk9d407992006-07-10 23:07:28 +020066}
67
68#else
69
70static inline void power_config(int slot)
71{
Marek Vasut6e967032011-10-05 02:51:55 +000072 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Wolfgang Denk9d407992006-07-10 23:07:28 +020073 /*
Marek Vasut6e967032011-10-05 02:51:55 +000074 * Configure Port C pins for
75 * 5 Volts Enable and 3 Volts enable
76 */
77 clrbits_be16(&immap->im_ioport.iop_pcpar, 0x0002 | 0x0004);
78 clrbits_be16(&immap->im_ioport.iop_pcso, 0x0002 | 0x0004);
Wolfgang Denk9d407992006-07-10 23:07:28 +020079}
80
81static inline void power_off(int slot)
82{
Marek Vasut6e967032011-10-05 02:51:55 +000083 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
84 clrbits_be16(&immap->im_ioport.iop_pcdat, 0x0002 | 0x0004);
Wolfgang Denk9d407992006-07-10 23:07:28 +020085}
86
87static inline void power_on_5_0(int slot)
88{
Marek Vasut6e967032011-10-05 02:51:55 +000089 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
90 setbits_be16(&immap->im_ioport.iop_pcdat, 0x0004);
91 setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
Wolfgang Denk9d407992006-07-10 23:07:28 +020092}
93
94static inline void power_on_3_3(int slot)
95{
Marek Vasut6e967032011-10-05 02:51:55 +000096 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
97 setbits_be16(&immap->im_ioport.iop_pcdat, 0x0002);
98 setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
Wolfgang Denk9d407992006-07-10 23:07:28 +020099}
100
101#endif
102
Marek Vasut6e967032011-10-05 02:51:55 +0000103/*
104 * Function to retrieve the PIPR register, used for debuging purposes.
105 */
106static inline uint32_t debug_get_pipr(void)
107{
108 uint32_t pipr = 0;
109#ifdef DEBUG
110 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
111 pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
112#endif
113 return pipr;
114}
115
116
Wolfgang Denk9d407992006-07-10 23:07:28 +0200117static inline int check_card_is_absent(int slot)
118{
Marek Vasut6e967032011-10-05 02:51:55 +0000119 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
120 uint32_t pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
121 return pipr & (0x18000000 >> (slot << 4));
Wolfgang Denk9d407992006-07-10 23:07:28 +0200122}
Wolfgang Denk9d407992006-07-10 23:07:28 +0200123
124#ifdef NSCU_OE_INV
125#define NSCU_GCRX_CXOE 0
126#else
127#define NSCU_GCRX_CXOE __MY_PCMCIA_GCRX_CXOE
128#endif
129
130int pcmcia_hardware_enable(int slot)
131{
Marek Vasut6e967032011-10-05 02:51:55 +0000132 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200133 uint reg, mask;
134
Marek Vasut6e967032011-10-05 02:51:55 +0000135 debug("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
Wolfgang Denk9d407992006-07-10 23:07:28 +0200136
137 udelay(10000);
138
139 /*
Marek Vasut6e967032011-10-05 02:51:55 +0000140 * Configure SIUMCR to enable PCMCIA port B
141 * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
142 */
Wolfgang Denk9d407992006-07-10 23:07:28 +0200143
Marek Vasut6e967032011-10-05 02:51:55 +0000144 /* Set DBGC to 00 */
145 clrbits_be32(&immap->im_siu_conf.sc_siumcr, SIUMCR_DBGC11);
146
147 /* Clear interrupt state, and disable interrupts */
148 out_be32(&immap->im_pcmcia.pcmc_pscr, PCMCIA_MASK(slot));
149 clrbits_be32(&immap->im_pcmcia.pcmc_per, PCMCIA_MASK(slot));
Wolfgang Denk9d407992006-07-10 23:07:28 +0200150
151 /*
Marek Vasut6e967032011-10-05 02:51:55 +0000152 * Disable interrupts, DMA, and PCMCIA buffers
153 * (isolate the interface) and assert RESET signal
154 */
155 debug("Disable PCMCIA buffers and assert RESET\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200156 reg = 0;
157 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
158 reg |= NSCU_GCRX_CXOE;
159
160 PCMCIA_PGCRX(slot) = reg;
161 udelay(500);
162
163 power_config(slot);
164 power_off(slot);
165
166 /*
167 * Make sure there is a card in the slot, then configure the interface.
168 */
169 udelay(10000);
Marek Vasut6e967032011-10-05 02:51:55 +0000170 reg = debug_get_pipr();
171 debug("[%d] %s: PIPR(%p)=0x%x\n", __LINE__, __FUNCTION__,
172 &immap->im_pcmcia.pcmc_pipr, reg);
Wolfgang Denkb87dfd22006-07-19 13:50:38 +0200173
Wolfgang Denk9d407992006-07-10 23:07:28 +0200174 if (check_card_is_absent(slot)) {
175 printf (" No Card found\n");
176 return (1);
177 }
178
179 /*
Marek Vasut6e967032011-10-05 02:51:55 +0000180 * Power On.
181 */
Wolfgang Denk9d407992006-07-10 23:07:28 +0200182 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
Marek Vasut6e967032011-10-05 02:51:55 +0000183 reg = in_be32(&immap->im_pcmcia.pcmc_pipr);
Wolfgang Denk9d407992006-07-10 23:07:28 +0200184 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
185 reg,
Marek Vasut6e967032011-10-05 02:51:55 +0000186 (reg & PCMCIA_VS1(slot)) ? "n" : "ff",
187 (reg & PCMCIA_VS2(slot)) ? "n" : "ff");
Wolfgang Denkb87dfd22006-07-19 13:50:38 +0200188
Wolfgang Denk9d407992006-07-10 23:07:28 +0200189 if ((reg & mask) == mask) {
190 power_on_5_0(slot);
191 puts (" 5.0V card found: ");
192 } else {
193 power_on_3_3(slot);
194 puts (" 3.3V card found: ");
195 }
196
197#if 0
198 /* VCC switch error flag, PCMCIA slot INPACK_ pin */
199 cp->cp_pbdir &= ~(0x0020 | 0x0010);
200 cp->cp_pbpar &= ~(0x0020 | 0x0010);
201 udelay(500000);
202#endif
203
204 udelay(1000);
Marek Vasut6e967032011-10-05 02:51:55 +0000205 debug("Enable PCMCIA buffers and stop RESET\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200206 reg = PCMCIA_PGCRX(slot);
207 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
208 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
209 reg &= ~NSCU_GCRX_CXOE;
Wolfgang Denkb87dfd22006-07-19 13:50:38 +0200210
Wolfgang Denk9d407992006-07-10 23:07:28 +0200211 PCMCIA_PGCRX(slot) = reg;
212
213 udelay(250000); /* some cards need >150 ms to come up :-( */
214
Marek Vasut6e967032011-10-05 02:51:55 +0000215 debug("# hardware_enable done\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200216
217 return (0);
218}
219
220
Jon Loeligercb51c0b2007-07-09 17:39:42 -0500221#if defined(CONFIG_CMD_PCMCIA)
Wolfgang Denk9d407992006-07-10 23:07:28 +0200222int pcmcia_hardware_disable(int slot)
223{
Wolfgang Denk9d407992006-07-10 23:07:28 +0200224 u_long reg;
225
Marek Vasut6e967032011-10-05 02:51:55 +0000226 debug("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
Wolfgang Denk9d407992006-07-10 23:07:28 +0200227
228 /* remove all power */
229 power_off(slot);
230
Marek Vasut6e967032011-10-05 02:51:55 +0000231 debug("Disable PCMCIA buffers and assert RESET\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200232 reg = 0;
233 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
234 reg |= NSCU_GCRX_CXOE; /* active low */
235
236 PCMCIA_PGCRX(slot) = reg;
237
238 udelay(10000);
239
240 return (0);
241}
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500242#endif
Wolfgang Denk9d407992006-07-10 23:07:28 +0200243
244int pcmcia_voltage_set(int slot, int vcc, int vpp)
245{
246#ifndef CONFIG_NSCU
Wolfgang Denk966083e2006-07-21 15:24:56 +0200247 u_long reg;
Marek Vasut6e967032011-10-05 02:51:55 +0000248 uint32_t pipr = 0;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200249
Marek Vasut6e967032011-10-05 02:51:55 +0000250 debug("voltage_set: " PCMCIA_BOARD_MSG
Wolfgang Denk9d407992006-07-10 23:07:28 +0200251 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
252 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
253
254 /*
Marek Vasut6e967032011-10-05 02:51:55 +0000255 * Disable PCMCIA buffers (isolate the interface)
256 * and assert RESET signal
257 */
258 debug("Disable PCMCIA buffers and assert RESET\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200259 reg = PCMCIA_PGCRX(slot);
260 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
261 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
262 reg |= NSCU_GCRX_CXOE; /* active low */
Wolfgang Denkb87dfd22006-07-19 13:50:38 +0200263
Wolfgang Denk9d407992006-07-10 23:07:28 +0200264 PCMCIA_PGCRX(slot) = reg;
265 udelay(500);
266
Marek Vasut6e967032011-10-05 02:51:55 +0000267 debug("PCMCIA power OFF\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200268 power_config(slot);
269 power_off(slot);
270
271 switch(vcc) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200272 case 0: break;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200273 case 33: power_on_3_3(slot); break;
274 case 50: power_on_5_0(slot); break;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200275 default: goto done;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200276 }
277
278 /* Checking supported voltages */
Marek Vasut6e967032011-10-05 02:51:55 +0000279 pipr = debug_get_pipr();
280 debug("PIPR: 0x%x --> %s\n", pipr,
281 (pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200282
283 if (vcc)
284 debug("PCMCIA powered at %sV\n", (vcc == 50) ? "5.0" : "3.3");
285 else
286 debug("PCMCIA powered down\n");
287
288done:
289 debug("Enable PCMCIA buffers and stop RESET\n");
290 reg = PCMCIA_PGCRX(slot);
291 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
292 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
293 reg &= ~NSCU_GCRX_CXOE; /* active low */
294
295 PCMCIA_PGCRX(slot) = reg;
296 udelay(500);
297
298 debug("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", slot+'A');
299#endif /* CONFIG_NSCU */
Marek Vasut6e967032011-10-05 02:51:55 +0000300 return 0;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200301}
302
Masahiro Yamadad1a4aaf2014-08-06 12:59:52 +0900303#endif /* CONFIG_PCMCIA && CONFIG_TQM8xxL */