lkml.org 
[lkml]   [2023]   [Mar]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRE: [Patch V8 2/3] tpm_tis-spi: Add hardware wait polling
    Date
    > -----Original Message-----
    > From: Hillf Danton <hdanton@sina.com>
    > Sent: 19 March 2023 19:58
    > To: Krishna Yarlagadda <kyarlagadda@nvidia.com>
    > Cc: robh+dt@kernel.org; broonie@kernel.org; peterhuewe@gmx.de;
    > jgg@ziepe.ca; jarkko@kernel.org; krzysztof.kozlowski+dt@linaro.org; linux-
    > kernel@vger.kernel.org
    > Subject: Re: [Patch V8 2/3] tpm_tis-spi: Add hardware wait polling
    >
    > External email: Use caution opening links or attachments
    >
    >
    > On 2 Mar 2023 09:48:03 +0530 Krishna Yarlagadda <kyarlagadda@nvidia.com>
    > > +static int tpm_tis_spi_hw_flow_transfer(struct tpm_tis_data *data,
    > > + u32 addr, u16 len, u8 *in,
    > > + const u8 *out)
    > > +{
    > > + struct tpm_tis_spi_phy *phy = to_tpm_tis_spi_phy(data);
    > > + struct spi_transfer spi_xfer[3];
    > > + struct spi_message m;
    > > + u8 transfer_len;
    > > + int ret;
    > > +
    > > + while (len) {
    > > + transfer_len = min_t(u16, len, MAX_SPI_FRAMESIZE);
    > > +
    > > + spi_message_init(&m);
    > > + phy->iobuf[0] = (in ? 0x80 : 0) | (transfer_len - 1);
    > > + phy->iobuf[1] = 0xd4;
    > > + phy->iobuf[2] = addr >> 8;
    > > + phy->iobuf[3] = addr;
    > > +
    > > + memset(&spi_xfer, 0, sizeof(spi_xfer));
    > > +
    > > + spi_xfer[0].tx_buf = phy->iobuf;
    > > + spi_xfer[0].len = 1;
    > > + spi_message_add_tail(&spi_xfer[0], &m);
    > > +
    > > + spi_xfer[1].tx_buf = phy->iobuf + 1;
    > > + spi_xfer[1].len = 3;
    > > + spi_message_add_tail(&spi_xfer[1], &m);
    > > +
    > > + if (out) {
    > > + spi_xfer[2].tx_buf = &phy->iobuf[4];
    > > + spi_xfer[2].rx_buf = NULL;
    > > + memcpy(&phy->iobuf[4], out, transfer_len);
    > > + out += transfer_len;
    > > + }
    > > +
    > > + if (in) {
    > > + spi_xfer[2].tx_buf = NULL;
    > > + spi_xfer[2].rx_buf = &phy->iobuf[4];
    > > + }
    > > +
    > > + spi_xfer[2].len = transfer_len;
    > > + spi_message_add_tail(&spi_xfer[2], &m);
    > > +
    > > + reinit_completion(&phy->ready);
    >
    > What breaks without reinit? Or what sense made by init-ing it again?
    When length is over frame size, this loop will run for more than
    one iterations. Reinit to start transfer again.
    KY
    > > +
    > > + ret = spi_sync_locked(phy->spi_device, &m);
    > > + if (ret < 0)
    > > + return ret;
    > > +
    > > + if (in) {
    > > + memcpy(in, &phy->iobuf[4], transfer_len);
    > > + in += transfer_len;
    > > + }
    > > +
    > > + len -= transfer_len;
    > > + }
    > > +
    > > + return ret;
    > > +}

    \
     
     \ /
      Last update: 2023-03-27 01:14    [W:3.535 / U:0.724 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site