diff options
author | Martin Peres <martin.peres@ensi-bourges.fr> | 2011-08-14 21:10:30 -0400 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2011-12-21 04:01:11 -0500 |
commit | 11b7d895216f7f954c6cfa0c23b76dccb7a890c1 (patch) | |
tree | efc9af29ec90e3159bef8f99d88d5bc31c51903c /drivers/gpu/drm/nouveau | |
parent | cb9fa62671ace5ac40b9924e9014cebf04b78228 (diff) |
drm/nouveau/pm: manual pwm fanspeed management for nv40+ boards
Exposes the following sysfs entries:
- fan0_input: read the rotational speed of the fan (poll a bit during 250ms)
- pwm0: set the pwm duty cycle
- pwm0_min/max: set the minimum/maximum pwm value
v2 (Ben Skeggs):
- nv50 pwm controller code removed in favour of other more complete code
- FAN_RPM -> FAN_SENSE
- merged FAN_SENSE readout into common code, not at all nv50-specific
- protected fanspeed changes with perflvl_wr
- formatting tidying
- added some comments where things are shaky
v3 (Martin Peres)
- ensure duty min/max from thermal table are sane
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Signed-off-by: Martin Peres <martin.peres@ensi-bourges.fr>
Diffstat (limited to 'drivers/gpu/drm/nouveau')
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_bios.h | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_drv.h | 6 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_pm.c | 234 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_temp.c | 16 |
4 files changed, 252 insertions, 6 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.h b/drivers/gpu/drm/nouveau/nouveau_bios.h index 8adb69e4a6b1..3f36c7074d4f 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bios.h +++ b/drivers/gpu/drm/nouveau/nouveau_bios.h | |||
@@ -58,6 +58,8 @@ struct dcb_i2c_entry { | |||
58 | enum dcb_gpio_tag { | 58 | enum dcb_gpio_tag { |
59 | DCB_GPIO_TVDAC0 = 0xc, | 59 | DCB_GPIO_TVDAC0 = 0xc, |
60 | DCB_GPIO_TVDAC1 = 0x2d, | 60 | DCB_GPIO_TVDAC1 = 0x2d, |
61 | DCB_GPIO_PWM_FAN = 0x9, | ||
62 | DCB_GPIO_FAN_SENSE = 0x3d, | ||
61 | }; | 63 | }; |
62 | 64 | ||
63 | struct dcb_gpio_entry { | 65 | struct dcb_gpio_entry { |
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index 2c8ebf6248a0..432be658060d 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h | |||
@@ -521,6 +521,11 @@ struct nouveau_pm_memtimings { | |||
521 | int nr_timing; | 521 | int nr_timing; |
522 | }; | 522 | }; |
523 | 523 | ||
524 | struct nouveau_pm_fan { | ||
525 | u32 min_duty; | ||
526 | u32 max_duty; | ||
527 | }; | ||
528 | |||
524 | struct nouveau_pm_engine { | 529 | struct nouveau_pm_engine { |
525 | struct nouveau_pm_voltage voltage; | 530 | struct nouveau_pm_voltage voltage; |
526 | struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL]; | 531 | struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL]; |
@@ -528,6 +533,7 @@ struct nouveau_pm_engine { | |||
528 | struct nouveau_pm_memtimings memtimings; | 533 | struct nouveau_pm_memtimings memtimings; |
529 | struct nouveau_pm_temp_sensor_constants sensor_constants; | 534 | struct nouveau_pm_temp_sensor_constants sensor_constants; |
530 | struct nouveau_pm_threshold_temp threshold_temp; | 535 | struct nouveau_pm_threshold_temp threshold_temp; |
536 | struct nouveau_pm_fan fan; | ||
531 | u32 pwm_divisor; | 537 | u32 pwm_divisor; |
532 | 538 | ||
533 | struct nouveau_pm_level boot; | 539 | struct nouveau_pm_level boot; |
diff --git a/drivers/gpu/drm/nouveau/nouveau_pm.c b/drivers/gpu/drm/nouveau/nouveau_pm.c index ee2872ed60ee..23b297fd6f61 100644 --- a/drivers/gpu/drm/nouveau/nouveau_pm.c +++ b/drivers/gpu/drm/nouveau/nouveau_pm.c | |||
@@ -64,6 +64,10 @@ nouveau_pm_perflvl_set(struct drm_device *dev, struct nouveau_pm_level *perflvl) | |||
64 | if (perflvl == pm->cur) | 64 | if (perflvl == pm->cur) |
65 | return 0; | 65 | return 0; |
66 | 66 | ||
67 | /*XXX: not on all boards, we should control based on temperature | ||
68 | * on recent boards.. or maybe on some other factor we don't | ||
69 | * know about? | ||
70 | */ | ||
67 | if (pm->fanspeed_set && perflvl->fanspeed) { | 71 | if (pm->fanspeed_set && perflvl->fanspeed) { |
68 | ret = pm->fanspeed_set(dev, perflvl->fanspeed); | 72 | ret = pm->fanspeed_set(dev, perflvl->fanspeed); |
69 | if (ret) | 73 | if (ret) |
@@ -424,6 +428,176 @@ static SENSOR_DEVICE_ATTR(update_rate, S_IRUGO, | |||
424 | nouveau_hwmon_show_update_rate, | 428 | nouveau_hwmon_show_update_rate, |
425 | NULL, 0); | 429 | NULL, 0); |
426 | 430 | ||
431 | static ssize_t | ||
432 | nouveau_hwmon_show_fan0_input(struct device *d, struct device_attribute *attr, | ||
433 | char *buf) | ||
434 | { | ||
435 | struct drm_device *dev = dev_get_drvdata(d); | ||
436 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
437 | struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer; | ||
438 | struct nouveau_gpio_engine *pgpio = &dev_priv->engine.gpio; | ||
439 | struct dcb_gpio_entry *gpio; | ||
440 | u32 cycles, cur, prev; | ||
441 | u64 start; | ||
442 | |||
443 | gpio = nouveau_bios_gpio_entry(dev, DCB_GPIO_FAN_SENSE); | ||
444 | if (!gpio) | ||
445 | return -ENODEV; | ||
446 | |||
447 | /* Monitor the GPIO input 0x3b for 250ms. | ||
448 | * When the fan spins, it changes the value of GPIO FAN_SENSE. | ||
449 | * We get 4 changes (0 -> 1 -> 0 -> 1 -> [...]) per complete rotation. | ||
450 | */ | ||
451 | start = ptimer->read(dev); | ||
452 | prev = pgpio->get(dev, DCB_GPIO_FAN_SENSE); | ||
453 | cycles = 0; | ||
454 | do { | ||
455 | cur = pgpio->get(dev, DCB_GPIO_FAN_SENSE); | ||
456 | if (prev != cur) { | ||
457 | cycles++; | ||
458 | prev = cur; | ||
459 | } | ||
460 | |||
461 | usleep_range(500, 1000); /* supports 0 < rpm < 7500 */ | ||
462 | } while (ptimer->read(dev) - start < 250000000); | ||
463 | |||
464 | /* interpolate to get rpm */ | ||
465 | return sprintf(buf, "%i\n", cycles / 4 * 4 * 60); | ||
466 | } | ||
467 | static SENSOR_DEVICE_ATTR(fan0_input, S_IRUGO, nouveau_hwmon_show_fan0_input, | ||
468 | NULL, 0); | ||
469 | |||
470 | static ssize_t | ||
471 | nouveau_hwmon_get_pwm0(struct device *d, struct device_attribute *a, char *buf) | ||
472 | { | ||
473 | struct drm_device *dev = dev_get_drvdata(d); | ||
474 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
475 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
476 | int ret = -ENODEV; | ||
477 | |||
478 | if (pm->fanspeed_get) | ||
479 | ret = pm->fanspeed_get(dev); | ||
480 | if (ret < 0) | ||
481 | return ret; | ||
482 | |||
483 | return sprintf(buf, "%i\n", ret); | ||
484 | } | ||
485 | |||
486 | static ssize_t | ||
487 | nouveau_hwmon_set_pwm0(struct device *d, struct device_attribute *a, | ||
488 | const char *buf, size_t count) | ||
489 | { | ||
490 | struct drm_device *dev = dev_get_drvdata(d); | ||
491 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
492 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
493 | int ret = -ENODEV; | ||
494 | long value; | ||
495 | |||
496 | if (nouveau_perflvl_wr != 7777) | ||
497 | return -EPERM; | ||
498 | |||
499 | if (strict_strtol(buf, 10, &value) == -EINVAL) | ||
500 | return -EINVAL; | ||
501 | |||
502 | if (value < pm->fan.min_duty) | ||
503 | value = pm->fan.min_duty; | ||
504 | if (value > pm->fan.max_duty) | ||
505 | value = pm->fan.max_duty; | ||
506 | |||
507 | if (pm->fanspeed_set) | ||
508 | ret = pm->fanspeed_set(dev, value); | ||
509 | if (ret) | ||
510 | return ret; | ||
511 | |||
512 | return count; | ||
513 | } | ||
514 | |||
515 | static SENSOR_DEVICE_ATTR(pwm0, S_IRUGO | S_IWUSR, | ||
516 | nouveau_hwmon_get_pwm0, | ||
517 | nouveau_hwmon_set_pwm0, 0); | ||
518 | |||
519 | static ssize_t | ||
520 | nouveau_hwmon_get_pwm0_min(struct device *d, | ||
521 | struct device_attribute *a, char *buf) | ||
522 | { | ||
523 | struct drm_device *dev = dev_get_drvdata(d); | ||
524 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
525 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
526 | |||
527 | return sprintf(buf, "%i\n", pm->fan.min_duty); | ||
528 | } | ||
529 | |||
530 | static ssize_t | ||
531 | nouveau_hwmon_set_pwm0_min(struct device *d, struct device_attribute *a, | ||
532 | const char *buf, size_t count) | ||
533 | { | ||
534 | struct drm_device *dev = dev_get_drvdata(d); | ||
535 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
536 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
537 | long value; | ||
538 | |||
539 | if (strict_strtol(buf, 10, &value) == -EINVAL) | ||
540 | return -EINVAL; | ||
541 | |||
542 | if (value < 0) | ||
543 | value = 0; | ||
544 | |||
545 | if (pm->fan.max_duty - value < 10) | ||
546 | value = pm->fan.max_duty - 10; | ||
547 | |||
548 | if (value < 10) | ||
549 | pm->fan.min_duty = 10; | ||
550 | else | ||
551 | pm->fan.min_duty = value; | ||
552 | |||
553 | return count; | ||
554 | } | ||
555 | |||
556 | static SENSOR_DEVICE_ATTR(pwm0_min, S_IRUGO | S_IWUSR, | ||
557 | nouveau_hwmon_get_pwm0_min, | ||
558 | nouveau_hwmon_set_pwm0_min, 0); | ||
559 | |||
560 | static ssize_t | ||
561 | nouveau_hwmon_get_pwm0_max(struct device *d, | ||
562 | struct device_attribute *a, char *buf) | ||
563 | { | ||
564 | struct drm_device *dev = dev_get_drvdata(d); | ||
565 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
566 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
567 | |||
568 | return sprintf(buf, "%i\n", pm->fan.max_duty); | ||
569 | } | ||
570 | |||
571 | static ssize_t | ||
572 | nouveau_hwmon_set_pwm0_max(struct device *d, struct device_attribute *a, | ||
573 | const char *buf, size_t count) | ||
574 | { | ||
575 | struct drm_device *dev = dev_get_drvdata(d); | ||
576 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
577 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | ||
578 | long value; | ||
579 | |||
580 | if (strict_strtol(buf, 10, &value) == -EINVAL) | ||
581 | return -EINVAL; | ||
582 | |||
583 | if (value < 0) | ||
584 | value = 0; | ||
585 | |||
586 | if (value - pm->fan.min_duty < 10) | ||
587 | value = pm->fan.min_duty + 10; | ||
588 | |||
589 | if (value > 100) | ||
590 | pm->fan.max_duty = 100; | ||
591 | else | ||
592 | pm->fan.max_duty = value; | ||
593 | |||
594 | return count; | ||
595 | } | ||
596 | |||
597 | static SENSOR_DEVICE_ATTR(pwm0_max, S_IRUGO | S_IWUSR, | ||
598 | nouveau_hwmon_get_pwm0_max, | ||
599 | nouveau_hwmon_set_pwm0_max, 0); | ||
600 | |||
427 | static struct attribute *hwmon_attributes[] = { | 601 | static struct attribute *hwmon_attributes[] = { |
428 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 602 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
429 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 603 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
@@ -432,10 +606,26 @@ static struct attribute *hwmon_attributes[] = { | |||
432 | &sensor_dev_attr_update_rate.dev_attr.attr, | 606 | &sensor_dev_attr_update_rate.dev_attr.attr, |
433 | NULL | 607 | NULL |
434 | }; | 608 | }; |
609 | static struct attribute *hwmon_fan_rpm_attributes[] = { | ||
610 | &sensor_dev_attr_fan0_input.dev_attr.attr, | ||
611 | NULL | ||
612 | }; | ||
613 | static struct attribute *hwmon_pwm_fan_attributes[] = { | ||
614 | &sensor_dev_attr_pwm0.dev_attr.attr, | ||
615 | &sensor_dev_attr_pwm0_min.dev_attr.attr, | ||
616 | &sensor_dev_attr_pwm0_max.dev_attr.attr, | ||
617 | NULL | ||
618 | }; | ||
435 | 619 | ||
436 | static const struct attribute_group hwmon_attrgroup = { | 620 | static const struct attribute_group hwmon_attrgroup = { |
437 | .attrs = hwmon_attributes, | 621 | .attrs = hwmon_attributes, |
438 | }; | 622 | }; |
623 | static const struct attribute_group hwmon_fan_rpm_attrgroup = { | ||
624 | .attrs = hwmon_fan_rpm_attributes, | ||
625 | }; | ||
626 | static const struct attribute_group hwmon_pwm_fan_attrgroup = { | ||
627 | .attrs = hwmon_pwm_fan_attributes, | ||
628 | }; | ||
439 | #endif | 629 | #endif |
440 | 630 | ||
441 | static int | 631 | static int |
@@ -445,7 +635,7 @@ nouveau_hwmon_init(struct drm_device *dev) | |||
445 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 635 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
446 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; | 636 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; |
447 | struct device *hwmon_dev; | 637 | struct device *hwmon_dev; |
448 | int ret; | 638 | int ret = 0; |
449 | 639 | ||
450 | if (!pm->temp_get) | 640 | if (!pm->temp_get) |
451 | return -ENODEV; | 641 | return -ENODEV; |
@@ -458,17 +648,46 @@ nouveau_hwmon_init(struct drm_device *dev) | |||
458 | return ret; | 648 | return ret; |
459 | } | 649 | } |
460 | dev_set_drvdata(hwmon_dev, dev); | 650 | dev_set_drvdata(hwmon_dev, dev); |
651 | |||
652 | /* default sysfs entries */ | ||
461 | ret = sysfs_create_group(&dev->pdev->dev.kobj, &hwmon_attrgroup); | 653 | ret = sysfs_create_group(&dev->pdev->dev.kobj, &hwmon_attrgroup); |
462 | if (ret) { | 654 | if (ret) { |
463 | NV_ERROR(dev, | 655 | if (ret) |
464 | "Unable to create hwmon sysfs file: %d\n", ret); | 656 | goto error; |
465 | hwmon_device_unregister(hwmon_dev); | 657 | } |
466 | return ret; | 658 | |
659 | /* if the card has a pwm fan */ | ||
660 | /*XXX: incorrect, need better detection for this, some boards have | ||
661 | * the gpio entries for pwm fan control even when there's no | ||
662 | * actual fan connected to it... therm table? */ | ||
663 | if (pm->fanspeed_get && pm->fanspeed_get(dev) >= 0) { | ||
664 | ret = sysfs_create_group(&dev->pdev->dev.kobj, | ||
665 | &hwmon_pwm_fan_attrgroup); | ||
666 | if (ret) | ||
667 | goto error; | ||
668 | } | ||
669 | |||
670 | /* if the card can read the fan rpm */ | ||
671 | if (nouveau_bios_gpio_entry(dev, DCB_GPIO_FAN_SENSE)) { | ||
672 | ret = sysfs_create_group(&dev->pdev->dev.kobj, | ||
673 | &hwmon_fan_rpm_attrgroup); | ||
674 | if (ret) | ||
675 | goto error; | ||
467 | } | 676 | } |
468 | 677 | ||
469 | pm->hwmon = hwmon_dev; | 678 | pm->hwmon = hwmon_dev; |
470 | #endif | 679 | |
471 | return 0; | 680 | return 0; |
681 | |||
682 | error: | ||
683 | NV_ERROR(dev, "Unable to create some hwmon sysfs files: %d\n", ret); | ||
684 | hwmon_device_unregister(hwmon_dev); | ||
685 | pm->hwmon = NULL; | ||
686 | return ret; | ||
687 | #else | ||
688 | pm->hwmon = NULL; | ||
689 | return 0; | ||
690 | #endif | ||
472 | } | 691 | } |
473 | 692 | ||
474 | static void | 693 | static void |
@@ -480,6 +699,9 @@ nouveau_hwmon_fini(struct drm_device *dev) | |||
480 | 699 | ||
481 | if (pm->hwmon) { | 700 | if (pm->hwmon) { |
482 | sysfs_remove_group(&dev->pdev->dev.kobj, &hwmon_attrgroup); | 701 | sysfs_remove_group(&dev->pdev->dev.kobj, &hwmon_attrgroup); |
702 | sysfs_remove_group(&dev->pdev->dev.kobj, &hwmon_pwm_fan_attrgroup); | ||
703 | sysfs_remove_group(&dev->pdev->dev.kobj, &hwmon_fan_rpm_attrgroup); | ||
704 | |||
483 | hwmon_device_unregister(pm->hwmon); | 705 | hwmon_device_unregister(pm->hwmon); |
484 | } | 706 | } |
485 | #endif | 707 | #endif |
diff --git a/drivers/gpu/drm/nouveau/nouveau_temp.c b/drivers/gpu/drm/nouveau/nouveau_temp.c index 5a46446dd5a8..97c172cae3bc 100644 --- a/drivers/gpu/drm/nouveau/nouveau_temp.c +++ b/drivers/gpu/drm/nouveau/nouveau_temp.c | |||
@@ -55,6 +55,10 @@ nouveau_temp_vbios_parse(struct drm_device *dev, u8 *temp) | |||
55 | temps->down_clock = 100; | 55 | temps->down_clock = 100; |
56 | temps->fan_boost = 90; | 56 | temps->fan_boost = 90; |
57 | 57 | ||
58 | /* Set the default range for the pwm fan */ | ||
59 | pm->fan.min_duty = 30; | ||
60 | pm->fan.max_duty = 100; | ||
61 | |||
58 | /* Set the known default values to setup the temperature sensor */ | 62 | /* Set the known default values to setup the temperature sensor */ |
59 | if (dev_priv->card_type >= NV_40) { | 63 | if (dev_priv->card_type >= NV_40) { |
60 | switch (dev_priv->chipset) { | 64 | switch (dev_priv->chipset) { |
@@ -156,11 +160,23 @@ nouveau_temp_vbios_parse(struct drm_device *dev, u8 *temp) | |||
156 | case 0x13: | 160 | case 0x13: |
157 | sensor->slope_div = value; | 161 | sensor->slope_div = value; |
158 | break; | 162 | break; |
163 | case 0x22: | ||
164 | pm->fan.min_duty = value & 0xff; | ||
165 | pm->fan.max_duty = (value & 0xff00) >> 8; | ||
166 | break; | ||
159 | } | 167 | } |
160 | temp += recordlen; | 168 | temp += recordlen; |
161 | } | 169 | } |
162 | 170 | ||
163 | nouveau_temp_safety_checks(dev); | 171 | nouveau_temp_safety_checks(dev); |
172 | |||
173 | /* check the fan min/max settings */ | ||
174 | if (pm->fan.min_duty < 10) | ||
175 | pm->fan.min_duty = 10; | ||
176 | if (pm->fan.max_duty > 100) | ||
177 | pm->fan.max_duty = 100; | ||
178 | if (pm->fan.max_duty < pm->fan.min_duty) | ||
179 | pm->fan.max_duty = pm->fan.min_duty; | ||
164 | } | 180 | } |
165 | 181 | ||
166 | static int | 182 | static int |