blob: f90e7b1a59586e386b7a62c183c972a1cd772165 [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
Mike Rapoport8616e2f2008-10-05 10:27:22 +010019#include "soc_common.h"
20
21#define GPIO_PCMCIA_SKTSEL (54)
22#define GPIO_PCMCIA_S0_CD_VALID (16)
23#define GPIO_PCMCIA_S1_CD_VALID (17)
24#define GPIO_PCMCIA_S0_RDYINT (6)
25#define GPIO_PCMCIA_S1_RDYINT (8)
26#define GPIO_PCMCIA_RESET (9)
27
Mike Rapoport8616e2f2008-10-05 10:27:22 +010028static int cmx255_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
29{
30 int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
31 if (ret)
32 return ret;
33 gpio_direction_output(GPIO_PCMCIA_RESET, 0);
34
Russell Kinga9bb5a42012-01-13 22:56:32 +000035 if (skt->nr == 0) {
36 skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S0_CD_VALID;
37 skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
38 skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S0_RDYINT;
39 skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY";
40 } else {
41 skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S1_CD_VALID;
42 skt->stat[SOC_STAT_CD].name = "PCMCIA1 CD";
43 skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S1_RDYINT;
44 skt->stat[SOC_STAT_RDY].name = "PCMCIA1 RDY";
45 }
Mike Rapoport8616e2f2008-10-05 10:27:22 +010046
Russell Kinga9bb5a42012-01-13 22:56:32 +000047 return 0;
Mike Rapoport8616e2f2008-10-05 10:27:22 +010048}
49
50static void cmx255_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
51{
Mike Rapoport8616e2f2008-10-05 10:27:22 +010052 gpio_free(GPIO_PCMCIA_RESET);
53}
54
55
56static void cmx255_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
57 struct pcmcia_state *state)
58{
Mike Rapoport8616e2f2008-10-05 10:27:22 +010059 state->vs_3v = 0;
60 state->vs_Xv = 0;
61 state->wrprot = 0; /* not available */
62}
63
64
65static int cmx255_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
66 const socket_state_t *state)
67{
68 switch (skt->nr) {
69 case 0:
70 if (state->flags & SS_RESET) {
71 gpio_set_value(GPIO_PCMCIA_SKTSEL, 0);
72 udelay(1);
73 gpio_set_value(GPIO_PCMCIA_RESET, 1);
74 udelay(10);
75 gpio_set_value(GPIO_PCMCIA_RESET, 0);
76 }
77 break;
78 case 1:
79 if (state->flags & SS_RESET) {
80 gpio_set_value(GPIO_PCMCIA_SKTSEL, 1);
81 udelay(1);
82 gpio_set_value(GPIO_PCMCIA_RESET, 1);
83 udelay(10);
84 gpio_set_value(GPIO_PCMCIA_RESET, 0);
85 }
86 break;
87 }
88
89 return 0;
90}
91
Mike Rapoport8616e2f2008-10-05 10:27:22 +010092static struct pcmcia_low_level cmx255_pcmcia_ops __initdata = {
93 .owner = THIS_MODULE,
94 .hw_init = cmx255_pcmcia_hw_init,
95 .hw_shutdown = cmx255_pcmcia_shutdown,
96 .socket_state = cmx255_pcmcia_socket_state,
97 .configure_socket = cmx255_pcmcia_configure_socket,
Mike Rapoport8616e2f2008-10-05 10:27:22 +010098 .nr = 1,
99};
100
101static struct platform_device *cmx255_pcmcia_device;
102
103int __init cmx255_pcmcia_init(void)
104{
105 int ret;
106
107 cmx255_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
108
109 if (!cmx255_pcmcia_device)
110 return -ENOMEM;
111
112 ret = platform_device_add_data(cmx255_pcmcia_device, &cmx255_pcmcia_ops,
113 sizeof(cmx255_pcmcia_ops));
114
115 if (ret == 0) {
116 printk(KERN_INFO "Registering cm-x255 PCMCIA interface.\n");
117 ret = platform_device_add(cmx255_pcmcia_device);
118 }
119
120 if (ret)
121 platform_device_put(cmx255_pcmcia_device);
122
123 return ret;
124}
125
126void __exit cmx255_pcmcia_exit(void)
127{
128 platform_device_unregister(cmx255_pcmcia_device);
129}