Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wang Yang" <yang.wang@deepcomputing.io>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 3/9] bus: Add SpacemiT K3 eSPI controller support
Date: Wed, 18 Nov 2026 09:23:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-220546@kernel.org> (raw)
In-Reply-To: <20261118085742.1817536-4-yang.wang@deepcomputing.io>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] bus: spacemit-k3-espi: boolean DT properties always evaluate
  to true
- [Medium] bus: spacemit-k3-espi: status clear race and error masking in
  poll
- [Medium] bus: spacemit-k3-espi: sclk rate set on wrong clock before
  negotiation
--

commit 725541204887e2363d68e7147b0b1af23aa4f9a3
Author: Wang Yang <yang.wang@deepcomputing.io>

bus: Add SpacemiT K3 eSPI controller support

This commit adds a bus driver for the SpacemiT K3 eSPI controller to
handle clock and reset management, channel configuration, and link
recovery for child devices.

> diff --git a/drivers/bus/spacemit-k3-espi.c b/drivers/bus/spacemit-k3-espi.c
> new file mode 100644
> index 0000000000000..b511b164b3cfc
> --- /dev/null
> +++ b/drivers/bus/spacemit-k3-espi.c

[ ... ]

> +static bool spacemit_espi_property_enabled(struct device_node *np,
> +					   const char *name, bool default_value)
> +{
> +	if (of_find_property(np, name, NULL))
> +		return of_property_read_bool(np, name);
> +
> +	return default_value;
> +}

[Severity: Medium]
Can spacemit_espi_property_enabled() ever return false when default_value
is true?

of_property_read_bool() tests whether the property exists via
of_find_property(), so it always returns true once the if condition passes.
Because spacemit_espi_parse_dt() passes default_value = true for all six
boolean properties (crc-enable, peripheral-channel-enable,
vwire-channel-enable, oob-channel-enable, flash-channel-enable, and
auto-gating-enable), all six flags evaluate to true whether the properties
are present in the Device Tree or omitted, making it impossible for a board
DT to disable any of these features or channels.

[ ... ]

