Skip to contentSkip to conversation

clk: tc9564: introduce clock and reset drivers

PATCH In review Alex Elder 4 participants 11 messages Dec 1

Subsystems (6)
lore
Share & tools
lore

Alex Elder

author
#0 lore raw

v4 cover clk: tc9564: introduce clock and reset drivers

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 3. It includes adding an "imply" statement in the Kconfig for the PCI driver (located under drivers/misc).

-Alex

Version 3 is available here:
https://lore.kernel.org/all/[email protected]/

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.

Version 2 is available here:
https://lore.kernel.org/all/[email protected]/

Between version 2 and version 3:
- Added Lorenzo's Reviewed-by on the devicetree binding patch
- The devicetree binding now uses @kernel.org e-mail addresses for Daniel and me
- Cleaned up the patch header text in patch 2
- The Kconfig option now depends on RESET_CONTROLLER
- The Kconfig option can now be enabled if COMPILE_TEST is enabled
- The generic gate clock controller code is now used rather than implementing a custom one
- Only the gate clock IDs are now published in "toshiba,tc9564.h"; the PLL and internal fixed clocks are implemented and accessed only within "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
- There are no more "unnecessary newlines" in the initialization arrays for clocks and resets
- An update to the DTS file is now included as the last patch in this series

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

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

 .../bindings/clock/toshiba,tc9564-clock.yaml  |  74 ++++
 MAINTAINERS                                   |  17 +
 arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts  |  15 +
 drivers/clk/Kconfig                           |   9 +
 drivers/clk/Makefile                          |   1 +
 drivers/clk/clk-tc9564.c                      | 401 ++++++++++++++++++
 drivers/misc/Kconfig                          |   1 +
 drivers/reset/Kconfig                         |   7 +
 drivers/reset/Makefile                        |   1 +
 drivers/reset/reset-tc9564.c                  | 190 +++++++++
 include/dt-bindings/clock/toshiba,tc9564.h    |  26 ++
 include/dt-bindings/reset/toshiba,tc9564.h    |  24 ++
 include/linux/soc/qcom/tc9563.h               |   9 +
 13 files changed, 775 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: 253f86660c1f882fbf554db5eaa34bc5d66dc7e8

Signature · 1 line
2.53.0
author
#1 lore raw

PATCH v4 1/4 dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml

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

---
v4: - Reset IDs are now defined in a separate header file
- Clock and reset ID symbols now have a "TC9564_" prefix.
- A missing space in a guard #endif has been added

 .../bindings/clock/toshiba,tc9564-clock.yaml  | 74 +++++++++++++++++++
 MAINTAINERS                                   | 15 ++++
 include/dt-bindings/clock/toshiba,tc9564.h    | 26 +++++++
 include/dt-bindings/reset/toshiba,tc9564.h    | 24 ++++++
 4 files changed, 139 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
Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml new file +74 -0
new file mode 100644
index 0000000000000..0f55d18c61193
@@ -0,0 +1,74 @@
+# 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 <[email protected]>
+  - Alex Elder <[email protected]>
+  - Daniel Thompson <[email protected]>
+
+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 that clock is
+  multiplied by a PLL, 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, and the I2C and PCIE resets
+  are treated as critical.
+
+  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>;
+    };
MAINTAINERS +15 -0
index e7652ab2061a2..0a30100222123 100644
@@ -28723,6 +28723,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 <[email protected]>
+M:	Alex Elder <[email protected]>
+M:	Daniel Thompson <[email protected]>
+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 <[email protected]>
 M:	Daniel Thompson <[email protected]>
@@ -28730,6 +28738,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 <[email protected]>
+M:	Alex Elder <[email protected]>
+M:	Daniel Thompson <[email protected]>
+S:	Maintained
+F:	include/dt-bindings/reset/toshiba,tc9564.h
+
 TOSHIBA WMI HOTKEYS DRIVER
 M:	Azael Avalos <[email protected]>
 L:	[email protected]
