.. | .. |
---|
5 | 5 | */ |
---|
6 | 6 | |
---|
7 | 7 | #include <dt-bindings/soc/rockchip-system-status.h> |
---|
| 8 | +#include <linux/clk-provider.h> |
---|
8 | 9 | #include <linux/cpu.h> |
---|
9 | 10 | #include <linux/cpufreq.h> |
---|
| 11 | +#include <linux/devfreq.h> |
---|
10 | 12 | #include <linux/device.h> |
---|
11 | 13 | #include <linux/fb.h> |
---|
12 | 14 | #include <linux/module.h> |
---|
.. | .. |
---|
15 | 17 | #include <linux/of.h> |
---|
16 | 18 | #include <linux/platform_device.h> |
---|
17 | 19 | #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> |
---|
19 | 26 | #include <linux/reboot.h> |
---|
20 | 27 | #include <linux/slab.h> |
---|
21 | 28 | #include <linux/suspend.h> |
---|
22 | 29 | #include <linux/thermal.h> |
---|
| 30 | +#include <linux/uaccess.h> |
---|
23 | 31 | #include <linux/version.h> |
---|
| 32 | +#include <linux/delay.h> |
---|
| 33 | +#include <soc/rockchip/rockchip_opp_select.h> |
---|
24 | 34 | #include <soc/rockchip/rockchip_system_monitor.h> |
---|
25 | 35 | #include <soc/rockchip/rockchip-system-status.h> |
---|
26 | 36 | |
---|
27 | | -#include "../../opp/opp.h" |
---|
28 | | -#include "../../devfreq/governor.h" |
---|
29 | | - |
---|
30 | 37 | #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" |
---|
31 | 41 | |
---|
32 | 42 | #define CPU_REBOOT_FREQ 816000 /* kHz */ |
---|
33 | 43 | #define VIDEO_1080P_SIZE (1920 * 1080) |
---|
34 | 44 | #define THERMAL_POLLING_DELAY 200 /* milliseconds */ |
---|
35 | | - |
---|
36 | | -#define devfreq_nb_to_monitor(nb) container_of(nb, struct monitor_dev_info, \ |
---|
37 | | - devfreq_nb) |
---|
38 | 45 | |
---|
39 | 46 | struct video_info { |
---|
40 | 47 | unsigned int width; |
---|
.. | .. |
---|
64 | 71 | |
---|
65 | 72 | struct thermal_zone_device *tz; |
---|
66 | 73 | struct delayed_work thermal_work; |
---|
| 74 | + int last_temp; |
---|
67 | 75 | int offline_cpus_temp; |
---|
68 | 76 | int temp_hysteresis; |
---|
69 | 77 | unsigned int delay; |
---|
.. | .. |
---|
84 | 92 | static struct system_monitor *system_monitor; |
---|
85 | 93 | static atomic_t monitor_in_suspend; |
---|
86 | 94 | |
---|
| 95 | +static BLOCKING_NOTIFIER_HEAD(system_monitor_notifier_list); |
---|
87 | 96 | static BLOCKING_NOTIFIER_HEAD(system_status_notifier_list); |
---|
88 | 97 | |
---|
89 | 98 | int rockchip_register_system_status_notifier(struct notifier_block *nb) |
---|
.. | .. |
---|
173 | 182 | return -EINVAL; |
---|
174 | 183 | } |
---|
175 | 184 | |
---|
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); |
---|
179 | 188 | } |
---|
180 | 189 | EXPORT_SYMBOL(rockchip_add_system_status_interface); |
---|
181 | 190 | |
---|
.. | .. |
---|
288 | 297 | { |
---|
289 | 298 | struct video_info *video_info; |
---|
290 | 299 | unsigned int max_res = 0, max_stream_bitrate = 0, res = 0; |
---|
| 300 | + unsigned int max_video_framerate = 0; |
---|
291 | 301 | |
---|
292 | 302 | mutex_lock(&video_info_mutex); |
---|
293 | 303 | if (list_empty(&video_info_list)) { |
---|
.. | .. |
---|
302 | 312 | max_res = res; |
---|
303 | 313 | if (video_info->streamBitrate > max_stream_bitrate) |
---|
304 | 314 | max_stream_bitrate = video_info->streamBitrate; |
---|
| 315 | + if (video_info->videoFramerate > max_video_framerate) |
---|
| 316 | + max_video_framerate = video_info->videoFramerate; |
---|
305 | 317 | } |
---|
306 | 318 | mutex_unlock(&video_info_mutex); |
---|
307 | 319 | |
---|
.. | .. |
---|
310 | 322 | } else { |
---|
311 | 323 | if (max_stream_bitrate == 10) |
---|
312 | 324 | 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); |
---|
315 | 328 | } |
---|
316 | 329 | } |
---|
317 | 330 | |
---|
.. | .. |
---|
354 | 367 | case 'n': |
---|
355 | 368 | /* clear performance flag */ |
---|
356 | 369 | 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); |
---|
357 | 378 | break; |
---|
358 | 379 | default: |
---|
359 | 380 | break; |
---|
.. | .. |
---|
492 | 513 | int delta_volt = 0; |
---|
493 | 514 | int i = 0, max_count; |
---|
494 | 515 | unsigned long low_limit = 0, high_limit = 0; |
---|
| 516 | + unsigned long low_limit_mem = 0, high_limit_mem = 0; |
---|
495 | 517 | bool reach_max_volt = false; |
---|
| 518 | + bool reach_max_mem_volt = false; |
---|
496 | 519 | bool reach_high_temp_max_volt = false; |
---|
| 520 | + bool reach_high_temp_max_mem_volt = false; |
---|
497 | 521 | |
---|
498 | 522 | max_count = dev_pm_opp_get_opp_count(dev); |
---|
499 | 523 | if (max_count <= 0) |
---|
.. | .. |
---|
511 | 535 | } |
---|
512 | 536 | mutex_lock(&opp_table->lock); |
---|
513 | 537 | list_for_each_entry(opp, &opp_table->opp_list, node) { |
---|
| 538 | + if (!opp->available) |
---|
| 539 | + continue; |
---|
514 | 540 | info->opp_table[i].rate = opp->rate; |
---|
515 | 541 | info->opp_table[i].volt = opp->supplies[0].u_volt; |
---|
516 | 542 | info->opp_table[i].max_volt = opp->supplies[0].u_volt_max; |
---|
.. | .. |
---|
542 | 568 | info->low_limit = low_limit; |
---|
543 | 569 | if (high_limit && high_limit != opp->rate) |
---|
544 | 570 | 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", |
---|
546 | 609 | 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); |
---|
548 | 613 | i++; |
---|
549 | 614 | } |
---|
550 | 615 | mutex_unlock(&opp_table->lock); |
---|
.. | .. |
---|
586 | 651 | else |
---|
587 | 652 | info->high_temp_max_volt = value; |
---|
588 | 653 | 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) { |
---|
592 | 660 | if (!of_property_read_u32(np, "rockchip,high-temp-max-freq", |
---|
593 | 661 | &value)) { |
---|
594 | 662 | high_temp_max_freq = value * 1000; |
---|
.. | .. |
---|
640 | 708 | &info->video_4k_freq); |
---|
641 | 709 | ret &= of_property_read_u32(np, "rockchip,reboot-freq", |
---|
642 | 710 | &info->reboot_freq); |
---|
643 | | - if (info->devp->type == MONITOR_TPYE_CPU) { |
---|
| 711 | + if (info->devp->type == MONITOR_TYPE_CPU) { |
---|
644 | 712 | if (!info->reboot_freq) { |
---|
645 | 713 | info->reboot_freq = CPU_REBOOT_FREQ; |
---|
646 | 714 | ret = 0; |
---|
.. | .. |
---|
650 | 718 | return ret; |
---|
651 | 719 | } |
---|
652 | 720 | |
---|
| 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 | + |
---|
653 | 747 | static int monitor_device_parse_dt(struct device *dev, |
---|
654 | 748 | struct monitor_dev_info *info) |
---|
655 | 749 | { |
---|
656 | 750 | 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; |
---|
661 | 752 | |
---|
662 | 753 | np = of_parse_phandle(dev->of_node, "operating-points-v2", 0); |
---|
663 | 754 | if (!np) |
---|
664 | 755 | return -EINVAL; |
---|
665 | 756 | |
---|
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); |
---|
677 | 764 | |
---|
678 | 765 | of_node_put(np); |
---|
679 | 766 | |
---|
680 | 767 | return ret; |
---|
681 | 768 | } |
---|
682 | 769 | |
---|
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 | | - |
---|
696 | 770 | int rockchip_monitor_cpu_low_temp_adjust(struct monitor_dev_info *info, |
---|
697 | 771 | bool is_low) |
---|
698 | 772 | { |
---|
699 | | - struct device *dev = info->dev; |
---|
700 | | - unsigned int cpu = cpumask_any(&info->devp->allowed_cpus); |
---|
| 773 | + if (!info->low_limit) |
---|
| 774 | + return 0; |
---|
701 | 775 | |
---|
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; |
---|
709 | 778 | |
---|
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); |
---|
713 | 785 | |
---|
714 | 786 | return 0; |
---|
715 | 787 | } |
---|
.. | .. |
---|
718 | 790 | int rockchip_monitor_cpu_high_temp_adjust(struct monitor_dev_info *info, |
---|
719 | 791 | bool is_high) |
---|
720 | 792 | { |
---|
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; |
---|
722 | 798 | |
---|
723 | 799 | 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; |
---|
734 | 803 | } |
---|
| 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); |
---|
735 | 811 | |
---|
736 | 812 | return 0; |
---|
737 | 813 | } |
---|
738 | 814 | EXPORT_SYMBOL(rockchip_monitor_cpu_high_temp_adjust); |
---|
739 | 815 | |
---|
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 | | - |
---|
752 | 816 | int rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info *info, |
---|
753 | 817 | bool is_low) |
---|
754 | 818 | { |
---|
755 | | - struct devfreq *df; |
---|
| 819 | + if (!dev_pm_qos_request_active(&info->dev_max_freq_req)) |
---|
| 820 | + return 0; |
---|
756 | 821 | |
---|
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; |
---|
763 | 824 | |
---|
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); |
---|
768 | 831 | |
---|
769 | 832 | return 0; |
---|
770 | 833 | } |
---|
.. | .. |
---|
773 | 836 | int rockchip_monitor_dev_high_temp_adjust(struct monitor_dev_info *info, |
---|
774 | 837 | bool is_high) |
---|
775 | 838 | { |
---|
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; |
---|
777 | 844 | |
---|
778 | 845 | 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; |
---|
795 | 849 | } |
---|
| 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); |
---|
796 | 857 | |
---|
797 | 858 | return 0; |
---|
798 | 859 | } |
---|
.. | .. |
---|
812 | 873 | |
---|
813 | 874 | mutex_lock(&opp_table->lock); |
---|
814 | 875 | list_for_each_entry(opp, &opp_table->opp_list, node) { |
---|
| 876 | + if (!opp->available) |
---|
| 877 | + continue; |
---|
815 | 878 | if (is_low_temp) { |
---|
816 | 879 | if (opp->supplies[0].u_volt_max < |
---|
817 | 880 | info->opp_table[i].low_temp_volt) |
---|
.. | .. |
---|
820 | 883 | opp->supplies[0].u_volt = |
---|
821 | 884 | info->opp_table[i].low_temp_volt; |
---|
822 | 885 | 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 | + } |
---|
823 | 896 | } else { |
---|
824 | 897 | opp->supplies[0].u_volt_min = info->opp_table[i].volt; |
---|
825 | 898 | opp->supplies[0].u_volt = opp->supplies[0].u_volt_min; |
---|
826 | 899 | opp->supplies[0].u_volt_max = |
---|
827 | 900 | 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 | + } |
---|
828 | 909 | } |
---|
829 | 910 | i++; |
---|
830 | 911 | } |
---|
.. | .. |
---|
850 | 931 | ret = devp->low_temp_adjust(info, is_low); |
---|
851 | 932 | if (!ret) |
---|
852 | 933 | info->is_low_temp = is_low; |
---|
| 934 | + |
---|
| 935 | + if (devp->update_volt) |
---|
| 936 | + devp->update_volt(info); |
---|
853 | 937 | } |
---|
854 | 938 | |
---|
855 | 939 | static void rockchip_high_temp_adjust(struct monitor_dev_info *info, |
---|
.. | .. |
---|
858 | 942 | struct monitor_dev_profile *devp = info->devp; |
---|
859 | 943 | int ret = 0; |
---|
860 | 944 | |
---|
| 945 | + if (!devp->high_temp_adjust) |
---|
| 946 | + return; |
---|
| 947 | + |
---|
861 | 948 | if (info->high_limit_table) { |
---|
862 | 949 | devp->high_temp_adjust(info, is_high); |
---|
863 | 950 | } else { |
---|
864 | 951 | 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); |
---|
867 | 953 | if (!ret) |
---|
868 | 954 | info->is_high_temp = is_high; |
---|
869 | 955 | } |
---|
.. | .. |
---|
874 | 960 | struct monitor_dev_info *info = NULL, *tmp; |
---|
875 | 961 | |
---|
876 | 962 | 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) |
---|
878 | 964 | continue; |
---|
879 | 965 | if (cpumask_test_cpu(cpu, &tmp->devp->allowed_cpus)) { |
---|
880 | 966 | info = tmp; |
---|
.. | .. |
---|
941 | 1027 | { |
---|
942 | 1028 | int ret, temp; |
---|
943 | 1029 | |
---|
| 1030 | + if (!info->opp_table) |
---|
| 1031 | + return; |
---|
| 1032 | + if (!system_monitor->tz) |
---|
| 1033 | + return; |
---|
| 1034 | + |
---|
944 | 1035 | /* |
---|
945 | 1036 | * set the init state to low temperature that the voltage will be enough |
---|
946 | 1037 | * when cpu up at low temperature. |
---|
.. | .. |
---|
948 | 1039 | if (!info->is_low_temp) { |
---|
949 | 1040 | if (info->opp_table) |
---|
950 | 1041 | rockchip_adjust_low_temp_opp_volt(info, true); |
---|
951 | | - info->wide_temp_limit = info->low_limit; |
---|
952 | 1042 | info->is_low_temp = true; |
---|
953 | 1043 | } |
---|
954 | 1044 | |
---|
.. | .. |
---|
963 | 1053 | if (info->opp_table) |
---|
964 | 1054 | rockchip_adjust_low_temp_opp_volt(info, false); |
---|
965 | 1055 | info->is_low_temp = false; |
---|
966 | | - |
---|
967 | | - info->wide_temp_limit = info->high_limit; |
---|
968 | 1056 | info->is_high_temp = true; |
---|
969 | 1057 | } else if (temp > (info->low_temp + info->temp_hysteresis)) { |
---|
970 | 1058 | if (info->opp_table) |
---|
971 | 1059 | rockchip_adjust_low_temp_opp_volt(info, false); |
---|
972 | 1060 | info->is_low_temp = false; |
---|
973 | | - info->wide_temp_limit = 0; |
---|
974 | 1061 | } |
---|
975 | 1062 | } |
---|
976 | 1063 | |
---|
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) |
---|
980 | 1065 | { |
---|
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 ""; |
---|
991 | 1072 | } |
---|
992 | 1073 | |
---|
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) |
---|
995 | 1076 | { |
---|
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; |
---|
1000 | 1079 | |
---|
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; |
---|
1004 | 1082 | |
---|
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; |
---|
1015 | 1089 | } |
---|
| 1090 | +} |
---|
1016 | 1091 | |
---|
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; |
---|
1022 | 1149 | } |
---|
1023 | 1150 | } |
---|
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 | + } |
---|
1025 | 1185 | |
---|
1026 | 1186 | dev_pm_opp_put_opp_table(opp_table); |
---|
1027 | 1187 | |
---|
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 | + } |
---|
1029 | 1218 | |
---|
1030 | 1219 | return 0; |
---|
1031 | 1220 | } |
---|
1032 | 1221 | |
---|
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) |
---|
1035 | 1224 | { |
---|
1036 | | - unsigned long i = 0; |
---|
| 1225 | + if (!opp_info) |
---|
| 1226 | + return; |
---|
1037 | 1227 | |
---|
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); |
---|
1049 | 1229 | } |
---|
1050 | 1230 | |
---|
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) |
---|
1053 | 1236 | { |
---|
1054 | | - unsigned long target_state, target_freq = 0; |
---|
1055 | | - int i; |
---|
| 1237 | + struct dev_pm_set_opp_data *data; |
---|
| 1238 | + int size; |
---|
1056 | 1239 | |
---|
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) |
---|
1058 | 1274 | 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; |
---|
1063 | 1298 | } |
---|
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; |
---|
1069 | 1321 | } |
---|
1070 | 1322 | |
---|
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 | + } |
---|
1076 | 1332 | } |
---|
| 1333 | + rockchip_monitor_enable_opp_clk(dev, opp_info); |
---|
| 1334 | + rockchip_get_read_margin(dev, opp_info, new_volt, &target_rm); |
---|
1077 | 1335 | |
---|
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; |
---|
1079 | 1408 | } |
---|
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); |
---|
1099 | 1410 | |
---|
1100 | 1411 | struct monitor_dev_info * |
---|
1101 | 1412 | rockchip_system_monitor_register(struct device *dev, |
---|
1102 | 1413 | struct monitor_dev_profile *devp) |
---|
1103 | 1414 | { |
---|
1104 | 1415 | struct monitor_dev_info *info; |
---|
1105 | | - struct devfreq *devfreq; |
---|
1106 | | - int ret; |
---|
1107 | 1416 | |
---|
1108 | 1417 | if (!system_monitor) |
---|
1109 | 1418 | return ERR_PTR(-ENOMEM); |
---|
| 1419 | + |
---|
| 1420 | + if (!devp) |
---|
| 1421 | + return ERR_PTR(-EINVAL); |
---|
1110 | 1422 | |
---|
1111 | 1423 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
---|
1112 | 1424 | if (!info) |
---|
.. | .. |
---|
1114 | 1426 | info->dev = dev; |
---|
1115 | 1427 | info->devp = devp; |
---|
1116 | 1428 | |
---|
1117 | | - ret = monitor_device_parse_dt(dev, info); |
---|
1118 | | - if (ret) |
---|
1119 | | - goto free_info; |
---|
| 1429 | + mutex_init(&info->volt_adjust_mutex); |
---|
1120 | 1430 | |
---|
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); |
---|
1129 | 1438 | } |
---|
1130 | 1439 | |
---|
| 1440 | + rockchip_system_monitor_early_regulator_init(info); |
---|
1131 | 1441 | 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); |
---|
1133 | 1445 | |
---|
1134 | 1446 | down_write(&mdev_list_sem); |
---|
1135 | 1447 | list_add(&info->node, &monitor_dev_list); |
---|
1136 | 1448 | up_write(&mdev_list_sem); |
---|
1137 | 1449 | |
---|
1138 | 1450 | return info; |
---|
1139 | | - |
---|
1140 | | -free_info: |
---|
1141 | | - kfree(info); |
---|
1142 | | - return ERR_PTR(-EINVAL); |
---|
1143 | 1451 | } |
---|
1144 | 1452 | EXPORT_SYMBOL(rockchip_system_monitor_register); |
---|
1145 | 1453 | |
---|
1146 | 1454 | void rockchip_system_monitor_unregister(struct monitor_dev_info *info) |
---|
1147 | 1455 | { |
---|
1148 | | - struct devfreq *devfreq; |
---|
1149 | | - |
---|
1150 | 1456 | if (!info) |
---|
1151 | 1457 | return; |
---|
1152 | 1458 | |
---|
.. | .. |
---|
1154 | 1460 | list_del(&info->node); |
---|
1155 | 1461 | up_write(&mdev_list_sem); |
---|
1156 | 1462 | |
---|
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 | + } |
---|
1162 | 1474 | |
---|
1163 | 1475 | kfree(info->low_temp_adjust_table); |
---|
1164 | 1476 | kfree(info->opp_table); |
---|
1165 | | - kfree(info->freq_table); |
---|
| 1477 | + kfree(info->set_opp_data); |
---|
1166 | 1478 | kfree(info); |
---|
1167 | 1479 | } |
---|
1168 | 1480 | 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 | +}; |
---|
1169 | 1516 | |
---|
1170 | 1517 | static int rockchip_system_monitor_parse_dt(struct system_monitor *monitor) |
---|
1171 | 1518 | { |
---|
.. | .. |
---|
1173 | 1520 | const char *tz_name, *buf = NULL; |
---|
1174 | 1521 | |
---|
1175 | 1522 | 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); |
---|
1177 | 1524 | else |
---|
1178 | 1525 | cpulist_parse(buf, &monitor->video_4k_offline_cpus); |
---|
1179 | 1526 | |
---|
.. | .. |
---|
1199 | 1546 | system_monitor->offline_cpus_temp = INT_MAX; |
---|
1200 | 1547 | of_property_read_u32(np, "rockchip,temp-hysteresis", |
---|
1201 | 1548 | &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 | + |
---|
1202 | 1556 | out: |
---|
1203 | 1557 | return 0; |
---|
1204 | 1558 | } |
---|
.. | .. |
---|
1224 | 1578 | cpumask_copy(&system_monitor->offline_cpus, &offline_cpus); |
---|
1225 | 1579 | for_each_cpu(cpu, &system_monitor->offline_cpus) { |
---|
1226 | 1580 | if (cpu_online(cpu)) |
---|
1227 | | - cpu_down(cpu); |
---|
| 1581 | + remove_cpu(cpu); |
---|
1228 | 1582 | } |
---|
1229 | 1583 | |
---|
1230 | 1584 | cpumask_clear(&online_cpus); |
---|
.. | .. |
---|
1234 | 1588 | if (cpumask_empty(&online_cpus)) |
---|
1235 | 1589 | goto out; |
---|
1236 | 1590 | for_each_cpu(cpu, &online_cpus) |
---|
1237 | | - cpu_up(cpu); |
---|
| 1591 | + add_cpu(cpu); |
---|
1238 | 1592 | |
---|
1239 | 1593 | out: |
---|
1240 | 1594 | mutex_unlock(&cpu_on_off_mutex); |
---|
.. | .. |
---|
1266 | 1620 | { |
---|
1267 | 1621 | int temp, ret; |
---|
1268 | 1622 | struct monitor_dev_info *info; |
---|
1269 | | - static int last_temp = INT_MAX; |
---|
1270 | 1623 | |
---|
1271 | 1624 | ret = thermal_zone_get_temp(system_monitor->tz, &temp); |
---|
1272 | 1625 | if (ret || temp == THERMAL_TEMP_INVALID) |
---|
.. | .. |
---|
1274 | 1627 | |
---|
1275 | 1628 | dev_dbg(system_monitor->dev, "temperature=%d\n", temp); |
---|
1276 | 1629 | |
---|
1277 | | - if (temp < last_temp && last_temp - temp <= 2000) |
---|
| 1630 | + if (temp < system_monitor->last_temp && |
---|
| 1631 | + system_monitor->last_temp - temp <= 2000) |
---|
1278 | 1632 | goto out; |
---|
1279 | | - last_temp = temp; |
---|
| 1633 | + system_monitor->last_temp = temp; |
---|
| 1634 | + |
---|
| 1635 | + rockchip_system_monitor_temp_notify(temp); |
---|
1280 | 1636 | |
---|
1281 | 1637 | down_read(&mdev_list_sem); |
---|
1282 | 1638 | list_for_each_entry(info, &monitor_dev_list, node) |
---|
.. | .. |
---|
1302 | 1658 | unsigned long status) |
---|
1303 | 1659 | { |
---|
1304 | 1660 | 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; |
---|
1307 | 1666 | |
---|
1308 | 1667 | 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; |
---|
1313 | 1673 | } |
---|
1314 | 1674 | |
---|
1315 | 1675 | if (info->video_4k_freq && (status & SYS_STATUS_VIDEO_4K)) |
---|
1316 | 1676 | 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) |
---|
1319 | 1679 | return; |
---|
1320 | 1680 | 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); |
---|
1325 | 1687 | } |
---|
1326 | 1688 | |
---|
1327 | 1689 | static void rockchip_system_status_limit_freq(unsigned long status) |
---|
.. | .. |
---|
1330 | 1692 | |
---|
1331 | 1693 | down_read(&mdev_list_sem); |
---|
1332 | 1694 | 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) |
---|
1334 | 1696 | rockchip_system_status_cpu_limit_freq(info, status); |
---|
1335 | 1697 | } |
---|
1336 | 1698 | up_read(&mdev_list_sem); |
---|
.. | .. |
---|
1364 | 1726 | return NOTIFY_OK; |
---|
1365 | 1727 | } |
---|
1366 | 1728 | |
---|
| 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 | + |
---|
1367 | 1749 | static int monitor_pm_notify(struct notifier_block *nb, |
---|
1368 | 1750 | unsigned long mode, void *_unused) |
---|
1369 | 1751 | { |
---|
.. | .. |
---|
1372 | 1754 | case PM_RESTORE_PREPARE: |
---|
1373 | 1755 | case PM_SUSPEND_PREPARE: |
---|
1374 | 1756 | atomic_set(&monitor_in_suspend, 1); |
---|
| 1757 | + rockchip_system_monitor_set_cpu_uevent_suppress(true); |
---|
1375 | 1758 | break; |
---|
1376 | 1759 | case PM_POST_HIBERNATION: |
---|
1377 | 1760 | case PM_POST_RESTORE: |
---|
.. | .. |
---|
1379 | 1762 | if (system_monitor->tz) |
---|
1380 | 1763 | rockchip_system_monitor_thermal_update(); |
---|
1381 | 1764 | atomic_set(&monitor_in_suspend, 0); |
---|
| 1765 | + rockchip_system_monitor_set_cpu_uevent_suppress(false); |
---|
| 1766 | + system_monitor->last_temp = INT_MAX; |
---|
1382 | 1767 | break; |
---|
1383 | 1768 | default: |
---|
1384 | 1769 | break; |
---|
.. | .. |
---|
1388 | 1773 | |
---|
1389 | 1774 | static struct notifier_block monitor_pm_nb = { |
---|
1390 | 1775 | .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, |
---|
1436 | 1776 | }; |
---|
1437 | 1777 | |
---|
1438 | 1778 | static int rockchip_monitor_reboot_notifier(struct notifier_block *nb, |
---|
.. | .. |
---|
1454 | 1794 | { |
---|
1455 | 1795 | struct fb_event *event = ptr; |
---|
1456 | 1796 | |
---|
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); |
---|
1466 | 1803 | 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); |
---|
1475 | 1806 | break; |
---|
1476 | 1807 | default: |
---|
1477 | 1808 | break; |
---|
.. | .. |
---|
1494 | 1825 | case EBC_OFF: |
---|
1495 | 1826 | rockchip_set_system_status(SYS_STATUS_LOW_POWER); |
---|
1496 | 1827 | 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; |
---|
1503 | 1828 | default: |
---|
1504 | 1829 | break; |
---|
1505 | 1830 | } |
---|
.. | .. |
---|
1510 | 1835 | static struct notifier_block rockchip_monitor_ebc_nb = { |
---|
1511 | 1836 | .notifier_call = rockchip_eink_devfs_notifier, |
---|
1512 | 1837 | }; |
---|
| 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); |
---|
1513 | 1864 | |
---|
1514 | 1865 | static int rockchip_system_monitor_probe(struct platform_device *pdev) |
---|
1515 | 1866 | { |
---|
.. | .. |
---|
1532 | 1883 | |
---|
1533 | 1884 | rockchip_system_monitor_parse_dt(system_monitor); |
---|
1534 | 1885 | if (system_monitor->tz) { |
---|
| 1886 | + system_monitor->last_temp = INT_MAX; |
---|
1535 | 1887 | INIT_DELAYED_WORK(&system_monitor->thermal_work, |
---|
1536 | 1888 | rockchip_system_monitor_thermal_check); |
---|
1537 | 1889 | mod_delayed_work(system_freezable_wq, |
---|
.. | .. |
---|
1546 | 1898 | if (register_pm_notifier(&monitor_pm_nb)) |
---|
1547 | 1899 | dev_err(dev, "failed to register suspend notifier\n"); |
---|
1548 | 1900 | |
---|
1549 | | - cpufreq_register_notifier(&rockchip_monitor_cpufreq_policy_nb, |
---|
1550 | | - CPUFREQ_POLICY_NOTIFIER); |
---|
1551 | | - |
---|
1552 | 1901 | register_reboot_notifier(&rockchip_monitor_reboot_nb); |
---|
1553 | 1902 | |
---|
1554 | 1903 | if (fb_register_client(&rockchip_monitor_fb_nb)) |
---|
.. | .. |
---|
1556 | 1905 | |
---|
1557 | 1906 | ebc_register_notifier(&rockchip_monitor_ebc_nb); |
---|
1558 | 1907 | |
---|
| 1908 | + schedule_delayed_work(&system_monitor_early_min_volt_work, |
---|
| 1909 | + msecs_to_jiffies(30000)); |
---|
| 1910 | + |
---|
1559 | 1911 | dev_info(dev, "system monitor probe\n"); |
---|
1560 | 1912 | |
---|
1561 | 1913 | return 0; |
---|