0041-soc-mediatek-PMIC-wrap-add-MT2701-7623-support.patch 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. From 7736d97fe2c6c71c9009a1b45a94de06bfc94a37 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Wed, 20 Jan 2016 12:09:14 +0100
  4. Subject: [PATCH 041/102] soc: mediatek: PMIC wrap: add MT2701/7623 support
  5. Add the registers, callbacks and data structures required to make the
  6. wrapper work on MT2701 and MT7623.
  7. Signed-off-by: John Crispin <blogic@openwrt.org>
  8. ---
  9. drivers/soc/mediatek/mtk-pmic-wrap.c | 154 ++++++++++++++++++++++++++++++++++
  10. 1 file changed, 154 insertions(+)
  11. --- a/drivers/soc/mediatek/mtk-pmic-wrap.c
  12. +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
  13. @@ -52,6 +52,7 @@
  14. #define PWRAP_DEW_WRITE_TEST_VAL 0xa55a
  15. /* macro for manual command */
  16. +#define PWRAP_MAN_CMD_SPI_WRITE_NEW (1 << 14)
  17. #define PWRAP_MAN_CMD_SPI_WRITE (1 << 13)
  18. #define PWRAP_MAN_CMD_OP_CSH (0x0 << 8)
  19. #define PWRAP_MAN_CMD_OP_CSL (0x1 << 8)
  20. @@ -200,6 +201,13 @@ enum pwrap_regs {
  21. PWRAP_DCM_EN,
  22. PWRAP_DCM_DBC_PRD,
  23. + /* MT2701 only regs */
  24. + PWRAP_ADC_CMD_ADDR,
  25. + PWRAP_PWRAP_ADC_CMD,
  26. + PWRAP_ADC_RDY_ADDR,
  27. + PWRAP_ADC_RDATA_ADDR1,
  28. + PWRAP_ADC_RDATA_ADDR2,
  29. +
  30. /* MT8135 only regs */
  31. PWRAP_CSHEXT,
  32. PWRAP_EVENT_IN_EN,
  33. @@ -236,6 +244,92 @@ enum pwrap_regs {
  34. PWRAP_CIPHER_EN,
  35. };
  36. +static int mt2701_regs[] = {
  37. + [PWRAP_MUX_SEL] = 0x0,
  38. + [PWRAP_WRAP_EN] = 0x4,
  39. + [PWRAP_DIO_EN] = 0x8,
  40. + [PWRAP_SIDLY] = 0xc,
  41. + [PWRAP_RDDMY] = 0x18,
  42. + [PWRAP_SI_CK_CON] = 0x1c,
  43. + [PWRAP_CSHEXT_WRITE] = 0x20,
  44. + [PWRAP_CSHEXT_READ] = 0x24,
  45. + [PWRAP_CSLEXT_START] = 0x28,
  46. + [PWRAP_CSLEXT_END] = 0x2c,
  47. + [PWRAP_STAUPD_PRD] = 0x30,
  48. + [PWRAP_STAUPD_GRPEN] = 0x34,
  49. + [PWRAP_STAUPD_MAN_TRIG] = 0x38,
  50. + [PWRAP_STAUPD_STA] = 0x3c,
  51. + [PWRAP_WRAP_STA] = 0x44,
  52. + [PWRAP_HARB_INIT] = 0x48,
  53. + [PWRAP_HARB_HPRIO] = 0x4c,
  54. + [PWRAP_HIPRIO_ARB_EN] = 0x50,
  55. + [PWRAP_HARB_STA0] = 0x54,
  56. + [PWRAP_HARB_STA1] = 0x58,
  57. + [PWRAP_MAN_EN] = 0x5c,
  58. + [PWRAP_MAN_CMD] = 0x60,
  59. + [PWRAP_MAN_RDATA] = 0x64,
  60. + [PWRAP_MAN_VLDCLR] = 0x68,
  61. + [PWRAP_WACS0_EN] = 0x6c,
  62. + [PWRAP_INIT_DONE0] = 0x70,
  63. + [PWRAP_WACS0_CMD] = 0x74,
  64. + [PWRAP_WACS0_RDATA] = 0x78,
  65. + [PWRAP_WACS0_VLDCLR] = 0x7c,
  66. + [PWRAP_WACS1_EN] = 0x80,
  67. + [PWRAP_INIT_DONE1] = 0x84,
  68. + [PWRAP_WACS1_CMD] = 0x88,
  69. + [PWRAP_WACS1_RDATA] = 0x8c,
  70. + [PWRAP_WACS1_VLDCLR] = 0x90,
  71. + [PWRAP_WACS2_EN] = 0x94,
  72. + [PWRAP_INIT_DONE2] = 0x98,
  73. + [PWRAP_WACS2_CMD] = 0x9c,
  74. + [PWRAP_WACS2_RDATA] = 0xa0,
  75. + [PWRAP_WACS2_VLDCLR] = 0xa4,
  76. + [PWRAP_INT_EN] = 0xa8,
  77. + [PWRAP_INT_FLG_RAW] = 0xac,
  78. + [PWRAP_INT_FLG] = 0xb0,
  79. + [PWRAP_INT_CLR] = 0xb4,
  80. + [PWRAP_SIG_ADR] = 0xb8,
  81. + [PWRAP_SIG_MODE] = 0xbc,
  82. + [PWRAP_SIG_VALUE] = 0xc0,
  83. + [PWRAP_SIG_ERRVAL] = 0xc4,
  84. + [PWRAP_CRC_EN] = 0xc8,
  85. + [PWRAP_TIMER_EN] = 0xcc,
  86. + [PWRAP_TIMER_STA] = 0xd0,
  87. + [PWRAP_WDT_UNIT] = 0xd4,
  88. + [PWRAP_WDT_SRC_EN] = 0xd8,
  89. + [PWRAP_WDT_FLG] = 0xdc,
  90. + [PWRAP_DEBUG_INT_SEL] = 0xe0,
  91. + [PWRAP_DVFS_ADR0] = 0xe4,
  92. + [PWRAP_DVFS_WDATA0] = 0xe8,
  93. + [PWRAP_DVFS_ADR1] = 0xec,
  94. + [PWRAP_DVFS_WDATA1] = 0xf0,
  95. + [PWRAP_DVFS_ADR2] = 0xf4,
  96. + [PWRAP_DVFS_WDATA2] = 0xf8,
  97. + [PWRAP_DVFS_ADR3] = 0xfc,
  98. + [PWRAP_DVFS_WDATA3] = 0x100,
  99. + [PWRAP_DVFS_ADR4] = 0x104,
  100. + [PWRAP_DVFS_WDATA4] = 0x108,
  101. + [PWRAP_DVFS_ADR5] = 0x10c,
  102. + [PWRAP_DVFS_WDATA5] = 0x110,
  103. + [PWRAP_DVFS_ADR6] = 0x114,
  104. + [PWRAP_DVFS_WDATA6] = 0x118,
  105. + [PWRAP_DVFS_ADR7] = 0x11c,
  106. + [PWRAP_DVFS_WDATA7] = 0x120,
  107. + [PWRAP_CIPHER_KEY_SEL] = 0x124,
  108. + [PWRAP_CIPHER_IV_SEL] = 0x128,
  109. + [PWRAP_CIPHER_EN] = 0x12c,
  110. + [PWRAP_CIPHER_RDY] = 0x130,
  111. + [PWRAP_CIPHER_MODE] = 0x134,
  112. + [PWRAP_CIPHER_SWRST] = 0x138,
  113. + [PWRAP_DCM_EN] = 0x13c,
  114. + [PWRAP_DCM_DBC_PRD] = 0x140,
  115. + [PWRAP_ADC_CMD_ADDR] = 0x144,
  116. + [PWRAP_PWRAP_ADC_CMD] = 0x148,
  117. + [PWRAP_ADC_RDY_ADDR] = 0x14c,
  118. + [PWRAP_ADC_RDATA_ADDR1] = 0x150,
  119. + [PWRAP_ADC_RDATA_ADDR2] = 0x154,
  120. +};
  121. +
  122. static int mt8173_regs[] = {
  123. [PWRAP_MUX_SEL] = 0x0,
  124. [PWRAP_WRAP_EN] = 0x4,
  125. @@ -397,6 +491,7 @@ enum pmic_type {
  126. };
  127. enum pwrap_type {
  128. + PWRAP_MT2701,
  129. PWRAP_MT8135,
  130. PWRAP_MT8173,
  131. };
  132. @@ -637,6 +732,31 @@ static int pwrap_mt8173_init_reg_clock(s
  133. return 0;
  134. }
  135. +static int pwrap_mt2701_init_reg_clock(struct pmic_wrapper *wrp)
  136. +{
  137. + switch (wrp->slave->type) {
  138. + case PMIC_MT6397:
  139. + pwrap_writel(wrp, 0xc, PWRAP_RDDMY);
  140. + pwrap_writel(wrp, 0x4, PWRAP_CSHEXT_WRITE);
  141. + pwrap_writel(wrp, 0x0, PWRAP_CSHEXT_READ);
  142. + pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_START);
  143. + pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_END);
  144. + break;
  145. +
  146. + case PMIC_MT6323:
  147. + pwrap_writel(wrp, 0x8, PWRAP_RDDMY);
  148. + pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_RDDMY_NO],
  149. + 0x8);
  150. + pwrap_writel(wrp, 0x5, PWRAP_CSHEXT_WRITE);
  151. + pwrap_writel(wrp, 0x0, PWRAP_CSHEXT_READ);
  152. + pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_START);
  153. + pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_END);
  154. + break;
  155. + }
  156. +
  157. + return 0;
  158. +}
  159. +
  160. static bool pwrap_is_cipher_ready(struct pmic_wrapper *wrp)
  161. {
  162. return pwrap_readl(wrp, PWRAP_CIPHER_RDY) & 1;
  163. @@ -670,6 +790,7 @@ static int pwrap_init_cipher(struct pmic
  164. pwrap_writel(wrp, 1, PWRAP_CIPHER_LOAD);
  165. pwrap_writel(wrp, 1, PWRAP_CIPHER_START);
  166. break;
  167. + case PWRAP_MT2701:
  168. case PWRAP_MT8173:
  169. pwrap_writel(wrp, 1, PWRAP_CIPHER_EN);
  170. break;
  171. @@ -772,6 +893,24 @@ static int pwrap_mt8173_init_soc_specifi
  172. return 0;
  173. }
  174. +static int pwrap_mt2701_init_soc_specific(struct pmic_wrapper *wrp)
  175. +{
  176. + /* GPS_INTF initialization */
  177. + switch (wrp->slave->type) {
  178. + case PMIC_MT6323:
  179. + pwrap_writel(wrp, 0x076c, PWRAP_ADC_CMD_ADDR);
  180. + pwrap_writel(wrp, 0x8000, PWRAP_PWRAP_ADC_CMD);
  181. + pwrap_writel(wrp, 0x072c, PWRAP_ADC_RDY_ADDR);
  182. + pwrap_writel(wrp, 0x072e, PWRAP_ADC_RDATA_ADDR1);
  183. + pwrap_writel(wrp, 0x0730, PWRAP_ADC_RDATA_ADDR2);
  184. + break;
  185. + default:
  186. + break;
  187. + }
  188. +
  189. + return 0;
  190. +}
  191. +
  192. static int pwrap_init(struct pmic_wrapper *wrp)
  193. {
  194. int ret;
  195. @@ -916,6 +1055,18 @@ static const struct of_device_id of_slav
  196. };
  197. MODULE_DEVICE_TABLE(of, of_slave_match_tbl);
  198. +static const struct pmic_wrapper_type pwrap_mt2701 = {
  199. + .regs = mt2701_regs,
  200. + .type = PWRAP_MT2701,
  201. + .arb_en_all = 0x3f,
  202. + .int_en_all = ~(BIT(31) | BIT(2)),
  203. + .spi_w = PWRAP_MAN_CMD_SPI_WRITE_NEW,
  204. + .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
  205. + .has_bridge = 0,
  206. + .init_reg_clock = pwrap_mt2701_init_reg_clock,
  207. + .init_soc_specific = pwrap_mt2701_init_soc_specific,
  208. +};
  209. +
  210. static struct pmic_wrapper_type pwrap_mt8135 = {
  211. .regs = mt8135_regs,
  212. .type = PWRAP_MT8135,
  213. @@ -942,6 +1093,9 @@ static struct pmic_wrapper_type pwrap_mt
  214. static struct of_device_id of_pwrap_match_tbl[] = {
  215. {
  216. + .compatible = "mediatek,mt2701-pwrap",
  217. + .data = &pwrap_mt2701,
  218. + }, {
  219. .compatible = "mediatek,mt8135-pwrap",
  220. .data = &pwrap_mt8135,
  221. }, {