lpass-macro-common.c 1.7 KB

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