* [PATCH v6 0/6] clk: spacemit: add K1 reset support
@ 2025-05-06 21:06 Alex Elder
2025-05-06 21:06 ` [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets Alex Elder
` (5 more replies)
0 siblings, 6 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-06 21:06 UTC (permalink / raw)
To: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
This series adds reset controller support for the SpacemiT K1 SoC.
This code builds upon the clock controller driver from Haylen Chu.
This version has been reworked to use the auxiliary device model,
as requested by Stephen Boyd. As a result the reset code resides
under drivers/reset rather than drivers/clk. A new header file
holds definitions used by the clock and reset drivers. The first
patch is the same as before, so I preserved Krzysztof's Reviewed-by
tag. I dropped the tags from Haylen and Philipp, given the new
location of the code. (The actual reset code is largely the same.)
This series is based on the "for-next" branch in the SpacemiT
repository:
https://github.com/spacemit-com/linux/tree/for-next
All of these patches are available here:
https://github.com/riscstar/linux/tree/outgoing/reset-v6
Between version 5 and version 6:
- Reworked the code to use the auxiliary device framework.
- Moved the code supporting reset under drivers/reset/spacemit.
- Created a new header file shared by reset and clock.
- Separated generic from SoC-specific code in the reset driver.
- Dropped two Reviewed-by tags.
Between version 4 and version 5:
- Added Haylen's Reviewed-by on the second patch.
- Added Philipp's Reviewed-by on the third patch.
- In patch 4, added a const qualifier to some structures, and removed
parentheses surrounding integer constants, as suggested by Philipp
- Now based on the SpacemiT for-next branch
Here is version 4 of this series.
https://lore.kernel.org/lkml/20250414191715.2264758-1-elder@riscstar.com/
Between version 3 and version 4:
- Now based on Haylen Chu's v7 clock code, built on v6.15-rc2.
- Added Krzysztof's Reviewed-by on the first patch.
Here is version 3 of this series.
https://lore.kernel.org/lkml/20250409211741.1171584-1-elder@riscstar.com/
Between version 2 and version 3 there was no feedback, however:
- Haylen posted v6 of the clock series, and it included some changes
that affected the logic in this reset code.
- I was informed that defining CCU nodes without any clocks led to
warnings about "clocks" being a required property when running
"make dtbs_check". For that reason, I made clock properties
optional for reset-only CCU nodes.
- This code is now based on v6.15-rc1, which includes a few commits
that were listed as dependencies previously.
Here is version 2 of this series.
https://lore.kernel.org/lkml/20250328210233.1077035-1-elder@riscstar.com/
Between version 1 and version 2:
- Added Rob's Reviewed-by tag on the first patch
- Renamed the of_match_data data type (and one or two other symbols) to
use "spacemit" rather than "k1".
- Replaced the abbreviated "rst" or "RST" in names of newly-defined
sympols with "reset" or "RESET" respectively.
- Eliminated rcdev_to_controller(), which was only used once.
- Changed a function that unsafely did a read/modify/write of a register
to use regmap_update_bits() instead as suggested by Haylen.
- Eliminated a null check for a pointer known to be non-null.
- Reordered the assignment of reset controller device fields.
- Added a "sentinel" comment as requested by Yixun.
- Updated to be based on Linux v6.14 final.
Here is the first version of this series.
https://lore.kernel.org/lkml/20250321151831.623575-1-elder@riscstar.com/
-Alex
Alex Elder (6):
dt-bindings: soc: spacemit: define spacemit,k1-ccu resets
soc: spacemit: create a header for clock/reset registers
clk: spacemit: set up reset auxiliary devices
reset: spacemit: add support for SpacemiT CCU resets
reset: spacemit: define three more CCUs
riscv: dts: spacemit: add reset support for the K1 SoC
.../soc/spacemit/spacemit,k1-syscon.yaml | 29 ++-
arch/riscv/boot/dts/spacemit/k1.dtsi | 18 ++
drivers/clk/spacemit/ccu-k1.c | 220 ++++++++---------
drivers/reset/Kconfig | 1 +
drivers/reset/Makefile | 1 +
drivers/reset/spacemit/Kconfig | 12 +
drivers/reset/spacemit/Makefile | 7 +
drivers/reset/spacemit/core.c | 61 +++++
drivers/reset/spacemit/core.h | 39 +++
drivers/reset/spacemit/k1.c | 231 ++++++++++++++++++
.../dt-bindings/clock/spacemit,k1-syscon.h | 128 ++++++++++
include/soc/spacemit/ccu_k1.h | 155 ++++++++++++
12 files changed, 777 insertions(+), 125 deletions(-)
create mode 100644 drivers/reset/spacemit/Kconfig
create mode 100644 drivers/reset/spacemit/Makefile
create mode 100644 drivers/reset/spacemit/core.c
create mode 100644 drivers/reset/spacemit/core.h
create mode 100644 drivers/reset/spacemit/k1.c
create mode 100644 include/soc/spacemit/ccu_k1.h
base-commit: cb9c3aeae509b36afbdf46942a7a0a0dfc856ce7
--
2.45.2
^ permalink raw reply [flat|nested] 27+ messages in thread
* [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets
2025-05-06 21:06 [PATCH v6 0/6] clk: spacemit: add K1 reset support Alex Elder
@ 2025-05-06 21:06 ` Alex Elder
2025-05-07 22:35 ` Yixun Lan
2025-05-06 21:06 ` [PATCH v6 2/6] soc: spacemit: create a header for clock/reset registers Alex Elder
` (4 subsequent siblings)
5 siblings, 1 reply; 27+ messages in thread
From: Alex Elder @ 2025-05-06 21:06 UTC (permalink / raw)
To: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel, Krzysztof Kozlowski
There are additional SpacemiT syscon CCUs whose registers control both
clocks and resets: RCPU, RCPU2, and APBC2. Unlike those defined
previously, these will (initially) support only resets. They do not
incorporate power domain functionality.
Previously the clock properties were required for all compatible nodes.
Make that requirement only apply to the three existing CCUs (APBC, APMU,
and MPMU), so that the new reset-only CCUs can go without specifying them.
Define the index values for resets associated with all SpacemiT K1
syscon nodes, including those with clocks already defined, as well as
the new ones (without clocks).
Signed-off-by: Alex Elder <elder@riscstar.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
.../soc/spacemit/spacemit,k1-syscon.yaml | 29 +++-
.../dt-bindings/clock/spacemit,k1-syscon.h | 128 ++++++++++++++++++
2 files changed, 150 insertions(+), 7 deletions(-)
diff --git a/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml b/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml
index 30aaf49da03d3..133a391ee68cd 100644
--- a/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml
+++ b/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml
@@ -19,6 +19,9 @@ properties:
- spacemit,k1-syscon-apbc
- spacemit,k1-syscon-apmu
- spacemit,k1-syscon-mpmu
+ - spacemit,k1-syscon-rcpu
+ - spacemit,k1-syscon-rcpu2
+ - spacemit,k1-syscon-apbc2
reg:
maxItems: 1
@@ -47,9 +50,6 @@ properties:
required:
- compatible
- reg
- - clocks
- - clock-names
- - "#clock-cells"
- "#reset-cells"
allOf:
@@ -57,13 +57,28 @@ allOf:
properties:
compatible:
contains:
- const: spacemit,k1-syscon-apbc
+ enum:
+ - spacemit,k1-syscon-apmu
+ - spacemit,k1-syscon-mpmu
then:
- properties:
- "#power-domain-cells": false
- else:
required:
- "#power-domain-cells"
+ else:
+ properties:
+ "#power-domain-cells": false
+ - if:
+ properties:
+ compatible:
+ contains:
+ enum:
+ - spacemit,k1-syscon-apbc
+ - spacemit,k1-syscon-apmu
+ - spacemit,k1-syscon-mpmu
+ then:
+ required:
+ - clocks
+ - clock-names
+ - "#clock-cells"
additionalProperties: false
diff --git a/include/dt-bindings/clock/spacemit,k1-syscon.h b/include/dt-bindings/clock/spacemit,k1-syscon.h
index 35968ae982466..f5965dda3b905 100644
--- a/include/dt-bindings/clock/spacemit,k1-syscon.h
+++ b/include/dt-bindings/clock/spacemit,k1-syscon.h
@@ -78,6 +78,9 @@
#define CLK_APB 31
#define CLK_WDT_BUS 32
+/* MPMU resets */
+#define RESET_WDT 0
+
/* APBC clocks */
#define CLK_UART0 0
#define CLK_UART2 1
@@ -180,6 +183,59 @@
#define CLK_TSEN_BUS 98
#define CLK_IPC_AP2AUD_BUS 99
+/* APBC resets */
+#define RESET_UART0 0
+#define RESET_UART2 1
+#define RESET_UART3 2
+#define RESET_UART4 3
+#define RESET_UART5 4
+#define RESET_UART6 5
+#define RESET_UART7 6
+#define RESET_UART8 7
+#define RESET_UART9 8
+#define RESET_GPIO 9
+#define RESET_PWM0 10
+#define RESET_PWM1 11
+#define RESET_PWM2 12
+#define RESET_PWM3 13
+#define RESET_PWM4 14
+#define RESET_PWM5 15
+#define RESET_PWM6 16
+#define RESET_PWM7 17
+#define RESET_PWM8 18
+#define RESET_PWM9 19
+#define RESET_PWM10 20
+#define RESET_PWM11 21
+#define RESET_PWM12 22
+#define RESET_PWM13 23
+#define RESET_PWM14 24
+#define RESET_PWM15 25
+#define RESET_PWM16 26
+#define RESET_PWM17 27
+#define RESET_PWM18 28
+#define RESET_PWM19 29
+#define RESET_SSP3 30
+#define RESET_RTC 31
+#define RESET_TWSI0 32
+#define RESET_TWSI1 33
+#define RESET_TWSI2 34
+#define RESET_TWSI4 35
+#define RESET_TWSI5 36
+#define RESET_TWSI6 37
+#define RESET_TWSI7 38
+#define RESET_TWSI8 39
+#define RESET_TIMERS1 40
+#define RESET_TIMERS2 41
+#define RESET_AIB 42
+#define RESET_ONEWIRE 43
+#define RESET_SSPA0 44
+#define RESET_SSPA1 45
+#define RESET_DRO 46
+#define RESET_IR 47
+#define RESET_TSEN 48
+#define RESET_IPC_AP2AUD 49
+#define RESET_CAN0 50
+
/* APMU clocks */
#define CLK_CCI550 0
#define CLK_CPU_C0_HI 1
@@ -244,4 +300,76 @@
#define CLK_V2D 60
#define CLK_EMMC_BUS 61
+/* APMU resets */
+#define RESET_CCIC_4X 0
+#define RESET_CCIC1_PHY 1
+#define RESET_SDH_AXI 2
+#define RESET_SDH0 3
+#define RESET_SDH1 4
+#define RESET_SDH2 5
+#define RESET_USBP1_AXI 6
+#define RESET_USB_AXI 7
+#define RESET_USB3_0 8
+#define RESET_QSPI 9
+#define RESET_QSPI_BUS 10
+#define RESET_DMA 11
+#define RESET_AES 12
+#define RESET_VPU 13
+#define RESET_GPU 14
+#define RESET_EMMC 15
+#define RESET_EMMC_X 16
+#define RESET_AUDIO 17
+#define RESET_HDMI 18
+#define RESET_PCIE0 19
+#define RESET_PCIE1 20
+#define RESET_PCIE2 21
+#define RESET_EMAC0 22
+#define RESET_EMAC1 23
+#define RESET_JPG 24
+#define RESET_CCIC2PHY 25
+#define RESET_CCIC3PHY 26
+#define RESET_CSI 27
+#define RESET_ISP_CPP 28
+#define RESET_ISP_BUS 29
+#define RESET_ISP 30
+#define RESET_ISP_CI 31
+#define RESET_DPU_MCLK 32
+#define RESET_DPU_ESC 33
+#define RESET_DPU_HCLK 34
+#define RESET_DPU_SPIBUS 35
+#define RESET_DPU_SPI_HBUS 36
+#define RESET_V2D 37
+#define RESET_MIPI 38
+#define RESET_MC 39
+
+/* RCPU resets */
+#define RESET_RCPU_SSP0 0
+#define RESET_RCPU_I2C0 1
+#define RESET_RCPU_UART1 2
+#define RESET_RCPU_IR 3
+#define RESET_RCPU_CAN 4
+#define RESET_RCPU_UART0 5
+#define RESET_RCPU_HDMI_AUDIO 6
+
+/* RCPU2 resets */
+#define RESET_RCPU2_PWM0 0
+#define RESET_RCPU2_PWM1 1
+#define RESET_RCPU2_PWM2 2
+#define RESET_RCPU2_PWM3 3
+#define RESET_RCPU2_PWM4 4
+#define RESET_RCPU2_PWM5 5
+#define RESET_RCPU2_PWM6 6
+#define RESET_RCPU2_PWM7 7
+#define RESET_RCPU2_PWM8 8
+#define RESET_RCPU2_PWM9 9
+
+/* APBC2 resets */
+#define RESET_APBC2_UART1 0
+#define RESET_APBC2_SSP2 1
+#define RESET_APBC2_TWSI3 2
+#define RESET_APBC2_RTC 3
+#define RESET_APBC2_TIMERS0 4
+#define RESET_APBC2_KPC 5
+#define RESET_APBC2_GPIO 6
+
#endif /* _DT_BINDINGS_SPACEMIT_CCU_H_ */
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v6 2/6] soc: spacemit: create a header for clock/reset registers
2025-05-06 21:06 [PATCH v6 0/6] clk: spacemit: add K1 reset support Alex Elder
2025-05-06 21:06 ` [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets Alex Elder
@ 2025-05-06 21:06 ` Alex Elder
2025-05-08 4:16 ` Haylen Chu
2025-05-06 21:06 ` [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices Alex Elder
` (3 subsequent siblings)
5 siblings, 1 reply; 27+ messages in thread
From: Alex Elder @ 2025-05-06 21:06 UTC (permalink / raw)
To: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
Move the definitions of register offsets and fields used by the SpacemiT
K1 SoC CCUs into a separate header file, so that they can be shared by
the reset driver that will be found under drivers/reset.
Signed-off-by: Alex Elder <elder@riscstar.com>
---
drivers/clk/spacemit/ccu-k1.c | 111 +--------------------------------
include/soc/spacemit/ccu_k1.h | 113 ++++++++++++++++++++++++++++++++++
2 files changed, 114 insertions(+), 110 deletions(-)
create mode 100644 include/soc/spacemit/ccu_k1.h
diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c
index cdde37a052353..9545cfe60b92b 100644
--- a/drivers/clk/spacemit/ccu-k1.c
+++ b/drivers/clk/spacemit/ccu-k1.c
@@ -11,6 +11,7 @@
#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/platform_device.h>
+#include <soc/spacemit/ccu_k1.h>
#include "ccu_common.h"
#include "ccu_pll.h"
@@ -19,116 +20,6 @@
#include <dt-bindings/clock/spacemit,k1-syscon.h>
-/* APBS register offset */
-#define APBS_PLL1_SWCR1 0x100
-#define APBS_PLL1_SWCR2 0x104
-#define APBS_PLL1_SWCR3 0x108
-#define APBS_PLL2_SWCR1 0x118
-#define APBS_PLL2_SWCR2 0x11c
-#define APBS_PLL2_SWCR3 0x120
-#define APBS_PLL3_SWCR1 0x124
-#define APBS_PLL3_SWCR2 0x128
-#define APBS_PLL3_SWCR3 0x12c
-
-/* MPMU register offset */
-#define MPMU_POSR 0x0010
-#define POSR_PLL1_LOCK BIT(27)
-#define POSR_PLL2_LOCK BIT(28)
-#define POSR_PLL3_LOCK BIT(29)
-#define MPMU_SUCCR 0x0014
-#define MPMU_ISCCR 0x0044
-#define MPMU_WDTPCR 0x0200
-#define MPMU_RIPCCR 0x0210
-#define MPMU_ACGR 0x1024
-#define MPMU_APBCSCR 0x1050
-#define MPMU_SUCCR_1 0x10b0
-
-/* APBC register offset */
-#define APBC_UART1_CLK_RST 0x00
-#define APBC_UART2_CLK_RST 0x04
-#define APBC_GPIO_CLK_RST 0x08
-#define APBC_PWM0_CLK_RST 0x0c
-#define APBC_PWM1_CLK_RST 0x10
-#define APBC_PWM2_CLK_RST 0x14
-#define APBC_PWM3_CLK_RST 0x18
-#define APBC_TWSI8_CLK_RST 0x20
-#define APBC_UART3_CLK_RST 0x24
-#define APBC_RTC_CLK_RST 0x28
-#define APBC_TWSI0_CLK_RST 0x2c
-#define APBC_TWSI1_CLK_RST 0x30
-#define APBC_TIMERS1_CLK_RST 0x34
-#define APBC_TWSI2_CLK_RST 0x38
-#define APBC_AIB_CLK_RST 0x3c
-#define APBC_TWSI4_CLK_RST 0x40
-#define APBC_TIMERS2_CLK_RST 0x44
-#define APBC_ONEWIRE_CLK_RST 0x48
-#define APBC_TWSI5_CLK_RST 0x4c
-#define APBC_DRO_CLK_RST 0x58
-#define APBC_IR_CLK_RST 0x5c
-#define APBC_TWSI6_CLK_RST 0x60
-#define APBC_COUNTER_CLK_SEL 0x64
-#define APBC_TWSI7_CLK_RST 0x68
-#define APBC_TSEN_CLK_RST 0x6c
-#define APBC_UART4_CLK_RST 0x70
-#define APBC_UART5_CLK_RST 0x74
-#define APBC_UART6_CLK_RST 0x78
-#define APBC_SSP3_CLK_RST 0x7c
-#define APBC_SSPA0_CLK_RST 0x80
-#define APBC_SSPA1_CLK_RST 0x84
-#define APBC_IPC_AP2AUD_CLK_RST 0x90
-#define APBC_UART7_CLK_RST 0x94
-#define APBC_UART8_CLK_RST 0x98
-#define APBC_UART9_CLK_RST 0x9c
-#define APBC_CAN0_CLK_RST 0xa0
-#define APBC_PWM4_CLK_RST 0xa8
-#define APBC_PWM5_CLK_RST 0xac
-#define APBC_PWM6_CLK_RST 0xb0
-#define APBC_PWM7_CLK_RST 0xb4
-#define APBC_PWM8_CLK_RST 0xb8
-#define APBC_PWM9_CLK_RST 0xbc
-#define APBC_PWM10_CLK_RST 0xc0
-#define APBC_PWM11_CLK_RST 0xc4
-#define APBC_PWM12_CLK_RST 0xc8
-#define APBC_PWM13_CLK_RST 0xcc
-#define APBC_PWM14_CLK_RST 0xd0
-#define APBC_PWM15_CLK_RST 0xd4
-#define APBC_PWM16_CLK_RST 0xd8
-#define APBC_PWM17_CLK_RST 0xdc
-#define APBC_PWM18_CLK_RST 0xe0
-#define APBC_PWM19_CLK_RST 0xe4
-
-/* APMU register offset */
-#define APMU_JPG_CLK_RES_CTRL 0x020
-#define APMU_CSI_CCIC2_CLK_RES_CTRL 0x024
-#define APMU_ISP_CLK_RES_CTRL 0x038
-#define APMU_LCD_CLK_RES_CTRL1 0x044
-#define APMU_LCD_SPI_CLK_RES_CTRL 0x048
-#define APMU_LCD_CLK_RES_CTRL2 0x04c
-#define APMU_CCIC_CLK_RES_CTRL 0x050
-#define APMU_SDH0_CLK_RES_CTRL 0x054
-#define APMU_SDH1_CLK_RES_CTRL 0x058
-#define APMU_USB_CLK_RES_CTRL 0x05c
-#define APMU_QSPI_CLK_RES_CTRL 0x060
-#define APMU_DMA_CLK_RES_CTRL 0x064
-#define APMU_AES_CLK_RES_CTRL 0x068
-#define APMU_VPU_CLK_RES_CTRL 0x0a4
-#define APMU_GPU_CLK_RES_CTRL 0x0cc
-#define APMU_SDH2_CLK_RES_CTRL 0x0e0
-#define APMU_PMUA_MC_CTRL 0x0e8
-#define APMU_PMU_CC2_AP 0x100
-#define APMU_PMUA_EM_CLK_RES_CTRL 0x104
-#define APMU_AUDIO_CLK_RES_CTRL 0x14c
-#define APMU_HDMI_CLK_RES_CTRL 0x1b8
-#define APMU_CCI550_CLK_CTRL 0x300
-#define APMU_ACLK_CLK_CTRL 0x388
-#define APMU_CPU_C0_CLK_CTRL 0x38C
-#define APMU_CPU_C1_CLK_CTRL 0x390
-#define APMU_PCIE_CLK_RES_CTRL_0 0x3cc
-#define APMU_PCIE_CLK_RES_CTRL_1 0x3d4
-#define APMU_PCIE_CLK_RES_CTRL_2 0x3dc
-#define APMU_EMAC0_CLK_RES_CTRL 0x3e4
-#define APMU_EMAC1_CLK_RES_CTRL 0x3ec
-
struct spacemit_ccu_data {
struct clk_hw **hws;
size_t num;
diff --git a/include/soc/spacemit/ccu_k1.h b/include/soc/spacemit/ccu_k1.h
new file mode 100644
index 0000000000000..7df75043e78af
--- /dev/null
+++ b/include/soc/spacemit/ccu_k1.h
@@ -0,0 +1,113 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/* SpacemiT clock and reset driver definitions for the K1 SoC */
+
+/* APBS register offset */
+#define APBS_PLL1_SWCR1 0x100
+#define APBS_PLL1_SWCR2 0x104
+#define APBS_PLL1_SWCR3 0x108
+#define APBS_PLL2_SWCR1 0x118
+#define APBS_PLL2_SWCR2 0x11c
+#define APBS_PLL2_SWCR3 0x120
+#define APBS_PLL3_SWCR1 0x124
+#define APBS_PLL3_SWCR2 0x128
+#define APBS_PLL3_SWCR3 0x12c
+
+/* MPMU register offset */
+#define MPMU_POSR 0x0010
+#define POSR_PLL1_LOCK BIT(27)
+#define POSR_PLL2_LOCK BIT(28)
+#define POSR_PLL3_LOCK BIT(29)
+#define MPMU_SUCCR 0x0014
+#define MPMU_ISCCR 0x0044
+#define MPMU_WDTPCR 0x0200
+#define MPMU_RIPCCR 0x0210
+#define MPMU_ACGR 0x1024
+#define MPMU_APBCSCR 0x1050
+#define MPMU_SUCCR_1 0x10b0
+
+/* APBC register offset */
+#define APBC_UART1_CLK_RST 0x00
+#define APBC_UART2_CLK_RST 0x04
+#define APBC_GPIO_CLK_RST 0x08
+#define APBC_PWM0_CLK_RST 0x0c
+#define APBC_PWM1_CLK_RST 0x10
+#define APBC_PWM2_CLK_RST 0x14
+#define APBC_PWM3_CLK_RST 0x18
+#define APBC_TWSI8_CLK_RST 0x20
+#define APBC_UART3_CLK_RST 0x24
+#define APBC_RTC_CLK_RST 0x28
+#define APBC_TWSI0_CLK_RST 0x2c
+#define APBC_TWSI1_CLK_RST 0x30
+#define APBC_TIMERS1_CLK_RST 0x34
+#define APBC_TWSI2_CLK_RST 0x38
+#define APBC_AIB_CLK_RST 0x3c
+#define APBC_TWSI4_CLK_RST 0x40
+#define APBC_TIMERS2_CLK_RST 0x44
+#define APBC_ONEWIRE_CLK_RST 0x48
+#define APBC_TWSI5_CLK_RST 0x4c
+#define APBC_DRO_CLK_RST 0x58
+#define APBC_IR_CLK_RST 0x5c
+#define APBC_TWSI6_CLK_RST 0x60
+#define APBC_COUNTER_CLK_SEL 0x64
+#define APBC_TWSI7_CLK_RST 0x68
+#define APBC_TSEN_CLK_RST 0x6c
+#define APBC_UART4_CLK_RST 0x70
+#define APBC_UART5_CLK_RST 0x74
+#define APBC_UART6_CLK_RST 0x78
+#define APBC_SSP3_CLK_RST 0x7c
+#define APBC_SSPA0_CLK_RST 0x80
+#define APBC_SSPA1_CLK_RST 0x84
+#define APBC_IPC_AP2AUD_CLK_RST 0x90
+#define APBC_UART7_CLK_RST 0x94
+#define APBC_UART8_CLK_RST 0x98
+#define APBC_UART9_CLK_RST 0x9c
+#define APBC_CAN0_CLK_RST 0xa0
+#define APBC_PWM4_CLK_RST 0xa8
+#define APBC_PWM5_CLK_RST 0xac
+#define APBC_PWM6_CLK_RST 0xb0
+#define APBC_PWM7_CLK_RST 0xb4
+#define APBC_PWM8_CLK_RST 0xb8
+#define APBC_PWM9_CLK_RST 0xbc
+#define APBC_PWM10_CLK_RST 0xc0
+#define APBC_PWM11_CLK_RST 0xc4
+#define APBC_PWM12_CLK_RST 0xc8
+#define APBC_PWM13_CLK_RST 0xcc
+#define APBC_PWM14_CLK_RST 0xd0
+#define APBC_PWM15_CLK_RST 0xd4
+#define APBC_PWM16_CLK_RST 0xd8
+#define APBC_PWM17_CLK_RST 0xdc
+#define APBC_PWM18_CLK_RST 0xe0
+#define APBC_PWM19_CLK_RST 0xe4
+
+/* APMU register offset */
+#define APMU_JPG_CLK_RES_CTRL 0x020
+#define APMU_CSI_CCIC2_CLK_RES_CTRL 0x024
+#define APMU_ISP_CLK_RES_CTRL 0x038
+#define APMU_LCD_CLK_RES_CTRL1 0x044
+#define APMU_LCD_SPI_CLK_RES_CTRL 0x048
+#define APMU_LCD_CLK_RES_CTRL2 0x04c
+#define APMU_CCIC_CLK_RES_CTRL 0x050
+#define APMU_SDH0_CLK_RES_CTRL 0x054
+#define APMU_SDH1_CLK_RES_CTRL 0x058
+#define APMU_USB_CLK_RES_CTRL 0x05c
+#define APMU_QSPI_CLK_RES_CTRL 0x060
+#define APMU_DMA_CLK_RES_CTRL 0x064
+#define APMU_AES_CLK_RES_CTRL 0x068
+#define APMU_VPU_CLK_RES_CTRL 0x0a4
+#define APMU_GPU_CLK_RES_CTRL 0x0cc
+#define APMU_SDH2_CLK_RES_CTRL 0x0e0
+#define APMU_PMUA_MC_CTRL 0x0e8
+#define APMU_PMU_CC2_AP 0x100
+#define APMU_PMUA_EM_CLK_RES_CTRL 0x104
+#define APMU_AUDIO_CLK_RES_CTRL 0x14c
+#define APMU_HDMI_CLK_RES_CTRL 0x1b8
+#define APMU_CCI550_CLK_CTRL 0x300
+#define APMU_ACLK_CLK_CTRL 0x388
+#define APMU_CPU_C0_CLK_CTRL 0x38C
+#define APMU_CPU_C1_CLK_CTRL 0x390
+#define APMU_PCIE_CLK_RES_CTRL_0 0x3cc
+#define APMU_PCIE_CLK_RES_CTRL_1 0x3d4
+#define APMU_PCIE_CLK_RES_CTRL_2 0x3dc
+#define APMU_EMAC0_CLK_RES_CTRL 0x3e4
+#define APMU_EMAC1_CLK_RES_CTRL 0x3ec
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices
2025-05-06 21:06 [PATCH v6 0/6] clk: spacemit: add K1 reset support Alex Elder
2025-05-06 21:06 ` [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets Alex Elder
2025-05-06 21:06 ` [PATCH v6 2/6] soc: spacemit: create a header for clock/reset registers Alex Elder
@ 2025-05-06 21:06 ` Alex Elder
2025-05-08 4:09 ` kernel test robot
2025-05-08 4:46 ` Haylen Chu
2025-05-06 21:06 ` [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets Alex Elder
` (2 subsequent siblings)
5 siblings, 2 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-06 21:06 UTC (permalink / raw)
To: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
Add a new reset_name field to the spacemit_ccu_data structure. If it is
non-null, the CCU implements a reset controller, and the name will be
used as the name for the auxiliary device that implements it.
Define a new type to hold an auxiliary device as well as the regmap
pointer that will be needed by CCU reset controllers. Set up code to
initialize and add an auxiliary device for any CCU that implements reset
functionality.
Make it optional for a CCU to implement a clock controller. This
doesn't apply to any of the existing CCUs but will for some new ones
that will be added soon.
Signed-off-by: Alex Elder <elder@riscstar.com>
---
drivers/clk/spacemit/ccu-k1.c | 85 +++++++++++++++++++++++++++++++----
include/soc/spacemit/ccu_k1.h | 12 +++++
2 files changed, 89 insertions(+), 8 deletions(-)
diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c
index 9545cfe60b92b..6b1845e899e5f 100644
--- a/drivers/clk/spacemit/ccu-k1.c
+++ b/drivers/clk/spacemit/ccu-k1.c
@@ -5,6 +5,7 @@
*/
#include <linux/array_size.h>
+#include <linux/auxiliary_bus.h>
#include <linux/clk-provider.h>
#include <linux/delay.h>
#include <linux/mfd/syscon.h>
@@ -21,6 +22,7 @@
#include <dt-bindings/clock/spacemit,k1-syscon.h>
struct spacemit_ccu_data {
+ const char *reset_name;
struct clk_hw **hws;
size_t num;
};
@@ -710,6 +712,7 @@ static struct clk_hw *k1_ccu_pll_hws[] = {
};
static const struct spacemit_ccu_data k1_ccu_pll_data = {
+ /* The PLL CCU implements no resets */
.hws = k1_ccu_pll_hws,
.num = ARRAY_SIZE(k1_ccu_pll_hws),
};
@@ -751,8 +754,9 @@ static struct clk_hw *k1_ccu_mpmu_hws[] = {
};
static const struct spacemit_ccu_data k1_ccu_mpmu_data = {
- .hws = k1_ccu_mpmu_hws,
- .num = ARRAY_SIZE(k1_ccu_mpmu_hws),
+ .reset_name = "mpmu-reset",
+ .hws = k1_ccu_mpmu_hws,
+ .num = ARRAY_SIZE(k1_ccu_mpmu_hws),
};
static struct clk_hw *k1_ccu_apbc_hws[] = {
@@ -859,8 +863,9 @@ static struct clk_hw *k1_ccu_apbc_hws[] = {
};
static const struct spacemit_ccu_data k1_ccu_apbc_data = {
- .hws = k1_ccu_apbc_hws,
- .num = ARRAY_SIZE(k1_ccu_apbc_hws),
+ .reset_name = "apbc-reset",
+ .hws = k1_ccu_apbc_hws,
+ .num = ARRAY_SIZE(k1_ccu_apbc_hws),
};
static struct clk_hw *k1_ccu_apmu_hws[] = {
@@ -929,8 +934,9 @@ static struct clk_hw *k1_ccu_apmu_hws[] = {
};
static const struct spacemit_ccu_data k1_ccu_apmu_data = {
- .hws = k1_ccu_apmu_hws,
- .num = ARRAY_SIZE(k1_ccu_apmu_hws),
+ .reset_name = "apmu-reset",
+ .hws = k1_ccu_apmu_hws,
+ .num = ARRAY_SIZE(k1_ccu_apmu_hws),
};
static int spacemit_ccu_register(struct device *dev,
@@ -941,6 +947,10 @@ static int spacemit_ccu_register(struct device *dev,
struct clk_hw_onecell_data *clk_data;
int i, ret;
+ /* Nothing to do if the CCU does not implement any clocks */
+ if (!data->hws)
+ return 0;
+
clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, data->num),
GFP_KERNEL);
if (!clk_data)
@@ -981,9 +991,63 @@ static int spacemit_ccu_register(struct device *dev,
return ret;
}
+static void spacemit_cadev_release(struct device *dev)
+{
+ struct auxiliary_device *adev = to_auxiliary_dev(dev);
+
+ kfree(to_spacemit_ccu_adev(adev));
+}
+
+static void spacemit_adev_unregister(void *data)
+{
+ struct auxiliary_device *adev = data;
+
+ auxiliary_device_delete(adev);
+ auxiliary_device_uninit(adev);
+}
+
+static int spacemit_ccu_reset_register(struct device *dev,
+ struct regmap *regmap,
+ const char *reset_name)
+{
+ struct spacemit_ccu_adev *cadev;
+ struct auxiliary_device *adev;
+ static u32 next_id;
+ int ret;
+
+ /* Nothing to do if the CCU does not implement a reset controller */
+ if (!reset_name)
+ return 0;
+
+ cadev = devm_kzalloc(dev, sizeof(*cadev), GFP_KERNEL);
+ if (!cadev)
+ return -ENOMEM;
+ cadev->regmap = regmap;
+
+ adev = &cadev->adev;
+ adev->name = reset_name;
+ adev->dev.parent = dev;
+ adev->dev.release = spacemit_cadev_release;
+ adev->dev.of_node = dev->of_node;
+ adev->id = next_id++;
+
+ ret = auxiliary_device_init(adev);
+ if (ret)
+ return ret;
+
+ ret = auxiliary_device_add(adev);
+ if (ret) {
+ auxiliary_device_uninit(adev);
+ return ret;
+ }
+
+ return devm_add_action_or_reset(dev, spacemit_adev_unregister, adev);
+}
+
static int k1_ccu_probe(struct platform_device *pdev)
{
struct regmap *base_regmap, *lock_regmap = NULL;
+ const struct spacemit_ccu_data *data;
struct device *dev = &pdev->dev;
int ret;
@@ -1012,11 +1076,16 @@ static int k1_ccu_probe(struct platform_device *pdev)
"failed to get lock regmap\n");
}
- ret = spacemit_ccu_register(dev, base_regmap, lock_regmap,
- of_device_get_match_data(dev));
+ data = of_device_get_match_data(dev);
+
+ ret = spacemit_ccu_register(dev, base_regmap, lock_regmap, data);
if (ret)
return dev_err_probe(dev, ret, "failed to register clocks\n");
+ ret = spacemit_ccu_reset_register(dev, base_regmap, data->reset_name);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to register resets\n");
+
return 0;
}
diff --git a/include/soc/spacemit/ccu_k1.h b/include/soc/spacemit/ccu_k1.h
index 7df75043e78af..8b2581fb3055d 100644
--- a/include/soc/spacemit/ccu_k1.h
+++ b/include/soc/spacemit/ccu_k1.h
@@ -2,6 +2,18 @@
/* SpacemiT clock and reset driver definitions for the K1 SoC */
+/* Auxiliary device used to represent a CCU reset controller */
+struct spacemit_ccu_adev {
+ struct auxiliary_device adev;
+ struct regmap *regmap;
+};
+
+static inline struct spacemit_ccu_adev *
+to_spacemit_ccu_adev(struct auxiliary_device *adev)
+{
+ return container_of(adev, struct spacemit_ccu_adev, adev);
+}
+
/* APBS register offset */
#define APBS_PLL1_SWCR1 0x100
#define APBS_PLL1_SWCR2 0x104
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets
2025-05-06 21:06 [PATCH v6 0/6] clk: spacemit: add K1 reset support Alex Elder
` (2 preceding siblings ...)
2025-05-06 21:06 ` [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices Alex Elder
@ 2025-05-06 21:06 ` Alex Elder
2025-05-08 5:38 ` Haylen Chu
2025-05-08 9:01 ` Philipp Zabel
2025-05-06 21:06 ` [PATCH v6 5/6] reset: spacemit: define three more CCUs Alex Elder
2025-05-06 21:06 ` [PATCH v6 6/6] riscv: dts: spacemit: add reset support for the K1 SoC Alex Elder
5 siblings, 2 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-06 21:06 UTC (permalink / raw)
To: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
Implement reset support for SpacemiT CCUs. The code is structured to
handle SpacemiT resets generically, while defining the set of specific
reset controllers and their resets in an SoC-specific source file. A
SpacemiT reset controller device is an auxiliary device associated with
a clock controller (CCU).
This initial patch defines the reset controllers for the MPMU, APBC, and
MPMU CCUs, which already defined clock controllers.
Signed-off-by: Alex Elder <elder@riscstar.com>
---
drivers/reset/Kconfig | 1 +
drivers/reset/Makefile | 1 +
drivers/reset/spacemit/Kconfig | 12 +++
drivers/reset/spacemit/Makefile | 7 ++
drivers/reset/spacemit/core.c | 61 +++++++++++
drivers/reset/spacemit/core.h | 39 +++++++
drivers/reset/spacemit/k1.c | 177 ++++++++++++++++++++++++++++++++
7 files changed, 298 insertions(+)
create mode 100644 drivers/reset/spacemit/Kconfig
create mode 100644 drivers/reset/spacemit/Makefile
create mode 100644 drivers/reset/spacemit/core.c
create mode 100644 drivers/reset/spacemit/core.h
create mode 100644 drivers/reset/spacemit/k1.c
diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
index 99f6f9784e686..b1f1af50ca10b 100644
--- a/drivers/reset/Kconfig
+++ b/drivers/reset/Kconfig
@@ -354,6 +354,7 @@ source "drivers/reset/amlogic/Kconfig"
source "drivers/reset/starfive/Kconfig"
source "drivers/reset/sti/Kconfig"
source "drivers/reset/hisilicon/Kconfig"
+source "drivers/reset/spacemit/Kconfig"
source "drivers/reset/tegra/Kconfig"
endif
diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
index 31f9904d13f9c..6c19fd875ff13 100644
--- a/drivers/reset/Makefile
+++ b/drivers/reset/Makefile
@@ -2,6 +2,7 @@
obj-y += core.o
obj-y += amlogic/
obj-y += hisilicon/
+obj-y += spacemit/
obj-y += starfive/
obj-y += sti/
obj-y += tegra/
diff --git a/drivers/reset/spacemit/Kconfig b/drivers/reset/spacemit/Kconfig
new file mode 100644
index 0000000000000..4ff3487a99eff
--- /dev/null
+++ b/drivers/reset/spacemit/Kconfig
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config RESET_SPACEMIT
+ bool
+
+config RESET_SPACEMIT_K1
+ tristate "SpacemiT K1 reset driver"
+ depends on ARCH_SPACEMIT || COMPILE_TEST
+ select RESET_SPACEMIT
+ default ARCH_SPACEMIT
+ help
+ This enables the reset controller driver for the SpacemiT K1 SoC.
diff --git a/drivers/reset/spacemit/Makefile b/drivers/reset/spacemit/Makefile
new file mode 100644
index 0000000000000..3a064e9d5d6b4
--- /dev/null
+++ b/drivers/reset/spacemit/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_RESET_SPACEMIT) += reset_spacemit.o
+
+reset_spacemit-y := core.o
+
+reset_spacemit-$(CONFIG_RESET_SPACEMIT_K1) += k1.o
diff --git a/drivers/reset/spacemit/core.c b/drivers/reset/spacemit/core.c
new file mode 100644
index 0000000000000..5cd981eb3f097
--- /dev/null
+++ b/drivers/reset/spacemit/core.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/* SpacemiT reset driver core */
+
+#include <linux/container_of.h>
+#include <linux/regmap.h>
+#include <linux/reset-controller.h>
+#include <linux/types.h>
+
+#include "core.h"
+
+static int spacemit_reset_update(struct reset_controller_dev *rcdev,
+ unsigned long id, bool assert)
+{
+ struct ccu_reset_controller *controller;
+ const struct ccu_reset_data *data;
+ u32 mask;
+ u32 val;
+
+ controller = container_of(rcdev, struct ccu_reset_controller, rcdev);
+ data = &controller->data->reset_data[id];
+ mask = data->assert_mask | data->deassert_mask;
+ val = assert ? data->assert_mask : data->deassert_mask;
+
+ return regmap_update_bits(controller->regmap, data->offset, mask, val);
+}
+
+static int spacemit_reset_assert(struct reset_controller_dev *rcdev,
+ unsigned long id)
+{
+ return spacemit_reset_update(rcdev, id, true);
+}
+
+static int spacemit_reset_deassert(struct reset_controller_dev *rcdev,
+ unsigned long id)
+{
+ return spacemit_reset_update(rcdev, id, false);
+}
+
+static const struct reset_control_ops spacemit_reset_control_ops = {
+ .assert = spacemit_reset_assert,
+ .deassert = spacemit_reset_deassert,
+};
+
+/**
+ * spacemit_reset_controller_register() - register a reset controller
+ * @dev: Device that's registering the controller
+ * @controller: SpacemiT CCU reset controller structure
+ */
+int spacemit_reset_controller_register(struct device *dev,
+ struct ccu_reset_controller *controller)
+{
+ struct reset_controller_dev *rcdev = &controller->rcdev;
+
+ rcdev->ops = &spacemit_reset_control_ops;
+ rcdev->owner = THIS_MODULE;
+ rcdev->of_node = dev->of_node;
+ rcdev->nr_resets = controller->data->count;
+
+ return devm_reset_controller_register(dev, &controller->rcdev);
+}
diff --git a/drivers/reset/spacemit/core.h b/drivers/reset/spacemit/core.h
new file mode 100644
index 0000000000000..a71f835ccb779
--- /dev/null
+++ b/drivers/reset/spacemit/core.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/* SpacemiT reset driver core */
+
+#ifndef __RESET_SPACEMIT_CORE_H__
+#define __RESET_SPACEMIT_CORE_H__
+
+#include <linux/device.h>
+#include <linux/reset-controller.h>
+#include <linux/types.h>
+
+struct ccu_reset_data {
+ u32 offset;
+ u32 assert_mask;
+ u32 deassert_mask;
+};
+
+#define RESET_DATA(_offset, _assert_mask, _deassert_mask) \
+ { \
+ .offset = (_offset), \
+ .assert_mask = (_assert_mask), \
+ .deassert_mask = (_deassert_mask), \
+ }
+
+struct ccu_reset_controller_data {
+ const struct ccu_reset_data *reset_data; /* array */
+ size_t count;
+};
+
+struct ccu_reset_controller {
+ struct reset_controller_dev rcdev;
+ const struct ccu_reset_controller_data *data;
+ struct regmap *regmap;
+};
+
+extern int spacemit_reset_controller_register(struct device *dev,
+ struct ccu_reset_controller *controller);
+
+#endif /* __RESET_SPACEMIT_CORE_H__ */
diff --git a/drivers/reset/spacemit/k1.c b/drivers/reset/spacemit/k1.c
new file mode 100644
index 0000000000000..19a34f151b214
--- /dev/null
+++ b/drivers/reset/spacemit/k1.c
@@ -0,0 +1,177 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/* SpacemiT reset driver data for the K1 SoC */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/bits.h>
+#include <linux/container_of.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/reset-controller.h>
+#include <linux/types.h>
+
+#include <soc/spacemit/ccu_k1.h>
+#include <dt-bindings/clock/spacemit,k1-syscon.h>
+
+#include "core.h"
+
+static const struct ccu_reset_data mpmu_resets[] = {
+ [RESET_WDT] = RESET_DATA(MPMU_WDTPCR, BIT(2), 0),
+};
+
+static const struct ccu_reset_controller_data k1_mpmu_reset_data = {
+ .reset_data = mpmu_resets,
+ .count = ARRAY_SIZE(mpmu_resets),
+};
+
+static const struct ccu_reset_data apbc_resets[] = {
+ [RESET_UART0] = RESET_DATA(APBC_UART1_CLK_RST, BIT(2), 0),
+ [RESET_UART2] = RESET_DATA(APBC_UART2_CLK_RST, BIT(2), 0),
+ [RESET_GPIO] = RESET_DATA(APBC_GPIO_CLK_RST, BIT(2), 0),
+ [RESET_PWM0] = RESET_DATA(APBC_PWM0_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM1] = RESET_DATA(APBC_PWM1_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM2] = RESET_DATA(APBC_PWM2_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM3] = RESET_DATA(APBC_PWM3_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM4] = RESET_DATA(APBC_PWM4_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM5] = RESET_DATA(APBC_PWM5_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM6] = RESET_DATA(APBC_PWM6_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM7] = RESET_DATA(APBC_PWM7_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM8] = RESET_DATA(APBC_PWM8_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM9] = RESET_DATA(APBC_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM10] = RESET_DATA(APBC_PWM10_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM11] = RESET_DATA(APBC_PWM11_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM12] = RESET_DATA(APBC_PWM12_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM13] = RESET_DATA(APBC_PWM13_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM14] = RESET_DATA(APBC_PWM14_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM15] = RESET_DATA(APBC_PWM15_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM16] = RESET_DATA(APBC_PWM16_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM17] = RESET_DATA(APBC_PWM17_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM18] = RESET_DATA(APBC_PWM18_CLK_RST, BIT(2), BIT(0)),
+ [RESET_PWM19] = RESET_DATA(APBC_PWM19_CLK_RST, BIT(2), BIT(0)),
+ [RESET_SSP3] = RESET_DATA(APBC_SSP3_CLK_RST, BIT(2), 0),
+ [RESET_UART3] = RESET_DATA(APBC_UART3_CLK_RST, BIT(2), 0),
+ [RESET_RTC] = RESET_DATA(APBC_RTC_CLK_RST, BIT(2), 0),
+ [RESET_TWSI0] = RESET_DATA(APBC_TWSI0_CLK_RST, BIT(2), 0),
+ [RESET_TIMERS1] = RESET_DATA(APBC_TIMERS1_CLK_RST, BIT(2), 0),
+ [RESET_AIB] = RESET_DATA(APBC_AIB_CLK_RST, BIT(2), 0),
+ [RESET_TIMERS2] = RESET_DATA(APBC_TIMERS2_CLK_RST, BIT(2), 0),
+ [RESET_ONEWIRE] = RESET_DATA(APBC_ONEWIRE_CLK_RST, BIT(2), 0),
+ [RESET_SSPA0] = RESET_DATA(APBC_SSPA0_CLK_RST, BIT(2), 0),
+ [RESET_SSPA1] = RESET_DATA(APBC_SSPA1_CLK_RST, BIT(2), 0),
+ [RESET_DRO] = RESET_DATA(APBC_DRO_CLK_RST, BIT(2), 0),
+ [RESET_IR] = RESET_DATA(APBC_IR_CLK_RST, BIT(2), 0),
+ [RESET_TWSI1] = RESET_DATA(APBC_TWSI1_CLK_RST, BIT(2), 0),
+ [RESET_TSEN] = RESET_DATA(APBC_TSEN_CLK_RST, BIT(2), 0),
+ [RESET_TWSI2] = RESET_DATA(APBC_TWSI2_CLK_RST, BIT(2), 0),
+ [RESET_TWSI4] = RESET_DATA(APBC_TWSI4_CLK_RST, BIT(2), 0),
+ [RESET_TWSI5] = RESET_DATA(APBC_TWSI5_CLK_RST, BIT(2), 0),
+ [RESET_TWSI6] = RESET_DATA(APBC_TWSI6_CLK_RST, BIT(2), 0),
+ [RESET_TWSI7] = RESET_DATA(APBC_TWSI7_CLK_RST, BIT(2), 0),
+ [RESET_TWSI8] = RESET_DATA(APBC_TWSI8_CLK_RST, BIT(2), 0),
+ [RESET_IPC_AP2AUD] = RESET_DATA(APBC_IPC_AP2AUD_CLK_RST, BIT(2), 0),
+ [RESET_UART4] = RESET_DATA(APBC_UART4_CLK_RST, BIT(2), 0),
+ [RESET_UART5] = RESET_DATA(APBC_UART5_CLK_RST, BIT(2), 0),
+ [RESET_UART6] = RESET_DATA(APBC_UART6_CLK_RST, BIT(2), 0),
+ [RESET_UART7] = RESET_DATA(APBC_UART7_CLK_RST, BIT(2), 0),
+ [RESET_UART8] = RESET_DATA(APBC_UART8_CLK_RST, BIT(2), 0),
+ [RESET_UART9] = RESET_DATA(APBC_UART9_CLK_RST, BIT(2), 0),
+ [RESET_CAN0] = RESET_DATA(APBC_CAN0_CLK_RST, BIT(2), 0),
+};
+
+static const struct ccu_reset_controller_data k1_apbc_reset_data = {
+ .reset_data = apbc_resets,
+ .count = ARRAY_SIZE(apbc_resets),
+};
+
+static const struct ccu_reset_data apmu_resets[] = {
+ [RESET_CCIC_4X] = RESET_DATA(APMU_CCIC_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_CCIC1_PHY] = RESET_DATA(APMU_CCIC_CLK_RES_CTRL, 0, BIT(2)),
+ [RESET_SDH_AXI] = RESET_DATA(APMU_SDH0_CLK_RES_CTRL, 0, BIT(0)),
+ [RESET_SDH0] = RESET_DATA(APMU_SDH0_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_SDH1] = RESET_DATA(APMU_SDH1_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_SDH2] = RESET_DATA(APMU_SDH2_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_USBP1_AXI] = RESET_DATA(APMU_USB_CLK_RES_CTRL, 0, BIT(4)),
+ [RESET_USB_AXI] = RESET_DATA(APMU_USB_CLK_RES_CTRL, 0, BIT(0)),
+ [RESET_USB3_0] = RESET_DATA(APMU_USB_CLK_RES_CTRL, 0,
+ BIT(11) | BIT(10) | BIT(9)),
+ [RESET_QSPI] = RESET_DATA(APMU_QSPI_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_QSPI_BUS] = RESET_DATA(APMU_QSPI_CLK_RES_CTRL, 0, BIT(0)),
+ [RESET_DMA] = RESET_DATA(APMU_DMA_CLK_RES_CTRL, 0, BIT(0)),
+ [RESET_AES] = RESET_DATA(APMU_AES_CLK_RES_CTRL, 0, BIT(4)),
+ [RESET_VPU] = RESET_DATA(APMU_VPU_CLK_RES_CTRL, 0, BIT(0)),
+ [RESET_GPU] = RESET_DATA(APMU_GPU_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_EMMC] = RESET_DATA(APMU_PMUA_EM_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_EMMC_X] = RESET_DATA(APMU_PMUA_EM_CLK_RES_CTRL, 0, BIT(0)),
+ [RESET_AUDIO] = RESET_DATA(APMU_AUDIO_CLK_RES_CTRL, 0,
+ BIT(3) | BIT(2) | BIT(0)),
+ [RESET_HDMI] = RESET_DATA(APMU_HDMI_CLK_RES_CTRL, 0, BIT(9)),
+ [RESET_PCIE0] = RESET_DATA(APMU_PCIE_CLK_RES_CTRL_0, BIT(8),
+ BIT(5) | BIT(4) | BIT(3)),
+ [RESET_PCIE1] = RESET_DATA(APMU_PCIE_CLK_RES_CTRL_1, BIT(8),
+ BIT(5) | BIT(4) | BIT(3)),
+ [RESET_PCIE2] = RESET_DATA(APMU_PCIE_CLK_RES_CTRL_2, BIT(8),
+ BIT(5) | BIT(4) | BIT(3)),
+ [RESET_EMAC0] = RESET_DATA(APMU_EMAC0_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_EMAC1] = RESET_DATA(APMU_EMAC1_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_JPG] = RESET_DATA(APMU_JPG_CLK_RES_CTRL, 0, BIT(0)),
+ [RESET_CCIC2PHY] = RESET_DATA(APMU_CSI_CCIC2_CLK_RES_CTRL, 0, BIT(2)),
+ [RESET_CCIC3PHY] = RESET_DATA(APMU_CSI_CCIC2_CLK_RES_CTRL, 0, BIT(29)),
+ [RESET_CSI] = RESET_DATA(APMU_CSI_CCIC2_CLK_RES_CTRL, 0, BIT(1)),
+ [RESET_ISP] = RESET_DATA(APMU_ISP_CLK_RES_CTRL, 0, BIT(0)),
+ [RESET_ISP_CPP] = RESET_DATA(APMU_ISP_CLK_RES_CTRL, 0, BIT(27)),
+ [RESET_ISP_BUS] = RESET_DATA(APMU_ISP_CLK_RES_CTRL, 0, BIT(3)),
+ [RESET_ISP_CI] = RESET_DATA(APMU_ISP_CLK_RES_CTRL, 0, BIT(16)),
+ [RESET_DPU_MCLK] = RESET_DATA(APMU_LCD_CLK_RES_CTRL2, 0, BIT(9)),
+ [RESET_DPU_ESC] = RESET_DATA(APMU_LCD_CLK_RES_CTRL1, 0, BIT(3)),
+ [RESET_DPU_HCLK] = RESET_DATA(APMU_LCD_CLK_RES_CTRL1, 0, BIT(4)),
+ [RESET_DPU_SPIBUS] = RESET_DATA(APMU_LCD_SPI_CLK_RES_CTRL, 0, BIT(4)),
+ [RESET_DPU_SPI_HBUS] = RESET_DATA(APMU_LCD_SPI_CLK_RES_CTRL, 0, BIT(2)),
+ [RESET_V2D] = RESET_DATA(APMU_LCD_CLK_RES_CTRL1, 0, BIT(27)),
+ [RESET_MIPI] = RESET_DATA(APMU_LCD_CLK_RES_CTRL1, 0, BIT(15)),
+ [RESET_MC] = RESET_DATA(APMU_PMUA_MC_CTRL, 0, BIT(0)),
+};
+
+static const struct ccu_reset_controller_data k1_apmu_reset_data = {
+ .reset_data = apmu_resets,
+ .count = ARRAY_SIZE(apmu_resets),
+};
+
+static int spacemit_k1_reset_probe(struct auxiliary_device *adev,
+ const struct auxiliary_device_id *id)
+{
+ struct spacemit_ccu_adev *rdev = to_spacemit_ccu_adev(adev);
+ const void *data = (void *)id->driver_data;
+ struct ccu_reset_controller *controller;
+ struct device *dev = &adev->dev;
+
+ controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);
+ if (!controller)
+ return -ENODEV;
+ controller->data = data;
+ controller->regmap = rdev->regmap;
+
+ return spacemit_reset_controller_register(dev, controller);
+}
+
+#define K1_AUX_DEV_ID(_unit) \
+ { \
+ .name = "spacemit_ccu_k1." #_unit "-reset", \
+ .driver_data = (kernel_ulong_t)&k1_ ## _unit ## _reset_data, \
+ }
+
+static const struct auxiliary_device_id spacemit_k1_reset_ids[] = {
+ K1_AUX_DEV_ID(mpmu),
+ K1_AUX_DEV_ID(apbc),
+ K1_AUX_DEV_ID(apmu),
+ { },
+};
+MODULE_DEVICE_TABLE(auxiliary, spacemit_k1_reset_ids);
+
+#undef K1_AUX_DEV_ID
+
+static struct auxiliary_driver spacemit_k1_reset_driver = {
+ .probe = spacemit_k1_reset_probe,
+ .id_table = spacemit_k1_reset_ids,
+};
+module_auxiliary_driver(spacemit_k1_reset_driver);
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v6 5/6] reset: spacemit: define three more CCUs
2025-05-06 21:06 [PATCH v6 0/6] clk: spacemit: add K1 reset support Alex Elder
` (3 preceding siblings ...)
2025-05-06 21:06 ` [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets Alex Elder
@ 2025-05-06 21:06 ` Alex Elder
2025-05-08 9:11 ` Philipp Zabel
2025-05-06 21:06 ` [PATCH v6 6/6] riscv: dts: spacemit: add reset support for the K1 SoC Alex Elder
5 siblings, 1 reply; 27+ messages in thread
From: Alex Elder @ 2025-05-06 21:06 UTC (permalink / raw)
To: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
Three more CCUs on the SpacemiT K1 SoC implement only resets, not clocks.
Define these resets so they can be used.
Signed-off-by: Alex Elder <elder@riscstar.com>
---
drivers/clk/spacemit/ccu-k1.c | 24 ++++++++++++++++
drivers/reset/spacemit/k1.c | 54 +++++++++++++++++++++++++++++++++++
include/soc/spacemit/ccu_k1.h | 30 +++++++++++++++++++
3 files changed, 108 insertions(+)
diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c
index 6b1845e899e5f..bddc83aff23cd 100644
--- a/drivers/clk/spacemit/ccu-k1.c
+++ b/drivers/clk/spacemit/ccu-k1.c
@@ -939,6 +939,18 @@ static const struct spacemit_ccu_data k1_ccu_apmu_data = {
.num = ARRAY_SIZE(k1_ccu_apmu_hws),
};
+static const struct spacemit_ccu_data k1_ccu_rcpu_data = {
+ .reset_name = "rcpu-reset",
+};
+
+static const struct spacemit_ccu_data k1_ccu_rcpu2_data = {
+ .reset_name = "rcpu2-reset",
+};
+
+static const struct spacemit_ccu_data k1_ccu_apbc2_data = {
+ .reset_name = "apbc2-reset",
+};
+
static int spacemit_ccu_register(struct device *dev,
struct regmap *regmap,
struct regmap *lock_regmap,
@@ -1106,6 +1118,18 @@ static const struct of_device_id of_k1_ccu_match[] = {
.compatible = "spacemit,k1-syscon-apmu",
.data = &k1_ccu_apmu_data,
},
+ {
+ .compatible = "spacemit,k1-syscon-rcpu",
+ .data = &k1_ccu_rcpu_data,
+ },
+ {
+ .compatible = "spacemit,k1-syscon-rcpu2",
+ .data = &k1_ccu_rcpu2_data,
+ },
+ {
+ .compatible = "spacemit,k1-syscon-apbc2",
+ .data = &k1_ccu_apbc2_data,
+ },
{ }
};
MODULE_DEVICE_TABLE(of, of_k1_ccu_match);
diff --git a/drivers/reset/spacemit/k1.c b/drivers/reset/spacemit/k1.c
index 19a34f151b214..27434a1928261 100644
--- a/drivers/reset/spacemit/k1.c
+++ b/drivers/reset/spacemit/k1.c
@@ -137,6 +137,57 @@ static const struct ccu_reset_controller_data k1_apmu_reset_data = {
.count = ARRAY_SIZE(apmu_resets),
};
+static const struct ccu_reset_data rcpu_resets[] = {
+ [RESET_RCPU_SSP0] = RESET_DATA(RCPU_SSP0_CLK_RST, 0, BIT(0)),
+ [RESET_RCPU_I2C0] = RESET_DATA(RCPU_I2C0_CLK_RST, 0, BIT(0)),
+ [RESET_RCPU_UART1] = RESET_DATA(RCPU_UART1_CLK_RST, 0, BIT(0)),
+ [RESET_RCPU_IR] = RESET_DATA(RCPU_CAN_CLK_RST, 0, BIT(0)),
+ [RESET_RCPU_CAN] = RESET_DATA(RCPU_IR_CLK_RST, 0, BIT(0)),
+ [RESET_RCPU_UART0] = RESET_DATA(RCPU_UART0_CLK_RST, 0, BIT(0)),
+ [RESET_RCPU_HDMI_AUDIO] = RESET_DATA(AUDIO_HDMI_CLK_CTRL, 0, BIT(0)),
+};
+
+static const struct ccu_reset_controller_data k1_rcpu_reset_data = {
+ /* No clocks in the RCPU CCU */
+ .reset_data = rcpu_resets,
+ .count = ARRAY_SIZE(rcpu_resets),
+};
+
+static const struct ccu_reset_data rcpu2_resets[] = {
+ [RESET_RCPU2_PWM0] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_RCPU2_PWM1] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_RCPU2_PWM2] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_RCPU2_PWM3] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_RCPU2_PWM4] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_RCPU2_PWM5] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_RCPU2_PWM6] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_RCPU2_PWM7] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_RCPU2_PWM8] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+ [RESET_RCPU2_PWM9] = RESET_DATA(RCPU2_PWM9_CLK_RST, BIT(2), BIT(0)),
+};
+
+static const struct ccu_reset_controller_data k1_rcpu2_reset_data = {
+ /* No clocks in the RCPU2 CCU */
+ .reset_data = rcpu2_resets,
+ .count = ARRAY_SIZE(rcpu2_resets),
+};
+
+static const struct ccu_reset_data apbc2_resets[] = {
+ [RESET_APBC2_UART1] = RESET_DATA(APBC2_UART1_CLK_RST, BIT(2), 0),
+ [RESET_APBC2_SSP2] = RESET_DATA(APBC2_SSP2_CLK_RST, BIT(2), 0),
+ [RESET_APBC2_TWSI3] = RESET_DATA(APBC2_TWSI3_CLK_RST, BIT(2), 0),
+ [RESET_APBC2_RTC] = RESET_DATA(APBC2_RTC_CLK_RST, BIT(2), 0),
+ [RESET_APBC2_TIMERS0] = RESET_DATA(APBC2_TIMERS0_CLK_RST, BIT(2), 0),
+ [RESET_APBC2_KPC] = RESET_DATA(APBC2_KPC_CLK_RST, BIT(2), 0),
+ [RESET_APBC2_GPIO] = RESET_DATA(APBC2_GPIO_CLK_RST, BIT(2), 0),
+};
+
+static const struct ccu_reset_controller_data k1_apbc2_reset_data = {
+ /* No clocks in the APBC2 CCU */
+ .reset_data = apbc2_resets,
+ .count = ARRAY_SIZE(apbc2_resets),
+};
+
static int spacemit_k1_reset_probe(struct auxiliary_device *adev,
const struct auxiliary_device_id *id)
{
@@ -164,6 +215,9 @@ static const struct auxiliary_device_id spacemit_k1_reset_ids[] = {
K1_AUX_DEV_ID(mpmu),
K1_AUX_DEV_ID(apbc),
K1_AUX_DEV_ID(apmu),
+ K1_AUX_DEV_ID(rcpu),
+ K1_AUX_DEV_ID(rcpu2),
+ K1_AUX_DEV_ID(apbc2),
{ },
};
MODULE_DEVICE_TABLE(auxiliary, spacemit_k1_reset_ids);
diff --git a/include/soc/spacemit/ccu_k1.h b/include/soc/spacemit/ccu_k1.h
index 8b2581fb3055d..66035012317c9 100644
--- a/include/soc/spacemit/ccu_k1.h
+++ b/include/soc/spacemit/ccu_k1.h
@@ -123,3 +123,33 @@ to_spacemit_ccu_adev(struct auxiliary_device *adev)
#define APMU_PCIE_CLK_RES_CTRL_2 0x3dc
#define APMU_EMAC0_CLK_RES_CTRL 0x3e4
#define APMU_EMAC1_CLK_RES_CTRL 0x3ec
+
+/* RCPU register offsets */
+#define RCPU_SSP0_CLK_RST 0x0028
+#define RCPU_I2C0_CLK_RST 0x0030
+#define RCPU_UART1_CLK_RST 0x003c
+#define RCPU_CAN_CLK_RST 0x0048
+#define RCPU_IR_CLK_RST 0x004c
+#define RCPU_UART0_CLK_RST 0x00d8
+#define AUDIO_HDMI_CLK_CTRL 0x2044
+
+/* RCPU2 register offsets */
+#define RCPU2_PWM0_CLK_RST 0x0000
+#define RCPU2_PWM1_CLK_RST 0x0004
+#define RCPU2_PWM2_CLK_RST 0x0008
+#define RCPU2_PWM3_CLK_RST 0x000c
+#define RCPU2_PWM4_CLK_RST 0x0010
+#define RCPU2_PWM5_CLK_RST 0x0014
+#define RCPU2_PWM6_CLK_RST 0x0018
+#define RCPU2_PWM7_CLK_RST 0x001c
+#define RCPU2_PWM8_CLK_RST 0x0020
+#define RCPU2_PWM9_CLK_RST 0x0024
+
+/* APBC2 register offsets */
+#define APBC2_UART1_CLK_RST 0x0000
+#define APBC2_SSP2_CLK_RST 0x0004
+#define APBC2_TWSI3_CLK_RST 0x0008
+#define APBC2_RTC_CLK_RST 0x000c
+#define APBC2_TIMERS0_CLK_RST 0x0010
+#define APBC2_KPC_CLK_RST 0x0014
+#define APBC2_GPIO_CLK_RST 0x001c
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* [PATCH v6 6/6] riscv: dts: spacemit: add reset support for the K1 SoC
2025-05-06 21:06 [PATCH v6 0/6] clk: spacemit: add K1 reset support Alex Elder
` (4 preceding siblings ...)
2025-05-06 21:06 ` [PATCH v6 5/6] reset: spacemit: define three more CCUs Alex Elder
@ 2025-05-06 21:06 ` Alex Elder
5 siblings, 0 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-06 21:06 UTC (permalink / raw)
To: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
Define syscon nodes for the RCPU, RCPU2, and APBC2 SpacemiT CCUS, which
currently support resets but not clocks in the SpacemiT K1.
Signed-off-by: Alex Elder <elder@riscstar.com>
---
arch/riscv/boot/dts/spacemit/k1.dtsi | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/arch/riscv/boot/dts/spacemit/k1.dtsi b/arch/riscv/boot/dts/spacemit/k1.dtsi
index 6eec6328c26fe..f4afb35dc6bc9 100644
--- a/arch/riscv/boot/dts/spacemit/k1.dtsi
+++ b/arch/riscv/boot/dts/spacemit/k1.dtsi
@@ -346,6 +346,18 @@ soc {
dma-noncoherent;
ranges;
+ syscon_rcpu: system-controller@c0880000 {
+ compatible = "spacemit,k1-syscon-rcpu";
+ reg = <0x0 0xc0880000 0x0 0x2048>;
+ #reset-cells = <1>;
+ };
+
+ syscon_rcpu2: system-controller@c0888000 {
+ compatible = "spacemit,k1-syscon-rcpu2";
+ reg = <0x0 0xc0888000 0x0 0x28>;
+ #reset-cells = <1>;
+ };
+
syscon_apbc: system-control@d4015000 {
compatible = "spacemit,k1-syscon-apbc";
reg = <0x0 0xd4015000 0x0 0x1000>;
@@ -553,6 +565,12 @@ clint: timer@e4000000 {
<&cpu7_intc 3>, <&cpu7_intc 7>;
};
+ syscon_apbc2: system-controller@f0610000 {
+ compatible = "spacemit,k1-syscon-apbc2";
+ reg = <0x0 0xf0610000 0x0 0x20>;
+ #reset-cells = <1>;
+ };
+
sec_uart1: serial@f0612000 {
compatible = "spacemit,k1-uart", "intel,xscale-uart";
reg = <0x0 0xf0612000 0x0 0x100>;
--
2.45.2
^ permalink raw reply related [flat|nested] 27+ messages in thread
* Re: [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets
2025-05-06 21:06 ` [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets Alex Elder
@ 2025-05-07 22:35 ` Yixun Lan
2025-05-08 2:19 ` Alex Elder
2025-05-08 12:02 ` Krzysztof Kozlowski
0 siblings, 2 replies; 27+ messages in thread
From: Yixun Lan @ 2025-05-07 22:35 UTC (permalink / raw)
To: Alex Elder
Cc: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, heylenay, inochiama, guodong,
devicetree, linux-clk, spacemit, linux-riscv, linux-kernel,
Krzysztof Kozlowski
hi Alex,
On 16:06 Tue 06 May , Alex Elder wrote:
> There are additional SpacemiT syscon CCUs whose registers control both
> clocks and resets: RCPU, RCPU2, and APBC2. Unlike those defined
> previously, these will (initially) support only resets. They do not
> incorporate power domain functionality.
>
> Previously the clock properties were required for all compatible nodes.
> Make that requirement only apply to the three existing CCUs (APBC, APMU,
> and MPMU), so that the new reset-only CCUs can go without specifying them.
>
> Define the index values for resets associated with all SpacemiT K1
> syscon nodes, including those with clocks already defined, as well as
> the new ones (without clocks).
>
> Signed-off-by: Alex Elder <elder@riscstar.com>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
> .../soc/spacemit/spacemit,k1-syscon.yaml | 29 +++-
> .../dt-bindings/clock/spacemit,k1-syscon.h | 128 ++++++++++++++++++
> 2 files changed, 150 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml b/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml
> index 30aaf49da03d3..133a391ee68cd 100644
> --- a/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml
> +++ b/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml
> @@ -19,6 +19,9 @@ properties:
> - spacemit,k1-syscon-apbc
> - spacemit,k1-syscon-apmu
> - spacemit,k1-syscon-mpmu
> + - spacemit,k1-syscon-rcpu
> + - spacemit,k1-syscon-rcpu2
> + - spacemit,k1-syscon-apbc2
>
> reg:
> maxItems: 1
> @@ -47,9 +50,6 @@ properties:
> required:
> - compatible
> - reg
> - - clocks
> - - clock-names
> - - "#clock-cells"
> - "#reset-cells"
>
> allOf:
> @@ -57,13 +57,28 @@ allOf:
> properties:
> compatible:
> contains:
> - const: spacemit,k1-syscon-apbc
> + enum:
> + - spacemit,k1-syscon-apmu
> + - spacemit,k1-syscon-mpmu
> then:
> - properties:
> - "#power-domain-cells": false
> - else:
> required:
> - "#power-domain-cells"
> + else:
> + properties:
> + "#power-domain-cells": false
> + - if:
> + properties:
> + compatible:
> + contains:
> + enum:
> + - spacemit,k1-syscon-apbc
> + - spacemit,k1-syscon-apmu
> + - spacemit,k1-syscon-mpmu
> + then:
> + required:
> + - clocks
> + - clock-names
> + - "#clock-cells"
>
> additionalProperties: false
>
> diff --git a/include/dt-bindings/clock/spacemit,k1-syscon.h b/include/dt-bindings/clock/spacemit,k1-syscon.h
> index 35968ae982466..f5965dda3b905 100644
> --- a/include/dt-bindings/clock/spacemit,k1-syscon.h
> +++ b/include/dt-bindings/clock/spacemit,k1-syscon.h
would it be better to move all reset definition to its dedicated dir?
which like: include/dt-bindings/reset/spacemit,k1-syscon.h?
> @@ -78,6 +78,9 @@
> #define CLK_APB 31
> #define CLK_WDT_BUS 32
>
> +/* MPMU resets */
> +#define RESET_WDT 0
> +
> /* APBC clocks */
> #define CLK_UART0 0
> #define CLK_UART2 1
> @@ -180,6 +183,59 @@
> #define CLK_TSEN_BUS 98
> #define CLK_IPC_AP2AUD_BUS 99
>
> +/* APBC resets */
> +#define RESET_UART0 0
> +#define RESET_UART2 1
> +#define RESET_UART3 2
> +#define RESET_UART4 3
> +#define RESET_UART5 4
> +#define RESET_UART6 5
> +#define RESET_UART7 6
> +#define RESET_UART8 7
> +#define RESET_UART9 8
> +#define RESET_GPIO 9
> +#define RESET_PWM0 10
> +#define RESET_PWM1 11
> +#define RESET_PWM2 12
> +#define RESET_PWM3 13
> +#define RESET_PWM4 14
> +#define RESET_PWM5 15
> +#define RESET_PWM6 16
> +#define RESET_PWM7 17
> +#define RESET_PWM8 18
> +#define RESET_PWM9 19
> +#define RESET_PWM10 20
> +#define RESET_PWM11 21
> +#define RESET_PWM12 22
> +#define RESET_PWM13 23
> +#define RESET_PWM14 24
> +#define RESET_PWM15 25
> +#define RESET_PWM16 26
> +#define RESET_PWM17 27
> +#define RESET_PWM18 28
> +#define RESET_PWM19 29
> +#define RESET_SSP3 30
> +#define RESET_RTC 31
> +#define RESET_TWSI0 32
> +#define RESET_TWSI1 33
> +#define RESET_TWSI2 34
> +#define RESET_TWSI4 35
> +#define RESET_TWSI5 36
> +#define RESET_TWSI6 37
> +#define RESET_TWSI7 38
> +#define RESET_TWSI8 39
> +#define RESET_TIMERS1 40
> +#define RESET_TIMERS2 41
> +#define RESET_AIB 42
> +#define RESET_ONEWIRE 43
> +#define RESET_SSPA0 44
> +#define RESET_SSPA1 45
> +#define RESET_DRO 46
> +#define RESET_IR 47
> +#define RESET_TSEN 48
> +#define RESET_IPC_AP2AUD 49
> +#define RESET_CAN0 50
> +
> /* APMU clocks */
> #define CLK_CCI550 0
> #define CLK_CPU_C0_HI 1
> @@ -244,4 +300,76 @@
> #define CLK_V2D 60
> #define CLK_EMMC_BUS 61
>
> +/* APMU resets */
> +#define RESET_CCIC_4X 0
> +#define RESET_CCIC1_PHY 1
> +#define RESET_SDH_AXI 2
> +#define RESET_SDH0 3
> +#define RESET_SDH1 4
> +#define RESET_SDH2 5
> +#define RESET_USBP1_AXI 6
> +#define RESET_USB_AXI 7
> +#define RESET_USB3_0 8
> +#define RESET_QSPI 9
> +#define RESET_QSPI_BUS 10
> +#define RESET_DMA 11
> +#define RESET_AES 12
> +#define RESET_VPU 13
> +#define RESET_GPU 14
> +#define RESET_EMMC 15
> +#define RESET_EMMC_X 16
> +#define RESET_AUDIO 17
> +#define RESET_HDMI 18
> +#define RESET_PCIE0 19
> +#define RESET_PCIE1 20
> +#define RESET_PCIE2 21
> +#define RESET_EMAC0 22
> +#define RESET_EMAC1 23
> +#define RESET_JPG 24
> +#define RESET_CCIC2PHY 25
> +#define RESET_CCIC3PHY 26
> +#define RESET_CSI 27
> +#define RESET_ISP_CPP 28
> +#define RESET_ISP_BUS 29
> +#define RESET_ISP 30
> +#define RESET_ISP_CI 31
> +#define RESET_DPU_MCLK 32
> +#define RESET_DPU_ESC 33
> +#define RESET_DPU_HCLK 34
> +#define RESET_DPU_SPIBUS 35
> +#define RESET_DPU_SPI_HBUS 36
> +#define RESET_V2D 37
> +#define RESET_MIPI 38
> +#define RESET_MC 39
> +
> +/* RCPU resets */
> +#define RESET_RCPU_SSP0 0
> +#define RESET_RCPU_I2C0 1
> +#define RESET_RCPU_UART1 2
> +#define RESET_RCPU_IR 3
> +#define RESET_RCPU_CAN 4
> +#define RESET_RCPU_UART0 5
> +#define RESET_RCPU_HDMI_AUDIO 6
> +
> +/* RCPU2 resets */
> +#define RESET_RCPU2_PWM0 0
> +#define RESET_RCPU2_PWM1 1
> +#define RESET_RCPU2_PWM2 2
> +#define RESET_RCPU2_PWM3 3
> +#define RESET_RCPU2_PWM4 4
> +#define RESET_RCPU2_PWM5 5
> +#define RESET_RCPU2_PWM6 6
> +#define RESET_RCPU2_PWM7 7
> +#define RESET_RCPU2_PWM8 8
> +#define RESET_RCPU2_PWM9 9
> +
> +/* APBC2 resets */
> +#define RESET_APBC2_UART1 0
> +#define RESET_APBC2_SSP2 1
> +#define RESET_APBC2_TWSI3 2
> +#define RESET_APBC2_RTC 3
> +#define RESET_APBC2_TIMERS0 4
> +#define RESET_APBC2_KPC 5
> +#define RESET_APBC2_GPIO 6
> +
> #endif /* _DT_BINDINGS_SPACEMIT_CCU_H_ */
> --
> 2.45.2
>
--
Yixun Lan (dlan)
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets
2025-05-07 22:35 ` Yixun Lan
@ 2025-05-08 2:19 ` Alex Elder
2025-05-08 12:02 ` Krzysztof Kozlowski
1 sibling, 0 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-08 2:19 UTC (permalink / raw)
To: Yixun Lan
Cc: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, heylenay, inochiama, guodong,
devicetree, linux-clk, spacemit, linux-riscv, linux-kernel,
Krzysztof Kozlowski
On 5/7/25 5:35 PM, Yixun Lan wrote:
> hi Alex,
>
> On 16:06 Tue 06 May , Alex Elder wrote:
>> There are additional SpacemiT syscon CCUs whose registers control both
>> clocks and resets: RCPU, RCPU2, and APBC2. Unlike those defined
>> previously, these will (initially) support only resets. They do not
>> incorporate power domain functionality.
>>
>> Previously the clock properties were required for all compatible nodes.
>> Make that requirement only apply to the three existing CCUs (APBC, APMU,
>> and MPMU), so that the new reset-only CCUs can go without specifying them.
>>
>> Define the index values for resets associated with all SpacemiT K1
>> syscon nodes, including those with clocks already defined, as well as
>> the new ones (without clocks).
>>
>> Signed-off-by: Alex Elder <elder@riscstar.com>
>> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
>> ---
>> .../soc/spacemit/spacemit,k1-syscon.yaml | 29 +++-
>> .../dt-bindings/clock/spacemit,k1-syscon.h | 128 ++++++++++++++++++
>> 2 files changed, 150 insertions(+), 7 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml b/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml
>> index 30aaf49da03d3..133a391ee68cd 100644
>> --- a/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml
>> +++ b/Documentation/devicetree/bindings/soc/spacemit/spacemit,k1-syscon.yaml
>> @@ -19,6 +19,9 @@ properties:
>> - spacemit,k1-syscon-apbc
>> - spacemit,k1-syscon-apmu
>> - spacemit,k1-syscon-mpmu
>> + - spacemit,k1-syscon-rcpu
>> + - spacemit,k1-syscon-rcpu2
>> + - spacemit,k1-syscon-apbc2
>>
>> reg:
>> maxItems: 1
>> @@ -47,9 +50,6 @@ properties:
>> required:
>> - compatible
>> - reg
>> - - clocks
>> - - clock-names
>> - - "#clock-cells"
>> - "#reset-cells"
>>
>> allOf:
>> @@ -57,13 +57,28 @@ allOf:
>> properties:
>> compatible:
>> contains:
>> - const: spacemit,k1-syscon-apbc
>> + enum:
>> + - spacemit,k1-syscon-apmu
>> + - spacemit,k1-syscon-mpmu
>> then:
>> - properties:
>> - "#power-domain-cells": false
>> - else:
>> required:
>> - "#power-domain-cells"
>> + else:
>> + properties:
>> + "#power-domain-cells": false
>> + - if:
>> + properties:
>> + compatible:
>> + contains:
>> + enum:
>> + - spacemit,k1-syscon-apbc
>> + - spacemit,k1-syscon-apmu
>> + - spacemit,k1-syscon-mpmu
>> + then:
>> + required:
>> + - clocks
>> + - clock-names
>> + - "#clock-cells"
>>
>> additionalProperties: false
>>
>> diff --git a/include/dt-bindings/clock/spacemit,k1-syscon.h b/include/dt-bindings/clock/spacemit,k1-syscon.h
>> index 35968ae982466..f5965dda3b905 100644
>> --- a/include/dt-bindings/clock/spacemit,k1-syscon.h
>> +++ b/include/dt-bindings/clock/spacemit,k1-syscon.h
> would it be better to move all reset definition to its dedicated dir?
> which like: include/dt-bindings/reset/spacemit,k1-syscon.h?
That's fine with me. I should have thought of that.
Krzysztof, I'll drop your Reviewed-by if I make that change,
but if you say I can before I post v7 I will keep it.
I'll wait a bit more before I update so others can comment
(on this or anything else).
Thanks.
-Alex
>
>> @@ -78,6 +78,9 @@
>> #define CLK_APB 31
>> #define CLK_WDT_BUS 32
>>
>> +/* MPMU resets */
>> +#define RESET_WDT 0
>> +
>> /* APBC clocks */
>> #define CLK_UART0 0
>> #define CLK_UART2 1
>> @@ -180,6 +183,59 @@
>> #define CLK_TSEN_BUS 98
>> #define CLK_IPC_AP2AUD_BUS 99
>>
>> +/* APBC resets */
>> +#define RESET_UART0 0
>> +#define RESET_UART2 1
>> +#define RESET_UART3 2
>> +#define RESET_UART4 3
>> +#define RESET_UART5 4
>> +#define RESET_UART6 5
>> +#define RESET_UART7 6
>> +#define RESET_UART8 7
>> +#define RESET_UART9 8
>> +#define RESET_GPIO 9
>> +#define RESET_PWM0 10
>> +#define RESET_PWM1 11
>> +#define RESET_PWM2 12
>> +#define RESET_PWM3 13
>> +#define RESET_PWM4 14
>> +#define RESET_PWM5 15
>> +#define RESET_PWM6 16
>> +#define RESET_PWM7 17
>> +#define RESET_PWM8 18
>> +#define RESET_PWM9 19
>> +#define RESET_PWM10 20
>> +#define RESET_PWM11 21
>> +#define RESET_PWM12 22
>> +#define RESET_PWM13 23
>> +#define RESET_PWM14 24
>> +#define RESET_PWM15 25
>> +#define RESET_PWM16 26
>> +#define RESET_PWM17 27
>> +#define RESET_PWM18 28
>> +#define RESET_PWM19 29
>> +#define RESET_SSP3 30
>> +#define RESET_RTC 31
>> +#define RESET_TWSI0 32
>> +#define RESET_TWSI1 33
>> +#define RESET_TWSI2 34
>> +#define RESET_TWSI4 35
>> +#define RESET_TWSI5 36
>> +#define RESET_TWSI6 37
>> +#define RESET_TWSI7 38
>> +#define RESET_TWSI8 39
>> +#define RESET_TIMERS1 40
>> +#define RESET_TIMERS2 41
>> +#define RESET_AIB 42
>> +#define RESET_ONEWIRE 43
>> +#define RESET_SSPA0 44
>> +#define RESET_SSPA1 45
>> +#define RESET_DRO 46
>> +#define RESET_IR 47
>> +#define RESET_TSEN 48
>> +#define RESET_IPC_AP2AUD 49
>> +#define RESET_CAN0 50
>> +
>> /* APMU clocks */
>> #define CLK_CCI550 0
>> #define CLK_CPU_C0_HI 1
>> @@ -244,4 +300,76 @@
>> #define CLK_V2D 60
>> #define CLK_EMMC_BUS 61
>>
>> +/* APMU resets */
>> +#define RESET_CCIC_4X 0
>> +#define RESET_CCIC1_PHY 1
>> +#define RESET_SDH_AXI 2
>> +#define RESET_SDH0 3
>> +#define RESET_SDH1 4
>> +#define RESET_SDH2 5
>> +#define RESET_USBP1_AXI 6
>> +#define RESET_USB_AXI 7
>> +#define RESET_USB3_0 8
>> +#define RESET_QSPI 9
>> +#define RESET_QSPI_BUS 10
>> +#define RESET_DMA 11
>> +#define RESET_AES 12
>> +#define RESET_VPU 13
>> +#define RESET_GPU 14
>> +#define RESET_EMMC 15
>> +#define RESET_EMMC_X 16
>> +#define RESET_AUDIO 17
>> +#define RESET_HDMI 18
>> +#define RESET_PCIE0 19
>> +#define RESET_PCIE1 20
>> +#define RESET_PCIE2 21
>> +#define RESET_EMAC0 22
>> +#define RESET_EMAC1 23
>> +#define RESET_JPG 24
>> +#define RESET_CCIC2PHY 25
>> +#define RESET_CCIC3PHY 26
>> +#define RESET_CSI 27
>> +#define RESET_ISP_CPP 28
>> +#define RESET_ISP_BUS 29
>> +#define RESET_ISP 30
>> +#define RESET_ISP_CI 31
>> +#define RESET_DPU_MCLK 32
>> +#define RESET_DPU_ESC 33
>> +#define RESET_DPU_HCLK 34
>> +#define RESET_DPU_SPIBUS 35
>> +#define RESET_DPU_SPI_HBUS 36
>> +#define RESET_V2D 37
>> +#define RESET_MIPI 38
>> +#define RESET_MC 39
>> +
>> +/* RCPU resets */
>> +#define RESET_RCPU_SSP0 0
>> +#define RESET_RCPU_I2C0 1
>> +#define RESET_RCPU_UART1 2
>> +#define RESET_RCPU_IR 3
>> +#define RESET_RCPU_CAN 4
>> +#define RESET_RCPU_UART0 5
>> +#define RESET_RCPU_HDMI_AUDIO 6
>> +
>> +/* RCPU2 resets */
>> +#define RESET_RCPU2_PWM0 0
>> +#define RESET_RCPU2_PWM1 1
>> +#define RESET_RCPU2_PWM2 2
>> +#define RESET_RCPU2_PWM3 3
>> +#define RESET_RCPU2_PWM4 4
>> +#define RESET_RCPU2_PWM5 5
>> +#define RESET_RCPU2_PWM6 6
>> +#define RESET_RCPU2_PWM7 7
>> +#define RESET_RCPU2_PWM8 8
>> +#define RESET_RCPU2_PWM9 9
>> +
>> +/* APBC2 resets */
>> +#define RESET_APBC2_UART1 0
>> +#define RESET_APBC2_SSP2 1
>> +#define RESET_APBC2_TWSI3 2
>> +#define RESET_APBC2_RTC 3
>> +#define RESET_APBC2_TIMERS0 4
>> +#define RESET_APBC2_KPC 5
>> +#define RESET_APBC2_GPIO 6
>> +
>> #endif /* _DT_BINDINGS_SPACEMIT_CCU_H_ */
>> --
>> 2.45.2
>>
>
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices
2025-05-06 21:06 ` [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices Alex Elder
@ 2025-05-08 4:09 ` kernel test robot
2025-05-08 4:46 ` Haylen Chu
1 sibling, 0 replies; 27+ messages in thread
From: kernel test robot @ 2025-05-08 4:09 UTC (permalink / raw)
To: Alex Elder, robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: llvm, oe-kbuild-all, heylenay, inochiama, guodong, devicetree,
linux-clk, spacemit, linux-riscv, linux-kernel
Hi Alex,
kernel test robot noticed the following build errors:
[auto build test ERROR on cb9c3aeae509b36afbdf46942a7a0a0dfc856ce7]
url: https://github.com/intel-lab-lkp/linux/commits/Alex-Elder/dt-bindings-soc-spacemit-define-spacemit-k1-ccu-resets/20250507-051019
base: cb9c3aeae509b36afbdf46942a7a0a0dfc856ce7
patch link: https://lore.kernel.org/r/20250506210638.2800228-4-elder%40riscstar.com
patch subject: [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20250508/202505081113.CwKtDYbs-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250508/202505081113.CwKtDYbs-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505081113.CwKtDYbs-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/clk/spacemit/ccu-k1.c:998:2: error: call to undeclared function 'kfree'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
998 | kfree(to_spacemit_ccu_adev(adev));
| ^
1 error generated.
vim +/kfree +998 drivers/clk/spacemit/ccu-k1.c
993
994 static void spacemit_cadev_release(struct device *dev)
995 {
996 struct auxiliary_device *adev = to_auxiliary_dev(dev);
997
> 998 kfree(to_spacemit_ccu_adev(adev));
999 }
1000
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 2/6] soc: spacemit: create a header for clock/reset registers
2025-05-06 21:06 ` [PATCH v6 2/6] soc: spacemit: create a header for clock/reset registers Alex Elder
@ 2025-05-08 4:16 ` Haylen Chu
2025-05-08 11:40 ` Alex Elder
0 siblings, 1 reply; 27+ messages in thread
From: Haylen Chu @ 2025-05-08 4:16 UTC (permalink / raw)
To: Alex Elder, robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: inochiama, guodong, devicetree, linux-clk, spacemit, linux-riscv,
linux-kernel
On Tue, May 06, 2025 at 04:06:33PM -0500, Alex Elder wrote:
> Move the definitions of register offsets and fields used by the SpacemiT
> K1 SoC CCUs into a separate header file, so that they can be shared by
> the reset driver that will be found under drivers/reset.
>
> Signed-off-by: Alex Elder <elder@riscstar.com>
> ---
> drivers/clk/spacemit/ccu-k1.c | 111 +--------------------------------
> include/soc/spacemit/ccu_k1.h | 113 ++++++++++++++++++++++++++++++++++
CCU is abbreviated from "clock controller unit" thus the filename seems
a little strange to me. Will k1-syscon.h be a better name? We could put
all syscon registers together when introducing the power-domain driver
later, which could provide an overall view of register layout.
> 2 files changed, 114 insertions(+), 110 deletions(-)
> create mode 100644 include/soc/spacemit/ccu_k1.h
Best regards,
Haylen Chu
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices
2025-05-06 21:06 ` [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices Alex Elder
2025-05-08 4:09 ` kernel test robot
@ 2025-05-08 4:46 ` Haylen Chu
2025-05-08 20:04 ` Alex Elder
1 sibling, 1 reply; 27+ messages in thread
From: Haylen Chu @ 2025-05-08 4:46 UTC (permalink / raw)
To: Alex Elder, robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: inochiama, guodong, devicetree, linux-clk, spacemit, linux-riscv,
linux-kernel
On Tue, May 06, 2025 at 04:06:34PM -0500, Alex Elder wrote:
> Add a new reset_name field to the spacemit_ccu_data structure. If it is
> non-null, the CCU implements a reset controller, and the name will be
> used as the name for the auxiliary device that implements it.
>
> Define a new type to hold an auxiliary device as well as the regmap
> pointer that will be needed by CCU reset controllers. Set up code to
> initialize and add an auxiliary device for any CCU that implements reset
> functionality.
>
> Make it optional for a CCU to implement a clock controller. This
> doesn't apply to any of the existing CCUs but will for some new ones
> that will be added soon.
>
> Signed-off-by: Alex Elder <elder@riscstar.com>
> ---
> drivers/clk/spacemit/ccu-k1.c | 85 +++++++++++++++++++++++++++++++----
> include/soc/spacemit/ccu_k1.h | 12 +++++
> 2 files changed, 89 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c
> index 9545cfe60b92b..6b1845e899e5f 100644
> --- a/drivers/clk/spacemit/ccu-k1.c
> +++ b/drivers/clk/spacemit/ccu-k1.c
...
> +static void spacemit_cadev_release(struct device *dev)
> +{
> + struct auxiliary_device *adev = to_auxiliary_dev(dev);
> +
> + kfree(to_spacemit_ccu_adev(adev));
> +}
spacemit_ccu_adev structures are allocated with devm_kzalloc() in
spacemit_ccu_reset_register(), which means its lifetime is bound to the
driver and it'll be automatically released after driver removal; won't
there be a possibility of double-free? I think the release callback
could be simply dropped.
...
> +static int spacemit_ccu_reset_register(struct device *dev,
> + struct regmap *regmap,
> + const char *reset_name)
> +{
> + struct spacemit_ccu_adev *cadev;
> + struct auxiliary_device *adev;
> + static u32 next_id;
> + int ret;
> +
> + /* Nothing to do if the CCU does not implement a reset controller */
> + if (!reset_name)
> + return 0;
> +
> + cadev = devm_kzalloc(dev, sizeof(*cadev), GFP_KERNEL);
Here spacemit_ccu_adev is allocated.
> + if (!cadev)
> + return -ENOMEM;
> + cadev->regmap = regmap;
> +
> + adev = &cadev->adev;
> + adev->name = reset_name;
> + adev->dev.parent = dev;
> + adev->dev.release = spacemit_cadev_release;
> + adev->dev.of_node = dev->of_node;
> + adev->id = next_id++;
> +
> + ret = auxiliary_device_init(adev);
> + if (ret)
> + return ret;
> +
> + ret = auxiliary_device_add(adev);
> + if (ret) {
> + auxiliary_device_uninit(adev);
> + return ret;
> + }
> +
> + return devm_add_action_or_reset(dev, spacemit_adev_unregister, adev);
> +}
> +
Best regards,
Haylen Chu
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets
2025-05-06 21:06 ` [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets Alex Elder
@ 2025-05-08 5:38 ` Haylen Chu
2025-05-08 11:55 ` Alex Elder
2025-05-08 9:01 ` Philipp Zabel
1 sibling, 1 reply; 27+ messages in thread
From: Haylen Chu @ 2025-05-08 5:38 UTC (permalink / raw)
To: Alex Elder, robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: inochiama, guodong, devicetree, linux-clk, spacemit, linux-riscv,
linux-kernel
On Tue, May 06, 2025 at 04:06:35PM -0500, Alex Elder wrote:
> Implement reset support for SpacemiT CCUs. The code is structured to
> handle SpacemiT resets generically, while defining the set of specific
> reset controllers and their resets in an SoC-specific source file. A
> SpacemiT reset controller device is an auxiliary device associated with
> a clock controller (CCU).
>
> This initial patch defines the reset controllers for the MPMU, APBC, and
> MPMU CCUs, which already defined clock controllers.
>
> Signed-off-by: Alex Elder <elder@riscstar.com>
> ---
> drivers/reset/Kconfig | 1 +
> drivers/reset/Makefile | 1 +
> drivers/reset/spacemit/Kconfig | 12 +++
> drivers/reset/spacemit/Makefile | 7 ++
> drivers/reset/spacemit/core.c | 61 +++++++++++
> drivers/reset/spacemit/core.h | 39 +++++++
> drivers/reset/spacemit/k1.c | 177 ++++++++++++++++++++++++++++++++
> 7 files changed, 298 insertions(+)
> create mode 100644 drivers/reset/spacemit/Kconfig
> create mode 100644 drivers/reset/spacemit/Makefile
> create mode 100644 drivers/reset/spacemit/core.c
> create mode 100644 drivers/reset/spacemit/core.h
> create mode 100644 drivers/reset/spacemit/k1.c
>
...
> diff --git a/drivers/reset/spacemit/Kconfig b/drivers/reset/spacemit/Kconfig
> new file mode 100644
> index 0000000000000..4ff3487a99eff
> --- /dev/null
> +++ b/drivers/reset/spacemit/Kconfig
> @@ -0,0 +1,12 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +config RESET_SPACEMIT
> + bool
> +
> +config RESET_SPACEMIT_K1
> + tristate "SpacemiT K1 reset driver"
> + depends on ARCH_SPACEMIT || COMPILE_TEST
> + select RESET_SPACEMIT
> + default ARCH_SPACEMIT
> + help
> + This enables the reset controller driver for the SpacemiT K1 SoC.
With auxiliary bus introduced, Kconfig entries for both the reset and
clock should select AUXILIARY_BUS, or building defconfig will fail with
undefined references,
riscv64-unknown-linux-musl-ld: drivers/clk/spacemit/ccu-k1.o: in function `k1_ccu_probe':
ccu-k1.c:(.text+0x19c): undefined reference to `auxiliary_device_init'
riscv64-unknown-linux-musl-ld: ccu-k1.c:(.text+0x226): undefined reference to `__auxiliary_device_add'
riscv64-unknown-linux-musl-ld: drivers/reset/spacemit/k1.o: in function `spacemit_k1_reset_driver_init':
k1.c:(.init.text+0x1a): undefined reference to `__auxiliary_driver_register'
riscv64-unknown-linux-musl-ld: drivers/reset/spacemit/k1.o: in function `spacemit_k1_reset_driver_exit':
k1.c:(.exit.text+0x10): undefined reference to `auxiliary_driver_unregister'
> diff --git a/drivers/reset/spacemit/Makefile b/drivers/reset/spacemit/Makefile
> new file mode 100644
> index 0000000000000..3a064e9d5d6b4
> --- /dev/null
> +++ b/drivers/reset/spacemit/Makefile
> @@ -0,0 +1,7 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +obj-$(CONFIG_RESET_SPACEMIT) += reset_spacemit.o
As RESET_SPACEMIT is defined as bool, the reset driver will never be
compiled as a module... so either the RESET_SPACEMIT_K1 should be
limited to bool as well or you could take an approach similar to the
clock driver.
> +reset_spacemit-y := core.o
> +
> +reset_spacemit-$(CONFIG_RESET_SPACEMIT_K1) += k1.o
...
> new file mode 100644
> index 0000000000000..19a34f151b214
> --- /dev/null
> +++ b/drivers/reset/spacemit/k1.c
...
> +MODULE_DEVICE_TABLE(auxiliary, spacemit_k1_reset_ids);
> +
> +#undef K1_AUX_DEV_ID
> +
> +static struct auxiliary_driver spacemit_k1_reset_driver = {
> + .probe = spacemit_k1_reset_probe,
> + .id_table = spacemit_k1_reset_ids,
> +};
> +module_auxiliary_driver(spacemit_k1_reset_driver);
> --
> 2.45.2
If you're willing to make the reset driver buildable as a module, please
add MODULE_{LICENSE,DESCRIPTION} statements and possibly also
MODULE_AUTHOR(), or modpost will complain,
ERROR: modpost: missing MODULE_LICENSE() in drivers/reset/spacemit/reset_spacemit.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/reset/spacemit/reset_spacemit.o
Best regards,
Haylen Chu
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets
2025-05-06 21:06 ` [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets Alex Elder
2025-05-08 5:38 ` Haylen Chu
@ 2025-05-08 9:01 ` Philipp Zabel
2025-05-08 12:05 ` Alex Elder
1 sibling, 1 reply; 27+ messages in thread
From: Philipp Zabel @ 2025-05-08 9:01 UTC (permalink / raw)
To: Alex Elder, robh, krzk+dt, conor+dt, mturquette, sboyd,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
Hi Alex,
On Di, 2025-05-06 at 16:06 -0500, Alex Elder wrote:
> Implement reset support for SpacemiT CCUs. The code is structured to
> handle SpacemiT resets generically, while defining the set of specific
> reset controllers and their resets in an SoC-specific source file.
Are you confident that future SpacemiT CCUs will be sufficiently
similar for this split to make sense? This feels like it could be a
premature abstraction to me.
> A SpacemiT reset controller device is an auxiliary device associated with
> a clock controller (CCU).
>
> This initial patch defines the reset controllers for the MPMU, APBC, and
> MPMU CCUs, which already defined clock controllers.
>
> Signed-off-by: Alex Elder <elder@riscstar.com>
> ---
> drivers/reset/Kconfig | 1 +
> drivers/reset/Makefile | 1 +
> drivers/reset/spacemit/Kconfig | 12 +++
> drivers/reset/spacemit/Makefile | 7 ++
> drivers/reset/spacemit/core.c | 61 +++++++++++
> drivers/reset/spacemit/core.h | 39 +++++++
> drivers/reset/spacemit/k1.c | 177 ++++++++++++++++++++++++++++++++
> 7 files changed, 298 insertions(+)
> create mode 100644 drivers/reset/spacemit/Kconfig
> create mode 100644 drivers/reset/spacemit/Makefile
> create mode 100644 drivers/reset/spacemit/core.c
> create mode 100644 drivers/reset/spacemit/core.h
> create mode 100644 drivers/reset/spacemit/k1.c
>
> diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
> index 99f6f9784e686..b1f1af50ca10b 100644
> --- a/drivers/reset/Kconfig
> +++ b/drivers/reset/Kconfig
> @@ -354,6 +354,7 @@ source "drivers/reset/amlogic/Kconfig"
> source "drivers/reset/starfive/Kconfig"
> source "drivers/reset/sti/Kconfig"
> source "drivers/reset/hisilicon/Kconfig"
> +source "drivers/reset/spacemit/Kconfig"
> source "drivers/reset/tegra/Kconfig"
>
> endif
> diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
> index 31f9904d13f9c..6c19fd875ff13 100644
> --- a/drivers/reset/Makefile
> +++ b/drivers/reset/Makefile
> @@ -2,6 +2,7 @@
> obj-y += core.o
> obj-y += amlogic/
> obj-y += hisilicon/
> +obj-y += spacemit/
> obj-y += starfive/
> obj-y += sti/
> obj-y += tegra/
> diff --git a/drivers/reset/spacemit/Kconfig b/drivers/reset/spacemit/Kconfig
> new file mode 100644
> index 0000000000000..4ff3487a99eff
> --- /dev/null
> +++ b/drivers/reset/spacemit/Kconfig
> @@ -0,0 +1,12 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +config RESET_SPACEMIT
> + bool
> +
> +config RESET_SPACEMIT_K1
> + tristate "SpacemiT K1 reset driver"
> + depends on ARCH_SPACEMIT || COMPILE_TEST
> + select RESET_SPACEMIT
> + default ARCH_SPACEMIT
> + help
> + This enables the reset controller driver for the SpacemiT K1 SoC.
Does the size of the K1 specific parts even warrant this per-SoC
Kconfig option? I suggest to only have a user visible tristate
RESET_SPACEMIT option.
> diff --git a/drivers/reset/spacemit/Makefile b/drivers/reset/spacemit/Makefile
> new file mode 100644
> index 0000000000000..3a064e9d5d6b4
> --- /dev/null
> +++ b/drivers/reset/spacemit/Makefile
> @@ -0,0 +1,7 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +obj-$(CONFIG_RESET_SPACEMIT) += reset_spacemit.o
> +
> +reset_spacemit-y := core.o
> +
> +reset_spacemit-$(CONFIG_RESET_SPACEMIT_K1) += k1.o
> diff --git a/drivers/reset/spacemit/core.c b/drivers/reset/spacemit/core.c
> new file mode 100644
> index 0000000000000..5cd981eb3f097
> --- /dev/null
> +++ b/drivers/reset/spacemit/core.c
> @@ -0,0 +1,61 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +
> +/* SpacemiT reset driver core */
> +
> +#include <linux/container_of.h>
> +#include <linux/regmap.h>
> +#include <linux/reset-controller.h>
> +#include <linux/types.h>
> +
> +#include "core.h"
> +
> +static int spacemit_reset_update(struct reset_controller_dev *rcdev,
> + unsigned long id, bool assert)
> +{
> + struct ccu_reset_controller *controller;
> + const struct ccu_reset_data *data;
> + u32 mask;
> + u32 val;
> +
> + controller = container_of(rcdev, struct ccu_reset_controller, rcdev);
> + data = &controller->data->reset_data[id];
> + mask = data->assert_mask | data->deassert_mask;
> + val = assert ? data->assert_mask : data->deassert_mask;
> +
> + return regmap_update_bits(controller->regmap, data->offset, mask, val);
> +}
> +
> +static int spacemit_reset_assert(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + return spacemit_reset_update(rcdev, id, true);
> +}
> +
> +static int spacemit_reset_deassert(struct reset_controller_dev *rcdev,
> + unsigned long id)
> +{
> + return spacemit_reset_update(rcdev, id, false);
> +}
> +
> +static const struct reset_control_ops spacemit_reset_control_ops = {
> + .assert = spacemit_reset_assert,
> + .deassert = spacemit_reset_deassert,
> +};
> +
> +/**
> + * spacemit_reset_controller_register() - register a reset controller
> + * @dev: Device that's registering the controller
> + * @controller: SpacemiT CCU reset controller structure
> + */
> +int spacemit_reset_controller_register(struct device *dev,
> + struct ccu_reset_controller *controller)
> +{
> + struct reset_controller_dev *rcdev = &controller->rcdev;
> +
> + rcdev->ops = &spacemit_reset_control_ops;
> + rcdev->owner = THIS_MODULE;
> + rcdev->of_node = dev->of_node;
> + rcdev->nr_resets = controller->data->count;
> +
> + return devm_reset_controller_register(dev, &controller->rcdev);
> +}
> diff --git a/drivers/reset/spacemit/core.h b/drivers/reset/spacemit/core.h
> new file mode 100644
> index 0000000000000..a71f835ccb779
> --- /dev/null
> +++ b/drivers/reset/spacemit/core.h
> @@ -0,0 +1,39 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +
> +/* SpacemiT reset driver core */
> +
> +#ifndef __RESET_SPACEMIT_CORE_H__
> +#define __RESET_SPACEMIT_CORE_H__
> +
> +#include <linux/device.h>
This include can be replaced by forward declarations for struct device
and struct regmap.
> +#include <linux/reset-controller.h>
> +#include <linux/types.h>
> +
> +struct ccu_reset_data {
> + u32 offset;
> + u32 assert_mask;
> + u32 deassert_mask;
> +};
> +
> +#define RESET_DATA(_offset, _assert_mask, _deassert_mask) \
> + { \
> + .offset = (_offset), \
> + .assert_mask = (_assert_mask), \
> + .deassert_mask = (_deassert_mask), \
> + }
> +
> +struct ccu_reset_controller_data {
> + const struct ccu_reset_data *reset_data; /* array */
> + size_t count;
> +};
> +
> +struct ccu_reset_controller {
> + struct reset_controller_dev rcdev;
> + const struct ccu_reset_controller_data *data;
> + struct regmap *regmap;
> +};
> +
> +extern int spacemit_reset_controller_register(struct device *dev,
> + struct ccu_reset_controller *controller);
Drop the extern keyword.
> +
> +#endif /* __RESET_SPACEMIT_CORE_H__ */
> diff --git a/drivers/reset/spacemit/k1.c b/drivers/reset/spacemit/k1.c
> new file mode 100644
> index 0000000000000..19a34f151b214
> --- /dev/null
> +++ b/drivers/reset/spacemit/k1.c
> @@ -0,0 +1,177 @@
[...]
> +static int spacemit_k1_reset_probe(struct auxiliary_device *adev,
> + const struct auxiliary_device_id *id)
> +{
> + struct spacemit_ccu_adev *rdev = to_spacemit_ccu_adev(adev);
> + const void *data = (void *)id->driver_data;
> + struct ccu_reset_controller *controller;
> + struct device *dev = &adev->dev;
> +
> + controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);
> + if (!controller)
> + return -ENODEV;
-ENOMEM, this is a failed memory allocation.
regards
Philipp
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 5/6] reset: spacemit: define three more CCUs
2025-05-06 21:06 ` [PATCH v6 5/6] reset: spacemit: define three more CCUs Alex Elder
@ 2025-05-08 9:11 ` Philipp Zabel
2025-05-08 12:29 ` Alex Elder
0 siblings, 1 reply; 27+ messages in thread
From: Philipp Zabel @ 2025-05-08 9:11 UTC (permalink / raw)
To: Alex Elder, robh, krzk+dt, conor+dt, mturquette, sboyd,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
On Di, 2025-05-06 at 16:06 -0500, Alex Elder wrote:
> Three more CCUs on the SpacemiT K1 SoC implement only resets, not clocks.
> Define these resets so they can be used.
>
> Signed-off-by: Alex Elder <elder@riscstar.com>
> ---
> drivers/clk/spacemit/ccu-k1.c | 24 ++++++++++++++++
> drivers/reset/spacemit/k1.c | 54 +++++++++++++++++++++++++++++++++++
> include/soc/spacemit/ccu_k1.h | 30 +++++++++++++++++++
> 3 files changed, 108 insertions(+)
>
> diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c
> index 6b1845e899e5f..bddc83aff23cd 100644
> --- a/drivers/clk/spacemit/ccu-k1.c
> +++ b/drivers/clk/spacemit/ccu-k1.c
> @@ -939,6 +939,18 @@ static const struct spacemit_ccu_data k1_ccu_apmu_data = {
> .num = ARRAY_SIZE(k1_ccu_apmu_hws),
> };
>
> +static const struct spacemit_ccu_data k1_ccu_rcpu_data = {
The /* No clocks in the RCPU CCU */ comment belongs here, instead of in
the reset driver.
I wonder though, if these units have no clocks, why are they called
CCUs? It doesn't make much sense to me to add their compatibles to the
ccu-k1 driver only to load the reset aux driver. Why not just add a
platform driver next to the aux driver in reset-spacemit.ko for these
three?
> + .reset_name = "rcpu-reset",
> +};
> +
> +static const struct spacemit_ccu_data k1_ccu_rcpu2_data = {
> + .reset_name = "rcpu2-reset",
> +};
> +
> +static const struct spacemit_ccu_data k1_ccu_apbc2_data = {
> + .reset_name = "apbc2-reset",
> +};
> +
> static int spacemit_ccu_register(struct device *dev,
> struct regmap *regmap,
> struct regmap *lock_regmap,
> @@ -1106,6 +1118,18 @@ static const struct of_device_id of_k1_ccu_match[] = {
> .compatible = "spacemit,k1-syscon-apmu",
> .data = &k1_ccu_apmu_data,
> },
> + {
> + .compatible = "spacemit,k1-syscon-rcpu",
> + .data = &k1_ccu_rcpu_data,
> + },
> + {
> + .compatible = "spacemit,k1-syscon-rcpu2",
> + .data = &k1_ccu_rcpu2_data,
> + },
> + {
> + .compatible = "spacemit,k1-syscon-apbc2",
> + .data = &k1_ccu_apbc2_data,
> + },
> { }
> };
> MODULE_DEVICE_TABLE(of, of_k1_ccu_match);
> diff --git a/drivers/reset/spacemit/k1.c b/drivers/reset/spacemit/k1.c
> index 19a34f151b214..27434a1928261 100644
> --- a/drivers/reset/spacemit/k1.c
> +++ b/drivers/reset/spacemit/k1.c
> @@ -137,6 +137,57 @@ static const struct ccu_reset_controller_data k1_apmu_reset_data = {
> .count = ARRAY_SIZE(apmu_resets),
> };
>
> +static const struct ccu_reset_data rcpu_resets[] = {
> + [RESET_RCPU_SSP0] = RESET_DATA(RCPU_SSP0_CLK_RST, 0, BIT(0)),
> + [RESET_RCPU_I2C0] = RESET_DATA(RCPU_I2C0_CLK_RST, 0, BIT(0)),
> + [RESET_RCPU_UART1] = RESET_DATA(RCPU_UART1_CLK_RST, 0, BIT(0)),
> + [RESET_RCPU_IR] = RESET_DATA(RCPU_CAN_CLK_RST, 0, BIT(0)),
> + [RESET_RCPU_CAN] = RESET_DATA(RCPU_IR_CLK_RST, 0, BIT(0)),
> + [RESET_RCPU_UART0] = RESET_DATA(RCPU_UART0_CLK_RST, 0, BIT(0)),
> + [RESET_RCPU_HDMI_AUDIO] = RESET_DATA(AUDIO_HDMI_CLK_CTRL, 0, BIT(0)),
> +};
> +
> +static const struct ccu_reset_controller_data k1_rcpu_reset_data = {
> + /* No clocks in the RCPU CCU */
This information is not useful in the reset driver.
regards
Philipp
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 2/6] soc: spacemit: create a header for clock/reset registers
2025-05-08 4:16 ` Haylen Chu
@ 2025-05-08 11:40 ` Alex Elder
0 siblings, 0 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-08 11:40 UTC (permalink / raw)
To: Haylen Chu, robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: inochiama, guodong, devicetree, linux-clk, spacemit, linux-riscv,
linux-kernel
On 5/7/25 11:16 PM, Haylen Chu wrote:
> On Tue, May 06, 2025 at 04:06:33PM -0500, Alex Elder wrote:
>> Move the definitions of register offsets and fields used by the SpacemiT
>> K1 SoC CCUs into a separate header file, so that they can be shared by
>> the reset driver that will be found under drivers/reset.
>>
>> Signed-off-by: Alex Elder <elder@riscstar.com>
>> ---
>> drivers/clk/spacemit/ccu-k1.c | 111 +--------------------------------
>> include/soc/spacemit/ccu_k1.h | 113 ++++++++++++++++++++++++++++++++++
>
> CCU is abbreviated from "clock controller unit" thus the filename seems
> a little strange to me. Will k1-syscon.h be a better name? We could put
> all syscon registers together when introducing the power-domain driver
> later, which could provide an overall view of register layout.
I'm OK with making that change.
To me the "CCU" was the that IP block that offered clock and
reset controls (and maybe a few other things?). But renaming
it, given we're separating the functionality more clearly,
is pretty reasonable.
Thanks.
-Alex
>> 2 files changed, 114 insertions(+), 110 deletions(-)
>> create mode 100644 include/soc/spacemit/ccu_k1.h
>
> Best regards,
> Haylen Chu
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets
2025-05-08 5:38 ` Haylen Chu
@ 2025-05-08 11:55 ` Alex Elder
2025-05-08 12:47 ` Haylen Chu
0 siblings, 1 reply; 27+ messages in thread
From: Alex Elder @ 2025-05-08 11:55 UTC (permalink / raw)
To: Haylen Chu, robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: inochiama, guodong, devicetree, linux-clk, spacemit, linux-riscv,
linux-kernel
On 5/8/25 12:38 AM, Haylen Chu wrote:
> On Tue, May 06, 2025 at 04:06:35PM -0500, Alex Elder wrote:
>> Implement reset support for SpacemiT CCUs. The code is structured to
>> handle SpacemiT resets generically, while defining the set of specific
>> reset controllers and their resets in an SoC-specific source file. A
>> SpacemiT reset controller device is an auxiliary device associated with
>> a clock controller (CCU).
>>
>> This initial patch defines the reset controllers for the MPMU, APBC, and
>> MPMU CCUs, which already defined clock controllers.
>>
>> Signed-off-by: Alex Elder <elder@riscstar.com>
>> ---
>> drivers/reset/Kconfig | 1 +
>> drivers/reset/Makefile | 1 +
>> drivers/reset/spacemit/Kconfig | 12 +++
>> drivers/reset/spacemit/Makefile | 7 ++
>> drivers/reset/spacemit/core.c | 61 +++++++++++
>> drivers/reset/spacemit/core.h | 39 +++++++
>> drivers/reset/spacemit/k1.c | 177 ++++++++++++++++++++++++++++++++
>> 7 files changed, 298 insertions(+)
>> create mode 100644 drivers/reset/spacemit/Kconfig
>> create mode 100644 drivers/reset/spacemit/Makefile
>> create mode 100644 drivers/reset/spacemit/core.c
>> create mode 100644 drivers/reset/spacemit/core.h
>> create mode 100644 drivers/reset/spacemit/k1.c
>>
>
> ...
>
>> diff --git a/drivers/reset/spacemit/Kconfig b/drivers/reset/spacemit/Kconfig
>> new file mode 100644
>> index 0000000000000..4ff3487a99eff
>> --- /dev/null
>> +++ b/drivers/reset/spacemit/Kconfig
>> @@ -0,0 +1,12 @@
>> +# SPDX-License-Identifier: GPL-2.0-only
>> +
>> +config RESET_SPACEMIT
>> + bool
>> +
>> +config RESET_SPACEMIT_K1
>> + tristate "SpacemiT K1 reset driver"
>> + depends on ARCH_SPACEMIT || COMPILE_TEST
>> + select RESET_SPACEMIT
>> + default ARCH_SPACEMIT
>> + help
>> + This enables the reset controller driver for the SpacemiT K1 SoC.
>
> With auxiliary bus introduced, Kconfig entries for both the reset and
> clock should select AUXILIARY_BUS, or building defconfig will fail with
> undefined references,
Wow, I really should have made this v1 of a new series. You point
out several problems that came out of this using the auxiliary
device framework, which I should have tested more thoroughly.
Yes I will update this to select that, and will test it before
my next version.
>
> riscv64-unknown-linux-musl-ld: drivers/clk/spacemit/ccu-k1.o: in function `k1_ccu_probe':
> ccu-k1.c:(.text+0x19c): undefined reference to `auxiliary_device_init'
> riscv64-unknown-linux-musl-ld: ccu-k1.c:(.text+0x226): undefined reference to `__auxiliary_device_add'
> riscv64-unknown-linux-musl-ld: drivers/reset/spacemit/k1.o: in function `spacemit_k1_reset_driver_init':
> k1.c:(.init.text+0x1a): undefined reference to `__auxiliary_driver_register'
> riscv64-unknown-linux-musl-ld: drivers/reset/spacemit/k1.o: in function `spacemit_k1_reset_driver_exit':
> k1.c:(.exit.text+0x10): undefined reference to `auxiliary_driver_unregister'
>
>> diff --git a/drivers/reset/spacemit/Makefile b/drivers/reset/spacemit/Makefile
>> new file mode 100644
>> index 0000000000000..3a064e9d5d6b4
>> --- /dev/null
>> +++ b/drivers/reset/spacemit/Makefile
>> @@ -0,0 +1,7 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +
>> +obj-$(CONFIG_RESET_SPACEMIT) += reset_spacemit.o
>
> As RESET_SPACEMIT is defined as bool, the reset driver will never be
> compiled as a module... so either the RESET_SPACEMIT_K1 should be
> limited to bool as well or you could take an approach similar to the
> clock driver.
I'm not sure I understand this statement, at least in this
context. This pattern is used to define a single module
"reset_spacemit.o" out of several source files.
But I think you're saying that RESET_SPACEMIT and
RESET_SPACEMIT_K1 should both be bool, or both be
tristate. I will resolve that question before I
send the next version.
>> +reset_spacemit-y := core.o
>> +
>> +reset_spacemit-$(CONFIG_RESET_SPACEMIT_K1) += k1.o
>
> ...
>
>> new file mode 100644
>> index 0000000000000..19a34f151b214
>> --- /dev/null
>> +++ b/drivers/reset/spacemit/k1.c
>
> ...
>
>> +MODULE_DEVICE_TABLE(auxiliary, spacemit_k1_reset_ids);
>> +
>> +#undef K1_AUX_DEV_ID
>> +
>> +static struct auxiliary_driver spacemit_k1_reset_driver = {
>> + .probe = spacemit_k1_reset_probe,
>> + .id_table = spacemit_k1_reset_ids,
>> +};
>> +module_auxiliary_driver(spacemit_k1_reset_driver);
>> --
>> 2.45.2
>
> If you're willing to make the reset driver buildable as a module, please
> add MODULE_{LICENSE,DESCRIPTION} statements and possibly also
> MODULE_AUTHOR(), or modpost will complain,
OK, thank you.
-Alex
>
> ERROR: modpost: missing MODULE_LICENSE() in drivers/reset/spacemit/reset_spacemit.o
> WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/reset/spacemit/reset_spacemit.o
>
> Best regards,
> Haylen Chu
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets
2025-05-07 22:35 ` Yixun Lan
2025-05-08 2:19 ` Alex Elder
@ 2025-05-08 12:02 ` Krzysztof Kozlowski
2025-05-08 12:17 ` Alex Elder
1 sibling, 1 reply; 27+ messages in thread
From: Krzysztof Kozlowski @ 2025-05-08 12:02 UTC (permalink / raw)
To: Yixun Lan, Alex Elder
Cc: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, heylenay, inochiama, guodong,
devicetree, linux-clk, spacemit, linux-riscv, linux-kernel,
Krzysztof Kozlowski
On 08/05/2025 00:35, Yixun Lan wrote:
>> + - if:
>> + properties:
>> + compatible:
>> + contains:
>> + enum:
>> + - spacemit,k1-syscon-apbc
>> + - spacemit,k1-syscon-apmu
>> + - spacemit,k1-syscon-mpmu
>> + then:
>> + required:
>> + - clocks
>> + - clock-names
>> + - "#clock-cells"
>>
>> additionalProperties: false
>>
>> diff --git a/include/dt-bindings/clock/spacemit,k1-syscon.h b/include/dt-bindings/clock/spacemit,k1-syscon.h
>> index 35968ae982466..f5965dda3b905 100644
>> --- a/include/dt-bindings/clock/spacemit,k1-syscon.h
>> +++ b/include/dt-bindings/clock/spacemit,k1-syscon.h
> would it be better to move all reset definition to its dedicated dir?
> which like: include/dt-bindings/reset/spacemit,k1-syscon.h?
Please kindly trim the replies from unnecessary context. It makes it
much easier to find new content.
I don't get why such comments are appearing so late - at v6. There was
nothing from you about this in v1, v2 and v3, which finally got reviewed.
I just feel people wait for maintainers to review and only after they
will add their 2 cents of nitpicks or even some more important things
potentially invalidating the review. Lesson for me: do not review
people's work before it reaches v10, right?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets
2025-05-08 9:01 ` Philipp Zabel
@ 2025-05-08 12:05 ` Alex Elder
0 siblings, 0 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-08 12:05 UTC (permalink / raw)
To: Philipp Zabel, robh, krzk+dt, conor+dt, mturquette, sboyd,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
On 5/8/25 4:01 AM, Philipp Zabel wrote:
> Hi Alex,
>
> On Di, 2025-05-06 at 16:06 -0500, Alex Elder wrote:
>> Implement reset support for SpacemiT CCUs. The code is structured to
>> handle SpacemiT resets generically, while defining the set of specific
>> reset controllers and their resets in an SoC-specific source file.
>
> Are you confident that future SpacemiT CCUs will be sufficiently
> similar for this split to make sense? This feels like it could be a
> premature abstraction to me.
Honestly, no. I decided to do it this way to mirror how
the clock driver is structured, but I agree with you. The
code is pretty simple currently, and it could all go in a
single file. Splitting it later would be easy if needed.
I'll do that for the next version.
>> A SpacemiT reset controller device is an auxiliary device associated with
>> a clock controller (CCU).
>>
>> This initial patch defines the reset controllers for the MPMU, APBC, and
>> MPMU CCUs, which already defined clock controllers.
>>
>> Signed-off-by: Alex Elder <elder@riscstar.com>
>> ---
>> drivers/reset/Kconfig | 1 +
>> drivers/reset/Makefile | 1 +
>> drivers/reset/spacemit/Kconfig | 12 +++
>> drivers/reset/spacemit/Makefile | 7 ++
>> drivers/reset/spacemit/core.c | 61 +++++++++++
>> drivers/reset/spacemit/core.h | 39 +++++++
>> drivers/reset/spacemit/k1.c | 177 ++++++++++++++++++++++++++++++++
>> 7 files changed, 298 insertions(+)
>> create mode 100644 drivers/reset/spacemit/Kconfig
>> create mode 100644 drivers/reset/spacemit/Makefile
>> create mode 100644 drivers/reset/spacemit/core.c
>> create mode 100644 drivers/reset/spacemit/core.h
>> create mode 100644 drivers/reset/spacemit/k1.c
>>
>> diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig
>> index 99f6f9784e686..b1f1af50ca10b 100644
>> --- a/drivers/reset/Kconfig
>> +++ b/drivers/reset/Kconfig
>> @@ -354,6 +354,7 @@ source "drivers/reset/amlogic/Kconfig"
>> source "drivers/reset/starfive/Kconfig"
>> source "drivers/reset/sti/Kconfig"
>> source "drivers/reset/hisilicon/Kconfig"
>> +source "drivers/reset/spacemit/Kconfig"
>> source "drivers/reset/tegra/Kconfig"
>>
>> endif
>> diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile
>> index 31f9904d13f9c..6c19fd875ff13 100644
>> --- a/drivers/reset/Makefile
>> +++ b/drivers/reset/Makefile
>> @@ -2,6 +2,7 @@
>> obj-y += core.o
>> obj-y += amlogic/
>> obj-y += hisilicon/
>> +obj-y += spacemit/
>> obj-y += starfive/
>> obj-y += sti/
>> obj-y += tegra/
>> diff --git a/drivers/reset/spacemit/Kconfig b/drivers/reset/spacemit/Kconfig
>> new file mode 100644
>> index 0000000000000..4ff3487a99eff
>> --- /dev/null
>> +++ b/drivers/reset/spacemit/Kconfig
>> @@ -0,0 +1,12 @@
>> +# SPDX-License-Identifier: GPL-2.0-only
>> +
>> +config RESET_SPACEMIT
>> + bool
>> +
>> +config RESET_SPACEMIT_K1
>> + tristate "SpacemiT K1 reset driver"
>> + depends on ARCH_SPACEMIT || COMPILE_TEST
>> + select RESET_SPACEMIT
>> + default ARCH_SPACEMIT
>> + help
>> + This enables the reset controller driver for the SpacemiT K1 SoC.
>
> Does the size of the K1 specific parts even warrant this per-SoC
> Kconfig option? I suggest to only have a user visible tristate
> RESET_SPACEMIT option.
I don't know if the size warrants it, it was more about structuring
config options to match the separation of the reset definitions.
Along with consolidating into a single source file, I'll just use
a single config option.
>
>> diff --git a/drivers/reset/spacemit/Makefile b/drivers/reset/spacemit/Makefile
>> new file mode 100644
>> index 0000000000000..3a064e9d5d6b4
>> --- /dev/null
>> +++ b/drivers/reset/spacemit/Makefile
>> @@ -0,0 +1,7 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +
>> +obj-$(CONFIG_RESET_SPACEMIT) += reset_spacemit.o
>> +
>> +reset_spacemit-y := core.o
>> +
>> +reset_spacemit-$(CONFIG_RESET_SPACEMIT_K1) += k1.o
>> diff --git a/drivers/reset/spacemit/core.c b/drivers/reset/spacemit/core.c
>> new file mode 100644
>> index 0000000000000..5cd981eb3f097
>> --- /dev/null
>> +++ b/drivers/reset/spacemit/core.c
>> @@ -0,0 +1,61 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +
>> +/* SpacemiT reset driver core */
>> +
>> +#include <linux/container_of.h>
>> +#include <linux/regmap.h>
>> +#include <linux/reset-controller.h>
>> +#include <linux/types.h>
>> +
>> +#include "core.h"
>> +
>> +static int spacemit_reset_update(struct reset_controller_dev *rcdev,
>> + unsigned long id, bool assert)
>> +{
>> + struct ccu_reset_controller *controller;
>> + const struct ccu_reset_data *data;
>> + u32 mask;
>> + u32 val;
>> +
>> + controller = container_of(rcdev, struct ccu_reset_controller, rcdev);
>> + data = &controller->data->reset_data[id];
>> + mask = data->assert_mask | data->deassert_mask;
>> + val = assert ? data->assert_mask : data->deassert_mask;
>> +
>> + return regmap_update_bits(controller->regmap, data->offset, mask, val);
>> +}
>> +
>> +static int spacemit_reset_assert(struct reset_controller_dev *rcdev,
>> + unsigned long id)
>> +{
>> + return spacemit_reset_update(rcdev, id, true);
>> +}
>> +
>> +static int spacemit_reset_deassert(struct reset_controller_dev *rcdev,
>> + unsigned long id)
>> +{
>> + return spacemit_reset_update(rcdev, id, false);
>> +}
>> +
>> +static const struct reset_control_ops spacemit_reset_control_ops = {
>> + .assert = spacemit_reset_assert,
>> + .deassert = spacemit_reset_deassert,
>> +};
>> +
>> +/**
>> + * spacemit_reset_controller_register() - register a reset controller
>> + * @dev: Device that's registering the controller
>> + * @controller: SpacemiT CCU reset controller structure
>> + */
>> +int spacemit_reset_controller_register(struct device *dev,
>> + struct ccu_reset_controller *controller)
>> +{
>> + struct reset_controller_dev *rcdev = &controller->rcdev;
>> +
>> + rcdev->ops = &spacemit_reset_control_ops;
>> + rcdev->owner = THIS_MODULE;
>> + rcdev->of_node = dev->of_node;
>> + rcdev->nr_resets = controller->data->count;
>> +
>> + return devm_reset_controller_register(dev, &controller->rcdev);
>> +}
>> diff --git a/drivers/reset/spacemit/core.h b/drivers/reset/spacemit/core.h
>> new file mode 100644
>> index 0000000000000..a71f835ccb779
>> --- /dev/null
>> +++ b/drivers/reset/spacemit/core.h
>> @@ -0,0 +1,39 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +
>> +/* SpacemiT reset driver core */
>> +
>> +#ifndef __RESET_SPACEMIT_CORE_H__
>> +#define __RESET_SPACEMIT_CORE_H__
>> +
>> +#include <linux/device.h>
>
> This include can be replaced by forward declarations for struct device
> and struct regmap.
You're right, but I think this will be moot with a single source file.
Anyway, I'll fix this.
>> +#include <linux/reset-controller.h>
>> +#include <linux/types.h>
>> +
>> +struct ccu_reset_data {
>> + u32 offset;
>> + u32 assert_mask;
>> + u32 deassert_mask;
>> +};
>> +
>> +#define RESET_DATA(_offset, _assert_mask, _deassert_mask) \
>> + { \
>> + .offset = (_offset), \
>> + .assert_mask = (_assert_mask), \
>> + .deassert_mask = (_deassert_mask), \
>> + }
>> +
>> +struct ccu_reset_controller_data {
>> + const struct ccu_reset_data *reset_data; /* array */
>> + size_t count;
>> +};
>> +
>> +struct ccu_reset_controller {
>> + struct reset_controller_dev rcdev;
>> + const struct ccu_reset_controller_data *data;
>> + struct regmap *regmap;
>> +};
>> +
>> +extern int spacemit_reset_controller_register(struct device *dev,
>> + struct ccu_reset_controller *controller);
>
> Drop the extern keyword.
OK, but here too I think there will be no external declaration in
the next version.
>> +
>> +#endif /* __RESET_SPACEMIT_CORE_H__ */
>> diff --git a/drivers/reset/spacemit/k1.c b/drivers/reset/spacemit/k1.c
>> new file mode 100644
>> index 0000000000000..19a34f151b214
>> --- /dev/null
>> +++ b/drivers/reset/spacemit/k1.c
>> @@ -0,0 +1,177 @@
> [...]
>> +static int spacemit_k1_reset_probe(struct auxiliary_device *adev,
>> + const struct auxiliary_device_id *id)
>> +{
>> + struct spacemit_ccu_adev *rdev = to_spacemit_ccu_adev(adev);
>> + const void *data = (void *)id->driver_data;
>> + struct ccu_reset_controller *controller;
>> + struct device *dev = &adev->dev;
>> +
>> + controller = devm_kzalloc(dev, sizeof(*controller), GFP_KERNEL);
>> + if (!controller)
>> + return -ENODEV;
>
> -ENOMEM, this is a failed memory allocation.
Yes, you're correct, I'll fix this. Thank you very much
for your review.
-Alex
> regards
> Philipp
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets
2025-05-08 12:02 ` Krzysztof Kozlowski
@ 2025-05-08 12:17 ` Alex Elder
2025-05-08 12:36 ` Krzysztof Kozlowski
2025-05-08 12:40 ` Yixun Lan
0 siblings, 2 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-08 12:17 UTC (permalink / raw)
To: Krzysztof Kozlowski, Yixun Lan
Cc: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, heylenay, inochiama, guodong,
devicetree, linux-clk, spacemit, linux-riscv, linux-kernel,
Krzysztof Kozlowski
On 5/8/25 7:02 AM, Krzysztof Kozlowski wrote:
> On 08/05/2025 00:35, Yixun Lan wrote:
>>> + - if:
>>> + properties:
>>> + compatible:
>>> + contains:
>>> + enum:
>>> + - spacemit,k1-syscon-apbc
>>> + - spacemit,k1-syscon-apmu
>>> + - spacemit,k1-syscon-mpmu
>>> + then:
>>> + required:
>>> + - clocks
>>> + - clock-names
>>> + - "#clock-cells"
>>>
>>> additionalProperties: false
>>>
>>> diff --git a/include/dt-bindings/clock/spacemit,k1-syscon.h b/include/dt-bindings/clock/spacemit,k1-syscon.h
>>> index 35968ae982466..f5965dda3b905 100644
>>> --- a/include/dt-bindings/clock/spacemit,k1-syscon.h
>>> +++ b/include/dt-bindings/clock/spacemit,k1-syscon.h
>> would it be better to move all reset definition to its dedicated dir?
>> which like: include/dt-bindings/reset/spacemit,k1-syscon.h?
>
> Please kindly trim the replies from unnecessary context. It makes it
> much easier to find new content.
>
>
> I don't get why such comments are appearing so late - at v6. There was
> nothing from you about this in v1, v2 and v3, which finally got reviewed.
Stephen Boyd said "please rework this to use the auxiliary driver
framework" on version 5 of the series; it was otherwise "done" at
that point.
Doing this meant there was a much clearer separation of the clock
definitions from the reset definitions. And Yixun's suggestion
came from viewing things in that context.
Given the rework, I considered sending this as v1 of a new series
but did not.
> I just feel people wait for maintainers to review and only after they
> will add their 2 cents of nitpicks or even some more important things
> potentially invalidating the review. Lesson for me: do not review
> people's work before it reaches v10, right?
That's not what happened here--or at least, it's not as simple
as that. Your quick review was very much appreciated.
Yixun: Krzysztof was satisfied with things the way they're
defined here. Do you feel strongly I should make your suggested
change? Or are you OK with me just keeping things defined this
way for the next version? I'd like this question resolved before
I send the next version.
Thank you.
-Alex
> Best regards,
> Krzysztof
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 5/6] reset: spacemit: define three more CCUs
2025-05-08 9:11 ` Philipp Zabel
@ 2025-05-08 12:29 ` Alex Elder
0 siblings, 0 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-08 12:29 UTC (permalink / raw)
To: Philipp Zabel, robh, krzk+dt, conor+dt, mturquette, sboyd,
paul.walmsley, palmer, aou, alex, dlan
Cc: heylenay, inochiama, guodong, devicetree, linux-clk, spacemit,
linux-riscv, linux-kernel
On 5/8/25 4:11 AM, Philipp Zabel wrote:
> On Di, 2025-05-06 at 16:06 -0500, Alex Elder wrote:
>> Three more CCUs on the SpacemiT K1 SoC implement only resets, not clocks.
>> Define these resets so they can be used.
>>
>> Signed-off-by: Alex Elder <elder@riscstar.com>
>> ---
>> drivers/clk/spacemit/ccu-k1.c | 24 ++++++++++++++++
>> drivers/reset/spacemit/k1.c | 54 +++++++++++++++++++++++++++++++++++
>> include/soc/spacemit/ccu_k1.h | 30 +++++++++++++++++++
>> 3 files changed, 108 insertions(+)
>>
>> diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c
>> index 6b1845e899e5f..bddc83aff23cd 100644
>> --- a/drivers/clk/spacemit/ccu-k1.c
>> +++ b/drivers/clk/spacemit/ccu-k1.c
>> @@ -939,6 +939,18 @@ static const struct spacemit_ccu_data k1_ccu_apmu_data = {
>> .num = ARRAY_SIZE(k1_ccu_apmu_hws),
>> };
>>
>> +static const struct spacemit_ccu_data k1_ccu_rcpu_data = {
>
> The /* No clocks in the RCPU CCU */ comment belongs here, instead of in
> the reset driver.
>
> I wonder though, if these units have no clocks, why are they called
> CCUs? It doesn't make much sense to me to add their compatibles to the
> ccu-k1 driver only to load the reset aux driver. Why not just add a
> platform driver next to the aux driver in reset-spacemit.ko for these
> three?
In fact, the particular registers involved *do* have fields
to control some clocks, but there is currently no use for
them, so support for them isn't implemented. The reset
controls in those registers are needed now, however.
I actually first implemented this as a small, separate reset
driver, only to learn late in the process that these other
clocks might be needed someday.
>
>> + .reset_name = "rcpu-reset",
>> +};
>> +
>> +static const struct spacemit_ccu_data k1_ccu_rcpu2_data = {
>> + .reset_name = "rcpu2-reset",
>> +};
>> +
>> +static const struct spacemit_ccu_data k1_ccu_apbc2_data = {
>> + .reset_name = "apbc2-reset",
>> +};
>> +
>> static int spacemit_ccu_register(struct device *dev,
>> struct regmap *regmap,
>> struct regmap *lock_regmap,
>> @@ -1106,6 +1118,18 @@ static const struct of_device_id of_k1_ccu_match[] = {
>> .compatible = "spacemit,k1-syscon-apmu",
>> .data = &k1_ccu_apmu_data,
>> },
>> + {
>> + .compatible = "spacemit,k1-syscon-rcpu",
>> + .data = &k1_ccu_rcpu_data,
>> + },
>> + {
>> + .compatible = "spacemit,k1-syscon-rcpu2",
>> + .data = &k1_ccu_rcpu2_data,
>> + },
>> + {
>> + .compatible = "spacemit,k1-syscon-apbc2",
>> + .data = &k1_ccu_apbc2_data,
>> + },
>> { }
>> };
>> MODULE_DEVICE_TABLE(of, of_k1_ccu_match);
>> diff --git a/drivers/reset/spacemit/k1.c b/drivers/reset/spacemit/k1.c
>> index 19a34f151b214..27434a1928261 100644
>> --- a/drivers/reset/spacemit/k1.c
>> +++ b/drivers/reset/spacemit/k1.c
>> @@ -137,6 +137,57 @@ static const struct ccu_reset_controller_data k1_apmu_reset_data = {
>> .count = ARRAY_SIZE(apmu_resets),
>> };
>>
>> +static const struct ccu_reset_data rcpu_resets[] = {
>> + [RESET_RCPU_SSP0] = RESET_DATA(RCPU_SSP0_CLK_RST, 0, BIT(0)),
>> + [RESET_RCPU_I2C0] = RESET_DATA(RCPU_I2C0_CLK_RST, 0, BIT(0)),
>> + [RESET_RCPU_UART1] = RESET_DATA(RCPU_UART1_CLK_RST, 0, BIT(0)),
>> + [RESET_RCPU_IR] = RESET_DATA(RCPU_CAN_CLK_RST, 0, BIT(0)),
>> + [RESET_RCPU_CAN] = RESET_DATA(RCPU_IR_CLK_RST, 0, BIT(0)),
>> + [RESET_RCPU_UART0] = RESET_DATA(RCPU_UART0_CLK_RST, 0, BIT(0)),
>> + [RESET_RCPU_HDMI_AUDIO] = RESET_DATA(AUDIO_HDMI_CLK_CTRL, 0, BIT(0)),
>> +};
>> +
>> +static const struct ccu_reset_controller_data k1_rcpu_reset_data = {
>> + /* No clocks in the RCPU CCU */
>
> This information is not useful in the reset driver.
Yes, I think this was just copy-pasted from the previous code.
This won't be there in the next version.
-Alex
> regards
> Philipp
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets
2025-05-08 12:17 ` Alex Elder
@ 2025-05-08 12:36 ` Krzysztof Kozlowski
2025-05-08 12:42 ` Alex Elder
2025-05-08 12:40 ` Yixun Lan
1 sibling, 1 reply; 27+ messages in thread
From: Krzysztof Kozlowski @ 2025-05-08 12:36 UTC (permalink / raw)
To: Alex Elder, Yixun Lan
Cc: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, heylenay, inochiama, guodong,
devicetree, linux-clk, spacemit, linux-riscv, linux-kernel,
Krzysztof Kozlowski
On 08/05/2025 14:17, Alex Elder wrote:
> On 5/8/25 7:02 AM, Krzysztof Kozlowski wrote:
>> On 08/05/2025 00:35, Yixun Lan wrote:
>>>> + - if:
>>>> + properties:
>>>> + compatible:
>>>> + contains:
>>>> + enum:
>>>> + - spacemit,k1-syscon-apbc
>>>> + - spacemit,k1-syscon-apmu
>>>> + - spacemit,k1-syscon-mpmu
>>>> + then:
>>>> + required:
>>>> + - clocks
>>>> + - clock-names
>>>> + - "#clock-cells"
>>>>
>>>> additionalProperties: false
>>>>
>>>> diff --git a/include/dt-bindings/clock/spacemit,k1-syscon.h b/include/dt-bindings/clock/spacemit,k1-syscon.h
>>>> index 35968ae982466..f5965dda3b905 100644
>>>> --- a/include/dt-bindings/clock/spacemit,k1-syscon.h
>>>> +++ b/include/dt-bindings/clock/spacemit,k1-syscon.h
>>> would it be better to move all reset definition to its dedicated dir?
>>> which like: include/dt-bindings/reset/spacemit,k1-syscon.h?
>>
>> Please kindly trim the replies from unnecessary context. It makes it
>> much easier to find new content.
>>
>>
>> I don't get why such comments are appearing so late - at v6. There was
>> nothing from you about this in v1, v2 and v3, which finally got reviewed.
>
> Stephen Boyd said "please rework this to use the auxiliary driver
> framework" on version 5 of the series; it was otherwise "done" at
> that point.
Stephen is a subsystem maintainer so his comments are fine or acceptable
to be late.
>
> Doing this meant there was a much clearer separation of the clock
> definitions from the reset definitions. And Yixun's suggestion
> came from viewing things in that context.
Weren't they applicable to v1 as well? How bindings could change with
change to auxiliary bus/driver?
>
> Given the rework, I considered sending this as v1 of a new series
> but did not.
Sorry but no. Bindings headers at v1 are exactly the same or almost the
same as now:
https://lore.kernel.org/lkml/20250321151831.623575-2-elder@riscstar.com/
so this idea could have been given at v1, v2, v3, v4, v5 (that would be
late).... but at some point this is just unnecessary late nitpicking.
So what then? Imagine that you prepare v7 and some other person gives
you different comment about bindings or bindings headers. Then you
prepare v8. And then someone comes with one more, different comment,
because that person did not bother to review between v1-v8 (that
imaginary future v8), so you need to prepare v9.
I don't think this process is correct.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets
2025-05-08 12:17 ` Alex Elder
2025-05-08 12:36 ` Krzysztof Kozlowski
@ 2025-05-08 12:40 ` Yixun Lan
1 sibling, 0 replies; 27+ messages in thread
From: Yixun Lan @ 2025-05-08 12:40 UTC (permalink / raw)
To: Alex Elder
Cc: Krzysztof Kozlowski, robh, krzk+dt, conor+dt, mturquette, sboyd,
p.zabel, paul.walmsley, palmer, aou, alex, heylenay, inochiama,
guodong, devicetree, linux-clk, spacemit, linux-riscv,
linux-kernel, Krzysztof Kozlowski
Hi Alex,
On 07:17 Thu 08 May , Alex Elder wrote:
> On 5/8/25 7:02 AM, Krzysztof Kozlowski wrote:
> > On 08/05/2025 00:35, Yixun Lan wrote:
> >>> + - if:
> >>> + properties:
> >>> + compatible:
> >>> + contains:
> >>> + enum:
> >>> + - spacemit,k1-syscon-apbc
> >>> + - spacemit,k1-syscon-apmu
> >>> + - spacemit,k1-syscon-mpmu
> >>> + then:
> >>> + required:
> >>> + - clocks
> >>> + - clock-names
> >>> + - "#clock-cells"
> >>>
> >>> additionalProperties: false
> >>>
> >>> diff --git a/include/dt-bindings/clock/spacemit,k1-syscon.h b/include/dt-bindings/clock/spacemit,k1-syscon.h
> >>> index 35968ae982466..f5965dda3b905 100644
> >>> --- a/include/dt-bindings/clock/spacemit,k1-syscon.h
> >>> +++ b/include/dt-bindings/clock/spacemit,k1-syscon.h
> >> would it be better to move all reset definition to its dedicated dir?
> >> which like: include/dt-bindings/reset/spacemit,k1-syscon.h?
> >
> > Please kindly trim the replies from unnecessary context. It makes it
> > much easier to find new content.
> >
> >
> > I don't get why such comments are appearing so late - at v6. There was
> > nothing from you about this in v1, v2 and v3, which finally got reviewed.
>
> Stephen Boyd said "please rework this to use the auxiliary driver
> framework" on version 5 of the series; it was otherwise "done" at
> that point.
>
> Doing this meant there was a much clearer separation of the clock
> definitions from the reset definitions. And Yixun's suggestion
> came from viewing things in that context.
>
> Given the rework, I considered sending this as v1 of a new series
> but did not.
>
> > I just feel people wait for maintainers to review and only after they
> > will add their 2 cents of nitpicks or even some more important things
> > potentially invalidating the review. Lesson for me: do not review
> > people's work before it reaches v10, right?
>
> That's not what happened here--or at least, it's not as simple
> as that. Your quick review was very much appreciated.
>
> Yixun: Krzysztof was satisfied with things the way they're
> defined here. Do you feel strongly I should make your suggested
> change? Or are you OK with me just keeping things defined this
> way for the next version? I'd like this question resolved before
> I send the next version.
>
I was fine with squashing all definitions in one file for old version,
but now, a new reset driver is introduced, I think it is deemed an
independent header file? all newly added macros are related to reset.
--
Yixun Lan (dlan)
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets
2025-05-08 12:36 ` Krzysztof Kozlowski
@ 2025-05-08 12:42 ` Alex Elder
0 siblings, 0 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-08 12:42 UTC (permalink / raw)
To: Krzysztof Kozlowski, Yixun Lan
Cc: robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, heylenay, inochiama, guodong,
devicetree, linux-clk, spacemit, linux-riscv, linux-kernel,
Krzysztof Kozlowski
On 5/8/25 7:36 AM, Krzysztof Kozlowski wrote:
> On 08/05/2025 14:17, Alex Elder wrote:
>> On 5/8/25 7:02 AM, Krzysztof Kozlowski wrote:
>>> On 08/05/2025 00:35, Yixun Lan wrote:
>>>>> + - if:
>>>>> + properties:
>>>>> + compatible:
>>>>> + contains:
>>>>> + enum:
>>>>> + - spacemit,k1-syscon-apbc
>>>>> + - spacemit,k1-syscon-apmu
>>>>> + - spacemit,k1-syscon-mpmu
>>>>> + then:
>>>>> + required:
>>>>> + - clocks
>>>>> + - clock-names
>>>>> + - "#clock-cells"
>>>>>
>>>>> additionalProperties: false
>>>>>
>>>>> diff --git a/include/dt-bindings/clock/spacemit,k1-syscon.h b/include/dt-bindings/clock/spacemit,k1-syscon.h
>>>>> index 35968ae982466..f5965dda3b905 100644
>>>>> --- a/include/dt-bindings/clock/spacemit,k1-syscon.h
>>>>> +++ b/include/dt-bindings/clock/spacemit,k1-syscon.h
>>>> would it be better to move all reset definition to its dedicated dir?
>>>> which like: include/dt-bindings/reset/spacemit,k1-syscon.h?
>>>
>>> Please kindly trim the replies from unnecessary context. It makes it
>>> much easier to find new content.
>>>
>>>
>>> I don't get why such comments are appearing so late - at v6. There was
>>> nothing from you about this in v1, v2 and v3, which finally got reviewed.
>>
>> Stephen Boyd said "please rework this to use the auxiliary driver
>> framework" on version 5 of the series; it was otherwise "done" at
>> that point.
>
> Stephen is a subsystem maintainer so his comments are fine or acceptable
> to be late.
>
>>
>> Doing this meant there was a much clearer separation of the clock
>> definitions from the reset definitions. And Yixun's suggestion
>> came from viewing things in that context.
>
> Weren't they applicable to v1 as well? How bindings could change with
> change to auxiliary bus/driver?
>
>>
>> Given the rework, I considered sending this as v1 of a new series
>> but did not.
>
> Sorry but no. Bindings headers at v1 are exactly the same or almost the
> same as now:
>
> https://lore.kernel.org/lkml/20250321151831.623575-2-elder@riscstar.com/
>
> so this idea could have been given at v1, v2, v3, v4, v5 (that would be
> late).... but at some point this is just unnecessary late nitpicking.
>
> So what then? Imagine that you prepare v7 and some other person gives
> you different comment about bindings or bindings headers. Then you
> prepare v8. And then someone comes with one more, different comment,
> because that person did not bother to review between v1-v8 (that
> imaginary future v8), so you need to prepare v9.
>
> I don't think this process is correct.
We'll stick with the original binding definition. -Alex
>
> Best regards,
> Krzysztof
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets
2025-05-08 11:55 ` Alex Elder
@ 2025-05-08 12:47 ` Haylen Chu
0 siblings, 0 replies; 27+ messages in thread
From: Haylen Chu @ 2025-05-08 12:47 UTC (permalink / raw)
To: Alex Elder, robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: inochiama, guodong, devicetree, linux-clk, spacemit, linux-riscv,
linux-kernel
On Thu, May 08, 2025 at 06:55:17AM -0500, Alex Elder wrote:
> On 5/8/25 12:38 AM, Haylen Chu wrote:
> > On Tue, May 06, 2025 at 04:06:35PM -0500, Alex Elder wrote:
> > > Implement reset support for SpacemiT CCUs. The code is structured to
> > > handle SpacemiT resets generically, while defining the set of specific
> > > reset controllers and their resets in an SoC-specific source file. A
> > > SpacemiT reset controller device is an auxiliary device associated with
> > > a clock controller (CCU).
> > >
> > > This initial patch defines the reset controllers for the MPMU, APBC, and
> > > MPMU CCUs, which already defined clock controllers.
> > >
> > > Signed-off-by: Alex Elder <elder@riscstar.com>
> > > ---
> > > drivers/reset/Kconfig | 1 +
> > > drivers/reset/Makefile | 1 +
> > > drivers/reset/spacemit/Kconfig | 12 +++
> > > drivers/reset/spacemit/Makefile | 7 ++
> > > drivers/reset/spacemit/core.c | 61 +++++++++++
> > > drivers/reset/spacemit/core.h | 39 +++++++
> > > drivers/reset/spacemit/k1.c | 177 ++++++++++++++++++++++++++++++++
> > > 7 files changed, 298 insertions(+)
> > > create mode 100644 drivers/reset/spacemit/Kconfig
> > > create mode 100644 drivers/reset/spacemit/Makefile
> > > create mode 100644 drivers/reset/spacemit/core.c
> > > create mode 100644 drivers/reset/spacemit/core.h
> > > create mode 100644 drivers/reset/spacemit/k1.c
> > >
> >
> > ...
> >
> > > diff --git a/drivers/reset/spacemit/Kconfig b/drivers/reset/spacemit/Kconfig
> > > new file mode 100644
> > > index 0000000000000..4ff3487a99eff
> > > --- /dev/null
> > > +++ b/drivers/reset/spacemit/Kconfig
> > > @@ -0,0 +1,12 @@
> > > +# SPDX-License-Identifier: GPL-2.0-only
> > > +
> > > +config RESET_SPACEMIT
> > > + bool
> > > +
> > > +config RESET_SPACEMIT_K1
> > > + tristate "SpacemiT K1 reset driver"
> > > + depends on ARCH_SPACEMIT || COMPILE_TEST
> > > + select RESET_SPACEMIT
> > > + default ARCH_SPACEMIT
> > > + help
> > > + This enables the reset controller driver for the SpacemiT K1 SoC.
...
> > > diff --git a/drivers/reset/spacemit/Makefile b/drivers/reset/spacemit/Makefile
> > > new file mode 100644
> > > index 0000000000000..3a064e9d5d6b4
> > > --- /dev/null
> > > +++ b/drivers/reset/spacemit/Makefile
> > > @@ -0,0 +1,7 @@
> > > +# SPDX-License-Identifier: GPL-2.0
> > > +
> > > +obj-$(CONFIG_RESET_SPACEMIT) += reset_spacemit.o
> >
> > As RESET_SPACEMIT is defined as bool, the reset driver will never be
> > compiled as a module... so either the RESET_SPACEMIT_K1 should be
> > limited to bool as well or you could take an approach similar to the
> > clock driver.
>
> I'm not sure I understand this statement, at least in this
> context. This pattern is used to define a single module
> "reset_spacemit.o" out of several source files.
The problem is that RESET_SPACEMIT could only evaluate to N or Y (it's a
bool entry), thus reset_spacemit.o will always be built into the kernel,
regardless whether RESET_SPACEMIT_K1 is set to Y or M.
In the clock driver, the platform config entry (SPACEMIT_CCU, bool type)
is used to hide SoC-specific entries instead of being really used in
Makefile.
> But I think you're saying that RESET_SPACEMIT and
> RESET_SPACEMIT_K1 should both be bool, or both be
> tristate. I will resolve that question before I
> send the next version.
This isn't necessary, but making both of them bool will definitely
simplify your work, although I'd like to see the reset driver able to
be built as module, just like the clock one :)
> > > +reset_spacemit-y := core.o
> > > +
> > > +reset_spacemit-$(CONFIG_RESET_SPACEMIT_K1) += k1.o
Regards,
Haylen Chu
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices
2025-05-08 4:46 ` Haylen Chu
@ 2025-05-08 20:04 ` Alex Elder
2025-05-08 20:17 ` Alex Elder
0 siblings, 1 reply; 27+ messages in thread
From: Alex Elder @ 2025-05-08 20:04 UTC (permalink / raw)
To: Haylen Chu, robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: inochiama, guodong, devicetree, linux-clk, spacemit, linux-riscv,
linux-kernel
On 5/7/25 11:46 PM, Haylen Chu wrote:
> On Tue, May 06, 2025 at 04:06:34PM -0500, Alex Elder wrote:
>> Add a new reset_name field to the spacemit_ccu_data structure. If it is
>> non-null, the CCU implements a reset controller, and the name will be
>> used as the name for the auxiliary device that implements it.
>>
>> Define a new type to hold an auxiliary device as well as the regmap
>> pointer that will be needed by CCU reset controllers. Set up code to
>> initialize and add an auxiliary device for any CCU that implements reset
>> functionality.
>>
>> Make it optional for a CCU to implement a clock controller. This
>> doesn't apply to any of the existing CCUs but will for some new ones
>> that will be added soon.
>>
>> Signed-off-by: Alex Elder <elder@riscstar.com>
>> ---
>> drivers/clk/spacemit/ccu-k1.c | 85 +++++++++++++++++++++++++++++++----
>> include/soc/spacemit/ccu_k1.h | 12 +++++
>> 2 files changed, 89 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c
>> index 9545cfe60b92b..6b1845e899e5f 100644
>> --- a/drivers/clk/spacemit/ccu-k1.c
>> +++ b/drivers/clk/spacemit/ccu-k1.c
>
> ...
>
>> +static void spacemit_cadev_release(struct device *dev)
>> +{
>> + struct auxiliary_device *adev = to_auxiliary_dev(dev);
>> +
>> + kfree(to_spacemit_ccu_adev(adev));
>> +}
>
> spacemit_ccu_adev structures are allocated with devm_kzalloc() in
> spacemit_ccu_reset_register(), which means its lifetime is bound to the
> driver and it'll be automatically released after driver removal; won't
> there be a possibility of double-free? I think the release callback
> could be simply dropped.
You are correct. And unfortunately I didn't include the fix
for this in the patches I just posted, because somehow this
message was not included with the group in my mail program.
I'm going to send v8 after I fix this and verify it again.
-Alex
> ...
>
>> +static int spacemit_ccu_reset_register(struct device *dev,
>> + struct regmap *regmap,
>> + const char *reset_name)
>> +{
>> + struct spacemit_ccu_adev *cadev;
>> + struct auxiliary_device *adev;
>> + static u32 next_id;
>> + int ret;
>> +
>> + /* Nothing to do if the CCU does not implement a reset controller */
>> + if (!reset_name)
>> + return 0;
>> +
>> + cadev = devm_kzalloc(dev, sizeof(*cadev), GFP_KERNEL);
>
> Here spacemit_ccu_adev is allocated.
>
>> + if (!cadev)
>> + return -ENOMEM;
>> + cadev->regmap = regmap;
>> +
>> + adev = &cadev->adev;
>> + adev->name = reset_name;
>> + adev->dev.parent = dev;
>> + adev->dev.release = spacemit_cadev_release;
>> + adev->dev.of_node = dev->of_node;
>> + adev->id = next_id++;
>> +
>> + ret = auxiliary_device_init(adev);
>> + if (ret)
>> + return ret;
>> +
>> + ret = auxiliary_device_add(adev);
>> + if (ret) {
>> + auxiliary_device_uninit(adev);
>> + return ret;
>> + }
>> +
>> + return devm_add_action_or_reset(dev, spacemit_adev_unregister, adev);
>> +}
>> +
>
> Best regards,
> Haylen Chu
^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices
2025-05-08 20:04 ` Alex Elder
@ 2025-05-08 20:17 ` Alex Elder
0 siblings, 0 replies; 27+ messages in thread
From: Alex Elder @ 2025-05-08 20:17 UTC (permalink / raw)
To: Haylen Chu, robh, krzk+dt, conor+dt, mturquette, sboyd, p.zabel,
paul.walmsley, palmer, aou, alex, dlan
Cc: inochiama, guodong, devicetree, linux-clk, spacemit, linux-riscv,
linux-kernel
On 5/8/25 3:04 PM, Alex Elder wrote:
> On 5/7/25 11:46 PM, Haylen Chu wrote:
>> On Tue, May 06, 2025 at 04:06:34PM -0500, Alex Elder wrote:
>>> Add a new reset_name field to the spacemit_ccu_data structure. If it is
>>> non-null, the CCU implements a reset controller, and the name will be
>>> used as the name for the auxiliary device that implements it.
>>>
>>> Define a new type to hold an auxiliary device as well as the regmap
>>> pointer that will be needed by CCU reset controllers. Set up code to
>>> initialize and add an auxiliary device for any CCU that implements reset
>>> functionality.
>>>
>>> Make it optional for a CCU to implement a clock controller. This
>>> doesn't apply to any of the existing CCUs but will for some new ones
>>> that will be added soon.
>>>
>>> Signed-off-by: Alex Elder <elder@riscstar.com>
>>> ---
>>> drivers/clk/spacemit/ccu-k1.c | 85 +++++++++++++++++++++++++++++++----
>>> include/soc/spacemit/ccu_k1.h | 12 +++++
>>> 2 files changed, 89 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/
>>> ccu-k1.c
>>> index 9545cfe60b92b..6b1845e899e5f 100644
>>> --- a/drivers/clk/spacemit/ccu-k1.c
>>> +++ b/drivers/clk/spacemit/ccu-k1.c
>>
>> ...
>>
>>> +static void spacemit_cadev_release(struct device *dev)
>>> +{
>>> + struct auxiliary_device *adev = to_auxiliary_dev(dev);
>>> +
>>> + kfree(to_spacemit_ccu_adev(adev));
>>> +}
>>
>> spacemit_ccu_adev structures are allocated with devm_kzalloc() in
>> spacemit_ccu_reset_register(), which means its lifetime is bound to the
>> driver and it'll be automatically released after driver removal; won't
>> there be a possibility of double-free? I think the release callback
>> could be simply dropped.
>
> You are correct. And unfortunately I didn't include the fix
> for this in the patches I just posted, because somehow this
> message was not included with the group in my mail program.
>
> I'm going to send v8 after I fix this and verify it again.
To be clear, the fix is to use kzalloc(), rather than calling
devm_kzalloc() with the parent device as first argument.
I'll also include <linux/slab.h> to avoid the warning
reported by the kernel test robot.
-Alex
>
> -Alex
>
>
>> ...
>>
>>> +static int spacemit_ccu_reset_register(struct device *dev,
>>> + struct regmap *regmap,
>>> + const char *reset_name)
>>> +{
>>> + struct spacemit_ccu_adev *cadev;
>>> + struct auxiliary_device *adev;
>>> + static u32 next_id;
>>> + int ret;
>>> +
>>> + /* Nothing to do if the CCU does not implement a reset
>>> controller */
>>> + if (!reset_name)
>>> + return 0;
>>> +
>>> + cadev = devm_kzalloc(dev, sizeof(*cadev), GFP_KERNEL);
>>
>> Here spacemit_ccu_adev is allocated.
>>
>>> + if (!cadev)
>>> + return -ENOMEM;
>>> + cadev->regmap = regmap;
>>> +
>>> + adev = &cadev->adev;
>>> + adev->name = reset_name;
>>> + adev->dev.parent = dev;
>>> + adev->dev.release = spacemit_cadev_release;
>>> + adev->dev.of_node = dev->of_node;
>>> + adev->id = next_id++;
>>> +
>>> + ret = auxiliary_device_init(adev);
>>> + if (ret)
>>> + return ret;
>>> +
>>> + ret = auxiliary_device_add(adev);
>>> + if (ret) {
>>> + auxiliary_device_uninit(adev);
>>> + return ret;
>>> + }
>>> +
>>> + return devm_add_action_or_reset(dev, spacemit_adev_unregister,
>>> adev);
>>> +}
>>> +
>>
>> Best regards,
>> Haylen Chu
>
^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2025-05-08 20:17 UTC | newest]
Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-06 21:06 [PATCH v6 0/6] clk: spacemit: add K1 reset support Alex Elder
2025-05-06 21:06 ` [PATCH v6 1/6] dt-bindings: soc: spacemit: define spacemit,k1-ccu resets Alex Elder
2025-05-07 22:35 ` Yixun Lan
2025-05-08 2:19 ` Alex Elder
2025-05-08 12:02 ` Krzysztof Kozlowski
2025-05-08 12:17 ` Alex Elder
2025-05-08 12:36 ` Krzysztof Kozlowski
2025-05-08 12:42 ` Alex Elder
2025-05-08 12:40 ` Yixun Lan
2025-05-06 21:06 ` [PATCH v6 2/6] soc: spacemit: create a header for clock/reset registers Alex Elder
2025-05-08 4:16 ` Haylen Chu
2025-05-08 11:40 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 3/6] clk: spacemit: set up reset auxiliary devices Alex Elder
2025-05-08 4:09 ` kernel test robot
2025-05-08 4:46 ` Haylen Chu
2025-05-08 20:04 ` Alex Elder
2025-05-08 20:17 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 4/6] reset: spacemit: add support for SpacemiT CCU resets Alex Elder
2025-05-08 5:38 ` Haylen Chu
2025-05-08 11:55 ` Alex Elder
2025-05-08 12:47 ` Haylen Chu
2025-05-08 9:01 ` Philipp Zabel
2025-05-08 12:05 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 5/6] reset: spacemit: define three more CCUs Alex Elder
2025-05-08 9:11 ` Philipp Zabel
2025-05-08 12:29 ` Alex Elder
2025-05-06 21:06 ` [PATCH v6 6/6] riscv: dts: spacemit: add reset support for the K1 SoC Alex Elder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).