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>
26 #define DRIVER_DESC "NCI NFC driver for ST21NFCB"
28 #define ST21NFCB_NCI1_X_PROPRIETARY_ISO15693 0x83
30 static int st21nfcb_nci_open(struct nci_dev
*ndev
)
32 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
35 if (test_and_set_bit(ST21NFCB_NCI_RUNNING
, &info
->flags
))
38 r
= ndlc_open(info
->ndlc
);
40 clear_bit(ST21NFCB_NCI_RUNNING
, &info
->flags
);
45 static int st21nfcb_nci_close(struct nci_dev
*ndev
)
47 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
49 if (!test_and_clear_bit(ST21NFCB_NCI_RUNNING
, &info
->flags
))
52 ndlc_close(info
->ndlc
);
57 static int st21nfcb_nci_send(struct nci_dev
*ndev
, struct sk_buff
*skb
)
59 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
61 skb
->dev
= (void *)ndev
;
63 if (!test_bit(ST21NFCB_NCI_RUNNING
, &info
->flags
))
66 return ndlc_send(info
->ndlc
, skb
);
69 static __u32
st21nfcb_nci_get_rfprotocol(struct nci_dev
*ndev
,
72 return rf_protocol
== ST21NFCB_NCI1_X_PROPRIETARY_ISO15693
?
73 NFC_PROTO_ISO15693_MASK
: 0;
76 static struct nci_ops st21nfcb_nci_ops
= {
77 .open
= st21nfcb_nci_open
,
78 .close
= st21nfcb_nci_close
,
79 .send
= st21nfcb_nci_send
,
80 .get_rfprotocol
= st21nfcb_nci_get_rfprotocol
,
83 int st21nfcb_nci_probe(struct llt_ndlc
*ndlc
, int phy_headroom
,
86 struct st21nfcb_nci_info
*info
;
90 info
= devm_kzalloc(ndlc
->dev
,
91 sizeof(struct st21nfcb_nci_info
), GFP_KERNEL
);
95 protocols
= NFC_PROTO_JEWEL_MASK
96 | NFC_PROTO_MIFARE_MASK
97 | NFC_PROTO_FELICA_MASK
98 | NFC_PROTO_ISO14443_MASK
99 | NFC_PROTO_ISO14443_B_MASK
100 | NFC_PROTO_ISO15693_MASK
101 | NFC_PROTO_NFC_DEP_MASK
;
103 ndlc
->ndev
= nci_allocate_device(&st21nfcb_nci_ops
, protocols
,
104 phy_headroom
, phy_tailroom
);
106 pr_err("Cannot allocate nfc ndev\n");
111 nci_set_drvdata(ndlc
->ndev
, info
);
113 r
= nci_register_device(ndlc
->ndev
);
115 pr_err("Cannot register nfc device to nci core\n");
116 nci_free_device(ndlc
->ndev
);
121 EXPORT_SYMBOL_GPL(st21nfcb_nci_probe
);
123 void st21nfcb_nci_remove(struct nci_dev
*ndev
)
125 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
127 nci_unregister_device(ndev
);
128 nci_free_device(ndev
);
131 EXPORT_SYMBOL_GPL(st21nfcb_nci_remove
);
133 MODULE_LICENSE("GPL");
134 MODULE_DESCRIPTION(DRIVER_DESC
);