i2c: Fill req_seq in i2c_post_bind()

For i2c controllers which are missing alias in DT there is no req_seq
setup. This function is setting up proper ID based on highest found
alias ID.

On zcu102 this is the behavior when patch is applied.
ZynqMP> i2c bus
Bus 0:	i2c@ff020000
   20: gpio@20, offset len 1, flags 0
   21: gpio@21, offset len 1, flags 0
   75: i2c-mux@75, offset len 1, flags 0
Bus 2:	i2c@0
Bus 3:	i2c@1
Bus 4:	i2c@2
Bus 1:	i2c@ff030000  (active 1)
   74: i2c-mux@74, offset len 1, flags 0
   75: i2c-mux@75, offset len 1, flags 0
Bus 5:	i2c@0  (active 5)
   54: eeprom@54, offset len 1, flags 0
Bus 6:	i2c@1
Bus 7:	i2c@2
Bus 8:	i2c@3
Bus 9:	i2c@4
Bus 10:	i2c@0
Bus 11:	i2c@1
Bus 12:	i2c@2
Bus 13:	i2c@3
Bus 14:	i2c@4
Bus 15:	i2c@5
Bus 16:	i2c@6
Bus 17:	i2c@7

Before this patch applied (controllers have -1 ID)
ZynqMP> i2c bus
Bus 0:	i2c@ff020000
   20: gpio@20, offset len 1, flags 0
   21: gpio@21, offset len 1, flags 0
   75: i2c-mux@75, offset len 1, flags 0
Bus -1:	i2c@0
Bus -1:	i2c@1
Bus -1:	i2c@2
Bus 1:	i2c@ff030000  (active 1)
   74: i2c-mux@74, offset len 1, flags 0
   75: i2c-mux@75, offset len 1, flags 0
Bus -1:	i2c@0  (active 0)
   54: eeprom@54, offset len 1, flags 0
Bus -1:	i2c@1
Bus -1:	i2c@2
Bus -1:	i2c@3
Bus -1:	i2c@4
Bus -1:	i2c@0
Bus -1:	i2c@1
Bus -1:	i2c@2
Bus -1:	i2c@3
Bus -1:	i2c@4
Bus -1:	i2c@5
Bus -1:	i2c@6
Bus -1:	i2c@7

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Reviewed-by: Heiko Schocher <hs@denx.de>
This commit is contained in:
Michal Simek 2019-01-31 16:31:02 +01:00 committed by Heiko Schocher
parent 6bfacc8aad
commit 61607225d1

View File

@ -623,6 +623,30 @@ struct i2c_priv {
int max_id;
};
static int i2c_post_bind(struct udevice *dev)
{
struct uclass *class = dev->uclass;
struct i2c_priv *priv = class->priv;
int ret = 0;
/* Just for sure */
if (!priv)
return -ENOMEM;
debug("%s: %s, req_seq=%d\n", __func__, dev->name, dev->req_seq);
/* if there is no alias ID, use the first free */
if (dev->req_seq == -1)
dev->req_seq = ++priv->max_id;
debug("%s: %s, new req_seq=%d\n", __func__, dev->name, dev->req_seq);
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
ret = dm_scan_fdt_dev(dev);
#endif
return ret;
}
int i2c_uclass_init(struct uclass *class)
{
struct i2c_priv *priv = class->priv;
@ -647,9 +671,7 @@ UCLASS_DRIVER(i2c) = {
.id = UCLASS_I2C,
.name = "i2c",
.flags = DM_UC_FLAG_SEQ_ALIAS,
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
.post_bind = dm_scan_fdt_dev,
#endif
.post_bind = i2c_post_bind,
.init = i2c_uclass_init,
.priv_auto_alloc_size = sizeof(struct i2c_priv),
.post_probe = i2c_post_probe,