Skip to content

usb: dwc3: pci: skip BYT GPIO lookup table for hardwired phy - #123

Merged
bstreiff merged 1 commit into
ni:nilrt/master/6.1from
gratian:dev/nilrt/master/6.1-dwc3-usb-device-fix
Jul 17, 2023
Merged

bstreiff merged 1 commit into
ni:nilrt/master/6.1from
gratian:dev/nilrt/master/6.1-dwc3-usb-device-fix

Conversation

@gratian

@gratian gratian commented Jul 13, 2023

Copy link
Copy Markdown
Contributor

Hardware based on the Bay Trail / BYT SoCs require an external ULPI phy for USB device-mode. The phy chip usually has its 'reset' and 'chip select' lines connected to GPIOs described by ACPI fwnodes in the DSDT table.

Because of hardware with missing ACPI resources for the 'reset' and 'chip select' GPIOs commit 5741022 ("usb: dwc3: pci: Add GPIO lookup table on platforms without ACPI GPIO resources") introduced a fallback gpiod_lookup_table with hard-coded mappings for Bay Trail devices.

However there are existing Bay Trail based devices, like the National Instruments cRIO-903x series, where the phy chip has its 'reset' and 'chip-select' lines always asserted in hardware via resistor pull-ups. On this hardware the phy chip is always enabled and the ACPI dsdt table is missing information not only for the 'chip-select' and 'reset' lines but also for the BYT GPIO controller itself "INT33FC".

With the introduction of the gpiod_lookup_table initializing the USB device-mode on these hardware now errors out. The error comes from the gpiod_get_optional() calls in dwc3_pci_quirks() which will now return an -ENOENT error due to the missing ACPI entry for the INT33FC gpio controller used in the aforementioned table.

This hardware used to work before because gpiod_get_optional() will return NULL instead of -ENOENT if no GPIO has been assigned to the requested function. The dwc3_pci_quirks() code for setting the 'cs' and 'reset' GPIOs was then skipped (due to the NULL return). This is the correct behavior in cases where the phy chip is hardwired and there are no GPIOs to control.

Since the gpiod_lookup_table relies on the presence of INT33FC fwnode in ACPI tables only add the table if we know the entry for the INT33FC gpio controller is present. Additionally check the 'cs' gpio handle is not NULL before using it (like we do for the 'reset' line). This allows Bay Trail based devices with hardwired dwc3 ULPI phys to continue working.

Fixes: 5741022 ("usb: dwc3: pci: Add GPIO lookup table on platforms without ACPI GPIO resources")

@gratian
gratian requested a review from a team July 13, 2023 21:18
@gratian

gratian commented Jul 13, 2023

Copy link
Copy Markdown
Contributor Author

Testing

  • locally built new 6.1-rt kernel and installed on two cRIO-903x targets cross connected over USB. One of the targets has the old BIOS with the missing GPIO controller information the other one has the updated BIOS
  • verified that the USB ethernet interface comes up correctly on both targets
  • verified that I can connect in both directions between these targets over the USB device connection

@gratian

gratian commented Jul 13, 2023

Copy link
Copy Markdown
Contributor Author

Note for reviewers

  • I'm going to try to submit this upstream so I would appreciate feedback on the commit message itself in addition to the code.

@chaitu236 chaitu236 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both code change and description look good to me.

@gratian
gratian force-pushed the dev/nilrt/master/6.1-dwc3-usb-device-fix branch from 19c3b52 to bdd1166 Compare July 14, 2023 21:22
@gratian gratian changed the title usb: dwc3: pci: don't use a BYT GPIO lookup table if the ACPI resource for GPIO controller is not present usb: dwc3: pci: skip BYT GPIO lookup table if phy is hardwired Jul 14, 2023
@gratian

gratian commented Jul 14, 2023

Copy link
Copy Markdown
Contributor Author

Tweaked the patch subject line to fit within the kernel patches max subject line rules.

Hardware based on the Bay Trail / BYT SoCs require an external ULPI phy for
USB device-mode. The phy chip usually has its 'reset' and 'chip select'
lines connected to GPIOs described by ACPI fwnodes in the DSDT table.

Because of hardware with missing ACPI resources for the 'reset' and 'chip
select' GPIOs commit 5741022 ("usb: dwc3: pci: Add GPIO lookup table
on platforms without ACPI GPIO resources") introduced a fallback
gpiod_lookup_table with hard-coded mappings for Bay Trail devices.

However there are existing Bay Trail based devices, like the National
Instruments cRIO-903x series, where the phy chip has its 'reset' and
'chip-select' lines always asserted in hardware via resistor pull-ups. On
this hardware the phy chip is always enabled and the ACPI dsdt table is
missing information not only for the 'chip-select' and 'reset' lines but
also for the BYT GPIO controller itself "INT33FC".

With the introduction of the gpiod_lookup_table initializing the USB
device-mode on these hardware now errors out. The error comes from the
gpiod_get_optional() calls in dwc3_pci_quirks() which will now return an
-ENOENT error due to the missing ACPI entry for the INT33FC gpio controller
used in the aforementioned table.

This hardware used to work before because gpiod_get_optional() will return
NULL instead of -ENOENT if no GPIO has been assigned to the requested
function. The dwc3_pci_quirks() code for setting the 'cs' and 'reset' GPIOs
was then skipped (due to the NULL return). This is the correct behavior in
cases where the phy chip is hardwired and there are no GPIOs to control.

Since the gpiod_lookup_table relies on the presence of INT33FC fwnode
in ACPI tables only add the table if we know the entry for the INT33FC
gpio controller is present. Additionally check the 'cs' gpio handle is
not NULL before using it (like we do for the 'reset' line). This
allows Bay Trail based devices with hardwired dwc3 ULPI phys to
continue working.

Fixes: 5741022 ("usb: dwc3: pci: Add GPIO lookup table on platforms without ACPI GPIO resources")
Signed-off-by: Gratian Crisan <gratian.crisan@ni.com>
@gratian
gratian force-pushed the dev/nilrt/master/6.1-dwc3-usb-device-fix branch from bdd1166 to 5e47a56 Compare July 17, 2023 15:55
@gratian gratian changed the title usb: dwc3: pci: skip BYT GPIO lookup table if phy is hardwired usb: dwc3: pci: skip BYT GPIO lookup table for hardwired phy Jul 17, 2023
@gratian

gratian commented Jul 17, 2023

Copy link
Copy Markdown
Contributor Author

Made the subject line (even) shorter to avoid wrapping in the email for upstream.

@bstreiff
bstreiff merged commit 5e47a56 into ni:nilrt/master/6.1 Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants