aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2016-02-19 03:44:08 -0500
committerMatthias Brugger <matthias.bgg@gmail.com>2016-04-20 07:03:01 -0400
commit41c11f32d86ac1b64c78b827f977432df4934147 (patch)
tree5878cd0c1a0e1715bcaec8246da706b0fdb9fa64
parenta397845338af260658f55b2ba73834940244cf6d (diff)
soc: mediatek: PMIC wrap: split SoC specific init into callback
This patch moves the SoC specific wrapper init code into separate callback to avoid pwrap_init() getting too large. This is done by adding a new element called init_special to pmic_wrapper_type. Each currently supported SoC gets its own version of the callback and we copy the code that was previously inside pwrap_init() to these new callbacks. Finally we point the 2 instances of pmic_wrapper_type at the 2 new functions. 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.c67
1 files changed, 42 insertions, 25 deletions
diff --git a/drivers/soc/mediatek/mtk-pmic-wrap.c b/drivers/soc/mediatek/mtk-pmic-wrap.c
index b22b664b155b..22c89e96a731 100644
--- a/drivers/soc/mediatek/mtk-pmic-wrap.c
+++ b/drivers/soc/mediatek/mtk-pmic-wrap.c
@@ -372,6 +372,7 @@ struct pmic_wrapper_type {
372 enum pwrap_type type; 372 enum pwrap_type type;
373 u32 arb_en_all; 373 u32 arb_en_all;
374 int (*init_reg_clock)(struct pmic_wrapper *wrp); 374 int (*init_reg_clock)(struct pmic_wrapper *wrp);
375 int (*init_soc_specific)(struct pmic_wrapper *wrp);
375}; 376};
376 377
377static inline int pwrap_is_mt8135(struct pmic_wrapper *wrp) 378static inline int pwrap_is_mt8135(struct pmic_wrapper *wrp)
@@ -665,6 +666,41 @@ static int pwrap_init_cipher(struct pmic_wrapper *wrp)
665 return 0; 666 return 0;
666} 667}
667 668
669static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
670{
671 /* enable pwrap events and pwrap bridge in AP side */
672 pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN);
673 pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN);
674 writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
675 writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
676 writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
677 writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
678 writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
679 writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
680 writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
681
682 /* enable PMIC event out and sources */
683 if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
684 pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
685 dev_err(wrp->dev, "enable dewrap fail\n");
686 return -EFAULT;
687 }
688
689 return 0;
690}
691
692static int pwrap_mt8173_init_soc_specific(struct pmic_wrapper *wrp)
693{
694 /* PMIC_DEWRAP enables */
695 if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
696 pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
697 dev_err(wrp->dev, "enable dewrap fail\n");
698 return -EFAULT;
699 }
700
701 return 0;
702}
703
668static int pwrap_init(struct pmic_wrapper *wrp) 704static int pwrap_init(struct pmic_wrapper *wrp)
669{ 705{
670 int ret; 706 int ret;
@@ -743,31 +779,10 @@ static int pwrap_init(struct pmic_wrapper *wrp)
743 pwrap_writel(wrp, 0x5, PWRAP_STAUPD_PRD); 779 pwrap_writel(wrp, 0x5, PWRAP_STAUPD_PRD);
744 pwrap_writel(wrp, 0xff, PWRAP_STAUPD_GRPEN); 780 pwrap_writel(wrp, 0xff, PWRAP_STAUPD_GRPEN);
745 781
746 if (pwrap_is_mt8135(wrp)) { 782 if (wrp->master->init_soc_specific) {
747 /* enable pwrap events and pwrap bridge in AP side */ 783 ret = wrp->master->init_soc_specific(wrp);
748 pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN); 784 if (ret)
749 pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN); 785 return ret;
750 writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
751 writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
752 writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
753 writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
754 writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
755 writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
756 writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
757
758 /* enable PMIC event out and sources */
759 if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
760 pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
761 dev_err(wrp->dev, "enable dewrap fail\n");
762 return -EFAULT;
763 }
764 } else {
765 /* PMIC_DEWRAP enables */
766 if (pwrap_write(wrp, PWRAP_DEW_EVENT_OUT_EN, 0x1) ||
767 pwrap_write(wrp, PWRAP_DEW_EVENT_SRC_EN, 0xffff)) {
768 dev_err(wrp->dev, "enable dewrap fail\n");
769 return -EFAULT;
770 }
771 } 786 }
772 787
773 /* Setup the init done registers */ 788 /* Setup the init done registers */
@@ -811,6 +826,7 @@ static struct pmic_wrapper_type pwrap_mt8135 = {
811 .type = PWRAP_MT8135, 826 .type = PWRAP_MT8135,
812 .arb_en_all = 0x1ff, 827 .arb_en_all = 0x1ff,
813 .init_reg_clock = pwrap_mt8135_init_reg_clock, 828 .init_reg_clock = pwrap_mt8135_init_reg_clock,
829 .init_soc_specific = pwrap_mt8135_init_soc_specific,
814}; 830};
815 831
816static struct pmic_wrapper_type pwrap_mt8173 = { 832static struct pmic_wrapper_type pwrap_mt8173 = {
@@ -818,6 +834,7 @@ static struct pmic_wrapper_type pwrap_mt8173 = {
818 .type = PWRAP_MT8173, 834 .type = PWRAP_MT8173,
819 .arb_en_all = 0x3f, 835 .arb_en_all = 0x3f,
820 .init_reg_clock = pwrap_mt8173_init_reg_clock, 836 .init_reg_clock = pwrap_mt8173_init_reg_clock,
837 .init_soc_specific = pwrap_mt8173_init_soc_specific,
821}; 838};
822 839
823static struct of_device_id of_pwrap_match_tbl[] = { 840static struct of_device_id of_pwrap_match_tbl[] = {