Lines Matching +full:int +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2007-2008 MontaVista Software, Inc.
26 #include "gpiolib-of.h"
29 * This is Linux-specific flags. By default controllers' and Linux' mapping
31 * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended.
44 * of_gpio_named_count() - Count GPIOs for a device
45 * @np: device node to count GPIOs for
48 * The function returns the count of GPIOs specified for a node.
52 * Either number of GPIOs defined in the property, or
53 * * %-EINVAL for an incorrectly formed "gpios" property, or
54 * * %-ENOENT for a missing "gpios" property.
58 * gpios = <0
63 * The above example defines four GPIOs, two of which are not specified.
66 static int of_gpio_named_count(const struct device_node *np, in of_gpio_named_count()
69 return of_count_phandle_with_args(np, propname, "#gpio-cells"); in of_gpio_named_count()
73 * of_gpio_spi_cs_get_count() - special GPIO counting for SPI
79 * established "cs-gpios" for chip selects but instead rely on
80 * "gpios" for the chip select lines. If we detect this, we redirect
81 * the counting of "cs-gpios" to count "gpios" transparent to the
85 * Either number of GPIOs defined in the property, or
86 * * %-EINVAL for an incorrectly formed "gpios" property, or
87 * * %-ENOENT for a missing "gpios" property.
89 static int of_gpio_spi_cs_get_count(const struct device_node *np, in of_gpio_spi_cs_get_count()
98 !of_device_is_compatible(np, "ibm,ppc4xx-spi")) in of_gpio_spi_cs_get_count()
100 return of_gpio_named_count(np, "gpios"); in of_gpio_spi_cs_get_count()
103 int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id) in of_gpio_count()
106 int ret; in of_gpio_count()
118 return ret ? ret : -ENOENT; in of_gpio_count()
121 static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, in of_gpiochip_match_node_and_xlate()
126 return device_match_of_node(&chip->gpiodev->dev, gpiospec->np) && in of_gpiochip_match_node_and_xlate()
127 chip->of_xlate && in of_gpiochip_match_node_and_xlate()
128 chip->of_xlate(chip, gpiospec, NULL) >= 0; in of_gpiochip_match_node_and_xlate()
141 int ret; in of_xlate_and_get_gpiod_flags()
143 if (chip->of_gpio_n_cells != gpiospec->args_count) in of_xlate_and_get_gpiod_flags()
144 return ERR_PTR(-EINVAL); in of_xlate_and_get_gpiod_flags()
146 ret = chip->of_xlate(chip, gpiospec, flags); in of_xlate_and_get_gpiod_flags()
163 pr_warn("%s GPIO handle specifies active low - ignored\n", in of_gpio_quirk_polarity()
187 } gpios[] = { in of_gpio_try_fixup_polarity() local
191 * "gpios-reset" property and also specified wrong in of_gpio_try_fixup_polarity()
194 { "himax,hx8357", "gpios-reset", false }, in of_gpio_try_fixup_polarity()
195 { "himax,hx8369", "gpios-reset", false }, in of_gpio_try_fixup_polarity()
199 * The rb-gpios semantics was undocumented and qi,lb60 (along with in of_gpio_try_fixup_polarity()
202 * inverter on this board, it should be active-high. Let's fix that in of_gpio_try_fixup_polarity()
203 * here for older DTs so we can re-use the generic nand_gpio_waitrdy() in of_gpio_try_fixup_polarity()
206 { "qi,lb60", "rb-gpios", true }, in of_gpio_try_fixup_polarity()
210 * According to the datasheet, the NRST pin 27 is an active-low in of_gpio_try_fixup_polarity()
212 * the out-of-tree implementations have been used for a long in of_gpio_try_fixup_polarity()
213 * time incorrectly by describing reset GPIO as active-high. in of_gpio_try_fixup_polarity()
215 { "cascoda,ca8210", "reset-gpio", false }, in of_gpio_try_fixup_polarity()
220 * active-low signal. However, most of the device trees that in of_gpio_try_fixup_polarity()
222 * reset GPIO as active-high, and were also using wrong name in of_gpio_try_fixup_polarity()
225 { "lantiq,pci-xway", "gpio-reset", false }, in of_gpio_try_fixup_polarity()
230 * active-high signals. However, exynos5250-spring.dts use in of_gpio_try_fixup_polarity()
231 * active-low setting. in of_gpio_try_fixup_polarity()
233 { "samsung,s5m8767-pmic", "s5m8767,pmic-buck-dvs-gpios", true }, in of_gpio_try_fixup_polarity()
234 { "samsung,s5m8767-pmic", "s5m8767,pmic-buck-ds-gpios", true }, in of_gpio_try_fixup_polarity()
242 { "ti,tsc2005", "reset-gpios", false }, in of_gpio_try_fixup_polarity()
245 unsigned int i; in of_gpio_try_fixup_polarity()
247 for (i = 0; i < ARRAY_SIZE(gpios); i++) { in of_gpio_try_fixup_polarity()
248 if (of_device_is_compatible(np, gpios[i].compatible) && in of_gpio_try_fixup_polarity()
249 !strcmp(propname, gpios[i].propname)) { in of_gpio_try_fixup_polarity()
250 of_gpio_quirk_polarity(np, gpios[i].active_high, flags); in of_gpio_try_fixup_polarity()
266 } gpios[] = { in of_gpio_set_polarity_by_property() local
269 { "fsl,imx25-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
270 { "fsl,imx27-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
271 { "fsl,imx28-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
272 { "fsl,imx6q-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
273 { "fsl,mvf600-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
274 { "fsl,imx6sx-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
275 { "fsl,imx6ul-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
276 { "fsl,imx8mq-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
277 { "fsl,imx8qm-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
278 { "fsl,s32v234-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
281 { "atmel,hsmci", "cd-gpios", "cd-inverted" }, in of_gpio_set_polarity_by_property()
284 { "fsl,imx6q-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
285 { "fsl,imx6sx-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
286 { "fsl,imx6qp-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
287 { "fsl,imx7d-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
288 { "fsl,imx8mq-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
289 { "fsl,imx8mm-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
290 { "fsl,imx8mp-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
295 * presence or absence of "enable-active-high" solely controls in of_gpio_set_polarity_by_property()
300 { "regulator-fixed", "gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
301 { "regulator-fixed", "gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
302 { "reg-fixed-voltage", "gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
303 { "reg-fixed-voltage", "gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
306 { "regulator-gpio", "enable-gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
307 { "regulator-gpio", "enable-gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
310 unsigned int i; in of_gpio_set_polarity_by_property()
318 if (of_device_is_compatible(np->parent, "atmel,hsmci")) { in of_gpio_set_polarity_by_property()
319 np_compat = np->parent; in of_gpio_set_polarity_by_property()
324 for (i = 0; i < ARRAY_SIZE(gpios); i++) { in of_gpio_set_polarity_by_property()
325 if (of_device_is_compatible(np_compat, gpios[i].compatible) && in of_gpio_set_polarity_by_property()
326 !strcmp(propname, gpios[i].gpio_propname)) { in of_gpio_set_polarity_by_property()
328 gpios[i].polarity_propname); in of_gpio_set_polarity_by_property()
338 int index) in of_gpio_flags_quirks()
347 of_device_is_compatible(np, "reg-fixed-voltage") && in of_gpio_flags_quirks()
348 of_property_read_bool(np, "gpio-open-drain")) { in of_gpio_flags_quirks()
350 pr_info("%s uses legacy open drain flag - update the DTS if you can\n", in of_gpio_flags_quirks()
356 * property named "cs-gpios" we need to inspect the child node in of_gpio_flags_quirks()
359 if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") && in of_gpio_flags_quirks()
360 of_property_present(np, "cs-gpios")) { in of_gpio_flags_quirks()
362 int ret; in of_gpio_flags_quirks()
372 * by just omitting "spi-cs-high" in the in of_gpio_flags_quirks()
377 * and has the "spi-cs-high" set, we get a in of_gpio_flags_quirks()
378 * conflict and the "spi-cs-high" flag will in of_gpio_flags_quirks()
382 "spi-cs-high"); in of_gpio_flags_quirks()
390 /* Legacy handling of stmmac's active-low PHY reset line */ in of_gpio_flags_quirks()
392 !strcmp(propname, "snps,reset-gpio") && in of_gpio_flags_quirks()
393 of_property_read_bool(np, "snps,reset-active-low")) in of_gpio_flags_quirks()
398 * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API
410 const char *propname, int index, enum of_gpio_flags *flags) in of_get_named_gpiod_flags()
414 int ret; in of_get_named_gpiod_flags()
427 desc = ERR_PTR(-EPROBE_DEFER); in of_get_named_gpiod_flags()
439 pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", in of_get_named_gpiod_flags()
450 * of_get_named_gpio() - Get a GPIO number to use with GPIO API
461 int of_get_named_gpio(const struct device_node *np, const char *propname, in of_get_named_gpio()
462 int index) in of_get_named_gpio()
507 unsigned int idx, in of_find_gpio_rename()
512 const char *legacy_id; /* NULL - same as con_id */ in of_find_gpio_rename()
521 } gpios[] = { in of_find_gpio_rename() local
523 /* Himax LCD controllers used "gpios-reset" */ in of_find_gpio_rename()
524 { "reset", "gpios-reset", "himax,hx8357" }, in of_find_gpio_rename()
525 { "reset", "gpios-reset", "himax,hx8369" }, in of_find_gpio_rename()
531 { "rtc-data", "gpio-rtc-data", "moxa,moxart-rtc" }, in of_find_gpio_rename()
532 { "rtc-sclk", "gpio-rtc-sclk", "moxa,moxart-rtc" }, in of_find_gpio_rename()
533 { "rtc-reset", "gpio-rtc-reset", "moxa,moxart-rtc" }, in of_find_gpio_rename()
536 { "reset", "reset-n-io", "marvell,nfc-i2c" }, in of_find_gpio_rename()
539 { "reset", "reset-n-io", "marvell,nfc-spi" }, in of_find_gpio_rename()
542 { "reset", "reset-n-io", "marvell,nfc-uart" }, in of_find_gpio_rename()
543 { "reset", "reset-n-io", "mrvl,nfc-uart" }, in of_find_gpio_rename()
547 { "reset", "gpio-reset", "lantiq,pci-xway" }, in of_find_gpio_rename()
553 * "foo-gpios" so we have this special kludge for them. in of_find_gpio_rename()
564 { "reset", "cirrus,gpio-nreset", "cirrus,cs42l56" }, in of_find_gpio_rename()
567 { "i2s1-in-sel-gpio1", NULL, "mediatek,mt2701-cs42448-machine" }, in of_find_gpio_rename()
568 { "i2s1-in-sel-gpio2", NULL, "mediatek,mt2701-cs42448-machine" }, in of_find_gpio_rename()
571 { "reset", "gpio-reset", "ti,tlv320aic3x" }, in of_find_gpio_rename()
572 { "reset", "gpio-reset", "ti,tlv320aic33" }, in of_find_gpio_rename()
573 { "reset", "gpio-reset", "ti,tlv320aic3007" }, in of_find_gpio_rename()
574 { "reset", "gpio-reset", "ti,tlv320aic3104" }, in of_find_gpio_rename()
575 { "reset", "gpio-reset", "ti,tlv320aic3106" }, in of_find_gpio_rename()
581 * "foo-gpios" so we have this special kludge for them. in of_find_gpio_rename()
583 { "miso", "gpio-miso", "spi-gpio" }, in of_find_gpio_rename()
584 { "mosi", "gpio-mosi", "spi-gpio" }, in of_find_gpio_rename()
585 { "sck", "gpio-sck", "spi-gpio" }, in of_find_gpio_rename()
589 * The old Freescale bindings use simply "gpios" as name in of_find_gpio_rename()
590 * for the chip select lines rather than "cs-gpios" like in of_find_gpio_rename()
595 { "cs", "gpios", "fsl,spi" }, in of_find_gpio_rename()
596 { "cs", "gpios", "aeroflexgaisler,spictrl" }, in of_find_gpio_rename()
599 { "cs", "gpios", "ibm,ppc4xx-spi" }, in of_find_gpio_rename()
605 * property without the compulsory "-gpios" suffix. in of_find_gpio_rename()
612 unsigned int i; in of_find_gpio_rename()
615 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
617 for (i = 0; i < ARRAY_SIZE(gpios); i++) { in of_find_gpio_rename()
618 if (strcmp(con_id, gpios[i].con_id)) in of_find_gpio_rename()
621 if (gpios[i].compatible && in of_find_gpio_rename()
622 !of_device_is_compatible(np, gpios[i].compatible)) in of_find_gpio_rename()
625 legacy_id = gpios[i].legacy_id ?: gpios[i].con_id; in of_find_gpio_rename()
628 pr_info("%s uses legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_gpio_rename()
634 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
639 unsigned int idx, in of_find_mt2701_gpio()
646 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
648 if (!of_device_is_compatible(np, "mediatek,mt2701-cs42448-machine")) in of_find_mt2701_gpio()
649 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
651 if (!con_id || strcmp(con_id, "i2s1-in-sel")) in of_find_mt2701_gpio()
652 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
655 legacy_id = "i2s1-in-sel-gpio1"; in of_find_mt2701_gpio()
657 legacy_id = "i2s1-in-sel-gpio2"; in of_find_mt2701_gpio()
659 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
663 pr_info("%s is using legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_mt2701_gpio()
671 * and have the name "trigger-sources" no matter which kind of phandle it is
673 * we allow looking something up that is not named "foo-gpios".
677 unsigned int idx, in of_find_trigger_gpio()
683 return ERR_PTR(-ENOENT); in of_find_trigger_gpio()
685 if (!con_id || strcmp(con_id, "trigger-sources")) in of_find_trigger_gpio()
686 return ERR_PTR(-ENOENT); in of_find_trigger_gpio()
698 unsigned int idx,
708 unsigned int idx, unsigned long *flags) in of_find_gpio()
715 /* Try GPIO property "foo-gpios" and "foo-gpio" */ in of_find_gpio()
735 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
740 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
742 * @dflags: gpiod_flags - optional GPIO initialization flags
750 unsigned int idx, const char **name, in of_parse_own_gpio()
758 unsigned int i; in of_parse_own_gpio()
760 int ret; in of_parse_own_gpio()
762 chip_np = dev_of_node(&chip->gpiodev->dev); in of_parse_own_gpio()
764 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
770 ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp); in of_parse_own_gpio()
778 ret = of_property_read_u32_index(np, "gpios", idx * tmp + i, in of_parse_own_gpio()
792 else if (of_property_read_bool(np, "output-low")) in of_parse_own_gpio()
794 else if (of_property_read_bool(np, "output-high")) in of_parse_own_gpio()
799 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
802 if (name && of_property_read_string(np, "line-name", name)) in of_parse_own_gpio()
803 *name = np->name; in of_parse_own_gpio()
809 * of_gpiochip_add_hog - Add all hogs in a hog device node
816 static int of_gpiochip_add_hog(struct gpio_chip *chip, struct device_node *hog) in of_gpiochip_add_hog()
822 unsigned int i; in of_gpiochip_add_hog()
823 int ret; in of_gpiochip_add_hog()
835 WRITE_ONCE(desc->hog, hog); in of_gpiochip_add_hog()
843 * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
852 static int of_gpiochip_scan_gpios(struct gpio_chip *chip) in of_gpiochip_scan_gpios()
854 int ret; in of_gpiochip_scan_gpios()
856 for_each_available_child_of_node_scoped(dev_of_node(&chip->gpiodev->dev), np) { in of_gpiochip_scan_gpios()
857 if (!of_property_read_bool(np, "gpio-hog")) in of_gpiochip_scan_gpios()
872 * of_gpiochip_remove_hog - Remove all hogs in a hog device node
882 if (READ_ONCE(desc->hog) == hog) in of_gpiochip_remove_hog()
886 static int of_gpiochip_match_node(struct gpio_chip *chip, const void *data) in of_gpiochip_match_node()
888 return device_match_of_node(&chip->gpiodev->dev, data); in of_gpiochip_match_node()
896 static int of_gpio_notify(struct notifier_block *nb, unsigned long action, in of_gpio_notify()
901 int ret; in of_gpio_notify()
904 * This only supports adding and removing complete gpio-hog nodes. in of_gpio_notify()
905 * Modifying an existing gpio-hog node is not supported (except for in of_gpio_notify()
911 if (!of_property_read_bool(rd->dn, "gpio-hog")) in of_gpio_notify()
914 if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
917 gdev = of_find_gpio_device_by_node(rd->dn->parent); in of_gpio_notify()
921 ret = of_gpiochip_add_hog(gpio_device_get_chip(gdev), rd->dn); in of_gpio_notify()
924 rd->dn); in of_gpio_notify()
925 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
931 if (!of_node_check_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
934 gdev = of_find_gpio_device_by_node(rd->dn->parent); in of_gpio_notify()
938 of_gpiochip_remove_hog(gpio_device_get_chip(gdev), rd->dn); in of_gpio_notify()
939 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
952 * of_gpio_twocell_xlate - translate twocell gpiospec to the GPIO number and flags
964 static int of_gpio_twocell_xlate(struct gpio_chip *gc, in of_gpio_twocell_xlate()
971 * number and the flags from a single gpio cell -- this is possible, in of_gpio_twocell_xlate()
974 if (gc->of_gpio_n_cells != 2) { in of_gpio_twocell_xlate()
976 return -EINVAL; in of_gpio_twocell_xlate()
979 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) in of_gpio_twocell_xlate()
980 return -EINVAL; in of_gpio_twocell_xlate()
982 if (gpiospec->args[0] >= gc->ngpio) in of_gpio_twocell_xlate()
983 return -EINVAL; in of_gpio_twocell_xlate()
986 *flags = gpiospec->args[1]; in of_gpio_twocell_xlate()
988 return gpiospec->args[0]; in of_gpio_twocell_xlate()
992 * of_gpio_threecell_xlate - translate threecell gpiospec to the GPIO number and flags
1001 * foo-gpios = <&gpio instance offset flags>;
1006 static int of_gpio_threecell_xlate(struct gpio_chip *gc, in of_gpio_threecell_xlate()
1010 if (gc->of_gpio_n_cells != 3) { in of_gpio_threecell_xlate()
1012 return -EINVAL; in of_gpio_threecell_xlate()
1015 if (WARN_ON(gpiospec->args_count != 3)) in of_gpio_threecell_xlate()
1016 return -EINVAL; in of_gpio_threecell_xlate()
1022 if (!gc->of_node_instance_match(gc, gpiospec->args[0])) in of_gpio_threecell_xlate()
1023 return -EINVAL; in of_gpio_threecell_xlate()
1025 if (gpiospec->args[1] >= gc->ngpio) in of_gpio_threecell_xlate()
1026 return -EINVAL; in of_gpio_threecell_xlate()
1029 *flags = gpiospec->args[2]; in of_gpio_threecell_xlate()
1031 return gpiospec->args[1]; in of_gpio_threecell_xlate()
1035 #include <linux/gpio/legacy-of-mm-gpiochip.h>
1037 * of_mm_gpiochip_add_data - Add memory mapped GPIO chip (bank)
1045 * - all the callbacks
1046 * - of_gpio_n_cells
1047 * - of_xlate callback (optional)
1050 * - save_regs callback (optional)
1054 * to manage GPIOs from the callbacks.
1059 int of_mm_gpiochip_add_data(struct device_node *np, in of_mm_gpiochip_add_data()
1063 int ret = -ENOMEM; in of_mm_gpiochip_add_data()
1064 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_add_data()
1066 gc->label = kasprintf(GFP_KERNEL, "%pOF", np); in of_mm_gpiochip_add_data()
1067 if (!gc->label) in of_mm_gpiochip_add_data()
1070 mm_gc->regs = of_iomap(np, 0); in of_mm_gpiochip_add_data()
1071 if (!mm_gc->regs) in of_mm_gpiochip_add_data()
1074 gc->base = -1; in of_mm_gpiochip_add_data()
1076 if (mm_gc->save_regs) in of_mm_gpiochip_add_data()
1077 mm_gc->save_regs(mm_gc); in of_mm_gpiochip_add_data()
1079 fwnode_handle_put(mm_gc->gc.fwnode); in of_mm_gpiochip_add_data()
1080 mm_gc->gc.fwnode = fwnode_handle_get(of_fwnode_handle(np)); in of_mm_gpiochip_add_data()
1089 iounmap(mm_gc->regs); in of_mm_gpiochip_add_data()
1091 kfree(gc->label); in of_mm_gpiochip_add_data()
1099 * of_mm_gpiochip_remove - Remove memory mapped GPIO chip (bank)
1104 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_remove()
1107 iounmap(mm_gc->regs); in of_mm_gpiochip_remove()
1108 kfree(gc->label); in of_mm_gpiochip_remove()
1114 static int of_gpiochip_add_pin_range(struct gpio_chip *chip) in of_gpiochip_add_pin_range()
1119 int index = 0, ret, trim; in of_gpiochip_add_pin_range()
1121 static const char group_names_propname[] = "gpio-ranges-group-names"; in of_gpiochip_add_pin_range()
1123 int offset; /* Offset of the first GPIO line on the chip */ in of_gpiochip_add_pin_range()
1124 int pin; /* Pin base number in the range */ in of_gpiochip_add_pin_range()
1125 int count; /* Number of pins/GPIO lines to map */ in of_gpiochip_add_pin_range()
1127 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add_pin_range()
1135 * Ordinary phandles contain 2-3 cells: in of_gpiochip_add_pin_range()
1136 * gpios = <&gpio [instance] offset flags>; in of_gpiochip_add_pin_range()
1138 * gpio-ranges <&pinctrl [gpio_instance] gpio_offet pin_offet count>; in of_gpiochip_add_pin_range()
1139 * This is why we parse chip->of_gpio_n_cells + 1 cells in of_gpiochip_add_pin_range()
1141 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", in of_gpiochip_add_pin_range()
1142 chip->of_gpio_n_cells + 1, in of_gpiochip_add_pin_range()
1150 return -EPROBE_DEFER; in of_gpiochip_add_pin_range()
1152 if (chip->of_gpio_n_cells == 3) { in of_gpiochip_add_pin_range()
1167 if (chip->of_node_instance_match && in of_gpiochip_add_pin_range()
1168 (chip->of_gpio_n_cells == 3) && in of_gpiochip_add_pin_range()
1169 !chip->of_node_instance_match(chip, pinspec.args[0])) in of_gpiochip_add_pin_range()
1173 if (offset >= (chip->offset + chip->ngpio)) in of_gpiochip_add_pin_range()
1175 if (offset + count <= chip->offset) in of_gpiochip_add_pin_range()
1192 if (chip->offset > offset) { in of_gpiochip_add_pin_range()
1193 trim = chip->offset - offset; in of_gpiochip_add_pin_range()
1194 count -= trim; in of_gpiochip_add_pin_range()
1198 offset -= chip->offset; in of_gpiochip_add_pin_range()
1200 if ((offset + count) > chip->ngpio) in of_gpiochip_add_pin_range()
1201 count = chip->ngpio - offset; in of_gpiochip_add_pin_range()
1213 pr_err("%pOF: Illegal gpio-range format.\n", in of_gpiochip_add_pin_range()
1247 static int of_gpiochip_add_pin_range(struct gpio_chip *chip) { return 0; } in of_gpiochip_add_pin_range()
1250 int of_gpiochip_add(struct gpio_chip *chip) in of_gpiochip_add()
1253 int ret; in of_gpiochip_add()
1255 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add()
1259 if (!chip->of_xlate) { in of_gpiochip_add()
1260 if (chip->of_gpio_n_cells == 3) { in of_gpiochip_add()
1261 if (!chip->of_node_instance_match) in of_gpiochip_add()
1262 return -EINVAL; in of_gpiochip_add()
1263 chip->of_xlate = of_gpio_threecell_xlate; in of_gpiochip_add()
1265 chip->of_gpio_n_cells = 2; in of_gpiochip_add()
1266 chip->of_xlate = of_gpio_twocell_xlate; in of_gpiochip_add()
1270 if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS) in of_gpiochip_add()
1271 return -EINVAL; in of_gpiochip_add()
1288 of_node_put(dev_of_node(&chip->gpiodev->dev)); in of_gpiochip_remove()
1291 bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index) in of_gpiochip_instance_match()
1293 if (gc->of_node_instance_match) in of_gpiochip_instance_match()
1294 return gc->of_node_instance_match(gc, index); in of_gpiochip_instance_match()