2 * NCI based Driver for STMicroelectronics NFC Chip
4 * Copyright (C) 2014-2015 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>
23 #include <linux/gpio.h>
24 #include <linux/delay.h>
27 #include "st-nci_se.h"
29 #define DRIVER_DESC "NCI NFC driver for ST_NCI"
31 #define ST_NCI1_X_PROPRIETARY_ISO15693 0x83
33 static int st_nci_init(struct nci_dev
*ndev
)
35 struct nci_mode_set_cmd cmd
;
37 cmd
.cmd_type
= ST_NCI_SET_NFC_MODE
;
40 return nci_prop_cmd(ndev
, ST_NCI_CORE_PROP
,
41 sizeof(struct nci_mode_set_cmd
), (__u8
*)&cmd
);
44 static int st_nci_open(struct nci_dev
*ndev
)
46 struct st_nci_info
*info
= nci_get_drvdata(ndev
);
49 if (test_and_set_bit(ST_NCI_RUNNING
, &info
->flags
))
52 r
= ndlc_open(info
->ndlc
);
54 clear_bit(ST_NCI_RUNNING
, &info
->flags
);
59 static int st_nci_close(struct nci_dev
*ndev
)
61 struct st_nci_info
*info
= nci_get_drvdata(ndev
);
63 if (!test_bit(ST_NCI_RUNNING
, &info
->flags
))
66 ndlc_close(info
->ndlc
);
68 clear_bit(ST_NCI_RUNNING
, &info
->flags
);
73 static int st_nci_send(struct nci_dev
*ndev
, struct sk_buff
*skb
)
75 struct st_nci_info
*info
= nci_get_drvdata(ndev
);
77 skb
->dev
= (void *)ndev
;
79 if (!test_bit(ST_NCI_RUNNING
, &info
->flags
))
82 return ndlc_send(info
->ndlc
, skb
);
85 static __u32
st_nci_get_rfprotocol(struct nci_dev
*ndev
,
88 return rf_protocol
== ST_NCI1_X_PROPRIETARY_ISO15693
?
89 NFC_PROTO_ISO15693_MASK
: 0;
92 static int st_nci_prop_rsp_packet(struct nci_dev
*ndev
,
95 __u8 status
= skb
->data
[0];
97 nci_req_complete(ndev
, status
);
101 static struct nci_prop_ops st_nci_prop_ops
[] = {
103 .opcode
= nci_opcode_pack(NCI_GID_PROPRIETARY
,
105 .rsp
= st_nci_prop_rsp_packet
,
109 static struct nci_ops st_nci_ops
= {
112 .close
= st_nci_close
,
114 .get_rfprotocol
= st_nci_get_rfprotocol
,
115 .discover_se
= st_nci_discover_se
,
116 .enable_se
= st_nci_enable_se
,
117 .disable_se
= st_nci_disable_se
,
118 .se_io
= st_nci_se_io
,
119 .hci_load_session
= st_nci_hci_load_session
,
120 .hci_event_received
= st_nci_hci_event_received
,
121 .hci_cmd_received
= st_nci_hci_cmd_received
,
122 .prop_ops
= st_nci_prop_ops
,
123 .n_prop_ops
= ARRAY_SIZE(st_nci_prop_ops
),
126 int st_nci_probe(struct llt_ndlc
*ndlc
, int phy_headroom
,
129 struct st_nci_info
*info
;
133 info
= devm_kzalloc(ndlc
->dev
,
134 sizeof(struct st_nci_info
), GFP_KERNEL
);
138 protocols
= NFC_PROTO_JEWEL_MASK
139 | NFC_PROTO_MIFARE_MASK
140 | NFC_PROTO_FELICA_MASK
141 | NFC_PROTO_ISO14443_MASK
142 | NFC_PROTO_ISO14443_B_MASK
143 | NFC_PROTO_ISO15693_MASK
144 | NFC_PROTO_NFC_DEP_MASK
;
146 ndlc
->ndev
= nci_allocate_device(&st_nci_ops
, protocols
,
147 phy_headroom
, phy_tailroom
);
149 pr_err("Cannot allocate nfc ndev\n");
154 nci_set_drvdata(ndlc
->ndev
, info
);
156 r
= nci_register_device(ndlc
->ndev
);
158 pr_err("Cannot register nfc device to nci core\n");
159 nci_free_device(ndlc
->ndev
);
163 return st_nci_se_init(ndlc
->ndev
);
165 EXPORT_SYMBOL_GPL(st_nci_probe
);
167 void st_nci_remove(struct nci_dev
*ndev
)
169 struct st_nci_info
*info
= nci_get_drvdata(ndev
);
171 ndlc_close(info
->ndlc
);
173 nci_unregister_device(ndev
);
174 nci_free_device(ndev
);
176 EXPORT_SYMBOL_GPL(st_nci_remove
);
178 MODULE_LICENSE("GPL");
179 MODULE_DESCRIPTION(DRIVER_DESC
);