HI Mark.  I am trying to add H3 support to the sxitemp driver.  The H3 SOC
only has the CPU thermal sensor, but it maps well to the CPU thermal sensor
on the H5.  With the diff below I think I have been able to do all the
mechanical stuff to get the sensor to register.  I also had to add a dtb
entry for the sensor, also shown below.  The sensor shows up in sysctl and
the readout value corresponds to a value of 0 from the device temperature
register.

To figure out why the sensor is not providing a readout I added some
printouts to the driver.  It would seem that the registers are not being set
or that the address is not correct.  But everything looks good.

Do you have any suggestions as to what to look at next?

***
Sysctl output
***
op1bsdsnap# sysctl hw.sensors
hw.sensors.sxitemp0.temp0=187.74 degC (CPU)
hw.sensors.bme0.temp0=21.88 degC
hw.sensors.bme0.humidity0=54.37%
hw.sensors.bme0.pressure0=100.37 Pa
hw.sensors.bme1.temp0=22.64 degC
hw.sensors.bme1.humidity0=50.28%
hw.sensors.bme1.pressure0=100.34 Pa

***
Dmesg after additional debug printouts
***
sxitemp0 at simplebus0
addr: 0x1c25000, size: 0x400
Before start acquistion
reg: 0x70, data: 0x1
reg: 0x44, data: 0x0
reg: 0x0, data: 0xf0000
reg: 0x40, data: 0x40000
reg: 0x80, data: 0x0
After start acquistion
reg: 0x70, data: 0x1
reg: 0x44, data: 0x0
reg: 0x0, data: 0xf0000
reg: 0x40, data: 0x40000
reg: 0x80, data: 0x0


***
Code for debug
***

        pinctrl_byname(node, "default");
printf("addr: 0x%llx, size: 0x%llx\n", faa->fa_reg[0].addr,
faa->fa_reg[0].size);
        clock_enable_all(node);
        reset_deassert_all(node);

printf("Before start acquistion\n");
printf("reg: 0x%x, data: 0x%x\n", THS_FILTER, HREAD4(sc, 0x70));
printf("reg: 0x%x, data: 0x%x\n", THS_INT_CTRL, HREAD4(sc, 0x44));
printf("reg: 0x%x, data: 0x%x\n", THS_CTRL0, HREAD4(sc, 0x0));
printf("reg: 0x%x, data: 0x%x\n", THS_CTRL2, HREAD4(sc, 0x40));
printf("reg: 0x%x, data: 0x%x\n", THS0_DATA, HREAD4(sc, 0x80));

        /* Start data acquisition. */
        HWRITE4(sc, THS_FILTER, THS_FILTER_EN | THS_FILTER_TYPE(1));
        HWRITE4(sc, THS_INT_CTRL, THS_INT_CTRL_THERMAL_PER(800));
        HWRITE4(sc, THS_CTRL0, THS_CTRL0_SENSOR_ACQ(31));
        HWRITE4(sc, THS_CTRL2, THS_CTRL2_ADC_ACQ(31) |
            THS_CTRL2_SENSE0_EN | THS_CTRL2_SENSE1_EN);

printf("After start acquistion\n");
printf("reg: 0x%x, data: 0x%x\n", THS_FILTER, HREAD4(sc, 0x70));
printf("reg: 0x%x, data: 0x%x\n", THS_INT_CTRL, HREAD4(sc, 0x44));
printf("reg: 0x%x, data: 0x%x\n", THS_CTRL0, HREAD4(sc, 0x0));
printf("reg: 0x%x, data: 0x%x\n", THS_CTRL2, HREAD4(sc, 0x40));
printf("reg: 0x%x, data: 0x%x\n", THS0_DATA, HREAD4(sc, 0x80));



