1 /* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are
5  * met:
6  *  * Redistributions of source code must retain the above copyright
7  *    notice, this list of conditions and the following disclaimer.
8  *  * Redistributions in binary form must reproduce the above
9  *    copyright notice, this list of conditions and the following
10  *    disclaimer in the documentation and/or other materials provided
11  *    with the distribution.
12  *  * Neither the name of The Linux Foundation nor the names of its
13  *    contributors may be used to endorse or promote products derived
14  *    from this software without specific prior written permission.
15 
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #define LOG_TAG "ThermalHAL-TARGET"
30 #include <utils/Log.h>
31 
32 #include <hardware/hardware.h>
33 #include <hardware/thermal.h>
34 #include <stdlib.h>
35 #include "thermal_common.h"
36 
37 #define SYSFS_PLATFORMID   "/sys/devices/soc0/soc_id"
38 #define SOC_INFO_NAME_LEN  15
39 
40 struct therm_msm_soc_type {
41     enum therm_msm_id msm_id;
42     int  soc_id;
43 };
44 
45 static struct therm_msm_soc_type msm_soc_table[] = {
46     {THERM_MSM_8953, 293},
47     {THERM_MSM_8953, 304},
48     {THERM_MSM_8953, 338},
49     {THERM_MSM_8953, 351},
50     {THERM_SDM_660, 317},
51     {THERM_SDM_660, 324},
52     {THERM_SDM_660, 325},
53     {THERM_SDM_660, 326},
54     {THERM_SDM_660, 345},
55     {THERM_SDM_660, 346},
56     {THERM_SDM_630, 318},
57     {THERM_SDM_630, 327},
58     {THERM_SDM_630, 385},
59     {THERM_SDM_710, 336},
60     {THERM_SDM_710, 337},
61     {THERM_SDM_710, 393}, // This SOC ID is for SDM712
62     {THERM_QCS_605, 347},
63     {THERM_SDM_632, 349},
64     {THERM_SDM_632, 350},
65     {THERM_SDM_439, 353},
66     {THERM_SDM_439, 354},
67     {THERM_SDM_439, 363},
68     {THERM_SDM_439, 364},
69     {THERM_MSMNILE, 339},
70     {THERM_MSMNILE, 361},
71     {THERM_MSMNILE, 362},
72     {THERM_MSMNILE, 367},
73     {THERM_KONA, 356},
74     {THERM_TALOS,  355},
75     {THERM_SDMMAGPIE, 365},
76     {THERM_MSM_8917, 303},
77     {THERM_MSM_8917, 307},
78     {THERM_MSM_8917, 308},
79     {THERM_MSM_8917, 309},
80     {THERM_MSM_8917, 386}, // This SOC ID is for QM215
81     {THERM_MSM_8917, 436}, // This SOC ID is for QCM2150
82     {THERM_TRINKET,  394},
83     {THERM_LITO,  400},
84     {THERM_ATOLL,  407},
85     {THERM_BENGAL,  417},
86 };
87 
88 static char *cpu_sensors_talos[] =
89 {
90     "cpuss-2-usr",
91     "cpuss-2-usr",
92     "cpuss-1-usr",
93     "cpuss-1-usr",
94     "cpuss-0-usr",
95     "cpuss-0-usr",
96     "cpu-1-0-usr",
97     "cpu-1-2-usr",
98 };
99 
100 static char *misc_sensors_talos[] =
101 {
102     "gpu-usr",
103     "battery",
104     "xo-therm"
105 };
106 
107 static struct target_therm_cfg sensor_cfg_talos[] = {
108     {
109         .type = DEVICE_TEMPERATURE_CPU,
110         .sensor_list = cpu_sensors_talos,
111         .sens_cnt = ARRAY_SIZE(cpu_sensors_talos),
112         .mult = 0.001,
113     },
114     {
115         .type = DEVICE_TEMPERATURE_GPU,
116         .sensor_list = &misc_sensors_talos[0],
117         .sens_cnt = 1,
118         .mult = 0.001,
119         .label = "GPU",
120     },
121     {
122         .type = DEVICE_TEMPERATURE_BATTERY,
123         .sensor_list = &misc_sensors_talos[1],
124         .sens_cnt = 1,
125         .mult = 0.001,
126         .label = "battery",
127     },
128     {
129         .type = DEVICE_TEMPERATURE_SKIN,
130         .sensor_list = &misc_sensors_talos[2],
131         .sens_cnt = 1,
132         .mult = 0.001,
133         .label = "skin",
134     }
135 };
136 
137 static char *cpu_sensors_sdmmagpie[] =
138 {
139     "cpu-0-0-usr",
140     "cpu-0-1-usr",
141     "cpu-0-2-usr",
142     "cpu-0-3-usr",
143     "cpu-0-4-usr",
144     "cpu-0-5-usr",
145     "cpu-1-0-usr",
146     "cpu-1-2-usr",
147 };
148 
149 static char *misc_sensors_sdmmagpie[] =
150 {
151     "gpuss-0-usr",
152     "battery",
153     "xo-therm-adc"
154 };
155 
156 static struct target_therm_cfg sensor_cfg_sdmmagpie[] = {
157     {
158         .type = DEVICE_TEMPERATURE_CPU,
159         .sensor_list = cpu_sensors_sdmmagpie,
160         .sens_cnt = ARRAY_SIZE(cpu_sensors_sdmmagpie),
161         .mult = 0.001,
162     },
163     {
164         .type = DEVICE_TEMPERATURE_GPU,
165         .sensor_list = &misc_sensors_sdmmagpie[0],
166         .sens_cnt = 1,
167         .mult = 0.001,
168         .label = "GPU",
169     },
170     {
171         .type = DEVICE_TEMPERATURE_BATTERY,
172         .sensor_list = &misc_sensors_sdmmagpie[1],
173         .sens_cnt = 1,
174         .mult = 0.001,
175         .label = "battery",
176     },
177     {
178         .type = DEVICE_TEMPERATURE_SKIN,
179         .sensor_list = &misc_sensors_sdmmagpie[2],
180         .sens_cnt = 1,
181         .mult = 0.001,
182         .label = "skin",
183     }
184 };
185 
186 static char *misc_sensors_lito[] =
187 {
188     "gpuss-0-usr",
189     "battery",
190     "xo-therm-usr"
191 };
192 
193 static struct target_therm_cfg sensor_cfg_lito[] = {
194     {
195         .type = DEVICE_TEMPERATURE_CPU,
196         .sensor_list = cpu_sensors_sdmmagpie,
197         .sens_cnt = ARRAY_SIZE(cpu_sensors_sdmmagpie),
198         .mult = 0.001,
199     },
200     {
201         .type = DEVICE_TEMPERATURE_GPU,
202         .sensor_list = &misc_sensors_lito[0],
203         .sens_cnt = 1,
204         .mult = 0.001,
205         .label = "GPU",
206     },
207     {
208         .type = DEVICE_TEMPERATURE_BATTERY,
209         .sensor_list = &misc_sensors_lito[1],
210         .sens_cnt = 1,
211         .mult = 0.001,
212         .label = "battery",
213     },
214     {
215         .type = DEVICE_TEMPERATURE_SKIN,
216         .sensor_list = &misc_sensors_lito[2],
217         .sens_cnt = 1,
218         .mult = 0.001,
219         .label = "skin",
220     }
221 };
222 
223 static char *cpu_sensors_trinket[] =
224 {
225     "cpuss-0-usr",
226     "cpuss-0-usr",
227     "cpuss-0-usr",
228     "cpuss-0-usr",
229     "cpu-1-0-usr",
230     "cpu-1-1-usr",
231     "cpu-1-2-usr",
232     "cpu-1-3-usr",
233 };
234 
235 static char *misc_sensors_trinket[] =
236 {
237     "gpu-usr",
238     "battery",
239     "xo-therm-adc"
240 };
241 
242 static struct target_therm_cfg sensor_cfg_trinket[] = {
243     {
244         .type = DEVICE_TEMPERATURE_CPU,
245         .sensor_list = cpu_sensors_trinket,
246         .sens_cnt = ARRAY_SIZE(cpu_sensors_trinket),
247         .mult = 0.001,
248     },
249     {
250         .type = DEVICE_TEMPERATURE_GPU,
251         .sensor_list = &misc_sensors_trinket[0],
252         .sens_cnt = 1,
253         .mult = 0.001,
254         .label = "GPU",
255     },
256     {
257         .type = DEVICE_TEMPERATURE_BATTERY,
258         .sensor_list = &misc_sensors_trinket[1],
259         .sens_cnt = 1,
260         .mult = 0.001,
261         .label = "battery",
262     },
263     {
264         .type = DEVICE_TEMPERATURE_SKIN,
265         .sensor_list = &misc_sensors_trinket[2],
266         .sens_cnt = 1,
267         .mult = 0.001,
268         .label = "skin",
269     }
270 };
271 
272 static char *cpu_sensors_bengal[] =
273 {
274     "cpuss-2-usr",
275     "cpuss-2-usr",
276     "cpuss-2-usr",
277     "cpuss-2-usr",
278     "cpu-1-0-usr",
279     "cpu-1-1-usr",
280     "cpu-1-2-usr",
281     "cpu-1-3-usr",
282 };
283 
284 static char *misc_sensors_bengal[] =
285 {
286     "gpu-usr",
287     "battery",
288     "xo-therm-usr"
289 };
290 
291 static struct target_therm_cfg sensor_cfg_bengal[] = {
292     {
293         .type = DEVICE_TEMPERATURE_CPU,
294         .sensor_list = cpu_sensors_bengal,
295         .sens_cnt = ARRAY_SIZE(cpu_sensors_bengal),
296         .mult = 0.001,
297     },
298     {
299         .type = DEVICE_TEMPERATURE_GPU,
300         .sensor_list = &misc_sensors_bengal[0],
301         .sens_cnt = 1,
302         .mult = 0.001,
303         .label = "GPU",
304     },
305     {
306         .type = DEVICE_TEMPERATURE_BATTERY,
307         .sensor_list = &misc_sensors_bengal[1],
308         .sens_cnt = 1,
309         .mult = 0.001,
310         .label = "battery",
311     },
312     {
313         .type = DEVICE_TEMPERATURE_SKIN,
314         .sensor_list = &misc_sensors_bengal[2],
315         .sens_cnt = 1,
316         .mult = 0.001,
317         .label = "skin",
318     }
319 };
320 
321 static char *cpu_sensors_msmnile[] =
322 {
323     "cpu-0-0-usr",
324     "cpu-0-1-usr",
325     "cpu-0-2-usr",
326     "cpu-0-3-usr",
327     "cpu-1-0-usr",
328     "cpu-1-1-usr",
329     "cpu-1-2-usr",
330     "cpu-1-3-usr",
331 };
332 
333 static char *misc_sensors_msmnile[] =
334 {
335     "gpuss-0-usr",
336     "battery",
337     "xo-therm"
338 };
339 
340 static struct target_therm_cfg sensor_cfg_msmnile[] = {
341     {
342         .type = DEVICE_TEMPERATURE_CPU,
343         .sensor_list = cpu_sensors_msmnile,
344         .sens_cnt = ARRAY_SIZE(cpu_sensors_msmnile),
345         .mult = 0.001,
346     },
347     {
348         .type = DEVICE_TEMPERATURE_GPU,
349         .sensor_list = &misc_sensors_msmnile[0],
350         .sens_cnt = 1,
351         .mult = 0.001,
352         .label = "GPU",
353     },
354     {
355         .type = DEVICE_TEMPERATURE_BATTERY,
356         .sensor_list = &misc_sensors_msmnile[1],
357         .sens_cnt = 1,
358         .mult = 0.001,
359         .label = "battery",
360     },
361     {
362         .type = DEVICE_TEMPERATURE_SKIN,
363         .sensor_list = &misc_sensors_msmnile[2],
364         .sens_cnt = 1,
365         .mult = 0.001,
366         .label = "skin",
367     }
368 };
369 
370 static struct target_therm_cfg sensor_cfg_kona[] = {
371     {
372         .type = DEVICE_TEMPERATURE_CPU,
373         .sensor_list = cpu_sensors_msmnile,
374         .sens_cnt = ARRAY_SIZE(cpu_sensors_msmnile),
375         .mult = 0.001,
376     },
377     {
378         .type = DEVICE_TEMPERATURE_GPU,
379         .sensor_list = &misc_sensors_lito[0],
380         .sens_cnt = 1,
381         .mult = 0.001,
382         .label = "GPU",
383     },
384     {
385         .type = DEVICE_TEMPERATURE_BATTERY,
386         .sensor_list = &misc_sensors_lito[1],
387         .sens_cnt = 1,
388         .mult = 0.001,
389         .label = "battery",
390     },
391     {
392         .type = DEVICE_TEMPERATURE_SKIN,
393         .sensor_list = &misc_sensors_lito[2],
394         .sens_cnt = 1,
395         .mult = 0.001,
396         .label = "skin",
397     }
398 };
399 
400 static char *cpu_sensors_660[] =
401 {
402     "tsens_tz_sensor1",
403     "tsens_tz_sensor1",
404     "tsens_tz_sensor1",
405     "tsens_tz_sensor1",
406     "tsens_tz_sensor3",
407     "tsens_tz_sensor4",
408     "tsens_tz_sensor5",
409     "tsens_tz_sensor6",
410 };
411 
412 static char *misc_sensors_660[] =
413 {
414     "tsens_tz_sensor8",
415     "battery",
416     "xo_therm"
417 };
418 
419 static struct target_therm_cfg sensor_cfg_660[] = {
420     {
421         .type = DEVICE_TEMPERATURE_CPU,
422         .sensor_list = cpu_sensors_660,
423         .sens_cnt = ARRAY_SIZE(cpu_sensors_660),
424         .mult = 0.1,
425     },
426     {
427         .type = DEVICE_TEMPERATURE_GPU,
428         .sensor_list = &misc_sensors_660[0],
429         .sens_cnt = 1,
430         .mult = 0.1,
431         .label = "GPU",
432     },
433     {
434         .type = DEVICE_TEMPERATURE_BATTERY,
435         .sensor_list = &misc_sensors_660[1],
436         .sens_cnt = 1,
437         .mult = 0.001,
438         .label = "battery",
439     },
440     {
441         .type = DEVICE_TEMPERATURE_SKIN,
442         .sensor_list = &misc_sensors_660[2],
443         .sens_cnt = 1,
444         .mult = 1,
445         .label = "skin",
446     }
447 };
448 
449 static char *cpu_sensors_630[] =
450 {
451     "tsens_tz_sensor3",
452     "tsens_tz_sensor4",
453     "tsens_tz_sensor5",
454     "tsens_tz_sensor6",
455     "tsens_tz_sensor7",
456     "tsens_tz_sensor7",
457     "tsens_tz_sensor7",
458     "tsens_tz_sensor7",
459 };
460 
461 static struct target_therm_cfg sensor_cfg_630[] = {
462     {
463         .type = DEVICE_TEMPERATURE_CPU,
464         .sensor_list = cpu_sensors_630,
465         .sens_cnt = ARRAY_SIZE(cpu_sensors_630),
466         .mult = 0.1,
467     },
468     {
469         .type = DEVICE_TEMPERATURE_GPU,
470         .sensor_list = &misc_sensors_660[0],
471         .sens_cnt = 1,
472         .mult = 0.1,
473         .label = "GPU",
474     },
475     {
476         .type = DEVICE_TEMPERATURE_BATTERY,
477         .sensor_list = &misc_sensors_660[1],
478         .sens_cnt = 1,
479         .mult = 0.001,
480         .label = "battery",
481     },
482     {
483         .type = DEVICE_TEMPERATURE_SKIN,
484         .sensor_list = &misc_sensors_660[2],
485         .sens_cnt = 1,
486         .mult = 1,
487         .label = "skin",
488     }
489 };
490 
491 static char *cpu_sensors_8953[] =
492 {
493     "tsens_tz_sensor9",
494     "tsens_tz_sensor10",
495     "tsens_tz_sensor11",
496     "tsens_tz_sensor12",
497     "tsens_tz_sensor4",
498     "tsens_tz_sensor5",
499     "tsens_tz_sensor6",
500     "tsens_tz_sensor7",
501 };
502 
503 static char *misc_sensors_8953[] =
504 {
505     "tsens_tz_sensor15",
506     "battery",
507     "xo_therm"
508 };
509 
510 static struct target_therm_cfg sensor_cfg_8953[] = {
511     {
512         .type = DEVICE_TEMPERATURE_CPU,
513         .sensor_list = cpu_sensors_8953,
514         .sens_cnt = ARRAY_SIZE(cpu_sensors_8953),
515         .mult = 0.1,
516     },
517     {
518         .type = DEVICE_TEMPERATURE_GPU,
519         .sensor_list = &misc_sensors_8953[0],
520         .sens_cnt = 1,
521         .mult = 0.1,
522         .label = "GPU",
523     },
524     {
525         .type = DEVICE_TEMPERATURE_BATTERY,
526         .sensor_list = &misc_sensors_8953[1],
527         .sens_cnt = 1,
528         .mult = 0.001,
529         .label = "battery",
530     },
531     {
532         .type = DEVICE_TEMPERATURE_SKIN,
533         .sensor_list = &misc_sensors_8953[2],
534         .sens_cnt = 1,
535         .mult = 1,
536         .label = "skin",
537     }
538 };
539 
540 
541 static char *cpu_sensors_710[] =
542 {
543     "cpu0-silver-usr",
544     "cpu1-silver-usr",
545     "cpu2-silver-usr",
546     "cpu3-silver-usr",
547     "cpu4-silver-usr",
548     "cpu5-silver-usr",
549     "cpu0-gold-usr",
550     "cpu1-gold-usr",
551 };
552 
553 static char *misc_sensors_710[] =
554 {
555     "gpu0-usr",
556     "battery",
557     "xo-therm-adc"
558 };
559 
560 static struct target_therm_cfg sensor_cfg_710[] = {
561     {
562         .type = DEVICE_TEMPERATURE_CPU,
563         .sensor_list = cpu_sensors_710,
564         .sens_cnt = ARRAY_SIZE(cpu_sensors_710),
565         .mult = 0.001,
566     },
567     {
568         .type = DEVICE_TEMPERATURE_GPU,
569         .sensor_list = &misc_sensors_710[0],
570         .sens_cnt = 1,
571         .mult = 0.001,
572         .label = "GPU",
573     },
574     {
575         .type = DEVICE_TEMPERATURE_BATTERY,
576         .sensor_list = &misc_sensors_710[1],
577         .sens_cnt = 1,
578         .mult = 0.001,
579         .label = "battery",
580     },
581     {
582         .type = DEVICE_TEMPERATURE_SKIN,
583         .sensor_list = &misc_sensors_710[2],
584         .sens_cnt = 1,
585         .mult = 0.001,
586         .label = "skin",
587     }
588 };
589 
590 static char *cpu_sensors_632[] =
591 {
592     "cpuss0-usr",
593     "cpuss0-usr",
594     "cpuss0-usr",
595     "cpuss0-usr",
596     "apc1-cpu0-usr",
597     "apc1-cpu1-usr",
598     "apc1-cpu2-usr",
599     "apc1-cpu3-usr",
600 };
601 
602 static char *misc_sensors_632[] =
603 {
604     "gpu0-usr",
605     "battery",
606     "quiet-therm-adc"
607 };
608 
609 static struct target_therm_cfg sensor_cfg_632[] = {
610     {
611         .type = DEVICE_TEMPERATURE_CPU,
612         .sensor_list = cpu_sensors_632,
613         .sens_cnt = ARRAY_SIZE(cpu_sensors_632),
614         .mult = 0.001,
615     },
616     {
617         .type = DEVICE_TEMPERATURE_GPU,
618         .sensor_list = &misc_sensors_632[0],
619         .sens_cnt = 1,
620         .mult = 0.001,
621         .label = "GPU",
622     },
623     {
624         .type = DEVICE_TEMPERATURE_BATTERY,
625         .sensor_list = &misc_sensors_632[1],
626         .sens_cnt = 1,
627         .mult = 0.001,
628         .label = "battery",
629     },
630     {
631         .type = DEVICE_TEMPERATURE_SKIN,
632         .sensor_list = &misc_sensors_632[2],
633         .sens_cnt = 1,
634         .mult = 0.001,
635         .label = "skin",
636     }
637 };
638 
639 static char *cpu_sensors_439[] =
640 {
641     "apc1-cpu0-usr",
642     "apc1-cpu1-usr",
643     "apc1-cpu2-usr",
644     "apc1-cpu3-usr",
645     "cpuss0-usr",
646     "cpuss0-usr",
647     "cpuss0-usr",
648     "cpuss0-usr",
649 };
650 
651 static char *misc_sensors_439[] =
652 {
653     "gpu-usr",
654     "battery",
655     "quiet-therm-adc"
656 };
657 
658 static struct target_therm_cfg sensor_cfg_439[] = {
659     {
660         .type = DEVICE_TEMPERATURE_CPU,
661         .sensor_list = cpu_sensors_439,
662         .sens_cnt = ARRAY_SIZE(cpu_sensors_439),
663         .mult = 0.001,
664     },
665     {
666         .type = DEVICE_TEMPERATURE_GPU,
667         .sensor_list = &misc_sensors_439[0],
668         .sens_cnt = 1,
669         .mult = 0.001,
670         .label = "GPU",
671     },
672     {
673         .type = DEVICE_TEMPERATURE_BATTERY,
674         .sensor_list = &misc_sensors_439[1],
675         .sens_cnt = 1,
676         .mult = 0.001,
677         .label = "battery",
678     },
679     {
680         .type = DEVICE_TEMPERATURE_SKIN,
681         .sensor_list = &misc_sensors_439[2],
682         .sens_cnt = 1,
683         .mult = 0.001,
684         .label = "skin",
685     }
686 };
687 
688 static char *cpu_sensors_8917[] =
689 {
690     "apc1-cpu0-usr",
691     "apc1-cpu1-usr",
692     "apc1-cpu2-usr",
693     "apc1-cpu3-usr",
694 };
695 
696 static char *misc_sensors_8917[] =
697 {
698     "gpu0-usr",
699     "battery",
700     "xo-therm-adc"
701 };
702 
703 static struct target_therm_cfg sensor_cfg_8917[] = {
704     {
705         .type = DEVICE_TEMPERATURE_CPU,
706         .sensor_list = cpu_sensors_8917,
707         .sens_cnt = ARRAY_SIZE(cpu_sensors_8917),
708         .mult = 0.001,
709     },
710     {
711         .type = DEVICE_TEMPERATURE_GPU,
712         .sensor_list = &misc_sensors_8917[0],
713         .sens_cnt = 1,
714         .mult = 0.001,
715         .label = "GPU",
716     },
717     {
718         .type = DEVICE_TEMPERATURE_BATTERY,
719         .sensor_list = &misc_sensors_8917[1],
720         .sens_cnt = 1,
721         .mult = 0.001,
722         .label = "battery",
723     },
724     {
725         .type = DEVICE_TEMPERATURE_SKIN,
726         .sensor_list = &misc_sensors_8917[2],
727         .sens_cnt = 1,
728         .mult = 0.001,
729         .label = "skin",
730     }
731 };
732 
get_soc_info(char * buf)733 static int get_soc_info(char *buf)
734 {
735     int ret = 0;
736 
737     ret = read_line_from_file(SYSFS_PLATFORMID, buf, SOC_INFO_NAME_LEN);
738     if (ret < 0) {
739         ALOGE("Error getting platform_id %d", ret);
740         return ret;
741     }
742     if (ret && buf[ret - 1] == '\n')
743         buf[ret - 1] = '\0';
744 
745     return ret;
746 }
747 
therm_get_soc_id(void)748 enum therm_msm_id therm_get_soc_id(void)
749 {
750     static enum therm_msm_id msm_id;
751     int soc_id = -1;
752 
753     if (!msm_id) {
754         int idx;
755         char buf[SOC_INFO_NAME_LEN];
756 
757         if (get_soc_info(buf) <= 0)
758             return msm_id;
759 
760         soc_id = atoi(buf);
761         for (idx = 0; idx < ARRAY_SIZE(msm_soc_table); idx++) {
762             if (soc_id == msm_soc_table[idx].soc_id) {
763                 msm_id = msm_soc_table[idx].msm_id;
764                 break;
765             }
766         }
767         if (!msm_id)
768             ALOGE("Unknown target identified with soc id %d\n", soc_id);
769    }
770 
771    return msm_id;
772 }
773 
get_temperatures(thermal_module_t * module,temperature_t * list,size_t size)774 ssize_t get_temperatures(thermal_module_t *module, temperature_t *list, size_t size) {
775     ALOGD("Entering %s",__func__);
776     static int thermal_sens_size;
777 
778     if (!thermal_sens_size) {
779 	struct target_therm_cfg *cfg = NULL;
780         size_t num_cfg = 0;
781 
782         switch (therm_get_soc_id()) {
783             case THERM_MSM_8953:
784                 cfg = sensor_cfg_8953;
785                 num_cfg = ARRAY_SIZE(sensor_cfg_8953);
786                 break;
787             case THERM_SDM_660:
788                 cfg = sensor_cfg_660;
789                 num_cfg = ARRAY_SIZE(sensor_cfg_660);
790                 break;
791             case THERM_SDM_630:
792                 cfg = sensor_cfg_630;
793                 num_cfg = ARRAY_SIZE(sensor_cfg_630);
794                 break;
795             case THERM_SDM_710:
796             case THERM_QCS_605:
797                 cfg = sensor_cfg_710;
798                 num_cfg = ARRAY_SIZE(sensor_cfg_710);
799                 break;
800             case THERM_SDM_632:
801                 cfg = sensor_cfg_632;
802                 num_cfg = ARRAY_SIZE(sensor_cfg_632);
803                 break;
804             case THERM_SDM_439:
805                 cfg = sensor_cfg_439;
806                 num_cfg = ARRAY_SIZE(sensor_cfg_439);
807                 break;
808             case THERM_MSM_8917:
809                 cfg = sensor_cfg_8917;
810                 num_cfg = ARRAY_SIZE(sensor_cfg_8917);
811                 break;
812             case THERM_MSMNILE:
813                 cfg = sensor_cfg_msmnile;
814                 num_cfg = ARRAY_SIZE(sensor_cfg_msmnile);
815                 break;
816             case THERM_KONA:
817 		cfg = sensor_cfg_kona;
818 		num_cfg = ARRAY_SIZE(sensor_cfg_kona);
819 		break;
820             case THERM_TALOS:
821                 cfg = sensor_cfg_talos;
822                 num_cfg = ARRAY_SIZE(sensor_cfg_talos);
823                 break;
824             case THERM_SDMMAGPIE:
825                 cfg = sensor_cfg_sdmmagpie;
826                 num_cfg = ARRAY_SIZE(sensor_cfg_sdmmagpie);
827                 break;
828             case THERM_TRINKET:
829                 cfg = sensor_cfg_trinket;
830                 num_cfg = ARRAY_SIZE(sensor_cfg_trinket);
831                 break;
832             case THERM_BENGAL:
833                 cfg = sensor_cfg_bengal;
834                 num_cfg = ARRAY_SIZE(sensor_cfg_bengal);
835                 break;
836             case THERM_LITO:
837             case THERM_ATOLL:
838                 cfg = sensor_cfg_lito;
839                 num_cfg = ARRAY_SIZE(sensor_cfg_lito);
840                 break;
841             default:
842                 cfg = NULL;
843                 num_cfg = 0;
844                 break;
845 	}
846 	if (cfg == NULL || num_cfg == 0) {
847             ALOGE("No target specific sensor config\n");
848             return 0;
849 	}
850 	thermal_sens_size = thermal_zone_init(cfg, num_cfg);
851 	if (thermal_sens_size <= 0) {
852             ALOGE("thermal sensor initialization is failed\n");
853             thermal_sens_size = 0;
854 	    return 0;
855         }
856     }
857 
858     if (list == NULL)
859         return thermal_sens_size;
860 
861     return get_temperature_for_all(list, size);
862 }
863