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