Introduce usb charger framework to deal with the usb gadget power negotation
Subsystems (3)
v12 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, which is pending testing. Moreover there may be other potential users will use it in future.
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):
gadget: Introduce the usb charger framework
gadget: Support for the usb charger framework
gadget: Integrate with the usb gadget supporting for usb charger
power: wm831x_power: Support USB charger current limit management
drivers/power/wm831x_power.c | 69 ++++ drivers/usb/gadget/Kconfig | 7 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/charger.c | 807 +++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/udc/udc-core.c | 11 + include/linux/mfd/wm831x/pdata.h | 3 + include/linux/usb/charger.h | 191 +++++++++ include/linux/usb/gadget.h | 11 + include/uapi/linux/usb/charger.h | 31 ++ 9 files changed, 1131 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
Signature · 1 line
1.7.9.5
PATCH v12 1/4 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 | 7 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/charger.c | 770 ++++++++++++++++++++++++++++++++++++++ include/linux/usb/charger.h | 191 ++++++++++ include/uapi/linux/usb/charger.h | 31 ++ 5 files changed, 1000 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 +7 -0
@@ -134,6 +134,13 @@ config U_SERIAL_CONSOLE help It supports the serial gadget can be used as a console. +config USB_CHARGER + bool "USB charger support" + 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 @@ # USB peripheral controller drivers # obj-$(CONFIG_USB_GADGET) += udc-core.o +obj-$(CONFIG_USB_CHARGER) += charger.o obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o obj-$(CONFIG_USB_NET2272) += net2272.o obj-$(CONFIG_USB_NET2280) += net2280.o
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 +191 -0
191 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_REMOVE , +}; + +#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
Re: [PATCH v12 1/4] gadget: Introduce the usb charger framework
Hi,
Quoted 41 lines · Baolin Wang
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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>--- drivers/usb/gadget/Kconfig | 7 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/charger.c | 770 ++++++++++++++++++++++++++++++++++++++ include/linux/usb/charger.h | 191 ++++++++++ include/uapi/linux/usb/charger.h | 31 ++ 5 files changed, 1000 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.hdrivers/usb/gadget/Kconfig +0
-0
drivers/usb/gadget/Kconfig config U_SERIAL_CONSOLE · line 138
Quoted 5 lines
drivers/usb/gadget/Kconfig +2
-0@@ -134,6 +134,13 @@ config U_SERIAL_CONSOLE help It supports the serial gadget can be used as a console. +config USB_CHARGER + bool "USB charger support"
you didn't build test all possibilities, did you?
I have a feeling this won't link if USB_GADGET=m. Can you test that?
Quoted 1 line
drivers/usb/gadget/udc/charger.c +0
-0
[...]
Quoted 1 line
+struct class
*usb_charger_class;
We already have a UDC class, do we really, really need another class here?
Quoted 1 line
+subsys_initcall(usb_charger_class_init);
this should always work as module_init(). Please make sure that's the case.
Signature · 1 line
balbi
Re: [PATCH v12 1/4] gadget: Introduce the usb charger framework
Quoted 48 lines · Felipe Balbi
Hi,
Quoted 44 lines · Baolin Wang
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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>--- drivers/usb/gadget/Kconfig | 7 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/charger.c | 770 ++++++++++++++++++++++++++++++++++++++ include/linux/usb/charger.h | 191 ++++++++++ include/uapi/linux/usb/charger.h | 31 ++ 5 files changed, 1000 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.hdrivers/usb/gadget/Kconfig +0
-0@@ -134,6 +134,13 @@ config U_SERIAL_CONSOLE help It supports the serial gadget can be used as a console.
Quoted 6 lines
drivers/usb/gadget/Kconfig config U_SERIAL_CONSOLE · line 138
Quoted 2 lines
drivers/usb/gadget/Kconfig +2
-0+config USB_CHARGER + bool "USB charger support"you didn't build test all possibilities, did you?
I have a feeling this won't link if USB_GADGET=m. Can you test that?
OK.
Quoted 7 lines
Quoted 2 lines
drivers/usb/gadget/udc/charger.c +0
-0[...]
Quoted 1 line
+struct class
*usb_charger_class;We already have a UDC class, do we really, really need another class here?
We want to manage the usb charger devices by this class and one usb charger device is not equal with one usb device which managed by UDC class, so can we use UDC class to manage charger devices? By the way, you also suggested to use the 'class' things instead of 'bus' in previous mail.
Quoted 5 lines
Quoted 2 lines
+subsys_initcall(usb_charger_class_init);
this should always work as
module_init(). Please make sure that's the case.
we should make sure the charger class has been allocated before user try to add a new gadget to the udc class. So it should be issued before 'module_init()' (many usb drivers are at module_init level). Another hand this follows the UDC class allocation.
Quoted 3 lines
--
balbi
Signature · 2 lines
Baolin.wang Best Regards
Re: [PATCH v12 1/4] gadget: Introduce the usb charger framework
Hi,
Quoted 56 lines · Baolin Wang
Quoted 44 lines
Quoted 44 lines
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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>--- drivers/usb/gadget/Kconfig | 7 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/charger.c | 770 ++++++++++++++++++++++++++++++++++++++ include/linux/usb/charger.h | 191 ++++++++++ include/uapi/linux/usb/charger.h | 31 ++ 5 files changed, 1000 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.hdrivers/usb/gadget/Kconfig +0
-0@@ -134,6 +134,13 @@ config U_SERIAL_CONSOLE help It supports the serial gadget can be used as a console.Quoted 6 lines
drivers/usb/gadget/Kconfig config U_SERIAL_CONSOLE · line 138
Quoted 2 lines
drivers/usb/gadget/Kconfig +2
-0+config USB_CHARGER + bool "USB charger support"you didn't build test all possibilities, did you?
I have a feeling this won't link if USB_GADGET=m. Can you test that?
OK.
Quoted 3 lines
Quoted 2 lines
drivers/usb/gadget/udc/charger.c +0
-0[...]
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
+struct class
*usb_charger_class;We already have a UDC class, do we really, really need another class here?
We want to manage the usb charger devices by this class and one usb charger device is not equal with one usb device which managed by UDC
Can you explain this statement? If charging is done via a USB peripheral port, why don't we have a 1:1 mapping between charger and UDC?
Quoted 3 lines
class, so can we use UDC class to manage charger devices? By the way, you also suggested to use the 'class' things instead of 'bus' in previous mail.
true, I did say that. It seems clearer, however, that we don't need this virtual device here.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
+subsys_initcall(usb_charger_class_init);
this should always work as
module_init(). Please make sure that's the case.we should make sure the charger class has been allocated before user try to add a new gadget to the udc class. So it should be issued before '
module_init()' (many usb drivers are atmodule_initlevel).
-EPROBE_DEFER?
Signature · 1 line
balbi
Re: [PATCH v12 1/4] gadget: Introduce the usb charger framework
Quoted 62 lines · Felipe Balbi
Hi,
Quoted 58 lines · Baolin Wang
Quoted 44 lines
Quoted 44 lines
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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>--- drivers/usb/gadget/Kconfig | 7 + drivers/usb/gadget/udc/Makefile | 1 + drivers/usb/gadget/udc/charger.c | 770 ++++++++++++++++++++++++++++++++++++++ include/linux/usb/charger.h | 191 ++++++++++ include/uapi/linux/usb/charger.h | 31 ++ 5 files changed, 1000 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.hdrivers/usb/gadget/Kconfig +0
-0@@ -134,6 +134,13 @@ config U_SERIAL_CONSOLE help It supports the serial gadget can be used as a console.Quoted 6 lines
drivers/usb/gadget/Kconfig config U_SERIAL_CONSOLE · line 138
Quoted 2 lines
drivers/usb/gadget/Kconfig +2
-0+config USB_CHARGER + bool "USB charger support"you didn't build test all possibilities, did you?
I have a feeling this won't link if USB_GADGET=m. Can you test that?
OK.
Quoted 5 lines
Quoted 2 lines
drivers/usb/gadget/udc/charger.c +0
-0[...]
Quoted 1 line
+struct class
*usb_charger_class;
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
We already have a UDC class, do we really, really need another class here?
We want to manage the usb charger devices by this class and one usb charger device is not equal with one usb device which managed by UDC
Can you explain this statement? If charging is done via a USB peripheral port, why don't we have a 1:1 mapping between charger and UDC?
Sorry for confusing, but forget it, I plan to remove the device/class things as you suggested.
Quoted 7 lines
Quoted 4 lines
class, so can we use UDC class to manage charger devices? By the way, you also suggested to use the 'class' things instead of 'bus' in previous mail.
true, I did say that. It seems clearer, however, that we don't need this virtual device here.
OK.
Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
+subsys_initcall(usb_charger_class_init);
this should always work as
module_init(). Please make sure that's the case.we should make sure the charger class has been allocated before user try to add a new gadget to the udc class. So it should be issued before '
module_init()' (many usb drivers are atmodule_initlevel).-EPROBE_DEFER?
OK. But 'EPROBE_DEFER' is not needed if we remove the class things.
Signature · 2 lines
Baolin.wang Best Regards
PATCH v12 2/4 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/udc-core.c | 11 +++++++++++ include/linux/usb/gadget.h | 11 +++++++++++ 2 files changed, 22 insertions(+)
drivers/usb/gadget/udc/udc-core.c +11 -0
@@ -28,6 +28,7 @@#include <linux/usb/ch9.h> #include <linux/usb/gadget.h> #include <linux/usb.h> +#include <linux/usb/charger.h> /** * struct usb_udc - describes one usb device controller
@@ -242,6 +243,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" ); }
@@ -411,6 +415,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;
@@ -431,6 +439,8 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,return 0 ; +err5: +device_del (&udc->dev); err4:list_del (&udc->list);mutex_unlock (&udc_lock);
@@ -539,6 +549,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 +11 -0
@@ -24,6 +24,7 @@#include <linux/types.h> #include <linux/workqueue.h> #include <linux/usb/ch9.h> +#include <linux/usb/charger.h> struct usb_ep ;
@@ -639,6 +640,8 @@ struct usb_gadget {unsigned out_epnum;unsigned in_epnum;struct usb_otg_caps *otg_caps; +/* negotiate the power with the usb charger */ +struct usb_charger *charger; unsigned sg_supported:1; unsigned is_otg:1;
@@ -855,10 +858,18 @@ static inline 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. */ static inline int usb_gadget_vbus_draw (struct usb_gadget *gadget,unsigned mA) { +if (gadget->charger) +usb_charger_set_cur_limit_by_type (gadget->charger, + gadget->charger->type, + mA); +if (!gadget->ops->vbus_draw)return -EOPNOTSUPP ;return gadget->ops->vbus_draw (gadget, mA);
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
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 9 lines · Baolin Wang
For supporting the usb charger, it adds the
usb_charger_init()andusb_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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>
Before anything, I must say that I really liked this patch. It's minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
include/linux/usb/gadget.h static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget) · line 868
Quoted 3 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){include/linux/usb/gadget.h +1
-0+if (gadget->charger)
I guess you could do this check insideusb_gadget_set_cur_limit_by_type() itself.
Signature · 1 line
balbi
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Quoted 7 lines · Felipe Balbi
Hi,
Quoted 3 lines · Baolin Wang
For supporting the usb charger, it adds the
usb_charger_init()andusb_charger_exit()functions for usb charger initialization and exit.
Quoted 8 lines
Quoted 6 lines
It will report to the usb charger when the gadget state is changed, then the usb charger can do the power things.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>Before anything, I must say that I really liked this patch. It's
Thanks.
Quoted 5 lines
minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
Quoted 7 lines
Quoted 4 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){
+ if (gadget->charger)I guess you could do this check inside
usb_gadget_set_cur_limit_by_type()itself.
OK.
Quoted 3 lines
--
balbi
Signature · 2 lines
Baolin.wang Best Regards
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 6 lines · Baolin Wang
Quoted 2 lines
Can't you just tie a charger to a UDC and avoid the charger class completely?
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
manage in what way? It seems to me that they don't need to be real devices, just a handle as part of struct usb_gadget, no?
Signature · 1 line
balbi
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Quoted 7 lines · Felipe Balbi
Hi,
Quoted 3 lines · Baolin Wang
Quoted 2 lines
Can't you just tie a charger to a UDC and avoid the charger class completely?
Quoted 6 lines
Quoted 3 lines
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
manage in what way? It seems to me that they don't need to be real devices, just a handle as part of struct
usb_gadget, no?
Although charger device is not one real hardware device, we also use one 'struct device' to describe it in charger.c file. So we should manage the 'struct device' with one proper way.
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
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 8 lines · Baolin Wang
Quoted 8 lines
Quoted 6 lines · Baolin Wang
Quoted 2 lines
Can't you just tie a charger to a UDC and avoid the charger class completely?
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
Quoted 6 lines
Quoted 2 lines
manage in what way? It seems to me that they don't need to be real devices, just a handle as part of struct
usb_gadget, no?Although charger device is not one real hardware device, we also use one 'struct device' to describe it in
charger.cfile. So we should manage the 'struct device' with one proper way.
that's fine, but why do you think they need a struct device to start with?
Signature · 1 line
balbi
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Quoted 12 lines · Felipe Balbi
Hi,
Quoted 8 lines · Baolin Wang
Quoted 8 lines
Quoted 6 lines · Baolin Wang
Quoted 2 lines
Can't you just tie a charger to a UDC and avoid the charger class completely?
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
manage in what way? It seems to me that they don't need to be real devices, just a handle as part of struct
usb_gadget, no?Although charger device is not one real hardware device, we also use one 'struct device' to describe it in
charger.cfile. So we should manage the 'struct device' with one proper way.that's fine, but why do you think they need a struct device to start with?
We can get/put usb charger and mange usb charger attributes with the device model if we use a struct device.
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
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 12 lines · Baolin Wang
Quoted 12 lines
Quoted 11 lines · Baolin Wang
Quoted 10 lines
Quoted 6 lines · Baolin Wang
Quoted 2 lines
Can't you just tie a charger to a UDC and avoid the charger class completely?
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
manage in what way? It seems to me that they don't need to be real devices, just a handle as part of struct
usb_gadget, no?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Although charger device is not one real hardware device, we also use one 'struct device' to describe it in
charger.cfile. So we should manage the 'struct device' with one proper way.that's fine, but why do you think they need a struct device to start with?
We can get/put usb charger and mange usb charger attributes with the device model if we use a struct device.
We already have that as part of struct usb_udc. Why don't you just create a subdirectory called charger which will hold all your charger-related attributes. That directory will only be created if a valid ->charger pointer exists.
USB Charging is always tied to a peripheral side controller, anyway.
Signature · 1 line
balbi
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Quoted 22 lines · Felipe Balbi
Hi,
Quoted 18 lines · Baolin Wang
Quoted 17 lines
Quoted 8 lines · Baolin Wang
Quoted 8 lines
Quoted 6 lines · Baolin Wang
Quoted 2 lines
Can't you just tie a charger to a UDC and avoid the charger class completely?
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
Quoted 6 lines
Quoted 2 lines
manage in what way? It seems to me that they don't need to be real devices, just a handle as part of struct
usb_gadget, no?Although charger device is not one real hardware device, we also use one 'struct device' to describe it in
charger.cfile. So we should manage the 'struct device' with one proper way.that's fine, but why do you think they need a struct device to start with?
Quoted 7 lines
Quoted 2 lines
We can get/put usb charger and mange usb charger attributes with the device model if we use a struct device.
We already have that as part of struct
usb_udc. Why don't you just create a subdirectory called charger which will hold all your charger-related attributes. That directory will only be created if a valid ->charger pointer exists.
That means we can remove all the device and class things in charger.c file, right? OK, I try to do that. Thanks.
Quoted 5 lines
USB Charging is always tied to a peripheral side controller, anyway.
--
balbi
Signature · 2 lines
Baolin.wang Best Regards
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 19 lines · Baolin Wang
Quoted 19 lines
Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Can't you just tie a charger to a UDC and avoid the charger class completely?
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
manage in what way? It seems to me that they don't need to be real devices, just a handle as part of struct
usb_gadget, no?Although charger device is not one real hardware device, we also use one 'struct device' to describe it in
charger.cfile. So we should manage the 'struct device' with one proper way.that's fine, but why do you think they need a struct device to start with?
We can get/put usb charger and mange usb charger attributes with the device model if we use a struct device.
Quoted 7 lines
Quoted 4 lines
We already have that as part of struct
usb_udc. Why don't you just create a subdirectory called charger which will hold all your charger-related attributes. That directory will only be created if a valid ->charger pointer exists.That means we can remove all the device and class things in
charger.cfile, right? OK, I try to do that. Thanks.
right. Keep your charger.c file, because to conditionally compile and link that to udc-core.ko, but remove all the class initialization and all of that extra code.
Signature · 1 line
balbi
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 24 lines · Felipe Balbi
Quoted 24 lines
Quoted 23 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Can't you just tie a charger to a UDC and avoid the charger class completely?
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
manage in what way? It seems to me that they don't need to be real devices, just a handle as part of struct
usb_gadget, no?Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Although charger device is not one real hardware device, we also use one 'struct device' to describe it in
charger.cfile. So we should manage the 'struct device' with one proper way.that's fine, but why do you think they need a struct device to start with?
We can get/put usb charger and mange usb charger attributes with the device model if we use a struct device.
We already have that as part of struct
usb_udc. Why don't you just create a subdirectory called charger which will hold all your charger-related attributes. That directory will only be created if a valid ->charger pointer exists.
Quoted 4 lines
Quoted 2 lines
That means we can remove all the device and class things in
charger.cfile, right? OK, I try to do that. Thanks.right. Keep your
charger.cfile, because to conditionally compile and
^
we want Quoted 5 lines
link that to udc-core.ko, but remove all the class initialization and all of that extra code.
Signature · 1 line
balbi
Signature · 1 line
balbi
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
In reply to Felipe BalbiQuoted 28 lines · Felipe Balbi
Hi,
Quoted 24 lines · Baolin Wang
Quoted 23 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Can't you just tie a charger to a UDC and avoid the charger class completely?
Yeah, I also hope so. But we really want something to manage the charger devices, do you have any good suggestion to avoid the 'class' but also can manage the charger devices?
manage in what way? It seems to me that they don't need to be real devices, just a handle as part of struct
usb_gadget, no?Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Although charger device is not one real hardware device, we also use one 'struct device' to describe it in
charger.cfile. So we should manage the 'struct device' with one proper way.that's fine, but why do you think they need a struct device to start with?
We can get/put usb charger and mange usb charger attributes with the device model if we use a struct device.
We already have that as part of struct
usb_udc. Why don't you just create a subdirectory called charger which will hold all your charger-related attributes. That directory will only be created if a valid ->charger pointer exists.
Quoted 6 lines
Quoted 2 lines
That means we can remove all the device and class things in
charger.cfile, right? OK, I try to do that. Thanks.right. Keep your
charger.cfile, because to conditionally compile and link that to udc-core.ko, but remove all the class initialization and all of that extra code.
Make sense.
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
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
In reply to Felipe BalbiHi,
Quoted 21 lines · Felipe Balbi
Hi,
Quoted 9 lines · Baolin Wang
For supporting the usb charger, it adds the
usb_charger_init()andusb_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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>Before anything, I must say that I really liked this patch. It's minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
Quoted 6 lines
Quoted 3 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){
+ if (gadget->charger)I guess you could do this check inside
usb_gadget_set_cur_limit_by_type()itself.
We will access the 'gadget->charger->type' member when issuing usb_gadget_set_cur_limit_by_type(), so I think I should leave the check here in next new version.
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
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 22 lines · Baolin Wang
Quoted 22 lines
Quoted 9 lines · Baolin Wang
For supporting the usb charger, it adds the
usb_charger_init()andusb_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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>Before anything, I must say that I really liked this patch. It's minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
Quoted 3 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){
+ if (gadget->charger)
Quoted 6 lines
Quoted 2 lines
I guess you could do this check inside
usb_gadget_set_cur_limit_by_type()itself.We will access the '
gadget->charger->type' member when issuingusb_gadget_set_cur_limit_by_type(), so I think I should leave the check here in next new version.
Here's what I mean:
int usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)
{
struct usb_charger *charger;
enum usb_charger_type type;
if (!gadget->charger)
return 0;
charger = gadget->charger;
type = charger->type;
return __usb_charger_set_cur_limit(charger, type, mA);
}static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
{
usb_charger_set_cur_limit(gadget, mA); if (!gadget->ops->vbus_draw)
return -EOPNOTSUPP;
return gadget->ops->vbus_draw(gadget, mA);
}
Signature · 1 line
balbi
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi Felipe,
Quoted 36 lines · Felipe Balbi
Hi,
Quoted 22 lines · Baolin Wang
Quoted 22 lines
Quoted 9 lines · Baolin Wang
For supporting the usb charger, it adds the
usb_charger_init()andusb_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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>Before anything, I must say that I really liked this patch. It's minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
Quoted 3 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){
+ if (gadget->charger)Quoted 6 lines
Quoted 2 lines
I guess you could do this check inside
usb_gadget_set_cur_limit_by_type()itself.We will access the '
gadget->charger->type' member when issuingusb_gadget_set_cur_limit_by_type(), so I think I should leave the check here in next new version.Here's what I mean:
int
usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)
Quoted 12 lines
{
struct usb_charger *charger;
enum usb_charger_type type;
if (!gadget->charger)
return 0;
charger = gadget->charger;
type = charger->type;
return __usb_charger_set_cur_limit(charger, type, mA);
}But that means we need to export both 'usb_charger_set_cur_limit()' function and '__usb_charger_set_cur_limit()' function in charger.c file. Cause some user may want to set the current limitation by one charger type parameter (may be not from charger->type), like by issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do you think about this situation? Thanks.
Quoted 12 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){ usb_charger_set_cur_limit(gadget, mA); if (!gadget->ops->vbus_draw) return -EOPNOTSUPP; return gadget->ops->vbus_draw(gadget, mA); }--
balbi
Signature · 2 lines
Baolin.wang Best Regards
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 44 lines · Baolin Wang
Quoted 31 lines
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
For supporting the usb charger, it adds the
usb_charger_init()andusb_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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>Before anything, I must say that I really liked this patch. It's minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
Quoted 3 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){
+ if (gadget->charger)Quoted 6 lines
Quoted 2 lines
I guess you could do this check inside
usb_gadget_set_cur_limit_by_type()itself.We will access the '
gadget->charger->type' member when issuingusb_gadget_set_cur_limit_by_type(), so I think I should leave the check here in next new version.Here's what I mean:
int
usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)Quoted 12 lines
{ struct usb_charger *charger; enum usb_charger_type type; if (!gadget->charger) return 0; charger = gadget->charger; type = charger->type; return __usb_charger_set_cur_limit(charger, type, mA); }
Quoted 6 lines
But that means we need to export both '
usb_charger_set_cur_limit()' function and '__usb_charger_set_cur_limit()' function incharger.cfile. Cause some user may want to set the current limitation by one charger type parameter (may be not fromcharger->type), like by issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do you think about this situation? Thanks.
if we have that requirement, that's totally fine. Just rename __usb_charger_set_cur_limit() back to _usb_charger_set_cur_limit_by_type() and expose both. But set_cur_limit_by_type can assume its arguments are valid at all times.
Signature · 1 line
balbi
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Quoted 55 lines · Felipe Balbi
Hi,
Quoted 44 lines · Baolin Wang
Quoted 31 lines
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
For supporting the usb charger, it adds the
usb_charger_init()andusb_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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>Before anything, I must say that I really liked this patch. It's minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
Quoted 3 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){
+ if (gadget->charger)Quoted 6 lines
Quoted 2 lines
I guess you could do this check inside
usb_gadget_set_cur_limit_by_type()itself.We will access the '
gadget->charger->type' member when issuingusb_gadget_set_cur_limit_by_type(), so I think I should leave the check here in next new version.Here's what I mean:
int
usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)Quoted 12 lines
{ struct usb_charger *charger; enum usb_charger_type type; if (!gadget->charger) return 0; charger = gadget->charger; type = charger->type; return __usb_charger_set_cur_limit(charger, type, mA); }Quoted 6 lines
But that means we need to export both '
usb_charger_set_cur_limit()' function and '__usb_charger_set_cur_limit()' function incharger.cfile. Cause some user may want to set the current limitation by one charger type parameter (may be not fromcharger->type), like by issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do you think about this situation? Thanks.
Quoted 4 lines
if we have that requirement, that's totally fine. Just rename
__usb_charger_set_cur_limit()back to_usb_charger_set_cur_limit_by_type()and expose both. Butset_cur_limit_by_typecan assume its arguments are valid at all times.
Make sense. I'll fix this issue in v14 version. Thanks.
Signature · 2 lines
Baolin.wang Best Regards
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 51 lines · Baolin Wang
Quoted 51 lines
Quoted 50 lines
Quoted 31 lines
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
For supporting the usb charger, it adds the
usb_charger_init()andusb_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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>Before anything, I must say that I really liked this patch. It's minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
Quoted 3 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){
+ if (gadget->charger)Quoted 6 lines
Quoted 2 lines
I guess you could do this check inside
usb_gadget_set_cur_limit_by_type()itself.We will access the '
gadget->charger->type' member when issuingusb_gadget_set_cur_limit_by_type(), so I think I should leave the check here in next new version.Here's what I mean:
int
usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)Quoted 12 lines
{ struct usb_charger *charger; enum usb_charger_type type; if (!gadget->charger) return 0; charger = gadget->charger; type = charger->type; return __usb_charger_set_cur_limit(charger, type, mA); }But that means we need to export both '
usb_charger_set_cur_limit()' function and '__usb_charger_set_cur_limit()' function incharger.cfile. Cause some user may want to set the current limitation by one charger type parameter (may be not fromcharger->type), like by issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do you think about this situation? Thanks.
Quoted 6 lines
Quoted 4 lines
if we have that requirement, that's totally fine. Just rename
__usb_charger_set_cur_limit()back to_usb_charger_set_cur_limit_by_type()and expose both. Butset_cur_limit_by_typecan assume its arguments are valid at all times.Make sense. I'll fix this issue in v14 version. Thanks.
there's one thing bothering me though:
gadget->charger is supposed to be "current detected charger" right? If we have a single port tied to a single charger, in which case would we *ever* need to change current limit of any charger type other than "current charger" ?
IOW, why do we need _set_cur_limit_by_type() exported at all?
Signature · 1 line
balbi
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi Felipe,
Quoted 60 lines · Felipe Balbi
Hi,
Quoted 56 lines · Baolin Wang
Quoted 55 lines
Quoted 44 lines
Quoted 31 lines
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
For supporting the usb charger, it adds the
usb_charger_init()andusb_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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>Before anything, I must say that I really liked this patch. It's minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
Quoted 3 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){
+ if (gadget->charger)Quoted 6 lines
Quoted 2 lines
I guess you could do this check inside
usb_gadget_set_cur_limit_by_type()itself.We will access the '
gadget->charger->type' member when issuingusb_gadget_set_cur_limit_by_type(), so I think I should leave the check here in next new version.Here's what I mean:
int
usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)Quoted 12 lines
{ struct usb_charger *charger; enum usb_charger_type type; if (!gadget->charger) return 0; charger = gadget->charger; type = charger->type; return __usb_charger_set_cur_limit(charger, type, mA); }Quoted 6 lines
But that means we need to export both '
usb_charger_set_cur_limit()' function and '__usb_charger_set_cur_limit()' function incharger.cfile. Cause some user may want to set the current limitation by one charger type parameter (may be not fromcharger->type), like by issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do you think about this situation? Thanks.if we have that requirement, that's totally fine. Just rename
__usb_charger_set_cur_limit()back to_usb_charger_set_cur_limit_by_type()and expose both. Butset_cur_limit_by_typecan assume its arguments are valid at all times.
Quoted 8 lines
Quoted 1 line
Make sense. I'll fix this issue in v14 version. Thanks.
there's one thing bothering me though:
gadget->chargeris supposed to be "current detected charger" right? If we have a single port tied to a single charger, in which case would we *ever* need to change current limit of any charger type other than "current charger" ?
What I mean is user can set the current limit by charger type as what they want at initial stage. As we know the default current of SDP (not super speed) is 500 mA, but user can set the current limit of SDP as 450 mA if there are some special on their own platform by issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, 450)'.
Quoted 5 lines
IOW, why do we need
_set_cur_limit_by_type()exported at all?--
balbi
Signature · 2 lines
Baolin.wang Best Regards
Re: [PATCH v12 2/4] gadget: Support for the usb charger framework
Hi,
Quoted 65 lines · Baolin Wang
Quoted 56 lines
Quoted 56 lines
Quoted 55 lines
Quoted 44 lines
Quoted 31 lines
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
For supporting the usb charger, it adds the
usb_charger_init()andusb_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.
Signed-off-by Baolin Wang <[email protected]>Reviewed-by Li Jun <[email protected]>Tested-by Li Jun <[email protected]>Before anything, I must say that I really liked this patch. It's minimaly invasive to udc core and does all the necessary changes. If it wasn't for the extra charger class, this would've been perfect.
Can't you just tie a charger to a UDC and avoid the charger class completely?
Quoted 3 lines
static inline int
usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA){
+ if (gadget->charger)Quoted 6 lines
Quoted 2 lines
I guess you could do this check inside
usb_gadget_set_cur_limit_by_type()itself.We will access the '
gadget->charger->type' member when issuingusb_gadget_set_cur_limit_by_type(), so I think I should leave the check here in next new version.Here's what I mean:
int
usb_charger_set_cur_limit(struct usb_gadget *gadget, unsigned int mA)Quoted 12 lines
{ struct usb_charger *charger; enum usb_charger_type type; if (!gadget->charger) return 0; charger = gadget->charger; type = charger->type; return __usb_charger_set_cur_limit(charger, type, mA); }Quoted 6 lines
But that means we need to export both '
usb_charger_set_cur_limit()' function and '__usb_charger_set_cur_limit()' function incharger.cfile. Cause some user may want to set the current limitation by one charger type parameter (may be not fromcharger->type), like by issuing '__usb_charger_set_cur_limit(charger, SDP_TYPE, mA)'. How do you think about this situation? Thanks.if we have that requirement, that's totally fine. Just rename
__usb_charger_set_cur_limit()back to_usb_charger_set_cur_limit_by_type()and expose both. Butset_cur_limit_by_typecan assume its arguments are valid at all times.Quoted 8 lines
Quoted 1 line
Make sense. I'll fix this issue in v14 version. Thanks.
there's one thing bothering me though:
gadget->chargeris supposed to be "current detected charger" right? If we have a single port tied to a single charger, in which case would we *ever* need to change current limit of any charger type other than "current charger" ?
Quoted 5 lines
What I mean is user can set the current limit by charger type as what they want at initial stage. As we know the default current of SDP (not super speed) is 500 mA, but user can set the current limit of SDP as 450 mA if there are some special on their own platform by issuing '
__usb_charger_set_cur_limit(charger, SDP_TYPE, 450)'.
Oh I see. Odd, but okay
Signature · 1 line
balbi
PATCH v12 3/4 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 and usb_charger_exit() function by getting 'struct usb_charger' from 'struct gadget'.
--- drivers/usb/gadget/udc/charger.c | 39 +++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
drivers/usb/gadget/udc/charger.c +38 -1
@@ -568,6 +568,30 @@ 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 ) + uchger_state =USB_CHARGER_REMOVE ; +else + uchger_state =USB_CHARGER_DEFAULT ; + +usb_charger_notify_others (uchger, uchger_state); + } +return 0 ; }EXPORT_SYMBOL_GPL (usb_charger_plug_by_gadget);
@@ -724,6 +748,7 @@ int usb_charger_init(struct usb_gadget *ugadget)/* register a notifier on a usb gadget device */ uchger->gadget = ugadget; + ugadget->charger = uchger; uchger->old_gadget_state =USB_STATE_NOTATTACHED ;/* register a new usb charger */
@@ -744,7 +769,19 @@ fail:int usb_charger_exit (struct usb_gadget *ugadget) { -return 0 ; +struct usb_charger *uchger = ugadget->charger; + +if (WARN (!uchger,"charger can not be NULL" )) +return -EINVAL ; + +if (uchger->extcon_dev) +extcon_unregister_notifier (uchger->extcon_dev, +EXTCON_USB , + &uchger->extcon_nb.nb); + +ida_simple_remove (&usb_charger_ida, uchger->id); + +return usb_charger_unregister (uchger); }static int __init usb_charger_class_init (void )
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 v12 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/wm831x_power.c | 69 ++++++++++++++++++++++++++++++++++++++ include/linux/mfd/wm831x/pdata.h | 3 ++ 2 files changed, 72 insertions(+)
drivers/power/wm831x_power.c +69 -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,43 @@ static enum power_supply_property wm831x_usb_props[] = { 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); +unsigned int i, best; + +/* 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 +647,31 @@ static int wm831x_power_probe(struct platform_device *pdev) } } +if (wm831x_pdata && wm831x_pdata->usb_gadget) { + power->usb_charger = +usb_charger_find_by_name (wm831x_pdata->usb_gadget); +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 +700,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,
include/linux/mfd/wm831x/pdata.h +3 -0
@@ -126,6 +126,9 @@ struct wm831x_pdata {/** The driver should initiate a power off sequence during shutdown */ bool soft_shutdown; +/** dev_name of USB charger gadget to integrate with */ +const char *usb_gadget; +int irq_base;int gpio_base;int gpio_defaults[WM831X_GPIO_NUM ];
Signature · 1 line
1.7.9.5
Re: [PATCH v12 4/4] power: wm831x_power: Support USB charger current limit management
Hi,
drivers/power/wm831x_power.c static int wm831x_power_probe(struct platform_device *pdev) · line 652
Quoted 7 lines · Baolin Wang
drivers/power/wm831x_power.c +3
-0@@ -607,8 +647,31 @@ static int wm831x_power_probe(struct platform_device *pdev) } } +if (wm831x_pdata && wm831x_pdata->usb_gadget) { + power->usb_charger = +usb_charger_find_by_name (wm831x_pdata->usb_gadget);
the fact that you rely on strings and pass them via pdata is an indication that you don't have enough description of the HW. Seems like we need to come up with a set of DT properties which tie a charger to a UDC.
I'm thinking a phandle would be enough?
Signature · 1 line
balbi
Re: [PATCH v12 4/4] power: wm831x_power: Support USB charger current limit management
Quoted 14 lines · Felipe Balbi
drivers/power/wm831x_power.c static int wm831x_power_probe(struct platform_device *pdev) · line 652
Quoted 7 lines · Baolin Wang
drivers/power/wm831x_power.c +3
-0@@ -607,8 +647,31 @@ static int wm831x_power_probe(struct platform_device *pdev) } } +if (wm831x_pdata && wm831x_pdata->usb_gadget) { + power->usb_charger = +usb_charger_find_by_name (wm831x_pdata->usb_gadget);the fact that you rely on strings and pass them via pdata is an indication that you don't have enough description of the HW. Seems like we need to come up with a set of DT properties which tie a charger to a UDC.
Quoted 1 line
I'm thinking a phandle would be enough?
The wm831x has no DT support currently.
Re: [PATCH v12 4/4] power: wm831x_power: Support USB charger current limit management
Quoted 10 lines · Mark Brown
Quoted 8 lines · Felipe Balbi
Quoted 7 lines · Baolin Wang
drivers/power/wm831x_power.c +3
-0@@ -607,8 +647,31 @@ static int wm831x_power_probe(struct platform_device *pdev) } } +if (wm831x_pdata && wm831x_pdata->usb_gadget) { + power->usb_charger = +usb_charger_find_by_name (wm831x_pdata->usb_gadget);
Quoted 8 lines
Quoted 6 lines
the fact that you rely on strings and pass them via pdata is an indication that you don't have enough description of the HW. Seems like we need to come up with a set of DT properties which tie a charger to a UDC.
I'm thinking a phandle would be enough?
The wm831x has no DT support currently.
Another hand I suppose the usb charger is one virtual device and does not need be described from DT.
Signature · 2 lines
Baolin.wang Best Regards
Re: [PATCH v12 4/4] power: wm831x_power: Support USB charger current limit management
Hi,
Quoted 16 lines · Baolin Wang
Quoted 15 lines · Mark Brown
Quoted 13 lines · Felipe Balbi
drivers/power/wm831x_power.c static int wm831x_power_probe(struct platform_device *pdev) · line 652
Quoted 7 lines · Baolin Wang
drivers/power/wm831x_power.c +3
-0@@ -607,8 +647,31 @@ static int wm831x_power_probe(struct platform_device *pdev) } } +if (wm831x_pdata && wm831x_pdata->usb_gadget) { + power->usb_charger = +usb_charger_find_by_name (wm831x_pdata->usb_gadget);the fact that you rely on strings and pass them via pdata is an indication that you don't have enough description of the HW. Seems like we need to come up with a set of DT properties which tie a charger to a UDC.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
I'm thinking a phandle would be enough?
The wm831x has no DT support currently.
Another hand I suppose the usb charger is one virtual device and does not need be described from DT.
Right, I don't think that should be a device at all. But you can pass a phandle to the UDC controller and use that to get to struct usb_gadget from which you could reach ->charger.
Signature · 1 line
balbi
Re: [PATCH v12 4/4] power: wm831x_power: Support USB charger current limit management
Quoted 22 lines · Felipe Balbi
Hi,
Quoted 18 lines · Baolin Wang
Quoted 17 lines · Mark Brown
Quoted 15 lines · Felipe Balbi
drivers/power/wm831x_power.c static int wm831x_power_probe(struct platform_device *pdev) · line 652
Quoted 7 lines · Baolin Wang
drivers/power/wm831x_power.c +3
-0@@ -607,8 +647,31 @@ static int wm831x_power_probe(struct platform_device *pdev) } } +if (wm831x_pdata && wm831x_pdata->usb_gadget) { + power->usb_charger = +usb_charger_find_by_name (wm831x_pdata->usb_gadget);the fact that you rely on strings and pass them via pdata is an indication that you don't have enough description of the HW. Seems like we need to come up with a set of DT properties which tie a charger to a UDC.
I'm thinking a phandle would be enough?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
The wm831x has no DT support currently.
Another hand I suppose the usb charger is one virtual device and does not need be described from DT.
Right, I don't think that should be a device at all. But you can pass a phandle to the UDC controller and use that to get to struct
usb_gadgetfrom which you could reach ->charger.
Ah, make sense.
Signature · 2 lines
Baolin.wang Best Regards
Re: [PATCH v12 4/4] power: wm831x_power: Support USB charger current limit management
In reply to Mark BrownHi,
Quoted 16 lines · Mark Brown
[ Unknown signature status ]
Quoted 13 lines · Felipe Balbi
drivers/power/wm831x_power.c static int wm831x_power_probe(struct platform_device *pdev) · line 652
Quoted 7 lines · Baolin Wang
drivers/power/wm831x_power.c +3
-0@@ -607,8 +647,31 @@ static int wm831x_power_probe(struct platform_device *pdev) } } +if (wm831x_pdata && wm831x_pdata->usb_gadget) { + power->usb_charger = +usb_charger_find_by_name (wm831x_pdata->usb_gadget);the fact that you rely on strings and pass them via pdata is an indication that you don't have enough description of the HW. Seems like we need to come up with a set of DT properties which tie a charger to a UDC.
Quoted 3 lines
Quoted 1 line
I'm thinking a phandle would be enough?
The wm831x has no DT support currently.
okay, perhaps its time to add it.
Signature · 1 line
balbi
Re: [PATCH v12 4/4] power: wm831x_power: Support USB charger current limit management
Quoted 5 lines · Felipe Balbi
Quoted 1 line · Mark Brown
The wm831x has no DT support currently.
okay, perhaps its time to add it.
The only platform using it would need the DT connector overlays completing in order to be able to convert to DT. I'm really not convinced it's worth the effort either.