2 * PCMCIA socket code for the MyCable XXS1500 system.
4 * Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com>
8 #include <linux/delay.h>
9 #include <linux/gpio.h>
10 #include <linux/interrupt.h>
12 #include <linux/ioport.h>
14 #include <linux/platform_device.h>
16 #include <linux/resource.h>
17 #include <linux/slab.h>
18 #include <linux/spinlock.h>
20 #include <pcmcia/cs_types.h>
21 #include <pcmcia/cs.h>
22 #include <pcmcia/ss.h>
23 #include <pcmcia/cistpl.h>
26 #include <asm/system.h>
27 #include <asm/mach-au1x00/au1000.h>
29 #define MEM_MAP_SIZE 0x400000
30 #define IO_MAP_SIZE 0x1000
34 * 3.3V cards only; all interfacing is done via gpios:
36 * 0/1: carddetect (00 = card present, xx = huh)
38 * 204: reset (high-act)
39 * 205: buffer enable (low-act)
40 * 208/209: card voltage key (00,01,10,11)
43 * 214: power (low-act)
47 #define GPIO_CARDIRQ 4
48 #define GPIO_RESET 204
49 #define GPIO_OUTEN 205
52 #define GPIO_BATTDEAD 210
53 #define GPIO_BATTWARN 211
54 #define GPIO_POWER 214
56 struct xxs1500_pcmcia_sock {
57 struct pcmcia_socket socket;
61 phys_addr_t phys_attr;
64 /* previous flags for set_socket() */
65 unsigned int old_flags;
68 #define to_xxs_socket(x) container_of(x, struct xxs1500_pcmcia_sock, socket)
70 static irqreturn_t cdirq(int irq, void *data)
72 struct xxs1500_pcmcia_sock *sock = data;
74 pcmcia_parse_events(&sock->socket, SS_DETECT);
79 static int xxs1500_pcmcia_configure(struct pcmcia_socket *skt,
80 struct socket_state_t *state)
82 struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt);
88 gpio_set_value(GPIO_POWER, 1); /* power off */
91 gpio_set_value(GPIO_POWER, 0); /* power on */
98 changed = state->flags ^ sock->old_flags;
100 if (changed & SS_RESET) {
101 if (state->flags & SS_RESET) {
102 gpio_set_value(GPIO_RESET, 1); /* assert reset */
103 gpio_set_value(GPIO_OUTEN, 1); /* buffers off */
105 gpio_set_value(GPIO_RESET, 0); /* deassert reset */
106 gpio_set_value(GPIO_OUTEN, 0); /* buffers on */
111 sock->old_flags = state->flags;
116 static int xxs1500_pcmcia_get_status(struct pcmcia_socket *skt,
124 /* check carddetects: GPIO[0:1] must both be low */
125 if (!gpio_get_value(GPIO_CDA) && !gpio_get_value(GPIO_CDB))
128 /* determine card voltage: GPIO[208:209] binary value */
129 i = (!!gpio_get_value(GPIO_VSL)) | ((!!gpio_get_value(GPIO_VSH)) << 1);
135 status |= SS_3VCARD; /* 3V card */
137 case 3: /* 5V card, unsupported */
139 status |= SS_XVCARD; /* treated as unsupported in core */
142 /* GPIO214: low active power switch */
143 status |= gpio_get_value(GPIO_POWER) ? 0 : SS_POWERON;
145 /* GPIO204: high-active reset line */
146 status |= gpio_get_value(GPIO_RESET) ? SS_RESET : SS_READY;
149 status |= gpio_get_value(GPIO_BATTDEAD) ? 0 : SS_BATDEAD;
150 status |= gpio_get_value(GPIO_BATTWARN) ? 0 : SS_BATWARN;
157 static int xxs1500_pcmcia_sock_init(struct pcmcia_socket *skt)
159 gpio_direction_input(GPIO_CDA);
160 gpio_direction_input(GPIO_CDB);
161 gpio_direction_input(GPIO_VSL);
162 gpio_direction_input(GPIO_VSH);
163 gpio_direction_input(GPIO_BATTDEAD);
164 gpio_direction_input(GPIO_BATTWARN);
165 gpio_direction_output(GPIO_RESET, 1); /* assert reset */
166 gpio_direction_output(GPIO_OUTEN, 1); /* disable buffers */
167 gpio_direction_output(GPIO_POWER, 1); /* power off */
172 static int xxs1500_pcmcia_sock_suspend(struct pcmcia_socket *skt)
177 static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt,
178 struct pccard_io_map *map)
180 struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt);
182 map->start = (u32)sock->virt_io;
183 map->stop = map->start + IO_MAP_SIZE;
188 static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt,
189 struct pccard_mem_map *map)
191 struct xxs1500_pcmcia_sock *sock = to_xxs_socket(skt);
193 if (map->flags & MAP_ATTRIB)
194 map->static_start = sock->phys_attr + map->card_start;
196 map->static_start = sock->phys_mem + map->card_start;
201 static struct pccard_operations xxs1500_pcmcia_operations = {
202 .init = xxs1500_pcmcia_sock_init,
203 .suspend = xxs1500_pcmcia_sock_suspend,
204 .get_status = xxs1500_pcmcia_get_status,
205 .set_socket = xxs1500_pcmcia_configure,
206 .set_io_map = au1x00_pcmcia_set_io_map,
207 .set_mem_map = au1x00_pcmcia_set_mem_map,
210 static int __devinit xxs1500_pcmcia_probe(struct platform_device *pdev)
212 struct xxs1500_pcmcia_sock *sock;
216 sock = kzalloc(sizeof(struct xxs1500_pcmcia_sock), GFP_KERNEL);
222 /* 36bit PCMCIA Attribute area address */
223 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr");
225 dev_err(&pdev->dev, "missing 'pcmcia-attr' resource!\n");
228 sock->phys_attr = r->start;
230 /* 36bit PCMCIA Memory area address */
231 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem");
233 dev_err(&pdev->dev, "missing 'pcmcia-mem' resource!\n");
236 sock->phys_mem = r->start;
238 /* 36bit PCMCIA IO area address */
239 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io");
241 dev_err(&pdev->dev, "missing 'pcmcia-io' resource!\n");
244 sock->phys_io = r->start;
248 * PCMCIA client drivers use the inb/outb macros to access
249 * the IO registers. Since mips_io_port_base is added
250 * to the access address of the mips implementation of
251 * inb/outb, we need to subtract it here because we want
252 * to access the I/O or MEM address directly, without
253 * going through this "mips_io_port_base" mechanism.
255 sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) -
258 if (!sock->virt_io) {
259 dev_err(&pdev->dev, "cannot remap IO area\n");
264 sock->socket.ops = &xxs1500_pcmcia_operations;
265 sock->socket.owner = THIS_MODULE;
266 sock->socket.pci_irq = gpio_to_irq(GPIO_CARDIRQ);
267 sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD;
268 sock->socket.map_size = MEM_MAP_SIZE;
269 sock->socket.io_offset = (unsigned long)sock->virt_io;
270 sock->socket.dev.parent = &pdev->dev;
271 sock->socket.resource_ops = &pccard_static_ops;
273 platform_set_drvdata(pdev, sock);
275 /* setup carddetect irq: use one of the 2 GPIOs as an
278 irq = gpio_to_irq(GPIO_CDA);
279 set_irq_type(irq, IRQ_TYPE_EDGE_BOTH);
280 ret = request_irq(irq, cdirq, 0, "pcmcia_carddetect", sock);
282 dev_err(&pdev->dev, "cannot setup cd irq\n");
286 ret = pcmcia_register_socket(&sock->socket);
288 dev_err(&pdev->dev, "failed to register\n");
292 printk(KERN_INFO "MyCable XXS1500 PCMCIA socket services\n");
297 free_irq(gpio_to_irq(GPIO_CDA), sock);
299 iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
305 static int __devexit xxs1500_pcmcia_remove(struct platform_device *pdev)
307 struct xxs1500_pcmcia_sock *sock = platform_get_drvdata(pdev);
309 pcmcia_unregister_socket(&sock->socket);
310 free_irq(gpio_to_irq(GPIO_CDA), sock);
311 iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
317 static struct platform_driver xxs1500_pcmcia_socket_driver = {
319 .name = "xxs1500_pcmcia",
320 .owner = THIS_MODULE,
322 .probe = xxs1500_pcmcia_probe,
323 .remove = __devexit_p(xxs1500_pcmcia_remove),
326 int __init xxs1500_pcmcia_socket_load(void)
328 return platform_driver_register(&xxs1500_pcmcia_socket_driver);
331 void __exit xxs1500_pcmcia_socket_unload(void)
333 platform_driver_unregister(&xxs1500_pcmcia_socket_driver);
336 module_init(xxs1500_pcmcia_socket_load);
337 module_exit(xxs1500_pcmcia_socket_unload);
339 MODULE_LICENSE("GPL");
340 MODULE_DESCRIPTION("PCMCIA Socket Services for MyCable XXS1500 systems");
341 MODULE_AUTHOR("Manuel Lauss");