Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b8f8be3f authored by David S. Miller's avatar David S. Miller
Browse files


NFC: 3.20 first pull request

This is the first NFC pull request for 3.20.

With this one we have:

- Secure element support for the ST Micro st21nfca driver. This depends
  on a few HCI internal changes in order for example to support more
  than one secure element per controller.

- ACPI support for NXP's pn544 HCI driver. This controller is found on
  many x86 SoCs and is typically enumerated on the ACPI bus there.

- A few st21nfca and st21nfcb fixes.

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents ff660f75 0a5942c8
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
* STMicroelectronics SAS. ST21NFCA NFC Controller

Required properties:
- compatible: Should be "st,st21nfca_i2c".
- compatible: Should be "st,st21nfca-i2c".
- clock-frequency: I²C work frequency.
- reg: address on the bus
- interrupt-parent: phandle for the interrupt gpio controller
@@ -11,6 +11,10 @@ Required properties:
Optional SoC Specific Properties:
- pinctrl-names: Contains only one value - "default".
- pintctrl-0: Specifies the pin control groups used for this controller.
- ese-present: Specifies that an ese is physically connected to the nfc
controller.
- uicc-present: Specifies that the uicc swp signal can be physically
connected to the nfc controller.

Example (for ARM-based BeagleBoard xM with ST21NFCA on I2C2):

@@ -20,7 +24,7 @@ Example (for ARM-based BeagleBoard xM with ST21NFCA on I2C2):

	st21nfca: st21nfca@1 {

		compatible = "st,st21nfca_i2c";
		compatible = "st,st21nfca-i2c";

		reg = <0x01>;
		clock-frequency = <400000>;
@@ -29,5 +33,8 @@ Example (for ARM-based BeagleBoard xM with ST21NFCA on I2C2):
		interrupts = <2 IRQ_TYPE_LEVEL_LOW>;

		enable-gpios = <&gpio5 29 GPIO_ACTIVE_HIGH>;

		ese-present;
		uicc-present;
	};
};
+2 −2
Original line number Diff line number Diff line
* STMicroelectronics SAS. ST21NFCB NFC Controller

