Linux clock framework development
 help / color / mirror / Atom feed
* [PATCH v5 0/4] clk: tc9564: introduce clock and reset drivers
@ 2026-12-03 20:09 Alex Elder
  2026-12-03 20:09 ` [PATCH v5 1/4] dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml Alex Elder
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Alex Elder @ 2026-12-03 20:09 UTC (permalink / raw)
  To: sboyd, bmasney+clk, jbrunet+clk, robh, krzk+dt, conor+dt, p.zabel,
	andersson, konradybcio, abelvesa, arnd, gregkh
  Cc: daniel, mohd.anwar, lorenzo.bianconi, fabrice.gasnier,
	alexandre.torgue, marex, changhuang.liang, linux-clk, devicetree,
	linux-arm-msm, linux-kernel

This series introduces a devicetree binding for a clock and reset
controller, along with a clock driver and an auxiliary reset driver,
to support the clock and reset components present within the Toshiba
TC9564 chip.

The Toshiba TC9564 is an SoC that attaches to a host system via PCIe.
It includes a PCIe switch with three downstream ports.  To one of
these ports an embedded PCIe endpoint is attached, and that implements
two PCI functions.  BAR 4 for both PCI functions provides access to
registers controlling blocks within the SoC, including the clock and
reset controllers supported by this series.

This version of the series addresses feedback received on version 4.

					-Alex

Version 4 is available here:
  https://lore.kernel.org/all/20261201160810.2422466-1-elder@riscstar.com/

Between version 4 and version 5:
  General
  - The reset driver is included before the clock driver in the series.
  - A few things have been reworded or renamed.

  Binding
  - Comments in the header file about the I2C and PCIE clocks being
    critical have been removed.  (These clocks are still registered
    with CLK_IS_CRITICAL flag.)
  - The I2C and PCIE resets no longer have publicly-defined reset IDs.

  Reset driver
  - Without public reset IDs, the I2C and PCIE resets will never be
    asserted, and the code that previously warned on any attempt to
    "get" them has been removed.
  - The reset driver Kconfig now selects AUXILIARY_BUS.
  - Philipp's Reviewed-by tag has been added.

  Clock driver
  - In the previous version, the clock controller driver erroneously
    added three separate clock hardware providers using a single
    device.  Instead, a single clock hardware provider is added
    using a clk_hw_onecell_data structure which now represents the
    PLL, fixed clocks, and gate clocks.
  - There is no longer any need to track the clk_hw_onecell_data
    structure that contains the clk_hw pointers for clocks after
    initialization.
  - The mapped memory address used for clock and reset control
    registers is used during initialization in the clock probe, but
    is not needed thereafter.
  - Because various pointers are only needed at initialization time,
    there is no longer any need for a per-instance structure to be
    allocated for a probed clock device.
  - Gate clocks no longer specify their fixed rate parent clock with
    an ID; they instead indicate the rate they need.  When a gate
    clock is initialized, the clk_hw pointer for the fixed clock
    having the desired rate (which will already have been registered)
    is looked up and used as the parent.
  - Each fixed rate clock is defined with a name and a divider value.
    IDs are no longer used for fixed clocks.
  - The probe function now iterates over fixed rate and gate clocks,
    calling functions that initialize individual clocks and return a
    clk_hw pointer.
  - The clock driver now uses __devm_auxiliary_device_create() to
    create the reset device, rather than duplicating code.
  - The clock driver Kconfig now selects AUXILIARY_BUS.
  - An unneeded include of <linux/reset-controller.h> has been removed
    from the clock controller driver.
  - A spinlock that was associated with resets in an earlier version of
    the code has been removed.

Version 3 is available here:
  https://lore.kernel.org/all/20261125202141.1288493-1-elder@riscstar.com/

Between version 3 and version 4:
  - The reset driver functionality has been separated from the clock
    platform driver source code, into its own auxiliary device driver.
  - The clock driver now creates an auxiliary device representing the
    reset controller.
  - A few definitions are placed in an existing common header file,
    to define the interface between the clock and reset drivers.
  - Reset IDs are defined in a header file separate from the clock IDs.
  - The three clock types implemented by the clock driver (PLL, fixed
    rate, and gate) now have distinct zero-based identifiers, and are
    no longer represented within a single clk_hw_onecell_data->clk_hw[]
    array.
  - Clock and reset ID symbols now have a "TC9564_" prefix.
  - The function that formats clock names using kasprintf() now has the
    suffix "_alloc", to make it more obvious the caller must free the
    returned pointer.
  - The clock driver no longer *depends on* the TC9564_PCI config option
    (for the TC9564 PCI driver).  Instead, the PCI driver *implies* the
    clock driver config option.
  - The clock driver no longer specifies that it prefers asynchronous
    probing.
  - The reset and clock drivers have separate Kconfig options, and the
    reset driver config option is *implied* by the clock driver.
  - The 25 MHz clock crystal is now defined within the "clocks" node
    in the RB3gen2 DTS, rather than inside the TC9564.
  - Added a Reviewed-by tag from Lorenzo on the last patch.

Please refer to version 3 for more information about prior versions
of this code.


Alex Elder (4):
  dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml
  reset: toshiba: introduce a TC9564 reset driver
  clk: toshiba: introduce a TC9564 clock driver
  arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node

 .../bindings/clock/toshiba,tc9564-clock.yaml  |  73 ++++
 MAINTAINERS                                   |  17 +
 arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts  |  15 +
 drivers/clk/Kconfig                           |  10 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/clk-tc9564.c                      | 326 ++++++++++++++++++
 drivers/misc/Kconfig                          |   1 +
 drivers/reset/Kconfig                         |   8 +
 drivers/reset/Makefile                        |   1 +
 drivers/reset/reset-tc9564.c                  | 165 +++++++++
 include/dt-bindings/clock/toshiba,tc9564.h    |  26 ++
 include/dt-bindings/reset/toshiba,tc9564.h    |  22 ++
 include/linux/soc/qcom/tc9563.h               |   9 +
 13 files changed, 674 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml
 create mode 100644 drivers/clk/clk-tc9564.c
 create mode 100644 drivers/reset/reset-tc9564.c
 create mode 100644 include/dt-bindings/clock/toshiba,tc9564.h
 create mode 100644 include/dt-bindings/reset/toshiba,tc9564.h


base-commit: 799dd936553182df5770dde7f38d94c8337df75a
-- 
2.53.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v5 1/4] dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml
  2026-12-03 20:09 [PATCH v5 0/4] clk: tc9564: introduce clock and reset drivers Alex Elder
@ 2026-12-03 20:09 ` Alex Elder
  2026-12-03 20:18   ` sashiko-bot
  2026-12-03 20:09 ` [PATCH v5 2/4] reset: toshiba: introduce a TC9564 reset driver Alex Elder
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Alex Elder @ 2026-12-03 20:09 UTC (permalink / raw)
  To: sboyd, bmasney+clk, jbrunet+clk, robh, krzk+dt, conor+dt, p.zabel,
	andersson, konradybcio, abelvesa, arnd, gregkh
  Cc: daniel, mohd.anwar, lorenzo.bianconi, fabrice.gasnier,
	alexandre.torgue, marex, changhuang.liang, linux-clk, devicetree,
	linux-arm-msm, linux-kernel

