Skip to content

Commit

Permalink
NFC: nfcmrvl: add chip reset management
Browse files Browse the repository at this point in the history
Low level driver can specify a GPIO that will be used to reset
the chip. Thanks to this the driver can ensure the state of the
device at init.

Signed-off-by: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Vincent Cuissard authored and Samuel Ortiz committed Jun 11, 2015
1 parent 8a81a96 commit 4a2b947
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions drivers/nfc/nfcmrvl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

#include <linux/module.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include <linux/nfc.h>
#include <net/nfc/nci.h>
#include <net/nfc/nci_core.h>
Expand Down Expand Up @@ -107,6 +109,16 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
priv->if_ops = ops;
priv->dev = dev;
priv->hci_muxed = (flags & NFCMRVL_DEV_FLAG_HCI_MUXED) ? 1 : 0;
priv->reset_n_io = NFCMRVL_DEV_FLAG_GET_RESET_N_IO(flags);

if (priv->reset_n_io) {
rc = devm_gpio_request_one(dev,
priv->reset_n_io,
GPIOF_OUT_INIT_LOW,
"nfcmrvl_reset_n");
if (rc < 0)
nfc_err(dev, "failed to request reset_n io\n");
}

if (priv->hci_muxed)
headroom = NFCMRVL_HCI_EVENT_HEADER_SIZE;
Expand All @@ -127,6 +139,8 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,

nci_set_drvdata(priv->ndev, priv);

nfcmrvl_chip_reset(priv);

rc = nci_register_device(priv->ndev);
if (rc) {
nfc_err(dev, "nci_register_device failed %d\n", rc);
Expand Down Expand Up @@ -179,6 +193,22 @@ int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
}
EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);

void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)
{
/*
* This function does not take care if someone is using the device.
* To be improved.
*/

if (priv->reset_n_io) {
nfc_info(priv->dev, "reset the chip\n");
gpio_set_value(priv->reset_n_io, 0);
usleep_range(5000, 10000);
gpio_set_value(priv->reset_n_io, 1);
} else
nfc_info(priv->dev, "no reset available on this interface\n");
}

MODULE_AUTHOR("Marvell International Ltd.");
MODULE_DESCRIPTION("Marvell NFC driver ver " VERSION);
MODULE_VERSION(VERSION);
Expand Down
8 changes: 8 additions & 0 deletions drivers/nfc/nfcmrvl/nfcmrvl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@
#define NFCMRVL_HCI_OCF 0xFE

#define NFCMRVL_DEV_FLAG_HCI_MUXED (1 << 0)
#define NFCMRVL_DEV_FLAG_SET_RESET_N_IO(X) ((X) << 16)
#define NFCMRVL_DEV_FLAG_GET_RESET_N_IO(X) ((X) >> 16)

struct nfcmrvl_private {

/* Tell if NCI packets are encapsulated in HCI ones */
int hci_muxed;
struct nci_dev *ndev;

/* Reset IO (0 if not available) */
int reset_n_io;

unsigned long flags;
void *drv_data;
struct device *dev;
Expand All @@ -63,3 +69,5 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
struct nfcmrvl_if_ops *ops,
struct device *dev,
unsigned int flags);

void nfcmrvl_chip_reset(struct nfcmrvl_private *priv);

0 comments on commit 4a2b947

Please sign in to comment.