7 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)
11 #if (CONFIG_COMMANDS & CFG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
17 /* some sane bit macros */
18 #define _BD(_b) (1U << (31-(_b)))
19 #define _BDR(_l, _h) (((((1U << (31-(_l))) - 1) << 1) | 1) & ~((1U << (31-(_h))) - 1))
21 #define _BW(_b) (1U << (15-(_b)))
22 #define _BWR(_l, _h) (((((1U << (15-(_l))) - 1) << 1) | 1) & ~((1U << (15-(_h))) - 1))
24 #define _BB(_b) (1U << (7-(_b)))
25 #define _BBR(_l, _h) (((((1U << (7-(_l))) - 1) << 1) | 1) & ~((1U << (7-(_h))) - 1))
27 #define _B(_b) _BD(_b)
28 #define _BR(_l, _h) _BDR(_l, _h)
30 #define PCMCIA_BOARD_MSG "NETTA"
32 static const unsigned short vppd_masks[2] = { _BW(14), _BW(15) };
34 static void cfg_vppd(int no)
36 volatile immap_t *immap = (immap_t *)CFG_IMMR;
39 if ((unsigned int)no >= sizeof(vppd_masks)/sizeof(vppd_masks[0]))
42 mask = vppd_masks[no];
44 immap->im_ioport.iop_papar &= ~mask;
45 immap->im_ioport.iop_paodr &= ~mask;
46 immap->im_ioport.iop_padir |= mask;
49 static void set_vppd(int no, int what)
51 volatile immap_t *immap = (immap_t *)CFG_IMMR;
54 if ((unsigned int)no >= sizeof(vppd_masks)/sizeof(vppd_masks[0]))
57 mask = vppd_masks[no];
60 immap->im_ioport.iop_padat |= mask;
62 immap->im_ioport.iop_padat &= ~mask;
65 static const unsigned short vccd_masks[2] = { _BW(10), _BW(6) };
67 static void cfg_vccd(int no)
69 volatile immap_t *immap = (immap_t *)CFG_IMMR;
72 if ((unsigned int)no >= sizeof(vccd_masks)/sizeof(vccd_masks[0]))
75 mask = vccd_masks[no];
77 immap->im_ioport.iop_papar &= ~mask;
78 immap->im_ioport.iop_paodr &= ~mask;
79 immap->im_ioport.iop_padir |= mask;
82 static void set_vccd(int no, int what)
84 volatile immap_t *immap = (immap_t *)CFG_IMMR;
87 if ((unsigned int)no >= sizeof(vccd_masks)/sizeof(vccd_masks[0]))
90 mask = vccd_masks[no];
93 immap->im_ioport.iop_padat |= mask;
95 immap->im_ioport.iop_padat &= ~mask;
98 static const unsigned short oc_mask = _BW(8);
100 static void cfg_oc(void)
102 volatile immap_t *immap = (immap_t *)CFG_IMMR;
103 unsigned short mask = oc_mask;
105 immap->im_ioport.iop_pcdir &= ~mask;
106 immap->im_ioport.iop_pcso &= ~mask;
107 immap->im_ioport.iop_pcint &= ~mask;
108 immap->im_ioport.iop_pcpar &= ~mask;
111 static int get_oc(void)
113 volatile immap_t *immap = (immap_t *)CFG_IMMR;
114 unsigned short mask = oc_mask;
117 what = !!(immap->im_ioport.iop_pcdat & mask);;
121 static const unsigned short shdn_mask = _BW(12);
123 static void cfg_shdn(void)
125 volatile immap_t *immap = (immap_t *)CFG_IMMR;
130 immap->im_ioport.iop_papar &= ~mask;
131 immap->im_ioport.iop_paodr &= ~mask;
132 immap->im_ioport.iop_padir |= mask;
135 static void set_shdn(int what)
137 volatile immap_t *immap = (immap_t *)CFG_IMMR;
143 immap->im_ioport.iop_padat |= mask;
145 immap->im_ioport.iop_padat &= ~mask;
148 static void cfg_ports (void)
150 volatile immap_t *immap;
151 volatile cpm8xx_t *cp;
153 immap = (immap_t *)CFG_IMMR;
154 cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
157 cfg_vppd(0); cfg_vppd(1); /* VPPD0,VPPD1 VAVPP => Hi-Z */
158 cfg_vccd(0); cfg_vccd(1); /* 3V and 5V off */
163 * Configure Port A for TPS2211 PC-Card Power-Interface Switch
165 * Switch off all voltages, assert shutdown
167 set_vppd(0, 1); set_vppd(1, 1);
168 set_vccd(0, 0); set_vccd(1, 0);
174 int pcmcia_hardware_enable(int slot)
176 volatile immap_t *immap;
177 volatile cpm8xx_t *cp;
178 volatile pcmconf8xx_t *pcmp;
179 volatile sysconf8xx_t *sysp;
180 uint reg, pipr, mask;
183 debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
187 immap = (immap_t *)CFG_IMMR;
188 sysp = (sysconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_siu_conf));
189 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
190 cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
192 /* Configure Ports for TPS2211A PC-Card Power-Interface Switch */
195 /* clear interrupt state, and disable interrupts */
196 pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
197 pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
200 * Disable interrupts, DMA, and PCMCIA buffers
201 * (isolate the interface) and assert RESET signal
203 debug ("Disable PCMCIA buffers and assert RESET\n");
205 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
206 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
207 PCMCIA_PGCRX(_slot_) = reg;
212 * Make sure there is a card in the slot, then configure the interface.
215 debug ("[%d] %s: PIPR(%p)=0x%x\n",
216 __LINE__,__FUNCTION__,
217 &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
218 if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
219 printf (" No Card found\n");
224 * Power On: Set VAVCC to 3.3V or 5V, set VAVPP to Hi-Z
226 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
227 pipr = pcmp->pcmc_pipr;
228 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
230 (reg&PCMCIA_VS1(slot))?"n":"ff",
231 (reg&PCMCIA_VS2(slot))?"n":"ff");
233 if ((pipr & mask) == mask) {
234 set_vppd(0, 1); set_vppd(1, 1); /* VAVPP => Hi-Z */
235 set_vccd(0, 0); set_vccd(1, 1); /* 5V on, 3V off */
236 puts (" 5.0V card found: ");
238 set_vppd(0, 1); set_vppd(1, 1); /* VAVPP => Hi-Z */
239 set_vccd(0, 1); set_vccd(1, 0); /* 5V off, 3V on */
240 puts (" 3.3V card found: ");
243 /* Wait 500 ms; use this to check for over-current */
244 for (i=0; i<5000; ++i) {
246 printf (" *** Overcurrent - Safety shutdown ***\n");
247 set_vccd(0, 0); set_vccd(1, 0); /* VAVPP => Hi-Z */
253 debug ("Enable PCMCIA buffers and stop RESET\n");
254 reg = PCMCIA_PGCRX(_slot_);
255 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
256 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
257 PCMCIA_PGCRX(_slot_) = reg;
259 udelay(250000); /* some cards need >150 ms to come up :-( */
261 debug ("# hardware_enable done\n");
267 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)
268 int pcmcia_hardware_disable(int slot)
270 volatile immap_t *immap;
271 volatile pcmconf8xx_t *pcmp;
274 debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
276 immap = (immap_t *)CFG_IMMR;
277 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
279 /* Configure PCMCIA General Control Register */
280 debug ("Disable PCMCIA buffers and assert RESET\n");
282 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
283 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
284 PCMCIA_PGCRX(_slot_) = reg;
286 /* All voltages off / Hi-Z */
287 set_vppd(0, 1); set_vppd(1, 1);
288 set_vccd(0, 1); set_vccd(1, 1);
294 #endif /* CFG_CMD_PCMCIA */
297 int pcmcia_voltage_set(int slot, int vcc, int vpp)
299 volatile immap_t *immap;
300 volatile cpm8xx_t *cp;
301 volatile pcmconf8xx_t *pcmp;
305 debug ("voltage_set: "
307 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
308 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
310 immap = (immap_t *)CFG_IMMR;
311 cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
312 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
314 * Disable PCMCIA buffers (isolate the interface)
315 * and assert RESET signal
317 debug ("Disable PCMCIA buffers and assert RESET\n");
318 reg = PCMCIA_PGCRX(_slot_);
319 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
320 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
321 PCMCIA_PGCRX(_slot_) = reg;
325 * Configure Port C pins for
326 * 5 Volts Enable and 3 Volts enable,
327 * Turn all power pins to Hi-Z
329 debug ("PCMCIA power OFF\n");
330 cfg_ports (); /* Enables switch, but all in Hi-Z */
332 sreg = immap->im_ioport.iop_pcdat;
333 set_vppd(0, 1); set_vppd(1, 1);
337 break; /* Switch off */
340 set_vccd(0, 1); set_vccd(1, 0);
344 set_vccd(0, 0); set_vccd(1, 1);
351 /* Checking supported voltages */
353 debug ("PIPR: 0x%x --> %s\n",
355 (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
358 debug ("Enable PCMCIA buffers and stop RESET\n");
359 reg = PCMCIA_PGCRX(_slot_);
360 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
361 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
362 PCMCIA_PGCRX(_slot_) = reg;
365 debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
370 #endif /* CONFIG_PCMCIA */