4 * Compaq ASIC3 support.
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.
10 * Copyright 2001 Compaq Computer Corporation.
11 * Copyright 2004-2005 Phil Blundell
12 * Copyright 2007-2008 OpenedHand Ltd.
14 * Authors: Phil Blundell <pb@handhelds.org>,
15 * Samuel Ortiz <sameo@openedhand.com>
19 #include <linux/kernel.h>
20 #include <linux/delay.h>
21 #include <linux/irq.h>
22 #include <linux/gpio.h>
24 #include <linux/spinlock.h>
25 #include <linux/platform_device.h>
27 #include <linux/mfd/asic3.h>
28 #include <linux/mfd/core.h>
29 #include <linux/mfd/ds1wm.h>
30 #include <linux/mfd/tmio.h>
53 #define INIT_CDEX(_name, _rate) \
54 [ASIC3_CLOCK_##_name] = { \
55 .cdex = CLOCK_CDEX_##_name, \
59 struct asic3_clk asic3_clk_init[] __initdata = {
61 INIT_CDEX(OWM, 5000000),
67 INIT_CDEX(SD_HOST, 24576000),
68 INIT_CDEX(SD_BUS, 12288000),
70 INIT_CDEX(EX0, 32768),
71 INIT_CDEX(EX1, 24576000),
75 void __iomem *mapping;
76 unsigned int bus_shift;
78 unsigned int irq_base;
81 struct gpio_chip gpio;
84 struct asic3_clk clocks[ARRAY_SIZE(asic3_clk_init)];
87 static int asic3_gpio_get(struct gpio_chip *chip, unsigned offset);
89 static inline void asic3_write_register(struct asic3 *asic,
90 unsigned int reg, u32 value)
92 iowrite16(value, asic->mapping +
93 (reg >> asic->bus_shift));
96 static inline u32 asic3_read_register(struct asic3 *asic,
99 return ioread16(asic->mapping +
100 (reg >> asic->bus_shift));
103 void asic3_set_register(struct asic3 *asic, u32 reg, u32 bits, bool set)
108 spin_lock_irqsave(&asic->lock, flags);
109 val = asic3_read_register(asic, reg);
114 asic3_write_register(asic, reg, val);
115 spin_unlock_irqrestore(&asic->lock, flags);
119 #define MAX_ASIC_ISR_LOOPS 20
120 #define ASIC3_GPIO_BASE_INCR \
121 (ASIC3_GPIO_B_BASE - ASIC3_GPIO_A_BASE)
123 static void asic3_irq_flip_edge(struct asic3 *asic,
129 spin_lock_irqsave(&asic->lock, flags);
130 edge = asic3_read_register(asic,
131 base + ASIC3_GPIO_EDGE_TRIGGER);
133 asic3_write_register(asic,
134 base + ASIC3_GPIO_EDGE_TRIGGER, edge);
135 spin_unlock_irqrestore(&asic->lock, flags);
138 static void asic3_irq_demux(unsigned int irq, struct irq_desc *desc)
144 desc->chip->ack(irq);
146 asic = desc->handler_data;
148 for (iter = 0 ; iter < MAX_ASIC_ISR_LOOPS; iter++) {
152 spin_lock_irqsave(&asic->lock, flags);
153 status = asic3_read_register(asic,
154 ASIC3_OFFSET(INTR, P_INT_STAT));
155 spin_unlock_irqrestore(&asic->lock, flags);
157 /* Check all ten register bits */
158 if ((status & 0x3ff) == 0)
161 /* Handle GPIO IRQs */
162 for (bank = 0; bank < ASIC3_NUM_GPIO_BANKS; bank++) {
163 if (status & (1 << bank)) {
164 unsigned long base, istat;
166 base = ASIC3_GPIO_A_BASE
167 + bank * ASIC3_GPIO_BASE_INCR;
169 spin_lock_irqsave(&asic->lock, flags);
170 istat = asic3_read_register(asic,
172 ASIC3_GPIO_INT_STATUS);
173 /* Clearing IntStatus */
174 asic3_write_register(asic,
176 ASIC3_GPIO_INT_STATUS, 0);
177 spin_unlock_irqrestore(&asic->lock, flags);
179 for (i = 0; i < ASIC3_GPIOS_PER_BANK; i++) {
186 irqnr = asic->irq_base +
187 (ASIC3_GPIOS_PER_BANK * bank)
189 desc = irq_to_desc(irqnr);
190 desc->handle_irq(irqnr, desc);
191 if (asic->irq_bothedge[bank] & bit)
192 asic3_irq_flip_edge(asic, base,
198 /* Handle remaining IRQs in the status register */
199 for (i = ASIC3_NUM_GPIOS; i < ASIC3_NR_IRQS; i++) {
200 /* They start at bit 4 and go up */
201 if (status & (1 << (i - ASIC3_NUM_GPIOS + 4))) {
202 desc = irq_to_desc(asic->irq_base + i);
203 desc->handle_irq(asic->irq_base + i,
209 if (iter >= MAX_ASIC_ISR_LOOPS)
210 dev_err(asic->dev, "interrupt processing overrun\n");
213 static inline int asic3_irq_to_bank(struct asic3 *asic, int irq)
217 n = (irq - asic->irq_base) >> 4;
219 return (n * (ASIC3_GPIO_B_BASE - ASIC3_GPIO_A_BASE));
222 static inline int asic3_irq_to_index(struct asic3 *asic, int irq)
224 return (irq - asic->irq_base) & 0xf;
227 static void asic3_mask_gpio_irq(unsigned int irq)
229 struct asic3 *asic = get_irq_chip_data(irq);
230 u32 val, bank, index;
233 bank = asic3_irq_to_bank(asic, irq);
234 index = asic3_irq_to_index(asic, irq);
236 spin_lock_irqsave(&asic->lock, flags);
237 val = asic3_read_register(asic, bank + ASIC3_GPIO_MASK);
239 asic3_write_register(asic, bank + ASIC3_GPIO_MASK, val);
240 spin_unlock_irqrestore(&asic->lock, flags);
243 static void asic3_mask_irq(unsigned int irq)
245 struct asic3 *asic = get_irq_chip_data(irq);
249 spin_lock_irqsave(&asic->lock, flags);
250 regval = asic3_read_register(asic,
252 ASIC3_INTR_INT_MASK);
254 regval &= ~(ASIC3_INTMASK_MASK0 <<
255 (irq - (asic->irq_base + ASIC3_NUM_GPIOS)));
257 asic3_write_register(asic,
261 spin_unlock_irqrestore(&asic->lock, flags);
264 static void asic3_unmask_gpio_irq(unsigned int irq)
266 struct asic3 *asic = get_irq_chip_data(irq);
267 u32 val, bank, index;
270 bank = asic3_irq_to_bank(asic, irq);
271 index = asic3_irq_to_index(asic, irq);
273 spin_lock_irqsave(&asic->lock, flags);
274 val = asic3_read_register(asic, bank + ASIC3_GPIO_MASK);
275 val &= ~(1 << index);
276 asic3_write_register(asic, bank + ASIC3_GPIO_MASK, val);
277 spin_unlock_irqrestore(&asic->lock, flags);
280 static void asic3_unmask_irq(unsigned int irq)
282 struct asic3 *asic = get_irq_chip_data(irq);
286 spin_lock_irqsave(&asic->lock, flags);
287 regval = asic3_read_register(asic,
289 ASIC3_INTR_INT_MASK);
291 regval |= (ASIC3_INTMASK_MASK0 <<
292 (irq - (asic->irq_base + ASIC3_NUM_GPIOS)));
294 asic3_write_register(asic,
298 spin_unlock_irqrestore(&asic->lock, flags);
301 static int asic3_gpio_irq_type(unsigned int irq, unsigned int type)
303 struct asic3 *asic = get_irq_chip_data(irq);
305 u16 trigger, level, edge, bit;
308 bank = asic3_irq_to_bank(asic, irq);
309 index = asic3_irq_to_index(asic, irq);
312 spin_lock_irqsave(&asic->lock, flags);
313 level = asic3_read_register(asic,
314 bank + ASIC3_GPIO_LEVEL_TRIGGER);
315 edge = asic3_read_register(asic,
316 bank + ASIC3_GPIO_EDGE_TRIGGER);
317 trigger = asic3_read_register(asic,
318 bank + ASIC3_GPIO_TRIGGER_TYPE);
319 asic->irq_bothedge[(irq - asic->irq_base) >> 4] &= ~bit;
321 if (type == IRQ_TYPE_EDGE_RISING) {
324 } else if (type == IRQ_TYPE_EDGE_FALLING) {
327 } else if (type == IRQ_TYPE_EDGE_BOTH) {
329 if (asic3_gpio_get(&asic->gpio, irq - asic->irq_base))
333 asic->irq_bothedge[(irq - asic->irq_base) >> 4] |= bit;
334 } else if (type == IRQ_TYPE_LEVEL_LOW) {
337 } else if (type == IRQ_TYPE_LEVEL_HIGH) {
342 * if type == IRQ_TYPE_NONE, we should mask interrupts, but
343 * be careful to not unmask them if mask was also called.
344 * Probably need internal state for mask.
346 dev_notice(asic->dev, "irq type not changed\n");
348 asic3_write_register(asic, bank + ASIC3_GPIO_LEVEL_TRIGGER,
350 asic3_write_register(asic, bank + ASIC3_GPIO_EDGE_TRIGGER,
352 asic3_write_register(asic, bank + ASIC3_GPIO_TRIGGER_TYPE,
354 spin_unlock_irqrestore(&asic->lock, flags);
358 static struct irq_chip asic3_gpio_irq_chip = {
359 .name = "ASIC3-GPIO",
360 .ack = asic3_mask_gpio_irq,
361 .mask = asic3_mask_gpio_irq,
362 .unmask = asic3_unmask_gpio_irq,
363 .set_type = asic3_gpio_irq_type,
366 static struct irq_chip asic3_irq_chip = {
368 .ack = asic3_mask_irq,
369 .mask = asic3_mask_irq,
370 .unmask = asic3_unmask_irq,
373 static int __init asic3_irq_probe(struct platform_device *pdev)
375 struct asic3 *asic = platform_get_drvdata(pdev);
376 unsigned long clksel = 0;
377 unsigned int irq, irq_base;
380 ret = platform_get_irq(pdev, 0);
385 /* turn on clock to IRQ controller */
386 clksel |= CLOCK_SEL_CX;
387 asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL),
390 irq_base = asic->irq_base;
392 for (irq = irq_base; irq < irq_base + ASIC3_NR_IRQS; irq++) {
393 if (irq < asic->irq_base + ASIC3_NUM_GPIOS)
394 set_irq_chip(irq, &asic3_gpio_irq_chip);
396 set_irq_chip(irq, &asic3_irq_chip);
398 set_irq_chip_data(irq, asic);
399 set_irq_handler(irq, handle_level_irq);
400 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
403 asic3_write_register(asic, ASIC3_OFFSET(INTR, INT_MASK),
404 ASIC3_INTMASK_GINTMASK);
406 set_irq_chained_handler(asic->irq_nr, asic3_irq_demux);
407 set_irq_type(asic->irq_nr, IRQ_TYPE_EDGE_RISING);
408 set_irq_data(asic->irq_nr, asic);
413 static void asic3_irq_remove(struct platform_device *pdev)
415 struct asic3 *asic = platform_get_drvdata(pdev);
416 unsigned int irq, irq_base;
418 irq_base = asic->irq_base;
420 for (irq = irq_base; irq < irq_base + ASIC3_NR_IRQS; irq++) {
421 set_irq_flags(irq, 0);
422 set_irq_handler(irq, NULL);
423 set_irq_chip(irq, NULL);
424 set_irq_chip_data(irq, NULL);
426 set_irq_chained_handler(asic->irq_nr, NULL);
430 static int asic3_gpio_direction(struct gpio_chip *chip,
431 unsigned offset, int out)
433 u32 mask = ASIC3_GPIO_TO_MASK(offset), out_reg;
434 unsigned int gpio_base;
438 asic = container_of(chip, struct asic3, gpio);
439 gpio_base = ASIC3_GPIO_TO_BASE(offset);
441 if (gpio_base > ASIC3_GPIO_D_BASE) {
442 dev_err(asic->dev, "Invalid base (0x%x) for gpio %d\n",
447 spin_lock_irqsave(&asic->lock, flags);
449 out_reg = asic3_read_register(asic, gpio_base + ASIC3_GPIO_DIRECTION);
451 /* Input is 0, Output is 1 */
457 asic3_write_register(asic, gpio_base + ASIC3_GPIO_DIRECTION, out_reg);
459 spin_unlock_irqrestore(&asic->lock, flags);
465 static int asic3_gpio_direction_input(struct gpio_chip *chip,
468 return asic3_gpio_direction(chip, offset, 0);
471 static int asic3_gpio_direction_output(struct gpio_chip *chip,
472 unsigned offset, int value)
474 return asic3_gpio_direction(chip, offset, 1);
477 static int asic3_gpio_get(struct gpio_chip *chip,
480 unsigned int gpio_base;
481 u32 mask = ASIC3_GPIO_TO_MASK(offset);
484 asic = container_of(chip, struct asic3, gpio);
485 gpio_base = ASIC3_GPIO_TO_BASE(offset);
487 if (gpio_base > ASIC3_GPIO_D_BASE) {
488 dev_err(asic->dev, "Invalid base (0x%x) for gpio %d\n",
493 return asic3_read_register(asic, gpio_base + ASIC3_GPIO_STATUS) & mask;
496 static void asic3_gpio_set(struct gpio_chip *chip,
497 unsigned offset, int value)
500 unsigned int gpio_base;
504 asic = container_of(chip, struct asic3, gpio);
505 gpio_base = ASIC3_GPIO_TO_BASE(offset);
507 if (gpio_base > ASIC3_GPIO_D_BASE) {
508 dev_err(asic->dev, "Invalid base (0x%x) for gpio %d\n",
513 mask = ASIC3_GPIO_TO_MASK(offset);
515 spin_lock_irqsave(&asic->lock, flags);
517 out_reg = asic3_read_register(asic, gpio_base + ASIC3_GPIO_OUT);
524 asic3_write_register(asic, gpio_base + ASIC3_GPIO_OUT, out_reg);
526 spin_unlock_irqrestore(&asic->lock, flags);
531 static __init int asic3_gpio_probe(struct platform_device *pdev,
532 u16 *gpio_config, int num)
534 struct asic3 *asic = platform_get_drvdata(pdev);
535 u16 alt_reg[ASIC3_NUM_GPIO_BANKS];
536 u16 out_reg[ASIC3_NUM_GPIO_BANKS];
537 u16 dir_reg[ASIC3_NUM_GPIO_BANKS];
540 memset(alt_reg, 0, ASIC3_NUM_GPIO_BANKS * sizeof(u16));
541 memset(out_reg, 0, ASIC3_NUM_GPIO_BANKS * sizeof(u16));
542 memset(dir_reg, 0, ASIC3_NUM_GPIO_BANKS * sizeof(u16));
544 /* Enable all GPIOs */
545 asic3_write_register(asic, ASIC3_GPIO_OFFSET(A, MASK), 0xffff);
546 asic3_write_register(asic, ASIC3_GPIO_OFFSET(B, MASK), 0xffff);
547 asic3_write_register(asic, ASIC3_GPIO_OFFSET(C, MASK), 0xffff);
548 asic3_write_register(asic, ASIC3_GPIO_OFFSET(D, MASK), 0xffff);
550 for (i = 0; i < num; i++) {
551 u8 alt, pin, dir, init, bank_num, bit_num;
552 u16 config = gpio_config[i];
554 pin = ASIC3_CONFIG_GPIO_PIN(config);
555 alt = ASIC3_CONFIG_GPIO_ALT(config);
556 dir = ASIC3_CONFIG_GPIO_DIR(config);
557 init = ASIC3_CONFIG_GPIO_INIT(config);
559 bank_num = ASIC3_GPIO_TO_BANK(pin);
560 bit_num = ASIC3_GPIO_TO_BIT(pin);
562 alt_reg[bank_num] |= (alt << bit_num);
563 out_reg[bank_num] |= (init << bit_num);
564 dir_reg[bank_num] |= (dir << bit_num);
567 for (i = 0; i < ASIC3_NUM_GPIO_BANKS; i++) {
568 asic3_write_register(asic,
569 ASIC3_BANK_TO_BASE(i) +
570 ASIC3_GPIO_DIRECTION,
572 asic3_write_register(asic,
573 ASIC3_BANK_TO_BASE(i) + ASIC3_GPIO_OUT,
575 asic3_write_register(asic,
576 ASIC3_BANK_TO_BASE(i) +
577 ASIC3_GPIO_ALT_FUNCTION,
581 return gpiochip_add(&asic->gpio);
584 static int asic3_gpio_remove(struct platform_device *pdev)
586 struct asic3 *asic = platform_get_drvdata(pdev);
588 return gpiochip_remove(&asic->gpio);
591 static int asic3_clk_enable(struct asic3 *asic, struct asic3_clk *clk)
596 spin_lock_irqsave(&asic->lock, flags);
597 if (clk->enabled++ == 0) {
598 cdex = asic3_read_register(asic, ASIC3_OFFSET(CLOCK, CDEX));
600 asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex);
602 spin_unlock_irqrestore(&asic->lock, flags);
607 static void asic3_clk_disable(struct asic3 *asic, struct asic3_clk *clk)
612 WARN_ON(clk->enabled == 0);
614 spin_lock_irqsave(&asic->lock, flags);
615 if (--clk->enabled == 0) {
616 cdex = asic3_read_register(asic, ASIC3_OFFSET(CLOCK, CDEX));
618 asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex);
620 spin_unlock_irqrestore(&asic->lock, flags);
623 /* MFD cells (SPI, PWM, LED, DS1WM, MMC) */
624 static struct ds1wm_driver_data ds1wm_pdata = {
628 static struct resource ds1wm_resources[] = {
630 .start = ASIC3_OWM_BASE,
631 .end = ASIC3_OWM_BASE + 0x13,
632 .flags = IORESOURCE_MEM,
635 .start = ASIC3_IRQ_OWM,
636 .start = ASIC3_IRQ_OWM,
637 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
641 static int ds1wm_enable(struct platform_device *pdev)
643 struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
645 /* Turn on external clocks and the OWM clock */
646 asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
647 asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
648 asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_OWM]);
651 /* Reset and enable DS1WM */
652 asic3_set_register(asic, ASIC3_OFFSET(EXTCF, RESET),
653 ASIC3_EXTCF_OWM_RESET, 1);
655 asic3_set_register(asic, ASIC3_OFFSET(EXTCF, RESET),
656 ASIC3_EXTCF_OWM_RESET, 0);
658 asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
659 ASIC3_EXTCF_OWM_EN, 1);
665 static int ds1wm_disable(struct platform_device *pdev)
667 struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
669 asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
670 ASIC3_EXTCF_OWM_EN, 0);
672 asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_OWM]);
673 asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
674 asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
679 static struct mfd_cell asic3_cell_ds1wm = {
681 .enable = ds1wm_enable,
682 .disable = ds1wm_disable,
683 .driver_data = &ds1wm_pdata,
684 .num_resources = ARRAY_SIZE(ds1wm_resources),
685 .resources = ds1wm_resources,
688 static struct tmio_mmc_data asic3_mmc_data = {
692 static struct resource asic3_mmc_resources[] = {
694 .start = ASIC3_SD_CTRL_BASE,
695 .end = ASIC3_SD_CTRL_BASE + 0x3ff,
696 .flags = IORESOURCE_MEM,
699 .start = ASIC3_SD_CONFIG_BASE,
700 .end = ASIC3_SD_CONFIG_BASE + 0x1ff,
701 .flags = IORESOURCE_MEM,
706 .flags = IORESOURCE_IRQ,
710 static int asic3_mmc_enable(struct platform_device *pdev)
712 struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
714 /* Not sure if it must be done bit by bit, but leaving as-is */
715 asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
716 ASIC3_SDHWCTRL_LEVCD, 1);
717 asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
718 ASIC3_SDHWCTRL_LEVWP, 1);
719 asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
720 ASIC3_SDHWCTRL_SUSPEND, 0);
721 asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
722 ASIC3_SDHWCTRL_PCLR, 0);
724 asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
725 /* CLK32 used for card detection and for interruption detection
726 * when HCLK is stopped.
728 asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
731 /* HCLK 24.576 MHz, BCLK 12.288 MHz: */
732 asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL),
733 CLOCK_SEL_CX | CLOCK_SEL_SD_HCLK_SEL);
735 asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_SD_HOST]);
736 asic3_clk_enable(asic, &asic->clocks[ASIC3_CLOCK_SD_BUS]);
739 asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
740 ASIC3_EXTCF_SD_MEM_ENABLE, 1);
742 /* Enable SD card slot 3.3V power supply */
743 asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
744 ASIC3_SDHWCTRL_SDPWR, 1);
749 static int asic3_mmc_disable(struct platform_device *pdev)
751 struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
753 /* Put in suspend mode */
754 asic3_set_register(asic, ASIC3_OFFSET(SDHWCTRL, SDCONF),
755 ASIC3_SDHWCTRL_SUSPEND, 1);
758 asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_SD_HOST]);
759 asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_SD_BUS]);
760 asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX0]);
761 asic3_clk_disable(asic, &asic->clocks[ASIC3_CLOCK_EX1]);
765 static struct mfd_cell asic3_cell_mmc = {
767 .enable = asic3_mmc_enable,
768 .disable = asic3_mmc_disable,
769 .driver_data = &asic3_mmc_data,
770 .num_resources = ARRAY_SIZE(asic3_mmc_resources),
771 .resources = asic3_mmc_resources,
774 static int __init asic3_mfd_probe(struct platform_device *pdev,
775 struct resource *mem)
777 struct asic3 *asic = platform_get_drvdata(pdev);
778 struct resource *mem_sdio;
781 mem_sdio = platform_get_resource(pdev, IORESOURCE_MEM, 1);
783 dev_dbg(asic->dev, "no SDIO MEM resource\n");
785 irq = platform_get_irq(pdev, 1);
787 dev_dbg(asic->dev, "no SDIO IRQ resource\n");
790 asic3_set_register(asic, ASIC3_OFFSET(EXTCF, SELECT),
791 ASIC3_EXTCF_OWM_SMB, 0);
793 ds1wm_resources[0].start >>= asic->bus_shift;
794 ds1wm_resources[0].end >>= asic->bus_shift;
796 asic3_cell_ds1wm.platform_data = &asic3_cell_ds1wm;
797 asic3_cell_ds1wm.data_size = sizeof(asic3_cell_ds1wm);
800 asic3_mmc_resources[0].start >>= asic->bus_shift;
801 asic3_mmc_resources[0].end >>= asic->bus_shift;
802 asic3_mmc_resources[1].start >>= asic->bus_shift;
803 asic3_mmc_resources[1].end >>= asic->bus_shift;
805 asic3_cell_mmc.platform_data = &asic3_cell_mmc;
806 asic3_cell_mmc.data_size = sizeof(asic3_cell_mmc);
808 ret = mfd_add_devices(&pdev->dev, pdev->id,
809 &asic3_cell_ds1wm, 1, mem, asic->irq_base);
813 if (mem_sdio && (irq >= 0))
814 ret = mfd_add_devices(&pdev->dev, pdev->id,
815 &asic3_cell_mmc, 1, mem_sdio, irq);
821 static void asic3_mfd_remove(struct platform_device *pdev)
823 mfd_remove_devices(&pdev->dev);
827 static int __init asic3_probe(struct platform_device *pdev)
829 struct asic3_platform_data *pdata = pdev->dev.platform_data;
831 struct resource *mem;
832 unsigned long clksel;
835 asic = kzalloc(sizeof(struct asic3), GFP_KERNEL);
837 printk(KERN_ERR "kzalloc failed\n");
841 spin_lock_init(&asic->lock);
842 platform_set_drvdata(pdev, asic);
843 asic->dev = &pdev->dev;
845 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
848 dev_err(asic->dev, "no MEM resource\n");
852 asic->mapping = ioremap(mem->start, resource_size(mem));
853 if (!asic->mapping) {
855 dev_err(asic->dev, "Couldn't ioremap\n");
859 asic->irq_base = pdata->irq_base;
861 /* calculate bus shift from mem resource */
862 asic->bus_shift = 2 - (resource_size(mem) >> 12);
865 asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL), clksel);
867 ret = asic3_irq_probe(pdev);
869 dev_err(asic->dev, "Couldn't probe IRQs\n");
873 asic->gpio.base = pdata->gpio_base;
874 asic->gpio.ngpio = ASIC3_NUM_GPIOS;
875 asic->gpio.get = asic3_gpio_get;
876 asic->gpio.set = asic3_gpio_set;
877 asic->gpio.direction_input = asic3_gpio_direction_input;
878 asic->gpio.direction_output = asic3_gpio_direction_output;
880 ret = asic3_gpio_probe(pdev,
882 pdata->gpio_config_num);
884 dev_err(asic->dev, "GPIO probe failed\n");
888 /* Making a per-device copy is only needed for the
889 * theoretical case of multiple ASIC3s on one board:
891 memcpy(asic->clocks, asic3_clk_init, sizeof(asic3_clk_init));
893 asic3_mfd_probe(pdev, mem);
895 dev_info(asic->dev, "ASIC3 Core driver\n");
900 asic3_irq_remove(pdev);
903 iounmap(asic->mapping);
911 static int __devexit asic3_remove(struct platform_device *pdev)
914 struct asic3 *asic = platform_get_drvdata(pdev);
916 asic3_mfd_remove(pdev);
918 ret = asic3_gpio_remove(pdev);
921 asic3_irq_remove(pdev);
923 asic3_write_register(asic, ASIC3_OFFSET(CLOCK, SEL), 0);
925 iounmap(asic->mapping);
932 static void asic3_shutdown(struct platform_device *pdev)
936 static struct platform_driver asic3_device_driver = {
940 .remove = __devexit_p(asic3_remove),
941 .shutdown = asic3_shutdown,
944 static int __init asic3_init(void)
947 retval = platform_driver_probe(&asic3_device_driver, asic3_probe);
951 subsys_initcall(asic3_init);