Skip to contentSkip to conversation

Marvell EBU thermal sensor consolidation

PATCH New Ezequiel Garcia 6 participants 43 messages Mar 20, 2013 – Mar 22, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Marvell EBU thermal sensor consolidation

This patchset is my first attempt at adding basic thermal sensor support on Armada 370 and Armada XP.

Given Armada 370/XP and the other Marvell SoC with thermal support, namely Kirkwood and Dove, have fairly similar thermal devices it made sense to integrate all of them into a single driver: mvebu-thermal.

The patches have been carefully splitted to make the changeset as less invasive as possible. These changes can be divided in five stages:

1. Rename 'kirkwood' driver to 'mvebu'
2. Some fixes inherited from kirkwood driver applied to new mvebu driver
3. Prepare mvebu driver to support multiple SoC
4. Add thermal support for each Marvell SoC on top of mvebu driver
5. Add device tree nodes for Armada 370 and Armada XP
6. Fix defconfigs for all the platforms involved

Testing have been done on the following boards:

Kirkwood:   Plat'home Openblocks A6
Armada 370: Globalscale Mirabox and Marvell Armada 370 RD
Armada XP:  Plat'home Openblocks AX3 and Marvell Armada XP DB-MV784MP-GP

Dove is *not* tested due to lack of hardware.

Also, please note that the defconfigs for involved platforms have been fixed deliberately in a single patch, to ease maintainer's job as the defconfigs file goes through one tree and the thermal driver should go through another.

Since I'm merging two existing drivers into a new driver, I retained authorship and copyright of the merged drivers and added my own. For this reason, I'd like to have Andrew and Nobuhiro Acked (or Nacked, of course).

Any feedback or comments are welcome!

Ezequiel Garcia (16):
thermal: Rename driver 'kirkwood' -> 'mvebu'
thermal: mvebu: Rename symbols 'kirkwood' -> 'mvebu'
thermal: mvebu: Move MODULE_DEVICE_TABLE upwards
thermal: mvebu: Remove unneeded variable initialization
thermal: mvebu: Fix valid check for thermal register
thermal: mvebu: Convert to devm_ioremap_resource()
thermal: mvebu: Fix license declaration
thermal: mvebu: Fix temperature output formula for kirkwood
thermal: mvebu: Rename kirkwood definitions to mvebu
thermal: mvebu: Add infrastructure to support more multiple SoC
variants
thermal: mvebu: Add support for Armada XP thermal sensor
thermal: mvebu: Add support for Armada 370 thermal sensor
thermal: mvebu: Add support for Marvell Dove SoC family
ARM: mvebu: Add thermal support to Armada XP device tree
ARM: mvebu: Add thermal support to Armada 370 device tree
ARM: configs: Update mvebu, dove and kirkwood defconfigs for thermal

 .../devicetree/bindings/thermal/dove-thermal.txt   |   18 -
 .../bindings/thermal/kirkwood-thermal.txt          |   15 -
 .../devicetree/bindings/thermal/mvebu-thermal.txt  |   31 ++
 arch/arm/boot/dts/armada-370.dtsi                  |    6 +
 arch/arm/boot/dts/armada-xp.dtsi                   |    6 +
 arch/arm/configs/dove_defconfig                    |    2 +-
 arch/arm/configs/kirkwood_defconfig                |    2 +-
 arch/arm/configs/mvebu_defconfig                   |    2 +
 drivers/thermal/Kconfig                            |   18 +-
 drivers/thermal/Makefile                           |    3 +-
 drivers/thermal/dove_thermal.c                     |  209 ------------
 drivers/thermal/kirkwood_thermal.c                 |  134 --------
 drivers/thermal/mvebu_thermal.c                    |  342 ++++++++++++++++++++
 13 files changed, 395 insertions(+), 393 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/thermal/dove-thermal.txt
 delete mode 100644 Documentation/devicetree/bindings/thermal/kirkwood-thermal.txt
 create mode 100644 Documentation/devicetree/bindings/thermal/mvebu-thermal.txt
 delete mode 100644 drivers/thermal/dove_thermal.c
 delete mode 100644 drivers/thermal/kirkwood_thermal.c
 create mode 100644 drivers/thermal/mvebu_thermal.c
Signature · 1 line
1.7.8.6
#1 lore raw

PATCH 1/16 thermal: Rename driver 'kirkwood' -> 'mvebu'

This driver will support several Marvell SoC, so it is convenient to rename it to 'mvebu' to represent accurately the hardware it supports.

---
 .../bindings/thermal/kirkwood-thermal.txt          |   15 ---
 .../devicetree/bindings/thermal/mvebu-thermal.txt  |   15 +++
 drivers/thermal/Kconfig                            |   10 +-
 drivers/thermal/Makefile                           |    2 +-
 drivers/thermal/kirkwood_thermal.c                 |  134 --------------------
 drivers/thermal/mvebu_thermal.c                    |  134 ++++++++++++++++++++
 6 files changed, 155 insertions(+), 155 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/thermal/kirkwood-thermal.txt
 create mode 100644 Documentation/devicetree/bindings/thermal/mvebu-thermal.txt
 delete mode 100644 drivers/thermal/kirkwood_thermal.c
 create mode 100644 drivers/thermal/mvebu_thermal.c
Documentation/devicetree/bindings/thermal/kirkwood-thermal.txt deleted +0 -15
deleted file mode 100644
index 8c0f5eb..0000000
@@ -1,15 +0,0 @@
-* Kirkwood Thermal
-
-This version is for Kirkwood 88F8262 & 88F6283 SoCs. Other kirkwoods
-don't contain a thermal sensor.
-
-Required properties:
-- compatible : "marvell,kirkwood-thermal"
-- reg : Address range of the thermal registers
-
-Example:
-
-	thermal at 10078 {
-		compatible = "marvell,kirkwood-thermal";
-		reg = <0x10078 0x4>;
-	};
Documentation/devicetree/bindings/thermal/mvebu-thermal.txt new file +15 -0
new file mode 100644
index 0000000..8c0f5eb
@@ -0,0 +1,15 @@
+* Kirkwood Thermal
+
+This version is for Kirkwood 88F8262 & 88F6283 SoCs. Other kirkwoods
+don't contain a thermal sensor.
+
+Required properties:
+- compatible : "marvell,kirkwood-thermal"
+- reg : Address range of the thermal registers
+
+Example:
+
+	thermal at 10078 {
+		compatible = "marvell,kirkwood-thermal";
+		reg = <0x10078 0x4>;
+	};
drivers/thermal/Kconfig +5 -5
index a764f16..74f6b97 100644
@@ -101,13 +101,13 @@ config RCAR_THERMAL
 	  Enable this to plug the R-Car thermal sensor driver into the Linux
 	  thermal framework
 
-config KIRKWOOD_THERMAL
-	tristate "Temperature sensor on Marvell Kirkwood SoCs"
-	depends on ARCH_KIRKWOOD
+config MVEBU_THERMAL
+	tristate "Temperature sensor on Marvell EBU SoCs"
+	depends on PLAT_ORION
 	depends on OF
 	help
-	  Support for the Kirkwood thermal sensor driver into the Linux thermal
-	  framework. Only kirkwood 88F6282 and 88F6283 have this sensor.
+	  Support for the thermal controllers available in several Marvell
+	  EBU SoCs in the thermal framework.
 
 config EXYNOS_THERMAL
 	tristate "Temperature sensor on Samsung EXYNOS"
drivers/thermal/Makefile +1 -1
index d3a2b38..40293a1 100644
@@ -15,7 +15,7 @@ obj-$(CONFIG_CPU_THERMAL)	+= cpu_cooling.o
 # platform thermal drivers
 obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_RCAR_THERMAL)	+= rcar_thermal.o
-obj-$(CONFIG_KIRKWOOD_THERMAL)  += kirkwood_thermal.o
+obj-$(CONFIG_MVEBU_THERMAL)	+= mvebu_thermal.o
 obj-$(CONFIG_EXYNOS_THERMAL)	+= exynos_thermal.o
 obj-$(CONFIG_DOVE_THERMAL)  	+= dove_thermal.o
 obj-$(CONFIG_DB8500_THERMAL)	+= db8500_thermal.o
drivers/thermal/kirkwood_thermal.c deleted +0 -134

