Linux I2C development
 help / color / mirror / Atom feed
From: Kai-Heng Feng <kai.heng.feng@canonical.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: ajayg@nvidia.com, Wolfram Sang <wsa@the-dreams.de>,
	"open list:I2C CONTROLLER DRIVER FOR NVIDIA GPU"
	<linux-i2c@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status()
Date: Tue, 24 Mar 2020 22:39:22 +0800	[thread overview]
Message-ID: <AF4DCBBE-FF35-4B58-92EE-8BD804A502C4@canonical.com> (raw)
In-Reply-To: <20200324134124.GL1922688@smile.fi.intel.com>

Hi Andy,

> On Mar 24, 2020, at 21:41, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> 
> On Tue, Mar 24, 2020 at 09:07:12PM +0800, Kai-Heng Feng wrote:
>> Nvidia card may come with a "phantom" UCSI device, and its driver gets
>> stuck in probe routine, prevents any system PM operations like suspend.
>> 
>> When the target time equals to jiffies, it's not included by
>> time_is_before_jiffies(). So let's use a boolean to make sure the
>> operation is done or timeout.
> 
> Thank you for an update, my comments below.
> 
>> 	unsigned long target = jiffies + msecs_to_jiffies(1000);
>> 	u32 val;
>> +	bool done = false;
>> 
>> 	do {
>> 		val = readl(i2cd->regs + I2C_MST_CNTL);
>> -		if (!(val & I2C_MST_CNTL_CYCLE_TRIGGER))
>> -			break;
>> -		if ((val & I2C_MST_CNTL_STATUS) !=
>> -				I2C_MST_CNTL_STATUS_BUS_BUSY)
> 
>> +		if (!(val & I2C_MST_CNTL_CYCLE_TRIGGER)
>> +		    || (val & I2C_MST_CNTL_STATUS) !=
>> +				I2C_MST_CNTL_STATUS_BUS_BUSY) {
> 
> Bad formatting. But see below.
> 
>> +			done = true;
>> 			break;
>> +		}
>> 		usleep_range(500, 600);
>> 	} while (time_is_after_jiffies(target));
>> 
>> -	if (time_is_before_jiffies(target)) {
>> +	if (!done) {
>> 		dev_err(i2cd->dev, "i2c timeout error %x\n", val);
>> 		return -ETIMEDOUT;
>> 	}
> 
> 
> Overall it can use simple tries since you already have sleep inside, but
> moreover, you may simple switch to readl_poll_timeout() this entire
> loop.

Yes that can make the retry loop much simpler.
I'll send a v3 based on your suggestion.

Kai-Heng

> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
> 

      reply	other threads:[~2020-03-24 14:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24 13:07 [PATCH v2] i2c: nvidia-gpu: Handle timeout correctly in gpu_i2c_check_status() Kai-Heng Feng
2020-03-24 13:41 ` Andy Shevchenko
2020-03-24 14:39   ` Kai-Heng Feng [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=AF4DCBBE-FF35-4B58-92EE-8BD804A502C4@canonical.com \
    --to=kai.heng.feng@canonical.com \
    --cc=ajayg@nvidia.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /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