Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2405075ybv; Fri, 14 Feb 2020 18:13:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzrnMnD04sfLH4zEkJiV0fLBkTTWxnKcwxgI1kDHcO4b7AIqFqsWO9lP8dNu8W97dYw+rxu X-Received: by 2002:aca:c68f:: with SMTP id w137mr3924086oif.179.1581732814532; Fri, 14 Feb 2020 18:13:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581732814; cv=none; d=google.com; s=arc-20160816; b=A1Uq57P3Z2gSP0H/oIaveLnNcfz9k7EXCYPLgL95p3VdsT/3mhKbZNUy8ghjJ+XeSR Ov/Vp5vD5dvwuzXZgdvI6XzRjDXyrp6s+KKdeD5HBgPvRkLlOM8EE6RM+NqyiDdwg0Oc D1Hr2xVEDwQ33fTED8Bb6LhKlNuNHJqadXqhQqEmiPOiBKEl7c9ZfB8Sau+gLurWkiDz H+RP0/P7le5b94OkGYDvSdcx7vT5nMcbewNcfCcLdIObnvuir3RdzdCAroHJRdeQXjbZ KdBSpgkqfGQNVllH2JJcBptNCJSRdUPEpRJX3grucvaGlWwTCPfacpLdeUMe7Ln1cdS3 sGow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dmarc-filter:dkim-signature; bh=FWN168EASJBq5LyNsiOFzXjZn7DYbmkiFzZr0eZ3VcM=; b=CKYd/mHVJMn29vtLM3pEdBgoDEh592fxLJLrgqyZuxdawnn4T21o5veSXe+rrn47To TxVaA/lEHg1jsDH3hY2JUu/dlrdVleU3WlwgmBXHYa+ISyzzfEnNYVJPrfzLdKGLRej9 5J3wO4mRd1iBPMRkNBSVGE6V9JOKEVFl9ArKww9OsZqm9Mi3MlZzPpidLflKT1KaoWEq d9Q9poFTdPoqg7rgKOHYQDX0S6+DSLJDv90UMIV33kuhP1QN4BS9g1cDrEbhCZBzHZ73 oF9ZMD5UODsmbWVYVSkR780yqe0nZzMGfYj3YA5y4YDF4fAWOr9Hmeln2cOovlL8rWgL wHkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=erSLoIYA; 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 g5si3871288otn.232.2020.02.14.18.13.09; Fri, 14 Feb 2020 18:13:34 -0800 (PST) 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; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=erSLoIYA; 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 S1727804AbgBOCMy (ORCPT + 99 others); Fri, 14 Feb 2020 21:12:54 -0500 Received: from mail27.static.mailgun.info ([104.130.122.27]:15167 "EHLO mail27.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727680AbgBOCMy (ORCPT ); Fri, 14 Feb 2020 21:12:54 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1581732773; h=Content-Transfer-Encoding: MIME-Version: Message-Id: Date: Subject: Cc: To: From: Sender; bh=FWN168EASJBq5LyNsiOFzXjZn7DYbmkiFzZr0eZ3VcM=; b=erSLoIYAywXvR74DKvBvQC0JXH4irHG2kBO9AMCMTRjHoHJPYwmXYSw7uuPWsstT99tb+wFn sEdemgo0REFf3zSBXi26p/okjfz84tmRxsyN6rrAOLaAEkQ9YWZnE0qJoIocTGgLqcf4Z//7 SUHy3Da4iq5Izn53hpvrJP2dHQs= X-Mailgun-Sending-Ip: 104.130.122.27 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5e47539f.7f03a1d35148-smtp-out-n03; Sat, 15 Feb 2020 02:12:47 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 38597C4479C; Sat, 15 Feb 2020 02:12:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mdtipton-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mdtipton) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3D828C43383; Sat, 15 Feb 2020 02:12:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3D828C43383 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=mdtipton@codeaurora.org From: Mike Tipton To: sboyd@kernel.org, tdas@codeaurora.org Cc: bjorn.andersson@linaro.org, mturquette@baylibre.com, agross@kernel.org, linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Tipton Subject: [PATCH] clk: qcom: clk-rpmh: Wait for completion when enabling clocks Date: Fri, 14 Feb 2020 18:12:32 -0800 Message-Id: <20200215021232.1149-1-mdtipton@codeaurora.org> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation always uses rpmh_write_async, which doesn't wait for completion. That's fine for disable requests since there's no immediate need for the clocks and they can be disabled in the background. However, for enable requests we need to ensure the clocks are actually enabled before returning to the client. Otherwise, clients can end up accessing their HW before the necessary clocks are enabled, which can lead to bus errors. Use the synchronous version of this API (rpmh_write) for enable requests in the active set to ensure completion. Completion isn't required for sleep/wake sets, since they don't take effect until after we enter sleep. All rpmh requests are automatically flushed prior to entering sleep. Fixes: 9c7e47025a6b ("clk: qcom: clk-rpmh: Add QCOM RPMh clock driver") Signed-off-by: Mike Tipton --- drivers/clk/qcom/clk-rpmh.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/clk/qcom/clk-rpmh.c b/drivers/clk/qcom/clk-rpmh.c index 12bd8715dece..3137595a736b 100644 --- a/drivers/clk/qcom/clk-rpmh.c +++ b/drivers/clk/qcom/clk-rpmh.c @@ -143,6 +143,19 @@ static inline bool has_state_changed(struct clk_rpmh *c, u32 state) != (c->aggr_state & BIT(state)); } +static int clk_rpmh_send(struct clk_rpmh *c, enum rpmh_state state, + struct tcs_cmd *cmd, bool wait_for_completion) +{ + int ret; + + if (wait_for_completion) + ret = rpmh_write(c->dev, state, cmd, 1); + else + ret = rpmh_write_async(c->dev, state, cmd, 1); + + return ret; +} + static int clk_rpmh_send_aggregate_command(struct clk_rpmh *c) { struct tcs_cmd cmd = { 0 }; @@ -159,7 +172,8 @@ static int clk_rpmh_send_aggregate_command(struct clk_rpmh *c) if (cmd_state & BIT(state)) cmd.data = on_val; - ret = rpmh_write_async(c->dev, state, &cmd, 1); + ret = clk_rpmh_send(c, state, &cmd, + cmd_state && state == RPMH_ACTIVE_ONLY_STATE); if (ret) { dev_err(c->dev, "set %s state of %s failed: (%d)\n", !state ? "sleep" : @@ -267,7 +281,7 @@ static int clk_rpmh_bcm_send_cmd(struct clk_rpmh *c, bool enable) cmd.addr = c->res_addr; cmd.data = BCM_TCS_CMD(1, enable, 0, cmd_state); - ret = rpmh_write_async(c->dev, RPMH_ACTIVE_ONLY_STATE, &cmd, 1); + ret = clk_rpmh_send(c, RPMH_ACTIVE_ONLY_STATE, &cmd, enable); if (ret) { dev_err(c->dev, "set active state of %s failed: (%d)\n", c->res_name, ret); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project