blob: cab576b2f15e5c8ed11aacf3e33ae0eedb5ad1f1 [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
Ben Skeggs3b5565d2011-06-09 16:57:07 +100067 if (pm->voltage.supported && pm->voltage_set && perflvl->volt_min) {
68 ret = pm->voltage_set(dev, perflvl->volt_min);
Ben Skeggs64f1c112010-09-17 13:35:25 +100069 if (ret) {
70 NV_ERROR(dev, "voltage_set %d failed: %d\n",
Ben Skeggs3b5565d2011-06-09 16:57:07 +100071 perflvl->volt_min, ret);
Ben Skeggs64f1c112010-09-17 13:35:25 +100072 }
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);
Ben Skeggs3b5565d2011-06-09 16:57:07 +1000149 if (ret > 0) {
150 perflvl->volt_min = ret;
151 perflvl->volt_max = ret;
152 }
Ben Skeggs330c5982010-09-16 15:39:49 +1000153 }
154
155 return 0;
156}
157
158static void
159nouveau_pm_perflvl_info(struct nouveau_pm_level *perflvl, char *ptr, int len)
160{
Ben Skeggs3b5565d2011-06-09 16:57:07 +1000161 char c[16], s[16], v[32], f[16], t[16];
Francisco Jerez0fbb1142010-09-20 16:18:28 +0200162
163 c[0] = '\0';
164 if (perflvl->core)
165 snprintf(c, sizeof(c), " core %dMHz", perflvl->core / 1000);
Ben Skeggs330c5982010-09-16 15:39:49 +1000166
167 s[0] = '\0';
168 if (perflvl->shader)
169 snprintf(s, sizeof(s), " shader %dMHz", perflvl->shader / 1000);
170
171 v[0] = '\0';
Ben Skeggs3b5565d2011-06-09 16:57:07 +1000172 if (perflvl->volt_min && perflvl->volt_min != perflvl->volt_max) {
173 snprintf(v, sizeof(v), " voltage %dmV-%dmV",
174 perflvl->volt_min / 1000, perflvl->volt_max / 1000);
175 } else
176 if (perflvl->volt_min) {
177 snprintf(v, sizeof(v), " voltage %dmV",
178 perflvl->volt_min / 1000);
179 }
Ben Skeggs330c5982010-09-16 15:39:49 +1000180
181 f[0] = '\0';
182 if (perflvl->fanspeed)
183 snprintf(f, sizeof(f), " fanspeed %d%%", perflvl->fanspeed);
184
Martin Perese614b2e2011-04-14 00:46:19 +0200185 t[0] = '\0';
186 if (perflvl->timing)
187 snprintf(t, sizeof(t), " timing %d", perflvl->timing->id);
188
189 snprintf(ptr, len, "memory %dMHz%s%s%s%s%s\n", perflvl->memory / 1000,
190 c, s, v, f, t);
Ben Skeggs330c5982010-09-16 15:39:49 +1000191}
192
193static ssize_t
194nouveau_pm_get_perflvl_info(struct device *d,
195 struct device_attribute *a, char *buf)
196{
197 struct nouveau_pm_level *perflvl = (struct nouveau_pm_level *)a;
198 char *ptr = buf;
199 int len = PAGE_SIZE;
200
201 snprintf(ptr, len, "%d: ", perflvl->id);
202 ptr += strlen(buf);
203 len -= strlen(buf);
204
205 nouveau_pm_perflvl_info(perflvl, ptr, len);
206 return strlen(buf);
207}
208
209static ssize_t
210nouveau_pm_get_perflvl(struct device *d, struct device_attribute *a, char *buf)
211{
Martin Peres34e9d852010-09-22 20:54:22 +0200212 struct drm_device *dev = pci_get_drvdata(to_pci_dev(d));
Ben Skeggs330c5982010-09-16 15:39:49 +1000213 struct drm_nouveau_private *dev_priv = dev->dev_private;
214 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
215 struct nouveau_pm_level cur;
216 int len = PAGE_SIZE, ret;
217 char *ptr = buf;
218
219 if (!pm->cur)
220 snprintf(ptr, len, "setting: boot\n");
221 else if (pm->cur == &pm->boot)
222 snprintf(ptr, len, "setting: boot\nc: ");
223 else
224 snprintf(ptr, len, "setting: static %d\nc: ", pm->cur->id);
225 ptr += strlen(buf);
226 len -= strlen(buf);
227
228 ret = nouveau_pm_perflvl_get(dev, &cur);
229 if (ret == 0)
230 nouveau_pm_perflvl_info(&cur, ptr, len);
231 return strlen(buf);
232}
233
234static ssize_t
235nouveau_pm_set_perflvl(struct device *d, struct device_attribute *a,
236 const char *buf, size_t count)
237{
Martin Peres34e9d852010-09-22 20:54:22 +0200238 struct drm_device *dev = pci_get_drvdata(to_pci_dev(d));
Ben Skeggs6f876982010-09-16 16:47:14 +1000239 int ret;
240
241 ret = nouveau_pm_profile_set(dev, buf);
242 if (ret)
243 return ret;
244 return strlen(buf);
Ben Skeggs330c5982010-09-16 15:39:49 +1000245}
246
Francisco Jerez5c4abd02010-09-23 20:36:42 +0200247static DEVICE_ATTR(performance_level, S_IRUGO | S_IWUSR,
248 nouveau_pm_get_perflvl, nouveau_pm_set_perflvl);
Ben Skeggs330c5982010-09-16 15:39:49 +1000249
Martin Peres34e9d852010-09-22 20:54:22 +0200250static int
251nouveau_sysfs_init(struct drm_device *dev)
Ben Skeggs330c5982010-09-16 15:39:49 +1000252{
253 struct drm_nouveau_private *dev_priv = dev->dev_private;
254 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
255 struct device *d = &dev->pdev->dev;
Ben Skeggs330c5982010-09-16 15:39:49 +1000256 int ret, i;
257
Ben Skeggs330c5982010-09-16 15:39:49 +1000258 ret = device_create_file(d, &dev_attr_performance_level);
259 if (ret)
260 return ret;
261
262 for (i = 0; i < pm->nr_perflvl; i++) {
263 struct nouveau_pm_level *perflvl = &pm->perflvl[i];
264
265 perflvl->dev_attr.attr.name = perflvl->name;
266 perflvl->dev_attr.attr.mode = S_IRUGO;
267 perflvl->dev_attr.show = nouveau_pm_get_perflvl_info;
268 perflvl->dev_attr.store = NULL;
269 sysfs_attr_init(&perflvl->dev_attr.attr);
270
271 ret = device_create_file(d, &perflvl->dev_attr);
272 if (ret) {
273 NV_ERROR(dev, "failed pervlvl %d sysfs: %d\n",
274 perflvl->id, i);
275 perflvl->dev_attr.attr.name = NULL;
276 nouveau_pm_fini(dev);
277 return ret;
278 }
279 }
280
281 return 0;
282}
283
Martin Peres34e9d852010-09-22 20:54:22 +0200284static void
285nouveau_sysfs_fini(struct drm_device *dev)
Ben Skeggs330c5982010-09-16 15:39:49 +1000286{
287 struct drm_nouveau_private *dev_priv = dev->dev_private;
288 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
289 struct device *d = &dev->pdev->dev;
290 int i;
291
292 device_remove_file(d, &dev_attr_performance_level);
293 for (i = 0; i < pm->nr_perflvl; i++) {
294 struct nouveau_pm_level *pl = &pm->perflvl[i];
295
296 if (!pl->dev_attr.attr.name)
297 break;
298
299 device_remove_file(d, &pl->dev_attr);
300 }
Martin Peres34e9d852010-09-22 20:54:22 +0200301}
302
Martin Peresb54262f2010-10-26 12:48:28 +0200303#ifdef CONFIG_HWMON
Martin Peres34e9d852010-09-22 20:54:22 +0200304static ssize_t
305nouveau_hwmon_show_temp(struct device *d, struct device_attribute *a, char *buf)
306{
307 struct drm_device *dev = dev_get_drvdata(d);
Francisco Jerez8155cac2010-09-23 20:58:38 +0200308 struct drm_nouveau_private *dev_priv = dev->dev_private;
309 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
Martin Peres34e9d852010-09-22 20:54:22 +0200310
Francisco Jerez8155cac2010-09-23 20:58:38 +0200311 return snprintf(buf, PAGE_SIZE, "%d\n", pm->temp_get(dev)*1000);
Martin Peres34e9d852010-09-22 20:54:22 +0200312}
313static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, nouveau_hwmon_show_temp,
314 NULL, 0);
315
316static ssize_t
317nouveau_hwmon_max_temp(struct device *d, struct device_attribute *a, char *buf)
318{
319 struct drm_device *dev = dev_get_drvdata(d);
320 struct drm_nouveau_private *dev_priv = dev->dev_private;
321 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
322 struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp;
323
324 return snprintf(buf, PAGE_SIZE, "%d\n", temp->down_clock*1000);
325}
326static ssize_t
327nouveau_hwmon_set_max_temp(struct device *d, struct device_attribute *a,
328 const char *buf, size_t count)
329{
330 struct drm_device *dev = dev_get_drvdata(d);
331 struct drm_nouveau_private *dev_priv = dev->dev_private;
332 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
333 struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp;
334 long value;
335
Francisco Jerez5c4abd02010-09-23 20:36:42 +0200336 if (strict_strtol(buf, 10, &value) == -EINVAL)
Martin Peres34e9d852010-09-22 20:54:22 +0200337 return count;
338
339 temp->down_clock = value/1000;
340
341 nouveau_temp_safety_checks(dev);
342
343 return count;
344}
345static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, nouveau_hwmon_max_temp,
346 nouveau_hwmon_set_max_temp,
347 0);
348
349static ssize_t
350nouveau_hwmon_critical_temp(struct device *d, struct device_attribute *a,
351 char *buf)
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
358 return snprintf(buf, PAGE_SIZE, "%d\n", temp->critical*1000);
359}
360static ssize_t
361nouveau_hwmon_set_critical_temp(struct device *d, struct device_attribute *a,
362 const char *buf,
363 size_t count)
364{
365 struct drm_device *dev = dev_get_drvdata(d);
366 struct drm_nouveau_private *dev_priv = dev->dev_private;
367 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
368 struct nouveau_pm_threshold_temp *temp = &pm->threshold_temp;
369 long value;
370
Francisco Jerez5c4abd02010-09-23 20:36:42 +0200371 if (strict_strtol(buf, 10, &value) == -EINVAL)
Martin Peres34e9d852010-09-22 20:54:22 +0200372 return count;
373
374 temp->critical = value/1000;
375
376 nouveau_temp_safety_checks(dev);
377
378 return count;
379}
380static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO | S_IWUSR,
381 nouveau_hwmon_critical_temp,
382 nouveau_hwmon_set_critical_temp,
383 0);
384
385static ssize_t nouveau_hwmon_show_name(struct device *dev,
386 struct device_attribute *attr,
387 char *buf)
388{
389 return sprintf(buf, "nouveau\n");
390}
391static SENSOR_DEVICE_ATTR(name, S_IRUGO, nouveau_hwmon_show_name, NULL, 0);
392
393static ssize_t nouveau_hwmon_show_update_rate(struct device *dev,
394 struct device_attribute *attr,
395 char *buf)
396{
397 return sprintf(buf, "1000\n");
398}
399static SENSOR_DEVICE_ATTR(update_rate, S_IRUGO,
400 nouveau_hwmon_show_update_rate,
401 NULL, 0);
402
403static struct attribute *hwmon_attributes[] = {
404 &sensor_dev_attr_temp1_input.dev_attr.attr,
405 &sensor_dev_attr_temp1_max.dev_attr.attr,
406 &sensor_dev_attr_temp1_crit.dev_attr.attr,
407 &sensor_dev_attr_name.dev_attr.attr,
408 &sensor_dev_attr_update_rate.dev_attr.attr,
409 NULL
410};
411
412static const struct attribute_group hwmon_attrgroup = {
413 .attrs = hwmon_attributes,
414};
Martin Peresb54262f2010-10-26 12:48:28 +0200415#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200416
417static int
418nouveau_hwmon_init(struct drm_device *dev)
419{
Martin Peresb54262f2010-10-26 12:48:28 +0200420#ifdef CONFIG_HWMON
Martin Peres34e9d852010-09-22 20:54:22 +0200421 struct drm_nouveau_private *dev_priv = dev->dev_private;
Francisco Jerez8155cac2010-09-23 20:58:38 +0200422 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
Martin Peres34e9d852010-09-22 20:54:22 +0200423 struct device *hwmon_dev;
424 int ret;
425
Francisco Jerez8155cac2010-09-23 20:58:38 +0200426 if (!pm->temp_get)
427 return -ENODEV;
Martin Peres34e9d852010-09-22 20:54:22 +0200428
429 hwmon_dev = hwmon_device_register(&dev->pdev->dev);
430 if (IS_ERR(hwmon_dev)) {
431 ret = PTR_ERR(hwmon_dev);
432 NV_ERROR(dev,
433 "Unable to register hwmon device: %d\n", ret);
434 return ret;
435 }
436 dev_set_drvdata(hwmon_dev, dev);
Lucas Stach07cfe0e2011-01-06 20:29:53 +0100437 ret = sysfs_create_group(&dev->pdev->dev.kobj, &hwmon_attrgroup);
Martin Peres34e9d852010-09-22 20:54:22 +0200438 if (ret) {
439 NV_ERROR(dev,
440 "Unable to create hwmon sysfs file: %d\n", ret);
441 hwmon_device_unregister(hwmon_dev);
442 return ret;
443 }
444
Francisco Jerez8155cac2010-09-23 20:58:38 +0200445 pm->hwmon = hwmon_dev;
Martin Peresb54262f2010-10-26 12:48:28 +0200446#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200447 return 0;
448}
449
450static void
451nouveau_hwmon_fini(struct drm_device *dev)
452{
Martin Peresb54262f2010-10-26 12:48:28 +0200453#ifdef CONFIG_HWMON
Martin Peres34e9d852010-09-22 20:54:22 +0200454 struct drm_nouveau_private *dev_priv = dev->dev_private;
Francisco Jerez8155cac2010-09-23 20:58:38 +0200455 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
Martin Peres34e9d852010-09-22 20:54:22 +0200456
Francisco Jerez8155cac2010-09-23 20:58:38 +0200457 if (pm->hwmon) {
Lucas Stach8c06a3e2011-01-30 10:54:11 +0100458 sysfs_remove_group(&dev->pdev->dev.kobj, &hwmon_attrgroup);
Francisco Jerez8155cac2010-09-23 20:58:38 +0200459 hwmon_device_unregister(pm->hwmon);
Martin Peres34e9d852010-09-22 20:54:22 +0200460 }
Martin Peresb54262f2010-10-26 12:48:28 +0200461#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200462}
463
Martin Peres1f962792011-04-12 00:55:44 +0200464#if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
Ben Skeggs60326492010-10-12 12:31:32 +1000465static int
466nouveau_pm_acpi_event(struct notifier_block *nb, unsigned long val, void *data)
467{
468 struct drm_nouveau_private *dev_priv =
469 container_of(nb, struct drm_nouveau_private, engine.pm.acpi_nb);
470 struct drm_device *dev = dev_priv->dev;
471 struct acpi_bus_event *entry = (struct acpi_bus_event *)data;
472
473 if (strcmp(entry->device_class, "ac_adapter") == 0) {
474 bool ac = power_supply_is_system_supplied();
475
476 NV_DEBUG(dev, "power supply changed: %s\n", ac ? "AC" : "DC");
477 }
478
479 return NOTIFY_OK;
480}
481#endif
482
Martin Peres34e9d852010-09-22 20:54:22 +0200483int
484nouveau_pm_init(struct drm_device *dev)
485{
486 struct drm_nouveau_private *dev_priv = dev->dev_private;
487 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
488 char info[256];
489 int ret, i;
490
Martin Perese614b2e2011-04-14 00:46:19 +0200491 nouveau_mem_timing_init(dev);
Martin Peres34e9d852010-09-22 20:54:22 +0200492 nouveau_volt_init(dev);
493 nouveau_perf_init(dev);
494 nouveau_temp_init(dev);
495
496 NV_INFO(dev, "%d available performance level(s)\n", pm->nr_perflvl);
497 for (i = 0; i < pm->nr_perflvl; i++) {
498 nouveau_pm_perflvl_info(&pm->perflvl[i], info, sizeof(info));
499 NV_INFO(dev, "%d: %s", pm->perflvl[i].id, info);
500 }
501
502 /* determine current ("boot") performance level */
503 ret = nouveau_pm_perflvl_get(dev, &pm->boot);
504 if (ret == 0) {
Martin Peres01e542c2011-03-19 22:44:35 +0100505 strncpy(pm->boot.name, "boot", 4);
Martin Peres34e9d852010-09-22 20:54:22 +0200506 pm->cur = &pm->boot;
507
508 nouveau_pm_perflvl_info(&pm->boot, info, sizeof(info));
509 NV_INFO(dev, "c: %s", info);
510 }
511
512 /* switch performance levels now if requested */
513 if (nouveau_perflvl != NULL) {
514 ret = nouveau_pm_profile_set(dev, nouveau_perflvl);
515 if (ret) {
516 NV_ERROR(dev, "error setting perflvl \"%s\": %d\n",
517 nouveau_perflvl, ret);
518 }
519 }
520
521 nouveau_sysfs_init(dev);
522 nouveau_hwmon_init(dev);
Martin Peres1f962792011-04-12 00:55:44 +0200523#if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
Ben Skeggs60326492010-10-12 12:31:32 +1000524 pm->acpi_nb.notifier_call = nouveau_pm_acpi_event;
525 register_acpi_notifier(&pm->acpi_nb);
526#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200527
528 return 0;
529}
530
531void
532nouveau_pm_fini(struct drm_device *dev)
533{
534 struct drm_nouveau_private *dev_priv = dev->dev_private;
535 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
536
537 if (pm->cur != &pm->boot)
538 nouveau_pm_perflvl_set(dev, &pm->boot);
Ben Skeggs330c5982010-09-16 15:39:49 +1000539
Roy Spliet7760fcb2010-09-17 23:17:24 +0200540 nouveau_temp_fini(dev);
Ben Skeggs330c5982010-09-16 15:39:49 +1000541 nouveau_perf_fini(dev);
542 nouveau_volt_fini(dev);
Martin Perese614b2e2011-04-14 00:46:19 +0200543 nouveau_mem_timing_fini(dev);
Martin Peres34e9d852010-09-22 20:54:22 +0200544
Martin Peres1f962792011-04-12 00:55:44 +0200545#if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
Ben Skeggs60326492010-10-12 12:31:32 +1000546 unregister_acpi_notifier(&pm->acpi_nb);
547#endif
Martin Peres34e9d852010-09-22 20:54:22 +0200548 nouveau_hwmon_fini(dev);
549 nouveau_sysfs_fini(dev);
Ben Skeggs330c5982010-09-16 15:39:49 +1000550}
551
Ben Skeggs64f1c112010-09-17 13:35:25 +1000552void
553nouveau_pm_resume(struct drm_device *dev)
554{
555 struct drm_nouveau_private *dev_priv = dev->dev_private;
556 struct nouveau_pm_engine *pm = &dev_priv->engine.pm;
557 struct nouveau_pm_level *perflvl;
558
Ben Skeggs317495b2011-02-17 11:11:28 +1000559 if (!pm->cur || pm->cur == &pm->boot)
Ben Skeggs64f1c112010-09-17 13:35:25 +1000560 return;
561
562 perflvl = pm->cur;
563 pm->cur = &pm->boot;
564 nouveau_pm_perflvl_set(dev, perflvl);
565}