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 * ########################################################################
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 * ########################################################################
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/config.h>
31 #include <linux/delay.h>
32 #include <linux/ioport.h>
33 #include <linux/kernel.h>
34 #include <linux/tqueue.h>
35 #include <linux/timer.h>
37 #include <linux/proc_fs.h>
38 #include <linux/version.h>
39 #include <linux/types.h>
41 #include <pcmcia/version.h>
42 #include <pcmcia/cs_types.h>
43 #include <pcmcia/cs.h>
44 #include <pcmcia/ss.h>
45 #include <pcmcia/bulkmem.h>
46 #include <pcmcia/cistpl.h>
47 #include <pcmcia/bus_ops.h>
48 #include "cs_internal.h"
52 #include <asm/system.h>
54 #include <asm/au1000.h>
55 #include <asm/au1000_pcmcia.h>
57 #include <asm/db1x00.h>
59 static BCSR * const bcsr = (BCSR *)BCSR_KSEG1_ADDR;
61 static int db1x00_pcmcia_init(struct pcmcia_init *init)
63 bcsr->pcmcia = 0; /* turn off power */
65 return PCMCIA_NUM_SOCKS;
68 static int db1x00_pcmcia_shutdown(void)
70 bcsr->pcmcia = 0; /* turn off power */
76 db1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
81 if(sock > PCMCIA_MAX_SOCK) return -1;
89 vs = bcsr->status & 0x3;
90 inserted = !(bcsr->status & (1<<4));
93 vs = (bcsr->status & 0xC)>>2;
94 inserted = !(bcsr->status & (1<<5));
97 DEBUG(KERN_DEBUG "db1x00 socket %d: inserted %d, vs %d\n",
109 /* return without setting 'detect' */
110 printk(KERN_ERR "db1x00 bad VS (%d)\n",
118 /* if the card was previously inserted and then ejected,
119 * we should turn off power to it
121 if ((sock == 0) && (bcsr->pcmcia & BCSR_PCMCIA_PC0RST)) {
122 bcsr->pcmcia &= ~(BCSR_PCMCIA_PC0RST |
123 BCSR_PCMCIA_PC0DRVEN |
127 else if ((sock == 1) && (bcsr->pcmcia & BCSR_PCMCIA_PC1RST)) {
128 bcsr->pcmcia &= ~(BCSR_PCMCIA_PC1RST |
129 BCSR_PCMCIA_PC1DRVEN |
142 static int db1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
144 if(info->sock > PCMCIA_MAX_SOCK) return -1;
147 #ifdef CONFIG_MIPS_DB1550
148 info->irq = AU1000_GPIO_3;
150 info->irq = AU1000_GPIO_5;
152 info->irq = AU1000_GPIO_2;
154 info->irq = AU1000_GPIO_5;
162 db1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
165 int sock = configure->sock;
167 if(sock > PCMCIA_MAX_SOCK) return -1;
169 DEBUG(KERN_DEBUG "socket %d Vcc %dV Vpp %dV, reset %d\n",
170 sock, configure->vcc, configure->vpp, configure->reset);
172 /* pcmcia reg was set to zero at init time. Be careful when
173 * initializing a socket not to wipe out the settings of the
177 pwr &= ~(0xf << sock*8); /* clear voltage settings */
179 switch(configure->vcc){
181 pwr |= SET_VCC_VPP(0,0,sock);
183 case 50: /* Vcc 5V */
184 switch(configure->vpp) {
186 pwr |= SET_VCC_VPP(2,0,sock);
189 pwr |= SET_VCC_VPP(2,1,sock);
192 pwr |= SET_VCC_VPP(2,2,sock);
196 pwr |= SET_VCC_VPP(0,0,sock);
197 printk("%s: bad Vcc/Vpp (%d:%d)\n",
204 case 33: /* Vcc 3.3V */
205 switch(configure->vpp) {
207 pwr |= SET_VCC_VPP(1,0,sock);
210 pwr |= SET_VCC_VPP(1,2,sock);
213 pwr |= SET_VCC_VPP(1,1,sock);
217 pwr |= SET_VCC_VPP(0,0,sock);
218 printk("%s: bad Vcc/Vpp (%d:%d)\n",
225 default: /* what's this ? */
226 pwr |= SET_VCC_VPP(0,0,sock);
227 printk(KERN_ERR "%s: bad Vcc %d\n",
228 __FUNCTION__, configure->vcc);
236 if (!configure->reset) {
237 pwr |= BCSR_PCMCIA_PC0DRVEN;
240 pwr |= BCSR_PCMCIA_PC0RST;
245 pwr &= ~(BCSR_PCMCIA_PC0RST | BCSR_PCMCIA_PC0DRVEN);
251 if (!configure->reset) {
252 pwr |= BCSR_PCMCIA_PC1DRVEN;
255 pwr |= BCSR_PCMCIA_PC1RST;
260 pwr &= ~(BCSR_PCMCIA_PC1RST | BCSR_PCMCIA_PC1DRVEN);
268 struct pcmcia_low_level au1x00_pcmcia_ops = {
270 db1x00_pcmcia_shutdown,
271 db1x00_pcmcia_socket_state,
272 db1x00_pcmcia_get_irq_info,
273 db1x00_pcmcia_configure_socket