linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data
@ 2023-01-16 12:47 Andy Shevchenko
  2023-01-16 12:47 ` [PATCH v1 2/3] gpio: pcf857x: Make use of device properties Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Andy Shevchenko @ 2023-01-16 12:47 UTC (permalink / raw)
  To: Uwe Kleine-König, Andy Shevchenko, linux-kernel, linux-gpio
  Cc: Linus Walleij, Bartosz Golaszewski

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 <andriy.shevchenko@linux.intel.com>
---
 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

diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index d9db878802b7..dfa15444a24a 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -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,
 };
diff --git a/include/linux/platform_data/pcf857x.h b/include/linux/platform_data/pcf857x.h
deleted file mode 100644
index 01d0a3ea3aef..000000000000
--- a/include/linux/platform_data/pcf857x.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef __LINUX_PCF857X_H
-#define __LINUX_PCF857X_H
-
-/**
- * struct pcf857x_platform_data - data to set up pcf857x driver
- * @gpio_base: number of the chip's first GPIO
- * @n_latch: optional bit-inverse of initial register value; if
- *	you leave this initialized to zero the driver will act
- *	like the chip was just reset
- * @setup: optional callback issued once the GPIOs are valid
- * @teardown: optional callback issued before the GPIOs are invalidated
- * @context: optional parameter passed to setup() and teardown()
- *
- * In addition to the I2C_BOARD_INFO() state appropriate to each chip,
- * the i2c_board_info used with the pcf875x driver must provide its
- * platform_data (pointer to one of these structures) with at least
- * the gpio_base value initialized.
- *
- * The @setup callback may be used with the kind of board-specific glue
- * which hands the (now-valid) GPIOs to other drivers, or which puts
- * devices in their initial states using these GPIOs.
- *
- * These GPIO chips are only "quasi-bidirectional"; read the chip specs
- * to understand the behavior.  They don't have separate registers to
- * record which pins are used for input or output, record which output
- * values are driven, or provide access to input values.  That must be
- * inferred by reading the chip's value and knowing the last value written
- * to it.  If you leave n_latch initialized to zero, that last written
- * value is presumed to be all ones (as if the chip were just reset).
- */
-struct pcf857x_platform_data {
-	unsigned	gpio_base;
-	unsigned	n_latch;
-
-	int		(*setup)(struct i2c_client *client,
-					int gpio, unsigned ngpio,
-					void *context);
-	void		(*teardown)(struct i2c_client *client,
-					int gpio, unsigned ngpio,
-					void *context);
-	void		*context;
-};
-
-#endif /* __LINUX_PCF857X_H */
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 2/3] gpio: pcf857x: Make use of device properties
  2023-01-16 12:47 [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data Andy Shevchenko
@ 2023-01-16 12:47 ` Andy Shevchenko
  2023-01-17 12:41   ` Linus Walleij
  2023-01-16 12:47 ` [PATCH v1 3/3] gpio: pcf857x: Drop unneeded explicit casting Andy Shevchenko
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2023-01-16 12:47 UTC (permalink / raw)
  To: Uwe Kleine-König, Andy Shevchenko, linux-kernel, linux-gpio
  Cc: Linus Walleij, Bartosz Golaszewski

Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.

Add mod_devicetable.h include.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pcf857x.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index dfa15444a24a..9d34776109db 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -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,
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v1 3/3] gpio: pcf857x: Drop unneeded explicit casting
  2023-01-16 12:47 [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data Andy Shevchenko
  2023-01-16 12:47 ` [PATCH v1 2/3] gpio: pcf857x: Make use of device properties Andy Shevchenko
@ 2023-01-16 12:47 ` Andy Shevchenko
  2023-01-17 13:12   ` Linus Walleij
  2023-01-17  9:00 ` [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data Linus Walleij
  2023-01-18 14:17 ` Bartosz Golaszewski
  3 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2023-01-16 12:47 UTC (permalink / raw)
  To: Uwe Kleine-König, Andy Shevchenko, linux-kernel, linux-gpio
  Cc: Linus Walleij, Bartosz Golaszewski

The s32 is compatible with int, no need to cast.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pcf857x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index 9d34776109db..3de1d3ad7472 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -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 */
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data
  2023-01-16 12:47 [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data Andy Shevchenko
  2023-01-16 12:47 ` [PATCH v1 2/3] gpio: pcf857x: Make use of device properties Andy Shevchenko
  2023-01-16 12:47 ` [PATCH v1 3/3] gpio: pcf857x: Drop unneeded explicit casting Andy Shevchenko
@ 2023-01-17  9:00 ` Linus Walleij
  2023-01-18 14:17 ` Bartosz Golaszewski
  3 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2023-01-17  9:00 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Uwe Kleine-König, linux-kernel, linux-gpio,
	Bartosz Golaszewski

On Mon, Jan 16, 2023 at 1:46 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> 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 <andriy.shevchenko@linux.intel.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 2/3] gpio: pcf857x: Make use of device properties
  2023-01-16 12:47 ` [PATCH v1 2/3] gpio: pcf857x: Make use of device properties Andy Shevchenko
@ 2023-01-17 12:41   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2023-01-17 12:41 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Uwe Kleine-König, linux-kernel, linux-gpio,
	Bartosz Golaszewski

On Mon, Jan 16, 2023 at 1:46 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> Convert the module to be property provider agnostic and allow
> it to be used on non-OF platforms.
>
> Add mod_devicetable.h include.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

LGTM:
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

> -       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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 3/3] gpio: pcf857x: Drop unneeded explicit casting
  2023-01-16 12:47 ` [PATCH v1 3/3] gpio: pcf857x: Drop unneeded explicit casting Andy Shevchenko
@ 2023-01-17 13:12   ` Linus Walleij
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Walleij @ 2023-01-17 13:12 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Uwe Kleine-König, linux-kernel, linux-gpio,
	Bartosz Golaszewski

On Mon, Jan 16, 2023 at 1:46 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> The s32 is compatible with int, no need to cast.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data
  2023-01-16 12:47 [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data Andy Shevchenko
                   ` (2 preceding siblings ...)
  2023-01-17  9:00 ` [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data Linus Walleij
@ 2023-01-18 14:17 ` Bartosz Golaszewski
  3 siblings, 0 replies; 7+ messages in thread
From: Bartosz Golaszewski @ 2023-01-18 14:17 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Uwe Kleine-König, linux-kernel, linux-gpio, Linus Walleij

On Mon, Jan 16, 2023 at 1:46 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> 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 <andriy.shevchenko@linux.intel.com>
> ---

Applied the entire series, thanks!

Bart

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-01-18 14:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-16 12:47 [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data Andy Shevchenko
2023-01-16 12:47 ` [PATCH v1 2/3] gpio: pcf857x: Make use of device properties Andy Shevchenko
2023-01-17 12:41   ` Linus Walleij
2023-01-16 12:47 ` [PATCH v1 3/3] gpio: pcf857x: Drop unneeded explicit casting Andy Shevchenko
2023-01-17 13:12   ` Linus Walleij
2023-01-17  9:00 ` [PATCH v1 1/3] gpio: pcf857x: Get rid of legacy platform data Linus Walleij
2023-01-18 14:17 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).