Skip to content

Commit e0c8104

Browse files
author
Bartosz Golaszewski
committed
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.
2 parents c452588 + b6420bd commit e0c8104

12 files changed

Lines changed: 65 additions & 222 deletions

File tree

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10959,7 +10959,6 @@ F: drivers/gpio/
1095910959
F: include/dt-bindings/gpio/
1096010960
F: include/linux/gpio.h
1096110961
F: include/linux/gpio/
10962-
F: include/linux/of_gpio.h
1096310962
K: (devm_)?gpio_(request|free|direction|get|set)
1096410963
K: GPIOD_FLAGS_BIT_NONEXCLUSIVE
1096510964
K: devm_gpiod_unhinge

drivers/gpio/TODO

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,6 @@ Work items:
5858

5959
-------------------------------------------------------------------------------
6060

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-
8961
Collect drivers
9062

9163
Collect GPIO drivers from arch/* and other places that should be placed

drivers/gpio/gpiolib-of.c

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <linux/module.h>
1515
#include <linux/of.h>
1616
#include <linux/of_address.h>
17-
#include <linux/of_gpio.h>
1817
#include <linux/pinctrl/pinctrl.h>
1918
#include <linux/slab.h>
2019
#include <linux/string.h>
@@ -446,32 +445,6 @@ static struct gpio_desc *of_get_named_gpiod_flags(const struct device_node *np,
446445
return desc;
447446
}
448447

449-
/**
450-
* of_get_named_gpio() - Get a GPIO number to use with GPIO API
451-
* @np: device node to get GPIO from
452-
* @propname: Name of property containing gpio specifier(s)
453-
* @index: index of the GPIO
454-
*
455-
* **DEPRECATED** This function is deprecated and must not be used in new code.
456-
*
457-
* Returns:
458-
* GPIO number to use with Linux generic GPIO API, or one of the errno
459-
* value on the error condition.
460-
*/
461-
int of_get_named_gpio(const struct device_node *np, const char *propname,
462-
int index)
463-
{
464-
struct gpio_desc *desc;
465-
466-
desc = of_get_named_gpiod_flags(np, propname, index, NULL);
467-
468-
if (IS_ERR(desc))
469-
return PTR_ERR(desc);
470-
else
471-
return desc_to_gpio(desc);
472-
}
473-
EXPORT_SYMBOL_GPL(of_get_named_gpio);
474-
475448
/* Converts gpio_lookup_flags into bitmask of GPIO_* values */
476449
static unsigned long of_convert_gpio_flags(enum of_gpio_flags flags)
477450
{
@@ -542,6 +515,10 @@ static struct gpio_desc *of_find_gpio_rename(struct device_node *np,
542515
{ "reset", "reset-n-io", "marvell,nfc-uart" },
543516
{ "reset", "reset-n-io", "mrvl,nfc-uart" },
544517
#endif
518+
#if IS_ENABLED(CONFIG_NFC_S3FWRN5_I2C)
519+
{ "en", "s3fwrn5,en-gpios", "samsung,s3fwrn5-i2c" },
520+
{ "wake", "s3fwrn5,fw-gpios", "samsung,s3fwrn5-i2c" },
521+
#endif
545522
#if IS_ENABLED(CONFIG_PCI_LANTIQ)
546523
/* MIPS Lantiq PCI */
547524
{ "reset", "gpio-reset", "lantiq,pci-xway" },

drivers/nfc/nfcmrvl/main.c

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
*/
77

88
#include <linux/module.h>
9-
#include <linux/gpio.h>
9+
#include <linux/gpio/consumer.h>
1010
#include <linux/delay.h>
11-
#include <linux/of_gpio.h>
11+
#include <linux/of.h>
1212
#include <linux/nfc.h>
1313
#include <net/nfc/nci.h>
1414
#include <net/nfc/nci_core.h>
@@ -112,13 +112,12 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy,
112112

113113
memcpy(&priv->config, pdata, sizeof(*pdata));
114114

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");
122121
}
123122
}
124123

@@ -144,7 +143,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy,
144143
if (!priv->ndev) {
145144
nfc_err(dev, "nci_allocate_device failed\n");
146145
rc = -ENOMEM;
147-
goto error_free_gpio;
146+
goto error_free;
148147
}
149148

150149
rc = nfcmrvl_fw_dnld_init(priv);
@@ -171,9 +170,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy,
171170
nfcmrvl_fw_dnld_deinit(priv);
172171
error_free_dev:
173172
nci_free_device(priv->ndev);
174-
error_free_gpio:
175-
if (gpio_is_valid(priv->config.reset_n_io))
176-
gpio_free(priv->config.reset_n_io);
173+
error_free:
177174
kfree(priv);
178175
return ERR_PTR(rc);
179176
}
@@ -189,9 +186,6 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv)
189186

