tscpu_settings.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. #include "mt_gpufreq.h"
  2. /*=============================================================
  3. * Genernal
  4. *=============================================================*/
  5. #define MIN(_a_, _b_) ((_a_) > (_b_) ? (_b_) : (_a_))
  6. #define MAX(_a_, _b_) ((_a_) > (_b_) ? (_a_) : (_b_))
  7. #define _BIT_(_bit_) (unsigned)(1 << (_bit_))
  8. #define _BITMASK_(_bits_) (((unsigned) -1 >> (31 - ((1) ? _bits_))) & ~((1U << ((0) ? _bits_)) - 1))
  9. /*=============================================================
  10. * CONFIG (SW related)
  11. *=============================================================*/
  12. #define THERMAL_GET_AHB_BUS_CLOCK (0)
  13. #define THERMAL_PERFORMANCE_PROFILE (0)
  14. /* 1: turn on GPIO toggle monitor; 0: turn off */
  15. #define THERMAL_GPIO_OUT_TOGGLE (0)
  16. /* 1: turn on adaptive AP cooler; 0: turn off */
  17. #define CPT_ADAPTIVE_AP_COOLER (1)
  18. /* 1: turn on supports to MET logging; 0: turn off */
  19. #define CONFIG_SUPPORT_MET_MTKTSCPU (0)
  20. /* Thermal controller HW filtering function. Only 1, 2, 4, 8, 16 are valid values,
  21. they means one reading is a avg of X samples */
  22. #define THERMAL_CONTROLLER_HW_FILTER (1) /* 1, 2, 4, 8, 16 */
  23. /* 1: turn on thermal controller HW thermal protection; 0: turn off */
  24. #define THERMAL_CONTROLLER_HW_TP (1)
  25. /* 1: turn on fast polling in this sw module; 0: turn off */
  26. #define MTKTSCPU_FAST_POLLING (1)
  27. #if CPT_ADAPTIVE_AP_COOLER
  28. #define MAX_CPT_ADAPTIVE_COOLERS (3)
  29. #define THERMAL_HEADROOM (0)
  30. #define CONTINUOUS_TM (1)
  31. #define DYNAMIC_GET_GPU_POWER (1)
  32. /* 1: turn on precise power budgeting; 0: turn off */
  33. #define PRECISE_HYBRID_POWER_BUDGET (0)
  34. #endif
  35. /* 1: thermal driver fast polling, use hrtimer; 0: turn off */
  36. /* #define THERMAL_DRV_FAST_POLL_HRTIMER (1) */
  37. /* 1: thermal driver update temp to MET directly, use hrtimer; 0: turn off */
  38. #define THERMAL_DRV_UPDATE_TEMP_DIRECT_TO_MET (1)
  39. #define THERMAL_INIT_VALUE (0xDA1)
  40. /*=============================================================
  41. * Chip related
  42. *=============================================================*/
  43. /* double check */
  44. #define TS_CONFIGURE TS_CON1_TM /* depend on CPU design */
  45. #define TS_CONFIGURE_P TS_CON1_P /* depend on CPU design */
  46. #define TS_TURN_ON 0xFFFFFFCF /* turn on TS_CON1[5:4] 2'b 00 11001111 -> 0xCF ~(0x30) */
  47. #define TS_TURN_OFF 0x00000030 /* turn off thermal */
  48. /* chip dependent */
  49. #define ADDRESS_INDEX_0 43 /* 0x102061A0 */
  50. #define ADDRESS_INDEX_1 42 /* 0x1020619C */
  51. #define ADDRESS_INDEX_2 44 /* 0x102061A4 */
  52. #define CLEAR_TEMP 26111
  53. /* TSCON1 bit table */
  54. #define TSCON0_bit_6_7_00 0x00 /* TSCON0[7:6]=2'b00 */
  55. #define TSCON0_bit_6_7_01 0x40 /* TSCON0[7:6]=2'b01 */
  56. #define TSCON0_bit_6_7_10 0x80 /* TSCON0[7:6]=2'b10 */
  57. #define TSCON0_bit_6_7_11 0xc0 /* TSCON0[7:6]=2'b11 */
  58. #define TSCON0_bit_6_7_MASK 0xc0
  59. #define TSCON1_bit_4_5_00 0x00 /* TSCON1[5:4]=2'b00 */
  60. #define TSCON1_bit_4_5_01 0x10 /* TSCON1[5:4]=2'b01 */
  61. #define TSCON1_bit_4_5_10 0x20 /* TSCON1[5:4]=2'b10 */
  62. #define TSCON1_bit_4_5_11 0x30 /* TSCON1[5:4]=2'b11 */
  63. #define TSCON1_bit_4_5_MASK 0x30
  64. #define TSCON1_bit_0_2_000 0x00 /* TSCON1[2:0]=3'b000 */
  65. #define TSCON1_bit_0_2_001 0x01 /* TSCON1[2:0]=3'b001 */
  66. #define TSCON1_bit_0_2_010 0x02 /* TSCON1[2:0]=3'b010 */
  67. #define TSCON1_bit_0_2_011 0x03 /* TSCON1[2:0]=3'b011 */
  68. #define TSCON1_bit_0_2_100 0x04 /* TSCON1[2:0]=3'b100 */
  69. #define TSCON1_bit_0_2_101 0x05 /* TSCON1[2:0]=3'b101 */
  70. #define TSCON1_bit_0_2_110 0x06 /* TSCON1[2:0]=3'b110 */
  71. #define TSCON1_bit_0_2_111 0x07 /* TSCON1[2:0]=3'b111 */
  72. #define TSCON1_bit_0_2_MASK 0x07
  73. /* ADC value to mcu */
  74. /* chip dependent */
  75. #define TEMPADC_MCU1 ((0xC0&TSCON0_bit_6_7_00)|(0x07&TSCON1_bit_0_2_000))
  76. #define TEMPADC_MCU2 ((0xC0&TSCON0_bit_6_7_00)|(0x07&TSCON1_bit_0_2_001))
  77. #define TEMPADC_MCU3 ((0xC0&TSCON0_bit_6_7_00)|(0x07&TSCON1_bit_0_2_010))
  78. #define TEMPADC_MCU4 ((0xC0&TSCON0_bit_6_7_00)|(0x07&TSCON1_bit_0_2_011))
  79. #define TEMPADC_ABB ((0xC0&TSCON0_bit_6_7_01)|(0x07&TSCON1_bit_0_2_000))
  80. #define TS_FILL(n) {#n, n}
  81. #define TS_LEN_ARRAY(name) (sizeof(name)/sizeof(name[0]))
  82. #define MAX_TS_NAME 20
  83. #define CPU_COOLER_NUM 34
  84. #define MTK_TS_CPU_RT (0)
  85. #ifdef CONFIG_MTK_RAM_CONSOLE
  86. #define CONFIG_THERMAL_AEE_RR_REC (1)
  87. #else
  88. #define CONFIG_THERMAL_AEE_RR_REC (0)
  89. #endif
  90. /*=============================================================
  91. *REG ACCESS
  92. *=============================================================*/
  93. #define thermal_readl(addr) DRV_Reg32(addr)
  94. #define thermal_writel(addr, val) mt_reg_sync_writel((val), ((void *)addr))
  95. #define thermal_setl(addr, val) mt_reg_sync_writel(thermal_readl(addr) | (val), ((void *)addr))
  96. #define thermal_clrl(addr, val) mt_reg_sync_writel(thermal_readl(addr) & ~(val), ((void *)addr))
  97. #define MTKTSCPU_TEMP_CRIT 120000 /* 120.000 degree Celsius */
  98. #define y_curr_repeat_times 1
  99. #define THERMAL_NAME "mtk-thermal"
  100. #define TS_MS_TO_NS(x) (x * 1000 * 1000)
  101. #if THERMAL_GET_AHB_BUS_CLOCK
  102. #define THERMAL_MODULE_SW_CG_SET (therm_clk_infracfg_ao_base + 0x88)
  103. #define THERMAL_MODULE_SW_CG_CLR (therm_clk_infracfg_ao_base + 0x8C)
  104. #define THERMAL_MODULE_SW_CG_STA (therm_clk_infracfg_ao_base + 0x94)
  105. #define THERMAL_CG (therm_clk_infracfg_ao_base + 0x80)
  106. #define THERMAL_DCM (therm_clk_infracfg_ao_base + 0x70)
  107. #endif
  108. /*=============================================================
  109. *LOG
  110. *=============================================================*/
  111. #define tscpu_dprintk(fmt, args...) \
  112. do { \
  113. if (tscpu_debug_log) { \
  114. pr_debug("[Power/CPU_Thermal]" fmt, ##args); \
  115. } \
  116. } while (0)
  117. #define tscpu_printk(fmt, args...) pr_debug("[Power/CPU_Thermal]" fmt, ##args)
  118. #define tscpu_warn(fmt, args...) pr_warn("[Power/CPU_Thermal]" fmt, ##args)
  119. /*=============================================================
  120. * Structures
  121. *=============================================================*/
  122. /* Align with thermal_sensor_name struct @ Mt_thermal.h */
  123. typedef enum thermal_sensor_enum {
  124. MCU1 = 0,
  125. MCU2,
  126. MCU3,
  127. MCU4,
  128. ABB,
  129. ENUM_MAX,
  130. } ts_e;
  131. typedef struct {
  132. char ts_name[MAX_TS_NAME];
  133. ts_e type;
  134. } thermal_sensor_t;
  135. typedef struct {
  136. thermal_sensor_t ts[ENUM_MAX];
  137. int ts_number;
  138. } bank_t;
  139. #if (CONFIG_THERMAL_AEE_RR_REC == 1)
  140. enum thermal_state {
  141. TSCPU_SUSPEND = 0,
  142. TSCPU_RESUME = 1,
  143. TSCPU_NORMAL = 2,
  144. TSCPU_INIT = 3
  145. };
  146. #endif
  147. struct mtk_cpu_power_info {
  148. unsigned int cpufreq_khz;
  149. unsigned int cpufreq_ncpu;
  150. unsigned int cpufreq_power;
  151. };
  152. /*=============================================================
  153. * Shared variables
  154. *=============================================================*/
  155. /*In src/mtk_tc.c*/
  156. extern int tscpu_debug_log;
  157. extern const struct of_device_id mt_thermal_of_match[2];
  158. extern int tscpu_bank_ts[THERMAL_BANK_NUM][ENUM_MAX];
  159. extern int tscpu_bank_ts_r[THERMAL_BANK_NUM][ENUM_MAX]; /* raw data */
  160. extern bank_t tscpu_g_bank[THERMAL_BANK_NUM];
  161. extern int tscpu_polling_trip_temp1;
  162. extern int tscpu_polling_trip_temp2;
  163. extern int tscpu_polling_factor1;
  164. extern int tscpu_polling_factor2;
  165. #if MTKTSCPU_FAST_POLLING
  166. /* Combined fast_polling_trip_temp and fast_polling_factor,
  167. it means polling_delay will be 1/5 of original interval
  168. after mtktscpu reports > 65C w/o exit point */
  169. extern int fast_polling_trip_temp;
  170. extern int fast_polling_trip_temp_high;
  171. extern int fast_polling_factor;
  172. extern int tscpu_cur_fp_factor;
  173. extern int tscpu_next_fp_factor;
  174. #endif
  175. /*In common/thermal_zones/mtk_ts_cpu.c*/
  176. extern int Num_of_GPU_OPP;
  177. extern struct mt_gpufreq_power_table_info *mtk_gpu_power;
  178. extern int tscpu_read_curr_temp;
  179. #if MTKTSCPU_FAST_POLLING
  180. extern int tscpu_cur_fp_factor;
  181. #endif
  182. #if !defined(CONFIG_MTK_CLKMGR)
  183. extern struct clk *therm_main; /* main clock for Thermal */
  184. #endif
  185. #if CPT_ADAPTIVE_AP_COOLER
  186. extern int tscpu_g_curr_temp;
  187. extern int tscpu_g_prev_temp;
  188. #if (THERMAL_HEADROOM == 1) || (CONTINUOUS_TM == 1)
  189. extern int bts_cur_temp; /* in mtk_ts_bts.c */
  190. #endif
  191. #endif
  192. #ifdef CONFIG_OF
  193. extern u32 thermal_irq_number;
  194. extern void __iomem *thermal_base;
  195. extern void __iomem *auxadc_ts_base;
  196. extern void __iomem *infracfg_ao_base;
  197. extern void __iomem *apmixed_base;
  198. extern void __iomem *INFRACFG_AO_base;
  199. extern int thermal_phy_base;
  200. extern int auxadc_ts_phy_base;
  201. extern int apmixed_phy_base;
  202. extern int pericfg_phy_base;
  203. #endif
  204. extern char *adaptive_cooler_name;
  205. /*common/coolers/mtk_cooler_atm.c*/
  206. extern unsigned int adaptive_cpu_power_limit;
  207. extern unsigned int adaptive_gpu_power_limit;
  208. extern int TARGET_TJS[MAX_CPT_ADAPTIVE_COOLERS];
  209. extern unsigned int get_adaptive_power_limit(int type);
  210. /*common/coolers/mtk_cooler_dtm.c*/
  211. extern unsigned int static_cpu_power_limit;
  212. extern unsigned int static_gpu_power_limit;
  213. extern int tscpu_cpu_dmips[CPU_COOLER_NUM];
  214. /*=============================================================
  215. * Shared functions
  216. *=============================================================*/
  217. /*In common/thermal_zones/mtk_ts_cpu.c*/
  218. extern void tscpu_print_all_temperature(int isDprint);
  219. extern void tscpu_update_tempinfo(void);
  220. #if THERMAL_GPIO_OUT_TOGGLE
  221. void tscpu_set_GPIO_toggle_for_monitor(void);
  222. #endif
  223. extern void tscpu_thermal_tempADCPNP(int adc, int order);
  224. extern int tscpu_thermal_ADCValueOfMcu(ts_e type);
  225. extern void tscpu_thermal_enable_all_periodoc_sensing_point(thermal_bank_name bank_num);
  226. extern void tscpu_update_tempinfo(void);
  227. extern int tscpu_max_temperature(void);
  228. /*In common/thermal_zones/mtk_ts.c*/
  229. extern int get_io_reg_base(void);
  230. extern void tscpu_config_all_tc_hw_protect(int temperature, int temperature2);
  231. extern void tscpu_reset_thermal(void);
  232. extern void tscpu_thermal_initial_all_bank(void);
  233. extern int tscpu_switch_bank(thermal_bank_name bank);
  234. extern void tscpu_thermal_read_bank_temp(thermal_bank_name bank, ts_e type, int order);
  235. extern void tscpu_thermal_cal_prepare(void);
  236. extern void tscpu_thermal_cal_prepare_2(U32 ret);
  237. extern irqreturn_t tscpu_thermal_all_bank_interrupt_handler(int irq, void *dev_id);
  238. extern int tscpu_thermal_clock_on(void);
  239. extern int tscpu_thermal_clock_off(void);
  240. extern int tscpu_read_temperature_info(struct seq_file *m, void *v);
  241. extern int tscpu_thermal_fast_init(void);
  242. extern int tscpu_get_curr_temp(void);
  243. /*
  244. In drivers/misc/mediatek/gpu/hal/mtk_gpu_utility.c
  245. It's not our api, ask them to provide header file
  246. */
  247. extern bool mtk_get_gpu_loading(unsigned int *pLoading);
  248. /*
  249. In drivers/misc/mediatek/auxadc/mt_auxadc.c
  250. It's not our api, ask them to provide header file
  251. */
  252. extern int IMM_IsAdcInitReady(void);
  253. /*aee related*/
  254. #if (CONFIG_THERMAL_AEE_RR_REC == 1)
  255. extern void aee_rr_rec_thermal_temp1(u8 val);
  256. extern void aee_rr_rec_thermal_temp2(u8 val);
  257. extern void aee_rr_rec_thermal_temp3(u8 val);
  258. extern void aee_rr_rec_thermal_temp4(u8 val);
  259. extern void aee_rr_rec_thermal_temp5(u8 val);
  260. extern void aee_rr_rec_thermal_status(u8 val);
  261. extern u8 aee_rr_curr_thermal_temp1(void);
  262. extern u8 aee_rr_curr_thermal_temp2(void);
  263. extern u8 aee_rr_curr_thermal_temp3(void);
  264. extern u8 aee_rr_curr_thermal_temp4(void);
  265. extern u8 aee_rr_curr_thermal_temp5(void);
  266. extern u8 aee_rr_curr_thermal_status(void);
  267. #endif