blob: 6e4b6d6c66ff3b135dad14ab70e9f7a242814d05 [file] [log] [blame]
Wolfgang Denk9d407992006-07-10 23:07:28 +02001#include <common.h>
2#include <mpc8xx.h>
3#include <pcmcia.h>
4
5#undef CONFIG_PCMCIA
6
7#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)
8#define CONFIG_PCMCIA
9#endif
10
11#if (CONFIG_COMMANDS & CFG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
12#define CONFIG_PCMCIA
13#endif
14
15#ifdef CONFIG_PCMCIA
16
17#define PCMCIA_BOARD_MSG "UC100"
18
19/*
20 * Remark: don't turn off OE "__MY_PCMCIA_GCRX_CXOE" on UC100 board.
21 * This leads to board-hangup! (sr, 8 Dez. 2004)
22 */
23static void cfg_ports (void)
24{
25 volatile immap_t *immap;
26
27 immap = (immap_t *)CFG_IMMR;
28
29 /*
30 * Configure Port A for MAX1602 PC-Card Power-Interface Switch
31 */
32 immap->im_ioport.iop_padat &= ~0x8000; /* set port x output to low */
33 immap->im_ioport.iop_padir |= 0x8000; /* enable port x as output */
34
35 debug ("Set Port A: PAR: %08x DIR: %08x DAT: %08x\n",
36 immap->im_ioport.iop_papar, immap->im_ioport.iop_padir,
37 immap->im_ioport.iop_padat);
38}
39
40int pcmcia_hardware_enable(int slot)
41{
42 volatile immap_t *immap;
43 volatile cpm8xx_t *cp;
44 volatile pcmconf8xx_t *pcmp;
45 volatile sysconf8xx_t *sysp;
46 uint reg, mask;
47
48 debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
49
50 udelay(10000);
51
52 immap = (immap_t *)CFG_IMMR;
53 sysp = (sysconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_siu_conf));
54 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
55 cp = (cpm8xx_t *)(&(((immap_t *)CFG_IMMR)->im_cpm));
56
57 /* Configure Ports for TPS2211A PC-Card Power-Interface Switch */
58 cfg_ports ();
59
60 /*
61 * Configure SIUMCR to enable PCMCIA port B
62 * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
63 */
64 sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
65
66 /* clear interrupt state, and disable interrupts */
67 pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
68 pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
69
70 /*
71 * Disable interrupts, DMA, and PCMCIA buffers
72 * (isolate the interface) and assert RESET signal
73 */
74 debug ("Disable PCMCIA buffers and assert RESET\n");
75 reg = 0;
76 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
77 PCMCIA_PGCRX(_slot_) = reg;
78 udelay(500);
79
80 /*
81 * Make sure there is a card in the slot, then configure the interface.
82 */
83 udelay(10000);
84 debug ("[%d] %s: PIPR(%p)=0x%x\n",
85 __LINE__,__FUNCTION__,
86 &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
87 if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
88 printf (" No Card found\n");
89 return (1);
90 }
91
92 /*
93 * Power On.
94 */
95 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
96 reg = pcmp->pcmc_pipr;
97 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
98 reg,
99 (reg&PCMCIA_VS1(slot))?"n":"ff",
100 (reg&PCMCIA_VS2(slot))?"n":"ff");
101 if ((reg & mask) == mask) {
102 puts (" 5.0V card found: ");
103 } else {
104 puts (" 3.3V card found: ");
105 }
106
107 /* switch VCC on */
108 immap->im_ioport.iop_padat |= 0x8000; /* power enable 3.3V */
109
110 udelay(10000);
111
112 debug ("Enable PCMCIA buffers and stop RESET\n");
113 reg = PCMCIA_PGCRX(_slot_);
114 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
115 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
116 PCMCIA_PGCRX(_slot_) = reg;
117
118 udelay(250000); /* some cards need >150 ms to come up :-( */
119
120 debug ("# hardware_enable done\n");
121
122 return (0);
123}
124
125
126#if (CONFIG_COMMANDS & CFG_CMD_PCMCIA)
127int pcmcia_hardware_disable(int slot)
128{
129 volatile immap_t *immap;
130 volatile cpm8xx_t *cp;
131 volatile pcmconf8xx_t *pcmp;
132 u_long reg;
133
134 debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
135
136 immap = (immap_t *)CFG_IMMR;
137 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
138
139 /* switch VCC off */
140 immap->im_ioport.iop_padat &= ~0x8000; /* power disable 3.3V */
141
142 /* Configure PCMCIA General Control Register */
143 debug ("Disable PCMCIA buffers and assert RESET\n");
144 reg = 0;
145 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
146 PCMCIA_PGCRX(_slot_) = reg;
147
148 udelay(10000);
149
150 return (0);
151}
152#endif /* CFG_CMD_PCMCIA */
153
154
155int pcmcia_voltage_set(int slot, int vcc, int vpp)
156{
157 volatile immap_t *immap;
158 volatile pcmconf8xx_t *pcmp;
159 u_long reg;
160
161 debug ("voltage_set: "
162 PCMCIA_BOARD_MSG
163 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
164 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
165
166 immap = (immap_t *)CFG_IMMR;
167 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CFG_IMMR)->im_pcmcia));
168 /*
169 * Disable PCMCIA buffers (isolate the interface)
170 * and assert RESET signal
171 */
172 debug ("Disable PCMCIA buffers and assert RESET\n");
173 reg = PCMCIA_PGCRX(_slot_);
174 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
175 PCMCIA_PGCRX(_slot_) = reg;
176 udelay(500);
177
178 /*
179 * Configure Port C pins for
180 * 5 Volts Enable and 3 Volts enable,
181 * Turn all power pins to Hi-Z
182 */
183 debug ("PCMCIA power OFF\n");
184 cfg_ports (); /* Enables switch, but all in Hi-Z */
185
186 debug ("Enable PCMCIA buffers and stop RESET\n");
187 reg = PCMCIA_PGCRX(_slot_);
188 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
189 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
190 PCMCIA_PGCRX(_slot_) = reg;
191 udelay(500);
192
193 debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
194 slot+'A');
195 return (0);
196}
197
198#endif /* CONFIG_PCMCIA */