public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Krzysztof Hałasa" <khalasa@piap.pl>
To: linux-media <linux-media@vger.kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	Oleksij Rempel <linux@rempel-privat.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	linux-i2c@vger.kernel.org,
	Stefan Lengfeld <contact@stefanchrist.eu>
Subject: Re: Sony IMX290/462 image sensors I2C xfer peculiarity
Date: Wed, 11 Oct 2023 11:50:12 +0200	[thread overview]
Message-ID: <m3jzrttrmz.fsf@t19.piap.pl> (raw)
In-Reply-To: <m3o7h5tthf.fsf@t19.piap.pl> ("Krzysztof Hałasa"'s message of "Wed, 11 Oct 2023 11:10:20 +0200")

Hi,

adding more people to Cc: as this is more general stuff than my specific
image sensor setup.

Is there any reason for the following (meta) patch to not be applied?

Currently, every i.MX8MP atomic I2C transfer starts with 100 us delay
(just after the START condition). At 400 kHz bus (384 kHz or whatever),
this is equivalent to several tens of bits. Is this delay needed?

This is on NXP 5.15 branch, but it seems the mainline is identical here.

With this patch, the 1-byte (quasi) atomic image sensor register reads
(16-bit address + 8-bit value) are down to ca. 160 us, and writes take
120 us.

It seems one bit on the bus takes ca. 2.66 us (hardware), and the delay
between consecutive bytes is ca. 4.82 us (I guess CPU takes a fair share
of this). This is i.MX8MP @ apparently 1200 MHz (1600 MHz with freq
scaler).

Fire away.
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -534,xx +534,xx @@
 static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool atomic)
 {
     unsigned long orig_jiffies = jiffies;
     unsigned int temp;
 
     while (1) {
         temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
 
         /* check for arbitration lost */
         if (temp & I2SR_IAL) {
             i2c_imx_clear_irq(i2c_imx, I2SR_IAL);
             return -EAGAIN;
         }
 
         if (for_busy && (temp & I2SR_IBB)) {
             i2c_imx->stopped = 0;
             break;
         }
         if (!for_busy && !(temp & I2SR_IBB)) {
             i2c_imx->stopped = 1;
             break;
         }
         if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
             dev_dbg(&i2c_imx->adapter.dev,
                 "<%s> I2C bus is busy\n", __func__);
             return -ETIMEDOUT;
         }
         if (atomic)
-            udelay(100);
+            udelay(1);
         else
             schedule();
     }
 
     return 0;
 }
-- 
Krzysztof "Chris" Hałasa

Sieć Badawcza Łukasiewicz
Przemysłowy Instytut Automatyki i Pomiarów PIAP
Al. Jerozolimskie 202, 02-486 Warszawa

  reply	other threads:[~2023-10-11  9:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-29 10:53 Sony IMX290/462 image sensors I2C xfer peculiarity Krzysztof Hałasa
2023-09-29 13:33 ` Dave Stevenson
2023-10-03 12:59   ` Krzysztof Hałasa
2023-10-10  9:46     ` Krzysztof Hałasa
2023-10-11  9:10       ` Krzysztof Hałasa
2023-10-11  9:50         ` Krzysztof Hałasa [this message]
2023-10-11 10:15           ` Stefan Lengfeld
2023-10-11 11:25             ` Krzysztof Hałasa
2023-10-11 11:59               ` Alexander Stein
2023-10-11 12:18                 ` Krzysztof Hałasa
2023-10-12 22:01               ` Stefan Lengfeld
2023-10-13  7:17                 ` Wolfram Sang
2023-10-13 10:39                 ` Krzysztof Hałasa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3jzrttrmz.fsf@t19.piap.pl \
    --to=khalasa@piap.pl \
    --cc=contact@stefanchrist.eu \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux@rempel-privat.de \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox