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
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.h>
35 #include <pcmcia/ss.h>
36 #include <pcmcia/cistpl.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)
53 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
55 au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
57 au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
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);
65 return PCMCIA_NUM_SOCKS;
68 static int pb1x00_pcmcia_shutdown(void)
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);
80 pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
82 u32 inserted0, inserted1;
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;
106 /* return without setting 'detect' */
107 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
124 /* return without setting 'detect' */
125 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
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;
160 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
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);
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){
182 switch(configure->vpp) {
184 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
188 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
192 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
196 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
200 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
202 printk("%s: bad Vcc/Vpp (%d:%d)\n",
209 case 50: /* Vcc 5V */
210 switch(configure->vpp) {
212 pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
216 pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
220 pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
224 pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
228 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
230 printk("%s: bad Vcc/Vpp (%d:%d)\n",
237 case 33: /* Vcc 3.3V */
238 switch(configure->vpp) {
240 pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
244 pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
248 pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
252 pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
256 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
258 printk("%s: bad Vcc/Vpp (%d:%d)\n",
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);
272 if (configure->sock == 0) {
273 pcr &= ~(PCR_SLOT_0_RST);
274 if (configure->reset)
275 pcr |= PCR_SLOT_0_RST;
278 pcr &= ~(PCR_SLOT_1_RST);
279 if (configure->reset)
280 pcr |= PCR_SLOT_1_RST;
282 au_writel(pcr, PB1000_PCR);
289 struct pcmcia_low_level pb1x00_pcmcia_ops = {
291 pb1x00_pcmcia_shutdown,
292 pb1x00_pcmcia_socket_state,
293 pb1x00_pcmcia_get_irq_info,
294 pb1x00_pcmcia_configure_socket