mtk_vcodec_enc_pm.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (c) 2016 MediaTek Inc.
  3. * Author: Tiffany Lin <tiffany.lin@mediatek.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_platform.h>
  17. #include <linux/pm_runtime.h>
  18. #include <soc/mediatek/smi.h>
  19. #include "mtk_vcodec_enc_pm.h"
  20. #include "mtk_vcodec_util.h"
  21. #include "mtk_vpu.h"
  22. int mtk_vcodec_init_enc_pm(struct mtk_vcodec_dev *mtkdev)
  23. {
  24. struct device_node *node;
  25. struct platform_device *pdev;
  26. struct device *dev;
  27. struct mtk_vcodec_pm *pm;
  28. int ret = 0;
  29. pdev = mtkdev->plat_dev;
  30. pm = &mtkdev->pm;
  31. memset(pm, 0, sizeof(struct mtk_vcodec_pm));
  32. pm->mtkdev = mtkdev;
  33. pm->dev = &pdev->dev;
  34. dev = &pdev->dev;
  35. node = of_parse_phandle(dev->of_node, "mediatek,larb", 0);
  36. if (!node) {
  37. mtk_v4l2_err("no mediatek,larb found");
  38. return -ENODEV;
  39. }
  40. pdev = of_find_device_by_node(node);
  41. of_node_put(node);
  42. if (!pdev) {
  43. mtk_v4l2_err("no mediatek,larb device found");
  44. return -ENODEV;
  45. }
  46. pm->larbvenc = &pdev->dev;
  47. node = of_parse_phandle(dev->of_node, "mediatek,larb", 1);
  48. if (!node) {
  49. mtk_v4l2_err("no mediatek,larb found");
  50. return -ENODEV;
  51. }
  52. pdev = of_find_device_by_node(node);
  53. of_node_put(node);
  54. if (!pdev) {
  55. mtk_v4l2_err("no mediatek,larb device found");
  56. return -ENODEV;
  57. }
  58. pm->larbvenclt = &pdev->dev;
  59. pdev = mtkdev->plat_dev;
  60. pm->dev = &pdev->dev;
  61. pm->vencpll_d2 = devm_clk_get(&pdev->dev, "venc_sel_src");
  62. if (IS_ERR(pm->vencpll_d2)) {
  63. mtk_v4l2_err("devm_clk_get vencpll_d2 fail");
  64. ret = PTR_ERR(pm->vencpll_d2);
  65. }
  66. pm->venc_sel = devm_clk_get(&pdev->dev, "venc_sel");
  67. if (IS_ERR(pm->venc_sel)) {
  68. mtk_v4l2_err("devm_clk_get venc_sel fail");
  69. ret = PTR_ERR(pm->venc_sel);
  70. }
  71. pm->univpll1_d2 = devm_clk_get(&pdev->dev, "venc_lt_sel_src");
  72. if (IS_ERR(pm->univpll1_d2)) {
  73. mtk_v4l2_err("devm_clk_get univpll1_d2 fail");
  74. ret = PTR_ERR(pm->univpll1_d2);
  75. }
  76. pm->venc_lt_sel = devm_clk_get(&pdev->dev, "venc_lt_sel");
  77. if (IS_ERR(pm->venc_lt_sel)) {
  78. mtk_v4l2_err("devm_clk_get venc_lt_sel fail");
  79. ret = PTR_ERR(pm->venc_lt_sel);
  80. }
  81. return ret;
  82. }
  83. void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *mtkdev)
  84. {
  85. }
  86. void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
  87. {
  88. int ret;
  89. ret = clk_prepare_enable(pm->venc_sel);
  90. if (ret)
  91. mtk_v4l2_err("clk_prepare_enable fail %d", ret);
  92. ret = clk_set_parent(pm->venc_sel, pm->vencpll_d2);
  93. if (ret)
  94. mtk_v4l2_err("clk_set_parent fail %d", ret);
  95. ret = clk_prepare_enable(pm->venc_lt_sel);
  96. if (ret)
  97. mtk_v4l2_err("clk_prepare_enable fail %d", ret);
  98. ret = clk_set_parent(pm->venc_lt_sel, pm->univpll1_d2);
  99. if (ret)
  100. mtk_v4l2_err("clk_set_parent fail %d", ret);
  101. ret = mtk_smi_larb_get(pm->larbvenc);
  102. if (ret)
  103. mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
  104. ret = mtk_smi_larb_get(pm->larbvenclt);
  105. if (ret)
  106. mtk_v4l2_err("mtk_smi_larb_get larb4 fail %d", ret);
  107. }
  108. void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
  109. {
  110. mtk_smi_larb_put(pm->larbvenc);
  111. mtk_smi_larb_put(pm->larbvenclt);
  112. clk_disable_unprepare(pm->venc_lt_sel);
  113. clk_disable_unprepare(pm->venc_sel);
  114. }