From patchwork Mon Oct 10 23:11:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caesar Wang X-Patchwork-Id: 9370001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2681060487 for ; Mon, 10 Oct 2016 23:11:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F04D629A79 for ; Mon, 10 Oct 2016 23:11:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1BBF29A7D; Mon, 10 Oct 2016 23:11:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, URIBL_BLACK autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5A0B729A79 for ; Mon, 10 Oct 2016 23:11:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1btjjP-0007tg-5P; Mon, 10 Oct 2016 23:11:39 +0000 Received: from mail-pa0-f68.google.com ([209.85.220.68]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1btjjM-0007sI-12 for linux-rockchip@lists.infradead.org; Mon, 10 Oct 2016 23:11:37 +0000 Received: by mail-pa0-f68.google.com with SMTP id r9so288180paz.1 for ; Mon, 10 Oct 2016 16:11:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=c5gWPE1aHw7VJyQWWfZ2+CtkI/AMHKG5ekYSgcIPKaE=; b=HTMpN3jyVQXfeRAaIYGBgdL2Od6lqRGliiXIVJX4t331yfREBJpIUQ77KZmskhNs/P V+Qjh0xULI8zXyog8Qf5/5DM53T0Z/axdCp2yaSfPVVyoEDY6H2q/qy6vW3uG7Jw/A9z Ism2dJPk3rnhN2NS/nOmkMliFMb45qjxr0e2MNUzltS5nshqCPLFQ44kAx6t/O+i4Q+u wTp24XbbhGI40/8RLU0nWv3tEFbG5EOUZEJft2ivL7T6tE2H/2DAoP0Troqr5glgcLT+ 9qzomBzvjosOD892mesMf/9SecDvBa1rtiXgSuQWX8+D/p265DDCTIZ7EAHhFm6TOR0L oeMA== X-Gm-Message-State: AA6/9RnBedhGyNvyCroT+gx68H7lNkqQV12+W6UbkzEjw058xjM5BimTiCNIJHolQkaHig== X-Received: by 10.66.11.231 with SMTP id t7mr1167792pab.203.1476141074240; Mon, 10 Oct 2016 16:11:14 -0700 (PDT) Received: from nb.corp.google.com ([172.22.52.163]) by smtp.gmail.com with ESMTPSA id b4sm346508paw.10.2016.10.10.16.11.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 10 Oct 2016 16:11:13 -0700 (PDT) From: Caesar Wang To: khilman@linaro.org, heiko@sntech.de Subject: [PATCH] soc: rockchip: avoid infinite loop for power domain Date: Tue, 11 Oct 2016 07:11:07 +0800 Message-Id: <1476141067-21186-1-git-send-email-wxt@rock-chips.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161010_161136_157319_F7372CE7 X-CRM114-Status: GOOD ( 13.02 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-rockchip@lists.infradead.org, zhangqing@rock-chips.com, linux-kernel@vger.kernel.org, Caesar Wang , tfiga@chromium.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In some cases, we have met the infinite loop in rockchip_pmu_set_idle_request. This patch adds the error message and avoid infinite loop if it fails to get the ack. Signed-off-by: Caesar Wang --- drivers/soc/rockchip/pm_domains.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c index 7acd151..cb2a076 100644 --- a/drivers/soc/rockchip/pm_domains.c +++ b/drivers/soc/rockchip/pm_domains.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -105,12 +106,24 @@ static bool rockchip_pmu_domain_is_idle(struct rockchip_pm_domain *pd) return (val & pd_info->idle_mask) == pd_info->idle_mask; } +static u32 rockchip_pmu_read_ack(struct rockchip_pmu *pmu) +{ + u32 val; + + regmap_read(pmu->regmap, pmu->info->ack_offset, &val); + return val; +} + static int rockchip_pmu_set_idle_request(struct rockchip_pm_domain *pd, bool idle) { const struct rockchip_domain_info *pd_info = pd->info; + struct generic_pm_domain *genpd = &pd->genpd; struct rockchip_pmu *pmu = pd->pmu; unsigned int val; + u32 target_ack; + bool target_idle; + int ret; if (pd_info->req_mask == 0) return 0; @@ -120,12 +133,26 @@ static int rockchip_pmu_set_idle_request(struct rockchip_pm_domain *pd, dsb(sy); - do { - regmap_read(pmu->regmap, pmu->info->ack_offset, &val); - } while ((val & pd_info->ack_mask) != (idle ? pd_info->ack_mask : 0)); + /* Wait util idle_ack = 1 */ + target_ack = idle ? pd_info->ack_mask : 0; + ret = readx_poll_timeout_atomic(rockchip_pmu_read_ack, pmu, val, + (val & pd_info->ack_mask) == target_ack, 0, 10000); + if (ret) { + dev_err(pmu->dev, + "failed to get ack on domain '%s', val=0x%x\n", + genpd->name, val); + return ret; + } - while (rockchip_pmu_domain_is_idle(pd) != idle) - cpu_relax(); + ret = readx_poll_timeout_atomic(rockchip_pmu_domain_is_idle, pd, + target_idle, target_idle == idle, + 0, 10000); + if (ret) { + dev_err(pmu->dev, + "failed to set idle on domain '%s', val=0x%x\n", + genpd->name, target_idle); + return ret; + } return 0; }