summaryrefslogtreecommitdiff
path: root/drivers/usb/otg/ab5500-usb.c
blob: acd3dcbb73975dd54cd512c5a7d7a9bc90d09d14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
/*
 * Copyright (C) ST-Ericsson SA 2011
 *
 * Author: Avinash Kumar <avinash.kumar@stericsson.com> for ST-Ericsson
 * License terms: GNU General Public License (GPL) version 2
 */

#include <linux/platform_device.h>
#include <linux/usb/otg.h>
#include <linux/slab.h>
#include <linux/notifier.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/mfd/abx500/ab5500.h>
#include <linux/mfd/abx500.h>
#include <linux/regulator/consumer.h>
#include <mach/prcmu.h>
#include <mach/usb.h>
#include <linux/kernel_stat.h>
#include <mach/gpio.h>

#include <linux/wakelock.h>
static struct wake_lock ab5500_musb_wakelock;

/* AB5500 USB macros
 */
#define AB5500_USB_HOST_ENABLE 0x1
#define AB5500_USB_HOST_DISABLE 0x0
#define AB5500_USB_DEVICE_ENABLE 0x2
#define AB5500_USB_DEVICE_DISABLE 0x0
#define AB5500_MAIN_WATCHDOG_ENABLE 0x1
#define AB5500_MAIN_WATCHDOG_KICK 0x2
#define AB5500_MAIN_WATCHDOG_DISABLE 0x0
#define AB5500_USB_ADP_ENABLE 0x1
#define AB5500_WATCHDOG_DELAY 10
#define AB5500_WATCHDOG_DELAY_US 100
#define AB5500_PHY_DELAY_US 100
#define AB5500_USB_DEVICE_DISABLE 0x0
#define AB5500_MAIN_WDOG_CTRL_REG      0x01
#define AB5500_USB_LINE_STAT_REG       0x80
#define AB5500_USB_PHY_CTRL_REG        0x8A
#define AB5500_MAIN_WATCHDOG_ENABLE 0x1
#define AB5500_MAIN_WATCHDOG_KICK 0x2
#define AB5500_MAIN_WATCHDOG_DISABLE 0x0
#define AB5500_SYS_CTRL2_BLOCK	0x2

#define USB_PROBE_DELAY 1000 /* 1 seconds */

/* UsbLineStatus register - usb types */
enum ab8500_usb_link_status {
	USB_LINK_NOT_CONFIGURED,
	USB_LINK_STD_HOST_NC,
	USB_LINK_STD_HOST_C_NS,
	USB_LINK_STD_HOST_C_S,
	USB_LINK_HOST_CHG_NM,
	USB_LINK_HOST_CHG_HS,
	USB_LINK_HOST_CHG_HS_CHIRP,
	USB_LINK_DEDICATED_CHG,
	USB_LINK_ACA_RID_A,
	USB_LINK_ACA_RID_B,
	USB_LINK_ACA_RID_C_NM,
	USB_LINK_ACA_RID_C_HS,
	USB_LINK_ACA_RID_C_HS_CHIRP,
	USB_LINK_HM_IDGND,
	USB_LINK_OTG_HOST_NO_CURRENT,
	USB_LINK_NOT_VALID_LINK,
	USB_LINK_HM_IDGND_V2 = 18,
};

/**
 * ab5500_usb_mode - Different states of ab usb_chip
 *
 * Used for USB cable plug-in state machine
 */
enum ab5500_usb_mode {
	USB_IDLE,
	USB_DEVICE,
	USB_HOST,
	USB_DEDICATED_CHG,
};
struct ab5500_usb {
	struct otg_transceiver otg;
	struct device *dev;
	int irq_num_id_rise;
	int irq_num_id_fall;
	int irq_num_vbus_rise;
	int irq_num_vbus_fall;
	int irq_num_link_status;
	unsigned vbus_draw;
	struct delayed_work dwork;
	struct work_struct phy_dis_work;
	unsigned long link_status_wait;
	int rev;
	int usb_cs_gpio;
	enum ab5500_usb_mode mode;
	struct clk *sysclk;
	struct regulator *v_ape;
	struct abx500_usbgpio_platform_data *usb_gpio;
};

