Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'ib-gpio-remove-of-gpio-h-for-v7.1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git into gpio/for-next

Immutable branch between GPIO and net

Convert remaining users of of_gpio.h to using GPIO descriptors and
remove the header.

+65 -222
-1
MAINTAINERS
··· 10959 10959 F: include/dt-bindings/gpio/ 10960 10960 F: include/linux/gpio.h 10961 10961 F: include/linux/gpio/ 10962 - F: include/linux/of_gpio.h 10963 10962 K: (devm_)?gpio_(request|free|direction|get|set) 10964 10963 K: GPIOD_FLAGS_BIT_NONEXCLUSIVE 10965 10964 K: devm_gpiod_unhinge
-28
drivers/gpio/TODO
··· 58 58 59 59 ------------------------------------------------------------------------------- 60 60 61 - Get rid of <linux/of_gpio.h> 62 - 63 - This header and helpers appeared at one point when there was no proper 64 - driver infrastructure for doing simpler MMIO GPIO devices and there was 65 - no core support for parsing device tree GPIOs from the core library with 66 - the [devm_]gpiod_get() calls we have today that will implicitly go into 67 - the device tree back-end. It is legacy and should not be used in new code. 68 - 69 - Work items: 70 - 71 - - Change all consumer drivers that #include <linux/of_gpio.h> to 72 - #include <linux/gpio/consumer.h> and stop doing custom parsing of the 73 - GPIO lines from the device tree. This can be tricky and often involves 74 - changing board files, etc. 75 - 76 - - Pull semantics for legacy device tree (OF) GPIO lookups into 77 - gpiolib-of.c: in some cases subsystems are doing custom flags and 78 - lookups for polarity inversion, open drain and what not. As we now 79 - handle this with generic OF bindings, pull all legacy handling into 80 - gpiolib so the library API becomes narrow and deep and handle all 81 - legacy bindings internally. (See e.g. commits 6953c57ab172, 82 - 6a537d48461d etc) 83 - 84 - - Delete <linux/of_gpio.h> when all the above is complete and everything 85 - uses <linux/gpio/consumer.h> or <linux/gpio/driver.h> instead. 86 - 87 - ------------------------------------------------------------------------------- 88 - 89 61 Collect drivers 90 62 91 63 Collect GPIO drivers from arch/* and other places that should be placed
+4 -27
drivers/gpio/gpiolib-of.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/of.h> 16 16 #include <linux/of_address.h> 17 - #include <linux/of_gpio.h> 18 17 #include <linux/pinctrl/pinctrl.h> 19 18 #include <linux/slab.h> 20 19 #include <linux/string.h> ··· 445 446 return desc; 446 447 } 447 448 448 - /** 449 - * of_get_named_gpio() - Get a GPIO number to use with GPIO API 450 - * @np: device node to get GPIO from 451 - * @propname: Name of property containing gpio specifier(s) 452 - * @index: index of the GPIO 453 - * 454 - * **DEPRECATED** This function is deprecated and must not be used in new code. 455 - * 456 - * Returns: 457 - * GPIO number to use with Linux generic GPIO API, or one of the errno 458 - * value on the error condition. 459 - */ 460 - int of_get_named_gpio(const struct device_node *np, const char *propname, 461 - int index) 462 - { 463 - struct gpio_desc *desc; 464 - 465 - desc = of_get_named_gpiod_flags(np, propname, index, NULL); 466 - 467 - if (IS_ERR(desc)) 468 - return PTR_ERR(desc); 469 - else 470 - return desc_to_gpio(desc); 471 - } 472 - EXPORT_SYMBOL_GPL(of_get_named_gpio); 473 - 474 449 /* Converts gpio_lookup_flags into bitmask of GPIO_* values */ 475 450 static unsigned long of_convert_gpio_flags(enum of_gpio_flags flags) 476 451 { ··· 514 541 #if IS_ENABLED(CONFIG_NFC_MRVL_UART) 515 542 { "reset", "reset-n-io", "marvell,nfc-uart" }, 516 543 { "reset", "reset-n-io", "mrvl,nfc-uart" }, 544 + #endif 545 + #if IS_ENABLED(CONFIG_NFC_S3FWRN5_I2C) 546 + { "en", "s3fwrn5,en-gpios", "samsung,s3fwrn5-i2c" }, 547 + { "wake", "s3fwrn5,fw-gpios", "samsung,s3fwrn5-i2c" }, 517 548 #endif 518 549 #if IS_ENABLED(CONFIG_PCI_LANTIQ) 519 550 /* MIPS Lantiq PCI */
+16 -31
drivers/nfc/nfcmrvl/main.c
··· 6 6 */ 7 7 8 8 #include <linux/module.h> 9 - #include <linux/gpio.h> 9 + #include <linux/gpio/consumer.h> 10 10 #include <linux/delay.h> 11 - #include <linux/of_gpio.h> 11 + #include <linux/of.h> 12 12 #include <linux/nfc.h> 13 13 #include <net/nfc/nci.h> 14 14 #include <net/nfc/nci_core.h> ··· 112 112 113 113 memcpy(&priv->config, pdata, sizeof(*pdata)); 114 114 115 - if (gpio_is_valid(priv->config.reset_n_io)) { 116 - rc = gpio_request_one(priv->config.reset_n_io, 117 - GPIOF_OUT_INIT_LOW, 118 - "nfcmrvl_reset_n"); 119 - if (rc < 0) { 120 - priv->config.reset_n_io = -EINVAL; 121 - nfc_err(dev, "failed to request reset_n io\n"); 115 + if (!priv->config.reset_gpio) { 116 + priv->config.reset_gpio = 117 + devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 118 + if (IS_ERR(priv->config.reset_gpio)) { 119 + priv->config.reset_gpio = NULL; 120 + nfc_err(dev, "failed to get reset gpio\n"); 122 121 } 123 122 } 124 123 ··· 143 144 if (!priv->ndev) { 144 145 nfc_err(dev, "nci_allocate_device failed\n"); 145 146 rc = -ENOMEM; 146 - goto error_free_gpio; 147 + goto error_free; 147 148 } 148 149 149 150 rc = nfcmrvl_fw_dnld_init(priv); ··· 170 171 nfcmrvl_fw_dnld_deinit(priv); 171 172 error_free_dev: 172 173 nci_free_device(priv->ndev); 173 - error_free_gpio: 174 - if (gpio_is_valid(priv->config.reset_n_io)) 175 - gpio_free(priv->config.reset_n_io); 174 + error_free: 176 175 kfree(priv); 177 176 return ERR_PTR(rc); 178 177 } ··· 185 188 nfcmrvl_fw_dnld_abort(priv); 186 189 187 190 nfcmrvl_fw_dnld_deinit(priv); 188 - 189 - if (gpio_is_valid(priv->config.reset_n_io)) 190 - gpio_free(priv->config.reset_n_io); 191 191 192 192 nci_free_device(ndev); 193 193 kfree(priv); ··· 227 233 /* Reset possible fault of previous session */ 228 234 clear_bit(NFCMRVL_PHY_ERROR, &priv->flags); 229 235 230 - if (gpio_is_valid(priv->config.reset_n_io)) { 236 + if (priv->config.reset_gpio) { 231 237 nfc_info(priv->dev, "reset the chip\n"); 232 - gpio_set_value(priv->config.reset_n_io, 0); 238 + gpiod_set_value(priv->config.reset_gpio, 1); 233 239 usleep_range(5000, 10000); 234 - gpio_set_value(priv->config.reset_n_io, 1); 240 + gpiod_set_value(priv->config.reset_gpio, 0); 235 241 } else 236 242 nfc_info(priv->dev, "no reset available on this interface\n"); 237 243 } 238 244 239 245 void nfcmrvl_chip_halt(struct nfcmrvl_private *priv) 240 246 { 241 - if (gpio_is_valid(priv->config.reset_n_io)) 242 - gpio_set_value(priv->config.reset_n_io, 0); 247 + if (priv->config.reset_gpio) 248 + gpiod_set_value(priv->config.reset_gpio, 1); 243 249 } 244 250 245 251 int nfcmrvl_parse_dt(struct device_node *node, 246 252 struct nfcmrvl_platform_data *pdata) 247 253 { 248 - int reset_n_io; 249 - 250 - reset_n_io = of_get_named_gpio(node, "reset-n-io", 0); 251 - if (reset_n_io < 0) { 252 - pr_info("no reset-n-io config\n"); 253 - } else if (!gpio_is_valid(reset_n_io)) { 254 - pr_err("invalid reset-n-io GPIO\n"); 255 - return reset_n_io; 256 - } 257 - pdata->reset_n_io = reset_n_io; 254 + pdata->reset_gpio = NULL; 258 255 pdata->hci_muxed = of_property_read_bool(node, "hci-muxed"); 259 256 260 257 return 0;
+3 -1
drivers/nfc/nfcmrvl/nfcmrvl.h
··· 10 10 11 11 #include "fw_dnld.h" 12 12 13 + struct gpio_desc; 14 + 13 15 /* Define private flags: */ 14 16 #define NFCMRVL_NCI_RUNNING 1 15 17 #define NFCMRVL_PHY_ERROR 2 ··· 56 54 */ 57 55 58 56 /* GPIO that is wired to RESET_N signal */ 59 - int reset_n_io; 57 + struct gpio_desc *reset_gpio; 60 58 /* Tell if transport is muxed in HCI one */ 61 59 bool hci_muxed; 62 60
+16 -7
drivers/nfc/nfcmrvl/uart.c
··· 8 8 #include <linux/delay.h> 9 9 #include <linux/device.h> 10 10 #include <linux/err.h> 11 + #include <linux/gpio/consumer.h> 11 12 #include <linux/module.h> 12 13 #include <linux/of.h> 13 14 #include <linux/printk.h> ··· 21 20 static unsigned int hci_muxed; 22 21 static unsigned int flow_control; 23 22 static unsigned int break_control; 24 - static int reset_n_io = -EINVAL; 25 23 26 24 /* 27 25 * NFCMRVL NCI OPS ··· 62 62 }; 63 63 64 64 static int nfcmrvl_uart_parse_dt(struct device_node *node, 65 - struct nfcmrvl_platform_data *pdata) 65 + struct nfcmrvl_platform_data *pdata, 66 + struct device *dev) 66 67 { 67 68 struct device_node *matched_node; 69 + struct gpio_desc *reset_gpio; 68 70 int ret; 69 71 70 72 matched_node = of_get_compatible_child(node, "marvell,nfc-uart"); ··· 85 83 86 84 pdata->flow_control = of_property_read_bool(matched_node, "flow-control"); 87 85 pdata->break_control = of_property_read_bool(matched_node, "break-control"); 86 + 87 + reset_gpio = devm_fwnode_gpiod_get_optional(dev, 88 + of_fwnode_handle(matched_node), 89 + "reset", GPIOD_OUT_HIGH, 90 + "nfcmrvl_reset_n"); 91 + if (IS_ERR(reset_gpio)) { 92 + of_node_put(matched_node); 93 + return PTR_ERR(reset_gpio); 94 + } 95 + pdata->reset_gpio = reset_gpio; 88 96 89 97 of_node_put(matched_node); 90 98 ··· 119 107 */ 120 108 121 109 if (dev && dev->parent && dev->parent->of_node) 122 - if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0) 110 + if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config, dev) == 0) 123 111 pdata = &config; 124 112 125 113 if (!pdata) { 126 114 pr_info("No platform data / DT -> fallback to module params\n"); 127 115 config.hci_muxed = hci_muxed; 128 - config.reset_n_io = reset_n_io; 116 + config.reset_gpio = NULL; 129 117 config.flow_control = flow_control; 130 118 config.break_control = break_control; 131 119 pdata = &config; ··· 213 201 214 202 module_param(hci_muxed, uint, 0); 215 203 MODULE_PARM_DESC(hci_muxed, "Tell if transport is muxed in HCI one."); 216 - 217 - module_param(reset_n_io, int, 0); 218 - MODULE_PARM_DESC(reset_n_io, "GPIO that is wired to RESET_N signal.");
+1 -1
drivers/nfc/nfcmrvl/usb.c
··· 294 294 295 295 /* No configuration for USB */ 296 296 memset(&config, 0, sizeof(config)); 297 - config.reset_n_io = -EINVAL; 297 + config.reset_gpio = NULL; 298 298 299 299 nfc_info(&udev->dev, "intf %p id %p\n", intf, id); 300 300
+7 -47
drivers/nfc/s3fwrn5/i2c.c
··· 8 8 9 9 #include <linux/clk.h> 10 10 #include <linux/i2c.h> 11 - #include <linux/gpio.h> 11 + #include <linux/gpio/consumer.h> 12 12 #include <linux/delay.h> 13 - #include <linux/of_gpio.h> 14 - #include <linux/of_irq.h> 15 13 #include <linux/module.h> 16 14 17 15 #include <net/nfc/nfc.h> ··· 144 146 return IRQ_HANDLED; 145 147 } 146 148 147 - static int s3fwrn5_i2c_parse_dt(struct i2c_client *client) 148 - { 149 - struct s3fwrn5_i2c_phy *phy = i2c_get_clientdata(client); 150 - struct device_node *np = client->dev.of_node; 151 - 152 - if (!np) 153 - return -ENODEV; 154 - 155 - phy->common.gpio_en = of_get_named_gpio(np, "en-gpios", 0); 156 - if (!gpio_is_valid(phy->common.gpio_en)) { 157 - /* Support also deprecated property */ 158 - phy->common.gpio_en = of_get_named_gpio(np, 159 - "s3fwrn5,en-gpios", 160 - 0); 161 - if (!gpio_is_valid(phy->common.gpio_en)) 162 - return -ENODEV; 163 - } 164 - 165 - phy->common.gpio_fw_wake = of_get_named_gpio(np, "wake-gpios", 0); 166 - if (!gpio_is_valid(phy->common.gpio_fw_wake)) { 167 - /* Support also deprecated property */ 168 - phy->common.gpio_fw_wake = of_get_named_gpio(np, 169 - "s3fwrn5,fw-gpios", 170 - 0); 171 - if (!gpio_is_valid(phy->common.gpio_fw_wake)) 172 - return -ENODEV; 173 - } 174 - 175 - return 0; 176 - } 177 - 178 149 static int s3fwrn5_i2c_probe(struct i2c_client *client) 179 150 { 180 151 struct s3fwrn5_i2c_phy *phy; ··· 160 193 phy->i2c_dev = client; 161 194 i2c_set_clientdata(client, phy); 162 195 163 - ret = s3fwrn5_i2c_parse_dt(client); 164 - if (ret < 0) 165 - return ret; 196 + phy->common.gpio_en = devm_gpiod_get(&client->dev, "en", GPIOD_OUT_HIGH); 197 + if (IS_ERR(phy->common.gpio_en)) 198 + return PTR_ERR(phy->common.gpio_en); 166 199 167 - ret = devm_gpio_request_one(&phy->i2c_dev->dev, phy->common.gpio_en, 168 - GPIOF_OUT_INIT_HIGH, "s3fwrn5_en"); 169 - if (ret < 0) 170 - return ret; 171 - 172 - ret = devm_gpio_request_one(&phy->i2c_dev->dev, 173 - phy->common.gpio_fw_wake, 174 - GPIOF_OUT_INIT_LOW, "s3fwrn5_fw_wake"); 175 - if (ret < 0) 176 - return ret; 200 + phy->common.gpio_fw_wake = devm_gpiod_get(&client->dev, "wake", GPIOD_OUT_LOW); 201 + if (IS_ERR(phy->common.gpio_fw_wake)) 202 + return PTR_ERR(phy->common.gpio_fw_wake); 177 203 178 204 /* 179 205 * S3FWRN5 depends on a clock input ("XI" pin) to function properly.
+5 -6
drivers/nfc/s3fwrn5/phy_common.c
··· 8 8 * Bongsu Jeon <bongsu.jeon@samsung.com> 9 9 */ 10 10 11 - #include <linux/gpio.h> 12 11 #include <linux/delay.h> 13 12 #include <linux/module.h> 14 13 ··· 18 19 struct phy_common *phy = phy_id; 19 20 20 21 mutex_lock(&phy->mutex); 21 - gpio_set_value(phy->gpio_fw_wake, wake); 22 + gpiod_set_value(phy->gpio_fw_wake, wake); 22 23 if (wake) 23 24 msleep(S3FWRN5_EN_WAIT_TIME); 24 25 mutex_unlock(&phy->mutex); ··· 32 33 33 34 phy->mode = mode; 34 35 35 - gpio_set_value(phy->gpio_en, 1); 36 - gpio_set_value(phy->gpio_fw_wake, 0); 36 + gpiod_set_value(phy->gpio_en, 1); 37 + gpiod_set_value(phy->gpio_fw_wake, 0); 37 38 if (mode == S3FWRN5_MODE_FW) 38 - gpio_set_value(phy->gpio_fw_wake, 1); 39 + gpiod_set_value(phy->gpio_fw_wake, 1); 39 40 40 41 if (mode != S3FWRN5_MODE_COLD) { 41 42 msleep(S3FWRN5_EN_WAIT_TIME); 42 - gpio_set_value(phy->gpio_en, 0); 43 + gpiod_set_value(phy->gpio_en, 0); 43 44 msleep(S3FWRN5_EN_WAIT_TIME); 44 45 } 45 46
+3 -2
drivers/nfc/s3fwrn5/phy_common.h
··· 12 12 #define __NFC_S3FWRN5_PHY_COMMON_H 13 13 14 14 #include <linux/mutex.h> 15 + #include <linux/gpio/consumer.h> 15 16 #include <net/nfc/nci_core.h> 16 17 17 18 #include "s3fwrn5.h" ··· 22 21 struct phy_common { 23 22 struct nci_dev *ndev; 24 23 25 - int gpio_en; 26 - int gpio_fw_wake; 24 + struct gpio_desc *gpio_en; 25 + struct gpio_desc *gpio_fw_wake; 27 26 28 27 struct mutex mutex; 29 28
+10 -33
drivers/nfc/s3fwrn5/uart.c
··· 10 10 11 11 #include <linux/device.h> 12 12 #include <linux/kernel.h> 13 + #include <linux/mod_devicetable.h> 13 14 #include <linux/module.h> 14 15 #include <linux/nfc.h> 15 16 #include <linux/netdevice.h> 16 - #include <linux/of.h> 17 17 #include <linux/serdev.h> 18 - #include <linux/gpio.h> 19 - #include <linux/of_gpio.h> 18 + #include <linux/gpio/consumer.h> 20 19 21 20 #include "phy_common.h" 22 21 ··· 87 88 }; 88 89 MODULE_DEVICE_TABLE(of, s3fwrn82_uart_of_match); 89 90 90 - static int s3fwrn82_uart_parse_dt(struct serdev_device *serdev) 91 - { 92 - struct s3fwrn82_uart_phy *phy = serdev_device_get_drvdata(serdev); 93 - struct device_node *np = serdev->dev.of_node; 94 - 95 - if (!np) 96 - return -ENODEV; 97 - 98 - phy->common.gpio_en = of_get_named_gpio(np, "en-gpios", 0); 99 - if (!gpio_is_valid(phy->common.gpio_en)) 100 - return -ENODEV; 101 - 102 - phy->common.gpio_fw_wake = of_get_named_gpio(np, "wake-gpios", 0); 103 - if (!gpio_is_valid(phy->common.gpio_fw_wake)) 104 - return -ENODEV; 105 - 106 - return 0; 107 - } 108 - 109 91 static int s3fwrn82_uart_probe(struct serdev_device *serdev) 110 92 { 111 93 struct s3fwrn82_uart_phy *phy; ··· 120 140 121 141 serdev_device_set_flow_control(serdev, false); 122 142 123 - ret = s3fwrn82_uart_parse_dt(serdev); 124 - if (ret < 0) 143 + phy->common.gpio_en = devm_gpiod_get(&serdev->dev, "en", GPIOD_OUT_HIGH); 144 + if (IS_ERR(phy->common.gpio_en)) { 145 + ret = PTR_ERR(phy->common.gpio_en); 125 146 goto err_serdev; 147 + } 126 148 127 - ret = devm_gpio_request_one(&phy->ser_dev->dev, phy->common.gpio_en, 128 - GPIOF_OUT_INIT_HIGH, "s3fwrn82_en"); 129 - if (ret < 0) 149 + phy->common.gpio_fw_wake = devm_gpiod_get(&serdev->dev, "wake", GPIOD_OUT_LOW); 150 + if (IS_ERR(phy->common.gpio_fw_wake)) { 151 + ret = PTR_ERR(phy->common.gpio_fw_wake); 130 152 goto err_serdev; 131 - 132 - ret = devm_gpio_request_one(&phy->ser_dev->dev, 133 - phy->common.gpio_fw_wake, 134 - GPIOF_OUT_INIT_LOW, "s3fwrn82_fw_wake"); 135 - if (ret < 0) 136 - goto err_serdev; 153 + } 137 154 138 155 ret = s3fwrn5_probe(&phy->common.ndev, phy, &phy->ser_dev->dev, 139 156 &uart_phy_ops);
-38
include/linux/of_gpio.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 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> 8 - */ 9 - 10 - #ifndef __LINUX_OF_GPIO_H 11 - #define __LINUX_OF_GPIO_H 12 - 13 - #include <linux/compiler.h> 14 - #include <linux/gpio/driver.h> 15 - #include <linux/gpio.h> /* FIXME: Shouldn't be here */ 16 - #include <linux/of.h> 17 - 18 - struct device_node; 19 - 20 - #ifdef CONFIG_OF_GPIO 21 - 22 - extern int of_get_named_gpio(const struct device_node *np, 23 - const char *list_name, int index); 24 - 25 - #else /* CONFIG_OF_GPIO */ 26 - 27 - #include <linux/errno.h> 28 - 29 - /* Drivers may not strictly depend on the GPIO support, so let them link. */ 30 - static inline int of_get_named_gpio(const struct device_node *np, 31 - const char *propname, int index) 32 - { 33 - return -ENOSYS; 34 - } 35 - 36 - #endif /* CONFIG_OF_GPIO */ 37 - 38 - #endif /* __LINUX_OF_GPIO_H */