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>
45 #define DRIVER_VERSION "24 August 2004"
46 #define DRIVER_NAME (isp1301_driver.driver.name)
48 MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver");
49 MODULE_LICENSE("GPL");
52 struct otg_transceiver otg;
53 struct i2c_client *client;
54 void (*i2c_release)(struct device *dev);
61 struct timer_list timer;
63 /* use keventd context to change the state for us */
64 struct work_struct work;
67 # define WORK_UPDATE_ISP 0 /* update ISP from OTG */
68 # define WORK_UPDATE_OTG 1 /* update OTG from ISP */
69 # define WORK_HOST_RESUME 4 /* resume host */
70 # define WORK_TIMER 6 /* timer fired */
71 # define WORK_STOP 7 /* don't resubmit */
75 /* bits in OTG_CTRL */
77 #define OTG_XCEIV_OUTPUTS \
78 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
79 #define OTG_XCEIV_INPUTS \
80 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
81 #define OTG_CTRL_BITS \
82 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
83 /* and OTG_PULLUP is sometimes written */
85 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
86 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
90 /*-------------------------------------------------------------------------*/
92 #ifdef CONFIG_MACH_OMAP_H2
94 /* board-specific PM hooks */
98 #include <asm/mach-types.h>
101 #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
103 #include <linux/i2c/tps65010.h>
107 static inline int tps65010_set_vbus_draw(unsigned mA)
109 pr_debug("tps65010: draw %d mA (STUB)\n", mA);
115 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
117 int status = tps65010_set_vbus_draw(mA);
119 pr_debug(" VBUS %d mA error %d\n", mA, status);
122 static void enable_vbus_source(struct isp1301 *isp)
124 /* this board won't supply more than 8mA vbus power.
125 * some boards can switch a 100ma "unit load" (or more).
130 /* products will deliver OTG messages with LEDs, GUI, etc */
131 static inline void notresponding(struct isp1301 *isp)
133 printk(KERN_NOTICE "OTG device not responding.\n");
139 /*-------------------------------------------------------------------------*/
141 static struct i2c_driver isp1301_driver;
143 /* smbus apis are used for portability */
146 isp1301_get_u8(struct isp1301 *isp, u8 reg)
148 return i2c_smbus_read_byte_data(isp->client, reg + 0);
152 isp1301_get_u16(struct isp1301 *isp, u8 reg)
154 return i2c_smbus_read_word_data(isp->client, reg);
158 isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
160 return i2c_smbus_write_byte_data(isp->client, reg + 0, bits);
164 isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
166 return i2c_smbus_write_byte_data(isp->client, reg + 1, bits);
169 /*-------------------------------------------------------------------------*/
172 #define ISP1301_VENDOR_ID 0x00 /* u16 read */
173 #define ISP1301_PRODUCT_ID 0x02 /* u16 read */
174 #define ISP1301_BCD_DEVICE 0x14 /* u16 read */
176 #define I2C_VENDOR_ID_PHILIPS 0x04cc
177 #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
179 /* operational registers */
180 #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
181 # define MC1_SPEED (1 << 0)
182 # define MC1_SUSPEND (1 << 1)
183 # define MC1_DAT_SE0 (1 << 2)
184 # define MC1_TRANSPARENT (1 << 3)
185 # define MC1_BDIS_ACON_EN (1 << 4)
186 # define MC1_OE_INT_EN (1 << 5)
187 # define MC1_UART_EN (1 << 6)
188 # define MC1_MASK 0x7f
189 #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
190 # define MC2_GLOBAL_PWR_DN (1 << 0)
191 # define MC2_SPD_SUSP_CTRL (1 << 1)
192 # define MC2_BI_DI (1 << 2)
193 # define MC2_TRANSP_BDIR0 (1 << 3)
194 # define MC2_TRANSP_BDIR1 (1 << 4)
195 # define MC2_AUDIO_EN (1 << 5)
196 # define MC2_PSW_EN (1 << 6)
197 # define MC2_EN2V7 (1 << 7)
198 #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
199 # define OTG1_DP_PULLUP (1 << 0)
200 # define OTG1_DM_PULLUP (1 << 1)
201 # define OTG1_DP_PULLDOWN (1 << 2)
202 # define OTG1_DM_PULLDOWN (1 << 3)
203 # define OTG1_ID_PULLDOWN (1 << 4)
204 # define OTG1_VBUS_DRV (1 << 5)
205 # define OTG1_VBUS_DISCHRG (1 << 6)
206 # define OTG1_VBUS_CHRG (1 << 7)
207 #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
208 # define OTG_B_SESS_END (1 << 6)
209 # define OTG_B_SESS_VLD (1 << 7)
211 #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */
212 #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */
214 #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */
215 #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */
217 /* same bitfields in all interrupt registers */
218 # define INTR_VBUS_VLD (1 << 0)
219 # define INTR_SESS_VLD (1 << 1)
220 # define INTR_DP_HI (1 << 2)
221 # define INTR_ID_GND (1 << 3)
222 # define INTR_DM_HI (1 << 4)
223 # define INTR_ID_FLOAT (1 << 5)
224 # define INTR_BDIS_ACON (1 << 6)
225 # define INTR_CR_INT (1 << 7)
227 /*-------------------------------------------------------------------------*/
229 static const char *state_string(enum usb_otg_state state)
232 case OTG_STATE_A_IDLE: return "a_idle";
233 case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
234 case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
235 case OTG_STATE_A_HOST: return "a_host";
236 case OTG_STATE_A_SUSPEND: return "a_suspend";
237 case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
238 case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
239 case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
240 case OTG_STATE_B_IDLE: return "b_idle";
241 case OTG_STATE_B_SRP_INIT: return "b_srp_init";
242 case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
243 case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
244 case OTG_STATE_B_HOST: return "b_host";
245 default: return "UNDEFINED";
249 static inline const char *state_name(struct isp1301 *isp)
251 return state_string(isp->otg.state);
254 /*-------------------------------------------------------------------------*/
256 /* NOTE: some of this ISP1301 setup is specific to H2 boards;
257 * not everything is guarded by board-specific checks, or even using
258 * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI.
260 * ALSO: this currently doesn't use ISP1301 low-power modes
261 * while OTG is running.
264 static void power_down(struct isp1301 *isp)
266 isp->otg.state = OTG_STATE_UNDEFINED;
268 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
269 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
271 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN);
272 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
275 static void power_up(struct isp1301 *isp)
277 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
278 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
280 /* do this only when cpu is driving transceiver,
281 * so host won't see a low speed device...
283 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
286 #define NO_HOST_SUSPEND
288 static int host_suspend(struct isp1301 *isp)
290 #ifdef NO_HOST_SUSPEND
298 /* Currently ASSUMES only the OTG port matters;
299 * other ports could be active...
301 dev = isp->otg.host->controller;
302 return dev->driver->suspend(dev, 3, 0);
306 static int host_resume(struct isp1301 *isp)
308 #ifdef NO_HOST_SUSPEND
316 dev = isp->otg.host->controller;
317 return dev->driver->resume(dev, 0);
321 static int gadget_suspend(struct isp1301 *isp)
323 isp->otg.gadget->b_hnp_enable = 0;
324 isp->otg.gadget->a_hnp_support = 0;
325 isp->otg.gadget->a_alt_hnp_support = 0;
326 return usb_gadget_vbus_disconnect(isp->otg.gadget);
329 /*-------------------------------------------------------------------------*/
331 #define TIMER_MINUTES 10
332 #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
334 /* Almost all our I2C messaging comes from a work queue's task context.
335 * NOTE: guaranteeing certain response times might mean we shouldn't
336 * share keventd's work queue; a realtime task might be safest.
339 isp1301_defer_work(struct isp1301 *isp, int work)
343 if (isp && !test_and_set_bit(work, &isp->todo)) {
344 (void) get_device(&isp->client->dev);
345 status = schedule_work(&isp->work);
346 if (!status && !isp->working)
347 dev_vdbg(&isp->client->dev,
348 "work item %d may be lost\n", work);
352 /* called from irq handlers */
353 static void a_idle(struct isp1301 *isp, const char *tag)
357 if (isp->otg.state == OTG_STATE_A_IDLE)
360 isp->otg.default_a = 1;
362 isp->otg.host->is_b_host = 0;
365 if (isp->otg.gadget) {
366 isp->otg.gadget->is_a_peripheral = 1;
369 isp->otg.state = OTG_STATE_A_IDLE;
370 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
371 omap_writel(l, OTG_CTRL);
372 isp->last_otg_ctrl = l;
373 pr_debug(" --> %s/%s\n", state_name(isp), tag);
376 /* called from irq handlers */
377 static void b_idle(struct isp1301 *isp, const char *tag)
381 if (isp->otg.state == OTG_STATE_B_IDLE)
384 isp->otg.default_a = 0;
386 isp->otg.host->is_b_host = 1;
389 if (isp->otg.gadget) {
390 isp->otg.gadget->is_a_peripheral = 0;
393 isp->otg.state = OTG_STATE_B_IDLE;
394 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
395 omap_writel(l, OTG_CTRL);
396 isp->last_otg_ctrl = l;
397 pr_debug(" --> %s/%s\n", state_name(isp), tag);
401 dump_regs(struct isp1301 *isp, const char *label)
404 u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1);
405 u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
406 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
408 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
409 omap_readl(OTG_CTRL), label, state_name(isp),
411 /* mode control and irq enables don't change much */
415 /*-------------------------------------------------------------------------*/
417 #ifdef CONFIG_USB_OTG
420 * The OMAP OTG controller handles most of the OTG state transitions.
422 * We translate isp1301 outputs (mostly voltage comparator status) into
423 * OTG inputs; OTG outputs (mostly pullup/pulldown controls) and HNP state
424 * flags into isp1301 inputs ... and infer state transitions.
429 static void check_state(struct isp1301 *isp, const char *tag)
431 enum usb_otg_state state = OTG_STATE_UNDEFINED;
432 u8 fsm = omap_readw(OTG_TEST) & 0x0ff;
439 state = OTG_STATE_B_IDLE;
445 state = OTG_STATE_B_PERIPHERAL;
448 state = OTG_STATE_B_SRP_INIT;
451 /* extra dual-role default-b states */
457 state = OTG_STATE_B_WAIT_ACON;
460 state = OTG_STATE_B_HOST;
465 state = OTG_STATE_A_IDLE;
468 state = OTG_STATE_A_WAIT_VFALL;
471 state = OTG_STATE_A_VBUS_ERR;
477 state = OTG_STATE_A_PERIPHERAL;
480 state = OTG_STATE_A_WAIT_VRISE;
483 state = OTG_STATE_A_WAIT_BCON;
486 state = OTG_STATE_A_HOST;
489 state = OTG_STATE_A_SUSPEND;
494 if (isp->otg.state == state && !extra)
496 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
497 state_string(state), fsm, state_name(isp),
498 omap_readl(OTG_CTRL));
503 static inline void check_state(struct isp1301 *isp, const char *tag) { }
507 /* outputs from ISP1301_INTERRUPT_SOURCE */
508 static void update_otg1(struct isp1301 *isp, u8 int_src)
512 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
513 otg_ctrl &= ~OTG_XCEIV_INPUTS;
514 otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
517 if (int_src & INTR_SESS_VLD)
518 otg_ctrl |= OTG_ASESSVLD;
519 else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) {
520 a_idle(isp, "vfall");
521 otg_ctrl &= ~OTG_CTRL_BITS;
523 if (int_src & INTR_VBUS_VLD)
524 otg_ctrl |= OTG_VBUSVLD;
525 if (int_src & INTR_ID_GND) { /* default-A */
526 if (isp->otg.state == OTG_STATE_B_IDLE
527 || isp->otg.state == OTG_STATE_UNDEFINED) {
531 } else { /* default-B */
533 if (isp->otg.state == OTG_STATE_A_IDLE
534 || isp->otg.state == OTG_STATE_UNDEFINED) {
539 omap_writel(otg_ctrl, OTG_CTRL);
542 /* outputs from ISP1301_OTG_STATUS */
543 static void update_otg2(struct isp1301 *isp, u8 otg_status)
547 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
548 otg_ctrl &= ~OTG_XCEIV_INPUTS;
549 otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND);
550 if (otg_status & OTG_B_SESS_VLD)
551 otg_ctrl |= OTG_BSESSVLD;
552 else if (otg_status & OTG_B_SESS_END)
553 otg_ctrl |= OTG_BSESSEND;
554 omap_writel(otg_ctrl, OTG_CTRL);
557 /* inputs going to ISP1301 */
558 static void otg_update_isp(struct isp1301 *isp)
560 u32 otg_ctrl, otg_change;
561 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
563 otg_ctrl = omap_readl(OTG_CTRL);
564 otg_change = otg_ctrl ^ isp->last_otg_ctrl;
565 isp->last_otg_ctrl = otg_ctrl;
566 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
568 switch (isp->otg.state) {
569 case OTG_STATE_B_IDLE:
570 case OTG_STATE_B_PERIPHERAL:
571 case OTG_STATE_B_SRP_INIT:
572 if (!(otg_ctrl & OTG_PULLUP)) {
573 // if (otg_ctrl & OTG_B_HNPEN) {
574 if (isp->otg.gadget->b_hnp_enable) {
575 isp->otg.state = OTG_STATE_B_WAIT_ACON;
576 pr_debug(" --> b_wait_acon\n");
581 set |= OTG1_DP_PULLUP;
582 clr |= OTG1_DP_PULLDOWN;
584 case OTG_STATE_A_SUSPEND:
585 case OTG_STATE_A_PERIPHERAL:
586 if (otg_ctrl & OTG_PULLUP)
589 // case OTG_STATE_B_WAIT_ACON:
592 set |= OTG1_DP_PULLDOWN;
593 clr |= OTG1_DP_PULLUP;
597 # define toggle(OTG,ISP) do { \
598 if (otg_ctrl & OTG) set |= ISP; \
602 if (!(isp->otg.host))
603 otg_ctrl &= ~OTG_DRV_VBUS;
605 switch (isp->otg.state) {
606 case OTG_STATE_A_SUSPEND:
607 if (otg_ctrl & OTG_DRV_VBUS) {
608 set |= OTG1_VBUS_DRV;
611 /* HNP failed for some reason (A_AIDL_BDIS timeout) */
615 case OTG_STATE_A_VBUS_ERR:
616 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
617 pr_debug(" --> a_wait_vfall\n");
619 case OTG_STATE_A_WAIT_VFALL:
620 /* FIXME usbcore thinks port power is still on ... */
621 clr |= OTG1_VBUS_DRV;
623 case OTG_STATE_A_IDLE:
624 if (otg_ctrl & OTG_DRV_VBUS) {
625 isp->otg.state = OTG_STATE_A_WAIT_VRISE;
626 pr_debug(" --> a_wait_vrise\n");
630 toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV);
633 toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG);
634 toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG);
638 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set);
639 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr);
641 /* HNP switch to host or peripheral; and SRP */
642 if (otg_change & OTG_PULLUP) {
645 switch (isp->otg.state) {
646 case OTG_STATE_B_IDLE:
647 if (clr & OTG1_DP_PULLUP)
649 isp->otg.state = OTG_STATE_B_PERIPHERAL;
650 pr_debug(" --> b_peripheral\n");
652 case OTG_STATE_A_SUSPEND:
653 if (clr & OTG1_DP_PULLUP)
655 isp->otg.state = OTG_STATE_A_PERIPHERAL;
656 pr_debug(" --> a_peripheral\n");
661 l = omap_readl(OTG_CTRL);
663 omap_writel(l, OTG_CTRL);
666 check_state(isp, __func__);
667 dump_regs(isp, "otg->isp1301");
670 static irqreturn_t omap_otg_irq(int irq, void *_isp)
672 u16 otg_irq = omap_readw(OTG_IRQ_SRC);
675 struct isp1301 *isp = _isp;
677 /* update ISP1301 transciever from OTG controller */
678 if (otg_irq & OPRT_CHG) {
679 omap_writew(OPRT_CHG, OTG_IRQ_SRC);
680 isp1301_defer_work(isp, WORK_UPDATE_ISP);
683 /* SRP to become b_peripheral failed */
684 } else if (otg_irq & B_SRP_TMROUT) {
685 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL));
688 /* gadget drivers that care should monitor all kinds of
689 * remote wakeup (SRP, normal) using their own timer
690 * to give "check cable and A-device" messages.
692 if (isp->otg.state == OTG_STATE_B_SRP_INIT)
693 b_idle(isp, "srp_timeout");
695 omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
698 /* HNP to become b_host failed */
699 } else if (otg_irq & B_HNP_FAIL) {
700 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
701 state_name(isp), omap_readl(OTG_CTRL));
704 otg_ctrl = omap_readl(OTG_CTRL);
705 otg_ctrl |= OTG_BUSDROP;
706 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
707 omap_writel(otg_ctrl, OTG_CTRL);
709 /* subset of b_peripheral()... */
710 isp->otg.state = OTG_STATE_B_PERIPHERAL;
711 pr_debug(" --> b_peripheral\n");
713 omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
716 /* detect SRP from B-device ... */
717 } else if (otg_irq & A_SRP_DETECT) {
718 pr_debug("otg: %s SRP_DETECT, %06x\n",
719 state_name(isp), omap_readl(OTG_CTRL));
721 isp1301_defer_work(isp, WORK_UPDATE_OTG);
722 switch (isp->otg.state) {
723 case OTG_STATE_A_IDLE:
726 isp1301_defer_work(isp, WORK_HOST_RESUME);
727 otg_ctrl = omap_readl(OTG_CTRL);
728 otg_ctrl |= OTG_A_BUSREQ;
729 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
732 omap_writel(otg_ctrl, OTG_CTRL);
738 omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
741 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
742 * we don't track them separately
744 } else if (otg_irq & A_REQ_TMROUT) {
745 otg_ctrl = omap_readl(OTG_CTRL);
746 pr_info("otg: BCON_TMOUT from %s, %06x\n",
747 state_name(isp), otg_ctrl);
750 otg_ctrl |= OTG_BUSDROP;
751 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
752 omap_writel(otg_ctrl, OTG_CTRL);
753 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
755 omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
758 /* A-supplied voltage fell too low; overcurrent */
759 } else if (otg_irq & A_VBUS_ERR) {
760 otg_ctrl = omap_readl(OTG_CTRL);
761 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
762 state_name(isp), otg_irq, otg_ctrl);
764 otg_ctrl |= OTG_BUSDROP;
765 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
766 omap_writel(otg_ctrl, OTG_CTRL);
767 isp->otg.state = OTG_STATE_A_VBUS_ERR;
769 omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
772 /* switch driver; the transciever code activates it,
773 * ungating the udc clock or resuming OHCI.
775 } else if (otg_irq & DRIVER_SWITCH) {
778 otg_ctrl = omap_readl(OTG_CTRL);
779 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
781 (otg_ctrl & OTG_DRIVER_SEL)
784 isp1301_defer_work(isp, WORK_UPDATE_ISP);
786 /* role is peripheral */
787 if (otg_ctrl & OTG_DRIVER_SEL) {
788 switch (isp->otg.state) {
789 case OTG_STATE_A_IDLE:
790 b_idle(isp, __func__);
795 isp1301_defer_work(isp, WORK_UPDATE_ISP);
799 if (!(otg_ctrl & OTG_ID)) {
800 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
801 omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL);
805 switch (isp->otg.state) {
806 case OTG_STATE_B_WAIT_ACON:
807 isp->otg.state = OTG_STATE_B_HOST;
808 pr_debug(" --> b_host\n");
811 case OTG_STATE_A_WAIT_BCON:
812 isp->otg.state = OTG_STATE_A_HOST;
813 pr_debug(" --> a_host\n");
815 case OTG_STATE_A_PERIPHERAL:
816 isp->otg.state = OTG_STATE_A_WAIT_BCON;
817 pr_debug(" --> a_wait_bcon\n");
822 isp1301_defer_work(isp, WORK_HOST_RESUME);
826 omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
830 usb_bus_start_enum(isp->otg.host,
831 isp->otg.host->otg_port);
834 check_state(isp, __func__);
838 static struct platform_device *otg_dev;
840 static int otg_init(struct isp1301 *isp)
847 dump_regs(isp, __func__);
848 /* some of these values are board-specific... */
849 l = omap_readl(OTG_SYSCON_2);
852 | SRP_GPDATA /* 9msec Bdev D+ pulse */
853 | SRP_GPDVBUS /* discharge after VBUS pulse */
854 // | (3 << 24) /* 2msec VBUS pulse */
856 | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
857 | SRP_DPW /* detect 167+ns SRP pulses */
858 | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */
860 omap_writel(l, OTG_SYSCON_2);
862 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
863 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
865 check_state(isp, __func__);
866 pr_debug("otg: %s, %s %06x\n",
867 state_name(isp), __func__, omap_readl(OTG_CTRL));
869 omap_writew(DRIVER_SWITCH | OPRT_CHG
870 | B_SRP_TMROUT | B_HNP_FAIL
871 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN);
873 l = omap_readl(OTG_SYSCON_2);
875 omap_writel(l, OTG_SYSCON_2);
880 static int otg_probe(struct platform_device *dev)
882 // struct omap_usb_config *config = dev->platform_data;
888 static int otg_remove(struct platform_device *dev)
894 struct platform_driver omap_otg_driver = {
896 .remove = otg_remove,
898 .owner = THIS_MODULE,
903 static int otg_bind(struct isp1301 *isp)
910 status = platform_driver_register(&omap_otg_driver);
915 status = request_irq(otg_dev->resource[1].start, omap_otg_irq,
916 IRQF_DISABLED, DRIVER_NAME, isp);
921 platform_driver_unregister(&omap_otg_driver);
925 static void otg_unbind(struct isp1301 *isp)
929 free_irq(otg_dev->resource[1].start, isp);
934 /* OTG controller isn't clocked */
936 #endif /* CONFIG_USB_OTG */
938 /*-------------------------------------------------------------------------*/
940 static void b_peripheral(struct isp1301 *isp)
944 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
945 omap_writel(l, OTG_CTRL);
947 usb_gadget_vbus_connect(isp->otg.gadget);
949 #ifdef CONFIG_USB_OTG
950 enable_vbus_draw(isp, 8);
953 enable_vbus_draw(isp, 100);
954 /* UDC driver just set OTG_BSESSVLD */
955 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP);
956 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN);
957 isp->otg.state = OTG_STATE_B_PERIPHERAL;
958 pr_debug(" --> b_peripheral\n");
959 dump_regs(isp, "2periph");
963 static void isp_update_otg(struct isp1301 *isp, u8 stat)
965 u8 isp_stat, isp_bstat;
966 enum usb_otg_state state = isp->otg.state;
968 if (stat & INTR_BDIS_ACON)
969 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp));
971 /* start certain state transitions right away */
972 isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
973 if (isp_stat & INTR_ID_GND) {
974 if (isp->otg.default_a) {
976 case OTG_STATE_B_IDLE:
979 case OTG_STATE_A_IDLE:
980 enable_vbus_source(isp);
982 case OTG_STATE_A_WAIT_VRISE:
983 /* we skip over OTG_STATE_A_WAIT_BCON, since
984 * the HC will transition to A_HOST (or
985 * A_SUSPEND!) without our noticing except
988 if (isp_stat & INTR_VBUS_VLD)
989 isp->otg.state = OTG_STATE_A_HOST;
991 case OTG_STATE_A_WAIT_VFALL:
992 if (!(isp_stat & INTR_SESS_VLD))
993 a_idle(isp, "vfell");
996 if (!(isp_stat & INTR_VBUS_VLD))
997 isp->otg.state = OTG_STATE_A_VBUS_ERR;
1000 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1003 case OTG_STATE_B_PERIPHERAL:
1004 case OTG_STATE_B_HOST:
1005 case OTG_STATE_B_WAIT_ACON:
1006 usb_gadget_vbus_disconnect(isp->otg.gadget);
1011 if (state != OTG_STATE_A_IDLE)
1013 if (isp->otg.host && state == OTG_STATE_A_IDLE)
1014 isp1301_defer_work(isp, WORK_HOST_RESUME);
1020 /* if user unplugged mini-A end of cable,
1021 * don't bypass A_WAIT_VFALL.
1023 if (isp->otg.default_a) {
1026 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
1028 case OTG_STATE_A_WAIT_VFALL:
1029 state = OTG_STATE_A_IDLE;
1030 /* khubd may take a while to notice and
1031 * handle this disconnect, so don't go
1032 * to B_IDLE quite yet.
1035 case OTG_STATE_A_IDLE:
1037 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
1039 isp->otg.state = OTG_STATE_B_IDLE;
1040 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1041 l &= ~OTG_CTRL_BITS;
1042 omap_writel(l, OTG_CTRL);
1044 case OTG_STATE_B_IDLE:
1048 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1050 switch (isp->otg.state) {
1051 case OTG_STATE_B_PERIPHERAL:
1052 case OTG_STATE_B_WAIT_ACON:
1053 case OTG_STATE_B_HOST:
1054 if (likely(isp_bstat & OTG_B_SESS_VLD))
1056 enable_vbus_draw(isp, 0);
1057 #ifndef CONFIG_USB_OTG
1058 /* UDC driver will clear OTG_BSESSVLD */
1059 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1061 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1063 dump_regs(isp, __func__);
1066 case OTG_STATE_B_SRP_INIT:
1067 b_idle(isp, __func__);
1068 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
1069 omap_writel(l, OTG_CTRL);
1071 case OTG_STATE_B_IDLE:
1072 if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) {
1073 #ifdef CONFIG_USB_OTG
1074 update_otg1(isp, isp_stat);
1075 update_otg2(isp, isp_bstat);
1078 } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD)))
1079 isp_bstat |= OTG_B_SESS_END;
1081 case OTG_STATE_A_WAIT_VFALL:
1084 pr_debug("otg: unsupported b-device %s\n",
1090 if (state != isp->otg.state)
1091 pr_debug(" isp, %s -> %s\n",
1092 state_string(state), state_name(isp));
1094 #ifdef CONFIG_USB_OTG
1095 /* update the OTG controller state to match the isp1301; may
1096 * trigger OPRT_CHG irqs for changes going to the isp1301.
1098 update_otg1(isp, isp_stat);
1099 update_otg2(isp, isp_bstat);
1100 check_state(isp, __func__);
1103 dump_regs(isp, "isp1301->otg");
1106 /*-------------------------------------------------------------------------*/
1108 static u8 isp1301_clear_latch(struct isp1301 *isp)
1110 u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH);
1111 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch);
1116 isp1301_work(struct work_struct *work)
1118 struct isp1301 *isp = container_of(work, struct isp1301, work);
1121 /* implicit lock: we're the only task using this device */
1124 stop = test_bit(WORK_STOP, &isp->todo);
1126 #ifdef CONFIG_USB_OTG
1127 /* transfer state from otg engine to isp1301 */
1128 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1129 otg_update_isp(isp);
1130 put_device(&isp->client->dev);
1133 /* transfer state from isp1301 to otg engine */
1134 if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) {
1135 u8 stat = isp1301_clear_latch(isp);
1137 isp_update_otg(isp, stat);
1138 put_device(&isp->client->dev);
1141 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
1145 * skip A_WAIT_VRISE; hc transitions invisibly
1146 * skip A_WAIT_BCON; same.
1148 switch (isp->otg.state) {
1149 case OTG_STATE_A_WAIT_BCON:
1150 case OTG_STATE_A_WAIT_VRISE:
1151 isp->otg.state = OTG_STATE_A_HOST;
1152 pr_debug(" --> a_host\n");
1153 otg_ctrl = omap_readl(OTG_CTRL);
1154 otg_ctrl |= OTG_A_BUSREQ;
1155 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
1157 omap_writel(otg_ctrl, OTG_CTRL);
1159 case OTG_STATE_B_WAIT_ACON:
1160 isp->otg.state = OTG_STATE_B_HOST;
1161 pr_debug(" --> b_host (acon)\n");
1163 case OTG_STATE_B_HOST:
1164 case OTG_STATE_B_IDLE:
1165 case OTG_STATE_A_IDLE:
1168 pr_debug(" host resume in %s\n",
1173 put_device(&isp->client->dev);
1176 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
1178 dump_regs(isp, "timer");
1180 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1182 put_device(&isp->client->dev);
1186 dev_vdbg(&isp->client->dev,
1187 "work done, todo = 0x%lx\n",
1190 dev_dbg(&isp->client->dev, "stop\n");
1193 } while (isp->todo);
1197 static irqreturn_t isp1301_irq(int irq, void *isp)
1199 isp1301_defer_work(isp, WORK_UPDATE_OTG);
1203 static void isp1301_timer(unsigned long _isp)
1205 isp1301_defer_work((void *)_isp, WORK_TIMER);
1208 /*-------------------------------------------------------------------------*/
1210 static void isp1301_release(struct device *dev)
1212 struct isp1301 *isp;
1214 isp = dev_get_drvdata(dev);
1216 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1217 if (isp->i2c_release)
1218 isp->i2c_release(dev);
1222 static struct isp1301 *the_transceiver;
1224 static int __exit isp1301_remove(struct i2c_client *i2c)
1226 struct isp1301 *isp;
1228 isp = i2c_get_clientdata(i2c);
1230 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1231 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1232 free_irq(i2c->irq, isp);
1233 #ifdef CONFIG_USB_OTG
1236 if (machine_is_omap_h2())
1239 isp->timer.data = 0;
1240 set_bit(WORK_STOP, &isp->todo);
1241 del_timer_sync(&isp->timer);
1242 flush_scheduled_work();
1244 put_device(&i2c->dev);
1245 the_transceiver = 0;
1250 /*-------------------------------------------------------------------------*/
1252 /* NOTE: three modes are possible here, only one of which
1253 * will be standards-conformant on any given system:
1255 * - OTG mode (dual-role), required if there's a Mini-AB connector
1256 * - HOST mode, for when there's one or more A (host) connectors
1257 * - DEVICE mode, for when there's a B/Mini-B (device) connector
1259 * As a rule, you won't have an isp1301 chip unless it's there to
1260 * support the OTG mode. Other modes help testing USB controllers
1261 * in isolation from (full) OTG support, or maybe so later board
1262 * revisions can help to support those feature.
1265 #ifdef CONFIG_USB_OTG
1267 static int isp1301_otg_enable(struct isp1301 *isp)
1272 /* NOTE: since we don't change this, this provides
1273 * a few more interrupts than are strictly needed.
1275 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1276 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1277 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1278 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1280 dev_info(&isp->client->dev, "ready for dual-role USB ...\n");
1287 /* add or disable the host device+driver */
1289 isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1291 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1293 if (!otg || isp != the_transceiver)
1297 omap_writew(0, OTG_IRQ_EN);
1303 #ifdef CONFIG_USB_OTG
1304 isp->otg.host = host;
1305 dev_dbg(&isp->client->dev, "registered host\n");
1307 if (isp->otg.gadget)
1308 return isp1301_otg_enable(isp);
1311 #elif !defined(CONFIG_USB_GADGET_OMAP)
1312 // FIXME update its refcount
1313 isp->otg.host = host;
1317 if (machine_is_omap_h2())
1318 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1320 dev_info(&isp->client->dev, "A-Host sessions ok\n");
1321 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1323 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1326 /* If this has a Mini-AB connector, this mode is highly
1327 * nonstandard ... but can be handy for testing, especially with
1328 * the Mini-A end of an OTG cable. (Or something nonstandard
1329 * like MiniB-to-StandardB, maybe built with a gender mender.)
1331 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV);
1333 dump_regs(isp, __func__);
1338 dev_dbg(&isp->client->dev, "host sessions not allowed\n");
1345 isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1347 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1350 if (!otg || isp != the_transceiver)
1354 omap_writew(0, OTG_IRQ_EN);
1355 if (!isp->otg.default_a)
1356 enable_vbus_draw(isp, 0);
1357 usb_gadget_vbus_disconnect(isp->otg.gadget);
1358 isp->otg.gadget = 0;
1363 #ifdef CONFIG_USB_OTG
1364 isp->otg.gadget = gadget;
1365 dev_dbg(&isp->client->dev, "registered gadget\n");
1366 /* gadget driver may be suspended until vbus_connect () */
1368 return isp1301_otg_enable(isp);
1371 #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1372 isp->otg.gadget = gadget;
1373 // FIXME update its refcount
1375 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1376 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS);
1378 omap_writel(l, OTG_CTRL);
1381 isp->otg.state = OTG_STATE_B_IDLE;
1383 if (machine_is_omap_h2())
1384 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1386 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1388 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1390 dev_info(&isp->client->dev, "B-Peripheral sessions ok\n");
1391 dump_regs(isp, __func__);
1393 /* If this has a Mini-AB connector, this mode is highly
1394 * nonstandard ... but can be handy for testing, so long
1395 * as you don't plug a Mini-A cable into the jack.
1397 if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD)
1403 dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n");
1409 /*-------------------------------------------------------------------------*/
1412 isp1301_set_power(struct otg_transceiver *dev, unsigned mA)
1414 if (!the_transceiver)
1416 if (dev->state == OTG_STATE_B_PERIPHERAL)
1417 enable_vbus_draw(the_transceiver, mA);
1422 isp1301_start_srp(struct otg_transceiver *dev)
1424 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1427 if (!dev || isp != the_transceiver
1428 || isp->otg.state != OTG_STATE_B_IDLE)
1431 otg_ctrl = omap_readl(OTG_CTRL);
1432 if (!(otg_ctrl & OTG_BSESSEND))
1435 otg_ctrl |= OTG_B_BUSREQ;
1436 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
1437 omap_writel(otg_ctrl, OTG_CTRL);
1438 isp->otg.state = OTG_STATE_B_SRP_INIT;
1440 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp),
1441 omap_readl(OTG_CTRL));
1442 #ifdef CONFIG_USB_OTG
1443 check_state(isp, __func__);
1449 isp1301_start_hnp(struct otg_transceiver *dev)
1451 #ifdef CONFIG_USB_OTG
1452 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1455 if (!dev || isp != the_transceiver)
1457 if (isp->otg.default_a && (isp->otg.host == NULL
1458 || !isp->otg.host->b_hnp_enable))
1460 if (!isp->otg.default_a && (isp->otg.gadget == NULL
1461 || !isp->otg.gadget->b_hnp_enable))
1464 /* We want hardware to manage most HNP protocol timings.
1465 * So do this part as early as possible...
1467 switch (isp->otg.state) {
1468 case OTG_STATE_B_HOST:
1469 isp->otg.state = OTG_STATE_B_PERIPHERAL;
1470 /* caller will suspend next */
1472 case OTG_STATE_A_HOST:
1474 /* autoconnect mode avoids irq latency bugs */
1475 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1478 /* caller must suspend then clear A_BUSREQ */
1479 usb_gadget_vbus_connect(isp->otg.gadget);
1480 l = omap_readl(OTG_CTRL);
1481 l |= OTG_A_SETB_HNPEN;
1482 omap_writel(l, OTG_CTRL);
1485 case OTG_STATE_A_PERIPHERAL:
1486 /* initiated by B-Host suspend */
1491 pr_debug("otg: HNP %s, %06x ...\n",
1492 state_name(isp), omap_readl(OTG_CTRL));
1493 check_state(isp, __func__);
1501 /*-------------------------------------------------------------------------*/
1503 static int __init isp1301_probe(struct i2c_client *i2c)
1506 struct isp1301 *isp;
1508 if (the_transceiver)
1511 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1515 INIT_WORK(&isp->work, isp1301_work);
1516 init_timer(&isp->timer);
1517 isp->timer.function = isp1301_timer;
1518 isp->timer.data = (unsigned long) isp;
1520 i2c_set_clientdata(i2c, isp);
1523 /* verify the chip (shouldn't be necesary) */
1524 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1525 if (status != I2C_VENDOR_ID_PHILIPS) {
1526 dev_dbg(&i2c->dev, "not philips id: %d\n", status);
1529 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1530 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1531 dev_dbg(&i2c->dev, "not isp1301, %d\n", status);
1534 isp->i2c_release = i2c->dev.release;
1535 i2c->dev.release = isp1301_release;
1537 /* initial development used chiprev 2.00 */
1538 status = i2c_smbus_read_word_data(i2c, ISP1301_BCD_DEVICE);
1539 dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n",
1540 status >> 8, status & 0xff);
1542 /* make like power-on reset */
1543 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK);
1545 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI);
1546 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI);
1548 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1549 OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
1550 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1551 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
1553 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0);
1554 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1555 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1557 #ifdef CONFIG_USB_OTG
1558 status = otg_bind(isp);
1560 dev_dbg(&i2c->dev, "can't bind OTG\n");
1565 if (machine_is_omap_h2()) {
1566 /* full speed signaling by default */
1567 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1569 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2,
1572 /* IRQ wired at M14 */
1573 omap_cfg_reg(M14_1510_GPIO2);
1574 if (gpio_request(2, "isp1301") == 0)
1575 gpio_direction_input(2);
1576 isp->irq_type = IRQF_TRIGGER_FALLING;
1579 isp->irq_type |= IRQF_SAMPLE_RANDOM;
1580 status = request_irq(i2c->irq, isp1301_irq,
1581 isp->irq_type, DRIVER_NAME, isp);
1583 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n",
1588 isp->otg.dev = &i2c->dev;
1589 isp->otg.label = DRIVER_NAME;
1591 isp->otg.set_host = isp1301_set_host,
1592 isp->otg.set_peripheral = isp1301_set_peripheral,
1593 isp->otg.set_power = isp1301_set_power,
1594 isp->otg.start_srp = isp1301_start_srp,
1595 isp->otg.start_hnp = isp1301_start_hnp,
1597 enable_vbus_draw(isp, 0);
1599 the_transceiver = isp;
1601 #ifdef CONFIG_USB_OTG
1602 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
1603 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
1606 dump_regs(isp, __func__);
1609 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1610 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1613 status = otg_set_transceiver(&isp->otg);
1615 dev_err(&i2c->dev, "can't register transceiver, %d\n",
1625 static const struct i2c_device_id isp1301_id[] = {
1626 { "isp1301_omap", 0 },
1629 MODULE_DEVICE_TABLE(i2c, isp1301_id);
1631 static struct i2c_driver isp1301_driver = {
1633 .name = "isp1301_omap",
1635 .probe = isp1301_probe,
1636 .remove = __exit_p(isp1301_remove),
1637 .id_table = isp1301_id,
1640 /*-------------------------------------------------------------------------*/
1642 static int __init isp_init(void)
1644 return i2c_add_driver(&isp1301_driver);
1646 module_init(isp_init);
1648 static void __exit isp_exit(void)
1650 if (the_transceiver)
1651 otg_set_transceiver(0);
1652 i2c_del_driver(&isp1301_driver);
1654 module_exit(isp_exit);