Skip to contentSkip to conversation

Calling i2c set speed twice for i2c_mux_bus

DISCUSSION Michal Simek 3 participants 15 messages Apr 9, 2020 – May 11, 2020 I2C

lore
Share & tools
lore
#0 lore raw

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Simon: I think that make sense to use some flags to skip calling post_probe in this case. Or any suggestion how to fix it would be great.

Thanks,
Michal

#1 lore raw

Hi Michal,

Quoted 10 lines · Michal Simek

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

Quoted 5 lines

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Simon: I think that make sense to use some flags to skip calling post_probe in this case. Or any suggestion how to fix it would be great.

Ick, hope not. Can you please point me to the board config and the device tree?

Regards,
Simon

#2 lore raw

Hi Simon,

Quoted 13 lines · Simon Glass

Hi Michal,

Quoted 10 lines · Michal Simek

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

Quoted 7 lines
Quoted 5 lines

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Simon: I think that make sense to use some flags to skip calling post_probe in this case. Or any suggestion how to fix it would be great.

Ick, hope not. Can you please point me to the board config and the device tree?

We have switch to generic config for all zynqmp boards. That's why

export DEVICE_TREE=zynqmp-zcu104-revC
make xilinx_zynqmp_virt_defconfig

It means DT arch/arm/dts/zynqmp-zcu104-revC.dts but I expect the same behavior on zynqmp-zcu102-revA and others who have i2c mux driver.

Thanks,
Michal

#3 lore raw
In reply to Michal Simek

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 11 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

No :-(

The question is, is this a bug?

Should a i2c bus behind a mux not be able to set his own speed?

But may as a feature (or bugfix?) if "clock-frequency" is not there, use the speed of the parent bus...?

Quoted 6 lines

Simon: I think that make sense to use some flags to skip calling post_probe in this case. Or any suggestion how to fix it would be great.

Thanks,
Michal

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#4 lore raw

Hi Heiko,

Quoted 12 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 9 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

Quoted 6 lines
Quoted 2 lines

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

No :-(

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I have looked at linux dt binding docs and nothing like that is specified there. From quick look also pca954x driver is not reading it.

Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not saying it doesn't make sense but I haven't seen this feature.

Quoted 2 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there, use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
 {
 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
        struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+       int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+       if (dev->parent &&
+           device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+           dev->parent->parent &&
+           device_get_uclass_id(dev->parent->parent) == UCLASS_I2C) {
+               struct dm_i2c_bus *i2c_parent;
+
+               i2c_parent = dev_get_uclass_priv(dev->parent->parent);
+               parent_speed = i2c_parent->speed_hz;
+               /* Not sure if make sense to check that parent_speed is

not 0 */
+ }

        i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency",

- I2C_SPEED_STANDARD_RATE);
+ parent_speed);

        return dm_i2c_set_bus_speed(dev, i2c->speed_hz);

#else

Thanks,
Michal

#5 lore raw

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 18 lines

Hi Heiko,

Quoted 15 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 11 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Quoted 7 lines
Quoted 3 lines

No :-(

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I have looked at linux dt binding docs and nothing like that is specified there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 4 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 26 lines
Quoted 2 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there, use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
  {
  #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
         struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+       int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+       if (dev->parent &&
+           device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+           dev->parent->parent &&
+           device_get_uclass_id(dev->parent->parent) == UCLASS_I2C) {
+               struct dm_i2c_bus *i2c_parent;
+
+               i2c_parent = dev_get_uclass_priv(dev->parent->parent);
+               parent_speed = i2c_parent->speed_hz;
+               /* Not sure if make sense to check that parent_speed is
Quoted 1 line

not 0 */

I think this check is not needed.

drivers/i2c/i2c-uclass.c

Quoted 5 lines
drivers/i2c/i2c-uclass.c +2 -1
+       }
 
         i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency",
-                                            I2C_SPEED_STANDARD_RATE);
+                                            parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) {
	udevice *parent2 = dev_get_parent(parent);
	if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) {
		struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

		parent_speed = i2cp->speed_hz;
	}
}

but Simon has a deeper DM knowledge, may there is a better approach.

Quoted 6 lines
         return dm_i2c_set_bus_speed(dev, i2c->speed_hz);

#else

