1
2
3
4
5
6
7
8
9
10
11#include <linux/gpio/consumer.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/interrupt.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/platform_device.h>
18
19#include <pcmcia/ss.h>
20
21#include <asm/mach-types.h>
22
23#include "soc_common.h"
24#include "max1600.h"
25
26static int mst_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
27{
28 struct device *dev = skt->socket.dev.parent;
29 struct max1600 *m;
30 int ret;
31
32 skt->stat[SOC_STAT_CD].name = skt->nr ? "bdetect" : "adetect";
33 skt->stat[SOC_STAT_BVD1].name = skt->nr ? "bbvd1" : "abvd1";
34 skt->stat[SOC_STAT_BVD2].name = skt->nr ? "bbvd2" : "abvd2";
35 skt->stat[SOC_STAT_RDY].name = skt->nr ? "bready" : "aready";
36 skt->stat[SOC_STAT_VS1].name = skt->nr ? "bvs1" : "avs1";
37 skt->stat[SOC_STAT_VS2].name = skt->nr ? "bvs2" : "avs2";
38
39 skt->gpio_reset = devm_gpiod_get(dev, skt->nr ? "breset" : "areset",
40 GPIOD_OUT_HIGH);
41 if (IS_ERR(skt->gpio_reset))
42 return PTR_ERR(skt->gpio_reset);
43
44 ret = max1600_init(dev, &m, skt->nr ? MAX1600_CHAN_B : MAX1600_CHAN_A,
45 MAX1600_CODE_HIGH);
46 if (ret)
47 return ret;
48
49 skt->driver_data = m;
50
51 return soc_pcmcia_request_gpiods(skt);
52}
53
54static unsigned int mst_pcmcia_bvd1_status[2];
55
56static void mst_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
57 struct pcmcia_state *state)
58{
59 unsigned int flip = mst_pcmcia_bvd1_status[skt->nr] ^ state->bvd1;
60
61
62
63
64
65
66 if (flip) {
67 mst_pcmcia_bvd1_status[skt->nr] = state->bvd1;
68 if (state->bvd1)
69 enable_irq(skt->stat[SOC_STAT_BVD1].irq);
70 else
71 disable_irq(skt->stat[SOC_STAT_BVD2].irq);
72 }
73}
74
75static int mst_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
76 const socket_state_t *state)
77{
78 return max1600_configure(skt->driver_data, state->Vcc, state->Vpp);
79}
80
81static struct pcmcia_low_level mst_pcmcia_ops __initdata = {
82 .owner = THIS_MODULE,
83 .hw_init = mst_pcmcia_hw_init,
84 .socket_state = mst_pcmcia_socket_state,
85 .configure_socket = mst_pcmcia_configure_socket,
86 .nr = 2,
87};
88
89static struct platform_device *mst_pcmcia_device;
90
91static int __init mst_pcmcia_init(void)
92{
93 int ret;
94
95 if (!machine_is_mainstone())
96 return -ENODEV;
97
98 mst_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
99 if (!mst_pcmcia_device)
100 return -ENOMEM;
101
102 ret = platform_device_add_data(mst_pcmcia_device, &mst_pcmcia_ops,
103 sizeof(mst_pcmcia_ops));
104 if (ret == 0)
105 ret = platform_device_add(mst_pcmcia_device);
106
107 if (ret)
108 platform_device_put(mst_pcmcia_device);
109
110 return ret;
111}
112
113static void __exit mst_pcmcia_exit(void)
114{
115 platform_device_unregister(mst_pcmcia_device);
116}
117
118fs_initcall(mst_pcmcia_init);
119module_exit(mst_pcmcia_exit);
120
121MODULE_LICENSE("GPL");
122MODULE_ALIAS("platform:pxa2xx-pcmcia");
123