NFC: clean up for ACPI GPIO usage
v3 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 v3:
- incorporate Samuel's fixes
- fix the bug kbuild bot complains about
- add MAINTAINERS patch
Changelog v2:
- add patches 1,4-12
Andy Shevchenko (13):
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 properties API meaningfully
NFC: st-nci: Add GPIO ACPI mapping table
NFC: st-nci: Get rid of code duplication in ->probe()
MAINTAINERS: Remove non-existing NFC platform data files
MAINTAINERS | 3 - 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 | 162 ++++++---------------------------- drivers/nfc/st21nfca/i2c.c | 62 ++++--------- include/linux/platform_data/st-nci.h | 31 ------- 8 files changed, 90 insertions(+), 388 deletions(-) delete mode 100644 include/linux/platform_data/st-nci.h
Signature · 1 line
2.11.0
PATCH v3 1/13 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 assignment 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 v3 2/13 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 v3 3/13 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 v3 4/13 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 v3 5/13 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 managed variants of the 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
@@ -749,11 +749,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;
@@ -775,8 +773,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);
@@ -792,9 +789,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);
@@ -808,7 +802,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 v3 6/13 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 v3 7/13 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.
--- MAINTAINERS | 1 - drivers/nfc/st-nci/i2c.c | 43 ++---------------------------------- drivers/nfc/st-nci/spi.c | 43 ++---------------------------------- include/linux/platform_data/st-nci.h | 31 -------------------------- 4 files changed, 4 insertions(+), 114 deletions(-) delete mode 100644 include/linux/platform_data/st-nci.h
MAINTAINERS +0 -1
@@ -9177,7 +9177,6 @@ F: include/linux/platform_data/nfcmrvl.h F: include/linux/platform_data/nxp-nci.h F: include/linux/platform_data/pn544.h F: include/linux/platform_data/st21nfca.h -F: include/linux/platform_data/st-nci.h F: Documentation/devicetree/bindings/net/nfc/ NFS, SUNRPC, AND LOCKD CLIENTS
drivers/nfc/st-nci/i2c.c +2 -41
76 lines not on this page · raw message
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 v3 8/13 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 v3 9/13 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 | 39 ++++++++++++--------------------------- drivers/nfc/st-nci/spi.c | 47 ++++++++++++++++------------------------------- 2 files changed, 28 insertions(+), 58 deletions(-)
drivers/nfc/st-nci/i2c.c +12 -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,17 @@ 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 +238,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 +16 -31
98 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v3 10/13 NFC: st-nci: Use unified device properties API meaningfully
In reply to Andy ShevchenkoUse unified device properties 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,
@@ -219,19 +218,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 ; }
@@ -239,11 +225,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 );
@@ -252,17 +233,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;
@@ -301,6 +278,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,
@@ -234,19 +233,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 ; }
@@ -254,11 +240,6 @@ static int st_nci_spi_of_request_resources(struct spi_device *spi) {struct st_nci_spi_phy *phy =spi_get_drvdata (spi);struct device *dev = &spi->dev; -struct device_node *pp; - - pp = spi->dev.of_node; -if (!pp) -return -ENODEV ;/* Get GPIO from device tree */ phy->gpiod_reset =devm_gpiod_get (dev,"reset" ,GPIOD_OUT_HIGH );
@@ -267,11 +248,6 @@ static int st_nci_spi_of_request_resources(struct spi_device *spi)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 ; }
@@ -317,6 +293,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 v3 11/13 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 | 17 +++++++++++++---- drivers/nfc/st-nci/spi.c | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-)
drivers/nfc/st-nci/i2c.c +13 -4
@@ -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,14 +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 -4
@@ -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,14 +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 v3 12/13 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 | 60 +++++++---------------------------------------- 2 files changed, 18 insertions(+), 103 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 +9 -51
72 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v3 13/13 MAINTAINERS: Remove non-existing NFC platform data files
In reply to Andy ShevchenkoThere are no longer platform data files for NFC drivers. Remove it from MAINTAINERS data base.
--- MAINTAINERS | 2 -- 1 file changed, 2 deletions(-)
MAINTAINERS +0 -2
@@ -9175,8 +9175,6 @@ F: include/uapi/linux/nfc.h F: drivers/nfc/ F: include/linux/platform_data/nfcmrvl.h F: include/linux/platform_data/nxp-nci.h -F: include/linux/platform_data/pn544.h -F: include/linux/platform_data/st21nfca.h F: Documentation/devicetree/bindings/net/nfc/ NFS, SUNRPC, AND LOCKD CLIENTS
Signature · 1 line
2.11.0
Hi Andy,
Quoted 16 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.
Changelog v3:
- incorporate Samuel's fixes
- fix the bug kbuild bot complains about
- addMAINTAINERSpatchChangelog v2:
- add patches 1,4-12
Quoted 14 lines
Andy Shevchenko (13):
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 properties API meaningfully
NFC: st-nci: Add GPIO ACPI mapping table
NFC: st-nci: Get rid of code duplication in ->probe()
MAINTAINERS: Remove non-existing NFC platform data files
All patches applied, thanks.
Cheers,
Samuel.