Define the binding for the clock and reset controller present in the
Toshiba TC9564 SoC.

Reviewed-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
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: - The I2C and PCIE reset IDs have been removed.
    - The I2C and PCIE clock IDs no longer indicate they're critical.

 .../bindings/clock/toshiba,tc9564-clock.yaml  | 73 +++++++++++++++++++
 MAINTAINERS                                   | 15 ++++
 include/dt-bindings/clock/toshiba,tc9564.h    | 26 +++++++
 include/dt-bindings/reset/toshiba,tc9564.h    | 22 ++++++
 4 files changed, 136 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml
 create mode 100644 include/dt-bindings/clock/toshiba,tc9564.h
 create mode 100644 include/dt-bindings/reset/toshiba,tc9564.h

diff --git a/Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml b/Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml
new file mode 100644
index 0000000000000..2217eaea05e21
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml
@@ -0,0 +1,73 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/clock/toshiba,tc9564-clock.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Toshiba TC9564 Clock and Reset Controllers
+
+maintainers:
+  - Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
+  - Alex Elder <elder@kernel.org>
+  - Daniel Thompson <danielt@kernel.org>
+
+description:
+  The Toshiba TC9564 is an SoC accessed by a host system through the
+  upstream PCIe port on the PCIe switch it implements.  The chip includes
+  an embedded PCIe endpoint that provides access to various peripherals
+  within the SoC via its BARs.  These peripherals include a simple
+  controller to gate internal clocks, and a reset controller.
+
+  The TC9564 chip has a single input clock.  Internally a PLL multiplies
+  that clock, and the PLL signal is divided internally into a set of
+  fixed rate, always-on clocks.
+
+  The clock controller exposes a set of simple gated clocks, which are
+  controlled by two registers.  Each is derived from one of the internal
+  fixed-rate clocks.  A total of 21 gated clocks are implemented within
+  the chip, but support for enabling and disabling only a subset of them
+  is provided at this time.  Two clocks (I2C and PCIE) are marked critical
+  to make it clear that they should never be disabled.
+
+  The reset controller uses two other registers to control a set of 13
+  resets that can be asserted or deasserted.  Here too, only a subset
+  of the resets can currently be managed.
+
+  Clock IDs are defined <dt-bindings/clock/toshiba,tc9564.h>, and reset
+  IDs are defined <dt-bindings/reset/toshiba,tc9564.h>.
+
+properties:
+  compatible:
+    items:
+      - const: toshiba,tc9564-clock
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  "#clock-cells":
+    const: 1
+
+  "#reset-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - "#clock-cells"
+  - "#reset-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    clock-controller@1004 {
+        compatible = "toshiba,tc9564-clock";
+        reg = <0x1004 0x10>;
+        clocks = <&tc9564_xo_board>;
+        #clock-cells = <1>;
+        #reset-cells = <1>;
+    };
diff --git a/MAINTAINERS b/MAINTAINERS
index a20ba230b7f0b..5d9fc5c5fbcd8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -28792,6 +28792,14 @@ F:	Documentation/devicetree/bindings/media/i2c/toshiba,tc358743.yaml
 F:	drivers/media/i2c/tc358743*
 F:	include/media/i2c/tc358743.h
 
