1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2017 Chelsio Communications. All rights reserved.
5 * Written by: Ganesh Goudar (ganeshgr@chelsio.com)
10 #define CXGB4_NUM_TRIPS 1
12 static int cxgb4_thermal_get_temp(struct thermal_zone_device
*tzdev
,
15 struct adapter
*adap
= tzdev
->devdata
;
19 param
= (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV
) |
20 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG
) |
21 FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP
));
23 ret
= t4_query_params(adap
, adap
->mbox
, adap
->pf
, 0, 1,
25 if (ret
< 0 || val
== 0)
32 static int cxgb4_thermal_get_trip_type(struct thermal_zone_device
*tzdev
,
33 int trip
, enum thermal_trip_type
*type
)
35 struct adapter
*adap
= tzdev
->devdata
;
37 if (!adap
->ch_thermal
.trip_temp
)
40 *type
= adap
->ch_thermal
.trip_type
;
44 static int cxgb4_thermal_get_trip_temp(struct thermal_zone_device
*tzdev
,
47 struct adapter
*adap
= tzdev
->devdata
;
49 if (!adap
->ch_thermal
.trip_temp
)
52 *temp
= adap
->ch_thermal
.trip_temp
;
56 static struct thermal_zone_device_ops cxgb4_thermal_ops
= {
57 .get_temp
= cxgb4_thermal_get_temp
,
58 .get_trip_type
= cxgb4_thermal_get_trip_type
,
59 .get_trip_temp
= cxgb4_thermal_get_trip_temp
,
62 int cxgb4_thermal_init(struct adapter
*adap
)
64 struct ch_thermal
*ch_thermal
= &adap
->ch_thermal
;
65 int num_trip
= CXGB4_NUM_TRIPS
;
69 /* on older firmwares we may not get the trip temperature,
70 * set the num of trips to 0.
72 param
= (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV
) |
73 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG
) |
74 FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_MAXTMPTHRESH
));
76 ret
= t4_query_params(adap
, adap
->mbox
, adap
->pf
, 0, 1,
79 num_trip
= 0; /* could not get trip temperature */
81 ch_thermal
->trip_temp
= val
* 1000;
82 ch_thermal
->trip_type
= THERMAL_TRIP_CRITICAL
;
85 ch_thermal
->tzdev
= thermal_zone_device_register("cxgb4", num_trip
,
89 if (IS_ERR(ch_thermal
->tzdev
)) {
90 ret
= PTR_ERR(ch_thermal
->tzdev
);
91 dev_err(adap
->pdev_dev
, "Failed to register thermal zone\n");
92 ch_thermal
->tzdev
= NULL
;
98 int cxgb4_thermal_remove(struct adapter
*adap
)
100 if (adap
->ch_thermal
.tzdev
)
101 thermal_zone_device_unregister(adap
->ch_thermal
.tzdev
);