Commit | Line | Data |
---|---|---|
9e3d83c5 SRM |
1 | // SPDX-License-Identifier: GPL-2.0-only |
2 | // Copyright (c) 2022, The Linux Foundation. All rights reserved. | |
3 | ||
4 | #include <linux/export.h> | |
5 | #include <linux/module.h> | |
6 | #include <linux/init.h> | |
7 | #include <linux/of_platform.h> | |
8 | #include <linux/platform_device.h> | |
9 | #include <linux/pm_domain.h> | |
10 | #include <linux/pm_runtime.h> | |
11 | ||
12 | #include "lpass-macro-common.h" | |
13 | ||
14 | struct lpass_macro *lpass_macro_pds_init(struct device *dev) | |
15 | { | |
16 | struct lpass_macro *l_pds; | |
17 | int ret; | |
18 | ||
19 | if (!of_find_property(dev->of_node, "power-domains", NULL)) | |
20 | return NULL; | |
21 | ||
22 | l_pds = devm_kzalloc(dev, sizeof(*l_pds), GFP_KERNEL); | |
23 | if (!l_pds) | |
24 | return ERR_PTR(-ENOMEM); | |
25 | ||
26 | l_pds->macro_pd = dev_pm_domain_attach_by_name(dev, "macro"); | |
1a8ee4cf SRM |
27 | if (IS_ERR_OR_NULL(l_pds->macro_pd)) { |
28 | ret = PTR_ERR(l_pds->macro_pd); | |
9e3d83c5 SRM |
29 | goto macro_err; |
30 | } | |
31 | ||
1a8ee4cf SRM |
32 | ret = pm_runtime_resume_and_get(l_pds->macro_pd); |
33 | if (ret < 0) | |
34 | goto macro_sync_err; | |
35 | ||
9e3d83c5 | 36 | l_pds->dcodec_pd = dev_pm_domain_attach_by_name(dev, "dcodec"); |
1a8ee4cf SRM |
37 | if (IS_ERR_OR_NULL(l_pds->dcodec_pd)) { |
38 | ret = PTR_ERR(l_pds->dcodec_pd); | |
9e3d83c5 | 39 | goto dcodec_err; |
1a8ee4cf | 40 | } |
9e3d83c5 | 41 | |
1a8ee4cf SRM |
42 | ret = pm_runtime_resume_and_get(l_pds->dcodec_pd); |
43 | if (ret < 0) | |
9e3d83c5 | 44 | goto dcodec_sync_err; |
9e3d83c5 SRM |
45 | return l_pds; |
46 | ||
47 | dcodec_sync_err: | |
48 | dev_pm_domain_detach(l_pds->dcodec_pd, false); | |
49 | dcodec_err: | |
50 | pm_runtime_put(l_pds->macro_pd); | |
1a8ee4cf | 51 | macro_sync_err: |
9e3d83c5 | 52 | dev_pm_domain_detach(l_pds->macro_pd, false); |
1a8ee4cf | 53 | macro_err: |
9e3d83c5 SRM |
54 | return ERR_PTR(ret); |
55 | } | |
56 | EXPORT_SYMBOL_GPL(lpass_macro_pds_init); | |
57 | ||
58 | void lpass_macro_pds_exit(struct lpass_macro *pds) | |
59 | { | |
1a8ee4cf SRM |
60 | if (pds) { |
61 | pm_runtime_put(pds->macro_pd); | |
62 | dev_pm_domain_detach(pds->macro_pd, false); | |
63 | pm_runtime_put(pds->dcodec_pd); | |
64 | dev_pm_domain_detach(pds->dcodec_pd, false); | |
65 | } | |
9e3d83c5 SRM |
66 | } |
67 | EXPORT_SYMBOL_GPL(lpass_macro_pds_exit); | |
68 | ||
69 | MODULE_DESCRIPTION("Common macro driver"); | |
70 | MODULE_LICENSE("GPL"); |