Commit c90aaecc authored by Daniel Lezcano's avatar Daniel Lezcano Committed by Eduardo Valentin

thermal/drivers/hisi: Change the platform data pointer to sensor ops

Group the temperature sensor specific ops into a single structure and
assign it to hisi thermal data structure.

Change the platform data pointer to reference the specific sensor ops
instead of the probe functions.

Moving out those allow to split the code to self-encapsulate the
sensor object.
Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Signed-off-by: default avatarEduardo Valentin <edubezval@gmail.com>
parent d1d2c290
...@@ -64,11 +64,18 @@ struct hisi_thermal_sensor { ...@@ -64,11 +64,18 @@ struct hisi_thermal_sensor {
uint32_t thres_temp; uint32_t thres_temp;
}; };
struct hisi_thermal_data { struct hisi_thermal_data;
struct hisi_thermal_ops {
int (*get_temp)(struct hisi_thermal_data *data); int (*get_temp)(struct hisi_thermal_data *data);
int (*enable_sensor)(struct hisi_thermal_data *data); int (*enable_sensor)(struct hisi_thermal_data *data);
int (*disable_sensor)(struct hisi_thermal_data *data); int (*disable_sensor)(struct hisi_thermal_data *data);
int (*irq_handler)(struct hisi_thermal_data *data); int (*irq_handler)(struct hisi_thermal_data *data);
int (*probe)(struct hisi_thermal_data *data);
};
struct hisi_thermal_data {
const struct hisi_thermal_ops *ops;
struct platform_device *pdev; struct platform_device *pdev;
struct clk *clk; struct clk *clk;
struct hisi_thermal_sensor sensor; struct hisi_thermal_sensor sensor;
...@@ -374,11 +381,6 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data) ...@@ -374,11 +381,6 @@ static int hi6220_thermal_probe(struct hisi_thermal_data *data)
struct resource *res; struct resource *res;
int ret; int ret;
data->get_temp = hi6220_thermal_get_temp;
data->enable_sensor = hi6220_thermal_enable_sensor;
data->disable_sensor = hi6220_thermal_disable_sensor;
data->irq_handler = hi6220_thermal_irq_handler;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
data->regs = devm_ioremap_resource(dev, res); data->regs = devm_ioremap_resource(dev, res);
if (IS_ERR(data->regs)) { if (IS_ERR(data->regs)) {
...@@ -409,11 +411,6 @@ static int hi3660_thermal_probe(struct hisi_thermal_data *data) ...@@ -409,11 +411,6 @@ static int hi3660_thermal_probe(struct hisi_thermal_data *data)
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct resource *res; struct resource *res;
data->get_temp = hi3660_thermal_get_temp;
data->enable_sensor = hi3660_thermal_enable_sensor;
data->disable_sensor = hi3660_thermal_disable_sensor;
data->irq_handler = hi3660_thermal_irq_handler;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
data->regs = devm_ioremap_resource(dev, res); data->regs = devm_ioremap_resource(dev, res);
if (IS_ERR(data->regs)) { if (IS_ERR(data->regs)) {
...@@ -435,7 +432,7 @@ static int hisi_thermal_get_temp(void *__data, int *temp) ...@@ -435,7 +432,7 @@ static int hisi_thermal_get_temp(void *__data, int *temp)
struct hisi_thermal_data *data = __data; struct hisi_thermal_data *data = __data;
struct hisi_thermal_sensor *sensor = &data->sensor; struct hisi_thermal_sensor *sensor = &data->sensor;
*temp = data->get_temp(data); *temp = data->ops->get_temp(data);
dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n",
sensor->id, *temp, sensor->thres_temp); sensor->id, *temp, sensor->thres_temp);
...@@ -453,7 +450,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) ...@@ -453,7 +450,7 @@ static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev)
struct hisi_thermal_sensor *sensor = &data->sensor; struct hisi_thermal_sensor *sensor = &data->sensor;
int temp = 0; int temp = 0;
data->irq_handler(data); data->ops->irq_handler(data);
hisi_thermal_get_temp(data, &temp); hisi_thermal_get_temp(data, &temp);
...@@ -502,14 +499,30 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev, ...@@ -502,14 +499,30 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev,
return 0; return 0;
} }
static const struct hisi_thermal_ops hi6220_ops = {
.get_temp = hi6220_thermal_get_temp,
.enable_sensor = hi6220_thermal_enable_sensor,
.disable_sensor = hi6220_thermal_disable_sensor,
.irq_handler = hi6220_thermal_irq_handler,
.probe = hi6220_thermal_probe,
};
static const struct hisi_thermal_ops hi3660_ops = {
.get_temp = hi3660_thermal_get_temp,
.enable_sensor = hi3660_thermal_enable_sensor,
.disable_sensor = hi3660_thermal_disable_sensor,
.irq_handler = hi3660_thermal_irq_handler,
.probe = hi3660_thermal_probe,
};
static const struct of_device_id of_hisi_thermal_match[] = { static const struct of_device_id of_hisi_thermal_match[] = {
{ {
.compatible = "hisilicon,tsensor", .compatible = "hisilicon,tsensor",
.data = hi6220_thermal_probe .data = &hi6220_ops,
}, },
{ {
.compatible = "hisilicon,hi3660-tsensor", .compatible = "hisilicon,hi3660-tsensor",
.data = hi3660_thermal_probe .data = &hi3660_ops,
}, },
{ /* end */ } { /* end */ }
}; };
...@@ -527,7 +540,6 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, ...@@ -527,7 +540,6 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor,
static int hisi_thermal_probe(struct platform_device *pdev) static int hisi_thermal_probe(struct platform_device *pdev)
{ {
struct hisi_thermal_data *data; struct hisi_thermal_data *data;
int (*platform_probe)(struct hisi_thermal_data *);
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
int ret; int ret;
...@@ -538,13 +550,9 @@ static int hisi_thermal_probe(struct platform_device *pdev) ...@@ -538,13 +550,9 @@ static int hisi_thermal_probe(struct platform_device *pdev)
data->pdev = pdev; data->pdev = pdev;
platform_set_drvdata(pdev, data); platform_set_drvdata(pdev, data);
platform_probe = of_device_get_match_data(dev); data->ops = of_device_get_match_data(dev);
if (!platform_probe) {
dev_err(dev, "failed to get probe func\n");
return -EINVAL;
}
ret = platform_probe(data); ret = data->ops->probe(data);
if (ret) if (ret)
return ret; return ret;
...@@ -555,7 +563,7 @@ static int hisi_thermal_probe(struct platform_device *pdev) ...@@ -555,7 +563,7 @@ static int hisi_thermal_probe(struct platform_device *pdev)
return ret; return ret;
} }
ret = data->enable_sensor(data); ret = data->ops->enable_sensor(data);
if (ret) { if (ret) {
dev_err(dev, "Failed to setup the sensor: %d\n", ret); dev_err(dev, "Failed to setup the sensor: %d\n", ret);
return ret; return ret;
...@@ -583,7 +591,7 @@ static int hisi_thermal_remove(struct platform_device *pdev) ...@@ -583,7 +591,7 @@ static int hisi_thermal_remove(struct platform_device *pdev)
hisi_thermal_toggle_sensor(sensor, false); hisi_thermal_toggle_sensor(sensor, false);
data->disable_sensor(data); data->ops->disable_sensor(data);
return 0; return 0;
} }
...@@ -593,7 +601,7 @@ static int hisi_thermal_suspend(struct device *dev) ...@@ -593,7 +601,7 @@ static int hisi_thermal_suspend(struct device *dev)
{ {
struct hisi_thermal_data *data = dev_get_drvdata(dev); struct hisi_thermal_data *data = dev_get_drvdata(dev);
data->disable_sensor(data); data->ops->disable_sensor(data);
return 0; return 0;
} }
...@@ -602,7 +610,7 @@ static int hisi_thermal_resume(struct device *dev) ...@@ -602,7 +610,7 @@ static int hisi_thermal_resume(struct device *dev)
{ {
struct hisi_thermal_data *data = dev_get_drvdata(dev); struct hisi_thermal_data *data = dev_get_drvdata(dev);
return data->enable_sensor(data); return data->ops->enable_sensor(data);
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment