From: Mark Brown <broonie@kernel.org>
To: Chris Morgan <macroalpha82@gmail.com>
Cc: linux-spi@vger.kernel.org, robh+dt@kernel.org, heiko@sntech.de,
jbx6244@gmail.com, hjc@rock-chips.com,
yifeng.zhao@rock-chips.com, sugar.zhang@rock-chips.com,
linux-rockchip@lists.infradead.org,
linux-mtd@lists.infradead.org, p.yadav@ti.com,
Chris Morgan <macromorgan@hotmail.com>
Subject: Re: [PATCH v3 2/4] spi: rockchip-sfc: add rockchip serial flash controller driver
Date: Wed, 2 Jun 2021 17:03:57 +0100 [thread overview]
Message-ID: <20210602160357.GA4914@sirena.org.uk> (raw)
In-Reply-To: <20210601201021.4406-3-macroalpha82@gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 2716 bytes --]
On Tue, Jun 01, 2021 at 03:10:19PM -0500, Chris Morgan wrote:
This looks mostly good, a few mostly minor comments below:
> @@ -0,0 +1,861 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Rockchip Serial Flash Controller Driver
Please make the entire comment a C++ one to make things look more
intentional.
> +static int rockchip_sfc_get_if_type(const struct spi_mem_op *op,
> + struct rockchip_sfc *sfc)
> +{
> + if (op->data.buswidth == 2)
> + return IF_TYPE_DUAL;
> + else if (op->data.buswidth == 4)
> + return IF_TYPE_QUAD;
> + else if (op->data.buswidth == 1)
> + return IF_TYPE_STD;
> +
> + dev_err(sfc->dev, "unsupported SPI read mode\n");
> +
> + return -EINVAL;
> +}
This would be more idiomatically implemented as a switch statement.
> +static int rockchip_sfc_wait_fifo_ready(struct rockchip_sfc *sfc, int wr, u32 timeout)
> +{
> + unsigned long deadline = jiffies + timeout;
> + int level;
> +
> + while (!(level = rockchip_sfc_get_fifo_level(sfc, wr))) {
> + if (time_after_eq(jiffies, deadline)) {
> + dev_warn(sfc->dev, "%s fifo timeout\n", wr ? "write" : "read");
> + return -ETIMEDOUT;
> + }
> + udelay(1);
> + }
> +
> + return level;
The use of the assignment in the while conditional makes it hard to tell
if this code is doing what was intended.
> +static int rockchip_sfc_write_fifo(struct rockchip_sfc *sfc, const u8 *buf, int len)
> +{
> + u8 bytes = len & 0x3;
> + u32 dwords;
> + int tx_level;
> + u32 write_words;
> + u32 tmp = 0;
> +
> + dwords = len >> 2;
> + while (dwords) {
> + tx_level = rockchip_sfc_wait_fifo_ready(sfc, SFC_CMD_DIR_WR, HZ);
> + if (tx_level < 0)
> + return tx_level;
> + write_words = min_t(u32, tx_level, dwords);
> + iowrite32_rep(sfc->regbase + SFC_DATA, buf, write_words);
> + buf += write_words << 2;
> + dwords -= write_words;
> + }
Weird indentation on the } here.
> + /* write the rest non word aligned bytes */
> + if (bytes) {
> + tx_level = rockchip_sfc_wait_fifo_ready(sfc, SFC_CMD_DIR_WR, HZ);
It's not the source buffer being aligned that's the issue here, it's the
buffer not being a multiple of word size.
> +static irqreturn_t rockchip_sfc_irq_handler(int irq, void *dev_id)
> +{
> + struct rockchip_sfc *sfc = dev_id;
> + u32 reg;
> +
> + reg = readl(sfc->regbase + SFC_RISR);
> +
> + /* Clear interrupt */
> + writel_relaxed(reg, sfc->regbase + SFC_ICLR);
> +
> + if (reg & SFC_RISR_TRAN_FINISH)
> + complete(&sfc->cp);
> +
> + return IRQ_HANDLED;
> +}
This will silently clear any unknown interrupt, and silently claim to
have handled an interrupt even if none happened (eg, due to shared IRQs)
- it would be better to only ack interrupts we handle and return
IRQ_NONE if we didn't handle any.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 144 bytes --]
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2021-06-02 16:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-01 20:10 [PATCH v3 0/4] Add Rockchip SFC(serial flash controller) support Chris Morgan
2021-06-01 20:10 ` [PATCH v3 1/4] dt-bindings: rockchip-sfc: Bindings for Rockchip serial flash controller Chris Morgan
2021-06-02 8:13 ` Johan Jonker
2021-06-02 14:49 ` Chris Morgan
2021-06-01 20:10 ` [PATCH v3 2/4] spi: rockchip-sfc: add rockchip serial flash controller driver Chris Morgan
2021-06-02 16:03 ` Mark Brown [this message]
2021-06-01 20:10 ` [PATCH v3 3/4] arm64: dts: rockchip: Add SFC to PX30 Chris Morgan
2021-06-01 20:10 ` [PATCH v4 4/4] arm64: dts: rockchip: Enable SFC for Odroid Go Advance Chris Morgan
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=20210602160357.GA4914@sirena.org.uk \
--to=broonie@kernel.org \
--cc=heiko@sntech.de \
--cc=hjc@rock-chips.com \
--cc=jbx6244@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=macroalpha82@gmail.com \
--cc=macromorgan@hotmail.com \
--cc=p.yadav@ti.com \
--cc=robh+dt@kernel.org \
--cc=sugar.zhang@rock-chips.com \
--cc=yifeng.zhao@rock-chips.com \
/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