Skip to content

Commit

Permalink
nfc: st-nci: Rename st21nfcb to st-nci
Browse files Browse the repository at this point in the history
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 <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Christophe Ricard authored and Samuel Ortiz committed Jun 10, 2015
1 parent 2df7f8c commit ed06aee
Show file tree
Hide file tree
Showing 18 changed files with 585 additions and 553 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
* STMicroelectronics SAS. ST21NFCB NFC Controller
* STMicroelectronics SAS. ST NCI NFC Controller

Required properties:
- compatible: Should be "st,st21nfcb-i2c".
- compatible: Should be "st,st21nfcb-i2c" or "st,st21nfcc-i2c".
- clock-frequency: I²C work frequency.
- reg: address on the bus
- interrupt-parent: phandle for the interrupt gpio controller
Expand Down
2 changes: 1 addition & 1 deletion drivers/nfc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ source "drivers/nfc/pn544/Kconfig"
source "drivers/nfc/microread/Kconfig"
source "drivers/nfc/nfcmrvl/Kconfig"
source "drivers/nfc/st21nfca/Kconfig"
source "drivers/nfc/st21nfcb/Kconfig"
source "drivers/nfc/st-nci/Kconfig"
source "drivers/nfc/nxp-nci/Kconfig"
endmenu
2 changes: 1 addition & 1 deletion drivers/nfc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ obj-$(CONFIG_NFC_PORT100) += port100.o
obj-$(CONFIG_NFC_MRVL) += nfcmrvl/
obj-$(CONFIG_NFC_TRF7970A) += trf7970a.o
obj-$(CONFIG_NFC_ST21NFCA) += st21nfca/
obj-$(CONFIG_NFC_ST21NFCB) += st21nfcb/
obj-$(CONFIG_NFC_ST_NCI) += st-nci/
obj-$(CONFIG_NFC_NXP_NCI) += nxp-nci/
23 changes: 23 additions & 0 deletions drivers/nfc/st-nci/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
config NFC_ST_NCI
tristate "STMicroelectronics ST NCI NFC driver"
depends on NFC_NCI
default n
---help---
STMicroelectronics NFC NCI chips core driver. It implements the chipset
NCI logic and hooks into the NFC kernel APIs. Physical layers will
register against it.

To compile this driver as a module, choose m here. The module will
be called st-nci.
Say N if unsure.

config NFC_ST_NCI_I2C
tristate "NFC ST NCI i2c support"
depends on NFC_ST_NCI && I2C
---help---
This module adds support for an I2C interface to the
STMicroelectronics NFC NCI chips familly.
Select this if your platform is using the i2c bus.

If you choose to build a module, it'll be called st-nci_i2c.
Say N if unsure.
9 changes: 9 additions & 0 deletions drivers/nfc/st-nci/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Makefile for ST21NFCB NCI based NFC driver
#

st-nci-objs = ndlc.o core.o st-nci_se.o
obj-$(CONFIG_NFC_ST_NCI) += st-nci.o

st-nci_i2c-objs = i2c.o
obj-$(CONFIG_NFC_ST_NCI_I2C) += st-nci_i2c.o
179 changes: 179 additions & 0 deletions drivers/nfc/st-nci/core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* NCI based Driver for STMicroelectronics NFC Chip
*
* Copyright (C) 2014-2015 STMicroelectronics SAS. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include <linux/module.h>
#include <linux/nfc.h>
#include <net/nfc/nci.h>
#include <net/nfc/nci_core.h>
#include <linux/gpio.h>
#include <linux/delay.h>

#include "st-nci.h"
#include "st-nci_se.h"

#define DRIVER_DESC "NCI NFC driver for ST_NCI"

#define ST_NCI1_X_PROPRIETARY_ISO15693 0x83

static int st_nci_init(struct nci_dev *ndev)
{
struct nci_mode_set_cmd cmd;

cmd.cmd_type = ST_NCI_SET_NFC_MODE;
cmd.mode = 1;

return nci_prop_cmd(ndev, ST_NCI_CORE_PROP,
sizeof(struct nci_mode_set_cmd), (__u8 *)&cmd);
}

