From 16a901fb940d24793492567fd1fac66608f3e400 Mon Sep 17 00:00:00 2001 From: Christian Marangi Date: Tue, 13 Sep 2022 22:14:20 +0200 Subject: [PATCH] ipq806x: 5.15: add rpm fixes for regulator Add rpm fixes for regulator to set it to OEM frequency and set system load. Signed-off-by: Christian Marangi --- ...pm-fix-wrong-freq-table-for-switch-m.patch | 98 +++++++++++++++++++ ...pm-add-support-to-set-regulator-syst.patch | 46 +++++++++ 2 files changed, 144 insertions(+) create mode 100644 target/linux/ipq806x/patches-5.15/120-01-regulator-qcom_rpm-fix-wrong-freq-table-for-switch-m.patch create mode 100644 target/linux/ipq806x/patches-5.15/120-02-regulator-qcom_rpm-add-support-to-set-regulator-syst.patch diff --git a/target/linux/ipq806x/patches-5.15/120-01-regulator-qcom_rpm-fix-wrong-freq-table-for-switch-m.patch b/target/linux/ipq806x/patches-5.15/120-01-regulator-qcom_rpm-fix-wrong-freq-table-for-switch-m.patch new file mode 100644 index 0000000000..b72db204f6 --- /dev/null +++ b/target/linux/ipq806x/patches-5.15/120-01-regulator-qcom_rpm-fix-wrong-freq-table-for-switch-m.patch @@ -0,0 +1,98 @@ +From 3a2eda673a09fbe474c7a3bd26026927f5ea3dbf Mon Sep 17 00:00:00 2001 +From: Christian Marangi +Date: Sun, 7 Aug 2022 20:17:17 +0200 +Subject: [PATCH 1/2] regulator: qcom_rpm: fix wrong freq table for + switch-mode-frequency + +Fix wrong freq table used for qcom,switch-mode-frequency to parse the +swich freq. + +We currently parse the index value on a wrong table that lacks of +some values. This cause the wrong index to be set in the RPM request. + +smb208 regulator for example can run at max 500 or 1000 kHz and this +freq is not present in the current table. Checking really old code +permits to get the real table and set the correct value. + +Fixes: 2720386ec5d4 ("regulator: qcom-rpm: Regulator driver for the Qualcomm RPM") +Signed-off-by: Christian Marangi +--- + drivers/regulator/qcom_rpm-regulator.c | 56 +++++++++++++++++++++----- + 1 file changed, 47 insertions(+), 9 deletions(-) + +--- a/drivers/regulator/qcom_rpm-regulator.c ++++ b/drivers/regulator/qcom_rpm-regulator.c +@@ -640,16 +640,54 @@ static int rpm_reg_set(struct qcom_rpm_r + return 0; + } + ++enum rpm_reg_freqs { ++ RPM_VREG_FREQ_NONE, ++ RPM_VREG_FREQ_0p50, ++ RPM_VREG_FREQ_1p00, ++ RPM_VREG_FREQ_19p20, ++ RPM_VREG_FREQ_9p60, ++ RPM_VREG_FREQ_6p40, ++ RPM_VREG_FREQ_4p80, ++ RPM_VREG_FREQ_3p84, ++ RPM_VREG_FREQ_3p20, ++ RPM_VREG_FREQ_2p74, ++ RPM_VREG_FREQ_2p40, ++ RPM_VREG_FREQ_2p13, ++ RPM_VREG_FREQ_1p92, ++ RPM_VREG_FREQ_1p75, ++ RPM_VREG_FREQ_1p60, ++ RPM_VREG_FREQ_1p48, ++ RPM_VREG_FREQ_1p37, ++ RPM_VREG_FREQ_1p28, ++ RPM_VREG_FREQ_1p20, ++}; ++ ++static const int rpm_reg_freq_tbl[] = { ++ [RPM_VREG_FREQ_NONE] = 0, ++ [RPM_VREG_FREQ_0p50] = 500000, ++ [RPM_VREG_FREQ_1p00] = 1000000, ++ [RPM_VREG_FREQ_19p20] = 19200000, ++ [RPM_VREG_FREQ_9p60] = 9600000, ++ [RPM_VREG_FREQ_6p40] = 6400000, ++ [RPM_VREG_FREQ_4p80] = 4800000, ++ [RPM_VREG_FREQ_3p84] = 3840000, ++ [RPM_VREG_FREQ_3p20] = 3200000, ++ [RPM_VREG_FREQ_2p74] = 2740000, ++ [RPM_VREG_FREQ_2p40] = 2400000, ++ [RPM_VREG_FREQ_2p13] = 2130000, ++ [RPM_VREG_FREQ_1p92] = 1920000, ++ [RPM_VREG_FREQ_1p75] = 1750000, ++ [RPM_VREG_FREQ_1p60] = 1600000, ++ [RPM_VREG_FREQ_1p48] = 1480000, ++ [RPM_VREG_FREQ_1p37] = 1370000, ++ [RPM_VREG_FREQ_1p28] = 1280000, ++ [RPM_VREG_FREQ_1p20] = 1200000, ++}; ++ + static int rpm_reg_of_parse_freq(struct device *dev, + struct device_node *node, + struct qcom_rpm_reg *vreg) + { +- static const int freq_table[] = { +- 19200000, 9600000, 6400000, 4800000, 3840000, 3200000, 2740000, +- 2400000, 2130000, 1920000, 1750000, 1600000, 1480000, 1370000, +- 1280000, 1200000, +- +- }; + const char *key; + u32 freq; + int ret; +@@ -662,9 +700,9 @@ static int rpm_reg_of_parse_freq(struct + return -EINVAL; + } + +- for (i = 0; i < ARRAY_SIZE(freq_table); i++) { +- if (freq == freq_table[i]) { +- rpm_reg_set(vreg, &vreg->parts->freq, i + 1); ++ for (i = 0; i < ARRAY_SIZE(rpm_reg_freq_tbl); i++) { ++ if (freq == rpm_reg_freq_tbl[i]) { ++ rpm_reg_set(vreg, &vreg->parts->freq, i); + return 0; + } + } diff --git a/target/linux/ipq806x/patches-5.15/120-02-regulator-qcom_rpm-add-support-to-set-regulator-syst.patch b/target/linux/ipq806x/patches-5.15/120-02-regulator-qcom_rpm-add-support-to-set-regulator-syst.patch new file mode 100644 index 0000000000..79ecc6921e --- /dev/null +++ b/target/linux/ipq806x/patches-5.15/120-02-regulator-qcom_rpm-add-support-to-set-regulator-syst.patch @@ -0,0 +1,46 @@ +From 78e96cd2d710b041bab8073698d93d6aa41cccce Mon Sep 17 00:00:00 2001 +From: Christian Marangi +Date: Sun, 7 Aug 2022 21:42:16 +0200 +Subject: [PATCH 2/2] regulator: qcom_rpm: add support to set regulator system + load + +Add support to set regulator system load by setting the regulator +peak mA regs. If the provided value exceed the reg mask, the max +possible value is set instead of the DT value. + +Signed-off-by: Christian Marangi +--- + drivers/regulator/qcom_rpm-regulator.c | 22 ++++++++++++++++++++++ + 1 file changed, 22 insertions(+) + +--- a/drivers/regulator/qcom_rpm-regulator.c ++++ b/drivers/regulator/qcom_rpm-regulator.c +@@ -803,6 +803,28 @@ static int rpm_reg_of_parse(struct devic + } + } + ++ if (vreg->parts->ip.mask) { ++ u32 max_uA = (vreg->parts->ip.mask >> vreg->parts->ip.shift) * 1000; ++ key = "regulator-system-load"; ++ ++ ret = of_property_read_u32(node, key, &val); ++ if (ret == -EINVAL) { ++ val = max_uA; ++ } else if (ret < 0) { ++ dev_err(dev, "failed to read %s\n", key); ++ return ret; ++ } ++ ++ if (val > max_uA) ++ val = max_uA; ++ ++ ret = rpm_reg_set(vreg, &vreg->parts->ip, val / 1000); ++ if (ret) { ++ dev_err(dev, "failed to set peak mA\n"); ++ return ret; ++ } ++ } ++ + return 0; + } + -- 2.30.2