Skip to content

Introduce usb charger framework to deal with the usb gadget power negotation

Baolin Wang linux-pm lkml 26 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v19 Latest4 patches 20 repliesIn review
  2. v184 patches 33 repliesSuperseded
  3. v174 patches 6 repliesSuperseded
Earlier versions · 23
VersionPostedPatchesRepliesStatus
v164 patches28 repliesSuperseded
v154 patches1 replySuperseded
v144 patches2 repliesSuperseded
v134 patches0 repliesSuperseded
v124 patches30 repliesSuperseded
v11 posting 3/34 patches7 repliesSuperseded
v11 posting 2/31 of 4 patches0 repliesSuperseded
v11 posting 1/34 patches0 repliesSuperseded
v10 posting 2/24 patches4 repliesSuperseded
v10 posting 1/24 patches11 repliesSuperseded
v94 patches36 repliesSuperseded
v84 patches34 repliesSuperseded
v7 posting 3/34 patches41 repliesSuperseded
v7 posting 2/34 patches8 repliesSuperseded
v7 posting 1/34 patches0 repliesSuperseded
v64 patches2 repliesSuperseded
v55 patches3 repliesSuperseded
v4 posting 3/35 patches20 repliesSuperseded
v4 posting 2/33 of 5 patches1 replySuperseded
v4 posting 1/35 patches6 repliesSuperseded
v33 patches5 repliesSuperseded
v23 patches30 repliesSuperseded
v12 patches19 repliesSuperseded

Changes in v19 from the cover letter

Other issues addressed in this patchset:
- Modify the method of looking up one USB charger instance, we assume there is only one USB charger in the system. But leaving things there to avoid any need for future refactoring to touch the usb_charger_register() interface.
- Remove usb_charger_set_current() API.
- Rename usb charger state.
- Remove ->get_charger_type() interface.
- Add some documentation for ->charger_detect() interface explicitly.
- Fix one issue: reset current to default values when cable was unplugged.
- Only notify the max current to power users, but users can get the min current by usb_charger_get_current() if users want to use the min current.
- Other small optimizations.

Patches in v19 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4usb: gadget: Introduce the usb charger frameworkdrivers/usb/gadget/Kconfig drivers/usb/gadget/udc/Makefile drivers/usb/gadget/udc/charger.c +2 more+986 -00 replies
2/4usb: gadget: Support for the usb charger frameworkdrivers/usb/gadget/udc/core.c include/linux/usb/gadget.h+21 -11 reply
3/4usb: gadget: Integrate with the usb gadget supporting for usb chargerdrivers/usb/gadget/udc/charger.c+96 -10 replies
4/4power: wm831x_power: Support USB charger current limit managementdrivers/power/supply/wm831x_power.c+63 -00 replies

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchLi JunLee JonesCharles KeepaxPeter ChenSebastian Reichel
SeriesA-b A-b A-b A-b
1/4R-b T-b
2/4R-b T-b
3/4R-b T-b
4/4A-b A-b A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v19 thread

Cover letter [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotation

Currently the Linux kernel does not provide any standard integration of this feature that integrates the USB subsystem with the system power regulation provided by PMICs meaning that either vendors must add this in their kernels or USB gadget devices based on Linux (such as mobile phones) may not behave as they should. Thus provide a standard framework for doing this in kernel.

Now introduce one user with wm831x_power to support and test the usb charger. Another user introduced to support charger detection by Jun Li:
https://www.spinics.net/lists/linux-usb/msg139425.html
Moreover there may be other potential users will use it in future.

1. Before v19 patchset we've fixed below issues in extcon subsystem and usb phy driver, now all were merged. (Thanks for Neil's suggestion)
(1) Have fixed the inconsistencies with USB connector types in extcon subsystem by following links:
https://lkml.org/lkml/2016/12/21/13
https://lkml.org/lkml/2016/12/21/15
https://lkml.org/lkml/2016/12/21/79
https://lkml.org/lkml/2017/1/3/13

(2) Instead of using 'set_power' callback in phy drivers, we will introduce USB charger to set PMIC current drawn from USB configuration, moreover some 'set_power' callbacks did not implement anything to set PMIC current, thus remove them by following links:
https://lkml.org/lkml/2017/1/18/436
https://lkml.org/lkml/2017/1/18/439
https://lkml.org/lkml/2017/1/18/438
Now only two phy drivers (phy-isp1301-omap.c and phy-gpio-vbus-usb.c) still used 'set_power' callback to set current, we can remove them in future. (I have no platform with enabling these two phy drivers, so I can not test them if I converted 'set_power' callback to USB charger.)

