Author Topic: A20 (A10?) Temperature logging script  (Read 26139 times)

Offline Jojo

  • Developer
  • Full Member
  • ***
  • Posts: 190
  • Karma: +13/-0
  • Cubieboard 2 - A20, aRUNTU v1.666
    • View Profile
A20 (A10?) Temperature logging script
« on: April 03, 2014, 03:10:02 am »
Hi,

I have made a tiny script that lets you continously log the temperature of the TP controller in th A20. Due it is inside the same package you can use this information nearly as you CPU temperature ;) .


I have made a tiny script that lets you continously log the temperature of the AXP PMU IC on you CB2. Before the advice from ssvb (thx) I thought that it would be the sensor of the TP controller inside of the A20. That seems to be wrong. Sorry for that!

Feature overview:
  • scaling the readout to 0.1°C
  • log in intervals defined by the user
  • default logging interval is 1s
  • gives an output to the terminal with timestamp and temperature
  • creates a logfile everytime you start the script
  • logfile name is "Temp_log_hh:mm:ss" (starting time)
  • logging format in file is "hh:mm:ss   TT.t"
  • script will be stopped/closed by pressing any key

Known issues:
  • script does not prove the existance of the temperatue directory befor readout
  • if user input for logging interval is invalid (not a number) the script f**ks up and you have to cancel it

Usage:
Call the scipt with default logging interval (1 second)
Code: [Select]
bash Temperature_Logger.sh

Call the scipt with another logging interval (5 seconds)
Code: [Select]
bash Temperature_Logger.sh 5

Output will look like this (screenshot will follow):
Code: [Select]
Temperature logging started in file "Temp_log_hh:mm:ss"...
hh:mm:ss TT.t°C <- changing continously

Logging stopped at hh:mm:ss

The log file will be created in the same directory of the script!

You can end the script by pressing any key ("Where is the 'any'-key?!")

I have decided to log the temperature without unit (no "°C" in file) because that makes it more easy to convert the data to another software (for making charts, for example).
I think it could be useful if you are running benchmarks or if you want to see the influence of the CPU speed to the temperature.

I don't know if the script works on the A10, because the temperature register is located at another address (A20: 0x20, A10: 0x1C). Please let me know if it works on the A10!

Due the CB1 and and CB2 have the same layout, the script should also work on the CB1. But I have no CB1, so I can not test it.  Please let me know if it works on the CB1!

Please let me know if you like it. And also if not ;) .

Greetings!
« Last Edit: April 03, 2014, 02:22:12 pm by Jojo »
Don't think that anyone will take more pains for his answer, as you took for your question.

Offline ssvb

  • Jr. Member
  • **
  • Posts: 72
  • Karma: +5/-0
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #1 on: April 03, 2014, 04:32:35 am »
This is not the temperature of a TP controller exposed at /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input. It's the temperature of a PMU chip AXP209, which is located rather far from the A10/A20 SoC on the Cubieboard PCB.

Offline Jojo

  • Developer
  • Full Member
  • ***
  • Posts: 190
  • Karma: +13/-0
  • Cubieboard 2 - A20, aRUNTU v1.666
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #2 on: April 03, 2014, 04:49:56 am »
This is not the temperature of a TP controller exposed at /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input. It's the temperature of a PMU chip AXP209, which is located rather far from the A10/A20 SoC on the Cubieboard PCB.

Are you sure?
I have followed the information on these sites:
http://www.cubieforums.com/index.php?topic=2004.0
and
https://groups.google.com/forum/#!topic/linux-sunxi/2zoxTcepPVo

For me this sounds like the internal one. Please let me know, if this is wrong and why  :) .

Thanks!
Don't think that anyone will take more pains for his answer, as you took for your question.

Offline ssvb

  • Jr. Member
  • **
  • Posts: 72
  • Karma: +5/-0
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #3 on: April 03, 2014, 05:00:38 am »
Depends on which kernel you are using. The following patch adds reporting of the AXP209 temperature to the linux-sunxi kernel: https://github.com/linux-sunxi/linux-sunxi/commit/fcec507519157765c689ab3473a9e72d8b6df453
And your script seems to be reading exactly this data.

