summaryrefslogtreecommitdiff
path: root/drivers/thermal/hisi_thermal.c
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2018-09-25 12:03:00 +0300
committerEduardo Valentin <edubezval@gmail.com>2018-10-23 03:42:19 +0300
commit9c9ae8da710639790f1d45b1a55d28ee70734c11 (patch)
tree5c303bf5e8d3783c49f14c46d7b96398e6272bda /drivers/thermal/hisi_thermal.c
parentc90aaeccc7c6a8967f3efd43048eeae51072251c (diff)
downloadlinux-9c9ae8da710639790f1d45b1a55d28ee70734c11.tar.xz
thermal/drivers/hisi: Change the driver to be sensor oriented
In order to support multiple sensors, we have to change the code to deal with sensors and not the hisi thermal structure. Add a back pointer to the hisi thermal structure (containerof is not a good option because later we convert the sensor field to a pointer). Change the functions parameters to take a sensor instead of this hisi thermal 'data' structure. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Diffstat (limited to 'drivers/thermal/hisi_thermal.c')
-rw-r--r--drivers/thermal/hisi_thermal.c72
1 files changed, 42 insertions, 30 deletions
diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 9794cfe56a12..1fdda55bd93b 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -58,27 +58,28 @@
#define HI6220_DEFAULT_SENSOR 2
#define HI3660_DEFAULT_SENSOR 1
+struct hisi_thermal_data;
+
struct hisi_thermal_sensor {
+ struct hisi_thermal_data *data;
struct thermal_zone_device *tzd;
uint32_t id;
uint32_t thres_temp;
};
-struct hisi_thermal_data;
-
struct hisi_thermal_ops {
- int (*get_temp)(struct hisi_thermal_data *data);
- int (*enable_sensor)(struct hisi_thermal_data *data);
- int (*disable_sensor)(struct hisi_thermal_data *data);
- int (*irq_handler)(struct hisi_thermal_data *data);
+ int (*get_temp)(struct hisi_thermal_sensor *sensor);
+ int (*enable_sensor)(struct hisi_thermal_sensor *sensor);
+ int (*disable_sensor)(struct hisi_thermal_sensor *sensor);
+ int (*irq_handler)(struct hisi_thermal_sensor *sensor);
int (*probe)(struct hisi_thermal_data *data);
};
struct hisi_thermal_data {
const struct hisi_thermal_ops *ops;
+ struct hisi_thermal_sensor sensor;
struct platform_device *pdev;
struct clk *clk;
- struct hisi_thermal_sensor sensor;
void __iomem *regs;
int irq;
};
@@ -273,30 +274,40 @@ static inline void hi6220_thermal_hdak_set(void __iomem *addr, int value)
(value << 4), addr + HI6220_TEMP0_CFG);
}
-static int hi6220_thermal_irq_handler(struct hisi_thermal_data *data)
+static int hi6220_thermal_irq_handler(struct hisi_thermal_sensor *sensor)
{
+ struct hisi_thermal_data *data = sensor->data;
+
hi6220_thermal_alarm_clear(data->regs, 1);
return 0;
}
-static int hi3660_thermal_irq_handler(struct hisi_thermal_data *data)
+static int hi3660_thermal_irq_handler(struct hisi_thermal_sensor *sensor)
{
- hi3660_thermal_alarm_clear(data->regs, data->sensor.id, 1);
+ struct hisi_thermal_data *data = sensor->data;
+
+ hi3660_thermal_alarm_clear(data->regs, sensor->id, 1);
return 0;
}
-static int hi6220_thermal_get_temp(struct hisi_thermal_data *data)
+static int hi6220_thermal_get_temp(struct hisi_thermal_sensor *sensor)
{
+ struct hisi_thermal_data *data = sensor->data;
+
return hi6220_thermal_get_temperature(data->regs);
}
-static int hi3660_thermal_get_temp(struct hisi_thermal_data *data)
+static int hi3660_thermal_get_temp(struct hisi_thermal_sensor *sensor)
{
- return hi3660_thermal_get_temperature(data->regs, data->sensor.id);
+ struct hisi_thermal_data *data = sensor->data;
+
+ return hi3660_thermal_get_temperature(data->regs, sensor->id);
}
-static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data)
+static int hi6220_thermal_disable_sensor(struct hisi_thermal_sensor *sensor)
{
+ struct hisi_thermal_data *data = sensor->data;
+
/* disable sensor module */
hi6220_thermal_enable(data->regs, 0);
hi6220_thermal_alarm_enable(data->regs, 0);
@@ -307,16 +318,18 @@ static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data)
return 0;
}
-static int hi3660_thermal_disable_sensor(struct hisi_thermal_data *data)
+static int hi3660_thermal_disable_sensor(struct hisi_thermal_sensor *sensor)
{
+ struct hisi_thermal_data *data = sensor->data;
+
/* disable sensor module */
- hi3660_thermal_alarm_enable(data->regs, data->sensor.id, 0);
+ hi3660_thermal_alarm_enable(data->regs, sensor->id, 0);
return 0;
}
-static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data)
+static int hi6220_thermal_enable_sensor(struct hisi_thermal_sensor *sensor)
{
- struct hisi_thermal_sensor *sensor = &data->sensor;
+ struct hisi_thermal_data *data = sensor->data;
int ret;
/* enable clock for tsensor */
@@ -352,10 +365,10 @@ static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data)
return 0;
}
-static int hi3660_thermal_enable_sensor(struct hisi_thermal_data *data)
+static int hi3660_thermal_enable_sensor(struct hisi_thermal_sensor *sensor)
{
unsigned int value;
- struct hisi_thermal_sensor *sensor = &data->sensor;
+ struct hisi_thermal_data *data = sensor->data;
/* disable interrupt */
hi3660_thermal_alarm_enable(data->regs, sensor->id, 0);
@@ -432,7 +445,7 @@ static int hisi_thermal_get_temp(void *__data, int *temp)
struct hisi_thermal_data *data = __data;
struct hisi_thermal_sensor *sensor = &data->sensor;
- *temp = data->ops->get_temp(data);
+ *temp = data->ops->get_temp(sensor);
dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n",
sensor->id, *temp, sensor->thres_temp);
@@ -450,7 +463,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev)
struct hisi_thermal_sensor *sensor = &data->sensor;
int temp = 0;
- data->ops->irq_handler(data);
+ data->ops->irq_handler(sensor);
hisi_thermal_get_temp(data, &temp);
@@ -470,10 +483,10 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev)
}
static int hisi_thermal_register_sensor(struct platform_device *pdev,
- struct hisi_thermal_data *data,
struct hisi_thermal_sensor *sensor)
{
int ret, i;
+ struct hisi_thermal_data *data = sensor->data;
const struct thermal_trip *trip;
sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev,
@@ -549,21 +562,20 @@ static int hisi_thermal_probe(struct platform_device *pdev)
data->pdev = pdev;
platform_set_drvdata(pdev, data);
-
+ data->sensor.data = data;
data->ops = of_device_get_match_data(dev);
ret = data->ops->probe(data);
if (ret)
return ret;
- ret = hisi_thermal_register_sensor(pdev, data,
- &data->sensor);
+ ret = hisi_thermal_register_sensor(pdev, &data->sensor);
if (ret) {
dev_err(dev, "failed to register thermal sensor: %d\n", ret);
return ret;
}
- ret = data->ops->enable_sensor(data);
+ ret = data->ops->enable_sensor(&data->sensor);
if (ret) {
dev_err(dev, "Failed to setup the sensor: %d\n", ret);
return ret;
@@ -591,7 +603,7 @@ static int hisi_thermal_remove(struct platform_device *pdev)
hisi_thermal_toggle_sensor(sensor, false);
- data->ops->disable_sensor(data);
+ data->ops->disable_sensor(&data->sensor);
return 0;
}
@@ -601,7 +613,7 @@ static int hisi_thermal_suspend(struct device *dev)
{
struct hisi_thermal_data *data = dev_get_drvdata(dev);
- data->ops->disable_sensor(data);
+ data->ops->disable_sensor(&data->sensor);
return 0;
}
@@ -610,7 +622,7 @@ static int hisi_thermal_resume(struct device *dev)
{
struct hisi_thermal_data *data = dev_get_drvdata(dev);
- return data->ops->enable_sensor(data);
+ return data->ops->enable_sensor(&data->sensor);
}
#endif