Skip to content

Commit 253350d

Browse files
vimuxxBartosz Golaszewski
authored andcommitted
nfc: nfcmrvl: convert to gpio descriptors
Replace the legacy of_get_named_gpio() / gpio_request_one() / gpio_set_value() API with the descriptor-based devm_gpiod_get_optional() / gpiod_set_value() API from <linux/gpio/consumer.h>, removing the dependency on <linux/of_gpio.h>. The "reset-n-io" property rename quirk already exists in gpiolib-of.c (added in commit 9c2cc71), so no additional quirk is needed. Signed-off-by: Jialu Xu <xujialu@vimux.org> Reviewed-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/DD684946FD7EE161+20260307030623.3495092-4-xujialu@vimux.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
1 parent b544927 commit 253350d

4 files changed

Lines changed: 36 additions & 40 deletions

File tree

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

0 commit comments

Comments
 (0)