gpio: pcf857x: Get rid of legacy platform data
PATCH 1/3 gpio: pcf857x: Get rid of legacy platform data
Platform data is a legacy interface to supply device properties to the driver. In this case we don't have in-kernel users for it. Moreover it uses plain GPIO numbers which is no-no for a new code.
Just remove it for good.
--- drivers/gpio/gpio-pcf857x.c | 34 ++------------------ include/linux/platform_data/pcf857x.h | 45 --------------------------- 2 files changed, 2 insertions(+), 77 deletions(-) delete mode 100644 include/linux/platform_data/pcf857x.h
drivers/gpio/gpio-pcf857x.c +2 -32
@@ -7,7 +7,6 @@#include <linux/gpio/driver.h> #include <linux/i2c.h> -#include <linux/platform_data/pcf857x.h> #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/irqdomain.h>
@@ -18,7 +17,6 @@#include <linux/slab.h> #include <linux/spinlock.h> -static const struct i2c_device_id pcf857x_id[] = { {"pcf8574" ,8 }, {"pcf8574a" ,8 },
@@ -277,18 +275,12 @@ static const struct irq_chip pcf857x_irq_chip = {static int pcf857x_probe (struct i2c_client *client) {const struct i2c_device_id *id =i2c_client_get_device_id (client); -struct pcf857x_platform_data *pdata =dev_get_platdata (&client->dev);struct device_node *np = client->dev.of_node;struct pcf857x *gpio;unsigned int n_latch =0 ;int status; -if (IS_ENABLED (CONFIG_OF ) && np) -of_property_read_u32 (np,"lines-initial-states" , &n_latch); -else if (pdata) - n_latch = pdata->n_latch; -else -dev_dbg (&client->dev,"no platform data\n" ); +of_property_read_u32 (np,"lines-initial-states" , &n_latch);/* Allocate, initialize, and register this gpio_chip. */ gpio =devm_kzalloc (&client->dev,sizeof (*gpio),GFP_KERNEL );
@@ -297,7 +289,7 @@ static int pcf857x_probe(struct i2c_client *client)mutex_init (&gpio->lock); - gpio->chip.base = pdata ? pdata->gpio_base :-1 ; + gpio->chip.base =-1 ; gpio->chip.can_sleep = true; gpio->chip.parent = &client->dev; gpio->chip.owner =THIS_MODULE ;
@@ -406,17 +398,6 @@ static int pcf857x_probe(struct i2c_client *client)if (status <0 ) goto fail; -/* Let platform code set up the GPIOs and their users. -* Now is the first time anyone could use them. -*/ -if (pdata && pdata->setup) { - status = pdata->setup (client, - gpio->chip.base, gpio->chip.ngpio, - pdata->context); -if (status <0 ) -dev_warn (&client->dev,"setup --> %d\n" , status); - } -dev_info (&client->dev,"probed\n" );return 0 ;
@@ -428,16 +409,6 @@ static int pcf857x_probe(struct i2c_client *client)return status; } -static void pcf857x_remove (struct i2c_client *client) -{ -struct pcf857x_platform_data *pdata =dev_get_platdata (&client->dev); -struct pcf857x *gpio =i2c_get_clientdata (client); - -if (pdata && pdata->teardown) - pdata->teardown (client, gpio->chip.base, gpio->chip.ngpio, - pdata->context); -} -static void pcf857x_shutdown (struct i2c_client *client) {struct pcf857x *gpio =i2c_get_clientdata (client);
@@ -452,7 +423,6 @@ static struct i2c_driver pcf857x_driver = { .of_match_table = of_match_ptr(pcf857x_of_table), }, .probe_new = pcf857x_probe, - .remove = pcf857x_remove, .shutdown = pcf857x_shutdown, .id_table = pcf857x_id, };
include/linux/platform_data/pcf857x.h deleted +0 -45
45 lines not on this page · raw message
Signature · 1 line
2.39.0
PATCH 2/3 gpio: pcf857x: Make use of device properties
Convert the module to be property provider agnostic and allow it to be used on non-OF platforms.
Add mod_devicetable.h include.
--- drivers/gpio/gpio-pcf857x.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/gpio/gpio-pcf857x.c +4 -7
@@ -11,9 +11,9 @@#include <linux/irq.h> #include <linux/irqdomain.h> #include <linux/kernel.h> +#include <linux/mod_devicetable.h> #include <linux/module.h> -#include <linux/of.h> -#include <linux/of_device.h> +#include <linux/property.h> #include <linux/slab.h> #include <linux/spinlock.h>
@@ -35,7 +35,6 @@ static const struct i2c_device_id pcf857x_id[] = { };MODULE_DEVICE_TABLE (i2c, pcf857x_id); -#ifdef CONFIG_OF static const struct of_device_id pcf857x_of_table[] = { { .compatible ="nxp,pcf8574" }, { .compatible ="nxp,pcf8574a" },
@@ -53,7 +52,6 @@ static const struct of_device_id pcf857x_of_table[] = { { } };MODULE_DEVICE_TABLE (of, pcf857x_of_table); -#endif /* * The pcf857x, pca857x, and pca967x chips only expose one read and one
@@ -275,12 +273,11 @@ static const struct irq_chip pcf857x_irq_chip = {static int pcf857x_probe (struct i2c_client *client) {const struct i2c_device_id *id =i2c_client_get_device_id (client); -struct device_node *np = client->dev.of_node;struct pcf857x *gpio;unsigned int n_latch =0 ;int status; -of_property_read_u32 (np,"lines-initial-states" , &n_latch); +device_property_read_u32 (&client->dev,"lines-initial-states" , &n_latch);/* Allocate, initialize, and register this gpio_chip. */ gpio =devm_kzalloc (&client->dev,sizeof (*gpio),GFP_KERNEL );
@@ -420,7 +417,7 @@ static void pcf857x_shutdown(struct i2c_client *client)static struct i2c_driver pcf857x_driver = { .driver = { .name ="pcf857x" , - .of_match_table =of_match_ptr (pcf857x_of_table), + .of_match_table = pcf857x_of_table, }, .probe_new = pcf857x_probe, .shutdown = pcf857x_shutdown,
Signature · 1 line
2.39.0
Re: [PATCH v1 2/3] gpio: pcf857x: Make use of device properties
Quoted 6 lines · Andy Shevchenko
Convert the module to be property provider agnostic and allow it to be used on non-OF platforms.
Add
mod_devicetable.hinclude.Signed-off-by Andy Shevchenko <[email protected]>
LGTM:
drivers/gpio/gpio-pcf857x.c static const struct irq_chip pcf857x_irq_chip = { · line 280
Quoted 2 lines
drivers/gpio/gpio-pcf857x.c +1
-1-of_property_read_u32 (np,"lines-initial-states" , &n_latch); +device_property_read_u32 (&client->dev,"lines-initial-states" , &n_latch);
Haha we even managed to sneak in an official property for this, I don't know when that happened but very good to have, this is the first time I see it used actually.
Now I will recommend everyone with this problem to just follow the PCF857x example.
Yours,
Linus Walleij
PATCH 3/3 gpio: pcf857x: Drop unneeded explicit casting
In reply to Andy ShevchenkoThe s32 is compatible with int, no need to cast.
--- drivers/gpio/gpio-pcf857x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-pcf857x.c +1 -1
@@ -88,7 +88,7 @@ static int i2c_write_le8(struct i2c_client *client, unsigned int data)static int i2c_read_le8 (struct i2c_client *client) { -return (int )i2c_smbus_read_byte (client); +return i2c_smbus_read_byte (client); }/* Talk to 16-bit I/O expander */
Signature · 1 line
2.39.0
Re: [PATCH v1 3/3] gpio: pcf857x: Drop unneeded explicit casting
Quoted 3 lines · Andy Shevchenko
The s32 is compatible with int, no need to cast.
Signed-off-by Andy Shevchenko <[email protected]>
Yours,
Linus Walleij
Quoted 7 lines · Andy Shevchenko
Platform data is a legacy interface to supply device properties to the driver. In this case we don't have in-kernel users for it. Moreover it uses plain GPIO numbers which is no-no for a new code.
Just remove it for good.
Signed-off-by Andy Shevchenko <[email protected]>
Yours,
Linus Walleij
Quoted 9 lines · Andy Shevchenko
Platform data is a legacy interface to supply device properties to the driver. In this case we don't have in-kernel users for it. Moreover it uses plain GPIO numbers which is no-no for a new code.
Just remove it for good.
Signed-off-by Andy Shevchenko <[email protected]>---
Applied the entire series, thanks!
Bart