public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Rob Barnes <robbarnes@google.com>,
	Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] char: tpm: cr50: Set TPM_FIRMWARE_POWER_MANAGED based on device property
Date: Sat, 11 Dec 2021 07:06:05 +0200	[thread overview]
Message-ID: <d0dbaa48d39079322826bc5e5783db635bf6dc03.camel@kernel.org> (raw)
In-Reply-To: <20211206120311.2844838-1-robbarnes@google.com>

On Mon, 2021-12-06 at 12:03 +0000, Rob Barnes wrote:
> Set TPM_FIRMWARE_POWER_MANAGED flag based on 'firmware-power-managed'
> ACPI DSD property. For the CR50 TPM, this flag defaults to true when
> the property is unset.
> 
> When this flag is set to false, the CR50 TPM driver will always send
> a shutdown command whenever the system suspends.
> 
> Signed-off-by: Rob Barnes <robbarnes@google.com>
> ---
>  drivers/char/tpm/tpm_tis_i2c_cr50.c | 16 +++++++++++++++-
>  drivers/char/tpm/tpm_tis_spi_cr50.c | 16 +++++++++++++++-
>  2 files changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/tpm/tpm_tis_i2c_cr50.c b/drivers/char/tpm/tpm_tis_i2c_cr50.c
> index c89278103703..f6c0affbb456 100644
> --- a/drivers/char/tpm/tpm_tis_i2c_cr50.c
> +++ b/drivers/char/tpm/tpm_tis_i2c_cr50.c
> @@ -628,6 +628,19 @@ static bool tpm_cr50_i2c_req_canceled(struct tpm_chip *chip, u8 status)
>  	return status == TPM_STS_COMMAND_READY;
>  }
>  
> +static bool tpm_cr50_i2c_is_firmware_power_managed(struct device *dev)
> +{
> +	u8 val;
> +	int ret;
> +
> +	/* This flag should default true when the device property is not present */
> +	ret = device_property_read_u8(dev, "firmware-power-managed", &val);
> +	if (ret)
> +		return true;
> +
> +	return val;
> +}
> +
>  static const struct tpm_class_ops cr50_i2c = {
>  	.flags = TPM_OPS_AUTO_STARTUP,
>  	.status = &tpm_cr50_i2c_tis_status,
> @@ -686,7 +699,8 @@ static int tpm_cr50_i2c_probe(struct i2c_client *client)
>  
>  	/* cr50 is a TPM 2.0 chip */
>  	chip->flags |= TPM_CHIP_FLAG_TPM2;
> -	chip->flags |= TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED;
> +	if (tpm_cr50_i2c_is_firmware_power_managed(dev))
> +		chip->flags |= TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED;
>  
>  	/* Default timeouts */
>  	chip->timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
> diff --git a/drivers/char/tpm/tpm_tis_spi_cr50.c b/drivers/char/tpm/tpm_tis_spi_cr50.c
> index dae98dbeeeac..7bf123d3c537 100644
> --- a/drivers/char/tpm/tpm_tis_spi_cr50.c
> +++ b/drivers/char/tpm/tpm_tis_spi_cr50.c
> @@ -185,6 +185,19 @@ static int cr50_spi_flow_control(struct tpm_tis_spi_phy *phy,
>  	return 0;
>  }
>  
> +static bool tpm_cr50_spi_is_firmware_power_managed(struct device *dev)
> +{
> +	u8 val;
> +	int ret;
> +
> +	/* This flag should default true when the device property is not present */
> +	ret = device_property_read_u8(dev, "firmware-power-managed", &val);
> +	if (ret)
> +		return true;
> +
> +	return val;
> +}
> +
>  static int tpm_tis_spi_cr50_transfer(struct tpm_tis_data *data, u32 addr, u16 len,
>  				     u8 *in, const u8 *out)
>  {
> @@ -309,7 +322,8 @@ int cr50_spi_probe(struct spi_device *spi)
>  	cr50_print_fw_version(&phy->priv);
>  
>  	chip = dev_get_drvdata(&spi->dev);
> -	chip->flags |= TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED;
> +	if (tpm_cr50_spi_is_firmware_power_managed(&spi->dev))
> +		chip->flags |= TPM_CHIP_FLAG_FIRMWARE_POWER_MANAGED;
>  
>  	return 0;
>  }

Thank you.

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

I applied this to my tree, and it should be visible in linux-next soon.

/Jarkko

  reply	other threads:[~2021-12-11  5:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30 23:59 [PATCH] char: tpm: cr50: Set TPM_FIRMWARE_POWER_MANAGED based on device property Rob Barnes
2021-12-01  6:35 ` kernel test robot
2021-12-02 20:03   ` [PATCH v2] " Rob Barnes
2021-12-04 18:05     ` Jarkko Sakkinen
2021-12-06 12:03       ` [PATCH v3] " Rob Barnes
2021-12-11  5:06         ` Jarkko Sakkinen [this message]
2021-12-06 23:52 ` [PATCH] " Rob Barnes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d0dbaa48d39079322826bc5e5783db635bf6dc03.camel@kernel.org \
    --to=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=robbarnes@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox