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.
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
29 #include <linux/interrupt.h>
30 #include <linux/platform_device.h>
31 #include <linux/usb/ch9.h>
32 #include <linux/usb/gadget.h>
33 #include <linux/usb.h>
34 #include <linux/usb/otg.h>
35 #include <linux/i2c.h>
36 #include <linux/workqueue.h>
37 #include <asm/arch/usb.h>
39 #include <asm/mach-types.h> /* FIXME: Move machine_is_* to board-*.c files */
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);
59 struct timer_list timer;
61 /* use keventd context to change the state for us */
62 struct work_struct work;
65 # define WORK_UPDATE_ISP 0 /* update ISP from OTG */
66 # define WORK_UPDATE_OTG 1 /* update OTG from ISP */
67 # define WORK_HOST_RESUME 4 /* resume host */
68 # define WORK_TIMER 6 /* timer fired */
69 # define WORK_STOP 7 /* don't resubmit */
73 /* bits in OTG_CTRL */
75 #define OTG_XCEIV_OUTPUTS \
76 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
77 #define OTG_XCEIV_INPUTS \
78 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
79 #define OTG_CTRL_BITS \
80 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
81 /* and OTG_PULLUP is sometimes written */
83 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
84 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
88 /*-------------------------------------------------------------------------*/
90 #if defined(CONFIG_MACH_OMAP_H2) || \
91 defined(CONFIG_MACH_OMAP_H3)
93 /* board-specific PM hooks */
96 #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
98 #include <linux/i2c/tps65010.h>
102 static inline int tps65010_set_vbus_draw(unsigned mA)
104 pr_debug("tps65010: draw %d mA (STUB)\n", mA);
110 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
112 int status = tps65010_set_vbus_draw(mA);
114 pr_debug(" VBUS %d mA error %d\n", mA, status);
117 static void enable_vbus_source(struct isp1301 *isp)
119 /* this board won't supply more than 8mA vbus power.
120 * some boards can switch a 100ma "unit load" (or more).
127 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
129 pr_debug("%s UNIMPL\n", __FUNCTION__);
132 static void enable_vbus_source(struct isp1301 *isp)
134 pr_debug("%s UNIMPL\n", __FUNCTION__);
139 /*-------------------------------------------------------------------------*/
141 /* products will deliver OTG messages with LEDs, GUI, etc */
142 static inline void notresponding(struct isp1301 *isp)
144 printk(KERN_NOTICE "OTG device not responding.\n");
147 /*-------------------------------------------------------------------------*/
149 /* only two addresses possible */
150 static struct i2c_driver isp1301_driver;
152 /* smbus apis are used for portability */
155 isp1301_get_u8(struct isp1301 *isp, u8 reg)
157 return i2c_smbus_read_byte_data(isp->client, reg + 0);
161 isp1301_get_u16(struct isp1301 *isp, u8 reg)
163 return i2c_smbus_read_word_data(isp->client, reg);
167 isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
169 return i2c_smbus_write_byte_data(isp->client, reg + 0, bits);
173 isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
175 return i2c_smbus_write_byte_data(isp->client, reg + 1, bits);
178 /*-------------------------------------------------------------------------*/
181 #define ISP1301_VENDOR_ID 0x00 /* u16 read */
182 #define ISP1301_PRODUCT_ID 0x02 /* u16 read */
183 #define ISP1301_BCD_DEVICE 0x14 /* u16 read */
185 #define I2C_VENDOR_ID_PHILIPS 0x04cc
186 #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
188 /* operational registers */
189 #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
190 # define MC1_SPEED (1 << 0)
191 # define MC1_SUSPEND (1 << 1)
192 # define MC1_DAT_SE0 (1 << 2)
193 # define MC1_TRANSPARENT (1 << 3)
194 # define MC1_BDIS_ACON_EN (1 << 4)
195 # define MC1_OE_INT_EN (1 << 5)
196 # define MC1_UART_EN (1 << 6)
197 # define MC1_MASK 0x7f
198 #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
199 # define MC2_GLOBAL_PWR_DN (1 << 0)
200 # define MC2_SPD_SUSP_CTRL (1 << 1)
201 # define MC2_BI_DI (1 << 2)
202 # define MC2_TRANSP_BDIR0 (1 << 3)
203 # define MC2_TRANSP_BDIR1 (1 << 4)
204 # define MC2_AUDIO_EN (1 << 5)
205 # define MC2_PSW_EN (1 << 6)
206 # define MC2_EN2V7 (1 << 7)
207 #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
208 # define OTG1_DP_PULLUP (1 << 0)
209 # define OTG1_DM_PULLUP (1 << 1)
210 # define OTG1_DP_PULLDOWN (1 << 2)
211 # define OTG1_DM_PULLDOWN (1 << 3)
212 # define OTG1_ID_PULLDOWN (1 << 4)
213 # define OTG1_VBUS_DRV (1 << 5)
214 # define OTG1_VBUS_DISCHRG (1 << 6)
215 # define OTG1_VBUS_CHRG (1 << 7)
216 #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
217 # define OTG_B_SESS_END (1 << 6)
218 # define OTG_B_SESS_VLD (1 << 7)
220 #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */
221 #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */
223 #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */
224 #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */
226 /* same bitfields in all interrupt registers */
227 # define INTR_VBUS_VLD (1 << 0)
228 # define INTR_SESS_VLD (1 << 1)
229 # define INTR_DP_HI (1 << 2)
230 # define INTR_ID_GND (1 << 3)
231 # define INTR_DM_HI (1 << 4)
232 # define INTR_ID_FLOAT (1 << 5)
233 # define INTR_BDIS_ACON (1 << 6)
234 # define INTR_CR_INT (1 << 7)
236 /*-------------------------------------------------------------------------*/
238 static const char *state_string(enum usb_otg_state state)
241 case OTG_STATE_A_IDLE: return "a_idle";
242 case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
243 case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
244 case OTG_STATE_A_HOST: return "a_host";
245 case OTG_STATE_A_SUSPEND: return "a_suspend";
246 case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
247 case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
248 case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
249 case OTG_STATE_B_IDLE: return "b_idle";
250 case OTG_STATE_B_SRP_INIT: return "b_srp_init";
251 case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
252 case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
253 case OTG_STATE_B_HOST: return "b_host";
254 default: return "UNDEFINED";
258 static inline const char *state_name(struct isp1301 *isp)
260 return state_string(isp->otg.state);
263 /*-------------------------------------------------------------------------*/
265 /* NOTE: some of this ISP1301 setup is specific to H2 boards;
266 * not everything is guarded by board-specific checks, or even using
267 * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI.
269 * ALSO: this currently doesn't use ISP1301 low-power modes
270 * while OTG is running.
273 static void power_down(struct isp1301 *isp)
275 isp->otg.state = OTG_STATE_UNDEFINED;
277 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
278 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
280 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN);
281 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
284 static void power_up(struct isp1301 *isp)
286 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
287 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
289 /* do this only when cpu is driving transceiver,
290 * so host won't see a low speed device...
292 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
295 #define NO_HOST_SUSPEND
297 static int host_suspend(struct isp1301 *isp)
299 #ifdef NO_HOST_SUSPEND
307 /* Currently ASSUMES only the OTG port matters;
308 * other ports could be active...
310 dev = isp->otg.host->controller;
311 return dev->driver->suspend(dev, 3, 0);
315 static int host_resume(struct isp1301 *isp)
317 #ifdef NO_HOST_SUSPEND
325 dev = isp->otg.host->controller;
326 return dev->driver->resume(dev, 0);
330 static int gadget_suspend(struct isp1301 *isp)
332 isp->otg.gadget->b_hnp_enable = 0;
333 isp->otg.gadget->a_hnp_support = 0;
334 isp->otg.gadget->a_alt_hnp_support = 0;
335 return usb_gadget_vbus_disconnect(isp->otg.gadget);
338 /*-------------------------------------------------------------------------*/
340 #define TIMER_MINUTES 10
341 #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
343 /* Almost all our I2C messaging comes from a work queue's task context.
344 * NOTE: guaranteeing certain response times might mean we shouldn't
345 * share keventd's work queue; a realtime task might be safest.
348 isp1301_defer_work(struct isp1301 *isp, int work)
352 if (isp && !test_and_set_bit(work, &isp->todo)) {
353 (void) get_device(&isp->client->dev);
354 status = schedule_work(&isp->work);
355 if (!status && !isp->working)
356 dev_vdbg(&isp->client->dev,
357 "work item %d may be lost\n", work);
361 /* called from irq handlers */
362 static void a_idle(struct isp1301 *isp, const char *tag)
366 if (isp->otg.state == OTG_STATE_A_IDLE)
369 isp->otg.default_a = 1;
371 isp->otg.host->is_b_host = 0;
374 if (isp->otg.gadget) {
375 isp->otg.gadget->is_a_peripheral = 1;
378 isp->otg.state = OTG_STATE_A_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);
385 /* called from irq handlers */
386 static void b_idle(struct isp1301 *isp, const char *tag)
390 if (isp->otg.state == OTG_STATE_B_IDLE)
393 isp->otg.default_a = 0;
395 isp->otg.host->is_b_host = 1;
398 if (isp->otg.gadget) {
399 isp->otg.gadget->is_a_peripheral = 0;
402 isp->otg.state = OTG_STATE_B_IDLE;
403 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
404 omap_writel(l, OTG_CTRL);
405 isp->last_otg_ctrl = l;
406 pr_debug(" --> %s/%s\n", state_name(isp), tag);
410 dump_regs(struct isp1301 *isp, const char *label)
413 u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1);
414 u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
415 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
417 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
418 omap_readl(OTG_CTRL), label, state_name(isp),
420 /* mode control and irq enables don't change much */
424 /*-------------------------------------------------------------------------*/
426 #ifdef CONFIG_USB_OTG
429 * The OMAP OTG controller handles most of the OTG state transitions.
431 * We translate isp1301 outputs (mostly voltage comparator status) into
432 * OTG inputs; OTG outputs (mostly pullup/pulldown controls) and HNP state
433 * flags into isp1301 inputs ... and infer state transitions.
438 static void check_state(struct isp1301 *isp, const char *tag)
440 enum usb_otg_state state = OTG_STATE_UNDEFINED;
441 u8 fsm = omap_readw(OTG_TEST) & 0x0ff;
448 state = OTG_STATE_B_IDLE;
454 state = OTG_STATE_B_PERIPHERAL;
457 state = OTG_STATE_B_SRP_INIT;
460 /* extra dual-role default-b states */
466 state = OTG_STATE_B_WAIT_ACON;
469 state = OTG_STATE_B_HOST;
474 state = OTG_STATE_A_IDLE;
477 state = OTG_STATE_A_WAIT_VFALL;
480 state = OTG_STATE_A_VBUS_ERR;
486 state = OTG_STATE_A_PERIPHERAL;
489 state = OTG_STATE_A_WAIT_VRISE;
492 state = OTG_STATE_A_WAIT_BCON;
495 state = OTG_STATE_A_HOST;
498 state = OTG_STATE_A_SUSPEND;
503 if (isp->otg.state == state && !extra)
505 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
506 state_string(state), fsm, state_name(isp),
507 omap_readl(OTG_CTRL));
512 static inline void check_state(struct isp1301 *isp, const char *tag) { }
516 /* outputs from ISP1301_INTERRUPT_SOURCE */
517 static void update_otg1(struct isp1301 *isp, u8 int_src)
522 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
523 otg_ctrl &= ~OTG_XCEIV_INPUTS;
524 otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
527 if (int_src & INTR_SESS_VLD)
528 otg_ctrl |= OTG_ASESSVLD;
529 else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) {
530 a_idle(isp, "vfall");
531 otg_ctrl &= ~OTG_CTRL_BITS;
533 if (int_src & INTR_VBUS_VLD)
534 otg_ctrl |= OTG_VBUSVLD;
536 int_id = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
538 if (int_id & INTR_ID_GND) { /* default-A */
539 if (isp->otg.state == OTG_STATE_B_IDLE
540 || isp->otg.state == OTG_STATE_UNDEFINED) {
544 } else { /* default-B */
546 if (isp->otg.state == OTG_STATE_A_IDLE
547 || isp->otg.state == OTG_STATE_UNDEFINED) {
552 omap_writel(otg_ctrl, OTG_CTRL);
555 /* outputs from ISP1301_OTG_STATUS */
556 static void update_otg2(struct isp1301 *isp, u8 otg_status)
560 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
561 otg_ctrl &= ~OTG_XCEIV_INPUTS;
562 otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND);
563 if (otg_status & OTG_B_SESS_VLD)
564 otg_ctrl |= OTG_BSESSVLD;
565 else if (otg_status & OTG_B_SESS_END)
566 otg_ctrl |= OTG_BSESSEND;
567 omap_writel(otg_ctrl, OTG_CTRL);
570 /* inputs going to ISP1301 */
571 static void otg_update_isp(struct isp1301 *isp)
573 u32 otg_ctrl, otg_change;
574 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
576 otg_ctrl = omap_readl(OTG_CTRL);
577 otg_change = otg_ctrl ^ isp->last_otg_ctrl;
578 isp->last_otg_ctrl = otg_ctrl;
579 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
581 switch (isp->otg.state) {
582 case OTG_STATE_B_IDLE:
583 case OTG_STATE_B_PERIPHERAL:
584 case OTG_STATE_B_SRP_INIT:
585 if (!(otg_ctrl & OTG_PULLUP)) {
586 // if (otg_ctrl & OTG_B_HNPEN) {
587 if (isp->otg.gadget->b_hnp_enable) {
588 isp->otg.state = OTG_STATE_B_WAIT_ACON;
589 pr_debug(" --> b_wait_acon\n");
594 set |= OTG1_DP_PULLUP;
595 clr |= OTG1_DP_PULLDOWN;
597 case OTG_STATE_A_SUSPEND:
598 case OTG_STATE_A_PERIPHERAL:
599 if (otg_ctrl & OTG_PULLUP)
602 // case OTG_STATE_B_WAIT_ACON:
605 set |= OTG1_DP_PULLDOWN;
606 clr |= OTG1_DP_PULLUP;
610 # define toggle(OTG,ISP) do { \
611 if (otg_ctrl & OTG) set |= ISP; \
615 if (!(isp->otg.host))
616 otg_ctrl &= ~OTG_DRV_VBUS;
618 switch (isp->otg.state) {
619 case OTG_STATE_A_SUSPEND:
620 if (otg_ctrl & OTG_DRV_VBUS) {
621 set |= OTG1_VBUS_DRV;
624 /* HNP failed for some reason (A_AIDL_BDIS timeout) */
628 case OTG_STATE_A_VBUS_ERR:
629 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
630 pr_debug(" --> a_wait_vfall\n");
632 case OTG_STATE_A_WAIT_VFALL:
633 /* FIXME usbcore thinks port power is still on ... */
634 clr |= OTG1_VBUS_DRV;
636 case OTG_STATE_A_IDLE:
637 if (otg_ctrl & OTG_DRV_VBUS) {
638 isp->otg.state = OTG_STATE_A_WAIT_VRISE;
639 pr_debug(" --> a_wait_vrise\n");
643 toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV);
646 toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG);
647 toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG);
651 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set);
652 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr);
654 /* HNP switch to host or peripheral; and SRP */
655 if (otg_change & OTG_PULLUP) {
658 switch (isp->otg.state) {
659 case OTG_STATE_B_IDLE:
660 if (clr & OTG1_DP_PULLUP)
662 isp->otg.state = OTG_STATE_B_PERIPHERAL;
663 pr_debug(" --> b_peripheral\n");
665 case OTG_STATE_A_SUSPEND:
666 if (clr & OTG1_DP_PULLUP)
668 isp->otg.state = OTG_STATE_A_PERIPHERAL;
669 pr_debug(" --> a_peripheral\n");
674 l = omap_readl(OTG_CTRL);
676 omap_writel(l, OTG_CTRL);
679 check_state(isp, __func__);
680 dump_regs(isp, "otg->isp1301");
683 static irqreturn_t omap_otg_irq(int irq, void *_isp)
685 u16 otg_irq = omap_readw(OTG_IRQ_SRC);
688 struct isp1301 *isp = _isp;
690 /* update ISP1301 transciever from OTG controller */
691 if (otg_irq & OPRT_CHG) {
692 omap_writew(OPRT_CHG, OTG_IRQ_SRC);
693 isp1301_defer_work(isp, WORK_UPDATE_ISP);
696 /* SRP to become b_peripheral failed */
697 } else if (otg_irq & B_SRP_TMROUT) {
698 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL));
701 /* gadget drivers that care should monitor all kinds of
702 * remote wakeup (SRP, normal) using their own timer
703 * to give "check cable and A-device" messages.
705 if (isp->otg.state == OTG_STATE_B_SRP_INIT)
706 b_idle(isp, "srp_timeout");
708 omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
711 /* HNP to become b_host failed */
712 } else if (otg_irq & B_HNP_FAIL) {
713 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
714 state_name(isp), omap_readl(OTG_CTRL));
717 otg_ctrl = omap_readl(OTG_CTRL);
718 otg_ctrl |= OTG_BUSDROP;
719 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
720 omap_writel(otg_ctrl, OTG_CTRL);
722 /* subset of b_peripheral()... */
723 isp->otg.state = OTG_STATE_B_PERIPHERAL;
724 pr_debug(" --> b_peripheral\n");
726 omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
729 /* detect SRP from B-device ... */
730 } else if (otg_irq & A_SRP_DETECT) {
731 pr_debug("otg: %s SRP_DETECT, %06x\n",
732 state_name(isp), omap_readl(OTG_CTRL));
734 isp1301_defer_work(isp, WORK_UPDATE_OTG);
735 switch (isp->otg.state) {
736 case OTG_STATE_A_IDLE:
739 isp1301_defer_work(isp, WORK_HOST_RESUME);
740 otg_ctrl = omap_readl(OTG_CTRL);
741 otg_ctrl |= OTG_A_BUSREQ;
742 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
745 omap_writel(otg_ctrl, OTG_CTRL);
751 omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
754 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
755 * we don't track them separately
757 } else if (otg_irq & A_REQ_TMROUT) {
758 otg_ctrl = omap_readl(OTG_CTRL);
759 pr_info("otg: BCON_TMOUT from %s, %06x\n",
760 state_name(isp), 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_WAIT_VFALL;
768 omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
771 /* A-supplied voltage fell too low; overcurrent */
772 } else if (otg_irq & A_VBUS_ERR) {
773 otg_ctrl = omap_readl(OTG_CTRL);
774 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
775 state_name(isp), otg_irq, otg_ctrl);
777 otg_ctrl |= OTG_BUSDROP;
778 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
779 omap_writel(otg_ctrl, OTG_CTRL);
780 isp->otg.state = OTG_STATE_A_VBUS_ERR;
782 omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
785 /* switch driver; the transciever code activates it,
786 * ungating the udc clock or resuming OHCI.
788 } else if (otg_irq & DRIVER_SWITCH) {
791 otg_ctrl = omap_readl(OTG_CTRL);
792 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
794 (otg_ctrl & OTG_DRIVER_SEL)
797 isp1301_defer_work(isp, WORK_UPDATE_ISP);
799 /* role is peripheral */
800 if (otg_ctrl & OTG_DRIVER_SEL) {
801 switch (isp->otg.state) {
802 case OTG_STATE_A_IDLE:
803 b_idle(isp, __func__);
808 isp1301_defer_work(isp, WORK_UPDATE_ISP);
812 if (!(otg_ctrl & OTG_ID)) {
813 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
814 omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL);
818 switch (isp->otg.state) {
819 case OTG_STATE_B_WAIT_ACON:
820 isp->otg.state = OTG_STATE_B_HOST;
821 pr_debug(" --> b_host\n");
824 case OTG_STATE_A_WAIT_BCON:
825 isp->otg.state = OTG_STATE_A_HOST;
826 pr_debug(" --> a_host\n");
828 case OTG_STATE_A_PERIPHERAL:
829 isp->otg.state = OTG_STATE_A_WAIT_BCON;
830 pr_debug(" --> a_wait_bcon\n");
835 isp1301_defer_work(isp, WORK_HOST_RESUME);
839 omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
843 usb_bus_start_enum(isp->otg.host,
844 isp->otg.host->otg_port);
847 check_state(isp, __func__);
851 static struct platform_device *otg_dev;
853 static int otg_init(struct isp1301 *isp)
860 dump_regs(isp, __func__);
861 /* some of these values are board-specific... */
862 l = omap_readl(OTG_SYSCON_2);
865 | SRP_GPDATA /* 9msec Bdev D+ pulse */
866 | SRP_GPDVBUS /* discharge after VBUS pulse */
867 // | (3 << 24) /* 2msec VBUS pulse */
869 | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
870 | SRP_DPW /* detect 167+ns SRP pulses */
871 | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */
873 omap_writel(l, OTG_SYSCON_2);
875 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
876 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
878 check_state(isp, __func__);
879 pr_debug("otg: %s, %s %06x\n",
880 state_name(isp), __func__, omap_readl(OTG_CTRL));
882 omap_writew(DRIVER_SWITCH | OPRT_CHG
883 | B_SRP_TMROUT | B_HNP_FAIL
884 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN);
886 l = omap_readl(OTG_SYSCON_2);
888 omap_writel(l, OTG_SYSCON_2);
893 static int otg_probe(struct platform_device *dev)
895 // struct omap_usb_config *config = dev->platform_data;
901 static int otg_remove(struct platform_device *dev)
907 struct platform_driver omap_otg_driver = {
909 .remove = otg_remove,
911 .owner = THIS_MODULE,
916 static int otg_bind(struct isp1301 *isp)
923 status = platform_driver_register(&omap_otg_driver);
928 status = request_irq(otg_dev->resource[1].start, omap_otg_irq,
929 IRQF_DISABLED, DRIVER_NAME, isp);
934 platform_driver_unregister(&omap_otg_driver);
938 static void otg_unbind(struct isp1301 *isp)
942 free_irq(otg_dev->resource[1].start, isp);
947 /* OTG controller isn't clocked */
949 #endif /* CONFIG_USB_OTG */
951 /*-------------------------------------------------------------------------*/
953 static void b_peripheral(struct isp1301 *isp)
957 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
958 omap_writel(l, OTG_CTRL);
960 usb_gadget_vbus_connect(isp->otg.gadget);
962 #ifdef CONFIG_USB_OTG
963 enable_vbus_draw(isp, 8);
966 enable_vbus_draw(isp, 100);
967 /* UDC driver just set OTG_BSESSVLD */
968 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP);
969 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN);
970 isp->otg.state = OTG_STATE_B_PERIPHERAL;
971 pr_debug(" --> b_peripheral\n");
972 dump_regs(isp, "2periph");
976 static void isp_update_otg(struct isp1301 *isp, u8 stat)
978 u8 isp_stat, isp_bstat;
979 enum usb_otg_state state = isp->otg.state;
981 if (stat & INTR_BDIS_ACON)
982 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp));
984 /* start certain state transitions right away */
985 isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
986 if (isp_stat & INTR_ID_GND) {
987 if (isp->otg.default_a) {
989 case OTG_STATE_B_IDLE:
992 case OTG_STATE_A_IDLE:
993 enable_vbus_source(isp);
995 case OTG_STATE_A_WAIT_VRISE:
996 /* we skip over OTG_STATE_A_WAIT_BCON, since
997 * the HC will transition to A_HOST (or
998 * A_SUSPEND!) without our noticing except
1001 if (isp_stat & INTR_VBUS_VLD)
1002 isp->otg.state = OTG_STATE_A_HOST;
1004 case OTG_STATE_A_WAIT_VFALL:
1005 if (!(isp_stat & INTR_SESS_VLD))
1006 a_idle(isp, "vfell");
1009 if (!(isp_stat & INTR_VBUS_VLD))
1010 isp->otg.state = OTG_STATE_A_VBUS_ERR;
1013 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1016 case OTG_STATE_B_PERIPHERAL:
1017 case OTG_STATE_B_HOST:
1018 case OTG_STATE_B_WAIT_ACON:
1019 usb_gadget_vbus_disconnect(isp->otg.gadget);
1024 if (state != OTG_STATE_A_IDLE)
1026 if (isp->otg.host && state == OTG_STATE_A_IDLE)
1027 isp1301_defer_work(isp, WORK_HOST_RESUME);
1033 /* if user unplugged mini-A end of cable,
1034 * don't bypass A_WAIT_VFALL.
1036 if (isp->otg.default_a) {
1039 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
1041 case OTG_STATE_A_WAIT_VFALL:
1042 state = OTG_STATE_A_IDLE;
1043 /* khubd may take a while to notice and
1044 * handle this disconnect, so don't go
1045 * to B_IDLE quite yet.
1048 case OTG_STATE_A_IDLE:
1050 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
1052 isp->otg.state = OTG_STATE_B_IDLE;
1053 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1054 l &= ~OTG_CTRL_BITS;
1055 omap_writel(l, OTG_CTRL);
1057 case OTG_STATE_B_IDLE:
1061 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1063 switch (isp->otg.state) {
1064 case OTG_STATE_B_PERIPHERAL:
1065 case OTG_STATE_B_WAIT_ACON:
1066 case OTG_STATE_B_HOST:
1067 if (likely(isp_bstat & OTG_B_SESS_VLD))
1069 enable_vbus_draw(isp, 0);
1070 #ifndef CONFIG_USB_OTG
1071 /* UDC driver will clear OTG_BSESSVLD */
1072 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1074 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1076 dump_regs(isp, __func__);
1079 case OTG_STATE_B_SRP_INIT:
1080 b_idle(isp, __func__);
1081 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
1082 omap_writel(l, OTG_CTRL);
1084 case OTG_STATE_B_IDLE:
1085 if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) {
1086 #ifdef CONFIG_USB_OTG
1087 update_otg1(isp, isp_stat);
1088 update_otg2(isp, isp_bstat);
1091 } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD)))
1092 isp_bstat |= OTG_B_SESS_END;
1094 case OTG_STATE_A_WAIT_VFALL:
1097 pr_debug("otg: unsupported b-device %s\n",
1103 if (state != isp->otg.state)
1104 pr_debug(" isp, %s -> %s\n",
1105 state_string(state), state_name(isp));
1107 #ifdef CONFIG_USB_OTG
1108 /* update the OTG controller state to match the isp1301; may
1109 * trigger OPRT_CHG irqs for changes going to the isp1301.
1111 update_otg1(isp, stat); // pass the actual interrupt latch status
1112 update_otg2(isp, isp_bstat);
1113 check_state(isp, __func__);
1116 dump_regs(isp, "isp1301->otg");
1119 /*-------------------------------------------------------------------------*/
1121 static u8 isp1301_clear_latch(struct isp1301 *isp)
1123 u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH);
1124 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch);
1129 isp1301_work(struct work_struct *work)
1131 struct isp1301 *isp = container_of(work, struct isp1301, work);
1134 /* implicit lock: we're the only task using this device */
1137 stop = test_bit(WORK_STOP, &isp->todo);
1139 #ifdef CONFIG_USB_OTG
1140 /* transfer state from otg engine to isp1301 */
1141 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1142 otg_update_isp(isp);
1143 put_device(&isp->client->dev);
1146 /* transfer state from isp1301 to otg engine */
1147 if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) {
1148 u8 stat = isp1301_clear_latch(isp);
1150 isp_update_otg(isp, stat);
1151 put_device(&isp->client->dev);
1154 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
1158 * skip A_WAIT_VRISE; hc transitions invisibly
1159 * skip A_WAIT_BCON; same.
1161 switch (isp->otg.state) {
1162 case OTG_STATE_A_WAIT_BCON:
1163 case OTG_STATE_A_WAIT_VRISE:
1164 isp->otg.state = OTG_STATE_A_HOST;
1165 pr_debug(" --> a_host\n");
1166 otg_ctrl = omap_readl(OTG_CTRL);
1167 otg_ctrl |= OTG_A_BUSREQ;
1168 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
1170 omap_writel(otg_ctrl, OTG_CTRL);
1172 case OTG_STATE_B_WAIT_ACON:
1173 isp->otg.state = OTG_STATE_B_HOST;
1174 pr_debug(" --> b_host (acon)\n");
1176 case OTG_STATE_B_HOST:
1177 case OTG_STATE_B_IDLE:
1178 case OTG_STATE_A_IDLE:
1181 pr_debug(" host resume in %s\n",
1186 put_device(&isp->client->dev);
1189 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
1191 dump_regs(isp, "timer");
1193 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1195 put_device(&isp->client->dev);
1199 dev_vdbg(&isp->client->dev,
1200 "work done, todo = 0x%lx\n",
1203 dev_dbg(&isp->client->dev, "stop\n");
1206 } while (isp->todo);
1210 static irqreturn_t isp1301_irq(int irq, void *isp)
1212 isp1301_defer_work(isp, WORK_UPDATE_OTG);
1216 static void isp1301_timer(unsigned long _isp)
1218 isp1301_defer_work((void *)_isp, WORK_TIMER);
1221 /*-------------------------------------------------------------------------*/
1223 static void isp1301_release(struct device *dev)
1225 struct i2c_client *client;
1226 struct isp1301 *isp;
1228 client = container_of(dev, struct i2c_client, dev);
1229 isp = i2c_get_clientdata(client);
1231 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1232 if (isp->i2c_release)
1233 isp->i2c_release(dev);
1237 static struct isp1301 *the_transceiver;
1239 static int __exit isp1301_remove(struct i2c_client *client)
1241 struct isp1301 *isp = i2c_get_clientdata(client);
1243 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1244 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1246 if (client->irq > 0)
1247 free_irq(client->irq, isp);
1248 #ifdef CONFIG_USB_OTG
1251 isp->timer.data = 0;
1252 set_bit(WORK_STOP, &isp->todo);
1253 del_timer_sync(&isp->timer);
1254 flush_scheduled_work();
1256 put_device(&client->dev);
1257 the_transceiver = 0;
1262 /*-------------------------------------------------------------------------*/
1264 /* NOTE: three modes are possible here, only one of which
1265 * will be standards-conformant on any given system:
1267 * - OTG mode (dual-role), required if there's a Mini-AB connector
1268 * - HOST mode, for when there's one or more A (host) connectors
1269 * - DEVICE mode, for when there's a B/Mini-B (device) connector
1271 * As a rule, you won't have an isp1301 chip unless it's there to
1272 * support the OTG mode. Other modes help testing USB controllers
1273 * in isolation from (full) OTG support, or maybe so later board
1274 * revisions can help to support those feature.
1277 #ifdef CONFIG_USB_OTG
1279 static int isp1301_otg_enable(struct isp1301 *isp)
1284 /* NOTE: since we don't change this, this provides
1285 * a few more interrupts than are strictly needed.
1287 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1288 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1289 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1290 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1292 dev_info(&isp->client->dev, "ready for dual-role USB ...\n");
1299 /* add or disable the host device+driver */
1301 isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1303 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1305 if (!otg || isp != the_transceiver)
1309 omap_writew(0, OTG_IRQ_EN);
1315 #ifdef CONFIG_USB_OTG
1316 isp->otg.host = host;
1317 dev_dbg(&isp->client->dev, "registered host\n");
1319 if (isp->otg.gadget)
1320 return isp1301_otg_enable(isp);
1323 #elif !defined(CONFIG_USB_GADGET_OMAP)
1324 // FIXME update its refcount
1325 isp->otg.host = host;
1329 dev_info(&isp->client->dev, "A-Host sessions ok\n");
1330 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1332 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1335 /* If this has a Mini-AB connector, this mode is highly
1336 * nonstandard ... but can be handy for testing, especially with
1337 * the Mini-A end of an OTG cable. (Or something nonstandard
1338 * like MiniB-to-StandardB, maybe built with a gender mender.)
1340 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV);
1342 dump_regs(isp, __func__);
1347 dev_dbg(&isp->client->dev, "host sessions not allowed\n");
1354 isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1356 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1359 if (!otg || isp != the_transceiver)
1363 omap_writew(0, OTG_IRQ_EN);
1364 if (!isp->otg.default_a)
1365 enable_vbus_draw(isp, 0);
1366 usb_gadget_vbus_disconnect(isp->otg.gadget);
1367 isp->otg.gadget = 0;
1372 #ifdef CONFIG_USB_OTG
1373 isp->otg.gadget = gadget;
1374 dev_dbg(&isp->client->dev, "registered gadget\n");
1375 /* gadget driver may be suspended until vbus_connect () */
1377 return isp1301_otg_enable(isp);
1380 #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1381 isp->otg.gadget = gadget;
1382 // FIXME update its refcount
1384 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1385 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS);
1387 omap_writel(l, OTG_CTRL);
1390 isp->otg.state = OTG_STATE_B_IDLE;
1393 if (machine_is_omap_h2() || machine_is_omap_h3())
1394 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1396 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1397 INTR_SESS_VLD | INTR_VBUS_VLD);
1398 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1399 INTR_VBUS_VLD | INTR_SESS_VLD);
1400 dev_info(&isp->client->dev, "B-Peripheral sessions ok\n");
1401 dump_regs(isp, __func__);
1403 /* If this has a Mini-AB connector, this mode is highly
1404 * nonstandard ... but can be handy for testing, so long
1405 * as you don't plug a Mini-A cable into the jack.
1407 if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD)
1413 dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n");
1419 /*-------------------------------------------------------------------------*/
1422 isp1301_set_power(struct otg_transceiver *dev, unsigned mA)
1424 if (!the_transceiver)
1426 if (dev->state == OTG_STATE_B_PERIPHERAL)
1427 enable_vbus_draw(the_transceiver, mA);
1432 isp1301_start_srp(struct otg_transceiver *dev)
1434 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1437 if (!dev || isp != the_transceiver
1438 || isp->otg.state != OTG_STATE_B_IDLE)
1441 otg_ctrl = omap_readl(OTG_CTRL);
1442 if (!(otg_ctrl & OTG_BSESSEND))
1445 otg_ctrl |= OTG_B_BUSREQ;
1446 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
1447 omap_writel(otg_ctrl, OTG_CTRL);
1448 isp->otg.state = OTG_STATE_B_SRP_INIT;
1450 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp),
1451 omap_readl(OTG_CTRL));
1452 #ifdef CONFIG_USB_OTG
1453 check_state(isp, __func__);
1459 isp1301_start_hnp(struct otg_transceiver *dev)
1461 #ifdef CONFIG_USB_OTG
1462 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1465 if (!dev || isp != the_transceiver)
1467 if (isp->otg.default_a && (isp->otg.host == NULL
1468 || !isp->otg.host->b_hnp_enable))
1470 if (!isp->otg.default_a && (isp->otg.gadget == NULL
1471 || !isp->otg.gadget->b_hnp_enable))
1474 /* We want hardware to manage most HNP protocol timings.
1475 * So do this part as early as possible...
1477 switch (isp->otg.state) {
1478 case OTG_STATE_B_PERIPHERAL:
1479 isp->otg.state = OTG_STATE_B_WAIT_ACON;
1480 isp1301_defer_work(isp, WORK_UPDATE_ISP);
1482 case OTG_STATE_B_HOST:
1483 isp->otg.state = OTG_STATE_B_PERIPHERAL;
1484 /* caller will suspend next */
1486 case OTG_STATE_A_HOST:
1488 /* autoconnect mode avoids irq latency bugs */
1489 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1492 /* caller must suspend then clear A_BUSREQ */
1493 usb_gadget_vbus_connect(isp->otg.gadget);
1494 l = omap_readl(OTG_CTRL);
1495 l |= OTG_A_SETB_HNPEN;
1496 omap_writel(l, OTG_CTRL);
1499 case OTG_STATE_A_PERIPHERAL:
1500 /* initiated by B-Host suspend */
1505 pr_debug("otg: HNP %s, %06x ...\n",
1506 state_name(isp), omap_readl(OTG_CTRL));
1507 check_state(isp, __func__);
1515 /*-------------------------------------------------------------------------*/
1517 /* no error returns, they'd just make bus scanning stop */
1518 static int __init isp1301_probe(struct i2c_client *client)
1521 struct isp1301 *isp;
1523 if (the_transceiver)
1526 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1530 INIT_WORK(&isp->work, isp1301_work);
1531 init_timer(&isp->timer);
1532 isp->timer.function = isp1301_timer;
1533 isp->timer.data = (unsigned long) isp;
1534 isp->client = client;
1536 /* if this is a true probe, verify the chip ... */
1537 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1538 if (status != I2C_VENDOR_ID_PHILIPS) {
1539 dev_dbg(&client->dev, "not philips id: %d\n",
1543 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1544 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1545 dev_dbg(&client->dev, "not isp1301, %d\n",
1551 dev_dbg(&client->dev, "can't attach %s to device, err %d\n",
1552 DRIVER_NAME, status);
1557 isp->i2c_release = client->dev.release;
1558 client->dev.release = isp1301_release;
1560 /* initial development used chiprev 2.00 */
1561 status = i2c_smbus_read_word_data(client, ISP1301_BCD_DEVICE);
1562 dev_info(&client->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n",
1563 status >> 8, status & 0xff);
1565 /* make like power-on reset */
1566 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK);
1568 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI);
1569 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI);
1571 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1572 OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
1573 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1574 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
1576 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0);
1577 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1578 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1580 #ifdef CONFIG_USB_OTG
1581 status = otg_bind(isp);
1583 dev_dbg(&client->dev, "can't bind OTG\n");
1588 status = request_irq(client->irq, isp1301_irq,
1589 IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_FALLING,
1592 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
1593 client->irq, status);
1594 #ifdef CONFIG_USB_OTG
1597 i2c_detach_client(client);
1601 isp->otg.dev = &client->dev;
1602 isp->otg.label = DRIVER_NAME;
1604 isp->otg.set_host = isp1301_set_host,
1605 isp->otg.set_peripheral = isp1301_set_peripheral,
1606 isp->otg.set_power = isp1301_set_power,
1607 isp->otg.start_srp = isp1301_start_srp,
1608 isp->otg.start_hnp = isp1301_start_hnp,
1610 enable_vbus_draw(isp, 0);
1612 the_transceiver = isp;
1614 #ifdef CONFIG_USB_OTG
1615 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
1616 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
1618 dump_regs(isp, __func__);
1621 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1622 dev_dbg(&client->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1625 status = otg_set_transceiver(&isp->otg);
1627 dev_err(&client->dev, "can't register transceiver, %d\n",
1633 static struct i2c_driver isp1301_driver = {
1635 .name = "isp1301_omap",
1637 .probe = isp1301_probe,
1638 .remove = __exit_p(isp1301_remove),
1641 /*-------------------------------------------------------------------------*/
1643 static int __init isp_init(void)
1645 return i2c_add_driver(&isp1301_driver);
1647 module_init(isp_init);
1649 static void __exit isp_exit(void)
1651 if (the_transceiver)
1652 otg_set_transceiver(0);
1653 i2c_del_driver(&isp1301_driver);
1655 module_exit(isp_exit);