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/version.h>
34 #include <linux/types.h>
36 #include <pcmcia/version.h>
37 #include <pcmcia/cs_types.h>
38 #include <pcmcia/cs.h>
39 #include <pcmcia/ss.h>
40 #include <pcmcia/bulkmem.h>
41 #include <pcmcia/cistpl.h>
42 #include <pcmcia/bus_ops.h>
43 #include "cs_internal.h"
47 #include <asm/system.h>
49 #include <asm/au1000.h>
50 #include <asm/au1000_pcmcia.h>
52 #define debug(fmt, arg...) do { } while (0)
54 #ifdef CONFIG_MIPS_PB1000
55 #include <asm/pb1000.h>
56 #define PCMCIA_IRQ AU1000_GPIO_15
57 #elif defined (CONFIG_MIPS_PB1500)
58 #include <asm/pb1500.h>
59 #define PCMCIA_IRQ AU1500_GPIO_203
60 #elif defined (CONFIG_MIPS_PB1100)
61 #include <asm/pb1100.h>
62 #define PCMCIA_IRQ AU1000_GPIO_11
65 static int pb1x00_pcmcia_init(struct pcmcia_init *init)
67 #ifdef CONFIG_MIPS_PB1000
69 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
71 au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
73 au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
76 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
77 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
78 au_writel(pcr, PB1000_PCR);
81 return PCMCIA_NUM_SOCKS;
83 #else /* fixme -- take care of the Pb1500 at some point */
86 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
87 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
88 au_writew(pcr, PCMCIA_BOARD_REG);
90 return PCMCIA_NUM_SOCKS;
94 static int pb1x00_pcmcia_shutdown(void)
96 #ifdef CONFIG_MIPS_PB1000
98 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
99 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
100 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
101 au_writel(pcr, PB1000_PCR);
106 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
107 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
108 au_writew(pcr, PCMCIA_BOARD_REG);
115 pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
117 u32 inserted0, inserted1;
120 #ifdef CONFIG_MIPS_PB1000
121 vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
122 inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
123 inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
124 vs0 = (vs0 >> 4) & 0x3;
125 vs1 = (vs1 >> 12) & 0x3;
127 vs0 = (au_readw(BOARD_STATUS_REG) >> 4) & 0x3;
128 #ifdef CONFIG_MIPS_PB1500
129 inserted0 = !((au_readl(GPIO2_PINSTATE) >> 1) & 0x1); /* gpio 201 */
131 inserted0 = !((au_readl(SYS_PINSTATERD) >> 9) & 0x1); /* gpio 9 */
151 /* return without setting 'detect' */
152 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
169 /* return without setting 'detect' */
170 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
189 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
192 if(info->sock > PCMCIA_MAX_SOCK) return -1;
195 * Even in the case of the Pb1000, both sockets are connected
196 * to the same irq line.
198 info->irq = PCMCIA_IRQ;
205 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
209 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
211 #ifdef CONFIG_MIPS_PB1000
212 pcr = au_readl(PB1000_PCR);
214 if (configure->sock == 0) {
215 pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
216 PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
219 pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
220 PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
223 pcr &= ~PCR_SLOT_0_RST;
224 debug("Vcc %dV Vpp %dV, pcr %x\n",
225 configure->vcc, configure->vpp, pcr);
226 switch(configure->vcc){
228 switch(configure->vpp) {
230 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
234 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
238 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
242 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
246 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
248 printk("%s: bad Vcc/Vpp (%d:%d)\n",
255 case 50: /* Vcc 5V */
256 switch(configure->vpp) {
258 pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
262 pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
266 pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
270 pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
274 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
276 printk("%s: bad Vcc/Vpp (%d:%d)\n",
283 case 33: /* Vcc 3.3V */
284 switch(configure->vpp) {
286 pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
290 pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
294 pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
298 pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
302 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
304 printk("%s: bad Vcc/Vpp (%d:%d)\n",
311 default: /* what's this ? */
312 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
313 printk(KERN_ERR "%s: bad Vcc %d\n",
314 __FUNCTION__, configure->vcc);
318 if (configure->sock == 0) {
319 pcr &= ~(PCR_SLOT_0_RST);
320 if (configure->reset)
321 pcr |= PCR_SLOT_0_RST;
324 pcr &= ~(PCR_SLOT_1_RST);
325 if (configure->reset)
326 pcr |= PCR_SLOT_1_RST;
328 au_writel(pcr, PB1000_PCR);
333 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf;
335 debug("Vcc %dV Vpp %dV, pcr %x, reset %d\n",
336 configure->vcc, configure->vpp, pcr, configure->reset);
339 switch(configure->vcc){
341 pcr |= SET_VCC_VPP(0,0);
343 case 50: /* Vcc 5V */
344 switch(configure->vpp) {
346 pcr |= SET_VCC_VPP(2,0);
349 pcr |= SET_VCC_VPP(2,1);
352 pcr |= SET_VCC_VPP(2,2);
356 pcr |= SET_VCC_VPP(0,0);
357 printk("%s: bad Vcc/Vpp (%d:%d)\n",
364 case 33: /* Vcc 3.3V */
365 switch(configure->vpp) {
367 pcr |= SET_VCC_VPP(1,0);
370 pcr |= SET_VCC_VPP(1,2);
373 pcr |= SET_VCC_VPP(1,1);
377 pcr |= SET_VCC_VPP(0,0);
378 printk("%s: bad Vcc/Vpp (%d:%d)\n",
385 default: /* what's this ? */
386 pcr |= SET_VCC_VPP(0,0);
387 printk(KERN_ERR "%s: bad Vcc %d\n",
388 __FUNCTION__, configure->vcc);
392 au_writew(pcr, PCMCIA_BOARD_REG);
395 if (!configure->reset) {
397 au_writew(pcr, PCMCIA_BOARD_REG);
399 pcr |= PC_DEASSERT_RST;
400 au_writew(pcr, PCMCIA_BOARD_REG);
404 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
405 au_writew(pcr, PCMCIA_BOARD_REG);
413 struct pcmcia_low_level pb1x00_pcmcia_ops = {
415 pb1x00_pcmcia_shutdown,
416 pb1x00_pcmcia_socket_state,
417 pb1x00_pcmcia_get_irq_info,
418 pb1x00_pcmcia_configure_socket