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/timer.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>
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
60 static int pb1x00_pcmcia_init(struct pcmcia_init
*init
)
62 #ifdef CONFIG_MIPS_PB1000
64 pcr
= PCR_SLOT_0_RST
| PCR_SLOT_1_RST
;
66 au_writel(0x8000, PB1000_MDR
); /* clear pcmcia interrupt */
68 au_writel(0x4000, PB1000_MDR
); /* enable pcmcia interrupt */
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
);
76 return PCMCIA_NUM_SOCKS
;
78 #else /* fixme -- take care of the Pb1500 at some point */
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
);
85 return PCMCIA_NUM_SOCKS
;
89 static int pb1x00_pcmcia_shutdown(void)
91 #ifdef CONFIG_MIPS_PB1000
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
);
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
);
110 pb1x00_pcmcia_socket_state(unsigned sock
, struct pcmcia_state
*state
)
112 u32 inserted0
, inserted1
;
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;
122 vs0
= (au_readw(BOARD_STATUS_REG
) >> 4) & 0x3;
123 #ifdef CONFIG_MIPS_PB1500
124 inserted0
= !((au_readl(GPIO2_PINSTATE
) >> 1) & 0x1); /* gpio 201 */
126 inserted0
= !((au_readl(SYS_PINSTATERD
) >> 9) & 0x1); /* gpio 9 */
146 /* return without setting 'detect' */
147 printk(KERN_ERR
"pb1x00 bad VS (%d)\n",
164 /* return without setting 'detect' */
165 printk(KERN_ERR
"pb1x00 bad VS (%d)\n",
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
;
200 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure
*configure
)
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
);
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
){
223 switch(configure
->vpp
) {
225 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_GND
,
229 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_12V
,
233 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_5V
,
237 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_3V
,
241 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,
243 printk("%s: bad Vcc/Vpp (%d:%d)\n",
250 case 50: /* Vcc 5V */
251 switch(configure
->vpp
) {
253 pcr
|= SET_VCC_VPP(VCC_5V
,VPP_GND
,
257 pcr
|= SET_VCC_VPP(VCC_5V
,VPP_5V
,
261 pcr
|= SET_VCC_VPP(VCC_5V
,VPP_12V
,
265 pcr
|= SET_VCC_VPP(VCC_5V
,VPP_3V
,
269 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,
271 printk("%s: bad Vcc/Vpp (%d:%d)\n",
278 case 33: /* Vcc 3.3V */
279 switch(configure
->vpp
) {
281 pcr
|= SET_VCC_VPP(VCC_3V
,VPP_GND
,
285 pcr
|= SET_VCC_VPP(VCC_3V
,VPP_5V
,
289 pcr
|= SET_VCC_VPP(VCC_3V
,VPP_12V
,
293 pcr
|= SET_VCC_VPP(VCC_3V
,VPP_3V
,
297 pcr
|= SET_VCC_VPP(VCC_HIZ
,VPP_HIZ
,
299 printk("%s: bad Vcc/Vpp (%d:%d)\n",
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
);
313 if (configure
->sock
== 0) {
314 pcr
&= ~(PCR_SLOT_0_RST
);
315 if (configure
->reset
)
316 pcr
|= PCR_SLOT_0_RST
;
319 pcr
&= ~(PCR_SLOT_1_RST
);
320 if (configure
->reset
)
321 pcr
|= PCR_SLOT_1_RST
;
323 au_writel(pcr
, PB1000_PCR
);
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
){
336 pcr
|= SET_VCC_VPP(0,0);
338 case 50: /* Vcc 5V */
339 switch(configure
->vpp
) {
341 pcr
|= SET_VCC_VPP(2,0);
344 pcr
|= SET_VCC_VPP(2,1);
347 pcr
|= SET_VCC_VPP(2,2);
351 pcr
|= SET_VCC_VPP(0,0);
352 printk("%s: bad Vcc/Vpp (%d:%d)\n",
359 case 33: /* Vcc 3.3V */
360 switch(configure
->vpp
) {
362 pcr
|= SET_VCC_VPP(1,0);
365 pcr
|= SET_VCC_VPP(1,2);
368 pcr
|= SET_VCC_VPP(1,1);
372 pcr
|= SET_VCC_VPP(0,0);
373 printk("%s: bad Vcc/Vpp (%d:%d)\n",
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
);
387 au_writew(pcr
, PCMCIA_BOARD_REG
);
390 if (!configure
->reset
) {
392 au_writew(pcr
, PCMCIA_BOARD_REG
);
394 pcr
|= PC_DEASSERT_RST
;
395 au_writew(pcr
, PCMCIA_BOARD_REG
);
399 pcr
&= ~(PC_DEASSERT_RST
| PC_DRV_EN
);
400 au_writew(pcr
, PCMCIA_BOARD_REG
);
408 struct pcmcia_low_level pb1x00_pcmcia_ops
= {
410 pb1x00_pcmcia_shutdown
,
411 pb1x00_pcmcia_socket_state
,
412 pb1x00_pcmcia_get_irq_info
,
413 pb1x00_pcmcia_configure_socket