gpiolib-of.c (1652a83fa494b12e20fc02a2cc3ddbcd75d53170) | gpiolib-of.c (dae5f0afcfc35ff64dfb65cddc6842ceeeca68c4) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 |
|
1/* 2 * OF helpers for the GPIO API 3 * 4 * Copyright (c) 2007-2008 MontaVista Software, Inc. 5 * 6 * Author: Anton Vorontsov <avorontsov@ru.mvista.com> | 2/* 3 * OF helpers for the GPIO API 4 * 5 * Copyright (c) 2007-2008 MontaVista Software, Inc. 6 * 7 * Author: Anton Vorontsov <avorontsov@ru.mvista.com> |
7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. | |
12 */ 13 14#include <linux/device.h> 15#include <linux/err.h> 16#include <linux/errno.h> 17#include <linux/module.h> 18#include <linux/io.h> 19#include <linux/gpio/consumer.h> --- 6 unchanged lines hidden (view full) --- 26 27#include "gpiolib.h" 28 29static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data) 30{ 31 struct of_phandle_args *gpiospec = data; 32 33 return chip->gpiodev->dev.of_node == gpiospec->np && | 8 */ 9 10#include <linux/device.h> 11#include <linux/err.h> 12#include <linux/errno.h> 13#include <linux/module.h> 14#include <linux/io.h> 15#include <linux/gpio/consumer.h> --- 6 unchanged lines hidden (view full) --- 22 23#include "gpiolib.h" 24 25static int of_gpiochip_match_node_and_xlate(struct gpio_chip *chip, void *data) 26{ 27 struct of_phandle_args *gpiospec = data; 28 29 return chip->gpiodev->dev.of_node == gpiospec->np && |
34 chip->of_xlate && | |
35 chip->of_xlate(chip, gpiospec, NULL) >= 0; 36} 37 38static struct gpio_chip *of_find_gpiochip_by_xlate( 39 struct of_phandle_args *gpiospec) 40{ 41 return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate); 42} --- 10 unchanged lines hidden (view full) --- 53 ret = chip->of_xlate(chip, gpiospec, flags); 54 if (ret < 0) 55 return ERR_PTR(ret); 56 57 return gpiochip_get_desc(chip, ret); 58} 59 60static void of_gpio_flags_quirks(struct device_node *np, | 30 chip->of_xlate(chip, gpiospec, NULL) >= 0; 31} 32 33static struct gpio_chip *of_find_gpiochip_by_xlate( 34 struct of_phandle_args *gpiospec) 35{ 36 return gpiochip_find(gpiospec, of_gpiochip_match_node_and_xlate); 37} --- 10 unchanged lines hidden (view full) --- 48 ret = chip->of_xlate(chip, gpiospec, flags); 49 if (ret < 0) 50 return ERR_PTR(ret); 51 52 return gpiochip_get_desc(chip, ret); 53} 54 55static void of_gpio_flags_quirks(struct device_node *np, |
61 enum of_gpio_flags *flags) | 56 enum of_gpio_flags *flags, 57 int index) |
62{ 63 /* 64 * Some GPIO fixed regulator quirks. 65 * Note that active low is the default. 66 */ 67 if (IS_ENABLED(CONFIG_REGULATOR) && 68 (of_device_is_compatible(np, "regulator-fixed") || 69 of_device_is_compatible(np, "reg-fixed-voltage") || --- 17 unchanged lines hidden (view full) --- 87 */ 88 if (IS_ENABLED(CONFIG_REGULATOR) && 89 of_device_is_compatible(np, "reg-fixed-voltage") && 90 of_property_read_bool(np, "gpio-open-drain")) { 91 *flags |= (OF_GPIO_SINGLE_ENDED | OF_GPIO_OPEN_DRAIN); 92 pr_info("%s uses legacy open drain flag - update the DTS if you can\n", 93 of_node_full_name(np)); 94 } | 58{ 59 /* 60 * Some GPIO fixed regulator quirks. 61 * Note that active low is the default. 62 */ 63 if (IS_ENABLED(CONFIG_REGULATOR) && 64 (of_device_is_compatible(np, "regulator-fixed") || 65 of_device_is_compatible(np, "reg-fixed-voltage") || --- 17 unchanged lines hidden (view full) --- 83 */ 84 if (IS_ENABLED(CONFIG_REGULATOR) && 85 of_device_is_compatible(np, "reg-fixed-voltage") && 86 of_property_read_bool(np, "gpio-open-drain")) { 87 *flags |= (OF_GPIO_SINGLE_ENDED | OF_GPIO_OPEN_DRAIN); 88 pr_info("%s uses legacy open drain flag - update the DTS if you can\n", 89 of_node_full_name(np)); 90 } |
91 92 /* 93 * Legacy handling of SPI active high chip select. If we have a 94 * property named "cs-gpios" we need to inspect the child node 95 * to determine if the flags should have inverted semantics. 96 */ 97 if (IS_ENABLED(CONFIG_SPI_MASTER) && 98 of_property_read_bool(np, "cs-gpios")) { 99 struct device_node *child; 100 u32 cs; 101 int ret; 102 103 for_each_child_of_node(np, child) { 104 ret = of_property_read_u32(child, "reg", &cs); 105 if (!ret) 106 continue; 107 if (cs == index) { 108 /* 109 * SPI children have active low chip selects 110 * by default. This can be specified negatively 111 * by just omitting "spi-cs-high" in the 112 * device node, or actively by tagging on 113 * GPIO_ACTIVE_LOW as flag in the device 114 * tree. If the line is simultaneously 115 * tagged as active low in the device tree 116 * and has the "spi-cs-high" set, we get a 117 * conflict and the "spi-cs-high" flag will 118 * take precedence. 119 */ 120 if (of_property_read_bool(np, "spi-cs-high")) { 121 if (*flags & OF_GPIO_ACTIVE_LOW) { 122 pr_warn("%s GPIO handle specifies active low - ignored\n", 123 of_node_full_name(np)); 124 *flags &= ~OF_GPIO_ACTIVE_LOW; 125 } 126 } else { 127 if (!(*flags & OF_GPIO_ACTIVE_LOW)) 128 pr_info("%s enforce active low on chipselect handle\n", 129 of_node_full_name(np)); 130 *flags |= OF_GPIO_ACTIVE_LOW; 131 } 132 break; 133 } 134 } 135 } |
|
95} 96 97/** 98 * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API 99 * @np: device node to get GPIO from 100 * @propname: property name containing gpio specifier(s) 101 * @index: index of the GPIO 102 * @flags: a flags pointer to fill in --- 24 unchanged lines hidden (view full) --- 127 goto out; 128 } 129 130 desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, flags); 131 if (IS_ERR(desc)) 132 goto out; 133 134 if (flags) | 136} 137 138/** 139 * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API 140 * @np: device node to get GPIO from 141 * @propname: property name containing gpio specifier(s) 142 * @index: index of the GPIO 143 * @flags: a flags pointer to fill in --- 24 unchanged lines hidden (view full) --- 168 goto out; 169 } 170 171 desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, flags); 172 if (IS_ERR(desc)) 173 goto out; 174 175 if (flags) |
135 of_gpio_flags_quirks(np, flags); | 176 of_gpio_flags_quirks(np, flags, index); |
136 137 pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", 138 __func__, propname, np, index, 139 PTR_ERR_OR_ZERO(desc)); 140 141out: 142 of_node_put(gpiospec.np); 143 --- 200 unchanged lines hidden (view full) --- 344 345 if (of_property_read_bool(np, "input")) 346 *dflags |= GPIOD_IN; 347 else if (of_property_read_bool(np, "output-low")) 348 *dflags |= GPIOD_OUT_LOW; 349 else if (of_property_read_bool(np, "output-high")) 350 *dflags |= GPIOD_OUT_HIGH; 351 else { | 177 178 pr_debug("%s: parsed '%s' property of node '%pOF[%d]' - status (%d)\n", 179 __func__, propname, np, index, 180 PTR_ERR_OR_ZERO(desc)); 181 182out: 183 of_node_put(gpiospec.np); 184 --- 200 unchanged lines hidden (view full) --- 385 386 if (of_property_read_bool(np, "input")) 387 *dflags |= GPIOD_IN; 388 else if (of_property_read_bool(np, "output-low")) 389 *dflags |= GPIOD_OUT_LOW; 390 else if (of_property_read_bool(np, "output-high")) 391 *dflags |= GPIOD_OUT_HIGH; 392 else { |
352 pr_warn("GPIO line %d (%s): no hogging state specified, bailing out\n", 353 desc_to_gpio(desc), np->name); | 393 pr_warn("GPIO line %d (%pOFn): no hogging state specified, bailing out\n", 394 desc_to_gpio(desc), np); |
354 return ERR_PTR(-EINVAL); 355 } 356 357 if (name && of_property_read_string(np, "line-name", name)) 358 *name = np->name; 359 360 return desc; 361} --- 295 unchanged lines hidden --- | 395 return ERR_PTR(-EINVAL); 396 } 397 398 if (name && of_property_read_string(np, "line-name", name)) 399 *name = np->name; 400 401 return desc; 402} --- 295 unchanged lines hidden --- |