Linux-Integrity Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] tpm: st33zp24: Convert to use GPIO descriptors
@ 2020-03-04 22:17 Linus Walleij
  2020-03-05 11:43 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2020-03-04 22:17 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen, Jason Gunthorpe
  Cc: linux-integrity, Linus Walleij, Jeremy Boone

The ST33ZP24 is using the old deprecated GPIO API.
It also goes to some measures to convert from the
new to the old API in the ACPI probe path of both
the I2C and SPI interfaces for the module.

Change the driver and subdrivers to use struct
gpio_desc * all the way and pass this around in
platform data and in probe and all associated
functions.

Cc: Jeremy Boone <jeremy.boone@nccgroup.trust>
Cc: Peter Huewe <peterhuewe@gmx.de>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/char/tpm/st33zp24/i2c.c        | 44 +++++--------------------
 drivers/char/tpm/st33zp24/spi.c        | 45 +++++---------------------
 drivers/char/tpm/st33zp24/st33zp24.c   | 12 +++----
 drivers/char/tpm/st33zp24/st33zp24.h   |  6 ++--
 include/linux/platform_data/st33zp24.h |  4 ++-
 5 files changed, 29 insertions(+), 82 deletions(-)

diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c
index 35333b65acd1..9daa55894c3b 100644
--- a/drivers/char/tpm/st33zp24/i2c.c
+++ b/drivers/char/tpm/st33zp24/i2c.c
@@ -6,10 +6,8 @@
 
 #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>
 #include <linux/acpi.h>
 #include <linux/tpm.h>
 #include <linux/platform_data/st33zp24.h>
@@ -22,7 +20,7 @@
 struct st33zp24_i2c_phy {
 	struct i2c_client *client;
 	u8 buf[ST33ZP24_BUFSIZE + 1];
-	int io_lpcpd;
+	struct gpio_desc *io_lpcpd;
 };
 
 /*
@@ -124,7 +122,7 @@ static int st33zp24_i2c_acpi_request_resources(struct i2c_client *client)
 	if (IS_ERR(gpiod_lpcpd)) {
 		dev_err(&client->dev,
 			"Failed to retrieve lpcpd-gpios from acpi.\n");
-		phy->io_lpcpd = -1;
+		phy->io_lpcpd = NULL;
 		/*
 		 * lpcpd pin is not specified. This is not an issue as
 		 * power management can be also managed by TPM specific
@@ -133,7 +131,7 @@ static int st33zp24_i2c_acpi_request_resources(struct i2c_client *client)
 		return 0;
 	}
 
-	phy->io_lpcpd = desc_to_gpio(gpiod_lpcpd);
+	phy->io_lpcpd = gpiod_lpcpd;
 
 	return 0;
 }
@@ -143,22 +141,14 @@ static int st33zp24_i2c_of_request_resources(struct i2c_client *client)
 	struct tpm_chip *chip = i2c_get_clientdata(client);
 	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
 	struct st33zp24_i2c_phy *phy = tpm_dev->phy_id;
-	struct device_node *pp;
-	int gpio;
-	int ret;
-
-	pp = client->dev.of_node;
-	if (!pp) {
-		dev_err(&client->dev, "No platform data\n");
-		return -ENODEV;
-	}
+	struct gpio_desc *gpiod;
 
 	/* Get GPIO from device tree */
-	gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0);
-	if (gpio < 0) {
+	gpiod = devm_gpiod_get(&client->dev, "lpcpd", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpiod)) {
 		dev_err(&client->dev,
 			"Failed to retrieve lpcpd-gpios from dts.\n");
-		phy->io_lpcpd = -1;
+		phy->io_lpcpd = NULL;
 		/*
 		 * lpcpd pin is not specified. This is not an issue as
 		 * power management can be also managed by TPM specific
@@ -166,14 +156,7 @@ static int st33zp24_i2c_of_request_resources(struct i2c_client *client)
 		 */
 		return 0;
 	}
