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/gpio.h>
29 #include <linux/usb/ch9.h>
30 #include <linux/usb/gadget.h>
31 #include <linux/usb.h>
32 #include <linux/usb/otg.h>
33 #include <linux/i2c.h>
34 #include <linux/workqueue.h>
38 #include <asm/mach-types.h>
49 #define DRIVER_VERSION "24 August 2004"
50 #define DRIVER_NAME (isp1301_driver.driver.name)
52 MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver");
53 MODULE_LICENSE("GPL");
56 struct otg_transceiver otg;
57 struct i2c_client *client;
58 void (*i2c_release)(struct device *dev);
65 struct timer_list timer;
67 /* use keventd context to change the state for us */
68 struct work_struct work;
71 # define WORK_UPDATE_ISP 0 /* update ISP from OTG */
72 # define WORK_UPDATE_OTG 1 /* update OTG from ISP */
73 # define WORK_HOST_RESUME 4 /* resume host */
74 # define WORK_TIMER 6 /* timer fired */
75 # define WORK_STOP 7 /* don't resubmit */
79 /* bits in OTG_CTRL */
81 #define OTG_XCEIV_OUTPUTS \
82 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
83 #define OTG_XCEIV_INPUTS \
84 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
85 #define OTG_CTRL_BITS \
86 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
87 /* and OTG_PULLUP is sometimes written */
89 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
90 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
94 /*-------------------------------------------------------------------------*/
96 /* board-specific PM hooks */
98 #if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3)
100 #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
102 #include <linux/i2c/tps65010.h>
106 static inline int tps65010_set_vbus_draw(unsigned mA)
108 pr_debug("tps65010: draw %d mA (STUB)\n", mA);
114 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
116 int status = tps65010_set_vbus_draw(mA);
118 pr_debug(" VBUS %d mA error %d\n", mA, status);
121 static void enable_vbus_source(struct isp1301 *isp)
123 /* this board won't supply more than 8mA vbus power.
124 * some boards can switch a 100ma "unit load" (or more).
129 /* products will deliver OTG messages with LEDs, GUI, etc */
130 static inline void notresponding(struct isp1301 *isp)
132 printk(KERN_NOTICE "OTG device not responding.\n");
138 #if defined(CONFIG_MACH_OMAP_H4)
140 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
142 /* H4 controls this by DIP switch S2.4; no soft control.
143 * ON means the charger is always enabled. Leave it OFF
144 * unless the OTG port is used only in B-peripheral mode.
148 static void enable_vbus_source(struct isp1301 *isp)
150 /* this board won't supply more than 8mA vbus power.
151 * some boards can switch a 100ma "unit load" (or more).
156 /* products will deliver OTG messages with LEDs, GUI, etc */
157 static inline void notresponding(struct isp1301 *isp)
159 printk(KERN_NOTICE "OTG device not responding.\n");
165 /*-------------------------------------------------------------------------*/
167 static struct i2c_driver isp1301_driver;
169 /* smbus apis are used for portability */
172 isp1301_get_u8(struct isp1301 *isp, u8 reg)
174 return i2c_smbus_read_byte_data(isp->client, reg + 0);
178 isp1301_get_u16(struct isp1301 *isp, u8 reg)
180 return i2c_smbus_read_word_data(isp->client, reg);
184 isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
186 return i2c_smbus_write_byte_data(isp->client, reg + 0, bits);
190 isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
192 return i2c_smbus_write_byte_data(isp->client, reg + 1, bits);
195 /*-------------------------------------------------------------------------*/
198 #define ISP1301_VENDOR_ID 0x00 /* u16 read */
199 #define ISP1301_PRODUCT_ID 0x02 /* u16 read */
200 #define ISP1301_BCD_DEVICE 0x14 /* u16 read */
202 #define I2C_VENDOR_ID_PHILIPS 0x04cc
203 #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
205 /* operational registers */
206 #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
207 # define MC1_SPEED (1 << 0)
208 # define MC1_SUSPEND (1 << 1)
209 # define MC1_DAT_SE0 (1 << 2)
210 # define MC1_TRANSPARENT (1 << 3)
211 # define MC1_BDIS_ACON_EN (1 << 4)
212 # define MC1_OE_INT_EN (1 << 5)
213 # define MC1_UART_EN (1 << 6)
214 # define MC1_MASK 0x7f
215 #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
216 # define MC2_GLOBAL_PWR_DN (1 << 0)
217 # define MC2_SPD_SUSP_CTRL (1 << 1)
218 # define MC2_BI_DI (1 << 2)
219 # define MC2_TRANSP_BDIR0 (1 << 3)
220 # define MC2_TRANSP_BDIR1 (1 << 4)
221 # define MC2_AUDIO_EN (1 << 5)
222 # define MC2_PSW_EN (1 << 6)
223 # define MC2_EN2V7 (1 << 7)
224 #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
225 # define OTG1_DP_PULLUP (1 << 0)
226 # define OTG1_DM_PULLUP (1 << 1)
227 # define OTG1_DP_PULLDOWN (1 << 2)
228 # define OTG1_DM_PULLDOWN (1 << 3)
229 # define OTG1_ID_PULLDOWN (1 << 4)
230 # define OTG1_VBUS_DRV (1 << 5)
231 # define OTG1_VBUS_DISCHRG (1 << 6)
232 # define OTG1_VBUS_CHRG (1 << 7)
233 #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
234 # define OTG_B_SESS_END (1 << 6)
235 # define OTG_B_SESS_VLD (1 << 7)
237 #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */
238 #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */
240 #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */
241 #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */
243 /* same bitfields in all interrupt registers */
244 # define INTR_VBUS_VLD (1 << 0)
245 # define INTR_SESS_VLD (1 << 1)
246 # define INTR_DP_HI (1 << 2)
247 # define INTR_ID_GND (1 << 3)
248 # define INTR_DM_HI (1 << 4)
249 # define INTR_ID_FLOAT (1 << 5)
250 # define INTR_BDIS_ACON (1 << 6)
251 # define INTR_CR_INT (1 << 7)
253 /*-------------------------------------------------------------------------*/
255 static const char *state_string(enum usb_otg_state state)
258 case OTG_STATE_A_IDLE: return "a_idle";
259 case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
260 case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
261 case OTG_STATE_A_HOST: return "a_host";
262 case OTG_STATE_A_SUSPEND: return "a_suspend";
263 case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
264 case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
265 case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
266 case OTG_STATE_B_IDLE: return "b_idle";
267 case OTG_STATE_B_SRP_INIT: return "b_srp_init";
268 case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
269 case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
270 case OTG_STATE_B_HOST: return "b_host";
271 default: return "UNDEFINED";
275 static inline const char *state_name(struct isp1301 *isp)
277 return state_string(isp->otg.state);
280 /*-------------------------------------------------------------------------*/
282 /* NOTE: some of this ISP1301 setup is specific to H2 boards;
283 * not everything is guarded by board-specific checks, or even using
284 * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI.
286 * ALSO: this currently doesn't use ISP1301 low-power modes
287 * while OTG is running.
290 static void power_down(struct isp1301 *isp)
292 isp->otg.state = OTG_STATE_UNDEFINED;
294 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
295 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
297 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN);
298 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
301 static void power_up(struct isp1301 *isp)
303 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
304 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
306 /* do this only when cpu is driving transceiver,
307 * so host won't see a low speed device...
309 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
312 #define NO_HOST_SUSPEND
314 static int host_suspend(struct isp1301 *isp)
316 #ifdef NO_HOST_SUSPEND
324 /* Currently ASSUMES only the OTG port matters;
325 * other ports could be active...
327 dev = isp->otg.host->controller;
328 return dev->driver->suspend(dev, 3, 0);
332 static int host_resume(struct isp1301 *isp)
334 #ifdef NO_HOST_SUSPEND
342 dev = isp->otg.host->controller;
343 return dev->driver->resume(dev, 0);
347 static int gadget_suspend(struct isp1301 *isp)
349 isp->otg.gadget->b_hnp_enable = 0;
350 isp->otg.gadget->a_hnp_support = 0;
351 isp->otg.gadget->a_alt_hnp_support = 0;
352 return usb_gadget_vbus_disconnect(isp->otg.gadget);
355 /*-------------------------------------------------------------------------*/
357 #define TIMER_MINUTES 10
358 #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
360 /* Almost all our I2C messaging comes from a work queue's task context.
361 * NOTE: guaranteeing certain response times might mean we shouldn't
362 * share keventd's work queue; a realtime task might be safest.
364 static void isp1301_defer_work(struct isp1301 *isp, int work)
368 if (isp && !test_and_set_bit(work, &isp->todo)) {
369 (void) get_device(&isp->client->dev);
370 status = schedule_work(&isp->work);
371 if (!status && !isp->working)
372 dev_vdbg(&isp->client->dev,
373 "work item %d may be lost\n", work);
377 /* called from irq handlers */
378 static void a_idle(struct isp1301 *isp, const char *tag)
382 if (isp->otg.state == OTG_STATE_A_IDLE)
385 isp->otg.default_a = 1;
387 isp->otg.host->is_b_host = 0;
390 if (isp->otg.gadget) {
391 isp->otg.gadget->is_a_peripheral = 1;
394 isp->otg.state = OTG_STATE_A_IDLE;
395 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
396 omap_writel(l, OTG_CTRL);
397 isp->last_otg_ctrl = l;
398 pr_debug(" --> %s/%s\n", state_name(isp), tag);
401 /* called from irq handlers */
402 static void b_idle(struct isp1301 *isp, const char *tag)
406 if (isp->otg.state == OTG_STATE_B_IDLE)
409 isp->otg.default_a = 0;
411 isp->otg.host->is_b_host = 1;
414 if (isp->otg.gadget) {
415 isp->otg.gadget->is_a_peripheral = 0;
418 isp->otg.state = OTG_STATE_B_IDLE;
419 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
420 omap_writel(l, OTG_CTRL);
421 isp->last_otg_ctrl = l;
422 pr_debug(" --> %s/%s\n", state_name(isp), tag);
426 dump_regs(struct isp1301 *isp, const char *label)
429 u8 ctrl = isp1301_get_u8(isp, ISP1301_OTG_CONTROL_1);
430 u8 status = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
431 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
433 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
434 omap_readl(OTG_CTRL), label, state_name(isp),
436 /* mode control and irq enables don't change much */
440 /*-------------------------------------------------------------------------*/
442 #ifdef CONFIG_USB_OTG
445 * The OMAP OTG controller handles most of the OTG state transitions.
447 * We translate isp1301 outputs (mostly voltage comparator status) into
448 * OTG inputs; OTG outputs (mostly pullup/pulldown controls) and HNP state
449 * flags into isp1301 inputs ... and infer state transitions.
454 static void check_state(struct isp1301 *isp, const char *tag)
456 enum usb_otg_state state = OTG_STATE_UNDEFINED;
457 u8 fsm = omap_readw(OTG_TEST) & 0x0ff;
464 state = OTG_STATE_B_IDLE;
470 state = OTG_STATE_B_PERIPHERAL;
473 state = OTG_STATE_B_SRP_INIT;
476 /* extra dual-role default-b states */
482 state = OTG_STATE_B_WAIT_ACON;
485 state = OTG_STATE_B_HOST;
490 state = OTG_STATE_A_IDLE;
493 state = OTG_STATE_A_WAIT_VFALL;
496 state = OTG_STATE_A_VBUS_ERR;
502 state = OTG_STATE_A_PERIPHERAL;
505 state = OTG_STATE_A_WAIT_VRISE;
508 state = OTG_STATE_A_WAIT_BCON;
511 state = OTG_STATE_A_HOST;
514 state = OTG_STATE_A_SUSPEND;
519 if (isp->otg.state == state && !extra)
521 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
522 state_string(state), fsm, state_name(isp),
523 omap_readl(OTG_CTRL));
528 static inline void check_state(struct isp1301 *isp, const char *tag) { }
532 /* outputs from ISP1301_INTERRUPT_SOURCE */
533 static void update_otg1(struct isp1301 *isp, u8 int_src)
537 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
538 otg_ctrl &= ~OTG_XCEIV_INPUTS;
539 otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
541 if (int_src & INTR_SESS_VLD)
542 otg_ctrl |= OTG_ASESSVLD;
543 else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) {
544 a_idle(isp, "vfall");
545 otg_ctrl &= ~OTG_CTRL_BITS;
547 if (int_src & INTR_VBUS_VLD)
548 otg_ctrl |= OTG_VBUSVLD;
549 if (int_src & 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 omap_writel(otg_ctrl, OTG_CTRL);
566 /* outputs from ISP1301_OTG_STATUS */
567 static void update_otg2(struct isp1301 *isp, u8 otg_status)
571 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
572 otg_ctrl &= ~OTG_XCEIV_INPUTS;
573 otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND);
574 if (otg_status & OTG_B_SESS_VLD)
575 otg_ctrl |= OTG_BSESSVLD;
576 else if (otg_status & OTG_B_SESS_END)
577 otg_ctrl |= OTG_BSESSEND;
578 omap_writel(otg_ctrl, OTG_CTRL);
581 /* inputs going to ISP1301 */
582 static void otg_update_isp(struct isp1301 *isp)
584 u32 otg_ctrl, otg_change;
585 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
587 otg_ctrl = omap_readl(OTG_CTRL);
588 otg_change = otg_ctrl ^ isp->last_otg_ctrl;
589 isp->last_otg_ctrl = otg_ctrl;
590 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
592 switch (isp->otg.state) {
593 case OTG_STATE_B_IDLE:
594 case OTG_STATE_B_PERIPHERAL:
595 case OTG_STATE_B_SRP_INIT:
596 if (!(otg_ctrl & OTG_PULLUP)) {
597 // if (otg_ctrl & OTG_B_HNPEN) {
598 if (isp->otg.gadget->b_hnp_enable) {
599 isp->otg.state = OTG_STATE_B_WAIT_ACON;
600 pr_debug(" --> b_wait_acon\n");
605 set |= OTG1_DP_PULLUP;
606 clr |= OTG1_DP_PULLDOWN;
608 case OTG_STATE_A_SUSPEND:
609 case OTG_STATE_A_PERIPHERAL:
610 if (otg_ctrl & OTG_PULLUP)
613 // case OTG_STATE_B_WAIT_ACON:
616 set |= OTG1_DP_PULLDOWN;
617 clr |= OTG1_DP_PULLUP;
621 # define toggle(OTG,ISP) do { \
622 if (otg_ctrl & OTG) set |= ISP; \
626 if (!(isp->otg.host))
627 otg_ctrl &= ~OTG_DRV_VBUS;
629 switch (isp->otg.state) {
630 case OTG_STATE_A_SUSPEND:
631 if (otg_ctrl & OTG_DRV_VBUS) {
632 set |= OTG1_VBUS_DRV;
635 /* HNP failed for some reason (A_AIDL_BDIS timeout) */
639 case OTG_STATE_A_VBUS_ERR:
640 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
641 pr_debug(" --> a_wait_vfall\n");
643 case OTG_STATE_A_WAIT_VFALL:
644 /* FIXME usbcore thinks port power is still on ... */
645 clr |= OTG1_VBUS_DRV;
647 case OTG_STATE_A_IDLE:
648 if (otg_ctrl & OTG_DRV_VBUS) {
649 isp->otg.state = OTG_STATE_A_WAIT_VRISE;
650 pr_debug(" --> a_wait_vrise\n");
654 toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV);
657 toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG);
658 toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG);
662 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set);
663 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr);
665 /* HNP switch to host or peripheral; and SRP */
666 if (otg_change & OTG_PULLUP) {
669 switch (isp->otg.state) {
670 case OTG_STATE_B_IDLE:
671 if (clr & OTG1_DP_PULLUP)
673 isp->otg.state = OTG_STATE_B_PERIPHERAL;
674 pr_debug(" --> b_peripheral\n");
676 case OTG_STATE_A_SUSPEND:
677 if (clr & OTG1_DP_PULLUP)
679 isp->otg.state = OTG_STATE_A_PERIPHERAL;
680 pr_debug(" --> a_peripheral\n");
685 l = omap_readl(OTG_CTRL);
687 omap_writel(l, OTG_CTRL);
690 check_state(isp, __func__);
691 dump_regs(isp, "otg->isp1301");
694 static irqreturn_t omap_otg_irq(int irq, void *_isp)
696 u16 otg_irq = omap_readw(OTG_IRQ_SRC);
699 struct isp1301 *isp = _isp;
701 /* update ISP1301 transciever from OTG controller */
702 if (otg_irq & OPRT_CHG) {
703 omap_writew(OPRT_CHG, OTG_IRQ_SRC);
704 isp1301_defer_work(isp, WORK_UPDATE_ISP);
707 /* SRP to become b_peripheral failed */
708 } else if (otg_irq & B_SRP_TMROUT) {
709 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL));
712 /* gadget drivers that care should monitor all kinds of
713 * remote wakeup (SRP, normal) using their own timer
714 * to give "check cable and A-device" messages.
716 if (isp->otg.state == OTG_STATE_B_SRP_INIT)
717 b_idle(isp, "srp_timeout");
719 omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
722 /* HNP to become b_host failed */
723 } else if (otg_irq & B_HNP_FAIL) {
724 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
725 state_name(isp), omap_readl(OTG_CTRL));
728 otg_ctrl = omap_readl(OTG_CTRL);
729 otg_ctrl |= OTG_BUSDROP;
730 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
731 omap_writel(otg_ctrl, OTG_CTRL);
733 /* subset of b_peripheral()... */
734 isp->otg.state = OTG_STATE_B_PERIPHERAL;
735 pr_debug(" --> b_peripheral\n");
737 omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
740 /* detect SRP from B-device ... */
741 } else if (otg_irq & A_SRP_DETECT) {
742 pr_debug("otg: %s SRP_DETECT, %06x\n",
743 state_name(isp), omap_readl(OTG_CTRL));
745 isp1301_defer_work(isp, WORK_UPDATE_OTG);
746 switch (isp->otg.state) {
747 case OTG_STATE_A_IDLE:
750 isp1301_defer_work(isp, WORK_HOST_RESUME);
751 otg_ctrl = omap_readl(OTG_CTRL);
752 otg_ctrl |= OTG_A_BUSREQ;
753 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
756 omap_writel(otg_ctrl, OTG_CTRL);
762 omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
765 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
766 * we don't track them separately
768 } else if (otg_irq & A_REQ_TMROUT) {
769 otg_ctrl = omap_readl(OTG_CTRL);
770 pr_info("otg: BCON_TMOUT from %s, %06x\n",
771 state_name(isp), otg_ctrl);
774 otg_ctrl |= OTG_BUSDROP;
775 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
776 omap_writel(otg_ctrl, OTG_CTRL);
777 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
779 omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
782 /* A-supplied voltage fell too low; overcurrent */
783 } else if (otg_irq & A_VBUS_ERR) {
784 otg_ctrl = omap_readl(OTG_CTRL);
785 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
786 state_name(isp), otg_irq, otg_ctrl);
788 otg_ctrl |= OTG_BUSDROP;
789 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
790 omap_writel(otg_ctrl, OTG_CTRL);
791 isp->otg.state = OTG_STATE_A_VBUS_ERR;
793 omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
796 /* switch driver; the transciever code activates it,
797 * ungating the udc clock or resuming OHCI.
799 } else if (otg_irq & DRIVER_SWITCH) {
802 otg_ctrl = omap_readl(OTG_CTRL);
803 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
805 (otg_ctrl & OTG_DRIVER_SEL)
808 isp1301_defer_work(isp, WORK_UPDATE_ISP);
810 /* role is peripheral */
811 if (otg_ctrl & OTG_DRIVER_SEL) {
812 switch (isp->otg.state) {
813 case OTG_STATE_A_IDLE:
814 b_idle(isp, __func__);
819 isp1301_defer_work(isp, WORK_UPDATE_ISP);
823 if (!(otg_ctrl & OTG_ID)) {
824 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
825 omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL);
829 switch (isp->otg.state) {
830 case OTG_STATE_B_WAIT_ACON:
831 isp->otg.state = OTG_STATE_B_HOST;
832 pr_debug(" --> b_host\n");
835 case OTG_STATE_A_WAIT_BCON:
836 isp->otg.state = OTG_STATE_A_HOST;
837 pr_debug(" --> a_host\n");
839 case OTG_STATE_A_PERIPHERAL:
840 isp->otg.state = OTG_STATE_A_WAIT_BCON;
841 pr_debug(" --> a_wait_bcon\n");
846 isp1301_defer_work(isp, WORK_HOST_RESUME);
850 omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
854 usb_bus_start_enum(isp->otg.host,
855 isp->otg.host->otg_port);
858 check_state(isp, __func__);
862 static struct platform_device *otg_dev;
864 static int otg_init(struct isp1301 *isp)
871 dump_regs(isp, __func__);
872 /* some of these values are board-specific... */
873 l = omap_readl(OTG_SYSCON_2);
876 | SRP_GPDATA /* 9msec Bdev D+ pulse */
877 | SRP_GPDVBUS /* discharge after VBUS pulse */
878 // | (3 << 24) /* 2msec VBUS pulse */
880 | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
881 | SRP_DPW /* detect 167+ns SRP pulses */
882 | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */
884 omap_writel(l, OTG_SYSCON_2);
886 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
887 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
889 check_state(isp, __func__);
890 pr_debug("otg: %s, %s %06x\n",
891 state_name(isp), __func__, omap_readl(OTG_CTRL));
893 omap_writew(DRIVER_SWITCH | OPRT_CHG
894 | B_SRP_TMROUT | B_HNP_FAIL
895 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN);
897 l = omap_readl(OTG_SYSCON_2);
899 omap_writel(l, OTG_SYSCON_2);
904 static int otg_probe(struct platform_device *dev)
906 // struct omap_usb_config *config = dev->platform_data;
912 static int otg_remove(struct platform_device *dev)
918 static struct platform_driver omap_otg_driver = {
920 .remove = otg_remove,
922 .owner = THIS_MODULE,
927 static int otg_bind(struct isp1301 *isp)
934 status = platform_driver_register(&omap_otg_driver);
939 status = request_irq(otg_dev->resource[1].start, omap_otg_irq,
940 IRQF_DISABLED, DRIVER_NAME, isp);
945 platform_driver_unregister(&omap_otg_driver);
949 static void otg_unbind(struct isp1301 *isp)
953 free_irq(otg_dev->resource[1].start, isp);
958 /* OTG controller isn't clocked */
960 #endif /* CONFIG_USB_OTG */
962 /*-------------------------------------------------------------------------*/
964 static void b_peripheral(struct isp1301 *isp)
968 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
969 omap_writel(l, OTG_CTRL);
971 usb_gadget_vbus_connect(isp->otg.gadget);
973 #ifdef CONFIG_USB_OTG
974 enable_vbus_draw(isp, 8);
977 enable_vbus_draw(isp, 100);
978 /* UDC driver just set OTG_BSESSVLD */
979 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP);
980 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN);
981 isp->otg.state = OTG_STATE_B_PERIPHERAL;
982 pr_debug(" --> b_peripheral\n");
983 dump_regs(isp, "2periph");
987 static void isp_update_otg(struct isp1301 *isp, u8 stat)
989 u8 isp_stat, isp_bstat;
990 enum usb_otg_state state = isp->otg.state;
992 if (stat & INTR_BDIS_ACON)
993 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp));
995 /* start certain state transitions right away */
996 isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
997 if (isp_stat & INTR_ID_GND) {
998 if (isp->otg.default_a) {
1000 case OTG_STATE_B_IDLE:
1001 a_idle(isp, "idle");
1003 case OTG_STATE_A_IDLE:
1004 enable_vbus_source(isp);
1006 case OTG_STATE_A_WAIT_VRISE:
1007 /* we skip over OTG_STATE_A_WAIT_BCON, since
1008 * the HC will transition to A_HOST (or
1009 * A_SUSPEND!) without our noticing except
1012 if (isp_stat & INTR_VBUS_VLD)
1013 isp->otg.state = OTG_STATE_A_HOST;
1015 case OTG_STATE_A_WAIT_VFALL:
1016 if (!(isp_stat & INTR_SESS_VLD))
1017 a_idle(isp, "vfell");
1020 if (!(isp_stat & INTR_VBUS_VLD))
1021 isp->otg.state = OTG_STATE_A_VBUS_ERR;
1024 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1027 case OTG_STATE_B_PERIPHERAL:
1028 case OTG_STATE_B_HOST:
1029 case OTG_STATE_B_WAIT_ACON:
1030 usb_gadget_vbus_disconnect(isp->otg.gadget);
1035 if (state != OTG_STATE_A_IDLE)
1037 if (isp->otg.host && state == OTG_STATE_A_IDLE)
1038 isp1301_defer_work(isp, WORK_HOST_RESUME);
1044 /* if user unplugged mini-A end of cable,
1045 * don't bypass A_WAIT_VFALL.
1047 if (isp->otg.default_a) {
1050 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
1052 case OTG_STATE_A_WAIT_VFALL:
1053 state = OTG_STATE_A_IDLE;
1054 /* khubd may take a while to notice and
1055 * handle this disconnect, so don't go
1056 * to B_IDLE quite yet.
1059 case OTG_STATE_A_IDLE:
1061 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
1063 isp->otg.state = OTG_STATE_B_IDLE;
1064 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1065 l &= ~OTG_CTRL_BITS;
1066 omap_writel(l, OTG_CTRL);
1068 case OTG_STATE_B_IDLE:
1072 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1074 switch (isp->otg.state) {
1075 case OTG_STATE_B_PERIPHERAL:
1076 case OTG_STATE_B_WAIT_ACON:
1077 case OTG_STATE_B_HOST:
1078 if (likely(isp_bstat & OTG_B_SESS_VLD))
1080 enable_vbus_draw(isp, 0);
1081 #ifndef CONFIG_USB_OTG
1082 /* UDC driver will clear OTG_BSESSVLD */
1083 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1085 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1087 dump_regs(isp, __func__);
1090 case OTG_STATE_B_SRP_INIT:
1091 b_idle(isp, __func__);
1092 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
1093 omap_writel(l, OTG_CTRL);
1095 case OTG_STATE_B_IDLE:
1096 if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) {
1097 #ifdef CONFIG_USB_OTG
1098 update_otg1(isp, isp_stat);
1099 update_otg2(isp, isp_bstat);
1102 } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD)))
1103 isp_bstat |= OTG_B_SESS_END;
1105 case OTG_STATE_A_WAIT_VFALL:
1108 pr_debug("otg: unsupported b-device %s\n",
1114 if (state != isp->otg.state)
1115 pr_debug(" isp, %s -> %s\n",
1116 state_string(state), state_name(isp));
1118 #ifdef CONFIG_USB_OTG
1119 /* update the OTG controller state to match the isp1301; may
1120 * trigger OPRT_CHG irqs for changes going to the isp1301.
1122 update_otg1(isp, isp_stat);
1123 update_otg2(isp, isp_bstat);
1124 check_state(isp, __func__);
1127 dump_regs(isp, "isp1301->otg");
1130 /*-------------------------------------------------------------------------*/
1132 static u8 isp1301_clear_latch(struct isp1301 *isp)
1134 u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH);
1135 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch);
1140 isp1301_work(struct work_struct *work)
1142 struct isp1301 *isp = container_of(work, struct isp1301, work);
1145 /* implicit lock: we're the only task using this device */
1148 stop = test_bit(WORK_STOP, &isp->todo);
1150 #ifdef CONFIG_USB_OTG
1151 /* transfer state from otg engine to isp1301 */
1152 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1153 otg_update_isp(isp);
1154 put_device(&isp->client->dev);
1157 /* transfer state from isp1301 to otg engine */
1158 if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) {
1159 u8 stat = isp1301_clear_latch(isp);
1161 isp_update_otg(isp, stat);
1162 put_device(&isp->client->dev);
1165 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
1169 * skip A_WAIT_VRISE; hc transitions invisibly
1170 * skip A_WAIT_BCON; same.
1172 switch (isp->otg.state) {
1173 case OTG_STATE_A_WAIT_BCON:
1174 case OTG_STATE_A_WAIT_VRISE:
1175 isp->otg.state = OTG_STATE_A_HOST;
1176 pr_debug(" --> a_host\n");
1177 otg_ctrl = omap_readl(OTG_CTRL);
1178 otg_ctrl |= OTG_A_BUSREQ;
1179 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
1181 omap_writel(otg_ctrl, OTG_CTRL);
1183 case OTG_STATE_B_WAIT_ACON:
1184 isp->otg.state = OTG_STATE_B_HOST;
1185 pr_debug(" --> b_host (acon)\n");
1187 case OTG_STATE_B_HOST:
1188 case OTG_STATE_B_IDLE:
1189 case OTG_STATE_A_IDLE:
1192 pr_debug(" host resume in %s\n",
1197 put_device(&isp->client->dev);
1200 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
1202 dump_regs(isp, "timer");
1204 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1206 put_device(&isp->client->dev);
1210 dev_vdbg(&isp->client->dev,
1211 "work done, todo = 0x%lx\n",
1214 dev_dbg(&isp->client->dev, "stop\n");
1217 } while (isp->todo);
1221 static irqreturn_t isp1301_irq(int irq, void *isp)
1223 isp1301_defer_work(isp, WORK_UPDATE_OTG);
1227 static void isp1301_timer(unsigned long _isp)
1229 isp1301_defer_work((void *)_isp, WORK_TIMER);
1232 /*-------------------------------------------------------------------------*/
1234 static void isp1301_release(struct device *dev)
1236 struct isp1301 *isp;
1238 isp = dev_get_drvdata(dev);
1240 /* FIXME -- not with a "new style" driver, it doesn't!! */
1242 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1243 if (isp->i2c_release)
1244 isp->i2c_release(dev);
1248 static struct isp1301 *the_transceiver;
1250 static int __exit isp1301_remove(struct i2c_client *i2c)
1252 struct isp1301 *isp;
1254 isp = i2c_get_clientdata(i2c);
1256 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1257 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1258 free_irq(i2c->irq, isp);
1259 #ifdef CONFIG_USB_OTG
1262 if (machine_is_omap_h2())
1265 isp->timer.data = 0;
1266 set_bit(WORK_STOP, &isp->todo);
1267 del_timer_sync(&isp->timer);
1268 flush_scheduled_work();
1270 put_device(&i2c->dev);
1271 the_transceiver = NULL;
1276 /*-------------------------------------------------------------------------*/
1278 /* NOTE: three modes are possible here, only one of which
1279 * will be standards-conformant on any given system:
1281 * - OTG mode (dual-role), required if there's a Mini-AB connector
1282 * - HOST mode, for when there's one or more A (host) connectors
1283 * - DEVICE mode, for when there's a B/Mini-B (device) connector
1285 * As a rule, you won't have an isp1301 chip unless it's there to
1286 * support the OTG mode. Other modes help testing USB controllers
1287 * in isolation from (full) OTG support, or maybe so later board
1288 * revisions can help to support those feature.
1291 #ifdef CONFIG_USB_OTG
1293 static int isp1301_otg_enable(struct isp1301 *isp)
1298 /* NOTE: since we don't change this, this provides
1299 * a few more interrupts than are strictly needed.
1301 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1302 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1303 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1304 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1306 dev_info(&isp->client->dev, "ready for dual-role USB ...\n");
1313 /* add or disable the host device+driver */
1315 isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1317 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1319 if (!otg || isp != the_transceiver)
1323 omap_writew(0, OTG_IRQ_EN);
1325 isp->otg.host = NULL;
1329 #ifdef CONFIG_USB_OTG
1330 isp->otg.host = host;
1331 dev_dbg(&isp->client->dev, "registered host\n");
1333 if (isp->otg.gadget)
1334 return isp1301_otg_enable(isp);
1337 #elif !defined(CONFIG_USB_GADGET_OMAP)
1338 // FIXME update its refcount
1339 isp->otg.host = host;
1343 if (machine_is_omap_h2())
1344 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1346 dev_info(&isp->client->dev, "A-Host sessions ok\n");
1347 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1349 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1352 /* If this has a Mini-AB connector, this mode is highly
1353 * nonstandard ... but can be handy for testing, especially with
1354 * the Mini-A end of an OTG cable. (Or something nonstandard
1355 * like MiniB-to-StandardB, maybe built with a gender mender.)
1357 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV);
1359 dump_regs(isp, __func__);
1364 dev_dbg(&isp->client->dev, "host sessions not allowed\n");
1371 isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1373 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1374 #ifndef CONFIG_USB_OTG
1378 if (!otg || isp != the_transceiver)
1382 omap_writew(0, OTG_IRQ_EN);
1383 if (!isp->otg.default_a)
1384 enable_vbus_draw(isp, 0);
1385 usb_gadget_vbus_disconnect(isp->otg.gadget);
1386 isp->otg.gadget = NULL;
1391 #ifdef CONFIG_USB_OTG
1392 isp->otg.gadget = gadget;
1393 dev_dbg(&isp->client->dev, "registered gadget\n");
1394 /* gadget driver may be suspended until vbus_connect () */
1396 return isp1301_otg_enable(isp);
1399 #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1400 isp->otg.gadget = gadget;
1401 // FIXME update its refcount
1403 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1404 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS);
1406 omap_writel(l, OTG_CTRL);
1409 isp->otg.state = OTG_STATE_B_IDLE;
1411 if (machine_is_omap_h2() || machine_is_omap_h3())
1412 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1414 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1416 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1418 dev_info(&isp->client->dev, "B-Peripheral sessions ok\n");
1419 dump_regs(isp, __func__);
1421 /* If this has a Mini-AB connector, this mode is highly
1422 * nonstandard ... but can be handy for testing, so long
1423 * as you don't plug a Mini-A cable into the jack.
1425 if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD)
1431 dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n");
1437 /*-------------------------------------------------------------------------*/
1440 isp1301_set_power(struct otg_transceiver *dev, unsigned mA)
1442 if (!the_transceiver)
1444 if (dev->state == OTG_STATE_B_PERIPHERAL)
1445 enable_vbus_draw(the_transceiver, mA);
1450 isp1301_start_srp(struct otg_transceiver *dev)
1452 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1455 if (!dev || isp != the_transceiver
1456 || isp->otg.state != OTG_STATE_B_IDLE)
1459 otg_ctrl = omap_readl(OTG_CTRL);
1460 if (!(otg_ctrl & OTG_BSESSEND))
1463 otg_ctrl |= OTG_B_BUSREQ;
1464 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
1465 omap_writel(otg_ctrl, OTG_CTRL);
1466 isp->otg.state = OTG_STATE_B_SRP_INIT;
1468 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp),
1469 omap_readl(OTG_CTRL));
1470 #ifdef CONFIG_USB_OTG
1471 check_state(isp, __func__);
1477 isp1301_start_hnp(struct otg_transceiver *dev)
1479 #ifdef CONFIG_USB_OTG
1480 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1483 if (!dev || isp != the_transceiver)
1485 if (isp->otg.default_a && (isp->otg.host == NULL
1486 || !isp->otg.host->b_hnp_enable))
1488 if (!isp->otg.default_a && (isp->otg.gadget == NULL
1489 || !isp->otg.gadget->b_hnp_enable))
1492 /* We want hardware to manage most HNP protocol timings.
1493 * So do this part as early as possible...
1495 switch (isp->otg.state) {
1496 case OTG_STATE_B_HOST:
1497 isp->otg.state = OTG_STATE_B_PERIPHERAL;
1498 /* caller will suspend next */
1500 case OTG_STATE_A_HOST:
1502 /* autoconnect mode avoids irq latency bugs */
1503 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1506 /* caller must suspend then clear A_BUSREQ */
1507 usb_gadget_vbus_connect(isp->otg.gadget);
1508 l = omap_readl(OTG_CTRL);
1509 l |= OTG_A_SETB_HNPEN;
1510 omap_writel(l, OTG_CTRL);
1513 case OTG_STATE_A_PERIPHERAL:
1514 /* initiated by B-Host suspend */
1519 pr_debug("otg: HNP %s, %06x ...\n",
1520 state_name(isp), omap_readl(OTG_CTRL));
1521 check_state(isp, __func__);
1529 /*-------------------------------------------------------------------------*/
1532 isp1301_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
1535 struct isp1301 *isp;
1537 if (the_transceiver)
1540 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1544 INIT_WORK(&isp->work, isp1301_work);
1545 init_timer(&isp->timer);
1546 isp->timer.function = isp1301_timer;
1547 isp->timer.data = (unsigned long) isp;
1549 i2c_set_clientdata(i2c, isp);
1552 /* verify the chip (shouldn't be necesary) */
1553 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1554 if (status != I2C_VENDOR_ID_PHILIPS) {
1555 dev_dbg(&i2c->dev, "not philips id: %d\n", status);
1558 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1559 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1560 dev_dbg(&i2c->dev, "not isp1301, %d\n", 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 if (gpio_request(2, "isp1301") == 0)
1604 gpio_direction_input(2);
1605 isp->irq_type = IRQF_TRIGGER_FALLING;
1608 isp->irq_type |= IRQF_SAMPLE_RANDOM;
1609 status = request_irq(i2c->irq, isp1301_irq,
1610 isp->irq_type, DRIVER_NAME, isp);
1612 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n",
1617 isp->otg.dev = &i2c->dev;
1618 isp->otg.label = DRIVER_NAME;
1620 isp->otg.set_host = isp1301_set_host,
1621 isp->otg.set_peripheral = isp1301_set_peripheral,
1622 isp->otg.set_power = isp1301_set_power,
1623 isp->otg.start_srp = isp1301_start_srp,
1624 isp->otg.start_hnp = isp1301_start_hnp,
1626 enable_vbus_draw(isp, 0);
1628 the_transceiver = isp;
1630 #ifdef CONFIG_USB_OTG
1631 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
1632 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
1635 dump_regs(isp, __func__);
1638 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1639 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1642 status = otg_set_transceiver(&isp->otg);
1644 dev_err(&i2c->dev, "can't register transceiver, %d\n",
1654 static const struct i2c_device_id isp1301_id[] = {
1655 { "isp1301_omap", 0 },
1658 MODULE_DEVICE_TABLE(i2c, isp1301_id);
1660 static struct i2c_driver isp1301_driver = {
1662 .name = "isp1301_omap",
1664 .probe = isp1301_probe,
1665 .remove = __exit_p(isp1301_remove),
1666 .id_table = isp1301_id,
1669 /*-------------------------------------------------------------------------*/
1671 static int __init isp_init(void)
1673 return i2c_add_driver(&isp1301_driver);
1675 module_init(isp_init);
1677 static void __exit isp_exit(void)
1679 if (the_transceiver)
1680 otg_set_transceiver(NULL);
1681 i2c_del_driver(&isp1301_driver);
1683 module_exit(isp_exit);