Lines Matching +full:spi +full:- +full:cs +full:- +full:high
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
51 * -EINVAL for an incorrectly formed gpios property, or
52 * -ENOENT for a missing gpios property
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
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()
87 if (!con_id || strcmp(con_id, "cs")) in of_gpio_spi_cs_get_count()
89 if (!of_device_is_compatible(np, "fsl,spi") && in of_gpio_spi_cs_get_count()
91 !of_device_is_compatible(np, "ibm,ppc4xx-spi")) 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()
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 * active-low signal. However, most of the device trees that in of_gpio_try_fixup_polarity()
201 * reset GPIO as active-high, and were also using wrong name in of_gpio_try_fixup_polarity()
204 { "lantiq,pci-xway", "gpio-reset", false }, in of_gpio_try_fixup_polarity()
208 * DTS for Nokia N900 incorrectly specified "active high" in of_gpio_try_fixup_polarity()
212 { "ti,tsc2005", "reset-gpios", false }, in of_gpio_try_fixup_polarity()
239 { "fsl,imx25-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
240 { "fsl,imx27-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
241 { "fsl,imx28-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
242 { "fsl,imx6q-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
243 { "fsl,mvf600-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
244 { "fsl,imx6sx-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
245 { "fsl,imx6ul-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
246 { "fsl,imx8mq-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
247 { "fsl,imx8qm-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
248 { "fsl,s32v234-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
251 { "fsl,imx6q-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
252 { "fsl,imx6sx-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
253 { "fsl,imx6qp-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
254 { "fsl,imx7d-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
255 { "fsl,imx8mq-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
256 { "fsl,imx8mm-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
257 { "fsl,imx8mp-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
262 * presence or absence of "enable-active-high" solely controls in of_gpio_set_polarity_by_property()
267 { "regulator-fixed", "gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
268 { "regulator-fixed", "gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
269 { "reg-fixed-voltage", "gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
270 { "reg-fixed-voltage", "gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
273 { "regulator-gpio", "enable-gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
274 { "regulator-gpio", "enable-gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
277 { "atmel,hsmci", "cd-gpios", "cd-inverted" }, in of_gpio_set_polarity_by_property()
288 if (of_device_is_compatible(np->parent, "atmel,hsmci")) { in of_gpio_set_polarity_by_property()
289 np_compat = np->parent; in of_gpio_set_polarity_by_property()
317 of_device_is_compatible(np, "reg-fixed-voltage") && in of_gpio_flags_quirks()
318 of_property_read_bool(np, "gpio-open-drain")) { in of_gpio_flags_quirks()
320 pr_info("%s uses legacy open drain flag - update the DTS if you can\n", in of_gpio_flags_quirks()
325 * Legacy handling of SPI active high chip select. If we have a in of_gpio_flags_quirks()
326 * property named "cs-gpios" we need to inspect the child node in of_gpio_flags_quirks()
329 if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") && in of_gpio_flags_quirks()
330 of_property_read_bool(np, "cs-gpios")) { in of_gpio_flags_quirks()
332 u32 cs; in of_gpio_flags_quirks() local
336 ret = of_property_read_u32(child, "reg", &cs); in of_gpio_flags_quirks()
339 if (cs == index) { in of_gpio_flags_quirks()
341 * SPI children have active low chip selects in of_gpio_flags_quirks()
343 * by just omitting "spi-cs-high" in the in of_gpio_flags_quirks()
348 * and has the "spi-cs-high" set, we get a in of_gpio_flags_quirks()
349 * conflict and the "spi-cs-high" flag will in of_gpio_flags_quirks()
353 "spi-cs-high"); in of_gpio_flags_quirks()
362 /* Legacy handling of stmmac's active-low PHY reset line */ in of_gpio_flags_quirks()
364 !strcmp(propname, "snps,reset-gpio") && in of_gpio_flags_quirks()
365 of_property_read_bool(np, "snps,reset-active-low")) in of_gpio_flags_quirks()
370 * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API
398 desc = ERR_PTR(-EPROBE_DEFER); in of_get_named_gpiod_flags()
409 pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", in of_get_named_gpiod_flags()
420 * of_get_named_gpio() - Get a GPIO number to use with GPIO API
479 const char *legacy_id; /* NULL - same as con_id */ in of_find_gpio_rename()
490 /* Himax LCD controllers used "gpios-reset" */ in of_find_gpio_rename()
491 { "reset", "gpios-reset", "himax,hx8357" }, in of_find_gpio_rename()
492 { "reset", "gpios-reset", "himax,hx8369" }, in of_find_gpio_rename()
498 { "rtc-data", "gpio-rtc-data", "moxa,moxart-rtc" }, in of_find_gpio_rename()
499 { "rtc-sclk", "gpio-rtc-sclk", "moxa,moxart-rtc" }, in of_find_gpio_rename()
500 { "rtc-reset", "gpio-rtc-reset", "moxa,moxart-rtc" }, in of_find_gpio_rename()
503 { "reset", "reset-n-io", "marvell,nfc-i2c" }, in of_find_gpio_rename()
506 { "reset", "reset-n-io", "marvell,nfc-spi" }, in of_find_gpio_rename()
509 { "reset", "reset-n-io", "marvell,nfc-uart" }, in of_find_gpio_rename()
510 { "reset", "reset-n-io", "mrvl,nfc-uart" }, in of_find_gpio_rename()
514 { "reset", "gpio-reset", "lantiq,pci-xway" }, in of_find_gpio_rename()
520 * "foo-gpios" so we have this special kludge for them. in of_find_gpio_rename()
531 { "reset", "cirrus,gpio-nreset", "cirrus,cs42l56" }, in of_find_gpio_rename()
534 { "i2s1-in-sel-gpio1", NULL, "mediatek,mt2701-cs42448-machine" }, in of_find_gpio_rename()
535 { "i2s1-in-sel-gpio2", NULL, "mediatek,mt2701-cs42448-machine" }, in of_find_gpio_rename()
538 { "reset", "gpio-reset", "ti,tlv320aic3x" }, in of_find_gpio_rename()
539 { "reset", "gpio-reset", "ti,tlv320aic33" }, in of_find_gpio_rename()
540 { "reset", "gpio-reset", "ti,tlv320aic3007" }, in of_find_gpio_rename()
541 { "reset", "gpio-reset", "ti,tlv320aic3104" }, in of_find_gpio_rename()
542 { "reset", "gpio-reset", "ti,tlv320aic3106" }, in of_find_gpio_rename()
546 * The SPI GPIO bindings happened before we managed to in of_find_gpio_rename()
548 * "foo-gpios" so we have this special kludge for them. in of_find_gpio_rename()
550 { "miso", "gpio-miso", "spi-gpio" }, in of_find_gpio_rename()
551 { "mosi", "gpio-mosi", "spi-gpio" }, in of_find_gpio_rename()
552 { "sck", "gpio-sck", "spi-gpio" }, in of_find_gpio_rename()
557 * for the chip select lines rather than "cs-gpios" like in of_find_gpio_rename()
558 * all other SPI hardware. Allow this specifically for in of_find_gpio_rename()
562 { "cs", "gpios", "fsl,spi" }, in of_find_gpio_rename()
563 { "cs", "gpios", "aeroflexgaisler,spictrl" }, in of_find_gpio_rename()
566 { "cs", "gpios", "ibm,ppc4xx-spi" }, in of_find_gpio_rename()
572 * property without the compulsory "-gpios" suffix. in of_find_gpio_rename()
582 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
595 pr_info("%s uses legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_gpio_rename()
601 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
613 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
615 if (!of_device_is_compatible(np, "mediatek,mt2701-cs42448-machine")) in of_find_mt2701_gpio()
616 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
618 if (!con_id || strcmp(con_id, "i2s1-in-sel")) in of_find_mt2701_gpio()
619 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
622 legacy_id = "i2s1-in-sel-gpio1"; in of_find_mt2701_gpio()
624 legacy_id = "i2s1-in-sel-gpio2"; in of_find_mt2701_gpio()
626 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
630 pr_info("%s is using legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_mt2701_gpio()
655 /* Try GPIO property "foo-gpios" and "foo-gpio" */ in of_find_gpio()
658 snprintf(prop_name, sizeof(prop_name), "%s-%s", con_id, in of_find_gpio()
683 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
688 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
690 * @dflags: gpiod_flags - optional GPIO initialization flags
709 chip_np = dev_of_node(&chip->gpiodev->dev); in of_parse_own_gpio()
711 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
717 ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp); in of_parse_own_gpio()
739 else if (of_property_read_bool(np, "output-low")) in of_parse_own_gpio()
741 else if (of_property_read_bool(np, "output-high")) in of_parse_own_gpio()
746 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
749 if (name && of_property_read_string(np, "line-name", name)) in of_parse_own_gpio()
750 *name = np->name; in of_parse_own_gpio()
756 * of_gpiochip_add_hog - Add all hogs in a hog device node
781 desc->hog = hog; in of_gpiochip_add_hog()
789 * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
801 for_each_available_child_of_node(dev_of_node(&chip->gpiodev->dev), np) { in of_gpiochip_scan_gpios()
802 if (!of_property_read_bool(np, "gpio-hog")) in of_gpiochip_scan_gpios()
819 * of_gpiochip_remove_hog - Remove all hogs in a hog device node
829 if (desc->hog == hog) in of_gpiochip_remove_hog()
835 return device_match_of_node(&chip->gpiodev->dev, data); in of_gpiochip_match_node()
851 * This only supports adding and removing complete gpio-hog nodes. in of_gpio_notify()
852 * Modifying an existing gpio-hog node is not supported (except for in of_gpio_notify()
858 if (!of_property_read_bool(rd->dn, "gpio-hog")) in of_gpio_notify()
861 if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
864 chip = of_find_gpiochip_by_node(rd->dn->parent); in of_gpio_notify()
868 ret = of_gpiochip_add_hog(chip, rd->dn); in of_gpio_notify()
871 rd->dn); in of_gpio_notify()
872 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
878 if (!of_node_check_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
881 chip = of_find_gpiochip_by_node(rd->dn->parent); in of_gpio_notify()
885 of_gpiochip_remove_hog(chip, rd->dn); in of_gpio_notify()
886 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
899 * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags
915 * number and the flags from a single gpio cell -- this is possible, in of_gpio_simple_xlate()
918 if (gc->of_gpio_n_cells < 2) { in of_gpio_simple_xlate()
920 return -EINVAL; in of_gpio_simple_xlate()
923 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) in of_gpio_simple_xlate()
924 return -EINVAL; in of_gpio_simple_xlate()
926 if (gpiospec->args[0] >= gc->ngpio) in of_gpio_simple_xlate()
927 return -EINVAL; in of_gpio_simple_xlate()
930 *flags = gpiospec->args[1]; in of_gpio_simple_xlate()
932 return gpiospec->args[0]; in of_gpio_simple_xlate()
936 #include <linux/gpio/legacy-of-mm-gpiochip.h>
938 * of_mm_gpiochip_add_data - Add memory mapped GPIO chip (bank)
946 * - all the callbacks
947 * - of_gpio_n_cells
948 * - of_xlate callback (optional)
951 * - save_regs callback (optional)
961 int ret = -ENOMEM; in of_mm_gpiochip_add_data()
962 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_add_data()
964 gc->label = kasprintf(GFP_KERNEL, "%pOF", np); in of_mm_gpiochip_add_data()
965 if (!gc->label) in of_mm_gpiochip_add_data()
968 mm_gc->regs = of_iomap(np, 0); in of_mm_gpiochip_add_data()
969 if (!mm_gc->regs) in of_mm_gpiochip_add_data()
972 gc->base = -1; in of_mm_gpiochip_add_data()
974 if (mm_gc->save_regs) in of_mm_gpiochip_add_data()
975 mm_gc->save_regs(mm_gc); in of_mm_gpiochip_add_data()
977 fwnode_handle_put(mm_gc->gc.fwnode); in of_mm_gpiochip_add_data()
978 mm_gc->gc.fwnode = fwnode_handle_get(of_fwnode_handle(np)); in of_mm_gpiochip_add_data()
987 iounmap(mm_gc->regs); in of_mm_gpiochip_add_data()
989 kfree(gc->label); in of_mm_gpiochip_add_data()
997 * of_mm_gpiochip_remove - Remove memory mapped GPIO chip (bank)
1002 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_remove()
1005 iounmap(mm_gc->regs); in of_mm_gpiochip_remove()
1006 kfree(gc->label); in of_mm_gpiochip_remove()
1019 static const char group_names_propname[] = "gpio-ranges-group-names"; in of_gpiochip_add_pin_range()
1022 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add_pin_range()
1029 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, in of_gpiochip_add_pin_range()
1037 return -EPROBE_DEFER; in of_gpiochip_add_pin_range()
1061 pr_err("%pOF: Illegal gpio-range format.\n", in of_gpiochip_add_pin_range()
1103 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add()
1107 if (!chip->of_xlate) { in of_gpiochip_add()
1108 chip->of_gpio_n_cells = 2; in of_gpiochip_add()
1109 chip->of_xlate = of_gpio_simple_xlate; in of_gpiochip_add()
1112 if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS) in of_gpiochip_add()
1113 return -EINVAL; in of_gpiochip_add()
1130 of_node_put(dev_of_node(&chip->gpiodev->dev)); in of_gpiochip_remove()