-	/* GPIO request and configuration */
-	ret = devm_gpio_request_one(&client->dev, gpio,
-			GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD");
-	if (ret) {
-		dev_err(&client->dev, "Failed to request lpcpd pin\n");
-		return -ENODEV;
-	}
-	phy->io_lpcpd = gpio;
+	phy->io_lpcpd = gpiod;
 
 	return 0;
 }
@@ -184,7 +167,6 @@ static int st33zp24_i2c_request_resources(struct i2c_client *client)
 	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
 	struct st33zp24_i2c_phy *phy = tpm_dev->phy_id;
 	struct st33zp24_platform_data *pdata;
-	int ret;
 
 	pdata = client->dev.platform_data;
 	if (!pdata) {
@@ -195,16 +177,6 @@ static int st33zp24_i2c_request_resources(struct i2c_client *client)
 	/* store for late use */
 	phy->io_lpcpd = pdata->io_lpcpd;
 
-	if (gpio_is_valid(pdata->io_lpcpd)) {
-		ret = devm_gpio_request_one(&client->dev,
-				pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH,
-				"TPM IO_LPCPD");
-		if (ret) {
-			dev_err(&client->dev, "Failed to request lpcpd pin\n");
-			return ret;
-		}
-	}
-
 	return 0;
 }
 
diff --git a/drivers/char/tpm/st33zp24/spi.c b/drivers/char/tpm/st33zp24/spi.c
index 26e09de50f1e..279525e258a6 100644
--- a/drivers/char/tpm/st33zp24/spi.c
+++ b/drivers/char/tpm/st33zp24/spi.c
@@ -6,10 +6,8 @@
 
 #include <linux/module.h>
 #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/tpm.h>
 #include <linux/platform_data/st33zp24.h>
@@ -61,7 +59,7 @@ struct st33zp24_spi_phy {
 	u8 tx_buf[ST33ZP24_SPI_BUFFER_SIZE];
 	u8 rx_buf[ST33ZP24_SPI_BUFFER_SIZE];
 
-	int io_lpcpd;
+	struct gpio_desc *io_lpcpd;
 	int latency;
 };
 
@@ -242,7 +240,7 @@ static int st33zp24_spi_acpi_request_resources(struct spi_device *spi_dev)
 	gpiod_lpcpd = devm_gpiod_get(dev, "lpcpd", GPIOD_OUT_HIGH);
 	if (IS_ERR(gpiod_lpcpd)) {
 		dev_err(dev, "Failed to retrieve lpcpd-gpios from acpi.\n");
-		phy->io_lpcpd = -1;
+		phy->io_lpcpd = NULL;
 		/*
 		 * lpcpd pin is not specified. This is not an issue as
 		 * power management can be also managed by TPM specific
@@ -251,7 +249,7 @@ static int st33zp24_spi_acpi_request_resources(struct spi_device *spi_dev)
 		return 0;
 	}
 
-	phy->io_lpcpd = desc_to_gpio(gpiod_lpcpd);
+	phy->io_lpcpd = gpiod_lpcpd;
 
 	return 0;
 }
@@ -261,22 +259,14 @@ static int st33zp24_spi_of_request_resources(struct spi_device *spi_dev)
 	struct tpm_chip *chip = spi_get_drvdata(spi_dev);
 	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
 	struct st33zp24_spi_phy *phy = tpm_dev->phy_id;
-	struct device_node *pp;
-	int gpio;
-	int ret;
-
-	pp = spi_dev->dev.of_node;
-	if (!pp) {
-		dev_err(&spi_dev->dev, "No platform data\n");
-		return -ENODEV;
-	}
+	struct gpio_desc *gpiod;
 
 	/* Get GPIO from device tree */
-	gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0);
-	if (gpio < 0) {
+	gpiod = devm_gpiod_get(&spi_dev->dev, "lpcpd", GPIOD_OUT_HIGH);
+	if (IS_ERR(gpiod)) {
 		dev_err(&spi_dev->dev,
 			"Failed to retrieve lpcpd-gpios from dts.\n");
-		phy->io_lpcpd = -1;
+		phy->io_lpcpd = NULL;
 		/*
 		 * lpcpd pin is not specified. This is not an issue as
 		 * power management can be also managed by TPM specific
@@ -284,14 +274,7 @@ static int st33zp24_spi_of_request_resources(struct spi_device *spi_dev)
 		 */
 		return 0;
 	}
-	/* GPIO request and configuration */
-	ret = devm_gpio_request_one(&spi_dev->dev, gpio,
-			GPIOF_OUT_INIT_HIGH, "TPM IO LPCPD");
-	if (ret) {
-		dev_err(&spi_dev->dev, "Failed to request lpcpd pin\n");
-		return -ENODEV;
-	}
-	phy->io_lpcpd = gpio;
+	phy->io_lpcpd = gpiod;
 
 	return 0;
 }
