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>
25 #include "st21nfcb_se.h"
27 #define DRIVER_DESC "NCI NFC driver for ST21NFCB"
29 #define ST21NFCB_NCI1_X_PROPRIETARY_ISO15693 0x83
31 static int st21nfcb_nci_open(struct nci_dev
*ndev
)
33 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
36 if (test_and_set_bit(ST21NFCB_NCI_RUNNING
, &info
->flags
))
39 r
= ndlc_open(info
->ndlc
);
41 clear_bit(ST21NFCB_NCI_RUNNING
, &info
->flags
);
46 static int st21nfcb_nci_close(struct nci_dev
*ndev
)
48 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
50 if (!test_and_clear_bit(ST21NFCB_NCI_RUNNING
, &info
->flags
))
53 ndlc_close(info
->ndlc
);
58 static int st21nfcb_nci_send(struct nci_dev
*ndev
, struct sk_buff
*skb
)
60 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
62 skb
->dev
= (void *)ndev
;
64 if (!test_bit(ST21NFCB_NCI_RUNNING
, &info
->flags
))
67 return ndlc_send(info
->ndlc
, skb
);
70 static __u32
st21nfcb_nci_get_rfprotocol(struct nci_dev
*ndev
,
73 return rf_protocol
== ST21NFCB_NCI1_X_PROPRIETARY_ISO15693
?
74 NFC_PROTO_ISO15693_MASK
: 0;
77 static struct nci_ops st21nfcb_nci_ops
= {
78 .open
= st21nfcb_nci_open
,
79 .close
= st21nfcb_nci_close
,
80 .send
= st21nfcb_nci_send
,
81 .get_rfprotocol
= st21nfcb_nci_get_rfprotocol
,
82 .discover_se
= st21nfcb_nci_discover_se
,
83 .enable_se
= st21nfcb_nci_enable_se
,
84 .disable_se
= st21nfcb_nci_disable_se
,
85 .se_io
= st21nfcb_nci_se_io
,
86 .hci_load_session
= st21nfcb_hci_load_session
,
87 .hci_event_received
= st21nfcb_hci_event_received
,
88 .hci_cmd_received
= st21nfcb_hci_cmd_received
,
91 int st21nfcb_nci_probe(struct llt_ndlc
*ndlc
, int phy_headroom
,
94 struct st21nfcb_nci_info
*info
;
98 info
= devm_kzalloc(ndlc
->dev
,
99 sizeof(struct st21nfcb_nci_info
), GFP_KERNEL
);
103 protocols
= NFC_PROTO_JEWEL_MASK
104 | NFC_PROTO_MIFARE_MASK
105 | NFC_PROTO_FELICA_MASK
106 | NFC_PROTO_ISO14443_MASK
107 | NFC_PROTO_ISO14443_B_MASK
108 | NFC_PROTO_ISO15693_MASK
109 | NFC_PROTO_NFC_DEP_MASK
;
111 ndlc
->ndev
= nci_allocate_device(&st21nfcb_nci_ops
, protocols
,
112 phy_headroom
, phy_tailroom
);
114 pr_err("Cannot allocate nfc ndev\n");
119 nci_set_drvdata(ndlc
->ndev
, info
);
121 r
= nci_register_device(ndlc
->ndev
);
123 pr_err("Cannot register nfc device to nci core\n");
124 nci_free_device(ndlc
->ndev
);
128 return st21nfcb_se_init(ndlc
->ndev
);
130 EXPORT_SYMBOL_GPL(st21nfcb_nci_probe
);
132 void st21nfcb_nci_remove(struct nci_dev
*ndev
)
134 struct st21nfcb_nci_info
*info
= nci_get_drvdata(ndev
);
136 nci_unregister_device(ndev
);
137 nci_free_device(ndev
);
140 EXPORT_SYMBOL_GPL(st21nfcb_nci_remove
);
142 MODULE_LICENSE("GPL");
143 MODULE_DESCRIPTION(DRIVER_DESC
);