2 * NCI based Driver for STMicroelectronics NFC Chip
4 * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include <linux/module.h>
20 #include <linux/nfc.h>
21 #include <net/nfc/nci.h>
22 #include <net/nfc/nci_core.h>
27 #define DRIVER_DESC "NCI NFC driver for ST21NFCB"
29 static int st21nfcb_nci_open(struct nci_dev *ndev)
31 struct st21nfcb_nci_info *info = nci_get_drvdata(ndev);
34 if (test_and_set_bit(ST21NFCB_NCI_RUNNING, &info->flags))
37 r = ndlc_open(info->ndlc);
39 clear_bit(ST21NFCB_NCI_RUNNING, &info->flags);
44 static int st21nfcb_nci_close(struct nci_dev *ndev)
46 struct st21nfcb_nci_info *info = nci_get_drvdata(ndev);
48 if (!test_and_clear_bit(ST21NFCB_NCI_RUNNING, &info->flags))
51 ndlc_close(info->ndlc);
56 static int st21nfcb_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
58 struct st21nfcb_nci_info *info = nci_get_drvdata(ndev);
60 skb->dev = (void *)ndev;
62 if (!test_bit(ST21NFCB_NCI_RUNNING, &info->flags))
65 return ndlc_send(info->ndlc, skb);
68 static struct nci_ops st21nfcb_nci_ops = {
69 .open = st21nfcb_nci_open,
70 .close = st21nfcb_nci_close,
71 .send = st21nfcb_nci_send,
74 int st21nfcb_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
77 struct st21nfcb_nci_info *info;
81 info = devm_kzalloc(ndlc->dev,
82 sizeof(struct st21nfcb_nci_info), GFP_KERNEL);
86 protocols = NFC_PROTO_JEWEL_MASK
87 | NFC_PROTO_MIFARE_MASK
88 | NFC_PROTO_FELICA_MASK
89 | NFC_PROTO_ISO14443_MASK
90 | NFC_PROTO_ISO14443_B_MASK
91 | NFC_PROTO_NFC_DEP_MASK;
93 ndlc->ndev = nci_allocate_device(&st21nfcb_nci_ops, protocols,
94 phy_headroom, phy_tailroom);
96 pr_err("Cannot allocate nfc ndev\n");
102 nci_set_drvdata(ndlc->ndev, info);
104 r = nci_register_device(ndlc->ndev);
110 nci_free_device(ndlc->ndev);
116 EXPORT_SYMBOL_GPL(st21nfcb_nci_probe);
118 void st21nfcb_nci_remove(struct nci_dev *ndev)
120 struct st21nfcb_nci_info *info = nci_get_drvdata(ndev);
122 nci_unregister_device(ndev);
123 nci_free_device(ndev);
126 EXPORT_SYMBOL_GPL(st21nfcb_nci_remove);
128 MODULE_LICENSE("GPL");
129 MODULE_DESCRIPTION(DRIVER_DESC);