2 * linux/drivers/pcmcia/pxa2xx_trizeps4.c
4 * TRIZEPS PCMCIA specific routines.
6 * Author: Jürgen Schindele
8 * Copyright: Jürgen Schindele
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/gpio.h>
19 #include <linux/interrupt.h>
20 #include <linux/platform_device.h>
22 #include <asm/mach-types.h>
25 #include <mach/pxa2xx-regs.h>
26 #include <mach/trizeps4.h>
28 #include "soc_common.h"
30 extern void board_pcmcia_power(int power);
32 static struct pcmcia_irqs irqs[] = {
33 { 0, IRQ_GPIO(GPIO_PCD), "cs0_cd" }
34 /* on other baseboards we can have more inputs */
37 static int trizeps_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
40 /* we dont have voltage/card/ready detection
41 * so we dont need interrupts for it
45 if (gpio_request(GPIO_PRDY, "cf_irq") < 0) {
46 pr_err("%s: sock %d unable to request gpio %d\n", __func__,
50 if (gpio_direction_input(GPIO_PRDY) < 0) {
51 pr_err("%s: sock %d unable to set input gpio %d\n", __func__,
56 skt->socket.pci_irq = IRQ_GPIO(GPIO_PRDY);
61 /* release the reset of this card */
62 pr_debug("%s: sock %d irq %d\n", __func__, skt->nr, skt->socket.pci_irq);
64 /* supplementory irqs for the socket */
65 for (i = 0; i < ARRAY_SIZE(irqs); i++) {
66 if (irqs[i].sock != skt->nr)
68 if (gpio_request(irq_to_gpio(irqs[i].irq), irqs[i].str) < 0) {
69 pr_err("%s: sock %d unable to request gpio %d\n",
70 __func__, skt->nr, irq_to_gpio(irqs[i].irq));
74 if (gpio_direction_input(irq_to_gpio(irqs[i].irq)) < 0) {
75 pr_err("%s: sock %d unable to set input gpio %d\n",
76 __func__, skt->nr, irq_to_gpio(irqs[i].irq));
81 return soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
85 gpio_free(irq_to_gpio(irqs[i].irq));
90 static void trizeps_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
93 /* free allocated gpio's */
95 for (i = 0; i < ARRAY_SIZE(irqs); i++)
96 gpio_free(irq_to_gpio(irqs[i].irq));
99 static unsigned long trizeps_pcmcia_status[2];
101 static void trizeps_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
102 struct pcmcia_state *state)
104 unsigned short status = 0, change;
105 status = CFSR_readw();
106 change = (status ^ trizeps_pcmcia_status[skt->nr]) &
109 trizeps_pcmcia_status[skt->nr] = status;
110 if (status & ConXS_CFSR_BVD1) {
111 /* enable_irq empty */
113 /* disable_irq empty */
119 /* just fill in fix states */
120 state->detect = gpio_get_value(GPIO_PCD) ? 0 : 1;
121 state->ready = gpio_get_value(GPIO_PRDY) ? 1 : 0;
122 state->bvd1 = (status & ConXS_CFSR_BVD1) ? 1 : 0;
123 state->bvd2 = (status & ConXS_CFSR_BVD2) ? 1 : 0;
124 state->vs_3v = (status & ConXS_CFSR_VS1) ? 0 : 1;
125 state->vs_Xv = (status & ConXS_CFSR_VS2) ? 0 : 1;
126 state->wrprot = 0; /* not available */
129 #ifndef CONFIG_MACH_TRIZEPS_CONXS
130 /* on ConXS we only have one slot. Second is inactive */
145 static int trizeps_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
146 const socket_state_t *state)
149 unsigned short power = 0;
151 /* we do nothing here just check a bit */
152 switch (state->Vcc) {
153 case 0: power &= 0xfc; break;
154 case 33: power |= ConXS_BCR_S0_VCC_3V3; break;
156 pr_err("%s(): Vcc 5V not supported in socket\n", __func__);
159 pr_err("%s(): bad Vcc %u\n", __func__, state->Vcc);
163 switch (state->Vpp) {
164 case 0: power &= 0xf3; break;
165 case 33: power |= ConXS_BCR_S0_VPP_3V3; break;
167 pr_err("%s(): Vpp 12V not supported in socket\n", __func__);
170 if (state->Vpp != state->Vcc) {
171 pr_err("%s(): bad Vpp %u\n", __func__, state->Vpp);
177 case 0: /* we only have 3.3V */
178 board_pcmcia_power(power);
181 #ifndef CONFIG_MACH_TRIZEPS_CONXS
182 /* on ConXS we only have one slot. Second is inactive */
192 static void trizeps_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
195 board_pcmcia_power(0x9);
198 static void trizeps_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
200 board_pcmcia_power(0x0);
203 static struct pcmcia_low_level trizeps_pcmcia_ops = {
204 .owner = THIS_MODULE,
205 .hw_init = trizeps_pcmcia_hw_init,
206 .hw_shutdown = trizeps_pcmcia_hw_shutdown,
207 .socket_state = trizeps_pcmcia_socket_state,
208 .configure_socket = trizeps_pcmcia_configure_socket,
209 .socket_init = trizeps_pcmcia_socket_init,
210 .socket_suspend = trizeps_pcmcia_socket_suspend,
211 #ifdef CONFIG_MACH_TRIZEPS_CONXS
219 static struct platform_device *trizeps_pcmcia_device;
221 static int __init trizeps_pcmcia_init(void)
225 if (!machine_is_trizeps4() && !machine_is_trizeps4wl())
228 trizeps_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
229 if (!trizeps_pcmcia_device)
232 ret = platform_device_add_data(trizeps_pcmcia_device,
233 &trizeps_pcmcia_ops, sizeof(trizeps_pcmcia_ops));
236 ret = platform_device_add(trizeps_pcmcia_device);
239 platform_device_put(trizeps_pcmcia_device);
244 static void __exit trizeps_pcmcia_exit(void)
246 platform_device_unregister(trizeps_pcmcia_device);
249 fs_initcall(trizeps_pcmcia_init);
250 module_exit(trizeps_pcmcia_exit);
252 MODULE_LICENSE("GPL");
253 MODULE_AUTHOR("Juergen Schindele");
254 MODULE_ALIAS("platform:pxa2xx-pcmcia");