blob: bcff5cfed051b19a8db8dc21669e31c31153a6fe [file] [log] [blame]
Mike Rapoport87944f32007-09-23 16:00:20 +01001/*
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 Rapoport779c5452008-06-17 09:48:03 +01008 * Compulab Ltd., 2003, 2007, 2008
Mike Rapoport87944f32007-09-23 16:00:20 +01009 * Mike Rapoport <mike@compulab.co.il>
10 *
11 */
12
Mike Rapoport87944f32007-09-23 16:00:20 +010013#include <linux/platform_device.h>
14#include <linux/irq.h>
15#include <linux/delay.h>
Mike Rapoport779c5452008-06-17 09:48:03 +010016#include <linux/gpio.h>
Mike Rapoport87944f32007-09-23 16:00:20 +010017
Russell King04ba0f62008-04-24 15:23:25 +010018#include <asm/mach-types.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010019#include <mach/pxa-regs.h>
Mike Rapoport87944f32007-09-23 16:00:20 +010020
21#include "soc_common.h"
22
Mike Rapoport779c5452008-06-17 09:48:03 +010023#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 Rapoport87944f32007-09-23 16:00:20 +010031static struct pcmcia_irqs irqs[] = {
32 { 0, PCMCIA_S0_CD_VALID, "PCMCIA0 CD" },
Mike Rapoport87944f32007-09-23 16:00:20 +010033};
34
35static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
36{
Mike Rapoport779c5452008-06-17 09:48:03 +010037 int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
38 if (ret)
39 return ret;
40 gpio_direction_output(GPIO_PCMCIA_RESET, 0);
Mike Rapoport87944f32007-09-23 16:00:20 +010041
Mike Rapoport779c5452008-06-17 09:48:03 +010042 skt->irq = PCMCIA_S0_RDYINT;
43 ret = soc_pcmcia_request_irqs(skt, irqs, ARRAY_SIZE(irqs));
44 if (!ret)
45 gpio_free(GPIO_PCMCIA_RESET);
Mike Rapoport87944f32007-09-23 16:00:20 +010046
Mike Rapoport779c5452008-06-17 09:48:03 +010047 return ret;
Mike Rapoport87944f32007-09-23 16:00:20 +010048}
49
50static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
51{
52 soc_pcmcia_free_irqs(skt, irqs, ARRAY_SIZE(irqs));
Mike Rapoport779c5452008-06-17 09:48:03 +010053 gpio_free(GPIO_PCMCIA_RESET);
Mike Rapoport87944f32007-09-23 16:00:20 +010054}
55
56
57static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
58 struct pcmcia_state *state)
59{
Mike Rapoport779c5452008-06-17 09:48:03 +010060 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 Rapoport87944f32007-09-23 16:00:20 +010062 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
70static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
71 const socket_state_t *state)
72{
Mike Rapoport87944f32007-09-23 16:00:20 +010073 switch (skt->nr) {
74 case 0:
75 if (state->flags & SS_RESET) {
Mike Rapoport779c5452008-06-17 09:48:03 +010076 gpio_set_value(GPIO_PCMCIA_RESET, 1);
Mike Rapoport87944f32007-09-23 16:00:20 +010077 udelay(10);
Mike Rapoport779c5452008-06-17 09:48:03 +010078 gpio_set_value(GPIO_PCMCIA_RESET, 0);
Mike Rapoport87944f32007-09-23 16:00:20 +010079 }
80 break;
81 }
82
Mike Rapoport87944f32007-09-23 16:00:20 +010083 return 0;
84}
85
86static void cmx270_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
87{
88}
89
90static void cmx270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
91{
92}
93
94
Russell King4e5e8de2008-04-24 15:28:11 +010095static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
Mike Rapoport87944f32007-09-23 16:00:20 +010096 .owner = THIS_MODULE,
97 .hw_init = cmx270_pcmcia_hw_init,
98 .hw_shutdown = cmx270_pcmcia_shutdown,
99 .socket_state = cmx270_pcmcia_socket_state,
100 .configure_socket = cmx270_pcmcia_configure_socket,
101 .socket_init = cmx270_pcmcia_socket_init,
102 .socket_suspend = cmx270_pcmcia_socket_suspend,
Mike Rapoport779c5452008-06-17 09:48:03 +0100103 .nr = 1,
Mike Rapoport87944f32007-09-23 16:00:20 +0100104};
105
106static struct platform_device *cmx270_pcmcia_device;
107
108static int __init cmx270_pcmcia_init(void)
109{
110 int ret;
111
Russell King04ba0f62008-04-24 15:23:25 +0100112 if (!machine_is_armcore())
113 return -ENODEV;
114
Mike Rapoport87944f32007-09-23 16:00:20 +0100115 cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
116
117 if (!cmx270_pcmcia_device)
118 return -ENOMEM;
119
Russell King4e5e8de2008-04-24 15:28:11 +0100120 ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops,
121 sizeof(cmx270_pcmcia_ops));
Mike Rapoport87944f32007-09-23 16:00:20 +0100122
Russell King4e5e8de2008-04-24 15:28:11 +0100123 if (ret == 0) {
124 printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
125 ret = platform_device_add(cmx270_pcmcia_device);
126 }
Mike Rapoport87944f32007-09-23 16:00:20 +0100127
128 if (ret)
129 platform_device_put(cmx270_pcmcia_device);
130
131 return ret;
132}
133
134static void __exit cmx270_pcmcia_exit(void)
135{
136 platform_device_unregister(cmx270_pcmcia_device);
137}
138
139module_init(cmx270_pcmcia_init);
140module_exit(cmx270_pcmcia_exit);
141
142MODULE_LICENSE("GPL");
143MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
144MODULE_DESCRIPTION("CM-x270 PCMCIA driver");