Thanks,
Michal

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#6 lore raw
Quoted 84 lines · Heiko Schocher

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 19 lines

Hi Heiko,

Quoted 16 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 12 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which
has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Quoted 7 lines
Quoted 3 lines

No :-(

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I have looked at linux dt binding docs and nothing like that is specified there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 4 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 26 lines
Quoted 2 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there, use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
 ? {
 ? #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 ???????? struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+?????? int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+?????? if (dev->parent &&
+?????????? device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+?????????? dev->parent->parent &&
+?????????? device_get_uclass_id(dev->parent->parent) == UCLASS_I2C) {
+?????????????? struct dm_i2c_bus *i2c_parent;
+
+?????????????? i2c_parent = dev_get_uclass_priv(dev->parent->parent);
+?????????????? parent_speed = i2c_parent->speed_hz;
+?????????????? /* Not sure if make sense to check that parent_speed is
Quoted 1 line

not 0 */

I think this check is not needed.

Quoted 5 lines

+?????? }

???????? i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency", -??????????????????????????????????????????? I2C_SPEED_STANDARD_RATE); +??????????????????????????????????????????? parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) { ????udevice *parent2 = dev_get_parent(parent);
????if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) { ??????? struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

Quoted 5 lines

??????? parent_speed = i2cp->speed_hz;
????}
}

but Simon has a deeper DM knowledge, may there is a better approach.

Simon: any comment on this one?

Thanks,
Michal

#7 lore raw
Quoted 85 lines · Michal Simek
Quoted 84 lines · Heiko Schocher

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 19 lines

Hi Heiko,

Quoted 16 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 12 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which
has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Quoted 7 lines
Quoted 3 lines

No :-(

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I have looked at linux dt binding docs and nothing like that is specified there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 4 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 26 lines
Quoted 2 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there, use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
 ? {
 ? #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
 ???????? struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+?????? int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+?????? if (dev->parent &&
+?????????? device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+?????????? dev->parent->parent &&
+?????????? device_get_uclass_id(dev->parent->parent) == UCLASS_I2C) {
+?????????????? struct dm_i2c_bus *i2c_parent;
+
+?????????????? i2c_parent = dev_get_uclass_priv(dev->parent->parent);
+?????????????? parent_speed = i2c_parent->speed_hz;
+?????????????? /* Not sure if make sense to check that parent_speed is
Quoted 1 line

not 0 */

I think this check is not needed.

Quoted 5 lines

+?????? }

???????? i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency", -??????????????????????????????????????????? I2C_SPEED_STANDARD_RATE); +??????????????????????????????????????????? parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) { ????udevice *parent2 = dev_get_parent(parent);
????if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) { ??????? struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

Quoted 7 lines
Quoted 5 lines

??????? parent_speed = i2cp->speed_hz;
????}
}

but Simon has a deeper DM knowledge, may there is a better approach.

Simon: any comment on this one?

Simon: Can you please comment this?

Thanks,
Michal

#8 lore raw

Hi Michal,

Quoted 91 lines · Michal Simek
Quoted 89 lines · Michal Simek
Quoted 88 lines · Heiko Schocher

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 19 lines

Hi Heiko,

Quoted 16 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 12 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which
has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Quoted 7 lines
Quoted 3 lines

No :-(

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I have looked at linux dt binding docs and nothing like that is specified there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 4 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 26 lines
Quoted 2 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there, use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
  {
  #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
         struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+       int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+       if (dev->parent &&
+           device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+           dev->parent->parent &&
+           device_get_uclass_id(dev->parent->parent) == UCLASS_I2C) {
+               struct dm_i2c_bus *i2c_parent;
+
+               i2c_parent = dev_get_uclass_priv(dev->parent->parent);
+               parent_speed = i2c_parent->speed_hz;
+               /* Not sure if make sense to check that parent_speed is
Quoted 1 line

not 0 */

I think this check is not needed.

drivers/i2c/i2c-uclass.c

Quoted 5 lines
drivers/i2c/i2c-uclass.c +2 -1
+       }
 
         i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency",
-                                            I2C_SPEED_STANDARD_RATE);
+                                            parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) {
    udevice *parent2 = dev_get_parent(parent);
    if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) {
        struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

        parent_speed = i2cp->speed_hz;
    }
}
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

