public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
To: Aleksandar Ivanov <ivanov.aleks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: at24 driver - a possible problem
Date: Thu, 5 Nov 2009 18:25:37 +0100	[thread overview]
Message-ID: <20091105172537.GA3332@pengutronix.de> (raw)
In-Reply-To: <533f29860911050810w4d939b39x2ad11c189f13c977-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 4720 bytes --]

Hello Aleksandar,

thank you for your very detailed and very good bug-report. I need to do some
tests myself tomorrow, but I think your assumptions are correct. Possibly we
need a similar loop for the read case. I'll add the linux-i2c-list to cc for
more opinions.

Regards,

   Wolfram

On Thu, Nov 05, 2009 at 06:10:12PM +0200, Aleksandar Ivanov wrote:
> Hello Mr Brownell and Mr Sang,
> 
> I've been experimenting with the at24 driver I want to make sure that
> what I encountered is not a limitation or a bug of the driver.
> The problem that I am experiencing is that a read operation
> immediately after a write.
> 
> Here is my testing environment:
> I am using a Linux kernel 2.6.30.3 and have a board with a AT24C512 eeprom chip.
> I am using the linux system calls read and write. At the end of the
> e-mail is the source of the test app that I'm using, which does the
> following:
> 1. Opens the eeprom file for reading and writing.
> 2. Performs a 10 byte read.
> 3. Performs a 10 byte write.
> 4. Performs a 10 byte read.
> 
> The final read fails with the errno seto to ENXIO (6 /* No such device
> or address */).
> 
> I've compiled the driver with debug information so here is the log
> corresponding to the execution of the test application:
> 
> i2c-adapter i2c-0: master_xfer[0] W, addr=0x50, len=2
> i2c-adapter i2c-0: master_xfer[1] R, addr=0x50, len=10
> at24 0-0050: i2c read 10@0 --> 2
> i2c-adapter i2c-0: master_xfer[0] W, addr=0x50, len=12
> at24 0-0050: write 10@10 --> 10 (597993)
> i2c-adapter i2c-0: master_xfer[0] W, addr=0x50, len=2
> i2c-adapter i2c-0: master_xfer[1] R, addr=0x50, len=10
> at24 0-0050: i2c read 10@20 --> -6
> 
> The failure is not in 100% of the cases. What I also noted is that if
> I insert a usleep() call, or just a for loop with enough cycles, the
> final read succeeds.
> After looking carefully at your code I found that when in a write
> operation you are expecting that a previous write might still be in
> progress.
> While this is not the case in the read operation.
> Could this be the problem that I am experiencing - the final read
> fails, because the previous write operation is not finished, and the
> read does not have a timeout protection.
> 
> If you need more information, I'll be glad to help.
> Thanks in advance for your consideration!
> Aleks
> 
> 
> Here is the source of the test app:
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <string.h>
> #include <errno.h>
> 
> #define EPPROM_FILE_NAME    "/sys/class/i2c-adapter/i2c-0/0-0050/eeprom"
> 
> int main(int argc, char *argv[])
> {
>     char            buf[10];
>     int             bytes = 0;
>     const unsigned  len = sizeof(buf);
>     int             fd = -1;
> 
>     fd = open(EPPROM_FILE_NAME, O_RDWR | O_SYNC);
>     if (-1 == fd)
>     {
>         printf("Error opening EEPROM file %s: %s.\n",
> EPPROM_FILE_NAME, strerror(errno));
>         return -1;
>     }
> 
>     bytes = read(fd, buf, len);
> 
>     if ((bytes > 0) &&
>         (len == (unsigned)bytes))
>     {
>         printf("Data read.\n");
>     }
>     else
>     {
>         printf("Failed to read from %s, bytes = %d, errno = %d, %s\n",
> EPPROM_FILE_NAME, bytes, errno, strerror(errno));
>         close(fd);
>         return -1;
>     }
> 
>     bytes = write(fd, buf, len);
> 
>     if ((bytes > 0) &&
>         (len == (unsigned)bytes))
>     {
>         printf("Data written.\n");
>     }
>     else
>     {
>         printf("Failed to write to %s, bytes = %d, %s\n",
> EPPROM_FILE_NAME, bytes, strerror(errno));
>         close(fd);
>         return -1;
>     }
> 
>     bytes = read(fd, buf, len);         // This call fails
> 
>     if ((bytes > 0) &&
>         (len == (unsigned)bytes))
>     {
>         printf("Data read.\n");
>     }
>     else
>     {
>         printf("Failed to read from %s, bytes = %d, errno = %d, %s\n",
> EPPROM_FILE_NAME, bytes, errno, strerror(errno));
>         close(fd);
>         return -1;
>     }
> 
>     close(fd);
>     return 0;
> }
> 
> 
> Here is the log from my test application:
> "Data read.
> Data written.
> Failed to read from /sys/class/i2c-adapter/i2c-0/0-0050/eeprom, bytes
> = -1, errno = 6, No such device or address"

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-5064 |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

       reply	other threads:[~2009-11-05 17:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <533f29860911050810w4d939b39x2ad11c189f13c977@mail.gmail.com>
     [not found] ` <533f29860911050810w4d939b39x2ad11c189f13c977-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-11-05 17:25   ` Wolfram Sang [this message]
     [not found]     ` <20091105172537.GA3332-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-06 12:15       ` at24 driver - a possible problem Jean Delvare
     [not found]         ` <20091106131524.76ae52b9-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-11-06 12:49           ` Wolfram Sang
     [not found]             ` <20091106124905.GA3980-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-06 12:57               ` Aleksandar Ivanov
     [not found]                 ` <533f29860911060457m70a1adfcr2dd11f0785748014-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-11-06 20:58                   ` David Brownell
     [not found]                     ` <200911061258.52179.david-b-yBeKhBN/0LDR7s880joybQ@public.gmane.org>
2009-11-08 20:23                       ` Wolfram Sang
     [not found]                         ` <20091108202331.GA6374-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-08 21:30                           ` David Brownell
2009-11-09  8:46                           ` Jean Delvare
     [not found]                             ` <20091109094638.2f05b29f-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-11-09  9:10                               ` Wolfram Sang
     [not found]                                 ` <20091109091045.GA3983-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-09 12:24                                   ` Aleksandar Ivanov
2009-11-08 20:14           ` [PATCH] at24: use timeout also for read Wolfram Sang
     [not found]             ` <1257711297-19927-1-git-send-email-w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-16 18:50               ` Wolfram Sang
     [not found]                 ` <20091116185030.GB21491-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-16 18:56                   ` Jean Delvare
2009-11-22 20:08               ` Jean Delvare
     [not found]                 ` <20091122210846.14666e23-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-11-25  8:09                   ` Jean Delvare
     [not found]                     ` <20091125090907.3e4e9155-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-11-25  9:20                       ` Wolfram Sang
2009-11-25  9:37                   ` [PATCH V2] " Wolfram Sang
     [not found]                     ` <1259141876-15458-1-git-send-email-w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2009-11-25 10:24                       ` 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=20091105172537.GA3332@pengutronix.de \
    --to=w.sang-bicnvbalz9megne8c9+irq@public.gmane.org \
    --cc=dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=ivanov.aleks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@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