From: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
To: Alex Elder <elder@riscstar.com>
Cc: sboyd@kernel.org, bmasney+clk@redhat.com,
jbrunet+clk@baylibre.com, robh@kernel.org, krzk+dt@kernel.org,
conor+dt@kernel.org, p.zabel@pengutronix.de,
andersson@kernel.org, konradybcio@kernel.org,
abelvesa@kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org,
daniel@riscstar.com, mohd.anwar@oss.qualcomm.com,
fabrice.gasnier@foss.st.com, alexandre.torgue@foss.st.com,
marex@nabladev.com, changhuang.liang@starfivetech.com,
linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 3/4] clk: toshiba: introduce a TC9564 clock driver
Date: Fri, 4 Dec 2026 10:40:51 +0100 [thread overview]
Message-ID: <axKKo6AckJG9Wv0G@lore-desk> (raw)
In-Reply-To: <20261203200948.1595470-4-elder@riscstar.com>
[-- Attachment #1: Type: text/plain, Size: 14848 bytes --]
> 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. The I2C and PCIE clocks marked
> as CRITICAL to prevent their state from ever changing.
>
> Two registers in an MMIO region manage the state of the clocks. The
> region is provided via a BAR on one of the PCI functions embedded in
> the TC9564 SoC.
>
> This driver creates an auxiliary device responsible for managing the
> reset controller implemented within the SoC. Definitions found in
> <linux/soc/qcom/tc9563.h> specify the interface between this driver
> and the reset auxiliary driver.
>
> Co-developed-by: Daniel Thompson <daniel@riscstar.com>
> Signed-off-by: Daniel Thompson <daniel@riscstar.com>
> Signed-off-by: Alex Elder <elder@riscstar.com>
> ---
> v5: - There is now only one clk_hw_onecell_data structure tracking
> all clocks (and this is the only one used to add a clock
> hardware provider).
> - There is no longer a per-instance structure allocated for probed
> clock devices. All information needed during operation is either
> static or is set up during initialization.
> - Fixed rate clocks no longer have IDs. They are identified by
> their clock rate, which is unique (and based on a divider).
> - Gate clocks now specify the clock rate they need from their
> parent clock. The clk_hw pointer used in registeration is
> found based on that rate.
> - Initialization of the fixed and gate clocks are no longer
> encapsulated; instead, the probe function iterates over the
> clocks to be initialized, and a helper function for each type
> is called for each clock.
> - The reset device is now created using an auxiliary device
> helper function, avoiding duplicated code.
> - A few bits of dead code pointed out during review have been
> removed.
>
> MAINTAINERS | 1 +
> drivers/clk/Kconfig | 10 ++
> drivers/clk/Makefile | 1 +
> drivers/clk/clk-tc9564.c | 326 +++++++++++++++++++++++++++++++++++++++
> drivers/misc/Kconfig | 1 +
> 5 files changed, 339 insertions(+)
> create mode 100644 drivers/clk/clk-tc9564.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 936d60a27dd3c..c6f26f750a5dc 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -28798,6 +28798,7 @@ M: Alex Elder <elder@kernel.org>
> M: Daniel Thompson <danielt@kernel.org>
> S: Maintained
> F: Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml
> +F: drivers/clk/clk-tc9564.c
> F: include/dt-bindings/clock/toshiba,tc9564.h
>
> TOSHIBA TC9564 PCI DRIVER
> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index 97db129f184ec..da547851c7c2b 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -186,6 +186,16 @@ config COMMON_CLK_CDCE706
> help
> This driver supports TI CDCE706 programmable 3-PLL clock synthesizer.
>
> +config COMMON_CLK_TC9564
> + tristate "Toshiba TC9564 clock support"
> + select AUXILIARY_BUS
> + imply RESET_TC9564
> + help
> + This enables support for the clock controller embedded in the
> + Toshiba TC9564 SoC. It is also required to support the embedded
> + reset device, which is represented as an auxiliary device created
> + by the clock controller driver.
> +
> config COMMON_CLK_TPS68470
> tristate "Clock Driver for TI TPS68470 PMIC"
> depends on I2C
> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> index 99377a13ebc57..d67cfb6d623d3 100644
> --- a/drivers/clk/Makefile
> +++ b/drivers/clk/Makefile
> @@ -111,6 +111,7 @@ obj-$(CONFIG_COMMON_CLK_SI570) += clk-si570.o
> obj-$(CONFIG_COMMON_CLK_SP7021) += clk-sp7021.o
> obj-$(CONFIG_COMMON_CLK_STM32F) += clk-stm32f4.o
> obj-$(CONFIG_COMMON_CLK_STM32H7) += clk-stm32h7.o
> +obj-$(CONFIG_COMMON_CLK_TC9564) += clk-tc9564.o
> obj-$(CONFIG_COMMON_CLK_TPS68470) += clk-tps68470.o
> obj-$(CONFIG_CLK_TWL6040) += clk-twl6040.o
> obj-$(CONFIG_CLK_TWL) += clk-twl.o
> diff --git a/drivers/clk/clk-tc9564.c b/drivers/clk/clk-tc9564.c
> new file mode 100644
> index 0000000000000..fb429d2ffe039
> --- /dev/null
> +++ b/drivers/clk/clk-tc9564.c
> @@ -0,0 +1,326 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +/*
> + * Copyright (C) 2026 by RISCstar Solutions Corporation. All rights reserved.
> + */
> +
> +#include <linux/auxiliary_bus.h>
> +#include <linux/bits.h>
> +#include <linux/clk-provider.h>
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/slab.h>
> +#include <linux/soc/qcom/tc9563.h>
> +
> +#include <dt-bindings/clock/toshiba,tc9564.h>
> +
> +/*
> + * Two registers implement the bits that control whether our clocks are
> + * enabled. These offsets are relative to the address space defined in
> + * devicetree.
> + */
> +#define CLOCK0_OFFSET 0x0
> +#define CLOCK1_OFFSET 0x8
> +
> +/*
> + * A PLL driven by a 25 MHz input oscillator provides a clock source to
> + * the chip. A set of fixed rate clocks is derived from the PLL, and a
> + * set of gate clocks are children of the fixed rate clocks.
> + */
> +#define CLOCK_COUNT (1 + FIXED_COUNT + GATE_COUNT)
nit: I guess this should be after fixed_init, gate_init and fixed_init
definitions.
> +
> +struct fixed_init {
> + const char *name;
> + unsigned int div; /* Rate is PLL rate divided by this */
> +};
> +
> +struct gate_init {
> + const char *name;
> + unsigned long parent_rate;
> + u8 offset; /* Control register offset (0x0 or 0x8) */
> + u8 bit; /* Bit in the control register (0-31) */
> + bool critical;
> +};
> +
> +/* Device IDs used for auxiliary bus reset devices */
> +static DEFINE_IDA(reset_ids);
> +
> +static const struct fixed_init fixed_init[] = {
> + { .name = "312.5MHz", .div = 4, },
> + { .name = "250MHz", .div = 5, },
> + { .name = "125MHz", .div = 10, },
> + { .name = "62.5MHz", .div = 20, },
> +};
> +#define FIXED_COUNT ARRAY_SIZE(fixed_init)
> +
> +static const struct gate_init gate_init[] = {
> + [TC9564_CLK_MAC0_TX] = {
> + .name = "MAC0-TX",
> + .parent_rate = 312500000,
> + .offset = CLOCK0_OFFSET,
> + .bit = 7,
> + },
> + [TC9564_CLK_PCIE] = {
> + .name = "PCIe",
> + .parent_rate = 250000000,
> + .offset = CLOCK0_OFFSET,
> + .bit = 9,
> + .critical = true,
> + },
> + [TC9564_CLK_I2C] = {
> + .name = "i2c",
> + .parent_rate = 62500000,
> + .offset = CLOCK0_OFFSET,
> + .bit = 12,
> + .critical = true,
> + },
> + [TC9564_CLK_MAC0_RX] = {
> + .name = "MAC0-RX",
> + .parent_rate = 312500000,
> + .offset = CLOCK0_OFFSET,
> + .bit = 14,
> + },
> + [TC9564_CLK_MSIGEN] = {
> + .name = "msigen",
> + .parent_rate = 125000000,
> + .offset = CLOCK0_OFFSET,
> + .bit = 18,
> + },
> + [TC9564_CLK_MAC0_125M] = {
> + .name = "MAC0-125MHz",
> + .parent_rate = 125000000,
> + .offset = CLOCK0_OFFSET,
> + .bit = 29,
> + },
> + [TC9564_CLK_MAC0_ALL] = {
> + .name = "MAC0-ALL",
> + .parent_rate = 250000000,
> + .offset = CLOCK0_OFFSET,
> + .bit = 31,
> + },
> + [TC9564_CLK_MAC1_TX] = {
> + .name = "MAC1-TX",
> + .parent_rate = 312500000,
> + .offset = CLOCK1_OFFSET,
> + .bit = 7,
> + },
> + [TC9564_CLK_MAC1_RX] = {
> + .name = "MAC1-RX",
> + .parent_rate = 312500000,
> + .offset = CLOCK1_OFFSET,
> + .bit = 14,
> + },
> + [TC9564_CLK_MAC1_125M] = {
> + .name = "MAC1-125MHz",
> + .parent_rate = 125000000,
> + .offset = CLOCK1_OFFSET,
> + .bit = 29,
> + },
> + [TC9564_CLK_MAC1_ALL] = {
> + .name = "MAC1-ALL",
> + .parent_rate = 250000000,
> + .offset = CLOCK1_OFFSET,
> + .bit = 31,
> + },
> +};
> +#define GATE_COUNT ARRAY_SIZE(gate_init)
> +
> +/* Caller must free the returned pointer */
> +static const char *clock_name_alloc(struct device *dev, const char *name)
> +{
> + return kasprintf(GFP_KERNEL, "%s-%s", dev_name(dev), name);
> +}
> +
> +/* Initialize the PLL (parent is the input oscillator) */
> +static struct clk_hw *pll_register(struct device *dev)
> +{
> + const char *name __free(kfree) = clock_name_alloc(dev, "pll");
> +
> + if (!name)
> + return ERR_PTR(-ENOMEM);
> +
> + return devm_clk_hw_register_fixed_factor_index(dev, name, 0, 0, 50, 1);
> +}
> +
> +static struct clk_hw *fixed_clock_register(struct device *dev,
> + struct clk_hw *pll_hw,
> + const struct fixed_init *finit)
> +{
> + const char *name __free(kfree) = clock_name_alloc(dev, finit->name);
> +
> + if (!name)
> + return ERR_PTR(-ENOMEM);
> +
> + return devm_clk_hw_register_fixed_factor_parent_hw(dev, name, pll_hw,
> + 0, 1, finit->div);
> +}
> +
> +/* Return the clk_hw pointer for a fixed clock having the given rate */
> +static struct clk_hw *fixed_hw_find_by_rate(struct clk_hw **fixed_hws,
> + unsigned long rate)
> +{
> + for (u32 i = 0; i < FIXED_COUNT; i++)
> + if (clk_hw_get_rate(fixed_hws[i]) == rate)
> + return fixed_hws[i];
nit: should we check even the name? What if in the future two clocks have the
same rate?
> +
> + return NULL;
> +}
> +
> +static struct clk_hw *gate_clock_register(struct device *dev,
> + struct clk_hw **fixed_hws,
> + const struct gate_init *ginit,
> + void __iomem *regs)
> +{
> + const char *name __free(kfree) = clock_name_alloc(dev, ginit->name);
> + unsigned long flags = ginit->critical ? CLK_IS_CRITICAL : 0;
> + void __iomem *reg = regs + ginit->offset;
> + struct clk_hw *parent_hw;
> +
> + if (!name)
> + return ERR_PTR(-ENOMEM);
> +
> + /* Each gate clock's parent is one of the fixed rate clocks */
> + parent_hw = fixed_hw_find_by_rate(fixed_hws, ginit->parent_rate);
> + if (!parent_hw) {
> + dev_err(dev, "failed to find %lu parent\n", ginit->parent_rate);
> +
> + return ERR_PTR(-EINVAL);
> + }
> +
> + return devm_clk_hw_register_gate_parent_hw(dev, name, parent_hw, flags,
> + reg, ginit->bit, 0, NULL);
> +}
> +
> +static struct clk_hw *
> +gate_of_clk_hw_onecell_get(struct of_phandle_args *clkspec, void *data)
> +{
> + struct clk_hw **gate_hws = data;
> + u32 id = clkspec->args[0];
> +
> + if (id < GATE_COUNT)
> + return gate_hws[id];
> +
> + pr_err("%s: invalid clock ID %u\n", __func__, id);
> +
> + return ERR_PTR(-EINVAL);
> +}
> +
> +static void reset_adev_free(void *data)
> +{
> + struct auxiliary_device *adev = data;
> +
> + ida_free(&reset_ids, adev->id);
> + kfree(dev_get_platdata(&adev->dev));
> +}
> +
> +/* Create the TC9564 reset auxiliary device; called by probe */
> +static int devm_reset_register(struct device *dev, void __iomem *regs)
nit: this function name seems a bit too generic
> +{
> + struct tc9564_aux_data *aux_data;
do we really need it? it is just a wrapper for __iomem *regs.
> + struct auxiliary_device *adev;
> + int id;
> +
> + aux_data = kzalloc_obj(*aux_data);
> + if (!aux_data)
> + return -ENOMEM;
> + aux_data->regs = regs;
> +
> + id = ida_alloc(&reset_ids, GFP_KERNEL);
> + if (id < 0)
> + return dev_err_probe(dev, id, "failed to get reset id\n");
> +
> + adev = __devm_auxiliary_device_create(dev, TC9564_CLK_MODNAME,
> + TC9564_RESET_DEV_NAME,
> + aux_data, id);
> + if (!adev) {
> + ida_free(&reset_ids, id);
> + kfree(aux_data);
> + return -ENOMEM;
> + }
> +
> + return devm_add_action_or_reset(dev, reset_adev_free, adev);
> +}
> +
> +static int tc9564_clk_probe(struct platform_device *pdev)
> +{
> + struct clk_hw_onecell_data *clock_data;
> + struct device *dev = &pdev->dev;
> + const struct fixed_init *finit;
> + const struct gate_init *ginit;
> + struct clk_hw **fixed_hws;
> + struct clk_hw **gate_hws;
> + struct clk_hw **clk_hws;
> + struct clk_hw *pll_hw;
> + void __iomem *regs;
> + struct clk_hw *hw;
> + int ret;
> + u32 i;
> +
> + if (!dev_of_node(dev))
> + return dev_err_probe(dev, -EINVAL, "no devicetree node\n");
> +
> + regs = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(regs))
> + return dev_err_probe(dev, PTR_ERR(regs),
> + "failed to map registers\n");
> +
> + clock_data = devm_kzalloc_flex(dev, *clock_data, hws, CLOCK_COUNT);
> + if (!clock_data)
> + return -ENOMEM;
> + clock_data->num = CLOCK_COUNT;
> +
> + clk_hws = &clock_data->hws[0];
> +
> + pll_hw = pll_register(dev);
> + if (IS_ERR(pll_hw))
> + return dev_err_probe(dev, PTR_ERR(pll_hw),
> + "failed to register PLL\n");
> + *clk_hws++ = pll_hw;
> +
> + fixed_hws = clk_hws;
> + for (i = 0, finit = &fixed_init[0]; i < FIXED_COUNT; i++, finit++) {
nit (only cosmetic): I guess you can just do:
for (i = 0; i < FIXED_COUNT; i++) {
const struct fixed_init *finit = &fixed_init[i];
...
}
> + hw = fixed_clock_register(dev, pll_hw, finit);
> + if (IS_ERR(hw))
> + return dev_err_probe(dev, PTR_ERR(hw),
> + "failed to register fixed %s\n",
> + finit->name);
> + *clk_hws++ = hw;
> + }
> +
> + gate_hws = clk_hws;
> + for (i = 0, ginit = &gate_init[0]; i < GATE_COUNT; i++, ginit++) {
> + hw = gate_clock_register(dev, fixed_hws, ginit, regs);
nit: same as above;
> + if (IS_ERR(hw))
> + return dev_err_probe(dev, PTR_ERR(hw),
> + "failed to register gate %s\n",
> + ginit->name);
> + *clk_hws++ = hw;
> + }
> +
> + ret = devm_of_clk_add_hw_provider(dev, gate_of_clk_hw_onecell_get,
> + gate_hws);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "failed to add clock provider\n");
> +
> + return devm_reset_register(dev, regs);
> +}
> +
> +static const struct of_device_id tc9564_clock_match[] = {
> + { .compatible = "toshiba,tc9564-clock", },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, tc9564_clock_match);
> +
> +static struct platform_driver tc9564_clk_driver = {
> + .probe = tc9564_clk_probe,
> + .driver = {
> + .name = KBUILD_MODNAME,
> + .of_match_table = tc9564_clock_match,
> + },
> +};
> +module_platform_driver(tc9564_clk_driver);
> +
> +MODULE_DESCRIPTION("Toshiba TC9564 Clock Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index c40e89cc57243..391d0ba79c96f 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -574,6 +574,7 @@ config TC9564_PCI
> tristate "Toshiba TC9564 PCI function support"
> depends on PCI_DYNAMIC_OF_NODES
> depends on PCI_QUIRKS
> + imply COMMON_CLK_TC9564
> default m
> help
> This enables support for two PCI functions implemented by the
> --
> 2.53.0
>
Regards,
Lorenzo
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-12-04 9:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 20:09 [PATCH v5 0/4] clk: tc9564: introduce clock and reset drivers Alex Elder
2026-12-03 20:09 ` [PATCH v5 1/4] dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml Alex Elder
2026-12-03 20:18 ` sashiko-bot
2026-12-04 2:42 ` Alex Elder
2026-12-03 20:09 ` [PATCH v5 2/4] reset: toshiba: introduce a TC9564 reset driver Alex Elder
2026-12-03 20:24 ` sashiko-bot
2026-12-04 2:42 ` Alex Elder
2026-12-04 9:42 ` Lorenzo Bianconi
2026-12-03 20:09 ` [PATCH v5 3/4] clk: toshiba: introduce a TC9564 clock driver Alex Elder
2026-12-03 20:22 ` sashiko-bot
2026-12-04 2:42 ` Alex Elder
2026-12-04 9:40 ` Lorenzo Bianconi [this message]
2026-12-03 20:09 ` [PATCH v5 4/4] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node Alex Elder
2026-12-03 20:28 ` sashiko-bot
2026-12-04 2:43 ` Alex Elder
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=axKKo6AckJG9Wv0G@lore-desk \
--to=lorenzo.bianconi@oss.qualcomm.com \
--cc=abelvesa@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=andersson@kernel.org \
--cc=arnd@arndb.de \
--cc=bmasney+clk@redhat.com \
--cc=changhuang.liang@starfivetech.com \
--cc=conor+dt@kernel.org \
--cc=daniel@riscstar.com \
--cc=devicetree@vger.kernel.org \
--cc=elder@riscstar.com \
--cc=fabrice.gasnier@foss.st.com \
--cc=gregkh@linuxfoundation.org \
--cc=jbrunet+clk@baylibre.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marex@nabladev.com \
--cc=mohd.anwar@oss.qualcomm.com \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
/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