Required properties:
- compatible: Should be "st,st21nfcb_i2c".
- compatible: Should be "st,st21nfcb-i2c".
- clock-frequency: I²C work frequency.
- reg: address on the bus
- interrupt-parent: phandle for the interrupt gpio controller
@@ -20,7 +20,7 @@ Example (for ARM-based BeagleBoard xM with ST21NFCB on I2C2):

	st21nfcb: st21nfcb@8 {

		compatible = "st,st21nfcb_i2c";
		compatible = "st,st21nfcb-i2c";

		reg = <0x08>;
		clock-frequency = <400000>;
+2 −1
Original line number Diff line number Diff line
@@ -557,10 +557,11 @@ static void microread_target_discovered(struct nfc_hci_dev *hdev, u8 gate,
		pr_err("Failed to handle discovered target err=%d\n", r);
}

static int microread_event_received(struct nfc_hci_dev *hdev, u8 gate,
static int microread_event_received(struct nfc_hci_dev *hdev, u8 pipe,
				     u8 event, struct sk_buff *skb)
{
	int r;
	u8 gate = hdev->pipes[pipe].gate;
	u8 mode;

	pr_info("Microread received event 0x%x to gate 0x%x\n", event, gate);
+121 −12
Original line number Diff line number Diff line
@@ -24,11 +24,13 @@
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/of_irq.h>
#include <linux/acpi.h>
#include <linux/miscdevice.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/nfc.h>
#include <linux/firmware.h>
#include <linux/gpio/consumer.h>
#include <linux/platform_data/pn544.h>
#include <asm/unaligned.h>

@@ -41,6 +43,11 @@
#define PN544_I2C_FRAME_HEADROOM 1
#define PN544_I2C_FRAME_TAILROOM 2

/* GPIO names */
#define PN544_GPIO_NAME_IRQ "pn544_irq"
#define PN544_GPIO_NAME_FW  "pn544_fw"
#define PN544_GPIO_NAME_EN  "pn544_en"

/* framing in HCI mode */
#define PN544_HCI_I2C_LLC_LEN		1
#define PN544_HCI_I2C_LLC_CRC		2
@@ -58,6 +65,13 @@ static struct i2c_device_id pn544_hci_i2c_id_table[] = {

MODULE_DEVICE_TABLE(i2c, pn544_hci_i2c_id_table);

static const struct acpi_device_id pn544_hci_i2c_acpi_match[] = {
	{"NXP5440", 0},
	{}
};

MODULE_DEVICE_TABLE(acpi, pn544_hci_i2c_acpi_match);

#define PN544_HCI_I2C_DRIVER_NAME "pn544_hci_i2c"

/*
@@ -195,18 +209,19 @@ static void pn544_hci_i2c_platform_init(struct pn544_i2c_phy *phy)
	nfc_info(&phy->i2c_dev->dev, "Detecting nfc_en polarity\n");

	/* Disable fw download */
	gpio_set_value(phy->gpio_fw, 0);
	gpio_set_value_cansleep(phy->gpio_fw, 0);

	for (polarity = 0; polarity < 2; polarity++) {
		phy->en_polarity = polarity;
		retry = 3;
		while (retry--) {
			/* power off */
			gpio_set_value(phy->gpio_en, !phy->en_polarity);
			gpio_set_value_cansleep(phy->gpio_en,
						!phy->en_polarity);
			usleep_range(10000, 15000);

			/* power on */
			gpio_set_value(phy->gpio_en, phy->en_polarity);
			gpio_set_value_cansleep(phy->gpio_en, phy->en_polarity);
			usleep_range(10000, 15000);

			/* send reset */
@@ -225,13 +240,14 @@ static void pn544_hci_i2c_platform_init(struct pn544_i2c_phy *phy)
		"Could not detect nfc_en polarity, fallback to active high\n");

out:
	gpio_set_value(phy->gpio_en, !phy->en_polarity);
	gpio_set_value_cansleep(phy->gpio_en, !phy->en_polarity);
}

static void pn544_hci_i2c_enable_mode(struct pn544_i2c_phy *phy, int run_mode)
{
	gpio_set_value(phy->gpio_fw, run_mode == PN544_FW_MODE ? 1 : 0);
	gpio_set_value(phy->gpio_en, phy->en_polarity);
	gpio_set_value_cansleep(phy->gpio_fw,
				run_mode == PN544_FW_MODE ? 1 : 0);
	gpio_set_value_cansleep(phy->gpio_en, phy->en_polarity);
	usleep_range(10000, 15000);

	phy->run_mode = run_mode;
@@ -254,14 +270,14 @@ static void pn544_hci_i2c_disable(void *phy_id)
{
	struct pn544_i2c_phy *phy = phy_id;

	gpio_set_value(phy->gpio_fw, 0);
	gpio_set_value(phy->gpio_en, !phy->en_polarity);
	gpio_set_value_cansleep(phy->gpio_fw, 0);
	gpio_set_value_cansleep(phy->gpio_en, !phy->en_polarity);
	usleep_range(10000, 15000);

	gpio_set_value(phy->gpio_en, phy->en_polarity);
	gpio_set_value_cansleep(phy->gpio_en, phy->en_polarity);
	usleep_range(10000, 15000);

	gpio_set_value(phy->gpio_en, !phy->en_polarity);
	gpio_set_value_cansleep(phy->gpio_en, !phy->en_polarity);
	usleep_range(10000, 15000);

	phy->powered = 0;
@@ -859,6 +875,90 @@ static void pn544_hci_i2c_fw_work(struct work_struct *work)
	}
}

static int pn544_hci_i2c_acpi_request_resources(struct i2c_client *client)
{
	struct pn544_i2c_phy *phy = i2c_get_clientdata(client);
	const struct acpi_device_id *id;
	struct gpio_desc *gpiod_en, *gpiod_irq, *gpiod_fw;
	struct device *dev;
	int ret;

	if (!client)
		return -EINVAL;

	dev = &client->dev;

	/* Match the struct device against a given list of ACPI IDs */
	id = acpi_match_device(dev->driver->acpi_match_table, dev);

	if (!id)
		return -ENODEV;

	/* Get EN GPIO from ACPI */
	gpiod_en = devm_gpiod_get_index(dev, PN544_GPIO_NAME_EN, 1);
	if (IS_ERR(gpiod_en)) {
		nfc_err(dev,
			"Unable to get EN GPIO\n");
		return -ENODEV;
	}

	phy->gpio_en  = desc_to_gpio(gpiod_en);

	/* Configuration EN GPIO */
	ret = gpiod_direction_output(gpiod_en, 0);
	if (ret) {
		nfc_err(dev, "Fail EN pin direction\n");
		return ret;
	}

	/* Get FW GPIO from ACPI */
	gpiod_fw = devm_gpiod_get_index(dev, PN544_GPIO_NAME_FW, 2);
	if (IS_ERR(gpiod_fw)) {
		nfc_err(dev,
			"Unable to get FW GPIO\n");
		return -ENODEV;
	}

	phy->gpio_fw  = desc_to_gpio(gpiod_fw);

	/* Configuration FW GPIO */
	ret = gpiod_direction_output(gpiod_fw, 0);
	if (ret) {
		nfc_err(dev, "Fail FW pin direction\n");
		return ret;
	}

	/* Get IRQ GPIO */
	gpiod_irq = devm_gpiod_get_index(dev, PN544_GPIO_NAME_IRQ, 0);
	if (IS_ERR(gpiod_irq)) {
		nfc_err(dev,
			"Unable to get IRQ GPIO\n");
		return -ENODEV;
	}

	phy->gpio_irq = desc_to_gpio(gpiod_irq);

	/* Configure IRQ GPIO */
	ret = gpiod_direction_input(gpiod_irq);
	if (ret) {
		nfc_err(dev, "Fail IRQ pin direction\n");
		return ret;
	}

	/* Map the pin to an IRQ */
	ret = gpiod_to_irq(gpiod_irq);
	if (ret < 0) {
		nfc_err(dev, "Fail pin IRQ mapping\n");
		return ret;
	}

	nfc_info(dev, "GPIO resource, no:%d irq:%d\n",
			desc_to_gpio(gpiod_irq), ret);
	client->irq = ret;

	return 0;
}

#ifdef CONFIG_OF

static int pn544_hci_i2c_of_request_resources(struct i2c_client *client)
@@ -884,7 +984,7 @@ static int pn544_hci_i2c_of_request_resources(struct i2c_client *client)
	phy->gpio_en = ret;

	/* Configuration of EN GPIO */
	ret = gpio_request(phy->gpio_en, "pn544_en");
	ret = gpio_request(phy->gpio_en, PN544_GPIO_NAME_EN);
	if (ret) {
		nfc_err(&client->dev, "Fail EN pin\n");
		goto err_dt;
@@ -906,7 +1006,7 @@ static int pn544_hci_i2c_of_request_resources(struct i2c_client *client)
	phy->gpio_fw = ret;

	/* Configuration of FW GPIO */
	ret = gpio_request(phy->gpio_fw, "pn544_fw");
	ret = gpio_request(phy->gpio_fw, PN544_GPIO_NAME_FW);
	if (ret) {
		nfc_err(&client->dev, "Fail FW pin\n");
		goto err_gpio_en;
@@ -1001,6 +1101,14 @@ static int pn544_hci_i2c_probe(struct i2c_client *client,
		phy->gpio_en = pdata->get_gpio(NFC_GPIO_ENABLE);
		phy->gpio_fw = pdata->get_gpio(NFC_GPIO_FW_RESET);
		phy->gpio_irq = pdata->get_gpio(NFC_GPIO_IRQ);
	/* Using ACPI */
	} else if (ACPI_HANDLE(&client->dev)) {
		r = pn544_hci_i2c_acpi_request_resources(client);
		if (r) {
			nfc_err(&client->dev,
				"Cannot get ACPI data\n");
			return r;
		}
	} else {
		nfc_err(&client->dev, "No platform data\n");
		return -EINVAL;
@@ -1080,6 +1188,7 @@ static struct i2c_driver pn544_hci_i2c_driver = {
		   .name = PN544_HCI_I2C_DRIVER_NAME,
		   .owner  = THIS_MODULE,
		   .of_match_table = of_match_ptr(of_pn544_i2c_match),
		   .acpi_match_table = ACPI_PTR(pn544_hci_i2c_acpi_match),
		  },
	.probe = pn544_hci_i2c_probe,
	.id_table = pn544_hci_i2c_id_table,
+2 −1
Original line number Diff line number Diff line
@@ -724,10 +724,11 @@ static int pn544_hci_check_presence(struct nfc_hci_dev *hdev,
 * <= 0: driver handled the event, skb consumed
 *    1: driver does not handle the event, please do standard processing
 */
static int pn544_hci_event_received(struct nfc_hci_dev *hdev, u8 gate, u8 event,
static int pn544_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
				    struct sk_buff *skb)
{
	struct sk_buff *rgb_skb = NULL;
	u8 gate = hdev->pipes[pipe].gate;
	int r;

	pr_debug("hci event %d\n", event);
Loading