2. Some issues pointed by Neil Brown were sill kept in this v19 patchset, and I expalined each issue and may be need discuss again:
(1) Change all usb phys to register an extcon and to send appropriate notifications. Firstly, now only 3 USB phy drivers (phy-qcom-8x16-usb.c, phy-omap-otg.c and phy-msm-usb.c) had registered an extcon, mostly did not. I can not change all usb phys to register an extcon, since there are no extcon device to register for these different phy drivers.
Secondly, I also agreed with Peter's comments: Not only USB PHY to register an extcon, but also for the drivers which can detect USB charger type, it may be USB controller driver, USB type-c driver, pmic driver, and these drivers may not have an extcon device since the internal part can finish the vbus detect.

(2) Change the notifier of usb_phy to be used consistently.
Now only 3 phy drivers (phy-generic.c, phy-ab8500-usb.c and phy-gpio-vbus-usb.c) used the notifier of usb_phy. phy-generic.c and phy-gpio-vbus-usb.c were used to send out the connect events, and phy-ab8500-usb.c also was used to send out the MUSB connect events. There are no phy drivers will notify 'vbus_draw' information by the notifier of usb_phy, which was used consistently now. Moreover it is difficult to change the notifier of usb_phy to be used only to communicate the 'vbus_draw' information, since we need to refactor and test these related phy drivers, power drivers or some mfd drivers, which is a huge workload.

(3) Still keep charger_type_show() API.
Firstly I think we should combine all charger related information into one place for users, which is convenient.
Secondly not only we get charger type from extcon, but also in some scenarios we can get charger type from USB controller driver, USB type-c driver, pmic driver, we should also need one place to export the charger type.

Changes since v18:
Other issues addressed in this patchset:
- Modify the method of looking up one USB charger instance, we assume there is only one USB charger in the system. But leaving things there to avoid any need for future refactoring to touch the usb_charger_register() interface.
- Remove usb_charger_set_current() API.
- Rename usb charger state.
- Remove ->get_charger_type() interface.
- Add some documentation for ->charger_detect() interface explicitly.
- Fix one issue: reset current to default values when cable was unplugged.
- Only notify the max current to power users, but users can get the min current by usb_charger_get_current() if users want to use the min current.
- Other small optimizations.

Changes since v17:
- Remove goto section in usb_charger_register() function.
- Remove 'extern' in charger.h file.
- Move the kfree() to usb_charger_exit() function.

Changes since v16:
- Modify the charger current range with introducing the maximum and minimum current.
- Remove the getting charger type method from power supply.
- Add the getting charger type method from extcon system.
- Introduce new usb_charger_get_current() API for users to get the maximum and minimum current.
- Rename some APIs and other optimization.

Changes since v15:
- Add charger state checking to avoid sending out duplicate notifies to users.
- Add one work to notify power users the current has been changed.

Changes since v14:
- Add kernel documentation for struct usb_cahrger.
- Remove some redundant WARN() functions.

Changes since v13:
- Remove the charger checking in usb_gadget_vbus_draw() function.
- Rename some functions in charger.c file.
- Rebase on git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git tags/usb-for-v4.8

Changes since v12:
- Remove the class and device things.
- Link usb charger to udc-core.ko.
- Create one "charger" subdirectory which holds all charger-related attributes.

Changes since v11:
- Reviewed and tested by Li Jun.

Changes since v10:
- Introduce usb_charger_get_state() function to check charger state.
- Remove the mutex lock in usb_charger_set_cur_limit_by_type() function in case will be issued in atomic context.

Baolin Wang (4):
usb: gadget: Introduce the usb charger framework
usb: gadget: Support for the usb charger framework
usb: gadget: Integrate with the usb gadget supporting for usb charger
power: wm831x_power: Support USB charger current limit management

 drivers/power/supply/wm831x_power.c |   63 +++
 drivers/usb/gadget/Kconfig          |    8 +
 drivers/usb/gadget/udc/Makefile     |    1 +
 drivers/usb/gadget/udc/charger.c    |  865 +++++++++++++++++++++++++++++++++++
 drivers/usb/gadget/udc/core.c       |   19 +-
 include/linux/usb/charger.h         |  176 +++++++
 include/linux/usb/gadget.h          |    3 +
 include/uapi/linux/usb/charger.h    |   31 ++
 8 files changed, 1165 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/gadget/udc/charger.c
 create mode 100644 include/linux/usb/charger.h
 create mode 100644 include/uapi/linux/usb/charger.h
Signature · 1 line
1.7.9.5