Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 27 | #include "drmP.h" |
| 28 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 29 | #include "nouveau_drm.h" |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 30 | #include "nouveau_pm.h" |
| 31 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 32 | #include <subdev/i2c.h> |
| 33 | |
Francisco Jerez | 5c4abd0 | 2010-09-23 20:36:42 +0200 | [diff] [blame] | 34 | static void |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 35 | nouveau_temp_vbios_parse(struct drm_device *dev, u8 *temp) |
| 36 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 37 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 38 | struct nouveau_pm *pm = nouveau_pm(dev); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 39 | struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants; |
| 40 | struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp; |
| 41 | int i, headerlen, recordlen, entries; |
| 42 | |
| 43 | if (!temp) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 44 | NV_DEBUG(drm, "temperature table pointer invalid\n"); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 45 | return; |
| 46 | } |
| 47 | |
| 48 | /* Set the default sensor's contants */ |
| 49 | sensor->offset_constant = 0; |
Emil Velikov | 40ce427 | 2011-06-22 02:13:23 +0100 | [diff] [blame] | 50 | sensor->offset_mult = 0; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 51 | sensor->offset_div = 1; |
| 52 | sensor->slope_mult = 1; |
| 53 | sensor->slope_div = 1; |
| 54 | |
| 55 | /* Set the default temperature thresholds */ |
| 56 | temps->critical = 110; |
| 57 | temps->down_clock = 100; |
| 58 | temps->fan_boost = 90; |
| 59 | |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 60 | /* Set the default range for the pwm fan */ |
| 61 | pm->fan.min_duty = 30; |
| 62 | pm->fan.max_duty = 100; |
| 63 | |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 64 | /* Set the known default values to setup the temperature sensor */ |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 65 | if (nv_device(drm->device)->card_type >= NV_40) { |
| 66 | switch (nv_device(drm->device)->chipset) { |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 67 | case 0x43: |
| 68 | sensor->offset_mult = 32060; |
| 69 | sensor->offset_div = 1000; |
| 70 | sensor->slope_mult = 792; |
| 71 | sensor->slope_div = 1000; |
| 72 | break; |
| 73 | |
| 74 | case 0x44: |
| 75 | case 0x47: |
Francisco Jerez | d34ec50 | 2010-09-23 16:27:14 +0200 | [diff] [blame] | 76 | case 0x4a: |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 77 | sensor->offset_mult = 27839; |
| 78 | sensor->offset_div = 1000; |
| 79 | sensor->slope_mult = 780; |
| 80 | sensor->slope_div = 1000; |
| 81 | break; |
| 82 | |
| 83 | case 0x46: |
| 84 | sensor->offset_mult = -24775; |
| 85 | sensor->offset_div = 100; |
| 86 | sensor->slope_mult = 467; |
| 87 | sensor->slope_div = 10000; |
| 88 | break; |
| 89 | |
| 90 | case 0x49: |
| 91 | sensor->offset_mult = -25051; |
| 92 | sensor->offset_div = 100; |
| 93 | sensor->slope_mult = 458; |
| 94 | sensor->slope_div = 10000; |
| 95 | break; |
| 96 | |
| 97 | case 0x4b: |
| 98 | sensor->offset_mult = -24088; |
| 99 | sensor->offset_div = 100; |
| 100 | sensor->slope_mult = 442; |
| 101 | sensor->slope_div = 10000; |
| 102 | break; |
| 103 | |
| 104 | case 0x50: |
| 105 | sensor->offset_mult = -22749; |
| 106 | sensor->offset_div = 100; |
| 107 | sensor->slope_mult = 431; |
| 108 | sensor->slope_div = 10000; |
| 109 | break; |
Emil Velikov | 6d13e9c | 2011-06-22 02:54:39 +0100 | [diff] [blame] | 110 | |
| 111 | case 0x67: |
| 112 | sensor->offset_mult = -26149; |
| 113 | sensor->offset_div = 100; |
| 114 | sensor->slope_mult = 484; |
| 115 | sensor->slope_div = 10000; |
| 116 | break; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | headerlen = temp[1]; |
| 121 | recordlen = temp[2]; |
| 122 | entries = temp[3]; |
| 123 | temp = temp + headerlen; |
| 124 | |
| 125 | /* Read the entries from the table */ |
| 126 | for (i = 0; i < entries; i++) { |
Emil Velikov | 40ce427 | 2011-06-22 02:13:23 +0100 | [diff] [blame] | 127 | s16 value = ROM16(temp[1]); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 128 | |
| 129 | switch (temp[0]) { |
| 130 | case 0x01: |
Francisco Jerez | 67e1d4f | 2010-09-23 17:01:05 +0200 | [diff] [blame] | 131 | if ((value & 0x8f) == 0) |
| 132 | sensor->offset_constant = (value >> 9) & 0x7f; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 133 | break; |
| 134 | |
| 135 | case 0x04: |
| 136 | if ((value & 0xf00f) == 0xa000) /* core */ |
| 137 | temps->critical = (value&0x0ff0) >> 4; |
| 138 | break; |
| 139 | |
| 140 | case 0x07: |
| 141 | if ((value & 0xf00f) == 0xa000) /* core */ |
| 142 | temps->down_clock = (value&0x0ff0) >> 4; |
| 143 | break; |
| 144 | |
| 145 | case 0x08: |
| 146 | if ((value & 0xf00f) == 0xa000) /* core */ |
| 147 | temps->fan_boost = (value&0x0ff0) >> 4; |
| 148 | break; |
| 149 | |
| 150 | case 0x10: |
| 151 | sensor->offset_mult = value; |
| 152 | break; |
| 153 | |
| 154 | case 0x11: |
| 155 | sensor->offset_div = value; |
| 156 | break; |
| 157 | |
| 158 | case 0x12: |
| 159 | sensor->slope_mult = value; |
| 160 | break; |
| 161 | |
| 162 | case 0x13: |
| 163 | sensor->slope_div = value; |
| 164 | break; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 165 | case 0x22: |
| 166 | pm->fan.min_duty = value & 0xff; |
| 167 | pm->fan.max_duty = (value & 0xff00) >> 8; |
| 168 | break; |
Ben Skeggs | 3f8e11e | 2011-08-15 16:13:34 +1000 | [diff] [blame] | 169 | case 0x26: |
| 170 | pm->fan.pwm_freq = value; |
| 171 | break; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 172 | } |
| 173 | temp += recordlen; |
| 174 | } |
| 175 | |
| 176 | nouveau_temp_safety_checks(dev); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 177 | |
| 178 | /* check the fan min/max settings */ |
| 179 | if (pm->fan.min_duty < 10) |
| 180 | pm->fan.min_duty = 10; |
| 181 | if (pm->fan.max_duty > 100) |
| 182 | pm->fan.max_duty = 100; |
| 183 | if (pm->fan.max_duty < pm->fan.min_duty) |
| 184 | pm->fan.max_duty = pm->fan.min_duty; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 187 | static int |
| 188 | nv40_sensor_setup(struct drm_device *dev) |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 189 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 190 | struct nouveau_device *device = nouveau_dev(dev); |
| 191 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 192 | struct nouveau_pm *pm = nouveau_pm(dev); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 193 | struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants; |
Emil Velikov | 40ce427 | 2011-06-22 02:13:23 +0100 | [diff] [blame] | 194 | s32 offset = sensor->offset_mult / sensor->offset_div; |
| 195 | s32 sensor_calibration; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 196 | |
| 197 | /* set up the sensors */ |
| 198 | sensor_calibration = 120 - offset - sensor->offset_constant; |
| 199 | sensor_calibration = sensor_calibration * sensor->slope_div / |
| 200 | sensor->slope_mult; |
| 201 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 202 | if (nv_device(drm->device)->chipset >= 0x46) |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 203 | sensor_calibration |= 0x80000000; |
| 204 | else |
| 205 | sensor_calibration |= 0x10000000; |
| 206 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 207 | nv_wr32(device, 0x0015b0, sensor_calibration); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 208 | |
| 209 | /* Wait for the sensor to update */ |
| 210 | msleep(5); |
| 211 | |
| 212 | /* read */ |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 213 | return nv_rd32(device, 0x0015b4) & 0x1fff; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 214 | } |
| 215 | |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 216 | int |
| 217 | nv40_temp_get(struct drm_device *dev) |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 218 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 219 | struct nouveau_device *device = nouveau_dev(dev); |
| 220 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 221 | struct nouveau_pm *pm = nouveau_pm(dev); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 222 | struct nouveau_pm_temp_sensor_constants *sensor = &pm->sensor_constants; |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 223 | int offset = sensor->offset_mult / sensor->offset_div; |
| 224 | int core_temp; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 225 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 226 | if (nv_device(drm->device)->card_type >= NV_50) { |
| 227 | core_temp = nv_rd32(device, 0x20008); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 228 | } else { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 229 | core_temp = nv_rd32(device, 0x0015b4) & 0x1fff; |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 230 | /* Setup the sensor if the temperature is 0 */ |
| 231 | if (core_temp == 0) |
| 232 | core_temp = nv40_sensor_setup(dev); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 233 | } |
| 234 | |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 235 | core_temp = core_temp * sensor->slope_mult / sensor->slope_div; |
| 236 | core_temp = core_temp + offset + sensor->offset_constant; |
| 237 | |
| 238 | return core_temp; |
| 239 | } |
| 240 | |
| 241 | int |
| 242 | nv84_temp_get(struct drm_device *dev) |
| 243 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 244 | struct nouveau_device *device = nouveau_dev(dev); |
| 245 | return nv_rd32(device, 0x20400); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void |
| 249 | nouveau_temp_safety_checks(struct drm_device *dev) |
| 250 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 251 | struct nouveau_pm *pm = nouveau_pm(dev); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 252 | struct nouveau_pm_threshold_temp *temps = &pm->threshold_temp; |
| 253 | |
| 254 | if (temps->critical > 120) |
| 255 | temps->critical = 120; |
| 256 | else if (temps->critical < 80) |
| 257 | temps->critical = 80; |
| 258 | |
| 259 | if (temps->down_clock > 110) |
| 260 | temps->down_clock = 110; |
| 261 | else if (temps->down_clock < 60) |
| 262 | temps->down_clock = 60; |
| 263 | |
| 264 | if (temps->fan_boost > 100) |
| 265 | temps->fan_boost = 100; |
| 266 | else if (temps->fan_boost < 40) |
| 267 | temps->fan_boost = 40; |
| 268 | } |
| 269 | |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 270 | static bool |
Ben Skeggs | 4196faa | 2012-07-10 14:36:38 +1000 | [diff] [blame] | 271 | probe_monitoring_device(struct nouveau_i2c_port *i2c, |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 272 | struct i2c_board_info *info) |
| 273 | { |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 274 | struct i2c_client *client; |
| 275 | |
Lucas Stach | f17811d | 2011-02-06 22:42:54 +0100 | [diff] [blame] | 276 | request_module("%s%s", I2C_MODULE_PREFIX, info->type); |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 277 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 278 | client = i2c_new_device(&i2c->adapter, info); |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 279 | if (!client) |
| 280 | return false; |
| 281 | |
| 282 | if (!client->driver || client->driver->detect(client, info)) { |
| 283 | i2c_unregister_device(client); |
| 284 | return false; |
| 285 | } |
| 286 | |
| 287 | return true; |
| 288 | } |
| 289 | |
| 290 | static void |
| 291 | nouveau_temp_probe_i2c(struct drm_device *dev) |
| 292 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 293 | struct nouveau_device *device = nouveau_dev(dev); |
| 294 | struct nouveau_i2c *i2c = nouveau_i2c(device); |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 295 | struct i2c_board_info info[] = { |
| 296 | { I2C_BOARD_INFO("w83l785ts", 0x2d) }, |
| 297 | { I2C_BOARD_INFO("w83781d", 0x2d) }, |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 298 | { I2C_BOARD_INFO("adt7473", 0x2e) }, |
Ben Skeggs | b26e72f | 2011-01-19 15:54:10 +1000 | [diff] [blame] | 299 | { I2C_BOARD_INFO("f75375", 0x2e) }, |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 300 | { I2C_BOARD_INFO("lm99", 0x4c) }, |
| 301 | { } |
| 302 | }; |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 303 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 304 | i2c->identify(i2c, NV_I2C_DEFAULT(0), "monitoring device", info, |
| 305 | probe_monitoring_device); |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 306 | } |
| 307 | |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 308 | void |
| 309 | nouveau_temp_init(struct drm_device *dev) |
| 310 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 311 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 312 | struct nvbios *bios = &drm->vbios; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 313 | struct bit_entry P; |
| 314 | u8 *temp = NULL; |
| 315 | |
| 316 | if (bios->type == NVBIOS_BIT) { |
| 317 | if (bit_table(dev, 'P', &P)) |
| 318 | return; |
| 319 | |
| 320 | if (P.version == 1) |
Ben Skeggs | f9f9f53 | 2011-10-12 16:48:48 +1000 | [diff] [blame] | 321 | temp = ROMPTR(dev, P.data[12]); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 322 | else if (P.version == 2) |
Ben Skeggs | f9f9f53 | 2011-10-12 16:48:48 +1000 | [diff] [blame] | 323 | temp = ROMPTR(dev, P.data[16]); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 324 | else |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame^] | 325 | NV_WARN(drm, "unknown temp for BIT P %d\n", P.version); |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 326 | |
| 327 | nouveau_temp_vbios_parse(dev, temp); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 328 | } |
| 329 | |
Francisco Jerez | 66146da | 2010-09-23 21:00:40 +0200 | [diff] [blame] | 330 | nouveau_temp_probe_i2c(dev); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void |
| 334 | nouveau_temp_fini(struct drm_device *dev) |
| 335 | { |
| 336 | |
| 337 | } |