@@ -302,7 +285,6 @@ static int st33zp24_spi_request_resources(struct spi_device *dev)
 	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
 	struct st33zp24_spi_phy *phy = tpm_dev->phy_id;
 	struct st33zp24_platform_data *pdata;
-	int ret;
 
 	pdata = dev->dev.platform_data;
 	if (!pdata) {
@@ -313,17 +295,6 @@ static int st33zp24_spi_request_resources(struct spi_device *dev)
 	/* store for late use */
 	phy->io_lpcpd = pdata->io_lpcpd;
 
-	if (gpio_is_valid(pdata->io_lpcpd)) {
-		ret = devm_gpio_request_one(&dev->dev,
-				pdata->io_lpcpd, GPIOF_OUT_INIT_HIGH,
-				"TPM IO_LPCPD");
-		if (ret) {
-			dev_err(&dev->dev, "%s : reset gpio_request failed\n",
-				__FILE__);
-			return ret;
-		}
-	}
-
 	return 0;
 }
 
diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c
index 37bb13f516be..0cacc13df25d 100644
--- a/drivers/char/tpm/st33zp24/st33zp24.c
+++ b/drivers/char/tpm/st33zp24/st33zp24.c
@@ -12,7 +12,7 @@
 #include <linux/freezer.h>
 #include <linux/string.h>
 #include <linux/interrupt.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/sched.h>
 #include <linux/uaccess.h>
 #include <linux/io.h>
