Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp11718963rwl; Tue, 3 Jan 2023 03:50:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXuDGJcxbLYILyXXYSzOPFI+Ow50uEl1aoPfVOkNbuUbZ5VT+5GY2M65Kk5peud14Ds4Pnag X-Received: by 2002:a17:907:6e05:b0:7c1:235d:2a2b with SMTP id sd5-20020a1709076e0500b007c1235d2a2bmr47926894ejc.24.1672746636352; Tue, 03 Jan 2023 03:50:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672746636; cv=none; d=google.com; s=arc-20160816; b=lWiaX+JjgKqvrgnDB9Wgg5HhRr0v1QRmO71wbbS3k6dS6WaNj352V6DIpPSn6KJkD2 wKLUQnbdaGlXnET3ywZuSnZ+E0h8FT4X0wu3GTBZhZqs7qotyOtXIpkbRcs3vcgqoTVM +1B+G39kRm3Bwo89CA+HTgL9jHFgSEI3WFxub72xB4goqsZCbiojGuiEgzso61L/SpjZ aWm8y+NhoptEqEbyN/V1w/n4BrXvZB4bEY2axA9MoLiOCV/X8HziCGzJyQZTtEnCoAYu aodtn2WhnJRK3wQHS7dtZYutDVtMmxq0cierbfOIH3lm8PzGJs43hcQoqNpaWkfpvYvq xFmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=joDrSmTBJDl3WxJvNdbN5S22yFRRAXSJgMe64PZtVIg=; b=m4scz2QfeLnqTU6kNlqALN1Mw62vDsS08tIgobzNp8hsonINP8gpDYm5En0NPpEJGP ISan5w62lF2aYKzvyyC61DP91XjAIvQm9IucWN9d4+1tBqxGCpVtTg8ei3dkWje7SKSX 34HPJbjUloneIuct5OTumMjIRamFqelIIb2PZAfKoHoaytd8Bd0TpMaQHZnWVBXMgm5D RBRxs2dqkhbXOPYsCbwTA5oXk7da5J4TSV4ZND/nV0zhwUJRUgnV8pZIp/P5014gX8VE s8fGL5F8TIeXyC2yFhiXRCOSJvYSZfLSLl9qu5Ttda0QBvkYXfNwwRYV8tNmuCONf/Qa Mk8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=oV0rWPkv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g12-20020a056402090c00b0048017a9576bsi27951443edz.543.2023.01.03.03.50.21; Tue, 03 Jan 2023 03:50:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=oV0rWPkv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237102AbjACLaV (ORCPT + 61 others); Tue, 3 Jan 2023 06:30:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237444AbjACL3n (ORCPT ); Tue, 3 Jan 2023 06:29:43 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2731F10048; Tue, 3 Jan 2023 03:29:36 -0800 (PST) X-UUID: 5ab5cb930ba64b2e905959ec2649b4d9-20230103 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=joDrSmTBJDl3WxJvNdbN5S22yFRRAXSJgMe64PZtVIg=; b=oV0rWPkvgwUL6Hcl2UyP3sBZs9/RpIEuObGHoo5Mk+8wG5+y7HCGQl6r2sbynOcLaE3dLxIv1Byx2jQafUi56UddErsAVPz6EYl31SDl7wmB3UBJZnhs68CqdfNXQDt8qE6pCZ2h0gVJ2k9OEMZFjNkyz5wvoPN+adk2KgmFAJc=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.16,REQID:9207940a-b425-485f-b014-d477db745bcc,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:95 X-CID-INFO: VERSION:1.1.16,REQID:9207940a-b425-485f-b014-d477db745bcc,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTION :quarantine,TS:95 X-CID-META: VersionHash:09771b1,CLOUDID:729e1b8b-8530-4eff-9f77-222cf6e2895b,B ulkID:230103192931RXVY4C3P,BulkQuantity:1,Recheck:0,SF:38|28|17|19|48,TC:n il,Content:0,EDM:-3,IP:nil,URL:11|1,File:nil,Bulk:40,QS:nil,BEC:nil,COL:0, OSI:0,OSA:0 X-CID-BVR: 0,NGT X-UUID: 5ab5cb930ba64b2e905959ec2649b4d9-20230103 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 997789662; Tue, 03 Jan 2023 19:29:28 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.186) 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.792.15; Tue, 3 Jan 2023 19:29:27 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Tue, 3 Jan 2023 19:29:27 +0800 From: Roger Lu To: Matthias Brugger , Enric Balletbo Serra , Kevin Hilman , Nicolas Boichat CC: Fan Chen , Roger Lu , Jia-wei Chang , , , , , , Subject: [PATCH v3 11/14] soc: mediatek: mtk-svs: use common function to disable restore voltages Date: Tue, 3 Jan 2023 19:29:22 +0800 Message-ID: <20230103112925.16554-12-roger.lu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230103112925.16554-1-roger.lu@mediatek.com> References: <20230103112925.16554-1-roger.lu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The timing of disabling SVS bank and restore default voltage is more than one place. Therefore, add a common function to use for removing the superfluous codes. Signed-off-by: Roger Lu --- drivers/soc/mediatek/mtk-svs.c | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/soc/mediatek/mtk-svs.c b/drivers/soc/mediatek/mtk-svs.c index 567536e32a46..f4382def9736 100644 --- a/drivers/soc/mediatek/mtk-svs.c +++ b/drivers/soc/mediatek/mtk-svs.c @@ -651,6 +651,26 @@ static int svs_adjust_pm_opp_volts(struct svs_bank *svsb) return ret; } +static void svs_bank_disable_and_restore_default_volts(struct svs_platform *svsp, + struct svs_bank *svsb) +{ + unsigned long flags; + + if (svsb->mode_support == SVSB_MODE_ALL_DISABLE) + return; + + /* This spinlock might wait for svs_isr() process */ + spin_lock_irqsave(&svs_lock, flags); + svsp->pbank = svsb; + svs_switch_bank(svsp); + svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN); + svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS); + spin_unlock_irqrestore(&svs_lock, flags); + + svsb->phase = SVSB_PHASE_ERROR; + svs_adjust_pm_opp_volts(svsb); +} + static int svs_dump_debug_show(struct seq_file *m, void *p) { struct svs_platform *svsp = (struct svs_platform *)m->private; @@ -726,7 +746,6 @@ static ssize_t svs_enable_debug_write(struct file *filp, { struct svs_bank *svsb = file_inode(filp)->i_private; struct svs_platform *svsp = dev_get_drvdata(svsb->dev); - unsigned long flags; int enabled, ret; char *buf = NULL; @@ -742,16 +761,8 @@ static ssize_t svs_enable_debug_write(struct file *filp, return ret; if (!enabled) { - spin_lock_irqsave(&svs_lock, flags); - svsp->pbank = svsb; + svs_bank_disable_and_restore_default_volts(svsp, svsb); svsb->mode_support = SVSB_MODE_ALL_DISABLE; - svs_switch_bank(svsp); - svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN); - svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS); - spin_unlock_irqrestore(&svs_lock, flags); - - svsb->phase = SVSB_PHASE_ERROR; - svs_adjust_pm_opp_volts(svsb); } kfree(buf); @@ -1568,7 +1579,6 @@ static int svs_suspend(struct device *dev) { struct svs_platform *svsp = dev_get_drvdata(dev); struct svs_bank *svsb; - unsigned long flags; int ret; u32 idx; @@ -1580,17 +1590,7 @@ static int svs_suspend(struct device *dev) for (idx = 0; idx < svsp->bank_max; idx++) { svsb = &svsp->banks[idx]; - - /* This might wait for svs_isr() process */ - spin_lock_irqsave(&svs_lock, flags); - svsp->pbank = svsb; - svs_switch_bank(svsp); - svs_writel_relaxed(svsp, SVSB_PTPEN_OFF, SVSEN); - svs_writel_relaxed(svsp, SVSB_INTSTS_VAL_CLEAN, INTSTS); - spin_unlock_irqrestore(&svs_lock, flags); - - svsb->phase = SVSB_PHASE_ERROR; - svs_adjust_pm_opp_volts(svsb); + svs_bank_disable_and_restore_default_volts(svsp, svsb); } ret = reset_control_assert(svsp->rst); -- 2.18.0