Re: [PATCH v3 2/3] clk: toshiba: introduce a TC9564 clock/reset driver

From: Alex Elder

Date: Fri Nov 27 2026 - 14:21:11 EST


On 11/26/26 3:55 AM, Lorenzo Bianconi wrote:
On Nov 25, Alex Elder wrote:
Define a new platform driver that manages clocks and resets 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. There are also 13 resets that can
be asserted or deasserted, but support for some of these is omitted as
well.

Two registers manage the state of the clocks, and two others manage
the state of the resets. All four registers are found in a region
mapped for MMIO. The region is provided via a BAR on one of the PCI
functions embedded in the TC9564 SoC.

The I2C and PCIE clocks and resets are treated as CRITICAL, meaning their
state should never be changed (and a warning is issued if changing their
state is attempted).

Co-developed-by: Daniel Thompson <daniel@xxxxxxxxxxxx>
Signed-off-by: Daniel Thompson <daniel@xxxxxxxxxxxx>
Signed-off-by: Alex Elder <elder@xxxxxxxxxxxx>
---
v3: - Fixed problems/garbage in the patch header
- The Kconfig option now depends on RESET_CONTROLLER, and can now
be enabled if COMPILE_TEST is enabled
- The generic gate clock controller code is now used rather than
implementing a custom one
- The PLL and internal fixed clocks IDs are no longer available
outside "clk-tc9564.c"
- The PLL is initialialized, followed by all fixed rate clocks,
followed by the gate clocks, to ensure each clock's parent is
initialized before the clock is
- Updating the reset registers (read/modify/write) is now protected
by a spinlock
- "Unnecessary newlines" have been removed

. . .

+struct tc9564_clock {
+ void __iomem *ioaddr; /* Mapped clock/reset registers */
+ spinlock_t lock; /* Protects reset register updates */
+ struct clk_hw_onecell_data *clk_data;

I think it would be more readable to have 3 different pointers here:
- struct clk_hw_onecell_data *clk_pll_data;
- struct clk_hw_onecell_data *clk_fixed_rate_data;
- struct clk_hw_onecell_data *clk_gate_data;

(using the same logic you implemented for fixed_init, gate_init stucts).

Doing so, I guess the code that is allocating the clock data would be
easier to manage.

I don't know that it's easier but it would avoid keeping
track of the difference between array indexes and identifiers.
I think I was trying to avoid registering three different
providers, but I think you're right, the result will be
simpler and more readable.

The PLL is a single clock, so it will be more like:

struct clk_hw *pll_hw;

So I will implement your suggestion.


+ struct reset_controller_dev rcdev;
+};
+
+/* Indexes into the fixed_init[] array */
+enum fixed_clock {
+ CLOCK_62_5M,
+ CLOCK_125M,
+ CLOCK_250M,
+ CLOCK_312_5M,
+};

. . .

+/* Caller must free the returned pointer if non-null */
+static const char *clock_name(struct device *dev, const char *name)
+{
+ return kasprintf(GFP_KERNEL, "%s-%s", dev_name(dev), name);
+}

nit: clock_name() is running just during probe, I would prefer to use
dev_kasprintf() instead and get rid of the related kfree(). Moreover,
clock_name() is just a wrapper around kasprintf(), do we really need it?

I think you mean devm_kasprintf(), but I still don't like keeping
that allocated memory around for every clock for the entire life
of the device. It's just a waste.

What I'll do, to get rid of what seems like a weird kfree() call,
*and* avoid having the allocated memory hang on longer than needed
is have all the callers do something like this:

const char *name __free(kfree) = clock_name(dev, "pll");

I do agree it's a simple wrapper but it's used in three places to
create a consistent name, so I prefer to keep it.

+/* Initialize the PLL (parent is the input oscillator); called from probe */
+static int pll_init(struct device *dev, struct tc9564_clock *clock)
+{
+ struct clk_hw *hw;
+ const char *name;
+
+ /* Initialize the PLL clock first (input oscillator is parent) */
+ name = clock_name(dev, "pll");
+ if (!name)
+ return -ENOMEM;
+
+ hw = devm_clk_hw_register_fixed_factor_index(dev, name, 0, 0, 50, 1);
+ kfree(name);
+ if (IS_ERR(hw))
+ return dev_err_probe(dev, PTR_ERR(hw),
+ "failed to register pll\n");
+
+ clock->clk_data->hws[CLOCK_PLL] = hw;
+
+ return 0;
+}
Thanks for the review.

-Alex