Commit 7f4957be authored by Andrzej Pietrasiewicz's avatar Andrzej Pietrasiewicz Committed by Daniel Lezcano

thermal: Use mode helpers in drivers

Use thermal_zone_device_{en|dis}able() and thermal_zone_device_is_enabled().

Consequently, all set_mode() implementations in drivers:

- can stop modifying tzd's "mode" member,
- shall stop taking tzd's lock, as it is taken in the helpers
- shall stop calling thermal_zone_device_update() as it is called in the
helpers
- can assume they are called when the mode truly changes, so checks to
verify that can be dropped

Not providing set_mode() by a driver no longer prevents the core from
being able to set tzd's mode, so the relevant check in mode_store() is
removed.

Other comments:

- acpi/thermal.c: tz->thermal_zone->mode will be updated only after we
return from set_mode(), so use function parameter in thermal_set_mode()
instead, no need to call acpi_thermal_check() in set_mode()
- thermal/imx_thermal.c: regmap writes and mode assignment are done in
thermal_zone_device_{en|dis}able() and set_mode() callback
- thermal/intel/intel_quark_dts_thermal.c: soc_dts_{en|dis}able() are a
part of set_mode() callback, so they don't need to modify tzd->mode, and
don't need to fall back to the opposite mode if unsuccessful, as the return
value will be propagated to thermal_zone_device_{en|dis}able() and
ultimately tzd's member will not be changed in thermal_zone_device_set_mode().
- thermal/of-thermal.c: no need to set zone->mode to DISABLED in
of_parse_thermal_zones() as a tzd is kzalloc'ed so mode is DISABLED anyway
Signed-off-by: default avatarAndrzej Pietrasiewicz <andrzej.p@collabora.com>
[for acerhdf]
Acked-by: default avatarPeter Kaestle <peter@piie.net>
Reviewed-by: default avatarAmit Kucheria <amit.kucheria@linaro.org>
Reviewed-by: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20200629122925.21729-8-andrzej.p@collabora.com
parent ac5d9ecc
...@@ -499,7 +499,7 @@ static void acpi_thermal_check(void *data) ...@@ -499,7 +499,7 @@ static void acpi_thermal_check(void *data)
{ {
struct acpi_thermal *tz = data; struct acpi_thermal *tz = data;
if (tz->thermal_zone->mode != THERMAL_DEVICE_ENABLED) if (!thermal_zone_device_is_enabled(tz->thermal_zone))
return; return;
thermal_zone_device_update(tz->thermal_zone, thermal_zone_device_update(tz->thermal_zone,
...@@ -542,14 +542,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal, ...@@ -542,14 +542,11 @@ static int thermal_set_mode(struct thermal_zone_device *thermal,
if (mode == THERMAL_DEVICE_DISABLED) if (mode == THERMAL_DEVICE_DISABLED)
pr_warn("thermal zone will be disabled\n"); pr_warn("thermal zone will be disabled\n");
if (mode != tz->thermal_zone->mode) { ACPI_DEBUG_PRINT((ACPI_DB_INFO,
tz->thermal_zone->mode = mode; "%s kernel ACPI thermal control\n",
ACPI_DEBUG_PRINT((ACPI_DB_INFO, mode == THERMAL_DEVICE_ENABLED ?
"%s kernel ACPI thermal control\n", "Enable" : "Disable"));
tz->thermal_zone->mode == THERMAL_DEVICE_ENABLED ?
"Enable" : "Disable"));
acpi_thermal_check(tz);
}
return 0; return 0;
} }
...@@ -897,13 +894,17 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) ...@@ -897,13 +894,17 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
goto remove_dev_link; goto remove_dev_link;
} }
tz->thermal_zone->mode = THERMAL_DEVICE_ENABLED; result = thermal_zone_device_enable(tz->thermal_zone);
if (result)
goto acpi_bus_detach;
dev_info(&tz->device->dev, "registered as thermal_zone%d\n", dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
tz->thermal_zone->id); tz->thermal_zone->id);
return 0; return 0;
acpi_bus_detach:
acpi_bus_detach_private_data(tz->device->handle);
remove_dev_link: remove_dev_link:
sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
remove_tz_link: remove_tz_link:
......
...@@ -280,18 +280,11 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev, ...@@ -280,18 +280,11 @@ static int mlxsw_thermal_set_mode(struct thermal_zone_device *tzdev,
{ {
struct mlxsw_thermal *thermal = tzdev->devdata; struct mlxsw_thermal *thermal = tzdev->devdata;
mutex_lock(&tzdev->lock);
if (mode == THERMAL_DEVICE_ENABLED) if (mode == THERMAL_DEVICE_ENABLED)
tzdev->polling_delay = thermal->polling_delay; tzdev->polling_delay = thermal->polling_delay;
else else
tzdev->polling_delay = 0; tzdev->polling_delay = 0;
tzdev->mode = mode;
mutex_unlock(&tzdev->lock);
thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED);
return 0; return 0;
} }
...@@ -458,19 +451,11 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev, ...@@ -458,19 +451,11 @@ static int mlxsw_thermal_module_mode_set(struct thermal_zone_device *tzdev,
struct mlxsw_thermal_module *tz = tzdev->devdata; struct mlxsw_thermal_module *tz = tzdev->devdata;
struct mlxsw_thermal *thermal = tz->parent; struct mlxsw_thermal *thermal = tz->parent;
mutex_lock(&tzdev->lock);
if (mode == THERMAL_DEVICE_ENABLED) if (mode == THERMAL_DEVICE_ENABLED)
tzdev->polling_delay = thermal->polling_delay; tzdev->polling_delay = thermal->polling_delay;
else else
tzdev->polling_delay = 0; tzdev->polling_delay = 0;
tzdev->mode = mode;
mutex_unlock(&tzdev->lock);
thermal_zone_device_update(tzdev, THERMAL_EVENT_UNSPECIFIED);
return 0; return 0;
} }
...@@ -756,8 +741,11 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz) ...@@ -756,8 +741,11 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz)
return err; return err;
} }
module_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; err = thermal_zone_device_enable(module_tz->tzdev);
return 0; if (err)
thermal_zone_device_unregister(module_tz->tzdev);
return err;
} }
static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev) static void mlxsw_thermal_module_tz_fini(struct thermal_zone_device *tzdev)
...@@ -860,6 +848,7 @@ static int ...@@ -860,6 +848,7 @@ static int
mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
{ {
char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME]; char tz_name[MLXSW_THERMAL_ZONE_MAX_NAME];
int ret;
snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d", snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d",
gearbox_tz->module + 1); gearbox_tz->module + 1);
...@@ -872,8 +861,11 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz) ...@@ -872,8 +861,11 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
if (IS_ERR(gearbox_tz->tzdev)) if (IS_ERR(gearbox_tz->tzdev))
return PTR_ERR(gearbox_tz->tzdev); return PTR_ERR(gearbox_tz->tzdev);
gearbox_tz->tzdev->mode = THERMAL_DEVICE_ENABLED; ret = thermal_zone_device_enable(gearbox_tz->tzdev);
return 0; if (ret)
thermal_zone_device_unregister(gearbox_tz->tzdev);
return ret;
} }
static void static void
...@@ -1041,10 +1033,15 @@ int mlxsw_thermal_init(struct mlxsw_core *core, ...@@ -1041,10 +1033,15 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
if (err) if (err)
goto err_unreg_modules_tzdev; goto err_unreg_modules_tzdev;
thermal->tzdev->mode = THERMAL_DEVICE_ENABLED; err = thermal_zone_device_enable(thermal->tzdev);
if (err)
goto err_unreg_gearboxes;
*p_thermal = thermal; *p_thermal = thermal;
return 0; return 0;
err_unreg_gearboxes:
mlxsw_thermal_gearboxes_fini(thermal);
err_unreg_modules_tzdev: err_unreg_modules_tzdev:
mlxsw_thermal_modules_fini(thermal); mlxsw_thermal_modules_fini(thermal);
err_unreg_tzdev: err_unreg_tzdev:
......
...@@ -397,19 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void) ...@@ -397,19 +397,16 @@ static inline void acerhdf_revert_to_bios_mode(void)
{ {
acerhdf_change_fanstate(ACERHDF_FAN_AUTO); acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
kernelmode = 0; kernelmode = 0;
if (thz_dev) { if (thz_dev)
thz_dev->mode = THERMAL_DEVICE_DISABLED;
thz_dev->polling_delay = 0; thz_dev->polling_delay = 0;
}
pr_notice("kernel mode fan control OFF\n"); pr_notice("kernel mode fan control OFF\n");
} }
static inline void acerhdf_enable_kernelmode(void) static inline void acerhdf_enable_kernelmode(void)
{ {
kernelmode = 1; kernelmode = 1;
thz_dev->mode = THERMAL_DEVICE_ENABLED;
thz_dev->polling_delay = interval*1000; thz_dev->polling_delay = interval*1000;
thermal_zone_device_update(thz_dev, THERMAL_EVENT_UNSPECIFIED);
pr_notice("kernel mode fan control ON\n"); pr_notice("kernel mode fan control ON\n");
} }
...@@ -723,6 +720,8 @@ static void acerhdf_unregister_platform(void) ...@@ -723,6 +720,8 @@ static void acerhdf_unregister_platform(void)
static int __init acerhdf_register_thermal(void) static int __init acerhdf_register_thermal(void)
{ {
int ret;
cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL, cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL,
&acerhdf_cooling_ops); &acerhdf_cooling_ops);
...@@ -736,8 +735,12 @@ static int __init acerhdf_register_thermal(void) ...@@ -736,8 +735,12 @@ static int __init acerhdf_register_thermal(void)
if (IS_ERR(thz_dev)) if (IS_ERR(thz_dev))
return -EINVAL; return -EINVAL;
thz_dev->mode = kernelmode ? if (kernelmode)
THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED; ret = thermal_zone_device_enable(thz_dev);
else
ret = thermal_zone_device_disable(thz_dev);
if (ret)
return ret;
if (strcmp(thz_dev->governor->name, if (strcmp(thz_dev->governor->name,
acerhdf_zone_params.governor_name)) { acerhdf_zone_params.governor_name)) {
......
...@@ -237,7 +237,11 @@ static int da9062_thermal_probe(struct platform_device *pdev) ...@@ -237,7 +237,11 @@ static int da9062_thermal_probe(struct platform_device *pdev)
ret = PTR_ERR(thermal->zone); ret = PTR_ERR(thermal->zone);
goto err; goto err;
} }
thermal->zone->mode = THERMAL_DEVICE_ENABLED; ret = thermal_zone_device_enable(thermal->zone);
if (ret) {
dev_err(&pdev->dev, "Cannot enable thermal zone device\n");
goto err_zone;
}
dev_dbg(&pdev->dev, dev_dbg(&pdev->dev,
"TJUNC temperature polling period set at %d ms\n", "TJUNC temperature polling period set at %d ms\n",
......
...@@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor, ...@@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor,
{ {
struct thermal_zone_device *tzd = sensor->tzd; struct thermal_zone_device *tzd = sensor->tzd;
tzd->ops->set_mode(tzd, if (on)
on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); thermal_zone_device_enable(tzd);
else
thermal_zone_device_disable(tzd);
} }
static int hisi_thermal_probe(struct platform_device *pdev) static int hisi_thermal_probe(struct platform_device *pdev)
......
...@@ -255,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) ...@@ -255,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
bool wait; bool wait;
u32 val; u32 val;
if (tz->mode == THERMAL_DEVICE_ENABLED) { if (thermal_zone_device_is_enabled(tz)) {
/* Check if a measurement is currently in progress */ /* Check if a measurement is currently in progress */
regmap_read(map, soc_data->temp_data, &val); regmap_read(map, soc_data->temp_data, &val);
wait = !(val & soc_data->temp_valid_mask); wait = !(val & soc_data->temp_valid_mask);
...@@ -282,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp) ...@@ -282,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
regmap_read(map, soc_data->temp_data, &val); regmap_read(map, soc_data->temp_data, &val);
if (tz->mode != THERMAL_DEVICE_ENABLED) { if (!thermal_zone_device_is_enabled(tz)) {
regmap_write(map, soc_data->sensor_ctrl + REG_CLR, regmap_write(map, soc_data->sensor_ctrl + REG_CLR,
soc_data->measure_temp_mask); soc_data->measure_temp_mask);
regmap_write(map, soc_data->sensor_ctrl + REG_SET, regmap_write(map, soc_data->sensor_ctrl + REG_SET,
...@@ -365,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz, ...@@ -365,9 +365,6 @@ static int imx_set_mode(struct thermal_zone_device *tz,
} }
} }
tz->mode = mode;
thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
return 0; return 0;
} }
...@@ -819,7 +816,9 @@ static int imx_thermal_probe(struct platform_device *pdev) ...@@ -819,7 +816,9 @@ static int imx_thermal_probe(struct platform_device *pdev)
data->socdata->measure_temp_mask); data->socdata->measure_temp_mask);
data->irq_enabled = true; data->irq_enabled = true;
data->tz->mode = THERMAL_DEVICE_ENABLED; ret = thermal_zone_device_enable(data->tz);
if (ret)
goto thermal_zone_unregister;
ret = devm_request_threaded_irq(&pdev->dev, data->irq, ret = devm_request_threaded_irq(&pdev->dev, data->irq,
imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread,
...@@ -861,19 +860,18 @@ static int imx_thermal_remove(struct platform_device *pdev) ...@@ -861,19 +860,18 @@ static int imx_thermal_remove(struct platform_device *pdev)
static int __maybe_unused imx_thermal_suspend(struct device *dev) static int __maybe_unused imx_thermal_suspend(struct device *dev)
{ {
struct imx_thermal_data *data = dev_get_drvdata(dev); struct imx_thermal_data *data = dev_get_drvdata(dev);
struct regmap *map = data->tempmon; int ret;
/* /*
* Need to disable thermal sensor, otherwise, when thermal core * Need to disable thermal sensor, otherwise, when thermal core
* try to get temperature before thermal sensor resume, a wrong * try to get temperature before thermal sensor resume, a wrong
* temperature will be read as the thermal sensor is powered * temperature will be read as the thermal sensor is powered
* down. * down. This is done in set_mode() operation called from
* thermal_zone_device_disable()
*/ */
regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, ret = thermal_zone_device_disable(data->tz);
data->socdata->measure_temp_mask); if (ret)
regmap_write(map, data->socdata->sensor_ctrl + REG_SET, return ret;
data->socdata->power_down_mask);
data->tz->mode = THERMAL_DEVICE_DISABLED;
clk_disable_unprepare(data->thermal_clk); clk_disable_unprepare(data->thermal_clk);
return 0; return 0;
...@@ -882,18 +880,15 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev) ...@@ -882,18 +880,15 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev)
static int __maybe_unused imx_thermal_resume(struct device *dev) static int __maybe_unused imx_thermal_resume(struct device *dev)
{ {
struct imx_thermal_data *data = dev_get_drvdata(dev); struct imx_thermal_data *data = dev_get_drvdata(dev);
struct regmap *map = data->tempmon;
int ret; int ret;
ret = clk_prepare_enable(data->thermal_clk); ret = clk_prepare_enable(data->thermal_clk);
if (ret) if (ret)
return ret; return ret;
/* Enabled thermal sensor after resume */ /* Enabled thermal sensor after resume */
regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, ret = thermal_zone_device_enable(data->tz);
data->socdata->power_down_mask); if (ret)
regmap_write(map, data->socdata->sensor_ctrl + REG_SET, return ret;
data->socdata->measure_temp_mask);
data->tz->mode = THERMAL_DEVICE_ENABLED;
return 0; return 0;
} }
......
...@@ -390,12 +390,11 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, ...@@ -390,12 +390,11 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal,
mode != THERMAL_DEVICE_DISABLED) mode != THERMAL_DEVICE_DISABLED)
return -EINVAL; return -EINVAL;
if (mode != thermal->mode) { if (mode != thermal->mode)
thermal->mode = mode;
result = int3400_thermal_run_osc(priv->adev->handle, result = int3400_thermal_run_osc(priv->adev->handle,
priv->current_uuid_index, priv->current_uuid_index,
mode == THERMAL_DEVICE_ENABLED); mode == THERMAL_DEVICE_ENABLED);
}
evaluate_odvp(priv); evaluate_odvp(priv);
......
...@@ -126,10 +126,8 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) ...@@ -126,10 +126,8 @@ static int soc_dts_enable(struct thermal_zone_device *tzd)
if (ret) if (ret)
return ret; return ret;
if (out & QRK_DTS_ENABLE_BIT) { if (out & QRK_DTS_ENABLE_BIT)
tzd->mode = THERMAL_DEVICE_ENABLED;
return 0; return 0;
}
if (!aux_entry->locked) { if (!aux_entry->locked) {
out |= QRK_DTS_ENABLE_BIT; out |= QRK_DTS_ENABLE_BIT;
...@@ -137,10 +135,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd) ...@@ -137,10 +135,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd)
QRK_DTS_REG_OFFSET_ENABLE, out); QRK_DTS_REG_OFFSET_ENABLE, out);
if (ret) if (ret)
return ret; return ret;
tzd->mode = THERMAL_DEVICE_ENABLED;
} else { } else {
tzd->mode = THERMAL_DEVICE_DISABLED;
pr_info("DTS is locked. Cannot enable DTS\n"); pr_info("DTS is locked. Cannot enable DTS\n");
ret = -EPERM; ret = -EPERM;
} }
...@@ -159,10 +154,8 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) ...@@ -159,10 +154,8 @@ static int soc_dts_disable(struct thermal_zone_device *tzd)
if (ret) if (ret)
return ret; return ret;
if (!(out & QRK_DTS_ENABLE_BIT)) { if (!(out & QRK_DTS_ENABLE_BIT))
tzd->mode = THERMAL_DEVICE_DISABLED;
return 0; return 0;
}
if (!aux_entry->locked) { if (!aux_entry->locked) {
out &= ~QRK_DTS_ENABLE_BIT; out &= ~QRK_DTS_ENABLE_BIT;
...@@ -171,10 +164,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd) ...@@ -171,10 +164,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd)
if (ret) if (ret)
return ret; return ret;
tzd->mode = THERMAL_DEVICE_DISABLED;
} else { } else {
tzd->mode = THERMAL_DEVICE_ENABLED;
pr_info("DTS is locked. Cannot disable DTS\n"); pr_info("DTS is locked. Cannot disable DTS\n");
ret = -EPERM; ret = -EPERM;
} }
...@@ -404,9 +394,7 @@ static struct soc_sensor_entry *alloc_soc_dts(void) ...@@ -404,9 +394,7 @@ static struct soc_sensor_entry *alloc_soc_dts(void)
goto err_ret; goto err_ret;
} }
mutex_lock(&dts_update_mutex); err = thermal_zone_device_enable(aux_entry->tzone);
err = soc_dts_enable(aux_entry->tzone);
mutex_unlock(&dts_update_mutex);
if (err) if (err)
goto err_aux_status; goto err_aux_status;
......
...@@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on) ...@@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on)
{ {
struct thermal_zone_device *tzd = sensor->tzd; struct thermal_zone_device *tzd = sensor->tzd;
tzd->ops->set_mode(tzd, if (on)
on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); thermal_zone_device_enable(tzd);
else
thermal_zone_device_disable(tzd);
} }
static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev)
......
...@@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on) ...@@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on)
{ {
struct thermal_zone_device *tzd = sen->tzd; struct thermal_zone_device *tzd = sen->tzd;
tzd->ops->set_mode(tzd, if (on)
on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); thermal_zone_device_enable(tzd);
else
thermal_zone_device_disable(tzd);
} }
static int sprd_thm_probe(struct platform_device *pdev) static int sprd_thm_probe(struct platform_device *pdev)
......
...@@ -1521,7 +1521,7 @@ static int thermal_pm_notify(struct notifier_block *nb, ...@@ -1521,7 +1521,7 @@ static int thermal_pm_notify(struct notifier_block *nb,
case PM_POST_SUSPEND: case PM_POST_SUSPEND:
atomic_set(&in_suspend, 0); atomic_set(&in_suspend, 0);
list_for_each_entry(tz, &thermal_tz_list, node) { list_for_each_entry(tz, &thermal_tz_list, node) {
if (tz->mode == THERMAL_DEVICE_DISABLED) if (!thermal_zone_device_is_enabled(tz))
continue; continue;
thermal_zone_device_init(tz); thermal_zone_device_init(tz);
......
...@@ -272,8 +272,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, ...@@ -272,8 +272,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,
{ {
struct __thermal_zone *data = tz->devdata; struct __thermal_zone *data = tz->devdata;
mutex_lock(&tz->lock);
if (mode == THERMAL_DEVICE_ENABLED) { if (mode == THERMAL_DEVICE_ENABLED) {
tz->polling_delay = data->polling_delay; tz->polling_delay = data->polling_delay;
tz->passive_delay = data->passive_delay; tz->passive_delay = data->passive_delay;
...@@ -282,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz, ...@@ -282,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,
tz->passive_delay = 0; tz->passive_delay = 0;
} }
mutex_unlock(&tz->lock);
tz->mode = mode;
thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
return 0; return 0;
} }
...@@ -541,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data, ...@@ -541,7 +534,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data,
tzd = thermal_zone_of_add_sensor(child, sensor_np, tzd = thermal_zone_of_add_sensor(child, sensor_np,
data, ops); data, ops);
if (!IS_ERR(tzd)) if (!IS_ERR(tzd))
tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); thermal_zone_device_enable(tzd);
of_node_put(child); of_node_put(child);
goto exit; goto exit;
...@@ -1120,7 +1113,6 @@ int __init of_parse_thermal_zones(void) ...@@ -1120,7 +1113,6 @@ int __init of_parse_thermal_zones(void)
of_thermal_free_zone(tz); of_thermal_free_zone(tz);
/* attempting to build remaining zones still */ /* attempting to build remaining zones still */
} }
zone->mode = THERMAL_DEVICE_DISABLED;
} }
of_node_put(np); of_node_put(np);
......
...@@ -49,9 +49,9 @@ static ssize_t ...@@ -49,9 +49,9 @@ static ssize_t
mode_show(struct device *dev, struct device_attribute *attr, char *buf) mode_show(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct thermal_zone_device *tz = to_thermal_zone(dev); struct thermal_zone_device *tz = to_thermal_zone(dev);
int enabled = thermal_zone_device_is_enabled(tz);
return sprintf(buf, "%s\n", tz->mode == THERMAL_DEVICE_ENABLED ? return sprintf(buf, "%s\n", enabled ? "enabled" : "disabled");
"enabled" : "disabled");
} }
static ssize_t static ssize_t
...@@ -61,13 +61,10 @@ mode_store(struct device *dev, struct device_attribute *attr, ...@@ -61,13 +61,10 @@ mode_store(struct device *dev, struct device_attribute *attr,
struct thermal_zone_device *tz = to_thermal_zone(dev); struct thermal_zone_device *tz = to_thermal_zone(dev);
int result; int result;
if (!tz->ops->set_mode)
return -EPERM;
if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); result = thermal_zone_device_enable(tz);
else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); result = thermal_zone_device_disable(tz);
else else
result = -EINVAL; result = -EINVAL;
......
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