+TOSHIBA TC9564 CLOCK CONTROLLER DRIVER
+M:	Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
+M:	Alex Elder <elder@kernel.org>
+M:	Daniel Thompson <danielt@kernel.org>
+S:	Maintained
+F:	Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml
+F:	include/dt-bindings/clock/toshiba,tc9564.h
+
 TOSHIBA TC9564 PCI DRIVER
 M:	Alex Elder <elder@kernel.org>
 M:	Daniel Thompson <danielt@kernel.org>
@@ -28799,6 +28807,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/misc/pci1179,0220.yaml
 F:	drivers/misc/tc9564-pci.c
 
+TOSHIBA TC9564 RESET CONTROLLER DRIVER
+M:	Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
+M:	Alex Elder <elder@kernel.org>
+M:	Daniel Thompson <danielt@kernel.org>
+S:	Maintained
+F:	include/dt-bindings/reset/toshiba,tc9564.h
+
 TOSHIBA WMI HOTKEYS DRIVER
 M:	Azael Avalos <coproscefalo@gmail.com>
 L:	platform-driver-x86@vger.kernel.org
diff --git a/include/dt-bindings/clock/toshiba,tc9564.h b/include/dt-bindings/clock/toshiba,tc9564.h
new file mode 100644
index 0000000000000..39353a8832fde
--- /dev/null
+++ b/include/dt-bindings/clock/toshiba,tc9564.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
+
+/*
+ * Copyright (C) 2026 by RISCstar Solutions Corporation.  All rights reserved.
+ */
+
+#ifndef __CLOCK_TOSHIBA_TC9564_H__
+#define __CLOCK_TOSHIBA_TC9564_H__
+
+/* Clock IDs */
+
+#define TC9564_CLK_I2C		0
+#define TC9564_CLK_PCIE		1
+#define TC9564_CLK_MSIGEN	2
+
+#define TC9564_CLK_MAC0_TX	3
+#define TC9564_CLK_MAC0_RX	4
+#define TC9564_CLK_MAC0_125M	5
+#define TC9564_CLK_MAC0_ALL	6
+
+#define TC9564_CLK_MAC1_TX	7
+#define TC9564_CLK_MAC1_RX	8
+#define TC9564_CLK_MAC1_125M	9
+#define TC9564_CLK_MAC1_ALL	10
+
+#endif /* __CLOCK_TOSHIBA_TC9564_H__ */
diff --git a/include/dt-bindings/reset/toshiba,tc9564.h b/include/dt-bindings/reset/toshiba,tc9564.h
new file mode 100644
index 0000000000000..73af49a0a3bc8
--- /dev/null
+++ b/include/dt-bindings/reset/toshiba,tc9564.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
+
+/*
+ * Copyright (C) 2026 by RISCstar Solutions Corporation.  All rights reserved.
+ */
+
+#ifndef __RESET_TOSHIBA_TC9564_H__
+#define __RESET_TOSHIBA_TC9564_H__
+
+/* Reset IDs */
+
+#define TC9564_RST_MSIGEN	0
+
+#define TC9564_RST_MAC0_MAC	1
+#define TC9564_RST_MAC0_PMA	2
+#define TC9564_RST_MAC0_XPCS	3
+
+#define TC9564_RST_MAC1_MAC	4
+#define TC9564_RST_MAC1_PMA	5
+#define TC9564_RST_MAC1_XPCS	6
+
+#endif /* __RESET_TOSHIBA_TC9564_H__ */
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v5 2/4] reset: toshiba: introduce a TC9564 reset driver
  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:09 ` Alex Elder
  2026-12-03 20:24   ` sashiko-bot
  2026-12-03 20:09 ` [PATCH v5 3/4] clk: toshiba: introduce a TC9564 clock driver Alex Elder
  2026-12-03 20:09 ` [PATCH v5 4/4] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node Alex Elder
  3 siblings, 1 reply; 9+ messages in thread
