Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp239206lqr; Wed, 5 Jun 2024 04:55:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVvszLkfT8OQC1u/3yJBPQDZcXw5qL2opaAc17QXU9CqEs1MV5Y4MEA65e5nDqspn/XZ8M+ZTJDxBDcYzNQN/tU3WTWDxq6x7DSnGrBUA== X-Google-Smtp-Source: AGHT+IFXAPzw7BQLvwaV64vnlzsFEzIsnwa9sOLGvZo1uSQrsHuoGIRIt5QSNWtdPWegNijkkpsZ X-Received: by 2002:a17:907:36c:b0:a65:2b64:f84a with SMTP id a640c23a62f3a-a69546b0a23mr439793966b.25.1717588543008; Wed, 05 Jun 2024 04:55:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717588542; cv=pass; d=google.com; s=arc-20160816; b=vhSOIHwFD6fujlb2vms2U2vvM53Li2BCxbhoJY3E1Nm6riOPXTS1c5+f/dDvAQ23tb mWDr/Nv+ttideOs3pNuadD/l0W5I+F2QOoWjHA4wiCYjyhXJg9JK9SHgHDJYUfJXn7nC Ht+wVPTpcn4/i4k0kjKpa71w+nGntnMe0ZADSrwp5uINbo7tvRQ+kk9KqnZ+Fk2nHbU6 ospYkFQkIyFRaWZlp8p1S0wQcuFas7I9Wzeox3TyN6bmTpEpjq6lU/vOzS7Xihd2FcaV dllEVqhTo5lUppOLgqtECbhNf24xJETwpQjZg5K0jFj5+Ej0Pc1i912KaRL9JRr5rsqI xSXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=MhHxCKuOByhdtjD9fOaQ+veq88D09o/uzEBMS85JRjw=; fh=wITi/tg0tG6ns0HgRqhkE4OF3K4Wo9DwGxDcQlvE7Rg=; b=Bxc5tG/nn6wpsjWR8Uf1vWN8H96+sZjxJ17OGsN4dhopjPGC7AzrglmMbFqU27826E sUFbePF7Sh5zFuIWM1+PO/Bbf8nHX3cvKstp7szLkcXFSPhYPo78ai3V40woGaqecsym hML5cFOZFWKiIJtcjvLx+6oTPjoPWSrlZj6OWWUgk1yiBwwY8Zp7imOEPep9w1QxcG4f ocouSWvMZw0SD9ZZd2+0CFCNTI4x7KLbVsSldap3URNLcez1FrQtAmkccOlWhH3uEXdK skunfnDePqI4tH6dsno2iNI9vTjj+6GJNqDUGm8R0r2T3TLk8HfSWg3nK9SAG0cMZzUT P7Sw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fMskRonR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202322-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a67ea99159esi597015666b.539.2024.06.05.04.55.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 04:55:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fMskRonR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202322-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202322-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9768E1F245C4 for ; Wed, 5 Jun 2024 11:55:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88EE619A286; Wed, 5 Jun 2024 11:50:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fMskRonR" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9818A1990D4; Wed, 5 Jun 2024 11:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588217; cv=none; b=H8GOXRzqVxLPrU2xvy/XBvH7Wb9lOzoqy7YSuUYXhLhtTkas1uqQhWiN7GjBMprzBcVw3u7u4R7HWoow3sTvZOxeNT7fNfDj9dCpdaqU2sL4TYmAq8zEI9IbjYXN5pwVgBFDxVK4TxVFSsrBh1/FIbTSr7Wb2O6+dRQRnkaGMo0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588217; c=relaxed/simple; bh=ofMFuZutyc8UqgcT5XmcJ+uqQ0V9bPSOejxM9gZ7iic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eKM0ZhqMUVYdPSee2tbHRxLuvqNaIuWp5KnTsIO0BPZfFZRBLL3Hu1+gFCS3bcB8AGmRwHLIBymP3vLy3+wA2lYl3riCN4sjXJlbuFnE2pXijLgeBn33hgq2GqyhELADSd5D2n4VGD/Apl6SG+KwK83uAGhZIcPVrHQZUrmBQaI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fMskRonR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4FE3C4AF07; Wed, 5 Jun 2024 11:50:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588217; bh=ofMFuZutyc8UqgcT5XmcJ+uqQ0V9bPSOejxM9gZ7iic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fMskRonRrRM6NmUpu7eFzU4ZWSt+5/GZnDifC3g5BBKW+cIyLqr00OYR8rRxZ9UsL 5WFQvNnsU6NRPay7sxnmi/L7cbw0Twi85pDxxneGixBjvBodQdw3ntmd2a4kpJbbRN rQhIXHckPbbWOtUKKwfNUJ/y0iR/067B76ZOOaX0r1/NSCsgwu2S5yRBMiY7iBuZf1 fDuz2gjYcniE5jgW7mJBrOKynD0taRtEo6ScCGWMZTZ0bXlUrkdbNHdvJ9KKf9MHtt NWHD4YX2sJyOfTOieCbn7d3dMJgHM9Ixc1KEi4aFpSuHw/ItNh6xukkB0zQYke9+J1 c4NeqYaU1cVBQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alexander Stein , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Andi Shyti , Sasha Levin , aisheng.dong@nxp.com, shawnguo@kernel.org, linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 6.9 21/28] i2c: lpi2c: Avoid calling clk_get_rate during transfer Date: Wed, 5 Jun 2024 07:48:50 -0400 Message-ID: <20240605114927.2961639-21-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605114927.2961639-1-sashal@kernel.org> References: <20240605114927.2961639-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.9.3 Content-Transfer-Encoding: 8bit From: Alexander Stein [ Upstream commit 4268254a39484fc11ba991ae148bacbe75d9cc0a ] Instead of repeatedly calling clk_get_rate for each transfer, lock the clock rate and cache the value. A deadlock has been observed while adding tlv320aic32x4 audio codec to the system. When this clock provider adds its clock, the clk mutex is locked already, it needs to access i2c, which in return needs the mutex for clk_get_rate as well. Signed-off-by: Alexander Stein Reviewed-by: Uwe Kleine-König Reviewed-by: Andi Shyti Signed-off-by: Andi Shyti Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-imx-lpi2c.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c index 6d72e4e126dde..36e8f6196a87b 100644 --- a/drivers/i2c/busses/i2c-imx-lpi2c.c +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c @@ -99,6 +99,7 @@ struct lpi2c_imx_struct { __u8 *rx_buf; __u8 *tx_buf; struct completion complete; + unsigned long rate_per; unsigned int msglen; unsigned int delivered; unsigned int block_data; @@ -212,9 +213,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx) lpi2c_imx_set_mode(lpi2c_imx); - clk_rate = clk_get_rate(lpi2c_imx->clks[0].clk); - if (!clk_rate) - return -EINVAL; + clk_rate = lpi2c_imx->rate_per; if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST) filt = 0; @@ -611,6 +610,20 @@ static int lpi2c_imx_probe(struct platform_device *pdev) if (ret) return ret; + /* + * Lock the parent clock rate to avoid getting parent clock upon + * each transfer + */ + ret = devm_clk_rate_exclusive_get(&pdev->dev, lpi2c_imx->clks[0].clk); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "can't lock I2C peripheral clock rate\n"); + + lpi2c_imx->rate_per = clk_get_rate(lpi2c_imx->clks[0].clk); + if (!lpi2c_imx->rate_per) + return dev_err_probe(&pdev->dev, -EINVAL, + "can't get I2C peripheral clock rate\n"); + pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_get_noresume(&pdev->dev); -- 2.43.0