1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
|
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/dmi.h>
#include <linux/acpi.h>
#include <linux/thermal.h>
#include <linux/platform_device.h>
#include <linux/aee.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "mach/mtk_thermal_monitor.h"
#include "mach/mt_typedefs.h"
#include "mach/mt_thermal.h"
#include <cust_pmic.h>
//#include <mach/pmic_mt6329_hw_bank1.h>
//#include <mach/pmic_mt6329_sw_bank1.h>
//#include <mach/pmic_mt6329_hw.h>
//#include <mach/pmic_mt6329_sw.h>
#include <mach/upmu_common_sw.h>
#include <mach/upmu_hw.h>
#include <mach/mt_pmic_wrap.h>
//2015.5.20 Jerry FIX_ME #include <mach/pmic_mt6331_6332_sw.h>
//#include <mach/pmic_mt6325_sw.h>
extern struct proc_dir_entry * mtk_thermal_get_proc_drv_therm_dir_entry(void);
extern u32 pmic_Read_Efuse_HPOffset(int i);
static unsigned int interval = 0; /* seconds, 0 : no auto polling */
static unsigned int trip_temp[10] = {120000,110000,100000,90000,80000,70000,65000,60000,55000,50000};
static unsigned int cl_dev_sysrst_state = 0;
static struct thermal_zone_device *thz_dev;
static struct thermal_cooling_device *cl_dev_sysrst;
static int mtktspmic_debug_log = 0;
static int kernelmode = 0;
static int g_THERMAL_TRIP[10] = {0,0,0,0,0,0,0,0,0,0};
static int num_trip=0;
static char g_bind0[20]={0};
static char g_bind1[20]={0};
static char g_bind2[20]={0};
static char g_bind3[20]={0};
static char g_bind4[20]={0};
static char g_bind5[20]={0};
static char g_bind6[20]={0};
static char g_bind7[20]={0};
static char g_bind8[20]={0};
static char g_bind9[20]={0};
/**
* If curr_temp >= polling_trip_temp1, use interval
* else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, use interval*polling_factor1
* else, use interval*polling_factor2
*/
static int polling_trip_temp1 = 40000;
static int polling_trip_temp2 = 20000;
static int polling_factor1 = 5000;
static int polling_factor2 = 10000;
#define mtktspmic_TEMP_CRIT 150000 /* 150.000 degree Celsius */
#define mtktspmic_dprintk(fmt, args...) \
do { \
if (mtktspmic_debug_log) { \
pr_notice("Power/PMIC_Thermal" fmt, ##args); \
} \
} while(0)
/* Cali */
static kal_int32 g_o_vts = 0;
static kal_int32 g_degc_cali = 0;
static kal_int32 g_adc_cali_en = 0;
static kal_int32 g_o_slope = 0;
static kal_int32 g_o_slope_sign = 0;
static kal_int32 g_id = 0;
static kal_int32 g_slope1= 1;
static kal_int32 g_slope2= 1;
static kal_int32 g_intercept;
//extern int PMIC_IMM_GetOneChannelValue(int dwChannel, int deCount, int trimd);
#define y_pmic_repeat_times 1
void mtktspmic_read_efuse(void);
extern kal_uint32 upmu_get_reg_value(kal_uint32 reg);
void mtktspmic_read_efuse(void)
{
U32 ret=0;
U32 reg_val=0;
int i=0,j=0;
U32 efusevalue[3];
printk("[mtktspmic_read_efuse] start\n");
#if 1
/*
0x8 640 655
0x9 656 671
0xa 672 687
Thermal data from 653 to 680
*/
efusevalue[0] = pmic_Read_Efuse_HPOffset(0x8);
efusevalue[1] = pmic_Read_Efuse_HPOffset(0x9);
efusevalue[2] = pmic_Read_Efuse_HPOffset(0xa);
printk("[mtktspmic_read_efuse]6328_efuse:\n"
"efusevalue[0]=0x%x\n"
"efusevalue[1]=0x%x\n"
"efusevalue[2]=0x%x\n\n"
,efusevalue[0], efusevalue[1], efusevalue[2]);
#else
//1. enable efuse ctrl engine clock
ret=pmic_config_interface(0x027C, 0x0040, 0xFFFF, 0);
ret=pmic_config_interface(0x0252, 0x0004, 0xFFFF, 0);
//2.
ret=pmic_config_interface(0x0C16, 0x1, 0x1, 0);
/*
0x8 640 655
0x9 656 671
0xa 672 687
Thermal data from 653 to 680
*/
for(i=0x8;i<=0xa;i++)
{
//3. set row to read
ret=pmic_config_interface(0x0C00, i, 0x1F, 1);
//4. Toggle
ret=pmic_read_interface(0xC10, ®_val, 0x1, 0);
if(reg_val==0)
ret=pmic_config_interface(0xC10, 1, 0x1, 0);
else
ret=pmic_config_interface(0xC10, 0, 0x1, 0);
reg_val=1;
while(reg_val == 1)
{
ret=pmic_read_interface(0xC1A, ®_val, 0x1, 0);
mtktspmic_dprintk("5. polling Reg[0x61A][0]=0x%x\n", reg_val);
}
udelay(1000);//Need to delay at least 1ms for 0x61A and than can read 0x618
printk("5. 6328 delay 1 ms\n");
//6. read data
efusevalue[j] = upmu_get_reg_value(0x0C18);
printk("6328_efuse : efusevalue[%d]=0x%x\n",j, efusevalue[j]);
j++;
}
//7. Disable efuse ctrl engine clock
ret=pmic_config_interface(0x0250, 0x0004, 0xFFFF, 0);
ret=pmic_config_interface(0x027A, 0x0040, 0xFFFF, 0); // new add
#endif
g_adc_cali_en = (efusevalue[0]>>13)&0x1;
g_degc_cali = ((efusevalue[0]>>14)&0x3) + ((efusevalue[1]& 0xF)<<2);
g_o_vts = ((efusevalue[1]>>4)&0x0FFF) + (((efusevalue[2])&0x1)<<11);
g_o_slope_sign= (efusevalue[2]>>1)&0x1;
g_o_slope = (efusevalue[2]>>2)&0x3F;
g_id = (efusevalue[2]>>8)&0x1;
//Note: O_SLOPE is signed integer.
//O_SLOPE_SIGN=1 ' it is Negative.
//O_SLOPE_SIGN=0 ' it is Positive.
printk("[mtktspmic_read_efuse]6328_efuse: g_o_vts = %x\n", g_o_vts);
printk("[mtktspmic_read_efuse]6328_efuse: g_degc_cali = %x\n", g_degc_cali);
printk("[mtktspmic_read_efuse]6328_efuse: g_adc_cali_en = %x\n", g_adc_cali_en);
printk("[mtktspmic_read_efuse]6328_efuse: g_o_slope = %x\n", g_o_slope);
printk("[mtktspmic_read_efuse]6328_efuse: g_o_slope_sign = %x\n", g_o_slope_sign);
printk("[mtktspmic_read_efuse]6328_efuse: g_id = %x\n", g_id);
printk("[mtktspmic_read_efuse] end\n");
}
void pmic_cali_prepare(void)
{
mtktspmic_read_efuse();
if(g_id==0)
{
g_o_slope=0;
}
//g_adc_cali_en=0;//FIX ME
if(g_adc_cali_en == 0) //no calibration
{
#if 0
g_o_vts = 3698;
g_degc_cali = 50;
g_o_slope = 0;
g_o_slope_sign = 0;
#else
g_o_vts = 1600;
g_degc_cali = 50;
g_o_slope = 0;
g_o_slope_sign = 0;
#endif
}
printk("Power/PMIC_Thermal: g_o_vts = 0x%x\n", g_o_vts);
printk("Power/PMIC_Thermal: g_degc_cali = 0x%x\n", g_degc_cali);
printk("Power/PMIC_Thermal: g_adc_cali_en = 0x%x\n", g_adc_cali_en);
printk("Power/PMIC_Thermal: g_o_slope = 0x%x\n", g_o_slope);
printk("Power/PMIC_Thermal: g_o_slope_sign = 0x%x\n", g_o_slope_sign);
printk("Power/PMIC_Thermal: g_id = 0x%x\n", g_id);
}
void pmic_cali_prepare2(void)
{
kal_int32 vbe_t;
g_slope1 = (100 * 1000); //1000 is for 0.001 degree
if(g_o_slope_sign==0)
{
g_slope2 = -(171+g_o_slope);
}
else
{
g_slope2 = -(171-g_o_slope);
}
vbe_t= (-1) * ((((g_o_vts)*1800))/4096)* 1000;
if(g_o_slope_sign==0)
{
g_intercept = (vbe_t * 100) / (-(171+g_o_slope)); //0.001 degree
}
else
{
g_intercept = (vbe_t * 100) / (-(171-g_o_slope)); //0.001 degree
}
g_intercept = g_intercept + (g_degc_cali*(1000/2)); // 1000 is for 0.1 degree
printk("[Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n",
g_slope1, g_slope2, g_intercept,vbe_t);
}
static kal_int32 pmic_raw_to_temp(kal_uint32 ret)
{
kal_int32 y_curr = ret;
kal_int32 t_current;
t_current = g_intercept + ((g_slope1 * y_curr) / (g_slope2));
mtktspmic_dprintk("[pmic_raw_to_temp] t_current=%d\n",t_current);
return t_current;
}
static DEFINE_MUTEX(TSPMIC_lock);
static int pre_temp1=0, PMIC_counter=0;
static int mtktspmic_get_hw_temp(void)
{
int temp=0, temp1=0;
mutex_lock(&TSPMIC_lock);
//AUX_TSENSE_AP is for MT6735
temp = PMIC_IMM_GetOneChannelValue(MT6328_AUX_CH4 , y_pmic_repeat_times , 2);
temp1 = pmic_raw_to_temp(temp);
//printk("[mtktspmic_get_hw_temp]Raw=%d, T=%d, 0xeb0=%x,temp2=%d\n",temp, temp1,temp2,upmu_get_reg_value(0xeb0));
if((temp1>100000) || (temp1<-30000))
{
printk("[Power/PMIC_Thermal] raw=%d, PMIC T=%d", temp, temp1);
}
if((temp1>150000) || (temp1<-50000))
{
printk("[Power/PMIC_Thermal] drop this data\n");
temp1 = pre_temp1;
}
else if( (PMIC_counter!=0) && (((pre_temp1-temp1)>30000) || ((temp1-pre_temp1)>30000)) )
{
printk("[Power/PMIC_Thermal] drop this data 2\n");
temp1 = pre_temp1;
}
else
{
//update previous temp
pre_temp1 = temp1;
mtktspmic_dprintk("[Power/PMIC_Thermal] pre_temp1=%d\n", pre_temp1);
if(PMIC_counter==0)
PMIC_counter++;
}
mutex_unlock(&TSPMIC_lock);
return temp1;
}
static int mtktspmic_get_temp(struct thermal_zone_device *thermal,
unsigned long *t)
{
*t = mtktspmic_get_hw_temp();
if ((int) *t >= polling_trip_temp1)
thermal->polling_delay = interval*1000;
else if ((int) *t < polling_trip_temp2)
thermal->polling_delay = interval * polling_factor2;
else
thermal->polling_delay = interval * polling_factor1;
return 0;
}
static int mtktspmic_bind(struct thermal_zone_device *thermal,
struct thermal_cooling_device *cdev)
{
int table_val=0;
if(!strcmp(cdev->type, g_bind0))
{
table_val = 0;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind1))
{
table_val = 1;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind2))
{
table_val = 2;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind3))
{
table_val = 3;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind4))
{
table_val = 4;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind5))
{
table_val = 5;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind6))
{
table_val = 6;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind7))
{
table_val = 7;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind8))
{
table_val = 8;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind9))
{
table_val = 9;
mtktspmic_dprintk("[mtktspmic_bind] %s\n", cdev->type);
}
else
{
return 0;
}
if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) {
mtktspmic_dprintk("[mtktspmic_bind] error binding cooling dev\n");
return -EINVAL;
} else {
mtktspmic_dprintk("[mtktspmic_bind] binding OK, %d\n", table_val);
}
return 0;
}
static int mtktspmic_unbind(struct thermal_zone_device *thermal,
struct thermal_cooling_device *cdev)
{
int table_val=0;
if(!strcmp(cdev->type, g_bind0))
{
table_val = 0;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind1))
{
table_val = 1;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind2))
{
table_val = 2;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind3))
{
table_val = 3;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind4))
{
table_val = 4;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind5))
{
table_val = 5;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind6))
{
table_val = 6;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind7))
{
table_val = 7;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind8))
{
table_val = 8;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else if(!strcmp(cdev->type, g_bind9))
{
table_val = 9;
mtktspmic_dprintk("[mtktspmic_unbind] %s\n", cdev->type);
}
else
return 0;
if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) {
mtktspmic_dprintk("[mtktspmic_unbind] error unbinding cooling dev\n");
return -EINVAL;
} else {
mtktspmic_dprintk("[mtktspmic_unbind] unbinding OK\n");
}
return 0;
}
static int mtktspmic_get_mode(struct thermal_zone_device *thermal,
enum thermal_device_mode *mode)
{
*mode = (kernelmode) ? THERMAL_DEVICE_ENABLED
: THERMAL_DEVICE_DISABLED;
return 0;
}
static int mtktspmic_set_mode(struct thermal_zone_device *thermal,
enum thermal_device_mode mode)
{
kernelmode = mode;
return 0;
}
static int mtktspmic_get_trip_type(struct thermal_zone_device *thermal, int trip,
enum thermal_trip_type *type)
{
*type = g_THERMAL_TRIP[trip];
return 0;
}
static int mtktspmic_get_trip_temp(struct thermal_zone_device *thermal, int trip,
unsigned long *temp)
{
*temp = trip_temp[trip];
return 0;
}
static int mtktspmic_get_crit_temp(struct thermal_zone_device *thermal,
unsigned long *temperature)
{
*temperature = mtktspmic_TEMP_CRIT;
return 0;
}
/* bind callback functions to thermalzone */
static struct thermal_zone_device_ops mtktspmic_dev_ops = {
.bind = mtktspmic_bind,
.unbind = mtktspmic_unbind,
.get_temp = mtktspmic_get_temp,
.get_mode = mtktspmic_get_mode,
.set_mode = mtktspmic_set_mode,
.get_trip_type = mtktspmic_get_trip_type,
.get_trip_temp = mtktspmic_get_trip_temp,
.get_crit_temp = mtktspmic_get_crit_temp,
};
static int tspmic_sysrst_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
*state = 1;
return 0;
}
static int tspmic_sysrst_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
*state = cl_dev_sysrst_state;
return 0;
}
static int tspmic_sysrst_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
{
cl_dev_sysrst_state = state;
if(cl_dev_sysrst_state == 1)
{
printk("Power/PMIC_Thermal: reset, reset, reset!!!");
printk("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
printk("*****************************************");
printk("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
// BUG();
*(unsigned int*) 0x0 = 0xdead; // To trigger data abort to reset the system for thermal protection.
//arch_reset(0,NULL);
}
return 0;
}
static struct thermal_cooling_device_ops mtktspmic_cooling_sysrst_ops = {
.get_max_state = tspmic_sysrst_get_max_state,
.get_cur_state = tspmic_sysrst_get_cur_state,
.set_cur_state = tspmic_sysrst_set_cur_state,
};
extern void mt6328_dump_register(void);
static int mtktspmic_read(struct seq_file *m, void *v)
{
// U16 pmic_data=0;
seq_printf(m, "[ mtktspmic_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,trip_4_temp=%d,\n\
trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n\
g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,\n\
g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n\
cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n\
cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n",
trip_temp[0],trip_temp[1],trip_temp[2],trip_temp[3],trip_temp[4],
trip_temp[5],trip_temp[6],trip_temp[7],trip_temp[8],trip_temp[9],
g_THERMAL_TRIP[0],g_THERMAL_TRIP[1],g_THERMAL_TRIP[2],g_THERMAL_TRIP[3],g_THERMAL_TRIP[4],
g_THERMAL_TRIP[5],g_THERMAL_TRIP[6],g_THERMAL_TRIP[7],g_THERMAL_TRIP[8],g_THERMAL_TRIP[9],
g_bind0,g_bind1,g_bind2,g_bind3,g_bind4,g_bind5,g_bind6,g_bind7,g_bind8,g_bind9,
interval*1000);
//mtktspmic_read_efuse();
//pmic_data = ts_pmic_read(0x0E9E);
//seq_printf(m,"/PMIC_Thermal: (efusevalue[0]>>15)&0x1 = 0x%x\n", (efusevalue[0]>>15)&0x1);
//seq_printf(m,"/PMIC_Thermal: ((efusevalue[1]&0x1F)<<1) = 0x%x\n", ((efusevalue[1]&0x1F)<<1));
seq_printf(m,"PMIC_Thermal: g_o_vts = 0x%x\n", g_o_vts);
seq_printf(m,"PMIC_Thermal: g_degc_cali = 0x%x\n", g_degc_cali);
seq_printf(m,"PMIC_Thermal: g_adc_cali_en = 0x%x\n", g_adc_cali_en);
seq_printf(m,"PMIC_Thermal: g_o_slope = 0x%x\n", g_o_slope);
seq_printf(m,"PMIC_Thermal: g_o_slope_sign = 0x%x\n", g_o_slope_sign);
seq_printf(m,"PMIC_Thermal: g_id = 0x%x\n", g_id);
//seq_printf(m,"PMIC_Thermal: : efusevalue[0]=0x%x,efusevalue[1]=0x%x,efusevalue[2]=0x%x\n",efusevalue[0],efusevalue[1],efusevalue[2]);
return 0;
}
int mtktspmic_register_thermal(void);
void mtktspmic_unregister_thermal(void);
static ssize_t mtktspmic_write(struct file *file, const char __user *buffer, size_t count, loff_t *data)
{
int len=0,time_msec=0;
int trip[10]={0};
int t_type[10]={0};
int i;
char bind0[20],bind1[20],bind2[20],bind3[20],bind4[20];
char bind5[20],bind6[20],bind7[20],bind8[20],bind9[20];
char desc[512];
len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1);
if (copy_from_user(desc, buffer, len))
{
return 0;
}
desc[len] = '\0';
if (sscanf(desc, "%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",
&num_trip, &trip[0],&t_type[0],bind0, &trip[1],&t_type[1],bind1,
&trip[2],&t_type[2],bind2, &trip[3],&t_type[3],bind3,
&trip[4],&t_type[4],bind4, &trip[5],&t_type[5],bind5,
&trip[6],&t_type[6],bind6, &trip[7],&t_type[7],bind7,
&trip[8],&t_type[8],bind8, &trip[9],&t_type[9],bind9,
&time_msec) == 32)
{
mtktspmic_dprintk("[mtktspmic_write] mtktspmic_unregister_thermal\n");
mtktspmic_unregister_thermal();
for(i=0; i<num_trip; i++)
g_THERMAL_TRIP[i] = t_type[i];
g_bind0[0]=g_bind1[0]=g_bind2[0]=g_bind3[0]=g_bind4[0]=g_bind5[0]=g_bind6[0]=g_bind7[0]=g_bind8[0]=g_bind9[0]='\0';
for(i=0; i<20; i++)
{
g_bind0[i]=bind0[i];
g_bind1[i]=bind1[i];
g_bind2[i]=bind2[i];
g_bind3[i]=bind3[i];
g_bind4[i]=bind4[i];
g_bind5[i]=bind5[i];
g_bind6[i]=bind6[i];
g_bind7[i]=bind7[i];
g_bind8[i]=bind8[i];
g_bind9[i]=bind9[i];
}
mtktspmic_dprintk("[mtktspmic_write] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,\
g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n",
g_THERMAL_TRIP[0],g_THERMAL_TRIP[1],g_THERMAL_TRIP[2],g_THERMAL_TRIP[3],g_THERMAL_TRIP[4],
g_THERMAL_TRIP[5],g_THERMAL_TRIP[6],g_THERMAL_TRIP[7],g_THERMAL_TRIP[8],g_THERMAL_TRIP[9]);
mtktspmic_dprintk("[mtktspmic_write] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\
cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n",
g_bind0,g_bind1,g_bind2,g_bind3,g_bind4,g_bind5,g_bind6,g_bind7,g_bind8,g_bind9);
for(i=0; i<num_trip; i++)
{
trip_temp[i]=trip[i];
}
interval=time_msec / 1000;
mtktspmic_dprintk("[mtktspmic_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,trip_4_temp=%d,\
trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,time_ms=%d\n",
trip_temp[0],trip_temp[1],trip_temp[2],trip_temp[3],trip_temp[4],
trip_temp[5],trip_temp[6],trip_temp[7],trip_temp[8],trip_temp[9],interval*1000);
mtktspmic_dprintk("[mtktspmic_write] mtktspmic_register_thermal\n");
mtktspmic_register_thermal();
return count;
}
else
{
mtktspmic_dprintk("[mtktspmic_write] bad argument\n");
}
return -EINVAL;
}
void mtkts_pmic_cancel_thermal_timer(void)
{
//cancel timer
//printk("mtkts_pmic_cancel_thermal_timer \n");
// stop thermal framework polling when entering deep idle
if (thz_dev)
cancel_delayed_work(&(thz_dev->poll_queue));
}
void mtkts_pmic_start_thermal_timer(void)
{
//printk("mtkts_pmic_start_thermal_timer \n");
// resume thermal framework polling when leaving deep idle
if (thz_dev != NULL && interval != 0)
mod_delayed_work(system_freezable_wq, &(thz_dev->poll_queue), round_jiffies(msecs_to_jiffies(1000))); // 60ms
}
int mtktspmic_register_cooler(void)
{
cl_dev_sysrst = mtk_thermal_cooling_device_register("mtktspmic-sysrst", NULL,
&mtktspmic_cooling_sysrst_ops);
return 0;
}
int mtktspmic_register_thermal(void)
{
mtktspmic_dprintk("[mtktspmic_register_thermal] \n");
/* trips : trip 0~2 */
thz_dev = mtk_thermal_zone_device_register("mtktspmic", num_trip, NULL,
&mtktspmic_dev_ops, 0, 0, 0, interval*1000);
return 0;
}
void mtktspmic_unregister_cooler(void)
{
if (cl_dev_sysrst) {
mtk_thermal_cooling_device_unregister(cl_dev_sysrst);
cl_dev_sysrst = NULL;
}
}
void mtktspmic_unregister_thermal(void)
{
mtktspmic_dprintk("[mtktspmic_unregister_thermal] \n");
if (thz_dev) {
mtk_thermal_zone_device_unregister(thz_dev);
thz_dev = NULL;
}
}
static int mtktspmic_open(struct inode *inode, struct file *file)
{
return single_open(file, mtktspmic_read, NULL);
}
static const struct file_operations mtktspmic_fops = {
.owner = THIS_MODULE,
.open = mtktspmic_open,
.read = seq_read,
.llseek = seq_lseek,
.write = mtktspmic_write,
.release = single_release,
};
static int mtktspmic_read_log(struct seq_file *m, void *v)
{
seq_printf(m, "mtktspmic_read_log = %d\n", mtktspmic_debug_log);
return 0;
}
static ssize_t mtktspmic_write_log(struct file *file, const char __user *buffer, size_t count, loff_t *data)
{
char desc[32];
int log_switch;
int len = 0;
len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1);
if (copy_from_user(desc, buffer, len))
{
return 0;
}
desc[len] = '\0';
if (sscanf(desc, "%d", &log_switch) == 1)
{
mtktspmic_debug_log = log_switch;
return count;
}
else
{
printk("mtktspmic_write_log bad argument\n");
}
return -EINVAL;
}
static int mtktspmic_open_log(struct inode *inode, struct file *file)
{
return single_open(file, mtktspmic_read_log, NULL);
}
static const struct file_operations mtktspmic_log_fops = {
.owner = THIS_MODULE,
.open = mtktspmic_open_log,
.read = seq_read,
.llseek = seq_lseek,
.write = mtktspmic_write_log,
.release = single_release,
};
static int __init mtktspmic_init(void)
{
int err = 0;
struct proc_dir_entry *entry = NULL;
struct proc_dir_entry *mtktspmic_dir = NULL;
printk("[mtktspmic_init] \n");
/*
bit4 RG_VBUF_EN 1: turn on Vbuf.
0: turn off Vbuf.
bit2 RG_VBUF_BYP 1: Bypass Vbuf.
0: turn on Vbuf.
RG_VBUF_EN = 1 / RG_VBUF_BYP = 0
pmic_data = ts_pmic_read(0x0E9E);
if((pmic_data>>4&0x1)!=1 || (pmic_data>>2&0x1)!=0)
printk("[mtktspmic_init]: Warrning !!! Need to checking this !!!!!\n");
*/
pmic_cali_prepare();
pmic_cali_prepare2();
err = mtktspmic_register_cooler();
if(err)
return err;
err = mtktspmic_register_thermal();
if (err)
goto err_unreg;
mtktspmic_dir = mtk_thermal_get_proc_drv_therm_dir_entry();
if (!mtktspmic_dir)
{
mtktspmic_dprintk("[%s]: mkdir /proc/driver/thermal failed\n", __func__);
}
else
{
entry = proc_create("tzpmic", S_IRUGO | S_IWUSR | S_IWGRP, mtktspmic_dir, &mtktspmic_fops);
if (entry) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
proc_set_user(entry, 0, 1000);
#else
entry->gid = 1000;
#endif
}
entry = proc_create("tzpmic_log", S_IRUGO | S_IWUSR, mtktspmic_dir, &mtktspmic_log_fops);
}
return 0;
err_unreg:
mtktspmic_unregister_cooler();
return err;
}
static void __exit mtktspmic_exit(void)
{
mtktspmic_dprintk("[mtktspmic_exit] \n");
mtktspmic_unregister_thermal();
mtktspmic_unregister_cooler();
}
module_init(mtktspmic_init);
module_exit(mtktspmic_exit);
|