Skip to content

Commit 4a2b947

Browse files
Vincent CuissardSamuel Ortiz
authored andcommitted
NFC: nfcmrvl: add chip reset management
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 <[email protected]> Signed-off-by: Samuel Ortiz <[email protected]>
1 parent 8a81a96 commit 4a2b947

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

drivers/nfc/nfcmrvl/main.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818

1919
#include <linux/module.h>
20+
#include <linux/gpio.h>
21+
#include <linux/delay.h>
2022
#include <linux/nfc.h>
2123
#include <net/nfc/nci.h>
2224
#include <net/nfc/nci_core.h>
@@ -107,6 +109,16 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
107109
priv->if_ops = ops;
108110
priv->dev = dev;
109111
priv->hci_muxed = (flags & NFCMRVL_DEV_FLAG_HCI_MUXED) ? 1 : 0;
112+
priv->reset_n_io = NFCMRVL_DEV_FLAG_GET_RESET_N_IO(flags);
113+
114+
if (priv->reset_n_io) {
115+
rc = devm_gpio_request_one(dev,
116+
priv->reset_n_io,
117+
GPIOF_OUT_INIT_LOW,
118+
"nfcmrvl_reset_n");
119+
if (rc < 0)
120+
nfc_err(dev, "failed to request reset_n io\n");
121+
}
110122

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

128140
nci_set_drvdata(priv->ndev, priv);
129141

142+
nfcmrvl_chip_reset(priv);
143+
130144
rc = nci_register_device(priv->ndev);
131145
if (rc) {
132146
nfc_err(dev, "nci_register_device failed %d\n", rc);
@@ -179,6 +193,22 @@ int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
179193
}
180194
EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);
181195

196+
void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)
197+
{
198+
/*
199+
* This function does not take care if someone is using the device.
200+
* To be improved.
201+
*/
202+
203+
if (priv->reset_n_io) {
204+
nfc_info(priv->dev, "reset the chip\n");
205+
gpio_set_value(priv->reset_n_io, 0);
206+
usleep_range(5000, 10000);
207+
gpio_set_value(priv->reset_n_io, 1);
208+
} else
209+
nfc_info(priv->dev, "no reset available on this interface\n");
210+
}
211+
182212
MODULE_AUTHOR("Marvell International Ltd.");
183213
MODULE_DESCRIPTION("Marvell NFC driver ver " VERSION);
184214
MODULE_VERSION(VERSION);

drivers/nfc/nfcmrvl/nfcmrvl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@
3939
#define NFCMRVL_HCI_OCF 0xFE
4040

4141
#define NFCMRVL_DEV_FLAG_HCI_MUXED (1 << 0)
42+
#define NFCMRVL_DEV_FLAG_SET_RESET_N_IO(X) ((X) << 16)
43+
#define NFCMRVL_DEV_FLAG_GET_RESET_N_IO(X) ((X) >> 16)
4244

4345
struct nfcmrvl_private {
4446

4547
/* Tell if NCI packets are encapsulated in HCI ones */
4648
int hci_muxed;
4749
struct nci_dev *ndev;
50+
51+
/* Reset IO (0 if not available) */
52+
int reset_n_io;
53+
4854
unsigned long flags;
4955
void *drv_data;
5056
struct device *dev;
@@ -63,3 +69,5 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
6369
struct nfcmrvl_if_ops *ops,
6470
struct device *dev,
6571
unsigned int flags);
72+
73+
void nfcmrvl_chip_reset(struct nfcmrvl_private *priv);

0 commit comments

Comments
 (0)