Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 Red Hat 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: Ben Skeggs |
| 23 | */ |
| 24 | |
Ben Skeggs | 6032649 | 2010-10-12 12:31:32 +1000 | [diff] [blame] | 25 | #ifdef CONFIG_ACPI |
| 26 | #include <linux/acpi.h> |
| 27 | #endif |
| 28 | #include <linux/power_supply.h> |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 29 | #include <linux/hwmon.h> |
| 30 | #include <linux/hwmon-sysfs.h> |
| 31 | |
Linus Torvalds | 612a9aa | 2012-10-03 23:29:23 -0700 | [diff] [blame^] | 32 | #include <drm/drmP.h> |
Ben Skeggs | a175094 | 2011-09-17 01:42:12 +1000 | [diff] [blame] | 33 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 34 | #include "nouveau_drm.h" |
| 35 | #include "nouveau_pm.h" |
Ben Skeggs | a175094 | 2011-09-17 01:42:12 +1000 | [diff] [blame] | 36 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 37 | #include <subdev/gpio.h> |
| 38 | #include <subdev/timer.h> |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 39 | #include <subdev/therm.h> |
Ben Skeggs | a175094 | 2011-09-17 01:42:12 +1000 | [diff] [blame] | 40 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 41 | MODULE_PARM_DESC(perflvl, "Performance level (default: boot)"); |
| 42 | static char *nouveau_perflvl; |
| 43 | module_param_named(perflvl, nouveau_perflvl, charp, 0400); |
Ben Skeggs | a175094 | 2011-09-17 01:42:12 +1000 | [diff] [blame] | 44 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 45 | MODULE_PARM_DESC(perflvl_wr, "Allow perflvl changes (warning: dangerous!)"); |
| 46 | static int nouveau_perflvl_wr; |
| 47 | module_param_named(perflvl_wr, nouveau_perflvl_wr, int, 0400); |
Ben Skeggs | a175094 | 2011-09-17 01:42:12 +1000 | [diff] [blame] | 48 | |
| 49 | static int |
Ben Skeggs | 0b627a0 | 2011-10-27 12:02:12 +1000 | [diff] [blame] | 50 | nouveau_pm_perflvl_aux(struct drm_device *dev, struct nouveau_pm_level *perflvl, |
| 51 | struct nouveau_pm_level *a, struct nouveau_pm_level *b) |
| 52 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 53 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 54 | struct nouveau_pm *pm = nouveau_pm(dev); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 55 | struct nouveau_therm *therm = nouveau_therm(drm); |
Ben Skeggs | 0b627a0 | 2011-10-27 12:02:12 +1000 | [diff] [blame] | 56 | int ret; |
| 57 | |
| 58 | /*XXX: not on all boards, we should control based on temperature |
| 59 | * on recent boards.. or maybe on some other factor we don't |
| 60 | * know about? |
| 61 | */ |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 62 | if (therm && therm->fan_set && |
| 63 | a->fanspeed && b->fanspeed && b->fanspeed > a->fanspeed) { |
| 64 | ret = therm->fan_set(therm, perflvl->fanspeed); |
Ben Skeggs | 0b627a0 | 2011-10-27 12:02:12 +1000 | [diff] [blame] | 65 | if (ret && ret != -ENODEV) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 66 | NV_ERROR(drm, "fanspeed set failed: %d\n", ret); |
Ben Skeggs | 0b627a0 | 2011-10-27 12:02:12 +1000 | [diff] [blame] | 67 | return ret; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if (pm->voltage.supported && pm->voltage_set) { |
Ben Skeggs | d2edab4 | 2011-11-10 13:20:14 +1000 | [diff] [blame] | 72 | if (perflvl->volt_min && b->volt_min > a->volt_min) { |
Ben Skeggs | 0b627a0 | 2011-10-27 12:02:12 +1000 | [diff] [blame] | 73 | ret = pm->voltage_set(dev, perflvl->volt_min); |
| 74 | if (ret) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 75 | NV_ERROR(drm, "voltage set failed: %d\n", ret); |
Ben Skeggs | 0b627a0 | 2011-10-27 12:02:12 +1000 | [diff] [blame] | 76 | return ret; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 85 | nouveau_pm_perflvl_set(struct drm_device *dev, struct nouveau_pm_level *perflvl) |
| 86 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 87 | struct nouveau_pm *pm = nouveau_pm(dev); |
Ben Skeggs | ff2b6c6 | 2011-10-27 10:28:17 +1000 | [diff] [blame] | 88 | void *state; |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 89 | int ret; |
| 90 | |
| 91 | if (perflvl == pm->cur) |
| 92 | return 0; |
| 93 | |
Ben Skeggs | 0b627a0 | 2011-10-27 12:02:12 +1000 | [diff] [blame] | 94 | ret = nouveau_pm_perflvl_aux(dev, perflvl, pm->cur, perflvl); |
| 95 | if (ret) |
| 96 | return ret; |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 97 | |
Ben Skeggs | ff2b6c6 | 2011-10-27 10:28:17 +1000 | [diff] [blame] | 98 | state = pm->clocks_pre(dev, perflvl); |
Martin Peres | b010374 | 2011-11-03 00:03:06 +0100 | [diff] [blame] | 99 | if (IS_ERR(state)) { |
| 100 | ret = PTR_ERR(state); |
| 101 | goto error; |
| 102 | } |
| 103 | ret = pm->clocks_set(dev, state); |
| 104 | if (ret) |
| 105 | goto error; |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 106 | |
Ben Skeggs | 0b627a0 | 2011-10-27 12:02:12 +1000 | [diff] [blame] | 107 | ret = nouveau_pm_perflvl_aux(dev, perflvl, perflvl, pm->cur); |
| 108 | if (ret) |
| 109 | return ret; |
| 110 | |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 111 | pm->cur = perflvl; |
| 112 | return 0; |
Martin Peres | b010374 | 2011-11-03 00:03:06 +0100 | [diff] [blame] | 113 | |
| 114 | error: |
| 115 | /* restore the fan speed and voltage before leaving */ |
| 116 | nouveau_pm_perflvl_aux(dev, perflvl, perflvl, pm->cur); |
| 117 | return ret; |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 118 | } |
| 119 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 120 | void |
| 121 | nouveau_pm_trigger(struct drm_device *dev) |
| 122 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 123 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 124 | struct nouveau_timer *ptimer = nouveau_timer(drm->device); |
| 125 | struct nouveau_pm *pm = nouveau_pm(dev); |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 126 | struct nouveau_pm_profile *profile = NULL; |
| 127 | struct nouveau_pm_level *perflvl = NULL; |
| 128 | int ret; |
| 129 | |
| 130 | /* select power profile based on current power source */ |
| 131 | if (power_supply_is_system_supplied()) |
| 132 | profile = pm->profile_ac; |
| 133 | else |
| 134 | profile = pm->profile_dc; |
| 135 | |
Ben Skeggs | 25c53c1 | 2012-01-24 18:03:25 +1000 | [diff] [blame] | 136 | if (profile != pm->profile) { |
| 137 | pm->profile->func->fini(pm->profile); |
| 138 | pm->profile = profile; |
| 139 | pm->profile->func->init(pm->profile); |
| 140 | } |
| 141 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 142 | /* select performance level based on profile */ |
| 143 | perflvl = profile->func->select(profile); |
| 144 | |
| 145 | /* change perflvl, if necessary */ |
| 146 | if (perflvl != pm->cur) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 147 | u64 time0 = ptimer->read(ptimer); |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 148 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 149 | NV_INFO(drm, "setting performance level: %d", perflvl->id); |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 150 | ret = nouveau_pm_perflvl_set(dev, perflvl); |
| 151 | if (ret) |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 152 | NV_INFO(drm, "> reclocking failed: %d\n\n", ret); |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 153 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 154 | NV_INFO(drm, "> reclocking took %lluns\n\n", |
| 155 | ptimer->read(ptimer) - time0); |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
| 159 | static struct nouveau_pm_profile * |
| 160 | profile_find(struct drm_device *dev, const char *string) |
| 161 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 162 | struct nouveau_pm *pm = nouveau_pm(dev); |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 163 | struct nouveau_pm_profile *profile; |
| 164 | |
| 165 | list_for_each_entry(profile, &pm->profiles, head) { |
| 166 | if (!strncmp(profile->name, string, sizeof(profile->name))) |
| 167 | return profile; |
| 168 | } |
| 169 | |
| 170 | return NULL; |
| 171 | } |
| 172 | |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 173 | static int |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 174 | nouveau_pm_profile_set(struct drm_device *dev, const char *profile) |
| 175 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 176 | struct nouveau_pm *pm = nouveau_pm(dev); |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 177 | struct nouveau_pm_profile *ac = NULL, *dc = NULL; |
| 178 | char string[16], *cur = string, *ptr; |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 179 | |
| 180 | /* safety precaution, for now */ |
| 181 | if (nouveau_perflvl_wr != 7777) |
| 182 | return -EPERM; |
| 183 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 184 | strncpy(string, profile, sizeof(string)); |
Jim Meyering | 5799d9e | 2012-04-17 21:27:54 +0200 | [diff] [blame] | 185 | string[sizeof(string) - 1] = 0; |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 186 | if ((ptr = strchr(string, '\n'))) |
| 187 | *ptr = '\0'; |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 188 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 189 | ptr = strsep(&cur, ","); |
| 190 | if (ptr) |
| 191 | ac = profile_find(dev, ptr); |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 192 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 193 | ptr = strsep(&cur, ","); |
| 194 | if (ptr) |
| 195 | dc = profile_find(dev, ptr); |
| 196 | else |
| 197 | dc = ac; |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 198 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 199 | if (ac == NULL || dc == NULL) |
| 200 | return -EINVAL; |
Martin Peres | b010374 | 2011-11-03 00:03:06 +0100 | [diff] [blame] | 201 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 202 | pm->profile_ac = ac; |
| 203 | pm->profile_dc = dc; |
| 204 | nouveau_pm_trigger(dev); |
| 205 | return 0; |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 206 | } |
| 207 | |
Ben Skeggs | 25c53c1 | 2012-01-24 18:03:25 +1000 | [diff] [blame] | 208 | static void |
| 209 | nouveau_pm_static_dummy(struct nouveau_pm_profile *profile) |
| 210 | { |
| 211 | } |
| 212 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 213 | static struct nouveau_pm_level * |
| 214 | nouveau_pm_static_select(struct nouveau_pm_profile *profile) |
| 215 | { |
| 216 | return container_of(profile, struct nouveau_pm_level, profile); |
| 217 | } |
| 218 | |
| 219 | const struct nouveau_pm_profile_func nouveau_pm_static_profile_func = { |
Ben Skeggs | 25c53c1 | 2012-01-24 18:03:25 +1000 | [diff] [blame] | 220 | .destroy = nouveau_pm_static_dummy, |
| 221 | .init = nouveau_pm_static_dummy, |
| 222 | .fini = nouveau_pm_static_dummy, |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 223 | .select = nouveau_pm_static_select, |
| 224 | }; |
| 225 | |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 226 | static int |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 227 | nouveau_pm_perflvl_get(struct drm_device *dev, struct nouveau_pm_level *perflvl) |
| 228 | { |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 229 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 230 | struct nouveau_pm *pm = nouveau_pm(dev); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 231 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 232 | int ret; |
| 233 | |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 234 | memset(perflvl, 0, sizeof(*perflvl)); |
| 235 | |
Ben Skeggs | c11dd0d | 2012-03-07 14:18:49 +1000 | [diff] [blame] | 236 | if (pm->clocks_get) { |
| 237 | ret = pm->clocks_get(dev, perflvl); |
| 238 | if (ret) |
| 239 | return ret; |
| 240 | } |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 241 | |
| 242 | if (pm->voltage.supported && pm->voltage_get) { |
| 243 | ret = pm->voltage_get(dev); |
Ben Skeggs | 3b5565d | 2011-06-09 16:57:07 +1000 | [diff] [blame] | 244 | if (ret > 0) { |
| 245 | perflvl->volt_min = ret; |
| 246 | perflvl->volt_max = ret; |
| 247 | } |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 248 | } |
| 249 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 250 | if (therm && therm->fan_get) { |
| 251 | ret = therm->fan_get(therm); |
| 252 | if (ret >= 0) |
| 253 | perflvl->fanspeed = ret; |
| 254 | } |
Ben Skeggs | 771e103 | 2011-07-28 11:01:21 +1000 | [diff] [blame] | 255 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 256 | nouveau_mem_timing_read(dev, &perflvl->timing); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | static void |
| 261 | nouveau_pm_perflvl_info(struct nouveau_pm_level *perflvl, char *ptr, int len) |
| 262 | { |
Ben Skeggs | 085028c | 2012-01-18 09:02:28 +1000 | [diff] [blame] | 263 | char c[16], s[16], v[32], f[16], m[16]; |
Francisco Jerez | 0fbb114 | 2010-09-20 16:18:28 +0200 | [diff] [blame] | 264 | |
| 265 | c[0] = '\0'; |
| 266 | if (perflvl->core) |
| 267 | snprintf(c, sizeof(c), " core %dMHz", perflvl->core / 1000); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 268 | |
| 269 | s[0] = '\0'; |
| 270 | if (perflvl->shader) |
| 271 | snprintf(s, sizeof(s), " shader %dMHz", perflvl->shader / 1000); |
| 272 | |
Ben Skeggs | 93dccbe | 2011-06-09 17:27:47 +1000 | [diff] [blame] | 273 | m[0] = '\0'; |
| 274 | if (perflvl->memory) |
| 275 | snprintf(m, sizeof(m), " memory %dMHz", perflvl->memory / 1000); |
| 276 | |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 277 | v[0] = '\0'; |
Ben Skeggs | 3b5565d | 2011-06-09 16:57:07 +1000 | [diff] [blame] | 278 | if (perflvl->volt_min && perflvl->volt_min != perflvl->volt_max) { |
| 279 | snprintf(v, sizeof(v), " voltage %dmV-%dmV", |
| 280 | perflvl->volt_min / 1000, perflvl->volt_max / 1000); |
| 281 | } else |
| 282 | if (perflvl->volt_min) { |
| 283 | snprintf(v, sizeof(v), " voltage %dmV", |
| 284 | perflvl->volt_min / 1000); |
| 285 | } |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 286 | |
| 287 | f[0] = '\0'; |
| 288 | if (perflvl->fanspeed) |
| 289 | snprintf(f, sizeof(f), " fanspeed %d%%", perflvl->fanspeed); |
| 290 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 291 | snprintf(ptr, len, "%s%s%s%s%s\n", c, s, m, v, f); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static ssize_t |
| 295 | nouveau_pm_get_perflvl_info(struct device *d, |
| 296 | struct device_attribute *a, char *buf) |
| 297 | { |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 298 | struct nouveau_pm_level *perflvl = |
| 299 | container_of(a, struct nouveau_pm_level, dev_attr); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 300 | char *ptr = buf; |
| 301 | int len = PAGE_SIZE; |
| 302 | |
Ben Skeggs | 93dccbe | 2011-06-09 17:27:47 +1000 | [diff] [blame] | 303 | snprintf(ptr, len, "%d:", perflvl->id); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 304 | ptr += strlen(buf); |
| 305 | len -= strlen(buf); |
| 306 | |
| 307 | nouveau_pm_perflvl_info(perflvl, ptr, len); |
| 308 | return strlen(buf); |
| 309 | } |
| 310 | |
| 311 | static ssize_t |
| 312 | nouveau_pm_get_perflvl(struct device *d, struct device_attribute *a, char *buf) |
| 313 | { |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 314 | struct drm_device *dev = pci_get_drvdata(to_pci_dev(d)); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 315 | struct nouveau_pm *pm = nouveau_pm(dev); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 316 | struct nouveau_pm_level cur; |
| 317 | int len = PAGE_SIZE, ret; |
| 318 | char *ptr = buf; |
| 319 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 320 | snprintf(ptr, len, "profile: %s, %s\nc:", |
| 321 | pm->profile_ac->name, pm->profile_dc->name); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 322 | ptr += strlen(buf); |
| 323 | len -= strlen(buf); |
| 324 | |
| 325 | ret = nouveau_pm_perflvl_get(dev, &cur); |
| 326 | if (ret == 0) |
| 327 | nouveau_pm_perflvl_info(&cur, ptr, len); |
| 328 | return strlen(buf); |
| 329 | } |
| 330 | |
| 331 | static ssize_t |
| 332 | nouveau_pm_set_perflvl(struct device *d, struct device_attribute *a, |
| 333 | const char *buf, size_t count) |
| 334 | { |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 335 | struct drm_device *dev = pci_get_drvdata(to_pci_dev(d)); |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 336 | int ret; |
| 337 | |
| 338 | ret = nouveau_pm_profile_set(dev, buf); |
| 339 | if (ret) |
| 340 | return ret; |
| 341 | return strlen(buf); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 342 | } |
| 343 | |
Francisco Jerez | 5c4abd0 | 2010-09-23 20:36:42 +0200 | [diff] [blame] | 344 | static DEVICE_ATTR(performance_level, S_IRUGO | S_IWUSR, |
| 345 | nouveau_pm_get_perflvl, nouveau_pm_set_perflvl); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 346 | |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 347 | static int |
| 348 | nouveau_sysfs_init(struct drm_device *dev) |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 349 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 350 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 351 | struct nouveau_pm *pm = nouveau_pm(dev); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 352 | struct device *d = &dev->pdev->dev; |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 353 | int ret, i; |
| 354 | |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 355 | ret = device_create_file(d, &dev_attr_performance_level); |
| 356 | if (ret) |
| 357 | return ret; |
| 358 | |
| 359 | for (i = 0; i < pm->nr_perflvl; i++) { |
| 360 | struct nouveau_pm_level *perflvl = &pm->perflvl[i]; |
| 361 | |
| 362 | perflvl->dev_attr.attr.name = perflvl->name; |
| 363 | perflvl->dev_attr.attr.mode = S_IRUGO; |
| 364 | perflvl->dev_attr.show = nouveau_pm_get_perflvl_info; |
| 365 | perflvl->dev_attr.store = NULL; |
| 366 | sysfs_attr_init(&perflvl->dev_attr.attr); |
| 367 | |
| 368 | ret = device_create_file(d, &perflvl->dev_attr); |
| 369 | if (ret) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 370 | NV_ERROR(drm, "failed pervlvl %d sysfs: %d\n", |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 371 | perflvl->id, i); |
| 372 | perflvl->dev_attr.attr.name = NULL; |
| 373 | nouveau_pm_fini(dev); |
| 374 | return ret; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 381 | static void |
| 382 | nouveau_sysfs_fini(struct drm_device *dev) |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 383 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 384 | struct nouveau_pm *pm = nouveau_pm(dev); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 385 | struct device *d = &dev->pdev->dev; |
| 386 | int i; |
| 387 | |
| 388 | device_remove_file(d, &dev_attr_performance_level); |
| 389 | for (i = 0; i < pm->nr_perflvl; i++) { |
| 390 | struct nouveau_pm_level *pl = &pm->perflvl[i]; |
| 391 | |
| 392 | if (!pl->dev_attr.attr.name) |
| 393 | break; |
| 394 | |
| 395 | device_remove_file(d, &pl->dev_attr); |
| 396 | } |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 397 | } |
| 398 | |
Ken Milmore | 658e86e | 2011-07-03 19:54:28 +0100 | [diff] [blame] | 399 | #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 400 | static ssize_t |
| 401 | nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf) |
| 402 | { |
| 403 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 404 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 405 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 406 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 407 | return snprintf(buf, PAGE_SIZE, "%d\n", therm->temp_get(therm) * 1000); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 408 | } |
| 409 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp, |
| 410 | NULL, 0); |
| 411 | |
| 412 | static ssize_t |
| 413 | nouveau_hwmon_max_temp(struct device *d, struct device_attribute *a, char *buf) |
| 414 | { |
| 415 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 416 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 417 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 418 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 419 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 420 | therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK) * 1000); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 421 | } |
| 422 | static ssize_t |
| 423 | nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a, |
| 424 | const char *buf, size_t count) |
| 425 | { |
| 426 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 427 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 428 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 429 | long value; |
| 430 | |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 431 | if (kstrtol(buf, 10, &value) == -EINVAL) |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 432 | return count; |
| 433 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 434 | therm->attr_set(therm, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK, value / 1000); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 435 | |
| 436 | return count; |
| 437 | } |
| 438 | static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, nouveau_hwmon_max_temp, |
| 439 | nouveau_hwmon_set_max_temp, |
| 440 | 0); |
| 441 | |
| 442 | static ssize_t |
| 443 | nouveau_hwmon_critical_temp(struct device *d, struct device_attribute *a, |
| 444 | char *buf) |
| 445 | { |
| 446 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 447 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 448 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 449 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 450 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 451 | therm->attr_get(therm, NOUVEAU_THERM_ATTR_THRS_CRITICAL) * 1000); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 452 | } |
| 453 | static ssize_t |
| 454 | nouveau_hwmon_set_critical_temp(struct device *d, struct device_attribute *a, |
| 455 | const char *buf, |
| 456 | size_t count) |
| 457 | { |
| 458 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 459 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 460 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 461 | long value; |
| 462 | |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 463 | if (kstrtol(buf, 10, &value) == -EINVAL) |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 464 | return count; |
| 465 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 466 | therm->attr_set(therm, NOUVEAU_THERM_ATTR_THRS_CRITICAL, value / 1000); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 467 | |
| 468 | return count; |
| 469 | } |
| 470 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR, |
| 471 | nouveau_hwmon_critical_temp, |
| 472 | nouveau_hwmon_set_critical_temp, |
| 473 | 0); |
| 474 | |
| 475 | static ssize_t nouveau_hwmon_show_name(struct device *dev, |
| 476 | struct device_attribute *attr, |
| 477 | char *buf) |
| 478 | { |
| 479 | return sprintf(buf, "nouveau\n"); |
| 480 | } |
| 481 | static SENSOR_DEVICE_ATTR(name, S_IRUGO, nouveau_hwmon_show_name, NULL, 0); |
| 482 | |
| 483 | static ssize_t nouveau_hwmon_show_update_rate(struct device *dev, |
| 484 | struct device_attribute *attr, |
| 485 | char *buf) |
| 486 | { |
| 487 | return sprintf(buf, "1000\n"); |
| 488 | } |
| 489 | static SENSOR_DEVICE_ATTR(update_rate, S_IRUGO, |
| 490 | nouveau_hwmon_show_update_rate, |
| 491 | NULL, 0); |
| 492 | |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 493 | static ssize_t |
| 494 | nouveau_hwmon_show_fan0_input(struct device *d, struct device_attribute *attr, |
| 495 | char *buf) |
| 496 | { |
| 497 | struct drm_device *dev = dev_get_drvdata(d); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 498 | struct nouveau_drm *drm = nouveau_drm(dev); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 499 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 500 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 501 | return snprintf(buf, PAGE_SIZE, "%d\n", therm->fan_sense(therm)); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 502 | } |
| 503 | static SENSOR_DEVICE_ATTR(fan0_input, S_IRUGO, nouveau_hwmon_show_fan0_input, |
| 504 | NULL, 0); |
| 505 | |
Martin Peres | 2f951a5 | 2012-09-04 13:52:00 +0200 | [diff] [blame] | 506 | static ssize_t |
| 507 | nouveau_hwmon_get_pwm1_enable(struct device *d, |
| 508 | struct device_attribute *a, char *buf) |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 509 | { |
| 510 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | 2f951a5 | 2012-09-04 13:52:00 +0200 | [diff] [blame] | 511 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 512 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Ben Skeggs | a175094 | 2011-09-17 01:42:12 +1000 | [diff] [blame] | 513 | int ret; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 514 | |
Martin Peres | 2f951a5 | 2012-09-04 13:52:00 +0200 | [diff] [blame] | 515 | ret = therm->attr_get(therm, NOUVEAU_THERM_ATTR_FAN_MODE); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 516 | if (ret < 0) |
| 517 | return ret; |
| 518 | |
| 519 | return sprintf(buf, "%i\n", ret); |
| 520 | } |
| 521 | |
| 522 | static ssize_t |
Martin Peres | 2f951a5 | 2012-09-04 13:52:00 +0200 | [diff] [blame] | 523 | nouveau_hwmon_set_pwm1_enable(struct device *d, struct device_attribute *a, |
| 524 | const char *buf, size_t count) |
| 525 | { |
| 526 | struct drm_device *dev = dev_get_drvdata(d); |
| 527 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 528 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
| 529 | long value; |
| 530 | int ret; |
| 531 | |
| 532 | if (strict_strtol(buf, 10, &value) == -EINVAL) |
| 533 | return -EINVAL; |
| 534 | |
| 535 | ret = therm->attr_set(therm, NOUVEAU_THERM_ATTR_FAN_MODE, value); |
| 536 | if (ret) |
| 537 | return ret; |
| 538 | else |
| 539 | return count; |
| 540 | } |
| 541 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, |
| 542 | nouveau_hwmon_get_pwm1_enable, |
| 543 | nouveau_hwmon_set_pwm1_enable, 0); |
| 544 | |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 545 | static ssize_t |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 546 | nouveau_hwmon_get_pwm1(struct device *d, struct device_attribute *a, char *buf) |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 547 | { |
| 548 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 549 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 550 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 551 | int ret; |
| 552 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 553 | ret = therm->fan_get(therm); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 554 | if (ret < 0) |
| 555 | return ret; |
| 556 | |
| 557 | return sprintf(buf, "%i\n", ret); |
| 558 | } |
| 559 | |
| 560 | static ssize_t |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 561 | nouveau_hwmon_set_pwm1(struct device *d, struct device_attribute *a, |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 562 | const char *buf, size_t count) |
| 563 | { |
| 564 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 565 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 566 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 567 | int ret = -ENODEV; |
| 568 | long value; |
| 569 | |
| 570 | if (nouveau_perflvl_wr != 7777) |
| 571 | return -EPERM; |
| 572 | |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 573 | if (kstrtol(buf, 10, &value) == -EINVAL) |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 574 | return -EINVAL; |
| 575 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 576 | ret = therm->fan_set(therm, value); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 577 | if (ret) |
| 578 | return ret; |
| 579 | |
| 580 | return count; |
| 581 | } |
| 582 | |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 583 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, |
| 584 | nouveau_hwmon_get_pwm1, |
| 585 | nouveau_hwmon_set_pwm1, 0); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 586 | |
| 587 | static ssize_t |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 588 | nouveau_hwmon_get_pwm1_min(struct device *d, |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 589 | struct device_attribute *a, char *buf) |
| 590 | { |
| 591 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 592 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 593 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
| 594 | int ret; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 595 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 596 | ret = therm->attr_get(therm, NOUVEAU_THERM_ATTR_FAN_MIN_DUTY); |
| 597 | if (ret < 0) |
| 598 | return ret; |
| 599 | |
| 600 | return sprintf(buf, "%i\n", ret); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static ssize_t |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 604 | nouveau_hwmon_set_pwm1_min(struct device *d, struct device_attribute *a, |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 605 | const char *buf, size_t count) |
| 606 | { |
| 607 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 608 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 609 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 610 | long value; |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 611 | int ret; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 612 | |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 613 | if (kstrtol(buf, 10, &value) == -EINVAL) |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 614 | return -EINVAL; |
| 615 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 616 | ret = therm->attr_set(therm, NOUVEAU_THERM_ATTR_FAN_MIN_DUTY, value); |
| 617 | if (ret < 0) |
| 618 | return ret; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 619 | |
| 620 | return count; |
| 621 | } |
| 622 | |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 623 | static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO | S_IWUSR, |
| 624 | nouveau_hwmon_get_pwm1_min, |
| 625 | nouveau_hwmon_set_pwm1_min, 0); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 626 | |
| 627 | static ssize_t |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 628 | nouveau_hwmon_get_pwm1_max(struct device *d, |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 629 | struct device_attribute *a, char *buf) |
| 630 | { |
| 631 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 632 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 633 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
| 634 | int ret; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 635 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 636 | ret = therm->attr_get(therm, NOUVEAU_THERM_ATTR_FAN_MAX_DUTY); |
| 637 | if (ret < 0) |
| 638 | return ret; |
| 639 | |
| 640 | return sprintf(buf, "%i\n", ret); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static ssize_t |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 644 | nouveau_hwmon_set_pwm1_max(struct device *d, struct device_attribute *a, |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 645 | const char *buf, size_t count) |
| 646 | { |
| 647 | struct drm_device *dev = dev_get_drvdata(d); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 648 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 649 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 650 | long value; |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 651 | int ret; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 652 | |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 653 | if (kstrtol(buf, 10, &value) == -EINVAL) |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 654 | return -EINVAL; |
| 655 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 656 | ret = therm->attr_set(therm, NOUVEAU_THERM_ATTR_FAN_MAX_DUTY, value); |
| 657 | if (ret < 0) |
| 658 | return ret; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 659 | |
| 660 | return count; |
| 661 | } |
| 662 | |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 663 | static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO | S_IWUSR, |
| 664 | nouveau_hwmon_get_pwm1_max, |
| 665 | nouveau_hwmon_set_pwm1_max, 0); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 666 | |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 667 | static struct attribute *hwmon_attributes[] = { |
| 668 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 669 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 670 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 671 | &sensor_dev_attr_name.dev_attr.attr, |
| 672 | &sensor_dev_attr_update_rate.dev_attr.attr, |
| 673 | NULL |
| 674 | }; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 675 | static struct attribute *hwmon_fan_rpm_attributes[] = { |
| 676 | &sensor_dev_attr_fan0_input.dev_attr.attr, |
| 677 | NULL |
| 678 | }; |
| 679 | static struct attribute *hwmon_pwm_fan_attributes[] = { |
Martin Peres | 2f951a5 | 2012-09-04 13:52:00 +0200 | [diff] [blame] | 680 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
Martin Peres | c9cbf13 | 2012-09-04 13:39:40 +0200 | [diff] [blame] | 681 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 682 | &sensor_dev_attr_pwm1_min.dev_attr.attr, |
| 683 | &sensor_dev_attr_pwm1_max.dev_attr.attr, |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 684 | NULL |
| 685 | }; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 686 | |
| 687 | static const struct attribute_group hwmon_attrgroup = { |
| 688 | .attrs = hwmon_attributes, |
| 689 | }; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 690 | static const struct attribute_group hwmon_fan_rpm_attrgroup = { |
| 691 | .attrs = hwmon_fan_rpm_attributes, |
| 692 | }; |
| 693 | static const struct attribute_group hwmon_pwm_fan_attrgroup = { |
| 694 | .attrs = hwmon_pwm_fan_attributes, |
| 695 | }; |
Martin Peres | b54262f | 2010-10-26 12:48:28 +0200 | [diff] [blame] | 696 | #endif |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 697 | |
| 698 | static int |
| 699 | nouveau_hwmon_init(struct drm_device *dev) |
| 700 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 701 | struct nouveau_pm *pm = nouveau_pm(dev); |
| 702 | struct nouveau_drm *drm = nouveau_drm(dev); |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 703 | struct nouveau_therm *therm = nouveau_therm(drm->device); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 704 | |
Dave Airlie | 095f979 | 2012-01-10 10:13:16 +0000 | [diff] [blame] | 705 | #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 706 | struct device *hwmon_dev; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 707 | int ret = 0; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 708 | |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 709 | if (!therm || !therm->temp_get || !therm->attr_get || |
| 710 | !therm->attr_set || therm->temp_get(therm) < 0) |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 711 | return -ENODEV; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 712 | |
| 713 | hwmon_dev = hwmon_device_register(&dev->pdev->dev); |
| 714 | if (IS_ERR(hwmon_dev)) { |
| 715 | ret = PTR_ERR(hwmon_dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 716 | NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 717 | return ret; |
| 718 | } |
| 719 | dev_set_drvdata(hwmon_dev, dev); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 720 | |
| 721 | /* default sysfs entries */ |
Lucas Stach | 07cfe0e | 2011-01-06 20:29:53 +0100 | [diff] [blame] | 722 | ret = sysfs_create_group(&dev->pdev->dev.kobj, &hwmon_attrgroup); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 723 | if (ret) { |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 724 | if (ret) |
| 725 | goto error; |
| 726 | } |
| 727 | |
| 728 | /* if the card has a pwm fan */ |
| 729 | /*XXX: incorrect, need better detection for this, some boards have |
| 730 | * the gpio entries for pwm fan control even when there's no |
| 731 | * actual fan connected to it... therm table? */ |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 732 | if (therm->fan_get && therm->fan_get(therm) >= 0) { |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 733 | ret = sysfs_create_group(&dev->pdev->dev.kobj, |
| 734 | &hwmon_pwm_fan_attrgroup); |
| 735 | if (ret) |
| 736 | goto error; |
| 737 | } |
| 738 | |
| 739 | /* if the card can read the fan rpm */ |
Martin Peres | aa1b9b4 | 2012-09-02 02:55:58 +0200 | [diff] [blame] | 740 | if (therm->fan_sense(therm) >= 0) { |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 741 | ret = sysfs_create_group(&dev->pdev->dev.kobj, |
| 742 | &hwmon_fan_rpm_attrgroup); |
| 743 | if (ret) |
| 744 | goto error; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 745 | } |
| 746 | |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 747 | pm->hwmon = hwmon_dev; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 748 | |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 749 | return 0; |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 750 | |
| 751 | error: |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 752 | NV_ERROR(drm, "Unable to create some hwmon sysfs files: %d\n", ret); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 753 | hwmon_device_unregister(hwmon_dev); |
| 754 | pm->hwmon = NULL; |
| 755 | return ret; |
| 756 | #else |
| 757 | pm->hwmon = NULL; |
| 758 | return 0; |
| 759 | #endif |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static void |
| 763 | nouveau_hwmon_fini(struct drm_device *dev) |
| 764 | { |
Ken Milmore | 658e86e | 2011-07-03 19:54:28 +0100 | [diff] [blame] | 765 | #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 766 | struct nouveau_pm *pm = nouveau_pm(dev); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 767 | |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 768 | if (pm->hwmon) { |
Lucas Stach | 8c06a3e | 2011-01-30 10:54:11 +0100 | [diff] [blame] | 769 | sysfs_remove_group(&dev->pdev->dev.kobj, &hwmon_attrgroup); |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 770 | sysfs_remove_group(&dev->pdev->dev.kobj, |
| 771 | &hwmon_pwm_fan_attrgroup); |
| 772 | sysfs_remove_group(&dev->pdev->dev.kobj, |
| 773 | &hwmon_fan_rpm_attrgroup); |
Martin Peres | 11b7d895 | 2011-08-15 11:10:30 +1000 | [diff] [blame] | 774 | |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 775 | hwmon_device_unregister(pm->hwmon); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 776 | } |
Martin Peres | b54262f | 2010-10-26 12:48:28 +0200 | [diff] [blame] | 777 | #endif |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 778 | } |
| 779 | |
Martin Peres | 1f96279 | 2011-04-12 00:55:44 +0200 | [diff] [blame] | 780 | #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY) |
Ben Skeggs | 6032649 | 2010-10-12 12:31:32 +1000 | [diff] [blame] | 781 | static int |
| 782 | nouveau_pm_acpi_event(struct notifier_block *nb, unsigned long val, void *data) |
| 783 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 784 | struct nouveau_pm *pm = container_of(nb, struct nouveau_pm, acpi_nb); |
| 785 | struct nouveau_drm *drm = nouveau_drm(pm->dev); |
Ben Skeggs | 6032649 | 2010-10-12 12:31:32 +1000 | [diff] [blame] | 786 | struct acpi_bus_event *entry = (struct acpi_bus_event *)data; |
| 787 | |
| 788 | if (strcmp(entry->device_class, "ac_adapter") == 0) { |
| 789 | bool ac = power_supply_is_system_supplied(); |
| 790 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 791 | NV_DEBUG(drm, "power supply changed: %s\n", ac ? "AC" : "DC"); |
| 792 | nouveau_pm_trigger(pm->dev); |
Ben Skeggs | 6032649 | 2010-10-12 12:31:32 +1000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | return NOTIFY_OK; |
| 796 | } |
| 797 | #endif |
| 798 | |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 799 | int |
| 800 | nouveau_pm_init(struct drm_device *dev) |
| 801 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 802 | struct nouveau_device *device = nouveau_dev(dev); |
| 803 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 804 | struct nouveau_pm *pm; |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 805 | char info[256]; |
| 806 | int ret, i; |
| 807 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 808 | pm = drm->pm = kzalloc(sizeof(*pm), GFP_KERNEL); |
| 809 | if (!pm) |
| 810 | return -ENOMEM; |
| 811 | |
| 812 | pm->dev = dev; |
| 813 | |
| 814 | if (device->card_type < NV_40) { |
| 815 | pm->clocks_get = nv04_pm_clocks_get; |
| 816 | pm->clocks_pre = nv04_pm_clocks_pre; |
| 817 | pm->clocks_set = nv04_pm_clocks_set; |
| 818 | if (nouveau_gpio(drm->device)) { |
| 819 | pm->voltage_get = nouveau_voltage_gpio_get; |
| 820 | pm->voltage_set = nouveau_voltage_gpio_set; |
| 821 | } |
| 822 | } else |
| 823 | if (device->card_type < NV_50) { |
| 824 | pm->clocks_get = nv40_pm_clocks_get; |
| 825 | pm->clocks_pre = nv40_pm_clocks_pre; |
| 826 | pm->clocks_set = nv40_pm_clocks_set; |
| 827 | pm->voltage_get = nouveau_voltage_gpio_get; |
| 828 | pm->voltage_set = nouveau_voltage_gpio_set; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 829 | } else |
| 830 | if (device->card_type < NV_C0) { |
| 831 | if (device->chipset < 0xa3 || |
| 832 | device->chipset == 0xaa || |
| 833 | device->chipset == 0xac) { |
| 834 | pm->clocks_get = nv50_pm_clocks_get; |
| 835 | pm->clocks_pre = nv50_pm_clocks_pre; |
| 836 | pm->clocks_set = nv50_pm_clocks_set; |
| 837 | } else { |
| 838 | pm->clocks_get = nva3_pm_clocks_get; |
| 839 | pm->clocks_pre = nva3_pm_clocks_pre; |
| 840 | pm->clocks_set = nva3_pm_clocks_set; |
| 841 | } |
| 842 | pm->voltage_get = nouveau_voltage_gpio_get; |
| 843 | pm->voltage_set = nouveau_voltage_gpio_set; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 844 | } else |
| 845 | if (device->card_type < NV_E0) { |
| 846 | pm->clocks_get = nvc0_pm_clocks_get; |
| 847 | pm->clocks_pre = nvc0_pm_clocks_pre; |
| 848 | pm->clocks_set = nvc0_pm_clocks_set; |
| 849 | pm->voltage_get = nouveau_voltage_gpio_get; |
| 850 | pm->voltage_set = nouveau_voltage_gpio_set; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | |
Ben Skeggs | 68a64ca | 2012-01-23 13:47:02 +1000 | [diff] [blame] | 854 | /* parse aux tables from vbios */ |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 855 | nouveau_volt_init(dev); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 856 | |
Dmitry Eremin-Solenikov | d89c8ce | 2012-09-25 10:31:40 +0400 | [diff] [blame] | 857 | INIT_LIST_HEAD(&pm->profiles); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 858 | |
Ben Skeggs | 68a64ca | 2012-01-23 13:47:02 +1000 | [diff] [blame] | 859 | /* determine current ("boot") performance level */ |
| 860 | ret = nouveau_pm_perflvl_get(dev, &pm->boot); |
| 861 | if (ret) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 862 | NV_ERROR(drm, "failed to determine boot perflvl\n"); |
Ben Skeggs | 68a64ca | 2012-01-23 13:47:02 +1000 | [diff] [blame] | 863 | return ret; |
| 864 | } |
| 865 | |
| 866 | strncpy(pm->boot.name, "boot", 4); |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 867 | strncpy(pm->boot.profile.name, "boot", 4); |
| 868 | pm->boot.profile.func = &nouveau_pm_static_profile_func; |
| 869 | |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 870 | list_add(&pm->boot.profile.head, &pm->profiles); |
| 871 | |
| 872 | pm->profile_ac = &pm->boot.profile; |
| 873 | pm->profile_dc = &pm->boot.profile; |
Ben Skeggs | 25c53c1 | 2012-01-24 18:03:25 +1000 | [diff] [blame] | 874 | pm->profile = &pm->boot.profile; |
Ben Skeggs | 68a64ca | 2012-01-23 13:47:02 +1000 | [diff] [blame] | 875 | pm->cur = &pm->boot; |
| 876 | |
| 877 | /* add performance levels from vbios */ |
| 878 | nouveau_perf_init(dev); |
| 879 | |
| 880 | /* display available performance levels */ |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 881 | NV_INFO(drm, "%d available performance level(s)\n", pm->nr_perflvl); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 882 | for (i = 0; i < pm->nr_perflvl; i++) { |
| 883 | nouveau_pm_perflvl_info(&pm->perflvl[i], info, sizeof(info)); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 884 | NV_INFO(drm, "%d:%s", pm->perflvl[i].id, info); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 885 | } |
| 886 | |
Ben Skeggs | 68a64ca | 2012-01-23 13:47:02 +1000 | [diff] [blame] | 887 | nouveau_pm_perflvl_info(&pm->boot, info, sizeof(info)); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 888 | NV_INFO(drm, "c:%s", info); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 889 | |
| 890 | /* switch performance levels now if requested */ |
Ben Skeggs | 8d7bb40 | 2012-01-24 15:59:07 +1000 | [diff] [blame] | 891 | if (nouveau_perflvl != NULL) |
| 892 | nouveau_pm_profile_set(dev, nouveau_perflvl); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 893 | |
| 894 | nouveau_sysfs_init(dev); |
| 895 | nouveau_hwmon_init(dev); |
Martin Peres | 1f96279 | 2011-04-12 00:55:44 +0200 | [diff] [blame] | 896 | #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY) |
Ben Skeggs | 6032649 | 2010-10-12 12:31:32 +1000 | [diff] [blame] | 897 | pm->acpi_nb.notifier_call = nouveau_pm_acpi_event; |
| 898 | register_acpi_notifier(&pm->acpi_nb); |
| 899 | #endif |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 900 | |
| 901 | return 0; |
| 902 | } |
| 903 | |
| 904 | void |
| 905 | nouveau_pm_fini(struct drm_device *dev) |
| 906 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 907 | struct nouveau_pm *pm = nouveau_pm(dev); |
Ben Skeggs | 25c53c1 | 2012-01-24 18:03:25 +1000 | [diff] [blame] | 908 | struct nouveau_pm_profile *profile, *tmp; |
| 909 | |
| 910 | list_for_each_entry_safe(profile, tmp, &pm->profiles, head) { |
| 911 | list_del(&profile->head); |
| 912 | profile->func->destroy(profile); |
| 913 | } |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 914 | |
| 915 | if (pm->cur != &pm->boot) |
| 916 | nouveau_pm_perflvl_set(dev, &pm->boot); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 917 | |
| 918 | nouveau_perf_fini(dev); |
| 919 | nouveau_volt_fini(dev); |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 920 | |
Martin Peres | 1f96279 | 2011-04-12 00:55:44 +0200 | [diff] [blame] | 921 | #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY) |
Ben Skeggs | 6032649 | 2010-10-12 12:31:32 +1000 | [diff] [blame] | 922 | unregister_acpi_notifier(&pm->acpi_nb); |
| 923 | #endif |
Martin Peres | 34e9d85 | 2010-09-22 20:54:22 +0200 | [diff] [blame] | 924 | nouveau_hwmon_fini(dev); |
| 925 | nouveau_sysfs_fini(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 926 | |
| 927 | nouveau_drm(dev)->pm = NULL; |
| 928 | kfree(pm); |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 929 | } |
| 930 | |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 931 | void |
| 932 | nouveau_pm_resume(struct drm_device *dev) |
| 933 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 934 | struct nouveau_pm *pm = nouveau_pm(dev); |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 935 | struct nouveau_pm_level *perflvl; |
| 936 | |
Ben Skeggs | 317495b | 2011-02-17 11:11:28 +1000 | [diff] [blame] | 937 | if (!pm->cur || pm->cur == &pm->boot) |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 938 | return; |
| 939 | |
| 940 | perflvl = pm->cur; |
| 941 | pm->cur = &pm->boot; |
| 942 | nouveau_pm_perflvl_set(dev, perflvl); |
| 943 | } |