From: Alex Elder @ 2026-12-03 20:09 UTC (permalink / raw)
  To: sboyd, bmasney+clk, jbrunet+clk, robh, krzk+dt, conor+dt, p.zabel,
	andersson, konradybcio, abelvesa, arnd, gregkh
  Cc: daniel, mohd.anwar, lorenzo.bianconi, fabrice.gasnier,
	alexandre.torgue, marex, changhuang.liang, linux-clk, devicetree,
	linux-arm-msm, linux-kernel

Define a new auxiliary device driver that manages resets implemented
by the Toshiba TC9564 SoC.  The TC9564 clock driver will create the
reset device, which will bind to this driver.

The reset controller uses two registers to control a set of 13 resets
that can be asserted or deasserted.  Only a subset of the resets can
currently be managed.

The MMIO region containing the two control registers is mapped by
the clock controller driver, and passed via the auxiliary device's
platform data.

Some common definitions are added to <linux/soc/qcom/tc9563.h> to
specify the interface between the clock and reset drivers.

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
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: - Code related to the I2C and PCIE resets (including code that
      warned if they were used) has been removed.
    - The Kconfig now selects AUXILIARY_BUS
    - Philipp's Reviewed-by tag has been added.

 MAINTAINERS                     |   1 +
 drivers/reset/Kconfig           |   8 ++
 drivers/reset/Makefile          |   1 +
 drivers/reset/reset-tc9564.c    | 165 ++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/tc9563.h |   9 ++
 5 files changed, 184 insertions(+)
 create mode 100644 drivers/reset/reset-tc9564.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 5d9fc5c5fbcd8..936d60a27dd3c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -28812,6 +28812,7 @@ M:	Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
 M:	Alex Elder <elder@kernel.org>
 M:	Daniel Thompson <danielt@kernel.org>
 S:	Maintained
+F:	drivers/reset/reset-tc9564.c
 F:	include/dt-bindings/reset/toshiba,tc9564.h
 
 TOSHIBA WMI HOTKEYS DRIVER
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index 673bca1e594e0..f8ef663ac5b79 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -369,6 +369,14 @@ config RESET_SUNXI
 	help
 	  This enables the reset driver for Allwinner SoCs.
 
+config RESET_TC9564
+	tristate "Toshiba TC9564 reset controller driver"
+	select AUXILIARY_BUS
+	help
+	  This enables support for the reset controller embedded in the
+	  Toshiba TC9564 SoC.  The device is created by the TC9564 clock
+	  controller driver as an auxiliary device.
+
 config RESET_TENSTORRENT_ATLANTIS
 	tristate "Tenstorrent atlantis reset driver"
 	depends on ARCH_TENSTORRENT || COMPILE_TEST
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 2fe527a7be8e1..2144095c14b3d 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_RESET_SKY1_AUDSS) += reset-sky1-audss.o
 obj-$(CONFIG_RESET_SOCFPGA) += reset-socfpga.o
 obj-$(CONFIG_RESET_SUNPLUS) += reset-sunplus.o
 obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o
+obj-$(CONFIG_RESET_TC9564) += reset-tc9564.o
 obj-$(CONFIG_RESET_TENSTORRENT_ATLANTIS) += reset-tenstorrent-atlantis.o
 obj-$(CONFIG_RESET_TH1520) += reset-th1520.o
 obj-$(CONFIG_RESET_TI_SCI) += reset-ti-sci.o
