Linux 2.6.33-rc6
[cris-mirror.git] / drivers / pcmcia / au1000_pb1x00.c
blobb1984ed72d1d78ef6f0a673ab5dd797c5c76f6cb
1 /*
3 * Alchemy Semi Pb1x00 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_types.h>
35 #include <pcmcia/cs.h>
36 #include <pcmcia/ss.h>
37 #include <pcmcia/cistpl.h>
38 #include <pcmcia/bus_ops.h>
40 #include <asm/io.h>
41 #include <asm/irq.h>
42 #include <asm/system.h>
44 #include <asm/au1000.h>
45 #include <asm/au1000_pcmcia.h>
47 #define debug(fmt, arg...) do { } while (0)
49 #ifdef CONFIG_MIPS_PB1000
50 #include <asm/pb1000.h>
51 #define PCMCIA_IRQ AU1000_GPIO_15
52 #elif defined (CONFIG_MIPS_PB1500)
53 #include <asm/pb1500.h>
54 #define PCMCIA_IRQ AU1500_GPIO_203
55 #elif defined (CONFIG_MIPS_PB1100)
56 #include <asm/pb1100.h>
57 #define PCMCIA_IRQ AU1000_GPIO_11
58 #endif
60 static int pb1x00_pcmcia_init(struct pcmcia_init *init)
62 #ifdef CONFIG_MIPS_PB1000
63 u16 pcr;
64 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
66 au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
67 au_sync_delay(100);
68 au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
69 au_sync();
71 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
72 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
73 au_writel(pcr, PB1000_PCR);
74 au_sync_delay(20);
76 return PCMCIA_NUM_SOCKS;
78 #else /* fixme -- take care of the Pb1500 at some point */
80 u16 pcr;
81 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
82 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
83 au_writew(pcr, PCMCIA_BOARD_REG);
84 au_sync_delay(500);
85 return PCMCIA_NUM_SOCKS;
86 #endif
89 static int pb1x00_pcmcia_shutdown(void)
91 #ifdef CONFIG_MIPS_PB1000
92 u16 pcr;
93 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
94 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
95 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
96 au_writel(pcr, PB1000_PCR);
97 au_sync_delay(20);
98 return 0;
99 #else
100 u16 pcr;
101 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
102 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
103 au_writew(pcr, PCMCIA_BOARD_REG);
104 au_sync_delay(2);
105 return 0;
106 #endif
109 static int
110 pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
112 u32 inserted0, inserted1;
113 u16 vs0, vs1;
115 #ifdef CONFIG_MIPS_PB1000
116 vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
117 inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
118 inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
119 vs0 = (vs0 >> 4) & 0x3;
120 vs1 = (vs1 >> 12) & 0x3;
121 #else
122 vs0 = (au_readw(BOARD_STATUS_REG) >> 4) & 0x3;
123 #ifdef CONFIG_MIPS_PB1500
124 inserted0 = !((au_readl(GPIO2_PINSTATE) >> 1) & 0x1); /* gpio 201 */
125 #else /* Pb1100 */
126 inserted0 = !((au_readl(SYS_PINSTATERD) >> 9) & 0x1); /* gpio 9 */
127 #endif
128 inserted1 = 0;
129 #endif
131 state->ready = 0;
132 state->vs_Xv = 0;
133 state->vs_3v = 0;
134 state->detect = 0;
136 if (sock == 0) {
137 if (inserted0) {
138 switch (vs0) {
139 case 0:
140 case 2:
141 state->vs_3v=1;
142 break;
143 case 3: /* 5V */
144 break;
145 default:
146 /* return without setting 'detect' */
147 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
148 vs0);
149 return 0;
151 state->detect = 1;
154 else {
155 if (inserted1) {
156 switch (vs1) {
157 case 0:
158 case 2:
159 state->vs_3v=1;
160 break;
161 case 3: /* 5V */
162 break;
163 default:
164 /* return without setting 'detect' */
165 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
166 vs1);
167 return 0;
169 state->detect = 1;
173 if (state->detect) {
174 state->ready = 1;
177 state->bvd1=1;
178 state->bvd2=1;
179 state->wrprot=0;
180 return 1;
184 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
187 if(info->sock > PCMCIA_MAX_SOCK) return -1;
190 * Even in the case of the Pb1000, both sockets are connected
191 * to the same irq line.
193 info->irq = PCMCIA_IRQ;
195 return 0;
199 static int
200 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
202 u16 pcr;
204 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
206 #ifdef CONFIG_MIPS_PB1000
207 pcr = au_readl(PB1000_PCR);
209 if (configure->sock == 0) {
210 pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
211 PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
213 else {
214 pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
215 PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
218 pcr &= ~PCR_SLOT_0_RST;
219 debug("Vcc %dV Vpp %dV, pcr %x\n",
220 configure->vcc, configure->vpp, pcr);
221 switch(configure->vcc){
222 case 0: /* Vcc 0 */
223 switch(configure->vpp) {
224 case 0:
225 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
226 configure->sock);
227 break;
228 case 12:
229 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
230 configure->sock);
231 break;
232 case 50:
233 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
234 configure->sock);
235 break;
236 case 33:
237 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
238 configure->sock);
239 break;
240 default:
241 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
242 configure->sock);
243 printk("%s: bad Vcc/Vpp (%d:%d)\n",
244 __func__,
245 configure->vcc,
246 configure->vpp);
247 break;
249 break;
250 case 50: /* Vcc 5V */
251 switch(configure->vpp) {
252 case 0:
253 pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
254 configure->sock);
255 break;
256 case 50:
257 pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
258 configure->sock);
259 break;
260 case 12:
261 pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
262 configure->sock);
263 break;
264 case 33:
265 pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
266 configure->sock);
267 break;
268 default:
269 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
270 configure->sock);
271 printk("%s: bad Vcc/Vpp (%d:%d)\n",
272 __func__,
273 configure->vcc,
274 configure->vpp);
275 break;
277 break;
278 case 33: /* Vcc 3.3V */
279 switch(configure->vpp) {
280 case 0:
281 pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
282 configure->sock);
283 break;
284 case 50:
285 pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
286 configure->sock);
287 break;
288 case 12:
289 pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
290 configure->sock);
291 break;
292 case 33:
293 pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
294 configure->sock);
295 break;
296 default:
297 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
298 configure->sock);
299 printk("%s: bad Vcc/Vpp (%d:%d)\n",
300 __func__,
301 configure->vcc,
302 configure->vpp);
303 break;
305 break;
306 default: /* what's this ? */
307 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
308 printk(KERN_ERR "%s: bad Vcc %d\n",
309 __func__, configure->vcc);
310 break;
313 if (configure->sock == 0) {
314 pcr &= ~(PCR_SLOT_0_RST);
315 if (configure->reset)
316 pcr |= PCR_SLOT_0_RST;
318 else {
319 pcr &= ~(PCR_SLOT_1_RST);
320 if (configure->reset)
321 pcr |= PCR_SLOT_1_RST;
323 au_writel(pcr, PB1000_PCR);
324 au_sync_delay(300);
326 #else
328 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf;
330 debug("Vcc %dV Vpp %dV, pcr %x, reset %d\n",
331 configure->vcc, configure->vpp, pcr, configure->reset);
334 switch(configure->vcc){
335 case 0: /* Vcc 0 */
336 pcr |= SET_VCC_VPP(0,0);
337 break;
338 case 50: /* Vcc 5V */
339 switch(configure->vpp) {
340 case 0:
341 pcr |= SET_VCC_VPP(2,0);
342 break;
343 case 50:
344 pcr |= SET_VCC_VPP(2,1);
345 break;
346 case 12:
347 pcr |= SET_VCC_VPP(2,2);
348 break;
349 case 33:
350 default:
351 pcr |= SET_VCC_VPP(0,0);
352 printk("%s: bad Vcc/Vpp (%d:%d)\n",
353 __func__,
354 configure->vcc,
355 configure->vpp);
356 break;
358 break;
359 case 33: /* Vcc 3.3V */
360 switch(configure->vpp) {
361 case 0:
362 pcr |= SET_VCC_VPP(1,0);
363 break;
364 case 12:
365 pcr |= SET_VCC_VPP(1,2);
366 break;
367 case 33:
368 pcr |= SET_VCC_VPP(1,1);
369 break;
370 case 50:
371 default:
372 pcr |= SET_VCC_VPP(0,0);
373 printk("%s: bad Vcc/Vpp (%d:%d)\n",
374 __func__,
375 configure->vcc,
376 configure->vpp);
377 break;
379 break;
380 default: /* what's this ? */
381 pcr |= SET_VCC_VPP(0,0);
382 printk(KERN_ERR "%s: bad Vcc %d\n",
383 __func__, configure->vcc);
384 break;
387 au_writew(pcr, PCMCIA_BOARD_REG);
388 au_sync_delay(300);
390 if (!configure->reset) {
391 pcr |= PC_DRV_EN;
392 au_writew(pcr, PCMCIA_BOARD_REG);
393 au_sync_delay(100);
394 pcr |= PC_DEASSERT_RST;
395 au_writew(pcr, PCMCIA_BOARD_REG);
396 au_sync_delay(100);
398 else {
399 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
400 au_writew(pcr, PCMCIA_BOARD_REG);
401 au_sync_delay(100);
403 #endif
404 return 0;
408 struct pcmcia_low_level pb1x00_pcmcia_ops = {
409 pb1x00_pcmcia_init,
410 pb1x00_pcmcia_shutdown,
411 pb1x00_pcmcia_socket_state,
412 pb1x00_pcmcia_get_irq_info,
413 pb1x00_pcmcia_configure_socket