Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ $schema: http://devicetree.org/meta-schemas/core.yaml#

title: NXP Semiconductors NCI NFC controller

description:
NFC controllers that speak plain NCI over I2C, with an enable line and an
interrupt. Besides NXP's, ST's ST54L uses the same transport.

maintainers:
- Krzysztof Kozlowski <krzk@kernel.org>

Expand All @@ -19,6 +23,7 @@ properties:
- nxp,pn547
- nxp,pn553
- nxp,pn557
- st,st54l
- const: nxp,nxp-nci-i2c

enable-gpios:
Expand Down
77 changes: 77 additions & 0 deletions drivers/nfc/nxp-nci/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/delay.h>
#include <linux/module.h>
#include <linux/nfc.h>
#include <linux/property.h>

#include <net/nfc/nci_core.h>

Expand Down Expand Up @@ -123,13 +124,88 @@ static const struct nci_driver_ops nxp_nci_core_ops[] = {
},
};

#define ST54L_NCI_PROP_NFC_MODE_SET 0x02
#define ST54L_NFC_MODE_SET 0x02

/*
* PROP_NFC_MODE_SET_RSP: on success the request ends with the controller's
* CORE_RESET_NTF, which the NCI core completes (nci_core_reset_ntf_packet()),
* bounded by nci_prop_cmd()'s timeout; ST's HAL waits for that NTF too.
*/
static int nxp_nci_st54l_mode_rsp(struct nci_dev *ndev, struct sk_buff *skb)
{
struct nxp_nci_info *info = nci_get_drvdata(ndev);
u8 status = skb->len ? skb->data[0] : NCI_STATUS_SYNTAX_ERROR;

if (!info->st54l)
return -ENOTSUPP;
if (status != NCI_STATUS_OK)
nci_req_complete(ndev, status);

return 0;
}

static const struct nci_driver_ops nxp_nci_prop_ops[] = {
{
.opcode = nci_opcode_pack(NCI_GID_PROPRIETARY,
ST54L_NCI_PROP_NFC_MODE_SET),
.rsp = nxp_nci_st54l_mode_rsp,
},
};

/*
* The ST54L speaks the same plain NCI over I2C, but needs two things ST's
* HAL does after init. First its NFC mode turned on (PROP_NFC_MODE_SET, as
* the HAL's halWrapperDataCallback does), after which the controller resets
* (CORE_RESET_NTF) and is initialised again; without it, the controller
* stops answering on I2C about 2 s after init whenever no discovery runs.
* Then the configuration the HAL sends: its proprietary 0xa1 (0x1e), 0xa2
* (0x19) and 0x80 (0x01), and TOTAL_DURATION 500 ms; without that it polls
* and never reports a target.
*/
static int nxp_nci_post_setup(struct nci_dev *ndev)
{
static const u8 st54l_mode_on[] = { ST54L_NFC_MODE_SET, 0x01 };
static const u8 init_v2[] = { 0x00, 0x00 };
static const u8 st54l_conf[] = {
0x04, /* number of parameters */
0xa1, 0x01, 0x1e,
0xa2, 0x01, 0x19,
0x80, 0x01, 0x01,
0x00, 0x02, 0xf4, 0x01, /* TOTAL_DURATION: 500 ms */
};
struct nxp_nci_info *info = nci_get_drvdata(ndev);
int r;

if (!info->st54l)
return 0;

r = nci_prop_cmd(ndev, ST54L_NCI_PROP_NFC_MODE_SET,
sizeof(st54l_mode_on), st54l_mode_on);
if (r)
return r;
/*
* The controller has reset (CORE_RESET_NTF) and is initialised again,
* as NCI 2.0 (nci_core_init() sends the 1.x form, which it rejects).
*/
r = nci_core_cmd(ndev, NCI_OP_CORE_INIT_CMD, sizeof(init_v2), init_v2);
if (r)
return r;

return nci_core_cmd(ndev, NCI_OP_CORE_SET_CONFIG_CMD,
sizeof(st54l_conf), st54l_conf);
}

static const struct nci_ops nxp_nci_ops = {
.open = nxp_nci_open,
.close = nxp_nci_close,
.send = nxp_nci_send,
.fw_download = nxp_nci_fw_download,
.post_setup = nxp_nci_post_setup,
.core_ops = nxp_nci_core_ops,
.n_core_ops = ARRAY_SIZE(nxp_nci_core_ops),
.prop_ops = nxp_nci_prop_ops,
.n_prop_ops = ARRAY_SIZE(nxp_nci_prop_ops),
};

int nxp_nci_probe(void *phy_id, struct device *pdev,
Expand All @@ -148,6 +224,7 @@ int nxp_nci_probe(void *phy_id, struct device *pdev,
info->pdev = pdev;
info->phy_ops = phy_ops;
info->max_payload = max_payload;
info->st54l = device_is_compatible(pdev, "st,st54l");
INIT_WORK(&info->fw_info.work, nxp_nci_fw_work);
init_completion(&info->fw_info.cmd_completion);
mutex_init(&info->info_lock);
Expand Down
3 changes: 3 additions & 0 deletions drivers/nfc/nxp-nci/nxp-nci.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ struct nxp_nci_info {
struct mutex info_lock;

struct nxp_nci_fw_info fw_info;

/* an ST ST54L: needs its configuration after init */
bool st54l;
};

int nxp_nci_fw_download(struct nci_dev *ndev, const char *firmware_name);
Expand Down