thermal zones on R40

116 views
Skip to first unread message

@lex

unread,
Jul 24, 2019, 12:46:47 PM7/24/19
to linux-sunxi
Hi,

I am trying to get the thermal readout to work on bpi m2 ultra using the same setup from the H3 without success.
i get:
[  802.038807] thermal thermal_zone0: failed to read out thermal zone (-16)

Anyone have this working or have a fix for this?

This is what i am using:

    ths: ths@1c25000 {
        #thermal-sensor-cells = <0>;
        compatible = "allwinner,sun8i-h3-ths";
        reg = <0x01c25000 0x400>,
              <0x01c14234 0x4>;
        reg-names = "ths", "calibration";
        interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>;
        resets = <&ccu RST_BUS_THS>;
        reset-names = "ahb";
        clocks = <&ccu CLK_BUS_THS>, <&ccu CLK_THS>;
        clock-names = "ahb", "ths";
    };

BR

Clément Péron

unread,
Jul 25, 2019, 12:31:24 PM7/25/19
to alex....@gmail.com, linux-sunxi
Hi Alex,

On Wednesday, 24 July 2019, @lex <alex....@gmail.com> wrote:
>
> Hi,
>
> I am trying to get the thermal readout to work on bpi m2 ultra using the same setup from the H3 without success.
> i get:
> [  802.038807] thermal thermal_zone0: failed to read out thermal zone (-16)
>
> Anyone have this working or have a fix for this?


Did you check the R40 user manual?

You have to first update the register address and irq number.

Then check if they are some difference in the memory mapping of the IP
between H3 and R40.

Regards,
Clement

>
>
> This is what i am using:
>
>     ths: ths@1c25000 {
>         #thermal-sensor-cells = <0>;
>         compatible = "allwinner,sun8i-h3-ths";
>         reg = <0x01c25000 0x400>,
>               <0x01c14234 0x4>;
>         reg-names = "ths", "calibration";
>         interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>;
>         resets = <&ccu RST_BUS_THS>;
>         reset-names = "ahb";
>         clocks = <&ccu CLK_BUS_THS>, <&ccu CLK_THS>;
>         clock-names = "ahb", "ths";
>     };
>
> BR
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/9040e607-50c4-4875-ad5b-8a1be83fdb64%40googlegroups.com.

@lex

unread,
Jul 25, 2019, 1:12:06 PM7/25/19
to linux-sunxi
Hi Clément,

No. i did not read the R40 manual until now, Base address: 1c24c00
But how to find the correct interrupt number and the correct Mapping in the Manual? What should o look for?

Thanks for the answer.

@lex

Clément Péron

unread,
Jul 25, 2019, 3:28:07 PM7/25/19
to alex....@gmail.com, linux-sunxi
Hi Alex,

On Thu, 25 Jul 2019 at 19:12, @lex <alex....@gmail.com> wrote:
>
> Hi Clément,
>
> No. i did not read the R40 manual until now, Base address: 1c24c00
> But how to find the correct interrupt number and the correct Mapping in the Manual? What should o look for?
You have to look for GIC interrupt table (page 205).
And you have to find the correct interrupt number.
To have it you have to subtract 32 (the first 32 interrupts are ARM reserved).

Regards,
Clément

>
> Thanks for the answer.
>
> @lex
>
>
>
> On Wednesday, July 24, 2019 at 1:46:47 PM UTC-3, @lex wrote:
>>
>> Hi,
>>
>> I am trying to get the thermal readout to work on bpi m2 ultra using the same setup from the H3 without success.
>> i get:
>> [ 802.038807] thermal thermal_zone0: failed to read out thermal zone (-16)
>>
>> Anyone have this working or have a fix for this?
>>
>> This is what i am using:
>>
>> ths: ths@1c25000 {
>> #thermal-sensor-cells = <0>;
>> compatible = "allwinner,sun8i-h3-ths";
>> reg = <0x01c25000 0x400>,
>> <0x01c14234 0x4>;
>> reg-names = "ths", "calibration";
>> interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>;
>> resets = <&ccu RST_BUS_THS>;
>> reset-names = "ahb";
>> clocks = <&ccu CLK_BUS_THS>, <&ccu CLK_THS>;
>> clock-names = "ahb", "ths";
>> };
>>
>> BR
>
> --
> You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/29d0e510-bc3f-479d-9f8b-5f7f4fa3b77a%40googlegroups.com.

@lex

unread,
Jul 25, 2019, 4:01:20 PM7/25/19
to linux-sunxi
Thank you for the info.

Almost there, i get negative values for the temp, still something missing or wrong.

I came up with this:

ths: ths@1c24c00 {

        #thermal-sensor-cells = <0>;
        compatible = "allwinner,sun8i-h3-ths";
        reg = <0x1c24c00 0x400>,

              <0x01c14234 0x4>;
        reg-names = "ths", "calibration";
        interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>;

        resets = <&ccu RST_BUS_THS>;
        reset-names = "ahb";
        clocks = <&ccu CLK_BUS_THS>, <&ccu CLK_THS>;
        clock-names = "ahb", "ths";
    };
