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 (*enable_sensor)(struct hisi_thermal_data *data);
int (*disable_sensor)(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 clk *clk;
struct hisi_thermal_sensor sensor;
struct resource *res;
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);
data->regs = devm_ioremap_resource(dev, res);
if (IS_ERR(data->regs)) {
struct device *dev = &pdev->dev;
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);
data->regs = devm_ioremap_resource(dev, res);
if (IS_ERR(data->regs)) {
struct hisi_thermal_data *data = __data;
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",
sensor->id, *temp, sensor->thres_temp);
struct hisi_thermal_sensor *sensor = &data->sensor;
int temp = 0;
- data->irq_handler(data);
+ data->ops->irq_handler(data);
hisi_thermal_get_temp(data, &temp);
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[] = {
{
.compatible = "hisilicon,tsensor",
- .data = hi6220_thermal_probe
+ .data = &hi6220_ops,
},
{
.compatible = "hisilicon,hi3660-tsensor",
- .data = hi3660_thermal_probe
+ .data = &hi3660_ops,
},
{ /* end */ }
};
static int hisi_thermal_probe(struct platform_device *pdev)
{
struct hisi_thermal_data *data;
- int (*platform_probe)(struct hisi_thermal_data *);
struct device *dev = &pdev->dev;
int ret;
data->pdev = pdev;
platform_set_drvdata(pdev, data);
- platform_probe = of_device_get_match_data(dev);
- if (!platform_probe) {
- dev_err(dev, "failed to get probe func\n");
- return -EINVAL;
- }
+ data->ops = of_device_get_match_data(dev);
- ret = platform_probe(data);
+ ret = data->ops->probe(data);
if (ret)
return ret;
return ret;
}
- ret = data->enable_sensor(data);
+ ret = data->ops->enable_sensor(data);
if (ret) {
dev_err(dev, "Failed to setup the sensor: %d\n", ret);
return ret;
hisi_thermal_toggle_sensor(sensor, false);
- data->disable_sensor(data);
+ data->ops->disable_sensor(data);
return 0;
}
{
struct hisi_thermal_data *data = dev_get_drvdata(dev);
- data->disable_sensor(data);
+ data->ops->disable_sensor(data);
return 0;
}
{
struct hisi_thermal_data *data = dev_get_drvdata(dev);
- return data->enable_sensor(data);
+ return data->ops->enable_sensor(data);
}
#endif