blob: 54e3d9222f799fff51ee0ddd9416b186da4177c1 [file] [log] [blame]
Martin Peres34e9d852010-09-22 20:54:22 +02001/*
2 * Copyright 2010 PathScale inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Martin Peres
23 */
24
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28#include "nouveau_pm.h"
29
30void
31nouveau_temp_vbios_parse(struct drm_device *dev, u8 *temp)
32{
33 struct drm_nouveau_private *dev_priv = dev->dev_private;
34 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
35 struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
36 struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
37 int i, headerlen, recordlen, entries;
38
39 if (!temp) {
40 NV_DEBUG(dev, "temperature table pointer invalid\n");
41 return;
42 }
43
44 /* Set the default sensor's contants */
45 sensor->offset_constant = 0;
46 sensor->offset_mult = 1;
47 sensor->offset_div = 1;
48 sensor->slope_mult = 1;
49 sensor->slope_div = 1;
50
51 /* Set the default temperature thresholds */
52 temps->critical = 110;
53 temps->down_clock = 100;
54 temps->fan_boost = 90;
55
56 /* Set the known default values to setup the temperature sensor */
57 if (dev_priv->card_type >= NV_40) {
58 switch (dev_priv->chipset) {
59 case 0x43:
60 sensor->offset_mult = 32060;
61 sensor->offset_div = 1000;
62 sensor->slope_mult = 792;
63 sensor->slope_div = 1000;
64 break;
65
66 case 0x44:
67 case 0x47:
Francisco Jerezd34ec502010-09-23 16:27:14 +020068 case 0x4a:
Martin Peres34e9d852010-09-22 20:54:22 +020069 sensor->offset_mult = 27839;
70 sensor->offset_div = 1000;
71 sensor->slope_mult = 780;
72 sensor->slope_div = 1000;
73 break;
74
75 case 0x46:
76 sensor->offset_mult = -24775;
77 sensor->offset_div = 100;
78 sensor->slope_mult = 467;
79 sensor->slope_div = 10000;
80 break;
81
82 case 0x49:
83 sensor->offset_mult = -25051;
84 sensor->offset_div = 100;
85 sensor->slope_mult = 458;
86 sensor->slope_div = 10000;
87 break;
88
89 case 0x4b:
90 sensor->offset_mult = -24088;
91 sensor->offset_div = 100;
92 sensor->slope_mult = 442;
93 sensor->slope_div = 10000;
94 break;
95
96 case 0x50:
97 sensor->offset_mult = -22749;
98 sensor->offset_div = 100;
99 sensor->slope_mult = 431;
100 sensor->slope_div = 10000;
101 break;
102 }
103 }
104
105 headerlen = temp[1];
106 recordlen = temp[2];
107 entries = temp[3];
108 temp = temp + headerlen;
109
110 /* Read the entries from the table */
111 for (i = 0; i < entries; i++) {
112 u16 value = ROM16(temp[1]);
113
114 switch (temp[0]) {
115 case 0x01:
116 value = (value&0x8f) == 0 ? (value >> 9) & 0x7f : 0;
117 sensor->offset_constant = value;
118 break;
119
120 case 0x04:
121 if ((value & 0xf00f) == 0xa000) /* core */
122 temps->critical = (value&0x0ff0) >> 4;
123 break;
124
125 case 0x07:
126 if ((value & 0xf00f) == 0xa000) /* core */
127 temps->down_clock = (value&0x0ff0) >> 4;
128 break;
129
130 case 0x08:
131 if ((value & 0xf00f) == 0xa000) /* core */
132 temps->fan_boost = (value&0x0ff0) >> 4;
133 break;
134
135 case 0x10:
136 sensor->offset_mult = value;
137 break;
138
139 case 0x11:
140 sensor->offset_div = value;
141 break;
142
143 case 0x12:
144 sensor->slope_mult = value;
145 break;
146
147 case 0x13:
148 sensor->slope_div = value;
149 break;
150 }
151 temp += recordlen;
152 }
153
154 nouveau_temp_safety_checks(dev);
155}
156
157static s16
158nouveau_nv40_sensor_setup(struct drm_device *dev)
159{
160 struct drm_nouveau_private *dev_priv = dev->dev_private;
161 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
162 struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
163 u32 offset = sensor->offset_mult / sensor->offset_div;
164 u32 sensor_calibration;
165
166 /* set up the sensors */
167 sensor_calibration = 120 - offset - sensor->offset_constant;
168 sensor_calibration = sensor_calibration * sensor->slope_div /
169 sensor->slope_mult;
170
171 if (dev_priv->chipset >= 0x46)
172 sensor_calibration |= 0x80000000;
173 else
174 sensor_calibration |= 0x10000000;
175
176 nv_wr32(dev, 0x0015b0, sensor_calibration);
177
178 /* Wait for the sensor to update */
179 msleep(5);
180
181 /* read */
Francesco Marella41647432010-09-23 09:14:22 +0200182 return nv_rd32(dev, 0x0015b4) & 0x1fff;
Martin Peres34e9d852010-09-22 20:54:22 +0200183}
184
185s16
186nouveau_temp_get(struct drm_device *dev)
187{
188 struct drm_nouveau_private *dev_priv = dev->dev_private;
189 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
190 struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
191
192 if (dev_priv->chipset >= 0x84) {
193 return nv_rd32(dev, 0x20400);
194 } else if (dev_priv->chipset >= 0x40) {
195 u32 offset = sensor->offset_mult / sensor->offset_div;
196 u32 core_temp;
197
198 if (dev_priv->chipset >= 0x50) {
199 core_temp = nv_rd32(dev, 0x20008);
200 } else {
Francesco Marella41647432010-09-23 09:14:22 +0200201 core_temp = nv_rd32(dev, 0x0015b4) & 0x1fff;
Martin Peres34e9d852010-09-22 20:54:22 +0200202 /* Setup the sensor if the temperature is 0 */
203 if (core_temp == 0)
204 core_temp = nouveau_nv40_sensor_setup(dev);
205 }
206
207 core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
208 core_temp = core_temp + offset + sensor->offset_constant;
209
210 return core_temp;
211 } else {
212 NV_ERROR(dev,
213 "Temperature cannot be retrieved from an nv%x card\n",
214 dev_priv->chipset);
215 return 0;
216 }
217
218 return 0;
219}
220
221void
222nouveau_temp_safety_checks(struct drm_device *dev)
223{
224 struct drm_nouveau_private *dev_priv = dev->dev_private;
225 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
226 struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
227
228 if (temps->critical > 120)
229 temps->critical = 120;
230 else if (temps->critical < 80)
231 temps->critical = 80;
232
233 if (temps->down_clock > 110)
234 temps->down_clock = 110;
235 else if (temps->down_clock < 60)
236 temps->down_clock = 60;
237
238 if (temps->fan_boost > 100)
239 temps->fan_boost = 100;
240 else if (temps->fan_boost < 40)
241 temps->fan_boost = 40;
242}
243
244void
245nouveau_temp_init(struct drm_device *dev)
246{
247 struct drm_nouveau_private *dev_priv = dev->dev_private;
248 struct nvbios *bios = &dev_priv->vbios;
249 struct bit_entry P;
250 u8 *temp = NULL;
251
252 if (bios->type == NVBIOS_BIT) {
253 if (bit_table(dev, 'P', &P))
254 return;
255
256 if (P.version == 1)
257 temp = ROMPTR(bios, P.data[12]);
258 else if (P.version == 2)
259 temp = ROMPTR(bios, P.data[16]);
260 else
261 NV_WARN(dev, "unknown temp for BIT P %d\n", P.version);
262 } else {
263 NV_WARN(dev, "BMP entry unknown for temperature table.\n");
264 }
265
266 nouveau_temp_vbios_parse(dev, temp);
267}
268
269void
270nouveau_temp_fini(struct drm_device *dev)
271{
272
273}