]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/nfc/st-nci/i2c.c
Merge tag 'libnvdimm-for-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdim...
[karo-tx-linux.git] / drivers / nfc / st-nci / i2c.c
index 6d3d8e43fa50475670edd08bad91f8c99a54d3cf..515f08d037fb40c0656dd07808c67e6ffffc1f0e 100644 (file)
 
 #include <linux/module.h>
 #include <linux/i2c.h>
-#include <linux/gpio.h>
 #include <linux/gpio/consumer.h>
-#include <linux/of_irq.h>
-#include <linux/of_gpio.h>
 #include <linux/acpi.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/nfc.h>
+#include <linux/of.h>
 
 #include "st-nci.h"
 
 #define ST_NCI_DRIVER_NAME "st_nci"
 #define ST_NCI_I2C_DRIVER_NAME "st_nci_i2c"
 
-#define ST_NCI_GPIO_NAME_RESET "reset"
-
 struct st_nci_i2c_phy {
        struct i2c_client *i2c_dev;
        struct llt_ndlc *ndlc;
 
        bool irq_active;
 
-       unsigned int gpio_reset;
-       unsigned int irq_polarity;
+       struct gpio_desc *gpiod_reset;
 
        struct st_nci_se_status se_status;
 };
@@ -60,9 +55,9 @@ static int st_nci_i2c_enable(void *phy_id)
 {
        struct st_nci_i2c_phy *phy = phy_id;
 
-       gpio_set_value(phy->gpio_reset, 0);
+       gpiod_set_value(phy->gpiod_reset, 0);
        usleep_range(10000, 15000);
-       gpio_set_value(phy->gpio_reset, 1);
+       gpiod_set_value(phy->gpiod_reset, 1);
        usleep_range(80000, 85000);
 
        if (phy->ndlc->powered == 0 && phy->irq_active == 0) {
@@ -208,82 +203,17 @@ static struct nfc_phy_ops i2c_phy_ops = {
        .disable = st_nci_i2c_disable,
 };
 
-static int st_nci_i2c_acpi_request_resources(struct i2c_client *client)
-{
-       struct st_nci_i2c_phy *phy = i2c_get_clientdata(client);
-       struct gpio_desc *gpiod_reset;
-       struct device *dev = &client->dev;
-       u8 tmp;
-
-       /* Get RESET GPIO from ACPI */
-       gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, 1,
-                                          GPIOD_OUT_HIGH);
-       if (IS_ERR(gpiod_reset)) {
-               nfc_err(dev, "Unable to get RESET GPIO\n");
-               return -ENODEV;
-       }
-
-       phy->gpio_reset = desc_to_gpio(gpiod_reset);
-
-       phy->irq_polarity = irq_get_trigger_type(client->irq);
-
-       phy->se_status.is_ese_present = false;
-       phy->se_status.is_uicc_present = false;
-
-       if (device_property_present(dev, "ese-present")) {
-               device_property_read_u8(dev, "ese-present", &tmp);
-               phy->se_status.is_ese_present = tmp;
-       }
-
-       if (device_property_present(dev, "uicc-present")) {
-               device_property_read_u8(dev, "uicc-present", &tmp);
-               phy->se_status.is_uicc_present = tmp;
-       }
-
-       return 0;
-}
-
-static int st_nci_i2c_of_request_resources(struct i2c_client *client)
-{
-       struct st_nci_i2c_phy *phy = i2c_get_clientdata(client);
-       struct device_node *pp;
-       int gpio;
-       int r;
-
-       pp = client->dev.of_node;
-       if (!pp)
-               return -ENODEV;
-
-       /* Get GPIO from device tree */
-       gpio = of_get_named_gpio(pp, "reset-gpios", 0);
-       if (gpio < 0) {
-               nfc_err(&client->dev,
-                       "Failed to retrieve reset-gpios from device tree\n");
-               return gpio;
-       }
-
-       /* GPIO request and configuration */
-       r = devm_gpio_request_one(&client->dev, gpio,
-                               GPIOF_OUT_INIT_HIGH, ST_NCI_GPIO_NAME_RESET);
-       if (r) {
-               nfc_err(&client->dev, "Failed to request reset pin\n");
-               return r;
-       }
-       phy->gpio_reset = gpio;
-
-       phy->irq_polarity = irq_get_trigger_type(client->irq);
-
-       phy->se_status.is_ese_present =
-                               of_property_read_bool(pp, "ese-present");
-       phy->se_status.is_uicc_present =
-                               of_property_read_bool(pp, "uicc-present");
+static const struct acpi_gpio_params reset_gpios = { 1, 0, false };
 
-       return 0;
-}
+static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = {
+       { "reset-gpios", &reset_gpios, 1 },
+       {},
+};
 
 static int st_nci_i2c_probe(struct i2c_client *client,
                                  const struct i2c_device_id *id)
 {
+       struct device *dev = &client->dev;
        struct st_nci_i2c_phy *phy;
        int r;
 
@@ -295,8 +225,7 @@ static int st_nci_i2c_probe(struct i2c_client *client,
                return -ENODEV;
        }
 
-       phy = devm_kzalloc(&client->dev, sizeof(struct st_nci_i2c_phy),
-                          GFP_KERNEL);
+       phy = devm_kzalloc(dev, sizeof(struct st_nci_i2c_phy), GFP_KERNEL);
        if (!phy)
                return -ENOMEM;
 
@@ -304,24 +233,22 @@ static int st_nci_i2c_probe(struct i2c_client *client,
 
        i2c_set_clientdata(client, phy);
 
-       if (client->dev.of_node) {
-               r = st_nci_i2c_of_request_resources(client);
-               if (r) {
-                       nfc_err(&client->dev, "No platform data\n");
-                       return r;
-               }
-       } else if (ACPI_HANDLE(&client->dev)) {
-               r = st_nci_i2c_acpi_request_resources(client);
-               if (r) {
-                       nfc_err(&client->dev, "Cannot get ACPI data\n");
-                       return r;
-               }
-       } else {
-               nfc_err(&client->dev,
-                       "st_nci platform resources not available\n");
+       r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios);
+       if (r)
+               dev_dbg(dev, "Unable to add GPIO mapping table\n");
+
+       /* Get RESET GPIO */
+       phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+       if (IS_ERR(phy->gpiod_reset)) {
+               nfc_err(dev, "Unable to get RESET GPIO\n");
                return -ENODEV;
        }
 
+       phy->se_status.is_ese_present =
+                               device_property_read_bool(dev, "ese-present");
+       phy->se_status.is_uicc_present =
+                               device_property_read_bool(dev, "uicc-present");
+
        r = ndlc_probe(phy, &i2c_phy_ops, &client->dev,
                        ST_NCI_FRAME_HEADROOM, ST_NCI_FRAME_TAILROOM,
                        &phy->ndlc, &phy->se_status);
@@ -333,7 +260,7 @@ static int st_nci_i2c_probe(struct i2c_client *client,
        phy->irq_active = true;
        r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
                                st_nci_irq_thread_fn,
-                               phy->irq_polarity | IRQF_ONESHOT,
+                               IRQF_ONESHOT,
                                ST_NCI_DRIVER_NAME, phy);
        if (r < 0)
                nfc_err(&client->dev, "Unable to register IRQ handler\n");