From: u.kleine-koenig@pengutronix.de (Uwe Kleine-König)
To: linux-arm-kernel@lists.infradead.org
Subject: i2c: imx: could not read data
Date: Mon, 30 Jul 2012 09:38:21 +0200 [thread overview]
Message-ID: <20120730073821.GJ1528@pengutronix.de> (raw)
In-Reply-To: <CAD9ZU8BLrMbh684DN_Pyj0y-EtbvALKvtBUYUz+iVj00SNHstQ@mail.gmail.com>
Hello,
On Sat, Jul 28, 2012 at 10:07:35PM +0200, Gabriel Tisan wrote:
> I have the following environment :
> - Kernel based on 3.2.21 with custom changes and with commit (bb79a07)
> "i2c: imx: fix imx driver to work though signal is pending" applied
> - board based on imx35 derived from Freescale i.MX35 3-stack eval board
>
> I try to read some data from I2C by following userspace application,
> but I get some error:
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <errno.h>
>
> #include <linux/i2c-dev.h>
>
> int main() {
> int file, i;
> char filename[20];
> char buf[3];
> int adapter_nr = 0; /* I2C-0 */
> int addr = 0x08; /* The I2C address */
> char reg = 0x07; /* Device register to access */
>
> snprintf(filename, 19, "/dev/i2c-%d", adapter_nr);
> file = open(filename, O_RDWR);
> if (file < 0) {
> printf("%s: open failed: %s\n",file, strerror(errno));
> exit(1);
> }
>
> if (ioctl(file, I2C_SLAVE, addr) < 0) {
> printf("%s: set slave address failed: %s\n",file, strerror(errno));
> exit(1);
> }
>
> buf[0] = reg;
> buf[1] = 0;
> buf[2] = 0;
> if (write(file, buf, 1) != 1) {
> printf("%s: write failed: %s\n",file, strerror(errno));
> exit(1);
> }
>
> if (read(file, buf, 2) != 2) {
> printf("%s: read failed: %s\n",filename, strerror(errno));
> exit(1);
> } else {
> printf("Read bytes\n");
> /* buf contains the ID bytes */
> printf("ID: ");
> for (i=0; i<2; i++) {
> printf("%02x ",buf[i]);
> }
> }
> return 0;
> }
>
> Here is the debug log with the error that I get when i run the program
> from above:
> i2c i2c-0: ioctl, cmd=0x703, arg=0x08
> i2c-dev: i2c-0 writing 1 bytes.
> i2c i2c-0: master_xfer[0] W, addr=0x08, len=1
> i2c i2c-0: <i2c_imx_xfer>
> i2c i2c-0: <i2c_imx_start>
> i2c i2c-0: <i2c_imx_bus_busy>
> i2c i2c-0: <i2c_imx_xfer> transfer message: 0
> i2c i2c-0: <i2c_imx_xfer> CONTROL: IEN=1, IIEN=1, MSTA=1, MTX=1, TXAK=1, RSTA=0
> i2c i2c-0: <i2c_imx_xfer> STATUS: ICF=1, IAAS=0, IBB=1, IAL=0, SRW=0,
> IIF=0, RXAK=1
> i2c i2c-0: <i2c_imx_write> write slave address: addr=0x10
> i2c i2c-0: <i2c_imx_trx_complete> TRX complete
> i2c i2c-0: <i2c_imx_acked> ACK received
> i2c i2c-0: <i2c_imx_write> write data
> i2c i2c-0: <i2c_imx_write> write byte: B0=0x7
> i2c i2c-0: <i2c_imx_trx_complete> TRX complete
> i2c i2c-0: <i2c_imx_acked> ACK received
> i2c i2c-0: <i2c_imx_stop>
> i2c i2c-0: <i2c_imx_bus_busy>
> i2c i2c-0: <i2c_imx_xfer> exit with: success msg: 1
> i2c-dev: i2c-0 reading 2 bytes.
> i2c i2c-0: master_xfer[0] R, addr=0x08, len=2
> i2c i2c-0: <i2c_imx_xfer>
> i2c i2c-0: <i2c_imx_start>
> i2c i2c-0: <i2c_imx_bus_busy>
> i2c i2c-0: <i2c_imx_xfer> transfer message: 0
> i2c i2c-0: <i2c_imx_xfer> CONTROL: IEN=1, IIEN=1, MSTA=1, MTX=1, TXAK=1, RSTA=0
> i2c i2c-0: <i2c_imx_xfer> STATUS: ICF=1, IAAS=0, IBB=1, IAL=0, SRW=0,
> IIF=0, RXAK=1
> i2c i2c-0: <i2c_imx_read> write slave address: addr=0x11
> i2c i2c-0: <i2c_imx_trx_complete> TRX complete
> i2c i2c-0: <i2c_imx_acked> No ACK
> i2c i2c-0: <i2c_imx_stop>
> i2c i2c-0: <i2c_imx_bus_busy>
> i2c i2c-0: <i2c_imx_xfer> exit with: error: -5
>
> Using i2ctools it seems that with i2c everything is fine:
> # i2cdetect -l
> i2c-0i2c imx-i2c I2C adapter
> i2c-1i2c imx-i2c I2C adapter
> i2c-2i2c imx-i2c I2C adapter
> # i2cdetect -y 0
> 0 1 2 3 4 5 6 7 8 9 a b c d e f
> 00: -- -- -- -- -- 08 -- -- -- -- -- -- --
> 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> 70: -- -- -- -- -- -- -- --
> # i2cget -y 0 0x08 07 w
> 0x4100
>
> How you can see using i2ctools I can read without any errors from
> register 07 of slave device 08 found on i2c-0.
> On the same board using an old kernel 2.6.32.16 I can read data from
> i2c-0 using my userspace app.
>
> Has anybody some suggestions what could I try to go forward ?
As your problem seems to be more i2c related than arm related I suggest
asking your question on the i2c list.
Other than that I'd take a look into the source of i2cget.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |
prev parent reply other threads:[~2012-07-30 7:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-28 20:07 i2c: imx: could not read data Gabriel Tisan
2012-07-30 7:38 ` Uwe Kleine-König [this message]
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=20120730073821.GJ1528@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).