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 #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 AU1000_GPIO_11 /* fixme */
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(PB1100_MEM_PCMCIA) & ~0xf; /* turn off power */
85 pcr &= ~(PB1100_PC_DEASSERT_RST | PB1100_PC_DRV_EN);
86 au_writew(pcr, PB1100_MEM_PCMCIA);
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(PB1100_MEM_PCMCIA) & ~0xf; /* turn off power */
105 pcr &= ~(PB1100_PC_DEASSERT_RST | PB1100_PC_DRV_EN);
106 au_writew(pcr, PB1100_MEM_PCMCIA);
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(PB1100_BOARD_STATUS) >> 4) & 0x3;
126 inserted0 = !((au_readl(SYS_PINSTATERD) >> 9) & 0x1); /* gpio 9 */
144 /* return without setting 'detect' */
145 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
162 /* return without setting 'detect' */
163 printk(KERN_ERR "pb1x00 bad VS (%d)\n",
182 static int pb1x00_pcmcia_get_irq_info(struct pcmcia_irq_info *info)
185 if(info->sock > PCMCIA_MAX_SOCK) return -1;
188 * Even in the case of the Pb1000, both sockets are connected
189 * to the same irq line.
191 info->irq = PCMCIA_IRQ;
198 pb1x00_pcmcia_configure_socket(const struct pcmcia_configure *configure)
202 if(configure->sock > PCMCIA_MAX_SOCK) return -1;
204 #ifdef CONFIG_MIPS_PB1000
205 pcr = au_readl(PB1000_PCR);
207 if (configure->sock == 0) {
208 pcr &= ~(PCR_SLOT_0_VCC0 | PCR_SLOT_0_VCC1 |
209 PCR_SLOT_0_VPP0 | PCR_SLOT_0_VPP1);
212 pcr &= ~(PCR_SLOT_1_VCC0 | PCR_SLOT_1_VCC1 |
213 PCR_SLOT_1_VPP0 | PCR_SLOT_1_VPP1);
216 pcr &= ~PCR_SLOT_0_RST;
217 DEBUG(KERN_INFO "Vcc %dV Vpp %dV, pcr %x\n",
218 configure->vcc, configure->vpp, pcr);
219 switch(configure->vcc){
221 switch(configure->vpp) {
223 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_GND,
227 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_12V,
231 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_5V,
235 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_3V,
239 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
241 printk("%s: bad Vcc/Vpp (%d:%d)\n",
248 case 50: /* Vcc 5V */
249 switch(configure->vpp) {
251 pcr |= SET_VCC_VPP(VCC_5V,VPP_GND,
255 pcr |= SET_VCC_VPP(VCC_5V,VPP_5V,
259 pcr |= SET_VCC_VPP(VCC_5V,VPP_12V,
263 pcr |= SET_VCC_VPP(VCC_5V,VPP_3V,
267 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
269 printk("%s: bad Vcc/Vpp (%d:%d)\n",
276 case 33: /* Vcc 3.3V */
277 switch(configure->vpp) {
279 pcr |= SET_VCC_VPP(VCC_3V,VPP_GND,
283 pcr |= SET_VCC_VPP(VCC_3V,VPP_5V,
287 pcr |= SET_VCC_VPP(VCC_3V,VPP_12V,
291 pcr |= SET_VCC_VPP(VCC_3V,VPP_3V,
295 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,
297 printk("%s: bad Vcc/Vpp (%d:%d)\n",
304 default: /* what's this ? */
305 pcr |= SET_VCC_VPP(VCC_HIZ,VPP_HIZ,configure->sock);
306 printk(KERN_ERR "%s: bad Vcc %d\n",
307 __FUNCTION__, configure->vcc);
311 if (configure->sock == 0) {
312 pcr &= ~(PCR_SLOT_0_RST);
313 if (configure->reset)
314 pcr |= PCR_SLOT_0_RST;
317 pcr &= ~(PCR_SLOT_1_RST);
318 if (configure->reset)
319 pcr |= PCR_SLOT_1_RST;
321 au_writel(pcr, PB1000_PCR);
326 pcr = au_readw(PB1100_MEM_PCMCIA) & ~0xf;
328 DEBUG(KERN_INFO "Vcc %dV Vpp %dV, pcr %x, reset %d\n",
329 configure->vcc, configure->vpp, pcr, configure->reset);
332 switch(configure->vcc){
334 pcr |= SET_VCC_VPP(0,0);
336 case 50: /* Vcc 5V */
337 switch(configure->vpp) {
339 pcr |= SET_VCC_VPP(2,0);
342 pcr |= SET_VCC_VPP(2,1);
345 pcr |= SET_VCC_VPP(2,2);
349 pcr |= SET_VCC_VPP(0,0);
350 printk("%s: bad Vcc/Vpp (%d:%d)\n",
357 case 33: /* Vcc 3.3V */
358 switch(configure->vpp) {
360 pcr |= SET_VCC_VPP(1,0);
363 pcr |= SET_VCC_VPP(1,2);
366 pcr |= SET_VCC_VPP(1,1);
370 pcr |= SET_VCC_VPP(0,0);
371 printk("%s: bad Vcc/Vpp (%d:%d)\n",
378 default: /* what's this ? */
379 pcr |= SET_VCC_VPP(0,0);
380 printk(KERN_ERR "%s: bad Vcc %d\n",
381 __FUNCTION__, configure->vcc);
385 au_writew(pcr, PB1100_MEM_PCMCIA);
388 if (!configure->reset) {
389 pcr |= PB1100_PC_DRV_EN;
390 au_writew(pcr, PB1100_MEM_PCMCIA);
392 pcr |= PB1100_PC_DEASSERT_RST;
393 au_writew(pcr, PB1100_MEM_PCMCIA);
397 pcr &= ~(PB1100_PC_DEASSERT_RST | PB1100_PC_DRV_EN);
398 au_writew(pcr, PB1100_MEM_PCMCIA);
405 struct pcmcia_low_level pb1x00_pcmcia_ops = {
407 pb1x00_pcmcia_shutdown,
408 pb1x00_pcmcia_socket_state,
409 pb1x00_pcmcia_get_irq_info,
410 pb1x00_pcmcia_configure_socket