Skip to contentSkip to conversation

thermal OF rework

PATCH Superseded Daniel Lezcano 7 participants 29 messages May 7, 2022 – Jun 26, 2022

Subsystems (22)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover thermal OF rework

The thermal framework initialization with the device tree appears to be complicated and hard to make it to evolve.

It contains duplication of almost the same thermal generic structures and has an assymetric initialization making hard any kind of serious changes for more complex features. One of them is the multiple sensors support per thermal zone.

In order to set the scene for the aforementioned feature with generic code, we need to cleanup and rework the device tree initialization.

However this rework is not obvious because of the multiple components entering in the composition of a thermal zone and being initialized at different moments. For instance, a cooling device can be initialized before a sensor, so the thermal zones must exist before the cooling device as well as the sensor. This asynchonous initialization forces the thermal zone to be created with fake ops because they are mandotory and build a list of cooling devices which is used to lookup afterwards when the cooling device driver is registering itself.

As there could be a large number of changes, this first series provide some steps forward for a simpler device tree initialization.

Changelog:
- V2:
- Drop patch 1/15 which contains too many changes for a simple structure renaming. This could be addressed in a separate series as it is not necessary for the OF rework

- Fixed of_node_put with gchild not initialized as reported by kbuild and Dan Carpenter

- V1:
- Initial post

Daniel Lezcano (14):
thermal/core: Change thermal_zone_ops to thermal_sensor_ops thermal/core: Add a thermal sensor structure in the thermal zone thermal/core: Remove duplicate information when an error occurs thermal/of: Replace device node match with device node search thermal/of: Remove the device node pointer for thermal_trip thermal/of: Move thermal_trip structure to thermal.h thermal/core: Remove unneeded EXPORT_SYMBOLS thermal/core: Move thermal_set_delay_jiffies to static thermal/core: Rename trips to ntrips
thermal/core: Add thermal_trip in thermal_zone thermal/core: Register with the trip points thermal/of: Store the trips in the thermal zone thermal/of: Use thermal trips stored in the thermal zone thermal/of: Initialize trip points separately

 .../driver-api/thermal/sysfs-api.rst          |   2 +-
 drivers/acpi/thermal.c                        |   6 +-
 .../ethernet/chelsio/cxgb4/cxgb4_thermal.c    |   2 +-
 .../ethernet/mellanox/mlxsw/core_thermal.c    |   6 +-
 drivers/net/wireless/intel/iwlwifi/mvm/tt.c   |   2 +-
 drivers/platform/x86/acerhdf.c                |   2 +-
 drivers/power/supply/power_supply_core.c      |   2 +-
 drivers/thermal/armada_thermal.c              |   2 +-
 drivers/thermal/broadcom/bcm2835_thermal.c    |   2 +-
 drivers/thermal/da9062-thermal.c              |   2 +-
 drivers/thermal/dove_thermal.c                |   2 +-
 drivers/thermal/gov_bang_bang.c               |   6 +-
 drivers/thermal/gov_fair_share.c              |  10 +-
 drivers/thermal/gov_power_allocator.c         |  22 +-
 drivers/thermal/gov_step_wise.c               |   4 +-
 drivers/thermal/imx_thermal.c                 |   2 +-
 .../intel/int340x_thermal/int3400_thermal.c   |   2 +-
 .../int340x_thermal/int340x_thermal_zone.c    |   6 +-
 .../int340x_thermal/int340x_thermal_zone.h    |   4 +-
 .../processor_thermal_device.c                |   4 +-
 .../processor_thermal_device_pci.c            |   2 +-
 drivers/thermal/intel/intel_pch_thermal.c     |   2 +-
 .../thermal/intel/intel_quark_dts_thermal.c   |   2 +-
 drivers/thermal/intel/intel_soc_dts_iosf.c    |   2 +-
 drivers/thermal/intel/x86_pkg_temp_thermal.c  |   2 +-
 drivers/thermal/kirkwood_thermal.c            |   2 +-
 drivers/thermal/rcar_gen3_thermal.c           |   6 +-
 drivers/thermal/rcar_thermal.c                |   4 +-
 drivers/thermal/samsung/exynos_tmu.c          |   6 +-
 drivers/thermal/spear_thermal.c               |   2 +-
 drivers/thermal/st/st_thermal.c               |   2 +-
 drivers/thermal/tegra/soctherm.c              |  10 +-
 drivers/thermal/tegra/tegra30-tsensor.c       |   6 +-
 drivers/thermal/thermal_core.c                | 102 ++++----
 drivers/thermal/thermal_core.h                |  25 +-
 drivers/thermal/thermal_helpers.c             |  35 ++-
 drivers/thermal/thermal_hwmon.c               |   4 +-
 drivers/thermal/thermal_netlink.c             |  10 +-
 drivers/thermal/thermal_of.c                  | 221 ++++++++++--------
 drivers/thermal/thermal_sysfs.c               |  62 ++---
 include/linux/thermal.h                       |  34 ++-
 41 files changed, 341 insertions(+), 290 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/14 thermal/core: Change thermal_zone_ops to thermal_sensor_ops

A thermal zone is software abstraction of a sensor associated with properties and cooling devices if any.

The fact that we have thermal_zone and thermal_zone_ops mixed is confusing and does not clearly identify the different components entering in the thermal management process. A thermal zone appears to be a sensor while it is not.

In order to set the scene for multiple thermal sensors aggregated into a single thermal zone. Rename the thermal_zone_ops to thermal_sensor_ops, that will appear clearyl the thermal zone is not a sensor but an abstraction of one [or multiple] sensor(s).

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 Documentation/driver-api/thermal/sysfs-api.rst            | 2 +-
 drivers/acpi/thermal.c                                    | 6 +++---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c        | 2 +-
 drivers/net/ethernet/mellanox/mlxsw/core_thermal.c        | 6 +++---
 drivers/net/wireless/intel/iwlwifi/mvm/tt.c               | 2 +-
 drivers/platform/x86/acerhdf.c                            | 2 +-
 drivers/power/supply/power_supply_core.c                  | 2 +-
 drivers/thermal/armada_thermal.c                          | 2 +-
 drivers/thermal/da9062-thermal.c                          | 2 +-
 drivers/thermal/dove_thermal.c                            | 2 +-
 drivers/thermal/imx_thermal.c                             | 2 +-
 drivers/thermal/intel/int340x_thermal/int3400_thermal.c   | 2 +-
 .../thermal/intel/int340x_thermal/int340x_thermal_zone.c  | 6 +++---
 .../thermal/intel/int340x_thermal/int340x_thermal_zone.h  | 4 ++--
 .../intel/int340x_thermal/processor_thermal_device.c      | 4 ++--
 .../intel/int340x_thermal/processor_thermal_device_pci.c  | 2 +-
 drivers/thermal/intel/intel_pch_thermal.c                 | 2 +-
 drivers/thermal/intel/intel_quark_dts_thermal.c           | 2 +-
 drivers/thermal/intel/intel_soc_dts_iosf.c                | 2 +-
 drivers/thermal/intel/x86_pkg_temp_thermal.c              | 2 +-
 drivers/thermal/kirkwood_thermal.c                        | 2 +-
 drivers/thermal/rcar_thermal.c                            | 4 ++--
 drivers/thermal/spear_thermal.c                           | 2 +-
 drivers/thermal/st/st_thermal.c                           | 2 +-
 drivers/thermal/thermal_core.c                            | 2 +-
 drivers/thermal/thermal_of.c                              | 4 ++--
 include/linux/thermal.h                                   | 8 ++++----
 27 files changed, 40 insertions(+), 40 deletions(-)
Documentation/driver-api/thermal/sysfs-api.rst +1 -1
index 2e0f79a9e2ee..6dff5e6e1166 100644
@@ -41,7 +41,7 @@ temperature) and throttle appropriate devices.
 	struct thermal_zone_device
 	*thermal_zone_device_register(char *type,
 				      int trips, int mask, void *devdata,
-				      struct thermal_zone_device_ops *ops,
+				      struct thermal_sensor_ops *ops,
 				      const struct thermal_zone_params *tzp,
 				      int passive_delay, int polling_delay))
 
drivers/acpi/thermal.c +3 -3
index 539660ef93c7..c2b8100f9cd8 100644
@@ -774,7 +774,7 @@ acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal,
 	return acpi_thermal_cooling_device_cb(thermal, cdev, false);
 }
 
