[CONNECTOR]: Initialize subsystem earlier.
[linux-2.6/verdex.git] / drivers / pcmcia / pxa2xx_lubbock.c
blobfd1f691c7c2c670ab27e3f4cf4983933d43943f0
1 /*
2 * linux/drivers/pcmcia/pxa2xx_lubbock.c
4 * Author: George Davis
5 * Created: Jan 10, 2002
6 * Copyright: MontaVista Software Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * Originally based upon linux/drivers/pcmcia/sa1100_neponset.c
14 * Lubbock PCMCIA specific routines.
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/device.h>
21 #include <linux/errno.h>
22 #include <linux/init.h>
23 #include <linux/delay.h>
25 #include <asm/hardware.h>
26 #include <asm/hardware/sa1111.h>
27 #include <asm/mach-types.h>
28 #include <asm/arch/pxa-regs.h>
29 #include <asm/arch/lubbock.h>
31 #include "sa1111_generic.h"
33 static int
34 lubbock_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
37 * Setup default state of GPIO outputs
38 * before we enable them as outputs.
40 GPSR(GPIO48_nPOE) =
41 GPIO_bit(GPIO48_nPOE) |
42 GPIO_bit(GPIO49_nPWE) |
43 GPIO_bit(GPIO50_nPIOR) |
44 GPIO_bit(GPIO51_nPIOW) |
45 GPIO_bit(GPIO52_nPCE_1) |
46 GPIO_bit(GPIO53_nPCE_2);
48 pxa_gpio_mode(GPIO48_nPOE_MD);
49 pxa_gpio_mode(GPIO49_nPWE_MD);
50 pxa_gpio_mode(GPIO50_nPIOR_MD);
51 pxa_gpio_mode(GPIO51_nPIOW_MD);
52 pxa_gpio_mode(GPIO52_nPCE_1_MD);
53 pxa_gpio_mode(GPIO53_nPCE_2_MD);
54 pxa_gpio_mode(GPIO54_pSKTSEL_MD);
55 pxa_gpio_mode(GPIO55_nPREG_MD);
56 pxa_gpio_mode(GPIO56_nPWAIT_MD);
57 pxa_gpio_mode(GPIO57_nIOIS16_MD);
59 return sa1111_pcmcia_hw_init(skt);
62 static int
63 lubbock_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
64 const socket_state_t *state)
66 unsigned int pa_dwr_mask, pa_dwr_set, misc_mask, misc_set;
67 int ret = 0;
69 pa_dwr_mask = pa_dwr_set = misc_mask = misc_set = 0;
71 /* Lubbock uses the Maxim MAX1602, with the following connections:
73 * Socket 0 (PCMCIA):
74 * MAX1602 Lubbock Register
75 * Pin Signal
76 * ----- ------- ----------------------
77 * A0VPP S0_PWR0 SA-1111 GPIO A<0>
78 * A1VPP S0_PWR1 SA-1111 GPIO A<1>
79 * A0VCC S0_PWR2 SA-1111 GPIO A<2>
80 * A1VCC S0_PWR3 SA-1111 GPIO A<3>
81 * VX VCC
82 * VY +3.3V
83 * 12IN +12V
84 * CODE +3.3V Cirrus Code, CODE = High (VY)
86 * Socket 1 (CF):
87 * MAX1602 Lubbock Register
88 * Pin Signal
89 * ----- ------- ----------------------
90 * A0VPP GND VPP is not connected
91 * A1VPP GND VPP is not connected
92 * A0VCC S1_PWR0 MISC_WR<14>
93 * A1VCC S1_PWR1 MISC_WR<15>
94 * VX VCC
95 * VY +3.3V
96 * 12IN GND VPP is not connected
97 * CODE +3.3V Cirrus Code, CODE = High (VY)
101 again:
102 switch (skt->nr) {
103 case 0:
104 pa_dwr_mask = GPIO_A0 | GPIO_A1 | GPIO_A2 | GPIO_A3;
106 switch (state->Vcc) {
107 case 0: /* Hi-Z */
108 break;
110 case 33: /* VY */
111 pa_dwr_set |= GPIO_A3;
112 break;
114 case 50: /* VX */
115 pa_dwr_set |= GPIO_A2;
116 break;
118 default:
119 printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
120 __FUNCTION__, state->Vcc);
121 ret = -1;
124 switch (state->Vpp) {
125 case 0: /* Hi-Z */
126 break;
128 case 120: /* 12IN */
129 pa_dwr_set |= GPIO_A1;
130 break;
132 default: /* VCC */
133 if (state->Vpp == state->Vcc)
134 pa_dwr_set |= GPIO_A0;
135 else {
136 printk(KERN_ERR "%s(): unrecognized Vpp %u\n",
137 __FUNCTION__, state->Vpp);
138 ret = -1;
139 break;
142 break;
144 case 1:
145 misc_mask = (1 << 15) | (1 << 14);
147 switch (state->Vcc) {
148 case 0: /* Hi-Z */
149 break;
151 case 33: /* VY */
152 misc_set |= 1 << 15;
153 break;
155 case 50: /* VX */
156 misc_set |= 1 << 14;
157 break;
159 default:
160 printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
161 __FUNCTION__, state->Vcc);
162 ret = -1;
163 break;
166 if (state->Vpp != state->Vcc && state->Vpp != 0) {
167 printk(KERN_ERR "%s(): CF slot cannot support Vpp %u\n",
168 __FUNCTION__, state->Vpp);
169 ret = -1;
170 break;
172 break;
174 default:
175 ret = -1;
178 if (ret == 0)
179 ret = sa1111_pcmcia_configure_socket(skt, state);
181 if (ret == 0) {
182 lubbock_set_misc_wr(misc_mask, misc_set);
183 sa1111_set_io(SA1111_DEV(skt->dev), pa_dwr_mask, pa_dwr_set);
186 #if 1
187 if (ret == 0 && state->Vcc == 33) {
188 struct pcmcia_state new_state;
191 * HACK ALERT:
192 * We can't sense the voltage properly on Lubbock before
193 * actually applying some power to the socket (catch 22).
194 * Resense the socket Voltage Sense pins after applying
195 * socket power.
197 * Note: It takes about 2.5ms for the MAX1602 VCC output
198 * to rise.
200 mdelay(3);
202 sa1111_pcmcia_socket_state(skt, &new_state);
204 if (!new_state.vs_3v && !new_state.vs_Xv) {
206 * Switch to 5V, Configure socket with 5V voltage
208 lubbock_set_misc_wr(misc_mask, 0);
209 sa1111_set_io(SA1111_DEV(skt->dev), pa_dwr_mask, 0);
212 * It takes about 100ms to turn off Vcc.
214 mdelay(100);
217 * We need to hack around the const qualifier as
218 * well to keep this ugly workaround localized and
219 * not force it to the rest of the code. Barf bags
220 * avaliable in the seat pocket in front of you!
222 ((socket_state_t *)state)->Vcc = 50;
223 ((socket_state_t *)state)->Vpp = 50;
224 goto again;
227 #endif
229 return ret;
232 static struct pcmcia_low_level lubbock_pcmcia_ops = {
233 .owner = THIS_MODULE,
234 .hw_init = lubbock_pcmcia_hw_init,
235 .hw_shutdown = sa1111_pcmcia_hw_shutdown,
236 .socket_state = sa1111_pcmcia_socket_state,
237 .configure_socket = lubbock_pcmcia_configure_socket,
238 .socket_init = sa1111_pcmcia_socket_init,
239 .socket_suspend = sa1111_pcmcia_socket_suspend,
240 .first = 0,
241 .nr = 2,
244 #include "pxa2xx_base.h"
246 int __init pcmcia_lubbock_init(struct sa1111_dev *sadev)
248 int ret = -ENODEV;
250 if (machine_is_lubbock()) {
252 * Set GPIO_A<3:0> to be outputs for the MAX1600,
253 * and switch to standby mode.
255 sa1111_set_io_dir(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0, 0);
256 sa1111_set_io(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0);
257 sa1111_set_sleep_io(sadev, GPIO_A0|GPIO_A1|GPIO_A2|GPIO_A3, 0);
259 /* Set CF Socket 1 power to standby mode. */
260 lubbock_set_misc_wr((1 << 15) | (1 << 14), 0);
262 sadev->dev.platform_data = &lubbock_pcmcia_ops;
263 ret = pxa2xx_drv_pcmcia_probe(&sadev->dev);
266 return ret;
269 MODULE_LICENSE("GPL");