include/dt-bindings/clock/toshiba,tc9564.h new file +26 -0
new file mode 100644
index 0000000000000..540fef71016be
@@ -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	/* critical */
+#define TC9564_CLK_PCIE		1	/* critical */
+#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__ */
include/dt-bindings/reset/toshiba,tc9564.h new file +24 -0
new file mode 100644
index 0000000000000..942a284b0d2f8
@@ -0,0 +1,24 @@
+/* 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_I2C		0	/* critical */
+#define TC9564_RST_PCIE		1	/* critical */
+#define TC9564_RST_MSIGEN	2
+
+#define TC9564_RST_MAC0_MAC	3
+#define TC9564_RST_MAC0_PMA	4
+#define TC9564_RST_MAC0_XPCS	5
+
+#define TC9564_RST_MAC1_MAC	6
+#define TC9564_RST_MAC1_PMA	7
+#define TC9564_RST_MAC1_XPCS	8
+
+#endif /* __RESET_TOSHIBA_TC9564_H__ */
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v4 2/4 clk: toshiba: introduce a TC9564 clock driver

In reply to Alex Elder

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.

---
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
MAINTAINERS +1 -0
index 0a30100222123..aa52ede9a1aa3 100644
@@ -28729,6 +28729,7 @@ M:	Alex Elder <[email protected]>
 M:	Daniel Thompson <[email protected]>
 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
drivers/clk/Kconfig +8 -0
index 6bfa2c8fffe1b..a3d89c55f17a5 100644
@@ -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
drivers/clk/Makefile +1 -0
index 99377a13ebc57..d67cfb6d623d3 100644
@@ -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
drivers/clk/clk-tc9564.c new file +401 -0

401 lines not on this page · raw message

drivers/misc/Kconfig +1 -0
index c40e89cc57243..391d0ba79c96f 100644
@@ -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
include/linux/soc/qcom/tc9563.h +9 -0
index 086f37a40d801..2045ffb179133 100644
@@ -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 */
Signature · 1 line
2.53.0
#3 lore raw

Re: [PATCH v4 2/4] clk: toshiba: introduce a TC9564 clock driver

Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] clk: tc9564: conflicting OF clock providers registered on same DT node - [Medium] clk: tc9564…

Thank you for your contribution! Sashiko AI review found 5 potential issues to consider:
- [Medium] clk: tc9564: conflicting OF clock providers registered on same DT node
- [Medium] clk: tc9564: premature kfree() of reset_aux outside reset_dev_release()
- [Medium] clk: tc9564: missing select AUXILIARY_BUS in Kconfig for COMMON_CLK_TC9564
- [Low] clk: tc9564: hardcoded adev->id in devm_reset_setup() breaks multi-instance
- [Low] clk: tc9564: unused lock field, write-only gate_data, and reset header
--

commit 36b5909afe8d085c12caff8d18e2b1828c4c5a70
Author: Alex Elder <[email protected]>

clk: toshiba: introduce a TC9564 clock driver

This commit adds a platform driver for the Toshiba TC9564 SoC clock controller and registers an auxiliary device for the SoC reset controller.

Quoted 5 lines
drivers/clk/Kconfig +0 -0
index 6bfa2c8fffe1b..a3d89c55f17a5 100644

drivers/clk/Kconfig config COMMON_CLK_CDCE706 · line 194

Quoted 10 lines
drivers/clk/Kconfig +7 -0
@@ -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.

[Severity: Medium]
Should COMMON_CLK_TC9564 select AUXILIARY_BUS? devm_reset_setup() calls auxiliary_device_init() and auxiliary_device_add(), which are only built when CONFIG_AUXILIARY_BUS is enabled, so linking fails with undefined references when no other enabled driver selects AUXILIARY_BUS.

