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_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 #include <asm/pb1000.h>
50 #define PCMCIA_IRQ AU1000_GPIO_15
52 static int pb1x00_pcmcia_init(struct pcmcia_init *init)
55 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
57 au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
59 au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
62 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
63 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
64 au_writel(pcr, PB1000_PCR);
67 return PCMCIA_NUM_SOCKS;
70 static int pb1x00_pcmcia_shutdown(void)
73 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
74 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
75 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
76 au_writel(pcr, PB1000_PCR);
82 pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
84 u32 inserted0, inserted1;
87 vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
88 inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
89 inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
90 vs0 = (vs0 >> 4) & 0x3;
91 vs1 = (vs1 >> 12) & 0x3;
108 /* return without setting 'detect' */
109 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
126 /* return without setting 'detect' */
127 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
146 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
149 if(info->sock > PCMCIA_MAX_SOCK) return -1;
152 * Even in the case of the Pb1000, both sockets are connected
153 * to the same irq line.
155 info->irq = PCMCIA_IRQ;
162 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
166 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
168 pcr = au_readl(PB1000_PCR);
170 if (configure->sock == 0) {
171 pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
172 PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
175 pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
176 PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
179 pcr &= ~PCR_SLOT_0_RST;
180 debug("Vcc %dV Vpp %dV, pcr %x\n",
181 configure->vcc, configure->vpp, pcr);
182 switch(configure->vcc){
184 switch(configure->vpp) {
186 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
190 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
194 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
198 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
202 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
204 printk("%s: bad Vcc/Vpp (%d:%d)\n",
211 case 50: /* Vcc 5V */
212 switch(configure->vpp) {
214 pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
218 pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
222 pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
226 pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
230 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
232 printk("%s: bad Vcc/Vpp (%d:%d)\n",
239 case 33: /* Vcc 3.3V */
240 switch(configure->vpp) {
242 pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
246 pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
250 pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
254 pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
258 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
260 printk("%s: bad Vcc/Vpp (%d:%d)\n",
267 default: /* what's this ? */
268 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
269 printk(KERN_ERR "%s: bad Vcc %d\n",
270 __func__, configure->vcc);
274 if (configure->sock == 0) {
275 pcr &= ~(PCR_SLOT_0_RST);
276 if (configure->reset)
277 pcr |= PCR_SLOT_0_RST;
280 pcr &= ~(PCR_SLOT_1_RST);
281 if (configure->reset)
282 pcr |= PCR_SLOT_1_RST;
284 au_writel(pcr, PB1000_PCR);
291 struct pcmcia_low_level pb1x00_pcmcia_ops = {
293 pb1x00_pcmcia_shutdown,
294 pb1x00_pcmcia_socket_state,
295 pb1x00_pcmcia_get_irq_info,
296 pb1x00_pcmcia_configure_socket