public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Stefan Eichenberger <eichest@gmail.com>
To: Frank Li <Frank.li@nxp.com>
Cc: o.rempel@pengutronix.de, kernel@pengutronix.de,
	andi.shyti@kernel.org, shawnguo@kernel.org,
	s.hauer@pengutronix.de, festevam@gmail.com,
	wsa+renesas@sang-engineering.com, francesco.dolcini@toradex.com,
	joao.goncalves@toradex.com, linux-i2c@vger.kernel.org,
	imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Stefan Eichenberger <stefan.eichenberger@toradex.com>
Subject: Re: [PATCH v1 3/3] i2c: imx: prevent rescheduling in non dma mode
Date: Tue, 16 Jul 2024 17:05:28 +0200	[thread overview]
Message-ID: <ZpaMOHhs1uDPAuKe@eichest-laptop> (raw)
In-Reply-To: <ZpVWXlR6j2i0ZtVQ@lizhi-Precision-Tower-5810>

Hi Frank,

On Mon, Jul 15, 2024 at 01:03:26PM -0400, Frank Li wrote:
> > +static inline void i2c_imx_isr_read_continue(struct imx_i2c_struct *i2c_imx)
> > +{
> > +	unsigned int temp;
> > +
> > +	if ((i2c_imx->msg->len - 1) == i2c_imx->msg_buf_idx) {
> > +		if (i2c_imx->is_lastmsg) {
> > +			/*
> > +			 * It must generate STOP before read I2DR to prevent
> > +			 * controller from generating another clock cycle
> > +			 */
> > +			temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
> > +			if (!(temp & I2CR_MSTA))
> > +				i2c_imx->stopped =  1;
> > +			temp &= ~(I2CR_MSTA | I2CR_MTX);
> > +			imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
> > +		} else {
> > +			/*
> > +			 * For i2c master receiver repeat restart operation like:
> > +			 * read -> repeat MSTA -> read/write
> > +			 * The controller must set MTX before read the last byte in
> > +			 * the first read operation, otherwise the first read cost
> > +			 * one extra clock cycle.
> > +			 */
> > +			temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
> > +			temp |= I2CR_MTX;
> > +			imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
> > +		}
> > +	} else if (i2c_imx->msg_buf_idx == (i2c_imx->msg->len - 2)) {
> > +		temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
> > +		temp |= I2CR_TXAK;
> > +		imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
> > +	}
> > +
> > +	i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR);
> 
> Why not use loop to read all data from FIFO? I think read_reg use readb(),
> suggest change to readb_relaxed(). The similar case for writeb. dma_engine
> will use writel() at least once when start DMA. it should be enough for
> memory barrier. 
> 
> Because it move to irq handle, writex__relaxed() will help reduce some
> register access time.
> 

I think there is not FIFO on the i.MX I2C controller, or do I miss
something? In the i.MX 8M Plus reference manual they write for example:
> In Master Receive mode, reading the data register allows a read to occur
> and initiates the next byte to be received.

I will test the changes with readb_relaxed() and writeb_relaxed() and
see what happens, thanks a lot for the hint.

Regards,
Stefan

      reply	other threads:[~2024-07-16 15:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-15 15:17 [PATCH v1 0/3] i2c: imx: prevent rescheduling in non-dma mode Stefan Eichenberger
2024-07-15 15:17 ` [PATCH v1 1/3] i2c: imx: only poll for bus busy in multi master mode Stefan Eichenberger
2024-07-15 16:32   ` Frank Li
2024-07-15 15:17 ` [PATCH v1 2/3] i2c: imx: separate atomic, dma and non-dma use case Stefan Eichenberger
2024-07-15 16:44   ` Frank Li
2024-07-15 15:17 ` [PATCH v1 3/3] i2c: imx: prevent rescheduling in non dma mode Stefan Eichenberger
2024-07-15 17:03   ` Frank Li
2024-07-16 15:05     ` Stefan Eichenberger [this message]

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=ZpaMOHhs1uDPAuKe@eichest-laptop \
    --to=eichest@gmail.com \
    --cc=Frank.li@nxp.com \
    --cc=andi.shyti@kernel.org \
    --cc=festevam@gmail.com \
    --cc=francesco.dolcini@toradex.com \
    --cc=imx@lists.linux.dev \
    --cc=joao.goncalves@toradex.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=stefan.eichenberger@toradex.com \
    --cc=wsa+renesas@sang-engineering.com \
    /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