Offline ssvb

  • Jr. Member
  • **
  • Posts: 72
  • Karma: +5/-0
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #4 on: April 03, 2014, 05:08:19 am »
And http://www.cubieforums.com/index.php?topic=2004.msg12920#msg12920 says that the TP temperature sensor should be exposed at /sys/devices/platform/a20-tp-hwmon/temp1_input if you apply the patch from the google groups link. We are just dealing with different temperature sensors here :)

Offline Jojo

  • Developer
  • Full Member
  • ***
  • Posts: 190
  • Karma: +13/-0
  • Cubieboard 2 - A20, aRUNTU v1.666
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #5 on: April 03, 2014, 05:15:27 am »
This confuses me alot  :-[ . In my first link, "Madozu" says:
Quote
Yes, CT has a temperature sensor ... or kind of ... built in to the touch pannel controller. There are two ways of accessing it:
  • Use Pats Kernel version 3.4.79. You find the sensor data at "/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input". Divide the value read by 1000 to get degrees Celsius.

This sounds to me as if this kernel uses the internal sensor  ??? . But I also was wondering, why there is something with "i2c" in the path...  ??? .

I sadly really don't understand much about kernel and driver programming. But for me is very confusing  :-[ .

What information is correct? Is there something I have to do to access the TP sensor? I am not in front of my CB" at the moment...
Don't think that anyone will take more pains for his answer, as you took for your question.

Offline ssvb

  • Jr. Member
  • **
  • Posts: 72
  • Karma: +5/-0
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #6 on: April 03, 2014, 05:25:25 am »
The TP controller is documented in the A20 manual: http://dl.linux-sunxi.org/A20/A20%20User%20Manual%202013-03-22.pdf
AXP20x is documented here (with some links to pdf files): http://linux-sunxi.org/AXP209

And if you look at the sources of the kernel patches in question, you can see that they are substantially different for these two. The only thing they have in common is the assumption that they are calibrated in the same way (the ADC values are in [0, 4095] range, which corresponds to [-144.7C, +264.8C] range of temperatures).

Offline Jojo

  • Developer
  • Full Member
  • ***
  • Posts: 190
  • Karma: +13/-0
  • Cubieboard 2 - A20, aRUNTU v1.666
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #7 on: April 03, 2014, 05:36:33 am »
Ok, I will have a look if I have access to the /sys/devices/platform/a20-tp-hwmon/temp1_input directory on my system. If yes, I will update the script.
If not: can you tell me what to do?

PS: I remember... aren't you one of the developer guys :) ? I think I've read your name somewhere under a kernel source code driver whatever file...  :D
Don't think that anyone will take more pains for his answer, as you took for your question.

ikeeki

  • Guest
Re: A20 (A10?) Temperature logging script
« Reply #8 on: April 03, 2014, 07:36:33 am »
Fbturbo and others. Ingenieer.

Offline Jojo

  • Developer
  • Full Member
  • ***
  • Posts: 190
  • Karma: +13/-0
  • Cubieboard 2 - A20, aRUNTU v1.666
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #9 on: April 03, 2014, 02:04:09 pm »
And http://www.cubieforums.com/index.php?topic=2004.msg12920#msg12920 says that the TP temperature sensor should be exposed at /sys/devices/platform/a20-tp-hwmon/temp1_input if you apply the patch from the google groups link. We are just dealing with different temperature sensors here :)

Hi and thanks for the information so far  :-* !
Could you (ssvb) please explain me (or give me a hint) how I have to apply the patch to have access to the sensor? Do I have to recompile the kernel?
It would be really nice, if you'd take the time to push me in the right direction :) !

Greetings
Don't think that anyone will take more pains for his answer, as you took for your question.

Offline ssvb

  • Jr. Member
  • **
  • Posts: 72
  • Karma: +5/-0
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #10 on: April 04, 2014, 12:33:21 am »
Could you (ssvb) please explain me (or give me a hint) how I have to apply the patch to have access to the sensor? Do I have to recompile the kernel?
Yes, you (or somebody else) needs to apply that patch and compile the kernel. Also disabling touchscreen drivers would be necessary and enabling CONFIG_SENSORS_A20_TP_HWMON=y in the kernel config. However, as I can see from the comments, this was just he initial revision of the patch and it had some issues. Actually, the support for this temperature sensor (as part of the touchscreen driver) has been already submitted to the mainline kernel - https://www.mail-archive.com/linux-sunxi@googlegroups.com/msg00312.html

We might want to backport it to 3.4 too.

The old initial revision of the driver also works. And it indeed seems to report the right temperature for the A20 chip itself. This can be easily verified (I have done this already) by following these steps:
1. Run something heavy on the CPU, so that it heats up.
2. Watch the reported numbers from both temperature sensors and touch the A20 chip with your finger for a little bit. The reported temperature for the sensor corresponding to the A20 chip should instantly drop by something like ~5C.
3. Watch the reported numbers from both temperature sensors and touch the PMU chip with your finger for a little bit.. It is a small rectangular chip near the barrel shaped power plug on the cubieboard. The reported temperature for the sensor corresponding to the AXP209 chip should instantly drop by something like ~5C.

The temperatures of AXP209 and A20 are actually very similar and usually don't differ much from each other (if the CPU is using a lot of power, then the PMU chip temperature also goes up). But they are still not exactly the same.

In any case, we have temperature sensors for each of these two hottest chips on the board. All the bases are covered :)

