1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/interrupt.h>
27#include <linux/platform_device.h>
28#include <linux/gpio.h>
29#include <linux/usb/ch9.h>
30#include <linux/usb/gadget.h>
31#include <linux/usb.h>
32#include <linux/usb/otg.h>
33#include <linux/i2c.h>
34#include <linux/workqueue.h>
35
36#include <asm/irq.h>
37#include <asm/mach-types.h>
38
39#include <mach/mux.h>
40
41#include <mach/usb.h>
42
43#undef VERBOSE
44
45
46#define DRIVER_VERSION "24 August 2004"
47#define DRIVER_NAME (isp1301_driver.driver.name)
48
49MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver");
50MODULE_LICENSE("GPL");
51
52struct isp1301 {
53 struct usb_phy phy;
54 struct i2c_client *client;
55 void (*i2c_release)(struct device *dev);
56
57 int irq_type;
58
59 u32 last_otg_ctrl;
60 unsigned working:1;
61
62 struct timer_list timer;
63
64
65 struct work_struct work;
66
67 unsigned long todo;
68# define WORK_UPDATE_ISP 0
69# define WORK_UPDATE_OTG 1
70# define WORK_HOST_RESUME 4
71# define WORK_TIMER 6
72# define WORK_STOP 7
73};
74
75
76
77
78#define OTG_XCEIV_OUTPUTS \
79 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
80#define OTG_XCEIV_INPUTS \
81 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
82#define OTG_CTRL_BITS \
83 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
84
85
86#define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
87 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
88 OTG_CTRL_BITS)
89
90
91
92
93
94
95#if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3)
96
97#if IS_REACHABLE(CONFIG_TPS65010)
98
99#include <linux/i2c/tps65010.h>
100
101#else
102
103static inline int tps65010_set_vbus_draw(unsigned mA)
104{
105 pr_debug("tps65010: draw %d mA (STUB)\n", mA);
106 return 0;
107}
108
109#endif
110
111static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
112{
113 int status = tps65010_set_vbus_draw(mA);
114 if (status < 0)
115 pr_debug(" VBUS %d mA error %d\n", mA, status);
116}
117
118#else
119
120static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
121{
122
123
124
125
126}
127
128#endif
129
130static void enable_vbus_source(struct isp1301 *isp)
131{
132
133
134
135}
136
137
138
139static inline void notresponding(struct isp1301 *isp)
140{
141 printk(KERN_NOTICE "OTG device not responding.\n");
142}
143
144
145
146
147static struct i2c_driver isp1301_driver;
148
149
150
151static inline u8
152isp1301_get_u8(struct isp1301 *isp, u8 reg)
153{
154 return i2c_smbus_read_byte_data(isp->client, reg + 0);
155}
156
157static inline int
158isp1301_get_u16(struct isp1301 *isp, u8 reg)
159{
160 return i2c_smbus_read_word_data(isp->client, reg);
161}
162
163static inline int
164isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
165{
166 return i2c_smbus_write_byte_data(isp->client, reg + 0, bits);
167}
168
169static inline int
170isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
171{
172 return i2c_smbus_write_byte_data(isp->client, reg + 1, bits);
173}
174
175
176
177
178#define ISP1301_VENDOR_ID 0x00
179#define ISP1301_PRODUCT_ID 0x02
180#define ISP1301_BCD_DEVICE 0x14
181
182#define I2C_VENDOR_ID_PHILIPS 0x04cc
183#define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
184
185
186#define ISP1301_MODE_CONTROL_1 0x04
187# define MC1_SPEED (1 << 0)
188# define MC1_SUSPEND (1 << 1)
189# define MC1_DAT_SE0 (1 << 2)
190# define MC1_TRANSPARENT (1 << 3)
191# define MC1_BDIS_ACON_EN (1 << 4)
192# define MC1_OE_INT_EN (1 << 5)
193# define MC1_UART_EN (1 << 6)
194# define MC1_MASK 0x7f
195#define ISP1301_MODE_CONTROL_2 0x12
196# define MC2_GLOBAL_PWR_DN (1 << 0)
197# define MC2_SPD_SUSP_CTRL (1 << 1)
198# define MC2_BI_DI (1 << 2)
199# define MC2_TRANSP_BDIR0 (1 << 3)
200# define MC2_TRANSP_BDIR1 (1 << 4)
201# define MC2_AUDIO_EN (1 << 5)
202# define MC2_PSW_EN (1 << 6)
203# define MC2_EN2V7 (1 << 7)
204#define ISP1301_OTG_CONTROL_1 0x06
205# define OTG1_DP_PULLUP (1 << 0)
206# define OTG1_DM_PULLUP (1 << 1)
207# define OTG1_DP_PULLDOWN (1 << 2)
208# define OTG1_DM_PULLDOWN (1 << 3)
209# define OTG1_ID_PULLDOWN (1 << 4)
210# define OTG1_VBUS_DRV (1 << 5)
211# define OTG1_VBUS_DISCHRG (1 << 6)
212# define OTG1_VBUS_CHRG (1 << 7)
213#define ISP1301_OTG_STATUS 0x10
214# define OTG_B_SESS_END (1 << 6)
215# define OTG_B_SESS_VLD (1 << 7)
216
217#define ISP1301_INTERRUPT_SOURCE 0x08
218#define ISP1301_INTERRUPT_LATCH 0x0A
219
220#define ISP1301_INTERRUPT_FALLING 0x0C
221#define ISP1301_INTERRUPT_RISING 0x0E
222
223
224# define INTR_VBUS_VLD (1 << 0)
225# define INTR_SESS_VLD (1 << 1)
226# define INTR_DP_HI (1 << 2)
227# define INTR_ID_GND (1 << 3)
228# define INTR_DM_HI (1 << 4)
229# define INTR_ID_FLOAT (1 << 5)
230# define INTR_BDIS_ACON (1 << 6)
231# define INTR_CR_INT (1 << 7)
232
233
234
235static inline const char *state_name(struct isp1301 *isp)
236{
237 return usb_otg_state_string(isp->phy.otg->state);
238}
239
240
241
242
243
244
245
246
247
248
249
250static void power_down(struct isp1301 *isp)
251{
252 isp->phy.otg->state = OTG_STATE_UNDEFINED;
253
254
255 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
256
257 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN);
258 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
259}
260
261static void __maybe_unused power_up(struct isp1301 *isp)
262{
263
264 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
265
266
267
268
269 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
270}
271
272#define NO_HOST_SUSPEND
273
274static int host_suspend(struct isp1301 *isp)
275{
276#ifdef NO_HOST_SUSPEND
277 return 0;
278#else
279 struct device *dev;
280
281 if (!isp->phy.otg->host)
282 return -ENODEV;
283
284
285
286
287 dev = isp->phy.otg->host->controller;
288 return dev->driver->suspend(dev, 3, 0);
289#endif
290}
291
292static int host_resume(struct isp1301 *isp)
293{
294#ifdef NO_HOST_SUSPEND
295 return 0;
296#else
297 struct device *dev;
298
299 if (!isp->phy.otg->host)
300 return -ENODEV;
301
302 dev = isp->phy.otg->host->controller;
303 return dev->driver->resume(dev, 0);
304#endif
305}
306
307static int gadget_suspend(struct isp1301 *isp)
308{
309 isp->phy.otg->gadget->b_hnp_enable = 0;
310 isp->phy.otg->gadget->a_hnp_support = 0;
311 isp->phy.otg->gadget->a_alt_hnp_support = 0;
312 return usb_gadget_vbus_disconnect(isp->phy.otg->gadget);
313}
314
315
316
317#define TIMER_MINUTES 10
318#define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
319
320
321
322
323
324static void isp1301_defer_work(struct isp1301 *isp, int work)
325{
326 int status;
327
328 if (isp && !test_and_set_bit(work, &isp->todo)) {
329 (void) get_device(&isp->client->dev);
330 status = schedule_work(&isp->work);
331 if (!status && !isp->working)
332 dev_vdbg(&isp->client->dev,
333 "work item %d may be lost\n", work);
334 }
335}
336
337
338static void a_idle(struct isp1301 *isp, const char *tag)
339{
340 u32 l;
341
342 if (isp->phy.otg->state == OTG_STATE_A_IDLE)
343 return;
344
345 isp->phy.otg->default_a = 1;
346 if (isp->phy.otg->host) {
347 isp->phy.otg->host->is_b_host = 0;
348 host_suspend(isp);
349 }
350 if (isp->phy.otg->gadget) {
351 isp->phy.otg->gadget->is_a_peripheral = 1;
352 gadget_suspend(isp);
353 }
354 isp->phy.otg->state = OTG_STATE_A_IDLE;
355 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
356 omap_writel(l, OTG_CTRL);
357 isp->last_otg_ctrl = l;
358 pr_debug(" --> %s/%s\n", state_name(isp), tag);
359}
360
361
362static void b_idle(struct isp1301 *isp, const char *tag)
363{
364 u32 l;
365
366 if (isp->phy.otg->state == OTG_STATE_B_IDLE)
367 return;
368
369 isp->phy.otg->default_a = 0;
370 if (isp->phy.otg->host) {
371 isp->phy.otg->host->is_b_host = 1;
372 host_suspend(isp);
373 }
374 if (isp->phy.otg->gadget) {
375 isp->phy.otg->gadget->is_a_peripheral = 0;
376 gadget_suspend(isp);
377 }
378 isp->phy.otg->state = OTG_STATE_B_IDLE;
379 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
380 omap_writel(l, OTG_CTRL);
381 isp->last_otg_ctrl = l;
382 pr_debug(" --> %s/%s\n", state_name(isp), tag);
383}
384
385static void
386dump_regs(struct isp1301 *isp, const char *label)
387{
388 u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1);
389 u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
390 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
391
392 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
393 omap_readl(OTG_CTRL), label, state_name(isp),
394 ctrl, status, src);
395
396}
397
398
399
400#ifdef CONFIG_USB_OTG
401
402
403
404
405
406
407
408
409
410#ifdef VERBOSE
411
412static void check_state(struct isp1301 *isp, const char *tag)
413{
414 enum usb_otg_state state = OTG_STATE_UNDEFINED;
415 u8 fsm = omap_readw(OTG_TEST) & 0x0ff;
416 unsigned extra = 0;
417
418 switch (fsm) {
419
420
421 case 0x0:
422 state = OTG_STATE_B_IDLE;
423 break;
424 case 0x3:
425 case 0x7:
426 extra = 1;
427 case 0x1:
428 state = OTG_STATE_B_PERIPHERAL;
429 break;
430 case 0x11:
431 state = OTG_STATE_B_SRP_INIT;
432 break;
433
434
435 case 0x12:
436 case 0x13:
437 case 0x16:
438 extra = 1;
439 case 0x17:
440 state = OTG_STATE_B_WAIT_ACON;
441 break;
442 case 0x34:
443 state = OTG_STATE_B_HOST;
444 break;
445
446
447 case 0x36:
448 state = OTG_STATE_A_IDLE;
449 break;
450 case 0x3c:
451 state = OTG_STATE_A_WAIT_VFALL;
452 break;
453 case 0x7d:
454 state = OTG_STATE_A_VBUS_ERR;
455 break;
456 case 0x9e:
457 case 0x9f:
458 extra = 1;
459 case 0x89:
460 state = OTG_STATE_A_PERIPHERAL;
461 break;
462 case 0xb7:
463 state = OTG_STATE_A_WAIT_VRISE;
464 break;
465 case 0xb8:
466 state = OTG_STATE_A_WAIT_BCON;
467 break;
468 case 0xb9:
469 state = OTG_STATE_A_HOST;
470 break;
471 case 0xba:
472 state = OTG_STATE_A_SUSPEND;
473 break;
474 default:
475 break;
476 }
477 if (isp->phy.otg->state == state && !extra)
478 return;
479 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
480 usb_otg_state_string(state), fsm, state_name(isp),
481 omap_readl(OTG_CTRL));
482}
483
484#else
485
486static inline void check_state(struct isp1301 *isp, const char *tag) { }
487
488#endif
489
490
491static void update_otg1(struct isp1301 *isp, u8 int_src)
492{
493 u32 otg_ctrl;
494
495 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
496 otg_ctrl &= ~OTG_XCEIV_INPUTS;
497 otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
498
499 if (int_src & INTR_SESS_VLD)
500 otg_ctrl |= OTG_ASESSVLD;
501 else if (isp->phy.otg->state == OTG_STATE_A_WAIT_VFALL) {
502 a_idle(isp, "vfall");
503 otg_ctrl &= ~OTG_CTRL_BITS;
504 }
505 if (int_src & INTR_VBUS_VLD)
506 otg_ctrl |= OTG_VBUSVLD;
507 if (int_src & INTR_ID_GND) {
508 if (isp->phy.otg->state == OTG_STATE_B_IDLE
509 || isp->phy.otg->state
510 == OTG_STATE_UNDEFINED) {
511 a_idle(isp, "init");
512 return;
513 }
514 } else {
515 otg_ctrl |= OTG_ID;
516 if (isp->phy.otg->state == OTG_STATE_A_IDLE
517 || isp->phy.otg->state == OTG_STATE_UNDEFINED) {
518 b_idle(isp, "init");
519 return;
520 }
521 }
522 omap_writel(otg_ctrl, OTG_CTRL);
523}
524
525
526static void update_otg2(struct isp1301 *isp, u8 otg_status)
527{
528 u32 otg_ctrl;
529
530 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
531 otg_ctrl &= ~OTG_XCEIV_INPUTS;
532 otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND);
533 if (otg_status & OTG_B_SESS_VLD)
534 otg_ctrl |= OTG_BSESSVLD;
535 else if (otg_status & OTG_B_SESS_END)
536 otg_ctrl |= OTG_BSESSEND;
537 omap_writel(otg_ctrl, OTG_CTRL);
538}
539
540
541static void otg_update_isp(struct isp1301 *isp)
542{
543 u32 otg_ctrl, otg_change;
544 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
545
546 otg_ctrl = omap_readl(OTG_CTRL);
547 otg_change = otg_ctrl ^ isp->last_otg_ctrl;
548 isp->last_otg_ctrl = otg_ctrl;
549 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
550
551 switch (isp->phy.otg->state) {
552 case OTG_STATE_B_IDLE:
553 case OTG_STATE_B_PERIPHERAL:
554 case OTG_STATE_B_SRP_INIT:
555 if (!(otg_ctrl & OTG_PULLUP)) {
556
557 if (isp->phy.otg->gadget->b_hnp_enable) {
558 isp->phy.otg->state = OTG_STATE_B_WAIT_ACON;
559 pr_debug(" --> b_wait_acon\n");
560 }
561 goto pulldown;
562 }
563pullup:
564 set |= OTG1_DP_PULLUP;
565 clr |= OTG1_DP_PULLDOWN;
566 break;
567 case OTG_STATE_A_SUSPEND:
568 case OTG_STATE_A_PERIPHERAL:
569 if (otg_ctrl & OTG_PULLUP)
570 goto pullup;
571
572
573 default:
574pulldown:
575 set |= OTG1_DP_PULLDOWN;
576 clr |= OTG1_DP_PULLUP;
577 break;
578 }
579
580# define toggle(OTG,ISP) do { \
581 if (otg_ctrl & OTG) set |= ISP; \
582 else clr |= ISP; \
583 } while (0)
584
585 if (!(isp->phy.otg->host))
586 otg_ctrl &= ~OTG_DRV_VBUS;
587
588 switch (isp->phy.otg->state) {
589 case OTG_STATE_A_SUSPEND:
590 if (otg_ctrl & OTG_DRV_VBUS) {
591 set |= OTG1_VBUS_DRV;
592 break;
593 }
594
595 notresponding(isp);
596
597
598 case OTG_STATE_A_VBUS_ERR:
599 isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL;
600 pr_debug(" --> a_wait_vfall\n");
601
602 case OTG_STATE_A_WAIT_VFALL:
603
604 clr |= OTG1_VBUS_DRV;
605 break;
606 case OTG_STATE_A_IDLE:
607 if (otg_ctrl & OTG_DRV_VBUS) {
608 isp->phy.otg->state = OTG_STATE_A_WAIT_VRISE;
609 pr_debug(" --> a_wait_vrise\n");
610 }
611
612 default:
613 toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV);
614 }
615
616 toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG);
617 toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG);
618
619# undef toggle
620
621 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set);
622 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr);
623
624
625 if (otg_change & OTG_PULLUP) {
626 u32 l;
627
628 switch (isp->phy.otg->state) {
629 case OTG_STATE_B_IDLE:
630 if (clr & OTG1_DP_PULLUP)
631 break;
632 isp->phy.otg->state = OTG_STATE_B_PERIPHERAL;
633 pr_debug(" --> b_peripheral\n");
634 break;
635 case OTG_STATE_A_SUSPEND:
636 if (clr & OTG1_DP_PULLUP)
637 break;
638 isp->phy.otg->state = OTG_STATE_A_PERIPHERAL;
639 pr_debug(" --> a_peripheral\n");
640 break;
641 default:
642 break;
643 }
644 l = omap_readl(OTG_CTRL);
645 l |= OTG_PULLUP;
646 omap_writel(l, OTG_CTRL);
647 }
648
649 check_state(isp, __func__);
650 dump_regs(isp, "otg->isp1301");
651}
652
653static irqreturn_t omap_otg_irq(int irq, void *_isp)
654{
655 u16 otg_irq = omap_readw(OTG_IRQ_SRC);
656 u32 otg_ctrl;
657 int ret = IRQ_NONE;
658 struct isp1301 *isp = _isp;
659 struct usb_otg *otg = isp->phy.otg;
660
661
662 if (otg_irq & OPRT_CHG) {
663 omap_writew(OPRT_CHG, OTG_IRQ_SRC);
664 isp1301_defer_work(isp, WORK_UPDATE_ISP);
665 ret = IRQ_HANDLED;
666
667
668 } else if (otg_irq & B_SRP_TMROUT) {
669 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL));
670 notresponding(isp);
671
672
673
674
675
676 if (isp->phy.otg->state == OTG_STATE_B_SRP_INIT)
677 b_idle(isp, "srp_timeout");
678
679 omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
680 ret = IRQ_HANDLED;
681
682
683 } else if (otg_irq & B_HNP_FAIL) {
684 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
685 state_name(isp), omap_readl(OTG_CTRL));
686 notresponding(isp);
687
688 otg_ctrl = omap_readl(OTG_CTRL);
689 otg_ctrl |= OTG_BUSDROP;
690 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
691 omap_writel(otg_ctrl, OTG_CTRL);
692
693
694 isp->phy.otg->state = OTG_STATE_B_PERIPHERAL;
695 pr_debug(" --> b_peripheral\n");
696
697 omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
698 ret = IRQ_HANDLED;
699
700
701 } else if (otg_irq & A_SRP_DETECT) {
702 pr_debug("otg: %s SRP_DETECT, %06x\n",
703 state_name(isp), omap_readl(OTG_CTRL));
704
705 isp1301_defer_work(isp, WORK_UPDATE_OTG);
706 switch (isp->phy.otg->state) {
707 case OTG_STATE_A_IDLE:
708 if (!otg->host)
709 break;
710 isp1301_defer_work(isp, WORK_HOST_RESUME);
711 otg_ctrl = omap_readl(OTG_CTRL);
712 otg_ctrl |= OTG_A_BUSREQ;
713 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
714 & ~OTG_XCEIV_INPUTS
715 & OTG_CTRL_MASK;
716 omap_writel(otg_ctrl, OTG_CTRL);
717 break;
718 default:
719 break;
720 }
721
722 omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
723 ret = IRQ_HANDLED;
724
725
726
727
728 } else if (otg_irq & A_REQ_TMROUT) {
729 otg_ctrl = omap_readl(OTG_CTRL);
730 pr_info("otg: BCON_TMOUT from %s, %06x\n",
731 state_name(isp), otg_ctrl);
732 notresponding(isp);
733
734 otg_ctrl |= OTG_BUSDROP;
735 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
736 omap_writel(otg_ctrl, OTG_CTRL);
737 isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL;
738
739 omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
740 ret = IRQ_HANDLED;
741
742
743 } else if (otg_irq & A_VBUS_ERR) {
744 otg_ctrl = omap_readl(OTG_CTRL);
745 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
746 state_name(isp), otg_irq, otg_ctrl);
747
748 otg_ctrl |= OTG_BUSDROP;
749 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
750 omap_writel(otg_ctrl, OTG_CTRL);
751 isp->phy.otg->state = OTG_STATE_A_VBUS_ERR;
752
753 omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
754 ret = IRQ_HANDLED;
755
756
757
758
759 } else if (otg_irq & DRIVER_SWITCH) {
760 int kick = 0;
761
762 otg_ctrl = omap_readl(OTG_CTRL);
763 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
764 state_name(isp),
765 (otg_ctrl & OTG_DRIVER_SEL)
766 ? "gadget" : "host",
767 otg_ctrl);
768 isp1301_defer_work(isp, WORK_UPDATE_ISP);
769
770
771 if (otg_ctrl & OTG_DRIVER_SEL) {
772 switch (isp->phy.otg->state) {
773 case OTG_STATE_A_IDLE:
774 b_idle(isp, __func__);
775 break;
776 default:
777 break;
778 }
779 isp1301_defer_work(isp, WORK_UPDATE_ISP);
780
781
782 } else {
783 if (!(otg_ctrl & OTG_ID)) {
784 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
785 omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL);
786 }
787
788 if (otg->host) {
789 switch (isp->phy.otg->state) {
790 case OTG_STATE_B_WAIT_ACON:
791 isp->phy.otg->state = OTG_STATE_B_HOST;
792 pr_debug(" --> b_host\n");
793 kick = 1;
794 break;
795 case OTG_STATE_A_WAIT_BCON:
796 isp->phy.otg->state = OTG_STATE_A_HOST;
797 pr_debug(" --> a_host\n");
798 break;
799 case OTG_STATE_A_PERIPHERAL:
800 isp->phy.otg->state = OTG_STATE_A_WAIT_BCON;
801 pr_debug(" --> a_wait_bcon\n");
802 break;
803 default:
804 break;
805 }
806 isp1301_defer_work(isp, WORK_HOST_RESUME);
807 }
808 }
809
810 omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
811 ret = IRQ_HANDLED;
812
813 if (kick)
814 usb_bus_start_enum(otg->host, otg->host->otg_port);
815 }
816
817 check_state(isp, __func__);
818 return ret;
819}
820
821static struct platform_device *otg_dev;
822
823static int isp1301_otg_init(struct isp1301 *isp)
824{
825 u32 l;
826
827 if (!otg_dev)
828 return -ENODEV;
829
830 dump_regs(isp, __func__);
831
832 l = omap_readl(OTG_SYSCON_2);
833 l |= OTG_EN
834
835 | SRP_GPDATA
836 | SRP_GPDVBUS
837
838
839 | (0 << 20)
840 | SRP_DPW
841 | SRP_DATA | SRP_VBUS
842 ;
843 omap_writel(l, OTG_SYSCON_2);
844
845 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
846 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
847
848 check_state(isp, __func__);
849 pr_debug("otg: %s, %s %06x\n",
850 state_name(isp), __func__, omap_readl(OTG_CTRL));
851
852 omap_writew(DRIVER_SWITCH | OPRT_CHG
853 | B_SRP_TMROUT | B_HNP_FAIL
854 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN);
855
856 l = omap_readl(OTG_SYSCON_2);
857 l |= OTG_EN;
858 omap_writel(l, OTG_SYSCON_2);
859
860 return 0;
861}
862
863static int otg_probe(struct platform_device *dev)
864{
865
866
867 otg_dev = dev;
868 return 0;
869}
870
871static int otg_remove(struct platform_device *dev)
872{
873 otg_dev = NULL;
874 return 0;
875}
876
877static struct platform_driver omap_otg_driver = {
878 .probe = otg_probe,
879 .remove = otg_remove,
880 .driver = {
881 .name = "omap_otg",
882 },
883};
884
885static int otg_bind(struct isp1301 *isp)
886{
887 int status;
888
889 if (otg_dev)
890 return -EBUSY;
891
892 status = platform_driver_register(&omap_otg_driver);
893 if (status < 0)
894 return status;
895
896 if (otg_dev)
897 status = request_irq(otg_dev->resource[1].start, omap_otg_irq,
898 0, DRIVER_NAME, isp);
899 else
900 status = -ENODEV;
901
902 if (status < 0)
903 platform_driver_unregister(&omap_otg_driver);
904 return status;
905}
906
907static void otg_unbind(struct isp1301 *isp)
908{
909 if (!otg_dev)
910 return;
911 free_irq(otg_dev->resource[1].start, isp);
912}
913
914#else
915
916
917
918#endif
919
920
921
922static void b_peripheral(struct isp1301 *isp)
923{
924 u32 l;
925
926 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
927 omap_writel(l, OTG_CTRL);
928
929 usb_gadget_vbus_connect(isp->phy.otg->gadget);
930
931#ifdef CONFIG_USB_OTG
932 enable_vbus_draw(isp, 8);
933 otg_update_isp(isp);
934#else
935 enable_vbus_draw(isp, 100);
936
937 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP);
938 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN);
939 isp->phy.otg->state = OTG_STATE_B_PERIPHERAL;
940 pr_debug(" --> b_peripheral\n");
941 dump_regs(isp, "2periph");
942#endif
943}
944
945static void isp_update_otg(struct isp1301 *isp, u8 stat)
946{
947 struct usb_otg *otg = isp->phy.otg;
948 u8 isp_stat, isp_bstat;
949 enum usb_otg_state state = isp->phy.otg->state;
950
951 if (stat & INTR_BDIS_ACON)
952 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp));
953
954
955 isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
956 if (isp_stat & INTR_ID_GND) {
957 if (otg->default_a) {
958 switch (state) {
959 case OTG_STATE_B_IDLE:
960 a_idle(isp, "idle");
961
962 case OTG_STATE_A_IDLE:
963 enable_vbus_source(isp);
964
965 case OTG_STATE_A_WAIT_VRISE:
966
967
968
969
970
971 if (isp_stat & INTR_VBUS_VLD)
972 isp->phy.otg->state = OTG_STATE_A_HOST;
973 break;
974 case OTG_STATE_A_WAIT_VFALL:
975 if (!(isp_stat & INTR_SESS_VLD))
976 a_idle(isp, "vfell");
977 break;
978 default:
979 if (!(isp_stat & INTR_VBUS_VLD))
980 isp->phy.otg->state = OTG_STATE_A_VBUS_ERR;
981 break;
982 }
983 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
984 } else {
985 switch (state) {
986 case OTG_STATE_B_PERIPHERAL:
987 case OTG_STATE_B_HOST:
988 case OTG_STATE_B_WAIT_ACON:
989 usb_gadget_vbus_disconnect(otg->gadget);
990 break;
991 default:
992 break;
993 }
994 if (state != OTG_STATE_A_IDLE)
995 a_idle(isp, "id");
996 if (otg->host && state == OTG_STATE_A_IDLE)
997 isp1301_defer_work(isp, WORK_HOST_RESUME);
998 isp_bstat = 0;
999 }
1000 } else {
1001 u32 l;
1002
1003
1004
1005
1006 if (otg->default_a) {
1007 switch (state) {
1008 default:
1009 isp->phy.otg->state = OTG_STATE_A_WAIT_VFALL;
1010 break;
1011 case OTG_STATE_A_WAIT_VFALL:
1012 state = OTG_STATE_A_IDLE;
1013
1014
1015
1016
1017 break;
1018 case OTG_STATE_A_IDLE:
1019 host_suspend(isp);
1020 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
1021 MC1_BDIS_ACON_EN);
1022 isp->phy.otg->state = OTG_STATE_B_IDLE;
1023 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1024 l &= ~OTG_CTRL_BITS;
1025 omap_writel(l, OTG_CTRL);
1026 break;
1027 case OTG_STATE_B_IDLE:
1028 break;
1029 }
1030 }
1031 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1032
1033 switch (isp->phy.otg->state) {
1034 case OTG_STATE_B_PERIPHERAL:
1035 case OTG_STATE_B_WAIT_ACON:
1036 case OTG_STATE_B_HOST:
1037 if (likely(isp_bstat & OTG_B_SESS_VLD))
1038 break;
1039 enable_vbus_draw(isp, 0);
1040#ifndef CONFIG_USB_OTG
1041
1042 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1043 OTG1_DP_PULLDOWN);
1044 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1045 OTG1_DP_PULLUP);
1046 dump_regs(isp, __func__);
1047#endif
1048
1049 case OTG_STATE_B_SRP_INIT:
1050 b_idle(isp, __func__);
1051 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
1052 omap_writel(l, OTG_CTRL);
1053
1054 case OTG_STATE_B_IDLE:
1055 if (otg->gadget && (isp_bstat & OTG_B_SESS_VLD)) {
1056#ifdef CONFIG_USB_OTG
1057 update_otg1(isp, isp_stat);
1058 update_otg2(isp, isp_bstat);
1059#endif
1060 b_peripheral(isp);
1061 } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD)))
1062 isp_bstat |= OTG_B_SESS_END;
1063 break;
1064 case OTG_STATE_A_WAIT_VFALL:
1065 break;
1066 default:
1067 pr_debug("otg: unsupported b-device %s\n",
1068 state_name(isp));
1069 break;
1070 }
1071 }
1072
1073 if (state != isp->phy.otg->state)
1074 pr_debug(" isp, %s -> %s\n",
1075 usb_otg_state_string(state), state_name(isp));
1076
1077#ifdef CONFIG_USB_OTG
1078
1079
1080
1081 update_otg1(isp, isp_stat);
1082 update_otg2(isp, isp_bstat);
1083 check_state(isp, __func__);
1084#endif
1085
1086 dump_regs(isp, "isp1301->otg");
1087}
1088
1089
1090
1091static u8 isp1301_clear_latch(struct isp1301 *isp)
1092{
1093 u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH);
1094 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch);
1095 return latch;
1096}
1097
1098static void
1099isp1301_work(struct work_struct *work)
1100{
1101 struct isp1301 *isp = container_of(work, struct isp1301, work);
1102 int stop;
1103
1104
1105 isp->working = 1;
1106 do {
1107 stop = test_bit(WORK_STOP, &isp->todo);
1108
1109#ifdef CONFIG_USB_OTG
1110
1111 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1112 otg_update_isp(isp);
1113 put_device(&isp->client->dev);
1114 }
1115#endif
1116
1117 if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) {
1118 u8 stat = isp1301_clear_latch(isp);
1119
1120 isp_update_otg(isp, stat);
1121 put_device(&isp->client->dev);
1122 }
1123
1124 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
1125 u32 otg_ctrl;
1126
1127
1128
1129
1130
1131 switch (isp->phy.otg->state) {
1132 case OTG_STATE_A_WAIT_BCON:
1133 case OTG_STATE_A_WAIT_VRISE:
1134 isp->phy.otg->state = OTG_STATE_A_HOST;
1135 pr_debug(" --> a_host\n");
1136 otg_ctrl = omap_readl(OTG_CTRL);
1137 otg_ctrl |= OTG_A_BUSREQ;
1138 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
1139 & OTG_CTRL_MASK;
1140 omap_writel(otg_ctrl, OTG_CTRL);
1141 break;
1142 case OTG_STATE_B_WAIT_ACON:
1143 isp->phy.otg->state = OTG_STATE_B_HOST;
1144 pr_debug(" --> b_host (acon)\n");
1145 break;
1146 case OTG_STATE_B_HOST:
1147 case OTG_STATE_B_IDLE:
1148 case OTG_STATE_A_IDLE:
1149 break;
1150 default:
1151 pr_debug(" host resume in %s\n",
1152 state_name(isp));
1153 }
1154 host_resume(isp);
1155
1156 put_device(&isp->client->dev);
1157 }
1158
1159 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
1160#ifdef VERBOSE
1161 dump_regs(isp, "timer");
1162 if (!stop)
1163 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1164#endif
1165 put_device(&isp->client->dev);
1166 }
1167
1168 if (isp->todo)
1169 dev_vdbg(&isp->client->dev,
1170 "work done, todo = 0x%lx\n",
1171 isp->todo);
1172 if (stop) {
1173 dev_dbg(&isp->client->dev, "stop\n");
1174 break;
1175 }
1176 } while (isp->todo);
1177 isp->working = 0;
1178}
1179
1180static irqreturn_t isp1301_irq(int irq, void *isp)
1181{
1182 isp1301_defer_work(isp, WORK_UPDATE_OTG);
1183 return IRQ_HANDLED;
1184}
1185
1186static void isp1301_timer(unsigned long _isp)
1187{
1188 isp1301_defer_work((void *)_isp, WORK_TIMER);
1189}
1190
1191
1192
1193static void isp1301_release(struct device *dev)
1194{
1195 struct isp1301 *isp;
1196
1197 isp = dev_get_drvdata(dev);
1198
1199
1200
1201
1202 if (isp->i2c_release)
1203 isp->i2c_release(dev);
1204 kfree(isp->phy.otg);
1205 kfree (isp);
1206}
1207
1208static struct isp1301 *the_transceiver;
1209
1210static int isp1301_remove(struct i2c_client *i2c)
1211{
1212 struct isp1301 *isp;
1213
1214 isp = i2c_get_clientdata(i2c);
1215
1216 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1217 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1218 free_irq(i2c->irq, isp);
1219#ifdef CONFIG_USB_OTG
1220 otg_unbind(isp);
1221#endif
1222 if (machine_is_omap_h2())
1223 gpio_free(2);
1224
1225 isp->timer.data = 0;
1226 set_bit(WORK_STOP, &isp->todo);
1227 del_timer_sync(&isp->timer);
1228 flush_work(&isp->work);
1229
1230 put_device(&i2c->dev);
1231 the_transceiver = NULL;
1232
1233 return 0;
1234}
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251#ifdef CONFIG_USB_OTG
1252
1253static int isp1301_otg_enable(struct isp1301 *isp)
1254{
1255 power_up(isp);
1256 isp1301_otg_init(isp);
1257
1258
1259
1260
1261 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1262 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1263 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1264 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1265
1266 dev_info(&isp->client->dev, "ready for dual-role USB ...\n");
1267
1268 return 0;
1269}
1270
1271#endif
1272
1273
1274static int
1275isp1301_set_host(struct usb_otg *otg, struct usb_bus *host)
1276{
1277 struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy);
1278
1279 if (isp != the_transceiver)
1280 return -ENODEV;
1281
1282 if (!host) {
1283 omap_writew(0, OTG_IRQ_EN);
1284 power_down(isp);
1285 otg->host = NULL;
1286 return 0;
1287 }
1288
1289#ifdef CONFIG_USB_OTG
1290 otg->host = host;
1291 dev_dbg(&isp->client->dev, "registered host\n");
1292 host_suspend(isp);
1293 if (otg->gadget)
1294 return isp1301_otg_enable(isp);
1295 return 0;
1296
1297#elif !IS_ENABLED(CONFIG_USB_OMAP)
1298
1299 otg->host = host;
1300
1301 power_up(isp);
1302
1303 if (machine_is_omap_h2())
1304 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1305
1306 dev_info(&isp->client->dev, "A-Host sessions ok\n");
1307 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1308 INTR_ID_GND);
1309 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1310 INTR_ID_GND);
1311
1312
1313
1314
1315
1316
1317 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV);
1318
1319 dump_regs(isp, __func__);
1320
1321 return 0;
1322
1323#else
1324 dev_dbg(&isp->client->dev, "host sessions not allowed\n");
1325 return -EINVAL;
1326#endif
1327
1328}
1329
1330static int
1331isp1301_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
1332{
1333 struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy);
1334
1335 if (isp != the_transceiver)
1336 return -ENODEV;
1337
1338 if (!gadget) {
1339 omap_writew(0, OTG_IRQ_EN);
1340 if (!otg->default_a)
1341 enable_vbus_draw(isp, 0);
1342 usb_gadget_vbus_disconnect(otg->gadget);
1343 otg->gadget = NULL;
1344 power_down(isp);
1345 return 0;
1346 }
1347
1348#ifdef CONFIG_USB_OTG
1349 otg->gadget = gadget;
1350 dev_dbg(&isp->client->dev, "registered gadget\n");
1351
1352 if (otg->host)
1353 return isp1301_otg_enable(isp);
1354 return 0;
1355
1356#elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1357 otg->gadget = gadget;
1358
1359
1360 {
1361 u32 l;
1362
1363 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1364 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS);
1365 l |= OTG_ID;
1366 omap_writel(l, OTG_CTRL);
1367 }
1368
1369 power_up(isp);
1370 isp->phy.otg->state = OTG_STATE_B_IDLE;
1371
1372 if (machine_is_omap_h2() || machine_is_omap_h3())
1373 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1374
1375 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1376 INTR_SESS_VLD);
1377 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1378 INTR_VBUS_VLD);
1379 dev_info(&isp->client->dev, "B-Peripheral sessions ok\n");
1380 dump_regs(isp, __func__);
1381
1382
1383
1384
1385
1386 if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD)
1387 b_peripheral(isp);
1388
1389 return 0;
1390
1391#else
1392 dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n");
1393 return -EINVAL;
1394#endif
1395}
1396
1397
1398
1399
1400static int
1401isp1301_set_power(struct usb_phy *dev, unsigned mA)
1402{
1403 if (!the_transceiver)
1404 return -ENODEV;
1405 if (dev->otg->state == OTG_STATE_B_PERIPHERAL)
1406 enable_vbus_draw(the_transceiver, mA);
1407 return 0;
1408}
1409
1410static int
1411isp1301_start_srp(struct usb_otg *otg)
1412{
1413 struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy);
1414 u32 otg_ctrl;
1415
1416 if (isp != the_transceiver || isp->phy.otg->state != OTG_STATE_B_IDLE)
1417 return -ENODEV;
1418
1419 otg_ctrl = omap_readl(OTG_CTRL);
1420 if (!(otg_ctrl & OTG_BSESSEND))
1421 return -EINVAL;
1422
1423 otg_ctrl |= OTG_B_BUSREQ;
1424 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
1425 omap_writel(otg_ctrl, OTG_CTRL);
1426 isp->phy.otg->state = OTG_STATE_B_SRP_INIT;
1427
1428 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp),
1429 omap_readl(OTG_CTRL));
1430#ifdef CONFIG_USB_OTG
1431 check_state(isp, __func__);
1432#endif
1433 return 0;
1434}
1435
1436static int
1437isp1301_start_hnp(struct usb_otg *otg)
1438{
1439#ifdef CONFIG_USB_OTG
1440 struct isp1301 *isp = container_of(otg->usb_phy, struct isp1301, phy);
1441 u32 l;
1442
1443 if (isp != the_transceiver)
1444 return -ENODEV;
1445 if (otg->default_a && (otg->host == NULL || !otg->host->b_hnp_enable))
1446 return -ENOTCONN;
1447 if (!otg->default_a && (otg->gadget == NULL
1448 || !otg->gadget->b_hnp_enable))
1449 return -ENOTCONN;
1450
1451
1452
1453
1454 switch (isp->phy.otg->state) {
1455 case OTG_STATE_B_HOST:
1456 isp->phy.otg->state = OTG_STATE_B_PERIPHERAL;
1457
1458 break;
1459 case OTG_STATE_A_HOST:
1460#if 0
1461
1462 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1463 MC1_BDIS_ACON_EN);
1464#endif
1465
1466 usb_gadget_vbus_connect(otg->gadget);
1467 l = omap_readl(OTG_CTRL);
1468 l |= OTG_A_SETB_HNPEN;
1469 omap_writel(l, OTG_CTRL);
1470
1471 break;
1472 case OTG_STATE_A_PERIPHERAL:
1473
1474 break;
1475 default:
1476 return -EILSEQ;
1477 }
1478 pr_debug("otg: HNP %s, %06x ...\n",
1479 state_name(isp), omap_readl(OTG_CTRL));
1480 check_state(isp, __func__);
1481 return 0;
1482#else
1483
1484 return -EINVAL;
1485#endif
1486}
1487
1488
1489
1490static int
1491isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
1492{
1493 int status;
1494 struct isp1301 *isp;
1495
1496 if (the_transceiver)
1497 return 0;
1498
1499 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1500 if (!isp)
1501 return 0;
1502
1503 isp->phy.otg = kzalloc(sizeof *isp->phy.otg, GFP_KERNEL);
1504 if (!isp->phy.otg) {
1505 kfree(isp);
1506 return 0;
1507 }
1508
1509 INIT_WORK(&isp->work, isp1301_work);
1510 init_timer(&isp->timer);
1511 isp->timer.function = isp1301_timer;
1512 isp->timer.data = (unsigned long) isp;
1513
1514 i2c_set_clientdata(i2c, isp);
1515 isp->client = i2c;
1516
1517
1518 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1519 if (status != I2C_VENDOR_ID_PHILIPS) {
1520 dev_dbg(&i2c->dev, "not philips id: %d\n", status);
1521 goto fail;
1522 }
1523 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1524 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1525 dev_dbg(&i2c->dev, "not isp1301, %d\n", status);
1526 goto fail;
1527 }
1528 isp->i2c_release = i2c->dev.release;
1529 i2c->dev.release = isp1301_release;
1530
1531
1532 status = i2c_smbus_read_word_data(i2c, ISP1301_BCD_DEVICE);
1533 dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n",
1534 status >> 8, status & 0xff);
1535
1536
1537 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK);
1538
1539 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI);
1540 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI);
1541
1542 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1543 OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
1544 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1545 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
1546
1547 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0);
1548 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1549 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1550
1551#ifdef CONFIG_USB_OTG
1552 status = otg_bind(isp);
1553 if (status < 0) {
1554 dev_dbg(&i2c->dev, "can't bind OTG\n");
1555 goto fail;
1556 }
1557#endif
1558
1559 if (machine_is_omap_h2()) {
1560
1561 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1562 MC1_SPEED);
1563 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2,
1564 MC2_SPD_SUSP_CTRL);
1565
1566
1567 omap_cfg_reg(M14_1510_GPIO2);
1568 if (gpio_request(2, "isp1301") == 0)
1569 gpio_direction_input(2);
1570 isp->irq_type = IRQF_TRIGGER_FALLING;
1571 }
1572
1573 status = request_irq(i2c->irq, isp1301_irq,
1574 isp->irq_type, DRIVER_NAME, isp);
1575 if (status < 0) {
1576 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n",
1577 i2c->irq, status);
1578 goto fail;
1579 }
1580
1581 isp->phy.dev = &i2c->dev;
1582 isp->phy.label = DRIVER_NAME;
1583 isp->phy.set_power = isp1301_set_power,
1584
1585 isp->phy.otg->usb_phy = &isp->phy;
1586 isp->phy.otg->set_host = isp1301_set_host,
1587 isp->phy.otg->set_peripheral = isp1301_set_peripheral,
1588 isp->phy.otg->start_srp = isp1301_start_srp,
1589 isp->phy.otg->start_hnp = isp1301_start_hnp,
1590
1591 enable_vbus_draw(isp, 0);
1592 power_down(isp);
1593 the_transceiver = isp;
1594
1595#ifdef CONFIG_USB_OTG
1596 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
1597 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
1598#endif
1599
1600 dump_regs(isp, __func__);
1601
1602#ifdef VERBOSE
1603 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1604 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1605#endif
1606
1607 status = usb_add_phy(&isp->phy, USB_PHY_TYPE_USB2);
1608 if (status < 0)
1609 dev_err(&i2c->dev, "can't register transceiver, %d\n",
1610 status);
1611
1612 return 0;
1613
1614fail:
1615 kfree(isp->phy.otg);
1616 kfree(isp);
1617 return -ENODEV;
1618}
1619
1620static const struct i2c_device_id isp1301_id[] = {
1621 { "isp1301_omap", 0 },
1622 { }
1623};
1624MODULE_DEVICE_TABLE(i2c, isp1301_id);
1625
1626static struct i2c_driver isp1301_driver = {
1627 .driver = {
1628 .name = "isp1301_omap",
1629 },
1630 .probe = isp1301_probe,
1631 .remove = isp1301_remove,
1632 .id_table = isp1301_id,
1633};
1634
1635
1636
1637static int __init isp_init(void)
1638{
1639 return i2c_add_driver(&isp1301_driver);
1640}
1641subsys_initcall(isp_init);
1642
1643static void __exit isp_exit(void)
1644{
1645 if (the_transceiver)
1646 usb_remove_phy(&the_transceiver->phy);
1647 i2c_del_driver(&isp1301_driver);
1648}
1649module_exit(isp_exit);
1650
1651