BPI-R64 Thermal

so hwmon_action (registered by devm_*) is only called if driver is unloaded? it sounds like it is a generic callback if any data is tried to read from sysfs

with your patch we can use lm-sensors, right? how have you tested it? if i run sensors-detect, no sensors are found

imho we should only show message (dev_err) instead of unload full thermal

something like this:

+       tzdev->tzp->no_hwmon = false;
+       ret = thermal_add_hwmon_sysfs(tzdev);
+       if (ret)
+               dev_err(&pdev->dev,"error in thermal_add_hwmon_sysfs");
+               //goto err_disable_clk_peri_therm;
+
+       ret = devm_add_action(&pdev->dev, mtk_thermal_hwmon_action, tzdev);
+       if (ret) {
+               dev_err(&pdev->dev,"error in devm_add_action");
+               mtk_thermal_hwmon_action(tzdev);
+               //goto err_disable_clk_peri_therm;
+       }

yes, with the patch the “sensors” command (lm sensors) works (validated on r64).

https://static.lwn.net/kerneldoc/driver-api/basics.html#c.devm_add_action it refers to “resource unwinding” (description)…

It could be replaced by devm_add_action_or_reset reset, like in this example https://lore.kernel.org/patchwork/patch/1098197/

As stated above, it makes sense to maximize similarity with other drivers, e.g.: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/drivers/thermal/rcar_gen3_thermal.c?id=9f24a81e2e5daf8820c8654afcd8512e797c41f2

If there is duplicate code (which is bad), it makes sense to make it as similar as possible, otherwise the complexity increases (which is even worse)… :roll_eyes:

have not got it working ;( MTK_THERMAL is built-in (default y) in my 5.4-main

none of my dev_err is printed

root@bpi-r64:~# cat /sys/class/thermal/thermal_zone0/temp                                                                                                           
54300                                                                                                                                                               
root@bpi-r64:~# 

is still working, sensors-detect finds none, and so sensors too…i2c brings some errors

details
root@bpi-r64:~# sensors                                                                                                                                             
No sensors found!                                                                                                                                                   
Make sure you loaded all the kernel drivers you need.                                                                                                               
Try sensors-detect to find out which these are.                                                                                                                     
root@bpi-r64:~# sensors-detect                                                                                                                                      
# sensors-detect revision $Revision$                                                                                                                                
# Kernel: 5.4.12-bpi-r64-main aarch64                                                                                                                               
# Processor:  (//)                                                                                                                                                  
                                                                                                                                                                    
This program will help you determine which kernel modules you need                                                                                                  
to load to use lm_sensors most effectively. It is generally safe                                                                                                    
and recommended to accept the default answers to all questions,                                                                                                     
unless you know what you're doing.                                                                                                                                  
                                                                                                                                                                    
Some south bridges, CPUs or memory controllers contain embedded sensors.                                                                                            
Do you want to scan for them? This is totally safe. (YES/no):                                                                                                       
modprobe: FATAL: Module cpuid not found in directory /lib/modules/5.4.12-bpi-r64-main                                                                               
Failed to load module cpuid.                                                                                                                                        
Silicon Integrated Systems SIS5595...                       No                                                                                                      
VIA VT82C686 Integrated Sensors...                          No                                                                                                      
VIA VT8231 Integrated Sensors...                            No                                                                                                      
AMD K8 thermal sensors...                                   No                                                                                                      
AMD Family 10h thermal sensors...                           No                                                                                                      
AMD Family 11h thermal sensors...                           No                                                                                                      
AMD Family 12h and 14h thermal sensors...                   No                                                                                                      
AMD Family 15h thermal sensors...                           No                                                                                                      
AMD Family 16h thermal sensors...                           No                                                                                                      
AMD Family 17h thermal sensors...                           No                                                                                                      
AMD Family 15h power sensors...                             No                                                                                                      
AMD Family 16h power sensors...                             No                                                                                                      
Intel digital thermal sensor...                             No                                                                                                      
Intel AMB FB-DIMM thermal sensor...                         No                                                                                                      
Intel 5500/5520/X58 thermal sensor...                       No                                                                                                      
VIA C7 thermal sensor...                                    No                                                                                                      
VIA Nano thermal sensor...                                  No                                                                                                      
                                                                                                                                                                    
Lastly, we can probe the I2C/SMBus adapters for connected hardware                                                                                                  
monitoring devices. This is the most risky part, and while it works                                                                                                 
reasonably well on most systems, it has been reported to cause trouble                                                                                              
on some systems.                                                                                                                                                    
Do you want to probe the I2C/SMBus adapters now? (YES/no):                                                                                                          
Sorry, no supported PCI bus adapters found.                                                                                                                         
                                                                                                                                                                    
Next adapter: i2c-mt65xx (i2c-0)                                                                                                                                    
Do you want to scan it? (YES/no/selectively):                                                                                                                       
[ 1246.869062] i2c i2c-0: ioctl, cmd=0x5401, arg=0x7fe2480660                                                                                                       
[ 1246.875273] i2c i2c-0: ioctl, cmd=0x705, arg=0x55d3b4ac90                                                                                                        
[ 1246.881320] i2c i2c-0: ioctl, cmd=0x703, arg=0x18                                                                                                                
[ 1246.886703] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.892872] i2c i2c-0: ioctl, cmd=0x703, arg=0x19                                                                                                                
[ 1246.898028] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.903971] i2c i2c-0: ioctl, cmd=0x703, arg=0x1a                                                                                                                
[ 1246.909187] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.915102] i2c i2c-0: ioctl, cmd=0x703, arg=0x1b                                                                                                                
[ 1246.920320] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.926235] i2c i2c-0: ioctl, cmd=0x703, arg=0x1c                                                                                                                
[ 1246.931458] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.937415] i2c i2c-0: ioctl, cmd=0x703, arg=0x1d                                                                                                                
[ 1246.942647] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.948588] i2c i2c-0: ioctl, cmd=0x703, arg=0x1e                                                                                                                
[ 1246.953901] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.959825] i2c i2c-0: ioctl, cmd=0x703, arg=0x1f                                                                                                                
[ 1246.965043] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.970995] i2c i2c-0: ioctl, cmd=0x703, arg=0x28                                                                                                                
[ 1246.976215] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.982138] i2c i2c-0: ioctl, cmd=0x703, arg=0x29                                                                                                                
[ 1246.987348] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1246.993234] i2c i2c-0: ioctl, cmd=0x703, arg=0x2a                                                                                                                
[ 1246.998442] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.004337] i2c i2c-0: ioctl, cmd=0x703, arg=0x2b                                                                                                                
[ 1247.009538] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.015436] i2c i2c-0: ioctl, cmd=0x703, arg=0x2c                                                                                                                
[ 1247.020862] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.026692] i2c i2c-0: ioctl, cmd=0x703, arg=0x2d                                                                                                                
[ 1247.031913] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.037807] i2c i2c-0: ioctl, cmd=0x703, arg=0x2e                                                                                                                
[ 1247.043011] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.048968] i2c i2c-0: ioctl, cmd=0x703, arg=0x2f                                                                                                                
[ 1247.054195] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.060100] i2c i2c-0: ioctl, cmd=0x703, arg=0x48                                                                                                                
[ 1247.065319] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.071286] i2c i2c-0: ioctl, cmd=0x703, arg=0x49                                                                                                                
[ 1247.076522] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.082423] i2c i2c-0: ioctl, cmd=0x703, arg=0x4a                                                                                                                
[ 1247.087655] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.093550] i2c i2c-0: ioctl, cmd=0x703, arg=0x4b                                                                                                                
[ 1247.098773] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.104878] i2c i2c-0: ioctl, cmd=0x703, arg=0x4c                                                                                                                
[ 1247.110023] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.115958] i2c i2c-0: ioctl, cmd=0x703, arg=0x4d                                                                                                                
[ 1247.121168] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.127090] i2c i2c-0: ioctl, cmd=0x703, arg=0x4e                                                                                                                
[ 1247.132301] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.138208] i2c i2c-0: ioctl, cmd=0x703, arg=0x4f                                                                                                                
[ 1247.143413] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.149817] i2c i2c-0: ioctl, cmd=0x703, arg=0x50                                                                                                                
[ 1247.155266] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.161203] i2c-core: using bounce buffer for addr=0x50, len=1                                                                                                   
[ 1247.167621] i2c-mt65xx 11008000.i2c: addr: 50, transfer ACK error                                                                                                
[ 1247.174336] i2c i2c-0: ioctl, cmd=0x703, arg=0x51                                                                                                                
[ 1247.179564] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.185320] i2c-core: using bounce buffer for addr=0x51, len=1                                                                                                   
[ 1247.191724] i2c-mt65xx 11008000.i2c: addr: 51, transfer ACK error                                                                                                
[ 1247.198592] i2c i2c-0: ioctl, cmd=0x703, arg=0x52                                                                                                                
[ 1247.203839] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.209749] i2c-core: using bounce buffer for addr=0x52, len=1                                                                                                   
[ 1247.216162] i2c-mt65xx 11008000.i2c: addr: 52, transfer ACK error                                                                                                
[ 1247.222974] i2c i2c-0: ioctl, cmd=0x703, arg=0x53                                                                                                                
[ 1247.228239] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.234147] i2c-core: using bounce buffer for addr=0x53, len=1                                                                                                   
[ 1247.240949] i2c-mt65xx 11008000.i2c: addr: 53, transfer ACK error                                                                                                
[ 1247.247530] i2c i2c-0: ioctl, cmd=0x703, arg=0x58                                                                                                                
[ 1247.253157] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.258953] i2c-core: using bounce buffer for addr=0x58, len=1                                                                                                   
[ 1247.265477] i2c-mt65xx 11008000.i2c: addr: 58, transfer ACK error                                                                                                
[ 1247.272159] i2c i2c-0: ioctl, cmd=0x703, arg=0x5c                                                                                                                
[ 1247.277564] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.283356] i2c-core: using bounce buffer for addr=0x5c, len=1                                                                                                   
[ 1247.290249] i2c-mt65xx 11008000.i2c: addr: 5c, transfer ACK error                                                                                                
[ 1247.297279] i2c i2c-0: ioctl, cmd=0x703, arg=0x73                                                                                                                
[ 1247.302601] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1247.308545] i2c-core: using bounce buffer for addr=0x73, len=1                                                                                                   
[ 1247.314867] i2c-core: using bounce buffer for addr=0x73, len=1                                                                                                   
[ 1247.321431] i2c-mt65xx 11008000.i2c: addr: 73, transfer ACK error                                                                                                
[ 1247.328272] i2c i2c-0: ioctl, cmd=0x703, arg=0x77                                                                                                                
[ 1247.333713] i2c i2c-0: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
                                                                                                                                                                    
Next adapter: i2c-mt65xx (i2c-1)                                                                                                                                    
Do you want to scan it? (YES/no/selectively):                                                                                                                       
[ 1266.434697] i2c i2c-1: ioctl, cmd=0x5401, arg=0x7fe2480660                                                                                                       
[ 1266.440698] i2c i2c-1: ioctl, cmd=0x705, arg=0x55d3b4ac90                                                                                                        
[ 1266.446646] i2c i2c-1: ioctl, cmd=0x703, arg=0x18                                                                                                                
[ 1266.451910] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.457880] i2c i2c-1: ioctl, cmd=0x703, arg=0x19                                                                                                                
[ 1266.463103] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.469039] i2c i2c-1: ioctl, cmd=0x703, arg=0x1a                                                                                                                
[ 1266.474262] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.480190] i2c i2c-1: ioctl, cmd=0x703, arg=0x1b                                                                                                                
[ 1266.485402] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.491319] i2c i2c-1: ioctl, cmd=0x703, arg=0x1c                                                                                                                
[ 1266.496739] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.502570] i2c i2c-1: ioctl, cmd=0x703, arg=0x1d                                                                                                                
[ 1266.507760] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.513677] i2c i2c-1: ioctl, cmd=0x703, arg=0x1e                                                                                                                
[ 1266.518904] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.524807] i2c i2c-1: ioctl, cmd=0x703, arg=0x1f                                                                                                                
[ 1266.530011] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.535904] i2c i2c-1: ioctl, cmd=0x703, arg=0x28                                                                                                                
[ 1266.541173] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.547098] i2c i2c-1: ioctl, cmd=0x703, arg=0x29                                                                                                                
[ 1266.552338] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.558357] i2c i2c-1: ioctl, cmd=0x703, arg=0x2a                                                                                                                
[ 1266.563599] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.569517] i2c i2c-1: ioctl, cmd=0x703, arg=0x2b                                                                                                                
[ 1266.574741] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.580702] i2c i2c-1: ioctl, cmd=0x703, arg=0x2c                                                                                                                
[ 1266.585937] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.591830] i2c i2c-1: ioctl, cmd=0x703, arg=0x2d                                                                                                                
[ 1266.597033] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.602924] i2c i2c-1: ioctl, cmd=0x703, arg=0x2e                                                                                                                
[ 1266.608152] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.614056] i2c i2c-1: ioctl, cmd=0x703, arg=0x2f                                                                                                                
[ 1266.622063] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.628038] i2c i2c-1: ioctl, cmd=0x703, arg=0x48                                                                                                                
[ 1266.633264] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.639156] i2c i2c-1: ioctl, cmd=0x703, arg=0x49                                                                                                                
[ 1266.644644] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.650478] i2c i2c-1: ioctl, cmd=0x703, arg=0x4a                                                                                                                
[ 1266.655704] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.661618] i2c i2c-1: ioctl, cmd=0x703, arg=0x4b                                                                                                                
[ 1266.666847] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.672808] i2c i2c-1: ioctl, cmd=0x703, arg=0x4c                                                                                                                
[ 1266.678033] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.683938] i2c i2c-1: ioctl, cmd=0x703, arg=0x4d                                                                                                                
[ 1266.689163] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.695055] i2c i2c-1: ioctl, cmd=0x703, arg=0x4e                                                                                                                
[ 1266.700290] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.706190] i2c i2c-1: ioctl, cmd=0x703, arg=0x4f                                                                                                                
[ 1266.711419] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.717324] i2c i2c-1: ioctl, cmd=0x703, arg=0x50                                                                                                                
[ 1266.722551] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.728305] i2c-core: using bounce buffer for addr=0x50, len=1                                                                                                   
[ 1266.734702] i2c-mt65xx 11009000.i2c: addr: 50, transfer ACK error                                                                                                
[ 1266.741407] i2c i2c-1: ioctl, cmd=0x703, arg=0x51                                                                                                                
[ 1266.746658] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.752594] i2c-core: using bounce buffer for addr=0x51, len=1                                                                                                   
[ 1266.758926] i2c-mt65xx 11009000.i2c: addr: 51, transfer ACK error                                                                                                
[ 1266.765774] i2c i2c-1: ioctl, cmd=0x703, arg=0x52                                                                                                                
[ 1266.771040] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.776821] i2c-core: using bounce buffer for addr=0x52, len=1                                                                                                   
[ 1266.783209] i2c-mt65xx 11009000.i2c: addr: 52, transfer ACK error                                                                                                
[ 1266.790064] i2c i2c-1: ioctl, cmd=0x703, arg=0x53                                                                                                                
[ 1266.795343] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.801115] i2c-core: using bounce buffer for addr=0x53, len=1                                                                                                   
[ 1266.807536] i2c-mt65xx 11009000.i2c: addr: 53, transfer ACK error                                                                                                
[ 1266.814383] i2c i2c-1: ioctl, cmd=0x703, arg=0x58                                                                                                                
[ 1266.819641] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.825429] i2c-core: using bounce buffer for addr=0x58, len=1                                                                                                   
[ 1266.831819] i2c-mt65xx 11009000.i2c: addr: 58, transfer ACK error                                                                                                
[ 1266.838666] i2c i2c-1: ioctl, cmd=0x703, arg=0x5c                                                                                                                
[ 1266.843943] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.849873] i2c-core: using bounce buffer for addr=0x5c, len=1                                                                                                   
[ 1266.856300] i2c-mt65xx 11009000.i2c: addr: 5c, transfer ACK error                                                                                                
[ 1266.863111] i2c i2c-1: ioctl, cmd=0x703, arg=0x73                                                                                                                
[ 1266.868728] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
[ 1266.874418] i2c-core: using bounce buffer for addr=0x73, len=1                                                                                                   
[ 1266.880766] i2c-core: using bounce buffer for addr=0x73, len=1                                                                                                   
[ 1266.887172] i2c-mt65xx 11009000.i2c: addr: 73, transfer ACK error                                                                                                
[ 1266.893998] i2c i2c-1: ioctl, cmd=0x703, arg=0x77                                                                                                                
[ 1266.899291] i2c i2c-1: ioctl, cmd=0x720, arg=0x55d3b4ae80                                                                                                        
                                                                                                                                                                    
Sorry, no sensors were detected.                                                                                                                                    
Either your system has no sensors, or they are not supported, or                                                                                                    
they are connected to an I2C or SMBus adapter that is not                                                                                                           
supported. If you find out what chips are on your board, check                                                                                                      
https://hwmon.wiki.kernel.org/device_support_status for driver status.                                                                                              
root@bpi-r64:~#

do i need additional kernel-options? like Symbol: HWMON [=n] / THERMAL_HWMON ?? if yes code should be only executed if this is set

yes, you need:

https://cateee.net/lkddb/web-lkddb/THERMAL_HWMON.html

if this kernel option is not set, thermal driver should still load/work… but “sensors” not. Whether “sensors” work, should correspond to /sys/class/hwmon

// edit: if it works, it looks like that:

root@bpi-r64:~# sensors
cpu_thermal-virtual-0
Adapter: Virtual device
temp1:        +45.1°C  (crit = +107.0°C)
1 Like
root@bpi-r64:~# cat /sys/class/thermal/thermal_zone0/temp                                                                                                           
36000                                                                                                                                                               
root@bpi-r64:~# sensors                                                                                                                                             
cpu_thermal-virtual-0                                                                                                                                               
Adapter: Virtual device                                                                                                                                             
temp1:        +36.6�°C  (crit = +107.0�°C) 

:slight_smile:

btw. on r2 it works too:

root@bpi-r2:~# sensors
cpu_thermal-virtual-0
Adapter: Virtual device
temp1:        +45.7�°C  (crit = +107.0�°C)

root@bpi-r2:~#

Hello, well I must confess I started this topic and I also have to confess that after the first couple of posts I stopped understanding. But I definitely cheer you for putting so much work into this subject.

My project is running to 90 percent except for the fan control. But reading your posts I am convinced there is something going on. :blush:

Have a nice weekend

I have pushed changes (hwmon,led) to my repo 5.4-main branch…

For r64 first change board in build.conf. then importconfig and build kernel

That is going to be my Sunday fun. :slight_smile:

mhm, looks like sensors on my debian stretch (bpi-2) does not support hwmon (my test-r2 with buster works)…

# zcat /proc/config.gz | grep -i hwmon
CONFIG_HWMON=y
# CONFIG_HWMON_DEBUG_CHIP is not set
# CONFIG_SENSORS_IIO_HWMON is not set
CONFIG_THERMAL_HWMON=y
# cat /sys/class/thermal/thermal_zone0/temp 
49665
# sensors
No sensors found!
Make sure you loaded all the kernel drivers you need.
Try sensors-detect to find out which these are.

I applied all patches and I can confirm that I do have temperature reading on R64

root@OpenWrt:~# sensors
cpu_thermal-virtual-0
Adapter: Virtual device
temp1: +68.9°C (crit = +107.0°C)

but that seems to be a temperature of PMIC MT6380.

Temperature of MT7622 can be read from debugfs of wmac. I do have a radiator on CPU and memories but it not cover pmic. In wmac temp debugfs I can read around 40 deg and on sensors 68 as above. When I put big fan that cover pmic and mt7531 temperature from ‘sensors’ output drops. Also looking at thermal camera the only IC with temp above 60 deg is PMIC

Patches from here: https://lkml.org/lkml/2020/4/30/297

seems to work better. Temperature between ‘sensors’ and wmac reading are still different but only few C deg.

What is difference of these patches (patchwork link) and the patches you’ve used before?

In my repo i used Patches provided here…if these are wrong i should replace them

They are the same. I did not spot them on patchwork before.

I know that patchwork is same as lkml…i want to know difference to the patches you’ve used before (which bring wrong temperature)

I did not compared them deeply. Only checked if it will be any changes.

created a branch 5.7-thermal where i reverted my current patches and applied the new

made a diff that shows this:

diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
index b991a22b86fc..88620f7e9890 100644
--- a/drivers/thermal/mtk_thermal.c
+++ b/drivers/thermal/mtk_thermal.c
@@ -266,8 +266,6 @@ struct mtk_thermal_data {
        bool need_switch_bank;
        struct thermal_bank_cfg bank_data[MAX_NUM_ZONES];
        enum mtk_thermal_version version;
-       int (*extract)(struct mtk_thermal *mt, u32 *buf);
-       int (*convert)(struct mtk_thermal *mt, int sensno, s32 raw);
 };
 
 struct mtk_thermal {
@@ -383,11 +381,6 @@ static const int mt7622_mux_values[MT7622_NUM_SENSORS] = { 0, };
 static const int mt7622_vts_index[MT7622_NUM_SENSORS] = { VTS1 };
 static const int mt7622_tc_offset[MT7622_NUM_CONTROLLER] = { 0x0, };
 
-static int mtk_thermal_extract_efuse_v1(struct mtk_thermal *mt, u32 *buf);
-static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf);
-static int raw_to_mcelsius_v1(struct mtk_thermal *mt, int sensno, s32 raw);
-static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw);
-
 /*
  * The MT8173 thermal controller has four banks. Each bank can read up to
  * four temperature sensors simultaneously. The MT8173 has a total of 5
@@ -429,8 +422,6 @@ static const struct mtk_thermal_data mt8173_thermal_data = {
        .adcpnp = mt8173_adcpnp,
        .sensor_mux_values = mt8173_mux_values,
        .version = MTK_THERMAL_V1,
-       .extract = mtk_thermal_extract_efuse_v1,
-       .convert = raw_to_mcelsius_v1,
 };
 
 /*
@@ -462,8 +453,6 @@ static const struct mtk_thermal_data mt2701_thermal_data = {
        .adcpnp = mt2701_adcpnp,
        .sensor_mux_values = mt2701_mux_values,
        .version = MTK_THERMAL_V1,
-       .extract = mtk_thermal_extract_efuse_v1,
-       .convert = raw_to_mcelsius_v1,
 };
 
 /*
@@ -495,8 +484,6 @@ static const struct mtk_thermal_data mt2712_thermal_data = {
        .adcpnp = mt2712_adcpnp,
        .sensor_mux_values = mt2712_mux_values,
        .version = MTK_THERMAL_V1,
-       .extract = mtk_thermal_extract_efuse_v1,
-       .convert = raw_to_mcelsius_v1,
 };
 
 /*
@@ -522,8 +509,6 @@ static const struct mtk_thermal_data mt7622_thermal_data = {
        .adcpnp = mt7622_adcpnp,
        .sensor_mux_values = mt7622_mux_values,
        .version = MTK_THERMAL_V2,
-       .extract = mtk_thermal_extract_efuse_v2,
-       .convert = raw_to_mcelsius_v2,
 };
 
 /*
@@ -557,8 +542,6 @@ static const struct mtk_thermal_data mt8183_thermal_data = {
        .adcpnp = mt8183_adcpnp,
        .sensor_mux_values = mt8183_mux_values,
        .version = MTK_THERMAL_V1,
-       .extract = mtk_thermal_extract_efuse_v1,
-       .convert = raw_to_mcelsius_v1,
 };
 
 /**
@@ -669,9 +652,13 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
                raw = readl(mt->thermal_base +
                            conf->msr[conf->bank_data[bank->id].sensors[i]]);
 
-               temp = conf->convert(mt,
-                                    conf->bank_data[bank->id].sensors[i],
-                                    raw);
+               if (mt->conf->version == MTK_THERMAL_V1) {
+                       temp = raw_to_mcelsius_v1(
+                               mt, conf->bank_data[bank->id].sensors[i], raw);
+               } else {
+                       temp = raw_to_mcelsius_v2(
+                               mt, conf->bank_data[bank->id].sensors[i], raw);
+               }
 
                /*
                 * The first read of a sensor often contains very high bogus
@@ -932,9 +919,14 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
                goto out;
        }
 
-       if (mt->conf->extract(mt, buf)) {
+       if (mt->conf->version == MTK_THERMAL_V1)
+               ret = mtk_thermal_extract_efuse_v1(mt, buf);
+       else
+               ret = mtk_thermal_extract_efuse_v2(mt, buf);
+
+       if (ret) {
                dev_info(dev, "Device not calibrated, using default calibration values\n");
-//             ret = -EINVAL;
+               ret = 0;
        }
 
 out:

so it looks like the calculation is same, only mtk_thermal_extract_efuse_v[12] and raw_to_mcelsius_v[12] called directly based on mt->conf->version instead of field in mtk_thermal_data and these functions are not declared in forward way…last change is for fixing bpi-r2 that was not part of first patches ( ret = -EINVAL broke thermal on bpi-r2)

Thermal patches are merged for 5.9

https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git/log/?h=thermal/linux-next

@jasmin are you still active here?

i posted the hwmon-support to mailing list and got response

https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

in your Patch you use thermal_add_hwmon_sysfs followed by devm_add_action, daniel lezcano suggests devm_thermal_add_hwmon_sysfs. I’m not sure this does the same as i do not see the link to the mtk_thermal_hwmon_action function

https://elixir.bootlin.com/linux/latest/source/drivers/thermal/thermal_hwmon.c#L258

but the function seems to handle only the cleanup

i guess instead of ifdef i should use

#if IS_ENABLED(CONFIG_THERMAL_HWMON)

so i end up with this code:

#if IS_ENABLED(CONFIG_THERMAL_HWMON)
    tzdev->tzp->no_hwmon = false;
    ret = devm_thermal_add_hwmon_sysfs(tzdev);
    if (ret)
        dev_err(&pdev->dev, "error in thermal_add_hwmon_sysfs");
#endif

is this enough? at least it works (on r2)

edit posted new version: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

hi frank, … yes, there is a specialized wrapper available since jan 2020:

thanks for posting the change :slight_smile:

But it (v3) seems it is not merged yet

i send a ping to mailinglist/maintainer

After ping got response from mtk maintainer,send out v4 and got reviewed-by