diff options
author | John Crispin <blogic@openwrt.org> | 2016-02-19 03:44:15 -0500 |
---|---|---|
committer | Matthias Brugger <matthias.bgg@gmail.com> | 2016-04-20 07:03:06 -0400 |
commit | 060a1d6461ebed23463262365fe41556e8a5cfc7 (patch) | |
tree | 1c086b0fb03eda21579bc7f44bdea4978de607d6 | |
parent | 5ae48040aa479e9bb4f2e4630867725edca1a1c3 (diff) |
soc: mediatek: PMIC wrap: add MT2701/7623 support
Add the registers, callbacks and data structures required to make the
wrapper work on MT2701 and MT7623.
Signed-off-by: John Crispin <blogic@openwrt.org>
Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
-rw-r--r-- | drivers/soc/mediatek/mtk-pmic-wrap.c | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c index 0e4ebb84ee7f..3c3e56df526e 100644 --- a/drivers/soc/mediatek/mtk-pmic-wrap.c +++ b/drivers/soc/mediatek/mtk-pmic-wrap.c | |||
@@ -52,6 +52,7 @@ | |||
52 | #define PWRAP_DEW_WRITE_TEST_VAL 0xa55a | 52 | #define PWRAP_DEW_WRITE_TEST_VAL 0xa55a |
53 | 53 | ||
54 | /* macro for manual command */ | 54 | /* macro for manual command */ |
55 | #define PWRAP_MAN_CMD_SPI_WRITE_NEW (1 << 14) | ||
55 | #define PWRAP_MAN_CMD_SPI_WRITE (1 << 13) | 56 | #define PWRAP_MAN_CMD_SPI_WRITE (1 << 13) |
56 | #define PWRAP_MAN_CMD_OP_CSH (0x0 << 8) | 57 | #define PWRAP_MAN_CMD_OP_CSH (0x0 << 8) |
57 | #define PWRAP_MAN_CMD_OP_CSL (0x1 << 8) | 58 | #define PWRAP_MAN_CMD_OP_CSL (0x1 << 8) |
@@ -200,6 +201,13 @@ enum pwrap_regs { | |||
200 | PWRAP_DCM_EN, | 201 | PWRAP_DCM_EN, |
201 | PWRAP_DCM_DBC_PRD, | 202 | PWRAP_DCM_DBC_PRD, |
202 | 203 | ||
204 | /* MT2701 only regs */ | ||
205 | PWRAP_ADC_CMD_ADDR, | ||
206 | PWRAP_PWRAP_ADC_CMD, | ||
207 | PWRAP_ADC_RDY_ADDR, | ||
208 | PWRAP_ADC_RDATA_ADDR1, | ||
209 | PWRAP_ADC_RDATA_ADDR2, | ||
210 | |||
203 | /* MT8135 only regs */ | 211 | /* MT8135 only regs */ |
204 | PWRAP_CSHEXT, | 212 | PWRAP_CSHEXT, |
205 | PWRAP_EVENT_IN_EN, | 213 | PWRAP_EVENT_IN_EN, |
@@ -236,6 +244,92 @@ enum pwrap_regs { | |||
236 | PWRAP_CIPHER_EN, | 244 | PWRAP_CIPHER_EN, |
237 | }; | 245 | }; |
238 | 246 | ||
247 | static int mt2701_regs[] = { | ||
248 | [PWRAP_MUX_SEL] = 0x0, | ||
249 | [PWRAP_WRAP_EN] = 0x4, | ||
250 | [PWRAP_DIO_EN] = 0x8, | ||
251 | [PWRAP_SIDLY] = 0xc, | ||
252 | [PWRAP_RDDMY] = 0x18, | ||
253 | [PWRAP_SI_CK_CON] = 0x1c, | ||
254 | [PWRAP_CSHEXT_WRITE] = 0x20, | ||
255 | [PWRAP_CSHEXT_READ] = 0x24, | ||
256 | [PWRAP_CSLEXT_START] = 0x28, | ||
257 | [PWRAP_CSLEXT_END] = 0x2c, | ||
258 | [PWRAP_STAUPD_PRD] = 0x30, | ||
259 | [PWRAP_STAUPD_GRPEN] = 0x34, | ||
260 | [PWRAP_STAUPD_MAN_TRIG] = 0x38, | ||
261 | [PWRAP_STAUPD_STA] = 0x3c, | ||
262 | [PWRAP_WRAP_STA] = 0x44, | ||
263 | [PWRAP_HARB_INIT] = 0x48, | ||
264 | [PWRAP_HARB_HPRIO] = 0x4c, | ||
265 | [PWRAP_HIPRIO_ARB_EN] = 0x50, | ||
266 | [PWRAP_HARB_STA0] = 0x54, | ||
267 | [PWRAP_HARB_STA1] = 0x58, | ||
268 | [PWRAP_MAN_EN] = 0x5c, | ||
269 | [PWRAP_MAN_CMD] = 0x60, | ||
270 | [PWRAP_MAN_RDATA] = 0x64, | ||
271 | [PWRAP_MAN_VLDCLR] = 0x68, | ||
272 | [PWRAP_WACS0_EN] = 0x6c, | ||
273 | [PWRAP_INIT_DONE0] = 0x70, | ||
274 | [PWRAP_WACS0_CMD] = 0x74, | ||
275 | [PWRAP_WACS0_RDATA] = 0x78, | ||
276 | [PWRAP_WACS0_VLDCLR] = 0x7c, | ||
277 | [PWRAP_WACS1_EN] = 0x80, | ||
278 | [PWRAP_INIT_DONE1] = 0x84, | ||
279 | [PWRAP_WACS1_CMD] = 0x88, | ||
280 | [PWRAP_WACS1_RDATA] = 0x8c, | ||
281 | [PWRAP_WACS1_VLDCLR] = 0x90, | ||
282 | [PWRAP_WACS2_EN] = 0x94, | ||
283 | [PWRAP_INIT_DONE2] = 0x98, | ||
284 | [PWRAP_WACS2_CMD] = 0x9c, | ||
285 | [PWRAP_WACS2_RDATA] = 0xa0, | ||
286 | [PWRAP_WACS2_VLDCLR] = 0xa4, | ||
287 | [PWRAP_INT_EN] = 0xa8, | ||
288 | [PWRAP_INT_FLG_RAW] = 0xac, | ||
289 | [PWRAP_INT_FLG] = 0xb0, | ||
290 | [PWRAP_INT_CLR] = 0xb4, | ||
291 | [PWRAP_SIG_ADR] = 0xb8, | ||
292 | [PWRAP_SIG_MODE] = 0xbc, | ||
293 | [PWRAP_SIG_VALUE] = 0xc0, | ||
294 | [PWRAP_SIG_ERRVAL] = 0xc4, | ||
295 | [PWRAP_CRC_EN] = 0xc8, | ||
296 | [PWRAP_TIMER_EN] = 0xcc, | ||
297 | [PWRAP_TIMER_STA] = 0xd0, | ||
298 | [PWRAP_WDT_UNIT] = 0xd4, | ||
299 | [PWRAP_WDT_SRC_EN] = 0xd8, | ||
300 | [PWRAP_WDT_FLG] = 0xdc, | ||
301 | [PWRAP_DEBUG_INT_SEL] = 0xe0, | ||
302 | [PWRAP_DVFS_ADR0] = 0xe4, | ||
303 | [PWRAP_DVFS_WDATA0] = 0xe8, | ||
304 | [PWRAP_DVFS_ADR1] = 0xec, | ||
305 | [PWRAP_DVFS_WDATA1] = 0xf0, | ||
306 | [PWRAP_DVFS_ADR2] = 0xf4, | ||
307 | [PWRAP_DVFS_WDATA2] = 0xf8, | ||
308 | [PWRAP_DVFS_ADR3] = 0xfc, | ||
309 | [PWRAP_DVFS_WDATA3] = 0x100, | ||
310 | [PWRAP_DVFS_ADR4] = 0x104, | ||
311 | [PWRAP_DVFS_WDATA4] = 0x108, | ||
312 | [PWRAP_DVFS_ADR5] = 0x10c, | ||
313 | [PWRAP_DVFS_WDATA5] = 0x110, | ||
314 | [PWRAP_DVFS_ADR6] = 0x114, | ||
315 | [PWRAP_DVFS_WDATA6] = 0x118, | ||
316 | [PWRAP_DVFS_ADR7] = 0x11c, | ||
317 | [PWRAP_DVFS_WDATA7] = 0x120, | ||
318 | [PWRAP_CIPHER_KEY_SEL] = 0x124, | ||
319 | [PWRAP_CIPHER_IV_SEL] = 0x128, | ||
320 | [PWRAP_CIPHER_EN] = 0x12c, | ||
321 | [PWRAP_CIPHER_RDY] = 0x130, | ||
322 | [PWRAP_CIPHER_MODE] = 0x134, | ||
323 | [PWRAP_CIPHER_SWRST] = 0x138, | ||
324 | [PWRAP_DCM_EN] = 0x13c, | ||
325 | [PWRAP_DCM_DBC_PRD] = 0x140, | ||
326 | [PWRAP_ADC_CMD_ADDR] = 0x144, | ||
327 | [PWRAP_PWRAP_ADC_CMD] = 0x148, | ||
328 | [PWRAP_ADC_RDY_ADDR] = 0x14c, | ||
329 | [PWRAP_ADC_RDATA_ADDR1] = 0x150, | ||
330 | [PWRAP_ADC_RDATA_ADDR2] = 0x154, | ||
331 | }; | ||
332 | |||
239 | static int mt8173_regs[] = { | 333 | static int mt8173_regs[] = { |
240 | [PWRAP_MUX_SEL] = 0x0, | 334 | [PWRAP_MUX_SEL] = 0x0, |
241 | [PWRAP_WRAP_EN] = 0x4, | 335 | [PWRAP_WRAP_EN] = 0x4, |
@@ -397,6 +491,7 @@ enum pmic_type { | |||
397 | }; | 491 | }; |
398 | 492 | ||
399 | enum pwrap_type { | 493 | enum pwrap_type { |
494 | PWRAP_MT2701, | ||
400 | PWRAP_MT8135, | 495 | PWRAP_MT8135, |
401 | PWRAP_MT8173, | 496 | PWRAP_MT8173, |
402 | }; | 497 | }; |
@@ -637,6 +732,31 @@ static int pwrap_mt8173_init_reg_clock(struct pmic_wrapper *wrp) | |||
637 | return 0; | 732 | return 0; |
638 | } | 733 | } |
639 | 734 | ||
735 | static int pwrap_mt2701_init_reg_clock(struct pmic_wrapper *wrp) | ||
736 | { | ||
737 | switch (wrp->slave->type) { | ||
738 | case PMIC_MT6397: | ||
739 | pwrap_writel(wrp, 0xc, PWRAP_RDDMY); | ||
740 | pwrap_writel(wrp, 0x4, PWRAP_CSHEXT_WRITE); | ||
741 | pwrap_writel(wrp, 0x0, PWRAP_CSHEXT_READ); | ||
742 | pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_START); | ||
743 | pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_END); | ||
744 | break; | ||
745 | |||
746 | case PMIC_MT6323: | ||
747 | pwrap_writel(wrp, 0x8, PWRAP_RDDMY); | ||
748 | pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_RDDMY_NO], | ||
749 | 0x8); | ||
750 | pwrap_writel(wrp, 0x5, PWRAP_CSHEXT_WRITE); | ||
751 | pwrap_writel(wrp, 0x0, PWRAP_CSHEXT_READ); | ||
752 | pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_START); | ||
753 | pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_END); | ||
754 | break; | ||
755 | } | ||
756 | |||
757 | return 0; | ||
758 | } | ||
759 | |||
640 | static bool pwrap_is_cipher_ready(struct pmic_wrapper *wrp) | 760 | static bool pwrap_is_cipher_ready(struct pmic_wrapper *wrp) |
641 | { | 761 | { |
642 | return pwrap_readl(wrp, PWRAP_CIPHER_RDY) & 1; | 762 | return pwrap_readl(wrp, PWRAP_CIPHER_RDY) & 1; |
@@ -670,6 +790,7 @@ static int pwrap_init_cipher(struct pmic_wrapper *wrp) | |||
670 | pwrap_writel(wrp, 1, PWRAP_CIPHER_LOAD); | 790 | pwrap_writel(wrp, 1, PWRAP_CIPHER_LOAD); |
671 | pwrap_writel(wrp, 1, PWRAP_CIPHER_START); | 791 | pwrap_writel(wrp, 1, PWRAP_CIPHER_START); |
672 | break; | 792 | break; |
793 | case PWRAP_MT2701: | ||
673 | case PWRAP_MT8173: | 794 | case PWRAP_MT8173: |
674 | pwrap_writel(wrp, 1, PWRAP_CIPHER_EN); | 795 | pwrap_writel(wrp, 1, PWRAP_CIPHER_EN); |
675 | break; | 796 | break; |
@@ -772,6 +893,24 @@ static int pwrap_mt8173_init_soc_specific(struct pmic_wrapper *wrp) | |||
772 | return 0; | 893 | return 0; |
773 | } | 894 | } |
774 | 895 | ||
896 | static int pwrap_mt2701_init_soc_specific(struct pmic_wrapper *wrp) | ||
897 | { | ||
898 | /* GPS_INTF initialization */ | ||
899 | switch (wrp->slave->type) { | ||
900 | case PMIC_MT6323: | ||
901 | pwrap_writel(wrp, 0x076c, PWRAP_ADC_CMD_ADDR); | ||
902 | pwrap_writel(wrp, 0x8000, PWRAP_PWRAP_ADC_CMD); | ||
903 | pwrap_writel(wrp, 0x072c, PWRAP_ADC_RDY_ADDR); | ||
904 | pwrap_writel(wrp, 0x072e, PWRAP_ADC_RDATA_ADDR1); | ||
905 | pwrap_writel(wrp, 0x0730, PWRAP_ADC_RDATA_ADDR2); | ||
906 | break; | ||
907 | default: | ||
908 | break; | ||
909 | } | ||
910 | |||
911 | return 0; | ||
912 | } | ||
913 | |||
775 | static int pwrap_init(struct pmic_wrapper *wrp) | 914 | static int pwrap_init(struct pmic_wrapper *wrp) |
776 | { | 915 | { |
777 | int ret; | 916 | int ret; |
@@ -916,6 +1055,18 @@ static const struct of_device_id of_slave_match_tbl[] = { | |||
916 | }; | 1055 | }; |
917 | MODULE_DEVICE_TABLE(of, of_slave_match_tbl); | 1056 | MODULE_DEVICE_TABLE(of, of_slave_match_tbl); |
918 | 1057 | ||
1058 | static const struct pmic_wrapper_type pwrap_mt2701 = { | ||
1059 | .regs = mt2701_regs, | ||
1060 | .type = PWRAP_MT2701, | ||
1061 | .arb_en_all = 0x3f, | ||
1062 | .int_en_all = ~(BIT(31) | BIT(2)), | ||
1063 | .spi_w = PWRAP_MAN_CMD_SPI_WRITE_NEW, | ||
1064 | .wdt_src = PWRAP_WDT_SRC_MASK_ALL, | ||
1065 | .has_bridge = 0, | ||
1066 | .init_reg_clock = pwrap_mt2701_init_reg_clock, | ||
1067 | .init_soc_specific = pwrap_mt2701_init_soc_specific, | ||
1068 | }; | ||
1069 | |||
919 | static struct pmic_wrapper_type pwrap_mt8135 = { | 1070 | static struct pmic_wrapper_type pwrap_mt8135 = { |
920 | .regs = mt8135_regs, | 1071 | .regs = mt8135_regs, |
921 | .type = PWRAP_MT8135, | 1072 | .type = PWRAP_MT8135, |
@@ -942,6 +1093,9 @@ static struct pmic_wrapper_type pwrap_mt8173 = { | |||
942 | 1093 | ||
943 | static struct of_device_id of_pwrap_match_tbl[] = { | 1094 | static struct of_device_id of_pwrap_match_tbl[] = { |
944 | { | 1095 | { |
1096 | .compatible = "mediatek,mt2701-pwrap", | ||
1097 | .data = &pwrap_mt2701, | ||
1098 | }, { | ||
945 | .compatible = "mediatek,mt8135-pwrap", | 1099 | .compatible = "mediatek,mt8135-pwrap", |
946 | .data = &pwrap_mt8135, | 1100 | .data = &pwrap_mt8135, |
947 | }, { | 1101 | }, { |