Commit | Line | Data |
---|---|---|
4fa9c49f | 1 | // SPDX-License-Identifier: GPL-2.0-only |
b1871915 GG |
2 | /* |
3 | * Copyright (C) 2017 Chelsio Communications. All rights reserved. | |
4 | * | |
b1871915 GG |
5 | * Written by: Ganesh Goudar (ganeshgr@chelsio.com) |
6 | */ | |
7 | ||
8 | #include "cxgb4.h" | |
9 | ||
10 | #define CXGB4_NUM_TRIPS 1 | |
11 | ||
12 | static int cxgb4_thermal_get_temp(struct thermal_zone_device *tzdev, | |
13 | int *temp) | |
14 | { | |
3d4e1bad | 15 | struct adapter *adap = thermal_zone_device_priv(tzdev); |
b1871915 GG |
16 | u32 param, val; |
17 | int ret; | |
18 | ||
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)); | |
22 | ||
23 | ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, | |
24 | ¶m, &val); | |
25 | if (ret < 0 || val == 0) | |
26 | return -1; | |
27 | ||
28 | *temp = val * 1000; | |
29 | return 0; | |
30 | } | |
31 | ||
b1871915 GG |
32 | static struct thermal_zone_device_ops cxgb4_thermal_ops = { |
33 | .get_temp = cxgb4_thermal_get_temp, | |
b1871915 GG |
34 | }; |
35 | ||
9ddcb809 DL |
36 | static struct thermal_trip trip = { .type = THERMAL_TRIP_CRITICAL } ; |
37 | ||
b1871915 GG |
38 | int cxgb4_thermal_init(struct adapter *adap) |
39 | { | |
40 | struct ch_thermal *ch_thermal = &adap->ch_thermal; | |
6b6382a8 | 41 | char ch_tz_name[THERMAL_NAME_LENGTH]; |
b1871915 GG |
42 | int num_trip = CXGB4_NUM_TRIPS; |
43 | u32 param, val; | |
44 | int ret; | |
45 | ||
46 | /* on older firmwares we may not get the trip temperature, | |
47 | * set the num of trips to 0. | |
48 | */ | |
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)); | |
52 | ||
53 | ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, | |
54 | ¶m, &val); | |
55 | if (ret < 0) { | |
56 | num_trip = 0; /* could not get trip temperature */ | |
57 | } else { | |
9ddcb809 | 58 | trip.temperature = val * 1000; |
b1871915 GG |
59 | } |
60 | ||
6b6382a8 | 61 | snprintf(ch_tz_name, sizeof(ch_tz_name), "cxgb4_%s", adap->name); |
9ddcb809 | 62 | ch_thermal->tzdev = thermal_zone_device_register_with_trips(ch_tz_name, &trip, num_trip, |
4a62d588 | 63 | adap, |
9ddcb809 DL |
64 | &cxgb4_thermal_ops, |
65 | NULL, 0, 0); | |
b1871915 GG |
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; | |
70 | return ret; | |
71 | } | |
bbcf90c0 AP |
72 | |
73 | ret = thermal_zone_device_enable(ch_thermal->tzdev); | |
74 | if (ret) { | |
75 | dev_err(adap->pdev_dev, "Failed to enable thermal zone\n"); | |
76 | thermal_zone_device_unregister(adap->ch_thermal.tzdev); | |
77 | return ret; | |
78 | } | |
79 | ||
b1871915 GG |
80 | return 0; |
81 | } | |
82 | ||
83 | int cxgb4_thermal_remove(struct adapter *adap) | |
84 | { | |
6b6382a8 | 85 | if (adap->ch_thermal.tzdev) { |
b1871915 | 86 | thermal_zone_device_unregister(adap->ch_thermal.tzdev); |
6b6382a8 PBT |
87 | adap->ch_thermal.tzdev = NULL; |
88 | } | |
b1871915 GG |
89 | return 0; |
90 | } |