190187
nfcmrvl_fw_dnld_deinit(priv);
191188

192-
if (gpio_is_valid(priv->config.reset_n_io))
193-
gpio_free(priv->config.reset_n_io);
194-
195189
nci_free_device(ndev);
196190
kfree(priv);
197191
}
@@ -233,34 +227,25 @@ void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)
233227
/* Reset possible fault of previous session */
234228
clear_bit(NFCMRVL_PHY_ERROR, &priv->flags);
235229

236-
if (gpio_is_valid(priv->config.reset_n_io)) {
230+
if (priv->config.reset_gpio) {
237231
nfc_info(priv->dev, "reset the chip\n");
238-
gpio_set_value(priv->config.reset_n_io, 0);
232+
gpiod_set_value(priv->config.reset_gpio, 1);
239233
usleep_range(5000, 10000);
240-
gpio_set_value(priv->config.reset_n_io, 1);
234+
gpiod_set_value(priv->config.reset_gpio, 0);
241235
} else
242236
nfc_info(priv->dev, "no reset available on this interface\n");
243237
}
244238

245239
void nfcmrvl_chip_halt(struct nfcmrvl_private *priv)
246240
{
247-
if (gpio_is_valid(priv->config.reset_n_io))
248-
gpio_set_value(priv->config.reset_n_io, 0);
241+
if (priv->config.reset_gpio)
242+
gpiod_set_value(priv->config.reset_gpio, 1);
249243
}
250244

251245
int nfcmrvl_parse_dt(struct device_node *node,
252246
struct nfcmrvl_platform_data *pdata)
253247
{
254-
int reset_n_io;
255-
256-
reset_n_io = of_get_named_gpio(node, "reset-n-io", 0);
257-
if (reset_n_io < 0) {
258-
pr_info("no reset-n-io config\n");
259-
} else if (!gpio_is_valid(reset_n_io)) {
260-
pr_err("invalid reset-n-io GPIO\n");
261-
return reset_n_io;
262-
}
263-
pdata->reset_n_io = reset_n_io;
248+
pdata->reset_gpio = NULL;
264249
pdata->hci_muxed = of_property_read_bool(node, "hci-muxed");
265250

266251
return 0;

drivers/nfc/nfcmrvl/nfcmrvl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include "fw_dnld.h"
1212

13+
struct gpio_desc;
14+
1315
/* Define private flags: */
1416
#define NFCMRVL_NCI_RUNNING 1
1517
#define NFCMRVL_PHY_ERROR 2
@@ -54,7 +56,7 @@ struct nfcmrvl_platform_data {
5456
*/
5557

5658
/* GPIO that is wired to RESET_N signal */
57-
int reset_n_io;
59+
struct gpio_desc *reset_gpio;
5860
/* Tell if transport is muxed in HCI one */
5961
bool hci_muxed;
6062

drivers/nfc/nfcmrvl/uart.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/delay.h>
99
#include <linux/device.h>
1010
#include <linux/err.h>
11+
#include <linux/gpio/consumer.h>
1112
#include <linux/module.h>
1213
#include <linux/of.h>
1314
#include <linux/printk.h>
@@ -20,7 +21,6 @@
2021
static unsigned int hci_muxed;
2122
static unsigned int flow_control;
2223
static unsigned int break_control;
23-
static int reset_n_io = -EINVAL;
2424

2525
/*
2626
* NFCMRVL NCI OPS
@@ -62,9 +62,11 @@ static const struct nfcmrvl_if_ops uart_ops = {
6262
};
6363

6464
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)
6667
{
6768
struct device_node *matched_node;
69+
struct gpio_desc *reset_gpio;
6870
int ret;
6971

7072
matched_node = of_get_compatible_child(node, "marvell,nfc-uart");
@@ -84,6 +86,16 @@ static int nfcmrvl_uart_parse_dt(struct device_node *node,
8486
pdata->flow_control = of_property_read_bool(matched_node, "flow-control");
8587
pdata->break_control = of_property_read_bool(matched_node, "break-control");
8688

89+
reset_gpio = devm_fwnode_gpiod_get_optional(dev,
90+
of_fwnode_handle(matched_node),
91+
"reset", GPIOD_OUT_HIGH,
92+
"nfcmrvl_reset_n");
93+
if (IS_ERR(reset_gpio)) {
94+
of_node_put(matched_node);
95+
return PTR_ERR(reset_gpio);
96+
}
97+
pdata->reset_gpio = reset_gpio;
98+
8799
of_node_put(matched_node);
88100

89101
return 0;
@@ -107,13 +119,13 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu)
107119
*/
108120

109121
if (dev && dev->parent && dev->parent->of_node)
110-
if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0)
122+
if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config, dev) == 0)
111123
pdata = &config;
112124

