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