3 * Alchemy Semi Db1x00 boards specific pcmcia routines.
5 * Copyright 2002 MontaVista Software Inc.
6 * Author: MontaVista Software, Inc.
7 * ppopov@mvista.com or source@mvista.com
9 * Copyright 2004 Pete Popov, updated the driver to 2.6.
10 * Followed the sa11xx API and largely copied many of the hardware
11 * independent functions.
13 * ########################################################################
15 * This program is free software; you can distribute it and/or modify it
16 * under the terms of the GNU General Public License (Version 2) as
17 * published by the Free Software Foundation.
19 * This program is distributed in the hope it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
28 * ########################################################################
33 #include <linux/module.h>
34 #include <linux/kernel.h>
35 #include <linux/errno.h>
36 #include <linux/interrupt.h>
37 #include <linux/device.h>
38 #include <linux/init.h>
41 #include <asm/signal.h>
42 #include <asm/mach-au1x00/au1000.h>
44 #if defined(CONFIG_MIPS_DB1200)
46 #elif defined(CONFIG_MIPS_PB1200)
49 #include <asm/mach-db1x00/db1x00.h>
50 static BCSR
* const bcsr
= (BCSR
*)BCSR_KSEG1_ADDR
;
53 #include "au1000_generic.h"
56 #define debug(x,args...) printk(KERN_DEBUG "%s: " x, __func__ , ##args)
58 #define debug(x,args...)
62 struct au1000_pcmcia_socket au1000_pcmcia_socket
[PCMCIA_NUM_SOCKS
];
63 extern int au1x00_pcmcia_socket_probe(struct device
*, struct pcmcia_low_level
*, int, int);
65 static int db1x00_pcmcia_hw_init(struct au1000_pcmcia_socket
*skt
)
67 #ifdef CONFIG_MIPS_DB1550
68 skt
->irq
= skt
->nr
? AU1000_GPIO_5
: AU1000_GPIO_3
;
69 #elif defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200)
70 skt
->irq
= skt
->nr
? BOARD_PC1_INT
: BOARD_PC0_INT
;
72 skt
->irq
= skt
->nr
? AU1000_GPIO_5
: AU1000_GPIO_2
;
77 static void db1x00_pcmcia_shutdown(struct au1000_pcmcia_socket
*skt
)
79 bcsr
->pcmcia
= 0; /* turn off power */
84 db1x00_pcmcia_socket_state(struct au1000_pcmcia_socket
*skt
, struct pcmcia_state
*state
)
96 vs
= bcsr
->status
& 0x3;
97 #if defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200)
98 inserted
= BOARD_CARD_INSERTED(0);
100 inserted
= !(bcsr
->status
& (1<<4));
104 vs
= (bcsr
->status
& 0xC)>>2;
105 #if defined(CONFIG_MIPS_DB1200) || defined(CONFIG_MIPS_PB1200)
106 inserted
= BOARD_CARD_INSERTED(1);
108 inserted
= !(bcsr
->status
& (1<<5));
111 default:/* should never happen */
116 debug("db1x00 socket %d: inserted %d, vs %d pcmcia %x\n",
117 skt
->nr
, inserted
, vs
, bcsr
->pcmcia
);
128 /* return without setting 'detect' */
129 printk(KERN_ERR
"db1x00 bad VS (%d)\n",
136 /* if the card was previously inserted and then ejected,
137 * we should turn off power to it
139 if ((skt
->nr
== 0) && (bcsr
->pcmcia
& BCSR_PCMCIA_PC0RST
)) {
140 bcsr
->pcmcia
&= ~(BCSR_PCMCIA_PC0RST
|
141 BCSR_PCMCIA_PC0DRVEN
|
146 else if ((skt
->nr
== 1) && bcsr
->pcmcia
& BCSR_PCMCIA_PC1RST
) {
147 bcsr
->pcmcia
&= ~(BCSR_PCMCIA_PC1RST
|
148 BCSR_PCMCIA_PC1DRVEN
|
161 db1x00_pcmcia_configure_socket(struct au1000_pcmcia_socket
*skt
, struct socket_state_t
*state
)
166 debug("config_skt %d Vcc %dV Vpp %dV, reset %d\n",
167 sock
, state
->Vcc
, state
->Vpp
,
168 state
->flags
& SS_RESET
);
170 /* pcmcia reg was set to zero at init time. Be careful when
171 * initializing a socket not to wipe out the settings of the
175 pwr
&= ~(0xf << sock
*8); /* clear voltage settings */
180 pwr
|= SET_VCC_VPP(0,0,sock
);
182 case 50: /* Vcc 5V */
185 pwr
|= SET_VCC_VPP(2,0,sock
);
188 pwr
|= SET_VCC_VPP(2,1,sock
);
191 pwr
|= SET_VCC_VPP(2,2,sock
);
195 pwr
|= SET_VCC_VPP(0,0,sock
);
196 printk("%s: bad Vcc/Vpp (%d:%d)\n",
203 case 33: /* Vcc 3.3V */
206 pwr
|= SET_VCC_VPP(1,0,sock
);
209 pwr
|= SET_VCC_VPP(1,2,sock
);
212 pwr
|= SET_VCC_VPP(1,1,sock
);
216 pwr
|= SET_VCC_VPP(0,0,sock
);
217 printk("%s: bad Vcc/Vpp (%d:%d)\n",
224 default: /* what's this ? */
225 pwr
|= SET_VCC_VPP(0,0,sock
);
226 printk(KERN_ERR
"%s: bad Vcc %d\n",
227 __FUNCTION__
, state
->Vcc
);
235 if (!(state
->flags
& SS_RESET
)) {
236 pwr
|= BCSR_PCMCIA_PC0DRVEN
;
239 pwr
|= BCSR_PCMCIA_PC0RST
;
244 pwr
&= ~(BCSR_PCMCIA_PC0RST
| BCSR_PCMCIA_PC0DRVEN
);
250 if (!(state
->flags
& SS_RESET
)) {
251 pwr
|= BCSR_PCMCIA_PC1DRVEN
;
254 pwr
|= BCSR_PCMCIA_PC1RST
;
259 pwr
&= ~(BCSR_PCMCIA_PC1RST
| BCSR_PCMCIA_PC1DRVEN
);
268 * Enable card status IRQs on (re-)initialisation. This can
269 * be called at initialisation, power management event, or
272 void db1x00_socket_init(struct au1000_pcmcia_socket
*skt
)
274 /* nothing to do for now */
278 * Disable card status IRQs and PCMCIA bus on suspend.
280 void db1x00_socket_suspend(struct au1000_pcmcia_socket
*skt
)
282 /* nothing to do for now */
285 struct pcmcia_low_level db1x00_pcmcia_ops
= {
286 .owner
= THIS_MODULE
,
288 .hw_init
= db1x00_pcmcia_hw_init
,
289 .hw_shutdown
= db1x00_pcmcia_shutdown
,
291 .socket_state
= db1x00_pcmcia_socket_state
,
292 .configure_socket
= db1x00_pcmcia_configure_socket
,
294 .socket_init
= db1x00_socket_init
,
295 .socket_suspend
= db1x00_socket_suspend
298 int au1x_board_init(struct device
*dev
)
301 bcsr
->pcmcia
= 0; /* turn off power, if it's not already off */
303 ret
= au1x00_pcmcia_socket_probe(dev
, &db1x00_pcmcia_ops
, 0, 2);