public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: "Voss, Nikolaus" <N.Voss@weinmann.de>
Cc: "'linux-i2c@vger.kernel.org'" <linux-i2c@vger.kernel.org>,
	"'linux-arm-kernel@lists.infradead.org'" 
	<linux-arm-kernel@lists.infradead.org>,
	"'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>,
	"'ben-linux@fluff.org'" <ben-linux@fluff.org>,
	"'carsten.behling@garz-fricke.com'"
	<carsten.behling@garz-fricke.com>
Subject: Re: [PATCH v7 3/5] drivers/i2c/busses/i2c-at91.c: add new driver
Date: Thu, 24 Nov 2011 15:39:06 +0000	[thread overview]
Message-ID: <201111241539.06990.arnd@arndb.de> (raw)
In-Reply-To: <EF2E73589CA71846A15D0B2CDF79505D087B44FEAF@wm021.weinmann.com>

On Thursday 24 November 2011, Voss, Nikolaus wrote:
> > 
> > > +/*
> > > + * Calculate and set symmetric clock as stated in datasheet:
> > > + * twi_clk = F_MAIN / (2 * cdiv * (1 << ckdiv) + 4)
> > > + */
> > > +static void __devinit at91_set_twi_clock(struct at91_twi_dev *dev, int
> > twi_clk)
> > > +{
> > > +   const int div = DIV_ROUND_UP(clk_get_rate(dev->clk), 2 * twi_clk) - 2;
> > > +   int ckdiv = fls(div >> 8);
> > > +   const int cdiv = div >> ckdiv;
> > > +
> > > +   if (cpu_is_at91rm9200() && (ckdiv > 5)) {
> > > +           dev_warn(dev->dev, "AT91RM9200 erratum 22: using ckdiv = 5.\n");
> > > +           ckdiv = 5;
> > > +   }
> > 
> > Don't check a global property like this locally in the driver. Instead,
> > make it a property of the device that you check here and set it based on
> > the the device name set by the platform, or by a device tree property.
> 
> Yes, this is a known problem and was discussed in
> https://lkml.org/lkml/2011/11/8/217 . The main problem is that there a no
> revisions for specific at91 IP devices but the revision is implicitly
> defined by the cpu type and version. Changing this would need to add some
> arch infrastructure which I think is beyond the scope of this driver.

Aside from the flamewar in that thread, my impression is that in general
people (me certainly) prefer to have driver-local workarounds be expressed
in a driver specific way, not in a platform or architecture specific way
because that makes the driver less portable.

Anyway, I don't see this point as a show-stopper since the driver is already
platform specific, but it's generally a good idea to write code like this
defensively, if only to avoid getting comments about it.

> > > diff --git a/drivers/i2c/busses/i2c-at91.h b/drivers/i2c/busses/i2c-at91.h
> > > new file mode 100644
> > > index 0000000..a898159
> > > --- /dev/null
> > > +++ b/drivers/i2c/busses/i2c-at91.h
> > > @@ -0,0 +1,80 @@
> > > +
> > > +#ifndef AT91_TWI_H
> > > +#define AT91_TWI_H
> > > +
> > 
> > No need for a header file if all the values in it are used in only one
> > source file. Just move everything to i2c_at91.c
> > 
> > > +#define    AT91_TWI_MMR            0x04            /* Master Mode Register */
> > > +#define    AT91_TWI_IADRSZ         (3    <<  8)    /* Internal Device Address
> > > +                                            *  Size */
> > > +#define    AT91_TWI_IADRSZ_NO      (0 << 8)
> > > +#define    AT91_TWI_IADRSZ_1       (1 << 8)
> > > +#define    AT91_TWI_IADRSZ_2       (2 << 8)
> > > +#define    AT91_TWI_IADRSZ_3       (3 << 8)
> > > +#define    AT91_TWI_MREAD          (1    << 12)    /* Master Read Direction
> > */
> > > +#define    AT91_TWI_DADR           (0x7f << 16)    /* Device Address */
> > 
> > These are harder to read than just using hexadecimal bitmasks:
> > 
> > #define       AT91_TWI_MMR            0x00000004
> > #define       AT91_TWI_IADRSZ         0x00000300
> > #define       AT91_TWI_IADRSZ_NO      0x00000000
> > #define       AT91_TWI_IADRSZ_1       0x00000100
> > ...
> 
> I agree, but this header file was already used by the old driver and
> converting would add possible errors to register definitions which are
> not (yet) used. That's why I've left it as is and just made it a local
> include.

But you are presenting the driver as a new one, so you should be
prepared to get review comments like any other new code.

Please at least move the data into the main driver file to get rid of
the header file.

	Arnd

  reply	other threads:[~2011-11-24 15:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-23 15:35 [PATCH v7 0/5] AT91: replace broken TWI driver i2c-at91.c Nikolaus Voss
2011-11-08 10:49 ` [PATCH v7 1/5] drivers/i2c/busses/i2c-at91.c: remove broken driver Nikolaus Voss
2011-11-08 10:49 ` [PATCH v7 3/5] drivers/i2c/busses/i2c-at91.c: add new driver Nikolaus Voss
2011-11-23 16:18   ` Arnd Bergmann
2011-11-24 10:33     ` Voss, Nikolaus
2011-11-24 15:39       ` Arnd Bergmann [this message]
2011-11-24 16:36         ` Voss, Nikolaus
2011-11-24 16:47           ` Arnd Bergmann
2011-11-08 11:09 ` [PATCH v7 2/5] Replace clk_lookup.con_id with clk_lookup.dev_id entries for twi clk Nikolaus Voss
2011-11-08 11:11 ` [PATCH v7 4/5] G45 TWI: remove open drain setting for twi function gpios Nikolaus Voss
2011-11-18 11:38 ` [PATCH v7 5/5] i2c-at91.c: add SMBUS_READ_BLOCK_DATA functionality Nikolaus Voss
2011-11-23 23:32 ` [PATCH v7 0/5] AT91: replace broken TWI driver i2c-at91.c Ben Dooks
2011-11-24  6:33   ` Voss, Nikolaus
2011-11-24 22:13     ` Ryan Mallon
2011-11-25 15:42 ` Hubert Feurstein
2011-12-28 13:36   ` AW: " Carsten Behling
2012-01-11 14:06     ` Voss, Nikolaus

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=201111241539.06990.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=N.Voss@weinmann.de \
    --cc=ben-linux@fluff.org \
    --cc=carsten.behling@garz-fricke.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.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