2 * Copyright (C) 2014-2017 Broadcom
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 * This file contains the Broadcom Iproc GPIO driver that supports 3
16 * GPIO controllers on Iproc including the ASIU GPIO controller, the
17 * chipCommonG GPIO controller, and the always-on GPIO controller. Basic
18 * PINCONF such as bias pull up/down, and drive strength are also supported
21 * It provides the functionality where pins from the GPIO can be
22 * individually muxed to GPIO function, if individual pad
23 * configuration is supported, through the interaction with respective
24 * SoCs IOMUX controller.
27 #include <linux/kernel.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
31 #include <linux/gpio/driver.h>
32 #include <linux/ioport.h>
33 #include <linux/of_device.h>
34 #include <linux/of_irq.h>
35 #include <linux/pinctrl/pinctrl.h>
36 #include <linux/pinctrl/pinconf.h>
37 #include <linux/pinctrl/pinconf-generic.h>
39 #include "../pinctrl-utils.h"
41 #define IPROC_GPIO_DATA_IN_OFFSET 0x00
42 #define IPROC_GPIO_DATA_OUT_OFFSET 0x04
43 #define IPROC_GPIO_OUT_EN_OFFSET 0x08
44 #define IPROC_GPIO_INT_TYPE_OFFSET 0x0c
45 #define IPROC_GPIO_INT_DE_OFFSET 0x10
46 #define IPROC_GPIO_INT_EDGE_OFFSET 0x14
47 #define IPROC_GPIO_INT_MSK_OFFSET 0x18
48 #define IPROC_GPIO_INT_STAT_OFFSET 0x1c
49 #define IPROC_GPIO_INT_MSTAT_OFFSET 0x20
50 #define IPROC_GPIO_INT_CLR_OFFSET 0x24
51 #define IPROC_GPIO_PAD_RES_OFFSET 0x34
52 #define IPROC_GPIO_RES_EN_OFFSET 0x38
54 /* drive strength control for ASIU GPIO */
55 #define IPROC_GPIO_ASIU_DRV0_CTRL_OFFSET 0x58
57 /* drive strength control for CCM/CRMU (AON) GPIO */
58 #define IPROC_GPIO_DRV0_CTRL_OFFSET 0x00
60 #define GPIO_BANK_SIZE 0x200
61 #define NGPIOS_PER_BANK 32
62 #define GPIO_BANK(pin) ((pin) / NGPIOS_PER_BANK)
64 #define IPROC_GPIO_REG(pin, reg) (GPIO_BANK(pin) * GPIO_BANK_SIZE + (reg))
65 #define IPROC_GPIO_SHIFT(pin) ((pin) % NGPIOS_PER_BANK)
67 #define GPIO_DRV_STRENGTH_BIT_SHIFT 20
68 #define GPIO_DRV_STRENGTH_BITS 3
69 #define GPIO_DRV_STRENGTH_BIT_MASK ((1 << GPIO_DRV_STRENGTH_BITS) - 1)
71 enum iproc_pinconf_param
{
72 IPROC_PINCONF_DRIVE_STRENGTH
= 0,
73 IPROC_PINCONF_BIAS_DISABLE
,
74 IPROC_PINCONF_BIAS_PULL_UP
,
75 IPROC_PINCONF_BIAS_PULL_DOWN
,
82 * @dev: pointer to device
83 * @base: I/O register base for Iproc GPIO controller
84 * @io_ctrl: I/O register base for certain type of Iproc GPIO controller that
85 * has the PINCONF support implemented outside of the GPIO block
86 * @lock: lock to protect access to I/O registers
88 * @num_banks: number of GPIO banks, each bank supports up to 32 GPIOs
89 * @pinmux_is_supported: flag to indicate this GPIO controller contains pins
90 * that can be individually muxed to GPIO
91 * @pinconf_disable: contains a list of PINCONF parameters that need to be
93 * @nr_pinconf_disable: total number of PINCONF parameters that need to be
95 * @pctl: pointer to pinctrl_dev
96 * @pctldesc: pinctrl descriptor
102 void __iomem
*io_ctrl
;
109 bool pinmux_is_supported
;
111 enum pin_config_param
*pinconf_disable
;
112 unsigned int nr_pinconf_disable
;
114 struct pinctrl_dev
*pctl
;
115 struct pinctrl_desc pctldesc
;
119 * Mapping from PINCONF pins to GPIO pins is 1-to-1
121 static inline unsigned iproc_pin_to_gpio(unsigned pin
)
127 * iproc_set_bit - set or clear one bit (corresponding to the GPIO pin) in a
128 * Iproc GPIO register
130 * @iproc_gpio: Iproc GPIO device
131 * @reg: register offset
135 static inline void iproc_set_bit(struct iproc_gpio
*chip
, unsigned int reg
,
136 unsigned gpio
, bool set
)
138 unsigned int offset
= IPROC_GPIO_REG(gpio
, reg
);
139 unsigned int shift
= IPROC_GPIO_SHIFT(gpio
);
142 val
= readl(chip
->base
+ offset
);
147 writel(val
, chip
->base
+ offset
);
150 static inline bool iproc_get_bit(struct iproc_gpio
*chip
, unsigned int reg
,
153 unsigned int offset
= IPROC_GPIO_REG(gpio
, reg
);
154 unsigned int shift
= IPROC_GPIO_SHIFT(gpio
);
156 return !!(readl(chip
->base
+ offset
) & BIT(shift
));
159 static void iproc_gpio_irq_handler(struct irq_desc
*desc
)
161 struct gpio_chip
*gc
= irq_desc_get_handler_data(desc
);
162 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
163 struct irq_chip
*irq_chip
= irq_desc_get_chip(desc
);
166 chained_irq_enter(irq_chip
, desc
);
168 /* go through the entire GPIO banks and handle all interrupts */
169 for (i
= 0; i
< chip
->num_banks
; i
++) {
170 unsigned long val
= readl(chip
->base
+ (i
* GPIO_BANK_SIZE
) +
171 IPROC_GPIO_INT_MSTAT_OFFSET
);
173 for_each_set_bit(bit
, &val
, NGPIOS_PER_BANK
) {
174 unsigned pin
= NGPIOS_PER_BANK
* i
+ bit
;
175 int child_irq
= irq_find_mapping(gc
->irq
.domain
, pin
);
178 * Clear the interrupt before invoking the
179 * handler, so we do not leave any window
181 writel(BIT(bit
), chip
->base
+ (i
* GPIO_BANK_SIZE
) +
182 IPROC_GPIO_INT_CLR_OFFSET
);
184 generic_handle_irq(child_irq
);
188 chained_irq_exit(irq_chip
, desc
);
192 static void iproc_gpio_irq_ack(struct irq_data
*d
)
194 struct gpio_chip
*gc
= irq_data_get_irq_chip_data(d
);
195 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
196 unsigned gpio
= d
->hwirq
;
197 unsigned int offset
= IPROC_GPIO_REG(gpio
,
198 IPROC_GPIO_INT_CLR_OFFSET
);
199 unsigned int shift
= IPROC_GPIO_SHIFT(gpio
);
200 u32 val
= BIT(shift
);
202 writel(val
, chip
->base
+ offset
);
206 * iproc_gpio_irq_set_mask - mask/unmask a GPIO interrupt
209 * @unmask: mask/unmask GPIO interrupt
211 static void iproc_gpio_irq_set_mask(struct irq_data
*d
, bool unmask
)
213 struct gpio_chip
*gc
= irq_data_get_irq_chip_data(d
);
214 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
215 unsigned gpio
= d
->hwirq
;
217 iproc_set_bit(chip
, IPROC_GPIO_INT_MSK_OFFSET
, gpio
, unmask
);
220 static void iproc_gpio_irq_mask(struct irq_data
*d
)
222 struct gpio_chip
*gc
= irq_data_get_irq_chip_data(d
);
223 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
226 raw_spin_lock_irqsave(&chip
->lock
, flags
);
227 iproc_gpio_irq_set_mask(d
, false);
228 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
231 static void iproc_gpio_irq_unmask(struct irq_data
*d
)
233 struct gpio_chip
*gc
= irq_data_get_irq_chip_data(d
);
234 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
237 raw_spin_lock_irqsave(&chip
->lock
, flags
);
238 iproc_gpio_irq_set_mask(d
, true);
239 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
242 static int iproc_gpio_irq_set_type(struct irq_data
*d
, unsigned int type
)
244 struct gpio_chip
*gc
= irq_data_get_irq_chip_data(d
);
245 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
246 unsigned gpio
= d
->hwirq
;
247 bool level_triggered
= false;
248 bool dual_edge
= false;
249 bool rising_or_high
= false;
252 switch (type
& IRQ_TYPE_SENSE_MASK
) {
253 case IRQ_TYPE_EDGE_RISING
:
254 rising_or_high
= true;
257 case IRQ_TYPE_EDGE_FALLING
:
260 case IRQ_TYPE_EDGE_BOTH
:
264 case IRQ_TYPE_LEVEL_HIGH
:
265 level_triggered
= true;
266 rising_or_high
= true;
269 case IRQ_TYPE_LEVEL_LOW
:
270 level_triggered
= true;
274 dev_err(chip
->dev
, "invalid GPIO IRQ type 0x%x\n",
279 raw_spin_lock_irqsave(&chip
->lock
, flags
);
280 iproc_set_bit(chip
, IPROC_GPIO_INT_TYPE_OFFSET
, gpio
,
282 iproc_set_bit(chip
, IPROC_GPIO_INT_DE_OFFSET
, gpio
, dual_edge
);
283 iproc_set_bit(chip
, IPROC_GPIO_INT_EDGE_OFFSET
, gpio
,
285 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
288 "gpio:%u level_triggered:%d dual_edge:%d rising_or_high:%d\n",
289 gpio
, level_triggered
, dual_edge
, rising_or_high
);
294 static struct irq_chip iproc_gpio_irq_chip
= {
295 .name
= "bcm-iproc-gpio",
296 .irq_ack
= iproc_gpio_irq_ack
,
297 .irq_mask
= iproc_gpio_irq_mask
,
298 .irq_unmask
= iproc_gpio_irq_unmask
,
299 .irq_set_type
= iproc_gpio_irq_set_type
,
303 * Request the Iproc IOMUX pinmux controller to mux individual pins to GPIO
305 static int iproc_gpio_request(struct gpio_chip
*gc
, unsigned offset
)
307 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
308 unsigned gpio
= gc
->base
+ offset
;
310 /* not all Iproc GPIO pins can be muxed individually */
311 if (!chip
->pinmux_is_supported
)
314 return pinctrl_gpio_request(gpio
);
317 static void iproc_gpio_free(struct gpio_chip
*gc
, unsigned offset
)
319 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
320 unsigned gpio
= gc
->base
+ offset
;
322 if (!chip
->pinmux_is_supported
)
325 pinctrl_gpio_free(gpio
);
328 static int iproc_gpio_direction_input(struct gpio_chip
*gc
, unsigned gpio
)
330 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
333 raw_spin_lock_irqsave(&chip
->lock
, flags
);
334 iproc_set_bit(chip
, IPROC_GPIO_OUT_EN_OFFSET
, gpio
, false);
335 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
337 dev_dbg(chip
->dev
, "gpio:%u set input\n", gpio
);
342 static int iproc_gpio_direction_output(struct gpio_chip
*gc
, unsigned gpio
,
345 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
348 raw_spin_lock_irqsave(&chip
->lock
, flags
);
349 iproc_set_bit(chip
, IPROC_GPIO_OUT_EN_OFFSET
, gpio
, true);
350 iproc_set_bit(chip
, IPROC_GPIO_DATA_OUT_OFFSET
, gpio
, !!(val
));
351 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
353 dev_dbg(chip
->dev
, "gpio:%u set output, value:%d\n", gpio
, val
);
358 static void iproc_gpio_set(struct gpio_chip
*gc
, unsigned gpio
, int val
)
360 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
363 raw_spin_lock_irqsave(&chip
->lock
, flags
);
364 iproc_set_bit(chip
, IPROC_GPIO_DATA_OUT_OFFSET
, gpio
, !!(val
));
365 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
367 dev_dbg(chip
->dev
, "gpio:%u set, value:%d\n", gpio
, val
);
370 static int iproc_gpio_get(struct gpio_chip
*gc
, unsigned gpio
)
372 struct iproc_gpio
*chip
= gpiochip_get_data(gc
);
373 unsigned int offset
= IPROC_GPIO_REG(gpio
,
374 IPROC_GPIO_DATA_IN_OFFSET
);
375 unsigned int shift
= IPROC_GPIO_SHIFT(gpio
);
377 return !!(readl(chip
->base
+ offset
) & BIT(shift
));
381 * Mapping of the iProc PINCONF parameters to the generic pin configuration
384 static const enum pin_config_param iproc_pinconf_disable_map
[] = {
385 [IPROC_PINCONF_DRIVE_STRENGTH
] = PIN_CONFIG_DRIVE_STRENGTH
,
386 [IPROC_PINCONF_BIAS_DISABLE
] = PIN_CONFIG_BIAS_DISABLE
,
387 [IPROC_PINCONF_BIAS_PULL_UP
] = PIN_CONFIG_BIAS_PULL_UP
,
388 [IPROC_PINCONF_BIAS_PULL_DOWN
] = PIN_CONFIG_BIAS_PULL_DOWN
,
391 static bool iproc_pinconf_param_is_disabled(struct iproc_gpio
*chip
,
392 enum pin_config_param param
)
396 if (!chip
->nr_pinconf_disable
)
399 for (i
= 0; i
< chip
->nr_pinconf_disable
; i
++)
400 if (chip
->pinconf_disable
[i
] == param
)
406 static int iproc_pinconf_disable_map_create(struct iproc_gpio
*chip
,
407 unsigned long disable_mask
)
409 unsigned int map_size
= ARRAY_SIZE(iproc_pinconf_disable_map
);
410 unsigned int bit
, nbits
= 0;
412 /* figure out total number of PINCONF parameters to disable */
413 for_each_set_bit(bit
, &disable_mask
, map_size
)
420 * Allocate an array to store PINCONF parameters that need to be
423 chip
->pinconf_disable
= devm_kcalloc(chip
->dev
, nbits
,
424 sizeof(*chip
->pinconf_disable
),
426 if (!chip
->pinconf_disable
)
429 chip
->nr_pinconf_disable
= nbits
;
431 /* now store these parameters */
433 for_each_set_bit(bit
, &disable_mask
, map_size
)
434 chip
->pinconf_disable
[nbits
++] = iproc_pinconf_disable_map
[bit
];
439 static int iproc_get_groups_count(struct pinctrl_dev
*pctldev
)
445 * Only one group: "gpio_grp", since this local pinctrl device only performs
446 * GPIO specific PINCONF configurations
448 static const char *iproc_get_group_name(struct pinctrl_dev
*pctldev
,
454 static const struct pinctrl_ops iproc_pctrl_ops
= {
455 .get_groups_count
= iproc_get_groups_count
,
456 .get_group_name
= iproc_get_group_name
,
457 .dt_node_to_map
= pinconf_generic_dt_node_to_map_pin
,
458 .dt_free_map
= pinctrl_utils_free_map
,
461 static int iproc_gpio_set_pull(struct iproc_gpio
*chip
, unsigned gpio
,
462 bool disable
, bool pull_up
)
466 raw_spin_lock_irqsave(&chip
->lock
, flags
);
469 iproc_set_bit(chip
, IPROC_GPIO_RES_EN_OFFSET
, gpio
, false);
471 iproc_set_bit(chip
, IPROC_GPIO_PAD_RES_OFFSET
, gpio
,
473 iproc_set_bit(chip
, IPROC_GPIO_RES_EN_OFFSET
, gpio
, true);
476 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
478 dev_dbg(chip
->dev
, "gpio:%u set pullup:%d\n", gpio
, pull_up
);
483 static void iproc_gpio_get_pull(struct iproc_gpio
*chip
, unsigned gpio
,
484 bool *disable
, bool *pull_up
)
488 raw_spin_lock_irqsave(&chip
->lock
, flags
);
489 *disable
= !iproc_get_bit(chip
, IPROC_GPIO_RES_EN_OFFSET
, gpio
);
490 *pull_up
= iproc_get_bit(chip
, IPROC_GPIO_PAD_RES_OFFSET
, gpio
);
491 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
494 static int iproc_gpio_set_strength(struct iproc_gpio
*chip
, unsigned gpio
,
498 unsigned int i
, offset
, shift
;
502 /* make sure drive strength is supported */
503 if (strength
< 2 || strength
> 16 || (strength
% 2))
507 base
= chip
->io_ctrl
;
508 offset
= IPROC_GPIO_DRV0_CTRL_OFFSET
;
511 offset
= IPROC_GPIO_REG(gpio
,
512 IPROC_GPIO_ASIU_DRV0_CTRL_OFFSET
);
515 shift
= IPROC_GPIO_SHIFT(gpio
);
517 dev_dbg(chip
->dev
, "gpio:%u set drive strength:%d mA\n", gpio
,
520 raw_spin_lock_irqsave(&chip
->lock
, flags
);
521 strength
= (strength
/ 2) - 1;
522 for (i
= 0; i
< GPIO_DRV_STRENGTH_BITS
; i
++) {
523 val
= readl(base
+ offset
);
525 val
|= ((strength
>> i
) & 0x1) << shift
;
526 writel(val
, base
+ offset
);
529 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
534 static int iproc_gpio_get_strength(struct iproc_gpio
*chip
, unsigned gpio
,
538 unsigned int i
, offset
, shift
;
543 base
= chip
->io_ctrl
;
544 offset
= IPROC_GPIO_DRV0_CTRL_OFFSET
;
547 offset
= IPROC_GPIO_REG(gpio
,
548 IPROC_GPIO_ASIU_DRV0_CTRL_OFFSET
);
551 shift
= IPROC_GPIO_SHIFT(gpio
);
553 raw_spin_lock_irqsave(&chip
->lock
, flags
);
555 for (i
= 0; i
< GPIO_DRV_STRENGTH_BITS
; i
++) {
556 val
= readl(base
+ offset
) & BIT(shift
);
558 *strength
+= (val
<< i
);
563 *strength
= (*strength
+ 1) * 2;
564 raw_spin_unlock_irqrestore(&chip
->lock
, flags
);
569 static int iproc_pin_config_get(struct pinctrl_dev
*pctldev
, unsigned pin
,
570 unsigned long *config
)
572 struct iproc_gpio
*chip
= pinctrl_dev_get_drvdata(pctldev
);
573 enum pin_config_param param
= pinconf_to_config_param(*config
);
574 unsigned gpio
= iproc_pin_to_gpio(pin
);
576 bool disable
, pull_up
;
579 if (iproc_pinconf_param_is_disabled(chip
, param
))
583 case PIN_CONFIG_BIAS_DISABLE
:
584 iproc_gpio_get_pull(chip
, gpio
, &disable
, &pull_up
);
590 case PIN_CONFIG_BIAS_PULL_UP
:
591 iproc_gpio_get_pull(chip
, gpio
, &disable
, &pull_up
);
592 if (!disable
&& pull_up
)
597 case PIN_CONFIG_BIAS_PULL_DOWN
:
598 iproc_gpio_get_pull(chip
, gpio
, &disable
, &pull_up
);
599 if (!disable
&& !pull_up
)
604 case PIN_CONFIG_DRIVE_STRENGTH
:
605 ret
= iproc_gpio_get_strength(chip
, gpio
, &arg
);
608 *config
= pinconf_to_config_packed(param
, arg
);
619 static int iproc_pin_config_set(struct pinctrl_dev
*pctldev
, unsigned pin
,
620 unsigned long *configs
, unsigned num_configs
)
622 struct iproc_gpio
*chip
= pinctrl_dev_get_drvdata(pctldev
);
623 enum pin_config_param param
;
625 unsigned i
, gpio
= iproc_pin_to_gpio(pin
);
628 for (i
= 0; i
< num_configs
; i
++) {
629 param
= pinconf_to_config_param(configs
[i
]);
631 if (iproc_pinconf_param_is_disabled(chip
, param
))
634 arg
= pinconf_to_config_argument(configs
[i
]);
637 case PIN_CONFIG_BIAS_DISABLE
:
638 ret
= iproc_gpio_set_pull(chip
, gpio
, true, false);
643 case PIN_CONFIG_BIAS_PULL_UP
:
644 ret
= iproc_gpio_set_pull(chip
, gpio
, false, true);
649 case PIN_CONFIG_BIAS_PULL_DOWN
:
650 ret
= iproc_gpio_set_pull(chip
, gpio
, false, false);
655 case PIN_CONFIG_DRIVE_STRENGTH
:
656 ret
= iproc_gpio_set_strength(chip
, gpio
, arg
);
662 dev_err(chip
->dev
, "invalid configuration\n");
665 } /* for each config */
671 static const struct pinconf_ops iproc_pconf_ops
= {
673 .pin_config_get
= iproc_pin_config_get
,
674 .pin_config_set
= iproc_pin_config_set
,
678 * Iproc GPIO controller supports some PINCONF related configurations such as
679 * pull up, pull down, and drive strength, when the pin is configured to GPIO
681 * Here a local pinctrl device is created with simple 1-to-1 pin mapping to the
684 static int iproc_gpio_register_pinconf(struct iproc_gpio
*chip
)
686 struct pinctrl_desc
*pctldesc
= &chip
->pctldesc
;
687 struct pinctrl_pin_desc
*pins
;
688 struct gpio_chip
*gc
= &chip
->gc
;
691 pins
= devm_kcalloc(chip
->dev
, gc
->ngpio
, sizeof(*pins
), GFP_KERNEL
);
695 for (i
= 0; i
< gc
->ngpio
; i
++) {
697 pins
[i
].name
= devm_kasprintf(chip
->dev
, GFP_KERNEL
,
703 pctldesc
->name
= dev_name(chip
->dev
);
704 pctldesc
->pctlops
= &iproc_pctrl_ops
;
705 pctldesc
->pins
= pins
;
706 pctldesc
->npins
= gc
->ngpio
;
707 pctldesc
->confops
= &iproc_pconf_ops
;
709 chip
->pctl
= devm_pinctrl_register(chip
->dev
, pctldesc
, chip
);
710 if (IS_ERR(chip
->pctl
)) {
711 dev_err(chip
->dev
, "unable to register pinctrl device\n");
712 return PTR_ERR(chip
->pctl
);
718 static const struct of_device_id iproc_gpio_of_match
[] = {
719 { .compatible
= "brcm,iproc-gpio" },
720 { .compatible
= "brcm,cygnus-ccm-gpio" },
721 { .compatible
= "brcm,cygnus-asiu-gpio" },
722 { .compatible
= "brcm,cygnus-crmu-gpio" },
723 { .compatible
= "brcm,iproc-nsp-gpio" },
724 { .compatible
= "brcm,iproc-stingray-gpio" },
728 static int iproc_gpio_probe(struct platform_device
*pdev
)
730 struct device
*dev
= &pdev
->dev
;
731 struct resource
*res
;
732 struct iproc_gpio
*chip
;
733 struct gpio_chip
*gc
;
734 u32 ngpios
, pinconf_disable_mask
= 0;
736 bool no_pinconf
= false;
738 /* NSP does not support drive strength config */
739 if (of_device_is_compatible(dev
->of_node
, "brcm,iproc-nsp-gpio"))
740 pinconf_disable_mask
= BIT(IPROC_PINCONF_DRIVE_STRENGTH
);
741 /* Stingray does not support pinconf in this controller */
742 else if (of_device_is_compatible(dev
->of_node
,
743 "brcm,iproc-stingray-gpio"))
746 chip
= devm_kzalloc(dev
, sizeof(*chip
), GFP_KERNEL
);
751 platform_set_drvdata(pdev
, chip
);
753 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
754 chip
->base
= devm_ioremap_resource(dev
, res
);
755 if (IS_ERR(chip
->base
)) {
756 dev_err(dev
, "unable to map I/O memory\n");
757 return PTR_ERR(chip
->base
);
760 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
762 chip
->io_ctrl
= devm_ioremap_resource(dev
, res
);
763 if (IS_ERR(chip
->io_ctrl
)) {
764 dev_err(dev
, "unable to map I/O memory\n");
765 return PTR_ERR(chip
->io_ctrl
);
769 if (of_property_read_u32(dev
->of_node
, "ngpios", &ngpios
)) {
770 dev_err(&pdev
->dev
, "missing ngpios DT property\n");
774 raw_spin_lock_init(&chip
->lock
);
779 chip
->num_banks
= (ngpios
+ NGPIOS_PER_BANK
- 1) / NGPIOS_PER_BANK
;
780 gc
->label
= dev_name(dev
);
782 gc
->of_node
= dev
->of_node
;
783 gc
->request
= iproc_gpio_request
;
784 gc
->free
= iproc_gpio_free
;
785 gc
->direction_input
= iproc_gpio_direction_input
;
786 gc
->direction_output
= iproc_gpio_direction_output
;
787 gc
->set
= iproc_gpio_set
;
788 gc
->get
= iproc_gpio_get
;
790 chip
->pinmux_is_supported
= of_property_read_bool(dev
->of_node
,
793 ret
= gpiochip_add_data(gc
, chip
);
795 dev_err(dev
, "unable to add GPIO chip\n");
800 ret
= iproc_gpio_register_pinconf(chip
);
802 dev_err(dev
, "unable to register pinconf\n");
803 goto err_rm_gpiochip
;
806 if (pinconf_disable_mask
) {
807 ret
= iproc_pinconf_disable_map_create(chip
,
808 pinconf_disable_mask
);
811 "unable to create pinconf disable map\n");
812 goto err_rm_gpiochip
;
817 /* optional GPIO interrupt support */
818 irq
= platform_get_irq(pdev
, 0);
820 ret
= gpiochip_irqchip_add(gc
, &iproc_gpio_irq_chip
, 0,
821 handle_simple_irq
, IRQ_TYPE_NONE
);
823 dev_err(dev
, "no GPIO irqchip\n");
824 goto err_rm_gpiochip
;
827 gpiochip_set_chained_irqchip(gc
, &iproc_gpio_irq_chip
, irq
,
828 iproc_gpio_irq_handler
);
839 static struct platform_driver iproc_gpio_driver
= {
841 .name
= "iproc-gpio",
842 .of_match_table
= iproc_gpio_of_match
,
844 .probe
= iproc_gpio_probe
,
847 static int __init
iproc_gpio_init(void)
849 return platform_driver_register(&iproc_gpio_driver
);
851 arch_initcall_sync(iproc_gpio_init
);