@@ -508,7 +508,7 @@ static const struct tpm_class_ops st33zp24_tpm = {
  *	 -1 in other case.
  */
 int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops,
-		   struct device *dev, int irq, int io_lpcpd)
+		   struct device *dev, int irq, struct gpio_desc *io_lpcpd)
 {
 	int ret;
 	u8 intmask = 0;
@@ -609,8 +609,8 @@ int st33zp24_pm_suspend(struct device *dev)
 
 	int ret = 0;
 
-	if (gpio_is_valid(tpm_dev->io_lpcpd))
-		gpio_set_value(tpm_dev->io_lpcpd, 0);
+	if (tpm_dev->io_lpcpd)
+		gpiod_set_value(tpm_dev->io_lpcpd, 0);
 	else
 		ret = tpm_pm_suspend(dev);
 
@@ -629,8 +629,8 @@ int st33zp24_pm_resume(struct device *dev)
 	struct st33zp24_dev *tpm_dev = dev_get_drvdata(&chip->dev);
 	int ret = 0;
 
-	if (gpio_is_valid(tpm_dev->io_lpcpd)) {
-		gpio_set_value(tpm_dev->io_lpcpd, 1);
+	if (tpm_dev->io_lpcpd) {
+		gpiod_set_value(tpm_dev->io_lpcpd, 1);
 		ret = wait_for_stat(chip,
 				TPM_STS_VALID, chip->timeout_b,
 				&tpm_dev->read_queue, false);
diff --git a/drivers/char/tpm/st33zp24/st33zp24.h b/drivers/char/tpm/st33zp24/st33zp24.h
index 6747be1e2502..3a8871eebbb6 100644
--- a/drivers/char/tpm/st33zp24/st33zp24.h
+++ b/drivers/char/tpm/st33zp24/st33zp24.h
@@ -10,6 +10,8 @@
 #define TPM_WRITE_DIRECTION	0x80
 #define ST33ZP24_BUFSIZE	2048
 
+struct gpio_desc;
+
 struct st33zp24_dev {
 	struct tpm_chip *chip;
 	void *phy_id;
@@ -17,7 +19,7 @@ struct st33zp24_dev {
 	int locality;
 	int irq;
 	u32 intrs;
-	int io_lpcpd;
+	struct gpio_desc *io_lpcpd;
 	wait_queue_head_t read_queue;
 };
 
@@ -33,6 +35,6 @@ int st33zp24_pm_resume(struct device *dev);
 #endif
 
 int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops,
-		   struct device *dev, int irq, int io_lpcpd);
+		   struct device *dev, int irq, struct gpio_desc *io_lpcpd);
 int st33zp24_remove(struct tpm_chip *chip);
 #endif /* __LOCAL_ST33ZP24_H__ */
diff --git a/include/linux/platform_data/st33zp24.h b/include/linux/platform_data/st33zp24.h
index 61db674f36cc..933034350ff5 100644
--- a/include/linux/platform_data/st33zp24.h
+++ b/include/linux/platform_data/st33zp24.h
@@ -9,8 +9,10 @@
 #define TPM_ST33_I2C			"st33zp24-i2c"
 #define TPM_ST33_SPI			"st33zp24-spi"
 
+struct gpio_desc;
+
 struct st33zp24_platform_data {
-	int io_lpcpd;
+	struct gpio_desc *io_lpcpd;
 };
 
 #endif /* __ST33ZP24_H__ */
-- 
2.17.1


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

* Re: [PATCH] tpm: st33zp24: Convert to use GPIO descriptors
  2020-03-04 22:17 [PATCH] tpm: st33zp24: Convert to use GPIO descriptors Linus Walleij
@ 2020-03-05 11:43 ` Jarkko Sakkinen
  0 siblings, 0 replies; 2+ messages in thread
From: Jarkko Sakkinen @ 2020-03-05 11:43 UTC (permalink / raw)
  To: Linus Walleij, Peter Huewe, Jason Gunthorpe; +Cc: linux-integrity, Jeremy Boone

On Wed, 2020-03-04 at 23:17 +0100, Linus Walleij wrote:
> The ST33ZP24 is using the old deprecated GPIO API.
> It also goes to some measures to convert from the
> new to the old API in the ACPI probe path of both
> the I2C and SPI interfaces for the module.
> 
> Change the driver and subdrivers to use struct
> gpio_desc * all the way and pass this around in
> platform data and in probe and all associated
> functions.
> 
> Cc: Jeremy Boone <jeremy.boone@nccgroup.trust>
> Cc: Peter Huewe <peterhuewe@gmx.de>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

Thanks, look great.

Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
[with the assumption that it passes sparse and checkpatch.pl]

Any chance to get like maybe even one tested-by for this? The change
is so straightforward and obvious that I'll pick it up anyway but
would feel better to have it tested by another peer.

/Jarkko


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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-04 22:17 [PATCH] tpm: st33zp24: Convert to use GPIO descriptors Linus Walleij
2020-03-05 11:43 ` Jarkko Sakkinen

Linux-Integrity Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-integrity/0 linux-integrity/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-integrity linux-integrity/ https://lore.kernel.org/linux-integrity \
		linux-integrity@vger.kernel.org
	public-inbox-index linux-integrity

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-integrity


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git