| Message ID | 20190428202854.8590-11-jagan@amarulasolutions.com |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-amarula+bncBD7MFH7A7EEBBKU2TDTAKGQEWG6NSKI@amarulasolutions.com> X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 2191E3F08F for <linux-amarula@patchwork.amarulasolutions.com>; Sun, 28 Apr 2019 22:29:32 +0200 (CEST) Received: by mail-pf1-f200.google.com with SMTP id i23sf6144500pfa.0 for <linux-amarula@patchwork.amarulasolutions.com>; Sun, 28 Apr 2019 13:29:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1556483371; cv=pass; d=google.com; s=arc-20160816; b=QgzKb2yfsW8sY0hXSnJIxSHYOZzNO6imo7NZsKfQB/L1bH3dvN4ag902QEnFmHzq2V aqWwdwdUVSWAGsmPlyb43E91CY1TIozoENNO1FSng+oARMdSRWhxJ1FgVYDsSXilBcnv /BMCfh9xEiOpJpXOOgglWE628rKjBJJN+icWlEbZWj7UNN2FoWo128Ggh9sFNc90ktm3 oTjC2QiB4cYGyDD2Po4ocW8Ef8weyjipLN9+/Be05fg8NpWWT0Cl4iEyo9G7/43S8acr 7WMLg6loZh6Lylp8RD0QfmmWNUQB9iIxM54jTU8XOJZaNg3kZEWKLwZm3FSMs3+qJBl5 sS8Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=GfRvy++mcuM6fS9KVUgWjkhIL+ryW2q2XqRBfCVIqxc=; b=jqyoM/VYb5m8veYV5HfQZF5ZzFtQYrTzVc+geEWL/lUUlpYu3W5HZnIrs7WH7EWrIs gL+uZncWpXc7ZvHdHxVMBtctfpK3WXxtgOBu1qxtFjKKJBiLdZD3FDGX80pmGP1NAyty EA30q/i/8elVR+0+HH9cuSxsE2kem5dd+xNSMeaMpPHtvN3QM583/a0lWyn/gNrob20/ oQAKsExkfE8S4L2wK9IB5qWuJs17jxsHmwgpTg7j/YPTZwYTxpC+T6Q5Rfkm5mQ5QKh5 b406e8k1EinxQttD9IGIdkCouxRpUhFr69T3J3QdlkDgKNmjcrpOxbJ+j0LwRr3FTP+T 5znw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="VyJA/7wF"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=GfRvy++mcuM6fS9KVUgWjkhIL+ryW2q2XqRBfCVIqxc=; b=YEZkR9GiJ93ZUIewe0Sxvgu1eMN2IK59+hugYSWDmvSedDxttdpHKJ16VuQEUCTLO6 pLbuSViFmYrO2pFg7c188jwkl2IAfdDWYwvGvR4Amrzdd7NasxyKLfP+3sXXdXmFQqzd Rh28RXlpA9deQhWd3HLzvBma/rg3jiKLzo4R8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=GfRvy++mcuM6fS9KVUgWjkhIL+ryW2q2XqRBfCVIqxc=; b=Wpgfm4UJAo9N/7RugslZKzCCpxHcMMTgN1Gss+H7zzhfTAqad6aKhaKX6SFsf0Aq+t bybhYpZIN+on2Znztjvg31P7Ds7GOoHrSfGAIeoXAtIUO/JN7f+uUqYN3zFQ5jjGHUOm T3Y7Z+ViuRBIJxC4mt99El9vu2o4M0cg3UBsdq6Mtd/33nneoIrYZUg1q8lMzkTqF+g9 e9BXTlBdAC3/hLE4kCIRlHfwUkSnRbCfepEmPZKDUEJORk8/jKpDP8uAoKOahXaj2Bte s01w/AyddKzRWQw7R38rfpJYmkaEQG4eZ62RUHEQCa5fxSvWliVHzA1T8boGjvp9Tjh9 zD+A== X-Gm-Message-State: APjAAAVnYkJE5THVGhhjkumTFLFU4pA/GdvbHarbpYRPhpM279LEsagm DG5U5sJAJ9uhhLBlj79KAJEumebK X-Google-Smtp-Source: APXvYqyFoVaDjWFNzr4PqqhVp28KffoBy0AR1WlqTX9zULqArpfZBkGidky19QT2zQPZs9v5VxZjmg== X-Received: by 2002:a63:6cc7:: with SMTP id h190mr54298387pgc.350.1556483370926; Sun, 28 Apr 2019 13:29:30 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:54d:: with SMTP id 71ls766114plf.10.gmail; Sun, 28 Apr 2019 13:29:30 -0700 (PDT) X-Received: by 2002:a17:902:9a48:: with SMTP id x8mr11144186plv.133.1556483370572; Sun, 28 Apr 2019 13:29:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556483370; cv=none; d=google.com; s=arc-20160816; b=Rcc1ijWxkm9xas4rxJCcozjRn0rgwomtdbeyWkE3QHRrTOWfZFL285gBdVrasLHR1a ZvXdl83qUdHNWzBbyYXujbm6nD0Tsv5OyJv/dJKo0fSABmwQ3TeBkJ3TPgsPqWSVUqSb Ga8W3+egzW1xfB5CBL3sx2Q5x3AROdKu7fYsvdaoSFmS0srLNlOHkelJXmINHKGx/ek3 c3OUXuYt4OQ87yvDq6EahZOt02MKaVhEb7Yfwc445lm5tXekI69Vvy08rxG1WSo5p7fz ZTwZVzB7Mg0iF/V6gfdikvCEK4Tm9Pog6TPestRfUKh5qPN7R+i6v7QhuaGjM3uaFahE Cj6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=DTO6ewJO6LxtcHMlk6isa3AoPn6RhI6b3q543pvVwGE=; b=HlunoFB+UVUSwwRmgqDasezf+DhYUYi/7kVPTEiv/oN2e8uww3Q29Ei8VkR0lY8tOW 0M6RtVPxXXSQKOn2bNWSPorcXbVWlPxdsXCetJM+zAjd8ndRwiXWhbiC7OJgBodHOBYg KPqLN2CERRSIFKtTbnte4n59MWGbfRWHLMYDnXAHML3AbVHzRRQ7ZM7DgclUoRH2csKB nFv3+2lw77ar3/7Ehau1zxpEt/FXqn1yx1dhU5NsIAAanLP8TGb4U5bqo0bgNfzFAwry uZQdiUjlO2v5s1+gmmFWvjelH7s5qVVCYVLZ3m5Oymjh7qBo2hcYSllUtwvb8RQVNEQC /0PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="VyJA/7wF"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d12sor24369689pgk.19.2019.04.28.13.29.30 for <linux-amarula@amarulasolutions.com> (Google Transport Security); Sun, 28 Apr 2019 13:29:30 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a63:5b4d:: with SMTP id l13mr54842512pgm.160.1556483370258; Sun, 28 Apr 2019 13:29:30 -0700 (PDT) Received: from localhost.localdomain ([115.97.185.144]) by smtp.gmail.com with ESMTPSA id x66sm68841439pfb.78.2019.04.28.13.29.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Apr 2019 13:29:29 -0700 (PDT) From: Jagan Teki <jagan@amarulasolutions.com> To: Heiko Schocher <hs@denx.de>, Tom Rini <trini@konsulko.com> Cc: u-boot@lists.denx.de, linux-amarula@amarulasolutions.com, Mario Six <mario.six@gdsys.cc> Subject: [PATCH v2 10/19] spi: mpc8xxx: Simplify logic a bit Date: Mon, 29 Apr 2019 01:58:45 +0530 Message-Id: <20190428202854.8590-11-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190428202854.8590-1-jagan@amarulasolutions.com> References: <20190428202854.8590-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="VyJA/7wF"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: <linux-amarula.amarulasolutions.com> X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/post>, <mailto:linux-amarula@amarulasolutions.com> List-Help: <https://support.google.com/a/amarulasolutions.com/bin/topic.py?topic=25838>, <mailto:linux-amarula+help@amarulasolutions.com> List-Archive: <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/> List-Unsubscribe: <mailto:googlegroups-manage+476853432473+unsubscribe@googlegroups.com>, <https://groups.google.com/a/amarulasolutions.com/group/linux-amarula/subscribe> |
| Series |
[v2,01/19] spi: mpc8xxx: Use short type names
|
|
Commit Message
Jagan Teki
April 28, 2019, 8:28 p.m. UTC
From: Mario Six <mario.six@gdsys.cc> We do nothing in the loop if the "not empty" event was not detected. To simplify the logic, check if this is the case, and skip the execution of the loop early to reduce the nesting level and flag checking. Signed-off-by: Mario Six <mario.six@gdsys.cc> --- drivers/spi/mpc8xxx_spi.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
Comments
On Mon, 2019-04-29 at 01:58 +0530, Jagan Teki wrote: > > From: Mario Six <mario.six@gdsys.cc> > > We do nothing in the loop if the "not empty" event was not detected. To > simplify the logic, check if this is the case, and skip the execution of > the loop early to reduce the nesting level and flag checking. Looked at the driver to refresh memory and noticed: if (charSize == 32) { /* Advance output buffer by 32 bits */ din += 4; } which suggests that only 32 bit char will increase the din ptr so does other bitlens work for reading? Jocke > > Signed-off-by: Mario Six <mario.six@gdsys.cc> > --- > drivers/spi/mpc8xxx_spi.c | 23 +++++++++++++---------- > 1 file changed, 13 insertions(+), 10 deletions(-) > > diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c > index 962ef710f8..a2e698ea17 100644 > --- a/drivers/spi/mpc8xxx_spi.c > +++ b/drivers/spi/mpc8xxx_spi.c > @@ -149,25 +149,28 @@ int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din, > bool have_ne = event & SPI_EV_NE; > bool have_nf = event & SPI_EV_NF; > > - if (have_ne) { > - tmpdin = in_be32(&spi->rx); > - setbits_be32(&spi->event, SPI_EV_NE); > - > - *(u32 *)din = (tmpdin << (32 - char_size)); > - if (char_size == 32) { > - /* Advance output buffer by 32 bits */ > - din += 4; > - } > + if (!have_ne) > + continue; > + > + tmpdin = in_be32(&spi->rx); > + setbits_be32(&spi->event, SPI_EV_NE); > + > + *(u32 *)din = (tmpdin << (32 - char_size)); > + if (char_size == 32) { > + /* Advance output buffer by 32 bits */ > + din += 4; > } > + > /* > * Only bail when we've had both NE and NF events. > * This will cause timeouts on RO devices, so maybe > * in the future put an arbitrary delay after writing > * the device. Arbitrary delays suck, though... > */ > - if (have_ne && have_nf) > + if (have_nf) > break; > } > + > if (tm >= SPI_TIMEOUT) > debug("*** %s: Time out during SPI transfer\n", > __func__); > -- > 2.18.0.321.gffc6fa0e3 > > _______________________________________________ > U-Boot mailing list > U-Boot@lists.denx.de > https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.denx.de%2Flistinfo%2Fu-boot&data=02%7C01%7Cjoakim.tjernlund%40infinera.com%7Cb423ca475f53471860b308d6cc195be8%7C285643de5f5b4b03a1530ae2dc8aaf77%7C1%7C0%7C636920806635383891&sdata=PxiqErmkjcpBVL4yBUi2UYiJ5oqtBTI4fCnb4XBTpmE%3D&reserved=0
+ Mario On Mon, Apr 29, 2019 at 2:48 PM Joakim Tjernlund <Joakim.Tjernlund@infinera.com> wrote: > > On Mon, 2019-04-29 at 01:58 +0530, Jagan Teki wrote: > > > > From: Mario Six <mario.six@gdsys.cc> > > > > We do nothing in the loop if the "not empty" event was not detected. To > > simplify the logic, check if this is the case, and skip the execution of > > the loop early to reduce the nesting level and flag checking. > > Looked at the driver to refresh memory and noticed: > if (charSize == 32) { > /* Advance output buffer by 32 bits */ > din += 4; > } > which suggests that only 32 bit char will increase the din ptr so does other bitlens > work for reading? Mario, can you respond this?
Hi Jagan and Jocke, I'm back from vacation, so here's my answer: On Mon, Apr 29, 2019 at 12:41 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > + Mario > > On Mon, Apr 29, 2019 at 2:48 PM Joakim Tjernlund > <Joakim.Tjernlund@infinera.com> wrote: > > > > On Mon, 2019-04-29 at 01:58 +0530, Jagan Teki wrote: > > > > > > From: Mario Six <mario.six@gdsys.cc> > > > > > > We do nothing in the loop if the "not empty" event was not detected. To > > > simplify the logic, check if this is the case, and skip the execution of > > > the loop early to reduce the nesting level and flag checking. > > > > Looked at the driver to refresh memory and noticed: > > if (charSize == 32) { > > /* Advance output buffer by 32 bits */ > > din += 4; > > } > > which suggests that only 32 bit char will increase the din ptr so does other bitlens > > work for reading? > Yes, It will work. When charSize < 32 in a loop execution, we necessarily also have numBlks == 0, since numBlks = DIV_ROUND_UP(bitlen, 32) and charSize = (bitlen >= 32 ? 32 : bitlen); in other words: we're at the very end of the data to be sent/received and also the final loop execution, so we don't have to advance the pointer anymore. > Mario, can you respond this? Best regards, Mario
On Thu, 2019-05-02 at 07:31 +0200, Mario Six wrote: > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. > > > Hi Jagan and Jocke, > > I'm back from vacation, so here's my answer: > > On Mon, Apr 29, 2019 at 12:41 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > + Mario > > > > On Mon, Apr 29, 2019 at 2:48 PM Joakim Tjernlund > > <Joakim.Tjernlund@infinera.com> wrote: > > > On Mon, 2019-04-29 at 01:58 +0530, Jagan Teki wrote: > > > > From: Mario Six <mario.six@gdsys.cc> > > > > > > > > We do nothing in the loop if the "not empty" event was not detected. To > > > > simplify the logic, check if this is the case, and skip the execution of > > > > the loop early to reduce the nesting level and flag checking. > > > > > > Looked at the driver to refresh memory and noticed: > > > if (charSize == 32) { > > > /* Advance output buffer by 32 bits */ > > > din += 4; > > > } > > > which suggests that only 32 bit char will increase the din ptr so does other bitlens > > > work for reading? > Yes, It will work. When charSize < 32 in a loop execution, we necessarily also > have numBlks == 0, since numBlks = DIV_ROUND_UP(bitlen, 32) and charSize = > (bitlen >= 32 ? 32 : bitlen); in other words: we're at the very end of the data > to be sent/received and also the final loop execution, so we don't have to > advance the pointer anymore. Ahh, I see now. But this over use of always 32 bits cause complexity/subtile bugs. The driver should use the requested charsize(wordlen) throughout. As is now you cannot use the NF/NE flag as intended or toggle LSB_FIRST I think fsl_espi driver is worse though. Jocke
On Thu, May 2, 2019 at 2:37 PM Joakim Tjernlund <Joakim.Tjernlund@infinera.com> wrote: > > On Thu, 2019-05-02 at 07:31 +0200, Mario Six wrote: > > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. > > > > > > Hi Jagan and Jocke, > > > > I'm back from vacation, so here's my answer: > > > > On Mon, Apr 29, 2019 at 12:41 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > > + Mario > > > > > > On Mon, Apr 29, 2019 at 2:48 PM Joakim Tjernlund > > > <Joakim.Tjernlund@infinera.com> wrote: > > > > On Mon, 2019-04-29 at 01:58 +0530, Jagan Teki wrote: > > > > > From: Mario Six <mario.six@gdsys.cc> > > > > > > > > > > We do nothing in the loop if the "not empty" event was not detected. To > > > > > simplify the logic, check if this is the case, and skip the execution of > > > > > the loop early to reduce the nesting level and flag checking. > > > > > > > > Looked at the driver to refresh memory and noticed: > > > > if (charSize == 32) { > > > > /* Advance output buffer by 32 bits */ > > > > din += 4; > > > > } > > > > which suggests that only 32 bit char will increase the din ptr so does other bitlens > > > > work for reading? > > Yes, It will work. When charSize < 32 in a loop execution, we necessarily also > > have numBlks == 0, since numBlks = DIV_ROUND_UP(bitlen, 32) and charSize = > > (bitlen >= 32 ? 32 : bitlen); in other words: we're at the very end of the data > > to be sent/received and also the final loop execution, so we don't have to > > advance the pointer anymore. > > Ahh, I see now. > > But this over use of always 32 bits cause complexity/subtile bugs. The driver should use > the requested charsize(wordlen) throughout. As is now you cannot use the NF/NE flag as intended or > toggle LSB_FIRST Look like Joakim has a point here. better we can check the required charsize instead of looking for magic 32 number. What do you say Mario?
On Tue, May 14, 2019 at 3:53 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > On Thu, May 2, 2019 at 2:37 PM Joakim Tjernlund > <Joakim.Tjernlund@infinera.com> wrote: > > > > On Thu, 2019-05-02 at 07:31 +0200, Mario Six wrote: > > > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. > > > > > > > > > Hi Jagan and Jocke, > > > > > > I'm back from vacation, so here's my answer: > > > > > > On Mon, Apr 29, 2019 at 12:41 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > > > + Mario > > > > > > > > On Mon, Apr 29, 2019 at 2:48 PM Joakim Tjernlund > > > > <Joakim.Tjernlund@infinera.com> wrote: > > > > > On Mon, 2019-04-29 at 01:58 +0530, Jagan Teki wrote: > > > > > > From: Mario Six <mario.six@gdsys.cc> > > > > > > > > > > > > We do nothing in the loop if the "not empty" event was not detected. To > > > > > > simplify the logic, check if this is the case, and skip the execution of > > > > > > the loop early to reduce the nesting level and flag checking. > > > > > > > > > > Looked at the driver to refresh memory and noticed: > > > > > if (charSize == 32) { > > > > > /* Advance output buffer by 32 bits */ > > > > > din += 4; > > > > > } > > > > > which suggests that only 32 bit char will increase the din ptr so does other bitlens > > > > > work for reading? > > > Yes, It will work. When charSize < 32 in a loop execution, we necessarily also > > > have numBlks == 0, since numBlks = DIV_ROUND_UP(bitlen, 32) and charSize = > > > (bitlen >= 32 ? 32 : bitlen); in other words: we're at the very end of the data > > > to be sent/received and also the final loop execution, so we don't have to > > > advance the pointer anymore. > > > > Ahh, I see now. > > > > But this over use of always 32 bits cause complexity/subtile bugs. The driver should use > > the requested charsize(wordlen) throughout. As is now you cannot use the NF/NE flag as intended or > > toggle LSB_FIRST > > Look like Joakim has a point here. better we can check the required > charsize instead of looking for magic 32 number. What do you say > Mario? I agree, the driver code could be made more readable and cleaned up a bit, but I don't know if it's worth postponing this series for a code readability issue that's not a functional bug; I'd say that's an optimization that could be made later on. What do you guys think? Best regards, Mario
On Wed, 2019-05-15 at 07:02 +0200, Mario Six wrote: > On Tue, May 14, 2019 at 3:53 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > On Thu, May 2, 2019 at 2:37 PM Joakim Tjernlund > > <Joakim.Tjernlund@infinera.com> wrote: > > > On Thu, 2019-05-02 at 07:31 +0200, Mario Six wrote: > > > > CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. > > > > > > > > > > > > Hi Jagan and Jocke, > > > > > > > > I'm back from vacation, so here's my answer: > > > > > > > > On Mon, Apr 29, 2019 at 12:41 PM Jagan Teki <jagan@amarulasolutions.com> wrote: > > > > > + Mario > > > > > > > > > > On Mon, Apr 29, 2019 at 2:48 PM Joakim Tjernlund > > > > > <Joakim.Tjernlund@infinera.com> wrote: > > > > > > On Mon, 2019-04-29 at 01:58 +0530, Jagan Teki wrote: > > > > > > > From: Mario Six <mario.six@gdsys.cc> > > > > > > > > > > > > > > We do nothing in the loop if the "not empty" event was not detected. To > > > > > > > simplify the logic, check if this is the case, and skip the execution of > > > > > > > the loop early to reduce the nesting level and flag checking. > > > > > > > > > > > > Looked at the driver to refresh memory and noticed: > > > > > > if (charSize == 32) { > > > > > > /* Advance output buffer by 32 bits */ > > > > > > din += 4; > > > > > > } > > > > > > which suggests that only 32 bit char will increase the din ptr so does other bitlens > > > > > > work for reading? > > > > Yes, It will work. When charSize < 32 in a loop execution, we necessarily also > > > > have numBlks == 0, since numBlks = DIV_ROUND_UP(bitlen, 32) and charSize = > > > > (bitlen >= 32 ? 32 : bitlen); in other words: we're at the very end of the data > > > > to be sent/received and also the final loop execution, so we don't have to > > > > advance the pointer anymore. > > > > > > Ahh, I see now. > > > > > > But this over use of always 32 bits cause complexity/subtile bugs. The driver should use > > > the requested charsize(wordlen) throughout. As is now you cannot use the NF/NE flag as intended or > > > toggle LSB_FIRST > > > > Look like Joakim has a point here. better we can check the required > > charsize instead of looking for magic 32 number. What do you say > > Mario? > > I agree, the driver code could be made more readable and cleaned up a bit, but > I don't know if it's worth postponing this series for a code readability issue > that's not a functional bug; I'd say that's an optimization that could be made > later on. I would not call it just an optimization but I am fine with applying this patch. Jocke
diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c index 962ef710f8..a2e698ea17 100644 --- a/drivers/spi/mpc8xxx_spi.c +++ b/drivers/spi/mpc8xxx_spi.c @@ -149,25 +149,28 @@ int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din, bool have_ne = event & SPI_EV_NE; bool have_nf = event & SPI_EV_NF; - if (have_ne) { - tmpdin = in_be32(&spi->rx); - setbits_be32(&spi->event, SPI_EV_NE); - - *(u32 *)din = (tmpdin << (32 - char_size)); - if (char_size == 32) { - /* Advance output buffer by 32 bits */ - din += 4; - } + if (!have_ne) + continue; + + tmpdin = in_be32(&spi->rx); + setbits_be32(&spi->event, SPI_EV_NE); + + *(u32 *)din = (tmpdin << (32 - char_size)); + if (char_size == 32) { + /* Advance output buffer by 32 bits */ + din += 4; } + /* * Only bail when we've had both NE and NF events. * This will cause timeouts on RO devices, so maybe * in the future put an arbitrary delay after writing * the device. Arbitrary delays suck, though... */ - if (have_ne && have_nf) + if (have_nf) break; } + if (tm >= SPI_TIMEOUT) debug("*** %s: Time out during SPI transfer\n", __func__);