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/cistpl.h>
39 #include <pcmcia/bus_ops.h>
43 #include <asm/system.h>
45 #include <asm/au1000.h>
46 #include <asm/au1000_pcmcia.h>
48 #define debug(fmt, arg...) do { } while (0)
50 #ifdef CONFIG_MIPS_PB1000
51 #include <asm/pb1000.h>
52 #define PCMCIA_IRQ AU1000_GPIO_15
53 #elif defined (CONFIG_MIPS_PB1500)
54 #include <asm/pb1500.h>
55 #define PCMCIA_IRQ AU1500_GPIO_203
56 #elif defined (CONFIG_MIPS_PB1100)
57 #include <asm/pb1100.h>
58 #define PCMCIA_IRQ AU1000_GPIO_11
61 static int pb1x00_pcmcia_init(struct pcmcia_init *init)
63 #ifdef CONFIG_MIPS_PB1000
65 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
67 au_writel(0x8000, PB1000_MDR); /* clear pcmcia interrupt */
69 au_writel(0x4000, PB1000_MDR); /* enable pcmcia interrupt */
72 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
73 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
74 au_writel(pcr, PB1000_PCR);
77 return PCMCIA_NUM_SOCKS;
79 #else /* fixme -- take care of the Pb1500 at some point */
82 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
83 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
84 au_writew(pcr, PCMCIA_BOARD_REG);
86 return PCMCIA_NUM_SOCKS;
90 static int pb1x00_pcmcia_shutdown(void)
92 #ifdef CONFIG_MIPS_PB1000
94 pcr = PCR_SLOT_0_RST | PCR_SLOT_1_RST;
95 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,0);
96 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,1);
97 au_writel(pcr, PB1000_PCR);
102 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf; /* turn off power */
103 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
104 au_writew(pcr, PCMCIA_BOARD_REG);
111 pb1x00_pcmcia_socket_state(unsigned sock, struct pcmcia_state *state)
113 u32 inserted0, inserted1;
116 #ifdef CONFIG_MIPS_PB1000
117 vs0 = vs1 = (u16)au_readl(PB1000_ACR1);
118 inserted0 = !(vs0 & (ACR1_SLOT_0_CD1 | ACR1_SLOT_0_CD2));
119 inserted1 = !(vs1 & (ACR1_SLOT_1_CD1 | ACR1_SLOT_1_CD2));
120 vs0 = (vs0 >> 4) & 0x3;
121 vs1 = (vs1 >> 12) & 0x3;
123 vs0 = (au_readw(BOARD_STATUS_REG) >> 4) & 0x3;
124 #ifdef CONFIG_MIPS_PB1500
125 inserted0 = !((au_readl(GPIO2_PINSTATE) >> 1) & 0x1); /* gpio 201 */
127 inserted0 = !((au_readl(SYS_PINSTATERD) >> 9) & 0x1); /* gpio 9 */
147 /* return without setting 'detect' */
148 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
165 /* return without setting 'detect' */
166 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
185 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
188 if(info->sock > PCMCIA_MAX_SOCK) return -1;
191 * Even in the case of the Pb1000, both sockets are connected
192 * to the same irq line.
194 info->irq = PCMCIA_IRQ;
201 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
205 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
207 #ifdef CONFIG_MIPS_PB1000
208 pcr = au_readl(PB1000_PCR);
210 if (configure->sock == 0) {
211 pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
212 PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
215 pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
216 PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
219 pcr &= ~PCR_SLOT_0_RST;
220 debug("Vcc %dV Vpp %dV, pcr %x\n",
221 configure->vcc, configure->vpp, pcr);
222 switch(configure->vcc){
224 switch(configure->vpp) {
226 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
230 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
234 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
238 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
242 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
244 printk("%s: bad Vcc/Vpp (%d:%d)\n",
251 case 50: /* Vcc 5V */
252 switch(configure->vpp) {
254 pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
258 pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
262 pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
266 pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
270 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
272 printk("%s: bad Vcc/Vpp (%d:%d)\n",
279 case 33: /* Vcc 3.3V */
280 switch(configure->vpp) {
282 pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
286 pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
290 pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
294 pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
298 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
300 printk("%s: bad Vcc/Vpp (%d:%d)\n",
307 default: /* what's this ? */
308 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
309 printk(KERN_ERR "%s: bad Vcc %d\n",
310 __func__, configure->vcc);
314 if (configure->sock == 0) {
315 pcr &= ~(PCR_SLOT_0_RST);
316 if (configure->reset)
317 pcr |= PCR_SLOT_0_RST;
320 pcr &= ~(PCR_SLOT_1_RST);
321 if (configure->reset)
322 pcr |= PCR_SLOT_1_RST;
324 au_writel(pcr, PB1000_PCR);
329 pcr = au_readw(PCMCIA_BOARD_REG) & ~0xf;
331 debug("Vcc %dV Vpp %dV, pcr %x, reset %d\n",
332 configure->vcc, configure->vpp, pcr, configure->reset);
335 switch(configure->vcc){
337 pcr |= SET_VCC_VPP(0,0);
339 case 50: /* Vcc 5V */
340 switch(configure->vpp) {
342 pcr |= SET_VCC_VPP(2,0);
345 pcr |= SET_VCC_VPP(2,1);
348 pcr |= SET_VCC_VPP(2,2);
352 pcr |= SET_VCC_VPP(0,0);
353 printk("%s: bad Vcc/Vpp (%d:%d)\n",
360 case 33: /* Vcc 3.3V */
361 switch(configure->vpp) {
363 pcr |= SET_VCC_VPP(1,0);
366 pcr |= SET_VCC_VPP(1,2);
369 pcr |= SET_VCC_VPP(1,1);
373 pcr |= SET_VCC_VPP(0,0);
374 printk("%s: bad Vcc/Vpp (%d:%d)\n",
381 default: /* what's this ? */
382 pcr |= SET_VCC_VPP(0,0);
383 printk(KERN_ERR "%s: bad Vcc %d\n",
384 __func__, configure->vcc);
388 au_writew(pcr, PCMCIA_BOARD_REG);
391 if (!configure->reset) {
393 au_writew(pcr, PCMCIA_BOARD_REG);
395 pcr |= PC_DEASSERT_RST;
396 au_writew(pcr, PCMCIA_BOARD_REG);
400 pcr &= ~(PC_DEASSERT_RST | PC_DRV_EN);
401 au_writew(pcr, PCMCIA_BOARD_REG);
409 struct pcmcia_low_level pb1x00_pcmcia_ops = {
411 pb1x00_pcmcia_shutdown,
412 pb1x00_pcmcia_socket_state,
413 pb1x00_pcmcia_get_irq_info,
414 pb1x00_pcmcia_configure_socket