New Broadcom BCM63xx codebase, huge thanks to Maxime ;)
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / patches-2.6.27 / 006-pcmcia_cardbus_support.patch
1 From b17597be763621ba63534fda6e1ea0a802be2087 Mon Sep 17 00:00:00 2001
2 From: Maxime Bizon <mbizon@freebox.fr>
3 Date: Fri, 18 Jul 2008 21:18:51 +0200
4 Subject: [PATCH] [MIPS] BCM63XX: Add PCMCIA & Cardbus support.
5
6 Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
7 ---
8 arch/mips/bcm63xx/Makefile | 1 +
9 arch/mips/bcm63xx/dev-pcmcia.c | 135 +++++
10 drivers/pcmcia/Kconfig | 4 +
11 drivers/pcmcia/Makefile | 1 +
12 drivers/pcmcia/bcm63xx_pcmcia.c | 521 ++++++++++++++++++++
13 drivers/pcmcia/bcm63xx_pcmcia.h | 65 +++
14 include/asm-mips/mach-bcm63xx/bcm63xx_dev_pcmcia.h | 13 +
15 7 files changed, 740 insertions(+), 0 deletions(-)
16 create mode 100644 arch/mips/bcm63xx/dev-pcmcia.c
17 create mode 100644 drivers/pcmcia/bcm63xx_pcmcia.c
18 create mode 100644 drivers/pcmcia/bcm63xx_pcmcia.h
19 create mode 100644 include/asm-mips/mach-bcm63xx/bcm63xx_dev_pcmcia.h
20
21 diff --git a/arch/mips/bcm63xx/Makefile b/arch/mips/bcm63xx/Makefile
22 index 8f3299e..456e915 100644
23 --- a/arch/mips/bcm63xx/Makefile
24 +++ b/arch/mips/bcm63xx/Makefile
25 @@ -1,3 +1,4 @@
26 obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o
27 obj-y += dev-uart.o
28 +obj-y += dev-pcmcia.o
29 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
30 diff --git a/arch/mips/bcm63xx/dev-pcmcia.c b/arch/mips/bcm63xx/dev-pcmcia.c
31 new file mode 100644
32 index 0000000..40ec4bc
33 --- /dev/null
34 +++ b/arch/mips/bcm63xx/dev-pcmcia.c
35 @@ -0,0 +1,135 @@
36 +/*
37 + * This file is subject to the terms and conditions of the GNU General Public
38 + * License. See the file "COPYING" in the main directory of this archive
39 + * for more details.
40 + *
41 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
42 + */
43 +
44 +#include <linux/init.h>
45 +#include <linux/kernel.h>
46 +#include <asm/bootinfo.h>
47 +#include <linux/platform_device.h>
48 +#include <bcm63xx_cs.h>
49 +#include <bcm63xx_cpu.h>
50 +#include <bcm63xx_dev_pcmcia.h>
51 +#include <bcm63xx_io.h>
52 +#include <bcm63xx_regs.h>
53 +
54 +static struct resource pcmcia_resources[] = {
55 + /* pcmcia registers */
56 + {
57 + .start = -1, /* filled at runtime */
58 + .end = -1, /* filled at runtime */
59 + .flags = IORESOURCE_MEM,
60 + },
61 +
62 + /* pcmcia memory zone resources */
63 + {
64 + .start = BCM_PCMCIA_COMMON_BASE_PA,
65 + .end = BCM_PCMCIA_COMMON_END_PA,
66 + .flags = IORESOURCE_MEM,
67 + },
68 + {
69 + .start = BCM_PCMCIA_ATTR_BASE_PA,
70 + .end = BCM_PCMCIA_ATTR_END_PA,
71 + .flags = IORESOURCE_MEM,
72 + },
73 + {
74 + .start = BCM_PCMCIA_IO_BASE_PA,
75 + .end = BCM_PCMCIA_IO_END_PA,
76 + .flags = IORESOURCE_MEM,
77 + },
78 +
79 + /* PCMCIA irq */
80 + {
81 + .start = -1, /* filled at runtime */
82 + .flags = IORESOURCE_IRQ,
83 + },
84 +
85 + /* declare PCMCIA IO resource also */
86 + {
87 + .start = BCM_PCMCIA_IO_BASE_PA,
88 + .end = BCM_PCMCIA_IO_END_PA,
89 + .flags = IORESOURCE_IO,
90 + },
91 +};
92 +
93 +static struct bcm63xx_pcmcia_platform_data pd;
94 +
95 +static struct platform_device bcm63xx_pcmcia_device = {
96 + .name = "bcm63xx_pcmcia",
97 + .id = 0,
98 + .num_resources = ARRAY_SIZE(pcmcia_resources),
99 + .resource = pcmcia_resources,
100 + .dev = {
101 + .platform_data = &pd,
102 + },
103 +};
104 +
105 +static int __init config_pcmcia_cs(unsigned int cs,
106 + u32 base, unsigned int size)
107 +{
108 + int ret;
109 +
110 + ret = bcm63xx_set_cs_status(cs, 0);
111 + if (!ret)
112 + ret = bcm63xx_set_cs_base(cs, base, size);
113 + if (!ret)
114 + ret = bcm63xx_set_cs_status(cs, 1);
115 + return ret;
116 +}
117 +
118 +static const __initdata unsigned int pcmcia_cs[3][3] = {
119 + /* cs, base address, size */
120 + { MPI_CS_PCMCIA_COMMON, BCM_PCMCIA_COMMON_BASE_PA,
121 + BCM_PCMCIA_COMMON_SIZE },
122 +
123 + { MPI_CS_PCMCIA_ATTR, BCM_PCMCIA_ATTR_BASE_PA,
124 + BCM_PCMCIA_ATTR_SIZE },
125 +
126 + { MPI_CS_PCMCIA_IO, BCM_PCMCIA_IO_BASE_PA,
127 + BCM_PCMCIA_IO_SIZE },
128 +};
129 +
130 +int __init bcm63xx_pcmcia_register(void)
131 +{
132 + int ret, i;
133 +
134 + if (!BCMCPU_IS_6348() && !BCMCPU_IS_6358())
135 + return 0;
136 +
137 + /* use correct pcmcia ready gpio depending on processor */
138 + switch (bcm63xx_get_cpu_id()) {
139 + case BCM6348_CPU_ID:
140 + pd.ready_gpio = 22;
141 + break;
142 +
143 + case BCM6358_CPU_ID:
144 + pd.ready_gpio = 22;
145 + break;
146 +
147 + default:
148 + return -ENODEV;
149 + }
150 +
151 + pcmcia_resources[0].start = bcm63xx_regset_address(RSET_PCMCIA);
152 + pcmcia_resources[0].end = pcmcia_resources[0].start;
153 + pcmcia_resources[0].end += RSET_PCMCIA_SIZE - 1;
154 + pcmcia_resources[4].start = bcm63xx_get_irq_number(IRQ_PCMCIA);
155 +
156 + /* configure pcmcia chip selects */
157 + for (i = 0; i < 3; i++) {
158 + ret = config_pcmcia_cs(pcmcia_cs[i][0],
159 + pcmcia_cs[i][1],
160 + pcmcia_cs[i][2]);
161 + if (ret)
162 + goto out_err;
163 + }
164 +
165 + return platform_device_register(&bcm63xx_pcmcia_device);
166 +
167 +out_err:
168 + printk(KERN_ERR "unable to set pcmcia chip select");
169 + return ret;
170 +}
171 diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
172 index e0f8840..5c640ca 100644
173 --- a/drivers/pcmcia/Kconfig
174 +++ b/drivers/pcmcia/Kconfig
175 @@ -196,6 +196,10 @@ config PCMCIA_AU1X00
176 tristate "Au1x00 pcmcia support"
177 depends on SOC_AU1X00 && PCMCIA
178
179 +config PCMCIA_BCM63XX
180 + tristate "bcm63xx pcmcia support"
181 + depends on BCM63XX && PCMCIA
182 +
183 config PCMCIA_SA1100
184 tristate "SA1100 support"
185 depends on ARM && ARCH_SA1100 && PCMCIA
186 diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
187 index 269a9e9..32b19b5 100644
188 --- a/drivers/pcmcia/Makefile
189 +++ b/drivers/pcmcia/Makefile
190 @@ -33,6 +33,7 @@ obj-$(CONFIG_PCMCIA_PXA2XX) += pxa2xx_core.o pxa2xx_cs.o
191 obj-$(CONFIG_M32R_PCC) += m32r_pcc.o
192 obj-$(CONFIG_M32R_CFC) += m32r_cfc.o
193 obj-$(CONFIG_PCMCIA_AU1X00) += au1x00_ss.o
194 +obj-$(CONFIG_PCMCIA_BCM63XX) += bcm63xx_pcmcia.o
195 obj-$(CONFIG_PCMCIA_VRC4171) += vrc4171_card.o
196 obj-$(CONFIG_PCMCIA_VRC4173) += vrc4173_cardu.o
197 obj-$(CONFIG_OMAP_CF) += omap_cf.o
198 diff --git a/drivers/pcmcia/bcm63xx_pcmcia.c b/drivers/pcmcia/bcm63xx_pcmcia.c
199 new file mode 100644
200 index 0000000..3a0b7fc
201 --- /dev/null
202 +++ b/drivers/pcmcia/bcm63xx_pcmcia.c
203 @@ -0,0 +1,521 @@
204 +/*
205 + * This file is subject to the terms and conditions of the GNU General Public
206 + * License. See the file "COPYING" in the main directory of this archive
207 + * for more details.
208 + *
209 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
210 + */
211 +
212 +#include <linux/kernel.h>
213 +#include <linux/module.h>
214 +#include <linux/ioport.h>
215 +#include <linux/timer.h>
216 +#include <linux/platform_device.h>
217 +#include <linux/delay.h>
218 +#include <linux/pci.h>
219 +#include <linux/gpio.h>
220 +
221 +#include <bcm63xx_regs.h>
222 +#include <bcm63xx_io.h>
223 +#include "bcm63xx_pcmcia.h"
224 +
225 +#define PFX "bcm63xx_pcmcia: "
226 +
227 +#ifdef CONFIG_CARDBUS
228 +/* if cardbus is used, platform device needs reference to actual pci
229 + * device */
230 +static struct pci_dev *bcm63xx_cb_dev;
231 +#endif
232 +
233 +/*
234 + * read/write helper for pcmcia regs
235 + */
236 +static inline u32 pcmcia_readl(struct bcm63xx_pcmcia_socket *skt, u32 off)
237 +{
238 + return bcm_readl(skt->base + off);
239 +}
240 +
241 +static inline void pcmcia_writel(struct bcm63xx_pcmcia_socket *skt,
242 + u32 val, u32 off)
243 +{
244 + bcm_writel(val, skt->base + off);
245 +}
246 +
247 +/*
248 + * (Re-)Initialise the socket, turning on status interrupts and PCMCIA
249 + * bus. This must wait for power to stabilise so that the card status
250 + * signals report correctly.
251 + */
252 +static int bcm63xx_pcmcia_sock_init(struct pcmcia_socket *sock)
253 +{
254 + struct bcm63xx_pcmcia_socket *skt;
255 + skt = sock->driver_data;
256 + return 0;
257 +}
258 +
259 +/*
260 + * Remove power on the socket, disable IRQs from the card.
261 + * Turn off status interrupts, and disable the PCMCIA bus.
262 + */
263 +static int bcm63xx_pcmcia_suspend(struct pcmcia_socket *sock)
264 +{
265 + struct bcm63xx_pcmcia_socket *skt;
266 + skt = sock->driver_data;
267 + return 0;
268 +}
269 +
270 +/*
271 + * Implements the set_socket() operation for the in-kernel PCMCIA
272 + * service (formerly SS_SetSocket in Card Services). We more or
273 + * less punt all of this work and let the kernel handle the details
274 + * of power configuration, reset, &c. We also record the value of
275 + * `state' in order to regurgitate it to the PCMCIA core later.
276 + */
277 +static int bcm63xx_pcmcia_set_socket(struct pcmcia_socket *sock,
278 + socket_state_t *state)
279 +{
280 + struct bcm63xx_pcmcia_socket *skt;
281 + unsigned long flags;
282 + u32 val;
283 +
284 + skt = sock->driver_data;
285 +
286 + spin_lock_irqsave(&skt->lock, flags);
287 +
288 + /* apply requested socket power */
289 + /* FIXME: hardware can't do this */
290 +
291 + /* apply socket reset */
292 + val = pcmcia_readl(skt, PCMCIA_C1_REG);
293 + if (state->flags & SS_RESET)
294 + val |= PCMCIA_C1_RESET_MASK;
295 + else
296 + val &= ~PCMCIA_C1_RESET_MASK;
297 +
298 + /* reverse reset logic for cardbus card */
299 + if (skt->card_detected && (skt->card_type & CARD_CARDBUS))
300 + val ^= PCMCIA_C1_RESET_MASK;
301 +
302 + pcmcia_writel(skt, val, PCMCIA_C1_REG);
303 +
304 + /* keep requested state for event reporting */
305 + skt->requested_state = *state;
306 +
307 + spin_unlock_irqrestore(&skt->lock, flags);
308 +
309 + return 0;
310 +}
311 +
312 +/*
313 + * identity cardtype from VS[12] input, CD[12] input while only VS2 is
314 + * floating, and CD[12] input while only VS1 is floating
315 + */
316 +enum {
317 + IN_VS1 = (1 << 0),
318 + IN_VS2 = (1 << 1),
319 + IN_CD1_VS2H = (1 << 2),
320 + IN_CD2_VS2H = (1 << 3),
321 + IN_CD1_VS1H = (1 << 4),
322 + IN_CD2_VS1H = (1 << 5),
323 +};
324 +
325 +static const u8 vscd_to_cardtype[] = {
326 +
327 + /* VS1 float, VS2 float */
328 + [IN_VS1 | IN_VS2] = (CARD_PCCARD | CARD_5V),
329 +
330 + /* VS1 grounded, VS2 float */
331 + [IN_VS2] = (CARD_PCCARD | CARD_5V | CARD_3V),
332 +
333 + /* VS1 grounded, VS2 grounded */
334 + [0] = (CARD_PCCARD | CARD_5V | CARD_3V | CARD_XV),
335 +
336 + /* VS1 tied to CD1, VS2 float */
337 + [IN_VS1 | IN_VS2 | IN_CD1_VS1H] = (CARD_CARDBUS | CARD_3V),
338 +
339 + /* VS1 grounded, VS2 tied to CD2 */
340 + [IN_VS2 | IN_CD2_VS2H] = (CARD_CARDBUS | CARD_3V | CARD_XV),
341 +
342 + /* VS1 tied to CD2, VS2 grounded */
343 + [IN_VS1 | IN_CD2_VS1H] = (CARD_CARDBUS | CARD_3V | CARD_XV | CARD_YV),
344 +
345 + /* VS1 float, VS2 grounded */
346 + [IN_VS1] = (CARD_PCCARD | CARD_XV),
347 +
348 + /* VS1 float, VS2 tied to CD2 */
349 + [IN_VS1 | IN_VS2 | IN_CD2_VS2H] = (CARD_CARDBUS | CARD_3V),
350 +
351 + /* VS1 float, VS2 tied to CD1 */
352 + [IN_VS1 | IN_VS2 | IN_CD1_VS2H] = (CARD_CARDBUS | CARD_XV | CARD_YV),
353 +
354 + /* VS1 tied to CD2, VS2 float */
355 + [IN_VS1 | IN_VS2 | IN_CD2_VS1H] = (CARD_CARDBUS | CARD_YV),
356 +
357 + /* VS2 grounded, VS1 is tied to CD1, CD2 is grounded */
358 + [IN_VS1 | IN_CD1_VS1H] = 0, /* ignore cardbay */
359 +};
360 +
361 +/*
362 + * poll hardware to check card insertion status
363 + */
364 +static unsigned int __get_socket_status(struct bcm63xx_pcmcia_socket *skt)
365 +{
366 + unsigned int stat;
367 + u32 val;
368 +
369 + stat = 0;
370 +
371 + /* check CD for card presence */
372 + val = pcmcia_readl(skt, PCMCIA_C1_REG);
373 +
374 + if (!(val & PCMCIA_C1_CD1_MASK) && !(val & PCMCIA_C1_CD2_MASK))
375 + stat |= SS_DETECT;
376 +
377 + /* if new insertion, detect cardtype */
378 + if ((stat & SS_DETECT) && !skt->card_detected) {
379 + unsigned int stat = 0;
380 +
381 + /* float VS1, float VS2 */
382 + val |= PCMCIA_C1_VS1OE_MASK;
383 + val |= PCMCIA_C1_VS2OE_MASK;
384 + pcmcia_writel(skt, val, PCMCIA_C1_REG);
385 +
386 + /* wait for output to stabilize and read VS[12] */
387 + udelay(10);
388 + val = pcmcia_readl(skt, PCMCIA_C1_REG);
389 + stat |= (val & PCMCIA_C1_VS1_MASK) ? IN_VS1 : 0;
390 + stat |= (val & PCMCIA_C1_VS2_MASK) ? IN_VS2 : 0;
391 +
392 + /* drive VS1 low, float VS2 */
393 + val &= ~PCMCIA_C1_VS1OE_MASK;
394 + val |= PCMCIA_C1_VS2OE_MASK;
395 + pcmcia_writel(skt, val, PCMCIA_C1_REG);
396 +
397 + /* wait for output to stabilize and read CD[12] */
398 + udelay(10);
399 + val = pcmcia_readl(skt, PCMCIA_C1_REG);
400 + stat |= (val & PCMCIA_C1_CD1_MASK) ? IN_CD1_VS2H : 0;
401 + stat |= (val & PCMCIA_C1_CD2_MASK) ? IN_CD2_VS2H : 0;
402 +
403 + /* float VS1, drive VS2 low */
404 + val |= PCMCIA_C1_VS1OE_MASK;
405 + val &= ~PCMCIA_C1_VS2OE_MASK;
406 + pcmcia_writel(skt, val, PCMCIA_C1_REG);
407 +
408 + /* wait for output to stabilize and read CD[12] */
409 + udelay(10);
410 + val = pcmcia_readl(skt, PCMCIA_C1_REG);
411 + stat |= (val & PCMCIA_C1_CD1_MASK) ? IN_CD1_VS1H : 0;
412 + stat |= (val & PCMCIA_C1_CD2_MASK) ? IN_CD2_VS1H : 0;
413 +
414 + /* guess cardtype from all this */
415 + skt->card_type = vscd_to_cardtype[stat];
416 + if (!skt->card_type)
417 + printk(KERN_ERR PFX "unsupported card type\n");
418 +
419 + /* drive both VS pin to 0 again */
420 + val &= ~(PCMCIA_C1_VS1OE_MASK | PCMCIA_C1_VS2OE_MASK);
421 +
422 + /* enable correct logic */
423 + val &= ~(PCMCIA_C1_EN_PCMCIA_MASK | PCMCIA_C1_EN_CARDBUS_MASK);
424 + if (skt->card_type & CARD_PCCARD)
425 + val |= PCMCIA_C1_EN_PCMCIA_MASK;
426 + else
427 + val |= PCMCIA_C1_EN_CARDBUS_MASK;
428 +
429 + pcmcia_writel(skt, val, PCMCIA_C1_REG);
430 + }
431 + skt->card_detected = (stat & SS_DETECT) ? 1 : 0;
432 +
433 + /* report card type/voltage */
434 + if (skt->card_type & CARD_CARDBUS)
435 + stat |= SS_CARDBUS;
436 + if (skt->card_type & CARD_3V)
437 + stat |= SS_3VCARD;
438 + if (skt->card_type & CARD_XV)
439 + stat |= SS_XVCARD;
440 + stat |= SS_POWERON;
441 +
442 + if (gpio_get_value(skt->pd->ready_gpio))
443 + stat |= SS_READY;
444 +
445 + return stat;
446 +}
447 +
448 +/*
449 + * core request to get current socket status
450 + */
451 +static int bcm63xx_pcmcia_get_status(struct pcmcia_socket *sock,
452 + unsigned int *status)
453 +{
454 + struct bcm63xx_pcmcia_socket *skt;
455 +
456 + skt = sock->driver_data;
457 +
458 + spin_lock_bh(&skt->lock);
459 + *status = __get_socket_status(skt);
460 + spin_unlock_bh(&skt->lock);
461 +
462 + return 0;
463 +}
464 +
465 +/*
466 + * socket polling timer callback
467 + */
468 +static void bcm63xx_pcmcia_poll(unsigned long data)
469 +{
470 + struct bcm63xx_pcmcia_socket *skt;
471 + unsigned int stat, events;
472 +
473 + skt = (struct bcm63xx_pcmcia_socket *)data;
474 +
475 + spin_lock_bh(&skt->lock);
476 +
477 + stat = __get_socket_status(skt);
478 +
479 + /* keep only changed bits, and mask with required one from the
480 + * core */
481 + events = (stat ^ skt->old_status) & skt->requested_state.csc_mask;
482 + skt->old_status = stat;
483 + spin_unlock_bh(&skt->lock);
484 +
485 + if (events)
486 + pcmcia_parse_events(&skt->socket, events);
487 +
488 + mod_timer(&skt->timer,
489 + jiffies + msecs_to_jiffies(BCM63XX_PCMCIA_POLL_RATE));
490 +}
491 +
492 +static int bcm63xx_pcmcia_set_io_map(struct pcmcia_socket *sock,
493 + struct pccard_io_map *map)
494 +{
495 + /* this doesn't seem to be called by pcmcia layer if static
496 + * mapping is used */
497 + return 0;
498 +}
499 +
500 +static int bcm63xx_pcmcia_set_mem_map(struct pcmcia_socket *sock,
501 + struct pccard_mem_map *map)
502 +{
503 + struct bcm63xx_pcmcia_socket *skt;
504 + struct resource *res;
505 +
506 + skt = sock->driver_data;
507 + if (map->flags & MAP_ATTRIB)
508 + res = skt->attr_res;
509 + else
510 + res = skt->common_res;
511 +
512 + map->static_start = res->start + map->card_start;
513 + return 0;
514 +}
515 +
516 +static struct pccard_operations bcm63xx_pcmcia_operations = {
517 + .init = bcm63xx_pcmcia_sock_init,
518 + .suspend = bcm63xx_pcmcia_suspend,
519 + .get_status = bcm63xx_pcmcia_get_status,
520 + .set_socket = bcm63xx_pcmcia_set_socket,
521 + .set_io_map = bcm63xx_pcmcia_set_io_map,
522 + .set_mem_map = bcm63xx_pcmcia_set_mem_map,
523 +};
524 +
525 +/*
526 + * register pcmcia socket to core
527 + */
528 +static int bcm63xx_drv_pcmcia_probe(struct platform_device *pdev)
529 +{
530 + struct bcm63xx_pcmcia_socket *skt;
531 + struct pcmcia_socket *sock;
532 + struct resource *res, *irq_res;
533 + unsigned int regmem_size = 0, iomem_size = 0;
534 + u32 val;
535 + int ret;
536 +
537 + skt = kzalloc(sizeof(*skt), GFP_KERNEL);
538 + if (!skt)
539 + return -ENOMEM;
540 + spin_lock_init(&skt->lock);
541 + sock = &skt->socket;
542 + sock->driver_data = skt;
543 +
544 + /* make sure we have all resources we need */
545 + skt->common_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
546 + skt->attr_res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
547 + irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
548 + skt->pd = pdev->dev.platform_data;
549 + if (!skt->common_res || !skt->attr_res || !irq_res || !skt->pd) {
550 + ret = -EINVAL;
551 + goto err;
552 + }
553 +
554 + /* remap pcmcia registers */
555 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
556 + regmem_size = res->end - res->start + 1;
557 + if (!request_mem_region(res->start, regmem_size, "bcm63xx_pcmcia")) {
558 + ret = -EINVAL;
559 + goto err;
560 + }
561 + skt->reg_res = res;
562 +
563 + skt->base = ioremap(res->start, regmem_size);
564 + if (!skt->base) {
565 + ret = -ENOMEM;
566 + goto err;
567 + }
568 +
569 + /* remap io registers */
570 + res = platform_get_resource(pdev, IORESOURCE_MEM, 3);
571 + iomem_size = res->end - res->start + 1;
572 + skt->io_base = ioremap(res->start, iomem_size);
573 + if (!skt->io_base) {
574 + ret = -ENOMEM;
575 + goto err;
576 + }
577 +
578 + /* resources are static */
579 + sock->resource_ops = &pccard_static_ops;
580 + sock->ops = &bcm63xx_pcmcia_operations;
581 + sock->owner = THIS_MODULE;
582 + sock->dev.parent = &pdev->dev;
583 + sock->features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD;
584 + sock->io_offset = (unsigned long)skt->io_base;
585 + sock->pci_irq = irq_res->start;
586 +
587 +#ifdef CONFIG_CARDBUS
588 + sock->cb_dev = bcm63xx_cb_dev;
589 + if (bcm63xx_cb_dev)
590 + sock->features |= SS_CAP_CARDBUS;
591 +#endif
592 +
593 + /* assume common & attribute memory have the same size */
594 + sock->map_size = skt->common_res->end - skt->common_res->start + 1;
595 +
596 + /* initialize polling timer */
597 + setup_timer(&skt->timer, bcm63xx_pcmcia_poll, (unsigned long)skt);
598 +
599 + /* initialize pcmcia control register, drive VS[12] to 0,
600 + * leave CB IDSEL to the old value since it is set by the PCI
601 + * layer */
602 + val = pcmcia_readl(skt, PCMCIA_C1_REG);
603 + val &= PCMCIA_C1_CBIDSEL_MASK;
604 + val |= PCMCIA_C1_EN_PCMCIA_GPIO_MASK;
605 + pcmcia_writel(skt, val, PCMCIA_C1_REG);
606 +
607 + /* FIXME set correct pcmcia timings */
608 + val = PCMCIA_C2_DATA16_MASK;
609 + val |= 10 << PCMCIA_C2_RWCOUNT_SHIFT;
610 + val |= 6 << PCMCIA_C2_INACTIVE_SHIFT;
611 + val |= 3 << PCMCIA_C2_SETUP_SHIFT;
612 + val |= 3 << PCMCIA_C2_HOLD_SHIFT;
613 + pcmcia_writel(skt, val, PCMCIA_C2_REG);
614 +
615 + ret = pcmcia_register_socket(sock);
616 + if (ret)
617 + goto err;
618 +
619 + /* start polling socket */
620 + mod_timer(&skt->timer,
621 + jiffies + msecs_to_jiffies(BCM63XX_PCMCIA_POLL_RATE));
622 +
623 + platform_set_drvdata(pdev, skt);
624 + return 0;
625 +
626 +err:
627 + if (skt->io_base)
628 + iounmap(skt->io_base);
629 + if (skt->base)
630 + iounmap(skt->base);
631 + if (skt->reg_res)
632 + release_mem_region(skt->reg_res->start, regmem_size);
633 + kfree(skt);
634 + return ret;
635 +}
636 +
637 +static int bcm63xx_drv_pcmcia_remove(struct platform_device *pdev)
638 +{
639 + struct bcm63xx_pcmcia_socket *skt;
640 + struct resource *res;
641 +
642 + skt = platform_get_drvdata(pdev);
643 + del_timer_sync(&skt->timer);
644 + iounmap(skt->base);
645 + iounmap(skt->io_base);
646 + res = skt->reg_res;
647 + release_mem_region(res->start, res->end - res->start + 1);
648 + kfree(skt);
649 + return 0;
650 +}
651 +
652 +struct platform_driver bcm63xx_pcmcia_driver = {
653 + .probe = bcm63xx_drv_pcmcia_probe,
654 + .remove = __devexit_p(bcm63xx_drv_pcmcia_remove),
655 + .driver = {
656 + .name = "bcm63xx_pcmcia",
657 + .owner = THIS_MODULE,
658 + },
659 +};
660 +
661 +#ifdef CONFIG_CARDBUS
662 +static int __devinit bcm63xx_cb_probe(struct pci_dev *dev,
663 + const struct pci_device_id *id)
664 +{
665 + /* keep pci device */
666 + bcm63xx_cb_dev = dev;
667 + return platform_driver_register(&bcm63xx_pcmcia_driver);
668 +}
669 +
670 +static void __devexit bcm63xx_cb_exit(struct pci_dev *dev)
671 +{
672 + platform_driver_unregister(&bcm63xx_pcmcia_driver);
673 + bcm63xx_cb_dev = NULL;
674 +}
675 +
676 +static struct pci_device_id bcm63xx_cb_table[] = {
677 + {
678 + .vendor = PCI_VENDOR_ID_BROADCOM,
679 + .device = PCI_ANY_ID,
680 + .subvendor = PCI_VENDOR_ID_BROADCOM,
681 + .subdevice = PCI_ANY_ID,
682 + .class = PCI_CLASS_BRIDGE_CARDBUS << 8,
683 + .class_mask = ~0,
684 + },
685 +};
686 +
687 +MODULE_DEVICE_TABLE(pci, bcm63xx_cb_table);
688 +
689 +static struct pci_driver bcm63xx_cardbus_driver = {
690 + .name = "yenta_cardbus",
691 + .id_table = bcm63xx_cb_table,
692 + .probe = bcm63xx_cb_probe,
693 + .remove = __devexit_p(bcm63xx_cb_exit),
694 +};
695 +#endif
696 +
697 +/*
698 + * if cardbus support is enabled, register our platform device after
699 + * our fake cardbus bridge has been registered
700 + */
701 +static int __init bcm63xx_pcmcia_init(void)
702 +{
703 +#ifdef CONFIG_CARDBUS
704 + return pci_register_driver(&bcm63xx_cardbus_driver);
705 +#else
706 + return platform_driver_register(&bcm63xx_pcmcia_driver);
707 +#endif
708 +}
709 +
710 +static void __exit bcm63xx_pcmcia_exit(void)
711 +{
712 +#ifdef CONFIG_CARDBUS
713 + return pci_unregister_driver(&bcm63xx_cardbus_driver);
714 +#else
715 + platform_driver_unregister(&bcm63xx_pcmcia_driver);
716 +#endif
717 +}
718 +
719 +module_init(bcm63xx_pcmcia_init);
720 +module_exit(bcm63xx_pcmcia_exit);
721 +
722 +MODULE_LICENSE("GPL");
723 +MODULE_AUTHOR("Maxime Bizon <mbizon@freebox.fr>");
724 +MODULE_DESCRIPTION("Linux PCMCIA Card Services: bcm63xx Socket Controller");
725 diff --git a/drivers/pcmcia/bcm63xx_pcmcia.h b/drivers/pcmcia/bcm63xx_pcmcia.h
726 new file mode 100644
727 index 0000000..85de866
728 --- /dev/null
729 +++ b/drivers/pcmcia/bcm63xx_pcmcia.h
730 @@ -0,0 +1,65 @@
731 +#ifndef BCM63XX_PCMCIA_H_
732 +#define BCM63XX_PCMCIA_H_
733 +
734 +#include <linux/types.h>
735 +#include <linux/timer.h>
736 +#include <pcmcia/ss.h>
737 +#include <bcm63xx_dev_pcmcia.h>
738 +
739 +/* socket polling rate in ms */
740 +#define BCM63XX_PCMCIA_POLL_RATE 500
741 +
742 +enum {
743 + CARD_CARDBUS = (1 << 0),
744 +
745 + CARD_PCCARD = (1 << 1),
746 +
747 + CARD_5V = (1 << 2),
748 +
749 + CARD_3V = (1 << 3),
750 +
751 + CARD_XV = (1 << 4),
752 +
753 + CARD_YV = (1 << 5),
754 +};
755 +
756 +struct bcm63xx_pcmcia_socket {
757 + struct pcmcia_socket socket;
758 +
759 + /* platform specific data */
760 + struct bcm63xx_pcmcia_platform_data *pd;
761 +
762 + /* all regs access are protected by this spinlock */
763 + spinlock_t lock;
764 +
765 + /* pcmcia registers resource */
766 + struct resource *reg_res;
767 +
768 + /* base remapped address of registers */
769 + void __iomem *base;
770 +
771 + /* whether a card is detected at the moment */
772 + int card_detected;
773 +
774 + /* type of detected card (mask of above enum) */
775 + u8 card_type;
776 +
777 + /* keep last socket status to implement event reporting */
778 + unsigned int old_status;
779 +
780 + /* backup of requested socket state */
781 + socket_state_t requested_state;
782 +
783 + /* timer used for socket status polling */
784 + struct timer_list timer;
785 +
786 + /* attribute/common memory resources */
787 + struct resource *attr_res;
788 + struct resource *common_res;
789 + struct resource *io_res;
790 +
791 + /* base address of io memory */
792 + void __iomem *io_base;
793 +};
794 +
795 +#endif /* BCM63XX_PCMCIA_H_ */
796 diff --git a/include/asm-mips/mach-bcm63xx/bcm63xx_dev_pcmcia.h b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_pcmcia.h
797 new file mode 100644
798 index 0000000..2beb396
799 --- /dev/null
800 +++ b/include/asm-mips/mach-bcm63xx/bcm63xx_dev_pcmcia.h
801 @@ -0,0 +1,13 @@
802 +#ifndef BCM63XX_DEV_PCMCIA_H_
803 +#define BCM63XX_DEV_PCMCIA_H_
804 +
805 +/*
806 + * PCMCIA driver platform data
807 + */
808 +struct bcm63xx_pcmcia_platform_data {
809 + unsigned int ready_gpio;
810 +};
811 +
812 +int bcm63xx_pcmcia_register(void);
813 +
814 +#endif /* BCM63XX_DEV_PCMCIA_H_ */
815 --
816 1.5.4.3
817