7 #if defined(CONFIG_CMD_PCMCIA)
11 #if defined(CONFIG_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 *)CONFIG_SYS_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 *)CONFIG_SYS_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 *)CONFIG_SYS_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 *)CONFIG_SYS_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 *)CONFIG_SYS_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 *)CONFIG_SYS_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 *)CONFIG_SYS_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 *)CONFIG_SYS_IMMR;
143 immap->im_ioport.iop_padat |= mask;
145 immap->im_ioport.iop_padat &= ~mask;
148 static void cfg_ports (void)
150 cfg_vppd(0); cfg_vppd(1); /* VPPD0,VPPD1 VAVPP => Hi-Z */
151 cfg_vccd(0); cfg_vccd(1); /* 3V and 5V off */
156 * Configure Port A for TPS2211 PC-Card Power-Interface Switch
158 * Switch off all voltages, assert shutdown
160 set_vppd(0, 1); set_vppd(1, 1);
161 set_vccd(0, 0); set_vccd(1, 0);
167 int pcmcia_hardware_enable(int slot)
169 volatile pcmconf8xx_t *pcmp;
170 uint reg, pipr, mask;
173 debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
177 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
179 /* Configure Ports for TPS2211A PC-Card Power-Interface Switch */
182 /* clear interrupt state, and disable interrupts */
183 pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
184 pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
187 * Disable interrupts, DMA, and PCMCIA buffers
188 * (isolate the interface) and assert RESET signal
190 debug ("Disable PCMCIA buffers and assert RESET\n");
192 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
193 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
194 PCMCIA_PGCRX(_slot_) = reg;
199 * Make sure there is a card in the slot, then configure the interface.
202 debug ("[%d] %s: PIPR(%p)=0x%x\n",
203 __LINE__,__FUNCTION__,
204 &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
205 if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
206 printf (" No Card found\n");
211 * Power On: Set VAVCC to 3.3V or 5V, set VAVPP to Hi-Z
213 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
214 pipr = pcmp->pcmc_pipr;
215 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
217 (reg&PCMCIA_VS1(slot))?"n":"ff",
218 (reg&PCMCIA_VS2(slot))?"n":"ff");
220 if ((pipr & mask) == mask) {
221 set_vppd(0, 1); set_vppd(1, 1); /* VAVPP => Hi-Z */
222 set_vccd(0, 0); set_vccd(1, 1); /* 5V on, 3V off */
223 puts (" 5.0V card found: ");
225 set_vppd(0, 1); set_vppd(1, 1); /* VAVPP => Hi-Z */
226 set_vccd(0, 1); set_vccd(1, 0); /* 5V off, 3V on */
227 puts (" 3.3V card found: ");
230 /* Wait 500 ms; use this to check for over-current */
231 for (i=0; i<5000; ++i) {
233 printf (" *** Overcurrent - Safety shutdown ***\n");
234 set_vccd(0, 0); set_vccd(1, 0); /* VAVPP => Hi-Z */
240 debug ("Enable PCMCIA buffers and stop RESET\n");
241 reg = PCMCIA_PGCRX(_slot_);
242 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
243 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
244 PCMCIA_PGCRX(_slot_) = reg;
246 udelay(250000); /* some cards need >150 ms to come up :-( */
248 debug ("# hardware_enable done\n");
254 #if defined(CONFIG_CMD_PCMCIA)
255 int pcmcia_hardware_disable(int slot)
259 debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
261 /* Configure PCMCIA General Control Register */
262 debug ("Disable PCMCIA buffers and assert RESET\n");
264 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
265 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
266 PCMCIA_PGCRX(_slot_) = reg;
268 /* All voltages off / Hi-Z */
269 set_vppd(0, 1); set_vppd(1, 1);
270 set_vccd(0, 1); set_vccd(1, 1);
279 int pcmcia_voltage_set(int slot, int vcc, int vpp)
281 volatile pcmconf8xx_t *pcmp;
284 debug ("voltage_set: "
286 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
287 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
289 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
291 * Disable PCMCIA buffers (isolate the interface)
292 * and assert RESET signal
294 debug ("Disable PCMCIA buffers and assert RESET\n");
295 reg = PCMCIA_PGCRX(_slot_);
296 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
297 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
298 PCMCIA_PGCRX(_slot_) = reg;
302 * Configure Port C pins for
303 * 5 Volts Enable and 3 Volts enable,
304 * Turn all power pins to Hi-Z
306 debug ("PCMCIA power OFF\n");
307 cfg_ports (); /* Enables switch, but all in Hi-Z */
309 set_vppd(0, 1); set_vppd(1, 1);
313 break; /* Switch off */
316 set_vccd(0, 1); set_vccd(1, 0);
320 set_vccd(0, 0); set_vccd(1, 1);
327 /* Checking supported voltages */
329 debug ("PIPR: 0x%x --> %s\n",
331 (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
334 debug ("Enable PCMCIA buffers and stop RESET\n");
335 reg = PCMCIA_PGCRX(_slot_);
336 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
337 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
338 PCMCIA_PGCRX(_slot_) = reg;
341 debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
346 #endif /* CONFIG_PCMCIA */