Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/drivers/accel/amdxdna/amdxdna_pm.c
50904 views
1
// SPDX-License-Identifier: GPL-2.0
2
/*
3
* Copyright (C) 2025, Advanced Micro Devices, Inc.
4
*/
5
6
#include <drm/amdxdna_accel.h>
7
#include <drm/drm_drv.h>
8
#include <linux/pm_runtime.h>
9
10
#include "amdxdna_pm.h"
11
12
#define AMDXDNA_AUTOSUSPEND_DELAY 5000 /* milliseconds */
13
14
int amdxdna_pm_suspend(struct device *dev)
15
{
16
struct amdxdna_dev *xdna = to_xdna_dev(dev_get_drvdata(dev));
17
int ret = -EOPNOTSUPP;
18
19
if (xdna->dev_info->ops->suspend)
20
ret = xdna->dev_info->ops->suspend(xdna);
21
22
XDNA_DBG(xdna, "Suspend done ret %d", ret);
23
return ret;
24
}
25
26
int amdxdna_pm_resume(struct device *dev)
27
{
28
struct amdxdna_dev *xdna = to_xdna_dev(dev_get_drvdata(dev));
29
int ret = -EOPNOTSUPP;
30
31
if (xdna->dev_info->ops->resume)
32
ret = xdna->dev_info->ops->resume(xdna);
33
34
XDNA_DBG(xdna, "Resume done ret %d", ret);
35
return ret;
36
}
37
38
int amdxdna_pm_resume_get(struct amdxdna_dev *xdna)
39
{
40
struct device *dev = xdna->ddev.dev;
41
int ret;
42
43
ret = pm_runtime_resume_and_get(dev);
44
if (ret) {
45
XDNA_ERR(xdna, "Resume failed: %d", ret);
46
pm_runtime_set_suspended(dev);
47
}
48
49
return ret;
50
}
51
52
void amdxdna_pm_suspend_put(struct amdxdna_dev *xdna)
53
{
54
struct device *dev = xdna->ddev.dev;
55
56
pm_runtime_put_autosuspend(dev);
57
}
58
59
void amdxdna_pm_init(struct amdxdna_dev *xdna)
60
{
61
struct device *dev = xdna->ddev.dev;
62
63
pm_runtime_set_active(dev);
64
pm_runtime_set_autosuspend_delay(dev, AMDXDNA_AUTOSUSPEND_DELAY);
65
pm_runtime_use_autosuspend(dev);
66
pm_runtime_allow(dev);
67
pm_runtime_put_autosuspend(dev);
68
}
69
70
void amdxdna_pm_fini(struct amdxdna_dev *xdna)
71
{
72
struct device *dev = xdna->ddev.dev;
73
74
pm_runtime_get_noresume(dev);
75
pm_runtime_forbid(dev);
76
}
77
78