Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2683018rwb; Mon, 7 Aug 2023 01:26:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUfN+CgFp6LyOAlAMOMbC4uyy4TLkF40ApOmampH33CXKKkZWyplqXYhJd6t4jj0Uwu1DS X-Received: by 2002:a17:902:a613:b0:1bc:2bd:8523 with SMTP id u19-20020a170902a61300b001bc02bd8523mr6365790plq.24.1691396793704; Mon, 07 Aug 2023 01:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691396793; cv=none; d=google.com; s=arc-20160816; b=LzZ45XhkXVYAe3OhmJHAEmKsnyYEm6q5C5lt0V/bv0yhmOVZi6fKYJ4bwsYqdmMaZQ ntEbYZEFl+axw+ikYzeJm4bdQNDkaz3BBNHA55N9kLF6akOLdahM/+ZyCpZYiWtX+bfe Ds8XlWJymviYS7RKd7l6froftZaW4534QK/reH8FYjCM+1U8SDJRyH/vgFPivAE2xrCl yPRGy69aDa9wgEkZOBkJNcdqNSSHGg+YIcssGwYJkgij7odR1BAZnJyf18rN7tPVzT+0 hRTjE+eatQExCbOS3A3YZaOcfKnBIaipqZtrolJ1+6LOVM6sSHMT0GNWMs+gyLBBslsZ tLYw== 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=P4w/qQmjGI9PH/sbz5HJVhi7Oqvzk2jEF7DVifP9fzU=; fh=GxtS6PY2UfGU0GBz3aGAnxdKS9w8PGmIfD8r8Li4Bfc=; b=HtH12y6Lam6oZNJL7ya0Lk9d0BFmMFCukXpvC5wmuN21k1PUCof8qXdHR+m2KVgj6p fwxLvTzEqzphoZgIREW2fVTMCAFD/w+PycgfQlAOdfae1XSAf+k6K6cUuf5u47s2EBh2 fExLckrW1dF5BMwZ8Pk8HzIZDIDTMKcuFQgA/EmfNFBnJiZS3X6OJu6Dqxybi2uAgia6 ZES9WbtHetSxw4DSuQ0erxZiiEq0hIkCP2SZg+fJxH3S8aFas0nUkumcmwtW8ZLXCQ6A rIMwapcJ4WWbcxKraq/mhraDSyq/KOJMd+irtcZ7VHK6ZJIe5uA3zEhZOq4NeIVcG7LH pzQg== 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 h10-20020a170902f54a00b001bbce4a587esi5588171plf.456.2023.08.07.01.26.20; Mon, 07 Aug 2023 01:26:33 -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 S230009AbjHGIW0 (ORCPT + 99 others); Mon, 7 Aug 2023 04:22:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230147AbjHGIWZ (ORCPT ); Mon, 7 Aug 2023 04:22:25 -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 11F1D170B for ; Mon, 7 Aug 2023 01:22:24 -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 1qSvV9-00009U-TV; Mon, 07 Aug 2023 10:22:07 +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 1qSvV8-001hda-UD; Mon, 07 Aug 2023 10:22:06 +0200 Received: from afa by dude05.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qSvV8-009n6M-1f; Mon, 07 Aug 2023 10:22:06 +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: Peng Fan , Ahmad Fatoum , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] clk: imx: composite-8m: fix clock pauses when set_rate would be a no-op Date: Mon, 7 Aug 2023 10:22:00 +0200 Message-Id: <20230807082201.2332746-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=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 longer than usual clock pause, probably because the divider restarts counting whenever the register is rewritten. 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 reconfigure an upstream clock, the common code will call set_rate with the newly calculated rate on all children, e.g.: - sai5 is running normally and divides Audio PLL out by 16. - Audio PLL rate is increased by 32Hz (glitch-free kdiv change) - rates for children are recalculated and rates are set recursively - imx8m_clk_composite_divider_set_rate(sai5) is called with 32/16 = 2Hz more - imx8m_clk_composite_divider_set_rate computes same divider as before - divider register is written, so it restarts counting from zero and MCLK is briefly paused, so instead of e.g. 40ns, MCLK is low for 120ns. Some external clock consumers can be upset by such unexpected clock pauses, so let's make sure we only rewrite the divider value when the value to be written is actually different. Fixes: d3ff9728134e ("clk: imx: Add imx composite clock") Signed-off-by: Ahmad Fatoum --- v1 -> v2: - replace glitch with clock pause instead (Peng) - describe how bug triggers in more detail (Peng) --- 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