diff --git a/drivers/reset/reset-tc9564.c b/drivers/reset/reset-tc9564.c
new file mode 100644
index 0000000000000..218be6dbbb2a3
--- /dev/null
+++ b/drivers/reset/reset-tc9564.c
@@ -0,0 +1,165 @@
+// 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/io.h>
+#include <linux/module.h>
+#include <linux/reset-controller.h>
+#include <linux/slab.h>
+#include <linux/soc/qcom/tc9563.h>
+
+#include <dt-bindings/reset/toshiba,tc9564.h>
+
+/*
+ * Two registers implement the bits that control whether our resets are
+ * asserted.  These offsets are relative to the mapped memory passed
+ * as platform data from the TC9564 clock driver.
+ */
+#define RESET0_OFFSET	0x4
+#define RESET1_OFFSET	0xc
+
+struct tc9564_reset {
+	void __iomem *regs;	/* Mapped registers base address */
+	spinlock_t lock;	/* Protects register updates */
+	struct reset_controller_dev rcdev;
+};
+
+struct reset_init {
+	u16 offset;		/* Control register offset (0x4 or 0xc) */
+	u16 bit;		/* Bit in the control register (0-31) */
+};
+
+static const struct reset_init reset_init[] = {
+	[TC9564_RST_MAC0_MAC] = {
+		.offset = RESET0_OFFSET,
+		.bit = 7,
+	},
+	[TC9564_RST_MSIGEN] = {
+		.offset = RESET0_OFFSET,
+		.bit = 18,
+	},
+	[TC9564_RST_MAC0_PMA] = {
+		.offset = RESET0_OFFSET,
+		.bit = 30,
+	},
+	[TC9564_RST_MAC0_XPCS] = {
+		.offset = RESET0_OFFSET,
+		.bit = 31,
+	},
+	[TC9564_RST_MAC1_MAC] = {
+		.offset = RESET1_OFFSET,
+		.bit = 7,
+	},
+	[TC9564_RST_MAC1_PMA] = {
+		.offset = RESET1_OFFSET,
+		.bit = 30,
+	},
+	[TC9564_RST_MAC1_XPCS] = {
+		.offset = RESET1_OFFSET,
+		.bit = 31,
+	},
+};
+#define RESET_COUNT	ARRAY_SIZE(reset_init)
+
+static int reset_update(struct reset_controller_dev *rcdev,
+			unsigned long id, bool assert)
+{
+	struct tc9564_reset *reset = dev_get_drvdata(rcdev->dev);
+	const struct reset_init *init = &reset_init[id];
+	void __iomem *reg = reset->regs + init->offset;
+	u32 mask = BIT(init->bit);
+	u32 val;
+
+	guard(spinlock_irqsave)(&reset->lock);
+
+	val = readl(reg);
+	if (assert)
+		val |= mask;
+	else
+		val &= ~mask;
+	writel(val, reg);
+
+	return 0;
+}
+
+static int reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
+{
+	return reset_update(rcdev, id, true);
+}
+
+static int reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
+{
+	return reset_update(rcdev, id, false);
+}
+
+static int reset_status(struct reset_controller_dev *rcdev, unsigned long id)
+{
+	struct tc9564_reset *reset = dev_get_drvdata(rcdev->dev);
+	const struct reset_init *init = &reset_init[id];
+	void __iomem *reg = reset->regs + init->offset;
+
+	return readl(reg) & BIT(init->bit) ? 1 : 0;
+}
+
+static const struct reset_control_ops reset_control_ops = {
+	.assert = reset_assert,
+	.deassert = reset_deassert,
+	.status = reset_status,
+};
+
+static int tc9564_reset_probe(struct auxiliary_device *adev,
+			      const struct auxiliary_device_id *id)
+{
+	struct reset_controller_dev *rcdev;
+	struct tc9564_aux_data *aux_data;
+	struct device *dev = &adev->dev;
+	struct tc9564_reset *reset;
+	int ret;
+
+	aux_data = dev_get_platdata(dev);
+	if (!aux_data)
+		return dev_err_probe(dev, -EINVAL, "no register pointer\n");
+
+	reset = devm_kzalloc_obj(dev, *reset);
+	if (!reset)
+		return -ENOMEM;
+
+	reset->regs = aux_data->regs;
+	spin_lock_init(&reset->lock);
+
+	/* This needs to be set before registering */
+	dev_set_drvdata(dev, reset);
+
+	rcdev = &reset->rcdev;
+	rcdev->ops = &reset_control_ops;
+	rcdev->owner = THIS_MODULE;
+	rcdev->dev = dev;
+	rcdev->of_node = dev_of_node(dev);
+	rcdev->nr_resets = RESET_COUNT;
+
+	ret = devm_reset_controller_register(dev, rcdev);
+	if (ret)
+		return dev_err_probe(dev, ret,
+				     "failed to register reset controller\n");
+	return 0;
+}
+
+static const struct auxiliary_device_id tc9564_reset_ids[] = {
+	{ TC9564_CLK_MODNAME "." TC9564_RESET_DEV_NAME },
+	{ }
+};
+MODULE_DEVICE_TABLE(auxiliary, tc9564_reset_ids);
+
+static struct auxiliary_driver tc9564_reset_driver = {
+	.name = KBUILD_MODNAME,
+	.probe = tc9564_reset_probe,
+	.id_table = tc9564_reset_ids,
+};
+module_auxiliary_driver(tc9564_reset_driver);
+
+MODULE_DESCRIPTION("Toshiba TC9564 Reset Driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/soc/qcom/tc9563.h b/include/linux/soc/qcom/tc9563.h
index 086f37a40d801..f778ce9ae2e7c 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 to the TC9564 reset auxiliary driver */
+struct tc9564_aux_data {
+	void __iomem *regs;
+};
+
 #endif /* __QCOM_TC9563_H */
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v5 3/4] clk: toshiba: introduce a TC9564 clock driver
  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:09 ` [PATCH v5 2/4] reset: toshiba: introduce a TC9564 reset driver Alex Elder
@ 2026-12-03 20:09 ` Alex Elder
  2026-12-03 20:22   ` sashiko-bot
  2026-12-03 20:09 ` [PATCH v5 4/4] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node Alex Elder
  3 siblings, 1 reply; 9+ messages in thread
