@@ -20,6 +20,7 @@
#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_VALID_OFFSET 9
@@ -27,36 +28,56 @@
#define MVEBU_THERMAL_TEMP_OFFSET 10
#define MVEBU_THERMAL_TEMP_MASK 0x1FF
+struct mvebu_thermal_ops;
+
/* Marvell EBU Thermal Sensor Dev Structure */
struct mvebu_thermal_priv {
void __iomem *sensor;
+ void __iomem *control;
+ struct mvebu_thermal_ops *ops;
+};
+
+struct mvebu_thermal_ops {
+ /* Converts the sensor register to ajunction temperature */
+ unsigned long (*sensor_temp)(struct mvebu_thermal_priv *);
+
+ /* 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 unsigned long orion_sensor_temp(struct mvebu_thermal_priv *priv)
+{
+ unsigned long reg = readl_relaxed(priv->sensor);
+
+ reg = (reg >> MVEBU_THERMAL_TEMP_OFFSET) &
+ MVEBU_THERMAL_TEMP_MASK;
+ return (3220000000UL - (10000000UL * reg)) / 13625;
+}
+
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->ops->is_valid && !priv->ops->is_valid(priv)) {
dev_err(&thermal->device,
"Temperature sensor reading not valid\n");
return -EIO;
}
- /*
- * Calculate temperature. According to Marvell internal
- * documentation the formula for this is:
- * Celsius = (322-reg)/1.3625
- */
- reg = (reg >> MVEBU_THERMAL_TEMP_OFFSET) &
- MVEBU_THERMAL_TEMP_MASK;
- *temp = ((3220000000UL - (10000000UL * reg)) / 13625);
-
+ *temp = priv->ops->sensor_temp(priv);
return 0;
}
@@ -64,18 +85,33 @@ static struct thermal_zone_device_ops ops = {
.get_temp = mvebu_get_temp,
};
+static const struct mvebu_thermal_ops kirkwood_ops = {
+ .sensor_temp = orion_sensor_temp,
+ .is_valid = mvebu_is_valid,
+};
+
static const struct of_device_id mvebu_thermal_id_table[] = {
- { .compatible = "marvell,kirkwood-thermal" },
- {}
+ {
+ .compatible = "marvell,kirkwood-thermal",
+ .data = &kirkwood_ops,
+ },
+ {
+ /* 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");
@@ -90,6 +126,18 @@ static int mvebu_thermal_probe(struct platform_device *pdev)
if (IS_ERR(priv->sensor))
return PTR_ERR(priv->sensor);
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+ if (res) {
+ priv->control = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(priv->control))
+ return PTR_ERR(priv->control);
+ }
+
+ priv->ops = (struct mvebu_thermal_ops *)match->data;
+
+ if (priv->ops->init_sensor)
+ priv->ops->init_sensor(priv);
+
thermal = thermal_zone_device_register("mvebu_thermal", 0, 0,
priv, &ops, NULL, 0, 0);
if (IS_ERR(thermal)) {
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 new struct to contain the operation for each SoC variant. Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com> --- drivers/thermal/mvebu_thermal.c | 80 +++++++++++++++++++++++++++++++-------- 1 files changed, 64 insertions(+), 16 deletions(-)