| .. | .. |
|---|
| 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; |
|---|
| 70 | 78 | bool is_temp_offline; |
|---|
| 71 | | - bool boosted; |
|---|
| 72 | 79 | }; |
|---|
| 73 | 80 | |
|---|
| 74 | 81 | static unsigned long system_status; |
|---|
| .. | .. |
|---|
| 85 | 92 | static struct system_monitor *system_monitor; |
|---|
| 86 | 93 | static atomic_t monitor_in_suspend; |
|---|
| 87 | 94 | |
|---|
| 95 | +static BLOCKING_NOTIFIER_HEAD(system_monitor_notifier_list); |
|---|
| 88 | 96 | static BLOCKING_NOTIFIER_HEAD(system_status_notifier_list); |
|---|
| 89 | 97 | |
|---|
| 90 | 98 | int rockchip_register_system_status_notifier(struct notifier_block *nb) |
|---|
| .. | .. |
|---|
| 174 | 182 | return -EINVAL; |
|---|
| 175 | 183 | } |
|---|
| 176 | 184 | |
|---|
| 177 | | - return __compat_only_sysfs_link_entry_to_kobj(&dev->kobj, |
|---|
| 178 | | - system_monitor->kobj, |
|---|
| 179 | | - "system_status"); |
|---|
| 185 | + return compat_only_sysfs_link_entry_to_kobj(&dev->kobj, |
|---|
| 186 | + system_monitor->kobj, |
|---|
| 187 | + "system_status", NULL); |
|---|
| 180 | 188 | } |
|---|
| 181 | 189 | EXPORT_SYMBOL(rockchip_add_system_status_interface); |
|---|
| 182 | 190 | |
|---|
| .. | .. |
|---|
| 360 | 368 | /* clear performance flag */ |
|---|
| 361 | 369 | rockchip_clear_system_status(SYS_STATUS_PERFORMANCE); |
|---|
| 362 | 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); |
|---|
| 378 | + break; |
|---|
| 363 | 379 | default: |
|---|
| 364 | 380 | break; |
|---|
| 365 | 381 | } |
|---|
| .. | .. |
|---|
| 497 | 513 | int delta_volt = 0; |
|---|
| 498 | 514 | int i = 0, max_count; |
|---|
| 499 | 515 | unsigned long low_limit = 0, high_limit = 0; |
|---|
| 516 | + unsigned long low_limit_mem = 0, high_limit_mem = 0; |
|---|
| 500 | 517 | bool reach_max_volt = false; |
|---|
| 518 | + bool reach_max_mem_volt = false; |
|---|
| 501 | 519 | bool reach_high_temp_max_volt = false; |
|---|
| 520 | + bool reach_high_temp_max_mem_volt = false; |
|---|
| 502 | 521 | |
|---|
| 503 | 522 | max_count = dev_pm_opp_get_opp_count(dev); |
|---|
| 504 | 523 | if (max_count <= 0) |
|---|
| .. | .. |
|---|
| 516 | 535 | } |
|---|
| 517 | 536 | mutex_lock(&opp_table->lock); |
|---|
| 518 | 537 | list_for_each_entry(opp, &opp_table->opp_list, node) { |
|---|
| 538 | + if (!opp->available) |
|---|
| 539 | + continue; |
|---|
| 519 | 540 | info->opp_table[i].rate = opp->rate; |
|---|
| 520 | 541 | info->opp_table[i].volt = opp->supplies[0].u_volt; |
|---|
| 521 | 542 | info->opp_table[i].max_volt = opp->supplies[0].u_volt_max; |
|---|
| .. | .. |
|---|
| 547 | 568 | info->low_limit = low_limit; |
|---|
| 548 | 569 | if (high_limit && high_limit != opp->rate) |
|---|
| 549 | 570 | info->high_limit = high_limit; |
|---|
| 550 | | - dev_dbg(dev, "rate=%lu, volt=%lu, low_temp_volt=%lu\n", |
|---|
| 571 | + |
|---|
| 572 | + if (opp_table->regulator_count > 1) { |
|---|
| 573 | + info->opp_table[i].mem_volt = opp->supplies[1].u_volt; |
|---|
| 574 | + info->opp_table[i].max_mem_volt = opp->supplies[1].u_volt_max; |
|---|
| 575 | + |
|---|
| 576 | + if (opp->supplies[1].u_volt <= info->high_temp_max_volt) { |
|---|
| 577 | + if (!reach_high_temp_max_mem_volt) |
|---|
| 578 | + high_limit_mem = opp->rate; |
|---|
| 579 | + if (opp->supplies[1].u_volt == info->high_temp_max_volt) |
|---|
| 580 | + reach_high_temp_max_mem_volt = true; |
|---|
| 581 | + } |
|---|
| 582 | + |
|---|
| 583 | + if ((opp->supplies[1].u_volt + delta_volt) <= info->max_volt) { |
|---|
| 584 | + info->opp_table[i].low_temp_mem_volt = |
|---|
| 585 | + opp->supplies[1].u_volt + delta_volt; |
|---|
| 586 | + if (info->opp_table[i].low_temp_mem_volt < |
|---|
| 587 | + info->low_temp_min_volt) |
|---|
| 588 | + info->opp_table[i].low_temp_mem_volt = |
|---|
| 589 | + info->low_temp_min_volt; |
|---|
| 590 | + if (!reach_max_mem_volt) |
|---|
| 591 | + low_limit_mem = opp->rate; |
|---|
| 592 | + if (info->opp_table[i].low_temp_mem_volt == info->max_volt) |
|---|
| 593 | + reach_max_mem_volt = true; |
|---|
| 594 | + } else { |
|---|
| 595 | + info->opp_table[i].low_temp_mem_volt = info->max_volt; |
|---|
| 596 | + } |
|---|
| 597 | + |
|---|
| 598 | + if (low_limit_mem && low_limit_mem != opp->rate) { |
|---|
| 599 | + if (info->low_limit > low_limit_mem) |
|---|
| 600 | + info->low_limit = low_limit_mem; |
|---|
| 601 | + } |
|---|
| 602 | + if (high_limit_mem && high_limit_mem != opp->rate) { |
|---|
| 603 | + if (info->high_limit > high_limit_mem) |
|---|
| 604 | + info->high_limit = high_limit_mem; |
|---|
| 605 | + } |
|---|
| 606 | + } |
|---|
| 607 | + |
|---|
| 608 | + dev_dbg(dev, "rate=%lu, volt=%lu %lu low_temp_volt=%lu %lu\n", |
|---|
| 551 | 609 | info->opp_table[i].rate, info->opp_table[i].volt, |
|---|
| 552 | | - info->opp_table[i].low_temp_volt); |
|---|
| 610 | + info->opp_table[i].mem_volt, |
|---|
| 611 | + info->opp_table[i].low_temp_volt, |
|---|
| 612 | + info->opp_table[i].low_temp_mem_volt); |
|---|
| 553 | 613 | i++; |
|---|
| 554 | 614 | } |
|---|
| 555 | 615 | mutex_unlock(&opp_table->lock); |
|---|
| .. | .. |
|---|
| 591 | 651 | else |
|---|
| 592 | 652 | info->high_temp_max_volt = value; |
|---|
| 593 | 653 | rockchip_init_temp_opp_table(info); |
|---|
| 594 | | - if (rockchip_get_temp_freq_table(np, "rockchip,high-temp-limit-table", |
|---|
| 595 | | - &info->high_limit_table)) { |
|---|
| 596 | | - info->high_limit_table = NULL; |
|---|
| 654 | + rockchip_get_temp_freq_table(np, "rockchip,temp-freq-table", |
|---|
| 655 | + &info->high_limit_table); |
|---|
| 656 | + if (!info->high_limit_table) |
|---|
| 657 | + rockchip_get_temp_freq_table(np, "rockchip,high-temp-limit-table", |
|---|
| 658 | + &info->high_limit_table); |
|---|
| 659 | + if (!info->high_limit_table) { |
|---|
| 597 | 660 | if (!of_property_read_u32(np, "rockchip,high-temp-max-freq", |
|---|
| 598 | 661 | &value)) { |
|---|
| 599 | 662 | high_temp_max_freq = value * 1000; |
|---|
| .. | .. |
|---|
| 645 | 708 | &info->video_4k_freq); |
|---|
| 646 | 709 | ret &= of_property_read_u32(np, "rockchip,reboot-freq", |
|---|
| 647 | 710 | &info->reboot_freq); |
|---|
| 648 | | - if (info->devp->type == MONITOR_TPYE_CPU) { |
|---|
| 711 | + if (info->devp->type == MONITOR_TYPE_CPU) { |
|---|
| 649 | 712 | if (!info->reboot_freq) { |
|---|
| 650 | 713 | info->reboot_freq = CPU_REBOOT_FREQ; |
|---|
| 651 | 714 | ret = 0; |
|---|
| .. | .. |
|---|
| 655 | 718 | return ret; |
|---|
| 656 | 719 | } |
|---|
| 657 | 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 | + |
|---|
| 658 | 747 | static int monitor_device_parse_dt(struct device *dev, |
|---|
| 659 | 748 | struct monitor_dev_info *info) |
|---|
| 660 | 749 | { |
|---|
| 661 | 750 | struct device_node *np; |
|---|
| 662 | | - int ret = 0; |
|---|
| 663 | | - bool is_wide_temp_en = false; |
|---|
| 664 | | - bool is_status_limit_en = false; |
|---|
| 665 | | - bool is_temp_freq_en = false; |
|---|
| 751 | + int ret; |
|---|
| 666 | 752 | |
|---|
| 667 | 753 | np = of_parse_phandle(dev->of_node, "operating-points-v2", 0); |
|---|
| 668 | 754 | if (!np) |
|---|
| 669 | 755 | return -EINVAL; |
|---|
| 670 | 756 | |
|---|
| 671 | | - if (!monitor_device_parse_wide_temp_config(np, info)) |
|---|
| 672 | | - is_wide_temp_en = true; |
|---|
| 673 | | - if (!monitor_device_parse_status_config(np, info)) |
|---|
| 674 | | - is_status_limit_en = true; |
|---|
| 675 | | - if (!rockchip_get_temp_freq_table(np, "rockchip,temp-freq-table", |
|---|
| 676 | | - &info->temp_freq_table)) |
|---|
| 677 | | - is_temp_freq_en = true; |
|---|
| 678 | | - if (is_wide_temp_en || is_status_limit_en || is_temp_freq_en) |
|---|
| 679 | | - ret = 0; |
|---|
| 680 | | - else |
|---|
| 681 | | - ret = -EINVAL; |
|---|
| 757 | + of_property_read_u32(np, "rockchip,init-freq", &info->init_freq); |
|---|
| 758 | + |
|---|
| 759 | + ret = monitor_device_parse_wide_temp_config(np, info); |
|---|
| 760 | + ret &= monitor_device_parse_status_config(np, info); |
|---|
| 761 | + ret &= monitor_device_parse_early_min_volt(np, info); |
|---|
| 762 | + ret &= monitor_device_parse_read_margin(np, info); |
|---|
| 763 | + ret &= monitor_device_parse_scmi_clk(np, info); |
|---|
| 682 | 764 | |
|---|
| 683 | 765 | of_node_put(np); |
|---|
| 684 | 766 | |
|---|
| 685 | 767 | return ret; |
|---|
| 686 | 768 | } |
|---|
| 687 | 769 | |
|---|
| 688 | | -int rockchip_monitor_opp_set_rate(struct monitor_dev_info *info, |
|---|
| 689 | | - unsigned long target_freq) |
|---|
| 690 | | -{ |
|---|
| 691 | | - int ret = 0; |
|---|
| 692 | | - |
|---|
| 693 | | - mutex_lock(&info->volt_adjust_mutex); |
|---|
| 694 | | - ret = dev_pm_opp_set_rate(info->dev, target_freq); |
|---|
| 695 | | - mutex_unlock(&info->volt_adjust_mutex); |
|---|
| 696 | | - |
|---|
| 697 | | - return ret; |
|---|
| 698 | | -} |
|---|
| 699 | | -EXPORT_SYMBOL(rockchip_monitor_opp_set_rate); |
|---|
| 700 | | - |
|---|
| 701 | 770 | int rockchip_monitor_cpu_low_temp_adjust(struct monitor_dev_info *info, |
|---|
| 702 | 771 | bool is_low) |
|---|
| 703 | 772 | { |
|---|
| 704 | | - struct device *dev = info->dev; |
|---|
| 705 | | - unsigned int cpu = cpumask_any(&info->devp->allowed_cpus); |
|---|
| 773 | + if (!info->low_limit) |
|---|
| 774 | + return 0; |
|---|
| 706 | 775 | |
|---|
| 707 | | - if (info->low_limit) { |
|---|
| 708 | | - if (is_low) |
|---|
| 709 | | - info->wide_temp_limit = info->low_limit; |
|---|
| 710 | | - else |
|---|
| 711 | | - info->wide_temp_limit = 0; |
|---|
| 712 | | - cpufreq_update_policy(cpu); |
|---|
| 713 | | - } |
|---|
| 776 | + if (!freq_qos_request_active(&info->max_temp_freq_req)) |
|---|
| 777 | + return 0; |
|---|
| 714 | 778 | |
|---|
| 715 | | - mutex_lock(&info->volt_adjust_mutex); |
|---|
| 716 | | - dev_pm_opp_check_rate_volt(dev, false); |
|---|
| 717 | | - mutex_unlock(&info->volt_adjust_mutex); |
|---|
| 779 | + if (is_low) |
|---|
| 780 | + freq_qos_update_request(&info->max_temp_freq_req, |
|---|
| 781 | + info->low_limit / 1000); |
|---|
| 782 | + else |
|---|
| 783 | + freq_qos_update_request(&info->max_temp_freq_req, |
|---|
| 784 | + FREQ_QOS_MAX_DEFAULT_VALUE); |
|---|
| 718 | 785 | |
|---|
| 719 | 786 | return 0; |
|---|
| 720 | 787 | } |
|---|
| .. | .. |
|---|
| 723 | 790 | int rockchip_monitor_cpu_high_temp_adjust(struct monitor_dev_info *info, |
|---|
| 724 | 791 | bool is_high) |
|---|
| 725 | 792 | { |
|---|
| 726 | | - unsigned int cpu = cpumask_any(&info->devp->allowed_cpus); |
|---|
| 793 | + if (!info->high_limit) |
|---|
| 794 | + return 0; |
|---|
| 795 | + |
|---|
| 796 | + if (!freq_qos_request_active(&info->max_temp_freq_req)) |
|---|
| 797 | + return 0; |
|---|
| 727 | 798 | |
|---|
| 728 | 799 | if (info->high_limit_table) { |
|---|
| 729 | | - info->wide_temp_limit = info->high_limit; |
|---|
| 730 | | - cpufreq_update_policy(cpu); |
|---|
| 731 | | - } else { |
|---|
| 732 | | - if (info->high_limit) { |
|---|
| 733 | | - if (is_high) |
|---|
| 734 | | - info->wide_temp_limit = info->high_limit; |
|---|
| 735 | | - else |
|---|
| 736 | | - info->wide_temp_limit = 0; |
|---|
| 737 | | - cpufreq_update_policy(cpu); |
|---|
| 738 | | - } |
|---|
| 800 | + freq_qos_update_request(&info->max_temp_freq_req, |
|---|
| 801 | + info->high_limit / 1000); |
|---|
| 802 | + return 0; |
|---|
| 739 | 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); |
|---|
| 740 | 811 | |
|---|
| 741 | 812 | return 0; |
|---|
| 742 | 813 | } |
|---|
| 743 | 814 | EXPORT_SYMBOL(rockchip_monitor_cpu_high_temp_adjust); |
|---|
| 744 | 815 | |
|---|
| 745 | | -void rockchip_monitor_set_boosted(void) |
|---|
| 746 | | -{ |
|---|
| 747 | | - if (system_monitor) |
|---|
| 748 | | - system_monitor->boosted = true; |
|---|
| 749 | | -} |
|---|
| 750 | | -EXPORT_SYMBOL(rockchip_monitor_set_boosted); |
|---|
| 751 | | - |
|---|
| 752 | | -void rockchip_monitor_clear_boosted(void) |
|---|
| 753 | | -{ |
|---|
| 754 | | - if (system_monitor) |
|---|
| 755 | | - system_monitor->boosted = false; |
|---|
| 756 | | -} |
|---|
| 757 | | -EXPORT_SYMBOL(rockchip_monitor_clear_boosted); |
|---|
| 758 | | - |
|---|
| 759 | | -static int rockchip_monitor_update_devfreq(struct devfreq *df) |
|---|
| 760 | | -{ |
|---|
| 761 | | - int ret = 0; |
|---|
| 762 | | - |
|---|
| 763 | | -#ifdef CONFIG_PM_DEVFREQ |
|---|
| 764 | | - mutex_lock(&df->lock); |
|---|
| 765 | | - ret = update_devfreq(df); |
|---|
| 766 | | - mutex_unlock(&df->lock); |
|---|
| 767 | | -#endif |
|---|
| 768 | | - return ret; |
|---|
| 769 | | -}; |
|---|
| 770 | | - |
|---|
| 771 | 816 | int rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info *info, |
|---|
| 772 | 817 | bool is_low) |
|---|
| 773 | 818 | { |
|---|
| 774 | | - struct devfreq *df; |
|---|
| 819 | + if (!dev_pm_qos_request_active(&info->dev_max_freq_req)) |
|---|
| 820 | + return 0; |
|---|
| 775 | 821 | |
|---|
| 776 | | - if (info->low_limit) { |
|---|
| 777 | | - if (is_low) |
|---|
| 778 | | - info->wide_temp_limit = info->low_limit; |
|---|
| 779 | | - else |
|---|
| 780 | | - info->wide_temp_limit = 0; |
|---|
| 781 | | - } |
|---|
| 822 | + if (!info->low_limit) |
|---|
| 823 | + return 0; |
|---|
| 782 | 824 | |
|---|
| 783 | | - if (info->devp && info->devp->data) { |
|---|
| 784 | | - df = (struct devfreq *)info->devp->data; |
|---|
| 785 | | - rockchip_monitor_update_devfreq(df); |
|---|
| 786 | | - } else if (info->devp && info->devp->low_temp_adjust_volt) { |
|---|
| 787 | | - info->devp->low_temp_adjust_volt(info); |
|---|
| 788 | | - } |
|---|
| 825 | + if (is_low) |
|---|
| 826 | + dev_pm_qos_update_request(&info->dev_max_freq_req, |
|---|
| 827 | + info->low_limit / 1000); |
|---|
| 828 | + else |
|---|
| 829 | + dev_pm_qos_update_request(&info->dev_max_freq_req, |
|---|
| 830 | + PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE); |
|---|
| 789 | 831 | |
|---|
| 790 | 832 | return 0; |
|---|
| 791 | 833 | } |
|---|
| .. | .. |
|---|
| 794 | 836 | int rockchip_monitor_dev_high_temp_adjust(struct monitor_dev_info *info, |
|---|
| 795 | 837 | bool is_high) |
|---|
| 796 | 838 | { |
|---|
| 797 | | - struct devfreq *df; |
|---|
| 839 | + if (!dev_pm_qos_request_active(&info->dev_max_freq_req)) |
|---|
| 840 | + return 0; |
|---|
| 841 | + |
|---|
| 842 | + if (!info->high_limit) |
|---|
| 843 | + return 0; |
|---|
| 798 | 844 | |
|---|
| 799 | 845 | if (info->high_limit_table) { |
|---|
| 800 | | - info->wide_temp_limit = info->high_limit; |
|---|
| 801 | | - if (info->devp && info->devp->data) { |
|---|
| 802 | | - df = (struct devfreq *)info->devp->data; |
|---|
| 803 | | - rockchip_monitor_update_devfreq(df); |
|---|
| 804 | | - } |
|---|
| 805 | | - } else { |
|---|
| 806 | | - if (info->high_limit) { |
|---|
| 807 | | - if (is_high) |
|---|
| 808 | | - info->wide_temp_limit = info->high_limit; |
|---|
| 809 | | - else |
|---|
| 810 | | - info->wide_temp_limit = 0; |
|---|
| 811 | | - if (info->devp && info->devp->data) { |
|---|
| 812 | | - df = (struct devfreq *)info->devp->data; |
|---|
| 813 | | - rockchip_monitor_update_devfreq(df); |
|---|
| 814 | | - } |
|---|
| 815 | | - } |
|---|
| 846 | + dev_pm_qos_update_request(&info->dev_max_freq_req, |
|---|
| 847 | + info->high_limit / 1000); |
|---|
| 848 | + return 0; |
|---|
| 816 | 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); |
|---|
| 817 | 857 | |
|---|
| 818 | 858 | return 0; |
|---|
| 819 | 859 | } |
|---|
| .. | .. |
|---|
| 833 | 873 | |
|---|
| 834 | 874 | mutex_lock(&opp_table->lock); |
|---|
| 835 | 875 | list_for_each_entry(opp, &opp_table->opp_list, node) { |
|---|
| 876 | + if (!opp->available) |
|---|
| 877 | + continue; |
|---|
| 836 | 878 | if (is_low_temp) { |
|---|
| 837 | 879 | if (opp->supplies[0].u_volt_max < |
|---|
| 838 | 880 | info->opp_table[i].low_temp_volt) |
|---|
| .. | .. |
|---|
| 841 | 883 | opp->supplies[0].u_volt = |
|---|
| 842 | 884 | info->opp_table[i].low_temp_volt; |
|---|
| 843 | 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 | + } |
|---|
| 844 | 896 | } else { |
|---|
| 845 | 897 | opp->supplies[0].u_volt_min = info->opp_table[i].volt; |
|---|
| 846 | 898 | opp->supplies[0].u_volt = opp->supplies[0].u_volt_min; |
|---|
| 847 | 899 | opp->supplies[0].u_volt_max = |
|---|
| 848 | 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 | + } |
|---|
| 849 | 909 | } |
|---|
| 850 | 910 | i++; |
|---|
| 851 | 911 | } |
|---|
| .. | .. |
|---|
| 871 | 931 | ret = devp->low_temp_adjust(info, is_low); |
|---|
| 872 | 932 | if (!ret) |
|---|
| 873 | 933 | info->is_low_temp = is_low; |
|---|
| 934 | + |
|---|
| 935 | + if (devp->update_volt) |
|---|
| 936 | + devp->update_volt(info); |
|---|
| 874 | 937 | } |
|---|
| 875 | 938 | |
|---|
| 876 | 939 | static void rockchip_high_temp_adjust(struct monitor_dev_info *info, |
|---|
| .. | .. |
|---|
| 879 | 942 | struct monitor_dev_profile *devp = info->devp; |
|---|
| 880 | 943 | int ret = 0; |
|---|
| 881 | 944 | |
|---|
| 945 | + if (!devp->high_temp_adjust) |
|---|
| 946 | + return; |
|---|
| 947 | + |
|---|
| 882 | 948 | if (info->high_limit_table) { |
|---|
| 883 | 949 | devp->high_temp_adjust(info, is_high); |
|---|
| 884 | 950 | } else { |
|---|
| 885 | 951 | dev_dbg(info->dev, "high_temp %d\n", is_high); |
|---|
| 886 | | - if (devp->high_temp_adjust) |
|---|
| 887 | | - ret = devp->high_temp_adjust(info, is_high); |
|---|
| 952 | + ret = devp->high_temp_adjust(info, is_high); |
|---|
| 888 | 953 | if (!ret) |
|---|
| 889 | 954 | info->is_high_temp = is_high; |
|---|
| 890 | 955 | } |
|---|
| .. | .. |
|---|
| 895 | 960 | struct monitor_dev_info *info = NULL, *tmp; |
|---|
| 896 | 961 | |
|---|
| 897 | 962 | list_for_each_entry(tmp, &monitor_dev_list, node) { |
|---|
| 898 | | - if (tmp->devp->type != MONITOR_TPYE_CPU) |
|---|
| 963 | + if (tmp->devp->type != MONITOR_TYPE_CPU) |
|---|
| 899 | 964 | continue; |
|---|
| 900 | 965 | if (cpumask_test_cpu(cpu, &tmp->devp->allowed_cpus)) { |
|---|
| 901 | 966 | info = tmp; |
|---|
| .. | .. |
|---|
| 962 | 1027 | { |
|---|
| 963 | 1028 | int ret, temp; |
|---|
| 964 | 1029 | |
|---|
| 1030 | + if (!info->opp_table) |
|---|
| 1031 | + return; |
|---|
| 1032 | + |
|---|
| 965 | 1033 | /* |
|---|
| 966 | 1034 | * set the init state to low temperature that the voltage will be enough |
|---|
| 967 | 1035 | * when cpu up at low temperature. |
|---|
| .. | .. |
|---|
| 969 | 1037 | if (!info->is_low_temp) { |
|---|
| 970 | 1038 | if (info->opp_table) |
|---|
| 971 | 1039 | rockchip_adjust_low_temp_opp_volt(info, true); |
|---|
| 972 | | - info->wide_temp_limit = info->low_limit; |
|---|
| 973 | 1040 | info->is_low_temp = true; |
|---|
| 974 | 1041 | } |
|---|
| 975 | 1042 | |
|---|
| .. | .. |
|---|
| 984 | 1051 | if (info->opp_table) |
|---|
| 985 | 1052 | rockchip_adjust_low_temp_opp_volt(info, false); |
|---|
| 986 | 1053 | info->is_low_temp = false; |
|---|
| 987 | | - |
|---|
| 988 | | - info->wide_temp_limit = info->high_limit; |
|---|
| 989 | 1054 | info->is_high_temp = true; |
|---|
| 990 | 1055 | } else if (temp > (info->low_temp + info->temp_hysteresis)) { |
|---|
| 991 | 1056 | if (info->opp_table) |
|---|
| 992 | 1057 | rockchip_adjust_low_temp_opp_volt(info, false); |
|---|
| 993 | 1058 | info->is_low_temp = false; |
|---|
| 994 | | - info->wide_temp_limit = 0; |
|---|
| 995 | 1059 | } |
|---|
| 996 | 1060 | } |
|---|
| 997 | 1061 | |
|---|
| 998 | | -static int system_monitor_devfreq_notifier_call(struct notifier_block *nb, |
|---|
| 999 | | - unsigned long event, |
|---|
| 1000 | | - void *data) |
|---|
| 1062 | +static const char *get_rdev_name(struct regulator_dev *rdev) |
|---|
| 1001 | 1063 | { |
|---|
| 1002 | | - struct monitor_dev_info *info = devfreq_nb_to_monitor(nb); |
|---|
| 1003 | | - struct devfreq_policy *policy = data; |
|---|
| 1004 | | - |
|---|
| 1005 | | - if (event != DEVFREQ_ADJUST) |
|---|
| 1006 | | - return NOTIFY_DONE; |
|---|
| 1007 | | - |
|---|
| 1008 | | - if (info->wide_temp_limit && info->wide_temp_limit < policy->max) |
|---|
| 1009 | | - devfreq_verify_within_limits(policy, 0, info->wide_temp_limit); |
|---|
| 1010 | | - |
|---|
| 1011 | | - return NOTIFY_OK; |
|---|
| 1064 | + if (rdev->constraints && rdev->constraints->name) |
|---|
| 1065 | + return rdev->constraints->name; |
|---|
| 1066 | + else if (rdev->desc->name) |
|---|
| 1067 | + return rdev->desc->name; |
|---|
| 1068 | + else |
|---|
| 1069 | + return ""; |
|---|
| 1012 | 1070 | } |
|---|
| 1013 | 1071 | |
|---|
| 1014 | | -static int monitor_set_freq_table(struct device *dev, |
|---|
| 1015 | | - struct monitor_dev_info *info) |
|---|
| 1072 | +static void |
|---|
| 1073 | +rockchip_system_monitor_early_regulator_init(struct monitor_dev_info *info) |
|---|
| 1016 | 1074 | { |
|---|
| 1017 | | - struct opp_table *opp_table; |
|---|
| 1018 | | - struct dev_pm_opp *opp; |
|---|
| 1019 | | - unsigned long *freq_table; |
|---|
| 1020 | | - int count; |
|---|
| 1075 | + struct regulator *reg; |
|---|
| 1076 | + struct regulator_dev *rdev; |
|---|
| 1021 | 1077 | |
|---|
| 1022 | | - opp_table = dev_pm_opp_get_opp_table(dev); |
|---|
| 1023 | | - if (!opp_table) |
|---|
| 1024 | | - return -ENOMEM; |
|---|
| 1078 | + if (!info->early_min_volt || !info->regulators) |
|---|
| 1079 | + return; |
|---|
| 1025 | 1080 | |
|---|
| 1026 | | - /* Initialize the freq_table from OPP table */ |
|---|
| 1027 | | - count = dev_pm_opp_get_opp_count(dev); |
|---|
| 1028 | | - if (count <= 0) |
|---|
| 1029 | | - return -EINVAL; |
|---|
| 1030 | | - |
|---|
| 1031 | | - info->max_state = count; |
|---|
| 1032 | | - freq_table = kcalloc(count, sizeof(*info->freq_table), GFP_KERNEL); |
|---|
| 1033 | | - if (!freq_table) { |
|---|
| 1034 | | - info->max_state = 0; |
|---|
| 1035 | | - return -ENOMEM; |
|---|
| 1081 | + rdev = info->regulators[0]->rdev; |
|---|
| 1082 | + reg = regulator_get(NULL, get_rdev_name(rdev)); |
|---|
| 1083 | + if (!IS_ERR_OR_NULL(reg)) { |
|---|
| 1084 | + info->early_reg = reg; |
|---|
| 1085 | + reg->voltage[PM_SUSPEND_ON].min_uV = info->early_min_volt; |
|---|
| 1086 | + reg->voltage[PM_SUSPEND_ON].max_uV = rdev->constraints->max_uV; |
|---|
| 1036 | 1087 | } |
|---|
| 1088 | +} |
|---|
| 1037 | 1089 | |
|---|
| 1038 | | - mutex_lock(&opp_table->lock); |
|---|
| 1039 | | - list_for_each_entry(opp, &opp_table->opp_list, node) { |
|---|
| 1040 | | - if (opp->available) { |
|---|
| 1041 | | - count--; |
|---|
| 1042 | | - freq_table[count] = opp->rate; |
|---|
| 1090 | +static int |
|---|
| 1091 | +rockchip_system_monitor_freq_qos_requset(struct monitor_dev_info *info) |
|---|
| 1092 | +{ |
|---|
| 1093 | + struct devfreq *devfreq; |
|---|
| 1094 | + struct cpufreq_policy *policy; |
|---|
| 1095 | + int max_default_value = FREQ_QOS_MAX_DEFAULT_VALUE; |
|---|
| 1096 | + int ret; |
|---|
| 1097 | + |
|---|
| 1098 | + if (!info->devp->data) |
|---|
| 1099 | + return 0; |
|---|
| 1100 | + |
|---|
| 1101 | + if (info->is_low_temp && info->low_limit) |
|---|
| 1102 | + max_default_value = info->low_limit / 1000; |
|---|
| 1103 | + else if (info->is_high_temp && info->high_limit) |
|---|
| 1104 | + max_default_value = info->high_limit / 1000; |
|---|
| 1105 | + |
|---|
| 1106 | + if (info->devp->type == MONITOR_TYPE_CPU) { |
|---|
| 1107 | + policy = (struct cpufreq_policy *)info->devp->data; |
|---|
| 1108 | + ret = freq_qos_add_request(&policy->constraints, |
|---|
| 1109 | + &info->max_temp_freq_req, |
|---|
| 1110 | + FREQ_QOS_MAX, |
|---|
| 1111 | + max_default_value); |
|---|
| 1112 | + if (ret < 0) { |
|---|
| 1113 | + dev_info(info->dev, |
|---|
| 1114 | + "failed to add temp freq constraint\n"); |
|---|
| 1115 | + return ret; |
|---|
| 1116 | + } |
|---|
| 1117 | + ret = freq_qos_add_request(&policy->constraints, |
|---|
| 1118 | + &info->min_sta_freq_req, |
|---|
| 1119 | + FREQ_QOS_MIN, |
|---|
| 1120 | + FREQ_QOS_MIN_DEFAULT_VALUE); |
|---|
| 1121 | + if (ret < 0) { |
|---|
| 1122 | + dev_info(info->dev, |
|---|
| 1123 | + "failed to add sta freq constraint\n"); |
|---|
| 1124 | + freq_qos_remove_request(&info->max_temp_freq_req); |
|---|
| 1125 | + return ret; |
|---|
| 1126 | + } |
|---|
| 1127 | + ret = freq_qos_add_request(&policy->constraints, |
|---|
| 1128 | + &info->max_sta_freq_req, |
|---|
| 1129 | + FREQ_QOS_MAX, |
|---|
| 1130 | + FREQ_QOS_MAX_DEFAULT_VALUE); |
|---|
| 1131 | + if (ret < 0) { |
|---|
| 1132 | + dev_info(info->dev, |
|---|
| 1133 | + "failed to add sta freq constraint\n"); |
|---|
| 1134 | + freq_qos_remove_request(&info->max_temp_freq_req); |
|---|
| 1135 | + freq_qos_remove_request(&info->min_sta_freq_req); |
|---|
| 1136 | + return ret; |
|---|
| 1137 | + } |
|---|
| 1138 | + } else if (info->devp->type == MONITOR_TYPE_DEV) { |
|---|
| 1139 | + devfreq = (struct devfreq *)info->devp->data; |
|---|
| 1140 | + ret = dev_pm_qos_add_request(devfreq->dev.parent, |
|---|
| 1141 | + &info->dev_max_freq_req, |
|---|
| 1142 | + DEV_PM_QOS_MAX_FREQUENCY, |
|---|
| 1143 | + max_default_value); |
|---|
| 1144 | + if (ret < 0) { |
|---|
| 1145 | + dev_info(info->dev, "failed to add freq constraint\n"); |
|---|
| 1146 | + return ret; |
|---|
| 1043 | 1147 | } |
|---|
| 1044 | 1148 | } |
|---|
| 1045 | | - mutex_unlock(&opp_table->lock); |
|---|
| 1149 | + |
|---|
| 1150 | + return 0; |
|---|
| 1151 | +} |
|---|
| 1152 | + |
|---|
| 1153 | +static int rockchip_system_monitor_parse_supplies(struct device *dev, |
|---|
| 1154 | + struct monitor_dev_info *info) |
|---|
| 1155 | +{ |
|---|
| 1156 | + struct opp_table *opp_table; |
|---|
| 1157 | + struct dev_pm_set_opp_data *data; |
|---|
| 1158 | + int len, count; |
|---|
| 1159 | + |
|---|
| 1160 | + opp_table = dev_pm_opp_get_opp_table(dev); |
|---|
| 1161 | + if (IS_ERR(opp_table)) |
|---|
| 1162 | + return PTR_ERR(opp_table); |
|---|
| 1163 | + |
|---|
| 1164 | + if (opp_table->clk) |
|---|
| 1165 | + info->clk = opp_table->clk; |
|---|
| 1166 | + if (opp_table->regulators) |
|---|
| 1167 | + info->regulators = opp_table->regulators; |
|---|
| 1168 | + info->regulator_count = opp_table->regulator_count; |
|---|
| 1169 | + |
|---|
| 1170 | + if (opp_table->regulators && info->devp->set_opp) { |
|---|
| 1171 | + count = opp_table->regulator_count; |
|---|
| 1172 | + /* space for set_opp_data */ |
|---|
| 1173 | + len = sizeof(*data); |
|---|
| 1174 | + /* space for old_opp.supplies and new_opp.supplies */ |
|---|
| 1175 | + len += 2 * sizeof(struct dev_pm_opp_supply) * count; |
|---|
| 1176 | + data = kzalloc(len, GFP_KERNEL); |
|---|
| 1177 | + if (!data) |
|---|
| 1178 | + return -ENOMEM; |
|---|
| 1179 | + data->old_opp.supplies = (void *)(data + 1); |
|---|
| 1180 | + data->new_opp.supplies = data->old_opp.supplies + count; |
|---|
| 1181 | + info->set_opp_data = data; |
|---|
| 1182 | + } |
|---|
| 1046 | 1183 | |
|---|
| 1047 | 1184 | dev_pm_opp_put_opp_table(opp_table); |
|---|
| 1048 | 1185 | |
|---|
| 1049 | | - info->freq_table = freq_table; |
|---|
| 1186 | + return 0; |
|---|
| 1187 | +} |
|---|
| 1188 | + |
|---|
| 1189 | +void rockchip_monitor_volt_adjust_lock(struct monitor_dev_info *info) |
|---|
| 1190 | +{ |
|---|
| 1191 | + if (info) |
|---|
| 1192 | + mutex_lock(&info->volt_adjust_mutex); |
|---|
| 1193 | +} |
|---|
| 1194 | +EXPORT_SYMBOL(rockchip_monitor_volt_adjust_lock); |
|---|
| 1195 | + |
|---|
| 1196 | +void rockchip_monitor_volt_adjust_unlock(struct monitor_dev_info *info) |
|---|
| 1197 | +{ |
|---|
| 1198 | + if (info) |
|---|
| 1199 | + mutex_unlock(&info->volt_adjust_mutex); |
|---|
| 1200 | +} |
|---|
| 1201 | +EXPORT_SYMBOL(rockchip_monitor_volt_adjust_unlock); |
|---|
| 1202 | + |
|---|
| 1203 | +static int rockchip_monitor_enable_opp_clk(struct device *dev, |
|---|
| 1204 | + struct rockchip_opp_info *opp_info) |
|---|
| 1205 | +{ |
|---|
| 1206 | + int ret = 0; |
|---|
| 1207 | + |
|---|
| 1208 | + if (!opp_info) |
|---|
| 1209 | + return 0; |
|---|
| 1210 | + |
|---|
| 1211 | + ret = clk_bulk_prepare_enable(opp_info->num_clks, opp_info->clks); |
|---|
| 1212 | + if (ret) { |
|---|
| 1213 | + dev_err(dev, "failed to enable opp clks\n"); |
|---|
| 1214 | + return ret; |
|---|
| 1215 | + } |
|---|
| 1050 | 1216 | |
|---|
| 1051 | 1217 | return 0; |
|---|
| 1052 | 1218 | } |
|---|
| 1053 | 1219 | |
|---|
| 1054 | | -static unsigned long monitor_freq_to_state(struct monitor_dev_info *info, |
|---|
| 1055 | | - unsigned long freq) |
|---|
| 1220 | +static void rockchip_monitor_disable_opp_clk(struct device *dev, |
|---|
| 1221 | + struct rockchip_opp_info *opp_info) |
|---|
| 1056 | 1222 | { |
|---|
| 1057 | | - unsigned long i = 0; |
|---|
| 1223 | + if (!opp_info) |
|---|
| 1224 | + return; |
|---|
| 1058 | 1225 | |
|---|
| 1059 | | - if (!info->freq_table) { |
|---|
| 1060 | | - dev_info(info->dev, "failed to get freq_table"); |
|---|
| 1061 | | - return 0; |
|---|
| 1062 | | - } |
|---|
| 1063 | | - |
|---|
| 1064 | | - for (i = 0; i < info->max_state; i++) { |
|---|
| 1065 | | - if (freq >= info->freq_table[i]) |
|---|
| 1066 | | - return i; |
|---|
| 1067 | | - } |
|---|
| 1068 | | - |
|---|
| 1069 | | - return info->max_state - 1; |
|---|
| 1226 | + clk_bulk_disable_unprepare(opp_info->num_clks, opp_info->clks); |
|---|
| 1070 | 1227 | } |
|---|
| 1071 | 1228 | |
|---|
| 1072 | | -static int monitor_temp_to_state(struct monitor_dev_info *info, |
|---|
| 1073 | | - int temp, unsigned long *state) |
|---|
| 1229 | +static int rockchip_monitor_set_opp(struct monitor_dev_info *info, |
|---|
| 1230 | + unsigned long old_freq, |
|---|
| 1231 | + unsigned long freq, |
|---|
| 1232 | + struct dev_pm_opp_supply *old_supply, |
|---|
| 1233 | + struct dev_pm_opp_supply *new_supply) |
|---|
| 1074 | 1234 | { |
|---|
| 1075 | | - unsigned long target_state, target_freq = 0; |
|---|
| 1076 | | - int i; |
|---|
| 1235 | + struct dev_pm_set_opp_data *data; |
|---|
| 1236 | + int size; |
|---|
| 1077 | 1237 | |
|---|
| 1078 | | - if (temp == THERMAL_TEMP_INVALID) |
|---|
| 1238 | + data = info->set_opp_data; |
|---|
| 1239 | + data->regulators = info->regulators; |
|---|
| 1240 | + data->regulator_count = info->regulator_count; |
|---|
| 1241 | + data->clk = info->clk; |
|---|
| 1242 | + data->dev = info->dev; |
|---|
| 1243 | + |
|---|
| 1244 | + data->old_opp.rate = old_freq; |
|---|
| 1245 | + size = sizeof(*old_supply) * info->regulator_count; |
|---|
| 1246 | + if (!old_supply) |
|---|
| 1247 | + memset(data->old_opp.supplies, 0, size); |
|---|
| 1248 | + else |
|---|
| 1249 | + memcpy(data->old_opp.supplies, old_supply, size); |
|---|
| 1250 | + |
|---|
| 1251 | + data->new_opp.rate = freq; |
|---|
| 1252 | + memcpy(data->new_opp.supplies, new_supply, size); |
|---|
| 1253 | + |
|---|
| 1254 | + return info->devp->set_opp(data); |
|---|
| 1255 | +} |
|---|
| 1256 | + |
|---|
| 1257 | +int rockchip_monitor_check_rate_volt(struct monitor_dev_info *info) |
|---|
| 1258 | +{ |
|---|
| 1259 | + struct device *dev = info->dev; |
|---|
| 1260 | + struct regulator *vdd_reg = NULL; |
|---|
| 1261 | + struct regulator *mem_reg = NULL; |
|---|
| 1262 | + struct rockchip_opp_info *opp_info = info->devp->opp_info; |
|---|
| 1263 | + struct dev_pm_opp *opp; |
|---|
| 1264 | + unsigned long old_rate, new_rate, new_volt, new_mem_volt; |
|---|
| 1265 | + int old_volt, old_mem_volt; |
|---|
| 1266 | + u32 target_rm = UINT_MAX; |
|---|
| 1267 | + bool is_set_clk = true; |
|---|
| 1268 | + bool is_set_rm = false; |
|---|
| 1269 | + int ret = 0; |
|---|
| 1270 | + |
|---|
| 1271 | + if (!info->regulators || !info->clk) |
|---|
| 1079 | 1272 | return 0; |
|---|
| 1080 | | - if (info->temp_freq_table) { |
|---|
| 1081 | | - for (i = 0; info->temp_freq_table[i].freq != UINT_MAX; i++) { |
|---|
| 1082 | | - if (temp > info->temp_freq_table[i].temp) |
|---|
| 1083 | | - target_freq = info->temp_freq_table[i].freq; |
|---|
| 1273 | + |
|---|
| 1274 | + mutex_lock(&info->volt_adjust_mutex); |
|---|
| 1275 | + |
|---|
| 1276 | + vdd_reg = info->regulators[0]; |
|---|
| 1277 | + old_rate = clk_get_rate(info->clk); |
|---|
| 1278 | + old_volt = regulator_get_voltage(vdd_reg); |
|---|
| 1279 | + if (info->regulator_count > 1) { |
|---|
| 1280 | + mem_reg = info->regulators[1]; |
|---|
| 1281 | + old_mem_volt = regulator_get_voltage(mem_reg); |
|---|
| 1282 | + } |
|---|
| 1283 | + |
|---|
| 1284 | + if (info->init_freq) { |
|---|
| 1285 | + new_rate = info->init_freq * 1000; |
|---|
| 1286 | + info->init_freq = 0; |
|---|
| 1287 | + } else { |
|---|
| 1288 | + new_rate = old_rate; |
|---|
| 1289 | + } |
|---|
| 1290 | + opp = dev_pm_opp_find_freq_ceil(dev, &new_rate); |
|---|
| 1291 | + if (IS_ERR(opp)) { |
|---|
| 1292 | + opp = dev_pm_opp_find_freq_floor(dev, &new_rate); |
|---|
| 1293 | + if (IS_ERR(opp)) { |
|---|
| 1294 | + ret = PTR_ERR(opp); |
|---|
| 1295 | + goto unlock; |
|---|
| 1084 | 1296 | } |
|---|
| 1085 | | - if (target_freq) |
|---|
| 1086 | | - *state = monitor_freq_to_state(info, |
|---|
| 1087 | | - target_freq * 1000); |
|---|
| 1088 | | - else |
|---|
| 1089 | | - *state = 0; |
|---|
| 1297 | + } |
|---|
| 1298 | + new_volt = opp->supplies[0].u_volt; |
|---|
| 1299 | + if (info->regulator_count > 1) |
|---|
| 1300 | + new_mem_volt = opp->supplies[1].u_volt; |
|---|
| 1301 | + dev_pm_opp_put(opp); |
|---|
| 1302 | + |
|---|
| 1303 | + if (old_rate == new_rate) { |
|---|
| 1304 | + if (info->regulator_count > 1) { |
|---|
| 1305 | + if (old_volt == new_volt && |
|---|
| 1306 | + new_mem_volt == old_mem_volt) |
|---|
| 1307 | + goto unlock; |
|---|
| 1308 | + } else if (old_volt == new_volt) { |
|---|
| 1309 | + goto unlock; |
|---|
| 1310 | + } |
|---|
| 1311 | + } |
|---|
| 1312 | + if (!new_volt || (info->regulator_count > 1 && !new_mem_volt)) |
|---|
| 1313 | + goto unlock; |
|---|
| 1314 | + |
|---|
| 1315 | + if (info->devp->set_opp) { |
|---|
| 1316 | + ret = rockchip_monitor_set_opp(info, old_rate, new_rate, |
|---|
| 1317 | + NULL, opp->supplies); |
|---|
| 1318 | + goto unlock; |
|---|
| 1090 | 1319 | } |
|---|
| 1091 | 1320 | |
|---|
| 1092 | | - if (info->status_min_limit) { |
|---|
| 1093 | | - target_freq = info->status_min_limit * 1000; |
|---|
| 1094 | | - target_state = monitor_freq_to_state(info, target_freq); |
|---|
| 1095 | | - if (*state > target_state) |
|---|
| 1096 | | - *state = target_state; |
|---|
| 1321 | + if (opp_info && opp_info->data && opp_info->data->set_read_margin) { |
|---|
| 1322 | + is_set_rm = true; |
|---|
| 1323 | + if (info->devp->type == MONITOR_TYPE_DEV) { |
|---|
| 1324 | + if (!pm_runtime_active(dev)) { |
|---|
| 1325 | + is_set_rm = false; |
|---|
| 1326 | + if (opp_info->scmi_clk) |
|---|
| 1327 | + is_set_clk = false; |
|---|
| 1328 | + } |
|---|
| 1329 | + } |
|---|
| 1097 | 1330 | } |
|---|
| 1331 | + rockchip_monitor_enable_opp_clk(dev, opp_info); |
|---|
| 1332 | + rockchip_get_read_margin(dev, opp_info, new_volt, &target_rm); |
|---|
| 1098 | 1333 | |
|---|
| 1099 | | - return 0; |
|---|
| 1334 | + dev_dbg(dev, "%s: %lu Hz --> %lu Hz\n", __func__, old_rate, new_rate); |
|---|
| 1335 | + if (new_rate >= old_rate) { |
|---|
| 1336 | + rockchip_set_intermediate_rate(dev, opp_info, info->clk, |
|---|
| 1337 | + old_rate, new_rate, |
|---|
| 1338 | + true, is_set_clk); |
|---|
| 1339 | + if (info->regulator_count > 1) { |
|---|
| 1340 | + ret = regulator_set_voltage(mem_reg, new_mem_volt, |
|---|
| 1341 | + INT_MAX); |
|---|
| 1342 | + if (ret) { |
|---|
| 1343 | + dev_err(dev, "%s: failed to set volt: %lu\n", |
|---|
| 1344 | + __func__, new_mem_volt); |
|---|
| 1345 | + goto restore_voltage; |
|---|
| 1346 | + } |
|---|
| 1347 | + } |
|---|
| 1348 | + ret = regulator_set_voltage(vdd_reg, new_volt, INT_MAX); |
|---|
| 1349 | + if (ret) { |
|---|
| 1350 | + dev_err(dev, "%s: failed to set volt: %lu\n", |
|---|
| 1351 | + __func__, new_volt); |
|---|
| 1352 | + goto restore_voltage; |
|---|
| 1353 | + } |
|---|
| 1354 | + rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm); |
|---|
| 1355 | + if (is_set_clk && clk_set_rate(info->clk, new_rate)) { |
|---|
| 1356 | + dev_err(dev, "%s: failed to set clock rate: %lu\n", |
|---|
| 1357 | + __func__, new_rate); |
|---|
| 1358 | + goto restore_rm; |
|---|
| 1359 | + } |
|---|
| 1360 | + } else { |
|---|
| 1361 | + rockchip_set_intermediate_rate(dev, opp_info, info->clk, |
|---|
| 1362 | + old_rate, new_rate, |
|---|
| 1363 | + false, is_set_clk); |
|---|
| 1364 | + rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm); |
|---|
| 1365 | + if (is_set_clk && clk_set_rate(info->clk, new_rate)) { |
|---|
| 1366 | + dev_err(dev, "%s: failed to set clock rate: %lu\n", |
|---|
| 1367 | + __func__, new_rate); |
|---|
| 1368 | + goto restore_rm; |
|---|
| 1369 | + } |
|---|
| 1370 | + ret = regulator_set_voltage(vdd_reg, new_volt, |
|---|
| 1371 | + INT_MAX); |
|---|
| 1372 | + if (ret) { |
|---|
| 1373 | + dev_err(dev, "%s: failed to set volt: %lu\n", |
|---|
| 1374 | + __func__, new_volt); |
|---|
| 1375 | + goto restore_freq; |
|---|
| 1376 | + } |
|---|
| 1377 | + if (info->regulator_count > 1) { |
|---|
| 1378 | + ret = regulator_set_voltage(mem_reg, new_mem_volt, |
|---|
| 1379 | + INT_MAX); |
|---|
| 1380 | + if (ret) { |
|---|
| 1381 | + dev_err(dev, "%s: failed to set volt: %lu\n", |
|---|
| 1382 | + __func__, new_mem_volt); |
|---|
| 1383 | + goto restore_freq; |
|---|
| 1384 | + } |
|---|
| 1385 | + } |
|---|
| 1386 | + } |
|---|
| 1387 | + goto disable_clk; |
|---|
| 1388 | + |
|---|
| 1389 | +restore_freq: |
|---|
| 1390 | + if (is_set_clk && clk_set_rate(info->clk, old_rate)) |
|---|
| 1391 | + dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n", |
|---|
| 1392 | + __func__, old_rate); |
|---|
| 1393 | +restore_rm: |
|---|
| 1394 | + rockchip_get_read_margin(dev, opp_info, old_volt, &target_rm); |
|---|
| 1395 | + rockchip_set_read_margin(dev, opp_info, target_rm, is_set_rm); |
|---|
| 1396 | +restore_voltage: |
|---|
| 1397 | + if (info->regulator_count > 1) |
|---|
| 1398 | + regulator_set_voltage(mem_reg, old_mem_volt, INT_MAX); |
|---|
| 1399 | + regulator_set_voltage(vdd_reg, old_volt, INT_MAX); |
|---|
| 1400 | +disable_clk: |
|---|
| 1401 | + rockchip_monitor_disable_opp_clk(dev, opp_info); |
|---|
| 1402 | +unlock: |
|---|
| 1403 | + mutex_unlock(&info->volt_adjust_mutex); |
|---|
| 1404 | + |
|---|
| 1405 | + return ret; |
|---|
| 1100 | 1406 | } |
|---|
| 1101 | | - |
|---|
| 1102 | | -int |
|---|
| 1103 | | -rockchip_system_monitor_adjust_cdev_state(struct thermal_cooling_device *cdev, |
|---|
| 1104 | | - int temp, unsigned long *state) |
|---|
| 1105 | | -{ |
|---|
| 1106 | | - struct monitor_dev_info *info; |
|---|
| 1107 | | - |
|---|
| 1108 | | - down_read(&mdev_list_sem); |
|---|
| 1109 | | - list_for_each_entry(info, &monitor_dev_list, node) { |
|---|
| 1110 | | - if (cdev->np != info->dev->of_node) |
|---|
| 1111 | | - continue; |
|---|
| 1112 | | - monitor_temp_to_state(info, temp, state); |
|---|
| 1113 | | - break; |
|---|
| 1114 | | - } |
|---|
| 1115 | | - up_read(&mdev_list_sem); |
|---|
| 1116 | | - |
|---|
| 1117 | | - return 0; |
|---|
| 1118 | | -} |
|---|
| 1119 | | -EXPORT_SYMBOL(rockchip_system_monitor_adjust_cdev_state); |
|---|
| 1407 | +EXPORT_SYMBOL(rockchip_monitor_check_rate_volt); |
|---|
| 1120 | 1408 | |
|---|
| 1121 | 1409 | struct monitor_dev_info * |
|---|
| 1122 | 1410 | rockchip_system_monitor_register(struct device *dev, |
|---|
| 1123 | 1411 | struct monitor_dev_profile *devp) |
|---|
| 1124 | 1412 | { |
|---|
| 1125 | 1413 | struct monitor_dev_info *info; |
|---|
| 1126 | | - struct devfreq *devfreq; |
|---|
| 1127 | | - int ret; |
|---|
| 1128 | 1414 | |
|---|
| 1129 | 1415 | if (!system_monitor) |
|---|
| 1130 | 1416 | return ERR_PTR(-ENOMEM); |
|---|
| 1417 | + |
|---|
| 1418 | + if (!devp) |
|---|
| 1419 | + return ERR_PTR(-EINVAL); |
|---|
| 1131 | 1420 | |
|---|
| 1132 | 1421 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
|---|
| 1133 | 1422 | if (!info) |
|---|
| .. | .. |
|---|
| 1135 | 1424 | info->dev = dev; |
|---|
| 1136 | 1425 | info->devp = devp; |
|---|
| 1137 | 1426 | |
|---|
| 1138 | | - ret = monitor_device_parse_dt(dev, info); |
|---|
| 1139 | | - if (ret) |
|---|
| 1140 | | - goto free_info; |
|---|
| 1427 | + mutex_init(&info->volt_adjust_mutex); |
|---|
| 1141 | 1428 | |
|---|
| 1142 | | - monitor_set_freq_table(dev, info); |
|---|
| 1143 | | - |
|---|
| 1144 | | - if (info->devp->type == MONITOR_TPYE_DEV && info->devp->data) { |
|---|
| 1145 | | - info->devfreq_nb.notifier_call = |
|---|
| 1146 | | - system_monitor_devfreq_notifier_call; |
|---|
| 1147 | | - devfreq = (struct devfreq *)info->devp->data; |
|---|
| 1148 | | - devm_devfreq_register_notifier(dev, devfreq, &info->devfreq_nb, |
|---|
| 1149 | | - DEVFREQ_POLICY_NOTIFIER); |
|---|
| 1429 | + rockchip_system_monitor_parse_supplies(dev, info); |
|---|
| 1430 | + if (monitor_device_parse_dt(dev, info)) { |
|---|
| 1431 | + rockchip_monitor_check_rate_volt(info); |
|---|
| 1432 | + devp->is_checked = true; |
|---|
| 1433 | + kfree(info->set_opp_data); |
|---|
| 1434 | + kfree(info); |
|---|
| 1435 | + return ERR_PTR(-EINVAL); |
|---|
| 1150 | 1436 | } |
|---|
| 1151 | 1437 | |
|---|
| 1438 | + rockchip_system_monitor_early_regulator_init(info); |
|---|
| 1152 | 1439 | rockchip_system_monitor_wide_temp_init(info); |
|---|
| 1153 | | - mutex_init(&info->volt_adjust_mutex); |
|---|
| 1440 | + rockchip_monitor_check_rate_volt(info); |
|---|
| 1441 | + devp->is_checked = true; |
|---|
| 1442 | + rockchip_system_monitor_freq_qos_requset(info); |
|---|
| 1154 | 1443 | |
|---|
| 1155 | 1444 | down_write(&mdev_list_sem); |
|---|
| 1156 | 1445 | list_add(&info->node, &monitor_dev_list); |
|---|
| 1157 | 1446 | up_write(&mdev_list_sem); |
|---|
| 1158 | 1447 | |
|---|
| 1159 | 1448 | return info; |
|---|
| 1160 | | - |
|---|
| 1161 | | -free_info: |
|---|
| 1162 | | - kfree(info); |
|---|
| 1163 | | - return ERR_PTR(-EINVAL); |
|---|
| 1164 | 1449 | } |
|---|
| 1165 | 1450 | EXPORT_SYMBOL(rockchip_system_monitor_register); |
|---|
| 1166 | 1451 | |
|---|
| 1167 | 1452 | void rockchip_system_monitor_unregister(struct monitor_dev_info *info) |
|---|
| 1168 | 1453 | { |
|---|
| 1169 | | - struct devfreq *devfreq; |
|---|
| 1170 | | - |
|---|
| 1171 | 1454 | if (!info) |
|---|
| 1172 | 1455 | return; |
|---|
| 1173 | 1456 | |
|---|
| .. | .. |
|---|
| 1175 | 1458 | list_del(&info->node); |
|---|
| 1176 | 1459 | up_write(&mdev_list_sem); |
|---|
| 1177 | 1460 | |
|---|
| 1178 | | - if (info->devp->type == MONITOR_TPYE_DEV && info->devp->data) { |
|---|
| 1179 | | - devfreq = (struct devfreq *)info->devp->data; |
|---|
| 1180 | | - devm_devfreq_unregister_notifier(info->dev, devfreq, |
|---|
| 1181 | | - &info->devfreq_nb, |
|---|
| 1182 | | - DEVFREQ_TRANSITION_NOTIFIER); |
|---|
| 1461 | + if (info->devp->type == MONITOR_TYPE_CPU) { |
|---|
| 1462 | + if (freq_qos_request_active(&info->max_temp_freq_req)) |
|---|
| 1463 | + freq_qos_remove_request(&info->max_temp_freq_req); |
|---|
| 1464 | + if (freq_qos_request_active(&info->min_sta_freq_req)) |
|---|
| 1465 | + freq_qos_remove_request(&info->min_sta_freq_req); |
|---|
| 1466 | + if (freq_qos_request_active(&info->max_sta_freq_req)) |
|---|
| 1467 | + freq_qos_remove_request(&info->max_sta_freq_req); |
|---|
| 1468 | + } else { |
|---|
| 1469 | + if (dev_pm_qos_request_active(&info->dev_max_freq_req)) |
|---|
| 1470 | + dev_pm_qos_remove_request(&info->dev_max_freq_req); |
|---|
| 1183 | 1471 | } |
|---|
| 1184 | 1472 | |
|---|
| 1185 | 1473 | kfree(info->low_temp_adjust_table); |
|---|
| 1186 | 1474 | kfree(info->opp_table); |
|---|
| 1187 | | - kfree(info->freq_table); |
|---|
| 1475 | + kfree(info->set_opp_data); |
|---|
| 1188 | 1476 | kfree(info); |
|---|
| 1189 | 1477 | } |
|---|
| 1190 | 1478 | EXPORT_SYMBOL(rockchip_system_monitor_unregister); |
|---|
| 1479 | + |
|---|
| 1480 | +int rockchip_system_monitor_register_notifier(struct notifier_block *nb) |
|---|
| 1481 | +{ |
|---|
| 1482 | + return blocking_notifier_chain_register(&system_monitor_notifier_list, nb); |
|---|
| 1483 | +} |
|---|
| 1484 | +EXPORT_SYMBOL(rockchip_system_monitor_register_notifier); |
|---|
| 1485 | + |
|---|
| 1486 | +void rockchip_system_monitor_unregister_notifier(struct notifier_block *nb) |
|---|
| 1487 | +{ |
|---|
| 1488 | + blocking_notifier_chain_unregister(&system_monitor_notifier_list, nb); |
|---|
| 1489 | +} |
|---|
| 1490 | +EXPORT_SYMBOL(rockchip_system_monitor_unregister_notifier); |
|---|
| 1491 | + |
|---|
| 1492 | +static int rockchip_system_monitor_temp_notify(int temp) |
|---|
| 1493 | +{ |
|---|
| 1494 | + struct system_monitor_event_data event_data; |
|---|
| 1495 | + int ret; |
|---|
| 1496 | + |
|---|
| 1497 | + event_data.temp = temp; |
|---|
| 1498 | + ret = blocking_notifier_call_chain(&system_monitor_notifier_list, |
|---|
| 1499 | + SYSTEM_MONITOR_CHANGE_TEMP, |
|---|
| 1500 | + (void *)&event_data); |
|---|
| 1501 | + |
|---|
| 1502 | + return notifier_to_errno(ret); |
|---|
| 1503 | +} |
|---|
| 1504 | + |
|---|
| 1505 | +static int notify_dummy(struct thermal_zone_device *tz, int trip) |
|---|
| 1506 | +{ |
|---|
| 1507 | + return 0; |
|---|
| 1508 | +} |
|---|
| 1509 | + |
|---|
| 1510 | +static struct thermal_governor thermal_gov_dummy = { |
|---|
| 1511 | + .name = "dummy", |
|---|
| 1512 | + .throttle = notify_dummy, |
|---|
| 1513 | +}; |
|---|
| 1191 | 1514 | |
|---|
| 1192 | 1515 | static int rockchip_system_monitor_parse_dt(struct system_monitor *monitor) |
|---|
| 1193 | 1516 | { |
|---|
| .. | .. |
|---|
| 1195 | 1518 | const char *tz_name, *buf = NULL; |
|---|
| 1196 | 1519 | |
|---|
| 1197 | 1520 | if (of_property_read_string(np, "rockchip,video-4k-offline-cpus", &buf)) |
|---|
| 1198 | | - cpumask_clear(&system_monitor->video_4k_offline_cpus); |
|---|
| 1521 | + cpumask_clear(&monitor->video_4k_offline_cpus); |
|---|
| 1199 | 1522 | else |
|---|
| 1200 | 1523 | cpulist_parse(buf, &monitor->video_4k_offline_cpus); |
|---|
| 1201 | 1524 | |
|---|
| .. | .. |
|---|
| 1221 | 1544 | system_monitor->offline_cpus_temp = INT_MAX; |
|---|
| 1222 | 1545 | of_property_read_u32(np, "rockchip,temp-hysteresis", |
|---|
| 1223 | 1546 | &system_monitor->temp_hysteresis); |
|---|
| 1547 | + |
|---|
| 1548 | + if (of_find_property(np, "rockchip,thermal-governor-dummy", NULL)) { |
|---|
| 1549 | + if (monitor->tz->governor->unbind_from_tz) |
|---|
| 1550 | + monitor->tz->governor->unbind_from_tz(monitor->tz); |
|---|
| 1551 | + monitor->tz->governor = &thermal_gov_dummy; |
|---|
| 1552 | + } |
|---|
| 1553 | + |
|---|
| 1224 | 1554 | out: |
|---|
| 1225 | 1555 | return 0; |
|---|
| 1226 | 1556 | } |
|---|
| .. | .. |
|---|
| 1246 | 1576 | cpumask_copy(&system_monitor->offline_cpus, &offline_cpus); |
|---|
| 1247 | 1577 | for_each_cpu(cpu, &system_monitor->offline_cpus) { |
|---|
| 1248 | 1578 | if (cpu_online(cpu)) |
|---|
| 1249 | | - cpu_down(cpu); |
|---|
| 1579 | + remove_cpu(cpu); |
|---|
| 1250 | 1580 | } |
|---|
| 1251 | 1581 | |
|---|
| 1252 | 1582 | cpumask_clear(&online_cpus); |
|---|
| .. | .. |
|---|
| 1256 | 1586 | if (cpumask_empty(&online_cpus)) |
|---|
| 1257 | 1587 | goto out; |
|---|
| 1258 | 1588 | for_each_cpu(cpu, &online_cpus) |
|---|
| 1259 | | - cpu_up(cpu); |
|---|
| 1589 | + add_cpu(cpu); |
|---|
| 1260 | 1590 | |
|---|
| 1261 | 1591 | out: |
|---|
| 1262 | 1592 | mutex_unlock(&cpu_on_off_mutex); |
|---|
| .. | .. |
|---|
| 1288 | 1618 | { |
|---|
| 1289 | 1619 | int temp, ret; |
|---|
| 1290 | 1620 | struct monitor_dev_info *info; |
|---|
| 1291 | | - static int last_temp = INT_MAX; |
|---|
| 1292 | 1621 | |
|---|
| 1293 | 1622 | ret = thermal_zone_get_temp(system_monitor->tz, &temp); |
|---|
| 1294 | 1623 | if (ret || temp == THERMAL_TEMP_INVALID) |
|---|
| .. | .. |
|---|
| 1296 | 1625 | |
|---|
| 1297 | 1626 | dev_dbg(system_monitor->dev, "temperature=%d\n", temp); |
|---|
| 1298 | 1627 | |
|---|
| 1299 | | - if (temp < last_temp && last_temp - temp <= 2000) |
|---|
| 1628 | + if (temp < system_monitor->last_temp && |
|---|
| 1629 | + system_monitor->last_temp - temp <= 2000) |
|---|
| 1300 | 1630 | goto out; |
|---|
| 1301 | | - last_temp = temp; |
|---|
| 1631 | + system_monitor->last_temp = temp; |
|---|
| 1632 | + |
|---|
| 1633 | + rockchip_system_monitor_temp_notify(temp); |
|---|
| 1302 | 1634 | |
|---|
| 1303 | 1635 | down_read(&mdev_list_sem); |
|---|
| 1304 | 1636 | list_for_each_entry(info, &monitor_dev_list, node) |
|---|
| .. | .. |
|---|
| 1324 | 1656 | unsigned long status) |
|---|
| 1325 | 1657 | { |
|---|
| 1326 | 1658 | unsigned int target_freq = 0; |
|---|
| 1327 | | - bool is_freq_fixed = false; |
|---|
| 1328 | | - int cpu; |
|---|
| 1659 | + |
|---|
| 1660 | + if (!freq_qos_request_active(&info->min_sta_freq_req)) |
|---|
| 1661 | + return; |
|---|
| 1662 | + if (!freq_qos_request_active(&info->max_sta_freq_req)) |
|---|
| 1663 | + return; |
|---|
| 1329 | 1664 | |
|---|
| 1330 | 1665 | if (status & SYS_STATUS_REBOOT) { |
|---|
| 1331 | | - info->status_min_limit = info->reboot_freq; |
|---|
| 1332 | | - info->status_max_limit = info->reboot_freq; |
|---|
| 1333 | | - info->is_status_freq_fixed = true; |
|---|
| 1334 | | - goto next; |
|---|
| 1666 | + freq_qos_update_request(&info->max_sta_freq_req, |
|---|
| 1667 | + info->reboot_freq); |
|---|
| 1668 | + freq_qos_update_request(&info->min_sta_freq_req, |
|---|
| 1669 | + info->reboot_freq); |
|---|
| 1670 | + return; |
|---|
| 1335 | 1671 | } |
|---|
| 1336 | 1672 | |
|---|
| 1337 | 1673 | if (info->video_4k_freq && (status & SYS_STATUS_VIDEO_4K)) |
|---|
| 1338 | 1674 | target_freq = info->video_4k_freq; |
|---|
| 1339 | | - if (target_freq == info->status_max_limit && |
|---|
| 1340 | | - info->is_status_freq_fixed == is_freq_fixed) |
|---|
| 1675 | + |
|---|
| 1676 | + if (target_freq == info->status_max_limit) |
|---|
| 1341 | 1677 | return; |
|---|
| 1342 | 1678 | info->status_max_limit = target_freq; |
|---|
| 1343 | | - info->is_status_freq_fixed = is_freq_fixed; |
|---|
| 1344 | | -next: |
|---|
| 1345 | | - cpu = cpumask_any(&info->devp->allowed_cpus); |
|---|
| 1346 | | - cpufreq_update_policy(cpu); |
|---|
| 1679 | + if (info->status_max_limit) |
|---|
| 1680 | + freq_qos_update_request(&info->max_sta_freq_req, |
|---|
| 1681 | + info->status_max_limit); |
|---|
| 1682 | + else |
|---|
| 1683 | + freq_qos_update_request(&info->max_sta_freq_req, |
|---|
| 1684 | + FREQ_QOS_MAX_DEFAULT_VALUE); |
|---|
| 1347 | 1685 | } |
|---|
| 1348 | 1686 | |
|---|
| 1349 | 1687 | static void rockchip_system_status_limit_freq(unsigned long status) |
|---|
| .. | .. |
|---|
| 1352 | 1690 | |
|---|
| 1353 | 1691 | down_read(&mdev_list_sem); |
|---|
| 1354 | 1692 | list_for_each_entry(info, &monitor_dev_list, node) { |
|---|
| 1355 | | - if (info->devp->type == MONITOR_TPYE_CPU) |
|---|
| 1693 | + if (info->devp->type == MONITOR_TYPE_CPU) |
|---|
| 1356 | 1694 | rockchip_system_status_cpu_limit_freq(info, status); |
|---|
| 1357 | 1695 | } |
|---|
| 1358 | 1696 | up_read(&mdev_list_sem); |
|---|
| .. | .. |
|---|
| 1386 | 1724 | return NOTIFY_OK; |
|---|
| 1387 | 1725 | } |
|---|
| 1388 | 1726 | |
|---|
| 1727 | +static int rockchip_system_monitor_set_cpu_uevent_suppress(bool is_suppress) |
|---|
| 1728 | +{ |
|---|
| 1729 | + struct monitor_dev_info *info; |
|---|
| 1730 | + struct cpufreq_policy *policy; |
|---|
| 1731 | + |
|---|
| 1732 | + list_for_each_entry(info, &monitor_dev_list, node) { |
|---|
| 1733 | + if (info->devp->type != MONITOR_TYPE_CPU) |
|---|
| 1734 | + continue; |
|---|
| 1735 | + policy = (struct cpufreq_policy *)info->devp->data; |
|---|
| 1736 | + if (!policy || !policy->cdev) |
|---|
| 1737 | + continue; |
|---|
| 1738 | + if (is_suppress) |
|---|
| 1739 | + dev_set_uevent_suppress(&policy->cdev->device, 1); |
|---|
| 1740 | + else |
|---|
| 1741 | + dev_set_uevent_suppress(&policy->cdev->device, 0); |
|---|
| 1742 | + } |
|---|
| 1743 | + |
|---|
| 1744 | + return 0; |
|---|
| 1745 | +} |
|---|
| 1746 | + |
|---|
| 1389 | 1747 | static int monitor_pm_notify(struct notifier_block *nb, |
|---|
| 1390 | 1748 | unsigned long mode, void *_unused) |
|---|
| 1391 | 1749 | { |
|---|
| .. | .. |
|---|
| 1394 | 1752 | case PM_RESTORE_PREPARE: |
|---|
| 1395 | 1753 | case PM_SUSPEND_PREPARE: |
|---|
| 1396 | 1754 | atomic_set(&monitor_in_suspend, 1); |
|---|
| 1755 | + rockchip_system_monitor_set_cpu_uevent_suppress(true); |
|---|
| 1397 | 1756 | break; |
|---|
| 1398 | 1757 | case PM_POST_HIBERNATION: |
|---|
| 1399 | 1758 | case PM_POST_RESTORE: |
|---|
| .. | .. |
|---|
| 1401 | 1760 | if (system_monitor->tz) |
|---|
| 1402 | 1761 | rockchip_system_monitor_thermal_update(); |
|---|
| 1403 | 1762 | atomic_set(&monitor_in_suspend, 0); |
|---|
| 1763 | + rockchip_system_monitor_set_cpu_uevent_suppress(false); |
|---|
| 1764 | + system_monitor->last_temp = INT_MAX; |
|---|
| 1404 | 1765 | break; |
|---|
| 1405 | 1766 | default: |
|---|
| 1406 | 1767 | break; |
|---|
| .. | .. |
|---|
| 1410 | 1771 | |
|---|
| 1411 | 1772 | static struct notifier_block monitor_pm_nb = { |
|---|
| 1412 | 1773 | .notifier_call = monitor_pm_notify, |
|---|
| 1413 | | -}; |
|---|
| 1414 | | - |
|---|
| 1415 | | -static int rockchip_monitor_cpufreq_policy_notifier(struct notifier_block *nb, |
|---|
| 1416 | | - unsigned long event, |
|---|
| 1417 | | - void *data) |
|---|
| 1418 | | -{ |
|---|
| 1419 | | - struct monitor_dev_info *info; |
|---|
| 1420 | | - struct cpufreq_policy *policy = data; |
|---|
| 1421 | | - int cpu = policy->cpu; |
|---|
| 1422 | | - unsigned int limit_freq = UINT_MAX; |
|---|
| 1423 | | - |
|---|
| 1424 | | - if (event != CPUFREQ_ADJUST) |
|---|
| 1425 | | - return NOTIFY_OK; |
|---|
| 1426 | | - |
|---|
| 1427 | | - down_read(&mdev_list_sem); |
|---|
| 1428 | | - list_for_each_entry(info, &monitor_dev_list, node) { |
|---|
| 1429 | | - if (info->devp->type != MONITOR_TPYE_CPU) |
|---|
| 1430 | | - continue; |
|---|
| 1431 | | - if (!cpumask_test_cpu(cpu, &info->devp->allowed_cpus)) |
|---|
| 1432 | | - continue; |
|---|
| 1433 | | - |
|---|
| 1434 | | - if (info->wide_temp_limit) { |
|---|
| 1435 | | - if (limit_freq > info->wide_temp_limit / 1000) |
|---|
| 1436 | | - limit_freq = info->wide_temp_limit / 1000; |
|---|
| 1437 | | - } |
|---|
| 1438 | | - if (!system_monitor->boosted && |
|---|
| 1439 | | - info->status_max_limit && |
|---|
| 1440 | | - limit_freq > info->status_max_limit) |
|---|
| 1441 | | - limit_freq = info->status_max_limit; |
|---|
| 1442 | | - |
|---|
| 1443 | | - if (info->is_status_freq_fixed) { |
|---|
| 1444 | | - cpufreq_verify_within_limits(policy, limit_freq, |
|---|
| 1445 | | - limit_freq); |
|---|
| 1446 | | - dev_info(info->dev, "min=%u, max=%u\n", policy->min, |
|---|
| 1447 | | - policy->max); |
|---|
| 1448 | | - } else if (limit_freq < policy->max) { |
|---|
| 1449 | | - cpufreq_verify_within_limits(policy, 0, limit_freq); |
|---|
| 1450 | | - } |
|---|
| 1451 | | - } |
|---|
| 1452 | | - up_read(&mdev_list_sem); |
|---|
| 1453 | | - |
|---|
| 1454 | | - return NOTIFY_OK; |
|---|
| 1455 | | -} |
|---|
| 1456 | | - |
|---|
| 1457 | | -static struct notifier_block rockchip_monitor_cpufreq_policy_nb = { |
|---|
| 1458 | | - .notifier_call = rockchip_monitor_cpufreq_policy_notifier, |
|---|
| 1459 | 1774 | }; |
|---|
| 1460 | 1775 | |
|---|
| 1461 | 1776 | static int rockchip_monitor_reboot_notifier(struct notifier_block *nb, |
|---|
| .. | .. |
|---|
| 1477 | 1792 | { |
|---|
| 1478 | 1793 | struct fb_event *event = ptr; |
|---|
| 1479 | 1794 | |
|---|
| 1480 | | - switch (action) { |
|---|
| 1481 | | - case FB_EARLY_EVENT_BLANK: |
|---|
| 1482 | | - switch (*((int *)event->data)) { |
|---|
| 1483 | | - case FB_BLANK_UNBLANK: |
|---|
| 1484 | | - rockchip_clear_system_status(SYS_STATUS_SUSPEND); |
|---|
| 1485 | | - break; |
|---|
| 1486 | | - default: |
|---|
| 1487 | | - break; |
|---|
| 1488 | | - } |
|---|
| 1795 | + if (action != FB_EVENT_BLANK) |
|---|
| 1796 | + return NOTIFY_OK; |
|---|
| 1797 | + |
|---|
| 1798 | + switch (*((int *)event->data)) { |
|---|
| 1799 | + case FB_BLANK_UNBLANK: |
|---|
| 1800 | + rockchip_clear_system_status(SYS_STATUS_SUSPEND); |
|---|
| 1489 | 1801 | break; |
|---|
| 1490 | | - case FB_EVENT_BLANK: |
|---|
| 1491 | | - switch (*((int *)event->data)) { |
|---|
| 1492 | | - case FB_BLANK_POWERDOWN: |
|---|
| 1493 | | - rockchip_set_system_status(SYS_STATUS_SUSPEND); |
|---|
| 1494 | | - break; |
|---|
| 1495 | | - default: |
|---|
| 1496 | | - break; |
|---|
| 1497 | | - } |
|---|
| 1802 | + case FB_BLANK_POWERDOWN: |
|---|
| 1803 | + rockchip_set_system_status(SYS_STATUS_SUSPEND); |
|---|
| 1498 | 1804 | break; |
|---|
| 1499 | 1805 | default: |
|---|
| 1500 | 1806 | break; |
|---|
| .. | .. |
|---|
| 1517 | 1823 | case EBC_OFF: |
|---|
| 1518 | 1824 | rockchip_set_system_status(SYS_STATUS_LOW_POWER); |
|---|
| 1519 | 1825 | break; |
|---|
| 1520 | | - case EBC_FB_BLANK: |
|---|
| 1521 | | - rockchip_set_system_status(SYS_STATUS_SUSPEND); |
|---|
| 1522 | | - break; |
|---|
| 1523 | | - case EBC_FB_UNBLANK: |
|---|
| 1524 | | - rockchip_clear_system_status(SYS_STATUS_SUSPEND); |
|---|
| 1525 | | - break; |
|---|
| 1526 | 1826 | default: |
|---|
| 1527 | 1827 | break; |
|---|
| 1528 | 1828 | } |
|---|
| .. | .. |
|---|
| 1533 | 1833 | static struct notifier_block rockchip_monitor_ebc_nb = { |
|---|
| 1534 | 1834 | .notifier_call = rockchip_eink_devfs_notifier, |
|---|
| 1535 | 1835 | }; |
|---|
| 1836 | + |
|---|
| 1837 | +static void system_monitor_early_min_volt_function(struct work_struct *work) |
|---|
| 1838 | +{ |
|---|
| 1839 | + struct monitor_dev_info *info; |
|---|
| 1840 | + struct regulator_dev *rdev; |
|---|
| 1841 | + int min_uV, max_uV; |
|---|
| 1842 | + int ret; |
|---|
| 1843 | + |
|---|
| 1844 | + down_read(&mdev_list_sem); |
|---|
| 1845 | + list_for_each_entry(info, &monitor_dev_list, node) { |
|---|
| 1846 | + if (!info->early_min_volt || !info->early_reg) |
|---|
| 1847 | + continue; |
|---|
| 1848 | + rdev = info->early_reg->rdev; |
|---|
| 1849 | + min_uV = rdev->constraints->min_uV; |
|---|
| 1850 | + max_uV = rdev->constraints->max_uV; |
|---|
| 1851 | + ret = regulator_set_voltage(info->early_reg, min_uV, max_uV); |
|---|
| 1852 | + if (ret) |
|---|
| 1853 | + dev_err(&rdev->dev, |
|---|
| 1854 | + "%s: failed to set volt\n", __func__); |
|---|
| 1855 | + regulator_put(info->early_reg); |
|---|
| 1856 | + } |
|---|
| 1857 | + up_read(&mdev_list_sem); |
|---|
| 1858 | +} |
|---|
| 1859 | + |
|---|
| 1860 | +static DECLARE_DELAYED_WORK(system_monitor_early_min_volt_work, |
|---|
| 1861 | + system_monitor_early_min_volt_function); |
|---|
| 1536 | 1862 | |
|---|
| 1537 | 1863 | static int rockchip_system_monitor_probe(struct platform_device *pdev) |
|---|
| 1538 | 1864 | { |
|---|
| .. | .. |
|---|
| 1555 | 1881 | |
|---|
| 1556 | 1882 | rockchip_system_monitor_parse_dt(system_monitor); |
|---|
| 1557 | 1883 | if (system_monitor->tz) { |
|---|
| 1884 | + system_monitor->last_temp = INT_MAX; |
|---|
| 1558 | 1885 | INIT_DELAYED_WORK(&system_monitor->thermal_work, |
|---|
| 1559 | 1886 | rockchip_system_monitor_thermal_check); |
|---|
| 1560 | 1887 | mod_delayed_work(system_freezable_wq, |
|---|
| .. | .. |
|---|
| 1569 | 1896 | if (register_pm_notifier(&monitor_pm_nb)) |
|---|
| 1570 | 1897 | dev_err(dev, "failed to register suspend notifier\n"); |
|---|
| 1571 | 1898 | |
|---|
| 1572 | | - cpufreq_register_notifier(&rockchip_monitor_cpufreq_policy_nb, |
|---|
| 1573 | | - CPUFREQ_POLICY_NOTIFIER); |
|---|
| 1574 | | - |
|---|
| 1575 | 1899 | register_reboot_notifier(&rockchip_monitor_reboot_nb); |
|---|
| 1576 | 1900 | |
|---|
| 1577 | 1901 | if (fb_register_client(&rockchip_monitor_fb_nb)) |
|---|
| .. | .. |
|---|
| 1579 | 1903 | |
|---|
| 1580 | 1904 | ebc_register_notifier(&rockchip_monitor_ebc_nb); |
|---|
| 1581 | 1905 | |
|---|
| 1906 | + schedule_delayed_work(&system_monitor_early_min_volt_work, |
|---|
| 1907 | + msecs_to_jiffies(30000)); |
|---|
| 1908 | + |
|---|
| 1582 | 1909 | dev_info(dev, "system monitor probe\n"); |
|---|
| 1583 | 1910 | |
|---|
| 1584 | 1911 | return 0; |
|---|