4 * Copyright (C) 2007-2012 ST-Ericsson AB
5 * License terms: GNU General Public License (GPL) version 2
6 * COH 901 571/3 - Used in DB3210 (U365 2.0) and DB3350 (U335 1.0)
7 * Author: Linus Walleij <linus.walleij@linaro.org>
8 * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
10 #include <linux/module.h>
11 #include <linux/irq.h>
12 #include <linux/interrupt.h>
13 #include <linux/delay.h>
14 #include <linux/errno.h>
16 #include <linux/irqdomain.h>
17 #include <linux/clk.h>
18 #include <linux/err.h>
19 #include <linux/platform_device.h>
20 #include <linux/gpio.h>
21 #include <linux/list.h>
22 #include <linux/slab.h>
23 #include <linux/pinctrl/consumer.h>
24 #include <linux/pinctrl/pinconf-generic.h>
25 #include "pinctrl-coh901.h"
27 #define U300_GPIO_PORT_STRIDE (0x30)
29 * Control Register 32bit (R/W)
30 * bit 15-9 (mask 0x0000FE00) contains the number of cores. 8*cores
31 * gives the number of GPIO pins.
32 * bit 8-2 (mask 0x000001FC) contains the core version ID.
34 #define U300_GPIO_CR (0x00)
35 #define U300_GPIO_CR_SYNC_SEL_ENABLE (0x00000002UL)
36 #define U300_GPIO_CR_BLOCK_CLKRQ_ENABLE (0x00000001UL)
37 #define U300_GPIO_PXPDIR (0x04)
38 #define U300_GPIO_PXPDOR (0x08)
39 #define U300_GPIO_PXPCR (0x0C)
40 #define U300_GPIO_PXPCR_ALL_PINS_MODE_MASK (0x0000FFFFUL)
41 #define U300_GPIO_PXPCR_PIN_MODE_MASK (0x00000003UL)
42 #define U300_GPIO_PXPCR_PIN_MODE_SHIFT (0x00000002UL)
43 #define U300_GPIO_PXPCR_PIN_MODE_INPUT (0x00000000UL)
44 #define U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL (0x00000001UL)
45 #define U300_GPIO_PXPCR_PIN_MODE_OUTPUT_OPEN_DRAIN (0x00000002UL)
46 #define U300_GPIO_PXPCR_PIN_MODE_OUTPUT_OPEN_SOURCE (0x00000003UL)
47 #define U300_GPIO_PXPER (0x10)
48 #define U300_GPIO_PXPER_ALL_PULL_UP_DISABLE_MASK (0x000000FFUL)
49 #define U300_GPIO_PXPER_PULL_UP_DISABLE (0x00000001UL)
50 #define U300_GPIO_PXIEV (0x14)
51 #define U300_GPIO_PXIEN (0x18)
52 #define U300_GPIO_PXIFR (0x1C)
53 #define U300_GPIO_PXICR (0x20)
54 #define U300_GPIO_PXICR_ALL_IRQ_CONFIG_MASK (0x000000FFUL)
55 #define U300_GPIO_PXICR_IRQ_CONFIG_MASK (0x00000001UL)
56 #define U300_GPIO_PXICR_IRQ_CONFIG_FALLING_EDGE (0x00000000UL)
57 #define U300_GPIO_PXICR_IRQ_CONFIG_RISING_EDGE (0x00000001UL)
59 /* 8 bits per port, no version has more than 7 ports */
60 #define U300_GPIO_NUM_PORTS 7
61 #define U300_GPIO_PINS_PER_PORT 8
62 #define U300_GPIO_MAX (U300_GPIO_PINS_PER_PORT * U300_GPIO_NUM_PORTS)
65 struct gpio_chip chip
;
66 struct list_head port_list
;
71 /* Register offsets */
81 struct u300_gpio_port
{
82 struct list_head node
;
83 struct u300_gpio
*gpio
;
85 struct irq_domain
*domain
;
92 * Macro to expand to read a specific register found in the "gpio"
93 * struct. It requires the struct u300_gpio *gpio variable to exist in
94 * its context. It calculates the port offset from the given pin
95 * offset, muliplies by the port stride and adds the register offset
96 * so it provides a pointer to the desired register.
98 #define U300_PIN_REG(pin, reg) \
99 (gpio->base + (pin >> 3) * gpio->stride + gpio->reg)
102 * Provides a bitmask for a specific gpio pin inside an 8-bit GPIO
105 #define U300_PIN_BIT(pin) \
108 struct u300_gpio_confdata
{
114 #define U300_FLOATING_INPUT { \
115 .bias_mode = PIN_CONFIG_BIAS_HIGH_IMPEDANCE, \
119 #define U300_PULL_UP_INPUT { \
120 .bias_mode = PIN_CONFIG_BIAS_PULL_UP, \
124 #define U300_OUTPUT_LOW { \
129 #define U300_OUTPUT_HIGH { \
134 /* Initial configuration */
135 static const struct __initconst u300_gpio_confdata
136 bs335_gpio_config
[U300_GPIO_NUM_PORTS
][U300_GPIO_PINS_PER_PORT
] = {
137 /* Port 0, pins 0-7 */
148 /* Port 1, pins 0-7 */
159 /* Port 2, pins 0-7 */
170 /* Port 3, pins 0-7 */
181 /* Port 4, pins 0-7 */
192 /* Port 5, pins 0-7 */
203 /* Port 6, pind 0-7 */
217 * to_u300_gpio() - get the pointer to u300_gpio
218 * @chip: the gpio chip member of the structure u300_gpio
220 static inline struct u300_gpio
*to_u300_gpio(struct gpio_chip
*chip
)
222 return container_of(chip
, struct u300_gpio
, chip
);
225 static int u300_gpio_request(struct gpio_chip
*chip
, unsigned offset
)
228 * Map back to global GPIO space and request muxing, the direction
229 * parameter does not matter for this controller.
231 int gpio
= chip
->base
+ offset
;
233 return pinctrl_request_gpio(gpio
);
236 static void u300_gpio_free(struct gpio_chip
*chip
, unsigned offset
)
238 int gpio
= chip
->base
+ offset
;
240 pinctrl_free_gpio(gpio
);
243 static int u300_gpio_get(struct gpio_chip
*chip
, unsigned offset
)
245 struct u300_gpio
*gpio
= to_u300_gpio(chip
);
247 return readl(U300_PIN_REG(offset
, dir
)) & U300_PIN_BIT(offset
);
250 static void u300_gpio_set(struct gpio_chip
*chip
, unsigned offset
, int value
)
252 struct u300_gpio
*gpio
= to_u300_gpio(chip
);
256 local_irq_save(flags
);
258 val
= readl(U300_PIN_REG(offset
, dor
));
260 writel(val
| U300_PIN_BIT(offset
), U300_PIN_REG(offset
, dor
));
262 writel(val
& ~U300_PIN_BIT(offset
), U300_PIN_REG(offset
, dor
));
264 local_irq_restore(flags
);
267 static int u300_gpio_direction_input(struct gpio_chip
*chip
, unsigned offset
)
269 struct u300_gpio
*gpio
= to_u300_gpio(chip
);
273 local_irq_save(flags
);
274 val
= readl(U300_PIN_REG(offset
, pcr
));
275 /* Mask out this pin, note 2 bits per setting */
276 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<< ((offset
& 0x07) << 1));
277 writel(val
, U300_PIN_REG(offset
, pcr
));
278 local_irq_restore(flags
);
282 static int u300_gpio_direction_output(struct gpio_chip
*chip
, unsigned offset
,
285 struct u300_gpio
*gpio
= to_u300_gpio(chip
);
290 local_irq_save(flags
);
291 val
= readl(U300_PIN_REG(offset
, pcr
));
293 * Drive mode must be set by the special mode set function, set
294 * push/pull mode by default if no mode has been selected.
296 oldmode
= val
& (U300_GPIO_PXPCR_PIN_MODE_MASK
<<
297 ((offset
& 0x07) << 1));
298 /* mode = 0 means input, else some mode is already set */
300 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
<<
301 ((offset
& 0x07) << 1));
302 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL
303 << ((offset
& 0x07) << 1));
304 writel(val
, U300_PIN_REG(offset
, pcr
));
306 u300_gpio_set(chip
, offset
, value
);
307 local_irq_restore(flags
);
311 static int u300_gpio_to_irq(struct gpio_chip
*chip
, unsigned offset
)
313 struct u300_gpio
*gpio
= to_u300_gpio(chip
);
314 int portno
= offset
>> 3;
315 struct u300_gpio_port
*port
= NULL
;
320 list_for_each(p
, &gpio
->port_list
) {
321 port
= list_entry(p
, struct u300_gpio_port
, node
);
322 if (port
->number
== portno
) {
328 dev_err(gpio
->dev
, "could not locate port for GPIO %d IRQ\n",
334 * The local hwirqs on the port are the lower three bits, there
335 * are exactly 8 IRQs per port since they are 8-bit
337 retirq
= irq_find_mapping(port
->domain
, (offset
& 0x7));
339 dev_dbg(gpio
->dev
, "request IRQ for GPIO %d, return %d from port %d\n",
340 offset
, retirq
, port
->number
);
344 /* Returning -EINVAL means "supported but not available" */
345 int u300_gpio_config_get(struct gpio_chip
*chip
,
347 unsigned long *config
)
349 struct u300_gpio
*gpio
= to_u300_gpio(chip
);
350 enum pin_config_param param
= (enum pin_config_param
) *config
;
354 /* One bit per pin, clamp to bool range */
355 biasmode
= !!(readl(U300_PIN_REG(offset
, per
)) & U300_PIN_BIT(offset
));
357 /* Mask out the two bits for this pin and shift to bits 0,1 */
358 drmode
= readl(U300_PIN_REG(offset
, pcr
));
359 drmode
&= (U300_GPIO_PXPCR_PIN_MODE_MASK
<< ((offset
& 0x07) << 1));
360 drmode
>>= ((offset
& 0x07) << 1);
363 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
370 case PIN_CONFIG_BIAS_PULL_UP
:
377 case PIN_CONFIG_DRIVE_PUSH_PULL
:
379 if (drmode
== U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL
)
384 case PIN_CONFIG_DRIVE_OPEN_DRAIN
:
386 if (drmode
== U300_GPIO_PXPCR_PIN_MODE_OUTPUT_OPEN_DRAIN
)
391 case PIN_CONFIG_DRIVE_OPEN_SOURCE
:
393 if (drmode
== U300_GPIO_PXPCR_PIN_MODE_OUTPUT_OPEN_SOURCE
)
404 int u300_gpio_config_set(struct gpio_chip
*chip
, unsigned offset
,
405 enum pin_config_param param
)
407 struct u300_gpio
*gpio
= to_u300_gpio(chip
);
411 local_irq_save(flags
);
413 case PIN_CONFIG_BIAS_DISABLE
:
414 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE
:
415 val
= readl(U300_PIN_REG(offset
, per
));
416 writel(val
| U300_PIN_BIT(offset
), U300_PIN_REG(offset
, per
));
418 case PIN_CONFIG_BIAS_PULL_UP
:
419 val
= readl(U300_PIN_REG(offset
, per
));
420 writel(val
& ~U300_PIN_BIT(offset
), U300_PIN_REG(offset
, per
));
422 case PIN_CONFIG_DRIVE_PUSH_PULL
:
423 val
= readl(U300_PIN_REG(offset
, pcr
));
424 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
425 << ((offset
& 0x07) << 1));
426 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_PUSH_PULL
427 << ((offset
& 0x07) << 1));
428 writel(val
, U300_PIN_REG(offset
, pcr
));
430 case PIN_CONFIG_DRIVE_OPEN_DRAIN
:
431 val
= readl(U300_PIN_REG(offset
, pcr
));
432 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
433 << ((offset
& 0x07) << 1));
434 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_OPEN_DRAIN
435 << ((offset
& 0x07) << 1));
436 writel(val
, U300_PIN_REG(offset
, pcr
));
438 case PIN_CONFIG_DRIVE_OPEN_SOURCE
:
439 val
= readl(U300_PIN_REG(offset
, pcr
));
440 val
&= ~(U300_GPIO_PXPCR_PIN_MODE_MASK
441 << ((offset
& 0x07) << 1));
442 val
|= (U300_GPIO_PXPCR_PIN_MODE_OUTPUT_OPEN_SOURCE
443 << ((offset
& 0x07) << 1));
444 writel(val
, U300_PIN_REG(offset
, pcr
));
447 local_irq_restore(flags
);
448 dev_err(gpio
->dev
, "illegal configuration requested\n");
451 local_irq_restore(flags
);
455 static struct gpio_chip u300_gpio_chip
= {
456 .label
= "u300-gpio-chip",
457 .owner
= THIS_MODULE
,
458 .request
= u300_gpio_request
,
459 .free
= u300_gpio_free
,
460 .get
= u300_gpio_get
,
461 .set
= u300_gpio_set
,
462 .direction_input
= u300_gpio_direction_input
,
463 .direction_output
= u300_gpio_direction_output
,
464 .to_irq
= u300_gpio_to_irq
,
467 static void u300_toggle_trigger(struct u300_gpio
*gpio
, unsigned offset
)
471 val
= readl(U300_PIN_REG(offset
, icr
));
472 /* Set mode depending on state */
473 if (u300_gpio_get(&gpio
->chip
, offset
)) {
474 /* High now, let's trigger on falling edge next then */
475 writel(val
& ~U300_PIN_BIT(offset
), U300_PIN_REG(offset
, icr
));
476 dev_dbg(gpio
->dev
, "next IRQ on falling edge on pin %d\n",
479 /* Low now, let's trigger on rising edge next then */
480 writel(val
| U300_PIN_BIT(offset
), U300_PIN_REG(offset
, icr
));
481 dev_dbg(gpio
->dev
, "next IRQ on rising edge on pin %d\n",
486 static int u300_gpio_irq_type(struct irq_data
*d
, unsigned trigger
)
488 struct u300_gpio_port
*port
= irq_data_get_irq_chip_data(d
);
489 struct u300_gpio
*gpio
= port
->gpio
;
490 int offset
= (port
->number
<< 3) + d
->hwirq
;
493 if ((trigger
& IRQF_TRIGGER_RISING
) &&
494 (trigger
& IRQF_TRIGGER_FALLING
)) {
496 * The GPIO block can only trigger on falling OR rising edges,
497 * not both. So we need to toggle the mode whenever the pin
498 * goes from one state to the other with a special state flag
501 "trigger on both rising and falling edge on pin %d\n",
503 port
->toggle_edge_mode
|= U300_PIN_BIT(offset
);
504 u300_toggle_trigger(gpio
, offset
);
505 } else if (trigger
& IRQF_TRIGGER_RISING
) {
506 dev_dbg(gpio
->dev
, "trigger on rising edge on pin %d\n",
508 val
= readl(U300_PIN_REG(offset
, icr
));
509 writel(val
| U300_PIN_BIT(offset
), U300_PIN_REG(offset
, icr
));
510 port
->toggle_edge_mode
&= ~U300_PIN_BIT(offset
);
511 } else if (trigger
& IRQF_TRIGGER_FALLING
) {
512 dev_dbg(gpio
->dev
, "trigger on falling edge on pin %d\n",
514 val
= readl(U300_PIN_REG(offset
, icr
));
515 writel(val
& ~U300_PIN_BIT(offset
), U300_PIN_REG(offset
, icr
));
516 port
->toggle_edge_mode
&= ~U300_PIN_BIT(offset
);
522 static void u300_gpio_irq_enable(struct irq_data
*d
)
524 struct u300_gpio_port
*port
= irq_data_get_irq_chip_data(d
);
525 struct u300_gpio
*gpio
= port
->gpio
;
526 int offset
= (port
->number
<< 3) + d
->hwirq
;
530 dev_dbg(gpio
->dev
, "enable IRQ for hwirq %lu on port %s, offset %d\n",
531 d
->hwirq
, port
->name
, offset
);
532 if (gpio_lock_as_irq(&gpio
->chip
, d
->hwirq
))
534 "unable to lock HW IRQ %lu for IRQ\n",
536 local_irq_save(flags
);
537 val
= readl(U300_PIN_REG(offset
, ien
));
538 writel(val
| U300_PIN_BIT(offset
), U300_PIN_REG(offset
, ien
));
539 local_irq_restore(flags
);
542 static void u300_gpio_irq_disable(struct irq_data
*d
)
544 struct u300_gpio_port
*port
= irq_data_get_irq_chip_data(d
);
545 struct u300_gpio
*gpio
= port
->gpio
;
546 int offset
= (port
->number
<< 3) + d
->hwirq
;
550 local_irq_save(flags
);
551 val
= readl(U300_PIN_REG(offset
, ien
));
552 writel(val
& ~U300_PIN_BIT(offset
), U300_PIN_REG(offset
, ien
));
553 local_irq_restore(flags
);
554 gpio_unlock_as_irq(&gpio
->chip
, d
->hwirq
);
557 static struct irq_chip u300_gpio_irqchip
= {
558 .name
= "u300-gpio-irqchip",
559 .irq_enable
= u300_gpio_irq_enable
,
560 .irq_disable
= u300_gpio_irq_disable
,
561 .irq_set_type
= u300_gpio_irq_type
,
565 static void u300_gpio_irq_handler(unsigned irq
, struct irq_desc
*desc
)
567 struct u300_gpio_port
*port
= irq_get_handler_data(irq
);
568 struct u300_gpio
*gpio
= port
->gpio
;
569 int pinoffset
= port
->number
<< 3; /* get the right stride */
572 desc
->irq_data
.chip
->irq_ack(&desc
->irq_data
);
573 /* Read event register */
574 val
= readl(U300_PIN_REG(pinoffset
, iev
));
575 /* Mask relevant bits */
576 val
&= 0xFFU
; /* 8 bits per port */
577 /* ACK IRQ (clear event) */
578 writel(val
, U300_PIN_REG(pinoffset
, iev
));
580 /* Call IRQ handler */
584 for_each_set_bit(irqoffset
, &val
, U300_GPIO_PINS_PER_PORT
) {
585 int pin_irq
= irq_find_mapping(port
->domain
, irqoffset
);
586 int offset
= pinoffset
+ irqoffset
;
588 dev_dbg(gpio
->dev
, "GPIO IRQ %d on pin %d\n",
590 generic_handle_irq(pin_irq
);
592 * Triggering IRQ on both rising and falling edge
595 if (port
->toggle_edge_mode
& U300_PIN_BIT(offset
))
596 u300_toggle_trigger(gpio
, offset
);
600 desc
->irq_data
.chip
->irq_unmask(&desc
->irq_data
);
603 static void __init
u300_gpio_init_pin(struct u300_gpio
*gpio
,
605 const struct u300_gpio_confdata
*conf
)
607 /* Set mode: input or output */
609 u300_gpio_direction_output(&gpio
->chip
, offset
, conf
->outval
);
611 /* Deactivate bias mode for output */
612 u300_gpio_config_set(&gpio
->chip
, offset
,
613 PIN_CONFIG_BIAS_HIGH_IMPEDANCE
);
615 /* Set drive mode for output */
616 u300_gpio_config_set(&gpio
->chip
, offset
,
617 PIN_CONFIG_DRIVE_PUSH_PULL
);
619 dev_dbg(gpio
->dev
, "set up pin %d as output, value: %d\n",
620 offset
, conf
->outval
);
622 u300_gpio_direction_input(&gpio
->chip
, offset
);
624 /* Always set output low on input pins */
625 u300_gpio_set(&gpio
->chip
, offset
, 0);
627 /* Set bias mode for input */
628 u300_gpio_config_set(&gpio
->chip
, offset
, conf
->bias_mode
);
630 dev_dbg(gpio
->dev
, "set up pin %d as input, bias: %04x\n",
631 offset
, conf
->bias_mode
);
635 static void __init
u300_gpio_init_coh901571(struct u300_gpio
*gpio
)
639 /* Write default config and values to all pins */
640 for (i
= 0; i
< U300_GPIO_NUM_PORTS
; i
++) {
641 for (j
= 0; j
< 8; j
++) {
642 const struct u300_gpio_confdata
*conf
;
643 int offset
= (i
*8) + j
;
645 conf
= &bs335_gpio_config
[i
][j
];
646 u300_gpio_init_pin(gpio
, offset
, conf
);
651 static inline void u300_gpio_free_ports(struct u300_gpio
*gpio
)
653 struct u300_gpio_port
*port
;
654 struct list_head
*p
, *n
;
656 list_for_each_safe(p
, n
, &gpio
->port_list
) {
657 port
= list_entry(p
, struct u300_gpio_port
, node
);
658 list_del(&port
->node
);
660 irq_domain_remove(port
->domain
);
666 * Here we map a GPIO in the local gpio_chip pin space to a pin in
667 * the local pinctrl pin space. The pin controller used is
670 struct coh901_pinpair
{
672 unsigned int pin_base
;
675 #define COH901_PINRANGE(a, b) { .offset = a, .pin_base = b }
677 static struct coh901_pinpair coh901_pintable
[] = {
678 COH901_PINRANGE(10, 426),
679 COH901_PINRANGE(11, 180),
680 COH901_PINRANGE(12, 165), /* MS/MMC card insertion */
681 COH901_PINRANGE(13, 179),
682 COH901_PINRANGE(14, 178),
683 COH901_PINRANGE(16, 194),
684 COH901_PINRANGE(17, 193),
685 COH901_PINRANGE(18, 192),
686 COH901_PINRANGE(19, 191),
687 COH901_PINRANGE(20, 186),
688 COH901_PINRANGE(21, 185),
689 COH901_PINRANGE(22, 184),
690 COH901_PINRANGE(23, 183),
691 COH901_PINRANGE(24, 182),
692 COH901_PINRANGE(25, 181),
695 static int __init
u300_gpio_probe(struct platform_device
*pdev
)
697 struct u300_gpio
*gpio
;
698 struct resource
*memres
;
705 gpio
= devm_kzalloc(&pdev
->dev
, sizeof(struct u300_gpio
), GFP_KERNEL
);
709 gpio
->chip
= u300_gpio_chip
;
710 gpio
->chip
.ngpio
= U300_GPIO_NUM_PORTS
* U300_GPIO_PINS_PER_PORT
;
711 gpio
->chip
.dev
= &pdev
->dev
;
713 gpio
->dev
= &pdev
->dev
;
715 memres
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
716 gpio
->base
= devm_ioremap_resource(&pdev
->dev
, memres
);
717 if (IS_ERR(gpio
->base
))
718 return PTR_ERR(gpio
->base
);
720 gpio
->clk
= devm_clk_get(gpio
->dev
, NULL
);
721 if (IS_ERR(gpio
->clk
)) {
722 err
= PTR_ERR(gpio
->clk
);
723 dev_err(gpio
->dev
, "could not get GPIO clock\n");
727 err
= clk_prepare_enable(gpio
->clk
);
729 dev_err(gpio
->dev
, "could not enable GPIO clock\n");
734 "initializing GPIO Controller COH 901 571/3\n");
735 gpio
->stride
= U300_GPIO_PORT_STRIDE
;
736 gpio
->pcr
= U300_GPIO_PXPCR
;
737 gpio
->dor
= U300_GPIO_PXPDOR
;
738 gpio
->dir
= U300_GPIO_PXPDIR
;
739 gpio
->per
= U300_GPIO_PXPER
;
740 gpio
->icr
= U300_GPIO_PXICR
;
741 gpio
->ien
= U300_GPIO_PXIEN
;
742 gpio
->iev
= U300_GPIO_PXIEV
;
743 ifr
= U300_GPIO_PXIFR
;
745 val
= readl(gpio
->base
+ U300_GPIO_CR
);
746 dev_info(gpio
->dev
, "COH901571/3 block version: %d, " \
747 "number of cores: %d totalling %d pins\n",
748 ((val
& 0x000001FC) >> 2),
749 ((val
& 0x0000FE00) >> 9),
750 ((val
& 0x0000FE00) >> 9) * 8);
751 writel(U300_GPIO_CR_BLOCK_CLKRQ_ENABLE
,
752 gpio
->base
+ U300_GPIO_CR
);
753 u300_gpio_init_coh901571(gpio
);
755 /* Add each port with its IRQ separately */
756 INIT_LIST_HEAD(&gpio
->port_list
);
757 for (portno
= 0 ; portno
< U300_GPIO_NUM_PORTS
; portno
++) {
758 struct u300_gpio_port
*port
=
759 kmalloc(sizeof(struct u300_gpio_port
), GFP_KERNEL
);
762 dev_err(gpio
->dev
, "out of memory\n");
767 snprintf(port
->name
, 8, "gpio%d", portno
);
768 port
->number
= portno
;
771 port
->irq
= platform_get_irq(pdev
, portno
);
773 dev_dbg(gpio
->dev
, "register IRQ %d for port %s\n", port
->irq
,
776 port
->domain
= irq_domain_add_linear(pdev
->dev
.of_node
,
777 U300_GPIO_PINS_PER_PORT
,
778 &irq_domain_simple_ops
,
785 irq_set_chained_handler(port
->irq
, u300_gpio_irq_handler
);
786 irq_set_handler_data(port
->irq
, port
);
788 /* For each GPIO pin set the unique IRQ handler */
789 for (i
= 0; i
< U300_GPIO_PINS_PER_PORT
; i
++) {
790 int irqno
= irq_create_mapping(port
->domain
, i
);
792 dev_dbg(gpio
->dev
, "GPIO%d on port %s gets IRQ %d\n",
793 gpio
->chip
.base
+ (port
->number
<< 3) + i
,
795 irq_set_chip_and_handler(irqno
, &u300_gpio_irqchip
,
797 set_irq_flags(irqno
, IRQF_VALID
);
798 irq_set_chip_data(irqno
, port
);
801 /* Turns off irq force (test register) for this port */
802 writel(0x0, gpio
->base
+ portno
* gpio
->stride
+ ifr
);
804 list_add_tail(&port
->node
, &gpio
->port_list
);
806 dev_dbg(gpio
->dev
, "initialized %d GPIO ports\n", portno
);
808 #ifdef CONFIG_OF_GPIO
809 gpio
->chip
.of_node
= pdev
->dev
.of_node
;
811 err
= gpiochip_add(&gpio
->chip
);
813 dev_err(gpio
->dev
, "unable to add gpiochip: %d\n", err
);
818 * Add pinctrl pin ranges, the pin controller must be registered
821 for (i
= 0; i
< ARRAY_SIZE(coh901_pintable
); i
++) {
822 struct coh901_pinpair
*p
= &coh901_pintable
[i
];
824 err
= gpiochip_add_pin_range(&gpio
->chip
, "pinctrl-u300",
825 p
->offset
, p
->pin_base
, 1);
830 platform_set_drvdata(pdev
, gpio
);
835 if (gpiochip_remove(&gpio
->chip
))
836 dev_err(&pdev
->dev
, "failed to remove gpio chip\n");
840 u300_gpio_free_ports(gpio
);
841 clk_disable_unprepare(gpio
->clk
);
842 dev_err(&pdev
->dev
, "module ERROR:%d\n", err
);
846 static int __exit
u300_gpio_remove(struct platform_device
*pdev
)
848 struct u300_gpio
*gpio
= platform_get_drvdata(pdev
);
851 /* Turn off the GPIO block */
852 writel(0x00000000U
, gpio
->base
+ U300_GPIO_CR
);
854 err
= gpiochip_remove(&gpio
->chip
);
856 dev_err(gpio
->dev
, "unable to remove gpiochip: %d\n", err
);
859 u300_gpio_free_ports(gpio
);
860 clk_disable_unprepare(gpio
->clk
);
864 static const struct of_device_id u300_gpio_match
[] = {
865 { .compatible
= "stericsson,gpio-coh901" },
869 static struct platform_driver u300_gpio_driver
= {
872 .of_match_table
= u300_gpio_match
,
874 .remove
= __exit_p(u300_gpio_remove
),
877 static int __init
u300_gpio_init(void)
879 return platform_driver_probe(&u300_gpio_driver
, u300_gpio_probe
);
882 static void __exit
u300_gpio_exit(void)
884 platform_driver_unregister(&u300_gpio_driver
);
887 arch_initcall(u300_gpio_init
);
888 module_exit(u300_gpio_exit
);
890 MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
891 MODULE_DESCRIPTION("ST-Ericsson AB COH 901 335/COH 901 571/3 GPIO driver");
892 MODULE_LICENSE("GPL");