to make u-boot work for fat32 filesystem
[jz_uboot.git] / board / c2mon / pcmcia.c
blob5e50c4d9bc129a8e85e8482aa7bfa32963fa36e6
1 #include <common.h>
2 #include <mpc8xx.h>
3 #include <pcmcia.h>
5 #undef CONFIG_PCMCIA
7 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)
8 #define CONFIG_PCMCIA
9 #endif
11 #if (CONFIG_COMMANDS & CFG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
12 #define CONFIG_PCMCIA
13 #endif
15 #ifdef CONFIG_PCMCIA
17 #define PCMCIA_BOARD_MSG "C2MON"
19 static void cfg_ports (void)
21 volatile immap_t *immap;
22 volatile cpm8xx_t *cp;
23 ushort sreg;
25 immap = (immap_t *)CFG_IMMR;
26 cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
29 * Configure Port C for TPS2211 PC-Card Power-Interface Switch
31 * Switch off all voltages, assert shutdown
33 sreg = immap->im_ioport.iop_pcdat;
34 sreg |= (TPS2211_VPPD0 | TPS2211_VPPD1); /* VAVPP => Hi-Z */
35 sreg &= ~(TPS2211_VCCD0 | TPS2211_VCCD1); /* 3V and 5V off */
36 immap->im_ioport.iop_pcdat = sreg;
38 immap->im_ioport.iop_pcpar &= ~(TPS2211_OUTPUTS);
39 immap->im_ioport.iop_pcdir |= TPS2211_OUTPUTS;
41 debug ("Set Port C: PAR: %04x DIR: %04x DAT: %04x\n",
42 immap->im_ioport.iop_pcpar,
43 immap->im_ioport.iop_pcdir,
44 immap->im_ioport.iop_pcdat);
47 * Configure Port B for TPS2211 PC-Card Power-Interface Switch
49 * Over-Current Input only
51 cp->cp_pbpar &= ~(TPS2211_INPUTS);
52 cp->cp_pbdir &= ~(TPS2211_INPUTS);
54 debug ("Set Port B: PAR: %08x DIR: %08x DAT: %08x\n",
55 cp->cp_pbpar, cp->cp_pbdir, cp->cp_pbdat);
58 int pcmcia_hardware_enable(int slot)
60 volatile immap_t *immap;
61 volatile cpm8xx_t *cp;
62 volatile pcmconf8xx_t *pcmp;
63 volatile sysconf8xx_t *sysp;
64 uint reg, pipr, mask;
65 ushort sreg;
66 int i;
68 debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
70 udelay(10000);
72 immap = (immap_t *)CFG_IMMR;
73 sysp = (sysconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_siu_conf));
74 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
75 cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
77 /* Configure Ports for TPS2211A PC-Card Power-Interface Switch */
78 cfg_ports ();
81 * Configure SIUMCR to enable PCMCIA port B
82 * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
84 sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
86 /* clear interrupt state, and disable interrupts */
87 pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
88 pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
91 * Disable interrupts, DMA, and PCMCIA buffers
92 * (isolate the interface) and assert RESET signal
94 debug ("Disable PCMCIA buffers and assert RESET\n");
95 reg = 0;
96 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
97 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
98 PCMCIA_PGCRX(_slot_) = reg;
99 udelay(500);
102 * Make sure there is a card in the slot, then configure the interface.
104 udelay(10000);
105 debug ("[%d] %s: PIPR(%p)=0x%x\n",
106 __LINE__,__FUNCTION__,
107 &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
108 if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
109 printf (" No Card found\n");
110 return (1);
114 * Power On: Set VAVCC to 3.3V or 5V, set VAVPP to Hi-Z
116 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
117 pipr = pcmp->pcmc_pipr;
118 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
119 pipr,
120 (reg&PCMCIA_VS1(slot))?"n":"ff",
121 (reg&PCMCIA_VS2(slot))?"n":"ff");
123 sreg = immap->im_ioport.iop_pcdat;
124 if ((pipr & mask) == mask) {
125 sreg |= (TPS2211_VPPD0 | TPS2211_VPPD1 | /* VAVPP => Hi-Z */
126 TPS2211_VCCD1); /* 5V on */
127 sreg &= ~(TPS2211_VCCD0); /* 3V off */
128 puts (" 5.0V card found: ");
129 } else {
130 sreg |= (TPS2211_VPPD0 | TPS2211_VPPD1 | /* VAVPP => Hi-Z */
131 TPS2211_VCCD0); /* 3V on */
132 sreg &= ~(TPS2211_VCCD1); /* 5V off */
133 puts (" 3.3V card found: ");
136 debug ("\nPC DAT: %04x -> 3.3V %s 5.0V %s\n",
137 sreg,
138 ( (sreg & TPS2211_VCCD0) && !(sreg & TPS2211_VCCD1)) ? "on" : "off",
139 (!(sreg & TPS2211_VCCD0) && (sreg & TPS2211_VCCD1)) ? "on" : "off"
142 immap->im_ioport.iop_pcdat = sreg;
144 /* Wait 500 ms; use this to check for over-current */
145 for (i=0; i<5000; ++i) {
146 if ((cp->cp_pbdat & TPS2211_OC) == 0) {
147 printf (" *** Overcurrent - Safety shutdown ***\n");
148 immap->im_ioport.iop_pcdat &= ~(TPS2211_VCCD0|TPS2211_VCCD1);
149 return (1);
151 udelay (100);
154 debug ("Enable PCMCIA buffers and stop RESET\n");
155 reg = PCMCIA_PGCRX(_slot_);
156 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
157 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
158 PCMCIA_PGCRX(_slot_) = reg;
160 udelay(250000); /* some cards need >150 ms to come up :-( */
162 debug ("# hardware_enable done\n");
164 return (0);
168 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)
169 int pcmcia_hardware_disable(int slot)
171 volatile immap_t *immap;
172 volatile cpm8xx_t *cp;
173 volatile pcmconf8xx_t *pcmp;
174 u_long reg;
176 debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
178 immap = (immap_t *)CFG_IMMR;
179 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
181 /* Configure PCMCIA General Control Register */
182 debug ("Disable PCMCIA buffers and assert RESET\n");
183 reg = 0;
184 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
185 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
186 PCMCIA_PGCRX(_slot_) = reg;
188 /* ALl voltages off / Hi-Z */
189 immap->im_ioport.iop_pcdat |= (TPS2211_VPPD0 | TPS2211_VPPD1 |
190 TPS2211_VCCD0 | TPS2211_VCCD1 );
192 udelay(10000);
194 return (0);
196 #endif /* CFG_CMD_PCMCIA */
199 int pcmcia_voltage_set(int slot, int vcc, int vpp)
201 volatile immap_t *immap;
202 volatile cpm8xx_t *cp;
203 volatile pcmconf8xx_t *pcmp;
204 u_long reg;
205 ushort sreg;
207 debug ("voltage_set: "
208 PCMCIA_BOARD_MSG
209 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
210 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
212 immap = (immap_t *)CFG_IMMR;
213 cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
214 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
216 * Disable PCMCIA buffers (isolate the interface)
217 * and assert RESET signal
219 debug ("Disable PCMCIA buffers and assert RESET\n");
220 reg = PCMCIA_PGCRX(_slot_);
221 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
222 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
223 PCMCIA_PGCRX(_slot_) = reg;
224 udelay(500);
227 * Configure Port C pins for
228 * 5 Volts Enable and 3 Volts enable,
229 * Turn all power pins to Hi-Z
231 debug ("PCMCIA power OFF\n");
232 cfg_ports (); /* Enables switch, but all in Hi-Z */
234 sreg = immap->im_ioport.iop_pcdat;
235 sreg |= TPS2211_VPPD0 | TPS2211_VPPD1; /* VAVPP always Hi-Z */
237 switch(vcc) {
238 case 0: break; /* Switch off */
239 case 33: sreg |= TPS2211_VCCD0; /* Switch on 3.3V */
240 sreg &= ~TPS2211_VCCD1;
241 break;
242 case 50: sreg &= ~TPS2211_VCCD0; /* Switch on 5.0V */
243 sreg |= TPS2211_VCCD1;
244 break;
245 default: goto done;
248 /* Checking supported voltages */
250 debug ("PIPR: 0x%x --> %s\n",
251 pcmp->pcmc_pipr,
252 (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
254 immap->im_ioport.iop_pcdat = sreg;
256 #ifdef DEBUG
258 char *s;
260 if ((sreg & TPS2211_VCCD0) && !(sreg & TPS2211_VCCD1)) {
261 s = "at 3.3V";
262 } else if (!(sreg & TPS2211_VCCD0) && (sreg & TPS2211_VCCD1)) {
263 s = "at 5.0V";
264 } else {
265 s = "down";
267 printf ("PCMCIA powered %s\n", s);
269 #endif
271 done:
272 debug ("Enable PCMCIA buffers and stop RESET\n");
273 reg = PCMCIA_PGCRX(_slot_);
274 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
275 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
276 PCMCIA_PGCRX(_slot_) = reg;
277 udelay(500);
279 debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
280 slot+'A');
281 return (0);
284 #endif /* CONFIG_PCMCIA */