From: Alex Elder @ 2026-12-03 20:09 UTC (permalink / raw)
  To: sboyd, bmasney+clk, jbrunet+clk, robh, krzk+dt, conor+dt, p.zabel,
	andersson, konradybcio, abelvesa, arnd, gregkh
  Cc: daniel, mohd.anwar, lorenzo.bianconi, fabrice.gasnier,
	alexandre.torgue, marex, changhuang.liang, linux-clk, devicetree,
	linux-arm-msm, linux-kernel

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)
+
+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];
+
+	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)
+{
+	struct tc9564_aux_data *aux_data;
+	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++) {
+		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);
+		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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v5 4/4] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node
  2026-12-03 20:09 [PATCH v5 0/4] clk: tc9564: introduce clock and reset drivers Alex Elder
                   ` (2 preceding siblings ...)
  2026-12-03 20:09 ` [PATCH v5 3/4] clk: toshiba: introduce a TC9564 clock driver Alex Elder
@ 2026-12-03 20:09 ` Alex Elder
  2026-12-03 20:28   ` sashiko-bot
  3 siblings, 1 reply; 9+ messages in thread
From: Alex Elder @ 2026-12-03 20:09 UTC (permalink / raw)
  To: sboyd, bmasney+clk, jbrunet+clk, robh, krzk+dt, conor+dt, p.zabel,
	andersson, konradybcio, abelvesa, arnd, gregkh
  Cc: daniel, mohd.anwar, lorenzo.bianconi, fabrice.gasnier,
	alexandre.torgue, marex, changhuang.liang, linux-clk, devicetree,
	linux-arm-msm, linux-kernel

Add a node for the clock and reset controller found within the
Toshiba TC9564 SoC.  Also add a node representing the fixed
rate 25 MHz crystal that supplies the chip.

Reviewed-by: Lorenzo Bianconi <lorenzo.bianconi@oss.qualcomm.com>
Co-developed-by: Daniel Thompson <daniel@riscstar.com>
Signed-off-by: Daniel Thompson <daniel@riscstar.com>
Signed-off-by: Alex Elder <elder@riscstar.com>
---
 arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts b/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts
index 682bcbc0b466b..87035745b6720 100644
--- a/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts
+++ b/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts
@@ -49,6 +49,13 @@ mcp2518fd_osc: can-clk {
 			clock-frequency = <40000000>;
 			#clock-cells = <0>;
 		};
+
+		tc9564_xo_board: clock-25000000 {
+			compatible = "fixed-clock";
+			#clock-cells = <0>;
+			clock-frequency = <25000000>;
+			clock-output-names = "tc9564_xo_board";
+		};
 	};
 
 	dp-connector {
@@ -969,6 +976,14 @@ pci-ep-bus@4 {
 					#size-cells = <1>;
 					/* Map 0x0-0x1fffff to BAR 4 */
 					ranges = <0x0  0x4 0x0 0x0  0x200000>;
+
+					clock-controller@1004 {
+						compatible = "toshiba,tc9564-clock";
+						reg = <0x1004 0x10>;
+						clocks = <&tc9564_xo_board>;
+						#clock-cells = <1>;
+						#reset-cells = <1>;
+					};
 				};
 			};
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 1/4] dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml
  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
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-03 20:18 UTC (permalink / raw)
  To: Alex Elder; +Cc: linux-clk, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: clock: stale critical clock claim in
  toshiba,tc9564-clock.yaml
--

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

dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml

This commit adds the Device Tree binding schema, clock and reset ID
headers, and MAINTAINERS entries for the Toshiba TC9564 clock and reset
controller.

> diff --git a/Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml b/Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml
> new file mode 100644
> index 0000000000000..2217eaea05e21
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml

[ ... ]

> +  The clock controller exposes a set of simple gated clocks, which are
> +  controlled by two registers.  Each is derived from one of the internal
> +  fixed-rate clocks.  A total of 21 gated clocks are implemented within
> +  the chip, but support for enabling and disabling only a subset of them
> +  is provided at this time.  Two clocks (I2C and PCIE) are marked critical
> +  to make it clear that they should never be disabled.

