diff --git a/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml b/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml index 4f3847f649..fbf2b14f69 100644 --- a/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml +++ b/Documentation/devicetree/bindings/net/nfc/nxp,nci.yaml @@ -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 @@ -19,6 +23,7 @@ properties: - nxp,pn547 - nxp,pn553 - nxp,pn557 + - st,st54l - const: nxp,nxp-nci-i2c enable-gpios: diff --git a/drivers/nfc/nxp-nci/core.c b/drivers/nfc/nxp-nci/core.c index 386dcd4ff7..72f22eba50 100644 --- a/drivers/nfc/nxp-nci/core.c +++ b/drivers/nfc/nxp-nci/core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include @@ -123,11 +124,36 @@ static const struct nci_driver_ops nxp_nci_core_ops[] = { }, }; +/* + * The ST54L speaks the same plain NCI over I2C, but finds no card until it + * gets the configuration ST's HAL sends after init: its proprietary 0xa1 + * (0x1e), 0xa2 (0x19) and 0x80 (0x01), and TOTAL_DURATION 500 ms. Without + * it the controller polls and never reports a target. + */ +static int nxp_nci_post_setup(struct nci_dev *ndev) +{ + 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); + + if (!info->st54l) + return 0; + + 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), }; @@ -148,6 +174,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); diff --git a/drivers/nfc/nxp-nci/i2c.c b/drivers/nfc/nxp-nci/i2c.c index 92ce096e9b..0c1d2b3757 100644 --- a/drivers/nfc/nxp-nci/i2c.c +++ b/drivers/nfc/nxp-nci/i2c.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -37,6 +38,9 @@ struct nxp_nci_i2c_phy { struct gpio_desc *gpiod_en; struct gpio_desc *gpiod_fw; + /* quick retries for a controller that NACKs the transfer waking it */ + unsigned int wake_retries; + int hard_fault; /* * < 0 if hardware error occurred (e.g. i2c err) * and prevents normal operation. @@ -60,6 +64,7 @@ static int nxp_nci_i2c_set_mode(void *phy_id, static int nxp_nci_i2c_write(void *phy_id, struct sk_buff *skb) { + unsigned int i; int r; struct nxp_nci_i2c_phy *phy = phy_id; struct i2c_client *client = phy->i2c_dev; @@ -68,6 +73,14 @@ static int nxp_nci_i2c_write(void *phy_id, struct sk_buff *skb) return phy->hard_fault; r = i2c_master_send(client, skb->data, skb->len); + /* + * The ST54L NACKs the transfer that wakes it from standby and may be + * back in standby before the 110 ms retry: retry it quickly first. + */ + for (i = 0; r < 0 && i < phy->wake_retries; i++) { + usleep_range(2000, 2500); + r = i2c_master_send(client, skb->data, skb->len); + } if (r < 0) { /* Retry, chip was in standby */ msleep(110); @@ -291,6 +304,8 @@ static int nxp_nci_i2c_probe(struct i2c_client *client) phy->i2c_dev = client; i2c_set_clientdata(client, phy); + if (device_is_compatible(dev, "st,st54l")) + phy->wake_retries = 5; r = devm_acpi_dev_add_driver_gpios(dev, acpi_nxp_nci_gpios); if (r) diff --git a/drivers/nfc/nxp-nci/nxp-nci.h b/drivers/nfc/nxp-nci/nxp-nci.h index ae3fb2735a..68b0f53d6f 100644 --- a/drivers/nfc/nxp-nci/nxp-nci.h +++ b/drivers/nfc/nxp-nci/nxp-nci.h @@ -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);