blob: b9894cf01198b1df2f429f9a2d3ffea1834f27be [file] [log] [blame]
Wolfgang Denk9d407992006-07-10 23:07:28 +02001#include <common.h>
2#include <mpc8xx.h>
3#include <pcmcia.h>
4#include <i2c.h>
5
6#undef CONFIG_PCMCIA
7
Jon Loeligerc508a4c2007-07-09 18:31:28 -05008#if defined(CONFIG_CMD_PCMCIA)
Wolfgang Denk9d407992006-07-10 23:07:28 +02009#define CONFIG_PCMCIA
10#endif
11
Jon Loeligerc508a4c2007-07-09 18:31:28 -050012#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_8xx_PCCARD)
Wolfgang Denk9d407992006-07-10 23:07:28 +020013#define CONFIG_PCMCIA
14#endif
15
16#ifdef CONFIG_PCMCIA
17
18#define PCMCIA_BOARD_MSG "LWMON"
19
20/* #define's for MAX1604 Power Switch */
21#define MAX1604_OP_SUS 0x80
22#define MAX1604_VCCBON 0x40
23#define MAX1604_VCC_35 0x20
24#define MAX1604_VCCBHIZ 0x10
25#define MAX1604_VPPBON 0x08
26#define MAX1604_VPPBPBPGM 0x04
27#define MAX1604_VPPBHIZ 0x02
28/* reserved 0x01 */
29
30int pcmcia_hardware_enable(int slot)
31{
Wolfgang Denk9d407992006-07-10 23:07:28 +020032 volatile pcmconf8xx_t *pcmp;
33 volatile sysconf8xx_t *sysp;
34 uint reg, mask;
35 uchar val;
36
37
38 debug ("hardware_enable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
39
40 /* Switch on PCMCIA port in PIC register 0x60 */
41 reg = pic_read (0x60);
42 debug ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
43 reg &= ~0x10;
44 /* reg |= 0x08; Vpp not needed */
45 pic_write (0x60, reg);
46#ifdef DEBUG
47 reg = pic_read (0x60);
48 printf ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
49#endif
50 udelay(10000);
51
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020052 sysp = (sysconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_siu_conf));
53 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
Wolfgang Denk9d407992006-07-10 23:07:28 +020054
55 /*
56 * Configure SIUMCR to enable PCMCIA port B
57 * (VFLS[0:1] are not used for debugging, we connect FRZ# instead)
58 */
59 sysp->sc_siumcr &= ~SIUMCR_DBGC11; /* set DBGC to 00 */
60
61 /* clear interrupt state, and disable interrupts */
62 pcmp->pcmc_pscr = PCMCIA_MASK(_slot_);
63 pcmp->pcmc_per &= ~PCMCIA_MASK(_slot_);
64
65 /*
66 * Disable interrupts, DMA, and PCMCIA buffers
67 * (isolate the interface) and assert RESET signal
68 */
69 debug ("Disable PCMCIA buffers and assert RESET\n");
70 reg = 0;
71 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
72 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
73 PCMCIA_PGCRX(_slot_) = reg;
74 udelay(500);
75
76 /*
77 * Make sure there is a card in the slot, then configure the interface.
78 */
79 udelay(10000);
80 debug ("[%d] %s: PIPR(%p)=0x%x\n",
81 __LINE__,__FUNCTION__,
82 &(pcmp->pcmc_pipr),pcmp->pcmc_pipr);
83 if (pcmp->pcmc_pipr & (0x18000000 >> (slot << 4))) {
84 printf (" No Card found\n");
85 return (1);
86 }
87
88 /*
89 * Power On.
90 */
91 mask = PCMCIA_VS1(slot) | PCMCIA_VS2(slot);
92 reg = pcmp->pcmc_pipr;
93 debug ("PIPR: 0x%x ==> VS1=o%s, VS2=o%s\n",
94 reg,
95 (reg&PCMCIA_VS1(slot))?"n":"ff",
96 (reg&PCMCIA_VS2(slot))?"n":"ff");
97 if ((reg & mask) == mask) {
98 val = 0; /* VCCB3/5 = 0 ==> use Vx = 5.0 V */
99 puts (" 5.0V card found: ");
100 } else {
101 val = MAX1604_VCC_35; /* VCCB3/5 = 1 ==> use Vy = 3.3 V */
102 puts (" 3.3V card found: ");
103 }
104
105 /* switch VCC on */
106 val |= MAX1604_OP_SUS | MAX1604_VCCBON;
Heiko Schocherea818db2013-01-29 08:53:15 +0100107 i2c_set_bus_num(0);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200108 i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
Wolfgang Denk9d407992006-07-10 23:07:28 +0200109
110 udelay(500000);
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
Jon Loeligerc508a4c2007-07-09 18:31:28 -0500126#if defined(CONFIG_CMD_PCMCIA)
Wolfgang Denk9d407992006-07-10 23:07:28 +0200127int pcmcia_hardware_disable(int slot)
128{
129 volatile immap_t *immap;
130 volatile pcmconf8xx_t *pcmp;
131 u_long reg;
132 uchar val;
133
134 debug ("hardware_disable: " PCMCIA_BOARD_MSG " Slot %c\n", 'A'+slot);
135
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200136 immap = (immap_t *)CONFIG_SYS_IMMR;
137 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
Wolfgang Denk9d407992006-07-10 23:07:28 +0200138
139 /* remove all power, put output in high impedance state */
140 val = MAX1604_VCCBHIZ | MAX1604_VPPBHIZ;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200141 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
142 i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
Wolfgang Denk9d407992006-07-10 23:07:28 +0200143
144 /* Configure PCMCIA General Control Register */
145 debug ("Disable PCMCIA buffers and assert RESET\n");
146 reg = 0;
147 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
148 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
149 PCMCIA_PGCRX(_slot_) = reg;
150
151 /* Switch off PCMCIA port in PIC register 0x60 */
152 reg = pic_read (0x60);
153 debug ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
154 reg |= 0x10;
155 reg &= ~0x08;
156 pic_write (0x60, reg);
157#ifdef DEBUG
158 reg = pic_read (0x60);
159 printf ("[%d] PIC read: reg_60 = 0x%02x\n", __LINE__, reg);
160#endif
161 udelay(10000);
162
163 return (0);
164}
Jon Loeligerd39b5742007-07-10 10:48:22 -0500165#endif
Wolfgang Denk9d407992006-07-10 23:07:28 +0200166
167
168int pcmcia_voltage_set(int slot, int vcc, int vpp)
169{
Wolfgang Denk9d407992006-07-10 23:07:28 +0200170 volatile pcmconf8xx_t *pcmp;
171 u_long reg;
172 uchar val;
173
174 debug ("voltage_set: "
175 PCMCIA_BOARD_MSG
176 " Slot %c, Vcc=%d.%d, Vpp=%d.%d\n",
177 'A'+slot, vcc/10, vcc%10, vpp/10, vcc%10);
178
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200179 pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
Wolfgang Denk9d407992006-07-10 23:07:28 +0200180 /*
181 * Disable PCMCIA buffers (isolate the interface)
182 * and assert RESET signal
183 */
184 debug ("Disable PCMCIA buffers and assert RESET\n");
185 reg = PCMCIA_PGCRX(_slot_);
186 reg |= __MY_PCMCIA_GCRX_CXRESET; /* active high */
187 reg |= __MY_PCMCIA_GCRX_CXOE; /* active low */
188 PCMCIA_PGCRX(_slot_) = reg;
189 udelay(500);
190
191 /*
192 * Turn off all power (switch to high impedance)
193 */
194 debug ("PCMCIA power OFF\n");
195 val = MAX1604_VCCBHIZ | MAX1604_VPPBHIZ;
Heiko Schocherea818db2013-01-29 08:53:15 +0100196 i2c_set_bus_num(0);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200197 i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
Wolfgang Denk9d407992006-07-10 23:07:28 +0200198
199 val = 0;
200 switch(vcc) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200201 case 0: break;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200202 case 33: val = MAX1604_VCC_35; break;
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200203 case 50: break;
204 default: goto done;
Wolfgang Denk9d407992006-07-10 23:07:28 +0200205 }
206
207 /* Checking supported voltages */
208
209 debug ("PIPR: 0x%x --> %s\n",
210 pcmp->pcmc_pipr,
211 (pcmp->pcmc_pipr & 0x00008000) ? "only 5 V" : "can do 3.3V");
212
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200213 i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
Wolfgang Denk9d407992006-07-10 23:07:28 +0200214 if (val) {
215 debug ("PCMCIA powered at %sV\n",
216 (val & MAX1604_VCC_35) ? "3.3" : "5.0");
217 } else {
218 debug ("PCMCIA powered down\n");
219 }
220
221done:
222 debug ("Enable PCMCIA buffers and stop RESET\n");
223 reg = PCMCIA_PGCRX(_slot_);
224 reg &= ~__MY_PCMCIA_GCRX_CXRESET; /* active high */
225 reg &= ~__MY_PCMCIA_GCRX_CXOE; /* active low */
226 PCMCIA_PGCRX(_slot_) = reg;
227 udelay(500);
228
229 debug ("voltage_set: " PCMCIA_BOARD_MSG " Slot %c, DONE\n",
230 slot+'A');
231 return (0);
232}
233
234#endif /* CONFIG_PCMCIA */