NFC: clean up for ACPI GPIO usage
v2 cover NFC: clean up for ACPI GPIO usage
This clean up series to NFC drivers that are using GPIOs on ACPI enabled platforms. Since GPIO ACPI library goes stricter about requesting resources we need to amend drivers for that. Here we are for NFC subsystem.
While doing above, get rid of legacy and unused platform data as well as some artificial IDs.
Changelog v2:
- add patches 1,4-12
Andy Shevchenko (12):
NFC: pn544: Switch to devm_acpi_dev_add_driver_gpios()
NFC: st21nfca: Add GPIO ACPI mapping table
NFC: st21nfca: Get rid of code duplication in ->probe()
NFC: fdp: Convert I2C driver to ->probe_new()
NFC: fdp: Convert to use devres API
NFC: fdp: Add GPIO ACPI mapping table
NFC: st-nci: Get rid of platform data
NFC: st-nci: Get rid of "interesting" use of interrupt polarity
NFC: st-nci: Covert to use GPIO descriptor
NFC: st-nci: Use unified device property API meaningfully
NFC: st-nci: Add GPIO ACPI mapping table
NFC: st-nci: Get rid of code duplication in ->probe()
drivers/nfc/fdp/fdp.c | 15 +--- drivers/nfc/fdp/i2c.c | 38 ++++---- drivers/nfc/pn544/i2c.c | 3 +- drivers/nfc/st-nci/i2c.c | 164 ++++++---------------------------- drivers/nfc/st-nci/spi.c | 165 ++++++----------------------------- drivers/nfc/st21nfca/i2c.c | 62 ++++--------- include/linux/platform_data/st-nci.h | 31 ------- 7 files changed, 91 insertions(+), 387 deletions(-) delete mode 100644 include/linux/platform_data/st-nci.h
Signature · 1 line
2.11.0
PATCH v2 1/12 NFC: pn544: Switch to devm_acpi_dev_add_driver_gpios()
Switch to use managed variant of acpi_dev_add_driver_gpios() to simplify error path and fix potentially wrong assingment if ->probe() fails.
--- drivers/nfc/pn544/i2c.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nfc/pn544/i2c.c +1 -2
@@ -904,7 +904,7 @@ static int pn544_hci_i2c_probe(struct i2c_client *client, phy->i2c_dev = client;i2c_set_clientdata (client, phy); - r =acpi_dev_add_driver_gpios (ACPI_COMPANION (dev), acpi_pn544_gpios); + r =devm_acpi_dev_add_driver_gpios (dev, acpi_pn544_gpios);if (r)dev_dbg (dev,"Unable to add GPIO mapping table\n" );
@@ -958,7 +958,6 @@ static int pn544_hci_i2c_remove(struct i2c_client *client)if (phy->powered)pn544_hci_i2c_disable (phy); -acpi_dev_remove_driver_gpios (ACPI_COMPANION (&client->dev));return 0 ; }
Signature · 1 line
2.11.0
PATCH v2 2/12 NFC: st21nfca: Add GPIO ACPI mapping table
In reply to Andy ShevchenkoIn order to make GPIO ACPI library stricter prepare users of gpiod_get_index() to correctly behave when there no mapping is provided by firmware.
Here we add explicit mapping between _CRS GpioIo() resources and their names used in the driver.
--- drivers/nfc/st21nfca/i2c.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/nfc/st21nfca/i2c.c +14 -4
@@ -501,14 +501,25 @@ static struct nfc_phy_ops i2c_phy_ops = { .disable = st21nfca_hci_i2c_disable, }; +static const struct acpi_gpio_params enable_gpios = {1 ,0 , false }; + +static const struct acpi_gpio_mapping acpi_st21nfca_gpios[] = { + {"enable-gpios" , &enable_gpios,1 }, + {}, +}; +static int st21nfca_hci_i2c_acpi_request_resources (struct i2c_client *client) {struct st21nfca_i2c_phy *phy =i2c_get_clientdata (client);struct device *dev = &client->dev; +int ret; + + ret =devm_acpi_dev_add_driver_gpios (dev, acpi_st21nfca_gpios); +if (ret) +return ret;/* Get EN GPIO from ACPI */ - phy->gpiod_ena =devm_gpiod_get_index (dev,ST21NFCA_GPIO_NAME_EN ,1 , -GPIOD_OUT_LOW ); + phy->gpiod_ena =devm_gpiod_get (dev,ST21NFCA_GPIO_NAME_EN ,GPIOD_OUT_LOW );if (IS_ERR (phy->gpiod_ena)) {nfc_err (dev,"Unable to get ENABLE GPIO\n" );return PTR_ERR (phy->gpiod_ena);
@@ -523,8 +534,7 @@ static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client)struct device *dev = &client->dev;/* Get GPIO from device tree */ - phy->gpiod_ena =devm_gpiod_get_index (dev,ST21NFCA_GPIO_NAME_EN ,0 , -GPIOD_OUT_HIGH ); + phy->gpiod_ena =devm_gpiod_get (dev,ST21NFCA_GPIO_NAME_EN ,GPIOD_OUT_HIGH );if (IS_ERR (phy->gpiod_ena)) {nfc_err (dev,"Failed to request enable pin\n" );return PTR_ERR (phy->gpiod_ena);
Signature · 1 line
2.11.0
PATCH v2 3/12 NFC: st21nfca: Get rid of code duplication in ->probe()
In reply to Andy ShevchenkoSince OF and ACPI case almost the same get rid of code duplication by moving gpiod_get() calls directly to ->probe().
--- drivers/nfc/st21nfca/i2c.c | 62 ++++++++-------------------------------------- 1 file changed, 10 insertions(+), 52 deletions(-)
drivers/nfc/st21nfca/i2c.c +10 -52
@@ -61,8 +61,6 @@#define ST21NFCA_HCI_DRIVER_NAME "st21nfca_hci"#define ST21NFCA_HCI_I2C_DRIVER_NAME "st21nfca_hci_i2c" -#define ST21NFCA_GPIO_NAME_EN "enable" -struct st21nfca_i2c_phy {struct i2c_client *i2c_dev;struct nfc_hci_dev *hdev;
@@ -508,44 +506,10 @@ static const struct acpi_gpio_mapping acpi_st21nfca_gpios[] = { {}, }; -static int st21nfca_hci_i2c_acpi_request_resources (struct i2c_client *client) -{ -struct st21nfca_i2c_phy *phy =i2c_get_clientdata (client); -struct device *dev = &client->dev; -int ret; - - ret =devm_acpi_dev_add_driver_gpios (dev, acpi_st21nfca_gpios); -if (ret) -return ret; - -/* Get EN GPIO from ACPI */ - phy->gpiod_ena =devm_gpiod_get (dev,ST21NFCA_GPIO_NAME_EN ,GPIOD_OUT_LOW ); -if (IS_ERR (phy->gpiod_ena)) { -nfc_err (dev,"Unable to get ENABLE GPIO\n" ); -return PTR_ERR (phy->gpiod_ena); - } - -return 0 ; -} - -static int st21nfca_hci_i2c_of_request_resources (struct i2c_client *client) -{ -struct st21nfca_i2c_phy *phy =i2c_get_clientdata (client); -struct device *dev = &client->dev; - -/* Get GPIO from device tree */ - phy->gpiod_ena =devm_gpiod_get (dev,ST21NFCA_GPIO_NAME_EN ,GPIOD_OUT_HIGH ); -if (IS_ERR (phy->gpiod_ena)) { -nfc_err (dev,"Failed to request enable pin\n" ); -return PTR_ERR (phy->gpiod_ena); - } - -return 0 ; -} -static int st21nfca_hci_i2c_probe (struct i2c_client *client,const struct i2c_device_id *id) { +struct device *dev = &client->dev;struct st21nfca_i2c_phy *phy;int r;
@@ -572,21 +536,15 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,mutex_init (&phy->phy_lock);i2c_set_clientdata (client, phy); -if (client->dev.of_node) { - r =st21nfca_hci_i2c_of_request_resources (client); -if (r) { -nfc_err (&client->dev,"No platform data\n" ); -return r; - } - }else if (ACPI_HANDLE (&client->dev)) { - r =st21nfca_hci_i2c_acpi_request_resources (client); -if (r) { -nfc_err (&client->dev,"Cannot get ACPI data\n" ); -return r; - } - }else { -nfc_err (&client->dev,"st21nfca platform resources not available\n" ); -return -ENODEV ; + r =devm_acpi_dev_add_driver_gpios (dev, acpi_st21nfca_gpios); +if (r) +dev_dbg (dev,"Unable to add GPIO mapping table\n" ); + +/* Get EN GPIO from resource provider */ + phy->gpiod_ena =devm_gpiod_get (dev,"enable" ,GPIOD_OUT_LOW ); +if (IS_ERR (phy->gpiod_ena)) { +nfc_err (dev,"Unable to get ENABLE GPIO\n" ); +return PTR_ERR (phy->gpiod_ena); } phy->se_status.is_ese_present =
Signature · 1 line
2.11.0
PATCH v2 4/12 NFC: fdp: Convert I2C driver to ->probe_new()
In reply to Andy ShevchenkoThere is no platform code that uses i2c module table. Remove it altogether and adjust ->probe() to be ->probe_new().
--- drivers/nfc/fdp/i2c.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/nfc/fdp/i2c.c +2 -10
@@ -281,8 +281,7 @@ static void fdp_nci_i2c_read_device_properties(struct device *dev, *clock_type, *clock_freq, *fw_vsc_cfg != NULL ? "yes" : "no"); } -static int fdp_nci_i2c_probe (struct i2c_client *client, -const struct i2c_device_id *id) +static int fdp_nci_i2c_probe (struct i2c_client *client) {struct fdp_i2c_phy *phy;struct device *dev = &client->dev;
@@ -360,12 +359,6 @@ static int fdp_nci_i2c_remove(struct i2c_client *client)return 0 ; } -static struct i2c_device_id fdp_nci_i2c_id_table[] = { - {"int339a" ,0 }, - {} -}; -MODULE_DEVICE_TABLE (i2c, fdp_nci_i2c_id_table); -static const struct acpi_device_id fdp_nci_i2c_acpi_match[] = { {"INT339A" ,0 }, {}
@@ -377,8 +370,7 @@ static struct i2c_driver fdp_nci_i2c_driver = { .name = FDP_I2C_DRIVER_NAME, .acpi_match_table = ACPI_PTR(fdp_nci_i2c_acpi_match), }, - .id_table = fdp_nci_i2c_id_table, - .probe = fdp_nci_i2c_probe, + .probe_new = fdp_nci_i2c_probe, .remove = fdp_nci_i2c_remove, };module_i2c_driver (fdp_nci_i2c_driver);
Signature · 1 line
2.11.0
PATCH v2 5/12 NFC: fdp: Convert to use devres API
In reply to Andy ShevchenkoIt looks like there are two leftovers, at least one of which can leak the resource (IRQ).
Convert both places to use devm variants of functions.
--- drivers/nfc/fdp/fdp.c | 15 ++++----------- drivers/nfc/fdp/i2c.c | 10 +++++----- 2 files changed, 9 insertions(+), 16 deletions(-)
drivers/nfc/fdp/fdp.c +4 -11
@@ -750,11 +750,9 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops,u32 protocols;int r; - info =kzalloc (sizeof (struct fdp_nci_info ),GFP_KERNEL ); -if (!info) { - r = -ENOMEM ; - goto err_info_alloc; - } + info =devm_kzalloc (dev,sizeof (struct fdp_nci_info ),GFP_KERNEL ); +if (!info) +return -ENOMEM ; info->phy = phy; info->phy_ops = phy_ops;
@@ -776,8 +774,7 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, tx_tailroom);if (!ndev) {nfc_err (dev,"Cannot allocate nfc ndev\n" ); - r = -ENOMEM ; - goto err_alloc_ndev; +return -ENOMEM ; } r =nci_register_device (ndev);
@@ -793,9 +790,6 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, err_regdev:nci_free_device (ndev); -err_alloc_ndev: -kfree (info); -err_info_alloc:return r; }EXPORT_SYMBOL (fdp_nci_probe);
@@ -809,7 +803,6 @@ void fdp_nci_remove(struct nci_dev *ndev)nci_unregister_device (ndev);nci_free_device (ndev); -kfree (info); }EXPORT_SYMBOL (fdp_nci_remove);
drivers/nfc/fdp/i2c.c +5 -5
@@ -303,8 +303,7 @@ static int fdp_nci_i2c_probe(struct i2c_client *client)return -ENODEV ; } - phy =devm_kzalloc (dev,sizeof (struct fdp_i2c_phy ), -GFP_KERNEL ); + phy =devm_kzalloc (dev,sizeof (struct fdp_i2c_phy ),GFP_KERNEL );if (!phy)return -ENOMEM ;
@@ -312,9 +311,10 @@ static int fdp_nci_i2c_probe(struct i2c_client *client) phy->next_read_size =FDP_NCI_I2C_MIN_PAYLOAD ;i2c_set_clientdata (client, phy); - r =request_threaded_irq (client->irq,NULL , fdp_nci_i2c_irq_thread_fn, -IRQF_TRIGGER_RISING |IRQF_ONESHOT , -FDP_I2C_DRIVER_NAME , phy); + r =devm_request_threaded_irq (dev, client->irq, +NULL , fdp_nci_i2c_irq_thread_fn, +IRQF_TRIGGER_RISING |IRQF_ONESHOT , +FDP_I2C_DRIVER_NAME , phy);if (r <0 ) {nfc_err (&client->dev,"Unable to register IRQ handler\n" );
Signature · 1 line
2.11.0
PATCH v2 6/12 NFC: fdp: Add GPIO ACPI mapping table
In reply to Andy ShevchenkoIn order to make GPIO ACPI library stricter prepare users of gpiod_get_index() to correctly behave when there no mapping is provided by firmware.
Here we add explicit mapping between _CRS GpioIo() resources and their names used in the driver.
--- drivers/nfc/fdp/i2c.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/nfc/fdp/i2c.c +12 -4
@@ -27,7 +27,6 @@#define FDP_I2C_DRIVER_NAME "fdp_nci_i2c" -#define FDP_DP_POWER_GPIO_NAME "power"#define FDP_DP_CLOCK_TYPE_NAME "clock-type"#define FDP_DP_CLOCK_FREQ_NAME "clock-freq"#define FDP_DP_FW_VSC_CFG_NAME "fw-vsc-cfg"
@@ -281,6 +280,13 @@ static void fdp_nci_i2c_read_device_properties(struct device *dev, *clock_type, *clock_freq, *fw_vsc_cfg != NULL ? "yes" : "no"); } +static const struct acpi_gpio_params power_gpios = {0 ,0 , false }; + +static const struct acpi_gpio_mapping acpi_fdp_gpios[] = { + {"power-gpios" , &power_gpios,1 }, + {}, +}; +static int fdp_nci_i2c_probe (struct i2c_client *client) {struct fdp_i2c_phy *phy;
@@ -321,10 +327,12 @@ static int fdp_nci_i2c_probe(struct i2c_client *client)return r; } -/* Requesting the power gpio */ - phy->power_gpio =devm_gpiod_get (dev,FDP_DP_POWER_GPIO_NAME , -GPIOD_OUT_LOW ); + r =devm_acpi_dev_add_driver_gpios (dev, acpi_fdp_gpios); +if (r) +dev_dbg (dev,"Unable to add GPIO mapping table\n" ); +/* Requesting the power gpio */ + phy->power_gpio =devm_gpiod_get (dev,"power" ,GPIOD_OUT_LOW );if (IS_ERR (phy->power_gpio)) {nfc_err (dev,"Power GPIO request failed\n" );return PTR_ERR (phy->power_gpio);
Signature · 1 line
2.11.0
PATCH v2 7/12 NFC: st-nci: Get rid of platform data
In reply to Andy ShevchenkoLegacy platform data must go away. We are on the safe side here since there are no users of it in the kernel.
If anyone by any odd reason needs it the GPIO lookup tables and built-in device properties at your service.
--- drivers/nfc/st-nci/i2c.c | 43 ++---------------------------------- drivers/nfc/st-nci/spi.c | 43 ++---------------------------------- include/linux/platform_data/st-nci.h | 31 -------------------------- 3 files changed, 4 insertions(+), 113 deletions(-) delete mode 100644 include/linux/platform_data/st-nci.h
drivers/nfc/st-nci/i2c.c +2 -41
@@ -27,7 +27,6 @@#include <linux/interrupt.h> #include <linux/delay.h> #include <linux/nfc.h> -#include <linux/platform_data/st-nci.h> #include "st-nci.h"
@@ -40,6 +39,7 @@#define ST_NCI_I2C_MIN_SIZE 4/* PCB(1) + NCI Packet header(3) */ #define ST_NCI_I2C_MAX_SIZE 250/* req 4.2.1 */ +#define ST_NCI_DRIVER_NAME "st_nci"#define ST_NCI_I2C_DRIVER_NAME "st_nci_i2c"#define ST_NCI_GPIO_NAME_RESET "reset"
@@ -281,41 +281,10 @@ static int st_nci_i2c_of_request_resources(struct i2c_client *client)return 0 ; } -static int st_nci_i2c_request_resources (struct i2c_client *client) -{ -struct st_nci_nfc_platform_data *pdata; -struct st_nci_i2c_phy *phy =i2c_get_clientdata (client); -int r; - - pdata = client->dev.platform_data; -if (pdata ==NULL ) { -nfc_err (&client->dev,"No platform data\n" ); -return -EINVAL ; - } - -/* store for later use */ - phy->gpio_reset = pdata->gpio_reset; - phy->irq_polarity = pdata->irq_polarity; - - r =devm_gpio_request_one (&client->dev, - phy->gpio_reset,GPIOF_OUT_INIT_HIGH , -ST_NCI_GPIO_NAME_RESET ); -if (r) { -pr_err ("%s : reset gpio_request failed\n" , __FILE__); -return r; - } - - phy->se_status.is_ese_present = pdata->is_ese_present; - phy->se_status.is_uicc_present = pdata->is_uicc_present; - -return 0 ; -} -static int st_nci_i2c_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct st_nci_i2c_phy *phy; -struct st_nci_nfc_platform_data *pdata;int r;dev_dbg (&client->dev,"%s\n" , __func__);
@@ -335,20 +304,12 @@ static int st_nci_i2c_probe(struct i2c_client *client,i2c_set_clientdata (client, phy); - pdata = client->dev.platform_data; -if (!pdata && client->dev.of_node) { +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 (pdata) { - r =st_nci_i2c_request_resources (client); -if (r) { -nfc_err (&client->dev, -"Cannot get platform resources\n" ); -return r; - } }else if (ACPI_HANDLE (&client->dev)) { r =st_nci_i2c_acpi_request_resources (client);if (r) {
drivers/nfc/st-nci/spi.c +2 -41
75 lines not on this page · raw message
include/linux/platform_data/st-nci.h deleted +0 -31
@@ -1,31 +0,0 @@ -/* -* Driver include for ST NCI NFC chip family. -* -* 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/>. -*/ - -#ifndef _ST_NCI_H_ -#define _ST_NCI_H_ - -#define ST_NCI_DRIVER_NAME "st_nci" - -struct st_nci_nfc_platform_data { -unsigned int gpio_reset; -unsigned int irq_polarity; -bool is_ese_present; -bool is_uicc_present; -}; - -#endif /* _ST_NCI_H_ */
Signature · 1 line
2.11.0
PATCH v2 8/12 NFC: st-nci: Get rid of "interesting" use of interrupt polarity
In reply to Andy ShevchenkoI2C and SPI frameworks followed by IRQ framework do set interrupt polarity correctly if it's properly specified in firmware (ACPI or DT).
Get rid of the redundant trick when requesting interrupt.
--- drivers/nfc/st-nci/i2c.c | 8 +------- drivers/nfc/st-nci/spi.c | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-)
drivers/nfc/st-nci/i2c.c +1 -7
@@ -21,7 +21,6 @@#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>
@@ -51,7 +50,6 @@ struct st_nci_i2c_phy {bool irq_active;unsigned int gpio_reset; -unsigned int irq_polarity;struct st_nci_se_status se_status; };
@@ -225,8 +223,6 @@ static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) 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;
@@ -271,8 +267,6 @@ static int st_nci_i2c_of_request_resources(struct i2c_client *client) } 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 =
@@ -333,7 +327,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" );
drivers/nfc/st-nci/spi.c +1 -7
@@ -21,7 +21,6 @@#include <linux/spi/spi.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>
@@ -52,7 +51,6 @@ struct st_nci_spi_phy {bool irq_active;unsigned int gpio_reset; -unsigned int irq_polarity;struct st_nci_se_status se_status; };
@@ -240,8 +238,6 @@ static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) phy->gpio_reset =desc_to_gpio (gpiod_reset); - phy->irq_polarity =irq_get_trigger_type (spi_dev->irq); - phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false;
@@ -286,8 +282,6 @@ static int st_nci_spi_of_request_resources(struct spi_device *dev) } phy->gpio_reset = gpio; - phy->irq_polarity =irq_get_trigger_type (dev->irq); - phy->se_status.is_ese_present =of_property_read_bool (pp,"ese-present" ); phy->se_status.is_uicc_present =
@@ -349,7 +343,7 @@ static int st_nci_spi_probe(struct spi_device *dev) phy->irq_active = true; r =devm_request_threaded_irq (&dev->dev, dev->irq,NULL , st_nci_irq_thread_fn, - phy->irq_polarity |IRQF_ONESHOT , +IRQF_ONESHOT ,ST_NCI_SPI_DRIVER_NAME , phy);if (r <0 )nfc_err (&dev->dev,"Unable to register IRQ handler\n" );
Signature · 1 line
2.11.0
PATCH v2 9/12 NFC: st-nci: Covert to use GPIO descriptor
In reply to Andy ShevchenkoSince we got rid of platform data, the driver may use GPIO descriptor directly.
Looking deeply to the use of the GPIO pin it looks like it should be a GPIO based reset control rather than custom GPIO handling. But this is out of scope of the change.
--- drivers/nfc/st-nci/i2c.c | 38 +++++++++++--------------------------- drivers/nfc/st-nci/spi.c | 40 ++++++++++++---------------------------- 2 files changed, 23 insertions(+), 55 deletions(-)
drivers/nfc/st-nci/i2c.c +11 -27
@@ -19,13 +19,12 @@#include <linux/module.h> #include <linux/i2c.h> -#include <linux/gpio.h> #include <linux/gpio/consumer.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"
@@ -49,7 +48,7 @@ struct st_nci_i2c_phy {bool irq_active; -unsigned int gpio_reset; +struct gpio_desc *gpiod_reset;struct st_nci_se_status se_status; };
@@ -58,9 +57,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 ) {
@@ -209,20 +208,16 @@ static struct nfc_phy_ops i2c_phy_ops = {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)) { + phy->gpiod_reset =devm_gpiod_get_index (dev,ST_NCI_GPIO_NAME_RESET ,1 ,GPIOD_OUT_HIGH ); +if (IS_ERR (phy->gpiod_reset)) {nfc_err (dev,"Unable to get RESET GPIO\n" );return -ENODEV ; } - phy->gpio_reset =desc_to_gpio (gpiod_reset); - phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false;
@@ -242,30 +237,19 @@ static int st_nci_i2c_acpi_request_resources(struct i2c_client *client)static int st_nci_i2c_of_request_resources (struct i2c_client *client) {struct st_nci_i2c_phy *phy =i2c_get_clientdata (client); +struct device *dev = &client->dev;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->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 PTR_ERR (phy->gpiod_reset); } - phy->gpio_reset = gpio; phy->se_status.is_ese_present =of_property_read_bool (pp,"ese-present" );
drivers/nfc/st-nci/spi.c +12 -28
@@ -19,13 +19,12 @@#include <linux/module.h> #include <linux/spi/spi.h> -#include <linux/gpio.h> #include <linux/gpio/consumer.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 <net/nfc/nci.h> #include "st-nci.h"
@@ -50,7 +49,7 @@ struct st_nci_spi_phy {bool irq_active; -unsigned int gpio_reset; +struct gpio_desc *gpiod_reset;struct st_nci_se_status se_status; };
@@ -59,9 +58,9 @@ static int st_nci_spi_enable(void *phy_id) {struct st_nci_spi_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 ) {
@@ -224,20 +223,16 @@ static struct nfc_phy_ops spi_phy_ops = {static int st_nci_spi_acpi_request_resources (struct spi_device *spi_dev) {struct st_nci_spi_phy *phy =spi_get_drvdata (spi_dev); -struct gpio_desc *gpiod_reset;struct device *dev = &spi_dev->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)) { + phy->gpiod_reset =devm_gpiod_get_index (dev,ST_NCI_GPIO_NAME_RESET ,1 ,GPIOD_OUT_HIGH ); +if (IS_ERR (phy->gpiod_reset)) {nfc_err (dev,"Unable to get RESET GPIO\n" ); -return -ENODEV ; +return PTR_ERR (phy->gpiod_reset); } - phy->gpio_reset =desc_to_gpio (gpiod_reset); - phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false;
@@ -257,30 +252,19 @@ static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev)static int st_nci_spi_of_request_resources (struct spi_device *dev) {struct st_nci_spi_phy *phy =spi_get_drvdata (dev); +struct device *dev = &dev->dev;struct device_node *pp; -int gpio; -int r; pp = dev->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 (&dev->dev, -"Failed to retrieve reset-gpios from device tree\n" ); -return gpio; - } - -/* GPIO request and configuration */ - r =devm_gpio_request_one (&dev->dev, gpio, -GPIOF_OUT_INIT_HIGH ,ST_NCI_GPIO_NAME_RESET ); -if (r) { -nfc_err (&dev->dev,"Failed to request reset pin\n" ); -return r; + 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 PTR_ERR (phy->gpiod_reset); } - phy->gpio_reset = gpio; phy->se_status.is_ese_present =of_property_read_bool (pp,"ese-present" );
Signature · 1 line
2.11.0
PATCH v2 10/12 NFC: st-nci: Use unified device property API meaningfully
In reply to Andy ShevchenkoUse unified device property API in meaningful way.
--- drivers/nfc/st-nci/i2c.c | 30 ++++++------------------------ drivers/nfc/st-nci/spi.c | 29 +++++------------------------ 2 files changed, 11 insertions(+), 48 deletions(-)
drivers/nfc/st-nci/i2c.c +6 -24
@@ -209,7 +209,6 @@ static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) {struct st_nci_i2c_phy *phy =i2c_get_clientdata (client);struct device *dev = &client->dev; -u8 tmp;/* Get RESET GPIO from ACPI */ phy->gpiod_reset =devm_gpiod_get_index (dev,ST_NCI_GPIO_NAME_RESET ,1 ,GPIOD_OUT_HIGH );
@@ -218,19 +217,6 @@ static int st_nci_i2c_acpi_request_resources(struct i2c_client *client)return -ENODEV ; } - 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 ; }
@@ -238,11 +224,6 @@ static int st_nci_i2c_of_request_resources(struct i2c_client *client) {struct st_nci_i2c_phy *phy =i2c_get_clientdata (client);struct device *dev = &client->dev; -struct device_node *pp; - - pp = client->dev.of_node; -if (!pp) -return -ENODEV ;/* Get GPIO from device tree */ phy->gpiod_reset =devm_gpiod_get (dev,"reset" ,GPIOD_OUT_HIGH );
@@ -251,17 +232,13 @@ static int st_nci_i2c_of_request_resources(struct i2c_client *client)return PTR_ERR (phy->gpiod_reset); } - 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" ); -return 0 ; }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;
@@ -300,6 +277,11 @@ static int st_nci_i2c_probe(struct i2c_client *client,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);
drivers/nfc/st-nci/spi.c +5 -24
@@ -224,7 +224,6 @@ static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) {struct st_nci_spi_phy *phy =spi_get_drvdata (spi_dev);struct device *dev = &spi_dev->dev; -u8 tmp;/* Get RESET GPIO from ACPI */ phy->gpiod_reset =devm_gpiod_get_index (dev,ST_NCI_GPIO_NAME_RESET ,1 ,GPIOD_OUT_HIGH );
@@ -233,19 +232,6 @@ static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev)return PTR_ERR (phy->gpiod_reset); } - 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); - tmp = phy->se_status.is_ese_present; - } - -if (device_property_present (dev,"uicc-present" )) { -device_property_read_u8 (dev,"uicc-present" , &tmp); - tmp = phy->se_status.is_uicc_present; - } -return 0 ; }
@@ -253,11 +239,6 @@ static int st_nci_spi_of_request_resources(struct spi_device *dev) {struct st_nci_spi_phy *phy =spi_get_drvdata (dev);struct device *dev = &dev->dev; -struct device_node *pp; - - pp = dev->dev.of_node; -if (!pp) -return -ENODEV ;/* Get GPIO from device tree */ phy->gpiod_reset =devm_gpiod_get (dev,"reset" ,GPIOD_OUT_HIGH );
@@ -266,11 +247,6 @@ static int st_nci_spi_of_request_resources(struct spi_device *dev)return PTR_ERR (phy->gpiod_reset); } - 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" ); -return 0 ; }
@@ -316,6 +292,11 @@ static int st_nci_spi_probe(struct spi_device *dev)return -ENODEV ; } + phy->se_status.is_ese_present = +device_property_read_bool (&dev->dev,"ese-present" ); + phy->se_status.is_uicc_present = +device_property_read_bool (&dev->dev,"uicc-present" ); + r =ndlc_probe (phy, &spi_phy_ops, &dev->dev,ST_NCI_FRAME_HEADROOM ,ST_NCI_FRAME_TAILROOM , &phy->ndlc, &phy->se_status);
Signature · 1 line
2.11.0
PATCH v2 11/12 NFC: st-nci: Add GPIO ACPI mapping table
In reply to Andy ShevchenkoIn order to make GPIO ACPI library stricter prepare users of gpiod_get_index() to correctly behave when there no mapping is provided by firmware.
Here we add explicit mapping between _CRS GpioIo() resources and their names used in the driver.
--- drivers/nfc/st-nci/i2c.c | 16 +++++++++++++--- drivers/nfc/st-nci/spi.c | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-)
drivers/nfc/st-nci/i2c.c +13 -3
@@ -40,8 +40,6 @@#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;
@@ -205,13 +203,25 @@ static struct nfc_phy_ops i2c_phy_ops = { .disable = st_nci_i2c_disable, }; +static const struct acpi_gpio_params reset_gpios = {1 ,0 , false }; + +static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = { + {"reset-gpios" , &reset_gpios,1 }, + {}, +}; +static int st_nci_i2c_acpi_request_resources (struct i2c_client *client) {struct st_nci_i2c_phy *phy =i2c_get_clientdata (client);struct device *dev = &client->dev; +int r; + + r =devm_acpi_dev_add_driver_gpios (dev, acpi_st_nci_gpios); +if (r) +return r;/* Get RESET GPIO from ACPI */ - phy->gpiod_reset =devm_gpiod_get_index (dev,ST_NCI_GPIO_NAME_RESET ,1 ,GPIOD_OUT_HIGH ); + 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 ;
drivers/nfc/st-nci/spi.c +13 -3
@@ -41,8 +41,6 @@#define ST_NCI_DRIVER_NAME "st_nci"#define ST_NCI_SPI_DRIVER_NAME "st_nci_spi" -#define ST_NCI_GPIO_NAME_RESET "reset" -struct st_nci_spi_phy {struct spi_device *spi_dev;struct llt_ndlc *ndlc;
@@ -220,13 +218,25 @@ static struct nfc_phy_ops spi_phy_ops = { .disable = st_nci_spi_disable, }; +static const struct acpi_gpio_params reset_gpios = {1 ,0 , false }; + +static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = { + {"reset-gpios" , &reset_gpios,1 }, + {}, +}; +static int st_nci_spi_acpi_request_resources (struct spi_device *spi_dev) {struct st_nci_spi_phy *phy =spi_get_drvdata (spi_dev);struct device *dev = &spi_dev->dev; +int r; + + r =devm_acpi_dev_add_driver_gpios (dev, acpi_st_nci_gpios); +if (r) +return r;/* Get RESET GPIO from ACPI */ - phy->gpiod_reset =devm_gpiod_get_index (dev,ST_NCI_GPIO_NAME_RESET ,1 ,GPIOD_OUT_HIGH ); + 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 PTR_ERR (phy->gpiod_reset);
Signature · 1 line
2.11.0
PATCH v2 12/12 NFC: st-nci: Get rid of code duplication in ->probe()
In reply to Andy ShevchenkoSince OF and ACPI case almost the same get rid of code duplication by moving gpiod_get() calls directly to ->probe().
--- drivers/nfc/st-nci/i2c.c | 61 +++++++--------------------------------------- drivers/nfc/st-nci/spi.c | 63 ++++++++---------------------------------------- 2 files changed, 19 insertions(+), 105 deletions(-)
drivers/nfc/st-nci/i2c.c +9 -52
@@ -210,41 +210,6 @@ static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = { {}, }; -static int st_nci_i2c_acpi_request_resources (struct i2c_client *client) -{ -struct st_nci_i2c_phy *phy =i2c_get_clientdata (client); -struct device *dev = &client->dev; -int r; - - r =devm_acpi_dev_add_driver_gpios (dev, acpi_st_nci_gpios); -if (r) -return r; - -/* Get RESET GPIO from ACPI */ - 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 ; - } - -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 *dev = &client->dev; - -/* Get GPIO from device tree */ - 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 PTR_ERR (phy->gpiod_reset); - } - -return 0 ; -} -static int st_nci_i2c_probe (struct i2c_client *client,const struct i2c_device_id *id) {
@@ -260,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 ;
@@ -269,21 +233,14 @@ 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 ; }
drivers/nfc/st-nci/spi.c +10 -53
81 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 9 lines · Andy Shevchenko
This clean up series to NFC drivers that are using GPIOs on ACPI enabled
platforms. Since GPIO ACPI library goes stricter about requesting resources we need to amend drivers for that. Here we are for NFC subsystem.While doing above, get rid of legacy and unused platform data as well as
some artificial IDs.
Samuel, anything to comment?
Quoted 30 lines
Changelog v2:
- add patches 1,4-12Andy Shevchenko (12):
NFC: pn544: Switch todevm_acpi_dev_add_driver_gpios()
NFC: st21nfca: Add GPIO ACPI mapping table
NFC: st21nfca: Get rid of code duplication in ->probe()
NFC: fdp: Convert I2C driver to ->probe_new()
NFC: fdp: Convert to use devres API
NFC: fdp: Add GPIO ACPI mapping table
NFC: st-nci: Get rid of platform data
NFC: st-nci: Get rid of "interesting" use of interrupt polarity
NFC: st-nci: Covert to use GPIO descriptor
NFC: st-nci: Use unified device property API meaningfully
NFC: st-nci: Add GPIO ACPI mapping table
NFC: st-nci: Get rid of code duplication in ->probe()drivers/nfc/fdp/fdp.c | 15 +--- drivers/nfc/fdp/i2c.c | 38 ++++---- drivers/nfc/pn544/i2c.c | 3 +- drivers/nfc/st-nci/i2c.c | 164 ++++++------------------
----------
drivers/nfc/st-nci/spi.c | 165 ++++++------------------
-----------
drivers/nfc/st21nfca/i2c.c | 62 ++++---------include/linux/platform_data/st-nci.h| 31 -------7 files changed, 91 insertions(+), 387 deletions(-)delete mode 100644
include/linux/platform_data/st-nci.h
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Andy,
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
This clean up series to NFC drivers that are using GPIOs on ACPI enabled
platforms. Since GPIO ACPI library goes stricter about requesting resources we need to amend drivers for that. Here we are for NFC subsystem.
Quoted 5 lines
Quoted 3 lines
While doing above, get rid of legacy and unused platform data as well as
some artificial IDs.Samuel, anything to comment?
I will get to my pending NFC patches during the week.
Cheers,
Samuel.
Quoted 5 lines · Samuel Ortiz
Quoted 1 line · Andy Shevchenko
Samuel, anything to comment?
I will get to my pending NFC patches during the week.
Thanks!
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Hi Andy,
Quoted 5 lines · Andy Shevchenko
Andy Shevchenko (12):
NFC: pn544: Switch todevm_acpi_dev_add_driver_gpios()
NFC: st21nfca: Add GPIO ACPI mapping table
NFC: st21nfca: Get rid of code duplication in ->probe()
NFC: fdp: Convert I2C driver to ->probe_new()
Quoted 8 lines
NFC: fdp: Convert to use devres API
NFC: fdp: Add GPIO ACPI mapping table
NFC: st-nci: Get rid of platform data
NFC: st-nci: Get rid of "interesting" use of interrupt polarity
NFC: st-nci: Covert to use GPIO descriptor
NFC: st-nci: Use unified device property API meaningfully
NFC: st-nci: Add GPIO ACPI mapping table
NFC: st-nci: Get rid of code duplication in ->probe()
After fixing a couple of nitpicks, all patches applied now. I'm fine with getting rid of the platform data, let's see if out of tree users (especially for the ST driver) complain. Also, I'd appreciate if you could cc linux-nfc to your submissions.
Cheers,
Samuel.