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
;
83 void __iomem
*tmio_cnf
;
85 struct asic3_clk clocks
[ARRAY_SIZE(asic3_clk_init
)];
88 static int asic3_gpio_get(struct gpio_chip
*chip
, unsigned offset
);
90 static inline void asic3_write_register(struct asic3
*asic
,
91 unsigned int reg
, u32 value
)
93 iowrite16(value
, asic
->mapping
+
94 (reg
>> asic
->bus_shift
));
97 static inline u32
asic3_read_register(struct asic3
*asic
,
100 return ioread16(asic
->mapping
+
101 (reg
>> asic
->bus_shift
));
104 void asic3_set_register(struct asic3
*asic
, u32 reg
, u32 bits
, bool set
)
109 spin_lock_irqsave(&asic
->lock
, flags
);
110 val
= asic3_read_register(asic
, reg
);
115 asic3_write_register(asic
, reg
, val
);
116 spin_unlock_irqrestore(&asic
->lock
, flags
);
120 #define MAX_ASIC_ISR_LOOPS 20
121 #define ASIC3_GPIO_BASE_INCR \
122 (ASIC3_GPIO_B_BASE - ASIC3_GPIO_A_BASE)
124 static void asic3_irq_flip_edge(struct asic3
*asic
,
130 spin_lock_irqsave(&asic
->lock
, flags
);
131 edge
= asic3_read_register(asic
,
132 base
+ ASIC3_GPIO_EDGE_TRIGGER
);
134 asic3_write_register(asic
,
135 base
+ ASIC3_GPIO_EDGE_TRIGGER
, edge
);
136 spin_unlock_irqrestore(&asic
->lock
, flags
);
139 static void asic3_irq_demux(unsigned int irq
, struct irq_desc
*desc
)
145 desc
->chip
->ack(irq
);
147 asic
= desc
->handler_data
;
149 for (iter
= 0 ; iter
< MAX_ASIC_ISR_LOOPS
; iter
++) {
153 spin_lock_irqsave(&asic
->lock
, flags
);
154 status
= asic3_read_register(asic
,
155 ASIC3_OFFSET(INTR
, P_INT_STAT
));
156 spin_unlock_irqrestore(&asic
->lock
, flags
);
158 /* Check all ten register bits */
159 if ((status
& 0x3ff) == 0)
162 /* Handle GPIO IRQs */
163 for (bank
= 0; bank
< ASIC3_NUM_GPIO_BANKS
; bank
++) {
164 if (status
& (1 << bank
)) {
165 unsigned long base
, istat
;
167 base
= ASIC3_GPIO_A_BASE
168 + bank
* ASIC3_GPIO_BASE_INCR
;
170 spin_lock_irqsave(&asic
->lock
, flags
);
171 istat
= asic3_read_register(asic
,
173 ASIC3_GPIO_INT_STATUS
);
174 /* Clearing IntStatus */
175 asic3_write_register(asic
,
177 ASIC3_GPIO_INT_STATUS
, 0);
178 spin_unlock_irqrestore(&asic
->lock
, flags
);
180 for (i
= 0; i
< ASIC3_GPIOS_PER_BANK
; i
++) {
187 irqnr
= asic
->irq_base
+
188 (ASIC3_GPIOS_PER_BANK
* bank
)
190 desc
= irq_to_desc(irqnr
);
191 desc
->handle_irq(irqnr
, desc
);
192 if (asic
->irq_bothedge
[bank
] & bit
)
193 asic3_irq_flip_edge(asic
, base
,
199 /* Handle remaining IRQs in the status register */
200 for (i
= ASIC3_NUM_GPIOS
; i
< ASIC3_NR_IRQS
; i
++) {
201 /* They start at bit 4 and go up */
202 if (status
& (1 << (i
- ASIC3_NUM_GPIOS
+ 4))) {
203 desc
= irq_to_desc(asic
->irq_base
+ i
);
204 desc
->handle_irq(asic
->irq_base
+ i
,
210 if (iter
>= MAX_ASIC_ISR_LOOPS
)
211 dev_err(asic
->dev
, "interrupt processing overrun\n");
214 static inline int asic3_irq_to_bank(struct asic3
*asic
, int irq
)
218 n
= (irq
- asic
->irq_base
) >> 4;
220 return (n
* (ASIC3_GPIO_B_BASE
- ASIC3_GPIO_A_BASE
));
223 static inline int asic3_irq_to_index(struct asic3
*asic
, int irq
)
225 return (irq
- asic
->irq_base
) & 0xf;
228 static void asic3_mask_gpio_irq(unsigned int irq
)
230 struct asic3
*asic
= get_irq_chip_data(irq
);
231 u32 val
, bank
, index
;
234 bank
= asic3_irq_to_bank(asic
, irq
);
235 index
= asic3_irq_to_index(asic
, irq
);
237 spin_lock_irqsave(&asic
->lock
, flags
);
238 val
= asic3_read_register(asic
, bank
+ ASIC3_GPIO_MASK
);
240 asic3_write_register(asic
, bank
+ ASIC3_GPIO_MASK
, val
);
241 spin_unlock_irqrestore(&asic
->lock
, flags
);
244 static void asic3_mask_irq(unsigned int irq
)
246 struct asic3
*asic
= get_irq_chip_data(irq
);
250 spin_lock_irqsave(&asic
->lock
, flags
);
251 regval
= asic3_read_register(asic
,
253 ASIC3_INTR_INT_MASK
);
255 regval
&= ~(ASIC3_INTMASK_MASK0
<<
256 (irq
- (asic
->irq_base
+ ASIC3_NUM_GPIOS
)));
258 asic3_write_register(asic
,
262 spin_unlock_irqrestore(&asic
->lock
, flags
);
265 static void asic3_unmask_gpio_irq(unsigned int irq
)
267 struct asic3
*asic
= get_irq_chip_data(irq
);
268 u32 val
, bank
, index
;
271 bank
= asic3_irq_to_bank(asic
, irq
);
272 index
= asic3_irq_to_index(asic
, irq
);
274 spin_lock_irqsave(&asic
->lock
, flags
);
275 val
= asic3_read_register(asic
, bank
+ ASIC3_GPIO_MASK
);
276 val
&= ~(1 << index
);
277 asic3_write_register(asic
, bank
+ ASIC3_GPIO_MASK
, val
);
278 spin_unlock_irqrestore(&asic
->lock
, flags
);
281 static void asic3_unmask_irq(unsigned int irq
)
283 struct asic3
*asic
= get_irq_chip_data(irq
);
287 spin_lock_irqsave(&asic
->lock
, flags
);
288 regval
= asic3_read_register(asic
,
290 ASIC3_INTR_INT_MASK
);
292 regval
|= (ASIC3_INTMASK_MASK0
<<
293 (irq
- (asic
->irq_base
+ ASIC3_NUM_GPIOS
)));
295 asic3_write_register(asic
,
299 spin_unlock_irqrestore(&asic
->lock
, flags
);
302 static int asic3_gpio_irq_type(unsigned int irq
, unsigned int type
)
304 struct asic3
*asic
= get_irq_chip_data(irq
);
306 u16 trigger
, level
, edge
, bit
;
309 bank
= asic3_irq_to_bank(asic
, irq
);
310 index
= asic3_irq_to_index(asic
, irq
);
313 spin_lock_irqsave(&asic
->lock
, flags
);
314 level
= asic3_read_register(asic
,
315 bank
+ ASIC3_GPIO_LEVEL_TRIGGER
);
316 edge
= asic3_read_register(asic
,
317 bank
+ ASIC3_GPIO_EDGE_TRIGGER
);
318 trigger
= asic3_read_register(asic
,
319 bank
+ ASIC3_GPIO_TRIGGER_TYPE
);
320 asic
->irq_bothedge
[(irq
- asic
->irq_base
) >> 4] &= ~bit
;
322 if (type
== IRQ_TYPE_EDGE_RISING
) {
325 } else if (type
== IRQ_TYPE_EDGE_FALLING
) {
328 } else if (type
== IRQ_TYPE_EDGE_BOTH
) {
330 if (asic3_gpio_get(&asic
->gpio
, irq
- asic
->irq_base
))
334 asic
->irq_bothedge
[(irq
- asic
->irq_base
) >> 4] |= bit
;
335 } else if (type
== IRQ_TYPE_LEVEL_LOW
) {
338 } else if (type
== IRQ_TYPE_LEVEL_HIGH
) {
343 * if type == IRQ_TYPE_NONE, we should mask interrupts, but
344 * be careful to not unmask them if mask was also called.
345 * Probably need internal state for mask.
347 dev_notice(asic
->dev
, "irq type not changed\n");
349 asic3_write_register(asic
, bank
+ ASIC3_GPIO_LEVEL_TRIGGER
,
351 asic3_write_register(asic
, bank
+ ASIC3_GPIO_EDGE_TRIGGER
,
353 asic3_write_register(asic
, bank
+ ASIC3_GPIO_TRIGGER_TYPE
,
355 spin_unlock_irqrestore(&asic
->lock
, flags
);
359 static struct irq_chip asic3_gpio_irq_chip
= {
360 .name
= "ASIC3-GPIO",
361 .ack
= asic3_mask_gpio_irq
,
362 .mask
= asic3_mask_gpio_irq
,
363 .unmask
= asic3_unmask_gpio_irq
,
364 .set_type
= asic3_gpio_irq_type
,
367 static struct irq_chip asic3_irq_chip
= {
369 .ack
= asic3_mask_irq
,
370 .mask
= asic3_mask_irq
,
371 .unmask
= asic3_unmask_irq
,
374 static int __init
asic3_irq_probe(struct platform_device
*pdev
)
376 struct asic3
*asic
= platform_get_drvdata(pdev
);
377 unsigned long clksel
= 0;
378 unsigned int irq
, irq_base
;
381 ret
= platform_get_irq(pdev
, 0);
386 /* turn on clock to IRQ controller */
387 clksel
|= CLOCK_SEL_CX
;
388 asic3_write_register(asic
, ASIC3_OFFSET(CLOCK
, SEL
),
391 irq_base
= asic
->irq_base
;
393 for (irq
= irq_base
; irq
< irq_base
+ ASIC3_NR_IRQS
; irq
++) {
394 if (irq
< asic
->irq_base
+ ASIC3_NUM_GPIOS
)
395 set_irq_chip(irq
, &asic3_gpio_irq_chip
);
397 set_irq_chip(irq
, &asic3_irq_chip
);
399 set_irq_chip_data(irq
, asic
);
400 set_irq_handler(irq
, handle_level_irq
);
401 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
404 asic3_write_register(asic
, ASIC3_OFFSET(INTR
, INT_MASK
),
405 ASIC3_INTMASK_GINTMASK
);
407 set_irq_chained_handler(asic
->irq_nr
, asic3_irq_demux
);
408 set_irq_type(asic
->irq_nr
, IRQ_TYPE_EDGE_RISING
);
409 set_irq_data(asic
->irq_nr
, asic
);
414 static void asic3_irq_remove(struct platform_device
*pdev
)
416 struct asic3
*asic
= platform_get_drvdata(pdev
);
417 unsigned int irq
, irq_base
;
419 irq_base
= asic
->irq_base
;
421 for (irq
= irq_base
; irq
< irq_base
+ ASIC3_NR_IRQS
; irq
++) {
422 set_irq_flags(irq
, 0);
423 set_irq_handler(irq
, NULL
);
424 set_irq_chip(irq
, NULL
);
425 set_irq_chip_data(irq
, NULL
);
427 set_irq_chained_handler(asic
->irq_nr
, NULL
);
431 static int asic3_gpio_direction(struct gpio_chip
*chip
,
432 unsigned offset
, int out
)
434 u32 mask
= ASIC3_GPIO_TO_MASK(offset
), out_reg
;
435 unsigned int gpio_base
;
439 asic
= container_of(chip
, struct asic3
, gpio
);
440 gpio_base
= ASIC3_GPIO_TO_BASE(offset
);
442 if (gpio_base
> ASIC3_GPIO_D_BASE
) {
443 dev_err(asic
->dev
, "Invalid base (0x%x) for gpio %d\n",
448 spin_lock_irqsave(&asic
->lock
, flags
);
450 out_reg
= asic3_read_register(asic
, gpio_base
+ ASIC3_GPIO_DIRECTION
);
452 /* Input is 0, Output is 1 */
458 asic3_write_register(asic
, gpio_base
+ ASIC3_GPIO_DIRECTION
, out_reg
);
460 spin_unlock_irqrestore(&asic
->lock
, flags
);
466 static int asic3_gpio_direction_input(struct gpio_chip
*chip
,
469 return asic3_gpio_direction(chip
, offset
, 0);
472 static int asic3_gpio_direction_output(struct gpio_chip
*chip
,
473 unsigned offset
, int value
)
475 return asic3_gpio_direction(chip
, offset
, 1);
478 static int asic3_gpio_get(struct gpio_chip
*chip
,
481 unsigned int gpio_base
;
482 u32 mask
= ASIC3_GPIO_TO_MASK(offset
);
485 asic
= container_of(chip
, struct asic3
, gpio
);
486 gpio_base
= ASIC3_GPIO_TO_BASE(offset
);
488 if (gpio_base
> ASIC3_GPIO_D_BASE
) {
489 dev_err(asic
->dev
, "Invalid base (0x%x) for gpio %d\n",
494 return asic3_read_register(asic
, gpio_base
+ ASIC3_GPIO_STATUS
) & mask
;
497 static void asic3_gpio_set(struct gpio_chip
*chip
,
498 unsigned offset
, int value
)
501 unsigned int gpio_base
;
505 asic
= container_of(chip
, struct asic3
, gpio
);
506 gpio_base
= ASIC3_GPIO_TO_BASE(offset
);
508 if (gpio_base
> ASIC3_GPIO_D_BASE
) {
509 dev_err(asic
->dev
, "Invalid base (0x%x) for gpio %d\n",
514 mask
= ASIC3_GPIO_TO_MASK(offset
);
516 spin_lock_irqsave(&asic
->lock
, flags
);
518 out_reg
= asic3_read_register(asic
, gpio_base
+ ASIC3_GPIO_OUT
);
525 asic3_write_register(asic
, gpio_base
+ ASIC3_GPIO_OUT
, out_reg
);
527 spin_unlock_irqrestore(&asic
->lock
, flags
);
532 static __init
int asic3_gpio_probe(struct platform_device
*pdev
,
533 u16
*gpio_config
, int num
)
535 struct asic3
*asic
= platform_get_drvdata(pdev
);
536 u16 alt_reg
[ASIC3_NUM_GPIO_BANKS
];
537 u16 out_reg
[ASIC3_NUM_GPIO_BANKS
];
538 u16 dir_reg
[ASIC3_NUM_GPIO_BANKS
];
541 memset(alt_reg
, 0, ASIC3_NUM_GPIO_BANKS
* sizeof(u16
));
542 memset(out_reg
, 0, ASIC3_NUM_GPIO_BANKS
* sizeof(u16
));
543 memset(dir_reg
, 0, ASIC3_NUM_GPIO_BANKS
* sizeof(u16
));
545 /* Enable all GPIOs */
546 asic3_write_register(asic
, ASIC3_GPIO_OFFSET(A
, MASK
), 0xffff);
547 asic3_write_register(asic
, ASIC3_GPIO_OFFSET(B
, MASK
), 0xffff);
548 asic3_write_register(asic
, ASIC3_GPIO_OFFSET(C
, MASK
), 0xffff);
549 asic3_write_register(asic
, ASIC3_GPIO_OFFSET(D
, MASK
), 0xffff);
551 for (i
= 0; i
< num
; i
++) {
552 u8 alt
, pin
, dir
, init
, bank_num
, bit_num
;
553 u16 config
= gpio_config
[i
];
555 pin
= ASIC3_CONFIG_GPIO_PIN(config
);
556 alt
= ASIC3_CONFIG_GPIO_ALT(config
);
557 dir
= ASIC3_CONFIG_GPIO_DIR(config
);
558 init
= ASIC3_CONFIG_GPIO_INIT(config
);
560 bank_num
= ASIC3_GPIO_TO_BANK(pin
);
561 bit_num
= ASIC3_GPIO_TO_BIT(pin
);
563 alt_reg
[bank_num
] |= (alt
<< bit_num
);
564 out_reg
[bank_num
] |= (init
<< bit_num
);
565 dir_reg
[bank_num
] |= (dir
<< bit_num
);
568 for (i
= 0; i
< ASIC3_NUM_GPIO_BANKS
; i
++) {
569 asic3_write_register(asic
,
570 ASIC3_BANK_TO_BASE(i
) +
571 ASIC3_GPIO_DIRECTION
,
573 asic3_write_register(asic
,
574 ASIC3_BANK_TO_BASE(i
) + ASIC3_GPIO_OUT
,
576 asic3_write_register(asic
,
577 ASIC3_BANK_TO_BASE(i
) +
578 ASIC3_GPIO_ALT_FUNCTION
,
582 return gpiochip_add(&asic
->gpio
);
585 static int asic3_gpio_remove(struct platform_device
*pdev
)
587 struct asic3
*asic
= platform_get_drvdata(pdev
);
589 return gpiochip_remove(&asic
->gpio
);
592 static int asic3_clk_enable(struct asic3
*asic
, struct asic3_clk
*clk
)
597 spin_lock_irqsave(&asic
->lock
, flags
);
598 if (clk
->enabled
++ == 0) {
599 cdex
= asic3_read_register(asic
, ASIC3_OFFSET(CLOCK
, CDEX
));
601 asic3_write_register(asic
, ASIC3_OFFSET(CLOCK
, CDEX
), cdex
);
603 spin_unlock_irqrestore(&asic
->lock
, flags
);
608 static void asic3_clk_disable(struct asic3
*asic
, struct asic3_clk
*clk
)
613 WARN_ON(clk
->enabled
== 0);
615 spin_lock_irqsave(&asic
->lock
, flags
);
616 if (--clk
->enabled
== 0) {
617 cdex
= asic3_read_register(asic
, ASIC3_OFFSET(CLOCK
, CDEX
));
619 asic3_write_register(asic
, ASIC3_OFFSET(CLOCK
, CDEX
), cdex
);
621 spin_unlock_irqrestore(&asic
->lock
, flags
);
624 /* MFD cells (SPI, PWM, LED, DS1WM, MMC) */
625 static struct ds1wm_driver_data ds1wm_pdata
= {
629 static struct resource ds1wm_resources
[] = {
631 .start
= ASIC3_OWM_BASE
,
632 .end
= ASIC3_OWM_BASE
+ 0x13,
633 .flags
= IORESOURCE_MEM
,
636 .start
= ASIC3_IRQ_OWM
,
637 .start
= ASIC3_IRQ_OWM
,
638 .flags
= IORESOURCE_IRQ
| IORESOURCE_IRQ_HIGHEDGE
,
642 static int ds1wm_enable(struct platform_device
*pdev
)
644 struct asic3
*asic
= dev_get_drvdata(pdev
->dev
.parent
);
646 /* Turn on external clocks and the OWM clock */
647 asic3_clk_enable(asic
, &asic
->clocks
[ASIC3_CLOCK_EX0
]);
648 asic3_clk_enable(asic
, &asic
->clocks
[ASIC3_CLOCK_EX1
]);
649 asic3_clk_enable(asic
, &asic
->clocks
[ASIC3_CLOCK_OWM
]);
652 /* Reset and enable DS1WM */
653 asic3_set_register(asic
, ASIC3_OFFSET(EXTCF
, RESET
),
654 ASIC3_EXTCF_OWM_RESET
, 1);
656 asic3_set_register(asic
, ASIC3_OFFSET(EXTCF
, RESET
),
657 ASIC3_EXTCF_OWM_RESET
, 0);
659 asic3_set_register(asic
, ASIC3_OFFSET(EXTCF
, SELECT
),
660 ASIC3_EXTCF_OWM_EN
, 1);
666 static int ds1wm_disable(struct platform_device
*pdev
)
668 struct asic3
*asic
= dev_get_drvdata(pdev
->dev
.parent
);
670 asic3_set_register(asic
, ASIC3_OFFSET(EXTCF
, SELECT
),
671 ASIC3_EXTCF_OWM_EN
, 0);
673 asic3_clk_disable(asic
, &asic
->clocks
[ASIC3_CLOCK_OWM
]);
674 asic3_clk_disable(asic
, &asic
->clocks
[ASIC3_CLOCK_EX0
]);
675 asic3_clk_disable(asic
, &asic
->clocks
[ASIC3_CLOCK_EX1
]);
680 static struct mfd_cell asic3_cell_ds1wm
= {
682 .enable
= ds1wm_enable
,
683 .disable
= ds1wm_disable
,
684 .driver_data
= &ds1wm_pdata
,
685 .num_resources
= ARRAY_SIZE(ds1wm_resources
),
686 .resources
= ds1wm_resources
,
689 static void asic3_mmc_pwr(struct platform_device
*pdev
, int state
)
691 struct asic3
*asic
= dev_get_drvdata(pdev
->dev
.parent
);
693 tmio_core_mmc_pwr(asic
->tmio_cnf
, state
);
696 static void asic3_mmc_clk_div(struct platform_device
*pdev
, int state
)
698 struct asic3
*asic
= dev_get_drvdata(pdev
->dev
.parent
);
700 tmio_core_mmc_clk_div(asic
->tmio_cnf
, state
);
703 static struct tmio_mmc_data asic3_mmc_data
= {
705 .set_pwr
= asic3_mmc_pwr
,
706 .set_no_clk_div
= asic3_mmc_clk_div
,
709 static struct resource asic3_mmc_resources
[] = {
711 .start
= ASIC3_SD_CTRL_BASE
,
712 .end
= ASIC3_SD_CTRL_BASE
+ 0x3ff,
713 .flags
= IORESOURCE_MEM
,
718 .flags
= IORESOURCE_IRQ
,
722 static int asic3_mmc_enable(struct platform_device
*pdev
)
724 struct asic3
*asic
= dev_get_drvdata(pdev
->dev
.parent
);
726 /* Not sure if it must be done bit by bit, but leaving as-is */
727 asic3_set_register(asic
, ASIC3_OFFSET(SDHWCTRL
, SDCONF
),
728 ASIC3_SDHWCTRL_LEVCD
, 1);
729 asic3_set_register(asic
, ASIC3_OFFSET(SDHWCTRL
, SDCONF
),
730 ASIC3_SDHWCTRL_LEVWP
, 1);
731 asic3_set_register(asic
, ASIC3_OFFSET(SDHWCTRL
, SDCONF
),
732 ASIC3_SDHWCTRL_SUSPEND
, 0);
733 asic3_set_register(asic
, ASIC3_OFFSET(SDHWCTRL
, SDCONF
),
734 ASIC3_SDHWCTRL_PCLR
, 0);
736 asic3_clk_enable(asic
, &asic
->clocks
[ASIC3_CLOCK_EX0
]);
737 /* CLK32 used for card detection and for interruption detection
738 * when HCLK is stopped.
740 asic3_clk_enable(asic
, &asic
->clocks
[ASIC3_CLOCK_EX1
]);
743 /* HCLK 24.576 MHz, BCLK 12.288 MHz: */
744 asic3_write_register(asic
, ASIC3_OFFSET(CLOCK
, SEL
),
745 CLOCK_SEL_CX
| CLOCK_SEL_SD_HCLK_SEL
);
747 asic3_clk_enable(asic
, &asic
->clocks
[ASIC3_CLOCK_SD_HOST
]);
748 asic3_clk_enable(asic
, &asic
->clocks
[ASIC3_CLOCK_SD_BUS
]);
751 asic3_set_register(asic
, ASIC3_OFFSET(EXTCF
, SELECT
),
752 ASIC3_EXTCF_SD_MEM_ENABLE
, 1);
754 /* Enable SD card slot 3.3V power supply */
755 asic3_set_register(asic
, ASIC3_OFFSET(SDHWCTRL
, SDCONF
),
756 ASIC3_SDHWCTRL_SDPWR
, 1);
758 /* ASIC3_SD_CTRL_BASE assumes 32-bit addressing, TMIO is 16-bit */
759 tmio_core_mmc_enable(asic
->tmio_cnf
, ASIC3_SD_CTRL_BASE
>> 1);
764 static int asic3_mmc_disable(struct platform_device
*pdev
)
766 struct asic3
*asic
= dev_get_drvdata(pdev
->dev
.parent
);
768 /* Put in suspend mode */
769 asic3_set_register(asic
, ASIC3_OFFSET(SDHWCTRL
, SDCONF
),
770 ASIC3_SDHWCTRL_SUSPEND
, 1);
773 asic3_clk_disable(asic
, &asic
->clocks
[ASIC3_CLOCK_SD_HOST
]);
774 asic3_clk_disable(asic
, &asic
->clocks
[ASIC3_CLOCK_SD_BUS
]);
775 asic3_clk_disable(asic
, &asic
->clocks
[ASIC3_CLOCK_EX0
]);
776 asic3_clk_disable(asic
, &asic
->clocks
[ASIC3_CLOCK_EX1
]);
780 static struct mfd_cell asic3_cell_mmc
= {
782 .enable
= asic3_mmc_enable
,
783 .disable
= asic3_mmc_disable
,
784 .suspend
= asic3_mmc_disable
,
785 .resume
= asic3_mmc_enable
,
786 .driver_data
= &asic3_mmc_data
,
787 .num_resources
= ARRAY_SIZE(asic3_mmc_resources
),
788 .resources
= asic3_mmc_resources
,
791 static int __init
asic3_mfd_probe(struct platform_device
*pdev
,
792 struct resource
*mem
)
794 struct asic3
*asic
= platform_get_drvdata(pdev
);
795 struct resource
*mem_sdio
;
798 mem_sdio
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
800 dev_dbg(asic
->dev
, "no SDIO MEM resource\n");
802 irq
= platform_get_irq(pdev
, 1);
804 dev_dbg(asic
->dev
, "no SDIO IRQ resource\n");
807 asic3_set_register(asic
, ASIC3_OFFSET(EXTCF
, SELECT
),
808 ASIC3_EXTCF_OWM_SMB
, 0);
810 ds1wm_resources
[0].start
>>= asic
->bus_shift
;
811 ds1wm_resources
[0].end
>>= asic
->bus_shift
;
813 asic3_cell_ds1wm
.platform_data
= &asic3_cell_ds1wm
;
814 asic3_cell_ds1wm
.data_size
= sizeof(asic3_cell_ds1wm
);
817 asic
->tmio_cnf
= ioremap((ASIC3_SD_CONFIG_BASE
>> asic
->bus_shift
) +
818 mem_sdio
->start
, 0x400 >> asic
->bus_shift
);
819 if (!asic
->tmio_cnf
) {
821 dev_dbg(asic
->dev
, "Couldn't ioremap SD_CONFIG\n");
824 asic3_mmc_resources
[0].start
>>= asic
->bus_shift
;
825 asic3_mmc_resources
[0].end
>>= asic
->bus_shift
;
827 asic3_cell_mmc
.platform_data
= &asic3_cell_mmc
;
828 asic3_cell_mmc
.data_size
= sizeof(asic3_cell_mmc
);
830 tmio_core_set_bus_shift(1 - asic
->bus_shift
);
832 ret
= mfd_add_devices(&pdev
->dev
, pdev
->id
,
833 &asic3_cell_ds1wm
, 1, mem
, asic
->irq_base
);
837 if (mem_sdio
&& (irq
>= 0))
838 ret
= mfd_add_devices(&pdev
->dev
, pdev
->id
,
839 &asic3_cell_mmc
, 1, mem_sdio
, irq
);
845 static void asic3_mfd_remove(struct platform_device
*pdev
)
847 struct asic3
*asic
= platform_get_drvdata(pdev
);
849 mfd_remove_devices(&pdev
->dev
);
850 iounmap(asic
->tmio_cnf
);
854 static int __init
asic3_probe(struct platform_device
*pdev
)
856 struct asic3_platform_data
*pdata
= pdev
->dev
.platform_data
;
858 struct resource
*mem
;
859 unsigned long clksel
;
862 asic
= kzalloc(sizeof(struct asic3
), GFP_KERNEL
);
864 printk(KERN_ERR
"kzalloc failed\n");
868 spin_lock_init(&asic
->lock
);
869 platform_set_drvdata(pdev
, asic
);
870 asic
->dev
= &pdev
->dev
;
872 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
875 dev_err(asic
->dev
, "no MEM resource\n");
879 asic
->mapping
= ioremap(mem
->start
, resource_size(mem
));
880 if (!asic
->mapping
) {
882 dev_err(asic
->dev
, "Couldn't ioremap\n");
886 asic
->irq_base
= pdata
->irq_base
;
888 /* calculate bus shift from mem resource */
889 asic
->bus_shift
= 2 - (resource_size(mem
) >> 12);
892 asic3_write_register(asic
, ASIC3_OFFSET(CLOCK
, SEL
), clksel
);
894 ret
= asic3_irq_probe(pdev
);
896 dev_err(asic
->dev
, "Couldn't probe IRQs\n");
900 asic
->gpio
.base
= pdata
->gpio_base
;
901 asic
->gpio
.ngpio
= ASIC3_NUM_GPIOS
;
902 asic
->gpio
.get
= asic3_gpio_get
;
903 asic
->gpio
.set
= asic3_gpio_set
;
904 asic
->gpio
.direction_input
= asic3_gpio_direction_input
;
905 asic
->gpio
.direction_output
= asic3_gpio_direction_output
;
907 ret
= asic3_gpio_probe(pdev
,
909 pdata
->gpio_config_num
);
911 dev_err(asic
->dev
, "GPIO probe failed\n");
915 /* Making a per-device copy is only needed for the
916 * theoretical case of multiple ASIC3s on one board:
918 memcpy(asic
->clocks
, asic3_clk_init
, sizeof(asic3_clk_init
));
920 asic3_mfd_probe(pdev
, mem
);
922 dev_info(asic
->dev
, "ASIC3 Core driver\n");
927 asic3_irq_remove(pdev
);
930 iounmap(asic
->mapping
);
938 static int __devexit
asic3_remove(struct platform_device
*pdev
)
941 struct asic3
*asic
= platform_get_drvdata(pdev
);
943 asic3_mfd_remove(pdev
);
945 ret
= asic3_gpio_remove(pdev
);
948 asic3_irq_remove(pdev
);
950 asic3_write_register(asic
, ASIC3_OFFSET(CLOCK
, SEL
), 0);
952 iounmap(asic
->mapping
);
959 static void asic3_shutdown(struct platform_device
*pdev
)
963 static struct platform_driver asic3_device_driver
= {
967 .remove
= __devexit_p(asic3_remove
),
968 .shutdown
= asic3_shutdown
,
971 static int __init
asic3_init(void)
974 retval
= platform_driver_probe(&asic3_device_driver
, asic3_probe
);
978 subsys_initcall(asic3_init
);