Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alex Elder" <elder@riscstar.com>
Cc: devicetree@vger.kernel.org, linux-clk@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 2/2] clk: toshiba: introduce a TC9564 clock/reset driver
Date: Fri, 20 Nov 2026 18:42:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-225862@kernel.org> (raw)
In-Reply-To: <20261120183212.1264522-3-elder@riscstar.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] clk: tc9564: unlocked register read-modify-write in
  reset_manage()
- [Medium] clk: tc9564: missing select RESET_CONTROLLER in
  COMMON_CLK_TC9564
- [Low] clk: tc9564: stale v1 and dt-binding text in commit message
- [Low] clk: tc9564: duplicate clk_gate implementation in
  gate_register()
--

commit c8a057c6e9911108f130ae1447d0fae1c9ba8eff
Author: Alex Elder <elder@kernel.org>

clk: toshiba: introduce a TC9564 clock/reset driver

This commit adds a platform driver for the clock and reset controllers on
the Toshiba TC9564 SoC.

> Define a new platform driver that manages clocks implemented by the
> Toshiba TC9564 SoC.  There are 21 gate clocks that can be enabled
> and disabled, but currently only the clocks that are (or will soon
> be) used are defined to be controllable.
> 
> Two registers manage the state of the clocks.  The registers are
> accessed via a regmap supplied by a system controller.  Access to
> the memory region is provided via a BAR on a PCIe endpoint function
> embedded in the TC9564 SoC.
> 
> Define the binding for the clock and reset controller that present in
> the Toshiba TC9564 SoC.

[Severity: Low]
These first three paragraphs appear to be leftover text from v1 and the
devicetree binding patch: the driver now maps the platform MMIO resource
directly via devm_platform_ioremap_resource() instead of using a syscon
regmap, and the description restarts in the fourth paragraph.

> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index 6bfa2c8fffe1b..b27807ee93863 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -185,6 +185,14 @@ config COMMON_CLK_CDCE706
>  	help
>  	  This driver supports TI CDCE706 programmable 3-PLL clock synthesizer.
>  
> +config COMMON_CLK_TC9564
> +	tristate "Toshiba TC9564 clock and reset support"
> +	depends on TC9564_PCI || COMPILE_TEST
> +	default TC9564_PCI
> +	help
> +	  This enables support for the clock and reset controllers embedded
> +	  in the Toshiba TC9564 SoC.

[Severity: Medium]
Should COMMON_CLK_TC9564 select RESET_CONTROLLER?  Because TC9564 is a
PCIe endpoint device, this driver can be enabled on host architectures
that do not select ARCH_HAS_RESET_CONTROLLER.  When
CONFIG_RESET_CONTROLLER is disabled, devm_reset_controller_register()
compiles to a no-op stub returning 0, silently omitting the reset
controller functionality and causing non-optional reset consumers to fail
with -ENOTSUPP.

> diff --git a/drivers/clk/clk-tc9564.c b/drivers/clk/clk-tc9564.c
> new file mode 100644
> index 0000000000000..65ed524bf2ee7
> --- /dev/null
> +++ b/drivers/clk/clk-tc9564.c

[ ... ]

> +static const struct reset_init reset_init[] = {
> +	[RESET_I2C] = {
> +		.offset = RESET0_OFFSET,
> +		.mask = BIT(12),
> +	},
> +	[RESET_PCIE] = {
> +		.offset = RESET0_OFFSET,
> +		.mask = BIT(9),
> +	},
> +	[RESET_MSIGEN] = {
> +		.offset = RESET0_OFFSET,
> +		.mask = BIT(18),
> +	},
> +
> +	[RESET_MAC0_MAC] = {
> +		.offset = RESET0_OFFSET,
> +		.mask = BIT(7),
> +	},
> +	[RESET_MAC0_PMA] = {
> +		.offset = RESET0_OFFSET,
> +		.mask = BIT(30),
> +	},
> +	[RESET_MAC0_XPCS] = {
> +		.offset = RESET0_OFFSET,
> +		.mask = BIT(31),
> +	},
> +
> +	[RESET_MAC1_MAC] = {
> +		.offset = RESET1_OFFSET,
> +		.mask = BIT(7),
> +	},
> +	[RESET_MAC1_PMA] = {
> +		.offset = RESET1_OFFSET,
> +		.mask = BIT(30),
> +	},
> +	[RESET_MAC1_XPCS] = {
> +		.offset = RESET1_OFFSET,
> +		.mask = BIT(31),
> +	},
> +};
> +#define RESET_COUNT	ARRAY_SIZE(reset_init)

[ ... ]

> +static const struct gate_clock *hw_to_gate_clock(struct clk_hw *hw)
> +{
> +	return container_of_const(hw, struct gate_clock, hw);
> +}
> +
> +static int gate_clk_manage(struct clk_hw *hw, bool enable)
> +{
> +	struct tc9564_clock *tc9564_clock = dev_get_drvdata(clk_hw_get_dev(hw));
> +	const struct gate_clock *clock = hw_to_gate_clock(hw);
> +	u32 mask = clock->init->mask;
> +	void __iomem *ioaddr;
> +	u32 val;
> +
> +	ioaddr = tc9564_clock->ioaddr + clock->init->offset;
> +
> +	val = readl(ioaddr);
> +	if (enable)
> +		val |= mask;
> +	else
> +		val &= ~mask;
> +	writel(val, ioaddr);
> +
> +	return 0;
> +}
> +
> +static int gate_clk_enable(struct clk_hw *hw)
> +{
> +	return gate_clk_manage(hw, true);
> +}
> +
> +static void gate_clk_disable(struct clk_hw *hw)
> +{
> +	(void)gate_clk_manage(hw, false);
> +}
> +
> +static int gate_clk_is_enabled(struct clk_hw *hw)
> +{
> +	struct tc9564_clock *tc9564_clock = dev_get_drvdata(clk_hw_get_dev(hw));
> +	const struct gate_clock *clock = hw_to_gate_clock(hw);
> +	void __iomem *ioaddr;
> +
> +	ioaddr = tc9564_clock->ioaddr + clock->init->offset;
> +
> +	return readl(ioaddr) & clock->init->mask ? 1 : 0;
> +}
> +
> +static const struct clk_ops gate_clk_ops = {
> +	.enable = gate_clk_enable,
> +	.disable = gate_clk_disable,
> +	.is_enabled = gate_clk_is_enabled,
> +};
> +
> +static struct clk_hw *gate_register(struct device *dev, const char *name,
> +				    const struct clock_init *init)
> +{
> +	struct tc9564_clock *tc9564_clock = dev_get_drvdata(dev);
> +	struct clk_init_data clk_init = { };
> +	const struct clk_hw *parent_hw;
> +	struct gate_clock *clock;
> +	int ret;
> +
> +	clock = devm_kzalloc_obj(dev, *clock);
> +	if (!clock)
> +		return ERR_PTR(-ENOMEM);
> +
> +	parent_hw = tc9564_clock->clk_data->hws[init->parent];
> +
> +	clk_init.name = name;
> +	clk_init.ops = &gate_clk_ops;
> +	clk_init.parent_hws = &parent_hw;
> +	clk_init.num_parents = 1;
> +	if (init->type == CRITICAL_GATE)
> +		clk_init.flags = CLK_IS_CRITICAL;
> +
> +	clock->hw.init = &clk_init;
> +	clock->init = init;
> +
> +	ret = devm_clk_hw_register(dev, &clock->hw);
> +	if (ret)
> +		return ERR_PTR(ret);
> +
> +	return &clock->hw;
> +}

[Severity: Low]
This isn't a bug, but now that the driver accesses MMIO registers directly
rather than through regmap, gate_register() and gate_clk_ops duplicate the
standard single-bit MMIO gate implementation.  Using
devm_clk_hw_register_gate_parent_hw() (as pll_register() and
fixed_register() do with the fixed-factor helpers) would allow dropping
struct gate_clock and the custom gate callbacks.

> +
> +/* Warn on requests to assert or deassert critical resets */
> +static bool reset_is_critical(unsigned long id)
> +{
> +	return WARN_ON(id == RESET_I2C) || WARN_ON(id == RESET_PCIE);
> +}
> +
> +static int reset_manage(struct reset_controller_dev *rcdev,
> +			unsigned long id, bool assert)
> +{
> +	struct tc9564_clock *tc9564_clock = dev_get_drvdata(rcdev->dev);
> +	const struct reset_init *reset = &reset_init[id];
> +	u32 mask = reset->mask;
> +	void __iomem *ioaddr;
> +	u32 val;
> +
> +	if (reset_is_critical(id))
> +		return 0;		/* Just ignore the request */
> +
> +	ioaddr = tc9564_clock->ioaddr + reset->offset;
> +
> +	val = readl(ioaddr);
> +	if (assert)
> +		val |= mask;
> +	else
> +		val &= ~mask;
> +	writel(val, ioaddr);
> +
> +	return 0;
> +}

[Severity: Medium]
Can concurrent reset operations on lines sharing RESET0_OFFSET or
RESET1_OFFSET race in reset_manage()?

Unlike the clock framework (which holds enable_lock across enable and
disable callbacks), the reset controller core only acquires a
per-reset-control SRCU read lock in reset_control_assert() and
reset_control_deassert().  Two consumers asserting or deasserting
different resets in the same register (such as RESET_MSIGEN and
RESET_MAC0_MAC in RESET0_OFFSET) can perform concurrent read-modify-write
sequences and overwrite each other's bit changes.  A spinlock in struct
tc9564_clock around the readl()/writel() sequence in reset_manage() would
prevent this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120183212.1264522-1-elder@riscstar.com?part=2

      reply	other threads:[~2026-11-20 18:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 18:32 [PATCH v2 0/2] clk: tc9564: introduce a clock and reset driver Alex Elder
2026-11-20 18:32 ` [PATCH v2 1/2] dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml Alex Elder
2026-11-20 18:32 ` [PATCH v2 2/2] clk: toshiba: introduce a TC9564 clock/reset driver Alex Elder
2026-11-20 18:42   ` sashiko-bot [this message]

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-225862@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=elder@riscstar.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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