Commit 14ccb5ed authored by Daniel Lezcano's avatar Daniel Lezcano Committed by Daniel Lezcano

thermal/of: Use thermal trips stored in the thermal zone

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 <abailon@baylibre.com>
Cc: Kevin Hilman <khilman@baylibre.com>
Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linexp.org>
Link: https://lore.kernel.org/r/20220722200007.1839356-10-daniel.lezcano@linexp.orgSigned-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent fae11de5
...@@ -118,12 +118,7 @@ static int of_thermal_set_trips(struct thermal_zone_device *tz, ...@@ -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) int of_thermal_get_ntrips(struct thermal_zone_device *tz)
{ {
struct __thermal_zone *data = tz->devdata; return tz->num_trips;
if (!data || IS_ERR(data))
return -ENODEV;
return data->ntrips;
} }
EXPORT_SYMBOL_GPL(of_thermal_get_ntrips); EXPORT_SYMBOL_GPL(of_thermal_get_ntrips);
...@@ -139,9 +134,7 @@ 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) bool of_thermal_is_trip_valid(struct thermal_zone_device *tz, int trip)
{ {
struct __thermal_zone *data = tz->devdata; if (trip >= tz->num_trips || trip < 0)
if (!data || trip >= data->ntrips || trip < 0)
return false; return false;
return true; return true;
...@@ -161,12 +154,7 @@ EXPORT_SYMBOL_GPL(of_thermal_is_trip_valid); ...@@ -161,12 +154,7 @@ EXPORT_SYMBOL_GPL(of_thermal_is_trip_valid);
const struct thermal_trip * const struct thermal_trip *
of_thermal_get_trip_points(struct thermal_zone_device *tz) of_thermal_get_trip_points(struct thermal_zone_device *tz)
{ {
struct __thermal_zone *data = tz->devdata; return tz->trips;
if (!data)
return NULL;
return data->trips;
} }
EXPORT_SYMBOL_GPL(of_thermal_get_trip_points); EXPORT_SYMBOL_GPL(of_thermal_get_trip_points);
...@@ -281,12 +269,10 @@ static int of_thermal_unbind(struct thermal_zone_device *thermal, ...@@ -281,12 +269,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, static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip,
enum thermal_trip_type *type) enum thermal_trip_type *type)
{ {
struct __thermal_zone *data = tz->devdata; if (trip >= tz->num_trips || trip < 0)
if (trip >= data->ntrips || trip < 0)
return -EDOM; return -EDOM;
*type = data->trips[trip].type; *type = tz->trips[trip].type;
return 0; return 0;
} }
...@@ -294,12 +280,10 @@ static int of_thermal_get_trip_type(struct thermal_zone_device *tz, int trip, ...@@ -294,12 +280,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, static int of_thermal_get_trip_temp(struct thermal_zone_device *tz, int trip,
int *temp) int *temp)
{ {
struct __thermal_zone *data = tz->devdata; if (trip >= tz->num_trips || trip < 0)
if (trip >= data->ntrips || trip < 0)
return -EDOM; return -EDOM;
*temp = data->trips[trip].temperature; *temp = tz->trips[trip].temperature;
return 0; return 0;
} }
...@@ -309,7 +293,7 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, ...@@ -309,7 +293,7 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip,
{ {
struct __thermal_zone *data = tz->devdata; struct __thermal_zone *data = tz->devdata;
if (trip >= data->ntrips || trip < 0) if (trip >= tz->num_trips || trip < 0)
return -EDOM; return -EDOM;
if (data->ops && data->ops->set_trip_temp) { if (data->ops && data->ops->set_trip_temp) {
...@@ -321,7 +305,7 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, ...@@ -321,7 +305,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) */ /* thermal framework should take care of data->mask & (1 << trip) */
data->trips[trip].temperature = temp; tz->trips[trip].temperature = temp;
return 0; return 0;
} }
...@@ -329,12 +313,10 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip, ...@@ -329,12 +313,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, static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip,
int *hyst) int *hyst)
{ {
struct __thermal_zone *data = tz->devdata; if (trip >= tz->num_trips || trip < 0)
if (trip >= data->ntrips || trip < 0)
return -EDOM; return -EDOM;
*hyst = data->trips[trip].hysteresis; *hyst = tz->trips[trip].hysteresis;
return 0; return 0;
} }
...@@ -342,13 +324,11 @@ static int of_thermal_get_trip_hyst(struct thermal_zone_device *tz, int trip, ...@@ -342,13 +324,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, static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip,
int hyst) int hyst)
{ {
struct __thermal_zone *data = tz->devdata; if (trip >= tz->num_trips || trip < 0)
if (trip >= data->ntrips || trip < 0)
return -EDOM; return -EDOM;
/* thermal framework should take care of data->mask & (1 << trip) */ /* thermal framework should take care of data->mask & (1 << trip) */
data->trips[trip].hysteresis = hyst; tz->trips[trip].hysteresis = hyst;
return 0; return 0;
} }
...@@ -356,12 +336,11 @@ static int of_thermal_set_trip_hyst(struct thermal_zone_device *tz, int trip, ...@@ -356,12 +336,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, static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
int *temp) int *temp)
{ {
struct __thermal_zone *data = tz->devdata;
int i; int i;
for (i = 0; i < data->ntrips; i++) for (i = 0; i < tz->num_trips; i++)
if (data->trips[i].type == THERMAL_TRIP_CRITICAL) { if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) {
*temp = data->trips[i].temperature; *temp = tz->trips[i].temperature;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment