NFC: st21nfca: Fix obvious typo when check error code
PATCH 1/6 NFC: st21nfca: Fix obvious typo when check error code
We return -ENODEV if ACPI provides a GPIO resource. Looks really wrong. If it has even been tested?
--- drivers/nfc/st21nfca/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/nfc/st21nfca/i2c.c +2 -2
@@ -514,9 +514,9 @@ static int st21nfca_hci_i2c_acpi_request_resources(struct i2c_client *client)/* Get EN GPIO from ACPI */ gpiod_ena =devm_gpiod_get_index (dev,ST21NFCA_GPIO_NAME_EN ,1 ,GPIOD_OUT_LOW ); -if (!IS_ERR (gpiod_ena)) { +if (IS_ERR (gpiod_ena)) {nfc_err (dev,"Unable to get ENABLE GPIO\n" ); -return -ENODEV ; +return PTR_ERR (gpiod_ena); } phy->gpio_ena =desc_to_gpio (gpiod_ena);
Signature · 1 line
2.11.0
PATCH 2/6 NFC: st21nfca: Fix typo in copy pasted macro
Seems this driver has never been even compile tested.
Fix obvious typo in macro to make it defined.
--- drivers/nfc/st21nfca/i2c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/nfc/st21nfca/i2c.c +3 -3
@@ -286,7 +286,7 @@ static int check_crc(u8 *buf, int buflen) crc = ~crc;if (buf[buflen -2 ] != (crc &0xff ) || buf[buflen -1 ] != (crc >>8 )) { -pr_err (ST21NFCA_HCI_DRIVER_NAME +pr_err (ST21NFCA_HCI_I2C_DRIVER_NAME ": CRC error 0x%x != 0x%x 0x%x\n" , crc, buf[buflen -1 ], buf[buflen -2 ]);
@@ -672,7 +672,7 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client, r =devm_request_threaded_irq (&client->dev, client->irq,NULL , st21nfca_hci_irq_thread_fn, phy->irq_polarity |IRQF_ONESHOT , -ST21NFCA_HCI_DRIVER_NAME , phy); +ST21NFCA_HCI_I2C_DRIVER_NAME , phy);if (r <0 ) {nfc_err (&client->dev,"Unable to register IRQ handler\n" );return r;
@@ -701,7 +701,7 @@ static int st21nfca_hci_i2c_remove(struct i2c_client *client) }static struct i2c_device_id st21nfca_hci_i2c_id_table[] = { - {ST21NFCA_HCI_DRIVER_NAME ,0 }, + {ST21NFCA_HCI_I2C_DRIVER_NAME ,0 }, {} };MODULE_DEVICE_TABLE (i2c, st21nfca_hci_i2c_id_table);
Signature · 1 line
2.11.0
Re: [PATCH v1 2/6] NFC: st21nfca: Fix typo in copy pasted macro
Quoted 3 lines · Andy Shevchenko
Seems this driver has never been even compile tested.
Fix obvious typo in macro to make it defined.
Ah, now I got it. It's defined in removed platform data file :-(.
I will fix this in v2.
Quoted 43 lines
Signed-off-by Andy Shevchenko <[email protected]>---
drivers/nfc/st21nfca/i2c.c | 6 +++---1 file changed, 3 insertions(+), 3 deletions(-)drivers/nfc/st21nfca/i2c.c +0
-0@@ -286,7 +286,7 @@ static int check_crc(u8 *buf, int buflen) crc = ~crc;
if (buf[buflen - 2] != (crc &0xff) || buf[buflen - 1] != (crc >> 8)) {drivers/nfc/st21nfca/i2c.c +1
-1- pr_err(ST21NFCA_HCI_DRIVER_NAME + pr_err(ST21NFCA_HCI_I2C_DRIVER_NAME": CRC error 0x%x != 0x%x 0x%x\n", crc, buf[buflen - 1],
buf[buflen - 2]);drivers/nfc/st21nfca/i2c.c +1
-1@@ -672,7 +672,7 @@ static int st21nfca_hci_i2c_probe(structi2c_client *client, r = devm_request_threaded_irq(&client->dev, client->irq,NULL , st21nfca_hci_irq_thread_fn, phy->irq_polarity | IRQF_ONESHOT, -ST21NFCA_HCI_DRIVER_NAME , phy); +ST21NFCA_HCI_I2C_DRIVER_NAME , phy); if (r < 0) {
nfc_err(&client->dev, "Unable to register IRQ handler\n");
return r;drivers/nfc/st21nfca/i2c.c +0
-0@@ -701,7 +701,7 @@ static int st21nfca_hci_i2c_remove(struct i2c_client *client) }
static structi2c_device_idst21nfca_hci_i2c_id_table[] = {drivers/nfc/st21nfca/i2c.c +1
-1- {ST21NFCA_HCI_DRIVER_NAME, 0}, + {ST21NFCA_HCI_I2C_DRIVER_NAME, 0},{}
};
MODULE_DEVICE_TABLE(i2c,st21nfca_hci_i2c_id_table);
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
PATCH 3/6 NFC: st21nfca: 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/st21nfca/i2c.c | 45 ++-------------------------------- include/linux/platform_data/st21nfca.h | 33 ------------------------- 2 files changed, 2 insertions(+), 76 deletions(-) delete mode 100644 include/linux/platform_data/st21nfca.h
drivers/nfc/st21nfca/i2c.c +2 -43
@@ -20,7 +20,6 @@#include <linux/crc-ccitt.h> #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>
@@ -30,7 +29,7 @@#include <linux/delay.h> #include <linux/nfc.h> #include <linux/firmware.h> -#include <linux/platform_data/st21nfca.h> +#include <asm/unaligned.h> #include <net/nfc/hci.h>
@@ -577,43 +576,10 @@ static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client)return 0 ; } -static int st21nfca_hci_i2c_request_resources (struct i2c_client *client) -{ -struct st21nfca_nfc_platform_data *pdata; -struct st21nfca_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_ena = pdata->gpio_ena; - phy->irq_polarity = pdata->irq_polarity; - -if (phy->gpio_ena >0 ) { - r =devm_gpio_request_one (&client->dev, phy->gpio_ena, -GPIOF_OUT_INIT_HIGH , -ST21NFCA_GPIO_NAME_EN ); -if (r) { -pr_err ("%s : ena 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 st21nfca_hci_i2c_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct st21nfca_i2c_phy *phy; -struct st21nfca_nfc_platform_data *pdata;int r;dev_dbg (&client->dev,"%s\n" , __func__);
@@ -639,19 +605,12 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,mutex_init (&phy->phy_lock);i2c_set_clientdata (client, phy); - pdata = client->dev.platform_data; -if (!pdata && client->dev.of_node) { +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 (pdata) { - r =st21nfca_hci_i2c_request_resources (client); -if (r) { -nfc_err (&client->dev,"Cannot get platform resources\n" ); -return r; - } }else if (ACPI_HANDLE (&client->dev)) { r =st21nfca_hci_i2c_acpi_request_resources (client);if (r) {
include/linux/platform_data/st21nfca.h deleted +0 -33
@@ -1,33 +0,0 @@ -/* -* Driver include for the ST21NFCA NFC chip. -* -* Copyright (C) 2014 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 _ST21NFCA_HCI_H_ -#define _ST21NFCA_HCI_H_ - -#include <linux/i2c.h> - -#define ST21NFCA_HCI_DRIVER_NAME "st21nfca_hci" - -struct st21nfca_nfc_platform_data { -unsigned int gpio_ena; -unsigned int irq_polarity; -bool is_ese_present; -bool is_uicc_present; -}; - -#endif /* _ST21NFCA_HCI_H_ */
Signature · 1 line
2.11.0
PATCH 4/6 NFC: st21nfca: Get rid of "interesting" use of interrupt polarity
In reply to Andy ShevchenkoI2C framework followed by IRQ framework does 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/st21nfca/i2c.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/nfc/st21nfca/i2c.c +1 -6
@@ -68,7 +68,6 @@ struct st21nfca_i2c_phy {struct nfc_hci_dev *hdev;unsigned int gpio_ena; -unsigned int irq_polarity;struct st21nfca_se_status se_status;
@@ -520,8 +519,6 @@ static int st21nfca_hci_i2c_acpi_request_resources(struct i2c_client *client) phy->gpio_ena =desc_to_gpio (gpiod_ena); - phy->irq_polarity =irq_get_trigger_type (client->irq); - phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false;
@@ -566,8 +563,6 @@ static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client) phy->gpio_ena = 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 =
@@ -630,7 +625,7 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client, r =devm_request_threaded_irq (&client->dev, client->irq,NULL , st21nfca_hci_irq_thread_fn, - phy->irq_polarity |IRQF_ONESHOT , +IRQF_ONESHOT ,ST21NFCA_HCI_I2C_DRIVER_NAME , phy);if (r <0 ) {nfc_err (&client->dev,"Unable to register IRQ handler\n" );
Signature · 1 line
2.11.0
PATCH 5/6 NFC: st21nfca: 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 fixed voltage regulator rather than custom GPIO handling. But this is out of scope of the change.
--- drivers/nfc/st21nfca/i2c.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-)
drivers/nfc/st21nfca/i2c.c +13 -27
@@ -67,8 +67,7 @@ struct st21nfca_i2c_phy {struct i2c_client *i2c_dev;struct nfc_hci_dev *hdev; -unsigned int gpio_ena; - +struct gpio_desc *gpiod_ena;struct st21nfca_se_status se_status;struct sk_buff *pending_skb;
@@ -149,7 +148,7 @@ static int st21nfca_hci_i2c_enable(void *phy_id) {struct st21nfca_i2c_phy *phy = phy_id; -gpio_set_value (phy->gpio_ena,1 ); +gpiod_set_value (phy->gpiod_ena,1 ); phy->powered =1 ; phy->run_mode =ST21NFCA_HCI_MODE ;
@@ -162,7 +161,7 @@ static void st21nfca_hci_i2c_disable(void *phy_id) {struct st21nfca_i2c_phy *phy = phy_id; -gpio_set_value (phy->gpio_ena,0 ); +gpiod_set_value (phy->gpiod_ena,0 ); phy->powered =0 ; }
@@ -505,20 +504,17 @@ static struct nfc_phy_ops i2c_phy_ops = {static int st21nfca_hci_i2c_acpi_request_resources (struct i2c_client *client) {struct st21nfca_i2c_phy *phy =i2c_get_clientdata (client); -struct gpio_desc *gpiod_ena;struct device *dev = &client->dev;u8 tmp;/* Get EN GPIO from ACPI */ - gpiod_ena =devm_gpiod_get_index (dev,ST21NFCA_GPIO_NAME_EN ,1 , -GPIOD_OUT_LOW ); -if (IS_ERR (gpiod_ena)) { + phy->gpiod_ena =devm_gpiod_get_index (dev,ST21NFCA_GPIO_NAME_EN ,1 , +GPIOD_OUT_LOW ); +if (IS_ERR (phy->gpiod_ena)) {nfc_err (dev,"Unable to get ENABLE GPIO\n" ); -return PTR_ERR (gpiod_ena); +return PTR_ERR (phy->gpiod_ena); } - phy->gpio_ena =desc_to_gpio (gpiod_ena); - phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false;
@@ -538,31 +534,21 @@ static int st21nfca_hci_i2c_acpi_request_resources(struct i2c_client *client)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;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,"enable-gpios" ,0 ); -if (gpio <0 ) { -nfc_err (&client->dev,"Failed to retrieve enable-gpios from device tree\n" ); -return gpio; + phy->gpiod_ena =devm_gpiod_get_index (dev,ST21NFCA_GPIO_NAME_EN ,0 , +GPIOD_OUT_HIGH ); +if (IS_ERR (phy->gpiod_ena)) { +nfc_err (dev,"Failed to request enable pin\n" ); +return PTR_ERR (phy->gpiod_ena); } -/* GPIO request and configuration */ - r =devm_gpio_request_one (&client->dev, gpio,GPIOF_OUT_INIT_HIGH , -ST21NFCA_GPIO_NAME_EN ); -if (r) { -nfc_err (&client->dev,"Failed to request enable pin\n" ); -return r; - } - - phy->gpio_ena = gpio; - phy->se_status.is_ese_present =of_property_read_bool (pp,"ese-present" ); phy->se_status.is_uicc_present =
Signature · 1 line
2.11.0
PATCH 6/6 NFC: st21nfca: Use unified device property API meaningfully
In reply to Andy ShevchenkoAnother place in the code that unveils non-tested at all ACPI case.
Use unified device property API in meaningful way.
--- drivers/nfc/st21nfca/i2c.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-)
drivers/nfc/st21nfca/i2c.c +5 -24
@@ -505,7 +505,6 @@ 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; -u8 tmp;/* Get EN GPIO from ACPI */ phy->gpiod_ena = devm_gpiod_get_index(dev, ST21NFCA_GPIO_NAME_EN, 1,
@@ -515,19 +514,6 @@ static int st21nfca_hci_i2c_acpi_request_resources(struct i2c_client *client)return PTR_ERR (phy->gpiod_ena); } - 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 ; }
@@ -535,11 +521,6 @@ 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; -struct device_node *pp; - - pp = client->dev.of_node; -if (!pp) -return -ENODEV ;/* Get GPIO from device tree */ phy->gpiod_ena = devm_gpiod_get_index(dev, ST21NFCA_GPIO_NAME_EN, 0,
@@ -549,11 +530,6 @@ static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client)return PTR_ERR (phy->gpiod_ena); } - 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 ; }
@@ -603,6 +579,11 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,return -ENODEV ; } + phy->se_status.is_ese_present = +device_property_read_bool (&client->dev,"ese-present" ); + phy->se_status.is_uicc_present = +device_property_read_bool (&client->dev,"uicc-present" ); + r =st21nfca_hci_platform_init (phy);if (r <0 ) {nfc_err (&client->dev,"Unable to reboot st21nfca\n" );
Signature · 1 line
2.11.0