From: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
Subject: Re: [PATCH] Add a new-style driver for most I2C EEPROMs
Date: Fri, 11 Apr 2008 14:24:55 +0200 [thread overview]
Message-ID: <ftnlao$o2r$1@ger.gmane.org> (raw)
In-Reply-To: <1207914198-8561-1-git-send-email-w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Hello,
I'll just review myself to ask for some comments where I think some more
opinions would be good. I also tried to contact David Brownell as the
original author directly last week, but all my mails got blocked; I hope
we can negotiate through this list.
I tested this version of the driver on a blackfin based board with a
24c02. In the next days, a powerpc based board with a X24645 (strange
one) will follow. On x86 and x86-64, it builds without warnings.
> + * at24.c - handle most I2C EEPROMs
Maybe rename the driver? at24 is vendor-specific. 24xx? 24cxx?
eeprom-ng? I'd go for 24xx.
> +/* One chip may consume up to this numbe of clients */
> +#define AT24_MAX_CLIENTS 8
> +
> +struct at24_data {
> + struct at24_platform_data chip;
> + bool use_smbus;
> +
> + /* Lock protects against activities from other Linux tasks,
> + * but not from changes by other I2C masters.
> + */
> + struct mutex lock;
> + struct bin_attribute bin;
> +
> + /* Some chips tie up multiple I2C addresses; dummy devices reserve
> + * them for ourselves, and we'll use them with SMBus calls.
> + */
> + struct i2c_client *client[AT24_MAX_CLIENTS];
> +
> + u8 *writebuf;
> + unsigned write_max;
> +};
To support the X24645, it would be necessary to raise AT24_MAX_CLIENTS
to 32 (what a beast!). Then again, most eeproms will just need one
client, so this would cause quite some overhead in most use-cases. Maybe
it pays off to hande this dynamically?
> +/*
> + * This routine supports chips which consume multiple I2C addresess. It
> + * computes the addressing information to be used for a given r/w request.
> + */
> +static struct i2c_client *at24_ee_address(
> + struct at24_data *at24,
> + u16 *addr,
> + unsigned *offset
> +)
> +{
> + unsigned per_address = 256;
> + struct at24_platform_data *chip = &at24->chip;
> + unsigned i;
> +
> + if (*offset >= chip->byte_len)
> + return NULL;
> +
> + if (chip->flags & AT24_EE_ADDR2)
> + per_address = 64 * 1024;
> + *addr = at24->client[0]->addr;
> + for (i = 0; *offset >= per_address; i++) {
> + (*addr)++;
> + *offset -= per_address;
> + }
> +
> + return at24->client[i];
> +}
I would suggest shortening it like this, unless I fail to see a drawback:
---
static struct i2c_client *at24_ee_address(
struct at24_data *at24,
u16 *addr,
unsigned *offset
)
{
const struct chip_desc *chip = &at24->chip;
unsigned i;
if (*offset >= chip->byte_len)
return NULL;
if (chip->flags & EE_ADDR2) {
i = *offset >> 16;
*offset &= 0xffff;
} else {
i = *offset >> 8;
*offset &= 0x00ff;
}
*addr = at24->client[i]->addr;
return at24->client[i];
}
---
This will save the for-loop and a variable.
> + /* Export the EEPROM bytes through sysfs, since that's convenient.
> + * By default, only root should see the data (maybe passwords etc)
> + */
> + at24->bin.attr.name = "eeprom";
> + at24->bin.attr.mode = S_IRUSR;
> + at24->bin.attr.owner = THIS_MODULE;
> + at24->bin.read = at24_bin_read;
> +
> + at24->bin.size = at24->chip.byte_len;
Use C99 initialization in struct at24_data above?
I guess, there is more to come during the discussion. But hopefully,
this is a start to get it into 2.6.26... That would be great!
Kind regards,
Wolfram
--
Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de
Pengutronix - Linux Solutions for Science and Industry
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
next prev parent reply other threads:[~2008-04-11 12:24 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-11 11:43 [PATCH] Add a new-style driver for most I2C EEPROMs Wolfram Sang
[not found] ` <1207914198-8561-1-git-send-email-w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-04-11 12:24 ` Wolfram Sang [this message]
2008-04-14 7:22 ` Robert Schwebel
[not found] ` <20080414072227.GU13814-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-04-14 12:39 ` Jean Delvare
[not found] ` <20080414143925.31b55b39-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-04-14 15:57 ` David Brownell
[not found] ` <200804140857.33732.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-04-17 21:17 ` David Brownell
[not found] ` <200804171417.23753.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-04-18 8:07 ` Trent Piepho
[not found] ` <Pine.LNX.4.58.0804172346580.10592-nuiHJn5p267P3RPoUHIrnuTW4wlIGRCZ@public.gmane.org>
2008-04-18 10:31 ` Wolfram Sang
[not found] ` <20080418103149.GA4245-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-04-18 23:06 ` Trent Piepho
[not found] ` <Pine.LNX.4.58.0804181555560.15372-13q4cmjDBaTP3RPoUHIrnuTW4wlIGRCZ@public.gmane.org>
2008-04-21 9:17 ` Wolfram Sang
2008-04-21 17:20 ` Trent Piepho
[not found] ` <Pine.LNX.4.58.0804211005410.15697-nuiHJn5p267P3RPoUHIrnuTW4wlIGRCZ@public.gmane.org>
2008-04-24 10:47 ` Wolfram Sang
[not found] ` <20080424104740.GB4201-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-04-27 1:28 ` Trent Piepho
2008-04-18 16:48 ` David Brownell
[not found] ` <200804180948.15298.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-04-18 23:26 ` Trent Piepho
2008-04-18 8:59 ` Wolfram Sang
2008-04-15 10:13 ` Wolfram Sang
2008-04-17 16:05 ` Wolfram Sang
2008-04-17 16:24 ` Jean Delvare
-- strict thread matches above, loose matches on Subject: below --
2008-05-15 20:36 Wolfram Sang
[not found] ` <1210883799-25188-1-git-send-email-w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-05-22 20:20 ` Jean Delvare
[not found] ` <20080522222022.68d65cd7-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-22 21:35 ` David Brownell
[not found] ` <200805221435.36829.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-05-23 7:17 ` Jean Delvare
[not found] ` <20080523091703.2ba86bb1-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-24 21:11 ` David Brownell
2008-05-30 9:15 ` Wolfram Sang
[not found] ` <20080530091534.GB727-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-05-30 9:51 ` Jean Delvare
[not found] ` <20080530115131.0e111fdb-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-05-30 10:45 ` Wolfram Sang
2008-06-02 16:21 ` Wolfram Sang
[not found] ` <20080602162154.GA11141-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2008-06-02 18:50 ` Jean Delvare
[not found] ` <20080602205034.3e2b392b-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-02 19:33 ` David Brownell
[not found] ` <200806021233.46781.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-02 19:48 ` Jean Delvare
[not found] ` <20080602214823.15ca190b-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-03 20:36 ` David Brownell
[not found] ` <200806031336.35678.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2008-06-03 21:19 ` Jean Delvare
[not found] ` <20080603231927.61f9eb61-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-04 11:51 ` Wolfram Sang
2008-06-08 8:40 ` Jean Delvare
[not found] ` <20080608104038.006be072-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-06-08 20:26 ` David Brownell
2008-05-23 7:21 ` 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='ftnlao$o2r$1@ger.gmane.org' \
--to=w.sang-bicnvbalz9megne8c9+irq@public.gmane.org \
--cc=i2c-GZX6beZjE8VD60Wz+7aTrA@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