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
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/tqueue.h>
30 #include <linux/timer.h>
32 #include <linux/proc_fs.h>
33 #include <linux/types.h>
35 #include <pcmcia/cs_types.h>
36 #include <pcmcia/cs.h>
37 #include <pcmcia/ss.h>
38 #include <pcmcia/cistpl.h>
39 #include <pcmcia/bus_ops.h>
40 #include "cs_internal.h"
44 #include <asm/system.h>
46 #include <asm/au1000.h>
47 #include <asm/au1000_pcmcia.h>
49 #define debug(fmt, arg...) do { } while (0)
51 #ifdef CONFIG_MIPS_PB1000
52 #include <asm/pb1000.h>
53 #define PCMCIA_IRQ AU1000_GPIO_15
54 #elif defined (CONFIG_MIPS_PB1500)
55 #include <asm/pb1500.h>
56 #define PCMCIA_IRQ AU1500_GPIO_203
57 #elif defined (CONFIG_MIPS_PB1100)
58 #include <asm/pb1100.h>
59 #define PCMCIA_IRQ AU1000_GPIO_11
62 static int pb1x00_pcmcia_init(struct pcmcia_init
*init
)
64 #ifdef CONFIG_MIPS_PB1000
66 pcr
= PCR_SLOT_0_RST
| PCR_SLOT_1_RST
;
68 au_writel(0x8000, PB1000_MDR
); /* clear pcmcia interrupt */
70 au_writel(0x4000, PB1000_MDR
); /* enable pcmcia interrupt */
73 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,0);
74 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,1);
75 au_writel(pcr
, PB1000_PCR
);
78 return PCMCIA_NUM_SOCKS
;
80 #else /* fixme -- take care of the Pb1500 at some point */
83 pcr
= au_readw(PCMCIA_BOARD_REG
) & ~0xf; /* turn off power */
84 pcr
&= ~(PC_DEASSERT_RST
| PC_DRV_EN
);
85 au_writew(pcr
, PCMCIA_BOARD_REG
);
87 return PCMCIA_NUM_SOCKS
;
91 static int pb1x00_pcmcia_shutdown(void)
93 #ifdef CONFIG_MIPS_PB1000
95 pcr
= PCR_SLOT_0_RST
| PCR_SLOT_1_RST
;
96 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,0);
97 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,1);
98 au_writel(pcr
, PB1000_PCR
);
103 pcr
= au_readw(PCMCIA_BOARD_REG
) & ~0xf; /* turn off power */
104 pcr
&= ~(PC_DEASSERT_RST
| PC_DRV_EN
);
105 au_writew(pcr
, PCMCIA_BOARD_REG
);
112 pb1x00_pcmcia_socket_state(unsigned sock
, struct pcmcia_state
*state
)
114 u32 inserted0
, inserted1
;
117 #ifdef CONFIG_MIPS_PB1000
118 vs0
= vs1
= (u16
)au_readl(PB1000_ACR1
);
119 inserted0
= !(vs0
& (ACR1_SLOT_0_CD1
| ACR1_SLOT_0_CD2
));
120 inserted1
= !(vs1
& (ACR1_SLOT_1_CD1
| ACR1_SLOT_1_CD2
));
121 vs0
= (vs0
>> 4) & 0x3;
122 vs1
= (vs1
>> 12) & 0x3;
124 vs0
= (au_readw(BOARD_STATUS_REG
) >> 4) & 0x3;
125 #ifdef CONFIG_MIPS_PB1500
126 inserted0
= !((au_readl(GPIO2_PINSTATE
) >> 1) & 0x1); /* gpio 201 */
128 inserted0
= !((au_readl(SYS_PINSTATERD
) >> 9) & 0x1); /* gpio 9 */
148 /* return without setting 'detect' */
149 printk(KERN_ERR
"pb1x00 bad VS (%d)\n",
166 /* return without setting 'detect' */
167 printk(KERN_ERR
"pb1x00 bad VS (%d)\n",
186 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info
*info
)
189 if(info
->sock
> PCMCIA_MAX_SOCK
) return -1;
192 * Even in the case of the Pb1000, both sockets are connected
193 * to the same irq line.
195 info
->irq
= PCMCIA_IRQ
;
202 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure
*configure
)
206 if(configure
->sock
> PCMCIA_MAX_SOCK
) return -1;
208 #ifdef CONFIG_MIPS_PB1000
209 pcr
= au_readl(PB1000_PCR
);
211 if (configure
->sock
== 0) {
212 pcr
&= ~(PCR_SLOT_0_VCC0
| PCR_SLOT_0_VCC1
|
213 PCR_SLOT_0_VPP0
| PCR_SLOT_0_VPP1
);
216 pcr
&= ~(PCR_SLOT_1_VCC0
| PCR_SLOT_1_VCC1
|
217 PCR_SLOT_1_VPP0
| PCR_SLOT_1_VPP1
);
220 pcr
&= ~PCR_SLOT_0_RST
;
221 debug("Vcc %dV Vpp %dV, pcr %x\n",
222 configure
->vcc
, configure
->vpp
, pcr
);
223 switch(configure
->vcc
){
225 switch(configure
->vpp
) {
227 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_GND
,
231 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_12V
,
235 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_5V
,
239 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_3V
,
243 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,
245 printk("%s: bad Vcc/Vpp (%d:%d)\n",
252 case 50: /* Vcc 5V */
253 switch(configure
->vpp
) {
255 pcr
|= SET_VCC_VPP(VCC_5V
,VPP_GND
,
259 pcr
|= SET_VCC_VPP(VCC_5V
,VPP_5V
,
263 pcr
|= SET_VCC_VPP(VCC_5V
,VPP_12V
,
267 pcr
|= SET_VCC_VPP(VCC_5V
,VPP_3V
,
271 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,
273 printk("%s: bad Vcc/Vpp (%d:%d)\n",
280 case 33: /* Vcc 3.3V */
281 switch(configure
->vpp
) {
283 pcr
|= SET_VCC_VPP(VCC_3V
,VPP_GND
,
287 pcr
|= SET_VCC_VPP(VCC_3V
,VPP_5V
,
291 pcr
|= SET_VCC_VPP(VCC_3V
,VPP_12V
,
295 pcr
|= SET_VCC_VPP(VCC_3V
,VPP_3V
,
299 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,
301 printk("%s: bad Vcc/Vpp (%d:%d)\n",
308 default: /* what's this ? */
309 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,configure
->sock
);
310 printk(KERN_ERR
"%s: bad Vcc %d\n",
311 __func__
, configure
->vcc
);
315 if (configure
->sock
== 0) {
316 pcr
&= ~(PCR_SLOT_0_RST
);
317 if (configure
->reset
)
318 pcr
|= PCR_SLOT_0_RST
;
321 pcr
&= ~(PCR_SLOT_1_RST
);
322 if (configure
->reset
)
323 pcr
|= PCR_SLOT_1_RST
;
325 au_writel(pcr
, PB1000_PCR
);
330 pcr
= au_readw(PCMCIA_BOARD_REG
) & ~0xf;
332 debug("Vcc %dV Vpp %dV, pcr %x, reset %d\n",
333 configure
->vcc
, configure
->vpp
, pcr
, configure
->reset
);
336 switch(configure
->vcc
){
338 pcr
|= SET_VCC_VPP(0,0);
340 case 50: /* Vcc 5V */
341 switch(configure
->vpp
) {
343 pcr
|= SET_VCC_VPP(2,0);
346 pcr
|= SET_VCC_VPP(2,1);
349 pcr
|= SET_VCC_VPP(2,2);
353 pcr
|= SET_VCC_VPP(0,0);
354 printk("%s: bad Vcc/Vpp (%d:%d)\n",
361 case 33: /* Vcc 3.3V */
362 switch(configure
->vpp
) {
364 pcr
|= SET_VCC_VPP(1,0);
367 pcr
|= SET_VCC_VPP(1,2);
370 pcr
|= SET_VCC_VPP(1,1);
374 pcr
|= SET_VCC_VPP(0,0);
375 printk("%s: bad Vcc/Vpp (%d:%d)\n",
382 default: /* what's this ? */
383 pcr
|= SET_VCC_VPP(0,0);
384 printk(KERN_ERR
"%s: bad Vcc %d\n",
385 __func__
, configure
->vcc
);
389 au_writew(pcr
, PCMCIA_BOARD_REG
);
392 if (!configure
->reset
) {
394 au_writew(pcr
, PCMCIA_BOARD_REG
);
396 pcr
|= PC_DEASSERT_RST
;
397 au_writew(pcr
, PCMCIA_BOARD_REG
);
401 pcr
&= ~(PC_DEASSERT_RST
| PC_DRV_EN
);
402 au_writew(pcr
, PCMCIA_BOARD_REG
);
410 struct pcmcia_low_level pb1x00_pcmcia_ops
= {
412 pb1x00_pcmcia_shutdown
,
413 pb1x00_pcmcia_socket_state
,
414 pb1x00_pcmcia_get_irq_info
,
415 pb1x00_pcmcia_configure_socket