blob: 61ba586e178db9bce8a2f94e625f2c15cb319747 [file] [log] [blame]
Wolfgang Denk50440e72006-07-10 23:07:28 +02001#include <common.h>
2#include <mpc8xx.h>
3#include <pcmcia.h>
4
5#undef CONFIG_PCMCIA
6
Jon Loeliger96892a92007-07-09 18:31:28 -05007#if defined(CONFIG_CMD_PCMCIA)
Wolfgang Denk50440e72006-07-10 23:07:28 +02008#define CONFIG_PCMCIA
9#endif
10
Jon Loeliger96892a92007-07-09 18:31:28 -050011#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
Wolfgang Denk50440e72006-07-10 23:07:28 +020012#define CONFIG_PCMCIA
13#endif
14
15#ifdef CONFIG_PCMCIA
16
17#define PCMCIA_BOARD_MSG "KUP"
18
19#define KUP4K_PCMCIA_B_3V3 (0x00020000)
20
21int pcmcia_hardware_enable(int slot)
22{
Wolfgang Denk50440e72006-07-10 23:07:28 +020023 volatile cpm8xx_t *cp;
24 volatile pcmconf8xx_t *pcmp;
25 volatile sysconf8xx_t *sysp;
26 uint reg, mask;
27
28 debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
29
30 udelay(10000);
31
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020032 sysp = (sysconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_siu_conf));
33 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
34 cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
Wolfgang Denk50440e72006-07-10 23:07:28 +020035
36 /*
Wolfgang Denk06b0b332011-11-04 15:55:25 +000037 * Configure SIUMCR to enable PCMCIA port B
38 * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
39 */
Wolfgang Denk50440e72006-07-10 23:07:28 +020040 sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
41
42 /* clear interrupt state, and disable interrupts */
43 pcmp->pcmc_pscr = PCMCIA_MASK(slot);
44 pcmp->pcmc_per &= ~PCMCIA_MASK(slot);
45
46 /*
Wolfgang Denk06b0b332011-11-04 15:55:25 +000047 * Disable interrupts, DMA, and PCMCIA buffers
48 * (isolate the interface) and assert RESET signal
49 */
Wolfgang Denk50440e72006-07-10 23:07:28 +020050 debug ("Disable PCMCIA buffers and assert RESET\n");
51 reg = 0;
52 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
53 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
54 PCMCIA_PGCRX(slot) = reg;
55 udelay(2500);
56
57 /*
Wolfgang Denk06b0b332011-11-04 15:55:25 +000058 * Configure Port B pins for
59 * 3 Volts enable
60 */
Wolfgang Denk50440e72006-07-10 23:07:28 +020061 if (slot) { /* Slot A is built-in */
62 cp->cp_pbdir |= KUP4K_PCMCIA_B_3V3;
63 cp->cp_pbpar &= ~KUP4K_PCMCIA_B_3V3;
64 /* remove all power */
65 cp->cp_pbdat |= KUP4K_PCMCIA_B_3V3; /* active low */
66 }
67 /*
Wolfgang Denk06b0b332011-11-04 15:55:25 +000068 * Make sure there is a card in the slot, then configure the interface.
69 */
Wolfgang Denk50440e72006-07-10 23:07:28 +020070 udelay(10000);
71 debug ("[%d] %s: PIPR(%p)=0x%x\n",
72 __LINE__,__FUNCTION__,
73 &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
74 if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
75 printf (" No Card found\n");
76 return (1);
77 }
78
79 /*
Wolfgang Denk06b0b332011-11-04 15:55:25 +000080 * Power On.
81 */
Wolfgang Denk50440e72006-07-10 23:07:28 +020082 printf("%s Slot %c:", slot ? "" : "\n", 'A' + slot);
83 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
84 reg = pcmp->pcmc_pipr;
85 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
86 reg,
87 (reg&PCMCIA_VS1(slot))?"n":"ff",
88 (reg&PCMCIA_VS2(slot))?"n":"ff");
89 if ((reg & mask) == mask) {
90 puts (" 5.0V card found: NOT SUPPORTED !!!\n");
91 } else {
92 if(slot)
93 cp->cp_pbdat &= ~KUP4K_PCMCIA_B_3V3;
94 puts (" 3.3V card found: ");
95 }
96#if 0
97 /* VCC switch error flag, PCMCIA slot INPACK_ pin */
98 cp->cp_pbdir &= ~(0x0020 | 0x0010);
99 cp->cp_pbpar &= ~(0x0020 | 0x0010);
100 udelay(500000);
101#endif
102 debug ("Enable PCMCIA buffers and stop RESET\n");
103 reg = PCMCIA_PGCRX(slot);
104 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
105 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
106 PCMCIA_PGCRX(slot) = reg;
107
108 udelay(250000); /* some cards need >150 ms to come up :-( */
109
110 debug ("# hardware_enable done\n");
111
112 return (0);
113}
114
115
Jon Loeliger96892a92007-07-09 18:31:28 -0500116#if defined(CONFIG_CMD_PCMCIA)
Wolfgang Denk50440e72006-07-10 23:07:28 +0200117int pcmcia_hardware_disable(int slot)
118{
119 volatile immap_t *immap;
120 volatile cpm8xx_t *cp;
121 volatile pcmconf8xx_t *pcmp;
122 u_long reg;
123
124 debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
125
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126 immap = (immap_t *)CONFIG_SYS_IMMR;
127 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
128 cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
Wolfgang Denk50440e72006-07-10 23:07:28 +0200129
130 /* remove all power */
131 if (slot)
132 cp->cp_pbdat |= KUP4K_PCMCIA_B_3V3;
133
134 /* Configure PCMCIA General Control Register */
135 debug ("Disable PCMCIA buffers and assert RESET\n");
136 reg = 0;
137 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
138 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
139 PCMCIA_PGCRX(slot) = reg;
140
141 udelay(10000);
142
143 return (0);
144}
Jon Loeliger761ea742007-07-10 10:48:22 -0500145#endif
Wolfgang Denk50440e72006-07-10 23:07:28 +0200146
147
148int pcmcia_voltage_set(int slot, int vcc, int vpp)
149{
Wolfgang Denk50440e72006-07-10 23:07:28 +0200150 volatile cpm8xx_t *cp;
151 volatile pcmconf8xx_t *pcmp;
152 u_long reg;
153
154 debug ("voltage_set: " \
155 PCMCIA_BOARD_MSG \
156 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
157 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
158
159 if (!slot) /* Slot A is not configurable */
160 return 0;
161
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200162 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
163 cp = (cpm8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_cpm));
Wolfgang Denk50440e72006-07-10 23:07:28 +0200164
165 /*
Wolfgang Denk06b0b332011-11-04 15:55:25 +0000166 * Disable PCMCIA buffers (isolate the interface)
167 * and assert RESET signal
168 */
Wolfgang Denk50440e72006-07-10 23:07:28 +0200169 debug ("Disable PCMCIA buffers and assert RESET\n");
170 reg = PCMCIA_PGCRX(slot);
171 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
172 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
173 PCMCIA_PGCRX(slot) = reg;
174 udelay(500);
175
176 debug ("PCMCIA power OFF\n");
177 /*
Wolfgang Denk06b0b332011-11-04 15:55:25 +0000178 * Configure Port B pins for
179 * 3 Volts enable
180 */
Wolfgang Denk50440e72006-07-10 23:07:28 +0200181 cp->cp_pbdir |= KUP4K_PCMCIA_B_3V3;
182 cp->cp_pbpar &= ~KUP4K_PCMCIA_B_3V3;
183 /* remove all power */
184 cp->cp_pbdat |= KUP4K_PCMCIA_B_3V3; /* active low */
185
186 switch(vcc) {
Wolfgang Denka1be4762008-05-20 16:00:29 +0200187 case 0: break;
Wolfgang Denk50440e72006-07-10 23:07:28 +0200188 case 33:
189 cp->cp_pbdat &= ~KUP4K_PCMCIA_B_3V3;
190 debug ("PCMCIA powered at 3.3V\n");
191 break;
192 case 50:
193 debug ("PCMCIA: 5Volt vcc not supported\n");
194 break;
195 default:
196 puts("PCMCIA: vcc not supported");
197 break;
198 }
199 udelay(10000);
200 /* Checking supported voltages */
201
202 debug ("PIPR: 0x%x --> %s\n",
203 pcmp->pcmc_pipr,
204 (pcmp->pcmc_pipr & (0x80000000 >> (slot << 4)))
205 ? "only 5 V --> NOT SUPPORTED"
206 : "can do 3.3V");
207
208
209 debug ("Enable PCMCIA buffers and stop RESET\n");
210 reg = PCMCIA_PGCRX(slot);
211 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
212 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
213 PCMCIA_PGCRX(slot) = reg;
214 udelay(500);
215
216 debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
217 slot+'A');
218 return (0);
219}
220
221#endif /* CONFIG_PCMCIA */