Introduce usb charger framework to deal with the usb gadget power negotation
Subsystems (4)
v19 cover 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
PATCH v19 1/4 usb: gadget: Introduce the usb charger framework
This patch introduces the usb charger driver based on usb gadget that makes an enhancement to a power driver. It works well in practice but that requires a system with suitable hardware.
The basic conception of the usb charger is that, when one usb charger is added or removed by reporting from the usb gadget state change or the extcon device state change, the usb charger will report to power user to set the current limitation.
The usb charger will register notifiees on the usb gadget or the extcon device to get notified the usb charger state. It also supplies the notification mechanism to userspace When the usb charger state is changed.
Power user will register a notifiee on the usb charger to get notified by status changes from the usb charger. It will report to power user to set the current limitation when detecting the usb charger is added or removed from extcon device state or usb gadget state.
This patch doesn't yet integrate with the gadget code, so some functions which rely on the 'gadget' are not completed, that will be implemented in the following patches.
--- drivers/usb/gadget/Kconfig | 8 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/charger.c | 770 ++++++++++++++++++++++++++++++++++++++ include/linux/usb/charger.h | 176 +++++++++ include/uapi/linux/usb/charger.h | 31 ++ 5 files changed, 986 insertions(+) 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
drivers/usb/gadget/Kconfig +8 -0
@@ -134,6 +134,14 @@ config U_SERIAL_CONSOLE help It supports the serial gadget can be used as a console. +config USB_CHARGER + bool "USB charger support" + select EXTCON + help + The usb charger driver based on the usb gadget that makes an + enhancement to a power driver which can set the current limitation + when the usb charger is added or removed. + source "drivers/usb/gadget/udc/Kconfig" #
drivers/usb/gadget/udc/Makefile +1 -0
@@ -2,6 +2,7 @@ CFLAGS_trace.o := -I$(src) udc-core-y := core.o trace.o +udc-core-$(CONFIG_USB_CHARGER) += charger.o # # USB peripheral controller drivers
drivers/usb/gadget/udc/charger.c new file +770 -0
770 lines not on this page · raw message
include/linux/usb/charger.h new file +176 -0
176 lines not on this page · raw message
include/uapi/linux/usb/charger.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* This file defines the USB charger type and state that are needed for +* USB device APIs. +*/ + +#ifndef _UAPI__LINUX_USB_CHARGER_H +#define _UAPI__LINUX_USB_CHARGER_H + +/* +* USB charger type: +* SDP (Standard Downstream Port) +* DCP (Dedicated Charging Port) +* CDP (Charging Downstream Port) +* ACA (Accessory Charger Adapters) +*/ +enum usb_charger_type { +UNKNOWN_TYPE , +SDP_TYPE , +DCP_TYPE , +CDP_TYPE , +ACA_TYPE , +}; + +/* USB charger state */ +enum usb_charger_state { +USB_CHARGER_DEFAULT , +USB_CHARGER_PRESENT , +USB_CHARGER_ABSENT , +}; + +#endif /* _UAPI__LINUX_USB_CHARGER_H */
Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v19 2/4 usb: gadget: Support for the usb charger framework
In reply to Baolin WangFor supporting the usb charger, it adds the usb_charger_init() and usb_charger_exit() functions for usb charger initialization and exit.
It will report to the usb charger when the gadget state is changed, then the usb charger can do the power things.
--- drivers/usb/gadget/udc/core.c | 19 ++++++++++++++++++- include/linux/usb/gadget.h | 3 +++ 2 files changed, 21 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/core.c +18 -1
@@ -25,6 +25,7 @@#include <linux/dma-mapping.h> #include <linux/workqueue.h> +#include <linux/usb/charger.h> #include <linux/usb/ch9.h> #include <linux/usb/gadget.h> #include <linux/usb.h>
@@ -576,12 +577,17 @@ int usb_gadget_vbus_connect(struct usb_gadget *gadget)* reporting how much power the device may consume. For example, this * could affect how quickly batteries are recharged. * +* It will also notify the USB charger how much power the device may +* consume if there is a USB charger linking with the gadget. +* * Returns zero on success, else negative errno. */ int usb_gadget_vbus_draw (struct usb_gadget *gadget,unsigned mA) {int ret =0 ; +usb_charger_set_cur_limit_by_gadget (gadget, mA); +if (!gadget->ops->vbus_draw) { ret = -EOPNOTSUPP ; goto out;
@@ -963,6 +969,9 @@ static void usb_gadget_state_work(struct work_struct *work)struct usb_gadget *gadget =work_to_gadget (work);struct usb_udc *udc = gadget->udc; +/* when the gadget state is changed, then report to USB charger */ +usb_charger_plug_by_gadget (gadget, gadget->state); +if (udc)sysfs_notify (&udc->dev.kobj,NULL ,"state" ); }
@@ -1132,6 +1141,10 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,if (ret) goto err4; + ret =usb_charger_init (gadget); +if (ret) + goto err5; +usb_gadget_set_state (gadget,USB_STATE_NOTATTACHED ); udc->vbus = true;
@@ -1143,7 +1156,7 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,if (ret != -EPROBE_DEFER )list_del (&driver->pending);if (ret) - goto err5; + goto err6;break ; } }
@@ -1152,6 +1165,9 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,return 0 ; +err6: +usb_charger_exit (gadget); + err5:device_del (&udc->dev);
@@ -1263,6 +1279,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)kobject_uevent (&udc->dev.kobj,KOBJ_REMOVE );flush_work (&gadget->work);device_unregister (&udc->dev); +usb_charger_exit (gadget);device_unregister (&gadget->dev); }EXPORT_SYMBOL_GPL (usb_del_gadget_udc);
include/linux/usb/gadget.h +3 -0
@@ -24,6 +24,7 @@#include <linux/types.h> #include <linux/workqueue.h> #include <linux/usb/ch9.h> +#include <linux/usb/charger.h> #define UDC_TRACE_STR_MAX 512
@@ -328,6 +329,7 @@ struct usb_gadget_ops {* @in_epnum: last used in ep number * @mA: last set mA value * @otg_caps: OTG capabilities of this gadget. +* @charger: Negotiate the power with the usb charger. * @sg_supported: true if we can handle scatter-gather * @is_otg: True if the USB device port uses a Mini-AB jack, so that the * gadget driver must provide a USB OTG descriptor.
@@ -387,6 +389,7 @@ struct usb_gadget {unsigned in_epnum;unsigned mA;struct usb_otg_caps *otg_caps; +struct usb_charger *charger; unsigned sg_supported:1; unsigned is_otg:1;
Signature · 1 line
1.7.9.5
kbuild test robot
build botRe: [PATCH v19 2/4] usb: gadget: Support for the usb charger framework
url: https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20170220-173051 config: i386-randconfig-x015-201708 (attached…
Hi Baolin,
[auto build test ERROR on v4.9-rc8]
[cannot apply to balbi-usb/next usb/usb-testing battery/master next-20170220]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20170220-173051
config: i386-randconfig-x015-201708 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
In file included from drivers/usb/gadget/udc/core.c:28:0:
include/linux/usb/charger.h: In function 'usb_charger_get_state':
>> include/linux/usb/charger.h:151:9: error: 'USB_CHARGER_REMOVE' undeclared (first use in this function)
return USB_CHARGER_REMOVE;
^~~~~~~~~~~~~~~~~~ include/linux/usb/charger.h:151:9: note: each undeclared identifier is reported only once for each function it appears in
vim +/USB_CHARGER_REMOVE +151 include/linux/usb/charger.h
28929615 Baolin Wang 2017-02-20 145 return UNKNOWN_TYPE;
28929615 Baolin Wang 2017-02-20 146 }
28929615 Baolin Wang 2017-02-20 147
28929615 Baolin Wang 2017-02-20 148 static inline enum usb_charger_state
28929615 Baolin Wang 2017-02-20 149 usb_charger_get_state(struct usb_charger *uchger)
28929615 Baolin Wang 2017-02-20 150 {
28929615 Baolin Wang 2017-02-20 @151 return USB_CHARGER_REMOVE;
28929615 Baolin Wang 2017-02-20 152 }
28929615 Baolin Wang 2017-02-20 153
28929615 Baolin Wang 2017-02-20 154 static inline int usb_charger_detect_type(struct usb_charger *uchger):::::: The code at line 151 was first introduced by commit
:::::: 289296154f05985dedc08273f04d5b738450b3c7 usb: gadget: Introduce the usb charger framework
:::::: TO: Baolin Wang <[email protected]>
:::::: CC: 0day robot <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH v19 2/4] usb: gadget: Support for the usb charger framework
Quoted 13 lines · kbuild test robot
Hi Baolin,
[auto build test ERROR on v4.9-rc8]
[cannot apply to balbi-usb/next usb/usb-testing battery/master next-20170220]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20170220-173051
config: i386-randconfig-x015-201708 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:# save the attached .config to linux build tree make ARCH=i386
Quoted 6 lines
All errors (new ones prefixed by >>):
In file included from
drivers/usb/gadget/udc/core.c:28:0:
include/linux/usb/charger.h: In function 'usb_charger_get_state':Quoted 1 line
Quoted 1 line
include/linux/usb/charger.h:151:9: error: 'USB_CHARGER_REMOVE' undeclared (first use in this function)return USB_CHARGER_REMOVE;
Ah, missed fixing the state name without enable USB charger. Will fix in next version.
Quoted 25 lines
^~~~~~~~~~~~~~~~~~
include/linux/usb/charger.h:151:9: note: each undeclared identifier is reported only once for each function it appears invim +/USB_CHARGER_REMOVE +151
include/linux/usb/charger.h28929615 Baolin Wang 2017-02-20 145 return UNKNOWN_TYPE; 28929615 Baolin Wang 2017-02-20 146 } 28929615 Baolin Wang 2017-02-20 147 28929615 Baolin Wang 2017-02-20 148 static inline enum usb_charger_state 28929615 Baolin Wang 2017-02-20 149 usb_charger_get_state(struct usb_charger *uchger) 28929615 Baolin Wang 2017-02-20 150 { 28929615 Baolin Wang 2017-02-20 @151 return USB_CHARGER_REMOVE; 28929615 Baolin Wang 2017-02-20 152 } 28929615 Baolin Wang 2017-02-20 153 28929615 Baolin Wang 2017-02-20 154 static inline int usb_charger_detect_type(struct usb_charger *uchger):::::: The code at line 151 was first introduced by commit
::::::289296154f05985dedc08273f04d5b738450b3c7usb: gadget: Introduce the usb charger framework:::::: TO: Baolin Wang <[email protected]>
:::::: CC: 0day robot <[email protected]>---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Signature · 2 lines
Baolin.wang Best Regards
PATCH v19 3/4 usb: gadget: Integrate with the usb gadget supporting for usb charger
In reply to Baolin WangWhen the usb gadget supporting for usb charger is ready, the usb charger can implement the usb_charger_plug_by_gadget() function, usb_charger_exit() function and dev_to_uchger() function by getting 'struct usb_charger' from 'struct gadget'.
--- drivers/usb/gadget/udc/charger.c | 97 +++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/charger.c +96 -1
@@ -38,7 +38,9 @@static struct usb_charger *dev_to_uchger (struct device *dev) { -return NULL ; + struct usb_gadget *gadget = container_of(dev, struct usb_gadget, dev); + +return gadget->charger; }/*
@@ -398,6 +400,18 @@ static int __usb_charger_set_cur_limit_by_type(struct usb_charger *uchger,int usb_charger_set_cur_limit_by_gadget (struct usb_gadget *gadget,unsigned int cur_limit) { +struct usb_charger *uchger = gadget->charger; +int ret; + +if (!uchger) +return -EINVAL ; + + ret =__usb_charger_set_cur_limit_by_type (uchger, uchger->type, + cur_limit); +if (ret) +return ret; + +schedule_work (&uchger->work);return 0 ; }EXPORT_SYMBOL_GPL (usb_charger_set_cur_limit_by_gadget);
@@ -622,11 +636,66 @@ static int usb_charger_plug_by_extcon(struct notifier_block *nb,int usb_charger_plug_by_gadget (struct usb_gadget *gadget,unsigned long state) { +struct usb_charger *uchger = gadget->charger; +enum usb_charger_state uchger_state; + +if (WARN (!uchger,"charger can not be NULL" )) +return -EINVAL ; + +/* +* Report event to power to setting the current limitation +* for this usb charger when one usb charger state is changed +* with detecting by usb gadget state. +*/ +if (uchger->old_gadget_state != state) { + uchger->old_gadget_state = state; + +if (state >=USB_STATE_ATTACHED ) { + uchger_state =USB_CHARGER_PRESENT ; + }else if (state ==USB_STATE_NOTATTACHED ) { +mutex_lock (&uchger->lock); + +/* +* Need check the charger type to make sure the usb +* cable is removed, in case it just changes the usb +* function with configfs. +*/ +if (uchger->type !=UNKNOWN_TYPE ) { +mutex_unlock (&uchger->lock); +return 0 ; + } + +mutex_unlock (&uchger->lock); + uchger_state =USB_CHARGER_ABSENT ; + }else { + uchger_state =USB_CHARGER_DEFAULT ; + } + +usb_charger_notify_state (uchger, uchger_state); + } +return 0 ; }EXPORT_SYMBOL_GPL (usb_charger_plug_by_gadget);/* +* usb_charger_unregister() - Unregister a usb charger. +* @uchger - the usb charger to be unregistered. +*/ +static int usb_charger_unregister (struct usb_charger *uchger) +{ +ida_simple_remove (&usb_charger_ida, uchger->id); +sysfs_remove_groups (&uchger->gadget->dev.kobj, usb_charger_groups); + uchger->id =-1 ; + +mutex_lock (&charger_lock); +list_del (&uchger->list); +mutex_unlock (&charger_lock); + +return 0 ; +} + +/* * usb_charger_register() - Register a new usb charger. * @uchger - the new usb charger instance. */
@@ -725,6 +794,7 @@ int usb_charger_init(struct usb_gadget *ugadget) } uchger->gadget = ugadget; + ugadget->charger = uchger; uchger->old_gadget_state =USB_STATE_NOTATTACHED ;/* Register a new usb charger */
@@ -762,6 +832,31 @@ int usb_charger_init(struct usb_gadget *ugadget)int usb_charger_exit (struct usb_gadget *ugadget) { +struct usb_charger *uchger = ugadget->charger; + +if (!uchger) +return -EINVAL ; + +usb_charger_unregister (uchger); + ugadget->charger =NULL ; + +extcon_unregister_notifier (uchger->extcon_dev, +EXTCON_USB , + &uchger->extcon_nb.nb); +extcon_unregister_notifier (uchger->extcon_dev, +EXTCON_CHG_USB_SDP , + &uchger->extcon_type_nb.nb); +extcon_unregister_notifier (uchger->extcon_dev, +EXTCON_CHG_USB_CDP , + &uchger->extcon_type_nb.nb); +extcon_unregister_notifier (uchger->extcon_dev, +EXTCON_CHG_USB_DCP , + &uchger->extcon_type_nb.nb); +extcon_unregister_notifier (uchger->extcon_dev, +EXTCON_CHG_USB_ACA , + &uchger->extcon_type_nb.nb); + +kfree (uchger);return 0 ; }
Signature · 1 line
1.7.9.5
PATCH v19 4/4 power: wm831x_power: Support USB charger current limit management
In reply to Baolin WangIntegrate with the newly added USB charger interface to limit the current we draw from the USB input based on the input device configuration identified by the USB stack, allowing us to charge more quickly from high current inputs without drawing more current than specified from others.
--- drivers/power/supply/wm831x_power.c | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
drivers/power/supply/wm831x_power.c +63 -0
@@ -13,6 +13,7 @@#include <linux/platform_device.h> #include <linux/power_supply.h> #include <linux/slab.h> +#include <linux/usb/charger.h> #include <linux/mfd/wm831x/core.h> #include <linux/mfd/wm831x/auxadc.h>
@@ -31,6 +32,8 @@ struct wm831x_power {char usb_name[20 ];char battery_name[20 ];bool have_battery; +struct usb_charger *usb_charger; +struct notifier_block usb_notify; }; static int wm831x_power_check_online(struct wm831x *wm831x, int supply,
@@ -125,6 +128,42 @@ static int wm831x_usb_get_prop(struct power_supply *psy, POWER_SUPPLY_PROP_VOLTAGE_NOW, }; +/* In milliamps */ +static const unsigned int wm831x_usb_limits[] = { +0 , +2 , +100 , +500 , +900 , +1500 , +1800 , +550 , +}; + +static int wm831x_usb_limit_change (struct notifier_block *nb, +unsigned long limit,void *data) +{ +struct wm831x_power *wm831x_power =container_of (nb, + struct wm831x_power, + usb_notify); + +/* Find the highest supported limit */ + best =0 ; +for (i =0 ; i <ARRAY_SIZE (wm831x_usb_limits); i++) { +if (limit >= wm831x_usb_limits[i] && + wm831x_usb_limits[best] < wm831x_usb_limits[i]) + best = i; + } + +dev_dbg (wm831x_power->wm831x->dev, +"Limiting USB current to %umA" , wm831x_usb_limits[best]); + +wm831x_set_bits (wm831x_power->wm831x,WM831X_POWER_STATE , +WM831X_USB_ILIM_MASK , best); + +return 0 ; +} +/********************************************************************* * Battery properties *********************************************************************/
@@ -607,8 +646,26 @@ static int wm831x_power_probe(struct platform_device *pdev) } } + power->usb_charger =usb_charger_get_instance (); +if (IS_ERR (power->usb_charger)) { + ret =PTR_ERR (power->usb_charger); +dev_err (&pdev->dev,"Failed to find USB gadget: %d\n" , ret); + goto err_bat_irq; + } + + power->usb_notify.notifier_call = wm831x_usb_limit_change; + + ret =usb_charger_register_notify (power->usb_charger, + &power->usb_notify); +if (ret !=0 ) { +dev_err (&pdev->dev,"Failed to register notifier: %d\n" , ret); + goto err_usb_charger; + } +return ret; +err_usb_charger: +/* put_device on charger */ err_bat_irq: --i;for (; i >=0 ; i--) {
@@ -637,6 +694,12 @@ static int wm831x_power_remove(struct platform_device *pdev)struct wm831x *wm831x = wm831x_power->wm831x;int irq, i; +if (wm831x_power->usb_charger) { +usb_charger_unregister_notify (wm831x_power->usb_charger, + &wm831x_power->usb_notify); +/* Free charger */ + } +for (i =0 ; i <ARRAY_SIZE (wm831x_bat_irqs); i++) { irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev,
Signature · 6 lines
1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
kbuild test robot
build botRe: [PATCH v19 4/4] power: wm831x_power: Support USB charger current limit management
url: https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20170220-173051 config: i386-randconfig-x017-201708 (attached…
Hi Baolin,
[auto build test ERROR on v4.9-rc8]
[cannot apply to balbi-usb/next usb/usb-testing battery/master next-20170220]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Baolin-Wang/Introduce-usb-charger-framework-to-deal-with-the-usb-gadget-power-negotation/20170220-173051
config: i386-randconfig-x017-201708 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 All errors (new ones prefixed by >>):
In file included from drivers/power/supply/wm831x_power.c:16:0:
include/linux/usb/charger.h: In function 'usb_charger_get_state':
include/linux/usb/charger.h:151:9: error: 'USB_CHARGER_REMOVE' undeclared (first use in this function)
return USB_CHARGER_REMOVE;
^~~~~~~~~~~~~~~~~~
include/linux/usb/charger.h:151:9: note: each undeclared identifier is reported only once for each function it appears in
drivers/power/supply/wm831x_power.c: In function 'wm831x_usb_limit_change':
>> drivers/power/supply/wm831x_power.c:151:2: error: 'best' undeclared (first use in this function)
best = 0;
^~~~
>> drivers/power/supply/wm831x_power.c:152:7: error: 'i' undeclared (first use in this function)
for (i = 0; i < ARRAY_SIZE(wm831x_usb_limits); i++) {
^vim +/best +151 drivers/power/supply/wm831x_power.c
10
11 #include <linux/module.h>
12 #include <linux/err.h>
13 #include <linux/platform_device.h>
14 #include <linux/power_supply.h>
15 #include <linux/slab.h>
> 16 #include <linux/usb/charger.h>
17
18 #include <linux/mfd/wm831x/core.h>
19 #include <linux/mfd/wm831x/auxadc.h>
20 #include <linux/mfd/wm831x/pmu.h>
21 #include <linux/mfd/wm831x/pdata.h>
22
23 struct wm831x_power {
24 struct wm831x *wm831x;
25 struct power_supply *wall;
26 struct power_supply *usb;
27 struct power_supply *battery;
28 struct power_supply_desc wall_desc;
29 struct power_supply_desc usb_desc;
30 struct power_supply_desc battery_desc;
31 char wall_name[20];
32 char usb_name[20];
33 char battery_name[20];
34 bool have_battery;
35 struct usb_charger *usb_charger;
36 struct notifier_block usb_notify;
37 };
38
39 static int wm831x_power_check_online(struct wm831x *wm831x, int supply,
40 union power_supply_propval *val)
41 {
42 int ret;
43
44 ret = wm831x_reg_read(wm831x, WM831X_SYSTEM_STATUS);
45 if (ret < 0)
46 return ret;
47
48 if (ret & supply)
49 val->intval = 1;
50 else
51 val->intval = 0;
52
53 return 0;
54 }
55
56 static int wm831x_power_read_voltage(struct wm831x *wm831x,
57 enum wm831x_auxadc src,
58 union power_supply_propval *val)
59 {
60 int ret;
61
62 ret = wm831x_auxadc_read_uv(wm831x, src);
63 if (ret >= 0)
64 val->intval = ret;
65
66 return ret;
67 }
68
69 /*********************************************************************
70 * WALL Power
71 *********************************************************************/
72 static int wm831x_wall_get_prop(struct power_supply *psy,
73 enum power_supply_property psp,
74 union power_supply_propval *val)
75 {
76 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev.parent);
77 struct wm831x *wm831x = wm831x_power->wm831x;
78 int ret = 0;
79
80 switch (psp) {
81 case POWER_SUPPLY_PROP_ONLINE:
82 ret = wm831x_power_check_online(wm831x, WM831X_PWR_WALL, val);
83 break;
84 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
85 ret = wm831x_power_read_voltage(wm831x, WM831X_AUX_WALL, val);
86 break;
87 default:
88 ret = -EINVAL;
89 break;
90 }
91
92 return ret;
93 }
94
95 static enum power_supply_property wm831x_wall_props[] = {
96 POWER_SUPPLY_PROP_ONLINE,
97 POWER_SUPPLY_PROP_VOLTAGE_NOW,
98 };
99
100 /*********************************************************************
101 * USB Power
102 *********************************************************************/
103 static int wm831x_usb_get_prop(struct power_supply *psy,
104 enum power_supply_property psp,
105 union power_supply_propval *val)
106 {
107 struct wm831x_power *wm831x_power = dev_get_drvdata(psy->dev.parent);
108 struct wm831x *wm831x = wm831x_power->wm831x;
109 int ret = 0;
110
111 switch (psp) {
112 case POWER_SUPPLY_PROP_ONLINE:
113 ret = wm831x_power_check_online(wm831x, WM831X_PWR_USB, val);
114 break;
115 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
116 ret = wm831x_power_read_voltage(wm831x, WM831X_AUX_USB, val);
117 break;
118 default:
119 ret = -EINVAL;
120 break;
121 }
122
123 return ret;
124 }
125
126 static enum power_supply_property wm831x_usb_props[] = {
127 POWER_SUPPLY_PROP_ONLINE,
128 POWER_SUPPLY_PROP_VOLTAGE_NOW,
129 };
130
131 /* In milliamps */
132 static const unsigned int wm831x_usb_limits[] = {
133 0,
134 2,
135 100,
136 500,
137 900,
138 1500,
139 1800,
140 550,
141 };
142
143 static int wm831x_usb_limit_change(struct notifier_block *nb,
144 unsigned long limit, void *data)
145 {
146 struct wm831x_power *wm831x_power = container_of(nb,
147 struct wm831x_power,
148 usb_notify);
149
150 /* Find the highest supported limit */
> 151 best = 0;
> 152 for (i = 0; i < ARRAY_SIZE(wm831x_usb_limits); i++) { 153 if (limit >= wm831x_usb_limits[i] &&
154 wm831x_usb_limits[best] < wm831x_usb_limits[i])
155 best = i;
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 32 lines · Baolin Wang
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_powerto 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.candphy-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.)
Quoted 7 lines
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.candphy-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.
You don't have to change every driver. You just need to make it easy and obvious how to change drivers in a consistent coherent way. For a start you would add a 'struct extcon_dev' to 'struct usb_phy', and possibly add or extend some 'static inline's in linux/usb/phy.h to send notification on that extcon (if it is non-NULL).
e.g. usb_phy_vbus_on() could send an extcon notification.
Then any phy driver which adds support for setting phy->extcon_dev appropriately, immediately gets the relevant notifications sent.
Quoted 5 lines
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.
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification.
Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together.
Somehow these three need to work together to determine what is plugged in to the external connection port. Somewhere there much an 'extcon' device which represents that port and which the three devices can find and can interact with.
I think it makes sense for the usb_phy to be the connection point. Each of the devices can get to the phy, and the phy can get to the extcon. It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that represents it.
Quoted 11 lines
(2) Change the notifier of
usb_phyto be used consistently.
Now only 3 phy drivers (phy-generic.c,phy-ab8500-usb.candphy-gpio-vbus-usb.c) used the notifier ofusb_phy.phy-generic.candphy-gpio-vbus-usb.cwere used to send out the connect events, andphy-ab8500-usb.calso was used to send out the MUSB connect events. There are no phy drivers will notify 'vbus_draw' information by the notifier ofusb_phy, which was used consistently now. Moreover it is difficult to change the notifier ofusb_phyto 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.
You missed drivers/usb/musb/omap2430.c in you list, but that hardly matters.phy-ab8500-usb.c appears to send vbus_draw information.
I understand your reluctance to change drivers that you cannot test. An alternative it do change all the
atomic_notifier_call_chain(.*notifier,
calls that don't pass a pointer to vbus_draw to pass NULL, and to declare the passing of NULL to be deprecated (so hopefully people won't use it in new code).
Then any notification callback that expects a current can just ignore calls where the pointer is NULL.
The one difficulty with this is drivers/usb/gadget/udc/pxa27x_udc.c It is the only driver which expects a 'gadget', and it doesn't really need to as it already knows the gadget.
The patch below fixes this.
With that in place, phy-generic and phy-gpio-vbus-usb can be changed to pass NULL. When we can safely use the notifier to pass vbus_draw information uniformly.
Quoted 4 lines
(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.
convenience is very much a secondary issue.
Quoted 3 lines
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.
As I have said, all of these sources of information should feed into the extcon.
There are ultimately two possible sources of information about the current available from the usb port.
One is the physical properties of the cable, such as resistance of ID, any short between D+ and D- etc. Being properties of the cable, they should be reported through the extcon.
The other is information gathered during the USB protocol handshake. For USB2, this is the requested current of the profile that the host activates. This should be reported though the USB gadget device.
I don't know how USB3 and/or type-C work but I would be surprised if they don't fit into the two cases above. If you think otherwise, please surprise me. I'm always keen to learn.
If the extcon reports the type of cable detected, and the gadget reports the result of any negotiation, then that is enough to determine the charger type. It doesn't need to be more convenient than that.
Thanks,
NeilBrown
From 75a77246d2e9224f579ab996640a435a1c587d5f Mon Sep 17 00:00:00 2001
From: NeilBrown <[email protected]>
Date: Fri, 3 Mar 2017 13:05:17 +1100
Subject: [PATCH] usb: gadget: pxa27x: change event handler to not expect
gadget.
We are planning to change the usb notifier to not pass a gadget, as different drivers pass different things and consistency would be nice.
The only driver to expect a gadget is pxa27x.
Unlike other drivers that register a usb notifier, pxa27x uses a static notifier_block. Other drivers embed a notifer_block in their data struct so that struct can be access from the notifer callback.
So change pxa27x to use as embedded notifer_block, and to use that to find the target gadget.
With this, it can ignore that pointer that is passed. This will allow us to change all calls that pass a gadget, to instead pass NULL.
--- drivers/usb/gadget/udc/pxa27x_udc.c | 14 ++++++-------- drivers/usb/gadget/udc/pxa27x_udc.h | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/usb/gadget/udc/pxa27x_udc.c +6 -8
@@ -1669,7 +1669,8 @@ static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)static int pxa_udc_phy_event (struct notifier_block *nb,unsigned long action,void *data) { -struct usb_gadget *gadget = data; + struct pxa_udc *udc = container_of(nb, struct pxa_udc, nb); +struct usb_gadget *gadget = &udc->gadget;switch (action) {case USB_EVENT_VBUS :
@@ -1683,10 +1684,6 @@ static int pxa_udc_phy_event(struct notifier_block *nb, unsigned long action, } } -static struct notifier_block pxa27x_udc_phy = { - .notifier_call = pxa_udc_phy_event, -}; -static int pxa27x_udc_start (struct usb_gadget *g,struct usb_gadget_driver *driver);static int pxa27x_udc_stop (struct usb_gadget *g);
@@ -2504,8 +2501,9 @@ static int pxa_udc_probe(struct platform_device *pdev) goto err; } + udc->nb.notifier_call = pxa_udc_phy_event;if (!IS_ERR_OR_NULL (udc->transceiver)) -usb_register_notifier (udc->transceiver, &pxa27x_udc_phy); +usb_register_notifier (udc->transceiver, &udc->nb); retval =usb_add_gadget_udc (&pdev->dev, &udc->gadget);if (retval) goto err_add_gadget;
@@ -2517,7 +2515,7 @@ static int pxa_udc_probe(struct platform_device *pdev) err_add_gadget:if (!IS_ERR_OR_NULL (udc->transceiver)) -usb_unregister_notifier (udc->transceiver, &pxa27x_udc_phy); +usb_unregister_notifier (udc->transceiver, &udc->nb); err:clk_unprepare (udc->clk);return retval;
@@ -2535,7 +2533,7 @@ static int pxa_udc_remove(struct platform_device *_dev)pxa_cleanup_debugfs (udc);if (!IS_ERR_OR_NULL (udc->transceiver)) -usb_unregister_notifier (udc->transceiver, &pxa27x_udc_phy); +usb_unregister_notifier (udc->transceiver, &udc->nb);usb_put_phy (udc->transceiver); udc->transceiver =NULL ;
drivers/usb/gadget/udc/pxa27x_udc.h +2 -0
@@ -461,6 +461,8 @@ struct pxa_udc {struct gpio_desc *gpiod;struct usb_phy *transceiver; +struct notifier_block nb; +enum ep0_state ep0state;struct udc_stats stats;
Signature · 1 line
2.11.0
Quoted 49 lines · NeilBrown
Quoted 32 lines · Baolin Wang
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_powerto 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.candphy-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.)Quoted 7 lines
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.candphy-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.You don't have to change every driver. You just need to make it easy and obvious how to change drivers in a consistent coherent way. For a start you would add a 'struct
extcon_dev' to 'structusb_phy', and possibly add or extend some 'static inline's inlinux/usb/phy.hto send notification on that extcon (if it is non-NULL).
e.g.usb_phy_vbus_on()could send an extcon notification.
Quoted 2 lines
Then any phy driver which adds support for setting
phy->extcon_devappropriately, immediately gets the relevant notifications sent.
OK. We can make these extcon related code into phy common part.
Quoted 22 lines
Quoted 6 lines
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.
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification.
Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together.
Somehow these three need to work together to determine what is plugged in to the external connection port. Somewhere there much an 'extcon' device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connection point. Each of the devices can get to the phy, and the phy can get to the extcon. It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).
Quoted 2 lines
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that represents it.
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by software?
Quoted 13 lines
Quoted 12 lines
(2) Change the notifier of
usb_phyto be used consistently.
Now only 3 phy drivers (phy-generic.c,phy-ab8500-usb.candphy-gpio-vbus-usb.c) used the notifier ofusb_phy.phy-generic.candphy-gpio-vbus-usb.cwere used to send out the connect events, andphy-ab8500-usb.calso was used to send out the MUSB connect events. There are no phy drivers will notify 'vbus_draw' information by the notifier ofusb_phy, which was used consistently now. Moreover it is difficult to change the notifier ofusb_phyto 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.
Quoted 2 lines
You missed
drivers/usb/musb/omap2430.cin you list, but that hardly matters.
But it did not use the notifier of usb_phy.
Quoted 1 line
phy-ab8500-usb.cappears to sendvbus_drawinformation.
Users will not use the vbus_draw information send from phy-ab8500-usb.c
Quoted 9 lines
I understand your reluctance to change drivers that you cannot test. An alternative it do change all the
atomic_notifier_call_chain(.*notifier,
calls that don't pass a pointer tovbus_drawto pass NULL, and to declare the passing of NULL to be deprecated (so hopefully people won't use it in new code).
Then any notification callback that expects a current can just ignore calls where the pointer is NULL.
I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.
Quoted 33 lines
The one difficulty with this is
drivers/usb/gadget/udc/pxa27x_udc.cIt is the only driver which expects a 'gadget', and it doesn't really need to as it already knows the gadget.
The patch below fixes this.
With that in place, phy-generic and phy-gpio-vbus-usb can be changed to pass NULL. When we can safely use the notifier to passvbus_drawinformation uniformly.Quoted 4 lines
(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.convenience is very much a secondary issue.
Quoted 3 lines
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.
As I have said, all of these sources of information should feed into the extcon.
There are ultimately two possible sources of information about the current available from the usb port.
One is the physical properties of the cable, such as resistance of ID, any short between D+ and D- etc. Being properties of the cable, they should be reported through the extcon.The other is information gathered during the USB protocol handshake. For USB2, this is the requested current of the profile that the host activates. This should be reported though the USB gadget device.
Quoted 7 lines
I don't know how USB3 and/or type-C work but I would be surprised if they don't fit into the two cases above. If you think otherwise, please surprise me. I'm always keen to learn.
If the extcon reports the type of cable detected, and the gadget reports the result of any negotiation, then that is enough to determine the charger type. It doesn't need to be more convenient than that.
If we are all agree we did not need the USB charger, then we can add 'current' attribute of USB gadget device.
Thanks for your suggestion.
Signature · 6 lines
Baolin.wang Best Regards -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
Quoted 76 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Tuesday, March 07, 2017 5:39 PM
To: NeilBrown <[email protected]>
Cc: Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Jun Li <[email protected]>; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 7 lines · NeilBrown
Quoted 5 lines · Baolin Wang
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.
Quoted 2 lines
Quoted 2 lines
Now introduce one user with
wm831x_powerto support and test the usbcharger.
Quoted 27 lines
Quoted 27 lines
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.candphy-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.)Quoted 3 lines
Quoted 3 lines
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 appropriatenotifications.
Quoted 13 lines
Quoted 5 lines
Firstly, now only 3 USB phy drivers (
phy-qcom-8x16-usb.c,phy-omap-otg.candphy-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.You don't have to change every driver. You just need to make it easy and obvious how to change drivers in a consistent coherent way. For a start you would add a 'struct
extcon_dev' to 'structusb_phy', and possibly add or extend some 'static inline's inlinux/usb/phy.hto send notification on that extcon (if it is non-NULL).
e.g.usb_phy_vbus_on()could send an extcon notification.
Quoted 5 lines
Quoted 2 lines
Then any phy driver which adds support for setting
phy->extcon_devappropriately, immediately gets the relevant notifications sent.OK. We can make these extcon related code into phy common part.
Will generic phy need add extcon as well?
Quoted 23 lines
Quoted 7 lines
Quoted 6 lines
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.
Quoted 6 lines
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification.
Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together.
Somehow these three need to work together to determine what isplugged
Quoted 9 lines
in to the external connection port. Somewhere there much an 'extcon' device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connection point. Each of the devices can get to the phy, and the phy can get to the extcon. It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).
Quoted 6 lines
Quoted 2 lines
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that represents it.
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by software?
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework, right?
Li Jun
Quoted 87 lines
Quoted 8 lines
Quoted 8 lines
(2) Change the notifier of
usb_phyto be used consistently. Now only 3 phy drivers (phy-generic.c,phy-ab8500-usb.candphy-gpio-vbus-usb.c) used the notifier ofusb_phy.phy-generic.candphy-gpio-vbus-usb.cwere used to send out the connect events, andphy-ab8500-usb.calso was used to send out the MUSB connect events. There are no phy drivers will notify 'vbus_draw' information by thenotifier of
usb_phy, which was used consistently now.Quoted 7 lines
Quoted 4 lines
Moreover it is difficult to change the notifier of
usb_phyto 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.You missed
drivers/usb/musb/omap2430.cin you list, but that hardly matters.But it did not use the notifier of
usb_phy.Quoted 1 line
phy-ab8500-usb.cappears to sendvbus_drawinformation.Users will not use the
vbus_drawinformation send fromphy-ab8500-usb.cQuoted 9 lines
I understand your reluctance to change drivers that you cannot test. An alternative it do change all the
atomic_notifier_call_chain(.*notifier,
calls that don't pass a pointer tovbus_drawto pass NULL, and to declare the passing of NULL to be deprecated (so hopefully people won't use it in new code).
Then any notification callback that expects a current can just ignore calls where the pointer is NULL.I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.
Quoted 10 lines
The one difficulty with this is
drivers/usb/gadget/udc/pxa27x_udc.cIt is the only driver which expects a 'gadget', and it doesn't really need to as it already knows the gadget.
The patch below fixes this.
With that in place, phy-generic and phy-gpio-vbus-usb can be changed to pass NULL. When we can safely use the notifier to passvbus_drawinformation uniformly.Quoted 1 line
Quoted 9 lines
Quoted 3 lines
(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.convenience is very much a secondary issue.
Quoted 3 lines
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.
Quoted 14 lines
As I have said, all of these sources of information should feed into the extcon.
There are ultimately two possible sources of information about the current available from the usb port.
One is the physical properties of the cable, such as resistance of ID, any short between D+ and D- etc. Being properties of the cable, they should be reported through the extcon.The other is information gathered during the USB protocol handshake. For USB2, this is the requested current of the profile that the host activates. This should be reported though the USB gadget device.
Quoted 7 lines
I don't know how USB3 and/or type-C work but I would be surprised if they don't fit into the two cases above. If you think otherwise, please surprise me. I'm always keen to learn.
If the extcon reports the type of cable detected, and the gadget reports the result of any negotiation, then that is enough to determine the charger type. It doesn't need to be more convenient than
that.
If we are all agree we did not need the USB charger, then we can add 'current' attribute of USB gadget device.
Thanks for your suggestion.--
Baolin.wang
Best Regards
Hi,
Quoted 78 lines · Jun Li
Hi,
Quoted 76 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Tuesday, March 07, 2017 5:39 PM
To: NeilBrown <[email protected]>
Cc: Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Jun Li <[email protected]>; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 7 lines · NeilBrown
Quoted 5 lines · Baolin Wang
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.
Quoted 2 lines
Quoted 2 lines
Now introduce one user with
wm831x_powerto support and test the usbcharger.
Quoted 27 lines
Quoted 27 lines
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.candphy-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.)Quoted 3 lines
Quoted 3 lines
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 appropriatenotifications.
Quoted 13 lines
Quoted 5 lines
Firstly, now only 3 USB phy drivers (
phy-qcom-8x16-usb.c,phy-omap-otg.candphy-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.You don't have to change every driver. You just need to make it easy and obvious how to change drivers in a consistent coherent way. For a start you would add a 'struct
extcon_dev' to 'structusb_phy', and possibly add or extend some 'static inline's inlinux/usb/phy.hto send notification on that extcon (if it is non-NULL).
e.g.usb_phy_vbus_on()could send an extcon notification.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Then any phy driver which adds support for setting
phy->extcon_devappropriately, immediately gets the relevant notifications sent.OK. We can make these extcon related code into phy common part.
Will generic phy need add extcon as well?
Yes, will add a 'struct extcon_dev*' in 'struct usb_phy', which will be common code.
Quoted 27 lines
Quoted 27 lines
Quoted 8 lines
Quoted 7 lines
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.
Quoted 6 lines
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification.
Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together.
Somehow these three need to work together to determine what isplugged
Quoted 11 lines
in to the external connection port. Somewhere there much an 'extcon' device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connection point. Each of the devices can get to the phy, and the phy can get to the extcon. It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that represents it.
Quoted 7 lines
Quoted 3 lines
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by software?
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework, right?
Not in USB charger framework. If we are all agree every usb_phy can register one extcon device, can get correct charger type and send out correct vbus_draw information, then we don't need USB charger framework as Neil suggested. So this will be okay for your case (especially for detecting the charger type by software) ?
Quoted 87 lines
Quoted 87 lines
Quoted 8 lines
Quoted 8 lines
(2) Change the notifier of
usb_phyto be used consistently. Now only 3 phy drivers (phy-generic.c,phy-ab8500-usb.candphy-gpio-vbus-usb.c) used the notifier ofusb_phy.phy-generic.candphy-gpio-vbus-usb.cwere used to send out the connect events, andphy-ab8500-usb.calso was used to send out the MUSB connect events. There are no phy drivers will notify 'vbus_draw' information by thenotifier of
usb_phy, which was used consistently now.Quoted 7 lines
Quoted 4 lines
Moreover it is difficult to change the notifier of
usb_phyto 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.You missed
drivers/usb/musb/omap2430.cin you list, but that hardly matters.But it did not use the notifier of
usb_phy.Quoted 1 line
phy-ab8500-usb.cappears to sendvbus_drawinformation.Users will not use the
vbus_drawinformation send fromphy-ab8500-usb.cQuoted 9 lines
I understand your reluctance to change drivers that you cannot test. An alternative it do change all the
atomic_notifier_call_chain(.*notifier,
calls that don't pass a pointer tovbus_drawto pass NULL, and to declare the passing of NULL to be deprecated (so hopefully people won't use it in new code).
Then any notification callback that expects a current can just ignore calls where the pointer is NULL.I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.
Quoted 10 lines
The one difficulty with this is
drivers/usb/gadget/udc/pxa27x_udc.cIt is the only driver which expects a 'gadget', and it doesn't really need to as it already knows the gadget.
The patch below fixes this.
With that in place, phy-generic and phy-gpio-vbus-usb can be changed to pass NULL. When we can safely use the notifier to passvbus_drawinformation uniformly.Quoted 1 line
Quoted 9 lines
Quoted 3 lines
(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.convenience is very much a secondary issue.
Quoted 3 lines
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.
Quoted 14 lines
As I have said, all of these sources of information should feed into the extcon.
There are ultimately two possible sources of information about the current available from the usb port.
One is the physical properties of the cable, such as resistance of ID, any short between D+ and D- etc. Being properties of the cable, they should be reported through the extcon.The other is information gathered during the USB protocol handshake. For USB2, this is the requested current of the profile that the host activates. This should be reported though the USB gadget device.
Quoted 7 lines
I don't know how USB3 and/or type-C work but I would be surprised if they don't fit into the two cases above. If you think otherwise, please surprise me. I'm always keen to learn.
If the extcon reports the type of cable detected, and the gadget reports the result of any negotiation, then that is enough to determine the charger type. It doesn't need to be more convenient than
that.
If we are all agree we did not need the USB charger, then we can add 'current' attribute of USB gadget device.
Thanks for your suggestion.--
Baolin.wang
Best Regards
Signature · 2 lines
Baolin.wang Best Regards
Quoted 114 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Thursday, March 09, 2017 2:11 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationHi,
Quoted 57 lines · Jun Li
Hi,
Quoted 55 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Tuesday, March 07, 2017 5:39 PM
To: NeilBrown <[email protected]>
Cc: Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Jun Li <[email protected]>; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 8 lines · NeilBrown
Quoted 6 lines · Baolin Wang
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.
Quoted 3 lines
Quoted 3 lines
Now introduce one user with
wm831x_powerto support and test the usbcharger.
Quoted 19 lines
Quoted 19 lines
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 byfollowing links:
Quoted 31 lines
Quoted 31 lines
Quoted 10 lines
Quoted 10 lines
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.candphy-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.)Quoted 4 lines
Quoted 4 lines
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 appropriatenotifications.
Quoted 15 lines
Quoted 5 lines
Firstly, now only 3 USB phy drivers (
phy-qcom-8x16-usb.c,phy-omap-otg.candphy-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.You don't have to change every driver. You just need to make it easy and obvious how to change drivers in a consistent coherent way. For a start you would add a 'struct
extcon_dev' to 'structusb_phy', and possibly add or extend some 'static inline's inlinux/usb/phy.hto send notification on that extcon (if it is non-NULL). e.g.usb_phy_vbus_on()could send an extcon notification.Then any phy driver which adds support for setting
phy->extcon_devappropriately, immediately gets the relevant notifications sent.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
OK. We can make these extcon related code into phy common part.
Will generic phy need add extcon as well?
Yes, will add a 'struct extcon_dev*' in 'struct
usb_phy', which will be common code.
I mean the common code need add 'struct extcon_dev' into both 'struct phy' and 'struct usb_phy', right? as some/new usb phy use that generic phy driver.
Quoted 37 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 7 lines
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.
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification. Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together.
Somehow these three need to work together to determine what isQuoted 6 lines
Quoted 6 lines
plugged
Quoted 5 lines
in to the external connection port. Somewhere there much an 'extcon' device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connection point. Each of the devices can get to the phy, and the phy can get to theextcon.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that represents it.
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by
software?
Quoted 5 lines
Quoted 1 line
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework, right?
Quoted 5 lines
Not in USB charger framework. If we are all agree every
usb_phycan register one extcon device, can get correct charger type and send out correctvbus_drawinformation, then we don't need USB charger framework as Neil suggested. So this will be okay for your case (especially for detecting the charger type by software) ?
In my case, charger detection is done by controller driver and I need do charger type detection internally, and only pass the current draw info via phy which will send out, this seems ok for me, but I think it will be good if you or someone can show us an example user based on the design Neil suggested.
Will you work out that common code if this USB charger framework is not needed?
Li Jun
Quoted 99 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
(2) Change the notifier of
usb_phyto be used consistently. Now only 3 phy drivers (phy-generic.c,phy-ab8500-usb.candphy-gpio-vbus-usb.c) used the notifier ofusb_phy.phy-generic.candphy-gpio-vbus-usb.cwere used to send out the connect events, andphy-ab8500-usb.calso was used to send out the MUSB connectevents.
Quoted 77 lines
Quoted 77 lines
Quoted 2 lines
Quoted 2 lines
There are no phy drivers will notify '
vbus_draw' information by thenotifier of
usb_phy, which was used consistently now.Quoted 7 lines
Quoted 4 lines
Moreover it is difficult to change the notifier of
usb_phyto 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.You missed
drivers/usb/musb/omap2430.cin you list, but that hardly matters.But it did not use the notifier of
usb_phy.Quoted 1 line
phy-ab8500-usb.cappears to sendvbus_drawinformation.Users will not use the
vbus_drawinformation send fromphy-ab8500-usb.cQuoted 9 lines
I understand your reluctance to change drivers that you cannot test. An alternative it do change all the
atomic_notifier_call_chain(.*notifier,
calls that don't pass a pointer tovbus_drawto pass NULL, and to declare the passing of NULL to be deprecated (so hopefully people won't use it in new code).
Then any notification callback that expects a current can just ignore calls where the pointer is NULL.I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.
Quoted 10 lines
The one difficulty with this is
drivers/usb/gadget/udc/pxa27x_udc.cIt is the only driver which expects a 'gadget', and it doesn't really need to as it already knows the gadget.
The patch below fixes this.
With that in place, phy-generic and phy-gpio-vbus-usb can be changed to pass NULL. When we can safely use the notifier to passvbus_drawinformation uniformly.Quoted 1 line
Quoted 10 lines
Quoted 3 lines
(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.convenience is very much a secondary issue.
Quoted 4 lines
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.
Quoted 14 lines
As I have said, all of these sources of information should feed into the extcon.
There are ultimately two possible sources of information about the current available from the usb port.
One is the physical properties of the cable, such as resistance of ID, any short between D+ and D- etc. Being properties of the cable, they should be reported through the extcon.The other is information gathered during the USB protocol handshake. For USB2, this is the requested current of the profile that the host activates. This should be reported though the USB gadget device.
Quoted 8 lines
I don't know how USB3 and/or type-C work but I would be surprised if they don't fit into the two cases above. If you think otherwise, please surprise me. I'm always keen to learn.
If the extcon reports the type of cable detected, and the gadget reports the result of any negotiation, then that is enough to determine the charger type. It doesn't need to be more convenient than
that.
Quoted 7 lines
Quoted 7 lines
If we are all agree we did not need the USB charger, then we can add 'current' attribute of USB gadget device.
Thanks for your suggestion.--
Baolin.wang
Best Regards--
Baolin.wang
Best Regards
Quoted 117 lines · Jun Li
Quoted 117 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Thursday, March 09, 2017 2:11 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationHi,
Quoted 57 lines · Jun Li
Hi,
Quoted 55 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Tuesday, March 07, 2017 5:39 PM
To: NeilBrown <[email protected]>
Cc: Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Jun Li <[email protected]>; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 8 lines · NeilBrown
Quoted 6 lines · Baolin Wang
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.
Quoted 3 lines
Quoted 3 lines
Now introduce one user with
wm831x_powerto support and test the usbcharger.
Quoted 19 lines
Quoted 19 lines
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 byfollowing links:
Quoted 34 lines
Quoted 33 lines
Quoted 10 lines
Quoted 10 lines
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.candphy-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.)Quoted 4 lines
Quoted 4 lines
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 appropriatenotifications.
Quoted 13 lines
Quoted 5 lines
Firstly, now only 3 USB phy drivers (
phy-qcom-8x16-usb.c,phy-omap-otg.candphy-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.You don't have to change every driver. You just need to make it easy and obvious how to change drivers in a consistent coherent way. For a start you would add a 'struct
extcon_dev' to 'structusb_phy', and possibly add or extend some 'static inline's inlinux/usb/phy.hto send notification on that extcon (if it is non-NULL). e.g.usb_phy_vbus_on()could send an extcon notification.Quoted 2 lines
Then any phy driver which adds support for setting
phy->extcon_devappropriately, immediately gets the relevant notifications sent.OK. We can make these extcon related code into phy common part.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Will generic phy need add extcon as well?
Yes, will add a 'struct extcon_dev*' in 'struct
usb_phy', which will be common code.I mean the common code need add 'struct
extcon_dev' into both 'struct phy' and 'structusb_phy', right? as some/new usb phy use that generic phy driver.
Ah, you remind me. Seems we need also add one 'struct extcon_dev' into 'struct phy'.
Quoted 43 lines
Quoted 37 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 7 lines
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.
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification. Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together.
Somehow these three need to work together to determine what isQuoted 6 lines
Quoted 6 lines
plugged
Quoted 5 lines
in to the external connection port. Somewhere there much an 'extcon' device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connection point. Each of the devices can get to the phy, and the phy can get to theextcon.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that represents it.
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by
software?
Quoted 5 lines
Quoted 1 line
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework, right?
Quoted 5 lines
Not in USB charger framework. If we are all agree every
usb_phycan register one extcon device, can get correct charger type and send out correctvbus_drawinformation, then we don't need USB charger framework as Neil suggested. So this will be okay for your case (especially for detecting the charger type by software) ?
Quoted 5 lines
In my case, charger detection is done by controller driver and I need do charger type detection internally, and only pass the current draw info via phy which will send out, this seems ok for me, but I think it will be good if you or someone can show us an example user based on the design Neil suggested.
Will you work out that common code if this USB charger framework is not needed?
I will add a 'struct extcon_dev*' in 'struct usb_phy' and struct phy“. Others are already ready if everyone has no complain about current design, except my one concern. (I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.)
Quoted 98 lines
Quoted 98 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
(2) Change the notifier of
usb_phyto be used consistently. Now only 3 phy drivers (phy-generic.c,phy-ab8500-usb.candphy-gpio-vbus-usb.c) used the notifier ofusb_phy.phy-generic.candphy-gpio-vbus-usb.cwere used to send out the connect events, andphy-ab8500-usb.calso was used to send out the MUSB connectevents.
Quoted 77 lines
Quoted 77 lines
Quoted 2 lines
Quoted 2 lines
There are no phy drivers will notify '
vbus_draw' information by thenotifier of
usb_phy, which was used consistently now.Quoted 7 lines
Quoted 4 lines
Moreover it is difficult to change the notifier of
usb_phyto 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.You missed
drivers/usb/musb/omap2430.cin you list, but that hardly matters.But it did not use the notifier of
usb_phy.Quoted 1 line
phy-ab8500-usb.cappears to sendvbus_drawinformation.Users will not use the
vbus_drawinformation send fromphy-ab8500-usb.cQuoted 9 lines
I understand your reluctance to change drivers that you cannot test. An alternative it do change all the
atomic_notifier_call_chain(.*notifier,
calls that don't pass a pointer tovbus_drawto pass NULL, and to declare the passing of NULL to be deprecated (so hopefully people won't use it in new code).
Then any notification callback that expects a current can just ignore calls where the pointer is NULL.I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.
Quoted 10 lines
The one difficulty with this is
drivers/usb/gadget/udc/pxa27x_udc.cIt is the only driver which expects a 'gadget', and it doesn't really need to as it already knows the gadget.
The patch below fixes this.
With that in place, phy-generic and phy-gpio-vbus-usb can be changed to pass NULL. When we can safely use the notifier to passvbus_drawinformation uniformly.Quoted 1 line
Quoted 10 lines
Quoted 3 lines
(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.convenience is very much a secondary issue.
Quoted 4 lines
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.
Quoted 14 lines
As I have said, all of these sources of information should feed into the extcon.
There are ultimately two possible sources of information about the current available from the usb port.
One is the physical properties of the cable, such as resistance of ID, any short between D+ and D- etc. Being properties of the cable, they should be reported through the extcon.The other is information gathered during the USB protocol handshake. For USB2, this is the requested current of the profile that the host activates. This should be reported though the USB gadget device.
Quoted 8 lines
I don't know how USB3 and/or type-C work but I would be surprised if they don't fit into the two cases above. If you think otherwise, please surprise me. I'm always keen to learn.
If the extcon reports the type of cable detected, and the gadget reports the result of any negotiation, then that is enough to determine the charger type. It doesn't need to be more convenient than
that.
Quoted 7 lines
Quoted 7 lines
If we are all agree we did not need the USB charger, then we can add 'current' attribute of USB gadget device.
Thanks for your suggestion.--
Baolin.wang
Best Regards--
Baolin.wang
Best Regards
Signature · 2 lines
Baolin.wang Best Regards
Quoted 210 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Thursday, March 09, 2017 7:23 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 29 lines · Jun Li
Quoted 29 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Thursday, March 09, 2017 2:11 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationHi,
Quoted 2 lines · Jun Li
Hi,
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Tuesday, March 07, 2017 5:39 PM
To: NeilBrown <[email protected]>
Cc: Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; DavidWoodhouse
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
<[email protected]>; [email protected]; Jun Li <[email protected]>; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines · NeilBrown
Quoted 7 lines · Baolin Wang
Quoted 6 lines
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.
Quoted 54 lines
Quoted 54 lines
Quoted 21 lines
Quoted 21 lines
Quoted 1 line
Quoted 1 line
Thus provide a
standard framework for doing this in kernel.
Quoted 3 lines
Quoted 3 lines
Now introduce one user with
wm831x_powerto support and test the usbcharger.
Quoted 15 lines
Quoted 15 lines
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/13Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
(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 byfollowing links:
Quoted 28 lines
Quoted 28 lines
Quoted 10 lines
Quoted 10 lines
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.candphy-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.)Quoted 4 lines
Quoted 4 lines
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 appropriatenotifications.
Quoted 13 lines
Quoted 5 lines
Firstly, now only 3 USB phy drivers (
phy-qcom-8x16-usb.c,phy-omap-otg.candphy-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.You don't have to change every driver. You just need to make it easy and obvious how to change drivers in a consistent coherent way. For a start you would add a 'struct
extcon_dev' to 'structusb_phy', and possibly add or extend some 'static inline's inlinux/usb/phy.hto send notification on that extcon (if it is non-NULL). e.g.usb_phy_vbus_on()could send an extcon notification.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Then any phy driver which adds support for setting
phy->extcon_devappropriately, immediately gets the relevantnotifications sent.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
OK. We can make these extcon related code into phy common part.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Will generic phy need add extcon as well?
Yes, will add a 'struct extcon_dev*' in 'struct
usb_phy', which will be common code.I mean the common code need add 'struct
extcon_dev' into both 'struct phy' and 'structusb_phy', right? as some/new usb phy use that generic phydriver.
Ah, you remind me. Seems we need also add one 'struct
extcon_dev' into 'struct phy'.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
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.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification. Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together. Somehow these three need to work together to determine what is
plugged
Quoted 1 line
in to the external connection port. Somewhere there much an
'extcon'
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connection point. Each of the devices can get to the phy, and the phy can get to theQuoted 7 lines
Quoted 7 lines
extcon.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that
represents it.
Quoted 17 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by
software?
Quoted 5 lines
Quoted 1 line
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework, right?
Quoted 5 lines
Not in USB charger framework. If we are all agree every
usb_phycan register one extcon device, can get correct charger type and send out correctvbus_drawinformation, then we don't need USB charger framework as Neil suggested. So this will be okay for your case (especially for detecting the charger type by software) ?Quoted 4 lines
In my case, charger detection is done by controller driver and I need do charger type detection internally, and only pass the current draw info via phy which will send out, this seems ok for me, but I think it will be good if you or someone can show us an example user based on the
Quoted 6 lines
design Neil suggested.
Quoted 1 line
Will you work out that common code if this USB charger framework is not
needed?
I will add a 'struct extcon_dev*' in 'struct
usb_phy' and struct phy“. Others are already ready if everyone has no complain about current design, except
Only adding extcon_dev into usb_phy/phy and all others are ready?
My understanding you will also do:
- We need find a central place to send the notification(phy common part).
- If the extcon_dev is directly added in usb_phy/phy, PMIC needs some API to findup it.
Quoted 4 lines
my one concern. (I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.)
Can we handle this in USB(so has super speed information) and just send out 900mA directly?
Li Jun
Quoted 67 lines · Jun Li
Quoted 67 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Will generic phy need add extcon as well?
Yes, will add a 'struct extcon_dev*' in 'struct
usb_phy', which will be common code.I mean the common code need add 'struct
extcon_dev' into both 'struct phy' and 'structusb_phy', right? as some/new usb phy use that generic phydriver.
Ah, you remind me. Seems we need also add one 'struct
extcon_dev' into 'struct phy'.Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
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.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification. Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together. Somehow these three need to work together to determine what is
plugged
Quoted 1 line
in to the external connection port. Somewhere there much an
'extcon'
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connection point. Each of the devices can get to the phy, and the phy can get to theQuoted 7 lines
Quoted 7 lines
extcon.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that
represents it.
Quoted 17 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by
software?
Quoted 5 lines
Quoted 1 line
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework, right?
Quoted 5 lines
Not in USB charger framework. If we are all agree every
usb_phycan register one extcon device, can get correct charger type and send out correctvbus_drawinformation, then we don't need USB charger framework as Neil suggested. So this will be okay for your case (especially for detecting the charger type by software) ?Quoted 4 lines
In my case, charger detection is done by controller driver and I need do charger type detection internally, and only pass the current draw info via phy which will send out, this seems ok for me, but I think it will be good if you or someone can show us an example user based on the
design Neil suggested.
Quoted 1 line
Will you work out that common code if this USB charger framework is not
Quoted 8 lines
Quoted 4 lines
needed?
I will add a 'struct extcon_dev*' in 'struct
usb_phy' and struct phy“. Others are already ready if everyone has no complain about current design, exceptOnly adding
extcon_devinto usb_phy/phy and all others are ready? My understanding you will also do:
- We need find a central place to send the notification(phy common part).
That will include these implementation when adding extcon_dev.
Quoted 1 line
- If the
extcon_devis directly added in usb_phy/phy, PMIC needs some API to findup it.
PMIC can find extcon device by phandle.
Quoted 10 lines
Quoted 5 lines
my one concern. (I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.)
Can we handle this in USB(so has super speed information) and just send out 900mA directly?
From Neil's suggestion, we only have one place to send out current
information from usb phy, so I have this concern and doubt if we still need the USB charger framework.
Signature · 2 lines
Baolin.wang Best Regards
Hi
Quoted 100 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Friday, March 10, 2017 3:15 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 17 lines · Jun Li
Quoted 17 lines
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
Will generic phy need add extcon as well?
Yes, will add a 'struct extcon_dev*' in 'struct
usb_phy', which will be common code.I mean the common code need add 'struct
extcon_dev' into both 'struct phy' and 'structusb_phy', right? as some/new usb phy use that generic phydriver.
Ah, you remind me. Seems we need also add one 'struct
extcon_dev' into 'struct phy'.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
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.
Quoted 28 lines
Quoted 28 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification. Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together. Somehow these three need to work together to determine what is
plugged
Quoted 1 line
in to the external connection port. Somewhere there much an
'extcon'
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connection point. Each of the devices can get to the phy, and the phy can get to theQuoted 7 lines
Quoted 7 lines
extcon.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that
represents it.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
software?
Quoted 5 lines
Quoted 1 line
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework,
right?
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Not in USB charger framework. If we are all agree every
usb_phycan register one extcon device, can get correct charger type and send out correctvbus_drawinformation, then we don't need USB charger framework as Neil suggested. So this will be okay for your case (especially for detecting the charger type by software) ?Quoted 5 lines
In my case, charger detection is done by controller driver and I need do charger type detection internally, and only pass the current draw info via phy which will send out, this seems ok for me, but I think it will be good if you or someone can show us an example user based on the
design Neil suggested.
Quoted 2 lines
Will you work out that common code if this USB charger framework is not
needed?
I will add a 'struct extcon_dev*' in 'struct
usb_phy' and struct phy“. Others are already ready if everyone has no complain about current design, except
Quoted 6 lines
Quoted 3 lines
Only adding
extcon_devinto usb_phy/phy and all others are ready? My understanding you will also do:
- We need find a central place to send the notification(phy common part).That will include these implementation when adding
extcon_dev.
OK, thanks.
Quoted 4 lines
Quoted 1 line
- If the
extcon_devis directly added in usb_phy/phy, PMIC needs someAPI to findup it.
PMIC can find extcon device by phandle.
extcon_dev(not a reference pointer) is directly added in usb_phy/phy, not via devicetree, how PMIC find it by phandle?
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
my one concern. (I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.)
Quoted 6 lines
Quoted 2 lines
Can we handle this in USB(so has super speed information) and just send out 900mA directly?
From Neil's suggestion, we only have one place to send out current information from usb phy, so I have this concern and doubt if we still need the USB charger framework.
So if put it in phy/usb_phy, this is a problem, that only one place should have the infor of both speed and usb state, how about put it at usb_gadget, then, e.g. send the notification in usb_gadget_vbus_connect()?
Li Jun
Quoted 4 lines
--
Baolin.wang
Best Regards
Quoted 112 lines · Jun Li
Hi
Quoted 100 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Friday, March 10, 2017 3:15 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 17 lines · Jun Li
Quoted 17 lines
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
Will generic phy need add extcon as well?
Yes, will add a 'struct extcon_dev*' in 'struct
usb_phy', which will be common code.I mean the common code need add 'struct
extcon_dev' into both 'struct phy' and 'structusb_phy', right? as some/new usb phy use that generic phydriver.
Ah, you remind me. Seems we need also add one 'struct
extcon_dev' into 'struct phy'.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
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.
Quoted 28 lines
Quoted 28 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification. Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together. Somehow these three need to work together to determine what is
plugged
Quoted 1 line
in to the external connection port. Somewhere there much an
'extcon'
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connection point. Each of the devices can get to the phy, and the phy can get to theQuoted 7 lines
Quoted 7 lines
extcon.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on devicetree info).
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that
represents it.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
software?
Quoted 5 lines
Quoted 1 line
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework,
right?
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Not in USB charger framework. If we are all agree every
usb_phycan register one extcon device, can get correct charger type and send out correctvbus_drawinformation, then we don't need USB charger framework as Neil suggested. So this will be okay for your case (especially for detecting the charger type by software) ?Quoted 5 lines
In my case, charger detection is done by controller driver and I need do charger type detection internally, and only pass the current draw info via phy which will send out, this seems ok for me, but I think it will be good if you or someone can show us an example user based on the
design Neil suggested.
Quoted 2 lines
Will you work out that common code if this USB charger framework is not
needed?
I will add a 'struct extcon_dev*' in 'struct
usb_phy' and struct phy“. Others are already ready if everyone has no complain about current design, exceptQuoted 6 lines
Quoted 3 lines
Only adding
extcon_devinto usb_phy/phy and all others are ready? My understanding you will also do:
- We need find a central place to send the notification(phy common part).That will include these implementation when adding
extcon_dev.OK, thanks.
Quoted 1 line
Quoted 1 line
- If the
extcon_devis directly added in usb_phy/phy, PMIC needs some
Quoted 8 lines
Quoted 3 lines
API to findup it.
PMIC can find extcon device by phandle.
extcon_dev(not a reference pointer)is directly added in usb_phy/phy, not via devicetree, how PMIC find it by phandle?From my understanding, here we should add one pointer (
extcon_dev*),
since usb phy is not one external connect device.
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
my one concern. (I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.)
Can we handle this in USB(so has super speed information) and just send out 900mA directly?
Quoted 7 lines
Quoted 3 lines
From Neil's suggestion, we only have one place to send out current information from usb phy, so I have this concern and doubt if we still need the USB charger framework.
So if put it in phy/usb_phy, this is a problem, that only one place should have the infor of both speed and usb state, how about put it at
usb_gadget, then, e.g. send the notification inusb_gadget_vbus_connect()?
That is same what USB charger did, from this point, we need USB charger to send out vbus draw information according to speed and usb state. But I should listen to other guys suggestion. Peter and Felipe, what do you think?
Signature · 2 lines
Baolin.wang Best Regards
Hi,
Quoted 145 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Friday, March 10, 2017 6:52 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 64 lines · Jun Li
Hi
Quoted 62 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Friday, March 10, 2017 3:15 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 17 lines · Jun Li
Quoted 17 lines
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
Will generic phy need add extcon as well?
Yes, will add a 'struct extcon_dev*' in 'struct
usb_phy', which will be common code.I mean the common code need add 'struct
extcon_dev' into both 'struct phy' and 'structusb_phy', right? as some/new usb phy use that generic phydriver.
Ah, you remind me. Seems we need also add one 'struct
extcon_dev' into 'struct phy'.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
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.
Quoted 15 lines
Quoted 15 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification. Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together. Somehow these three need to work together to determine what is
plugged
Quoted 2 lines
in to the external connection port. Somewhere there much an
'extcon'
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connectionpoint.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Each of the devices can get to the phy, and the phy can get to the
extcon.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on
devicetree info).
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that
represents it.
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by
software?
Quoted 6 lines
Quoted 1 line
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework,
Quoted 7 lines
Quoted 7 lines
right?
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Not in USB charger framework. If we are all agree every
usb_phycan register one extcon device, can get correct charger type and send out correctvbus_drawinformation, then we don't need USB charger framework as Neil suggested. So this will be okay for your case (especially for detecting the charger type bysoftware) ?
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
In my case, charger detection is done by controller driver and I need do charger type detection internally, and only pass the current draw info via phy which will send out, this seems ok for me, but I think it will be good if you or someone can show us an example user based on the
design Neil suggested.
Quoted 2 lines
Will you work out that common code if this USB charger framework is not
needed?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I will add a 'struct extcon_dev*' in 'struct
usb_phy' and struct phy“. Others are already ready if everyone has no complain about current design, exceptOnly adding
extcon_devinto usb_phy/phy and all others are ready? My understanding you will also do:
- We need find a central place to send the notification(phy commonpart).
Quoted 10 lines
Quoted 3 lines
That will include these implementation when adding
extcon_dev.OK, thanks.
Quoted 4 lines
Quoted 2 lines
- If the
extcon_devis directly added in usb_phy/phy, PMIC needs someAPI to findup it.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
PMIC can find extcon device by phandle.
extcon_dev(not a reference pointer)is directly added in usb_phy/phy, not via devicetree, how PMIC find it by phandle?From my understanding, here we should add one pointer (
extcon_dev*), since usb phy is not one external connect device.
Agreed.
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
Quoted 8 lines
Quoted 5 lines
my one concern. (I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.)
Can we handle this in USB(so has super speed information) and just send out 900mA directly?
From Neil's suggestion, we only have one place to send out current information from usb phy, so I have this concern and doubt if we still need the USB charger framework.
Quoted 8 lines
Quoted 3 lines
So if put it in phy/usb_phy, this is a problem, that only one place should have the infor of both speed and usb state, how about put it at
usb_gadget, then, e.g. send the notification in
usb_gadget_vbus_connect()?That is same what USB charger did, from this point, we need USB charger to send out vbus draw information according to speed and usb state. But I should listen to other guys suggestion. Peter and Felipe, what do you think?
So now the only to do work is to find a common place to send the notification out (based on gadget speed and sate).
Li Jun
Quoted 4 lines
--
Baolin.wang
Best Regards
Quoted 177 lines · Jun Li
Hi,
Quoted 145 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Friday, March 10, 2017 6:52 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 64 lines · Jun Li
Hi
Quoted 62 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Friday, March 10, 2017 3:15 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotationQuoted 17 lines · Jun Li
Quoted 17 lines
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
Will generic phy need add extcon as well?
Yes, will add a 'struct extcon_dev*' in 'struct
usb_phy', which will be common code.I mean the common code need add 'struct
extcon_dev' into both 'struct phy' and 'structusb_phy', right? as some/new usb phy use that generic phydriver.
Ah, you remind me. Seems we need also add one 'struct
extcon_dev' into 'struct phy'.Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
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.
Quoted 15 lines
Quoted 15 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 8 lines
Whichever part can detect vbus, the driver for that part must be able to find the extcon and trigger a notification. Maybe one part can detect VBUS, another can measure the resistance on ID and a third can work through the state machine to determine if D+ and D- are shorted together. Somehow these three need to work together to determine what is
plugged
Quoted 2 lines
in to the external connection port. Somewhere there much an
'extcon'
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
device which represents that port and which the three devices can find and can interact with.
I think it makes sense for theusb_phyto be the connectionpoint.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Each of the devices can get to the phy, and the phy can get to the
extcon.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
It doesn't matter very much if the usb phy driver creates the extcon, or if something else creates the extcon and the phy driver performs a lookup to find it (e.g. based on
devicetree info).
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
The point is that there is obviously an external physical connection, and so there should be an 'extcon' device that
represents it.
Quoted 11 lines
Quoted 11 lines
Quoted 4 lines
Quoted 4 lines
Peter & Jun, is it OK for you every phy has one extcon device to receive VBUS notification, especially for detecting the charger type by
software?
Quoted 6 lines
Quoted 1 line
My understanding is phy/usb_phy as the connection point, will send the notification to PMIC driver which actually control the charge current, also this will be done in your common framework,
Quoted 7 lines
Quoted 7 lines
right?
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Not in USB charger framework. If we are all agree every
usb_phycan register one extcon device, can get correct charger type and send out correctvbus_drawinformation, then we don't need USB charger framework as Neil suggested. So this will be okay for your case (especially for detecting the charger type bysoftware) ?
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
In my case, charger detection is done by controller driver and I need do charger type detection internally, and only pass the current draw info via phy which will send out, this seems ok for me, but I think it will be good if you or someone can show us an example user based on the
design Neil suggested.
Quoted 2 lines
Will you work out that common code if this USB charger framework is not
needed?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I will add a 'struct extcon_dev*' in 'struct
usb_phy' and struct phy“. Others are already ready if everyone has no complain about current design, exceptOnly adding
extcon_devinto usb_phy/phy and all others are ready? My understanding you will also do:
- We need find a central place to send the notification(phy commonpart).
Quoted 10 lines
Quoted 3 lines
That will include these implementation when adding
extcon_dev.OK, thanks.
Quoted 4 lines
Quoted 2 lines
- If the
extcon_devis directly added in usb_phy/phy, PMIC needs someAPI to findup it.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
PMIC can find extcon device by phandle.
extcon_dev(not a reference pointer)is directly added in usb_phy/phy, not via devicetree, how PMIC find it by phandle?From my understanding, here we should add one pointer (
extcon_dev*), since usb phy is not one external connect device.Agreed.
Quoted 20 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
my one concern. (I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.)
Quoted 6 lines
Quoted 2 lines
Can we handle this in USB(so has super speed information) and just send out 900mA directly?
From Neil's suggestion, we only have one place to send out current information from usb phy, so I have this concern and doubt if we still need the USB charger framework.
So if put it in phy/usb_phy, this is a problem, that only one place should have the infor of both speed and usb state, how about put it at
usb_gadget, then, e.g. send the notification in
Quoted 8 lines
Quoted 5 lines
usb_gadget_vbus_connect()?That is same what USB charger did, from this point, we need USB charger to send out vbus draw information according to speed and usb state. But I should listen to other guys suggestion. Peter and Felipe, what do you think?
So now the only to do work is to find a common place to send the notification out (based on gadget speed and sate).
Yes.
Signature · 2 lines
Baolin.wang Best Regards
Hi,
Quoted 20 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Monday, March 13, 2017 4:44 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <[email protected]>; [email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- [email protected]; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with the usb gadget power negotation
... ...
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
That is same what USB charger did, from this point, we need USB charger to send out vbus draw information according to speed and usb state. But I should listen to other guys suggestion. Peter and Felipe, what
do you think?
Instead of waiting for maintainer's comments on this long discussion, I'd suggest you directly post the patches for the required change, so they can easily know what's the conclusion/solution looks like.
Li Jun
Quoted 9 lines
Quoted 3 lines
So now the only to do work is to find a common place to send the notification out (based on gadget speed and sate).
Yes.
--
Baolin.wang
Best Regards
Quoted 23 lines · Jun Li
Hi,
Quoted 20 lines
-----Original Message-----
From: Baolin Wang [mailto:[email protected]]
Sent: Monday, March 13, 2017 4:44 PM
To: Jun Li <[email protected]>
Cc: NeilBrown <neilb-IBi9RG/[email protected]>; Felipe Balbi <[email protected]>; Greg KH <[email protected]>; Sebastian Reichel <[email protected]>; Dmitry Eremin-Solenikov <[email protected]>; David Woodhouse <[email protected]>; [email protected]; Marek Szyprowski <[email protected]>; Ruslan Bilovol <[email protected]>; Peter Chen <[email protected]>; Alan Stern <stern-nwvwT67g6+6dFdvTe/[email protected]>; [email protected]; Yoshihiro Shimoda <[email protected]>; Lee Jones <[email protected]>; Mark Brown <[email protected]>; John Stultz <[email protected]>; Charles Keepax <ckeepax-yzvPICuk2AATkU/[email protected]>; patches-yzvPICuk2AATkU/[email protected]; Linux PM list <linux- [email protected]>; USB <[email protected]>; device- mainlining-cunTk1MwBs98uUxBSJOaYoYkZiVZrdSR2LY78lusg7I@public.gmane.org; LKML <[email protected]>
Subject: Re: [PATCH v19 0/4] Introduce usb charger framework to deal with
the usb gadget power negotation... ...
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
That is same what USB charger did, from this point, we need USB charger to send out vbus draw information according to speed and usb state. But I should listen to other guys suggestion. Peter and Felipe, what
do you think?
Instead of waiting for maintainer's comments on this long discussion, I'd suggest you directly post the patches for the required change, so they can easily know what's the conclusion/solution looks like.
That's right, I am creating patches for adding extcon_dev in phy/usb_phy. Thanks.
Signature · 6 lines
Baolin.wang Best Regards -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 12 lines · Baolin Wang
Quoted 9 lines · NeilBrown
I understand your reluctance to change drivers that you cannot test. An alternative it do change all the
atomic_notifier_call_chain(.*notifier,
calls that don't pass a pointer tovbus_drawto pass NULL, and to declare the passing of NULL to be deprecated (so hopefully people won't use it in new code).
Then any notification callback that expects a current can just ignore calls where the pointer is NULL.
Quoted 3 lines
I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.
When the gadget driver determines that 900mA is available, it calls usb_phy_set_power() which calls the ->set_power() method on the usb_phy. The usb_phy the uses the notifier to inform all interested parties that 900mA is available.
NeilBrown
Hi,
Quoted 14 lines · NeilBrown
Quoted 12 lines · Baolin Wang
Quoted 9 lines · NeilBrown
I understand your reluctance to change drivers that you cannot test. An alternative it do change all the
atomic_notifier_call_chain(.*notifier,
calls that don't pass a pointer tovbus_drawto pass NULL, and to declare the passing of NULL to be deprecated (so hopefully people won't use it in new code).
Then any notification callback that expects a current can just ignore calls where the pointer is NULL.
Quoted 8 lines
Quoted 3 lines
I am afraid if it is enough to send out vbus draw information from USB phy driver, for example you will miss super speed (900mA), which need get the speed information from gadget driver.
When the gadget driver determines that 900mA is available, it calls
usb_phy_set_power()which calls the ->set_power() method on theusb_phy. Theusb_phythe uses the notifier to inform all interested parties that 900mA is available.
That is one possible way. Now we only set vbus draw by usb_gadget_vbus_draw() after setting config and suspend/resume usb device. Maybe we can add one condition in usb_gadget_vbus_draw() like:
if (mA >= 500 && gadet->speed >= SUPER_SPEED)
mA = 900;
Signature · 2 lines
Baolin.wang Best Regards
On Mon, 20 Feb 2017, Baolin Wang wrote:
[...]
Quoted 4 lines
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 +++++++++++++++++++++++++++++++++++
Quoted 8 lines
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
Why have you sent this set to me?
Please be careful when submitting patches, since a lot of us have enough mail to contend with already.
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Baolin Wang
Acked-by Lee Jones Acked-by Charles Keepax Acked-by Peter Chen Acked-by Sebastian ReichelHi,
Quoted 17 lines · Lee Jones
On Mon, 20 Feb 2017, Baolin Wang wrote:
[...]
Quoted 4 lines
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 +++++++++++++++++++++++++++++++++++Quoted 8 lines
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
Quoted 1 line
Why have you sent this set to me?
Since you have one ack on patch 4, I think I need CC you. But If you are not interested in this patchset, I will not CC you next time. Sorry.
[PATCH v19 4/4] power: wm831x_power: Support USB charger current limit management
Integrate with the newly added USB charger interface to limit the current we draw from the USB input based on the input device configuration identified by the USB stack, allowing us to charge more quickly from high current inputs without drawing more current than specified from others.
.......
Signature · 2 lines
Baolin.wang Best Regards
Quoted 20 lines · Baolin Wang
Hi,
Quoted 17 lines · Lee Jones
On Mon, 20 Feb 2017, Baolin Wang wrote:
[...]
Quoted 12 lines
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
Quoted 5 lines
Quoted 1 line
Why have you sent this set to me?
Since you have one ack on patch 4, I think I need CC you. But If you are not interested in this patchset, I will not CC you next time. Sorry.
I Acked one of the patches 9 months ago since it contained an MFD change.
Yes, if you could drop me from any new submissions, that'd be great, thanks.
Quoted 16 lines
[PATCH v19 4/4] power:
wm831x_power: Support USB charger current limit managementIntegrate with the newly added USB charger interface to limit the current we draw from the USB input based on the input device configuration identified by the USB stack, allowing us to charge more quickly from high current inputs without drawing more current than specified from others.
Signed-off-by Mark Brown <[email protected]>Signed-off-by Baolin Wang <[email protected]>Acked-by Lee Jones <[email protected]>Acked-by Charles Keepax <[email protected]>Acked-by Peter Chen <[email protected]>.......
Signature · 4 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog