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"); 27 if (IS_ERR_OR_NULL(l_pds->macro_pd)) 28 return NULL; 29 30 ret = pm_runtime_get_sync(l_pds->macro_pd); 31 if (ret < 0) { 32 pm_runtime_put_noidle(l_pds->macro_pd); 33 goto macro_err; 34 } 35 36 l_pds->dcodec_pd = dev_pm_domain_attach_by_name(dev, "dcodec"); 37 if (IS_ERR_OR_NULL(l_pds->dcodec_pd)) 38 goto dcodec_err; 39 40 ret = pm_runtime_get_sync(l_pds->dcodec_pd); 41 if (ret < 0) { 42 pm_runtime_put_noidle(l_pds->dcodec_pd); 43 goto dcodec_sync_err; 44 } 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); 51 macro_err: 52 dev_pm_domain_detach(l_pds->macro_pd, false); 53 return ERR_PTR(ret); 54 } 55 EXPORT_SYMBOL_GPL(lpass_macro_pds_init); 56 57 void lpass_macro_pds_exit(struct lpass_macro *pds) 58 { 59 pm_runtime_put(pds->macro_pd); 60 dev_pm_domain_detach(pds->macro_pd, false); 61 pm_runtime_put(pds->dcodec_pd); 62 dev_pm_domain_detach(pds->dcodec_pd, false); 63 } 64 EXPORT_SYMBOL_GPL(lpass_macro_pds_exit); 65 66 MODULE_DESCRIPTION("Common macro driver"); 67 MODULE_LICENSE("GPL"); 68