***
Diff
***
sxitemp0 at simplebus0
addr: 0x1c25000, size: 0x400
Before start acquistion
reg: 0x70, data: 0x1
reg: 0x44, data: 0x0
reg: 0x0, data: 0xf0000
reg: 0x40, data: 0x40000
reg: 0x80, data: 0x0
After start acquistion
reg: 0x70, data: 0x1
reg: 0x44, data: 0x0
reg: 0x0, data: 0xf0000
reg: 0x40, data: 0x40000
reg: 0x80, data: 0x0
op1bsdsnap$ diff -u -p sxitemp.c.orig sxitemp.c
--- sxitemp.c.orig      Sun Dec 31 07:41:25 2017
+++ sxitemp.c   Tue May  8 15:46:30 2018
@@ -76,7 +76,9 @@ struct cfdriver sxitemp_cd = {
 uint64_t sxitemp_r40_calc_temp(int64_t);
 uint64_t sxitemp_h5_calc_temp0(int64_t);
 uint64_t sxitemp_h5_calc_temp1(int64_t);
+uint64_t sxitemp_h3_calc_temp(int64_t);
 void   sxitemp_refresh_sensors(void *);
+void    sxitemp_refresh_h3_sensors(void *);

 int
 sxitemp_match(struct device *parent, void *match, void *aux)
@@ -84,6 +86,7 @@ sxitemp_match(struct device *parent, void *match, void
        struct fdt_attach_args *faa = aux;

        return (OF_is_compatible(faa->fa_node, "allwinner,sun8i-r40-ths") ||
+            OF_is_compatible(faa->fa_node, "allwinner,sun8i-h3-ths") ||
            OF_is_compatible(faa->fa_node, "allwinner,sun50i-h5-ths"));
 }

@@ -113,12 +116,17 @@ sxitemp_attach(struct device *parent, struct device *s
        clock_enable_all(node);
        reset_deassert_all(node);

-       if (OF_is_compatible(faa->fa_node, "allwinner,sun8i-r40-ths")) {
-               sc->sc_calc_temp0 = sxitemp_r40_calc_temp;
-               sc->sc_calc_temp1 = sxitemp_r40_calc_temp;
-       } else {
-               sc->sc_calc_temp0 = sxitemp_h5_calc_temp0;
-               sc->sc_calc_temp1 = sxitemp_h5_calc_temp1;
+        if (OF_is_compatible(faa->fa_node, "allwinner,sun8i-h3-ths"))
+                sc->sc_calc_temp0 = sxitemp_h3_calc_temp;
+        else {
+
+               if (OF_is_compatible(faa->fa_node,
"allwinner,sun8i-r40-ths")) {
+                       sc->sc_calc_temp0 = sxitemp_r40_calc_temp;
+                       sc->sc_calc_temp1 = sxitemp_r40_calc_temp;
+               } else {
+                       sc->sc_calc_temp0 = sxitemp_h5_calc_temp0;
+                       sc->sc_calc_temp1 = sxitemp_h5_calc_temp1;
+               }
        }

        /* Start data acquisition. */
@@ -135,15 +143,29 @@ sxitemp_attach(struct device *parent, struct device *s
        sc->sc_sensors[0].type = SENSOR_TEMP;
        sc->sc_sensors[0].flags = SENSOR_FINVALID;
        sensor_attach(&sc->sc_sensordev, &sc->sc_sensors[0]);
-       strlcpy(sc->sc_sensors[1].desc, "GPU",
sizeof(sc->sc_sensors[1].desc));
-       sc->sc_sensors[1].type = SENSOR_TEMP;
-       sc->sc_sensors[1].flags = SENSOR_FINVALID;
-       sensor_attach(&sc->sc_sensordev, &sc->sc_sensors[1]);
-       sensordev_install(&sc->sc_sensordev);
-       sensor_task_register(sc, sxitemp_refresh_sensors, 5);
+
+       if (~OF_is_compatible(faa->fa_node, "allwinner,sun8i-h3-ths")) {
+                strlcpy(sc->sc_sensors[1].desc, "GPU",
sizeof(sc->sc_sensors[1].desc));
+                sc->sc_sensors[1].type = SENSOR_TEMP;
+                sc->sc_sensors[1].flags = SENSOR_FINVALID;
+                sensor_attach(&sc->sc_sensordev, &sc->sc_sensors[1]);
+        }
+
+        sensordev_install(&sc->sc_sensordev);
+        if (OF_is_compatible(faa->fa_node, "allwinner,sun8i-h3-ths"))
+                sensor_task_register(sc, sxitemp_refresh_h3_sensors, 5);
+        else
+                sensor_task_register(sc, sxitemp_refresh_sensors, 5);
 }

 uint64_t
+sxitemp_h3_calc_temp(int64_t data)
+{
+        /* from H3 datasheet T = (TEM-2794)/-14.882 */
+        return (2794000000000 - data * 1000000000) / 14882;
+}
+
+uint64_t
 sxitemp_r40_calc_temp(int64_t data)
 {
        /* From BSP as the R40 User Manual says T.B.D. */
@@ -182,3 +204,15 @@ sxitemp_refresh_sensors(void *arg)
        sc->sc_sensors[1].value = sc->sc_calc_temp1(data) + 273150000;
        sc->sc_sensors[1].flags &= ~SENSOR_FINVALID;
 }
+
+void
+sxitemp_refresh_h3_sensors(void *arg)
+{
+        struct sxitemp_softc *sc = arg;
+        uint32_t data;
+
+        data = HREAD4(sc, THS0_DATA);
+        sc->sc_sensors[0].value = sc->sc_calc_temp0(data) + 273150000;
+        sc->sc_sensors[0].flags &= ~SENSOR_FINVALID;
+}
+

***
DTB for thermal sensor
***

                ths@01c25000 {
                        #thermal-sensor-cells = <0x0>;
                        compatible = "allwinner,sun8i-h3-ths";
                        reg = <0x1c25000 0x400>;
                        interrupts = <0x0 0x1f 0x4>;
                        resets = <0x2 0x2a>;
                        reset-names = "ahb";
                        clocks = <0x2 0x37 0x2 0x45>;
                        clock-names = "ahb", "ths";
                        linux,phandle = <0x20>;
                        phandle = <0x20>;
                };


Reply via email to