forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/soc/rockchip/rockchip_system_monitor.c
....@@ -5,8 +5,10 @@
55 */
66
77 #include <dt-bindings/soc/rockchip-system-status.h>
8
+#include <linux/clk-provider.h>
89 #include <linux/cpu.h>
910 #include <linux/cpufreq.h>
11
+#include <linux/devfreq.h>
1012 #include <linux/device.h>
1113 #include <linux/fb.h>
1214 #include <linux/module.h>
....@@ -15,26 +17,31 @@
1517 #include <linux/of.h>
1618 #include <linux/platform_device.h>
1719 #include <linux/pm_opp.h>
18
-#include <linux/uaccess.h>
20
+#include <linux/pm_qos.h>
21
+#include <linux/pm_runtime.h>
22
+#include <linux/regulator/consumer.h>
23
+#include <linux/regulator/coupler.h>
24
+#include <linux/regulator/driver.h>
25
+#include <linux/regulator/machine.h>
1926 #include <linux/reboot.h>
2027 #include <linux/slab.h>
2128 #include <linux/suspend.h>
2229 #include <linux/thermal.h>
30
+#include <linux/uaccess.h>
2331 #include <linux/version.h>
32
+#include <linux/delay.h>
33
+#include <soc/rockchip/rockchip_opp_select.h>
2434 #include <soc/rockchip/rockchip_system_monitor.h>
2535 #include <soc/rockchip/rockchip-system-status.h>
2636
27
-#include "../../opp/opp.h"
28
-#include "../../devfreq/governor.h"
29
-
3037 #include "../../gpu/drm/rockchip/ebc-dev/ebc_dev.h"
38
+#include "../../opp/opp.h"
39
+#include "../../regulator/internal.h"
40
+#include "../../thermal/thermal_core.h"
3141
3242 #define CPU_REBOOT_FREQ 816000 /* kHz */
3343 #define VIDEO_1080P_SIZE (1920 * 1080)
3444 #define THERMAL_POLLING_DELAY 200 /* milliseconds */
35
-
36
-#define devfreq_nb_to_monitor(nb) container_of(nb, struct monitor_dev_info, \
37
- devfreq_nb)
3845
3946 struct video_info {
4047 unsigned int width;
....@@ -64,11 +71,11 @@
6471
6572 struct thermal_zone_device *tz;
6673 struct delayed_work thermal_work;
74
+ int last_temp;
6775 int offline_cpus_temp;
6876 int temp_hysteresis;
6977 unsigned int delay;
7078 bool is_temp_offline;
71
- bool boosted;
7279 };
7380
7481 static unsigned long system_status;
....@@ -85,6 +92,7 @@
8592 static struct system_monitor *system_monitor;
8693 static atomic_t monitor_in_suspend;
8794
95
+static BLOCKING_NOTIFIER_HEAD(system_monitor_notifier_list);
8896 static BLOCKING_NOTIFIER_HEAD(system_status_notifier_list);
8997
9098 int rockchip_register_system_status_notifier(struct notifier_block *nb)
....@@ -174,9 +182,9 @@
174182 return -EINVAL;
175183 }
176184
177
- return __compat_only_sysfs_link_entry_to_kobj(&dev->kobj,
178
- system_monitor->kobj,
179
- "system_status");
185
+ return compat_only_sysfs_link_entry_to_kobj(&dev->kobj,
186
+ system_monitor->kobj,
187
+ "system_status", NULL);
180188 }
181189 EXPORT_SYMBOL(rockchip_add_system_status_interface);
182190
....@@ -360,6 +368,14 @@
360368 /* clear performance flag */
361369 rockchip_clear_system_status(SYS_STATUS_PERFORMANCE);
362370 break;
371
+ case 'S':
372
+ /* set video svep flag */
373
+ rockchip_set_system_status(SYS_STATUS_VIDEO_SVEP);
374
+ break;
375
+ case 's':
376
+ /* clear video svep flag */
377
+ rockchip_clear_system_status(SYS_STATUS_VIDEO_SVEP);
378
+ break;
363379 default:
364380 break;
365381 }
....@@ -497,8 +513,11 @@
497513 int delta_volt = 0;
498514 int i = 0, max_count;
499515 unsigned long low_limit = 0, high_limit = 0;
516
+ unsigned long low_limit_mem = 0, high_limit_mem = 0;
500517 bool reach_max_volt = false;
518
+ bool reach_max_mem_volt = false;
501519 bool reach_high_temp_max_volt = false;
520
+ bool reach_high_temp_max_mem_volt = false;
502521
503522 max_count = dev_pm_opp_get_opp_count(dev);
504523 if (max_count <= 0)
....@@ -516,6 +535,8 @@
516535 }
517536 mutex_lock(&opp_table->lock);
518537 list_for_each_entry(opp, &opp_table->opp_list, node) {
538
+ if (!opp->available)
539
+ continue;
519540 info->opp_table[i].rate = opp->rate;
520541 info->opp_table[i].volt = opp->supplies[0].u_volt;
521542 info->opp_table[i].max_volt = opp->supplies[0].u_volt_max;
....@@ -547,9 +568,48 @@
547568 info->low_limit = low_limit;
548569 if (high_limit && high_limit != opp->rate)
549570 info->high_limit = high_limit;
550
- dev_dbg(dev, "rate=%lu, volt=%lu, low_temp_volt=%lu\n",
571
+
572
+ if (opp_table->regulator_count > 1) {
573
+ info->opp_table[i].mem_volt = opp->supplies[1].u_volt;
574
+ info->opp_table[i].max_mem_volt = opp->supplies[1].u_volt_max;
575
+
576
+ if (opp->supplies[1].u_volt <= info->high_temp_max_volt) {
577
+ if (!reach_high_temp_max_mem_volt)
578
+ high_limit_mem = opp->rate;
579
+ if (opp->supplies[1].u_volt == info->high_temp_max_volt)
580
+ reach_high_temp_max_mem_volt = true;
581
+ }
582
+
583
+ if ((opp->supplies[1].u_volt + delta_volt) <= info->max_volt) {
584
+ info->opp_table[i].low_temp_mem_volt =
585
+ opp->supplies[1].u_volt + delta_volt;
586
+ if (info->opp_table[i].low_temp_mem_volt <
587
+ info->low_temp_min_volt)
588
+ info->opp_table[i].low_temp_mem_volt =
589
+ info->low_temp_min_volt;
590
+ if (!reach_max_mem_volt)
591
+ low_limit_mem = opp->rate;
592
+ if (info->opp_table[i].low_temp_mem_volt == info->max_volt)
593
+ reach_max_mem_volt = true;
594
+ } else {
595
+ info->opp_table[i].low_temp_mem_volt = info->max_volt;
596
+ }
597
+
598
+ if (low_limit_mem && low_limit_mem != opp->rate) {
599
+ if (info->low_limit > low_limit_mem)
600
+ info->low_limit = low_limit_mem;
601
+ }
602
+ if (high_limit_mem && high_limit_mem != opp->rate) {
603
+ if (info->high_limit > high_limit_mem)
604
+ info->high_limit = high_limit_mem;
605
+ }
606
+ }
607
+
608
+ dev_dbg(dev, "rate=%lu, volt=%lu %lu low_temp_volt=%lu %lu\n",
551609 info->opp_table[i].rate, info->opp_table[i].volt,
552
- info->opp_table[i].low_temp_volt);
610
+ info->opp_table[i].mem_volt,
611
+ info->opp_table[i].low_temp_volt,
612
+ info->opp_table[i].low_temp_mem_volt);
553613 i++;
554614 }
555615 mutex_unlock(&opp_table->lock);
....@@ -591,9 +651,12 @@
591651 else
592652 info->high_temp_max_volt = value;
593653 rockchip_init_temp_opp_table(info);
594
- if (rockchip_get_temp_freq_table(np, "rockchip,high-temp-limit-table",
595
- &info->high_limit_table)) {
596
- info->high_limit_table = NULL;
654
+ rockchip_get_temp_freq_table(np, "rockchip,temp-freq-table",
655
+ &info->high_limit_table);
656
+ if (!info->high_limit_table)
657
+ rockchip_get_temp_freq_table(np, "rockchip,high-temp-limit-table",
658
+ &info->high_limit_table);
659
+ if (!info->high_limit_table) {
597660 if (!of_property_read_u32(np, "rockchip,high-temp-max-freq",
598661 &value)) {
599662 high_temp_max_freq = value * 1000;
....@@ -645,7 +708,7 @@
645708 &info->video_4k_freq);
646709 ret &= of_property_read_u32(np, "rockchip,reboot-freq",
647710 &info->reboot_freq);
648
- if (info->devp->type == MONITOR_TPYE_CPU) {
711
+ if (info->devp->type == MONITOR_TYPE_CPU) {
649712 if (!info->reboot_freq) {
650713 info->reboot_freq = CPU_REBOOT_FREQ;
651714 ret = 0;
....@@ -655,66 +718,70 @@
655718 return ret;
656719 }
657720
721
+static int monitor_device_parse_early_min_volt(struct device_node *np,
722
+ struct monitor_dev_info *info)
723
+{
724
+ return of_property_read_u32(np, "rockchip,early-min-microvolt",
725
+ &info->early_min_volt);
726
+}
727
+
728
+static int monitor_device_parse_read_margin(struct device_node *np,
729
+ struct monitor_dev_info *info)
730
+{
731
+ if (of_property_read_bool(np, "volt-mem-read-margin"))
732
+ return 0;
733
+ return -EINVAL;
734
+}
735
+
736
+static int monitor_device_parse_scmi_clk(struct device_node *np,
737
+ struct monitor_dev_info *info)
738
+{
739
+ struct clk *clk;
740
+
741
+ clk = clk_get(info->dev, NULL);
742
+ if (strstr(__clk_get_name(clk), "scmi"))
743
+ return 0;
744
+ return -EINVAL;
745
+}
746
+
658747 static int monitor_device_parse_dt(struct device *dev,
659748 struct monitor_dev_info *info)
660749 {
661750 struct device_node *np;
662
- int ret = 0;
663
- bool is_wide_temp_en = false;
664
- bool is_status_limit_en = false;
665
- bool is_temp_freq_en = false;
751
+ int ret;
666752
667753 np = of_parse_phandle(dev->of_node, "operating-points-v2", 0);
668754 if (!np)
669755 return -EINVAL;
670756
671
- if (!monitor_device_parse_wide_temp_config(np, info))
672
- is_wide_temp_en = true;
673
- if (!monitor_device_parse_status_config(np, info))
674
- is_status_limit_en = true;
675
- if (!rockchip_get_temp_freq_table(np, "rockchip,temp-freq-table",
676
- &info->temp_freq_table))
677
- is_temp_freq_en = true;
678
- if (is_wide_temp_en || is_status_limit_en || is_temp_freq_en)
679
- ret = 0;
680
- else
681
- ret = -EINVAL;
757
+ of_property_read_u32(np, "rockchip,init-freq", &info->init_freq);
758
+
759
+ ret = monitor_device_parse_wide_temp_config(np, info);
760
+ ret &= monitor_device_parse_status_config(np, info);
761
+ ret &= monitor_device_parse_early_min_volt(np, info);
762
+ ret &= monitor_device_parse_read_margin(np, info);
763
+ ret &= monitor_device_parse_scmi_clk(np, info);
682764
683765 of_node_put(np);
684766
685767 return ret;
686768 }
687769
688
-int rockchip_monitor_opp_set_rate(struct monitor_dev_info *info,
689
- unsigned long target_freq)
690
-{
691
- int ret = 0;
692
-
693
- mutex_lock(&info->volt_adjust_mutex);
694
- ret = dev_pm_opp_set_rate(info->dev, target_freq);
695
- mutex_unlock(&info->volt_adjust_mutex);
696
-
697
- return ret;
698
-}
699
-EXPORT_SYMBOL(rockchip_monitor_opp_set_rate);
700
-
701770 int rockchip_monitor_cpu_low_temp_adjust(struct monitor_dev_info *info,
702771 bool is_low)
703772 {
704
- struct device *dev = info->dev;
705
- unsigned int cpu = cpumask_any(&info->devp->allowed_cpus);
773
+ if (!info->low_limit)
774
+ return 0;
706775
707
- if (info->low_limit) {
708
- if (is_low)
709
- info->wide_temp_limit = info->low_limit;
710
- else
711
- info->wide_temp_limit = 0;
712
- cpufreq_update_policy(cpu);
713
- }
776
+ if (!freq_qos_request_active(&info->max_temp_freq_req))
777
+ return 0;
714778
715
- mutex_lock(&info->volt_adjust_mutex);
716
- dev_pm_opp_check_rate_volt(dev, false);
717
- mutex_unlock(&info->volt_adjust_mutex);
779
+ if (is_low)
780
+ freq_qos_update_request(&info->max_temp_freq_req,
781
+ info->low_limit / 1000);
782
+ else
783
+ freq_qos_update_request(&info->max_temp_freq_req,
784
+ FREQ_QOS_MAX_DEFAULT_VALUE);
718785
719786 return 0;
720787 }
....@@ -723,69 +790,44 @@
723790 int rockchip_monitor_cpu_high_temp_adjust(struct monitor_dev_info *info,
724791 bool is_high)
725792 {
726
- unsigned int cpu = cpumask_any(&info->devp->allowed_cpus);
793
+ if (!info->high_limit)
794
+ return 0;
795
+
796
+ if (!freq_qos_request_active(&info->max_temp_freq_req))
797
+ return 0;
727798
728799 if (info->high_limit_table) {
729
- info->wide_temp_limit = info->high_limit;
730
- cpufreq_update_policy(cpu);
731
- } else {
732
- if (info->high_limit) {
733
- if (is_high)
734
- info->wide_temp_limit = info->high_limit;
735
- else
736
- info->wide_temp_limit = 0;
737
- cpufreq_update_policy(cpu);
738
- }
800
+ freq_qos_update_request(&info->max_temp_freq_req,
801
+ info->high_limit / 1000);
802
+ return 0;
739803 }
804
+
805
+ if (is_high)
806
+ freq_qos_update_request(&info->max_temp_freq_req,
807
+ info->high_limit / 1000);
808
+ else
809
+ freq_qos_update_request(&info->max_temp_freq_req,
810
+ FREQ_QOS_MAX_DEFAULT_VALUE);
740811
741812 return 0;
742813 }
743814 EXPORT_SYMBOL(rockchip_monitor_cpu_high_temp_adjust);
744815
745
-void rockchip_monitor_set_boosted(void)
746
-{
747
- if (system_monitor)
748
- system_monitor->boosted = true;
749
-}
750
-EXPORT_SYMBOL(rockchip_monitor_set_boosted);
751
-
752
-void rockchip_monitor_clear_boosted(void)
753
-{
754
- if (system_monitor)
755
- system_monitor->boosted = false;
756
-}
757
-EXPORT_SYMBOL(rockchip_monitor_clear_boosted);
758
-
759
-static int rockchip_monitor_update_devfreq(struct devfreq *df)
760
-{
761
- int ret = 0;
762
-
763
-#ifdef CONFIG_PM_DEVFREQ
764
- mutex_lock(&df->lock);
765
- ret = update_devfreq(df);
766
- mutex_unlock(&df->lock);
767
-#endif
768
- return ret;
769
-};
770
-
771816 int rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info *info,
772817 bool is_low)
773818 {
774
- struct devfreq *df;
819
+ if (!dev_pm_qos_request_active(&info->dev_max_freq_req))
820
+ return 0;
775821
776
- if (info->low_limit) {
777
- if (is_low)
778
- info->wide_temp_limit = info->low_limit;
779
- else
780
- info->wide_temp_limit = 0;
781
- }
822
+ if (!info->low_limit)
823
+ return 0;
782824
783
- if (info->devp && info->devp->data) {
784
- df = (struct devfreq *)info->devp->data;
785
- rockchip_monitor_update_devfreq(df);
786
- } else if (info->devp && info->devp->low_temp_adjust_volt) {
787
- info->devp->low_temp_adjust_volt(info);
788
- }
825
+ if (is_low)
826
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
827
+ info->low_limit / 1000);
828
+ else
829
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
830
+ PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE);
789831
790832 return 0;
791833 }
....@@ -794,26 +836,24 @@
794836 int rockchip_monitor_dev_high_temp_adjust(struct monitor_dev_info *info,
795837 bool is_high)
796838 {
797
- struct devfreq *df;
839
+ if (!dev_pm_qos_request_active(&info->dev_max_freq_req))
840
+ return 0;
841
+
842
+ if (!info->high_limit)
843
+ return 0;
798844
799845 if (info->high_limit_table) {
800
- info->wide_temp_limit = info->high_limit;
801
- if (info->devp && info->devp->data) {
802
- df = (struct devfreq *)info->devp->data;
803
- rockchip_monitor_update_devfreq(df);
804
- }
805
- } else {
806
- if (info->high_limit) {
807
- if (is_high)
808
- info->wide_temp_limit = info->high_limit;
809
- else
810
- info->wide_temp_limit = 0;
811
- if (info->devp && info->devp->data) {
812
- df = (struct devfreq *)info->devp->data;
813
- rockchip_monitor_update_devfreq(df);
814
- }
815
- }
846
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
847
+ info->high_limit / 1000);
848
+ return 0;
816849 }
850
+
851
+ if (is_high)
852
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
853
+ info->high_limit / 1000);
854
+ else
855
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
856
+ PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE);
817857
818858 return 0;
819859 }
....@@ -833,6 +873,8 @@
833873
834874 mutex_lock(&opp_table->lock);
835875 list_for_each_entry(opp, &opp_table->opp_list, node) {
876
+ if (!opp->available)
877
+ continue;
836878 if (is_low_temp) {
837879 if (opp->supplies[0].u_volt_max <
838880 info->opp_table[i].low_temp_volt)
....@@ -841,11 +883,29 @@
841883 opp->supplies[0].u_volt =
842884 info->opp_table[i].low_temp_volt;
843885 opp->supplies[0].u_volt_min = opp->supplies[0].u_volt;
886
+ if (opp_table->regulator_count > 1) {
887
+ if (opp->supplies[1].u_volt_max <
888
+ info->opp_table[i].low_temp_mem_volt)
889
+ opp->supplies[1].u_volt_max =
890
+ info->opp_table[i].low_temp_mem_volt;
891
+ opp->supplies[1].u_volt =
892
+ info->opp_table[i].low_temp_mem_volt;
893
+ opp->supplies[1].u_volt_min =
894
+ opp->supplies[1].u_volt;
895
+ }
844896 } else {
845897 opp->supplies[0].u_volt_min = info->opp_table[i].volt;
846898 opp->supplies[0].u_volt = opp->supplies[0].u_volt_min;
847899 opp->supplies[0].u_volt_max =
848900 info->opp_table[i].max_volt;
901
+ if (opp_table->regulator_count > 1) {
902
+ opp->supplies[1].u_volt_min =
903
+ info->opp_table[i].mem_volt;
904
+ opp->supplies[1].u_volt =
905
+ opp->supplies[1].u_volt_min;
906
+ opp->supplies[1].u_volt_max =
907
+ info->opp_table[i].max_mem_volt;
908
+ }
849909 }
850910 i++;
851911 }
....@@ -871,6 +931,9 @@
871931 ret = devp->low_temp_adjust(info, is_low);
872932 if (!ret)
873933 info->is_low_temp = is_low;
934
+
935
+ if (devp->update_volt)
936
+ devp->update_volt(info);
874937 }
875938
876939 static void rockchip_high_temp_adjust(struct monitor_dev_info *info,
....@@ -879,12 +942,14 @@
879942 struct monitor_dev_profile *devp = info->devp;
880943 int ret = 0;
881944
945
+ if (!devp->high_temp_adjust)
946
+ return;
947
+
882948 if (info->high_limit_table) {
883949 devp->high_temp_adjust(info, is_high);
884950 } else {
885951 dev_dbg(info->dev, "high_temp %d\n", is_high);
886
- if (devp->high_temp_adjust)
887
- ret = devp->high_temp_adjust(info, is_high);
952
+ ret = devp->high_temp_adjust(info, is_high);
888953 if (!ret)
889954 info->is_high_temp = is_high;
890955 }
....@@ -895,7 +960,7 @@
895960 struct monitor_dev_info *info = NULL, *tmp;
896961
897962 list_for_each_entry(tmp, &monitor_dev_list, node) {
898
- if (tmp->devp->type != MONITOR_TPYE_CPU)
963
+ if (tmp->devp->type != MONITOR_TYPE_CPU)
899964 continue;
900965 if (cpumask_test_cpu(cpu, &tmp->devp->allowed_cpus)) {
901966 info = tmp;
....@@ -962,6 +1027,9 @@
9621027 {
9631028 int ret, temp;
9641029
1030
+ if (!info->opp_table)
1031
+ return;
1032
+
9651033 /*
9661034 * set the init state to low temperature that the voltage will be enough
9671035 * when cpu up at low temperature.
....@@ -969,7 +1037,6 @@
9691037 if (!info->is_low_temp) {
9701038 if (info->opp_table)
9711039 rockchip_adjust_low_temp_opp_volt(info, true);
972
- info->wide_temp_limit = info->low_limit;
9731040 info->is_low_temp = true;
9741041 }
9751042
....@@ -984,150 +1051,372 @@
9841051 if (info->opp_table)
9851052 rockchip_adjust_low_temp_opp_volt(info, false);
9861053 info->is_low_temp = false;
987
-
988
- info->wide_temp_limit = info->high_limit;
9891054 info->is_high_temp = true;
9901055 } else if (temp > (info->low_temp + info->temp_hysteresis)) {
9911056 if (info->opp_table)
9921057 rockchip_adjust_low_temp_opp_volt(info, false);
9931058 info->is_low_temp = false;
994
- info->wide_temp_limit = 0;
9951059 }
9961060 }
9971061
998
-static int system_monitor_devfreq_notifier_call(struct notifier_block *nb,
999
- unsigned long event,
1000
- void *data)
1062
+static const char *get_rdev_name(struct regulator_dev *rdev)
10011063 {
1002
- struct monitor_dev_info *info = devfreq_nb_to_monitor(nb);
1003
- struct devfreq_policy *policy = data;
1004
-
1005
- if (event != DEVFREQ_ADJUST)
1006
- return NOTIFY_DONE;
1007
-
1008
- if (info->wide_temp_limit && info->wide_temp_limit < policy->max)
1009
- devfreq_verify_within_limits(policy, 0, info->wide_temp_limit);
1010
-
1011
- return NOTIFY_OK;
1064
+ if (rdev->constraints && rdev->constraints->name)
1065
+ return rdev->constraints->name;
1066
+ else if (rdev->desc->name)
1067
+ return rdev->desc->name;
1068
+ else
1069
+ return "";
10121070 }
10131071
1014
-static int monitor_set_freq_table(struct device *dev,
1015
- struct monitor_dev_info *info)
1072
+static void
1073
+rockchip_system_monitor_early_regulator_init(struct monitor_dev_info *info)
10161074 {
1017
- struct opp_table *opp_table;
1018
- struct dev_pm_opp *opp;
1019
- unsigned long *freq_table;
1020
- int count;
1075
+ struct regulator *reg;
1076
+ struct regulator_dev *rdev;
10211077
1022
- opp_table = dev_pm_opp_get_opp_table(dev);
1023
- if (!opp_table)
1024
- return -ENOMEM;
1078
+ if (!info->early_min_volt || !info->regulators)
1079
+ return;
10251080
1026
- /* Initialize the freq_table from OPP table */
1027
- count = dev_pm_opp_get_opp_count(dev);
1028
- if (count <= 0)
1029
- return -EINVAL;
1030
-
1031
- info->max_state = count;
1032
- freq_table = kcalloc(count, sizeof(*info->freq_table), GFP_KERNEL);
1033
- if (!freq_table) {
1034
- info->max_state = 0;
1035
- return -ENOMEM;
1081
+ rdev = info->regulators[0]->rdev;
1082
+ reg = regulator_get(NULL, get_rdev_name(rdev));
1083
+ if (!IS_ERR_OR_NULL(reg)) {
1084
+ info->early_reg = reg;
1085
+ reg->voltage[PM_SUSPEND_ON].min_uV = info->early_min_volt;
1086
+ reg->voltage[PM_SUSPEND_ON].max_uV = rdev->constraints->max_uV;
10361087 }
1088
+}
10371089
1038
- mutex_lock(&opp_table->lock);
1039
- list_for_each_entry(opp, &opp_table->opp_list, node) {
1040
- if (opp->available) {
1041
- count--;
1042
- freq_table[count] = opp->rate;
1090
+static int
1091
+rockchip_system_monitor_freq_qos_requset(struct monitor_dev_info *info)
1092
+{
1093
+ struct devfreq *devfreq;
1094
+ struct cpufreq_policy *policy;
1095
+ int max_default_value = FREQ_QOS_MAX_DEFAULT_VALUE;
1096
+ int ret;
1097
+
1098
+ if (!info->devp->data)
1099
+ return 0;
1100
+
1101
+ if (info->is_low_temp && info->low_limit)
1102
+ max_default_value = info->low_limit / 1000;
1103
+ else if (info->is_high_temp && info->high_limit)
1104
+ max_default_value = info->high_limit / 1000;
1105
+
1106
+ if (info->devp->type == MONITOR_TYPE_CPU) {
1107
+ policy = (struct cpufreq_policy *)info->devp->data;
1108
+ ret = freq_qos_add_request(&policy->constraints,
1109
+ &info->max_temp_freq_req,
1110
+ FREQ_QOS_MAX,
1111
+ max_default_value);
1112
+ if (ret < 0) {
1113
+ dev_info(info->dev,
1114
+ "failed to add temp freq constraint\n");
1115
+ return ret;
1116
+ }
1117
+ ret = freq_qos_add_request(&policy->constraints,
1118
+ &info->min_sta_freq_req,
1119
+ FREQ_QOS_MIN,
1120
+ FREQ_QOS_MIN_DEFAULT_VALUE);
1121
+ if (ret < 0) {
1122
+ dev_info(info->dev,
1123
+ "failed to add sta freq constraint\n");
1124
+ freq_qos_remove_request(&info->max_temp_freq_req);
1125
+ return ret;
1126
+ }
1127
+ ret = freq_qos_add_request(&policy->constraints,
1128
+ &info->max_sta_freq_req,
1129
+ FREQ_QOS_MAX,
1130
+ FREQ_QOS_MAX_DEFAULT_VALUE);
1131
+ if (ret < 0) {
1132
+ dev_info(info->dev,
1133
+ "failed to add sta freq constraint\n");
1134
+ freq_qos_remove_request(&info->max_temp_freq_req);
1135
+ freq_qos_remove_request(&info->min_sta_freq_req);
1136
+ return ret;
1137
+ }
1138
+ } else if (info->devp->type == MONITOR_TYPE_DEV) {
1139
+ devfreq = (struct devfreq *)info->devp->data;
1140
+ ret = dev_pm_qos_add_request(devfreq->dev.parent,
1141
+ &info->dev_max_freq_req,
1142
+ DEV_PM_QOS_MAX_FREQUENCY,
1143
+ max_default_value);
1144
+ if (ret < 0) {
1145
+ dev_info(info->dev, "failed to add freq constraint\n");
1146
+ return ret;
10431147 }
10441148 }
1045
- mutex_unlock(&opp_table->lock);
1149
+
1150
+ return 0;
1151
+}
1152
+
1153
+static int rockchip_system_monitor_parse_supplies(struct device *dev,
1154
+ struct monitor_dev_info *info)
1155
+{
1156
+ struct opp_table *opp_table;
1157
+ struct dev_pm_set_opp_data *data;
1158
+ int len, count;
1159
+
1160
+ opp_table = dev_pm_opp_get_opp_table(dev);
1161
+ if (IS_ERR(opp_table))
1162
+ return PTR_ERR(opp_table);
1163
+
1164
+ if (opp_table->clk)
1165
+ info->clk = opp_table->clk;
1166
+ if (opp_table->regulators)
1167
+ info->regulators = opp_table->regulators;
1168
+ info->regulator_count = opp_table->regulator_count;
1169
+
1170
+ if (opp_table->regulators && info->devp->set_opp) {
1171
+ count = opp_table->regulator_count;
1172
+ /* space for set_opp_data */
1173
+ len = sizeof(*data);
1174
+ /* space for old_opp.supplies and new_opp.supplies */
1175
+ len += 2 * sizeof(struct dev_pm_opp_supply) * count;
1176
+ data = kzalloc(len, GFP_KERNEL);
1177
+ if (!data)
1178
+ return -ENOMEM;
1179
+ data->old_opp.supplies = (void *)(data + 1);
1180
+ data->new_opp.supplies = data->old_opp.supplies + count;
1181
+ info->set_opp_data = data;
1182
+ }
10461183
10471184 dev_pm_opp_put_opp_table(opp_table);
10481185
1049
- info->freq_table = freq_table;
1186
+ return 0;
1187
+}
1188
+
1189
+void rockchip_monitor_volt_adjust_lock(struct monitor_dev_info *info)
1190
+{
1191
+ if (info)
1192
+ mutex_lock(&info->volt_adjust_mutex);
1193
+}
1194
+EXPORT_SYMBOL(rockchip_monitor_volt_adjust_lock);
1195
+
1196
+void rockchip_monitor_volt_adjust_unlock(struct monitor_dev_info *info)
1197
+{
1198
+ if (info)
1199
+ mutex_unlock(&info->volt_adjust_mutex);
1200
+}
1201
+EXPORT_SYMBOL(rockchip_monitor_volt_adjust_unlock);
1202
+
1203
+static int rockchip_monitor_enable_opp_clk(struct device *dev,
1204
+ struct rockchip_opp_info *opp_info)
1205
+{
1206
+ int ret = 0;
1207
+
1208
+ if (!opp_info)
1209
+ return 0;
1210
+
1211
+ ret = clk_bulk_prepare_enable(opp_info->num_clks, opp_info->clks);
1212
+ if (ret) {
1213
+ dev_err(dev, "failed to enable opp clks\n");
1214
+ return ret;
1215
+ }
10501216
10511217 return 0;
10521218 }
10531219
1054
-static unsigned long monitor_freq_to_state(struct monitor_dev_info *info,
1055
- unsigned long freq)
1220
+static void rockchip_monitor_disable_opp_clk(struct device *dev,
1221
+ struct rockchip_opp_info *opp_info)
10561222 {
1057
- unsigned long i = 0;
1223
+ if (!opp_info)
1224
+ return;
10581225
1059
- if (!info->freq_table) {
1060
- dev_info(info->dev, "failed to get freq_table");
1061
- return 0;
1062
- }
1063
-
1064
- for (i = 0; i < info->max_state; i++) {
1065
- if (freq >= info->freq_table[i])
1066
- return i;
1067
- }
1068
-
1069
- return info->max_state - 1;
1226
+ clk_bulk_disable_unprepare(opp_info->num_clks, opp_info->clks);
10701227 }
10711228
1072
-static int monitor_temp_to_state(struct monitor_dev_info *info,
1073
- int temp, unsigned long *state)
1229
+static int rockchip_monitor_set_opp(struct monitor_dev_info *info,
1230
+ unsigned long old_freq,
1231
+ unsigned long freq,
1232
+ struct dev_pm_opp_supply *old_supply,
1233
+ struct dev_pm_opp_supply *new_supply)
10741234 {
1075
- unsigned long target_state, target_freq = 0;
1076
- int i;
1235
+ struct dev_pm_set_opp_data *data;
1236
+ int size;
10771237
1078
- if (temp == THERMAL_TEMP_INVALID)
1238
+ data = info->set_opp_data;
1239
+ data->regulators = info->regulators;
1240
+ data->regulator_count = info->regulator_count;
1241
+ data->clk = info->clk;
1242
+ data->dev = info->dev;
1243
+
1244
+ data->old_opp.rate = old_freq;
1245
+ size = sizeof(*old_supply) * info->regulator_count;
1246
+ if (!old_supply)
1247
+ memset(data->old_opp.supplies, 0, size);
1248
+ else
1249
+ memcpy(data->old_opp.supplies, old_supply, size);
1250
+
1251
+ data->new_opp.rate = freq;
1252
+ memcpy(data->new_opp.supplies, new_supply, size);
1253
+
1254
+ return info->devp->set_opp(data);
1255
+}
1256
+
1257
+int rockchip_monitor_check_rate_volt(struct monitor_dev_info *info)
1258
+{
1259
+ struct device *dev = info->dev;
1260
+ struct regulator *vdd_reg = NULL;
1261
+ struct regulator *mem_reg = NULL;
1262
+ struct rockchip_opp_info *opp_info = info->devp->opp_info;
1263
+ struct dev_pm_opp *opp;
1264
+ unsigned long old_rate, new_rate, new_volt, new_mem_volt;
1265
+ int old_volt, old_mem_volt;
1266
+ u32 target_rm = UINT_MAX;
1267
+ bool is_set_clk = true;
1268
+ bool is_set_rm = false;
1269
+ int ret = 0;
1270
+
1271
+ if (!info->regulators || !info->clk)
10791272 return 0;
1080
- if (info->temp_freq_table) {
1081
- for (i = 0; info->temp_freq_table[i].freq != UINT_MAX; i++) {
1082
- if (temp > info->temp_freq_table[i].temp)
1083
- target_freq = info->temp_freq_table[i].freq;
1273
+
1274
+ mutex_lock(&info->volt_adjust_mutex);
1275
+
1276
+ vdd_reg = info->regulators[0];
1277
+ old_rate = clk_get_rate(info->clk);
1278
+ old_volt = regulator_get_voltage(vdd_reg);
1279
+ if (info->regulator_count > 1) {
1280
+ mem_reg = info->regulators[1];
1281
+ old_mem_volt = regulator_get_voltage(mem_reg);
1282
+ }
1283
+
1284
+ if (info->init_freq) {
1285
+ new_rate = info->init_freq * 1000;
1286
+ info->init_freq = 0;
1287
+ } else {
1288
+ new_rate = old_rate;
1289
+ }
1290
+ opp = dev_pm_opp_find_freq_ceil(dev, &new_rate);
1291
+ if (IS_ERR(opp)) {
1292
+ opp = dev_pm_opp_find_freq_floor(dev, &new_rate);
1293
+ if (IS_ERR(opp)) {
1294
+ ret = PTR_ERR(opp);
1295
+ goto unlock;
10841296 }
1085
- if (target_freq)
1086
- *state = monitor_freq_to_state(info,
1087
- target_freq * 1000);
1088
- else
1089
- *state = 0;
1297
+ }
1298
+ new_volt = opp->supplies[0].u_volt;
1299
+ if (info->regulator_count > 1)
1300
+ new_mem_volt = opp->supplies[1].u_volt;
1301
+ dev_pm_opp_put(opp);
1302
+
1303
+ if (old_rate == new_rate) {
1304
+ if (info->regulator_count > 1) {
1305
+ if (old_volt == new_volt &&
1306
+ new_mem_volt == old_mem_volt)
1307
+ goto unlock;
1308
+ } else if (old_volt == new_volt) {
1309
+ goto unlock;
1310
+ }
1311
+ }
1312
+ if (!new_volt || (info->regulator_count > 1 && !new_mem_volt))
1313
+ goto unlock;
1314
+
1315
+ if (info->devp->set_opp) {
1316
+ ret = rockchip_monitor_set_opp(info, old_rate, new_rate,
1317
+ NULL, opp->supplies);
1318
+ goto unlock;
10901319 }
10911320
1092
- if (info->status_min_limit) {
1093
- target_freq = info->status_min_limit * 1000;
1094
- target_state = monitor_freq_to_state(info, target_freq);
1095
- if (*state > target_state)
1096
- *state = target_state;
1321
+ if (opp_info && opp_info->data && opp_info->data->set_read_margin) {
1322
+ is_set_rm = true;
1323
+ if (info->devp->type == MONITOR_TYPE_DEV) {
1324
+ if (!pm_runtime_active(dev)) {
1325
+ is_set_rm = false;
1326
+ if (opp_info->scmi_clk)
1327
+ is_set_clk = false;
1328
+ }
1329
+ }
10971330 }
1331
+ rockchip_monitor_enable_opp_clk(dev, opp_info);
1332
+ rockchip_get_read_margin(dev, opp_info, new_volt, &target_rm);
10981333
1099
- return 0;
1334
+ dev_dbg(dev, "%s: %lu Hz --> %lu Hz\n", __func__, old_rate, new_rate);
1335
+ if (new_rate >= old_rate) {
1336
+ rockchip_set_intermediate_rate(dev, opp_info, info->clk,
1337
+ old_rate, new_rate,
1338
+ true, is_set_clk);
1339
+ if (info->regulator_count > 1) {
1340
+ ret = regulator_set_voltage(mem_reg, new_mem_volt,
1341
+ INT_MAX);
1342
+ if (ret) {
1343
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1344
+ __func__, new_mem_volt);
1345
+ goto restore_voltage;
1346
+ }
1347
+ }
1348
+ ret = regulator_set_voltage(vdd_reg, new_volt, INT_MAX);
1349
+ if (ret) {
1350
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1351
+ __func__, new_volt);
1352
+ goto restore_voltage;
1353
+ }
1354
+ rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm);
1355
+ if (is_set_clk && clk_set_rate(info->clk, new_rate)) {
1356
+ dev_err(dev, "%s: failed to set clock rate: %lu\n",
1357
+ __func__, new_rate);
1358
+ goto restore_rm;
1359
+ }
1360
+ } else {
1361
+ rockchip_set_intermediate_rate(dev, opp_info, info->clk,
1362
+ old_rate, new_rate,
1363
+ false, is_set_clk);
1364
+ rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm);
1365
+ if (is_set_clk && clk_set_rate(info->clk, new_rate)) {
1366
+ dev_err(dev, "%s: failed to set clock rate: %lu\n",
1367
+ __func__, new_rate);
1368
+ goto restore_rm;
1369
+ }
1370
+ ret = regulator_set_voltage(vdd_reg, new_volt,
1371
+ INT_MAX);
1372
+ if (ret) {
1373
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1374
+ __func__, new_volt);
1375
+ goto restore_freq;
1376
+ }
1377
+ if (info->regulator_count > 1) {
1378
+ ret = regulator_set_voltage(mem_reg, new_mem_volt,
1379
+ INT_MAX);
1380
+ if (ret) {
1381
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1382
+ __func__, new_mem_volt);
1383
+ goto restore_freq;
1384
+ }
1385
+ }
1386
+ }
1387
+ goto disable_clk;
1388
+
1389
+restore_freq:
1390
+ if (is_set_clk && clk_set_rate(info->clk, old_rate))
1391
+ dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
1392
+ __func__, old_rate);
1393
+restore_rm:
1394
+ rockchip_get_read_margin(dev, opp_info, old_volt, &target_rm);
1395
+ rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm);
1396
+restore_voltage:
1397
+ if (info->regulator_count > 1)
1398
+ regulator_set_voltage(mem_reg, old_mem_volt, INT_MAX);
1399
+ regulator_set_voltage(vdd_reg, old_volt, INT_MAX);
1400
+disable_clk:
1401
+ rockchip_monitor_disable_opp_clk(dev, opp_info);
1402
+unlock:
1403
+ mutex_unlock(&info->volt_adjust_mutex);
1404
+
1405
+ return ret;
11001406 }
1101
-
1102
-int
1103
-rockchip_system_monitor_adjust_cdev_state(struct thermal_cooling_device *cdev,
1104
- int temp, unsigned long *state)
1105
-{
1106
- struct monitor_dev_info *info;
1107
-
1108
- down_read(&mdev_list_sem);
1109
- list_for_each_entry(info, &monitor_dev_list, node) {
1110
- if (cdev->np != info->dev->of_node)
1111
- continue;
1112
- monitor_temp_to_state(info, temp, state);
1113
- break;
1114
- }
1115
- up_read(&mdev_list_sem);
1116
-
1117
- return 0;
1118
-}
1119
-EXPORT_SYMBOL(rockchip_system_monitor_adjust_cdev_state);
1407
+EXPORT_SYMBOL(rockchip_monitor_check_rate_volt);
11201408
11211409 struct monitor_dev_info *
11221410 rockchip_system_monitor_register(struct device *dev,
11231411 struct monitor_dev_profile *devp)
11241412 {
11251413 struct monitor_dev_info *info;
1126
- struct devfreq *devfreq;
1127
- int ret;
11281414
11291415 if (!system_monitor)
11301416 return ERR_PTR(-ENOMEM);
1417
+
1418
+ if (!devp)
1419
+ return ERR_PTR(-EINVAL);
11311420
11321421 info = kzalloc(sizeof(*info), GFP_KERNEL);
11331422 if (!info)
....@@ -1135,39 +1424,33 @@
11351424 info->dev = dev;
11361425 info->devp = devp;
11371426
1138
- ret = monitor_device_parse_dt(dev, info);
1139
- if (ret)
1140
- goto free_info;
1427
+ mutex_init(&info->volt_adjust_mutex);
11411428
1142
- monitor_set_freq_table(dev, info);
1143
-
1144
- if (info->devp->type == MONITOR_TPYE_DEV && info->devp->data) {
1145
- info->devfreq_nb.notifier_call =
1146
- system_monitor_devfreq_notifier_call;
1147
- devfreq = (struct devfreq *)info->devp->data;
1148
- devm_devfreq_register_notifier(dev, devfreq, &info->devfreq_nb,
1149
- DEVFREQ_POLICY_NOTIFIER);
1429
+ rockchip_system_monitor_parse_supplies(dev, info);
1430
+ if (monitor_device_parse_dt(dev, info)) {
1431
+ rockchip_monitor_check_rate_volt(info);
1432
+ devp->is_checked = true;
1433
+ kfree(info->set_opp_data);
1434
+ kfree(info);
1435
+ return ERR_PTR(-EINVAL);
11501436 }
11511437
1438
+ rockchip_system_monitor_early_regulator_init(info);
11521439 rockchip_system_monitor_wide_temp_init(info);
1153
- mutex_init(&info->volt_adjust_mutex);
1440
+ rockchip_monitor_check_rate_volt(info);
1441
+ devp->is_checked = true;
1442
+ rockchip_system_monitor_freq_qos_requset(info);
11541443
11551444 down_write(&mdev_list_sem);
11561445 list_add(&info->node, &monitor_dev_list);
11571446 up_write(&mdev_list_sem);
11581447
11591448 return info;
1160
-
1161
-free_info:
1162
- kfree(info);
1163
- return ERR_PTR(-EINVAL);
11641449 }
11651450 EXPORT_SYMBOL(rockchip_system_monitor_register);
11661451
11671452 void rockchip_system_monitor_unregister(struct monitor_dev_info *info)
11681453 {
1169
- struct devfreq *devfreq;
1170
-
11711454 if (!info)
11721455 return;
11731456
....@@ -1175,19 +1458,59 @@
11751458 list_del(&info->node);
11761459 up_write(&mdev_list_sem);
11771460
1178
- if (info->devp->type == MONITOR_TPYE_DEV && info->devp->data) {
1179
- devfreq = (struct devfreq *)info->devp->data;
1180
- devm_devfreq_unregister_notifier(info->dev, devfreq,
1181
- &info->devfreq_nb,
1182
- DEVFREQ_TRANSITION_NOTIFIER);
1461
+ if (info->devp->type == MONITOR_TYPE_CPU) {
1462
+ if (freq_qos_request_active(&info->max_temp_freq_req))
1463
+ freq_qos_remove_request(&info->max_temp_freq_req);
1464
+ if (freq_qos_request_active(&info->min_sta_freq_req))
1465
+ freq_qos_remove_request(&info->min_sta_freq_req);
1466
+ if (freq_qos_request_active(&info->max_sta_freq_req))
1467
+ freq_qos_remove_request(&info->max_sta_freq_req);
1468
+ } else {
1469
+ if (dev_pm_qos_request_active(&info->dev_max_freq_req))
1470
+ dev_pm_qos_remove_request(&info->dev_max_freq_req);
11831471 }
11841472
11851473 kfree(info->low_temp_adjust_table);
11861474 kfree(info->opp_table);
1187
- kfree(info->freq_table);
1475
+ kfree(info->set_opp_data);
11881476 kfree(info);
11891477 }
11901478 EXPORT_SYMBOL(rockchip_system_monitor_unregister);
1479
+
1480
+int rockchip_system_monitor_register_notifier(struct notifier_block *nb)
1481
+{
1482
+ return blocking_notifier_chain_register(&system_monitor_notifier_list, nb);
1483
+}
1484
+EXPORT_SYMBOL(rockchip_system_monitor_register_notifier);
1485
+
1486
+void rockchip_system_monitor_unregister_notifier(struct notifier_block *nb)
1487
+{
1488
+ blocking_notifier_chain_unregister(&system_monitor_notifier_list, nb);
1489
+}
1490
+EXPORT_SYMBOL(rockchip_system_monitor_unregister_notifier);
1491
+
1492
+static int rockchip_system_monitor_temp_notify(int temp)
1493
+{
1494
+ struct system_monitor_event_data event_data;
1495
+ int ret;
1496
+
1497
+ event_data.temp = temp;
1498
+ ret = blocking_notifier_call_chain(&system_monitor_notifier_list,
1499
+ SYSTEM_MONITOR_CHANGE_TEMP,
1500
+ (void *)&event_data);
1501
+
1502
+ return notifier_to_errno(ret);
1503
+}
1504
+
1505
+static int notify_dummy(struct thermal_zone_device *tz, int trip)
1506
+{
1507
+ return 0;
1508
+}
1509
+
1510
+static struct thermal_governor thermal_gov_dummy = {
1511
+ .name = "dummy",
1512
+ .throttle = notify_dummy,
1513
+};
11911514
11921515 static int rockchip_system_monitor_parse_dt(struct system_monitor *monitor)
11931516 {
....@@ -1195,7 +1518,7 @@
11951518 const char *tz_name, *buf = NULL;
11961519
11971520 if (of_property_read_string(np, "rockchip,video-4k-offline-cpus", &buf))
1198
- cpumask_clear(&system_monitor->video_4k_offline_cpus);
1521
+ cpumask_clear(&monitor->video_4k_offline_cpus);
11991522 else
12001523 cpulist_parse(buf, &monitor->video_4k_offline_cpus);
12011524
....@@ -1221,6 +1544,13 @@
12211544 system_monitor->offline_cpus_temp = INT_MAX;
12221545 of_property_read_u32(np, "rockchip,temp-hysteresis",
12231546 &system_monitor->temp_hysteresis);
1547
+
1548
+ if (of_find_property(np, "rockchip,thermal-governor-dummy", NULL)) {
1549
+ if (monitor->tz->governor->unbind_from_tz)
1550
+ monitor->tz->governor->unbind_from_tz(monitor->tz);
1551
+ monitor->tz->governor = &thermal_gov_dummy;
1552
+ }
1553
+
12241554 out:
12251555 return 0;
12261556 }
....@@ -1246,7 +1576,7 @@
12461576 cpumask_copy(&system_monitor->offline_cpus, &offline_cpus);
12471577 for_each_cpu(cpu, &system_monitor->offline_cpus) {
12481578 if (cpu_online(cpu))
1249
- cpu_down(cpu);
1579
+ remove_cpu(cpu);
12501580 }
12511581
12521582 cpumask_clear(&online_cpus);
....@@ -1256,7 +1586,7 @@
12561586 if (cpumask_empty(&online_cpus))
12571587 goto out;
12581588 for_each_cpu(cpu, &online_cpus)
1259
- cpu_up(cpu);
1589
+ add_cpu(cpu);
12601590
12611591 out:
12621592 mutex_unlock(&cpu_on_off_mutex);
....@@ -1288,7 +1618,6 @@
12881618 {
12891619 int temp, ret;
12901620 struct monitor_dev_info *info;
1291
- static int last_temp = INT_MAX;
12921621
12931622 ret = thermal_zone_get_temp(system_monitor->tz, &temp);
12941623 if (ret || temp == THERMAL_TEMP_INVALID)
....@@ -1296,9 +1625,12 @@
12961625
12971626 dev_dbg(system_monitor->dev, "temperature=%d\n", temp);
12981627
1299
- if (temp < last_temp && last_temp - temp <= 2000)
1628
+ if (temp < system_monitor->last_temp &&
1629
+ system_monitor->last_temp - temp <= 2000)
13001630 goto out;
1301
- last_temp = temp;
1631
+ system_monitor->last_temp = temp;
1632
+
1633
+ rockchip_system_monitor_temp_notify(temp);
13021634
13031635 down_read(&mdev_list_sem);
13041636 list_for_each_entry(info, &monitor_dev_list, node)
....@@ -1324,26 +1656,32 @@
13241656 unsigned long status)
13251657 {
13261658 unsigned int target_freq = 0;
1327
- bool is_freq_fixed = false;
1328
- int cpu;
1659
+
1660
+ if (!freq_qos_request_active(&info->min_sta_freq_req))
1661
+ return;
1662
+ if (!freq_qos_request_active(&info->max_sta_freq_req))
1663
+ return;
13291664
13301665 if (status & SYS_STATUS_REBOOT) {
1331
- info->status_min_limit = info->reboot_freq;
1332
- info->status_max_limit = info->reboot_freq;
1333
- info->is_status_freq_fixed = true;
1334
- goto next;
1666
+ freq_qos_update_request(&info->max_sta_freq_req,
1667
+ info->reboot_freq);
1668
+ freq_qos_update_request(&info->min_sta_freq_req,
1669
+ info->reboot_freq);
1670
+ return;
13351671 }
13361672
13371673 if (info->video_4k_freq && (status & SYS_STATUS_VIDEO_4K))
13381674 target_freq = info->video_4k_freq;
1339
- if (target_freq == info->status_max_limit &&
1340
- info->is_status_freq_fixed == is_freq_fixed)
1675
+
1676
+ if (target_freq == info->status_max_limit)
13411677 return;
13421678 info->status_max_limit = target_freq;
1343
- info->is_status_freq_fixed = is_freq_fixed;
1344
-next:
1345
- cpu = cpumask_any(&info->devp->allowed_cpus);
1346
- cpufreq_update_policy(cpu);
1679
+ if (info->status_max_limit)
1680
+ freq_qos_update_request(&info->max_sta_freq_req,
1681
+ info->status_max_limit);
1682
+ else
1683
+ freq_qos_update_request(&info->max_sta_freq_req,
1684
+ FREQ_QOS_MAX_DEFAULT_VALUE);
13471685 }
13481686
13491687 static void rockchip_system_status_limit_freq(unsigned long status)
....@@ -1352,7 +1690,7 @@
13521690
13531691 down_read(&mdev_list_sem);
13541692 list_for_each_entry(info, &monitor_dev_list, node) {
1355
- if (info->devp->type == MONITOR_TPYE_CPU)
1693
+ if (info->devp->type == MONITOR_TYPE_CPU)
13561694 rockchip_system_status_cpu_limit_freq(info, status);
13571695 }
13581696 up_read(&mdev_list_sem);
....@@ -1386,6 +1724,26 @@
13861724 return NOTIFY_OK;
13871725 }
13881726
1727
+static int rockchip_system_monitor_set_cpu_uevent_suppress(bool is_suppress)
1728
+{
1729
+ struct monitor_dev_info *info;
1730
+ struct cpufreq_policy *policy;
1731
+
1732
+ list_for_each_entry(info, &monitor_dev_list, node) {
1733
+ if (info->devp->type != MONITOR_TYPE_CPU)
1734
+ continue;
1735
+ policy = (struct cpufreq_policy *)info->devp->data;
1736
+ if (!policy || !policy->cdev)
1737
+ continue;
1738
+ if (is_suppress)
1739
+ dev_set_uevent_suppress(&policy->cdev->device, 1);
1740
+ else
1741
+ dev_set_uevent_suppress(&policy->cdev->device, 0);
1742
+ }
1743
+
1744
+ return 0;
1745
+}
1746
+
13891747 static int monitor_pm_notify(struct notifier_block *nb,
13901748 unsigned long mode, void *_unused)
13911749 {
....@@ -1394,6 +1752,7 @@
13941752 case PM_RESTORE_PREPARE:
13951753 case PM_SUSPEND_PREPARE:
13961754 atomic_set(&monitor_in_suspend, 1);
1755
+ rockchip_system_monitor_set_cpu_uevent_suppress(true);
13971756 break;
13981757 case PM_POST_HIBERNATION:
13991758 case PM_POST_RESTORE:
....@@ -1401,6 +1760,8 @@
14011760 if (system_monitor->tz)
14021761 rockchip_system_monitor_thermal_update();
14031762 atomic_set(&monitor_in_suspend, 0);
1763
+ rockchip_system_monitor_set_cpu_uevent_suppress(false);
1764
+ system_monitor->last_temp = INT_MAX;
14041765 break;
14051766 default:
14061767 break;
....@@ -1410,52 +1771,6 @@
14101771
14111772 static struct notifier_block monitor_pm_nb = {
14121773 .notifier_call = monitor_pm_notify,
1413
-};
1414
-
1415
-static int rockchip_monitor_cpufreq_policy_notifier(struct notifier_block *nb,
1416
- unsigned long event,
1417
- void *data)
1418
-{
1419
- struct monitor_dev_info *info;
1420
- struct cpufreq_policy *policy = data;
1421
- int cpu = policy->cpu;
1422
- unsigned int limit_freq = UINT_MAX;
1423
-
1424
- if (event != CPUFREQ_ADJUST)
1425
- return NOTIFY_OK;
1426
-
1427
- down_read(&mdev_list_sem);
1428
- list_for_each_entry(info, &monitor_dev_list, node) {
1429
- if (info->devp->type != MONITOR_TPYE_CPU)
1430
- continue;
1431
- if (!cpumask_test_cpu(cpu, &info->devp->allowed_cpus))
1432
- continue;
1433
-
1434
- if (info->wide_temp_limit) {
1435
- if (limit_freq > info->wide_temp_limit / 1000)
1436
- limit_freq = info->wide_temp_limit / 1000;
1437
- }
1438
- if (!system_monitor->boosted &&
1439
- info->status_max_limit &&
1440
- limit_freq > info->status_max_limit)
1441
- limit_freq = info->status_max_limit;
1442
-
1443
- if (info->is_status_freq_fixed) {
1444
- cpufreq_verify_within_limits(policy, limit_freq,
1445
- limit_freq);
1446
- dev_info(info->dev, "min=%u, max=%u\n", policy->min,
1447
- policy->max);
1448
- } else if (limit_freq < policy->max) {
1449
- cpufreq_verify_within_limits(policy, 0, limit_freq);
1450
- }
1451
- }
1452
- up_read(&mdev_list_sem);
1453
-
1454
- return NOTIFY_OK;
1455
-}
1456
-
1457
-static struct notifier_block rockchip_monitor_cpufreq_policy_nb = {
1458
- .notifier_call = rockchip_monitor_cpufreq_policy_notifier,
14591774 };
14601775
14611776 static int rockchip_monitor_reboot_notifier(struct notifier_block *nb,
....@@ -1477,24 +1792,15 @@
14771792 {
14781793 struct fb_event *event = ptr;
14791794
1480
- switch (action) {
1481
- case FB_EARLY_EVENT_BLANK:
1482
- switch (*((int *)event->data)) {
1483
- case FB_BLANK_UNBLANK:
1484
- rockchip_clear_system_status(SYS_STATUS_SUSPEND);
1485
- break;
1486
- default:
1487
- break;
1488
- }
1795
+ if (action != FB_EVENT_BLANK)
1796
+ return NOTIFY_OK;
1797
+
1798
+ switch (*((int *)event->data)) {
1799
+ case FB_BLANK_UNBLANK:
1800
+ rockchip_clear_system_status(SYS_STATUS_SUSPEND);
14891801 break;
1490
- case FB_EVENT_BLANK:
1491
- switch (*((int *)event->data)) {
1492
- case FB_BLANK_POWERDOWN:
1493
- rockchip_set_system_status(SYS_STATUS_SUSPEND);
1494
- break;
1495
- default:
1496
- break;
1497
- }
1802
+ case FB_BLANK_POWERDOWN:
1803
+ rockchip_set_system_status(SYS_STATUS_SUSPEND);
14981804 break;
14991805 default:
15001806 break;
....@@ -1517,12 +1823,6 @@
15171823 case EBC_OFF:
15181824 rockchip_set_system_status(SYS_STATUS_LOW_POWER);
15191825 break;
1520
- case EBC_FB_BLANK:
1521
- rockchip_set_system_status(SYS_STATUS_SUSPEND);
1522
- break;
1523
- case EBC_FB_UNBLANK:
1524
- rockchip_clear_system_status(SYS_STATUS_SUSPEND);
1525
- break;
15261826 default:
15271827 break;
15281828 }
....@@ -1533,6 +1833,32 @@
15331833 static struct notifier_block rockchip_monitor_ebc_nb = {
15341834 .notifier_call = rockchip_eink_devfs_notifier,
15351835 };
1836
+
1837
+static void system_monitor_early_min_volt_function(struct work_struct *work)
1838
+{
1839
+ struct monitor_dev_info *info;
1840
+ struct regulator_dev *rdev;
1841
+ int min_uV, max_uV;
1842
+ int ret;
1843
+
1844
+ down_read(&mdev_list_sem);
1845
+ list_for_each_entry(info, &monitor_dev_list, node) {
1846
+ if (!info->early_min_volt || !info->early_reg)
1847
+ continue;
1848
+ rdev = info->early_reg->rdev;
1849
+ min_uV = rdev->constraints->min_uV;
1850
+ max_uV = rdev->constraints->max_uV;
1851
+ ret = regulator_set_voltage(info->early_reg, min_uV, max_uV);
1852
+ if (ret)
1853
+ dev_err(&rdev->dev,
1854
+ "%s: failed to set volt\n", __func__);
1855
+ regulator_put(info->early_reg);
1856
+ }
1857
+ up_read(&mdev_list_sem);
1858
+}
1859
+
1860
+static DECLARE_DELAYED_WORK(system_monitor_early_min_volt_work,
1861
+ system_monitor_early_min_volt_function);
15361862
15371863 static int rockchip_system_monitor_probe(struct platform_device *pdev)
15381864 {
....@@ -1555,6 +1881,7 @@
15551881
15561882 rockchip_system_monitor_parse_dt(system_monitor);
15571883 if (system_monitor->tz) {
1884
+ system_monitor->last_temp = INT_MAX;
15581885 INIT_DELAYED_WORK(&system_monitor->thermal_work,
15591886 rockchip_system_monitor_thermal_check);
15601887 mod_delayed_work(system_freezable_wq,
....@@ -1569,9 +1896,6 @@
15691896 if (register_pm_notifier(&monitor_pm_nb))
15701897 dev_err(dev, "failed to register suspend notifier\n");
15711898
1572
- cpufreq_register_notifier(&rockchip_monitor_cpufreq_policy_nb,
1573
- CPUFREQ_POLICY_NOTIFIER);
1574
-
15751899 register_reboot_notifier(&rockchip_monitor_reboot_nb);
15761900
15771901 if (fb_register_client(&rockchip_monitor_fb_nb))
....@@ -1579,6 +1903,9 @@
15791903
15801904 ebc_register_notifier(&rockchip_monitor_ebc_nb);
15811905
1906
+ schedule_delayed_work(&system_monitor_early_min_volt_work,
1907
+ msecs_to_jiffies(30000));
1908
+
15821909 dev_info(dev, "system monitor probe\n");
15831910
15841911 return 0;