xref: /OK3568_Linux_fs/kernel/drivers/usb/phy/phy.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0+
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * phy.c -- USB phy handling
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2004-2013 Texas Instruments
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #include <linux/kernel.h>
8*4882a593Smuzhiyun #include <linux/export.h>
9*4882a593Smuzhiyun #include <linux/err.h>
10*4882a593Smuzhiyun #include <linux/device.h>
11*4882a593Smuzhiyun #include <linux/module.h>
12*4882a593Smuzhiyun #include <linux/slab.h>
13*4882a593Smuzhiyun #include <linux/of.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <linux/usb/phy.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /* Default current range by charger type. */
18*4882a593Smuzhiyun #define DEFAULT_SDP_CUR_MIN	2
19*4882a593Smuzhiyun #define DEFAULT_SDP_CUR_MAX	500
20*4882a593Smuzhiyun #define DEFAULT_SDP_CUR_MIN_SS	150
21*4882a593Smuzhiyun #define DEFAULT_SDP_CUR_MAX_SS	900
22*4882a593Smuzhiyun #define DEFAULT_DCP_CUR_MIN	500
23*4882a593Smuzhiyun #define DEFAULT_DCP_CUR_MAX	5000
24*4882a593Smuzhiyun #define DEFAULT_CDP_CUR_MIN	1500
25*4882a593Smuzhiyun #define DEFAULT_CDP_CUR_MAX	5000
26*4882a593Smuzhiyun #define DEFAULT_ACA_CUR_MIN	1500
27*4882a593Smuzhiyun #define DEFAULT_ACA_CUR_MAX	5000
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun static LIST_HEAD(phy_list);
30*4882a593Smuzhiyun static DEFINE_SPINLOCK(phy_lock);
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun struct phy_devm {
33*4882a593Smuzhiyun 	struct usb_phy *phy;
34*4882a593Smuzhiyun 	struct notifier_block *nb;
35*4882a593Smuzhiyun };
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun static const char *const usb_chger_type[] = {
38*4882a593Smuzhiyun 	[UNKNOWN_TYPE]			= "USB_CHARGER_UNKNOWN_TYPE",
39*4882a593Smuzhiyun 	[SDP_TYPE]			= "USB_CHARGER_SDP_TYPE",
40*4882a593Smuzhiyun 	[CDP_TYPE]			= "USB_CHARGER_CDP_TYPE",
41*4882a593Smuzhiyun 	[DCP_TYPE]			= "USB_CHARGER_DCP_TYPE",
42*4882a593Smuzhiyun 	[ACA_TYPE]			= "USB_CHARGER_ACA_TYPE",
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun 
__usb_find_phy(struct list_head * list,enum usb_phy_type type)45*4882a593Smuzhiyun static struct usb_phy *__usb_find_phy(struct list_head *list,
46*4882a593Smuzhiyun 	enum usb_phy_type type)
47*4882a593Smuzhiyun {
48*4882a593Smuzhiyun 	struct usb_phy  *phy = NULL;
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	list_for_each_entry(phy, list, head) {
51*4882a593Smuzhiyun 		if (phy->type != type)
52*4882a593Smuzhiyun 			continue;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 		return phy;
55*4882a593Smuzhiyun 	}
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	return ERR_PTR(-ENODEV);
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun 
__of_usb_find_phy(struct device_node * node)60*4882a593Smuzhiyun static struct usb_phy *__of_usb_find_phy(struct device_node *node)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun 	struct usb_phy  *phy;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	if (!of_device_is_available(node))
65*4882a593Smuzhiyun 		return ERR_PTR(-ENODEV);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	list_for_each_entry(phy, &phy_list, head) {
68*4882a593Smuzhiyun 		if (node != phy->dev->of_node)
69*4882a593Smuzhiyun 			continue;
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 		return phy;
72*4882a593Smuzhiyun 	}
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	return ERR_PTR(-EPROBE_DEFER);
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun 
usb_phy_set_default_current(struct usb_phy * usb_phy)77*4882a593Smuzhiyun static void usb_phy_set_default_current(struct usb_phy *usb_phy)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun 	usb_phy->chg_cur.sdp_min = DEFAULT_SDP_CUR_MIN;
80*4882a593Smuzhiyun 	usb_phy->chg_cur.sdp_max = DEFAULT_SDP_CUR_MAX;
81*4882a593Smuzhiyun 	usb_phy->chg_cur.dcp_min = DEFAULT_DCP_CUR_MIN;
82*4882a593Smuzhiyun 	usb_phy->chg_cur.dcp_max = DEFAULT_DCP_CUR_MAX;
83*4882a593Smuzhiyun 	usb_phy->chg_cur.cdp_min = DEFAULT_CDP_CUR_MIN;
84*4882a593Smuzhiyun 	usb_phy->chg_cur.cdp_max = DEFAULT_CDP_CUR_MAX;
85*4882a593Smuzhiyun 	usb_phy->chg_cur.aca_min = DEFAULT_ACA_CUR_MIN;
86*4882a593Smuzhiyun 	usb_phy->chg_cur.aca_max = DEFAULT_ACA_CUR_MAX;
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun /**
90*4882a593Smuzhiyun  * usb_phy_notify_charger_work - notify the USB charger state
91*4882a593Smuzhiyun  * @work: the charger work to notify the USB charger state
92*4882a593Smuzhiyun  *
93*4882a593Smuzhiyun  * This work can be issued when USB charger state has been changed or
94*4882a593Smuzhiyun  * USB charger current has been changed, then we can notify the current
95*4882a593Smuzhiyun  * what can be drawn to power user and the charger state to userspace.
96*4882a593Smuzhiyun  *
97*4882a593Smuzhiyun  * If we get the charger type from extcon subsystem, we can notify the
98*4882a593Smuzhiyun  * charger state to power user automatically by usb_phy_get_charger_type()
99*4882a593Smuzhiyun  * issuing from extcon subsystem.
100*4882a593Smuzhiyun  *
101*4882a593Smuzhiyun  * If we get the charger type from ->charger_detect() instead of extcon
102*4882a593Smuzhiyun  * subsystem, the usb phy driver should issue usb_phy_set_charger_state()
103*4882a593Smuzhiyun  * to set charger state when the charger state has been changed.
104*4882a593Smuzhiyun  */
usb_phy_notify_charger_work(struct work_struct * work)105*4882a593Smuzhiyun static void usb_phy_notify_charger_work(struct work_struct *work)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun 	struct usb_phy *usb_phy = container_of(work, struct usb_phy, chg_work);
108*4882a593Smuzhiyun 	char uchger_state[50] = { 0 };
109*4882a593Smuzhiyun 	char uchger_type[50] = { 0 };
110*4882a593Smuzhiyun 	char *envp[] = { uchger_state, uchger_type, NULL };
111*4882a593Smuzhiyun 	unsigned int min, max;
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	switch (usb_phy->chg_state) {
114*4882a593Smuzhiyun 	case USB_CHARGER_PRESENT:
115*4882a593Smuzhiyun 		usb_phy_get_charger_current(usb_phy, &min, &max);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun 		atomic_notifier_call_chain(&usb_phy->notifier, max, usb_phy);
118*4882a593Smuzhiyun 		snprintf(uchger_state, ARRAY_SIZE(uchger_state),
119*4882a593Smuzhiyun 			 "USB_CHARGER_STATE=%s", "USB_CHARGER_PRESENT");
120*4882a593Smuzhiyun 		break;
121*4882a593Smuzhiyun 	case USB_CHARGER_ABSENT:
122*4882a593Smuzhiyun 		usb_phy_set_default_current(usb_phy);
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 		atomic_notifier_call_chain(&usb_phy->notifier, 0, usb_phy);
125*4882a593Smuzhiyun 		snprintf(uchger_state, ARRAY_SIZE(uchger_state),
126*4882a593Smuzhiyun 			 "USB_CHARGER_STATE=%s", "USB_CHARGER_ABSENT");
127*4882a593Smuzhiyun 		break;
128*4882a593Smuzhiyun 	default:
129*4882a593Smuzhiyun 		dev_warn(usb_phy->dev, "Unknown USB charger state: %d\n",
130*4882a593Smuzhiyun 			 usb_phy->chg_state);
131*4882a593Smuzhiyun 		return;
132*4882a593Smuzhiyun 	}
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun 	snprintf(uchger_type, ARRAY_SIZE(uchger_type),
135*4882a593Smuzhiyun 		 "USB_CHARGER_TYPE=%s", usb_chger_type[usb_phy->chg_type]);
136*4882a593Smuzhiyun 	kobject_uevent_env(&usb_phy->dev->kobj, KOBJ_CHANGE, envp);
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun 
__usb_phy_get_charger_type(struct usb_phy * usb_phy)139*4882a593Smuzhiyun static void __usb_phy_get_charger_type(struct usb_phy *usb_phy)
140*4882a593Smuzhiyun {
141*4882a593Smuzhiyun 	if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_SDP) > 0) {
142*4882a593Smuzhiyun 		usb_phy->chg_type = SDP_TYPE;
143*4882a593Smuzhiyun 		usb_phy->chg_state = USB_CHARGER_PRESENT;
144*4882a593Smuzhiyun 	} else if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_CDP) > 0) {
145*4882a593Smuzhiyun 		usb_phy->chg_type = CDP_TYPE;
146*4882a593Smuzhiyun 		usb_phy->chg_state = USB_CHARGER_PRESENT;
147*4882a593Smuzhiyun 	} else if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_DCP) > 0) {
148*4882a593Smuzhiyun 		usb_phy->chg_type = DCP_TYPE;
149*4882a593Smuzhiyun 		usb_phy->chg_state = USB_CHARGER_PRESENT;
150*4882a593Smuzhiyun 	} else if (extcon_get_state(usb_phy->edev, EXTCON_CHG_USB_ACA) > 0) {
151*4882a593Smuzhiyun 		usb_phy->chg_type = ACA_TYPE;
152*4882a593Smuzhiyun 		usb_phy->chg_state = USB_CHARGER_PRESENT;
153*4882a593Smuzhiyun 	} else {
154*4882a593Smuzhiyun 		usb_phy->chg_type = UNKNOWN_TYPE;
155*4882a593Smuzhiyun 		usb_phy->chg_state = USB_CHARGER_ABSENT;
156*4882a593Smuzhiyun 	}
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun 	schedule_work(&usb_phy->chg_work);
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun /**
162*4882a593Smuzhiyun  * usb_phy_get_charger_type - get charger type from extcon subsystem
163*4882a593Smuzhiyun  * @nb: the notifier block to determine charger type
164*4882a593Smuzhiyun  * @state: the cable state
165*4882a593Smuzhiyun  * @data: private data
166*4882a593Smuzhiyun  *
167*4882a593Smuzhiyun  * Determin the charger type from extcon subsystem which also means the
168*4882a593Smuzhiyun  * charger state has been chaned, then we should notify this event.
169*4882a593Smuzhiyun  */
usb_phy_get_charger_type(struct notifier_block * nb,unsigned long state,void * data)170*4882a593Smuzhiyun static int usb_phy_get_charger_type(struct notifier_block *nb,
171*4882a593Smuzhiyun 				    unsigned long state, void *data)
172*4882a593Smuzhiyun {
173*4882a593Smuzhiyun 	struct usb_phy *usb_phy = container_of(nb, struct usb_phy, type_nb);
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 	__usb_phy_get_charger_type(usb_phy);
176*4882a593Smuzhiyun 	return NOTIFY_OK;
177*4882a593Smuzhiyun }
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun /**
180*4882a593Smuzhiyun  * usb_phy_set_charger_current - set the USB charger current
181*4882a593Smuzhiyun  * @usb_phy: the USB phy to be used
182*4882a593Smuzhiyun  * @mA: the current need to be set
183*4882a593Smuzhiyun  *
184*4882a593Smuzhiyun  * Usually we only change the charger default current when USB finished the
185*4882a593Smuzhiyun  * enumeration as one SDP charger. As one SDP charger, usb_phy_set_power()
186*4882a593Smuzhiyun  * will issue this function to change charger current when after setting USB
187*4882a593Smuzhiyun  * configuration, or suspend/resume USB. For other type charger, we should
188*4882a593Smuzhiyun  * use the default charger current and we do not suggest to issue this function
189*4882a593Smuzhiyun  * to change the charger current.
190*4882a593Smuzhiyun  *
191*4882a593Smuzhiyun  * When USB charger current has been changed, we need to notify the power users.
192*4882a593Smuzhiyun  */
usb_phy_set_charger_current(struct usb_phy * usb_phy,unsigned int mA)193*4882a593Smuzhiyun void usb_phy_set_charger_current(struct usb_phy *usb_phy, unsigned int mA)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun 	switch (usb_phy->chg_type) {
196*4882a593Smuzhiyun 	case SDP_TYPE:
197*4882a593Smuzhiyun 		if (usb_phy->chg_cur.sdp_max == mA)
198*4882a593Smuzhiyun 			return;
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 		usb_phy->chg_cur.sdp_max = (mA > DEFAULT_SDP_CUR_MAX_SS) ?
201*4882a593Smuzhiyun 			DEFAULT_SDP_CUR_MAX_SS : mA;
202*4882a593Smuzhiyun 		break;
203*4882a593Smuzhiyun 	case DCP_TYPE:
204*4882a593Smuzhiyun 		if (usb_phy->chg_cur.dcp_max == mA)
205*4882a593Smuzhiyun 			return;
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 		usb_phy->chg_cur.dcp_max = (mA > DEFAULT_DCP_CUR_MAX) ?
208*4882a593Smuzhiyun 			DEFAULT_DCP_CUR_MAX : mA;
209*4882a593Smuzhiyun 		break;
210*4882a593Smuzhiyun 	case CDP_TYPE:
211*4882a593Smuzhiyun 		if (usb_phy->chg_cur.cdp_max == mA)
212*4882a593Smuzhiyun 			return;
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun 		usb_phy->chg_cur.cdp_max = (mA > DEFAULT_CDP_CUR_MAX) ?
215*4882a593Smuzhiyun 			DEFAULT_CDP_CUR_MAX : mA;
216*4882a593Smuzhiyun 		break;
217*4882a593Smuzhiyun 	case ACA_TYPE:
218*4882a593Smuzhiyun 		if (usb_phy->chg_cur.aca_max == mA)
219*4882a593Smuzhiyun 			return;
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun 		usb_phy->chg_cur.aca_max = (mA > DEFAULT_ACA_CUR_MAX) ?
222*4882a593Smuzhiyun 			DEFAULT_ACA_CUR_MAX : mA;
223*4882a593Smuzhiyun 		break;
224*4882a593Smuzhiyun 	default:
225*4882a593Smuzhiyun 		return;
226*4882a593Smuzhiyun 	}
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun 	schedule_work(&usb_phy->chg_work);
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_phy_set_charger_current);
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun /**
233*4882a593Smuzhiyun  * usb_phy_get_charger_current - get the USB charger current
234*4882a593Smuzhiyun  * @usb_phy: the USB phy to be used
235*4882a593Smuzhiyun  * @min: the minimum current
236*4882a593Smuzhiyun  * @max: the maximum current
237*4882a593Smuzhiyun  *
238*4882a593Smuzhiyun  * Usually we will notify the maximum current to power user, but for some
239*4882a593Smuzhiyun  * special case, power user also need the minimum current value. Then the
240*4882a593Smuzhiyun  * power user can issue this function to get the suitable current.
241*4882a593Smuzhiyun  */
usb_phy_get_charger_current(struct usb_phy * usb_phy,unsigned int * min,unsigned int * max)242*4882a593Smuzhiyun void usb_phy_get_charger_current(struct usb_phy *usb_phy,
243*4882a593Smuzhiyun 				 unsigned int *min, unsigned int *max)
244*4882a593Smuzhiyun {
245*4882a593Smuzhiyun 	switch (usb_phy->chg_type) {
246*4882a593Smuzhiyun 	case SDP_TYPE:
247*4882a593Smuzhiyun 		*min = usb_phy->chg_cur.sdp_min;
248*4882a593Smuzhiyun 		*max = usb_phy->chg_cur.sdp_max;
249*4882a593Smuzhiyun 		break;
250*4882a593Smuzhiyun 	case DCP_TYPE:
251*4882a593Smuzhiyun 		*min = usb_phy->chg_cur.dcp_min;
252*4882a593Smuzhiyun 		*max = usb_phy->chg_cur.dcp_max;
253*4882a593Smuzhiyun 		break;
254*4882a593Smuzhiyun 	case CDP_TYPE:
255*4882a593Smuzhiyun 		*min = usb_phy->chg_cur.cdp_min;
256*4882a593Smuzhiyun 		*max = usb_phy->chg_cur.cdp_max;
257*4882a593Smuzhiyun 		break;
258*4882a593Smuzhiyun 	case ACA_TYPE:
259*4882a593Smuzhiyun 		*min = usb_phy->chg_cur.aca_min;
260*4882a593Smuzhiyun 		*max = usb_phy->chg_cur.aca_max;
261*4882a593Smuzhiyun 		break;
262*4882a593Smuzhiyun 	default:
263*4882a593Smuzhiyun 		*min = 0;
264*4882a593Smuzhiyun 		*max = 0;
265*4882a593Smuzhiyun 		break;
266*4882a593Smuzhiyun 	}
267*4882a593Smuzhiyun }
268*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_phy_get_charger_current);
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun /**
271*4882a593Smuzhiyun  * usb_phy_set_charger_state - set the USB charger state
272*4882a593Smuzhiyun  * @usb_phy: the USB phy to be used
273*4882a593Smuzhiyun  * @state: the new state need to be set for charger
274*4882a593Smuzhiyun  *
275*4882a593Smuzhiyun  * The usb phy driver can issue this function when the usb phy driver
276*4882a593Smuzhiyun  * detected the charger state has been changed, in this case the charger
277*4882a593Smuzhiyun  * type should be get from ->charger_detect().
278*4882a593Smuzhiyun  */
usb_phy_set_charger_state(struct usb_phy * usb_phy,enum usb_charger_state state)279*4882a593Smuzhiyun void usb_phy_set_charger_state(struct usb_phy *usb_phy,
280*4882a593Smuzhiyun 			       enum usb_charger_state state)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun 	if (usb_phy->chg_state == state || !usb_phy->charger_detect)
283*4882a593Smuzhiyun 		return;
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun 	usb_phy->chg_state = state;
286*4882a593Smuzhiyun 	if (usb_phy->chg_state == USB_CHARGER_PRESENT)
287*4882a593Smuzhiyun 		usb_phy->chg_type = usb_phy->charger_detect(usb_phy);
288*4882a593Smuzhiyun 	else
289*4882a593Smuzhiyun 		usb_phy->chg_type = UNKNOWN_TYPE;
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 	schedule_work(&usb_phy->chg_work);
292*4882a593Smuzhiyun }
293*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_phy_set_charger_state);
294*4882a593Smuzhiyun 
devm_usb_phy_release(struct device * dev,void * res)295*4882a593Smuzhiyun static void devm_usb_phy_release(struct device *dev, void *res)
296*4882a593Smuzhiyun {
297*4882a593Smuzhiyun 	struct usb_phy *phy = *(struct usb_phy **)res;
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun 	usb_put_phy(phy);
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun 
devm_usb_phy_release2(struct device * dev,void * _res)302*4882a593Smuzhiyun static void devm_usb_phy_release2(struct device *dev, void *_res)
303*4882a593Smuzhiyun {
304*4882a593Smuzhiyun 	struct phy_devm *res = _res;
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun 	if (res->nb)
307*4882a593Smuzhiyun 		usb_unregister_notifier(res->phy, res->nb);
308*4882a593Smuzhiyun 	usb_put_phy(res->phy);
309*4882a593Smuzhiyun }
310*4882a593Smuzhiyun 
devm_usb_phy_match(struct device * dev,void * res,void * match_data)311*4882a593Smuzhiyun static int devm_usb_phy_match(struct device *dev, void *res, void *match_data)
312*4882a593Smuzhiyun {
313*4882a593Smuzhiyun 	struct usb_phy **phy = res;
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun 	return *phy == match_data;
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun 
usb_charger_init(struct usb_phy * usb_phy)318*4882a593Smuzhiyun static void usb_charger_init(struct usb_phy *usb_phy)
319*4882a593Smuzhiyun {
320*4882a593Smuzhiyun 	usb_phy->chg_type = UNKNOWN_TYPE;
321*4882a593Smuzhiyun 	usb_phy->chg_state = USB_CHARGER_DEFAULT;
322*4882a593Smuzhiyun 	usb_phy_set_default_current(usb_phy);
323*4882a593Smuzhiyun 	INIT_WORK(&usb_phy->chg_work, usb_phy_notify_charger_work);
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun 
usb_add_extcon(struct usb_phy * x)326*4882a593Smuzhiyun static int usb_add_extcon(struct usb_phy *x)
327*4882a593Smuzhiyun {
328*4882a593Smuzhiyun 	int ret;
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun 	if (of_property_read_bool(x->dev->of_node, "extcon")) {
331*4882a593Smuzhiyun 		x->edev = extcon_get_edev_by_phandle(x->dev, 0);
332*4882a593Smuzhiyun 		if (IS_ERR(x->edev))
333*4882a593Smuzhiyun 			return PTR_ERR(x->edev);
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun 		x->id_edev = extcon_get_edev_by_phandle(x->dev, 1);
336*4882a593Smuzhiyun 		if (IS_ERR(x->id_edev)) {
337*4882a593Smuzhiyun 			x->id_edev = NULL;
338*4882a593Smuzhiyun 			dev_info(x->dev, "No separate ID extcon device\n");
339*4882a593Smuzhiyun 		}
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun 		if (x->vbus_nb.notifier_call) {
342*4882a593Smuzhiyun 			ret = devm_extcon_register_notifier(x->dev, x->edev,
343*4882a593Smuzhiyun 							    EXTCON_USB,
344*4882a593Smuzhiyun 							    &x->vbus_nb);
345*4882a593Smuzhiyun 			if (ret < 0) {
346*4882a593Smuzhiyun 				dev_err(x->dev,
347*4882a593Smuzhiyun 					"register VBUS notifier failed\n");
348*4882a593Smuzhiyun 				return ret;
349*4882a593Smuzhiyun 			}
350*4882a593Smuzhiyun 		} else {
351*4882a593Smuzhiyun 			x->type_nb.notifier_call = usb_phy_get_charger_type;
352*4882a593Smuzhiyun 
353*4882a593Smuzhiyun 			ret = devm_extcon_register_notifier(x->dev, x->edev,
354*4882a593Smuzhiyun 							    EXTCON_CHG_USB_SDP,
355*4882a593Smuzhiyun 							    &x->type_nb);
356*4882a593Smuzhiyun 			if (ret) {
357*4882a593Smuzhiyun 				dev_err(x->dev,
358*4882a593Smuzhiyun 					"register extcon USB SDP failed.\n");
359*4882a593Smuzhiyun 				return ret;
360*4882a593Smuzhiyun 			}
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun 			ret = devm_extcon_register_notifier(x->dev, x->edev,
363*4882a593Smuzhiyun 							    EXTCON_CHG_USB_CDP,
364*4882a593Smuzhiyun 							    &x->type_nb);
365*4882a593Smuzhiyun 			if (ret) {
366*4882a593Smuzhiyun 				dev_err(x->dev,
367*4882a593Smuzhiyun 					"register extcon USB CDP failed.\n");
368*4882a593Smuzhiyun 				return ret;
369*4882a593Smuzhiyun 			}
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun 			ret = devm_extcon_register_notifier(x->dev, x->edev,
372*4882a593Smuzhiyun 							    EXTCON_CHG_USB_DCP,
373*4882a593Smuzhiyun 							    &x->type_nb);
374*4882a593Smuzhiyun 			if (ret) {
375*4882a593Smuzhiyun 				dev_err(x->dev,
376*4882a593Smuzhiyun 					"register extcon USB DCP failed.\n");
377*4882a593Smuzhiyun 				return ret;
378*4882a593Smuzhiyun 			}
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun 			ret = devm_extcon_register_notifier(x->dev, x->edev,
381*4882a593Smuzhiyun 							    EXTCON_CHG_USB_ACA,
382*4882a593Smuzhiyun 							    &x->type_nb);
383*4882a593Smuzhiyun 			if (ret) {
384*4882a593Smuzhiyun 				dev_err(x->dev,
385*4882a593Smuzhiyun 					"register extcon USB ACA failed.\n");
386*4882a593Smuzhiyun 				return ret;
387*4882a593Smuzhiyun 			}
388*4882a593Smuzhiyun 		}
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 		if (x->id_nb.notifier_call) {
391*4882a593Smuzhiyun 			struct extcon_dev *id_ext;
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun 			if (x->id_edev)
394*4882a593Smuzhiyun 				id_ext = x->id_edev;
395*4882a593Smuzhiyun 			else
396*4882a593Smuzhiyun 				id_ext = x->edev;
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun 			ret = devm_extcon_register_notifier(x->dev, id_ext,
399*4882a593Smuzhiyun 							    EXTCON_USB_HOST,
400*4882a593Smuzhiyun 							    &x->id_nb);
401*4882a593Smuzhiyun 			if (ret < 0) {
402*4882a593Smuzhiyun 				dev_err(x->dev,
403*4882a593Smuzhiyun 					"register ID notifier failed\n");
404*4882a593Smuzhiyun 				return ret;
405*4882a593Smuzhiyun 			}
406*4882a593Smuzhiyun 		}
407*4882a593Smuzhiyun 	}
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun 	if (x->type_nb.notifier_call)
410*4882a593Smuzhiyun 		__usb_phy_get_charger_type(x);
411*4882a593Smuzhiyun 
412*4882a593Smuzhiyun 	return 0;
413*4882a593Smuzhiyun }
414*4882a593Smuzhiyun 
415*4882a593Smuzhiyun /**
416*4882a593Smuzhiyun  * devm_usb_get_phy - find the USB PHY
417*4882a593Smuzhiyun  * @dev: device that requests this phy
418*4882a593Smuzhiyun  * @type: the type of the phy the controller requires
419*4882a593Smuzhiyun  *
420*4882a593Smuzhiyun  * Gets the phy using usb_get_phy(), and associates a device with it using
421*4882a593Smuzhiyun  * devres. On driver detach, release function is invoked on the devres data,
422*4882a593Smuzhiyun  * then, devres data is freed.
423*4882a593Smuzhiyun  *
424*4882a593Smuzhiyun  * For use by USB host and peripheral drivers.
425*4882a593Smuzhiyun  */
devm_usb_get_phy(struct device * dev,enum usb_phy_type type)426*4882a593Smuzhiyun struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
427*4882a593Smuzhiyun {
428*4882a593Smuzhiyun 	struct usb_phy **ptr, *phy;
429*4882a593Smuzhiyun 
430*4882a593Smuzhiyun 	ptr = devres_alloc(devm_usb_phy_release, sizeof(*ptr), GFP_KERNEL);
431*4882a593Smuzhiyun 	if (!ptr)
432*4882a593Smuzhiyun 		return ERR_PTR(-ENOMEM);
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun 	phy = usb_get_phy(type);
435*4882a593Smuzhiyun 	if (!IS_ERR(phy)) {
436*4882a593Smuzhiyun 		*ptr = phy;
437*4882a593Smuzhiyun 		devres_add(dev, ptr);
438*4882a593Smuzhiyun 	} else
439*4882a593Smuzhiyun 		devres_free(ptr);
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun 	return phy;
442*4882a593Smuzhiyun }
443*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(devm_usb_get_phy);
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun /**
446*4882a593Smuzhiyun  * usb_get_phy - find the USB PHY
447*4882a593Smuzhiyun  * @type: the type of the phy the controller requires
448*4882a593Smuzhiyun  *
449*4882a593Smuzhiyun  * Returns the phy driver, after getting a refcount to it; or
450*4882a593Smuzhiyun  * -ENODEV if there is no such phy.  The caller is responsible for
451*4882a593Smuzhiyun  * calling usb_put_phy() to release that count.
452*4882a593Smuzhiyun  *
453*4882a593Smuzhiyun  * For use by USB host and peripheral drivers.
454*4882a593Smuzhiyun  */
usb_get_phy(enum usb_phy_type type)455*4882a593Smuzhiyun struct usb_phy *usb_get_phy(enum usb_phy_type type)
456*4882a593Smuzhiyun {
457*4882a593Smuzhiyun 	struct usb_phy	*phy = NULL;
458*4882a593Smuzhiyun 	unsigned long	flags;
459*4882a593Smuzhiyun 
460*4882a593Smuzhiyun 	spin_lock_irqsave(&phy_lock, flags);
461*4882a593Smuzhiyun 
462*4882a593Smuzhiyun 	phy = __usb_find_phy(&phy_list, type);
463*4882a593Smuzhiyun 	if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
464*4882a593Smuzhiyun 		pr_debug("PHY: unable to find transceiver of type %s\n",
465*4882a593Smuzhiyun 			usb_phy_type_string(type));
466*4882a593Smuzhiyun 		if (!IS_ERR(phy))
467*4882a593Smuzhiyun 			phy = ERR_PTR(-ENODEV);
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun 		goto err0;
470*4882a593Smuzhiyun 	}
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun 	get_device(phy->dev);
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun err0:
475*4882a593Smuzhiyun 	spin_unlock_irqrestore(&phy_lock, flags);
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun 	return phy;
478*4882a593Smuzhiyun }
479*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_get_phy);
480*4882a593Smuzhiyun 
481*4882a593Smuzhiyun /**
482*4882a593Smuzhiyun  * devm_usb_get_phy_by_node - find the USB PHY by device_node
483*4882a593Smuzhiyun  * @dev: device that requests this phy
484*4882a593Smuzhiyun  * @node: the device_node for the phy device.
485*4882a593Smuzhiyun  * @nb: a notifier_block to register with the phy.
486*4882a593Smuzhiyun  *
487*4882a593Smuzhiyun  * Returns the phy driver associated with the given device_node,
488*4882a593Smuzhiyun  * after getting a refcount to it, -ENODEV if there is no such phy or
489*4882a593Smuzhiyun  * -EPROBE_DEFER if the device is not yet loaded. While at that, it
490*4882a593Smuzhiyun  * also associates the device with
491*4882a593Smuzhiyun  * the phy using devres. On driver detach, release function is invoked
492*4882a593Smuzhiyun  * on the devres data, then, devres data is freed.
493*4882a593Smuzhiyun  *
494*4882a593Smuzhiyun  * For use by peripheral drivers for devices related to a phy,
495*4882a593Smuzhiyun  * such as a charger.
496*4882a593Smuzhiyun  */
devm_usb_get_phy_by_node(struct device * dev,struct device_node * node,struct notifier_block * nb)497*4882a593Smuzhiyun struct  usb_phy *devm_usb_get_phy_by_node(struct device *dev,
498*4882a593Smuzhiyun 					  struct device_node *node,
499*4882a593Smuzhiyun 					  struct notifier_block *nb)
500*4882a593Smuzhiyun {
501*4882a593Smuzhiyun 	struct usb_phy	*phy = ERR_PTR(-ENOMEM);
502*4882a593Smuzhiyun 	struct phy_devm	*ptr;
503*4882a593Smuzhiyun 	unsigned long	flags;
504*4882a593Smuzhiyun 
505*4882a593Smuzhiyun 	ptr = devres_alloc(devm_usb_phy_release2, sizeof(*ptr), GFP_KERNEL);
506*4882a593Smuzhiyun 	if (!ptr) {
507*4882a593Smuzhiyun 		dev_dbg(dev, "failed to allocate memory for devres\n");
508*4882a593Smuzhiyun 		goto err0;
509*4882a593Smuzhiyun 	}
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun 	spin_lock_irqsave(&phy_lock, flags);
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun 	phy = __of_usb_find_phy(node);
514*4882a593Smuzhiyun 	if (IS_ERR(phy)) {
515*4882a593Smuzhiyun 		devres_free(ptr);
516*4882a593Smuzhiyun 		goto err1;
517*4882a593Smuzhiyun 	}
518*4882a593Smuzhiyun 
519*4882a593Smuzhiyun 	if (!try_module_get(phy->dev->driver->owner)) {
520*4882a593Smuzhiyun 		phy = ERR_PTR(-ENODEV);
521*4882a593Smuzhiyun 		devres_free(ptr);
522*4882a593Smuzhiyun 		goto err1;
523*4882a593Smuzhiyun 	}
524*4882a593Smuzhiyun 	if (nb)
525*4882a593Smuzhiyun 		usb_register_notifier(phy, nb);
526*4882a593Smuzhiyun 	ptr->phy = phy;
527*4882a593Smuzhiyun 	ptr->nb = nb;
528*4882a593Smuzhiyun 	devres_add(dev, ptr);
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun 	get_device(phy->dev);
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun err1:
533*4882a593Smuzhiyun 	spin_unlock_irqrestore(&phy_lock, flags);
534*4882a593Smuzhiyun 
535*4882a593Smuzhiyun err0:
536*4882a593Smuzhiyun 
537*4882a593Smuzhiyun 	return phy;
538*4882a593Smuzhiyun }
539*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(devm_usb_get_phy_by_node);
540*4882a593Smuzhiyun 
541*4882a593Smuzhiyun /**
542*4882a593Smuzhiyun  * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
543*4882a593Smuzhiyun  * @dev: device that requests this phy
544*4882a593Smuzhiyun  * @phandle: name of the property holding the phy phandle value
545*4882a593Smuzhiyun  * @index: the index of the phy
546*4882a593Smuzhiyun  *
547*4882a593Smuzhiyun  * Returns the phy driver associated with the given phandle value,
548*4882a593Smuzhiyun  * after getting a refcount to it, -ENODEV if there is no such phy or
549*4882a593Smuzhiyun  * -EPROBE_DEFER if there is a phandle to the phy, but the device is
550*4882a593Smuzhiyun  * not yet loaded. While at that, it also associates the device with
551*4882a593Smuzhiyun  * the phy using devres. On driver detach, release function is invoked
552*4882a593Smuzhiyun  * on the devres data, then, devres data is freed.
553*4882a593Smuzhiyun  *
554*4882a593Smuzhiyun  * For use by USB host and peripheral drivers.
555*4882a593Smuzhiyun  */
devm_usb_get_phy_by_phandle(struct device * dev,const char * phandle,u8 index)556*4882a593Smuzhiyun struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
557*4882a593Smuzhiyun 	const char *phandle, u8 index)
558*4882a593Smuzhiyun {
559*4882a593Smuzhiyun 	struct device_node *node;
560*4882a593Smuzhiyun 	struct usb_phy	*phy;
561*4882a593Smuzhiyun 
562*4882a593Smuzhiyun 	if (!dev->of_node) {
563*4882a593Smuzhiyun 		dev_dbg(dev, "device does not have a device node entry\n");
564*4882a593Smuzhiyun 		return ERR_PTR(-EINVAL);
565*4882a593Smuzhiyun 	}
566*4882a593Smuzhiyun 
567*4882a593Smuzhiyun 	node = of_parse_phandle(dev->of_node, phandle, index);
568*4882a593Smuzhiyun 	if (!node) {
569*4882a593Smuzhiyun 		dev_dbg(dev, "failed to get %s phandle in %pOF node\n", phandle,
570*4882a593Smuzhiyun 			dev->of_node);
571*4882a593Smuzhiyun 		return ERR_PTR(-ENODEV);
572*4882a593Smuzhiyun 	}
573*4882a593Smuzhiyun 	phy = devm_usb_get_phy_by_node(dev, node, NULL);
574*4882a593Smuzhiyun 	of_node_put(node);
575*4882a593Smuzhiyun 	return phy;
576*4882a593Smuzhiyun }
577*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(devm_usb_get_phy_by_phandle);
578*4882a593Smuzhiyun 
579*4882a593Smuzhiyun /**
580*4882a593Smuzhiyun  * devm_usb_put_phy - release the USB PHY
581*4882a593Smuzhiyun  * @dev: device that wants to release this phy
582*4882a593Smuzhiyun  * @phy: the phy returned by devm_usb_get_phy()
583*4882a593Smuzhiyun  *
584*4882a593Smuzhiyun  * destroys the devres associated with this phy and invokes usb_put_phy
585*4882a593Smuzhiyun  * to release the phy.
586*4882a593Smuzhiyun  *
587*4882a593Smuzhiyun  * For use by USB host and peripheral drivers.
588*4882a593Smuzhiyun  */
devm_usb_put_phy(struct device * dev,struct usb_phy * phy)589*4882a593Smuzhiyun void devm_usb_put_phy(struct device *dev, struct usb_phy *phy)
590*4882a593Smuzhiyun {
591*4882a593Smuzhiyun 	int r;
592*4882a593Smuzhiyun 
593*4882a593Smuzhiyun 	r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy);
594*4882a593Smuzhiyun 	dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
595*4882a593Smuzhiyun }
596*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(devm_usb_put_phy);
597*4882a593Smuzhiyun 
598*4882a593Smuzhiyun /**
599*4882a593Smuzhiyun  * usb_put_phy - release the USB PHY
600*4882a593Smuzhiyun  * @x: the phy returned by usb_get_phy()
601*4882a593Smuzhiyun  *
602*4882a593Smuzhiyun  * Releases a refcount the caller received from usb_get_phy().
603*4882a593Smuzhiyun  *
604*4882a593Smuzhiyun  * For use by USB host and peripheral drivers.
605*4882a593Smuzhiyun  */
usb_put_phy(struct usb_phy * x)606*4882a593Smuzhiyun void usb_put_phy(struct usb_phy *x)
607*4882a593Smuzhiyun {
608*4882a593Smuzhiyun 	if (x) {
609*4882a593Smuzhiyun 		struct module *owner = x->dev->driver->owner;
610*4882a593Smuzhiyun 
611*4882a593Smuzhiyun 		put_device(x->dev);
612*4882a593Smuzhiyun 		module_put(owner);
613*4882a593Smuzhiyun 	}
614*4882a593Smuzhiyun }
615*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_put_phy);
616*4882a593Smuzhiyun 
617*4882a593Smuzhiyun /**
618*4882a593Smuzhiyun  * usb_add_phy: declare the USB PHY
619*4882a593Smuzhiyun  * @x: the USB phy to be used; or NULL
620*4882a593Smuzhiyun  * @type: the type of this PHY
621*4882a593Smuzhiyun  *
622*4882a593Smuzhiyun  * This call is exclusively for use by phy drivers, which
623*4882a593Smuzhiyun  * coordinate the activities of drivers for host and peripheral
624*4882a593Smuzhiyun  * controllers, and in some cases for VBUS current regulation.
625*4882a593Smuzhiyun  */
usb_add_phy(struct usb_phy * x,enum usb_phy_type type)626*4882a593Smuzhiyun int usb_add_phy(struct usb_phy *x, enum usb_phy_type type)
627*4882a593Smuzhiyun {
628*4882a593Smuzhiyun 	int		ret = 0;
629*4882a593Smuzhiyun 	unsigned long	flags;
630*4882a593Smuzhiyun 	struct usb_phy	*phy;
631*4882a593Smuzhiyun 
632*4882a593Smuzhiyun 	if (x->type != USB_PHY_TYPE_UNDEFINED) {
633*4882a593Smuzhiyun 		dev_err(x->dev, "not accepting initialized PHY %s\n", x->label);
634*4882a593Smuzhiyun 		return -EINVAL;
635*4882a593Smuzhiyun 	}
636*4882a593Smuzhiyun 
637*4882a593Smuzhiyun 	usb_charger_init(x);
638*4882a593Smuzhiyun 	ret = usb_add_extcon(x);
639*4882a593Smuzhiyun 	if (ret)
640*4882a593Smuzhiyun 		return ret;
641*4882a593Smuzhiyun 
642*4882a593Smuzhiyun 	ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier);
643*4882a593Smuzhiyun 
644*4882a593Smuzhiyun 	spin_lock_irqsave(&phy_lock, flags);
645*4882a593Smuzhiyun 
646*4882a593Smuzhiyun 	list_for_each_entry(phy, &phy_list, head) {
647*4882a593Smuzhiyun 		if (phy->type == type) {
648*4882a593Smuzhiyun 			ret = -EBUSY;
649*4882a593Smuzhiyun 			dev_err(x->dev, "transceiver type %s already exists\n",
650*4882a593Smuzhiyun 						usb_phy_type_string(type));
651*4882a593Smuzhiyun 			goto out;
652*4882a593Smuzhiyun 		}
653*4882a593Smuzhiyun 	}
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun 	x->type = type;
656*4882a593Smuzhiyun 	list_add_tail(&x->head, &phy_list);
657*4882a593Smuzhiyun 
658*4882a593Smuzhiyun out:
659*4882a593Smuzhiyun 	spin_unlock_irqrestore(&phy_lock, flags);
660*4882a593Smuzhiyun 	return ret;
661*4882a593Smuzhiyun }
662*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_add_phy);
663*4882a593Smuzhiyun 
664*4882a593Smuzhiyun /**
665*4882a593Smuzhiyun  * usb_add_phy_dev - declare the USB PHY
666*4882a593Smuzhiyun  * @x: the USB phy to be used; or NULL
667*4882a593Smuzhiyun  *
668*4882a593Smuzhiyun  * This call is exclusively for use by phy drivers, which
669*4882a593Smuzhiyun  * coordinate the activities of drivers for host and peripheral
670*4882a593Smuzhiyun  * controllers, and in some cases for VBUS current regulation.
671*4882a593Smuzhiyun  */
usb_add_phy_dev(struct usb_phy * x)672*4882a593Smuzhiyun int usb_add_phy_dev(struct usb_phy *x)
673*4882a593Smuzhiyun {
674*4882a593Smuzhiyun 	unsigned long flags;
675*4882a593Smuzhiyun 	int ret;
676*4882a593Smuzhiyun 
677*4882a593Smuzhiyun 	if (!x->dev) {
678*4882a593Smuzhiyun 		dev_err(x->dev, "no device provided for PHY\n");
679*4882a593Smuzhiyun 		return -EINVAL;
680*4882a593Smuzhiyun 	}
681*4882a593Smuzhiyun 
682*4882a593Smuzhiyun 	usb_charger_init(x);
683*4882a593Smuzhiyun 	ret = usb_add_extcon(x);
684*4882a593Smuzhiyun 	if (ret)
685*4882a593Smuzhiyun 		return ret;
686*4882a593Smuzhiyun 
687*4882a593Smuzhiyun 	ATOMIC_INIT_NOTIFIER_HEAD(&x->notifier);
688*4882a593Smuzhiyun 
689*4882a593Smuzhiyun 	spin_lock_irqsave(&phy_lock, flags);
690*4882a593Smuzhiyun 	list_add_tail(&x->head, &phy_list);
691*4882a593Smuzhiyun 	spin_unlock_irqrestore(&phy_lock, flags);
692*4882a593Smuzhiyun 
693*4882a593Smuzhiyun 	return 0;
694*4882a593Smuzhiyun }
695*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_add_phy_dev);
696*4882a593Smuzhiyun 
697*4882a593Smuzhiyun /**
698*4882a593Smuzhiyun  * usb_remove_phy - remove the OTG PHY
699*4882a593Smuzhiyun  * @x: the USB OTG PHY to be removed;
700*4882a593Smuzhiyun  *
701*4882a593Smuzhiyun  * This reverts the effects of usb_add_phy
702*4882a593Smuzhiyun  */
usb_remove_phy(struct usb_phy * x)703*4882a593Smuzhiyun void usb_remove_phy(struct usb_phy *x)
704*4882a593Smuzhiyun {
705*4882a593Smuzhiyun 	unsigned long	flags;
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun 	spin_lock_irqsave(&phy_lock, flags);
708*4882a593Smuzhiyun 	if (x)
709*4882a593Smuzhiyun 		list_del(&x->head);
710*4882a593Smuzhiyun 	spin_unlock_irqrestore(&phy_lock, flags);
711*4882a593Smuzhiyun }
712*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_remove_phy);
713*4882a593Smuzhiyun 
714*4882a593Smuzhiyun /**
715*4882a593Smuzhiyun  * usb_phy_set_event - set event to phy event
716*4882a593Smuzhiyun  * @x: the phy returned by usb_get_phy();
717*4882a593Smuzhiyun  * @event: event to set
718*4882a593Smuzhiyun  *
719*4882a593Smuzhiyun  * This sets event to phy event
720*4882a593Smuzhiyun  */
usb_phy_set_event(struct usb_phy * x,unsigned long event)721*4882a593Smuzhiyun void usb_phy_set_event(struct usb_phy *x, unsigned long event)
722*4882a593Smuzhiyun {
723*4882a593Smuzhiyun 	x->last_event = event;
724*4882a593Smuzhiyun }
725*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(usb_phy_set_event);
726