Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/pcmcia/pxa2xx_colibri.c |
| 3 | * |
| 4 | * Driver for Toradex Colibri PXA270 CF socket |
| 5 | * |
| 6 | * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/gpio.h> |
| 18 | |
| 19 | #include <asm/mach-types.h> |
| 20 | |
| 21 | #include "soc_common.h" |
| 22 | |
| 23 | #define COLIBRI270_RESET_GPIO 53 |
| 24 | #define COLIBRI270_PPEN_GPIO 107 |
| 25 | #define COLIBRI270_BVD1_GPIO 83 |
| 26 | #define COLIBRI270_BVD2_GPIO 82 |
| 27 | #define COLIBRI270_DETECT_GPIO 84 |
| 28 | #define COLIBRI270_READY_GPIO 1 |
| 29 | |
Marek Vasut | fd62999 | 2010-08-11 05:04:53 +0200 | [diff] [blame] | 30 | #define COLIBRI320_RESET_GPIO 77 |
| 31 | #define COLIBRI320_PPEN_GPIO 57 |
| 32 | #define COLIBRI320_BVD1_GPIO 53 |
| 33 | #define COLIBRI320_BVD2_GPIO 79 |
| 34 | #define COLIBRI320_DETECT_GPIO 81 |
| 35 | #define COLIBRI320_READY_GPIO 29 |
| 36 | |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 37 | enum { |
| 38 | DETECT = 0, |
| 39 | READY = 1, |
| 40 | BVD1 = 2, |
| 41 | BVD2 = 3, |
| 42 | PPEN = 4, |
| 43 | RESET = 5, |
| 44 | }; |
| 45 | |
| 46 | /* Contents of this array are configured on-the-fly in init function */ |
| 47 | static struct gpio colibri_pcmcia_gpios[] = { |
| 48 | { 0, GPIOF_IN, "PCMCIA Detect" }, |
| 49 | { 0, GPIOF_IN, "PCMCIA Ready" }, |
| 50 | { 0, GPIOF_IN, "PCMCIA BVD1" }, |
| 51 | { 0, GPIOF_IN, "PCMCIA BVD2" }, |
| 52 | { 0, GPIOF_INIT_LOW, "PCMCIA PPEN" }, |
| 53 | { 0, GPIOF_INIT_HIGH,"PCMCIA Reset" }, |
| 54 | }; |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 55 | |
| 56 | static struct pcmcia_irqs colibri_irqs[] = { |
| 57 | { |
| 58 | .sock = 0, |
| 59 | .str = "PCMCIA CD" |
| 60 | }, |
| 61 | }; |
| 62 | |
| 63 | static int colibri_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 64 | { |
| 65 | int ret; |
| 66 | |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 67 | ret = gpio_request_array(colibri_pcmcia_gpios, |
| 68 | ARRAY_SIZE(colibri_pcmcia_gpios)); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 69 | if (ret) |
| 70 | goto err1; |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 71 | |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 72 | colibri_irqs[0].irq = gpio_to_irq(colibri_pcmcia_gpios[DETECT].gpio); |
| 73 | skt->socket.pci_irq = gpio_to_irq(colibri_pcmcia_gpios[READY].gpio); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 74 | |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 75 | ret = soc_pcmcia_request_irqs(skt, colibri_irqs, |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 76 | ARRAY_SIZE(colibri_irqs)); |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 77 | if (ret) |
| 78 | goto err2; |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 79 | |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 80 | return ret; |
| 81 | |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 82 | err2: |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 83 | gpio_free_array(colibri_pcmcia_gpios, |
| 84 | ARRAY_SIZE(colibri_pcmcia_gpios)); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 85 | err1: |
| 86 | return ret; |
| 87 | } |
| 88 | |
| 89 | static void colibri_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 90 | { |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 91 | gpio_free_array(colibri_pcmcia_gpios, |
| 92 | ARRAY_SIZE(colibri_pcmcia_gpios)); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static void colibri_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 96 | struct pcmcia_state *state) |
| 97 | { |
| 98 | |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 99 | state->detect = !!gpio_get_value(colibri_pcmcia_gpios[DETECT].gpio); |
| 100 | state->ready = !!gpio_get_value(colibri_pcmcia_gpios[READY].gpio); |
| 101 | state->bvd1 = !!gpio_get_value(colibri_pcmcia_gpios[BVD1].gpio); |
| 102 | state->bvd2 = !!gpio_get_value(colibri_pcmcia_gpios[BVD2].gpio); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 103 | state->wrprot = 0; |
| 104 | state->vs_3v = 1; |
| 105 | state->vs_Xv = 0; |
| 106 | } |
| 107 | |
| 108 | static int |
| 109 | colibri_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 110 | const socket_state_t *state) |
| 111 | { |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 112 | gpio_set_value(colibri_pcmcia_gpios[PPEN].gpio, |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 113 | !(state->Vcc == 33 && state->Vpp < 50)); |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 114 | gpio_set_value(colibri_pcmcia_gpios[RESET].gpio, |
| 115 | state->flags & SS_RESET); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | static void colibri_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 120 | { |
| 121 | } |
| 122 | |
| 123 | static void colibri_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | static struct pcmcia_low_level colibri_pcmcia_ops = { |
| 128 | .owner = THIS_MODULE, |
| 129 | |
| 130 | .first = 0, |
| 131 | .nr = 1, |
| 132 | |
| 133 | .hw_init = colibri_pcmcia_hw_init, |
| 134 | .hw_shutdown = colibri_pcmcia_hw_shutdown, |
| 135 | |
| 136 | .socket_state = colibri_pcmcia_socket_state, |
| 137 | .configure_socket = colibri_pcmcia_configure_socket, |
| 138 | |
| 139 | .socket_init = colibri_pcmcia_socket_init, |
| 140 | .socket_suspend = colibri_pcmcia_socket_suspend, |
| 141 | }; |
| 142 | |
| 143 | static struct platform_device *colibri_pcmcia_device; |
| 144 | |
| 145 | static int __init colibri_pcmcia_init(void) |
| 146 | { |
| 147 | int ret; |
| 148 | |
Dmitry Eremin-Solenikov | 8d9bd90 | 2011-02-23 02:30:28 +0300 | [diff] [blame] | 149 | if (!machine_is_colibri() && !machine_is_colibri320()) |
| 150 | return -ENODEV; |
| 151 | |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 152 | colibri_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 153 | if (!colibri_pcmcia_device) |
| 154 | return -ENOMEM; |
| 155 | |
| 156 | /* Colibri PXA270 */ |
| 157 | if (machine_is_colibri()) { |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 158 | colibri_pcmcia_gpios[RESET].gpio = COLIBRI270_RESET_GPIO; |
| 159 | colibri_pcmcia_gpios[PPEN].gpio = COLIBRI270_PPEN_GPIO; |
| 160 | colibri_pcmcia_gpios[BVD1].gpio = COLIBRI270_BVD1_GPIO; |
| 161 | colibri_pcmcia_gpios[BVD2].gpio = COLIBRI270_BVD2_GPIO; |
| 162 | colibri_pcmcia_gpios[DETECT].gpio = COLIBRI270_DETECT_GPIO; |
| 163 | colibri_pcmcia_gpios[READY].gpio = COLIBRI270_READY_GPIO; |
Marek Vasut | fd62999 | 2010-08-11 05:04:53 +0200 | [diff] [blame] | 164 | /* Colibri PXA320 */ |
| 165 | } else if (machine_is_colibri320()) { |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 166 | colibri_pcmcia_gpios[RESET].gpio = COLIBRI320_RESET_GPIO; |
| 167 | colibri_pcmcia_gpios[PPEN].gpio = COLIBRI320_PPEN_GPIO; |
| 168 | colibri_pcmcia_gpios[BVD1].gpio = COLIBRI320_BVD1_GPIO; |
| 169 | colibri_pcmcia_gpios[BVD2].gpio = COLIBRI320_BVD2_GPIO; |
| 170 | colibri_pcmcia_gpios[DETECT].gpio = COLIBRI320_DETECT_GPIO; |
| 171 | colibri_pcmcia_gpios[READY].gpio = COLIBRI320_READY_GPIO; |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | ret = platform_device_add_data(colibri_pcmcia_device, |
| 175 | &colibri_pcmcia_ops, sizeof(colibri_pcmcia_ops)); |
| 176 | |
| 177 | if (!ret) |
| 178 | ret = platform_device_add(colibri_pcmcia_device); |
| 179 | |
| 180 | if (ret) |
| 181 | platform_device_put(colibri_pcmcia_device); |
| 182 | |
| 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | static void __exit colibri_pcmcia_exit(void) |
| 187 | { |
| 188 | platform_device_unregister(colibri_pcmcia_device); |
| 189 | } |
| 190 | |
| 191 | module_init(colibri_pcmcia_init); |
| 192 | module_exit(colibri_pcmcia_exit); |
| 193 | |
| 194 | MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); |
Marek Vasut | fd62999 | 2010-08-11 05:04:53 +0200 | [diff] [blame] | 195 | MODULE_DESCRIPTION("PCMCIA support for Toradex Colibri PXA270/PXA320"); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 196 | MODULE_ALIAS("platform:pxa2xx-pcmcia"); |
| 197 | MODULE_LICENSE("GPL"); |