MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / pcmcia / sa1100_freebird.c
blob8dd00f04d492373ec072b74b9b658dd6b9fabf18
1 /*
2 * drivers/pcmcia/sa1100_freebird.c
4 * Created by Eric Peng <ericpeng@coventive.com>
6 */
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/device.h>
11 #include <linux/init.h>
13 #include <asm/hardware.h>
14 #include <asm/mach-types.h>
15 #include <asm/irq.h>
16 #include "sa1100_generic.h"
18 static struct pcmcia_irqs irqs[] = {
19 { 0, IRQ_GPIO_FREEBIRD_CF_CD, "CF_CD" },
20 { 0, IRQ_GPIO_FREEBIRD_CF_BVD, "CF_BVD1" },
23 static int freebird_pcmcia_init(struct soc_pcmcia_socket *skt)
25 /* Enable Linkup CF card */
26 LINKUP_PRC = 0xc0;
27 mdelay(100);
28 LINKUP_PRC = 0xc1;
29 mdelay(100);
30 LINKUP_PRC = 0xd1;
31 mdelay(100);
32 LINKUP_PRC = 0xd1;
33 mdelay(100);
34 LINKUP_PRC = 0xc0;
36 skt->irq = IRQ_GPIO_FREEBIRD_CF_IRQ;
38 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
41 static void freebird_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
43 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs);
45 /* Disable CF card */
46 LINKUP_PRC = 0x40; /* SSP=1 SOE=0 */
47 mdelay(100);
50 static void
51 freebird_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
53 unsigned long levels = LINKUP_PRS;
54 // printk("LINKUP_PRS=%x\n",levels);
56 state->detect = ((levels & (LINKUP_CD1 | LINKUP_CD2))==0)?1:0;
57 state->ready = (levels & LINKUP_RDY)?1:0;
58 state->bvd1 = (levels & LINKUP_BVD1)?1:0;
59 state->bvd2 = (levels & LINKUP_BVD2)?1:0;
60 state->wrprot = 0; /* Not available on Assabet. */
61 state->vs_3v = 1; /* Can only apply 3.3V on Assabet. */
62 state->vs_Xv = 0;
65 static int
66 freebird_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
67 socket_state_t *state)
69 unsigned long value, flags;
71 local_irq_save(flags);
73 value = 0xc0; /* SSP=1 SOE=1 CFE=1 */
75 switch (state->Vcc) {
76 case 0:
77 break;
79 case 50:
80 printk(KERN_WARNING "%s(): CS asked for 5V, applying 3.3V...\n",
81 __FUNCTION__);
83 case 33: /* Can only apply 3.3V to the CF slot. */
84 value |= LINKUP_S1;
85 break;
87 default:
88 printk(KERN_ERR "%s(): unrecognized Vcc %u\n",
89 __FUNCTION__, state->Vcc);
90 local_irq_restore(flags);
91 return -1;
94 if (state->flags & SS_RESET)
95 value |= LINKUP_RESET;
97 /* Silently ignore Vpp, output enable, speaker enable. */
99 LINKUP_PRC = value;
100 // printk("LINKUP_PRC=%x\n",value);
101 local_irq_restore(flags);
103 return 0;
106 static void freebird_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
108 soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs));
111 static void freebird_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
113 soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs));
116 static struct pcmcia_low_level freebird_pcmcia_ops = {
117 .owner = THIS_MODULE,
118 .hw_init = freebird_pcmcia_hw_init,
119 .hw_shutdown = freebird_pcmcia_hw_shutdown,
120 .socket_state = freebird_pcmcia_socket_state,
121 .configure_socket = freebird_pcmcia_configure_socket,
123 .socket_init = freebird_pcmcia_socket_init,
124 .socket_suspend = freebird_pcmcia_socket_suspend,
127 int __init pcmcia_freebird_init(struct device *dev)
129 int ret = -ENODEV;
131 if (machine_is_freebird())
132 ret = sa11xx_drv_pcmcia_probe(dev, &freebird_pcmcia_ops, 0, 1);
134 return ret;