134 lines not on this page · raw message

drivers/thermal/mvebu_thermal.c new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
1.7.8.6
#2 lore raw

PATCH 2/16 thermal: mvebu: Rename symbols 'kirkwood' -> 'mvebu'

In reply to Ezequiel Garcia

This driver will be used to support Marvell EBU SoC thermal sensors. Therefore, we change every symbol and comment accordingly, before we make any functionality change.

---
 drivers/thermal/mvebu_thermal.c |   42 +++++++++++++++++++-------------------
 1 files changed, 21 insertions(+), 21 deletions(-)
drivers/thermal/mvebu_thermal.c +21 -21
index 65cb4f0..d61a750 100644
@@ -1,5 +1,5 @@
 /*
- * Kirkwood thermal sensor driver
+ * Marvell EBU thermal sensor driver
  *
  * Copyright (C) 2012 Nobuhiro Iwamatsu <[email protected]>
  *
@@ -27,16 +27,16 @@
 #define KIRKWOOD_THERMAL_TEMP_OFFSET	10
 #define KIRKWOOD_THERMAL_TEMP_MASK	0x1FF
 
-/* Kirkwood Thermal Sensor Dev Structure */
-struct kirkwood_thermal_priv {
+/* Marvell EBU Thermal Sensor Dev Structure */
+struct mvebu_thermal_priv {
 	void __iomem *sensor;
 };
 
-static int kirkwood_get_temp(struct thermal_zone_device *thermal,
+static int mvebu_get_temp(struct thermal_zone_device *thermal,
 			  unsigned long *temp)
 {
 	unsigned long reg;
-	struct kirkwood_thermal_priv *priv = thermal->devdata;
+	struct mvebu_thermal_priv *priv = thermal->devdata;
 
 	reg = readl_relaxed(priv->sensor);
 
@@ -61,18 +61,18 @@ static int kirkwood_get_temp(struct thermal_zone_device *thermal,
 }
 
 static struct thermal_zone_device_ops ops = {
-	.get_temp = kirkwood_get_temp,
+	.get_temp = mvebu_get_temp,
 };
 
-static const struct of_device_id kirkwood_thermal_id_table[] = {
+static const struct of_device_id mvebu_thermal_id_table[] = {
 	{ .compatible = "marvell,kirkwood-thermal" },
 	{}
 };
 
-static int kirkwood_thermal_probe(struct platform_device *pdev)
+static int mvebu_thermal_probe(struct platform_device *pdev)
 {
 	struct thermal_zone_device *thermal = NULL;
-	struct kirkwood_thermal_priv *priv;
+	struct mvebu_thermal_priv *priv;
 	struct resource *res;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -91,7 +91,7 @@ static int kirkwood_thermal_probe(struct platform_device *pdev)
 		return -EADDRNOTAVAIL;
 	}
 
-	thermal = thermal_zone_device_register("kirkwood_thermal", 0, 0,
+	thermal = thermal_zone_device_register("mvebu_thermal", 0, 0,
 					       priv, &ops, NULL, 0, 0);
 	if (IS_ERR(thermal)) {
 		dev_err(&pdev->dev,
@@ -104,31 +104,31 @@ static int kirkwood_thermal_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int kirkwood_thermal_exit(struct platform_device *pdev)
+static int mvebu_thermal_exit(struct platform_device *pdev)
 {
-	struct thermal_zone_device *kirkwood_thermal =
+	struct thermal_zone_device *mvebu_thermal =
 		platform_get_drvdata(pdev);
 
-	thermal_zone_device_unregister(kirkwood_thermal);
+	thermal_zone_device_unregister(mvebu_thermal);
 	platform_set_drvdata(pdev, NULL);
 
 	return 0;
 }
 
-MODULE_DEVICE_TABLE(of, kirkwood_thermal_id_table);
+MODULE_DEVICE_TABLE(of, mvebu_thermal_id_table);
 
-static struct platform_driver kirkwood_thermal_driver = {
-	.probe = kirkwood_thermal_probe,
-	.remove = kirkwood_thermal_exit,
+static struct platform_driver mvebu_thermal_driver = {
+	.probe = mvebu_thermal_probe,
+	.remove = mvebu_thermal_exit,
 	.driver = {
-		.name = "kirkwood_thermal",
+		.name = "mvebu_thermal",
 		.owner = THIS_MODULE,
-		.of_match_table = of_match_ptr(kirkwood_thermal_id_table),
+		.of_match_table = of_match_ptr(mvebu_thermal_id_table),
 	},
 };
 
-module_platform_driver(kirkwood_thermal_driver);
+module_platform_driver(mvebu_thermal_driver);
 
 MODULE_AUTHOR("Nobuhiro Iwamatsu <[email protected]>");
-MODULE_DESCRIPTION("kirkwood thermal driver");
+MODULE_DESCRIPTION("mvebu thermal driver");
 MODULE_LICENSE("GPL");
Signature · 1 line
1.7.8.6
#3 lore raw

PATCH 3/16 thermal: mvebu: Move MODULE_DEVICE_TABLE upwards

In reply to Ezequiel Garcia

This table will be needed by mvebu_thermal_probe() so we move it just below the declaration of the compatible device table.

---
 drivers/thermal/mvebu_thermal.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/thermal/mvebu_thermal.c +1 -2
index d61a750..77c488c 100644
@@ -68,6 +68,7 @@ static const struct of_device_id mvebu_thermal_id_table[] = {
 	{ .compatible = "marvell,kirkwood-thermal" },
 	{}
 };
+MODULE_DEVICE_TABLE(of, mvebu_thermal_id_table);
 
 static int mvebu_thermal_probe(struct platform_device *pdev)
 {
@@ -115,8 +116,6 @@ static int mvebu_thermal_exit(struct platform_device *pdev)
 	return 0;
 }
 
-MODULE_DEVICE_TABLE(of, mvebu_thermal_id_table);
-
 static struct platform_driver mvebu_thermal_driver = {
 	.probe = mvebu_thermal_probe,
 	.remove = mvebu_thermal_exit,
Signature · 1 line
1.7.8.6
#4 lore raw

PATCH 4/16 thermal: mvebu: Remove unneeded variable initialization

In reply to Ezequiel Garcia

This variable is used only after it's properly initialized, so there's no need to set it to NULL in its declaration.

---
 drivers/thermal/mvebu_thermal.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/thermal/mvebu_thermal.c +1 -1
index 77c488c..d54f90c 100644
@@ -72,7 +72,7 @@ MODULE_DEVICE_TABLE(of, mvebu_thermal_id_table);
 
 static int mvebu_thermal_probe(struct platform_device *pdev)
 {
-	struct thermal_zone_device *thermal = NULL;
+	struct thermal_zone_device *thermal;
 	struct mvebu_thermal_priv *priv;
 	struct resource *res;
 
Signature · 1 line
1.7.8.6
#5 lore raw

PATCH 5/16 thermal: mvebu: Fix valid check for thermal register

In reply to Ezequiel Garcia

The correct value is obtain by first shifting the register by the offset, later applying the valid mask and finally invert the result. This check was lacking an extra parenthesis to be strictly correct.

---
 drivers/thermal/mvebu_thermal.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/mvebu_thermal.c +2 -2
index d54f90c..ef04e4e 100644
@@ -41,8 +41,8 @@ static int mvebu_get_temp(struct thermal_zone_device *thermal,
 	reg = readl_relaxed(priv->sensor);
 
 	/* Valid check */
-	if (!(reg >> KIRKWOOD_THERMAL_VALID_OFFSET) &
-	    KIRKWOOD_THERMAL_VALID_MASK) {
+	if (!((reg >> KIRKWOOD_THERMAL_VALID_OFFSET) &
+	    KIRKWOOD_THERMAL_VALID_MASK)) {
 		dev_err(&thermal->device,
 			"Temperature sensor reading not valid\n");
 		return -EIO;
Signature · 1 line
1.7.8.6
#6 lore raw

PATCH 5/16 thermal: mvebu: Fix valid check for thermal register

Ezequiel,

Quoted 8 lines · Ezequiel Garcia

The correct value is obtain by first shifting the register by the offset, later applying the valid mask and finally invert the result. This check was lacking an extra parenthesis to be strictly correct.

---
 drivers/thermal/mvebu_thermal.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

For the next version of this series, could you please put this fix first in the series? In this state, it can't be applied to v3.9-rcX, nor -stable.

thx,

Jason.

#7 lore raw

PATCH 5/16 thermal: mvebu: Fix valid check for thermal register

Hi Jason,

Quoted 5 lines · Jason Cooper
Quoted 4 lines · Ezequiel Garcia

The correct value is obtain by first shifting the register by the offset, later applying the valid mask and finally invert the result. This check was lacking an extra parenthesis to be strictly correct.

Quoted 9 lines
Quoted 4 lines
---
 drivers/thermal/mvebu_thermal.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

For the next version of this series, could you please put this fix first in the series? In this state, it can't be applied to v3.9-rcX, nor -stable.

Given we're still discussing the aproach of this patchset. I think I prefer to send the fixes now, not as part of the current series but as independent patches.

What do you think?

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#8 lore raw

PATCH 5/16 thermal: mvebu: Fix valid check for thermal register

Quoted 18 lines · Ezequiel Garcia

Hi Jason,

Quoted 5 lines · Jason Cooper
Quoted 4 lines · Ezequiel Garcia

The correct value is obtain by first shifting the register by the offset, later applying the valid mask and finally invert the result. This check was lacking an extra parenthesis to be strictly correct.

Quoted 9 lines
Quoted 4 lines
---
 drivers/thermal/mvebu_thermal.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

For the next version of this series, could you please put this fix first in the series? In this state, it can't be applied to v3.9-rcX, nor -stable.

Quoted 5 lines

Given we're still discussing the aproach of this patchset. I think I prefer to send the fixes now, not as part of the current series but as independent patches.

What do you think?

I agree.

thx,

Jason.

#9 lore raw

PATCH 5/16 thermal: mvebu: Fix valid check for thermal register

Quoted 19 lines · Jason Cooper
Quoted 18 lines · Ezequiel Garcia

Hi Jason,

Quoted 14 lines · Jason Cooper
Quoted 8 lines · Ezequiel Garcia

The correct value is obtain by first shifting the register by the offset, later applying the valid mask and finally invert the result. This check was lacking an extra parenthesis to be strictly correct.

---
 drivers/thermal/mvebu_thermal.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

For the next version of this series, could you please put this fix first in the series? In this state, it can't be applied to v3.9-rcX, nor -stable.

Quoted 8 lines
Quoted 5 lines

Given we're still discussing the aproach of this patchset. I think I prefer to send the fixes now, not as part of the current series but as independent patches.

What do you think?

I agree.

I have a question about this though: Who should pick patches for drivers/thermal/{dove,kirkwood,mvebu} ? You or Zhang?

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#10 lore raw

PATCH 5/16 thermal: mvebu: Fix valid check for thermal register

Quoted 24 lines · Ezequiel Garcia
Quoted 23 lines · Jason Cooper
Quoted 22 lines · Ezequiel Garcia

Hi Jason,

Quoted 5 lines · Jason Cooper
Quoted 4 lines · Ezequiel Garcia

The correct value is obtain by first shifting the register by the offset, later applying the valid mask and finally invert the result. This check was lacking an extra parenthesis to be strictly correct.

Quoted 9 lines
Quoted 4 lines
---
 drivers/thermal/mvebu_thermal.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

For the next version of this series, could you please put this fix first in the series? In this state, it can't be applied to v3.9-rcX, nor -stable.

Given we're still discussing the aproach of this patchset. I think I prefer to send the fixes now, not as part of the current series but as independent patches.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

What do you think?

I agree.

I have a question about this though: Who should pick patches for drivers/thermal/{dove,kirkwood,mvebu} ? You or Zhang?

That's up to Zhang. If he has a lot of changes going on this cycle, he'll probably want to take them through his tree. However, if he doesn't, and we have a lot of stuff depending on it (the rest of your series), he'll probably be ok with Ack'ing it and letting us take it through our tree.

thx,

Jason.

#11 lore raw

PATCH 6/16 thermal: mvebu: Convert to devm_ioremap_resource()

In reply to Ezequiel Garcia

Convert devm_request_and_ioremap() to the newly introduced devm_ioremap_resource() which provides more consistent error handling.

---
 drivers/thermal/mvebu_thermal.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/mvebu_thermal.c +2 -4
index ef04e4e..089b43d 100644
@@ -86,11 +86,9 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	priv->sensor = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->sensor) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
+	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
+	if (!priv->sensor)
 		return -EADDRNOTAVAIL;
-	}
 
 	thermal = thermal_zone_device_register("mvebu_thermal", 0, 0,
 					       priv, &ops, NULL, 0, 0);
Signature · 1 line
1.7.8.6
#12 lore raw

PATCH 6/16 thermal: mvebu: Convert to devm_ioremap_resource()

Quoted 13 lines · Ezequiel Garcia

Convert devm_request_and_ioremap() to the newly introduced devm_ioremap_resource() which provides more consistent error handling.

---
 drivers/thermal/mvebu_thermal.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/mvebu_thermal.c +0 -0
index ef04e4e..089b43d 100644

drivers/thermal/mvebu_thermal.c static int mvebu_thermal_probe(struct platform_device *pdev) · line 93

Quoted 10 lines
drivers/thermal/mvebu_thermal.c +2 -4
@@ -86,11 +86,9 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	priv->sensor = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->sensor) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
+	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
+	if (!priv->sensor)
 		return -EADDRNOTAVAIL;
-	}

Hi Ezequiel

It would be better to return priv->sensor, not a fixed error code.

Andrew

#13 lore raw

PATCH 6/16 thermal: mvebu: Convert to devm_ioremap_resource()

Quoted 17 lines · Andrew Lunn
Quoted 16 lines · Ezequiel Garcia

Convert devm_request_and_ioremap() to the newly introduced devm_ioremap_resource() which provides more consistent error handling.

---
 drivers/thermal/mvebu_thermal.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/mvebu_thermal.c +0 -0
index ef04e4e..089b43d 100644
@@ -86,11 +86,9 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
Quoted 11 lines

drivers/thermal/mvebu_thermal.c static int mvebu_thermal_probe(struct platform_device *pdev) · line 93

Quoted 7 lines
drivers/thermal/mvebu_thermal.c +2 -4
-	priv->sensor = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->sensor) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
+	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
+	if (!priv->sensor)
 		return -EADDRNOTAVAIL;
-	}

It would be better to return priv->sensor, not a fixed error code.

Good catch! I missed that.

Thanks,

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#14 lore raw

PATCH 6/16 thermal: mvebu: Convert to devm_ioremap_resource()

Quoted 30 lines · Ezequiel Garcia
Quoted 17 lines · Andrew Lunn
Quoted 16 lines · Ezequiel Garcia

Convert devm_request_and_ioremap() to the newly introduced devm_ioremap_resource() which provides more consistent error handling.

---
 drivers/thermal/mvebu_thermal.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/mvebu_thermal.c +0 -0
index ef04e4e..089b43d 100644
@@ -86,11 +86,9 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
Quoted 11 lines

drivers/thermal/mvebu_thermal.c static int mvebu_thermal_probe(struct platform_device *pdev) · line 93

Quoted 7 lines
drivers/thermal/mvebu_thermal.c +2 -4
-	priv->sensor = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->sensor) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
+	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
+	if (!priv->sensor)
 		return -EADDRNOTAVAIL;
-	}

It would be better to return priv->sensor, not a fixed error code.

Quoted 1 line

Good catch! I missed that.

And the same where the priv->control is introduced.

Andrew

#15 lore raw

PATCH 6/16 thermal: mvebu: Convert to devm_ioremap_resource()

In reply to Ezequiel Garcia

Hello.

Quoted 13 lines · Ezequiel Garcia

Convert devm_request_and_ioremap() to the newly introduced devm_ioremap_resource() which provides more consistent error handling.

---
  drivers/thermal/mvebu_thermal.c |    6 ++----
  1 files changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/mvebu_thermal.c +0 -0
index ef04e4e..089b43d 100644

drivers/thermal/mvebu_thermal.c static int mvebu_thermal_probe(struct platform_device *pdev) · line 90

Quoted 8 lines
drivers/thermal/mvebu_thermal.c +2 -3
@@ -86,11 +86,9 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
  	if (!priv)
  		return -ENOMEM;
 
-	priv->sensor = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->sensor) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
+	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
+	if (!priv->sensor)

devm_ioremap_resource() returns error code, not NULL.

WBR, Sergei

#16 lore raw

PATCH 6/16 thermal: mvebu: Convert to devm_ioremap_resource()

Hi Sergei,

Quoted 18 lines · Sergei Shtylyov
Quoted 16 lines · Ezequiel Garcia

Convert devm_request_and_ioremap() to the newly introduced devm_ioremap_resource() which provides more consistent error handling.

---
  drivers/thermal/mvebu_thermal.c |    6 ++----
  1 files changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/mvebu_thermal.c +0 -0
index ef04e4e..089b43d 100644
@@ -86,11 +86,9 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
  	if (!priv)
  		return -ENOMEM;
 
Quoted 8 lines

drivers/thermal/mvebu_thermal.c static int mvebu_thermal_probe(struct platform_device *pdev) · line 90

Quoted 5 lines
drivers/thermal/mvebu_thermal.c +2 -3
-	priv->sensor = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->sensor) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
+	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
+	if (!priv->sensor)

devm_ioremap_resource() returns error code, not NULL.

Yes, you're right. Andrew has already pointed this out and I'll fix it in the next round.

Thanks for the review!

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#17 lore raw

PATCH 6/16 thermal: mvebu: Convert to devm_ioremap_resource()

In reply to Ezequiel Garcia
Quoted 13 lines · Ezequiel Garcia

Convert devm_request_and_ioremap() to the newly introduced devm_ioremap_resource() which provides more consistent error handling.

---
 drivers/thermal/mvebu_thermal.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/mvebu_thermal.c +0 -0
index ef04e4e..089b43d 100644

drivers/thermal/mvebu_thermal.c static int mvebu_thermal_probe(struct platform_device *pdev) · line 91

Quoted 9 lines
drivers/thermal/mvebu_thermal.c +2 -3
@@ -86,11 +86,9 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
-	priv->sensor = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->sensor) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
+	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
+	if (!priv->sensor)
 		return -EADDRNOTAVAIL;

NAK. It pays to understand the interface that you're using. In this case, it *doesn't* return NULL on error, so you'll never reach -EADDRNOTAVAIL. Please look this function up in lib/devres.c and understand its API.

#18 lore raw

PATCH 6/16 thermal: mvebu: Convert to devm_ioremap_resource()

Quoted 17 lines · Russell King - ARM Linux
Quoted 16 lines · Ezequiel Garcia

Convert devm_request_and_ioremap() to the newly introduced devm_ioremap_resource() which provides more consistent error handling.

---
 drivers/thermal/mvebu_thermal.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/thermal/mvebu_thermal.c +0 -0
index ef04e4e..089b43d 100644
@@ -86,11 +86,9 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
 	if (!priv)
 		return -ENOMEM;
 
Quoted 12 lines

drivers/thermal/mvebu_thermal.c static int mvebu_thermal_probe(struct platform_device *pdev) · line 91

Quoted 6 lines
drivers/thermal/mvebu_thermal.c +2 -3
-	priv->sensor = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->sensor) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
+	priv->sensor = devm_ioremap_resource(&pdev->dev, res);
+	if (!priv->sensor)
 		return -EADDRNOTAVAIL;

NAK. It pays to understand the interface that you're using. In this case, it *doesn't* return NULL on error, so you'll never reach -EADDRNOTAVAIL. Please look this function up in lib/devres.c and understand its API.

Yes, you're right, I'll fix this on v2.

Thanks,

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#19 lore raw

PATCH 7/16 thermal: mvebu: Fix license declaration

In reply to Ezequiel Garcia

The license text declared in the header explicit says GPL v2 only, but the MODULE_LICENSE macro says GPL, which means GPL v2 or later. Fix it.

---
 drivers/thermal/mvebu_thermal.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/thermal/mvebu_thermal.c +1 -1
index 089b43d..5886a9c 100644
@@ -128,4 +128,4 @@ module_platform_driver(mvebu_thermal_driver);
 
 MODULE_AUTHOR("Nobuhiro Iwamatsu <[email protected]>");
 MODULE_DESCRIPTION("mvebu thermal driver");
-MODULE_LICENSE("GPL");
+MODULE_LICENSE("GPL v2");
Signature · 1 line
1.7.8.6
#20 lore raw

PATCH 8/16 thermal: mvebu: Fix temperature output formula for kirkwood

In reply to Ezequiel Garcia

The temperature formula was taken from the Armada 510 datasheet. This is wrong because the Kirkwood SoC thermal sensor has different coefficients.

Fix it using values from 88F682/88F683 Kirkwood datasheet.

---
 drivers/thermal/mvebu_thermal.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)
drivers/thermal/mvebu_thermal.c +1 -6
index 5886a9c..ed4c9b0 100644
@@ -48,14 +48,9 @@ static int mvebu_get_temp(struct thermal_zone_device *thermal,
 		return -EIO;
 	}
 
-	/*
-	 * Calculate temperature. See Section 8.10.1 of the 88AP510,
-	 * datasheet, which has the same sensor.
-	 * Documentation/arm/Marvell/README
-	 */
 	reg = (reg >> KIRKWOOD_THERMAL_TEMP_OFFSET) &
 		KIRKWOOD_THERMAL_TEMP_MASK;
-	*temp = ((2281638UL - (7298*reg)) / 10);
+	*temp = ((2363302UL - (7339*reg)) / 10);
 
 	return 0;
 }
Signature · 1 line
1.7.8.6
#21 lore raw

PATCH 8/16 thermal: mvebu: Fix temperature output formula for kirkwood

Quoted 10 lines · Ezequiel Garcia

The temperature formula was taken from the Armada 510 datasheet. This is wrong because the Kirkwood SoC thermal sensor has different coefficients.

Fix it using values from 88F682/88F683 Kirkwood datasheet.

---
 drivers/thermal/mvebu_thermal.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)

This is also a fix which should go at the beginning of the series.

thx,

Jason.

#22 lore raw

PATCH 8/16 thermal: mvebu: Fix temperature output formula for kirkwood

In reply to Ezequiel Garcia
Quoted 5 lines · Ezequiel Garcia

The temperature formula was taken from the Armada 510 datasheet. This is wrong because the Kirkwood SoC thermal sensor has different coefficients.

Fix it using values from 88F682/88F683 Kirkwood datasheet.

Err, hang on. You've changed this from being a Kirkwood specific driver to being a "mvebu" driver, which I had understood was being done to cover all Kirkwood, Dove, etc SoCs.

If that's the case, then this change is wrong because you break it for Dove.

If the coefficients are different between Kirkwood and Dove, then it needs to be adapted at run time depending on whether it's running on Kirkwood or Dove - not just having the coefficients changed at compile time to suit a different set of platforms.

If it's worth making a change, do it *properly*.

#23 lore raw

PATCH 8/16 thermal: mvebu: Fix temperature output formula for kirkwood

Quoted 14 lines · Russell King - ARM Linux
Quoted 5 lines · Ezequiel Garcia

The temperature formula was taken from the Armada 510 datasheet. This is wrong because the Kirkwood SoC thermal sensor has different coefficients.

Fix it using values from 88F682/88F683 Kirkwood datasheet.

Err, hang on. You've changed this from being a Kirkwood specific driver to being a "mvebu" driver, which I had understood was being done to cover all Kirkwood, Dove, etc SoCs.

If that's the case, then this change is wrong because you break it for Dove.

Quoted 6 lines

If the coefficients are different between Kirkwood and Dove, then it needs to be adapted at run time depending on whether it's running on Kirkwood or Dove - not just having the coefficients changed at compile time to suit a different set of platforms.

If it's worth making a change, do it *properly*.

I'm not sure I'm following you.

This patch fixes the Kirkwood formula on a driver that, at this point, only supports Kirkwood.

Dove SoC thermal sensor is supported in dove-thermal, until it's merged in patch 13/16 (i.e. after this patch).

AFAIK, I'm not breaking support for any platform in any point of the patchset.

Perhaps I'm missing something?

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#24 lore raw

PATCH 9/16 thermal: mvebu: Rename kirkwood definitions to mvebu

