aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Cuissard <cuissard@marvell.com>2015-06-11 08:00:19 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2015-06-11 17:40:23 -0400
commitdc14bdef8762a8098b1da881b611d722e24fe787 (patch)
tree39d165e83956d979519c009fd282026c58fc2925
parent9961127d4bce6325e9a0b0fb105e0c85a6c62cb7 (diff)
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>
-rw-r--r--drivers/nfc/nfcmrvl/main.c66
-rw-r--r--drivers/nfc/nfcmrvl/nfcmrvl.h36
-rw-r--r--drivers/nfc/nfcmrvl/usb.c6
-rw-r--r--include/linux/platform_data/nfcmrvl.h31
4 files changed, 113 insertions, 26 deletions
diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c
index 708aad28c567..e317a69a4560 100644
--- a/drivers/nfc/nfcmrvl/main.c
+++ b/drivers/nfc/nfcmrvl/main.c
@@ -19,6 +19,7 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/gpio.h> 20#include <linux/gpio.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/of_gpio.h>
22#include <linux/nfc.h> 23#include <linux/nfc.h>
23#include <net/nfc/nci.h> 24#include <net/nfc/nci.h>
24#include <net/nfc/nci_core.h> 25#include <net/nfc/nci_core.h>
@@ -65,7 +66,7 @@ static int nfcmrvl_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
65 if (!test_bit(NFCMRVL_NCI_RUNNING, &priv->flags)) 66 if (!test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
66 return -EBUSY; 67 return -EBUSY;
67 68
68 if (priv->hci_muxed) { 69 if (priv->config.hci_muxed) {
69 unsigned char *hdr; 70 unsigned char *hdr;
70 unsigned char len = skb->len; 71 unsigned char len = skb->len;
71 72
@@ -92,9 +93,9 @@ static struct nci_ops nfcmrvl_nci_ops = {
92}; 93};
93 94
94struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data, 95struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
95 struct nfcmrvl_if_ops *ops, 96 struct nfcmrvl_if_ops *ops,
96 struct device *dev, 97 struct device *dev,
97 unsigned int flags) 98 struct nfcmrvl_platform_data *pdata)
98{ 99{
99 struct nfcmrvl_private *priv; 100 struct nfcmrvl_private *priv;
100 int rc; 101 int rc;
@@ -108,23 +109,24 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
108 priv->drv_data = drv_data; 109 priv->drv_data = drv_data;
109 priv->if_ops = ops; 110 priv->if_ops = ops;
110 priv->dev = dev; 111 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);
113 112
114 if (priv->reset_n_io) { 113 memcpy(&priv->config, pdata, sizeof(*pdata));
114
115 if (priv->config.reset_n_io) {
115 rc = devm_gpio_request_one(dev, 116 rc = devm_gpio_request_one(dev,
116 priv->reset_n_io, 117 priv->config.reset_n_io,
117 GPIOF_OUT_INIT_LOW, 118 GPIOF_OUT_INIT_LOW,
118 "nfcmrvl_reset_n"); 119 "nfcmrvl_reset_n");
119 if (rc < 0) 120 if (rc < 0)
120 nfc_err(dev, "failed to request reset_n io\n"); 121 nfc_err(dev, "failed to request reset_n io\n");
121 } 122 }
122 123
123 if (priv->hci_muxed) 124 if (priv->config.hci_muxed)
124 headroom = NFCMRVL_HCI_EVENT_HEADER_SIZE; 125 headroom = NFCMRVL_HCI_EVENT_HEADER_SIZE;
125 126
126 protocols = NFC_PROTO_JEWEL_MASK 127 protocols = NFC_PROTO_JEWEL_MASK
127 | NFC_PROTO_MIFARE_MASK | NFC_PROTO_FELICA_MASK 128 | NFC_PROTO_MIFARE_MASK
129 | NFC_PROTO_FELICA_MASK
128 | NFC_PROTO_ISO14443_MASK 130 | NFC_PROTO_ISO14443_MASK
129 | NFC_PROTO_ISO14443_B_MASK 131 | NFC_PROTO_ISO14443_B_MASK
130 | NFC_PROTO_NFC_DEP_MASK; 132 | NFC_PROTO_NFC_DEP_MASK;
@@ -169,7 +171,7 @@ EXPORT_SYMBOL_GPL(nfcmrvl_nci_unregister_dev);
169 171
170int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb) 172int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
171{ 173{
172 if (priv->hci_muxed) { 174 if (priv->config.hci_muxed) {
173 if (skb->data[0] == NFCMRVL_HCI_EVENT_CODE && 175 if (skb->data[0] == NFCMRVL_HCI_EVENT_CODE &&
174 skb->data[1] == NFCMRVL_HCI_NFC_EVENT_CODE) { 176 skb->data[1] == NFCMRVL_HCI_NFC_EVENT_CODE) {
175 /* Data packet, let's extract NCI payload */ 177 /* Data packet, let's extract NCI payload */
@@ -200,15 +202,51 @@ void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)
200 * To be improved. 202 * To be improved.
201 */ 203 */
202 204
203 if (priv->reset_n_io) { 205 if (priv->config.reset_n_io) {
204 nfc_info(priv->dev, "reset the chip\n"); 206 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);
206 usleep_range(5000, 10000); 208 usleep_range(5000, 10000);
207 gpio_set_value(priv->reset_n_io, 1); 209 gpio_set_value(priv->config.reset_n_io, 1);
208 } else 210 } else
209 nfc_info(priv->dev, "no reset available on this interface\n"); 211 nfc_info(priv->dev, "no reset available on this interface\n");
210} 212}
211 213
214#ifdef CONFIG_OF
215
216int 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
241int nfcmrvl_parse_dt(struct device_node *node,
242 struct nfcmrvl_platform_data *pdata)
243{
244 return -ENODEV;
245}
246
247#endif
248EXPORT_SYMBOL_GPL(nfcmrvl_parse_dt);
249
212MODULE_AUTHOR("Marvell International Ltd."); 250MODULE_AUTHOR("Marvell International Ltd.");
213MODULE_DESCRIPTION("Marvell NFC driver ver " VERSION); 251MODULE_DESCRIPTION("Marvell NFC driver ver " VERSION);
214MODULE_VERSION(VERSION); 252MODULE_VERSION(VERSION);
diff --git a/drivers/nfc/nfcmrvl/nfcmrvl.h b/drivers/nfc/nfcmrvl/nfcmrvl.h
index 2edae9a4b6bd..214412bd6110 100644
--- a/drivers/nfc/nfcmrvl/nfcmrvl.h
+++ b/drivers/nfc/nfcmrvl/nfcmrvl.h
@@ -16,6 +16,11 @@
16 * this warranty disclaimer. 16 * this warranty disclaimer.
17 **/ 17 **/
18 18
19#ifndef _NFCMRVL_H_
20#define _NFCMRVL_H_
21
22#include <linux/platform_data/nfcmrvl.h>
23
19/* Define private flags: */ 24/* Define private flags: */
20#define NFCMRVL_NCI_RUNNING 1 25#define NFCMRVL_NCI_RUNNING 1
21 26
@@ -38,22 +43,25 @@
38#define NFCMRVL_HCI_OGF 0x81 43#define NFCMRVL_HCI_OGF 0x81
39#define NFCMRVL_HCI_OCF 0xFE 44#define NFCMRVL_HCI_OCF 0xFE
40 45
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)
44 46
45struct nfcmrvl_private { 47struct nfcmrvl_private {
46 48
47 /* Tell if NCI packets are encapsulated in HCI ones */ 49 unsigned long flags;
48 int hci_muxed; 50
51 /* Platform configuration */
52 struct nfcmrvl_platform_data config;
53
49 struct nci_dev *ndev; 54 struct nci_dev *ndev;
50 55
51 /* Reset IO (0 if not available) */ 56 /*
52 int reset_n_io; 57 ** PHY related information
58 */
53 59
54 unsigned long flags; 60 /* PHY driver context */
55 void *drv_data; 61 void *drv_data;
62 /* PHY device */
56 struct device *dev; 63 struct device *dev;
64 /* Low level driver ops */
57 struct nfcmrvl_if_ops *if_ops; 65 struct nfcmrvl_if_ops *if_ops;
58}; 66};
59 67
@@ -66,8 +74,14 @@ struct nfcmrvl_if_ops {
66void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv); 74void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv);
67int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb); 75int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb);
68struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data, 76struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
69 struct nfcmrvl_if_ops *ops, 77 struct nfcmrvl_if_ops *ops,
70 struct device *dev, 78 struct device *dev,
71 unsigned int flags); 79 struct nfcmrvl_platform_data *pdata);
80
72 81
73void nfcmrvl_chip_reset(struct nfcmrvl_private *priv); 82void nfcmrvl_chip_reset(struct nfcmrvl_private *priv);
83
84int nfcmrvl_parse_dt(struct device_node *node,
85 struct nfcmrvl_platform_data *pdata);
86
87#endif
diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c
index c4046b681bfa..aa3f3c1cff0a 100644
--- a/drivers/nfc/nfcmrvl/usb.c
+++ b/drivers/nfc/nfcmrvl/usb.c
@@ -302,6 +302,10 @@ static int nfcmrvl_probe(struct usb_interface *intf,
302 struct nfcmrvl_private *priv; 302 struct nfcmrvl_private *priv;
303 int i; 303 int i;
304 struct usb_device *udev = interface_to_usbdev(intf); 304 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));
305 309
306 nfc_info(&udev->dev, "intf %p id %p\n", intf, id); 310 nfc_info(&udev->dev, "intf %p id %p\n", intf, id);
307 311
@@ -339,7 +343,7 @@ static int nfcmrvl_probe(struct usb_interface *intf,
339 init_usb_anchor(&drv_data->deferred); 343 init_usb_anchor(&drv_data->deferred);
340 344
341 priv = nfcmrvl_nci_register_dev(drv_data, &usb_ops, 345 priv = nfcmrvl_nci_register_dev(drv_data, &usb_ops,
342 &drv_data->udev->dev, 0); 346 &drv_data->udev->dev, &config);
343 if (IS_ERR(priv)) 347 if (IS_ERR(priv))
344 return PTR_ERR(priv); 348 return PTR_ERR(priv);
345 349
diff --git a/include/linux/platform_data/nfcmrvl.h b/include/linux/platform_data/nfcmrvl.h
new file mode 100644
index 000000000000..106cfe5ed589
--- /dev/null
+++ b/include/linux/platform_data/nfcmrvl.h
@@ -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
20struct 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_ */