static int st_nci_open(struct nci_dev *ndev)
{
struct st_nci_info *info = nci_get_drvdata(ndev);
int r;

if (test_and_set_bit(ST_NCI_RUNNING, &info->flags))
return 0;

r = ndlc_open(info->ndlc);
if (r)
clear_bit(ST_NCI_RUNNING, &info->flags);

return r;
}

static int st_nci_close(struct nci_dev *ndev)
{
struct st_nci_info *info = nci_get_drvdata(ndev);

if (!test_bit(ST_NCI_RUNNING, &info->flags))
return 0;

ndlc_close(info->ndlc);

clear_bit(ST_NCI_RUNNING, &info->flags);

return 0;
}

static int st_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
{
struct st_nci_info *info = nci_get_drvdata(ndev);

skb->dev = (void *)ndev;

if (!test_bit(ST_NCI_RUNNING, &info->flags))
return -EBUSY;

return ndlc_send(info->ndlc, skb);
}

static __u32 st_nci_get_rfprotocol(struct nci_dev *ndev,
__u8 rf_protocol)
{
return rf_protocol == ST_NCI1_X_PROPRIETARY_ISO15693 ?
NFC_PROTO_ISO15693_MASK : 0;
}

static int st_nci_prop_rsp_packet(struct nci_dev *ndev,
struct sk_buff *skb)
{
__u8 status = skb->data[0];

nci_req_complete(ndev, status);
return 0;
}

static struct nci_prop_ops st_nci_prop_ops[] = {
{
.opcode = nci_opcode_pack(NCI_GID_PROPRIETARY,
ST_NCI_CORE_PROP),
.rsp = st_nci_prop_rsp_packet,
},
};

static struct nci_ops st_nci_ops = {
.init = st_nci_init,
.open = st_nci_open,
.close = st_nci_close,
.send = st_nci_send,
.get_rfprotocol = st_nci_get_rfprotocol,
.discover_se = st_nci_discover_se,
.enable_se = st_nci_enable_se,
.disable_se = st_nci_disable_se,
.se_io = st_nci_se_io,
.hci_load_session = st_nci_hci_load_session,
.hci_event_received = st_nci_hci_event_received,
.hci_cmd_received = st_nci_hci_cmd_received,
.prop_ops = st_nci_prop_ops,
.n_prop_ops = ARRAY_SIZE(st_nci_prop_ops),
};

int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
int phy_tailroom)
{
struct st_nci_info *info;
int r;
u32 protocols;

info = devm_kzalloc(ndlc->dev,
sizeof(struct st_nci_info), GFP_KERNEL);
if (!info)
return -ENOMEM;

protocols = NFC_PROTO_JEWEL_MASK
| NFC_PROTO_MIFARE_MASK
| NFC_PROTO_FELICA_MASK
| NFC_PROTO_ISO14443_MASK
| NFC_PROTO_ISO14443_B_MASK
| NFC_PROTO_ISO15693_MASK
| NFC_PROTO_NFC_DEP_MASK;

ndlc->ndev = nci_allocate_device(&st_nci_ops, protocols,
phy_headroom, phy_tailroom);
if (!ndlc->ndev) {
pr_err("Cannot allocate nfc ndev\n");
return -ENOMEM;
}
info->ndlc = ndlc;

nci_set_drvdata(ndlc->ndev, info);

r = nci_register_device(ndlc->ndev);
if (r) {
pr_err("Cannot register nfc device to nci core\n");
nci_free_device(ndlc->ndev);
return r;
}

return st_nci_se_init(ndlc->ndev);
}
EXPORT_SYMBOL_GPL(st_nci_probe);

void st_nci_remove(struct nci_dev *ndev)
{
struct st_nci_info *info = nci_get_drvdata(ndev);

ndlc_close(info->ndlc);

nci_unregister_device(ndev);
nci_free_device(ndev);
}
EXPORT_SYMBOL_GPL(st_nci_remove);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION(DRIVER_DESC);
Loading

0 comments on commit ed06aee

Please sign in to comment.