| @@ -1,39 +1,39 @@ | | | @@ -1,39 +1,39 @@ |
1 | /* $NetBSD: radeon_pm.c,v 1.4 2018/08/27 04:58:36 riastradh Exp $ */ | | 1 | /* $NetBSD: radeon_pm.c,v 1.5 2018/08/27 07:50:19 riastradh Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
5 | * copy of this software and associated documentation files (the "Software"), | | 5 | * copy of this software and associated documentation files (the "Software"), |
6 | * to deal in the Software without restriction, including without limitation | | 6 | * to deal in the Software without restriction, including without limitation |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | | 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 | | 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: | | 9 | * Software is furnished to do so, subject to the following conditions: |
10 | * | | 10 | * |
11 | * The above copyright notice and this permission notice shall be included in | | 11 | * The above copyright notice and this permission notice shall be included in |
12 | * all copies or substantial portions of the Software. | | 12 | * all copies or substantial portions of the Software. |
13 | * | | 13 | * |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | | 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, | | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | | 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 | | 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, | | 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 | | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
20 | * OTHER DEALINGS IN THE SOFTWARE. | | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
21 | * | | 21 | * |
22 | * Authors: Rafał Miłecki <zajec5@gmail.com> | | 22 | * Authors: Rafał Miłecki <zajec5@gmail.com> |
23 | * Alex Deucher <alexdeucher@gmail.com> | | 23 | * Alex Deucher <alexdeucher@gmail.com> |
24 | */ | | 24 | */ |
25 | #include <sys/cdefs.h> | | 25 | #include <sys/cdefs.h> |
26 | __KERNEL_RCSID(0, "$NetBSD: radeon_pm.c,v 1.4 2018/08/27 04:58:36 riastradh Exp $"); | | 26 | __KERNEL_RCSID(0, "$NetBSD: radeon_pm.c,v 1.5 2018/08/27 07:50:19 riastradh Exp $"); |
27 | | | 27 | |
28 | #include <drm/drmP.h> | | 28 | #include <drm/drmP.h> |
29 | #include "radeon.h" | | 29 | #include "radeon.h" |
30 | #include "avivod.h" | | 30 | #include "avivod.h" |
31 | #include "atom.h" | | 31 | #include "atom.h" |
32 | #include "r600_dpm.h" | | 32 | #include "r600_dpm.h" |
33 | #include <linux/power_supply.h> | | 33 | #include <linux/power_supply.h> |
34 | #include <linux/hwmon.h> | | 34 | #include <linux/hwmon.h> |
35 | #include <linux/hwmon-sysfs.h> | | 35 | #include <linux/hwmon-sysfs.h> |
36 | | | 36 | |
37 | #define RADEON_IDLE_LOOP_MS 100 | | 37 | #define RADEON_IDLE_LOOP_MS 100 |
38 | #define RADEON_RECLOCK_DELAY_MS 200 | | 38 | #define RADEON_RECLOCK_DELAY_MS 200 |
39 | #define RADEON_WAIT_VBLANK_TIMEOUT 200 | | 39 | #define RADEON_WAIT_VBLANK_TIMEOUT 200 |
| @@ -1545,68 +1545,72 @@ int radeon_pm_init(struct radeon_device | | | @@ -1545,68 +1545,72 @@ int radeon_pm_init(struct radeon_device |
1545 | | | 1545 | |
1546 | if (rdev->pm.pm_method == PM_METHOD_DPM) | | 1546 | if (rdev->pm.pm_method == PM_METHOD_DPM) |
1547 | return radeon_pm_init_dpm(rdev); | | 1547 | return radeon_pm_init_dpm(rdev); |
1548 | else | | 1548 | else |
1549 | return radeon_pm_init_old(rdev); | | 1549 | return radeon_pm_init_old(rdev); |
1550 | } | | 1550 | } |
1551 | | | 1551 | |
1552 | int radeon_pm_late_init(struct radeon_device *rdev) | | 1552 | int radeon_pm_late_init(struct radeon_device *rdev) |
1553 | { | | 1553 | { |
1554 | int ret = 0; | | 1554 | int ret = 0; |
1555 | | | 1555 | |
1556 | if (rdev->pm.pm_method == PM_METHOD_DPM) { | | 1556 | if (rdev->pm.pm_method == PM_METHOD_DPM) { |
1557 | if (rdev->pm.dpm_enabled) { | | 1557 | if (rdev->pm.dpm_enabled) { |
| | | 1558 | #ifndef __NetBSD__ /* XXX radeon sysfs */ |
1558 | if (!rdev->pm.sysfs_initialized) { | | 1559 | if (!rdev->pm.sysfs_initialized) { |
1559 | ret = device_create_file(rdev->dev, &dev_attr_power_dpm_state); | | 1560 | ret = device_create_file(rdev->dev, &dev_attr_power_dpm_state); |
1560 | if (ret) | | 1561 | if (ret) |
1561 | DRM_ERROR("failed to create device file for dpm state\n"); | | 1562 | DRM_ERROR("failed to create device file for dpm state\n"); |
1562 | ret = device_create_file(rdev->dev, &dev_attr_power_dpm_force_performance_level); | | 1563 | ret = device_create_file(rdev->dev, &dev_attr_power_dpm_force_performance_level); |
1563 | if (ret) | | 1564 | if (ret) |
1564 | DRM_ERROR("failed to create device file for dpm state\n"); | | 1565 | DRM_ERROR("failed to create device file for dpm state\n"); |
1565 | /* XXX: these are noops for dpm but are here for backwards compat */ | | 1566 | /* XXX: these are noops for dpm but are here for backwards compat */ |
1566 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); | | 1567 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); |
1567 | if (ret) | | 1568 | if (ret) |
1568 | DRM_ERROR("failed to create device file for power profile\n"); | | 1569 | DRM_ERROR("failed to create device file for power profile\n"); |
1569 | ret = device_create_file(rdev->dev, &dev_attr_power_method); | | 1570 | ret = device_create_file(rdev->dev, &dev_attr_power_method); |
1570 | if (ret) | | 1571 | if (ret) |
1571 | DRM_ERROR("failed to create device file for power method\n"); | | 1572 | DRM_ERROR("failed to create device file for power method\n"); |
1572 | rdev->pm.sysfs_initialized = true; | | 1573 | rdev->pm.sysfs_initialized = true; |
1573 | } | | 1574 | } |
| | | 1575 | #endif |
1574 | | | 1576 | |
1575 | mutex_lock(&rdev->pm.mutex); | | 1577 | mutex_lock(&rdev->pm.mutex); |
1576 | ret = radeon_dpm_late_enable(rdev); | | 1578 | ret = radeon_dpm_late_enable(rdev); |
1577 | mutex_unlock(&rdev->pm.mutex); | | 1579 | mutex_unlock(&rdev->pm.mutex); |
1578 | if (ret) { | | 1580 | if (ret) { |
1579 | rdev->pm.dpm_enabled = false; | | 1581 | rdev->pm.dpm_enabled = false; |
1580 | DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n"); | | 1582 | DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n"); |
1581 | } else { | | 1583 | } else { |
1582 | /* set the dpm state for PX since there won't be | | 1584 | /* set the dpm state for PX since there won't be |
1583 | * a modeset to call this. | | 1585 | * a modeset to call this. |
1584 | */ | | 1586 | */ |
1585 | radeon_pm_compute_clocks(rdev); | | 1587 | radeon_pm_compute_clocks(rdev); |
1586 | } | | 1588 | } |
1587 | } | | 1589 | } |
1588 | } else { | | 1590 | } else { |
1589 | if ((rdev->pm.num_power_states > 1) && | | 1591 | if ((rdev->pm.num_power_states > 1) && |
1590 | (!rdev->pm.sysfs_initialized)) { | | 1592 | (!rdev->pm.sysfs_initialized)) { |
| | | 1593 | #ifndef __NetBSD__ /* XXX radeon sysfs */ |
1591 | /* where's the best place to put these? */ | | 1594 | /* where's the best place to put these? */ |
1592 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); | | 1595 | ret = device_create_file(rdev->dev, &dev_attr_power_profile); |
1593 | if (ret) | | 1596 | if (ret) |
1594 | DRM_ERROR("failed to create device file for power profile\n"); | | 1597 | DRM_ERROR("failed to create device file for power profile\n"); |
1595 | ret = device_create_file(rdev->dev, &dev_attr_power_method); | | 1598 | ret = device_create_file(rdev->dev, &dev_attr_power_method); |
1596 | if (ret) | | 1599 | if (ret) |
1597 | DRM_ERROR("failed to create device file for power method\n"); | | 1600 | DRM_ERROR("failed to create device file for power method\n"); |
1598 | if (!ret) | | 1601 | if (!ret) |
1599 | rdev->pm.sysfs_initialized = true; | | 1602 | rdev->pm.sysfs_initialized = true; |
| | | 1603 | #endif |
1600 | } | | 1604 | } |
1601 | } | | 1605 | } |
1602 | return ret; | | 1606 | return ret; |
1603 | } | | 1607 | } |
1604 | | | 1608 | |
1605 | static void radeon_pm_fini_old(struct radeon_device *rdev) | | 1609 | static void radeon_pm_fini_old(struct radeon_device *rdev) |
1606 | { | | 1610 | { |
1607 | if (rdev->pm.num_power_states > 1) { | | 1611 | if (rdev->pm.num_power_states > 1) { |
1608 | mutex_lock(&rdev->pm.mutex); | | 1612 | mutex_lock(&rdev->pm.mutex); |
1609 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { | | 1613 | if (rdev->pm.pm_method == PM_METHOD_PROFILE) { |
1610 | rdev->pm.profile = PM_PROFILE_DEFAULT; | | 1614 | rdev->pm.profile = PM_PROFILE_DEFAULT; |
1611 | radeon_pm_update_profile(rdev); | | 1615 | radeon_pm_update_profile(rdev); |
1612 | radeon_pm_set_clocks(rdev); | | 1616 | radeon_pm_set_clocks(rdev); |