[Severity: Low]
Should this last sentence about the I2C and PCIE clocks be removed or
reworded?  After the v5 update, neither this schema nor
include/dt-bindings/clock/toshiba,tc9564.h marks TC9564_CLK_I2C or
TC9564_CLK_PCIE that way anymore, leaving the description stale.

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 3/4] clk: toshiba: introduce a TC9564 clock driver
  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
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-03 20:22 UTC (permalink / raw)
  To: Alex Elder; +Cc: linux-clk, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] clk: tc9564: reversed devres order frees aux_data before aux
  device destroy
- [Medium] clk: tc9564: memory leak of aux_data on ida_alloc() failure
- [Medium] clk: tc9564: rate-based parent lookup breaks orphan clocks
  and probe order
- [Low] clk: tc9564: duplicate of_clk_hw_onecell_get() and unused
  clock_data slots
--

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

clk: toshiba: introduce a TC9564 clock driver

This commit adds a platform clock driver for the Toshiba TC9564 SoC that
registers a PLL, fixed-rate divider clocks, and gate clocks controlled by
two MMIO registers.  It also creates an auxiliary device for the embedded
reset controller.

> 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 @@

[ ... ]

> +/* 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];
> +
> +	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);
> +	}

[Severity: Medium]
Can fixed_hw_find_by_rate() permanently fail probe when the input clock
provider has not registered yet or runs at a rate other than 25 MHz?

If the input clock provider at index 0 is not yet registered, pll_register()
succeeds with pll_hw orphaned at rate 0 instead of deferring probe.  Each
fixed clock inherits rate 0, so fixed_hw_find_by_rate() returns NULL and
tc9564_clk_probe() fails permanently with -EINVAL.

clk_hw_get_rate() also reads core->parent and core->rate without
prepare_lock, racing with clk_core_reparent_orphans() if the input clock
registers concurrently.  Selecting each gate's parent statically by index
into fixed_init[] avoids both problems and supports any input frequency.

[ ... ]

> +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);
> +}

[Severity: Low]
As reported by Jerome Brunet on v4 [1], gate_of_clk_hw_onecell_get()
duplicates of_clk_hw_onecell_get() only because clock_data prepends pll_hw
and fixed_hws slots that are never read after probe.

Keeping fixed_hws in a local array during probe and sizing clock_data to
GATE_COUNT allows passing of_clk_hw_onecell_get and clock_data directly to
devm_of_clk_add_hw_provider().

> +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)
> +{
> +	struct tc9564_aux_data *aux_data;
> +	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");

[Severity: Medium]
Does this return leak aux_data when ida_alloc() fails?

> +	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);
> +}

[Severity: Medium]
Can reset_adev_free() free aux_data while the reset auxiliary device is
still registered and cause a use-after-free in tc9564_reset_probe()?

__devm_auxiliary_device_create() registers auxiliary_device_destroy() as a
devres action before devm_add_action_or_reset() registers reset_adev_free().
Because devres runs actions in LIFO order, unbinding the clock device frees
aux_data and releases adev->id before adev is removed from the bus:

CPU0                                  CPU1
devres_release_all()
  reset_adev_free(adev)
    ida_free(&reset_ids, adev->id)
    kfree(aux_data)
                                      tc9564_reset_probe()
                                        aux_data = dev_get_platdata(dev)
                                        reset->regs = aux_data->regs
                                                      <-- use-after-free
  auxiliary_device_destroy(adev)

Freeing adev->id before adev is deleted also allows a concurrent probe of
another TC9564 instance to reuse the ID and fail with -EEXIST.  Allocating
aux_data with devm_kzalloc_obj() and registering an IDA-release devres
action before __devm_auxiliary_device_create() keeps the teardown order safe.

[1] https://lore.kernel.org/r/179631464066.3767986.13287406761565723851.b4-reply@b4

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 2/4] reset: toshiba: introduce a TC9564 reset driver
  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
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-03 20:24 UTC (permalink / raw)
  To: Alex Elder; +Cc: linux-clk, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] reset: tc9564: missing readback to flush posted PCIe write in
  reset_update()
- [Low] reset: tc9564: .name = KBUILD_MODNAME duplicates auxiliary
  driver name
--

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

reset: toshiba: introduce a TC9564 reset driver

This commit adds an auxiliary reset controller driver for the Toshiba TC9564
SoC, using MMIO registers mapped and passed as platform data by the TC9564
clock driver.

> diff --git a/drivers/reset/reset-tc9564.c b/drivers/reset/reset-tc9564.c
> new file mode 100644
> index 0000000000000..218be6dbbb2a3
> --- /dev/null
> +++ b/drivers/reset/reset-tc9564.c

[ ... ]

> +static int reset_update(struct reset_controller_dev *rcdev,
> +			unsigned long id, bool assert)
> +{
> +	struct tc9564_reset *reset = dev_get_drvdata(rcdev->dev);
> +	const struct reset_init *init = &reset_init[id];
> +	void __iomem *reg = reset->regs + init->offset;
> +	u32 mask = BIT(init->bit);
> +	u32 val;
> +
> +	guard(spinlock_irqsave)(&reset->lock);
> +
> +	val = readl(reg);
> +	if (assert)
> +		val |= mask;
> +	else
> +		val &= ~mask;
> +	writel(val, reg);
> +
> +	return 0;
> +}

[Severity: Medium]
Should reset_update() read back reg with readl() after writel() to flush the
posted PCIe write?

The reset registers are on PCIe Function 0 BAR 4, where writel() is posted.
Returning before the write reaches the hardware can shorten consumer reset
delays or let subsequent accesses to XGMAC 1 on Function 1 BAR 4 race with
the reset update.

[ ... ]

> +static struct auxiliary_driver tc9564_reset_driver = {
> +	.name = KBUILD_MODNAME,
> +	.probe = tc9564_reset_probe,
> +	.id_table = tc9564_reset_ids,
> +};
> +module_auxiliary_driver(tc9564_reset_driver);

[Severity: Low]
Does setting .name = KBUILD_MODNAME duplicate the auxiliary driver name?

module_auxiliary_driver() already passes KBUILD_MODNAME as the module name to
__auxiliary_driver_register(), which formats driver.name as "%s.%s" when
auxdrv->name is set.  This registers the driver as reset_tc9564.reset_tc9564
in sysfs and logs; omitting .name registers it as reset_tc9564.

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v5 4/4] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node
  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
  0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-03 20:28 UTC (permalink / raw)
  To: Alex Elder; +Cc: linux-clk, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] arm64: dts: qcom: BAR4 translation fails for TC9564
  clock-controller@1004
- [Medium] clk: toshiba: devm_reset_register() frees aux_data before
  auxdev destroy
- [Medium] clk: toshiba: devm_reset_register() leaks aux_data on
  ida_alloc() failure
--

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

arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node

This commit adds a fixed 25 MHz crystal clock node and a TC9564 clock and
reset controller node under pci-ep-bus@4 in the QCS6490 RB3Gen2 device tree.

> diff --git a/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts b/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts
> index 682bcbc0b466b..87035745b6720 100644
> --- a/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts
> +++ b/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts

[ ... ]

> @@ -969,6 +976,14 @@ pci-ep-bus@4 {
>  					#size-cells = <1>;
>  					/* Map 0x0-0x1fffff to BAR 4 */
>  					ranges = <0x0  0x4 0x0 0x0  0x200000>;
> +
> +					clock-controller@1004 {
> +						compatible = "toshiba,tc9564-clock";
> +						reg = <0x1004 0x10>;
> +						clocks = <&tc9564_xo_board>;
> +						#clock-cells = <1>;
> +						#reset-cells = <1>;
> +					};

