Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

John Crispin and committed by
Matthias Brugger
060a1d64 5ae48040

+154
+154
drivers/soc/mediatek/mtk-pmic-wrap.c
··· 52 52 #define PWRAP_DEW_WRITE_TEST_VAL 0xa55a 53 53 54 54 /* macro for manual command */ 55 + #define PWRAP_MAN_CMD_SPI_WRITE_NEW (1 << 14) 55 56 #define PWRAP_MAN_CMD_SPI_WRITE (1 << 13) 56 57 #define PWRAP_MAN_CMD_OP_CSH (0x0 << 8) 57 58 #define PWRAP_MAN_CMD_OP_CSL (0x1 << 8) ··· 201 200 PWRAP_DCM_EN, 202 201 PWRAP_DCM_DBC_PRD, 203 202 203 + /* MT2701 only regs */ 204 + PWRAP_ADC_CMD_ADDR, 205 + PWRAP_PWRAP_ADC_CMD, 206 + PWRAP_ADC_RDY_ADDR, 207 + PWRAP_ADC_RDATA_ADDR1, 208 + PWRAP_ADC_RDATA_ADDR2, 209 + 204 210 /* MT8135 only regs */ 205 211 PWRAP_CSHEXT, 206 212 PWRAP_EVENT_IN_EN, ··· 242 234 PWRAP_DVFS_WDATA7, 243 235 PWRAP_SPMINF_STA, 244 236 PWRAP_CIPHER_EN, 237 + }; 238 + 239 + static int mt2701_regs[] = { 240 + [PWRAP_MUX_SEL] = 0x0, 241 + [PWRAP_WRAP_EN] = 0x4, 242 + [PWRAP_DIO_EN] = 0x8, 243 + [PWRAP_SIDLY] = 0xc, 244 + [PWRAP_RDDMY] = 0x18, 245 + [PWRAP_SI_CK_CON] = 0x1c, 246 + [PWRAP_CSHEXT_WRITE] = 0x20, 247 + [PWRAP_CSHEXT_READ] = 0x24, 248 + [PWRAP_CSLEXT_START] = 0x28, 249 + [PWRAP_CSLEXT_END] = 0x2c, 250 + [PWRAP_STAUPD_PRD] = 0x30, 251 + [PWRAP_STAUPD_GRPEN] = 0x34, 252 + [PWRAP_STAUPD_MAN_TRIG] = 0x38, 253 + [PWRAP_STAUPD_STA] = 0x3c, 254 + [PWRAP_WRAP_STA] = 0x44, 255 + [PWRAP_HARB_INIT] = 0x48, 256 + [PWRAP_HARB_HPRIO] = 0x4c, 257 + [PWRAP_HIPRIO_ARB_EN] = 0x50, 258 + [PWRAP_HARB_STA0] = 0x54, 259 + [PWRAP_HARB_STA1] = 0x58, 260 + [PWRAP_MAN_EN] = 0x5c, 261 + [PWRAP_MAN_CMD] = 0x60, 262 + [PWRAP_MAN_RDATA] = 0x64, 263 + [PWRAP_MAN_VLDCLR] = 0x68, 264 + [PWRAP_WACS0_EN] = 0x6c, 265 + [PWRAP_INIT_DONE0] = 0x70, 266 + [PWRAP_WACS0_CMD] = 0x74, 267 + [PWRAP_WACS0_RDATA] = 0x78, 268 + [PWRAP_WACS0_VLDCLR] = 0x7c, 269 + [PWRAP_WACS1_EN] = 0x80, 270 + [PWRAP_INIT_DONE1] = 0x84, 271 + [PWRAP_WACS1_CMD] = 0x88, 272 + [PWRAP_WACS1_RDATA] = 0x8c, 273 + [PWRAP_WACS1_VLDCLR] = 0x90, 274 + [PWRAP_WACS2_EN] = 0x94, 275 + [PWRAP_INIT_DONE2] = 0x98, 276 + [PWRAP_WACS2_CMD] = 0x9c, 277 + [PWRAP_WACS2_RDATA] = 0xa0, 278 + [PWRAP_WACS2_VLDCLR] = 0xa4, 279 + [PWRAP_INT_EN] = 0xa8, 280 + [PWRAP_INT_FLG_RAW] = 0xac, 281 + [PWRAP_INT_FLG] = 0xb0, 282 + [PWRAP_INT_CLR] = 0xb4, 283 + [PWRAP_SIG_ADR] = 0xb8, 284 + [PWRAP_SIG_MODE] = 0xbc, 285 + [PWRAP_SIG_VALUE] = 0xc0, 286 + [PWRAP_SIG_ERRVAL] = 0xc4, 287 + [PWRAP_CRC_EN] = 0xc8, 288 + [PWRAP_TIMER_EN] = 0xcc, 289 + [PWRAP_TIMER_STA] = 0xd0, 290 + [PWRAP_WDT_UNIT] = 0xd4, 291 + [PWRAP_WDT_SRC_EN] = 0xd8, 292 + [PWRAP_WDT_FLG] = 0xdc, 293 + [PWRAP_DEBUG_INT_SEL] = 0xe0, 294 + [PWRAP_DVFS_ADR0] = 0xe4, 295 + [PWRAP_DVFS_WDATA0] = 0xe8, 296 + [PWRAP_DVFS_ADR1] = 0xec, 297 + [PWRAP_DVFS_WDATA1] = 0xf0, 298 + [PWRAP_DVFS_ADR2] = 0xf4, 299 + [PWRAP_DVFS_WDATA2] = 0xf8, 300 + [PWRAP_DVFS_ADR3] = 0xfc, 301 + [PWRAP_DVFS_WDATA3] = 0x100, 302 + [PWRAP_DVFS_ADR4] = 0x104, 303 + [PWRAP_DVFS_WDATA4] = 0x108, 304 + [PWRAP_DVFS_ADR5] = 0x10c, 305 + [PWRAP_DVFS_WDATA5] = 0x110, 306 + [PWRAP_DVFS_ADR6] = 0x114, 307 + [PWRAP_DVFS_WDATA6] = 0x118, 308 + [PWRAP_DVFS_ADR7] = 0x11c, 309 + [PWRAP_DVFS_WDATA7] = 0x120, 310 + [PWRAP_CIPHER_KEY_SEL] = 0x124, 311 + [PWRAP_CIPHER_IV_SEL] = 0x128, 312 + [PWRAP_CIPHER_EN] = 0x12c, 313 + [PWRAP_CIPHER_RDY] = 0x130, 314 + [PWRAP_CIPHER_MODE] = 0x134, 315 + [PWRAP_CIPHER_SWRST] = 0x138, 316 + [PWRAP_DCM_EN] = 0x13c, 317 + [PWRAP_DCM_DBC_PRD] = 0x140, 318 + [PWRAP_ADC_CMD_ADDR] = 0x144, 319 + [PWRAP_PWRAP_ADC_CMD] = 0x148, 320 + [PWRAP_ADC_RDY_ADDR] = 0x14c, 321 + [PWRAP_ADC_RDATA_ADDR1] = 0x150, 322 + [PWRAP_ADC_RDATA_ADDR2] = 0x154, 245 323 }; 246 324 247 325 static int mt8173_regs[] = { ··· 491 397 }; 492 398 493 399 enum pwrap_type { 400 + PWRAP_MT2701, 494 401 PWRAP_MT8135, 495 402 PWRAP_MT8173, 496 403 }; ··· 732 637 return 0; 733 638 } 734 639 640 + static int pwrap_mt2701_init_reg_clock(struct pmic_wrapper *wrp) 641 + { 642 + switch (wrp->slave->type) { 643 + case PMIC_MT6397: 644 + pwrap_writel(wrp, 0xc, PWRAP_RDDMY); 645 + pwrap_writel(wrp, 0x4, PWRAP_CSHEXT_WRITE); 646 + pwrap_writel(wrp, 0x0, PWRAP_CSHEXT_READ); 647 + pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_START); 648 + pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_END); 649 + break; 650 + 651 + case PMIC_MT6323: 652 + pwrap_writel(wrp, 0x8, PWRAP_RDDMY); 653 + pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_RDDMY_NO], 654 + 0x8); 655 + pwrap_writel(wrp, 0x5, PWRAP_CSHEXT_WRITE); 656 + pwrap_writel(wrp, 0x0, PWRAP_CSHEXT_READ); 657 + pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_START); 658 + pwrap_writel(wrp, 0x2, PWRAP_CSLEXT_END); 659 + break; 660 + } 661 + 662 + return 0; 663 + } 664 + 735 665 static bool pwrap_is_cipher_ready(struct pmic_wrapper *wrp) 736 666 { 737 667 return pwrap_readl(wrp, PWRAP_CIPHER_RDY) & 1; ··· 790 670 pwrap_writel(wrp, 1, PWRAP_CIPHER_LOAD); 791 671 pwrap_writel(wrp, 1, PWRAP_CIPHER_START); 792 672 break; 673 + case PWRAP_MT2701: 793 674 case PWRAP_MT8173: 794 675 pwrap_writel(wrp, 1, PWRAP_CIPHER_EN); 795 676 break; ··· 888 767 0xffff)) { 889 768 dev_err(wrp->dev, "enable dewrap fail\n"); 890 769 return -EFAULT; 770 + } 771 + 772 + return 0; 773 + } 774 + 775 + static int pwrap_mt2701_init_soc_specific(struct pmic_wrapper *wrp) 776 + { 777 + /* GPS_INTF initialization */ 778 + switch (wrp->slave->type) { 779 + case PMIC_MT6323: 780 + pwrap_writel(wrp, 0x076c, PWRAP_ADC_CMD_ADDR); 781 + pwrap_writel(wrp, 0x8000, PWRAP_PWRAP_ADC_CMD); 782 + pwrap_writel(wrp, 0x072c, PWRAP_ADC_RDY_ADDR); 783 + pwrap_writel(wrp, 0x072e, PWRAP_ADC_RDATA_ADDR1); 784 + pwrap_writel(wrp, 0x0730, PWRAP_ADC_RDATA_ADDR2); 785 + break; 786 + default: 787 + break; 891 788 } 892 789 893 790 return 0; ··· 1055 916 }; 1056 917 MODULE_DEVICE_TABLE(of, of_slave_match_tbl); 1057 918 919 + static const struct pmic_wrapper_type pwrap_mt2701 = { 920 + .regs = mt2701_regs, 921 + .type = PWRAP_MT2701, 922 + .arb_en_all = 0x3f, 923 + .int_en_all = ~(BIT(31) | BIT(2)), 924 + .spi_w = PWRAP_MAN_CMD_SPI_WRITE_NEW, 925 + .wdt_src = PWRAP_WDT_SRC_MASK_ALL, 926 + .has_bridge = 0, 927 + .init_reg_clock = pwrap_mt2701_init_reg_clock, 928 + .init_soc_specific = pwrap_mt2701_init_soc_specific, 929 + }; 930 + 1058 931 static struct pmic_wrapper_type pwrap_mt8135 = { 1059 932 .regs = mt8135_regs, 1060 933 .type = PWRAP_MT8135, ··· 1093 942 1094 943 static struct of_device_id of_pwrap_match_tbl[] = { 1095 944 { 945 + .compatible = "mediatek,mt2701-pwrap", 946 + .data = &pwrap_mt2701, 947 + }, { 1096 948 .compatible = "mediatek,mt8135-pwrap", 1097 949 .data = &pwrap_mt8135, 1098 950 }, {