@@ -36,33 +36,39 @@ enum mlxsw_thermal_trips {
3636 MLXSW_THERMAL_TEMP_TRIP_HOT ,
3737};
3838
39- struct mlxsw_thermal_trip {
40- int type ;
41- int temp ;
42- int hyst ;
39+ struct mlxsw_cooling_states {
4340 int min_state ;
4441 int max_state ;
4542};
4643
47- static const struct mlxsw_thermal_trip default_thermal_trips [] = {
44+ static const struct thermal_trip default_thermal_trips [] = {
4845 { /* In range - 0-40% PWM */
4946 .type = THERMAL_TRIP_ACTIVE ,
50- .temp = MLXSW_THERMAL_ASIC_TEMP_NORM ,
51- .hyst = MLXSW_THERMAL_HYSTERESIS_TEMP ,
52- .min_state = 0 ,
53- .max_state = (4 * MLXSW_THERMAL_MAX_STATE ) / 10 ,
47+ .temperature = MLXSW_THERMAL_ASIC_TEMP_NORM ,
48+ .hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP ,
5449 },
5550 {
5651 /* In range - 40-100% PWM */
5752 .type = THERMAL_TRIP_ACTIVE ,
58- .temp = MLXSW_THERMAL_ASIC_TEMP_HIGH ,
59- .hyst = MLXSW_THERMAL_HYSTERESIS_TEMP ,
60- .min_state = (4 * MLXSW_THERMAL_MAX_STATE ) / 10 ,
61- .max_state = MLXSW_THERMAL_MAX_STATE ,
53+ .temperature = MLXSW_THERMAL_ASIC_TEMP_HIGH ,
54+ .hysteresis = MLXSW_THERMAL_HYSTERESIS_TEMP ,
6255 },
6356 { /* Warning */
6457 .type = THERMAL_TRIP_HOT ,
65- .temp = MLXSW_THERMAL_ASIC_TEMP_HOT ,
58+ .temperature = MLXSW_THERMAL_ASIC_TEMP_HOT ,
59+ },
60+ };
61+
62+ static const struct mlxsw_cooling_states default_cooling_states [] = {
63+ {
64+ .min_state = 0 ,
65+ .max_state = (4 * MLXSW_THERMAL_MAX_STATE ) / 10 ,
66+ },
67+ {
68+ .min_state = (4 * MLXSW_THERMAL_MAX_STATE ) / 10 ,
69+ .max_state = MLXSW_THERMAL_MAX_STATE ,
70+ },
71+ {
6672 .min_state = MLXSW_THERMAL_MAX_STATE ,
6773 .max_state = MLXSW_THERMAL_MAX_STATE ,
6874 },
@@ -78,7 +84,8 @@ struct mlxsw_thermal;
7884struct mlxsw_thermal_module {
7985 struct mlxsw_thermal * parent ;
8086 struct thermal_zone_device * tzdev ;
81- struct mlxsw_thermal_trip trips [MLXSW_THERMAL_NUM_TRIPS ];
87+ struct thermal_trip trips [MLXSW_THERMAL_NUM_TRIPS ];
88+ struct mlxsw_cooling_states cooling_states [MLXSW_THERMAL_NUM_TRIPS ];
8289 int module ; /* Module or gearbox number */
8390 u8 slot_index ;
8491};
@@ -99,7 +106,8 @@ struct mlxsw_thermal {
99106 int polling_delay ;
100107 struct thermal_cooling_device * cdevs [MLXSW_MFCR_PWMS_MAX ];
101108 u8 cooling_levels [MLXSW_THERMAL_MAX_STATE + 1 ];
102- struct mlxsw_thermal_trip trips [MLXSW_THERMAL_NUM_TRIPS ];
109+ struct thermal_trip trips [MLXSW_THERMAL_NUM_TRIPS ];
110+ struct mlxsw_cooling_states cooling_states [MLXSW_THERMAL_NUM_TRIPS ];
103111 struct mlxsw_thermal_area line_cards [];
104112};
105113
@@ -136,9 +144,9 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal,
136144static void
137145mlxsw_thermal_module_trips_reset (struct mlxsw_thermal_module * tz )
138146{
139- tz -> trips [MLXSW_THERMAL_TEMP_TRIP_NORM ].temp = 0 ;
140- tz -> trips [MLXSW_THERMAL_TEMP_TRIP_HIGH ].temp = 0 ;
141- tz -> trips [MLXSW_THERMAL_TEMP_TRIP_HOT ].temp = 0 ;
147+ tz -> trips [MLXSW_THERMAL_TEMP_TRIP_NORM ].temperature = 0 ;
148+ tz -> trips [MLXSW_THERMAL_TEMP_TRIP_HIGH ].temperature = 0 ;
149+ tz -> trips [MLXSW_THERMAL_TEMP_TRIP_HOT ].temperature = 0 ;
142150}
143151
144152static int
@@ -180,12 +188,12 @@ mlxsw_thermal_module_trips_update(struct device *dev, struct mlxsw_core *core,
180188 * by subtracting double hysteresis value.
181189 */
182190 if (crit_temp >= MLXSW_THERMAL_MODULE_TEMP_SHIFT )
183- tz -> trips [MLXSW_THERMAL_TEMP_TRIP_NORM ].temp = crit_temp -
191+ tz -> trips [MLXSW_THERMAL_TEMP_TRIP_NORM ].temperature = crit_temp -
184192 MLXSW_THERMAL_MODULE_TEMP_SHIFT ;
185193 else
186- tz -> trips [MLXSW_THERMAL_TEMP_TRIP_NORM ].temp = crit_temp ;
187- tz -> trips [MLXSW_THERMAL_TEMP_TRIP_HIGH ].temp = crit_temp ;
188- tz -> trips [MLXSW_THERMAL_TEMP_TRIP_HOT ].temp = emerg_temp ;
194+ tz -> trips [MLXSW_THERMAL_TEMP_TRIP_NORM ].temperature = crit_temp ;
195+ tz -> trips [MLXSW_THERMAL_TEMP_TRIP_HIGH ].temperature = crit_temp ;
196+ tz -> trips [MLXSW_THERMAL_TEMP_TRIP_HOT ].temperature = emerg_temp ;
189197
190198 return 0 ;
191199}
@@ -202,11 +210,11 @@ static int mlxsw_thermal_bind(struct thermal_zone_device *tzdev,
202210 return 0 ;
203211
204212 for (i = 0 ; i < MLXSW_THERMAL_NUM_TRIPS ; i ++ ) {
205- const struct mlxsw_thermal_trip * trip = & thermal -> trips [i ];
213+ const struct mlxsw_cooling_states * state = & thermal -> cooling_states [i ];
206214
207215 err = thermal_zone_bind_cooling_device (tzdev , i , cdev ,
208- trip -> max_state ,
209- trip -> min_state ,
216+ state -> max_state ,
217+ state -> min_state ,
210218 THERMAL_WEIGHT_DEFAULT );
211219 if (err < 0 ) {
212220 dev_err (dev , "Failed to bind cooling device to trip %d\n" , i );
@@ -260,61 +268,6 @@ static int mlxsw_thermal_get_temp(struct thermal_zone_device *tzdev,
260268 return 0 ;
261269}
262270
263- static int mlxsw_thermal_get_trip_type (struct thermal_zone_device * tzdev ,
264- int trip ,
265- enum thermal_trip_type * p_type )
266- {
267- struct mlxsw_thermal * thermal = tzdev -> devdata ;
268-
269- if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS )
270- return - EINVAL ;
271-
272- * p_type = thermal -> trips [trip ].type ;
273- return 0 ;
274- }
275-
276- static int mlxsw_thermal_get_trip_temp (struct thermal_zone_device * tzdev ,
277- int trip , int * p_temp )
278- {
279- struct mlxsw_thermal * thermal = tzdev -> devdata ;
280-
281- if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS )
282- return - EINVAL ;
283-
284- * p_temp = thermal -> trips [trip ].temp ;
285- return 0 ;
286- }
287-
288- static int mlxsw_thermal_set_trip_temp (struct thermal_zone_device * tzdev ,
289- int trip , int temp )
290- {
291- struct mlxsw_thermal * thermal = tzdev -> devdata ;
292-
293- if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS )
294- return - EINVAL ;
295-
296- thermal -> trips [trip ].temp = temp ;
297- return 0 ;
298- }
299-
300- static int mlxsw_thermal_get_trip_hyst (struct thermal_zone_device * tzdev ,
301- int trip , int * p_hyst )
302- {
303- struct mlxsw_thermal * thermal = tzdev -> devdata ;
304-
305- * p_hyst = thermal -> trips [trip ].hyst ;
306- return 0 ;
307- }
308-
309- static int mlxsw_thermal_set_trip_hyst (struct thermal_zone_device * tzdev ,
310- int trip , int hyst )
311- {
312- struct mlxsw_thermal * thermal = tzdev -> devdata ;
313-
314- thermal -> trips [trip ].hyst = hyst ;
315- return 0 ;
316- }
317-
318271static struct thermal_zone_params mlxsw_thermal_params = {
319272 .no_hwmon = true,
320273};
@@ -323,11 +276,6 @@ static struct thermal_zone_device_ops mlxsw_thermal_ops = {
323276 .bind = mlxsw_thermal_bind ,
324277 .unbind = mlxsw_thermal_unbind ,
325278 .get_temp = mlxsw_thermal_get_temp ,
326- .get_trip_type = mlxsw_thermal_get_trip_type ,
327- .get_trip_temp = mlxsw_thermal_get_trip_temp ,
328- .set_trip_temp = mlxsw_thermal_set_trip_temp ,
329- .get_trip_hyst = mlxsw_thermal_get_trip_hyst ,
330- .set_trip_hyst = mlxsw_thermal_set_trip_hyst ,
331279};
332280
333281static int mlxsw_thermal_module_bind (struct thermal_zone_device * tzdev ,
@@ -342,11 +290,11 @@ static int mlxsw_thermal_module_bind(struct thermal_zone_device *tzdev,
342290 return 0 ;
343291
344292 for (i = 0 ; i < MLXSW_THERMAL_NUM_TRIPS ; i ++ ) {
345- const struct mlxsw_thermal_trip * trip = & tz -> trips [i ];
293+ const struct mlxsw_cooling_states * state = & tz -> cooling_states [i ];
346294
347295 err = thermal_zone_bind_cooling_device (tzdev , i , cdev ,
348- trip -> max_state ,
349- trip -> min_state ,
296+ state -> max_state ,
297+ state -> min_state ,
350298 THERMAL_WEIGHT_DEFAULT );
351299 if (err < 0 )
352300 goto err_thermal_zone_bind_cooling_device ;
@@ -434,74 +382,10 @@ static int mlxsw_thermal_module_temp_get(struct thermal_zone_device *tzdev,
434382 return 0 ;
435383}
436384
437- static int
438- mlxsw_thermal_module_trip_type_get (struct thermal_zone_device * tzdev , int trip ,
439- enum thermal_trip_type * p_type )
440- {
441- struct mlxsw_thermal_module * tz = tzdev -> devdata ;
442-
443- if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS )
444- return - EINVAL ;
445-
446- * p_type = tz -> trips [trip ].type ;
447- return 0 ;
448- }
449-
450- static int
451- mlxsw_thermal_module_trip_temp_get (struct thermal_zone_device * tzdev ,
452- int trip , int * p_temp )
453- {
454- struct mlxsw_thermal_module * tz = tzdev -> devdata ;
455-
456- if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS )
457- return - EINVAL ;
458-
459- * p_temp = tz -> trips [trip ].temp ;
460- return 0 ;
461- }
462-
463- static int
464- mlxsw_thermal_module_trip_temp_set (struct thermal_zone_device * tzdev ,
465- int trip , int temp )
466- {
467- struct mlxsw_thermal_module * tz = tzdev -> devdata ;
468-
469- if (trip < 0 || trip >= MLXSW_THERMAL_NUM_TRIPS )
470- return - EINVAL ;
471-
472- tz -> trips [trip ].temp = temp ;
473- return 0 ;
474- }
475-
476- static int
477- mlxsw_thermal_module_trip_hyst_get (struct thermal_zone_device * tzdev , int trip ,
478- int * p_hyst )
479- {
480- struct mlxsw_thermal_module * tz = tzdev -> devdata ;
481-
482- * p_hyst = tz -> trips [trip ].hyst ;
483- return 0 ;
484- }
485-
486- static int
487- mlxsw_thermal_module_trip_hyst_set (struct thermal_zone_device * tzdev , int trip ,
488- int hyst )
489- {
490- struct mlxsw_thermal_module * tz = tzdev -> devdata ;
491-
492- tz -> trips [trip ].hyst = hyst ;
493- return 0 ;
494- }
495-
496385static struct thermal_zone_device_ops mlxsw_thermal_module_ops = {
497386 .bind = mlxsw_thermal_module_bind ,
498387 .unbind = mlxsw_thermal_module_unbind ,
499388 .get_temp = mlxsw_thermal_module_temp_get ,
500- .get_trip_type = mlxsw_thermal_module_trip_type_get ,
501- .get_trip_temp = mlxsw_thermal_module_trip_temp_get ,
502- .set_trip_temp = mlxsw_thermal_module_trip_temp_set ,
503- .get_trip_hyst = mlxsw_thermal_module_trip_hyst_get ,
504- .set_trip_hyst = mlxsw_thermal_module_trip_hyst_set ,
505389};
506390
507391static int mlxsw_thermal_gearbox_temp_get (struct thermal_zone_device * tzdev ,
@@ -531,11 +415,6 @@ static struct thermal_zone_device_ops mlxsw_thermal_gearbox_ops = {
531415 .bind = mlxsw_thermal_module_bind ,
532416 .unbind = mlxsw_thermal_module_unbind ,
533417 .get_temp = mlxsw_thermal_gearbox_temp_get ,
534- .get_trip_type = mlxsw_thermal_module_trip_type_get ,
535- .get_trip_temp = mlxsw_thermal_module_trip_temp_get ,
536- .set_trip_temp = mlxsw_thermal_module_trip_temp_set ,
537- .get_trip_hyst = mlxsw_thermal_module_trip_hyst_get ,
538- .set_trip_hyst = mlxsw_thermal_module_trip_hyst_set ,
539418};
540419
541420static int mlxsw_thermal_get_max_state (struct thermal_cooling_device * cdev ,
@@ -617,7 +496,8 @@ mlxsw_thermal_module_tz_init(struct mlxsw_thermal_module *module_tz)
617496 else
618497 snprintf (tz_name , sizeof (tz_name ), "mlxsw-module%d" ,
619498 module_tz -> module + 1 );
620- module_tz -> tzdev = thermal_zone_device_register (tz_name ,
499+ module_tz -> tzdev = thermal_zone_device_register_with_trips (tz_name ,
500+ module_tz -> trips ,
621501 MLXSW_THERMAL_NUM_TRIPS ,
622502 MLXSW_THERMAL_TRIP_MASK ,
623503 module_tz ,
@@ -661,6 +541,8 @@ mlxsw_thermal_module_init(struct device *dev, struct mlxsw_core *core,
661541 module_tz -> parent = thermal ;
662542 memcpy (module_tz -> trips , default_thermal_trips ,
663543 sizeof (thermal -> trips ));
544+ memcpy (module_tz -> cooling_states , default_cooling_states ,
545+ sizeof (thermal -> cooling_states ));
664546 /* Initialize all trip point. */
665547 mlxsw_thermal_module_trips_reset (module_tz );
666548 /* Read module temperature and thresholds. */
@@ -756,7 +638,8 @@ mlxsw_thermal_gearbox_tz_init(struct mlxsw_thermal_module *gearbox_tz)
756638 else
757639 snprintf (tz_name , sizeof (tz_name ), "mlxsw-gearbox%d" ,
758640 gearbox_tz -> module + 1 );
759- gearbox_tz -> tzdev = thermal_zone_device_register (tz_name ,
641+ gearbox_tz -> tzdev = thermal_zone_device_register_with_trips (tz_name ,
642+ gearbox_tz -> trips ,
760643 MLXSW_THERMAL_NUM_TRIPS ,
761644 MLXSW_THERMAL_TRIP_MASK ,
762645 gearbox_tz ,
@@ -813,6 +696,8 @@ mlxsw_thermal_gearboxes_init(struct device *dev, struct mlxsw_core *core,
813696 gearbox_tz = & area -> tz_gearbox_arr [i ];
814697 memcpy (gearbox_tz -> trips , default_thermal_trips ,
815698 sizeof (thermal -> trips ));
699+ memcpy (gearbox_tz -> cooling_states , default_cooling_states ,
700+ sizeof (thermal -> cooling_states ));
816701 gearbox_tz -> module = i ;
817702 gearbox_tz -> parent = thermal ;
818703 gearbox_tz -> slot_index = area -> slot_index ;
@@ -928,6 +813,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
928813 thermal -> core = core ;
929814 thermal -> bus_info = bus_info ;
930815 memcpy (thermal -> trips , default_thermal_trips , sizeof (thermal -> trips ));
816+ memcpy (thermal -> cooling_states , default_cooling_states , sizeof (thermal -> cooling_states ));
931817 thermal -> line_cards [0 ].slot_index = 0 ;
932818
933819 err = mlxsw_reg_query (thermal -> core , MLXSW_REG (mfcr ), mfcr_pl );
@@ -981,7 +867,8 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
981867 MLXSW_THERMAL_SLOW_POLL_INT :
982868 MLXSW_THERMAL_POLL_INT ;
983869
984- thermal -> tzdev = thermal_zone_device_register ("mlxsw" ,
870+ thermal -> tzdev = thermal_zone_device_register_with_trips ("mlxsw" ,
871+ thermal -> trips ,
985872 MLXSW_THERMAL_NUM_TRIPS ,
986873 MLXSW_THERMAL_TRIP_MASK ,
987874 thermal ,
0 commit comments