#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;
};
(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);
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 */
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);
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);
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);
}
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,
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;
hisi_thermal_toggle_sensor(sensor, false);
- data->ops->disable_sensor(data);
+ data->ops->disable_sensor(&data->sensor);
return 0;
}
{
struct hisi_thermal_data *data = dev_get_drvdata(dev);
- data->ops->disable_sensor(data);
+ data->ops->disable_sensor(&data->sensor);
return 0;
}
{
struct hisi_thermal_data *data = dev_get_drvdata(dev);
- return data->ops->enable_sensor(data);
+ return data->ops->enable_sensor(&data->sensor);
}
#endif