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.
26 #include <linux/acpi.h>
28 #include <linux/power_supply.h>
29 #include <linux/hwmon.h>
30 #include <linux/hwmon-sysfs.h>
34 #include "nouveau_drm.h"
35 #include "nouveau_pm.h"
37 #include <subdev/gpio.h>
38 #include <subdev/timer.h>
39 #include <subdev/therm.h>
41 MODULE_PARM_DESC(perflvl
, "Performance level (default: boot)");
42 static char *nouveau_perflvl
;
43 module_param_named(perflvl
, nouveau_perflvl
, charp
, 0400);
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);
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
)
53 struct nouveau_drm
*drm
= nouveau_drm(dev
);
54 struct nouveau_pm
*pm
= nouveau_pm(dev
);
55 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
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
62 if (therm
&& therm
->fan_set
&&
63 a
->fanspeed
&& b
->fanspeed
&& b
->fanspeed
> a
->fanspeed
) {
64 ret
= therm
->fan_set(therm
, perflvl
->fanspeed
);
65 if (ret
&& ret
!= -ENODEV
) {
66 NV_ERROR(drm
, "fanspeed set failed: %d\n", ret
);
70 if (pm
->voltage
.supported
&& pm
->voltage_set
) {
71 if (perflvl
->volt_min
&& b
->volt_min
> a
->volt_min
) {
72 ret
= pm
->voltage_set(dev
, perflvl
->volt_min
);
74 NV_ERROR(drm
, "voltage set failed: %d\n", ret
);
84 nouveau_pm_perflvl_set(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
86 struct nouveau_pm
*pm
= nouveau_pm(dev
);
90 if (perflvl
== pm
->cur
)
93 ret
= nouveau_pm_perflvl_aux(dev
, perflvl
, pm
->cur
, perflvl
);
97 state
= pm
->clocks_pre(dev
, perflvl
);
102 ret
= pm
->clocks_set(dev
, state
);
106 ret
= nouveau_pm_perflvl_aux(dev
, perflvl
, perflvl
, pm
->cur
);
114 /* restore the fan speed and voltage before leaving */
115 nouveau_pm_perflvl_aux(dev
, perflvl
, perflvl
, pm
->cur
);
120 nouveau_pm_trigger(struct drm_device
*dev
)
122 struct nouveau_drm
*drm
= nouveau_drm(dev
);
123 struct nouveau_timer
*ptimer
= nouveau_timer(drm
->device
);
124 struct nouveau_pm
*pm
= nouveau_pm(dev
);
125 struct nouveau_pm_profile
*profile
= NULL
;
126 struct nouveau_pm_level
*perflvl
= NULL
;
129 /* select power profile based on current power source */
130 if (power_supply_is_system_supplied())
131 profile
= pm
->profile_ac
;
133 profile
= pm
->profile_dc
;
135 if (profile
!= pm
->profile
) {
136 pm
->profile
->func
->fini(pm
->profile
);
137 pm
->profile
= profile
;
138 pm
->profile
->func
->init(pm
->profile
);
141 /* select performance level based on profile */
142 perflvl
= profile
->func
->select(profile
);
144 /* change perflvl, if necessary */
145 if (perflvl
!= pm
->cur
) {
146 u64 time0
= ptimer
->read(ptimer
);
148 NV_INFO(drm
, "setting performance level: %d", perflvl
->id
);
149 ret
= nouveau_pm_perflvl_set(dev
, perflvl
);
151 NV_INFO(drm
, "> reclocking failed: %d\n\n", ret
);
153 NV_INFO(drm
, "> reclocking took %lluns\n\n",
154 ptimer
->read(ptimer
) - time0
);
158 static struct nouveau_pm_profile
*
159 profile_find(struct drm_device
*dev
, const char *string
)
161 struct nouveau_pm
*pm
= nouveau_pm(dev
);
162 struct nouveau_pm_profile
*profile
;
164 list_for_each_entry(profile
, &pm
->profiles
, head
) {
165 if (!strncmp(profile
->name
, string
, sizeof(profile
->name
)))
173 nouveau_pm_profile_set(struct drm_device
*dev
, const char *profile
)
175 struct nouveau_pm
*pm
= nouveau_pm(dev
);
176 struct nouveau_pm_profile
*ac
= NULL
, *dc
= NULL
;
177 char string
[16], *cur
= string
, *ptr
;
179 /* safety precaution, for now */
180 if (nouveau_perflvl_wr
!= 7777)
183 strncpy(string
, profile
, sizeof(string
));
184 string
[sizeof(string
) - 1] = 0;
185 if ((ptr
= strchr(string
, '\n')))
188 ptr
= strsep(&cur
, ",");
190 ac
= profile_find(dev
, ptr
);
192 ptr
= strsep(&cur
, ",");
194 dc
= profile_find(dev
, ptr
);
198 if (ac
== NULL
|| dc
== NULL
)
203 nouveau_pm_trigger(dev
);
208 nouveau_pm_static_dummy(struct nouveau_pm_profile
*profile
)
212 static struct nouveau_pm_level
*
213 nouveau_pm_static_select(struct nouveau_pm_profile
*profile
)
215 return container_of(profile
, struct nouveau_pm_level
, profile
);
218 const struct nouveau_pm_profile_func nouveau_pm_static_profile_func
= {
219 .destroy
= nouveau_pm_static_dummy
,
220 .init
= nouveau_pm_static_dummy
,
221 .fini
= nouveau_pm_static_dummy
,
222 .select
= nouveau_pm_static_select
,
226 nouveau_pm_perflvl_get(struct drm_device
*dev
, struct nouveau_pm_level
*perflvl
)
228 struct nouveau_drm
*drm
= nouveau_drm(dev
);
229 struct nouveau_pm
*pm
= nouveau_pm(dev
);
230 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
233 memset(perflvl
, 0, sizeof(*perflvl
));
235 if (pm
->clocks_get
) {
236 ret
= pm
->clocks_get(dev
, perflvl
);
241 if (pm
->voltage
.supported
&& pm
->voltage_get
) {
242 ret
= pm
->voltage_get(dev
);
244 perflvl
->volt_min
= ret
;
245 perflvl
->volt_max
= ret
;
249 if (therm
&& therm
->fan_get
) {
250 ret
= therm
->fan_get(therm
);
252 perflvl
->fanspeed
= ret
;
255 nouveau_mem_timing_read(dev
, &perflvl
->timing
);
260 nouveau_pm_perflvl_info(struct nouveau_pm_level
*perflvl
, char *ptr
, int len
)
262 char c
[16], s
[16], v
[32], f
[16], m
[16];
266 snprintf(c
, sizeof(c
), " core %dMHz", perflvl
->core
/ 1000);
270 snprintf(s
, sizeof(s
), " shader %dMHz", perflvl
->shader
/ 1000);
274 snprintf(m
, sizeof(m
), " memory %dMHz", perflvl
->memory
/ 1000);
277 if (perflvl
->volt_min
&& perflvl
->volt_min
!= perflvl
->volt_max
) {
278 snprintf(v
, sizeof(v
), " voltage %dmV-%dmV",
279 perflvl
->volt_min
/ 1000, perflvl
->volt_max
/ 1000);
281 if (perflvl
->volt_min
) {
282 snprintf(v
, sizeof(v
), " voltage %dmV",
283 perflvl
->volt_min
/ 1000);
287 if (perflvl
->fanspeed
)
288 snprintf(f
, sizeof(f
), " fanspeed %d%%", perflvl
->fanspeed
);
290 snprintf(ptr
, len
, "%s%s%s%s%s\n", c
, s
, m
, v
, f
);
294 nouveau_pm_get_perflvl_info(struct device
*d
,
295 struct device_attribute
*a
, char *buf
)
297 struct nouveau_pm_level
*perflvl
=
298 container_of(a
, struct nouveau_pm_level
, dev_attr
);
302 snprintf(ptr
, len
, "%d:", perflvl
->id
);
306 nouveau_pm_perflvl_info(perflvl
, ptr
, len
);
311 nouveau_pm_get_perflvl(struct device
*d
, struct device_attribute
*a
, char *buf
)
313 struct drm_device
*dev
= pci_get_drvdata(to_pci_dev(d
));
314 struct nouveau_pm
*pm
= nouveau_pm(dev
);
315 struct nouveau_pm_level cur
;
316 int len
= PAGE_SIZE
, ret
;
319 snprintf(ptr
, len
, "profile: %s, %s\nc:",
320 pm
->profile_ac
->name
, pm
->profile_dc
->name
);
324 ret
= nouveau_pm_perflvl_get(dev
, &cur
);
326 nouveau_pm_perflvl_info(&cur
, ptr
, len
);
331 nouveau_pm_set_perflvl(struct device
*d
, struct device_attribute
*a
,
332 const char *buf
, size_t count
)
334 struct drm_device
*dev
= pci_get_drvdata(to_pci_dev(d
));
337 ret
= nouveau_pm_profile_set(dev
, buf
);
343 static DEVICE_ATTR(performance_level
, S_IRUGO
| S_IWUSR
,
344 nouveau_pm_get_perflvl
, nouveau_pm_set_perflvl
);
347 nouveau_sysfs_init(struct drm_device
*dev
)
349 struct nouveau_drm
*drm
= nouveau_drm(dev
);
350 struct nouveau_pm
*pm
= nouveau_pm(dev
);
351 struct device
*d
= &dev
->pdev
->dev
;
354 ret
= device_create_file(d
, &dev_attr_performance_level
);
358 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
359 struct nouveau_pm_level
*perflvl
= &pm
->perflvl
[i
];
361 perflvl
->dev_attr
.attr
.name
= perflvl
->name
;
362 perflvl
->dev_attr
.attr
.mode
= S_IRUGO
;
363 perflvl
->dev_attr
.show
= nouveau_pm_get_perflvl_info
;
364 perflvl
->dev_attr
.store
= NULL
;
365 sysfs_attr_init(&perflvl
->dev_attr
.attr
);
367 ret
= device_create_file(d
, &perflvl
->dev_attr
);
369 NV_ERROR(drm
, "failed pervlvl %d sysfs: %d\n",
371 perflvl
->dev_attr
.attr
.name
= NULL
;
372 nouveau_pm_fini(dev
);
381 nouveau_sysfs_fini(struct drm_device
*dev
)
383 struct nouveau_pm
*pm
= nouveau_pm(dev
);
384 struct device
*d
= &dev
->pdev
->dev
;
387 device_remove_file(d
, &dev_attr_performance_level
);
388 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
389 struct nouveau_pm_level
*pl
= &pm
->perflvl
[i
];
391 if (!pl
->dev_attr
.attr
.name
)
394 device_remove_file(d
, &pl
->dev_attr
);
398 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
400 nouveau_hwmon_show_temp(struct device
*d
, struct device_attribute
*a
, char *buf
)
402 struct drm_device
*dev
= dev_get_drvdata(d
);
403 struct nouveau_drm
*drm
= nouveau_drm(dev
);
404 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
406 return snprintf(buf
, PAGE_SIZE
, "%d\n", therm
->temp_get(therm
) * 1000);
408 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, nouveau_hwmon_show_temp
,
412 nouveau_hwmon_max_temp(struct device
*d
, struct device_attribute
*a
, char *buf
)
414 struct drm_device
*dev
= dev_get_drvdata(d
);
415 struct nouveau_drm
*drm
= nouveau_drm(dev
);
416 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
418 return snprintf(buf
, PAGE_SIZE
, "%d\n",
419 therm
->attr_get(therm
, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK
) * 1000);
422 nouveau_hwmon_set_max_temp(struct device
*d
, struct device_attribute
*a
,
423 const char *buf
, size_t count
)
425 struct drm_device
*dev
= dev_get_drvdata(d
);
426 struct nouveau_drm
*drm
= nouveau_drm(dev
);
427 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
430 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
433 therm
->attr_set(therm
, NOUVEAU_THERM_ATTR_THRS_DOWN_CLK
, value
/ 1000);
437 static SENSOR_DEVICE_ATTR(temp1_max
, S_IRUGO
| S_IWUSR
, nouveau_hwmon_max_temp
,
438 nouveau_hwmon_set_max_temp
,
442 nouveau_hwmon_critical_temp(struct device
*d
, struct device_attribute
*a
,
445 struct drm_device
*dev
= dev_get_drvdata(d
);
446 struct nouveau_drm
*drm
= nouveau_drm(dev
);
447 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
449 return snprintf(buf
, PAGE_SIZE
, "%d\n",
450 therm
->attr_get(therm
, NOUVEAU_THERM_ATTR_THRS_CRITICAL
) * 1000);
453 nouveau_hwmon_set_critical_temp(struct device
*d
, struct device_attribute
*a
,
457 struct drm_device
*dev
= dev_get_drvdata(d
);
458 struct nouveau_drm
*drm
= nouveau_drm(dev
);
459 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
462 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
465 therm
->attr_set(therm
, NOUVEAU_THERM_ATTR_THRS_CRITICAL
, value
/ 1000);
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 nouveau_drm
*drm
= nouveau_drm(dev
);
498 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
500 return snprintf(buf
, PAGE_SIZE
, "%d\n", therm
->fan_sense(therm
));
502 static SENSOR_DEVICE_ATTR(fan0_input
, S_IRUGO
, nouveau_hwmon_show_fan0_input
,
506 nouveau_hwmon_get_pwm1_enable(struct device
*d
,
507 struct device_attribute
*a
, char *buf
)
509 struct drm_device
*dev
= dev_get_drvdata(d
);
510 struct nouveau_drm
*drm
= nouveau_drm(dev
);
511 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
514 ret
= therm
->attr_get(therm
, NOUVEAU_THERM_ATTR_FAN_MODE
);
518 return sprintf(buf
, "%i\n", ret
);
522 nouveau_hwmon_set_pwm1_enable(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 nouveau_drm
*drm
= nouveau_drm(dev
);
527 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
531 if (strict_strtol(buf
, 10, &value
) == -EINVAL
)
534 ret
= therm
->attr_set(therm
, NOUVEAU_THERM_ATTR_FAN_MODE
, value
);
540 static SENSOR_DEVICE_ATTR(pwm1_enable
, S_IRUGO
| S_IWUSR
,
541 nouveau_hwmon_get_pwm1_enable
,
542 nouveau_hwmon_set_pwm1_enable
, 0);
545 nouveau_hwmon_get_pwm1(struct device
*d
, struct device_attribute
*a
, char *buf
)
547 struct drm_device
*dev
= dev_get_drvdata(d
);
548 struct nouveau_drm
*drm
= nouveau_drm(dev
);
549 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
552 ret
= therm
->fan_get(therm
);
556 return sprintf(buf
, "%i\n", ret
);
560 nouveau_hwmon_set_pwm1(struct device
*d
, struct device_attribute
*a
,
561 const char *buf
, size_t count
)
563 struct drm_device
*dev
= dev_get_drvdata(d
);
564 struct nouveau_drm
*drm
= nouveau_drm(dev
);
565 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
569 if (nouveau_perflvl_wr
!= 7777)
572 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
575 ret
= therm
->fan_set(therm
, value
);
582 static SENSOR_DEVICE_ATTR(pwm1
, S_IRUGO
| S_IWUSR
,
583 nouveau_hwmon_get_pwm1
,
584 nouveau_hwmon_set_pwm1
, 0);
587 nouveau_hwmon_get_pwm1_min(struct device
*d
,
588 struct device_attribute
*a
, char *buf
)
590 struct drm_device
*dev
= dev_get_drvdata(d
);
591 struct nouveau_drm
*drm
= nouveau_drm(dev
);
592 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
595 ret
= therm
->attr_get(therm
, NOUVEAU_THERM_ATTR_FAN_MIN_DUTY
);
599 return sprintf(buf
, "%i\n", ret
);
603 nouveau_hwmon_set_pwm1_min(struct device
*d
, struct device_attribute
*a
,
604 const char *buf
, size_t count
)
606 struct drm_device
*dev
= dev_get_drvdata(d
);
607 struct nouveau_drm
*drm
= nouveau_drm(dev
);
608 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
612 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
615 ret
= therm
->attr_set(therm
, NOUVEAU_THERM_ATTR_FAN_MIN_DUTY
, value
);
622 static SENSOR_DEVICE_ATTR(pwm1_min
, S_IRUGO
| S_IWUSR
,
623 nouveau_hwmon_get_pwm1_min
,
624 nouveau_hwmon_set_pwm1_min
, 0);
627 nouveau_hwmon_get_pwm1_max(struct device
*d
,
628 struct device_attribute
*a
, char *buf
)
630 struct drm_device
*dev
= dev_get_drvdata(d
);
631 struct nouveau_drm
*drm
= nouveau_drm(dev
);
632 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
635 ret
= therm
->attr_get(therm
, NOUVEAU_THERM_ATTR_FAN_MAX_DUTY
);
639 return sprintf(buf
, "%i\n", ret
);
643 nouveau_hwmon_set_pwm1_max(struct device
*d
, struct device_attribute
*a
,
644 const char *buf
, size_t count
)
646 struct drm_device
*dev
= dev_get_drvdata(d
);
647 struct nouveau_drm
*drm
= nouveau_drm(dev
);
648 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
652 if (kstrtol(buf
, 10, &value
) == -EINVAL
)
655 ret
= therm
->attr_set(therm
, NOUVEAU_THERM_ATTR_FAN_MAX_DUTY
, value
);
662 static SENSOR_DEVICE_ATTR(pwm1_max
, S_IRUGO
| S_IWUSR
,
663 nouveau_hwmon_get_pwm1_max
,
664 nouveau_hwmon_set_pwm1_max
, 0);
666 static struct attribute
*hwmon_attributes
[] = {
667 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
668 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
669 &sensor_dev_attr_temp1_crit
.dev_attr
.attr
,
670 &sensor_dev_attr_name
.dev_attr
.attr
,
671 &sensor_dev_attr_update_rate
.dev_attr
.attr
,
674 static struct attribute
*hwmon_fan_rpm_attributes
[] = {
675 &sensor_dev_attr_fan0_input
.dev_attr
.attr
,
678 static struct attribute
*hwmon_pwm_fan_attributes
[] = {
679 &sensor_dev_attr_pwm1_enable
.dev_attr
.attr
,
680 &sensor_dev_attr_pwm1
.dev_attr
.attr
,
681 &sensor_dev_attr_pwm1_min
.dev_attr
.attr
,
682 &sensor_dev_attr_pwm1_max
.dev_attr
.attr
,
686 static const struct attribute_group hwmon_attrgroup
= {
687 .attrs
= hwmon_attributes
,
689 static const struct attribute_group hwmon_fan_rpm_attrgroup
= {
690 .attrs
= hwmon_fan_rpm_attributes
,
692 static const struct attribute_group hwmon_pwm_fan_attrgroup
= {
693 .attrs
= hwmon_pwm_fan_attributes
,
698 nouveau_hwmon_init(struct drm_device
*dev
)
700 struct nouveau_pm
*pm
= nouveau_pm(dev
);
701 struct nouveau_drm
*drm
= nouveau_drm(dev
);
702 struct nouveau_therm
*therm
= nouveau_therm(drm
->device
);
704 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
705 struct device
*hwmon_dev
;
708 if (!therm
|| !therm
->temp_get
|| !therm
->attr_get
|| !therm
->attr_set
)
711 hwmon_dev
= hwmon_device_register(&dev
->pdev
->dev
);
712 if (IS_ERR(hwmon_dev
)) {
713 ret
= PTR_ERR(hwmon_dev
);
714 NV_ERROR(drm
, "Unable to register hwmon device: %d\n", ret
);
717 dev_set_drvdata(hwmon_dev
, dev
);
719 /* default sysfs entries */
720 ret
= sysfs_create_group(&dev
->pdev
->dev
.kobj
, &hwmon_attrgroup
);
726 /* if the card has a pwm fan */
727 /*XXX: incorrect, need better detection for this, some boards have
728 * the gpio entries for pwm fan control even when there's no
729 * actual fan connected to it... therm table? */
730 if (therm
->fan_get
&& therm
->fan_get(therm
) >= 0) {
731 ret
= sysfs_create_group(&dev
->pdev
->dev
.kobj
,
732 &hwmon_pwm_fan_attrgroup
);
737 /* if the card can read the fan rpm */
738 if (therm
->fan_sense(therm
) >= 0) {
739 ret
= sysfs_create_group(&dev
->pdev
->dev
.kobj
,
740 &hwmon_fan_rpm_attrgroup
);
745 pm
->hwmon
= hwmon_dev
;
750 NV_ERROR(drm
, "Unable to create some hwmon sysfs files: %d\n", ret
);
751 hwmon_device_unregister(hwmon_dev
);
761 nouveau_hwmon_fini(struct drm_device
*dev
)
763 #if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE))
764 struct nouveau_pm
*pm
= nouveau_pm(dev
);
767 sysfs_remove_group(&dev
->pdev
->dev
.kobj
, &hwmon_attrgroup
);
768 sysfs_remove_group(&dev
->pdev
->dev
.kobj
,
769 &hwmon_pwm_fan_attrgroup
);
770 sysfs_remove_group(&dev
->pdev
->dev
.kobj
,
771 &hwmon_fan_rpm_attrgroup
);
773 hwmon_device_unregister(pm
->hwmon
);
778 #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
780 nouveau_pm_acpi_event(struct notifier_block
*nb
, unsigned long val
, void *data
)
782 struct nouveau_pm
*pm
= container_of(nb
, struct nouveau_pm
, acpi_nb
);
783 struct nouveau_drm
*drm
= nouveau_drm(pm
->dev
);
784 struct acpi_bus_event
*entry
= (struct acpi_bus_event
*)data
;
786 if (strcmp(entry
->device_class
, "ac_adapter") == 0) {
787 bool ac
= power_supply_is_system_supplied();
789 NV_DEBUG(drm
, "power supply changed: %s\n", ac
? "AC" : "DC");
790 nouveau_pm_trigger(pm
->dev
);
798 nouveau_pm_init(struct drm_device
*dev
)
800 struct nouveau_device
*device
= nouveau_dev(dev
);
801 struct nouveau_drm
*drm
= nouveau_drm(dev
);
802 struct nouveau_pm
*pm
;
806 pm
= drm
->pm
= kzalloc(sizeof(*pm
), GFP_KERNEL
);
812 if (device
->card_type
< NV_40
) {
813 pm
->clocks_get
= nv04_pm_clocks_get
;
814 pm
->clocks_pre
= nv04_pm_clocks_pre
;
815 pm
->clocks_set
= nv04_pm_clocks_set
;
816 if (nouveau_gpio(drm
->device
)) {
817 pm
->voltage_get
= nouveau_voltage_gpio_get
;
818 pm
->voltage_set
= nouveau_voltage_gpio_set
;
821 if (device
->card_type
< NV_50
) {
822 pm
->clocks_get
= nv40_pm_clocks_get
;
823 pm
->clocks_pre
= nv40_pm_clocks_pre
;
824 pm
->clocks_set
= nv40_pm_clocks_set
;
825 pm
->voltage_get
= nouveau_voltage_gpio_get
;
826 pm
->voltage_set
= nouveau_voltage_gpio_set
;
828 if (device
->card_type
< NV_C0
) {
829 if (device
->chipset
< 0xa3 ||
830 device
->chipset
== 0xaa ||
831 device
->chipset
== 0xac) {
832 pm
->clocks_get
= nv50_pm_clocks_get
;
833 pm
->clocks_pre
= nv50_pm_clocks_pre
;
834 pm
->clocks_set
= nv50_pm_clocks_set
;
836 pm
->clocks_get
= nva3_pm_clocks_get
;
837 pm
->clocks_pre
= nva3_pm_clocks_pre
;
838 pm
->clocks_set
= nva3_pm_clocks_set
;
840 pm
->voltage_get
= nouveau_voltage_gpio_get
;
841 pm
->voltage_set
= nouveau_voltage_gpio_set
;
843 if (device
->card_type
< NV_E0
) {
844 pm
->clocks_get
= nvc0_pm_clocks_get
;
845 pm
->clocks_pre
= nvc0_pm_clocks_pre
;
846 pm
->clocks_set
= nvc0_pm_clocks_set
;
847 pm
->voltage_get
= nouveau_voltage_gpio_get
;
848 pm
->voltage_set
= nouveau_voltage_gpio_set
;
852 /* parse aux tables from vbios */
853 nouveau_volt_init(dev
);
855 INIT_LIST_HEAD(&pm
->profiles
);
857 /* determine current ("boot") performance level */
858 ret
= nouveau_pm_perflvl_get(dev
, &pm
->boot
);
860 NV_ERROR(drm
, "failed to determine boot perflvl\n");
864 strncpy(pm
->boot
.name
, "boot", 4);
865 strncpy(pm
->boot
.profile
.name
, "boot", 4);
866 pm
->boot
.profile
.func
= &nouveau_pm_static_profile_func
;
868 list_add(&pm
->boot
.profile
.head
, &pm
->profiles
);
870 pm
->profile_ac
= &pm
->boot
.profile
;
871 pm
->profile_dc
= &pm
->boot
.profile
;
872 pm
->profile
= &pm
->boot
.profile
;
875 /* add performance levels from vbios */
876 nouveau_perf_init(dev
);
878 /* display available performance levels */
879 NV_INFO(drm
, "%d available performance level(s)\n", pm
->nr_perflvl
);
880 for (i
= 0; i
< pm
->nr_perflvl
; i
++) {
881 nouveau_pm_perflvl_info(&pm
->perflvl
[i
], info
, sizeof(info
));
882 NV_INFO(drm
, "%d:%s", pm
->perflvl
[i
].id
, info
);
885 nouveau_pm_perflvl_info(&pm
->boot
, info
, sizeof(info
));
886 NV_INFO(drm
, "c:%s", info
);
888 /* switch performance levels now if requested */
889 if (nouveau_perflvl
!= NULL
)
890 nouveau_pm_profile_set(dev
, nouveau_perflvl
);
892 nouveau_sysfs_init(dev
);
893 nouveau_hwmon_init(dev
);
894 #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
895 pm
->acpi_nb
.notifier_call
= nouveau_pm_acpi_event
;
896 register_acpi_notifier(&pm
->acpi_nb
);
903 nouveau_pm_fini(struct drm_device
*dev
)
905 struct nouveau_pm
*pm
= nouveau_pm(dev
);
906 struct nouveau_pm_profile
*profile
, *tmp
;
908 list_for_each_entry_safe(profile
, tmp
, &pm
->profiles
, head
) {
909 list_del(&profile
->head
);
910 profile
->func
->destroy(profile
);
913 if (pm
->cur
!= &pm
->boot
)
914 nouveau_pm_perflvl_set(dev
, &pm
->boot
);
916 nouveau_perf_fini(dev
);
917 nouveau_volt_fini(dev
);
919 #if defined(CONFIG_ACPI) && defined(CONFIG_POWER_SUPPLY)
920 unregister_acpi_notifier(&pm
->acpi_nb
);
922 nouveau_hwmon_fini(dev
);
923 nouveau_sysfs_fini(dev
);
925 nouveau_drm(dev
)->pm
= NULL
;
930 nouveau_pm_resume(struct drm_device
*dev
)
932 struct nouveau_pm
*pm
= nouveau_pm(dev
);
933 struct nouveau_pm_level
*perflvl
;
935 if (!pm
->cur
|| pm
->cur
== &pm
->boot
)
940 nouveau_pm_perflvl_set(dev
, perflvl
);