Skip to content

Conversation

@nmaggioni
Copy link
Contributor

@nmaggioni nmaggioni commented Sep 2, 2025

Summary

This PR adds support for the I2C interface of the Hynetek HUSB238 USB Type-C Power Delivery Sink Controller.

Since this is, if I'm not mistaken, the first USB-PD driver implemented in NuttX, I tried to apply the conventions used in other types of drivers while extending the power-related headers, IOCTL definitions, and Kconfig keys. I reckon that drivers/power/supply is the right place for this driver and the prefix of its config keys should be USBPD_HUSB238, but let me know if things should be organized/named differently.

I also have an example app ready, I'll open a PR on the apps repo once this one gets out of draft status. As before, CI will complain that the relative config key does not exist (yet) and will try to remove it during the normalization step.

This PR should also be updated in case #16869 gets merged: for now I used the old style of bus initialization to avoid merge conflicts.

Impact

Users will be able to query the controller for the currently active USB-PD PDO (combined specification of voltage and current), and interactively request different PDOs from the power supply.

Testing

These changes were tested on a Linux host, targeting a custom Cortex-M0+ (RP2040) board using NuttX v12.8.0 as the baseline. They were then manually ported to the current master branch.

Note: All the read commands have been tested, but I did not fully test the write commands (change active USB-PD voltage range, reset the power supply) as my current hardware is not designed for being exposed to wildly different voltage ranges and I do not have a dedicated breakout/evaluation board for this IC at hand.

…troller

Add support for the Hynetek HUSB238 USB Type-C Power Delivery Sink
Controller. Also add a new defconfig that includes support for a
HUSB238 IC connected via I2C and extend the existing documentation
to include its description.

Signed-off-by: Niccolò Maggioni <nicco.maggioni+nuttx@gmail.com>
@github-actions github-actions bot added Area: Documentation Improvements or additions to documentation Area: Drivers Drivers issues Board: arm Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Sep 2, 2025

/* Write the contents of the SRC_PDO register */

case PWRIOC_HUSB238_SET_SELECTED_PDO:
Copy link
Contributor

Choose a reason for hiding this comment

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

should we define and implement. USB P Dofficially in nuttx?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean, these commands only interact with the internal state machine of the IC (see registries definitions and datasheet).

If you are suggesting to define PDOs globally for future implementations, I'd say that it's not worth the trouble as they are a constantly moving target due to each manufacurer's different implementation - both at the sink and source levels.

@acassis
Copy link
Contributor

acassis commented Sep 3, 2025

"Since this is, if I'm not mistaken, the first USB-PD driver implemented in NuttX"

Actually you are mistaken! hehehe

NuttX already supports it (yes, NuttX is full of hidden features and resources).

Please take a look at drivers/usbmisc/stusb4500.c, it was implemented by @SimonFilgis

This is why all new PR that introduces a new feature or API ask people to include a Documentation.

@nmaggioni @xiaoxiang781216 @SimonFilgis please align it to avoid spreading similar drivers to different places. I'm not sure which place (drivers/usbmisc or drivers/power/supply)

@nmaggioni
Copy link
Contributor Author

Ah, it indeed seemed strange to me that nobody else dabbled with this before! Hence the conditional :)

Thanks for pointing me in the right direction, I'll take a look at the STUSB4500 driver. With USB-PD being a relatively new standard, I'm often having difficulties finding existing sources because it can be referred to in a few subtly different ways.

@acassis
Copy link
Contributor

acassis commented Sep 3, 2025

@nmaggioni maybe your application could become a standard for control USB PD device, maybe renaming it to usbpdctl or something similar. Please take a look how it is done on Linux, that should be our reference ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Area: Drivers Drivers issues Board: arm Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants