Implement hardware automatic clock gating (HWACG) for gs101
Subsystems (5)
Peter Griffin
maintainerv6 cover Implement hardware automatic clock gating (HWACG) for gs101
Hi folks,
This series addresses an issue with Samsung Exynos based upstream clock driver whereby the upstream clock driver sets all the clock gates into "manual mode" (which uses a bit that is documented as reserved in the gate registers).
Another issue with the current "manual clock gating" approach upstream is there are many bus/interconnect clocks whose relationships to the IPs are not well documented or defined in the specs. When adding a new CMU until now we have tried to label these clocks appropriately with CLK_IS_CRITICAL and CLK_IGNORE_UNUSED but doing so is both error prone and time consuming. If your lucky disabling a critical bus clock causes an immediate hang. Other clocks however aren't so obvious and show up through random instability some period of time later.
Fortunately each CMU (at least on newer Exynos) provides a "hardware automatic clock gating" HWACG feature that is used by the downstream Samsung clock drivers. Hardware automatic clock gating uses a hardware interface between the CMU and IP to control all clocks required by the IP. This interface is called Q-channel, and is part of the Arm AMBA low power interface specification [1].
The advantage of using this Qchannel hardware interface for enabling/disabling the clocks is that it takes care of all clocks (including bus/interconnect) ones for the IP automatically thereby reducing the dynamic power.
Whilst each clock component (GATE, MUX, DIV, QCH etc) has a HWACG enable bit there are also some "global enable override" bits for the entire CMU in the CMU_CONTROLLER_OPTION register.
This series makes use of those "global enable" override bits to enable auto clock mode for the entire CMU and every component within it. Through experimentation we can see that setting the "manual mode" reserved gate bit on a particular gate register overides the global enable bits. So the code is updated accordingly not to do that.
Auto clock mode has been implemented as a "opt in" by setting a new auto_clock_gate flag in the CMU static data. The intention is existing platforms in manual mode should not be effected by any of these changes.
If auto_clock_mode flag is set and the option_offset field is specified then the global enable override bits will be written for the CMU (to avoid relying on any prior bootstage configuration). Again if auto mode is enabled the code no longer sets MANUAL and clears HWACG bits on each gate register.
To ensure compatibility with older DTs (that specified an incorrect CMU size) the resource size is checked and the driver falls back to manual clock gate mode in such cases. As the CLK_IGNORE_UNUSED and CLK_IS_CRITICAL flags are required for manual clock gate mode, the patch removing these flags has been dropped from v2. I tested with an old DT and we successfully switch to manual clock gate mode and the system correctly boots.
To have dynamic root clock gating (drcg) of bus components and memclk enabled, it is required to set the bus_component_drcg and memclk registers in the correspondingly named sysreg controller. If auto clock mode is enabled the clock driver will now attempt to get the sysreg syscon via the samsung,sysreg property (as used by other Exynos drivers upstream) and set the registers accordingly. The suspend/resume code paths are also updated to handle saving/restoring registers using a regmap. Note cmu_top is an exception and does not have a corresondingly named sysreg_top.
As all clock gates are currently exposed in the gs101 drivers and DT, we continue to register all of these gates in auto clock mode, but with some new samsung_auto_clk_gate_ops. As clk enable and clk disable are now handled by Q-channel interface the .enable and .disable implementations are no-ops. However by using some CMU qchannel debug registers we can report the current clock status (enabled or disabled) of every clock gate in the system. This has the nice effect of still being able to dump the entire clock tree from /sys/kernel/debug/clk/clk_summary and see a live view of every auto clock in the system.
With the infrastructure in place, all the CMUs registered in clk-gs101 are now updated to enable auto clock mode. From dumping /sys/kernel/debug/clk/clk_summary it is possible to see that after enabling auto clock mode approximately 305 clocks are enabled, and 299 are now disabled. This number goes up and down a bit by 3-5 clocks just on a idle system sat at a console.
With auto clock mode enabled it is now also possible to boot without the clk_ignore_unused kernel command line property for the first time!
For future CMUs in gs101 I propose we continue to expose all gates, but register the CMU in "auto mode". For new device drivers or updates to existing dt bindings related to clocks to support gs101 I suggest we only use the "obviously correct" clock(s). By "obviously correct" I mean a clock has the IP name in the clock register name, but not try to deduce other obsucurely named bus/interconnect clocks which will now all be handled automatically. Note it is still possible to test whether the "obviously correct" clock is indeed correct by putting the individual gate in manual mode and disabling the clock (e.g. by using devmem).
Note: As everything here will go via one of Krzysztof's trees I've sent it as one series.
regards,
Peter
[1] https://documentation-service.arm.com/static/5f915e69f86e16515cdc3b3e?token=
---
Changes in v6:
- Rebased onto next-20251219 (Krzysztof)
- NOTE: linux-next has a regression atm
24ec03cc5512 ("serial: core: Restore sysfs fwnode information") needs to be reverted for boot testing this series on Pixel 6.
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Invert the test in dt-bindings: clock: google,gs101-clock (Andre)
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Update commit description with additional requested details (Krzysztof)
- Remove unnecessary header of_address.h (Peter)
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Add missing 'np' func param to kerneldoc in samsung_cmu_register_clocks (0-DAY CI )
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Rebased onto next-20251024
- Fallback to manual clock gate mode for old DTs with incorrect CMU reg
size (added samsung_is_auto_capable(). Tested with old DT and it works as expected. It does require keeping all the CLK_IS_CRITICAL
CLK_IGNORE_UNUSED flags in clk-gs101 so patch removing those is
dropped. (Krzysztof)
- Rename OPT_UNKNOWN bit to OPT_EN_LAYER2_CTRL (Andre)
- Rename OPT_EN_MEM_PM_GATING to OPT_EN_MEM_PWR_GATING (Peter)
- Reverse Option bit definitions LSB -> MSB (Krzysztof)
- Update kerneldoc init_clk_regs comment (Andre)
- Fix space on various comments (Andre)
- Fix regmap typo on samsung_clk_save/restore calls (Andre)
- Include error code in pr_err message (Andre)
- Add macros for dcrg and memclk (Andre)
- Avoid confusing !IS_ERR_OR_NULL(ctx->sysreg) test (Krzysztof)
- Update kerneldoc to mention drcg_offset & memclk_offset are in sysreg
(Andre)
- Update bindings commit description as to why the sysreg is required (Krzysztof)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Peter Griffin (4):
dt-bindings: clock: google,gs101-clock: add samsung,sysreg property as required
arm64: dts: exynos: gs101: add samsung,sysreg property to CMU nodes
clk: samsung: Implement automatic clock gating mode for CMUs
clk: samsung: gs101: Enable auto_clock_gate mode for each gs101 CMU
.../bindings/clock/google,gs101-clock.yaml | 19 +- arch/arm64/boot/dts/exynos/google/gs101.dtsi | 6 + drivers/clk/samsung/clk-exynos-arm64.c | 62 ++++++- drivers/clk/samsung/clk-exynos4.c | 12 +- drivers/clk/samsung/clk-exynos4412-isp.c | 4 +- drivers/clk/samsung/clk-exynos5250.c | 2 +- drivers/clk/samsung/clk-exynos5420.c | 4 +- drivers/clk/samsung/clk-gs101.c | 55 ++++++ drivers/clk/samsung/clk-s3c64xx.c | 4 +- drivers/clk/samsung/clk-s5pv210.c | 2 +- drivers/clk/samsung/clk.c | 200 +++++++++++++++++++-- drivers/clk/samsung/clk.h | 55 +++++- 12 files changed, 381 insertions(+), 44 deletions(-)
---
base-commit: cc3aa43b44bdb43dfbac0fcb51c56594a11338a8
change-id: 20251008-automatic-clocks-249ab60f62ce
Best regards,
Signature · 1 line
Peter Griffin <[email protected]>
Peter Griffin
maintainerPATCH v6 1/4 dt-bindings: clock: google,gs101-clock: add samsung,sysreg property as required
Each CMU (with the exception of cmu_top) has a corresponding sysreg bank that contains the BUSCOMPONENT_DRCG_EN and optional MEMCLK registers. The BUSCOMPONENT_DRCG_EN register enables dynamic root clock gating of bus components and MEMCLK gates the sram clock.
Now the clock driver supports automatic clock mode, to fully enable dynamic root clock gating it is required to configure these registers. Update the bindings documentation so that all CMUs (with the exception of gs101-cmu-top) have samsung,sysreg as a required property.
Note this is NOT an ABI break, as if the property isn't specified the clock driver will fallback to the current behaviour of not initializing the registers. The system still boots, but bus components won't benefit from dynamic root clock gating and dynamic power will be higher (which has been the case until now anyway).
Additionally update the DT example to included the correct CMU size as registers in that region are used for automatic clock mode.
---
Changes in v5:
- Invert the test for google,gs101-cmu-top (Andre)
Changes in v4
- Update commit description with additional requested details (Krzysztof)
Changes in v3:
- Update commit description as to why the sysreg is required (Krzysztof)
Changes in v2:
- Update commit description regarding updated example (Andre)
--- .../devicetree/bindings/clock/google,gs101-clock.yaml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/clock/google,gs101-clock.yaml +18 -1
@@ -52,6 +52,11 @@ properties: reg: maxItems: 1 + samsung,sysreg: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Phandle to system registers interface. + required: - compatible - "#clock-cells"
@@ -166,6 +171,18 @@ allOf: - const: bus - const: ip + - if: + properties: + compatible: + contains: + const: google,gs101-cmu-top + then: + properties: + samsung,sysreg: false + else: + required: + - samsung,sysreg + additionalProperties: false examples:
@@ -175,7 +192,7 @@ examples: cmu_top: clock-controller@1e080000 { compatible = "google,gs101-cmu-top"; - reg = <0x1e080000 0x8000>; + reg = <0x1e080000 0x10000>; #clock-cells = <1>; clocks = <&ext_24_5m>; clock-names = "oscclk";
Signature · 1 line
2.52.0.351.gbe84eed79e-goog
Krzysztof Kozlowski
maintainerRe: [PATCH v6 1/4] dt-bindings: clock: google,gs101-clock: add samsung,sysreg property as required
Quoted 16 lines · Peter Griffin
Each CMU (with the exception of
cmu_top) has a corresponding sysreg bank that contains theBUSCOMPONENT_DRCG_ENand optional MEMCLK registers. TheBUSCOMPONENT_DRCG_ENregister enables dynamic root clock gating of bus components and MEMCLK gates the sram clock.Now the clock driver supports automatic clock mode, to fully enable dynamic root clock gating it is required to configure these registers. Update the bindings documentation so that all CMUs (with the exception of gs101-cmu-top) have samsung,sysreg as a required property.
Note this is NOT an ABI break, as if the property isn't specified the clock driver will fallback to the current behaviour of not initializing the registers. The system still boots, but bus components won't benefit from dynamic root clock gating and dynamic power will be higher (which has been the case until now anyway).
Quoted 8 lines
Additionally update the DT example to included the correct CMU size as registers in that region are used for automatic clock mode.
Signed-off-by Peter Griffin <[email protected]>---
Changes in v5:
- Invert the test for google,gs101-cmu-top (Andre)
<form letter>
This is a friendly reminder during the review process.
It looks like you received a tag and forgot to add it.
If you do not know the process, here is a short explanation:
Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions of patchset, under or above your Signed-off-by tag, unless patch changed significantly (e.g. new properties added to the DT bindings). Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.
Please read:
https://elixir.bootlin.com/linux/v6.12-rc3/source/Documentation/process/submitting-patches.rst#L577
If a tag was not added on purpose, please state why and what changed. </form letter>
Best regards,
Krzysztof
Peter Griffin
maintainerRe: [PATCH v6 1/4] dt-bindings: clock: google,gs101-clock: add samsung,sysreg property as required
Hi Krzysztof,
Quoted 42 lines · Krzysztof Kozlowski
Quoted 16 lines · Peter Griffin
Each CMU (with the exception of
cmu_top) has a corresponding sysreg bank that contains theBUSCOMPONENT_DRCG_ENand optional MEMCLK registers. TheBUSCOMPONENT_DRCG_ENregister enables dynamic root clock gating of bus components and MEMCLK gates the sram clock.Now the clock driver supports automatic clock mode, to fully enable dynamic root clock gating it is required to configure these registers. Update the bindings documentation so that all CMUs (with the exception of gs101-cmu-top) have samsung,sysreg as a required property.
Note this is NOT an ABI break, as if the property isn't specified the clock driver will fallback to the current behaviour of not initializing the registers. The system still boots, but bus components won't benefit from dynamic root clock gating and dynamic power will be higher (which has been the case until now anyway).
Quoted 8 lines
Additionally update the DT example to included the correct CMU size as registers in that region are used for automatic clock mode.
Signed-off-by Peter Griffin <[email protected]>---
Changes in v5:
- Invert the test for google,gs101-cmu-top (Andre)<form letter>
This is a friendly reminder during the review process.It looks like you received a tag and forgot to add it.
If you do not know the process, here is a short explanation:
Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions of patchset, under or above your Signed-off-by tag, unless patch changed significantly (e.g. new properties added to the DT bindings). Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.
Quoted 5 lines
Please read:
https://elixir.bootlin.com/linux/v6.12-rc3/source/Documentation/process/submitting-patches.rst#L577If a tag was not added on purpose, please state why and what changed. </form letter>
Apologies, your tag should have been added.... got kind of sidetracked bisecting the linux-next regression with the serial console and then forgot to apply it.
Peter.
Krzysztof Kozlowski
maintainerRe: [PATCH v6 1/4] dt-bindings: clock: google,gs101-clock: add samsung,sysreg property as required
Quoted 48 lines · Peter Griffin
Hi Krzysztof,
Quoted 45 lines · Krzysztof Kozlowski
Quoted 16 lines · Peter Griffin
Each CMU (with the exception of
cmu_top) has a corresponding sysreg bank that contains theBUSCOMPONENT_DRCG_ENand optional MEMCLK registers. TheBUSCOMPONENT_DRCG_ENregister enables dynamic root clock gating of bus components and MEMCLK gates the sram clock.Now the clock driver supports automatic clock mode, to fully enable dynamic root clock gating it is required to configure these registers. Update the bindings documentation so that all CMUs (with the exception of gs101-cmu-top) have samsung,sysreg as a required property.
Note this is NOT an ABI break, as if the property isn't specified the clock driver will fallback to the current behaviour of not initializing the registers. The system still boots, but bus components won't benefit from dynamic root clock gating and dynamic power will be higher (which has been the case until now anyway).
Quoted 8 lines
Additionally update the DT example to included the correct CMU size as registers in that region are used for automatic clock mode.
Signed-off-by Peter Griffin <[email protected]>---
Changes in v5:
- Invert the test for google,gs101-cmu-top (Andre)<form letter>
This is a friendly reminder during the review process.It looks like you received a tag and forgot to add it.
If you do not know the process, here is a short explanation:
Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions of patchset, under or above your Signed-off-by tag, unless patch changed significantly (e.g. new properties added to the DT bindings). Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.Please read:
https://elixir.bootlin.com/linux/v6.12-rc3/source/Documentation/process/submitting-patches.rst#L577
Quoted 6 lines
Quoted 2 lines
If a tag was not added on purpose, please state why and what changed. </form letter>
Apologies, your tag should have been added.... got kind of sidetracked bisecting the linux-next regression with the serial console and then forgot to apply it.
I think it was more than one tag, so I decided not to look for them. Please send v7 with all tags collected.
Best regards,
Krzysztof
Peter Griffin
maintainerRe: [PATCH v6 1/4] dt-bindings: clock: google,gs101-clock: add samsung,sysreg property as required
Hi Krzysztof,
Quoted 53 lines · Krzysztof Kozlowski
Quoted 51 lines · Peter Griffin
Hi Krzysztof,
Quoted 47 lines · Krzysztof Kozlowski
Quoted 16 lines · Peter Griffin
Each CMU (with the exception of
cmu_top) has a corresponding sysreg bank that contains theBUSCOMPONENT_DRCG_ENand optional MEMCLK registers. TheBUSCOMPONENT_DRCG_ENregister enables dynamic root clock gating of bus components and MEMCLK gates the sram clock.Now the clock driver supports automatic clock mode, to fully enable dynamic root clock gating it is required to configure these registers. Update the bindings documentation so that all CMUs (with the exception of gs101-cmu-top) have samsung,sysreg as a required property.
Note this is NOT an ABI break, as if the property isn't specified the clock driver will fallback to the current behaviour of not initializing the registers. The system still boots, but bus components won't benefit from dynamic root clock gating and dynamic power will be higher (which has been the case until now anyway).
Quoted 8 lines
Additionally update the DT example to included the correct CMU size as registers in that region are used for automatic clock mode.
Signed-off-by Peter Griffin <[email protected]>---
Changes in v5:
- Invert the test for google,gs101-cmu-top (Andre)<form letter>
This is a friendly reminder during the review process.It looks like you received a tag and forgot to add it.
If you do not know the process, here is a short explanation:
Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions of patchset, under or above your Signed-off-by tag, unless patch changed significantly (e.g. new properties added to the DT bindings). Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.Please read:
https://elixir.bootlin.com/linux/v6.12-rc3/source/Documentation/process/submitting-patches.rst#L577If a tag was not added on purpose, please state why and what changed. </form letter>
Quoted 6 lines
Quoted 3 lines
Apologies, your tag should have been added.... got kind of sidetracked bisecting the linux-next regression with the serial console and then forgot to apply it.
I think it was more than one tag, so I decided not to look for them. Please send v7 with all tags collected.
Sure, will resend shortly.
Peter
Peter Griffin
maintainerPATCH v6 2/4 arm64: dts: exynos: gs101: add samsung,sysreg property to CMU nodes
In reply to Peter GriffinWith the exception of cmu_top, each CMU has a corresponding sysreg bank that contains the BUSCOMPONENT_DRCG_EN and optional MEMCLK registers. The BUSCOMPONENT_DRCG_EN register enables dynamic root clock gating of bus components and MEMCLK gates the sram clock.
Now the clock driver supports automatic clock mode, provide the samsung,sysreg property so the driver can enable dynamic root clock gating of bus components and gate sram clock.
Note without the property specified the driver simply falls back to previous behaviour of not configuring these registers so it is not an ABI break.
---
Changes in v4:
- Update commit message (Peter)
--- arch/arm64/boot/dts/exynos/google/gs101.dtsi | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm64/boot/dts/exynos/google/gs101.dtsi +6 -0
@@ -578,6 +578,7 @@ cmu_misc: clock-controller@10010000 { clocks = <&cmu_top CLK_DOUT_CMU_MISC_BUS>, <&cmu_top CLK_DOUT_CMU_MISC_SSS>; clock-names = "bus", "sss"; + samsung,sysreg = <&sysreg_misc>; }; sysreg_misc: syscon@10030000 {
@@ -671,6 +672,7 @@ cmu_peric0: clock-controller@10800000 { <&cmu_top CLK_DOUT_CMU_PERIC0_BUS>, <&cmu_top CLK_DOUT_CMU_PERIC0_IP>; clock-names = "oscclk", "bus", "ip"; + samsung,sysreg = <&sysreg_peric0>; }; sysreg_peric0: syscon@10820000 {
@@ -1217,6 +1219,7 @@ cmu_peric1: clock-controller@10c00000 { <&cmu_top CLK_DOUT_CMU_PERIC1_BUS>, <&cmu_top CLK_DOUT_CMU_PERIC1_IP>; clock-names = "oscclk", "bus", "ip"; + samsung,sysreg = <&sysreg_peric1>; }; sysreg_peric1: syscon@10c20000 {
@@ -1575,6 +1578,7 @@ cmu_hsi0: clock-controller@11000000 { <&cmu_top CLK_DOUT_CMU_HSI0_USBDPDBG>; clock-names = "oscclk", "bus", "dpgtc", "usb31drd", "usbdpdbg"; + samsung,sysreg = <&sysreg_hsi0>; }; sysreg_hsi0: syscon@11020000 {
@@ -1646,6 +1650,7 @@ cmu_hsi2: clock-controller@14400000 { <&cmu_top CLK_DOUT_CMU_HSI2_UFS_EMBD>, <&cmu_top CLK_DOUT_CMU_HSI2_MMC_CARD>; clock-names = "oscclk", "bus", "pcie", "ufs", "mmc"; + samsung,sysreg = <&sysreg_hsi2>; }; sysreg_hsi2: syscon@14420000 {
@@ -1706,6 +1711,7 @@ cmu_apm: clock-controller@17400000 { clocks = <&ext_24_5m>; clock-names = "oscclk"; + samsung,sysreg = <&sysreg_apm>; }; sysreg_apm: syscon@17420000 {
Signature · 1 line
2.52.0.351.gbe84eed79e-goog
Peter Griffin
maintainerPATCH v6 3/4 clk: samsung: Implement automatic clock gating mode for CMUs
In reply to Peter GriffinUpdate exynos_arm64_init_clocks() so that it enables the automatic clock mode bits in the CMU option register if the auto_clock_gate flag and option_offset fields are set for the CMU. To ensure compatibility with older DTs (that specified an incorrect CMU reg size), detect this and fallback to manual clock gate mode as the auto clock mode feature depends on registers in this area.
The CMU option register bits are global and effect every clock component in the CMU, as such clearing the GATE_ENABLE_HWACG bit and setting GATE_MANUAL bit on every gate register is only required if auto_clock_gate is false.
Additionally if auto_clock_gate is enabled the dynamic root clock gating and memclk registers will be configured in the corresponding CMUs sysreg bank. These registers are exposed via syscon, so the register samsung_clk_save/restore paths are updated to also take a regmap.
As many gates for various Samsung SoCs are already exposed in the Samsung clock drivers a new samsung_auto_clk_gate_ops is implemented. This uses some CMU debug registers to report whether clocks are enabled or disabled when operating in automatic mode. This allows /sys/kernel/debug/clk/clk_summary to still dump the entire clock tree and correctly report the status of each clock in the system.
---
Changes in v3:
- Add missing 'np' func param to kerneldoc in samsung_cmu_register_clocks (0-DAY CI)
Changes in v2:
- Fallback to manual clock gate mode for old DTs with incorrect CMU size (added samsung_is_auto_capable()) (Krzysztof)
- Rename OPT_UNKNOWN bit to OPT_EN_LAYER2_CTRL (Andre)
- Rename OPT_EN_MEM_PM_GATING to OPT_EN_MEM_PWR_GATING (Andre)
- Reverse Option bit definitions LSB -> MSB (Krzysztof)
- Update kerneldoc init_clk_regs comment (Andre)
- Fix space on various comments (Andre)
- Fix regmap typo on samsung_clk_save/restore calls (Andre)
- Include error code in pr_err message (Andre)
- Add macros for dcrg and memclk (Andre)
- Avoid confusing !IS_ERR_OR_NULL(ctx->sysreg) test (Krzysztof)
- Update kerneldoc to mention drcg_offset & memclk_offset are in sysreg (Andre)
- Fix 0-DAY CI randconfig warning (0-DAY CI)
- Update clk-s5pv210 and clk-s3c64xx.c samsung_clk_sleep_init call sites (Peter)
--- drivers/clk/samsung/clk-exynos-arm64.c | 62 ++++++++-- drivers/clk/samsung/clk-exynos4.c | 12 +- drivers/clk/samsung/clk-exynos4412-isp.c | 4 +- drivers/clk/samsung/clk-exynos5250.c | 2 +- drivers/clk/samsung/clk-exynos5420.c | 4 +- drivers/clk/samsung/clk-s3c64xx.c | 4 +- drivers/clk/samsung/clk-s5pv210.c | 2 +- drivers/clk/samsung/clk.c | 200 ++++++++++++++++++++++++++++--- drivers/clk/samsung/clk.h | 55 ++++++++- 9 files changed, 302 insertions(+), 43 deletions(-)
drivers/clk/samsung/clk-exynos-arm64.c +53 -9
@@ -24,6 +24,16 @@#define GATE_MANUAL BIT(20)#define GATE_ENABLE_HWACG BIT(28) +/* Option register bits */ +#define OPT_EN_MEM_PWR_GATING BIT(24) +#define OPT_EN_AUTO_GATING BIT(28) +#define OPT_EN_PWR_MANAGEMENT BIT(29) +#define OPT_EN_LAYER2_CTRL BIT(30) +#define OPT_EN_DBG BIT(31) + +#define CMU_OPT_GLOBAL_EN_AUTO_GATING (OPT_EN_DBG | OPT_EN_LAYER2_CTRL | \ + OPT_EN_PWR_MANAGEMENT | OPT_EN_AUTO_GATING | OPT_EN_MEM_PWR_GATING) +/* PLL_CONx_PLL register offsets range */ #define PLL_CON_OFF_START 0x100#define PLL_CON_OFF_END 0x600
@@ -37,6 +47,8 @@ struct exynos_arm64_cmu_data {unsigned int nr_clk_save;const struct samsung_clk_reg_dump *clk_suspend;unsigned int nr_clk_suspend; +struct samsung_clk_reg_dump *clk_sysreg_save; +unsigned int nr_clk_sysreg;struct clk *clk;struct clk **pclks;
@@ -76,19 +88,41 @@ static void __init exynos_arm64_init_clocks(struct device_node *np,const unsigned long *reg_offs = cmu->clk_regs;size_t reg_offs_len = cmu->nr_clk_regs;void __iomem *reg_base; +bool init_auto;size_t i; reg_base =of_iomap (np,0 );if (!reg_base)panic ("%s: failed to map registers\n" , __func__); +/* ensure compatibility with older DTs */ +if (cmu->auto_clock_gate &&samsung_is_auto_capable (np)) + init_auto = true; +else + init_auto = false; + +if (cmu->option_offset && init_auto) { +/* +* Enable the global automatic mode for the entire CMU. +* This overrides the individual HWACG bits in each of the +* individual gate, mux and qch registers. +*/ +writel (CMU_OPT_GLOBAL_EN_AUTO_GATING , + reg_base + cmu->option_offset); + } +for (i =0 ; i < reg_offs_len; ++i) {void __iomem *reg = reg_base + reg_offs[i];u32 val;if (cmu->manual_plls &&is_pll_con1_reg (reg_offs[i])) {writel (PLL_CON1_MANUAL , reg); - }else if (is_gate_reg (reg_offs[i])) { + }else if (is_gate_reg (reg_offs[i]) && !init_auto) { +/* +* Setting GATE_MANUAL bit (which is described in TRM as +* reserved!) overrides the global CMU automatic mode +* option. +*/ val =readl (reg); val |=GATE_MANUAL ; val &= ~GATE_ENABLE_HWACG ;
@@ -210,8 +244,8 @@ void __init exynos_arm64_register_cmu(struct device *dev,/** * exynos_arm64_register_cmu_pm - Register Exynos CMU domain with PM support * -* @pdev: Platform device object -* @set_manual: If true, set gate clocks to manual mode +* @pdev: Platform device object +* @init_clk_regs: If true, initialize CMU registers * * It's a version of exynos_arm64_register_cmu() with PM support. Should be * called from probe function of platform driver.
@@ -219,7 +253,7 @@ void __init exynos_arm64_register_cmu(struct device *dev,* Return: 0 on success, or negative error code on error. */ int __init exynos_arm64_register_cmu_pm (struct platform_device *pdev, -bool set_manual) +bool init_clk_regs) {const struct samsung_cmu_info *cmu;struct device *dev = &pdev->dev;
@@ -249,7 +283,7 @@ int __init exynos_arm64_register_cmu_pm(struct platform_device *pdev,dev_err (dev,"%s: could not enable bus clock %s; err = %d\n" , __func__, cmu->clk_name, ret); -if (set_manual) +if (init_clk_regs)exynos_arm64_init_clocks (np, cmu); reg_base =devm_platform_ioremap_resource (pdev,0 );
@@ -268,8 +302,10 @@ int __init exynos_arm64_register_cmu_pm(struct platform_device *pdev,pm_runtime_set_active (dev);pm_runtime_enable (dev); -samsung_cmu_register_clocks (data->ctx, cmu); +samsung_cmu_register_clocks (data->ctx, cmu, np);samsung_clk_of_add_provider (dev->of_node, data->ctx); +/* sysreg DT nodes reference a clock in this CMU */ +samsung_en_dyn_root_clk_gating (np, data->ctx, cmu);pm_runtime_put_sync (dev);return 0 ;
@@ -280,14 +316,17 @@ int exynos_arm64_cmu_suspend(struct device *dev)struct exynos_arm64_cmu_data *data =dev_get_drvdata (dev);int i; -samsung_clk_save (data->ctx->reg_base, data->clk_save, +samsung_clk_save (data->ctx->reg_base,NULL , data->clk_save, data->nr_clk_save); +samsung_clk_save (NULL , data->ctx->sysreg, data->clk_sysreg_save, + data->nr_clk_sysreg); +for (i =0 ; i < data->nr_pclks; i++)clk_prepare_enable (data->pclks[i]);/* For suspend some registers have to be set to certain values */ -samsung_clk_restore (data->ctx->reg_base, data->clk_suspend, +samsung_clk_restore (data->ctx->reg_base,NULL , data->clk_suspend, data->nr_clk_suspend);for (i =0 ; i < data->nr_pclks; i++)
@@ -308,9 +347,14 @@ int exynos_arm64_cmu_resume(struct device *dev)for (i =0 ; i < data->nr_pclks; i++)clk_prepare_enable (data->pclks[i]); -samsung_clk_restore (data->ctx->reg_base, data->clk_save, +samsung_clk_restore (data->ctx->reg_base,NULL , data->clk_save, data->nr_clk_save); +if (data->ctx->sysreg) +samsung_clk_restore (NULL , data->ctx->sysreg, + data->clk_sysreg_save, + data->nr_clk_sysreg); +for (i =0 ; i < data->nr_pclks; i++)clk_disable_unprepare (data->pclks[i]);
drivers/clk/samsung/clk-exynos4.c +6 -6
@@ -1361,12 +1361,12 @@ static void __init exynos4_clk_init(struct device_node *np, ARRAY_SIZE(exynos4x12_plls)); } -samsung_cmu_register_clocks (ctx, &cmu_info_exynos4); +samsung_cmu_register_clocks (ctx, &cmu_info_exynos4, np);if (exynos4_soc ==EXYNOS4210 ) { -samsung_cmu_register_clocks (ctx, &cmu_info_exynos4210); +samsung_cmu_register_clocks (ctx, &cmu_info_exynos4210, np); }else { -samsung_cmu_register_clocks (ctx, &cmu_info_exynos4x12); +samsung_cmu_register_clocks (ctx, &cmu_info_exynos4x12, np);if (soc ==EXYNOS4412 )samsung_clk_register_cpu (ctx, exynos4412_cpu_clks,ARRAY_SIZE (exynos4412_cpu_clks));
@@ -1378,15 +1378,15 @@ static void __init exynos4_clk_init(struct device_node *np,if (soc ==EXYNOS4212 || soc ==EXYNOS4412 )exynos4x12_core_down_clock (); -samsung_clk_extended_sleep_init (reg_base, +samsung_clk_extended_sleep_init (reg_base,NULL , exynos4_clk_regs,ARRAY_SIZE (exynos4_clk_regs), src_mask_suspend,ARRAY_SIZE (src_mask_suspend));if (exynos4_soc ==EXYNOS4210 ) -samsung_clk_extended_sleep_init (reg_base, +samsung_clk_extended_sleep_init (reg_base,NULL , exynos4210_clk_save,ARRAY_SIZE (exynos4210_clk_save), src_mask_suspend_e4210,ARRAY_SIZE (src_mask_suspend_e4210));else -samsung_clk_sleep_init (reg_base, exynos4x12_clk_save, +samsung_clk_sleep_init (reg_base,NULL , exynos4x12_clk_save,ARRAY_SIZE (exynos4x12_clk_save));samsung_clk_of_add_provider (np, ctx);
drivers/clk/samsung/clk-exynos4412-isp.c +2 -2
@@ -94,7 +94,7 @@ static int __maybe_unused exynos4x12_isp_clk_suspend(struct device *dev) {struct samsung_clk_provider *ctx =dev_get_drvdata (dev); -samsung_clk_save (ctx->reg_base, exynos4x12_save_isp, +samsung_clk_save (ctx->reg_base,NULL , exynos4x12_save_isp,ARRAY_SIZE (exynos4x12_clk_isp_save));return 0 ; }
@@ -103,7 +103,7 @@ static int __maybe_unused exynos4x12_isp_clk_resume(struct device *dev) {struct samsung_clk_provider *ctx =dev_get_drvdata (dev); -samsung_clk_restore (ctx->reg_base, exynos4x12_save_isp, +samsung_clk_restore (ctx->reg_base,NULL , exynos4x12_save_isp,ARRAY_SIZE (exynos4x12_clk_isp_save));return 0 ; }
drivers/clk/samsung/clk-exynos5250.c +1 -1
@@ -854,7 +854,7 @@ static void __init exynos5250_clk_init(struct device_node *np) PWR_CTRL2_CORE2_UP_RATIO | PWR_CTRL2_CORE1_UP_RATIO);__raw_writel (tmp, reg_base +PWR_CTRL2 ); -samsung_clk_sleep_init (reg_base, exynos5250_clk_regs, +samsung_clk_sleep_init (reg_base,NULL , exynos5250_clk_regs,ARRAY_SIZE (exynos5250_clk_regs));exynos5_subcmus_init (ctx,ARRAY_SIZE (exynos5250_subcmus), exynos5250_subcmus);
drivers/clk/samsung/clk-exynos5420.c +2 -2
@@ -1649,12 +1649,12 @@ static void __init exynos5x_clk_init(struct device_node *np, ARRAY_SIZE(exynos5800_cpu_clks)); } -samsung_clk_extended_sleep_init (reg_base, +samsung_clk_extended_sleep_init (reg_base,NULL , exynos5x_clk_regs,ARRAY_SIZE (exynos5x_clk_regs), exynos5420_set_clksrc,ARRAY_SIZE (exynos5420_set_clksrc));if (soc ==EXYNOS5800 ) { -samsung_clk_sleep_init (reg_base, exynos5800_clk_regs, +samsung_clk_sleep_init (reg_base,NULL , exynos5800_clk_regs,ARRAY_SIZE (exynos5800_clk_regs)); exynos5_subcmus_init(ctx, ARRAY_SIZE(exynos5800_subcmus),
drivers/clk/samsung/clk-s3c64xx.c +2 -2
@@ -449,10 +449,10 @@ void __init s3c64xx_clk_init(struct device_node *np, unsigned long xtal_f,samsung_clk_register_alias (ctx, s3c64xx_clock_aliases,ARRAY_SIZE (s3c64xx_clock_aliases)); -samsung_clk_sleep_init (reg_base, s3c64xx_clk_regs, +samsung_clk_sleep_init (reg_base,NULL , s3c64xx_clk_regs,ARRAY_SIZE (s3c64xx_clk_regs));if (!is_s3c6400) -samsung_clk_sleep_init (reg_base, s3c6410_clk_regs, +samsung_clk_sleep_init (reg_base,NULL , s3c6410_clk_regs,ARRAY_SIZE (s3c6410_clk_regs));samsung_clk_of_add_provider (np, ctx);
drivers/clk/samsung/clk-s5pv210.c +1 -1
@@ -782,7 +782,7 @@ static void __init __s5pv210_clk_init(struct device_node *np,samsung_clk_register_alias (ctx, s5pv210_aliases,ARRAY_SIZE (s5pv210_aliases)); -samsung_clk_sleep_init (reg_base, s5pv210_clk_regs, +samsung_clk_sleep_init (reg_base,NULL , s5pv210_clk_regs,ARRAY_SIZE (s5pv210_clk_regs));samsung_clk_of_add_provider (np, ctx);
drivers/clk/samsung/clk.c +183 -17
290 lines not on this page · raw message
drivers/clk/samsung/clk.h +52 -3
127 lines not on this page · raw message
Signature · 1 line
2.52.0.351.gbe84eed79e-goog
Peter Griffin
maintainerPATCH v6 4/4 clk: samsung: gs101: Enable auto_clock_gate mode for each gs101 CMU
In reply to Peter GriffinEnable auto clock mode, and define the additional fields which are used when this mode is enabled.
/sys/kernel/debug/clk/clk_summary now reports approximately 308 running clocks and 298 disabled clocks. Prior to this commit 586 clocks were running and 17 disabled.
---
Changes in v4:
- Remove unnecessary header of_address.h (Peter)
--- drivers/clk/samsung/clk-gs101.c | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
drivers/clk/samsung/clk-gs101.c +55 -0
@@ -26,6 +26,10 @@#define CLKS_NR_PERIC0 (CLK_GOUT_PERIC0_SYSREG_PERIC0_PCLK + 1)#define CLKS_NR_PERIC1 (CLK_GOUT_PERIC1_SYSREG_PERIC1_PCLK + 1) +#define GS101_GATE_DBG_OFFSET 0x4000 +#define GS101_DRCG_EN_OFFSET 0x104 +#define GS101_MEMCLK_OFFSET 0x108 +/* ---- CMU_TOP ------------------------------------------------------------- */ /* Register Offset definitions for CMU_TOP (0x1e080000) */
@@ -1433,6 +1437,9 @@ static const struct samsung_cmu_info top_cmu_info __initconst = { .nr_clk_ids = CLKS_NR_TOP, .clk_regs = cmu_top_clk_regs, .nr_clk_regs = ARRAY_SIZE(cmu_top_clk_regs), + .auto_clock_gate = true, + .gate_dbg_offset = GS101_GATE_DBG_OFFSET, + .option_offset = CMU_CMU_TOP_CONTROLLER_OPTION, };static void __init gs101_cmu_top_init (struct device_node *np)
@@ -1900,6 +1907,11 @@ static const struct samsung_gate_clock apm_gate_clks[] __initconst = { CLK_CON_GAT_GOUT_BLK_APM_UID_XIU_DP_APM_IPCLKPORT_ACLK, 21, CLK_IS_CRITICAL, 0), }; +static const unsigned long dcrg_memclk_sysreg[]__initconst = { +GS101_DRCG_EN_OFFSET , +GS101_MEMCLK_OFFSET , +}; +static const struct samsung_cmu_info apm_cmu_info__initconst = { .mux_clks = apm_mux_clks, .nr_mux_clks =ARRAY_SIZE (apm_mux_clks),
@@ -1912,6 +1924,12 @@ static const struct samsung_cmu_info apm_cmu_info __initconst = { .nr_clk_ids = CLKS_NR_APM, .clk_regs = apm_clk_regs, .nr_clk_regs = ARRAY_SIZE(apm_clk_regs), + .sysreg_clk_regs = dcrg_memclk_sysreg, + .nr_sysreg_clk_regs = ARRAY_SIZE(dcrg_memclk_sysreg), + .auto_clock_gate = true, + .gate_dbg_offset = GS101_GATE_DBG_OFFSET, + .drcg_offset = GS101_DRCG_EN_OFFSET, + .memclk_offset = GS101_MEMCLK_OFFSET, };/* ---- CMU_HSI0 ------------------------------------------------------------ */
@@ -2375,7 +2393,14 @@ static const struct samsung_cmu_info hsi0_cmu_info __initconst = { .nr_clk_ids = CLKS_NR_HSI0, .clk_regs = hsi0_clk_regs, .nr_clk_regs = ARRAY_SIZE(hsi0_clk_regs), + .sysreg_clk_regs = dcrg_memclk_sysreg, + .nr_sysreg_clk_regs = ARRAY_SIZE(dcrg_memclk_sysreg), .clk_name = "bus", + .auto_clock_gate = true, + .gate_dbg_offset = GS101_GATE_DBG_OFFSET, + .option_offset = HSI0_CMU_HSI0_CONTROLLER_OPTION, + .drcg_offset = GS101_DRCG_EN_OFFSET, + .memclk_offset = GS101_MEMCLK_OFFSET, };/* ---- CMU_HSI2 ------------------------------------------------------------ */
@@ -2863,7 +2888,14 @@ static const struct samsung_cmu_info hsi2_cmu_info __initconst = { .nr_clk_ids = CLKS_NR_HSI2, .clk_regs = cmu_hsi2_clk_regs, .nr_clk_regs = ARRAY_SIZE(cmu_hsi2_clk_regs), + .sysreg_clk_regs = dcrg_memclk_sysreg, + .nr_sysreg_clk_regs = ARRAY_SIZE(dcrg_memclk_sysreg), .clk_name = "bus", + .auto_clock_gate = true, + .gate_dbg_offset = GS101_GATE_DBG_OFFSET, + .option_offset = HSI2_CMU_HSI2_CONTROLLER_OPTION, + .drcg_offset = GS101_DRCG_EN_OFFSET, + .memclk_offset = GS101_MEMCLK_OFFSET, };/* ---- CMU_MISC ------------------------------------------------------------ */
@@ -3423,7 +3455,14 @@ static const struct samsung_cmu_info misc_cmu_info __initconst = { .nr_clk_ids = CLKS_NR_MISC, .clk_regs = misc_clk_regs, .nr_clk_regs = ARRAY_SIZE(misc_clk_regs), + .sysreg_clk_regs = dcrg_memclk_sysreg, + .nr_sysreg_clk_regs = ARRAY_SIZE(dcrg_memclk_sysreg), .clk_name = "bus", + .auto_clock_gate = true, + .gate_dbg_offset = GS101_GATE_DBG_OFFSET, + .option_offset = MISC_CMU_MISC_CONTROLLER_OPTION, + .drcg_offset = GS101_DRCG_EN_OFFSET, + .memclk_offset = GS101_MEMCLK_OFFSET, };static void __init gs101_cmu_misc_init (struct device_node *np)
@@ -4010,6 +4049,10 @@ static const struct samsung_gate_clock peric0_gate_clks[] __initconst = { 21, 0, 0), }; +static const unsigned long dcrg_sysreg[]__initconst = { +GS101_DRCG_EN_OFFSET , +}; +static const struct samsung_cmu_info peric0_cmu_info__initconst = { .mux_clks = peric0_mux_clks, .nr_mux_clks =ARRAY_SIZE (peric0_mux_clks),
@@ -4020,7 +4063,13 @@ static const struct samsung_cmu_info peric0_cmu_info __initconst = { .nr_clk_ids = CLKS_NR_PERIC0, .clk_regs = peric0_clk_regs, .nr_clk_regs = ARRAY_SIZE(peric0_clk_regs), + .sysreg_clk_regs = dcrg_sysreg, + .nr_sysreg_clk_regs = ARRAY_SIZE(dcrg_sysreg), .clk_name = "bus", + .auto_clock_gate = true, + .gate_dbg_offset = GS101_GATE_DBG_OFFSET, + .option_offset = PERIC0_CMU_PERIC0_CONTROLLER_OPTION, + .drcg_offset = GS101_DRCG_EN_OFFSET, };/* ---- CMU_PERIC1 ---------------------------------------------------------- */
@@ -4368,7 +4417,13 @@ static const struct samsung_cmu_info peric1_cmu_info __initconst = { .nr_clk_ids = CLKS_NR_PERIC1, .clk_regs = peric1_clk_regs, .nr_clk_regs = ARRAY_SIZE(peric1_clk_regs), + .sysreg_clk_regs = dcrg_sysreg, + .nr_sysreg_clk_regs = ARRAY_SIZE(dcrg_sysreg), .clk_name = "bus", + .auto_clock_gate = true, + .gate_dbg_offset = GS101_GATE_DBG_OFFSET, + .option_offset = PERIC1_CMU_PERIC1_CONTROLLER_OPTION, + .drcg_offset = GS101_DRCG_EN_OFFSET, };/* ---- platform_driver ----------------------------------------------------- */
Signature · 1 line
2.52.0.351.gbe84eed79e-goog