[PATCH v1 3/3] dt-bindings: thermal: sun8i: Add binding for D1/T113s THS controller

Maxim Kiselev bigunclemax at gmail.com
Sun Jun 11 00:53:56 PDT 2023


вс, 11 июн. 2023 г. в 01:14, Conor Dooley <conor at kernel.org>:
>
> On Sat, Jun 10, 2023 at 11:31:03PM +0300, Maxim Kiselev wrote:
> > сб, 10 июн. 2023 г. в 21:01, Conor Dooley <conor at kernel.org>:
> >
> > ...
> >
> > > > > > +  - |
> > > > > > +    thermal-sensor at 2009400 {
> > > > > > +          compatible = "allwinner,sun20i-d1-ths";
> > > > > > +          reg = <0x02009400 0x400>;
> > > > > > +          interrupts = <0 90 0>;
> > > > > > +          clocks = <&ccu 0>;
> > > > > > +          clock-names = "bus";
> > > > > > +          resets = <&ccu 2>;
> > > > > > +          nvmem-cells = <&ths_calibration>;
> > > > > > +          nvmem-cell-names = "calibration";
> > > > > > +          #thermal-sensor-cells = <0>;
> > > > > >
> > > > > >> Is this calibration required, or optional, for the d1?
> > > > >
> > > > > Calibration data for the D1 is optional as for the H6.
> > > > > (But without it, the sensor data will be inaccurate).
> > > >
> > > > Okay. Modulo the signoff:
> > > > Reviewed-by: Conor Dooley <conor.dooley at microchip.com>
> > >
> > > Wait, that's not what I meant to say... Clearly turned my brain off for
> > > a moment. If it is not going to function correctly without the
> > > calibration data, why not make the calibration data required for the
> > > d1's ths?
> >
> > I don't really know why, but the calibration data is optional for
> > other controllers.
> > So I just did it the same way.
> > Here is explanation comment about it from the driver:
> >         /*
> >          * Even if the external calibration data stored in sid is
> >          * not accessible, the THS hardware can still work, although
> >          * the data won't be so accurate.
> >          *
> >          * The default value of calibration register is 0x800 for
> >          * every sensor, and the calibration value is usually 0x7xx
> >          * or 0x8xx, so they won't be away from the default value
> >          * for a lot.
> >          *
> >          * So here we do not return error if the calibration data is
> >          * not available, except the probe needs deferring.
> >          */
>
> Wait, so if there is no calibration data then this thing will just defer
> probing, ad infinitum? Looks like everything other than the a33 has the
> cells in the dts, and the software seems to expect the cells.
> What am I missing?

Not quite. If we don't have a calibration cell in the dts, then we
just skip the calibration.
We will only get EPROBE_DEFER if we have calibration in the dts.
Here is the whole function code:

static int sun8i_ths_calibrate(struct ths_device *tmdev)
{
    struct nvmem_cell *calcell;
    struct device *dev = tmdev->dev;
    u16 *caldata;
    size_t callen;
    int ret = 0;

    calcell = devm_nvmem_cell_get(dev, "calibration");
    if (IS_ERR(calcell)) {
        if (PTR_ERR(calcell) == -EPROBE_DEFER)
            return -EPROBE_DEFER;
        /*
         * Even if the external calibration data stored in sid is
         * not accessible, the THS hardware can still work, although
         * the data won't be so accurate.
         *
         * The default value of calibration register is 0x800 for
         * every sensor, and the calibration value is usually 0x7xx
         * or 0x8xx, so they won't be away from the default value
         * for a lot.
         *
         * So here we do not return error if the calibration data is
         * not available, except the probe needs deferring.
         */
        goto out;
    }

    caldata = nvmem_cell_read(calcell, &callen);
    if (IS_ERR(caldata)) {
        ret = PTR_ERR(caldata);
        goto out;
    }

    tmdev->chip->calibrate(tmdev, caldata, callen);

    kfree(caldata);
out:
    return ret;
}



More information about the linux-arm-kernel mailing list