Received: by 10.213.65.68 with SMTP id h4csp3207594imn; Tue, 3 Apr 2018 00:18:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx48qQJeGdpD1kirAo/tamS+VQkCqmm+DgLKxyfqYIBfpM1rfCcIi69YuLFIaJpSvYM9hUr2b X-Received: by 10.101.102.12 with SMTP id w12mr8091801pgv.162.1522739938063; Tue, 03 Apr 2018 00:18:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522739938; cv=none; d=google.com; s=arc-20160816; b=XiuKin7GYZXy58PThO6xsN9Bj2n0B44vHHd9PGAf6gtLkYcpF/f0/iA0sAuOR5wvqb 5Ivon5521kUMl2PTNXI42O0439MV4n8ul91SskuIV3SuyHlTNmW9zQITUBS32YRr//Yf olT/OgsWYmD646E0EJAJcRqLmt3Uc+YI41jqs5CbgXCrCdTvYlfFIIc0Pv2cqLbtw/5B qIMLYOfppqUfwa9Qnq4wXGqugJ+riwP7dMAOjSCmC2V+1vYqi1xH3NlIrwNEg1ue49AA 3nJmfFLmjrP3PFey4/WZw41C/L4WFzF1nWgYVoV+GiiahsOzA3+4M+5iCXPKzEnHLbLG T/+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=k9+cwIt8r9nSqwsLXyxl9NCew1wFUjuoSfzut//KeDY=; b=oxw1NITKYx2PyRpGL16xAz1IrQr1QF/d1WaG0LCAUCJnu58Uyw/8N22KL4cVvWY2Kn vvlF2CrehQs5mG1Vroa9dzqV+vKePfIoIe9cx8WNyRc2KFMpccYqk7iQBbahIAGPILa6 rYVwruJHAVy84A/dkxdegcPS+vT+4I/X0XTAQ7DtODBLIswXc4cuOKVgXqoloBDA74b4 SoyzpJO9ErG0kfeJwptSerP7ndW74a9xD0WbhJDyLJDn7L0SBXtkwQS20tXk2X1o3Jgm zxzgxYsIlPlmPJRKPfaTJmgLvxQkRBoQlecwmz2//fbCIU4dS0NBTMY5iY40f1yb/fam y+9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5-v6si2403550plo.410.2018.04.03.00.18.44; Tue, 03 Apr 2018 00:18:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754992AbeDCHRG (ORCPT + 99 others); Tue, 3 Apr 2018 03:17:06 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:15870 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754876AbeDCHQN (ORCPT ); Tue, 3 Apr 2018 03:16:13 -0400 X-UUID: 57dcce543e774c968d2aa3369e66022b-20180403 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 891228540; Tue, 03 Apr 2018 15:16:10 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs02n2.mediatek.inc (172.21.101.101) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 3 Apr 2018 15:16:08 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Tue, 3 Apr 2018 15:16:08 +0800 From: To: , , , CC: , , , , , Sean Wang , "Matthias Brugger" , Ulf Hansson , "Weiyi Lu" Subject: [PATCH v1 4/7] soc: mediatek: reuse regmap_read_poll_timeout helpers Date: Tue, 3 Apr 2018 15:15:54 +0800 Message-ID: <2f84f7695ea3223b8626a8369aa4ae5e0d03fdce.1522736996.git.sean.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-Product-Ver: SMEX-12.5.0.5042-8.2.9001-23760.005 X-TM-AS-Result: No-2.757200-8.000000-10 X-TMASE-MatchedRID: K16+lmNpxx2kwTZnxyBJ8wPZZctd3P4Bl2F9+KxZd8cCgjr7b0ytGURX PzMAiCClE4XSoP7sKf9blfYeHRl8CKmRcn9t9csLliwpJdZauwd9LQinZ4QefPcjNeVeWlqY+gt Hj7OwNO3DBRxZClZqwVKENRwtMheUs/ukzHUWa4VE0Qow03OSYbzzbi8SaXX8Oty0bGeZI/OATk RXSCHKGGiED+bMVzF6GjL4m1EM04WlkT9Huk9AodpAu0sLxpSoQ8G+yYJYYdZRZDsGiXQioL4jx KnHJRLcwL6SxPpr1/I= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--2.757200-8.000000 X-TMASE-Version: SMEX-12.5.0.5042-8.2.9001-23760.005 X-TMASE-POSTMAN: 2-d; X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Wang Reuse the common helpers regmap_read_poll_timeout provided by Linux core instead of an open-coded handling. Signed-off-by: Sean Wang Cc: Matthias Brugger Cc: Ulf Hansson Cc: Weiyi Lu --- drivers/soc/mediatek/mtk-infracfg.c | 45 +++++++++---------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/drivers/soc/mediatek/mtk-infracfg.c b/drivers/soc/mediatek/mtk-infracfg.c index 8c310de..b849aa5 100644 --- a/drivers/soc/mediatek/mtk-infracfg.c +++ b/drivers/soc/mediatek/mtk-infracfg.c @@ -12,6 +12,7 @@ */ #include +#include #include #include #include @@ -37,7 +38,6 @@ int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask, bool reg_update) { - unsigned long expired; u32 val; int ret; @@ -47,22 +47,11 @@ int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask, else regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_SET, mask); - expired = jiffies + HZ; + ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1, + val, (val & mask) == mask, 10, + jiffies_to_usecs(HZ)); - while (1) { - ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val); - if (ret) - return ret; - - if ((val & mask) == mask) - break; - - cpu_relax(); - if (time_after(jiffies, expired)) - return -EIO; - } - - return 0; + return ret; } /** @@ -80,30 +69,16 @@ int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask, int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask, bool reg_update) { - unsigned long expired; int ret; + u32 val; if (reg_update) regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0); else regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_CLR, mask); - expired = jiffies + HZ; - - while (1) { - u32 val; - - ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val); - if (ret) - return ret; - - if (!(val & mask)) - break; - - cpu_relax(); - if (time_after(jiffies, expired)) - return -EIO; - } - - return 0; + ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1, + val, !(val & mask), 10, + jiffies_to_usecs(HZ)); + return ret; } -- 2.7.4