static int ab5500_usb_irq_setup(struct platform_device *pdev,
				struct ab5500_usb *ab);
static int ab5500_usb_boot_detect(struct ab5500_usb *ab);
static int ab5500_usb_link_status_update(struct ab5500_usb *ab);

static void ab5500_usb_phy_enable(struct ab5500_usb *ab, bool sel_host);

static inline struct ab5500_usb *xceiv_to_ab(struct otg_transceiver *x)
{
	return container_of(x, struct ab5500_usb, otg);
}

/**
 * ab5500_usb_wd_workaround() - Kick the watch dog timer
 *
 * This function used to Kick the watch dog timer
 */
static void ab5500_usb_wd_workaround(struct ab5500_usb *ab)
{
	abx500_set_register_interruptible(ab->dev,
			AB5500_SYS_CTRL2_BLOCK,
			AB5500_MAIN_WDOG_CTRL_REG,
			AB5500_MAIN_WATCHDOG_ENABLE);

		udelay(AB5500_WATCHDOG_DELAY_US);

	abx500_set_register_interruptible(ab->dev,
			AB5500_SYS_CTRL2_BLOCK,
			AB5500_MAIN_WDOG_CTRL_REG,
			(AB5500_MAIN_WATCHDOG_ENABLE
			 | AB5500_MAIN_WATCHDOG_KICK));

		udelay(AB5500_WATCHDOG_DELAY_US);

	abx500_set_register_interruptible(ab->dev,
			AB5500_SYS_CTRL2_BLOCK,
			AB5500_MAIN_WDOG_CTRL_REG,
			AB5500_MAIN_WATCHDOG_DISABLE);

		udelay(AB5500_WATCHDOG_DELAY_US);
}

static void ab5500_usb_phy_enable(struct ab5500_usb *ab, bool sel_host)
{
	u8 bit;
	bit = sel_host ? AB5500_USB_HOST_ENABLE :
			AB5500_USB_DEVICE_ENABLE;

	wake_lock(&ab5500_musb_wakelock);
	ab->usb_gpio->enable();
	clk_enable(ab->sysclk);
	regulator_enable(ab->v_ape);

	abx500_set_register_interruptible(ab->dev,
			AB5500_BANK_USB,
			AB5500_USB_PHY_CTRL_REG,
			bit);
}

static void ab5500_usb_phy_disable(struct ab5500_usb *ab, bool sel_host)
{
	u8 bit;
	bit = sel_host ? AB5500_USB_HOST_ENABLE :
			AB5500_USB_DEVICE_ENABLE;

	abx500_set_register_interruptible(ab->dev,
			AB5500_BANK_USB,
			AB5500_USB_PHY_CTRL_REG,
			bit);

	/* Needed to disable the phy.*/
	ab5500_usb_wd_workaround(ab);

	regulator_disable(ab->v_ape);
	clk_disable(ab->sysclk);
	ab->usb_gpio->disable();

	wake_unlock(&ab5500_musb_wakelock);
}

#define ab5500_usb_peri_phy_en(ab)	ab5500_usb_phy_enable(ab, false)
#define ab5500_usb_peri_phy_dis(ab)	ab5500_usb_phy_disable(ab, false)
#define ab5500_usb_host_phy_en(ab)	ab5500_usb_phy_enable(ab, true)
#define ab5500_usb_host_phy_dis(ab)	ab5500_usb_phy_disable(ab, true)

