From: Masahiro Yamada <yamada.m@jp.panasonic.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 01/10] dm: i2c: Add a uclass for I2C
Date: Thu, 04 Dec 2014 11:01:45 +0900 [thread overview]
Message-ID: <20141204110145.314F.AA925319@jp.panasonic.com> (raw)
In-Reply-To: <1416855444-32016-2-git-send-email-sjg@chromium.org>
Hi Simon,
More comments again.
On Mon, 24 Nov 2014 11:57:15 -0700
> +
> +static int i2c_probe_chip(struct udevice *bus, uint chip_addr)
> +{
> + struct dm_i2c_ops *ops = i2c_get_ops(bus);
> + struct i2c_msg msg[1];
> + uint8_t ch = 0;
> +
> + if (!ops->xfer)
> + return -ENOSYS;
> +
> + msg->addr = chip_addr;
> + msg->flags = 0;
> + msg->len = 1;
> + msg->buf = &ch;
> +
> + return ops->xfer(bus, msg, 1);
> +}
i2c_probe_chip() issues a write transaction with one length,
but a read transaction should be used.
For most of chips, the first write data is the first byte of
the offset address, so no real data will be written into the chip.
But it is possible to have offset_address_length == 0.
The read transaction is always safer than the write transaction.
BTW, I implemented an i2c driver for my Panasonic board base on this series,
and I am playing around with it.
I found a strange behavior.
Assume an EEPROM chip is assigned with slave-address 0x50.
There is no other chip on this i2c bus.
If I run "i2c probe 50" command, it correctly detects the EEPROM
chip and create a generic device node "generic_50".
If I run "i2c probe 49" command, it simply fails and nothing else happens.
On the other hand, when I run "i2c read 49 0.2 1 84000000",
it forcibly create a generic device node "generic_49".
"i2c read" command directly calls i2c_get_chip() and skips the probing step.
This is odd.
My "dm tree" output is like this:
=> dm tree
ROOT 9fb49028
- * root_driver @ 9fb49028
`- * soc @ 9fb49098
|- * serial at 54006800 @ 9fb49108, 1409312768
|- serial at 54006900 @ 9fb49158, 1409313024
|- serial at 54006a00 @ 9fb491a8, 1409313280
|- serial at 54006b00 @ 9fb491f8, 1409313536
|- * i2c at 58400000 @ 9fb49268, 0
||- * generic_50 @ 9fb51f00
|`- * generic_49 @ 9fb51f70 <--- nothing exists on slave address 0x49 !!!
|- i2c at 58480000 @ 9fb492b8, 1
|- i2c at 58500000 @ 9fb49308, 2
`- i2c@58580000 @ 9fb49358, 3
It should not create any device node for non-existing slave address.
I think i2c_get_chip() implementation is wrong.
My rough image of the correct implemenation is like this:
The key is to split it into i2c_create_chip() and i2c_get_chip(), I think
int i2c_probe ( .... )
{
i2c_probe_chip();
if (failed)
return;
i2c_create_chip()
}
int i2c_create_chip()
{
search the suitable chip driver based on DeviceTree
if (found) {
use it
} else {
call i2c_bind_driver() to create "generic" chip
}
}
int i2c_get_chip ()
{
search a child node with the given chip_addr
if (found)
return dev;
i2c_probe();
}
Best Regards
Masahiro Yamada
next prev parent reply other threads:[~2014-12-04 2:01 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-24 18:57 [U-Boot] [PATCH v3 0/10] dm: Add I2C support and convert sandbox, tegra Simon Glass
2014-11-24 18:57 ` [U-Boot] [PATCH v3 01/10] dm: i2c: Add a uclass for I2C Simon Glass
2014-11-28 4:47 ` Simon Glass
2014-12-01 9:02 ` Masahiro Yamada
2014-12-01 11:47 ` Masahiro Yamada
2014-12-02 4:31 ` Simon Glass
2014-12-02 4:35 ` Masahiro Yamada
2014-12-02 6:29 ` Heiko Schocher
2014-12-02 17:42 ` Simon Glass
2014-12-03 15:12 ` Simon Glass
2014-12-03 13:24 ` Masahiro Yamada
2014-12-03 15:13 ` Simon Glass
2014-12-03 16:02 ` Masahiro YAMADA
2014-12-04 2:01 ` Masahiro Yamada [this message]
2014-12-04 2:32 ` Simon Glass
2014-12-04 7:24 ` Masahiro Yamada
2014-12-04 12:23 ` Simon Glass
2014-12-04 2:36 ` Simon Glass
2014-12-04 7:27 ` Masahiro Yamada
2014-12-04 12:27 ` Simon Glass
2014-12-04 4:36 ` Masahiro Yamada
2014-12-04 5:07 ` Simon Glass
2014-11-24 18:57 ` [U-Boot] [PATCH v3 02/10] dm: i2c: Implement driver model support in the i2c command Simon Glass
2014-11-24 18:57 ` [U-Boot] [PATCH v3 03/10] dm: i2c: Add I2C emulation driver for sandbox Simon Glass
2014-11-24 18:57 ` [U-Boot] [PATCH v3 04/10] dm: i2c: Add a sandbox I2C driver Simon Glass
2014-11-24 18:57 ` [U-Boot] [PATCH v3 05/10] dm: i2c: Add an I2C EEPROM simulator Simon Glass
2014-11-24 18:57 ` [U-Boot] [PATCH v3 06/10] dm: i2c: config: Enable I2C for sandbox using driver model Simon Glass
2014-11-24 18:57 ` [U-Boot] [PATCH v3 07/10] dm: i2c: dts: Add an I2C bus for sandbox Simon Glass
2014-11-24 18:57 ` [U-Boot] [PATCH v3 08/10] dm: Add a simple EEPROM driver Simon Glass
2014-12-01 11:48 ` Masahiro Yamada
2014-12-03 15:18 ` Simon Glass
2014-12-03 16:03 ` Masahiro YAMADA
2014-12-03 16:16 ` Przemyslaw Marczak
2014-11-24 18:57 ` [U-Boot] [PATCH v3 09/10] dm: i2c: Add tests for I2C Simon Glass
2014-11-24 18:57 ` [U-Boot] [PATCH v3 10/10] dm: i2c: tegra: Convert to driver model Simon Glass
2014-12-01 11:53 ` Masahiro Yamada
2014-12-03 13:30 ` Masahiro Yamada
2014-12-03 15:23 ` Simon Glass
2014-12-03 15:52 ` Masahiro YAMADA
2014-12-03 16:37 ` Simon Glass
2014-12-03 16:13 ` [U-Boot] [PATCH v3 0/10] dm: Add I2C support and convert sandbox, tegra Przemyslaw Marczak
2014-12-04 2:00 ` Simon Glass
2014-12-05 13:09 ` Przemyslaw Marczak
2014-12-05 17:47 ` Simon Glass
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=20141204110145.314F.AA925319@jp.panasonic.com \
--to=yamada.m@jp.panasonic.com \
--cc=u-boot@lists.denx.de \
/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