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>
28 #include <linux/interrupt.h>
29 #include <linux/platform_device.h>
30 #include <linux/usb/ch9.h>
31 #include <linux/usb/gadget.h>
32 #include <linux/usb.h>
33 #include <linux/usb/otg.h>
34 #include <linux/i2c.h>
35 #include <linux/workqueue.h>
38 #include <asm/mach-types.h>
40 #include <asm/arch/gpio.h>
41 #include <asm/arch/usb.h>
42 #include <asm/arch/mux.h>
50 #define DRIVER_VERSION "24 August 2004"
51 #define DRIVER_NAME (isp1301_driver.driver.name)
53 MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver");
54 MODULE_LICENSE("GPL");
57 struct otg_transceiver otg;
58 struct i2c_client client;
59 void (*i2c_release)(struct device *dev);
67 struct timer_list timer;
69 /* use keventd context to change the state for us */
70 struct work_struct work;
73 # define WORK_UPDATE_ISP 0 /* update ISP from OTG */
74 # define WORK_UPDATE_OTG 1 /* update OTG from ISP */
75 # define WORK_HOST_RESUME 4 /* resume host */
76 # define WORK_TIMER 6 /* timer fired */
77 # define WORK_STOP 7 /* don't resubmit */
81 /* bits in OTG_CTRL_REG */
83 #define OTG_XCEIV_OUTPUTS \
84 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
85 #define OTG_XCEIV_INPUTS \
86 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
87 #define OTG_CTRL_BITS \
88 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
89 /* and OTG_PULLUP is sometimes written */
91 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
92 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
96 /*-------------------------------------------------------------------------*/
98 #if defined(CONFIG_MACH_OMAP_H2) || \
99 defined(CONFIG_MACH_OMAP_H3)
101 /* board-specific PM hooks */
104 #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
106 #include <asm/arch/tps65010.h>
110 static inline int tps65010_set_vbus_draw(unsigned mA)
112 pr_debug("tps65010: draw %d mA (STUB)\n", mA);
118 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
120 int status = tps65010_set_vbus_draw(mA);
122 pr_debug(" VBUS %d mA error %d\n", mA, status);
125 static void enable_vbus_source(struct isp1301 *isp)
127 /* this board won't supply more than 8mA vbus power.
128 * some boards can switch a 100ma "unit load" (or more).
135 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
137 pr_debug("%s UNIMPL\n", __FUNCTION__);
140 static void enable_vbus_source(struct isp1301 *isp)
142 pr_debug("%s UNIMPL\n", __FUNCTION__);
147 /*-------------------------------------------------------------------------*/
149 /* products will deliver OTG messages with LEDs, GUI, etc */
150 static inline void notresponding(struct isp1301 *isp)
152 printk(KERN_NOTICE "OTG device not responding.\n");
155 /*-------------------------------------------------------------------------*/
157 /* only two addresses possible */
158 #define ISP_BASE 0x2c
159 static unsigned short normal_i2c[] = {
160 ISP_BASE, ISP_BASE + 1,
165 static struct i2c_driver isp1301_driver;
167 /* smbus apis are used for portability */
170 isp1301_get_u8(struct isp1301 *isp, u8 reg)
172 return i2c_smbus_read_byte_data(&isp->client, reg + 0);
176 isp1301_get_u16(struct isp1301 *isp, u8 reg)
178 return i2c_smbus_read_word_data(&isp->client, reg);
182 isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
184 return i2c_smbus_write_byte_data(&isp->client, reg + 0, bits);
188 isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
190 return i2c_smbus_write_byte_data(&isp->client, reg + 1, bits);
193 /*-------------------------------------------------------------------------*/
196 #define ISP1301_VENDOR_ID 0x00 /* u16 read */
197 #define ISP1301_PRODUCT_ID 0x02 /* u16 read */
198 #define ISP1301_BCD_DEVICE 0x14 /* u16 read */
200 #define I2C_VENDOR_ID_PHILIPS 0x04cc
201 #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
203 /* operational registers */
204 #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
205 # define MC1_SPEED_REG (1 << 0)
206 # define MC1_SUSPEND_REG (1 << 1)
207 # define MC1_DAT_SE0 (1 << 2)
208 # define MC1_TRANSPARENT (1 << 3)
209 # define MC1_BDIS_ACON_EN (1 << 4)
210 # define MC1_OE_INT_EN (1 << 5)
211 # define MC1_UART_EN (1 << 6)
212 # define MC1_MASK 0x7f
213 #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
214 # define MC2_GLOBAL_PWR_DN (1 << 0)
215 # define MC2_SPD_SUSP_CTRL (1 << 1)
216 # define MC2_BI_DI (1 << 2)
217 # define MC2_TRANSP_BDIR0 (1 << 3)
218 # define MC2_TRANSP_BDIR1 (1 << 4)
219 # define MC2_AUDIO_EN (1 << 5)
220 # define MC2_PSW_EN (1 << 6)
221 # define MC2_EN2V7 (1 << 7)
222 #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
223 # define OTG1_DP_PULLUP (1 << 0)
224 # define OTG1_DM_PULLUP (1 << 1)
225 # define OTG1_DP_PULLDOWN (1 << 2)
226 # define OTG1_DM_PULLDOWN (1 << 3)
227 # define OTG1_ID_PULLDOWN (1 << 4)
228 # define OTG1_VBUS_DRV (1 << 5)
229 # define OTG1_VBUS_DISCHRG (1 << 6)
230 # define OTG1_VBUS_CHRG (1 << 7)
231 #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
232 # define OTG_B_SESS_END (1 << 6)
233 # define OTG_B_SESS_VLD (1 << 7)
235 #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */
236 #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */
238 #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */
239 #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */
241 /* same bitfields in all interrupt registers */
242 # define INTR_VBUS_VLD (1 << 0)
243 # define INTR_SESS_VLD (1 << 1)
244 # define INTR_DP_HI (1 << 2)
245 # define INTR_ID_GND (1 << 3)
246 # define INTR_DM_HI (1 << 4)
247 # define INTR_ID_FLOAT (1 << 5)
248 # define INTR_BDIS_ACON (1 << 6)
249 # define INTR_CR_INT (1 << 7)
251 /*-------------------------------------------------------------------------*/
253 static const char *state_string(enum usb_otg_state state)
256 case OTG_STATE_A_IDLE: return "a_idle";
257 case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
258 case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
259 case OTG_STATE_A_HOST: return "a_host";
260 case OTG_STATE_A_SUSPEND: return "a_suspend";
261 case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
262 case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
263 case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
264 case OTG_STATE_B_IDLE: return "b_idle";
265 case OTG_STATE_B_SRP_INIT: return "b_srp_init";
266 case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
267 case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
268 case OTG_STATE_B_HOST: return "b_host";
269 default: return "UNDEFINED";
273 static inline const char *state_name(struct isp1301 *isp)
275 return state_string(isp->otg.state);
279 #define dev_vdbg dev_dbg
281 #define dev_vdbg(dev, fmt, arg...) do{}while(0)
284 /*-------------------------------------------------------------------------*/
286 /* NOTE: some of this ISP1301 setup is specific to H2 boards;
287 * not everything is guarded by board-specific checks, or even using
288 * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI.
290 * ALSO: this currently doesn't use ISP1301 low-power modes
291 * while OTG is running.
294 static void power_down(struct isp1301 *isp)
296 isp->otg.state = OTG_STATE_UNDEFINED;
298 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
299 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND_REG);
301 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN);
302 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
305 static void power_up(struct isp1301 *isp)
307 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
308 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND_REG);
310 /* do this only when cpu is driving transceiver,
311 * so host won't see a low speed device...
313 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
316 #define NO_HOST_SUSPEND
318 static int host_suspend(struct isp1301 *isp)
320 #ifdef NO_HOST_SUSPEND
328 /* Currently ASSUMES only the OTG port matters;
329 * other ports could be active...
331 dev = isp->otg.host->controller;
332 return dev->driver->suspend(dev, 3, 0);
336 static int host_resume(struct isp1301 *isp)
338 #ifdef NO_HOST_SUSPEND
346 dev = isp->otg.host->controller;
347 return dev->driver->resume(dev, 0);
351 static int gadget_suspend(struct isp1301 *isp)
353 isp->otg.gadget->b_hnp_enable = 0;
354 isp->otg.gadget->a_hnp_support = 0;
355 isp->otg.gadget->a_alt_hnp_support = 0;
356 return usb_gadget_vbus_disconnect(isp->otg.gadget);
359 /*-------------------------------------------------------------------------*/
361 #define TIMER_MINUTES 10
362 #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
364 /* Almost all our I2C messaging comes from a work queue's task context.
365 * NOTE: guaranteeing certain response times might mean we shouldn't
366 * share keventd's work queue; a realtime task might be safest.
369 isp1301_defer_work(struct isp1301 *isp, int work)
373 if (isp && !test_and_set_bit(work, &isp->todo)) {
374 (void) get_device(&isp->client.dev);
375 status = schedule_work(&isp->work);
376 if (!status && !isp->working)
377 dev_vdbg(&isp->client.dev,
378 "work item %d may be lost\n", work);
382 /* called from irq handlers */
383 static void a_idle(struct isp1301 *isp, const char *tag)
385 if (isp->otg.state == OTG_STATE_A_IDLE)
388 isp->otg.default_a = 1;
390 isp->otg.host->is_b_host = 0;
393 if (isp->otg.gadget) {
394 isp->otg.gadget->is_a_peripheral = 1;
397 isp->otg.state = OTG_STATE_A_IDLE;
398 isp->last_otg_ctrl = OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
399 pr_debug(" --> %s/%s\n", state_name(isp), tag);
402 /* called from irq handlers */
403 static void b_idle(struct isp1301 *isp, const char *tag)
405 if (isp->otg.state == OTG_STATE_B_IDLE)
408 isp->otg.default_a = 0;
410 isp->otg.host->is_b_host = 1;
413 if (isp->otg.gadget) {
414 isp->otg.gadget->is_a_peripheral = 0;
417 isp->otg.state = OTG_STATE_B_IDLE;
418 isp->last_otg_ctrl = OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
419 pr_debug(" --> %s/%s\n", state_name(isp), tag);
423 dump_regs(struct isp1301 *isp, const char *label)
426 u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1);
427 u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
428 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
430 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
431 OTG_CTRL_REG, label, state_name(isp),
433 /* mode control and irq enables don't change much */
437 /*-------------------------------------------------------------------------*/
439 #ifdef CONFIG_USB_OTG
442 * The OMAP OTG controller handles most of the OTG state transitions.
444 * We translate isp1301 outputs (mostly voltage comparator status) into
445 * OTG inputs; OTG outputs (mostly pullup/pulldown controls) and HNP state
446 * flags into isp1301 inputs ... and infer state transitions.
451 static void check_state(struct isp1301 *isp, const char *tag)
453 enum usb_otg_state state = OTG_STATE_UNDEFINED;
454 u8 fsm = OTG_TEST_REG & 0x0ff;
461 state = OTG_STATE_B_IDLE;
467 state = OTG_STATE_B_PERIPHERAL;
470 state = OTG_STATE_B_SRP_INIT;
473 /* extra dual-role default-b states */
479 state = OTG_STATE_B_WAIT_ACON;
482 state = OTG_STATE_B_HOST;
487 state = OTG_STATE_A_IDLE;
490 state = OTG_STATE_A_WAIT_VFALL;
493 state = OTG_STATE_A_VBUS_ERR;
499 state = OTG_STATE_A_PERIPHERAL;
502 state = OTG_STATE_A_WAIT_VRISE;
505 state = OTG_STATE_A_WAIT_BCON;
508 state = OTG_STATE_A_HOST;
511 state = OTG_STATE_A_SUSPEND;
516 if (isp->otg.state == state && !extra)
518 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
519 state_string(state), fsm, state_name(isp), OTG_CTRL_REG);
524 static inline void check_state(struct isp1301 *isp, const char *tag) { }
528 /* outputs from ISP1301_INTERRUPT_SOURCE */
529 static void update_otg1(struct isp1301 *isp, u8 int_src)
534 otg_ctrl = OTG_CTRL_REG
537 & ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
538 if (int_src & INTR_SESS_VLD)
539 otg_ctrl |= OTG_ASESSVLD;
540 else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) {
541 a_idle(isp, "vfall");
542 otg_ctrl &= ~OTG_CTRL_BITS;
544 if (int_src & INTR_VBUS_VLD)
545 otg_ctrl |= OTG_VBUSVLD;
547 int_id = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
549 if (int_id & INTR_ID_GND) { /* default-A */
550 if (isp->otg.state == OTG_STATE_B_IDLE
551 || isp->otg.state == OTG_STATE_UNDEFINED) {
555 } else { /* default-B */
557 if (isp->otg.state == OTG_STATE_A_IDLE
558 || isp->otg.state == OTG_STATE_UNDEFINED) {
563 OTG_CTRL_REG = otg_ctrl;
566 /* outputs from ISP1301_OTG_STATUS */
567 static void update_otg2(struct isp1301 *isp, u8 otg_status)
571 otg_ctrl = OTG_CTRL_REG
574 & ~(OTG_BSESSVLD|OTG_BSESSEND);
575 if (otg_status & OTG_B_SESS_VLD)
576 otg_ctrl |= OTG_BSESSVLD;
577 else if (otg_status & OTG_B_SESS_END)
578 otg_ctrl |= OTG_BSESSEND;
579 OTG_CTRL_REG = otg_ctrl;
582 /* inputs going to ISP1301 */
583 static void otg_update_isp(struct isp1301 *isp)
585 u32 otg_ctrl, otg_change;
586 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
588 otg_ctrl = OTG_CTRL_REG;
589 otg_change = otg_ctrl ^ isp->last_otg_ctrl;
590 isp->last_otg_ctrl = otg_ctrl;
591 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
593 switch (isp->otg.state) {
594 case OTG_STATE_B_IDLE:
595 case OTG_STATE_B_PERIPHERAL:
596 case OTG_STATE_B_SRP_INIT:
597 if (!(otg_ctrl & OTG_PULLUP)) {
598 // if (otg_ctrl & OTG_B_HNPEN) {
599 if (isp->otg.gadget->b_hnp_enable) {
600 isp->otg.state = OTG_STATE_B_WAIT_ACON;
601 pr_debug(" --> b_wait_acon\n");
606 set |= OTG1_DP_PULLUP;
607 clr |= OTG1_DP_PULLDOWN;
609 case OTG_STATE_A_SUSPEND:
610 case OTG_STATE_A_PERIPHERAL:
611 if (otg_ctrl & OTG_PULLUP)
614 // case OTG_STATE_B_WAIT_ACON:
617 set |= OTG1_DP_PULLDOWN;
618 clr |= OTG1_DP_PULLUP;
622 # define toggle(OTG,ISP) do { \
623 if (otg_ctrl & OTG) set |= ISP; \
627 if (!(isp->otg.host))
628 otg_ctrl &= ~OTG_DRV_VBUS;
630 switch (isp->otg.state) {
631 case OTG_STATE_A_SUSPEND:
632 if (otg_ctrl & OTG_DRV_VBUS) {
633 set |= OTG1_VBUS_DRV;
636 /* HNP failed for some reason (A_AIDL_BDIS timeout) */
640 case OTG_STATE_A_VBUS_ERR:
641 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
642 pr_debug(" --> a_wait_vfall\n");
644 case OTG_STATE_A_WAIT_VFALL:
645 /* FIXME usbcore thinks port power is still on ... */
646 clr |= OTG1_VBUS_DRV;
648 case OTG_STATE_A_IDLE:
649 if (otg_ctrl & OTG_DRV_VBUS) {
650 isp->otg.state = OTG_STATE_A_WAIT_VRISE;
651 pr_debug(" --> a_wait_vrise\n");
655 toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV);
658 toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG);
659 toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG);
663 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set);
664 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr);
666 /* HNP switch to host or peripheral; and SRP */
667 if (otg_change & OTG_PULLUP) {
668 switch (isp->otg.state) {
669 case OTG_STATE_B_IDLE:
670 if (clr & OTG1_DP_PULLUP)
672 isp->otg.state = OTG_STATE_B_PERIPHERAL;
673 pr_debug(" --> b_peripheral\n");
675 case OTG_STATE_A_SUSPEND:
676 if (clr & OTG1_DP_PULLUP)
678 isp->otg.state = OTG_STATE_A_PERIPHERAL;
679 pr_debug(" --> a_peripheral\n");
684 OTG_CTRL_REG |= OTG_PULLUP;
687 check_state(isp, __FUNCTION__);
688 dump_regs(isp, "otg->isp1301");
691 static irqreturn_t omap_otg_irq(int irq, void *_isp)
693 u16 otg_irq = OTG_IRQ_SRC_REG;
696 struct isp1301 *isp = _isp;
698 /* update ISP1301 transciever from OTG controller */
699 if (otg_irq & OPRT_CHG) {
700 OTG_IRQ_SRC_REG = OPRT_CHG;
701 isp1301_defer_work(isp, WORK_UPDATE_ISP);
704 /* SRP to become b_peripheral failed */
705 } else if (otg_irq & B_SRP_TMROUT) {
706 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", OTG_CTRL_REG);
709 /* gadget drivers that care should monitor all kinds of
710 * remote wakeup (SRP, normal) using their own timer
711 * to give "check cable and A-device" messages.
713 if (isp->otg.state == OTG_STATE_B_SRP_INIT)
714 b_idle(isp, "srp_timeout");
716 OTG_IRQ_SRC_REG = B_SRP_TMROUT;
719 /* HNP to become b_host failed */
720 } else if (otg_irq & B_HNP_FAIL) {
721 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
722 state_name(isp), OTG_CTRL_REG);
725 otg_ctrl = OTG_CTRL_REG;
726 otg_ctrl |= OTG_BUSDROP;
727 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
728 OTG_CTRL_REG = otg_ctrl;
730 /* subset of b_peripheral()... */
731 isp->otg.state = OTG_STATE_B_PERIPHERAL;
732 pr_debug(" --> b_peripheral\n");
734 OTG_IRQ_SRC_REG = B_HNP_FAIL;
737 /* detect SRP from B-device ... */
738 } else if (otg_irq & A_SRP_DETECT) {
739 pr_debug("otg: %s SRP_DETECT, %06x\n",
740 state_name(isp), OTG_CTRL_REG);
742 isp1301_defer_work(isp, WORK_UPDATE_OTG);
743 switch (isp->otg.state) {
744 case OTG_STATE_A_IDLE:
747 isp1301_defer_work(isp, WORK_HOST_RESUME);
748 otg_ctrl = OTG_CTRL_REG;
749 otg_ctrl |= OTG_A_BUSREQ;
750 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
753 OTG_CTRL_REG = otg_ctrl;
759 OTG_IRQ_SRC_REG = A_SRP_DETECT;
762 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
763 * we don't track them separately
765 } else if (otg_irq & A_REQ_TMROUT) {
766 otg_ctrl = OTG_CTRL_REG;
767 pr_info("otg: BCON_TMOUT from %s, %06x\n",
768 state_name(isp), otg_ctrl);
771 otg_ctrl |= OTG_BUSDROP;
772 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
773 OTG_CTRL_REG = otg_ctrl;
774 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
776 OTG_IRQ_SRC_REG = A_REQ_TMROUT;
779 /* A-supplied voltage fell too low; overcurrent */
780 } else if (otg_irq & A_VBUS_ERR) {
781 otg_ctrl = OTG_CTRL_REG;
782 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
783 state_name(isp), otg_irq, otg_ctrl);
785 otg_ctrl |= OTG_BUSDROP;
786 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
787 OTG_CTRL_REG = otg_ctrl;
788 isp->otg.state = OTG_STATE_A_VBUS_ERR;
790 OTG_IRQ_SRC_REG = A_VBUS_ERR;
793 /* switch driver; the transciever code activates it,
794 * ungating the udc clock or resuming OHCI.
796 } else if (otg_irq & DRIVER_SWITCH) {
799 otg_ctrl = OTG_CTRL_REG;
800 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
802 (otg_ctrl & OTG_DRIVER_SEL)
805 isp1301_defer_work(isp, WORK_UPDATE_ISP);
807 /* role is peripheral */
808 if (otg_ctrl & OTG_DRIVER_SEL) {
809 switch (isp->otg.state) {
810 case OTG_STATE_A_IDLE:
811 b_idle(isp, __FUNCTION__);
816 isp1301_defer_work(isp, WORK_UPDATE_ISP);
820 if (!(otg_ctrl & OTG_ID)) {
821 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
822 OTG_CTRL_REG = otg_ctrl | OTG_A_BUSREQ;
826 switch (isp->otg.state) {
827 case OTG_STATE_B_WAIT_ACON:
828 isp->otg.state = OTG_STATE_B_HOST;
829 pr_debug(" --> b_host\n");
832 case OTG_STATE_A_WAIT_BCON:
833 isp->otg.state = OTG_STATE_A_HOST;
834 pr_debug(" --> a_host\n");
836 case OTG_STATE_A_PERIPHERAL:
837 isp->otg.state = OTG_STATE_A_WAIT_BCON;
838 pr_debug(" --> a_wait_bcon\n");
843 isp1301_defer_work(isp, WORK_HOST_RESUME);
847 OTG_IRQ_SRC_REG = DRIVER_SWITCH;
851 usb_bus_start_enum(isp->otg.host,
852 isp->otg.host->otg_port);
855 check_state(isp, __FUNCTION__);
859 static struct platform_device *otg_dev;
861 static int otg_init(struct isp1301 *isp)
866 dump_regs(isp, __FUNCTION__);
867 /* some of these values are board-specific... */
868 OTG_SYSCON_2_REG |= OTG_EN
870 | SRP_GPDATA /* 9msec Bdev D+ pulse */
871 | SRP_GPDVBUS /* discharge after VBUS pulse */
872 // | (3 << 24) /* 2msec VBUS pulse */
874 | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
875 | SRP_DPW /* detect 167+ns SRP pulses */
876 | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */
879 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
880 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
882 check_state(isp, __FUNCTION__);
883 pr_debug("otg: %s, %s %06x\n",
884 state_name(isp), __FUNCTION__, OTG_CTRL_REG);
886 OTG_IRQ_EN_REG = DRIVER_SWITCH | OPRT_CHG
887 | B_SRP_TMROUT | B_HNP_FAIL
888 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT;
889 OTG_SYSCON_2_REG |= OTG_EN;
894 static int otg_probe(struct platform_device *dev)
896 // struct omap_usb_config *config = dev->platform_data;
902 static int otg_remove(struct platform_device *dev)
908 struct platform_driver omap_otg_driver = {
910 .remove = otg_remove,
912 .owner = THIS_MODULE,
917 static int otg_bind(struct isp1301 *isp)
924 status = platform_driver_register(&omap_otg_driver);
929 status = request_irq(otg_dev->resource[1].start, omap_otg_irq,
930 IRQF_DISABLED, DRIVER_NAME, isp);
935 platform_driver_unregister(&omap_otg_driver);
939 static void otg_unbind(struct isp1301 *isp)
943 free_irq(otg_dev->resource[1].start, isp);
948 /* OTG controller isn't clocked */
950 #endif /* CONFIG_USB_OTG */
952 /*-------------------------------------------------------------------------*/
954 static void b_peripheral(struct isp1301 *isp)
956 OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
957 usb_gadget_vbus_connect(isp->otg.gadget);
959 #ifdef CONFIG_USB_OTG
960 enable_vbus_draw(isp, 8);
963 enable_vbus_draw(isp, 100);
964 /* UDC driver just set OTG_BSESSVLD */
965 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP);
966 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN);
967 isp->otg.state = OTG_STATE_B_PERIPHERAL;
968 pr_debug(" --> b_peripheral\n");
969 dump_regs(isp, "2periph");
973 static void isp_update_otg(struct isp1301 *isp, u8 stat)
975 u8 isp_stat, isp_bstat;
976 enum usb_otg_state state = isp->otg.state;
978 if (stat & INTR_BDIS_ACON)
979 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp));
981 /* start certain state transitions right away */
982 isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
983 if (isp_stat & INTR_ID_GND) {
984 if (isp->otg.default_a) {
986 case OTG_STATE_B_IDLE:
989 case OTG_STATE_A_IDLE:
990 enable_vbus_source(isp);
992 case OTG_STATE_A_WAIT_VRISE:
993 /* we skip over OTG_STATE_A_WAIT_BCON, since
994 * the HC will transition to A_HOST (or
995 * A_SUSPEND!) without our noticing except
998 if (isp_stat & INTR_VBUS_VLD)
999 isp->otg.state = OTG_STATE_A_HOST;
1001 case OTG_STATE_A_WAIT_VFALL:
1002 if (!(isp_stat & INTR_SESS_VLD))
1003 a_idle(isp, "vfell");
1006 if (!(isp_stat & INTR_VBUS_VLD))
1007 isp->otg.state = OTG_STATE_A_VBUS_ERR;
1010 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1013 case OTG_STATE_B_PERIPHERAL:
1014 case OTG_STATE_B_HOST:
1015 case OTG_STATE_B_WAIT_ACON:
1016 usb_gadget_vbus_disconnect(isp->otg.gadget);
1021 if (state != OTG_STATE_A_IDLE)
1023 if (isp->otg.host && state == OTG_STATE_A_IDLE)
1024 isp1301_defer_work(isp, WORK_HOST_RESUME);
1028 /* if user unplugged mini-A end of cable,
1029 * don't bypass A_WAIT_VFALL.
1031 if (isp->otg.default_a) {
1034 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
1036 case OTG_STATE_A_WAIT_VFALL:
1037 state = OTG_STATE_A_IDLE;
1038 /* khubd may take a while to notice and
1039 * handle this disconnect, so don't go
1040 * to B_IDLE quite yet.
1043 case OTG_STATE_A_IDLE:
1045 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
1047 isp->otg.state = OTG_STATE_B_IDLE;
1048 OTG_CTRL_REG &= OTG_CTRL_REG & OTG_CTRL_MASK
1051 case OTG_STATE_B_IDLE:
1055 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1057 switch (isp->otg.state) {
1058 case OTG_STATE_B_PERIPHERAL:
1059 case OTG_STATE_B_WAIT_ACON:
1060 case OTG_STATE_B_HOST:
1061 if (likely(isp_bstat & OTG_B_SESS_VLD))
1063 enable_vbus_draw(isp, 0);
1064 #ifndef CONFIG_USB_OTG
1065 /* UDC driver will clear OTG_BSESSVLD */
1066 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1068 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1070 dump_regs(isp, __FUNCTION__);
1073 case OTG_STATE_B_SRP_INIT:
1074 b_idle(isp, __FUNCTION__);
1075 OTG_CTRL_REG &= OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
1077 case OTG_STATE_B_IDLE:
1078 if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) {
1079 #ifdef CONFIG_USB_OTG
1080 update_otg1(isp, isp_stat);
1081 update_otg2(isp, isp_bstat);
1084 } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD)))
1085 isp_bstat |= OTG_B_SESS_END;
1087 case OTG_STATE_A_WAIT_VFALL:
1090 pr_debug("otg: unsupported b-device %s\n",
1096 if (state != isp->otg.state)
1097 pr_debug(" isp, %s -> %s\n",
1098 state_string(state), state_name(isp));
1100 #ifdef CONFIG_USB_OTG
1101 /* update the OTG controller state to match the isp1301; may
1102 * trigger OPRT_CHG irqs for changes going to the isp1301.
1104 update_otg1(isp, stat); // pass the actual interrupt latch status
1105 update_otg2(isp, isp_bstat);
1106 check_state(isp, __FUNCTION__);
1109 dump_regs(isp, "isp1301->otg");
1112 /*-------------------------------------------------------------------------*/
1114 static u8 isp1301_clear_latch(struct isp1301 *isp)
1116 u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH);
1117 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch);
1122 isp1301_work(struct work_struct *work)
1124 struct isp1301 *isp = container_of(work, struct isp1301, work);
1127 /* implicit lock: we're the only task using this device */
1130 stop = test_bit(WORK_STOP, &isp->todo);
1132 #ifdef CONFIG_USB_OTG
1133 /* transfer state from otg engine to isp1301 */
1134 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1135 otg_update_isp(isp);
1136 put_device(&isp->client.dev);
1139 /* transfer state from isp1301 to otg engine */
1140 if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) {
1141 u8 stat = isp1301_clear_latch(isp);
1143 isp_update_otg(isp, stat);
1144 put_device(&isp->client.dev);
1147 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
1151 * skip A_WAIT_VRISE; hc transitions invisibly
1152 * skip A_WAIT_BCON; same.
1154 switch (isp->otg.state) {
1155 case OTG_STATE_A_WAIT_BCON:
1156 case OTG_STATE_A_WAIT_VRISE:
1157 isp->otg.state = OTG_STATE_A_HOST;
1158 pr_debug(" --> a_host\n");
1159 otg_ctrl = OTG_CTRL_REG;
1160 otg_ctrl |= OTG_A_BUSREQ;
1161 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
1163 OTG_CTRL_REG = otg_ctrl;
1165 case OTG_STATE_B_WAIT_ACON:
1166 isp->otg.state = OTG_STATE_B_HOST;
1167 pr_debug(" --> b_host (acon)\n");
1169 case OTG_STATE_B_HOST:
1170 case OTG_STATE_B_IDLE:
1171 case OTG_STATE_A_IDLE:
1174 pr_debug(" host resume in %s\n",
1179 put_device(&isp->client.dev);
1182 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
1184 dump_regs(isp, "timer");
1186 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1188 put_device(&isp->client.dev);
1192 dev_vdbg(&isp->client.dev,
1193 "work done, todo = 0x%lx\n",
1196 dev_dbg(&isp->client.dev, "stop\n");
1199 } while (isp->todo);
1203 static irqreturn_t isp1301_irq(int irq, void *isp)
1205 isp1301_defer_work(isp, WORK_UPDATE_OTG);
1209 static void isp1301_timer(unsigned long _isp)
1211 isp1301_defer_work((void *)_isp, WORK_TIMER);
1214 /*-------------------------------------------------------------------------*/
1216 static void isp1301_release(struct device *dev)
1218 struct isp1301 *isp;
1220 isp = container_of(dev, struct isp1301, client.dev);
1222 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1223 if (isp->i2c_release)
1224 isp->i2c_release(dev);
1228 static struct isp1301 *the_transceiver;
1230 static int isp1301_detach_client(struct i2c_client *i2c)
1232 struct isp1301 *isp;
1234 isp = container_of(i2c, struct isp1301, client);
1236 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1237 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1238 free_irq(isp->irq, isp);
1239 #ifdef CONFIG_USB_OTG
1242 if (machine_is_omap_h2())
1245 if (machine_is_omap_h3())
1248 if (machine_is_omap_h4())
1249 omap_free_gpio(125);
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(&i2c->dev);
1257 the_transceiver = 0;
1259 return i2c_detach_client(i2c);
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)
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;
1330 if (machine_is_omap_h2() || machine_is_omap_h3())
1331 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1333 dev_info(&isp->client.dev, "A-Host sessions ok\n");
1334 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1336 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1339 /* If this has a Mini-AB connector, this mode is highly
1340 * nonstandard ... but can be handy for testing, especially with
1341 * the Mini-A end of an OTG cable. (Or something nonstandard
1342 * like MiniB-to-StandardB, maybe built with a gender mender.)
1344 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV);
1346 dump_regs(isp, __FUNCTION__);
1351 dev_dbg(&isp->client.dev, "host sessions not allowed\n");
1358 isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1360 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1362 if (!otg || isp != the_transceiver)
1367 if (!isp->otg.default_a)
1368 enable_vbus_draw(isp, 0);
1369 usb_gadget_vbus_disconnect(isp->otg.gadget);
1370 isp->otg.gadget = 0;
1375 #ifdef CONFIG_USB_OTG
1376 isp->otg.gadget = gadget;
1377 dev_dbg(&isp->client.dev, "registered gadget\n");
1378 /* gadget driver may be suspended until vbus_connect () */
1380 return isp1301_otg_enable(isp);
1383 #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1384 isp->otg.gadget = gadget;
1385 // FIXME update its refcount
1387 OTG_CTRL_REG = (OTG_CTRL_REG & OTG_CTRL_MASK
1388 & ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS))
1391 isp->otg.state = OTG_STATE_B_IDLE;
1394 if (machine_is_omap_h2() || machine_is_omap_h3())
1395 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1397 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1398 INTR_SESS_VLD | INTR_VBUS_VLD);
1399 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1400 INTR_VBUS_VLD | INTR_SESS_VLD);
1401 dev_info(&isp->client.dev, "B-Peripheral sessions ok\n");
1402 dump_regs(isp, __FUNCTION__);
1404 /* If this has a Mini-AB connector, this mode is highly
1405 * nonstandard ... but can be handy for testing, so long
1406 * as you don't plug a Mini-A cable into the jack.
1408 if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD)
1414 dev_dbg(&isp->client.dev, "peripheral sessions not allowed\n");
1420 /*-------------------------------------------------------------------------*/
1423 isp1301_set_power(struct otg_transceiver *dev, unsigned mA)
1425 if (!the_transceiver)
1427 if (dev->state == OTG_STATE_B_PERIPHERAL)
1428 enable_vbus_draw(the_transceiver, mA);
1433 isp1301_start_srp(struct otg_transceiver *dev)
1435 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1438 if (!dev || isp != the_transceiver
1439 || isp->otg.state != OTG_STATE_B_IDLE)
1442 otg_ctrl = OTG_CTRL_REG;
1443 if (!(otg_ctrl & OTG_BSESSEND))
1446 otg_ctrl |= OTG_B_BUSREQ;
1447 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
1448 OTG_CTRL_REG = otg_ctrl;
1449 isp->otg.state = OTG_STATE_B_SRP_INIT;
1451 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), OTG_CTRL_REG);
1452 #ifdef CONFIG_USB_OTG
1453 check_state(isp, __FUNCTION__);
1459 isp1301_start_hnp(struct otg_transceiver *dev)
1461 #ifdef CONFIG_USB_OTG
1462 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_PERIPHERAL:
1478 isp->otg.state = OTG_STATE_B_WAIT_ACON;
1479 isp1301_defer_work(isp, WORK_UPDATE_ISP);
1481 case OTG_STATE_B_HOST:
1482 isp->otg.state = OTG_STATE_B_PERIPHERAL;
1483 /* caller will suspend next */
1485 case OTG_STATE_A_HOST:
1487 /* autoconnect mode avoids irq latency bugs */
1488 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1491 /* caller must suspend then clear A_BUSREQ */
1492 usb_gadget_vbus_connect(isp->otg.gadget);
1493 OTG_CTRL_REG |= OTG_A_SETB_HNPEN;
1496 case OTG_STATE_A_PERIPHERAL:
1497 /* initiated by B-Host suspend */
1502 pr_debug("otg: HNP %s, %06x ...\n",
1503 state_name(isp), OTG_CTRL_REG);
1504 check_state(isp, __FUNCTION__);
1512 /*-------------------------------------------------------------------------*/
1514 /* no error returns, they'd just make bus scanning stop */
1515 static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1518 struct isp1301 *isp;
1519 struct i2c_client *i2c;
1521 if (the_transceiver)
1524 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1528 INIT_WORK(&isp->work, isp1301_work);
1529 init_timer(&isp->timer);
1530 isp->timer.function = isp1301_timer;
1531 isp->timer.data = (unsigned long) isp;
1535 isp->client.addr = address;
1536 i2c_set_clientdata(&isp->client, isp);
1537 isp->client.adapter = bus;
1538 isp->client.driver = &isp1301_driver;
1539 strlcpy(isp->client.name, DRIVER_NAME, I2C_NAME_SIZE);
1542 /* if this is a true probe, verify the chip ... */
1544 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1545 if (status != I2C_VENDOR_ID_PHILIPS) {
1546 dev_dbg(&bus->dev, "addr %d not philips id: %d\n",
1550 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1551 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1552 dev_dbg(&bus->dev, "%d not isp1301, %d\n",
1558 status = i2c_attach_client(i2c);
1560 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n",
1561 DRIVER_NAME, address, status);
1566 isp->i2c_release = i2c->dev.release;
1567 i2c->dev.release = isp1301_release;
1569 /* initial development used chiprev 2.00 */
1570 status = i2c_smbus_read_word_data(i2c, ISP1301_BCD_DEVICE);
1571 dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n",
1572 status >> 8, status & 0xff);
1574 /* make like power-on reset */
1575 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK);
1577 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI);
1578 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI);
1580 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1581 OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
1582 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1583 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
1585 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0);
1586 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1587 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1589 #ifdef CONFIG_USB_OTG
1590 status = otg_bind(isp);
1592 dev_dbg(&i2c->dev, "can't bind OTG\n");
1598 if (machine_is_omap_h2() || machine_is_omap_h3()) {
1599 /* full speed signaling by default */
1600 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1602 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2,
1606 if (machine_is_omap_h2()) {
1607 /* IRQ wired at M14 */
1608 omap_cfg_reg(M14_1510_GPIO2);
1609 isp->irq = OMAP_GPIO_IRQ(2);
1610 omap_request_gpio(2);
1611 omap_set_gpio_direction(2, 1);
1612 isp->irq_type = IRQF_TRIGGER_FALLING;
1615 if (machine_is_omap_h3()) {
1616 /* IRQ wired at N21 */
1617 omap_cfg_reg(N21_1710_GPIO14);
1618 isp->irq = OMAP_GPIO_IRQ(14);
1619 omap_request_gpio(14);
1620 omap_set_gpio_direction(14, 1);
1621 isp->irq_type = IRQF_TRIGGER_FALLING;
1624 if (machine_is_omap_h4()) {
1625 /* IRQ wired at P14 */
1626 omap_cfg_reg(P14_24XX_GPIO125);
1627 isp->irq = OMAP_GPIO_IRQ(125);
1628 omap_request_gpio(125);
1629 omap_set_gpio_direction(125, 1);
1630 isp->irq_type = IRQF_TRIGGER_LOW;
1633 status = request_irq(isp->irq, isp1301_irq,
1634 isp->irq_type, DRIVER_NAME, isp);
1636 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n",
1638 #ifdef CONFIG_USB_OTG
1641 i2c_detach_client(i2c);
1645 isp->otg.dev = &isp->client.dev;
1646 isp->otg.label = DRIVER_NAME;
1648 isp->otg.set_host = isp1301_set_host,
1649 isp->otg.set_peripheral = isp1301_set_peripheral,
1650 isp->otg.set_power = isp1301_set_power,
1651 isp->otg.start_srp = isp1301_start_srp,
1652 isp->otg.start_hnp = isp1301_start_hnp,
1654 enable_vbus_draw(isp, 0);
1656 the_transceiver = isp;
1658 #ifdef CONFIG_USB_OTG
1659 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
1660 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
1663 dump_regs(isp, __FUNCTION__);
1666 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1667 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1670 status = otg_set_transceiver(&isp->otg);
1672 dev_err(&i2c->dev, "can't register transceiver, %d\n",
1678 static int isp1301_scan_bus(struct i2c_adapter *bus)
1680 if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA
1681 | I2C_FUNC_SMBUS_READ_WORD_DATA))
1683 return i2c_probe(bus, &addr_data, isp1301_probe);
1686 static struct i2c_driver isp1301_driver = {
1688 .name = "isp1301_omap",
1690 .attach_adapter = isp1301_scan_bus,
1691 .detach_client = isp1301_detach_client,
1694 /*-------------------------------------------------------------------------*/
1696 static int __init isp_init(void)
1698 return i2c_add_driver(&isp1301_driver);
1700 module_init(isp_init);
1702 static void __exit isp_exit(void)
1704 if (the_transceiver)
1705 otg_set_transceiver(0);
1706 i2c_del_driver(&isp1301_driver);
1708 module_exit(isp_exit);