Page MenuHomeFreeBSD

pca954x: harmonize pca9547 and pca954x and add pca9540 support

Authored by bz on Jul 2 2022, 11:41 PM.
Referenced Files
Unknown Object (File)
Thu, May 9, 2:36 AM
Unknown Object (File)
Mon, May 6, 4:57 AM
Unknown Object (File)
Sun, May 5, 12:40 PM
Unknown Object (File)
Wed, May 1, 4:31 PM
Unknown Object (File)
Tue, Apr 30, 9:07 PM
Unknown Object (File)
Sun, Apr 28, 6:02 PM
Unknown Object (File)
Sat, Apr 27, 7:32 AM
Unknown Object (File)
Mon, Apr 22, 7:47 AM



The two implementations for the pca9548 switch and the pca9547 mux
seemed close enough so we can put them together and with a bit more
abstraction add pca9540 support.

While here apply a bit of consistency in variable and driver naming and
use device_has_property instead of the FDT-only OF_ variant.

This disconnects pca9547 from the build but does not yet delete it.

Test Plan

I cannot test either pca9547 or pca9548. And frankly I did this by
visual inspection and not much thinking in order to not add yet another
almost similar file for the pca9540.

Would be great if you could test things still work as expected in addition
to reviewing.

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable

Event Timeline

bz requested review of this revision.Jul 2 2022, 11:41 PM

I don't think it should be #ifdefed. The "okay" test is obviously missing in the original probe method.


Is that status inherited? I never saw a '''status = "okay"''' inside the '''i2c-switch''' blocks, only in the upper '''i2c'' node.


this drops a comma.


Generally only direct children of ofwbus/fdtbus need to check this.

Also, I have a huge patch set I've been rebasing forward for years that hoists this check into the bus code and now seems like a good time to solicit comments on that :)


Given this got merged from two files, ... also the comma is not in /usr/share/etc/bsd-style-copyright . I can add this back is needed but eventually we'll need to align this "templates" (also with the one for the SPDX tag)


Right but please on a separate review... I'll just remove the #if 0 block..., right?

remove the #if 0 block for status valid check.

This revision is now accepted and ready to land.Jul 4 2022, 5:00 AM

I think that this is a very good change. Some minor code style / improvement suggestions from me.
Thank you.


Style nit: I'd add an empty line before the multi-line comment.


Can this be "collapsed" into 'else if'?
Also, there is no default /catch-all else clause... maybe it's worthwhile adding it with some error and diagnostic? Or panic?


I think that what should be asserted here is that en is a power of 2, not just an even number.
Also, if en == 0 is allowed here, then this clause would cover the next clause as well.


What does the XXX comment suggest here?
It wasn't clear to me.
I do not see how anything from iic_reqbus_data::flags could affect iic_msg::flags.


I think that adding the okay status was a correct change.
A mux / switch is a device tree node, so it can be disabled via its status property.
This was an oversight in my code.

bz marked 7 inline comments as done.Jul 4 2022, 4:02 PM
bz added inline comments.

I cannot follow the en == 0 logic as

busidx != (1 << busdix);

I am probably misunderstanding here.

I'll do the power2 check though.

Correct all but on coments from avg; KASSERT to be discussed still. I didn't understand.

This revision now requires review to proceed.Jul 4 2022, 4:03 PM

Apologies, I misread the code.

bz marked an inline comment as done.Jul 4 2022, 4:14 PM

Does that mean we are good now (again)? Sorry the approved went away with the other corrections.

One final super-small nit: I am not sure what style(9) says about it, but my personal preference is that if one block of an if-else chain needs curly braces then all blocks in the chain should have them.
To my eye, that looks prettier.
But feel free to ignore this if it looks uglier or just the same to you.

Thank you!

This revision is now accepted and ready to land.Jul 4 2022, 4:18 PM

Added { } here and below for consistency.


and this has become a return (NULL); c&p error.