• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */
2 /*
3  * Copyright (C) 2019, Fuzhou Rockchip Electronics Co., Ltd
4  */
5 
6 #ifndef __SOC_ROCKCHIP_SYSTEM_MONITOR_H
7 #define __SOC_ROCKCHIP_SYSTEM_MONITOR_H
8 
9 enum monitor_dev_type {
10 	MONITOR_TPYE_CPU = 0,	/* CPU */
11 	MONITOR_TPYE_DEV,	/* GPU, NPU, DMC, and so on */
12 };
13 
14 struct volt_adjust_table {
15 	unsigned int min;	/* Minimum frequency in MHz */
16 	unsigned int max;	/* Maximum frequency in MHz */
17 	int volt;		/* Voltage in microvolt */
18 };
19 
20 struct temp_freq_table {
21 	int temp;		/* millicelsius */
22 	unsigned int freq;	/* KHz */
23 };
24 
25 /**
26  * struct temp_opp_table - System monitor device OPP description structure
27  * @rate:		Frequency in hertz
28  * @volt:		Target voltage in microvolt
29  * @low_temp_volt:	Target voltage when low temperature, in microvolt
30  * @max_volt:		Maximum voltage in microvolt
31  */
32 struct temp_opp_table {
33 	unsigned long rate;
34 	unsigned long volt;
35 	unsigned long low_temp_volt;
36 	unsigned long max_volt;
37 };
38 
39 /**
40  * struct monitor_dev_info - structure for a system monitor device
41  * @dev:		Device registered by system monitor
42  * @low_temp_adjust_table:	Voltage margin for different OPPs when lowe
43  *				temperature
44  * @opp_table:		Frequency and voltage information of device
45  * @devp:		Device-specific system monitor profile
46  * @node:		Node in monitor_dev_list
47  * @high_limit_table:	Limit maximum frequency at different temperature,
48  *			but the frequency is also changed by thermal framework.
49  * @volt_adjust_mutex:	A mutex to protect changing voltage.
50  * @max_temp_freq_req:	CPU maximum frequency constraint changed according
51  *			to temperature.
52  * @min_sta_freq_req:   CPU minimum frequency constraint changed according
53  *			to system status.
54  * @max_sta_freq_req:   CPU maximum frequency constraint changed according
55  *			to system status.
56  * @dev_max_freq_req:	Devices maximum frequency constraint changed according
57  *			to temperature.
58  * @low_limit:		Limit maximum frequency when low temperature, in Hz
59  * @high_limit:		Limit maximum frequency when high temperature, in Hz
60  * @max_volt:		Maximum voltage in microvolt
61  * @low_temp_min_volt:	Minimum voltage of OPPs when low temperature, in
62  *			microvolt
63  * @high_temp_max_volt:	Maximum voltage when high temperature, in microvolt
64  * @wide_temp_limit:	Target maximum frequency when low or high temperature,
65  *			in Hz
66  * @video_4k_freq:	Maximum frequency when paly 4k video, in KHz
67  * @reboot_freq:	Limit maximum and minimum frequency when reboot, in KHz
68  * @status_min_limit:	Minimum frequency of some status frequency, in KHz
69  * @status_max_limit:	Minimum frequency of all status frequency, in KHz
70  * @low_temp:		Low temperature trip point, in millicelsius
71  * @high_temp:		High temperature trip point, in millicelsius
72  * @temp_hysteresis:	A low hysteresis value on low_temp, in millicelsius
73  * @is_low_temp:	True if current temperature less than low_temp
74  * @is_high_temp:	True if current temperature greater than high_temp
75  * @is_low_temp_enabled:	True if device node contains low temperature
76  *				configuration
77  * @is_status_freq_fixed:	True if enter into some status
78  */
79 struct monitor_dev_info {
80 	struct device *dev;
81 	struct volt_adjust_table *low_temp_adjust_table;
82 	struct temp_opp_table *opp_table;
83 	struct monitor_dev_profile *devp;
84 	struct list_head node;
85 	struct temp_freq_table *high_limit_table;
86 	struct mutex volt_adjust_mutex;
87 	struct freq_qos_request max_temp_freq_req;
88 	struct freq_qos_request min_sta_freq_req;
89 	struct freq_qos_request max_sta_freq_req;
90 	struct dev_pm_qos_request dev_max_freq_req;
91 	struct regulator *early_reg;
92 	struct regulator **regulators;
93 	struct clk *clk;
94 	unsigned long low_limit;
95 	unsigned long high_limit;
96 	unsigned long max_volt;
97 	unsigned long low_temp_min_volt;
98 	unsigned long high_temp_max_volt;
99 	unsigned int video_4k_freq;
100 	unsigned int reboot_freq;
101 	unsigned int init_freq;
102 	unsigned int status_min_limit;
103 	unsigned int status_max_limit;
104 	unsigned int early_min_volt;
105 	unsigned int regulator_count;
106 	int low_temp;
107 	int high_temp;
108 	int temp_hysteresis;
109 	bool is_low_temp;
110 	bool is_high_temp;
111 	bool is_low_temp_enabled;
112 };
113 
114 struct monitor_dev_profile {
115 	enum monitor_dev_type type;
116 	void *data;
117 	bool is_checked;
118 	int (*low_temp_adjust)(struct monitor_dev_info *info, bool is_low);
119 	int (*high_temp_adjust)(struct monitor_dev_info *info, bool is_low);
120 	int (*update_volt)(struct monitor_dev_info *info, bool is_set_clk);
121 	struct cpumask allowed_cpus;
122 	struct rockchip_opp_info *opp_info;
123 };
124 
125 #if IS_ENABLED(CONFIG_ROCKCHIP_SYSTEM_MONITOR)
126 struct monitor_dev_info *
127 rockchip_system_monitor_register(struct device *dev,
128 				 struct monitor_dev_profile *devp);
129 void rockchip_system_monitor_unregister(struct monitor_dev_info *info);
130 int rockchip_monitor_cpu_low_temp_adjust(struct monitor_dev_info *info,
131 					 bool is_low);
132 int rockchip_monitor_cpu_high_temp_adjust(struct monitor_dev_info *info,
133 					  bool is_high);
134 void rockchip_monitor_volt_adjust_lock(struct monitor_dev_info *info);
135 void rockchip_monitor_volt_adjust_unlock(struct monitor_dev_info *info);
136 int rockchip_monitor_check_rate_volt(struct monitor_dev_info *info,
137 				     bool is_set_clk);
138 int rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info *info,
139 					 bool is_low);
140 int rockchip_monitor_dev_high_temp_adjust(struct monitor_dev_info *info,
141 					  bool is_high);
142 int rockchip_monitor_suspend_low_temp_adjust(int cpu);
143 #else
144 static inline struct monitor_dev_info *
rockchip_system_monitor_register(struct device * dev,struct monitor_dev_profile * devp)145 rockchip_system_monitor_register(struct device *dev,
146 				 struct monitor_dev_profile *devp)
147 {
148 	return ERR_PTR(-ENOTSUPP);
149 };
150 
151 static inline void
rockchip_system_monitor_unregister(struct monitor_dev_info * info)152 rockchip_system_monitor_unregister(struct monitor_dev_info *info)
153 {
154 }
155 
156 static inline int
rockchip_monitor_cpu_low_temp_adjust(struct monitor_dev_info * info,bool is_low)157 rockchip_monitor_cpu_low_temp_adjust(struct monitor_dev_info *info, bool is_low)
158 {
159 	return 0;
160 };
161 
162 static inline int
rockchip_monitor_cpu_high_temp_adjust(struct monitor_dev_info * info,bool is_high)163 rockchip_monitor_cpu_high_temp_adjust(struct monitor_dev_info *info,
164 				      bool is_high)
165 {
166 	return 0;
167 };
168 
169 static inline void
rockchip_monitor_volt_adjust_lock(struct monitor_dev_info * info)170 rockchip_monitor_volt_adjust_lock(struct monitor_dev_info *info)
171 {
172 }
173 
174 static inline void
rockchip_monitor_volt_adjust_unlock(struct monitor_dev_info * info)175 rockchip_monitor_volt_adjust_unlock(struct monitor_dev_info *info)
176 {
177 }
178 
179 static inline int
rockchip_monitor_check_rate_volt(struct monitor_dev_info * info,bool is_set_clk)180 rockchip_monitor_check_rate_volt(struct monitor_dev_info *info, bool is_set_clk)
181 {
182 	return 0;
183 }
184 
185 static inline int
rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info * info,bool is_low)186 rockchip_monitor_dev_low_temp_adjust(struct monitor_dev_info *info, bool is_low)
187 {
188 	return 0;
189 };
190 
191 static inline int
rockchip_monitor_dev_high_temp_adjust(struct monitor_dev_info * info,bool is_high)192 rockchip_monitor_dev_high_temp_adjust(struct monitor_dev_info *info,
193 				      bool is_high)
194 {
195 	return 0;
196 };
197 
rockchip_monitor_suspend_low_temp_adjust(int cpu)198 static inline int rockchip_monitor_suspend_low_temp_adjust(int cpu)
199 {
200 	return 0;
201 };
202 
203 #endif /* CONFIG_ROCKCHIP_SYSTEM_MONITOR */
204 
205 #endif
206