On Mon, Aug 12, 2019 at 03:36:18PM -0700, Stephen Boyd wrote: > Cr50 firmware has a different flow control protocol than the one used by > this TPM PTP SPI driver. Introduce a flow control callback so we can > override the standard sequence with the custom one that Cr50 uses. > > Cc: Andrey Pronin <apronin@xxxxxxxxxxxx> > Cc: Duncan Laurie <dlaurie@xxxxxxxxxxxx> > Cc: Jason Gunthorpe <jgg@xxxxxxxx> > Cc: Arnd Bergmann <arnd@xxxxxxxx> > Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> > Cc: Guenter Roeck <groeck@xxxxxxxxxxxx> > Cc: Alexander Steffen <Alexander.Steffen@xxxxxxxxxxxx> > Signed-off-by: Stephen Boyd <swboyd@xxxxxxxxxxxx> > --- > drivers/char/tpm/tpm_tis_spi.c | 55 +++++++++++++++++++++------------- > 1 file changed, 34 insertions(+), 21 deletions(-) > > diff --git a/drivers/char/tpm/tpm_tis_spi.c b/drivers/char/tpm/tpm_tis_spi.c > index 19513e622053..819602e85b34 100644 > --- a/drivers/char/tpm/tpm_tis_spi.c > +++ b/drivers/char/tpm/tpm_tis_spi.c > @@ -42,6 +42,8 @@ > struct tpm_tis_spi_phy { > struct tpm_tis_data priv; > struct spi_device *spi_device; > + int (*flow_control)(struct tpm_tis_spi_phy *phy, > + struct spi_transfer *xfer); > u8 *iobuf; > }; > > @@ -50,12 +52,39 @@ static inline struct tpm_tis_spi_phy *to_tpm_tis_spi_phy(struct tpm_tis_data *da > return container_of(data, struct tpm_tis_spi_phy, priv); > } > > +static int tpm_tis_spi_flow_control(struct tpm_tis_spi_phy *phy, > + struct spi_transfer *spi_xfer) > +{ > + struct spi_message m; > + int ret, i; > + > + if ((phy->iobuf[3] & 0x01) == 0) { > + // handle SPI wait states > + phy->iobuf[0] = 0; > + > + for (i = 0; i < TPM_RETRY; i++) { > + spi_xfer->len = 1; > + spi_message_init(&m); > + spi_message_add_tail(spi_xfer, &m); > + ret = spi_sync_locked(phy->spi_device, &m); > + if (ret < 0) > + return ret; > + if (phy->iobuf[0] & 0x01) > + break; > + } > + > + if (i == TPM_RETRY) > + return -ETIMEDOUT; > + } > + > + return 0; > +} AFAIK the flow control is not part of the SPI standard itself but is proprietary for each slave device. Thus, the flow control should be documented to the source code. I do not want flow control mechanisms to be multiplied before this is done. The magic number 0x01 would be also good to get rid off. /Jarkko