2 * Marvell NFC driver: major functions
4 * Copyright (C) 2014, Marvell International Ltd.
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.
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.
19 #include <linux/module.h>
20 #include <linux/nfc.h>
21 #include <net/nfc/nci.h>
22 #include <net/nfc/nci_core.h>
27 static int nfcmrvl_nci_open(struct nci_dev *ndev)
29 struct nfcmrvl_private *priv = nci_get_drvdata(ndev);
32 if (test_and_set_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
35 err = priv->if_ops->nci_open(priv);
38 clear_bit(NFCMRVL_NCI_RUNNING, &priv->flags);
43 static int nfcmrvl_nci_close(struct nci_dev *ndev)
45 struct nfcmrvl_private *priv = nci_get_drvdata(ndev);
47 if (!test_and_clear_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
50 priv->if_ops->nci_close(priv);
55 static int nfcmrvl_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
57 struct nfcmrvl_private *priv = nci_get_drvdata(ndev);
59 nfc_info(priv->dev, "send entry, len %d\n", skb->len);
61 skb->dev = (void *)ndev;
63 if (!test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
66 return priv->if_ops->nci_send(priv, skb);
69 static int nfcmrvl_nci_setup(struct nci_dev *ndev)
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,
81 struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
82 struct nfcmrvl_if_ops *ops,
85 struct nfcmrvl_private *priv;
89 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
91 return ERR_PTR(-ENOMEM);
93 priv->drv_data = drv_data;
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;
103 priv->ndev = nci_allocate_device(&nfcmrvl_nci_ops, protocols, 0, 0);
105 nfc_err(dev, "nci_allocate_device failed\n");
110 nci_set_drvdata(priv->ndev, priv);
112 rc = nci_register_device(priv->ndev);
114 nfc_err(dev, "nci_register_device failed %d\n", rc);
115 nci_free_device(priv->ndev);
119 nfc_info(dev, "registered with nci successfully\n");
126 EXPORT_SYMBOL_GPL(nfcmrvl_nci_register_dev);
128 void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv)
130 struct nci_dev *ndev = priv->ndev;
132 nci_unregister_device(ndev);
133 nci_free_device(ndev);
136 EXPORT_SYMBOL_GPL(nfcmrvl_nci_unregister_dev);
138 int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, void *data, int count)
142 skb = nci_skb_alloc(priv->ndev, count, GFP_ATOMIC);
146 memcpy(skb_put(skb, count), data, count);
147 nci_recv_frame(priv->ndev, skb);
151 EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);
153 MODULE_AUTHOR("Marvell International Ltd.");
154 MODULE_DESCRIPTION("Marvell NFC driver ver " VERSION);
155 MODULE_VERSION(VERSION);
156 MODULE_LICENSE("GPL v2");