* [PATCH] at24: Fall back to byte or word reads if needed
@ 2010-03-08 7:50 Jean Delvare
[not found] ` <20100308085008.366915c3-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Jean Delvare @ 2010-03-08 7:50 UTC (permalink / raw)
To: Linux I2C; +Cc: Wolfram Sang, Konstantin Lazarev
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Subject: at24: Fall back to byte or word reads if needed
Increase the portability of the at24 driver by letting it read from
EEPROM chips connected to cheap SMBus controllers that support neither
raw I2C messages nor even I2C block reads. All SMBus controllers
should support either word reads or byte reads, so read support
becomes universal, much like with the legacy "eeprom" driver.
Obviously, this only works with EEPROM chips up to AT24C16, that use
8-bit offset addressing. 16-bit offset addressing is almost impossible
to support on SMBus controllers.
I did not add universal support for writes, as I had no immediate need
for this, but it could be added later if needed (with the same
performance issue as byte and word reads have, of course.)
Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Cc: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
Cc: Konstantin Lazarev <klazarev-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org>
---
Konstantin, please test and report.
drivers/misc/eeprom/at24.c | 47 +++++++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 9 deletions(-)
--- linux-2.6.33.orig/drivers/misc/eeprom/at24.c 2010-02-25 09:10:35.000000000 +0100
+++ linux-2.6.33/drivers/misc/eeprom/at24.c 2010-03-06 14:19:03.000000000 +0100
@@ -54,7 +54,7 @@
struct at24_data {
struct at24_platform_data chip;
struct memory_accessor macc;
- bool use_smbus;
+ int use_smbus;
/*
* Lock protects against activities from other Linux tasks,
@@ -184,10 +184,14 @@ static ssize_t at24_eeprom_read(struct a
if (count > io_limit)
count = io_limit;
- if (at24->use_smbus) {
+ if (at24->use_smbus == I2C_SMBUS_I2C_BLOCK_DATA) {
/* Smaller eeproms can work given some SMBus extension calls */
if (count > I2C_SMBUS_BLOCK_MAX)
count = I2C_SMBUS_BLOCK_MAX;
+ } else if (at24->use_smbus == I2C_SMBUS_WORD_DATA) {
+ count = 2;
+ } else if (at24->use_smbus == I2C_SMBUS_BYTE_DATA) {
+ count = 1;
} else {
/*
* When we have a better choice than SMBus calls, use a
@@ -219,9 +223,22 @@ static ssize_t at24_eeprom_read(struct a
timeout = jiffies + msecs_to_jiffies(write_timeout);
do {
read_time = jiffies;
- if (at24->use_smbus) {
+ if (at24->use_smbus == I2C_SMBUS_I2C_BLOCK_DATA) {
status = i2c_smbus_read_i2c_block_data(client, offset,
count, buf);
+ } else if (at24->use_smbus == I2C_SMBUS_WORD_DATA) {
+ status = i2c_smbus_read_word_data(client, offset);
+ if (status >= 0) {
+ buf[0] = status & 0xff;
+ buf[1] = status >> 8;
+ status = count;
+ }
+ } else if (at24->use_smbus == I2C_SMBUS_BYTE_DATA) {
+ status = i2c_smbus_read_byte_data(client, offset);
+ if (status >= 0) {
+ buf[0] = status;
+ status = count;
+ }
} else {
status = i2c_transfer(client->adapter, msg, 2);
if (status == 2)
@@ -434,7 +451,7 @@ static int at24_probe(struct i2c_client
{
struct at24_platform_data chip;
bool writable;
- bool use_smbus = false;
+ int use_smbus = 0;
struct at24_data *at24;
int err;
unsigned i, num_addresses;
@@ -475,12 +492,19 @@ static int at24_probe(struct i2c_client
err = -EPFNOSUPPORT;
goto err_out;
}
- if (!i2c_check_functionality(client->adapter,
+ if (i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
+ use_smbus = I2C_SMBUS_I2C_BLOCK_DATA;
+ } else if (i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_READ_WORD_DATA)) {
+ use_smbus = I2C_SMBUS_WORD_DATA;
+ } else if (i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
+ use_smbus = I2C_SMBUS_BYTE_DATA;
+ } else {
err = -EPFNOSUPPORT;
goto err_out;
}
- use_smbus = true;
}
if (chip.flags & AT24_FLAG_TAKE8ADDR)
@@ -565,11 +589,16 @@ static int at24_probe(struct i2c_client
dev_info(&client->dev, "%zu byte %s EEPROM %s\n",
at24->bin.size, client->name,
writable ? "(writable)" : "(read-only)");
+ if (use_smbus == I2C_SMBUS_WORD_DATA ||
+ use_smbus == I2C_SMBUS_BYTE_DATA) {
+ dev_notice(&client->dev, "Falling back to %s reads, "
+ "performance will suffer\n", use_smbus ==
+ I2C_SMBUS_WORD_DATA ? "word" : "byte");
+ }
dev_dbg(&client->dev,
- "page_size %d, num_addresses %d, write_max %d%s\n",
+ "page_size %d, num_addresses %d, write_max %d, use_smbus %d\n",
chip.page_size, num_addresses,
- at24->write_max,
- use_smbus ? ", use_smbus" : "");
+ at24->write_max, use_smbus);
/* export data to kernel code */
if (chip.setup)
--
Jean Delvare
^ permalink raw reply [flat|nested] 4+ messages in thread[parent not found: <20100308085008.366915c3-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>]
* Re: [PATCH] at24: Fall back to byte or word reads if needed [not found] ` <20100308085008.366915c3-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org> @ 2010-03-08 13:24 ` Wolfram Sang [not found] ` <20100308132454.GC3375-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> 2010-03-08 14:12 ` Ben Dooks 1 sibling, 1 reply; 4+ messages in thread From: Wolfram Sang @ 2010-03-08 13:24 UTC (permalink / raw) To: Jean Delvare; +Cc: Linux I2C, Konstantin Lazarev [-- Attachment #1: Type: text/plain, Size: 1649 bytes --] On Mon, Mar 08, 2010 at 08:50:08AM +0100, Jean Delvare wrote: > From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> > Subject: at24: Fall back to byte or word reads if needed > > Increase the portability of the at24 driver by letting it read from > EEPROM chips connected to cheap SMBus controllers that support neither > raw I2C messages nor even I2C block reads. All SMBus controllers > should support either word reads or byte reads, so read support > becomes universal, much like with the legacy "eeprom" driver. > > Obviously, this only works with EEPROM chips up to AT24C16, that use > 8-bit offset addressing. 16-bit offset addressing is almost impossible > to support on SMBus controllers. > > I did not add universal support for writes, as I had no immediate need > for this, but it could be added later if needed (with the same > performance issue as byte and word reads have, of course.) > > Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> > Cc: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> > Cc: Konstantin Lazarev <klazarev-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> I wondered a bit if switch-case would make the code more readable instead of if-elseif-elseif-else. But definately no show-stopper. I don't have hardware to actually test the new functionality, other than that it appears good to me. Thanks! Reviewed-by: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> -- Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ | [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 197 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <20100308132454.GC3375-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>]
* Re: [PATCH] at24: Fall back to byte or word reads if needed [not found] ` <20100308132454.GC3375-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> @ 2010-03-08 15:15 ` Jean Delvare 0 siblings, 0 replies; 4+ messages in thread From: Jean Delvare @ 2010-03-08 15:15 UTC (permalink / raw) To: Wolfram Sang; +Cc: Linux I2C, Konstantin Lazarev Hi Wolfram, On Mon, 8 Mar 2010 14:24:54 +0100, Wolfram Sang wrote: > On Mon, Mar 08, 2010 at 08:50:08AM +0100, Jean Delvare wrote: > > From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> > > Subject: at24: Fall back to byte or word reads if needed > > > > Increase the portability of the at24 driver by letting it read from > > EEPROM chips connected to cheap SMBus controllers that support neither > > raw I2C messages nor even I2C block reads. All SMBus controllers > > should support either word reads or byte reads, so read support > > becomes universal, much like with the legacy "eeprom" driver. > > > > Obviously, this only works with EEPROM chips up to AT24C16, that use > > 8-bit offset addressing. 16-bit offset addressing is almost impossible > > to support on SMBus controllers. > > > > I did not add universal support for writes, as I had no immediate need > > for this, but it could be added later if needed (with the same > > performance issue as byte and word reads have, of course.) > > > > Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> > > Cc: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> > > Cc: Konstantin Lazarev <klazarev-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> > > I wondered a bit if switch-case would make the code more readable instead of > if-elseif-elseif-else. But definately no show-stopper. Good point, I'll post an updated version soon. > I don't have hardware to actually test the new functionality, other than that > it appears good to me. Thanks! > > Reviewed-by: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org> Thanks for the review. -- Jean Delvare ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] at24: Fall back to byte or word reads if needed [not found] ` <20100308085008.366915c3-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org> 2010-03-08 13:24 ` Wolfram Sang @ 2010-03-08 14:12 ` Ben Dooks 1 sibling, 0 replies; 4+ messages in thread From: Ben Dooks @ 2010-03-08 14:12 UTC (permalink / raw) To: Jean Delvare; +Cc: Linux I2C, Wolfram Sang, Konstantin Lazarev On Mon, Mar 08, 2010 at 08:50:08AM +0100, Jean Delvare wrote: > From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> > Subject: at24: Fall back to byte or word reads if needed > > Increase the portability of the at24 driver by letting it read from > EEPROM chips connected to cheap SMBus controllers that support neither > raw I2C messages nor even I2C block reads. All SMBus controllers > should support either word reads or byte reads, so read support > becomes universal, much like with the legacy "eeprom" driver. > > Obviously, this only works with EEPROM chips up to AT24C16, that use > 8-bit offset addressing. 16-bit offset addressing is almost impossible > to support on SMBus controllers. > > I did not add universal support for writes, as I had no immediate need > for this, but it could be added later if needed (with the same > performance issue as byte and word reads have, of course.) It would be worth sorting out which i2c busses are exporting the correct functionality, I think for example the i2c-s3c2410.c driver is missing the I2C block functionality. -- Ben (ben-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org, http://www.fluff.org/) 'a smiley only costs 4 bytes' ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-03-08 15:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-08 7:50 [PATCH] at24: Fall back to byte or word reads if needed Jean Delvare
[not found] ` <20100308085008.366915c3-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-03-08 13:24 ` Wolfram Sang
[not found] ` <20100308132454.GC3375-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2010-03-08 15:15 ` Jean Delvare
2010-03-08 14:12 ` Ben Dooks
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox