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;
54 void (*i2c_release)(struct device *dev);
62 struct timer_list timer;
64 /* use keventd context to change the state for us */
65 struct work_struct work;
68 # define WORK_UPDATE_ISP 0 /* update ISP from OTG */
69 # define WORK_UPDATE_OTG 1 /* update OTG from ISP */
70 # define WORK_HOST_RESUME 4 /* resume host */
71 # define WORK_TIMER 6 /* timer fired */
72 # define WORK_STOP 7 /* don't resubmit */
76 /* bits in OTG_CTRL */
78 #define OTG_XCEIV_OUTPUTS \
79 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
80 #define OTG_XCEIV_INPUTS \
81 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
82 #define OTG_CTRL_BITS \
83 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
84 /* and OTG_PULLUP is sometimes written */
86 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
87 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
91 /*-------------------------------------------------------------------------*/
93 #ifdef CONFIG_MACH_OMAP_H2
95 /* board-specific PM hooks */
99 #include <asm/mach-types.h>
102 #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
104 #include <linux/i2c/tps65010.h>
108 static inline int tps65010_set_vbus_draw(unsigned mA)
110 pr_debug("tps65010: draw %d mA (STUB)\n", mA);
116 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
118 int status = tps65010_set_vbus_draw(mA);
120 pr_debug(" VBUS %d mA error %d\n", mA, status);
123 static void enable_vbus_source(struct isp1301 *isp)
125 /* this board won't supply more than 8mA vbus power.
126 * some boards can switch a 100ma "unit load" (or more).
131 /* products will deliver OTG messages with LEDs, GUI, etc */
132 static inline void notresponding(struct isp1301 *isp)
134 printk(KERN_NOTICE "OTG device not responding.\n");
140 /*-------------------------------------------------------------------------*/
142 /* only two addresses possible */
143 #define ISP_BASE 0x2c
144 static unsigned short normal_i2c[] = {
145 ISP_BASE, ISP_BASE + 1,
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)
521 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
522 otg_ctrl &= ~OTG_XCEIV_INPUTS;
523 otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
526 if (int_src & INTR_SESS_VLD)
527 otg_ctrl |= OTG_ASESSVLD;
528 else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) {
529 a_idle(isp, "vfall");
530 otg_ctrl &= ~OTG_CTRL_BITS;
532 if (int_src & INTR_VBUS_VLD)
533 otg_ctrl |= OTG_VBUSVLD;
534 if (int_src & INTR_ID_GND) { /* default-A */
535 if (isp->otg.state == OTG_STATE_B_IDLE
536 || isp->otg.state == OTG_STATE_UNDEFINED) {
540 } else { /* default-B */
542 if (isp->otg.state == OTG_STATE_A_IDLE
543 || isp->otg.state == OTG_STATE_UNDEFINED) {
548 omap_writel(otg_ctrl, OTG_CTRL);
551 /* outputs from ISP1301_OTG_STATUS */
552 static void update_otg2(struct isp1301 *isp, u8 otg_status)
556 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
557 otg_ctrl &= ~OTG_XCEIV_INPUTS;
558 otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND);
559 if (otg_status & OTG_B_SESS_VLD)
560 otg_ctrl |= OTG_BSESSVLD;
561 else if (otg_status & OTG_B_SESS_END)
562 otg_ctrl |= OTG_BSESSEND;
563 omap_writel(otg_ctrl, OTG_CTRL);
566 /* inputs going to ISP1301 */
567 static void otg_update_isp(struct isp1301 *isp)
569 u32 otg_ctrl, otg_change;
570 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
572 otg_ctrl = omap_readl(OTG_CTRL);
573 otg_change = otg_ctrl ^ isp->last_otg_ctrl;
574 isp->last_otg_ctrl = otg_ctrl;
575 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
577 switch (isp->otg.state) {
578 case OTG_STATE_B_IDLE:
579 case OTG_STATE_B_PERIPHERAL:
580 case OTG_STATE_B_SRP_INIT:
581 if (!(otg_ctrl & OTG_PULLUP)) {
582 // if (otg_ctrl & OTG_B_HNPEN) {
583 if (isp->otg.gadget->b_hnp_enable) {
584 isp->otg.state = OTG_STATE_B_WAIT_ACON;
585 pr_debug(" --> b_wait_acon\n");
590 set |= OTG1_DP_PULLUP;
591 clr |= OTG1_DP_PULLDOWN;
593 case OTG_STATE_A_SUSPEND:
594 case OTG_STATE_A_PERIPHERAL:
595 if (otg_ctrl & OTG_PULLUP)
598 // case OTG_STATE_B_WAIT_ACON:
601 set |= OTG1_DP_PULLDOWN;
602 clr |= OTG1_DP_PULLUP;
606 # define toggle(OTG,ISP) do { \
607 if (otg_ctrl & OTG) set |= ISP; \
611 if (!(isp->otg.host))
612 otg_ctrl &= ~OTG_DRV_VBUS;
614 switch (isp->otg.state) {
615 case OTG_STATE_A_SUSPEND:
616 if (otg_ctrl & OTG_DRV_VBUS) {
617 set |= OTG1_VBUS_DRV;
620 /* HNP failed for some reason (A_AIDL_BDIS timeout) */
624 case OTG_STATE_A_VBUS_ERR:
625 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
626 pr_debug(" --> a_wait_vfall\n");
628 case OTG_STATE_A_WAIT_VFALL:
629 /* FIXME usbcore thinks port power is still on ... */
630 clr |= OTG1_VBUS_DRV;
632 case OTG_STATE_A_IDLE:
633 if (otg_ctrl & OTG_DRV_VBUS) {
634 isp->otg.state = OTG_STATE_A_WAIT_VRISE;
635 pr_debug(" --> a_wait_vrise\n");
639 toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV);
642 toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG);
643 toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG);
647 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set);
648 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr);
650 /* HNP switch to host or peripheral; and SRP */
651 if (otg_change & OTG_PULLUP) {
654 switch (isp->otg.state) {
655 case OTG_STATE_B_IDLE:
656 if (clr & OTG1_DP_PULLUP)
658 isp->otg.state = OTG_STATE_B_PERIPHERAL;
659 pr_debug(" --> b_peripheral\n");
661 case OTG_STATE_A_SUSPEND:
662 if (clr & OTG1_DP_PULLUP)
664 isp->otg.state = OTG_STATE_A_PERIPHERAL;
665 pr_debug(" --> a_peripheral\n");
670 l = omap_readl(OTG_CTRL);
672 omap_writel(l, OTG_CTRL);
675 check_state(isp, __func__);
676 dump_regs(isp, "otg->isp1301");
679 static irqreturn_t omap_otg_irq(int irq, void *_isp)
681 u16 otg_irq = omap_readw(OTG_IRQ_SRC);
684 struct isp1301 *isp = _isp;
686 /* update ISP1301 transciever from OTG controller */
687 if (otg_irq & OPRT_CHG) {
688 omap_writew(OPRT_CHG, OTG_IRQ_SRC);
689 isp1301_defer_work(isp, WORK_UPDATE_ISP);
692 /* SRP to become b_peripheral failed */
693 } else if (otg_irq & B_SRP_TMROUT) {
694 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL));
697 /* gadget drivers that care should monitor all kinds of
698 * remote wakeup (SRP, normal) using their own timer
699 * to give "check cable and A-device" messages.
701 if (isp->otg.state == OTG_STATE_B_SRP_INIT)
702 b_idle(isp, "srp_timeout");
704 omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
707 /* HNP to become b_host failed */
708 } else if (otg_irq & B_HNP_FAIL) {
709 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
710 state_name(isp), omap_readl(OTG_CTRL));
713 otg_ctrl = omap_readl(OTG_CTRL);
714 otg_ctrl |= OTG_BUSDROP;
715 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
716 omap_writel(otg_ctrl, OTG_CTRL);
718 /* subset of b_peripheral()... */
719 isp->otg.state = OTG_STATE_B_PERIPHERAL;
720 pr_debug(" --> b_peripheral\n");
722 omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
725 /* detect SRP from B-device ... */
726 } else if (otg_irq & A_SRP_DETECT) {
727 pr_debug("otg: %s SRP_DETECT, %06x\n",
728 state_name(isp), omap_readl(OTG_CTRL));
730 isp1301_defer_work(isp, WORK_UPDATE_OTG);
731 switch (isp->otg.state) {
732 case OTG_STATE_A_IDLE:
735 isp1301_defer_work(isp, WORK_HOST_RESUME);
736 otg_ctrl = omap_readl(OTG_CTRL);
737 otg_ctrl |= OTG_A_BUSREQ;
738 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
741 omap_writel(otg_ctrl, OTG_CTRL);
747 omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
750 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
751 * we don't track them separately
753 } else if (otg_irq & A_REQ_TMROUT) {
754 otg_ctrl = omap_readl(OTG_CTRL);
755 pr_info("otg: BCON_TMOUT from %s, %06x\n",
756 state_name(isp), otg_ctrl);
759 otg_ctrl |= OTG_BUSDROP;
760 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
761 omap_writel(otg_ctrl, OTG_CTRL);
762 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
764 omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
767 /* A-supplied voltage fell too low; overcurrent */
768 } else if (otg_irq & A_VBUS_ERR) {
769 otg_ctrl = omap_readl(OTG_CTRL);
770 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
771 state_name(isp), otg_irq, otg_ctrl);
773 otg_ctrl |= OTG_BUSDROP;
774 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
775 omap_writel(otg_ctrl, OTG_CTRL);
776 isp->otg.state = OTG_STATE_A_VBUS_ERR;
778 omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
781 /* switch driver; the transciever code activates it,
782 * ungating the udc clock or resuming OHCI.
784 } else if (otg_irq & DRIVER_SWITCH) {
787 otg_ctrl = omap_readl(OTG_CTRL);
788 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
790 (otg_ctrl & OTG_DRIVER_SEL)
793 isp1301_defer_work(isp, WORK_UPDATE_ISP);
795 /* role is peripheral */
796 if (otg_ctrl & OTG_DRIVER_SEL) {
797 switch (isp->otg.state) {
798 case OTG_STATE_A_IDLE:
799 b_idle(isp, __func__);
804 isp1301_defer_work(isp, WORK_UPDATE_ISP);
808 if (!(otg_ctrl & OTG_ID)) {
809 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
810 omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL);
814 switch (isp->otg.state) {
815 case OTG_STATE_B_WAIT_ACON:
816 isp->otg.state = OTG_STATE_B_HOST;
817 pr_debug(" --> b_host\n");
820 case OTG_STATE_A_WAIT_BCON:
821 isp->otg.state = OTG_STATE_A_HOST;
822 pr_debug(" --> a_host\n");
824 case OTG_STATE_A_PERIPHERAL:
825 isp->otg.state = OTG_STATE_A_WAIT_BCON;
826 pr_debug(" --> a_wait_bcon\n");
831 isp1301_defer_work(isp, WORK_HOST_RESUME);
835 omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
839 usb_bus_start_enum(isp->otg.host,
840 isp->otg.host->otg_port);
843 check_state(isp, __func__);
847 static struct platform_device *otg_dev;
849 static int otg_init(struct isp1301 *isp)
856 dump_regs(isp, __func__);
857 /* some of these values are board-specific... */
858 l = omap_readl(OTG_SYSCON_2);
861 | SRP_GPDATA /* 9msec Bdev D+ pulse */
862 | SRP_GPDVBUS /* discharge after VBUS pulse */
863 // | (3 << 24) /* 2msec VBUS pulse */
865 | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
866 | SRP_DPW /* detect 167+ns SRP pulses */
867 | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */
869 omap_writel(l, OTG_SYSCON_2);
871 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
872 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
874 check_state(isp, __func__);
875 pr_debug("otg: %s, %s %06x\n",
876 state_name(isp), __func__, omap_readl(OTG_CTRL));
878 omap_writew(DRIVER_SWITCH | OPRT_CHG
879 | B_SRP_TMROUT | B_HNP_FAIL
880 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN);
882 l = omap_readl(OTG_SYSCON_2);
884 omap_writel(l, OTG_SYSCON_2);
889 static int otg_probe(struct platform_device *dev)
891 // struct omap_usb_config *config = dev->platform_data;
897 static int otg_remove(struct platform_device *dev)
903 struct platform_driver omap_otg_driver = {
905 .remove = otg_remove,
907 .owner = THIS_MODULE,
912 static int otg_bind(struct isp1301 *isp)
919 status = platform_driver_register(&omap_otg_driver);
924 status = request_irq(otg_dev->resource[1].start, omap_otg_irq,
925 IRQF_DISABLED, DRIVER_NAME, isp);
930 platform_driver_unregister(&omap_otg_driver);
934 static void otg_unbind(struct isp1301 *isp)
938 free_irq(otg_dev->resource[1].start, isp);
943 /* OTG controller isn't clocked */
945 #endif /* CONFIG_USB_OTG */
947 /*-------------------------------------------------------------------------*/
949 static void b_peripheral(struct isp1301 *isp)
953 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
954 omap_writel(l, OTG_CTRL);
956 usb_gadget_vbus_connect(isp->otg.gadget);
958 #ifdef CONFIG_USB_OTG
959 enable_vbus_draw(isp, 8);
962 enable_vbus_draw(isp, 100);
963 /* UDC driver just set OTG_BSESSVLD */
964 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP);
965 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN);
966 isp->otg.state = OTG_STATE_B_PERIPHERAL;
967 pr_debug(" --> b_peripheral\n");
968 dump_regs(isp, "2periph");
972 static void isp_update_otg(struct isp1301 *isp, u8 stat)
974 u8 isp_stat, isp_bstat;
975 enum usb_otg_state state = isp->otg.state;
977 if (stat & INTR_BDIS_ACON)
978 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp));
980 /* start certain state transitions right away */
981 isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
982 if (isp_stat & INTR_ID_GND) {
983 if (isp->otg.default_a) {
985 case OTG_STATE_B_IDLE:
988 case OTG_STATE_A_IDLE:
989 enable_vbus_source(isp);
991 case OTG_STATE_A_WAIT_VRISE:
992 /* we skip over OTG_STATE_A_WAIT_BCON, since
993 * the HC will transition to A_HOST (or
994 * A_SUSPEND!) without our noticing except
997 if (isp_stat & INTR_VBUS_VLD)
998 isp->otg.state = OTG_STATE_A_HOST;
1000 case OTG_STATE_A_WAIT_VFALL:
1001 if (!(isp_stat & INTR_SESS_VLD))
1002 a_idle(isp, "vfell");
1005 if (!(isp_stat & INTR_VBUS_VLD))
1006 isp->otg.state = OTG_STATE_A_VBUS_ERR;
1009 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1012 case OTG_STATE_B_PERIPHERAL:
1013 case OTG_STATE_B_HOST:
1014 case OTG_STATE_B_WAIT_ACON:
1015 usb_gadget_vbus_disconnect(isp->otg.gadget);
1020 if (state != OTG_STATE_A_IDLE)
1022 if (isp->otg.host && state == OTG_STATE_A_IDLE)
1023 isp1301_defer_work(isp, WORK_HOST_RESUME);
1029 /* if user unplugged mini-A end of cable,
1030 * don't bypass A_WAIT_VFALL.
1032 if (isp->otg.default_a) {
1035 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
1037 case OTG_STATE_A_WAIT_VFALL:
1038 state = OTG_STATE_A_IDLE;
1039 /* khubd may take a while to notice and
1040 * handle this disconnect, so don't go
1041 * to B_IDLE quite yet.
1044 case OTG_STATE_A_IDLE:
1046 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
1048 isp->otg.state = OTG_STATE_B_IDLE;
1049 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1050 l &= ~OTG_CTRL_BITS;
1051 omap_writel(l, OTG_CTRL);
1053 case OTG_STATE_B_IDLE:
1057 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1059 switch (isp->otg.state) {
1060 case OTG_STATE_B_PERIPHERAL:
1061 case OTG_STATE_B_WAIT_ACON:
1062 case OTG_STATE_B_HOST:
1063 if (likely(isp_bstat & OTG_B_SESS_VLD))
1065 enable_vbus_draw(isp, 0);
1066 #ifndef CONFIG_USB_OTG
1067 /* UDC driver will clear OTG_BSESSVLD */
1068 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1070 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1072 dump_regs(isp, __func__);
1075 case OTG_STATE_B_SRP_INIT:
1076 b_idle(isp, __func__);
1077 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
1078 omap_writel(l, OTG_CTRL);
1080 case OTG_STATE_B_IDLE:
1081 if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) {
1082 #ifdef CONFIG_USB_OTG
1083 update_otg1(isp, isp_stat);
1084 update_otg2(isp, isp_bstat);
1087 } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD)))
1088 isp_bstat |= OTG_B_SESS_END;
1090 case OTG_STATE_A_WAIT_VFALL:
1093 pr_debug("otg: unsupported b-device %s\n",
1099 if (state != isp->otg.state)
1100 pr_debug(" isp, %s -> %s\n",
1101 state_string(state), state_name(isp));
1103 #ifdef CONFIG_USB_OTG
1104 /* update the OTG controller state to match the isp1301; may
1105 * trigger OPRT_CHG irqs for changes going to the isp1301.
1107 update_otg1(isp, isp_stat);
1108 update_otg2(isp, isp_bstat);
1109 check_state(isp, __func__);
1112 dump_regs(isp, "isp1301->otg");
1115 /*-------------------------------------------------------------------------*/
1117 static u8 isp1301_clear_latch(struct isp1301 *isp)
1119 u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH);
1120 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch);
1125 isp1301_work(struct work_struct *work)
1127 struct isp1301 *isp = container_of(work, struct isp1301, work);
1130 /* implicit lock: we're the only task using this device */
1133 stop = test_bit(WORK_STOP, &isp->todo);
1135 #ifdef CONFIG_USB_OTG
1136 /* transfer state from otg engine to isp1301 */
1137 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1138 otg_update_isp(isp);
1139 put_device(&isp->client->dev);
1142 /* transfer state from isp1301 to otg engine */
1143 if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) {
1144 u8 stat = isp1301_clear_latch(isp);
1146 isp_update_otg(isp, stat);
1147 put_device(&isp->client->dev);
1150 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
1154 * skip A_WAIT_VRISE; hc transitions invisibly
1155 * skip A_WAIT_BCON; same.
1157 switch (isp->otg.state) {
1158 case OTG_STATE_A_WAIT_BCON:
1159 case OTG_STATE_A_WAIT_VRISE:
1160 isp->otg.state = OTG_STATE_A_HOST;
1161 pr_debug(" --> a_host\n");
1162 otg_ctrl = omap_readl(OTG_CTRL);
1163 otg_ctrl |= OTG_A_BUSREQ;
1164 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
1166 omap_writel(otg_ctrl, OTG_CTRL);
1168 case OTG_STATE_B_WAIT_ACON:
1169 isp->otg.state = OTG_STATE_B_HOST;
1170 pr_debug(" --> b_host (acon)\n");
1172 case OTG_STATE_B_HOST:
1173 case OTG_STATE_B_IDLE:
1174 case OTG_STATE_A_IDLE:
1177 pr_debug(" host resume in %s\n",
1182 put_device(&isp->client->dev);
1185 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
1187 dump_regs(isp, "timer");
1189 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1191 put_device(&isp->client->dev);
1195 dev_vdbg(&isp->client->dev,
1196 "work done, todo = 0x%lx\n",
1199 dev_dbg(&isp->client->dev, "stop\n");
1202 } while (isp->todo);
1206 static irqreturn_t isp1301_irq(int irq, void *isp)
1208 isp1301_defer_work(isp, WORK_UPDATE_OTG);
1212 static void isp1301_timer(unsigned long _isp)
1214 isp1301_defer_work((void *)_isp, WORK_TIMER);
1217 /*-------------------------------------------------------------------------*/
1219 static void isp1301_release(struct device *dev)
1221 struct isp1301 *isp;
1223 isp = dev_get_drvdata(dev);
1225 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1226 if (isp->i2c_release)
1227 isp->i2c_release(dev);
1231 static struct isp1301 *the_transceiver;
1233 static int isp1301_detach_client(struct i2c_client *i2c)
1235 struct isp1301 *isp;
1237 isp = i2c_get_clientdata(i2c);
1239 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1240 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1241 free_irq(isp->irq, isp);
1242 #ifdef CONFIG_USB_OTG
1245 if (machine_is_omap_h2())
1248 isp->timer.data = 0;
1249 set_bit(WORK_STOP, &isp->todo);
1250 del_timer_sync(&isp->timer);
1251 flush_scheduled_work();
1253 put_device(&i2c->dev);
1254 the_transceiver = 0;
1256 return i2c_detach_client(i2c);
1259 /*-------------------------------------------------------------------------*/
1261 /* NOTE: three modes are possible here, only one of which
1262 * will be standards-conformant on any given system:
1264 * - OTG mode (dual-role), required if there's a Mini-AB connector
1265 * - HOST mode, for when there's one or more A (host) connectors
1266 * - DEVICE mode, for when there's a B/Mini-B (device) connector
1268 * As a rule, you won't have an isp1301 chip unless it's there to
1269 * support the OTG mode. Other modes help testing USB controllers
1270 * in isolation from (full) OTG support, or maybe so later board
1271 * revisions can help to support those feature.
1274 #ifdef CONFIG_USB_OTG
1276 static int isp1301_otg_enable(struct isp1301 *isp)
1281 /* NOTE: since we don't change this, this provides
1282 * a few more interrupts than are strictly needed.
1284 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1285 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1286 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1287 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1289 dev_info(&isp->client->dev, "ready for dual-role USB ...\n");
1296 /* add or disable the host device+driver */
1298 isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1300 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1302 if (!otg || isp != the_transceiver)
1306 omap_writew(0, OTG_IRQ_EN);
1312 #ifdef CONFIG_USB_OTG
1313 isp->otg.host = host;
1314 dev_dbg(&isp->client->dev, "registered host\n");
1316 if (isp->otg.gadget)
1317 return isp1301_otg_enable(isp);
1320 #elif !defined(CONFIG_USB_GADGET_OMAP)
1321 // FIXME update its refcount
1322 isp->otg.host = host;
1326 if (machine_is_omap_h2())
1327 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
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;
1392 if (machine_is_omap_h2())
1393 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1395 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1397 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1399 dev_info(&isp->client->dev, "B-Peripheral sessions ok\n");
1400 dump_regs(isp, __func__);
1402 /* If this has a Mini-AB connector, this mode is highly
1403 * nonstandard ... but can be handy for testing, so long
1404 * as you don't plug a Mini-A cable into the jack.
1406 if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD)
1412 dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n");
1418 /*-------------------------------------------------------------------------*/
1421 isp1301_set_power(struct otg_transceiver *dev, unsigned mA)
1423 if (!the_transceiver)
1425 if (dev->state == OTG_STATE_B_PERIPHERAL)
1426 enable_vbus_draw(the_transceiver, mA);
1431 isp1301_start_srp(struct otg_transceiver *dev)
1433 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1436 if (!dev || isp != the_transceiver
1437 || isp->otg.state != OTG_STATE_B_IDLE)
1440 otg_ctrl = omap_readl(OTG_CTRL);
1441 if (!(otg_ctrl & OTG_BSESSEND))
1444 otg_ctrl |= OTG_B_BUSREQ;
1445 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
1446 omap_writel(otg_ctrl, OTG_CTRL);
1447 isp->otg.state = OTG_STATE_B_SRP_INIT;
1449 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp),
1450 omap_readl(OTG_CTRL));
1451 #ifdef CONFIG_USB_OTG
1452 check_state(isp, __func__);
1458 isp1301_start_hnp(struct otg_transceiver *dev)
1460 #ifdef CONFIG_USB_OTG
1461 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1464 if (!dev || isp != the_transceiver)
1466 if (isp->otg.default_a && (isp->otg.host == NULL
1467 || !isp->otg.host->b_hnp_enable))
1469 if (!isp->otg.default_a && (isp->otg.gadget == NULL
1470 || !isp->otg.gadget->b_hnp_enable))
1473 /* We want hardware to manage most HNP protocol timings.
1474 * So do this part as early as possible...
1476 switch (isp->otg.state) {
1477 case OTG_STATE_B_HOST:
1478 isp->otg.state = OTG_STATE_B_PERIPHERAL;
1479 /* caller will suspend next */
1481 case OTG_STATE_A_HOST:
1483 /* autoconnect mode avoids irq latency bugs */
1484 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1487 /* caller must suspend then clear A_BUSREQ */
1488 usb_gadget_vbus_connect(isp->otg.gadget);
1489 l = omap_readl(OTG_CTRL);
1490 l |= OTG_A_SETB_HNPEN;
1491 omap_writel(l, OTG_CTRL);
1494 case OTG_STATE_A_PERIPHERAL:
1495 /* initiated by B-Host suspend */
1500 pr_debug("otg: HNP %s, %06x ...\n",
1501 state_name(isp), omap_readl(OTG_CTRL));
1502 check_state(isp, __func__);
1510 /*-------------------------------------------------------------------------*/
1512 /* no error returns, they'd just make bus scanning stop */
1513 static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1516 struct isp1301 *isp;
1517 struct i2c_client *i2c;
1519 if (the_transceiver)
1522 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1526 INIT_WORK(&isp->work, isp1301_work);
1527 init_timer(&isp->timer);
1528 isp->timer.function = isp1301_timer;
1529 isp->timer.data = (unsigned long) isp;
1532 isp->c.addr = address;
1533 i2c_set_clientdata(&isp->c, isp);
1534 isp->c.adapter = bus;
1535 isp->c.driver = &isp1301_driver;
1536 strlcpy(isp->c.name, DRIVER_NAME, I2C_NAME_SIZE);
1537 isp->client = i2c = &isp->c;
1539 /* if this is a true probe, verify the chip ... */
1541 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1542 if (status != I2C_VENDOR_ID_PHILIPS) {
1543 dev_dbg(&bus->dev, "addr %d not philips id: %d\n",
1547 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1548 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1549 dev_dbg(&bus->dev, "%d not isp1301, %d\n",
1555 status = i2c_attach_client(i2c);
1557 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n",
1558 DRIVER_NAME, address, status);
1563 isp->i2c_release = i2c->dev.release;
1564 i2c->dev.release = isp1301_release;
1566 /* initial development used chiprev 2.00 */
1567 status = i2c_smbus_read_word_data(i2c, ISP1301_BCD_DEVICE);
1568 dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n",
1569 status >> 8, status & 0xff);
1571 /* make like power-on reset */
1572 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK);
1574 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI);
1575 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI);
1577 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1578 OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
1579 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1580 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
1582 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0);
1583 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1584 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1586 #ifdef CONFIG_USB_OTG
1587 status = otg_bind(isp);
1589 dev_dbg(&i2c->dev, "can't bind OTG\n");
1594 if (machine_is_omap_h2()) {
1595 /* full speed signaling by default */
1596 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1598 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2,
1601 /* IRQ wired at M14 */
1602 omap_cfg_reg(M14_1510_GPIO2);
1603 isp->irq = OMAP_GPIO_IRQ(2);
1604 if (gpio_request(2, "isp1301") == 0)
1605 gpio_direction_input(2);
1606 isp->irq_type = IRQF_TRIGGER_FALLING;
1609 isp->irq_type |= IRQF_SAMPLE_RANDOM;
1610 status = request_irq(isp->irq, isp1301_irq,
1611 isp->irq_type, DRIVER_NAME, isp);
1613 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n",
1615 #ifdef CONFIG_USB_OTG
1618 i2c_detach_client(i2c);
1622 isp->otg.dev = &isp->client->dev;
1623 isp->otg.label = DRIVER_NAME;
1625 isp->otg.set_host = isp1301_set_host,
1626 isp->otg.set_peripheral = isp1301_set_peripheral,
1627 isp->otg.set_power = isp1301_set_power,
1628 isp->otg.start_srp = isp1301_start_srp,
1629 isp->otg.start_hnp = isp1301_start_hnp,
1631 enable_vbus_draw(isp, 0);
1633 the_transceiver = isp;
1635 #ifdef CONFIG_USB_OTG
1636 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
1637 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
1640 dump_regs(isp, __func__);
1643 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1644 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1647 status = otg_set_transceiver(&isp->otg);
1649 dev_err(&i2c->dev, "can't register transceiver, %d\n",
1655 static int isp1301_scan_bus(struct i2c_adapter *bus)
1657 if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA
1658 | I2C_FUNC_SMBUS_READ_WORD_DATA))
1660 return i2c_probe(bus, &addr_data, isp1301_probe);
1663 static struct i2c_driver isp1301_driver = {
1665 .name = "isp1301_omap",
1667 .attach_adapter = isp1301_scan_bus,
1668 .detach_client = isp1301_detach_client,
1671 /*-------------------------------------------------------------------------*/
1673 static int __init isp_init(void)
1675 return i2c_add_driver(&isp1301_driver);
1677 module_init(isp_init);
1679 static void __exit isp_exit(void)
1681 if (the_transceiver)
1682 otg_set_transceiver(0);
1683 i2c_del_driver(&isp1301_driver);
1685 module_exit(isp_exit);