@@ -364,6 +364,7 @@ static ssize_t store_fan_mode(struct class *cls, struct class_attribute *attr,
364
364
return count ;
365
365
}
366
366
367
+
367
368
static ssize_t show_fan_level (struct class * cls ,
368
369
struct class_attribute * attr , char * buf )
369
370
{
@@ -400,6 +401,111 @@ static ssize_t show_fan_temp(struct class *cls,
400
401
return sprintf (buf , "cpu_temp:%d\nFan trigger temperature: level0:%d level1:%d level2:%d\n" , temp , g_mcu_data -> fan_data .trig_temp_level0 , g_mcu_data -> fan_data .trig_temp_level1 , g_mcu_data -> fan_data .trig_temp_level2 );
401
402
}
402
403
404
+
405
+ void fan_level_set (struct mcu_data * ug_mcu_data ){
406
+
407
+ struct mcu_fan_data * fan_data = & g_mcu_data -> fan_data ;
408
+ int temp = - EINVAL ;
409
+
410
+ if ((KHADAS_BOARD_VIM1 == ug_mcu_data -> board ) ||
411
+ (KHADAS_BOARD_VIM2 == ug_mcu_data -> board ))
412
+ temp = get_cpu_temp ();
413
+ else if (KHADAS_BOARD_VIM3 == ug_mcu_data -> board )
414
+ temp = meson_get_temperature ();
415
+
416
+ if (temp != - EINVAL ){
417
+ if (temp < ug_mcu_data -> fan_data .trig_temp_level0 ) {
418
+ mcu_fan_level_set (fan_data , 0 );
419
+ }else if (temp < ug_mcu_data -> fan_data .trig_temp_level1 ) {
420
+ mcu_fan_level_set (fan_data , 1 );
421
+ }else if (temp < ug_mcu_data -> fan_data .trig_temp_level2 ) {
422
+ mcu_fan_level_set (fan_data , 2 );
423
+ }else {
424
+ mcu_fan_level_set (fan_data , 3 );
425
+ }
426
+ }
427
+ }
428
+
429
+
430
+ static ssize_t show_fan_trigger_low (struct class * cls ,
431
+ struct class_attribute * attr , char * buf ){
432
+
433
+ return sprintf (buf , "Fan trigger low speed temperature:%d\n" , g_mcu_data -> fan_data .trig_temp_level0 );
434
+ }
435
+
436
+ static ssize_t store_fan_trigger_low (struct class * cls , struct class_attribute * attr ,
437
+ const char * buf , size_t count ){
438
+
439
+ int trigger ;
440
+
441
+ if (kstrtoint (buf , 0 , & trigger ))
442
+ return - EINVAL ;
443
+
444
+ if (trigger >= g_mcu_data -> fan_data .trig_temp_level1 ){
445
+ pr_err ("Invalid parameter\n" );
446
+ return - EINVAL ;
447
+ }
448
+
449
+ g_mcu_data -> fan_data .trig_temp_level0 = trigger ;
450
+
451
+ fan_level_set (g_mcu_data );
452
+
453
+ return count ;
454
+ }
455
+
456
+ static ssize_t show_fan_trigger_mid (struct class * cls ,
457
+ struct class_attribute * attr , char * buf ){
458
+
459
+ return sprintf (buf , "Fan trigger mid speed temperature:%d\n" , g_mcu_data -> fan_data .trig_temp_level1 );
460
+ }
461
+
462
+ static ssize_t store_fan_trigger_mid (struct class * cls , struct class_attribute * attr ,
463
+ const char * buf , size_t count ){
464
+
465
+ int trigger ;
466
+
467
+ if (kstrtoint (buf , 0 , & trigger ))
468
+ return - EINVAL ;
469
+
470
+ if (trigger >= g_mcu_data -> fan_data .trig_temp_level2 || trigger <= g_mcu_data -> fan_data .trig_temp_level0 ){
471
+ pr_err ("Invalid parameter\n" );
472
+ return - EINVAL ;
473
+ }
474
+
475
+ g_mcu_data -> fan_data .trig_temp_level1 = trigger ;
476
+
477
+ fan_level_set (g_mcu_data );
478
+
479
+ return count ;
480
+ }
481
+
482
+ static ssize_t show_fan_trigger_high (struct class * cls ,
483
+ struct class_attribute * attr , char * buf ){
484
+
485
+ return sprintf (buf , "Fan trigger high speed temperature:%d\n" , g_mcu_data -> fan_data .trig_temp_level2 );
486
+ }
487
+
488
+ static ssize_t store_fan_trigger_high (struct class * cls , struct class_attribute * attr ,
489
+ const char * buf , size_t count ){
490
+
491
+ int trigger ;
492
+
493
+ if (kstrtoint (buf , 0 , & trigger ))
494
+ return - EINVAL ;
495
+
496
+ if (trigger <= g_mcu_data -> fan_data .trig_temp_level1 ){
497
+ pr_err ("Invalid parameter\n" );
498
+ return - EINVAL ;
499
+ }
500
+
501
+ g_mcu_data -> fan_data .trig_temp_level2 = trigger ;
502
+
503
+ fan_level_set (g_mcu_data );
504
+
505
+ return count ;
506
+ }
507
+
508
+
403
509
static ssize_t store_wol_enable (struct class * cls , struct class_attribute * attr ,
404
510
const char * buf , size_t count )
405
511
{
@@ -525,6 +631,9 @@ static struct class_attribute fan_class_attrs[] = {
525
631
__ATTR (enable , 0644 , show_fan_enable , store_fan_enable ),
526
632
__ATTR (mode , 0644 , show_fan_mode , store_fan_mode ),
527
633
__ATTR (level , 0644 , show_fan_level , store_fan_level ),
634
+ __ATTR (trigger_temp_low , 0644 , show_fan_trigger_low , store_fan_trigger_low ),
635
+ __ATTR (trigger_temp_mid , 0644 , show_fan_trigger_mid , store_fan_trigger_mid ),
636
+ __ATTR (trigger_temp_high , 0644 , show_fan_trigger_high , store_fan_trigger_high ),
528
637
__ATTR (temp , 0644 , show_fan_temp , NULL ),
529
638
};
530
639
0 commit comments