blob: 0b4f946cf13aa6126f9b55a371cd9279fe5a8c3e [file] [log] [blame]
Mike Rapoport8616e2f2008-10-05 10:27:22 +01001/*
2 * linux/drivers/pcmcia/pxa/pxa_cm_x255.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 *
8 * Compulab Ltd., 2003, 2007, 2008
9 * Mike Rapoport <mike@compulab.co.il>
10 *
11 */
12
13#include <linux/platform_device.h>
14#include <linux/irq.h>
15#include <linux/delay.h>
16#include <linux/gpio.h>
Paul Gortmaker402b20d2011-07-31 16:21:42 -040017#include <linux/export.h>
Mike Rapoport8616e2f2008-10-05 10:27:22 +010018
19#include <asm/mach-types.h>
Mike Rapoport8616e2f2008-10-05 10:27:22 +010020
21#include "soc_common.h"
22
23#define GPIO_PCMCIA_SKTSEL (54)
24#define GPIO_PCMCIA_S0_CD_VALID (16)
25#define GPIO_PCMCIA_S1_CD_VALID (17)
26#define GPIO_PCMCIA_S0_RDYINT (6)
27#define GPIO_PCMCIA_S1_RDYINT (8)
28#define GPIO_PCMCIA_RESET (9)
29
30#define PCMCIA_S0_CD_VALID IRQ_GPIO(GPIO_PCMCIA_S0_CD_VALID)
31#define PCMCIA_S1_CD_VALID IRQ_GPIO(GPIO_PCMCIA_S1_CD_VALID)
32#define PCMCIA_S0_RDYINT IRQ_GPIO(GPIO_PCMCIA_S0_RDYINT)
33#define PCMCIA_S1_RDYINT IRQ_GPIO(GPIO_PCMCIA_S1_RDYINT)
34
35
36static struct pcmcia_irqs irqs[] = {
37 { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" },
38 { 1, PCMCIA_S1_CD_VALID, "PCMCIA1 CD" },
39};
40
41static int cmx255_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
42{
43 int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
44 if (ret)
45 return ret;
46 gpio_direction_output(GPIO_PCMCIA_RESET, 0);
47
Russell King - ARM Linux66024db2009-03-29 22:45:26 +010048 skt->socket.pci_irq = skt->nr == 0 ? PCMCIA_S0_RDYINT : PCMCIA_S1_RDYINT;
Mike Rapoport8616e2f2008-10-05 10:27:22 +010049 ret = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
50 if (!ret)
51 gpio_free(GPIO_PCMCIA_RESET);
52
53 return ret;
54}
55
56static void cmx255_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
57{
58 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
59 gpio_free(GPIO_PCMCIA_RESET);
60}
61
62
63static void cmx255_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
64 struct pcmcia_state *state)
65{
66 int cd = skt->nr ? GPIO_PCMCIA_S1_CD_VALID : GPIO_PCMCIA_S0_CD_VALID;
Mike Rapoport91c39dc2009-04-02 10:21:29 +010067 int rdy = skt->nr ? GPIO_PCMCIA_S1_RDYINT : GPIO_PCMCIA_S0_RDYINT;
Mike Rapoport8616e2f2008-10-05 10:27:22 +010068
69 state->detect = !gpio_get_value(cd);
70 state->ready = !!gpio_get_value(rdy);
71 state->bvd1 = 1;
72 state->bvd2 = 1;
73 state->vs_3v = 0;
74 state->vs_Xv = 0;
75 state->wrprot = 0; /* not available */
76}
77
78
79static int cmx255_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
80 const socket_state_t *state)
81{
82 switch (skt->nr) {
83 case 0:
84 if (state->flags & SS_RESET) {
85 gpio_set_value(GPIO_PCMCIA_SKTSEL, 0);
86 udelay(1);
87 gpio_set_value(GPIO_PCMCIA_RESET, 1);
88 udelay(10);
89 gpio_set_value(GPIO_PCMCIA_RESET, 0);
90 }
91 break;
92 case 1:
93 if (state->flags & SS_RESET) {
94 gpio_set_value(GPIO_PCMCIA_SKTSEL, 1);
95 udelay(1);
96 gpio_set_value(GPIO_PCMCIA_RESET, 1);
97 udelay(10);
98 gpio_set_value(GPIO_PCMCIA_RESET, 0);
99 }
100 break;
101 }
102
103 return 0;
104}
105
Mike Rapoport8616e2f2008-10-05 10:27:22 +0100106static struct pcmcia_low_level cmx255_pcmcia_ops __initdata = {
107 .owner = THIS_MODULE,
108 .hw_init = cmx255_pcmcia_hw_init,
109 .hw_shutdown = cmx255_pcmcia_shutdown,
110 .socket_state = cmx255_pcmcia_socket_state,
111 .configure_socket = cmx255_pcmcia_configure_socket,
Mike Rapoport8616e2f2008-10-05 10:27:22 +0100112 .nr = 1,
113};
114
115static struct platform_device *cmx255_pcmcia_device;
116
117int __init cmx255_pcmcia_init(void)
118{
119 int ret;
120
121 cmx255_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
122
123 if (!cmx255_pcmcia_device)
124 return -ENOMEM;
125
126 ret = platform_device_add_data(cmx255_pcmcia_device, &cmx255_pcmcia_ops,
127 sizeof(cmx255_pcmcia_ops));
128
129 if (ret == 0) {
130 printk(KERN_INFO "Registering cm-x255 PCMCIA interface.\n");
131 ret = platform_device_add(cmx255_pcmcia_device);
132 }
133
134 if (ret)
135 platform_device_put(cmx255_pcmcia_device);
136
137 return ret;
138}
139
140void __exit cmx255_pcmcia_exit(void)
141{
142 platform_device_unregister(cmx255_pcmcia_device);
143}