blob: f59223f2307d0878bca779465f9c1ce56ffaf2f7 [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>
Paul Gortmaker402b20d2011-07-31 16:21:42 -040017#include <linux/export.h>
Mike Rapoport87944f32007-09-23 16:00:20 +010018
Mike Rapoport87944f32007-09-23 16:00:20 +010019#include "soc_common.h"
20
Mike Rapoport779c5452008-06-17 09:48:03 +010021#define GPIO_PCMCIA_S0_CD_VALID (84)
22#define GPIO_PCMCIA_S0_RDYINT (82)
23#define GPIO_PCMCIA_RESET (53)
24
Mike Rapoport87944f32007-09-23 16:00:20 +010025static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
26{
Mike Rapoport779c5452008-06-17 09:48:03 +010027 int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
28 if (ret)
29 return ret;
30 gpio_direction_output(GPIO_PCMCIA_RESET, 0);
Mike Rapoport87944f32007-09-23 16:00:20 +010031
Russell Kinga9bb5a42012-01-13 22:56:32 +000032 skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S0_CD_VALID;
33 skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
34 skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S0_RDYINT;
35 skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY";
Mike Rapoport87944f32007-09-23 16:00:20 +010036
Mike Rapoport779c5452008-06-17 09:48:03 +010037 return ret;
Mike Rapoport87944f32007-09-23 16:00:20 +010038}
39
40static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
41{
Mike Rapoport779c5452008-06-17 09:48:03 +010042 gpio_free(GPIO_PCMCIA_RESET);
Mike Rapoport87944f32007-09-23 16:00:20 +010043}
44
45
46static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
47 struct pcmcia_state *state)
48{
Mike Rapoport87944f32007-09-23 16:00:20 +010049 state->vs_3v = 0;
50 state->vs_Xv = 0;
Mike Rapoport87944f32007-09-23 16:00:20 +010051}
52
53
54static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
55 const socket_state_t *state)
56{
Mike Rapoport87944f32007-09-23 16:00:20 +010057 switch (skt->nr) {
58 case 0:
59 if (state->flags & SS_RESET) {
Mike Rapoport779c5452008-06-17 09:48:03 +010060 gpio_set_value(GPIO_PCMCIA_RESET, 1);
Mike Rapoport87944f32007-09-23 16:00:20 +010061 udelay(10);
Mike Rapoport779c5452008-06-17 09:48:03 +010062 gpio_set_value(GPIO_PCMCIA_RESET, 0);
Mike Rapoport87944f32007-09-23 16:00:20 +010063 }
64 break;
65 }
66
Mike Rapoport87944f32007-09-23 16:00:20 +010067 return 0;
68}
69
Russell King4e5e8de2008-04-24 15:28:11 +010070static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
Mike Rapoport87944f32007-09-23 16:00:20 +010071 .owner = THIS_MODULE,
72 .hw_init = cmx270_pcmcia_hw_init,
73 .hw_shutdown = cmx270_pcmcia_shutdown,
74 .socket_state = cmx270_pcmcia_socket_state,
75 .configure_socket = cmx270_pcmcia_configure_socket,
Mike Rapoport779c5452008-06-17 09:48:03 +010076 .nr = 1,
Mike Rapoport87944f32007-09-23 16:00:20 +010077};
78
79static struct platform_device *cmx270_pcmcia_device;
80
Mike Rapoport8616e2f2008-10-05 10:27:22 +010081int __init cmx270_pcmcia_init(void)
Mike Rapoport87944f32007-09-23 16:00:20 +010082{
83 int ret;
84
Mike Rapoport87944f32007-09-23 16:00:20 +010085 cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
86
87 if (!cmx270_pcmcia_device)
88 return -ENOMEM;
89
Russell King4e5e8de2008-04-24 15:28:11 +010090 ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops,
91 sizeof(cmx270_pcmcia_ops));
Mike Rapoport87944f32007-09-23 16:00:20 +010092
Russell King4e5e8de2008-04-24 15:28:11 +010093 if (ret == 0) {
94 printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
95 ret = platform_device_add(cmx270_pcmcia_device);
96 }
Mike Rapoport87944f32007-09-23 16:00:20 +010097
98 if (ret)
99 platform_device_put(cmx270_pcmcia_device);
100
101 return ret;
102}
103
Mike Rapoport8616e2f2008-10-05 10:27:22 +0100104void __exit cmx270_pcmcia_exit(void)
Mike Rapoport87944f32007-09-23 16:00:20 +0100105{
106 platform_device_unregister(cmx270_pcmcia_device);
107}