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 | |
Russell King | 04ba0f6 | 2008-04-24 15:23:25 +0100 | [diff] [blame] | 19 | #include <asm/mach-types.h> |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 20 | |
| 21 | #include "soc_common.h" |
| 22 | |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 23 | #define GPIO_PCMCIA_S0_CD_VALID (84) |
| 24 | #define GPIO_PCMCIA_S0_RDYINT (82) |
| 25 | #define GPIO_PCMCIA_RESET (53) |
| 26 | |
| 27 | #define PCMCIA_S0_CD_VALID IRQ_GPIO(GPIO_PCMCIA_S0_CD_VALID) |
| 28 | #define PCMCIA_S0_RDYINT IRQ_GPIO(GPIO_PCMCIA_S0_RDYINT) |
| 29 | |
| 30 | |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 31 | static struct pcmcia_irqs irqs[] = { |
| 32 | { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" }, |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt) |
| 36 | { |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 37 | int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset"); |
| 38 | if (ret) |
| 39 | return ret; |
| 40 | gpio_direction_output(GPIO_PCMCIA_RESET, 0); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 41 | |
Russell King - ARM Linux | 66024db | 2009-03-29 22:45:26 +0100 | [diff] [blame] | 42 | skt->socket.pci_irq = PCMCIA_S0_RDYINT; |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 43 | ret = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
| 44 | if (!ret) |
| 45 | gpio_free(GPIO_PCMCIA_RESET); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 46 | |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 47 | return ret; |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt) |
| 51 | { |
| 52 | soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs)); |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 53 | gpio_free(GPIO_PCMCIA_RESET); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | |
| 57 | static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt, |
| 58 | struct pcmcia_state *state) |
| 59 | { |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 60 | state->detect = (gpio_get_value(GPIO_PCMCIA_S0_CD_VALID) == 0) ? 1 : 0; |
| 61 | state->ready = (gpio_get_value(GPIO_PCMCIA_S0_RDYINT) == 0) ? 0 : 1; |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 62 | state->bvd1 = 1; |
| 63 | state->bvd2 = 1; |
| 64 | state->vs_3v = 0; |
| 65 | state->vs_Xv = 0; |
| 66 | state->wrprot = 0; /* not available */ |
| 67 | } |
| 68 | |
| 69 | |
| 70 | static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, |
| 71 | const socket_state_t *state) |
| 72 | { |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 73 | switch (skt->nr) { |
| 74 | case 0: |
| 75 | if (state->flags & SS_RESET) { |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 76 | gpio_set_value(GPIO_PCMCIA_RESET, 1); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 77 | udelay(10); |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 78 | gpio_set_value(GPIO_PCMCIA_RESET, 0); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 79 | } |
| 80 | break; |
| 81 | } |
| 82 | |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 86 | static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = { |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 87 | .owner = THIS_MODULE, |
| 88 | .hw_init = cmx270_pcmcia_hw_init, |
| 89 | .hw_shutdown = cmx270_pcmcia_shutdown, |
| 90 | .socket_state = cmx270_pcmcia_socket_state, |
| 91 | .configure_socket = cmx270_pcmcia_configure_socket, |
Mike Rapoport | 779c545 | 2008-06-17 09:48:03 +0100 | [diff] [blame] | 92 | .nr = 1, |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | static struct platform_device *cmx270_pcmcia_device; |
| 96 | |
Mike Rapoport | 8616e2f | 2008-10-05 10:27:22 +0100 | [diff] [blame] | 97 | int __init cmx270_pcmcia_init(void) |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 98 | { |
| 99 | int ret; |
| 100 | |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 101 | cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); |
| 102 | |
| 103 | if (!cmx270_pcmcia_device) |
| 104 | return -ENOMEM; |
| 105 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 106 | ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops, |
| 107 | sizeof(cmx270_pcmcia_ops)); |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 108 | |
Russell King | 4e5e8de | 2008-04-24 15:28:11 +0100 | [diff] [blame] | 109 | if (ret == 0) { |
| 110 | printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n"); |
| 111 | ret = platform_device_add(cmx270_pcmcia_device); |
| 112 | } |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 113 | |
| 114 | if (ret) |
| 115 | platform_device_put(cmx270_pcmcia_device); |
| 116 | |
| 117 | return ret; |
| 118 | } |
| 119 | |
Mike Rapoport | 8616e2f | 2008-10-05 10:27:22 +0100 | [diff] [blame] | 120 | void __exit cmx270_pcmcia_exit(void) |
Mike Rapoport | 87944f3 | 2007-09-23 16:00:20 +0100 | [diff] [blame] | 121 | { |
| 122 | platform_device_unregister(cmx270_pcmcia_device); |
| 123 | } |