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/config.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/slab.h>
29 #include <linux/interrupt.h>
30 #include <linux/device.h>
31 #include <linux/usb_ch9.h>
32 #include <linux/usb_gadget.h>
33 #include <linux/usb.h>
34 #include <linux/usb_otg.h>
35 #include <linux/i2c.h>
36 #include <linux/workqueue.h>
39 #include <asm/arch/usb.h>
47 #define DRIVER_VERSION "24 August 2004"
48 #define DRIVER_NAME (isp1301_driver.name)
50 MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver");
51 MODULE_LICENSE("GPL");
54 struct otg_transceiver otg;
55 struct i2c_client client;
56 void (*i2c_release)(struct device *dev);
63 struct timer_list timer;
65 /* use keventd context to change the state for us */
66 struct work_struct work;
69 # define WORK_UPDATE_ISP 0 /* update ISP from OTG */
70 # define WORK_UPDATE_OTG 1 /* update OTG from ISP */
71 # define WORK_HOST_RESUME 4 /* resume host */
72 # define WORK_TIMER 6 /* timer fired */
73 # define WORK_STOP 7 /* don't resubmit */
77 /* bits in OTG_CTRL_REG */
79 #define OTG_XCEIV_OUTPUTS \
80 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
81 #define OTG_XCEIV_INPUTS \
82 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
83 #define OTG_CTRL_BITS \
84 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
85 /* and OTG_PULLUP is sometimes written */
87 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
88 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
92 /*-------------------------------------------------------------------------*/
94 #ifdef CONFIG_MACH_OMAP_H2
96 /* board-specific PM hooks */
98 #include <asm/arch/gpio.h>
99 #include <asm/arch/mux.h>
100 #include <asm/mach-types.h>
103 #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
105 #include <asm/arch/tps65010.h>
109 static inline int tps65010_set_vbus_draw(unsigned mA)
111 pr_debug("tps65010: draw %d mA (STUB)\n", mA);
117 static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
119 int status = tps65010_set_vbus_draw(mA);
121 pr_debug(" VBUS %d mA error %d\n", mA, status);
124 static void enable_vbus_source(struct isp1301 *isp)
126 /* this board won't supply more than 8mA vbus power.
127 * some boards can switch a 100ma "unit load" (or more).
132 /* products will deliver OTG messages with LEDs, GUI, etc */
133 static inline void notresponding(struct isp1301 *isp)
135 printk(KERN_NOTICE "OTG device not responding.\n");
141 /*-------------------------------------------------------------------------*/
143 /* only two addresses possible */
144 #define ISP_BASE 0x2c
145 static unsigned short normal_i2c[] = {
146 ISP_BASE, ISP_BASE + 1,
148 static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
152 static struct i2c_driver isp1301_driver;
154 /* smbus apis are used for portability */
157 isp1301_get_u8(struct isp1301 *isp, u8 reg)
159 return i2c_smbus_read_byte_data(&isp->client, reg + 0);
163 isp1301_get_u16(struct isp1301 *isp, u8 reg)
165 return i2c_smbus_read_word_data(&isp->client, reg);
169 isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
171 return i2c_smbus_write_byte_data(&isp->client, reg + 0, bits);
175 isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
177 return i2c_smbus_write_byte_data(&isp->client, reg + 1, bits);
180 /*-------------------------------------------------------------------------*/
183 #define ISP1301_VENDOR_ID 0x00 /* u16 read */
184 #define ISP1301_PRODUCT_ID 0x02 /* u16 read */
185 #define ISP1301_BCD_DEVICE 0x14 /* u16 read */
187 #define I2C_VENDOR_ID_PHILIPS 0x04cc
188 #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
190 /* operational registers */
191 #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
192 # define MC1_SPEED_REG (1 << 0)
193 # define MC1_SUSPEND_REG (1 << 1)
194 # define MC1_DAT_SE0 (1 << 2)
195 # define MC1_TRANSPARENT (1 << 3)
196 # define MC1_BDIS_ACON_EN (1 << 4)
197 # define MC1_OE_INT_EN (1 << 5)
198 # define MC1_UART_EN (1 << 6)
199 # define MC1_MASK 0x7f
200 #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
201 # define MC2_GLOBAL_PWR_DN (1 << 0)
202 # define MC2_SPD_SUSP_CTRL (1 << 1)
203 # define MC2_BI_DI (1 << 2)
204 # define MC2_TRANSP_BDIR0 (1 << 3)
205 # define MC2_TRANSP_BDIR1 (1 << 4)
206 # define MC2_AUDIO_EN (1 << 5)
207 # define MC2_PSW_EN (1 << 6)
208 # define MC2_EN2V7 (1 << 7)
209 #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
210 # define OTG1_DP_PULLUP (1 << 0)
211 # define OTG1_DM_PULLUP (1 << 1)
212 # define OTG1_DP_PULLDOWN (1 << 2)
213 # define OTG1_DM_PULLDOWN (1 << 3)
214 # define OTG1_ID_PULLDOWN (1 << 4)
215 # define OTG1_VBUS_DRV (1 << 5)
216 # define OTG1_VBUS_DISCHRG (1 << 6)
217 # define OTG1_VBUS_CHRG (1 << 7)
218 #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
219 # define OTG_B_SESS_END (1 << 6)
220 # define OTG_B_SESS_VLD (1 << 7)
222 #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */
223 #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */
225 #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */
226 #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */
228 /* same bitfields in all interrupt registers */
229 # define INTR_VBUS_VLD (1 << 0)
230 # define INTR_SESS_VLD (1 << 1)
231 # define INTR_DP_HI (1 << 2)
232 # define INTR_ID_GND (1 << 3)
233 # define INTR_DM_HI (1 << 4)
234 # define INTR_ID_FLOAT (1 << 5)
235 # define INTR_BDIS_ACON (1 << 6)
236 # define INTR_CR_INT (1 << 7)
238 /*-------------------------------------------------------------------------*/
240 static const char *state_string(enum usb_otg_state state)
243 case OTG_STATE_A_IDLE: return "a_idle";
244 case OTG_STATE_A_WAIT_VRISE: return "a_wait_vrise";
245 case OTG_STATE_A_WAIT_BCON: return "a_wait_bcon";
246 case OTG_STATE_A_HOST: return "a_host";
247 case OTG_STATE_A_SUSPEND: return "a_suspend";
248 case OTG_STATE_A_PERIPHERAL: return "a_peripheral";
249 case OTG_STATE_A_WAIT_VFALL: return "a_wait_vfall";
250 case OTG_STATE_A_VBUS_ERR: return "a_vbus_err";
251 case OTG_STATE_B_IDLE: return "b_idle";
252 case OTG_STATE_B_SRP_INIT: return "b_srp_init";
253 case OTG_STATE_B_PERIPHERAL: return "b_peripheral";
254 case OTG_STATE_B_WAIT_ACON: return "b_wait_acon";
255 case OTG_STATE_B_HOST: return "b_host";
256 default: return "UNDEFINED";
260 static inline const char *state_name(struct isp1301 *isp)
262 return state_string(isp->otg.state);
266 #define dev_vdbg dev_dbg
268 #define dev_vdbg(dev, fmt, arg...) do{}while(0)
271 /*-------------------------------------------------------------------------*/
273 /* NOTE: some of this ISP1301 setup is specific to H2 boards;
274 * not everything is guarded by board-specific checks, or even using
275 * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI.
277 * ALSO: this currently doesn't use ISP1301 low-power modes
278 * while OTG is running.
281 static void power_down(struct isp1301 *isp)
283 isp->otg.state = OTG_STATE_UNDEFINED;
285 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
286 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND_REG);
288 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN);
289 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
292 static void power_up(struct isp1301 *isp)
294 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
295 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND_REG);
297 /* do this only when cpu is driving transceiver,
298 * so host won't see a low speed device...
300 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
303 #define NO_HOST_SUSPEND
305 static int host_suspend(struct isp1301 *isp)
307 #ifdef NO_HOST_SUSPEND
315 /* Currently ASSUMES only the OTG port matters;
316 * other ports could be active...
318 dev = isp->otg.host->controller;
319 return dev->driver->suspend(dev, 3, 0);
323 static int host_resume(struct isp1301 *isp)
325 #ifdef NO_HOST_SUSPEND
333 dev = isp->otg.host->controller;
334 return dev->driver->resume(dev, 0);
338 static int gadget_suspend(struct isp1301 *isp)
340 isp->otg.gadget->b_hnp_enable = 0;
341 isp->otg.gadget->a_hnp_support = 0;
342 isp->otg.gadget->a_alt_hnp_support = 0;
343 return usb_gadget_vbus_disconnect(isp->otg.gadget);
346 /*-------------------------------------------------------------------------*/
348 #define TIMER_MINUTES 10
349 #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
351 /* Almost all our I2C messaging comes from a work queue's task context.
352 * NOTE: guaranteeing certain response times might mean we shouldn't
353 * share keventd's work queue; a realtime task might be safest.
356 isp1301_defer_work(struct isp1301 *isp, int work)
360 if (isp && !test_and_set_bit(work, &isp->todo)) {
361 (void) get_device(&isp->client.dev);
362 status = schedule_work(&isp->work);
363 if (!status && !isp->working)
364 dev_vdbg(&isp->client.dev,
365 "work item %d may be lost\n", work);
369 /* called from irq handlers */
370 static void a_idle(struct isp1301 *isp, const char *tag)
372 if (isp->otg.state == OTG_STATE_A_IDLE)
375 isp->otg.default_a = 1;
377 isp->otg.host->is_b_host = 0;
380 if (isp->otg.gadget) {
381 isp->otg.gadget->is_a_peripheral = 1;
384 isp->otg.state = OTG_STATE_A_IDLE;
385 isp->last_otg_ctrl = OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
386 pr_debug(" --> %s/%s\n", state_name(isp), tag);
389 /* called from irq handlers */
390 static void b_idle(struct isp1301 *isp, const char *tag)
392 if (isp->otg.state == OTG_STATE_B_IDLE)
395 isp->otg.default_a = 0;
397 isp->otg.host->is_b_host = 1;
400 if (isp->otg.gadget) {
401 isp->otg.gadget->is_a_peripheral = 0;
404 isp->otg.state = OTG_STATE_B_IDLE;
405 isp->last_otg_ctrl = OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
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 OTG_CTRL_REG, 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 = OTG_TEST_REG & 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), OTG_CTRL_REG);
511 static inline void check_state(struct isp1301 *isp, const char *tag) { }
515 /* outputs from ISP1301_INTERRUPT_SOURCE */
516 static void update_otg1(struct isp1301 *isp, u8 int_src)
520 otg_ctrl = OTG_CTRL_REG
523 & ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
524 if (int_src & INTR_SESS_VLD)
525 otg_ctrl |= OTG_ASESSVLD;
526 else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) {
527 a_idle(isp, "vfall");
528 otg_ctrl &= ~OTG_CTRL_BITS;
530 if (int_src & INTR_VBUS_VLD)
531 otg_ctrl |= OTG_VBUSVLD;
532 if (int_src & INTR_ID_GND) { /* default-A */
533 if (isp->otg.state == OTG_STATE_B_IDLE
534 || isp->otg.state == OTG_STATE_UNDEFINED) {
538 } else { /* default-B */
540 if (isp->otg.state == OTG_STATE_A_IDLE
541 || isp->otg.state == OTG_STATE_UNDEFINED) {
546 OTG_CTRL_REG = otg_ctrl;
549 /* outputs from ISP1301_OTG_STATUS */
550 static void update_otg2(struct isp1301 *isp, u8 otg_status)
554 otg_ctrl = OTG_CTRL_REG
557 & ~(OTG_BSESSVLD|OTG_BSESSEND);
558 if (otg_status & OTG_B_SESS_VLD)
559 otg_ctrl |= OTG_BSESSVLD;
560 else if (otg_status & OTG_B_SESS_END)
561 otg_ctrl |= OTG_BSESSEND;
562 OTG_CTRL_REG = otg_ctrl;
565 /* inputs going to ISP1301 */
566 static void otg_update_isp(struct isp1301 *isp)
568 u32 otg_ctrl, otg_change;
569 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
571 otg_ctrl = OTG_CTRL_REG;
572 otg_change = otg_ctrl ^ isp->last_otg_ctrl;
573 isp->last_otg_ctrl = otg_ctrl;
574 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
576 switch (isp->otg.state) {
577 case OTG_STATE_B_IDLE:
578 case OTG_STATE_B_PERIPHERAL:
579 case OTG_STATE_B_SRP_INIT:
580 if (!(otg_ctrl & OTG_PULLUP)) {
581 // if (otg_ctrl & OTG_B_HNPEN) {
582 if (isp->otg.gadget->b_hnp_enable) {
583 isp->otg.state = OTG_STATE_B_WAIT_ACON;
584 pr_debug(" --> b_wait_acon\n");
589 set |= OTG1_DP_PULLUP;
590 clr |= OTG1_DP_PULLDOWN;
592 case OTG_STATE_A_SUSPEND:
593 case OTG_STATE_A_PERIPHERAL:
594 if (otg_ctrl & OTG_PULLUP)
597 // case OTG_STATE_B_WAIT_ACON:
600 set |= OTG1_DP_PULLDOWN;
601 clr |= OTG1_DP_PULLUP;
605 # define toggle(OTG,ISP) do { \
606 if (otg_ctrl & OTG) set |= ISP; \
610 if (!(isp->otg.host))
611 otg_ctrl &= ~OTG_DRV_VBUS;
613 switch (isp->otg.state) {
614 case OTG_STATE_A_SUSPEND:
615 if (otg_ctrl & OTG_DRV_VBUS) {
616 set |= OTG1_VBUS_DRV;
619 /* HNP failed for some reason (A_AIDL_BDIS timeout) */
623 case OTG_STATE_A_VBUS_ERR:
624 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
625 pr_debug(" --> a_wait_vfall\n");
627 case OTG_STATE_A_WAIT_VFALL:
628 /* FIXME usbcore thinks port power is still on ... */
629 clr |= OTG1_VBUS_DRV;
631 case OTG_STATE_A_IDLE:
632 if (otg_ctrl & OTG_DRV_VBUS) {
633 isp->otg.state = OTG_STATE_A_WAIT_VRISE;
634 pr_debug(" --> a_wait_vrise\n");
638 toggle(OTG_DRV_VBUS, OTG1_VBUS_DRV);
641 toggle(OTG_PU_VBUS, OTG1_VBUS_CHRG);
642 toggle(OTG_PD_VBUS, OTG1_VBUS_DISCHRG);
646 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, set);
647 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, clr);
649 /* HNP switch to host or peripheral; and SRP */
650 if (otg_change & OTG_PULLUP) {
651 switch (isp->otg.state) {
652 case OTG_STATE_B_IDLE:
653 if (clr & OTG1_DP_PULLUP)
655 isp->otg.state = OTG_STATE_B_PERIPHERAL;
656 pr_debug(" --> b_peripheral\n");
658 case OTG_STATE_A_SUSPEND:
659 if (clr & OTG1_DP_PULLUP)
661 isp->otg.state = OTG_STATE_A_PERIPHERAL;
662 pr_debug(" --> a_peripheral\n");
667 OTG_CTRL_REG |= OTG_PULLUP;
670 check_state(isp, __FUNCTION__);
671 dump_regs(isp, "otg->isp1301");
674 static irqreturn_t omap_otg_irq(int irq, void *_isp, struct pt_regs *regs)
676 u16 otg_irq = OTG_IRQ_SRC_REG;
679 struct isp1301 *isp = _isp;
681 /* update ISP1301 transciever from OTG controller */
682 if (otg_irq & OPRT_CHG) {
683 OTG_IRQ_SRC_REG = OPRT_CHG;
684 isp1301_defer_work(isp, WORK_UPDATE_ISP);
687 /* SRP to become b_peripheral failed */
688 } else if (otg_irq & B_SRP_TMROUT) {
689 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", OTG_CTRL_REG);
692 /* gadget drivers that care should monitor all kinds of
693 * remote wakeup (SRP, normal) using their own timer
694 * to give "check cable and A-device" messages.
696 if (isp->otg.state == OTG_STATE_B_SRP_INIT)
697 b_idle(isp, "srp_timeout");
699 OTG_IRQ_SRC_REG = B_SRP_TMROUT;
702 /* HNP to become b_host failed */
703 } else if (otg_irq & B_HNP_FAIL) {
704 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
705 state_name(isp), OTG_CTRL_REG);
708 otg_ctrl = OTG_CTRL_REG;
709 otg_ctrl |= OTG_BUSDROP;
710 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
711 OTG_CTRL_REG = otg_ctrl;
713 /* subset of b_peripheral()... */
714 isp->otg.state = OTG_STATE_B_PERIPHERAL;
715 pr_debug(" --> b_peripheral\n");
717 OTG_IRQ_SRC_REG = B_HNP_FAIL;
720 /* detect SRP from B-device ... */
721 } else if (otg_irq & A_SRP_DETECT) {
722 pr_debug("otg: %s SRP_DETECT, %06x\n",
723 state_name(isp), OTG_CTRL_REG);
725 isp1301_defer_work(isp, WORK_UPDATE_OTG);
726 switch (isp->otg.state) {
727 case OTG_STATE_A_IDLE:
730 isp1301_defer_work(isp, WORK_HOST_RESUME);
731 otg_ctrl = OTG_CTRL_REG;
732 otg_ctrl |= OTG_A_BUSREQ;
733 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
736 OTG_CTRL_REG = otg_ctrl;
742 OTG_IRQ_SRC_REG = A_SRP_DETECT;
745 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
746 * we don't track them separately
748 } else if (otg_irq & A_REQ_TMROUT) {
749 otg_ctrl = OTG_CTRL_REG;
750 pr_info("otg: BCON_TMOUT from %s, %06x\n",
751 state_name(isp), otg_ctrl);
754 otg_ctrl |= OTG_BUSDROP;
755 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
756 OTG_CTRL_REG = otg_ctrl;
757 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
759 OTG_IRQ_SRC_REG = A_REQ_TMROUT;
762 /* A-supplied voltage fell too low; overcurrent */
763 } else if (otg_irq & A_VBUS_ERR) {
764 otg_ctrl = OTG_CTRL_REG;
765 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
766 state_name(isp), otg_irq, otg_ctrl);
768 otg_ctrl |= OTG_BUSDROP;
769 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
770 OTG_CTRL_REG = otg_ctrl;
771 isp->otg.state = OTG_STATE_A_VBUS_ERR;
773 OTG_IRQ_SRC_REG = A_VBUS_ERR;
776 /* switch driver; the transciever code activates it,
777 * ungating the udc clock or resuming OHCI.
779 } else if (otg_irq & DRIVER_SWITCH) {
782 otg_ctrl = OTG_CTRL_REG;
783 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
785 (otg_ctrl & OTG_DRIVER_SEL)
788 isp1301_defer_work(isp, WORK_UPDATE_ISP);
790 /* role is peripheral */
791 if (otg_ctrl & OTG_DRIVER_SEL) {
792 switch (isp->otg.state) {
793 case OTG_STATE_A_IDLE:
794 b_idle(isp, __FUNCTION__);
799 isp1301_defer_work(isp, WORK_UPDATE_ISP);
803 if (!(otg_ctrl & OTG_ID)) {
804 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
805 OTG_CTRL_REG = otg_ctrl | OTG_A_BUSREQ;
809 switch (isp->otg.state) {
810 case OTG_STATE_B_WAIT_ACON:
811 isp->otg.state = OTG_STATE_B_HOST;
812 pr_debug(" --> b_host\n");
815 case OTG_STATE_A_WAIT_BCON:
816 isp->otg.state = OTG_STATE_A_HOST;
817 pr_debug(" --> a_host\n");
819 case OTG_STATE_A_PERIPHERAL:
820 isp->otg.state = OTG_STATE_A_WAIT_BCON;
821 pr_debug(" --> a_wait_bcon\n");
826 isp1301_defer_work(isp, WORK_HOST_RESUME);
830 OTG_IRQ_SRC_REG = DRIVER_SWITCH;
834 usb_bus_start_enum(isp->otg.host,
835 isp->otg.host->otg_port);
838 check_state(isp, __FUNCTION__);
842 static struct platform_device *otg_dev;
844 static int otg_init(struct isp1301 *isp)
849 dump_regs(isp, __FUNCTION__);
850 /* some of these values are board-specific... */
851 OTG_SYSCON_2_REG |= OTG_EN
853 | SRP_GPDATA /* 9msec Bdev D+ pulse */
854 | SRP_GPDVBUS /* discharge after VBUS pulse */
855 // | (3 << 24) /* 2msec VBUS pulse */
857 | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
858 | SRP_DPW /* detect 167+ns SRP pulses */
859 | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */
862 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
863 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
865 check_state(isp, __FUNCTION__);
866 pr_debug("otg: %s, %s %06x\n",
867 state_name(isp), __FUNCTION__, OTG_CTRL_REG);
869 OTG_IRQ_EN_REG = DRIVER_SWITCH | OPRT_CHG
870 | B_SRP_TMROUT | B_HNP_FAIL
871 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT;
872 OTG_SYSCON_2_REG |= OTG_EN;
877 static int otg_probe(struct device *dev)
879 // struct omap_usb_config *config = dev->platform_data;
881 otg_dev = to_platform_device(dev);
885 static int otg_remove(struct device *dev)
891 struct device_driver omap_otg_driver = {
893 .bus = &platform_bus_type,
895 .remove = otg_remove,
898 static int otg_bind(struct isp1301 *isp)
905 status = driver_register(&omap_otg_driver);
910 status = request_irq(otg_dev->resource[1].start, omap_otg_irq,
911 SA_INTERRUPT, DRIVER_NAME, isp);
916 driver_unregister(&omap_otg_driver);
920 static void otg_unbind(struct isp1301 *isp)
924 free_irq(otg_dev->resource[1].start, isp);
929 /* OTG controller isn't clocked */
931 #endif /* CONFIG_USB_OTG */
933 /*-------------------------------------------------------------------------*/
935 static void b_peripheral(struct isp1301 *isp)
937 enable_vbus_draw(isp, 8);
938 OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
939 usb_gadget_vbus_connect(isp->otg.gadget);
941 #ifdef CONFIG_USB_OTG
944 /* UDC driver just set OTG_BSESSVLD */
945 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLUP);
946 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_DP_PULLDOWN);
947 isp->otg.state = OTG_STATE_B_PERIPHERAL;
948 pr_debug(" --> b_peripheral\n");
949 dump_regs(isp, "2periph");
953 static int isp_update_otg(struct isp1301 *isp, u8 stat)
955 u8 isp_stat, isp_bstat;
956 enum usb_otg_state state = isp->otg.state;
958 if (stat & INTR_BDIS_ACON)
959 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp));
961 /* start certain state transitions right away */
962 isp_stat = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
963 if (isp_stat & INTR_ID_GND) {
964 if (isp->otg.default_a) {
966 case OTG_STATE_B_IDLE:
969 case OTG_STATE_A_IDLE:
970 enable_vbus_source(isp);
972 case OTG_STATE_A_WAIT_VRISE:
973 /* we skip over OTG_STATE_A_WAIT_BCON, since
974 * the HC will transition to A_HOST (or
975 * A_SUSPEND!) without our noticing except
978 if (isp_stat & INTR_VBUS_VLD)
979 isp->otg.state = OTG_STATE_A_HOST;
981 case OTG_STATE_A_WAIT_VFALL:
982 if (!(isp_stat & INTR_SESS_VLD))
983 a_idle(isp, "vfell");
986 if (!(isp_stat & INTR_VBUS_VLD))
987 isp->otg.state = OTG_STATE_A_VBUS_ERR;
990 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
993 case OTG_STATE_B_PERIPHERAL:
994 case OTG_STATE_B_HOST:
995 case OTG_STATE_B_WAIT_ACON:
996 usb_gadget_vbus_disconnect(isp->otg.gadget);
1001 if (state != OTG_STATE_A_IDLE)
1003 if (isp->otg.host && state == OTG_STATE_A_IDLE)
1004 isp1301_defer_work(isp, WORK_HOST_RESUME);
1008 /* if user unplugged mini-A end of cable,
1009 * don't bypass A_WAIT_VFALL.
1011 if (isp->otg.default_a) {
1014 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
1016 case OTG_STATE_A_WAIT_VFALL:
1017 state = OTG_STATE_A_IDLE;
1018 /* khubd may take a while to notice and
1019 * handle this disconnect, so don't go
1020 * to B_IDLE quite yet.
1023 case OTG_STATE_A_IDLE:
1025 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
1027 isp->otg.state = OTG_STATE_B_IDLE;
1028 OTG_CTRL_REG &= OTG_CTRL_REG & OTG_CTRL_MASK
1031 case OTG_STATE_B_IDLE:
1035 isp_bstat = isp1301_get_u8(isp, ISP1301_OTG_STATUS);
1037 switch (isp->otg.state) {
1038 case OTG_STATE_B_PERIPHERAL:
1039 case OTG_STATE_B_WAIT_ACON:
1040 case OTG_STATE_B_HOST:
1041 if (likely(isp_bstat & OTG_B_SESS_VLD))
1043 enable_vbus_draw(isp, 0);
1044 #ifndef CONFIG_USB_OTG
1045 /* UDC driver will clear OTG_BSESSVLD */
1046 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1048 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1050 dump_regs(isp, __FUNCTION__);
1053 case OTG_STATE_B_SRP_INIT:
1054 b_idle(isp, __FUNCTION__);
1055 OTG_CTRL_REG &= OTG_CTRL_REG & OTG_XCEIV_OUTPUTS;
1057 case OTG_STATE_B_IDLE:
1058 if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) {
1059 #ifdef CONFIG_USB_OTG
1060 update_otg1(isp, isp_stat);
1061 update_otg2(isp, isp_bstat);
1064 } else if (!(isp_stat & (INTR_VBUS_VLD|INTR_SESS_VLD)))
1065 isp_bstat |= OTG_B_SESS_END;
1067 case OTG_STATE_A_WAIT_VFALL:
1070 pr_debug("otg: unsupported b-device %s\n",
1076 if (state != isp->otg.state)
1077 pr_debug(" isp, %s -> %s\n",
1078 state_string(state), state_name(isp));
1080 #ifdef CONFIG_USB_OTG
1081 /* update the OTG controller state to match the isp1301; may
1082 * trigger OPRT_CHG irqs for changes going to the isp1301.
1084 update_otg1(isp, isp_stat);
1085 update_otg2(isp, isp_bstat);
1086 check_state(isp, __FUNCTION__);
1089 dump_regs(isp, "isp1301->otg");
1092 /*-------------------------------------------------------------------------*/
1094 static u8 isp1301_clear_latch(struct isp1301 *isp)
1096 u8 latch = isp1301_get_u8(isp, ISP1301_INTERRUPT_LATCH);
1097 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, latch);
1102 isp1301_work(void *data)
1104 struct isp1301 *isp = data;
1107 /* implicit lock: we're the only task using this device */
1110 stop = test_bit(WORK_STOP, &isp->todo);
1112 #ifdef CONFIG_USB_OTG
1113 /* transfer state from otg engine to isp1301 */
1114 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1115 otg_update_isp(isp);
1116 put_device(&isp->client.dev);
1119 /* transfer state from isp1301 to otg engine */
1120 if (test_and_clear_bit(WORK_UPDATE_OTG, &isp->todo)) {
1121 u8 stat = isp1301_clear_latch(isp);
1123 isp_update_otg(isp, stat);
1124 put_device(&isp->client.dev);
1127 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
1131 * skip A_WAIT_VRISE; hc transitions invisibly
1132 * skip A_WAIT_BCON; same.
1134 switch (isp->otg.state) {
1135 case OTG_STATE_A_WAIT_BCON:
1136 case OTG_STATE_A_WAIT_VRISE:
1137 isp->otg.state = OTG_STATE_A_HOST;
1138 pr_debug(" --> a_host\n");
1139 otg_ctrl = OTG_CTRL_REG;
1140 otg_ctrl |= OTG_A_BUSREQ;
1141 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
1143 OTG_CTRL_REG = otg_ctrl;
1145 case OTG_STATE_B_WAIT_ACON:
1146 isp->otg.state = OTG_STATE_B_HOST;
1147 pr_debug(" --> b_host (acon)\n");
1149 case OTG_STATE_B_HOST:
1150 case OTG_STATE_B_IDLE:
1151 case OTG_STATE_A_IDLE:
1154 pr_debug(" host resume in %s\n",
1159 put_device(&isp->client.dev);
1162 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
1164 dump_regs(isp, "timer");
1166 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1168 put_device(&isp->client.dev);
1172 dev_vdbg(&isp->client.dev,
1173 "work done, todo = 0x%lx\n",
1176 dev_dbg(&isp->client.dev, "stop\n");
1179 } while (isp->todo);
1183 static irqreturn_t isp1301_irq(int irq, void *isp, struct pt_regs *regs)
1185 isp1301_defer_work(isp, WORK_UPDATE_OTG);
1189 static void isp1301_timer(unsigned long _isp)
1191 isp1301_defer_work((void *)_isp, WORK_TIMER);
1194 /*-------------------------------------------------------------------------*/
1196 static void isp1301_release(struct device *dev)
1198 struct isp1301 *isp;
1200 isp = container_of(dev, struct isp1301, client.dev);
1202 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1203 if (isp->i2c_release)
1204 isp->i2c_release(dev);
1208 static struct isp1301 *the_transceiver;
1210 static int isp1301_detach_client(struct i2c_client *i2c)
1212 struct isp1301 *isp;
1214 isp = container_of(i2c, struct isp1301, client);
1216 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1217 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1218 free_irq(isp->irq, isp);
1219 #ifdef CONFIG_USB_OTG
1222 if (machine_is_omap_h2())
1225 isp->timer.data = 0;
1226 set_bit(WORK_STOP, &isp->todo);
1227 del_timer_sync(&isp->timer);
1228 flush_scheduled_work();
1230 put_device(&i2c->dev);
1231 the_transceiver = 0;
1233 return i2c_detach_client(i2c);
1236 /*-------------------------------------------------------------------------*/
1238 /* NOTE: three modes are possible here, only one of which
1239 * will be standards-conformant on any given system:
1241 * - OTG mode (dual-role), required if there's a Mini-AB connector
1242 * - HOST mode, for when there's one or more A (host) connectors
1243 * - DEVICE mode, for when there's a B/Mini-B (device) connector
1245 * As a rule, you won't have an isp1301 chip unless it's there to
1246 * support the OTG mode. Other modes help testing USB controllers
1247 * in isolation from (full) OTG support, or maybe so later board
1248 * revisions can help to support those feature.
1251 #ifdef CONFIG_USB_OTG
1253 static int isp1301_otg_enable(struct isp1301 *isp)
1258 /* NOTE: since we don't change this, this provides
1259 * a few more interrupts than are strictly needed.
1261 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1262 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1263 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1264 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1266 dev_info(&isp->client.dev, "ready for dual-role USB ...\n");
1273 /* add or disable the host device+driver */
1275 isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1277 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1279 if (!otg || isp != the_transceiver)
1289 #ifdef CONFIG_USB_OTG
1290 isp->otg.host = host;
1291 dev_dbg(&isp->client.dev, "registered host\n");
1293 if (isp->otg.gadget)
1294 return isp1301_otg_enable(isp);
1297 #elif !defined(CONFIG_USB_GADGET_OMAP)
1298 // FIXME update its refcount
1299 isp->otg.host = host;
1303 if (machine_is_omap_h2())
1304 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1306 dev_info(&isp->client.dev, "A-Host sessions ok\n");
1307 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1309 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1312 /* If this has a Mini-AB connector, this mode is highly
1313 * nonstandard ... but can be handy for testing, especially with
1314 * the Mini-A end of an OTG cable. (Or something nonstandard
1315 * like MiniB-to-StandardB, maybe built with a gender mender.)
1317 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_VBUS_DRV);
1319 dump_regs(isp, __FUNCTION__);
1324 dev_dbg(&isp->client.dev, "host sessions not allowed\n");
1331 isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1333 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1335 if (!otg || isp != the_transceiver)
1340 if (!isp->otg.default_a)
1341 enable_vbus_draw(isp, 0);
1342 usb_gadget_vbus_disconnect(isp->otg.gadget);
1343 isp->otg.gadget = 0;
1348 #ifdef CONFIG_USB_OTG
1349 isp->otg.gadget = gadget;
1350 dev_dbg(&isp->client.dev, "registered gadget\n");
1351 /* gadget driver may be suspended until vbus_connect () */
1353 return isp1301_otg_enable(isp);
1356 #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1357 isp->otg.gadget = gadget;
1358 // FIXME update its refcount
1360 OTG_CTRL_REG = (OTG_CTRL_REG & OTG_CTRL_MASK
1361 & ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS))
1364 isp->otg.state = OTG_STATE_B_IDLE;
1366 if (machine_is_omap_h2())
1367 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1369 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1371 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1373 dev_info(&isp->client.dev, "B-Peripheral sessions ok\n");
1374 dump_regs(isp, __FUNCTION__);
1376 /* If this has a Mini-AB connector, this mode is highly
1377 * nonstandard ... but can be handy for testing, so long
1378 * as you don't plug a Mini-A cable into the jack.
1380 if (isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE) & INTR_VBUS_VLD)
1386 dev_dbg(&isp->client.dev, "peripheral sessions not allowed\n");
1392 /*-------------------------------------------------------------------------*/
1395 isp1301_set_power(struct otg_transceiver *dev, unsigned mA)
1397 if (!the_transceiver)
1399 if (dev->state == OTG_STATE_B_PERIPHERAL)
1400 enable_vbus_draw(the_transceiver, mA);
1405 isp1301_start_srp(struct otg_transceiver *dev)
1407 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1410 if (!dev || isp != the_transceiver
1411 || isp->otg.state != OTG_STATE_B_IDLE)
1414 otg_ctrl = OTG_CTRL_REG;
1415 if (!(otg_ctrl & OTG_BSESSEND))
1418 otg_ctrl |= OTG_B_BUSREQ;
1419 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
1420 OTG_CTRL_REG = otg_ctrl;
1421 isp->otg.state = OTG_STATE_B_SRP_INIT;
1423 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), OTG_CTRL_REG);
1424 #ifdef CONFIG_USB_OTG
1425 check_state(isp, __FUNCTION__);
1431 isp1301_start_hnp(struct otg_transceiver *dev)
1433 #ifdef CONFIG_USB_OTG
1434 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1436 if (!dev || isp != the_transceiver)
1438 if (isp->otg.default_a && (isp->otg.host == NULL
1439 || !isp->otg.host->b_hnp_enable))
1441 if (!isp->otg.default_a && (isp->otg.gadget == NULL
1442 || !isp->otg.gadget->b_hnp_enable))
1445 /* We want hardware to manage most HNP protocol timings.
1446 * So do this part as early as possible...
1448 switch (isp->otg.state) {
1449 case OTG_STATE_B_HOST:
1450 isp->otg.state = OTG_STATE_B_PERIPHERAL;
1451 /* caller will suspend next */
1453 case OTG_STATE_A_HOST:
1455 /* autoconnect mode avoids irq latency bugs */
1456 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1459 /* caller must suspend then clear A_BUSREQ */
1460 usb_gadget_vbus_connect(isp->otg.gadget);
1461 OTG_CTRL_REG |= OTG_A_SETB_HNPEN;
1464 case OTG_STATE_A_PERIPHERAL:
1465 /* initiated by B-Host suspend */
1470 pr_debug("otg: HNP %s, %06x ...\n",
1471 state_name(isp), OTG_CTRL_REG);
1472 check_state(isp, __FUNCTION__);
1480 /*-------------------------------------------------------------------------*/
1482 /* no error returns, they'd just make bus scanning stop */
1483 static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1486 struct isp1301 *isp;
1487 struct i2c_client *i2c;
1489 if (the_transceiver)
1492 isp = kmalloc(sizeof *isp, GFP_KERNEL);
1496 memset(isp, 0, sizeof *isp);
1498 INIT_WORK(&isp->work, isp1301_work, isp);
1499 init_timer(&isp->timer);
1500 isp->timer.function = isp1301_timer;
1501 isp->timer.data = (unsigned long) isp;
1504 isp->client.addr = address;
1505 i2c_set_clientdata(&isp->client, isp);
1506 isp->client.adapter = bus;
1507 isp->client.id = 1301;
1508 isp->client.driver = &isp1301_driver;
1509 strlcpy(isp->client.name, DRIVER_NAME, I2C_NAME_SIZE);
1512 /* if this is a true probe, verify the chip ... */
1514 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1515 if (status != I2C_VENDOR_ID_PHILIPS) {
1516 dev_dbg(&bus->dev, "addr %d not philips id: %d\n",
1520 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1521 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1522 dev_dbg(&bus->dev, "%d not isp1301, %d\n",
1528 status = i2c_attach_client(i2c);
1530 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n",
1531 DRIVER_NAME, address, status);
1536 isp->i2c_release = i2c->dev.release;
1537 i2c->dev.release = isp1301_release;
1539 /* initial development used chiprev 2.00 */
1540 status = i2c_smbus_read_word_data(i2c, ISP1301_BCD_DEVICE);
1541 dev_info(&i2c->dev, "chiprev %x.%02x, driver " DRIVER_VERSION "\n",
1542 status >> 8, status & 0xff);
1544 /* make like power-on reset */
1545 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_MASK);
1547 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_BI_DI);
1548 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, ~MC2_BI_DI);
1550 isp1301_set_bits(isp, ISP1301_OTG_CONTROL_1,
1551 OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN);
1552 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1,
1553 ~(OTG1_DM_PULLDOWN | OTG1_DP_PULLDOWN));
1555 isp1301_clear_bits(isp, ISP1301_INTERRUPT_LATCH, ~0);
1556 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1557 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1559 #ifdef CONFIG_USB_OTG
1560 status = otg_bind(isp);
1562 dev_dbg(&i2c->dev, "can't bind OTG\n");
1567 if (machine_is_omap_h2()) {
1568 /* full speed signaling by default */
1569 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1,
1571 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2,
1574 /* IRQ wired at M14 */
1575 omap_cfg_reg(M14_1510_GPIO2);
1576 isp->irq = OMAP_GPIO_IRQ(2);
1577 omap_request_gpio(2);
1578 omap_set_gpio_direction(2, 1);
1579 omap_set_gpio_edge_ctrl(2, OMAP_GPIO_FALLING_EDGE);
1582 status = request_irq(isp->irq, isp1301_irq,
1583 SA_SAMPLE_RANDOM, DRIVER_NAME, isp);
1585 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n",
1587 #ifdef CONFIG_USB_OTG
1590 i2c_detach_client(i2c);
1594 isp->otg.dev = &isp->client.dev;
1595 isp->otg.label = DRIVER_NAME;
1597 isp->otg.set_host = isp1301_set_host,
1598 isp->otg.set_peripheral = isp1301_set_peripheral,
1599 isp->otg.set_power = isp1301_set_power,
1600 isp->otg.start_srp = isp1301_start_srp,
1601 isp->otg.start_hnp = isp1301_start_hnp,
1603 enable_vbus_draw(isp, 0);
1605 the_transceiver = isp;
1607 #ifdef CONFIG_USB_OTG
1608 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
1609 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
1612 dump_regs(isp, __FUNCTION__);
1615 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1616 dev_dbg(&i2c->dev, "scheduled timer, %d min\n", TIMER_MINUTES);
1619 status = otg_set_transceiver(&isp->otg);
1621 dev_err(&i2c->dev, "can't register transceiver, %d\n",
1627 static int isp1301_scan_bus(struct i2c_adapter *bus)
1629 if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA
1630 | I2C_FUNC_SMBUS_READ_WORD_DATA))
1632 return i2c_probe(bus, &addr_data, isp1301_probe);
1635 static struct i2c_driver isp1301_driver = {
1636 .owner = THIS_MODULE,
1637 .name = "isp1301_omap",
1638 .id = 1301, /* FIXME "official", i2c-ids.h */
1639 .class = I2C_CLASS_HWMON,
1640 .flags = I2C_DF_NOTIFY,
1641 .attach_adapter = isp1301_scan_bus,
1642 .detach_client = isp1301_detach_client,
1645 /*-------------------------------------------------------------------------*/
1647 static int __init isp_init(void)
1649 return i2c_add_driver(&isp1301_driver);
1651 module_init(isp_init);
1653 static void __exit isp_exit(void)
1655 if (the_transceiver)
1656 otg_set_transceiver(0);
1657 i2c_del_driver(&isp1301_driver);
1659 module_exit(isp_exit);