123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- /*
- * Copyright 2010 PathScale inc.
- *
- * 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 <linux/module.h>
- #include "drmP.h"
- #include "nouveau_drm.h"
- #include "nouveau_pm.h"
- #include <subdev/i2c.h>
- #include <subdev/bios/therm.h>
- #include <subdev/bios/extdev.h>
- static int
- nv40_sensor_setup(struct drm_device *dev)
- {
- struct nouveau_device *device = nouveau_dev(dev);
- struct nouveau_drm *drm = nouveau_drm(dev);
- /* enable ADC readout and disable the ALARM threshold */
- if (nv_device(drm->device)->chipset >= 0x46) {
- nv_mask(device, 0x15b8, 0x80000000, 0);
- nv_wr32(device, 0x15b0, 0x80003fff);
- return nv_rd32(device, 0x15b4) & 0x3fff;
- } else {
- nv_wr32(device, 0x15b0, 0xff);
- return nv_rd32(device, 0x15b4) & 0xff;
- }
- }
- int
- nv40_temp_get(struct drm_device *dev)
- {
- struct nouveau_device *device = nouveau_dev(dev);
- struct nouveau_drm *drm = nouveau_drm(dev);
- struct nouveau_pm *pm = nouveau_pm(dev);
- struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
- int core_temp;
- if (nv_device(drm->device)->chipset >= 0x46) {
- nv_wr32(device, 0x15b0, 0x80003fff);
- core_temp = nv_rd32(device, 0x15b4) & 0x3fff;
- } else {
- nv_wr32(device, 0x15b0, 0xff);
- core_temp = nv_rd32(device, 0x15b4) & 0xff;
- }
- /* Setup the sensor if the temperature is 0 */
- if (core_temp == 0)
- core_temp = nv40_sensor_setup(dev);
- if (sensor->slope_div == 0)
- sensor->slope_div = 1;
- if (sensor->offset_div == 0)
- sensor->offset_div = 1;
- if (sensor->slope_mult < 1)
- sensor->slope_mult = 1;
- core_temp = core_temp * sensor->slope_mult / sensor->slope_div;
- core_temp = core_temp + sensor->offset_mult / sensor->offset_div;
- core_temp = core_temp + sensor->offset_constant - 8;
- return core_temp;
- }
- int
- nv84_temp_get(struct drm_device *dev)
- {
- struct nouveau_device *device = nouveau_dev(dev);
- return nv_rd32(device, 0x20400);
- }
- void
- nouveau_temp_safety_checks(struct drm_device *dev)
- {
- struct nouveau_pm *pm = nouveau_pm(dev);
- struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
- if (temps->critical > 120)
- temps->critical = 120;
- else if (temps->critical < 80)
- temps->critical = 80;
- if (temps->down_clock > 110)
- temps->down_clock = 110;
- else if (temps->down_clock < 60)
- temps->down_clock = 60;
- }
- static bool
- probe_monitoring_device(struct nouveau_i2c_port *i2c,
- struct i2c_board_info *info)
- {
- struct i2c_client *client;
- request_module("%s%s", I2C_MODULE_PREFIX, info->type);
- client = i2c_new_device(&i2c->adapter, info);
- if (!client)
- return false;
- if (!client->driver || client->driver->detect(client, info)) {
- i2c_unregister_device(client);
- return false;
- }
- return true;
- }
- static void
- nouveau_temp_probe_i2c(struct drm_device *dev)
- {
- struct nouveau_device *device = nouveau_dev(dev);
- struct nouveau_bios *bios = nouveau_bios(device);
- struct nouveau_i2c *i2c = nouveau_i2c(device);
- struct nvbios_extdev_func extdev_entry;
- struct i2c_board_info info[] = {
- { I2C_BOARD_INFO("w83l785ts", 0x2d) },
- { I2C_BOARD_INFO("w83781d", 0x2d) },
- { I2C_BOARD_INFO("adt7473", 0x2e) },
- { I2C_BOARD_INFO("adt7473", 0x2d) },
- { I2C_BOARD_INFO("adt7473", 0x2c) },
- { I2C_BOARD_INFO("f75375", 0x2e) },
- { I2C_BOARD_INFO("lm99", 0x4c) },
- { I2C_BOARD_INFO("lm90", 0x4c) },
- { I2C_BOARD_INFO("lm90", 0x4d) },
- { I2C_BOARD_INFO("adm1021", 0x18) },
- { I2C_BOARD_INFO("adm1021", 0x19) },
- { I2C_BOARD_INFO("adm1021", 0x1a) },
- { I2C_BOARD_INFO("adm1021", 0x29) },
- { I2C_BOARD_INFO("adm1021", 0x2a) },
- { I2C_BOARD_INFO("adm1021", 0x2b) },
- { I2C_BOARD_INFO("adm1021", 0x4c) },
- { I2C_BOARD_INFO("adm1021", 0x4d) },
- { I2C_BOARD_INFO("adm1021", 0x4e) },
- { I2C_BOARD_INFO("lm63", 0x18) },
- { I2C_BOARD_INFO("lm63", 0x4e) },
- { }
- };
- if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_LM89, &extdev_entry)) {
- struct i2c_board_info board[] = {
- { I2C_BOARD_INFO("lm90", extdev_entry.addr >> 1) },
- { }
- };
- if (i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
- board, probe_monitoring_device))
- return;
- }
- if (!nvbios_extdev_find(bios, NVBIOS_EXTDEV_ADT7473, &extdev_entry)) {
- struct i2c_board_info board[] = {
- { I2C_BOARD_INFO("adt7473", extdev_entry.addr >> 1) },
- { }
- };
- if (i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device",
- board, probe_monitoring_device))
- return;
- }
- /* The vbios doesn't provide the address of an exisiting monitoring
- device. Let's try our static list.
- */
- i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device", info,
- probe_monitoring_device);
- }
- void
- nouveau_temp_init(struct drm_device *dev)
- {
- struct nouveau_drm *drm = nouveau_drm(dev);
- struct nouveau_device *device = nv_device(drm->device);
- struct nouveau_bios *bios = nouveau_bios(device);
- struct nouveau_pm *pm = nouveau_pm(dev);
- struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants;
- struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp;
- struct nvbios_therm_sensor bios_sensor;
- struct nvbios_therm_fan bios_fan;
- /* store some safe defaults */
- sensor->offset_constant = 0;
- sensor->offset_mult = 0;
- sensor->offset_div = 1;
- sensor->slope_mult = 1;
- sensor->slope_div = 1;
- if (!nvbios_therm_sensor_parse(bios, NVBIOS_THERM_DOMAIN_CORE,
- &bios_sensor)) {
- sensor->slope_mult = bios_sensor.slope_mult;
- sensor->slope_div = bios_sensor.slope_div;
- sensor->offset_mult = bios_sensor.offset_num;
- sensor->offset_div = bios_sensor.offset_den;
- sensor->offset_constant = bios_sensor.offset_constant;
- temps->down_clock = bios_sensor.thrs_down_clock.temp;
- temps->critical = bios_sensor.thrs_critical.temp;
- }
- if (nvbios_therm_fan_parse(bios, &bios_fan)) {
- pm->fan.min_duty = bios_fan.min_duty;
- pm->fan.max_duty = bios_fan.max_duty;
- pm->fan.pwm_freq = bios_fan.pwm_freq;
- }
- nouveau_temp_safety_checks(dev);
- nouveau_temp_probe_i2c(dev);
- }
- void
- nouveau_temp_fini(struct drm_device *dev)
- {
- }
|