Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 // Copyright (c) 2022, The Linux Foundation. All rights reserved.
0003 
0004 #include <linux/export.h>
0005 #include <linux/module.h>
0006 #include <linux/init.h>
0007 #include <linux/of_platform.h>
0008 #include <linux/platform_device.h>
0009 #include <linux/pm_domain.h>
0010 #include <linux/pm_runtime.h>
0011 
0012 #include "lpass-macro-common.h"
0013 
0014 struct lpass_macro *lpass_macro_pds_init(struct device *dev)
0015 {
0016     struct lpass_macro *l_pds;
0017     int ret;
0018 
0019     if (!of_find_property(dev->of_node, "power-domains", NULL))
0020         return NULL;
0021 
0022     l_pds = devm_kzalloc(dev, sizeof(*l_pds), GFP_KERNEL);
0023     if (!l_pds)
0024         return ERR_PTR(-ENOMEM);
0025 
0026     l_pds->macro_pd = dev_pm_domain_attach_by_name(dev, "macro");
0027     if (IS_ERR_OR_NULL(l_pds->macro_pd)) {
0028         ret = l_pds->macro_pd ? PTR_ERR(l_pds->macro_pd) : -ENODATA;
0029         goto macro_err;
0030     }
0031 
0032     ret = pm_runtime_resume_and_get(l_pds->macro_pd);
0033     if (ret < 0)
0034         goto macro_sync_err;
0035 
0036     l_pds->dcodec_pd = dev_pm_domain_attach_by_name(dev, "dcodec");
0037     if (IS_ERR_OR_NULL(l_pds->dcodec_pd)) {
0038         ret = l_pds->dcodec_pd ? PTR_ERR(l_pds->dcodec_pd) : -ENODATA;
0039         goto dcodec_err;
0040     }
0041 
0042     ret = pm_runtime_resume_and_get(l_pds->dcodec_pd);
0043     if (ret < 0)
0044         goto dcodec_sync_err;
0045     return l_pds;
0046 
0047 dcodec_sync_err:
0048     dev_pm_domain_detach(l_pds->dcodec_pd, false);
0049 dcodec_err:
0050     pm_runtime_put(l_pds->macro_pd);
0051 macro_sync_err:
0052     dev_pm_domain_detach(l_pds->macro_pd, false);
0053 macro_err:
0054     return ERR_PTR(ret);
0055 }
0056 EXPORT_SYMBOL_GPL(lpass_macro_pds_init);
0057 
0058 void lpass_macro_pds_exit(struct lpass_macro *pds)
0059 {
0060     if (pds) {
0061         pm_runtime_put(pds->macro_pd);
0062         dev_pm_domain_detach(pds->macro_pd, false);
0063         pm_runtime_put(pds->dcodec_pd);
0064         dev_pm_domain_detach(pds->dcodec_pd, false);
0065     }
0066 }
0067 EXPORT_SYMBOL_GPL(lpass_macro_pds_exit);
0068 
0069 MODULE_DESCRIPTION("Common macro driver");
0070 MODULE_LICENSE("GPL");