2 * isp1301_omap - ISP 1301 USB transceiver, talking to OMAP OTG controller
4 * Copyright (C) 2004 Texas Instruments
5 * Copyright (C) 2004 David Brownell
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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/usb/ch9.h>
29 #include <linux/usb/gadget.h>
30 #include <linux/usb.h>
31 #include <linux/usb/otg.h>
32 #include <linux/i2c.h>
33 #include <linux/workqueue.h>
44 #define DRIVER_VERSION "24 August 2004"
45 #define DRIVER_NAME (isp1301_driver.driver.name)
47 MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver");
48 MODULE_LICENSE("GPL");
51 struct otg_transceiver otg;
52 struct i2c_client *client;
53 void (*i2c_release)(struct device *dev);
60 struct timer_list timer;
62 /* use keventd context to change the state for us */
63 struct work_struct work;
66 # define WORK_UPDATE_ISP 0 /* update ISP from OTG */
67 # define WORK_UPDATE_OTG 1 /* update OTG from ISP */
68 # define WORK_HOST_RESUME 4 /* resume host */
69 # define WORK_TIMER 6 /* timer fired */
70 # define WORK_STOP 7 /* don't resubmit */
74 /* bits in OTG_CTRL */
76 #define OTG_XCEIV_OUTPUTS \
77 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
78 #define OTG_XCEIV_INPUTS \
79 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
80 #define OTG_CTRL_BITS \
81 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
82 /* and OTG_PULLUP is sometimes written */
84 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
85 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
89 /*-------------------------------------------------------------------------*/
91 #ifdef CONFIG_MACH_OMAP_H2
93 /* board-specific PM hooks */
97 #include <asm/mach-types.h>
100 #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
102 #include <linux/i2c/tps65010.h>
106 static inline int tps65010_set_vbus_draw(unsigned mA)
108 pr_debug("tps65010: draw %d mA (STUB)\n", mA);
114 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
116 int status = tps65010_set_vbus_draw(mA);
118 pr_debug(" VBUS %d mA error %d\n", mA, status);
121 static void enable_vbus_source(struct isp1301 *isp)
123 /* this board won't supply more than 8mA vbus power.
124 * some boards can switch a 100ma "unit load" (or more).
129 /* products will deliver OTG messages with LEDs, GUI, etc */
130 static inline void notresponding(struct isp1301 *isp)
132 printk(KERN_NOTICE "OTG device not responding.\n");
138 /*-------------------------------------------------------------------------*/
140 static struct i2c_driver isp1301_driver;
142 /* smbus apis are used for portability */
145 isp1301_get_u8(struct isp1301 *isp, u8 reg)
147 return i2c_smbus_read_byte_data(isp->client, reg + 0);
151 isp1301_get_u16(struct isp1301 *isp, u8 reg)
153 return i2c_smbus_read_word_data(isp->client, reg);
157 isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
159 return i2c_smbus_write_byte_data(isp->client, reg + 0, bits);
163 isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
165 return i2c_smbus_write_byte_data(isp->client, reg + 1, bits);
168 /*-------------------------------------------------------------------------*/
171 #define ISP1301_VENDOR_ID 0x00 /* u16 read */
172 #define ISP1301_PRODUCT_ID 0x02 /* u16 read */
173 #define ISP1301_BCD_DEVICE 0x14 /* u16 read */
175 #define I2C_VENDOR_ID_PHILIPS 0x04cc
176 #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
178 /* operational registers */
179 #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
180 # define MC1_SPEED (1 << 0)
181 # define MC1_SUSPEND (1 << 1)
182 # define MC1_DAT_SE0 (1 << 2)
183 # define MC1_TRANSPARENT (1 << 3)
184 # define MC1_BDIS_ACON_EN (1 << 4)
185 # define MC1_OE_INT_EN (1 << 5)
186 # define MC1_UART_EN (1 << 6)
187 # define MC1_MASK 0x7f
188 #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
189 # define MC2_GLOBAL_PWR_DN (1 << 0)
190 # define MC2_SPD_SUSP_CTRL (1 << 1)
191 # define MC2_BI_DI (1 << 2)
192 # define MC2_TRANSP_BDIR0 (1 << 3)
193 # define MC2_TRANSP_BDIR1 (1 << 4)
194 # define MC2_AUDIO_EN (1 << 5)
195 # define MC2_PSW_EN (1 << 6)
196 # define MC2_EN2V7 (1 << 7)
197 #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
198 # define OTG1_DP_PULLUP (1 << 0)
199 # define OTG1_DM_PULLUP (1 << 1)
200 # define OTG1_DP_PULLDOWN (1 << 2)
201 # define OTG1_DM_PULLDOWN (1 << 3)
202 # define OTG1_ID_PULLDOWN (1 << 4)
203 # define OTG1_VBUS_DRV (1 << 5)
204 # define OTG1_VBUS_DISCHRG (1 << 6)
205 # define OTG1_VBUS_CHRG (1 << 7)
206 #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
207 # define OTG_B_SESS_END (1 << 6)
208 # define OTG_B_SESS_VLD (1 << 7)
210 #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */
211 #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */
213 #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */
214 #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */
216 /* same bitfields in all interrupt registers */
217 # define INTR_VBUS_VLD (1 << 0)
218 # define INTR_SESS_VLD (1 << 1)
219 # define INTR_DP_HI (1 << 2)
220 # define INTR_ID_GND (1 << 3)
221 # define INTR_DM_HI (1 << 4)
222 # define INTR_ID_FLOAT (1 << 5)
223 # define INTR_BDIS_ACON (1 << 6)
224 # define INTR_CR_INT (1 << 7)
226 /*-------------------------------------------------------------------------*/
228 static const char *state_string(enum usb_otg_state state)
231 case OTG_STATE_A_IDLE: return "a_idle";
232 case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
233 case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
234 case OTG_STATE_A_HOST: return "a_host";
235 case OTG_STATE_A_SUSPEND: return "a_suspend";
236 case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
237 case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
238 case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
239 case OTG_STATE_B_IDLE: return "b_idle";
240 case OTG_STATE_B_SRP_INIT: return "b_srp_init";
241 case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
242 case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
243 case OTG_STATE_B_HOST: return "b_host";
244 default: return "UNDEFINED";
248 static inline const char *state_name(struct isp1301 *isp)
250 return state_string(isp->otg.state);
253 /*-------------------------------------------------------------------------*/
255 /* NOTE: some of this ISP1301 setup is specific to H2 boards;
256 * not everything is guarded by board-specific checks, or even using
257 * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI.
259 * ALSO: this currently doesn't use ISP1301 low-power modes
260 * while OTG is running.
263 static void power_down(struct isp1301 *isp)
265 isp->otg.state = OTG_STATE_UNDEFINED;
267 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
268 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
270 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN);
271 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
274 static void power_up(struct isp1301 *isp)
276 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
277 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
279 /* do this only when cpu is driving transceiver,
280 * so host won't see a low speed device...
282 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
285 #define NO_HOST_SUSPEND
287 static int host_suspend(struct isp1301 *isp)
289 #ifdef NO_HOST_SUSPEND
297 /* Currently ASSUMES only the OTG port matters;
298 * other ports could be active...
300 dev = isp->otg.host->controller;
301 return dev->driver->suspend(dev, 3, 0);
305 static int host_resume(struct isp1301 *isp)
307 #ifdef NO_HOST_SUSPEND
315 dev = isp->otg.host->controller;
316 return dev->driver->resume(dev, 0);
320 static int gadget_suspend(struct isp1301 *isp)
322 isp->otg.gadget->b_hnp_enable = 0;
323 isp->otg.gadget->a_hnp_support = 0;
324 isp->otg.gadget->a_alt_hnp_support = 0;
325 return usb_gadget_vbus_disconnect(isp->otg.gadget);
328 /*-------------------------------------------------------------------------*/
330 #define TIMER_MINUTES 10
331 #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
333 /* Almost all our I2C messaging comes from a work queue's task context.
334 * NOTE: guaranteeing certain response times might mean we shouldn't
335 * share keventd's work queue; a realtime task might be safest.
338 isp1301_defer_work(struct isp1301 *isp, int work)
342 if (isp && !test_and_set_bit(work, &isp->todo)) {
343 (void) get_device(&isp->client->dev);
344 status = schedule_work(&isp->work);
345 if (!status && !isp->working)
346 dev_vdbg(&isp->client->dev,
347 "work item %d may be lost\n", work);
351 /* called from irq handlers */
352 static void a_idle(struct isp1301 *isp, const char *tag)
356 if (isp->otg.state == OTG_STATE_A_IDLE)
359 isp->otg.default_a = 1;
361 isp->otg.host->is_b_host = 0;
364 if (isp->otg.gadget) {
365 isp->otg.gadget->is_a_peripheral = 1;
368 isp->otg.state = OTG_STATE_A_IDLE;
369 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
370 omap_writel(l, OTG_CTRL);
371 isp->last_otg_ctrl = l;
372 pr_debug(" --> %s/%s\n", state_name(isp), tag);
375 /* called from irq handlers */
376 static void b_idle(struct isp1301 *isp, const char *tag)
380 if (isp->otg.state == OTG_STATE_B_IDLE)
383 isp->otg.default_a = 0;
385 isp->otg.host->is_b_host = 1;
388 if (isp->otg.gadget) {
389 isp->otg.gadget->is_a_peripheral = 0;
392 isp->otg.state = OTG_STATE_B_IDLE;
393 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
394 omap_writel(l, OTG_CTRL);
395 isp->last_otg_ctrl = l;
396 pr_debug(" --> %s/%s\n", state_name(isp), tag);
400 dump_regs(struct isp1301 *isp, const char *label)
403 u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1);
404 u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
405 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
407 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
408 omap_readl(OTG_CTRL), label, state_name(isp),
410 /* mode control and irq enables don't change much */
414 /*-------------------------------------------------------------------------*/
416 #ifdef CONFIG_USB_OTG
419 * The OMAP OTG controller handles most of the OTG state transitions.
421 * We translate isp1301 outputs (mostly voltage comparator status) into
422 * OTG inputs; OTG outputs (mostly pullup/pulldown controls) and HNP state
423 * flags into isp1301 inputs ... and infer state transitions.
428 static void check_state(struct isp1301 *isp, const char *tag)
430 enum usb_otg_state state = OTG_STATE_UNDEFINED;
431 u8 fsm = omap_readw(OTG_TEST) & 0x0ff;
438 state = OTG_STATE_B_IDLE;
444 state = OTG_STATE_B_PERIPHERAL;
447 state = OTG_STATE_B_SRP_INIT;
450 /* extra dual-role default-b states */
456 state = OTG_STATE_B_WAIT_ACON;
459 state = OTG_STATE_B_HOST;
464 state = OTG_STATE_A_IDLE;
467 state = OTG_STATE_A_WAIT_VFALL;
470 state = OTG_STATE_A_VBUS_ERR;
476 state = OTG_STATE_A_PERIPHERAL;
479 state = OTG_STATE_A_WAIT_VRISE;
482 state = OTG_STATE_A_WAIT_BCON;
485 state = OTG_STATE_A_HOST;
488 state = OTG_STATE_A_SUSPEND;
493 if (isp->otg.state == state && !extra)
495 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
496 state_string(state), fsm, state_name(isp),
497 omap_readl(OTG_CTRL));
502 static inline void check_state(struct isp1301 *isp, const char *tag) { }
506 /* outputs from ISP1301_INTERRUPT_SOURCE */
507 static void update_otg1(struct isp1301 *isp, u8 int_src)
511 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
512 otg_ctrl &= ~OTG_XCEIV_INPUTS;
513 otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
516 if (int_src & INTR_SESS_VLD)
517 otg_ctrl |= OTG_ASESSVLD;
518 else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) {
519 a_idle(isp, "vfall");
520 otg_ctrl &= ~OTG_CTRL_BITS;
522 if (int_src & INTR_VBUS_VLD)
523 otg_ctrl |= OTG_VBUSVLD;
524 if (int_src & INTR_ID_GND) { /* default-A */
525 if (isp->otg.state == OTG_STATE_B_IDLE
526 || isp->otg.state == OTG_STATE_UNDEFINED) {
530 } else { /* default-B */
532 if (isp->otg.state == OTG_STATE_A_IDLE
533 || isp->otg.state == OTG_STATE_UNDEFINED) {
538 omap_writel(otg_ctrl, OTG_CTRL);
541 /* outputs from ISP1301_OTG_STATUS */
542 static void update_otg2(struct isp1301 *isp, u8 otg_status)
546 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
547 otg_ctrl &= ~OTG_XCEIV_INPUTS;
548 otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND);
549 if (otg_status & OTG_B_SESS_VLD)
550 otg_ctrl |= OTG_BSESSVLD;
551 else if (otg_status & OTG_B_SESS_END)
552 otg_ctrl |= OTG_BSESSEND;
553 omap_writel(otg_ctrl, OTG_CTRL);
556 /* inputs going to ISP1301 */
557 static void otg_update_isp(struct isp1301 *isp)
559 u32 otg_ctrl, otg_change;
560 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
562 otg_ctrl = omap_readl(OTG_CTRL);
563 otg_change = otg_ctrl ^ isp->last_otg_ctrl;
564 isp->last_otg_ctrl = otg_ctrl;
565 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
567 switch (isp->otg.state) {
568 case OTG_STATE_B_IDLE:
569 case OTG_STATE_B_PERIPHERAL:
570 case OTG_STATE_B_SRP_INIT:
571 if (!(otg_ctrl & OTG_PULLUP)) {
572 // if (otg_ctrl & OTG_B_HNPEN) {
573 if (isp->otg.gadget->b_hnp_enable) {
574 isp->otg.state = OTG_STATE_B_WAIT_ACON;
575 pr_debug(" --> b_wait_acon\n");
580 set |= OTG1_DP_PULLUP;
581 clr |= OTG1_DP_PULLDOWN;
583 case OTG_STATE_A_SUSPEND:
584 case OTG_STATE_A_PERIPHERAL:
585 if (otg_ctrl & OTG_PULLUP)
588 // case OTG_STATE_B_WAIT_ACON:
591 set |= OTG1_DP_PULLDOWN;
592 clr |= OTG1_DP_PULLUP;
596 # define toggle(OTG,ISP) do { \
597 if (otg_ctrl & OTG) set |= ISP; \
601 if (!(isp->otg.host))
602 otg_ctrl &= ~OTG_DRV_VBUS;
604 switch (isp->otg.state) {
605 case OTG_STATE_A_SUSPEND:
606 if (otg_ctrl & OTG_DRV_VBUS) {
607 set |= OTG1_VBUS_DRV;
610 /* HNP failed for some reason (A_AIDL_BDIS timeout) */
614 case OTG_STATE_A_VBUS_ERR:
615 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
616 pr_debug(" --> a_wait_vfall\n");
618 case OTG_STATE_A_WAIT_VFALL:
619 /* FIXME usbcore thinks port power is still on ... */
620 clr |= OTG1_VBUS_DRV;
622 case OTG_STATE_A_IDLE:
623 if (otg_ctrl & OTG_DRV_VBUS) {
624 isp->otg.state = OTG_STATE_A_WAIT_VRISE;
625 pr_debug(" --> a_wait_vrise\n");
629 toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV);
632 toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG);
633 toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG);
637 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set);
638 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr);
640 /* HNP switch to host or peripheral; and SRP */
641 if (otg_change & OTG_PULLUP) {
644 switch (isp->otg.state) {
645 case OTG_STATE_B_IDLE:
646 if (clr & OTG1_DP_PULLUP)
648 isp->otg.state = OTG_STATE_B_PERIPHERAL;
649 pr_debug(" --> b_peripheral\n");
651 case OTG_STATE_A_SUSPEND:
652 if (clr & OTG1_DP_PULLUP)
654 isp->otg.state = OTG_STATE_A_PERIPHERAL;
655 pr_debug(" --> a_peripheral\n");
660 l = omap_readl(OTG_CTRL);
662 omap_writel(l, OTG_CTRL);
665 check_state(isp, __func__);
666 dump_regs(isp, "otg->isp1301");
669 static irqreturn_t omap_otg_irq(int irq, void *_isp)
671 u16 otg_irq = omap_readw(OTG_IRQ_SRC);
674 struct isp1301 *isp = _isp;
676 /* update ISP1301 transciever from OTG controller */
677 if (otg_irq & OPRT_CHG) {
678 omap_writew(OPRT_CHG, OTG_IRQ_SRC);
679 isp1301_defer_work(isp, WORK_UPDATE_ISP);
682 /* SRP to become b_peripheral failed */
683 } else if (otg_irq & B_SRP_TMROUT) {
684 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL));
687 /* gadget drivers that care should monitor all kinds of
688 * remote wakeup (SRP, normal) using their own timer
689 * to give "check cable and A-device" messages.
691 if (isp->otg.state == OTG_STATE_B_SRP_INIT)
692 b_idle(isp, "srp_timeout");
694 omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
697 /* HNP to become b_host failed */
698 } else if (otg_irq & B_HNP_FAIL) {
699 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
700 state_name(isp), omap_readl(OTG_CTRL));
703 otg_ctrl = omap_readl(OTG_CTRL);
704 otg_ctrl |= OTG_BUSDROP;
705 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
706 omap_writel(otg_ctrl, OTG_CTRL);
708 /* subset of b_peripheral()... */
709 isp->otg.state = OTG_STATE_B_PERIPHERAL;
710 pr_debug(" --> b_peripheral\n");
712 omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
715 /* detect SRP from B-device ... */
716 } else if (otg_irq & A_SRP_DETECT) {
717 pr_debug("otg: %s SRP_DETECT, %06x\n",
718 state_name(isp), omap_readl(OTG_CTRL));
720 isp1301_defer_work(isp, WORK_UPDATE_OTG);
721 switch (isp->otg.state) {
722 case OTG_STATE_A_IDLE:
725 isp1301_defer_work(isp, WORK_HOST_RESUME);
726 otg_ctrl = omap_readl(OTG_CTRL);
727 otg_ctrl |= OTG_A_BUSREQ;
728 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
731 omap_writel(otg_ctrl, OTG_CTRL);
737 omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
740 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
741 * we don't track them separately
743 } else if (otg_irq & A_REQ_TMROUT) {
744 otg_ctrl = omap_readl(OTG_CTRL);
745 pr_info("otg: BCON_TMOUT from %s, %06x\n",
746 state_name(isp), otg_ctrl);
749 otg_ctrl |= OTG_BUSDROP;
750 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
751 omap_writel(otg_ctrl, OTG_CTRL);
752 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
754 omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
757 /* A-supplied voltage fell too low; overcurrent */
758 } else if (otg_irq & A_VBUS_ERR) {
759 otg_ctrl = omap_readl(OTG_CTRL);
760 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
761 state_name(isp), otg_irq, otg_ctrl);
763 otg_ctrl |= OTG_BUSDROP;
764 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
765 omap_writel(otg_ctrl, OTG_CTRL);
766 isp->otg.state = OTG_STATE_A_VBUS_ERR;
768 omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
771 /* switch driver; the transciever code activates it,
772 * ungating the udc clock or resuming OHCI.
774 } else if (otg_irq & DRIVER_SWITCH) {
777 otg_ctrl = omap_readl(OTG_CTRL);
778 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
780 (otg_ctrl & OTG_DRIVER_SEL)
783 isp1301_defer_work(isp, WORK_UPDATE_ISP);
785 /* role is peripheral */
786 if (otg_ctrl & OTG_DRIVER_SEL) {
787 switch (isp->otg.state) {
788 case OTG_STATE_A_IDLE:
789 b_idle(isp, __func__);
794 isp1301_defer_work(isp, WORK_UPDATE_ISP);
798 if (!(otg_ctrl & OTG_ID)) {
799 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
800 omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL);
804 switch (isp->otg.state) {
805 case OTG_STATE_B_WAIT_ACON:
806 isp->otg.state = OTG_STATE_B_HOST;
807 pr_debug(" --> b_host\n");
810 case OTG_STATE_A_WAIT_BCON:
811 isp->otg.state = OTG_STATE_A_HOST;
812 pr_debug(" --> a_host\n");
814 case OTG_STATE_A_PERIPHERAL:
815 isp->otg.state = OTG_STATE_A_WAIT_BCON;
816 pr_debug(" --> a_wait_bcon\n");
821 isp1301_defer_work(isp, WORK_HOST_RESUME);
825 omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
829 usb_bus_start_enum(isp->otg.host,
830 isp->otg.host->otg_port);
833 check_state(isp, __func__);
837 static struct platform_device *otg_dev;
839 static int otg_init(struct isp1301 *isp)
846 dump_regs(isp, __func__);
847 /* some of these values are board-specific... */
848 l = omap_readl(OTG_SYSCON_2);
851 | SRP_GPDATA /* 9msec Bdev D+ pulse */
852 | SRP_GPDVBUS /* discharge after VBUS pulse */
853 // | (3 << 24) /* 2msec VBUS pulse */
855 | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
856 | SRP_DPW /* detect 167+ns SRP pulses */
857 | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */
859 omap_writel(l, OTG_SYSCON_2);
861 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
862 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
864 check_state(isp, __func__);
865 pr_debug("otg: %s, %s %06x\n",
866 state_name(isp), __func__, omap_readl(OTG_CTRL));
868 omap_writew(DRIVER_SWITCH | OPRT_CHG
869 | B_SRP_TMROUT | B_HNP_FAIL
870 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN);
872 l = omap_readl(OTG_SYSCON_2);
874 omap_writel(l, OTG_SYSCON_2);
879 static int otg_probe(struct platform_device *dev)
881 // struct omap_usb_config *config = dev->platform_data;
887 static int otg_remove(struct platform_device *dev)
893 struct platform_driver omap_otg_driver = {
895 .remove = otg_remove,
897 .owner = THIS_MODULE,
902 static int otg_bind(struct isp1301 *isp)
909 status = platform_driver_register(&omap_otg_driver);
914 status = request_irq(otg_dev->resource[1].start, omap_otg_irq,
915 IRQF_DISABLED, DRIVER_NAME, isp);
920 platform_driver_unregister(&omap_otg_driver);
924 static void otg_unbind(struct isp1301 *isp)
928 free_irq(otg_dev->resource[1].start, isp);
933 /* OTG controller isn't clocked */
935 #endif /* CONFIG_USB_OTG */
937 /*-------------------------------------------------------------------------*/
939 static void b_peripheral(struct isp1301 *isp)
943 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
944 omap_writel(l, OTG_CTRL);
946 usb_gadget_vbus_connect(isp->otg.gadget);
948 #ifdef CONFIG_USB_OTG
949 enable_vbus_draw(isp, 8);
952 enable_vbus_draw(isp, 100);
953 /* UDC driver just set OTG_BSESSVLD */
954 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP);
955 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN);
956 isp->otg.state = OTG_STATE_B_PERIPHERAL;
957 pr_debug(" --> b_peripheral\n");
958 dump_regs(isp, "2periph");
962 static void isp_update_otg(struct isp1301 *isp, u8 stat)
964 u8 isp_stat, isp_bstat;
965 enum usb_otg_state state = isp->otg.state;
967 if (stat & INTR_BDIS_ACON)
968 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp));
970 /* start certain state transitions right away */
971 isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
972 if (isp_stat & INTR_ID_GND) {
973 if (isp->otg.default_a) {
975 case OTG_STATE_B_IDLE:
978 case OTG_STATE_A_IDLE:
979 enable_vbus_source(isp);
981 case OTG_STATE_A_WAIT_VRISE:
982 /* we skip over OTG_STATE_A_WAIT_BCON, since
983 * the HC will transition to A_HOST (or
984 * A_SUSPEND!) without our noticing except
987 if (isp_stat & INTR_VBUS_VLD)
988 isp->otg.state = OTG_STATE_A_HOST;
990 case OTG_STATE_A_WAIT_VFALL:
991 if (!(isp_stat & INTR_SESS_VLD))
992 a_idle(isp, "vfell");
995 if (!(isp_stat & INTR_VBUS_VLD))
996 isp->otg.state = OTG_STATE_A_VBUS_ERR;
999 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1002 case OTG_STATE_B_PERIPHERAL:
1003 case OTG_STATE_B_HOST:
1004 case OTG_STATE_B_WAIT_ACON:
1005 usb_gadget_vbus_disconnect(isp->otg.gadget);
1010 if (state != OTG_STATE_A_IDLE)
1012 if (isp->otg.host && state == OTG_STATE_A_IDLE)
1013 isp1301_defer_work(isp, WORK_HOST_RESUME);
1019 /* if user unplugged mini-A end of cable,
1020 * don't bypass A_WAIT_VFALL.
1022 if (isp->otg.default_a) {
1025 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
1027 case OTG_STATE_A_WAIT_VFALL:
1028 state = OTG_STATE_A_IDLE;
1029 /* khubd may take a while to notice and
1030 * handle this disconnect, so don't go
1031 * to B_IDLE quite yet.
1034 case OTG_STATE_A_IDLE:
1036 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
1038 isp->otg.state = OTG_STATE_B_IDLE;
1039 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1040 l &= ~OTG_CTRL_BITS;
1041 omap_writel(l, OTG_CTRL);
1043 case OTG_STATE_B_IDLE:
1047 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1049 switch (isp->otg.state) {
1050 case OTG_STATE_B_PERIPHERAL:
1051 case OTG_STATE_B_WAIT_ACON:
1052 case OTG_STATE_B_HOST:
1053 if (likely(isp_bstat & OTG_B_SESS_VLD))
1055 enable_vbus_draw(isp, 0);
1056 #ifndef CONFIG_USB_OTG
1057 /* UDC driver will clear OTG_BSESSVLD */
1058 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1060 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1062 dump_regs(isp, __func__);
1065 case OTG_STATE_B_SRP_INIT:
1066 b_idle(isp, __func__);
1067 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
1068 omap_writel(l, OTG_CTRL);
1070 case OTG_STATE_B_IDLE:
1071 if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) {
1072 #ifdef CONFIG_USB_OTG
1073 update_otg1(isp, isp_stat);
1074 update_otg2(isp, isp_bstat);
1077 } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD)))
1078 isp_bstat |= OTG_B_SESS_END;
1080 case OTG_STATE_A_WAIT_VFALL:
1083 pr_debug("otg: unsupported b-device %s\n",
1089 if (state != isp->otg.state)
1090 pr_debug(" isp, %s -> %s\n",
1091 state_string(state), state_name(isp));
1093 #ifdef CONFIG_USB_OTG
1094 /* update the OTG controller state to match the isp1301; may
1095 * trigger OPRT_CHG irqs for changes going to the isp1301.
1097 update_otg1(isp, isp_stat);
1098 update_otg2(isp, isp_bstat);
1099 check_state(isp, __func__);
1102 dump_regs(isp, "isp1301->otg");
1105 /*-------------------------------------------------------------------------*/
1107 static u8 isp1301_clear_latch(struct isp1301 *isp)
1109 u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH);
1110 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch);
1115 isp1301_work(struct work_struct *work)
1117 struct isp1301 *isp = container_of(work, struct isp1301, work);
1120 /* implicit lock: we're the only task using this device */
1123 stop = test_bit(WORK_STOP, &isp->todo);
1125 #ifdef CONFIG_USB_OTG
1126 /* transfer state from otg engine to isp1301 */
1127 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1128 otg_update_isp(isp);
1129 put_device(&isp->client->dev);
1132 /* transfer state from isp1301 to otg engine */
1133 if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) {
1134 u8 stat = isp1301_clear_latch(isp);
1136 isp_update_otg(isp, stat);
1137 put_device(&isp->client->dev);
1140 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
1144 * skip A_WAIT_VRISE; hc transitions invisibly
1145 * skip A_WAIT_BCON; same.
1147 switch (isp->otg.state) {
1148 case OTG_STATE_A_WAIT_BCON:
1149 case OTG_STATE_A_WAIT_VRISE:
1150 isp->otg.state = OTG_STATE_A_HOST;
1151 pr_debug(" --> a_host\n");
1152 otg_ctrl = omap_readl(OTG_CTRL);
1153 otg_ctrl |= OTG_A_BUSREQ;
1154 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
1156 omap_writel(otg_ctrl, OTG_CTRL);
1158 case OTG_STATE_B_WAIT_ACON:
1159 isp->otg.state = OTG_STATE_B_HOST;
1160 pr_debug(" --> b_host (acon)\n");
1162 case OTG_STATE_B_HOST:
1163 case OTG_STATE_B_IDLE:
1164 case OTG_STATE_A_IDLE:
1167 pr_debug(" host resume in %s\n",
1172 put_device(&isp->client->dev);
1175 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
1177 dump_regs(isp, "timer");
1179 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1181 put_device(&isp->client->dev);
1185 dev_vdbg(&isp->client->dev,
1186 "work done, todo = 0x%lx\n",
1189 dev_dbg(&isp->client->dev, "stop\n");
1192 } while (isp->todo);
1196 static irqreturn_t isp1301_irq(int irq, void *isp)
1198 isp1301_defer_work(isp, WORK_UPDATE_OTG);
1202 static void isp1301_timer(unsigned long _isp)
1204 isp1301_defer_work((void *)_isp, WORK_TIMER);
1207 /*-------------------------------------------------------------------------*/
1209 static void isp1301_release(struct device *dev)
1211 struct isp1301 *isp;
1213 isp = dev_get_drvdata(dev);
1215 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1216 if (isp->i2c_release)
1217 isp->i2c_release(dev);
1221 static struct isp1301 *the_transceiver;
1223 static int __exit isp1301_remove(struct i2c_client *i2c)
1225 struct isp1301 *isp;
1227 isp = i2c_get_clientdata(i2c);
1229 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1230 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1231 free_irq(i2c->irq, isp);
1232 #ifdef CONFIG_USB_OTG
1235 if (machine_is_omap_h2())
1238 isp->timer.data = 0;
1239 set_bit(WORK_STOP, &isp->todo);
1240 del_timer_sync(&isp->timer);
1241 flush_scheduled_work();
1243 put_device(&i2c->dev);
1244 the_transceiver = 0;
1249 /*-------------------------------------------------------------------------*/
1251 /* NOTE: three modes are possible here, only one of which
1252 * will be standards-conformant on any given system:
1254 * - OTG mode (dual-role), required if there's a Mini-AB connector
1255 * - HOST mode, for when there's one or more A (host) connectors
1256 * - DEVICE mode, for when there's a B/Mini-B (device) connector
1258 * As a rule, you won't have an isp1301 chip unless it's there to
1259 * support the OTG mode. Other modes help testing USB controllers
1260 * in isolation from (full) OTG support, or maybe so later board
1261 * revisions can help to support those feature.
1264 #ifdef CONFIG_USB_OTG
1266 static int isp1301_otg_enable(struct isp1301 *isp)
1271 /* NOTE: since we don't change this, this provides
1272 * a few more interrupts than are strictly needed.
1274 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1275 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1276 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1277 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1279 dev_info(&isp->client->dev, "ready for dual-role USB ...\n");
1286 /* add or disable the host device+driver */
1288 isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1290 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1292 if (!otg || isp != the_transceiver)
1296 omap_writew(0, OTG_IRQ_EN);
1302 #ifdef CONFIG_USB_OTG
1303 isp->otg.host = host;
1304 dev_dbg(&isp->client->dev, "registered host\n");
1306 if (isp->otg.gadget)
1307 return isp1301_otg_enable(isp);
1310 #elif !defined(CONFIG_USB_GADGET_OMAP)
1311 // FIXME update its refcount
1312 isp->otg.host = host;
1316 if (machine_is_omap_h2())
1317 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1319 dev_info(&isp->client->dev, "A-Host sessions ok\n");
1320 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1322 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1325 /* If this has a Mini-AB connector, this mode is highly
1326 * nonstandard ... but can be handy for testing, especially with
1327 * the Mini-A end of an OTG cable. (Or something nonstandard
1328 * like MiniB-to-StandardB, maybe built with a gender mender.)
1330 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV);
1332 dump_regs(isp, __func__);
1337 dev_dbg(&isp->client->dev, "host sessions not allowed\n");
1344 isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1346 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1349 if (!otg || isp != the_transceiver)
1353 omap_writew(0, OTG_IRQ_EN);
1354 if (!isp->otg.default_a)
1355 enable_vbus_draw(isp, 0);
1356 usb_gadget_vbus_disconnect(isp->otg.gadget);
1357 isp->otg.gadget = 0;
1362 #ifdef CONFIG_USB_OTG
1363 isp->otg.gadget = gadget;
1364 dev_dbg(&isp->client->dev, "registered gadget\n");
1365 /* gadget driver may be suspended until vbus_connect () */
1367 return isp1301_otg_enable(isp);
1370 #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1371 isp->otg.gadget = gadget;
1372 // FIXME update its refcount
1374 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1375 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS);
1377 omap_writel(l, OTG_CTRL);
1380 isp->otg.state = OTG_STATE_B_IDLE;
1382 if (machine_is_omap_h2())
1383 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1385 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1387 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1389 dev_info(&isp->client->dev, "B-Peripheral sessions ok\n");
1390 dump_regs(isp, __func__);
1392 /* If this has a Mini-AB connector, this mode is highly
1393 * nonstandard ... but can be handy for testing, so long
1394 * as you don't plug a Mini-A cable into the jack.
1396 if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD)
1402 dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n");
1408 /*-------------------------------------------------------------------------*/
1411 isp1301_set_power(struct otg_transceiver *dev, unsigned mA)
1413 if (!the_transceiver)
1415 if (dev->state == OTG_STATE_B_PERIPHERAL)
1416 enable_vbus_draw(the_transceiver, mA);
1421 isp1301_start_srp(struct otg_transceiver *dev)
1423 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1426 if (!dev || isp != the_transceiver
1427 || isp->otg.state != OTG_STATE_B_IDLE)
1430 otg_ctrl = omap_readl(OTG_CTRL);
1431 if (!(otg_ctrl & OTG_BSESSEND))
1434 otg_ctrl |= OTG_B_BUSREQ;
1435 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
1436 omap_writel(otg_ctrl, OTG_CTRL);
1437 isp->otg.state = OTG_STATE_B_SRP_INIT;
1439 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp),
1440 omap_readl(OTG_CTRL));
1441 #ifdef CONFIG_USB_OTG
1442 check_state(isp, __func__);
1448 isp1301_start_hnp(struct otg_transceiver *dev)
1450 #ifdef CONFIG_USB_OTG
1451 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1454 if (!dev || isp != the_transceiver)
1456 if (isp->otg.default_a && (isp->otg.host == NULL
1457 || !isp->otg.host->b_hnp_enable))
1459 if (!isp->otg.default_a && (isp->otg.gadget == NULL
1460 || !isp->otg.gadget->b_hnp_enable))
1463 /* We want hardware to manage most HNP protocol timings.
1464 * So do this part as early as possible...
1466 switch (isp->otg.state) {
1467 case OTG_STATE_B_HOST:
1468 isp->otg.state = OTG_STATE_B_PERIPHERAL;
1469 /* caller will suspend next */
1471 case OTG_STATE_A_HOST:
1473 /* autoconnect mode avoids irq latency bugs */
1474 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1477 /* caller must suspend then clear A_BUSREQ */
1478 usb_gadget_vbus_connect(isp->otg.gadget);
1479 l = omap_readl(OTG_CTRL);
1480 l |= OTG_A_SETB_HNPEN;
1481 omap_writel(l, OTG_CTRL);
1484 case OTG_STATE_A_PERIPHERAL:
1485 /* initiated by B-Host suspend */
1490 pr_debug("otg: HNP %s, %06x ...\n",
1491 state_name(isp), omap_readl(OTG_CTRL));
1492 check_state(isp, __func__);
1500 /*-------------------------------------------------------------------------*/
1502 static int __init isp1301_probe(struct i2c_client *i2c)
1505 struct isp1301 *isp;
1507 if (the_transceiver)
1510 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1514 INIT_WORK(&isp->work, isp1301_work);
1515 init_timer(&isp->timer);
1516 isp->timer.function = isp1301_timer;
1517 isp->timer.data = (unsigned long) isp;
1519 i2c_set_clientdata(i2c, isp);
1522 /* verify the chip (shouldn't be necesary) */
1523 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1524 if (status != I2C_VENDOR_ID_PHILIPS) {
1525 dev_dbg(&i2c->dev, "not philips id: %d\n", status);
1528 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1529 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1530 dev_dbg(&i2c->dev, "not isp1301, %d\n", status);
1533 isp->i2c_release = i2c->dev.release;
1534 i2c->dev.release = isp1301_release;
1536 /* initial development used chiprev 2.00 */
1537 status = i2c_smbus_read_word_data(i2c, ISP1301_BCD_DEVICE);
1538 dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n",
1539 status >> 8, status & 0xff);
1541 /* make like power-on reset */
1542 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK);
1544 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI);
1545 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI);
1547 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1548 OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
1549 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1550 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
1552 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0);
1553 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1554 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1556 #ifdef CONFIG_USB_OTG
1557 status = otg_bind(isp);
1559 dev_dbg(&i2c->dev, "can't bind OTG\n");
1564 if (machine_is_omap_h2()) {
1565 /* full speed signaling by default */
1566 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1568 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2,
1571 /* IRQ wired at M14 */
1572 omap_cfg_reg(M14_1510_GPIO2);
1573 if (gpio_request(2, "isp1301") == 0)
1574 gpio_direction_input(2);
1575 isp->irq_type = IRQF_TRIGGER_FALLING;
1578 isp->irq_type |= IRQF_SAMPLE_RANDOM;
1579 status = request_irq(i2c->irq, isp1301_irq,
1580 isp->irq_type, DRIVER_NAME, isp);
1582 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n",
1587 isp->otg.dev = &i2c->dev;
1588 isp->otg.label = DRIVER_NAME;
1590 isp->otg.set_host = isp1301_set_host,
1591 isp->otg.set_peripheral = isp1301_set_peripheral,
1592 isp->otg.set_power = isp1301_set_power,
1593 isp->otg.start_srp = isp1301_start_srp,
1594 isp->otg.start_hnp = isp1301_start_hnp,
1596 enable_vbus_draw(isp, 0);
1598 the_transceiver = isp;
1600 #ifdef CONFIG_USB_OTG
1601 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
1602 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
1605 dump_regs(isp, __func__);
1608 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1609 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1612 status = otg_set_transceiver(&isp->otg);
1614 dev_err(&i2c->dev, "can't register transceiver, %d\n",
1624 static const struct i2c_device_id isp1301_id[] = {
1625 { "isp1301_omap", 0 },
1628 MODULE_DEVICE_TABLE(i2c, isp1301_id);
1630 static struct i2c_driver isp1301_driver = {
1632 .name = "isp1301_omap",
1634 .probe = isp1301_probe,
1635 .remove = __exit_p(isp1301_remove),
1636 .id_table = isp1301_id,
1639 /*-------------------------------------------------------------------------*/
1641 static int __init isp_init(void)
1643 return i2c_add_driver(&isp1301_driver);
1645 module_init(isp_init);
1647 static void __exit isp_exit(void)
1649 if (the_transceiver)
1650 otg_set_transceiver(0);
1651 i2c_del_driver(&isp1301_driver);
1653 module_exit(isp_exit);