0034-soc-mediatek-PMIC-wrap-split-SoC-specific-init-into-.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. From a1bbd630710d5da89a9c347c84d7badd30e7e68a Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Wed, 20 Jan 2016 10:12:00 +0100
  4. Subject: [PATCH 034/102] soc: mediatek: PMIC wrap: split SoC specific init
  5. into callback
  6. This patch moves the SoC specific wrapper init code into separate callback
  7. to avoid pwrap_init() getting too large. This is done by adding a new
  8. element called init_special to pmic_wrapper_type. Each currently supported
  9. SoC gets its own version of the callback and we copy the code that was
  10. previously inside pwrap_init() to these new callbacks. Finally we point the
  11. 2 instances of pmic_wrapper_type at the 2 new functions.
  12. Signed-off-by: John Crispin <blogic@openwrt.org>
  13. ---
  14. drivers/soc/mediatek/mtk-pmic-wrap.c | 67 +++++++++++++++++++++-------------
  15. 1 file changed, 42 insertions(+), 25 deletions(-)
  16. --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
  17. +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
  18. @@ -372,6 +372,7 @@ struct pmic_wrapper_type {
  19. enum pwrap_type type;
  20. u32 arb_en_all;
  21. int (*init_reg_clock)(struct pmic_wrapper *wrp);
  22. + int (*init_soc_specific)(struct pmic_wrapper *wrp);
  23. };
  24. static inline int pwrap_is_mt8135(struct pmic_wrapper *wrp)
  25. @@ -665,6 +666,41 @@ static int pwrap_init_cipher(struct pmic
  26. return 0;
  27. }
  28. +static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
  29. +{
  30. + /* enable pwrap events and pwrap bridge in AP side */
  31. + pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN);
  32. + pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN);
  33. + writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
  34. + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
  35. + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
  36. + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
  37. + writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
  38. + writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
  39. + writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
  40. +
  41. + /* enable PMIC event out and sources */
  42. + if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
  43. + pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
  44. + dev_err(wrp->dev, "enable dewrap fail\n");
  45. + return -EFAULT;
  46. + }
  47. +
  48. + return 0;
  49. +}
  50. +
  51. +static int pwrap_mt8173_init_soc_specific(struct pmic_wrapper *wrp)
  52. +{
  53. + /* PMIC_DEWRAP enables */
  54. + if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
  55. + pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
  56. + dev_err(wrp->dev, "enable dewrap fail\n");
  57. + return -EFAULT;
  58. + }
  59. +
  60. + return 0;
  61. +}
  62. +
  63. static int pwrap_init(struct pmic_wrapper *wrp)
  64. {
  65. int ret;
  66. @@ -743,31 +779,10 @@ static int pwrap_init(struct pmic_wrappe
  67. pwrap_writel(wrp, 0x5, PWRAP_STAUPD_PRD);
  68. pwrap_writel(wrp, 0xff, PWRAP_STAUPD_GRPEN);
  69. - if (pwrap_is_mt8135(wrp)) {
  70. - /* enable pwrap events and pwrap bridge in AP side */
  71. - pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN);
  72. - pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN);
  73. - writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
  74. - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
  75. - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
  76. - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
  77. - writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
  78. - writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
  79. - writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
  80. -
  81. - /* enable PMIC event out and sources */
  82. - if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
  83. - pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
  84. - dev_err(wrp->dev, "enable dewrap fail\n");
  85. - return -EFAULT;
  86. - }
  87. - } else {
  88. - /* PMIC_DEWRAP enables */
  89. - if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
  90. - pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
  91. - dev_err(wrp->dev, "enable dewrap fail\n");
  92. - return -EFAULT;
  93. - }
  94. + if (wrp->master->init_soc_specific) {
  95. + ret = wrp->master->init_soc_specific(wrp);
  96. + if (ret)
  97. + return ret;
  98. }
  99. /* Setup the init done registers */
  100. @@ -811,6 +826,7 @@ static struct pmic_wrapper_type pwrap_mt
  101. .type = PWRAP_MT8135,
  102. .arb_en_all = 0x1ff,
  103. .init_reg_clock = pwrap_mt8135_init_reg_clock,
  104. + .init_soc_specific = pwrap_mt8135_init_soc_specific,
  105. };
  106. static struct pmic_wrapper_type pwrap_mt8173 = {
  107. @@ -818,6 +834,7 @@ static struct pmic_wrapper_type pwrap_mt
  108. .type = PWRAP_MT8173,
  109. .arb_en_all = 0x3f,
  110. .init_reg_clock = pwrap_mt8173_init_reg_clock,
  111. + .init_soc_specific = pwrap_mt8173_init_soc_specific,
  112. };
  113. static struct of_device_id of_pwrap_match_tbl[] = {