Merge branch 'drm-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[deliverable/linux.git] / drivers / pcmcia / pxa2xx_stargate2.c
1 /*
2 * linux/drivers/pcmcia/pxa2xx_stargate2.c
3 *
4 * Stargate 2 PCMCIA specific routines.
5 *
6 * Created: December 6, 2005
7 * Author: Ed C. Epp
8 * Copyright: Intel Corp 2005
9 * Jonathan Cameron <jic23@cam.ac.uk> 2009
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/interrupt.h>
20 #include <linux/delay.h>
21 #include <linux/platform_device.h>
22 #include <linux/gpio.h>
23
24 #include <pcmcia/ss.h>
25
26 #include <asm/irq.h>
27 #include <asm/mach-types.h>
28
29 #include "soc_common.h"
30
31 #define SG2_S0_BUFF_CTL 120
32 #define SG2_S0_POWER_CTL 108
33 #define SG2_S0_GPIO_RESET 82
34 #define SG2_S0_GPIO_DETECT 53
35 #define SG2_S0_GPIO_READY 81
36
37 static struct pcmcia_irqs irqs[] = {
38 { 0, IRQ_GPIO(SG2_S0_GPIO_DETECT), "PCMCIA0 CD" },
39 };
40
41 static int sg2_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
42 {
43 skt->socket.pci_irq = IRQ_GPIO(SG2_S0_GPIO_READY);
44 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
45 }
46
47 static void sg2_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
48 {
49 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
50 }
51
52 static void sg2_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
53 struct pcmcia_state *state)
54 {
55 state->detect = !gpio_get_value(SG2_S0_GPIO_DETECT);
56 state->ready = !!gpio_get_value(SG2_S0_GPIO_READY);
57 state->bvd1 = 0; /* not available - battery detect on card */
58 state->bvd2 = 0; /* not available */
59 state->vs_3v = 1; /* not available - voltage detect for card */
60 state->vs_Xv = 0; /* not available */
61 state->wrprot = 0; /* not available - write protect */
62 }
63
64 static int sg2_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
65 const socket_state_t *state)
66 {
67 /* Enable card power */
68 switch (state->Vcc) {
69 case 0:
70 /* sets power ctl register high */
71 gpio_set_value(SG2_S0_POWER_CTL, 1);
72 break;
73 case 33:
74 case 50:
75 /* sets power control register low (clear) */
76 gpio_set_value(SG2_S0_POWER_CTL, 0);
77 msleep(100);
78 break;
79 default:
80 pr_err("%s(): bad Vcc %u\n",
81 __func__, state->Vcc);
82 return -1;
83 }
84
85 /* reset */
86 gpio_set_value(SG2_S0_GPIO_RESET, !!(state->flags & SS_RESET));
87
88 return 0;
89 }
90
91 static void sg2_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
92 {
93 soc_pcmcia_enable_irqs(skt, irqs, ARRAY_SIZE(irqs));
94 }
95
96 static void sg2_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
97 {
98 soc_pcmcia_disable_irqs(skt, irqs, ARRAY_SIZE(irqs));
99 }
100
101 static struct pcmcia_low_level sg2_pcmcia_ops __initdata = {
102 .owner = THIS_MODULE,
103 .hw_init = sg2_pcmcia_hw_init,
104 .hw_shutdown = sg2_pcmcia_hw_shutdown,
105 .socket_state = sg2_pcmcia_socket_state,
106 .configure_socket = sg2_pcmcia_configure_socket,
107 .socket_init = sg2_pcmcia_socket_init,
108 .socket_suspend = sg2_pcmcia_socket_suspend,
109 .nr = 1,
110 };
111
112 static struct platform_device *sg2_pcmcia_device;
113
114 static int __init sg2_pcmcia_init(void)
115 {
116 int ret;
117
118 if (!machine_is_stargate2())
119 return -ENODEV;
120
121 sg2_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
122 if (!sg2_pcmcia_device)
123 return -ENOMEM;
124
125 ret = gpio_request(SG2_S0_BUFF_CTL, "SG2 CF buff ctl");
126 if (ret)
127 goto error_put_platform_device;
128 ret = gpio_request(SG2_S0_POWER_CTL, "SG2 CF power ctl");
129 if (ret)
130 goto error_free_gpio_buff_ctl;
131 ret = gpio_request(SG2_S0_GPIO_RESET, "SG2 CF reset");
132 if (ret)
133 goto error_free_gpio_power_ctl;
134 /* Set gpio directions */
135 gpio_direction_output(SG2_S0_BUFF_CTL, 0);
136 gpio_direction_output(SG2_S0_POWER_CTL, 1);
137 gpio_direction_output(SG2_S0_GPIO_RESET, 1);
138
139 ret = platform_device_add_data(sg2_pcmcia_device,
140 &sg2_pcmcia_ops,
141 sizeof(sg2_pcmcia_ops));
142 if (ret)
143 goto error_free_gpio_reset;
144
145 ret = platform_device_add(sg2_pcmcia_device);
146 if (ret)
147 goto error_free_gpio_reset;
148
149 return 0;
150 error_free_gpio_reset:
151 gpio_free(SG2_S0_GPIO_RESET);
152 error_free_gpio_power_ctl:
153 gpio_free(SG2_S0_POWER_CTL);
154 error_free_gpio_buff_ctl:
155 gpio_free(SG2_S0_BUFF_CTL);
156 error_put_platform_device:
157 platform_device_put(sg2_pcmcia_device);
158
159 return ret;
160 }
161
162 static void __exit sg2_pcmcia_exit(void)
163 {
164 platform_device_unregister(sg2_pcmcia_device);
165 gpio_free(SG2_S0_BUFF_CTL);
166 gpio_free(SG2_S0_POWER_CTL);
167 gpio_free(SG2_S0_GPIO_RESET);
168 }
169
170 fs_initcall(sg2_pcmcia_init);
171 module_exit(sg2_pcmcia_exit);
172
173 MODULE_LICENSE("GPL");
174 MODULE_ALIAS("platform:pxa2xx-pcmcia");
This page took 0.034738 seconds and 5 git commands to generate.