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 | |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 56 | static int colibri_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 57 | { |
| 58 | int ret; |
| 59 | |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 60 | ret = gpio_request_array(colibri_pcmcia_gpios, |
| 61 | ARRAY_SIZE(colibri_pcmcia_gpios)); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 62 | if (ret) |
| 63 | goto err1; |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 64 | |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 65 | skt->socket.pci_irq = gpio_to_irq(colibri_pcmcia_gpios[READY].gpio); |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame] | 66 | skt->stat[SOC_STAT_CD].irq = gpio_to_irq(colibri_pcmcia_gpios[DETECT].gpio); |
| 67 | skt->stat[SOC_STAT_CD].name = "PCMCIA CD"; |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 68 | |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 69 | err1: |
| 70 | return ret; |
| 71 | } |
| 72 | |
| 73 | static void colibri_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 74 | { |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 75 | gpio_free_array(colibri_pcmcia_gpios, |
| 76 | ARRAY_SIZE(colibri_pcmcia_gpios)); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void colibri_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 80 | struct pcmcia_state *state) |
| 81 | { |
| 82 | |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 83 | state->detect = !!gpio_get_value(colibri_pcmcia_gpios[DETECT].gpio); |
| 84 | state->ready = !!gpio_get_value(colibri_pcmcia_gpios[READY].gpio); |
| 85 | state->bvd1 = !!gpio_get_value(colibri_pcmcia_gpios[BVD1].gpio); |
| 86 | state->bvd2 = !!gpio_get_value(colibri_pcmcia_gpios[BVD2].gpio); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 87 | state->vs_3v = 1; |
| 88 | state->vs_Xv = 0; |
| 89 | } |
| 90 | |
| 91 | static int |
| 92 | colibri_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 93 | const socket_state_t *state) |
| 94 | { |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 95 | gpio_set_value(colibri_pcmcia_gpios[PPEN].gpio, |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 96 | !(state->Vcc == 33 && state->Vpp < 50)); |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 97 | gpio_set_value(colibri_pcmcia_gpios[RESET].gpio, |
| 98 | state->flags & SS_RESET); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 102 | static struct pcmcia_low_level colibri_pcmcia_ops = { |
| 103 | .owner = THIS_MODULE, |
| 104 | |
| 105 | .first = 0, |
| 106 | .nr = 1, |
| 107 | |
| 108 | .hw_init = colibri_pcmcia_hw_init, |
| 109 | .hw_shutdown = colibri_pcmcia_hw_shutdown, |
| 110 | |
| 111 | .socket_state = colibri_pcmcia_socket_state, |
| 112 | .configure_socket = colibri_pcmcia_configure_socket, |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | static struct platform_device *colibri_pcmcia_device; |
| 116 | |
| 117 | static int __init colibri_pcmcia_init(void) |
| 118 | { |
| 119 | int ret; |
| 120 | |
Dmitry Eremin-Solenikov | 8d9bd90 | 2011-02-23 02:30:28 +0300 | [diff] [blame] | 121 | if (!machine_is_colibri() && !machine_is_colibri320()) |
| 122 | return -ENODEV; |
| 123 | |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 124 | colibri_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 125 | if (!colibri_pcmcia_device) |
| 126 | return -ENOMEM; |
| 127 | |
| 128 | /* Colibri PXA270 */ |
| 129 | if (machine_is_colibri()) { |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 130 | colibri_pcmcia_gpios[RESET].gpio = COLIBRI270_RESET_GPIO; |
| 131 | colibri_pcmcia_gpios[PPEN].gpio = COLIBRI270_PPEN_GPIO; |
| 132 | colibri_pcmcia_gpios[BVD1].gpio = COLIBRI270_BVD1_GPIO; |
| 133 | colibri_pcmcia_gpios[BVD2].gpio = COLIBRI270_BVD2_GPIO; |
| 134 | colibri_pcmcia_gpios[DETECT].gpio = COLIBRI270_DETECT_GPIO; |
| 135 | colibri_pcmcia_gpios[READY].gpio = COLIBRI270_READY_GPIO; |
Marek Vasut | fd62999 | 2010-08-11 05:04:53 +0200 | [diff] [blame] | 136 | /* Colibri PXA320 */ |
| 137 | } else if (machine_is_colibri320()) { |
Marek Vasut | e593106 | 2011-01-15 18:40:49 +0100 | [diff] [blame] | 138 | colibri_pcmcia_gpios[RESET].gpio = COLIBRI320_RESET_GPIO; |
| 139 | colibri_pcmcia_gpios[PPEN].gpio = COLIBRI320_PPEN_GPIO; |
| 140 | colibri_pcmcia_gpios[BVD1].gpio = COLIBRI320_BVD1_GPIO; |
| 141 | colibri_pcmcia_gpios[BVD2].gpio = COLIBRI320_BVD2_GPIO; |
| 142 | colibri_pcmcia_gpios[DETECT].gpio = COLIBRI320_DETECT_GPIO; |
| 143 | colibri_pcmcia_gpios[READY].gpio = COLIBRI320_READY_GPIO; |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | ret = platform_device_add_data(colibri_pcmcia_device, |
| 147 | &colibri_pcmcia_ops, sizeof(colibri_pcmcia_ops)); |
| 148 | |
| 149 | if (!ret) |
| 150 | ret = platform_device_add(colibri_pcmcia_device); |
| 151 | |
| 152 | if (ret) |
| 153 | platform_device_put(colibri_pcmcia_device); |
| 154 | |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | static void __exit colibri_pcmcia_exit(void) |
| 159 | { |
| 160 | platform_device_unregister(colibri_pcmcia_device); |
| 161 | } |
| 162 | |
| 163 | module_init(colibri_pcmcia_init); |
| 164 | module_exit(colibri_pcmcia_exit); |
| 165 | |
| 166 | MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); |
Marek Vasut | fd62999 | 2010-08-11 05:04:53 +0200 | [diff] [blame] | 167 | MODULE_DESCRIPTION("PCMCIA support for Toradex Colibri PXA270/PXA320"); |
Marek Vasut | 960c0ac | 2010-08-11 03:32:53 +0200 | [diff] [blame] | 168 | MODULE_ALIAS("platform:pxa2xx-pcmcia"); |
| 169 | MODULE_LICENSE("GPL"); |