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 | |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 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[] = { |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 25 | { GPIO107_VPAC270_PCMCIA_PPEN, GPIOF_INIT_LOW, "PCMCIA PPEN" }, |
| 26 | { GPIO11_VPAC270_PCMCIA_RESET, GPIOF_INIT_LOW, "PCMCIA Reset" }, |
| 27 | }; |
| 28 | |
| 29 | static struct gpio vpac270_cf_gpios[] = { |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 30 | { GPIO16_VPAC270_CF_RESET, GPIOF_INIT_LOW, "CF Reset" }, |
| 31 | }; |
| 32 | |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 33 | static int vpac270_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 34 | { |
| 35 | int ret; |
| 36 | |
| 37 | if (skt->nr == 0) { |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 38 | ret = gpio_request_array(vpac270_pcmcia_gpios, |
| 39 | ARRAY_SIZE(vpac270_pcmcia_gpios)); |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 40 | |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame] | 41 | skt->stat[SOC_STAT_CD].gpio = GPIO84_VPAC270_PCMCIA_CD; |
| 42 | skt->stat[SOC_STAT_CD].name = "PCMCIA CD"; |
| 43 | skt->stat[SOC_STAT_RDY].gpio = GPIO35_VPAC270_PCMCIA_RDY; |
| 44 | skt->stat[SOC_STAT_RDY].name = "PCMCIA Ready"; |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 45 | } else { |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 46 | ret = gpio_request_array(vpac270_cf_gpios, |
| 47 | ARRAY_SIZE(vpac270_cf_gpios)); |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 48 | |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame] | 49 | skt->stat[SOC_STAT_CD].gpio = GPIO17_VPAC270_CF_CD; |
| 50 | skt->stat[SOC_STAT_CD].name = "CF CD"; |
| 51 | skt->stat[SOC_STAT_RDY].gpio = GPIO12_VPAC270_CF_RDY; |
| 52 | skt->stat[SOC_STAT_RDY].name = "CF Ready"; |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 53 | } |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 54 | |
| 55 | return ret; |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static void vpac270_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) |
| 59 | { |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 60 | if (skt->nr == 0) |
Jonathan Cameron | 512b7938 | 2011-06-06 15:24:13 +0100 | [diff] [blame] | 61 | gpio_free_array(vpac270_pcmcia_gpios, |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 62 | ARRAY_SIZE(vpac270_pcmcia_gpios)); |
| 63 | else |
Jonathan Cameron | 512b7938 | 2011-06-06 15:24:13 +0100 | [diff] [blame] | 64 | gpio_free_array(vpac270_cf_gpios, |
Marek Vasut | e27af7e | 2011-01-15 19:11:16 +0100 | [diff] [blame] | 65 | ARRAY_SIZE(vpac270_cf_gpios)); |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static void vpac270_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 69 | struct pcmcia_state *state) |
| 70 | { |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 71 | state->vs_3v = 1; |
| 72 | state->vs_Xv = 0; |
| 73 | } |
| 74 | |
| 75 | static int |
| 76 | vpac270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 77 | const socket_state_t *state) |
| 78 | { |
| 79 | if (skt->nr == 0) { |
| 80 | gpio_set_value(GPIO11_VPAC270_PCMCIA_RESET, |
| 81 | (state->flags & SS_RESET)); |
| 82 | gpio_set_value(GPIO107_VPAC270_PCMCIA_PPEN, |
| 83 | !(state->Vcc == 33 || state->Vcc == 50)); |
| 84 | } else { |
| 85 | gpio_set_value(GPIO16_VPAC270_CF_RESET, |
| 86 | (state->flags & SS_RESET)); |
| 87 | } |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 92 | static struct pcmcia_low_level vpac270_pcmcia_ops = { |
| 93 | .owner = THIS_MODULE, |
| 94 | |
| 95 | .first = 0, |
| 96 | .nr = 2, |
| 97 | |
| 98 | .hw_init = vpac270_pcmcia_hw_init, |
| 99 | .hw_shutdown = vpac270_pcmcia_hw_shutdown, |
| 100 | |
| 101 | .socket_state = vpac270_pcmcia_socket_state, |
| 102 | .configure_socket = vpac270_pcmcia_configure_socket, |
Marek Vasut | addff0f | 2010-03-10 04:16:28 +0100 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static struct platform_device *vpac270_pcmcia_device; |
| 106 | |
| 107 | static int __init vpac270_pcmcia_init(void) |
| 108 | { |
| 109 | int ret; |
| 110 | |
| 111 | if (!machine_is_vpac270()) |
| 112 | return -ENODEV; |
| 113 | |
| 114 | vpac270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 115 | if (!vpac270_pcmcia_device) |
| 116 | return -ENOMEM; |
| 117 | |
| 118 | ret = platform_device_add_data(vpac270_pcmcia_device, |
| 119 | &vpac270_pcmcia_ops, sizeof(vpac270_pcmcia_ops)); |
| 120 | |
| 121 | if (!ret) |
| 122 | ret = platform_device_add(vpac270_pcmcia_device); |
| 123 | |
| 124 | if (ret) |
| 125 | platform_device_put(vpac270_pcmcia_device); |
| 126 | |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | static void __exit vpac270_pcmcia_exit(void) |
| 131 | { |
| 132 | platform_device_unregister(vpac270_pcmcia_device); |
| 133 | } |
| 134 | |
| 135 | module_init(vpac270_pcmcia_init); |
| 136 | module_exit(vpac270_pcmcia_exit); |
| 137 | |
| 138 | MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); |
| 139 | MODULE_DESCRIPTION("PCMCIA support for Voipac PXA270"); |
| 140 | MODULE_ALIAS("platform:pxa2xx-pcmcia"); |
| 141 | MODULE_LICENSE("GPL"); |