> +static int spacemit_espi_poll_status(struct spacemit_espi *espi, u32 expected)
> +{
> +	unsigned int timeout = ESPI_CFG_TIMEOUT_US / 10;
> +	u32 status;
> +
> +	writel(expected, espi->regs + ESPI_SLAVE0_INT_STS);
> +
> +	do {
> +		status = readl(espi->regs + ESPI_SLAVE0_INT_STS);
> +		if (!status) {
> +			fsleep(10);
> +			continue;
> +		}
> +
> +		writel(status, espi->regs + ESPI_SLAVE0_INT_STS);
> +
> +		if (status & expected)
> +			return 0;
> +
> +		if (status & (ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT))
> +			return -EIO;
> +
> +		fsleep(10);
> +	} while (--timeout);
> +
> +	return -ETIMEDOUT;
> +}
> +
> +static int spacemit_espi_cmd_get_config(struct spacemit_espi *espi, u16 addr, u32 *value)
> +{
> +	int ret;
> +
> +	spacemit_espi_write_hdr(espi, 0, 0);
> +	spacemit_espi_write_hdr(espi, 1, addr >> 8);
> +	spacemit_espi_write_hdr(espi, 2, addr);
> +	spacemit_espi_trigger_cmd(espi, ESPI_DNCMD_GET_CONFIGURATION);
> +
> +	ret = spacemit_espi_poll_status(espi, ESPI_DNCMD_INT);

[Severity: Medium]
Does clearing expected in ESPI_SLAVE0_INT_STS inside
spacemit_espi_poll_status() race with command completion after
spacemit_espi_trigger_cmd() has already started the hardware transfer?

A short GET_CONFIGURATION or SET_CONFIGURATION transfer can finish and set
ESPI_DNCMD_INT before spacemit_espi_poll_status() executes its initial
write-1-to-clear writel(), wiping out the completion bit and causing a
50 ms -ETIMEDOUT failure.

In addition, spacemit_espi_send_inband_reset() does not clear
ESPI_SLAVE0_INT_STS after ESPI_DNCMD_IN_BAND_RESET, and
spacemit_espi_poll_status() only clears expected before the loop, leaving
any stale error bits pending.  Inside the loop, checking status & expected
before status & (ESPI_PROTOCOL_INT | ESPI_RESPONSE_INT) also masks bus or
protocol errors whenever ESPI_DNCMD_INT asserts alongside an error bit,
allowing spacemit_espi_cmd_get_config() to read invalid response bytes.

[ ... ]

> +static int spacemit_espi_init_locked(struct spacemit_espi *espi)
> +{
> +	u32 slave_caps = 0;
> +	u32 cfg;
> +	int ret;

[ ... ]

> +	if (espi->sclk && !IS_ERR(espi->sclk) && espi->op_freq_mhz) {
> +		ret = clk_set_rate(espi->sclk, espi->op_freq_mhz * 1000000UL);
> +		if (ret)
> +			dev_dbg(espi->dev, "failed to set sclk rate: %d\n", ret);
> +	}

[Severity: Medium]
Does calling clk_set_rate() on espi->sclk before capability negotiation
actually configure the K3 eSPI serial clock frequency?

In the K3 clock controller, espi_sclk_src owns the 20/25/33/50/66 MHz
parent mux while espi_sclk is defined without CLK_SET_RATE_PARENT:

drivers/clk/spacemit/ccu-k3.c:
    static const struct clk_parent_data espi_sclk_src_parents[] = {
    	CCU_PARENT_HW(pll2_20),
    	CCU_PARENT_HW(pll2_25),
    	CCU_PARENT_HW(pll2_33),
    	CCU_PARENT_HW(pll2_50),
    	CCU_PARENT_HW(pll2_66),
    };
    CCU_MUX_DEFINE(espi_sclk_src, espi_sclk_src_parents, APMU_ESPI_CLK_RES_CTRL, 4, 3, 0);

    static const struct clk_parent_data espi_sclk_parents[] = {
    	CCU_PARENT_NAME(external_clk),
    	CCU_PARENT_HW(espi_sclk_src),
    };
    CCU_MUX_GATE_DEFINE(espi_sclk, espi_sclk_parents, APMU_ESPI_CLK_RES_CTRL, 7, 1, BIT(3), 0);

Because spacemit_espi_probe() only acquires "sclk" and never "sclk_src",
clk_set_rate(espi->sclk, ...) only evaluates the current rate of its
immediate parents and never switches espi_sclk_src to the requested divider.
Furthermore, setting the clock rate to espi->op_freq_mhz before in-band
reset and spacemit_espi_build_negotiated_config() leaves the serial clock
unaligned with ESPI_SLAVE0_CONFIG and ESPI_SLAVE_GEN_CFG if the slave
negotiates a lower operating frequency.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118085742.1817536-1-yang.wang@deepcomputing.io?part=3

  reply	other threads:[~2026-11-18  9:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  8:57 [PATCH 0/9] Add SpacemiT K3 FML13V05 EC keyboard support Wang Yang
2026-11-18  8:57 ` [PATCH 1/9] dt-bindings: bus: Add SpacemiT K3 eSPI controller Wang Yang
2026-11-18  9:18   ` sashiko-bot
2026-11-18  8:57 ` [PATCH 2/9] dt-bindings: embedded-controller: Add SpacemiT K3 EC window Wang Yang
2026-11-18  8:57 ` [PATCH 3/9] bus: Add SpacemiT K3 eSPI controller support Wang Yang
2026-11-18  9:23   ` sashiko-bot [this message]
2026-11-18  8:57 ` [PATCH 4/9] platform/chrome: Allow ChromeOS platform support on RISC-V Wang Yang
2026-11-18  8:57 ` [PATCH 5/9] platform/chrome: Add SpacemiT K3 eSPI EC transport Wang Yang
2026-11-18  8:57 ` [PATCH 6/9] riscv: dts: spacemit: Add K3 eSPI pin group Wang Yang
2026-11-18  9:08   ` sashiko-bot
2026-11-18  8:57 ` [PATCH 7/9] riscv: dts: spacemit: Describe the K3 eSPI controller Wang Yang
2026-11-18  8:57 ` [PATCH 8/9] riscv: dts: spacemit: Enable the FML13V05 EC keyboard Wang Yang
2026-11-18  9:20   ` sashiko-bot
2026-11-18  8:57 ` [PATCH 9/9] riscv: defconfig: Enable the FML13V05 EC keyboard modules Wang Yang

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=sashiko-outbox-220546@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yang.wang@deepcomputing.io \
    /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