Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/pcmcia/pxa/pxa_cm_x270.c |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 8 | * Compulab Ltd., 2003, 2007, 2008 |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 9 | * Mike Rapoport <mike@compulab.co.il> |
| 10 | * |
| 11 | */ |
| 12 | |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 13 | #include <linux/platform_device.h> |
| 14 | #include <linux/irq.h> |
| 15 | #include <linux/delay.h> |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 16 | #include <linux/gpio.h> |
Paul Gortmaker | 402b20d | 2011-07-31 16:21:42 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 18 | |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 19 | #include "soc_common.h" |
| 20 | |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 21 | #define GPIO_PCMCIA_S0_CD_VALID (84) |
| 22 | #define GPIO_PCMCIA_S0_RDYINT (82) |
| 23 | #define GPIO_PCMCIA_RESET (53) |
| 24 | |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 25 | static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 26 | { |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 27 | int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset"); |
| 28 | if (ret) |
| 29 | return ret; |
| 30 | gpio_direction_output(GPIO_PCMCIA_RESET, 0); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 31 | |
Russell King | a9bb5a4 | 2012-01-13 22:56:32 +0000 | [diff] [blame^] | 32 | skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S0_CD_VALID; |
| 33 | skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD"; |
| 34 | skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S0_RDYINT; |
| 35 | skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY"; |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 36 | |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 37 | return ret; |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt) |
| 41 | { |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 42 | gpio_free(GPIO_PCMCIA_RESET); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | |
| 46 | static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 47 | struct pcmcia_state *state) |
| 48 | { |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 49 | state->vs_3v = 0; |
| 50 | state->vs_Xv = 0; |
| 51 | state->wrprot = 0; /* not available */ |
| 52 | } |
| 53 | |
| 54 | |
| 55 | static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 56 | const socket_state_t *state) |
| 57 | { |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 58 | switch (skt->nr) { |
| 59 | case 0: |
| 60 | if (state->flags & SS_RESET) { |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 61 | gpio_set_value(GPIO_PCMCIA_RESET, 1); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 62 | udelay(10); |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 63 | gpio_set_value(GPIO_PCMCIA_RESET, 0); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 64 | } |
| 65 | break; |
| 66 | } |
| 67 | |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 71 | static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = { |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 72 | .owner = THIS_MODULE, |
| 73 | .hw_init = cmx270_pcmcia_hw_init, |
| 74 | .hw_shutdown = cmx270_pcmcia_shutdown, |
| 75 | .socket_state = cmx270_pcmcia_socket_state, |
| 76 | .configure_socket = cmx270_pcmcia_configure_socket, |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 77 | .nr = 1, |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | static struct platform_device *cmx270_pcmcia_device; |
| 81 | |
Mike Rapoport | 8616e2f | 2008-10-05 10:27:22 +0100 | [diff] [blame] | 82 | int __init cmx270_pcmcia_init(void) |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 83 | { |
| 84 | int ret; |
| 85 | |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 86 | cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 87 | |
| 88 | if (!cmx270_pcmcia_device) |
| 89 | return -ENOMEM; |
| 90 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 91 | ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops, |
| 92 | sizeof(cmx270_pcmcia_ops)); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 93 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 94 | if (ret == 0) { |
| 95 | printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n"); |
| 96 | ret = platform_device_add(cmx270_pcmcia_device); |
| 97 | } |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 98 | |
| 99 | if (ret) |
| 100 | platform_device_put(cmx270_pcmcia_device); |
| 101 | |
| 102 | return ret; |
| 103 | } |
| 104 | |
Mike Rapoport | 8616e2f | 2008-10-05 10:27:22 +0100 | [diff] [blame] | 105 | void __exit cmx270_pcmcia_exit(void) |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 106 | { |
| 107 | platform_device_unregister(cmx270_pcmcia_device); |
| 108 | } |