In reply to Ezequiel Garcia

This definitions will be also valid for other SoC,
such as Armada 370 and Armada XP. Therefore we rename them as 'mvebu'.

---
 drivers/thermal/mvebu_thermal.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
drivers/thermal/mvebu_thermal.c +8 -8
index ed4c9b0..3304057 100644
@@ -22,10 +22,10 @@
 #include <linux/platform_device.h>
 #include <linux/thermal.h>
 
-#define KIRKWOOD_THERMAL_VALID_OFFSET	9
-#define KIRKWOOD_THERMAL_VALID_MASK	0x1
-#define KIRKWOOD_THERMAL_TEMP_OFFSET	10
-#define KIRKWOOD_THERMAL_TEMP_MASK	0x1FF
+#define MVEBU_THERMAL_VALID_OFFSET	9
+#define MVEBU_THERMAL_VALID_MASK	0x1
+#define MVEBU_THERMAL_TEMP_OFFSET	10
+#define MVEBU_THERMAL_TEMP_MASK		0x1FF
 
 /* Marvell EBU Thermal Sensor Dev Structure */
 struct mvebu_thermal_priv {
@@ -41,15 +41,15 @@ static int mvebu_get_temp(struct thermal_zone_device *thermal,
 	reg = readl_relaxed(priv->sensor);
 
 	/* Valid check */
-	if (!((reg >> KIRKWOOD_THERMAL_VALID_OFFSET) &
-	    KIRKWOOD_THERMAL_VALID_MASK)) {
+	if (!((reg >> MVEBU_THERMAL_VALID_OFFSET) &
+	    MVEBU_THERMAL_VALID_MASK)) {
 		dev_err(&thermal->device,
 			"Temperature sensor reading not valid\n");
 		return -EIO;
 	}
 
-	reg = (reg >> KIRKWOOD_THERMAL_TEMP_OFFSET) &
-		KIRKWOOD_THERMAL_TEMP_MASK;
+	reg = (reg >> MVEBU_THERMAL_TEMP_OFFSET) &
+		MVEBU_THERMAL_TEMP_MASK;
 	*temp = ((2363302UL - (7339*reg)) / 10);
 
 	return 0;
Signature · 1 line
1.7.8.6
#25 lore raw

PATCH 10/16 thermal: mvebu: Add infrastructure to support more multiple SoC variants

In reply to Ezequiel Garcia

This commit adds the infrastructure required for mvebu thermal driver to support multiple SoC variants.
In particular, we add support for an optional memory resource, and a couple of optionals function pointers:
* one to handle the case where the thermal sensor needs initialization,
* another one to support for valid sensor value checking

---
 drivers/thermal/mvebu_thermal.c |   68 ++++++++++++++++++++++++++++++++++----
 1 files changed, 60 insertions(+), 8 deletions(-)
drivers/thermal/mvebu_thermal.c +60 -8
index 3304057..bfe4817 100644
@@ -20,8 +20,11 @@
 #include <linux/of.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
+#include <linux/of_device.h>
 #include <linux/thermal.h>
 
+#define MVEBU_THERMAL_SOC_VARIANT_KIRKWOOD    0x1
+
 #define MVEBU_THERMAL_VALID_OFFSET	9
 #define MVEBU_THERMAL_VALID_MASK	0x1
 #define MVEBU_THERMAL_TEMP_OFFSET	10
@@ -30,28 +33,48 @@
 /* Marvell EBU Thermal Sensor Dev Structure */
 struct mvebu_thermal_priv {
 	void __iomem *sensor;
+	void __iomem *control;
+	int soc_variant;
+
+	/* Initialize the sensor (optional) */
+	void (*init_sensor)(struct mvebu_thermal_priv *);
+
+	/* Test for a valid sensor value (optional) */
+	bool (*is_valid)(struct mvebu_thermal_priv *);
 };
 
+static bool mvebu_is_valid(struct mvebu_thermal_priv *priv)
+{
+	unsigned long reg = readl_relaxed(priv->sensor);
+
+	return (reg >> MVEBU_THERMAL_VALID_OFFSET) &
+		MVEBU_THERMAL_VALID_MASK;
+}
+
 static int mvebu_get_temp(struct thermal_zone_device *thermal,
 			  unsigned long *temp)
 {
 	unsigned long reg;
 	struct mvebu_thermal_priv *priv = thermal->devdata;
 
-	reg = readl_relaxed(priv->sensor);
-
 	/* Valid check */
-	if (!((reg >> MVEBU_THERMAL_VALID_OFFSET) &
-	    MVEBU_THERMAL_VALID_MASK)) {
+	if (priv->is_valid && !priv->is_valid(priv)) {
 		dev_err(&thermal->device,
 			"Temperature sensor reading not valid\n");
 		return -EIO;
 	}
 
-	reg = (reg >> MVEBU_THERMAL_TEMP_OFFSET) &
+	reg = (readl_relaxed(priv->sensor) >> MVEBU_THERMAL_TEMP_OFFSET) &
 		MVEBU_THERMAL_TEMP_MASK;
-	*temp = ((2363302UL - (7339*reg)) / 10);
 
+	switch (priv->soc_variant) {
+	case MVEBU_THERMAL_SOC_VARIANT_KIRKWOOD:
+		*temp = ((2363302UL - (7339*reg)) / 10);
+		break;
+	default:
+		*temp = 0;
+		break;
+	}
 	return 0;
 }
 
@@ -60,17 +83,27 @@ static struct thermal_zone_device_ops ops = {
 };
 
 static const struct of_device_id mvebu_thermal_id_table[] = {
-	{ .compatible = "marvell,kirkwood-thermal" },
-	{}
+	{
+		.compatible = "marvell,kirkwood-thermal",
+		.data       = (void *) MVEBU_THERMAL_SOC_VARIANT_KIRKWOOD,
+	},
+	{
+		/* sentinel */
+	},
 };
 MODULE_DEVICE_TABLE(of, mvebu_thermal_id_table);
 
 static int mvebu_thermal_probe(struct platform_device *pdev)
 {
 	struct thermal_zone_device *thermal;
+	const struct of_device_id *match;
 	struct mvebu_thermal_priv *priv;
 	struct resource *res;
 
+	match = of_match_device(mvebu_thermal_id_table, &pdev->dev);
+	if (!match)
+		return -ENODEV;
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!res) {
 		dev_err(&pdev->dev, "Failed to get platform resource\n");
@@ -85,6 +118,25 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
 	if (!priv->sensor)
 		return -EADDRNOTAVAIL;
 
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	if (res) {
+		priv->control = devm_ioremap_resource(&pdev->dev, res);
+		if (!priv->control)
+			return -EADDRNOTAVAIL;
+	}
+
+	priv->soc_variant = (int)match->data;
+	switch (priv->soc_variant) {
+	case MVEBU_THERMAL_SOC_VARIANT_KIRKWOOD:
+		priv->is_valid = mvebu_is_valid;
+		break;
+	default:
+		break;
+	}
+
+	if (priv->init_sensor)
+		priv->init_sensor(priv);
+
 	thermal = thermal_zone_device_register("mvebu_thermal", 0, 0,
 					       priv, &ops, NULL, 0, 0);
 	if (IS_ERR(thermal)) {
Signature · 1 line
1.7.8.6
#26 lore raw

PATCH 11/16 thermal: mvebu: Add support for Armada XP thermal sensor

In reply to Ezequiel Garcia

With the infrastructure introduced to support more SoC, we can now easily add another thermal sensor.

The Armada XP sensor has no register to check for a valid temperature, and has a special formula to obtain the temperature from the thermal sensor output register.

---
 .../devicetree/bindings/thermal/mvebu-thermal.txt  |   21 ++++++---
 drivers/thermal/mvebu_thermal.c                    |   50 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 7 deletions(-)
Documentation/devicetree/bindings/thermal/mvebu-thermal.txt +14 -7
index 8c0f5eb..7cc3fd4 100644
@@ -1,13 +1,20 @@
-* Kirkwood Thermal
-
-This version is for Kirkwood 88F8262 & 88F6283 SoCs. Other kirkwoods
-don't contain a thermal sensor.
+* Marvell EBU Thermal
 
 Required properties:
-- compatible : "marvell,kirkwood-thermal"
-- reg : Address range of the thermal registers
 
-Example:
+- compatible:	Should be set to one of the following:
+		marvell,kirkwood-thermal
+		marvell,armadaxp-thermal
+
+- reg:		Device's register space.
+		One or two entries are expected, see the examples below.
+		The first one is required for the sensor register;
+		the second one is optional and is used as the control
+		register for sensor calibration.
+		Currently the only SoC variant having one register range
+		is Kirkwood.
+
+Kirkwood example:
 
 	thermal at 10078 {
 		compatible = "marvell,kirkwood-thermal";
drivers/thermal/mvebu_thermal.c +50 -0

97 lines not on this page · raw message

Signature · 1 line
1.7.8.6
#27 lore raw

PATCH 12/16 thermal: mvebu: Add support for Armada 370 thermal sensor

In reply to Ezequiel Garcia

The Armada 370 has a register to check a valid temperature, and its own formula to obtain the temperature from the thermal sensor output register.

---
 .../devicetree/bindings/thermal/mvebu-thermal.txt  |    1 +
 drivers/thermal/mvebu_thermal.c                    |   39 ++++++++++++++++++++
 2 files changed, 40 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/thermal/mvebu-thermal.txt +1 -0
index 7cc3fd4..49d55a9 100644
@@ -5,6 +5,7 @@ Required properties:
 - compatible:	Should be set to one of the following:
 		marvell,kirkwood-thermal
 		marvell,armadaxp-thermal
+		marvell,armada370-thermal
 
 - reg:		Device's register space.
 		One or two entries are expected, see the examples below.
drivers/thermal/mvebu_thermal.c +39 -0
index 50f13e7..0b1e7a8 100644
@@ -20,12 +20,14 @@
 #include <linux/kernel.h>
 #include <linux/of.h>
 #include <linux/module.h>
+#include <linux/delay.h>
 #include <linux/platform_device.h>
 #include <linux/of_device.h>
 #include <linux/thermal.h>
 
 #define MVEBU_THERMAL_SOC_VARIANT_KIRKWOOD    0x1
 #define MVEBU_THERMAL_SOC_VARIANT_ARMADA_XP   0x2
+#define MVEBU_THERMAL_SOC_VARIANT_ARMADA_370  0x3
 
 #define MVEBU_THERMAL_VALID_OFFSET	9
 #define MVEBU_THERMAL_VALID_MASK	0x1
@@ -39,6 +41,7 @@
 #define PMU_TDC0_REF_CAL_CNT_OFFS	11
 #define PMU_TDC0_REF_CAL_CNT_MASK	(0x1ff << PMU_TDC0_REF_CAL_CNT_OFFS)
 #define PMU_TDC0_OTF_CAL_MASK		(0x1 << 30)
+#define PMU_TDC0_START_CAL_MASK		(0x1 << 25)
 
 /* Marvell EBU Thermal Sensor Dev Structure */
 struct mvebu_thermal_priv {
@@ -82,6 +85,31 @@ static void armadaxp_init_sensor(struct mvebu_thermal_priv *priv)
 	writel(reg, priv->sensor);
 }
 
+static void armada370_init_sensor(struct mvebu_thermal_priv *priv)
+{
+	unsigned long reg;
+
+	if (!priv->control)
+		return;
+
+	/* ??? */
+	reg = readl_relaxed(priv->control);
+	reg |= PMU_TDC0_OTF_CAL_MASK;
+	writel(reg, priv->control);
+
+	/* Reference calibration value */
+	reg &= ~PMU_TDC0_REF_CAL_CNT_MASK;
+	reg |= (0xf1 << PMU_TDC0_REF_CAL_CNT_OFFS);
+	writel(reg, priv->control);
+
+	/* ??? */
+	reg &= ~PMU_TDC0_START_CAL_MASK;
+	writel(reg, priv->control);
+
+	/* FIXME: Why do we need this delay? */
+	mdelay(10);
+}
+
 static bool mvebu_is_valid(struct mvebu_thermal_priv *priv)
 {
 	unsigned long reg = readl_relaxed(priv->sensor);
@@ -113,6 +141,9 @@ static int mvebu_get_temp(struct thermal_zone_device *thermal,
 	case MVEBU_THERMAL_SOC_VARIANT_ARMADA_XP:
 		*temp = (3153000000UL - (10000000UL*reg)) / 13825;
 		break;
+	case MVEBU_THERMAL_SOC_VARIANT_ARMADA_370:
+		*temp = (228000UL - 723*reg);
+		break;
 	default:
 		*temp = 0;
 		break;
@@ -134,6 +165,10 @@ static const struct of_device_id mvebu_thermal_id_table[] = {
 		.data       = (void *) MVEBU_THERMAL_SOC_VARIANT_ARMADA_XP,
 	},
 	{
+		.compatible = "marvell,armada370-thermal",
+		.data       = (void *) MVEBU_THERMAL_SOC_VARIANT_ARMADA_370,
+	},
+	{
 		/* sentinel */
 	},
 };
@@ -179,6 +214,10 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
 	case MVEBU_THERMAL_SOC_VARIANT_ARMADA_XP:
 		priv->init_sensor = armadaxp_init_sensor;
 		break;
+	case MVEBU_THERMAL_SOC_VARIANT_ARMADA_370:
+		priv->is_valid = mvebu_is_valid;
+		priv->init_sensor = armada370_init_sensor;
+		break;
 	default:
 		break;
 	}
Signature · 1 line
1.7.8.6
#28 lore raw

PATCH 13/16 thermal: mvebu: Add support for Marvell Dove SoC family

In reply to Ezequiel Garcia

With the infrastructure added in mvebu-thermal to support multiple SoC families, it is now possible to add support for Dove SoC. This patch adds such support taking the implementation from the dove-thermal driver, and then removing it.

---
 .../devicetree/bindings/thermal/dove-thermal.txt   |   18 --
 .../devicetree/bindings/thermal/mvebu-thermal.txt  |    8 +
 drivers/thermal/Kconfig                            |    8 -
 drivers/thermal/Makefile                           |    1 -
 drivers/thermal/dove_thermal.c                     |  209 --------------------
 drivers/thermal/mvebu_thermal.c                    |   75 +++++++
 6 files changed, 83 insertions(+), 236 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/thermal/dove-thermal.txt
 delete mode 100644 drivers/thermal/dove_thermal.c
Documentation/devicetree/bindings/thermal/dove-thermal.txt deleted +0 -18
deleted file mode 100644
index 6f47467..0000000
@@ -1,18 +0,0 @@
-* Dove Thermal
-
-This driver is for Dove SoCs which contain a thermal sensor.
-
-Required properties:
-- compatible : "marvell,dove-thermal"
-- reg : Address range of the thermal registers
-
-The reg properties should contain two ranges. The first is for the
-three Thermal Manager registers, while the second range contains the
-Thermal Diode Control Registers.
-
-Example:
-
-	thermal at 10078 {
-		compatible = "marvell,dove-thermal";
-		reg = <0xd001c 0x0c>, <0xd005c 0x08>;
-	};
Documentation/devicetree/bindings/thermal/mvebu-thermal.txt +8 -0
index 49d55a9..2c5297a 100644
@@ -6,6 +6,7 @@ Required properties:
 		marvell,kirkwood-thermal
 		marvell,armadaxp-thermal
 		marvell,armada370-thermal
+		marvell,dove-thermal
 
 - reg:		Device's register space.
 		One or two entries are expected, see the examples below.
@@ -21,3 +22,10 @@ Kirkwood example:
 		compatible = "marvell,kirkwood-thermal";
 		reg = <0x10078 0x4>;
 	};
+
+Dove example:
+
+	thermal: thermal at d001c {
+		compatible = "marvell,dove-thermal";
+		reg = <0xd001c 0x0c>, <0xd005c 0x08>;
+	};
drivers/thermal/Kconfig +0 -8
index 74f6b97..237c3e6 100644
@@ -126,14 +126,6 @@ config EXYNOS_THERMAL_EMUL
 	  device directory to support emulation mode. With emulation mode sysfs
 	  node, you can manually input temperature to TMU for simulation purpose.
 
-config DOVE_THERMAL
-	tristate "Temperature sensor on Marvell Dove SoCs"
-	depends on ARCH_DOVE
-	depends on OF
-	help
-	  Support for the Dove thermal sensor driver in the Linux thermal
-	  framework.
-
 config DB8500_THERMAL
 	bool "DB8500 thermal management"
 	depends on ARCH_U8500
drivers/thermal/Makefile +0 -1
index 40293a1..ddd77f4 100644
@@ -17,7 +17,6 @@ obj-$(CONFIG_SPEAR_THERMAL)	+= spear_thermal.o
 obj-$(CONFIG_RCAR_THERMAL)	+= rcar_thermal.o
 obj-$(CONFIG_MVEBU_THERMAL)	+= mvebu_thermal.o
 obj-$(CONFIG_EXYNOS_THERMAL)	+= exynos_thermal.o
-obj-$(CONFIG_DOVE_THERMAL)  	+= dove_thermal.o
 obj-$(CONFIG_DB8500_THERMAL)	+= db8500_thermal.o
 obj-$(CONFIG_DB8500_CPUFREQ_COOLING)	+= db8500_cpufreq_cooling.o
 obj-$(CONFIG_INTEL_POWERCLAMP)	+= intel_powerclamp.o
drivers/thermal/dove_thermal.c deleted +0 -209

209 lines not on this page · raw message

drivers/thermal/mvebu_thermal.c +75 -0

129 lines not on this page · raw message

Signature · 1 line
1.7.8.6
#29 lore raw

PATCH 13/16 thermal: mvebu: Add support for Marvell Dove SoC family

drivers/thermal/dove_thermal.c line 161

Quoted 7 lines
drivers/thermal/dove_thermal.c deleted +0 -5
-	priv->control = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->control) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
-		return -EADDRNOTAVAIL;
-	}

Hi Ezequiel

I've not looked too hard, but i don't see the equivalent of the above in your new probe function.

Andrew

#30 lore raw

PATCH 13/16 thermal: mvebu: Add support for Marvell Dove SoC family

Quoted 11 lines · Andrew Lunn

drivers/thermal/dove_thermal.c line 161

Quoted 7 lines
drivers/thermal/dove_thermal.c deleted +0 -5
-	priv->control = devm_request_and_ioremap(&pdev->dev, res);
-	if (!priv->control) {
-		dev_err(&pdev->dev, "Failed to request_ioremap memory\n");
-		return -EADDRNOTAVAIL;
-	}

Hi Ezequiel

Quoted 2 lines

I've not looked too hard, but i don't see the equivalent of the above in your new probe function.

Upps, Sorry, found it. Does exists.

#31 lore raw

PATCH 14/16 ARM: mvebu: Add thermal support to Armada XP device tree

In reply to Ezequiel Garcia

This patch depends on the patch to support Armada XP in mvebu_thermal driver:
'thermal: mvebu: Add support for Armada XP thermal sensor'

---
 arch/arm/boot/dts/armada-xp.dtsi |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/arm/boot/dts/armada-xp.dtsi +6 -0
index 1443949..d85fa6a 100644
@@ -151,5 +151,11 @@
 			status = "disabled";
 		};
 
+		thermal at d00182b0 {
+			compatible = "marvell,armadaxp-thermal";
+			reg = <0xd00182b0 0x4
+			       0xd00184d0 0x4>;
+			status = "okay";
+		};
 	};
 };
Signature · 1 line
1.7.8.6
#32 lore raw

PATCH 15/16 ARM: mvebu: Add thermal support to Armada 370 device tree

In reply to Ezequiel Garcia

This patch depends on the patch to add Armada 370 support in the mvebu_thermal driver:
'thermal: mvebu: Add support for Armada 370 thermal sensor'

---
 arch/arm/boot/dts/armada-370.dtsi |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/arm/boot/dts/armada-370.dtsi +6 -0
index 8188d13..5831994 100644
@@ -153,5 +153,11 @@
 			clocks = <&coreclk 0>;
 		};
 
