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