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 { "reset", "gpio-reset", "ti,tlv320aic3x" }, in of_find_gpio_rename()
517 { "reset", "gpio-reset", "ti,tlv320aic33" }, in of_find_gpio_rename()
518 { "reset", "gpio-reset", "ti,tlv320aic3007" }, in of_find_gpio_rename()
519 { "reset", "gpio-reset", "ti,tlv320aic3104" }, in of_find_gpio_rename()
520 { "reset", "gpio-reset", "ti,tlv320aic3106" }, in of_find_gpio_rename()
526 * "foo-gpios" so we have this special kludge for them. in of_find_gpio_rename()
528 { "miso", "gpio-miso", "spi-gpio" }, in of_find_gpio_rename()
529 { "mosi", "gpio-mosi", "spi-gpio" }, in of_find_gpio_rename()
530 { "sck", "gpio-sck", "spi-gpio" }, in of_find_gpio_rename()
534 * The old Freescale bindings use simply "gpios" as name in of_find_gpio_rename()
535 * for the chip select lines rather than "cs-gpios" like in of_find_gpio_rename()
540 { "cs", "gpios", "fsl,spi" }, in of_find_gpio_rename()
541 { "cs", "gpios", "aeroflexgaisler,spictrl" }, in of_find_gpio_rename()
544 { "cs", "gpios", "ibm,ppc4xx-spi" }, in of_find_gpio_rename()
550 * property without the compulsory "-gpios" suffix. in of_find_gpio_rename()
560 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
562 for (i = 0; i < ARRAY_SIZE(gpios); i++) { in of_find_gpio_rename()
563 if (strcmp(con_id, gpios[i].con_id)) in of_find_gpio_rename()
566 if (gpios[i].compatible && in of_find_gpio_rename()
567 !of_device_is_compatible(np, gpios[i].compatible)) in of_find_gpio_rename()
570 legacy_id = gpios[i].legacy_id ?: gpios[i].con_id; in of_find_gpio_rename()
573 pr_info("%s uses legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_gpio_rename()
579 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
591 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
593 if (!of_device_is_compatible(np, "mediatek,mt2701-cs42448-machine")) in of_find_mt2701_gpio()
594 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
596 if (!con_id || strcmp(con_id, "i2s1-in-sel")) in of_find_mt2701_gpio()
597 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
600 legacy_id = "i2s1-in-sel-gpio1"; in of_find_mt2701_gpio()
602 legacy_id = "i2s1-in-sel-gpio2"; in of_find_mt2701_gpio()
604 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
608 pr_info("%s is using legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_mt2701_gpio()
633 /* Try GPIO property "foo-gpios" and "foo-gpio" */ in of_find_gpio()
636 snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, in of_find_gpio()
661 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
666 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
668 * @dflags: gpiod_flags - optional GPIO initialization flags
687 chip_np = dev_of_node(&chip->gpiodev->dev); in of_parse_own_gpio()
689 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
695 ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp); in of_parse_own_gpio()
703 ret = of_property_read_u32_index(np, "gpios", idx * tmp + i, in of_parse_own_gpio()
717 else if (of_property_read_bool(np, "output-low")) in of_parse_own_gpio()
719 else if (of_property_read_bool(np, "output-high")) in of_parse_own_gpio()
724 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
727 if (name && of_property_read_string(np, "line-name", name)) in of_parse_own_gpio()
728 *name = np->name; in of_parse_own_gpio()
734 * of_gpiochip_add_hog - Add all hogs in a hog device node
759 desc->hog = hog; in of_gpiochip_add_hog()
767 * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
779 for_each_available_child_of_node(dev_of_node(&chip->gpiodev->dev), np) { in of_gpiochip_scan_gpios()
780 if (!of_property_read_bool(np, "gpio-hog")) in of_gpiochip_scan_gpios()
797 * of_gpiochip_remove_hog - Remove all hogs in a hog device node
807 if (desc->hog == hog) in of_gpiochip_remove_hog()
813 return device_match_of_node(&chip->gpiodev->dev, data); in of_gpiochip_match_node()
829 * This only supports adding and removing complete gpio-hog nodes. in of_gpio_notify()
830 * Modifying an existing gpio-hog node is not supported (except for in of_gpio_notify()
836 if (!of_property_read_bool(rd->dn, "gpio-hog")) in of_gpio_notify()
839 if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
842 chip = of_find_gpiochip_by_node(rd->dn->parent); in of_gpio_notify()
846 ret = of_gpiochip_add_hog(chip, rd->dn); in of_gpio_notify()
849 rd->dn); in of_gpio_notify()
850 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
856 if (!of_node_check_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
859 chip = of_find_gpiochip_by_node(rd->dn->parent); in of_gpio_notify()
863 of_gpiochip_remove_hog(chip, rd->dn); in of_gpio_notify()
864 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
877 * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags
893 * number and the flags from a single gpio cell -- this is possible, in of_gpio_simple_xlate()
896 if (gc->of_gpio_n_cells < 2) { in of_gpio_simple_xlate()
898 return -EINVAL; in of_gpio_simple_xlate()
901 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) in of_gpio_simple_xlate()
902 return -EINVAL; in of_gpio_simple_xlate()
904 if (gpiospec->args[0] >= gc->ngpio) in of_gpio_simple_xlate()
905 return -EINVAL; in of_gpio_simple_xlate()
908 *flags = gpiospec->args[1]; in of_gpio_simple_xlate()
910 return gpiospec->args[0]; in of_gpio_simple_xlate()
914 #include <linux/gpio/legacy-of-mm-gpiochip.h>
916 * of_mm_gpiochip_add_data - Add memory mapped GPIO chip (bank)
924 * - all the callbacks
925 * - of_gpio_n_cells
926 * - of_xlate callback (optional)
929 * - save_regs callback (optional)
933 * to manage GPIOs from the callbacks.
939 int ret = -ENOMEM; in of_mm_gpiochip_add_data()
940 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_add_data()
942 gc->label = kasprintf(GFP_KERNEL, "%pOF", np); in of_mm_gpiochip_add_data()
943 if (!gc->label) in of_mm_gpiochip_add_data()
946 mm_gc->regs = of_iomap(np, 0); in of_mm_gpiochip_add_data()
947 if (!mm_gc->regs) in of_mm_gpiochip_add_data()
950 gc->base = -1; in of_mm_gpiochip_add_data()
952 if (mm_gc->save_regs) in of_mm_gpiochip_add_data()
953 mm_gc->save_regs(mm_gc); in of_mm_gpiochip_add_data()
955 fwnode_handle_put(mm_gc->gc.fwnode); in of_mm_gpiochip_add_data()
956 mm_gc->gc.fwnode = fwnode_handle_get(of_fwnode_handle(np)); in of_mm_gpiochip_add_data()
965 iounmap(mm_gc->regs); in of_mm_gpiochip_add_data()
967 kfree(gc->label); in of_mm_gpiochip_add_data()
975 * of_mm_gpiochip_remove - Remove memory mapped GPIO chip (bank)
980 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_remove()
983 iounmap(mm_gc->regs); in of_mm_gpiochip_remove()
984 kfree(gc->label); in of_mm_gpiochip_remove()
997 static const char group_names_propname[] = "gpio-ranges-group-names"; in of_gpiochip_add_pin_range()
1000 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add_pin_range()
1007 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, in of_gpiochip_add_pin_range()
1015 return -EPROBE_DEFER; in of_gpiochip_add_pin_range()
1039 pr_err("%pOF: Illegal gpio-range format.\n", in of_gpiochip_add_pin_range()
1081 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add()
1085 if (!chip->of_xlate) { in of_gpiochip_add()
1086 chip->of_gpio_n_cells = 2; in of_gpiochip_add()
1087 chip->of_xlate = of_gpio_simple_xlate; in of_gpiochip_add()
1090 if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS) in of_gpiochip_add()
1091 return -EINVAL; in of_gpiochip_add()
1108 of_node_put(dev_of_node(&chip->gpiodev->dev)); in of_gpiochip_remove()