From patchwork Mon Oct 14 13:15:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13835252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 041CBD1812A for ; Mon, 14 Oct 2024 15:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FUH25x79k8EHQsto7o4HWXcz+cLM47kx/MicJivdg7g=; b=z0qDRWV8fD2RpoEcdrUk5P0Nz0 K2sEoJcJFb78E3gABsLyIv+MWD9084KiFRbDSs+n8w06ZbFlbuZGLi/Ds9wMJFQ2lqBTf4YjqKzGV oL0BBkoG6pU+AGgzyJVkPsMqTa5m5J+VRyvq+82jyA2QPfFluVmeyOU/H/WIwi6FQTBcMgbBD4OQ9 mP/dVMzCojD4zRWbrxUi57BnZN24d8C3ENhQZHrzT+iQT0ID8MylDWCjAhG099F+X6wJF60pitlus uX5ujHc/9MOf/Io/FScIk1JmV8Fxr+ryB724CDXjf+Cp0xHhxj3WTjlsjVopFOpz50nr50COdGUcG ZqJsr6+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0N5m-00000005fdd-1D7S; Mon, 14 Oct 2024 15:34:42 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t0KwK-00000005EJ7-2xUJ for linux-arm-kernel@bombadil.infradead.org; Mon, 14 Oct 2024 13:16:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=FUH25x79k8EHQsto7o4HWXcz+cLM47kx/MicJivdg7g=; b=RKDg/aoag7egcruEZvcCQQkd8t JKElTS8Xo8/zi5BxWv9Sfs6ROyjm7iouXtJDbEHmjMKFKk0LVI64wFCStLsg3y0oq0J2P9ACxqIiA ElrRNGsaeQF4qSUFSWoL4PP+AKlUjTaDtaaGG7muWPkfIEgWjSj31UbZaYauGICWFf+PyGMRTz1fw xhcrCRzZVQOuoLhGh+l/eT8Ja60KCcjYjM6wVdkVTCws2qYir9lYK9hVQAlvY7i40nKoRXuuCHfrg MEQjy5LxWGDBHLujMKkj3LvTopVv+retkmrmq8DDsEfeyYehvfxlEUBpyGZoPpZntLpLLyb7AVT+G edgdiHJA==; Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t0KwH-00000006LUl-1mnj for linux-arm-kernel@lists.infradead.org; Mon, 14 Oct 2024 13:16:47 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-431160cdbd0so26772595e9.1 for ; Mon, 14 Oct 2024 06:16:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728911802; x=1729516602; darn=lists.infradead.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=FUH25x79k8EHQsto7o4HWXcz+cLM47kx/MicJivdg7g=; b=itTCIhUoWAyN0pot1jK0nYUczM632ExWzpywC0hxrl/eDCL1Pgy0VfyHSIyDm5DsU7 mIbSwHkPqiB2NCHq21xaPReUxHq9CjCwIsRGq04R6ZZrO0bk7y+ha7wppzSJ4Vv6G5Qt O9PGU9dK79rP1siJO7sWxfUsaeDgPoni/pxVginXBagQb/Gu2j1plwRreeXvBt/u7mil 3/ZwBFPQPeFCXEuU/pHq1fEN9pPIrAZrjT3Cl2mgosf7GorvdxqUxEd+olPzzqSljdrw rbwW5bo88X1LEm6vdxLGprOckLyQg1KW0Qt2/+aAyLBpBIeBOYO3JUfz4I2eugN4T1jh IS5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728911802; x=1729516602; 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=FUH25x79k8EHQsto7o4HWXcz+cLM47kx/MicJivdg7g=; b=AFM6P1SJh9iEbruFUiTNlcnw2YCOvFtOZim81YxFUjAPLi021RT9940FFTR6iWoKma PGpZVB0ZiaKKXT/167KwbYXE7txoqGJ1hQq4+pW43rqxRb2uzlI/J3z9CMKshpfkfRyf AUAry/mH7RDIXPxJTYJnXX2KlZDFOYc1KGVoFkf4jdfa/rsb1qQ8H7lPEzxa/o2NOTIm D6ploJEVxc6F4GuGpe4s9LijL+YpW8waTrIJ4lCiWP17XYqEo4OeHMBkZzCp06jrYhMJ WtRE0TE6NisiOMAWncKSTKj+CQVK0HB06+bd3+gLe3mqJjNm06cM3B83yNxvkmtLsWOB eDFA== X-Forwarded-Encrypted: i=1; AJvYcCWzmo0+4/e06Ff6fxZM6vjtO/mcUHpyVXv0h7/ngobeEmFFRMfvvBcUMS6ZL/WMY8menyHVSI5w5mwky4uoLS8k@lists.infradead.org X-Gm-Message-State: AOJu0YwoHVfhuDEsr0YRjFefhja+pcvGag87QSEFj29RIWxvwK+WWXwG 4rBY65Z/DqjNNtVL5E8uRXjrR2PgGa9TsqlupczYHG8uVQ/MvYgc X-Google-Smtp-Source: AGHT+IHFCOhkWsbSszMYyapdJCiM6wV55PCzOwhLCTtrrsuvQ5Od0oVlQ1v7sPpCFmpXOlc0aIrgWA== X-Received: by 2002:a05:600c:3106:b0:431:136b:8bef with SMTP id 5b1f17b1804b1-43115aa52a6mr133830585e9.7.1728911802065; Mon, 14 Oct 2024 06:16:42 -0700 (PDT) Received: from eichest-laptop.lan ([2a02:168:af72:0:d130:f8ef:c6c1:55ee]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-430d748d42fsm153420425e9.43.2024.10.14.06.16.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 06:16:41 -0700 (PDT) From: Stefan Eichenberger To: o.rempel@pengutronix.de, kernel@pengutronix.de, andi.shyti@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, francesco.dolcini@toradex.com, l.stach@pengutronix.de, arnd@arndb.de, Frank.Li@nxp.com Cc: linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Stefan Eichenberger Subject: [PATCH v5 1/3] i2c: imx: do not poll for bus busy in single master mode Date: Mon, 14 Oct 2024 15:15:12 +0200 Message-ID: <20241014131635.205489-2-eichest@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241014131635.205489-1-eichest@gmail.com> References: <20241014131635.205489-1-eichest@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241014_141645_629766_C5CA8197 X-CRM114-Status: GOOD ( 17.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Stefan Eichenberger According to the i.MX8M Mini reference manual chapter "16.1.4.2 Generation of Start" it is only necessary to poll for bus busy and arbitration lost in multi master mode. This helps to avoid rescheduling while the i2c bus is busy and avoids SMBus devices to timeout. For backward compatibility, the single-master property needs to be explicitly set to disable the bus busy polling. Signed-off-by: Stefan Eichenberger Reviewed-by: Frank Li Acked-by: Oleksij Rempel --- @Frank and Oleksij: I kept your tags even though I made multi-master the new default. Let me know if you have any objections. drivers/i2c/busses/i2c-imx.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 98539313cbc97..d697abd2459d4 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -216,6 +216,8 @@ struct imx_i2c_struct { struct i2c_client *slave; enum i2c_slave_event last_slave_event; + bool multi_master; + /* For checking slave events. */ spinlock_t slave_lock; struct hrtimer slave_timer; @@ -481,6 +483,9 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a unsigned long orig_jiffies = jiffies; unsigned int temp; + if (!i2c_imx->multi_master) + return 0; + while (1) { temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); @@ -540,8 +545,8 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx, bool atomic) return -ETIMEDOUT; } - /* check for arbitration lost */ - if (i2c_imx->i2csr & I2SR_IAL) { + /* In multi-master mode check for arbitration lost */ + if (i2c_imx->multi_master && (i2c_imx->i2csr & I2SR_IAL)) { dev_dbg(&i2c_imx->adapter.dev, "<%s> Arbitration lost\n", __func__); i2c_imx_clear_irq(i2c_imx, I2SR_IAL); @@ -1468,6 +1473,12 @@ static int i2c_imx_probe(struct platform_device *pdev) goto rpm_disable; } + /* + * We use the single-master property for backward compatibility. + * By default multi master mode is enabled. + */ + i2c_imx->multi_master = !of_property_read_bool(pdev->dev.of_node, "single-master"); + /* Set up clock divider */ i2c_imx->bitrate = I2C_MAX_STANDARD_MODE_FREQ; ret = of_property_read_u32(pdev->dev.of_node,