-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drm/nouveau/therm: rework thermal table parsing
As an accident, it should also fix temperature reading on nv4x. v2: introduce nvbios_therm_entry as advised by darktama Signed-off-by: Martin Peres <martin.peres@labri.fr> Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
- Loading branch information
Martin Peres
authored and
Ben Skeggs
committed
Oct 3, 2012
1 parent
e361999
commit 7d70e9c
Showing
6 changed files
with
282 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef __NVBIOS_THERM_H__ | ||
#define __NVBIOS_THERM_H__ | ||
|
||
struct nouveau_bios; | ||
|
||
struct nvbios_therm_threshold { | ||
u8 temp; | ||
u8 hysteresis; | ||
}; | ||
|
||
struct nvbios_therm_sensor { | ||
/* diode */ | ||
s16 slope_mult; | ||
s16 slope_div; | ||
s16 offset_num; | ||
s16 offset_den; | ||
s8 offset_constant; | ||
|
||
/* thresholds */ | ||
struct nvbios_therm_threshold thrs_fan_boost; | ||
struct nvbios_therm_threshold thrs_down_clock; | ||
struct nvbios_therm_threshold thrs_critical; | ||
struct nvbios_therm_threshold thrs_shutdown; | ||
}; | ||
|
||
struct nvbios_therm_fan { | ||
u16 pwm_freq; | ||
|
||
u8 min_duty; | ||
u8 max_duty; | ||
}; | ||
|
||
enum nvbios_therm_domain { | ||
NVBIOS_THERM_DOMAIN_CORE, | ||
NVBIOS_THERM_DOMAIN_AMBIENT, | ||
}; | ||
|
||
int | ||
nvbios_therm_sensor_parse(struct nouveau_bios *, enum nvbios_therm_domain, | ||
struct nvbios_therm_sensor *); | ||
|
||
int | ||
nvbios_therm_fan_parse(struct nouveau_bios *, struct nvbios_therm_fan *); | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
* Copyright 2012 Nouveau Community | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
* OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
* Authors: Martin Peres | ||
*/ | ||
|
||
#include <subdev/bios.h> | ||
#include <subdev/bios/bit.h> | ||
#include <subdev/bios/therm.h> | ||
|
||
static u16 | ||
therm_table(struct nouveau_bios *bios, u8 *ver, u8 *hdr, u8 *len, u8 *cnt) | ||
{ | ||
struct bit_entry bit_P; | ||
u16 therm = 0; | ||
|
||
if (!bit_entry(bios, 'P', &bit_P)) { | ||
if (bit_P.version == 1) | ||
therm = nv_ro16(bios, bit_P.offset + 12); | ||
else if (bit_P.version == 2) | ||
therm = nv_ro16(bios, bit_P.offset + 16); | ||
else | ||
nv_error(bios, | ||
"unknown offset for thermal in BIT P %d\n", | ||
bit_P.version); | ||
} | ||
|
||
/* exit now if we haven't found the thermal table */ | ||
if (!therm) | ||
return 0x0000; | ||
|
||
*ver = nv_ro08(bios, therm + 0); | ||
*hdr = nv_ro08(bios, therm + 1); | ||
*len = nv_ro08(bios, therm + 2); | ||
*cnt = nv_ro08(bios, therm + 3); | ||
|
||
return therm + nv_ro08(bios, therm + 1); | ||
} | ||
|
||
u16 | ||
nvbios_therm_entry(struct nouveau_bios *bios, int idx, u8 *ver, u8 *len) | ||
{ | ||
u8 hdr, cnt; | ||
u16 therm = therm_table(bios, ver, &hdr, len, &cnt); | ||
if (therm && idx < cnt) | ||
return therm + idx * *len; | ||
return 0x0000; | ||
} | ||
|
||
int | ||
nvbios_therm_sensor_parse(struct nouveau_bios *bios, | ||
enum nvbios_therm_domain domain, | ||
struct nvbios_therm_sensor *sensor) | ||
{ | ||
s8 thrs_section, sensor_section, offset; | ||
u8 ver, len, i; | ||
u16 entry; | ||
|
||
/* we only support the core domain for now */ | ||
if (domain != NVBIOS_THERM_DOMAIN_CORE) | ||
return -EINVAL; | ||
|
||
/* Read the entries from the table */ | ||
thrs_section = 0; | ||
sensor_section = -1; | ||
i = 0; | ||
while ((entry = nvbios_therm_entry(bios, i++, &ver, &len))) { | ||
s16 value = nv_ro16(bios, entry + 1); | ||
|
||
switch (nv_ro08(bios, entry + 0)) { | ||
case 0x0: | ||
thrs_section = value; | ||
if (value > 0) | ||
return 0; /* we do not try to support ambient */ | ||
break; | ||
case 0x01: | ||
sensor_section++; | ||
if (sensor_section == 0) { | ||
offset = ((s8) nv_ro08(bios, entry + 2)) / 2; | ||
sensor->offset_constant = offset; | ||
} | ||
break; | ||
|
||
case 0x04: | ||
if (thrs_section == 0) { | ||
sensor->thrs_critical.temp = (value & 0xff0) >> 4; | ||
sensor->thrs_critical.hysteresis = value & 0xf; | ||
} | ||
break; | ||
|
||
case 0x07: | ||
if (thrs_section == 0) { | ||
sensor->thrs_down_clock.temp = (value & 0xff0) >> 4; | ||
sensor->thrs_down_clock.hysteresis = value & 0xf; | ||
} | ||
break; | ||
|
||
case 0x08: | ||
if (thrs_section == 0) { | ||
sensor->thrs_fan_boost.temp = (value & 0xff0) >> 4; | ||
sensor->thrs_fan_boost.hysteresis = value & 0xf; | ||
} | ||
break; | ||
|
||
case 0x10: | ||
if (sensor_section == 0) | ||
sensor->offset_num = value; | ||
break; | ||
|
||
case 0x11: | ||
if (sensor_section == 0) | ||
sensor->offset_den = value; | ||
break; | ||
|
||
case 0x12: | ||
if (sensor_section == 0) | ||
sensor->slope_mult = value; | ||
break; | ||
|
||
case 0x13: | ||
if (sensor_section == 0) | ||
sensor->slope_div = value; | ||
break; | ||
case 0x32: | ||
if (thrs_section == 0) { | ||
sensor->thrs_shutdown.temp = (value & 0xff0) >> 4; | ||
sensor->thrs_shutdown.hysteresis = value & 0xf; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int | ||
nvbios_therm_fan_parse(struct nouveau_bios *bios, | ||
struct nvbios_therm_fan *fan) | ||
{ | ||
u8 ver, len, i; | ||
u16 entry; | ||
|
||
i = 0; | ||
while ((entry = nvbios_therm_entry(bios, i++, &ver, &len))) { | ||
s16 value = nv_ro16(bios, entry + 1); | ||
|
||
switch (nv_ro08(bios, entry + 0)) { | ||
case 0x22: | ||
fan->min_duty = value & 0xff; | ||
fan->max_duty = (value & 0xff00) >> 8; | ||
break; | ||
case 0x26: | ||
fan->pwm_freq = value; | ||
break; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.