Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
14int 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 guard(mutex)(&xdna->dev_lock);
20 if (xdna->dev_info->ops->suspend)
21 ret = xdna->dev_info->ops->suspend(xdna);
22
23 XDNA_DBG(xdna, "Suspend done ret %d", ret);
24 return ret;
25}
26
27int amdxdna_pm_resume(struct device *dev)
28{
29 struct amdxdna_dev *xdna = to_xdna_dev(dev_get_drvdata(dev));
30 int ret = -EOPNOTSUPP;
31
32 guard(mutex)(&xdna->dev_lock);
33 if (xdna->dev_info->ops->resume)
34 ret = xdna->dev_info->ops->resume(xdna);
35
36 XDNA_DBG(xdna, "Resume done ret %d", ret);
37 return ret;
38}
39
40int amdxdna_pm_resume_get(struct amdxdna_dev *xdna)
41{
42 struct device *dev = xdna->ddev.dev;
43 int ret;
44
45 ret = pm_runtime_resume_and_get(dev);
46 if (ret) {
47 XDNA_ERR(xdna, "Resume failed: %d", ret);
48 pm_runtime_set_suspended(dev);
49 }
50
51 return ret;
52}
53
54void amdxdna_pm_suspend_put(struct amdxdna_dev *xdna)
55{
56 struct device *dev = xdna->ddev.dev;
57
58 pm_runtime_put_autosuspend(dev);
59}
60
61void amdxdna_pm_init(struct amdxdna_dev *xdna)
62{
63 struct device *dev = xdna->ddev.dev;
64
65 pm_runtime_set_active(dev);
66 pm_runtime_set_autosuspend_delay(dev, AMDXDNA_AUTOSUSPEND_DELAY);
67 pm_runtime_use_autosuspend(dev);
68 pm_runtime_allow(dev);
69 pm_runtime_put_autosuspend(dev);
70}
71
72void amdxdna_pm_fini(struct amdxdna_dev *xdna)
73{
74 struct device *dev = xdna->ddev.dev;
75
76 pm_runtime_get_noresume(dev);
77 pm_runtime_forbid(dev);
78}