1 // SPDX-License-Identifier: GPL-2.0+
3 * OF helpers for the GPIO API
5 * Copyright (c) 2007-2008 MontaVista Software, Inc.
7 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
10 #include <linux/device.h>
11 #include <linux/err.h>
12 #include <linux/errno.h>
13 #include <linux/module.h>
15 #include <linux/gpio/consumer.h>
17 #include <linux/of_address.h>
18 #include <linux/of_gpio.h>
19 #include <linux/pinctrl/pinctrl.h>
20 #include <linux/slab.h>
21 #include <linux/gpio/machine.h>
24 #include "gpiolib-of.h"
27 * of_gpio_spi_cs_get_count() - special GPIO counting for SPI
28 * Some elder GPIO controllers need special quirks. Currently we handle
29 * the Freescale GPIO controller with bindings that doesn't use the
30 * established "cs-gpios" for chip selects but instead rely on
31 * "gpios" for the chip select lines. If we detect this, we redirect
32 * the counting of "cs-gpios" to count "gpios" transparent to the
35 int of_gpio_spi_cs_get_count(struct device *dev, const char *con_id)
37 struct device_node *np = dev->of_node;
39 if (!IS_ENABLED(CONFIG_SPI_MASTER))
41 if (!con_id || strcmp(con_id, "cs"))
43 if (!of_device_is_compatible(np, "fsl,spi") &&
44 !of_device_is_compatible(np, "aeroflexgaisler,spictrl"))
46 return of_gpio_named_count(np, "gpios");
50 * This is used by external users of of_gpio_count() from <linux/of_gpio.h>
52 * FIXME: get rid of those external users by converting them to GPIO
53 * descriptors and let them all use gpiod_get_count()
55 int of_gpio_get_count(struct device *dev, const char *con_id)
61 ret = of_gpio_spi_cs_get_count(dev, con_id);
65 for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
67 snprintf(propname, sizeof(propname), "%s-%s",
68 con_id, gpio_suffixes[i]);
70 snprintf(propname, sizeof(propname), "%s",
73 ret = of_gpio_named_count(dev->of_node, propname);
77 return ret ? ret : -ENOENT;
80 static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data)
82 struct of_phandle_args *gpiospec = data;
84 return chip->gpiodev->dev.of_node == gpiospec->np &&
86 chip->of_xlate(chip, gpiospec, NULL) >= 0;
89 static struct gpio_chip *of_find_gpiochip_by_xlate(
90 struct of_phandle_args *gpiospec)
92 return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate);
95 static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip,
96 struct of_phandle_args *gpiospec,
97 enum of_gpio_flags *flags)
101 if (chip->of_gpio_n_cells != gpiospec->args_count)
102 return ERR_PTR(-EINVAL);
104 ret = chip->of_xlate(chip, gpiospec, flags);
108 return gpiochip_get_desc(chip, ret);
112 * of_gpio_need_valid_mask() - figure out if the OF GPIO driver needs
113 * to set the .valid_mask
114 * @dev: the device for the GPIO provider
115 * @return: true if the valid mask needs to be set
117 bool of_gpio_need_valid_mask(const struct gpio_chip *gc)
120 struct device_node *np = gc->of_node;
122 size = of_property_count_u32_elems(np, "gpio-reserved-ranges");
123 if (size > 0 && size % 2 == 0)
128 static void of_gpio_flags_quirks(struct device_node *np,
129 const char *propname,
130 enum of_gpio_flags *flags,
134 * Handle MMC "cd-inverted" and "wp-inverted" semantics.
136 if (IS_ENABLED(CONFIG_MMC)) {
138 * Active low is the default according to the
139 * SDHCI specification and the device tree
140 * bindings. However the code in the current
141 * kernel was written such that the phandle
142 * flags were always respected, and "cd-inverted"
143 * would invert the flag from the device phandle.
145 if (!strcmp(propname, "cd-gpios")) {
146 if (of_property_read_bool(np, "cd-inverted"))
147 *flags ^= OF_GPIO_ACTIVE_LOW;
151 * Some GPIO fixed regulator quirks.
152 * Note that active low is the default.
154 if (IS_ENABLED(CONFIG_REGULATOR) &&
155 (of_device_is_compatible(np, "regulator-fixed") ||
156 of_device_is_compatible(np, "reg-fixed-voltage") ||
157 (!(strcmp(propname, "enable-gpio") &&
158 strcmp(propname, "enable-gpios")) &&
159 of_device_is_compatible(np, "regulator-gpio")))) {
161 * The regulator GPIO handles are specified such that the
162 * presence or absence of "enable-active-high" solely controls
163 * the polarity of the GPIO line. Any phandle flags must
164 * be actively ignored.
166 if (*flags & OF_GPIO_ACTIVE_LOW) {
167 pr_warn("%s GPIO handle specifies active low - ignored\n",
168 of_node_full_name(np));
169 *flags &= ~OF_GPIO_ACTIVE_LOW;
171 if (!of_property_read_bool(np, "enable-active-high"))
172 *flags |= OF_GPIO_ACTIVE_LOW;
175 * Legacy open drain handling for fixed voltage regulators.
177 if (IS_ENABLED(CONFIG_REGULATOR) &&
178 of_device_is_compatible(np, "reg-fixed-voltage") &&
179 of_property_read_bool(np, "gpio-open-drain")) {
180 *flags |= (OF_GPIO_SINGLE_ENDED | OF_GPIO_OPEN_DRAIN);
181 pr_info("%s uses legacy open drain flag - update the DTS if you can\n",
182 of_node_full_name(np));
186 * Legacy handling of SPI active high chip select. If we have a
187 * property named "cs-gpios" we need to inspect the child node
188 * to determine if the flags should have inverted semantics.
190 if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") &&
191 of_property_read_bool(np, "cs-gpios")) {
192 struct device_node *child;
196 for_each_child_of_node(np, child) {
197 ret = of_property_read_u32(child, "reg", &cs);
202 * SPI children have active low chip selects
203 * by default. This can be specified negatively
204 * by just omitting "spi-cs-high" in the
205 * device node, or actively by tagging on
206 * GPIO_ACTIVE_LOW as flag in the device
207 * tree. If the line is simultaneously
208 * tagged as active low in the device tree
209 * and has the "spi-cs-high" set, we get a
210 * conflict and the "spi-cs-high" flag will
213 if (of_property_read_bool(child, "spi-cs-high")) {
214 if (*flags & OF_GPIO_ACTIVE_LOW) {
215 pr_warn("%s GPIO handle specifies active low - ignored\n",
216 of_node_full_name(child));
217 *flags &= ~OF_GPIO_ACTIVE_LOW;
220 if (!(*flags & OF_GPIO_ACTIVE_LOW))
221 pr_info("%s enforce active low on chipselect handle\n",
222 of_node_full_name(child));
223 *flags |= OF_GPIO_ACTIVE_LOW;
231 /* Legacy handling of stmmac's active-low PHY reset line */
232 if (IS_ENABLED(CONFIG_STMMAC_ETH) &&
233 !strcmp(propname, "snps,reset-gpio") &&
234 of_property_read_bool(np, "snps,reset-active-low"))
235 *flags |= OF_GPIO_ACTIVE_LOW;
239 * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API
240 * @np: device node to get GPIO from
241 * @propname: property name containing gpio specifier(s)
242 * @index: index of the GPIO
243 * @flags: a flags pointer to fill in
245 * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno
246 * value on the error condition. If @flags is not NULL the function also fills
247 * in flags for the GPIO.
249 static struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
250 const char *propname, int index, enum of_gpio_flags *flags)
252 struct of_phandle_args gpiospec;
253 struct gpio_chip *chip;
254 struct gpio_desc *desc;
257 ret = of_parse_phandle_with_args_map(np, propname, "gpio", index,
260 pr_debug("%s: can't parse '%s' property of node '%pOF[%d]'\n",
261 __func__, propname, np, index);
265 chip = of_find_gpiochip_by_xlate(&gpiospec);
267 desc = ERR_PTR(-EPROBE_DEFER);
271 desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, flags);
276 of_gpio_flags_quirks(np, propname, flags, index);
278 pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n",
279 __func__, propname, np, index,
280 PTR_ERR_OR_ZERO(desc));
283 of_node_put(gpiospec.np);
288 int of_get_named_gpio_flags(struct device_node *np, const char *list_name,
289 int index, enum of_gpio_flags *flags)
291 struct gpio_desc *desc;
293 desc = of_get_named_gpiod_flags(np, list_name, index, flags);
296 return PTR_ERR(desc);
298 return desc_to_gpio(desc);
300 EXPORT_SYMBOL_GPL(of_get_named_gpio_flags);
303 * gpiod_get_from_of_node() - obtain a GPIO from an OF node
304 * @node: handle of the OF node
305 * @propname: name of the DT property representing the GPIO
306 * @index: index of the GPIO to obtain for the consumer
307 * @dflags: GPIO initialization flags
308 * @label: label to attach to the requested GPIO
311 * On successful request the GPIO pin is configured in accordance with
314 * In case of error an ERR_PTR() is returned.
316 struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
317 const char *propname, int index,
318 enum gpiod_flags dflags,
321 unsigned long lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
322 struct gpio_desc *desc;
323 enum of_gpio_flags flags;
324 bool active_low = false;
325 bool single_ended = false;
326 bool open_drain = false;
327 bool transitory = false;
330 desc = of_get_named_gpiod_flags(node, propname,
333 if (!desc || IS_ERR(desc)) {
337 active_low = flags & OF_GPIO_ACTIVE_LOW;
338 single_ended = flags & OF_GPIO_SINGLE_ENDED;
339 open_drain = flags & OF_GPIO_OPEN_DRAIN;
340 transitory = flags & OF_GPIO_TRANSITORY;
342 ret = gpiod_request(desc, label);
343 if (ret == -EBUSY && (dflags & GPIOD_FLAGS_BIT_NONEXCLUSIVE))
349 lflags |= GPIO_ACTIVE_LOW;
353 lflags |= GPIO_OPEN_DRAIN;
355 lflags |= GPIO_OPEN_SOURCE;
359 lflags |= GPIO_TRANSITORY;
361 ret = gpiod_configure_flags(desc, propname, lflags, dflags);
369 EXPORT_SYMBOL_GPL(gpiod_get_from_of_node);
372 * The SPI GPIO bindings happened before we managed to establish that GPIO
373 * properties should be named "foo-gpios" so we have this special kludge for
376 static struct gpio_desc *of_find_spi_gpio(struct device *dev, const char *con_id,
377 enum of_gpio_flags *of_flags)
379 char prop_name[32]; /* 32 is max size of property name */
380 struct device_node *np = dev->of_node;
381 struct gpio_desc *desc;
384 * Hopefully the compiler stubs the rest of the function if this
387 if (!IS_ENABLED(CONFIG_SPI_MASTER))
388 return ERR_PTR(-ENOENT);
390 /* Allow this specifically for "spi-gpio" devices */
391 if (!of_device_is_compatible(np, "spi-gpio") || !con_id)
392 return ERR_PTR(-ENOENT);
394 /* Will be "gpio-sck", "gpio-mosi" or "gpio-miso" */
395 snprintf(prop_name, sizeof(prop_name), "%s-%s", "gpio", con_id);
397 desc = of_get_named_gpiod_flags(np, prop_name, 0, of_flags);
402 * The old Freescale bindings use simply "gpios" as name for the chip select
403 * lines rather than "cs-gpios" like all other SPI hardware. Account for this
404 * with a special quirk.
406 static struct gpio_desc *of_find_spi_cs_gpio(struct device *dev,
409 unsigned long *flags)
411 struct device_node *np = dev->of_node;
413 if (!IS_ENABLED(CONFIG_SPI_MASTER))
414 return ERR_PTR(-ENOENT);
416 /* Allow this specifically for Freescale devices */
417 if (!of_device_is_compatible(np, "fsl,spi") &&
418 !of_device_is_compatible(np, "aeroflexgaisler,spictrl"))
419 return ERR_PTR(-ENOENT);
420 /* Allow only if asking for "cs-gpios" */
421 if (!con_id || strcmp(con_id, "cs"))
422 return ERR_PTR(-ENOENT);
425 * While all other SPI controllers use "cs-gpios" the Freescale
426 * uses just "gpios" so translate to that when "cs-gpios" is
429 return of_find_gpio(dev, NULL, idx, flags);
433 * Some regulator bindings happened before we managed to establish that GPIO
434 * properties should be named "foo-gpios" so we have this special kludge for
437 static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *con_id,
438 enum of_gpio_flags *of_flags)
440 /* These are the connection IDs we accept as legacy GPIO phandles */
441 const char *whitelist[] = {
442 "wlf,ldoena", /* Arizona */
443 "wlf,ldo1ena", /* WM8994 */
444 "wlf,ldo2ena", /* WM8994 */
446 struct device_node *np = dev->of_node;
447 struct gpio_desc *desc;
450 if (!IS_ENABLED(CONFIG_REGULATOR))
451 return ERR_PTR(-ENOENT);
454 return ERR_PTR(-ENOENT);
456 i = match_string(whitelist, ARRAY_SIZE(whitelist), con_id);
458 return ERR_PTR(-ENOENT);
460 desc = of_get_named_gpiod_flags(np, con_id, 0, of_flags);
464 static struct gpio_desc *of_find_arizona_gpio(struct device *dev,
466 enum of_gpio_flags *of_flags)
468 if (!IS_ENABLED(CONFIG_MFD_ARIZONA))
469 return ERR_PTR(-ENOENT);
471 if (!con_id || strcmp(con_id, "wlf,reset"))
472 return ERR_PTR(-ENOENT);
474 return of_get_named_gpiod_flags(dev->of_node, con_id, 0, of_flags);
477 struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
478 unsigned int idx, unsigned long *flags)
480 char prop_name[32]; /* 32 is max size of property name */
481 enum of_gpio_flags of_flags;
482 struct gpio_desc *desc;
485 /* Try GPIO property "foo-gpios" and "foo-gpio" */
486 for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
488 snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id,
491 snprintf(prop_name, sizeof(prop_name), "%s",
494 desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
497 if (!IS_ERR(desc) || PTR_ERR(desc) != -ENOENT)
501 if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
502 /* Special handling for SPI GPIOs if used */
503 desc = of_find_spi_gpio(dev, con_id, &of_flags);
506 if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
507 /* This quirk looks up flags and all */
508 desc = of_find_spi_cs_gpio(dev, con_id, idx, flags);
513 if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
514 /* Special handling for regulator GPIOs if used */
515 desc = of_find_regulator_gpio(dev, con_id, &of_flags);
518 if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT)
519 desc = of_find_arizona_gpio(dev, con_id, &of_flags);
524 if (of_flags & OF_GPIO_ACTIVE_LOW)
525 *flags |= GPIO_ACTIVE_LOW;
527 if (of_flags & OF_GPIO_SINGLE_ENDED) {
528 if (of_flags & OF_GPIO_OPEN_DRAIN)
529 *flags |= GPIO_OPEN_DRAIN;
531 *flags |= GPIO_OPEN_SOURCE;
534 if (of_flags & OF_GPIO_TRANSITORY)
535 *flags |= GPIO_TRANSITORY;
537 if (of_flags & OF_GPIO_PULL_UP)
538 *flags |= GPIO_PULL_UP;
539 if (of_flags & OF_GPIO_PULL_DOWN)
540 *flags |= GPIO_PULL_DOWN;
546 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
547 * @np: device node to get GPIO from
548 * @chip: GPIO chip whose hog is parsed
549 * @idx: Index of the GPIO to parse
550 * @name: GPIO line name
551 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
552 * of_find_gpio() or of_parse_own_gpio()
553 * @dflags: gpiod_flags - optional GPIO initialization flags
555 * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno
556 * value on the error condition.
558 static struct gpio_desc *of_parse_own_gpio(struct device_node *np,
559 struct gpio_chip *chip,
560 unsigned int idx, const char **name,
561 unsigned long *lflags,
562 enum gpiod_flags *dflags)
564 struct device_node *chip_np;
565 enum of_gpio_flags xlate_flags;
566 struct of_phandle_args gpiospec;
567 struct gpio_desc *desc;
572 chip_np = chip->of_node;
574 return ERR_PTR(-EINVAL);
577 *lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
580 ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp);
584 gpiospec.np = chip_np;
585 gpiospec.args_count = tmp;
587 for (i = 0; i < tmp; i++) {
588 ret = of_property_read_u32_index(np, "gpios", idx * tmp + i,
594 desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, &xlate_flags);
598 if (xlate_flags & OF_GPIO_ACTIVE_LOW)
599 *lflags |= GPIO_ACTIVE_LOW;
600 if (xlate_flags & OF_GPIO_TRANSITORY)
601 *lflags |= GPIO_TRANSITORY;
603 if (of_property_read_bool(np, "input"))
605 else if (of_property_read_bool(np, "output-low"))
606 *dflags |= GPIOD_OUT_LOW;
607 else if (of_property_read_bool(np, "output-high"))
608 *dflags |= GPIOD_OUT_HIGH;
610 pr_warn("GPIO line %d (%pOFn): no hogging state specified, bailing out\n",
611 desc_to_gpio(desc), np);
612 return ERR_PTR(-EINVAL);
615 if (name && of_property_read_string(np, "line-name", name))
622 * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
623 * @chip: gpio chip to act on
625 * This is only used by of_gpiochip_add to request/set GPIO initial
627 * It returns error if it fails otherwise 0 on success.
629 static int of_gpiochip_scan_gpios(struct gpio_chip *chip)
631 struct gpio_desc *desc = NULL;
632 struct device_node *np;
634 unsigned long lflags;
635 enum gpiod_flags dflags;
639 for_each_available_child_of_node(chip->of_node, np) {
640 if (!of_property_read_bool(np, "gpio-hog"))
644 desc = of_parse_own_gpio(np, chip, i, &name, &lflags,
649 ret = gpiod_hog(desc, name, lflags, dflags);
661 * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags
662 * @gc: pointer to the gpio_chip structure
663 * @gpiospec: GPIO specifier as found in the device tree
664 * @flags: a flags pointer to fill in
666 * This is simple translation function, suitable for the most 1:1 mapped
667 * GPIO chips. This function performs only one sanity check: whether GPIO
668 * is less than ngpios (that is specified in the gpio_chip).
670 static int of_gpio_simple_xlate(struct gpio_chip *gc,
671 const struct of_phandle_args *gpiospec,
675 * We're discouraging gpio_cells < 2, since that way you'll have to
676 * write your own xlate function (that will have to retrieve the GPIO
677 * number and the flags from a single gpio cell -- this is possible,
678 * but not recommended).
680 if (gc->of_gpio_n_cells < 2) {
685 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells))
688 if (gpiospec->args[0] >= gc->ngpio)
692 *flags = gpiospec->args[1];
694 return gpiospec->args[0];
698 * of_mm_gpiochip_add_data - Add memory mapped GPIO chip (bank)
699 * @np: device node of the GPIO chip
700 * @mm_gc: pointer to the of_mm_gpio_chip allocated structure
701 * @data: driver data to store in the struct gpio_chip
703 * To use this function you should allocate and fill mm_gc with:
705 * 1) In the gpio_chip structure:
706 * - all the callbacks
708 * - of_xlate callback (optional)
710 * 3) In the of_mm_gpio_chip structure:
711 * - save_regs callback (optional)
713 * If succeeded, this function will map bank's memory and will
714 * do all necessary work for you. Then you'll able to use .regs
715 * to manage GPIOs from the callbacks.
717 int of_mm_gpiochip_add_data(struct device_node *np,
718 struct of_mm_gpio_chip *mm_gc,
722 struct gpio_chip *gc = &mm_gc->gc;
724 gc->label = kasprintf(GFP_KERNEL, "%pOF", np);
728 mm_gc->regs = of_iomap(np, 0);
734 if (mm_gc->save_regs)
735 mm_gc->save_regs(mm_gc);
737 mm_gc->gc.of_node = np;
739 ret = gpiochip_add_data(gc, data);
745 iounmap(mm_gc->regs);
749 pr_err("%pOF: GPIO chip registration failed with status %d\n", np, ret);
752 EXPORT_SYMBOL_GPL(of_mm_gpiochip_add_data);
755 * of_mm_gpiochip_remove - Remove memory mapped GPIO chip (bank)
756 * @mm_gc: pointer to the of_mm_gpio_chip allocated structure
758 void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc)
760 struct gpio_chip *gc = &mm_gc->gc;
766 iounmap(mm_gc->regs);
769 EXPORT_SYMBOL_GPL(of_mm_gpiochip_remove);
771 static void of_gpiochip_init_valid_mask(struct gpio_chip *chip)
775 struct device_node *np = chip->of_node;
777 len = of_property_count_u32_elems(np, "gpio-reserved-ranges");
778 if (len < 0 || len % 2 != 0)
781 for (i = 0; i < len; i += 2) {
782 of_property_read_u32_index(np, "gpio-reserved-ranges",
784 of_property_read_u32_index(np, "gpio-reserved-ranges",
786 if (start >= chip->ngpio || start + count > chip->ngpio)
789 bitmap_clear(chip->valid_mask, start, count);
793 #ifdef CONFIG_PINCTRL
794 static int of_gpiochip_add_pin_range(struct gpio_chip *chip)
796 struct device_node *np = chip->of_node;
797 struct of_phandle_args pinspec;
798 struct pinctrl_dev *pctldev;
801 static const char group_names_propname[] = "gpio-ranges-group-names";
802 struct property *group_names;
807 group_names = of_find_property(np, group_names_propname, NULL);
810 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3,
815 pctldev = of_pinctrl_get(pinspec.np);
816 of_node_put(pinspec.np);
818 return -EPROBE_DEFER;
820 if (pinspec.args[2]) {
822 of_property_read_string_index(np,
823 group_names_propname,
826 pr_err("%pOF: Group name of numeric GPIO ranges must be the empty string.\n",
831 /* npins != 0: linear range */
832 ret = gpiochip_add_pin_range(chip,
833 pinctrl_dev_get_devname(pctldev),
840 /* npins == 0: special range */
841 if (pinspec.args[1]) {
842 pr_err("%pOF: Illegal gpio-range format.\n",
848 pr_err("%pOF: GPIO group range requested but no %s property.\n",
849 np, group_names_propname);
853 ret = of_property_read_string_index(np,
854 group_names_propname,
860 pr_err("%pOF: Group name of GPIO group range cannot be the empty string.\n",
865 ret = gpiochip_add_pingroup_range(chip, pctldev,
866 pinspec.args[0], name);
876 static int of_gpiochip_add_pin_range(struct gpio_chip *chip) { return 0; }
879 int of_gpiochip_add(struct gpio_chip *chip)
886 if (!chip->of_xlate) {
887 chip->of_gpio_n_cells = 2;
888 chip->of_xlate = of_gpio_simple_xlate;
891 if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS)
894 of_gpiochip_init_valid_mask(chip);
896 ret = of_gpiochip_add_pin_range(chip);
900 /* If the chip defines names itself, these take precedence */
902 devprop_gpiochip_set_names(chip,
903 of_fwnode_handle(chip->of_node));
905 of_node_get(chip->of_node);
907 ret = of_gpiochip_scan_gpios(chip);
909 of_node_put(chip->of_node);
914 void of_gpiochip_remove(struct gpio_chip *chip)
916 of_node_put(chip->of_node);