blob: dc8a0cc8e5dcc1997554b880ed1d472ad1b258f0 [file] [log] [blame]
Ben Skeggs330c5982010-09-16 15:39:49 +10001/*
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
25#include "drmP.h"
26
27#include "nouveau_drv.h"
28#include "nouveau_pm.h"
29
Ben Skeggs60326492010-10-12 12:31:32 +100030#ifdef CONFIG_ACPI
31#include <linux/acpi.h>
32#endif
33#include <linux/power_supply.h>
Martin Peres34e9d852010-09-22 20:54:22 +020034#include <linux/hwmon.h>
35#include <linux/hwmon-sysfs.h>
36
Ben Skeggs330c5982010-09-16 15:39:49 +100037static int
Ben Skeggs5c6dc652010-09-27 09:47:56 +100038nouveau_pm_clock_set(struct drm_device *dev, struct nouveau_pm_level *perflvl,
39 u8 id, u32 khz)
Ben Skeggs6f876982010-09-16 16:47:14 +100040{
41 struct drm_nouveau_private *dev_priv = dev->dev_private;
42 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
43 void *pre_state;
44
45 if (khz == 0)
46 return 0;
47
Ben Skeggs5c6dc652010-09-27 09:47:56 +100048 pre_state = pm->clock_pre(dev, perflvl, id, khz);
Ben Skeggs6f876982010-09-16 16:47:14 +100049 if (IS_ERR(pre_state))
50 return PTR_ERR(pre_state);
51
52 if (pre_state)
53 pm->clock_set(dev, pre_state);
54 return 0;
55}
56
57static int
Ben Skeggs64f1c112010-09-17 13:35:25 +100058nouveau_pm_perflvl_set(struct drm_device *dev, struct nouveau_pm_level *perflvl)
59{
60 struct drm_nouveau_private *dev_priv = dev->dev_private;
61 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
62 int ret;
63
64 if (perflvl == pm->cur)
65 return 0;
66
67 if (pm->voltage.supported && pm->voltage_set && perflvl->voltage) {
68 ret = pm->voltage_set(dev, perflvl->voltage);
69 if (ret) {
70 NV_ERROR(dev, "voltage_set %d failed: %d\n",
71 perflvl->voltage, ret);
72 }
73 }
74
Ben Skeggs5c6dc652010-09-27 09:47:56 +100075 nouveau_pm_clock_set(dev, perflvl, PLL_CORE, perflvl->core);
76 nouveau_pm_clock_set(dev, perflvl, PLL_SHADER, perflvl->shader);
77 nouveau_pm_clock_set(dev, perflvl, PLL_MEMORY, perflvl->memory);
78 nouveau_pm_clock_set(dev, perflvl, PLL_UNK05, perflvl->unk05);
Ben Skeggs64f1c112010-09-17 13:35:25 +100079
80 pm->cur = perflvl;
81 return 0;
82}
83
84static int
Ben Skeggs6f876982010-09-16 16:47:14 +100085nouveau_pm_profile_set(struct drm_device *dev, const char *profile)
86{
87 struct drm_nouveau_private *dev_priv = dev->dev_private;
88 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
89 struct nouveau_pm_level *perflvl = NULL;
Ben Skeggs6f876982010-09-16 16:47:14 +100090
91 /* safety precaution, for now */
92 if (nouveau_perflvl_wr != 7777)
93 return -EPERM;
94
95 if (!pm->clock_set)
96 return -EINVAL;
97
98 if (!strncmp(profile, "boot", 4))
99 perflvl = &pm->boot;
100 else {
101 int pl = simple_strtol(profile, NULL, 10);
102 int i;
103
104 for (i = 0; i < pm->nr_perflvl; i++) {
105 if (pm->perflvl[i].id == pl) {
106 perflvl = &pm->perflvl[i];
107 break;
108 }
109 }
110
111 if (!perflvl)
112 return -EINVAL;
113 }
114
Ben Skeggs6f876982010-09-16 16:47:14 +1000115 NV_INFO(dev, "setting performance level: %s\n", profile);
Ben Skeggs64f1c112010-09-17 13:35:25 +1000116 return nouveau_pm_perflvl_set(dev, perflvl);
Ben Skeggs6f876982010-09-16 16:47:14 +1000117}
118
119static int
Ben Skeggs330c5982010-09-16 15:39:49 +1000120nouveau_pm_perflvl_get(struct drm_device *dev, struct nouveau_pm_level *perflvl)
121{
122 struct drm_nouveau_private *dev_priv = dev->dev_private;
123 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
124 int ret;
125
126 if (!pm->clock_get)
127 return -EINVAL;
128
129 memset(perflvl, 0, sizeof(*perflvl));
130
131 ret = pm->clock_get(dev, PLL_CORE);
132 if (ret > 0)
133 perflvl->core = ret;
134
135 ret = pm->clock_get(dev, PLL_MEMORY);
136 if (ret > 0)
137 perflvl->memory = ret;
138
139 ret = pm->clock_get(dev, PLL_SHADER);
140 if (ret > 0)
141 perflvl->shader = ret;
142
143 ret = pm->clock_get(dev, PLL_UNK05);
144 if (ret > 0)
145 perflvl->unk05 = ret;
146
147 if (pm->voltage.supported && pm->voltage_get) {
148 ret = pm->voltage_get(dev);
149 if (ret > 0)
150 perflvl->voltage = ret;
151 }
152
153 return 0;
154}
155
156static void
157nouveau_pm_perflvl_info(struct nouveau_pm_level *perflvl, char *ptr, int len)
158{
Francisco Jerez0fbb1142010-09-20 16:18:28 +0200159 char c[16], s[16], v[16], f[16];
160
161 c[0] = '\0';
162 if (perflvl->core)
163 snprintf(c, sizeof(c), " core %dMHz", perflvl->core / 1000);
Ben Skeggs330c5982010-09-16 15:39:49 +1000164
165 s[0] = '\0';
166 if (perflvl->shader)
167 snprintf(s, sizeof(s), " shader %dMHz", perflvl->shader / 1000);
168
169 v[0] = '\0';
170 if (perflvl->voltage)
171 snprintf(v, sizeof(v), " voltage %dmV", perflvl->voltage * 10);
172
173 f[0] = '\0';
174 if (perflvl->fanspeed)
175 snprintf(f, sizeof(f), " fanspeed %d%%", perflvl->fanspeed);
176
Francisco Jerez0fbb1142010-09-20 16:18:28 +0200177 snprintf(ptr, len, "memory %dMHz%s%s%s%s\n", perflvl->memory / 1000,
178 c, s, v, f);
Ben Skeggs330c5982010-09-16 15:39:49 +1000179}
180
181static ssize_t
182nouveau_pm_get_perflvl_info(struct device *d,
183 struct device_attribute *a, char *buf)
184{
185 struct nouveau_pm_level *perflvl = (struct nouveau_pm_level *)a;
186 char *ptr = buf;
187 int len = PAGE_SIZE;
188
189 snprintf(ptr, len, "%d: ", perflvl->id);
190 ptr += strlen(buf);
191 len -= strlen(buf);
192
193 nouveau_pm_perflvl_info(perflvl, ptr, len);
194 return strlen(buf);
195}
196
197static ssize_t
198nouveau_pm_get_perflvl(struct device *d, struct device_attribute *a, char *buf)
199{
Martin Peres34e9d852010-09-22 20:54:22 +0200200 struct drm_device *dev = pci_get_drvdata(to_pci_dev(d));
Ben Skeggs330c5982010-09-16 15:39:49 +1000201 struct drm_nouveau_private *dev_priv = dev->dev_private;
202 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
203 struct nouveau_pm_level cur;
204 int len = PAGE_SIZE, ret;
205 char *ptr = buf;
206
207 if (!pm->cur)
208 snprintf(ptr, len, "setting: boot\n");
209 else if (pm->cur == &pm->boot)
210 snprintf(ptr, len, "setting: boot\nc: ");
211 else
212 snprintf(ptr, len, "setting: static %d\nc: ", pm->cur->id);
213 ptr += strlen(buf);
214 len -= strlen(buf);
215
216 ret = nouveau_pm_perflvl_get(dev, &cur);
217 if (ret == 0)
218 nouveau_pm_perflvl_info(&cur, ptr, len);
219 return strlen(buf);
220}
221
222static ssize_t
223nouveau_pm_set_perflvl(struct device *d, struct device_attribute *a,
224 const char *buf, size_t count)
225{
Martin Peres34e9d852010-09-22 20:54:22 +0200226 struct drm_device *dev = pci_get_drvdata(to_pci_dev(d));
Ben Skeggs6f876982010-09-16 16:47:14 +1000227 int ret;
228
229 ret = nouveau_pm_profile_set(dev, buf);
230 if (ret)
231 return ret;
232 return strlen(buf);
Ben Skeggs330c5982010-09-16 15:39:49 +1000233}
234
Francisco Jerez5c4abd02010-09-23 20:36:42 +0200235static DEVICE_ATTR(performance_level, S_IRUGO | S_IWUSR,
236 nouveau_pm_get_perflvl, nouveau_pm_set_perflvl);
Ben Skeggs330c5982010-09-16 15:39:49 +1000237
Martin Peres34e9d852010-09-22 20:54:22 +0200238static int
239nouveau_sysfs_init(struct drm_device *dev)
Ben Skeggs330c5982010-09-16 15:39:49 +1000240{
241 struct drm_nouveau_private *dev_priv = dev->dev_private;
242 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
243 struct device *d = &dev->pdev->dev;
Ben Skeggs330c5982010-09-16 15:39:49 +1000244 int ret, i;
245
Ben Skeggs330c5982010-09-16 15:39:49 +1000246 ret = device_create_file(d, &dev_attr_performance_level);
247 if (ret)
248 return ret;
249
250 for (i = 0; i < pm->nr_perflvl; i++) {
251 struct nouveau_pm_level *perflvl = &pm->perflvl[i];
252
253 perflvl->dev_attr.attr.name = perflvl->name;
254 perflvl->dev_attr.attr.mode = S_IRUGO;
255 perflvl->dev_attr.show = nouveau_pm_get_perflvl_info;
256 perflvl->dev_attr.store = NULL;
257 sysfs_attr_init(&perflvl->dev_attr.attr);
258
259 ret = device_create_file(d, &perflvl->dev_attr);
260 if (ret) {
261 NV_ERROR(dev, "failed pervlvl %d sysfs: %d\n",
262 perflvl->id, i);
263 perflvl->dev_attr.attr.name = NULL;
264 nouveau_pm_fini(dev);
265 return ret;
266 }
267 }
268
269 return 0;
270}
271
Martin Peres34e9d852010-09-22 20:54:22 +0200272static void
273nouveau_sysfs_fini(struct drm_device *dev)
Ben Skeggs330c5982010-09-16 15:39:49 +1000274{
275 struct drm_nouveau_private *dev_priv = dev->dev_private;
276 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
277 struct device *d = &dev->pdev->dev;
278 int i;
279
280 device_remove_file(d, &dev_attr_performance_level);
281 for (i = 0; i < pm->nr_perflvl; i++) {
282 struct nouveau_pm_level *pl = &pm->perflvl[i];
283
284 if (!pl->dev_attr.attr.name)
285 break;
286
287 device_remove_file(d, &pl->dev_attr);
288 }
Martin Peres34e9d852010-09-22 20:54:22 +0200289}
290
Martin Peresb54262f2010-10-26 12:48:28 +0200291#ifdef CONFIG_HWMON
Martin Peres34e9d852010-09-22 20:54:22 +0200292static ssize_t
293nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf)
294{
295 struct drm_device *dev = dev_get_drvdata(d);
Francisco Jerez8155cac2010-09-23 20:58:38 +0200296 struct drm_nouveau_private *dev_priv = dev->dev_private;
297 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
Martin Peres34e9d852010-09-22 20:54:22 +0200298
Francisco Jerez8155cac2010-09-23 20:58:38 +0200299 return snprintf(buf, PAGE_SIZE, "%d\n", pm->temp_get(dev)*1000);
Martin Peres34e9d852010-09-22 20:54:22 +0200300}
301static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp,
302 NULL, 0);
303
304static ssize_t
305nouveau_hwmon_max_temp(struct device *d, struct device_attribute *a, char *buf)
306{
307 struct drm_device *dev = dev_get_drvdata(d);
308 struct drm_nouveau_private *dev_priv = dev->dev_private;
309 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
310 struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp;
311
312 return snprintf(buf, PAGE_SIZE, "%d\n", temp->down_clock*1000);
313}
314static ssize_t
315nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a,
316 const char *buf, size_t count)
317{
318 struct drm_device *dev = dev_get_drvdata(d);
319 struct drm_nouveau_private *dev_priv = dev->dev_private;
320 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
321 struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp;
322 long value;
323
Francisco Jerez5c4abd02010-09-23 20:36:42 +0200324 if (strict_strtol(buf, 10, &value) == -EINVAL)
Martin Peres34e9d852010-09-22 20:54:22 +0200325 return count;
326
327 temp->down_clock = value/1000;
328
329 nouveau_temp_safety_checks(dev);
330
331 return count;
332}
333static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, nouveau_hwmon_max_temp,
334 nouveau_hwmon_set_max_temp,
335 0);
336
337static ssize_t
338nouveau_hwmon_critical_temp(struct device *d, struct device_attribute *a,
339 char *buf)
340{
341 struct drm_device *dev = dev_get_drvdata(d);
342 struct drm_nouveau_private *dev_priv = dev->dev_private;
343 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
344 struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp;
345
346 return snprintf(buf, PAGE_SIZE, "%d\n", temp->critical*1000);
347}
348static ssize_t
349nouveau_hwmon_set_critical_temp(struct device *d, struct device_attribute *a,
350 const char *buf,
351 size_t count)
352{
353 struct drm_device *dev = dev_get_drvdata(d);
354 struct drm_nouveau_private *dev_priv = dev->dev_private;
355 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
356 struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp;
357 long value;
358
Francisco Jerez5c4abd02010-09-23 20:36:42 +0200359 if (strict_strtol(buf, 10, &value) == -EINVAL)
Martin Peres34e9d852010-09-22 20:54:22 +0200360 return count;
361
362 temp->critical = value/1000;
363
364 nouveau_temp_safety_checks(dev);
365
366 return count;
367}
368static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR,
369 nouveau_hwmon_critical_temp,
370 nouveau_hwmon_set_critical_temp,
371 0);
372
373static ssize_t nouveau_hwmon_show_name(struct device *dev,
374 struct device_attribute *attr,
375 char *buf)
376{
377 return sprintf(buf, "nouveau\n");
378}
379static SENSOR_DEVICE_ATTR(name, S_IRUGO, nouveau_hwmon_show_name, NULL, 0);
380
381static ssize_t nouveau_hwmon_show_update_rate(struct device *dev,
382 struct device_attribute *attr,
383 char *buf)
384{
385 return sprintf(buf, "1000\n");
386}
387static SENSOR_DEVICE_ATTR(update_rate, S_IRUGO,
388 nouveau_hwmon_show_update_rate,
389 NULL, 0);
390
391static struct attribute *hwmon_attributes[] = {
392 &sensor_dev_attr_temp1_input.dev_attr.attr,
393 &sensor_dev_attr_temp1_max.dev_attr.attr,
394 &sensor_dev_attr_temp1_crit.dev_attr.attr,
395 &sensor_dev_attr_name.dev_attr.attr,
396 &sensor_dev_attr_update_rate.dev_attr.attr,
397 NULL
398};
399
400static const struct attribute_group hwmon_attrgroup = {
401 .attrs = hwmon_attributes,
402};
Martin Peresb54262f2010-10-26 12:48:28 +0200403#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200404
405static int
406nouveau_hwmon_init(struct drm_device *dev)
407{
Martin Peresb54262f2010-10-26 12:48:28 +0200408#ifdef CONFIG_HWMON
Martin Peres34e9d852010-09-22 20:54:22 +0200409 struct drm_nouveau_private *dev_priv = dev->dev_private;
Francisco Jerez8155cac2010-09-23 20:58:38 +0200410 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
Martin Peres34e9d852010-09-22 20:54:22 +0200411 struct device *hwmon_dev;
412 int ret;
413
Francisco Jerez8155cac2010-09-23 20:58:38 +0200414 if (!pm->temp_get)
415 return -ENODEV;
Martin Peres34e9d852010-09-22 20:54:22 +0200416
417 hwmon_dev = hwmon_device_register(&dev->pdev->dev);
418 if (IS_ERR(hwmon_dev)) {
419 ret = PTR_ERR(hwmon_dev);
420 NV_ERROR(dev,
421 "Unable to register hwmon device: %d\n", ret);
422 return ret;
423 }
424 dev_set_drvdata(hwmon_dev, dev);
Lucas Stach07cfe0e2011-01-06 20:29:53 +0100425 ret = sysfs_create_group(&dev->pdev->dev.kobj, &hwmon_attrgroup);
Martin Peres34e9d852010-09-22 20:54:22 +0200426 if (ret) {
427 NV_ERROR(dev,
428 "Unable to create hwmon sysfs file: %d\n", ret);
429 hwmon_device_unregister(hwmon_dev);
430 return ret;
431 }
432
Francisco Jerez8155cac2010-09-23 20:58:38 +0200433 pm->hwmon = hwmon_dev;
Martin Peresb54262f2010-10-26 12:48:28 +0200434#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200435 return 0;
436}
437
438static void
439nouveau_hwmon_fini(struct drm_device *dev)
440{
Martin Peresb54262f2010-10-26 12:48:28 +0200441#ifdef CONFIG_HWMON
Martin Peres34e9d852010-09-22 20:54:22 +0200442 struct drm_nouveau_private *dev_priv = dev->dev_private;
Francisco Jerez8155cac2010-09-23 20:58:38 +0200443 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
Martin Peres34e9d852010-09-22 20:54:22 +0200444
Francisco Jerez8155cac2010-09-23 20:58:38 +0200445 if (pm->hwmon) {
Lucas Stach8c06a3e2011-01-30 10:54:11 +0100446 sysfs_remove_group(&dev->pdev->dev.kobj, &hwmon_attrgroup);
Francisco Jerez8155cac2010-09-23 20:58:38 +0200447 hwmon_device_unregister(pm->hwmon);
Martin Peres34e9d852010-09-22 20:54:22 +0200448 }
Martin Peresb54262f2010-10-26 12:48:28 +0200449#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200450}
451
Martin Peres1f962792011-04-12 00:55:44 +0200452#if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
Ben Skeggs60326492010-10-12 12:31:32 +1000453static int
454nouveau_pm_acpi_event(struct notifier_block *nb, unsigned long val, void *data)
455{
456 struct drm_nouveau_private *dev_priv =
457 container_of(nb, struct drm_nouveau_private, engine.pm.acpi_nb);
458 struct drm_device *dev = dev_priv->dev;
459 struct acpi_bus_event *entry = (struct acpi_bus_event *)data;
460
461 if (strcmp(entry->device_class, "ac_adapter") == 0) {
462 bool ac = power_supply_is_system_supplied();
463
464 NV_DEBUG(dev, "power supply changed: %s\n", ac ? "AC" : "DC");
465 }
466
467 return NOTIFY_OK;
468}
469#endif
470
Martin Peres34e9d852010-09-22 20:54:22 +0200471int
472nouveau_pm_init(struct drm_device *dev)
473{
474 struct drm_nouveau_private *dev_priv = dev->dev_private;
475 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
476 char info[256];
477 int ret, i;
478
479 nouveau_volt_init(dev);
480 nouveau_perf_init(dev);
481 nouveau_temp_init(dev);
Roy Spliet7760fcb2010-09-17 23:17:24 +0200482 nouveau_mem_timing_init(dev);
Martin Peres34e9d852010-09-22 20:54:22 +0200483
484 NV_INFO(dev, "%d available performance level(s)\n", pm->nr_perflvl);
485 for (i = 0; i < pm->nr_perflvl; i++) {
486 nouveau_pm_perflvl_info(&pm->perflvl[i], info, sizeof(info));
487 NV_INFO(dev, "%d: %s", pm->perflvl[i].id, info);
488 }
489
490 /* determine current ("boot") performance level */
491 ret = nouveau_pm_perflvl_get(dev, &pm->boot);
492 if (ret == 0) {
Martin Peres01e542c2011-03-19 22:44:35 +0100493 strncpy(pm->boot.name, "boot", 4);
Martin Peres34e9d852010-09-22 20:54:22 +0200494 pm->cur = &pm->boot;
495
496 nouveau_pm_perflvl_info(&pm->boot, info, sizeof(info));
497 NV_INFO(dev, "c: %s", info);
498 }
499
500 /* switch performance levels now if requested */
501 if (nouveau_perflvl != NULL) {
502 ret = nouveau_pm_profile_set(dev, nouveau_perflvl);
503 if (ret) {
504 NV_ERROR(dev, "error setting perflvl \"%s\": %d\n",
505 nouveau_perflvl, ret);
506 }
507 }
508
509 nouveau_sysfs_init(dev);
510 nouveau_hwmon_init(dev);
Martin Peres1f962792011-04-12 00:55:44 +0200511#if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
Ben Skeggs60326492010-10-12 12:31:32 +1000512 pm->acpi_nb.notifier_call = nouveau_pm_acpi_event;
513 register_acpi_notifier(&pm->acpi_nb);
514#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200515
516 return 0;
517}
518
519void
520nouveau_pm_fini(struct drm_device *dev)
521{
522 struct drm_nouveau_private *dev_priv = dev->dev_private;
523 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
524
525 if (pm->cur != &pm->boot)
526 nouveau_pm_perflvl_set(dev, &pm->boot);
Ben Skeggs330c5982010-09-16 15:39:49 +1000527
Roy Spliet7760fcb2010-09-17 23:17:24 +0200528 nouveau_mem_timing_fini(dev);
529 nouveau_temp_fini(dev);
Ben Skeggs330c5982010-09-16 15:39:49 +1000530 nouveau_perf_fini(dev);
531 nouveau_volt_fini(dev);
Martin Peres34e9d852010-09-22 20:54:22 +0200532
Martin Peres1f962792011-04-12 00:55:44 +0200533#if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
Ben Skeggs60326492010-10-12 12:31:32 +1000534 unregister_acpi_notifier(&pm->acpi_nb);
535#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200536 nouveau_hwmon_fini(dev);
537 nouveau_sysfs_fini(dev);
Ben Skeggs330c5982010-09-16 15:39:49 +1000538}
539
Ben Skeggs64f1c112010-09-17 13:35:25 +1000540void
541nouveau_pm_resume(struct drm_device *dev)
542{
543 struct drm_nouveau_private *dev_priv = dev->dev_private;
544 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
545 struct nouveau_pm_level *perflvl;
546
Ben Skeggs317495b2011-02-17 11:11:28 +1000547 if (!pm->cur || pm->cur == &pm->boot)
Ben Skeggs64f1c112010-09-17 13:35:25 +1000548 return;
549
550 perflvl = pm->cur;
551 pm->cur = &pm->boot;
552 nouveau_pm_perflvl_set(dev, perflvl);
553}