mtk_vcodec_enc_pm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 -1;
  39. }
  40. pdev = of_find_device_by_node(node);
  41. if (!pdev) {
  42. mtk_v4l2_err("no mediatek,larb device found");
  43. return -1;
  44. }
  45. pm->larbvenc = &pdev->dev;
  46. node = of_parse_phandle(dev->of_node, "mediatek,larb", 1);
  47. if (!node) {
  48. mtk_v4l2_err("no mediatek,larb found");
  49. return -1;
  50. }
  51. pdev = of_find_device_by_node(node);
  52. if (!pdev) {
  53. mtk_v4l2_err("no mediatek,larb device found");
  54. return -1;
  55. }
  56. pm->larbvenclt = &pdev->dev;
  57. pdev = mtkdev->plat_dev;
  58. pm->dev = &pdev->dev;
  59. pm->vencpll_d2 = devm_clk_get(&pdev->dev, "venc_sel_src");
  60. if (IS_ERR(pm->vencpll_d2)) {
  61. mtk_v4l2_err("devm_clk_get vencpll_d2 fail");
  62. ret = PTR_ERR(pm->vencpll_d2);
  63. }
  64. pm->venc_sel = devm_clk_get(&pdev->dev, "venc_sel");
  65. if (IS_ERR(pm->venc_sel)) {
  66. mtk_v4l2_err("devm_clk_get venc_sel fail");
  67. ret = PTR_ERR(pm->venc_sel);
  68. }
  69. pm->univpll1_d2 = devm_clk_get(&pdev->dev, "venc_lt_sel_src");
  70. if (IS_ERR(pm->univpll1_d2)) {
  71. mtk_v4l2_err("devm_clk_get univpll1_d2 fail");
  72. ret = PTR_ERR(pm->univpll1_d2);
  73. }
  74. pm->venc_lt_sel = devm_clk_get(&pdev->dev, "venc_lt_sel");
  75. if (IS_ERR(pm->venc_lt_sel)) {
  76. mtk_v4l2_err("devm_clk_get venc_lt_sel fail");
  77. ret = PTR_ERR(pm->venc_lt_sel);
  78. }
  79. return ret;
  80. }
  81. void mtk_vcodec_release_enc_pm(struct mtk_vcodec_dev *mtkdev)
  82. {
  83. }
  84. void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
  85. {
  86. int ret;
  87. ret = clk_prepare_enable(pm->venc_sel);
  88. if (ret)
  89. mtk_v4l2_err("clk_prepare_enable fail %d", ret);
  90. ret = clk_set_parent(pm->venc_sel, pm->vencpll_d2);
  91. if (ret)
  92. mtk_v4l2_err("clk_set_parent fail %d", ret);
  93. ret = clk_prepare_enable(pm->venc_lt_sel);
  94. if (ret)
  95. mtk_v4l2_err("clk_prepare_enable fail %d", ret);
  96. ret = clk_set_parent(pm->venc_lt_sel, pm->univpll1_d2);
  97. if (ret)
  98. mtk_v4l2_err("clk_set_parent fail %d", ret);
  99. ret = mtk_smi_larb_get(pm->larbvenc);
  100. if (ret)
  101. mtk_v4l2_err("mtk_smi_larb_get larb3 fail %d", ret);
  102. ret = mtk_smi_larb_get(pm->larbvenclt);
  103. if (ret)
  104. mtk_v4l2_err("mtk_smi_larb_get larb4 fail %d", ret);
  105. }
  106. void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
  107. {
  108. mtk_smi_larb_put(pm->larbvenc);
  109. mtk_smi_larb_put(pm->larbvenclt);
  110. clk_disable_unprepare(pm->venc_lt_sel);
  111. clk_disable_unprepare(pm->venc_sel);
  112. }