Skip to content

Commit ed06aee

Browse files
cricard13Samuel Ortiz
authored andcommitted
nfc: st-nci: Rename st21nfcb to st-nci
STMicroelectronics NFC NCI chips family is extending with the new ST21NFCC using the AMS AS39230 RF booster. The st21nfcb driver is relevant for this solution and might be with future products. Signed-off-by: Christophe Ricard <[email protected]> Signed-off-by: Samuel Ortiz <[email protected]>
1 parent 2df7f8c commit ed06aee

File tree

18 files changed

+585
-553
lines changed

18 files changed

+585
-553
lines changed

Documentation/devicetree/bindings/net/nfc/st21nfcb.txt renamed to Documentation/devicetree/bindings/net/nfc/st-nci.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
* STMicroelectronics SAS. ST21NFCB NFC Controller
1+
* STMicroelectronics SAS. ST NCI NFC Controller
22

33
Required properties:
4-
- compatible: Should be "st,st21nfcb-i2c".
4+
- compatible: Should be "st,st21nfcb-i2c" or "st,st21nfcc-i2c".
55
- clock-frequency: I²C work frequency.
66
- reg: address on the bus
77
- interrupt-parent: phandle for the interrupt gpio controller

drivers/nfc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ source "drivers/nfc/pn544/Kconfig"
7272
source "drivers/nfc/microread/Kconfig"
7373
source "drivers/nfc/nfcmrvl/Kconfig"
7474
source "drivers/nfc/st21nfca/Kconfig"
75-
source "drivers/nfc/st21nfcb/Kconfig"
75+
source "drivers/nfc/st-nci/Kconfig"
7676
source "drivers/nfc/nxp-nci/Kconfig"
7777
endmenu

drivers/nfc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ obj-$(CONFIG_NFC_PORT100) += port100.o
1212
obj-$(CONFIG_NFC_MRVL) += nfcmrvl/
1313
obj-$(CONFIG_NFC_TRF7970A) += trf7970a.o
1414
obj-$(CONFIG_NFC_ST21NFCA) += st21nfca/
15-
obj-$(CONFIG_NFC_ST21NFCB) += st21nfcb/
15+
obj-$(CONFIG_NFC_ST_NCI) += st-nci/
1616
obj-$(CONFIG_NFC_NXP_NCI) += nxp-nci/

drivers/nfc/st-nci/Kconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
config NFC_ST_NCI
2+
tristate "STMicroelectronics ST NCI NFC driver"
3+
depends on NFC_NCI
4+
default n
5+
---help---
6+
STMicroelectronics NFC NCI chips core driver. It implements the chipset
7+
NCI logic and hooks into the NFC kernel APIs. Physical layers will
8+
register against it.
9+
10+
To compile this driver as a module, choose m here. The module will
11+
be called st-nci.
12+
Say N if unsure.
13+
14+
config NFC_ST_NCI_I2C
15+
tristate "NFC ST NCI i2c support"
16+
depends on NFC_ST_NCI && I2C
17+
---help---
18+
This module adds support for an I2C interface to the
19+
STMicroelectronics NFC NCI chips familly.
20+
Select this if your platform is using the i2c bus.
21+
22+
If you choose to build a module, it'll be called st-nci_i2c.
23+
Say N if unsure.

drivers/nfc/st-nci/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Makefile for ST21NFCB NCI based NFC driver
3+
#
4+
5+
st-nci-objs = ndlc.o core.o st-nci_se.o
6+
obj-$(CONFIG_NFC_ST_NCI) += st-nci.o
7+
8+
st-nci_i2c-objs = i2c.o
9+
obj-$(CONFIG_NFC_ST_NCI_I2C) += st-nci_i2c.o

drivers/nfc/st-nci/core.c

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
* NCI based Driver for STMicroelectronics NFC Chip
3+
*
4+
* Copyright (C) 2014-2015 STMicroelectronics SAS. All rights reserved.
5+
*
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.
9+
*
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.
14+
*
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/>.
17+
*/
18+
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>
25+
26+
#include "st-nci.h"
27+
#include "st-nci_se.h"
28+
29+
#define DRIVER_DESC "NCI NFC driver for ST_NCI"
30+
31+
#define ST_NCI1_X_PROPRIETARY_ISO15693 0x83
32+
33+
static int st_nci_init(struct nci_dev *ndev)
34+
{
35+
struct nci_mode_set_cmd cmd;
36+
37+
cmd.cmd_type = ST_NCI_SET_NFC_MODE;
38+
cmd.mode = 1;
39+
40+
return nci_prop_cmd(ndev, ST_NCI_CORE_PROP,
41+
sizeof(struct nci_mode_set_cmd), (__u8 *)&cmd);
42+
}
43+
44+
static int st_nci_open(struct nci_dev *ndev)
45+
{
46+
struct st_nci_info *info = nci_get_drvdata(ndev);
47+
int r;
48+
49+
if (test_and_set_bit(ST_NCI_RUNNING, &info->flags))
50+
return 0;
51+
52+
r = ndlc_open(info->ndlc);
53+
if (r)
54+
clear_bit(ST_NCI_RUNNING, &info->flags);
55+
56+
return r;
57+
}
58+
59+
static int st_nci_close(struct nci_dev *ndev)
60+
{
61+
struct st_nci_info *info = nci_get_drvdata(ndev);
62+
63+
if (!test_bit(ST_NCI_RUNNING, &info->flags))
64+
return 0;
65+
66+
ndlc_close(info->ndlc);
67+
68+
clear_bit(ST_NCI_RUNNING, &info->flags);
69+
70+
return 0;
71+
}
72+
73+
static int st_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
74+
{
75+
struct st_nci_info *info = nci_get_drvdata(ndev);
76+
77+
skb->dev = (void *)ndev;
78+
79+
if (!test_bit(ST_NCI_RUNNING, &info->flags))
80+
return -EBUSY;
81+
82+
return ndlc_send(info->ndlc, skb);
83+
}
84+
85+
static __u32 st_nci_get_rfprotocol(struct nci_dev *ndev,
86+
__u8 rf_protocol)
87+
{
88+
return rf_protocol == ST_NCI1_X_PROPRIETARY_ISO15693 ?
89+
NFC_PROTO_ISO15693_MASK : 0;
90+
}
91+
92+
static int st_nci_prop_rsp_packet(struct nci_dev *ndev,
93+
struct sk_buff *skb)
94+
{
95+
__u8 status = skb->data[0];
96+
97+
nci_req_complete(ndev, status);
98+
return 0;
99+
}
100+
101+
static struct nci_prop_ops st_nci_prop_ops[] = {
102+
{
103+
.opcode = nci_opcode_pack(NCI_GID_PROPRIETARY,
104+
ST_NCI_CORE_PROP),
105+
.rsp = st_nci_prop_rsp_packet,
106+
},
107+
};
108+
109+
static struct nci_ops st_nci_ops = {
110+
.init = st_nci_init,
111+
.open = st_nci_open,
112+
.close = st_nci_close,
113+
.send = st_nci_send,
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),
124+
};
125+
126+
int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
127+
int phy_tailroom)
128+
{
129+
struct st_nci_info *info;
130+
int r;
131+
u32 protocols;
132+
133+
info = devm_kzalloc(ndlc->dev,
134+
sizeof(struct st_nci_info), GFP_KERNEL);
135+
if (!info)
136+
return -ENOMEM;
137+
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;
145+
146+
ndlc->ndev = nci_allocate_device(&st_nci_ops, protocols,
147+
phy_headroom, phy_tailroom);
148+
if (!ndlc->ndev) {
149+
pr_err("Cannot allocate nfc ndev\n");
150+
return -ENOMEM;
151+
}
152+
info->ndlc = ndlc;
153+
154+
nci_set_drvdata(ndlc->ndev, info);
155+
156+
r = nci_register_device(ndlc->ndev);
157+
if (r) {
158+
pr_err("Cannot register nfc device to nci core\n");
159+
nci_free_device(ndlc->ndev);
160+
return r;
161+
}
162+
163+
return st_nci_se_init(ndlc->ndev);
164+
}
165+
EXPORT_SYMBOL_GPL(st_nci_probe);
166+
167+
void st_nci_remove(struct nci_dev *ndev)
168+
{
169+
struct st_nci_info *info = nci_get_drvdata(ndev);
170+
171+
ndlc_close(info->ndlc);
172+
173+
nci_unregister_device(ndev);
174+
nci_free_device(ndev);
175+
}
176+
EXPORT_SYMBOL_GPL(st_nci_remove);
177+
178+
MODULE_LICENSE("GPL");
179+
MODULE_DESCRIPTION(DRIVER_DESC);

0 commit comments

Comments
 (0)