Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 1 | /* |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 2 | * Viper/Zeus PCMCIA support |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 3 | * Copyright 2004 Arcom Control Systems |
| 4 | * |
| 5 | * Maintained by Marc Zyngier <maz@misterjones.org> |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 6 | * |
| 7 | * Based on: |
| 8 | * iPAQ h2200 PCMCIA support |
| 9 | * Copyright 2004 Koen Kooi <koen@vestingbar.nl> |
| 10 | * |
| 11 | * This file is subject to the terms and conditions of the GNU General Public |
| 12 | * License. See the file COPYING in the main directory of this archive for |
| 13 | * more details. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/errno.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/gpio.h> |
| 23 | |
| 24 | #include <pcmcia/ss.h> |
| 25 | |
| 26 | #include <asm/irq.h> |
| 27 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 28 | #include <mach/arcom-pcmcia.h> |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 29 | |
| 30 | #include "soc_common.h" |
| 31 | #include "pxa2xx_base.h" |
| 32 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 33 | static struct platform_device *arcom_pcmcia_dev; |
| 34 | |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 35 | static struct pcmcia_irqs irqs[] = { |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 36 | { |
| 37 | .sock = 0, |
| 38 | .str = "PCMCIA_CD", |
| 39 | }, |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 42 | static inline struct arcom_pcmcia_pdata *viper_get_pdata(void) |
| 43 | { |
| 44 | return arcom_pcmcia_dev->dev.platform_data; |
| 45 | } |
| 46 | |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 47 | static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 48 | { |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 49 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 50 | unsigned long flags; |
| 51 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 52 | skt->socket.pci_irq = gpio_to_irq(pdata->rdy_gpio); |
| 53 | irqs[0].irq = gpio_to_irq(pdata->cd_gpio); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 54 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 55 | if (gpio_request(pdata->cd_gpio, "CF detect")) |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 56 | goto err_request_cd; |
| 57 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 58 | if (gpio_request(pdata->rdy_gpio, "CF ready")) |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 59 | goto err_request_rdy; |
| 60 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 61 | if (gpio_request(pdata->pwr_gpio, "CF power")) |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 62 | goto err_request_pwr; |
| 63 | |
| 64 | local_irq_save(flags); |
| 65 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 66 | if (gpio_direction_output(pdata->pwr_gpio, 0) || |
| 67 | gpio_direction_input(pdata->cd_gpio) || |
| 68 | gpio_direction_input(pdata->rdy_gpio)) { |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 69 | local_irq_restore(flags); |
| 70 | goto err_dir; |
| 71 | } |
| 72 | |
| 73 | local_irq_restore(flags); |
| 74 | |
| 75 | return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 76 | |
| 77 | err_dir: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 78 | gpio_free(pdata->pwr_gpio); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 79 | err_request_pwr: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 80 | gpio_free(pdata->rdy_gpio); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 81 | err_request_rdy: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 82 | gpio_free(pdata->cd_gpio); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 83 | err_request_cd: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 84 | dev_err(&arcom_pcmcia_dev->dev, "Failed to setup PCMCIA GPIOs\n"); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 85 | return -1; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Release all resources. |
| 90 | */ |
| 91 | static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 92 | { |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 93 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
| 94 | |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 95 | soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 96 | gpio_free(pdata->pwr_gpio); |
| 97 | gpio_free(pdata->rdy_gpio); |
| 98 | gpio_free(pdata->cd_gpio); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 102 | struct pcmcia_state *state) |
| 103 | { |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 104 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
| 105 | |
| 106 | state->detect = !gpio_get_value(pdata->cd_gpio); |
| 107 | state->ready = !!gpio_get_value(pdata->rdy_gpio); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 108 | state->bvd1 = 1; |
| 109 | state->bvd2 = 1; |
| 110 | state->wrprot = 0; |
| 111 | state->vs_3v = 1; /* Can only apply 3.3V */ |
| 112 | state->vs_Xv = 0; |
| 113 | } |
| 114 | |
| 115 | static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 116 | const socket_state_t *state) |
| 117 | { |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 118 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
| 119 | |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 120 | /* Silently ignore Vpp, output enable, speaker enable. */ |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 121 | pdata->reset(state->flags & SS_RESET); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 122 | |
| 123 | /* Apply socket voltage */ |
| 124 | switch (state->Vcc) { |
| 125 | case 0: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 126 | gpio_set_value(pdata->pwr_gpio, 0); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 127 | break; |
| 128 | case 33: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 129 | gpio_set_value(pdata->pwr_gpio, 1); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 130 | break; |
| 131 | default: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 132 | dev_err(&arcom_pcmcia_dev->dev, "Unsupported Vcc:%d\n", state->Vcc); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 133 | return -1; |
| 134 | } |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 139 | static struct pcmcia_low_level viper_pcmcia_ops = { |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 140 | .owner = THIS_MODULE, |
| 141 | .hw_init = viper_pcmcia_hw_init, |
| 142 | .hw_shutdown = viper_pcmcia_hw_shutdown, |
| 143 | .socket_state = viper_pcmcia_socket_state, |
| 144 | .configure_socket = viper_pcmcia_configure_socket, |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 145 | .nr = 1, |
| 146 | }; |
| 147 | |
| 148 | static struct platform_device *viper_pcmcia_device; |
| 149 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 150 | static int viper_pcmcia_probe(struct platform_device *pdev) |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 151 | { |
| 152 | int ret; |
| 153 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 154 | /* I can't imagine more than one device, but you never know... */ |
| 155 | if (arcom_pcmcia_dev) |
| 156 | return -EEXIST; |
| 157 | |
| 158 | if (!pdev->dev.platform_data) |
| 159 | return -EINVAL; |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 160 | |
| 161 | viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 162 | if (!viper_pcmcia_device) |
| 163 | return -ENOMEM; |
| 164 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 165 | arcom_pcmcia_dev = pdev; |
| 166 | |
| 167 | viper_pcmcia_device->dev.parent = &pdev->dev; |
| 168 | |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 169 | ret = platform_device_add_data(viper_pcmcia_device, |
| 170 | &viper_pcmcia_ops, |
| 171 | sizeof(viper_pcmcia_ops)); |
| 172 | |
| 173 | if (!ret) |
| 174 | ret = platform_device_add(viper_pcmcia_device); |
| 175 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 176 | if (ret) { |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 177 | platform_device_put(viper_pcmcia_device); |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 178 | arcom_pcmcia_dev = NULL; |
| 179 | } |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 180 | |
| 181 | return ret; |
| 182 | } |
| 183 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 184 | static int viper_pcmcia_remove(struct platform_device *pdev) |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 185 | { |
| 186 | platform_device_unregister(viper_pcmcia_device); |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 187 | arcom_pcmcia_dev = NULL; |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static struct platform_device_id viper_pcmcia_id_table[] = { |
| 192 | { .name = "viper-pcmcia", }, |
| 193 | { .name = "zeus-pcmcia", }, |
| 194 | { }, |
| 195 | }; |
| 196 | |
| 197 | static struct platform_driver viper_pcmcia_driver = { |
| 198 | .probe = viper_pcmcia_probe, |
| 199 | .remove = viper_pcmcia_remove, |
| 200 | .driver = { |
| 201 | .name = "arcom-pcmcia", |
| 202 | .owner = THIS_MODULE, |
| 203 | }, |
| 204 | .id_table = viper_pcmcia_id_table, |
| 205 | }; |
| 206 | |
| 207 | static int __init viper_pcmcia_init(void) |
| 208 | { |
| 209 | return platform_driver_register(&viper_pcmcia_driver); |
| 210 | } |
| 211 | |
| 212 | static void __exit viper_pcmcia_exit(void) |
| 213 | { |
| 214 | return platform_driver_unregister(&viper_pcmcia_driver); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | module_init(viper_pcmcia_init); |
| 218 | module_exit(viper_pcmcia_exit); |
| 219 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 220 | MODULE_DEVICE_TABLE(platform, viper_pcmcia_id_table); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 221 | MODULE_LICENSE("GPL"); |