Skip to contentSkip to conversation

PM / AVS: SVS: Introduce SVS engine

PATCH Superseded Roger Lu 4 participants 12 messages Jan 7, 2020 – Apr 8, 2020

Subsystems (3)

v6 of 25 Superseded Latest is v25 →

lore
Share & tools
lore
author
#8 lore raw

PATCH v6 2/3 arm64: dts: mt8183: add svs device information

In reply to Roger Lu

add pmic/clock/irq/efuse setting in svs node

---
 arch/arm64/boot/dts/mediatek/mt8183-evb.dts | 16 ++++++++
 arch/arm64/boot/dts/mediatek/mt8183.dtsi    | 41 +++++++++++++++++++++
 2 files changed, 57 insertions(+)
arch/arm64/boot/dts/mediatek/mt8183-evb.dts +16 -0
index 1fb195c683c3..6ae1d9a1bcbf 100644
@@ -231,6 +231,22 @@
 
 };
 
+&svs_cpu_little {
+	vcpu-little-supply = <&mt6358_vproc12_reg>;
+};
+
+&svs_cpu_big {
+	vcpu-big-supply = <&mt6358_vproc11_reg>;
+};
+
+&svs_cci {
+	vcci-supply = <&mt6358_vproc12_reg>;
+};
+
+&svs_gpu {
+	vgpu-spply = <&mt6358_vgpu_reg>;
+};
+
 &uart0 {
 	status = "okay";
 };
arch/arm64/boot/dts/mediatek/mt8183.dtsi +41 -0

53 lines not on this page · raw message

Signature · 1 line
2.18.0

Roger Lu

author
#0 lore raw

1. SVS driver use OPP adjust event in [1] to update OPP table voltage part.
2. SVS dts node refers to CPU opp table [2] and GPU opp table [3].
3. SVS and thermal dts use the same thermal efuse [4].
4. SVS dts needs PMIC regulator [5].

[1] https://patchwork.kernel.org/patch/11193513/
[2] https://patchwork.kernel.org/patch/11304935/
[3] https://patchwork.kernel.org/patch/11132381/
[4] https://patchwork.kernel.org/patch/11316495/
[5] https://patchwork.kernel.org/patch/11284617/

changes since v5:
- Add CONFIG_NVMEM dependency in SVS Kconfig.
- Apply the latest dev_pm_opp_adjust_voltage() from [1] in SVS driver.
- Add dev_pm_opp_put(opp) after calling dev_pm_opp_get_voltage(opp).
- Fix multi-line comment style.
- Add #define w/bit for magic constants.
- Replace "int svs_is_supported()" with "bool svs_is_supported()".
- Use default/max size for allocating memories to opp_volts/init02_volts/volts/opp_freqs/freqs_pct in struct svs_bank.
- Name "main" instead of "main_clk" in SVS nodes for getting SVS clk.
- In SVS binding document, remove fourth parameter of GIC interrupts.
- Use '-' in node names.

Roger Lu (3):
dt-bindings: soc: add mtk svs dt-bindings
arm64: dts: mt8183: add svs device information
PM / AVS: SVS: Introduce SVS engine

 .../devicetree/bindings/power/mtk-svs.txt     |   76 +
 arch/arm64/boot/dts/mediatek/mt8183-evb.dts   |   16 +
 arch/arm64/boot/dts/mediatek/mt8183.dtsi      |   41 +
 drivers/power/avs/Kconfig                     |   10 +
 drivers/power/avs/Makefile                    |    1 +
 drivers/power/avs/mtk_svs.c                   | 2075 +++++++++++++++++
 include/linux/power/mtk_svs.h                 |   23 +
 7 files changed, 2242 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/mtk-svs.txt
 create mode 100644 drivers/power/avs/mtk_svs.c
 create mode 100644 include/linux/power/mtk_svs.h
author
#1 lore raw

PATCH v6 1/3 dt-bindings: soc: add mtk svs dt-bindings

Document the binding for enabling mtk svs on MediaTek SoC.

---
 .../devicetree/bindings/power/mtk-svs.txt     | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/mtk-svs.txt
Documentation/devicetree/bindings/power/mtk-svs.txt new file +76 -0
new file mode 100644
index 000000000000..9a3e81b9e1d2
@@ -0,0 +1,76 @@
+* Mediatek Smart Voltage Scaling (MTK SVS)
+
+This describes the device tree binding for the MTK SVS controller (bank)
+which helps provide the optimized CPU/GPU/CCI voltages. This device also
+needs thermal data to calculate thermal slope for accurately compensate
+the voltages when temperature change.
+
+Required properties:
+- compatible:
+  - "mediatek,mt8183-svs" : For MT8183 family of SoCs
+- reg: Address range of the MTK SVS controller.
+- interrupts: IRQ for the MTK SVS controller.
+- clocks, clock-names: Clocks needed for the svs hardware. required
+                       clocks are:
+		       "main": Main clock for svs controller to work.
+- nvmem-cells: Phandle to the calibration data provided by a nvmem device.
+- nvmem-cell-names: Should be "svs-calibration-data" and "calibration-data"
+
+Subnodes:
+- svs-cpu-little: SVS bank device node of little CPU
+  compatible: "mediatek,mt8183-svs-cpu-little"
+  operating-points-v2: OPP table hooked by SVS little CPU bank.
+		       SVS will optimze this OPP table voltage part.
+  vcpu-little-supply: PMIC buck of little CPU
+- svs-cpu-big: SVS bank device node of big CPU
+  compatible: "mediatek,mt8183-svs-cpu-big"
+  operating-points-v2: OPP table hooked by SVS big CPU bank.
+		       SVS will optimze this OPP table voltage part.
+  vcpu-big-supply: PMIC buck of big CPU
+- svs-cci: SVS bank device node of CCI
+  compatible: "mediatek,mt8183-svs-cci"
+  operating-points-v2: OPP table hooked by SVS CCI bank.
+		       SVS will optimze this OPP table voltage part.
+  vcci-supply: PMIC buck of CCI
+- svs-gpu: SVS bank device node of GPU
+  compatible: "mediatek,mt8183-svs-gpu"
+  operating-points-v2: OPP table hooked by SVS GPU bank.
+		       SVS will optimze this OPP table voltage part.
+  vgpu-supply: PMIC buck of GPU
+
+Example:
+
+	svs: svs@1100b000 {
+		compatible = "mediatek,mt8183-svs";
+		reg = <0 0x1100b000 0 0x1000>;
+		interrupts = <GIC_SPI 127 IRQ_TYPE_LEVEL_LOW>;
+		clocks = <&infracfg CLK_INFRA_THERM>;
+		clock-names = "main_clk";
+		nvmem-cells = <&svs_calibration>, <&thermal_calibration>;
+		nvmem-cell-names = "svs-calibration-data", "calibration-data";
+
+		svs_cpu_little: svs-cpu-little {
+			compatible = "mediatek,mt8183-svs-cpu-little";
+			operating-points-v2 = <&cluster0_opp>;
+			vcpu-little-supply = <&mt6358_vproc12_reg>;
+		};
+
+		svs_cpu_big: svs-cpu-big {
+			compatible = "mediatek,mt8183-svs-cpu-big";
+			operating-points-v2 = <&cluster1_opp>;
+			vcpu-big-supply = <&mt6358_vproc11_reg>;
+		};
+
+		svs_cci: svs-cci {
+			compatible = "mediatek,mt8183-svs-cci";
+			operating-points-v2 = <&cci_opp>;
+			vcci-supply = <&mt6358_vproc12_reg>;
+		};
+
+		svs_gpu: svs-gpu {
+			compatible = "mediatek,mt8183-svs-gpu";
+			power-domains = <&scpsys MT8183_POWER_DOMAIN_MFG_2D>;
+			operating-points-v2 = <&gpu_opp_table>;
+			vgpu-spply = <&mt6358_vgpu_reg>;
+		};
+	};
Signature · 1 line
2.18.0
author
#9 lore raw

PATCH v6 3/3 PM / AVS: SVS: Introduce SVS engine

In reply to Roger Lu

The SVS (Smart Voltage Scaling) engine is a piece of hardware which is used to calculate optimized voltage values of several power domains, e.g. CPU/GPU/CCI, according to chip process corner, temperatures, and other factors. Then DVFS driver could apply those optimized voltage values to reduce power consumption.

---
 drivers/power/avs/Kconfig     |   10 +
 drivers/power/avs/Makefile    |    1 +
 drivers/power/avs/mtk_svs.c   | 2075 +++++++++++++++++++++++++++++++++
 include/linux/power/mtk_svs.h |   23 +
 4 files changed, 2109 insertions(+)
 create mode 100644 drivers/power/avs/mtk_svs.c
 create mode 100644 include/linux/power/mtk_svs.h
drivers/power/avs/Kconfig +10 -0
index 089b6244b716..ba9d296bbdc1 100644
@@ -19,3 +19,13 @@ config ROCKCHIP_IODOMAIN
 	  Say y here to enable support io domains on Rockchip SoCs. It is
 	  necessary for the io domain setting of the SoC to match the
 	  voltage supplied by the regulators.
+
+config MTK_SVS
+	bool "MediaTek Smart Voltage Scaling(SVS)"
+	depends on POWER_AVS && MTK_EFUSE && NVMEM
+	help
+	  The SVS engine is a piece of hardware which is used to calculate
+	  optimized voltage values of several power domains, e.g.
+	  CPU clusters/GPU/CCI, according to chip process corner, temperatures,
+	  and other factors. Then DVFS driver could apply those optimized voltage
+	  values to reduce power consumption.
drivers/power/avs/Makefile +1 -0
index a1b8cd453f19..57246b977a93 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_POWER_AVS_OMAP)		+= smartreflex.o
 obj-$(CONFIG_ROCKCHIP_IODOMAIN)		+= rockchip-io-domain.o
