thermal: dove: convert to a thermal OF sensor device
Subsystems (2)
RFC PATCH 2/3 thermal: dove: convert to a thermal OF sensor device
Convert the dove thermal infrastructure to an OF sensor device, and add the thermal zones for the SoC, with a critical trip point of 120?C. This allows us to specify thermal zones and couple them to cooling devices in DT.
--- arch/arm/boot/dts/dove.dtsi | 17 +++++++++++++++++ drivers/thermal/dove_thermal.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 8 deletions(-)
arch/arm/boot/dts/dove.dtsi +17 -0
@@ -455,6 +455,7 @@ }; thermal: thermal-diode at 001c { + #thermal-sensor-cells = <0>; compatible = "marvell,dove-thermal"; reg = <0x001c 0x0c>, <0x005c 0x08>; };
@@ -800,4 +801,20 @@ }; }; }; + + thermal-zones { + soc-thermal { + polling-delay-passive = <250>; /* ms */ + polling-delay = <1000>; /* ms */ + thermal-sensors = <&thermal>; + + soc_trips: trips { + soc_trip_crit: soc-crit { + temperature = <120000>; /* ?mC */ + hysteresis = <2000>; /* ?mC */ + type = "critical"; + }; + }; + }; + }; };
drivers/thermal/dove_thermal.c +25 -8
@@ -46,6 +46,7 @@struct dove_thermal_priv {void __iomem *sensor;void __iomem *control; +struct device *dev; };static int dove_init_sensor (const struct dove_thermal_priv *priv)
@@ -92,17 +93,15 @@ static int dove_init_sensor(const struct dove_thermal_priv *priv)return 0 ; } -static int dove_get_temp (struct thermal_zone_device *thermal, -int *temp) +static int dove_of_get_temp (void *data,int *temp) { +struct dove_thermal_priv *priv = data;unsigned long reg; -struct dove_thermal_priv *priv = thermal->devdata;/* Valid check */ reg =readl_relaxed (priv->control +PMU_TEMP_DIOD_CTRL1_REG );if ((reg &PMU_TDC1_TEMP_VALID_MASK ) ==0x0 ) { -dev_err (&thermal->device, -"Temperature sensor reading not valid\n" ); +dev_err (priv->dev,"Temperature sensor reading not valid\n" );return -EIO ; }
@@ -118,10 +117,22 @@ static int dove_get_temp(struct thermal_zone_device *thermal,return 0 ; } +static int dove_get_temp (struct thermal_zone_device *thermal, +int *temp) +{ +struct dove_thermal_priv *priv = thermal->devdata; + +return dove_of_get_temp (priv, temp); +} +static struct thermal_zone_device_ops ops = { .get_temp = dove_get_temp, }; +static const struct thermal_zone_of_device_ops of_ops = { + .get_temp = dove_of_get_temp, +}; +static const struct of_device_id dove_thermal_id_table[] = { { .compatible ="marvell,dove-thermal" }, {}
@@ -138,6 +149,8 @@ static int dove_thermal_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; + priv->dev = &pdev->dev; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); priv->sensor =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (priv->sensor))
@@ -154,8 +167,11 @@ static int dove_thermal_probe(struct platform_device *pdev)return ret; } - thermal =thermal_zone_device_register ("dove_thermal" ,0 ,0 , - priv, &ops,NULL ,0 ,0 ); + thermal =devm_thermal_zone_of_sensor_register (&pdev->dev,0 , + priv, &of_ops); +if (IS_ERR (thermal)) + thermal =thermal_zone_device_register ("dove_thermal" ,0 ,0 , + priv, &ops,NULL ,0 ,0 );if (IS_ERR (thermal)) {dev_err (&pdev->dev,"Failed to register thermal zone device\n" );
@@ -172,7 +188,8 @@ static int dove_thermal_exit(struct platform_device *pdev)struct thermal_zone_device *dove_thermal =platform_get_drvdata (pdev); -thermal_zone_device_unregister (dove_thermal); +if (!pdev->dev.of_node) +thermal_zone_device_unregister (dove_thermal);return 0 ; }
Signature · 1 line
2.7.4
RFC PATCH 2/3 thermal: dove: convert to a thermal OF sensor device
Quoted 124 lines · Russell King
Convert the dove thermal infrastructure to an OF sensor device, and add the thermal zones for the SoC, with a critical trip point of 120?C. This allows us to specify thermal zones and couple them to cooling devices in DT.
Signed-off-by Russell King <[email protected]>--- arch/arm/boot/dts/dove.dtsi | 17 +++++++++++++++++ drivers/thermal/dove_thermal.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 8 deletions(-)arch/arm/boot/dts/dove.dtsi +17
-0@@ -455,6 +455,7 @@ }; thermal: thermal-diode at 001c { + #thermal-sensor-cells = <0>; compatible = "marvell,dove-thermal"; reg = <0x001c 0x0c>, <0x005c 0x08>; };@@ -800,4 +801,20 @@ }; }; }; + + thermal-zones { + soc-thermal { + polling-delay-passive = <250>; /* ms */ + polling-delay = <1000>; /* ms */ + thermal-sensors = <&thermal>; + + soc_trips: trips { + soc_trip_crit: soc-crit { + temperature = <120000>; /* ?mC */ + hysteresis = <2000>; /* ?mC */ + type = "critical"; + }; + }; + }; + }; };drivers/thermal/dove_thermal.c +23
-7@@ -46,6 +46,7 @@struct dove_thermal_priv {void __iomem *sensor;void __iomem *control; +struct device *dev; };static int dove_init_sensor (const struct dove_thermal_priv *priv)@@ -92,17 +93,15 @@ static int dove_init_sensor(const struct dove_thermal_priv *priv)return 0 ; } -static int dove_get_temp (struct thermal_zone_device *thermal, -int *temp) +static int dove_of_get_temp (void *data,int *temp) { +struct dove_thermal_priv *priv = data;unsigned long reg; -struct dove_thermal_priv *priv = thermal->devdata;/* Valid check */ reg =readl_relaxed (priv->control +PMU_TEMP_DIOD_CTRL1_REG );if ((reg &PMU_TDC1_TEMP_VALID_MASK ) ==0x0 ) { -dev_err (&thermal->device, -"Temperature sensor reading not valid\n" ); +dev_err (priv->dev,"Temperature sensor reading not valid\n" );return -EIO ; }@@ -118,10 +117,22 @@ static int dove_get_temp(struct thermal_zone_device *thermal,return 0 ; } +static int dove_get_temp (struct thermal_zone_device *thermal, +int *temp) +{ +struct dove_thermal_priv *priv = thermal->devdata; + +return dove_of_get_temp (priv, temp); +} +static struct thermal_zone_device_ops ops = { .get_temp = dove_get_temp, }; +static const struct thermal_zone_of_device_ops of_ops = { + .get_temp = dove_of_get_temp, +}; +static const struct of_device_id dove_thermal_id_table[] = { { .compatible ="marvell,dove-thermal" }, {}@@ -138,6 +149,8 @@ static int dove_thermal_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; + priv->dev = &pdev->dev; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); priv->sensor =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (priv->sensor))@@ -154,8 +167,11 @@ static int dove_thermal_probe(struct platform_device *pdev)return ret; } - thermal =thermal_zone_device_register ("dove_thermal" ,0 ,0 , - priv, &ops,NULL ,0 ,0 ); + thermal =devm_thermal_zone_of_sensor_register (&pdev->dev,0 , + priv, &of_ops); +if (IS_ERR (thermal)) + thermal =thermal_zone_device_register ("dove_thermal" ,0 ,0 , + priv, &ops,NULL ,0 ,0 );if (IS_ERR (thermal)) {dev_err (&pdev->dev,"Failed to register thermal zone device\n" );
drivers/thermal/dove_thermal.c static int dove_thermal_exit(struct platform_device *pdev) · line 192
Quoted 6 lines
drivers/thermal/dove_thermal.c +2
-1@@ -172,7 +188,8 @@ static int dove_thermal_exit(struct platform_device *pdev)struct thermal_zone_device *dove_thermal =platform_get_drvdata (pdev); -thermal_zone_device_unregister (dove_thermal); +if (!pdev->dev.of_node) +thermal_zone_device_unregister (dove_thermal);
Russell,
Now that thermal-zones is defined in dove.dtsi do you see any need to call thermal_zone_device_register? Is there a case where in devm_thermal_zone_of_sensor_register is known to fail?
If not then we can even get rid of ops, dove_get_temp function.
Regards,
Keerthy
Quoted 4 lines
drivers/thermal/dove_thermal.c +0
-0return 0 ; }
RFC PATCH 2/3 thermal: dove: convert to a thermal OF sensor device
Quoted 136 lines · Keerthy
Quoted 124 lines · Russell King
Convert the dove thermal infrastructure to an OF sensor device, and add the thermal zones for the SoC, with a critical trip point of 120?C. This allows us to specify thermal zones and couple them to cooling devices in DT.
Signed-off-by Russell King <[email protected]>---
arch/arm/boot/dts/dove.dtsi| 17 +++++++++++++++++drivers/thermal/dove_thermal.c| 33 +++++++++++++++++++++++++--------2 files changed, 42 insertions(+), 8 deletions(-)arch/arm/boot/dts/dove.dtsi +17
-0@@ -455,6 +455,7 @@ }; thermal: thermal-diode at 001c { + #thermal-sensor-cells = <0>; compatible = "marvell,dove-thermal"; reg = <0x001c 0x0c>, <0x005c 0x08>; };@@ -800,4 +801,20 @@ }; }; }; + + thermal-zones { + soc-thermal { + polling-delay-passive = <250>; /* ms */ + polling-delay = <1000>; /* ms */ + thermal-sensors = <&thermal>; + + soc_trips: trips { + soc_trip_crit: soc-crit { + temperature = <120000>; /* ?mC */ + hysteresis = <2000>; /* ?mC */ + type = "critical"; + }; + }; + }; + }; };drivers/thermal/dove_thermal.c +23
-7@@ -46,6 +46,7 @@struct dove_thermal_priv {void __iomem *sensor;void __iomem *control; +struct device *dev; };static int dove_init_sensor (const struct dove_thermal_priv *priv)@@ -92,17 +93,15 @@ static int dove_init_sensor(const struct dove_thermal_priv *priv)return 0 ; } -static int dove_get_temp (struct thermal_zone_device *thermal, -int *temp) +static int dove_of_get_temp (void *data,int *temp) { +struct dove_thermal_priv *priv = data;unsigned long reg; -struct dove_thermal_priv *priv = thermal->devdata;/* Valid check */ reg =readl_relaxed (priv->control +PMU_TEMP_DIOD_CTRL1_REG );if ((reg &PMU_TDC1_TEMP_VALID_MASK ) ==0x0 ) { -dev_err (&thermal->device, -"Temperature sensor reading not valid\n" ); +dev_err (priv->dev,"Temperature sensor reading not valid\n" );return -EIO ; }@@ -118,10 +117,22 @@ static int dove_get_temp(struct thermal_zone_device *thermal,return 0 ; } +static int dove_get_temp (struct thermal_zone_device *thermal, +int *temp) +{ +struct dove_thermal_priv *priv = thermal->devdata; + +return dove_of_get_temp (priv, temp); +} +static struct thermal_zone_device_ops ops = { .get_temp = dove_get_temp, }; +static const struct thermal_zone_of_device_ops of_ops = { + .get_temp = dove_of_get_temp, +}; +static const struct of_device_id dove_thermal_id_table[] = { { .compatible ="marvell,dove-thermal" }, {}@@ -138,6 +149,8 @@ static int dove_thermal_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; + priv->dev = &pdev->dev; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); priv->sensor =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (priv->sensor))@@ -154,8 +167,11 @@ static int dove_thermal_probe(struct platform_device *pdev)return ret; } - thermal =thermal_zone_device_register ("dove_thermal" ,0 ,0 , - priv, &ops,NULL ,0 ,0 ); + thermal =devm_thermal_zone_of_sensor_register (&pdev->dev,0 , + priv, &of_ops); +if (IS_ERR (thermal)) + thermal =thermal_zone_device_register ("dove_thermal" ,0 ,0 , + priv, &ops,NULL ,0 ,0 );if (IS_ERR (thermal)) {dev_err (&pdev->dev,"Failed to register thermal zone device\n" );drivers/thermal/dove_thermal.c static int dove_thermal_exit(struct platform_device *pdev) · line 192
Quoted 6 lines
drivers/thermal/dove_thermal.c +2
-1@@ -172,7 +188,8 @@ static int dove_thermal_exit(struct platform_device *pdev)struct thermal_zone_device *dove_thermal =platform_get_drvdata (pdev); -thermal_zone_device_unregister (dove_thermal); +if (!pdev->dev.of_node) +thermal_zone_device_unregister (dove_thermal);Russell,
Quoted 5 lines
Now that thermal-zones is defined in
dove.dtsido you see any need to callthermal_zone_device_register? Is there a case where indevm_thermal_zone_of_sensor_registeris known to fail?If not then we can even get rid of ops,
dove_get_tempfunction.
That's there because I also boot non-DT from time to time, and having the thermal driver still register means that I don't have to carry the older hwmon implementation of the same around. However, it can probably be dropped for mainline at the expense of an additional small patch carried locally.
Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
RFC PATCH 2/3 thermal: dove: convert to a thermal OF sensor device
Quoted 141 lines · Russell King - ARM Linux
Quoted 140 lines · Keerthy
Quoted 124 lines · Russell King
Convert the dove thermal infrastructure to an OF sensor device, and add the thermal zones for the SoC, with a critical trip point of 120?C. This allows us to specify thermal zones and couple them to cooling devices in DT.
Signed-off-by Russell King <[email protected]>---
arch/arm/boot/dts/dove.dtsi| 17 +++++++++++++++++drivers/thermal/dove_thermal.c| 33 +++++++++++++++++++++++++--------2 files changed, 42 insertions(+), 8 deletions(-)arch/arm/boot/dts/dove.dtsi +17
-0@@ -455,6 +455,7 @@ }; thermal: thermal-diode at 001c { + #thermal-sensor-cells = <0>; compatible = "marvell,dove-thermal"; reg = <0x001c 0x0c>, <0x005c 0x08>; };@@ -800,4 +801,20 @@ }; }; }; + + thermal-zones { + soc-thermal { + polling-delay-passive = <250>; /* ms */ + polling-delay = <1000>; /* ms */ + thermal-sensors = <&thermal>; + + soc_trips: trips { + soc_trip_crit: soc-crit { + temperature = <120000>; /* ?mC */ + hysteresis = <2000>; /* ?mC */ + type = "critical"; + }; + }; + }; + }; };drivers/thermal/dove_thermal.c +23
-7@@ -46,6 +46,7 @@struct dove_thermal_priv {void __iomem *sensor;void __iomem *control; +struct device *dev; };static int dove_init_sensor (const struct dove_thermal_priv *priv)@@ -92,17 +93,15 @@ static int dove_init_sensor(const struct dove_thermal_priv *priv)return 0 ; } -static int dove_get_temp (struct thermal_zone_device *thermal, -int *temp) +static int dove_of_get_temp (void *data,int *temp) { +struct dove_thermal_priv *priv = data;unsigned long reg; -struct dove_thermal_priv *priv = thermal->devdata;/* Valid check */ reg =readl_relaxed (priv->control +PMU_TEMP_DIOD_CTRL1_REG );if ((reg &PMU_TDC1_TEMP_VALID_MASK ) ==0x0 ) { -dev_err (&thermal->device, -"Temperature sensor reading not valid\n" ); +dev_err (priv->dev,"Temperature sensor reading not valid\n" );return -EIO ; }@@ -118,10 +117,22 @@ static int dove_get_temp(struct thermal_zone_device *thermal,return 0 ; } +static int dove_get_temp (struct thermal_zone_device *thermal, +int *temp) +{ +struct dove_thermal_priv *priv = thermal->devdata; + +return dove_of_get_temp (priv, temp); +} +static struct thermal_zone_device_ops ops = { .get_temp = dove_get_temp, }; +static const struct thermal_zone_of_device_ops of_ops = { + .get_temp = dove_of_get_temp, +}; +static const struct of_device_id dove_thermal_id_table[] = { { .compatible ="marvell,dove-thermal" }, {}@@ -138,6 +149,8 @@ static int dove_thermal_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; + priv->dev = &pdev->dev; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); priv->sensor =devm_ioremap_resource (&pdev->dev, res);if (IS_ERR (priv->sensor))@@ -154,8 +167,11 @@ static int dove_thermal_probe(struct platform_device *pdev)return ret; } - thermal =thermal_zone_device_register ("dove_thermal" ,0 ,0 , - priv, &ops,NULL ,0 ,0 ); + thermal =devm_thermal_zone_of_sensor_register (&pdev->dev,0 , + priv, &of_ops); +if (IS_ERR (thermal)) + thermal =thermal_zone_device_register ("dove_thermal" ,0 ,0 , + priv, &ops,NULL ,0 ,0 );if (IS_ERR (thermal)) {dev_err (&pdev->dev,"Failed to register thermal zone device\n" );drivers/thermal/dove_thermal.c static int dove_thermal_exit(struct platform_device *pdev) · line 192
Quoted 6 lines
drivers/thermal/dove_thermal.c +2
-1@@ -172,7 +188,8 @@ static int dove_thermal_exit(struct platform_device *pdev)struct thermal_zone_device *dove_thermal =platform_get_drvdata (pdev); -thermal_zone_device_unregister (dove_thermal); +if (!pdev->dev.of_node) +thermal_zone_device_unregister (dove_thermal);Russell,
Now that thermal-zones is defined in
dove.dtsido you see any need to callthermal_zone_device_register? Is there a case where indevm_thermal_zone_of_sensor_registeris known to fail?
Quoted 7 lines
Quoted 1 line
If not then we can even get rid of ops,
dove_get_tempfunction.That's there because I also boot non-DT from time to time, and having the thermal driver still register means that I don't have to carry the older hwmon implementation of the same around. However, it can probably be dropped for mainline at the expense of an additional small patch carried locally.
Okay. If there is still a non-DT case then it makes sense to keep it the way it is now and may be add that point in the commit log that there is fall back mechanism in place for non-DT.
Quoted 1 line
RFC PATCH 2/3 thermal: dove: convert to a thermal OF sensor device
In reply to Russell KingRussell,
Quoted 9 lines · Russell King
Convert the dove thermal infrastructure to an OF sensor device, and add the thermal zones for the SoC, with a critical trip point of 120?C. This allows us to specify thermal zones and couple them to cooling devices in DT.
Signed-off-by Russell King <[email protected]>--- arch/arm/boot/dts/dove.dtsi | 17 +++++++++++++++++ drivers/thermal/dove_thermal.c | 33 +++++++++++++++++++++++++--------
I have no opposition to these changes. The only request, to avoid conflicts, is to split the patch into driver and DTS changes. We have been pushing these separately. DTS changes go via the arch tree. Drivers changes goes via Rui/me.
You can add my:
On the DTSI patch.