2 * Copyright (C) 2017 Chelsio Communications. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
16 * Written by: Ganesh Goudar (ganeshgr@chelsio.com)
21 #define CXGB4_NUM_TRIPS 1
23 static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev,
26 struct adapter *adap = tzdev->devdata;
30 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
31 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
32 FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_TMP));
34 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
36 if (ret < 0 || val == 0)
43 static int cxgb4_thermal_get_trip_type(struct thermal_zone_device *tzdev,
44 int trip, enum thermal_trip_type *type)
46 struct adapter *adap = tzdev->devdata;
48 if (!adap->ch_thermal.trip_temp)
51 *type = adap->ch_thermal.trip_type;
55 static int cxgb4_thermal_get_trip_temp(struct thermal_zone_device *tzdev,
58 struct adapter *adap = tzdev->devdata;
60 if (!adap->ch_thermal.trip_temp)
63 *temp = adap->ch_thermal.trip_temp;
67 static struct thermal_zone_device_ops cxgb4_thermal_ops = {
68 .get_temp = cxgb4_thermal_get_temp,
69 .get_trip_type = cxgb4_thermal_get_trip_type,
70 .get_trip_temp = cxgb4_thermal_get_trip_temp,
73 int cxgb4_thermal_init(struct adapter *adap)
75 struct ch_thermal *ch_thermal = &adap->ch_thermal;
76 int num_trip = CXGB4_NUM_TRIPS;
80 /* on older firmwares we may not get the trip temperature,
81 * set the num of trips to 0.
83 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
84 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DIAG) |
85 FW_PARAMS_PARAM_Y_V(FW_PARAM_DEV_DIAG_MAXTMPTHRESH));
87 ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
90 num_trip = 0; /* could not get trip temperature */
92 ch_thermal->trip_temp = val * 1000;
93 ch_thermal->trip_type = THERMAL_TRIP_CRITICAL;
96 ch_thermal->tzdev = thermal_zone_device_register("cxgb4", num_trip,
100 if (IS_ERR(ch_thermal->tzdev)) {
101 ret = PTR_ERR(ch_thermal->tzdev);
102 dev_err(adap->pdev_dev, "Failed to register thermal zone\n");
103 ch_thermal->tzdev = NULL;
109 int cxgb4_thermal_remove(struct adapter *adap)
111 if (adap->ch_thermal.tzdev)
112 thermal_zone_device_unregister(adap->ch_thermal.tzdev);