Offline Jojo

  • Developer
  • Full Member
  • ***
  • Posts: 190
  • Karma: +13/-0
  • Cubieboard 2 - A20, aRUNTU v1.666
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #11 on: April 04, 2014, 02:57:35 am »
Could you (ssvb) please explain me (or give me a hint) how I have to apply the patch to have access to the sensor? Do I have to recompile the kernel?
Yes, you (or somebody else) needs to apply that patch and compile the kernel. Also disabling touchscreen drivers would be necessary and enabling CONFIG_SENSORS_A20_TP_HWMON=y in the kernel config. However, as I can see from the comments, this was just he initial revision of the patch and it had some issues. Actually, the support for this temperature sensor (as part of the touchscreen driver) has been already submitted to the mainline kernel - https://www.mail-archive.com/linux-sunxi@googlegroups.com/msg00312.html

We might want to backport it to 3.4 too.

The old initial revision of the driver also works. And it indeed seems to report the right temperature for the A20 chip itself. This can be easily verified (I have done this already) by following these steps:
1. Run something heavy on the CPU, so that it heats up.
2. Watch the reported numbers from both temperature sensors and touch the A20 chip with your finger for a little bit. The reported temperature for the sensor corresponding to the A20 chip should instantly drop by something like ~5C.
3. Watch the reported numbers from both temperature sensors and touch the PMU chip with your finger for a little bit.. It is a small rectangular chip near the barrel shaped power plug on the cubieboard. The reported temperature for the sensor corresponding to the AXP209 chip should instantly drop by something like ~5C.

The temperatures of AXP209 and A20 are actually very similar and usually don't differ much from each other (if the CPU is using a lot of power, then the PMU chip temperature also goes up). But they are still not exactly the same.

In any case, we have temperature sensors for each of these two hottest chips on the board. All the bases are covered :)

Thanks a lot for these information! For me all this sounds very complicated  :-[ .
What is your suggestion?
  • applying the patch to the kernel
  • backporting the driver to the 3.4 kernel
  • anything else?

I think the better solution is to add the driver for having TP support AND access to the sensor. Do you agree?
If yes, how is this managed? What does "backport" mean in this case? Is here somebody who can do that? Can I help in any way?

Greetings
Don't think that anyone will take more pains for his answer, as you took for your question.

Offline ssvb

  • Jr. Member
  • **
  • Posts: 72
  • Karma: +5/-0
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #12 on: April 04, 2014, 08:16:52 am »
Thanks a lot for these information! For me all this sounds very complicated  :-[ .
Well, all the complexity is just downloading the patch, applying it and compiling the kernel. Do you want somebody to provide a kernel binary for you? ;)

Anyway, for your convenience, I prepared a test branch for the kernel with all the needed patches: https://github.com/ssvb/linux-sunxi/commits/20140404-cpu-temperature-monitoring-test

Example output of the 'sensors' tool on my Cubietruck (running idle):
Code: [Select]
axp20_mfd-i2c-0-34
Adapter: sunxi-i2c.0
ACIN voltage:        +5.14 V  (avg =  +5.13 V)
VBUS voltage:        +0.01 V  (avg =  +0.01 V)
AXP20X temperature:  +30.9 C  (low  = -144.7 C, high = +264.8 C)
ACIN+VBUS power:      1.02 W  (avg =   1.05 W)
ACIN current:        +0.20 A  (avg =  +0.20 A)
VBUS current:        +0.00 A  (avg =  +0.00 A)

a20_tp-isa-0000
Adapter: ISA adapter
temp1:        +34.8 C  (low  = -144.7 C, high = +264.8 C)

The actual numbers from the AXP and from the TP (CPU) temperature sensors are usually not very far apart. Both of these chips heat up under load and both are reasonably cool when the system is idle.

Note that on Allwiner A10, the TP temperature sensor shows the temperature around 100C, which is obviously bogus. The sensor works, because this reported temperature increases under load. But the calibration is apparently very much different on A10 and we can't use the same formula as on A20.
« Last Edit: April 04, 2014, 08:18:38 am by ssvb »

Offline Jojo

  • Developer
  • Full Member
  • ***
  • Posts: 190
  • Karma: +13/-0
  • Cubieboard 2 - A20, aRUNTU v1.666
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #13 on: April 04, 2014, 05:55:41 pm »
Thanks a lot for these information! For me all this sounds very complicated  :-[ .
Well, all the complexity is just downloading the patch, applying it and compiling the kernel. Do you want somebody to provide a kernel binary for you? ;)
No, I don't want anybody doing anything for me  :-[ . I'd like to do as much as I can on my own. But my Linux skills are still very limited. To get the kernel source is no problem (download link somwhere here in the forum). But about the patch... I think I am just blind! I have found no "button" or something like that to download it  ??? ::) :o ! I already imagined that I would have to copy-paste the source code lines into the files of the kernel manually. But this is not the way to do it, right?
Thats why I asked for some hints. I just needed a push in the right direction to help myself.

But anyway, thanks for your help so far. I will try if I am also able to modify the kernel in that way. All hail to OS on SD card ;)  ;D !

Greetings
Don't think that anyone will take more pains for his answer, as you took for your question.

Offline ssvb

  • Jr. Member
  • **
  • Posts: 72
  • Karma: +5/-0
    • View Profile
Re: A20 (A10?) Temperature logging script
« Reply #14 on: April 05, 2014, 09:48:51 am »
But about the patch... I think I am just blind! I have found no "button" or something like that to download it  ??? ::)
You go to the right side of the screen in the google groups and select "show original" in the drop-down menu. Then press the "Show only message" button and get to https://groups.google.com/forum/message/raw?msg=linux-sunxi/2zoxTcepPVo/q4f3D1ZEm8cJ

For compiling your own kernel, there is a guide at http://linux-sunxi.org/Linux_Kernel#Compilation

If you have already cloned your kernel sources from git, then you can download and apply the cpu temperature sensor patch by running the following commands:
Code: [Select]
wget -O cpu-thermal-sensor.path https://groups.google.com/forum/message/raw?msg=linux-sunxi/2zoxTcepPVo/q4f3D1ZEm8cJ
git am cpu-thermal-sensor.path

Hope this helps. And one more warning again: this patch is not production quality and has some issues. Good enough for testing though.