*/
#include <linux/module.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
#include <linux/delay.h>
-#include <linux/of_gpio.h>
+#include <linux/of.h>
#include <linux/nfc.h>
#include <net/nfc/nci.h>
#include <net/nfc/nci_core.h>
memcpy(&priv->config, pdata, sizeof(*pdata));
- if (gpio_is_valid(priv->config.reset_n_io)) {
- rc = gpio_request_one(priv->config.reset_n_io,
- GPIOF_OUT_INIT_LOW,
- "nfcmrvl_reset_n");
- if (rc < 0) {
- priv->config.reset_n_io = -EINVAL;
- nfc_err(dev, "failed to request reset_n io\n");
+ if (!priv->config.reset_gpio) {
+ priv->config.reset_gpio =
+ devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(priv->config.reset_gpio)) {
+ priv->config.reset_gpio = NULL;
+ nfc_err(dev, "failed to get reset gpio\n");
}
}
if (!priv->ndev) {
nfc_err(dev, "nci_allocate_device failed\n");
rc = -ENOMEM;
- goto error_free_gpio;
+ goto error_free;
}
rc = nfcmrvl_fw_dnld_init(priv);
nfcmrvl_fw_dnld_deinit(priv);
error_free_dev:
nci_free_device(priv->ndev);
-error_free_gpio:
- if (gpio_is_valid(priv->config.reset_n_io))
- gpio_free(priv->config.reset_n_io);
+error_free:
kfree(priv);
return ERR_PTR(rc);
}
nfcmrvl_fw_dnld_deinit(priv);
- if (gpio_is_valid(priv->config.reset_n_io))
- gpio_free(priv->config.reset_n_io);
-
nci_free_device(ndev);
kfree(priv);
}
/* Reset possible fault of previous session */
clear_bit(NFCMRVL_PHY_ERROR, &priv->flags);
- if (gpio_is_valid(priv->config.reset_n_io)) {
+ if (priv->config.reset_gpio) {
nfc_info(priv->dev, "reset the chip\n");
- gpio_set_value(priv->config.reset_n_io, 0);
+ gpiod_set_value(priv->config.reset_gpio, 1);
usleep_range(5000, 10000);
- gpio_set_value(priv->config.reset_n_io, 1);
+ gpiod_set_value(priv->config.reset_gpio, 0);
} else
nfc_info(priv->dev, "no reset available on this interface\n");
}
void nfcmrvl_chip_halt(struct nfcmrvl_private *priv)
{
- if (gpio_is_valid(priv->config.reset_n_io))
- gpio_set_value(priv->config.reset_n_io, 0);
+ if (priv->config.reset_gpio)
+ gpiod_set_value(priv->config.reset_gpio, 1);
}
int nfcmrvl_parse_dt(struct device_node *node,
struct nfcmrvl_platform_data *pdata)
{
- int reset_n_io;
-
- reset_n_io = of_get_named_gpio(node, "reset-n-io", 0);
- if (reset_n_io < 0) {
- pr_info("no reset-n-io config\n");
- } else if (!gpio_is_valid(reset_n_io)) {
- pr_err("invalid reset-n-io GPIO\n");
- return reset_n_io;
- }
- pdata->reset_n_io = reset_n_io;
+ pdata->reset_gpio = NULL;
pdata->hci_muxed = of_property_read_bool(node, "hci-muxed");
return 0;
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
+#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/printk.h>
static unsigned int hci_muxed;
static unsigned int flow_control;
static unsigned int break_control;
-static int reset_n_io = -EINVAL;
/*
* NFCMRVL NCI OPS
};
static int nfcmrvl_uart_parse_dt(struct device_node *node,
- struct nfcmrvl_platform_data *pdata)
+ struct nfcmrvl_platform_data *pdata,
+ struct device *dev)
{
struct device_node *matched_node;
+ struct gpio_desc *reset_gpio;
int ret;
matched_node = of_get_compatible_child(node, "marvell,nfc-uart");
pdata->flow_control = of_property_read_bool(matched_node, "flow-control");
pdata->break_control = of_property_read_bool(matched_node, "break-control");
+ reset_gpio = devm_fwnode_gpiod_get_optional(dev,
+ of_fwnode_handle(matched_node),
+ "reset", GPIOD_OUT_HIGH,
+ "nfcmrvl_reset_n");
+ if (IS_ERR(reset_gpio)) {
+ of_node_put(matched_node);
+ return PTR_ERR(reset_gpio);
+ }
+ pdata->reset_gpio = reset_gpio;
+
of_node_put(matched_node);
return 0;
*/
if (dev && dev->parent && dev->parent->of_node)
- if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0)
+ if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config, dev) == 0)
pdata = &config;
if (!pdata) {
pr_info("No platform data / DT -> fallback to module params\n");
config.hci_muxed = hci_muxed;
- config.reset_n_io = reset_n_io;
+ config.reset_gpio = NULL;
config.flow_control = flow_control;
config.break_control = break_control;
pdata = &config;
module_param(hci_muxed, uint, 0);
MODULE_PARM_DESC(hci_muxed, "Tell if transport is muxed in HCI one.");
-
-module_param(reset_n_io, int, 0);
-MODULE_PARM_DESC(reset_n_io, "GPIO that is wired to RESET_N signal.");