@@ -100,6 +100,12 @@ static const struct mlxsw_cooling_states default_cooling_states[] = {
100
100
101
101
struct mlxsw_thermal ;
102
102
103
+ struct mlxsw_thermal_cooling_device {
104
+ struct mlxsw_thermal * thermal ;
105
+ struct thermal_cooling_device * cdev ;
106
+ unsigned int idx ;
107
+ };
108
+
103
109
struct mlxsw_thermal_module {
104
110
struct mlxsw_thermal * parent ;
105
111
struct thermal_zone_device * tzdev ;
@@ -123,7 +129,7 @@ struct mlxsw_thermal {
123
129
const struct mlxsw_bus_info * bus_info ;
124
130
struct thermal_zone_device * tzdev ;
125
131
int polling_delay ;
126
- struct thermal_cooling_device * cdevs [MLXSW_MFCR_PWMS_MAX ];
132
+ struct mlxsw_thermal_cooling_device cdevs [MLXSW_MFCR_PWMS_MAX ];
127
133
struct thermal_trip trips [MLXSW_THERMAL_NUM_TRIPS ];
128
134
struct mlxsw_cooling_states cooling_states [MLXSW_THERMAL_NUM_TRIPS ];
129
135
struct mlxsw_thermal_area line_cards [];
@@ -147,7 +153,7 @@ static int mlxsw_get_cooling_device_idx(struct mlxsw_thermal *thermal,
147
153
int i ;
148
154
149
155
for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ )
150
- if (thermal -> cdevs [i ] == cdev )
156
+ if (thermal -> cdevs [i ]. cdev == cdev )
151
157
return i ;
152
158
153
159
/* Allow mlxsw thermal zone binding to an external cooling device */
@@ -352,17 +358,14 @@ static int mlxsw_thermal_get_cur_state(struct thermal_cooling_device *cdev,
352
358
unsigned long * p_state )
353
359
354
360
{
355
- struct mlxsw_thermal * thermal = cdev -> devdata ;
361
+ struct mlxsw_thermal_cooling_device * mlxsw_cdev = cdev -> devdata ;
362
+ struct mlxsw_thermal * thermal = mlxsw_cdev -> thermal ;
356
363
struct device * dev = thermal -> bus_info -> dev ;
357
364
char mfsc_pl [MLXSW_REG_MFSC_LEN ];
358
- int err , idx ;
359
365
u8 duty ;
366
+ int err ;
360
367
361
- idx = mlxsw_get_cooling_device_idx (thermal , cdev );
362
- if (idx < 0 )
363
- return idx ;
364
-
365
- mlxsw_reg_mfsc_pack (mfsc_pl , idx , 0 );
368
+ mlxsw_reg_mfsc_pack (mfsc_pl , mlxsw_cdev -> idx , 0 );
366
369
err = mlxsw_reg_query (thermal -> core , MLXSW_REG (mfsc ), mfsc_pl );
367
370
if (err ) {
368
371
dev_err (dev , "Failed to query PWM duty\n" );
@@ -378,22 +381,19 @@ static int mlxsw_thermal_set_cur_state(struct thermal_cooling_device *cdev,
378
381
unsigned long state )
379
382
380
383
{
381
- struct mlxsw_thermal * thermal = cdev -> devdata ;
384
+ struct mlxsw_thermal_cooling_device * mlxsw_cdev = cdev -> devdata ;
385
+ struct mlxsw_thermal * thermal = mlxsw_cdev -> thermal ;
382
386
struct device * dev = thermal -> bus_info -> dev ;
383
387
char mfsc_pl [MLXSW_REG_MFSC_LEN ];
384
- int idx ;
385
388
int err ;
386
389
387
390
if (state > MLXSW_THERMAL_MAX_STATE )
388
391
return - EINVAL ;
389
392
390
- idx = mlxsw_get_cooling_device_idx (thermal , cdev );
391
- if (idx < 0 )
392
- return idx ;
393
-
394
393
/* Normalize the state to the valid speed range. */
395
394
state = max_t (unsigned long , MLXSW_THERMAL_MIN_STATE , state );
396
- mlxsw_reg_mfsc_pack (mfsc_pl , idx , mlxsw_state_to_duty (state ));
395
+ mlxsw_reg_mfsc_pack (mfsc_pl , mlxsw_cdev -> idx ,
396
+ mlxsw_state_to_duty (state ));
397
397
err = mlxsw_reg_write (thermal -> core , MLXSW_REG (mfsc ), mfsc_pl );
398
398
if (err ) {
399
399
dev_err (dev , "Failed to write PWM duty\n" );
@@ -753,17 +753,21 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
753
753
}
754
754
for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ ) {
755
755
if (pwm_active & BIT (i )) {
756
+ struct mlxsw_thermal_cooling_device * mlxsw_cdev ;
756
757
struct thermal_cooling_device * cdev ;
757
758
759
+ mlxsw_cdev = & thermal -> cdevs [i ];
760
+ mlxsw_cdev -> thermal = thermal ;
761
+ mlxsw_cdev -> idx = i ;
758
762
cdev = thermal_cooling_device_register ("mlxsw_fan" ,
759
- thermal ,
763
+ mlxsw_cdev ,
760
764
& mlxsw_cooling_ops );
761
765
if (IS_ERR (cdev )) {
762
766
err = PTR_ERR (cdev );
763
767
dev_err (dev , "Failed to register cooling device\n" );
764
768
goto err_thermal_cooling_device_register ;
765
769
}
766
- thermal -> cdevs [ i ] = cdev ;
770
+ mlxsw_cdev -> cdev = cdev ;
767
771
}
768
772
}
769
773
@@ -824,8 +828,7 @@ int mlxsw_thermal_init(struct mlxsw_core *core,
824
828
err_thermal_zone_device_register :
825
829
err_thermal_cooling_device_register :
826
830
for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ )
827
- if (thermal -> cdevs [i ])
828
- thermal_cooling_device_unregister (thermal -> cdevs [i ]);
831
+ thermal_cooling_device_unregister (thermal -> cdevs [i ].cdev );
829
832
err_reg_write :
830
833
err_reg_query :
831
834
kfree (thermal );
@@ -847,12 +850,8 @@ void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)
847
850
thermal -> tzdev = NULL ;
848
851
}
849
852
850
- for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ ) {
851
- if (thermal -> cdevs [i ]) {
852
- thermal_cooling_device_unregister (thermal -> cdevs [i ]);
853
- thermal -> cdevs [i ] = NULL ;
854
- }
855
- }
853
+ for (i = 0 ; i < MLXSW_MFCR_PWMS_MAX ; i ++ )
854
+ thermal_cooling_device_unregister (thermal -> cdevs [i ].cdev );
856
855
857
856
kfree (thermal );
858
857
}
0 commit comments