xref: /openbmc/linux/drivers/usb/phy/phy-ab8500-usb.c (revision 81ef6724)
1 /*
2  * drivers/usb/otg/ab8500_usb.c
3  *
4  * USB transceiver driver for AB8500 chip
5  *
6  * Copyright (C) 2010 ST-Ericsson AB
7  * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  */
24 
25 #include <linux/module.h>
26 #include <linux/platform_device.h>
27 #include <linux/usb/otg.h>
28 #include <linux/slab.h>
29 #include <linux/notifier.h>
30 #include <linux/interrupt.h>
31 #include <linux/delay.h>
32 #include <linux/mfd/abx500.h>
33 #include <linux/mfd/abx500/ab8500.h>
34 #include <linux/usb/musb-ux500.h>
35 
36 #define AB8500_MAIN_WD_CTRL_REG 0x01
37 #define AB8500_USB_LINE_STAT_REG 0x80
38 #define AB8505_USB_LINE_STAT_REG 0x94
39 #define AB8500_USB_PHY_CTRL_REG 0x8A
40 
41 #define AB8500_BIT_OTG_STAT_ID (1 << 0)
42 #define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
43 #define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
44 #define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
45 #define AB8500_BIT_WD_CTRL_KICK (1 << 1)
46 
47 #define AB8500_WD_KICK_DELAY_US 100 /* usec */
48 #define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */
49 #define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */
50 
51 /* Usb line status register */
52 enum ab8500_usb_link_status {
53 	USB_LINK_NOT_CONFIGURED_8500 = 0,
54 	USB_LINK_STD_HOST_NC_8500,
55 	USB_LINK_STD_HOST_C_NS_8500,
56 	USB_LINK_STD_HOST_C_S_8500,
57 	USB_LINK_HOST_CHG_NM_8500,
58 	USB_LINK_HOST_CHG_HS_8500,
59 	USB_LINK_HOST_CHG_HS_CHIRP_8500,
60 	USB_LINK_DEDICATED_CHG_8500,
61 	USB_LINK_ACA_RID_A_8500,
62 	USB_LINK_ACA_RID_B_8500,
63 	USB_LINK_ACA_RID_C_NM_8500,
64 	USB_LINK_ACA_RID_C_HS_8500,
65 	USB_LINK_ACA_RID_C_HS_CHIRP_8500,
66 	USB_LINK_HM_IDGND_8500,
67 	USB_LINK_RESERVED_8500,
68 	USB_LINK_NOT_VALID_LINK_8500,
69 };
70 
71 enum ab8505_usb_link_status {
72 	USB_LINK_NOT_CONFIGURED_8505 = 0,
73 	USB_LINK_STD_HOST_NC_8505,
74 	USB_LINK_STD_HOST_C_NS_8505,
75 	USB_LINK_STD_HOST_C_S_8505,
76 	USB_LINK_CDP_8505,
77 	USB_LINK_RESERVED0_8505,
78 	USB_LINK_RESERVED1_8505,
79 	USB_LINK_DEDICATED_CHG_8505,
80 	USB_LINK_ACA_RID_A_8505,
81 	USB_LINK_ACA_RID_B_8505,
82 	USB_LINK_ACA_RID_C_NM_8505,
83 	USB_LINK_RESERVED2_8505,
84 	USB_LINK_RESERVED3_8505,
85 	USB_LINK_HM_IDGND_8505,
86 	USB_LINK_CHARGERPORT_NOT_OK_8505,
87 	USB_LINK_CHARGER_DM_HIGH_8505,
88 	USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505,
89 	USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505,
90 	USB_LINK_STD_UPSTREAM_8505,
91 	USB_LINK_CHARGER_SE1_8505,
92 	USB_LINK_CARKIT_CHGR_1_8505,
93 	USB_LINK_CARKIT_CHGR_2_8505,
94 	USB_LINK_ACA_DOCK_CHGR_8505,
95 	USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505,
96 	USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505,
97 	USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505,
98 	USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505,
99 	USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505,
100 };
101 
102 enum ab8500_usb_mode {
103 	USB_IDLE = 0,
104 	USB_PERIPHERAL,
105 	USB_HOST,
106 	USB_DEDICATED_CHG
107 };
108 
109 struct ab8500_usb {
110 	struct usb_phy phy;
111 	struct device *dev;
112 	struct ab8500 *ab8500;
113 	unsigned vbus_draw;
114 	struct delayed_work dwork;
115 	struct work_struct phy_dis_work;
116 	unsigned long link_status_wait;
117 	enum ab8500_usb_mode mode;
118 	int previous_link_status_state;
119 };
120 
121 static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x)
122 {
123 	return container_of(x, struct ab8500_usb, phy);
124 }
125 
126 static void ab8500_usb_wd_workaround(struct ab8500_usb *ab)
127 {
128 	abx500_set_register_interruptible(ab->dev,
129 		AB8500_SYS_CTRL2_BLOCK,
130 		AB8500_MAIN_WD_CTRL_REG,
131 		AB8500_BIT_WD_CTRL_ENABLE);
132 
133 	udelay(AB8500_WD_KICK_DELAY_US);
134 
135 	abx500_set_register_interruptible(ab->dev,
136 		AB8500_SYS_CTRL2_BLOCK,
137 		AB8500_MAIN_WD_CTRL_REG,
138 		(AB8500_BIT_WD_CTRL_ENABLE
139 		| AB8500_BIT_WD_CTRL_KICK));
140 
141 	udelay(AB8500_WD_V11_DISABLE_DELAY_US);
142 
143 	abx500_set_register_interruptible(ab->dev,
144 		AB8500_SYS_CTRL2_BLOCK,
145 		AB8500_MAIN_WD_CTRL_REG,
146 		0);
147 }
148 
149 static void ab8500_usb_wd_linkstatus(struct ab8500_usb *ab, u8 bit)
150 {
151 	/* Workaround for v2.0 bug # 31952 */
152 	if (is_ab8500_2p0(ab->ab8500)) {
153 		abx500_mask_and_set_register_interruptible(ab->dev,
154 				AB8500_USB, AB8500_USB_PHY_CTRL_REG,
155 				bit, bit);
156 		udelay(AB8500_V20_31952_DISABLE_DELAY_US);
157 	}
158 }
159 
160 static void ab8500_usb_phy_ctrl(struct ab8500_usb *ab, bool sel_host,
161 					bool enable)
162 {
163 	u8 ctrl_reg;
164 	abx500_get_register_interruptible(ab->dev,
165 				AB8500_USB,
166 				AB8500_USB_PHY_CTRL_REG,
167 				&ctrl_reg);
168 	if (sel_host) {
169 		if (enable)
170 			ctrl_reg |= AB8500_BIT_PHY_CTRL_HOST_EN;
171 		else
172 			ctrl_reg &= ~AB8500_BIT_PHY_CTRL_HOST_EN;
173 	} else {
174 		if (enable)
175 			ctrl_reg |= AB8500_BIT_PHY_CTRL_DEVICE_EN;
176 		else
177 			ctrl_reg &= ~AB8500_BIT_PHY_CTRL_DEVICE_EN;
178 	}
179 
180 	abx500_set_register_interruptible(ab->dev,
181 				AB8500_USB,
182 				AB8500_USB_PHY_CTRL_REG,
183 				ctrl_reg);
184 
185 	/* Needed to enable the phy.*/
186 	if (enable)
187 		ab8500_usb_wd_workaround(ab);
188 }
189 
190 #define ab8500_usb_host_phy_en(ab)	ab8500_usb_phy_ctrl(ab, true, true)
191 #define ab8500_usb_host_phy_dis(ab)	ab8500_usb_phy_ctrl(ab, true, false)
192 #define ab8500_usb_peri_phy_en(ab)	ab8500_usb_phy_ctrl(ab, false, true)
193 #define ab8500_usb_peri_phy_dis(ab)	ab8500_usb_phy_ctrl(ab, false, false)
194 
195 static int ab8505_usb_link_status_update(struct ab8500_usb *ab,
196 		enum ab8505_usb_link_status lsts)
197 {
198 	enum ux500_musb_vbus_id_status event = 0;
199 
200 	dev_dbg(ab->dev, "ab8505_usb_link_status_update %d\n", lsts);
201 
202 	/*
203 	 * Spurious link_status interrupts are seen at the time of
204 	 * disconnection of a device in RIDA state
205 	 */
206 	if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8505 &&
207 			(lsts == USB_LINK_STD_HOST_NC_8505))
208 		return 0;
209 
210 	ab->previous_link_status_state = lsts;
211 
212 	switch (lsts) {
213 	case USB_LINK_ACA_RID_B_8505:
214 		event = UX500_MUSB_RIDB;
215 	case USB_LINK_NOT_CONFIGURED_8505:
216 	case USB_LINK_RESERVED0_8505:
217 	case USB_LINK_RESERVED1_8505:
218 	case USB_LINK_RESERVED2_8505:
219 	case USB_LINK_RESERVED3_8505:
220 		ab->mode = USB_IDLE;
221 		ab->phy.otg->default_a = false;
222 		ab->vbus_draw = 0;
223 		if (event != UX500_MUSB_RIDB)
224 			event = UX500_MUSB_NONE;
225 		/*
226 		 * Fallback to default B_IDLE as nothing
227 		 * is connected
228 		 */
229 		ab->phy.state = OTG_STATE_B_IDLE;
230 		break;
231 
232 	case USB_LINK_ACA_RID_C_NM_8505:
233 		event = UX500_MUSB_RIDC;
234 	case USB_LINK_STD_HOST_NC_8505:
235 	case USB_LINK_STD_HOST_C_NS_8505:
236 	case USB_LINK_STD_HOST_C_S_8505:
237 	case USB_LINK_CDP_8505:
238 		if (ab->mode == USB_IDLE) {
239 			ab->mode = USB_PERIPHERAL;
240 			ab8500_usb_peri_phy_en(ab);
241 			atomic_notifier_call_chain(&ab->phy.notifier,
242 					UX500_MUSB_PREPARE, &ab->vbus_draw);
243 		}
244 		if (event != UX500_MUSB_RIDC)
245 			event = UX500_MUSB_VBUS;
246 		break;
247 
248 	case USB_LINK_ACA_RID_A_8505:
249 	case USB_LINK_ACA_DOCK_CHGR_8505:
250 		event = UX500_MUSB_RIDA;
251 	case USB_LINK_HM_IDGND_8505:
252 		if (ab->mode == USB_IDLE) {
253 			ab->mode = USB_HOST;
254 			ab8500_usb_host_phy_en(ab);
255 			atomic_notifier_call_chain(&ab->phy.notifier,
256 					UX500_MUSB_PREPARE, &ab->vbus_draw);
257 		}
258 		ab->phy.otg->default_a = true;
259 		if (event != UX500_MUSB_RIDA)
260 			event = UX500_MUSB_ID;
261 		atomic_notifier_call_chain(&ab->phy.notifier,
262 				event, &ab->vbus_draw);
263 		break;
264 
265 	case USB_LINK_DEDICATED_CHG_8505:
266 		ab->mode = USB_DEDICATED_CHG;
267 		event = UX500_MUSB_CHARGER;
268 		atomic_notifier_call_chain(&ab->phy.notifier,
269 				event, &ab->vbus_draw);
270 		break;
271 
272 	default:
273 		break;
274 	}
275 
276 	return 0;
277 }
278 
279 static int ab8500_usb_link_status_update(struct ab8500_usb *ab,
280 		enum ab8500_usb_link_status lsts)
281 {
282 	enum ux500_musb_vbus_id_status event = 0;
283 
284 	dev_dbg(ab->dev, "ab8500_usb_link_status_update %d\n", lsts);
285 
286 	/*
287 	 * Spurious link_status interrupts are seen in case of a
288 	 * disconnection of a device in IDGND and RIDA stage
289 	 */
290 	if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8500 &&
291 			(lsts == USB_LINK_STD_HOST_C_NS_8500 ||
292 			 lsts == USB_LINK_STD_HOST_NC_8500))
293 		return 0;
294 
295 	if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8500 &&
296 			lsts == USB_LINK_STD_HOST_NC_8500)
297 		return 0;
298 
299 	ab->previous_link_status_state = lsts;
300 
301 	switch (lsts) {
302 	case USB_LINK_ACA_RID_B_8500:
303 		event = UX500_MUSB_RIDB;
304 	case USB_LINK_NOT_CONFIGURED_8500:
305 	case USB_LINK_NOT_VALID_LINK_8500:
306 		ab->mode = USB_IDLE;
307 		ab->phy.otg->default_a = false;
308 		ab->vbus_draw = 0;
309 		if (event != UX500_MUSB_RIDB)
310 			event = UX500_MUSB_NONE;
311 		/* Fallback to default B_IDLE as nothing is connected */
312 		ab->phy.state = OTG_STATE_B_IDLE;
313 		break;
314 
315 	case USB_LINK_ACA_RID_C_NM_8500:
316 	case USB_LINK_ACA_RID_C_HS_8500:
317 	case USB_LINK_ACA_RID_C_HS_CHIRP_8500:
318 		event = UX500_MUSB_RIDC;
319 	case USB_LINK_STD_HOST_NC_8500:
320 	case USB_LINK_STD_HOST_C_NS_8500:
321 	case USB_LINK_STD_HOST_C_S_8500:
322 	case USB_LINK_HOST_CHG_NM_8500:
323 	case USB_LINK_HOST_CHG_HS_8500:
324 	case USB_LINK_HOST_CHG_HS_CHIRP_8500:
325 		if (ab->mode == USB_IDLE) {
326 			ab->mode = USB_PERIPHERAL;
327 			ab8500_usb_peri_phy_en(ab);
328 			atomic_notifier_call_chain(&ab->phy.notifier,
329 					UX500_MUSB_PREPARE, &ab->vbus_draw);
330 		}
331 		if (event != UX500_MUSB_RIDC)
332 			event = UX500_MUSB_VBUS;
333 		break;
334 
335 	case USB_LINK_ACA_RID_A_8500:
336 		event = UX500_MUSB_RIDA;
337 	case USB_LINK_HM_IDGND_8500:
338 		if (ab->mode == USB_IDLE) {
339 			ab->mode = USB_HOST;
340 			ab8500_usb_host_phy_en(ab);
341 			atomic_notifier_call_chain(&ab->phy.notifier,
342 					UX500_MUSB_PREPARE, &ab->vbus_draw);
343 		}
344 		ab->phy.otg->default_a = true;
345 		if (event != UX500_MUSB_RIDA)
346 			event = UX500_MUSB_ID;
347 		atomic_notifier_call_chain(&ab->phy.notifier,
348 				event, &ab->vbus_draw);
349 		break;
350 
351 	case USB_LINK_DEDICATED_CHG_8500:
352 		ab->mode = USB_DEDICATED_CHG;
353 		event = UX500_MUSB_CHARGER;
354 		atomic_notifier_call_chain(&ab->phy.notifier,
355 				event, &ab->vbus_draw);
356 		break;
357 
358 	case USB_LINK_RESERVED_8500:
359 		break;
360 	}
361 
362 	return 0;
363 }
364 
365 /*
366  * Connection Sequence:
367  *   1. Link Status Interrupt
368  *   2. Enable AB clock
369  *   3. Enable AB regulators
370  *   4. Enable USB phy
371  *   5. Reset the musb controller
372  *   6. Switch the ULPI GPIO pins to fucntion mode
373  *   7. Enable the musb Peripheral5 clock
374  *   8. Restore MUSB context
375  */
376 static int abx500_usb_link_status_update(struct ab8500_usb *ab)
377 {
378 	u8 reg;
379 	int ret = 0;
380 
381 	if (is_ab8500(ab->ab8500)) {
382 		enum ab8500_usb_link_status lsts;
383 
384 		abx500_get_register_interruptible(ab->dev,
385 				AB8500_USB, AB8500_USB_LINE_STAT_REG, &reg);
386 		lsts = (reg >> 3) & 0x0F;
387 		ret = ab8500_usb_link_status_update(ab, lsts);
388 	} else if (is_ab8505(ab->ab8500)) {
389 		enum ab8505_usb_link_status lsts;
390 
391 		abx500_get_register_interruptible(ab->dev,
392 				AB8500_USB, AB8505_USB_LINE_STAT_REG, &reg);
393 		lsts = (reg >> 3) & 0x1F;
394 		ret = ab8505_usb_link_status_update(ab, lsts);
395 	}
396 
397 	return ret;
398 }
399 
400 /*
401  * Disconnection Sequence:
402  *   1. Disconect Interrupt
403  *   2. Disable regulators
404  *   3. Disable AB clock
405  *   4. Disable the Phy
406  *   5. Link Status Interrupt
407  *   6. Disable Musb Clock
408  */
409 static irqreturn_t ab8500_usb_disconnect_irq(int irq, void *data)
410 {
411 	struct ab8500_usb *ab = (struct ab8500_usb *) data;
412 	enum usb_phy_events event = UX500_MUSB_NONE;
413 
414 	/* Link status will not be updated till phy is disabled. */
415 	if (ab->mode == USB_HOST) {
416 		ab->phy.otg->default_a = false;
417 		ab->vbus_draw = 0;
418 		atomic_notifier_call_chain(&ab->phy.notifier,
419 				event, &ab->vbus_draw);
420 		ab8500_usb_host_phy_dis(ab);
421 		ab->mode = USB_IDLE;
422 	}
423 
424 	if (ab->mode == USB_PERIPHERAL) {
425 		atomic_notifier_call_chain(&ab->phy.notifier,
426 				event, &ab->vbus_draw);
427 		ab8500_usb_peri_phy_dis(ab);
428 		atomic_notifier_call_chain(&ab->phy.notifier,
429 				UX500_MUSB_CLEAN, &ab->vbus_draw);
430 		ab->mode = USB_IDLE;
431 		ab->phy.otg->default_a = false;
432 		ab->vbus_draw = 0;
433 	}
434 
435 	if (is_ab8500_2p0(ab->ab8500)) {
436 		if (ab->mode == USB_DEDICATED_CHG) {
437 			ab8500_usb_wd_linkstatus(ab,
438 					AB8500_BIT_PHY_CTRL_DEVICE_EN);
439 			abx500_mask_and_set_register_interruptible(ab->dev,
440 					AB8500_USB, AB8500_USB_PHY_CTRL_REG,
441 					AB8500_BIT_PHY_CTRL_DEVICE_EN, 0);
442 		}
443 	}
444 
445 	return IRQ_HANDLED;
446 }
447 
448 static irqreturn_t ab8500_usb_link_status_irq(int irq, void *data)
449 {
450 	struct ab8500_usb *ab = (struct ab8500_usb *) data;
451 
452 	abx500_usb_link_status_update(ab);
453 
454 	return IRQ_HANDLED;
455 }
456 
457 static void ab8500_usb_delayed_work(struct work_struct *work)
458 {
459 	struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
460 						dwork.work);
461 
462 	abx500_usb_link_status_update(ab);
463 }
464 
465 static void ab8500_usb_phy_disable_work(struct work_struct *work)
466 {
467 	struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
468 						phy_dis_work);
469 
470 	if (!ab->phy.otg->host)
471 		ab8500_usb_host_phy_dis(ab);
472 
473 	if (!ab->phy.otg->gadget)
474 		ab8500_usb_peri_phy_dis(ab);
475 }
476 
477 static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA)
478 {
479 	struct ab8500_usb *ab;
480 
481 	if (!phy)
482 		return -ENODEV;
483 
484 	ab = phy_to_ab(phy);
485 
486 	ab->vbus_draw = mA;
487 
488 	if (mA)
489 		atomic_notifier_call_chain(&ab->phy.notifier,
490 				UX500_MUSB_ENUMERATED, ab->phy.otg->gadget);
491 	return 0;
492 }
493 
494 /* TODO: Implement some way for charging or other drivers to read
495  * ab->vbus_draw.
496  */
497 
498 static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend)
499 {
500 	/* TODO */
501 	return 0;
502 }
503 
504 static int ab8500_usb_set_peripheral(struct usb_otg *otg,
505 					struct usb_gadget *gadget)
506 {
507 	struct ab8500_usb *ab;
508 
509 	if (!otg)
510 		return -ENODEV;
511 
512 	ab = phy_to_ab(otg->phy);
513 
514 	/* Some drivers call this function in atomic context.
515 	 * Do not update ab8500 registers directly till this
516 	 * is fixed.
517 	 */
518 
519 	if (!gadget) {
520 		/* TODO: Disable regulators. */
521 		otg->gadget = NULL;
522 		schedule_work(&ab->phy_dis_work);
523 	} else {
524 		otg->gadget = gadget;
525 		otg->phy->state = OTG_STATE_B_IDLE;
526 
527 		/* Phy will not be enabled if cable is already
528 		 * plugged-in. Schedule to enable phy.
529 		 * Use same delay to avoid any race condition.
530 		 */
531 		schedule_delayed_work(&ab->dwork, ab->link_status_wait);
532 	}
533 
534 	return 0;
535 }
536 
537 static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
538 {
539 	struct ab8500_usb *ab;
540 
541 	if (!otg)
542 		return -ENODEV;
543 
544 	ab = phy_to_ab(otg->phy);
545 
546 	/* Some drivers call this function in atomic context.
547 	 * Do not update ab8500 registers directly till this
548 	 * is fixed.
549 	 */
550 
551 	if (!host) {
552 		/* TODO: Disable regulators. */
553 		otg->host = NULL;
554 		schedule_work(&ab->phy_dis_work);
555 	} else {
556 		otg->host = host;
557 		/* Phy will not be enabled if cable is already
558 		 * plugged-in. Schedule to enable phy.
559 		 * Use same delay to avoid any race condition.
560 		 */
561 		schedule_delayed_work(&ab->dwork, ab->link_status_wait);
562 	}
563 
564 	return 0;
565 }
566 
567 static int ab8500_usb_irq_setup(struct platform_device *pdev,
568 		struct ab8500_usb *ab)
569 {
570 	int err;
571 	int irq;
572 
573 	irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS");
574 	if (irq < 0) {
575 		dev_err(&pdev->dev, "Link status irq not found\n");
576 		return irq;
577 	}
578 	err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
579 			ab8500_usb_link_status_irq,
580 			IRQF_NO_SUSPEND | IRQF_SHARED, "usb-link-status", ab);
581 	if (err < 0) {
582 		dev_err(ab->dev, "request_irq failed for link status irq\n");
583 		return err;
584 	}
585 
586 	irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F");
587 	if (irq < 0) {
588 		dev_err(&pdev->dev, "ID fall irq not found\n");
589 		return irq;
590 	}
591 	err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
592 			ab8500_usb_disconnect_irq,
593 			IRQF_NO_SUSPEND | IRQF_SHARED, "usb-id-fall", ab);
594 	if (err < 0) {
595 		dev_err(ab->dev, "request_irq failed for ID fall irq\n");
596 		return err;
597 	}
598 
599 	irq = platform_get_irq_byname(pdev, "VBUS_DET_F");
600 	if (irq < 0) {
601 		dev_err(&pdev->dev, "VBUS fall irq not found\n");
602 		return irq;
603 	}
604 	err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
605 			ab8500_usb_disconnect_irq,
606 			IRQF_NO_SUSPEND | IRQF_SHARED, "usb-vbus-fall", ab);
607 	if (err < 0) {
608 		dev_err(ab->dev, "request_irq failed for Vbus fall irq\n");
609 		return err;
610 	}
611 
612 	return 0;
613 }
614 
615 static int ab8500_usb_probe(struct platform_device *pdev)
616 {
617 	struct ab8500_usb	*ab;
618 	struct ab8500		*ab8500;
619 	struct usb_otg		*otg;
620 	int err;
621 	int rev;
622 
623 	ab8500 = dev_get_drvdata(pdev->dev.parent);
624 	rev = abx500_get_chip_id(&pdev->dev);
625 
626 	if (is_ab8500_1p1_or_earlier(ab8500)) {
627 		dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev);
628 		return -ENODEV;
629 	}
630 
631 	ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL);
632 	if (!ab)
633 		return -ENOMEM;
634 
635 	otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
636 	if (!otg)
637 		return -ENOMEM;
638 
639 	ab->dev			= &pdev->dev;
640 	ab->ab8500		= ab8500;
641 	ab->phy.dev		= ab->dev;
642 	ab->phy.otg		= otg;
643 	ab->phy.label		= "ab8500";
644 	ab->phy.set_suspend	= ab8500_usb_set_suspend;
645 	ab->phy.set_power	= ab8500_usb_set_power;
646 	ab->phy.state		= OTG_STATE_UNDEFINED;
647 
648 	otg->phy		= &ab->phy;
649 	otg->set_host		= ab8500_usb_set_host;
650 	otg->set_peripheral	= ab8500_usb_set_peripheral;
651 
652 	platform_set_drvdata(pdev, ab);
653 
654 	ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
655 
656 	/* v1: Wait for link status to become stable.
657 	 * all: Updates form set_host and set_peripheral as they are atomic.
658 	 */
659 	INIT_DELAYED_WORK(&ab->dwork, ab8500_usb_delayed_work);
660 
661 	/* all: Disable phy when called from set_host and set_peripheral */
662 	INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
663 
664 	err = ab8500_usb_irq_setup(pdev, ab);
665 	if (err < 0)
666 		return err;
667 
668 	err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
669 	if (err) {
670 		dev_err(&pdev->dev, "Can't register transceiver\n");
671 		return err;
672 	}
673 
674 	/* Needed to enable ID detection. */
675 	ab8500_usb_wd_workaround(ab);
676 
677 	dev_info(&pdev->dev, "revision 0x%2x driver initialized\n", rev);
678 
679 	return 0;
680 }
681 
682 static int ab8500_usb_remove(struct platform_device *pdev)
683 {
684 	struct ab8500_usb *ab = platform_get_drvdata(pdev);
685 
686 	cancel_delayed_work_sync(&ab->dwork);
687 
688 	cancel_work_sync(&ab->phy_dis_work);
689 
690 	usb_remove_phy(&ab->phy);
691 
692 	ab8500_usb_host_phy_dis(ab);
693 	ab8500_usb_peri_phy_dis(ab);
694 
695 	platform_set_drvdata(pdev, NULL);
696 
697 	return 0;
698 }
699 
700 static struct platform_driver ab8500_usb_driver = {
701 	.probe		= ab8500_usb_probe,
702 	.remove		= ab8500_usb_remove,
703 	.driver		= {
704 		.name	= "ab8500-usb",
705 		.owner	= THIS_MODULE,
706 	},
707 };
708 
709 static int __init ab8500_usb_init(void)
710 {
711 	return platform_driver_register(&ab8500_usb_driver);
712 }
713 subsys_initcall(ab8500_usb_init);
714 
715 static void __exit ab8500_usb_exit(void)
716 {
717 	platform_driver_unregister(&ab8500_usb_driver);
718 }
719 module_exit(ab8500_usb_exit);
720 
721 MODULE_ALIAS("platform:ab8500_usb");
722 MODULE_AUTHOR("ST-Ericsson AB");
723 MODULE_DESCRIPTION("AB8500 usb transceiver driver");
724 MODULE_LICENSE("GPL");
725