113125
if (!pdata) {
114126
pr_info("No platform data / DT -> fallback to module params\n");
115127
config.hci_muxed = hci_muxed;
116-
config.reset_n_io = reset_n_io;
128+
config.reset_gpio = NULL;
117129
config.flow_control = flow_control;
118130
config.break_control = break_control;
119131
pdata = &config;
@@ -201,6 +213,3 @@ MODULE_PARM_DESC(break_control, "Tell if UART driver must drive break signal.");
201213

202214
module_param(hci_muxed, uint, 0);
203215
MODULE_PARM_DESC(hci_muxed, "Tell if transport is muxed in HCI one.");
204-
205-
module_param(reset_n_io, int, 0);
206-
MODULE_PARM_DESC(reset_n_io, "GPIO that is wired to RESET_N signal.");

drivers/nfc/nfcmrvl/usb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static int nfcmrvl_probe(struct usb_interface *intf,
294294

295295
/* No configuration for USB */
296296
memset(&config, 0, sizeof(config));
297-
config.reset_n_io = -EINVAL;
297+
config.reset_gpio = NULL;
298298

299299
nfc_info(&udev->dev, "intf %p id %p\n", intf, id);
300300

drivers/nfc/s3fwrn5/i2c.c

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
#include <linux/clk.h>
1010
#include <linux/i2c.h>
11-
#include <linux/gpio.h>
11+
#include <linux/gpio/consumer.h>
1212
#include <linux/delay.h>
13-
#include <linux/of_gpio.h>
14-
#include <linux/of_irq.h>
1513
#include <linux/module.h>
1614

1715
#include <net/nfc/nfc.h>
@@ -146,37 +144,6 @@ static irqreturn_t s3fwrn5_i2c_irq_thread_fn(int irq, void *phy_id)
146144
return IRQ_HANDLED;
147145
}
148146

149-
static int s3fwrn5_i2c_parse_dt(struct i2c_client *client)
150-
{
151-
struct s3fwrn5_i2c_phy *phy = i2c_get_clientdata(client);
152-
struct device_node *np = client->dev.of_node;
153-
154-
if (!np)
155-
return -ENODEV;
156-
157-
phy->common.gpio_en = of_get_named_gpio(np, "en-gpios", 0);
158-
if (!gpio_is_valid(phy->common.gpio_en)) {
159-
/* Support also deprecated property */
160-
phy->common.gpio_en = of_get_named_gpio(np,
161-
"s3fwrn5,en-gpios",
162-
0);
163-
if (!gpio_is_valid(phy->common.gpio_en))
164-
return -ENODEV;
165-
}
166-
167-
phy->common.gpio_fw_wake = of_get_named_gpio(np, "wake-gpios", 0);
168-
if (!gpio_is_valid(phy->common.gpio_fw_wake)) {
169-
/* Support also deprecated property */
170-
phy->common.gpio_fw_wake = of_get_named_gpio(np,
171-
"s3fwrn5,fw-gpios",
172-
0);
173-
if (!gpio_is_valid(phy->common.gpio_fw_wake))
174-
return -ENODEV;
175-
}
176-
177-
return 0;
178-
}
179-
180147
static int s3fwrn5_i2c_probe(struct i2c_client *client)
181148
{
182149
struct s3fwrn5_i2c_phy *phy;
@@ -193,20 +160,13 @@ static int s3fwrn5_i2c_probe(struct i2c_client *client)
193160
phy->i2c_dev = client;
194161
i2c_set_clientdata(client, phy);
195162

196-
ret = s3fwrn5_i2c_parse_dt(client);
197-
if (ret < 0)
198-
return ret;
199-
200-
ret = devm_gpio_request_one(&phy->i2c_dev->dev, phy->common.gpio_en,
201-
GPIOF_OUT_INIT_HIGH, "s3fwrn5_en");
202-
if (ret < 0)
203-
return ret;
163+
phy->common.gpio_en = devm_gpiod_get(&client->dev, "en", GPIOD_OUT_HIGH);
164+
if (IS_ERR(phy->common.gpio_en))
165+
return PTR_ERR(phy->common.gpio_en);
204166

205-
ret = devm_gpio_request_one(&phy->i2c_dev->dev,
206-
phy->common.gpio_fw_wake,
207-
GPIOF_OUT_INIT_LOW, "s3fwrn5_fw_wake");
208-
if (ret < 0)
209-
return ret;
167+
phy->common.gpio_fw_wake = devm_gpiod_get(&client->dev, "wake", GPIOD_OUT_LOW);
168+
if (IS_ERR(phy->common.gpio_fw_wake))
169+
return PTR_ERR(phy->common.gpio_fw_wake);
210170

211171
/*
212172
* S3FWRN5 depends on a clock input ("XI" pin) to function properly.

0 commit comments

Comments
 (0)