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/tqueue.h>
30 #include <linux/timer.h>
32 #include <linux/proc_fs.h>
33 #include <linux/types.h>
35 #include <pcmcia/cs_types.h>
36 #include <pcmcia/cs.h>
37 #include <pcmcia/ss.h>
38 #include <pcmcia/bulkmem.h>
39 #include <pcmcia/cistpl.h>
40 #include <pcmcia/bus_ops.h>
41 #include "cs_internal.h"
45 #include <asm/system.h>
47 #include <asm/au1000.h>
48 #include <asm/au1000_pcmcia.h>
50 #define debug(fmt, arg...) do { } while (0)
52 #ifdef CONFIG_MIPS_PB1000
53 #include <asm/pb1000.h>
54 #define PCMCIA_IRQ AU1000_GPIO_15
55 #elif defined (CONFIG_MIPS_PB1500)
56 #include <asm/pb1500.h>
57 #define PCMCIA_IRQ AU1500_GPIO_203
58 #elif defined (CONFIG_MIPS_PB1100)
59 #include <asm/pb1100.h>
60 #define PCMCIA_IRQ AU1000_GPIO_11
63 static int pb1x00_pcmcia_init(struct pcmcia_init *init)
65 #ifdef CONFIG_MIPS_PB1000
67 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
69 au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
71 au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
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);
79 return PCMCIA_NUM_SOCKS;
81 #else /* fixme -- take care of the Pb1500 at some point */
84 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
85 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
86 au_writew(pcr, PCMCIA_BOARD_REG);
88 return PCMCIA_NUM_SOCKS;
92 static int pb1x00_pcmcia_shutdown(void)
94 #ifdef CONFIG_MIPS_PB1000
96 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
97 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
98 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
99 au_writel(pcr, PB1000_PCR);
104 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
105 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
106 au_writew(pcr, PCMCIA_BOARD_REG);
113 pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
115 u32 inserted0, inserted1;
118 #ifdef CONFIG_MIPS_PB1000
119 vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
120 inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
121 inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
122 vs0 = (vs0 >> 4) & 0x3;
123 vs1 = (vs1 >> 12) & 0x3;
125 vs0 = (au_readw(BOARD_STATUS_REG) >> 4) & 0x3;
126 #ifdef CONFIG_MIPS_PB1500
127 inserted0 = !((au_readl(GPIO2_PINSTATE) >> 1) & 0x1); /* gpio 201 */
129 inserted0 = !((au_readl(SYS_PINSTATERD) >> 9) & 0x1); /* gpio 9 */
149 /* return without setting 'detect' */
150 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
167 /* return without setting 'detect' */
168 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
187 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
190 if(info->sock > PCMCIA_MAX_SOCK) return -1;
193 * Even in the case of the Pb1000, both sockets are connected
194 * to the same irq line.
196 info->irq = PCMCIA_IRQ;
203 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
207 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
209 #ifdef CONFIG_MIPS_PB1000
210 pcr = au_readl(PB1000_PCR);
212 if (configure->sock == 0) {
213 pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
214 PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
217 pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
218 PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
221 pcr &= ~PCR_SLOT_0_RST;
222 debug("Vcc %dV Vpp %dV, pcr %x\n",
223 configure->vcc, configure->vpp, pcr);
224 switch(configure->vcc){
226 switch(configure->vpp) {
228 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
232 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
236 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
240 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
244 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
246 printk("%s: bad Vcc/Vpp (%d:%d)\n",
253 case 50: /* Vcc 5V */
254 switch(configure->vpp) {
256 pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
260 pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
264 pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
268 pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
272 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
274 printk("%s: bad Vcc/Vpp (%d:%d)\n",
281 case 33: /* Vcc 3.3V */
282 switch(configure->vpp) {
284 pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
288 pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
292 pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
296 pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
300 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
302 printk("%s: bad Vcc/Vpp (%d:%d)\n",
309 default: /* what's this ? */
310 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
311 printk(KERN_ERR "%s: bad Vcc %d\n",
312 __FUNCTION__, configure->vcc);
316 if (configure->sock == 0) {
317 pcr &= ~(PCR_SLOT_0_RST);
318 if (configure->reset)
319 pcr |= PCR_SLOT_0_RST;
322 pcr &= ~(PCR_SLOT_1_RST);
323 if (configure->reset)
324 pcr |= PCR_SLOT_1_RST;
326 au_writel(pcr, PB1000_PCR);
331 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf;
333 debug("Vcc %dV Vpp %dV, pcr %x, reset %d\n",
334 configure->vcc, configure->vpp, pcr, configure->reset);
337 switch(configure->vcc){
339 pcr |= SET_VCC_VPP(0,0);
341 case 50: /* Vcc 5V */
342 switch(configure->vpp) {
344 pcr |= SET_VCC_VPP(2,0);
347 pcr |= SET_VCC_VPP(2,1);
350 pcr |= SET_VCC_VPP(2,2);
354 pcr |= SET_VCC_VPP(0,0);
355 printk("%s: bad Vcc/Vpp (%d:%d)\n",
362 case 33: /* Vcc 3.3V */
363 switch(configure->vpp) {
365 pcr |= SET_VCC_VPP(1,0);
368 pcr |= SET_VCC_VPP(1,2);
371 pcr |= SET_VCC_VPP(1,1);
375 pcr |= SET_VCC_VPP(0,0);
376 printk("%s: bad Vcc/Vpp (%d:%d)\n",
383 default: /* what's this ? */
384 pcr |= SET_VCC_VPP(0,0);
385 printk(KERN_ERR "%s: bad Vcc %d\n",
386 __FUNCTION__, configure->vcc);
390 au_writew(pcr, PCMCIA_BOARD_REG);
393 if (!configure->reset) {
395 au_writew(pcr, PCMCIA_BOARD_REG);
397 pcr |= PC_DEASSERT_RST;
398 au_writew(pcr, PCMCIA_BOARD_REG);
402 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
403 au_writew(pcr, PCMCIA_BOARD_REG);
411 struct pcmcia_low_level pb1x00_pcmcia_ops = {
413 pb1x00_pcmcia_shutdown,
414 pb1x00_pcmcia_socket_state,
415 pb1x00_pcmcia_get_irq_info,
416 pb1x00_pcmcia_configure_socket