[Severity: High]
Can address translation for clock-controller@1004 succeed with dev@0,0's
static placeholder ranges?

During PCI enumeration, pci_setup_device() -> pci_set_of_node() binds the
static dev@0,0 node to the PCI device.  Because pci_device_to_OF_node() is
then already non-NULL, the final fixup of_pci_make_dev_node() returns early
without updating dev@0,0's ranges property.

When tc9564_function_probe() populates the bus, of_address_to_resource()
translates reg = <0x1004 0x10> via the stale BAR 4 range to 0x85004, outside
pcie1's 0x40300000 MEM window in kodiak.dtsi.  of_device_alloc() then hits
WARN_ON(rc) and tc9564_clk_probe() fails with -EINVAL.

[Severity: Medium]
In the bound clock driver from commit "clk: toshiba: introduce a TC9564
clock driver", does devm_reset_register() in drivers/clk/clk-tc9564.c free
aux_data and the IDA ID while the auxiliary device is still registered?

__devm_auxiliary_device_create() registers auxiliary_device_destroy() as a
devres action before returning.  Registering reset_adev_free() afterwards
means LIFO teardown frees aux_data and calls ida_free() before
auxiliary_device_destroy() removes the device:

CPU0                                CPU1
devres_release_all()
  reset_adev_free()
    ida_free(&reset_ids, adev->id)
    kfree(aux_data)
                                    tc9564_reset_probe()
                                      aux_data = dev_get_platdata(dev)
                                      aux_data->regs  <-- use-after-free
  auxiliary_device_destroy()

Registering cleanup for aux_data and the IDA ID before creating the
auxiliary device avoids both the use-after-free and early ID reuse.

[Severity: Medium]
Also in drivers/clk/clk-tc9564.c:devm_reset_register(), does the ida_alloc()
error path leak aux_data?  aux_data is allocated with kzalloc_obj() right
before ida_alloc(), but an allocation failure returns dev_err_probe()
without calling kfree(aux_data).

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-12-03 20:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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-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-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-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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox