Page MenuHomeFreeBSD

gpio: attach gpiobus when the controller is ready
ClosedPublic

Authored by vexeduxr on Sun, Jun 29, 12:24 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jul 20, 4:52 AM
Unknown Object (File)
Sun, Jul 20, 4:38 AM
Unknown Object (File)
Tue, Jul 8, 1:50 AM
Unknown Object (File)
Sun, Jul 6, 10:41 AM
Unknown Object (File)
Sat, Jul 5, 8:36 PM
Unknown Object (File)
Fri, Jul 4, 5:58 PM
Unknown Object (File)
Thu, Jul 3, 1:03 PM
Unknown Object (File)
Thu, Jul 3, 6:02 AM
Subscribers

Details

Summary

Only attach gpiobus when the controller is fully initialized. Children
of gpiobus expect this to be the case.

Test Plan

Tested the pl061 change, the rest are only compile tested.

Note that most drivers in the tree already do this. These are just the few that don't.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 65126
Build 62009: arc lint + arc unit

Event Timeline

mmel requested changes to this revision.Tue, Jul 1, 12:42 PM

One commit for moving gpiobus_attach_bus() after init (seems fine to me)
and another for changes to pl061 (the ACPI/WDT interrupt changes seems unrelated).
Removing bus_attach_children() is questionable ( and probably wrong)
and moving bus_setup_intr() before HW init is clearly wrong.

sys/arm/nvidia/as3722.c
314

This is clearly wrong, you can't set an interrupt without having fully initialized HW and driver data.

331

Why did you remove the bus_attach_children() function? Ditto for other drivers.

sys/arm64/apple/apple_pinctrl.c
164

Why?

sys/arm64/nvidia/tegra210/max77620.c
418

Again, wrong change.

This revision now requires changes to proceed.Tue, Jul 1, 12:42 PM

and another for changes to pl061 (the ACPI/WDT interrupt changes seems unrelated).

They're required to move the intr_pic_register call to pl061_attach.

sys/arm/nvidia/as3722.c
314

Hm, I should just move the gpiobus_attach_bus call out instead of moving the whole function.

331

Because gpiobus_attach_bus already calls it.

sys/arm64/apple/apple_pinctrl.c
164

The PIC needs to be registered before we attach gpiobus. If a gpiobus child gets attached in the same bus pass, and said child tried to setup an interrupt, it would fail.

sys/arm/nvidia/as3722.c
331

Would it make sense to make that a separate change?

sys/dev/gpio/pl061_acpi.c
76–80

error is now unneeded here and in the fdt attach.

sys/arm/nvidia/as3722.c
331

Yeah, I'll move it to a separate review.

Move as3722_gpio_attach and max77620_gpio_attach back up, and instead swap them with the rtc functions.
It's hard to tell if the interrupt is needed by the controller's children (presumably it is), but
they're both currently unimplemented.

Simplify the pl061 attach functions by tail calling pl061_attach.

Move the removal of bus_attach_children calls to a parent commit.

max77620 and as3722 are much more problematic. I think each function expects the other functions to have HW initialized before they can be consumed.

In other words, and I hope more clearly:
Having bus_attach_children() in gpiobus_attach_bus() is a nice shortcut for trivial cases, but a nightmare for complex ones. Personally, I vote for creating a 'clone' of gpiobus_attach_bus() without scanning children and using it in those cases along with explicit bus_attach_children() in the driver.

What do you think about that?

sys/arm64/apple/apple_pinctrl.c
164

However, you moved it before pinctrl configured the pins, so the result is again misordered. Imho, pinctrl init should be moved along with intr_pic_register().

max77620 and as3722 are much more problematic. I think each function expects the other functions to have HW initialized before they can be consumed.

I see, I'll revert the move.

In other words, and I hope more clearly:
Having bus_attach_children() in gpiobus_attach_bus() is a nice shortcut for trivial cases, but a nightmare for complex ones. Personally, I vote for creating a 'clone' of gpiobus_attach_bus() without scanning children and using it in those cases along with explicit bus_attach_children() in the driver.

What do you think about that?

Hmm, is there a reason we need to add a child in max77620_gpio_attach/as3722_gpio_attach specifically? I think we should just move the gpiobus_attach_bus call after hw init is done.

sys/arm64/apple/apple_pinctrl.c
164

Agreed. I think I just got confused since I saw other drivers doing it this way.

Hmm, is there a reason we need to add a child in max77620_gpio_attach/as3722_gpio_attach specifically? I think we should just move the gpiobus_attach_bus call after hw init is done.

Actually, I've changed my mind. You're right, even if the max77620 and as3722 drivers don't *need* this functionality, adding a separate function is definitely a cleaner way to implement it.

Move max77620 and as3722's gpio_attach functions to their original place,
and use gpiobus_add_bus instead.

Move the pinctrl functions before gpiobus attachment too.
Also fix a few more drivers that do this.

Thank you very much for your patience. Please don't forget the MFC for this whole series.

This revision is now accepted and ready to land.Thu, Jul 3, 7:06 AM
andrew added inline comments.
sys/arm/allwinner/aw_gpio.c
1160–1163 ↗(On Diff #157852)

Do we need to undo this in the failure case?

sys/arm/allwinner/aw_gpio.c
1160–1163 ↗(On Diff #157852)

All fdt_pinctrl_register does is call OF_device_register_xref on a few nodes, so I think that's fine.
However, fdt_pinctrl_configure_tree calls FDT_PINCTRL_CONFIGURE to configure pins, which is controller specific. These controllers don't have an "unconfigure" function. IMO It's fine to configure pins then bail if an error occurs.