Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp5985200rwb; Tue, 1 Aug 2023 10:31:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlGWMnDJRPe6qVwXSW2fL3rtsdteJJoC3JkH1inIcavN9V5apZHBj5kfX3R4x1jX2JpBmFSb X-Received: by 2002:a17:902:6943:b0:1b8:6984:f5e5 with SMTP id k3-20020a170902694300b001b86984f5e5mr13111512plt.12.1690911066875; Tue, 01 Aug 2023 10:31:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690911066; cv=none; d=google.com; s=arc-20160816; b=RivgPTA5OdPJ4H/8KdUoubSvOSZMhLtXsJB0P7ztL4UQiwr+Occ+fd5XRNBvRyEis6 Uqt+svBbNLGngTnnNoArjowkLyhorWnjvH73YIaA4D00nw+MMxKabRe9ENRuhBABKwHv I1EJcQ2n0Z/TYXiACiQ5PtImkd2pH25kYWlqQwoUV/mAkfmeScgu09iJVfF1YTE2z/8q DqsjW8ZqG01NPrmiPvPIn2D9POwJtgnloqczPGxSoLjXDnwW1l/OXUhOett7tvAUMDZk WkpbMvjfV6XJyxUo7pgUT5pknjxg8fspK5AJKsBg52ThmChmF8qOo9c/7Oaj6rjzT36a 9JUw== 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 :message-id:date:subject:cc:to:from; bh=qgcIY3ZGUA3SQSIGRAfbML0uq/9wC//36ldOQaa7HvM=; fh=SWEHQcBRCa6tI6IeOBY89k68XTqAL8eiUakPFKEYqdo=; b=hynlF9PJR2YNbcSpUHWU8AHTnD2WhFES5QA8CsREpvssJ20/U00NpVQLDsuRfOFjdM LiUzFnstoHQZEyTVC8c1E+NnJSLcPZO9o39zjjS+sV5fl/WeLSCQcsZOzXdf6qWKwz17 iN77Tf0IQYbqFtpl36dy8d9zdKnjzdITpvixbSPZD+pLtBuA1OUA/uf3SdmFc9EfEibX JlHbX+FLpbsbnq8zeovOTvwN91mtKFYxn0CnkrDgPsJQo8uvpGbwZC5i5cdS8uNDc0+i 1MSeMf/viNARIBvzWmMNhokbqoFMsEHvOzvsVN9sErZDuOBrZWxsBmXNdbUz2xTy1WA8 sqIg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u191-20020a6385c8000000b005638355e990si1849599pgd.410.2023.08.01.10.30.53; Tue, 01 Aug 2023 10:31:06 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229557AbjHAQ2J (ORCPT + 99 others); Tue, 1 Aug 2023 12:28:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbjHAQ2I (ORCPT ); Tue, 1 Aug 2023 12:28:08 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79CD9133 for ; Tue, 1 Aug 2023 09:28:07 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qQsDv-00018q-Q3; Tue, 01 Aug 2023 18:27:51 +0200 Received: from [2a0a:edc0:0:1101:1d::54] (helo=dude05.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1qQsDu-000QYa-SP; Tue, 01 Aug 2023 18:27:50 +0200 Received: from afa by dude05.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qQsDt-00Dkrt-2z; Tue, 01 Aug 2023 18:27:49 +0200 From: Ahmad Fatoum To: Abel Vesa , Peng Fan , Michael Turquette , Stephen Boyd , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team Cc: Ahmad Fatoum , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: imx: composite-8m: avoid glitches when set_rate would be a no-op Date: Tue, 1 Aug 2023 18:27:31 +0200 Message-Id: <20230801162731.3278396-1-a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: afa@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Reconfiguring the clock divider to the exact same value is observed on an i.MX8MN to often cause a short clock pause, probably because the divider restarts counting from the time the register is written. This issue doesn't show up normally, because the clock framework will take care to not call set_rate when the clock rate is the same. However, when we configure an upstream clock (e.g. an audio_pll), the common code will call set_rate with the newly calculated rate on all children. As the new rate is different, we enter set_rate and compute the same divider values, write them back and cause the glitch (e.g. on a SAI's MCLK). To avoid the glitch, we skip writing the same value back again. Fixes: d3ff9728134e ("clk: imx: Add imx composite clock") Signed-off-by: Ahmad Fatoum --- drivers/clk/imx/clk-composite-8m.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/clk/imx/clk-composite-8m.c b/drivers/clk/imx/clk-composite-8m.c index cbf0d7955a00..3e9a092e136c 100644 --- a/drivers/clk/imx/clk-composite-8m.c +++ b/drivers/clk/imx/clk-composite-8m.c @@ -97,7 +97,7 @@ static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw, int prediv_value; int div_value; int ret; - u32 val; + u32 orig, val; ret = imx8m_clk_composite_compute_dividers(rate, parent_rate, &prediv_value, &div_value); @@ -106,13 +106,15 @@ static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw, spin_lock_irqsave(divider->lock, flags); - val = readl(divider->reg); - val &= ~((clk_div_mask(divider->width) << divider->shift) | - (clk_div_mask(PCG_DIV_WIDTH) << PCG_DIV_SHIFT)); + orig = readl(divider->reg); + val = orig & ~((clk_div_mask(divider->width) << divider->shift) | + (clk_div_mask(PCG_DIV_WIDTH) << PCG_DIV_SHIFT)); val |= (u32)(prediv_value - 1) << divider->shift; val |= (u32)(div_value - 1) << PCG_DIV_SHIFT; - writel(val, divider->reg); + + if (val != orig) + writel(val, divider->reg); spin_unlock_irqrestore(divider->lock, flags); -- 2.39.2