Skip to content

Commit c33edd8

Browse files
Demon000dlezcano
authored andcommitted
thermal: renesas: rzg3e: make calibration value retrieval per-chip
The Renesas RZ/T2H (R9A09G077) and RZ/N2H (R9A09G087) SoCs expose the temperature calibration data via SMC SIP calls. To prepare for supporting these SoCs, do the following changes. Rename rzg3e_thermal_parse_dt() to rzg3e_thermal_get_syscon_trim(). Move the syscon usage out of rzg3e_thermal_get_calibration() and into rzg3e_thermal_get_syscon_trim() and remove single-use variables from the private state. Place a pointer to rzg3e_thermal_get_syscon_trim() into the chip-specific struct, and use it in the probe function to retrieve the calibration values. Now that syscon usage has been moved out of rzg3e_thermal_get_calibration(), remove it and inline the calibration validation into the probe function. Also, reuse the TSU_CODE_MAX macro to mask the calibration values, as GEMASK(11, 0) and 0xFFF are equivalent, and replace the hardcoded 0xFFF with TSU_CODE_MAX in the calibration validation. Reviewed-by: John Madieu <john.madieu.xa@bp.renesas.com> Tested-by: John Madieu <john.madieu.xa@bp.renesas.com> Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://patch.msgid.link/20260108195223.193531-4-cosmin-gabriel.tanislav.xa@renesas.com Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
1 parent 6c7f87f commit c33edd8

1 file changed

Lines changed: 29 additions & 42 deletions

File tree

drivers/thermal/renesas/rzg3e_thermal.c

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@
7070
#define TSU_POLL_DELAY_US 10 /* Polling interval */
7171
#define TSU_MIN_CLOCK_RATE 24000000 /* TSU_PCLK minimum 24MHz */
7272

73+
struct rzg3e_thermal_priv;
74+
7375
struct rzg3e_thermal_info {
76+
int (*get_trim)(struct rzg3e_thermal_priv *priv);
7477
int temp_d_mc;
7578
int temp_e_mc;
7679
};
@@ -91,13 +94,11 @@ struct rzg3e_thermal_info {
9194
struct rzg3e_thermal_priv {
9295
void __iomem *base;
9396
struct device *dev;
94-
struct regmap *syscon;
9597
struct thermal_zone_device *zone;
9698
struct reset_control *rstc;
9799
const struct rzg3e_thermal_info *info;
98100
u16 trmval0;
99101
u16 trmval1;
100-
u32 trim_offset;
101102
struct mutex lock;
102103
};
103104

@@ -334,51 +335,33 @@ static const struct thermal_zone_device_ops rzg3e_tz_ops = {
334335
.set_trips = rzg3e_thermal_set_trips,
335336
};
336337

337-
static int rzg3e_thermal_get_calibration(struct rzg3e_thermal_priv *priv)
338+
static int rzg3e_thermal_get_syscon_trim(struct rzg3e_thermal_priv *priv)
338339
{
339-
u32 val;
340+
struct device_node *np = priv->dev->of_node;
341+
struct regmap *syscon;
342+
u32 offset;
340343
int ret;
344+
u32 val;
345+
346+
syscon = syscon_regmap_lookup_by_phandle_args(np, "renesas,tsu-trim", 1, &offset);
347+
if (IS_ERR(syscon))
348+
return dev_err_probe(priv->dev, PTR_ERR(syscon),
349+
"Failed to parse renesas,tsu-trim\n");
341350

342351
/* Read calibration values from syscon */
343-
ret = regmap_read(priv->syscon, priv->trim_offset, &val);
352+
ret = regmap_read(syscon, offset, &val);
344353
if (ret)
345354
return ret;
346-
priv->trmval0 = val & GENMASK(11, 0);
355+
priv->trmval0 = val & TSU_CODE_MAX;
347356

348-
ret = regmap_read(priv->syscon, priv->trim_offset + 4, &val);
357+
ret = regmap_read(syscon, offset + 4, &val);
349358
if (ret)
350359
return ret;
351-
priv->trmval1 = val & GENMASK(11, 0);
352-
353-
/* Validate calibration data */
354-
if (!priv->trmval0 || !priv->trmval1 ||
355-
priv->trmval0 == priv->trmval1 ||
356-
priv->trmval0 == 0xFFF || priv->trmval1 == 0xFFF) {
357-
dev_err(priv->dev, "Invalid calibration: b=0x%03x, c=0x%03x\n",
358-
priv->trmval0, priv->trmval1);
359-
return -EINVAL;
360-
}
361-
362-
dev_dbg(priv->dev, "Calibration: b=0x%03x (%u), c=0x%03x (%u)\n",
363-
priv->trmval0, priv->trmval0, priv->trmval1, priv->trmval1);
360+
priv->trmval1 = val & TSU_CODE_MAX;
364361

365362
return 0;
366363
}
367364

368-
static int rzg3e_thermal_parse_dt(struct rzg3e_thermal_priv *priv)
369-
{
370-
struct device_node *np = priv->dev->of_node;
371-
u32 offset;
372-
373-
priv->syscon = syscon_regmap_lookup_by_phandle_args(np, "renesas,tsu-trim", 1, &offset);
374-
if (IS_ERR(priv->syscon))
375-
return dev_err_probe(priv->dev, PTR_ERR(priv->syscon),
376-
"Failed to parse renesas,tsu-trim\n");
377-
378-
priv->trim_offset = offset;
379-
return 0;
380-
}
381-
382365
static int rzg3e_thermal_probe(struct platform_device *pdev)
383366
{
384367
struct device *dev = &pdev->dev;
@@ -402,11 +385,20 @@ static int rzg3e_thermal_probe(struct platform_device *pdev)
402385
if (IS_ERR(priv->base))
403386
return PTR_ERR(priv->base);
404387

405-
/* Parse device tree for trim register info */
406-
ret = rzg3e_thermal_parse_dt(priv);
388+
ret = priv->info->get_trim(priv);
407389
if (ret)
408390
return ret;
409391

392+
if (!priv->trmval0 || !priv->trmval1 ||
393+
priv->trmval0 == priv->trmval1 ||
394+
priv->trmval0 == TSU_CODE_MAX || priv->trmval1 == TSU_CODE_MAX)
395+
return dev_err_probe(priv->dev, -EINVAL,
396+
"Invalid calibration: b=0x%03x, c=0x%03x\n",
397+
priv->trmval0, priv->trmval1);
398+
399+
dev_dbg(priv->dev, "Calibration: b=0x%03x (%u), c=0x%03x (%u)\n",
400+
priv->trmval0, priv->trmval0, priv->trmval1, priv->trmval1);
401+
410402
/* Get clock to verify frequency - clock is managed by power domain */
411403
clk = devm_clk_get(dev, NULL);
412404
if (IS_ERR(clk))
@@ -423,12 +415,6 @@ static int rzg3e_thermal_probe(struct platform_device *pdev)
423415
return dev_err_probe(dev, PTR_ERR(priv->rstc),
424416
"Failed to get/deassert reset control\n");
425417

426-
/* Get calibration data */
427-
ret = rzg3e_thermal_get_calibration(priv);
428-
if (ret)
429-
return dev_err_probe(dev, ret,
430-
"Failed to get valid calibration data\n");
431-
432418
/* Get comparison interrupt */
433419
irq = platform_get_irq_byname(pdev, "adcmpi");
434420
if (irq < 0)
@@ -533,6 +519,7 @@ static const struct dev_pm_ops rzg3e_thermal_pm_ops = {
533519
};
534520

535521
static const struct rzg3e_thermal_info rzg3e_thermal_info = {
522+
.get_trim = rzg3e_thermal_get_syscon_trim,
536523
.temp_d_mc = -41000,
537524
.temp_e_mc = 126000,
538525
};

0 commit comments

Comments
 (0)