Skip to content

Commit 5b5a5ad

Browse files
committed
Merge tag 'thermal-6.10-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull thermal control fixes from Rafael Wysocki: "These fix the MediaTek lvts_thermal driver and the handling of trip points that start as invalid and are adjusted later by user space via sysfs. Specifics: - Fix and clean up the MediaTek lvts_thermal driver (Julien Panis) - Prevent invalid trip point handling from triggering spurious trip point crossing events and allow passive polling to stop when a passive trip point involved in it becomes invalid (Rafael Wysocki)" * tag 'thermal-6.10-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: thermal: core: Fix the handling of invalid trip points thermal/drivers/mediatek/lvts_thermal: Fix wrong lvts_ctrl index thermal/drivers/mediatek/lvts_thermal: Remove unused members from struct lvts_ctrl_data thermal/drivers/mediatek/lvts_thermal: Check NULL ptr on lvts_data
2 parents 3b14403 + 8c69a77 commit 5b5a5ad

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

drivers/thermal/mediatek/lvts_thermal.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ struct lvts_sensor_data {
105105

106106
struct lvts_ctrl_data {
107107
struct lvts_sensor_data lvts_sensor[LVTS_SENSOR_MAX];
108-
int cal_offset[LVTS_SENSOR_MAX];
109-
int num_lvts_sensor;
110108
u8 valid_sensor_mask;
111109
int offset;
112110
int mode;
@@ -118,9 +116,9 @@ struct lvts_ctrl_data {
118116
((s2) ? BIT(2) : 0) | \
119117
((s3) ? BIT(3) : 0))
120118

121-
#define lvts_for_each_valid_sensor(i, lvts_ctrl_data) \
119+
#define lvts_for_each_valid_sensor(i, lvts_ctrl) \
122120
for ((i) = 0; (i) < LVTS_SENSOR_MAX; (i)++) \
123-
if (!((lvts_ctrl_data)->valid_sensor_mask & BIT(i))) \
121+
if (!((lvts_ctrl)->valid_sensor_mask & BIT(i))) \
124122
continue; \
125123
else
126124

@@ -147,6 +145,7 @@ struct lvts_ctrl {
147145
const struct lvts_data *lvts_data;
148146
u32 calibration[LVTS_SENSOR_MAX];
149147
u32 hw_tshut_raw_temp;
148+
u8 valid_sensor_mask;
150149
int mode;
151150
void __iomem *base;
152151
int low_thresh;
@@ -358,7 +357,7 @@ static bool lvts_should_update_thresh(struct lvts_ctrl *lvts_ctrl, int high)
358357
if (high > lvts_ctrl->high_thresh)
359358
return true;
360359

361-
lvts_for_each_valid_sensor(i, lvts_ctrl->lvts_data->lvts_ctrl)
360+
lvts_for_each_valid_sensor(i, lvts_ctrl)
362361
if (lvts_ctrl->sensors[i].high_thresh == lvts_ctrl->high_thresh
363362
&& lvts_ctrl->sensors[i].low_thresh == lvts_ctrl->low_thresh)
364363
return false;
@@ -619,6 +618,8 @@ static int lvts_sensor_init(struct device *dev, struct lvts_ctrl *lvts_ctrl,
619618
lvts_sensor[i].high_thresh = INT_MIN;
620619
};
621620

621+
lvts_ctrl->valid_sensor_mask = lvts_ctrl_data->valid_sensor_mask;
622+
622623
return 0;
623624
}
624625

@@ -1114,7 +1115,7 @@ static int lvts_ctrl_start(struct device *dev, struct lvts_ctrl *lvts_ctrl)
11141115
u32 *sensor_bitmap = lvts_ctrl->mode == LVTS_MSR_IMMEDIATE_MODE ?
11151116
sensor_imm_bitmap : sensor_filt_bitmap;
11161117

1117-
lvts_for_each_valid_sensor(i, lvts_ctrl->lvts_data->lvts_ctrl) {
1118+
lvts_for_each_valid_sensor(i, lvts_ctrl) {
11181119

11191120
int dt_id = lvts_sensors[i].dt_id;
11201121

@@ -1271,6 +1272,8 @@ static int lvts_probe(struct platform_device *pdev)
12711272
return -ENOMEM;
12721273

12731274
lvts_data = of_device_get_match_data(dev);
1275+
if (!lvts_data)
1276+
return -ENODEV;
12741277

12751278
lvts_td->clk = devm_clk_get_enabled(dev, NULL);
12761279
if (IS_ERR(lvts_td->clk))

drivers/thermal/thermal_core.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,15 @@ thermal_zone_device_register_with_trips(const char *type,
13981398
tz->device.class = thermal_class;
13991399
tz->devdata = devdata;
14001400
tz->num_trips = num_trips;
1401-
for_each_trip_desc(tz, td)
1401+
for_each_trip_desc(tz, td) {
14021402
td->trip = *trip++;
1403+
/*
1404+
* Mark all thresholds as invalid to start with even though
1405+
* this only matters for the trips that start as invalid and
1406+
* become valid later.
1407+
*/
1408+
td->threshold = INT_MAX;
1409+
}
14031410

14041411
thermal_set_delay_jiffies(&tz->passive_delay_jiffies, passive_delay);
14051412
thermal_set_delay_jiffies(&tz->polling_delay_jiffies, polling_delay);

drivers/thermal/thermal_trip.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ void thermal_zone_set_trip_temp(struct thermal_zone_device *tz,
152152
if (trip->temperature == temp)
153153
return;
154154

155+
if (temp == THERMAL_TEMP_INVALID) {
156+
struct thermal_trip_desc *td = trip_to_trip_desc(trip);
157+
158+
if (trip->type == THERMAL_TRIP_PASSIVE &&
159+
tz->temperature >= td->threshold) {
160+
/*
161+
* The trip has been crossed, so the thermal zone's
162+
* passive count needs to be adjusted.
163+
*/
164+
tz->passive--;
165+
WARN_ON_ONCE(tz->passive < 0);
166+
}
167+
/*
168+
* Invalidate the threshold to avoid triggering a spurious
169+
* trip crossing notification when the trip becomes valid.
170+
*/
171+
td->threshold = INT_MAX;
172+
}
155173
trip->temperature = temp;
156174
thermal_notify_tz_trip_change(tz, trip);
157175
}

0 commit comments

Comments
 (0)