• Home
  • Raw
  • Download

Lines Matching +full:reset +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.
50 * Number of gpios defined in property,
51 * -EINVAL for an incorrectly formed gpios property, or
52 * -ENOENT for a missing gpios property
55 * gpios = <0
60 * The above example defines four GPIOs, two of which are not specified.
66 return of_count_phandle_with_args(np, propname, "#gpio-cells"); in of_gpio_named_count()
70 * of_gpio_spi_cs_get_count() - special GPIO counting for SPI
76 * established "cs-gpios" for chip selects but instead rely on
77 * "gpios" for the chip select lines. If we detect this, we redirect
78 * the counting of "cs-gpios" to count "gpios" transparent to the
83 struct device_node *np = dev->of_node; in of_gpio_spi_cs_get_count()
91 !of_device_is_compatible(np, "ibm,ppc4xx-spi")) in of_gpio_spi_cs_get_count()
93 return of_gpio_named_count(np, "gpios"); in of_gpio_spi_cs_get_count()
108 snprintf(propname, sizeof(propname), "%s-%s", in of_gpio_get_count()
114 ret = of_gpio_named_count(dev->of_node, propname); in of_gpio_get_count()
118 return ret ? ret : -ENOENT; in of_gpio_get_count()
125 return device_match_of_node(&chip->gpiodev->dev, gpiospec->np) && in of_gpiochip_match_node_and_xlate()
126 chip->of_xlate && in of_gpiochip_match_node_and_xlate()
127 chip->of_xlate(chip, gpiospec, NULL) >= 0; in of_gpiochip_match_node_and_xlate()
142 if (chip->of_gpio_n_cells != gpiospec->args_count) in of_xlate_and_get_gpiod_flags()
143 return ERR_PTR(-EINVAL); in of_xlate_and_get_gpiod_flags()
145 ret = chip->of_xlate(chip, gpiospec, flags); in of_xlate_and_get_gpiod_flags()
162 pr_warn("%s GPIO handle specifies active low - ignored\n", in of_gpio_quirk_polarity()
186 } gpios[] = { in of_gpio_try_fixup_polarity() local
190 * "gpios-reset" property and also specified wrong in of_gpio_try_fixup_polarity()
193 { "himax,hx8357", "gpios-reset", false }, in of_gpio_try_fixup_polarity()
194 { "himax,hx8369", "gpios-reset", false }, in of_gpio_try_fixup_polarity()
199 for (i = 0; i < ARRAY_SIZE(gpios); i++) { in of_gpio_try_fixup_polarity()
200 if (of_device_is_compatible(np, gpios[i].compatible) && in of_gpio_try_fixup_polarity()
201 !strcmp(propname, gpios[i].propname)) { in of_gpio_try_fixup_polarity()
202 of_gpio_quirk_polarity(np, gpios[i].active_high, flags); in of_gpio_try_fixup_polarity()
218 } gpios[] = { in of_gpio_set_polarity_by_property() local
221 { "fsl,imx25-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
222 { "fsl,imx27-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
223 { "fsl,imx28-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
224 { "fsl,imx6q-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
225 { "fsl,mvf600-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
226 { "fsl,imx6sx-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
227 { "fsl,imx6ul-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
228 { "fsl,imx8mq-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
229 { "fsl,imx8qm-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
230 { "fsl,s32v234-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
233 { "fsl,imx6q-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
234 { "fsl,imx6sx-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
235 { "fsl,imx6qp-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
236 { "fsl,imx7d-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
237 { "fsl,imx8mq-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
238 { "fsl,imx8mm-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
239 { "fsl,imx8mp-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
244 * presence or absence of "enable-active-high" solely controls in of_gpio_set_polarity_by_property()
249 { "regulator-fixed", "gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
250 { "regulator-fixed", "gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
251 { "reg-fixed-voltage", "gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
252 { "reg-fixed-voltage", "gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
255 { "regulator-gpio", "enable-gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
256 { "regulator-gpio", "enable-gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
259 { "atmel,hsmci", "cd-gpios", "cd-inverted" }, in of_gpio_set_polarity_by_property()
270 if (of_device_is_compatible(np->parent, "atmel,hsmci")) { in of_gpio_set_polarity_by_property()
271 np_compat = np->parent; in of_gpio_set_polarity_by_property()
276 for (i = 0; i < ARRAY_SIZE(gpios); i++) { in of_gpio_set_polarity_by_property()
277 if (of_device_is_compatible(np_compat, gpios[i].compatible) && in of_gpio_set_polarity_by_property()
278 !strcmp(propname, gpios[i].gpio_propname)) { in of_gpio_set_polarity_by_property()
280 gpios[i].polarity_propname); in of_gpio_set_polarity_by_property()
299 of_device_is_compatible(np, "reg-fixed-voltage") && in of_gpio_flags_quirks()
300 of_property_read_bool(np, "gpio-open-drain")) { in of_gpio_flags_quirks()
302 pr_info("%s uses legacy open drain flag - update the DTS if you can\n", in of_gpio_flags_quirks()
308 * property named "cs-gpios" we need to inspect the child node in of_gpio_flags_quirks()
311 if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") && in of_gpio_flags_quirks()
312 of_property_read_bool(np, "cs-gpios")) { in of_gpio_flags_quirks()
325 * by just omitting "spi-cs-high" in the in of_gpio_flags_quirks()
330 * and has the "spi-cs-high" set, we get a in of_gpio_flags_quirks()
331 * conflict and the "spi-cs-high" flag will in of_gpio_flags_quirks()
335 "spi-cs-high"); in of_gpio_flags_quirks()
344 /* Legacy handling of stmmac's active-low PHY reset line */ in of_gpio_flags_quirks()
346 !strcmp(propname, "snps,reset-gpio") && in of_gpio_flags_quirks()
347 of_property_read_bool(np, "snps,reset-active-low")) in of_gpio_flags_quirks()
352 * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API
380 desc = ERR_PTR(-EPROBE_DEFER); in of_get_named_gpiod_flags()
391 pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", in of_get_named_gpiod_flags()
402 * of_get_named_gpio() - Get a GPIO number to use with GPIO API
461 const char *legacy_id; /* NULL - same as con_id */ in of_find_gpio_rename()
470 } gpios[] = { in of_find_gpio_rename() local
472 /* Himax LCD controllers used "gpios-reset" */ in of_find_gpio_rename()
473 { "reset", "gpios-reset", "himax,hx8357" }, in of_find_gpio_rename()
474 { "reset", "gpios-reset", "himax,hx8369" }, in of_find_gpio_rename()
477 { "wlf,reset", NULL, NULL }, in of_find_gpio_rename()
480 { "rtc-data", "gpio-rtc-data", "moxa,moxart-rtc" }, in of_find_gpio_rename()
481 { "rtc-sclk", "gpio-rtc-sclk", "moxa,moxart-rtc" }, in of_find_gpio_rename()
482 { "rtc-reset", "gpio-rtc-reset", "moxa,moxart-rtc" }, in of_find_gpio_rename()
485 { "reset", "reset-n-io", "marvell,nfc-i2c" }, in of_find_gpio_rename()
488 { "reset", "reset-n-io", "marvell,nfc-spi" }, in of_find_gpio_rename()
491 { "reset", "reset-n-io", "marvell,nfc-uart" }, in of_find_gpio_rename()
492 { "reset", "reset-n-io", "mrvl,nfc-uart" }, in of_find_gpio_rename()
496 { "reset", "gpios-reset", "lantiq,pci-xway" }, in of_find_gpio_rename()
502 * "foo-gpios" so we have this special kludge for them. in of_find_gpio_rename()
513 { "reset", "cirrus,gpio-nreset", "cirrus,cs42l56" }, in of_find_gpio_rename()
516 { "i2s1-in-sel-gpio1", NULL, "mediatek,mt2701-cs42448-machine" }, in of_find_gpio_rename()
517 { "i2s1-in-sel-gpio2", NULL, "mediatek,mt2701-cs42448-machine" }, in of_find_gpio_rename()
520 { "reset", "gpio-reset", "ti,tlv320aic3x" }, in of_find_gpio_rename()
521 { "reset", "gpio-reset", "ti,tlv320aic33" }, in of_find_gpio_rename()
522 { "reset", "gpio-reset", "ti,tlv320aic3007" }, in of_find_gpio_rename()
523 { "reset", "gpio-reset", "ti,tlv320aic3104" }, in of_find_gpio_rename()
524 { "reset", "gpio-reset", "ti,tlv320aic3106" }, in of_find_gpio_rename()
530 * "foo-gpios" so we have this special kludge for them. in of_find_gpio_rename()
532 { "miso", "gpio-miso", "spi-gpio" }, in of_find_gpio_rename()
533 { "mosi", "gpio-mosi", "spi-gpio" }, in of_find_gpio_rename()
534 { "sck", "gpio-sck", "spi-gpio" }, in of_find_gpio_rename()
538 * The old Freescale bindings use simply "gpios" as name in of_find_gpio_rename()
539 * for the chip select lines rather than "cs-gpios" like in of_find_gpio_rename()
544 { "cs", "gpios", "fsl,spi" }, in of_find_gpio_rename()
545 { "cs", "gpios", "aeroflexgaisler,spictrl" }, in of_find_gpio_rename()
548 { "cs", "gpios", "ibm,ppc4xx-spi" }, in of_find_gpio_rename()
554 * property without the compulsory "-gpios" suffix. in of_find_gpio_rename()
564 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
566 for (i = 0; i < ARRAY_SIZE(gpios); i++) { in of_find_gpio_rename()
567 if (strcmp(con_id, gpios[i].con_id)) in of_find_gpio_rename()
570 if (gpios[i].compatible && in of_find_gpio_rename()
571 !of_device_is_compatible(np, gpios[i].compatible)) in of_find_gpio_rename()
574 legacy_id = gpios[i].legacy_id ?: gpios[i].con_id; in of_find_gpio_rename()
577 pr_info("%s uses legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_gpio_rename()
583 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
595 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
597 if (!of_device_is_compatible(np, "mediatek,mt2701-cs42448-machine")) in of_find_mt2701_gpio()
598 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
600 if (!con_id || strcmp(con_id, "i2s1-in-sel")) in of_find_mt2701_gpio()
601 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
604 legacy_id = "i2s1-in-sel-gpio1"; in of_find_mt2701_gpio()
606 legacy_id = "i2s1-in-sel-gpio2"; in of_find_mt2701_gpio()
608 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
612 pr_info("%s is using legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_mt2701_gpio()
637 /* Try GPIO property "foo-gpios" and "foo-gpio" */ in of_find_gpio()
640 snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, in of_find_gpio()
665 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
670 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
672 * @dflags: gpiod_flags - optional GPIO initialization flags
691 chip_np = dev_of_node(&chip->gpiodev->dev); in of_parse_own_gpio()
693 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
699 ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp); in of_parse_own_gpio()
707 ret = of_property_read_u32_index(np, "gpios", idx * tmp + i, in of_parse_own_gpio()
721 else if (of_property_read_bool(np, "output-low")) in of_parse_own_gpio()
723 else if (of_property_read_bool(np, "output-high")) in of_parse_own_gpio()
728 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
731 if (name && of_property_read_string(np, "line-name", name)) in of_parse_own_gpio()
732 *name = np->name; in of_parse_own_gpio()
738 * of_gpiochip_add_hog - Add all hogs in a hog device node
763 desc->hog = hog; in of_gpiochip_add_hog()
771 * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
783 for_each_available_child_of_node(dev_of_node(&chip->gpiodev->dev), np) { in of_gpiochip_scan_gpios()
784 if (!of_property_read_bool(np, "gpio-hog")) in of_gpiochip_scan_gpios()
801 * of_gpiochip_remove_hog - Remove all hogs in a hog device node
811 if (desc->hog == hog) in of_gpiochip_remove_hog()
817 return device_match_of_node(&chip->gpiodev->dev, data); in of_gpiochip_match_node()
833 * This only supports adding and removing complete gpio-hog nodes. in of_gpio_notify()
834 * Modifying an existing gpio-hog node is not supported (except for in of_gpio_notify()
840 if (!of_property_read_bool(rd->dn, "gpio-hog")) in of_gpio_notify()
843 if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
846 chip = of_find_gpiochip_by_node(rd->dn->parent); in of_gpio_notify()
850 ret = of_gpiochip_add_hog(chip, rd->dn); in of_gpio_notify()
853 rd->dn); in of_gpio_notify()
854 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
860 if (!of_node_check_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
863 chip = of_find_gpiochip_by_node(rd->dn->parent); in of_gpio_notify()
867 of_gpiochip_remove_hog(chip, rd->dn); in of_gpio_notify()
868 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
881 * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags
897 * number and the flags from a single gpio cell -- this is possible, in of_gpio_simple_xlate()
900 if (gc->of_gpio_n_cells < 2) { in of_gpio_simple_xlate()
902 return -EINVAL; in of_gpio_simple_xlate()
905 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) in of_gpio_simple_xlate()
906 return -EINVAL; in of_gpio_simple_xlate()
908 if (gpiospec->args[0] >= gc->ngpio) in of_gpio_simple_xlate()
909 return -EINVAL; in of_gpio_simple_xlate()
912 *flags = gpiospec->args[1]; in of_gpio_simple_xlate()
914 return gpiospec->args[0]; in of_gpio_simple_xlate()
918 #include <linux/gpio/legacy-of-mm-gpiochip.h>
920 * of_mm_gpiochip_add_data - Add memory mapped GPIO chip (bank)
928 * - all the callbacks
929 * - of_gpio_n_cells
930 * - of_xlate callback (optional)
933 * - save_regs callback (optional)
937 * to manage GPIOs from the callbacks.
943 int ret = -ENOMEM; in of_mm_gpiochip_add_data()
944 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_add_data()
946 gc->label = kasprintf(GFP_KERNEL, "%pOF", np); in of_mm_gpiochip_add_data()
947 if (!gc->label) in of_mm_gpiochip_add_data()
950 mm_gc->regs = of_iomap(np, 0); in of_mm_gpiochip_add_data()
951 if (!mm_gc->regs) in of_mm_gpiochip_add_data()
954 gc->base = -1; in of_mm_gpiochip_add_data()
956 if (mm_gc->save_regs) in of_mm_gpiochip_add_data()
957 mm_gc->save_regs(mm_gc); in of_mm_gpiochip_add_data()
959 fwnode_handle_put(mm_gc->gc.fwnode); in of_mm_gpiochip_add_data()
960 mm_gc->gc.fwnode = fwnode_handle_get(of_fwnode_handle(np)); in of_mm_gpiochip_add_data()
969 iounmap(mm_gc->regs); in of_mm_gpiochip_add_data()
971 kfree(gc->label); in of_mm_gpiochip_add_data()
979 * of_mm_gpiochip_remove - Remove memory mapped GPIO chip (bank)
984 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_remove()
987 iounmap(mm_gc->regs); in of_mm_gpiochip_remove()
988 kfree(gc->label); in of_mm_gpiochip_remove()
1001 static const char group_names_propname[] = "gpio-ranges-group-names"; in of_gpiochip_add_pin_range()
1004 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add_pin_range()
1011 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, in of_gpiochip_add_pin_range()
1019 return -EPROBE_DEFER; in of_gpiochip_add_pin_range()
1043 pr_err("%pOF: Illegal gpio-range format.\n", in of_gpiochip_add_pin_range()
1085 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add()
1089 if (!chip->of_xlate) { in of_gpiochip_add()
1090 chip->of_gpio_n_cells = 2; in of_gpiochip_add()
1091 chip->of_xlate = of_gpio_simple_xlate; in of_gpiochip_add()
1094 if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS) in of_gpiochip_add()
1095 return -EINVAL; in of_gpiochip_add()
1112 of_node_put(dev_of_node(&chip->gpiodev->dev)); in of_gpiochip_remove()