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 | |
Arnd Bergmann | 293b2da | 2012-08-24 15:16:48 +0200 | [diff] [blame] | 28 | #include <linux/platform_data/pcmcia-pxa2xx_viper.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 | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 35 | static inline struct arcom_pcmcia_pdata *viper_get_pdata(void) |
| 36 | { |
| 37 | return arcom_pcmcia_dev->dev.platform_data; |
| 38 | } |
| 39 | |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 40 | static int viper_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 41 | { |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 42 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 43 | unsigned long flags; |
| 44 | |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame] | 45 | skt->stat[SOC_STAT_CD].gpio = pdata->cd_gpio; |
| 46 | skt->stat[SOC_STAT_CD].name = "PCMCIA_CD"; |
| 47 | skt->stat[SOC_STAT_RDY].gpio = pdata->rdy_gpio; |
| 48 | skt->stat[SOC_STAT_RDY].name = "CF ready"; |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 49 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 50 | if (gpio_request(pdata->pwr_gpio, "CF power")) |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 51 | goto err_request_pwr; |
| 52 | |
| 53 | local_irq_save(flags); |
| 54 | |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame] | 55 | if (gpio_direction_output(pdata->pwr_gpio, 0)) { |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 56 | local_irq_restore(flags); |
| 57 | goto err_dir; |
| 58 | } |
| 59 | |
| 60 | local_irq_restore(flags); |
| 61 | |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame] | 62 | return 0; |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 63 | |
| 64 | err_dir: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 65 | gpio_free(pdata->pwr_gpio); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 66 | err_request_pwr: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 67 | dev_err(&arcom_pcmcia_dev->dev, "Failed to setup PCMCIA GPIOs\n"); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 68 | return -1; |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * Release all resources. |
| 73 | */ |
| 74 | static void viper_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 75 | { |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 76 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
| 77 | |
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 | } |
| 80 | |
| 81 | static void viper_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 82 | struct pcmcia_state *state) |
| 83 | { |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 84 | state->vs_3v = 1; /* Can only apply 3.3V */ |
| 85 | state->vs_Xv = 0; |
| 86 | } |
| 87 | |
| 88 | static int viper_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 89 | const socket_state_t *state) |
| 90 | { |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 91 | struct arcom_pcmcia_pdata *pdata = viper_get_pdata(); |
| 92 | |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 93 | /* Silently ignore Vpp, output enable, speaker enable. */ |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 94 | pdata->reset(state->flags & SS_RESET); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 95 | |
| 96 | /* Apply socket voltage */ |
| 97 | switch (state->Vcc) { |
| 98 | case 0: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 99 | gpio_set_value(pdata->pwr_gpio, 0); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 100 | break; |
| 101 | case 33: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 102 | gpio_set_value(pdata->pwr_gpio, 1); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 103 | break; |
| 104 | default: |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 105 | dev_err(&arcom_pcmcia_dev->dev, "Unsupported Vcc:%d\n", state->Vcc); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 112 | static struct pcmcia_low_level viper_pcmcia_ops = { |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 113 | .owner = THIS_MODULE, |
| 114 | .hw_init = viper_pcmcia_hw_init, |
| 115 | .hw_shutdown = viper_pcmcia_hw_shutdown, |
| 116 | .socket_state = viper_pcmcia_socket_state, |
| 117 | .configure_socket = viper_pcmcia_configure_socket, |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 118 | .nr = 1, |
| 119 | }; |
| 120 | |
| 121 | static struct platform_device *viper_pcmcia_device; |
| 122 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 123 | static int viper_pcmcia_probe(struct platform_device *pdev) |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 124 | { |
| 125 | int ret; |
| 126 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 127 | /* I can't imagine more than one device, but you never know... */ |
| 128 | if (arcom_pcmcia_dev) |
| 129 | return -EEXIST; |
| 130 | |
| 131 | if (!pdev->dev.platform_data) |
| 132 | return -EINVAL; |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 133 | |
| 134 | viper_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 135 | if (!viper_pcmcia_device) |
| 136 | return -ENOMEM; |
| 137 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 138 | arcom_pcmcia_dev = pdev; |
| 139 | |
| 140 | viper_pcmcia_device->dev.parent = &pdev->dev; |
| 141 | |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 142 | ret = platform_device_add_data(viper_pcmcia_device, |
| 143 | &viper_pcmcia_ops, |
| 144 | sizeof(viper_pcmcia_ops)); |
| 145 | |
| 146 | if (!ret) |
| 147 | ret = platform_device_add(viper_pcmcia_device); |
| 148 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 149 | if (ret) { |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 150 | platform_device_put(viper_pcmcia_device); |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 151 | arcom_pcmcia_dev = NULL; |
| 152 | } |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 153 | |
| 154 | return ret; |
| 155 | } |
| 156 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 157 | static int viper_pcmcia_remove(struct platform_device *pdev) |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 158 | { |
| 159 | platform_device_unregister(viper_pcmcia_device); |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 160 | arcom_pcmcia_dev = NULL; |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | static struct platform_device_id viper_pcmcia_id_table[] = { |
| 165 | { .name = "viper-pcmcia", }, |
| 166 | { .name = "zeus-pcmcia", }, |
| 167 | { }, |
| 168 | }; |
| 169 | |
| 170 | static struct platform_driver viper_pcmcia_driver = { |
| 171 | .probe = viper_pcmcia_probe, |
| 172 | .remove = viper_pcmcia_remove, |
| 173 | .driver = { |
| 174 | .name = "arcom-pcmcia", |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 175 | }, |
| 176 | .id_table = viper_pcmcia_id_table, |
| 177 | }; |
| 178 | |
Axel Lin | 5d95f8e2 | 2011-11-27 12:53:06 +0800 | [diff] [blame] | 179 | module_platform_driver(viper_pcmcia_driver); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 180 | |
Marc Zyngier | c2de1c38 | 2009-11-14 13:39:13 +0100 | [diff] [blame] | 181 | MODULE_DEVICE_TABLE(platform, viper_pcmcia_id_table); |
Marc Zyngier | 20f18ff | 2008-08-19 12:15:53 +0200 | [diff] [blame] | 182 | MODULE_LICENSE("GPL"); |