linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
To: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Cc: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>,
	Ben Dooks <ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org>,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Thomas Kavanagh
	<tkavanagh-3r7Miqu9kMnR7s880joybQ@public.gmane.org>,
	Guenter Roeck <groeck-3r7Miqu9kMnR7s880joybQ@public.gmane.org>
Subject: Re: [PATCH 2/2] i2c: (algo-pca) Fix mode selection for PCA9665
Date: Thu, 13 Sep 2012 06:44:39 -0700	[thread overview]
Message-ID: <20120913134439.GA1400@roeck-us.net> (raw)
In-Reply-To: <20120913100530.GD14237-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>

On Thu, Sep 13, 2012 at 12:05:31PM +0200, Wolfram Sang wrote:
> On Wed, Sep 12, 2012 at 08:39:51PM -0700, Guenter Roeck wrote:
> > From: Thomas Kavanagh <tkavanagh-3r7Miqu9kMnR7s880joybQ@public.gmane.org>
> > 
> > As implemented, the code always selects turbo mode for PCA9665, no matter which
> > clock frequency is configured. This is because it compares clock boundaries
> > against constants reflecting (boundary / 100), but uses the actual clock frequency
> > to compare against. To fix the problem, use a variable reflecting (clock / 100),
> > not the actual clock frequency, when comparing against (boundary / 100).
> 
> Good point, however...
> 
> > 
> > Cc: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
> > Signed-off-by: Thomas Kavanagh <tkavanagh-3r7Miqu9kMnR7s880joybQ@public.gmane.org>
> > Signed-off-by: Guenter Roeck <groeck-3r7Miqu9kMnR7s880joybQ@public.gmane.org>
> > ---
> >  drivers/i2c/algos/i2c-algo-pca.c |    6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
> > index 07ccbef..572251b 100644
> > --- a/drivers/i2c/algos/i2c-algo-pca.c
> > +++ b/drivers/i2c/algos/i2c-algo-pca.c
> > @@ -477,17 +477,17 @@ static int pca_init(struct i2c_adapter *adap)
> >  		/* To avoid integer overflow, use clock/100 for calculations */
> >  		clock = pca_clock(pca_data) / 100;
> >  
> > -		if (pca_data->i2c_clock > 10000) {
> > +		if (clock > 10000) {
> 
> ... we should make the code more readable if we are at it.
> I'd suggest to drop the "/ 100" from above and move it below this
> if-block. This will allow for much more readable comparisons, e.g.
> "clock > 1000000" etc which is really the clock in Hz.
> 
We can simply compare against the real frequency:
		if (pca_data->i2c_clock > 1000000) {
which also makes the description a bit easier to understand.

> >  			mode = I2C_PCA_MODE_TURBO;
> >  			min_tlow = 14;
> >  			min_thi  = 5;
> >  			raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
> > -		} else if (pca_data->i2c_clock > 4000) {
> > +		} else if (clock > 4000) {
> >  			mode = I2C_PCA_MODE_FASTP;
> >  			min_tlow = 17;
> >  			min_thi  = 9;
> >  			raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
> > -		} else if (pca_data->i2c_clock > 1000) {
> > +		} else if (clock > 1000) {
> >  			mode = I2C_PCA_MODE_FAST;
> >  			min_tlow = 44;
> >  			min_thi  = 20;
> > -- 
> > 1.7.9.7
> > 
> 
> -- 
> Pengutronix e.K.                           | Wolfram Sang                |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |

  parent reply	other threads:[~2012-09-13 13:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-13  3:39 [PATCH 1/2] i2c: (algo-pca) Fix chip reset function for PCA9665 Guenter Roeck
     [not found] ` <1347507591-32352-1-git-send-email-linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2012-09-13  3:39   ` [PATCH 2/2] i2c: (algo-pca) Fix mode selection " Guenter Roeck
     [not found]     ` <1347507591-32352-2-git-send-email-linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2012-09-13 10:05       ` Wolfram Sang
     [not found]         ` <20120913100530.GD14237-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-09-13 13:44           ` Guenter Roeck [this message]
2012-09-13 10:14   ` [PATCH 1/2] i2c: (algo-pca) Fix chip reset function " Wolfram Sang
     [not found]     ` <20120913101423.GE14237-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-09-13 13:41       ` Guenter Roeck
     [not found]         ` <20120913134128.GA1343-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
2012-09-13 23:14           ` Thomas Kavanagh
     [not found]             ` <CC77B638.1126D%tkavanagh-3r7Miqu9kMnR7s880joybQ@public.gmane.org>
2012-09-14 12:12               ` Wolfram Sang
     [not found]                 ` <20120914121244.GE2630-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-09-14 18:23                   ` Thomas Kavanagh
2012-09-14 12:51   ` Wolfram Sang

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=20120913134439.GA1400@roeck-us.net \
    --to=linux-0h96xk9xttrk1umjsbkqmq@public.gmane.org \
    --cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=groeck-3r7Miqu9kMnR7s880joybQ@public.gmane.org \
    --cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=tkavanagh-3r7Miqu9kMnR7s880joybQ@public.gmane.org \
    --cc=w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.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;
as well as URLs for NNTP newsgroup(s).