diff mbox series

[v2] tpm: Add new device/vendor ID 0x50666666

Message ID 20240718202359.127482-1-jettrink@chromium.org (mailing list archive)
State Handled Elsewhere
Headers show
Series [v2] tpm: Add new device/vendor ID 0x50666666 | expand

Commit Message

Jett Rink July 18, 2024, 8:23 p.m. UTC
Accept another DID:VID for the next generation Google TPM. This TPM
has the same Ti50 firmware and fulfills the same interface.

Signed-off-by: Jett Rink <jettrink@chromium.org>
---

Changes in v2:
Patchset 2 applies cleanly

 drivers/char/tpm/tpm_tis_i2c_cr50.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Jett Rink Aug. 2, 2024, 3:19 p.m. UTC | #1
Could I get some feedback on this patch please? Is there something I
am not doing correctly?

-Jett

On Thu, Jul 18, 2024 at 2:24 PM Jett Rink <jettrink@chromium.org> wrote:
>
> Accept another DID:VID for the next generation Google TPM. This TPM
> has the same Ti50 firmware and fulfills the same interface.
>
> Signed-off-by: Jett Rink <jettrink@chromium.org>
> ---
>
> Changes in v2:
> Patchset 2 applies cleanly
>
>  drivers/char/tpm/tpm_tis_i2c_cr50.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/char/tpm/tpm_tis_i2c_cr50.c b/drivers/char/tpm/tpm_tis_i2c_cr50.c
> index adf22992138e..b50005ccfc5e 100644
> --- a/drivers/char/tpm/tpm_tis_i2c_cr50.c
> +++ b/drivers/char/tpm/tpm_tis_i2c_cr50.c
> @@ -31,7 +31,8 @@
>  #define TPM_CR50_TIMEOUT_SHORT_MS      2               /* Short timeout during transactions */
>  #define TPM_CR50_TIMEOUT_NOIRQ_MS      20              /* Timeout for TPM ready without IRQ */
>  #define TPM_CR50_I2C_DID_VID           0x00281ae0L     /* Device and vendor ID reg value */
> -#define TPM_TI50_I2C_DID_VID           0x504a6666L     /* Device and vendor ID reg value */
> +#define TPM_TI50_DT_I2C_DID_VID                0x504a6666L     /* Device and vendor ID reg value */
> +#define TPM_TI50_OT_I2C_DID_VID                0x50666666L     /* Device and vendor ID reg value */
>  #define TPM_CR50_I2C_MAX_RETRIES       3               /* Max retries due to I2C errors */
>  #define TPM_CR50_I2C_RETRY_DELAY_LO    55              /* Min usecs between retries on I2C */
>  #define TPM_CR50_I2C_RETRY_DELAY_HI    65              /* Max usecs between retries on I2C */
> @@ -741,14 +742,18 @@ static int tpm_cr50_i2c_probe(struct i2c_client *client)
>         }
>
>         vendor = le32_to_cpup((__le32 *)buf);
> -       if (vendor != TPM_CR50_I2C_DID_VID && vendor != TPM_TI50_I2C_DID_VID) {
> +       if (vendor != TPM_CR50_I2C_DID_VID &&
> +           vendor != TPM_TI50_DT_I2C_DID_VID &&
> +           vendor != TPM_TI50_OT_I2C_DID_VID) {
>                 dev_err(dev, "Vendor ID did not match! ID was %08x\n", vendor);
>                 tpm_cr50_release_locality(chip, true);
>                 return -ENODEV;
>         }
>
>         dev_info(dev, "%s TPM 2.0 (i2c 0x%02x irq %d id 0x%x)\n",
> -                vendor == TPM_TI50_I2C_DID_VID ? "ti50" : "cr50",
> +                vendor == TPM_CR50_I2C_DID_VID    ? "cr50" :
> +                vendor == TPM_TI50_DT_I2C_DID_VID ? "ti50 DT" :
> +                                                    "ti50 OT",
>                  client->addr, client->irq, vendor >> 16);
>         return tpm_chip_register(chip);
>  }
> --
> 2.45.2.1089.g2a221341d9-goog
>
Jarkko Sakkinen Aug. 2, 2024, 7:15 p.m. UTC | #2
On Fri Aug 2, 2024 at 6:19 PM EEST, Jett Rink wrote:
> Could I get some feedback on this patch please? Is there something I
> am not doing correctly?

Sorry, I just came from holidays.

>
> -Jett
>
> On Thu, Jul 18, 2024 at 2:24 PM Jett Rink <jettrink@chromium.org> wrote:
> >
> > Accept another DID:VID for the next generation Google TPM. This TPM
> > has the same Ti50 firmware and fulfills the same interface.
> >
> > Signed-off-by: Jett Rink <jettrink@chromium.org>
> > ---
> >
> > Changes in v2:
> > Patchset 2 applies cleanly
> >
> >  drivers/char/tpm/tpm_tis_i2c_cr50.c | 11 ++++++++---
> >  1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/char/tpm/tpm_tis_i2c_cr50.c b/drivers/char/tpm/tpm_tis_i2c_cr50.c
> > index adf22992138e..b50005ccfc5e 100644
> > --- a/drivers/char/tpm/tpm_tis_i2c_cr50.c
> > +++ b/drivers/char/tpm/tpm_tis_i2c_cr50.c
> > @@ -31,7 +31,8 @@
> >  #define TPM_CR50_TIMEOUT_SHORT_MS      2               /* Short timeout during transactions */
> >  #define TPM_CR50_TIMEOUT_NOIRQ_MS      20              /* Timeout for TPM ready without IRQ */
> >  #define TPM_CR50_I2C_DID_VID           0x00281ae0L     /* Device and vendor ID reg value */
> > -#define TPM_TI50_I2C_DID_VID           0x504a6666L     /* Device and vendor ID reg value */
> > +#define TPM_TI50_DT_I2C_DID_VID                0x504a6666L     /* Device and vendor ID reg value */
> > +#define TPM_TI50_OT_I2C_DID_VID                0x50666666L     /* Device and vendor ID reg value */
> >  #define TPM_CR50_I2C_MAX_RETRIES       3               /* Max retries due to I2C errors */
> >  #define TPM_CR50_I2C_RETRY_DELAY_LO    55              /* Min usecs between retries on I2C */
> >  #define TPM_CR50_I2C_RETRY_DELAY_HI    65              /* Max usecs between retries on I2C */
> > @@ -741,14 +742,18 @@ static int tpm_cr50_i2c_probe(struct i2c_client *client)
> >         }
> >
> >         vendor = le32_to_cpup((__le32 *)buf);
> > -       if (vendor != TPM_CR50_I2C_DID_VID && vendor != TPM_TI50_I2C_DID_VID) {
> > +       if (vendor != TPM_CR50_I2C_DID_VID &&
> > +           vendor != TPM_TI50_DT_I2C_DID_VID &&
> > +           vendor != TPM_TI50_OT_I2C_DID_VID) {
> >                 dev_err(dev, "Vendor ID did not match! ID was %08x\n", vendor);
> >                 tpm_cr50_release_locality(chip, true);
> >                 return -ENODEV;
> >         }
> >
> >         dev_info(dev, "%s TPM 2.0 (i2c 0x%02x irq %d id 0x%x)\n",
> > -                vendor == TPM_TI50_I2C_DID_VID ? "ti50" : "cr50",
> > +                vendor == TPM_CR50_I2C_DID_VID    ? "cr50" :
> > +                vendor == TPM_TI50_DT_I2C_DID_VID ? "ti50 DT" :
> > +                                                    "ti50 OT",

Whenever possible ternary operator should be avoided, unless the use
case super trivial: this complexity brings us zero measurable benefit
and unnecessarily obfuscates code.

I'd suggest to simply add a helper:

/*
 * Maps VID to a name.
 */
const char *tpm_cr50_vid_to_name(u32 vendor)
{
	switch (vendor) {
	case TPM_CR50_I2C_DID_VID:
		return "cr50";
	case TPM_TI50_DT_I2C_DID_VID:
		return "ti50 DT";
	case TPM_TI50_OT_I2C_DID_VID:
		return "ti50 OT";
	default:	
		break;
	}

	tpm_cr50_release_locality(chip, true);
	return NULL;
}

The code then transforms to:

	vendor = le32_to_cpup((__le32 *)buf);

	name = tpm2_cr50_vid_to_name(vendor);
	if (name == NULL) {
		dev_err(dev, "Vendor ID did not match! ID was %08x\n", vendor);
		return -ENODEV;
	}

	dev_info(dev, "%s TPM 2.0 (i2c 0x%02x irq %d id 0x%x)\n", name.
		 client->addr, client->addr, client->irq, vendor >> 16);

[and add suggested-by]

> >                  client->addr, client->irq, vendor >> 16);
> >         return tpm_chip_register(chip);
> >  }
> > --
> > 2.45.2.1089.g2a221341d9-goog
> >


BR, Jarkko
diff mbox series

Patch

diff --git a/drivers/char/tpm/tpm_tis_i2c_cr50.c b/drivers/char/tpm/tpm_tis_i2c_cr50.c
index adf22992138e..b50005ccfc5e 100644
--- a/drivers/char/tpm/tpm_tis_i2c_cr50.c
+++ b/drivers/char/tpm/tpm_tis_i2c_cr50.c
@@ -31,7 +31,8 @@ 
 #define TPM_CR50_TIMEOUT_SHORT_MS	2		/* Short timeout during transactions */
 #define TPM_CR50_TIMEOUT_NOIRQ_MS	20		/* Timeout for TPM ready without IRQ */
 #define TPM_CR50_I2C_DID_VID		0x00281ae0L	/* Device and vendor ID reg value */
-#define TPM_TI50_I2C_DID_VID		0x504a6666L	/* Device and vendor ID reg value */
+#define TPM_TI50_DT_I2C_DID_VID		0x504a6666L	/* Device and vendor ID reg value */
+#define TPM_TI50_OT_I2C_DID_VID		0x50666666L	/* Device and vendor ID reg value */
 #define TPM_CR50_I2C_MAX_RETRIES	3		/* Max retries due to I2C errors */
 #define TPM_CR50_I2C_RETRY_DELAY_LO	55		/* Min usecs between retries on I2C */
 #define TPM_CR50_I2C_RETRY_DELAY_HI	65		/* Max usecs between retries on I2C */
@@ -741,14 +742,18 @@  static int tpm_cr50_i2c_probe(struct i2c_client *client)
 	}
 
 	vendor = le32_to_cpup((__le32 *)buf);
-	if (vendor != TPM_CR50_I2C_DID_VID && vendor != TPM_TI50_I2C_DID_VID) {
+	if (vendor != TPM_CR50_I2C_DID_VID &&
+	    vendor != TPM_TI50_DT_I2C_DID_VID &&
+	    vendor != TPM_TI50_OT_I2C_DID_VID) {
 		dev_err(dev, "Vendor ID did not match! ID was %08x\n", vendor);
 		tpm_cr50_release_locality(chip, true);
 		return -ENODEV;
 	}
 
 	dev_info(dev, "%s TPM 2.0 (i2c 0x%02x irq %d id 0x%x)\n",
-		 vendor == TPM_TI50_I2C_DID_VID ? "ti50" : "cr50",
+		 vendor == TPM_CR50_I2C_DID_VID    ? "cr50" :
+		 vendor == TPM_TI50_DT_I2C_DID_VID ? "ti50 DT" :
+						     "ti50 OT",
 		 client->addr, client->irq, vendor >> 16);
 	return tpm_chip_register(chip);
 }