+obj-$(CONFIG_MTK_SVS)			+= mtk_svs.o
drivers/power/avs/mtk_svs.c new file +2075 -0

2,075 lines not on this page · raw message

include/linux/power/mtk_svs.h new file +23 -0
new file mode 100644
index 000000000000..5c03982e3576
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright (C) 2020 MediaTek Inc.
+ */
+
+#ifndef __MTK_SVS_H__
+#define __MTK_SVS_H__
+
+#if IS_ENABLED(CONFIG_MTK_SVS)
+unsigned long claim_mtk_svs_lock(void);
+void release_mtk_svs_lock(unsigned long flags);
+#else
+static inline unsigned long claim_mtk_svs_lock(void)
+{
+	return 0;
+}
+
+static inline void release_mtk_svs_lock(unsigned long flags)
+{
+}
+#endif /* CONFIG_MTK_SVS */
+
+#endif /* __MTK_SVS_H__ */
Signature · 1 line
2.18.0
#10 lore raw

Hi Roger,

Quoted 203 lines · Roger Lu

The SVS (Smart Voltage Scaling) engine is a piece of hardware which is used to calculate optimized voltage values of several power domains, e.g. CPU/GPU/CCI, according to chip process corner, temperatures, and other factors. Then DVFS driver could apply those optimized voltage values to reduce power consumption.

---
 drivers/power/avs/Kconfig     |   10 +
 drivers/power/avs/Makefile    |    1 +
 drivers/power/avs/mtk_svs.c   | 2075 +++++++++++++++++++++++++++++++++
 include/linux/power/mtk_svs.h |   23 +
 4 files changed, 2109 insertions(+)
 create mode 100644 drivers/power/avs/mtk_svs.c
 create mode 100644 include/linux/power/mtk_svs.h

[...]
new file mode 100644
index 000000000000..c46211a15fcd

