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 = thermal_zone_device_priv(tzdev);
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 struct thermal_zone_device_ops cxgb4_thermal_ops = {
33 .get_temp = cxgb4_thermal_get_temp,
36 static struct thermal_trip trip = { .type = THERMAL_TRIP_CRITICAL } ;
38 int cxgb4_thermal_init(struct adapter *adap)
40 struct ch_thermal *ch_thermal = &adap->ch_thermal;
41 char ch_tz_name[THERMAL_NAME_LENGTH];
42 int num_trip = CXGB4_NUM_TRIPS;
46 /* on older firmwares we may not get the trip temperature,
47 * set the num of trips to 0.
49 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
50 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
51 FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_MAXTMPTHRESH));
53 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
56 num_trip = 0; /* could not get trip temperature */
58 trip.temperature = val * 1000;
61 snprintf(ch_tz_name, sizeof(ch_tz_name), "cxgb4_%s", adap->name);
62 ch_thermal->tzdev = thermal_zone_device_register_with_trips(ch_tz_name, &trip, num_trip,
66 if (IS_ERR(ch_thermal->tzdev)) {
67 ret = PTR_ERR(ch_thermal->tzdev);
68 dev_err(adap->pdev_dev, "Failed to register thermal zone\n");
69 ch_thermal->tzdev = NULL;
73 ret = thermal_zone_device_enable(ch_thermal->tzdev);
75 dev_err(adap->pdev_dev, "Failed to enable thermal zone\n");
76 thermal_zone_device_unregister(adap->ch_thermal.tzdev);
83 int cxgb4_thermal_remove(struct adapter *adap)
85 if (adap->ch_thermal.tzdev) {
86 thermal_zone_device_unregister(adap->ch_thermal.tzdev);
87 adap->ch_thermal.tzdev = NULL;