From: Alex Elder <elder@riscstar.com>
To: 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
Cc: daniel@riscstar.com, mohd.anwar@oss.qualcomm.com,
lorenzo.bianconi@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: [PATCH v4 2/4] clk: toshiba: introduce a TC9564 clock driver
Date: Tue, 1 Dec 2026 10:08:07 -0600 [thread overview]
Message-ID: <20261201160810.2422466-3-elder@riscstar.com> (raw)
In-Reply-To: <20261201160810.2422466-1-elder@riscstar.com>
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. Some common definitions
are added to <linux/soc/qcom/tc9563.h> to define the interface between
the clock and the reset driver.
The clock driver should normally be present whenever the TC9564 PCI
driver is enabled, so have TC9564_PCI *imply* the clock driver's config
option, COMMON_CLK_TC9564.
Co-developed-by: Daniel Thompson <daniel@riscstar.com>
Signed-off-by: Daniel Thompson <daniel@riscstar.com>
Signed-off-by: Alex Elder <elder@riscstar.com>
---
v4: - The clocks are now separated by type. A clk_hw pointer is maintained
for the PLL; a hw_onecell_data array holds the clk_hw pointers for
the fixed rate clocks; and a separate hw_onecell_data array holds
clk_hw pointers for the gate clocks.
- The reset controller code has been removed from the clock driver
and placed in a new source file (found in the next patch).
- This clock driver now creates a reset controller auxiliary
device, to bind with the separate reset driver.
- The clock driver and reset device name are now defined in an
existing header file, <linux/soc/qcom/tc9563.h>. This header
is now included by both the clock and reset drivers. A data
structure that describes what is passed from the clock driver
to the reset driver via platform data is defined there as well.
- The function that creates each clock's name is now called
clock_name_alloc() to make it obvious the caller must free
the returned pointer.
- Calls to clock_name_alloc() now all assign the result to a
local variable declared with __free(kfree), so that the
returned pointer gets automatically freed.
- COMMON_CLK_TC9564 no longer depends on TC9564_PCI, and does
not assign a default value. Instead, TC9564_PCI now *implies*
COMMON_CLK_TC9564, meaning no default value is required.
- The driver's probe_type is no set to prefer asynchronous probing.
MAINTAINERS | 1 +
drivers/clk/Kconfig | 8 +
drivers/clk/Makefile | 1 +
drivers/clk/clk-tc9564.c | 401 ++++++++++++++++++++++++++++++++
drivers/misc/Kconfig | 1 +
include/linux/soc/qcom/tc9563.h | 9 +
6 files changed, 421 insertions(+)
create mode 100644 drivers/clk/clk-tc9564.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 0a30100222123..aa52ede9a1aa3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -28729,6 +28729,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 6bfa2c8fffe1b..a3d89c55f17a5 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 support"
+ 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..ec72a0207fd87
--- /dev/null
+++ b/drivers/clk/clk-tc9564.c
@@ -0,0 +1,401 @@
+// 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/reset-controller.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
+
+/* This struct just allows two structures to be allocated/freed together */
+struct reset_aux {
+ struct auxiliary_device adev;
+ struct tc9564_aux_data aux_data;
+};
+
+/*
+ * 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.
+ */
+struct tc9564_clock {
+ void __iomem *ioaddr; /* Mapped clock/reset registers */
+ spinlock_t lock; /* Protects reset register updates */
+ struct clk_hw *pll_hw;
+ struct clk_hw_onecell_data *fixed_data;
+ struct clk_hw_onecell_data *gate_data;
+};
+
+/* Indexes into the fixed_init[] array */
+enum fixed_clock {
+ TC9564_CLK_62_5M,
+ TC9564_CLK_125M,
+ TC9564_CLK_250M,
+ TC9564_CLK_312_5M,
+};
+
+struct fixed_init {
+ const char *name;
+ unsigned int div; /* Rate is PLL rate divided by this */
+};
+
+struct gate_init {
+ const char *name;
+ enum fixed_clock parent;
+ u8 offset; /* Control register offset (0x0 or 0x8) */
+ u8 bit; /* Bit in the control register (0-31) */
+ bool critical;
+};
+
+static const struct fixed_init fixed_init[] = {
+ [TC9564_CLK_312_5M] = {
+ .name = "312.5MHz",
+ .div = 4,
+ },
+ [TC9564_CLK_250M] = {
+ .name = "250MHz",
+ .div = 5,
+ },
+ [TC9564_CLK_125M] = {
+ .name = "125MHz",
+ .div = 10,
+ },
+ [TC9564_CLK_62_5M] = {
+ .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 = TC9564_CLK_312_5M,
+ .offset = CLOCK0_OFFSET,
+ .bit = 7,
+ },
+ [TC9564_CLK_PCIE] = {
+ .name = "PCIe",
+ .parent = TC9564_CLK_250M,
+ .offset = CLOCK0_OFFSET,
+ .bit = 9,
+ .critical = true,
+ },
+ [TC9564_CLK_I2C] = {
+ .name = "i2c",
+ .parent = TC9564_CLK_62_5M,
+ .offset = CLOCK0_OFFSET,
+ .bit = 12,
+ .critical = true,
+ },
+ [TC9564_CLK_MAC0_RX] = {
+ .name = "MAC0-RX",
+ .parent = TC9564_CLK_312_5M,
+ .offset = CLOCK0_OFFSET,
+ .bit = 14,
+ },
+ [TC9564_CLK_MSIGEN] = {
+ .name = "msigen",
+ .parent = TC9564_CLK_125M,
+ .offset = CLOCK0_OFFSET,
+ .bit = 18,
+ },
+ [TC9564_CLK_MAC0_125M] = {
+ .name = "MAC0-125MHz",
+ .parent = TC9564_CLK_125M,
+ .offset = CLOCK0_OFFSET,
+ .bit = 29,
+ },
+ [TC9564_CLK_MAC0_ALL] = {
+ .name = "MAC0-ALL",
+ .parent = TC9564_CLK_250M,
+ .offset = CLOCK0_OFFSET,
+ .bit = 31,
+ },
+ [TC9564_CLK_MAC1_TX] = {
+ .name = "MAC1-TX",
+ .parent = TC9564_CLK_312_5M,
+ .offset = CLOCK1_OFFSET,
+ .bit = 7,
+ },
+ [TC9564_CLK_MAC1_RX] = {
+ .name = "MAC1-RX",
+ .parent = TC9564_CLK_312_5M,
+ .offset = CLOCK1_OFFSET,
+ .bit = 14,
+ },
+ [TC9564_CLK_MAC1_125M] = {
+ .name = "MAC1-125MHz",
+ .parent = TC9564_CLK_125M,
+ .offset = CLOCK1_OFFSET,
+ .bit = 29,
+ },
+ [TC9564_CLK_MAC1_ALL] = {
+ .name = "MAC1-ALL",
+ .parent = TC9564_CLK_250M,
+ .offset = CLOCK1_OFFSET,
+ .bit = 31,
+ },
+};
+#define GATE_COUNT ARRAY_SIZE(gate_init)
+
+/* Caller must free the returned pointer if non-null */
+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); called from probe */
+static int pll_setup(struct device *dev)
+{
+ const char *name __free(kfree) = clock_name_alloc(dev, "pll");
+ struct tc9564_clock *clock = dev_get_drvdata(dev);
+ struct clk_hw *hw;
+ int ret;
+
+ if (!name)
+ return -ENOMEM;
+
+ hw = devm_clk_hw_register_fixed_factor_index(dev, name, 0, 0, 50, 1);
+ if (IS_ERR(hw))
+ return dev_err_probe(dev, PTR_ERR(hw),
+ "failed to register pll\n");
+
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to add pll provider\n");
+
+ clock->pll_hw = hw;
+
+ return 0;
+}
+
+/* Initialize the fixed rate clocks (PLL is parent); called from probe */
+static int fixed_clock_setup(struct device *dev)
+{
+ struct tc9564_clock *clock = dev_get_drvdata(dev);
+ const struct fixed_init *init = &fixed_init[0];
+ struct clk_hw_onecell_data *fixed_data;
+ struct clk_hw *pll_hw = clock->pll_hw;
+ int ret;
+
+ fixed_data = devm_kzalloc_flex(dev, *fixed_data, hws, FIXED_COUNT);
+ if (!fixed_data)
+ return -ENOMEM;
+ fixed_data->num = FIXED_COUNT;
+
+ for (u32 i = 0; i < FIXED_COUNT; i++, init++) {
+ const char *name __free(kfree) = clock_name_alloc(dev, init->name);
+ struct clk_hw *hw;
+
+ if (!name)
+ return -ENOMEM;
+
+ hw = devm_clk_hw_register_fixed_factor_parent_hw(dev, name,
+ pll_hw, 0,
+ 1, init->div);
+ if (IS_ERR(hw))
+ return dev_err_probe(dev, PTR_ERR(hw),
+ "failed to register fixed %s\n",
+ init->name);
+
+ fixed_data->hws[i] = hw;
+ }
+
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+ fixed_data);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to add fixed clock provider\n");
+
+ clock->fixed_data = fixed_data;
+
+ return 0;
+}
+
+/* Initialize the gate clocks; called from probe */
+static int gate_clock_setup(struct device *dev)
+{
+ struct tc9564_clock *clock = dev_get_drvdata(dev);
+ const struct gate_init *init = &gate_init[0];
+ struct clk_hw_onecell_data *fixed_data;
+ struct clk_hw_onecell_data *gate_data;
+ int ret;
+
+ gate_data = devm_kzalloc_flex(dev, *gate_data, hws, GATE_COUNT);
+ if (!gate_data)
+ return -ENOMEM;
+ gate_data->num = GATE_COUNT;
+
+ fixed_data = clock->fixed_data;
+ for (u32 i = 0; i < GATE_COUNT; i++, init++) {
+ const char *name __free(kfree) = clock_name_alloc(dev, init->name);
+ unsigned long flags = init->critical ? CLK_IS_CRITICAL : 0;
+ void __iomem *reg = clock->ioaddr + init->offset;
+ struct clk_hw *parent_hw;
+ struct clk_hw *hw;
+
+ if (!name)
+ return -ENOMEM;
+
+ /* Each gate clock's parent is a fixed rate clock */
+ parent_hw = fixed_data->hws[init->parent];
+
+ hw = devm_clk_hw_register_gate_parent_hw(dev, name, parent_hw,
+ flags, reg, init->bit,
+ 0, NULL);
+ if (IS_ERR(hw))
+ return dev_err_probe(dev, PTR_ERR(hw),
+ "failed to register gate %s\n",
+ init->name);
+
+ gate_data->hws[i] = hw;
+ }
+
+ ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
+ gate_data);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to add gate clock provider\n");
+
+ clock->gate_data = gate_data;
+
+ return 0;
+}
+
+
+static void reset_dev_release(struct device *dev)
+{
+ of_node_put(dev->of_node);
+}
+
+static struct reset_aux *adev_to_reset_aux(struct auxiliary_device *adev)
+{
+ return container_of(adev, struct reset_aux, adev);
+}
+
+static void reset_adev_remove(void *data)
+{
+ struct auxiliary_device *adev = data;
+
+ auxiliary_device_delete(adev);
+ auxiliary_device_uninit(adev);
+ kfree(adev_to_reset_aux(adev));
+}
+
+/* Create the TC9564 reset auxiliary device */
+static int devm_reset_setup(struct device *dev)
+{
+ struct tc9564_clock *clock = dev_get_drvdata(dev);
+ struct tc9564_aux_data *aux_data;
+ struct auxiliary_device *adev;
+ struct reset_aux *reset_aux;
+ int ret;
+
+ reset_aux = kzalloc_obj(*reset_aux);
+ if (!reset_aux)
+ return -ENOMEM;
+ adev = &reset_aux->adev;
+
+ aux_data = &reset_aux->aux_data;
+ aux_data->reg = clock->ioaddr;
+
+ adev->id = 0;
+ adev->name = TC9564_RESET_DEV_NAME;
+ adev->dev.parent = dev;
+ adev->dev.platform_data = aux_data;
+ adev->dev.release = reset_dev_release;
+ device_set_of_node_from_dev(&adev->dev, dev);
+
+ ret = auxiliary_device_init(adev);
+ if (ret) {
+ of_node_put(adev->dev.of_node);
+ kfree(reset_aux);
+ return ret;
+ }
+
+ ret = auxiliary_device_add(adev);
+ if (ret) {
+ auxiliary_device_uninit(adev);
+ kfree(reset_aux);
+
+ return ret;
+ }
+
+ return devm_add_action_or_reset(dev, reset_adev_remove, adev);
+}
+
+static int tc9564_clk_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct tc9564_clock *clock;
+ struct device_node *np;
+ int ret;
+
+ /* Make sure the reset driver uses the proper module name */
+ BUILD_BUG_ON(__builtin_strcmp(KBUILD_MODNAME, TC9564_CLK_MODNAME));
+
+ np = dev_of_node(dev);
+ if (!np)
+ return dev_err_probe(dev, -EINVAL, "no devicetree node\n");
+
+ clock = devm_kzalloc_obj(dev, *clock);
+ if (!clock)
+ return -ENOMEM;
+
+ clock->ioaddr = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(clock->ioaddr))
+ return dev_err_probe(dev, PTR_ERR(clock->ioaddr),
+ "failed to map registers\n");
+
+ dev_set_drvdata(dev, clock);
+
+ ret = pll_setup(dev);
+ if (ret)
+ return ret;
+
+ ret = fixed_clock_setup(dev);
+ if (ret)
+ return ret;
+
+ ret = gate_clock_setup(dev);
+ if (ret)
+ return ret;
+
+ return devm_reset_setup(dev);
+}
+
+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
diff --git a/include/linux/soc/qcom/tc9563.h b/include/linux/soc/qcom/tc9563.h
index 086f37a40d801..2045ffb179133 100644
--- a/include/linux/soc/qcom/tc9563.h
+++ b/include/linux/soc/qcom/tc9563.h
@@ -16,4 +16,13 @@
#define TC9563_GPIO_CONFIG TC9563_GPIO_EN0_OFFSET
#define TC9563_RESET_GPIO TC9563_GPIO_OUT0_OFFSET
+/* Name of the clock driver and the reset auxiliary device it creates */
+#define TC9564_CLK_MODNAME "clk_tc9564"
+#define TC9564_RESET_DEV_NAME "tc9564-reset"
+
+/* Platform data passed by the TC9564 clock driver to its auxiliary device */
+struct tc9564_aux_data {
+ void __iomem *reg;
+};
+
#endif /* __QCOM_TC9563_H */
--
2.53.0
next prev parent reply other threads:[~2026-12-01 16:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 16:08 [PATCH v4 0/4] clk: tc9564: introduce clock and reset drivers Alex Elder
2026-12-01 16:08 ` [PATCH v4 1/4] dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml Alex Elder
2026-12-01 16:08 ` Alex Elder [this message]
2026-12-01 16:08 ` [PATCH v4 3/4] reset: toshiba: introduce a TC9564 reset driver Alex Elder
2026-12-01 16:16 ` sashiko-bot
2026-12-01 16:08 ` [PATCH v4 4/4] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node 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=20261201160810.2422466-3-elder@riscstar.com \
--to=elder@riscstar.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=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=lorenzo.bianconi@oss.qualcomm.com \
--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