2 * Copyright 2012 Nouveau Community
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Martin Peres
24 #include <subdev/bios.h>
25 #include <subdev/bios/bit.h>
26 #include <subdev/bios/therm.h>
28 #include <core/device.h>
31 therm_table(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *len, u8 *cnt)
33 struct bit_entry bit_P;
36 if (!bit_entry(bios, 'P', &bit_P)) {
37 if (bit_P.version == 1)
38 therm = nv_ro16(bios, bit_P.offset + 12);
39 else if (bit_P.version == 2)
40 therm = nv_ro16(bios, bit_P.offset + 16);
43 "unknown offset for thermal in BIT P %d\n",
47 /* exit now if we haven't found the thermal table */
51 *ver = nv_ro08(bios, therm + 0);
52 *hdr = nv_ro08(bios, therm + 1);
53 *len = nv_ro08(bios, therm + 2);
54 *cnt = nv_ro08(bios, therm + 3);
55 return therm + nv_ro08(bios, therm + 1);
59 nvbios_therm_entry(struct nvkm_bios *bios, int idx, u8 *ver, u8 *len)
62 u16 therm = therm_table(bios, ver, &hdr, len, &cnt);
63 if (therm && idx < cnt)
64 return therm + idx * *len;
69 nvbios_therm_sensor_parse(struct nvkm_bios *bios,
70 enum nvbios_therm_domain domain,
71 struct nvbios_therm_sensor *sensor)
73 s8 thrs_section, sensor_section, offset;
77 /* we only support the core domain for now */
78 if (domain != NVBIOS_THERM_DOMAIN_CORE)
81 /* Read the entries from the table */
85 while ((entry = nvbios_therm_entry(bios, i++, &ver, &len))) {
86 s16 value = nv_ro16(bios, entry + 1);
88 switch (nv_ro08(bios, entry + 0)) {
92 return 0; /* we do not try to support ambient */
96 if (sensor_section == 0) {
97 offset = ((s8) nv_ro08(bios, entry + 2)) / 2;
98 sensor->offset_constant = offset;
103 if (thrs_section == 0) {
104 sensor->thrs_critical.temp = (value & 0xff0) >> 4;
105 sensor->thrs_critical.hysteresis = value & 0xf;
110 if (thrs_section == 0) {
111 sensor->thrs_down_clock.temp = (value & 0xff0) >> 4;
112 sensor->thrs_down_clock.hysteresis = value & 0xf;
117 if (thrs_section == 0) {
118 sensor->thrs_fan_boost.temp = (value & 0xff0) >> 4;
119 sensor->thrs_fan_boost.hysteresis = value & 0xf;
124 if (sensor_section == 0)
125 sensor->offset_num = value;
129 if (sensor_section == 0)
130 sensor->offset_den = value;
134 if (sensor_section == 0)
135 sensor->slope_mult = value;
139 if (sensor_section == 0)
140 sensor->slope_div = value;
143 if (thrs_section == 0) {
144 sensor->thrs_shutdown.temp = (value & 0xff0) >> 4;
145 sensor->thrs_shutdown.hysteresis = value & 0xf;
155 nvbios_therm_fan_parse(struct nvkm_bios *bios, struct nvbios_therm_fan *fan)
157 struct nvbios_therm_trip_point *cur_trip = NULL;
161 uint8_t duty_lut[] = { 0, 0, 25, 0, 40, 0, 50, 0,
162 75, 0, 85, 0, 100, 0, 100, 0 };
165 fan->nr_fan_trip = 0;
166 fan->fan_mode = NVBIOS_THERM_FAN_OTHER;
167 while ((entry = nvbios_therm_entry(bios, i++, &ver, &len))) {
168 s16 value = nv_ro16(bios, entry + 1);
170 switch (nv_ro08(bios, entry + 0)) {
172 fan->min_duty = value & 0xff;
173 fan->max_duty = (value & 0xff00) >> 8;
177 if (fan->fan_mode > NVBIOS_THERM_FAN_TRIP)
178 fan->fan_mode = NVBIOS_THERM_FAN_TRIP;
179 cur_trip = &fan->trip[fan->nr_fan_trip - 1];
180 cur_trip->hysteresis = value & 0xf;
181 cur_trip->temp = (value & 0xff0) >> 4;
182 cur_trip->fan_duty = duty_lut[(value & 0xf000) >> 12];
185 cur_trip = &fan->trip[fan->nr_fan_trip - 1];
186 cur_trip->fan_duty = value;
190 fan->pwm_freq = value;
193 fan->bump_period = value;
196 fan->slow_down_period = value;
199 if (fan->fan_mode > NVBIOS_THERM_FAN_LINEAR)
200 fan->fan_mode = NVBIOS_THERM_FAN_LINEAR;
201 fan->linear_min_temp = nv_ro08(bios, entry + 1);
202 fan->linear_max_temp = nv_ro08(bios, entry + 2);
207 /* starting from fermi, fan management is always linear */
208 if (nv_device(bios)->card_type >= NV_C0 &&
209 fan->fan_mode == NVBIOS_THERM_FAN_OTHER) {
210 fan->fan_mode = NVBIOS_THERM_FAN_LINEAR;