public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Cc: David Brownell <david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>,
	i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
Subject: Re: [PATCH v3] New-style I2C and SMBus EEPROM driver (with	device_ids)
Date: Tue, 10 Jun 2008 15:43:47 +0200	[thread overview]
Message-ID: <20080610134347.GA4210@pengutronix.de> (raw)
In-Reply-To: <20080608115033.5dd91786-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>


[-- Attachment #1.1: Type: text/plain, Size: 3208 bytes --]

Hi Jean,

thanks again for your review!

> As said before, I don't think it's needed, but if you and David insist
> on picking all addresses of the 24C00, so be it.

A new issue is now that some 24C01 also have this behaviour, so I guess the
flag should be renamed from AT24_FLAG_24C00 to AT24_FLAG_TAKE8ADDR or
something.

> > +/*-------------------------------------------------------------------------*/
> > +
> > +static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
> > +{
> > +	struct at24_platform_data *chip;
> > +	bool writable;
> > +	bool use_smbus = false;
> > +	struct at24_data *at24;
> > +	int err;
> > +	unsigned i, num_addresses;
> > +	kernel_ulong_t magic;
> > +
> > +	if (id->driver_data) {
> > +		chip = kmalloc(sizeof(struct at24_platform_data), GFP_KERNEL);
> > +		if (!chip) {
>
> You allocate this just to copy it to another structure and free it
> immediately. Allocating the other structure (struct at24_data) earlier
> would save this temporary allocation. Alternatively, just put the struct
> at24_platform_data on the stack, it's small enough to do so.

I can't allocate at24_data beforehand, as I need to know num_addresses,
so I can then calculate the actual size of at24_data. Will use the stack.

> > +		if (!at24->client[i]) {
> > +			dev_err(&client->dev, "address 0x%04x unavailable\n",
> 
> These are 7-bit addresses, so: 0x%02x.

I was unsure because of the 10-bit-addresses (and %03x looked even more
unusual). Will revert to %02x.

> > +/*
> > + * Chip data. Parameters are byte_len, page_size and flags
> > + */
> > +
> > +/* 128 bit chip, I2C A0-A2 ignored */
> > +#define AT24_DATA_24C00 128 / 8, 1, AT24_FLAG_24C00
> > +
> > +/* 1 Kbit chip, some have 16 byte pages: 24lc014, ... */
> > +#define AT24_DATA_24C01 1024 / 8, 8, 0
> 
> The Atmel 24C01 datasheet says page size is 4 bytes, and the Microchip
> 24C01A datasheet says 2 bytes. So defaulting to 8 doesn't look safe.

Will go back to 2 because of Microchip. But 24C01 seems to have lots of
variants, which makes a generic entry difficult. Some would need
AT24_FLAG_24C00 (doesn't really matter), and AT24C01 needs 128
addresses?? (please, someone, prove me wrong)

> You're going to quite some extent to obfuscate simple things ;) All

I wanted to make the transition from at24_v2 to at24_v3 easier by
reusing the defines containing chip data. I agree though, that the
benefit is mainly for those who already dared to use this driver (is
there anyone besides David and me?), and not for upstream. Will try to
make it more simple.

> In the end, the only things that must go in at24.h are the definition
> of struct at24_platform_data and its flags. All the rest is internal to
> the driver and should go in at24.c.

I wanted to have the AT24_SIZE_* flags next to the struct, so I won't
forget to change their size if anything inside the struct will change.
Then again, I might work with sizeof here; the result will probably look
a bit nasty, too...

All the best,

   Wolfram

-- 
  Dipl.-Ing. Wolfralfum Sang | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 157 bytes --]

_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c

  parent reply	other threads:[~2008-06-10 13:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-05 19:31 [PATCH v3] New-style I2C and SMBus EEPROM driver (with device_ids) Wolfram Sang
     [not found] ` <20080605193103.GA13062-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-06-08  9:50   ` Jean Delvare
     [not found]     ` <20080608115033.5dd91786-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-10 13:43       ` Wolfram Sang [this message]
     [not found]         ` <20080610134347.GA4210-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-06-10 16:54           ` Jean Delvare
     [not found]             ` <20080610185443.14a4516e-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-11  7:33               ` Wolfram Sang
     [not found]                 ` <20080611073323.GA4257-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-06-11  9:09                   ` Jean Delvare
     [not found]                     ` <20080611110921.5bf770dd-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-11 16:49                       ` David Brownell
2008-06-10 21:02       ` David Brownell
     [not found]         ` <200806101402.44392.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-11  7:02           ` Jean Delvare
     [not found]             ` <20080611090256.30031c79-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-11 17:25               ` David Brownell
     [not found]                 ` <200806111025.08951.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-11 19:41                   ` Jean Delvare
     [not found]                     ` <20080611214135.090ea690-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-12 21:17                       ` David Brownell
     [not found]                         ` <200806121417.51446.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-13  8:16                           ` Jean Delvare
     [not found]                             ` <20080613101644.6333fcff-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-07-01 13:20                               ` Wolfram Sang
     [not found]                                 ` <20080701132050.GA3836-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-07-01 14:28                                   ` Jean Delvare
2008-06-08  9:53   ` Jean Delvare

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=20080610134347.GA4210@pengutronix.de \
    --to=w.sang-bicnvbalz9megne8c9+irq@public.gmane.org \
    --cc=david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org \
    --cc=i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org \
    --cc=khali-PUYAD+kWke1g9hUCZPvPmw@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