+		thermal at d0018300 {
+			compatible = "marvell,armada370-thermal";
+			reg = <0xd0018300 0x4
+			       0xd0018304 0x4>;
+			status = "okay";
+		};
 	};
 };
Signature · 1 line
1.7.8.6
#33 lore raw

PATCH 15/16 ARM: mvebu: Add thermal support to Armada 370 device tree

Hello.

Quoted 3 lines · Ezequiel Garcia

This patch depends on the patch to add Armada 370 support in the mvebu_thermal driver:
'thermal: mvebu: Add support for Armada 370 thermal sensor'

Sch comments should follow the --- tear line, not precede it.

Quoted 4 lines
---
  arch/arm/boot/dts/armada-370.dtsi |    6 ++++++
  1 files changed, 6 insertions(+), 0 deletions(-)

WBR, Sergei

#34 lore raw

PATCH 15/16 ARM: mvebu: Add thermal support to Armada 370 device tree

Hi Sergei,

Quoted 8 lines · Sergei Shtylyov
Quoted 3 lines · Ezequiel Garcia

This patch depends on the patch to add Armada 370 support in the mvebu_thermal driver:
'thermal: mvebu: Add support for Armada 370 thermal sensor'

Sch comments should follow the --- tear line, not precede it.

Ouch. Yes, that was the original intention!

Thanks,

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#35 lore raw

PATCH 16/16 ARM: configs: Update mvebu, dove and kirkwood defconfigs for thermal

In reply to Ezequiel Garcia

The driver for Dove, Kirkwood and Armada XP/370 SoC has been integrated in a single driver called mvebu-thermal. Update the defconfig for each platform to reflect this.

---
Please note that this change was done independentely from the thermal driver patch in order to facilitate its merge by the respective maintainers.

 arch/arm/configs/dove_defconfig     |    2 +-
 arch/arm/configs/kirkwood_defconfig |    2 +-
 arch/arm/configs/mvebu_defconfig    |    2 ++
 3 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/configs/dove_defconfig +1 -1
index 4364eff..2136442 100644
@@ -76,7 +76,7 @@ CONFIG_SPI=y
 CONFIG_SPI_ORION=y
 # CONFIG_HWMON is not set
 CONFIG_THERMAL=y
-CONFIG_DOVE_THERMAL=y
+CONFIG_MVEBU_THERMAL=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_ROOT_HUB_TT=y
arch/arm/configs/kirkwood_defconfig +1 -1
index 8f0065b..081d39f 100644
@@ -120,7 +120,7 @@ CONFIG_SPI_ORION=y
 CONFIG_GPIO_SYSFS=y
 # CONFIG_HWMON is not set
 CONFIG_THERMAL=y
-CONFIG_KIRKWOOD_THERMAL=y
+CONFIG_MVEBU_THERMAL=y
 CONFIG_WATCHDOG=y
 CONFIG_ORION_WATCHDOG=y
 CONFIG_HID_DRAGONRISE=y
arch/arm/configs/mvebu_defconfig +2 -0
index 2ec8119..f2ac593 100644
@@ -49,6 +49,8 @@ CONFIG_MTD_M25P80=y
 CONFIG_SERIAL_8250_DW=y
 CONFIG_GPIOLIB=y
 CONFIG_GPIO_SYSFS=y
+CONFIG_THERMAL=y
+CONFIG_MVEBU_THERMAL=y
 CONFIG_USB_SUPPORT=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
Signature · 1 line
1.7.8.6
#36 lore raw

cover Marvell EBU thermal sensor consolidation

In reply to Ezequiel Garcia
Quoted 6 lines · Ezequiel Garcia

This patchset is my first attempt at adding basic thermal sensor support on Armada 370 and Armada XP.

Given Armada 370/XP and the other Marvell SoC with thermal support, namely Kirkwood and Dove, have fairly similar thermal devices it made sense to integrate all of them into a single driver: mvebu-thermal.

Hi Ezequiel

I went this way to start with, merging Dove, Kirkwood and something which nearly worked for 370. But then i looked at the code, at how little is actually shared, and went back to separate drivers.

Kirkwood has no control registers, so needs a special case in the probe. The bit location of the temperate value moves around in the register. Each SoC needs its own initialization sequence.
Each SoC needs its own is_valid() function.
Each Soc needs its own formula to convert to milli centigrad.

I've never seen the datasheets for 370/XP, just a list of registers for
370. But i get the impression it has two temperate sensors, so should export two values?

