On 24-12-10, Frank Li wrote: > On Tue, Dec 10, 2024 at 11:36:46AM +0100, Marco Felsch wrote: > > Hi, > > > > On 24-12-09, Frank Li wrote: ... > > > + /* disable the monitor during initialization */ > > > + imx91_tmu_enable(tmu, false); > > > + imx91_tmu_start(tmu, false); > > > > Make use of pm_runtime? > > thermal is always on after probe. continue measure tempature. So pm_runtime > is not suitable for this case. There are at least 3 drivers which use pm-runtime including the i.MX6/7 imx_thermal.c driver. > > > + ret = imx91_init_from_nvmem_cells(tmu); > > > + if (ret) { > > > + writel_relaxed(DEFAULT_TRIM1_CONFIG, tmu->base + TRIM1); > > > + writel_relaxed(DEFAULT_TRIM2_CONFIG, tmu->base + TRIM2); > > > + } > > > + > > > + /* The typical conv clk is 4MHz, the output freq is 'rate / (div + 1)' */ > > > + rate = clk_get_rate(tmu->clk); > > > + div = (rate / 4000000) - 1; > > > > Would be nice to validate the div value before passing to the HW and if > > the target rate of 4MHz can't be reached by the div you you should > > return -EINVAL. > > > > > + > > > + /* Set divider value and enable divider */ > > > + writel_relaxed(DIV_EN | FIELD_PREP(DIV_MASK, div), tmu->base + REF_DIV); > > > + > > > + /* Set max power up delay: 'Tpud(ms) = 0xFF * 1000 / 4000000' */ > > > + writel_relaxed(FIELD_PREP(PUDL_MASK, 100U), tmu->base + PUD_ST_CTRL); > > > + > > > + /* > > > + * Set resolution mode > > > + * 00b - Conversion time = 0.59325 ms > > > + * 01b - Conversion time = 1.10525 ms > > > + * 10b - Conversion time = 2.12925 ms > > > + * 11b - Conversion time = 4.17725 ms > > > + */ > > > + writel_relaxed(FIELD_PREP(CTRL1_RES_MASK, 0x3), tmu->base + CTRL1_CLR); > > > + writel_relaxed(FIELD_PREP(CTRL1_RES_MASK, 0x1), tmu->base + CTRL1_SET); > > > + > > > + /* > > > + * Set measure mode > > > + * 00b - Single oneshot measurement > > > + * 01b - Continuous measurement > > > + * 10b - Periodic oneshot measurement > > > + */ > > > > For the resolution it's fine to have the values directly coded without a > > define, but here we can definitly use a define and drop the comment. > > > > > + writel_relaxed(FIELD_PREP(CTRL1_MEAS_MODE_MASK, 0x3), tmu->base + CTRL1_CLR); > > > + writel_relaxed(FIELD_PREP(CTRL1_MEAS_MODE_MASK, 0x1), tmu->base + CTRL1_SET); > > > > Why do we set it to periodic mode instead of the single-shot? At the > > moment the device doesn't have IRQ support, and so there is no need to > > run the measurements in background. > > It is "continous measurement". first clean MODE_MASK, then then 01. Still, why? You return the temp value upon a request (get_temp). There is no async notification from this driver to others. So it can be left to single-shot and do the measurement on request (get_temp). > _CLR means clean bits according to mask > _SET means set bits according to mask. I know. Regards, Marco > > Frank > > > > > > + > > > + /* > > > + * Set Periodic Measurement Frequency to 25Hz: > > > + * tMEAS_FREQ = tCONV_CLK * PERIOD_CTRL[MEAS_FREQ]. -> > > > + * PERIOD_CTRL(MEAS_FREQ) = (1000 / 25) / (1000 / 4000000); > > > + * Where tMEAS_FREQ = Measurement period and tCONV_CLK = 1/fCONV_CLK. > > > + * This field should have value greater than count corresponds > > > + * to time greater than summation of conversion time, power up > > > + * delay, and six times of conversion clock time. > > > + * tMEAS_FREQ > (tCONV + tPUD + 6 * tCONV_CLK). > > > + * tCONV is conversion time determined by CTRL1[RESOLUTION]. > > > + */ > > > + writel_relaxed(FIELD_PREP(MEAS_FREQ_MASK, 0x27100), tmu->base + PERIOD_CTRL); > > > > With the single-shot measurements we could remove this part and.. > > > > > + > > > + /* enable the monitor */ > > > + imx91_tmu_enable(tmu, true); > > > + imx91_tmu_start(tmu, true); > > > > this part as well. > > > > Regards, > > Marco > > > > > + > > > + return 0; > > > +} > > > + > > > +static void imx91_tmu_remove(struct platform_device *pdev) > > > +{ > > > + struct imx91_tmu *tmu = platform_get_drvdata(pdev); > > > + > > > + /* disable tmu */ > > > + imx91_tmu_start(tmu, false); > > > + imx91_tmu_enable(tmu, false); > > > +} > > > + > > > +static int __maybe_unused imx91_tmu_suspend(struct device *dev) > > > +{ > > > + struct imx91_tmu *tmu = dev_get_drvdata(dev); > > > + > > > + /* disable tmu */ > > > + imx91_tmu_start(tmu, false); > > > + imx91_tmu_enable(tmu, false); > > > + > > > + clk_disable_unprepare(tmu->clk); > > > + > > > + return 0; > > > +} > > > + > > > +static int __maybe_unused imx91_tmu_resume(struct device *dev) > > > +{ > > > + struct imx91_tmu *tmu = dev_get_drvdata(dev); > > > + int ret; > > > + > > > + ret = clk_prepare_enable(tmu->clk); > > > + if (ret) > > > + return ret; > > > + > > > + imx91_tmu_enable(tmu, true); > > > + imx91_tmu_start(tmu, true); > > > + > > > + return 0; > > > +} > > > + > > > +static SIMPLE_DEV_PM_OPS(imx91_tmu_pm_ops, > > > + imx91_tmu_suspend, imx91_tmu_resume); > > > + > > > +static const struct of_device_id imx91_tmu_table[] = { > > > + { .compatible = "fsl,imx91-tmu", }, > > > + { }, > > > +}; > > > +MODULE_DEVICE_TABLE(of, imx91_tmu_table); > > > + > > > +static struct platform_driver imx91_tmu = { > > > + .driver = { > > > + .name = "i.MX91_thermal", > > > + .pm = pm_ptr(&imx91_tmu_pm_ops), > > > + .of_match_table = imx91_tmu_table, > > > + }, > > > + .probe = imx91_tmu_probe, > > > + .remove = imx91_tmu_remove, > > > +}; > > > +module_platform_driver(imx91_tmu); > > > + > > > +MODULE_AUTHOR("Peng Fan <peng.fan@xxxxxxx>"); > > > +MODULE_DESCRIPTION("i.MX91 Thermal Monitor Unit driver"); > > > +MODULE_LICENSE("GPL"); > > > > > > -- > > > 2.34.1 > > > > > > > > > >