but Simon has a deeper DM knowledge, may there is a better approach.

Simon: any comment on this one?

Simon: Can you please comment this?

OK will take a look.

Regards,
Simon

#9 lore raw

Hi Michal,

Quoted 95 lines · Simon Glass

Hi Michal,

Quoted 91 lines · Michal Simek
Quoted 89 lines · Michal Simek
Quoted 88 lines · Heiko Schocher

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 19 lines

Hi Heiko,

Quoted 16 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 12 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which
has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Quoted 7 lines
Quoted 3 lines

No :-(

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I have looked at linux dt binding docs and nothing like that is specified there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 4 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 26 lines
Quoted 2 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there, use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
  {
  #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
         struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+       int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+       if (dev->parent &&
+           device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+           dev->parent->parent &&
+           device_get_uclass_id(dev->parent->parent) == UCLASS_I2C) {
+               struct dm_i2c_bus *i2c_parent;
+
+               i2c_parent = dev_get_uclass_priv(dev->parent->parent);
+               parent_speed = i2c_parent->speed_hz;
+               /* Not sure if make sense to check that parent_speed is
Quoted 1 line

not 0 */

I think this check is not needed.

drivers/i2c/i2c-uclass.c

Quoted 5 lines
drivers/i2c/i2c-uclass.c +2 -1
+       }
 
         i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency",
-                                            I2C_SPEED_STANDARD_RATE);
+                                            parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) {
    udevice *parent2 = dev_get_parent(parent);
    if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) {
        struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

        parent_speed = i2cp->speed_hz;
    }
}
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

but Simon has a deeper DM knowledge, may there is a better approach.

Simon: any comment on this one?

Simon: Can you please comment this?

OK will take a look.

I wonder if i2c-mux-uclass.c should define a new uclass for muxed I2C buses, something like UCLASS_I2C_MUXED_BUS? Then you can define the behaviour correctly in i2c-mux-uclass.c.

An I2C controller is not the same as a muxed bus and perhaps we should be explicitly about the differences. It probably just needs changes to the mux uclass.

Regards,
Simon

#10 lore raw
Quoted 107 lines · Simon Glass

Hi Michal,

Quoted 95 lines · Simon Glass

Hi Michal,

Quoted 91 lines · Michal Simek
Quoted 89 lines · Michal Simek
Quoted 88 lines · Heiko Schocher

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 19 lines

Hi Heiko,

Quoted 16 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 12 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which
has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Quoted 7 lines
Quoted 3 lines

No :-(

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I have looked at linux dt binding docs and nothing like that is specified there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 4 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 26 lines
Quoted 2 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there, use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
  {
  #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
         struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+       int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+       if (dev->parent &&
+           device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+           dev->parent->parent &&
+           device_get_uclass_id(dev->parent->parent) == UCLASS_I2C) {
+               struct dm_i2c_bus *i2c_parent;
+
+               i2c_parent = dev_get_uclass_priv(dev->parent->parent);
+               parent_speed = i2c_parent->speed_hz;
+               /* Not sure if make sense to check that parent_speed is
Quoted 1 line

not 0 */

I think this check is not needed.

drivers/i2c/i2c-uclass.c

Quoted 5 lines
drivers/i2c/i2c-uclass.c +2 -1
+       }
 
         i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency",
-                                            I2C_SPEED_STANDARD_RATE);
+                                            parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) {
    udevice *parent2 = dev_get_parent(parent);
    if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) {
        struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

        parent_speed = i2cp->speed_hz;
    }
}
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

but Simon has a deeper DM knowledge, may there is a better approach.

Simon: any comment on this one?

Simon: Can you please comment this?

OK will take a look.

Quoted 7 lines

I wonder if i2c-mux-uclass.c should define a new uclass for muxed I2C buses, something like UCLASS_I2C_MUXED_BUS? Then you can define the behaviour correctly in i2c-mux-uclass.c.

An I2C controller is not the same as a muxed bus and perhaps we should be explicitly about the differences. It probably just needs changes to the mux uclass.

Definitely there need to be some changes in connection to i2c muxes. I am aware also about bad behavior when you detect devices. Just look at log below and you will see that devices on base i2c bus are copied also to subbus (especially listing i2c-mux again looks weird).

Thanks,
Michal

ZynqMP> i2c bus
Bus 0: i2c at ff030000 (active 0)
20: gpio at 20, offset len 1, flags 0
74: i2c-mux at 74, offset len 1, flags 0
Bus 1: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 1)
54: eeprom at 54, offset len 1, flags 0
Bus 2: i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 3: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 4: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 5
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 7
ZynqMP> i2c dev 1
Setting bus to 1
ZynqMP> i2c probe
Valid chip addresses: 20 54 55 56 57 74
ZynqMP> i2c bus
Bus 0: i2c at ff030000 (active 0)
20: gpio at 20, offset len 1, flags 0
74: i2c-mux at 74, offset len 1, flags 0
Bus 1: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 1)
54: eeprom at 54, offset len 1, flags 0
20: generic_20, offset len 1, flags 0
74: generic_74, offset len 1, flags 0
Bus 2: i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 3: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 4: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 5
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 7
ZynqMP> i2c dev 2
Setting bus to 2
ZynqMP> i2c probe
Valid chip addresses: 20 6C 74
ZynqMP> i2c bus
Bus 0: i2c at ff030000 (active 0)
20: gpio at 20, offset len 1, flags 0
74: i2c-mux at 74, offset len 1, flags 0
Bus 1: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 1)
54: eeprom at 54, offset len 1, flags 0
20: generic_20, offset len 1, flags 0
74: generic_74, offset len 1, flags 0
Bus 2: i2c at ff030000->i2c-mux at 74->i2c at 1 (active 2)
20: generic_20, offset len 1, flags 0
6c: generic_6c, offset len 1, flags 0
74: generic_74, offset len 1, flags 0
Bus 3: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 4: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 5
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 7

#11 lore raw

Hello Michal,

Am 07.05.2020 um 10:18 schrieb Michal Simek:

Quoted 112 lines · Simon Glass
Quoted 111 lines

Hi Michal,

Quoted 95 lines · Simon Glass

Hi Michal,

Quoted 91 lines · Michal Simek
Quoted 89 lines · Michal Simek
Quoted 88 lines · Heiko Schocher

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 19 lines

Hi Heiko,

Quoted 16 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 12 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board which
has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

Quoted 7 lines
Quoted 3 lines

No :-(

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I have looked at linux dt binding docs and nothing like that is specified there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 4 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 26 lines
Quoted 2 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there, use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
   {
   #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
          struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+       int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+       if (dev->parent &&
+           device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+           dev->parent->parent &&
+           device_get_uclass_id(dev->parent->parent) == UCLASS_I2C) {
+               struct dm_i2c_bus *i2c_parent;
+
+               i2c_parent = dev_get_uclass_priv(dev->parent->parent);
+               parent_speed = i2c_parent->speed_hz;
+               /* Not sure if make sense to check that parent_speed is
Quoted 1 line

not 0 */

I think this check is not needed.

drivers/i2c/i2c-uclass.c

Quoted 5 lines
drivers/i2c/i2c-uclass.c +2 -1
+       }
 
          i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency",
-                                            I2C_SPEED_STANDARD_RATE);
+                                            parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) {
     udevice *parent2 = dev_get_parent(parent);
     if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) {
         struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

         parent_speed = i2cp->speed_hz;
     }
}
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

but Simon has a deeper DM knowledge, may there is a better approach.

Simon: any comment on this one?

Simon: Can you please comment this?

OK will take a look.

I wonder if i2c-mux-uclass.c should define a new uclass for muxed I2C buses, something like UCLASS_I2C_MUXED_BUS? Then you can define the behaviour correctly in i2c-mux-uclass.c.

Quoted 8 lines
Quoted 3 lines

An I2C controller is not the same as a muxed bus and perhaps we should be explicitly about the differences. It probably just needs changes to the mux uclass.

Definitely there need to be some changes in connection to i2c muxes. I am aware also about bad behavior when you detect devices. Just look at log below and you will see that devices on base i2c bus are copied also to subbus (especially listing i2c-mux again looks weird).

Yes, this look like we need here a seperate uclass to handle this correct...

Quoted 47 lines

Thanks,
Michal

