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,6 +71,7 @@
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;
....@@ -84,6 +92,7 @@
8492 static struct system_monitor *system_monitor;
8593 static atomic_t monitor_in_suspend;
8694
95
+static BLOCKING_NOTIFIER_HEAD(system_monitor_notifier_list);
8796 static BLOCKING_NOTIFIER_HEAD(system_status_notifier_list);
8897
8998 int rockchip_register_system_status_notifier(struct notifier_block *nb)
....@@ -173,9 +182,9 @@
173182 return -EINVAL;
174183 }
175184
176
- return __compat_only_sysfs_link_entry_to_kobj(&dev->kobj,
177
- system_monitor->kobj,
178
- "system_status");
185
+ return compat_only_sysfs_link_entry_to_kobj(&dev->kobj,
186
+ system_monitor->kobj,
187
+ "system_status", NULL);
179188 }
180189 EXPORT_SYMBOL(rockchip_add_system_status_interface);
181190
....@@ -288,6 +297,7 @@
288297 {
289298 struct video_info *video_info;
290299 unsigned int max_res = 0, max_stream_bitrate = 0, res = 0;
300
+ unsigned int max_video_framerate = 0;
291301
292302 mutex_lock(&video_info_mutex);
293303 if (list_empty(&video_info_list)) {
....@@ -302,6 +312,8 @@
302312 max_res = res;
303313 if (video_info->streamBitrate > max_stream_bitrate)
304314 max_stream_bitrate = video_info->streamBitrate;
315
+ if (video_info->videoFramerate > max_video_framerate)
316
+ max_video_framerate = video_info->videoFramerate;
305317 }
306318 mutex_unlock(&video_info_mutex);
307319
....@@ -310,8 +322,9 @@
310322 } else {
311323 if (max_stream_bitrate == 10)
312324 rockchip_set_system_status(SYS_STATUS_VIDEO_4K_10B);
313
- else
314
- rockchip_set_system_status(SYS_STATUS_VIDEO_4K);
325
+ if (max_video_framerate == 60)
326
+ rockchip_set_system_status(SYS_STATUS_VIDEO_4K_60P);
327
+ rockchip_set_system_status(SYS_STATUS_VIDEO_4K);
315328 }
316329 }
317330
....@@ -354,6 +367,14 @@
354367 case 'n':
355368 /* clear performance flag */
356369 rockchip_clear_system_status(SYS_STATUS_PERFORMANCE);
370
+ 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);
357378 break;
358379 default:
359380 break;
....@@ -492,8 +513,11 @@
492513 int delta_volt = 0;
493514 int i = 0, max_count;
494515 unsigned long low_limit = 0, high_limit = 0;
516
+ unsigned long low_limit_mem = 0, high_limit_mem = 0;
495517 bool reach_max_volt = false;
518
+ bool reach_max_mem_volt = false;
496519 bool reach_high_temp_max_volt = false;
520
+ bool reach_high_temp_max_mem_volt = false;
497521
498522 max_count = dev_pm_opp_get_opp_count(dev);
499523 if (max_count <= 0)
....@@ -511,6 +535,8 @@
511535 }
512536 mutex_lock(&opp_table->lock);
513537 list_for_each_entry(opp, &opp_table->opp_list, node) {
538
+ if (!opp->available)
539
+ continue;
514540 info->opp_table[i].rate = opp->rate;
515541 info->opp_table[i].volt = opp->supplies[0].u_volt;
516542 info->opp_table[i].max_volt = opp->supplies[0].u_volt_max;
....@@ -542,9 +568,48 @@
542568 info->low_limit = low_limit;
543569 if (high_limit && high_limit != opp->rate)
544570 info->high_limit = high_limit;
545
- 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",
546609 info->opp_table[i].rate, info->opp_table[i].volt,
547
- 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);
548613 i++;
549614 }
550615 mutex_unlock(&opp_table->lock);
....@@ -586,9 +651,12 @@
586651 else
587652 info->high_temp_max_volt = value;
588653 rockchip_init_temp_opp_table(info);
589
- if (rockchip_get_temp_freq_table(np, "rockchip,high-temp-limit-table",
590
- &info->high_limit_table)) {
591
- 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) {
592660 if (!of_property_read_u32(np, "rockchip,high-temp-max-freq",
593661 &value)) {
594662 high_temp_max_freq = value * 1000;
....@@ -640,7 +708,7 @@
640708 &info->video_4k_freq);
641709 ret &= of_property_read_u32(np, "rockchip,reboot-freq",
642710 &info->reboot_freq);
643
- if (info->devp->type == MONITOR_TPYE_CPU) {
711
+ if (info->devp->type == MONITOR_TYPE_CPU) {
644712 if (!info->reboot_freq) {
645713 info->reboot_freq = CPU_REBOOT_FREQ;
646714 ret = 0;
....@@ -650,66 +718,70 @@
650718 return ret;
651719 }
652720
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
+
653747 static int monitor_device_parse_dt(struct device *dev,
654748 struct monitor_dev_info *info)
655749 {
656750 struct device_node *np;
657
- int ret = 0;
658
- bool is_wide_temp_en = false;
659
- bool is_status_limit_en = false;
660
- bool is_temp_freq_en = false;
751
+ int ret;
661752
662753 np = of_parse_phandle(dev->of_node, "operating-points-v2", 0);
663754 if (!np)
664755 return -EINVAL;
665756
666
- if (!monitor_device_parse_wide_temp_config(np, info))
667
- is_wide_temp_en = true;
668
- if (!monitor_device_parse_status_config(np, info))
669
- is_status_limit_en = true;
670
- if (!rockchip_get_temp_freq_table(np, "rockchip,temp-freq-table",
671
- &info->temp_freq_table))
672
- is_temp_freq_en = true;
673
- if (is_wide_temp_en || is_status_limit_en || is_temp_freq_en)
674
- ret = 0;
675
- else
676
- 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);
677764
678765 of_node_put(np);
679766
680767 return ret;
681768 }
682769
683
-int rockchip_monitor_opp_set_rate(struct monitor_dev_info *info,
684
- unsigned long target_freq)
685
-{
686
- int ret = 0;
687
-
688
- mutex_lock(&info->volt_adjust_mutex);
689
- ret = dev_pm_opp_set_rate(info->dev, target_freq);
690
- mutex_unlock(&info->volt_adjust_mutex);
691
-
692
- return ret;
693
-}
694
-EXPORT_SYMBOL(rockchip_monitor_opp_set_rate);
695
-
696770 int rockchip_monitor_cpu_low_temp_adjust(struct monitor_dev_info *info,
697771 bool is_low)
698772 {
699
- struct device *dev = info->dev;
700
- unsigned int cpu = cpumask_any(&info->devp->allowed_cpus);
773
+ if (!info->low_limit)
774
+ return 0;
701775
702
- if (info->low_limit) {
703
- if (is_low)
704
- info->wide_temp_limit = info->low_limit;
705
- else
706
- info->wide_temp_limit = 0;
707
- cpufreq_update_policy(cpu);
708
- }
776
+ if (!freq_qos_request_active(&info->max_temp_freq_req))
777
+ return 0;
709778
710
- mutex_lock(&info->volt_adjust_mutex);
711
- dev_pm_opp_check_rate_volt(dev, false);
712
- 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);
713785
714786 return 0;
715787 }
....@@ -718,53 +790,44 @@
718790 int rockchip_monitor_cpu_high_temp_adjust(struct monitor_dev_info *info,
719791 bool is_high)
720792 {
721
- 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;
722798
723799 if (info->high_limit_table) {
724
- info->wide_temp_limit = info->high_limit;
725
- cpufreq_update_policy(cpu);
726
- } else {
727
- if (info->high_limit) {
728
- if (is_high)
729
- info->wide_temp_limit = info->high_limit;
730
- else
731
- info->wide_temp_limit = 0;
732
- cpufreq_update_policy(cpu);
733
- }
800
+ freq_qos_update_request(&info->max_temp_freq_req,
801
+ info->high_limit / 1000);
802
+ return 0;
734803 }
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);
735811
736812 return 0;
737813 }
738814 EXPORT_SYMBOL(rockchip_monitor_cpu_high_temp_adjust);
739815
740
-static int rockchip_monitor_update_devfreq(struct devfreq *df)
741
-{
742
- int ret = 0;
743
-
744
-#ifdef CONFIG_PM_DEVFREQ
745
- mutex_lock(&df->lock);
746
- ret = update_devfreq(df);
747
- mutex_unlock(&df->lock);
748
-#endif
749
- return ret;
750
-};
751
-
752816 int rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info *info,
753817 bool is_low)
754818 {
755
- struct devfreq *df;
819
+ if (!dev_pm_qos_request_active(&info->dev_max_freq_req))
820
+ return 0;
756821
757
- if (info->low_limit) {
758
- if (is_low)
759
- info->wide_temp_limit = info->low_limit;
760
- else
761
- info->wide_temp_limit = 0;
762
- }
822
+ if (!info->low_limit)
823
+ return 0;
763824
764
- if (info->devp && info->devp->data) {
765
- df = (struct devfreq *)info->devp->data;
766
- rockchip_monitor_update_devfreq(df);
767
- }
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);
768831
769832 return 0;
770833 }
....@@ -773,26 +836,24 @@
773836 int rockchip_monitor_dev_high_temp_adjust(struct monitor_dev_info *info,
774837 bool is_high)
775838 {
776
- 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;
777844
778845 if (info->high_limit_table) {
779
- info->wide_temp_limit = info->high_limit;
780
- if (info->devp && info->devp->data) {
781
- df = (struct devfreq *)info->devp->data;
782
- rockchip_monitor_update_devfreq(df);
783
- }
784
- } else {
785
- if (info->high_limit) {
786
- if (is_high)
787
- info->wide_temp_limit = info->high_limit;
788
- else
789
- info->wide_temp_limit = 0;
790
- if (info->devp && info->devp->data) {
791
- df = (struct devfreq *)info->devp->data;
792
- rockchip_monitor_update_devfreq(df);
793
- }
794
- }
846
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
847
+ info->high_limit / 1000);
848
+ return 0;
795849 }
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);
796857
797858 return 0;
798859 }
....@@ -812,6 +873,8 @@
812873
813874 mutex_lock(&opp_table->lock);
814875 list_for_each_entry(opp, &opp_table->opp_list, node) {
876
+ if (!opp->available)
877
+ continue;
815878 if (is_low_temp) {
816879 if (opp->supplies[0].u_volt_max <
817880 info->opp_table[i].low_temp_volt)
....@@ -820,11 +883,29 @@
820883 opp->supplies[0].u_volt =
821884 info->opp_table[i].low_temp_volt;
822885 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
+ }
823896 } else {
824897 opp->supplies[0].u_volt_min = info->opp_table[i].volt;
825898 opp->supplies[0].u_volt = opp->supplies[0].u_volt_min;
826899 opp->supplies[0].u_volt_max =
827900 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
+ }
828909 }
829910 i++;
830911 }
....@@ -850,6 +931,9 @@
850931 ret = devp->low_temp_adjust(info, is_low);
851932 if (!ret)
852933 info->is_low_temp = is_low;
934
+
935
+ if (devp->update_volt)
936
+ devp->update_volt(info);
853937 }
854938
855939 static void rockchip_high_temp_adjust(struct monitor_dev_info *info,
....@@ -858,12 +942,14 @@
858942 struct monitor_dev_profile *devp = info->devp;
859943 int ret = 0;
860944
945
+ if (!devp->high_temp_adjust)
946
+ return;
947
+
861948 if (info->high_limit_table) {
862949 devp->high_temp_adjust(info, is_high);
863950 } else {
864951 dev_dbg(info->dev, "high_temp %d\n", is_high);
865
- if (devp->high_temp_adjust)
866
- ret = devp->high_temp_adjust(info, is_high);
952
+ ret = devp->high_temp_adjust(info, is_high);
867953 if (!ret)
868954 info->is_high_temp = is_high;
869955 }
....@@ -874,7 +960,7 @@
874960 struct monitor_dev_info *info = NULL, *tmp;
875961
876962 list_for_each_entry(tmp, &monitor_dev_list, node) {
877
- if (tmp->devp->type != MONITOR_TPYE_CPU)
963
+ if (tmp->devp->type != MONITOR_TYPE_CPU)
878964 continue;
879965 if (cpumask_test_cpu(cpu, &tmp->devp->allowed_cpus)) {
880966 info = tmp;
....@@ -941,6 +1027,9 @@
9411027 {
9421028 int ret, temp;
9431029
1030
+ if (!info->opp_table)
1031
+ return;
1032
+
9441033 /*
9451034 * set the init state to low temperature that the voltage will be enough
9461035 * when cpu up at low temperature.
....@@ -948,7 +1037,6 @@
9481037 if (!info->is_low_temp) {
9491038 if (info->opp_table)
9501039 rockchip_adjust_low_temp_opp_volt(info, true);
951
- info->wide_temp_limit = info->low_limit;
9521040 info->is_low_temp = true;
9531041 }
9541042
....@@ -963,150 +1051,372 @@
9631051 if (info->opp_table)
9641052 rockchip_adjust_low_temp_opp_volt(info, false);
9651053 info->is_low_temp = false;
966
-
967
- info->wide_temp_limit = info->high_limit;
9681054 info->is_high_temp = true;
9691055 } else if (temp > (info->low_temp + info->temp_hysteresis)) {
9701056 if (info->opp_table)
9711057 rockchip_adjust_low_temp_opp_volt(info, false);
9721058 info->is_low_temp = false;
973
- info->wide_temp_limit = 0;
9741059 }
9751060 }
9761061
977
-static int system_monitor_devfreq_notifier_call(struct notifier_block *nb,
978
- unsigned long event,
979
- void *data)
1062
+static const char *get_rdev_name(struct regulator_dev *rdev)
9801063 {
981
- struct monitor_dev_info *info = devfreq_nb_to_monitor(nb);
982
- struct devfreq_policy *policy = data;
983
-
984
- if (event != DEVFREQ_ADJUST)
985
- return NOTIFY_DONE;
986
-
987
- if (info->wide_temp_limit && info->wide_temp_limit < policy->max)
988
- devfreq_verify_within_limits(policy, 0, info->wide_temp_limit);
989
-
990
- 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 "";
9911070 }
9921071
993
-static int monitor_set_freq_table(struct device *dev,
994
- struct monitor_dev_info *info)
1072
+static void
1073
+rockchip_system_monitor_early_regulator_init(struct monitor_dev_info *info)
9951074 {
996
- struct opp_table *opp_table;
997
- struct dev_pm_opp *opp;
998
- unsigned long *freq_table;
999
- int count;
1075
+ struct regulator *reg;
1076
+ struct regulator_dev *rdev;
10001077
1001
- opp_table = dev_pm_opp_get_opp_table(dev);
1002
- if (!opp_table)
1003
- return -ENOMEM;
1078
+ if (!info->early_min_volt || !info->regulators)
1079
+ return;
10041080
1005
- /* Initialize the freq_table from OPP table */
1006
- count = dev_pm_opp_get_opp_count(dev);
1007
- if (count <= 0)
1008
- return -EINVAL;
1009
-
1010
- info->max_state = count;
1011
- freq_table = kcalloc(count, sizeof(*info->freq_table), GFP_KERNEL);
1012
- if (!freq_table) {
1013
- info->max_state = 0;
1014
- 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;
10151087 }
1088
+}
10161089
1017
- mutex_lock(&opp_table->lock);
1018
- list_for_each_entry(opp, &opp_table->opp_list, node) {
1019
- if (opp->available) {
1020
- count--;
1021
- 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;
10221147 }
10231148 }
1024
- 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
+ }
10251183
10261184 dev_pm_opp_put_opp_table(opp_table);
10271185
1028
- 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
+ }
10291216
10301217 return 0;
10311218 }
10321219
1033
-static unsigned long monitor_freq_to_state(struct monitor_dev_info *info,
1034
- unsigned long freq)
1220
+static void rockchip_monitor_disable_opp_clk(struct device *dev,
1221
+ struct rockchip_opp_info *opp_info)
10351222 {
1036
- unsigned long i = 0;
1223
+ if (!opp_info)
1224
+ return;
10371225
1038
- if (!info->freq_table) {
1039
- dev_info(info->dev, "failed to get freq_table");
1040
- return 0;
1041
- }
1042
-
1043
- for (i = 0; i < info->max_state; i++) {
1044
- if (freq >= info->freq_table[i])
1045
- return i;
1046
- }
1047
-
1048
- return info->max_state - 1;
1226
+ clk_bulk_disable_unprepare(opp_info->num_clks, opp_info->clks);
10491227 }
10501228
1051
-static int monitor_temp_to_state(struct monitor_dev_info *info,
1052
- 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)
10531234 {
1054
- unsigned long target_state, target_freq = 0;
1055
- int i;
1235
+ struct dev_pm_set_opp_data *data;
1236
+ int size;
10561237
1057
- 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)
10581272 return 0;
1059
- if (info->temp_freq_table) {
1060
- for (i = 0; info->temp_freq_table[i].freq != UINT_MAX; i++) {
1061
- if (temp > info->temp_freq_table[i].temp)
1062
- 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;
10631296 }
1064
- if (target_freq)
1065
- *state = monitor_freq_to_state(info,
1066
- target_freq * 1000);
1067
- else
1068
- *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;
10691319 }
10701320
1071
- if (info->status_min_limit) {
1072
- target_freq = info->status_min_limit * 1000;
1073
- target_state = monitor_freq_to_state(info, target_freq);
1074
- if (*state > target_state)
1075
- *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
+ }
10761330 }
1331
+ rockchip_monitor_enable_opp_clk(dev, opp_info);
1332
+ rockchip_get_read_margin(dev, opp_info, new_volt, &target_rm);
10771333
1078
- 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;
10791406 }
1080
-
1081
-int
1082
-rockchip_system_monitor_adjust_cdev_state(struct thermal_cooling_device *cdev,
1083
- int temp, unsigned long *state)
1084
-{
1085
- struct monitor_dev_info *info;
1086
-
1087
- down_read(&mdev_list_sem);
1088
- list_for_each_entry(info, &monitor_dev_list, node) {
1089
- if (cdev->np != info->dev->of_node)
1090
- continue;
1091
- monitor_temp_to_state(info, temp, state);
1092
- break;
1093
- }
1094
- up_read(&mdev_list_sem);
1095
-
1096
- return 0;
1097
-}
1098
-EXPORT_SYMBOL(rockchip_system_monitor_adjust_cdev_state);
1407
+EXPORT_SYMBOL(rockchip_monitor_check_rate_volt);
10991408
11001409 struct monitor_dev_info *
11011410 rockchip_system_monitor_register(struct device *dev,
11021411 struct monitor_dev_profile *devp)
11031412 {
11041413 struct monitor_dev_info *info;
1105
- struct devfreq *devfreq;
1106
- int ret;
11071414
11081415 if (!system_monitor)
11091416 return ERR_PTR(-ENOMEM);
1417
+
1418
+ if (!devp)
1419
+ return ERR_PTR(-EINVAL);
11101420
11111421 info = kzalloc(sizeof(*info), GFP_KERNEL);
11121422 if (!info)
....@@ -1114,39 +1424,33 @@
11141424 info->dev = dev;
11151425 info->devp = devp;
11161426
1117
- ret = monitor_device_parse_dt(dev, info);
1118
- if (ret)
1119
- goto free_info;
1427
+ mutex_init(&info->volt_adjust_mutex);
11201428
1121
- monitor_set_freq_table(dev, info);
1122
-
1123
- if (info->devp->type == MONITOR_TPYE_DEV) {
1124
- info->devfreq_nb.notifier_call =
1125
- system_monitor_devfreq_notifier_call;
1126
- devfreq = (struct devfreq *)info->devp->data;
1127
- devm_devfreq_register_notifier(dev, devfreq, &info->devfreq_nb,
1128
- 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);
11291436 }
11301437
1438
+ rockchip_system_monitor_early_regulator_init(info);
11311439 rockchip_system_monitor_wide_temp_init(info);
1132
- 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);
11331443
11341444 down_write(&mdev_list_sem);
11351445 list_add(&info->node, &monitor_dev_list);
11361446 up_write(&mdev_list_sem);
11371447
11381448 return info;
1139
-
1140
-free_info:
1141
- kfree(info);
1142
- return ERR_PTR(-EINVAL);
11431449 }
11441450 EXPORT_SYMBOL(rockchip_system_monitor_register);
11451451
11461452 void rockchip_system_monitor_unregister(struct monitor_dev_info *info)
11471453 {
1148
- struct devfreq *devfreq;
1149
-
11501454 if (!info)
11511455 return;
11521456
....@@ -1154,18 +1458,59 @@
11541458 list_del(&info->node);
11551459 up_write(&mdev_list_sem);
11561460
1157
- devfreq = (struct devfreq *)info->devp->data;
1158
- if (info->devp->type == MONITOR_TPYE_DEV)
1159
- devm_devfreq_unregister_notifier(info->dev, devfreq,
1160
- &info->devfreq_nb,
1161
- 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);
1471
+ }
11621472
11631473 kfree(info->low_temp_adjust_table);
11641474 kfree(info->opp_table);
1165
- kfree(info->freq_table);
1475
+ kfree(info->set_opp_data);
11661476 kfree(info);
11671477 }
11681478 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
+};
11691514
11701515 static int rockchip_system_monitor_parse_dt(struct system_monitor *monitor)
11711516 {
....@@ -1173,7 +1518,7 @@
11731518 const char *tz_name, *buf = NULL;
11741519
11751520 if (of_property_read_string(np, "rockchip,video-4k-offline-cpus", &buf))
1176
- cpumask_clear(&system_monitor->video_4k_offline_cpus);
1521
+ cpumask_clear(&monitor->video_4k_offline_cpus);
11771522 else
11781523 cpulist_parse(buf, &monitor->video_4k_offline_cpus);
11791524
....@@ -1199,6 +1544,13 @@
11991544 system_monitor->offline_cpus_temp = INT_MAX;
12001545 of_property_read_u32(np, "rockchip,temp-hysteresis",
12011546 &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
+
12021554 out:
12031555 return 0;
12041556 }
....@@ -1224,7 +1576,7 @@
12241576 cpumask_copy(&system_monitor->offline_cpus, &offline_cpus);
12251577 for_each_cpu(cpu, &system_monitor->offline_cpus) {
12261578 if (cpu_online(cpu))
1227
- cpu_down(cpu);
1579
+ remove_cpu(cpu);
12281580 }
12291581
12301582 cpumask_clear(&online_cpus);
....@@ -1234,7 +1586,7 @@
12341586 if (cpumask_empty(&online_cpus))
12351587 goto out;
12361588 for_each_cpu(cpu, &online_cpus)
1237
- cpu_up(cpu);
1589
+ add_cpu(cpu);
12381590
12391591 out:
12401592 mutex_unlock(&cpu_on_off_mutex);
....@@ -1266,7 +1618,6 @@
12661618 {
12671619 int temp, ret;
12681620 struct monitor_dev_info *info;
1269
- static int last_temp = INT_MAX;
12701621
12711622 ret = thermal_zone_get_temp(system_monitor->tz, &temp);
12721623 if (ret || temp == THERMAL_TEMP_INVALID)
....@@ -1274,9 +1625,12 @@
12741625
12751626 dev_dbg(system_monitor->dev, "temperature=%d\n", temp);
12761627
1277
- if (temp < last_temp && last_temp - temp <= 2000)
1628
+ if (temp < system_monitor->last_temp &&
1629
+ system_monitor->last_temp - temp <= 2000)
12781630 goto out;
1279
- last_temp = temp;
1631
+ system_monitor->last_temp = temp;
1632
+
1633
+ rockchip_system_monitor_temp_notify(temp);
12801634
12811635 down_read(&mdev_list_sem);
12821636 list_for_each_entry(info, &monitor_dev_list, node)
....@@ -1302,26 +1656,32 @@
13021656 unsigned long status)
13031657 {
13041658 unsigned int target_freq = 0;
1305
- bool is_freq_fixed = false;
1306
- 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;
13071664
13081665 if (status & SYS_STATUS_REBOOT) {
1309
- info->status_min_limit = info->reboot_freq;
1310
- info->status_max_limit = info->reboot_freq;
1311
- info->is_status_freq_fixed = true;
1312
- 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;
13131671 }
13141672
13151673 if (info->video_4k_freq && (status & SYS_STATUS_VIDEO_4K))
13161674 target_freq = info->video_4k_freq;
1317
- if (target_freq == info->status_max_limit &&
1318
- info->is_status_freq_fixed == is_freq_fixed)
1675
+
1676
+ if (target_freq == info->status_max_limit)
13191677 return;
13201678 info->status_max_limit = target_freq;
1321
- info->is_status_freq_fixed = is_freq_fixed;
1322
-next:
1323
- cpu = cpumask_any(&info->devp->allowed_cpus);
1324
- 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);
13251685 }
13261686
13271687 static void rockchip_system_status_limit_freq(unsigned long status)
....@@ -1330,7 +1690,7 @@
13301690
13311691 down_read(&mdev_list_sem);
13321692 list_for_each_entry(info, &monitor_dev_list, node) {
1333
- if (info->devp->type == MONITOR_TPYE_CPU)
1693
+ if (info->devp->type == MONITOR_TYPE_CPU)
13341694 rockchip_system_status_cpu_limit_freq(info, status);
13351695 }
13361696 up_read(&mdev_list_sem);
....@@ -1364,6 +1724,26 @@
13641724 return NOTIFY_OK;
13651725 }
13661726
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
+
13671747 static int monitor_pm_notify(struct notifier_block *nb,
13681748 unsigned long mode, void *_unused)
13691749 {
....@@ -1372,6 +1752,7 @@
13721752 case PM_RESTORE_PREPARE:
13731753 case PM_SUSPEND_PREPARE:
13741754 atomic_set(&monitor_in_suspend, 1);
1755
+ rockchip_system_monitor_set_cpu_uevent_suppress(true);
13751756 break;
13761757 case PM_POST_HIBERNATION:
13771758 case PM_POST_RESTORE:
....@@ -1379,6 +1760,8 @@
13791760 if (system_monitor->tz)
13801761 rockchip_system_monitor_thermal_update();
13811762 atomic_set(&monitor_in_suspend, 0);
1763
+ rockchip_system_monitor_set_cpu_uevent_suppress(false);
1764
+ system_monitor->last_temp = INT_MAX;
13821765 break;
13831766 default:
13841767 break;
....@@ -1388,51 +1771,6 @@
13881771
13891772 static struct notifier_block monitor_pm_nb = {
13901773 .notifier_call = monitor_pm_notify,
1391
-};
1392
-
1393
-static int rockchip_monitor_cpufreq_policy_notifier(struct notifier_block *nb,
1394
- unsigned long event,
1395
- void *data)
1396
-{
1397
- struct monitor_dev_info *info;
1398
- struct cpufreq_policy *policy = data;
1399
- int cpu = policy->cpu;
1400
- unsigned int limit_freq = UINT_MAX;
1401
-
1402
- if (event != CPUFREQ_ADJUST)
1403
- return NOTIFY_OK;
1404
-
1405
- down_read(&mdev_list_sem);
1406
- list_for_each_entry(info, &monitor_dev_list, node) {
1407
- if (info->devp->type != MONITOR_TPYE_CPU)
1408
- continue;
1409
- if (!cpumask_test_cpu(cpu, &info->devp->allowed_cpus))
1410
- continue;
1411
-
1412
- if (info->wide_temp_limit) {
1413
- if (limit_freq > info->wide_temp_limit / 1000)
1414
- limit_freq = info->wide_temp_limit / 1000;
1415
- }
1416
- if (info->status_max_limit &&
1417
- limit_freq > info->status_max_limit)
1418
- limit_freq = info->status_max_limit;
1419
-
1420
- if (info->is_status_freq_fixed) {
1421
- cpufreq_verify_within_limits(policy, limit_freq,
1422
- limit_freq);
1423
- dev_info(info->dev, "min=%u, max=%u\n", policy->min,
1424
- policy->max);
1425
- } else if (limit_freq < policy->max) {
1426
- cpufreq_verify_within_limits(policy, 0, limit_freq);
1427
- }
1428
- }
1429
- up_read(&mdev_list_sem);
1430
-
1431
- return NOTIFY_OK;
1432
-}
1433
-
1434
-static struct notifier_block rockchip_monitor_cpufreq_policy_nb = {
1435
- .notifier_call = rockchip_monitor_cpufreq_policy_notifier,
14361774 };
14371775
14381776 static int rockchip_monitor_reboot_notifier(struct notifier_block *nb,
....@@ -1454,24 +1792,15 @@
14541792 {
14551793 struct fb_event *event = ptr;
14561794
1457
- switch (action) {
1458
- case FB_EARLY_EVENT_BLANK:
1459
- switch (*((int *)event->data)) {
1460
- case FB_BLANK_UNBLANK:
1461
- rockchip_clear_system_status(SYS_STATUS_SUSPEND);
1462
- break;
1463
- default:
1464
- break;
1465
- }
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);
14661801 break;
1467
- case FB_EVENT_BLANK:
1468
- switch (*((int *)event->data)) {
1469
- case FB_BLANK_POWERDOWN:
1470
- rockchip_set_system_status(SYS_STATUS_SUSPEND);
1471
- break;
1472
- default:
1473
- break;
1474
- }
1802
+ case FB_BLANK_POWERDOWN:
1803
+ rockchip_set_system_status(SYS_STATUS_SUSPEND);
14751804 break;
14761805 default:
14771806 break;
....@@ -1494,12 +1823,6 @@
14941823 case EBC_OFF:
14951824 rockchip_set_system_status(SYS_STATUS_LOW_POWER);
14961825 break;
1497
- case EBC_FB_BLANK:
1498
- rockchip_set_system_status(SYS_STATUS_SUSPEND);
1499
- break;
1500
- case EBC_FB_UNBLANK:
1501
- rockchip_clear_system_status(SYS_STATUS_SUSPEND);
1502
- break;
15031826 default:
15041827 break;
15051828 }
....@@ -1510,6 +1833,32 @@
15101833 static struct notifier_block rockchip_monitor_ebc_nb = {
15111834 .notifier_call = rockchip_eink_devfs_notifier,
15121835 };
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);
15131862
15141863 static int rockchip_system_monitor_probe(struct platform_device *pdev)
15151864 {
....@@ -1532,6 +1881,7 @@
15321881
15331882 rockchip_system_monitor_parse_dt(system_monitor);
15341883 if (system_monitor->tz) {
1884
+ system_monitor->last_temp = INT_MAX;
15351885 INIT_DELAYED_WORK(&system_monitor->thermal_work,
15361886 rockchip_system_monitor_thermal_check);
15371887 mod_delayed_work(system_freezable_wq,
....@@ -1546,9 +1896,6 @@
15461896 if (register_pm_notifier(&monitor_pm_nb))
15471897 dev_err(dev, "failed to register suspend notifier\n");
15481898
1549
- cpufreq_register_notifier(&rockchip_monitor_cpufreq_policy_nb,
1550
- CPUFREQ_POLICY_NOTIFIER);
1551
-
15521899 register_reboot_notifier(&rockchip_monitor_reboot_nb);
15531900
15541901 if (fb_register_client(&rockchip_monitor_fb_nb))
....@@ -1556,6 +1903,9 @@
15561903
15571904 ebc_register_notifier(&rockchip_monitor_ebc_nb);
15581905
1906
+ schedule_delayed_work(&system_monitor_early_min_volt_work,
1907
+ msecs_to_jiffies(30000));
1908
+
15591909 dev_info(dev, "system monitor probe\n");
15601910
15611911 return 0;