clk: tc9564: introduce a clock and reset driver
v3 cover clk: tc9564: introduce a clock and reset driver
This series introduces a devicetree binding and single 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.
The first version of this series included a system controller, which has since been removed. This version addresses all review feedback received on version 2.
-Alex
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
The version prior to v2 of this code was included in this series:
https://lore.kernel.org/all/[email protected]/
Between that series (v1) and this one (v2):
- There is no more syscon, so its devicetree binding and driver have been dropped
- The clock and reset components now have a single devicetree binding
- We no longer use a syscon-generated regmap for accessing the common range of memory used by multiple drivers; specific sub-ranges are instead mapped
- The clock and reset drivers have been combined into a single driver located under drivers/clk
- The config option for the driver includes COMPILE_TEST, as requested (last month) by Jerome Brunet
- The help text for the config option is simplified, first suggested by Philipp Zabel
- The driver now names clocks using dev_name() rather than trying to hand-code a unique name into a fixed-size name array (also suggested by Jerome)
- Certain functions now always return 0, which simplifies callers so they can simply return what the called function returns
- As suggested by sashiko, a counted-by field in a flex array is now assigned explicitly
Alex Elder (3):
dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml
clk: toshiba: introduce a TC9564 clock/reset driver
arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node
.../bindings/clock/toshiba,tc9564-clock.yaml | 73 +++ MAINTAINERS | 9 + arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts | 15 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-tc9564.c | 456 ++++++++++++++++++ include/dt-bindings/clock/toshiba,tc9564.h | 40 ++ 7 files changed, 603 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml create mode 100644 drivers/clk/clk-tc9564.c create mode 100644 include/dt-bindings/clock/toshiba,tc9564.h
base-commit: 9437046953b2fb3bf55b36582450ea0267df82a7
Signature · 1 line
2.53.0
PATCH v3 1/3 dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml
Define the binding for the clock and reset controller that present in the Toshiba TC9564 SoC.
---
v3: - Added Lorenzo's Reviewed-by
- Changed to @kernel.org e-mails for Daniel and me
- Only the gated clock IDs are now published in "toshiba,tc9564.h"; the PLL and internal fixed clocks are implemented and accessed only within "clk-tc9564.c"
.../bindings/clock/toshiba,tc9564-clock.yaml | 73 +++++++++++++++++++ MAINTAINERS | 8 ++ include/dt-bindings/clock/toshiba,tc9564.h | 40 ++++++++++ 3 files changed, 121 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml create mode 100644 include/dt-bindings/clock/toshiba,tc9564.h
Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml new file +73 -0
@@ -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 Controller + +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 and reset IDs are defined <dt-bindings/clock/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 +8 -0
@@ -28716,6 +28716,14 @@ F: Documentation/devicetree/bindings/media/i2c/toshiba,tc358743.yaml F: drivers/media/i2c/tc358743* F: include/media/i2c/tc358743.h +TOSHIBA TC9564 CLOCK/RESET 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]>
include/dt-bindings/clock/toshiba,tc9564.h new file +40 -0
@@ -0,0 +1,40 @@ +/* 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 CLOCK_I2C 0/* critical */ +#define CLOCK_PCIE 1/* critical */ +#define CLOCK_MSIGEN 2 + +#define CLOCK_MAC0_TX 3 +#define CLOCK_MAC0_RX 4 +#define CLOCK_MAC0_125M 5 +#define CLOCK_MAC0_ALL 6 + +#define CLOCK_MAC1_TX 7 +#define CLOCK_MAC1_RX 8 +#define CLOCK_MAC1_125M 9 +#define CLOCK_MAC1_ALL 10 + +/* Reset IDs */ + +#define RESET_I2C 0/* critical */ +#define RESET_PCIE 1/* critical */ +#define RESET_MSIGEN 2 + +#define RESET_MAC0_MAC 3 +#define RESET_MAC0_PMA 4 +#define RESET_MAC0_XPCS 5 + +#define RESET_MAC1_MAC 6 +#define RESET_MAC1_PMA 7 +#define RESET_MAC1_XPCS 8 + +#endif /* __CLOCK_TOSHIBA_TC9564_H__*/
Signature · 1 line
2.53.0
PATCH v3 2/3 clk: toshiba: introduce a TC9564 clock/reset driver
In reply to Alex ElderDefine a new platform driver that manages clocks and resets implemented by the Toshiba TC9564 SoC. There are 21 gate clocks that can be enabled and disabled, but currently only the clocks that are (or will soon be) used are defined to be controllable. There are also 13 resets that can be asserted or deasserted, but support for some of these is omitted as well.
Two registers manage the state of the clocks, and two others manage the state of the resets. All four registers are found in a region mapped for MMIO. The region is provided via a BAR on one of the PCI functions embedded in the TC9564 SoC.
The I2C and PCIE clocks and resets are treated as CRITICAL, meaning their state should never be changed (and a warning is issued if changing their state is attempted).
---
v3: - Fixed problems/garbage in the patch header
- The Kconfig option now depends on RESET_CONTROLLER, and can now be enabled if COMPILE_TEST is enabled
- The generic gate clock controller code is now used rather than implementing a custom one
- The PLL and internal fixed clocks IDs are no longer available outside "clk-tc9564.c"
- The PLL is initialialized, followed by all fixed rate clocks, followed by the gate clocks, to ensure each clock's parent is initialized before the clock is
- Updating the reset registers (read/modify/write) is now protected by a spinlock
- "Unnecessary newlines" have been removed
MAINTAINERS | 1 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-tc9564.c | 456 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 467 insertions(+) create mode 100644 drivers/clk/clk-tc9564.c
MAINTAINERS +1 -0
@@ -28722,6 +28722,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 +9 -0
@@ -185,6 +185,15 @@ config COMMON_CLK_CDCE706 help This driver supports TI CDCE706 programmable 3-PLL clock synthesizer. +config COMMON_CLK_TC9564 + tristate "Toshiba TC9564 clock and reset support" + depends on TC9564_PCI || COMPILE_TEST + depends on RESET_CONTROLLER + default TC9564_PCI + help + This enables support for the clock and reset controllers embedded + in the Toshiba TC9564 SoC. + config COMMON_CLK_TPS68470 tristate "Clock Driver for TI TPS68470 PMIC" depends on I2C
drivers/clk/Makefile +1 -0
@@ -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 +456 -0
456 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v3 3/3 arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node
In reply to Alex ElderAdd 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.
---
v3: - This patch was previously not included in the series
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +15 -0
@@ -890,6 +890,13 @@ pcie@0,0 { pinctrl-0 = <&tc9563_resx_n>; pinctrl-names = "default"; + tc9564_xo_board: clock-25000000 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <25000000>; + clock-output-names = "tc9564_xo_board"; + }; + pcie1_switch0_dsp1: pcie@1,0 { reg = <0x20800 0x0 0x0 0x0 0x0>; #address-cells = <3>;
@@ -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
[email protected]
AI reviewRe: [PATCH v3 3/3] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] arm64: dts: qcom: clock-25000000 under pcie@0,0 shifts tc9563 port indexing --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] arm64: dts: qcom: clock-25000000 under pcie@0,0 shifts tc9563 port indexing
--
commit c4e2dd0c5c7aea169ea475dfdf59cb2e475d33be
Author: Alex Elder <[email protected]>
arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node
This commit adds a devicetree node for the Toshiba TC9564 clock and reset controller along with a 25 MHz fixed-clock node supplying it.
Quoted 8 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +0
-0@@ -890,6 +890,13 @@ pcie@0,0 { pinctrl-0 = <&tc9563_resx_n>; pinctrl-names = "default";
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts pcie@0,0 { · line 902
Quoted 10 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +7
-0+ tc9564_xo_board: clock-25000000 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <25000000>; + clock-output-names = "tc9564_xo_board"; + }; + pcie1_switch0_dsp1: pcie@1,0 { reg = <0x20800 0x0 0x0 0x0 0x0>; #address-cells = <3>;
[Severity: High]
Does placing clock-25000000 as the first child of pcie@0,0 shift the downstream port indexing in the tc9563 power control driver?
Both tc9563_pwrctrl_probe() and tc9563_pwrctrl_parse_reset_line() map the direct children of the pci1179,0623 node positionally to TC9563_DSP1, TC9563_DSP2, and TC9563_VDSP:
drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c:tc9563_pwrctrl_probe() {
...
port = TC9563_USP;
for_each_child_of_node_scoped(node, child) {
if (++port >= TC9563_MAX)
break;
ret = tc9563_pwrctrl_parse_device_dt(child, &tc9563->cfg[port]);
...
}With clock-25000000 ahead of pcie@1,0, pcie@2,0, and pcie@3,0, the driver treats clock-25000000 as TC9563_DSP1, shifts pcie@1,0 and pcie@2,0 into TC9563_DSP2 and TC9563_VDSP (misassociating per-port settings, reset GPIOs, and the integrated Ethernet endpoint), and stops before reaching pcie@3,0. It also violates Documentation/devicetree/bindings/pci/toshiba,tc9563.yaml, which only permits pcie@[1-2],0 and pcie@[3],0 child nodes. Should tc9564_xo_board live under the root /clocks node instead?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Quoted 10 lines · Alex Elder
This series introduces a devicetree binding and single 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.
Quoted 5 lines
The first version of this series included a system controller, which has since been removed. This version addresses all review feedback received on version 2.
-Alex
As I provided last time, a copy of a working DTS file that uses this binding and driver is available here:
https://github.com/riscstar/linux/tree/tc9564-dts
Isolated in this commit:
https://github.com/riscstar/linux/commit/e1f8e40b04137798ffd410fc675d9eccfb1c13f9
-Alex
Quoted 69 lines
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
- TheKconfigoption now depends onRESET_CONTROLLER
- TheKconfigoption can now be enabled ifCOMPILE_TESTis 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 seriesThe version prior to v2 of this code was included in this series:
https://lore.kernel.org/all/[email protected]/Between that series (v1) and this one (v2):
- There is no more syscon, so its devicetree binding and driver have been dropped
- The clock and reset components now have a single devicetree binding
- We no longer use a syscon-generated regmap for accessing the common range of memory used by multiple drivers; specific sub-ranges are instead mapped
- The clock and reset drivers have been combined into a single driver located underdrivers/clk
- The config option for the driver includesCOMPILE_TEST, as requested (last month) by Jerome Brunet
- The help text for the config option is simplified, first suggested by Philipp Zabel
- The driver now names clocks usingdev_name()rather than trying to hand-code a unique name into a fixed-size name array (also suggested by Jerome)
- Certain functions now always return 0, which simplifies callers so they can simply return what the called function returns
- As suggested by sashiko, a counted-by field in a flex array is now assigned explicitlyAlex Elder (3):
dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml
clk: toshiba: introduce a TC9564 clock/reset driver
arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node.../bindings/clock/toshiba,tc9564-clock.yaml | 73 +++ MAINTAINERS | 9 + arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts | 15 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-tc9564.c | 456 ++++++++++++++++++ include/dt-bindings/clock/toshiba,tc9564.h | 40 ++ 7 files changed, 603 insertions(+)create mode 100644
Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yamlcreate mode 100644drivers/clk/clk-tc9564.c
create mode 100644include/dt-bindings/clock/toshiba,tc9564.hbase-commit:
9437046953b2fb3bf55b36582450ea0267df82a7
Re: [PATCH v3 3/3] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node
In reply to [email protected]Quoted 5 lines · On 11/25/26 2:28 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] arm64: dts: qcom: clock-25000000 under pcie@0,0 shifts tc9563 port indexing
--
This was a great catch on a seemingly unrelated problem.
I will consider how to address it. Off hand I can think of two options, but I'm sure there are others:
- Move the tc9564_xo_board *after* the downstream ports (after the end of the pcie@3,0 node). In this case I would add a clear comment in the DTS file explaining why this is necessary.
- Make the logic in "pci-pwrctrl-tc9563.c" more robust, possibly by skipping nodes that aren't of type "pci" (or possibly "pciex"?).
I think the second option is better, but I'm open to other suggestions.
However, at the very end of this message there is another observation that might make the above moot. I think this clock node should probably be defined closer to the root of the tree. I'll verify that and will fix it.
Quoted 16 lines
commit
c4e2dd0c5c7aea169ea475dfdf59cb2e475d33be
Author: Alex Elder <[email protected]>arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node
This commit adds a devicetree node for the Toshiba TC9564 clock and reset controller along with a 25 MHz fixed-clock node supplying it.
Quoted 8 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +0
-0@@ -890,6 +890,13 @@ pcie@0,0 { pinctrl-0 = <&tc9563_resx_n>; pinctrl-names = "default";
Quoted 14 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts pcie@0,0 { · line 902
Quoted 10 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +7
-0+ tc9564_xo_board: clock-25000000 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <25000000>; + clock-output-names = "tc9564_xo_board"; + }; + pcie1_switch0_dsp1: pcie@1,0 { reg = <0x20800 0x0 0x0 0x0 0x0>; #address-cells = <3>;[Severity: High]
Does placing clock-25000000 as the first child of pcie@0,0 shift the downstream port indexing in the tc9563 power control driver?
I think it currently does.
Quoted 10 lines
Both
tc9563_pwrctrl_probe()andtc9563_pwrctrl_parse_reset_line()map the direct children of the pci1179,0623 node positionally toTC9563_DSP1,TC9563_DSP2, andTC9563_VDSP:drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c:tc9563_pwrctrl_probe() { ... port = TC9563_USP; for_each_child_of_node_scoped(node, child) { if (++port >= TC9563_MAX) break;
If the second option above is chosen, this function should be updated the same way.
Quoted 11 lines
ret = tc9563_pwrctrl_parse_device_dt(child, &tc9563->cfg[port]); ... }With clock-25000000 ahead of pcie@1,0, pcie@2,0, and pcie@3,0, the driver treats clock-25000000 as
TC9563_DSP1, shifts pcie@1,0 and pcie@2,0 intoTC9563_DSP2andTC9563_VDSP(misassociating per-port settings, reset GPIOs, and the integrated Ethernet endpoint), and stops before reaching pcie@3,0. It also violatesDocumentation/devicetree/bindings/pci/toshiba,tc9563.yaml, which only permits pcie@[1-2],0 and pcie@[3],0 child nodes. Shouldtc9564_xo_boardlive under the root /clocks node instead?
The 25 MHz oscillator comes from *outside* the TC9564 chip, not under the upstream PCIe switch port.
For this reason, it should be defined somewhere on the board, not within the TC9564 chip.
I will investigate the right way to represent this and will correct it.
-Alex
Re: [PATCH v3 2/3] clk: toshiba: introduce a TC9564 clock/reset driver
In reply to Alex ElderQuoted 41 lines · Alex Elder
Define a new platform driver that manages clocks and resets implemented by the Toshiba TC9564 SoC. There are 21 gate clocks that can be enabled and disabled, but currently only the clocks that are (or will soon be) used are defined to be controllable. There are also 13 resets that can be asserted or deasserted, but support for some of these is omitted as well.
Two registers manage the state of the clocks, and two others manage the state of the resets. All four registers are found in a region mapped for MMIO. The region is provided via a BAR on one of the PCI functions embedded in the TC9564 SoC.
The I2C and PCIE clocks and resets are treated as CRITICAL, meaning their state should never be changed (and a warning is issued if changing their state is attempted).
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>---
v3: - Fixed problems/garbage in the patch header
- TheKconfigoption now depends onRESET_CONTROLLER, and can now be enabled ifCOMPILE_TESTis enabled
- The generic gate clock controller code is now used rather than implementing a custom one
- The PLL and internal fixed clocks IDs are no longer available outside "clk-tc9564.c"
- The PLL is initialialized, followed by all fixed rate clocks, followed by the gate clocks, to ensure each clock's parent is initialized before the clock is
- Updating the reset registers (read/modify/write) is now protected by a spinlock
- "Unnecessary newlines" have been removedMAINTAINERS | 1 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-tc9564.c | 456 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 467 insertions(+) create mode 100644 drivers/clk/clk-tc9564.c
[...]
Quoted 6 lines
drivers/clk/clk-tc9564.c new file +0
-0@@ -0,0 +1,456 @@
[...]
Quoted 4 lines
drivers/clk/clk-tc9564.c new file +4
-0+ +static int reset_update (struct reset_controller_dev *rcdev, +unsigned long id,bool assert) +{
drivers/clk/clk-tc9564.c line 322
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+const struct reset_init *reset; +struct tc9564_clock *clock; +unsigned long flags; +void __iomem *reg; +u32 mask; +u32 val; + +/* Warn on any attempt to change state of a critical reset */ +if (WARN_ON (id ==RESET_I2C ) ||WARN_ON (id ==RESET_PCIE )) +return 0 ;
Can't this be checked at reset_control_get() time (in fwnode_xlate) so that critical reset controls aren't given out to consumers in the first place?
drivers/clk/clk-tc9564.c line 329
Quoted 7 lines
drivers/clk/clk-tc9564.c new file +7
-0+ + clock =dev_get_drvdata (rcdev->dev); + reset = &reset_init[id]; + reg = clock->ioaddr + reset->offset; + mask =BIT (reset->bit); + +spin_lock_irqsave (&clock->lock, flags);
Consider using guard(spinlock).
regards
Philipp
Re: [PATCH v3 2/3] clk: toshiba: introduce a TC9564 clock/reset driver
In reply to Alex ElderQuoted 91 lines · Alex Elder
Define a new platform driver that manages clocks and resets implemented by the Toshiba TC9564 SoC. There are 21 gate clocks that can be enabled and disabled, but currently only the clocks that are (or will soon be) used are defined to be controllable. There are also 13 resets that can be asserted or deasserted, but support for some of these is omitted as well.
Two registers manage the state of the clocks, and two others manage the state of the resets. All four registers are found in a region mapped for MMIO. The region is provided via a BAR on one of the PCI functions embedded in the TC9564 SoC.
The I2C and PCIE clocks and resets are treated as CRITICAL, meaning their state should never be changed (and a warning is issued if changing their state is attempted).
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>---
v3: - Fixed problems/garbage in the patch header
- TheKconfigoption now depends onRESET_CONTROLLER, and can now be enabled ifCOMPILE_TESTis enabled
- The generic gate clock controller code is now used rather than implementing a custom one
- The PLL and internal fixed clocks IDs are no longer available outside "clk-tc9564.c"
- The PLL is initialialized, followed by all fixed rate clocks, followed by the gate clocks, to ensure each clock's parent is initialized before the clock is
- Updating the reset registers (read/modify/write) is now protected by a spinlock
- "Unnecessary newlines" have been removedMAINTAINERS | 1 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-tc9564.c | 456 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 467 insertions(+) create mode 100644 drivers/clk/clk-tc9564.cMAINTAINERS +1
-0@@ -28722,6 +28722,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 DRIVERdrivers/clk/Kconfig +9
-0@@ -185,6 +185,15 @@ config COMMON_CLK_CDCE706 help This driver supports TI CDCE706 programmable 3-PLL clock synthesizer. +config COMMON_CLK_TC9564 + tristate "Toshiba TC9564 clock and reset support" + depends on TC9564_PCI || COMPILE_TEST + depends on RESET_CONTROLLER + default TC9564_PCI + help + This enables support for the clock and reset controllers embedded + in the Toshiba TC9564 SoC. + config COMMON_CLK_TPS68470 tristate "Clock Driver for TI TPS68470 PMIC" depends on I2Cdrivers/clk/Makefile +1
-0@@ -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.odrivers/clk/clk-tc9564.c new file +0
-0
drivers/clk/clk-tc9564.c line 5
Quoted 5 lines
drivers/clk/clk-tc9564.c new file +5
-0@@ -0,0 +1,456 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* +* Copyright (C) 2026 by RISCstar Solutions Corporation. All rights reserved. +*/
Hi Alex,
I think the patch is fine, just few nits inline.
Regards,
Lorenzo
Quoted 34 lines
drivers/clk/clk-tc9564.c new file +34
-0+ +#include <linux/bits.h> +#include <linux/clk-provider.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/reset-controller.h> +#include <linux/slab.h> + +#include <dt-bindings/clock/toshiba,tc9564.h> + +/* +* Define the offsets for the registers that implement clock enable/disable +* bits for gated clocks, and those that implement reset assertion bits for +* resets. These offsets are relative to the address space defined in +* devicetree. +*/ +#define CLOCK0_OFFSET 0x0 +#define CLOCK1_OFFSET 0x8 + +#define RESET0_OFFSET 0x4 +#define RESET1_OFFSET 0xc + +/* +* 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. +* +* The clk_hw[] array within a clk_hw_onecell_data structure tracks all +* of them. The following definitions describe how these are laid out +* based on their indexes into the clk_hw[] array. Gate clocks are first, +* so their "raw" public IDs can be used as indexes into the array. +*/ +#define GATE_BASE 0
drivers/clk/clk-tc9564.c line 49
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+#define FIXED_BASE (GATE_BASE + GATE_COUNT) +#define CLOCK_PLL (FIXED_BASE + FIXED_COUNT) + +/* The total number of clocks in the clk_hw[] array */ +#define CLOCK_COUNT (GATE_COUNT + FIXED_COUNT + 1) + +struct tc9564_clock { +void __iomem *ioaddr;/* Mapped clock/reset registers */ +spinlock_t lock;/* Protects reset register updates */ +struct clk_hw_onecell_data *clk_data;
I think it would be more readable to have 3 different pointers here:
- struct clk_hw_onecell_data *clk_pll_data;
- struct clk_hw_onecell_data *clk_fixed_rate_data;
- struct clk_hw_onecell_data *clk_gate_data;
(using the same logic you implemented for fixed_init, gate_init stucts).
Doing so, I guess the code that is allocating the clock data would be easier to manage.
Quoted 158 lines
drivers/clk/clk-tc9564.c new file +158
-0+struct reset_controller_dev rcdev; +}; + +/* Indexes into the fixed_init[] array */ +enum fixed_clock { +CLOCK_62_5M , +CLOCK_125M , +CLOCK_250M , +CLOCK_312_5M , +}; + +struct fixed_init { +const char *name; +unsigned int div;/* Rate is PLL rate divided by this */ +}; + +struct gate_init { +const char *name; +enum fixed_clock parent; +u8 offset;/* Control register offset (0x0 or 0x8) */ +u8 bit;/* Bit in the control register (0-31) */ +bool critical; +}; + +struct reset_init { +u8 offset;/* Control register offset (0x4 or 0xc) */ +u8 bit;/* Bit in the control register (0-31) */ +}; + +/* Add FIXED_BASE to index values to get their index into the clk_hw[] array */ +static const struct fixed_init fixed_init[] = { + [CLOCK_312_5M ] = { + .name ="312.5MHz" , + .div =4 , + }, + [CLOCK_250M ] = { + .name ="250MHz" , + .div =5 , + }, + [CLOCK_125M ] = { + .name ="125MHz" , + .div =10 , + }, + [CLOCK_62_5M ] = { + .name ="62.5MHz" , + .div =20 , + }, +}; +#define FIXED_COUNT ARRAY_SIZE(fixed_init) + +/* Add GATE_BASE to index values to get their index into the clk_hw[] array */ +static const struct gate_init gate_init[] = { + [CLOCK_MAC0_TX ] = { + .name ="MAC0-TX" , + .parent =CLOCK_312_5M , + .offset =CLOCK0_OFFSET , + .bit =7 , + }, + [CLOCK_PCIE ] = { + .name ="PCIe" , + .parent =CLOCK_250M , + .offset =CLOCK0_OFFSET , + .bit =9 , + .critical = true, + }, + [CLOCK_I2C ] = { + .name ="i2c" , + .parent =CLOCK_62_5M , + .offset =CLOCK0_OFFSET , + .bit =12 , + .critical = true, + }, + [CLOCK_MAC0_RX ] = { + .name ="MAC0-RX" , + .parent =CLOCK_312_5M , + .offset =CLOCK0_OFFSET , + .bit =14 , + }, + [CLOCK_MSIGEN ] = { + .name ="msigen" , + .parent =CLOCK_125M , + .offset =CLOCK0_OFFSET , + .bit =18 , + }, + [CLOCK_MAC0_125M ] = { + .name ="MAC0-125MHz" , + .parent =CLOCK_125M , + .offset =CLOCK0_OFFSET , + .bit =29 , + }, + [CLOCK_MAC0_ALL ] = { + .name ="MAC0-ALL" , + .parent =CLOCK_250M , + .offset =CLOCK0_OFFSET , + .bit =31 , + }, + [CLOCK_MAC1_TX ] = { + .name ="MAC1-TX" , + .parent =CLOCK_312_5M , + .offset =CLOCK1_OFFSET , + .bit =7 , + }, + [CLOCK_MAC1_RX ] = { + .name ="MAC1-RX" , + .parent =CLOCK_312_5M , + .offset =CLOCK1_OFFSET , + .bit =14 , + }, + [CLOCK_MAC1_125M ] = { + .name ="MAC1-125MHz" , + .parent =CLOCK_125M , + .offset =CLOCK1_OFFSET , + .bit =29 , + }, + [CLOCK_MAC1_ALL ] = { + .name ="MAC1-ALL" , + .parent =CLOCK_250M , + .offset =CLOCK1_OFFSET , + .bit =31 , + }, +}; +#define GATE_COUNT ARRAY_SIZE(gate_init) + +static const struct reset_init reset_init[] = { + [RESET_MAC0_MAC ] = { + .offset =RESET0_OFFSET , + .bit =7 , + }, + [RESET_PCIE ] = { + .offset =RESET0_OFFSET , + .bit =9 , + }, + [RESET_I2C ] = { + .offset =RESET0_OFFSET , + .bit =12 , + }, + [RESET_MSIGEN ] = { + .offset =RESET0_OFFSET , + .bit =18 , + }, + [RESET_MAC0_PMA ] = { + .offset =RESET0_OFFSET , + .bit =30 , + }, + [RESET_MAC0_XPCS ] = { + .offset =RESET0_OFFSET , + .bit =31 , + }, + [RESET_MAC1_MAC ] = { + .offset =RESET1_OFFSET , + .bit =7 , + }, + [RESET_MAC1_PMA ] = { + .offset =RESET1_OFFSET , + .bit =30 , + }, + [RESET_MAC1_XPCS ] = { + .offset =RESET1_OFFSET ,
drivers/clk/clk-tc9564.c line 217
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+ .bit = 31, + }, +}; +#define RESET_COUNT ARRAY_SIZE(reset_init) + +/* Caller must free the returned pointer if non-null */ +static const char *clock_name (struct device *dev,const char *name) +{ +return kasprintf (GFP_KERNEL ,"%s-%s" ,dev_name (dev), name); +}
nit: clock_name() is running just during probe, I would prefer to use dev_kasprintf() instead and get rid of the related kfree(). Moreover, clock_name() is just a wrapper around kasprintf(), do we really need it?
Quoted 242 lines
drivers/clk/clk-tc9564.c new file +239
-0+ +/* Initialize the PLL (parent is the input oscillator); called from probe */ +static int pll_init (struct device *dev,struct tc9564_clock *clock) +{ +struct clk_hw *hw; +const char *name; + +/* Initialize the PLL clock first (input oscillator is parent) */ + name =clock_name (dev,"pll" ); +if (!name) +return -ENOMEM ; + + hw =devm_clk_hw_register_fixed_factor_index (dev, name,0 ,0 ,50 ,1 ); +kfree (name); +if (IS_ERR (hw)) +return dev_err_probe (dev,PTR_ERR (hw), +"failed to register pll\n" ); + + clock->clk_data->hws[CLOCK_PLL ] = hw; + +return 0 ; +} + +/* Initialize the fixed rate clocks (PLL is parent); called from probe */ +static int fixed_clock_init (struct device *dev,struct tc9564_clock *clock) +{ +struct clk_hw_onecell_data *clk_data = clock->clk_data; +struct clk_hw *pll_hw = clk_data->hws[CLOCK_PLL ]; +const char *name; + +for (u32 i =0 ; i <FIXED_COUNT ; i++) { +const struct fixed_init *init = &fixed_init[i]; +struct clk_hw *hw; + + name =clock_name (dev, init->name); +if (!name) +return -ENOMEM ; + + hw =devm_clk_hw_register_fixed_factor_parent_hw (dev, name, + pll_hw,0 , +1 , init->div); +kfree (name); +if (IS_ERR (hw)) +return dev_err_probe (dev,PTR_ERR (hw), +"failed to register %s\n" , + init->name); + + clk_data->hws[FIXED_BASE + i] = hw; + } + +return 0 ; +} + +/* Initialize the gate clocks; called from probe */ +static int gate_clock_init (struct device *dev,struct tc9564_clock *clock) +{ +struct clk_hw_onecell_data *clk_data = clock->clk_data; +struct clk_hw *parent_hw; +const char *name; + +for (u32 i =0 ; i <GATE_COUNT ; i++) { +const struct gate_init *init = &gate_init[i]; +unsigned long flags; +struct clk_hw *hw; +void __iomem *reg; +u32 parent_index; + + name =clock_name (dev, init->name); +if (!name) +return -ENOMEM ; + +/* Each gate clock's parent is a fixed rate clock */ + parent_index =FIXED_BASE + init->parent; + parent_hw = clk_data->hws[parent_index]; + flags = init->critical ?CLK_IS_CRITICAL :0 ; + reg = clock->ioaddr + init->offset; + + hw =devm_clk_hw_register_gate_parent_hw (dev, name, parent_hw, + flags, reg, init->bit, +0 ,NULL ); +kfree (name); +if (IS_ERR (hw)) +return dev_err_probe (dev,PTR_ERR (hw), +"failed to register %s\n" , + init->name); + + clk_data->hws[GATE_BASE + i] = hw; + } + +return 0 ; +} + +static int reset_update (struct reset_controller_dev *rcdev, +unsigned long id,bool assert) +{ +const struct reset_init *reset; +struct tc9564_clock *clock; +unsigned long flags; +void __iomem *reg; +u32 mask; +u32 val; + +/* Warn on any attempt to change state of a critical reset */ +if (WARN_ON (id ==RESET_I2C ) ||WARN_ON (id ==RESET_PCIE )) +return 0 ; + + clock =dev_get_drvdata (rcdev->dev); + reset = &reset_init[id]; + reg = clock->ioaddr + reset->offset; + mask =BIT (reset->bit); + +spin_lock_irqsave (&clock->lock, flags); + + val =readl (reg); +if (assert) + val |= mask; +else + val &= ~mask; +writel (val, reg); + +spin_unlock_irqrestore (&clock->lock, flags); + +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_clock *clock =dev_get_drvdata (rcdev->dev); +const struct reset_init *reset = &reset_init[id]; +void __iomem *reg; + + reg = clock->ioaddr + reset->offset; + +return readl (reg) &BIT (reset->bit) ?1 :0 ; +} + +static const struct reset_control_ops reset_control_ops = { + .assert = reset_assert, + .deassert = reset_deassert, + .status = reset_status, +}; + +static int tc9564_clk_probe (struct platform_device *pdev) +{ +struct clk_hw_onecell_data *clk_data; +struct reset_controller_dev *rcdev; +struct tc9564_clock *clock; +struct device *dev = &pdev->dev; +struct device_node *np; +int ret; + + np =dev_of_node (dev); +if (!np) +return dev_err_probe (dev, -EINVAL ,"no devicetree node\n" ); + + clock =devm_kzalloc_obj (dev, *clock); +if (!clock) +return -ENOMEM ; + + clock->ioaddr =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (clock->ioaddr)) +return dev_err_probe (dev,PTR_ERR (clock->ioaddr), +"failed to map registers\n" ); + + clk_data =devm_kzalloc_flex (dev, *clock->clk_data, hws, +CLOCK_COUNT ); +if (!clk_data) +return -ENOMEM ; + clk_data->num =CLOCK_COUNT ; + + clock->clk_data = clk_data; + +/* We need the driver data pointer to initialize clocks and resets */ +dev_set_drvdata (dev, clock); + +/* Set up the clocks and register the provider */ + ret =pll_init (dev, clock); +if (ret) +return ret; + + ret =fixed_clock_init (dev, clock); +if (ret) +return ret; + + ret =gate_clock_init (dev, clock); +if (ret) +return ret; + + ret =devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, clk_data); +if (ret) +return dev_err_probe (dev, ret, +"failed to add clock provider\n" ); + +/* Set up and register the reset controller */ + rcdev = &clock->rcdev; + rcdev->ops = &reset_control_ops; + rcdev->owner =THIS_MODULE ; + rcdev->dev = dev; + rcdev->of_node = np; + rcdev->nr_resets =RESET_COUNT ; + +spin_lock_init (&clock->lock); + + 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 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, + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, +}; +module_platform_driver (tc9564_clk_driver); + +MODULE_DESCRIPTION ("Toshiba TC9564 Clock Driver" ); +MODULE_LICENSE ("GPL" );Signature · 1 line
2.53.0
Re: [PATCH v3 3/3] arm64: dts: qcom: qcs6490-rb3gen2: add TC9564 clock node
In reply to Alex ElderQuoted 4 lines
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.
Quoted 8 lines
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>---
v3: - This patch was previously not included in the seriesarch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
Quoted 37 lines
arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts +15
-0@@ -890,6 +890,13 @@ pcie@0,0 { pinctrl-0 = <&tc9563_resx_n>; pinctrl-names = "default"; + tc9564_xo_board: clock-25000000 { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <25000000>; + clock-output-names = "tc9564_xo_board"; + }; + pcie1_switch0_dsp1: pcie@1,0 { reg = <0x20800 0x0 0x0 0x0 0x0>; #address-cells = <3>;@@ -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
Re: [PATCH v3 2/3] clk: toshiba: introduce a TC9564 clock/reset driver
In reply to Philipp ZabelQuoted 60 lines · Philipp Zabel
Quoted 41 lines · Alex Elder
Define a new platform driver that manages clocks and resets implemented by the Toshiba TC9564 SoC. There are 21 gate clocks that can be enabled and disabled, but currently only the clocks that are (or will soon be) used are defined to be controllable. There are also 13 resets that can be asserted or deasserted, but support for some of these is omitted as well.
Two registers manage the state of the clocks, and two others manage the state of the resets. All four registers are found in a region mapped for MMIO. The region is provided via a BAR on one of the PCI functions embedded in the TC9564 SoC.
The I2C and PCIE clocks and resets are treated as CRITICAL, meaning their state should never be changed (and a warning is issued if changing their state is attempted).
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>---
v3: - Fixed problems/garbage in the patch header
- TheKconfigoption now depends onRESET_CONTROLLER, and can now be enabled ifCOMPILE_TESTis enabled
- The generic gate clock controller code is now used rather than implementing a custom one
- The PLL and internal fixed clocks IDs are no longer available outside "clk-tc9564.c"
- The PLL is initialialized, followed by all fixed rate clocks, followed by the gate clocks, to ensure each clock's parent is initialized before the clock is
- Updating the reset registers (read/modify/write) is now protected by a spinlock
- "Unnecessary newlines" have been removedMAINTAINERS | 1 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-tc9564.c | 456 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 467 insertions(+)create mode 100644
drivers/clk/clk-tc9564.c[...]
Quoted 6 lines
drivers/clk/clk-tc9564.c new file +0
-0@@ -0,0 +1,456 @@[...]
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+ +static int reset_update (struct reset_controller_dev *rcdev, +unsigned long id,bool assert) +{ +const struct reset_init *reset; +struct tc9564_clock *clock; +unsigned long flags; +void __iomem *reg; +u32 mask; +u32 val;
Quoted 8 lines
drivers/clk/clk-tc9564.c line 322
Quoted 4 lines
drivers/clk/clk-tc9564.c new file +4
-0+ +/* Warn on any attempt to change state of a critical reset */ +if (WARN_ON (id ==RESET_I2C ) ||WARN_ON (id ==RESET_PCIE )) +return 0 ;Can't this be checked at
reset_control_get()time (infwnode_xlate) so that critical reset controls aren't given out to consumers in the first place?
So I'd pass in a slightly modified fwnode_reset_simple_xlate() as the fwnode_xlate pointer? I hadn't thought about that, but it's a good suggestion.
Quoted 8 lines
drivers/clk/clk-tc9564.c line 329
Quoted 6 lines
drivers/clk/clk-tc9564.c new file +6
-0+ clock =dev_get_drvdata (rcdev->dev); + reset = &reset_init[id]; + reg = clock->ioaddr + reset->offset; + mask =BIT (reset->bit); + +spin_lock_irqsave (&clock->lock, flags);Consider using guard(spinlock).
OK I'll do that. This will be the first time I've used this...
Thanks.
-Alex
Quoted 2 lines
regards
Philipp
Re: [PATCH v3 2/3] clk: toshiba: introduce a TC9564 clock/reset driver
Quoted 2 lines · Alex Elder
Quoted 1 line · Philipp Zabel
On Mi, 2026-11-25 at 14:21 -0600, Alex Elder wrote:
[...]
Quoted 11 lines
Quoted 7 lines
drivers/clk/clk-tc9564.c line 322
Quoted 3 lines
drivers/clk/clk-tc9564.c new file +3
-0+/* Warn on any attempt to change state of a critical reset */ +if (WARN_ON (id ==RESET_I2C ) ||WARN_ON (id ==RESET_PCIE )) +return 0 ;Can't this be checked at
reset_control_get()time (infwnode_xlate) so that critical reset controls aren't given out to consumers in the first place?So I'd pass in a slightly modified
fwnode_reset_simple_xlate()as thefwnode_xlatepointer? I hadn't thought about that, but it's a good suggestion.
Exactly, and don't forget to set fwnode_reset_n_cells.
regards
Philipp
Re: [PATCH v3 1/3] dt-bindings: toshiba: introduce toshiba,tc9564-clock.yaml
In reply to Alex ElderQuoted 127 lines
Define the binding for the clock and reset controller that present in the Toshiba TC9564 SoC.
Reviewed-by Lorenzo Bianconi <[email protected]>Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>---
v3: - Added Lorenzo's Reviewed-by
- Changed to @kernel.org e-mails for Daniel and me
- Only the gated clock IDs are now published in "toshiba,tc9564.h"; the PLL and internal fixed clocks are implemented and accessed only within "clk-tc9564.c".../bindings/clock/toshiba,tc9564-clock.yaml | 73 +++++++++++++++++++ MAINTAINERS | 8 ++ include/dt-bindings/clock/toshiba,tc9564.h | 40 ++++++++++ 3 files changed, 121 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml create mode 100644 include/dt-bindings/clock/toshiba,tc9564.hDocumentation/devicetree/bindings/clock/toshiba,tc9564-clock.yaml new file +73
-0@@ -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 Controller + +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 and reset IDs are defined <dt-bindings/clock/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 +8
-0@@ -28332,6 +28332,14 @@ F: Documentation/devicetree/bindings/media/i2c/toshiba,tc358743.yaml F: drivers/media/i2c/tc358743* F: include/media/i2c/tc358743.h +TOSHIBA TC9564 CLOCK/RESET 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]>include/dt-bindings/clock/toshiba,tc9564.h new file +2
-0@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ +
include/dt-bindings/clock/toshiba,tc9564.h line 12
Quoted 10 lines
include/dt-bindings/clock/toshiba,tc9564.h new file +10
-0+/* +* Copyright (C) 2026 by RISCstar Solutions Corporation. All rights reserved. +*/ + +#ifndef __CLOCK_TOSHIBA_TC9564_H__ +#define __CLOCK_TOSHIBA_TC9564_H__ + +/* Clock IDs */ + +#define CLOCK_I2C 0/* critical */
Name seems a touch too generic.
If everybody named clock this way, we would be very likely to get collision in the DTS.
suggest TC9564_CLK_XXX
Quoted 16 lines
include/dt-bindings/clock/toshiba,tc9564.h new file +16
-0+#define CLOCK_PCIE 1/* critical */ +#define CLOCK_MSIGEN 2 + +#define CLOCK_MAC0_TX 3 +#define CLOCK_MAC0_RX 4 +#define CLOCK_MAC0_125M 5 +#define CLOCK_MAC0_ALL 6 + +#define CLOCK_MAC1_TX 7 +#define CLOCK_MAC1_RX 8 +#define CLOCK_MAC1_125M 9 +#define CLOCK_MAC1_ALL 10 + +/* Reset IDs */ + +#define RESET_I2C 0/* critical */
include/dt-bindings/clock/toshiba,tc9564.h line 38
Quoted 10 lines
include/dt-bindings/clock/toshiba,tc9564.h new file +10
-0+#define RESET_PCIE 1/* critical */ +#define RESET_MSIGEN 2 + +#define RESET_MAC0_MAC 3 +#define RESET_MAC0_PMA 4 +#define RESET_MAC0_XPCS 5 + +#define RESET_MAC1_MAC 6 +#define RESET_MAC1_PMA 7 +#define RESET_MAC1_XPCS 8
Those ids do not belong in include/dt-bindings/clock/
include/dt-bindings/clock/toshiba,tc9564.h line 40
Quoted 2 lines
include/dt-bindings/clock/toshiba,tc9564.h new file +2
-0+ +#endif /* __CLOCK_TOSHIBA_TC9564_H__*/
Nit: missing space before the closing */ in the comment.
Signature · 1 line
Jerome
Re: [PATCH v3 2/3] clk: toshiba: introduce a TC9564 clock/reset driver
In reply to Alex ElderQuoted 58 lines
Define a new platform driver that manages clocks and resets implemented by the Toshiba TC9564 SoC. There are 21 gate clocks that can be enabled and disabled, but currently only the clocks that are (or will soon be) used are defined to be controllable. There are also 13 resets that can be asserted or deasserted, but support for some of these is omitted as well.
Two registers manage the state of the clocks, and two others manage the state of the resets. All four registers are found in a region mapped for MMIO. The region is provided via a BAR on one of the PCI functions embedded in the TC9564 SoC.
The I2C and PCIE clocks and resets are treated as CRITICAL, meaning their state should never be changed (and a warning is issued if changing their state is attempted).
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>---
v3: - Fixed problems/garbage in the patch header
- TheKconfigoption now depends onRESET_CONTROLLER, and can now be enabled ifCOMPILE_TESTis enabled
- The generic gate clock controller code is now used rather than implementing a custom one
- The PLL and internal fixed clocks IDs are no longer available outside "clk-tc9564.c"
- The PLL is initialialized, followed by all fixed rate clocks, followed by the gate clocks, to ensure each clock's parent is initialized before the clock is
- Updating the reset registers (read/modify/write) is now protected by a spinlock
- "Unnecessary newlines" have been removedMAINTAINERS | 1 + drivers/clk/Kconfig | 9 + drivers/clk/Makefile | 1 + drivers/clk/clk-tc9564.c | 456 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 467 insertions(+) create mode 100644 drivers/clk/clk-tc9564.cMAINTAINERS +1
-0@@ -28338,6 +28338,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 DRIVERdrivers/clk/Kconfig +0
-0
drivers/clk/Kconfig config COMMON_CLK_CDCE706 · line 190
Quoted 6 lines
drivers/clk/Kconfig +3
-0@@ -185,6 +185,15 @@ config COMMON_CLK_CDCE706 help This driver supports TI CDCE706 programmable 3-PLL clock synthesizer. +config COMMON_CLK_TC9564 + tristate "Toshiba TC9564 clock and reset support" + depends on TC9564_PCI || COMPILE_TEST
Does it really depend on it ?
Shouldn't you imply this driver from TC9564_PCI instead ?
drivers/clk/Kconfig config COMMON_CLK_CDCE706 · line 192
Quoted 2 lines
drivers/clk/Kconfig +2
-0+ depends on RESET_CONTROLLER + default TC9564_PCI
... if you do, this is not needed
Quoted 27 lines
drivers/clk/Kconfig +4
-0+ help + This enables support for the clock and reset controllers embedded + in the Toshiba TC9564 SoC. + config COMMON_CLK_TPS68470 tristate "Clock Driver for TI TPS68470 PMIC" depends on I2Cdrivers/clk/Makefile +1
-0@@ -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.odrivers/clk/clk-tc9564.c new file +2
-0@@ -0,0 +1,456 @@ +// SPDX-License-Identifier: GPL-2.0-only +
drivers/clk/clk-tc9564.c line 12
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+/* +* Copyright (C) 2026 by RISCstar Solutions Corporation. All rights reserved. +*/ + +#include <linux/bits.h> +#include <linux/clk-provider.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/reset-controller.h>
Reset controllers belong in drivers/reset.
Please use the auxialiary or the MFD bus to handle this case.
Grep devm_auxiliary_device_create(), there are several example of this already.
Quoted 19 lines
drivers/clk/clk-tc9564.c new file +19
-0+#include <linux/slab.h> + +#include <dt-bindings/clock/toshiba,tc9564.h> + +/* +* Define the offsets for the registers that implement clock enable/disable +* bits for gated clocks, and those that implement reset assertion bits for +* resets. These offsets are relative to the address space defined in +* devicetree. +*/ +#define CLOCK0_OFFSET 0x0 +#define CLOCK1_OFFSET 0x8 + +#define RESET0_OFFSET 0x4 +#define RESET1_OFFSET 0xc + +/* +* 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
drivers/clk/clk-tc9564.c line 41
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+* set of gate clocks are children of the fixed rate clocks. +* +* The clk_hw[] array within a clk_hw_onecell_data structure tracks all +* of them. The following definitions describe how these are laid out +* based on their indexes into the clk_hw[] array. Gate clocks are first, +* so their "raw" public IDs can be used as indexes into the array. +*/ +#define GATE_BASE 0 +#define FIXED_BASE (GATE_BASE + GATE_COUNT) +#define CLOCK_PLL (FIXED_BASE + FIXED_COUNT)
That seems very fragile. Are sure you've defined all the clocks in the chip ? Because, if you did not and someone later add one, all the ids shift and it will be quite a mess to stay align with the DT ids.
drivers/clk/clk-tc9564.c line 49
Quoted 8 lines
drivers/clk/clk-tc9564.c new file +8
-0+ +/* The total number of clocks in the clk_hw[] array */ +#define CLOCK_COUNT (GATE_COUNT + FIXED_COUNT + 1) + +struct tc9564_clock { +void __iomem *ioaddr;/* Mapped clock/reset registers */ +spinlock_t lock;/* Protects reset register updates */ +struct clk_hw_onecell_data *clk_data;
That would means have a 2 cells controller. Those are rather uncommon for clock controllers. The representation here would be <&clk TYPE NUM>. Unnecessary complex IMO
drivers/clk/clk-tc9564.c line 59
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+struct reset_controller_dev rcdev; +}; + +/* Indexes into the fixed_init[] array */ +enum fixed_clock { +CLOCK_62_5M , +CLOCK_125M , +CLOCK_250M , +CLOCK_312_5M , +};
not sure why you need this
Quoted 14 lines
drivers/clk/clk-tc9564.c new file +14
-0+ +struct fixed_init { +const char *name; +unsigned int div;/* Rate is PLL rate divided by this */ +}; + +struct gate_init { +const char *name; +enum fixed_clock parent; +u8 offset;/* Control register offset (0x0 or 0x8) */ +u8 bit;/* Bit in the control register (0-31) */ +bool critical; +}; +
drivers/clk/clk-tc9564.c line 83
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+struct reset_init { +u8 offset;/* Control register offset (0x4 or 0xc) */ +u8 bit;/* Bit in the control register (0-31) */ +}; + +/* Add FIXED_BASE to index values to get their index into the clk_hw[] array */ +static const struct fixed_init fixed_init[] = { + [CLOCK_312_5M ] = { + .name ="312.5MHz" , + .div =4 ,
What you can do is store the DT id associated to each clock, because this is fixed. Then all you have to do is iterate over your 3 tables to fill the HW onecell.
This way, it is still possible to add clock later on without wrecking the DTS ids you can also put the onecell id of the parent.
Quoted 124 lines
drivers/clk/clk-tc9564.c new file +124
-0+ }, + [CLOCK_250M ] = { + .name ="250MHz" , + .div =5 , + }, + [CLOCK_125M ] = { + .name ="125MHz" , + .div =10 , + }, + [CLOCK_62_5M ] = { + .name ="62.5MHz" , + .div =20 , + }, +}; +#define FIXED_COUNT ARRAY_SIZE(fixed_init) + +/* Add GATE_BASE to index values to get their index into the clk_hw[] array */ +static const struct gate_init gate_init[] = { + [CLOCK_MAC0_TX ] = { + .name ="MAC0-TX" , + .parent =CLOCK_312_5M , + .offset =CLOCK0_OFFSET , + .bit =7 , + }, + [CLOCK_PCIE ] = { + .name ="PCIe" , + .parent =CLOCK_250M , + .offset =CLOCK0_OFFSET , + .bit =9 , + .critical = true, + }, + [CLOCK_I2C ] = { + .name ="i2c" , + .parent =CLOCK_62_5M , + .offset =CLOCK0_OFFSET , + .bit =12 , + .critical = true, + }, + [CLOCK_MAC0_RX ] = { + .name ="MAC0-RX" , + .parent =CLOCK_312_5M , + .offset =CLOCK0_OFFSET , + .bit =14 , + }, + [CLOCK_MSIGEN ] = { + .name ="msigen" , + .parent =CLOCK_125M , + .offset =CLOCK0_OFFSET , + .bit =18 , + }, + [CLOCK_MAC0_125M ] = { + .name ="MAC0-125MHz" , + .parent =CLOCK_125M , + .offset =CLOCK0_OFFSET , + .bit =29 , + }, + [CLOCK_MAC0_ALL ] = { + .name ="MAC0-ALL" , + .parent =CLOCK_250M , + .offset =CLOCK0_OFFSET , + .bit =31 , + }, + [CLOCK_MAC1_TX ] = { + .name ="MAC1-TX" , + .parent =CLOCK_312_5M , + .offset =CLOCK1_OFFSET , + .bit =7 , + }, + [CLOCK_MAC1_RX ] = { + .name ="MAC1-RX" , + .parent =CLOCK_312_5M , + .offset =CLOCK1_OFFSET , + .bit =14 , + }, + [CLOCK_MAC1_125M ] = { + .name ="MAC1-125MHz" , + .parent =CLOCK_125M , + .offset =CLOCK1_OFFSET , + .bit =29 , + }, + [CLOCK_MAC1_ALL ] = { + .name ="MAC1-ALL" , + .parent =CLOCK_250M , + .offset =CLOCK1_OFFSET , + .bit =31 , + }, +}; +#define GATE_COUNT ARRAY_SIZE(gate_init) + +static const struct reset_init reset_init[] = { + [RESET_MAC0_MAC ] = { + .offset =RESET0_OFFSET , + .bit =7 , + }, + [RESET_PCIE ] = { + .offset =RESET0_OFFSET , + .bit =9 , + }, + [RESET_I2C ] = { + .offset =RESET0_OFFSET , + .bit =12 , + }, + [RESET_MSIGEN ] = { + .offset =RESET0_OFFSET , + .bit =18 , + }, + [RESET_MAC0_PMA ] = { + .offset =RESET0_OFFSET , + .bit =30 , + }, + [RESET_MAC0_XPCS ] = { + .offset =RESET0_OFFSET , + .bit =31 , + }, + [RESET_MAC1_MAC ] = { + .offset =RESET1_OFFSET , + .bit =7 , + }, + [RESET_MAC1_PMA ] = { + .offset =RESET1_OFFSET , + .bit =30 , + }, + [RESET_MAC1_XPCS ] = { + .offset =RESET1_OFFSET ,
drivers/clk/clk-tc9564.c line 217
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+ .bit = 31, + }, +}; +#define RESET_COUNT ARRAY_SIZE(reset_init) + +/* Caller must free the returned pointer if non-null */ +static const char *clock_name (struct device *dev,const char *name) +{ +return kasprintf (GFP_KERNEL ,"%s-%s" ,dev_name (dev), name); +}
if you mean devm_kasprintf, it is possible but it means memory get wasted for the lifetime of the device. CCF already copies this on init, so it is useless after it.
That being said, it would be nice if the function name made it clear it allocate something. tc9564_clk_name_alloc() maybe ?
Quoted 111 lines
drivers/clk/clk-tc9564.c new file +111
-0+ +/* Initialize the PLL (parent is the input oscillator); called from probe */ +static int pll_init (struct device *dev,struct tc9564_clock *clock) +{ +struct clk_hw *hw; +const char *name; + +/* Initialize the PLL clock first (input oscillator is parent) */ + name =clock_name (dev,"pll" ); +if (!name) +return -ENOMEM ; + + hw =devm_clk_hw_register_fixed_factor_index (dev, name,0 ,0 ,50 ,1 ); +kfree (name); +if (IS_ERR (hw)) +return dev_err_probe (dev,PTR_ERR (hw), +"failed to register pll\n" ); + + clock->clk_data->hws[CLOCK_PLL ] = hw; + +return 0 ; +} + +/* Initialize the fixed rate clocks (PLL is parent); called from probe */ +static int fixed_clock_init (struct device *dev,struct tc9564_clock *clock) +{ +struct clk_hw_onecell_data *clk_data = clock->clk_data; +struct clk_hw *pll_hw = clk_data->hws[CLOCK_PLL ]; +const char *name; + +for (u32 i =0 ; i <FIXED_COUNT ; i++) { +const struct fixed_init *init = &fixed_init[i]; +struct clk_hw *hw; + + name =clock_name (dev, init->name); +if (!name) +return -ENOMEM ; + + hw =devm_clk_hw_register_fixed_factor_parent_hw (dev, name, + pll_hw,0 , +1 , init->div); +kfree (name); +if (IS_ERR (hw)) +return dev_err_probe (dev,PTR_ERR (hw), +"failed to register %s\n" , + init->name); + + clk_data->hws[FIXED_BASE + i] = hw; + } + +return 0 ; +} + +/* Initialize the gate clocks; called from probe */ +static int gate_clock_init (struct device *dev,struct tc9564_clock *clock) +{ +struct clk_hw_onecell_data *clk_data = clock->clk_data; +struct clk_hw *parent_hw; +const char *name; + +for (u32 i =0 ; i <GATE_COUNT ; i++) { +const struct gate_init *init = &gate_init[i]; +unsigned long flags; +struct clk_hw *hw; +void __iomem *reg; +u32 parent_index; + + name =clock_name (dev, init->name); +if (!name) +return -ENOMEM ; + +/* Each gate clock's parent is a fixed rate clock */ + parent_index =FIXED_BASE + init->parent; + parent_hw = clk_data->hws[parent_index]; + flags = init->critical ?CLK_IS_CRITICAL :0 ; + reg = clock->ioaddr + init->offset; + + hw =devm_clk_hw_register_gate_parent_hw (dev, name, parent_hw, + flags, reg, init->bit, +0 ,NULL ); +kfree (name); +if (IS_ERR (hw)) +return dev_err_probe (dev,PTR_ERR (hw), +"failed to register %s\n" , + init->name); + + clk_data->hws[GATE_BASE + i] = hw; + } + +return 0 ; +} + +static int reset_update (struct reset_controller_dev *rcdev, +unsigned long id,bool assert) +{ +const struct reset_init *reset; +struct tc9564_clock *clock; +unsigned long flags; +void __iomem *reg; +u32 mask; +u32 val; + +/* Warn on any attempt to change state of a critical reset */ +if (WARN_ON (id ==RESET_I2C ) ||WARN_ON (id ==RESET_PCIE )) +return 0 ; + + clock =dev_get_drvdata (rcdev->dev); + reset = &reset_init[id]; + reg = clock->ioaddr + reset->offset; + mask =BIT (reset->bit); +
drivers/clk/clk-tc9564.c line 338
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+spin_lock_irqsave (&clock->lock, flags); + + val =readl (reg); +if (assert) + val |= mask; +else + val &= ~mask; +writel (val, reg); + +spin_unlock_irqrestore (&clock->lock, flags);
look like you are re-implementing what regmap mmio provides here.
Quoted 102 lines
drivers/clk/clk-tc9564.c new file +102
-0+ +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_clock *clock =dev_get_drvdata (rcdev->dev); +const struct reset_init *reset = &reset_init[id]; +void __iomem *reg; + + reg = clock->ioaddr + reset->offset; + +return readl (reg) &BIT (reset->bit) ?1 :0 ; +} + +static const struct reset_control_ops reset_control_ops = { + .assert = reset_assert, + .deassert = reset_deassert, + .status = reset_status, +}; + +static int tc9564_clk_probe (struct platform_device *pdev) +{ +struct clk_hw_onecell_data *clk_data; +struct reset_controller_dev *rcdev; +struct tc9564_clock *clock; +struct device *dev = &pdev->dev; +struct device_node *np; +int ret; + + np =dev_of_node (dev); +if (!np) +return dev_err_probe (dev, -EINVAL ,"no devicetree node\n" ); + + clock =devm_kzalloc_obj (dev, *clock); +if (!clock) +return -ENOMEM ; + + clock->ioaddr =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (clock->ioaddr)) +return dev_err_probe (dev,PTR_ERR (clock->ioaddr), +"failed to map registers\n" ); + + clk_data =devm_kzalloc_flex (dev, *clock->clk_data, hws, +CLOCK_COUNT ); +if (!clk_data) +return -ENOMEM ; + clk_data->num =CLOCK_COUNT ; + + clock->clk_data = clk_data; + +/* We need the driver data pointer to initialize clocks and resets */ +dev_set_drvdata (dev, clock); + +/* Set up the clocks and register the provider */ + ret =pll_init (dev, clock); +if (ret) +return ret; + + ret =fixed_clock_init (dev, clock); +if (ret) +return ret; + + ret =gate_clock_init (dev, clock); +if (ret) +return ret; + + ret =devm_of_clk_add_hw_provider (dev, of_clk_hw_onecell_get, clk_data); +if (ret) +return dev_err_probe (dev, ret, +"failed to add clock provider\n" ); + +/* Set up and register the reset controller */ + rcdev = &clock->rcdev; + rcdev->ops = &reset_control_ops; + rcdev->owner =THIS_MODULE ; + rcdev->dev = dev; + rcdev->of_node = np; + rcdev->nr_resets =RESET_COUNT ; + +spin_lock_init (&clock->lock); + + 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 of_device_id tc9564_clock_match[] = { + { .compatible ="toshiba,tc9564-clock" , },
drivers/clk/clk-tc9564.c line 450
Quoted 10 lines
drivers/clk/clk-tc9564.c new file +10
-0+ { } +}; +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, + .probe_type =PROBE_PREFER_ASYNCHRONOUS ,
Why do you need to set this ? if you have a reason, you should probably add a comment about it
Signature · 1 line
Jerome
Re: [PATCH v3 2/3] clk: toshiba: introduce a TC9564 clock/reset driver
In reply to Lorenzo BianconiQuoted 26 lines · Lorenzo Bianconi
Quoted 25 lines · Alex Elder
Define a new platform driver that manages clocks and resets implemented by the Toshiba TC9564 SoC. There are 21 gate clocks that can be enabled and disabled, but currently only the clocks that are (or will soon be) used are defined to be controllable. There are also 13 resets that can be asserted or deasserted, but support for some of these is omitted as well.
Two registers manage the state of the clocks, and two others manage the state of the resets. All four registers are found in a region mapped for MMIO. The region is provided via a BAR on one of the PCI functions embedded in the TC9564 SoC.
The I2C and PCIE clocks and resets are treated as CRITICAL, meaning their state should never be changed (and a warning is issued if changing their state is attempted).
Co-developed-by Daniel Thompson <[email protected]>Signed-off-by Daniel Thompson <[email protected]>Signed-off-by Alex Elder <[email protected]>---
v3: - Fixed problems/garbage in the patch header
- TheKconfigoption now depends onRESET_CONTROLLER, and can now be enabled ifCOMPILE_TESTis enabled
- The generic gate clock controller code is now used rather than implementing a custom one
Quoted 8 lines
Quoted 8 lines
- The PLL and internal fixed clocks IDs are no longer available outside "
clk-tc9564.c"
- The PLL is initialialized, followed by all fixed rate clocks, followed by the gate clocks, to ensure each clock's parent is initialized before the clock is
- Updating the reset registers (read/modify/write) is now protected by a spinlock
- "Unnecessary newlines" have been removed
. . .
Quoted 10 lines
drivers/clk/clk-tc9564.c line 49
Quoted 4 lines
drivers/clk/clk-tc9564.c new file +4
-0+struct tc9564_clock { +void __iomem *ioaddr;/* Mapped clock/reset registers */ +spinlock_t lock;/* Protects reset register updates */ +struct clk_hw_onecell_data *clk_data;I think it would be more readable to have 3 different pointers here:
- structclk_hw_onecell_data*clk_pll_data;
- structclk_hw_onecell_data*clk_fixed_rate_data;
- structclk_hw_onecell_data*clk_gate_data;
Quoted 4 lines
(using the same logic you implemented for
fixed_init,gate_initstucts).Doing so, I guess the code that is allocating the clock data would be easier to manage.
I don't know that it's easier but it would avoid keeping track of the difference between array indexes and identifiers. I think I was trying to avoid registering three different providers, but I think you're right, the result will be simpler and more readable.
The PLL is a single clock, so it will be more like:
struct clk_hw *pll_hw;
So I will implement your suggestion.
Quoted 11 lines
drivers/clk/clk-tc9564.c line 59
Quoted 11 lines
drivers/clk/clk-tc9564.c new file +10
-0+struct reset_controller_dev rcdev; +}; + +/* Indexes into the fixed_init[] array */ +enum fixed_clock { +CLOCK_62_5M , +CLOCK_125M , +CLOCK_250M , +CLOCK_312_5M , +};
. . .
Quoted 9 lines
drivers/clk/clk-tc9564.c line 217
Quoted 5 lines
drivers/clk/clk-tc9564.c new file +5
-0+/* Caller must free the returned pointer if non-null */ +static const char *clock_name (struct device *dev,const char *name) +{ +return kasprintf (GFP_KERNEL ,"%s-%s" ,dev_name (dev), name); +}nit:
clock_name()is running just during probe, I would prefer to usedev_kasprintf()instead and get rid of the relatedkfree(). Moreover,clock_name()is just a wrapper aroundkasprintf(), do we really need it?
I think you mean devm_kasprintf(), but I still don't like keeping that allocated memory around for every clock for the entire life of the device. It's just a waste.
What I'll do, to get rid of what seems like a weird kfree() call, *and* avoid having the allocated memory hang on longer than needed is have all the callers do something like this:
const char *name __free(kfree) = clock_name(dev, "pll");
I do agree it's a simple wrapper but it's used in three places to create a consistent name, so I prefer to keep it.
Quoted 13 lines
Quoted 13 lines
drivers/clk/clk-tc9564.c new file +13
-0+/* Initialize the PLL (parent is the input oscillator); called from probe */ +static int pll_init (struct device *dev,struct tc9564_clock *clock) +{ +struct clk_hw *hw; +const char *name; + +/* Initialize the PLL clock first (input oscillator is parent) */ + name =clock_name (dev,"pll" ); +if (!name) +return -ENOMEM ; + + hw =devm_clk_hw_register_fixed_factor_index (dev, name,0 ,0 ,50 ,1 ); +kfree (name);
Quoted 8 lines
drivers/clk/clk-tc9564.c line 239
Quoted 8 lines
drivers/clk/clk-tc9564.c new file +8
-0+if (IS_ERR (hw)) +return dev_err_probe (dev,PTR_ERR (hw), +"failed to register pll\n" ); + + clock->clk_data->hws[CLOCK_PLL ] = hw; + +return 0 ; +}
Thanks for the review.
-Alex