blob: 45dcb54d71de9231ee6bde55a631eb6f5b87c5c2 [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
Masahiro Yamada5d2a5ef2014-12-15 23:26:06 +090025#if defined(CONFIG_TQM8xxL)
Wolfgang Denk9d407992006-07-10 23:07:28 +020026#define PCMCIA_BOARD_MSG "TQM8xxL"
Wolfgang Denk9d407992006-07-10 23:07:28 +020027#endif
28
Wolfgang Denk9d407992006-07-10 23:07:28 +020029static inline void power_config(int slot)
30{
Marek Vasut6e967032011-10-05 02:51:55 +000031 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Wolfgang Denk9d407992006-07-10 23:07:28 +020032 /*
Marek Vasut6e967032011-10-05 02:51:55 +000033 * Configure Port C pins for
34 * 5 Volts Enable and 3 Volts enable
35 */
36 clrbits_be16(&immap->im_ioport.iop_pcpar, 0x0002 | 0x0004);
37 clrbits_be16(&immap->im_ioport.iop_pcso, 0x0002 | 0x0004);
Wolfgang Denk9d407992006-07-10 23:07:28 +020038}
39
40static inline void power_off(int slot)
41{
Marek Vasut6e967032011-10-05 02:51:55 +000042 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
43 clrbits_be16(&immap->im_ioport.iop_pcdat, 0x0002 | 0x0004);
Wolfgang Denk9d407992006-07-10 23:07:28 +020044}
45
46static inline void power_on_5_0(int slot)
47{
Marek Vasut6e967032011-10-05 02:51:55 +000048 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
49 setbits_be16(&immap->im_ioport.iop_pcdat, 0x0004);
50 setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
Wolfgang Denk9d407992006-07-10 23:07:28 +020051}
52
53static inline void power_on_3_3(int slot)
54{
Marek Vasut6e967032011-10-05 02:51:55 +000055 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
56 setbits_be16(&immap->im_ioport.iop_pcdat, 0x0002);
57 setbits_be16(&immap->im_ioport.iop_pcdir, 0x0002 | 0x0004);
Wolfgang Denk9d407992006-07-10 23:07:28 +020058}
59
Marek Vasut6e967032011-10-05 02:51:55 +000060/*
61 * Function to retrieve the PIPR register, used for debuging purposes.
62 */
63static inline uint32_t debug_get_pipr(void)
64{
65 uint32_t pipr = 0;
66#ifdef DEBUG
67 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
68 pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
69#endif
70 return pipr;
71}
72
73
Wolfgang Denk9d407992006-07-10 23:07:28 +020074static inline int check_card_is_absent(int slot)
75{
Marek Vasut6e967032011-10-05 02:51:55 +000076 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
77 uint32_t pipr = in_be32(&immap->im_pcmcia.pcmc_pipr);
78 return pipr & (0x18000000 >> (slot << 4));
Wolfgang Denk9d407992006-07-10 23:07:28 +020079}
Wolfgang Denk9d407992006-07-10 23:07:28 +020080
Wolfgang Denk9d407992006-07-10 23:07:28 +020081#define NSCU_GCRX_CXOE __MY_PCMCIA_GCRX_CXOE
Wolfgang Denk9d407992006-07-10 23:07:28 +020082
83int pcmcia_hardware_enable(int slot)
84{
Marek Vasut6e967032011-10-05 02:51:55 +000085 immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Wolfgang Denk9d407992006-07-10 23:07:28 +020086 uint reg, mask;
87
Marek Vasut6e967032011-10-05 02:51:55 +000088 debug("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
Wolfgang Denk9d407992006-07-10 23:07:28 +020089
90 udelay(10000);
91
92 /*
Marek Vasut6e967032011-10-05 02:51:55 +000093 * Configure SIUMCR to enable PCMCIA port B
94 * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
95 */
Wolfgang Denk9d407992006-07-10 23:07:28 +020096
Marek Vasut6e967032011-10-05 02:51:55 +000097 /* Set DBGC to 00 */
98 clrbits_be32(&immap->im_siu_conf.sc_siumcr, SIUMCR_DBGC11);
99
100 /* Clear interrupt state, and disable interrupts */
101 out_be32(&immap->im_pcmcia.pcmc_pscr, PCMCIA_MASK(slot));
102 clrbits_be32(&immap->im_pcmcia.pcmc_per, PCMCIA_MASK(slot));
Wolfgang Denk9d407992006-07-10 23:07:28 +0200103
104 /*
Marek Vasut6e967032011-10-05 02:51:55 +0000105 * Disable interrupts, DMA, and PCMCIA buffers
106 * (isolate the interface) and assert RESET signal
107 */
108 debug("Disable PCMCIA buffers and assert RESET\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200109 reg = 0;
110 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
111 reg |= NSCU_GCRX_CXOE;
112
113 PCMCIA_PGCRX(slot) = reg;
114 udelay(500);
115
116 power_config(slot);
117 power_off(slot);
118
119 /*
120 * Make sure there is a card in the slot, then configure the interface.
121 */
122 udelay(10000);
Marek Vasut6e967032011-10-05 02:51:55 +0000123 reg = debug_get_pipr();
124 debug("[%d] %s: PIPR(%p)=0x%x\n", __LINE__, __FUNCTION__,
125 &immap->im_pcmcia.pcmc_pipr, reg);
Wolfgang Denkb87dfd22006-07-19 13:50:38 +0200126
Wolfgang Denk9d407992006-07-10 23:07:28 +0200127 if (check_card_is_absent(slot)) {
128 printf (" No Card found\n");
129 return (1);
130 }
131
132 /*
Marek Vasut6e967032011-10-05 02:51:55 +0000133 * Power On.
134 */
Wolfgang Denk9d407992006-07-10 23:07:28 +0200135 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
Marek Vasut6e967032011-10-05 02:51:55 +0000136 reg = in_be32(&immap->im_pcmcia.pcmc_pipr);
Wolfgang Denk9d407992006-07-10 23:07:28 +0200137 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
138 reg,
Marek Vasut6e967032011-10-05 02:51:55 +0000139 (reg & PCMCIA_VS1(slot)) ? "n" : "ff",
140 (reg & PCMCIA_VS2(slot)) ? "n" : "ff");
Wolfgang Denkb87dfd22006-07-19 13:50:38 +0200141
Wolfgang Denk9d407992006-07-10 23:07:28 +0200142 if ((reg & mask) == mask) {
143 power_on_5_0(slot);
144 puts (" 5.0V card found: ");
145 } else {
146 power_on_3_3(slot);
147 puts (" 3.3V card found: ");
148 }
149
150#if 0
151 /* VCC switch error flag, PCMCIA slot INPACK_ pin */
152 cp->cp_pbdir &= ~(0x0020 | 0x0010);
153 cp->cp_pbpar &= ~(0x0020 | 0x0010);
154 udelay(500000);
155#endif
156
157 udelay(1000);
Marek Vasut6e967032011-10-05 02:51:55 +0000158 debug("Enable PCMCIA buffers and stop RESET\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200159 reg = PCMCIA_PGCRX(slot);
160 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
161 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
162 reg &= ~NSCU_GCRX_CXOE;
Wolfgang Denkb87dfd22006-07-19 13:50:38 +0200163
Wolfgang Denk9d407992006-07-10 23:07:28 +0200164 PCMCIA_PGCRX(slot) = reg;
165
166 udelay(250000); /* some cards need >150 ms to come up :-( */
167
Marek Vasut6e967032011-10-05 02:51:55 +0000168 debug("# hardware_enable done\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200169
170 return (0);
171}
172
173
Jon Loeligercb51c0b2007-07-09 17:39:42 -0500174#if defined(CONFIG_CMD_PCMCIA)
Wolfgang Denk9d407992006-07-10 23:07:28 +0200175int pcmcia_hardware_disable(int slot)
176{
Wolfgang Denk9d407992006-07-10 23:07:28 +0200177 u_long reg;
178
Marek Vasut6e967032011-10-05 02:51:55 +0000179 debug("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
Wolfgang Denk9d407992006-07-10 23:07:28 +0200180
181 /* remove all power */
182 power_off(slot);
183
Marek Vasut6e967032011-10-05 02:51:55 +0000184 debug("Disable PCMCIA buffers and assert RESET\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200185 reg = 0;
186 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
187 reg |= NSCU_GCRX_CXOE; /* active low */
188
189 PCMCIA_PGCRX(slot) = reg;
190
191 udelay(10000);
192
193 return (0);
194}
Jon Loeligerddb5d86f2007-07-10 11:13:21 -0500195#endif
Wolfgang Denk9d407992006-07-10 23:07:28 +0200196
197int pcmcia_voltage_set(int slot, int vcc, int vpp)
198{
Wolfgang Denk966083e2006-07-21 15:24:56 +0200199 u_long reg;
Marek Vasut6e967032011-10-05 02:51:55 +0000200 uint32_t pipr = 0;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200201
Marek Vasut6e967032011-10-05 02:51:55 +0000202 debug("voltage_set: " PCMCIA_BOARD_MSG
Wolfgang Denk9d407992006-07-10 23:07:28 +0200203 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
204 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
205
206 /*
Marek Vasut6e967032011-10-05 02:51:55 +0000207 * Disable PCMCIA buffers (isolate the interface)
208 * and assert RESET signal
209 */
210 debug("Disable PCMCIA buffers and assert RESET\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200211 reg = PCMCIA_PGCRX(slot);
212 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
213 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
214 reg |= NSCU_GCRX_CXOE; /* active low */
Wolfgang Denkb87dfd22006-07-19 13:50:38 +0200215
Wolfgang Denk9d407992006-07-10 23:07:28 +0200216 PCMCIA_PGCRX(slot) = reg;
217 udelay(500);
218
Marek Vasut6e967032011-10-05 02:51:55 +0000219 debug("PCMCIA power OFF\n");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200220 power_config(slot);
221 power_off(slot);
222
223 switch(vcc) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200224 case 0: break;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200225 case 33: power_on_3_3(slot); break;
226 case 50: power_on_5_0(slot); break;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200227 default: goto done;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200228 }
229
230 /* Checking supported voltages */
Marek Vasut6e967032011-10-05 02:51:55 +0000231 pipr = debug_get_pipr();
232 debug("PIPR: 0x%x --> %s\n", pipr,
233 (pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
Wolfgang Denk9d407992006-07-10 23:07:28 +0200234
235 if (vcc)
236 debug("PCMCIA powered at %sV\n", (vcc == 50) ? "5.0" : "3.3");
237 else
238 debug("PCMCIA powered down\n");
239
240done:
241 debug("Enable PCMCIA buffers and stop RESET\n");
242 reg = PCMCIA_PGCRX(slot);
243 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
244 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
245 reg &= ~NSCU_GCRX_CXOE; /* active low */
246
247 PCMCIA_PGCRX(slot) = reg;
248 udelay(500);
249
250 debug("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n", slot+'A');
Marek Vasut6e967032011-10-05 02:51:55 +0000251 return 0;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200252}
253
Masahiro Yamadad1a4aaf2014-08-06 12:59:52 +0900254#endif /* CONFIG_PCMCIA && CONFIG_TQM8xxL */