[CIFS] Fix minor checkpatch warning and update cifs version
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / pcmcia / au1000_pb1x00.c
blob807f2d75dad3a84f7b98142af3e52e812cc601bd
1 /*
3 * Alchemy Semi Pb1000 boards specific pcmcia routines.
5 * Copyright 2002 MontaVista Software Inc.
6 * Author: MontaVista Software, Inc.
7 * ppopov@mvista.com or source@mvista.com
9 * ########################################################################
11 * This program is free software; you can distribute it and/or modify it
12 * under the terms of the GNU General Public License (Version 2) as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/ioport.h>
28 #include <linux/kernel.h>
29 #include <linux/timer.h>
30 #include <linux/mm.h>
31 #include <linux/proc_fs.h>
32 #include <linux/types.h>
34 #include <pcmcia/cs.h>
35 #include <pcmcia/ss.h>
36 #include <pcmcia/cistpl.h>
38 #include <asm/io.h>
39 #include <asm/irq.h>
40 #include <asm/system.h>
42 #include <asm/au1000.h>
43 #include <asm/au1000_pcmcia.h>
45 #define debug(fmt, arg...) do { } while (0)
47 #include <asm/pb1000.h>
48 #define PCMCIA_IRQ AU1000_GPIO_15
50 static int pb1x00_pcmcia_init(struct pcmcia_init *init)
52 u16 pcr;
53 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
55 au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
56 au_sync_delay(100);
57 au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
58 au_sync();
60 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
61 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
62 au_writel(pcr, PB1000_PCR);
63 au_sync_delay(20);
65 return PCMCIA_NUM_SOCKS;
68 static int pb1x00_pcmcia_shutdown(void)
70 u16 pcr;
71 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
72 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
73 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
74 au_writel(pcr, PB1000_PCR);
75 au_sync_delay(20);
76 return 0;
79 static int
80 pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
82 u32 inserted0, inserted1;
83 u16 vs0, vs1;
85 vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
86 inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
87 inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
88 vs0 = (vs0 >> 4) & 0x3;
89 vs1 = (vs1 >> 12) & 0x3;
91 state->ready = 0;
92 state->vs_Xv = 0;
93 state->vs_3v = 0;
94 state->detect = 0;
96 if (sock == 0) {
97 if (inserted0) {
98 switch (vs0) {
99 case 0:
100 case 2:
101 state->vs_3v=1;
102 break;
103 case 3: /* 5V */
104 break;
105 default:
106 /* return without setting 'detect' */
107 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
108 vs0);
109 return 0;
111 state->detect = 1;
114 else {
115 if (inserted1) {
116 switch (vs1) {
117 case 0:
118 case 2:
119 state->vs_3v=1;
120 break;
121 case 3: /* 5V */
122 break;
123 default:
124 /* return without setting 'detect' */
125 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
126 vs1);
127 return 0;
129 state->detect = 1;
133 if (state->detect) {
134 state->ready = 1;
137 state->bvd1=1;
138 state->bvd2=1;
139 state->wrprot=0;
140 return 1;
144 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
147 if(info->sock > PCMCIA_MAX_SOCK) return -1;
150 * Even in the case of the Pb1000, both sockets are connected
151 * to the same irq line.
153 info->irq = PCMCIA_IRQ;
155 return 0;
159 static int
160 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
162 u16 pcr;
164 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
166 pcr = au_readl(PB1000_PCR);
168 if (configure->sock == 0) {
169 pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
170 PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
172 else {
173 pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
174 PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
177 pcr &= ~PCR_SLOT_0_RST;
178 debug("Vcc %dV Vpp %dV, pcr %x\n",
179 configure->vcc, configure->vpp, pcr);
180 switch(configure->vcc){
181 case 0: /* Vcc 0 */
182 switch(configure->vpp) {
183 case 0:
184 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
185 configure->sock);
186 break;
187 case 12:
188 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
189 configure->sock);
190 break;
191 case 50:
192 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
193 configure->sock);
194 break;
195 case 33:
196 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
197 configure->sock);
198 break;
199 default:
200 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
201 configure->sock);
202 printk("%s: bad Vcc/Vpp (%d:%d)\n",
203 __func__,
204 configure->vcc,
205 configure->vpp);
206 break;
208 break;
209 case 50: /* Vcc 5V */
210 switch(configure->vpp) {
211 case 0:
212 pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
213 configure->sock);
214 break;
215 case 50:
216 pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
217 configure->sock);
218 break;
219 case 12:
220 pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
221 configure->sock);
222 break;
223 case 33:
224 pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
225 configure->sock);
226 break;
227 default:
228 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
229 configure->sock);
230 printk("%s: bad Vcc/Vpp (%d:%d)\n",
231 __func__,
232 configure->vcc,
233 configure->vpp);
234 break;
236 break;
237 case 33: /* Vcc 3.3V */
238 switch(configure->vpp) {
239 case 0:
240 pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
241 configure->sock);
242 break;
243 case 50:
244 pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
245 configure->sock);
246 break;
247 case 12:
248 pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
249 configure->sock);
250 break;
251 case 33:
252 pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
253 configure->sock);
254 break;
255 default:
256 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
257 configure->sock);
258 printk("%s: bad Vcc/Vpp (%d:%d)\n",
259 __func__,
260 configure->vcc,
261 configure->vpp);
262 break;
264 break;
265 default: /* what's this ? */
266 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
267 printk(KERN_ERR "%s: bad Vcc %d\n",
268 __func__, configure->vcc);
269 break;
272 if (configure->sock == 0) {
273 pcr &= ~(PCR_SLOT_0_RST);
274 if (configure->reset)
275 pcr |= PCR_SLOT_0_RST;
277 else {
278 pcr &= ~(PCR_SLOT_1_RST);
279 if (configure->reset)
280 pcr |= PCR_SLOT_1_RST;
282 au_writel(pcr, PB1000_PCR);
283 au_sync_delay(300);
285 return 0;
289 struct pcmcia_low_level pb1x00_pcmcia_ops = {
290 pb1x00_pcmcia_init,
291 pb1x00_pcmcia_shutdown,
292 pb1x00_pcmcia_socket_state,
293 pb1x00_pcmcia_get_irq_info,
294 pb1x00_pcmcia_configure_socket