Lines Matching +full:imx7d +full:- +full:pcie
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
53 * * %-EINVAL for an incorrectly formed "gpios" property, or
54 * * %-ENOENT for a missing "gpios" property.
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
81 * the counting of "cs-gpios" to count "gpios" transparent to the
86 * * %-EINVAL for an incorrectly formed "gpios" property, or
87 * * %-ENOENT for a missing "gpios" property.
98 !of_device_is_compatible(np, "ibm,ppc4xx-spi")) in of_gpio_spi_cs_get_count()
118 return ret ? ret : -ENOENT; in of_gpio_count()
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()
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()
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()
197 * The rb-gpios semantics was undocumented and qi,lb60 (along with in of_gpio_try_fixup_polarity()
200 * inverter on this board, it should be active-high. Let's fix that in of_gpio_try_fixup_polarity()
201 * here for older DTs so we can re-use the generic nand_gpio_waitrdy() in of_gpio_try_fixup_polarity()
204 { "qi,lb60", "rb-gpios", true }, in of_gpio_try_fixup_polarity()
209 * active-low signal. However, most of the device trees that in of_gpio_try_fixup_polarity()
211 * reset GPIO as active-high, and were also using wrong name in of_gpio_try_fixup_polarity()
214 { "lantiq,pci-xway", "gpio-reset", false }, in of_gpio_try_fixup_polarity()
222 { "ti,tsc2005", "reset-gpios", false }, in of_gpio_try_fixup_polarity()
249 { "fsl,imx25-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
250 { "fsl,imx27-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
251 { "fsl,imx28-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
252 { "fsl,imx6q-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
253 { "fsl,mvf600-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
254 { "fsl,imx6sx-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
255 { "fsl,imx6ul-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
256 { "fsl,imx8mq-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
257 { "fsl,imx8qm-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
258 { "fsl,s32v234-fec", "phy-reset-gpios", "phy-reset-active-high" }, in of_gpio_set_polarity_by_property()
261 { "fsl,imx6q-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
262 { "fsl,imx6sx-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
263 { "fsl,imx6qp-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
264 { "fsl,imx7d-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
265 { "fsl,imx8mq-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
266 { "fsl,imx8mm-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
267 { "fsl,imx8mp-pcie", "reset-gpio", "reset-gpio-active-high" }, in of_gpio_set_polarity_by_property()
272 * presence or absence of "enable-active-high" solely controls in of_gpio_set_polarity_by_property()
277 { "regulator-fixed", "gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
278 { "regulator-fixed", "gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
279 { "reg-fixed-voltage", "gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
280 { "reg-fixed-voltage", "gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
283 { "regulator-gpio", "enable-gpio", "enable-active-high" }, in of_gpio_set_polarity_by_property()
284 { "regulator-gpio", "enable-gpios", "enable-active-high" }, in of_gpio_set_polarity_by_property()
287 { "atmel,hsmci", "cd-gpios", "cd-inverted" }, in of_gpio_set_polarity_by_property()
298 if (of_device_is_compatible(np->parent, "atmel,hsmci")) { in of_gpio_set_polarity_by_property()
299 np_compat = np->parent; in of_gpio_set_polarity_by_property()
327 of_device_is_compatible(np, "reg-fixed-voltage") && in of_gpio_flags_quirks()
328 of_property_read_bool(np, "gpio-open-drain")) { in of_gpio_flags_quirks()
330 pr_info("%s uses legacy open drain flag - update the DTS if you can\n", in of_gpio_flags_quirks()
336 * property named "cs-gpios" we need to inspect the child node in of_gpio_flags_quirks()
339 if (IS_ENABLED(CONFIG_SPI_MASTER) && !strcmp(propname, "cs-gpios") && in of_gpio_flags_quirks()
340 of_property_read_bool(np, "cs-gpios")) { in of_gpio_flags_quirks()
352 * by just omitting "spi-cs-high" in the in of_gpio_flags_quirks()
357 * and has the "spi-cs-high" set, we get a in of_gpio_flags_quirks()
358 * conflict and the "spi-cs-high" flag will in of_gpio_flags_quirks()
362 "spi-cs-high"); in of_gpio_flags_quirks()
370 /* Legacy handling of stmmac's active-low PHY reset line */ in of_gpio_flags_quirks()
372 !strcmp(propname, "snps,reset-gpio") && in of_gpio_flags_quirks()
373 of_property_read_bool(np, "snps,reset-active-low")) in of_gpio_flags_quirks()
378 * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API
407 desc = ERR_PTR(-EPROBE_DEFER); in of_get_named_gpiod_flags()
419 pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", in of_get_named_gpiod_flags()
430 * of_get_named_gpio() - Get a GPIO number to use with GPIO API
492 const char *legacy_id; /* NULL - same as con_id */ in of_find_gpio_rename()
503 /* Himax LCD controllers used "gpios-reset" */ in of_find_gpio_rename()
504 { "reset", "gpios-reset", "himax,hx8357" }, in of_find_gpio_rename()
505 { "reset", "gpios-reset", "himax,hx8369" }, in of_find_gpio_rename()
511 { "rtc-data", "gpio-rtc-data", "moxa,moxart-rtc" }, in of_find_gpio_rename()
512 { "rtc-sclk", "gpio-rtc-sclk", "moxa,moxart-rtc" }, in of_find_gpio_rename()
513 { "rtc-reset", "gpio-rtc-reset", "moxa,moxart-rtc" }, in of_find_gpio_rename()
516 { "reset", "reset-n-io", "marvell,nfc-i2c" }, in of_find_gpio_rename()
519 { "reset", "reset-n-io", "marvell,nfc-spi" }, in of_find_gpio_rename()
522 { "reset", "reset-n-io", "marvell,nfc-uart" }, in of_find_gpio_rename()
523 { "reset", "reset-n-io", "mrvl,nfc-uart" }, in of_find_gpio_rename()
527 { "reset", "gpio-reset", "lantiq,pci-xway" }, in of_find_gpio_rename()
533 * "foo-gpios" so we have this special kludge for them. in of_find_gpio_rename()
544 { "reset", "cirrus,gpio-nreset", "cirrus,cs42l56" }, in of_find_gpio_rename()
547 { "i2s1-in-sel-gpio1", NULL, "mediatek,mt2701-cs42448-machine" }, in of_find_gpio_rename()
548 { "i2s1-in-sel-gpio2", NULL, "mediatek,mt2701-cs42448-machine" }, in of_find_gpio_rename()
551 { "reset", "gpio-reset", "ti,tlv320aic3x" }, in of_find_gpio_rename()
552 { "reset", "gpio-reset", "ti,tlv320aic33" }, in of_find_gpio_rename()
553 { "reset", "gpio-reset", "ti,tlv320aic3007" }, in of_find_gpio_rename()
554 { "reset", "gpio-reset", "ti,tlv320aic3104" }, in of_find_gpio_rename()
555 { "reset", "gpio-reset", "ti,tlv320aic3106" }, in of_find_gpio_rename()
561 * "foo-gpios" so we have this special kludge for them. in of_find_gpio_rename()
563 { "miso", "gpio-miso", "spi-gpio" }, in of_find_gpio_rename()
564 { "mosi", "gpio-mosi", "spi-gpio" }, in of_find_gpio_rename()
565 { "sck", "gpio-sck", "spi-gpio" }, in of_find_gpio_rename()
570 * for the chip select lines rather than "cs-gpios" like in of_find_gpio_rename()
579 { "cs", "gpios", "ibm,ppc4xx-spi" }, in of_find_gpio_rename()
585 * property without the compulsory "-gpios" suffix. in of_find_gpio_rename()
595 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
608 pr_info("%s uses legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_gpio_rename()
614 return ERR_PTR(-ENOENT); in of_find_gpio_rename()
626 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
628 if (!of_device_is_compatible(np, "mediatek,mt2701-cs42448-machine")) in of_find_mt2701_gpio()
629 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
631 if (!con_id || strcmp(con_id, "i2s1-in-sel")) in of_find_mt2701_gpio()
632 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
635 legacy_id = "i2s1-in-sel-gpio1"; in of_find_mt2701_gpio()
637 legacy_id = "i2s1-in-sel-gpio2"; in of_find_mt2701_gpio()
639 return ERR_PTR(-ENOENT); in of_find_mt2701_gpio()
643 pr_info("%s is using legacy gpio name '%s' instead of '%s-gpios'\n", in of_find_mt2701_gpio()
651 * and have the name "trigger-sources" no matter which kind of phandle it is
653 * we allow looking something up that is not named "foo-gpios".
663 return ERR_PTR(-ENOENT); in of_find_trigger_gpio()
665 if (!con_id || strcmp(con_id, "trigger-sources")) in of_find_trigger_gpio()
666 return ERR_PTR(-ENOENT); in of_find_trigger_gpio()
695 /* Try GPIO property "foo-gpios" and "foo-gpio" */ in of_find_gpio()
715 * of_parse_own_gpio() - Get a GPIO hog descriptor, names and flags for GPIO API
720 * @lflags: bitmask of gpio_lookup_flags GPIO_* values - returned from
722 * @dflags: gpiod_flags - optional GPIO initialization flags
742 chip_np = dev_of_node(&chip->gpiodev->dev); in of_parse_own_gpio()
744 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
750 ret = of_property_read_u32(chip_np, "#gpio-cells", &tmp); in of_parse_own_gpio()
772 else if (of_property_read_bool(np, "output-low")) in of_parse_own_gpio()
774 else if (of_property_read_bool(np, "output-high")) in of_parse_own_gpio()
779 return ERR_PTR(-EINVAL); in of_parse_own_gpio()
782 if (name && of_property_read_string(np, "line-name", name)) in of_parse_own_gpio()
783 *name = np->name; in of_parse_own_gpio()
789 * of_gpiochip_add_hog - Add all hogs in a hog device node
815 WRITE_ONCE(desc->hog, hog); in of_gpiochip_add_hog()
823 * of_gpiochip_scan_gpios - Scan gpio-controller for gpio definitions
836 for_each_available_child_of_node_scoped(dev_of_node(&chip->gpiodev->dev), np) { in of_gpiochip_scan_gpios()
837 if (!of_property_read_bool(np, "gpio-hog")) in of_gpiochip_scan_gpios()
852 * of_gpiochip_remove_hog - Remove all hogs in a hog device node
862 if (READ_ONCE(desc->hog) == hog) in of_gpiochip_remove_hog()
868 return device_match_of_node(&chip->gpiodev->dev, data); in of_gpiochip_match_node()
884 * This only supports adding and removing complete gpio-hog nodes. in of_gpio_notify()
885 * Modifying an existing gpio-hog node is not supported (except for in of_gpio_notify()
891 if (!of_property_read_bool(rd->dn, "gpio-hog")) in of_gpio_notify()
894 if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
897 gdev = of_find_gpio_device_by_node(rd->dn->parent); in of_gpio_notify()
901 ret = of_gpiochip_add_hog(gpio_device_get_chip(gdev), rd->dn); in of_gpio_notify()
904 rd->dn); in of_gpio_notify()
905 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
911 if (!of_node_check_flag(rd->dn, OF_POPULATED)) in of_gpio_notify()
914 gdev = of_find_gpio_device_by_node(rd->dn->parent); in of_gpio_notify()
918 of_gpiochip_remove_hog(gpio_device_get_chip(gdev), rd->dn); in of_gpio_notify()
919 of_node_clear_flag(rd->dn, OF_POPULATED); in of_gpio_notify()
932 * of_gpio_simple_xlate - translate gpiospec to the GPIO number and flags
951 * number and the flags from a single gpio cell -- this is possible, in of_gpio_simple_xlate()
954 if (gc->of_gpio_n_cells < 2) { in of_gpio_simple_xlate()
956 return -EINVAL; in of_gpio_simple_xlate()
959 if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) in of_gpio_simple_xlate()
960 return -EINVAL; in of_gpio_simple_xlate()
962 if (gpiospec->args[0] >= gc->ngpio) in of_gpio_simple_xlate()
963 return -EINVAL; in of_gpio_simple_xlate()
966 *flags = gpiospec->args[1]; in of_gpio_simple_xlate()
968 return gpiospec->args[0]; in of_gpio_simple_xlate()
972 #include <linux/gpio/legacy-of-mm-gpiochip.h>
974 * of_mm_gpiochip_add_data - Add memory mapped GPIO chip (bank)
982 * - all the callbacks
983 * - of_gpio_n_cells
984 * - of_xlate callback (optional)
987 * - save_regs callback (optional)
1000 int ret = -ENOMEM; in of_mm_gpiochip_add_data()
1001 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_add_data()
1003 gc->label = kasprintf(GFP_KERNEL, "%pOF", np); in of_mm_gpiochip_add_data()
1004 if (!gc->label) in of_mm_gpiochip_add_data()
1007 mm_gc->regs = of_iomap(np, 0); in of_mm_gpiochip_add_data()
1008 if (!mm_gc->regs) in of_mm_gpiochip_add_data()
1011 gc->base = -1; in of_mm_gpiochip_add_data()
1013 if (mm_gc->save_regs) in of_mm_gpiochip_add_data()
1014 mm_gc->save_regs(mm_gc); in of_mm_gpiochip_add_data()
1016 fwnode_handle_put(mm_gc->gc.fwnode); in of_mm_gpiochip_add_data()
1017 mm_gc->gc.fwnode = fwnode_handle_get(of_fwnode_handle(np)); in of_mm_gpiochip_add_data()
1026 iounmap(mm_gc->regs); in of_mm_gpiochip_add_data()
1028 kfree(gc->label); in of_mm_gpiochip_add_data()
1036 * of_mm_gpiochip_remove - Remove memory mapped GPIO chip (bank)
1041 struct gpio_chip *gc = &mm_gc->gc; in of_mm_gpiochip_remove()
1044 iounmap(mm_gc->regs); in of_mm_gpiochip_remove()
1045 kfree(gc->label); in of_mm_gpiochip_remove()
1058 static const char group_names_propname[] = "gpio-ranges-group-names"; in of_gpiochip_add_pin_range()
1061 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add_pin_range()
1068 ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, in of_gpiochip_add_pin_range()
1076 return -EPROBE_DEFER; in of_gpiochip_add_pin_range()
1079 if (pinspec.args[0] >= (chip->offset + chip->ngpio)) in of_gpiochip_add_pin_range()
1081 if (pinspec.args[0] + pinspec.args[2] <= chip->offset) in of_gpiochip_add_pin_range()
1098 if (chip->offset > pinspec.args[0]) { in of_gpiochip_add_pin_range()
1099 trim = chip->offset - pinspec.args[0]; in of_gpiochip_add_pin_range()
1100 pinspec.args[2] -= trim; in of_gpiochip_add_pin_range()
1104 pinspec.args[0] -= chip->offset; in of_gpiochip_add_pin_range()
1106 if ((pinspec.args[0] + pinspec.args[2]) > chip->ngpio) in of_gpiochip_add_pin_range()
1107 pinspec.args[2] = chip->ngpio - pinspec.args[0]; in of_gpiochip_add_pin_range()
1119 pr_err("%pOF: Illegal gpio-range format.\n", in of_gpiochip_add_pin_range()
1161 np = dev_of_node(&chip->gpiodev->dev); in of_gpiochip_add()
1165 if (!chip->of_xlate) { in of_gpiochip_add()
1166 chip->of_gpio_n_cells = 2; in of_gpiochip_add()
1167 chip->of_xlate = of_gpio_simple_xlate; in of_gpiochip_add()
1170 if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS) in of_gpiochip_add()
1171 return -EINVAL; in of_gpiochip_add()
1188 of_node_put(dev_of_node(&chip->gpiodev->dev)); in of_gpiochip_remove()