Skip to content

Commit dc14bde

Browse files
Vincent CuissardSamuel Ortiz
authored andcommitted
NFC: nfcmrvl: add platform_data and DT configuration
Declare nfcmrvl platform_data structure and few DT parameters for nfcmrvl driver. Signed-off-by: Vincent Cuissard <cuissard@marvell.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 9961127 commit dc14bde

File tree

4 files changed

+113
-26
lines changed

4 files changed

+113
-26
lines changed

drivers/nfc/nfcmrvl/main.c

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/module.h>
2020
#include <linux/gpio.h>
2121
#include <linux/delay.h>
22+
#include <linux/of_gpio.h>
2223
#include <linux/nfc.h>
2324
#include <net/nfc/nci.h>
2425
#include <net/nfc/nci_core.h>
@@ -65,7 +66,7 @@ static int nfcmrvl_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
6566
if (!test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
6667
return -EBUSY;
6768

68-
if (priv->hci_muxed) {
69+
if (priv->config.hci_muxed) {
6970
unsigned char *hdr;
7071
unsigned char len = skb->len;
7172

@@ -92,9 +93,9 @@ static struct nci_ops nfcmrvl_nci_ops = {
9293
};
9394

9495
struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
95-
struct nfcmrvl_if_ops *ops,
96-
struct device *dev,
97-
unsigned int flags)
96+
struct nfcmrvl_if_ops *ops,
97+
struct device *dev,
98+
struct nfcmrvl_platform_data *pdata)
9899
{
99100
struct nfcmrvl_private *priv;
100101
int rc;
@@ -108,23 +109,24 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
108109
priv->drv_data = drv_data;
109110
priv->if_ops = ops;
110111
priv->dev = dev;
111-
priv->hci_muxed = (flags & NFCMRVL_DEV_FLAG_HCI_MUXED) ? 1 : 0;
112-
priv->reset_n_io = NFCMRVL_DEV_FLAG_GET_RESET_N_IO(flags);
113112

114-
if (priv->reset_n_io) {
113+
memcpy(&priv->config, pdata, sizeof(*pdata));
114+
115+
if (priv->config.reset_n_io) {
115116
rc = devm_gpio_request_one(dev,
116-
priv->reset_n_io,
117+
priv->config.reset_n_io,
117118
GPIOF_OUT_INIT_LOW,
118119
"nfcmrvl_reset_n");
119120
if (rc < 0)
120121
nfc_err(dev, "failed to request reset_n io\n");
121122
}
122123

123-
if (priv->hci_muxed)
124+
if (priv->config.hci_muxed)
124125
headroom = NFCMRVL_HCI_EVENT_HEADER_SIZE;
125126

126127
protocols = NFC_PROTO_JEWEL_MASK
127-
| NFC_PROTO_MIFARE_MASK | NFC_PROTO_FELICA_MASK
128+
| NFC_PROTO_MIFARE_MASK
129+
| NFC_PROTO_FELICA_MASK
128130
| NFC_PROTO_ISO14443_MASK
129131
| NFC_PROTO_ISO14443_B_MASK
130132
| NFC_PROTO_NFC_DEP_MASK;
@@ -169,7 +171,7 @@ EXPORT_SYMBOL_GPL(nfcmrvl_nci_unregister_dev);
169171

170172
int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
171173
{
172-
if (priv->hci_muxed) {
174+
if (priv->config.hci_muxed) {
173175
if (skb->data[0] == NFCMRVL_HCI_EVENT_CODE &&
174176
skb->data[1] == NFCMRVL_HCI_NFC_EVENT_CODE) {
175177
/* Data packet, let's extract NCI payload */
@@ -200,15 +202,51 @@ void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)
200202
* To be improved.
201203
*/
202204

203-
if (priv->reset_n_io) {
205+
if (priv->config.reset_n_io) {
204206
nfc_info(priv->dev, "reset the chip\n");
205-
gpio_set_value(priv->reset_n_io, 0);
207+
gpio_set_value(priv->config.reset_n_io, 0);
206208
usleep_range(5000, 10000);
207-
gpio_set_value(priv->reset_n_io, 1);
209+
gpio_set_value(priv->config.reset_n_io, 1);
208210
} else
209211
nfc_info(priv->dev, "no reset available on this interface\n");
210212
}
211213

214+
#ifdef CONFIG_OF
215+
216+
int nfcmrvl_parse_dt(struct device_node *node,
217+
struct nfcmrvl_platform_data *pdata)
218+
{
219+
int reset_n_io;
220+
221+
reset_n_io = of_get_named_gpio(node, "reset-n-io", 0);
222+
if (reset_n_io < 0) {
223+
pr_info("no reset-n-io config\n");
224+
reset_n_io = 0;
225+
} else if (!gpio_is_valid(reset_n_io)) {
226+
pr_err("invalid reset-n-io GPIO\n");
227+
return reset_n_io;
228+
}
229+
pdata->reset_n_io = reset_n_io;
230+
231+
if (of_find_property(node, "hci-muxed", NULL))
232+
pdata->hci_muxed = 1;
233+
else
234+
pdata->hci_muxed = 0;
235+
236+
return 0;
237+
}
238+
239+
#else
240+
241+
int nfcmrvl_parse_dt(struct device_node *node,
242+
struct nfcmrvl_platform_data *pdata)
243+
{
244+
return -ENODEV;
245+
}
246+
247+
#endif
248+
EXPORT_SYMBOL_GPL(nfcmrvl_parse_dt);
249+
212250
MODULE_AUTHOR("Marvell International Ltd.");
213251
MODULE_DESCRIPTION("Marvell NFC driver ver " VERSION);
214252
MODULE_VERSION(VERSION);

drivers/nfc/nfcmrvl/nfcmrvl.h

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
* this warranty disclaimer.
1717
**/
1818

19+
#ifndef _NFCMRVL_H_
20+
#define _NFCMRVL_H_
21+
22+
#include <linux/platform_data/nfcmrvl.h>
23+
1924
/* Define private flags: */
2025
#define NFCMRVL_NCI_RUNNING 1
2126

@@ -38,22 +43,25 @@
3843
#define NFCMRVL_HCI_OGF 0x81
3944
#define NFCMRVL_HCI_OCF 0xFE
4045

41-
#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)
4446

4547
struct nfcmrvl_private {
4648

47-
/* Tell if NCI packets are encapsulated in HCI ones */
48-
int hci_muxed;
49+
unsigned long flags;
50+
51+
/* Platform configuration */
52+
struct nfcmrvl_platform_data config;
53+
4954
struct nci_dev *ndev;
5055

51-
/* Reset IO (0 if not available) */
52-
int reset_n_io;
56+
/*
57+
** PHY related information
58+
*/
5359

54-
unsigned long flags;
60+
/* PHY driver context */
5561
void *drv_data;
62+
/* PHY device */
5663
struct device *dev;
64+
/* Low level driver ops */
5765
struct nfcmrvl_if_ops *if_ops;
5866
};
5967

@@ -66,8 +74,14 @@ struct nfcmrvl_if_ops {
6674
void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv);
6775
int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb);
6876
struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
69-
struct nfcmrvl_if_ops *ops,
70-
struct device *dev,
71-
unsigned int flags);
77+
struct nfcmrvl_if_ops *ops,
78+
struct device *dev,
79+
struct nfcmrvl_platform_data *pdata);
80+
7281

7382
void nfcmrvl_chip_reset(struct nfcmrvl_private *priv);
83+
84+
int nfcmrvl_parse_dt(struct device_node *node,
85+
struct nfcmrvl_platform_data *pdata);
86+
87+
#endif

drivers/nfc/nfcmrvl/usb.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ static int nfcmrvl_probe(struct usb_interface *intf,
302302
struct nfcmrvl_private *priv;
303303
int i;
304304
struct usb_device *udev = interface_to_usbdev(intf);
305+
struct nfcmrvl_platform_data config;
306+
307+
/* No configuration for USB */
308+
memset(&config, 0, sizeof(config));
305309

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

@@ -339,7 +343,7 @@ static int nfcmrvl_probe(struct usb_interface *intf,
339343
init_usb_anchor(&drv_data->deferred);
340344

341345
priv = nfcmrvl_nci_register_dev(drv_data, &usb_ops,
342-
&drv_data->udev->dev, 0);
346+
&drv_data->udev->dev, &config);
343347
if (IS_ERR(priv))
344348
return PTR_ERR(priv);
345349

include/linux/platform_data/nfcmrvl.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2015, Marvell International Ltd.
3+
*
4+
* This software file (the "File") is distributed by Marvell International
5+
* Ltd. under the terms of the GNU General Public License Version 2, June 1991
6+
* (the "License"). You may use, redistribute and/or modify this File in
7+
* accordance with the terms and conditions of the License, a copy of which
8+
* is available on the worldwide web at
9+
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
10+
*
11+
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
12+
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
13+
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
14+
* this warranty disclaimer.
15+
*/
16+
17+
#ifndef _NFCMRVL_PTF_H_
18+
#define _NFCMRVL_PTF_H_
19+
20+
struct nfcmrvl_platform_data {
21+
/*
22+
* Generic
23+
*/
24+
25+
/* GPIO that is wired to RESET_N signal */
26+
unsigned int reset_n_io;
27+
/* Tell if transport is muxed in HCI one */
28+
unsigned int hci_muxed;
29+
};
30+
31+
#endif /* _NFCMRVL_PTF_H_ */

0 commit comments

Comments
 (0)