diff options
| author | Andrzej Pietrasiewicz <andrzej.p@collabora.com> | 2020-06-29 14:29:21 +0200 | 
|---|---|---|
| committer | Daniel Lezcano <daniel.lezcano@linaro.org> | 2020-06-29 20:26:36 +0200 | 
| commit | 7f4957be0d5b83c8964491863202136c916107ae (patch) | |
| tree | 5d3f46b069347b04ff78eb0c073e994efbb20047 /drivers/thermal | |
| parent | ac5d9ecc74d8beee8c87f1441e4adaf4e9fe90c5 (diff) | |
| download | linux-7f4957be0d5b83c8964491863202136c916107ae.tar.bz2 | |
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: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
[for acerhdf]
Acked-by: Peter Kaestle <peter@piie.net>
Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20200629122925.21729-8-andrzej.p@collabora.com
Diffstat (limited to 'drivers/thermal')
| -rw-r--r-- | drivers/thermal/da9062-thermal.c | 6 | ||||
| -rw-r--r-- | drivers/thermal/hisi_thermal.c | 6 | ||||
| -rw-r--r-- | drivers/thermal/imx_thermal.c | 33 | ||||
| -rw-r--r-- | drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 5 | ||||
| -rw-r--r-- | drivers/thermal/intel/intel_quark_dts_thermal.c | 18 | ||||
| -rw-r--r-- | drivers/thermal/rockchip_thermal.c | 6 | ||||
| -rw-r--r-- | drivers/thermal/sprd_thermal.c | 6 | ||||
| -rw-r--r-- | drivers/thermal/thermal_core.c | 2 | ||||
| -rw-r--r-- | drivers/thermal/thermal_of.c | 10 | ||||
| -rw-r--r-- | drivers/thermal/thermal_sysfs.c | 11 | 
10 files changed, 42 insertions, 61 deletions
| diff --git a/drivers/thermal/da9062-thermal.c b/drivers/thermal/da9062-thermal.c index a7ac8afb063e..4d74994f160a 100644 --- a/drivers/thermal/da9062-thermal.c +++ b/drivers/thermal/da9062-thermal.c @@ -237,7 +237,11 @@ static int da9062_thermal_probe(struct platform_device *pdev)  		ret = PTR_ERR(thermal->zone);  		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,  		"TJUNC temperature polling period set at %d ms\n", diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 2d26ae80e202..ee05950afd2f 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -549,8 +549,10 @@ static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor,  {  	struct thermal_zone_device *tzd = sensor->tzd; -	tzd->ops->set_mode(tzd, -		on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); +	if (on) +		thermal_zone_device_enable(tzd); +	else +		thermal_zone_device_disable(tzd);  }  static int hisi_thermal_probe(struct platform_device *pdev) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 2c7ee5da608a..53abb1be1cba 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -255,7 +255,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)  	bool wait;  	u32 val; -	if (tz->mode == THERMAL_DEVICE_ENABLED) { +	if (thermal_zone_device_is_enabled(tz)) {  		/* Check if a measurement is currently in progress */  		regmap_read(map, soc_data->temp_data, &val);  		wait = !(val & soc_data->temp_valid_mask); @@ -282,7 +282,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)  	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,  			     soc_data->measure_temp_mask);  		regmap_write(map, soc_data->sensor_ctrl + REG_SET, @@ -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;  } @@ -819,7 +816,9 @@ static int imx_thermal_probe(struct platform_device *pdev)  		     data->socdata->measure_temp_mask);  	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,  			imx_thermal_alarm_irq, imx_thermal_alarm_irq_thread, @@ -861,19 +860,18 @@ static int imx_thermal_remove(struct platform_device *pdev)  static int __maybe_unused imx_thermal_suspend(struct device *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  	 * try to get temperature before thermal sensor resume, a wrong  	 * 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, -		     data->socdata->measure_temp_mask); -	regmap_write(map, data->socdata->sensor_ctrl + REG_SET, -		     data->socdata->power_down_mask); -	data->tz->mode = THERMAL_DEVICE_DISABLED; +	ret = thermal_zone_device_disable(data->tz); +	if (ret) +		return ret;  	clk_disable_unprepare(data->thermal_clk);  	return 0; @@ -882,18 +880,15 @@ static int __maybe_unused imx_thermal_suspend(struct device *dev)  static int __maybe_unused imx_thermal_resume(struct device *dev)  {  	struct imx_thermal_data *data = dev_get_drvdata(dev); -	struct regmap *map = data->tempmon;  	int ret;  	ret = clk_prepare_enable(data->thermal_clk);  	if (ret)  		return ret;  	/* Enabled thermal sensor after resume */ -	regmap_write(map, data->socdata->sensor_ctrl + REG_CLR, -		     data->socdata->power_down_mask); -	regmap_write(map, data->socdata->sensor_ctrl + REG_SET, -		     data->socdata->measure_temp_mask); -	data->tz->mode = THERMAL_DEVICE_ENABLED; +	ret = thermal_zone_device_enable(data->tz); +	if (ret) +		return ret;  	return 0;  } diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 9a622aaf29dd..3c0397a29b8c 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -390,12 +390,11 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal,  	    mode != THERMAL_DEVICE_DISABLED)  		return -EINVAL; -	if (mode != thermal->mode) { -		thermal->mode = mode; +	if (mode != thermal->mode)  		result = int3400_thermal_run_osc(priv->adev->handle,  						priv->current_uuid_index,  						mode == THERMAL_DEVICE_ENABLED); -	} +  	evaluate_odvp(priv); diff --git a/drivers/thermal/intel/intel_quark_dts_thermal.c b/drivers/thermal/intel/intel_quark_dts_thermal.c index c4879b4bfbf1..e29c3e330b17 100644 --- a/drivers/thermal/intel/intel_quark_dts_thermal.c +++ b/drivers/thermal/intel/intel_quark_dts_thermal.c @@ -126,10 +126,8 @@ static int soc_dts_enable(struct thermal_zone_device *tzd)  	if (ret)  		return ret; -	if (out & QRK_DTS_ENABLE_BIT) { -		tzd->mode = THERMAL_DEVICE_ENABLED; +	if (out & QRK_DTS_ENABLE_BIT)  		return 0; -	}  	if (!aux_entry->locked) {  		out |= QRK_DTS_ENABLE_BIT; @@ -137,10 +135,7 @@ static int soc_dts_enable(struct thermal_zone_device *tzd)  				     QRK_DTS_REG_OFFSET_ENABLE, out);  		if (ret)  			return ret; - -		tzd->mode = THERMAL_DEVICE_ENABLED;  	} else { -		tzd->mode = THERMAL_DEVICE_DISABLED;  		pr_info("DTS is locked. Cannot enable DTS\n");  		ret = -EPERM;  	} @@ -159,10 +154,8 @@ static int soc_dts_disable(struct thermal_zone_device *tzd)  	if (ret)  		return ret; -	if (!(out & QRK_DTS_ENABLE_BIT)) { -		tzd->mode = THERMAL_DEVICE_DISABLED; +	if (!(out & QRK_DTS_ENABLE_BIT))  		return 0; -	}  	if (!aux_entry->locked) {  		out &= ~QRK_DTS_ENABLE_BIT; @@ -171,10 +164,7 @@ static int soc_dts_disable(struct thermal_zone_device *tzd)  		if (ret)  			return ret; - -		tzd->mode = THERMAL_DEVICE_DISABLED;  	} else { -		tzd->mode = THERMAL_DEVICE_ENABLED;  		pr_info("DTS is locked. Cannot disable DTS\n");  		ret = -EPERM;  	} @@ -404,9 +394,7 @@ static struct soc_sensor_entry *alloc_soc_dts(void)  		goto err_ret;  	} -	mutex_lock(&dts_update_mutex); -	err = soc_dts_enable(aux_entry->tzone); -	mutex_unlock(&dts_update_mutex); +	err = thermal_zone_device_enable(aux_entry->tzone);  	if (err)  		goto err_aux_status; diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c index 15a71ecc916c..aa9e0e31ef98 100644 --- a/drivers/thermal/rockchip_thermal.c +++ b/drivers/thermal/rockchip_thermal.c @@ -1068,8 +1068,10 @@ rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on)  {  	struct thermal_zone_device *tzd = sensor->tzd; -	tzd->ops->set_mode(tzd, -		on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); +	if (on) +		thermal_zone_device_enable(tzd); +	else +		thermal_zone_device_disable(tzd);  }  static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev) diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c index a340374e8c51..58f995b0f804 100644 --- a/drivers/thermal/sprd_thermal.c +++ b/drivers/thermal/sprd_thermal.c @@ -322,8 +322,10 @@ static void sprd_thm_toggle_sensor(struct sprd_thermal_sensor *sen, bool on)  {  	struct thermal_zone_device *tzd = sen->tzd; -	tzd->ops->set_mode(tzd, -		on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); +	if (on) +		thermal_zone_device_enable(tzd); +	else +		thermal_zone_device_disable(tzd);  }  static int sprd_thm_probe(struct platform_device *pdev) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index f02c57c986f0..52d136780577 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1521,7 +1521,7 @@ static int thermal_pm_notify(struct notifier_block *nb,  	case PM_POST_SUSPEND:  		atomic_set(&in_suspend, 0);  		list_for_each_entry(tz, &thermal_tz_list, node) { -			if (tz->mode == THERMAL_DEVICE_DISABLED) +			if (!thermal_zone_device_is_enabled(tz))  				continue;  			thermal_zone_device_init(tz); diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index ba65d48a48cb..43a516a35d64 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -272,8 +272,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,  {  	struct __thermal_zone *data = tz->devdata; -	mutex_lock(&tz->lock); -  	if (mode == THERMAL_DEVICE_ENABLED) {  		tz->polling_delay = data->polling_delay;  		tz->passive_delay = data->passive_delay; @@ -282,11 +280,6 @@ static int of_thermal_set_mode(struct thermal_zone_device *tz,  		tz->passive_delay = 0;  	} -	mutex_unlock(&tz->lock); - -	tz->mode = mode; -	thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); -  	return 0;  } @@ -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,  							 data, ops);  			if (!IS_ERR(tzd)) -				tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED); +				thermal_zone_device_enable(tzd);  			of_node_put(child);  			goto exit; @@ -1120,7 +1113,6 @@ int __init of_parse_thermal_zones(void)  			of_thermal_free_zone(tz);  			/* attempting to build remaining zones still */  		} -		zone->mode = THERMAL_DEVICE_DISABLED;  	}  	of_node_put(np); diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 096370977068..c23d67c4dc4e 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -49,9 +49,9 @@ static ssize_t  mode_show(struct device *dev, struct device_attribute *attr, char *buf)  {  	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 ? -		       "enabled" : "disabled"); +	return sprintf(buf, "%s\n", enabled ? "enabled" : "disabled");  }  static ssize_t @@ -61,13 +61,10 @@ mode_store(struct device *dev, struct device_attribute *attr,  	struct thermal_zone_device *tz = to_thermal_zone(dev);  	int result; -	if (!tz->ops->set_mode) -		return -EPERM; -  	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)) -		result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); +		result = thermal_zone_device_disable(tz);  	else  		result = -EINVAL; |