NFC: nfcmrvl: remove integration related settings
[linux-2.6-block.git] / drivers / nfc / nfcmrvl / main.c
1 /*
2  * Marvell NFC driver: major functions
3  *
4  * Copyright (C) 2014, Marvell International Ltd.
5  *
6  * This software file (the "File") is distributed by Marvell International
7  * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8  * (the "License").  You may use, redistribute and/or modify this File in
9  * accordance with the terms and conditions of the License, a copy of which
10  * is available on the worldwide web at
11  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
12  *
13  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
14  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
15  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
16  * this warranty disclaimer.
17  */
18
19 #include <linux/module.h>
20 #include <linux/nfc.h>
21 #include <net/nfc/nci.h>
22 #include <net/nfc/nci_core.h>
23 #include "nfcmrvl.h"
24
25 #define VERSION "1.0"
26
27 static int nfcmrvl_nci_open(struct nci_dev *ndev)
28 {
29         struct nfcmrvl_private *priv = nci_get_drvdata(ndev);
30         int err;
31
32         if (test_and_set_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
33                 return 0;
34
35         err = priv->if_ops->nci_open(priv);
36
37         if (err)
38                 clear_bit(NFCMRVL_NCI_RUNNING, &priv->flags);
39
40         return err;
41 }
42
43 static int nfcmrvl_nci_close(struct nci_dev *ndev)
44 {
45         struct nfcmrvl_private *priv = nci_get_drvdata(ndev);
46
47         if (!test_and_clear_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
48                 return 0;
49
50         priv->if_ops->nci_close(priv);
51
52         return 0;
53 }
54
55 static int nfcmrvl_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
56 {
57         struct nfcmrvl_private *priv = nci_get_drvdata(ndev);
58
59         nfc_info(priv->dev, "send entry, len %d\n", skb->len);
60
61         skb->dev = (void *)ndev;
62
63         if (!test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
64                 return -EBUSY;
65
66         return priv->if_ops->nci_send(priv, skb);
67 }
68
69 static int nfcmrvl_nci_setup(struct nci_dev *ndev)
70 {
71         return 0;
72 }
73
74 static struct nci_ops nfcmrvl_nci_ops = {
75         .open = nfcmrvl_nci_open,
76         .close = nfcmrvl_nci_close,
77         .send = nfcmrvl_nci_send,
78         .setup = nfcmrvl_nci_setup,
79 };
80
81 struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
82                                                  struct nfcmrvl_if_ops *ops,
83                                                  struct device *dev)
84 {
85         struct nfcmrvl_private *priv;
86         int rc;
87         u32 protocols;
88
89         priv = kzalloc(sizeof(*priv), GFP_KERNEL);
90         if (!priv)
91                 return ERR_PTR(-ENOMEM);
92
93         priv->drv_data = drv_data;
94         priv->if_ops = ops;
95         priv->dev = dev;
96
97         protocols = NFC_PROTO_JEWEL_MASK
98                 | NFC_PROTO_MIFARE_MASK | NFC_PROTO_FELICA_MASK
99                 | NFC_PROTO_ISO14443_MASK
100                 | NFC_PROTO_ISO14443_B_MASK
101                 | NFC_PROTO_NFC_DEP_MASK;
102
103         priv->ndev = nci_allocate_device(&nfcmrvl_nci_ops, protocols, 0, 0);
104         if (!priv->ndev) {
105                 nfc_err(dev, "nci_allocate_device failed\n");
106                 rc = -ENOMEM;
107                 goto error;
108         }
109
110         nci_set_drvdata(priv->ndev, priv);
111
112         rc = nci_register_device(priv->ndev);
113         if (rc) {
114                 nfc_err(dev, "nci_register_device failed %d\n", rc);
115                 nci_free_device(priv->ndev);
116                 goto error;
117         }
118
119         nfc_info(dev, "registered with nci successfully\n");
120         return priv;
121
122 error:
123         kfree(priv);
124         return ERR_PTR(rc);
125 }
126 EXPORT_SYMBOL_GPL(nfcmrvl_nci_register_dev);
127
128 void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv)
129 {
130         struct nci_dev *ndev = priv->ndev;
131
132         nci_unregister_device(ndev);
133         nci_free_device(ndev);
134         kfree(priv);
135 }
136 EXPORT_SYMBOL_GPL(nfcmrvl_nci_unregister_dev);
137
138 int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, void *data, int count)
139 {
140         struct sk_buff *skb;
141
142         skb = nci_skb_alloc(priv->ndev, count, GFP_ATOMIC);
143         if (!skb)
144                 return -ENOMEM;
145
146         memcpy(skb_put(skb, count), data, count);
147         nci_recv_frame(priv->ndev, skb);
148
149         return count;
150 }
151 EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);
152
153 MODULE_AUTHOR("Marvell International Ltd.");
154 MODULE_DESCRIPTION("Marvell NFC driver ver " VERSION);
155 MODULE_VERSION(VERSION);
156 MODULE_LICENSE("GPL v2");