Also, kirkwood will never be built into the same kernel as Dove/370/XP. So we end up with "bloat" in the driver, or at least a collection of #ifdefs.

In the end, i decided it was simpler and cleaner to just have separate drivers. This is something which we should think about and discuss.

Andrew

#37 lore raw

cover Marvell EBU thermal sensor consolidation

Hi Andrew,

Quoted 23 lines · Andrew Lunn
Quoted 6 lines · Ezequiel Garcia

This patchset is my first attempt at adding basic thermal sensor support on Armada 370 and Armada XP.

Given Armada 370/XP and the other Marvell SoC with thermal support, namely Kirkwood and Dove, have fairly similar thermal devices it made sense to integrate all of them into a single driver: mvebu-thermal.

I went this way to start with, merging Dove, Kirkwood and something which nearly worked for 370. But then i looked at the code, at how little is actually shared, and went back to separate drivers.

Kirkwood has no control registers, so needs a special case in the probe. The bit location of the temperate value moves around in the register. Each SoC needs its own initialization sequence.
Each SoC needs its own is_valid() function.
Each Soc needs its own formula to convert to milli centigrad.

I've never seen the datasheets for 370/XP, just a list of registers for
370. But i get the impression it has two temperate sensors, so should export two values?

Quoted 7 lines

Also, kirkwood will never be built into the same kernel as Dove/370/XP. So we end up with "bloat" in the driver, or at least a collection of #ifdefs.

In the end, i decided it was simpler and cleaner to just have separate drivers. This is something which we should think about and discuss.

Thanks for your comments.

I had the same concerns about a single driver against many; after trying this approach I was convinced by the diffstat:

13 files changed, 395 insertions(+), 393 deletions(-)

So we have almost no LoC increase and two new SoCs are supported.

The alternative would mean to have one driver for Armada 370 and yet another one for Armada XP, with some common boilerplate in each driver and only the differences you mention: a different initialization and a different conversion formula.
The initialization is solved my means of a function pointer, and the conversion is just a switch.

FWIW, the is_valid() is actually the same on Kirkwood and 370.

I debated myself a lot before unifying the drivers: in the end it seemed a proper solution: less maintainance, less configuration options, happier hackers :)

What do you think?

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#38 lore raw

cover Marvell EBU thermal sensor consolidation

In reply to Andrew Lunn
Quoted 18 lines · Andrew Lunn
Quoted 6 lines · Ezequiel Garcia

This patchset is my first attempt at adding basic thermal sensor support on Armada 370 and Armada XP.

Given Armada 370/XP and the other Marvell SoC with thermal support, namely Kirkwood and Dove, have fairly similar thermal devices it made sense to integrate all of them into a single driver: mvebu-thermal.

I went this way to start with, merging Dove, Kirkwood and something which nearly worked for 370. But then i looked at the code, at how little is actually shared, and went back to separate drivers.

Kirkwood has no control registers, so needs a special case in the probe. The bit location of the temperate value moves around in the register. Each SoC needs its own initialization sequence.
Each SoC needs its own is_valid() function.
Each Soc needs its own formula to convert to milli centigrad.

Quoted 4 lines

I've never seen the datasheets for 370/XP, just a list of registers for
370. But i get the impression it has two temperate sensors, so should export two values?

Why do you think it has two sensors?

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#39 lore raw

cover Marvell EBU thermal sensor consolidation

Quoted 1 line

Why do you think it has two sensors?

The register set i've seen talks of a junction temperate and a "thermal manager current temperature". The thermal manager temperature went up as i loaded the CPU and dropped down again as it was idle and cooled. I've no idea if these are two different sensors, or one is an averaged value of the other, etc. I would hope the datasheet gives a description.....

Andrew

#40 lore raw

cover Marvell EBU thermal sensor consolidation

In reply to Andrew Lunn
Quoted 2 lines · Andrew Lunn

In the end, i decided it was simpler and cleaner to just have separate drivers. This is something which we should think about and discuss.

When I looked through the merge'd driver I thought the shared code really had little to do with Marvell, it was mostly boilerplate that would be common to any memory mapped temperature sensor - so maybe the drivers should be kept apart and the boiler plate could be factored?

thermal_platform_mmio_init(pdev,&ops);

Where ops has the is_valid, init_sensor, get_sensor functions

Or something?

...

BTW, Ezequiel your driver is probably a bit smaller if you do

struct mvebu_ops {
	/* Initialize the sensor (optional) */
	void (*init_sensor)(struct mvebu_thermal_priv *);

	/* Test for a valid sensor value (optional) */
	bool (*is_valid)(struct mvebu_thermal_priv *);
};

static const struct mvebu_ops kirkwood_ops = {..};

static const struct of_device_id mvebu_thermal_id_table[] = {
	{
		.compatible = "marvell,kirkwood-thermal",
		.data       = &kirkwood_ops,
	},

And drop the switch statement and the MVEBU_THERMAL_SOC_* constants..

Cheers,
Jason

#41 lore raw

cover Marvell EBU thermal sensor consolidation

Quoted 10 lines · Jason Gunthorpe
Quoted 2 lines · Andrew Lunn

In the end, i decided it was simpler and cleaner to just have separate drivers. This is something which we should think about and discuss.

When I looked through the merge'd driver I thought the shared code really had little to do with Marvell, it was mostly boilerplate that would be common to any memory mapped temperature sensor - so maybe the drivers should be kept apart and the boiler plate could be factored?

Quoted 6 lines

thermal_platform_mmio_init(pdev,&ops);

Where ops has the is_valid, init_sensor, get_sensor functions

Or something?

Mmm... I'm not entirely sure. It might make sense if we could have thermal drivers for mor SoC than just Marvell's.

Is it judicious to have a thermal-mmio based on Marvell-only devices?

Quoted 14 lines

...

BTW, Ezequiel your driver is probably a bit smaller if you do

struct mvebu_ops {
	/* Initialize the sensor (optional) */
	void (*init_sensor)(struct mvebu_thermal_priv *);

	/* Test for a valid sensor value (optional) */
	bool (*is_valid)(struct mvebu_thermal_priv *);
};

static const struct mvebu_ops kirkwood_ops = {..};

Quoted 8 lines
static const struct of_device_id mvebu_thermal_id_table[] = {
	{
		.compatible = "marvell,kirkwood-thermal",
		.data       = &kirkwood_ops,
	},

And drop the switch statement and the MVEBU_THERMAL_SOC_* constants..

Yes, this sounds like a very good idea. I'll try it and see what happens.

Thanks,

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
#42 lore raw

cover Marvell EBU thermal sensor consolidation

In reply to Ezequiel Garcia
Quoted 17 lines · Ezequiel Garcia

This patchset is my first attempt at adding basic thermal sensor support on Armada 370 and Armada XP.

Given Armada 370/XP and the other Marvell SoC with thermal support, namely Kirkwood and Dove, have fairly similar thermal devices it made sense to integrate all of them into a single driver: mvebu-thermal.

The patches have been carefully splitted to make the changeset as less invasive as possible. These changes can be divided in five stages:

1. Rename 'kirkwood' driver to 'mvebu'
2. Some fixes inherited from kirkwood driver applied to new mvebu driver
3. Prepare mvebu driver to support multiple SoC
4. Add thermal support for each Marvell SoC on top of mvebu driver
5. Add device tree nodes for Armada 370 and Armada XP
6. Fix defconfigs for all the platforms involved

Quoted 8 lines

Testing have been done on the following boards:

Kirkwood:   Plat'home Openblocks A6
Armada 370: Globalscale Mirabox and Marvell Armada 370 RD
Armada XP:  Plat'home Openblocks AX3 and Marvell Armada XP DB-MV784MP-GP

Dove is *not* tested due to lack of hardware.

If anyone wants to test this patchset, I've prepared a public branch:

https://github.com/MISL-EBU-System-SW/mainline-public/tree/mvebu-thermal-v1

This branch is based on v3.9-rc1, with this patches:
arm: mvebu: Reduce reg-io-width with UARTs
ARM: Kirkwood: Add support thermal sensor for 88F6282 and 88F6283
Dove: Thermal: Add DT node and enable in defconfig

Thanks a lot,

Signature · 3 lines
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com