2 * Copyright 2010 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 #include "nouveau_drv.h"
28 #include "nouveau_pm.h"
29 #include "nouveau_gpio.h"
32 #include <linux/acpi.h>
34 #include <linux/power_supply.h>
35 #include <linux/hwmon.h>
36 #include <linux/hwmon-sysfs.h>
39 nouveau_pwmfan_get(struct drm_device
*dev
)
41 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
42 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
43 struct gpio_func gpio
;
50 ret
= nouveau_gpio_find(dev
, 0, DCB_GPIO_PWM_FAN
, 0xff, &gpio
);
52 ret
= pm
->pwm_get(dev
, gpio
.line
, &divs
, &duty
);
53 if (ret
== 0 && divs
) {
54 divs
= max(divs
, duty
);
55 if (dev_priv
->card_type
<= NV_40
|| (gpio
.log
[0] & 1))
57 return (duty
* 100) / divs
;
60 return nouveau_gpio_func_get(dev
, gpio
.func
) * 100;
67 nouveau_pwmfan_set(struct drm_device
*dev
, int percent
)
69 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
70 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
71 struct gpio_func gpio
;
78 ret
= nouveau_gpio_find(dev
, 0, DCB_GPIO_PWM_FAN
, 0xff, &gpio
);
80 divs
= pm
->fan
.pwm_divisor
;
81 if (pm
->fan
.pwm_freq
) {
82 /*XXX: PNVIO clock more than likely... */
83 divs
= 135000 / pm
->fan
.pwm_freq
;
84 if (dev_priv
->chipset
< 0xa3)
88 duty
= ((divs
* percent
) + 99) / 100;
89 if (dev_priv
->card_type
<= NV_40
|| (gpio
.log
[0] & 1))
92 ret
= pm
->pwm_set(dev
, gpio
.line
, divs
, duty
);
94 pm
->fan
.percent
= percent
;
102 nouveau_pm_perflvl_aux(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
,
103 struct nouveau_pm_level
*a
, struct nouveau_pm_level
*b
)
105 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
106 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
109 /*XXX: not on all boards, we should control based on temperature
110 * on recent boards.. or maybe on some other factor we don't
113 if (a
->fanspeed
&& b
->fanspeed
&& b
->fanspeed
> a
->fanspeed
) {
114 ret
= nouveau_pwmfan_set(dev
, perflvl
->fanspeed
);
115 if (ret
&& ret
!= -ENODEV
) {
116 NV_ERROR(dev
, "fanspeed set failed: %d\n", ret
);
121 if (pm
->voltage
.supported
&& pm
->voltage_set
) {
122 if (perflvl
->volt_min
&& b
->volt_min
> a
->volt_min
) {
123 ret
= pm
->voltage_set(dev
, perflvl
->volt_min
);
125 NV_ERROR(dev
, "voltage set failed: %d\n", ret
);
135 nouveau_pm_perflvl_set(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
137 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
138 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
142 if (perflvl
== pm
->cur
)
145 ret
= nouveau_pm_perflvl_aux(dev
, perflvl
, pm
->cur
, perflvl
);
149 state
= pm
->clocks_pre(dev
, perflvl
);
151 ret
= PTR_ERR(state
);
154 ret
= pm
->clocks_set(dev
, state
);
158 ret
= nouveau_pm_perflvl_aux(dev
, perflvl
, perflvl
, pm
->cur
);
166 /* restore the fan speed and voltage before leaving */
167 nouveau_pm_perflvl_aux(dev
, perflvl
, perflvl
, pm
->cur
);
172 nouveau_pm_profile_set(struct drm_device
*dev
, const char *profile
)
174 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
175 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
176 struct nouveau_pm_level
*perflvl
= NULL
;
181 /* safety precaution, for now */
182 if (nouveau_perflvl_wr
!= 7777)
185 if (!strncmp(profile
, "boot", 4))
189 if (kstrtol(profile
, 10, &pl
) == -EINVAL
)
192 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
193 if (pm
->perflvl
[i
].id
== pl
) {
194 perflvl
= &pm
->perflvl
[i
];
203 NV_INFO(dev
, "setting performance level: %s", profile
);
204 start_time
= nv04_timer_read(dev
);
205 ret
= nouveau_pm_perflvl_set(dev
, perflvl
);
207 NV_INFO(dev
, "> reclocking took %lluns\n\n",
208 (nv04_timer_read(dev
) - start_time
));
210 NV_INFO(dev
, "> reclocking failed\n\n");
217 nouveau_pm_perflvl_get(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
219 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
220 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
223 memset(perflvl
, 0, sizeof(*perflvl
));
225 ret
= pm
->clocks_get(dev
, perflvl
);
229 if (pm
->voltage
.supported
&& pm
->voltage_get
) {
230 ret
= pm
->voltage_get(dev
);
232 perflvl
->volt_min
= ret
;
233 perflvl
->volt_max
= ret
;
237 ret
= nouveau_pwmfan_get(dev
);
239 perflvl
->fanspeed
= ret
;
245 nouveau_pm_perflvl_info(struct nouveau_pm_level
*perflvl
, char *ptr
, int len
)
247 char c
[16], s
[16], v
[32], f
[16], t
[16], m
[16];
251 snprintf(c
, sizeof(c
), " core %dMHz", perflvl
->core
/ 1000);
255 snprintf(s
, sizeof(s
), " shader %dMHz", perflvl
->shader
/ 1000);
259 snprintf(m
, sizeof(m
), " memory %dMHz", perflvl
->memory
/ 1000);
262 if (perflvl
->volt_min
&& perflvl
->volt_min
!= perflvl
->volt_max
) {
263 snprintf(v
, sizeof(v
), " voltage %dmV-%dmV",
264 perflvl
->volt_min
/ 1000, perflvl
->volt_max
/ 1000);
266 if (perflvl
->volt_min
) {
267 snprintf(v
, sizeof(v
), " voltage %dmV",
268 perflvl
->volt_min
/ 1000);
272 if (perflvl
->fanspeed
)
273 snprintf(f
, sizeof(f
), " fanspeed %d%%", perflvl
->fanspeed
);
277 snprintf(t
, sizeof(t
), " timing %d", perflvl
->timing
->id
);
279 snprintf(ptr
, len
, "%s%s%s%s%s%s\n", c
, s
, m
, t
, v
, f
);
283 nouveau_pm_get_perflvl_info(struct device
*d
,
284 struct device_attribute
*a
, char *buf
)
286 struct nouveau_pm_level
*perflvl
= (struct nouveau_pm_level
*)a
;
290 snprintf(ptr
, len
, "%d:", perflvl
->id
);
294 nouveau_pm_perflvl_info(perflvl
, ptr
, len
);
299 nouveau_pm_get_perflvl(struct device
*d
, struct device_attribute
*a
, char *buf
)
301 struct drm_device
*dev
= pci_get_drvdata(to_pci_dev(d
));
302 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
303 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
304 struct nouveau_pm_level cur
;
305 int len
= PAGE_SIZE
, ret
;
309 snprintf(ptr
, len
, "setting: boot\n");
310 else if (pm
->cur
== &pm
->boot
)
311 snprintf(ptr
, len
, "setting: boot\nc:");
313 snprintf(ptr
, len
, "setting: static %d\nc:", pm
->cur
->id
);
317 ret
= nouveau_pm_perflvl_get(dev
, &cur
);
319 nouveau_pm_perflvl_info(&cur
, ptr
, len
);
324 nouveau_pm_set_perflvl(struct device
*d
, struct device_attribute
*a
,
325 const char *buf
, size_t count
)
327 struct drm_device
*dev
= pci_get_drvdata(to_pci_dev(d
));
330 ret
= nouveau_pm_profile_set(dev
, buf
);
336 static DEVICE_ATTR(performance_level
, S_IRUGO
| S_IWUSR
,
337 nouveau_pm_get_perflvl
, nouveau_pm_set_perflvl
);
340 nouveau_sysfs_init(struct drm_device
*dev
)
342 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
343 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
344 struct device
*d
= &dev
->pdev
->dev
;
347 ret
= device_create_file(d
, &dev_attr_performance_level
);
351 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
352 struct nouveau_pm_level
*perflvl
= &pm
->perflvl
[i
];
354 perflvl
->dev_attr
.attr
.name
= perflvl
->name
;
355 perflvl
->dev_attr
.attr
.mode
= S_IRUGO
;
356 perflvl
->dev_attr
.show
= nouveau_pm_get_perflvl_info
;
357 perflvl
->dev_attr
.store
= NULL
;
358 sysfs_attr_init(&perflvl
->dev_attr
.attr
);
360 ret
= device_create_file(d
, &perflvl
->dev_attr
);
362 NV_ERROR(dev
, "failed pervlvl %d sysfs: %d\n",
364 perflvl
->dev_attr
.attr
.name
= NULL
;
365 nouveau_pm_fini(dev
);
374 nouveau_sysfs_fini(struct drm_device
*dev
)
376 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
377 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
378 struct device
*d
= &dev
->pdev
->dev
;
381 device_remove_file(d
, &dev_attr_performance_level
);
382 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
383 struct nouveau_pm_level
*pl
= &pm
->perflvl
[i
];
385 if (!pl
->dev_attr
.attr
.name
)
388 device_remove_file(d
, &pl
->dev_attr
);
392 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
394 nouveau_hwmon_show_temp(struct device
*d
, struct device_attribute
*a
, char *buf
)
396 struct drm_device
*dev
= dev_get_drvdata(d
);
397 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
398 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
400 return snprintf(buf
, PAGE_SIZE
, "%d\n", pm
->temp_get(dev
)*1000);
402 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, nouveau_hwmon_show_temp
,
406 nouveau_hwmon_max_temp(struct device
*d
, struct device_attribute
*a
, char *buf
)
408 struct drm_device
*dev
= dev_get_drvdata(d
);
409 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
410 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
411 struct nouveau_pm_threshold_temp
*temp
= &pm
->threshold_temp
;
413 return snprintf(buf
, PAGE_SIZE
, "%d\n", temp
->down_clock
*1000);
416 nouveau_hwmon_set_max_temp(struct device
*d
, struct device_attribute
*a
,
417 const char *buf
, size_t count
)
419 struct drm_device
*dev
= dev_get_drvdata(d
);
420 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
421 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
422 struct nouveau_pm_threshold_temp
*temp
= &pm
->threshold_temp
;
425 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
428 temp
->down_clock
= value
/1000;
430 nouveau_temp_safety_checks(dev
);
434 static SENSOR_DEVICE_ATTR(temp1_max
, S_IRUGO
| S_IWUSR
, nouveau_hwmon_max_temp
,
435 nouveau_hwmon_set_max_temp
,
439 nouveau_hwmon_critical_temp(struct device
*d
, struct device_attribute
*a
,
442 struct drm_device
*dev
= dev_get_drvdata(d
);
443 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
444 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
445 struct nouveau_pm_threshold_temp
*temp
= &pm
->threshold_temp
;
447 return snprintf(buf
, PAGE_SIZE
, "%d\n", temp
->critical
*1000);
450 nouveau_hwmon_set_critical_temp(struct device
*d
, struct device_attribute
*a
,
454 struct drm_device
*dev
= dev_get_drvdata(d
);
455 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
456 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
457 struct nouveau_pm_threshold_temp
*temp
= &pm
->threshold_temp
;
460 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
463 temp
->critical
= value
/1000;
465 nouveau_temp_safety_checks(dev
);
469 static SENSOR_DEVICE_ATTR(temp1_crit
, S_IRUGO
| S_IWUSR
,
470 nouveau_hwmon_critical_temp
,
471 nouveau_hwmon_set_critical_temp
,
474 static ssize_t
nouveau_hwmon_show_name(struct device
*dev
,
475 struct device_attribute
*attr
,
478 return sprintf(buf
, "nouveau\n");
480 static SENSOR_DEVICE_ATTR(name
, S_IRUGO
, nouveau_hwmon_show_name
, NULL
, 0);
482 static ssize_t
nouveau_hwmon_show_update_rate(struct device
*dev
,
483 struct device_attribute
*attr
,
486 return sprintf(buf
, "1000\n");
488 static SENSOR_DEVICE_ATTR(update_rate
, S_IRUGO
,
489 nouveau_hwmon_show_update_rate
,
493 nouveau_hwmon_show_fan0_input(struct device
*d
, struct device_attribute
*attr
,
496 struct drm_device
*dev
= dev_get_drvdata(d
);
497 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
498 struct nouveau_timer_engine
*ptimer
= &dev_priv
->engine
.timer
;
499 struct gpio_func gpio
;
500 u32 cycles
, cur
, prev
;
504 ret
= nouveau_gpio_find(dev
, 0, DCB_GPIO_FAN_SENSE
, 0xff, &gpio
);
508 /* Monitor the GPIO input 0x3b for 250ms.
509 * When the fan spins, it changes the value of GPIO FAN_SENSE.
510 * We get 4 changes (0 -> 1 -> 0 -> 1 -> [...]) per complete rotation.
512 start
= ptimer
->read(dev
);
513 prev
= nouveau_gpio_sense(dev
, 0, gpio
.line
);
516 cur
= nouveau_gpio_sense(dev
, 0, gpio
.line
);
522 usleep_range(500, 1000); /* supports 0 < rpm < 7500 */
523 } while (ptimer
->read(dev
) - start
< 250000000);
525 /* interpolate to get rpm */
526 return sprintf(buf
, "%i\n", cycles
/ 4 * 4 * 60);
528 static SENSOR_DEVICE_ATTR(fan0_input
, S_IRUGO
, nouveau_hwmon_show_fan0_input
,
532 nouveau_hwmon_get_pwm0(struct device
*d
, struct device_attribute
*a
, char *buf
)
534 struct drm_device
*dev
= dev_get_drvdata(d
);
537 ret
= nouveau_pwmfan_get(dev
);
541 return sprintf(buf
, "%i\n", ret
);
545 nouveau_hwmon_set_pwm0(struct device
*d
, struct device_attribute
*a
,
546 const char *buf
, size_t count
)
548 struct drm_device
*dev
= dev_get_drvdata(d
);
549 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
550 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
554 if (nouveau_perflvl_wr
!= 7777)
557 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
560 if (value
< pm
->fan
.min_duty
)
561 value
= pm
->fan
.min_duty
;
562 if (value
> pm
->fan
.max_duty
)
563 value
= pm
->fan
.max_duty
;
565 ret
= nouveau_pwmfan_set(dev
, value
);
572 static SENSOR_DEVICE_ATTR(pwm0
, S_IRUGO
| S_IWUSR
,
573 nouveau_hwmon_get_pwm0
,
574 nouveau_hwmon_set_pwm0
, 0);
577 nouveau_hwmon_get_pwm0_min(struct device
*d
,
578 struct device_attribute
*a
, char *buf
)
580 struct drm_device
*dev
= dev_get_drvdata(d
);
581 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
582 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
584 return sprintf(buf
, "%i\n", pm
->fan
.min_duty
);
588 nouveau_hwmon_set_pwm0_min(struct device
*d
, struct device_attribute
*a
,
589 const char *buf
, size_t count
)
591 struct drm_device
*dev
= dev_get_drvdata(d
);
592 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
593 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
596 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
602 if (pm
->fan
.max_duty
- value
< 10)
603 value
= pm
->fan
.max_duty
- 10;
606 pm
->fan
.min_duty
= 10;
608 pm
->fan
.min_duty
= value
;
613 static SENSOR_DEVICE_ATTR(pwm0_min
, S_IRUGO
| S_IWUSR
,
614 nouveau_hwmon_get_pwm0_min
,
615 nouveau_hwmon_set_pwm0_min
, 0);
618 nouveau_hwmon_get_pwm0_max(struct device
*d
,
619 struct device_attribute
*a
, char *buf
)
621 struct drm_device
*dev
= dev_get_drvdata(d
);
622 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
623 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
625 return sprintf(buf
, "%i\n", pm
->fan
.max_duty
);
629 nouveau_hwmon_set_pwm0_max(struct device
*d
, struct device_attribute
*a
,
630 const char *buf
, size_t count
)
632 struct drm_device
*dev
= dev_get_drvdata(d
);
633 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
634 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
637 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
643 if (value
- pm
->fan
.min_duty
< 10)
644 value
= pm
->fan
.min_duty
+ 10;
647 pm
->fan
.max_duty
= 100;
649 pm
->fan
.max_duty
= value
;
654 static SENSOR_DEVICE_ATTR(pwm0_max
, S_IRUGO
| S_IWUSR
,
655 nouveau_hwmon_get_pwm0_max
,
656 nouveau_hwmon_set_pwm0_max
, 0);
658 static struct attribute
*hwmon_attributes
[] = {
659 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
660 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
661 &sensor_dev_attr_temp1_crit
.dev_attr
.attr
,
662 &sensor_dev_attr_name
.dev_attr
.attr
,
663 &sensor_dev_attr_update_rate
.dev_attr
.attr
,
666 static struct attribute
*hwmon_fan_rpm_attributes
[] = {
667 &sensor_dev_attr_fan0_input
.dev_attr
.attr
,
670 static struct attribute
*hwmon_pwm_fan_attributes
[] = {
671 &sensor_dev_attr_pwm0
.dev_attr
.attr
,
672 &sensor_dev_attr_pwm0_min
.dev_attr
.attr
,
673 &sensor_dev_attr_pwm0_max
.dev_attr
.attr
,
677 static const struct attribute_group hwmon_attrgroup
= {
678 .attrs
= hwmon_attributes
,
680 static const struct attribute_group hwmon_fan_rpm_attrgroup
= {
681 .attrs
= hwmon_fan_rpm_attributes
,
683 static const struct attribute_group hwmon_pwm_fan_attrgroup
= {
684 .attrs
= hwmon_pwm_fan_attributes
,
689 nouveau_hwmon_init(struct drm_device
*dev
)
691 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
692 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
693 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
694 struct device
*hwmon_dev
;
700 hwmon_dev
= hwmon_device_register(&dev
->pdev
->dev
);
701 if (IS_ERR(hwmon_dev
)) {
702 ret
= PTR_ERR(hwmon_dev
);
704 "Unable to register hwmon device: %d\n", ret
);
707 dev_set_drvdata(hwmon_dev
, dev
);
709 /* default sysfs entries */
710 ret
= sysfs_create_group(&dev
->pdev
->dev
.kobj
, &hwmon_attrgroup
);
716 /* if the card has a pwm fan */
717 /*XXX: incorrect, need better detection for this, some boards have
718 * the gpio entries for pwm fan control even when there's no
719 * actual fan connected to it... therm table? */
720 if (nouveau_pwmfan_get(dev
) >= 0) {
721 ret
= sysfs_create_group(&dev
->pdev
->dev
.kobj
,
722 &hwmon_pwm_fan_attrgroup
);
727 /* if the card can read the fan rpm */
728 if (nouveau_gpio_func_valid(dev
, DCB_GPIO_FAN_SENSE
)) {
729 ret
= sysfs_create_group(&dev
->pdev
->dev
.kobj
,
730 &hwmon_fan_rpm_attrgroup
);
735 pm
->hwmon
= hwmon_dev
;
740 NV_ERROR(dev
, "Unable to create some hwmon sysfs files: %d\n", ret
);
741 hwmon_device_unregister(hwmon_dev
);
751 nouveau_hwmon_fini(struct drm_device
*dev
)
753 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
754 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
755 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
758 sysfs_remove_group(&dev
->pdev
->dev
.kobj
, &hwmon_attrgroup
);
759 sysfs_remove_group(&dev
->pdev
->dev
.kobj
,
760 &hwmon_pwm_fan_attrgroup
);
761 sysfs_remove_group(&dev
->pdev
->dev
.kobj
,
762 &hwmon_fan_rpm_attrgroup
);
764 hwmon_device_unregister(pm
->hwmon
);
769 #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
771 nouveau_pm_acpi_event(struct notifier_block
*nb
, unsigned long val
, void *data
)
773 struct drm_nouveau_private
*dev_priv
=
774 container_of(nb
, struct drm_nouveau_private
, engine
.pm
.acpi_nb
);
775 struct drm_device
*dev
= dev_priv
->dev
;
776 struct acpi_bus_event
*entry
= (struct acpi_bus_event
*)data
;
778 if (strcmp(entry
->device_class
, "ac_adapter") == 0) {
779 bool ac
= power_supply_is_system_supplied();
781 NV_DEBUG(dev
, "power supply changed: %s\n", ac
? "AC" : "DC");
789 nouveau_pm_init(struct drm_device
*dev
)
791 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
792 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
796 nouveau_mem_timing_init(dev
);
797 nouveau_volt_init(dev
);
798 nouveau_perf_init(dev
);
799 nouveau_temp_init(dev
);
801 NV_INFO(dev
, "%d available performance level(s)\n", pm
->nr_perflvl
);
802 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
803 nouveau_pm_perflvl_info(&pm
->perflvl
[i
], info
, sizeof(info
));
804 NV_INFO(dev
, "%d:%s", pm
->perflvl
[i
].id
, info
);
807 /* determine current ("boot") performance level */
808 ret
= nouveau_pm_perflvl_get(dev
, &pm
->boot
);
810 strncpy(pm
->boot
.name
, "boot", 4);
811 pm
->boot
.timing
= &pm
->memtimings
.boot
;
814 nouveau_pm_perflvl_info(&pm
->boot
, info
, sizeof(info
));
815 NV_INFO(dev
, "c:%s", info
);
818 /* switch performance levels now if requested */
819 if (nouveau_perflvl
!= NULL
) {
820 ret
= nouveau_pm_profile_set(dev
, nouveau_perflvl
);
822 NV_ERROR(dev
, "error setting perflvl \"%s\": %d\n",
823 nouveau_perflvl
, ret
);
827 /* determine the current fan speed */
828 pm
->fan
.percent
= nouveau_pwmfan_get(dev
);
830 nouveau_sysfs_init(dev
);
831 nouveau_hwmon_init(dev
);
832 #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
833 pm
->acpi_nb
.notifier_call
= nouveau_pm_acpi_event
;
834 register_acpi_notifier(&pm
->acpi_nb
);
841 nouveau_pm_fini(struct drm_device
*dev
)
843 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
844 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
846 if (pm
->cur
!= &pm
->boot
)
847 nouveau_pm_perflvl_set(dev
, &pm
->boot
);
849 nouveau_temp_fini(dev
);
850 nouveau_perf_fini(dev
);
851 nouveau_volt_fini(dev
);
852 nouveau_mem_timing_fini(dev
);
854 #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
855 unregister_acpi_notifier(&pm
->acpi_nb
);
857 nouveau_hwmon_fini(dev
);
858 nouveau_sysfs_fini(dev
);
862 nouveau_pm_resume(struct drm_device
*dev
)
864 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
865 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
866 struct nouveau_pm_level
*perflvl
;
868 if (!pm
->cur
|| pm
->cur
== &pm
->boot
)
873 nouveau_pm_perflvl_set(dev
, perflvl
);
874 nouveau_pwmfan_set(dev
, pm
->fan
.percent
);