Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/pcmcia/pxa2xx_vpac270.c |
| 3 | * |
| 4 | * Driver for Voipac PXA270 PCMCIA and CF sockets |
| 5 | * |
Marek Vasut | 9ed3fbf | 2011-01-15 19:22:19 +0100 | [diff] [blame] | 6 | * Copyright (C) 2010-2011 Marek Vasut <marek.vasut@gmail.com> |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 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 | |
Randy Dunlap | 158f1e9 | 2011-06-14 17:06:02 -0700 | [diff] [blame] | 14 | #include <linux/gpio.h> |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | |
| 18 | #include <asm/mach-types.h> |
| 19 | |
| 20 | #include <mach/gpio.h> |
| 21 | #include <mach/vpac270.h> |
| 22 | |
| 23 | #include "soc_common.h" |
| 24 | |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 25 | static struct gpio vpac270_pcmcia_gpios[] = { |
| 26 | { GPIO84_VPAC270_PCMCIA_CD, GPIOF_IN, "PCMCIA Card Detect" }, |
| 27 | { GPIO35_VPAC270_PCMCIA_RDY, GPIOF_IN, "PCMCIA Ready" }, |
| 28 | { GPIO107_VPAC270_PCMCIA_PPEN, GPIOF_INIT_LOW, "PCMCIA PPEN" }, |
| 29 | { GPIO11_VPAC270_PCMCIA_RESET, GPIOF_INIT_LOW, "PCMCIA Reset" }, |
| 30 | }; |
| 31 | |
| 32 | static struct gpio vpac270_cf_gpios[] = { |
| 33 | { GPIO17_VPAC270_CF_CD, GPIOF_IN, "CF Card Detect" }, |
| 34 | { GPIO12_VPAC270_CF_RDY, GPIOF_IN, "CF Ready" }, |
| 35 | { GPIO16_VPAC270_CF_RESET, GPIOF_INIT_LOW, "CF Reset" }, |
| 36 | }; |
| 37 | |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 38 | static struct pcmcia_irqs cd_irqs[] = { |
| 39 | { |
| 40 | .sock = 0, |
| 41 | .irq = IRQ_GPIO(GPIO84_VPAC270_PCMCIA_CD), |
| 42 | .str = "PCMCIA CD" |
| 43 | }, |
| 44 | { |
| 45 | .sock = 1, |
| 46 | .irq = IRQ_GPIO(GPIO17_VPAC270_CF_CD), |
| 47 | .str = "CF CD" |
| 48 | }, |
| 49 | }; |
| 50 | |
| 51 | static int vpac270_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 52 | { |
| 53 | int ret; |
| 54 | |
| 55 | if (skt->nr == 0) { |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 56 | ret = gpio_request_array(vpac270_pcmcia_gpios, |
| 57 | ARRAY_SIZE(vpac270_pcmcia_gpios)); |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 58 | |
| 59 | skt->socket.pci_irq = gpio_to_irq(GPIO35_VPAC270_PCMCIA_RDY); |
| 60 | |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 61 | if (!ret) |
| 62 | ret = soc_pcmcia_request_irqs(skt, &cd_irqs[0], 1); |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 63 | } else { |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 64 | ret = gpio_request_array(vpac270_cf_gpios, |
| 65 | ARRAY_SIZE(vpac270_cf_gpios)); |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 66 | |
| 67 | skt->socket.pci_irq = gpio_to_irq(GPIO12_VPAC270_CF_RDY); |
| 68 | |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 69 | if (!ret) |
| 70 | ret = soc_pcmcia_request_irqs(skt, &cd_irqs[1], 1); |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 71 | } |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 72 | |
| 73 | return ret; |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static void vpac270_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 77 | { |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 78 | if (skt->nr == 0) |
Jonathan Cameron | 512b793 | 2011-06-06 15:24:13 +0100 | [diff] [blame] | 79 | gpio_free_array(vpac270_pcmcia_gpios, |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 80 | ARRAY_SIZE(vpac270_pcmcia_gpios)); |
| 81 | else |
Jonathan Cameron | 512b793 | 2011-06-06 15:24:13 +0100 | [diff] [blame] | 82 | gpio_free_array(vpac270_cf_gpios, |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 83 | ARRAY_SIZE(vpac270_cf_gpios)); |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static void vpac270_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 87 | struct pcmcia_state *state) |
| 88 | { |
| 89 | if (skt->nr == 0) { |
| 90 | state->detect = !gpio_get_value(GPIO84_VPAC270_PCMCIA_CD); |
| 91 | state->ready = !!gpio_get_value(GPIO35_VPAC270_PCMCIA_RDY); |
| 92 | } else { |
| 93 | state->detect = !gpio_get_value(GPIO17_VPAC270_CF_CD); |
| 94 | state->ready = !!gpio_get_value(GPIO12_VPAC270_CF_RDY); |
| 95 | } |
| 96 | state->bvd1 = 1; |
| 97 | state->bvd2 = 1; |
| 98 | state->wrprot = 0; |
| 99 | state->vs_3v = 1; |
| 100 | state->vs_Xv = 0; |
| 101 | } |
| 102 | |
| 103 | static int |
| 104 | vpac270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 105 | const socket_state_t *state) |
| 106 | { |
| 107 | if (skt->nr == 0) { |
| 108 | gpio_set_value(GPIO11_VPAC270_PCMCIA_RESET, |
| 109 | (state->flags & SS_RESET)); |
| 110 | gpio_set_value(GPIO107_VPAC270_PCMCIA_PPEN, |
| 111 | !(state->Vcc == 33 || state->Vcc == 50)); |
| 112 | } else { |
| 113 | gpio_set_value(GPIO16_VPAC270_CF_RESET, |
| 114 | (state->flags & SS_RESET)); |
| 115 | } |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static void vpac270_pcmcia_socket_init(struct soc_pcmcia_socket *skt) |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | static void vpac270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | static struct pcmcia_low_level vpac270_pcmcia_ops = { |
| 129 | .owner = THIS_MODULE, |
| 130 | |
| 131 | .first = 0, |
| 132 | .nr = 2, |
| 133 | |
| 134 | .hw_init = vpac270_pcmcia_hw_init, |
| 135 | .hw_shutdown = vpac270_pcmcia_hw_shutdown, |
| 136 | |
| 137 | .socket_state = vpac270_pcmcia_socket_state, |
| 138 | .configure_socket = vpac270_pcmcia_configure_socket, |
| 139 | |
| 140 | .socket_init = vpac270_pcmcia_socket_init, |
| 141 | .socket_suspend = vpac270_pcmcia_socket_suspend, |
| 142 | }; |
| 143 | |
| 144 | static struct platform_device *vpac270_pcmcia_device; |
| 145 | |
| 146 | static int __init vpac270_pcmcia_init(void) |
| 147 | { |
| 148 | int ret; |
| 149 | |
| 150 | if (!machine_is_vpac270()) |
| 151 | return -ENODEV; |
| 152 | |
| 153 | vpac270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 154 | if (!vpac270_pcmcia_device) |
| 155 | return -ENOMEM; |
| 156 | |
| 157 | ret = platform_device_add_data(vpac270_pcmcia_device, |
| 158 | &vpac270_pcmcia_ops, sizeof(vpac270_pcmcia_ops)); |
| 159 | |
| 160 | if (!ret) |
| 161 | ret = platform_device_add(vpac270_pcmcia_device); |
| 162 | |
| 163 | if (ret) |
| 164 | platform_device_put(vpac270_pcmcia_device); |
| 165 | |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | static void __exit vpac270_pcmcia_exit(void) |
| 170 | { |
| 171 | platform_device_unregister(vpac270_pcmcia_device); |
| 172 | } |
| 173 | |
| 174 | module_init(vpac270_pcmcia_init); |
| 175 | module_exit(vpac270_pcmcia_exit); |
| 176 | |
| 177 | MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); |
| 178 | MODULE_DESCRIPTION("PCMCIA support for Voipac PXA270"); |
| 179 | MODULE_ALIAS("platform:pxa2xx-pcmcia"); |
| 180 | MODULE_LICENSE("GPL"); |