Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/pcmcia/pxa/pxa_cm_x270.c |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * Compulab Ltd., 2003, 2007 |
| 9 | * Mike Rapoport <mike@compulab.co.il> |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/irq.h> |
| 17 | #include <linux/delay.h> |
| 18 | |
| 19 | #include <pcmcia/ss.h> |
| 20 | #include <asm/hardware.h> |
| 21 | |
| 22 | #include <asm/arch/pxa-regs.h> |
eric miao | a683b14 | 2008-03-03 09:44:25 +0800 | [diff] [blame] | 23 | #include <asm/arch/pxa2xx-gpio.h> |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 24 | #include <asm/arch/cm-x270.h> |
| 25 | |
| 26 | #include "soc_common.h" |
| 27 | |
| 28 | static struct pcmcia_irqs irqs[] = { |
| 29 | { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" }, |
| 30 | { 1, PCMCIA_S1_CD_VALID, "PCMCIA1 CD" }, |
| 31 | }; |
| 32 | |
| 33 | static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 34 | { |
| 35 | GPSR(GPIO48_nPOE) = GPIO_bit(GPIO48_nPOE) | |
| 36 | GPIO_bit(GPIO49_nPWE) | |
| 37 | GPIO_bit(GPIO50_nPIOR) | |
| 38 | GPIO_bit(GPIO51_nPIOW) | |
| 39 | GPIO_bit(GPIO85_nPCE_1) | |
| 40 | GPIO_bit(GPIO54_nPCE_2); |
| 41 | |
| 42 | pxa_gpio_mode(GPIO48_nPOE_MD); |
| 43 | pxa_gpio_mode(GPIO49_nPWE_MD); |
| 44 | pxa_gpio_mode(GPIO50_nPIOR_MD); |
| 45 | pxa_gpio_mode(GPIO51_nPIOW_MD); |
| 46 | pxa_gpio_mode(GPIO85_nPCE_1_MD); |
| 47 | pxa_gpio_mode(GPIO54_nPCE_2_MD); |
| 48 | pxa_gpio_mode(GPIO55_nPREG_MD); |
| 49 | pxa_gpio_mode(GPIO56_nPWAIT_MD); |
| 50 | pxa_gpio_mode(GPIO57_nIOIS16_MD); |
| 51 | |
| 52 | /* Reset signal */ |
| 53 | pxa_gpio_mode(GPIO53_nPCE_2 | GPIO_OUT); |
| 54 | GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2); |
| 55 | |
| 56 | set_irq_type(PCMCIA_S0_CD_VALID, IRQ_TYPE_EDGE_BOTH); |
| 57 | set_irq_type(PCMCIA_S1_CD_VALID, IRQ_TYPE_EDGE_BOTH); |
| 58 | |
| 59 | /* irq's for slots: */ |
| 60 | set_irq_type(PCMCIA_S0_RDYINT, IRQ_TYPE_EDGE_FALLING); |
| 61 | set_irq_type(PCMCIA_S1_RDYINT, IRQ_TYPE_EDGE_FALLING); |
| 62 | |
| 63 | skt->irq = (skt->nr == 0) ? PCMCIA_S0_RDYINT : PCMCIA_S1_RDYINT; |
| 64 | return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 65 | } |
| 66 | |
| 67 | static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt) |
| 68 | { |
| 69 | soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 70 | |
| 71 | set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_CD_VALID), IRQ_TYPE_NONE); |
| 72 | set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_CD_VALID), IRQ_TYPE_NONE); |
| 73 | |
| 74 | set_irq_type(IRQ_TO_GPIO(PCMCIA_S0_RDYINT), IRQ_TYPE_NONE); |
| 75 | set_irq_type(IRQ_TO_GPIO(PCMCIA_S1_RDYINT), IRQ_TYPE_NONE); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 80 | struct pcmcia_state *state) |
| 81 | { |
| 82 | state->detect = (PCC_DETECT(skt->nr) == 0) ? 1 : 0; |
| 83 | state->ready = (PCC_READY(skt->nr) == 0) ? 0 : 1; |
| 84 | state->bvd1 = 1; |
| 85 | state->bvd2 = 1; |
| 86 | state->vs_3v = 0; |
| 87 | state->vs_Xv = 0; |
| 88 | state->wrprot = 0; /* not available */ |
| 89 | } |
| 90 | |
| 91 | |
| 92 | static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 93 | const socket_state_t *state) |
| 94 | { |
| 95 | GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE); |
| 96 | pxa_gpio_mode(GPIO49_nPWE | GPIO_OUT); |
| 97 | |
| 98 | switch (skt->nr) { |
| 99 | case 0: |
| 100 | if (state->flags & SS_RESET) { |
| 101 | GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE); |
| 102 | GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2); |
| 103 | udelay(10); |
| 104 | GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2); |
| 105 | GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE); |
| 106 | } |
| 107 | break; |
| 108 | case 1: |
| 109 | if (state->flags & SS_RESET) { |
| 110 | GPCR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE); |
| 111 | GPSR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2); |
| 112 | udelay(10); |
| 113 | GPCR(GPIO53_nPCE_2) = GPIO_bit(GPIO53_nPCE_2); |
| 114 | GPSR(GPIO49_nPWE) = GPIO_bit(GPIO49_nPWE); |
| 115 | } |
| 116 | break; |
| 117 | } |
| 118 | |
| 119 | pxa_gpio_mode(GPIO49_nPWE_MD); |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static void cmx270_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
| 129 | { |
| 130 | } |
| 131 | |
| 132 | |
| 133 | static struct pcmcia_low_level cmx270_pcmcia_ops = { |
| 134 | .owner = THIS_MODULE, |
| 135 | .hw_init = cmx270_pcmcia_hw_init, |
| 136 | .hw_shutdown = cmx270_pcmcia_shutdown, |
| 137 | .socket_state = cmx270_pcmcia_socket_state, |
| 138 | .configure_socket = cmx270_pcmcia_configure_socket, |
| 139 | .socket_init = cmx270_pcmcia_socket_init, |
| 140 | .socket_suspend = cmx270_pcmcia_socket_suspend, |
| 141 | .nr = 2, |
| 142 | }; |
| 143 | |
| 144 | static struct platform_device *cmx270_pcmcia_device; |
| 145 | |
| 146 | static int __init cmx270_pcmcia_init(void) |
| 147 | { |
| 148 | int ret; |
| 149 | |
| 150 | cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 151 | |
| 152 | if (!cmx270_pcmcia_device) |
| 153 | return -ENOMEM; |
| 154 | |
| 155 | cmx270_pcmcia_device->dev.platform_data = &cmx270_pcmcia_ops; |
| 156 | |
| 157 | printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n"); |
| 158 | ret = platform_device_add(cmx270_pcmcia_device); |
| 159 | |
| 160 | if (ret) |
| 161 | platform_device_put(cmx270_pcmcia_device); |
| 162 | |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | static void __exit cmx270_pcmcia_exit(void) |
| 167 | { |
| 168 | platform_device_unregister(cmx270_pcmcia_device); |
| 169 | } |
| 170 | |
| 171 | module_init(cmx270_pcmcia_init); |
| 172 | module_exit(cmx270_pcmcia_exit); |
| 173 | |
| 174 | MODULE_LICENSE("GPL"); |
| 175 | MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>"); |
| 176 | MODULE_DESCRIPTION("CM-x270 PCMCIA driver"); |