Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4611440pxj; Wed, 12 May 2021 09:13:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlB79eDRAn8zyjm5NJzFZbg/bXMn1O6L4eOAB5FE40JILlnR0GX3xfVFRjknTToVT92qlL X-Received: by 2002:aa7:d146:: with SMTP id r6mr44995830edo.344.1620835983602; Wed, 12 May 2021 09:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835983; cv=none; d=google.com; s=arc-20160816; b=HT0VmUmS9/88ldYvCR58s1KJjXp3if5uJJGGHoE4aB60Y98g40lSEXM0DzWj6ltNx9 uPa+JU0DS03UKFk/9WULz1F5HPKOuQCsCgFQWrMxXKYGUVIqFWtmywII/GD0ScNJH1Kw ZO9YouVjk/5CeN+5+WUkeJkfA1jYl0/HAKLFRLinyo2iymmiLHh4kNOuzg59dio0O5Zo FUAyQsUol02cP00ykltb9Oh+TzodxBt1e66nwGMKFTuFcijen6YYdGZfD1QS4X0bOJ16 xs2qSRiJcy/xlGk8LTDetRtzcPDETFILddQ8PTf8st5uo/NbkYF8aVUw/Or5EanlW928 /u7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hLO07RvVt1fziUiRvtyGjpoeI4iemRmgljUR+sDMQ0c=; b=OuHudkFKFsxQ5PcYtuH80nQvHrVze2XPGfYMLdl/6P2cpy74gr0u1awtOOlRx1Kj0n fo9xYDn3/YcNtIr1dJDj58JEMaUeRlSBzmX2/gvpKfX5TFDgSg89vr75amV9iP2oy/k+ d463888AQ4MgWwBn1ZTrQDKuL2DctOr72lubCn9uZ4/b7jyz4B9IBq7p5Dzk9gS1cFH3 XSVvKKLjJKnkv5R8H+Nig+UkCQHI0D6pO2ut9e3kQZE2r6NH7Z4kDB4syVwlJHyUhNBc BvD04m+z4hGPVGByfGXPgJf79wOs90/SNm49GIsBWPDZZREqm4Oedw3BxzPhhADGiSEe excQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BGXDxc1b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z12si378339ejf.67.2021.05.12.09.12.39; Wed, 12 May 2021 09:13:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BGXDxc1b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239674AbhELQKo (ORCPT + 99 others); Wed, 12 May 2021 12:10:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:40904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235725AbhELP34 (ORCPT ); Wed, 12 May 2021 11:29:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7978761941; Wed, 12 May 2021 15:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832540; bh=VzURwon8NUEYzyv9nLyfGmon0Aw6bybOR2rs7eCOplU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BGXDxc1bgH+cTW46wf4tPpBI5GJJaPMqHQ/tZe2GRNcUj/XpjDJGAsXvAibAs3CT1 v5OYJOkfbu0RDxbeqpo5U3SzbaRdjoBbKecpVacdUhc+xINL9I0V6GDjQBZZxGH7Zq xFihCc32hGmITLml+YUyQnJWdp7SmurLADkAbwOs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Quanyang Wang , Laurent Pinchart , Stephen Boyd , Sasha Levin Subject: [PATCH 5.10 321/530] clk: zynqmp: pll: add set_pll_mode to check condition in zynqmp_pll_enable Date: Wed, 12 May 2021 16:47:11 +0200 Message-Id: <20210512144830.356813947@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quanyang Wang [ Upstream commit 394cdb69a3c30b33524cf1204afe5cceaba69cdc ] If there is a IOCTL_SET_PLL_FRAC_MODE request sent to ATF ever, we shouldn't skip invoking PM_CLOCK_ENABLE fn even though this pll has been enabled. In ATF implementation, it will only assign the mode to the variable (struct pm_pll *)pll->mode when handling IOCTL_SET_PLL_FRAC_MODE call. Invoking PM_CLOCK_ENABLE can force ATF send request to PWU to set the pll mode to PLL's register. There is a scenario that happens in enabling VPLL_INT(clk_id:96): 1) VPLL_INT has been enabled during booting. 2) A driver calls clk_set_rate and according to the rate, the VPLL_INT should be set to FRAC mode. Then zynqmp_pll_set_mode is called to pass IOCTL_SET_PLL_FRAC_MODE to ATF. Note that at this point ATF just stores the mode to a variable. 3) This driver calls clk_prepare_enable and zynqmp_pll_enable is called to try to enable VPLL_INT pll. Because of 1), the function zynqmp_pll_enable just returns without doing anything after checking that this pll has been enabled. In the scenario above, the pll mode of VPLL_INT will never be set successfully. So adding set_pll_mode to check condition to fix it. Fixes: 3fde0e16d016 ("drivers: clk: Add ZynqMP clock driver") Signed-off-by: Quanyang Wang Tested-by: Laurent Pinchart Link: https://lore.kernel.org/r/20210406153131.601701-1-quanyang.wang@windriver.com Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/zynqmp/pll.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/clk/zynqmp/pll.c b/drivers/clk/zynqmp/pll.c index 03bfe62c1e62..abe6afbf3407 100644 --- a/drivers/clk/zynqmp/pll.c +++ b/drivers/clk/zynqmp/pll.c @@ -14,10 +14,12 @@ * struct zynqmp_pll - PLL clock * @hw: Handle between common and hardware-specific interfaces * @clk_id: PLL clock ID + * @set_pll_mode: Whether an IOCTL_SET_PLL_FRAC_MODE request be sent to ATF */ struct zynqmp_pll { struct clk_hw hw; u32 clk_id; + bool set_pll_mode; }; #define to_zynqmp_pll(_hw) container_of(_hw, struct zynqmp_pll, hw) @@ -81,6 +83,8 @@ static inline void zynqmp_pll_set_mode(struct clk_hw *hw, bool on) if (ret) pr_warn_once("%s() PLL set frac mode failed for %s, ret = %d\n", __func__, clk_name, ret); + else + clk->set_pll_mode = true; } /** @@ -240,9 +244,15 @@ static int zynqmp_pll_enable(struct clk_hw *hw) u32 clk_id = clk->clk_id; int ret; - if (zynqmp_pll_is_enabled(hw)) + /* + * Don't skip enabling clock if there is an IOCTL_SET_PLL_FRAC_MODE request + * that has been sent to ATF. + */ + if (zynqmp_pll_is_enabled(hw) && (!clk->set_pll_mode)) return 0; + clk->set_pll_mode = false; + ret = zynqmp_pm_clock_enable(clk_id); if (ret) pr_warn_once("%s() clock enable failed for %s, ret = %d\n", -- 2.30.2