hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
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,11 @@
9411027 {
9421028 int ret, temp;
9431029
1030
+ if (!info->opp_table)
1031
+ return;
1032
+ if (!system_monitor->tz)
1033
+ return;
1034
+
9441035 /*
9451036 * set the init state to low temperature that the voltage will be enough
9461037 * when cpu up at low temperature.
....@@ -948,7 +1039,6 @@
9481039 if (!info->is_low_temp) {
9491040 if (info->opp_table)
9501041 rockchip_adjust_low_temp_opp_volt(info, true);
951
- info->wide_temp_limit = info->low_limit;
9521042 info->is_low_temp = true;
9531043 }
9541044
....@@ -963,150 +1053,372 @@
9631053 if (info->opp_table)
9641054 rockchip_adjust_low_temp_opp_volt(info, false);
9651055 info->is_low_temp = false;
966
-
967
- info->wide_temp_limit = info->high_limit;
9681056 info->is_high_temp = true;
9691057 } else if (temp > (info->low_temp + info->temp_hysteresis)) {
9701058 if (info->opp_table)
9711059 rockchip_adjust_low_temp_opp_volt(info, false);
9721060 info->is_low_temp = false;
973
- info->wide_temp_limit = 0;
9741061 }
9751062 }
9761063
977
-static int system_monitor_devfreq_notifier_call(struct notifier_block *nb,
978
- unsigned long event,
979
- void *data)
1064
+static const char *get_rdev_name(struct regulator_dev *rdev)
9801065 {
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;
1066
+ if (rdev->constraints && rdev->constraints->name)
1067
+ return rdev->constraints->name;
1068
+ else if (rdev->desc->name)
1069
+ return rdev->desc->name;
1070
+ else
1071
+ return "";
9911072 }
9921073
993
-static int monitor_set_freq_table(struct device *dev,
994
- struct monitor_dev_info *info)
1074
+static void
1075
+rockchip_system_monitor_early_regulator_init(struct monitor_dev_info *info)
9951076 {
996
- struct opp_table *opp_table;
997
- struct dev_pm_opp *opp;
998
- unsigned long *freq_table;
999
- int count;
1077
+ struct regulator *reg;
1078
+ struct regulator_dev *rdev;
10001079
1001
- opp_table = dev_pm_opp_get_opp_table(dev);
1002
- if (!opp_table)
1003
- return -ENOMEM;
1080
+ if (!info->early_min_volt || !info->regulators)
1081
+ return;
10041082
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;
1083
+ rdev = info->regulators[0]->rdev;
1084
+ reg = regulator_get(NULL, get_rdev_name(rdev));
1085
+ if (!IS_ERR_OR_NULL(reg)) {
1086
+ info->early_reg = reg;
1087
+ reg->voltage[PM_SUSPEND_ON].min_uV = info->early_min_volt;
1088
+ reg->voltage[PM_SUSPEND_ON].max_uV = rdev->constraints->max_uV;
10151089 }
1090
+}
10161091
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;
1092
+static int
1093
+rockchip_system_monitor_freq_qos_requset(struct monitor_dev_info *info)
1094
+{
1095
+ struct devfreq *devfreq;
1096
+ struct cpufreq_policy *policy;
1097
+ int max_default_value = FREQ_QOS_MAX_DEFAULT_VALUE;
1098
+ int ret;
1099
+
1100
+ if (!info->devp->data)
1101
+ return 0;
1102
+
1103
+ if (info->is_low_temp && info->low_limit)
1104
+ max_default_value = info->low_limit / 1000;
1105
+ else if (info->is_high_temp && info->high_limit)
1106
+ max_default_value = info->high_limit / 1000;
1107
+
1108
+ if (info->devp->type == MONITOR_TYPE_CPU) {
1109
+ policy = (struct cpufreq_policy *)info->devp->data;
1110
+ ret = freq_qos_add_request(&policy->constraints,
1111
+ &info->max_temp_freq_req,
1112
+ FREQ_QOS_MAX,
1113
+ max_default_value);
1114
+ if (ret < 0) {
1115
+ dev_info(info->dev,
1116
+ "failed to add temp freq constraint\n");
1117
+ return ret;
1118
+ }
1119
+ ret = freq_qos_add_request(&policy->constraints,
1120
+ &info->min_sta_freq_req,
1121
+ FREQ_QOS_MIN,
1122
+ FREQ_QOS_MIN_DEFAULT_VALUE);
1123
+ if (ret < 0) {
1124
+ dev_info(info->dev,
1125
+ "failed to add sta freq constraint\n");
1126
+ freq_qos_remove_request(&info->max_temp_freq_req);
1127
+ return ret;
1128
+ }
1129
+ ret = freq_qos_add_request(&policy->constraints,
1130
+ &info->max_sta_freq_req,
1131
+ FREQ_QOS_MAX,
1132
+ FREQ_QOS_MAX_DEFAULT_VALUE);
1133
+ if (ret < 0) {
1134
+ dev_info(info->dev,
1135
+ "failed to add sta freq constraint\n");
1136
+ freq_qos_remove_request(&info->max_temp_freq_req);
1137
+ freq_qos_remove_request(&info->min_sta_freq_req);
1138
+ return ret;
1139
+ }
1140
+ } else if (info->devp->type == MONITOR_TYPE_DEV) {
1141
+ devfreq = (struct devfreq *)info->devp->data;
1142
+ ret = dev_pm_qos_add_request(devfreq->dev.parent,
1143
+ &info->dev_max_freq_req,
1144
+ DEV_PM_QOS_MAX_FREQUENCY,
1145
+ max_default_value);
1146
+ if (ret < 0) {
1147
+ dev_info(info->dev, "failed to add freq constraint\n");
1148
+ return ret;
10221149 }
10231150 }
1024
- mutex_unlock(&opp_table->lock);
1151
+
1152
+ return 0;
1153
+}
1154
+
1155
+static int rockchip_system_monitor_parse_supplies(struct device *dev,
1156
+ struct monitor_dev_info *info)
1157
+{
1158
+ struct opp_table *opp_table;
1159
+ struct dev_pm_set_opp_data *data;
1160
+ int len, count;
1161
+
1162
+ opp_table = dev_pm_opp_get_opp_table(dev);
1163
+ if (IS_ERR(opp_table))
1164
+ return PTR_ERR(opp_table);
1165
+
1166
+ if (opp_table->clk)
1167
+ info->clk = opp_table->clk;
1168
+ if (opp_table->regulators)
1169
+ info->regulators = opp_table->regulators;
1170
+ info->regulator_count = opp_table->regulator_count;
1171
+
1172
+ if (opp_table->regulators && info->devp->set_opp) {
1173
+ count = opp_table->regulator_count;
1174
+ /* space for set_opp_data */
1175
+ len = sizeof(*data);
1176
+ /* space for old_opp.supplies and new_opp.supplies */
1177
+ len += 2 * sizeof(struct dev_pm_opp_supply) * count;
1178
+ data = kzalloc(len, GFP_KERNEL);
1179
+ if (!data)
1180
+ return -ENOMEM;
1181
+ data->old_opp.supplies = (void *)(data + 1);
1182
+ data->new_opp.supplies = data->old_opp.supplies + count;
1183
+ info->set_opp_data = data;
1184
+ }
10251185
10261186 dev_pm_opp_put_opp_table(opp_table);
10271187
1028
- info->freq_table = freq_table;
1188
+ return 0;
1189
+}
1190
+
1191
+void rockchip_monitor_volt_adjust_lock(struct monitor_dev_info *info)
1192
+{
1193
+ if (info)
1194
+ mutex_lock(&info->volt_adjust_mutex);
1195
+}
1196
+EXPORT_SYMBOL(rockchip_monitor_volt_adjust_lock);
1197
+
1198
+void rockchip_monitor_volt_adjust_unlock(struct monitor_dev_info *info)
1199
+{
1200
+ if (info)
1201
+ mutex_unlock(&info->volt_adjust_mutex);
1202
+}
1203
+EXPORT_SYMBOL(rockchip_monitor_volt_adjust_unlock);
1204
+
1205
+static int rockchip_monitor_enable_opp_clk(struct device *dev,
1206
+ struct rockchip_opp_info *opp_info)
1207
+{
1208
+ int ret = 0;
1209
+
1210
+ if (!opp_info)
1211
+ return 0;
1212
+
1213
+ ret = clk_bulk_prepare_enable(opp_info->num_clks, opp_info->clks);
1214
+ if (ret) {
1215
+ dev_err(dev, "failed to enable opp clks\n");
1216
+ return ret;
1217
+ }
10291218
10301219 return 0;
10311220 }
10321221
1033
-static unsigned long monitor_freq_to_state(struct monitor_dev_info *info,
1034
- unsigned long freq)
1222
+static void rockchip_monitor_disable_opp_clk(struct device *dev,
1223
+ struct rockchip_opp_info *opp_info)
10351224 {
1036
- unsigned long i = 0;
1225
+ if (!opp_info)
1226
+ return;
10371227
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;
1228
+ clk_bulk_disable_unprepare(opp_info->num_clks, opp_info->clks);
10491229 }
10501230
1051
-static int monitor_temp_to_state(struct monitor_dev_info *info,
1052
- int temp, unsigned long *state)
1231
+static int rockchip_monitor_set_opp(struct monitor_dev_info *info,
1232
+ unsigned long old_freq,
1233
+ unsigned long freq,
1234
+ struct dev_pm_opp_supply *old_supply,
1235
+ struct dev_pm_opp_supply *new_supply)
10531236 {
1054
- unsigned long target_state, target_freq = 0;
1055
- int i;
1237
+ struct dev_pm_set_opp_data *data;
1238
+ int size;
10561239
1057
- if (temp == THERMAL_TEMP_INVALID)
1240
+ data = info->set_opp_data;
1241
+ data->regulators = info->regulators;
1242
+ data->regulator_count = info->regulator_count;
1243
+ data->clk = info->clk;
1244
+ data->dev = info->dev;
1245
+
1246
+ data->old_opp.rate = old_freq;
1247
+ size = sizeof(*old_supply) * info->regulator_count;
1248
+ if (!old_supply)
1249
+ memset(data->old_opp.supplies, 0, size);
1250
+ else
1251
+ memcpy(data->old_opp.supplies, old_supply, size);
1252
+
1253
+ data->new_opp.rate = freq;
1254
+ memcpy(data->new_opp.supplies, new_supply, size);
1255
+
1256
+ return info->devp->set_opp(data);
1257
+}
1258
+
1259
+int rockchip_monitor_check_rate_volt(struct monitor_dev_info *info)
1260
+{
1261
+ struct device *dev = info->dev;
1262
+ struct regulator *vdd_reg = NULL;
1263
+ struct regulator *mem_reg = NULL;
1264
+ struct rockchip_opp_info *opp_info = info->devp->opp_info;
1265
+ struct dev_pm_opp *opp;
1266
+ unsigned long old_rate, new_rate, new_volt, new_mem_volt;
1267
+ int old_volt, old_mem_volt;
1268
+ u32 target_rm = UINT_MAX;
1269
+ bool is_set_clk = true;
1270
+ bool is_set_rm = false;
1271
+ int ret = 0;
1272
+
1273
+ if (!info->regulators || !info->clk)
10581274 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;
1275
+
1276
+ mutex_lock(&info->volt_adjust_mutex);
1277
+
1278
+ vdd_reg = info->regulators[0];
1279
+ old_rate = clk_get_rate(info->clk);
1280
+ old_volt = regulator_get_voltage(vdd_reg);
1281
+ if (info->regulator_count > 1) {
1282
+ mem_reg = info->regulators[1];
1283
+ old_mem_volt = regulator_get_voltage(mem_reg);
1284
+ }
1285
+
1286
+ if (info->init_freq) {
1287
+ new_rate = info->init_freq * 1000;
1288
+ info->init_freq = 0;
1289
+ } else {
1290
+ new_rate = old_rate;
1291
+ }
1292
+ opp = dev_pm_opp_find_freq_ceil(dev, &new_rate);
1293
+ if (IS_ERR(opp)) {
1294
+ opp = dev_pm_opp_find_freq_floor(dev, &new_rate);
1295
+ if (IS_ERR(opp)) {
1296
+ ret = PTR_ERR(opp);
1297
+ goto unlock;
10631298 }
1064
- if (target_freq)
1065
- *state = monitor_freq_to_state(info,
1066
- target_freq * 1000);
1067
- else
1068
- *state = 0;
1299
+ }
1300
+ new_volt = opp->supplies[0].u_volt;
1301
+ if (info->regulator_count > 1)
1302
+ new_mem_volt = opp->supplies[1].u_volt;
1303
+ dev_pm_opp_put(opp);
1304
+
1305
+ if (old_rate == new_rate) {
1306
+ if (info->regulator_count > 1) {
1307
+ if (old_volt == new_volt &&
1308
+ new_mem_volt == old_mem_volt)
1309
+ goto unlock;
1310
+ } else if (old_volt == new_volt) {
1311
+ goto unlock;
1312
+ }
1313
+ }
1314
+ if (!new_volt || (info->regulator_count > 1 && !new_mem_volt))
1315
+ goto unlock;
1316
+
1317
+ if (info->devp->set_opp) {
1318
+ ret = rockchip_monitor_set_opp(info, old_rate, new_rate,
1319
+ NULL, opp->supplies);
1320
+ goto unlock;
10691321 }
10701322
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;
1323
+ if (opp_info && opp_info->data && opp_info->data->set_read_margin) {
1324
+ is_set_rm = true;
1325
+ if (info->devp->type == MONITOR_TYPE_DEV) {
1326
+ if (!pm_runtime_active(dev)) {
1327
+ is_set_rm = false;
1328
+ if (opp_info->scmi_clk)
1329
+ is_set_clk = false;
1330
+ }
1331
+ }
10761332 }
1333
+ rockchip_monitor_enable_opp_clk(dev, opp_info);
1334
+ rockchip_get_read_margin(dev, opp_info, new_volt, &target_rm);
10771335
1078
- return 0;
1336
+ dev_dbg(dev, "%s: %lu Hz --> %lu Hz\n", __func__, old_rate, new_rate);
1337
+ if (new_rate >= old_rate) {
1338
+ rockchip_set_intermediate_rate(dev, opp_info, info->clk,
1339
+ old_rate, new_rate,
1340
+ true, is_set_clk);
1341
+ if (info->regulator_count > 1) {
1342
+ ret = regulator_set_voltage(mem_reg, new_mem_volt,
1343
+ INT_MAX);
1344
+ if (ret) {
1345
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1346
+ __func__, new_mem_volt);
1347
+ goto restore_voltage;
1348
+ }
1349
+ }
1350
+ ret = regulator_set_voltage(vdd_reg, new_volt, INT_MAX);
1351
+ if (ret) {
1352
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1353
+ __func__, new_volt);
1354
+ goto restore_voltage;
1355
+ }
1356
+ rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm);
1357
+ if (is_set_clk && clk_set_rate(info->clk, new_rate)) {
1358
+ dev_err(dev, "%s: failed to set clock rate: %lu\n",
1359
+ __func__, new_rate);
1360
+ goto restore_rm;
1361
+ }
1362
+ } else {
1363
+ rockchip_set_intermediate_rate(dev, opp_info, info->clk,
1364
+ old_rate, new_rate,
1365
+ false, is_set_clk);
1366
+ rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm);
1367
+ if (is_set_clk && clk_set_rate(info->clk, new_rate)) {
1368
+ dev_err(dev, "%s: failed to set clock rate: %lu\n",
1369
+ __func__, new_rate);
1370
+ goto restore_rm;
1371
+ }
1372
+ ret = regulator_set_voltage(vdd_reg, new_volt,
1373
+ INT_MAX);
1374
+ if (ret) {
1375
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1376
+ __func__, new_volt);
1377
+ goto restore_freq;
1378
+ }
1379
+ if (info->regulator_count > 1) {
1380
+ ret = regulator_set_voltage(mem_reg, new_mem_volt,
1381
+ INT_MAX);
1382
+ if (ret) {
1383
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1384
+ __func__, new_mem_volt);
1385
+ goto restore_freq;
1386
+ }
1387
+ }
1388
+ }
1389
+ goto disable_clk;
1390
+
1391
+restore_freq:
1392
+ if (is_set_clk && clk_set_rate(info->clk, old_rate))
1393
+ dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
1394
+ __func__, old_rate);
1395
+restore_rm:
1396
+ rockchip_get_read_margin(dev, opp_info, old_volt, &target_rm);
1397
+ rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm);
1398
+restore_voltage:
1399
+ if (info->regulator_count > 1)
1400
+ regulator_set_voltage(mem_reg, old_mem_volt, INT_MAX);
1401
+ regulator_set_voltage(vdd_reg, old_volt, INT_MAX);
1402
+disable_clk:
1403
+ rockchip_monitor_disable_opp_clk(dev, opp_info);
1404
+unlock:
1405
+ mutex_unlock(&info->volt_adjust_mutex);
1406
+
1407
+ return ret;
10791408 }
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);
1409
+EXPORT_SYMBOL(rockchip_monitor_check_rate_volt);
10991410
11001411 struct monitor_dev_info *
11011412 rockchip_system_monitor_register(struct device *dev,
11021413 struct monitor_dev_profile *devp)
11031414 {
11041415 struct monitor_dev_info *info;
1105
- struct devfreq *devfreq;
1106
- int ret;
11071416
11081417 if (!system_monitor)
11091418 return ERR_PTR(-ENOMEM);
1419
+
1420
+ if (!devp)
1421
+ return ERR_PTR(-EINVAL);
11101422
11111423 info = kzalloc(sizeof(*info), GFP_KERNEL);
11121424 if (!info)
....@@ -1114,39 +1426,33 @@
11141426 info->dev = dev;
11151427 info->devp = devp;
11161428
1117
- ret = monitor_device_parse_dt(dev, info);
1118
- if (ret)
1119
- goto free_info;
1429
+ mutex_init(&info->volt_adjust_mutex);
11201430
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);
1431
+ rockchip_system_monitor_parse_supplies(dev, info);
1432
+ if (monitor_device_parse_dt(dev, info)) {
1433
+ rockchip_monitor_check_rate_volt(info);
1434
+ devp->is_checked = true;
1435
+ kfree(info->set_opp_data);
1436
+ kfree(info);
1437
+ return ERR_PTR(-EINVAL);
11291438 }
11301439
1440
+ rockchip_system_monitor_early_regulator_init(info);
11311441 rockchip_system_monitor_wide_temp_init(info);
1132
- mutex_init(&info->volt_adjust_mutex);
1442
+ rockchip_monitor_check_rate_volt(info);
1443
+ devp->is_checked = true;
1444
+ rockchip_system_monitor_freq_qos_requset(info);
11331445
11341446 down_write(&mdev_list_sem);
11351447 list_add(&info->node, &monitor_dev_list);
11361448 up_write(&mdev_list_sem);
11371449
11381450 return info;
1139
-
1140
-free_info:
1141
- kfree(info);
1142
- return ERR_PTR(-EINVAL);
11431451 }
11441452 EXPORT_SYMBOL(rockchip_system_monitor_register);
11451453
11461454 void rockchip_system_monitor_unregister(struct monitor_dev_info *info)
11471455 {
1148
- struct devfreq *devfreq;
1149
-
11501456 if (!info)
11511457 return;
11521458
....@@ -1154,18 +1460,59 @@
11541460 list_del(&info->node);
11551461 up_write(&mdev_list_sem);
11561462
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);
1463
+ if (info->devp->type == MONITOR_TYPE_CPU) {
1464
+ if (freq_qos_request_active(&info->max_temp_freq_req))
1465
+ freq_qos_remove_request(&info->max_temp_freq_req);
1466
+ if (freq_qos_request_active(&info->min_sta_freq_req))
1467
+ freq_qos_remove_request(&info->min_sta_freq_req);
1468
+ if (freq_qos_request_active(&info->max_sta_freq_req))
1469
+ freq_qos_remove_request(&info->max_sta_freq_req);
1470
+ } else {
1471
+ if (dev_pm_qos_request_active(&info->dev_max_freq_req))
1472
+ dev_pm_qos_remove_request(&info->dev_max_freq_req);
1473
+ }
11621474
11631475 kfree(info->low_temp_adjust_table);
11641476 kfree(info->opp_table);
1165
- kfree(info->freq_table);
1477
+ kfree(info->set_opp_data);
11661478 kfree(info);
11671479 }
11681480 EXPORT_SYMBOL(rockchip_system_monitor_unregister);
1481
+
1482
+int rockchip_system_monitor_register_notifier(struct notifier_block *nb)
1483
+{
1484
+ return blocking_notifier_chain_register(&system_monitor_notifier_list, nb);
1485
+}
1486
+EXPORT_SYMBOL(rockchip_system_monitor_register_notifier);
1487
+
1488
+void rockchip_system_monitor_unregister_notifier(struct notifier_block *nb)
1489
+{
1490
+ blocking_notifier_chain_unregister(&system_monitor_notifier_list, nb);
1491
+}
1492
+EXPORT_SYMBOL(rockchip_system_monitor_unregister_notifier);
1493
+
1494
+static int rockchip_system_monitor_temp_notify(int temp)
1495
+{
1496
+ struct system_monitor_event_data event_data;
1497
+ int ret;
1498
+
1499
+ event_data.temp = temp;
1500
+ ret = blocking_notifier_call_chain(&system_monitor_notifier_list,
1501
+ SYSTEM_MONITOR_CHANGE_TEMP,
1502
+ (void *)&event_data);
1503
+
1504
+ return notifier_to_errno(ret);
1505
+}
1506
+
1507
+static int notify_dummy(struct thermal_zone_device *tz, int trip)
1508
+{
1509
+ return 0;
1510
+}
1511
+
1512
+static struct thermal_governor thermal_gov_dummy = {
1513
+ .name = "dummy",
1514
+ .throttle = notify_dummy,
1515
+};
11691516
11701517 static int rockchip_system_monitor_parse_dt(struct system_monitor *monitor)
11711518 {
....@@ -1173,7 +1520,7 @@
11731520 const char *tz_name, *buf = NULL;
11741521
11751522 if (of_property_read_string(np, "rockchip,video-4k-offline-cpus", &buf))
1176
- cpumask_clear(&system_monitor->video_4k_offline_cpus);
1523
+ cpumask_clear(&monitor->video_4k_offline_cpus);
11771524 else
11781525 cpulist_parse(buf, &monitor->video_4k_offline_cpus);
11791526
....@@ -1199,6 +1546,13 @@
11991546 system_monitor->offline_cpus_temp = INT_MAX;
12001547 of_property_read_u32(np, "rockchip,temp-hysteresis",
12011548 &system_monitor->temp_hysteresis);
1549
+
1550
+ if (of_find_property(np, "rockchip,thermal-governor-dummy", NULL)) {
1551
+ if (monitor->tz->governor->unbind_from_tz)
1552
+ monitor->tz->governor->unbind_from_tz(monitor->tz);
1553
+ monitor->tz->governor = &thermal_gov_dummy;
1554
+ }
1555
+
12021556 out:
12031557 return 0;
12041558 }
....@@ -1224,7 +1578,7 @@
12241578 cpumask_copy(&system_monitor->offline_cpus, &offline_cpus);
12251579 for_each_cpu(cpu, &system_monitor->offline_cpus) {
12261580 if (cpu_online(cpu))
1227
- cpu_down(cpu);
1581
+ remove_cpu(cpu);
12281582 }
12291583
12301584 cpumask_clear(&online_cpus);
....@@ -1234,7 +1588,7 @@
12341588 if (cpumask_empty(&online_cpus))
12351589 goto out;
12361590 for_each_cpu(cpu, &online_cpus)
1237
- cpu_up(cpu);
1591
+ add_cpu(cpu);
12381592
12391593 out:
12401594 mutex_unlock(&cpu_on_off_mutex);
....@@ -1266,7 +1620,6 @@
12661620 {
12671621 int temp, ret;
12681622 struct monitor_dev_info *info;
1269
- static int last_temp = INT_MAX;
12701623
12711624 ret = thermal_zone_get_temp(system_monitor->tz, &temp);
12721625 if (ret || temp == THERMAL_TEMP_INVALID)
....@@ -1274,9 +1627,12 @@
12741627
12751628 dev_dbg(system_monitor->dev, "temperature=%d\n", temp);
12761629
1277
- if (temp < last_temp && last_temp - temp <= 2000)
1630
+ if (temp < system_monitor->last_temp &&
1631
+ system_monitor->last_temp - temp <= 2000)
12781632 goto out;
1279
- last_temp = temp;
1633
+ system_monitor->last_temp = temp;
1634
+
1635
+ rockchip_system_monitor_temp_notify(temp);
12801636
12811637 down_read(&mdev_list_sem);
12821638 list_for_each_entry(info, &monitor_dev_list, node)
....@@ -1302,26 +1658,32 @@
13021658 unsigned long status)
13031659 {
13041660 unsigned int target_freq = 0;
1305
- bool is_freq_fixed = false;
1306
- int cpu;
1661
+
1662
+ if (!freq_qos_request_active(&info->min_sta_freq_req))
1663
+ return;
1664
+ if (!freq_qos_request_active(&info->max_sta_freq_req))
1665
+ return;
13071666
13081667 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;
1668
+ freq_qos_update_request(&info->max_sta_freq_req,
1669
+ info->reboot_freq);
1670
+ freq_qos_update_request(&info->min_sta_freq_req,
1671
+ info->reboot_freq);
1672
+ return;
13131673 }
13141674
13151675 if (info->video_4k_freq && (status & SYS_STATUS_VIDEO_4K))
13161676 target_freq = info->video_4k_freq;
1317
- if (target_freq == info->status_max_limit &&
1318
- info->is_status_freq_fixed == is_freq_fixed)
1677
+
1678
+ if (target_freq == info->status_max_limit)
13191679 return;
13201680 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);
1681
+ if (info->status_max_limit)
1682
+ freq_qos_update_request(&info->max_sta_freq_req,
1683
+ info->status_max_limit);
1684
+ else
1685
+ freq_qos_update_request(&info->max_sta_freq_req,
1686
+ FREQ_QOS_MAX_DEFAULT_VALUE);
13251687 }
13261688
13271689 static void rockchip_system_status_limit_freq(unsigned long status)
....@@ -1330,7 +1692,7 @@
13301692
13311693 down_read(&mdev_list_sem);
13321694 list_for_each_entry(info, &monitor_dev_list, node) {
1333
- if (info->devp->type == MONITOR_TPYE_CPU)
1695
+ if (info->devp->type == MONITOR_TYPE_CPU)
13341696 rockchip_system_status_cpu_limit_freq(info, status);
13351697 }
13361698 up_read(&mdev_list_sem);
....@@ -1364,6 +1726,26 @@
13641726 return NOTIFY_OK;
13651727 }
13661728
1729
+static int rockchip_system_monitor_set_cpu_uevent_suppress(bool is_suppress)
1730
+{
1731
+ struct monitor_dev_info *info;
1732
+ struct cpufreq_policy *policy;
1733
+
1734
+ list_for_each_entry(info, &monitor_dev_list, node) {
1735
+ if (info->devp->type != MONITOR_TYPE_CPU)
1736
+ continue;
1737
+ policy = (struct cpufreq_policy *)info->devp->data;
1738
+ if (!policy || !policy->cdev)
1739
+ continue;
1740
+ if (is_suppress)
1741
+ dev_set_uevent_suppress(&policy->cdev->device, 1);
1742
+ else
1743
+ dev_set_uevent_suppress(&policy->cdev->device, 0);
1744
+ }
1745
+
1746
+ return 0;
1747
+}
1748
+
13671749 static int monitor_pm_notify(struct notifier_block *nb,
13681750 unsigned long mode, void *_unused)
13691751 {
....@@ -1372,6 +1754,7 @@
13721754 case PM_RESTORE_PREPARE:
13731755 case PM_SUSPEND_PREPARE:
13741756 atomic_set(&monitor_in_suspend, 1);
1757
+ rockchip_system_monitor_set_cpu_uevent_suppress(true);
13751758 break;
13761759 case PM_POST_HIBERNATION:
13771760 case PM_POST_RESTORE:
....@@ -1379,6 +1762,8 @@
13791762 if (system_monitor->tz)
13801763 rockchip_system_monitor_thermal_update();
13811764 atomic_set(&monitor_in_suspend, 0);
1765
+ rockchip_system_monitor_set_cpu_uevent_suppress(false);
1766
+ system_monitor->last_temp = INT_MAX;
13821767 break;
13831768 default:
13841769 break;
....@@ -1388,51 +1773,6 @@
13881773
13891774 static struct notifier_block monitor_pm_nb = {
13901775 .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,
14361776 };
14371777
14381778 static int rockchip_monitor_reboot_notifier(struct notifier_block *nb,
....@@ -1454,24 +1794,15 @@
14541794 {
14551795 struct fb_event *event = ptr;
14561796
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
- }
1797
+ if (action != FB_EVENT_BLANK)
1798
+ return NOTIFY_OK;
1799
+
1800
+ switch (*((int *)event->data)) {
1801
+ case FB_BLANK_UNBLANK:
1802
+ rockchip_clear_system_status(SYS_STATUS_SUSPEND);
14661803 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
- }
1804
+ case FB_BLANK_POWERDOWN:
1805
+ rockchip_set_system_status(SYS_STATUS_SUSPEND);
14751806 break;
14761807 default:
14771808 break;
....@@ -1494,12 +1825,6 @@
14941825 case EBC_OFF:
14951826 rockchip_set_system_status(SYS_STATUS_LOW_POWER);
14961827 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;
15031828 default:
15041829 break;
15051830 }
....@@ -1510,6 +1835,32 @@
15101835 static struct notifier_block rockchip_monitor_ebc_nb = {
15111836 .notifier_call = rockchip_eink_devfs_notifier,
15121837 };
1838
+
1839
+static void system_monitor_early_min_volt_function(struct work_struct *work)
1840
+{
1841
+ struct monitor_dev_info *info;
1842
+ struct regulator_dev *rdev;
1843
+ int min_uV, max_uV;
1844
+ int ret;
1845
+
1846
+ down_read(&mdev_list_sem);
1847
+ list_for_each_entry(info, &monitor_dev_list, node) {
1848
+ if (!info->early_min_volt || !info->early_reg)
1849
+ continue;
1850
+ rdev = info->early_reg->rdev;
1851
+ min_uV = rdev->constraints->min_uV;
1852
+ max_uV = rdev->constraints->max_uV;
1853
+ ret = regulator_set_voltage(info->early_reg, min_uV, max_uV);
1854
+ if (ret)
1855
+ dev_err(&rdev->dev,
1856
+ "%s: failed to set volt\n", __func__);
1857
+ regulator_put(info->early_reg);
1858
+ }
1859
+ up_read(&mdev_list_sem);
1860
+}
1861
+
1862
+static DECLARE_DELAYED_WORK(system_monitor_early_min_volt_work,
1863
+ system_monitor_early_min_volt_function);
15131864
15141865 static int rockchip_system_monitor_probe(struct platform_device *pdev)
15151866 {
....@@ -1532,6 +1883,7 @@
15321883
15331884 rockchip_system_monitor_parse_dt(system_monitor);
15341885 if (system_monitor->tz) {
1886
+ system_monitor->last_temp = INT_MAX;
15351887 INIT_DELAYED_WORK(&system_monitor->thermal_work,
15361888 rockchip_system_monitor_thermal_check);
15371889 mod_delayed_work(system_freezable_wq,
....@@ -1546,9 +1898,6 @@
15461898 if (register_pm_notifier(&monitor_pm_nb))
15471899 dev_err(dev, "failed to register suspend notifier\n");
15481900
1549
- cpufreq_register_notifier(&rockchip_monitor_cpufreq_policy_nb,
1550
- CPUFREQ_POLICY_NOTIFIER);
1551
-
15521901 register_reboot_notifier(&rockchip_monitor_reboot_nb);
15531902
15541903 if (fb_register_client(&rockchip_monitor_fb_nb))
....@@ -1556,6 +1905,9 @@
15561905
15571906 ebc_register_notifier(&rockchip_monitor_ebc_nb);
15581907
1908
+ schedule_delayed_work(&system_monitor_early_min_volt_work,
1909
+ msecs_to_jiffies(30000));
1910
+
15591911 dev_info(dev, "system monitor probe\n");
15601912
15611913 return 0;