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/cs_types.h>
37 #include <pcmcia/cs.h>
38 #include <pcmcia/ss.h>
39 #include <pcmcia/bulkmem.h>
40 #include <pcmcia/cistpl.h>
41 #include <pcmcia/bus_ops.h>
42 #include "cs_internal.h"
46 #include <asm/system.h>
48 #include <asm/au1000.h>
49 #include <asm/au1000_pcmcia.h>
51 #define debug(fmt, arg...) do { } while (0)
53 #ifdef CONFIG_MIPS_PB1000
54 #include <asm/pb1000.h>
55 #define PCMCIA_IRQ AU1000_GPIO_15
56 #elif defined (CONFIG_MIPS_PB1500)
57 #include <asm/pb1500.h>
58 #define PCMCIA_IRQ AU1500_GPIO_203
59 #elif defined (CONFIG_MIPS_PB1100)
60 #include <asm/pb1100.h>
61 #define PCMCIA_IRQ AU1000_GPIO_11
64 static int pb1x00_pcmcia_init(struct pcmcia_init *init)
66 #ifdef CONFIG_MIPS_PB1000
68 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
70 au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
72 au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
75 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
76 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
77 au_writel(pcr, PB1000_PCR);
80 return PCMCIA_NUM_SOCKS;
82 #else /* fixme -- take care of the Pb1500 at some point */
85 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
86 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
87 au_writew(pcr, PCMCIA_BOARD_REG);
89 return PCMCIA_NUM_SOCKS;
93 static int pb1x00_pcmcia_shutdown(void)
95 #ifdef CONFIG_MIPS_PB1000
97 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
98 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
99 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
100 au_writel(pcr, PB1000_PCR);
105 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
106 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
107 au_writew(pcr, PCMCIA_BOARD_REG);
114 pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
116 u32 inserted0, inserted1;
119 #ifdef CONFIG_MIPS_PB1000
120 vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
121 inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
122 inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
123 vs0 = (vs0 >> 4) & 0x3;
124 vs1 = (vs1 >> 12) & 0x3;
126 vs0 = (au_readw(BOARD_STATUS_REG) >> 4) & 0x3;
127 #ifdef CONFIG_MIPS_PB1500
128 inserted0 = !((au_readl(GPIO2_PINSTATE) >> 1) & 0x1); /* gpio 201 */
130 inserted0 = !((au_readl(SYS_PINSTATERD) >> 9) & 0x1); /* gpio 9 */
150 /* return without setting 'detect' */
151 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
168 /* return without setting 'detect' */
169 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
188 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
191 if(info->sock > PCMCIA_MAX_SOCK) return -1;
194 * Even in the case of the Pb1000, both sockets are connected
195 * to the same irq line.
197 info->irq = PCMCIA_IRQ;
204 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
208 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
210 #ifdef CONFIG_MIPS_PB1000
211 pcr = au_readl(PB1000_PCR);
213 if (configure->sock == 0) {
214 pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
215 PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
218 pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
219 PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
222 pcr &= ~PCR_SLOT_0_RST;
223 debug("Vcc %dV Vpp %dV, pcr %x\n",
224 configure->vcc, configure->vpp, pcr);
225 switch(configure->vcc){
227 switch(configure->vpp) {
229 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
233 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
237 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
241 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
245 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
247 printk("%s: bad Vcc/Vpp (%d:%d)\n",
254 case 50: /* Vcc 5V */
255 switch(configure->vpp) {
257 pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
261 pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
265 pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
269 pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
273 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
275 printk("%s: bad Vcc/Vpp (%d:%d)\n",
282 case 33: /* Vcc 3.3V */
283 switch(configure->vpp) {
285 pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
289 pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
293 pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
297 pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
301 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
303 printk("%s: bad Vcc/Vpp (%d:%d)\n",
310 default: /* what's this ? */
311 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
312 printk(KERN_ERR "%s: bad Vcc %d\n",
313 __FUNCTION__, configure->vcc);
317 if (configure->sock == 0) {
318 pcr &= ~(PCR_SLOT_0_RST);
319 if (configure->reset)
320 pcr |= PCR_SLOT_0_RST;
323 pcr &= ~(PCR_SLOT_1_RST);
324 if (configure->reset)
325 pcr |= PCR_SLOT_1_RST;
327 au_writel(pcr, PB1000_PCR);
332 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf;
334 debug("Vcc %dV Vpp %dV, pcr %x, reset %d\n",
335 configure->vcc, configure->vpp, pcr, configure->reset);
338 switch(configure->vcc){
340 pcr |= SET_VCC_VPP(0,0);
342 case 50: /* Vcc 5V */
343 switch(configure->vpp) {
345 pcr |= SET_VCC_VPP(2,0);
348 pcr |= SET_VCC_VPP(2,1);
351 pcr |= SET_VCC_VPP(2,2);
355 pcr |= SET_VCC_VPP(0,0);
356 printk("%s: bad Vcc/Vpp (%d:%d)\n",
363 case 33: /* Vcc 3.3V */
364 switch(configure->vpp) {
366 pcr |= SET_VCC_VPP(1,0);
369 pcr |= SET_VCC_VPP(1,2);
372 pcr |= SET_VCC_VPP(1,1);
376 pcr |= SET_VCC_VPP(0,0);
377 printk("%s: bad Vcc/Vpp (%d:%d)\n",
384 default: /* what's this ? */
385 pcr |= SET_VCC_VPP(0,0);
386 printk(KERN_ERR "%s: bad Vcc %d\n",
387 __FUNCTION__, configure->vcc);
391 au_writew(pcr, PCMCIA_BOARD_REG);
394 if (!configure->reset) {
396 au_writew(pcr, PCMCIA_BOARD_REG);
398 pcr |= PC_DEASSERT_RST;
399 au_writew(pcr, PCMCIA_BOARD_REG);
403 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
404 au_writew(pcr, PCMCIA_BOARD_REG);
412 struct pcmcia_low_level pb1x00_pcmcia_ops = {
414 pb1x00_pcmcia_shutdown,
415 pb1x00_pcmcia_socket_state,
416 pb1x00_pcmcia_get_irq_info,
417 pb1x00_pcmcia_configure_socket