From patchwork Mon Sep 26 05:39:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 12988218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58AE3C32771 for ; Mon, 26 Sep 2022 05:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233173AbiIZFkI (ORCPT ); Mon, 26 Sep 2022 01:40:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232918AbiIZFkH (ORCPT ); Mon, 26 Sep 2022 01:40:07 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B53A167F8; Sun, 25 Sep 2022 22:40:02 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id b75so5593630pfb.7; Sun, 25 Sep 2022 22:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=q5q/pcoR5gK1IIB9xUnqRycDl4QSWIGORl5qJdRKAlU=; b=kilmXACPBwgGDUyCOTufSNuEpS5jGnEpSeJ5P0H++obXSnftsE968Z4jODHCWlVkfI YWm3hxV3GrFKj2G5McycpTffYH3kTeUDVNRR3NThIGOxZAne5LoTuZorzX3soSIsXVe8 Q67S59ORA1wyGuI6rpdrvficI+aWLEGditR0c3OPADLyNROFOJYbPtl2Wvbv9yRT2Gm7 ywQMfHxCDDNir1XxhufVuok+WF5QACRFAdvtWagRKK2xB/wb9b/Ie4m65hJlXdsgwDQ5 0CKvWg/qIFWDddNn0lbprIiyeuQyu0JAlq8PGckuMiWiejrgmPJz/t15+eQDtOBvEEif zjTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=q5q/pcoR5gK1IIB9xUnqRycDl4QSWIGORl5qJdRKAlU=; b=rP94jJcEAixegrV1LctYGf0y3riaN6khO2cvDxz5//y1y4Z++GSP1T4UKlVhYBhAHA KeSgUp3c/vlVRU2lzh81ox0Il6cIq7f4XMi96c68tmTFH6LGR87Z2Q5udXZ4gkWWVl/B 5VK4u0SxsJhs7bUz0Xk65bgWvm3Clqx/Yfe1TUDoiEHYATaY+ZUlLJtrGKzFsOqBatNj XVIZ5AiTy7r/f8srgYxzXYNMBwXRFmL5t7YK/+bpUK0WmApfKrw0ei994yAlULABZ1ZD ohhv7hUpqXFqcE2tnsNlsI4hflbGRyhNXTKUopWbKXcPxC1QcnuqbXPgZ2pkel0y2C9+ 5Vzw== X-Gm-Message-State: ACrzQf2F2odD9jS2dsTOY3A9vgkeOsrh9tMhXfcWmmSVuUpmgiN/bl9M PmQytuhTPo+k5zLOZs4KHp0= X-Google-Smtp-Source: AMsMyM78fghL+9zCc59H4edjUDWmgdkmu+TEpSQdhvWRz0P58xy4ODEN8U8p8KfxSovhuZpbz6Lvgg== X-Received: by 2002:a05:6a02:10e:b0:43b:e57d:2bfa with SMTP id bg14-20020a056a02010e00b0043be57d2bfamr18019941pgb.263.1664170801725; Sun, 25 Sep 2022 22:40:01 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:7e1b:858c:19dc:934]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f71200b00176b0dec886sm10120350plo.58.2022.09.25.22.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 22:40:01 -0700 (PDT) From: Dmitry Torokhov To: Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] tpm: st33zp24: drop support for platform data Date: Sun, 25 Sep 2022 22:39:56 -0700 Message-Id: <20220926053958.1541912-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org 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. Signed-off-by: Dmitry Torokhov --- 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 diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c index a3aa411389e7..c560532647c8 100644 --- a/drivers/char/tpm/st33zp24/i2c.c +++ b/drivers/char/tpm/st33zp24/i2c.c @@ -12,7 +12,6 @@ #include #include #include -#include #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, diff --git a/drivers/char/tpm/st33zp24/spi.c b/drivers/char/tpm/st33zp24/spi.c index 22d184884694..49630f2cb9b4 100644 --- a/drivers/char/tpm/st33zp24/spi.c +++ b/drivers/char/tpm/st33zp24/spi.c @@ -12,7 +12,6 @@ #include #include #include -#include #include "../tpm.h" #include "st33zp24.h" @@ -296,37 +295,6 @@ static int st33zp24_spi_of_request_resources(struct spi_device *spi_dev) return 0; } -static int st33zp24_spi_request_resources(struct spi_device *dev) -{ - struct tpm_chip *chip = spi_get_drvdata(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) { - dev_err(&dev->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(&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; -} - /* * st33zp24_spi_probe initialize the TPM device * @param: dev, the spi_device description (TPM SPI description). @@ -336,7 +304,6 @@ static int st33zp24_spi_request_resources(struct spi_device *dev) static int st33zp24_spi_probe(struct spi_device *dev) { int ret; - struct st33zp24_platform_data *pdata; struct st33zp24_spi_phy *phy; /* Check SPI platform functionnalities */ @@ -353,19 +320,16 @@ static int st33zp24_spi_probe(struct spi_device *dev) phy->spi_device = dev; - pdata = dev->dev.platform_data; - if (!pdata && dev->dev.of_node) { + if (dev->dev.of_node) { ret = st33zp24_spi_of_request_resources(dev); if (ret) return ret; - } else if (pdata) { - ret = st33zp24_spi_request_resources(dev); - if (ret) - return ret; } else if (ACPI_HANDLE(&dev->dev)) { ret = st33zp24_spi_acpi_request_resources(dev); if (ret) return ret; + } else { + return -ENODEV; } phy->latency = st33zp24_spi_evaluate_latency(phy); @@ -411,7 +375,7 @@ static SIMPLE_DEV_PM_OPS(st33zp24_spi_ops, st33zp24_pm_suspend, static struct spi_driver st33zp24_spi_driver = { .driver = { - .name = TPM_ST33_SPI, + .name = "st33zp24-spi", .pm = &st33zp24_spi_ops, .of_match_table = of_match_ptr(of_st33zp24_spi_match), .acpi_match_table = ACPI_PTR(st33zp24_spi_acpi_match), diff --git a/drivers/char/tpm/st33zp24/st33zp24.h b/drivers/char/tpm/st33zp24/st33zp24.h index b387a476c555..6a26dbc3206b 100644 --- a/drivers/char/tpm/st33zp24/st33zp24.h +++ b/drivers/char/tpm/st33zp24/st33zp24.h @@ -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 diff --git a/include/linux/platform_data/st33zp24.h b/include/linux/platform_data/st33zp24.h deleted file mode 100644 index 61db674f36cc..000000000000 --- a/include/linux/platform_data/st33zp24.h +++ /dev/null @@ -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__ */ From patchwork Mon Sep 26 05:39:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 12988219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7298C07E9D for ; Mon, 26 Sep 2022 05:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233157AbiIZFkJ (ORCPT ); Mon, 26 Sep 2022 01:40:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233155AbiIZFkH (ORCPT ); Mon, 26 Sep 2022 01:40:07 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C104517045; Sun, 25 Sep 2022 22:40:03 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id s26so5595463pgv.7; Sun, 25 Sep 2022 22:40:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=dSYEUAayX2mBF64whhmu237xF7qkCSlutx0zb2SUaeA=; b=KVs2phhFD7VGjzbKzthUMu4LUhPfEprhSge6ToxqIyvJanF6Ca9UXRz+NKZ+8kpuSe CS7RpNysHTwZ9UV0bwP5wTiIJPPPr0xYVFSWv3xz0Gvec1rGRflTc88fPJc0fJIxfp1B 9G2DpJDq5m1cqCtgWQTcqmTWnDKwMJfQ2aapLWa7A9W2z9OTs7KJ1Nut4ffC2C8UnKw8 zIDidjnONmoe1irB0psM/kByeNSsoqwPIhhLWqI3J/MFKQiPZEdQzM5EeRYQMdbMiZSc UMxhbhVFrIqXqAarsSUhaOgVjoSHbyeSjHbdwUPOFdrazDbS/nta+WyAav/LQVVbk/NF 5Bew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=dSYEUAayX2mBF64whhmu237xF7qkCSlutx0zb2SUaeA=; b=ucK0WI1MSHcWRBsqgxB03vmXKVB0PbTEaNa4W6ZhvzUk6IXofZ+u8sQGlvoLxoXatI 2z2LhQOTpB28AB05h68xItS7G2ig3L8cK9B9zhYFBO2mpEOmpx4r7mOR2oq4sc8Y8q5r wVnNOpY+hudhJRC5MJUfukxrJt8LWIJXI+zNFrUyeCsiTAWbjR4q4gNWUPTEGdcy1OKe /mAp10fKpihk558jrpNV9cUA2dWb/n8kCZbnqHsGDyv1usa7rq8LmyPgD2zhagc+Pc9e pkBfT8y4AwNQMi66C7IqZbaSWRMuHbT91/CAyAMt1CpLWNS+4BvPayUCv4+qOsNzLX4N Puzg== X-Gm-Message-State: ACrzQf3M94V7BOxs6SqjakeXD6sCKhoJ9vMmPkUQEKX+VTUcgyavoZKv H7Uei2mz0/8wgGwJ8V2PFR3wjTjBxTs= X-Google-Smtp-Source: AMsMyM42UnwNJWzO8asS+HgsVplnIGBoEtYeKuBEyvd2ZjN7lsF72tZk1dW2hl804lyF26YRRQ+ijA== X-Received: by 2002:a63:1e4b:0:b0:439:1ca4:22f9 with SMTP id p11-20020a631e4b000000b004391ca422f9mr17615399pgm.588.1664170802770; Sun, 25 Sep 2022 22:40:02 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:7e1b:858c:19dc:934]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f71200b00176b0dec886sm10120350plo.58.2022.09.25.22.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 22:40:02 -0700 (PDT) From: Dmitry Torokhov To: Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] tpm: st33zp24: switch to using gpiod API Date: Sun, 25 Sep 2022 22:39:57 -0700 Message-Id: <20220926053958.1541912-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220926053958.1541912-1-dmitry.torokhov@gmail.com> References: <20220926053958.1541912-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org 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. Signed-off-by: Dmitry Torokhov --- 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(-) diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c index c560532647c8..614c7d8ed84f 100644 --- a/drivers/char/tpm/st33zp24/i2c.c +++ b/drivers/char/tpm/st33zp24/i2c.c @@ -6,10 +6,7 @@ #include #include -#include -#include -#include -#include +#include #include #include @@ -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); } /* diff --git a/drivers/char/tpm/st33zp24/spi.c b/drivers/char/tpm/st33zp24/spi.c index 49630f2cb9b4..ff4adbe104cf 100644 --- a/drivers/char/tpm/st33zp24/spi.c +++ b/drivers/char/tpm/st33zp24/spi.c @@ -6,10 +6,7 @@ #include #include -#include -#include -#include -#include +#include #include #include @@ -60,7 +57,6 @@ struct st33zp24_spi_phy { u8 tx_buf[ST33ZP24_SPI_BUFFER_SIZE]; u8 rx_buf[ST33ZP24_SPI_BUFFER_SIZE]; - int io_lpcpd; int latency; }; @@ -217,84 +213,6 @@ static const struct st33zp24_phy_ops spi_phy_ops = { .recv = st33zp24_spi_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_spi_acpi_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 gpio_desc *gpiod_lpcpd; - struct device *dev = &spi_dev->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(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_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; - } - - /* Get GPIO from device tree */ - gpio = of_get_named_gpio(pp, "lpcpd-gpios", 0); - if (gpio < 0) { - dev_err(&spi_dev->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(&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; - - return 0; -} - /* * st33zp24_spi_probe initialize the TPM device * @param: dev, the spi_device description (TPM SPI description). @@ -303,7 +221,6 @@ static int st33zp24_spi_of_request_resources(struct spi_device *spi_dev) */ static int st33zp24_spi_probe(struct spi_device *dev) { - int ret; struct st33zp24_spi_phy *phy; /* Check SPI platform functionnalities */ @@ -320,24 +237,11 @@ static int st33zp24_spi_probe(struct spi_device *dev) phy->spi_device = dev; - if (dev->dev.of_node) { - ret = st33zp24_spi_of_request_resources(dev); - if (ret) - return ret; - } else if (ACPI_HANDLE(&dev->dev)) { - ret = st33zp24_spi_acpi_request_resources(dev); - if (ret) - return ret; - } else { - return -ENODEV; - } - phy->latency = st33zp24_spi_evaluate_latency(phy); if (phy->latency <= 0) return -ENODEV; - return st33zp24_probe(phy, &spi_phy_ops, &dev->dev, dev->irq, - phy->io_lpcpd); + return st33zp24_probe(phy, &spi_phy_ops, &dev->dev, dev->irq); } /* diff --git a/drivers/char/tpm/st33zp24/st33zp24.c b/drivers/char/tpm/st33zp24/st33zp24.c index 15b393e92c8e..a5b554cd4778 100644 --- a/drivers/char/tpm/st33zp24/st33zp24.c +++ b/drivers/char/tpm/st33zp24/st33zp24.c @@ -4,6 +4,7 @@ * Copyright (C) 2009 - 2016 STMicroelectronics */ +#include #include #include #include @@ -12,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -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); diff --git a/drivers/char/tpm/st33zp24/st33zp24.h b/drivers/char/tpm/st33zp24/st33zp24.h index 6a26dbc3206b..5acc85f711e6 100644 --- a/drivers/char/tpm/st33zp24/st33zp24.h +++ b/drivers/char/tpm/st33zp24/st33zp24.h @@ -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__ */ From patchwork Mon Sep 26 05:39:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 12988220 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2F53C6FA8E for ; Mon, 26 Sep 2022 05:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232918AbiIZFkL (ORCPT ); Mon, 26 Sep 2022 01:40:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233195AbiIZFkK (ORCPT ); Mon, 26 Sep 2022 01:40:10 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9727D183BA; Sun, 25 Sep 2022 22:40:04 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id u69so5618518pgd.2; Sun, 25 Sep 2022 22:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=zbMWBpJAr3OkSRe66ITLMsu2IwUoetprW3YnPTViuio=; b=dOx4PbxAEA45IugHMxj+VOgf0c4AcoOEBjy447rlNd/9AfP2QjGYXtea3yg9skyxIK fFjDAPYOleyizDiY0xCUpedgRZgYP2f5Tmssaj+rZXY07EEj5I4eh8pMWmFdBeGSJkBe LfilB76y6vrdRBTtBlKgGq2SidQxImUas7yA7A+sm2rjUPR1iXgLfPCMf7LMK8FMTBu2 1tkfrFu9+yCBHKMIhrf1oD9eazvBMpGmvcJE2lK3itp6b9mdCzfAuxQTSOjul6uEwRIE EGw9WgP3rLgHkTsD2nPR6S5+XmuRTF/Xq6J7NtSwuc1Qsc/UXedMAkm9yV8HiwZEBj+N q0ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=zbMWBpJAr3OkSRe66ITLMsu2IwUoetprW3YnPTViuio=; b=JHFm0Xlw7vIt/GxMxas/dYAWHUrjSLeQPvd6RNlbAeUBjCrh3GCgldcRrROwZJkchB /QWKnYEK9a73jzIsu0LXEd85qyO1QU9vcjRdXOP39io3OQoIePgmYrRhvkug0EjwLq8a WL3Nk1bvOG2bDTHV6NABQVw1GqL3pUUUCBBCv2FbKq6huYbSAiRuuy5JxuFkBf3kdc9J xkc7Z6Ns+kae0WfasW4pwy4SYLR8ghMQpmr1acYS/UYST4WLprc6YQrf/lk8ePzpRyLu YWmkFrK3nSHX+QFGNRxNjHExg/dTypGDhtTzZChI2s7XgeM/KPvUFmzt4NtrqSmora71 WXOg== X-Gm-Message-State: ACrzQf08vXBd6yNXqe1L7en3p5cd+cgBMQ3rHINsULKLoG2YZjnZVUA6 6flO4ZCPncO3SudAvHh37lI= X-Google-Smtp-Source: AMsMyM78y3GHje17aC0crHddY/JbQqOBEWo9hveb8SUBzolzOMysUeG0fZK7vLtmf1eNsVtTJuA1iw== X-Received: by 2002:a63:90c9:0:b0:434:b578:3bb4 with SMTP id a192-20020a6390c9000000b00434b5783bb4mr17686371pge.389.1664170803940; Sun, 25 Sep 2022 22:40:03 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:7e1b:858c:19dc:934]) by smtp.gmail.com with ESMTPSA id h18-20020a170902f71200b00176b0dec886sm10120350plo.58.2022.09.25.22.40.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Sep 2022 22:40:03 -0700 (PDT) From: Dmitry Torokhov To: Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] tpm: st33zp24: remove pointless checks on probe Date: Sun, 25 Sep 2022 22:39:58 -0700 Message-Id: <20220926053958.1541912-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog In-Reply-To: <20220926053958.1541912-1-dmitry.torokhov@gmail.com> References: <20220926053958.1541912-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org 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 --- drivers/char/tpm/st33zp24/i2c.c | 6 ------ drivers/char/tpm/st33zp24/spi.c | 7 ------- 2 files changed, 13 deletions(-) diff --git a/drivers/char/tpm/st33zp24/i2c.c b/drivers/char/tpm/st33zp24/i2c.c index 614c7d8ed84f..8156bb2af78c 100644 --- a/drivers/char/tpm/st33zp24/i2c.c +++ b/drivers/char/tpm/st33zp24/i2c.c @@ -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; diff --git a/drivers/char/tpm/st33zp24/spi.c b/drivers/char/tpm/st33zp24/spi.c index ff4adbe104cf..2154059f0235 100644 --- a/drivers/char/tpm/st33zp24/spi.c +++ b/drivers/char/tpm/st33zp24/spi.c @@ -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)