Advertisement
Guest User

soctemp/pmutemp 0.0.5 for A20/AXP209 devices

a guest
Nov 14th, 2014
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.82 KB | None | 0 0
  1. soctemp() {
  2.     # function to read out the thermal probes of the touch panel controller
  3.     # that is integrated into the A20 SoC. For background information have a
  4.     # look at http://forum.lemaker.org/thread-8137-3-1-3.html
  5.    
  6.     # SoCTempAdjustment is needed because the A20 SoC delivers somewhat
  7.     # uncalibrated temp values. Even after calibration the values are
  8.     # inaccurate by a few degrees
  9.     SoCTempAdjustment=1447
  10.  
  11.     # ensure module sunxi-dbgreg.ko is loaded
  12.     grep -q sunxi_dbgreg </proc/modules || ( modprobe sunxi-dbgreg ; sleep 0.1 )
  13.        
  14.     # prepare registers
  15.     echo 'f1c25000:27003f' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  16.     echo 'f1c25010:40000' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  17.     echo 'f1c25018:10fff' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  18.     echo 'f1c25004:90' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/write;
  19.        
  20.     # let the value be written to syslog
  21.     echo 'f1c25020' > /sys/devices/virtual/misc/sunxi-dbgreg/rw/read;
  22.        
  23.     # wait 0.1 seconds
  24.     sleep 0.1
  25.        
  26.     # read return value from syslog and transform it into degrees Celsius
  27.     HexVal=$(tail /var/log/syslog | awk -F" 0x" '/ 0x/ {print $2}' | tail -n1 )
  28.     CelsiusVal=$(echo $(( 0x${HexVal} - ${SoCTempAdjustment} )) | awk '{printf ("%0.1f",$1/10); }')
  29.     case $1 in
  30.         f|F)
  31.             echo ${CelsiusVal} | awk '{print "approx. "( ( 9/5 ) * $1 ) + 32"°F"}'
  32.             ;;
  33.         *)
  34.             echo "approx. ${CelsiusVal}°C"
  35.             ;;
  36.     esac
  37. } # soctemp
  38.  
  39. pmutemp() {
  40.     # function to read out the thermal probe inside the AXP209 power
  41.     # management unit via I2C
  42.     CelsiusVal=$(awk '{printf ("%0.1f",$1/1000); }' </sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input)
  43.     case $1 in
  44.         f|F)
  45.             echo ${CelsiusVal} | awk '{print "approx. "( ( 9/5 ) * $1 ) + 32"°F"}'
  46.             ;;
  47.         *)
  48.             echo "approx. ${CelsiusVal}°C"
  49.             ;;
  50.     esac
  51. } # pmutemp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement