Introduce MediaTek CCI devfreq driver
v6 cover Introduce MediaTek CCI devfreq driver
The Cache Coherent Interconnect (CCI) is the management of cache coherency by hardware. CCI DEVFREQ is DVFS driver for power saving by scaling clock frequency and supply voltage of CCI. CCI uses the same input clock source and power rail as LITTLE CPUs on Mediatek SoCs.
This series depends on:
Chanwoo's repo: kernel/git/chanwoo/linux.git
branch: devfreq-testing
[1]: PM / devfreq: Export devfreq_get_freq_range symbol within devfreq [2]: PM / devfreq: Add cpu based scaling support to passive governor [3]: PM / devfreq: passive: Reduce duplicate code when passive_devfreq case [4]: PM / devfreq: passive: Update frequency when start governor
Changes in v6:
- Remove unnecessary "goto" statement.
Changes in v5:
- Modify some binding description.
- Remove pre_voltage member.
- Not to enable/disable intermediate clock.
- Not to "put" resources that using devm_ variants.
Resend v4:
- CC interconnect maintainer.
- Change sign-off sequence in commit message.
Changes in v4:
- Add a maintainer in the binding document.
- Modify clock description.
- Add binding document into MAINTAINERS.
- Replace format specifier %d with %ld.
Changes in v3:
- Move binding document to 'interconnect' and rename it.
- Add COMPILE_TEST dependence symbol.
- Remove need_voltage_tracking variable.
- Move mtk_ccifreq_voltage_tracking() code into mtk_ccifreq_set_voltage().
- Add an interation limit in the while() loop.
- Replace 'cci_dev' with 'dev'
- Replace old_* with pre_*
- Remove of_match_ptr()
- Use module_platform_driver()
Changes in v2:
- Take MT8183 as example in binding document.
- Use dev_err() instead of pr_err().
- Use 'goto' statement to handle error case.
- Clean up driver code.
Johnson Wang (2):
dt-bindings: interconnect: Add MediaTek CCI dt-bindings PM / devfreq: mediatek: Introduce MediaTek CCI devfreq driver
.../bindings/interconnect/mediatek,cci.yaml | 140 ++++++ MAINTAINERS | 1 + drivers/devfreq/Kconfig | 10 + drivers/devfreq/Makefile | 1 + drivers/devfreq/mtk-cci-devfreq.c | 474 ++++++++++++++++++ 5 files changed, 626 insertions(+) create mode 100644 Documentation/devicetree/bindings/interconnect/mediatek,cci.yaml create mode 100644 drivers/devfreq/mtk-cci-devfreq.c
Signature · 1 line
2.18.0
PATCH v6 1/2 dt-bindings: interconnect: Add MediaTek CCI dt-bindings
Add devicetree binding of MediaTek CCI on MT8183 and MT8186.
--- .../bindings/interconnect/mediatek,cci.yaml | 141 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 142 insertions(+) create mode 100644 Documentation/devicetree/bindings/interconnect/mediatek,cci.yaml
Documentation/devicetree/bindings/interconnect/mediatek,cci.yaml new file +141 -0
@@ -0,0 +1,141 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/interconnect/mediatek,cci.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek Cache Coherent Interconnect (CCI) frequency and voltage scaling + +maintainers: + - Jia-Wei Chang <[email protected]> + - Johnson Wang <[email protected]> + +description: | + MediaTek Cache Coherent Interconnect (CCI) is a hardware engine used by + MT8183 and MT8186 SoCs to scale the frequency and adjust the voltage in + hardware. It can also optimize the voltage to reduce the power consumption. + +properties: + compatible: + enum: + - mediatek,mt8183-cci + - mediatek,mt8186-cci + + clocks: + items: + - description: + The multiplexer for clock input of the bus. + - description: + A parent of "bus" clock which is used as an intermediate clock source + when the original clock source (PLL) is under transition and not + stable yet. + + clock-names: + items: + - const: cci + - const: intermediate + + operating-points-v2: true + opp-table: true + + proc-supply: + description: + Phandle of the regulator for CCI that provides the supply voltage. + + sram-supply: + description: + Phandle of the regulator for sram of CCI that provides the supply + voltage. When it is present, the implementation needs to do + "voltage tracking" to step by step scale up/down Vproc and Vsram to fit + SoC specific needs. When absent, the voltage scaling flow is handled by + hardware, hence no software "voltage tracking" is needed. + +required: + - compatible + - clocks + - clock-names + - operating-points-v2 + - proc-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/mt8183-clk.h> + cci: cci { + compatible = "mediatek,mt8183-cci"; + clocks = <&mcucfg CLK_MCU_BUS_SEL>, + <&topckgen CLK_TOP_ARMPLL_DIV_PLL1>; + clock-names = "cci", "intermediate"; + operating-points-v2 = <&cci_opp>; + proc-supply = <&mt6358_vproc12_reg>; + }; + + cci_opp: opp-table-cci { + compatible = "operating-points-v2"; + opp-shared; + opp2_00: opp-273000000 { + opp-hz = /bits/ 64 <273000000>; + opp-microvolt = <650000>; + }; + opp2_01: opp-338000000 { + opp-hz = /bits/ 64 <338000000>; + opp-microvolt = <687500>; + }; + opp2_02: opp-403000000 { + opp-hz = /bits/ 64 <403000000>; + opp-microvolt = <718750>; + }; + opp2_03: opp-463000000 { + opp-hz = /bits/ 64 <463000000>; + opp-microvolt = <756250>; + }; + opp2_04: opp-546000000 { + opp-hz = /bits/ 64 <546000000>; + opp-microvolt = <800000>; + }; + opp2_05: opp-624000000 { + opp-hz = /bits/ 64 <624000000>; + opp-microvolt = <818750>; + }; + opp2_06: opp-689000000 { + opp-hz = /bits/ 64 <689000000>; + opp-microvolt = <850000>; + }; + opp2_07: opp-767000000 { + opp-hz = /bits/ 64 <767000000>; + opp-microvolt = <868750>; + }; + opp2_08: opp-845000000 { + opp-hz = /bits/ 64 <845000000>; + opp-microvolt = <893750>; + }; + opp2_09: opp-871000000 { + opp-hz = /bits/ 64 <871000000>; + opp-microvolt = <906250>; + }; + opp2_10: opp-923000000 { + opp-hz = /bits/ 64 <923000000>; + opp-microvolt = <931250>; + }; + opp2_11: opp-962000000 { + opp-hz = /bits/ 64 <962000000>; + opp-microvolt = <943750>; + }; + opp2_12: opp-1027000000 { + opp-hz = /bits/ 64 <1027000000>; + opp-microvolt = <975000>; + }; + opp2_13: opp-1092000000 { + opp-hz = /bits/ 64 <1092000000>; + opp-microvolt = <1000000>; + }; + opp2_14: opp-1144000000 { + opp-hz = /bits/ 64 <1144000000>; + opp-microvolt = <1025000>; + }; + opp2_15: opp-1196000000 { + opp-hz = /bits/ 64 <1196000000>; + opp-microvolt = <1050000>; + }; + };
MAINTAINERS +1 -0
@@ -5735,6 +5735,7 @@ L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git F: Documentation/devicetree/bindings/devfreq/ +F: Documentation/devicetree/bindings/interconnect/mediatek,cci.yaml F: drivers/devfreq/ F: include/linux/devfreq.h F: include/trace/events/devfreq.h
Signature · 1 line
2.18.0
Re: [PATCH v6 1/2] dt-bindings: interconnect: Add MediaTek CCI dt-bindings
Il 27/05/22 13:00, Johnson Wang ha scritto:
Quoted 7 lines
Add devicetree binding of MediaTek CCI on MT8183 and MT8186.
Signed-off-by Jia-Wei Chang <[email protected]>Signed-off-by Johnson Wang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>Acked-by Chanwoo Choi <[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>
Chanwoo Choi
maintainerRe: [PATCH v6 1/2] dt-bindings: interconnect: Add MediaTek CCI dt-bindings
In reply to Johnson WangHi Georgi,
If you agree this dt-bidning into .../bindings/interconnect, I'll merge it. Could you please review it?
Quoted 173 lines · Johnson Wang
Add devicetree binding of MediaTek CCI on MT8183 and MT8186.
Signed-off-by Jia-Wei Chang <[email protected]>Signed-off-by Johnson Wang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>Acked-by Chanwoo Choi <[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>--- .../bindings/interconnect/mediatek,cci.yaml | 141 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 142 insertions(+) create mode 100644 Documentation/devicetree/bindings/interconnect/mediatek,cci.yamlDocumentation/devicetree/bindings/interconnect/mediatek,cci.yaml new file +141
-0@@ -0,0 +1,141 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: https://protect2.fireeye.com/v1/url?k=ad4ad61b-cc317c8c-ad4b5d54-74fe4860001d-01f34b7b1b45f9dd&q=1&e=81fe0992-6204-4794-b412-8ba4ca747e10&u=http%3A%2F%2Fdevicetree.org%2Fschemas%2Finterconnect%2Fmediatek%2Ccci.yaml%23 +$schema: https://protect2.fireeye.com/v1/url?k=a032f6c0-c1495c57-a0337d8f-74fe4860001d-83ce1b32f63b7f35&q=1&e=81fe0992-6204-4794-b412-8ba4ca747e10&u=http%3A%2F%2Fdevicetree.org%2Fmeta-schemas%2Fcore.yaml%23 + +title: MediaTek Cache Coherent Interconnect (CCI) frequency and voltage scaling + +maintainers: + - Jia-Wei Chang <[email protected]> + - Johnson Wang <[email protected]> + +description: | + MediaTek Cache Coherent Interconnect (CCI) is a hardware engine used by + MT8183 and MT8186 SoCs to scale the frequency and adjust the voltage in + hardware. It can also optimize the voltage to reduce the power consumption. + +properties: + compatible: + enum: + - mediatek,mt8183-cci + - mediatek,mt8186-cci + + clocks: + items: + - description: + The multiplexer for clock input of the bus. + - description: + A parent of "bus" clock which is used as an intermediate clock source + when the original clock source (PLL) is under transition and not + stable yet. + + clock-names: + items: + - const: cci + - const: intermediate + + operating-points-v2: true + opp-table: true + + proc-supply: + description: + Phandle of the regulator for CCI that provides the supply voltage. + + sram-supply: + description: + Phandle of the regulator for sram of CCI that provides the supply + voltage. When it is present, the implementation needs to do + "voltage tracking" to step by step scale up/down Vproc and Vsram to fit + SoC specific needs. When absent, the voltage scaling flow is handled by + hardware, hence no software "voltage tracking" is needed. + +required: + - compatible + - clocks + - clock-names + - operating-points-v2 + - proc-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/mt8183-clk.h> + cci: cci { + compatible = "mediatek,mt8183-cci"; + clocks = <&mcucfg CLK_MCU_BUS_SEL>, + <&topckgen CLK_TOP_ARMPLL_DIV_PLL1>; + clock-names = "cci", "intermediate"; + operating-points-v2 = <&cci_opp>; + proc-supply = <&mt6358_vproc12_reg>; + }; + + cci_opp: opp-table-cci { + compatible = "operating-points-v2"; + opp-shared; + opp2_00: opp-273000000 { + opp-hz = /bits/ 64 <273000000>; + opp-microvolt = <650000>; + }; + opp2_01: opp-338000000 { + opp-hz = /bits/ 64 <338000000>; + opp-microvolt = <687500>; + }; + opp2_02: opp-403000000 { + opp-hz = /bits/ 64 <403000000>; + opp-microvolt = <718750>; + }; + opp2_03: opp-463000000 { + opp-hz = /bits/ 64 <463000000>; + opp-microvolt = <756250>; + }; + opp2_04: opp-546000000 { + opp-hz = /bits/ 64 <546000000>; + opp-microvolt = <800000>; + }; + opp2_05: opp-624000000 { + opp-hz = /bits/ 64 <624000000>; + opp-microvolt = <818750>; + }; + opp2_06: opp-689000000 { + opp-hz = /bits/ 64 <689000000>; + opp-microvolt = <850000>; + }; + opp2_07: opp-767000000 { + opp-hz = /bits/ 64 <767000000>; + opp-microvolt = <868750>; + }; + opp2_08: opp-845000000 { + opp-hz = /bits/ 64 <845000000>; + opp-microvolt = <893750>; + }; + opp2_09: opp-871000000 { + opp-hz = /bits/ 64 <871000000>; + opp-microvolt = <906250>; + }; + opp2_10: opp-923000000 { + opp-hz = /bits/ 64 <923000000>; + opp-microvolt = <931250>; + }; + opp2_11: opp-962000000 { + opp-hz = /bits/ 64 <962000000>; + opp-microvolt = <943750>; + }; + opp2_12: opp-1027000000 { + opp-hz = /bits/ 64 <1027000000>; + opp-microvolt = <975000>; + }; + opp2_13: opp-1092000000 { + opp-hz = /bits/ 64 <1092000000>; + opp-microvolt = <1000000>; + }; + opp2_14: opp-1144000000 { + opp-hz = /bits/ 64 <1144000000>; + opp-microvolt = <1025000>; + }; + opp2_15: opp-1196000000 { + opp-hz = /bits/ 64 <1196000000>; + opp-microvolt = <1050000>; + }; + };MAINTAINERS +1
-0@@ -5735,6 +5735,7 @@ L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git F: Documentation/devicetree/bindings/devfreq/ +F: Documentation/devicetree/bindings/interconnect/mediatek,cci.yaml F: drivers/devfreq/ F: include/linux/devfreq.h F: include/trace/events/devfreq.h
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Re: [PATCH v6 1/2] dt-bindings: interconnect: Add MediaTek CCI dt-bindings
Quoted 13 lines · Chanwoo Choi
Hi Georgi,
If you agree this dt-bidning into .../bindings/interconnect, I'll merge it. Could you please review it?
Quoted 7 lines · Johnson Wang
Add devicetree binding of MediaTek CCI on MT8183 and MT8186.
Signed-off-by Jia-Wei Chang <[email protected]>Signed-off-by Johnson Wang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>Acked-by Chanwoo Choi <[email protected]>Reviewed-by Chen-Yu Tsai <[email protected]>
Looks good to me. Thanks!
BR,
Georgi
Quoted 168 lines
Quoted 166 lines
--- .../bindings/interconnect/mediatek,cci.yaml | 141 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 142 insertions(+)create mode 100644
Documentation/devicetree/bindings/interconnect/mediatek,cci.yamlDocumentation/devicetree/bindings/interconnect/mediatek,cci.yaml new file +141
-0@@ -0,0 +1,141 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: https://protect2.fireeye.com/v1/url?k=ad4ad61b-cc317c8c-ad4b5d54-74fe4860001d-01f34b7b1b45f9dd&q=1&e=81fe0992-6204-4794-b412-8ba4ca747e10&u=http%3A%2F%2Fdevicetree.org%2Fschemas%2Finterconnect%2Fmediatek%2Ccci.yaml%23 +$schema: https://protect2.fireeye.com/v1/url?k=a032f6c0-c1495c57-a0337d8f-74fe4860001d-83ce1b32f63b7f35&q=1&e=81fe0992-6204-4794-b412-8ba4ca747e10&u=http%3A%2F%2Fdevicetree.org%2Fmeta-schemas%2Fcore.yaml%23 + +title: MediaTek Cache Coherent Interconnect (CCI) frequency and voltage scaling + +maintainers: + - Jia-Wei Chang <[email protected]> + - Johnson Wang <[email protected]> + +description: | + MediaTek Cache Coherent Interconnect (CCI) is a hardware engine used by + MT8183 and MT8186 SoCs to scale the frequency and adjust the voltage in + hardware. It can also optimize the voltage to reduce the power consumption. + +properties: + compatible: + enum: + - mediatek,mt8183-cci + - mediatek,mt8186-cci + + clocks: + items: + - description: + The multiplexer for clock input of the bus. + - description: + A parent of "bus" clock which is used as an intermediate clock source + when the original clock source (PLL) is under transition and not + stable yet. + + clock-names: + items: + - const: cci + - const: intermediate + + operating-points-v2: true + opp-table: true + + proc-supply: + description: + Phandle of the regulator for CCI that provides the supply voltage. + + sram-supply: + description: + Phandle of the regulator for sram of CCI that provides the supply + voltage. When it is present, the implementation needs to do + "voltage tracking" to step by step scale up/down Vproc and Vsram to fit + SoC specific needs. When absent, the voltage scaling flow is handled by + hardware, hence no software "voltage tracking" is needed. + +required: + - compatible + - clocks + - clock-names + - operating-points-v2 + - proc-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/mt8183-clk.h> + cci: cci { + compatible = "mediatek,mt8183-cci"; + clocks = <&mcucfg CLK_MCU_BUS_SEL>, + <&topckgen CLK_TOP_ARMPLL_DIV_PLL1>; + clock-names = "cci", "intermediate"; + operating-points-v2 = <&cci_opp>; + proc-supply = <&mt6358_vproc12_reg>; + }; + + cci_opp: opp-table-cci { + compatible = "operating-points-v2"; + opp-shared; + opp2_00: opp-273000000 { + opp-hz = /bits/ 64 <273000000>; + opp-microvolt = <650000>; + }; + opp2_01: opp-338000000 { + opp-hz = /bits/ 64 <338000000>; + opp-microvolt = <687500>; + }; + opp2_02: opp-403000000 { + opp-hz = /bits/ 64 <403000000>; + opp-microvolt = <718750>; + }; + opp2_03: opp-463000000 { + opp-hz = /bits/ 64 <463000000>; + opp-microvolt = <756250>; + }; + opp2_04: opp-546000000 { + opp-hz = /bits/ 64 <546000000>; + opp-microvolt = <800000>; + }; + opp2_05: opp-624000000 { + opp-hz = /bits/ 64 <624000000>; + opp-microvolt = <818750>; + }; + opp2_06: opp-689000000 { + opp-hz = /bits/ 64 <689000000>; + opp-microvolt = <850000>; + }; + opp2_07: opp-767000000 { + opp-hz = /bits/ 64 <767000000>; + opp-microvolt = <868750>; + }; + opp2_08: opp-845000000 { + opp-hz = /bits/ 64 <845000000>; + opp-microvolt = <893750>; + }; + opp2_09: opp-871000000 { + opp-hz = /bits/ 64 <871000000>; + opp-microvolt = <906250>; + }; + opp2_10: opp-923000000 { + opp-hz = /bits/ 64 <923000000>; + opp-microvolt = <931250>; + }; + opp2_11: opp-962000000 { + opp-hz = /bits/ 64 <962000000>; + opp-microvolt = <943750>; + }; + opp2_12: opp-1027000000 { + opp-hz = /bits/ 64 <1027000000>; + opp-microvolt = <975000>; + }; + opp2_13: opp-1092000000 { + opp-hz = /bits/ 64 <1092000000>; + opp-microvolt = <1000000>; + }; + opp2_14: opp-1144000000 { + opp-hz = /bits/ 64 <1144000000>; + opp-microvolt = <1025000>; + }; + opp2_15: opp-1196000000 { + opp-hz = /bits/ 64 <1196000000>; + opp-microvolt = <1050000>; + }; + };MAINTAINERS +1
-0@@ -5735,6 +5735,7 @@ L: [email protected] S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git F: Documentation/devicetree/bindings/devfreq/ +F: Documentation/devicetree/bindings/interconnect/mediatek,cci.yaml F: drivers/devfreq/ F: include/linux/devfreq.h F: include/trace/events/devfreq.h
PATCH v6 2/2 PM / devfreq: mediatek: Introduce MediaTek CCI devfreq driver
In reply to Johnson WangWe introduce a devfreq driver for the MediaTek Cache Coherent Interconnect (CCI) used by some MediaTek SoCs.
In this driver, we use the passive devfreq driver to get target frequencies and adjust voltages accordingly. In MT8183 and MT8186, the MediaTek CCI is supplied by the same regulators with the little core CPUs.
---
This patch depends on "devfreq-testing"[1]. [1]https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git/log/?h=devfreq-testing
--- drivers/devfreq/Kconfig | 10 + drivers/devfreq/Makefile | 1 + drivers/devfreq/mtk-cci-devfreq.c | 441 ++++++++++++++++++++++++++++++ 3 files changed, 452 insertions(+) create mode 100644 drivers/devfreq/mtk-cci-devfreq.c
drivers/devfreq/Kconfig +10 -0
@@ -120,6 +120,16 @@ config ARM_TEGRA_DEVFREQ It reads ACTMON counters of memory controllers and adjusts the operating frequencies and voltages with OPP support. +config ARM_MEDIATEK_CCI_DEVFREQ + tristate "MEDIATEK CCI DEVFREQ Driver" + depends on ARM_MEDIATEK_CPUFREQ || COMPILE_TEST + select DEVFREQ_GOV_PASSIVE + help + This adds a devfreq driver for MediaTek Cache Coherent Interconnect + which is shared the same regulators with the cpu cluster. It can track + buck voltages and update a proper CCI frequency. Use the notification + to get the regulator status. + config ARM_RK3399_DMC_DEVFREQ tristate "ARM RK3399 DMC DEVFREQ Driver" depends on (ARCH_ROCKCHIP && HAVE_ARM_SMCCC) || \
drivers/devfreq/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.o obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o obj-$(CONFIG_ARM_IMX_BUS_DEVFREQ) += imx-bus.o obj-$(CONFIG_ARM_IMX8M_DDRC_DEVFREQ) += imx8m-ddrc.o +obj-$(CONFIG_ARM_MEDIATEK_CCI_DEVFREQ) += mtk-cci-devfreq.o obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o obj-$(CONFIG_ARM_SUN8I_A33_MBUS_DEVFREQ) += sun8i-a33-mbus.o obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o
drivers/devfreq/mtk-cci-devfreq.c new file +441 -0
441 lines not on this page · raw message
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH v6 2/2] PM / devfreq: mediatek: Introduce MediaTek CCI devfreq driver
Il 27/05/22 13:00, Johnson Wang ha scritto:
Quoted 64 lines
We introduce a devfreq driver for the MediaTek Cache Coherent Interconnect (CCI) used by some MediaTek SoCs.
In this driver, we use the passive devfreq driver to get target frequencies and adjust voltages accordingly. In MT8183 and MT8186, the MediaTek CCI is supplied by the same regulators with the little core CPUs.
Signed-off-by Jia-Wei Chang <[email protected]>Signed-off-by Johnson Wang <[email protected]>Acked-by Chanwoo Choi <[email protected]>---
This patch depends on "devfreq-testing"[1]. [1]https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git/log/?h=devfreq-testing--- drivers/devfreq/Kconfig | 10 + drivers/devfreq/Makefile | 1 + drivers/devfreq/mtk-cci-devfreq.c | 441 ++++++++++++++++++++++++++++++ 3 files changed, 452 insertions(+)create mode 100644
drivers/devfreq/mtk-cci-devfreq.cdrivers/devfreq/Kconfig +10
-0@@ -120,6 +120,16 @@ config ARM_TEGRA_DEVFREQ It reads ACTMON counters of memory controllers and adjusts the operating frequencies and voltages with OPP support. +config ARM_MEDIATEK_CCI_DEVFREQ + tristate "MEDIATEK CCI DEVFREQ Driver" + depends on ARM_MEDIATEK_CPUFREQ || COMPILE_TEST + select DEVFREQ_GOV_PASSIVE + help + This adds a devfreq driver for MediaTek Cache Coherent Interconnect + which is shared the same regulators with the cpu cluster. It can track + buck voltages and update a proper CCI frequency. Use the notification + to get the regulator status. + config ARM_RK3399_DMC_DEVFREQ tristate "ARM RK3399 DMC DEVFREQ Driver" depends on (ARCH_ROCKCHIP && HAVE_ARM_SMCCC) || \drivers/devfreq/Makefile +1
-0@@ -11,6 +11,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.o obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o obj-$(CONFIG_ARM_IMX_BUS_DEVFREQ) += imx-bus.o obj-$(CONFIG_ARM_IMX8M_DDRC_DEVFREQ) += imx8m-ddrc.o +obj-$(CONFIG_ARM_MEDIATEK_CCI_DEVFREQ) += mtk-cci-devfreq.o obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o obj-$(CONFIG_ARM_SUN8I_A33_MBUS_DEVFREQ) += sun8i-a33-mbus.o obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.odrivers/devfreq/mtk-cci-devfreq.c new file +5
-0@@ -0,0 +1,441 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022 MediaTek Inc. +*/ +
..snip..
Quoted 26 lines
drivers/devfreq/mtk-cci-devfreq.c new file +26
-0+}; + +static int mtk_ccifreq_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct mtk_ccifreq_drv *drv; +struct devfreq_passive_data *passive_data; +struct dev_pm_opp *opp; +unsigned long rate, opp_volt; +int ret; + + drv =devm_kzalloc (dev,sizeof (*drv),GFP_KERNEL ); +if (!drv) +return -ENOMEM ; + + drv->dev = dev; + drv->soc_data = (const struct mtk_ccifreq_platform_data *) +of_device_get_match_data (&pdev->dev); +mutex_init (&drv->reg_lock); +platform_set_drvdata (pdev, drv); + + drv->cci_clk =devm_clk_get (dev,"cci" ); +if (IS_ERR (drv->cci_clk)) { + ret =PTR_ERR (drv->cci_clk); +return dev_err_probe (dev, ret, +"failed to get cci clk: %d\n" , ret);
drivers/devfreq/mtk-cci-devfreq.c line 281
Quoted 10 lines
drivers/devfreq/mtk-cci-devfreq.c new file +10
-0+ } + + drv->inter_clk =devm_clk_get (dev,"intermediate" ); +if (IS_ERR (drv->inter_clk)) { + ret =PTR_ERR (drv->inter_clk); +return dev_err_probe (dev, ret, +"failed to get intermediate clk: %d\n" , ret); + } + + drv->proc_reg =devm_regulator_get_optional (dev,"proc" );
In the devicetree binding for this driver, the "proc" regulator is *not* optional, but here you're using devm_regulator_get_optional.
If this is not optional, you should use devm_regulator_get() instead.
drivers/devfreq/mtk-cci-devfreq.c line 285
Quoted 4 lines
drivers/devfreq/mtk-cci-devfreq.c new file +4
-0+if (IS_ERR (drv->proc_reg)) { + ret =PTR_ERR (drv->proc_reg); +return dev_err_probe (dev, ret, +"failed to get proc regulator: %d\n" , ret);
There's no need to print ret... dev_err_probe() takes care of that for you already:
in this case, you're printing the value of ret twice.
drivers/devfreq/mtk-cci-devfreq.c line 288
Quoted 3 lines
drivers/devfreq/mtk-cci-devfreq.c new file +3
-0+ } + + ret =regulator_enable (drv->proc_reg);
If you move this call after the devm_regulator_get_optional() call for the sram vreg, you will be able to use dev_err_probe for the latter as well.
drivers/devfreq/mtk-cci-devfreq.c line 290
Quoted 2 lines
drivers/devfreq/mtk-cci-devfreq.c new file +2
-0+if (ret) { +dev_err (dev,"failed to enable proc regulator\n" );
Why aren't you using dev_err_probe here, like you've done for the other instances?
drivers/devfreq/mtk-cci-devfreq.c line 296
Quoted 6 lines
drivers/devfreq/mtk-cci-devfreq.c new file +6
-0+return ret; + } + + drv->sram_reg =devm_regulator_get_optional (dev,"sram" ); +if (IS_ERR (drv->sram_reg)) + drv->sram_reg =NULL ;
When you use regulator_get_optional() (including the devm_ variant of it), you shall return an error, if there's any... that's what the _optional() is for.
if (IS_ERR(drv->sram_reg))
return dev_err_probe(dev, PTR_ERR(drv->proc_reg), "failed to get sram regulator");
drivers/devfreq/mtk-cci-devfreq.c line 304
Quoted 8 lines
drivers/devfreq/mtk-cci-devfreq.c new file +8
-0+else { + ret =regulator_enable (drv->sram_reg); +if (ret) { +dev_err (dev,"failed to enable sram regulator\n" ); + goto out_free_resources; + } + } +
Regards,
Angelo
Re: [PATCH v6 2/2] PM / devfreq: mediatek: Introduce MediaTek CCI devfreq driver
Quoted 123 lines · AngeloGioacchino Del Regno
Il 27/05/22 13:00, Johnson Wang ha scritto:
Quoted 76 lines
We introduce a devfreq driver for the MediaTek Cache Coherent Interconnect
(CCI) used by some MediaTek SoCs.In this driver, we use the passive devfreq driver to get target frequencies
and adjust voltages accordingly. In MT8183 and MT8186, the MediaTek CCI
is supplied by the same regulators with the little core CPUs.Signed-off-by Jia-Wei Chang <[email protected]>Signed-off-by Johnson Wang <[email protected]>Acked-by Chanwoo Choi <[email protected]>---
This patch depends on "devfreq-testing"[1].
[1]
https://urldefense.com/v3/__https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git/log/?h=devfreq-testing__;!!CTRNKA9wMg0ARbw!2ldxtrMmK2WJP8_r1DcJRm0XQOSZQJfbI5DlNDPEfz84Ble0R7pSP7PbYLreNgVGRyFfDQ$--- drivers/devfreq/Kconfig | 10 + drivers/devfreq/Makefile | 1 + drivers/devfreq/mtk-cci-devfreq.c | 441 ++++++++++++++++++++++++++++++ 3 files changed, 452 insertions(+)create mode 100644
drivers/devfreq/mtk-cci-devfreq.cdrivers/devfreq/Kconfig +0
-0@@ -120,6 +120,16 @@ config ARM_TEGRA_DEVFREQ It reads ACTMON counters of memory controllers and adjuststhe
operating frequencies and voltages with OPP support.drivers/devfreq/Kconfig +6
-0+config ARM_MEDIATEK_CCI_DEVFREQ + tristate "MEDIATEK CCI DEVFREQ Driver" + depends on ARM_MEDIATEK_CPUFREQ || COMPILE_TEST + select DEVFREQ_GOV_PASSIVE + help + This adds a devfreq driver for MediaTek Cache CoherentInterconnect
drivers/devfreq/Kconfig +1
-0+ which is shared the same regulators with the cpu cluster. Itcan track
drivers/devfreq/Kconfig +1
-0+ buck voltages and update a proper CCI frequency. Use thenotification
drivers/devfreq/Kconfig +2
-0+ to get the regulator status. + config ARM_RK3399_DMC_DEVFREQ tristate "ARM RK3399 DMC DEVFREQ Driver" depends on (ARCH_ROCKCHIP && HAVE_ARM_SMCCC) || \drivers/devfreq/Makefile +0
-0@@ -11,6 +11,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) +=governor_passive.o
obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o
obj-$(CONFIG_ARM_IMX_BUS_DEVFREQ) += imx-bus.o
obj-$(CONFIG_ARM_IMX8M_DDRC_DEVFREQ) += imx8m-ddrc.odrivers/devfreq/Makefile +1
-0+obj-$(CONFIG_ARM_MEDIATEK_CCI_DEVFREQ) += mtk-cci-devfreq.o obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o obj-$(CONFIG_ARM_SUN8I_A33_MBUS_DEVFREQ) += sun8i-a33-mbus.o obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.odrivers/devfreq/mtk-cci-devfreq.c new file +5
-0@@ -0,0 +1,441 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022 MediaTek Inc. +*/ +..snip..
Quoted 35 lines
drivers/devfreq/mtk-cci-devfreq.c new file +26
-0+}; + +static int mtk_ccifreq_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct mtk_ccifreq_drv *drv; +struct devfreq_passive_data *passive_data; +struct dev_pm_opp *opp; +unsigned long rate, opp_volt; +int ret; + + drv =devm_kzalloc (dev,sizeof (*drv),GFP_KERNEL ); +if (!drv) +return -ENOMEM ; + + drv->dev = dev; + drv->soc_data = (const struct mtk_ccifreq_platform_data *) +of_device_get_match_data (&pdev->dev); +mutex_init (&drv->reg_lock); +platform_set_drvdata (pdev, drv); + + drv->cci_clk =devm_clk_get (dev,"cci" ); +if (IS_ERR (drv->cci_clk)) { + ret =PTR_ERR (drv->cci_clk); + return dev_err_probe(dev, ret, + "failed to get cci clk: %d\n",ret);
drivers/devfreq/mtk-cci-devfreq.c new file +7
-0+ } + + drv->inter_clk =devm_clk_get (dev,"intermediate" ); +if (IS_ERR (drv->inter_clk)) { + ret =PTR_ERR (drv->inter_clk); + return dev_err_probe(dev, ret, + "failed to get intermediate clk:%d\n", ret);
drivers/devfreq/mtk-cci-devfreq.c line 281
Quoted 3 lines
drivers/devfreq/mtk-cci-devfreq.c new file +3
-0+ } + + drv->proc_reg =devm_regulator_get_optional (dev,"proc" );In the devicetree binding for this driver, the "proc" regulator is *not* optional,
but here you're usingdevm_regulator_get_optional.
Quoted 2 lines
If this is not optional, you should use
devm_regulator_get()instead.
Hi Angelo,
This is similiar case to mediatek-cpufreq.c [1].
Regulator framework has three variants of APIs for getting regulator handler.
We do NOT choose regulator_get_exclusive() because cpufreq and cci share with the same power rail.
We choose regulator_get_optional() so that we can handle error if it returns ERR_PTR(-ENODEV) rather than a dummy handler from regulator_get().
Please inform me if I get it wrong.
That's what I understand and you can refer to [2].
Thanks.
[1]: [email protected] [2]:
https://www.mail-archive.com/[email protected]/msg1327385.html
Quoted 54 lines
Quoted 5 lines
drivers/devfreq/mtk-cci-devfreq.c new file +4
-0+if (IS_ERR (drv->proc_reg)) { + ret =PTR_ERR (drv->proc_reg); + return dev_err_probe(dev, ret, + "failed to get proc regulator:%d\n", ret);
There's no need to print ret...
dev_err_probe()takes care of that for you already:
in this case, you're printing the value of ret twice.drivers/devfreq/mtk-cci-devfreq.c line 288
Quoted 3 lines
drivers/devfreq/mtk-cci-devfreq.c new file +3
-0+ } + + ret =regulator_enable (drv->proc_reg);If you move this call after the
devm_regulator_get_optional()call for the sram
vreg, you will be able to usedev_err_probefor the latter as well.drivers/devfreq/mtk-cci-devfreq.c line 290
Quoted 2 lines
drivers/devfreq/mtk-cci-devfreq.c new file +2
-0+if (ret) { +dev_err (dev,"failed to enable proc regulator\n" );Why aren't you using
dev_err_probehere, like you've done for the other instances?drivers/devfreq/mtk-cci-devfreq.c line 296
Quoted 6 lines
drivers/devfreq/mtk-cci-devfreq.c new file +6
-0+return ret; + } + + drv->sram_reg =devm_regulator_get_optional (dev,"sram" ); +if (IS_ERR (drv->sram_reg)) + drv->sram_reg =NULL ;When you use
regulator_get_optional()(including thedevm_variant of it), you
shall return an error, if there's any... that's what the_optional()is for.if (
IS_ERR(drv->sram_reg))return dev_err_probe(dev, PTR_ERR(drv->proc_reg), "failed to get sram regulator");drivers/devfreq/mtk-cci-devfreq.c line 304
Quoted 9 lines
drivers/devfreq/mtk-cci-devfreq.c new file +4
-0+else { + ret =regulator_enable (drv->sram_reg); +if (ret) { + dev_err(dev, "failed to enable sramregulator\n");
drivers/devfreq/mtk-cci-devfreq.c new file +4
-0+ goto out_free_resources; + } + } +Regards,
Angelo
Chanwoo Choi
maintainerRe: [PATCH v6 2/2] PM / devfreq: mediatek: Introduce MediaTek CCI devfreq driver
In reply to AngeloGioacchino Del RegnoQuoted 109 lines · AngeloGioacchino Del Regno
Il 27/05/22 13:00, Johnson Wang ha scritto:
Quoted 63 lines
We introduce a devfreq driver for the MediaTek Cache Coherent Interconnect (CCI) used by some MediaTek SoCs.
In this driver, we use the passive devfreq driver to get target frequencies and adjust voltages accordingly. In MT8183 and MT8186, the MediaTek CCI is supplied by the same regulators with the little core CPUs.
Signed-off-by Jia-Wei Chang <[email protected]>Signed-off-by Johnson Wang <[email protected]>Acked-by Chanwoo Choi <[email protected]>---
This patch depends on "devfreq-testing"[1]. [1]https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git/log/?h=devfreq-testing
---
drivers/devfreq/Kconfig | 10 +
drivers/devfreq/Makefile | 1 +drivers/devfreq/mtk-cci-devfreq.c| 441 ++++++++++++++++++++++++++++++3 files changed, 452 insertions(+)create mode 100644
drivers/devfreq/mtk-cci-devfreq.cdrivers/devfreq/Kconfig +0
-0@@ -120,6 +120,16 @@ config ARM_TEGRA_DEVFREQIt reads ACTMON counters of memory controllers and adjusts the operating frequencies and voltages with OPP support. +config
ARM_MEDIATEK_CCI_DEVFREQ
+ tristate "MEDIATEK CCI DEVFREQ Driver"
+ depends onARM_MEDIATEK_CPUFREQ||COMPILE_TEST
+ selectDEVFREQ_GOV_PASSIVE
+ help
+ This adds a devfreq driver for MediaTek Cache Coherent Interconnect + which is shared the same regulators with the cpu cluster. It can track + buck voltages and update a proper CCI frequency. Use the notification + to get the regulator status.
+
configARM_RK3399_DMC_DEVFREQ
tristate "ARM RK3399 DMC DEVFREQ Driver"
depends on (ARCH_ROCKCHIP&&HAVE_ARM_SMCCC) || \drivers/devfreq/Makefile +0
-0@@ -11,6 +11,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE) += governor_passive.oobj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ) += exynos-bus.o obj-$(CONFIG_ARM_IMX_BUS_DEVFREQ) += imx-bus.o obj-$(CONFIG_ARM_IMX8M_DDRC_DEVFREQ) += imx8m-ddrc.o +obj-$(CONFIG_ARM_MEDIATEK_CCI_DEVFREQ) += mtk-cci-devfreq.o obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ) += rk3399_dmc.o obj-$(CONFIG_ARM_SUN8I_A33_MBUS_DEVFREQ) += sun8i-a33-mbus.o obj-$(CONFIG_ARM_TEGRA_DEVFREQ) += tegra30-devfreq.o
drivers/devfreq/mtk-cci-devfreq.c new file +5
-0@@ -0,0 +1,441 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022 MediaTek Inc. +*/ +..snip..
Quoted 26 lines
drivers/devfreq/mtk-cci-devfreq.c new file +26
-0+}; + +static int mtk_ccifreq_probe (struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct mtk_ccifreq_drv *drv; + struct devfreq_passive_data *passive_data; + struct dev_pm_opp *opp; + unsigned long rate, opp_volt; + int ret; + + drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); + if (!drv) + return -ENOMEM; + + drv->dev = dev; + drv->soc_data = (const struct mtk_ccifreq_platform_data *) + of_device_get_match_data(&pdev->dev); + mutex_init(&drv->reg_lock); + platform_set_drvdata(pdev, drv); + + drv->cci_clk = devm_clk_get(dev, "cci"); + if (IS_ERR(drv->cci_clk)) { + ret = PTR_ERR(drv->cci_clk); + return dev_err_probe(dev, ret, + "failed to get cci clk: %d\n", ret);drivers/devfreq/mtk-cci-devfreq.c line 281
Quoted 10 lines
drivers/devfreq/mtk-cci-devfreq.c new file +10
-0+ } + + drv->inter_clk = devm_clk_get(dev, "intermediate"); + if (IS_ERR(drv->inter_clk)) { + ret = PTR_ERR(drv->inter_clk); + return dev_err_probe(dev, ret, + "failed to get intermediate clk: %d\n", ret); + } + + drv->proc_reg = devm_regulator_get_optional(dev, "proc");In the devicetree binding for this driver, the "proc" regulator is *not* optional, but here you're using
devm_regulator_get_optional.If this is not optional, you should use
devm_regulator_get()instead.
Quoted 8 lines
Quoted 4 lines
+ if (
IS_ERR(drv->proc_reg)) {
+ ret =PTR_ERR(drv->proc_reg);
+ return dev_err_probe(dev, ret,
+ "failed to get proc regulator: %d\n", ret);There's no need to print ret...
dev_err_probe()takes care of that for you already:
in this case, you're printing the value of ret twice.
I agree. better to remove the additional 'ret' printing from dev_err_probe.
Quoted 11 lines
Quoted 3 lines
+ }
+
+ ret =regulator_enable(drv->proc_reg);If you move this call after the
devm_regulator_get_optional()call for the sram vreg, you will be able to usedev_err_probefor the latter as well.Quoted 2 lines
+ if (ret) {
+dev_err(dev, "failed to enable proc regulator\n");Why aren't you using
dev_err_probehere, like you've done for the other instances?
dev_err is enough because it means that get to regulator instance via regulator_get_optional. If error from regulator_enable happen, it depends on the internal logic of pmic driver.
Quoted 24 lines
Quoted 7 lines
+ return ret;
+ }
+
+drv->sram_reg=devm_regulator_get_optional(dev, "sram"); + if (IS_ERR(drv->sram_reg))
+drv->sram_reg= NULL;When you use
regulator_get_optional()(including thedevm_variant of it), you shall return an error, if there's any... that's what the_optional()is for.if (
IS_ERR(drv->sram_reg))
returndev_err_probe(dev, PTR_ERR(drv->proc_reg), "failed to get sram regulator");Quoted 8 lines
+ else {
+ ret =regulator_enable(drv->sram_reg);
+ if (ret) {
+dev_err(dev, "failed to enable sram regulator\n"); + gotoout_free_resources;
+ }
+ }
+
Quoted 3 lines
Regards,
Angelo
Hi Johnson,
Thanks for your work. Before merge, better to remove the 'ret' printing from dev_err_probe above. I'll merge it.
Signature · 3 lines
Best Regards, Chanwoo Choi Samsung Electronics
Quoted 50 lines · Johnson Wang
The Cache Coherent Interconnect (CCI) is the management of cache coherency by hardware. CCI DEVFREQ is DVFS driver for power saving by scaling clock frequency and supply voltage of CCI. CCI uses the same input clock source and power rail as LITTLE CPUs on Mediatek SoCs.
This series depends on:
Chanwoo's repo:kernel/git/chanwoo/linux.git
branch: devfreq-testing
[1]: PM / devfreq: Exportdevfreq_get_freq_rangesymbol within devfreq [2]: PM / devfreq: Add cpu based scaling support to passive governor [3]: PM / devfreq: passive: Reduce duplicate code whenpassive_devfreqcase [4]: PM / devfreq: passive: Update frequency when start governorChanges in v6:
- Remove unnecessary "goto" statement.Changes in v5:
- Modify some binding description.
- Removepre_voltagemember.
- Not to enable/disable intermediate clock.
- Not to "put" resources that usingdevm_variants.Resend v4:
- CC interconnect maintainer.
- Change sign-off sequence in commit message.Changes in v4:
- Add a maintainer in the binding document.
- Modify clock description.
- Add binding document intoMAINTAINERS.
- Replace format specifier %d with %ld.Changes in v3:
- Move binding document to 'interconnect' and rename it.
- AddCOMPILE_TESTdependence symbol.
- Removeneed_voltage_trackingvariable.
- Movemtk_ccifreq_voltage_tracking()code intomtk_ccifreq_set_voltage().
- Add an interation limit in thewhile()loop.
- Replace 'cci_dev' with 'dev'
- Replace old_* with pre_*
- Removeof_match_ptr()
- Usemodule_platform_driver()Changes in v2:
- Take MT8183 as example in binding document.
- Usedev_err()instead ofpr_err().
- Use 'goto' statement to handle error case.
- Clean up driver code.
Quoted 3 lines
Johnson Wang (2):
dt-bindings: interconnect: Add MediaTek CCI dt-bindings PM / devfreq: mediatek: Introduce MediaTek CCI devfreq driver
FTR,