/* Work created after an link status update handler*/
static int ab5500_usb_link_status_update(struct ab5500_usb *ab)
{
	u8 val = 0;
	int ret = 0;
	int gpioval = 0;
	enum ab8500_usb_link_status lsts;
	enum usb_xceiv_events event;

	(void)abx500_get_register_interruptible(ab->dev,
			AB5500_BANK_USB, AB5500_USB_LINE_STAT_REG, &val);

	lsts = (val >> 3) & 0x0F;

	switch (lsts) {

	case USB_LINK_STD_HOST_NC:
	case USB_LINK_STD_HOST_C_NS:
	case USB_LINK_STD_HOST_C_S:
	case USB_LINK_HOST_CHG_NM:
	case USB_LINK_HOST_CHG_HS:
	case USB_LINK_HOST_CHG_HS_CHIRP:
		if (ab->otg.gadget) {
			ab5500_usb_peri_phy_en(ab);
			ab->mode = USB_DEVICE;
		}
		gpio_set_value(ab->usb_cs_gpio, 1);
		event = USB_EVENT_VBUS;
		break;

	case USB_LINK_HM_IDGND:
		if (ab->rev == AB5500_2_0)
			break;

		/* enable usb chip Select */
		ret = gpio_direction_output(ab->usb_cs_gpio, gpioval);
		if (ret < 0) {
			dev_err(ab->dev, "usb_cs_gpio: gpio direction failed\n");
			gpio_free(ab->usb_cs_gpio);
			return ret;
		}
		gpio_set_value(ab->usb_cs_gpio, 1);

		ab5500_usb_host_phy_en(ab);

		break;

	case USB_LINK_HM_IDGND_V2:
		if (!(ab->rev == AB5500_2_0))
			break;

		/* enable usb chip Select */
		ret = gpio_direction_output(ab->usb_cs_gpio, gpioval);
		if (ret < 0) {
			dev_err(ab->dev, "usb_cs_gpio: gpio direction failed\n");
			gpio_free(ab->usb_cs_gpio);
			return ret;
		}
		gpio_set_value(ab->usb_cs_gpio, 1);

		ab5500_usb_host_phy_en(ab);

		break;
	default:
		break;
	}

	atomic_notifier_call_chain(&ab->otg.notifier, event, &ab->vbus_draw);

	return 0;
}

static void ab5500_usb_delayed_work(struct work_struct *work)
{
	struct delayed_work *dwork = to_delayed_work(work);
	struct ab5500_usb *ab = container_of(dwork, struct ab5500_usb, dwork);

	ab5500_usb_link_status_update(ab);
}

/**
 * This function is used to signal the completion of
 * USB Link status register update
 */
static irqreturn_t ab5500_usb_link_status_irq(int irq, void *data)
{
	struct ab5500_usb *ab = (struct ab5500_usb *) data;
	ab5500_usb_link_status_update(ab);

	return IRQ_HANDLED;
}

static irqreturn_t ab5500_usb_device_insert_irq(int irq, void *data)
{
	int ret = 0, val = 1;
	struct ab5500_usb *ab = (struct ab5500_usb *) data;
	ab->mode = USB_DEVICE;

	ab5500_usb_peri_phy_en(ab);
	/* enable usb chip Select */
	ret = gpio_direction_output(ab->usb_cs_gpio, val);
	if (ret < 0) {
		dev_err(ab->dev, "usb_cs_gpio: gpio direction failed\n");
		gpio_free(ab->usb_cs_gpio);
		return ret;
	}
	gpio_set_value(ab->usb_cs_gpio, 1);

	return IRQ_HANDLED;
}

/**
 * This function used to remove the voltage for USB ab->dev mode.
 */
static irqreturn_t ab5500_usb_device_disconnect_irq(int irq, void *data)
{
	struct ab5500_usb *ab = (struct ab5500_usb *) data;
	/* disable usb chip Select */
	gpio_set_value(ab->usb_cs_gpio, 0);
	ab5500_usb_peri_phy_dis(ab);
	return IRQ_HANDLED;
}

/**
 * ab5500_usb_host_disconnect_irq : work handler for host cable insert.
 * @work: work structure
 *
 * This function is used to handle the host cable insert work.
 */
static irqreturn_t ab5500_usb_host_disconnect_irq(int irq, void *data)
{
	struct ab5500_usb *ab = (struct ab5500_usb *) data;
	/* disable usb chip Select */
	gpio_set_value(ab->usb_cs_gpio, 0);
	ab5500_usb_host_phy_dis(ab);
	return IRQ_HANDLED;
}

