tpm: st33zp24: drop support for platform data
Subsystems (2)
PATCH 1/3 tpm: st33zp24: drop support for platform data
There are no users of st33zp24_platform_data in mainline, and new boards should be using device tree or ACPI to describe resources, so let's drop support for platform data from the driver.
--- drivers/char/tpm/st33zp24/i2c.c | 41 ++---------------------- drivers/char/tpm/st33zp24/spi.c | 44 +++----------------------- drivers/char/tpm/st33zp24/st33zp24.h | 3 ++ include/linux/platform_data/st33zp24.h | 16 ---------- 4 files changed, 10 insertions(+), 94 deletions(-) delete mode 100644 include/linux/platform_data/st33zp24.h
drivers/char/tpm/st33zp24/i2c.c +3 -38
@@ -12,7 +12,6 @@#include <linux/of_gpio.h> #include <linux/acpi.h> #include <linux/tpm.h> -#include <linux/platform_data/st33zp24.h> #include "../tpm.h" #include "st33zp24.h"
@@ -178,36 +177,6 @@ static int st33zp24_i2c_of_request_resources(struct i2c_client *client)return 0 ; } -static int st33zp24_i2c_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 st33zp24_platform_data *pdata; -int ret; - - pdata = client->dev.platform_data; -if (!pdata) { -dev_err (&client->dev,"No platform data\n" ); -return -ENODEV ; - } - -/* 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 ; -} -/* * st33zp24_i2c_probe initialize the TPM device * @param: client, the i2c_client description (TPM I2C description).
@@ -219,7 +188,6 @@ static int st33zp24_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) {int ret; -struct st33zp24_platform_data *pdata;struct st33zp24_i2c_phy *phy;if (!client) {
@@ -240,19 +208,16 @@ static int st33zp24_i2c_probe(struct i2c_client *client, phy->client = client; - pdata = client->dev.platform_data; -if (!pdata && client->dev.of_node) { +if (client->dev.of_node) { ret =st33zp24_i2c_of_request_resources (client);if (ret)return ret; - }else if (pdata) { - ret =st33zp24_i2c_request_resources (client); -if (ret) -return ret; }else if (ACPI_HANDLE (&client->dev)) { ret =st33zp24_i2c_acpi_request_resources (client);if (ret)return ret; + }else { +return -ENODEV ; } return st33zp24_probe(phy, &i2c_phy_ops, &client->dev, client->irq,
drivers/char/tpm/st33zp24/spi.c +4 -40
81 lines not on this page · raw message
drivers/char/tpm/st33zp24/st33zp24.h +3 -0
@@ -7,6 +7,9 @@#ifndef __LOCAL_ST33ZP24_H__#define __LOCAL_ST33ZP24_H__ +#define TPM_ST33_I2C "st33zp24-i2c" +#define TPM_ST33_SPI "st33zp24-spi" +#define TPM_WRITE_DIRECTION 0x80#define ST33ZP24_BUFSIZE 2048
include/linux/platform_data/st33zp24.h deleted +0 -16
@@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* STMicroelectronics TPM Linux driver for TPM 1.2 ST33ZP24 -* Copyright (C) 2009 - 2016 STMicroelectronics -*/ -#ifndef __ST33ZP24_H__ -#define __ST33ZP24_H__ - -#define TPM_ST33_I2C "st33zp24-i2c" -#define TPM_ST33_SPI "st33zp24-spi" - -struct st33zp24_platform_data { -int io_lpcpd; -}; - -#endif /* __ST33ZP24_H__ */
Signature · 1 line
2.37.3.998.g577e59143f-goog
PATCH 2/3 tpm: st33zp24: switch to using gpiod API
This patch switches the driver from legacy gpio API to the newer gpiod API, so that eventually we can drop the former.
During conversion it was noted that the gpio handling code for SPI and I2C variants duplicates each other, so it was moved into the core.
Also, it seems that the driver never assigned tpm_dev->io_lpcpd in the past, so gpio-based power management was most likely not working ever.
--- drivers/char/tpm/st33zp24/i2c.c | 101 +-------------------------- drivers/char/tpm/st33zp24/spi.c | 100 +------------------------- drivers/char/tpm/st33zp24/st33zp24.c | 39 +++++++++-- drivers/char/tpm/st33zp24/st33zp24.h | 4 +- 4 files changed, 39 insertions(+), 205 deletions(-)
drivers/char/tpm/st33zp24/i2c.c +2 -99
@@ -6,10 +6,7 @@#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/of.h> #include <linux/acpi.h> #include <linux/tpm.h>
@@ -21,7 +18,6 @@struct st33zp24_i2c_phy {struct i2c_client *client;u8 buf[ST33ZP24_BUFSIZE +1 ]; -int io_lpcpd; };/*
@@ -98,85 +94,6 @@ static const struct st33zp24_phy_ops i2c_phy_ops = { .recv = st33zp24_i2c_recv, }; -static const struct acpi_gpio_params lpcpd_gpios = {1 ,0 , false }; - -static const struct acpi_gpio_mapping acpi_st33zp24_gpios[] = { - {"lpcpd-gpios" , &lpcpd_gpios,1 }, - {}, -}; - -static int st33zp24_i2c_acpi_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 gpio_desc *gpiod_lpcpd; -struct device *dev = &client->dev; -int ret; - - ret =devm_acpi_dev_add_driver_gpios (dev, acpi_st33zp24_gpios); -if (ret) -return ret; - -/* Get LPCPD GPIO from ACPI */ - gpiod_lpcpd =devm_gpiod_get (dev,"lpcpd" ,GPIOD_OUT_HIGH ); -if (IS_ERR (gpiod_lpcpd)) { -dev_err (&client->dev, -"Failed to retrieve lpcpd-gpios from acpi.\n" ); - phy->io_lpcpd =-1 ; -/* -* lpcpd pin is not specified. This is not an issue as -* power management can be also managed by TPM specific -* commands. So leave with a success status code. -*/ -return 0 ; - } - - phy->io_lpcpd =desc_to_gpio (gpiod_lpcpd); - -return 0 ; -} - -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 ; - } - -/* Get GPIO from device tree */ - gpio =of_get_named_gpio (pp,"lpcpd-gpios" ,0 ); -if (gpio <0 ) { -dev_err (&client->dev, -"Failed to retrieve lpcpd-gpios from dts.\n" ); - phy->io_lpcpd =-1 ; -/* -* lpcpd pin is not specified. This is not an issue as -* power management can be also managed by TPM specific -* commands. So leave with a success status code. -*/ -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; - -return 0 ; -} -/* * st33zp24_i2c_probe initialize the TPM device * @param: client, the i2c_client description (TPM I2C description).
@@ -187,7 +104,6 @@ static int st33zp24_i2c_of_request_resources(struct i2c_client *client)static int st33zp24_i2c_probe (struct i2c_client *client,const struct i2c_device_id *id) { -int ret;struct st33zp24_i2c_phy *phy;if (!client) {
@@ -208,20 +124,7 @@ static int st33zp24_i2c_probe(struct i2c_client *client, phy->client = client; -if (client->dev.of_node) { - ret =st33zp24_i2c_of_request_resources (client); -if (ret) -return ret; - }else if (ACPI_HANDLE (&client->dev)) { - ret =st33zp24_i2c_acpi_request_resources (client); -if (ret) -return ret; - }else { -return -ENODEV ; - } - -return st33zp24_probe (phy, &i2c_phy_ops, &client->dev, client->irq, - phy->io_lpcpd); +return st33zp24_probe (phy, &i2c_phy_ops, &client->dev, client->irq); }/*
drivers/char/tpm/st33zp24/spi.c +2 -98
134 lines not on this page · raw message
drivers/char/tpm/st33zp24/st33zp24.c +33 -6
@@ -4,6 +4,7 @@* Copyright (C) 2009 - 2016 STMicroelectronics */ +#include <linux/acpi.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/kernel.h>
@@ -12,7 +13,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>
@@ -432,11 +433,18 @@ static const struct tpm_class_ops st33zp24_tpm = { .req_canceled = st33zp24_req_canceled, }; +static const struct acpi_gpio_params lpcpd_gpios = {1 ,0 , false }; + +static const struct acpi_gpio_mapping acpi_st33zp24_gpios[] = { + {"lpcpd-gpios" , &lpcpd_gpios,1 }, + { }, +}; +/* * initialize the TPM device */ 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) {int ret;u8 intmask =0 ;
@@ -463,6 +471,25 @@ int st33zp24_probe(void *phy_id, const struct st33zp24_phy_ops *ops, tpm_dev->locality =LOCALITY0 ; +if (ACPI_COMPANION (dev)) { + ret =devm_acpi_dev_add_driver_gpios (dev, acpi_st33zp24_gpios); +if (ret) +return ret; + } + +/* +* Get LPCPD GPIO. If lpcpd pin is not specified. This is not an +* issue as power management can be also managed by TPM specific +* commands. +*/ + tpm_dev->io_lpcpd =devm_gpiod_get_optional (dev,"lpcpd" , +GPIOD_OUT_HIGH ); + ret =PTR_ERR_OR_ZERO (tpm_dev->io_lpcpd); +if (ret) { +dev_err (dev,"failed to request lpcpd gpio: %d\n" , ret); +return ret; + } +if (irq) {/* INTERRUPT Setup */ init_waitqueue_head (&tpm_dev->read_queue);
@@ -525,8 +552,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_cansleep (tpm_dev->io_lpcpd,0 );else ret =tpm_pm_suspend (dev);
@@ -540,8 +567,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_cansleep (tpm_dev->io_lpcpd,1 ); ret =wait_for_stat (chip,TPM_STS_VALID , chip->timeout_b, &tpm_dev->read_queue, false);
drivers/char/tpm/st33zp24/st33zp24.h +2 -2
@@ -20,7 +20,7 @@ struct st33zp24_dev {int locality;int irq;u32 intrs; -int io_lpcpd; +struct gpio_desc *io_lpcpd;wait_queue_head_t read_queue; };
@@ -36,6 +36,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);void st33zp24_remove (struct tpm_chip *chip);#endif /* __LOCAL_ST33ZP24_H__ */
Signature · 1 line
2.37.3.998.g577e59143f-goog
Jarkko Sakkinen
maintainerRe: [PATCH 2/3] tpm: st33zp24: switch to using gpiod API
Quoted 2 lines · Dmitry Torokhov
This patch switches the driver from legacy gpio API to the newer gpiod API, so that eventually we can drop the former.
Once a patch is applied, it's a commit, not a patch. Just start by "Switch ...".
Please also define what is the legacy API exactly, and what sort of API it is switched to with a bit more detail. I don't follow GPIO.
Quoted 2 lines
During conversion it was noted that the gpio handling code for SPI and I2C variants duplicates each other, so it was moved into the core.
Who noted what? Please provide a reference. I do not connect this sentence to anything, as I do not follow gpio's mailing list.
Quoted 4 lines
Also, it seems that the driver never assigned
tpm_dev->io_lpcpdin the past, so gpio-based power management was most likely not working ever.Signed-off-by Dmitry Torokhov <[email protected]>
BR, Jarkko
PATCH 3/3 tpm: st33zp24: remove pointless checks on probe
In reply to Dmitry TorokhovDriver core will never call driver's probe method without appropriate device structure, so testing them for NULL is pointless.
--- drivers/char/tpm/st33zp24/i2c.c | 6 ------ drivers/char/tpm/st33zp24/spi.c | 7 ------- 2 files changed, 13 deletions(-)
drivers/char/tpm/st33zp24/i2c.c +0 -6
@@ -106,12 +106,6 @@ static int st33zp24_i2c_probe(struct i2c_client *client, {struct st33zp24_i2c_phy *phy; -if (!client) { -pr_info ("%s: i2c client is NULL. Device not accessible.\n" , - __func__); -return -ENODEV ; - } -if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) {dev_info (&client->dev,"client not i2c capable\n" );return -ENODEV ;
drivers/char/tpm/st33zp24/spi.c +0 -7
@@ -223,13 +223,6 @@ static int st33zp24_spi_probe(struct spi_device *dev) {struct st33zp24_spi_phy *phy; -/* Check SPI platform functionnalities */ -if (!dev) { -pr_info ("%s: dev is NULL. Device is not accessible.\n" , - __func__); -return -ENODEV ; - } - phy =devm_kzalloc (&dev->dev,sizeof (struct st33zp24_spi_phy ),GFP_KERNEL );if (!phy)
Signature · 1 line
2.37.3.998.g577e59143f-goog
Jarkko Sakkinen
maintainerRe: [PATCH 3/3] tpm: st33zp24: remove pointless checks on probe
Quoted 4 lines · Dmitry Torokhov
Driver core will never call driver's probe method without appropriate device structure, so testing them for NULL is pointless.
Signed-off-by Dmitry Torokhov <[email protected]>
Missing a description what the patch does.
Also instead of "driver's probe method" you could just use "st33zp24_i2c_probe()". It's even shorter.
BR, Jarkko
Re: [PATCH 3/3] tpm: st33zp24: remove pointless checks on probe
Quoted 10 lines · Jarkko Sakkinen
Quoted 4 lines · Dmitry Torokhov
Driver core will never call driver's probe method without appropriate device structure, so testing them for NULL is pointless.
Signed-off-by Dmitry Torokhov <[email protected]>Missing a description what the patch does.
Also instead of "driver's probe method" you could just use "
st33zp24_i2c_probe()". It's even shorter.
There are 2 interfaces: I2C and SPI, thus 2 separate probe methods.
Thanks.
Signature · 1 line
Dmitry
Jarkko Sakkinen
maintainerQuoted 3 lines · Dmitry Torokhov
There are no users of
st33zp24_platform_datain mainline, and new boards should be using device tree or ACPI to describe resources, so let's drop support for platform data from the driver.
Nit: drop instead of let's drop (needs also different sentence structure obviously).
Also, please leave predictions out, or back them up with data. It's good enough reason to remove code, if it is not used for anything. I really don't care about "should" part. It is is out-of-scope for a kernel patch.
BR, Jarkko
Quoted 7 lines · Jarkko Sakkinen
Quoted 3 lines · Dmitry Torokhov
There are no users of
st33zp24_platform_datain mainline, and new boards should be using device tree or ACPI to describe resources, so let's drop support for platform data from the driver.Nit: drop instead of let's drop (needs also different sentence structure obviously).
OK.
Quoted 5 lines
Also, please leave predictions out, or back them up with data. It's good enough reason to remove code, if it is not used for anything. I really don't care about "should" part. It is is out-of-scope for a kernel patch.
This is not a prediction, but a statement. The idea I was trying to express is that platform data is needed for legacy boards, those that predate device tree and/or ACPI support. Therefore there will be no new users of it appearing in the kernel, as we will not accept a new board/architecture it using wither ACPI or DT.
Thanks.
Signature · 1 line
Dmitry