blob: 24e00a503d088ca5292ceef3017ccfbf7a132675 [file] [log] [blame]
Ian Moltone38a9702008-10-07 22:01:59 +01001/*
2 * Toshiba e740 PCMCIA specific routines.
3 *
4 * (c) 2004 Ian Molton <spyro@f2s.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/init.h>
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/errno.h>
15#include <linux/gpio.h>
16#include <linux/interrupt.h>
17#include <linux/platform_device.h>
18
Ian Moltone38a9702008-10-07 22:01:59 +010019#include <mach/eseries-gpio.h>
20
21#include <asm/irq.h>
22#include <asm/mach-types.h>
23
24#include "soc_common.h"
25
Ian Moltone38a9702008-10-07 22:01:59 +010026static int e740_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
27{
Russell Kinga9bb5a42012-01-13 22:56:32 +000028 if (skt->nr == 0) {
29 skt->stat[SOC_STAT_CD].gpio = GPIO_E740_PCMCIA_CD0;
30 skt->stat[SOC_STAT_CD].name = "CF card detect";
31 skt->stat[SOC_STAT_RDY].gpio = GPIO_E740_PCMCIA_RDY0;
32 skt->stat[SOC_STAT_RDY].name = "CF ready";
33 } else {
34 skt->stat[SOC_STAT_CD].gpio = GPIO_E740_PCMCIA_CD1;
35 skt->stat[SOC_STAT_CD].name = "Wifi switch";
36 skt->stat[SOC_STAT_RDY].gpio = GPIO_E740_PCMCIA_RDY1;
37 skt->stat[SOC_STAT_RDY].name = "Wifi ready";
38 }
Axel Lin34641de2011-12-05 19:06:06 +080039
Russell Kinga9bb5a42012-01-13 22:56:32 +000040 return 0;
Ian Moltone38a9702008-10-07 22:01:59 +010041}
42
43static void e740_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
44 struct pcmcia_state *state)
45{
Ian Moltone38a9702008-10-07 22:01:59 +010046 state->vs_3v = 1;
Ian Moltone38a9702008-10-07 22:01:59 +010047 state->wrprot = 0;
48 state->vs_Xv = 0;
49}
50
51static int e740_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
52 const socket_state_t *state)
53{
54 if (state->flags & SS_RESET) {
55 if (skt->nr == 0)
56 gpio_set_value(GPIO_E740_PCMCIA_RST0, 1);
57 else
58 gpio_set_value(GPIO_E740_PCMCIA_RST1, 1);
59 } else {
60 if (skt->nr == 0)
61 gpio_set_value(GPIO_E740_PCMCIA_RST0, 0);
62 else
63 gpio_set_value(GPIO_E740_PCMCIA_RST1, 0);
64 }
65
66 switch (state->Vcc) {
67 case 0: /* Socket off */
68 if (skt->nr == 0)
69 gpio_set_value(GPIO_E740_PCMCIA_PWR0, 0);
70 else
71 gpio_set_value(GPIO_E740_PCMCIA_PWR1, 1);
72 break;
73 case 50:
74 case 33: /* socket on */
75 if (skt->nr == 0)
76 gpio_set_value(GPIO_E740_PCMCIA_PWR0, 1);
77 else
78 gpio_set_value(GPIO_E740_PCMCIA_PWR1, 0);
79 break;
80 default:
81 printk(KERN_ERR "e740_cs: Unsupported Vcc: %d\n", state->Vcc);
82 }
83
84 return 0;
85}
86
Ian Moltone38a9702008-10-07 22:01:59 +010087static struct pcmcia_low_level e740_pcmcia_ops = {
88 .owner = THIS_MODULE,
89 .hw_init = e740_pcmcia_hw_init,
Ian Moltone38a9702008-10-07 22:01:59 +010090 .socket_state = e740_pcmcia_socket_state,
91 .configure_socket = e740_pcmcia_configure_socket,
Ian Moltone38a9702008-10-07 22:01:59 +010092 .nr = 2,
93};
94
95static struct platform_device *e740_pcmcia_device;
96
97static int __init e740_pcmcia_init(void)
98{
99 int ret;
100
101 if (!machine_is_e740())
102 return -ENODEV;
103
104 e740_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
105 if (!e740_pcmcia_device)
106 return -ENOMEM;
107
108 ret = platform_device_add_data(e740_pcmcia_device, &e740_pcmcia_ops,
109 sizeof(e740_pcmcia_ops));
110
111 if (!ret)
112 ret = platform_device_add(e740_pcmcia_device);
113
114 if (ret)
115 platform_device_put(e740_pcmcia_device);
116
117 return ret;
118}
119
120static void __exit e740_pcmcia_exit(void)
121{
122 platform_device_unregister(e740_pcmcia_device);
123}
124
125module_init(e740_pcmcia_init);
126module_exit(e740_pcmcia_exit);
127
128MODULE_LICENSE("GPL v2");
129MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
130MODULE_ALIAS("platform:pxa2xx-pcmcia");
131MODULE_DESCRIPTION("e740 PCMCIA platform support");