static void ab5500_usb_irq_free(struct ab5500_usb *ab)
{
	if (ab->irq_num_id_rise)
		free_irq(ab->irq_num_id_rise, ab);

	if (ab->irq_num_id_fall)
		free_irq(ab->irq_num_id_fall, ab);

	if (ab->irq_num_vbus_rise)
		free_irq(ab->irq_num_vbus_rise, ab);

	if (ab->irq_num_vbus_fall)
		free_irq(ab->irq_num_vbus_fall, ab);

	if (ab->irq_num_link_status)
		free_irq(ab->irq_num_link_status, ab);
}

/**
 * ab5500_usb_irq_setup : register USB callback handlers for ab5500
 * @mode: value for mode.
 *
 * This function is used to register USB callback handlers for ab5500.
 */
static int ab5500_usb_irq_setup(struct platform_device *pdev,
				struct ab5500_usb *ab)
{
	int ret = 0;
	int irq, err;

	if (!ab->dev)
		return -EINVAL;

	irq = platform_get_irq_byname(pdev, "usb_idgnd_f");
	if (irq < 0) {
		dev_err(&pdev->dev, "ID fall irq not found\n");
		err = irq;
		goto irq_fail;
	}
	ab->irq_num_id_fall = irq;

	irq = platform_get_irq_byname(pdev, "VBUS_F");
	if (irq < 0) {
		dev_err(&pdev->dev, "VBUS fall irq not found\n");
		err = irq;
		goto irq_fail;

	}
	ab->irq_num_vbus_fall = irq;

	irq = platform_get_irq_byname(pdev, "VBUS_R");
	if (irq < 0) {
		dev_err(&pdev->dev, "VBUS raise irq not found\n");
		err = irq;
		goto irq_fail;

	}
	ab->irq_num_vbus_rise = irq;

	irq = platform_get_irq_byname(pdev, "Link_Update");
	if (irq < 0) {
		dev_err(&pdev->dev, "Link Update irq not found\n");
		err = irq;
		goto irq_fail;
	}
	ab->irq_num_link_status = irq;


	ret = request_threaded_irq(ab->irq_num_link_status,
		NULL, ab5500_usb_link_status_irq,
		IRQF_NO_SUSPEND | IRQF_SHARED,
		"usb-link-status-update", ab);
	if (ret < 0) {
		printk(KERN_ERR "failed to set the callback"
				" handler for usb charge"
				" detect done\n");
		err = ret;
		goto irq_fail;
	}

	ret = request_threaded_irq(ab->irq_num_vbus_rise, NULL,
		ab5500_usb_device_insert_irq,
		IRQF_NO_SUSPEND | IRQF_SHARED,
		"usb-vbus-rise", ab);
	if (ret < 0) {
		printk(KERN_ERR "failed to set the callback"
				" handler for usb ab->dev"
				" insertion\n");
		err = ret;
		goto irq_fail;
	}

	ret = request_threaded_irq(ab->irq_num_vbus_fall, NULL,
		ab5500_usb_device_disconnect_irq,
		IRQF_NO_SUSPEND | IRQF_SHARED,
		"usb-vbus-fall", ab);
	if (ret < 0) {
		printk(KERN_ERR "failed to set the callback"
				" handler for usb ab->dev"
				" removal\n");
		err = ret;
		goto irq_fail;
	}

	ret = request_threaded_irq((ab->irq_num_id_fall), NULL,
		ab5500_usb_host_disconnect_irq,
		IRQF_NO_SUSPEND | IRQF_SHARED,
		"usb-id-fall", ab);
	if (ret < 0) {
		printk(KERN_ERR "failed to set the callback"
				" handler for usb host"
				" removal\n");
		err = ret;
		goto irq_fail;
	}

	ab5500_usb_wd_workaround(ab);
	return 0;

irq_fail:
	ab5500_usb_irq_free(ab);
	return err;
}

/**
 * ab5500_usb_boot_detect : detect the USB cable during boot time.
 * @mode: value for mode.
 *
 * This function is used to detect the USB cable during boot time.
 */
static int ab5500_usb_boot_detect(struct ab5500_usb *ab)
{
	int ret;
	int val = 1;
	int usb_status = 0;
	int gpioval = 0;
	enum ab8500_usb_link_status lsts;
	if (!ab->dev)
		return -EINVAL;

	abx500_set_register_interruptible(ab->dev,
			AB5500_BANK_USB,
			AB5500_USB_PHY_CTRL_REG,
			AB5500_USB_DEVICE_ENABLE);

	udelay(AB5500_PHY_DELAY_US);

	abx500_set_register_interruptible(ab->dev,
			AB5500_BANK_USB,
			AB5500_USB_PHY_CTRL_REG,
			AB5500_USB_DEVICE_DISABLE);

	abx500_set_register_interruptible(ab->dev,
			AB5500_BANK_USB,
			AB5500_USB_PHY_CTRL_REG,
			AB5500_USB_HOST_ENABLE);

	udelay(AB5500_PHY_DELAY_US);

	abx500_set_register_interruptible(ab->dev,
			AB5500_BANK_USB,
			AB5500_USB_PHY_CTRL_REG,
			AB5500_USB_HOST_DISABLE);

	ab5500_usb_wd_workaround(ab);

	(void)abx500_get_register_interruptible(ab->dev,
			AB5500_BANK_USB, AB5500_USB_LINE_STAT_REG, &usb_status);

	lsts = (usb_status >> 3) & 0x0F;

	switch (lsts) {

	case USB_LINK_STD_HOST_NC:
	case USB_LINK_STD_HOST_C_NS:
	case USB_LINK_STD_HOST_C_S:
	case USB_LINK_HOST_CHG_NM:
	case USB_LINK_HOST_CHG_HS:
	case USB_LINK_HOST_CHG_HS_CHIRP:

		ab5500_usb_peri_phy_en(ab);

		/* enable usb chip Select */
		ret = gpio_direction_output(ab->usb_cs_gpio, val);
		if (ret < 0) {
			dev_err(ab->dev, "usb_cs_gpio: gpio direction failed\n");
			gpio_free(ab->usb_cs_gpio);
			return ret;
		}
		gpio_set_value(ab->usb_cs_gpio, 1);

		break;

	case USB_LINK_HM_IDGND:
	case USB_LINK_HM_IDGND_V2:
		/* enable usb chip Select */
		ret = gpio_direction_output(ab->usb_cs_gpio, gpioval);
		if (ret < 0) {
			dev_err(ab->dev, "usb_cs_gpio: gpio direction failed\n");
			gpio_free(ab->usb_cs_gpio);
			return ret;
		}
		gpio_set_value(ab->usb_cs_gpio, 1);
		ab5500_usb_host_phy_en(ab);

		break;
	default:
		break;
	}

	return 0;
}

static int ab5500_usb_set_power(struct otg_transceiver *otg, unsigned mA)
{
	struct ab5500_usb *ab;

	if (!otg)
		return -ENODEV;

	ab = xceiv_to_ab(otg);

	ab->vbus_draw = mA;

	atomic_notifier_call_chain(&ab->otg.notifier,
				USB_EVENT_VBUS, &ab->vbus_draw);
	return 0;
}

static int ab5500_usb_set_suspend(struct otg_transceiver *x, int suspend)
{
	/* TODO */
	return 0;
}

static int ab5500_usb_set_host(struct otg_transceiver *otg,
					struct usb_bus *host)
{
	struct ab5500_usb *ab;

	if (!otg)
		return -ENODEV;

	ab = xceiv_to_ab(otg);

	/* Some drivers call this function in atomic context.
	 * Do not update ab5500 registers directly till this
	 * is fixed.
	 */

	if (!host) {
		ab->otg.host = NULL;
		schedule_work(&ab->phy_dis_work);
	} else {
		ab->otg.host = host;
		/* Phy will not be enabled if cable is already
		 * plugged-in. Schedule to enable phy.
		 * Use same delay to avoid any race condition.
		 */
		schedule_delayed_work(&ab->dwork, ab->link_status_wait);
	}

	return 0;
}

static int ab5500_usb_set_peripheral(struct otg_transceiver *otg,
		struct usb_gadget *gadget)
{
	struct ab5500_usb *ab;

	if (!otg)
		return -ENODEV;

	ab = xceiv_to_ab(otg);

	/* Some drivers call this function in atomic context.
	 * Do not update ab5500 registers directly till this
	 * is fixed.
	 */

	if (!gadget) {
		ab->otg.gadget = NULL;
		schedule_work(&ab->phy_dis_work);
	} else {
		ab->otg.gadget = gadget;
		/* Phy will not be enabled if cable is already
		 * plugged-in. Schedule to enable phy.
		 * Use same delay to avoid any race condition.
		 */
		schedule_delayed_work(&ab->dwork, ab->link_status_wait);
	}

	return 0;
}

static int __devinit ab5500_usb_probe(struct platform_device *pdev)
{
	struct ab5500_usb	*ab;
	struct abx500_usbgpio_platform_data *usb_pdata =
				pdev->dev.platform_data;
	int err;
	int rev;
	int ret = -1;
	int irq;
	ab = kzalloc(sizeof *ab, GFP_KERNEL);
	if (!ab)
		return -ENOMEM;

	ab->dev			= &pdev->dev;
	ab->rev			= rev;
	ab->otg.dev		= ab->dev;
	ab->otg.label		= "ab5500";
	ab->otg.state		= OTG_STATE_B_IDLE;
	ab->otg.set_host	= ab5500_usb_set_host;
	ab->otg.set_peripheral	= ab5500_usb_set_peripheral;
	ab->otg.set_suspend	= ab5500_usb_set_suspend;
	ab->otg.set_power	= ab5500_usb_set_power;
	ab->usb_gpio		= usb_pdata;
	ab->mode			= USB_IDLE;

	platform_set_drvdata(pdev, ab);

	ATOMIC_INIT_NOTIFIER_HEAD(&ab->otg.notifier);

	/* v1: Wait for link status to become stable.
	 * all: Updates form set_host and set_peripheral as they are atomic.
	 */
	INIT_DELAYED_WORK(&ab->dwork, ab5500_usb_delayed_work);

	err = otg_set_transceiver(&ab->otg);
	if (err)
		dev_err(&pdev->dev, "Can't register transceiver\n");

	ab->usb_cs_gpio = ab->usb_gpio->usb_cs;

	ab->rev = abx500_get_chip_id(ab->dev);

	ab->sysclk = clk_get(ab->dev, "sysclk");
	if (IS_ERR(ab->sysclk)) {
		ret = PTR_ERR(ab->sysclk);
		ab->sysclk = NULL;
		return ret;
	}

	ab->v_ape = regulator_get(ab->dev, "v-ape");
	if (!ab->v_ape) {
		dev_err(ab->dev, "Could not get v-ape supply\n");

		return -EINVAL;
	}

	ab5500_usb_irq_setup(pdev, ab);

	ret = gpio_request(ab->usb_cs_gpio, "usb-cs");
	if (ret < 0)
		dev_err(&pdev->dev, "usb gpio request fail\n");

	/* Aquire GPIO alternate config struct for USB */
	err = ab->usb_gpio->get(ab->dev);
	if (err < 0)
		goto fail1;

	/*
	 * wake lock is acquired when usb cable is connected and released when
	 * cable is removed
	 */
	wake_lock_init(&ab5500_musb_wakelock, WAKE_LOCK_SUSPEND, "ab5500-usb");

	err = ab5500_usb_boot_detect(ab);
	if (err < 0)
		goto fail1;

	return 0;

fail1:
	ab5500_usb_irq_free(ab);
	kfree(ab);
	return err;
}

static int __devexit ab5500_usb_remove(struct platform_device *pdev)
{
	return 0;
}

static struct platform_driver ab5500_usb_driver = {
	.driver		= {
		.name	= "ab5500-usb",
		.owner	= THIS_MODULE,
	},
	.probe		= ab5500_usb_probe,
	.remove		= __devexit_p(ab5500_usb_remove),
};

static int __init ab5500_usb_init(void)
{
	return platform_driver_register(&ab5500_usb_driver);
}
subsys_initcall(ab5500_usb_init);

static void __exit ab5500_usb_exit(void)
{
	platform_driver_unregister(&ab5500_usb_driver);
}
module_exit(ab5500_usb_exit);

MODULE_LICENSE("GPL v2");