1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <subdev/bios.h>
26#include <subdev/bios/bit.h>
27#include <subdev/bios/therm.h>
28
29static u16
30therm_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *len, u8 *cnt)
31{
32 struct bit_entry bit_P;
33 u16 therm = 0;
34
35 if (!bit_entry(bios, 'P', &bit_P)) {
36 if (bit_P.version == 1)
37 therm = nv_ro16(bios, bit_P.offset + 12);
38 else if (bit_P.version == 2)
39 therm = nv_ro16(bios, bit_P.offset + 16);
40 else
41 nv_error(bios,
42 "unknown offset for thermal in BIT P %d\n",
43 bit_P.version);
44 }
45
46
47 if (!therm)
48 return 0x0000;
49
50 *ver = nv_ro08(bios, therm + 0);
51 *hdr = nv_ro08(bios, therm + 1);
52 *len = nv_ro08(bios, therm + 2);
53 *cnt = nv_ro08(bios, therm + 3);
54
55 return therm + nv_ro08(bios, therm + 1);
56}
57
58static u16
59nvbios_therm_entry(struct nouveau_bios *bios, int idx, u8 *ver, u8 *len)
60{
61 u8 hdr, cnt;
62 u16 therm = therm_table(bios, ver, &hdr, len, &cnt);
63 if (therm && idx < cnt)
64 return therm + idx * *len;
65 return 0x0000;
66}
67
68int
69nvbios_therm_sensor_parse(struct nouveau_bios *bios,
70 enum nvbios_therm_domain domain,
71 struct nvbios_therm_sensor *sensor)
72{
73 s8 thrs_section, sensor_section, offset;
74 u8 ver, len, i;
75 u16 entry;
76
77
78 if (domain != NVBIOS_THERM_DOMAIN_CORE)
79 return -EINVAL;
80
81
82 thrs_section = 0;
83 sensor_section = -1;
84 i = 0;
85 while ((entry = nvbios_therm_entry(bios, i++, &ver, &len))) {
86 s16 value = nv_ro16(bios, entry + 1);
87
88 switch (nv_ro08(bios, entry + 0)) {
89 case 0x0:
90 thrs_section = value;
91 if (value > 0)
92 return 0;
93 break;
94 case 0x01:
95 sensor_section++;
96 if (sensor_section == 0) {
97 offset = ((s8) nv_ro08(bios, entry + 2)) / 2;
98 sensor->offset_constant = offset;
99 }
100 break;
101
102 case 0x04:
103 if (thrs_section == 0) {
104 sensor->thrs_critical.temp = (value & 0xff0) >> 4;
105 sensor->thrs_critical.hysteresis = value & 0xf;
106 }
107 break;
108
109 case 0x07:
110 if (thrs_section == 0) {
111 sensor->thrs_down_clock.temp = (value & 0xff0) >> 4;
112 sensor->thrs_down_clock.hysteresis = value & 0xf;
113 }
114 break;
115
116 case 0x08:
117 if (thrs_section == 0) {
118 sensor->thrs_fan_boost.temp = (value & 0xff0) >> 4;
119 sensor->thrs_fan_boost.hysteresis = value & 0xf;
120 }
121 break;
122
123 case 0x10:
124 if (sensor_section == 0)
125 sensor->offset_num = value;
126 break;
127
128 case 0x11:
129 if (sensor_section == 0)
130 sensor->offset_den = value;
131 break;
132
133 case 0x12:
134 if (sensor_section == 0)
135 sensor->slope_mult = value;
136 break;
137
138 case 0x13:
139 if (sensor_section == 0)
140 sensor->slope_div = value;
141 break;
142 case 0x32:
143 if (thrs_section == 0) {
144 sensor->thrs_shutdown.temp = (value & 0xff0) >> 4;
145 sensor->thrs_shutdown.hysteresis = value & 0xf;
146 }
147 break;
148 }
149 }
150
151 return 0;
152}
153
154int
155nvbios_therm_fan_parse(struct nouveau_bios *bios,
156 struct nvbios_therm_fan *fan)
157{
158 struct nouveau_therm_trip_point *cur_trip = NULL;
159 u8 ver, len, i;
160 u16 entry;
161
162 uint8_t duty_lut[] = { 0, 0, 25, 0, 40, 0, 50, 0,
163 75, 0, 85, 0, 100, 0, 100, 0 };
164
165 i = 0;
166 fan->nr_fan_trip = 0;
167 fan->fan_mode = NVBIOS_THERM_FAN_OTHER;
168 while ((entry = nvbios_therm_entry(bios, i++, &ver, &len))) {
169 s16 value = nv_ro16(bios, entry + 1);
170
171 switch (nv_ro08(bios, entry + 0)) {
172 case 0x22:
173 fan->min_duty = value & 0xff;
174 fan->max_duty = (value & 0xff00) >> 8;
175 break;
176 case 0x24:
177 fan->nr_fan_trip++;
178 if (fan->fan_mode > NVBIOS_THERM_FAN_TRIP)
179 fan->fan_mode = NVBIOS_THERM_FAN_TRIP;
180 cur_trip = &fan->trip[fan->nr_fan_trip - 1];
181 cur_trip->hysteresis = value & 0xf;
182 cur_trip->temp = (value & 0xff0) >> 4;
183 cur_trip->fan_duty = duty_lut[(value & 0xf000) >> 12];
184 break;
185 case 0x25:
186 cur_trip = &fan->trip[fan->nr_fan_trip - 1];
187 cur_trip->fan_duty = value;
188 break;
189 case 0x26:
190 if (!fan->pwm_freq)
191 fan->pwm_freq = value;
192 break;
193 case 0x3b:
194 fan->bump_period = value;
195 break;
196 case 0x3c:
197 fan->slow_down_period = value;
198 break;
199 case 0x46:
200 if (fan->fan_mode > NVBIOS_THERM_FAN_LINEAR)
201 fan->fan_mode = NVBIOS_THERM_FAN_LINEAR;
202 fan->linear_min_temp = nv_ro08(bios, entry + 1);
203 fan->linear_max_temp = nv_ro08(bios, entry + 2);
204 break;
205 }
206 }
207
208
209 if (nv_device(bios)->card_type >= NV_C0 &&
210 fan->fan_mode == NVBIOS_THERM_FAN_OTHER) {
211 fan->fan_mode = NVBIOS_THERM_FAN_LINEAR;
212 }
213
214 return 0;
215}
216