mrdump_key_setup.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (c) 2020 MediaTek Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef CFG_MTK_WDT_COMMON
  24. #include <printf.h>
  25. void mrdump_key_secure_enable(void)
  26. {
  27. dprintf(CRITICAL, "%s: No MTK WDT Common Driver API\n", __func__);
  28. }
  29. void mrdump_key_fdt_init(void *fdt)
  30. {
  31. dprintf(CRITICAL, "%s: No MTK WDT Common Driver API\n", __func__);
  32. }
  33. #else
  34. #include <platform/mt_gpio.h>
  35. #include <platform/mt_typedefs.h>
  36. #include <mtk_wdt.h>
  37. #include <pmic_common.h>
  38. #include <printf.h>
  39. static void mrdump_key_select_eint(int mrdump_key_pin)
  40. {
  41. mt_set_gpio_pull_enable(mrdump_key_pin, GPIO_PULL_UP);
  42. mt_set_gpio_dir(mrdump_key_pin, GPIO_DIR_IN);
  43. mt_set_gpio_mode(mrdump_key_pin, GPIO_MODE_00);
  44. mtk_wdt_select_eint((unsigned int)mrdump_key_pin);
  45. }
  46. static void mrdump_key_apply(char *force_trigger, char *rst_mode,
  47. int mrdump_key_pin)
  48. {
  49. if (!rst_mode || !force_trigger) {
  50. dprintf(CRITICAL, "%s: no rst_mode or force_trigger\n",
  51. __func__);
  52. return;
  53. }
  54. if (!strncmp("SYSRST", force_trigger, strlen("SYSRST"))) {
  55. if (!strncmp(rst_mode, "IRQ", strlen("IRQ"))) {
  56. mtk_wdt_request_mode_set(MTK_WDT_STATUS_SYSRST_RST,
  57. WD_REQ_IRQ_MODE);
  58. mtk_wdt_request_en_set(MTK_WDT_STATUS_SYSRST_RST,
  59. WD_REQ_EN);
  60. enable_pmic_smart_reset(1); /* 1st timeout */
  61. enable_pmic_smart_reset_shutdown(1); /* 2nd timeout */
  62. } else if (!strncmp(rst_mode, "RST", strlen("RST"))) {
  63. mtk_wdt_request_mode_set(MTK_WDT_STATUS_SYSRST_RST,
  64. WD_REQ_RST_MODE);
  65. mtk_wdt_request_en_set(MTK_WDT_STATUS_SYSRST_RST,
  66. WD_REQ_EN);
  67. enable_pmic_smart_reset(1);
  68. enable_pmic_smart_reset_shutdown(1);
  69. } else {
  70. dprintf(CRITICAL, "%s: bad rst_mode=%s in SYSRST\n",
  71. __func__, rst_mode);
  72. }
  73. } else if (!strncmp("EINT", force_trigger, strlen("EINT"))) {
  74. if ((mrdump_key_pin < 0) || (mrdump_key_pin >12)) {
  75. dprintf(CRITICAL, "%s: incorrect mrdump_key_pin(%d)\n",
  76. __func__, mrdump_key_pin);
  77. return;
  78. }
  79. mrdump_key_select_eint(mrdump_key_pin);
  80. if (rst_mode && !strncmp(rst_mode, "IRQ", strlen("IRQ"))) {
  81. mtk_wdt_request_mode_set(MTK_WDT_STATUS_EINT_RST,
  82. WD_REQ_IRQ_MODE);
  83. mtk_wdt_request_en_set(MTK_WDT_STATUS_EINT_RST,
  84. WD_REQ_EN);
  85. } else if (rst_mode && !strncmp(rst_mode, "RST", strlen("RST"))) {
  86. mtk_wdt_request_mode_set(MTK_WDT_STATUS_EINT_RST,
  87. WD_REQ_RST_MODE);
  88. mtk_wdt_request_en_set(MTK_WDT_STATUS_EINT_RST,
  89. WD_REQ_EN);
  90. } else {
  91. dprintf(CRITICAL, "%s: bad rst_mode=%s in EINT\n",
  92. __func__, rst_mode);
  93. }
  94. } else {
  95. dprintf(CRITICAL, "%s: no valid force_trigger info (%s)\n",
  96. __func__, force_trigger);
  97. }
  98. }
  99. static char *force_mode;
  100. void mrdump_key_secure_enable(void)
  101. {
  102. force_mode = "SYSRST";
  103. }
  104. void mrdump_key_fdt_init(void *fdt)
  105. {
  106. const char mrdump_key_compatible[] = "mediatek, mrdump_ext_rst-eint";
  107. int offset, len;
  108. const void *data;
  109. int mrdump_key_pin, *interrupts;
  110. char *rst_mode = "IRQ";
  111. if (!force_mode) {
  112. #if defined(USER_BUILD)
  113. force_mode = "EINT";
  114. #else
  115. force_mode = "SYSRST";
  116. #endif
  117. dprintf(CRITICAL, "%s: force trigger default to %s\n", __func__, force_mode);
  118. } else {
  119. dprintf(CRITICAL, "%s: force trigger set to %s\n", __func__, force_mode);
  120. }
  121. offset = fdt_node_offset_by_compatible(fdt, -1, mrdump_key_compatible);
  122. if (offset < 0) {
  123. dprintf(CRITICAL, "%s not found\n", mrdump_key_compatible);
  124. return;
  125. }
  126. data = fdt_getprop(fdt, offset, "force_mode", &len);
  127. if (data) {
  128. dprintf(CRITICAL, "%s: force_mode = %s\n", __func__, (char *)data);
  129. force_mode = (char *)data;
  130. } else {
  131. dprintf(CRITICAL, "%s: no force_mode attribute default=%s\n",
  132. __func__, force_mode);
  133. }
  134. data = fdt_getprop(fdt, offset, "mode", &len);
  135. if (data) {
  136. dprintf(CRITICAL, "%s: rst_mode = %s\n", __func__, (char *)data);
  137. rst_mode = (char *)data;
  138. } else
  139. dprintf(CRITICAL, "%s: no mode attribute default=%s\n",
  140. __func__, rst_mode);
  141. data = fdt_getprop(fdt, offset, "interrupts", &len);
  142. if (data) {
  143. dprintf(CRITICAL, "%s: interrupts = 0x%x\n", __func__, *((int *)data));
  144. interrupts = (int *)data;
  145. mrdump_key_pin = (*interrupts/0x1000000);
  146. dprintf(CRITICAL, "%s: mrdump_key_pin = EINT%d\n", __func__, mrdump_key_pin);
  147. } else {
  148. dprintf(CRITICAL, "%s: no interrupts attribute\n", __func__);
  149. mrdump_key_pin = -1;
  150. }
  151. mrdump_key_apply(force_mode, rst_mode, mrdump_key_pin);
  152. }
  153. #endif