hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/soc/rockchip/rockchip_system_monitor.c
....@@ -4,9 +4,10 @@
44 * Author: Finley Xiao <finley.xiao@rock-chips.com>
55 */
66
7
-#include <dt-bindings/soc/rockchip-system-status.h>
7
+#include <linux/clk-provider.h>
88 #include <linux/cpu.h>
99 #include <linux/cpufreq.h>
10
+#include <linux/devfreq.h>
1011 #include <linux/device.h>
1112 #include <linux/fb.h>
1213 #include <linux/module.h>
....@@ -15,26 +16,32 @@
1516 #include <linux/of.h>
1617 #include <linux/platform_device.h>
1718 #include <linux/pm_opp.h>
18
-#include <linux/uaccess.h>
19
+#include <linux/pm_qos.h>
20
+#include <linux/pm_runtime.h>
21
+#include <linux/regulator/consumer.h>
22
+#include <linux/regulator/coupler.h>
23
+#include <linux/regulator/driver.h>
24
+#include <linux/regulator/machine.h>
1925 #include <linux/reboot.h>
26
+#include <linux/rockchip/rockchip_sip.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
....@@ -237,34 +246,6 @@
237246 return video_info;
238247 }
239248
240
-static struct video_info *rockchip_find_video_info(const char *buf)
241
-{
242
- struct video_info *info, *video_info;
243
-
244
- video_info = rockchip_parse_video_info(buf);
245
-
246
- if (!video_info)
247
- return NULL;
248
-
249
- mutex_lock(&video_info_mutex);
250
- list_for_each_entry(info, &video_info_list, node) {
251
- if (info->width == video_info->width &&
252
- info->height == video_info->height &&
253
- info->ishevc == video_info->ishevc &&
254
- info->videoFramerate == video_info->videoFramerate &&
255
- info->streamBitrate == video_info->streamBitrate) {
256
- mutex_unlock(&video_info_mutex);
257
- kfree(video_info);
258
- return info;
259
- }
260
- }
261
-
262
- mutex_unlock(&video_info_mutex);
263
- kfree(video_info);
264
-
265
- return NULL;
266
-}
267
-
268249 static void rockchip_add_video_info(struct video_info *video_info)
269250 {
270251 if (video_info) {
....@@ -276,18 +257,32 @@
276257
277258 static void rockchip_del_video_info(struct video_info *video_info)
278259 {
279
- if (video_info) {
280
- mutex_lock(&video_info_mutex);
281
- list_del(&video_info->node);
282
- mutex_unlock(&video_info_mutex);
283
- kfree(video_info);
260
+ struct video_info *info, *tmp;
261
+
262
+ if (!video_info)
263
+ return;
264
+
265
+ mutex_lock(&video_info_mutex);
266
+ list_for_each_entry_safe(info, tmp, &video_info_list, node) {
267
+ if (info->width == video_info->width &&
268
+ info->height == video_info->height &&
269
+ info->ishevc == video_info->ishevc &&
270
+ info->videoFramerate == video_info->videoFramerate &&
271
+ info->streamBitrate == video_info->streamBitrate) {
272
+ list_del(&info->node);
273
+ kfree(info);
274
+ break;
275
+ }
284276 }
277
+ kfree(video_info);
278
+ mutex_unlock(&video_info_mutex);
285279 }
286280
287281 static void rockchip_update_video_info(void)
288282 {
289283 struct video_info *video_info;
290284 unsigned int max_res = 0, max_stream_bitrate = 0, res = 0;
285
+ unsigned int max_video_framerate = 0;
291286
292287 mutex_lock(&video_info_mutex);
293288 if (list_empty(&video_info_list)) {
....@@ -302,6 +297,8 @@
302297 max_res = res;
303298 if (video_info->streamBitrate > max_stream_bitrate)
304299 max_stream_bitrate = video_info->streamBitrate;
300
+ if (video_info->videoFramerate > max_video_framerate)
301
+ max_video_framerate = video_info->videoFramerate;
305302 }
306303 mutex_unlock(&video_info_mutex);
307304
....@@ -310,8 +307,9 @@
310307 } else {
311308 if (max_stream_bitrate == 10)
312309 rockchip_set_system_status(SYS_STATUS_VIDEO_4K_10B);
313
- else
314
- rockchip_set_system_status(SYS_STATUS_VIDEO_4K);
310
+ if (max_video_framerate == 60)
311
+ rockchip_set_system_status(SYS_STATUS_VIDEO_4K_60P);
312
+ rockchip_set_system_status(SYS_STATUS_VIDEO_4K);
315313 }
316314 }
317315
....@@ -325,7 +323,7 @@
325323 switch (buf[0]) {
326324 case '0':
327325 /* clear video flag */
328
- video_info = rockchip_find_video_info(buf);
326
+ video_info = rockchip_parse_video_info(buf);
329327 if (video_info) {
330328 rockchip_del_video_info(video_info);
331329 rockchip_update_video_info();
....@@ -354,6 +352,14 @@
354352 case 'n':
355353 /* clear performance flag */
356354 rockchip_clear_system_status(SYS_STATUS_PERFORMANCE);
355
+ break;
356
+ case 'S':
357
+ /* set video svep flag */
358
+ rockchip_set_system_status(SYS_STATUS_VIDEO_SVEP);
359
+ break;
360
+ case 's':
361
+ /* clear video svep flag */
362
+ rockchip_clear_system_status(SYS_STATUS_VIDEO_SVEP);
357363 break;
358364 default:
359365 break;
....@@ -492,8 +498,11 @@
492498 int delta_volt = 0;
493499 int i = 0, max_count;
494500 unsigned long low_limit = 0, high_limit = 0;
501
+ unsigned long low_limit_mem = 0, high_limit_mem = 0;
495502 bool reach_max_volt = false;
503
+ bool reach_max_mem_volt = false;
496504 bool reach_high_temp_max_volt = false;
505
+ bool reach_high_temp_max_mem_volt = false;
497506
498507 max_count = dev_pm_opp_get_opp_count(dev);
499508 if (max_count <= 0)
....@@ -511,6 +520,8 @@
511520 }
512521 mutex_lock(&opp_table->lock);
513522 list_for_each_entry(opp, &opp_table->opp_list, node) {
523
+ if (!opp->available)
524
+ continue;
514525 info->opp_table[i].rate = opp->rate;
515526 info->opp_table[i].volt = opp->supplies[0].u_volt;
516527 info->opp_table[i].max_volt = opp->supplies[0].u_volt_max;
....@@ -542,9 +553,48 @@
542553 info->low_limit = low_limit;
543554 if (high_limit && high_limit != opp->rate)
544555 info->high_limit = high_limit;
545
- dev_dbg(dev, "rate=%lu, volt=%lu, low_temp_volt=%lu\n",
556
+
557
+ if (opp_table->regulator_count > 1) {
558
+ info->opp_table[i].mem_volt = opp->supplies[1].u_volt;
559
+ info->opp_table[i].max_mem_volt = opp->supplies[1].u_volt_max;
560
+
561
+ if (opp->supplies[1].u_volt <= info->high_temp_max_volt) {
562
+ if (!reach_high_temp_max_mem_volt)
563
+ high_limit_mem = opp->rate;
564
+ if (opp->supplies[1].u_volt == info->high_temp_max_volt)
565
+ reach_high_temp_max_mem_volt = true;
566
+ }
567
+
568
+ if ((opp->supplies[1].u_volt + delta_volt) <= info->max_volt) {
569
+ info->opp_table[i].low_temp_mem_volt =
570
+ opp->supplies[1].u_volt + delta_volt;
571
+ if (info->opp_table[i].low_temp_mem_volt <
572
+ info->low_temp_min_volt)
573
+ info->opp_table[i].low_temp_mem_volt =
574
+ info->low_temp_min_volt;
575
+ if (!reach_max_mem_volt)
576
+ low_limit_mem = opp->rate;
577
+ if (info->opp_table[i].low_temp_mem_volt == info->max_volt)
578
+ reach_max_mem_volt = true;
579
+ } else {
580
+ info->opp_table[i].low_temp_mem_volt = info->max_volt;
581
+ }
582
+
583
+ if (low_limit_mem && low_limit_mem != opp->rate) {
584
+ if (info->low_limit > low_limit_mem)
585
+ info->low_limit = low_limit_mem;
586
+ }
587
+ if (high_limit_mem && high_limit_mem != opp->rate) {
588
+ if (info->high_limit > high_limit_mem)
589
+ info->high_limit = high_limit_mem;
590
+ }
591
+ }
592
+
593
+ dev_dbg(dev, "rate=%lu, volt=%lu %lu low_temp_volt=%lu %lu\n",
546594 info->opp_table[i].rate, info->opp_table[i].volt,
547
- info->opp_table[i].low_temp_volt);
595
+ info->opp_table[i].mem_volt,
596
+ info->opp_table[i].low_temp_volt,
597
+ info->opp_table[i].low_temp_mem_volt);
548598 i++;
549599 }
550600 mutex_unlock(&opp_table->lock);
....@@ -586,9 +636,12 @@
586636 else
587637 info->high_temp_max_volt = value;
588638 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;
639
+ rockchip_get_temp_freq_table(np, "rockchip,temp-freq-table",
640
+ &info->high_limit_table);
641
+ if (!info->high_limit_table)
642
+ rockchip_get_temp_freq_table(np, "rockchip,high-temp-limit-table",
643
+ &info->high_limit_table);
644
+ if (!info->high_limit_table) {
592645 if (!of_property_read_u32(np, "rockchip,high-temp-max-freq",
593646 &value)) {
594647 high_temp_max_freq = value * 1000;
....@@ -640,7 +693,7 @@
640693 &info->video_4k_freq);
641694 ret &= of_property_read_u32(np, "rockchip,reboot-freq",
642695 &info->reboot_freq);
643
- if (info->devp->type == MONITOR_TPYE_CPU) {
696
+ if (info->devp->type == MONITOR_TYPE_CPU) {
644697 if (!info->reboot_freq) {
645698 info->reboot_freq = CPU_REBOOT_FREQ;
646699 ret = 0;
....@@ -650,66 +703,70 @@
650703 return ret;
651704 }
652705
706
+static int monitor_device_parse_early_min_volt(struct device_node *np,
707
+ struct monitor_dev_info *info)
708
+{
709
+ return of_property_read_u32(np, "rockchip,early-min-microvolt",
710
+ &info->early_min_volt);
711
+}
712
+
713
+static int monitor_device_parse_read_margin(struct device_node *np,
714
+ struct monitor_dev_info *info)
715
+{
716
+ if (of_property_read_bool(np, "volt-mem-read-margin"))
717
+ return 0;
718
+ return -EINVAL;
719
+}
720
+
721
+static int monitor_device_parse_scmi_clk(struct device_node *np,
722
+ struct monitor_dev_info *info)
723
+{
724
+ struct clk *clk;
725
+
726
+ clk = clk_get(info->dev, NULL);
727
+ if (strstr(__clk_get_name(clk), "scmi"))
728
+ return 0;
729
+ return -EINVAL;
730
+}
731
+
653732 static int monitor_device_parse_dt(struct device *dev,
654733 struct monitor_dev_info *info)
655734 {
656735 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;
736
+ int ret;
661737
662738 np = of_parse_phandle(dev->of_node, "operating-points-v2", 0);
663739 if (!np)
664740 return -EINVAL;
665741
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;
742
+ of_property_read_u32(np, "rockchip,init-freq", &info->init_freq);
743
+
744
+ ret = monitor_device_parse_wide_temp_config(np, info);
745
+ ret &= monitor_device_parse_status_config(np, info);
746
+ ret &= monitor_device_parse_early_min_volt(np, info);
747
+ ret &= monitor_device_parse_read_margin(np, info);
748
+ ret &= monitor_device_parse_scmi_clk(np, info);
677749
678750 of_node_put(np);
679751
680752 return ret;
681753 }
682754
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
-
696755 int rockchip_monitor_cpu_low_temp_adjust(struct monitor_dev_info *info,
697756 bool is_low)
698757 {
699
- struct device *dev = info->dev;
700
- unsigned int cpu = cpumask_any(&info->devp->allowed_cpus);
758
+ if (!info->low_limit)
759
+ return 0;
701760
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
- }
761
+ if (!freq_qos_request_active(&info->max_temp_freq_req))
762
+ return 0;
709763
710
- mutex_lock(&info->volt_adjust_mutex);
711
- dev_pm_opp_check_rate_volt(dev, false);
712
- mutex_unlock(&info->volt_adjust_mutex);
764
+ if (is_low)
765
+ freq_qos_update_request(&info->max_temp_freq_req,
766
+ info->low_limit / 1000);
767
+ else
768
+ freq_qos_update_request(&info->max_temp_freq_req,
769
+ FREQ_QOS_MAX_DEFAULT_VALUE);
713770
714771 return 0;
715772 }
....@@ -718,53 +775,44 @@
718775 int rockchip_monitor_cpu_high_temp_adjust(struct monitor_dev_info *info,
719776 bool is_high)
720777 {
721
- unsigned int cpu = cpumask_any(&info->devp->allowed_cpus);
778
+ if (!info->high_limit)
779
+ return 0;
780
+
781
+ if (!freq_qos_request_active(&info->max_temp_freq_req))
782
+ return 0;
722783
723784 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
- }
785
+ freq_qos_update_request(&info->max_temp_freq_req,
786
+ info->high_limit / 1000);
787
+ return 0;
734788 }
789
+
790
+ if (is_high)
791
+ freq_qos_update_request(&info->max_temp_freq_req,
792
+ info->high_limit / 1000);
793
+ else
794
+ freq_qos_update_request(&info->max_temp_freq_req,
795
+ FREQ_QOS_MAX_DEFAULT_VALUE);
735796
736797 return 0;
737798 }
738799 EXPORT_SYMBOL(rockchip_monitor_cpu_high_temp_adjust);
739800
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
-
752801 int rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info *info,
753802 bool is_low)
754803 {
755
- struct devfreq *df;
804
+ if (!dev_pm_qos_request_active(&info->dev_max_freq_req))
805
+ return 0;
756806
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
- }
807
+ if (!info->low_limit)
808
+ return 0;
763809
764
- if (info->devp && info->devp->data) {
765
- df = (struct devfreq *)info->devp->data;
766
- rockchip_monitor_update_devfreq(df);
767
- }
810
+ if (is_low)
811
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
812
+ info->low_limit / 1000);
813
+ else
814
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
815
+ PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE);
768816
769817 return 0;
770818 }
....@@ -773,26 +821,24 @@
773821 int rockchip_monitor_dev_high_temp_adjust(struct monitor_dev_info *info,
774822 bool is_high)
775823 {
776
- struct devfreq *df;
824
+ if (!dev_pm_qos_request_active(&info->dev_max_freq_req))
825
+ return 0;
826
+
827
+ if (!info->high_limit)
828
+ return 0;
777829
778830 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
- }
831
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
832
+ info->high_limit / 1000);
833
+ return 0;
795834 }
835
+
836
+ if (is_high)
837
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
838
+ info->high_limit / 1000);
839
+ else
840
+ dev_pm_qos_update_request(&info->dev_max_freq_req,
841
+ PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE);
796842
797843 return 0;
798844 }
....@@ -812,6 +858,8 @@
812858
813859 mutex_lock(&opp_table->lock);
814860 list_for_each_entry(opp, &opp_table->opp_list, node) {
861
+ if (!opp->available)
862
+ continue;
815863 if (is_low_temp) {
816864 if (opp->supplies[0].u_volt_max <
817865 info->opp_table[i].low_temp_volt)
....@@ -820,11 +868,29 @@
820868 opp->supplies[0].u_volt =
821869 info->opp_table[i].low_temp_volt;
822870 opp->supplies[0].u_volt_min = opp->supplies[0].u_volt;
871
+ if (opp_table->regulator_count > 1) {
872
+ if (opp->supplies[1].u_volt_max <
873
+ info->opp_table[i].low_temp_mem_volt)
874
+ opp->supplies[1].u_volt_max =
875
+ info->opp_table[i].low_temp_mem_volt;
876
+ opp->supplies[1].u_volt =
877
+ info->opp_table[i].low_temp_mem_volt;
878
+ opp->supplies[1].u_volt_min =
879
+ opp->supplies[1].u_volt;
880
+ }
823881 } else {
824882 opp->supplies[0].u_volt_min = info->opp_table[i].volt;
825883 opp->supplies[0].u_volt = opp->supplies[0].u_volt_min;
826884 opp->supplies[0].u_volt_max =
827885 info->opp_table[i].max_volt;
886
+ if (opp_table->regulator_count > 1) {
887
+ opp->supplies[1].u_volt_min =
888
+ info->opp_table[i].mem_volt;
889
+ opp->supplies[1].u_volt =
890
+ opp->supplies[1].u_volt_min;
891
+ opp->supplies[1].u_volt_max =
892
+ info->opp_table[i].max_mem_volt;
893
+ }
828894 }
829895 i++;
830896 }
....@@ -839,6 +905,7 @@
839905 bool is_low)
840906 {
841907 struct monitor_dev_profile *devp = info->devp;
908
+ struct arm_smccc_res res;
842909 int ret = 0;
843910
844911 dev_dbg(info->dev, "low_temp %d\n", is_low);
....@@ -850,6 +917,20 @@
850917 ret = devp->low_temp_adjust(info, is_low);
851918 if (!ret)
852919 info->is_low_temp = is_low;
920
+
921
+ if (devp->update_volt)
922
+ devp->update_volt(info);
923
+
924
+ if (devp->opp_info && devp->opp_info->pvtpll_low_temp) {
925
+ res = sip_smc_pvtpll_config(PVTPLL_LOW_TEMP,
926
+ devp->opp_info->pvtpll_clk_id,
927
+ is_low, 0, 0, 0, 0);
928
+ if (res.a0)
929
+ dev_err(info->dev,
930
+ "%s: error cfg id=%u low temp %d (%d)\n",
931
+ __func__, devp->opp_info->pvtpll_clk_id,
932
+ is_low, (int)res.a0);
933
+ }
853934 }
854935
855936 static void rockchip_high_temp_adjust(struct monitor_dev_info *info,
....@@ -858,12 +939,14 @@
858939 struct monitor_dev_profile *devp = info->devp;
859940 int ret = 0;
860941
942
+ if (!devp->high_temp_adjust)
943
+ return;
944
+
861945 if (info->high_limit_table) {
862946 devp->high_temp_adjust(info, is_high);
863947 } else {
864948 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);
949
+ ret = devp->high_temp_adjust(info, is_high);
867950 if (!ret)
868951 info->is_high_temp = is_high;
869952 }
....@@ -874,7 +957,7 @@
874957 struct monitor_dev_info *info = NULL, *tmp;
875958
876959 list_for_each_entry(tmp, &monitor_dev_list, node) {
877
- if (tmp->devp->type != MONITOR_TPYE_CPU)
960
+ if (tmp->devp->type != MONITOR_TYPE_CPU)
878961 continue;
879962 if (cpumask_test_cpu(cpu, &tmp->devp->allowed_cpus)) {
880963 info = tmp;
....@@ -941,6 +1024,11 @@
9411024 {
9421025 int ret, temp;
9431026
1027
+ if (!info->opp_table)
1028
+ return;
1029
+ if (!system_monitor->tz)
1030
+ return;
1031
+
9441032 /*
9451033 * set the init state to low temperature that the voltage will be enough
9461034 * when cpu up at low temperature.
....@@ -948,7 +1036,6 @@
9481036 if (!info->is_low_temp) {
9491037 if (info->opp_table)
9501038 rockchip_adjust_low_temp_opp_volt(info, true);
951
- info->wide_temp_limit = info->low_limit;
9521039 info->is_low_temp = true;
9531040 }
9541041
....@@ -963,150 +1050,386 @@
9631050 if (info->opp_table)
9641051 rockchip_adjust_low_temp_opp_volt(info, false);
9651052 info->is_low_temp = false;
966
-
967
- info->wide_temp_limit = info->high_limit;
9681053 info->is_high_temp = true;
9691054 } else if (temp > (info->low_temp + info->temp_hysteresis)) {
9701055 if (info->opp_table)
9711056 rockchip_adjust_low_temp_opp_volt(info, false);
9721057 info->is_low_temp = false;
973
- info->wide_temp_limit = 0;
9741058 }
9751059 }
9761060
977
-static int system_monitor_devfreq_notifier_call(struct notifier_block *nb,
978
- unsigned long event,
979
- void *data)
1061
+static const char *get_rdev_name(struct regulator_dev *rdev)
9801062 {
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;
1063
+ if (rdev->constraints && rdev->constraints->name)
1064
+ return rdev->constraints->name;
1065
+ else if (rdev->desc->name)
1066
+ return rdev->desc->name;
1067
+ else
1068
+ return "";
9911069 }
9921070
993
-static int monitor_set_freq_table(struct device *dev,
994
- struct monitor_dev_info *info)
1071
+static void
1072
+rockchip_system_monitor_early_regulator_init(struct monitor_dev_info *info)
9951073 {
996
- struct opp_table *opp_table;
997
- struct dev_pm_opp *opp;
998
- unsigned long *freq_table;
999
- int count;
1074
+ struct regulator *reg;
1075
+ struct regulator_dev *rdev;
10001076
1001
- opp_table = dev_pm_opp_get_opp_table(dev);
1002
- if (!opp_table)
1003
- return -ENOMEM;
1077
+ if (!info->early_min_volt || !info->regulators)
1078
+ return;
10041079
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;
1080
+ rdev = info->regulators[0]->rdev;
1081
+ reg = regulator_get(NULL, get_rdev_name(rdev));
1082
+ if (!IS_ERR_OR_NULL(reg)) {
1083
+ info->early_reg = reg;
1084
+ reg->voltage[PM_SUSPEND_ON].min_uV = info->early_min_volt;
1085
+ reg->voltage[PM_SUSPEND_ON].max_uV = rdev->constraints->max_uV;
10151086 }
1087
+}
10161088
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;
1089
+static int
1090
+rockchip_system_monitor_freq_qos_requset(struct monitor_dev_info *info)
1091
+{
1092
+ struct devfreq *devfreq;
1093
+ struct cpufreq_policy *policy;
1094
+ int max_default_value = FREQ_QOS_MAX_DEFAULT_VALUE;
1095
+ int ret;
1096
+
1097
+ if (!info->devp->data)
1098
+ return 0;
1099
+
1100
+ if (info->is_low_temp && info->low_limit)
1101
+ max_default_value = info->low_limit / 1000;
1102
+ else if (info->is_high_temp && info->high_limit)
1103
+ max_default_value = info->high_limit / 1000;
1104
+
1105
+ if (info->devp->type == MONITOR_TYPE_CPU) {
1106
+ policy = (struct cpufreq_policy *)info->devp->data;
1107
+ ret = freq_qos_add_request(&policy->constraints,
1108
+ &info->max_temp_freq_req,
1109
+ FREQ_QOS_MAX,
1110
+ max_default_value);
1111
+ if (ret < 0) {
1112
+ dev_info(info->dev,
1113
+ "failed to add temp freq constraint\n");
1114
+ return ret;
1115
+ }
1116
+ ret = freq_qos_add_request(&policy->constraints,
1117
+ &info->min_sta_freq_req,
1118
+ FREQ_QOS_MIN,
1119
+ FREQ_QOS_MIN_DEFAULT_VALUE);
1120
+ if (ret < 0) {
1121
+ dev_info(info->dev,
1122
+ "failed to add sta freq constraint\n");
1123
+ freq_qos_remove_request(&info->max_temp_freq_req);
1124
+ return ret;
1125
+ }
1126
+ ret = freq_qos_add_request(&policy->constraints,
1127
+ &info->max_sta_freq_req,
1128
+ FREQ_QOS_MAX,
1129
+ FREQ_QOS_MAX_DEFAULT_VALUE);
1130
+ if (ret < 0) {
1131
+ dev_info(info->dev,
1132
+ "failed to add sta freq constraint\n");
1133
+ freq_qos_remove_request(&info->max_temp_freq_req);
1134
+ freq_qos_remove_request(&info->min_sta_freq_req);
1135
+ return ret;
1136
+ }
1137
+ } else if (info->devp->type == MONITOR_TYPE_DEV) {
1138
+ devfreq = (struct devfreq *)info->devp->data;
1139
+ ret = dev_pm_qos_add_request(devfreq->dev.parent,
1140
+ &info->dev_max_freq_req,
1141
+ DEV_PM_QOS_MAX_FREQUENCY,
1142
+ max_default_value);
1143
+ if (ret < 0) {
1144
+ dev_info(info->dev, "failed to add freq constraint\n");
1145
+ return ret;
10221146 }
10231147 }
1024
- mutex_unlock(&opp_table->lock);
1148
+
1149
+ return 0;
1150
+}
1151
+
1152
+static int rockchip_system_monitor_parse_supplies(struct device *dev,
1153
+ struct monitor_dev_info *info)
1154
+{
1155
+ struct opp_table *opp_table;
1156
+ struct dev_pm_set_opp_data *data;
1157
+ int len, count;
1158
+
1159
+ opp_table = dev_pm_opp_get_opp_table(dev);
1160
+ if (IS_ERR(opp_table))
1161
+ return PTR_ERR(opp_table);
1162
+
1163
+ if (opp_table->clk)
1164
+ info->clk = opp_table->clk;
1165
+ if (opp_table->regulators)
1166
+ info->regulators = opp_table->regulators;
1167
+ info->regulator_count = opp_table->regulator_count;
1168
+
1169
+ if (opp_table->regulators && info->devp->set_opp) {
1170
+ count = opp_table->regulator_count;
1171
+ /* space for set_opp_data */
1172
+ len = sizeof(*data);
1173
+ /* space for old_opp.supplies and new_opp.supplies */
1174
+ len += 2 * sizeof(struct dev_pm_opp_supply) * count;
1175
+ data = kzalloc(len, GFP_KERNEL);
1176
+ if (!data)
1177
+ return -ENOMEM;
1178
+ data->old_opp.supplies = (void *)(data + 1);
1179
+ data->new_opp.supplies = data->old_opp.supplies + count;
1180
+ info->set_opp_data = data;
1181
+ }
10251182
10261183 dev_pm_opp_put_opp_table(opp_table);
10271184
1028
- info->freq_table = freq_table;
1185
+ return 0;
1186
+}
1187
+
1188
+void rockchip_monitor_volt_adjust_lock(struct monitor_dev_info *info)
1189
+{
1190
+ if (info)
1191
+ mutex_lock(&info->volt_adjust_mutex);
1192
+}
1193
+EXPORT_SYMBOL(rockchip_monitor_volt_adjust_lock);
1194
+
1195
+void rockchip_monitor_volt_adjust_unlock(struct monitor_dev_info *info)
1196
+{
1197
+ if (info)
1198
+ mutex_unlock(&info->volt_adjust_mutex);
1199
+}
1200
+EXPORT_SYMBOL(rockchip_monitor_volt_adjust_unlock);
1201
+
1202
+static int rockchip_monitor_enable_opp_clk(struct device *dev,
1203
+ struct rockchip_opp_info *opp_info)
1204
+{
1205
+ int ret = 0;
1206
+
1207
+ if (!opp_info)
1208
+ return 0;
1209
+
1210
+ ret = clk_bulk_prepare_enable(opp_info->num_clks, opp_info->clks);
1211
+ if (ret) {
1212
+ dev_err(dev, "failed to enable opp clks\n");
1213
+ return ret;
1214
+ }
10291215
10301216 return 0;
10311217 }
10321218
1033
-static unsigned long monitor_freq_to_state(struct monitor_dev_info *info,
1034
- unsigned long freq)
1219
+static void rockchip_monitor_disable_opp_clk(struct device *dev,
1220
+ struct rockchip_opp_info *opp_info)
10351221 {
1036
- unsigned long i = 0;
1222
+ if (!opp_info)
1223
+ return;
10371224
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;
1225
+ clk_bulk_disable_unprepare(opp_info->num_clks, opp_info->clks);
10491226 }
10501227
1051
-static int monitor_temp_to_state(struct monitor_dev_info *info,
1052
- int temp, unsigned long *state)
1228
+static int rockchip_monitor_set_opp(struct monitor_dev_info *info,
1229
+ unsigned long old_freq,
1230
+ unsigned long freq,
1231
+ struct dev_pm_opp_supply *old_supply,
1232
+ struct dev_pm_opp_supply *new_supply)
10531233 {
1054
- unsigned long target_state, target_freq = 0;
1055
- int i;
1234
+ struct dev_pm_set_opp_data *data;
1235
+ int size;
10561236
1057
- if (temp == THERMAL_TEMP_INVALID)
1237
+ data = info->set_opp_data;
1238
+ data->regulators = info->regulators;
1239
+ data->regulator_count = info->regulator_count;
1240
+ data->clk = info->clk;
1241
+ data->dev = info->dev;
1242
+
1243
+ data->old_opp.rate = old_freq;
1244
+ size = sizeof(*old_supply) * info->regulator_count;
1245
+ if (!old_supply)
1246
+ memset(data->old_opp.supplies, 0, size);
1247
+ else
1248
+ memcpy(data->old_opp.supplies, old_supply, size);
1249
+
1250
+ data->new_opp.rate = freq;
1251
+ memcpy(data->new_opp.supplies, new_supply, size);
1252
+
1253
+ return info->devp->set_opp(data);
1254
+}
1255
+
1256
+int rockchip_monitor_check_rate_volt(struct monitor_dev_info *info)
1257
+{
1258
+ struct device *dev = info->dev;
1259
+ struct regulator *vdd_reg = NULL;
1260
+ struct regulator *mem_reg = NULL;
1261
+ struct rockchip_opp_info *opp_info = info->devp->opp_info;
1262
+ struct dev_pm_opp *opp;
1263
+ unsigned long old_rate, new_rate, new_volt, new_mem_volt;
1264
+ int old_volt, old_mem_volt;
1265
+ u32 target_rm = UINT_MAX;
1266
+ bool is_set_clk = true;
1267
+ bool is_set_rm = false;
1268
+ int ret = 0;
1269
+
1270
+ if (!info->regulators || !info->clk)
10581271 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;
1272
+
1273
+ mutex_lock(&info->volt_adjust_mutex);
1274
+
1275
+ vdd_reg = info->regulators[0];
1276
+ old_rate = clk_get_rate(info->clk);
1277
+ old_volt = regulator_get_voltage(vdd_reg);
1278
+ if (info->regulator_count > 1) {
1279
+ mem_reg = info->regulators[1];
1280
+ old_mem_volt = regulator_get_voltage(mem_reg);
1281
+ }
1282
+
1283
+ if (info->init_freq) {
1284
+ new_rate = info->init_freq * 1000;
1285
+ info->init_freq = 0;
1286
+ } else {
1287
+ new_rate = old_rate;
1288
+ }
1289
+ opp = dev_pm_opp_find_freq_ceil(dev, &new_rate);
1290
+ if (IS_ERR(opp)) {
1291
+ opp = dev_pm_opp_find_freq_floor(dev, &new_rate);
1292
+ if (IS_ERR(opp)) {
1293
+ ret = PTR_ERR(opp);
1294
+ goto unlock;
10631295 }
1064
- if (target_freq)
1065
- *state = monitor_freq_to_state(info,
1066
- target_freq * 1000);
1067
- else
1068
- *state = 0;
1296
+ }
1297
+ new_volt = opp->supplies[0].u_volt;
1298
+ if (info->regulator_count > 1)
1299
+ new_mem_volt = opp->supplies[1].u_volt;
1300
+ dev_pm_opp_put(opp);
1301
+
1302
+ if (old_rate == new_rate) {
1303
+ if (info->regulator_count > 1) {
1304
+ if (old_volt == new_volt &&
1305
+ new_mem_volt == old_mem_volt)
1306
+ goto unlock;
1307
+ } else if (old_volt == new_volt) {
1308
+ goto unlock;
1309
+ }
1310
+ }
1311
+ if (!new_volt || (info->regulator_count > 1 && !new_mem_volt))
1312
+ goto unlock;
1313
+
1314
+ if (info->devp->set_opp) {
1315
+ ret = rockchip_monitor_set_opp(info, old_rate, new_rate,
1316
+ NULL, opp->supplies);
1317
+ goto unlock;
10691318 }
10701319
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;
1320
+ if (opp_info && opp_info->data && opp_info->data->set_read_margin) {
1321
+ is_set_rm = true;
1322
+ if (info->devp->type == MONITOR_TYPE_DEV) {
1323
+ if (!pm_runtime_active(dev)) {
1324
+ is_set_rm = false;
1325
+ if (opp_info->scmi_clk)
1326
+ is_set_clk = false;
1327
+ }
1328
+ }
10761329 }
1330
+ rockchip_monitor_enable_opp_clk(dev, opp_info);
1331
+ rockchip_get_read_margin(dev, opp_info, new_volt, &target_rm);
10771332
1078
- return 0;
1333
+ dev_dbg(dev, "%s: %lu Hz --> %lu Hz\n", __func__, old_rate, new_rate);
1334
+ if (new_rate >= old_rate) {
1335
+ rockchip_set_intermediate_rate(dev, opp_info, info->clk,
1336
+ old_rate, new_rate,
1337
+ true, is_set_clk);
1338
+
1339
+ if (old_volt > new_volt) {
1340
+ ret = regulator_set_voltage(vdd_reg, new_volt, INT_MAX);
1341
+ if (ret) {
1342
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1343
+ __func__, new_volt);
1344
+ goto restore_voltage;
1345
+ }
1346
+ }
1347
+ if (info->regulator_count > 1) {
1348
+ ret = regulator_set_voltage(mem_reg, new_mem_volt,
1349
+ INT_MAX);
1350
+ if (ret) {
1351
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1352
+ __func__, new_mem_volt);
1353
+ goto restore_voltage;
1354
+ }
1355
+ }
1356
+ if (old_volt <= new_volt) {
1357
+ ret = regulator_set_voltage(vdd_reg, new_volt, INT_MAX);
1358
+ if (ret) {
1359
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1360
+ __func__, new_volt);
1361
+ goto restore_voltage;
1362
+ }
1363
+ }
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
+ } else {
1371
+ rockchip_set_intermediate_rate(dev, opp_info, info->clk,
1372
+ old_rate, new_rate,
1373
+ false, is_set_clk);
1374
+ rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm);
1375
+ if (is_set_clk && clk_set_rate(info->clk, new_rate)) {
1376
+ dev_err(dev, "%s: failed to set clock rate: %lu\n",
1377
+ __func__, new_rate);
1378
+ goto restore_rm;
1379
+ }
1380
+ ret = regulator_set_voltage(vdd_reg, new_volt,
1381
+ INT_MAX);
1382
+ if (ret) {
1383
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1384
+ __func__, new_volt);
1385
+ goto restore_freq;
1386
+ }
1387
+ if (info->regulator_count > 1) {
1388
+ ret = regulator_set_voltage(mem_reg, new_mem_volt,
1389
+ INT_MAX);
1390
+ if (ret) {
1391
+ dev_err(dev, "%s: failed to set volt: %lu\n",
1392
+ __func__, new_mem_volt);
1393
+ goto restore_freq;
1394
+ }
1395
+ }
1396
+ }
1397
+ goto disable_clk;
1398
+
1399
+restore_freq:
1400
+ if (is_set_clk && clk_set_rate(info->clk, old_rate))
1401
+ dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
1402
+ __func__, old_rate);
1403
+restore_rm:
1404
+ rockchip_get_read_margin(dev, opp_info, old_volt, &target_rm);
1405
+ rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm);
1406
+restore_voltage:
1407
+ if (old_volt <= new_volt)
1408
+ regulator_set_voltage(vdd_reg, old_volt, INT_MAX);
1409
+ if (info->regulator_count > 1)
1410
+ regulator_set_voltage(mem_reg, old_mem_volt, INT_MAX);
1411
+ if (old_volt > new_volt)
1412
+ regulator_set_voltage(vdd_reg, old_volt, INT_MAX);
1413
+disable_clk:
1414
+ rockchip_monitor_disable_opp_clk(dev, opp_info);
1415
+unlock:
1416
+ mutex_unlock(&info->volt_adjust_mutex);
1417
+
1418
+ return ret;
10791419 }
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);
1420
+EXPORT_SYMBOL(rockchip_monitor_check_rate_volt);
10991421
11001422 struct monitor_dev_info *
11011423 rockchip_system_monitor_register(struct device *dev,
11021424 struct monitor_dev_profile *devp)
11031425 {
11041426 struct monitor_dev_info *info;
1105
- struct devfreq *devfreq;
1106
- int ret;
11071427
11081428 if (!system_monitor)
11091429 return ERR_PTR(-ENOMEM);
1430
+
1431
+ if (!devp)
1432
+ return ERR_PTR(-EINVAL);
11101433
11111434 info = kzalloc(sizeof(*info), GFP_KERNEL);
11121435 if (!info)
....@@ -1114,39 +1437,33 @@
11141437 info->dev = dev;
11151438 info->devp = devp;
11161439
1117
- ret = monitor_device_parse_dt(dev, info);
1118
- if (ret)
1119
- goto free_info;
1440
+ mutex_init(&info->volt_adjust_mutex);
11201441
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);
1442
+ rockchip_system_monitor_parse_supplies(dev, info);
1443
+ if (monitor_device_parse_dt(dev, info)) {
1444
+ rockchip_monitor_check_rate_volt(info);
1445
+ devp->is_checked = true;
1446
+ kfree(info->set_opp_data);
1447
+ kfree(info);
1448
+ return ERR_PTR(-EINVAL);
11291449 }
11301450
1451
+ rockchip_system_monitor_early_regulator_init(info);
11311452 rockchip_system_monitor_wide_temp_init(info);
1132
- mutex_init(&info->volt_adjust_mutex);
1453
+ rockchip_monitor_check_rate_volt(info);
1454
+ devp->is_checked = true;
1455
+ rockchip_system_monitor_freq_qos_requset(info);
11331456
11341457 down_write(&mdev_list_sem);
11351458 list_add(&info->node, &monitor_dev_list);
11361459 up_write(&mdev_list_sem);
11371460
11381461 return info;
1139
-
1140
-free_info:
1141
- kfree(info);
1142
- return ERR_PTR(-EINVAL);
11431462 }
11441463 EXPORT_SYMBOL(rockchip_system_monitor_register);
11451464
11461465 void rockchip_system_monitor_unregister(struct monitor_dev_info *info)
11471466 {
1148
- struct devfreq *devfreq;
1149
-
11501467 if (!info)
11511468 return;
11521469
....@@ -1154,18 +1471,59 @@
11541471 list_del(&info->node);
11551472 up_write(&mdev_list_sem);
11561473
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);
1474
+ if (info->devp->type == MONITOR_TYPE_CPU) {
1475
+ if (freq_qos_request_active(&info->max_temp_freq_req))
1476
+ freq_qos_remove_request(&info->max_temp_freq_req);
1477
+ if (freq_qos_request_active(&info->min_sta_freq_req))
1478
+ freq_qos_remove_request(&info->min_sta_freq_req);
1479
+ if (freq_qos_request_active(&info->max_sta_freq_req))
1480
+ freq_qos_remove_request(&info->max_sta_freq_req);
1481
+ } else {
1482
+ if (dev_pm_qos_request_active(&info->dev_max_freq_req))
1483
+ dev_pm_qos_remove_request(&info->dev_max_freq_req);
1484
+ }
11621485
11631486 kfree(info->low_temp_adjust_table);
11641487 kfree(info->opp_table);
1165
- kfree(info->freq_table);
1488
+ kfree(info->set_opp_data);
11661489 kfree(info);
11671490 }
11681491 EXPORT_SYMBOL(rockchip_system_monitor_unregister);
1492
+
1493
+int rockchip_system_monitor_register_notifier(struct notifier_block *nb)
1494
+{
1495
+ return blocking_notifier_chain_register(&system_monitor_notifier_list, nb);
1496
+}
1497
+EXPORT_SYMBOL(rockchip_system_monitor_register_notifier);
1498
+
1499
+void rockchip_system_monitor_unregister_notifier(struct notifier_block *nb)
1500
+{
1501
+ blocking_notifier_chain_unregister(&system_monitor_notifier_list, nb);
1502
+}
1503
+EXPORT_SYMBOL(rockchip_system_monitor_unregister_notifier);
1504
+
1505
+static int rockchip_system_monitor_temp_notify(int temp)
1506
+{
1507
+ struct system_monitor_event_data event_data;
1508
+ int ret;
1509
+
1510
+ event_data.temp = temp;
1511
+ ret = blocking_notifier_call_chain(&system_monitor_notifier_list,
1512
+ SYSTEM_MONITOR_CHANGE_TEMP,
1513
+ (void *)&event_data);
1514
+
1515
+ return notifier_to_errno(ret);
1516
+}
1517
+
1518
+static int notify_dummy(struct thermal_zone_device *tz, int trip)
1519
+{
1520
+ return 0;
1521
+}
1522
+
1523
+static struct thermal_governor thermal_gov_dummy = {
1524
+ .name = "dummy",
1525
+ .throttle = notify_dummy,
1526
+};
11691527
11701528 static int rockchip_system_monitor_parse_dt(struct system_monitor *monitor)
11711529 {
....@@ -1173,7 +1531,7 @@
11731531 const char *tz_name, *buf = NULL;
11741532
11751533 if (of_property_read_string(np, "rockchip,video-4k-offline-cpus", &buf))
1176
- cpumask_clear(&system_monitor->video_4k_offline_cpus);
1534
+ cpumask_clear(&monitor->video_4k_offline_cpus);
11771535 else
11781536 cpulist_parse(buf, &monitor->video_4k_offline_cpus);
11791537
....@@ -1199,6 +1557,13 @@
11991557 system_monitor->offline_cpus_temp = INT_MAX;
12001558 of_property_read_u32(np, "rockchip,temp-hysteresis",
12011559 &system_monitor->temp_hysteresis);
1560
+
1561
+ if (of_find_property(np, "rockchip,thermal-governor-dummy", NULL)) {
1562
+ if (monitor->tz->governor->unbind_from_tz)
1563
+ monitor->tz->governor->unbind_from_tz(monitor->tz);
1564
+ monitor->tz->governor = &thermal_gov_dummy;
1565
+ }
1566
+
12021567 out:
12031568 return 0;
12041569 }
....@@ -1224,7 +1589,7 @@
12241589 cpumask_copy(&system_monitor->offline_cpus, &offline_cpus);
12251590 for_each_cpu(cpu, &system_monitor->offline_cpus) {
12261591 if (cpu_online(cpu))
1227
- cpu_down(cpu);
1592
+ remove_cpu(cpu);
12281593 }
12291594
12301595 cpumask_clear(&online_cpus);
....@@ -1234,7 +1599,7 @@
12341599 if (cpumask_empty(&online_cpus))
12351600 goto out;
12361601 for_each_cpu(cpu, &online_cpus)
1237
- cpu_up(cpu);
1602
+ add_cpu(cpu);
12381603
12391604 out:
12401605 mutex_unlock(&cpu_on_off_mutex);
....@@ -1266,7 +1631,6 @@
12661631 {
12671632 int temp, ret;
12681633 struct monitor_dev_info *info;
1269
- static int last_temp = INT_MAX;
12701634
12711635 ret = thermal_zone_get_temp(system_monitor->tz, &temp);
12721636 if (ret || temp == THERMAL_TEMP_INVALID)
....@@ -1274,9 +1638,12 @@
12741638
12751639 dev_dbg(system_monitor->dev, "temperature=%d\n", temp);
12761640
1277
- if (temp < last_temp && last_temp - temp <= 2000)
1641
+ if (temp < system_monitor->last_temp &&
1642
+ system_monitor->last_temp - temp <= 2000)
12781643 goto out;
1279
- last_temp = temp;
1644
+ system_monitor->last_temp = temp;
1645
+
1646
+ rockchip_system_monitor_temp_notify(temp);
12801647
12811648 down_read(&mdev_list_sem);
12821649 list_for_each_entry(info, &monitor_dev_list, node)
....@@ -1302,26 +1669,32 @@
13021669 unsigned long status)
13031670 {
13041671 unsigned int target_freq = 0;
1305
- bool is_freq_fixed = false;
1306
- int cpu;
1672
+
1673
+ if (!freq_qos_request_active(&info->min_sta_freq_req))
1674
+ return;
1675
+ if (!freq_qos_request_active(&info->max_sta_freq_req))
1676
+ return;
13071677
13081678 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;
1679
+ freq_qos_update_request(&info->max_sta_freq_req,
1680
+ info->reboot_freq);
1681
+ freq_qos_update_request(&info->min_sta_freq_req,
1682
+ info->reboot_freq);
1683
+ return;
13131684 }
13141685
13151686 if (info->video_4k_freq && (status & SYS_STATUS_VIDEO_4K))
13161687 target_freq = info->video_4k_freq;
1317
- if (target_freq == info->status_max_limit &&
1318
- info->is_status_freq_fixed == is_freq_fixed)
1688
+
1689
+ if (target_freq == info->status_max_limit)
13191690 return;
13201691 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);
1692
+ if (info->status_max_limit)
1693
+ freq_qos_update_request(&info->max_sta_freq_req,
1694
+ info->status_max_limit);
1695
+ else
1696
+ freq_qos_update_request(&info->max_sta_freq_req,
1697
+ FREQ_QOS_MAX_DEFAULT_VALUE);
13251698 }
13261699
13271700 static void rockchip_system_status_limit_freq(unsigned long status)
....@@ -1330,7 +1703,7 @@
13301703
13311704 down_read(&mdev_list_sem);
13321705 list_for_each_entry(info, &monitor_dev_list, node) {
1333
- if (info->devp->type == MONITOR_TPYE_CPU)
1706
+ if (info->devp->type == MONITOR_TYPE_CPU)
13341707 rockchip_system_status_cpu_limit_freq(info, status);
13351708 }
13361709 up_read(&mdev_list_sem);
....@@ -1364,6 +1737,26 @@
13641737 return NOTIFY_OK;
13651738 }
13661739
1740
+static int rockchip_system_monitor_set_cpu_uevent_suppress(bool is_suppress)
1741
+{
1742
+ struct monitor_dev_info *info;
1743
+ struct cpufreq_policy *policy;
1744
+
1745
+ list_for_each_entry(info, &monitor_dev_list, node) {
1746
+ if (info->devp->type != MONITOR_TYPE_CPU)
1747
+ continue;
1748
+ policy = (struct cpufreq_policy *)info->devp->data;
1749
+ if (!policy || !policy->cdev)
1750
+ continue;
1751
+ if (is_suppress)
1752
+ dev_set_uevent_suppress(&policy->cdev->device, 1);
1753
+ else
1754
+ dev_set_uevent_suppress(&policy->cdev->device, 0);
1755
+ }
1756
+
1757
+ return 0;
1758
+}
1759
+
13671760 static int monitor_pm_notify(struct notifier_block *nb,
13681761 unsigned long mode, void *_unused)
13691762 {
....@@ -1372,6 +1765,7 @@
13721765 case PM_RESTORE_PREPARE:
13731766 case PM_SUSPEND_PREPARE:
13741767 atomic_set(&monitor_in_suspend, 1);
1768
+ rockchip_system_monitor_set_cpu_uevent_suppress(true);
13751769 break;
13761770 case PM_POST_HIBERNATION:
13771771 case PM_POST_RESTORE:
....@@ -1379,6 +1773,8 @@
13791773 if (system_monitor->tz)
13801774 rockchip_system_monitor_thermal_update();
13811775 atomic_set(&monitor_in_suspend, 0);
1776
+ rockchip_system_monitor_set_cpu_uevent_suppress(false);
1777
+ system_monitor->last_temp = INT_MAX;
13821778 break;
13831779 default:
13841780 break;
....@@ -1388,51 +1784,6 @@
13881784
13891785 static struct notifier_block monitor_pm_nb = {
13901786 .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,
14361787 };
14371788
14381789 static int rockchip_monitor_reboot_notifier(struct notifier_block *nb,
....@@ -1454,24 +1805,15 @@
14541805 {
14551806 struct fb_event *event = ptr;
14561807
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
- }
1808
+ if (action != FB_EVENT_BLANK)
1809
+ return NOTIFY_OK;
1810
+
1811
+ switch (*((int *)event->data)) {
1812
+ case FB_BLANK_UNBLANK:
1813
+ rockchip_clear_system_status(SYS_STATUS_SUSPEND);
14661814 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
- }
1815
+ case FB_BLANK_POWERDOWN:
1816
+ rockchip_set_system_status(SYS_STATUS_SUSPEND);
14751817 break;
14761818 default:
14771819 break;
....@@ -1494,12 +1836,6 @@
14941836 case EBC_OFF:
14951837 rockchip_set_system_status(SYS_STATUS_LOW_POWER);
14961838 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;
15031839 default:
15041840 break;
15051841 }
....@@ -1510,6 +1846,32 @@
15101846 static struct notifier_block rockchip_monitor_ebc_nb = {
15111847 .notifier_call = rockchip_eink_devfs_notifier,
15121848 };
1849
+
1850
+static void system_monitor_early_min_volt_function(struct work_struct *work)
1851
+{
1852
+ struct monitor_dev_info *info;
1853
+ struct regulator_dev *rdev;
1854
+ int min_uV, max_uV;
1855
+ int ret;
1856
+
1857
+ down_read(&mdev_list_sem);
1858
+ list_for_each_entry(info, &monitor_dev_list, node) {
1859
+ if (!info->early_min_volt || !info->early_reg)
1860
+ continue;
1861
+ rdev = info->early_reg->rdev;
1862
+ min_uV = rdev->constraints->min_uV;
1863
+ max_uV = rdev->constraints->max_uV;
1864
+ ret = regulator_set_voltage(info->early_reg, min_uV, max_uV);
1865
+ if (ret)
1866
+ dev_err(&rdev->dev,
1867
+ "%s: failed to set volt\n", __func__);
1868
+ regulator_put(info->early_reg);
1869
+ }
1870
+ up_read(&mdev_list_sem);
1871
+}
1872
+
1873
+static DECLARE_DELAYED_WORK(system_monitor_early_min_volt_work,
1874
+ system_monitor_early_min_volt_function);
15131875
15141876 static int rockchip_system_monitor_probe(struct platform_device *pdev)
15151877 {
....@@ -1532,6 +1894,7 @@
15321894
15331895 rockchip_system_monitor_parse_dt(system_monitor);
15341896 if (system_monitor->tz) {
1897
+ system_monitor->last_temp = INT_MAX;
15351898 INIT_DELAYED_WORK(&system_monitor->thermal_work,
15361899 rockchip_system_monitor_thermal_check);
15371900 mod_delayed_work(system_freezable_wq,
....@@ -1546,9 +1909,6 @@
15461909 if (register_pm_notifier(&monitor_pm_nb))
15471910 dev_err(dev, "failed to register suspend notifier\n");
15481911
1549
- cpufreq_register_notifier(&rockchip_monitor_cpufreq_policy_nb,
1550
- CPUFREQ_POLICY_NOTIFIER);
1551
-
15521912 register_reboot_notifier(&rockchip_monitor_reboot_nb);
15531913
15541914 if (fb_register_client(&rockchip_monitor_fb_nb))
....@@ -1556,6 +1916,9 @@
15561916
15571917 ebc_register_notifier(&rockchip_monitor_ebc_nb);
15581918
1919
+ schedule_delayed_work(&system_monitor_early_min_volt_work,
1920
+ msecs_to_jiffies(30000));
1921
+
15591922 dev_info(dev, "system monitor probe\n");
15601923
15611924 return 0;