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