diff mbox series

[RFC,23/26] mlxsw: core_thermal: Migrate to thermal_zone_device_register()

Message ID 20231221124825.149141-24-angelogioacchino.delregno@collabora.com
State New
Headers show
Series Add thermal zones names and new registration func | expand

Commit Message

AngeloGioacchino Del Regno Dec. 21, 2023, 12:48 p.m. UTC
The thermal API has a new thermal_zone_device_register() function which
is deprecating the older thermal_zone_device_register_with_trips() and
thermal_tripless_zone_device_register().

Migrate to the new thermal zone device registration function.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 .../ethernet/mellanox/mlxsw/core_thermal.c    | 93 ++++++++++---------
 1 file changed, 50 insertions(+), 43 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
index f1b48d6615f6..5ad9f90d096d 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_thermal.c
@@ -226,10 +226,6 @@  static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev,
 	return 0;
 }
 
-static struct thermal_zone_params mlxsw_thermal_params = {
-	.no_hwmon = true,
-};
-
 static struct thermal_zone_device_ops mlxsw_thermal_ops = {
 	.bind = mlxsw_thermal_bind,
 	.unbind = mlxsw_thermal_unbind,
@@ -408,28 +404,30 @@  static const struct thermal_cooling_device_ops mlxsw_cooling_ops = {
 static int
 mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz)
 {
-	char tz_name[THERMAL_NAME_LENGTH];
+	struct thermal_zone_device_params tzdp = {
+		.tzp = { .no_hwmon = true },
+		.ops = &mlxsw_thermal_module_ops,
+		.devdata = module_tz,
+		.trips = module_tz->trips,
+		.num_trips = MLXSW_THERMAL_NUM_TRIPS,
+		.mask = MLXSW_THERMAL_TRIP_MASK,
+		.polling_delay = module_tz->parent->polling_delay
+	};
 	int err;
 
 	if (module_tz->slot_index)
-		snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-module%d",
-			 module_tz->slot_index, module_tz->module + 1);
+		tzdp.type = kasprintf("mlxsw-lc%d-module%d",
+				      module_tz->slot_index, module_tz->module + 1);
 	else
-		snprintf(tz_name, sizeof(tz_name), "mlxsw-module%d",
-			 module_tz->module + 1);
-	module_tz->tzdev = thermal_zone_device_register_with_trips(tz_name,
-							module_tz->trips,
-							MLXSW_THERMAL_NUM_TRIPS,
-							MLXSW_THERMAL_TRIP_MASK,
-							module_tz,
-							&mlxsw_thermal_module_ops,
-							&mlxsw_thermal_params,
-							0,
-							module_tz->parent->polling_delay);
-	if (IS_ERR(module_tz->tzdev)) {
-		err = PTR_ERR(module_tz->tzdev);
-		return err;
-	}
+		tzdp.type = kasprintf("mlxsw-module%d", module_tz->module + 1);
+
+	if (!tzdp.type)
+		return -ENOMEM;
+
+	module_tz->tzdev = thermal_zone_device_register(&tzdp);
+	kfree(tzdp.type);
+	if (IS_ERR(module_tz->tzdev))
+		return PTR_ERR(module_tz->tzdev);
 
 	err = thermal_zone_device_enable(module_tz->tzdev);
 	if (err)
@@ -536,23 +534,28 @@  mlxsw_thermal_modules_fini(struct mlxsw_thermal *thermal,
 static int
 mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
 {
-	char tz_name[40];
+	struct thermal_zone_device_params tzdp = {
+		.tzp = { .no_hwmon = true },
+		.ops = &mlxsw_thermal_gearbox_ops,
+		.devdata = gearbox_tz,
+		.trips = gearbox_tz->trips,
+		.num_trips = MLXSW_THERMAL_NUM_TRIPS,
+		.mask = MLXSW_THERMAL_TRIP_MASK,
+		.polling_delay = gearbox_tz->parent->polling_delay
+	};
 	int ret;
 
 	if (gearbox_tz->slot_index)
-		snprintf(tz_name, sizeof(tz_name), "mlxsw-lc%d-gearbox%d",
-			 gearbox_tz->slot_index, gearbox_tz->module + 1);
+		tzdp.type = kasprintf("mlxsw-lc%d-gearbox%d",
+				      gearbox_tz->slot_index, gearbox_tz->module + 1);
 	else
-		snprintf(tz_name, sizeof(tz_name), "mlxsw-gearbox%d",
-			 gearbox_tz->module + 1);
-	gearbox_tz->tzdev = thermal_zone_device_register_with_trips(tz_name,
-						gearbox_tz->trips,
-						MLXSW_THERMAL_NUM_TRIPS,
-						MLXSW_THERMAL_TRIP_MASK,
-						gearbox_tz,
-						&mlxsw_thermal_gearbox_ops,
-						&mlxsw_thermal_params, 0,
-						gearbox_tz->parent->polling_delay);
+		tzdp.type = kasprintf("mlxsw-gearbox%d", gearbox_tz->module + 1);
+
+	if (!tzdp.type)
+		return -ENOMEM;
+
+	gearbox_tz->tzdev = thermal_zone_device_register(&tzdp);
+	kfree(tzdp.type);
 	if (IS_ERR(gearbox_tz->tzdev))
 		return PTR_ERR(gearbox_tz->tzdev);
 
@@ -695,6 +698,12 @@  int mlxsw_thermal_init(struct mlxsw_core *core,
 		       const struct mlxsw_bus_info *bus_info,
 		       struct mlxsw_thermal **p_thermal)
 {
+	struct thermal_zone_device_params tzdp = {
+		.type = "mlxsw",
+		.tzp = { .no_hwmon = true },
+		.ops = &mlxsw_thermal_ops,
+		.mask = MLXSW_THERMAL_TRIP_MASK
+	};
 	char mfcr_pl[MLXSW_REG_MFCR_LEN] = { 0 };
 	enum mlxsw_reg_mfcr_pwm_frequency freq;
 	struct device *dev = bus_info->dev;
@@ -770,14 +779,12 @@  int mlxsw_thermal_init(struct mlxsw_core *core,
 				 MLXSW_THERMAL_SLOW_POLL_INT :
 				 MLXSW_THERMAL_POLL_INT;
 
-	thermal->tzdev = thermal_zone_device_register_with_trips("mlxsw",
-						      thermal->trips,
-						      MLXSW_THERMAL_NUM_TRIPS,
-						      MLXSW_THERMAL_TRIP_MASK,
-						      thermal,
-						      &mlxsw_thermal_ops,
-						      &mlxsw_thermal_params, 0,
-						      thermal->polling_delay);
+	tzdp.devdata = thermal;
+	tzdp.trips = thermal->trips;
+	tzdp.num_trips = MLXSW_THERMAL_NUM_TRIPS;
+	tzdp.polling_delay = thermal->polling_delay;
+
+	thermal->tzdev = thermal_zone_device_register(&tzdp);
 	if (IS_ERR(thermal->tzdev)) {
 		err = PTR_ERR(thermal->tzdev);
 		dev_err(dev, "Failed to register thermal zone\n");