blob: 36e35da5f887be50c2edb5650719dbb712999278 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Mike Rapoport87944f32007-09-23 16:00:20 +01002/*
3 * linux/drivers/pcmcia/pxa/pxa_cm_x270.c
4 *
Mike Rapoport779c5452008-06-17 09:48:03 +01005 * Compulab Ltd., 2003, 2007, 2008
Mike Rapoport87944f32007-09-23 16:00:20 +01006 * Mike Rapoport <mike@compulab.co.il>
Mike Rapoport87944f32007-09-23 16:00:20 +01007 */
8
Mike Rapoport87944f32007-09-23 16:00:20 +01009#include <linux/platform_device.h>
10#include <linux/irq.h>
11#include <linux/delay.h>
Mike Rapoport779c5452008-06-17 09:48:03 +010012#include <linux/gpio.h>
Paul Gortmaker402b20d2011-07-31 16:21:42 -040013#include <linux/export.h>
Mike Rapoport87944f32007-09-23 16:00:20 +010014
Mike Rapoport87944f32007-09-23 16:00:20 +010015#include "soc_common.h"
16
Mike Rapoport779c5452008-06-17 09:48:03 +010017#define GPIO_PCMCIA_S0_CD_VALID (84)
18#define GPIO_PCMCIA_S0_RDYINT (82)
19#define GPIO_PCMCIA_RESET (53)
20
Mike Rapoport87944f32007-09-23 16:00:20 +010021static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
22{
Mike Rapoport779c5452008-06-17 09:48:03 +010023 int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset");
24 if (ret)
25 return ret;
26 gpio_direction_output(GPIO_PCMCIA_RESET, 0);
Mike Rapoport87944f32007-09-23 16:00:20 +010027
Russell Kinga9bb5a42012-01-13 22:56:32 +000028 skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S0_CD_VALID;
29 skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
30 skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S0_RDYINT;
31 skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY";
Mike Rapoport87944f32007-09-23 16:00:20 +010032
Mike Rapoport779c5452008-06-17 09:48:03 +010033 return ret;
Mike Rapoport87944f32007-09-23 16:00:20 +010034}
35
36static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt)
37{
Mike Rapoport779c5452008-06-17 09:48:03 +010038 gpio_free(GPIO_PCMCIA_RESET);
Mike Rapoport87944f32007-09-23 16:00:20 +010039}
40
41
42static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
43 struct pcmcia_state *state)
44{
Mike Rapoport87944f32007-09-23 16:00:20 +010045 state->vs_3v = 0;
46 state->vs_Xv = 0;
Mike Rapoport87944f32007-09-23 16:00:20 +010047}
48
49
50static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
51 const socket_state_t *state)
52{
Mike Rapoport87944f32007-09-23 16:00:20 +010053 switch (skt->nr) {
54 case 0:
55 if (state->flags & SS_RESET) {
Mike Rapoport779c5452008-06-17 09:48:03 +010056 gpio_set_value(GPIO_PCMCIA_RESET, 1);
Mike Rapoport87944f32007-09-23 16:00:20 +010057 udelay(10);
Mike Rapoport779c5452008-06-17 09:48:03 +010058 gpio_set_value(GPIO_PCMCIA_RESET, 0);
Mike Rapoport87944f32007-09-23 16:00:20 +010059 }
60 break;
61 }
62
Mike Rapoport87944f32007-09-23 16:00:20 +010063 return 0;
64}
65
Russell King4e5e8de2008-04-24 15:28:11 +010066static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = {
Mike Rapoport87944f32007-09-23 16:00:20 +010067 .owner = THIS_MODULE,
68 .hw_init = cmx270_pcmcia_hw_init,
69 .hw_shutdown = cmx270_pcmcia_shutdown,
70 .socket_state = cmx270_pcmcia_socket_state,
71 .configure_socket = cmx270_pcmcia_configure_socket,
Mike Rapoport779c5452008-06-17 09:48:03 +010072 .nr = 1,
Mike Rapoport87944f32007-09-23 16:00:20 +010073};
74
75static struct platform_device *cmx270_pcmcia_device;
76
Mike Rapoport8616e2f2008-10-05 10:27:22 +010077int __init cmx270_pcmcia_init(void)
Mike Rapoport87944f32007-09-23 16:00:20 +010078{
79 int ret;
80
Mike Rapoport87944f32007-09-23 16:00:20 +010081 cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
82
83 if (!cmx270_pcmcia_device)
84 return -ENOMEM;
85
Russell King4e5e8de2008-04-24 15:28:11 +010086 ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops,
87 sizeof(cmx270_pcmcia_ops));
Mike Rapoport87944f32007-09-23 16:00:20 +010088
Russell King4e5e8de2008-04-24 15:28:11 +010089 if (ret == 0) {
90 printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n");
91 ret = platform_device_add(cmx270_pcmcia_device);
92 }
Mike Rapoport87944f32007-09-23 16:00:20 +010093
94 if (ret)
95 platform_device_put(cmx270_pcmcia_device);
96
97 return ret;
98}
99
Mike Rapoport8616e2f2008-10-05 10:27:22 +0100100void __exit cmx270_pcmcia_exit(void)
Mike Rapoport87944f32007-09-23 16:00:20 +0100101{
102 platform_device_unregister(cmx270_pcmcia_device);
103}