> To unsubscribe from this group and stop receiving emails from it, send an email to linux...@googlegroups.com.

Clément Péron

unread,
Jul 25, 2019, 4:37:39 PM7/25/19
to alex....@gmail.com, linux-sunxi
Hi Alex,

On Thu, 25 Jul 2019 at 22:01, @lex <alex....@gmail.com> wrote:
>
> Thank you for the info.
>
> Almost there, i get negative values for the temp, still something missing or wrong.

This mean that the calibration data are wrong.

I don't know where the H3 is looking for his callibration data.

But the R40 seems to have a register for that with an offset of 0x74:
Maybe you should try :
reg = <0x1c24c00 0x400>,
<0x1c24c74 0x4>;

Else you have to open the H3 user manual and understand what this
"0x01c14234" address is pointing to.
And look for the same information for R40.

Regards,
Clément
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/b8b52334-b423-4f74-bb64-67c937279d56%40googlegroups.com.

@lex

unread,
Jul 25, 2019, 5:20:42 PM7/25/19
to linux-sunxi
Hi Clément,

I am using the H3 THS driver, maybe this needs a rewrite. 
3.15.3.2. Temperature Conversion Formula TBD. Could be just that, but who knows.
At least i tried.

Thank you anyway.

Clément Péron

unread,
Jul 28, 2019, 4:21:33 PM7/28/19
to alex....@gmail.com, linux-sunxi
Hi Alex,

On Thu, 25 Jul 2019 at 23:20, @lex <alex....@gmail.com> wrote:
>
> Hi Clément,
>
> I am using the H3 THS driver, maybe this needs a rewrite.
> 3.15.3.2. Temperature Conversion Formula TBD. Could be just that, but who knows.
> At least i tried.

Yes maybe the formula is different but I just check for the
calibration data and my previous message was wrong.
The calibration data for the H3 are pointing to the SID (internal eeprom).

H3 => 0x01C1 4000
R40 => 0x01C1 B000

So maybe you can try with this bindings.

reg = <0x1c24c00 0x400>,
<0x01c1b234 0x4>;

Hope this can help.

Regards,
Clément
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/de28da19-0644-4c5c-a811-763712f40f11%40googlegroups.com.

Clément Péron

unread,
Jul 28, 2019, 4:44:31 PM7/28/19
to alex....@gmail.com, linux-sunxi
On Sun, 28 Jul 2019 at 22:21, Clément Péron <peron...@gmail.com> wrote:
>
> Hi Alex,
>
> On Thu, 25 Jul 2019 at 23:20, @lex <alex....@gmail.com> wrote:
> >
> > Hi Clément,
> >
> > I am using the H3 THS driver, maybe this needs a rewrite.
> > 3.15.3.2. Temperature Conversion Formula TBD. Could be just that, but who knows.
> > At least i tried.
>
> Yes maybe the formula is different but I just check for the
> calibration data and my previous message was wrong.
> The calibration data for the H3 are pointing to the SID (internal eeprom).
>
> H3 => 0x01C1 4000
> R40 => 0x01C1 B000
>
> So maybe you can try with this bindings.
>
> reg = <0x1c24c00 0x400>,
> <0x01c1b234 0x4>;

You have to check this offset and the formula from the vendor kernel.

For the calibration data this seems to be "0x01c1b240" :
https://github.com/BPI-SINOVOIP/BPI-M2U-bsp/blob/cbfb10bffba398dd109262af9704fe70cb4b2f3e/linux-sunxi/drivers/soc/allwinner/sunxi-sid-efuse.h#L49

For the formula you have to check here:
https://github.com/BPI-SINOVOIP/BPI-M2U-bsp/blob/cbfb10bffba398dd109262af9704fe70cb4b2f3e/linux-sunxi/drivers/thermal/sunxi_thermal/sun8iw11_ths.c#L65

And you can check a bit the dt bindings for IRQ and memory mapping here :
https://github.com/BPI-SINOVOIP/BPI-M2U-bsp/blob/master/linux-sunxi/arch/arm/boot/dts/sun8iw11p1.dtsi#L1601-L1607

@lex

unread,
Jul 29, 2019, 7:15:08 PM7/29/19
to linux-sunxi
Clément,

I gave it a try but still something missing.

cat /sys/class/thermal/thermal_zone0/temp 
22506
cat /sys/class/thermal/thermal_zone0/temp 
22471
cat /sys/class/thermal/thermal_zone0/temp 
22471
cat /sys/class/thermal/thermal_zone0/temp 
22480
cat /sys/class/thermal/thermal_zone0/temp 
22471
cat /sys/class/thermal/thermal_zone0/temp 
22462


#define MULPA                   (u32)(0.1125*1024*1024)
#define DIVPA                   (20)
#define MINUPA                  (250*1024*1024)



