Skip to content

Commit e72f03e

Browse files
miquelraynalEduardo Valentin
authored andcommitted
thermal: armada: use the resource managed registration helper alternative
Current use of thermal_zone_device_register() triggers a warning at boot and should be replaced by devm_thermal_zone_of_sensor_register(). This allows better handling of multiple thermal zones for later multi-sensors support. Also change the driver data to embed a new structure to make the difference between legacy data (which needs to be cleaned) and syscon-related data. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
1 parent 1756377 commit e72f03e

File tree

1 file changed

+100
-22
lines changed

1 file changed

+100
-22
lines changed

drivers/thermal/armada_thermal.c

Lines changed: 100 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct armada_thermal_data;
6464

6565
/* Marvell EBU Thermal Sensor Dev Structure */
6666
struct armada_thermal_priv {
67+
struct device *dev;
6768
struct regmap *syscon;
6869
char zone_name[THERMAL_NAME_LENGTH];
6970
struct armada_thermal_data *data;
@@ -95,6 +96,26 @@ struct armada_thermal_data {
9596
unsigned int syscon_status_off;
9697
};
9798

99+
struct armada_drvdata {
100+
enum drvtype {
101+
LEGACY,
102+
SYSCON
103+
} type;
104+
union {
105+
struct armada_thermal_priv *priv;
106+
struct thermal_zone_device *tz;
107+
} data;
108+
};
109+
110+
/*
111+
* struct armada_thermal_sensor - hold the information of one thermal sensor
112+
* @thermal: pointer to the local private structure
113+
* @tzd: pointer to the thermal zone device
114+
*/
115+
struct armada_thermal_sensor {
116+
struct armada_thermal_priv *priv;
117+
};
118+
98119
static void armadaxp_init(struct platform_device *pdev,
99120
struct armada_thermal_priv *priv)
100121
{
@@ -243,16 +264,14 @@ static bool armada_is_valid(struct armada_thermal_priv *priv)
243264
return reg & priv->data->is_valid_bit;
244265
}
245266

246-
static int armada_get_temp(struct thermal_zone_device *thermal,
247-
int *temp)
267+
static int armada_read_sensor(struct armada_thermal_priv *priv, int *temp)
248268
{
249-
struct armada_thermal_priv *priv = thermal->devdata;
250269
u32 reg, div;
251270
s64 sample, b, m;
252271

253272
/* Valid check */
254273
if (priv->data->is_valid && !priv->data->is_valid(priv)) {
255-
dev_err(&thermal->device,
274+
dev_err(priv->dev,
256275
"Temperature sensor reading not valid\n");
257276
return -EIO;
258277
}
@@ -278,7 +297,32 @@ static int armada_get_temp(struct thermal_zone_device *thermal,
278297
return 0;
279298
}
280299

281-
static struct thermal_zone_device_ops ops = {
300+
static int armada_get_temp_legacy(struct thermal_zone_device *thermal,
301+
int *temp)
302+
{
303+
struct armada_thermal_priv *priv = thermal->devdata;
304+
int ret;
305+
306+
/* Do the actual reading */
307+
ret = armada_read_sensor(priv, temp);
308+
309+
return ret;
310+
}
311+
312+
static struct thermal_zone_device_ops legacy_ops = {
313+
.get_temp = armada_get_temp_legacy,
314+
};
315+
316+
static int armada_get_temp(void *_sensor, int *temp)
317+
{
318+
struct armada_thermal_sensor *sensor = _sensor;
319+
struct armada_thermal_priv *priv = sensor->priv;
320+
321+
/* Do the actual reading */
322+
return armada_read_sensor(priv, temp);
323+
}
324+
325+
static struct thermal_zone_of_device_ops of_ops = {
282326
.get_temp = armada_get_temp,
283327
};
284328

@@ -480,7 +524,9 @@ static void armada_set_sane_name(struct platform_device *pdev,
480524

481525
static int armada_thermal_probe(struct platform_device *pdev)
482526
{
483-
struct thermal_zone_device *thermal;
527+
struct thermal_zone_device *tz;
528+
struct armada_thermal_sensor *sensors;
529+
struct armada_drvdata *drvdata;
484530
const struct of_device_id *match;
485531
struct armada_thermal_priv *priv;
486532
int ret;
@@ -493,10 +539,12 @@ static int armada_thermal_probe(struct platform_device *pdev)
493539
if (!priv)
494540
return -ENOMEM;
495541

496-
priv->data = (struct armada_thermal_data *)match->data;
542+
drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
543+
if (!priv)
544+
return -ENOMEM;
497545

498-
/* Ensure device name is correct for the thermal core */
499-
armada_set_sane_name(pdev, priv);
546+
priv->dev = &pdev->dev;
547+
priv->data = (struct armada_thermal_data *)match->data;
500548

501549
/*
502550
* Legacy DT bindings only described "control1" register (also referred
@@ -510,35 +558,65 @@ static int armada_thermal_probe(struct platform_device *pdev)
510558
* is to define an overall system controller and put the thermal node
511559
* into it, which requires the use of regmaps across all the driver.
512560
*/
513-
if (IS_ERR(syscon_node_to_regmap(pdev->dev.parent->of_node)))
561+
if (IS_ERR(syscon_node_to_regmap(pdev->dev.parent->of_node))) {
562+
/* Ensure device name is correct for the thermal core */
563+
armada_set_sane_name(pdev, priv);
564+
514565
ret = armada_thermal_probe_legacy(pdev, priv);
515-
else
516-
ret = armada_thermal_probe_syscon(pdev, priv);
566+
if (ret)
567+
return ret;
517568

569+
priv->data->init(pdev, priv);
570+
571+
tz = thermal_zone_device_register(priv->zone_name, 0, 0, priv,
572+
&legacy_ops, NULL, 0, 0);
573+
if (IS_ERR(tz)) {
574+
dev_err(&pdev->dev,
575+
"Failed to register thermal zone device\n");
576+
return PTR_ERR(tz);
577+
}
578+
579+
drvdata->type = LEGACY;
580+
drvdata->data.tz = tz;
581+
platform_set_drvdata(pdev, drvdata);
582+
583+
return 0;
584+
}
585+
586+
ret = armada_thermal_probe_syscon(pdev, priv);
518587
if (ret)
519588
return ret;
520589

521590
priv->data->init(pdev, priv);
591+
drvdata->type = SYSCON;
592+
drvdata->data.priv = priv;
593+
platform_set_drvdata(pdev, drvdata);
522594

523-
thermal = thermal_zone_device_register(priv->zone_name, 0, 0, priv,
524-
&ops, NULL, 0, 0);
525-
if (IS_ERR(thermal)) {
595+
sensors = devm_kzalloc(&pdev->dev, sizeof(struct armada_thermal_sensor),
596+
GFP_KERNEL);
597+
if (!sensors)
598+
return -ENOMEM;
599+
600+
sensors->priv = priv;
601+
602+
tz = devm_thermal_zone_of_sensor_register(&pdev->dev, 0, sensors,
603+
&of_ops);
604+
if (IS_ERR(tz)) {
526605
dev_err(&pdev->dev,
527-
"Failed to register thermal zone device\n");
528-
return PTR_ERR(thermal);
606+
"Failed to register thermal sensor (err: %ld)\n",
607+
PTR_ERR(tz));
608+
return PTR_ERR(tz);
529609
}
530610

531-
platform_set_drvdata(pdev, thermal);
532-
533611
return 0;
534612
}
535613

536614
static int armada_thermal_exit(struct platform_device *pdev)
537615
{
538-
struct thermal_zone_device *armada_thermal =
539-
platform_get_drvdata(pdev);
616+
struct armada_drvdata *drvdata = platform_get_drvdata(pdev);
540617

541-
thermal_zone_device_unregister(armada_thermal);
618+
if (drvdata->type == LEGACY)
619+
thermal_zone_device_unregister(drvdata->data.tz);
542620

543621
return 0;
544622
}

0 commit comments

Comments
 (0)