All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Cc: Andi Shyti <andi.shyti@kernel.org>, Yixun Lan <dlan@gentoo.org>,
	Alex Elder <elder@riscstar.com>,
	Michael Opdenacker <michael.opdenacker@rootcommit.com>,
	Troy Mitchell <troymitchell988@gmail.com>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-riscv@lists.infradead.org, spacemit@lists.linux.dev
Subject: Re: [PATCH] i2c: spacemit: fix detect issue
Date: Thu, 6 Nov 2025 19:17:00 +0100	[thread overview]
Message-ID: <aQzmHB2FaPFS4qwj@aurel32.net> (raw)
In-Reply-To: <0E2B2679F0650AE1+aQw0VgKNbcFqDH33@kernel.org>

Hi,

On 2025-11-06 13:38, Troy Mitchell wrote:
> On Thu, Nov 06, 2025 at 06:34:26AM +0100, Aurelien Jarno wrote:
> > Hi,
> > 
> > On 2025-11-06 09:05, Troy Mitchell wrote:
> > > On Wed, Nov 05, 2025 at 11:44:00PM +0100, Aurelien Jarno wrote:
> > > > Hi,
> > > > 
> > > > On 2025-11-03 15:06, Troy Mitchell wrote:
> > > [...]
> > > > >  	if (i2c->status & (SPACEMIT_SR_BED | SPACEMIT_SR_ALD)) {
> > > > >  		spacemit_i2c_reset(i2c);
> > > > > -		return -EAGAIN;
> > > > > +		if (i2c->status & SPACEMIT_SR_ALD)
> > > > > +			return -EAGAIN;
> > > > >  	}
> > > > 
> > > > This makes the resulting code, while correct, complex to understand as 
> > > > it is now two really different errors, as you explained well in the 
> > > > commit message.
> > > > 
> > > > I therefore suggest to organize the code as:
> > > > 
> > > > 	/* Arbitration Loss Detected */
> > > > 	if (i2c->status & SPACEMIT_SR_ALD) {
> > > > 		spacemit_i2c_reset(i2c);
> > > > 		return -EAGAIN;
> > > > 	}
> > > > 
> > > > 	/* Bus Error No ACK/NAK */
> > > > 	if (i2c->status & SPACEMIT_SR_BED) {
> > > > 		spacemit_i2c_reset(i2c);
> > > > 	}
> > > Thanks. I'll fix it in the next version.
> > > > 
> > > > 
> > > > >  	return i2c->status & SPACEMIT_SR_ACKNAK ? -ENXIO : -EIO;
> > > > > @@ -491,6 +492,8 @@ static int spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, in
> > > > >  
> > > > >  	spacemit_i2c_init(i2c);
> > > > >  
> > > > > +	spacemit_i2c_clear_int_status(i2c, SPACEMIT_I2C_INT_STATUS_MASK);
> > > > > +
> > > > 
> > > > This sounds good to start the transfer with a clean interrupt state. I 
> > > > just wonder if it should be moved to spacemit_i2c_init(), ie where the 
> > > > corresponding interrupts are enabled.
> > > Uh, We can move it actually. But is it essentail?
> > 
> > For me ensuring that the interrupt status is in a clean state after 
> > enabling the interrupt is part of the initialization.
> Yes, I agree that.
> > Furthermore if 
> > spacemit_i2c_init() has to be called from another place, it's very 
> > likely that it's also needed to get interrupt status in a clean state.
> Why we need to call init() in other place?
> Could you give me a cese?

Currently there is no need to do that. However if the driver is extended 
(e.g. to add new features) and spacemit_i2c_init() needs to be called 
from another place, it is likely that a reset of the interrupt status 
should also be included. Therefore it's better to just include it 
directly in spacemit_i2c_init().

Regards
Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net

WARNING: multiple messages have this Message-ID (diff)
From: Aurelien Jarno <aurelien@aurel32.net>
To: Troy Mitchell <troy.mitchell@linux.spacemit.com>
Cc: Andi Shyti <andi.shyti@kernel.org>, Yixun Lan <dlan@gentoo.org>,
	Alex Elder <elder@riscstar.com>,
	Michael Opdenacker <michael.opdenacker@rootcommit.com>,
	Troy Mitchell <troymitchell988@gmail.com>,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-riscv@lists.infradead.org, spacemit@lists.linux.dev
Subject: Re: [PATCH] i2c: spacemit: fix detect issue
Date: Thu, 6 Nov 2025 19:17:00 +0100	[thread overview]
Message-ID: <aQzmHB2FaPFS4qwj@aurel32.net> (raw)
In-Reply-To: <0E2B2679F0650AE1+aQw0VgKNbcFqDH33@kernel.org>

Hi,

On 2025-11-06 13:38, Troy Mitchell wrote:
> On Thu, Nov 06, 2025 at 06:34:26AM +0100, Aurelien Jarno wrote:
> > Hi,
> > 
> > On 2025-11-06 09:05, Troy Mitchell wrote:
> > > On Wed, Nov 05, 2025 at 11:44:00PM +0100, Aurelien Jarno wrote:
> > > > Hi,
> > > > 
> > > > On 2025-11-03 15:06, Troy Mitchell wrote:
> > > [...]
> > > > >  	if (i2c->status & (SPACEMIT_SR_BED | SPACEMIT_SR_ALD)) {
> > > > >  		spacemit_i2c_reset(i2c);
> > > > > -		return -EAGAIN;
> > > > > +		if (i2c->status & SPACEMIT_SR_ALD)
> > > > > +			return -EAGAIN;
> > > > >  	}
> > > > 
> > > > This makes the resulting code, while correct, complex to understand as 
> > > > it is now two really different errors, as you explained well in the 
> > > > commit message.
> > > > 
> > > > I therefore suggest to organize the code as:
> > > > 
> > > > 	/* Arbitration Loss Detected */
> > > > 	if (i2c->status & SPACEMIT_SR_ALD) {
> > > > 		spacemit_i2c_reset(i2c);
> > > > 		return -EAGAIN;
> > > > 	}
> > > > 
> > > > 	/* Bus Error No ACK/NAK */
> > > > 	if (i2c->status & SPACEMIT_SR_BED) {
> > > > 		spacemit_i2c_reset(i2c);
> > > > 	}
> > > Thanks. I'll fix it in the next version.
> > > > 
> > > > 
> > > > >  	return i2c->status & SPACEMIT_SR_ACKNAK ? -ENXIO : -EIO;
> > > > > @@ -491,6 +492,8 @@ static int spacemit_i2c_xfer(struct i2c_adapter *adapt, struct i2c_msg *msgs, in
> > > > >  
> > > > >  	spacemit_i2c_init(i2c);
> > > > >  
> > > > > +	spacemit_i2c_clear_int_status(i2c, SPACEMIT_I2C_INT_STATUS_MASK);
> > > > > +
> > > > 
> > > > This sounds good to start the transfer with a clean interrupt state. I 
> > > > just wonder if it should be moved to spacemit_i2c_init(), ie where the 
> > > > corresponding interrupts are enabled.
> > > Uh, We can move it actually. But is it essentail?
> > 
> > For me ensuring that the interrupt status is in a clean state after 
> > enabling the interrupt is part of the initialization.
> Yes, I agree that.
> > Furthermore if 
> > spacemit_i2c_init() has to be called from another place, it's very 
> > likely that it's also needed to get interrupt status in a clean state.
> Why we need to call init() in other place?
> Could you give me a cese?

Currently there is no need to do that. However if the driver is extended 
(e.g. to add new features) and spacemit_i2c_init() needs to be called 
from another place, it is likely that a reset of the interrupt status 
should also be included. Therefore it's better to just include it 
directly in spacemit_i2c_init().

Regards
Aurelien

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2025-11-06 18:17 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-03  7:06 [PATCH] i2c: spacemit: fix detect issue Troy Mitchell
2025-11-03  7:06 ` Troy Mitchell
2025-11-05 22:44 ` Aurelien Jarno
2025-11-05 22:44   ` Aurelien Jarno
2025-11-06  1:05   ` Troy Mitchell
2025-11-06  1:05     ` Troy Mitchell
2025-11-06  5:34     ` Aurelien Jarno
2025-11-06  5:34       ` Aurelien Jarno
2025-11-06  5:38       ` Troy Mitchell
2025-11-06  5:38         ` Troy Mitchell
2025-11-06 18:17         ` Aurelien Jarno [this message]
2025-11-06 18:17           ` Aurelien Jarno
2025-11-07  1:22           ` Troy Mitchell
2025-11-07  1:22             ` Troy Mitchell

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=aQzmHB2FaPFS4qwj@aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=andi.shyti@kernel.org \
    --cc=dlan@gentoo.org \
    --cc=elder@riscstar.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=michael.opdenacker@rootcommit.com \
    --cc=spacemit@lists.linux.dev \
    --cc=troy.mitchell@linux.spacemit.com \
    --cc=troymitchell988@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.