From nobody Thu Nov 14 04:52:31 2024 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A74C7EAD7; Wed, 27 Mar 2024 05:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519066; cv=none; b=PDGMCcAJy2MZaWM++1fULKJoTVnsvYHynniYhEFvwXzO2wEOyTZ7f12dPvUS86+KZRnxQH/mCCVeso40U4TzpX7yKqt+UbLj7oI3hmplWvxtMuby/PK9opnAR/gAjdf+tS/8PC3aVNKOwJfBYUCJ9Xyhse6tR0jFLIWF4DRXoCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519066; c=relaxed/simple; bh=AZDTzW+hgqFQO8ID7WPWerRy74pzzuTRiWKDiN96uU8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L2t9WyKs1DPkSpw+zooNWri2ccRZn+X8w1/O0a40+m3mqxJndpp8sAAans94VTA6Y+HxGqIfteHlEBF+t3sz7XS4SSruj5zgwpqMdWm3+KmDoKw7Ima5G72RI0yFhwVhrxd2Zid3bNc8zguNvTilCVT8IdRFYMQGM3YYih67Qrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=oD7iwkEP; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="oD7iwkEP" X-UUID: e92c5c26ebfe11ee935d6952f98a51a9-20240327 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=C8MsNMAtgJ9u6U5BiH2pMWKJ+kiG/BS7o+mHTXW4has=; b=oD7iwkEPzy8W8qr/UtxGDHsb6Ug01XMViS8vsoH2XQoej4gJ144mWq2JLtfSoK4kK4PlGOpDFJrZz8KSZU94g7FDEGnLOKZ04iA/G+eSf00/2L2219LEBxlrLLO/qcTGDjhssIbJGLr1GmzOVw1mHgiW3gdclParzlT+eg2WwiU=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:92a9f0f4-9ee0-49b4-ac70-d27e1d55764a,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6f543d0,CLOUDID:dc9ce290-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: e92c5c26ebfe11ee935d6952f98a51a9-20240327 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 119168359; Wed, 27 Mar 2024 13:57:36 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 27 Mar 2024 13:57:34 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 27 Mar 2024 13:57:34 +0800 From: yu-chang.lee To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Ulf Hansson" , Matthias Brugger , AngeloGioacchino Del Regno , "MandyJH Liu" CC: , , , , , , , , Subject: [PATCH v2 1/3] pmdomain: mediatek: add smi_larb_reset function when power on Date: Wed, 27 Mar 2024 13:57:30 +0800 Message-ID: <20240327055732.28198-2-yu-chang.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240327055732.28198-1-yu-chang.lee@mediatek.com> References: <20240327055732.28198-1-yu-chang.lee@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--5.880400-8.000000 X-TMASE-MatchedRID: l7g8wxsUa9rSuXLpNqOJSR+WEMjoO9WWTJDl9FKHbrkKogmGusPLb9ro EGQiudNyN/7rnrBxoxyzFPg/Y3uT4hHdGMlurS25JmbrB1j4XwoOPDBPSvoRdDuM/8xRTTt71/H hkIjNCSaZ2BL2I+8mdgpVS+XW10LYBLIUC3yGa8rhuXUWQoMQt30tCKdnhB589yM15V5aWpj6C0 ePs7A07b4iOwQQ4jNi7Nj4c9lWXYH8ma3saMV3PsZrmPDoYt2pBWYtVDOiGBA= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--5.880400-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: BD9B2BA20D29EE6E1FA8A379423556C080388F387963D2F58893C5ED1598649F2000:8 X-MTK: N Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch avoid mtcmos power glitch from happening by set and clear smi larb reset. Signed-off-by: yu-chang.lee --- drivers/pmdomain/mediatek/mt8188-pm-domains.h | 28 +++++++++ drivers/pmdomain/mediatek/mtk-pm-domains.c | 59 +++++++++++++++++++ drivers/pmdomain/mediatek/mtk-pm-domains.h | 12 ++++ 3 files changed, 99 insertions(+) diff --git a/drivers/pmdomain/mediatek/mt8188-pm-domains.h b/drivers/pmdoma= in/mediatek/mt8188-pm-domains.h index 06834ab6597c..7bbba4d56a77 100644 --- a/drivers/pmdomain/mediatek/mt8188-pm-domains.h +++ b/drivers/pmdomain/mediatek/mt8188-pm-domains.h @@ -573,6 +573,18 @@ static const struct scpsys_domain_data scpsys_domain_d= ata_mt8188[] =3D { .pwr_sta2nd_offs =3D 0x170, .sram_pdn_bits =3D BIT(8), .sram_pdn_ack_bits =3D BIT(12), + .reset_smi =3D { + SMI_RESET_WR(MT8188_SMI_LARB10_RESET, + MT8188_SMI_LARB10_RESET_ADDR), + SMI_RESET_WR(MT8188_SMI_LARB11A_RESET, + MT8188_SMI_LARB11A_RESET_ADDR), + SMI_RESET_WR(MT8188_SMI_LARB11C_RESET, + MT8188_SMI_LARB11C_RESET_ADDR), + SMI_RESET_WR(MT8188_SMI_LARB11B_RESET, + MT8188_SMI_LARB11B_RESET_ADDR), + SMI_RESET_WR(MT8188_SMI_LARB15_RESET, + MT8188_SMI_LARB15_RESET_ADDR), + }, .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF, }, [MT8188_POWER_DOMAIN_IPE] =3D { @@ -583,6 +595,10 @@ static const struct scpsys_domain_data scpsys_domain_d= ata_mt8188[] =3D { .pwr_sta2nd_offs =3D 0x170, .sram_pdn_bits =3D BIT(8), .sram_pdn_ack_bits =3D BIT(12), + .reset_smi =3D { + SMI_RESET_WR(MT8188_SMI_LARB12_RESET, + MT8188_SMI_LARB12_RESET_ADDR), + }, .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF, }, [MT8188_POWER_DOMAIN_CAM_VCORE] =3D { @@ -660,6 +676,12 @@ static const struct scpsys_domain_data scpsys_domain_d= ata_mt8188[] =3D { .pwr_sta2nd_offs =3D 0x170, .sram_pdn_bits =3D BIT(8), .sram_pdn_ack_bits =3D BIT(12), + .reset_smi =3D { + SMI_RESET_WR(MT8188_SMI_LARB16A_RESET, + MT8188_SMI_LARB16A_RESET_ADDR), + SMI_RESET_WR(MT8188_SMI_LARB17A_RESET, + MT8188_SMI_LARB17A_RESET_ADDR), + }, .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF, }, [MT8188_POWER_DOMAIN_CAM_SUBB] =3D { @@ -670,6 +692,12 @@ static const struct scpsys_domain_data scpsys_domain_d= ata_mt8188[] =3D { .pwr_sta2nd_offs =3D 0x170, .sram_pdn_bits =3D BIT(8), .sram_pdn_ack_bits =3D BIT(12), + .reset_smi =3D { + SMI_RESET_WR(MT8188_SMI_LARB16B_RESET, + MT8188_SMI_LARB16B_RESET_ADDR), + SMI_RESET_WR(MT8188_SMI_LARB17B_RESET, + MT8188_SMI_LARB17B_RESET_ADDR), + }, .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF, }, }; diff --git a/drivers/pmdomain/mediatek/mtk-pm-domains.c b/drivers/pmdomain/= mediatek/mtk-pm-domains.c index e274e3315fe7..9ab6fa105c8c 100644 --- a/drivers/pmdomain/mediatek/mtk-pm-domains.c +++ b/drivers/pmdomain/mediatek/mtk-pm-domains.c @@ -48,6 +48,8 @@ struct scpsys_domain { struct regmap *infracfg_nao; struct regmap *infracfg; struct regmap *smi; + struct regmap **larb; + int num_larb; struct regulator *supply; }; =20 @@ -230,6 +232,39 @@ static int scpsys_regulator_disable(struct regulator *= supply) return supply ? regulator_disable(supply) : 0; } =20 +static int _scpsys_smi_larb_reset(const struct smi_reset_data bpd, + struct regmap *regmap) +{ + int ret; + u32 mask =3D bpd.smi_reset_mask; + + if (!mask) + return 0; + + ret =3D regmap_set_bits(regmap, bpd.smi_reset_addr, mask); + if (ret) + return ret; + + ret =3D regmap_clear_bits(regmap, bpd.smi_reset_addr, mask); + if (ret) + return ret; + + return 0; +} + +static int scpsys_smi_larb_reset(struct scpsys_domain *pd) +{ + int ret, i; + + for (i =3D 0; i < pd->num_larb; i++) { + ret =3D _scpsys_smi_larb_reset(pd->data->reset_smi[i], pd->larb[i]); + if (ret) + return ret; + } + + return 0; +} + static int scpsys_power_on(struct generic_pm_domain *genpd) { struct scpsys_domain *pd =3D container_of(genpd, struct scpsys_domain, ge= npd); @@ -279,6 +314,10 @@ static int scpsys_power_on(struct generic_pm_domain *g= enpd) if (ret < 0) goto err_disable_subsys_clks; =20 + ret =3D scpsys_smi_larb_reset(pd); + if (ret < 0) + goto err_disable_subsys_clks; + ret =3D scpsys_bus_protect_disable(pd); if (ret < 0) goto err_disable_sram; @@ -355,6 +394,7 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys = *scpsys, struct device_no struct scpsys_domain *pd; struct device_node *root_node =3D scpsys->dev->of_node; struct device_node *smi_node; + struct device_node *larb_node; struct property *prop; const char *clk_name; int i, ret, num_clks; @@ -418,6 +458,25 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsys= *scpsys, struct device_no return ERR_CAST(pd->smi); } =20 + pd->num_larb =3D of_count_phandle_with_args(node, "mediatek,larb", NULL); + if (pd->num_larb > 0) { + pd->larb =3D devm_kcalloc(scpsys->dev, pd->num_larb, sizeof(*pd->larb), = GFP_KERNEL); + if (!pd->larb) + return ERR_PTR(-ENOMEM); + + for (i =3D 0; i < pd->num_larb; i++) { + larb_node =3D of_parse_phandle(node, "mediatek,larb", i); + if (!larb_node) + return ERR_PTR(-EINVAL); + + pd->larb[i] =3D device_node_to_regmap(larb_node); + if (IS_ERR(pd->larb[i])) + return ERR_CAST(pd->larb[i]); + } + } else { + pd->num_larb =3D 0; + } + if (MTK_SCPD_CAPS(pd, MTK_SCPD_HAS_INFRA_NAO)) { pd->infracfg_nao =3D syscon_regmap_lookup_by_phandle(node, "mediatek,inf= racfg-nao"); if (IS_ERR(pd->infracfg_nao)) diff --git a/drivers/pmdomain/mediatek/mtk-pm-domains.h b/drivers/pmdomain/= mediatek/mtk-pm-domains.h index aaba5e6b0536..31c2a1bb500f 100644 --- a/drivers/pmdomain/mediatek/mtk-pm-domains.h +++ b/drivers/pmdomain/mediatek/mtk-pm-domains.h @@ -43,6 +43,7 @@ #define PWR_STATUS_USB BIT(25) =20 #define SPM_MAX_BUS_PROT_DATA 6 +#define SPM_MAX_SMI_RESET_DATA 6 =20 enum scpsys_bus_prot_flags { BUS_PROT_REG_UPDATE =3D BIT(1), @@ -79,6 +80,16 @@ enum scpsys_bus_prot_flags { INFRA_TOPAXI_PROTECTEN, \ INFRA_TOPAXI_PROTECTSTA1) =20 +#define SMI_RESET_WR(_mask, _addr) { \ + .smi_reset_mask =3D (_mask), \ + .smi_reset_addr =3D _addr, \ + } + +struct smi_reset_data { + u32 smi_reset_mask; + u32 smi_reset_addr; +}; + struct scpsys_bus_prot_data { u32 bus_prot_set_clr_mask; u32 bus_prot_set; @@ -110,6 +121,7 @@ struct scpsys_domain_data { u32 ext_buck_iso_mask; u16 caps; const struct scpsys_bus_prot_data bp_cfg[SPM_MAX_BUS_PROT_DATA]; + const struct smi_reset_data reset_smi[SPM_MAX_SMI_RESET_DATA]; int pwr_sta_offs; int pwr_sta2nd_offs; }; --=20 2.18.0 From nobody Thu Nov 14 04:52:31 2024 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6177224EF; Wed, 27 Mar 2024 05:57:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519064; cv=none; b=X5v9kZ6E+Pn2SanJOVVGA0fhRObaKqj0XTPF7tqxbj2o07iaZ7qCDToMj7nti/CVBwBNlb1Yv1RSHg6vcA2DVI4w37EpuFo4v5N8+1HHmbu80+72z8vp+fl0XKvGRJziaGU+EV6PtFYu3ifdDBnFxY/JHJQV8bFNiFpKkhRUtYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519064; c=relaxed/simple; bh=/0EvIoS4FoeQBZKeWVIpuWw0C4MKZXMmkpRB2++22RI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oW//8O/gWze26uoqDRlHvgSe4n//gEkaHJzLwrm1QnJDg0p1uJbeGW5kg2/2VuXMgVBG+amwwluFf70wVY7nJkfDWpTHUQRil/0uarqid5XGNOCCPU6MnhuXtqUCyGKQI8bNvhnrAJSVyHDHcEWb9foVVbDywQmY69iZEBHH4/Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=AdoOzG1W; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="AdoOzG1W" X-UUID: e916456cebfe11eeb8927bc1f75efef4-20240327 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=/2eLA/TH/ne/YsQmVXep4OzHNxDnmZn9sfsjEtn7A8g=; b=AdoOzG1WL8wqwnGWoL5L4CJkSqpmhxC34y+eVKyez1LyEldkjbCNprhNrVcPUn32OIkywzs1P8kbVcdeYmgUPVZiGrtZUUHoc46GV+KsZ8WrRFGb4btPsAinprcKlQd1yDArfg2TRCMM4bzZ3xUAxi7R6e6penZaSU0CFiIEKIg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:9be3e245-8492-44e3-a557-b50670007332,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6f543d0,CLOUDID:1460fb81-4f93-4875-95e7-8c66ea833d57,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: e916456cebfe11eeb8927bc1f75efef4-20240327 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 152260002; Wed, 27 Mar 2024 13:57:35 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 27 Mar 2024 13:57:34 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 27 Mar 2024 13:57:34 +0800 From: yu-chang.lee To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Matthias Brugger , AngeloGioacchino Del Regno , MandyJH Liu CC: , , , , , , , , Subject: [PATCH v2 2/3] dt-bindings: power: Add mediatek larb definition Date: Wed, 27 Mar 2024 13:57:31 +0800 Message-ID: <20240327055732.28198-3-yu-chang.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240327055732.28198-1-yu-chang.lee@mediatek.com> References: <20240327055732.28198-1-yu-chang.lee@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add Smart Multimedia Interface Local Arbiter to mediatek power domain. Signed-off-by: yu-chang.lee --- .../devicetree/bindings/power/mediatek,power-controller.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/power/mediatek,power-control= ler.yaml b/Documentation/devicetree/bindings/power/mediatek,power-controlle= r.yaml index 8985e2df8a56..228c0dec5253 100644 --- a/Documentation/devicetree/bindings/power/mediatek,power-controller.yaml +++ b/Documentation/devicetree/bindings/power/mediatek,power-controller.yaml @@ -125,6 +125,10 @@ $defs: $ref: /schemas/types.yaml#/definitions/phandle description: phandle to the device containing the SMI register ran= ge. =20 + mediatek,larb: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to the device containing the LARB register ra= nge. + required: - reg =20 --=20 2.18.0 From nobody Thu Nov 14 04:52:31 2024 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A74F0175AA; Wed, 27 Mar 2024 05:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519067; cv=none; b=I/2zEL7GeRQB5dACUKo3z3b4QpC3EzbfHPmdw2AqwRwCfdk5ENru8WEQmI53Bty1AHfav8GqEBpGRPkWJMx6qwsgs5IIKBQw3N0yk3JrOuH+tBb1DTQPzNUXof1Iopyd7V8n0JTm658gmthdqii+8AD7kh6+uyzpOXxlfPgZh9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711519067; c=relaxed/simple; bh=IefmKFLFOPBGQwfDlVugPJuprs8otf+Jat1LQKHyN3Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L3IiSj/ZYI6bHIPz5fewG8uVyTDMOEs9vvlmgq6TMobs+iYDRhzY4YYxc5Fbe+G2+1kcyPxffAkFVEpTV3+wo55gS+0H/oni8ODj60zoQiZv6swXkJOIw68q904TMnO/yTF90TDDx35/RnWj77ZCmHsoiAHsylwFObvCwyZfzok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=U+5LRffi; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="U+5LRffi" X-UUID: e9272a3aebfe11ee935d6952f98a51a9-20240327 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=YUgDF4AfXPRSldFHt5AC3QHjV4yg9ILDETo3MMuKaiw=; b=U+5LRffixbOOSmqFoy/zRBfTwZeSo5z3maMRganlXUnmnnTWRoo4j3H9DkvyP1zSzjGBxscX6cfNkYFe9t7kmmQsBn/bXNf0yargIpyZB9Kl835K9F+yM4KGV9cdGEPG4p32cTNC6uJ10Jtp1+nF612IVowsGy6F84Kdy5INuEE=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:6b6819cb-7b23-4807-911b-aa35b5dffb61,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:6f543d0,CLOUDID:d5666000-c26b-4159-a099-3b9d0558e447,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: e9272a3aebfe11ee935d6952f98a51a9-20240327 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 454580626; Wed, 27 Mar 2024 13:57:36 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 27 Mar 2024 13:57:34 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 27 Mar 2024 13:57:34 +0800 From: yu-chang.lee To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Matthias Brugger , AngeloGioacchino Del Regno , MandyJH Liu CC: , , , , , , , , Subject: [PATCH v2 3/3] pmdomain: mediatek: support smi clamp protection Date: Wed, 27 Mar 2024 13:57:32 +0800 Message-ID: <20240327055732.28198-4-yu-chang.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240327055732.28198-1-yu-chang.lee@mediatek.com> References: <20240327055732.28198-1-yu-chang.lee@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In order to avoid power glitch, this patch use smi clamp to disable/enable smi common port. Signed-off-by: yu-chang.lee --- drivers/pmdomain/mediatek/mt8188-pm-domains.h | 41 ++++++- drivers/pmdomain/mediatek/mtk-pm-domains.c | 109 +++++++++++++----- drivers/pmdomain/mediatek/mtk-pm-domains.h | 1 + 3 files changed, 115 insertions(+), 36 deletions(-) diff --git a/drivers/pmdomain/mediatek/mt8188-pm-domains.h b/drivers/pmdoma= in/mediatek/mt8188-pm-domains.h index 7bbba4d56a77..39f057dca92c 100644 --- a/drivers/pmdomain/mediatek/mt8188-pm-domains.h +++ b/drivers/pmdomain/mediatek/mt8188-pm-domains.h @@ -573,6 +573,18 @@ static const struct scpsys_domain_data scpsys_domain_d= ata_mt8188[] =3D { .pwr_sta2nd_offs =3D 0x170, .sram_pdn_bits =3D BIT(8), .sram_pdn_ack_bits =3D BIT(12), + .bp_cfg =3D { + BUS_PROT_WR(SMI, + MT8188_SMI_COMMON_SMI_CLAMP_DIP_TO_VDO0, + MT8188_SMI_COMMON_CLAMP_EN_SET, + MT8188_SMI_COMMON_CLAMP_EN_CLR, + MT8188_SMI_COMMON_CLAMP_EN_STA), + BUS_PROT_WR(SMI, + MT8188_SMI_COMMON_SMI_CLAMP_DIP_TO_VPP1, + MT8188_SMI_COMMON_CLAMP_EN_SET, + MT8188_SMI_COMMON_CLAMP_EN_CLR, + MT8188_SMI_COMMON_CLAMP_EN_STA), + }, .reset_smi =3D { SMI_RESET_WR(MT8188_SMI_LARB10_RESET, MT8188_SMI_LARB10_RESET_ADDR), @@ -585,7 +597,7 @@ static const struct scpsys_domain_data scpsys_domain_da= ta_mt8188[] =3D { SMI_RESET_WR(MT8188_SMI_LARB15_RESET, MT8188_SMI_LARB15_RESET_ADDR), }, - .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF, + .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF | MTK_SCPD_CLAMP_PROTECTION, }, [MT8188_POWER_DOMAIN_IPE] =3D { .name =3D "ipe", @@ -595,11 +607,18 @@ static const struct scpsys_domain_data scpsys_domain_= data_mt8188[] =3D { .pwr_sta2nd_offs =3D 0x170, .sram_pdn_bits =3D BIT(8), .sram_pdn_ack_bits =3D BIT(12), + .bp_cfg =3D { + BUS_PROT_WR(SMI, + MT8188_SMI_COMMON_SMI_CLAMP_IPE_TO_VPP1, + MT8188_SMI_COMMON_CLAMP_EN_SET, + MT8188_SMI_COMMON_CLAMP_EN_CLR, + MT8188_SMI_COMMON_CLAMP_EN_STA), + }, .reset_smi =3D { SMI_RESET_WR(MT8188_SMI_LARB12_RESET, MT8188_SMI_LARB12_RESET_ADDR), }, - .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF, + .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF | MTK_SCPD_CLAMP_PROTECTION, }, [MT8188_POWER_DOMAIN_CAM_VCORE] =3D { .name =3D "cam_vcore", @@ -676,13 +695,20 @@ static const struct scpsys_domain_data scpsys_domain_= data_mt8188[] =3D { .pwr_sta2nd_offs =3D 0x170, .sram_pdn_bits =3D BIT(8), .sram_pdn_ack_bits =3D BIT(12), + .bp_cfg =3D { + BUS_PROT_WR(SMI, + MT8188_SMI_COMMON_SMI_CLAMP_IPE_TO_VPP1, + MT8188_SMI_COMMON_CLAMP_EN_SET, + MT8188_SMI_COMMON_CLAMP_EN_CLR, + MT8188_SMI_COMMON_CLAMP_EN_STA), + }, .reset_smi =3D { SMI_RESET_WR(MT8188_SMI_LARB16A_RESET, MT8188_SMI_LARB16A_RESET_ADDR), SMI_RESET_WR(MT8188_SMI_LARB17A_RESET, MT8188_SMI_LARB17A_RESET_ADDR), }, - .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF, + .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF | MTK_SCPD_CLAMP_PROTECTION, }, [MT8188_POWER_DOMAIN_CAM_SUBB] =3D { .name =3D "cam_subb", @@ -692,13 +718,20 @@ static const struct scpsys_domain_data scpsys_domain_= data_mt8188[] =3D { .pwr_sta2nd_offs =3D 0x170, .sram_pdn_bits =3D BIT(8), .sram_pdn_ack_bits =3D BIT(12), + .bp_cfg =3D { + BUS_PROT_WR(SMI, + MT8188_SMI_COMMON_SMI_CLAMP_CAM_SUBB_TO_VDO0, + MT8188_SMI_COMMON_CLAMP_EN_SET, + MT8188_SMI_COMMON_CLAMP_EN_CLR, + MT8188_SMI_COMMON_CLAMP_EN_STA), + }, .reset_smi =3D { SMI_RESET_WR(MT8188_SMI_LARB16B_RESET, MT8188_SMI_LARB16B_RESET_ADDR), SMI_RESET_WR(MT8188_SMI_LARB17B_RESET, MT8188_SMI_LARB17B_RESET_ADDR), }, - .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF, + .caps =3D MTK_SCPD_KEEP_DEFAULT_OFF | MTK_SCPD_CLAMP_PROTECTION, }, }; =20 diff --git a/drivers/pmdomain/mediatek/mtk-pm-domains.c b/drivers/pmdomain/= mediatek/mtk-pm-domains.c index 9ab6fa105c8c..2a86ff4bf23e 100644 --- a/drivers/pmdomain/mediatek/mtk-pm-domains.c +++ b/drivers/pmdomain/mediatek/mtk-pm-domains.c @@ -47,9 +47,10 @@ struct scpsys_domain { struct clk_bulk_data *subsys_clks; struct regmap *infracfg_nao; struct regmap *infracfg; - struct regmap *smi; + struct regmap **smi; struct regmap **larb; int num_larb; + int num_smi; struct regulator *supply; }; =20 @@ -122,29 +123,19 @@ static int scpsys_sram_disable(struct scpsys_domain *= pd) MTK_POLL_TIMEOUT); } =20 -static struct regmap *scpsys_bus_protect_get_regmap(struct scpsys_domain *= pd, - const struct scpsys_bus_prot_data *bpd) -{ - if (bpd->flags & BUS_PROT_COMPONENT_SMI) - return pd->smi; - else - return pd->infracfg; -} - static struct regmap *scpsys_bus_protect_get_sta_regmap(struct scpsys_doma= in *pd, const struct scpsys_bus_prot_data *bpd) { if (bpd->flags & BUS_PROT_STA_COMPONENT_INFRA_NAO) return pd->infracfg_nao; else - return scpsys_bus_protect_get_regmap(pd, bpd); + return pd->infracfg; } =20 static int scpsys_bus_protect_clear(struct scpsys_domain *pd, - const struct scpsys_bus_prot_data *bpd) + const struct scpsys_bus_prot_data *bpd, + struct regmap *sta_regmap, struct regmap *regmap) { - struct regmap *sta_regmap =3D scpsys_bus_protect_get_sta_regmap(pd, bpd); - struct regmap *regmap =3D scpsys_bus_protect_get_regmap(pd, bpd); u32 sta_mask =3D bpd->bus_prot_sta_mask; u32 expected_ack; u32 val; @@ -165,10 +156,9 @@ static int scpsys_bus_protect_clear(struct scpsys_doma= in *pd, } =20 static int scpsys_bus_protect_set(struct scpsys_domain *pd, - const struct scpsys_bus_prot_data *bpd) + const struct scpsys_bus_prot_data *bpd, + struct regmap *sta_regmap, struct regmap *regmap) { - struct regmap *sta_regmap =3D scpsys_bus_protect_get_sta_regmap(pd, bpd); - struct regmap *regmap =3D scpsys_bus_protect_get_regmap(pd, bpd); u32 sta_mask =3D bpd->bus_prot_sta_mask; u32 val; =20 @@ -182,19 +172,32 @@ static int scpsys_bus_protect_set(struct scpsys_domai= n *pd, MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); } =20 -static int scpsys_bus_protect_enable(struct scpsys_domain *pd) +static int scpsys_clamp_bus_protection_enable(struct scpsys_domain *pd, bo= ol is_smi) { + int smi_count =3D 0; + for (int i =3D 0; i < SPM_MAX_BUS_PROT_DATA; i++) { const struct scpsys_bus_prot_data *bpd =3D &pd->data->bp_cfg[i]; + struct regmap *sta_regmap, *regmap; + bool is_smi =3D bpd->flags & BUS_PROT_COMPONENT_SMI; int ret; =20 if (!bpd->bus_prot_set_clr_mask) break; =20 + if (is_smi) { + sta_regmap =3D pd->smi[smi_count]; + regmap =3D pd->smi[smi_count]; + smi_count++; + } else { + sta_regmap =3D scpsys_bus_protect_get_sta_regmap(pd, bpd); + regmap =3D pd->infracfg; + } + if (bpd->flags & BUS_PROT_INVERTED) - ret =3D scpsys_bus_protect_clear(pd, bpd); + ret =3D scpsys_bus_protect_clear(pd, bpd, sta_regmap, regmap); else - ret =3D scpsys_bus_protect_set(pd, bpd); + ret =3D scpsys_bus_protect_set(pd, bpd, sta_regmap, regmap); if (ret) return ret; } @@ -202,19 +205,32 @@ static int scpsys_bus_protect_enable(struct scpsys_do= main *pd) return 0; } =20 -static int scpsys_bus_protect_disable(struct scpsys_domain *pd) +static int scpsys_clamp_bus_protection_disable(struct scpsys_domain *pd, b= ool is_smi) { + int smi_count =3D pd->num_smi - 1; + for (int i =3D SPM_MAX_BUS_PROT_DATA - 1; i >=3D 0; i--) { const struct scpsys_bus_prot_data *bpd =3D &pd->data->bp_cfg[i]; + struct regmap *sta_regmap, *regmap; + bool is_smi =3D bpd->flags & BUS_PROT_COMPONENT_SMI; int ret; =20 if (!bpd->bus_prot_set_clr_mask) continue; =20 + if (is_smi) { + sta_regmap =3D pd->smi[smi_count]; + regmap =3D pd->smi[smi_count]; + smi_count--; + } else { + sta_regmap =3D scpsys_bus_protect_get_sta_regmap(pd, bpd); + regmap =3D pd->infracfg; + } + if (bpd->flags & BUS_PROT_INVERTED) - ret =3D scpsys_bus_protect_set(pd, bpd); + ret =3D scpsys_bus_protect_set(pd, bpd, sta_regmap, regmap); else - ret =3D scpsys_bus_protect_clear(pd, bpd); + ret =3D scpsys_bus_protect_clear(pd, bpd, sta_regmap, regmap); if (ret) return ret; } @@ -272,6 +288,12 @@ static int scpsys_power_on(struct generic_pm_domain *g= enpd) bool tmp; int ret; =20 + if (MTK_SCPD_CAPS(pd, MTK_SCPD_CLAMP_PROTECTION)) { + ret =3D scpsys_clamp_bus_protection_enable(pd, true); + if (ret) + return ret; + } + ret =3D scpsys_regulator_enable(pd->supply); if (ret) return ret; @@ -318,7 +340,13 @@ static int scpsys_power_on(struct generic_pm_domain *g= enpd) if (ret < 0) goto err_disable_subsys_clks; =20 - ret =3D scpsys_bus_protect_disable(pd); + if (MTK_SCPD_CAPS(pd, MTK_SCPD_CLAMP_PROTECTION)) { + ret =3D scpsys_clamp_bus_protection_disable(pd, true); + if (ret) + return ret; + } + + ret =3D scpsys_clamp_bus_protection_disable(pd, false); if (ret < 0) goto err_disable_sram; =20 @@ -332,7 +360,7 @@ static int scpsys_power_on(struct generic_pm_domain *ge= npd) return 0; =20 err_enable_bus_protect: - scpsys_bus_protect_enable(pd); + scpsys_clamp_bus_protection_enable(pd, false); err_disable_sram: scpsys_sram_disable(pd); err_disable_subsys_clks: @@ -353,7 +381,13 @@ static int scpsys_power_off(struct generic_pm_domain *= genpd) bool tmp; int ret; =20 - ret =3D scpsys_bus_protect_enable(pd); + if (MTK_SCPD_CAPS(pd, MTK_SCPD_CLAMP_PROTECTION)) { + ret =3D scpsys_clamp_bus_protection_enable(pd, true); + if (ret) + return ret; + } + + ret =3D scpsys_clamp_bus_protection_enable(pd, false); if (ret < 0) return ret; =20 @@ -450,12 +484,23 @@ generic_pm_domain *scpsys_add_one_domain(struct scpsy= s *scpsys, struct device_no if (IS_ERR(pd->infracfg)) return ERR_CAST(pd->infracfg); =20 - smi_node =3D of_parse_phandle(node, "mediatek,smi", 0); - if (smi_node) { - pd->smi =3D device_node_to_regmap(smi_node); - of_node_put(smi_node); - if (IS_ERR(pd->smi)) - return ERR_CAST(pd->smi); + pd->num_smi =3D of_count_phandle_with_args(node, "mediatek,smi", NULL); + if (pd->num_smi > 0) { + pd->smi =3D devm_kcalloc(scpsys->dev, pd->num_smi, sizeof(*pd->smi), GFP= _KERNEL); + if (!pd->smi) + return ERR_PTR(-ENOMEM); + + for (i =3D 0; i < pd->num_smi; i++) { + smi_node =3D of_parse_phandle(node, "mediatek,smi", i); + if (!smi_node) + return ERR_PTR(-EINVAL); + + pd->smi[i] =3D device_node_to_regmap(smi_node); + if (IS_ERR(pd->smi[i])) + return ERR_CAST(pd->smi[i]); + } + } else { + pd->num_smi =3D 0; } =20 pd->num_larb =3D of_count_phandle_with_args(node, "mediatek,larb", NULL); diff --git a/drivers/pmdomain/mediatek/mtk-pm-domains.h b/drivers/pmdomain/= mediatek/mtk-pm-domains.h index 31c2a1bb500f..e0eb7214719e 100644 --- a/drivers/pmdomain/mediatek/mtk-pm-domains.h +++ b/drivers/pmdomain/mediatek/mtk-pm-domains.h @@ -13,6 +13,7 @@ #define MTK_SCPD_EXT_BUCK_ISO BIT(6) #define MTK_SCPD_HAS_INFRA_NAO BIT(7) #define MTK_SCPD_STRICT_BUS_PROTECTION BIT(8) +#define MTK_SCPD_CLAMP_PROTECTION BIT(9) #define MTK_SCPD_CAPS(_scpd, _x) ((_scpd)->data->caps & (_x)) =20 #define SPM_VDE_PWR_CON 0x0210 --=20 2.18.0