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
);
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
->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 return pm
->pwm_set(dev
, gpio
.line
, divs
, duty
);
99 nouveau_pm_perflvl_aux(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
,
100 struct nouveau_pm_level
*a
, struct nouveau_pm_level
*b
)
102 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
103 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
106 /*XXX: not on all boards, we should control based on temperature
107 * on recent boards.. or maybe on some other factor we don't
110 if (a
->fanspeed
&& b
->fanspeed
&& b
->fanspeed
> a
->fanspeed
) {
111 ret
= nouveau_pwmfan_set(dev
, perflvl
->fanspeed
);
112 if (ret
&& ret
!= -ENODEV
) {
113 NV_ERROR(dev
, "fanspeed set failed: %d\n", ret
);
118 if (pm
->voltage
.supported
&& pm
->voltage_set
) {
119 if (perflvl
->volt_min
&& b
->volt_min
> a
->volt_min
) {
120 ret
= pm
->voltage_set(dev
, perflvl
->volt_min
);
122 NV_ERROR(dev
, "voltage set failed: %d\n", ret
);
132 nouveau_pm_perflvl_set(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
134 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
135 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
139 if (perflvl
== pm
->cur
)
142 ret
= nouveau_pm_perflvl_aux(dev
, perflvl
, pm
->cur
, perflvl
);
146 state
= pm
->clocks_pre(dev
, perflvl
);
148 return PTR_ERR(state
);
149 pm
->clocks_set(dev
, state
);
151 ret
= nouveau_pm_perflvl_aux(dev
, perflvl
, perflvl
, pm
->cur
);
160 nouveau_pm_profile_set(struct drm_device
*dev
, const char *profile
)
162 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
163 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
164 struct nouveau_pm_level
*perflvl
= NULL
;
167 /* safety precaution, for now */
168 if (nouveau_perflvl_wr
!= 7777)
171 if (!strncmp(profile
, "boot", 4))
175 if (kstrtol(profile
, 10, &pl
) == -EINVAL
)
178 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
179 if (pm
->perflvl
[i
].id
== pl
) {
180 perflvl
= &pm
->perflvl
[i
];
189 NV_INFO(dev
, "setting performance level: %s\n", profile
);
190 return nouveau_pm_perflvl_set(dev
, perflvl
);
194 nouveau_pm_perflvl_get(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
196 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
197 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
200 memset(perflvl
, 0, sizeof(*perflvl
));
202 ret
= pm
->clocks_get(dev
, perflvl
);
206 if (pm
->voltage
.supported
&& pm
->voltage_get
) {
207 ret
= pm
->voltage_get(dev
);
209 perflvl
->volt_min
= ret
;
210 perflvl
->volt_max
= ret
;
214 ret
= nouveau_pwmfan_get(dev
);
216 perflvl
->fanspeed
= ret
;
222 nouveau_pm_perflvl_info(struct nouveau_pm_level
*perflvl
, char *ptr
, int len
)
224 char c
[16], s
[16], v
[32], f
[16], t
[16], m
[16];
228 snprintf(c
, sizeof(c
), " core %dMHz", perflvl
->core
/ 1000);
232 snprintf(s
, sizeof(s
), " shader %dMHz", perflvl
->shader
/ 1000);
236 snprintf(m
, sizeof(m
), " memory %dMHz", perflvl
->memory
/ 1000);
239 if (perflvl
->volt_min
&& perflvl
->volt_min
!= perflvl
->volt_max
) {
240 snprintf(v
, sizeof(v
), " voltage %dmV-%dmV",
241 perflvl
->volt_min
/ 1000, perflvl
->volt_max
/ 1000);
243 if (perflvl
->volt_min
) {
244 snprintf(v
, sizeof(v
), " voltage %dmV",
245 perflvl
->volt_min
/ 1000);
249 if (perflvl
->fanspeed
)
250 snprintf(f
, sizeof(f
), " fanspeed %d%%", perflvl
->fanspeed
);
254 snprintf(t
, sizeof(t
), " timing %d", perflvl
->timing
->id
);
256 snprintf(ptr
, len
, "%s%s%s%s%s%s\n", c
, s
, m
, t
, v
, f
);
260 nouveau_pm_get_perflvl_info(struct device
*d
,
261 struct device_attribute
*a
, char *buf
)
263 struct nouveau_pm_level
*perflvl
= (struct nouveau_pm_level
*)a
;
267 snprintf(ptr
, len
, "%d:", perflvl
->id
);
271 nouveau_pm_perflvl_info(perflvl
, ptr
, len
);
276 nouveau_pm_get_perflvl(struct device
*d
, struct device_attribute
*a
, char *buf
)
278 struct drm_device
*dev
= pci_get_drvdata(to_pci_dev(d
));
279 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
280 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
281 struct nouveau_pm_level cur
;
282 int len
= PAGE_SIZE
, ret
;
286 snprintf(ptr
, len
, "setting: boot\n");
287 else if (pm
->cur
== &pm
->boot
)
288 snprintf(ptr
, len
, "setting: boot\nc:");
290 snprintf(ptr
, len
, "setting: static %d\nc:", pm
->cur
->id
);
294 ret
= nouveau_pm_perflvl_get(dev
, &cur
);
296 nouveau_pm_perflvl_info(&cur
, ptr
, len
);
301 nouveau_pm_set_perflvl(struct device
*d
, struct device_attribute
*a
,
302 const char *buf
, size_t count
)
304 struct drm_device
*dev
= pci_get_drvdata(to_pci_dev(d
));
307 ret
= nouveau_pm_profile_set(dev
, buf
);
313 static DEVICE_ATTR(performance_level
, S_IRUGO
| S_IWUSR
,
314 nouveau_pm_get_perflvl
, nouveau_pm_set_perflvl
);
317 nouveau_sysfs_init(struct drm_device
*dev
)
319 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
320 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
321 struct device
*d
= &dev
->pdev
->dev
;
324 ret
= device_create_file(d
, &dev_attr_performance_level
);
328 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
329 struct nouveau_pm_level
*perflvl
= &pm
->perflvl
[i
];
331 perflvl
->dev_attr
.attr
.name
= perflvl
->name
;
332 perflvl
->dev_attr
.attr
.mode
= S_IRUGO
;
333 perflvl
->dev_attr
.show
= nouveau_pm_get_perflvl_info
;
334 perflvl
->dev_attr
.store
= NULL
;
335 sysfs_attr_init(&perflvl
->dev_attr
.attr
);
337 ret
= device_create_file(d
, &perflvl
->dev_attr
);
339 NV_ERROR(dev
, "failed pervlvl %d sysfs: %d\n",
341 perflvl
->dev_attr
.attr
.name
= NULL
;
342 nouveau_pm_fini(dev
);
351 nouveau_sysfs_fini(struct drm_device
*dev
)
353 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
354 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
355 struct device
*d
= &dev
->pdev
->dev
;
358 device_remove_file(d
, &dev_attr_performance_level
);
359 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
360 struct nouveau_pm_level
*pl
= &pm
->perflvl
[i
];
362 if (!pl
->dev_attr
.attr
.name
)
365 device_remove_file(d
, &pl
->dev_attr
);
369 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
371 nouveau_hwmon_show_temp(struct device
*d
, struct device_attribute
*a
, char *buf
)
373 struct drm_device
*dev
= dev_get_drvdata(d
);
374 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
375 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
377 return snprintf(buf
, PAGE_SIZE
, "%d\n", pm
->temp_get(dev
)*1000);
379 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, nouveau_hwmon_show_temp
,
383 nouveau_hwmon_max_temp(struct device
*d
, struct device_attribute
*a
, char *buf
)
385 struct drm_device
*dev
= dev_get_drvdata(d
);
386 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
387 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
388 struct nouveau_pm_threshold_temp
*temp
= &pm
->threshold_temp
;
390 return snprintf(buf
, PAGE_SIZE
, "%d\n", temp
->down_clock
*1000);
393 nouveau_hwmon_set_max_temp(struct device
*d
, struct device_attribute
*a
,
394 const char *buf
, size_t count
)
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
;
399 struct nouveau_pm_threshold_temp
*temp
= &pm
->threshold_temp
;
402 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
405 temp
->down_clock
= value
/1000;
407 nouveau_temp_safety_checks(dev
);
411 static SENSOR_DEVICE_ATTR(temp1_max
, S_IRUGO
| S_IWUSR
, nouveau_hwmon_max_temp
,
412 nouveau_hwmon_set_max_temp
,
416 nouveau_hwmon_critical_temp(struct device
*d
, struct device_attribute
*a
,
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
;
424 return snprintf(buf
, PAGE_SIZE
, "%d\n", temp
->critical
*1000);
427 nouveau_hwmon_set_critical_temp(struct device
*d
, struct device_attribute
*a
,
431 struct drm_device
*dev
= dev_get_drvdata(d
);
432 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
433 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
434 struct nouveau_pm_threshold_temp
*temp
= &pm
->threshold_temp
;
437 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
440 temp
->critical
= value
/1000;
442 nouveau_temp_safety_checks(dev
);
446 static SENSOR_DEVICE_ATTR(temp1_crit
, S_IRUGO
| S_IWUSR
,
447 nouveau_hwmon_critical_temp
,
448 nouveau_hwmon_set_critical_temp
,
451 static ssize_t
nouveau_hwmon_show_name(struct device
*dev
,
452 struct device_attribute
*attr
,
455 return sprintf(buf
, "nouveau\n");
457 static SENSOR_DEVICE_ATTR(name
, S_IRUGO
, nouveau_hwmon_show_name
, NULL
, 0);
459 static ssize_t
nouveau_hwmon_show_update_rate(struct device
*dev
,
460 struct device_attribute
*attr
,
463 return sprintf(buf
, "1000\n");
465 static SENSOR_DEVICE_ATTR(update_rate
, S_IRUGO
,
466 nouveau_hwmon_show_update_rate
,
470 nouveau_hwmon_show_fan0_input(struct device
*d
, struct device_attribute
*attr
,
473 struct drm_device
*dev
= dev_get_drvdata(d
);
474 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
475 struct nouveau_timer_engine
*ptimer
= &dev_priv
->engine
.timer
;
476 struct gpio_func gpio
;
477 u32 cycles
, cur
, prev
;
481 ret
= nouveau_gpio_find(dev
, 0, DCB_GPIO_FAN_SENSE
, 0xff, &gpio
);
485 /* Monitor the GPIO input 0x3b for 250ms.
486 * When the fan spins, it changes the value of GPIO FAN_SENSE.
487 * We get 4 changes (0 -> 1 -> 0 -> 1 -> [...]) per complete rotation.
489 start
= ptimer
->read(dev
);
490 prev
= nouveau_gpio_sense(dev
, 0, gpio
.line
);
493 cur
= nouveau_gpio_sense(dev
, 0, gpio
.line
);
499 usleep_range(500, 1000); /* supports 0 < rpm < 7500 */
500 } while (ptimer
->read(dev
) - start
< 250000000);
502 /* interpolate to get rpm */
503 return sprintf(buf
, "%i\n", cycles
/ 4 * 4 * 60);
505 static SENSOR_DEVICE_ATTR(fan0_input
, S_IRUGO
, nouveau_hwmon_show_fan0_input
,
509 nouveau_hwmon_get_pwm0(struct device
*d
, struct device_attribute
*a
, char *buf
)
511 struct drm_device
*dev
= dev_get_drvdata(d
);
514 ret
= nouveau_pwmfan_get(dev
);
518 return sprintf(buf
, "%i\n", ret
);
522 nouveau_hwmon_set_pwm0(struct device
*d
, struct device_attribute
*a
,
523 const char *buf
, size_t count
)
525 struct drm_device
*dev
= dev_get_drvdata(d
);
526 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
527 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
531 if (nouveau_perflvl_wr
!= 7777)
534 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
537 if (value
< pm
->fan
.min_duty
)
538 value
= pm
->fan
.min_duty
;
539 if (value
> pm
->fan
.max_duty
)
540 value
= pm
->fan
.max_duty
;
542 ret
= nouveau_pwmfan_set(dev
, value
);
549 static SENSOR_DEVICE_ATTR(pwm0
, S_IRUGO
| S_IWUSR
,
550 nouveau_hwmon_get_pwm0
,
551 nouveau_hwmon_set_pwm0
, 0);
554 nouveau_hwmon_get_pwm0_min(struct device
*d
,
555 struct device_attribute
*a
, char *buf
)
557 struct drm_device
*dev
= dev_get_drvdata(d
);
558 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
559 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
561 return sprintf(buf
, "%i\n", pm
->fan
.min_duty
);
565 nouveau_hwmon_set_pwm0_min(struct device
*d
, struct device_attribute
*a
,
566 const char *buf
, size_t count
)
568 struct drm_device
*dev
= dev_get_drvdata(d
);
569 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
570 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
573 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
579 if (pm
->fan
.max_duty
- value
< 10)
580 value
= pm
->fan
.max_duty
- 10;
583 pm
->fan
.min_duty
= 10;
585 pm
->fan
.min_duty
= value
;
590 static SENSOR_DEVICE_ATTR(pwm0_min
, S_IRUGO
| S_IWUSR
,
591 nouveau_hwmon_get_pwm0_min
,
592 nouveau_hwmon_set_pwm0_min
, 0);
595 nouveau_hwmon_get_pwm0_max(struct device
*d
,
596 struct device_attribute
*a
, char *buf
)
598 struct drm_device
*dev
= dev_get_drvdata(d
);
599 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
600 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
602 return sprintf(buf
, "%i\n", pm
->fan
.max_duty
);
606 nouveau_hwmon_set_pwm0_max(struct device
*d
, struct device_attribute
*a
,
607 const char *buf
, size_t count
)
609 struct drm_device
*dev
= dev_get_drvdata(d
);
610 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
611 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
614 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
620 if (value
- pm
->fan
.min_duty
< 10)
621 value
= pm
->fan
.min_duty
+ 10;
624 pm
->fan
.max_duty
= 100;
626 pm
->fan
.max_duty
= value
;
631 static SENSOR_DEVICE_ATTR(pwm0_max
, S_IRUGO
| S_IWUSR
,
632 nouveau_hwmon_get_pwm0_max
,
633 nouveau_hwmon_set_pwm0_max
, 0);
635 static struct attribute
*hwmon_attributes
[] = {
636 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
637 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
638 &sensor_dev_attr_temp1_crit
.dev_attr
.attr
,
639 &sensor_dev_attr_name
.dev_attr
.attr
,
640 &sensor_dev_attr_update_rate
.dev_attr
.attr
,
643 static struct attribute
*hwmon_fan_rpm_attributes
[] = {
644 &sensor_dev_attr_fan0_input
.dev_attr
.attr
,
647 static struct attribute
*hwmon_pwm_fan_attributes
[] = {
648 &sensor_dev_attr_pwm0
.dev_attr
.attr
,
649 &sensor_dev_attr_pwm0_min
.dev_attr
.attr
,
650 &sensor_dev_attr_pwm0_max
.dev_attr
.attr
,
654 static const struct attribute_group hwmon_attrgroup
= {
655 .attrs
= hwmon_attributes
,
657 static const struct attribute_group hwmon_fan_rpm_attrgroup
= {
658 .attrs
= hwmon_fan_rpm_attributes
,
660 static const struct attribute_group hwmon_pwm_fan_attrgroup
= {
661 .attrs
= hwmon_pwm_fan_attributes
,
666 nouveau_hwmon_init(struct drm_device
*dev
)
668 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
669 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
670 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
671 struct device
*hwmon_dev
;
677 hwmon_dev
= hwmon_device_register(&dev
->pdev
->dev
);
678 if (IS_ERR(hwmon_dev
)) {
679 ret
= PTR_ERR(hwmon_dev
);
681 "Unable to register hwmon device: %d\n", ret
);
684 dev_set_drvdata(hwmon_dev
, dev
);
686 /* default sysfs entries */
687 ret
= sysfs_create_group(&dev
->pdev
->dev
.kobj
, &hwmon_attrgroup
);
693 /* if the card has a pwm fan */
694 /*XXX: incorrect, need better detection for this, some boards have
695 * the gpio entries for pwm fan control even when there's no
696 * actual fan connected to it... therm table? */
697 if (nouveau_pwmfan_get(dev
) >= 0) {
698 ret
= sysfs_create_group(&dev
->pdev
->dev
.kobj
,
699 &hwmon_pwm_fan_attrgroup
);
704 /* if the card can read the fan rpm */
705 if (nouveau_gpio_func_valid(dev
, DCB_GPIO_FAN_SENSE
)) {
706 ret
= sysfs_create_group(&dev
->pdev
->dev
.kobj
,
707 &hwmon_fan_rpm_attrgroup
);
712 pm
->hwmon
= hwmon_dev
;
717 NV_ERROR(dev
, "Unable to create some hwmon sysfs files: %d\n", ret
);
718 hwmon_device_unregister(hwmon_dev
);
728 nouveau_hwmon_fini(struct drm_device
*dev
)
730 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
731 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
732 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
735 sysfs_remove_group(&dev
->pdev
->dev
.kobj
, &hwmon_attrgroup
);
736 sysfs_remove_group(&dev
->pdev
->dev
.kobj
,
737 &hwmon_pwm_fan_attrgroup
);
738 sysfs_remove_group(&dev
->pdev
->dev
.kobj
,
739 &hwmon_fan_rpm_attrgroup
);
741 hwmon_device_unregister(pm
->hwmon
);
746 #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
748 nouveau_pm_acpi_event(struct notifier_block
*nb
, unsigned long val
, void *data
)
750 struct drm_nouveau_private
*dev_priv
=
751 container_of(nb
, struct drm_nouveau_private
, engine
.pm
.acpi_nb
);
752 struct drm_device
*dev
= dev_priv
->dev
;
753 struct acpi_bus_event
*entry
= (struct acpi_bus_event
*)data
;
755 if (strcmp(entry
->device_class
, "ac_adapter") == 0) {
756 bool ac
= power_supply_is_system_supplied();
758 NV_DEBUG(dev
, "power supply changed: %s\n", ac
? "AC" : "DC");
766 nouveau_pm_init(struct drm_device
*dev
)
768 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
769 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
773 nouveau_mem_timing_init(dev
);
774 nouveau_volt_init(dev
);
775 nouveau_perf_init(dev
);
776 nouveau_temp_init(dev
);
778 NV_INFO(dev
, "%d available performance level(s)\n", pm
->nr_perflvl
);
779 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
780 nouveau_pm_perflvl_info(&pm
->perflvl
[i
], info
, sizeof(info
));
781 NV_INFO(dev
, "%d:%s", pm
->perflvl
[i
].id
, info
);
784 /* determine current ("boot") performance level */
785 ret
= nouveau_pm_perflvl_get(dev
, &pm
->boot
);
787 strncpy(pm
->boot
.name
, "boot", 4);
790 nouveau_pm_perflvl_info(&pm
->boot
, info
, sizeof(info
));
791 NV_INFO(dev
, "c:%s", info
);
794 /* switch performance levels now if requested */
795 if (nouveau_perflvl
!= NULL
) {
796 ret
= nouveau_pm_profile_set(dev
, nouveau_perflvl
);
798 NV_ERROR(dev
, "error setting perflvl \"%s\": %d\n",
799 nouveau_perflvl
, ret
);
803 nouveau_sysfs_init(dev
);
804 nouveau_hwmon_init(dev
);
805 #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
806 pm
->acpi_nb
.notifier_call
= nouveau_pm_acpi_event
;
807 register_acpi_notifier(&pm
->acpi_nb
);
814 nouveau_pm_fini(struct drm_device
*dev
)
816 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
817 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
819 if (pm
->cur
!= &pm
->boot
)
820 nouveau_pm_perflvl_set(dev
, &pm
->boot
);
822 nouveau_temp_fini(dev
);
823 nouveau_perf_fini(dev
);
824 nouveau_volt_fini(dev
);
825 nouveau_mem_timing_fini(dev
);
827 #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
828 unregister_acpi_notifier(&pm
->acpi_nb
);
830 nouveau_hwmon_fini(dev
);
831 nouveau_sysfs_fini(dev
);
835 nouveau_pm_resume(struct drm_device
*dev
)
837 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
838 struct nouveau_pm_engine
*pm
= &dev_priv
->engine
.pm
;
839 struct nouveau_pm_level
*perflvl
;
841 if (!pm
->cur
|| pm
->cur
== &pm
->boot
)
846 nouveau_pm_perflvl_set(dev
, perflvl
);