static int sun8i_ths_get_temp(void *_data, int *out)
{
 
struct sun8i_ths_data *data = _data;
 s32 reg
;
   
 
if (data->temp == 0)
     
return -EBUSY;


 
/* Formula and parameters from the Allwinner BSP 4.4 kernel */
 reg
= (MINUPA - (data->temp << DIVPA));
 reg
= reg / MULPA;
 
*out = reg;
 
return 0;
}




    ths: ths@1c24c00 {
       
#thermal-sensor-cells = <0>;
        compatible
= "allwinner,sun8i-h3-ths";
        reg
= <0x1c24c00 0x400>,

             
<0x01c1b234 0x4>;

        reg
-names = "ths", "calibration";
        interrupts
= <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>;
        resets
= <&ccu RST_BUS_THS>;
        reset
-names = "ahb";
        clocks
= <&ccu CLK_BUS_THS>, <&ccu CLK_THS>;
        clock
-names = "ahb", "ths";
   
};


Regards,
@lex


On Sunday, July 28, 2019 at 5:44:31 PM UTC-3, Clément Péron wrote:

Clément Péron

unread,
Jul 30, 2019, 4:18:37 AM7/30/19
to alex....@gmail.com, linux-sunxi
Hi Alex,
I didn't check the formula but still the calibration address is wrong.

You have a SUN8IW11 which gives offset 0x40 :
https://github.com/BPI-SINOVOIP/BPI-M2U-bsp/blob/cbfb10bffba398dd109262af9704fe70cb4b2f3e/linux-sunxi/drivers/soc/allwinner/sunxi-sid-efuse.h#L49

From the chip_id base address
https://github.com/BPI-SINOVOIP/BPI-M2U-bsp/blob/master/linux-sunxi/arch/arm/boot/dts/sun8iw11p1.dtsi#L205

So the correct calibration address is 0x1c1b240.

Regards,
Clément
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/linux-sunxi/a273ccf4-6aef-4b12-8a84-d343060c908b%40googlegroups.com.

@lex

unread,
Jul 30, 2019, 9:13:57 AM7/30/19
to linux-sunxi
Clément,

You are right.
The formula now gives some sane values.

static int sun8i_ths_get_temp(void *_data, int *out)
{
 
struct sun8i_ths_data *data = _data;

 
int temperature;

   
 
if (data->temp == 0)
     
return -EBUSY;



 
/* Formula and parameters from the Allwinner 4.4 BSP kernel */
 temperature
= (2500000 - (int)1125*data->temp)/10000;
 
*out = temperature;
 
return 0;
}


cat /sys/class/thermal/thermal_zone0/temp 
42
cat /sys/class/thermal/thermal_zone0/temp 
43
cat /sys/class/thermal/thermal_zone0/temp 
43
cat /sys/class/thermal/thermal_zone0/temp 
43
cat /sys/class/thermal/thermal_zone0/temp 
43
cat /sys/class/thermal/thermal_zone0/temp 
44
cat /sys/class/thermal/thermal_zone0/temp 
44
cat /sys/class/thermal/thermal_zone0/temp 
44
cat /sys/class/thermal/thermal_zone0/temp 
44
cat /sys/class/thermal/thermal_zone0/temp 
44
cat /sys/class/thermal/thermal_zone0/temp 
44

I think it is working.
Thank you!

Regards,
@lex

@lex

unread,
Jul 30, 2019, 9:55:09 AM7/30/19
to linux-sunxi
I was just thinking about the resolution of the values, shouldn't it be something like 42000 and not only 42 for the thermal throttling to occur? Any thoughts?

@lex

unread,
Jul 30, 2019, 2:52:48 PM7/30/19
to linux-sunxi
Ok, Changing from 42 to 42000 seems to be the correct way.
Cpu frequency scales from 480 ~ 1008 Mhz but is always at 1,10v. Board runs stable with a full load.
Any idea of how to scale core vdd from 1,0 ~ 1,30v and scale frequency ~ 1200 Mhz?


Gpu temp is also missing,
ls /sys/devices/virtual/thermal/thermal_zone?
/sys/devices/virtual/thermal/thermal_zone0:
available_policies  k_po       sustainable_power  trip_point_2_hyst
cdev0               k_pu       temp               trip_point_2_temp
cdev0_trip_point    mode       trip_point_0_hyst  trip_point_2_type
cdev0_weight        offset     trip_point_0_temp  type
emul_temp           policy     trip_point_0_type  uevent
integral_cutoff     power      trip_point_1_hyst
k_d                 slope      trip_point_1_temp
k_i                 subsystem  trip_point_1_type


/sys/devices/virtual/thermal/thermal_zone1:
available_policies  k_d   k_pu    passive  slope              temp
emul_temp           k_i   mode    policy   subsystem          type
integral_cutoff     k_po  offset  power    sustainable_power  uevent

cat /sys/devices/virtual/thermal/thermal_zone1/type
gpu0
-thermal
cat
/sys/devices/virtual/thermal/thermal_zone1/temp
cat
: /sys/devices/virtual/thermal/thermal_zone1/temp: Invalid argument

Reply all
Reply to author
Forward
0 new messages