| .. | .. |
|---|
| 6 | 6 | #ifndef __SOC_ROCKCHIP_SYSTEM_MONITOR_H |
|---|
| 7 | 7 | #define __SOC_ROCKCHIP_SYSTEM_MONITOR_H |
|---|
| 8 | 8 | |
|---|
| 9 | +#include <linux/pm_opp.h> |
|---|
| 10 | +#include <linux/pm_qos.h> |
|---|
| 11 | +#include <linux/regulator/consumer.h> |
|---|
| 12 | + |
|---|
| 9 | 13 | enum monitor_dev_type { |
|---|
| 10 | | - MONITOR_TPYE_CPU = 0, /* CPU */ |
|---|
| 11 | | - MONITOR_TPYE_DEV, /* GPU, NPU, DMC, and so on */ |
|---|
| 14 | + MONITOR_TYPE_CPU = 0, /* CPU */ |
|---|
| 15 | + MONITOR_TYPE_DEV, /* GPU, NPU, DMC, and so on */ |
|---|
| 16 | +}; |
|---|
| 17 | + |
|---|
| 18 | +enum system_monitor_event_type { |
|---|
| 19 | + SYSTEM_MONITOR_CHANGE_TEMP = 0, |
|---|
| 20 | +}; |
|---|
| 21 | + |
|---|
| 22 | +struct system_monitor_event_data { |
|---|
| 23 | + int temp; |
|---|
| 12 | 24 | }; |
|---|
| 13 | 25 | |
|---|
| 14 | 26 | struct volt_adjust_table { |
|---|
| .. | .. |
|---|
| 26 | 38 | * struct temp_opp_table - System monitor device OPP description structure |
|---|
| 27 | 39 | * @rate: Frequency in hertz |
|---|
| 28 | 40 | * @volt: Target voltage in microvolt |
|---|
| 41 | + * @mem_volt: Target voltage for memory in microvolt |
|---|
| 29 | 42 | * @low_temp_volt: Target voltage when low temperature, in microvolt |
|---|
| 43 | + * @low_temp_mem_volt: Target voltage for memory when low temperature, |
|---|
| 44 | + * in microvolt |
|---|
| 30 | 45 | * @max_volt: Maximum voltage in microvolt |
|---|
| 46 | + * @max_mem_volt: Maximum voltage for memory in microvolt |
|---|
| 31 | 47 | */ |
|---|
| 32 | 48 | struct temp_opp_table { |
|---|
| 33 | 49 | unsigned long rate; |
|---|
| 34 | 50 | unsigned long volt; |
|---|
| 51 | + unsigned long mem_volt; |
|---|
| 35 | 52 | unsigned long low_temp_volt; |
|---|
| 53 | + unsigned long low_temp_mem_volt; |
|---|
| 36 | 54 | unsigned long max_volt; |
|---|
| 55 | + unsigned long max_mem_volt; |
|---|
| 37 | 56 | }; |
|---|
| 38 | 57 | |
|---|
| 39 | 58 | /** |
|---|
| 40 | 59 | * struct monitor_dev_info - structure for a system monitor device |
|---|
| 41 | 60 | * @dev: Device registered by system monitor |
|---|
| 42 | | - * @devfreq_nb: Notifier block used to notify devfreq object |
|---|
| 43 | | - * that it should reevaluate operable frequencies |
|---|
| 44 | 61 | * @low_temp_adjust_table: Voltage margin for different OPPs when lowe |
|---|
| 45 | 62 | * temperature |
|---|
| 46 | 63 | * @opp_table: Frequency and voltage information of device |
|---|
| 47 | 64 | * @devp: Device-specific system monitor profile |
|---|
| 48 | 65 | * @node: Node in monitor_dev_list |
|---|
| 49 | | - * @temp_freq_table: Maximum frequency at different temperature and the |
|---|
| 50 | | - * frequency will not be changed by thermal framework. |
|---|
| 51 | 66 | * @high_limit_table: Limit maximum frequency at different temperature, |
|---|
| 52 | 67 | * but the frequency is also changed by thermal framework. |
|---|
| 53 | 68 | * @volt_adjust_mutex: A mutex to protect changing voltage. |
|---|
| 69 | + * @max_temp_freq_req: CPU maximum frequency constraint changed according |
|---|
| 70 | + * to temperature. |
|---|
| 71 | + * @min_sta_freq_req: CPU minimum frequency constraint changed according |
|---|
| 72 | + * to system status. |
|---|
| 73 | + * @max_sta_freq_req: CPU maximum frequency constraint changed according |
|---|
| 74 | + * to system status. |
|---|
| 75 | + * @dev_max_freq_req: Devices maximum frequency constraint changed according |
|---|
| 76 | + * to temperature. |
|---|
| 54 | 77 | * @low_limit: Limit maximum frequency when low temperature, in Hz |
|---|
| 55 | 78 | * @high_limit: Limit maximum frequency when high temperature, in Hz |
|---|
| 56 | 79 | * @max_volt: Maximum voltage in microvolt |
|---|
| .. | .. |
|---|
| 63 | 86 | * @reboot_freq: Limit maximum and minimum frequency when reboot, in KHz |
|---|
| 64 | 87 | * @status_min_limit: Minimum frequency of some status frequency, in KHz |
|---|
| 65 | 88 | * @status_max_limit: Minimum frequency of all status frequency, in KHz |
|---|
| 66 | | - * @freq_table: Optional list of frequencies in descending order |
|---|
| 67 | | - * @max_state: The size of freq_table |
|---|
| 68 | 89 | * @low_temp: Low temperature trip point, in millicelsius |
|---|
| 69 | 90 | * @high_temp: High temperature trip point, in millicelsius |
|---|
| 70 | 91 | * @temp_hysteresis: A low hysteresis value on low_temp, in millicelsius |
|---|
| .. | .. |
|---|
| 76 | 97 | */ |
|---|
| 77 | 98 | struct monitor_dev_info { |
|---|
| 78 | 99 | struct device *dev; |
|---|
| 79 | | - struct notifier_block devfreq_nb; |
|---|
| 80 | 100 | struct volt_adjust_table *low_temp_adjust_table; |
|---|
| 81 | 101 | struct temp_opp_table *opp_table; |
|---|
| 82 | 102 | struct monitor_dev_profile *devp; |
|---|
| 83 | 103 | struct list_head node; |
|---|
| 84 | | - struct temp_freq_table *temp_freq_table; |
|---|
| 85 | 104 | struct temp_freq_table *high_limit_table; |
|---|
| 86 | 105 | struct mutex volt_adjust_mutex; |
|---|
| 106 | + struct freq_qos_request max_temp_freq_req; |
|---|
| 107 | + struct freq_qos_request min_sta_freq_req; |
|---|
| 108 | + struct freq_qos_request max_sta_freq_req; |
|---|
| 109 | + struct dev_pm_qos_request dev_max_freq_req; |
|---|
| 110 | + struct regulator *early_reg; |
|---|
| 111 | + struct regulator **regulators; |
|---|
| 112 | + struct dev_pm_set_opp_data *set_opp_data; |
|---|
| 113 | + struct clk *clk; |
|---|
| 87 | 114 | unsigned long low_limit; |
|---|
| 88 | 115 | unsigned long high_limit; |
|---|
| 89 | 116 | unsigned long max_volt; |
|---|
| 90 | 117 | unsigned long low_temp_min_volt; |
|---|
| 91 | 118 | unsigned long high_temp_max_volt; |
|---|
| 92 | | - unsigned long wide_temp_limit; |
|---|
| 93 | 119 | unsigned int video_4k_freq; |
|---|
| 94 | 120 | unsigned int reboot_freq; |
|---|
| 121 | + unsigned int init_freq; |
|---|
| 95 | 122 | unsigned int status_min_limit; |
|---|
| 96 | 123 | unsigned int status_max_limit; |
|---|
| 97 | | - unsigned long *freq_table; |
|---|
| 98 | | - unsigned int max_state; |
|---|
| 124 | + unsigned int early_min_volt; |
|---|
| 125 | + unsigned int regulator_count; |
|---|
| 99 | 126 | int low_temp; |
|---|
| 100 | 127 | int high_temp; |
|---|
| 101 | 128 | int temp_hysteresis; |
|---|
| 102 | 129 | bool is_low_temp; |
|---|
| 103 | 130 | bool is_high_temp; |
|---|
| 104 | 131 | bool is_low_temp_enabled; |
|---|
| 105 | | - bool is_status_freq_fixed; |
|---|
| 106 | | - bool boosted; |
|---|
| 107 | 132 | }; |
|---|
| 108 | 133 | |
|---|
| 109 | 134 | struct monitor_dev_profile { |
|---|
| 110 | 135 | enum monitor_dev_type type; |
|---|
| 111 | 136 | void *data; |
|---|
| 112 | | - int (*low_temp_adjust_volt)(struct monitor_dev_info *info); |
|---|
| 137 | + bool is_checked; |
|---|
| 113 | 138 | int (*low_temp_adjust)(struct monitor_dev_info *info, bool is_low); |
|---|
| 114 | 139 | int (*high_temp_adjust)(struct monitor_dev_info *info, bool is_low); |
|---|
| 140 | + int (*update_volt)(struct monitor_dev_info *info); |
|---|
| 141 | + int (*set_opp)(struct dev_pm_set_opp_data *data); |
|---|
| 115 | 142 | struct cpumask allowed_cpus; |
|---|
| 143 | + struct rockchip_opp_info *opp_info; |
|---|
| 116 | 144 | }; |
|---|
| 117 | 145 | |
|---|
| 118 | | -#if IS_ENABLED(CONFIG_ROCKCHIP_SYSTEM_MONITOR) |
|---|
| 146 | +#if IS_REACHABLE(CONFIG_ROCKCHIP_SYSTEM_MONITOR) |
|---|
| 119 | 147 | struct monitor_dev_info * |
|---|
| 120 | 148 | rockchip_system_monitor_register(struct device *dev, |
|---|
| 121 | 149 | struct monitor_dev_profile *devp); |
|---|
| .. | .. |
|---|
| 124 | 152 | bool is_low); |
|---|
| 125 | 153 | int rockchip_monitor_cpu_high_temp_adjust(struct monitor_dev_info *info, |
|---|
| 126 | 154 | bool is_high); |
|---|
| 155 | +void rockchip_monitor_volt_adjust_lock(struct monitor_dev_info *info); |
|---|
| 156 | +void rockchip_monitor_volt_adjust_unlock(struct monitor_dev_info *info); |
|---|
| 157 | +int rockchip_monitor_check_rate_volt(struct monitor_dev_info *info); |
|---|
| 127 | 158 | int rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info *info, |
|---|
| 128 | 159 | bool is_low); |
|---|
| 129 | 160 | int rockchip_monitor_dev_high_temp_adjust(struct monitor_dev_info *info, |
|---|
| 130 | 161 | bool is_high); |
|---|
| 131 | 162 | int rockchip_monitor_suspend_low_temp_adjust(int cpu); |
|---|
| 132 | | -int |
|---|
| 133 | | -rockchip_system_monitor_adjust_cdev_state(struct thermal_cooling_device *cdev, |
|---|
| 134 | | - int temp, unsigned long *state); |
|---|
| 135 | | -int rockchip_monitor_opp_set_rate(struct monitor_dev_info *info, |
|---|
| 136 | | - unsigned long target_freq); |
|---|
| 137 | | -void rockchip_monitor_set_boosted(void); |
|---|
| 138 | | -void rockchip_monitor_clear_boosted(void); |
|---|
| 163 | +int rockchip_system_monitor_register_notifier(struct notifier_block *nb); |
|---|
| 164 | +void rockchip_system_monitor_unregister_notifier(struct notifier_block *nb); |
|---|
| 139 | 165 | #else |
|---|
| 140 | 166 | static inline struct monitor_dev_info * |
|---|
| 141 | 167 | rockchip_system_monitor_register(struct device *dev, |
|---|
| .. | .. |
|---|
| 162 | 188 | return 0; |
|---|
| 163 | 189 | }; |
|---|
| 164 | 190 | |
|---|
| 191 | +static inline void |
|---|
| 192 | +rockchip_monitor_volt_adjust_lock(struct monitor_dev_info *info) |
|---|
| 193 | +{ |
|---|
| 194 | +} |
|---|
| 195 | + |
|---|
| 196 | +static inline void |
|---|
| 197 | +rockchip_monitor_volt_adjust_unlock(struct monitor_dev_info *info) |
|---|
| 198 | +{ |
|---|
| 199 | +} |
|---|
| 200 | + |
|---|
| 201 | +static inline int |
|---|
| 202 | +rockchip_monitor_check_rate_volt(struct monitor_dev_info *info) |
|---|
| 203 | +{ |
|---|
| 204 | + return 0; |
|---|
| 205 | +} |
|---|
| 206 | + |
|---|
| 165 | 207 | static inline int |
|---|
| 166 | 208 | rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info *info, bool is_low) |
|---|
| 167 | 209 | { |
|---|
| .. | .. |
|---|
| 181 | 223 | }; |
|---|
| 182 | 224 | |
|---|
| 183 | 225 | static inline int |
|---|
| 184 | | -rockchip_system_monitor_adjust_cdev_state(struct thermal_cooling_device *cdev, |
|---|
| 185 | | - int temp, unsigned long *state) |
|---|
| 226 | +rockchip_system_monitor_register_notifier(struct notifier_block *nb) |
|---|
| 186 | 227 | { |
|---|
| 187 | 228 | return 0; |
|---|
| 188 | | -} |
|---|
| 229 | +}; |
|---|
| 189 | 230 | |
|---|
| 190 | | -static inline int rockchip_monitor_opp_set_rate(struct monitor_dev_info *info, |
|---|
| 191 | | - unsigned long target_freq) |
|---|
| 231 | +static inline void |
|---|
| 232 | +rockchip_system_monitor_unregister_notifier(struct notifier_block *nb) |
|---|
| 192 | 233 | { |
|---|
| 193 | | - return 0; |
|---|
| 194 | | -} |
|---|
| 195 | | -static inline void rockchip_monitor_set_boosted(void) {}; |
|---|
| 196 | | -static inline void rockchip_monitor_set_boosted(void) {}; |
|---|
| 234 | +}; |
|---|
| 197 | 235 | #endif /* CONFIG_ROCKCHIP_SYSTEM_MONITOR */ |
|---|
| 198 | 236 | |
|---|
| 199 | 237 | #endif |
|---|