Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3941706rdh; Fri, 29 Sep 2023 06:59:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErxwv0i7omsi+jWyZGl6r40xh+n+pxK7GJ7C8Balomn85jzD4z3tdEguNngk7sxiWhnSXS X-Received: by 2002:a17:902:720a:b0:1bb:b30e:4364 with SMTP id ba10-20020a170902720a00b001bbb30e4364mr3771387plb.39.1695995977583; Fri, 29 Sep 2023 06:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695995977; cv=none; d=google.com; s=arc-20160816; b=TTLo9SbOaFp7fBVkTazPcxpwtKg7ghKl2Jq1yJZBy8S8i17n46zJzI8bXGcgDMd0SX wZjLb8R2BY/KuTt69hhvKp+678JSreFKMFtwwBVCQzCsUS2Kc4zT5l/43adCC6pZMdiy g5Wew8Snz4KHxJ/r+kHfCxmnLwFFMUCnCszX5y3XW70MRL8JmbuZI3nUN8GKCByIXIUR LUBEpsW0wUja1yqNGAgamuvukSNrNJh1cmEfqX5aod6ahQ707Vn+vYK3icdnMDqG6LlI DOkSzLXwNZQcqp8mXYVmhi6BBTVWl4KZVEhjqjrzh149uSXZbZjU3gjM8ANMxFkrJYLe OKPQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=au5TjHif1NdZJ2Z7FrkXoOxh3rDBA3mHRRDa4P1Qy7A=; fh=9Jubxw0YxsAKXF35jmMjmwWFw//o5IirJtzOJTY4qOs=; b=bqR+rPx0HRV0hLGsxLz1p+Wt9NFPy5m9qR9vhoc7Vo6MwddUEMLwYyA2p05/sWk4gz Hp1RdxUeKDPKNiVTWEc/u8qI/eRsXw2moQlbZklOw0B17mM7fZBR6Z91G46NoKm19yMN 6y9yOZ6qpZXlHyj6erDSOb8SyIni9dz/C7rZChbxD1tJvCPJlX7hEyLrG8f1vkdzx2va t5Pe8BI9x/D7I0KH8I9SzMBpT++SJWDGFDslBavDDRLr7vicXszoKAgD5XIZO8QL0Z8s 7yTVFXpgwaqb2UsbKKX+4mt2H8X7j0Y+2pUWPQGS6BQLNJm5ohmGpQWQpN9aFVimDPwu 1qmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tuxon.dev header.s=google header.b=bbhcGyID; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id x15-20020a170902ec8f00b001c5eb1706d3si20328721plg.171.2023.09.29.06.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 06:59:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@tuxon.dev header.s=google header.b=bbhcGyID; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 947E98380FC1; Thu, 28 Sep 2023 22:40:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232720AbjI2Fjk (ORCPT + 99 others); Fri, 29 Sep 2023 01:39:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232666AbjI2Fja (ORCPT ); Fri, 29 Sep 2023 01:39:30 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB1F21AC for ; Thu, 28 Sep 2023 22:39:27 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9ae7383b7ecso64253366b.0 for ; Thu, 28 Sep 2023 22:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1695965966; x=1696570766; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=au5TjHif1NdZJ2Z7FrkXoOxh3rDBA3mHRRDa4P1Qy7A=; b=bbhcGyIDn/XHtayop1ONScEnDCLyGTMRomMTmeZAofjitENiGonQkKdWcLLh4Qr2w7 cFh0WJ3L/5YY72cDiDQD4/JbcDylEQXEucdtrHtshfwVe4ukATDoapBuM6yXl4XaPMCG VLJRe87tDkXKTxGr0rxVGb+pwFKuox0zE5+hLuROIKe286r+bjIB9MAm2KHnWJaZc+m4 Ass2BnhuDrxhgPwZAk1IMAsWITcNY6/qwOxEjJipIp4CnsskjLsHteqE/OzAOGHaXV5H ksHaNpHu6GkO781b3ftL6C4jOjfuMm5sFKR0qpptxNdxJSsnkJDsUdkYEcHonyI+aT+B GSvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695965966; x=1696570766; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=au5TjHif1NdZJ2Z7FrkXoOxh3rDBA3mHRRDa4P1Qy7A=; b=VJIDIMw3ztHuT3ivmu6F9viWVitpSSxC43318LZd9HE2Z8Va8iy6ZrrOIMgrJmq2wG cn9hO7GK3sJLQXkcE3mXKZ7r4kRm9zoRglDFwtZsUBxBbzZsm8bqIYCYi81r3XJ1JCWG 9KVSemOLii5/heFx4j4LFeAnQ7XvuajGMA4EkHL2jy3SgMVfd3hrDUFP9WzOl779r3J7 qlOouqufCLvUOm4OpgW5GIEQFKfkxxA9cPcntF5uXCqxMM3jTDXAYuhwadCjnjghZrof v1VLJ0sCkw2ysnclFObrYv9Qd6FPyr6wn7cWDy35hdbZHSmtREdndenxFjSTgx2Ze7Af XAzg== X-Gm-Message-State: AOJu0YyTIA19DMtZMmEeiNJtf0UXO9H+2wMQUga10PqAWCqVJtH8bNnR WXF0emlGZNNpvE5PgB7kiWzUgQ== X-Received: by 2002:a17:907:b60b:b0:9b2:cee1:1f82 with SMTP id vl11-20020a170907b60b00b009b2cee11f82mr1301071ejc.7.1695965965746; Thu, 28 Sep 2023 22:39:25 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.177]) by smtp.gmail.com with ESMTPSA id z19-20020a1709063ad300b009a1a653770bsm11971992ejd.87.2023.09.28.22.39.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 22:39:25 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: geert+renesas@glider.be, mturquette@baylibre.com, sboyd@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, linus.walleij@linaro.org, gregkh@linuxfoundation.org, jirislaby@kernel.org, magnus.damm@gmail.com, catalin.marinas@arm.com, will@kernel.org, quic_bjorande@quicinc.com, konrad.dybcio@linaro.org, arnd@arndb.de, neil.armstrong@linaro.org, prabhakar.mahadev-lad.rj@bp.renesas.com, biju.das.jz@bp.renesas.com Cc: linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 03/28] clk: renesas: rzg2l: lock around writes to mux register Date: Fri, 29 Sep 2023 08:38:50 +0300 Message-Id: <20230929053915.1530607-4-claudiu.beznea@bp.renesas.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230929053915.1530607-1-claudiu.beznea@bp.renesas.com> References: <20230929053915.1530607-1-claudiu.beznea@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 28 Sep 2023 22:40:16 -0700 (PDT) From: Claudiu Beznea SD MUX output (SD0) is further divided by 4 in G2{L, UL}. The divided clock is SD0_DIV4. SD0_DIV4 is registered with CLK_SET_RATE_PARENT which means a rate request for it is propagated to the MUX and could reach rzg2l_cpg_sd_clk_mux_set_parent() concurrently with the users of SD0. Add proper locking to avoid concurrent access on SD MUX set rate registers. Fixes: eaff33646f4cb ("clk: renesas: rzg2l: Add SDHI clk mux support") Signed-off-by: Claudiu Beznea --- Changes in v2: - adapted delay_us to 10us - adapted CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US to 200us; tested with this adjustements on RZ/G3S and RZ/G2L SoCs drivers/clk/renesas/rzg2l-cpg.c | 23 +++++++++++++---------- drivers/clk/renesas/rzg2l-cpg.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/clk/renesas/rzg2l-cpg.c b/drivers/clk/renesas/rzg2l-cpg.c index 5343d04fd70d..0679f2c7649e 100644 --- a/drivers/clk/renesas/rzg2l-cpg.c +++ b/drivers/clk/renesas/rzg2l-cpg.c @@ -189,6 +189,7 @@ static int rzg2l_cpg_sd_clk_mux_set_parent(struct clk_hw *hw, u8 index) u32 shift = GET_SHIFT(hwdata->conf); const u32 clk_src_266 = 2; u32 msk, val, bitmask; + unsigned long flags; int ret; /* @@ -204,23 +205,25 @@ static int rzg2l_cpg_sd_clk_mux_set_parent(struct clk_hw *hw, u8 index) */ bitmask = (GENMASK(GET_WIDTH(hwdata->conf) - 1, 0) << shift) << 16; msk = off ? CPG_CLKSTATUS_SELSDHI1_STS : CPG_CLKSTATUS_SELSDHI0_STS; + spin_lock_irqsave(&priv->rmw_lock, flags); if (index != clk_src_266) { writel(bitmask | ((clk_src_266 + 1) << shift), priv->base + off); - ret = readl_poll_timeout(priv->base + CPG_CLKSTATUS, val, - !(val & msk), 100, - CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US); - if (ret) { - dev_err(priv->dev, "failed to switch clk source\n"); - return ret; - } + ret = readl_poll_timeout_atomic(priv->base + CPG_CLKSTATUS, val, + !(val & msk), 10, + CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US); + if (ret) + goto unlock; } writel(bitmask | ((index + 1) << shift), priv->base + off); - ret = readl_poll_timeout(priv->base + CPG_CLKSTATUS, val, - !(val & msk), 100, - CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US); + ret = readl_poll_timeout_atomic(priv->base + CPG_CLKSTATUS, val, + !(val & msk), 10, + CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US); +unlock: + spin_unlock_irqrestore(&priv->rmw_lock, flags); + if (ret) dev_err(priv->dev, "failed to switch clk source\n"); diff --git a/drivers/clk/renesas/rzg2l-cpg.h b/drivers/clk/renesas/rzg2l-cpg.h index 0b28870a6f9d..097fd8f61680 100644 --- a/drivers/clk/renesas/rzg2l-cpg.h +++ b/drivers/clk/renesas/rzg2l-cpg.h @@ -43,7 +43,7 @@ #define CPG_CLKSTATUS_SELSDHI0_STS BIT(28) #define CPG_CLKSTATUS_SELSDHI1_STS BIT(29) -#define CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US 20000 +#define CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US 200 /* n = 0/1/2 for PLL1/4/6 */ #define CPG_SAMPLL_CLK1(n) (0x04 + (16 * n)) -- 2.39.2