aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/usb
diff options
context:
space:
mode:
authorBaolin Wang <baolin.wang@linaro.org>2017-08-15 07:07:54 -0400
committerFelipe Balbi <felipe.balbi@linux.intel.com>2017-08-15 08:05:01 -0400
commita9081a008f84819ab2f3da596bf89afa16beea94 (patch)
tree8ab66396b7c73b1a75275a3b86d30f67a0fcbfba /include/linux/usb
parent44dd8a989c787e9077745417140aa132bfe45bf5 (diff)
usb: phy: Add USB charger support
This patch introduces the usb charger support based on usb phy that makes an enhancement to a power driver. The basic conception of the usb charger is that, when one usb charger is added or removed by reporting from the extcon device state change, the usb charger will report to power user to set the current limitation. Power user can register a notifiee on the usb phy by issuing usb_register_notifier() to get notified by charger status changes or charger current changes. we can notify what current to be drawn to power user according to different charger type, and now we have 2 methods to get charger type. One is get charger type from extcon subsystem, which also means the charger state changes. Another is we can get the charger type from USB controller detecting or PMIC detecting, and the charger state changes should be told by issuing usb_phy_set_charger_state(). Signed-off-by: Baolin Wang <baolin.wang@linaro.org> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Diffstat (limited to 'include/linux/usb')
-rw-r--r--include/linux/usb/phy.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index 299245105610..de881b171ba9 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -12,6 +12,7 @@
12#include <linux/extcon.h> 12#include <linux/extcon.h>
13#include <linux/notifier.h> 13#include <linux/notifier.h>
14#include <linux/usb.h> 14#include <linux/usb.h>
15#include <uapi/linux/usb/charger.h>
15 16
16enum usb_phy_interface { 17enum usb_phy_interface {
17 USBPHY_INTERFACE_MODE_UNKNOWN, 18 USBPHY_INTERFACE_MODE_UNKNOWN,
@@ -72,6 +73,17 @@ struct usb_phy_io_ops {
72 int (*write)(struct usb_phy *x, u32 val, u32 reg); 73 int (*write)(struct usb_phy *x, u32 val, u32 reg);
73}; 74};
74 75
76struct usb_charger_current {
77 unsigned int sdp_min;
78 unsigned int sdp_max;
79 unsigned int dcp_min;
80 unsigned int dcp_max;
81 unsigned int cdp_min;
82 unsigned int cdp_max;
83 unsigned int aca_min;
84 unsigned int aca_max;
85};
86
75struct usb_phy { 87struct usb_phy {
76 struct device *dev; 88 struct device *dev;
77 const char *label; 89 const char *label;
@@ -91,6 +103,13 @@ struct usb_phy {
91 struct extcon_dev *id_edev; 103 struct extcon_dev *id_edev;
92 struct notifier_block vbus_nb; 104 struct notifier_block vbus_nb;
93 struct notifier_block id_nb; 105 struct notifier_block id_nb;
106 struct notifier_block type_nb;
107
108 /* Support USB charger */
109 enum usb_charger_type chg_type;
110 enum usb_charger_state chg_state;
111 struct usb_charger_current chg_cur;
112 struct work_struct chg_work;
94 113
95 /* for notification of usb_phy_events */ 114 /* for notification of usb_phy_events */
96 struct atomic_notifier_head notifier; 115 struct atomic_notifier_head notifier;
@@ -129,6 +148,12 @@ struct usb_phy {
129 enum usb_device_speed speed); 148 enum usb_device_speed speed);
130 int (*notify_disconnect)(struct usb_phy *x, 149 int (*notify_disconnect)(struct usb_phy *x,
131 enum usb_device_speed speed); 150 enum usb_device_speed speed);
151
152 /*
153 * Charger detection method can be implemented if you need to
154 * manually detect the charger type.
155 */
156 enum usb_charger_type (*charger_detect)(struct usb_phy *x);
132}; 157};
133 158
134/** 159/**
@@ -219,6 +244,12 @@ extern void devm_usb_put_phy(struct device *dev, struct usb_phy *x);
219extern int usb_bind_phy(const char *dev_name, u8 index, 244extern int usb_bind_phy(const char *dev_name, u8 index,
220 const char *phy_dev_name); 245 const char *phy_dev_name);
221extern void usb_phy_set_event(struct usb_phy *x, unsigned long event); 246extern void usb_phy_set_event(struct usb_phy *x, unsigned long event);
247extern void usb_phy_set_charger_current(struct usb_phy *usb_phy,
248 unsigned int mA);
249extern void usb_phy_get_charger_current(struct usb_phy *usb_phy,
250 unsigned int *min, unsigned int *max);
251extern void usb_phy_set_charger_state(struct usb_phy *usb_phy,
252 enum usb_charger_state state);
222#else 253#else
223static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) 254static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
224{ 255{
@@ -270,11 +301,29 @@ static inline int usb_bind_phy(const char *dev_name, u8 index,
270static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event) 301static inline void usb_phy_set_event(struct usb_phy *x, unsigned long event)
271{ 302{
272} 303}
304
305static inline void usb_phy_set_charger_current(struct usb_phy *usb_phy,
306 unsigned int mA)
307{
308}
309
310static inline void usb_phy_get_charger_current(struct usb_phy *usb_phy,
311 unsigned int *min,
312 unsigned int *max)
313{
314}
315
316static inline void usb_phy_set_charger_state(struct usb_phy *usb_phy,
317 enum usb_charger_state state)
318{
319}
273#endif 320#endif
274 321
275static inline int 322static inline int
276usb_phy_set_power(struct usb_phy *x, unsigned mA) 323usb_phy_set_power(struct usb_phy *x, unsigned mA)
277{ 324{
325 usb_phy_set_charger_current(x, mA);
326
278 if (x && x->set_power) 327 if (x && x->set_power)
279 return x->set_power(x, mA); 328 return x->set_power(x, mA);
280 return 0; 329 return 0;