drivers/power/avs/mtk_svs.c new file +179 -0
[...]
+
+static bool svs_mt8183_efuse_parsing(struct mtk_svs *svs)
+{
+       const struct svs_platform *svsp = svs->platform;
+       struct thermal_parameter tp;
+       struct svs_bank *svsb;
+       bool mon_mode_support = true;
+       int format[6], x_roomt[6], tb_roomt = 0;
+       u32 idx, i, ft_pgm, mts, temp0, temp1, temp2;
+
+       if (svsp->fake_efuse) {
+               pr_notice("fake efuse\n");
+               svs->efuse[0] = 0x00310080;
+               svs->efuse[1] = 0xabfbf757;
+               svs->efuse[2] = 0x47c747c7;
+               svs->efuse[3] = 0xabfbf757;
+               svs->efuse[4] = 0xe7fca0ec;
+               svs->efuse[5] = 0x47bf4b88;
+               svs->efuse[6] = 0xabfb8fa5;
+               svs->efuse[7] = 0xabfb217b;
+               svs->efuse[8] = 0x4bf34be1;
+               svs->efuse[9] = 0xabfb670d;
+               svs->efuse[16] = 0xabfbc653;
+               svs->efuse[17] = 0x47f347e1;
+               svs->efuse[18] = 0xabfbd848;
+
+               svs->thermal_efuse[0] = 0x02873f69;
+               svs->thermal_efuse[1] = 0xa11d9142;
+               svs->thermal_efuse[2] = 0xa2526900;
+       }
+
+       for (i = 0; i < svsp->efuse_num; i++) {
+               if (svs->efuse[i])
+                       pr_notice("M_HW_RES%d: 0x%08x\n", i, svs->efuse[i]);
+       }
+
+       /* svs efuse parsing */
+       ft_pgm = (svs->efuse[0] >> 4) & 0xf;
+
+       for (idx = 0; idx < svsp->bank_num; idx++) {
+               svsb = &svsp->banks[idx];
+               if (ft_pgm <= 1)
+                       svsb->init01_volt_flag = SVSB_INIT01_VOLT_IGNORE;
+
+               switch (svsb->sw_id) {
+               case SVS_CPU_LITTLE:
+                       svsb->bdes = svs->efuse[16] & GENMASK(7, 0);
+                       svsb->mdes = (svs->efuse[16] >> 8) & GENMASK(7, 0);
+                       svsb->dcbdet = (svs->efuse[16] >> 16) & GENMASK(7, 0);
+                       svsb->dcmdet = (svs->efuse[16] >> 24) & GENMASK(7, 0);
+                       svsb->mtdes  = (svs->efuse[17] >> 16) & GENMASK(7, 0);
+
+                       if (ft_pgm <= 3)
+                               svsb->volt_offset += 10;
+                       else
+                               svsb->volt_offset += 2;
+                       break;
+               case SVS_CPU_BIG:
+                       svsb->bdes = svs->efuse[18] & GENMASK(7, 0);
+                       svsb->mdes = (svs->efuse[18] >> 8) & GENMASK(7, 0);
+                       svsb->dcbdet = (svs->efuse[18] >> 16) & GENMASK(7, 0);
+                       svsb->dcmdet = (svs->efuse[18] >> 24) & GENMASK(7, 0);
+                       svsb->mtdes  = svs->efuse[17] & GENMASK(7, 0);
+
+                       if (ft_pgm <= 3)
+                               svsb->volt_offset += 15;
+                       else
+                               svsb->volt_offset += 12;
+                       break;
+               case SVS_CCI:
+                       svsb->bdes = svs->efuse[4] & GENMASK(7, 0);
+                       svsb->mdes = (svs->efuse[4] >> 8) & GENMASK(7, 0);
+                       svsb->dcbdet = (svs->efuse[4] >> 16) & GENMASK(7, 0);
+                       svsb->dcmdet = (svs->efuse[4] >> 24) & GENMASK(7, 0);
+                       svsb->mtdes  = (svs->efuse[5] >> 16) & GENMASK(7, 0);
+
+                       if (ft_pgm <= 3)
+                               svsb->volt_offset += 10;
+                       else
+                               svsb->volt_offset += 2;
+                       break;
+               case SVS_GPU:
+                       svsb->bdes = svs->efuse[6] & GENMASK(7, 0);
+                       svsb->mdes = (svs->efuse[6] >> 8) & GENMASK(7, 0);
+                       svsb->dcbdet = (svs->efuse[6] >> 16) & GENMASK(7, 0);
+                       svsb->dcmdet = (svs->efuse[6] >> 24) & GENMASK(7, 0);
+                       svsb->mtdes  = svs->efuse[5] & GENMASK(7, 0);
+
+                       if (ft_pgm >= 2) {
+                               svsb->freq_base = 800000000; /* 800MHz */
+                               svsb->dvt_fixed = 2;
+                       }
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       /* Thermal efuse parsing */
+       if (!svs->thermal_efuse)
+               return true;
+
+       tp.adc_ge_t = (svs->thermal_efuse[1] >> 22) & GENMASK(9, 0);
+       tp.adc_oe_t = (svs->thermal_efuse[1] >> 12) & GENMASK(9, 0);
+
+       tp.o_vtsmcu1 = (svs->thermal_efuse[0] >> 17) & GENMASK(8, 0);
+       tp.o_vtsmcu2 = (svs->thermal_efuse[0] >> 8) & GENMASK(8, 0);
+       tp.o_vtsmcu3 = svs->thermal_efuse[1] & GENMASK(8, 0);
+       tp.o_vtsmcu4 = (svs->thermal_efuse[2] >> 23) & GENMASK(8, 0);
+       tp.o_vtsmcu5 = (svs->thermal_efuse[2] >> 5) & GENMASK(8, 0);
+       tp.o_vtsabb = (svs->thermal_efuse[2] >> 14) & GENMASK(8, 0);
+
+       tp.degc_cali = (svs->thermal_efuse[0] >> 1) & GENMASK(5, 0);
+       tp.adc_cali_en_t = svs->thermal_efuse[0] & BIT(0);
+       tp.o_slope_sign = (svs->thermal_efuse[0] >> 7) & BIT(0);
+
+       tp.ts_id = (svs->thermal_efuse[1] >> 9) & BIT(0);
+       tp.o_slope = (svs->thermal_efuse[0] >> 26) & GENMASK(5, 0);
+
+       if (tp.adc_cali_en_t == 1) {
+               if (tp.ts_id == 0)
+                       tp.o_slope = 0;
+
+               if ((tp.adc_ge_t < 265 || tp.adc_ge_t > 758) ||
+                   (tp.adc_oe_t < 265 || tp.adc_oe_t > 758) ||
+                   (tp.o_vtsmcu1 < -8 || tp.o_vtsmcu1 > 484) ||
+                   (tp.o_vtsmcu2 < -8 || tp.o_vtsmcu2 > 484) ||
+                   (tp.o_vtsmcu3 < -8 || tp.o_vtsmcu3 > 484) ||
+                   (tp.o_vtsmcu4 < -8 || tp.o_vtsmcu4 > 484) ||
+                   (tp.o_vtsmcu5 < -8 || tp.o_vtsmcu5 > 484) ||
+                   (tp.o_vtsabb < -8 || tp.o_vtsabb > 484) ||
+                   (tp.degc_cali < 1 || tp.degc_cali > 63)) {
+                       pr_err("bad thermal efuse data. disable mon mode\n");
+                       mon_mode_support = false;
+               }
+       } else {
+               pr_err("no thermal efuse data. disable mon mode\n");
+               mon_mode_support = false;
+       }
+
+       if (!mon_mode_support) {
+               for (idx = 0; idx < svsp->bank_num; idx++) {
+                       svsb = &svsp->banks[idx];
+                       svsb->mode_support &= ~SVSB_MODE_MON;
+               }
+
+               return true;
+       }
+
+       tp.ge = ((tp.adc_ge_t - 512) * 10000) / 4096;
+       tp.oe = (tp.adc_oe_t - 512);
+       tp.gain = (10000 + tp.ge);
+
+       format[0] = (tp.o_vtsmcu1 + 3350 - tp.oe);
+       format[1] = (tp.o_vtsmcu2 + 3350 - tp.oe);
+       format[2] = (tp.o_vtsmcu3 + 3350 - tp.oe);
+       format[3] = (tp.o_vtsmcu4 + 3350 - tp.oe);
+       format[4] = (tp.o_vtsmcu5 + 3350 - tp.oe);
+       format[5] = (tp.o_vtsabb + 3350 - tp.oe);
+
+       for (i = 0; i < 6; i++)
+               x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / tp.gain;
+
+       temp0 = (10000 * 100000 / tp.gain) * 15 / 18;
+
+       if (tp.o_slope_sign == 0)
+               mts = (temp0 * 10) / (1534 + tp.o_slope * 10);
+       else
+               mts = (temp0 * 10) / (1534 - tp.o_slope * 10);
+
+       for (idx = 0; idx < svsp->bank_num; idx++) {
+               svsb = &svsp->banks[idx];
+               svsb->mts = mts;
+
+               switch (svsb->sw_id) {
+               case SVS_CPU_LITTLE:
+                       tb_roomt = x_roomt[3];
+                       break;
+               case SVS_CPU_BIG:

drivers/power/avs/mtk_svs.c line 1297

Quoted 10 lines
drivers/power/avs/mtk_svs.c new file +10 -0
+                       tb_roomt = x_roomt[4];
+                       break;
+               case SVS_CCI:
+                       tb_roomt = x_roomt[3];
+                       break;
+               case SVS_GPU:
+                       tb_roomt = x_roomt[1];
+                       break;
+               default:
+                       break;

There was a "return -EINVAL;" here in v5, should this be a "return false"? This function currently always return true.

Quoted 89 lines
drivers/power/avs/mtk_svs.c new file +88 -0
+               }
+
+               temp0 = (tp.degc_cali * 10 / 2);
+               temp1 = ((10000 * 100000 / 4096 / tp.gain) *
+                        tp.oe + tb_roomt * 10) * 15 / 18;
+
+               if (tp.o_slope_sign == 0)
+                       temp2 = temp1 * 100 / (1534 + tp.o_slope * 10);
+               else
+                       temp2 = temp1 * 100 / (1534 - tp.o_slope * 10);
+
+               svsb->bts = (temp0 + temp2 - 250) * 4 / 10;
+       }
+
+       return true;
+}
[...]
+
+static int svs_resource_setup(struct mtk_svs *svs)
+{
+       const struct svs_platform *svsp = svs->platform;
+       struct svs_bank *svsb;
+       struct platform_device *pdev;
+       struct device_node *np = NULL;
+       struct dev_pm_opp *opp;
+       unsigned long freq;
+       int count, ret;
+       u32 idx, i;
+
+       for (idx = 0; idx < svsp->bank_num; idx++) {
+               svsb = &svsp->banks[idx];
+
+               switch (svsb->sw_id) {
+               case SVS_CPU_LITTLE:
+                       svsb->name = "SVS_CPU_LITTLE";
+                       break;
+               case SVS_CPU_BIG:
+                       svsb->name = "SVS_CPU_BIG";
+                       break;
+               case SVS_CCI:
+                       svsb->name = "SVS_CCI";
+                       break;
+               case SVS_GPU:
+                       svsb->name = "SVS_GPU";
+                       break;
+               default:
+                       WARN_ON(1);
+                       return -EINVAL;
+               }
+
+               /* Add svs bank device for opp-table/mtcmos/buck control */
+               pdev = platform_device_alloc(svsb->name, 0);
+               if (!pdev) {
+                       pr_err("%s: fail to alloc pdev for svs_bank\n",
+                              svsb->name);
+                       return -ENOMEM;
+               }
+
+               for_each_child_of_node(svs->dev->of_node, np) {
+                       if (of_device_is_compatible(np, svsb->of_compatible)) {
+                               pdev->dev.of_node = np;
+                               break;
+                       }
+               }
+
+               ret = platform_device_add(pdev);
+               if (ret) {
+                       pr_err("%s: fail to add svs_bank device: %d\n",
+                              svsb->name, ret);
+                       return ret;
+               }
+
+               svsb->dev = &pdev->dev;
+               dev_set_drvdata(svsb->dev, svs);
+               ret = dev_pm_opp_of_add_table(svsb->dev);
+               if (ret) {
+                       pr_err("%s: fail to add opp table: %d\n",
+                              svsb->name, ret);
+                       return ret;
+               }
+
+               mutex_init(&svsb->lock);
+
+               svsb->buck = devm_regulator_get_optional(svsb->dev,
+                                                        svsb->buck_name);
+               if (IS_ERR(svsb->buck)) {
+                       pr_err("%s: cannot get regulator \"%s-supply\"\n",
+                              svsb->name, svsb->buck_name);
+                       return PTR_ERR(svsb->buck);

drivers/power/avs/mtk_svs.c line 1458

Quoted 10 lines
drivers/power/avs/mtk_svs.c new file +10 -0
+               }
+
+               count = dev_pm_opp_get_opp_count(svsb->dev);
+               if (svsb->opp_count != count) {
+                       pr_err("%s: opp_count not \"%u\" but get \"%d\"?\n",
+                              svsb->name, svsb->opp_count, count);
+                       return count;
+               }
+
+               for (i = 0, freq = (u32)-1; i < svsb->opp_count; i++, freq--) {

Can use U32_MAX instead of (u32)-1.

Quoted 37 lines
drivers/power/avs/mtk_svs.c new file +36 -0
+                       opp = dev_pm_opp_find_freq_floor(svsb->dev, &freq);
+                       if (IS_ERR(opp)) {
+                               pr_err("%s: error opp entry!!, err = %ld\n",
+                                      svsb->name, PTR_ERR(opp));
+                               return PTR_ERR(opp);
+                       }
+
+                       svsb->opp_freqs[i] = freq;
+                       svsb->opp_volts[i] = dev_pm_opp_get_voltage(opp);
+                       svsb->freqs_pct[i] = percent(svsb->opp_freqs[i],
+                                                    svsb->freq_base);
+                       dev_pm_opp_put(opp);
+               }
+       }
+
+       return 0;
+}
+
[...]
+
+static ssize_t svs_debug_proc_write(struct file *file,
+                                   const char __user *buffer,
+                                   size_t count, loff_t *pos)
+{
+       struct svs_bank *svsb = (struct svs_bank *)PDE_DATA(file_inode(file));
+       struct mtk_svs *svs = dev_get_drvdata(svsb->dev);
+       char *buf = (char *)__get_free_page(GFP_USER);
+       unsigned long flags;
+       int enabled, ret;
+
+       if (svsb->phase == SVSB_PHASE_ERROR)
+               return count;
+
+       if (!buf)
+               return -ENOMEM;
+
+       if (count >= PAGE_SIZE) {

drivers/power/avs/mtk_svs.c line 1580

Quoted 10 lines
drivers/power/avs/mtk_svs.c new file +10 -0
+               free_page((unsigned long)buf);
+               return -EINVAL;
+       }
+
+       if (copy_from_user(buf, buffer, count)) {
+               free_page((unsigned long)buf);
+               return -EFAULT;
+       }
+
+       buf[count] = '\0';

Can use memdup_user_nul to allocate the buf and copy from user buffer for the above operations (and for other _write() functions).

Quoted 7 lines
drivers/power/avs/mtk_svs.c new file +7 -0
+
+       ret = kstrtoint(buf, 10, &enabled);
+       if (ret)
+               return ret;
+
+       if (!enabled) {
+               flags = claim_mtk_svs_lock();

drivers/power/avs/mtk_svs.c line 1597

Quoted 10 lines
drivers/power/avs/mtk_svs.c new file +10 -0
+               svs->bank = svsb;
+               svsb->mode_support = SVSB_MODE_ALL_DISABLE;
+               svs_switch_bank(svs);
+               svs_writel(svs, SVSEN_OFF, SVSEN);
+               svs_writel(svs, INTSTS_CLEAN, INTSTS);
+               release_mtk_svs_lock(flags);
+       }
+
+       svsb->phase = SVSB_PHASE_ERROR;
+       svsb_set_volts(svsb, true);

Missing free_page() (or kfree() if changing to memdup_user_nul) here (and in other _write() functions).

Quoted 7 lines
drivers/power/avs/mtk_svs.c new file +6 -0
+
+       return count;
+}
+
+proc_fops_rw(svs_debug);
+
[...]
maintainer
#2 lore raw

Re: [PATCH v6 1/3] dt-bindings: soc: add mtk svs dt-bindings

In reply to Roger Lu
Quoted 60 lines · Roger Lu

Document the binding for enabling mtk svs on MediaTek SoC.

---
 .../devicetree/bindings/power/mtk-svs.txt     | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/mtk-svs.txt
Documentation/devicetree/bindings/power/mtk-svs.txt new file +46 -0
new file mode 100644
index 000000000000..9a3e81b9e1d2
@@ -0,0 +1,76 @@
+* Mediatek Smart Voltage Scaling (MTK SVS)
+
+This describes the device tree binding for the MTK SVS controller (bank)
+which helps provide the optimized CPU/GPU/CCI voltages. This device also
+needs thermal data to calculate thermal slope for accurately compensate
+the voltages when temperature change.
+
+Required properties:
+- compatible:
+  - "mediatek,mt8183-svs" : For MT8183 family of SoCs
+- reg: Address range of the MTK SVS controller.
+- interrupts: IRQ for the MTK SVS controller.
+- clocks, clock-names: Clocks needed for the svs hardware. required
+                       clocks are:
+		       "main": Main clock for svs controller to work.
+- nvmem-cells: Phandle to the calibration data provided by a nvmem device.
+- nvmem-cell-names: Should be "svs-calibration-data" and "calibration-data"
+
+Subnodes:
+- svs-cpu-little: SVS bank device node of little CPU
+  compatible: "mediatek,mt8183-svs-cpu-little"
+  operating-points-v2: OPP table hooked by SVS little CPU bank.
+		       SVS will optimze this OPP table voltage part.
+  vcpu-little-supply: PMIC buck of little CPU
+- svs-cpu-big: SVS bank device node of big CPU
+  compatible: "mediatek,mt8183-svs-cpu-big"
+  operating-points-v2: OPP table hooked by SVS big CPU bank.
+		       SVS will optimze this OPP table voltage part.
+  vcpu-big-supply: PMIC buck of big CPU
+- svs-cci: SVS bank device node of CCI
+  compatible: "mediatek,mt8183-svs-cci"
+  operating-points-v2: OPP table hooked by SVS CCI bank.
+		       SVS will optimze this OPP table voltage part.
+  vcci-supply: PMIC buck of CCI
+- svs-gpu: SVS bank device node of GPU
+  compatible: "mediatek,mt8183-svs-gpu"
+  operating-points-v2: OPP table hooked by SVS GPU bank.
+		       SVS will optimze this OPP table voltage part.
+  vgpu-supply: PMIC buck of GPU
+
+Example:
+
+	svs: svs@1100b000 {
+		compatible = "mediatek,mt8183-svs";
+		reg = <0 0x1100b000 0 0x1000>;
+		interrupts = <GIC_SPI 127 IRQ_TYPE_LEVEL_LOW>;

Documentation/devicetree/bindings/power/mtk-svs.txt line 56

Quoted 10 lines
Documentation/devicetree/bindings/power/mtk-svs.txt new file +10 -0
+		clocks = <&infracfg CLK_INFRA_THERM>;
+		clock-names = "main_clk";
+		nvmem-cells = <&svs_calibration>, <&thermal_calibration>;
+		nvmem-cell-names = "svs-calibration-data", "calibration-data";
+
+		svs_cpu_little: svs-cpu-little {
+			compatible = "mediatek,mt8183-svs-cpu-little";
+			operating-points-v2 = <&cluster0_opp>;
+			vcpu-little-supply = <&mt6358_vproc12_reg>;
+		};

I don't think this is a good binding. This information already exists elsewhere in the DT, so your driver should just look in those nodes. For example the regulator can be in the cpu nodes or the OPP table itself.

Rob

author
#11 lore raw
In reply to Pi-Hsun Shih

Dear Pi-Hsun,

Thanks for the advices.

Quoted 211 lines · Pi-Hsun Shih

Hi Roger,

Quoted 208 lines · Roger Lu

The SVS (Smart Voltage Scaling) engine is a piece of hardware which is used to calculate optimized voltage values of several power domains, e.g. CPU/GPU/CCI, according to chip process corner, temperatures, and other factors. Then DVFS driver could apply those optimized voltage values to reduce power consumption.

---
 drivers/power/avs/Kconfig     |   10 +
 drivers/power/avs/Makefile    |    1 +
 drivers/power/avs/mtk_svs.c   | 2075 +++++++++++++++++++++++++++++++++
 include/linux/power/mtk_svs.h |   23 +
 4 files changed, 2109 insertions(+)
 create mode 100644 drivers/power/avs/mtk_svs.c
 create mode 100644 include/linux/power/mtk_svs.h

[...]
new file mode 100644
index 000000000000..c46211a15fcd

drivers/power/avs/mtk_svs.c new file +184 -0
[...]
+
+static bool svs_mt8183_efuse_parsing(struct mtk_svs *svs)
+{
+       const struct svs_platform *svsp = svs->platform;
+       struct thermal_parameter tp;
+       struct svs_bank *svsb;
+       bool mon_mode_support = true;
+       int format[6], x_roomt[6], tb_roomt = 0;
+       u32 idx, i, ft_pgm, mts, temp0, temp1, temp2;
+
+       if (svsp->fake_efuse) {
+               pr_notice("fake efuse\n");
+               svs->efuse[0] = 0x00310080;
+               svs->efuse[1] = 0xabfbf757;
+               svs->efuse[2] = 0x47c747c7;
+               svs->efuse[3] = 0xabfbf757;
+               svs->efuse[4] = 0xe7fca0ec;
+               svs->efuse[5] = 0x47bf4b88;
+               svs->efuse[6] = 0xabfb8fa5;
+               svs->efuse[7] = 0xabfb217b;
+               svs->efuse[8] = 0x4bf34be1;
+               svs->efuse[9] = 0xabfb670d;
+               svs->efuse[16] = 0xabfbc653;
+               svs->efuse[17] = 0x47f347e1;
+               svs->efuse[18] = 0xabfbd848;
+
+               svs->thermal_efuse[0] = 0x02873f69;
+               svs->thermal_efuse[1] = 0xa11d9142;
+               svs->thermal_efuse[2] = 0xa2526900;
+       }
+
+       for (i = 0; i < svsp->efuse_num; i++) {
+               if (svs->efuse[i])
+                       pr_notice("M_HW_RES%d: 0x%08x\n", i, svs->efuse[i]);
+       }
+
+       /* svs efuse parsing */
+       ft_pgm = (svs->efuse[0] >> 4) & 0xf;
+
+       for (idx = 0; idx < svsp->bank_num; idx++) {
+               svsb = &svsp->banks[idx];
+               if (ft_pgm <= 1)
+                       svsb->init01_volt_flag = SVSB_INIT01_VOLT_IGNORE;
+
+               switch (svsb->sw_id) {
+               case SVS_CPU_LITTLE:
+                       svsb->bdes = svs->efuse[16] & GENMASK(7, 0);
+                       svsb->mdes = (svs->efuse[16] >> 8) & GENMASK(7, 0);
+                       svsb->dcbdet = (svs->efuse[16] >> 16) & GENMASK(7, 0);
+                       svsb->dcmdet = (svs->efuse[16] >> 24) & GENMASK(7, 0);
+                       svsb->mtdes  = (svs->efuse[17] >> 16) & GENMASK(7, 0);
+
+                       if (ft_pgm <= 3)
+                               svsb->volt_offset += 10;
+                       else
+                               svsb->volt_offset += 2;
+                       break;
+               case SVS_CPU_BIG:
+                       svsb->bdes = svs->efuse[18] & GENMASK(7, 0);
+                       svsb->mdes = (svs->efuse[18] >> 8) & GENMASK(7, 0);
+                       svsb->dcbdet = (svs->efuse[18] >> 16) & GENMASK(7, 0);
+                       svsb->dcmdet = (svs->efuse[18] >> 24) & GENMASK(7, 0);
+                       svsb->mtdes  = svs->efuse[17] & GENMASK(7, 0);
+
+                       if (ft_pgm <= 3)
+                               svsb->volt_offset += 15;
+                       else
+                               svsb->volt_offset += 12;
+                       break;
+               case SVS_CCI:
+                       svsb->bdes = svs->efuse[4] & GENMASK(7, 0);
+                       svsb->mdes = (svs->efuse[4] >> 8) & GENMASK(7, 0);
+                       svsb->dcbdet = (svs->efuse[4] >> 16) & GENMASK(7, 0);
+                       svsb->dcmdet = (svs->efuse[4] >> 24) & GENMASK(7, 0);
+                       svsb->mtdes  = (svs->efuse[5] >> 16) & GENMASK(7, 0);
+
+                       if (ft_pgm <= 3)
+                               svsb->volt_offset += 10;
+                       else
+                               svsb->volt_offset += 2;
+                       break;
+               case SVS_GPU:
+                       svsb->bdes = svs->efuse[6] & GENMASK(7, 0);
+                       svsb->mdes = (svs->efuse[6] >> 8) & GENMASK(7, 0);
+                       svsb->dcbdet = (svs->efuse[6] >> 16) & GENMASK(7, 0);
+                       svsb->dcmdet = (svs->efuse[6] >> 24) & GENMASK(7, 0);
+                       svsb->mtdes  = svs->efuse[5] & GENMASK(7, 0);
+
+                       if (ft_pgm >= 2) {
+                               svsb->freq_base = 800000000; /* 800MHz */
+                               svsb->dvt_fixed = 2;
+                       }
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       /* Thermal efuse parsing */
+       if (!svs->thermal_efuse)
+               return true;
+
+       tp.adc_ge_t = (svs->thermal_efuse[1] >> 22) & GENMASK(9, 0);
+       tp.adc_oe_t = (svs->thermal_efuse[1] >> 12) & GENMASK(9, 0);
+
+       tp.o_vtsmcu1 = (svs->thermal_efuse[0] >> 17) & GENMASK(8, 0);
+       tp.o_vtsmcu2 = (svs->thermal_efuse[0] >> 8) & GENMASK(8, 0);
+       tp.o_vtsmcu3 = svs->thermal_efuse[1] & GENMASK(8, 0);
+       tp.o_vtsmcu4 = (svs->thermal_efuse[2] >> 23) & GENMASK(8, 0);
+       tp.o_vtsmcu5 = (svs->thermal_efuse[2] >> 5) & GENMASK(8, 0);
+       tp.o_vtsabb = (svs->thermal_efuse[2] >> 14) & GENMASK(8, 0);
+
+       tp.degc_cali = (svs->thermal_efuse[0] >> 1) & GENMASK(5, 0);
+       tp.adc_cali_en_t = svs->thermal_efuse[0] & BIT(0);
+       tp.o_slope_sign = (svs->thermal_efuse[0] >> 7) & BIT(0);
+
+       tp.ts_id = (svs->thermal_efuse[1] >> 9) & BIT(0);
+       tp.o_slope = (svs->thermal_efuse[0] >> 26) & GENMASK(5, 0);
+
+       if (tp.adc_cali_en_t == 1) {
+               if (tp.ts_id == 0)
+                       tp.o_slope = 0;
+
+               if ((tp.adc_ge_t < 265 || tp.adc_ge_t > 758) ||
+                   (tp.adc_oe_t < 265 || tp.adc_oe_t > 758) ||
+                   (tp.o_vtsmcu1 < -8 || tp.o_vtsmcu1 > 484) ||
+                   (tp.o_vtsmcu2 < -8 || tp.o_vtsmcu2 > 484) ||
+                   (tp.o_vtsmcu3 < -8 || tp.o_vtsmcu3 > 484) ||
+                   (tp.o_vtsmcu4 < -8 || tp.o_vtsmcu4 > 484) ||
+                   (tp.o_vtsmcu5 < -8 || tp.o_vtsmcu5 > 484) ||
+                   (tp.o_vtsabb < -8 || tp.o_vtsabb > 484) ||
+                   (tp.degc_cali < 1 || tp.degc_cali > 63)) {
+                       pr_err("bad thermal efuse data. disable mon mode\n");
+                       mon_mode_support = false;
+               }
+       } else {
+               pr_err("no thermal efuse data. disable mon mode\n");
+               mon_mode_support = false;
+       }
+
+       if (!mon_mode_support) {
+               for (idx = 0; idx < svsp->bank_num; idx++) {
+                       svsb = &svsp->banks[idx];
+                       svsb->mode_support &= ~SVSB_MODE_MON;
+               }
+
+               return true;
+       }
+
+       tp.ge = ((tp.adc_ge_t - 512) * 10000) / 4096;
+       tp.oe = (tp.adc_oe_t - 512);
+       tp.gain = (10000 + tp.ge);
+
+       format[0] = (tp.o_vtsmcu1 + 3350 - tp.oe);
+       format[1] = (tp.o_vtsmcu2 + 3350 - tp.oe);
+       format[2] = (tp.o_vtsmcu3 + 3350 - tp.oe);
+       format[3] = (tp.o_vtsmcu4 + 3350 - tp.oe);
+       format[4] = (tp.o_vtsmcu5 + 3350 - tp.oe);
+       format[5] = (tp.o_vtsabb + 3350 - tp.oe);
+
+       for (i = 0; i < 6; i++)
+               x_roomt[i] = (((format[i] * 10000) / 4096) * 10000) / tp.gain;
+
+       temp0 = (10000 * 100000 / tp.gain) * 15 / 18;
+
+       if (tp.o_slope_sign == 0)
+               mts = (temp0 * 10) / (1534 + tp.o_slope * 10);
+       else
+               mts = (temp0 * 10) / (1534 - tp.o_slope * 10);
+
+       for (idx = 0; idx < svsp->bank_num; idx++) {
+               svsb = &svsp->banks[idx];
+               svsb->mts = mts;
+
+               switch (svsb->sw_id) {
+               case SVS_CPU_LITTLE:
+                       tb_roomt = x_roomt[3];
+                       break;
+               case SVS_CPU_BIG:
+                       tb_roomt = x_roomt[4];
+                       break;
+               case SVS_CCI:
+                       tb_roomt = x_roomt[3];
+                       break;
Quoted 8 lines

drivers/power/avs/mtk_svs.c line 1297

Quoted 5 lines
drivers/power/avs/mtk_svs.c new file +5 -0
+               case SVS_GPU:
+                       tb_roomt = x_roomt[1];
+                       break;
+               default:
+                       break;

There was a "return -EINVAL;" here in v5, should this be a "return false"? This function currently always return true.

This "return -EINVAL" will be detected in svs common flow "svs_resource_setup()". Platform efuse parsing flow does efuse parsing/checking job only.

Quoted 94 lines
Quoted 94 lines
drivers/power/avs/mtk_svs.c new file +92 -0
+               }
+
+               temp0 = (tp.degc_cali * 10 / 2);
+               temp1 = ((10000 * 100000 / 4096 / tp.gain) *
+                        tp.oe + tb_roomt * 10) * 15 / 18;
+
+               if (tp.o_slope_sign == 0)
+                       temp2 = temp1 * 100 / (1534 + tp.o_slope * 10);
+               else
+                       temp2 = temp1 * 100 / (1534 - tp.o_slope * 10);
+
+               svsb->bts = (temp0 + temp2 - 250) * 4 / 10;
+       }
+
+       return true;
+}
[...]
+
+static int svs_resource_setup(struct mtk_svs *svs)
+{
+       const struct svs_platform *svsp = svs->platform;
+       struct svs_bank *svsb;
+       struct platform_device *pdev;
+       struct device_node *np = NULL;
+       struct dev_pm_opp *opp;
+       unsigned long freq;
+       int count, ret;
+       u32 idx, i;
+
+       for (idx = 0; idx < svsp->bank_num; idx++) {
+               svsb = &svsp->banks[idx];
+
+               switch (svsb->sw_id) {
+               case SVS_CPU_LITTLE:
+                       svsb->name = "SVS_CPU_LITTLE";
+                       break;
+               case SVS_CPU_BIG:
+                       svsb->name = "SVS_CPU_BIG";
+                       break;
+               case SVS_CCI:
+                       svsb->name = "SVS_CCI";
+                       break;
+               case SVS_GPU:
+                       svsb->name = "SVS_GPU";
+                       break;
+               default:
+                       WARN_ON(1);
+                       return -EINVAL;
+               }
+
+               /* Add svs bank device for opp-table/mtcmos/buck control */
+               pdev = platform_device_alloc(svsb->name, 0);
+               if (!pdev) {
+                       pr_err("%s: fail to alloc pdev for svs_bank\n",
+                              svsb->name);
+                       return -ENOMEM;
+               }
+
+               for_each_child_of_node(svs->dev->of_node, np) {
+                       if (of_device_is_compatible(np, svsb->of_compatible)) {
+                               pdev->dev.of_node = np;
+                               break;
+                       }
+               }
+
+               ret = platform_device_add(pdev);
+               if (ret) {
+                       pr_err("%s: fail to add svs_bank device: %d\n",
+                              svsb->name, ret);
+                       return ret;
+               }
+
+               svsb->dev = &pdev->dev;
+               dev_set_drvdata(svsb->dev, svs);
+               ret = dev_pm_opp_of_add_table(svsb->dev);
+               if (ret) {
+                       pr_err("%s: fail to add opp table: %d\n",
+                              svsb->name, ret);
+                       return ret;
+               }
+
+               mutex_init(&svsb->lock);
+
+               svsb->buck = devm_regulator_get_optional(svsb->dev,
+                                                        svsb->buck_name);
+               if (IS_ERR(svsb->buck)) {
+                       pr_err("%s: cannot get regulator \"%s-supply\"\n",
+                              svsb->name, svsb->buck_name);
+                       return PTR_ERR(svsb->buck);
+               }
+
+               count = dev_pm_opp_get_opp_count(svsb->dev);
+               if (svsb->opp_count != count) {
Quoted 8 lines

drivers/power/avs/mtk_svs.c line 1458

Quoted 6 lines
drivers/power/avs/mtk_svs.c new file +6 -0
+                       pr_err("%s: opp_count not \"%u\" but get \"%d\"?\n",
+                              svsb->name, svsb->opp_count, count);
+                       return count;
+               }
+
+               for (i = 0, freq = (u32)-1; i < svsb->opp_count; i++, freq--) {

Can use U32_MAX instead of (u32)-1.

Oh Sure. Thanks for the reference. I'll update it in the next patch.

Quoted 43 lines
Quoted 43 lines
drivers/power/avs/mtk_svs.c new file +41 -0
+                       opp = dev_pm_opp_find_freq_floor(svsb->dev, &freq);
+                       if (IS_ERR(opp)) {
+                               pr_err("%s: error opp entry!!, err = %ld\n",
+                                      svsb->name, PTR_ERR(opp));
+                               return PTR_ERR(opp);
+                       }
+
+                       svsb->opp_freqs[i] = freq;
+                       svsb->opp_volts[i] = dev_pm_opp_get_voltage(opp);
+                       svsb->freqs_pct[i] = percent(svsb->opp_freqs[i],
+                                                    svsb->freq_base);
+                       dev_pm_opp_put(opp);
+               }
+       }
+
+       return 0;
+}
+
[...]
+
+static ssize_t svs_debug_proc_write(struct file *file,
+                                   const char __user *buffer,
+                                   size_t count, loff_t *pos)
+{
+       struct svs_bank *svsb = (struct svs_bank *)PDE_DATA(file_inode(file));
+       struct mtk_svs *svs = dev_get_drvdata(svsb->dev);
+       char *buf = (char *)__get_free_page(GFP_USER);
+       unsigned long flags;
+       int enabled, ret;
+
+       if (svsb->phase == SVSB_PHASE_ERROR)
+               return count;
+
+       if (!buf)
+               return -ENOMEM;
+
+       if (count >= PAGE_SIZE) {
+               free_page((unsigned long)buf);
+               return -EINVAL;
+       }
+
+       if (copy_from_user(buf, buffer, count)) {
Quoted 8 lines

drivers/power/avs/mtk_svs.c line 1580

Quoted 5 lines
drivers/power/avs/mtk_svs.c new file +5 -0
+               free_page((unsigned long)buf);
+               return -EFAULT;
+       }
+
+       buf[count] = '\0';

Can use memdup_user_nul to allocate the buf and copy from user buffer for the above operations (and for other _write() functions).

Cool. I'll use memdup_user_nul() instead in the next patch. Thanks.

Quoted 13 lines
Quoted 13 lines
drivers/power/avs/mtk_svs.c new file +12 -0
+
+       ret = kstrtoint(buf, 10, &enabled);
+       if (ret)
+               return ret;
+
+       if (!enabled) {
+               flags = claim_mtk_svs_lock();
+               svs->bank = svsb;
+               svsb->mode_support = SVSB_MODE_ALL_DISABLE;
+               svs_switch_bank(svs);
+               svs_writel(svs, SVSEN_OFF, SVSEN);
+               svs_writel(svs, INTSTS_CLEAN, INTSTS);
Quoted 8 lines

drivers/power/avs/mtk_svs.c line 1597

Quoted 5 lines
drivers/power/avs/mtk_svs.c new file +5 -0
+               release_mtk_svs_lock(flags);
+       }
+
+       svsb->phase = SVSB_PHASE_ERROR;
+       svsb_set_volts(svsb, true);

Missing free_page() (or kfree() if changing to memdup_user_nul) here (and in other _write() functions).

No problem. I'll add free method here in the next patch. Thanks.

Quoted 8 lines
Quoted 8 lines
drivers/power/avs/mtk_svs.c new file +6 -0
+
+       return count;
+}
+
+proc_fops_rw(svs_debug);
+
[...]
#3 lore raw

Re: [PATCH v6 1/3] dt-bindings: soc: add mtk svs dt-bindings

In reply to Rob Herring
Quoted 69 lines · Rob Herring
Quoted 67 lines · Roger Lu

Document the binding for enabling mtk svs on MediaTek SoC.

---
 .../devicetree/bindings/power/mtk-svs.txt     | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/mtk-svs.txt
Documentation/devicetree/bindings/power/mtk-svs.txt new file +53 -0
new file mode 100644
index 000000000000..9a3e81b9e1d2
@@ -0,0 +1,76 @@
+* Mediatek Smart Voltage Scaling (MTK SVS)
+
+This describes the device tree binding for the MTK SVS controller (bank)
+which helps provide the optimized CPU/GPU/CCI voltages. This device also
+needs thermal data to calculate thermal slope for accurately compensate
+the voltages when temperature change.
+
+Required properties:
+- compatible:
+  - "mediatek,mt8183-svs" : For MT8183 family of SoCs
+- reg: Address range of the MTK SVS controller.
+- interrupts: IRQ for the MTK SVS controller.
+- clocks, clock-names: Clocks needed for the svs hardware. required
+                       clocks are:
+                    "main": Main clock for svs controller to work.
+- nvmem-cells: Phandle to the calibration data provided by a nvmem device.
+- nvmem-cell-names: Should be "svs-calibration-data" and "calibration-data"
+
+Subnodes:
+- svs-cpu-little: SVS bank device node of little CPU
+  compatible: "mediatek,mt8183-svs-cpu-little"
+  operating-points-v2: OPP table hooked by SVS little CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-little-supply: PMIC buck of little CPU
+- svs-cpu-big: SVS bank device node of big CPU
+  compatible: "mediatek,mt8183-svs-cpu-big"
+  operating-points-v2: OPP table hooked by SVS big CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-big-supply: PMIC buck of big CPU
+- svs-cci: SVS bank device node of CCI
+  compatible: "mediatek,mt8183-svs-cci"
+  operating-points-v2: OPP table hooked by SVS CCI bank.
+                    SVS will optimze this OPP table voltage part.
+  vcci-supply: PMIC buck of CCI
+- svs-gpu: SVS bank device node of GPU
+  compatible: "mediatek,mt8183-svs-gpu"
+  operating-points-v2: OPP table hooked by SVS GPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vgpu-supply: PMIC buck of GPU
+
+Example:
+
+     svs: svs@1100b000 {
+             compatible = "mediatek,mt8183-svs";
+             reg = <0 0x1100b000 0 0x1000>;
+             interrupts = <GIC_SPI 127 IRQ_TYPE_LEVEL_LOW>;
+             clocks = <&infracfg CLK_INFRA_THERM>;
+             clock-names = "main_clk";
+             nvmem-cells = <&svs_calibration>, <&thermal_calibration>;
+             nvmem-cell-names = "svs-calibration-data", "calibration-data";
+
+             svs_cpu_little: svs-cpu-little {
+                     compatible = "mediatek,mt8183-svs-cpu-little";
Quoted 8 lines

Documentation/devicetree/bindings/power/mtk-svs.txt line 56

Quoted 3 lines
Documentation/devicetree/bindings/power/mtk-svs.txt new file +3 -0
+                     operating-points-v2 = <&cluster0_opp>;
+                     vcpu-little-supply = <&mt6358_vproc12_reg>;
+             };

I don't think this is a good binding. This information already exists elsewhere in the DT, so your driver should just look in those nodes. For example the regulator can be in the cpu nodes or the OPP table itself.

Roger, if that helps, without changing any other binding, on 8183, basically you could have:
- svs-cpu-little: Add a handle to &cpu0 and get the regulator/opp
table from it.
- svs-cpu-big: Handle to &cpu4
- svs-cci: Handle to &cci
- svs-gpu: Handle to &gpu (BTW, it is expected that SVS would only
apply to vgpu/mali regulator, and not vsram regulator?)

I'm not too sure how we'd fetch the right regulator name, however (for the first 3 the name is "proc", for the last one it's "mali"), maybe add a regulator-name list in the DT?

Quoted 2 lines

Rob

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#4 lore raw

Re: [PATCH v6 1/3] dt-bindings: soc: add mtk svs dt-bindings

Quoted 80 lines · Nicolas Boichat
Quoted 69 lines · Rob Herring
Quoted 67 lines · Roger Lu

Document the binding for enabling mtk svs on MediaTek SoC.

---
 .../devicetree/bindings/power/mtk-svs.txt     | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/mtk-svs.txt
Documentation/devicetree/bindings/power/mtk-svs.txt new file +53 -0
new file mode 100644
index 000000000000..9a3e81b9e1d2
@@ -0,0 +1,76 @@
+* Mediatek Smart Voltage Scaling (MTK SVS)
+
+This describes the device tree binding for the MTK SVS controller (bank)
+which helps provide the optimized CPU/GPU/CCI voltages. This device also
+needs thermal data to calculate thermal slope for accurately compensate
+the voltages when temperature change.
+
+Required properties:
+- compatible:
+  - "mediatek,mt8183-svs" : For MT8183 family of SoCs
+- reg: Address range of the MTK SVS controller.
+- interrupts: IRQ for the MTK SVS controller.
+- clocks, clock-names: Clocks needed for the svs hardware. required
+                       clocks are:
+                    "main": Main clock for svs controller to work.
+- nvmem-cells: Phandle to the calibration data provided by a nvmem device.
+- nvmem-cell-names: Should be "svs-calibration-data" and "calibration-data"
+
+Subnodes:
+- svs-cpu-little: SVS bank device node of little CPU
+  compatible: "mediatek,mt8183-svs-cpu-little"
+  operating-points-v2: OPP table hooked by SVS little CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-little-supply: PMIC buck of little CPU
+- svs-cpu-big: SVS bank device node of big CPU
+  compatible: "mediatek,mt8183-svs-cpu-big"
+  operating-points-v2: OPP table hooked by SVS big CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-big-supply: PMIC buck of big CPU
+- svs-cci: SVS bank device node of CCI
+  compatible: "mediatek,mt8183-svs-cci"
+  operating-points-v2: OPP table hooked by SVS CCI bank.
+                    SVS will optimze this OPP table voltage part.
+  vcci-supply: PMIC buck of CCI
+- svs-gpu: SVS bank device node of GPU
+  compatible: "mediatek,mt8183-svs-gpu"
+  operating-points-v2: OPP table hooked by SVS GPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vgpu-supply: PMIC buck of GPU
+
+Example:
+
+     svs: svs@1100b000 {
+             compatible = "mediatek,mt8183-svs";
+             reg = <0 0x1100b000 0 0x1000>;
+             interrupts = <GIC_SPI 127 IRQ_TYPE_LEVEL_LOW>;
+             clocks = <&infracfg CLK_INFRA_THERM>;
+             clock-names = "main_clk";
+             nvmem-cells = <&svs_calibration>, <&thermal_calibration>;
+             nvmem-cell-names = "svs-calibration-data", "calibration-data";
+
+             svs_cpu_little: svs-cpu-little {
+                     compatible = "mediatek,mt8183-svs-cpu-little";
Quoted 8 lines

Documentation/devicetree/bindings/power/mtk-svs.txt line 56

Quoted 3 lines
Documentation/devicetree/bindings/power/mtk-svs.txt new file +3 -0
+                     operating-points-v2 = <&cluster0_opp>;
+                     vcpu-little-supply = <&mt6358_vproc12_reg>;
+             };

I don't think this is a good binding. This information already exists elsewhere in the DT, so your driver should just look in those nodes. For example the regulator can be in the cpu nodes or the OPP table itself.

Quoted 5 lines

Roger, if that helps, without changing any other binding, on 8183, basically you could have:
- svs-cpu-little: Add a handle to &cpu0 and get the regulator/opp
table from it.
- svs-cpu-big: Handle to &cpu4

Why do you need those? Use the compatible of the cpus to determine big and little cores. Or there's the cpu capacity property that could be used instead.

Quoted 1 line

- svs-cci: Handle to &cci

Is there more than 1 CCI? Just retrieve the node by the compatible. There's no need to have nodes that simply serve as a collection of data for some driver.

Quoted 6 lines

- svs-gpu: Handle to &gpu (BTW, it is expected that SVS would only
apply to vgpu/mali regulator, and not vsram regulator?)

I'm not too sure how we'd fetch the right regulator name, however (for the first 3 the name is "proc", for the last one it's "mali"), maybe add a regulator-name list in the DT?

To put this another way, write an SoC specific driver that understands to some extent what exists in the SoC (and DT). I doubt something like this is going to be generic across more than a few SoCs at most.

Rob

author
#5 lore raw

Re: [PATCH v6 1/3] dt-bindings: soc: add mtk svs dt-bindings

Hi Rob & Nicolas,

Sorry for the late reply.

Quoted 91 lines · Rob Herring
Quoted 80 lines · Nicolas Boichat
Quoted 69 lines · Rob Herring
Quoted 67 lines · Roger Lu

Document the binding for enabling mtk svs on MediaTek SoC.

---
 .../devicetree/bindings/power/mtk-svs.txt     | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/mtk-svs.txt
Documentation/devicetree/bindings/power/mtk-svs.txt new file +53 -0
new file mode 100644
index 000000000000..9a3e81b9e1d2
@@ -0,0 +1,76 @@
+* Mediatek Smart Voltage Scaling (MTK SVS)
+
+This describes the device tree binding for the MTK SVS controller (bank)
+which helps provide the optimized CPU/GPU/CCI voltages. This device also
+needs thermal data to calculate thermal slope for accurately compensate
+the voltages when temperature change.
+
+Required properties:
+- compatible:
+  - "mediatek,mt8183-svs" : For MT8183 family of SoCs
+- reg: Address range of the MTK SVS controller.
+- interrupts: IRQ for the MTK SVS controller.
+- clocks, clock-names: Clocks needed for the svs hardware. required
+                       clocks are:
+                    "main": Main clock for svs controller to work.
+- nvmem-cells: Phandle to the calibration data provided by a nvmem device.
+- nvmem-cell-names: Should be "svs-calibration-data" and "calibration-data"
+
+Subnodes:
+- svs-cpu-little: SVS bank device node of little CPU
+  compatible: "mediatek,mt8183-svs-cpu-little"
+  operating-points-v2: OPP table hooked by SVS little CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-little-supply: PMIC buck of little CPU
+- svs-cpu-big: SVS bank device node of big CPU
+  compatible: "mediatek,mt8183-svs-cpu-big"
+  operating-points-v2: OPP table hooked by SVS big CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-big-supply: PMIC buck of big CPU
+- svs-cci: SVS bank device node of CCI
+  compatible: "mediatek,mt8183-svs-cci"
+  operating-points-v2: OPP table hooked by SVS CCI bank.
+                    SVS will optimze this OPP table voltage part.
+  vcci-supply: PMIC buck of CCI
+- svs-gpu: SVS bank device node of GPU
+  compatible: "mediatek,mt8183-svs-gpu"
+  operating-points-v2: OPP table hooked by SVS GPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vgpu-supply: PMIC buck of GPU
+
+Example:
+
+     svs: svs@1100b000 {
+             compatible = "mediatek,mt8183-svs";
+             reg = <0 0x1100b000 0 0x1000>;
+             interrupts = <GIC_SPI 127 IRQ_TYPE_LEVEL_LOW>;
+             clocks = <&infracfg CLK_INFRA_THERM>;
+             clock-names = "main_clk";
+             nvmem-cells = <&svs_calibration>, <&thermal_calibration>;
+             nvmem-cell-names = "svs-calibration-data", "calibration-data";
+
+             svs_cpu_little: svs-cpu-little {
+                     compatible = "mediatek,mt8183-svs-cpu-little";
Quoted 8 lines

Documentation/devicetree/bindings/power/mtk-svs.txt line 56

Quoted 3 lines
Documentation/devicetree/bindings/power/mtk-svs.txt new file +3 -0
+                     operating-points-v2 = <&cluster0_opp>;
+                     vcpu-little-supply = <&mt6358_vproc12_reg>;
+             };

I don't think this is a good binding. This information already exists elsewhere in the DT, so your driver should just look in those nodes. For example the regulator can be in the cpu nodes or the OPP table itself.

Quoted 5 lines

Roger, if that helps, without changing any other binding, on 8183, basically you could have:
- svs-cpu-little: Add a handle to &cpu0 and get the regulator/opp
table from it.
- svs-cpu-big: Handle to &cpu4

Why do you need those? Use the compatible of the cpus to determine big and little cores. Or there's the cpu capacity property that could be used instead.

Quoted 8 lines
Quoted 1 line

- svs-cci: Handle to &cci

Is there more than 1 CCI? Just retrieve the node by the compatible. There's no need to have nodes that simply serve as a collection of data for some driver.

Quoted 2 lines

- svs-gpu: Handle to &gpu (BTW, it is expected that SVS would only
apply to vgpu/mali regulator, and not vsram regulator?)

svs-gpu depends on vgpu power on for init (don't care vgpu_sram). After svs-gpu init is done, it doesn't need vgpu power on anymore. (vgpu can be turned off)

Please allows me to introduce more about what svs-gpu device needs.
1. It needs gpu opp table from "gpu node" and gpu_core2 power-domains from "gpu_core2 node". When svs-gpu has those resources, it turns on gpu_core2 power-domain for svs-gpu-hw to have power (for calculating) and svs-gpu-sw will update gpu opp table voltages' part.
2. Therefore, if I retrieve gpu-related node from phandle or compatible, it means svs-gpu device in driver needs to attach two different gpu nodes for attaining gpu opp table and gpu_core2 power-domains. I think this architecture of svs-gpu confuses maintainer why it attaches two different nodes instead of having a device to describe what it needs.
3. Is it acceptable to have a Linux device attaching two different nodes? If yes, could you guide us some APIs for one device to attach two nodes? I don't know how to implement it. Thanks.

Quoted 11 lines
Quoted 4 lines

I'm not too sure how we'd fetch the right regulator name, however (for the first 3 the name is "proc", for the last one it's "mali"), maybe add a regulator-name list in the DT?

To put this another way, write an SoC specific driver that understands to some extent what exists in the SoC (and DT). I doubt something like this is going to be generic across more than a few SoCs at most.

Rob

#6 lore raw

Re: [PATCH v6 1/3] dt-bindings: soc: add mtk svs dt-bindings

Hi Rob,

Quoted 121 lines · Roger Lu

Hi Rob & Nicolas,

Sorry for the late reply.

Quoted 91 lines · Rob Herring
Quoted 80 lines · Nicolas Boichat
Quoted 69 lines · Rob Herring
Quoted 67 lines · Roger Lu

Document the binding for enabling mtk svs on MediaTek SoC.

---
 .../devicetree/bindings/power/mtk-svs.txt     | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/mtk-svs.txt
Documentation/devicetree/bindings/power/mtk-svs.txt new file +53 -0
new file mode 100644
index 000000000000..9a3e81b9e1d2
@@ -0,0 +1,76 @@
+* Mediatek Smart Voltage Scaling (MTK SVS)
+
+This describes the device tree binding for the MTK SVS controller (bank)
+which helps provide the optimized CPU/GPU/CCI voltages. This device also
+needs thermal data to calculate thermal slope for accurately compensate
+the voltages when temperature change.
+
+Required properties:
+- compatible:
+  - "mediatek,mt8183-svs" : For MT8183 family of SoCs
+- reg: Address range of the MTK SVS controller.
+- interrupts: IRQ for the MTK SVS controller.
+- clocks, clock-names: Clocks needed for the svs hardware. required
+                       clocks are:
+                    "main": Main clock for svs controller to work.
+- nvmem-cells: Phandle to the calibration data provided by a nvmem device.
+- nvmem-cell-names: Should be "svs-calibration-data" and "calibration-data"
+
+Subnodes:
+- svs-cpu-little: SVS bank device node of little CPU
+  compatible: "mediatek,mt8183-svs-cpu-little"
+  operating-points-v2: OPP table hooked by SVS little CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-little-supply: PMIC buck of little CPU
+- svs-cpu-big: SVS bank device node of big CPU
+  compatible: "mediatek,mt8183-svs-cpu-big"
+  operating-points-v2: OPP table hooked by SVS big CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-big-supply: PMIC buck of big CPU
+- svs-cci: SVS bank device node of CCI
+  compatible: "mediatek,mt8183-svs-cci"
+  operating-points-v2: OPP table hooked by SVS CCI bank.
+                    SVS will optimze this OPP table voltage part.
+  vcci-supply: PMIC buck of CCI
+- svs-gpu: SVS bank device node of GPU
+  compatible: "mediatek,mt8183-svs-gpu"
+  operating-points-v2: OPP table hooked by SVS GPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vgpu-supply: PMIC buck of GPU
+
+Example:
+
+     svs: svs@1100b000 {
+             compatible = "mediatek,mt8183-svs";
+             reg = <0 0x1100b000 0 0x1000>;
+             interrupts = <GIC_SPI 127 IRQ_TYPE_LEVEL_LOW>;
+             clocks = <&infracfg CLK_INFRA_THERM>;
+             clock-names = "main_clk";
+             nvmem-cells = <&svs_calibration>, <&thermal_calibration>;
+             nvmem-cell-names = "svs-calibration-data", "calibration-data";
+
+             svs_cpu_little: svs-cpu-little {
+                     compatible = "mediatek,mt8183-svs-cpu-little";
Quoted 8 lines

Documentation/devicetree/bindings/power/mtk-svs.txt line 56

Quoted 3 lines
Documentation/devicetree/bindings/power/mtk-svs.txt new file +3 -0
+                     operating-points-v2 = <&cluster0_opp>;
+                     vcpu-little-supply = <&mt6358_vproc12_reg>;
+             };

I don't think this is a good binding. This information already exists elsewhere in the DT, so your driver should just look in those nodes. For example the regulator can be in the cpu nodes or the OPP table itself.

Quoted 5 lines

Roger, if that helps, without changing any other binding, on 8183, basically you could have:
- svs-cpu-little: Add a handle to &cpu0 and get the regulator/opp
table from it.
- svs-cpu-big: Handle to &cpu4

Why do you need those? Use the compatible of the cpus to determine big and little cores. Or there's the cpu capacity property that could be used instead.

Quoted 8 lines
Quoted 1 line

- svs-cci: Handle to &cci

Is there more than 1 CCI? Just retrieve the node by the compatible. There's no need to have nodes that simply serve as a collection of data for some driver.

Quoted 2 lines

- svs-gpu: Handle to &gpu (BTW, it is expected that SVS would only
apply to vgpu/mali regulator, and not vsram regulator?)

svs-gpu depends on vgpu power on for init (don't care vgpu_sram). After svs-gpu init is done, it doesn't need vgpu power on anymore. (vgpu can be turned off)

Please allows me to introduce more about what svs-gpu device needs.
1. It needs gpu opp table from "gpu node" and gpu_core2 power-domains from "gpu_core2 node". When svs-gpu has those resources, it turns on gpu_core2 power-domain for svs-gpu-hw to have power (for calculating) and svs-gpu-sw will update gpu opp table voltages' part.
2. Therefore, if I retrieve gpu-related node from phandle or compatible, it means svs-gpu device in driver needs to attach two different gpu nodes for attaining gpu opp table and gpu_core2 power-domains. I think this architecture of svs-gpu confuses maintainer why it attaches two different nodes instead of having a device to describe what it needs.

Quoted 3 lines

3. Is it acceptable to have a Linux device attaching two different nodes? If yes, could you guide us some APIs for one device to attach two nodes? I don't know how to implement it. Thanks.

I'm also trying to understand how that would work. The way the code
works now (https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/chromeos-4.19/drivers/power/avs/mtk_svs.c#1388):

The SVS driver creates a platform device for each sub-node, find the sub-node that matches the compatible (pdev->dev.of_node):
for_each_child_of_node(svs->dev->of_node, np) {

  if (of_device_is_compatible(np, svsb->of_compatible)) {
    pdev->dev.of_node = np;
    break;

}
}

Then, thanks to that, the 2 functions dev_pm_opp_of_add_table and devm_regulator_get_optional "just work", as the get the opp table and regulator from the device tree node.

So what you suggest is basically something like this:
pdev->dev.of_node = of_find_compatible_node(NULL, NULL, "mediatek,mt8183-cci");

I came up with a (very dirty) prototype here:
https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2076718
... and it doesn't really work
(https://gist.github.com/drinkcat/61e50eedbdc301d418c9cee3ee5b6b06, I think the kernel is probing more than it should, like the DMA mask errors should not happen...)

Before I dig further... I have the same concern as Roger, is it ok to have 2 devices bound to the same device tree node/compatible? My understanding was also that it's not.

Quoted 12 lines
Quoted 11 lines
Quoted 4 lines

I'm not too sure how we'd fetch the right regulator name, however (for the first 3 the name is "proc", for the last one it's "mali"), maybe add a regulator-name list in the DT?

To put this another way, write an SoC specific driver that understands to some extent what exists in the SoC (and DT). I doubt something like this is going to be generic across more than a few SoCs at most.

Rob

#7 lore raw

Re: [PATCH v6 1/3] dt-bindings: soc: add mtk svs dt-bindings

Quoted 155 lines · Nicolas Boichat

Hi Rob,

Quoted 121 lines · Roger Lu

Hi Rob & Nicolas,

Sorry for the late reply.

Quoted 91 lines · Rob Herring
Quoted 80 lines · Nicolas Boichat
Quoted 69 lines · Rob Herring
Quoted 67 lines · Roger Lu

Document the binding for enabling mtk svs on MediaTek SoC.

---
 .../devicetree/bindings/power/mtk-svs.txt     | 76 +++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/mtk-svs.txt
Documentation/devicetree/bindings/power/mtk-svs.txt new file +53 -0
new file mode 100644
index 000000000000..9a3e81b9e1d2
@@ -0,0 +1,76 @@
+* Mediatek Smart Voltage Scaling (MTK SVS)
+
+This describes the device tree binding for the MTK SVS controller (bank)
+which helps provide the optimized CPU/GPU/CCI voltages. This device also
+needs thermal data to calculate thermal slope for accurately compensate
+the voltages when temperature change.
+
+Required properties:
+- compatible:
+  - "mediatek,mt8183-svs" : For MT8183 family of SoCs
+- reg: Address range of the MTK SVS controller.
+- interrupts: IRQ for the MTK SVS controller.
+- clocks, clock-names: Clocks needed for the svs hardware. required
+                       clocks are:
+                    "main": Main clock for svs controller to work.
+- nvmem-cells: Phandle to the calibration data provided by a nvmem device.
+- nvmem-cell-names: Should be "svs-calibration-data" and "calibration-data"
+
+Subnodes:
+- svs-cpu-little: SVS bank device node of little CPU
+  compatible: "mediatek,mt8183-svs-cpu-little"
+  operating-points-v2: OPP table hooked by SVS little CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-little-supply: PMIC buck of little CPU
+- svs-cpu-big: SVS bank device node of big CPU
+  compatible: "mediatek,mt8183-svs-cpu-big"
+  operating-points-v2: OPP table hooked by SVS big CPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vcpu-big-supply: PMIC buck of big CPU
+- svs-cci: SVS bank device node of CCI
+  compatible: "mediatek,mt8183-svs-cci"
+  operating-points-v2: OPP table hooked by SVS CCI bank.
+                    SVS will optimze this OPP table voltage part.
+  vcci-supply: PMIC buck of CCI
+- svs-gpu: SVS bank device node of GPU
+  compatible: "mediatek,mt8183-svs-gpu"
+  operating-points-v2: OPP table hooked by SVS GPU bank.
+                    SVS will optimze this OPP table voltage part.
+  vgpu-supply: PMIC buck of GPU
+
+Example:
+
+     svs: svs@1100b000 {
+             compatible = "mediatek,mt8183-svs";
+             reg = <0 0x1100b000 0 0x1000>;
+             interrupts = <GIC_SPI 127 IRQ_TYPE_LEVEL_LOW>;
+             clocks = <&infracfg CLK_INFRA_THERM>;
+             clock-names = "main_clk";
+             nvmem-cells = <&svs_calibration>, <&thermal_calibration>;
+             nvmem-cell-names = "svs-calibration-data", "calibration-data";
+
+             svs_cpu_little: svs-cpu-little {
+                     compatible = "mediatek,mt8183-svs-cpu-little";
Quoted 8 lines

Documentation/devicetree/bindings/power/mtk-svs.txt line 56

Quoted 3 lines
Documentation/devicetree/bindings/power/mtk-svs.txt new file +3 -0
+                     operating-points-v2 = <&cluster0_opp>;
+                     vcpu-little-supply = <&mt6358_vproc12_reg>;
+             };

I don't think this is a good binding. This information already exists elsewhere in the DT, so your driver should just look in those nodes. For example the regulator can be in the cpu nodes or the OPP table itself.

Quoted 5 lines

Roger, if that helps, without changing any other binding, on 8183, basically you could have:
- svs-cpu-little: Add a handle to &cpu0 and get the regulator/opp
table from it.
- svs-cpu-big: Handle to &cpu4

Why do you need those? Use the compatible of the cpus to determine big and little cores. Or there's the cpu capacity property that could be used instead.

Quoted 8 lines
Quoted 1 line

- svs-cci: Handle to &cci

Is there more than 1 CCI? Just retrieve the node by the compatible. There's no need to have nodes that simply serve as a collection of data for some driver.

Quoted 2 lines

- svs-gpu: Handle to &gpu (BTW, it is expected that SVS would only
apply to vgpu/mali regulator, and not vsram regulator?)

svs-gpu depends on vgpu power on for init (don't care vgpu_sram). After svs-gpu init is done, it doesn't need vgpu power on anymore. (vgpu can be turned off)

Please allows me to introduce more about what svs-gpu device needs.
1. It needs gpu opp table from "gpu node" and gpu_core2 power-domains from "gpu_core2 node". When svs-gpu has those resources, it turns on gpu_core2 power-domain for svs-gpu-hw to have power (for calculating) and svs-gpu-sw will update gpu opp table voltages' part.
2. Therefore, if I retrieve gpu-related node from phandle or compatible, it means svs-gpu device in driver needs to attach two different gpu nodes for attaining gpu opp table and gpu_core2 power-domains. I think this architecture of svs-gpu confuses maintainer why it attaches two different nodes instead of having a device to describe what it needs.

Quoted 3 lines

3. Is it acceptable to have a Linux device attaching two different nodes? If yes, could you guide us some APIs for one device to attach two nodes? I don't know how to implement it. Thanks.

I'm also trying to understand how that would work. The way the code
works now (https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/chromeos-4.19/drivers/power/avs/mtk_svs.c#1388):

The SVS driver creates a platform device for each sub-node, find the sub-node that matches the compatible (pdev->dev.of_node):
for_each_child_of_node(svs->dev->of_node, np) {

  if (of_device_is_compatible(np, svsb->of_compatible)) {
    pdev->dev.of_node = np;
    break;

}
}

Then, thanks to that, the 2 functions dev_pm_opp_of_add_table and devm_regulator_get_optional "just work", as the get the opp table and regulator from the device tree node.

So what you suggest is basically something like this:
pdev->dev.of_node = of_find_compatible_node(NULL, NULL, "mediatek,mt8183-cci");

I came up with a (very dirty) prototype here:
https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/2076718
... and it doesn't really work
(https://gist.github.com/drinkcat/61e50eedbdc301d418c9cee3ee5b6b06, I think the kernel is probing more than it should, like the DMA mask errors should not happen...)

Quoted 3 lines

Before I dig further... I have the same concern as Roger, is it ok to have 2 devices bound to the same device tree node/compatible? My understanding was also that it's not.

Rob: It seems like this conversation died here. Do you have any suggestions for the above?

Thanks,