From: Andy Shevchenko <andy@kernel.org>
To: Binbin Zhou <zhoubb.aaron@gmail.com>
Cc: Binbin Zhou <zhoubinbin@loongson.cn>,
Wolfram Sang <wsa@kernel.org>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
linux-i2c@vger.kernel.org, loongarch@lists.linux.dev,
devicetree@vger.kernel.org, Huacai Chen <chenhuacai@loongson.cn>,
WANG Xuerui <kernel@xen0n.name>, Arnd Bergmann <arnd@arndb.de>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Jianmin Lv <lvjianmin@loongson.cn>
Subject: Re: [PATCH V7 3/4] i2c: ls2x: Add driver for Loongson-2K/LS7A I2C controller
Date: Tue, 20 Dec 2022 15:48:59 +0200 [thread overview]
Message-ID: <Y6G9S6i1EHyvB/EW@smile.fi.intel.com> (raw)
In-Reply-To: <CAMpQs4KcskSZdezVdNk9Q8UFYA3rFJm8CguiTRLdmffqkZ9FCg@mail.gmail.com>
On Tue, Dec 20, 2022 at 07:47:25PM +0800, Binbin Zhou wrote:
> On Mon, Dec 19, 2022 at 9:04 PM Andy Shevchenko <andy@kernel.org> wrote:
> > On Mon, Dec 19, 2022 at 08:28:33PM +0800, Binbin Zhou wrote:
...
> > > +static int ls2x_i2c_xfer_one(struct i2c_adapter *adap,
> > > + struct i2c_msg *msg, bool stop)
> > > +{
> > > + int ret;
> > > + bool is_read = msg->flags & I2C_M_RD;
> > > + struct ls2x_i2c_priv *priv = i2c_get_adapdata(adap);
> > > +
> > > + /* Contains steps to send start condition and address */
> > > + ret = ls2x_i2c_start(adap, msg);
> > > + if (!ret) {
> > > + if (is_read)
> > > + ret = ls2x_i2c_rx(adap, msg->buf, msg->len);
> > > + else
> > > + ret = ls2x_i2c_tx(adap, msg->buf, msg->len);
> >
> > > + if (!ret && stop)
> > > + ret = ls2x_i2c_stop(adap);
> >
> > So, we will send stop here...
> >
> > > + }
> >
> > > + if (ret == -ENXIO)
> > > + ls2x_i2c_stop(adap);
> >
> > ...and if it fails, we send it again here. Is it okay?
>
> First of all, I think the logic here is fine:
> In the first case, stop is called when the last msg is transmitted successfully;
> In the second case, stop is called when there is a NOACK during the
> transmission;
> In the third case, init is called when other errors occur during the
> transmission, such as TIMEOUT.
This is not obvious from the code above. Maybe the comment is missing, maybe as
you said the function should be amended and the code is refactored accordingly.
> The key point is that the current implementation of the stop function
> is probably imperfect, it directly ignores the NOACK. The more
> reasonable method would be to judge by LS2X_SR_BUSY(bus busy state).
> The basic idea: if the i2c bus is detected as idle within the timeout
> range of the stop command issued, the stop command is considered
> successful, otherwise -ETIMEDOUT is returned.
>
> As follows:
> static int ls2x_i2c_stop(struct i2c_adapter *adap)
> {
> - int ret = ls2x_i2c_send_byte(adap, LS2X_CR_STOP);
> + u8 value;
> + struct ls2x_i2c_priv *priv = i2c_get_adapdata(adap);
>
> - return (ret == -ENXIO) ? 0 : ret;
> + writeb(LS2X_CR_STOP, priv->base + I2C_LS2X_CR);
> + return readl_poll_timeout(priv->base + I2C_LS2X_SR,
> + value, !(value & LS2X_SR_BUSY),
> + 100, jiffies_to_usecs(adap->timeout));
> }
>
> Now, in the case you mentioned above, the last msg transmission is
> completed and the stop command is sent. If the stop command fails, it
> will only return -ETIMEDOUT and call ls2x_i2c_init().
>
> Of course, I will use tools like i2c-tools to do more tests.
>
> Thanks for the detailed review.
You're welcome!
> > > + else if (ret < 0)
> > > + ls2x_i2c_init(priv);
> > > +
> > > + return ret;
> > > +}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2022-12-20 13:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-19 12:28 [PATCH V7 0/4] i2c: ls2x: Add support for the Loongson-2K/LS7A I2C controller Binbin Zhou
2022-12-19 12:28 ` [PATCH V7 1/4] i2c: gpio: Add support on ACPI-based system Binbin Zhou
2022-12-19 12:28 ` [PATCH V7 2/4] dt-bindings: i2c: add Loongson LS2X I2C controller Binbin Zhou
2022-12-19 12:28 ` [PATCH V7 3/4] i2c: ls2x: Add driver for Loongson-2K/LS7A " Binbin Zhou
2022-12-19 13:04 ` Andy Shevchenko
2022-12-20 11:47 ` Binbin Zhou
2022-12-20 13:48 ` Andy Shevchenko [this message]
2022-12-19 12:29 ` [PATCH V7 4/4] LoongArch: Enable LS2X I2C in loongson3_defconfig Binbin Zhou
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=Y6G9S6i1EHyvB/EW@smile.fi.intel.com \
--to=andy@kernel.org \
--cc=arnd@arndb.de \
--cc=chenhuacai@loongson.cn \
--cc=devicetree@vger.kernel.org \
--cc=kernel@xen0n.name \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-i2c@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=lvjianmin@loongson.cn \
--cc=mika.westerberg@linux.intel.com \
--cc=robh+dt@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=wsa@kernel.org \
--cc=zhoubb.aaron@gmail.com \
--cc=zhoubinbin@loongson.cn \
/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