zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.88k stars 6.63k forks source link

Extend charger API with USB-C Power delivery features #74055

Open VinFar opened 5 months ago

VinFar commented 5 months ago

Is your enhancement proposal related to a problem? Please describe. Many battery charging ICs have integrated USB power delivery detection. Meaning that they connect to D+/D- (and CC pins when using USB-C) of the USB port, in order to detect the power delivery capabilities of the connected USB port. These function are built into these ICs and can be configured or status read using I²C. An example we are using is the MP2722. It can detect the current capabilities of the USB port, as well as request higher than 5V voltages from the USB port. It also can act as a source, providing power from the battery.

Describe the solution you'd like Extend the charger API for using these features. This would include adding some get/set properties, an API function for registering of a notification callback and some enums and struct for the get/set properties. These are e.g.

Theses features are derived from the function of the MP2722. For other IC there may be other functionatilities.

Describe alternatives you've considered I noticed that there USB Type-C Port Controller API here. Unfortunately, I do not know if it is a good practice two implement two device drivers (charger API and USB TCPC API) using one C file and how to do it.

Which way may be the best to use? May it be a good idea the extend the charger API with these features?

github-actions[bot] commented 5 months ago

Hi @VinFar! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

rriveramcrus commented 5 months ago

Hello @VinFar, I feel the driver for the MPS part (and any other charger IC that offers integrated input source detection) should be an MFD.

There are various input source detection schemes out in the wild:

I feel it would not be practical to maintain interfaces for these schemes in the charger_driver_api especially if there are dedicated APIs elsewhere in the tree.

The MAX20335 is a good example of a charger MFD as it is both a charger and a regulator.

A follow up question I have for you is, in the context of a MP2722 MFD driver, do you feel usb_type_c_port_controller_api and the charger_driver_api have everything you need to accomplish what you are trying to do?