-static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
+static struct thermal_sensor_ops acpi_thermal_sensor_ops = {
 	.bind = acpi_thermal_bind_cooling_device,
 	.unbind	= acpi_thermal_unbind_cooling_device,
 	.get_temp = thermal_get_temp,
@@ -808,13 +808,13 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
 	if (tz->trips.passive.flags.valid)
 		tz->thermal_zone =
 			thermal_zone_device_register("acpitz", trips, 0, tz,
-						&acpi_thermal_zone_ops, NULL,
+						&acpi_thermal_sensor_ops, NULL,
 						     tz->trips.passive.tsp*100,
 						     tz->polling_frequency*100);
 	else
 		tz->thermal_zone =
 			thermal_zone_device_register("acpitz", trips, 0, tz,
-						&acpi_thermal_zone_ops, NULL,
+						&acpi_thermal_sensor_ops, NULL,
 						0, tz->polling_frequency*100);
 	if (IS_ERR(tz->thermal_zone))
 		return -ENODEV;
drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c +1 -1
index 9a6d65243334..239824e90fbe 100644
@@ -53,7 +53,7 @@ static int cxgb4_thermal_get_trip_temp(struct thermal_zone_device *tzdev,
 	return 0;
 }
 
-static struct thermal_zone_device_ops cxgb4_thermal_ops = {
+static struct thermal_sensor_ops cxgb4_thermal_ops = {
 	.get_temp = cxgb4_thermal_get_temp,
 	.get_trip_type = cxgb4_thermal_get_trip_type,
 	.get_trip_temp = cxgb4_thermal_get_trip_temp,
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c +3 -3
index 05f54bd982c0..cf609dc39acd 100644
@@ -361,7 +361,7 @@ static struct thermal_zone_params mlxsw_thermal_params = {
 	.no_hwmon = true,
 };
 
-static struct thermal_zone_device_ops mlxsw_thermal_ops = {
+static struct thermal_sensor_ops mlxsw_thermal_ops = {
 	.bind = mlxsw_thermal_bind,
 	.unbind = mlxsw_thermal_unbind,
 	.get_temp = mlxsw_thermal_get_temp,
@@ -553,7 +553,7 @@ static int mlxsw_thermal_module_trend_get(struct thermal_zone_device *tzdev,
 	return 0;
 }
 
-static struct thermal_zone_device_ops mlxsw_thermal_module_ops = {
+static struct thermal_sensor_ops mlxsw_thermal_module_ops = {
 	.bind		= mlxsw_thermal_module_bind,
 	.unbind		= mlxsw_thermal_module_unbind,
 	.get_temp	= mlxsw_thermal_module_temp_get,
@@ -590,7 +590,7 @@ static int mlxsw_thermal_gearbox_temp_get(struct thermal_zone_device *tzdev,
 	return 0;
 }
 
-static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = {
+static struct thermal_sensor_ops mlxsw_thermal_gearbox_ops = {
 	.bind		= mlxsw_thermal_module_bind,
 	.unbind		= mlxsw_thermal_module_unbind,
 	.get_temp	= mlxsw_thermal_gearbox_temp_get,
drivers/net/wireless/intel/iwlwifi/mvm/tt.c +1 -1
index 69cf3a372759..74109a7d329f 100644
@@ -718,7 +718,7 @@ static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device,
 	return ret;
 }
 
-static  struct thermal_zone_device_ops tzone_ops = {
+static  struct thermal_sensor_ops tzone_ops = {
 	.get_temp = iwl_mvm_tzone_get_temp,
 	.get_trip_temp = iwl_mvm_tzone_get_trip_temp,
 	.get_trip_type = iwl_mvm_tzone_get_trip_type,
drivers/platform/x86/acerhdf.c +1 -1
index 3463629f8764..b9e8f6c60714 100644
@@ -469,7 +469,7 @@ static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal,
 }
 
 /* bind callback functions to thermalzone */
-static struct thermal_zone_device_ops acerhdf_dev_ops = {
+static struct thermal_sensor_ops acerhdf_dev_ops = {
 	.bind = acerhdf_bind,
 	.unbind = acerhdf_unbind,
 	.get_temp = acerhdf_get_ec_temp,
drivers/power/supply/power_supply_core.c +1 -1
index d925cb137e12..5ada4a94b4e3 100644
@@ -1149,7 +1149,7 @@ static int power_supply_read_temp(struct thermal_zone_device *tzd,
 	return ret;
 }
 
-static struct thermal_zone_device_ops psy_tzd_ops = {
+static struct thermal_sensor_ops psy_tzd_ops = {
 	.get_temp = power_supply_read_temp,
 };
 
drivers/thermal/armada_thermal.c +1 -1
index c2ebfb5be4b3..703ace32a217 100644
@@ -416,7 +416,7 @@ static int armada_get_temp_legacy(struct thermal_zone_device *thermal,
 	return ret;
 }
 
-static struct thermal_zone_device_ops legacy_ops = {
+static struct thermal_sensor_ops legacy_ops = {
 	.get_temp = armada_get_temp_legacy,
 };
 
drivers/thermal/da9062-thermal.c +1 -1
index 180edec34e07..d29953eee39f 100644
@@ -170,7 +170,7 @@ static int da9062_thermal_get_temp(struct thermal_zone_device *z,
 	return 0;
 }
 
-static struct thermal_zone_device_ops da9062_thermal_ops = {
+static struct thermal_sensor_ops da9062_thermal_ops = {
 	.get_temp	= da9062_thermal_get_temp,
 	.get_trip_type	= da9062_thermal_get_trip_type,
 	.get_trip_temp	= da9062_thermal_get_trip_temp,
drivers/thermal/dove_thermal.c +1 -1
index 73182eb94bc0..170a1168ae38 100644
@@ -109,7 +109,7 @@ static int dove_get_temp(struct thermal_zone_device *thermal,
 	return 0;
 }
 
-static struct thermal_zone_device_ops ops = {
+static struct thermal_sensor_ops ops = {
 	.get_temp = dove_get_temp,
 };
 
drivers/thermal/imx_thermal.c +1 -1
index 16663373b682..c57fa2029ee0 100644
@@ -418,7 +418,7 @@ static int imx_unbind(struct thermal_zone_device *tz,
 	return 0;
 }
 
-static struct thermal_zone_device_ops imx_tz_ops = {
+static struct thermal_sensor_ops imx_tz_ops = {
 	.bind = imx_bind,
 	.unbind = imx_unbind,
 	.get_temp = imx_get_temp,
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +1 -1
index 4954800b9850..cad48a886888 100644
@@ -485,7 +485,7 @@ static int int3400_thermal_change_mode(struct thermal_zone_device *thermal,
 	return result;
 }
 
-static struct thermal_zone_device_ops int3400_thermal_ops = {
+static struct thermal_sensor_ops int3400_thermal_ops = {
 	.get_temp = int3400_thermal_get_temp,
 	.change_mode = int3400_thermal_change_mode,
 };
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +3 -3
index 62c0aa5d0783..d78f29208352 100644
@@ -151,7 +151,7 @@ static void int340x_thermal_critical(struct thermal_zone_device *zone)
 	dev_dbg(&zone->device, "%s: critical temperature reached\n", zone->type);
 }
 
-static struct thermal_zone_device_ops int340x_thermal_zone_ops = {
+static struct thermal_sensor_ops int340x_thermal_sensor_ops = {
 	.get_temp       = int340x_thermal_get_zone_temp,
 	.get_trip_temp	= int340x_thermal_get_trip_temp,
 	.get_trip_type	= int340x_thermal_get_trip_type,
@@ -217,7 +217,7 @@ static struct thermal_zone_params int340x_thermal_params = {
 };
 
 struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
-				struct thermal_zone_device_ops *override_ops)
+				struct thermal_sensor_ops *override_ops)
 {
 	struct int34x_thermal_zone *int34x_thermal_zone;
 	acpi_status status;
@@ -262,7 +262,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
 						acpi_device_bid(adev),
 						trip_cnt,
 						trip_mask, int34x_thermal_zone,
-						&int340x_thermal_zone_ops,
+						&int340x_thermal_sensor_ops,
 						&int340x_thermal_params,
 						0, 0);
 	if (IS_ERR(int34x_thermal_zone->zone)) {
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h +2 -2
index 3b4971df1b33..a25c45e2eb66 100644
@@ -29,13 +29,13 @@ struct int34x_thermal_zone {
 	int hot_temp;
 	int hot_trip_id;
 	struct thermal_zone_device *zone;
-	struct thermal_zone_device_ops *override_ops;
+	struct thermal_sensor_ops *override_ops;
 	void *priv_data;
 	struct acpi_lpat_conversion_table *lpat_table;
 };
 
 struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *,
-				struct thermal_zone_device_ops *override_ops);
+				struct thermal_sensor_ops *override_ops);
 void int340x_thermal_zone_remove(struct int34x_thermal_zone *);
 int int340x_thermal_read_trips(struct int34x_thermal_zone *int34x_zone);
 
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +2 -2
index a8d98f1bd6c6..4b8544f72a23 100644
@@ -207,7 +207,7 @@ static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone,
 	return ret;
 }
 
-static struct thermal_zone_device_ops proc_thermal_local_ops = {
+static struct thermal_sensor_ops proc_thermal_local_ops = {
 	.get_temp       = proc_thermal_get_zone_temp,
 };
 
@@ -285,7 +285,7 @@ int proc_thermal_add(struct device *dev, struct proc_thermal_device *proc_priv)
 	struct acpi_device *adev;
 	acpi_status status;
 	unsigned long long tmp;
-	struct thermal_zone_device_ops *ops = NULL;
+	struct thermal_sensor_ops *ops = NULL;
 	int ret;
 
 	adev = ACPI_COMPANION(dev);
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c +1 -1
index ca40b0967cdd..5316143b09b2 100644
@@ -200,7 +200,7 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp
 	return 0;
 }
 
-static struct thermal_zone_device_ops tzone_ops = {
+static struct thermal_sensor_ops tzone_ops = {
 	.get_temp = sys_get_curr_temp,
 	.get_trip_temp = sys_get_trip_temp,
 	.get_trip_type = sys_get_trip_type,
drivers/thermal/intel/intel_pch_thermal.c +1 -1
index 527c91f5960b..e2161ab647b0 100644
@@ -331,7 +331,7 @@ static void pch_critical(struct thermal_zone_device *tzd)
 	dev_dbg(&tzd->device, "%s: critical temperature reached\n", tzd->type);
 }
 
-static struct thermal_zone_device_ops tzd_ops = {
+static struct thermal_sensor_ops tzd_ops = {
 	.get_temp = pch_thermal_get_temp,
 	.get_trip_type = pch_get_trip_type,
 	.get_trip_temp = pch_get_trip_temp,
drivers/thermal/intel/intel_quark_dts_thermal.c +1 -1
index 3eafc6b0e6c3..636286dc90fc 100644
@@ -313,7 +313,7 @@ static int sys_change_mode(struct thermal_zone_device *tzd,
 	return ret;
 }
 
-static struct thermal_zone_device_ops tzone_ops = {
+static struct thermal_sensor_ops tzone_ops = {
 	.get_temp = sys_get_curr_temp,
 	.get_trip_temp = sys_get_trip_temp,
 	.get_trip_type = sys_get_trip_type,
drivers/thermal/intel/intel_soc_dts_iosf.c +1 -1
index 342b0bb5a56d..38ce8426fc35 100644
@@ -243,7 +243,7 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd,
 	return 0;
 }
 
-static struct thermal_zone_device_ops tzone_ops = {
+static struct thermal_sensor_ops tzone_ops = {
 	.get_temp = sys_get_curr_temp,
 	.get_trip_temp = sys_get_trip_temp,
 	.get_trip_type = sys_get_trip_type,
drivers/thermal/intel/x86_pkg_temp_thermal.c +1 -1
index 4d8edc61a78b..047e27db72fe 100644
@@ -220,7 +220,7 @@ static int sys_get_trip_type(struct thermal_zone_device *thermal, int trip,
 }
 
 /* Thermal zone callback registry */
-static struct thermal_zone_device_ops tzone_ops = {
+static struct thermal_sensor_ops tzone_ops = {
 	.get_temp = sys_get_curr_temp,
 	.get_trip_temp = sys_get_trip_temp,
 	.get_trip_type = sys_get_trip_type,
drivers/thermal/kirkwood_thermal.c +1 -1
index 7fb6e476c82a..d8e24549428d 100644
@@ -51,7 +51,7 @@ static int kirkwood_get_temp(struct thermal_zone_device *thermal,
 	return 0;
 }
 
-static struct thermal_zone_device_ops ops = {
+static struct thermal_sensor_ops ops = {
 	.get_temp = kirkwood_get_temp,
 };
 
drivers/thermal/rcar_thermal.c +2 -2
index b49f04daaf47..a7c22e85adc6 100644
@@ -327,7 +327,7 @@ static const struct thermal_zone_of_device_ops rcar_thermal_zone_of_ops = {
 	.get_temp	= rcar_thermal_of_get_temp,
 };
 
-static struct thermal_zone_device_ops rcar_thermal_zone_ops = {
+static struct thermal_sensor_ops rcar_thermal_sensor_ops = {
 	.get_temp	= rcar_thermal_get_temp,
 	.get_trip_type	= rcar_thermal_get_trip_type,
 	.get_trip_temp	= rcar_thermal_get_trip_temp,
@@ -534,7 +534,7 @@ static int rcar_thermal_probe(struct platform_device *pdev)
 			priv->zone = thermal_zone_device_register(
 						"rcar_thermal",
 						1, 0, priv,
-						&rcar_thermal_zone_ops, NULL, 0,
+						&rcar_thermal_sensor_ops, NULL, 0,
 						idle);
 
 			ret = thermal_zone_device_enable(priv->zone);
drivers/thermal/spear_thermal.c +1 -1
index ee33ed692e4f..462a8d4bd1c8 100644
@@ -41,7 +41,7 @@ static inline int thermal_get_temp(struct thermal_zone_device *thermal,
 	return 0;
 }
 
-static struct thermal_zone_device_ops ops = {
+static struct thermal_sensor_ops ops = {
 	.get_temp = thermal_get_temp,
 };
 
drivers/thermal/st/st_thermal.c +1 -1
index 1276b95604fe..c42d9cae5e52 100644
@@ -170,7 +170,7 @@ static int st_thermal_get_trip_temp(struct thermal_zone_device *th,
 	return 0;
 }
 
-static struct thermal_zone_device_ops st_tz_ops = {
+static struct thermal_sensor_ops st_tz_ops = {
 	.get_temp	= st_thermal_get_temp,
 	.get_trip_type	= st_thermal_get_trip_type,
 	.get_trip_temp	= st_thermal_get_trip_temp,
drivers/thermal/thermal_core.c +1 -1
index 82654dc8382b..065dfc179e53 100644
@@ -1184,7 +1184,7 @@ static void bind_tz(struct thermal_zone_device *tz)
  */
 struct thermal_zone_device *
 thermal_zone_device_register(const char *type, int trips, int mask,
-			     void *devdata, struct thermal_zone_device_ops *ops,
+			     void *devdata, struct thermal_sensor_ops *ops,
 			     struct thermal_zone_params *tzp, int passive_delay,
 			     int polling_delay)
 {
drivers/thermal/thermal_of.c +2 -2
index 9233f7e74454..ef953cba3504 100644
@@ -360,7 +360,7 @@ static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
 	return -EINVAL;
 }
 
-static struct thermal_zone_device_ops of_thermal_ops = {
+static struct thermal_sensor_ops of_thermal_ops = {
 	.get_trip_type = of_thermal_get_trip_type,
 	.get_trip_temp = of_thermal_get_trip_temp,
 	.set_trip_temp = of_thermal_set_trip_temp,
@@ -1046,7 +1046,7 @@ int __init of_parse_thermal_zones(void)
 {
 	struct device_node *np, *child;
 	struct __thermal_zone *tz;
-	struct thermal_zone_device_ops *ops;
+	struct thermal_sensor_ops *ops;
 
 	np = of_find_node_by_name(NULL, "thermal-zones");
 	if (!np) {
include/linux/thermal.h +4 -4
index c314893970b3..991f7bc02d51 100644
@@ -57,7 +57,7 @@ enum thermal_notify_event {
 	THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */
 };
 
-struct thermal_zone_device_ops {
+struct thermal_sensor_ops {
 	int (*bind) (struct thermal_zone_device *,
 		     struct thermal_cooling_device *);
 	int (*unbind) (struct thermal_zone_device *,
@@ -164,7 +164,7 @@ struct thermal_zone_device {
 	int prev_low_trip;
 	int prev_high_trip;
 	atomic_t need_update;
-	struct thermal_zone_device_ops *ops;
+	struct thermal_sensor_ops *ops;
 	struct thermal_zone_params *tzp;
 	struct thermal_governor *governor;
 	void *governor_data;
@@ -361,7 +361,7 @@ void devm_thermal_zone_of_sensor_unregister(struct device *dev,
 
 #ifdef CONFIG_THERMAL
 struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
-		void *, struct thermal_zone_device_ops *,
+		void *, struct thermal_sensor_ops *,
 		struct thermal_zone_params *, int, int);
 void thermal_zone_device_unregister(struct thermal_zone_device *);
 
@@ -396,7 +396,7 @@ void thermal_zone_device_critical(struct thermal_zone_device *tz);
 #else
 static inline struct thermal_zone_device *thermal_zone_device_register(
 	const char *type, int trips, int mask, void *devdata,
-	struct thermal_zone_device_ops *ops,
+	struct thermal_sensor_ops *ops,
 	struct thermal_zone_params *tzp,
 	int passive_delay, int polling_delay)
 { return ERR_PTR(-ENODEV); }
Signature · 1 line
2.25.1
#10 lore raw

PATCH v2 2/14 thermal/core: Add a thermal sensor structure in the thermal zone

In reply to Daniel Lezcano

The thermal sensor ops is directly defined in the thermal zone but still its data structuration makes the sensor ops and the thermal zone too much interconnected for multiple sensors per thermal zone.

Create a dedicated structure for the thermal sensor to be included in the thermal zone structure so these components are clearly separated.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/broadcom/bcm2835_thermal.c |  2 +-
 drivers/thermal/gov_bang_bang.c            |  6 +--
 drivers/thermal/gov_fair_share.c           |  6 +--
 drivers/thermal/gov_power_allocator.c      | 18 ++++----
 drivers/thermal/gov_step_wise.c            |  4 +-
 drivers/thermal/rcar_gen3_thermal.c        |  6 +--
 drivers/thermal/samsung/exynos_tmu.c       |  6 +--
 drivers/thermal/tegra/soctherm.c           | 10 ++---
 drivers/thermal/tegra/tegra30-tsensor.c    |  4 +-
 drivers/thermal/thermal_core.c             | 48 +++++++++++-----------
 drivers/thermal/thermal_helpers.c          | 22 +++++-----
 drivers/thermal/thermal_hwmon.c            |  4 +-
 drivers/thermal/thermal_netlink.c          |  8 ++--
 drivers/thermal/thermal_of.c               | 16 ++++----
 drivers/thermal/thermal_sysfs.c            | 40 +++++++++---------
 include/linux/thermal.h                    |  7 +++-
 16 files changed, 106 insertions(+), 101 deletions(-)
drivers/thermal/broadcom/bcm2835_thermal.c +1 -1
index c8e4344d5a3d..a3feb82b560c 100644
@@ -232,7 +232,7 @@ static int bcm2835_thermal_probe(struct platform_device *pdev)
 		 * For now we deal only with critical, otherwise
 		 * would need to iterate
 		 */
-		err = tz->ops->get_trip_temp(tz, 0, &trip_temp);
+		err = tz->sensor.ops->get_trip_temp(tz, 0, &trip_temp);
 		if (err < 0) {
 			dev_err(&pdev->dev,
 				"Not able to read trip_temp: %d\n",
drivers/thermal/gov_bang_bang.c +3 -3
index 991a1c54296d..2d9695ded819 100644
@@ -18,14 +18,14 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
 	int trip_temp, trip_hyst;
 	struct thermal_instance *instance;
 
-	tz->ops->get_trip_temp(tz, trip, &trip_temp);
+	tz->sensor.ops->get_trip_temp(tz, trip, &trip_temp);
 
-	if (!tz->ops->get_trip_hyst) {
+	if (!tz->sensor.ops->get_trip_hyst) {
 		pr_warn_once("Undefined get_trip_hyst for thermal zone %s - "
 				"running with default hysteresis zero\n", tz->type);
 		trip_hyst = 0;
 	} else
-		tz->ops->get_trip_hyst(tz, trip, &trip_hyst);
+		tz->sensor.ops->get_trip_hyst(tz, trip, &trip_hyst);
 
 	dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n",
 				trip, trip_temp, tz->temperature,
drivers/thermal/gov_fair_share.c +3 -3
index 1e5abf4822be..a157c621da59 100644
@@ -25,11 +25,11 @@ static int get_trip_level(struct thermal_zone_device *tz)
 	int trip_temp;
 	enum thermal_trip_type trip_type;
 
-	if (tz->trips == 0 || !tz->ops->get_trip_temp)
+	if (tz->trips == 0 || !tz->sensor.ops->get_trip_temp)
 		return 0;
 
 	for (count = 0; count < tz->trips; count++) {
-		tz->ops->get_trip_temp(tz, count, &trip_temp);
+		tz->sensor.ops->get_trip_temp(tz, count, &trip_temp);
 		if (tz->temperature < trip_temp)
 			break;
 	}
@@ -39,7 +39,7 @@ static int get_trip_level(struct thermal_zone_device *tz)
 	 * point, in which case, trip_point = count - 1
 	 */
 	if (count > 0) {
-		tz->ops->get_trip_type(tz, count - 1, &trip_type);
+		tz->sensor.ops->get_trip_type(tz, count - 1, &trip_type);
 		trace_thermal_zone_trip(tz, count - 1, trip_type);
 	}
 
drivers/thermal/gov_power_allocator.c +9 -9
index 13e375751d22..bcd146175f84 100644
@@ -130,7 +130,7 @@ static void estimate_pid_constants(struct thermal_zone_device *tz,
 	u32 temperature_threshold;
 	s32 k_i;
 
-	ret = tz->ops->get_trip_temp(tz, trip_switch_on, &switch_on_temp);
+	ret = tz->sensor.ops->get_trip_temp(tz, trip_switch_on, &switch_on_temp);
 	if (ret)
 		switch_on_temp = 0;
 
@@ -531,7 +531,7 @@ static void get_governor_trips(struct thermal_zone_device *tz,
 		enum thermal_trip_type type;
 		int ret;
 
-		ret = tz->ops->get_trip_type(tz, i, &type);
+		ret = tz->sensor.ops->get_trip_type(tz, i, &type);
 		if (ret) {
 			dev_warn(&tz->device,
 				 "Failed to get trip point %d type: %d\n", i,
@@ -669,9 +669,9 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
 	get_governor_trips(tz, params);
 
 	if (tz->trips > 0) {
-		ret = tz->ops->get_trip_temp(tz,
-					params->trip_max_desired_temperature,
-					&control_temp);
+		ret = tz->sensor.ops->get_trip_temp(tz,
+						    params->trip_max_desired_temperature,
+						    &control_temp);
 		if (!ret)
 			estimate_pid_constants(tz, tz->tzp->sustainable_power,
 					       params->trip_switch_on,
@@ -719,8 +719,8 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
 	if (trip != params->trip_max_desired_temperature)
 		return 0;
 
-	ret = tz->ops->get_trip_temp(tz, params->trip_switch_on,
-				     &switch_on_temp);
+	ret = tz->sensor.ops->get_trip_temp(tz, params->trip_switch_on,
+					    &switch_on_temp);
 	if (!ret && (tz->temperature < switch_on_temp)) {
 		update = (tz->last_temperature >= switch_on_temp);
 		tz->passive = 0;
@@ -731,8 +731,8 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
 
 	tz->passive = 1;
 
-	ret = tz->ops->get_trip_temp(tz, params->trip_max_desired_temperature,
-				&control_temp);
+	ret = tz->sensor.ops->get_trip_temp(tz, params->trip_max_desired_temperature,
+					    &control_temp);
 	if (ret) {
 		dev_warn(&tz->device,
 			 "Failed to get the maximum desired temperature: %d\n",
drivers/thermal/gov_step_wise.c +2 -2
index 12acb12aac50..044cfd116eba 100644
@@ -122,8 +122,8 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
 	bool throttle = false;
 	int old_target;
 
-	tz->ops->get_trip_temp(tz, trip, &trip_temp);
-	tz->ops->get_trip_type(tz, trip, &trip_type);
+	tz->sensor.ops->get_trip_temp(tz, trip, &trip_temp);
+	tz->sensor.ops->get_trip_type(tz, trip, &trip_type);
 
 	trend = get_tz_trend(tz, trip);
 
drivers/thermal/rcar_gen3_thermal.c +3 -3
index 43eb25b167bc..b205602ef6d8 100644
@@ -321,7 +321,7 @@ static void rcar_gen3_thermal_init_r8a7795es1(struct rcar_gen3_thermal_tsc *tsc)
 
 	rcar_gen3_thermal_write(tsc, REG_GEN3_IRQCTL, 0x3F);
 	rcar_gen3_thermal_write(tsc, REG_GEN3_IRQMSK, 0);
-	if (tsc->zone->ops->set_trips)
+	if (tsc->zone->sensor.ops->set_trips)
 		rcar_gen3_thermal_write(tsc, REG_GEN3_IRQEN,
 					IRQ_TEMPD1 | IRQ_TEMP2);
 
@@ -349,7 +349,7 @@ static void rcar_gen3_thermal_init(struct rcar_gen3_thermal_tsc *tsc)
 
 	rcar_gen3_thermal_write(tsc, REG_GEN3_IRQCTL, 0);
 	rcar_gen3_thermal_write(tsc, REG_GEN3_IRQMSK, 0);
-	if (tsc->zone->ops->set_trips)
+	if (tsc->zone->sensor.ops->set_trips)
 		rcar_gen3_thermal_write(tsc, REG_GEN3_IRQEN,
 					IRQ_TEMPD1 | IRQ_TEMP2);
 
@@ -555,7 +555,7 @@ static int __maybe_unused rcar_gen3_thermal_resume(struct device *dev)
 		struct thermal_zone_device *zone = tsc->zone;
 
 		priv->thermal_init(tsc);
-		if (zone->ops->set_trips)
+		if (zone->sensor.ops->set_trips)
 			rcar_gen3_thermal_set_trips(tsc, zone->prev_low_trip,
 						    zone->prev_high_trip);
 	}
drivers/thermal/samsung/exynos_tmu.c +3 -3
index f4ab4c5b4b62..ff83c8c43893 100644
@@ -272,7 +272,7 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
 	}
 
 	if (data->soc != SOC_ARCH_EXYNOS5433) /* FIXME */
-		ret = tzd->ops->get_crit_temp(tzd, &temp);
+		ret = tzd->sensor.ops->get_crit_temp(tzd, &temp);
 	if (ret) {
 		dev_err(&pdev->dev,
 			"No CRITICAL trip point defined in device tree!\n");
@@ -304,14 +304,14 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
 		/* Write temperature code for rising and falling threshold */
 		for (i = 0; i < ntrips; i++) {
 			/* Write temperature code for rising threshold */
-			ret = tzd->ops->get_trip_temp(tzd, i, &temp);
+			ret = tzd->sensor.ops->get_trip_temp(tzd, i, &temp);
 			if (ret)
 				goto err;
 			temp /= MCELSIUS;
 			data->tmu_set_trip_temp(data, i, temp);
 
 			/* Write temperature code for falling threshold */
-			ret = tzd->ops->get_trip_hyst(tzd, i, &hyst);
+			ret = tzd->sensor.ops->get_trip_hyst(tzd, i, &hyst);
 			if (ret)
 				goto err;
 			hyst /= MCELSIUS;
drivers/thermal/tegra/soctherm.c +5 -5
index 210325f92559..f21deefe8682 100644
@@ -595,7 +595,7 @@ static int tegra_thermctl_set_trip_temp(void *data, int trip, int temp)
 	if (!tz)
 		return -EINVAL;
 
-	ret = tz->ops->get_trip_type(tz, trip, &type);
+	ret = tz->sensor.ops->get_trip_type(tz, trip, &type);
 	if (ret)
 		return ret;
 
@@ -643,7 +643,7 @@ static int tegra_thermctl_get_trend(void *data, int trip,
 	if (!tz)
 		return -EINVAL;
 
-	ret = tz->ops->get_trip_temp(zone->tz, trip, &trip_temp);
+	ret = tz->sensor.ops->get_trip_temp(zone->tz, trip, &trip_temp);
 	if (ret)
 		return ret;
 
@@ -730,11 +730,11 @@ static int get_hot_temp(struct thermal_zone_device *tz, int *trip, int *temp)
 		return -EINVAL;
 
 	for (i = 0; i < ntrips; i++) {
-		ret = tz->ops->get_trip_type(tz, i, &type);
+		ret = tz->sensor.ops->get_trip_type(tz, i, &type);
 		if (ret)
 			return -EINVAL;
 		if (type == THERMAL_TRIP_HOT) {
-			ret = tz->ops->get_trip_temp(tz, i, temp);
+			ret = tz->sensor.ops->get_trip_temp(tz, i, temp);
 			if (!ret)
 				*trip = i;
 
@@ -780,7 +780,7 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
 	/* Get thermtrips. If missing, try to get critical trips. */
 	temperature = tsensor_group_thermtrip_get(ts, sg->id);
 	if (min_low_temp == temperature)
-		if (tz->ops->get_crit_temp(tz, &temperature))
+		if (tz->sensor.ops->get_crit_temp(tz, &temperature))
 			temperature = max_high_temp;
 
 	ret = thermtrip_program(dev, sg, temperature);
drivers/thermal/tegra/tegra30-tsensor.c +2 -2
index 9b6b693cbcf8..fab2709569c1 100644
@@ -320,8 +320,8 @@ static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd,
 		enum thermal_trip_type type;
 		int trip_temp;
 
-		tzd->ops->get_trip_temp(tzd, i, &trip_temp);
-		tzd->ops->get_trip_type(tzd, i, &type);
+		tzd->sensor.ops->get_trip_temp(tzd, i, &trip_temp);
+		tzd->sensor.ops->get_trip_type(tzd, i, &type);
 
 		if (type == THERMAL_TRIP_HOT)
 			*hot_trip = trip_temp;
drivers/thermal/thermal_core.c +24 -24

123 lines not on this page · raw message

drivers/thermal/thermal_helpers.c +11 -11
index 3edd047e144f..334478fe40fa 100644
@@ -27,8 +27,8 @@ int get_tz_trend(struct thermal_zone_device *tz, int trip)
 {
 	enum thermal_trend trend;
 
-	if (tz->emul_temperature || !tz->ops->get_trend ||
-	    tz->ops->get_trend(tz, trip, &trend)) {
+	if (tz->emul_temperature || !tz->sensor.ops->get_trend ||
+	    tz->sensor.ops->get_trend(tz, trip, &trend)) {
 		if (tz->temperature > tz->last_temperature)
 			trend = THERMAL_TREND_RAISING;
 		else if (tz->temperature < tz->last_temperature)
@@ -82,19 +82,19 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
 	int crit_temp = INT_MAX;
 	enum thermal_trip_type type;
 
-	if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
+	if (!tz || IS_ERR(tz) || !tz->sensor.ops->get_temp)
 		goto exit;
 
 	mutex_lock(&tz->lock);
 
-	ret = tz->ops->get_temp(tz, temp);
+	ret = tz->sensor.ops->get_temp(tz, temp);
 
 	if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
 		for (count = 0; count < tz->trips; count++) {
-			ret = tz->ops->get_trip_type(tz, count, &type);
+			ret = tz->sensor.ops->get_trip_type(tz, count, &type);
 			if (!ret && type == THERMAL_TRIP_CRITICAL) {
-				ret = tz->ops->get_trip_temp(tz, count,
-						&crit_temp);
+				ret = tz->sensor.ops->get_trip_temp(tz, count,
+								    &crit_temp);
 				break;
 			}
 		}
@@ -135,14 +135,14 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz)
 
 	mutex_lock(&tz->lock);
 
-	if (!tz->ops->set_trips || !tz->ops->get_trip_hyst)
+	if (!tz->sensor.ops->set_trips || !tz->sensor.ops->get_trip_hyst)
 		goto exit;
 
 	for (i = 0; i < tz->trips; i++) {
 		int trip_low;
 
-		tz->ops->get_trip_temp(tz, i, &trip_temp);
-		tz->ops->get_trip_hyst(tz, i, &hysteresis);
+		tz->sensor.ops->get_trip_temp(tz, i, &trip_temp);
+		tz->sensor.ops->get_trip_hyst(tz, i, &hysteresis);
 
 		trip_low = trip_temp - hysteresis;
 
@@ -167,7 +167,7 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz)
 	 * Set a temperature window. When this window is left the driver
 	 * must inform the thermal core via thermal_zone_device_update.
 	 */
-	ret = tz->ops->set_trips(tz, low, high);
+	ret = tz->sensor.ops->set_trips(tz, low, high);
 	if (ret)
 		dev_err(&tz->device, "Failed to set trips: %d\n", ret);
 
drivers/thermal/thermal_hwmon.c +2 -2
index ad03262cca56..e271729fa84e 100644
@@ -77,7 +77,7 @@ temp_crit_show(struct device *dev, struct device_attribute *attr, char *buf)
 	int temperature;
 	int ret;
 
-	ret = tz->ops->get_crit_temp(tz, &temperature);
+	ret = tz->sensor.ops->get_crit_temp(tz, &temperature);
 	if (ret)
 		return ret;
 
@@ -126,7 +126,7 @@ thermal_hwmon_lookup_temp(const struct thermal_hwmon_device *hwmon,
 static bool thermal_zone_crit_temp_valid(struct thermal_zone_device *tz)
 {
 	int temp;
-	return tz->ops->get_crit_temp && !tz->ops->get_crit_temp(tz, &temp);
+	return tz->sensor.ops->get_crit_temp && !tz->sensor.ops->get_crit_temp(tz, &temp);
 }
 
 int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
drivers/thermal/thermal_netlink.c +4 -4
index 32fea5174cc0..b309b2412500 100644
@@ -474,10 +474,10 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)
 		enum thermal_trip_type type;
 		int temp, hyst = 0;
 
-		tz->ops->get_trip_type(tz, i, &type);
-		tz->ops->get_trip_temp(tz, i, &temp);
-		if (tz->ops->get_trip_hyst)
-			tz->ops->get_trip_hyst(tz, i, &hyst);
+		tz->sensor.ops->get_trip_type(tz, i, &type);
+		tz->sensor.ops->get_trip_temp(tz, i, &temp);
+		if (tz->sensor.ops->get_trip_hyst)
+			tz->sensor.ops->get_trip_hyst(tz, i, &hyst);
 
 		if (nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_ID, i) ||
 		    nla_put_u32(msg, THERMAL_GENL_ATTR_TZ_TRIP_TYPE, type) ||
drivers/thermal/thermal_of.c +8 -8
index ef953cba3504..d6917f1bc486 100644
@@ -395,18 +395,18 @@ thermal_zone_of_add_sensor(struct device_node *zone,
 	tz->ops = ops;
 	tz->sensor_data = data;
 
-	tzd->ops->get_temp = of_thermal_get_temp;
-	tzd->ops->get_trend = of_thermal_get_trend;
+	tzd->sensor.ops->get_temp = of_thermal_get_temp;
+	tzd->sensor.ops->get_trend = of_thermal_get_trend;
 
 	/*
 	 * The thermal zone core will calculate the window if they have set the
 	 * optional set_trips pointer.
 	 */
 	if (ops->set_trips)
-		tzd->ops->set_trips = of_thermal_set_trips;
+		tzd->sensor.ops->set_trips = of_thermal_set_trips;
 
 	if (ops->set_emul_temp)
-		tzd->ops->set_emul_temp = of_thermal_set_emul_temp;
+		tzd->sensor.ops->set_emul_temp = of_thermal_set_emul_temp;
 
 	mutex_unlock(&tzd->lock);
 
@@ -566,9 +566,9 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
 	thermal_zone_device_disable(tzd);
 
 	mutex_lock(&tzd->lock);
-	tzd->ops->get_temp = NULL;
-	tzd->ops->get_trend = NULL;
-	tzd->ops->set_emul_temp = NULL;
+	tzd->sensor.ops->get_temp = NULL;
+	tzd->sensor.ops->get_trend = NULL;
+	tzd->sensor.ops->set_emul_temp = NULL;
 
 	tz->ops = NULL;
 	tz->sensor_data = NULL;
@@ -1024,7 +1024,7 @@ static __init void of_thermal_destroy_zones(void)
 
 		thermal_zone_device_unregister(zone);
 		kfree(zone->tzp);
-		kfree(zone->ops);
+		kfree(zone->sensor.ops);
 		of_thermal_free_zone(zone->devdata);
 	}
 	of_node_put(np);
drivers/thermal/thermal_sysfs.c +20 -20
index f154bada2906..44212fa00c78 100644
@@ -82,13 +82,13 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
 	enum thermal_trip_type type;
 	int trip, result;
 
-	if (!tz->ops->get_trip_type)
+	if (!tz->sensor.ops->get_trip_type)
 		return -EPERM;
 
 	if (sscanf(attr->attr.name, "trip_point_%d_type", &trip) != 1)
 		return -EINVAL;
 
-	result = tz->ops->get_trip_type(tz, trip, &type);
+	result = tz->sensor.ops->get_trip_type(tz, trip, &type);
 	if (result)
 		return result;
 
@@ -115,7 +115,7 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
 	int temperature, hyst = 0;
 	enum thermal_trip_type type;
 
-	if (!tz->ops->set_trip_temp)
+	if (!tz->sensor.ops->set_trip_temp)
 		return -EPERM;
 
 	if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip) != 1)
@@ -124,17 +124,17 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
 	if (kstrtoint(buf, 10, &temperature))
 		return -EINVAL;
 
-	ret = tz->ops->set_trip_temp(tz, trip, temperature);
+	ret = tz->sensor.ops->set_trip_temp(tz, trip, temperature);
 	if (ret)
 		return ret;
 
-	if (tz->ops->get_trip_hyst) {
-		ret = tz->ops->get_trip_hyst(tz, trip, &hyst);
+	if (tz->sensor.ops->get_trip_hyst) {
+		ret = tz->sensor.ops->get_trip_hyst(tz, trip, &hyst);
 		if (ret)
 			return ret;
 	}
 
-	ret = tz->ops->get_trip_type(tz, trip, &type);
+	ret = tz->sensor.ops->get_trip_type(tz, trip, &type);
 	if (ret)
 		return ret;
 
@@ -153,13 +153,13 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
 	int trip, ret;
 	int temperature;
 
-	if (!tz->ops->get_trip_temp)
+	if (!tz->sensor.ops->get_trip_temp)
 		return -EPERM;
 
 	if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip) != 1)
 		return -EINVAL;
 
-	ret = tz->ops->get_trip_temp(tz, trip, &temperature);
+	ret = tz->sensor.ops->get_trip_temp(tz, trip, &temperature);
 
 	if (ret)
 		return ret;
@@ -175,7 +175,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
 	int trip, ret;
 	int temperature;
 
-	if (!tz->ops->set_trip_hyst)
+	if (!tz->sensor.ops->set_trip_hyst)
 		return -EPERM;
 
 	if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip) != 1)
@@ -189,7 +189,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
 	 * here. The driver implementing 'set_trip_hyst' has to
 	 * take care of this.
 	 */
-	ret = tz->ops->set_trip_hyst(tz, trip, temperature);
+	ret = tz->sensor.ops->set_trip_hyst(tz, trip, temperature);
 
 	if (!ret)
 		thermal_zone_set_trips(tz);
@@ -205,13 +205,13 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
 	int trip, ret;
 	int temperature;
 
-	if (!tz->ops->get_trip_hyst)
+	if (!tz->sensor.ops->get_trip_hyst)
 		return -EPERM;
 
 	if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip) != 1)
 		return -EINVAL;
 
-	ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
+	ret = tz->sensor.ops->get_trip_hyst(tz, trip, &temperature);
 
 	return ret ? ret : sprintf(buf, "%d\n", temperature);
 }
@@ -260,12 +260,12 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,
 	if (kstrtoint(buf, 10, &temperature))
 		return -EINVAL;
 
-	if (!tz->ops->set_emul_temp) {
+	if (!tz->sensor.ops->set_emul_temp) {
 		mutex_lock(&tz->lock);
 		tz->emul_temperature = temperature;
 		mutex_unlock(&tz->lock);
 	} else {
-		ret = tz->ops->set_emul_temp(tz, temperature);
+		ret = tz->sensor.ops->set_emul_temp(tz, temperature);
 	}
 
 	if (!ret)
@@ -431,7 +431,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 		return -ENOMEM;
 	}
 
-	if (tz->ops->get_trip_hyst) {
+	if (tz->sensor.ops->get_trip_hyst) {
 		tz->trip_hyst_attrs = kcalloc(tz->trips,
 					      sizeof(*tz->trip_hyst_attrs),
 					      GFP_KERNEL);
@@ -446,7 +446,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 	if (!attrs) {
 		kfree(tz->trip_type_attrs);
 		kfree(tz->trip_temp_attrs);
-		if (tz->ops->get_trip_hyst)
+		if (tz->sensor.ops->get_trip_hyst)
 			kfree(tz->trip_hyst_attrs);
 		return -ENOMEM;
 	}
@@ -481,7 +481,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 		attrs[indx + tz->trips] = &tz->trip_temp_attrs[indx].attr.attr;
 
 		/* create Optional trip hyst attribute */
-		if (!tz->ops->get_trip_hyst)
+		if (!tz->sensor.ops->get_trip_hyst)
 			continue;
 		snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH,
 			 "trip_point_%d_hyst", indx);
@@ -491,7 +491,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 					tz->trip_hyst_attrs[indx].name;
 		tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO;
 		tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show;
-		if (tz->ops->set_trip_hyst) {
+		if (tz->sensor.ops->set_trip_hyst) {
 			tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR;
 			tz->trip_hyst_attrs[indx].attr.store =
 					trip_point_hyst_store;
@@ -519,7 +519,7 @@ static void destroy_trip_attrs(struct thermal_zone_device *tz)
 
 	kfree(tz->trip_type_attrs);
 	kfree(tz->trip_temp_attrs);
-	if (tz->ops->get_trip_hyst)
+	if (tz->sensor.ops->get_trip_hyst)
 		kfree(tz->trip_hyst_attrs);
 	kfree(tz->trips_attribute_group.attrs);
 }
include/linux/thermal.h +6 -1
index 991f7bc02d51..10dea654df6c 100644
@@ -80,6 +80,11 @@ struct thermal_sensor_ops {
 	void (*critical)(struct thermal_zone_device *);
 };
 
+struct thermal_sensor {
+	struct thermal_sensor_ops *ops;
+	struct device *dev;
+};
+
 struct thermal_cooling_device_ops {
 	int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
 	int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
@@ -164,7 +169,7 @@ struct thermal_zone_device {
 	int prev_low_trip;
 	int prev_high_trip;
 	atomic_t need_update;
-	struct thermal_sensor_ops *ops;
+	struct thermal_sensor sensor;
 	struct thermal_zone_params *tzp;
 	struct thermal_governor *governor;
 	void *governor_data;
Signature · 1 line
2.25.1
#15 lore raw

PATCH v2 4/14 thermal/of: Replace device node match with device node search

In reply to Daniel Lezcano

The thermal_of code builds a trip array associated with the node pointer in order to compare the trip point phandle with the list.

The thermal trip is a thermal zone property and should be moved there. If some sensors have hardcoded trip points, they should use the exported structure instead of redefining again and again their own structure and data to describe exactly the same things.

In order to move this to the thermal.h header and allow more cleanup, we need to remove the node pointer from the structure.

Instead of building storing the device node, we search directly in the device tree the corresponding node. That results in a simplification of the code and allows to move the structure to thermal.h

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_of.c | 62 ++++++++++++++++++++++++------------
 1 file changed, 42 insertions(+), 20 deletions(-)
drivers/thermal/thermal_of.c +42 -20
index d6917f1bc486..d8b4a0ad2d5f 100644
@@ -659,6 +659,35 @@ EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister);
 
 /***   functions parsing device tree nodes   ***/
 
+static int of_find_trip_id(struct device_node *np, struct device_node *trip)
+{
+	struct device_node *trips;
+	struct device_node *t;
+	int i = 0;
+
+	trips = of_get_child_by_name(np, "trips");
+	if (!trips) {
+		pr_err("Failed to find 'trips' node\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Find the trip id point associated with the cooling device map
+	 */
+	for_each_child_of_node(trips, t) {
+
+		if (t == trip)
+			goto out;
+		i++;
+	}
+
+	i = -ENXIO;
+out:	
+	of_node_put(trips);
+
+	return i;
+}
+
 /**
  * thermal_of_populate_bind_params - parse and fill cooling map data
  * @np: DT node containing a cooling-map node
@@ -674,14 +703,13 @@ EXPORT_SYMBOL_GPL(devm_thermal_zone_of_sensor_unregister);
  * Return: 0 on success, proper error code otherwise
  */
 static int thermal_of_populate_bind_params(struct device_node *np,
-					   struct __thermal_bind_params *__tbp,
-					   struct thermal_trip *trips,
-					   int ntrips)
+					   struct __thermal_bind_params *__tbp)
 {
 	struct of_phandle_args cooling_spec;
 	struct __thermal_cooling_bind_param *__tcbp;
 	struct device_node *trip;
 	int ret, i, count;
+	int trip_id;
 	u32 prop;
 
 	/* Default weight. Usage is optional */
@@ -696,18 +724,14 @@ static int thermal_of_populate_bind_params(struct device_node *np,
 		return -ENODEV;
 	}
 
-	/* match using device_node */
-	for (i = 0; i < ntrips; i++)
-		if (trip == trips[i].np) {
-			__tbp->trip_id = i;
-			break;
-		}
-
-	if (i == ntrips) {
-		ret = -ENODEV;
+	trip_id = of_find_trip_id(np, trip);
+	if (trip_id < 0) {
+		ret = trip_id;
 		goto end;
 	}
 
+	__tbp->trip_id = trip_id;
+	
 	count = of_count_phandle_with_args(np, "cooling-device",
 					   "#cooling-cells");
 	if (count <= 0) {
@@ -856,6 +880,7 @@ static struct __thermal_zone
 __init *thermal_of_build_thermal_zone(struct device_node *np)
 {
 	struct device_node *child = NULL, *gchild;
+	struct device_node *trips;
 	struct __thermal_zone *tz;
 	int ret, i;
 	u32 prop, coef[2];
@@ -898,13 +923,13 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
 	}
 
 	/* trips */
-	child = of_get_child_by_name(np, "trips");
+	trips = of_get_child_by_name(np, "trips");
 
 	/* No trips provided */
-	if (!child)
+	if (!trips)
 		goto finish;
 
-	tz->ntrips = of_get_child_count(child);
+	tz->ntrips = of_get_child_count(trips);
 	if (tz->ntrips == 0) /* must have at least one child */
 		goto finish;
 
@@ -915,14 +940,12 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
 	}
 
 	i = 0;
-	for_each_child_of_node(child, gchild) {
+	for_each_child_of_node(trips, gchild) {
 		ret = thermal_of_populate_trip(gchild, &tz->trips[i++]);
 		if (ret)
 			goto free_trips;
 	}
 
-	of_node_put(child);
-
 	/* cooling-maps */
 	child = of_get_child_by_name(np, "cooling-maps");
 
@@ -942,8 +965,7 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
 
 	i = 0;
 	for_each_child_of_node(child, gchild) {
-		ret = thermal_of_populate_bind_params(gchild, &tz->tbps[i++],
-						      tz->trips, tz->ntrips);
+		ret = thermal_of_populate_bind_params(gchild, &tz->tbps[i++]);
 		if (ret)
 			goto free_tbps;
 	}
Signature · 1 line
2.25.1
#16 lore raw

PATCH v2 5/14 thermal/of: Remove the device node pointer for thermal_trip

In reply to Daniel Lezcano

The device node pointer is no longer needed in the thermal trip structure, remove it.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]> Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_core.h | 2 --
 drivers/thermal/thermal_of.c   | 8 --------
 2 files changed, 10 deletions(-)
drivers/thermal/thermal_core.h +0 -2
index 726e327b4205..ff10cdda056c 100644
@@ -70,13 +70,11 @@ void __thermal_cdev_update(struct thermal_cooling_device *cdev);
 
 /**
  * struct thermal_trip - representation of a point in temperature domain
- * @np: pointer to struct device_node that this trip point was created from
  * @temperature: temperature value in miliCelsius
  * @hysteresis: relative hysteresis in miliCelsius
  * @type: trip point type
  */
 struct thermal_trip {
-	struct device_node *np;
 	int temperature;
 	int hysteresis;
 	enum thermal_trip_type type;
drivers/thermal/thermal_of.c +0 -8
index d8b4a0ad2d5f..a8a3cb309822 100644
@@ -855,10 +855,6 @@ static int thermal_of_populate_trip(struct device_node *np,
 		return ret;
 	}
 
-	/* Required for cooling map matching */
-	trip->np = np;
-	of_node_get(np);
-
 	return 0;
 }
 
@@ -988,8 +984,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
 
 	kfree(tz->tbps);
 free_trips:
-	for (i = 0; i < tz->ntrips; i++)
-		of_node_put(tz->trips[i].np);
 	kfree(tz->trips);
 	of_node_put(gchild);
 free_tz:
@@ -1014,8 +1008,6 @@ static __init void of_thermal_free_zone(struct __thermal_zone *tz)
 	}
 
 	kfree(tz->tbps);
-	for (i = 0; i < tz->ntrips; i++)
-		of_node_put(tz->trips[i].np);
 	kfree(tz->trips);
 	kfree(tz);
 }
Signature · 1 line
2.25.1
#17 lore raw

PATCH v2 6/14 thermal/of: Move thermal_trip structure to thermal.h

In reply to Daniel Lezcano

The structure thermal_trip is now generic and will be usable by the different sensor drivers in place of their own structure.

Move its definition to thermal.h to make it accessible.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_core.h | 12 ------------
 include/linux/thermal.h        | 12 ++++++++++++
 2 files changed, 12 insertions(+), 12 deletions(-)
drivers/thermal/thermal_core.h +0 -12
index ff10cdda056c..60844e2d59bb 100644
@@ -68,18 +68,6 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
 void thermal_cdev_update(struct thermal_cooling_device *);
 void __thermal_cdev_update(struct thermal_cooling_device *cdev);
 
-/**
- * struct thermal_trip - representation of a point in temperature domain
- * @temperature: temperature value in miliCelsius
- * @hysteresis: relative hysteresis in miliCelsius
- * @type: trip point type
- */
-struct thermal_trip {
-	int temperature;
-	int hysteresis;
-	enum thermal_trip_type type;
-};
-
 int get_tz_trend(struct thermal_zone_device *tz, int trip);
 
 struct thermal_instance *
include/linux/thermal.h +12 -0
index 10dea654df6c..0b99b7707928 100644
@@ -80,6 +80,18 @@ struct thermal_sensor_ops {
 	void (*critical)(struct thermal_zone_device *);
 };
 
+/**
+ * struct thermal_trip - representation of a point in temperature domain
+ * @temperature: temperature value in miliCelsius
+ * @hysteresis: relative hysteresis in miliCelsius
+ * @type: trip point type
+ */
+struct thermal_trip {
+	int temperature;
+	int hysteresis;
+	enum thermal_trip_type type;
+};
+
 struct thermal_sensor {
 	struct thermal_sensor_ops *ops;
 	struct device *dev;
Signature · 1 line
2.25.1
#13 lore raw

PATCH v2 3/14 thermal/core: Remove duplicate information when an error occurs

In reply to Daniel Lezcano

The pr_err already tells it is an error, it is pointless to add the 'Error:' string in the messages. Remove them.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/thermal_core.c +4 -4
index 1a405854748a..dc5a03d51f5c 100644
@@ -1197,23 +1197,23 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 	struct thermal_governor *governor;
 
 	if (!type || strlen(type) == 0) {
-		pr_err("Error: No thermal zone type defined\n");
+		pr_err("No thermal zone type defined\n");
 		return ERR_PTR(-EINVAL);
 	}
 
 	if (type && strlen(type) >= THERMAL_NAME_LENGTH) {
-		pr_err("Error: Thermal zone name (%s) too long, should be under %d chars\n",
+		pr_err("Thermal zone name (%s) too long, should be under %d chars\n",
 		       type, THERMAL_NAME_LENGTH);
 		return ERR_PTR(-EINVAL);
 	}
 
 	if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) {
-		pr_err("Error: Incorrect number of thermal trips\n");
+		pr_err("Incorrect number of thermal trips\n");
 		return ERR_PTR(-EINVAL);
 	}
 
 	if (!ops) {
-		pr_err("Error: Thermal zone device ops not defined\n");
+		pr_err("Thermal zone device ops not defined\n");
 		return ERR_PTR(-EINVAL);
 	}
 
Signature · 1 line
2.25.1
#19 lore raw

PATCH v2 8/14 thermal/core: Move thermal_set_delay_jiffies to static

In reply to Daniel Lezcano

The function 'thermal_set_delay_jiffies' is only used in thermal_core.c but it is defined and implemented in a separate file. Move the function to thermal_core.c and make it static.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_core.c    | 7 +++++++
 drivers/thermal/thermal_core.h    | 1 -
 drivers/thermal/thermal_helpers.c | 7 -------
 3 files changed, 7 insertions(+), 8 deletions(-)
drivers/thermal/thermal_core.c +7 -0
index dc5a03d51f5c..386453d46e94 100644
@@ -1158,6 +1158,13 @@ static void bind_tz(struct thermal_zone_device *tz)
 	mutex_unlock(&thermal_list_lock);
 }
 
+static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms)
+{
+	*delay_jiffies = msecs_to_jiffies(delay_ms);
+	if (delay_ms > 1000)
+		*delay_jiffies = round_jiffies(*delay_jiffies);
+}
+
 /**
  * thermal_zone_device_register() - register a new thermal zone device
  * @type:	the thermal zone device type
drivers/thermal/thermal_core.h +0 -1
index 60844e2d59bb..c991bb290512 100644
@@ -112,7 +112,6 @@ int thermal_build_list_of_policies(char *buf);
 
 /* Helpers */
 void thermal_zone_set_trips(struct thermal_zone_device *tz);
-void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms);
 
 /* sysfs I/F */
 int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
drivers/thermal/thermal_helpers.c +0 -7
index beb97cd6b799..3c7aa31686ad 100644
@@ -174,13 +174,6 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz)
 	mutex_unlock(&tz->lock);
 }
 
-void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms)
-{
-	*delay_jiffies = msecs_to_jiffies(delay_ms);
-	if (delay_ms > 1000)
-		*delay_jiffies = round_jiffies(*delay_jiffies);
-}
-
 static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
 				       int target)
 {
Signature · 1 line
2.25.1
#20 lore raw

PATCH v2 9/14 thermal/core: Rename trips to ntrips

In reply to Daniel Lezcano

In order to use thermal trips defined in the thermal structure, rename the 'trips' field to 'ntrips' to have the 'trips' field containing the thermal trip points.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/gov_fair_share.c        |  6 +++---
 drivers/thermal/gov_power_allocator.c   |  4 ++--
 drivers/thermal/tegra/tegra30-tsensor.c |  2 +-
 drivers/thermal/thermal_core.c          | 20 ++++++++++----------
 drivers/thermal/thermal_helpers.c       |  4 ++--
 drivers/thermal/thermal_netlink.c       |  2 +-
 drivers/thermal/thermal_sysfs.c         | 22 +++++++++++-----------
 include/linux/thermal.h                 |  2 +-
 8 files changed, 31 insertions(+), 31 deletions(-)
drivers/thermal/gov_fair_share.c +3 -3
index a157c621da59..a5d95a69b033 100644
@@ -25,10 +25,10 @@ static int get_trip_level(struct thermal_zone_device *tz)
 	int trip_temp;
 	enum thermal_trip_type trip_type;
 
-	if (tz->trips == 0 || !tz->sensor.ops->get_trip_temp)
+	if (tz->ntrips == 0 || !tz->sensor.ops->get_trip_temp)
 		return 0;
 
-	for (count = 0; count < tz->trips; count++) {
+	for (count = 0; count < tz->ntrips; count++) {
 		tz->sensor.ops->get_trip_temp(tz, count, &trip_temp);
 		if (tz->temperature < trip_temp)
 			break;
@@ -53,7 +53,7 @@ static long get_target_state(struct thermal_zone_device *tz,
 
 	cdev->ops->get_max_state(cdev, &max_state);
 
-	return (long)(percentage * level * max_state) / (100 * tz->trips);
+	return (long)(percentage * level * max_state) / (100 * tz->ntrips);
 }
 
 /**
drivers/thermal/gov_power_allocator.c +2 -2
index bcd146175f84..86d0e6cc4b6a 100644
@@ -527,7 +527,7 @@ static void get_governor_trips(struct thermal_zone_device *tz,
 	last_active = INVALID_TRIP;
 	last_passive = INVALID_TRIP;
 
-	for (i = 0; i < tz->trips; i++) {
+	for (i = 0; i < tz->ntrips; i++) {
 		enum thermal_trip_type type;
 		int ret;
 
@@ -668,7 +668,7 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
 
 	get_governor_trips(tz, params);
 
-	if (tz->trips > 0) {
+	if (tz->ntrips > 0) {
 		ret = tz->sensor.ops->get_trip_temp(tz,
 						    params->trip_max_desired_temperature,
 						    &control_temp);
drivers/thermal/tegra/tegra30-tsensor.c +1 -1
index fab2709569c1..308646e0d8be 100644
@@ -316,7 +316,7 @@ static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd,
 	*hot_trip  = 85000;
 	*crit_trip = 90000;
 
-	for (i = 0; i < tzd->trips; i++) {
+	for (i = 0; i < tzd->ntrips; i++) {
 		enum thermal_trip_type type;
 		int trip_temp;
 
drivers/thermal/thermal_core.c +10 -10
index 386453d46e94..f898032ec23a 100644
@@ -505,7 +505,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz,
 
 	tz->notify_event = event;
 
-	for (count = 0; count < tz->trips; count++)
+	for (count = 0; count < tz->ntrips; count++)
 		handle_thermal_trip(tz, count);
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_update);
@@ -630,7 +630,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 	unsigned long max_state;
 	int result, ret;
 
-	if (trip >= tz->trips || trip < 0)
+	if (trip >= tz->ntrips || trip < 0)
 		return -EINVAL;
 
 	list_for_each_entry(pos1, &thermal_tz_list, node) {
@@ -811,7 +811,7 @@ static void __bind(struct thermal_zone_device *tz, int mask,
 {
 	int i, ret;
 
-	for (i = 0; i < tz->trips; i++) {
+	for (i = 0; i < tz->ntrips; i++) {
 		if (mask & (1 << i)) {
 			unsigned long upper, lower;
 
@@ -1056,7 +1056,7 @@ static void __unbind(struct thermal_zone_device *tz, int mask,
 {
 	int i;
 
-	for (i = 0; i < tz->trips; i++)
+	for (i = 0; i < tz->ntrips; i++)
 		if (mask & (1 << i))
 			thermal_zone_unbind_cooling_device(tz, i, cdev);
 }
@@ -1168,7 +1168,7 @@ static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms
 /**
  * thermal_zone_device_register() - register a new thermal zone device
  * @type:	the thermal zone device type
- * @trips:	the number of trip points the thermal zone support
+ * @ntrips:	the number of trip points the thermal zone support
  * @mask:	a bit string indicating the writeablility of trip points
  * @devdata:	private device data
  * @ops:	standard thermal zone device callbacks
@@ -1190,7 +1190,7 @@ static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms
  * IS_ERR*() helpers.
  */
 struct thermal_zone_device *
-thermal_zone_device_register(const char *type, int trips, int mask,
+thermal_zone_device_register(const char *type, int ntrips, int mask,
 			     void *devdata, struct thermal_sensor_ops *ops,
 			     struct thermal_zone_params *tzp, int passive_delay,
 			     int polling_delay)
@@ -1214,7 +1214,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 		return ERR_PTR(-EINVAL);
 	}
 
-	if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) {
+	if (ntrips > THERMAL_MAX_TRIPS || ntrips < 0 || mask >> ntrips) {
 		pr_err("Incorrect number of thermal trips\n");
 		return ERR_PTR(-EINVAL);
 	}
@@ -1224,7 +1224,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 		return ERR_PTR(-EINVAL);
 	}
 
-	if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp))
+	if (ntrips > 0 && (!ops->get_trip_type || !ops->get_trip_temp))
 		return ERR_PTR(-EINVAL);
 
 	tz = kzalloc(sizeof(*tz), GFP_KERNEL);
@@ -1254,7 +1254,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 	tz->tzp = tzp;
 	tz->device.class = &thermal_class;
 	tz->devdata = devdata;
-	tz->trips = trips;
+	tz->ntrips = ntrips;
 
 	thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
 	thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);
@@ -1272,7 +1272,7 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 	if (result)
 		goto release_device;
 
-	for (count = 0; count < trips; count++) {
+	for (count = 0; count < ntrips; count++) {
 		if (tz->sensor.ops->get_trip_type(tz, count, &trip_type) ||
 		    tz->sensor.ops->get_trip_temp(tz, count, &trip_temp) ||
 		    !trip_temp)
drivers/thermal/thermal_helpers.c +2 -2
index 3c7aa31686ad..50ca221367f7 100644
@@ -89,7 +89,7 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
 	ret = tz->sensor.ops->get_temp(tz, temp);
 
 	if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
-		for (count = 0; count < tz->trips; count++) {
+		for (count = 0; count < tz->ntrips; count++) {
 			ret = tz->sensor.ops->get_trip_type(tz, count, &type);
 			if (!ret && type == THERMAL_TRIP_CRITICAL) {
 				ret = tz->sensor.ops->get_trip_temp(tz, count,
@@ -137,7 +137,7 @@ void thermal_zone_set_trips(struct thermal_zone_device *tz)
 	if (!tz->sensor.ops->set_trips || !tz->sensor.ops->get_trip_hyst)
 		goto exit;
 
-	for (i = 0; i < tz->trips; i++) {
+	for (i = 0; i < tz->ntrips; i++) {
 		int trip_low;
 
 		tz->sensor.ops->get_trip_temp(tz, i, &trip_temp);
drivers/thermal/thermal_netlink.c +1 -1
index b309b2412500..1639fa5c92bb 100644
@@ -469,7 +469,7 @@ static int thermal_genl_cmd_tz_get_trip(struct param *p)
 
 	mutex_lock(&tz->lock);
 
-	for (i = 0; i < tz->trips; i++) {
+	for (i = 0; i < tz->ntrips; i++) {
 
 		enum thermal_trip_type type;
 		int temp, hyst = 0;
drivers/thermal/thermal_sysfs.c +11 -11
index 44212fa00c78..fd1207201c48 100644
@@ -416,15 +416,15 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 	int indx;
 
 	/* This function works only for zones with at least one trip */
-	if (tz->trips <= 0)
+	if (tz->ntrips <= 0)
 		return -EINVAL;
 
-	tz->trip_type_attrs = kcalloc(tz->trips, sizeof(*tz->trip_type_attrs),
+	tz->trip_type_attrs = kcalloc(tz->ntrips, sizeof(*tz->trip_type_attrs),
 				      GFP_KERNEL);
 	if (!tz->trip_type_attrs)
 		return -ENOMEM;
 
-	tz->trip_temp_attrs = kcalloc(tz->trips, sizeof(*tz->trip_temp_attrs),
+	tz->trip_temp_attrs = kcalloc(tz->ntrips, sizeof(*tz->trip_temp_attrs),
 				      GFP_KERNEL);
 	if (!tz->trip_temp_attrs) {
 		kfree(tz->trip_type_attrs);
@@ -432,7 +432,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 	}
 
 	if (tz->sensor.ops->get_trip_hyst) {
-		tz->trip_hyst_attrs = kcalloc(tz->trips,
+		tz->trip_hyst_attrs = kcalloc(tz->ntrips,
 					      sizeof(*tz->trip_hyst_attrs),
 					      GFP_KERNEL);
 		if (!tz->trip_hyst_attrs) {
@@ -442,7 +442,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 		}
 	}
 
-	attrs = kcalloc(tz->trips * 3 + 1, sizeof(*attrs), GFP_KERNEL);
+	attrs = kcalloc(tz->ntrips * 3 + 1, sizeof(*attrs), GFP_KERNEL);
 	if (!attrs) {
 		kfree(tz->trip_type_attrs);
 		kfree(tz->trip_temp_attrs);
@@ -451,7 +451,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 		return -ENOMEM;
 	}
 
-	for (indx = 0; indx < tz->trips; indx++) {
+	for (indx = 0; indx < tz->ntrips; indx++) {
 		/* create trip type attribute */
 		snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
 			 "trip_point_%d_type", indx);
@@ -478,7 +478,7 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 			tz->trip_temp_attrs[indx].attr.store =
 							trip_point_temp_store;
 		}
-		attrs[indx + tz->trips] = &tz->trip_temp_attrs[indx].attr.attr;
+		attrs[indx + tz->ntrips] = &tz->trip_temp_attrs[indx].attr.attr;
 
 		/* create Optional trip hyst attribute */
 		if (!tz->sensor.ops->get_trip_hyst)
@@ -496,10 +496,10 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 			tz->trip_hyst_attrs[indx].attr.store =
 					trip_point_hyst_store;
 		}
-		attrs[indx + tz->trips * 2] =
+		attrs[indx + tz->ntrips * 2] =
 					&tz->trip_hyst_attrs[indx].attr.attr;
 	}
-	attrs[tz->trips * 3] = NULL;
+	attrs[tz->ntrips * 3] = NULL;
 
 	tz->trips_attribute_group.attrs = attrs;
 
@@ -540,7 +540,7 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *tz,
 	for (i = 0; i < size - 2; i++)
 		groups[i] = thermal_zone_attribute_groups[i];
 
-	if (tz->trips) {
+	if (tz->ntrips) {
 		result = create_trip_attrs(tz, mask);
 		if (result) {
 			kfree(groups);
@@ -561,7 +561,7 @@ void thermal_zone_destroy_device_groups(struct thermal_zone_device *tz)
 	if (!tz)
 		return;
 
-	if (tz->trips)
+	if (tz->ntrips)
 		destroy_trip_attrs(tz);
 
 	kfree(tz->device.groups);
include/linux/thermal.h +1 -1
index 0b99b7707928..e11c3d922c18 100644
@@ -170,7 +170,7 @@ struct thermal_zone_device {
 	struct thermal_attr *trip_hyst_attrs;
 	enum thermal_device_mode mode;
 	void *devdata;
-	int trips;
+	int ntrips;
 	unsigned long trips_disabled;	/* bitmap for disabled trips */
 	unsigned long passive_delay_jiffies;
 	unsigned long polling_delay_jiffies;
Signature · 1 line
2.25.1
#18 lore raw

PATCH v2 7/14 thermal/core: Remove unneeded EXPORT_SYMBOLS

In reply to Daniel Lezcano

Different functions are exporting the symbols but are actually only used by the thermal framework internals. Remove these EXPORT_SYMBOLS.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_helpers.c | 2 --
 1 file changed, 2 deletions(-)
drivers/thermal/thermal_helpers.c +0 -2
index 334478fe40fa..beb97cd6b799 100644
@@ -39,7 +39,6 @@ int get_tz_trend(struct thermal_zone_device *tz, int trip)
 
 	return trend;
 }
-EXPORT_SYMBOL(get_tz_trend);
 
 struct thermal_instance *
 get_thermal_instance(struct thermal_zone_device *tz,
@@ -228,7 +227,6 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
 	}
 	mutex_unlock(&cdev->lock);
 }
-EXPORT_SYMBOL(thermal_cdev_update);
 
 /**
  * thermal_zone_get_slope - return the slope attribute of the thermal zone
Signature · 1 line
2.25.1
#21 lore raw

PATCH v2 10/14 thermal/core: Add thermal_trip in thermal_zone

In reply to Daniel Lezcano

The thermal trip points are properties of a thermal zone and the different sub systems should be able to save them in the thermal zone structure instead of having their own definition.

Give the opportunity to the drivers to create a thermal zone with thermal trips which will be accessible directly from the thermal core framework.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_core.h | 10 ++++++++++
 include/linux/thermal.h        |  1 +
 2 files changed, 11 insertions(+)
drivers/thermal/thermal_core.h +10 -0
index c991bb290512..84e341c1e0fc 100644
@@ -113,6 +113,16 @@ int thermal_build_list_of_policies(char *buf);
 /* Helpers */
 void thermal_zone_set_trips(struct thermal_zone_device *tz);
 
+static inline struct thermal_trip *thermal_zone_get_trips(struct thermal_zone *tz)
+{
+	return tz->trips;
+}
+
+static inline int thermal_zone_get_ntrips(struct thermal_zone *tz)
+{
+	return tz->ntrips;
+}
+
 /* sysfs I/F */
 int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
 void thermal_zone_destroy_device_groups(struct thermal_zone_device *);
include/linux/thermal.h +1 -0
index e11c3d922c18..a11c00062ef1 100644
@@ -184,6 +184,7 @@ struct thermal_zone_device {
 	struct thermal_sensor sensor;
 	struct thermal_zone_params *tzp;
 	struct thermal_governor *governor;
+	struct thermal_trip *trips;
 	void *governor_data;
 	struct list_head thermal_instances;
 	struct ida ida;
Signature · 1 line
2.25.1
#25 lore raw

PATCH v2 14/14 thermal/of: Initialize trip points separately

In reply to Daniel Lezcano

Self contain the trip initialization from the device tree in a single function for the sake of making the code flow more clear.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_of.c | 84 ++++++++++++++++++++++++------------
 1 file changed, 57 insertions(+), 27 deletions(-)
drivers/thermal/thermal_of.c +57 -27
index 64e5b9e92cb1..fd55e895258c 100644
@@ -681,7 +681,8 @@ static int of_find_trip_id(struct device_node *np, struct device_node *trip)
  *
  * Return: 0 on success, proper error code otherwise
  */
-static int thermal_of_populate_bind_params(struct device_node *np,
+static int thermal_of_populate_bind_params(struct device_node *tz_np,
+					   struct device_node *np,
 					   struct __thermal_bind_params *__tbp)
 {
 	struct of_phandle_args cooling_spec;
@@ -703,7 +704,7 @@ static int thermal_of_populate_bind_params(struct device_node *np,
 		return -ENODEV;
 	}
 
-	trip_id = of_find_trip_id(np, trip);
+	trip_id = of_find_trip_id(tz_np, trip);
 	if (trip_id < 0) {
 		ret = trip_id;
 		goto end;
@@ -837,6 +838,53 @@ static int thermal_of_populate_trip(struct device_node *np,
 	return 0;
 }
 
+static struct thermal_trip *thermal_of_trips_init(struct device_node *np, int *ntrips)
+{
+	struct thermal_trip *tt;
+	struct device_node *trips, *trip;
+	int ret, count;
+
+	trips = of_get_child_by_name(np, "trips");
+	if (!trips) {
+		pr_err("Failed to find 'trips' node\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	count = of_get_child_count(trips);
+	if (!count) {
+		pr_err("No trip point defined\n");
+		ret = -EINVAL;
+		goto out_of_node_put;
+	}
+
+	tt = kzalloc(sizeof(*tt) * count, GFP_KERNEL);
+	if (!tt) {
+		ret = -ENOMEM;
+		goto out_of_node_put;
+	}
+
+	*ntrips = count;
+
+	count = 0;
+	for_each_child_of_node(trips, trip) {
+		ret = thermal_of_populate_trip(trip, &tt[count++]);
+		if (ret)
+			goto out_kfree;
+	}
+
+	of_node_put(trips);
+	
+	return tt;
+	
+out_kfree:
+	kfree(tt);
+	*ntrips = 0;
+out_of_node_put:
+	of_node_put(trips);
+
+	return ERR_PTR(ret);
+}
+
 /**
  * thermal_of_build_thermal_zone - parse and fill one thermal zone data
  * @np: DT node containing a thermal zone node
@@ -855,7 +903,6 @@ static struct __thermal_zone
 __init *thermal_of_build_thermal_zone(struct device_node *np)
 {
 	struct device_node *child = NULL, *gchild;
-	struct device_node *trips;
 	struct __thermal_zone *tz;
 	int ret, i;
 	u32 prop, coef[2];
@@ -897,28 +944,10 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
 		tz->offset = 0;
 	}
 
-	/* trips */
-	trips = of_get_child_by_name(np, "trips");
-
-	/* No trips provided */
-	if (!trips)
-		goto finish;
-
-	tz->ntrips = of_get_child_count(trips);
-	if (tz->ntrips == 0) /* must have at least one child */
+	tz->trips = thermal_of_trips_init(np, &tz->ntrips);
+	if (IS_ERR(tz->trips)) {
+		ret = PTR_ERR(tz->trips);
 		goto finish;
-
-	tz->trips = kcalloc(tz->ntrips, sizeof(*tz->trips), GFP_KERNEL);
-	if (!tz->trips) {
-		ret = -ENOMEM;
-		goto free_tz;
-	}
-
-	i = 0;
-	for_each_child_of_node(trips, gchild) {
-		ret = thermal_of_populate_trip(gchild, &tz->trips[i++]);
-		if (ret)
-			goto free_trips;
 	}
 
 	/* cooling-maps */
@@ -940,9 +969,11 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
 
 	i = 0;
 	for_each_child_of_node(child, gchild) {
-		ret = thermal_of_populate_bind_params(gchild, &tz->tbps[i++]);
-		if (ret)
+		ret = thermal_of_populate_bind_params(np, gchild, &tz->tbps[i++]);
+		if (ret) {
+			of_node_put(gchild);
 			goto free_tbps;
+		}
 	}
 
 finish:
@@ -964,7 +995,6 @@ __init *thermal_of_build_thermal_zone(struct device_node *np)
 	kfree(tz->tbps);
 free_trips:
 	kfree(tz->trips);
-	of_node_put(gchild);
 free_tz:
 	kfree(tz);
 	of_node_put(child);
Signature · 1 line
2.25.1
#23 lore raw

PATCH v2 12/14 thermal/of: Store the trips in the thermal zone

In reply to Daniel Lezcano

As the thermal zone contains the trip point, we can store them directly in the when registering the thermal zone. That will allow another step forward to remove the duplicate thermal zone structure we find in the thermal_of code.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_of.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/thermal/thermal_of.c +3 -5
index a8a3cb309822..200d1d784211 100644
@@ -1105,11 +1105,9 @@ int __init of_parse_thermal_zones(void)
 		tzp->slope = tz->slope;
 		tzp->offset = tz->offset;
 
-		zone = thermal_zone_device_register(child->name, tz->ntrips,
-						    mask, tz,
-						    ops, tzp,
-						    tz->passive_delay,
-						    tz->polling_delay);
+		zone = thermal_zone_device_register_with_trips(child->name, tz->trips, tz->ntrips,
+							       mask, tz, ops, tzp, tz->passive_delay,
+							       tz->polling_delay);
 		if (IS_ERR(zone)) {
 			pr_err("Failed to build %pOFn zone %ld\n", child,
 			       PTR_ERR(zone));
Signature · 1 line
2.25.1
#22 lore raw

PATCH v2 11/14 thermal/core: Register with the trip points

In reply to Daniel Lezcano

As we added the thermal trip points structure in the thermal zone, let's extend the thermal zone register function to have the thermal trip structures as a parameter and store it in the 'trips' field of the thermal zone structure.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_core.c | 23 ++++++++++++++++++-----
 drivers/thermal/thermal_core.h |  4 ++--
 include/linux/thermal.h        |  6 ++++++
 3 files changed, 26 insertions(+), 7 deletions(-)
drivers/thermal/thermal_core.c +18 -5
index f898032ec23a..a0317be48b0c 100644
@@ -1166,8 +1166,9 @@ static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms
 }
 
 /**
- * thermal_zone_device_register() - register a new thermal zone device
+ * thermal_zone_device_register_with_trips() - register a new thermal zone device
  * @type:	the thermal zone device type
+ * @trips:	a pointer to an array of thermal trips
  * @ntrips:	the number of trip points the thermal zone support
  * @mask:	a bit string indicating the writeablility of trip points
  * @devdata:	private device data
@@ -1190,10 +1191,11 @@ static void thermal_set_delay_jiffies(unsigned long *delay_jiffies, int delay_ms
  * IS_ERR*() helpers.
  */
 struct thermal_zone_device *
-thermal_zone_device_register(const char *type, int ntrips, int mask,
-			     void *devdata, struct thermal_sensor_ops *ops,
-			     struct thermal_zone_params *tzp, int passive_delay,
-			     int polling_delay)
+thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *trips,
+					int ntrips, int mask,
+					void *devdata, struct thermal_sensor_ops *ops,
+					struct thermal_zone_params *tzp, int passive_delay,
+					int polling_delay)
 {
 	struct thermal_zone_device *tz;
 	enum thermal_trip_type trip_type;
@@ -1255,6 +1257,7 @@ thermal_zone_device_register(const char *type, int ntrips, int mask,
 	tz->device.class = &thermal_class;
 	tz->devdata = devdata;
 	tz->ntrips = ntrips;
+	tz->trips = trips;
 
 	thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
 	thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);
@@ -1330,6 +1333,16 @@ thermal_zone_device_register(const char *type, int ntrips, int mask,
 	kfree(tz);
 	return ERR_PTR(result);
 }
+
+struct thermal_zone_device *thermal_zone_device_register(const char *type, int ntrips, int mask,
+							 void *devdata, struct thermal_sensor_ops *ops,
+							 struct thermal_zone_params *tzp, int passive_delay,
+							 int polling_delay)
+{
+	return thermal_zone_device_register_with_trips(type, NULL, ntrips, mask,
+						       devdata, ops, tzp,
+						       passive_delay, polling_delay);
+}
 EXPORT_SYMBOL_GPL(thermal_zone_device_register);
 
 /**
drivers/thermal/thermal_core.h +2 -2
index 84e341c1e0fc..bbe3ec26d12e 100644
@@ -113,12 +113,12 @@ int thermal_build_list_of_policies(char *buf);
 /* Helpers */
 void thermal_zone_set_trips(struct thermal_zone_device *tz);
 
-static inline struct thermal_trip *thermal_zone_get_trips(struct thermal_zone *tz)
+static inline struct thermal_trip *thermal_zone_get_trips(struct thermal_zone_device *tz)
 {
 	return tz->trips;
 }
 
-static inline int thermal_zone_get_ntrips(struct thermal_zone *tz)
+static inline int thermal_zone_get_ntrips(struct thermal_zone_device *tz)
 {
 	return tz->ntrips;
 }
include/linux/thermal.h +6 -0
index a11c00062ef1..8c4bc6d1de97 100644
@@ -381,8 +381,14 @@ void devm_thermal_zone_of_sensor_unregister(struct device *dev,
 struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
 		void *, struct thermal_sensor_ops *,
 		struct thermal_zone_params *, int, int);
+
 void thermal_zone_device_unregister(struct thermal_zone_device *);
 
+struct thermal_zone_device *
+thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int, int,
+					void *, struct thermal_sensor_ops *,
+					struct thermal_zone_params *, int, int);
+
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
 				     struct thermal_cooling_device *,
 				     unsigned long, unsigned long,
Signature · 1 line
2.25.1
#24 lore raw

PATCH v2 13/14 thermal/of: Use thermal trips stored in the thermal zone

In reply to Daniel Lezcano

Now that we have the thermal trip stored in the thermal zone in a generic way, we can rely on them and remove one indirection we found in the thermal_of code and do one more step forward the removal of the duplicated structures.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_of.c | 53 +++++++++++-------------------------
 1 file changed, 16 insertions(+), 37 deletions(-)
drivers/thermal/thermal_of.c +16 -37
index 200d1d784211..64e5b9e92cb1 100644
@@ -118,12 +118,7 @@ static int of_thermal_set_trips(struct thermal_zone_device *tz,
  */
 int of_thermal_get_ntrips(struct thermal_zone_device *tz)
 {
-	struct __thermal_zone *data = tz->devdata;
-
-	if (!data || IS_ERR(data))
-		return -ENODEV;
-
-	return data->ntrips;
+	return tz->ntrips;
 }
 EXPORT_SYMBOL_GPL(of_thermal_get_ntrips);
 
@@ -139,9 +134,7 @@ EXPORT_SYMBOL_GPL(of_thermal_get_ntrips);
  */
 bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, int trip)
 {
-	struct __thermal_zone *data = tz->devdata;
-
-	if (!data || trip >= data->ntrips || trip < 0)
+	if (trip >= tz->ntrips || trip < 0)
 		return false;
 
 	return true;
@@ -161,12 +154,7 @@ EXPORT_SYMBOL_GPL(of_thermal_is_trip_valid);
 const struct thermal_trip *
 of_thermal_get_trip_points(struct thermal_zone_device *tz)
 {
-	struct __thermal_zone *data = tz->devdata;
-
-	if (!data)
-		return NULL;
-
-	return data->trips;
+	return tz->trips;
 }
 EXPORT_SYMBOL_GPL(of_thermal_get_trip_points);
 
@@ -273,12 +261,10 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal,
 static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip,
 				    enum thermal_trip_type *type)
 {
-	struct __thermal_zone *data = tz->devdata;
-
-	if (trip >= data->ntrips || trip < 0)
+	if (trip >= tz->ntrips || trip < 0)
 		return -EDOM;
 
-	*type = data->trips[trip].type;
+	*type = tz->trips[trip].type;
 
 	return 0;
 }
@@ -286,12 +272,10 @@ static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip,
 static int of_thermal_get_trip_temp(struct thermal_zone_device *tz, int trip,
 				    int *temp)
 {
-	struct __thermal_zone *data = tz->devdata;
-
-	if (trip >= data->ntrips || trip < 0)
+	if (trip >= tz->ntrips || trip < 0)
 		return -EDOM;
 
-	*temp = data->trips[trip].temperature;
+	*temp = tz->trips[trip].temperature;
 
 	return 0;
 }
@@ -301,7 +285,7 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip,
 {
 	struct __thermal_zone *data = tz->devdata;
 
-	if (trip >= data->ntrips || trip < 0)
+	if (trip >= tz->ntrips || trip < 0)
 		return -EDOM;
 
 	if (data->ops && data->ops->set_trip_temp) {
@@ -313,7 +297,7 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip,
 	}
 
 	/* thermal framework should take care of data->mask & (1 << trip) */
-	data->trips[trip].temperature = temp;
+	tz->trips[trip].temperature = temp;
 
 	return 0;
 }
@@ -321,12 +305,10 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip,
 static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip,
 				    int *hyst)
 {
-	struct __thermal_zone *data = tz->devdata;
-
-	if (trip >= data->ntrips || trip < 0)
+	if (trip >= tz->ntrips || trip < 0)
 		return -EDOM;
 
-	*hyst = data->trips[trip].hysteresis;
+	*hyst = tz->trips[trip].hysteresis;
 
 	return 0;
 }
@@ -334,13 +316,11 @@ static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip,
 static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip,
 				    int hyst)
 {
-	struct __thermal_zone *data = tz->devdata;
-
-	if (trip >= data->ntrips || trip < 0)
+	if (trip >= tz->ntrips || trip < 0)
 		return -EDOM;
 
 	/* thermal framework should take care of data->mask & (1 << trip) */
-	data->trips[trip].hysteresis = hyst;
+	tz->trips[trip].hysteresis = hyst;
 
 	return 0;
 }
@@ -348,12 +328,11 @@ static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip,
 static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
 				    int *temp)
 {
-	struct __thermal_zone *data = tz->devdata;
 	int i;
 
-	for (i = 0; i < data->ntrips; i++)
-		if (data->trips[i].type == THERMAL_TRIP_CRITICAL) {
-			*temp = data->trips[i].temperature;
+	for (i = 0; i < tz->ntrips; i++)
+		if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) {
+			*temp = tz->trips[i].temperature;
 			return 0;
 		}
 
Signature · 1 line
2.25.1
Acked-by on v2 1/14
#2 lore raw

Re: [PATCH v2 01/14] thermal/core: Change thermal_zone_ops to thermal_sensor_ops

In reply to Daniel Lezcano
Quoted 8 lines · Daniel Lezcano

A thermal zone is software abstraction of a sensor associated with properties and cooling devices if any.

The fact that we have thermal_zone and thermal_zone_ops mixed is confusing and does not clearly identify the different components entering in the thermal management process. A thermal zone appears to be a sensor while it is not.

Quoted 4 lines

In order to set the scene for multiple thermal sensors aggregated into a single thermal zone. Rename the thermal_zone_ops to thermal_sensor_ops, that will appear clearyl the thermal zone is not a sensor but an abstraction of one [or multiple] sensor(s).

for whatever drivers in this series I have somehow been involved into.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Acked-by on v2 2/14
#11 lore raw

Re: [PATCH v2 02/14] thermal/core: Add a thermal sensor structure in the thermal zone

In reply to Daniel Lezcano
Quoted 10 lines · Daniel Lezcano

The thermal sensor ops is directly defined in the thermal zone but still its data structuration makes the sensor ops and the thermal zone too much interconnected for multiple sensors per thermal zone.

Create a dedicated structure for the thermal sensor to be included in the thermal zone structure so these components are clearly separated.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

You have a ';' typo here.

Quoted 9 lines
---
 drivers/thermal/broadcom/bcm2835_thermal.c |  2 +-
 drivers/thermal/gov_bang_bang.c            |  6 +--
 drivers/thermal/gov_fair_share.c           |  6 +--
 drivers/thermal/gov_power_allocator.c      | 18 ++++----
 drivers/thermal/gov_step_wise.c            |  4 +-
 drivers/thermal/rcar_gen3_thermal.c        |  6 +--
 drivers/thermal/samsung/exynos_tmu.c       |  6 +--

For Samsung:

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by on v2 1/14
#3 lore raw

Re: [PATCH v2 01/14] thermal/core: Change thermal_zone_ops to thermal_sensor_ops

In reply to Daniel Lezcano

Hi Daniel,

Thanks for your patch!

Quoted 11 lines · Daniel Lezcano

A thermal zone is software abstraction of a sensor associated with properties and cooling devices if any.

The fact that we have thermal_zone and thermal_zone_ops mixed is confusing and does not clearly identify the different components entering in the thermal management process. A thermal zone appears to be a sensor while it is not.

In order to set the scene for multiple thermal sensors aggregated into a single thermal zone. Rename the thermal_zone_ops to thermal_sensor_ops, that will appear clearyl the thermal zone is not a

to make it clear

Quoted 8 lines

sensor but an abstraction of one [or multiple] sensor(s).

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

 drivers/thermal/rcar_thermal.c                            | 4 ++--

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by on v2 2/14
#12 lore raw

Re: [PATCH v2 02/14] thermal/core: Add a thermal sensor structure in the thermal zone

In reply to Daniel Lezcano

Hi Daniel,

Quoted 11 lines · Daniel Lezcano

The thermal sensor ops is directly defined in the thermal zone but still its data structuration makes the sensor ops and the thermal zone too much interconnected for multiple sensors per thermal zone.

Create a dedicated structure for the thermal sensor to be included in the thermal zone structure so these components are clearly separated.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

Thanks for your patch!

Quoted 1 line
 drivers/thermal/rcar_gen3_thermal.c        |  6 +--

include/linux/thermal.h struct thermal_sensor_ops { · line 85

Quoted 9 lines
include/linux/thermal.h +3 -0
@@ -80,6 +80,11 @@ struct thermal_sensor_ops {
        void (*critical)(struct thermal_zone_device *);
 };
 
+struct thermal_sensor {
+       struct thermal_sensor_ops *ops;
+       struct device *dev;

Unless I missed something, the "dev" field is unused in this series?

include/linux/thermal.h struct thermal_sensor_ops { · line 90

Quoted 5 lines
include/linux/thermal.h +2 -0
+};
+
 struct thermal_cooling_device_ops {
        int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
        int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#26 lore raw
In reply to Daniel Lezcano

Hi Rafael,

if you are ok with this series, I'll pick it up.

Is that ok ?

Quoted 94 lines · Daniel Lezcano

The thermal framework initialization with the device tree appears to be complicated and hard to make it to evolve.

It contains duplication of almost the same thermal generic structures and has an assymetric initialization making hard any kind of serious changes for more complex features. One of them is the multiple sensors support per thermal zone.

In order to set the scene for the aforementioned feature with generic code, we need to cleanup and rework the device tree initialization.

However this rework is not obvious because of the multiple components entering in the composition of a thermal zone and being initialized at different moments. For instance, a cooling device can be initialized before a sensor, so the thermal zones must exist before the cooling device as well as the sensor. This asynchonous initialization forces the thermal zone to be created with fake ops because they are mandotory and build a list of cooling devices which is used to lookup afterwards when the cooling device driver is registering itself.

As there could be a large number of changes, this first series provide some steps forward for a simpler device tree initialization.

Changelog:
- V2:
- Drop patch 1/15 which contains too many changes for a simple structure renaming. This could be addressed in a separate series as it is not necessary for the OF rework

- Fixed of_node_put with gchild not initialized as reported by kbuild and Dan Carpenter

- V1:
- Initial post

Daniel Lezcano (14):
thermal/core: Change thermal_zone_ops to thermal_sensor_ops thermal/core: Add a thermal sensor structure in the thermal zone thermal/core: Remove duplicate information when an error occurs thermal/of: Replace device node match with device node search thermal/of: Remove the device node pointer for thermal_trip thermal/of: Move thermal_trip structure to thermal.h thermal/core: Remove unneeded EXPORT_SYMBOLS thermal/core: Move thermal_set_delay_jiffies to static thermal/core: Rename trips to ntrips
thermal/core: Add thermal_trip in thermal_zone thermal/core: Register with the trip points thermal/of: Store the trips in the thermal zone thermal/of: Use thermal trips stored in the thermal zone thermal/of: Initialize trip points separately

  .../driver-api/thermal/sysfs-api.rst          |   2 +-
  drivers/acpi/thermal.c                        |   6 +-
  .../ethernet/chelsio/cxgb4/cxgb4_thermal.c    |   2 +-
  .../ethernet/mellanox/mlxsw/core_thermal.c    |   6 +-
  drivers/net/wireless/intel/iwlwifi/mvm/tt.c   |   2 +-
  drivers/platform/x86/acerhdf.c                |   2 +-
  drivers/power/supply/power_supply_core.c      |   2 +-
  drivers/thermal/armada_thermal.c              |   2 +-
  drivers/thermal/broadcom/bcm2835_thermal.c    |   2 +-
  drivers/thermal/da9062-thermal.c              |   2 +-
  drivers/thermal/dove_thermal.c                |   2 +-
  drivers/thermal/gov_bang_bang.c               |   6 +-
  drivers/thermal/gov_fair_share.c              |  10 +-
  drivers/thermal/gov_power_allocator.c         |  22 +-
  drivers/thermal/gov_step_wise.c               |   4 +-
  drivers/thermal/imx_thermal.c                 |   2 +-
  .../intel/int340x_thermal/int3400_thermal.c   |   2 +-
  .../int340x_thermal/int340x_thermal_zone.c    |   6 +-
  .../int340x_thermal/int340x_thermal_zone.h    |   4 +-
  .../processor_thermal_device.c                |   4 +-
  .../processor_thermal_device_pci.c            |   2 +-
  drivers/thermal/intel/intel_pch_thermal.c     |   2 +-
  .../thermal/intel/intel_quark_dts_thermal.c   |   2 +-
  drivers/thermal/intel/intel_soc_dts_iosf.c    |   2 +-
  drivers/thermal/intel/x86_pkg_temp_thermal.c  |   2 +-
  drivers/thermal/kirkwood_thermal.c            |   2 +-
  drivers/thermal/rcar_gen3_thermal.c           |   6 +-
  drivers/thermal/rcar_thermal.c                |   4 +-
  drivers/thermal/samsung/exynos_tmu.c          |   6 +-
  drivers/thermal/spear_thermal.c               |   2 +-
  drivers/thermal/st/st_thermal.c               |   2 +-
  drivers/thermal/tegra/soctherm.c              |  10 +-
  drivers/thermal/tegra/tegra30-tsensor.c       |   6 +-
  drivers/thermal/thermal_core.c                | 102 ++++----
  drivers/thermal/thermal_core.h                |  25 +-
  drivers/thermal/thermal_helpers.c             |  35 ++-
  drivers/thermal/thermal_hwmon.c               |   4 +-
  drivers/thermal/thermal_netlink.c             |  10 +-
  drivers/thermal/thermal_of.c                  | 221 ++++++++++--------
  drivers/thermal/thermal_sysfs.c               |  62 ++---
  include/linux/thermal.h                       |  34 ++-
  41 files changed, 341 insertions(+), 290 deletions(-)
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#27 lore raw
Quoted 7 lines · Daniel Lezcano

Hi Rafael,

if you are ok with this series, I'll pick it up.

Is that ok ?

Give me some more time to look at it, please.

I'll respond in the first half of next week.

Quoted 103 lines · Daniel Lezcano
Quoted 85 lines

The thermal framework initialization with the device tree appears to be complicated and hard to make it to evolve.

It contains duplication of almost the same thermal generic structures and has an assymetric initialization making hard any kind of serious changes for more complex features. One of them is the multiple sensors support per thermal zone.

In order to set the scene for the aforementioned feature with generic code, we need to cleanup and rework the device tree initialization.

However this rework is not obvious because of the multiple components entering in the composition of a thermal zone and being initialized at different moments. For instance, a cooling device can be initialized before a sensor, so the thermal zones must exist before the cooling device as well as the sensor. This asynchonous initialization forces the thermal zone to be created with fake ops because they are mandotory and build a list of cooling devices which is used to lookup afterwards when the cooling device driver is registering itself.

As there could be a large number of changes, this first series provide some steps forward for a simpler device tree initialization.

Changelog:
- V2:
- Drop patch 1/15 which contains too many changes for a simple structure renaming. This could be addressed in a separate series as it is not necessary for the OF rework

- Fixed of_node_put with gchild not initialized as reported by kbuild and Dan Carpenter

- V1:
- Initial post

Daniel Lezcano (14):
thermal/core: Change thermal_zone_ops to thermal_sensor_ops thermal/core: Add a thermal sensor structure in the thermal zone thermal/core: Remove duplicate information when an error occurs thermal/of: Replace device node match with device node search thermal/of: Remove the device node pointer for thermal_trip thermal/of: Move thermal_trip structure to thermal.h thermal/core: Remove unneeded EXPORT_SYMBOLS thermal/core: Move thermal_set_delay_jiffies to static thermal/core: Rename trips to ntrips
thermal/core: Add thermal_trip in thermal_zone thermal/core: Register with the trip points thermal/of: Store the trips in the thermal zone thermal/of: Use thermal trips stored in the thermal zone thermal/of: Initialize trip points separately

  .../driver-api/thermal/sysfs-api.rst          |   2 +-
  drivers/acpi/thermal.c                        |   6 +-
  .../ethernet/chelsio/cxgb4/cxgb4_thermal.c    |   2 +-
  .../ethernet/mellanox/mlxsw/core_thermal.c    |   6 +-
  drivers/net/wireless/intel/iwlwifi/mvm/tt.c   |   2 +-
  drivers/platform/x86/acerhdf.c                |   2 +-
  drivers/power/supply/power_supply_core.c      |   2 +-
  drivers/thermal/armada_thermal.c              |   2 +-
  drivers/thermal/broadcom/bcm2835_thermal.c    |   2 +-
  drivers/thermal/da9062-thermal.c              |   2 +-
  drivers/thermal/dove_thermal.c                |   2 +-
  drivers/thermal/gov_bang_bang.c               |   6 +-
  drivers/thermal/gov_fair_share.c              |  10 +-
  drivers/thermal/gov_power_allocator.c         |  22 +-
  drivers/thermal/gov_step_wise.c               |   4 +-
  drivers/thermal/imx_thermal.c                 |   2 +-
  .../intel/int340x_thermal/int3400_thermal.c   |   2 +-
  .../int340x_thermal/int340x_thermal_zone.c    |   6 +-
  .../int340x_thermal/int340x_thermal_zone.h    |   4 +-
  .../processor_thermal_device.c                |   4 +-
  .../processor_thermal_device_pci.c            |   2 +-
  drivers/thermal/intel/intel_pch_thermal.c     |   2 +-
  .../thermal/intel/intel_quark_dts_thermal.c   |   2 +-
  drivers/thermal/intel/intel_soc_dts_iosf.c    |   2 +-
  drivers/thermal/intel/x86_pkg_temp_thermal.c  |   2 +-
  drivers/thermal/kirkwood_thermal.c            |   2 +-
  drivers/thermal/rcar_gen3_thermal.c           |   6 +-
  drivers/thermal/rcar_thermal.c                |   4 +-
  drivers/thermal/samsung/exynos_tmu.c          |   6 +-
  drivers/thermal/spear_thermal.c               |   2 +-
  drivers/thermal/st/st_thermal.c               |   2 +-
  drivers/thermal/tegra/soctherm.c              |  10 +-
  drivers/thermal/tegra/tegra30-tsensor.c       |   6 +-
  drivers/thermal/thermal_core.c                | 102 ++++----
Quoted 9 lines
  drivers/thermal/thermal_core.h                |  25 +-
  drivers/thermal/thermal_helpers.c             |  35 ++-
  drivers/thermal/thermal_hwmon.c               |   4 +-
  drivers/thermal/thermal_netlink.c             |  10 +-
  drivers/thermal/thermal_of.c                  | 221 ++++++++++--------
  drivers/thermal/thermal_sysfs.c               |  62 ++---
  include/linux/thermal.h                       |  34 ++-
  41 files changed, 341 insertions(+), 290 deletions(-)

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

#28 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 4 lines · Daniel Lezcano

Hi Rafael,

Quoted 8 lines
Quoted 3 lines

if you are ok with this series, I'll pick it up.

Is that ok ?

Give me some more time to look at it, please.

I'll respond in the first half of next week.

Sure, no problem

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#4 lore raw

Re: [PATCH v2 01/14] thermal/core: Change thermal_zone_ops to thermal_sensor_ops

In reply to Daniel Lezcano
Quoted 8 lines · Daniel Lezcano

A thermal zone is software abstraction of a sensor associated with properties and cooling devices if any.

The fact that we have thermal_zone and thermal_zone_ops mixed is confusing and does not clearly identify the different components entering in the thermal management process. A thermal zone appears to be a sensor while it is not.

Well, the majority of the operations in thermal_zone_ops don't apply to thermal sensors. For example, ->set_trips(), ->get_trip_type(), ->get_trip_temp().

Quoted 4 lines

In order to set the scene for multiple thermal sensors aggregated into a single thermal zone. Rename the thermal_zone_ops to thermal_sensor_ops, that will appear clearyl the thermal zone is not a sensor but an abstraction of one [or multiple] sensor(s).

So I'm not convinced that the renaming mentioned above is particularly clean either.

IMV the way to go would be to split the thermal sensor operations, like ->get_temp(), out of thermal_zone_ops.

But then it is not clear what a thermal zone with multiple sensors in it really means. I guess it would require an aggregation function to combine the thermal sensors in it that would produce an effective temperature to check against the trip points.

Honestly, I don't think that setting a separate set of trips for each sensor in a thermal zone would make a lot of sense.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#14 lore raw

Re: [PATCH v2 03/14] thermal/core: Remove duplicate information when an error occurs

In reply to Daniel Lezcano
Quoted 35 lines · Daniel Lezcano

The pr_err already tells it is an error, it is pointless to add the 'Error:' string in the messages. Remove them.

Cc: Alexandre Bailon <[email protected]>
Cc: Kevin Hilman <[email protected]>
Cc; Eduardo Valentin <[email protected]>

---
 drivers/thermal/thermal_core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/thermal_core.c +3 -3
index 1a405854748a..dc5a03d51f5c 100644
@@ -1197,23 +1197,23 @@ thermal_zone_device_register(const char *type, int trips, int mask,
        struct thermal_governor *governor;
 
        if (!type || strlen(type) == 0) {
-               pr_err("Error: No thermal zone type defined\n");
+               pr_err("No thermal zone type defined\n");
                return ERR_PTR(-EINVAL);
        }
 
        if (type && strlen(type) >= THERMAL_NAME_LENGTH) {
-               pr_err("Error: Thermal zone name (%s) too long, should be under %d chars\n",
+               pr_err("Thermal zone name (%s) too long, should be under %d chars\n",
                       type, THERMAL_NAME_LENGTH);
                return ERR_PTR(-EINVAL);
        }
 
        if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) {
-               pr_err("Error: Incorrect number of thermal trips\n");
+               pr_err("Incorrect number of thermal trips\n");

drivers/thermal/thermal_core.c thermal_zone_device_register(const char *type, int trips, int mask,

Quoted 10 lines
drivers/thermal/thermal_core.c +1 -2
                return ERR_PTR(-EINVAL);
        }
 
        if (!ops) {
-               pr_err("Error: Thermal zone device ops not defined\n");
+               pr_err("Thermal zone device ops not defined\n");
                return ERR_PTR(-EINVAL);
        }
 
--

Do these need to be pr_err() messages at all? They all seem to be debug-type messages regarding thermal zone drivers.

#5 lore raw

Re: [PATCH v2 01/14] thermal/core: Change thermal_zone_ops to thermal_sensor_ops

In reply to Rafael J. Wysocki
Quoted 12 lines · Rafael J. Wysocki
Quoted 9 lines · Daniel Lezcano

A thermal zone is software abstraction of a sensor associated with properties and cooling devices if any.

The fact that we have thermal_zone and thermal_zone_ops mixed is confusing and does not clearly identify the different components entering in the thermal management process. A thermal zone appears to
be a sensor while it is not.

Quoted 4 lines

Well, the majority of the operations in thermal_zone_ops don't apply to thermal sensors.  For example, ->set_trips(), ->get_trip_type(), ->get_trip_temp().

In past we discussed adding thermal sensor sysfs with threshold to notify temperature.

So sensor can have set/get_threshold() functions instead of the set/get_trip for zones.

Like we have /sys/class/thermal_zone* we can have
/sys/class/thermal_sensor*.

Thermal sensor(s) are bound to thermal zones. This can also include multiple sensors in a zone and can create a virtual sensor also.

Thanks,
Srinivas

Quoted 21 lines
Quoted 6 lines

In order to set the scene for multiple thermal sensors aggregated into
a single thermal zone. Rename the thermal_zone_ops to thermal_sensor_ops, that will appear clearyl the thermal zone is not a
sensor but an abstraction of one [or multiple] sensor(s).

So I'm not convinced that the renaming mentioned above is particularly
clean either.

IMV the way to go would be to split the thermal sensor operations, like ->get_temp(), out of thermal_zone_ops.

But then it is not clear what a thermal zone with multiple sensors in it really means.  I guess it would require an aggregation function to combine the thermal sensors in it that would produce an effective temperature to check against the trip points.

Honestly, I don't think that setting a separate set of trips for each sensor in a thermal zone would make a lot of sense.

#6 lore raw

Re: [PATCH v2 01/14] thermal/core: Change thermal_zone_ops to thermal_sensor_ops

Quoted 18 lines · srinivas pandruvada
Quoted 12 lines · Rafael J. Wysocki
Quoted 9 lines · Daniel Lezcano

A thermal zone is software abstraction of a sensor associated with properties and cooling devices if any.

The fact that we have thermal_zone and thermal_zone_ops mixed is confusing and does not clearly identify the different components entering in the thermal management process. A thermal zone appears to
be a sensor while it is not.

Quoted 4 lines

Well, the majority of the operations in thermal_zone_ops don't apply to thermal sensors. For example, ->set_trips(), ->get_trip_type(), ->get_trip_temp().

Quoted 8 lines

In past we discussed adding thermal sensor sysfs with threshold to notify temperature.

So sensor can have set/get_threshold() functions instead of the set/get_trip for zones.

Like we have /sys/class/thermal_zone* we can have
/sys/class/thermal_sensor*.

Exactly, so renaming thermal_zone_ops as thermal_sensor_ops isn't quite helpful in this respect.

IMO there should be operations for sensors and there should be operations for thermal zones and those two sets of operations should be different.

Quoted 1 line

Thermal sensor(s) are bound to thermal zones.

So I think that this binding should be analogous to the binding between thermal zones and cooling devices.

Quoted 1 line

This can also include multiple sensors in a zone and can create a virtual sensor also.

It can.

However, what's the difference between a thermal zone with multiple sensors and a thermal zone with one virtual sensor being an aggregate of multiple physical sensors?

Both involve some type of aggregation of temperature values measured by the physical sensors.

Quoted 22 lines
Quoted 21 lines
Quoted 6 lines

In order to set the scene for multiple thermal sensors aggregated into
a single thermal zone. Rename the thermal_zone_ops to thermal_sensor_ops, that will appear clearyl the thermal zone is not a
sensor but an abstraction of one [or multiple] sensor(s).

So I'm not convinced that the renaming mentioned above is particularly
clean either.

IMV the way to go would be to split the thermal sensor operations, like ->get_temp(), out of thermal_zone_ops.

But then it is not clear what a thermal zone with multiple sensors in it really means. I guess it would require an aggregation function to combine the thermal sensors in it that would produce an effective temperature to check against the trip points.

Honestly, I don't think that setting a separate set of trips for each sensor in a thermal zone would make a lot of sense.

#7 lore raw

Re: [PATCH v2 01/14] thermal/core: Change thermal_zone_ops to thermal_sensor_ops

Quoted 47 lines · Rafael J. Wysocki
Quoted 24 lines · srinivas pandruvada
Quoted 16 lines · Rafael J. Wysocki
Quoted 5 lines · Daniel Lezcano

A thermal zone is software abstraction of a sensor associated with
properties and cooling devices if any.

Quoted 8 lines

The fact that we have thermal_zone and thermal_zone_ops mixed is
confusing and does not clearly identify the different components
entering in the thermal management process. A thermal zone appears
to
be a sensor while it is not.

Quoted 6 lines

Well, the majority of the operations in thermal_zone_ops don't apply
to thermal sensors.  For example, ->set_trips(), -

Quoted 1 line

get_trip_type(),

->get_trip_temp().

Quoted 8 lines

In past we discussed adding thermal sensor sysfs with threshold to notify temperature.

So sensor can have set/get_threshold() functions instead of the set/get_trip for zones.

Like we have /sys/class/thermal_zone* we can have
/sys/class/thermal_sensor*.

Exactly, so renaming thermal_zone_ops as thermal_sensor_ops isn't quite helpful in this respect.

IMO there should be operations for sensors and there should be operations for thermal zones and those two sets of operations should be different.

Quoted 1 line

Thermal sensor(s) are bound to  thermal zones.

So I think that this binding should be analogous to the binding between thermal zones and cooling devices.

Quoted 9 lines
Quoted 2 lines

This can also include multiple sensors in a zone and can create a virtual sensor also.

It can.

However, what's the difference between a thermal zone with multiple sensors and a thermal zone with one virtual sensor being an aggregate of multiple physical sensors?

Either way is fine. A thermal sensor can be aggregate of other sensors.

Quoted 31 lines

Both involve some type of aggregation of temperature values measured by the physical sensors.

Quoted 28 lines
Quoted 27 lines
Quoted 8 lines

In order to set the scene for multiple thermal sensors aggregated
into
a single thermal zone. Rename the thermal_zone_ops to thermal_sensor_ops, that will appear clearyl the thermal zone is
not a
sensor but an abstraction of one [or multiple] sensor(s).

So I'm not convinced that the renaming mentioned above is particularly
clean either.

IMV the way to go would be to split the thermal sensor operations,
like ->get_temp(), out of thermal_zone_ops.

But then it is not clear what a thermal zone with multiple sensors in
it really means.  I guess it would require an aggregation function to
combine the thermal sensors in it that would produce an effective temperature to check against the trip points.

Honestly, I don't think that setting a separate set of trips for each
sensor in a thermal zone would make a lot of sense.

#8 lore raw

Re: [PATCH v2 01/14] thermal/core: Change thermal_zone_ops to thermal_sensor_ops

Quoted 52 lines · srinivas pandruvada
Quoted 50 lines · Rafael J. Wysocki
Quoted 24 lines · srinivas pandruvada
Quoted 16 lines · Rafael J. Wysocki
Quoted 5 lines · Daniel Lezcano

A thermal zone is software abstraction of a sensor associated with
properties and cooling devices if any.

Quoted 8 lines

The fact that we have thermal_zone and thermal_zone_ops mixed is
confusing and does not clearly identify the different components
entering in the thermal management process. A thermal zone appears
to
be a sensor while it is not.

Quoted 6 lines

Well, the majority of the operations in thermal_zone_ops don't apply
to thermal sensors. For example, ->set_trips(), -

Quoted 1 line

get_trip_type(),

->get_trip_temp().

Quoted 8 lines

In past we discussed adding thermal sensor sysfs with threshold to notify temperature.

So sensor can have set/get_threshold() functions instead of the set/get_trip for zones.

Like we have /sys/class/thermal_zone* we can have
/sys/class/thermal_sensor*.

Exactly, so renaming thermal_zone_ops as thermal_sensor_ops isn't quite helpful in this respect.

IMO there should be operations for sensors and there should be operations for thermal zones and those two sets of operations should be different.

Quoted 1 line

Thermal sensor(s) are bound to thermal zones.

So I think that this binding should be analogous to the binding between thermal zones and cooling devices.

Quoted 2 lines

This can also include multiple sensors in a zone and can create a virtual sensor also.

Quoted 7 lines
Quoted 6 lines

It can.

However, what's the difference between a thermal zone with multiple sensors and a thermal zone with one virtual sensor being an aggregate of multiple physical sensors?

Either way is fine. A thermal sensor can be aggregate of other sensors.

Agreed.

But the point is that if we go with thermal zones bound to multiple physical sensors, I don't see much point in using virtual sensors. And the other way around.

Daniel seems to be preferring the thermal zones bound to multiple physical sensors approach.

Quoted 32 lines
Quoted 31 lines

Both involve some type of aggregation of temperature values measured by the physical sensors.

Quoted 28 lines
Quoted 27 lines
Quoted 8 lines

In order to set the scene for multiple thermal sensors aggregated
into
a single thermal zone. Rename the thermal_zone_ops to thermal_sensor_ops, that will appear clearyl the thermal zone is
not a
sensor but an abstraction of one [or multiple] sensor(s).

So I'm not convinced that the renaming mentioned above is particularly
clean either.

IMV the way to go would be to split the thermal sensor operations,
like ->get_temp(), out of thermal_zone_ops.

But then it is not clear what a thermal zone with multiple sensors in
it really means. I guess it would require an aggregation function to
combine the thermal sensors in it that would produce an effective temperature to check against the trip points.

Honestly, I don't think that setting a separate set of trips for each
sensor in a thermal zone would make a lot of sense.

#9 lore raw

Re: [PATCH v2 01/14] thermal/core: Change thermal_zone_ops to thermal_sensor_ops

In reply to Rafael J. Wysocki

Hi Rafael,

sorry for the delay, I was OoO.

Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Daniel Lezcano

A thermal zone is software abstraction of a sensor associated with properties and cooling devices if any.

Quoted 8 lines
Quoted 4 lines

The fact that we have thermal_zone and thermal_zone_ops mixed is confusing and does not clearly identify the different components entering in the thermal management process. A thermal zone appears to be a sensor while it is not.

Well, the majority of the operations in thermal_zone_ops don't apply to thermal sensors. For example, ->set_trips(), ->get_trip_type(), ->get_trip_temp().

The set_trips is necessary to set the sensor interrupt to fire when the trip temperature is crossed the way up or down.

Quoted 10 lines
Quoted 4 lines

In order to set the scene for multiple thermal sensors aggregated into a single thermal zone. Rename the thermal_zone_ops to thermal_sensor_ops, that will appear clearyl the thermal zone is not a sensor but an abstraction of one [or multiple] sensor(s).

So I'm not convinced that the renaming mentioned above is particularly clean either.

IMV the way to go would be to split the thermal sensor operations, like ->get_temp(), out of thermal_zone_ops.

Probably, we should first replace all the calls to ops->get_temp with a function. Then create the ops for the sensor:

- get_trend
- get_temp
- set_trips
- bind / unbind

Quoted 4 lines

But then it is not clear what a thermal zone with multiple sensors in it really means. I guess it would require an aggregation function to combine the thermal sensors in it that would produce an effective temperature to check against the trip points.

Yes, that is why the above ops->get_temp should be wrapped into a function which can evolve to an aggregation function.

Quoted 2 lines

Honestly, I don't think that setting a separate set of trips for each sensor in a thermal zone would make a lot of sense.

I agree the set_trips is for the interrupt mode only.

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog