Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp484519lqj; Sun, 2 Jun 2024 07:31:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV1qCEgTyJXjbAzbK4Uru5VuPObcrejp45H5dTS1IAt2i9BIZFJwC5+Eckq43oXn4iCWGJp50ysdd6HYjtpxzZvMhHUfv7I5/G26ZhAtg== X-Google-Smtp-Source: AGHT+IFWVMITVKb+brxgbruLE/Dd+CvmVN/xfVX8+cFH6U9CU+Pt86GbSym665hmejOTDxLldwLo X-Received: by 2002:a17:906:c94d:b0:a67:aa2b:1028 with SMTP id a640c23a62f3a-a681fc5cbccmr513751166b.8.1717338714048; Sun, 02 Jun 2024 07:31:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717338714; cv=pass; d=google.com; s=arc-20160816; b=ZI2PmV16eTSgUY2zg638kirFsHObDiG96uSCAvzbEmochhOioWjO1QxJUO/o0V+XTr wFsSO7BW7bvbJAp/24fm7w9UoBuH/9UHQzpzDz2INTyrX1yp8ezTUmSfwveLKm4paN6R 35/YLaYeHsWzNeysMBNrX90G8bItwMbKj9e/egB4NOkCjby12G5qQbsPn7w+mBESn/Jc FweC15INNvHhGtBDQp7R0G8wL4Q+eOWwNobQjhCpChqhVhqY/+41A1qPzDuEWAvZT011 004QpSmutGAlFDRYZXyWYFxxvVWMkYp0WSZAgBJRhbHET0T2bKUzvPELF8wBhBeXVC4y H8fA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=RWGYwTysSvB1AzNEXTEGFJRM12Fxwodp6LFILw+wyVM=; fh=SWEAvucMncNA5XrKEJlkEFYyHwS9jEBp2ScJVZ5PXuw=; b=GgE26H/lmigp864+Oc6M9+Rl5WBWsuhuJRmQFTzd9rX09hpwDVLCrc4Lm2A6t+7qA6 BAjKcp8WLw0gjjdze9a9ZhiRPa3Lkjq0/GI6RMhMk67EqhQkHrR75a1IB+7Dvbd7KYa0 dDb/EA51MEVWnh3JKjY5hNleF3hCFvQ/4RzO5dWEQWyiFu8l9rUQbiVAUK7eAK05R9R2 rjN/AmvyGhlOnr8k37xw0We1VeZOb/Pr8T3noPYQ1Vr6XX3ZP9zrsJomJcmWEZPhSXYu HUQ4bEZPiLncYslv839PUcy1s1wCTv2pygFz9+f0oW6P8HHXB1jcJcpNt7SrzWH3E/YR F9yA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b="0kucGJq/"; arc=pass (i=1 spf=pass spfdomain=lunn.ch dkim=pass dkdomain=lunn.ch dmarc=pass fromdomain=lunn.ch); spf=pass (google.com: domain of linux-kernel+bounces-198291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a68a7ad5688si203052466b.6.2024.06.02.07.31.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 07:31:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b="0kucGJq/"; arc=pass (i=1 spf=pass spfdomain=lunn.ch dkim=pass dkdomain=lunn.ch dmarc=pass fromdomain=lunn.ch); spf=pass (google.com: domain of linux-kernel+bounces-198291-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198291-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lunn.ch 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 B48DC1F224CF for ; Sun, 2 Jun 2024 14:31:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F222E43172; Sun, 2 Jun 2024 14:31:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="0kucGJq/" Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (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 45488B64B; Sun, 2 Jun 2024 14:31:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717338704; cv=none; b=EmjDFPHi6rw8AQBLp54J8/qCI0es5XuLi6eZ8K1RrYnZeuVUCXusrTfhUZGd11H3ZTpp5HUh8X994nOdmxtceuiRzlbEdFfTWjBtL2Fe7CK7dJ6P8pAlWFF7T2E3aa4gjMqRg+J5XYxVxG6vVJAwSlMP529mDMInVg2eOf2vM4s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717338704; c=relaxed/simple; bh=CotbdNz9LHK9WkQCoFQqdqV3uDXLQoDBucayG0hD5MI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=R8fc63TBmsoD2OUzedrwH9nPBC+VB4ykpas16UjICO6HDp8/AIkgMW1yvlKnzb5Siqe4gslhyRYaXZRfWHHq16kZvkhNAjg+GxbuuyLdWZLwZgBRfbnmAEclhy7+u2Tt5JlHo+5kiUIh7q1leVh35QuXe+V8+7G9kNzO3/hCR6w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=0kucGJq/; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=RWGYwTysSvB1AzNEXTEGFJRM12Fxwodp6LFILw+wyVM=; b=0kucGJq/2zFxgbs7FdovI3m/Ll zpIf8Am8tEyQf0bBEC4b/ONEn+HRO5v/03B53Vtpg/CpaGoCUtIFF9MOQawlK2wVuOselEUlDvOpg II/vCIWvIBW04lULUZbw8wLLKiuxT+s6eHY9EQpNDcuOkeHmmod46dJTxqWNZ9DAG+1w=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1sDmF5-00Gc71-T9; Sun, 02 Jun 2024 16:31:27 +0200 Date: Sun, 2 Jun 2024 16:31:27 +0200 From: Andrew Lunn To: Stefan Eichenberger Cc: o.rempel@pengutronix.de, kernel@pengutronix.de, andi.shyti@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, jic23@kernel.org, lars@metafoo.de, nuno.sa@analog.com, andriy.shevchenko@linux.intel.com, u.kleine-koenig@pengutronix.de, marcelo.schmitt@analog.com, gnstark@salutedevices.com, francesco.dolcini@toradex.com, linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Stefan Eichenberger Subject: Re: [RFC PATCH] i2c: imx: avoid rescheduling when waiting for bus not busy Message-ID: References: <20240531142437.74831-1-eichest@gmail.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240531142437.74831-1-eichest@gmail.com> On Fri, May 31, 2024 at 04:24:37PM +0200, Stefan Eichenberger wrote: > From: Stefan Eichenberger > > On our i.MX8M Mini based module we have an ADS1015 I2C ADC connected to > the I2C bus. The ADS1015 I2C ADC will timeout after 25ms when the I2C > bus is idle. The imx i2c driver will call schedule when waiting for the > bus to become idle after switching to master mode. When the i2c > controller switches to master mode it pulls SCL and SDA low, if the > ADS1015 I2C ADC sees this for more than 25 ms without seeing SCL > clocking, it will timeout and ignore all signals until the next start > condition occurs (SCL and SDA low). Does the I2C specification say anything about this behaviour, or is it specific to this device? > This rfc tries to solve the problem by using a udelay for the first 10 > ms before calling schedule. This reduces the chance that we will > reschedule. However, it is still theoretically possible for the problem > to occur. To properly solve the problem, we would also need to disable > interrupts during the transfer. > > After some internal discussion, we see three possible solutions: > 1. Use udelay as shown in this rfc and also disable the interrupts > during the transfer. This would solve the problem but disable the > interrupts. Also, we would have to re-enable the interrupts if the > timeout is longer than 1ms (TBD). > 2. We use a retry mechanism in the ti-ads1015 driver. When we see a > timeout, we try again. > 3. We use the suggested solution and accept that there is an edge case > where the timeout can happen. 2. has the advantage you fix it for any system with this device, not just those using an IMX. Once question would be, is such a retry safe in all conditions. Does the timeout happen before any non idempotent operation is performed? If the I2C specification allows this behaviour, maybe a more generic solution is needed, since it could affect more devices? Andrew