Quoted 6 lines
drivers/clk/clk-tc9564.c new file +0 -0
new file mode 100644
index 0000000000000..ec72a0207fd87
@@ -0,0 +1,401 @@

[ ... ]

Quoted 3 lines
drivers/clk/clk-tc9564.c new file +3 -0
+#include <linux/platform_device.h>
+#include <linux/reset-controller.h>
+#include <linux/slab.h>

[ ... ]

drivers/clk/clk-tc9564.c line 44

Quoted 7 lines
drivers/clk/clk-tc9564.c new file +7 -0
+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;
+};

[Severity: Low]
This isn't a bug, but <linux/reset-controller.h> and clock->lock appear to be unused leftovers from splitting out the reset driver, and clock->gate_data is only written in gate_clock_setup() and never read.

[ ... ]

Quoted 28 lines
drivers/clk/clk-tc9564.c new file +28 -0
+/* 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)
+{

[ ... ]

Quoted 14 lines
drivers/clk/clk-tc9564.c new file +14 -0
+	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)
+{

[ ... ]

drivers/clk/clk-tc9564.c line 281

Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10 -0
+	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;
+}

[Severity: Medium]
Should only gate_clock_setup() call devm_of_clk_add_hw_provider()?

Calling devm_of_clk_add_hw_provider() in pll_setup(), fixed_clock_setup(), and gate_clock_setup() registers three OF clock providers on the same dev->of_node. Because the PLL and fixed-factor clocks are wired as internal parents via clk_hw pointers and the DT binding only exports the gate clocks, the extra providers mark the DT node initialized and run of_clk_set_defaults() before the gate clocks exist. Also, in of_clk_get_hw_from_clkspec(), any out-of-range clock index falls through gate_data and fixed_data to of_clk_hw_simple_get(), returning pll_hw instead of -EINVAL.

Quoted 30 lines
drivers/clk/clk-tc9564.c new file +30 -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;
+

drivers/clk/clk-tc9564.c line 321

Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10 -0
+	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;

[Severity: Low]
Will hardcoding adev->id = 0 fail when a system has more than one TC9564 instance? A second instance registers the same "clk_tc9564.tc9564-reset.0" name on the auxiliary bus and fails in auxiliary_device_add() with -EEXIST.

Quoted 9 lines
drivers/clk/clk-tc9564.c new file +9 -0
+	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);

drivers/clk/clk-tc9564.c line 340

Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10 -0
+		return ret;
+	}
+
+	ret = auxiliary_device_add(adev);
+	if (ret) {
+		auxiliary_device_uninit(adev);
+		kfree(reset_aux);
+
+		return ret;
+	}

[Severity: Medium]
Can freeing reset_aux right after auxiliary_device_uninit(adev) in devm_reset_setup() and reset_adev_remove() cause a use-after-free on adev->dev?

Once auxiliary_device_init() succeeds, adev->dev is a reference-counted device whose memory must be freed in its release callback. If another reference to adev->dev is still held when auxiliary_device_uninit() calls put_device() (or when CONFIG_DEBUG_KOBJECT_RELEASE delays release), kfree() frees reset_aux before reset_dev_release() runs. Moving kfree(adev_to_reset_aux(to_auxiliary_dev(dev))) into reset_dev_release() and dropping the kfree() calls after auxiliary_device_uninit() avoids this.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author
#4 lore raw

Re: [PATCH v4 2/4] clk: toshiba: introduce a TC9564 clock driver

Quoted 5 lines · On 12/1/26 10:21 AM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 5 potential issues to consider:
- [Medium] clk: tc9564: conflicting OF clock providers registered on same DT node
- [Medium] clk: tc9564: premature kfree() of reset_aux outside

Quoted 8 lines

reset_dev_release()
- [Medium] clk: tc9564: missing select AUXILIARY_BUS in Kconfig for COMMON_CLK_TC9564
- [Low] clk: tc9564: hardcoded adev->id in devm_reset_setup() breaks multi-instance
- [Low] clk: tc9564: unused lock field, write-only gate_data, and reset header
--

Summary of what's explained further below is that all of these are legitimate issues that I will address in the next version of the series. The first one will take a little more work to resolve.

-Alex

Quoted 16 lines

commit 36b5909afe8d085c12caff8d18e2b1828c4c5a70
Author: Alex Elder <[email protected]>

clk: toshiba: introduce a TC9564 clock driver

This commit adds a platform driver for the Toshiba TC9564 SoC clock controller and registers an auxiliary device for the SoC reset controller.

Quoted 8 lines
drivers/clk/Kconfig +0 -0
index 6bfa2c8fffe1b..a3d89c55f17a5 100644
@@ -185,6 +185,14 @@ config COMMON_CLK_CDCE706
  	help
  	  This driver supports TI CDCE706 programmable 3-PLL clock synthesizer.
 
Quoted 13 lines

drivers/clk/Kconfig config COMMON_CLK_CDCE706 · line 194

Quoted 7 lines
drivers/clk/Kconfig +7 -0
+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.

[Severity: Medium]
Should COMMON_CLK_TC9564 select AUXILIARY_BUS? devm_reset_setup() calls auxiliary_device_init() and auxiliary_device_add(), which are only built when CONFIG_AUXILIARY_BUS is enabled, so linking fails with undefined references when no other enabled driver selects AUXILIARY_BUS.

This is correct. COMMON_CLK_TC9564 needs to select AUXILIARY_BUS for exactly this reason.

I ran COMPILE_TEST builds on a bunch of architectures, but never saw this problem. It looks like this already gets enabled on all the architectures that allow this to build (arm64, arm, riscv, loongarch, arc, mips).

Anyway, I will add this select statement for version 5.

Quoted 11 lines
Quoted 6 lines
drivers/clk/clk-tc9564.c new file +0 -0
new file mode 100644
index 0000000000000..ec72a0207fd87
@@ -0,0 +1,401 @@

[ ... ]

Quoted 3 lines
drivers/clk/clk-tc9564.c new file +3 -0
+#include <linux/platform_device.h>
+#include <linux/reset-controller.h>
+#include <linux/slab.h>

[ ... ]

Quoted 12 lines

drivers/clk/clk-tc9564.c line 44

Quoted 7 lines
drivers/clk/clk-tc9564.c new file +7 -0
+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;
+};

[Severity: Low]
This isn't a bug, but <linux/reset-controller.h> and clock->lock appear to be unused leftovers from splitting out the reset driver, and clock->gate_data is only written in gate_clock_setup() and never read.

Yes the lock and reset-controller include were detritus that should have been removed when the reset driver was separated into its own file. I'll fix this.

It's also true that there's no need to store the gate_data pointer. It gets cleaned up by devm_of_clk_release_provider() and we don't need it once the provider is added. I will drop this field from this structure.

Quoted 61 lines

[ ... ]

Quoted 28 lines
drivers/clk/clk-tc9564.c new file +28 -0
+/* 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)
+{

[ ... ]

Quoted 14 lines
drivers/clk/clk-tc9564.c new file +14 -0
+	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)
+{

[ ... ]

drivers/clk/clk-tc9564.c line 281

Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10 -0
+	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;
+}

[Severity: Medium]
Should only gate_clock_setup() call devm_of_clk_add_hw_provider()?

Quoted 9 lines

Calling devm_of_clk_add_hw_provider() in pll_setup(), fixed_clock_setup(), and gate_clock_setup() registers three OF clock providers on the same dev->of_node. Because the PLL and fixed-factor clocks are wired as internal parents via clk_hw pointers and the DT binding only exports the gate clocks, the extra providers mark the DT node initialized and run of_clk_set_defaults() before the gate clocks exist. Also, in of_clk_get_hw_from_clkspec(), any out-of-range clock index falls through gate_data and fixed_data to of_clk_hw_simple_get(), returning pll_hw instead of -EINVAL.

OK this was something I obviously didn't understand. I followed the suggestion of setting up multiple hardware providers on the same device, and now Jerome's "That would means have a 2 cells controller" makes a little more sense to me.

I'm going to have to look further into this and reconsider how to implement these different types of clocks.

Quoted 38 lines
Quoted 38 lines
drivers/clk/clk-tc9564.c new file +38 -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;
+
Quoted 8 lines

drivers/clk/clk-tc9564.c line 321

Quoted 2 lines
drivers/clk/clk-tc9564.c new file +2 -0
+	adev->id = 0;
+	adev->name = TC9564_RESET_DEV_NAME;

[Severity: Low]
Will hardcoding adev->id = 0 fail when a system has more than one TC9564 instance? A second instance registers the same "clk_tc9564.tc9564-reset.0" name on the auxiliary bus and fails in auxiliary_device_add() with -EEXIST.

I mistakenly thought that this would be unique, because each TC9564 instance would have a distinct clock device.

I'll add an IDA to assign a unique ID value for each created reset device.

Quoted 26 lines
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +9 -0
+	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);

drivers/clk/clk-tc9564.c line 340

Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10 -0
+		return ret;
+	}
+
+	ret = auxiliary_device_add(adev);
+	if (ret) {
+		auxiliary_device_uninit(adev);
+		kfree(reset_aux);
+
+		return ret;
+	}

[Severity: Medium]
Can freeing reset_aux right after auxiliary_device_uninit(adev) in devm_reset_setup() and reset_adev_remove() cause a use-after-free on adev->dev?

Quoted 7 lines

Once auxiliary_device_init() succeeds, adev->dev is a reference-counted device whose memory must be freed in its release callback. If another reference to adev->dev is still held when auxiliary_device_uninit() calls put_device() (or when CONFIG_DEBUG_KOBJECT_RELEASE delays release), kfree() frees reset_aux before reset_dev_release() runs. Moving kfree(adev_to_reset_aux(to_auxiliary_dev(dev))) into reset_dev_release() and dropping the kfree() calls after auxiliary_device_uninit() avoids this.

The adev pointer refers to a part of the reset_aux structure (which also contains data not touched after the auxiliary driver probes). The lifetime of the reset_aux structure is therefore the same as the lifetime of the auxiliary device.

The auxiliary device structure won't be touched again once its release callback has been called, so the device lifetime ends after that. That means the reset_aux lifetime should end at that point as well.

The comments above auxiliary_device_init() explain that memory cleanup is expected to be handled in the release callback.

So this is a correct observation, and the fix will be:
- Do not call kfree(reset_aux) here.
- Do not call that kfree() in reset_adev_remove()
- Instead have reset_dev_release() call that kfree().

author
#5 lore raw

PATCH v4 3/4 reset: toshiba: introduce a TC9564 reset driver

In reply to Alex Elder

Define a new auxiliary device driver that manages resets implemented by the Toshiba TC9564 SoC. The TC9564 clock driver creates 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 I2C and PCIE resets treated as CRITICAL, meaning their state should never change (and any attempt to do so results in a warning).

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

The reset driver should normally be present whenever the TC9564 clock driver is enabled, so have the COMMON_CLK_TC9564 config option *imply* the reset driver's config option, RESET_TC9564.

---
v4: - This is a new patch containing a new auxiliary driver for the
reset device. This code was previously included in the clock driver.
- Checking for attempts to update "critical" resets is no longer done at assert/deassert time. Instead, the reset controller defines a new fwnode_xlate callback to check it at "get" time.
- The spinlock used to wrap read/modify/write updates to the reset control registers is now handled by guard().

 MAINTAINERS                  |   1 +
 drivers/clk/Kconfig          |   1 +
 drivers/reset/Kconfig        |   7 ++
 drivers/reset/Makefile       |   1 +
 drivers/reset/reset-tc9564.c | 190 +++++++++++++++++++++++++++++++++++
 5 files changed, 200 insertions(+)
 create mode 100644 drivers/reset/reset-tc9564.c
MAINTAINERS +1 -0
index aa52ede9a1aa3..8fe319f72eace 100644
@@ -28744,6 +28744,7 @@ M:	Lorenzo Bianconi <[email protected]>
 M:	Alex Elder <[email protected]>
 M:	Daniel Thompson <[email protected]>
 S:	Maintained
+F:	drivers/reset/reset-tc9564.c
 F:	include/dt-bindings/reset/toshiba,tc9564.h
 
 TOSHIBA WMI HOTKEYS DRIVER
drivers/clk/Kconfig +1 -0
index a3d89c55f17a5..c78c5a817adec 100644
@@ -187,6 +187,7 @@ config COMMON_CLK_CDCE706
 
 config COMMON_CLK_TC9564
 	tristate "Toshiba TC9564 clock support"
+	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
drivers/reset/Kconfig +7 -0
index 673bca1e594e0..fe46877ea1cda 100644
@@ -369,6 +369,13 @@ config RESET_SUNXI
 	help
 	  This enables the reset driver for Allwinner SoCs.
 
+config RESET_TC9564
+	tristate "Toshiba TC9564 reset controller driver"
+	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
drivers/reset/Makefile +1 -0
index 2fe527a7be8e1..2144095c14b3d 100644
@@ -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
drivers/reset/reset-tc9564.c new file +190 -0

190 lines not on this page · raw message

Signature · 1 line
2.53.0
#6 lore raw

Re: [PATCH v4 3/4] reset: toshiba: introduce a TC9564 reset driver

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] reset: tc9564: missing select AUXILIARY_BUS in Kconfig causes link failure --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] reset: tc9564: missing select AUXILIARY_BUS in Kconfig causes link failure
--

commit ddbbc3eed2e024c35658a17b6bfba3123a686580
Author: Alex Elder <[email protected]>

reset: toshiba: introduce a TC9564 reset driver

This commit introduces an auxiliary device driver for the Toshiba TC9564 reset controller and adds its Kconfig and Makefile entries.

Quoted 5 lines
drivers/reset/Kconfig +0 -0
index 673bca1e594e0..fe46877ea1cda 100644

drivers/reset/Kconfig config RESET_SUNXI · line 378

Quoted 10 lines
drivers/reset/Kconfig +7 -0
@@ -369,6 +369,13 @@ config RESET_SUNXI
 	help
 	  This enables the reset driver for Allwinner SoCs.
 
+config RESET_TC9564
+	tristate "Toshiba TC9564 reset controller driver"
+	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.
+

[Severity: Medium]
Should RESET_TC9564 select AUXILIARY_BUS?

reset-tc9564.c uses module_auxiliary_driver(), so enabling RESET_TC9564 without another symbol selecting AUXILIARY_BUS fails to link with undefined references to __auxiliary_driver_register() and auxiliary_driver_unregister().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
author
#7 lore raw

Re: [PATCH v4 3/4] reset: toshiba: introduce a TC9564 reset driver

Quoted 4 lines · On 12/1/26 10:16 AM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] reset: tc9564: missing select AUXILIARY_BUS in Kconfig causes link failure

Yes, I will fix this in v5 (which I will send in the next day or so unless I get substantial feedback before then).

Quoted 29 lines

--

commit ddbbc3eed2e024c35658a17b6bfba3123a686580
Author: Alex Elder <[email protected]>

reset: toshiba: introduce a TC9564 reset driver

This commit introduces an auxiliary device driver for the Toshiba TC9564 reset controller and adds its Kconfig and Makefile entries.

Quoted 5 lines
drivers/reset/Kconfig +0 -0
index 673bca1e594e0..fe46877ea1cda 100644

drivers/reset/Kconfig config RESET_SUNXI · line 378

Quoted 10 lines
drivers/reset/Kconfig +7 -0
@@ -369,6 +369,13 @@ config RESET_SUNXI
  	help
  	  This enables the reset driver for Allwinner SoCs.
 
+config RESET_TC9564
+	tristate "Toshiba TC9564 reset controller driver"
+	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.
+

[Severity: Medium]
Should RESET_TC9564 select AUXILIARY_BUS?

Quoted 4 lines

reset-tc9564.c uses module_auxiliary_driver(), so enabling RESET_TC9564 without another symbol selecting AUXILIARY_BUS fails to link with undefined references to __auxiliary_driver_register() and auxiliary_driver_unregister().

Yes, RESET_TC9564 needs to select AUXILIARY_BUS for exactly the reason stated. My cross-compile builds using "defconfig" did not catch this, because AUXILIARY_BUS is already enabled for arm64, arm, riscv, loongarch, and mips.

-Alex

maintainer Reviewed-by on v4 3/4
#8 lore raw

Re: [PATCH v4 3/4] reset: toshiba: introduce a TC9564 reset driver

In reply to Alex Elder
Quoted 56 lines · Alex Elder

Define a new auxiliary device driver that manages resets implemented by the Toshiba TC9564 SoC. The TC9564 clock driver creates 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 I2C and PCIE resets treated as CRITICAL, meaning their state should never change (and any attempt to do so results in a warning).

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

The reset driver should normally be present whenever the TC9564 clock driver is enabled, so have the COMMON_CLK_TC9564 config option *imply* the reset driver's config option, RESET_TC9564.

---
v4: - This is a new patch containing a new auxiliary driver for the
reset device. This code was previously included in the clock driver.
- Checking for attempts to update "critical" resets is no longer done at assert/deassert time. Instead, the reset controller defines a new fwnode_xlate callback to check it at "get" time.
- The spinlock used to wrap read/modify/write updates to the reset control registers is now handled by guard().

 MAINTAINERS                  |   1 +
 drivers/clk/Kconfig          |   1 +
 drivers/reset/Kconfig        |   7 ++
 drivers/reset/Makefile       |   1 +
 drivers/reset/reset-tc9564.c | 190 +++++++++++++++++++++++++++++++++++
 5 files changed, 200 insertions(+)
 create mode 100644 drivers/reset/reset-tc9564.c
MAINTAINERS +1 -0
index aa52ede9a1aa3..8fe319f72eace 100644
@@ -28744,6 +28744,7 @@ M:	Lorenzo Bianconi <[email protected]>
 M:	Alex Elder <[email protected]>
 M:	Daniel Thompson <[email protected]>
 S:	Maintained
+F:	drivers/reset/reset-tc9564.c
 F:	include/dt-bindings/reset/toshiba,tc9564.h
 
 TOSHIBA WMI HOTKEYS DRIVER
drivers/clk/Kconfig +0 -0
index a3d89c55f17a5..c78c5a817adec 100644

drivers/clk/Kconfig config COMMON_CLK_CDCE706 · line 190

Quoted 4 lines
drivers/clk/Kconfig +1 -0
@@ -187,6 +187,7 @@ config COMMON_CLK_CDCE706
 
 config COMMON_CLK_TC9564
 	tristate "Toshiba TC9564 clock support"
+	imply RESET_TC9564

I'd make RESET_TC9564 default COMMON_CLK_TC9564 instead.

Otherwise,

regards
Philipp

Reviewed-by on v4 3/4
#9 lore raw

Re: [PATCH v4 3/4] reset: toshiba: introduce a TC9564 reset driver

In reply to Alex Elder
Quoted 14 lines

Define a new auxiliary device driver that manages resets implemented by the Toshiba TC9564 SoC. The TC9564 clock driver creates 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 I2C and PCIE resets treated as CRITICAL, meaning their state should never change (and any attempt to do so results in a warning).

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

Quoted 7 lines

The reset driver should normally be present whenever the TC9564 clock driver is enabled, so have the COMMON_CLK_TC9564 config option *imply* the reset driver's config option, RESET_TC9564.

Quoted 271 lines

---
v4: - This is a new patch containing a new auxiliary driver for the
reset device. This code was previously included in the clock driver.
- Checking for attempts to update "critical" resets is no longer done at assert/deassert time. Instead, the reset controller defines a new fwnode_xlate callback to check it at "get" time.
- The spinlock used to wrap read/modify/write updates to the reset control registers is now handled by guard().

 MAINTAINERS                  |   1 +
 drivers/clk/Kconfig          |   1 +
 drivers/reset/Kconfig        |   7 ++
 drivers/reset/Makefile       |   1 +
 drivers/reset/reset-tc9564.c | 190 +++++++++++++++++++++++++++++++++++
 5 files changed, 200 insertions(+)
 create mode 100644 drivers/reset/reset-tc9564.c
MAINTAINERS +1 -0
index aa52ede9a1aa3..8fe319f72eace 100644
@@ -28744,6 +28744,7 @@ M:	Lorenzo Bianconi <[email protected]>
 M:	Alex Elder <[email protected]>
 M:	Daniel Thompson <[email protected]>
 S:	Maintained
+F:	drivers/reset/reset-tc9564.c
 F:	include/dt-bindings/reset/toshiba,tc9564.h
 
 TOSHIBA WMI HOTKEYS DRIVER
drivers/clk/Kconfig +1 -0
index a3d89c55f17a5..c78c5a817adec 100644
@@ -187,6 +187,7 @@ config COMMON_CLK_CDCE706
 
 config COMMON_CLK_TC9564
 	tristate "Toshiba TC9564 clock support"
+	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
drivers/reset/Kconfig +7 -0
index 673bca1e594e0..fe46877ea1cda 100644
@@ -369,6 +369,13 @@ config RESET_SUNXI
 	help
 	  This enables the reset driver for Allwinner SoCs.
 
+config RESET_TC9564
+	tristate "Toshiba TC9564 reset controller driver"
+	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
drivers/reset/Makefile +1 -0
index 2fe527a7be8e1..2144095c14b3d 100644
@@ -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
drivers/reset/reset-tc9564.c new file +190 -0
new file mode 100644
index 0000000000000..017ea9f962a2b
@@ -0,0 +1,190 @@
+// 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 *reg;	/* Mapped register 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_PCIE] = {
+		.offset = RESET0_OFFSET,
+		.bit = 9,
+	},
+	[TC9564_RST_I2C] = {
+		.offset = RESET0_OFFSET,
+		.bit = 12,
+	},
+	[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->reg + 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->reg + 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 reset_fwnode_xlate(struct reset_controller_dev *rcdev,
+			    const struct fwnode_reference_args *reset_spec)
+{
+	unsigned int id = reset_spec->args[0];
+
+	if (id >= rcdev->nr_resets)
+		return -EINVAL;
+
+	/* Warn on any attempt to get a critical reset */
+	if (WARN_ON(id == TC9564_RST_I2C) || WARN_ON(id == TC9564_RST_PCIE))
+		return -EINVAL;
+
+	return id;
+}
+
+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->reg = aux_data->reg;
+	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->fwnode_reset_n_cells = 1;
+	rcdev->fwnode_xlate = reset_fwnode_xlate;
+	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");
Signature · 1 line
2.53.0
author
#10 lore raw

PATCH v4 4/4 arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node

In reply to Alex Elder

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.

---
v4: - The 25 MHz clock node is no longer defined as inside the PCI switch
within the TC9564. It's a board-level oscillator.
- Added Lorenzo's Reviewed-by tag.

 arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +15 -0
index 682bcbc0b466b..87035745b6720 100644
@@ -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>;
+					};
 				};
 			};
 
Signature · 1 line
2.53.0