2 * Copyright 2010 PathScale inc.
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
26 #include <linux/module.h>
28 #include "nouveau_drv.h"
29 #include "nouveau_pm.h"
32 nouveau_temp_vbios_parse(struct drm_device
*dev
, u8
*temp
)
34 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
35 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
36 struct nouveau_pm_temp_sensor_constants
*sensor
= &pm
->sensor_constants
;
37 struct nouveau_pm_threshold_temp
*temps
= &pm
->threshold_temp
;
38 int i
, headerlen
, recordlen
, entries
;
41 NV_DEBUG(dev
, "temperature table pointer invalid\n");
45 /* Set the default sensor's contants */
46 sensor
->offset_constant
= 0;
47 sensor
->offset_mult
= 1;
48 sensor
->offset_div
= 1;
49 sensor
->slope_mult
= 1;
50 sensor
->slope_div
= 1;
52 /* Set the default temperature thresholds */
53 temps
->critical
= 110;
54 temps
->down_clock
= 100;
55 temps
->fan_boost
= 90;
57 /* Set the known default values to setup the temperature sensor */
58 if (dev_priv
->card_type
>= NV_40
) {
59 switch (dev_priv
->chipset
) {
61 sensor
->offset_mult
= 32060;
62 sensor
->offset_div
= 1000;
63 sensor
->slope_mult
= 792;
64 sensor
->slope_div
= 1000;
70 sensor
->offset_mult
= 27839;
71 sensor
->offset_div
= 1000;
72 sensor
->slope_mult
= 780;
73 sensor
->slope_div
= 1000;
77 sensor
->offset_mult
= -24775;
78 sensor
->offset_div
= 100;
79 sensor
->slope_mult
= 467;
80 sensor
->slope_div
= 10000;
84 sensor
->offset_mult
= -25051;
85 sensor
->offset_div
= 100;
86 sensor
->slope_mult
= 458;
87 sensor
->slope_div
= 10000;
91 sensor
->offset_mult
= -24088;
92 sensor
->offset_div
= 100;
93 sensor
->slope_mult
= 442;
94 sensor
->slope_div
= 10000;
98 sensor
->offset_mult
= -22749;
99 sensor
->offset_div
= 100;
100 sensor
->slope_mult
= 431;
101 sensor
->slope_div
= 10000;
109 temp
= temp
+ headerlen
;
111 /* Read the entries from the table */
112 for (i
= 0; i
< entries
; i
++) {
113 u16 value
= ROM16(temp
[1]);
117 if ((value
& 0x8f) == 0)
118 sensor
->offset_constant
= (value
>> 9) & 0x7f;
122 if ((value
& 0xf00f) == 0xa000) /* core */
123 temps
->critical
= (value
&0x0ff0) >> 4;
127 if ((value
& 0xf00f) == 0xa000) /* core */
128 temps
->down_clock
= (value
&0x0ff0) >> 4;
132 if ((value
& 0xf00f) == 0xa000) /* core */
133 temps
->fan_boost
= (value
&0x0ff0) >> 4;
137 sensor
->offset_mult
= value
;
141 sensor
->offset_div
= value
;
145 sensor
->slope_mult
= value
;
149 sensor
->slope_div
= value
;
152 pm
->fan
.min_duty
= value
& 0xff;
153 pm
->fan
.max_duty
= (value
& 0xff00) >> 8;
156 pm
->fan
.pwm_freq
= value
;
162 nouveau_temp_safety_checks(dev
);
164 /* check the fan min/max settings */
165 if (pm
->fan
.min_duty
< 10)
166 pm
->fan
.min_duty
= 10;
167 if (pm
->fan
.max_duty
> 100)
168 pm
->fan
.max_duty
= 100;
169 if (pm
->fan
.max_duty
< pm
->fan
.min_duty
)
170 pm
->fan
.max_duty
= pm
->fan
.min_duty
;
174 nv40_sensor_setup(struct drm_device
*dev
)
176 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
177 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
178 struct nouveau_pm_temp_sensor_constants
*sensor
= &pm
->sensor_constants
;
179 u32 offset
= sensor
->offset_mult
/ sensor
->offset_div
;
180 u32 sensor_calibration
;
182 /* set up the sensors */
183 sensor_calibration
= 120 - offset
- sensor
->offset_constant
;
184 sensor_calibration
= sensor_calibration
* sensor
->slope_div
/
187 if (dev_priv
->chipset
>= 0x46)
188 sensor_calibration
|= 0x80000000;
190 sensor_calibration
|= 0x10000000;
192 nv_wr32(dev
, 0x0015b0, sensor_calibration
);
194 /* Wait for the sensor to update */
198 return nv_rd32(dev
, 0x0015b4) & 0x1fff;
202 nv40_temp_get(struct drm_device
*dev
)
204 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
205 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
206 struct nouveau_pm_temp_sensor_constants
*sensor
= &pm
->sensor_constants
;
207 int offset
= sensor
->offset_mult
/ sensor
->offset_div
;
210 if (dev_priv
->chipset
>= 0x50) {
211 core_temp
= nv_rd32(dev
, 0x20008);
213 core_temp
= nv_rd32(dev
, 0x0015b4) & 0x1fff;
214 /* Setup the sensor if the temperature is 0 */
216 core_temp
= nv40_sensor_setup(dev
);
219 core_temp
= core_temp
* sensor
->slope_mult
/ sensor
->slope_div
;
220 core_temp
= core_temp
+ offset
+ sensor
->offset_constant
;
226 nv84_temp_get(struct drm_device
*dev
)
228 return nv_rd32(dev
, 0x20400);
232 nouveau_temp_safety_checks(struct drm_device
*dev
)
234 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
235 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
236 struct nouveau_pm_threshold_temp
*temps
= &pm
->threshold_temp
;
238 if (temps
->critical
> 120)
239 temps
->critical
= 120;
240 else if (temps
->critical
< 80)
241 temps
->critical
= 80;
243 if (temps
->down_clock
> 110)
244 temps
->down_clock
= 110;
245 else if (temps
->down_clock
< 60)
246 temps
->down_clock
= 60;
248 if (temps
->fan_boost
> 100)
249 temps
->fan_boost
= 100;
250 else if (temps
->fan_boost
< 40)
251 temps
->fan_boost
= 40;
255 probe_monitoring_device(struct nouveau_i2c_chan
*i2c
,
256 struct i2c_board_info
*info
)
259 char modalias
[16] = "i2c:";
260 struct i2c_client
*client
;
262 strlcat(modalias
, info
->type
, sizeof(modalias
));
263 request_module(modalias
);
265 client
= i2c_new_device(&i2c
->adapter
, info
);
269 if (!client
->driver
|| client
->driver
->detect(client
, info
)) {
270 i2c_unregister_device(client
);
274 NV_WARN(i2c
->dev
, "Can not test for monitoring device \"%s\" on %02x due to missing os support\n", info
->name
, info
->addr
);
281 nouveau_temp_probe_i2c(struct drm_device
*dev
)
283 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
284 struct dcb_table
*dcb
= &dev_priv
->vbios
.dcb
;
285 struct i2c_board_info info
[] = {
286 { I2C_BOARD_INFO("w83l785ts", 0x2d) },
287 { I2C_BOARD_INFO("w83781d", 0x2d) },
288 { I2C_BOARD_INFO("f75375", 0x2e) },
289 { I2C_BOARD_INFO("adt7473", 0x2e) },
290 { I2C_BOARD_INFO("lm99", 0x4c) },
293 int idx
= (dcb
->version
>= 0x40 ?
294 dcb
->i2c_default_indices
& 0xf : 2);
296 nouveau_i2c_identify(dev
, "monitoring device", info
,
297 probe_monitoring_device
, idx
);
301 nouveau_temp_init(struct drm_device
*dev
)
303 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
304 struct nvbios
*bios
= &dev_priv
->vbios
;
308 if (bios
->type
== NVBIOS_BIT
) {
309 if (bit_table(dev
, 'P', &P
))
313 temp
= ROMPTR(bios
, P
.data
[12]);
314 else if (P
.version
== 2)
315 temp
= ROMPTR(bios
, P
.data
[16]);
317 NV_WARN(dev
, "unknown temp for BIT P %d\n", P
.version
);
319 nouveau_temp_vbios_parse(dev
, temp
);
322 nouveau_temp_probe_i2c(dev
);
326 nouveau_temp_fini(struct drm_device
*dev
)