mtk_ts_wmt.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  1. #include <linux/version.h>
  2. #include <linux/thermal.h>
  3. #include <linux/proc_fs.h>
  4. #include <linux/seq_file.h>
  5. #include <asm/uaccess.h>
  6. /* #include "wmt_tm.h" */
  7. #include <mt-plat/mtk_thermal_monitor.h>
  8. #include <linux/timer.h>
  9. #include <linux/pid.h>
  10. /* For using net dev + */
  11. #include <linux/netdevice.h>
  12. /* For using net dev - */
  13. #include <mt-plat/mtk_wcn_cmb_stub.h>
  14. #include <mt-plat/aee.h>
  15. #include "mach/mt_thermal.h"
  16. #include <linux/uidgid.h>
  17. #include <linux/slab.h>
  18. /*=============================================================
  19. *Weak functions
  20. *=============================================================*/
  21. int __attribute__ ((weak))
  22. mtk_wcn_cmb_stub_query_ctrl(void)
  23. {
  24. pr_err("E_WF: %s doesn't exist\n", __func__);
  25. return 0;
  26. }
  27. /*=============================================================*/
  28. static kuid_t uid = KUIDT_INIT(0);
  29. static kgid_t gid = KGIDT_INIT(1000);
  30. static int wmt_tm_debug_log;
  31. #define wmt_tm_dprintk(fmt, args...) \
  32. do { \
  33. if (wmt_tm_debug_log) \
  34. pr_debug("[Power/WMT_Thermal]" fmt, ##args); \
  35. } while (0)
  36. #define wmt_tm_printk(fmt, args...) \
  37. pr_debug("[Power/WMT_Thermal]" fmt, ##args)
  38. #define wmt_tm_info(fmt, args...) \
  39. pr_debug("[Power/WMT_Thermal]" fmt, ##args)
  40. struct linux_thermal_ctrl_if {
  41. int kernel_mode;
  42. int interval;
  43. struct thermal_zone_device *thz_dev;
  44. struct thermal_cooling_device *cl_dev;
  45. struct thermal_cooling_device *cl_pa1_dev;
  46. struct thermal_cooling_device *cl_pa2_dev;
  47. struct thermal_cooling_device *cl_pa3_dev;
  48. };
  49. #if 0
  50. struct wmt_thermal_ctrl_if {
  51. struct wmt_thermal_ctrl_ops ops;
  52. };
  53. #endif
  54. typedef struct wmt_tm {
  55. struct linux_thermal_ctrl_if linux_if;
  56. /* struct wmt_thermal_ctrl_if wmt_if; */
  57. } wmt_tm_t;
  58. struct wmt_stats {
  59. unsigned long pre_time;
  60. unsigned long pre_tx_bytes;
  61. };
  62. #define NR_TS_SENSORS 4
  63. static int (*ts_get_temp_wrap[4]) (void) = {
  64. mtk_wcn_cmb_stub_query_ctrl, /* 0 is for WMT sensor */
  65. mtkts_get_ts1_temp, mtkts_get_ts2_temp, mtkts_get_ts3_temp};
  66. static struct timer_list wmt_stats_timer;
  67. static struct wmt_stats wmt_stats_info;
  68. static unsigned long pre_time;
  69. static unsigned long tx_throughput;
  70. /*New Wifi throttling Algo+*/
  71. /* over_up_time * polling interval > up_duration --> throttling */
  72. static unsigned int over_up_time; /* polling time */
  73. static unsigned int up_duration = 30; /* sec */
  74. static unsigned int up_denominator = 2;
  75. static unsigned int up_numerator = 1;
  76. /* below_low_time * polling interval > low_duration --> throttling */
  77. static unsigned int below_low_time; /* polling time */
  78. static unsigned int low_duration = 10; /* sec */
  79. static unsigned int low_denominator = 2;
  80. static unsigned int low_numerator = 3;
  81. static unsigned int low_rst_time;
  82. static unsigned int low_rst_max = 3;
  83. /*New Wifi throttling Algo-*/
  84. #define MAX_LEN 256
  85. #define COOLER_THRO_NUM 3
  86. #define COOLER_NUM 10
  87. #define ONE_MBITS_PER_SEC 1000
  88. static unsigned int tm_pid;
  89. static unsigned int tm_input_pid;
  90. static unsigned int tm_wfd_stat;
  91. /* static unsigned int wifi_in_soc = 0; */
  92. static struct task_struct g_task;
  93. static struct task_struct *pg_task = &g_task;
  94. /* +Cooler info+ */
  95. static int g_num_trip = COOLER_THRO_NUM + 1;
  96. static char g_bind0[20] = "mtktswmt-pa1";
  97. static char g_bind1[20] = "mtktswmt-pa2";
  98. static char g_bind2[20] = "mtktswmt-pa3";
  99. static char g_bind3[20] = "mtktswmt-sysrst";
  100. static char g_bind4[20] = { 0 };
  101. static char g_bind5[20] = { 0 };
  102. static char g_bind6[20] = { 0 };
  103. static char g_bind7[20] = { 0 };
  104. static char g_bind8[20] = { 0 };
  105. static char g_bind9[20] = { 0 };
  106. /**
  107. * If curr_temp >= polling_trip_temp1, use interval
  108. * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, use interval*polling_factor1
  109. * else, use interval*polling_factor2
  110. */
  111. static int polling_trip_temp1 = 40000;
  112. static int polling_trip_temp2 = 20000;
  113. static int polling_factor1 = 5;
  114. static int polling_factor2 = 10;
  115. static unsigned int cl_dev_state;
  116. static unsigned int cl_pa1_dev_state;
  117. static unsigned int cl_pa2_dev_state;
  118. /*static unsigned int cl_pa3_dev_state =0;*/
  119. static unsigned int g_trip_temp[COOLER_NUM] = { 85000, 85000, 85000, 85000, 0, 0, 0, 0, 0, 0 };
  120. /*static int g_thro[COOLER_THRO_NUM] = {10 * ONE_MBITS_PER_SEC, 5 * ONE_MBITS_PER_SEC, 1 * ONE_MBITS_PER_SEC};*/
  121. static int g_thermal_trip[COOLER_NUM] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  122. /* -Cooler info- */
  123. wmt_tm_t g_wmt_tm;
  124. wmt_tm_t *pg_wmt_tm = &g_wmt_tm;
  125. static int wmt_thz_bind(struct thermal_zone_device *, struct thermal_cooling_device *);
  126. static int wmt_thz_unbind(struct thermal_zone_device *, struct thermal_cooling_device *);
  127. static int wmt_thz_get_temp(struct thermal_zone_device *, unsigned long *);
  128. static int wmt_thz_get_mode(struct thermal_zone_device *, enum thermal_device_mode *);
  129. static int wmt_thz_set_mode(struct thermal_zone_device *, enum thermal_device_mode);
  130. static int wmt_thz_get_trip_type(struct thermal_zone_device *, int, enum thermal_trip_type *);
  131. static int wmt_thz_get_trip_temp(struct thermal_zone_device *, int, unsigned long *);
  132. static int wmt_thz_get_crit_temp(struct thermal_zone_device *, unsigned long *);
  133. static int wmt_cl_get_max_state(struct thermal_cooling_device *, unsigned long *);
  134. static int wmt_cl_get_cur_state(struct thermal_cooling_device *, unsigned long *);
  135. static int wmt_cl_set_cur_state(struct thermal_cooling_device *, unsigned long);
  136. static int wmt_cl_pa1_get_max_state(struct thermal_cooling_device *, unsigned long *);
  137. static int wmt_cl_pa1_get_cur_state(struct thermal_cooling_device *, unsigned long *);
  138. static int wmt_cl_pa1_set_cur_state(struct thermal_cooling_device *, unsigned long);
  139. static int wmt_cl_pa2_get_max_state(struct thermal_cooling_device *, unsigned long *);
  140. static int wmt_cl_pa2_get_cur_state(struct thermal_cooling_device *, unsigned long *);
  141. static int wmt_cl_pa2_set_cur_state(struct thermal_cooling_device *, unsigned long);
  142. static int wmt_send_signal(int level);
  143. #ifdef NEVER
  144. static int wmt_cl_pa3_get_max_state(struct thermal_cooling_device *, unsigned long *);
  145. static int wmt_cl_pa3_get_cur_state(struct thermal_cooling_device *, unsigned long *);
  146. static int wmt_cl_pa3_set_cur_state(struct thermal_cooling_device *, unsigned long);
  147. #endif /* NEVER */
  148. static struct thermal_zone_device_ops wmt_thz_dev_ops = {
  149. .bind = wmt_thz_bind,
  150. .unbind = wmt_thz_unbind,
  151. .get_temp = wmt_thz_get_temp,
  152. .get_mode = wmt_thz_get_mode,
  153. .set_mode = wmt_thz_set_mode,
  154. .get_trip_type = wmt_thz_get_trip_type,
  155. .get_trip_temp = wmt_thz_get_trip_temp,
  156. .get_crit_temp = wmt_thz_get_crit_temp,
  157. };
  158. static struct thermal_cooling_device_ops mtktspa_cooling_sysrst_ops = {
  159. .get_max_state = wmt_cl_get_max_state,
  160. .get_cur_state = wmt_cl_get_cur_state,
  161. .set_cur_state = wmt_cl_set_cur_state,
  162. };
  163. static struct thermal_cooling_device_ops mtktspa_cooling_pa1_ops = {
  164. .get_max_state = wmt_cl_pa1_get_max_state,
  165. .get_cur_state = wmt_cl_pa1_get_cur_state,
  166. .set_cur_state = wmt_cl_pa1_set_cur_state,
  167. };
  168. static struct thermal_cooling_device_ops mtktspa_cooling_pa2_ops = {
  169. .get_max_state = wmt_cl_pa2_get_max_state,
  170. .get_cur_state = wmt_cl_pa2_get_cur_state,
  171. .set_cur_state = wmt_cl_pa2_set_cur_state,
  172. };
  173. #ifdef NEVER
  174. static struct thermal_cooling_device_ops mtktspa_cooling_pa3_ops = {
  175. .get_max_state = wmt_cl_pa3_get_max_state,
  176. .get_cur_state = wmt_cl_pa3_get_cur_state,
  177. .set_cur_state = wmt_cl_pa3_set_cur_state,
  178. };
  179. #endif /* NEVER */
  180. #define init_wifi_tput_ratio 100
  181. /* Interal usage */
  182. /* these two are in milli degree C */
  183. static int g_curr_temp;
  184. static int g_prev_temp;
  185. static int wifi_target_tj = 120000;
  186. static int wifi_target_offset = 1000;
  187. static int cpu_wifi_target_tj_offset = 10000;
  188. static int WIFI_TARGET_TJ_HIGH;
  189. static int WIFI_TARGET_TJ_LOW;
  190. static int g_limit_tput = -1;
  191. static unsigned int cl_dev_adp_cpu_state_active;
  192. /* parameter from adb shell */
  193. static int wifi_throttle_version = 1; /* 0: for old WiFi algorithm. 1: for HRA/ATR */
  194. static int wmt_wifi_target_tj = 120000;
  195. static int wmt_wifi_target_offset = 1000;
  196. static int tj_stable_range = 1000;
  197. /* 0: wifi last (default) 1: wifi first 2: no throttle wifi 3: independent 4: not share target tj */
  198. static int resource_allocator_policy = 4;
  199. static int min_wifi_tput_ratio = 40;
  200. static int max_wifi_tput_ratio = 200;
  201. static int min_wifi_tput = 1000;
  202. static int tt_wifi_high = 50; /* initial value: assume 1 degreeC for temp. <=> 1 unit for wifi_tput_ratio(0~100) */
  203. static int tt_wifi_low = 50;
  204. static int tp_wifi_rise = 10000;
  205. static int tp_wifi_fall = 10000;
  206. static int triggered; /* wt2 */
  207. static int sensor_select = 3; /* select TS,0=WMT,1=TS1,2=TS2,3=TS3 */
  208. static inline int is_wifi_tput_min(void)
  209. {
  210. wmt_tm_dprintk("%s: %d\n", __func__, __LINE__);
  211. return (g_limit_tput != -1 && g_limit_tput <= min_wifi_tput) ? 1 : 0;
  212. }
  213. static unsigned long set_adaptive_wifi_tput_limit(unsigned int cur_tput, unsigned int limit_ratio)
  214. {
  215. int limit_tput;
  216. static int prev_limit_tput = -1, limit_upper_bound = -1;
  217. if (limit_ratio == -1) {
  218. prev_limit_tput = -1;
  219. limit_tput = -1;
  220. } else {
  221. /* when we enter cooler */
  222. if (prev_limit_tput == -1) {
  223. prev_limit_tput = cur_tput;
  224. limit_upper_bound = cur_tput;
  225. }
  226. limit_tput = (prev_limit_tput * limit_ratio) / init_wifi_tput_ratio;
  227. if (limit_upper_bound >= min_wifi_tput)
  228. limit_tput = clamp(limit_tput, min_wifi_tput, limit_upper_bound);
  229. else
  230. limit_tput = -1;
  231. prev_limit_tput = limit_tput;
  232. }
  233. wmt_tm_dprintk("%s: Curr Tput= %lu ,ratio= %u, limit_tput= %d", __func__, tx_throughput,
  234. limit_ratio, limit_tput);
  235. wmt_send_signal(limit_tput);
  236. return limit_tput;
  237. }
  238. static int adaptive_tput_ratio(long prev_temp, long curr_temp)
  239. {
  240. static int wifi_tput_ratio;
  241. WIFI_TARGET_TJ_HIGH = wifi_target_tj + tj_stable_range;
  242. WIFI_TARGET_TJ_LOW = wifi_target_tj - tj_stable_range;
  243. wmt_tm_dprintk("%s : active= %d tirgger= %d\n", __func__, cl_dev_adp_cpu_state_active,
  244. triggered);
  245. if (cl_dev_adp_cpu_state_active == 1) {
  246. int tt_wifi = wifi_target_tj - curr_temp; /* unit: mC */
  247. int tp_wifi = prev_temp - curr_temp; /* unit: mC */
  248. /* Check if it is triggered */
  249. if (!triggered) {
  250. if (curr_temp < wifi_target_tj)
  251. return 0;
  252. triggered = 1;
  253. }
  254. wifi_tput_ratio = init_wifi_tput_ratio;
  255. /* Adjust total power budget if necessary */
  256. if (((curr_temp > WIFI_TARGET_TJ_HIGH) && (curr_temp > prev_temp)) ||
  257. ((curr_temp <= WIFI_TARGET_TJ_HIGH) && (curr_temp >= WIFI_TARGET_TJ_LOW)
  258. && (curr_temp >= (prev_temp + (tj_stable_range * 2))))) {
  259. wifi_tput_ratio += (tt_wifi / tt_wifi_high + tp_wifi / tp_wifi_rise);
  260. } else if (((curr_temp > WIFI_TARGET_TJ_HIGH) && (curr_temp <= prev_temp)) ||
  261. ((curr_temp <= WIFI_TARGET_TJ_HIGH) && (curr_temp >= WIFI_TARGET_TJ_LOW)
  262. && (curr_temp <= (prev_temp - (tj_stable_range * 2))))) {
  263. wifi_tput_ratio += (tt_wifi / tt_wifi_high + tp_wifi / tp_wifi_fall);
  264. } else if ((curr_temp < WIFI_TARGET_TJ_LOW) && (curr_temp > prev_temp)) {
  265. wifi_tput_ratio += (tt_wifi / tt_wifi_low + tp_wifi / tp_wifi_rise);
  266. } else if ((curr_temp < WIFI_TARGET_TJ_LOW) && (curr_temp <= prev_temp)) {
  267. wifi_tput_ratio += (tt_wifi / tt_wifi_low + tp_wifi / tp_wifi_fall);
  268. }
  269. wifi_tput_ratio =
  270. (wifi_tput_ratio > min_wifi_tput_ratio) ? wifi_tput_ratio : min_wifi_tput_ratio;
  271. wifi_tput_ratio =
  272. (wifi_tput_ratio < max_wifi_tput_ratio) ? wifi_tput_ratio : max_wifi_tput_ratio;
  273. wmt_tm_dprintk("%s Wifi TJ %d Tp %ld, Tc %ld, wifi_tput_ratio %d tput %lu\n",
  274. __func__, wifi_target_tj, prev_temp, curr_temp, wifi_tput_ratio,
  275. tx_throughput);
  276. set_adaptive_wifi_tput_limit(tx_throughput, wifi_tput_ratio);
  277. } else {
  278. if (triggered) {
  279. triggered = 0;
  280. wmt_tm_dprintk("%s :unlimit Tp %ld Tc %ld Pt %lu\n", __func__, prev_temp,
  281. curr_temp, tx_throughput);
  282. set_adaptive_wifi_tput_limit(0, -1);
  283. }
  284. }
  285. return 0;
  286. }
  287. /* extern int cpu_target_tj; // in mtk_ts_cpu.c */
  288. /* extern int cpu_target_offset; // in mtk_ts_cpu.c */
  289. /**
  290. * @temp current temperature in milli degree C
  291. */
  292. static void heterogeneous_resource_allocator(int temp)
  293. {
  294. wmt_tm_dprintk("%s: wifi_throttle_version= %d,wifi temp=%d\n", __func__,
  295. wifi_throttle_version, temp);
  296. if (wifi_throttle_version == 0) {
  297. return; /* for old WiFi throttle */
  298. } else if (wifi_throttle_version == 1) {
  299. wmt_tm_dprintk("%s: temp= %d policy= %d target_tj= %d target_offset= %d\n",
  300. __func__, temp, resource_allocator_policy, wifi_target_tj,
  301. wifi_target_offset);
  302. switch (resource_allocator_policy) {
  303. case 0: /* wifi last */
  304. if (is_cpu_power_unlimit()) {
  305. wifi_target_tj = wmt_wifi_target_tj;
  306. wifi_target_offset = wmt_wifi_target_offset;
  307. cl_dev_adp_cpu_state_active =
  308. (temp >= (wifi_target_tj - wifi_target_offset)) ? 1 : 0;
  309. adaptive_tput_ratio(g_prev_temp, temp);
  310. } else {
  311. if (!is_wifi_tput_min()) {
  312. set_adaptive_wifi_tput_limit(tx_throughput,
  313. min_wifi_tput_ratio);
  314. }
  315. triggered = 1; /* wt2 */
  316. }
  317. break;
  318. case 1: /* wifi first */
  319. break;
  320. case 2: /* no throttle wifi */
  321. if (g_limit_tput != -1)
  322. set_adaptive_wifi_tput_limit(0, -1);
  323. break;
  324. case 3: /* independent */
  325. wifi_target_offset = wmt_wifi_target_offset;
  326. if (is_cpu_power_unlimit())
  327. wifi_target_tj = wmt_wifi_target_tj;
  328. /* min(wmt_wifi_target_tj, get_cpu_target_tj() - cpu_wifi_target_tj_offset); */
  329. else
  330. wifi_target_tj =
  331. min(wmt_wifi_target_tj,
  332. get_cpu_target_tj() - cpu_wifi_target_tj_offset);
  333. cl_dev_adp_cpu_state_active =
  334. (temp >= (wifi_target_tj - wifi_target_offset)) ? 1 : 0;
  335. adaptive_tput_ratio(g_prev_temp, temp);
  336. break;
  337. case 4: /* not share target tj (default): for non-integrated WiFi */
  338. default:
  339. wifi_target_tj = wmt_wifi_target_tj;
  340. wifi_target_offset = wmt_wifi_target_offset;
  341. cl_dev_adp_cpu_state_active =
  342. (temp >= (wifi_target_tj - wifi_target_offset)) ? 1 : 0;
  343. adaptive_tput_ratio(g_prev_temp, temp);
  344. break;
  345. }
  346. }
  347. }
  348. static unsigned long get_tx_bytes(void)
  349. {
  350. struct net_device *dev;
  351. struct net *net;
  352. unsigned long tx_bytes = 0;
  353. read_lock(&dev_base_lock);
  354. for_each_net(net) {
  355. for_each_netdev(net, dev) {
  356. if (!strncmp(dev->name, "wlan", 4) || !strncmp(dev->name, "ap", 2)
  357. || !strncmp(dev->name, "p2p", 3)) {
  358. struct rtnl_link_stats64 temp;
  359. const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
  360. tx_bytes = tx_bytes + stats->tx_bytes;
  361. }
  362. }
  363. }
  364. read_unlock(&dev_base_lock);
  365. return tx_bytes;
  366. }
  367. static int wmt_cal_stats(unsigned long data)
  368. {
  369. struct wmt_stats *stats_info = (struct wmt_stats *)data;
  370. struct timeval cur_time;
  371. wmt_tm_dprintk("[%s] pre_time=%lu, pre_data=%lu\n", __func__, pre_time,
  372. stats_info->pre_tx_bytes);
  373. do_gettimeofday(&cur_time);
  374. if (pre_time != 0 && cur_time.tv_sec > pre_time) {
  375. unsigned long tx_bytes = get_tx_bytes();
  376. if (tx_bytes > stats_info->pre_tx_bytes) {
  377. tx_throughput =
  378. ((tx_bytes - stats_info->pre_tx_bytes) / (cur_time.tv_sec -
  379. pre_time)) >> 7;
  380. wmt_tm_dprintk
  381. ("[%s] cur_time=%lu, cur_data=%lu, tx_throughput=%luK bit/s(%luK Byte/s)\n",
  382. __func__, cur_time.tv_sec, tx_bytes, tx_throughput,
  383. tx_throughput >> 3);
  384. stats_info->pre_tx_bytes = tx_bytes;
  385. } else if (tx_bytes < stats_info->pre_tx_bytes) {
  386. /* Overflow */
  387. tx_throughput =
  388. ((0xffffffff - stats_info->pre_tx_bytes + tx_bytes) / (cur_time.tv_sec -
  389. pre_time)) >> 7;
  390. stats_info->pre_tx_bytes = tx_bytes;
  391. wmt_tm_dprintk("[%s] cur_tx(%lu) < pre_tx\n", __func__, tx_bytes);
  392. } else {
  393. /* No traffic */
  394. tx_throughput = 0;
  395. wmt_tm_dprintk("[%s] cur_tx(%lu) = pre_tx\n", __func__, tx_bytes);
  396. }
  397. } else {
  398. /* Overflow possible ?? */
  399. tx_throughput = 0;
  400. wmt_tm_printk("[%s] cur_time(%lu) < pre_time\n", __func__, cur_time.tv_sec);
  401. }
  402. pre_time = cur_time.tv_sec;
  403. wmt_tm_dprintk("[%s] pre_time=%lu, tv_sec=%lu\n", __func__, pre_time, cur_time.tv_sec);
  404. wmt_stats_timer.expires = jiffies + 1 * HZ;
  405. add_timer(&wmt_stats_timer);
  406. return 0;
  407. }
  408. static int wmt_thz_bind(struct thermal_zone_device *thz_dev,
  409. struct thermal_cooling_device *cool_dev)
  410. {
  411. struct linux_thermal_ctrl_if *p_linux_if = 0;
  412. int table_val = 0;
  413. wmt_tm_dprintk("[%s]\n", __func__);
  414. if (pg_wmt_tm)
  415. p_linux_if = &pg_wmt_tm->linux_if;
  416. else
  417. return -EINVAL;
  418. #ifdef NEVER
  419. /* cooling devices */
  420. if (cool_dev != p_linux_if->cl_dev)
  421. return 0;
  422. #endif
  423. if (!strcmp(cool_dev->type, g_bind0)) {
  424. table_val = 0;
  425. wmt_tm_dprintk("[%s] %s\n", __func__, cool_dev->type);
  426. } else if (!strcmp(cool_dev->type, g_bind1)) {
  427. table_val = 1;
  428. wmt_tm_dprintk("[%s] %s\n", __func__, cool_dev->type);
  429. } else if (!strcmp(cool_dev->type, g_bind2)) {
  430. table_val = 2;
  431. wmt_tm_dprintk("[%s]] %s\n", __func__, cool_dev->type);
  432. } else if (!strcmp(cool_dev->type, g_bind3)) {
  433. table_val = 3;
  434. wmt_tm_dprintk("[%s]] %s\n", __func__, cool_dev->type);
  435. } else
  436. return 0;
  437. if (mtk_thermal_zone_bind_cooling_device(thz_dev, table_val, cool_dev)) {
  438. wmt_tm_info("[%s] binding fail\n", __func__);
  439. return -EINVAL;
  440. }
  441. wmt_tm_dprintk("[%s]] binding OK\n", __func__);
  442. return 0;
  443. }
  444. static int wmt_thz_unbind(struct thermal_zone_device *thz_dev,
  445. struct thermal_cooling_device *cool_dev)
  446. {
  447. struct linux_thermal_ctrl_if *p_linux_if = 0;
  448. int table_val = 0;
  449. wmt_tm_dprintk("[wmt_thz_unbind]\n");
  450. if (pg_wmt_tm)
  451. p_linux_if = &pg_wmt_tm->linux_if;
  452. else
  453. return -EINVAL;
  454. #if 0
  455. /* cooling devices */
  456. if (cool_dev == p_linux_if->cl_dev) {
  457. table_val = 0;
  458. } else {
  459. wmt_tm_dprintk("[wmt_thz_unbind] unbind device fail..!\n");
  460. return -EINVAL;
  461. }
  462. #endif
  463. if (!strcmp(cool_dev->type, g_bind0)) {
  464. table_val = 0;
  465. wmt_tm_dprintk("[wmt_thz_unbind] %s\n", cool_dev->type);
  466. } else if (!strcmp(cool_dev->type, g_bind1)) {
  467. table_val = 1;
  468. wmt_tm_dprintk("[wmt_thz_unbind] %s\n", cool_dev->type);
  469. } else if (!strcmp(cool_dev->type, g_bind2)) {
  470. table_val = 2;
  471. wmt_tm_dprintk("[wmt_thz_unbind] %s\n", cool_dev->type);
  472. } else if (!strcmp(cool_dev->type, g_bind3)) {
  473. table_val = 3;
  474. wmt_tm_dprintk("[wmt_thz_unbind] %s\n", cool_dev->type);
  475. } else
  476. return 0;
  477. if (thermal_zone_unbind_cooling_device(thz_dev, table_val, cool_dev)) {
  478. wmt_tm_info("[wmt_thz_unbind] error unbinding cooling dev\n");
  479. return -EINVAL;
  480. }
  481. wmt_tm_dprintk("[wmt_thz_unbind] unbinding OK\n");
  482. return 0;
  483. }
  484. static int wmt_thz_get_temp(struct thermal_zone_device *thz_dev, unsigned long *pv)
  485. {
  486. /* struct wmt_thermal_ctrl_ops *p_des; */
  487. int temp = 0;
  488. int i;
  489. int temp_ts[NR_TS_SENSORS];
  490. /* int temp_ts4 = 0; */
  491. /* int temp_abb = 0, temp_cpu = 0, temp_gpu = 0, temp_soc = 0; */
  492. for (i = 0; i < NR_TS_SENSORS; i++)
  493. temp_ts[i] = (*ts_get_temp_wrap[i]) ();
  494. /* FIXME: temp_ts[0] (mtk_wcn_cmb_stub_query_ctrl) uses unit of degree,
  495. * while others temp_ts[x] use milli degree */
  496. temp_ts[0] *= 1000;
  497. temp = temp_ts[0];
  498. wmt_tm_dprintk("%s: TS1 %d TS2 %d TS3 %d\n", __func__, temp_ts[1], temp_ts[2], temp_ts[3]);
  499. wmt_tm_dprintk("%s: WIFI temp %d\n", __func__, temp);
  500. g_prev_temp = g_curr_temp;
  501. if (sensor_select < 0 || sensor_select >= NR_TS_SENSORS) {
  502. aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "wmt_thz_get_temp ",
  503. "sensor_select: %d\n", sensor_select);
  504. sensor_select = 0;
  505. }
  506. g_curr_temp = temp_ts[sensor_select];
  507. if (temp >= 255000) /* dummy values */
  508. temp = -127000;
  509. *pv = temp;
  510. if (temp != -127000) {
  511. if (temp > 100000 || temp < -30000)
  512. wmt_tm_info("[wmt_thz_get_temp] temp = %d\n", temp);
  513. }
  514. if ((int)*pv >= polling_trip_temp1)
  515. thz_dev->polling_delay = g_wmt_tm.linux_if.interval;
  516. else if ((int)*pv < polling_trip_temp2)
  517. thz_dev->polling_delay = g_wmt_tm.linux_if.interval * polling_factor2;
  518. else
  519. thz_dev->polling_delay = g_wmt_tm.linux_if.interval * polling_factor1;
  520. return 0;
  521. }
  522. static int wmt_thz_get_mode(struct thermal_zone_device *thz_dev, enum thermal_device_mode *mode)
  523. {
  524. struct linux_thermal_ctrl_if *p_linux_if = 0;
  525. /* int kernel_mode = 0; */
  526. wmt_tm_dprintk("[%s]\n", __func__);
  527. if (pg_wmt_tm) {
  528. p_linux_if = &pg_wmt_tm->linux_if;
  529. } else {
  530. wmt_tm_dprintk("[%s] fail!\n", __func__);
  531. return -EINVAL;
  532. }
  533. wmt_tm_dprintk("[%s] %d\n", __func__, p_linux_if->kernel_mode);
  534. *mode = (p_linux_if->kernel_mode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED;
  535. return 0;
  536. }
  537. static int wmt_thz_set_mode(struct thermal_zone_device *thz_dev, enum thermal_device_mode mode)
  538. {
  539. struct linux_thermal_ctrl_if *p_linux_if = 0;
  540. wmt_tm_dprintk("[%s]\n", __func__);
  541. if (pg_wmt_tm) {
  542. p_linux_if = &pg_wmt_tm->linux_if;
  543. } else {
  544. wmt_tm_dprintk("[%s] fail!\n", __func__);
  545. return -EINVAL;
  546. }
  547. wmt_tm_dprintk("[%s] %d\n", __func__, mode);
  548. p_linux_if->kernel_mode = mode;
  549. return 0;
  550. }
  551. static int wmt_thz_get_trip_type(struct thermal_zone_device *thz_dev, int trip,
  552. enum thermal_trip_type *type)
  553. {
  554. wmt_tm_dprintk("[mtktspa_get_trip_type] %d\n", trip);
  555. *type = g_thermal_trip[trip];
  556. return 0;
  557. }
  558. static int wmt_thz_get_trip_temp(struct thermal_zone_device *thz_dev, int trip, unsigned long *pv)
  559. {
  560. wmt_tm_dprintk("[mtktspa_get_trip_temp] %d\n", trip);
  561. *pv = g_trip_temp[trip];
  562. return 0;
  563. }
  564. static int wmt_thz_get_crit_temp(struct thermal_zone_device *thz_dev, unsigned long *pv)
  565. {
  566. wmt_tm_dprintk("[%s]\n", __func__);
  567. #define WMT_TM_TEMP_CRIT 85000 /* 85.000 degree Celsius */
  568. *pv = WMT_TM_TEMP_CRIT;
  569. return 0;
  570. }
  571. /* +mtktspa_cooling_sysrst_ops+ */
  572. static int wmt_cl_get_max_state(struct thermal_cooling_device *cool_dev, unsigned long *pv)
  573. {
  574. *pv = 1;
  575. wmt_tm_dprintk("[%s] %lu\n", __func__, *pv);
  576. return 0;
  577. }
  578. static int wmt_cl_get_cur_state(struct thermal_cooling_device *cool_dev, unsigned long *pv)
  579. {
  580. *pv = cl_dev_state;
  581. wmt_tm_dprintk("[%s] %lu\n", __func__, *pv);
  582. return 0;
  583. }
  584. static int wmt_cl_set_cur_state(struct thermal_cooling_device *cool_dev, unsigned long v)
  585. {
  586. wmt_tm_dprintk("[%s] %lu\n", __func__, v);
  587. cl_dev_state = v;
  588. if (cl_dev_state == 1) {
  589. wmt_tm_printk("wmt_cl_set_cur_state = 1\n");
  590. /* the temperature is over than the critical, system reboot. */
  591. /* BUG(); */
  592. *(unsigned int *)0x0 = 0xdead; /* To trigger data abort to reset the system for thermal protection. */
  593. }
  594. return 0;
  595. }
  596. /* -mtktspa_cooling_sysrst_ops- */
  597. static int wmt_send_signal(int level)
  598. {
  599. int ret = 0;
  600. int thro = level;
  601. g_limit_tput = level;
  602. wmt_tm_dprintk("%s +++ level %d\n", __func__, level);
  603. if (tm_input_pid == 0) {
  604. wmt_tm_dprintk("[%s] pid is empty\n", __func__);
  605. ret = -1;
  606. }
  607. wmt_tm_printk("[%s] pid is %d, %d, %d\n", __func__, tm_pid, tm_input_pid, thro);
  608. if (ret == 0 && tm_input_pid != tm_pid) {
  609. tm_pid = tm_input_pid;
  610. pg_task = get_pid_task(find_vpid(tm_pid), PIDTYPE_PID);
  611. }
  612. if (ret == 0 && pg_task) {
  613. siginfo_t info;
  614. info.si_signo = SIGIO;
  615. info.si_errno = 0;
  616. info.si_code = thro;
  617. info.si_addr = NULL;
  618. ret = send_sig_info(SIGIO, &info, pg_task);
  619. }
  620. if (ret != 0)
  621. wmt_tm_info("[%s] ret=%d\n", __func__, ret);
  622. return ret;
  623. }
  624. #define UNK_STAT -1
  625. #define LOW_STAT 0
  626. #define MID_STAT 1
  627. #define HIGH_STAT 2
  628. #define WFD_STAT 3
  629. static inline unsigned long thro(unsigned long a, unsigned int b, unsigned int c)
  630. {
  631. unsigned long tmp;
  632. tmp = (a << 10) * b / c;
  633. return tmp >> 10;
  634. }
  635. static int wmt_judge_throttling(int index, int is_on, int interval)
  636. {
  637. /*
  638. * throttling_stat
  639. * 2 ( pa1=1,pa2=1 )
  640. * UPPER ----
  641. * 1 ( pa1=1,pa2=0 )
  642. * LOWER ----
  643. * 0 ( pa1=0,pa2=0 )
  644. */
  645. static unsigned int throttling_pre_stat;
  646. static int mail_box[2] = { -1, -1 };
  647. static bool is_reset;
  648. unsigned long cur_thro = tx_throughput;
  649. static unsigned long thro_constraint = 99 * 1000;
  650. int cur_wifi_stat = 0;
  651. wmt_tm_dprintk("[%s]+ [0]=%d, [1]=%d || [%d] is %s\n", __func__, mail_box[0], mail_box[1],
  652. index, (is_on == 1 ? "ON" : "OFF"));
  653. mail_box[index] = is_on;
  654. if (mail_box[0] < 0 || mail_box[1] < 0) {
  655. wmt_tm_dprintk("[%s] dont get all info!!\n", __func__);
  656. return 0;
  657. }
  658. cur_wifi_stat = mail_box[0] + mail_box[1];
  659. /*
  660. * If Wifi-display is on, go to WFD_STAT state, and reset the throttling.
  661. */
  662. if (tm_wfd_stat == 2)
  663. cur_wifi_stat = WFD_STAT;
  664. switch (cur_wifi_stat) {
  665. case WFD_STAT:
  666. if (throttling_pre_stat != WFD_STAT) {
  667. /*
  668. * Enter Wifi-Display status, reset all throttling.
  669. * Dont affect the performance of Wifi-Display.
  670. */
  671. wmt_send_signal(-1);
  672. below_low_time = 0;
  673. over_up_time = 0;
  674. throttling_pre_stat = WFD_STAT;
  675. wmt_tm_printk("WFD is on, reset everything!");
  676. }
  677. break;
  678. case HIGH_STAT:
  679. if (throttling_pre_stat < HIGH_STAT || throttling_pre_stat == WFD_STAT) {
  680. if (cur_thro > 0) /*Wifi is working!! */
  681. thro_constraint = thro(cur_thro, up_numerator, up_denominator);
  682. else /*At this moment, current throughput is none. Use the previous constraint. */
  683. thro_constraint =
  684. thro(thro_constraint, up_numerator, up_denominator);
  685. wmt_tm_printk("LOW/MID-->HIGH:%lu <- (%d / %d) %lu",
  686. thro_constraint, up_numerator, up_denominator, cur_thro);
  687. /* wmt_send_signal( thro_constraint / 1000); */
  688. wmt_send_signal(thro_constraint); /* [star] unit : Kbytes */
  689. throttling_pre_stat = HIGH_STAT;
  690. over_up_time = 0;
  691. } else if (throttling_pre_stat == HIGH_STAT) {
  692. over_up_time++;
  693. if ((over_up_time * interval) >= up_duration) {
  694. if (cur_thro < thro_constraint) /*real throughput may have huge variant */
  695. thro_constraint =
  696. thro(cur_thro, up_numerator, up_denominator);
  697. else /* current throughput is large than constraint. WHAT!!! */
  698. thro_constraint =
  699. thro(thro_constraint, up_numerator, up_denominator);
  700. wmt_tm_printk("HIGH-->HIGH:%lu <- (%d / %d) %lu",
  701. thro_constraint, up_numerator, up_denominator,
  702. cur_thro);
  703. /* wmt_send_signal( thro_constraint / 1000); */
  704. wmt_send_signal(thro_constraint); /* [star] unit : Kbytes */
  705. over_up_time = 0;
  706. }
  707. } else {
  708. wmt_tm_info("[%s] Error state1=%d!!\n", __func__, throttling_pre_stat);
  709. }
  710. wmt_tm_printk("case2 time=%d\n", over_up_time);
  711. break;
  712. case MID_STAT:
  713. if (throttling_pre_stat == LOW_STAT) {
  714. below_low_time = 0;
  715. throttling_pre_stat = MID_STAT;
  716. wmt_tm_printk("[%s] Go up!!\n", __func__);
  717. } else if (throttling_pre_stat == HIGH_STAT) {
  718. over_up_time = 0;
  719. throttling_pre_stat = MID_STAT;
  720. wmt_tm_printk("[%s] Go down!!\n", __func__);
  721. } else {
  722. throttling_pre_stat = MID_STAT;
  723. wmt_tm_dprintk("[%s] pre_stat=%d!!\n", __func__, throttling_pre_stat);
  724. }
  725. break;
  726. case LOW_STAT:
  727. if (throttling_pre_stat == WFD_STAT) {
  728. throttling_pre_stat = LOW_STAT;
  729. wmt_tm_dprintk("[%s] pre_stat=%d!!\n", __func__, throttling_pre_stat);
  730. } else if (throttling_pre_stat > LOW_STAT) {
  731. if (cur_thro < 5000 && cur_thro > 0) {
  732. thro_constraint = cur_thro * 3;
  733. } else if (cur_thro >= 5000) {
  734. thro_constraint = thro(cur_thro, low_numerator, low_denominator);
  735. } else {
  736. thro_constraint =
  737. thro(thro_constraint, low_numerator, low_denominator);
  738. }
  739. wmt_tm_printk("MID/HIGH-->LOW:%lu <- (%d / %d) %lu",
  740. thro_constraint, low_numerator, low_denominator, cur_thro);
  741. /* wmt_send_signal( thro_constraint / 1000); */
  742. wmt_send_signal(thro_constraint); /* [star] unit : Kbytes */
  743. throttling_pre_stat = LOW_STAT;
  744. below_low_time = 0;
  745. low_rst_time = 0;
  746. is_reset = false;
  747. } else if (throttling_pre_stat == LOW_STAT) {
  748. below_low_time++;
  749. if ((below_low_time * interval) >= low_duration) {
  750. if (low_rst_time >= low_rst_max && !is_reset) {
  751. wmt_tm_printk("over rst time=%d", low_rst_time);
  752. wmt_send_signal(-1); /* reset */
  753. low_rst_time = low_rst_max;
  754. is_reset = true;
  755. } else if (!is_reset) {
  756. if (cur_thro < 5000 && cur_thro > 0) {
  757. thro_constraint = cur_thro * 3;
  758. } else if (cur_thro >= 5000) {
  759. thro_constraint =
  760. thro(cur_thro, low_numerator, low_denominator);
  761. low_rst_time++;
  762. } else {
  763. thro_constraint =
  764. thro(thro_constraint, low_numerator,
  765. low_denominator);
  766. low_rst_time++;
  767. }
  768. wmt_tm_printk("LOW-->LOW:%lu <-(%d / %d) %lu",
  769. thro_constraint, low_numerator,
  770. low_denominator, cur_thro);
  771. /* wmt_send_signal( thro_constraint / 1000); */
  772. wmt_send_signal(thro_constraint); /* [star] unit : Kbytes */
  773. below_low_time = 0;
  774. } else {
  775. wmt_tm_dprintk("Have reset, no control!!");
  776. }
  777. }
  778. } else {
  779. wmt_tm_info("[%s] Error state3 %d!!\n", __func__, throttling_pre_stat);
  780. }
  781. wmt_tm_dprintk("case0 time=%d, rst=%d %d\n", below_low_time, low_rst_time,
  782. is_reset);
  783. break;
  784. default:
  785. wmt_tm_info("[%s] Error cur_wifi_stat=%d!!\n", __func__, cur_wifi_stat);
  786. break;
  787. }
  788. mail_box[0] = UNK_STAT;
  789. mail_box[1] = UNK_STAT;
  790. return 0;
  791. }
  792. /* +mtktspa_cooling_pa1_ops+ */
  793. static int wmt_cl_pa1_get_max_state(struct thermal_cooling_device *cool_dev, unsigned long *pv)
  794. {
  795. *pv = 1;
  796. wmt_tm_dprintk("[%s] %lu\n", __func__, *pv);
  797. return 0;
  798. }
  799. static int wmt_cl_pa1_get_cur_state(struct thermal_cooling_device *cool_dev, unsigned long *pv)
  800. {
  801. *pv = cl_pa1_dev_state;
  802. wmt_tm_dprintk("[%s] %lu\n", __func__, *pv);
  803. return 0;
  804. }
  805. static int wmt_cl_pa1_set_cur_state(struct thermal_cooling_device *cool_dev, unsigned long v)
  806. {
  807. struct linux_thermal_ctrl_if *p_linux_if = 0;
  808. int ret = 0;
  809. wmt_tm_dprintk("[%s] %d\n", __func__, __LINE__);
  810. cl_pa1_dev_state = (unsigned int)v;
  811. wmt_tm_dprintk("[%s] wifi_throttle_version=%u,cl_pa1_dev_state=%u\n", __func__,
  812. wifi_throttle_version, cl_pa1_dev_state);
  813. if (0 == wifi_throttle_version) {
  814. wmt_tm_dprintk("[%s] %lu\n", __func__, v);
  815. if (pg_wmt_tm) {
  816. p_linux_if = &pg_wmt_tm->linux_if;
  817. if (p_linux_if == NULL)
  818. return -1;
  819. } else {
  820. return -1;
  821. }
  822. /* cl_pa1_dev_state = (unsigned int)v; */
  823. if (cl_pa1_dev_state == 1)
  824. ret = wmt_judge_throttling(0, 1, p_linux_if->interval / 1000);
  825. else
  826. ret = wmt_judge_throttling(0, 0, p_linux_if->interval / 1000);
  827. if (ret != 0)
  828. wmt_tm_info("[%s] ret=%d\n", __func__, ret);
  829. } else {
  830. /* cl_pa1_dev_state = (unsigned int)v; */
  831. wmt_tm_dprintk("[%s] cl_pa1_dev_state=%u,wif curr T=%d\n", __func__,
  832. cl_pa1_dev_state, g_curr_temp);
  833. /* need to do limit and unlimit */
  834. heterogeneous_resource_allocator(g_curr_temp);
  835. }
  836. return ret;
  837. }
  838. /* -mtktspa_cooling_pa1_ops- */
  839. /* +mtktspa_cooling_pa2_ops+ */
  840. static int wmt_cl_pa2_get_max_state(struct thermal_cooling_device *cool_dev, unsigned long *pv)
  841. {
  842. *pv = 1;
  843. wmt_tm_dprintk("[%s] %lu\n", __func__, *pv);
  844. return 0;
  845. }
  846. static int wmt_cl_pa2_get_cur_state(struct thermal_cooling_device *cool_dev, unsigned long *pv)
  847. {
  848. *pv = cl_pa2_dev_state;
  849. wmt_tm_dprintk("[%s] %lu\n", __func__, *pv);
  850. return 0;
  851. }
  852. static int wmt_cl_pa2_set_cur_state(struct thermal_cooling_device *cool_dev, unsigned long v)
  853. {
  854. struct linux_thermal_ctrl_if *p_linux_if = 0;
  855. int ret = 0;
  856. if (0 == wifi_throttle_version) {
  857. wmt_tm_dprintk("[%s] %lu\n", __func__, v);
  858. if (pg_wmt_tm) {
  859. p_linux_if = &pg_wmt_tm->linux_if;
  860. if (p_linux_if == NULL)
  861. return -1;
  862. } else {
  863. return -1;
  864. }
  865. cl_pa2_dev_state = (unsigned int)v;
  866. if (cl_pa2_dev_state == 1)
  867. ret = wmt_judge_throttling(1, 1, p_linux_if->interval / 1000);
  868. else
  869. ret = wmt_judge_throttling(1, 0, p_linux_if->interval / 1000);
  870. if (ret != 0)
  871. wmt_tm_info("[%s] ret=%d\n", __func__, ret);
  872. }
  873. return ret;
  874. }
  875. /* -mtktspa_cooling_pa2_ops- */
  876. #ifdef NEVER
  877. /* +mtktspa_cooling_pa3_ops+ */
  878. static int wmt_cl_pa3_get_max_state(struct thermal_cooling_device *cool_dev, unsigned long *pv)
  879. {
  880. *pv = 1;
  881. wmt_tm_dprintk("[%s] %lu\n", __func__, *pv);
  882. return 0;
  883. }
  884. static int wmt_cl_pa3_get_cur_state(struct thermal_cooling_device *cool_dev, unsigned long *pv)
  885. {
  886. *pv = cl_pa3_dev_state;
  887. wmt_tm_dprintk("[%s] %lu\n", __func__, *pv);
  888. return 0;
  889. }
  890. static int wmt_cl_pa3_set_cur_state(struct thermal_cooling_device *cool_dev, unsigned long v)
  891. {
  892. struct linux_thermal_ctrl_if *p_linux_if = 0;
  893. int ret = 0;
  894. wmt_tm_dprintk("[%s] %lu\n", __func__, v);
  895. if (pg_wmt_tm)
  896. p_linux_if = &pg_wmt_tm->linux_if;
  897. else
  898. ret = -1;
  899. cl_pa3_dev_state = (unsigned int)v;
  900. /*
  901. if (cl_pa3_dev_state == 1)
  902. ret = wmt_arbitrate_thro(2,3);
  903. else
  904. ret = wmt_arbitrate_thro(2,0);
  905. */
  906. if (ret != 0)
  907. wmt_tm_printk("[%s] ret=%d\n", __func__, ret);
  908. return ret;
  909. }
  910. /* -mtktspa_cooling_pa3_ops- */
  911. #endif /* NEVER */
  912. int wmt_wifi_tx_thro_read(struct seq_file *m, void *v)
  913. {
  914. seq_printf(m, "%lu\n", tx_throughput);
  915. wmt_tm_dprintk("[%s] tx=%lu\n", __func__, tx_throughput);
  916. return 0;
  917. }
  918. static int wmt_wifi_tx_thro_open(struct inode *inode, struct file *file)
  919. {
  920. return single_open(file, wmt_wifi_tx_thro_read, PDE_DATA(inode));
  921. }
  922. int wmt_wifi_tx_thro_limit_read(struct seq_file *m, void *v)
  923. {
  924. seq_printf(m, "%d\n", g_limit_tput);
  925. wmt_tm_dprintk("[%s] tx=%d\n", __func__, g_limit_tput);
  926. return 0;
  927. }
  928. static int wmt_wifi_tx_thro_limit_open(struct inode *inode, struct file *file)
  929. {
  930. return single_open(file, wmt_wifi_tx_thro_limit_read, PDE_DATA(inode));
  931. }
  932. /*New Wifi throttling Algo+*/
  933. ssize_t wmt_wifi_algo_write(struct file *filp, const char __user *buf, size_t len, loff_t *data)
  934. {
  935. char desc[MAX_LEN] = { 0 };
  936. unsigned int tmp_up_dur = 30;
  937. unsigned int tmp_up_den = 2;
  938. unsigned int tmp_up_num = 1;
  939. unsigned int tmp_low_dur = 3;
  940. unsigned int tmp_low_den = 2;
  941. unsigned int tmp_low_num = 3;
  942. unsigned int tmp_low_rst_max = 3;
  943. unsigned int tmp_log = 0;
  944. len = (len < (sizeof(desc) - 1)) ? len : (sizeof(desc) - 1);
  945. /* write data to the buffer */
  946. if (copy_from_user(desc, buf, len))
  947. return -EFAULT;
  948. if (sscanf
  949. (desc, "%d %d/%d %d %d/%d %d", &tmp_up_dur, &tmp_up_num, &tmp_up_den, &tmp_low_dur,
  950. &tmp_low_num, &tmp_low_den, &tmp_low_rst_max) == 7) {
  951. up_duration = tmp_up_dur;
  952. up_denominator = tmp_up_den;
  953. up_numerator = tmp_up_num;
  954. low_duration = tmp_low_dur;
  955. low_denominator = tmp_low_den;
  956. low_numerator = tmp_low_num;
  957. low_rst_max = tmp_low_rst_max;
  958. over_up_time = 0;
  959. below_low_time = 0;
  960. low_rst_time = 0;
  961. wmt_tm_printk("[%s] %s [up]%d %d/%d, [low]%d %d/%d, rst=%d\n", __func__, desc,
  962. up_duration, up_numerator, up_denominator, low_duration,
  963. low_numerator, low_denominator, low_rst_max);
  964. return len;
  965. }
  966. if (sscanf(desc, "log=%d", &tmp_log) == 1) {
  967. if (tmp_log == 1)
  968. wmt_tm_debug_log = 1;
  969. else
  970. wmt_tm_debug_log = 0;
  971. return len;
  972. }
  973. wmt_tm_printk("[%s] bad argument = %s\n", __func__, desc);
  974. return -EINVAL;
  975. }
  976. int wmt_wifi_algo_read(struct seq_file *m, void *v)
  977. {
  978. /* int ret; */
  979. /* char tmp[MAX_LEN] = {0}; */
  980. seq_printf(m, "[up]\t%3d(sec)\t%2d/%2d\n[low]\t%3d(sec)\t%2d/%2d\nrst=%2d\n", up_duration,
  981. up_numerator, up_denominator, low_duration, low_numerator, low_denominator,
  982. low_rst_max);
  983. /* ret = strlen(tmp); */
  984. /* memcpy(buf, tmp, ret*sizeof(char)); */
  985. wmt_tm_printk("[%s] [up]%d %d/%d, [low]%d %d/%d, rst=%d\n", __func__, up_duration,
  986. up_numerator, up_denominator, low_duration, low_numerator, low_denominator,
  987. low_rst_max);
  988. return 0;
  989. }
  990. static int wmt_wifi_algo_open(struct inode *inode, struct file *file)
  991. {
  992. return single_open(file, wmt_wifi_algo_read, PDE_DATA(inode));
  993. }
  994. /*New Wifi throttling Algo-*/
  995. ssize_t wmt_tm_wfd_write(struct file *filp, const char __user *buf, size_t count, loff_t *data)
  996. {
  997. int ret = 0;
  998. char tmp[MAX_LEN] = { 0 };
  999. int len = 0;
  1000. len = (count < (MAX_LEN - 1)) ? count : (MAX_LEN - 1);
  1001. /* write data to the buffer */
  1002. if (copy_from_user(tmp, buf, len))
  1003. return -EFAULT;
  1004. ret = kstrtoint(tmp, 10, &tm_wfd_stat);
  1005. /*wmt_tm_printk("[%s] %s = %d, len=%d, ret=%d\n", __func__, tmp, tm_wfd_stat, len, ret); */
  1006. return len;
  1007. }
  1008. int wmt_tm_wfd_read(struct seq_file *m, void *v)
  1009. {
  1010. /* int len; */
  1011. /* int ret = 0; */
  1012. /* char tmp[MAX_LEN] = {0}; */
  1013. seq_printf(m, "%d\n", tm_wfd_stat);
  1014. /* len = strlen(tmp); */
  1015. /* memcpy(buf, tmp, ret*sizeof(char)); */
  1016. wmt_tm_printk("[%s] %d\n", __func__, tm_wfd_stat);
  1017. return 0;
  1018. }
  1019. static int wmt_tm_wfd_open(struct inode *inode, struct file *file)
  1020. {
  1021. return single_open(file, wmt_tm_wfd_read, PDE_DATA(inode));
  1022. }
  1023. ssize_t wmt_wifi_in_soc_write(struct file *filp, const char __user *buf, size_t count,
  1024. loff_t *data)
  1025. {
  1026. int ret = 0;
  1027. char tmp[MAX_LEN] = { 0 };
  1028. int len = 0;
  1029. len = (count < (MAX_LEN - 1)) ? count : (MAX_LEN - 1);
  1030. /* write data to the buffer */
  1031. if (copy_from_user(tmp, buf, len))
  1032. return -EFAULT;
  1033. ret = sscanf(tmp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d", &wifi_throttle_version,
  1034. &sensor_select,
  1035. &resource_allocator_policy,
  1036. &cpu_wifi_target_tj_offset,
  1037. &wmt_wifi_target_tj,
  1038. &wmt_wifi_target_offset,
  1039. &tj_stable_range,
  1040. &min_wifi_tput_ratio,
  1041. &max_wifi_tput_ratio,
  1042. &min_wifi_tput, &tt_wifi_high, &tt_wifi_low, &tp_wifi_rise, &tp_wifi_fall);
  1043. wmt_tm_printk("qqq %s ret :%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", __func__, ret,
  1044. wifi_throttle_version,
  1045. sensor_select,
  1046. resource_allocator_policy,
  1047. cpu_wifi_target_tj_offset,
  1048. wmt_wifi_target_tj,
  1049. wmt_wifi_target_offset,
  1050. tj_stable_range,
  1051. min_wifi_tput_ratio,
  1052. max_wifi_tput_ratio,
  1053. min_wifi_tput, tt_wifi_high, tt_wifi_low, tp_wifi_rise, tp_wifi_fall);
  1054. if (sensor_select < 0 || sensor_select >= NR_TS_SENSORS) {
  1055. aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "wmt_wifi_in_soc_write ",
  1056. "sensor_select: %d\n", sensor_select);
  1057. sensor_select = 0;
  1058. }
  1059. /* wmt_wifi_in_soc_write ret 13 1 3 3 0 70000 3000 1000 50 200 1000 50 50 10000 */
  1060. return len;
  1061. }
  1062. int wmt_wifi_in_soc_read(struct seq_file *m, void *v)
  1063. {
  1064. seq_printf(m, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", wifi_throttle_version,
  1065. sensor_select,
  1066. resource_allocator_policy,
  1067. cpu_wifi_target_tj_offset,
  1068. wmt_wifi_target_tj,
  1069. wmt_wifi_target_offset,
  1070. tj_stable_range,
  1071. min_wifi_tput_ratio,
  1072. max_wifi_tput_ratio,
  1073. min_wifi_tput, tt_wifi_high, tt_wifi_low, tp_wifi_rise, tp_wifi_fall);
  1074. /* wmt_tm_printk("[%s] %d\n", __func__, wifi_in_soc); */
  1075. return 0;
  1076. }
  1077. static int wmt_wifi_in_soc_open(struct inode *inode, struct file *file)
  1078. {
  1079. return single_open(file, wmt_wifi_in_soc_read, PDE_DATA(inode));
  1080. }
  1081. ssize_t wmt_tm_pid_write(struct file *filp, const char __user *buf, size_t count, loff_t *data)
  1082. {
  1083. int ret = 0;
  1084. char tmp[MAX_LEN] = { 0 };
  1085. int len = 0;
  1086. len = (count < (MAX_LEN - 1)) ? count : (MAX_LEN - 1);
  1087. /* write data to the buffer */
  1088. if (copy_from_user(tmp, buf, len))
  1089. return -EFAULT;
  1090. ret = kstrtouint(tmp, 10, &tm_input_pid);
  1091. if (ret)
  1092. WARN_ON(1);
  1093. wmt_tm_printk("[%s] %s = %d\n", __func__, tmp, tm_input_pid);
  1094. return len;
  1095. }
  1096. int wmt_tm_pid_read(struct seq_file *m, void *v)
  1097. {
  1098. /* int ret; */
  1099. /* char tmp[MAX_LEN] = {0}; */
  1100. seq_printf(m, "%d\n", tm_input_pid);
  1101. /* ret = strlen(tmp); */
  1102. /* memcpy(buf, tmp, ret*sizeof(char)); */
  1103. wmt_tm_printk("[%s] %d\n", __func__, tm_input_pid);
  1104. return 0;
  1105. }
  1106. static int wmt_tm_pid_open(struct inode *inode, struct file *file)
  1107. {
  1108. return single_open(file, wmt_tm_pid_read, PDE_DATA(inode));
  1109. }
  1110. #define check_str(x) (x[0] == '\0'?"none\t":x)
  1111. static int wmt_tm_read(struct seq_file *m, void *v)
  1112. {
  1113. /* int len = 0; */
  1114. /* char *p = buf; */
  1115. struct linux_thermal_ctrl_if *p_linux_if = 0;
  1116. wmt_tm_printk("[%s]\n", __func__);
  1117. /* sanity */
  1118. if (pg_wmt_tm) {
  1119. p_linux_if = &pg_wmt_tm->linux_if;
  1120. } else {
  1121. wmt_tm_info("[wmt_tm_read] fail!\n");
  1122. return -EINVAL;
  1123. }
  1124. seq_printf(m,
  1125. "[wmt_tm_read]\n \tcooler\t\ttrip_temp\ttrip_type\n [0] %s\t%d\t\t%d\n [1] %s\t%d\t\t%d",
  1126. check_str(g_bind0), g_trip_temp[0], g_thermal_trip[0], check_str(g_bind1),
  1127. g_trip_temp[1], g_thermal_trip[1]);
  1128. seq_printf(m,
  1129. "\n [2] %s\t%d\t\t%d\n [3] %s\t%d\t\t%d\n [4] %s\t%d\t\t%d\n [5] %s\t%d\t\t%d",
  1130. check_str(g_bind2), g_trip_temp[2], g_thermal_trip[2], check_str(g_bind3),
  1131. g_trip_temp[3], g_thermal_trip[3], check_str(g_bind4), g_trip_temp[4],
  1132. g_thermal_trip[4], check_str(g_bind5), g_trip_temp[5], g_thermal_trip[5]);
  1133. seq_printf(m,
  1134. "\n [6] %s\t%d\t\t%d\n [7] %s\t%d\t\t%d\n [8] %s\t%d\t\t%d\n [9] %s\t%d\t\t%d\ntime_ms=%d\n",
  1135. check_str(g_bind6), g_trip_temp[6], g_thermal_trip[6], check_str(g_bind7),
  1136. g_trip_temp[7], g_thermal_trip[7], check_str(g_bind8), g_trip_temp[8],
  1137. g_thermal_trip[8], check_str(g_bind9), g_trip_temp[9], g_thermal_trip[9],
  1138. p_linux_if->interval);
  1139. return 0;
  1140. }
  1141. static int wmt_tm_open(struct inode *inode, struct file *file)
  1142. {
  1143. return single_open(file, wmt_tm_read, PDE_DATA(inode));
  1144. }
  1145. static ssize_t wmt_tm_write(struct file *filp, const char __user *buf, size_t count, loff_t *data)
  1146. {
  1147. int i = 0;
  1148. int len = 0;
  1149. struct tm_data {
  1150. int trip_temp[COOLER_NUM];
  1151. int thermal_trip[COOLER_NUM];
  1152. char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20];
  1153. char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20];
  1154. int time_msec;
  1155. char desc[512];
  1156. };
  1157. struct linux_thermal_ctrl_if *p_linux_if = 0;
  1158. struct tm_data *ptr_tm_data = kmalloc(sizeof(*ptr_tm_data), GFP_KERNEL);
  1159. if (ptr_tm_data == NULL) {
  1160. /* wmt_tm_printk("[%s] kmalloc fail\n\n", __func__); */
  1161. return -ENOMEM;
  1162. }
  1163. wmt_tm_printk("[%s]\n", __func__);
  1164. /* sanity */
  1165. if (pg_wmt_tm) {
  1166. p_linux_if = &pg_wmt_tm->linux_if;
  1167. } else {
  1168. wmt_tm_info("[wmt_thz_write] fail!\n");
  1169. kfree(ptr_tm_data);
  1170. return -EINVAL;
  1171. }
  1172. len = (count < (sizeof(ptr_tm_data->desc) - 1)) ? count : (sizeof(ptr_tm_data->desc) - 1);
  1173. if (copy_from_user(ptr_tm_data->desc, buf, len)) {
  1174. kfree(ptr_tm_data);
  1175. return 0;
  1176. }
  1177. ptr_tm_data->desc[len] = '\0';
  1178. if (sscanf
  1179. (ptr_tm_data->desc,
  1180. "%d %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d",
  1181. &g_num_trip, &ptr_tm_data->trip_temp[0], &ptr_tm_data->thermal_trip[0], ptr_tm_data->bind0,
  1182. &ptr_tm_data->trip_temp[1], &ptr_tm_data->thermal_trip[1], ptr_tm_data->bind1,
  1183. &ptr_tm_data->trip_temp[2], &ptr_tm_data->thermal_trip[2], ptr_tm_data->bind2,
  1184. &ptr_tm_data->trip_temp[3], &ptr_tm_data->thermal_trip[3], ptr_tm_data->bind3,
  1185. &ptr_tm_data->trip_temp[4], &ptr_tm_data->thermal_trip[4], ptr_tm_data->bind4,
  1186. &ptr_tm_data->trip_temp[5], &ptr_tm_data->thermal_trip[5], ptr_tm_data->bind5,
  1187. &ptr_tm_data->trip_temp[6], &ptr_tm_data->thermal_trip[6], ptr_tm_data->bind6,
  1188. &ptr_tm_data->trip_temp[7], &ptr_tm_data->thermal_trip[7], ptr_tm_data->bind7,
  1189. &ptr_tm_data->trip_temp[8], &ptr_tm_data->thermal_trip[8], ptr_tm_data->bind8,
  1190. &ptr_tm_data->trip_temp[9], &ptr_tm_data->thermal_trip[9], ptr_tm_data->bind9,
  1191. &ptr_tm_data->time_msec) == 32) {
  1192. /* unregister */
  1193. if (p_linux_if->thz_dev) {
  1194. mtk_thermal_zone_device_unregister(p_linux_if->thz_dev);
  1195. p_linux_if->thz_dev = NULL;
  1196. }
  1197. if (g_num_trip < 0 || g_num_trip > 10) {
  1198. aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "wmt_tm_write",
  1199. "Bad argument");
  1200. wmt_tm_info("[%s] bad argument = %s\n", __func__, ptr_tm_data->desc);
  1201. kfree(ptr_tm_data);
  1202. return -EINVAL;
  1203. }
  1204. for (i = 0; i < g_num_trip; i++)
  1205. g_thermal_trip[i] = ptr_tm_data->thermal_trip[i];
  1206. g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = '\0';
  1207. g_bind5[0] = g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0';
  1208. for (i = 0; i < 20; i++) {
  1209. g_bind0[i] = ptr_tm_data->bind0[i];
  1210. g_bind1[i] = ptr_tm_data->bind1[i];
  1211. g_bind2[i] = ptr_tm_data->bind2[i];
  1212. g_bind3[i] = ptr_tm_data->bind3[i];
  1213. g_bind4[i] = ptr_tm_data->bind4[i];
  1214. g_bind5[i] = ptr_tm_data->bind5[i];
  1215. g_bind6[i] = ptr_tm_data->bind6[i];
  1216. g_bind7[i] = ptr_tm_data->bind7[i];
  1217. g_bind8[i] = ptr_tm_data->bind8[i];
  1218. g_bind9[i] = ptr_tm_data->bind9[i];
  1219. }
  1220. for (i = 0; i < g_num_trip; i++)
  1221. g_trip_temp[i] = ptr_tm_data->trip_temp[i];
  1222. p_linux_if->interval = ptr_tm_data->time_msec;
  1223. wmt_tm_dprintk
  1224. ("[wmt_tm_write] g_trip_temp [0]=%d, [1]=%d, [2]=%d, [3]=%d, [4]=%d\n",
  1225. g_thermal_trip[0], g_thermal_trip[1], g_thermal_trip[2], g_thermal_trip[3],
  1226. g_thermal_trip[4]);
  1227. wmt_tm_dprintk
  1228. ("[wmt_tm_write] g_trip_temp [5]=%d, [6]=%d, [7]=%d, [8]=%d, [9]=%d\n",
  1229. g_thermal_trip[5], g_thermal_trip[6], g_thermal_trip[7], g_thermal_trip[8],
  1230. g_thermal_trip[9]);
  1231. wmt_tm_dprintk("[wmt_tm_write] cooldev [0]=%s, [1]=%s, [2]=%s, [3]=%s, [4]=%s,\n",
  1232. g_bind0, g_bind1, g_bind2, g_bind3, g_bind4);
  1233. wmt_tm_dprintk("[wmt_tm_write] cooldev [5]=%s, [6]=%s, [7]=%s, [8]=%s, [9]=%s,\n",
  1234. g_bind5, g_bind6, g_bind7, g_bind8, g_bind9);
  1235. wmt_tm_dprintk("[wmt_tm_write] trip_temp [0]=%d, [1]=%d, [2]=%d, [3]=%d, [4]=%d\n",
  1236. ptr_tm_data->trip_temp[0], ptr_tm_data->trip_temp[1], ptr_tm_data->trip_temp[2],
  1237. ptr_tm_data->trip_temp[3], ptr_tm_data->trip_temp[4]);
  1238. wmt_tm_dprintk("[wmt_tm_write] trip_temp [5]=%d, [6]=%d, [7]=%d, [8]=%d, [9]=%d\n",
  1239. ptr_tm_data->trip_temp[5], ptr_tm_data->trip_temp[6], ptr_tm_data->trip_temp[7],
  1240. ptr_tm_data->trip_temp[8], ptr_tm_data->trip_temp[9]);
  1241. wmt_tm_dprintk("[wmt_tm_write] polling time=%d\n", p_linux_if->interval);
  1242. /* p_linux_if->thz_dev->polling_delay = p_linux_if->interval*1000; */
  1243. /* thermal_zone_device_update(p_linux_if->thz_dev); */
  1244. /* register */
  1245. p_linux_if->thz_dev = mtk_thermal_zone_device_register("mtktswmt", g_num_trip, NULL,
  1246. &wmt_thz_dev_ops, 0, 0, 0,
  1247. p_linux_if->interval);
  1248. wmt_tm_dprintk("[wmt_tm_write] time_ms=%d\n", p_linux_if->interval);
  1249. kfree(ptr_tm_data);
  1250. return count;
  1251. }
  1252. wmt_tm_info("[%s] bad argument = %s\n", __func__, ptr_tm_data->desc);
  1253. aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "wmt_tm_write",
  1254. "Bad argument");
  1255. kfree(ptr_tm_data);
  1256. return -EINVAL;
  1257. }
  1258. void mtkts_wmt_cancel_thermal_timer(void)
  1259. {
  1260. struct linux_thermal_ctrl_if *p_linux_if = 0;
  1261. /* wmt_tm_dprintk("[%s]\n", __func__); */
  1262. if (pg_wmt_tm)
  1263. p_linux_if = &pg_wmt_tm->linux_if;
  1264. else
  1265. return;
  1266. /* pr_debug("mtkts_wmt_cancel_thermal_timer\n"); */
  1267. /* stop thermal framework polling when entering deep idle */
  1268. if (p_linux_if->thz_dev)
  1269. cancel_delayed_work(&(p_linux_if->thz_dev->poll_queue));
  1270. }
  1271. void mtkts_wmt_start_thermal_timer(void)
  1272. {
  1273. struct linux_thermal_ctrl_if *p_linux_if = 0;
  1274. /* wmt_tm_dprintk("[%s]\n", __func__); */
  1275. if (pg_wmt_tm)
  1276. p_linux_if = &pg_wmt_tm->linux_if;
  1277. else
  1278. return;
  1279. /* pr_debug("mtkts_wmt_start_thermal_timer\n"); */
  1280. /* resume thermal framework polling when leaving deep idle */
  1281. if (p_linux_if->thz_dev != NULL && p_linux_if->interval != 0)
  1282. mod_delayed_work(system_freezable_wq, &(p_linux_if->thz_dev->poll_queue),
  1283. round_jiffies(msecs_to_jiffies(2000)));
  1284. }
  1285. static const struct file_operations _wmt_tm_fops = {
  1286. .owner = THIS_MODULE,
  1287. .open = wmt_tm_open,
  1288. .read = seq_read,
  1289. .llseek = seq_lseek,
  1290. .write = wmt_tm_write,
  1291. .release = single_release,
  1292. };
  1293. static const struct file_operations _tm_pid_fops = {
  1294. .owner = THIS_MODULE,
  1295. .open = wmt_tm_pid_open,
  1296. .read = seq_read,
  1297. .llseek = seq_lseek,
  1298. .write = wmt_tm_pid_write,
  1299. .release = single_release,
  1300. };
  1301. static const struct file_operations _wmt_val_fops = {
  1302. .owner = THIS_MODULE,
  1303. .open = wmt_wifi_algo_open,
  1304. .read = seq_read,
  1305. .llseek = seq_lseek,
  1306. .write = wmt_wifi_algo_write,
  1307. .release = single_release,
  1308. };
  1309. static const struct file_operations _tx_thro_fops = {
  1310. .owner = THIS_MODULE,
  1311. .open = wmt_wifi_tx_thro_open,
  1312. .read = seq_read,
  1313. .llseek = seq_lseek,
  1314. .release = single_release,
  1315. };
  1316. static const struct file_operations _tx_thro_limit_fops = {
  1317. .owner = THIS_MODULE,
  1318. .open = wmt_wifi_tx_thro_limit_open,
  1319. .read = seq_read,
  1320. .llseek = seq_lseek,
  1321. .release = single_release,
  1322. };
  1323. static const struct file_operations _wfd_stat_fops = {
  1324. .owner = THIS_MODULE,
  1325. .open = wmt_tm_wfd_open,
  1326. .read = seq_read,
  1327. .llseek = seq_lseek,
  1328. .write = wmt_tm_wfd_write,
  1329. .release = single_release,
  1330. };
  1331. static const struct file_operations _wifi_in_soc_fops = {
  1332. .owner = THIS_MODULE,
  1333. .open = wmt_wifi_in_soc_open,
  1334. .read = seq_read,
  1335. .llseek = seq_lseek,
  1336. .write = wmt_wifi_in_soc_write,
  1337. .release = single_release,
  1338. };
  1339. static int wmt_tm_proc_register(void)
  1340. {
  1341. struct proc_dir_entry *entry = NULL;
  1342. struct proc_dir_entry *wmt_tm_proc_dir = NULL;
  1343. struct proc_dir_entry *wmt_thro_proc_dir = NULL;
  1344. wmt_tm_dprintk("[%s]\n", __func__);
  1345. wmt_thro_proc_dir = proc_mkdir("wmt_tm", NULL);
  1346. if (!wmt_thro_proc_dir) {
  1347. wmt_tm_printk("[wmt_tm_proc_register]: mkdir /proc/wmt_tm failed\n");
  1348. } else {
  1349. proc_create("tx_thro", S_IRUGO | S_IWUSR, wmt_thro_proc_dir, &_tx_thro_fops);
  1350. proc_create("tx_thro_limit", S_IRUGO | S_IWUSR, wmt_thro_proc_dir,
  1351. &_tx_thro_limit_fops);
  1352. }
  1353. wmt_tm_proc_dir = mtk_thermal_get_proc_drv_therm_dir_entry();
  1354. if (!wmt_tm_proc_dir) {
  1355. wmt_tm_printk("[%s]: mkdir /proc/driver/thermal failed\n", __func__);
  1356. } else {
  1357. entry =
  1358. proc_create("tzwmt", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, wmt_tm_proc_dir,
  1359. &_wmt_tm_fops);
  1360. if (entry)
  1361. proc_set_user(entry, uid, gid);
  1362. entry =
  1363. proc_create("clwmt_pid", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, wmt_tm_proc_dir,
  1364. &_tm_pid_fops);
  1365. if (entry)
  1366. proc_set_user(entry, uid, gid);
  1367. entry =
  1368. proc_create("clwmt_val", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, wmt_tm_proc_dir,
  1369. &_wmt_val_fops);
  1370. if (entry)
  1371. proc_set_user(entry, uid, gid);
  1372. entry =
  1373. proc_create("clwmt_wfdstat", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
  1374. wmt_tm_proc_dir, &_wfd_stat_fops);
  1375. if (entry)
  1376. proc_set_user(entry, uid, gid);
  1377. entry =
  1378. proc_create("wifi_in_soc", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
  1379. wmt_tm_proc_dir, &_wifi_in_soc_fops);
  1380. if (entry)
  1381. proc_set_user(entry, uid, gid);
  1382. }
  1383. return 0;
  1384. }
  1385. static int wmt_tm_proc_unregister(void)
  1386. {
  1387. wmt_tm_dprintk("[%s]\n", __func__);
  1388. /* remove_proc_entry("wmt_tm", proc_entry); */
  1389. return 0;
  1390. }
  1391. static int wmt_tm_thz_cl_register(void)
  1392. {
  1393. #define DEFAULT_POLL_TIME 0 /*Default disable, turn on by thermal policy */
  1394. struct linux_thermal_ctrl_if *p_linux_if = 0;
  1395. wmt_tm_dprintk("[%s]\n", __func__);
  1396. if (pg_wmt_tm)
  1397. p_linux_if = &pg_wmt_tm->linux_if;
  1398. else
  1399. return -1;
  1400. /* cooling devices */
  1401. p_linux_if->cl_dev = mtk_thermal_cooling_device_register("mtktswmt-sysrst", NULL,
  1402. &mtktspa_cooling_sysrst_ops);
  1403. p_linux_if->cl_pa1_dev = mtk_thermal_cooling_device_register("mtktswmt-pa1", NULL,
  1404. &mtktspa_cooling_pa1_ops);
  1405. p_linux_if->cl_pa2_dev = mtk_thermal_cooling_device_register("mtktswmt-pa2", NULL,
  1406. &mtktspa_cooling_pa2_ops);
  1407. #ifdef NEVER
  1408. p_linux_if->cl_pa3_dev = mtk_thermal_cooling_device_register("mtktswmt-pa3", NULL,
  1409. &mtktspa_cooling_pa3_ops);
  1410. #endif /* NEVER */
  1411. p_linux_if->interval = DEFAULT_POLL_TIME;
  1412. /* trips */
  1413. p_linux_if->thz_dev = mtk_thermal_zone_device_register("mtktswmt", g_num_trip, NULL,
  1414. &wmt_thz_dev_ops, 0, 0, 0,
  1415. p_linux_if->interval);
  1416. return 0;
  1417. }
  1418. static int wmt_tm_thz_cl_unregister(void)
  1419. {
  1420. struct linux_thermal_ctrl_if *p_linux_if = 0;
  1421. wmt_tm_dprintk("[%s]\n", __func__);
  1422. if (pg_wmt_tm)
  1423. p_linux_if = &pg_wmt_tm->linux_if;
  1424. else
  1425. return -1;
  1426. if (p_linux_if->cl_dev) {
  1427. mtk_thermal_cooling_device_unregister(p_linux_if->cl_dev);
  1428. p_linux_if->cl_dev = NULL;
  1429. }
  1430. if (p_linux_if->cl_pa1_dev) {
  1431. mtk_thermal_cooling_device_unregister(p_linux_if->cl_pa1_dev);
  1432. p_linux_if->cl_pa1_dev = NULL;
  1433. }
  1434. if (p_linux_if->cl_pa2_dev) {
  1435. mtk_thermal_cooling_device_unregister(p_linux_if->cl_pa2_dev);
  1436. p_linux_if->cl_pa2_dev = NULL;
  1437. }
  1438. #ifdef NEVER
  1439. if (p_linux_if->cl_pa3_dev) {
  1440. mtk_thermal_cooling_device_unregister(p_linux_if->cl_pa3_dev);
  1441. p_linux_if->cl_pa3_dev = NULL;
  1442. }
  1443. #endif /* NEVER */
  1444. if (p_linux_if->thz_dev) {
  1445. mtk_thermal_zone_device_unregister(p_linux_if->thz_dev);
  1446. p_linux_if->thz_dev = NULL;
  1447. }
  1448. return 0;
  1449. }
  1450. #if 0
  1451. static int wmt_tm_ops_register(struct wmt_thermal_ctrl_ops *ops)
  1452. {
  1453. struct wmt_thermal_ctrl_ops *p_des;
  1454. wmt_tm_printk("[%s]\n", __func__);
  1455. if (pg_wmt_tm) {
  1456. #if 1
  1457. p_des = &pg_wmt_tm->wmt_if.ops;
  1458. if (ops != NULL) {
  1459. wmt_tm_printk("[wmt_tm_ops_register] reg start ...\n");
  1460. p_des->query_temp = ops->query_temp;
  1461. p_des->set_temp = ops->set_temp;
  1462. wmt_tm_printk("[wmt_tm_ops_register] reg end ...\n");
  1463. } else {
  1464. p_des->query_temp = 0;
  1465. p_des->set_temp = 0;
  1466. }
  1467. #endif
  1468. return 0;
  1469. } else {
  1470. return -1;
  1471. }
  1472. }
  1473. static int wmt_tm_ops_unregister(void)
  1474. {
  1475. struct wmt_thermal_ctrl_ops *p_des;
  1476. wmt_tm_printk("[%s]\n", __func__);
  1477. if (pg_wmt_tm) {
  1478. p_des = &pg_wmt_tm->wmt_if.ops;
  1479. p_des->query_temp = 0;
  1480. p_des->set_temp = 0;
  1481. return 0;
  1482. } else {
  1483. return -1;
  1484. }
  1485. }
  1486. #endif
  1487. static int __init wmt_tm_init(void)
  1488. {
  1489. int err = 0;
  1490. wmt_tm_printk("[wmt_tm_init] start -->\n");
  1491. #if 0
  1492. err = wmt_tm_ops_register(ops);
  1493. if (err)
  1494. return err;
  1495. #endif
  1496. err = wmt_tm_proc_register();
  1497. if (err)
  1498. return err;
  1499. /* init a timer for stats tx bytes */
  1500. wmt_stats_info.pre_time = 0;
  1501. wmt_stats_info.pre_tx_bytes = 0;
  1502. init_timer_deferrable(&wmt_stats_timer);
  1503. wmt_stats_timer.function = (void *)&wmt_cal_stats;
  1504. wmt_stats_timer.data = (unsigned long)&wmt_stats_info;
  1505. wmt_stats_timer.expires = jiffies + 1 * HZ;
  1506. add_timer(&wmt_stats_timer);
  1507. #if 1
  1508. err = wmt_tm_thz_cl_register();
  1509. if (err)
  1510. return err;
  1511. #endif
  1512. wmt_tm_printk("[wmt_tm_init] end <--\n");
  1513. return 0;
  1514. }
  1515. #if 0
  1516. int wmt_tm_init_rt(void)
  1517. {
  1518. int err = 0;
  1519. wmt_tm_printk("[wmt_tm_init_rt] start -->\n");
  1520. err = wmt_tm_thz_cl_register();
  1521. if (err)
  1522. return err;
  1523. wmt_tm_printk("[wmt_tm_init_rt] end <--\n");
  1524. return 0;
  1525. }
  1526. int wmt_tm_deinit_rt(void)
  1527. {
  1528. int err = 0;
  1529. wmt_tm_printk("[wmt_tm_deinit_rt] start -->\n");
  1530. err = wmt_tm_thz_cl_unregister();
  1531. if (err)
  1532. return err;
  1533. wmt_tm_printk("[wmt_tm_deinit_rt] end <--\n");
  1534. return 0;
  1535. }
  1536. #endif
  1537. static void __exit wmt_tm_deinit(void)
  1538. {
  1539. int err = 0;
  1540. wmt_tm_printk("[%s]\n", __func__);
  1541. #if 1
  1542. err = wmt_tm_thz_cl_unregister();
  1543. if (err)
  1544. return;
  1545. #endif
  1546. err = wmt_tm_proc_unregister();
  1547. if (err)
  1548. return;
  1549. #if 0
  1550. err = wmt_tm_ops_unregister();
  1551. if (err)
  1552. return;
  1553. #endif
  1554. del_timer(&wmt_stats_timer);
  1555. }
  1556. /* EXPORT_SYMBOL(wifi_in_soc_throttle_enable); */
  1557. module_init(wmt_tm_init);
  1558. module_exit(wmt_tm_deinit);