ZynqMP> i2c bus
Bus 0: i2c at ff030000 (active 0)
20: gpio at 20, offset len 1, flags 0
74: i2c-mux at 74, offset len 1, flags 0
Bus 1: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 1)
54: eeprom at 54, offset len 1, flags 0
Bus 2: i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 3: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 4: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 5
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 7
ZynqMP> i2c dev 1
Setting bus to 1
ZynqMP> i2c probe
Valid chip addresses: 20 54 55 56 57 74
ZynqMP> i2c bus
Bus 0: i2c at ff030000 (active 0)
20: gpio at 20, offset len 1, flags 0
74: i2c-mux at 74, offset len 1, flags 0
Bus 1: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 1)

    54: eeprom at 54, offset len 1, flags 0
    20: generic_20, offset len 1, flags 0
    74: generic_74, offset len 1, flags 0

Bus 2: i2c at ff030000->i2c-mux at 74->i2c at 1
Bus 3: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 4: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 5
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 7
ZynqMP> i2c dev 2
Setting bus to 2
ZynqMP> i2c probe
Valid chip addresses: 20 6C 74
ZynqMP> i2c bus
Bus 0: i2c at ff030000 (active 0)
20: gpio at 20, offset len 1, flags 0
74: i2c-mux at 74, offset len 1, flags 0
Bus 1: i2c at ff030000->i2c-mux at 74->i2c at 0 (active 1)

    54: eeprom at 54, offset len 1, flags 0
    20: generic_20, offset len 1, flags 0
    74: generic_74, offset len 1, flags 0
Bus 2:	i2c at ff030000->i2c-mux at 74->i2c at 1  (active 2)
    20: generic_20, offset len 1, flags 0
    6c: generic_6c, offset len 1, flags 0
    74: generic_74, offset len 1, flags 0
Quoted 5 lines

Bus 3: i2c at ff030000->i2c-mux at 74->i2c at 2
Bus 4: i2c at ff030000->i2c-mux at 74->i2c at 3
Bus 5: i2c at ff030000->i2c-mux at 74->i2c at 5
Bus 6: i2c at ff030000->i2c-mux at 74->i2c at 7

:-(

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#12 lore raw
Quoted 132 lines · Heiko Schocher

Hello Michal,

Am 07.05.2020 um 10:18 schrieb Michal Simek:

Quoted 129 lines · Simon Glass
Quoted 127 lines

Hi Michal,

Quoted 108 lines · Simon Glass

Hi Michal,

Quoted 103 lines · Michal Simek
Quoted 101 lines · Michal Simek
Quoted 100 lines · Heiko Schocher

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 23 lines

Hi Heiko,

Quoted 20 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 12 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board
which
has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means
that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

Quoted 2 lines

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

No :-(

Quoted 7 lines
Quoted 1 line

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I
have looked at linux dt binding docs and nothing like that is specified
there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 5 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not
saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 24 lines
Quoted 3 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there,
use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +0 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
 ?? {

?? #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
????????? struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev); +?????? int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+?????? if (dev->parent &&
+?????????? device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX && +?????????? dev->parent->parent &&
+?????????? device_get_uclass_id(dev->parent->parent) == UCLASS_I2C) {

Quoted 8 lines

+?????????????? struct dm_i2c_bus *i2c_parent; +
+?????????????? i2c_parent = dev_get_uclass_priv(dev->parent->parent); +?????????????? parent_speed = i2c_parent->speed_hz; +?????????????? /* Not sure if make sense to check that parent_speed is
not 0 */

I think this check is not needed.

Quoted 7 lines

+?????? }

????????? i2c->speed_hz = dev_read_u32_default(dev, "clock-frequency", -??????????????????????????????????????????? I2C_SPEED_STANDARD_RATE); +??????????????????????????????????????????? parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) { ???? udevice *parent2 = dev_get_parent(parent);
???? if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) { ???????? struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

???????? parent_speed = i2cp->speed_hz;
???? }
}

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

but Simon has a deeper DM knowledge, may there is a better approach.

Simon: any comment on this one?

Simon: Can you please comment this?

OK will take a look.

I wonder if i2c-mux-uclass.c should define a new uclass for muxed I2C buses, something like UCLASS_I2C_MUXED_BUS? Then you can define the behaviour correctly in i2c-mux-uclass.c.

An I2C controller is not the same as a muxed bus and perhaps we should be explicitly about the differences. It probably just needs changes to the mux uclass.

Quoted 7 lines
Quoted 4 lines

Definitely there need to be some changes in connection to i2c muxes. I am aware also about bad behavior when you detect devices. Just look at log below and you will see that devices on base i2c bus are copied also to subbus (especially listing i2c-mux again looks weird).

Yes, this look like we need here a seperate uclass to handle this correct...

Are you going to invest to your time to create?

Thanks,
Michal

#13 lore raw

Hello Michal,

Am 11.05.2020 um 15:36 schrieb Michal Simek:

Quoted 138 lines · Heiko Schocher
Quoted 137 lines

Hello Michal,

Am 07.05.2020 um 10:18 schrieb Michal Simek:

Quoted 133 lines · Simon Glass
Quoted 120 lines

Hi Michal,

Quoted 108 lines · Simon Glass

Hi Michal,

Quoted 103 lines · Michal Simek
Quoted 101 lines · Michal Simek
Quoted 100 lines · Heiko Schocher

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 23 lines

Hi Heiko,

Quoted 20 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 12 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board
which
has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means
that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

Quoted 2 lines

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

No :-(

Quoted 7 lines
Quoted 1 line

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I
have looked at linux dt binding docs and nothing like that is specified
there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 5 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not
saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 30 lines
Quoted 3 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there,
use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
 ?? {
 ?? #if CONFIG_IS_ENABLED(OF_CONTROL) &&
 !CONFIG_IS_ENABLED(OF_PLATDATA)
 ????????? struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+?????? int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+?????? if (dev->parent &&
+?????????? device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+?????????? dev->parent->parent &&
+?????????? device_get_uclass_id(dev->parent->parent) ==
 UCLASS_I2C) {
+?????????????? struct dm_i2c_bus *i2c_parent;
+
+?????????????? i2c_parent =
 dev_get_uclass_priv(dev->parent->parent);
+?????????????? parent_speed = i2c_parent->speed_hz;
+?????????????? /* Not sure if make sense to check that
Quoted 2 lines

parent_speed is
not 0 */

I think this check is not needed.

Quoted 7 lines

+?????? }

????????? i2c->speed_hz = dev_read_u32_default(dev,
"clock-frequency",
-
I2C_SPEED_STANDARD_RATE); +??????????????????????????????????????????? parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) {
???? udevice *parent2 = dev_get_parent(parent);
???? if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) { ???????? struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

???????? parent_speed = i2cp->speed_hz;
???? }
}

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

but Simon has a deeper DM knowledge, may there is a better approach.

Simon: any comment on this one?

Simon: Can you please comment this?

OK will take a look.

Quoted 7 lines

I wonder if i2c-mux-uclass.c should define a new uclass for muxed I2C buses, something like UCLASS_I2C_MUXED_BUS? Then you can define the behaviour correctly in i2c-mux-uclass.c.

An I2C controller is not the same as a muxed bus and perhaps we should be explicitly about the differences. It probably just needs changes to the mux uclass.

Definitely there need to be some changes in connection to i2c muxes. I am aware also about bad behavior when you detect devices. Just look at log below and you will see that devices on base i2c bus are copied also to subbus (especially listing i2c-mux again looks weird).

Quoted 4 lines
Quoted 2 lines

Yes, this look like we need here a seperate uclass to handle this correct...

Are you going to invest to your time to create?

Unfortunately I have no time to look into this soon, and I must search for a hardware to test...

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#14 lore raw

Hi,

Quoted 142 lines · Heiko Schocher

Hello Michal,

Am 11.05.2020 um 15:36 schrieb Michal Simek:

Quoted 138 lines · Heiko Schocher
Quoted 137 lines

Hello Michal,

Am 07.05.2020 um 10:18 schrieb Michal Simek:

Quoted 133 lines · Simon Glass
Quoted 120 lines

Hi Michal,

Quoted 108 lines · Simon Glass

Hi Michal,

Quoted 103 lines · Michal Simek
Quoted 101 lines · Michal Simek
Quoted 100 lines · Heiko Schocher

Hello Michal,

Am 10.04.2020 um 08:46 schrieb Michal Simek:

Quoted 23 lines

Hi Heiko,

Quoted 20 lines · Heiko Schocher

Hello Michal,

Am 09.04.2020 um 16:03 schrieb Michal Simek:

Quoted 12 lines

Hi Heiko and Simon,

I have find out one bug in i2c class. I am using zcu104 revC board
which
has dts in mainline where i2c1 has i2c mux with some channels. In DT clock-frequency = <400000>; is specified and it is read in i2c_post_probe(). But i2c_mux_bus_drv is also UCLASS_I2C which means
that post probe is called for it too. And because clock-frequency property is not there default 100k is used.

Quoted 2 lines

I think that is bug and should be fixed.
Heiko: Are you aware about this issue?

No :-(

Quoted 7 lines
Quoted 1 line

The question is, is this a bug?

I have never seen clock-frequency property in i2c mux bus node. Also I
have looked at linux dt binding docs and nothing like that is specified
there. From quick look also pca954x driver is not reading it.

Indeed.

Quoted 5 lines
Quoted 1 line

Should a i2c bus behind a mux not be able to set his own speed?

Not sure if that make sense but Linux will likely ignore it. I am not
saying it doesn't make sense but I haven't seen this feature.

Ok.

Quoted 30 lines
Quoted 3 lines

But may as a feature (or bugfix?) if "clock-frequency" is not there,
use the speed of the parent bus...?

I was thinking about this too.
just c&p quick implementation would look like this. Because it is i2c->i2c_mux->i2c. But maybe there is a better way how to do it.

drivers/i2c/i2c-uclass.c +11 -0
index 2aa3efe8aaa0..982c467deba3 100644
@@ -640,9 +640,21 @@ static int i2c_post_probe(struct udevice *dev)
    {
    #if CONFIG_IS_ENABLED(OF_CONTROL) &&
 !CONFIG_IS_ENABLED(OF_PLATDATA)
           struct dm_i2c_bus *i2c = dev_get_uclass_priv(dev);
+       int parent_speed = I2C_SPEED_STANDARD_RATE;
+
+       if (dev->parent &&
+           device_get_uclass_id(dev->parent) == UCLASS_I2C_MUX &&
+           dev->parent->parent &&
+           device_get_uclass_id(dev->parent->parent) ==
 UCLASS_I2C) {
+               struct dm_i2c_bus *i2c_parent;
+
+               i2c_parent =
 dev_get_uclass_priv(dev->parent->parent);
+               parent_speed = i2c_parent->speed_hz;
+               /* Not sure if make sense to check that
Quoted 2 lines

parent_speed is
not 0 */

I think this check is not needed.

Quoted 7 lines

+ }

           i2c->speed_hz = dev_read_u32_default(dev,

"clock-frequency",
-
I2C_SPEED_STANDARD_RATE);
+ parent_speed);

Wow, a big if ... may this is clearer (not compile tested)?

udevice *parent = dev_get_parent(dev);

if (parent && device_get_uclass_id(parent) == UCLASS_I2C_MUX) {
      udevice *parent2 = dev_get_parent(parent);
      if (parent2 && device_get_uclass_id(parent2) == UCLASS_I2C) {
          struct dm_i2c_bus *i2cp = dev_get_uclass_priv(parent2);

          parent_speed = i2cp->speed_hz;
      }
}
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

but Simon has a deeper DM knowledge, may there is a better approach.

Simon: any comment on this one?

Simon: Can you please comment this?

OK will take a look.

Quoted 7 lines

I wonder if i2c-mux-uclass.c should define a new uclass for muxed I2C buses, something like UCLASS_I2C_MUXED_BUS? Then you can define the behaviour correctly in i2c-mux-uclass.c.

An I2C controller is not the same as a muxed bus and perhaps we should be explicitly about the differences. It probably just needs changes to the mux uclass.

Definitely there need to be some changes in connection to i2c muxes. I am aware also about bad behavior when you detect devices. Just look at log below and you will see that devices on base i2c bus are copied also to subbus (especially listing i2c-mux again looks weird).

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Yes, this look like we need here a seperate uclass to handle this correct...

Are you going to invest to your time to create?

Unfortunately I have no time to look into this soon, and I must search for a hardware to test...

I think this should be implemented in sandbox as it is much faster / simpler.

Regards,
SImon