Re: [PATCH] thermal: imx: interpret fsl,tempmon-data through nvmem

From: Leonard Crestez
Date: Wed Jul 05 2017 - 08:33:20 EST


On Tue, 2017-07-04 at 11:54 -0700, Eduardo Valentin wrote:
> On Mon, Jun 19, 2017 at 04:40:43PM +0300, Leonard Crestez wrote:
> >
> > On imx6sx accessing the ocotp memory area directly is wrong because the
> > ocotp clock needs to be enabled first. Fix this by reinterpreting the
> > fsl,tempmon-data phandle as a reference to a nvmem_device and doing all
> > the read through that.
> >
> > @@ -347,29 +348,39 @@ static struct thermal_zone_device_ops imx_tz_ops = {
> > Âstatic int imx_get_sensor_data(struct platform_device *pdev)
> > Â{
> > Â struct imx_thermal_data *data = platform_get_drvdata(pdev);
> > - struct regmap *map;
> > + struct device_node *ocotp_np;
> > + struct nvmem_device *ocotp;
> > Â int t1, n1;
> > Â int ret;
> > Â u32 val;
> > Â u64 temp64;
> > Â
> > - map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
> > - ÂÂÂÂÂÂ"fsl,tempmon-data");
> > - if (IS_ERR(map)) {
> > - ret = PTR_ERR(map);
> > - dev_err(&pdev->dev, "failed to get sensor regmap: %d\n", ret);
> > + ocotp_np = of_parse_phandle(pdev->dev.of_node, "fsl,tempmon-data", 0);
> > + if (IS_ERR(ocotp_np)) {
> > + ret = PTR_ERR(ocotp_np);
> > + dev_err(&pdev->dev, "failed to parse fsl,tempmon-data phandle: %d\n", ret);
> > + return ret;
> > + }
> > + ocotp = of_nvmem_device_phandle_get(ocotp_np);
> > + of_node_put(ocotp_np);
> > + if (IS_ERR(ocotp)) {
> > + ret = PTR_ERR(ocotp);
> > + if (ret != -EPROBE_DEFER)
> > + dev_err(&pdev->dev, "failed to get fsl,tempmon-data nvmem device: %d\n", ret);
> > Â return ret;
> > Â }
> > Â
> > @@ -404,10 +415,11 @@ static int imx_get_sensor_data(struct platform_device *pdev)
> > Â data->c2 = n1 * data->c1 + 1000 * t1;
> > Â
> > Â /* use OTP for thermal grade */
> > - ret = regmap_read(map, OCOTP_MEM0, &val);
> > - if (ret) {
> > - dev_err(&pdev->dev, "failed to read temp grade: %d\n", ret);
> > - return ret;

> I see a few other occurences of regmap_read() in this driver, for
> example, inside imx_get_temp(). Do they also get affect by the reported
> bug? Should they be replaced with nvmem_device_read() too?

No, most of the code uses regmap to read from the tempmon device
itself.

It is only imx_get_sensor_data which uses syscon_regmap_lookup to fetch
the regmap for another device (ocotp) in order to read calibration data
and thermal grading at probe time. Perhaps this function should be
renamed to something like imx_tempmon_init_calib.

The problem is that on newer imx SOCs reading directly from OCOTP like
that doesn't work if the ocotp clock is not enabled.

--
Regards,
Leonard