1 // SPDX-License-Identifier: GPL-2.0+
3 * isp1301_omap - ISP 1301 USB transceiver, talking to OMAP OTG controller
5 * Copyright (C) 2004 Texas Instruments
6 * Copyright (C) 2004 David Brownell
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/slab.h>
13 #include <linux/interrupt.h>
14 #include <linux/platform_device.h>
15 #include <linux/gpio.h>
16 #include <linux/usb/ch9.h>
17 #include <linux/usb/gadget.h>
18 #include <linux/usb.h>
19 #include <linux/usb/otg.h>
20 #include <linux/i2c.h>
21 #include <linux/workqueue.h>
24 #include <asm/mach-types.h>
33 #define DRIVER_VERSION "24 August 2004"
34 #define DRIVER_NAME (isp1301_driver.driver.name)
36 MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver");
37 MODULE_LICENSE("GPL");
41 struct i2c_client
*client
;
42 void (*i2c_release
)(struct device
*dev
);
49 struct timer_list timer
;
51 /* use keventd context to change the state for us */
52 struct work_struct work
;
55 # define WORK_UPDATE_ISP 0 /* update ISP from OTG */
56 # define WORK_UPDATE_OTG 1 /* update OTG from ISP */
57 # define WORK_HOST_RESUME 4 /* resume host */
58 # define WORK_TIMER 6 /* timer fired */
59 # define WORK_STOP 7 /* don't resubmit */
63 /* bits in OTG_CTRL */
65 #define OTG_XCEIV_OUTPUTS \
66 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
67 #define OTG_XCEIV_INPUTS \
68 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
69 #define OTG_CTRL_BITS \
70 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
71 /* and OTG_PULLUP is sometimes written */
73 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
74 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
78 /*-------------------------------------------------------------------------*/
80 /* board-specific PM hooks */
82 #if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3)
84 #if IS_REACHABLE(CONFIG_TPS65010)
86 #include <linux/mfd/tps65010.h>
90 static inline int tps65010_set_vbus_draw(unsigned mA
)
92 pr_debug("tps65010: draw %d mA (STUB)\n", mA
);
98 static void enable_vbus_draw(struct isp1301
*isp
, unsigned mA
)
100 int status
= tps65010_set_vbus_draw(mA
);
102 pr_debug(" VBUS %d mA error %d\n", mA
, status
);
107 static void enable_vbus_draw(struct isp1301
*isp
, unsigned mA
)
109 /* H4 controls this by DIP switch S2.4; no soft control.
110 * ON means the charger is always enabled. Leave it OFF
111 * unless the OTG port is used only in B-peripheral mode.
117 static void enable_vbus_source(struct isp1301
*isp
)
119 /* this board won't supply more than 8mA vbus power.
120 * some boards can switch a 100ma "unit load" (or more).
125 /* products will deliver OTG messages with LEDs, GUI, etc */
126 static inline void notresponding(struct isp1301
*isp
)
128 printk(KERN_NOTICE
"OTG device not responding.\n");
132 /*-------------------------------------------------------------------------*/
134 static struct i2c_driver isp1301_driver
;
136 /* smbus apis are used for portability */
139 isp1301_get_u8(struct isp1301
*isp
, u8 reg
)
141 return i2c_smbus_read_byte_data(isp
->client
, reg
+ 0);
145 isp1301_get_u16(struct isp1301
*isp
, u8 reg
)
147 return i2c_smbus_read_word_data(isp
->client
, reg
);
151 isp1301_set_bits(struct isp1301
*isp
, u8 reg
, u8 bits
)
153 return i2c_smbus_write_byte_data(isp
->client
, reg
+ 0, bits
);
157 isp1301_clear_bits(struct isp1301
*isp
, u8 reg
, u8 bits
)
159 return i2c_smbus_write_byte_data(isp
->client
, reg
+ 1, bits
);
162 /*-------------------------------------------------------------------------*/
165 #define ISP1301_VENDOR_ID 0x00 /* u16 read */
166 #define ISP1301_PRODUCT_ID 0x02 /* u16 read */
167 #define ISP1301_BCD_DEVICE 0x14 /* u16 read */
169 #define I2C_VENDOR_ID_PHILIPS 0x04cc
170 #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
172 /* operational registers */
173 #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
174 # define MC1_SPEED (1 << 0)
175 # define MC1_SUSPEND (1 << 1)
176 # define MC1_DAT_SE0 (1 << 2)
177 # define MC1_TRANSPARENT (1 << 3)
178 # define MC1_BDIS_ACON_EN (1 << 4)
179 # define MC1_OE_INT_EN (1 << 5)
180 # define MC1_UART_EN (1 << 6)
181 # define MC1_MASK 0x7f
182 #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
183 # define MC2_GLOBAL_PWR_DN (1 << 0)
184 # define MC2_SPD_SUSP_CTRL (1 << 1)
185 # define MC2_BI_DI (1 << 2)
186 # define MC2_TRANSP_BDIR0 (1 << 3)
187 # define MC2_TRANSP_BDIR1 (1 << 4)
188 # define MC2_AUDIO_EN (1 << 5)
189 # define MC2_PSW_EN (1 << 6)
190 # define MC2_EN2V7 (1 << 7)
191 #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
192 # define OTG1_DP_PULLUP (1 << 0)
193 # define OTG1_DM_PULLUP (1 << 1)
194 # define OTG1_DP_PULLDOWN (1 << 2)
195 # define OTG1_DM_PULLDOWN (1 << 3)
196 # define OTG1_ID_PULLDOWN (1 << 4)
197 # define OTG1_VBUS_DRV (1 << 5)
198 # define OTG1_VBUS_DISCHRG (1 << 6)
199 # define OTG1_VBUS_CHRG (1 << 7)
200 #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
201 # define OTG_B_SESS_END (1 << 6)
202 # define OTG_B_SESS_VLD (1 << 7)
204 #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */
205 #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */
207 #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */
208 #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */
210 /* same bitfields in all interrupt registers */
211 # define INTR_VBUS_VLD (1 << 0)
212 # define INTR_SESS_VLD (1 << 1)
213 # define INTR_DP_HI (1 << 2)
214 # define INTR_ID_GND (1 << 3)
215 # define INTR_DM_HI (1 << 4)
216 # define INTR_ID_FLOAT (1 << 5)
217 # define INTR_BDIS_ACON (1 << 6)
218 # define INTR_CR_INT (1 << 7)
220 /*-------------------------------------------------------------------------*/
222 static inline const char *state_name(struct isp1301
*isp
)
224 return usb_otg_state_string(isp
->phy
.otg
->state
);
227 /*-------------------------------------------------------------------------*/
229 /* NOTE: some of this ISP1301 setup is specific to H2 boards;
230 * not everything is guarded by board-specific checks, or even using
231 * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI.
233 * ALSO: this currently doesn't use ISP1301 low-power modes
234 * while OTG is running.
237 static void power_down(struct isp1301
*isp
)
239 isp
->phy
.otg
->state
= OTG_STATE_UNDEFINED
;
241 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
242 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_SUSPEND
);
244 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
, OTG1_ID_PULLDOWN
);
245 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_DAT_SE0
);
248 static void __maybe_unused
power_up(struct isp1301
*isp
)
250 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
251 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_SUSPEND
);
253 /* do this only when cpu is driving transceiver,
254 * so host won't see a low speed device...
256 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_DAT_SE0
);
259 #define NO_HOST_SUSPEND
261 static int host_suspend(struct isp1301
*isp
)
263 #ifdef NO_HOST_SUSPEND
268 if (!isp
->phy
.otg
->host
)
271 /* Currently ASSUMES only the OTG port matters;
272 * other ports could be active...
274 dev
= isp
->phy
.otg
->host
->controller
;
275 return dev
->driver
->suspend(dev
, 3, 0);
279 static int host_resume(struct isp1301
*isp
)
281 #ifdef NO_HOST_SUSPEND
286 if (!isp
->phy
.otg
->host
)
289 dev
= isp
->phy
.otg
->host
->controller
;
290 return dev
->driver
->resume(dev
, 0);
294 static int gadget_suspend(struct isp1301
*isp
)
296 isp
->phy
.otg
->gadget
->b_hnp_enable
= 0;
297 isp
->phy
.otg
->gadget
->a_hnp_support
= 0;
298 isp
->phy
.otg
->gadget
->a_alt_hnp_support
= 0;
299 return usb_gadget_vbus_disconnect(isp
->phy
.otg
->gadget
);
302 /*-------------------------------------------------------------------------*/
304 #define TIMER_MINUTES 10
305 #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
307 /* Almost all our I2C messaging comes from a work queue's task context.
308 * NOTE: guaranteeing certain response times might mean we shouldn't
309 * share keventd's work queue; a realtime task might be safest.
311 static void isp1301_defer_work(struct isp1301
*isp
, int work
)
315 if (isp
&& !test_and_set_bit(work
, &isp
->todo
)) {
316 (void) get_device(&isp
->client
->dev
);
317 status
= schedule_work(&isp
->work
);
318 if (!status
&& !isp
->working
)
319 dev_vdbg(&isp
->client
->dev
,
320 "work item %d may be lost\n", work
);
324 /* called from irq handlers */
325 static void a_idle(struct isp1301
*isp
, const char *tag
)
329 if (isp
->phy
.otg
->state
== OTG_STATE_A_IDLE
)
332 isp
->phy
.otg
->default_a
= 1;
333 if (isp
->phy
.otg
->host
) {
334 isp
->phy
.otg
->host
->is_b_host
= 0;
337 if (isp
->phy
.otg
->gadget
) {
338 isp
->phy
.otg
->gadget
->is_a_peripheral
= 1;
341 isp
->phy
.otg
->state
= OTG_STATE_A_IDLE
;
342 l
= omap_readl(OTG_CTRL
) & OTG_XCEIV_OUTPUTS
;
343 omap_writel(l
, OTG_CTRL
);
344 isp
->last_otg_ctrl
= l
;
345 pr_debug(" --> %s/%s\n", state_name(isp
), tag
);
348 /* called from irq handlers */
349 static void b_idle(struct isp1301
*isp
, const char *tag
)
353 if (isp
->phy
.otg
->state
== OTG_STATE_B_IDLE
)
356 isp
->phy
.otg
->default_a
= 0;
357 if (isp
->phy
.otg
->host
) {
358 isp
->phy
.otg
->host
->is_b_host
= 1;
361 if (isp
->phy
.otg
->gadget
) {
362 isp
->phy
.otg
->gadget
->is_a_peripheral
= 0;
365 isp
->phy
.otg
->state
= OTG_STATE_B_IDLE
;
366 l
= omap_readl(OTG_CTRL
) & OTG_XCEIV_OUTPUTS
;
367 omap_writel(l
, OTG_CTRL
);
368 isp
->last_otg_ctrl
= l
;
369 pr_debug(" --> %s/%s\n", state_name(isp
), tag
);
373 dump_regs(struct isp1301
*isp
, const char *label
)
375 u8 ctrl
= isp1301_get_u8(isp
, ISP1301_OTG_CONTROL_1
);
376 u8 status
= isp1301_get_u8(isp
, ISP1301_OTG_STATUS
);
377 u8 src
= isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
);
379 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
380 omap_readl(OTG_CTRL
), label
, state_name(isp
),
382 /* mode control and irq enables don't change much */
385 /*-------------------------------------------------------------------------*/
387 #ifdef CONFIG_USB_OTG
390 * The OMAP OTG controller handles most of the OTG state transitions.
392 * We translate isp1301 outputs (mostly voltage comparator status) into
393 * OTG inputs; OTG outputs (mostly pullup/pulldown controls) and HNP state
394 * flags into isp1301 inputs ... and infer state transitions.
399 static void check_state(struct isp1301
*isp
, const char *tag
)
401 enum usb_otg_state state
= OTG_STATE_UNDEFINED
;
402 u8 fsm
= omap_readw(OTG_TEST
) & 0x0ff;
409 state
= OTG_STATE_B_IDLE
;
415 state
= OTG_STATE_B_PERIPHERAL
;
418 state
= OTG_STATE_B_SRP_INIT
;
421 /* extra dual-role default-b states */
427 state
= OTG_STATE_B_WAIT_ACON
;
430 state
= OTG_STATE_B_HOST
;
435 state
= OTG_STATE_A_IDLE
;
438 state
= OTG_STATE_A_WAIT_VFALL
;
441 state
= OTG_STATE_A_VBUS_ERR
;
447 state
= OTG_STATE_A_PERIPHERAL
;
450 state
= OTG_STATE_A_WAIT_VRISE
;
453 state
= OTG_STATE_A_WAIT_BCON
;
456 state
= OTG_STATE_A_HOST
;
459 state
= OTG_STATE_A_SUSPEND
;
464 if (isp
->phy
.otg
->state
== state
&& !extra
)
466 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag
,
467 usb_otg_state_string(state
), fsm
, state_name(isp
),
468 omap_readl(OTG_CTRL
));
473 static inline void check_state(struct isp1301
*isp
, const char *tag
) { }
477 /* outputs from ISP1301_INTERRUPT_SOURCE */
478 static void update_otg1(struct isp1301
*isp
, u8 int_src
)
482 otg_ctrl
= omap_readl(OTG_CTRL
) & OTG_CTRL_MASK
;
483 otg_ctrl
&= ~OTG_XCEIV_INPUTS
;
484 otg_ctrl
&= ~(OTG_ID
|OTG_ASESSVLD
|OTG_VBUSVLD
);
486 if (int_src
& INTR_SESS_VLD
)
487 otg_ctrl
|= OTG_ASESSVLD
;
488 else if (isp
->phy
.otg
->state
== OTG_STATE_A_WAIT_VFALL
) {
489 a_idle(isp
, "vfall");
490 otg_ctrl
&= ~OTG_CTRL_BITS
;
492 if (int_src
& INTR_VBUS_VLD
)
493 otg_ctrl
|= OTG_VBUSVLD
;
494 if (int_src
& INTR_ID_GND
) { /* default-A */
495 if (isp
->phy
.otg
->state
== OTG_STATE_B_IDLE
496 || isp
->phy
.otg
->state
497 == OTG_STATE_UNDEFINED
) {
501 } else { /* default-B */
503 if (isp
->phy
.otg
->state
== OTG_STATE_A_IDLE
504 || isp
->phy
.otg
->state
== OTG_STATE_UNDEFINED
) {
509 omap_writel(otg_ctrl
, OTG_CTRL
);
512 /* outputs from ISP1301_OTG_STATUS */
513 static void update_otg2(struct isp1301
*isp
, u8 otg_status
)
517 otg_ctrl
= omap_readl(OTG_CTRL
) & OTG_CTRL_MASK
;
518 otg_ctrl
&= ~OTG_XCEIV_INPUTS
;
519 otg_ctrl
&= ~(OTG_BSESSVLD
| OTG_BSESSEND
);
520 if (otg_status
& OTG_B_SESS_VLD
)
521 otg_ctrl
|= OTG_BSESSVLD
;
522 else if (otg_status
& OTG_B_SESS_END
)
523 otg_ctrl
|= OTG_BSESSEND
;
524 omap_writel(otg_ctrl
, OTG_CTRL
);
527 /* inputs going to ISP1301 */
528 static void otg_update_isp(struct isp1301
*isp
)
530 u32 otg_ctrl
, otg_change
;
531 u8 set
= OTG1_DM_PULLDOWN
, clr
= OTG1_DM_PULLUP
;
533 otg_ctrl
= omap_readl(OTG_CTRL
);
534 otg_change
= otg_ctrl
^ isp
->last_otg_ctrl
;
535 isp
->last_otg_ctrl
= otg_ctrl
;
536 otg_ctrl
= otg_ctrl
& OTG_XCEIV_INPUTS
;
538 switch (isp
->phy
.otg
->state
) {
539 case OTG_STATE_B_IDLE
:
540 case OTG_STATE_B_PERIPHERAL
:
541 case OTG_STATE_B_SRP_INIT
:
542 if (!(otg_ctrl
& OTG_PULLUP
)) {
543 // if (otg_ctrl & OTG_B_HNPEN) {
544 if (isp
->phy
.otg
->gadget
->b_hnp_enable
) {
545 isp
->phy
.otg
->state
= OTG_STATE_B_WAIT_ACON
;
546 pr_debug(" --> b_wait_acon\n");
551 set
|= OTG1_DP_PULLUP
;
552 clr
|= OTG1_DP_PULLDOWN
;
554 case OTG_STATE_A_SUSPEND
:
555 case OTG_STATE_A_PERIPHERAL
:
556 if (otg_ctrl
& OTG_PULLUP
)
559 // case OTG_STATE_B_WAIT_ACON:
562 set
|= OTG1_DP_PULLDOWN
;
563 clr
|= OTG1_DP_PULLUP
;
567 # define toggle(OTG,ISP) do { \
568 if (otg_ctrl & OTG) set |= ISP; \
572 if (!(isp
->phy
.otg
->host
))
573 otg_ctrl
&= ~OTG_DRV_VBUS
;
575 switch (isp
->phy
.otg
->state
) {
576 case OTG_STATE_A_SUSPEND
:
577 if (otg_ctrl
& OTG_DRV_VBUS
) {
578 set
|= OTG1_VBUS_DRV
;
581 /* HNP failed for some reason (A_AIDL_BDIS timeout) */
585 case OTG_STATE_A_VBUS_ERR
:
586 isp
->phy
.otg
->state
= OTG_STATE_A_WAIT_VFALL
;
587 pr_debug(" --> a_wait_vfall\n");
589 case OTG_STATE_A_WAIT_VFALL
:
590 /* FIXME usbcore thinks port power is still on ... */
591 clr
|= OTG1_VBUS_DRV
;
593 case OTG_STATE_A_IDLE
:
594 if (otg_ctrl
& OTG_DRV_VBUS
) {
595 isp
->phy
.otg
->state
= OTG_STATE_A_WAIT_VRISE
;
596 pr_debug(" --> a_wait_vrise\n");
600 toggle(OTG_DRV_VBUS
, OTG1_VBUS_DRV
);
603 toggle(OTG_PU_VBUS
, OTG1_VBUS_CHRG
);
604 toggle(OTG_PD_VBUS
, OTG1_VBUS_DISCHRG
);
608 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
, set
);
609 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
, clr
);
611 /* HNP switch to host or peripheral; and SRP */
612 if (otg_change
& OTG_PULLUP
) {
615 switch (isp
->phy
.otg
->state
) {
616 case OTG_STATE_B_IDLE
:
617 if (clr
& OTG1_DP_PULLUP
)
619 isp
->phy
.otg
->state
= OTG_STATE_B_PERIPHERAL
;
620 pr_debug(" --> b_peripheral\n");
622 case OTG_STATE_A_SUSPEND
:
623 if (clr
& OTG1_DP_PULLUP
)
625 isp
->phy
.otg
->state
= OTG_STATE_A_PERIPHERAL
;
626 pr_debug(" --> a_peripheral\n");
631 l
= omap_readl(OTG_CTRL
);
633 omap_writel(l
, OTG_CTRL
);
636 check_state(isp
, __func__
);
637 dump_regs(isp
, "otg->isp1301");
640 static irqreturn_t
omap_otg_irq(int irq
, void *_isp
)
642 u16 otg_irq
= omap_readw(OTG_IRQ_SRC
);
645 struct isp1301
*isp
= _isp
;
646 struct usb_otg
*otg
= isp
->phy
.otg
;
648 /* update ISP1301 transceiver from OTG controller */
649 if (otg_irq
& OPRT_CHG
) {
650 omap_writew(OPRT_CHG
, OTG_IRQ_SRC
);
651 isp1301_defer_work(isp
, WORK_UPDATE_ISP
);
654 /* SRP to become b_peripheral failed */
655 } else if (otg_irq
& B_SRP_TMROUT
) {
656 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL
));
659 /* gadget drivers that care should monitor all kinds of
660 * remote wakeup (SRP, normal) using their own timer
661 * to give "check cable and A-device" messages.
663 if (isp
->phy
.otg
->state
== OTG_STATE_B_SRP_INIT
)
664 b_idle(isp
, "srp_timeout");
666 omap_writew(B_SRP_TMROUT
, OTG_IRQ_SRC
);
669 /* HNP to become b_host failed */
670 } else if (otg_irq
& B_HNP_FAIL
) {
671 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
672 state_name(isp
), omap_readl(OTG_CTRL
));
675 otg_ctrl
= omap_readl(OTG_CTRL
);
676 otg_ctrl
|= OTG_BUSDROP
;
677 otg_ctrl
&= OTG_CTRL_MASK
& ~OTG_XCEIV_INPUTS
;
678 omap_writel(otg_ctrl
, OTG_CTRL
);
680 /* subset of b_peripheral()... */
681 isp
->phy
.otg
->state
= OTG_STATE_B_PERIPHERAL
;
682 pr_debug(" --> b_peripheral\n");
684 omap_writew(B_HNP_FAIL
, OTG_IRQ_SRC
);
687 /* detect SRP from B-device ... */
688 } else if (otg_irq
& A_SRP_DETECT
) {
689 pr_debug("otg: %s SRP_DETECT, %06x\n",
690 state_name(isp
), omap_readl(OTG_CTRL
));
692 isp1301_defer_work(isp
, WORK_UPDATE_OTG
);
693 switch (isp
->phy
.otg
->state
) {
694 case OTG_STATE_A_IDLE
:
697 isp1301_defer_work(isp
, WORK_HOST_RESUME
);
698 otg_ctrl
= omap_readl(OTG_CTRL
);
699 otg_ctrl
|= OTG_A_BUSREQ
;
700 otg_ctrl
&= ~(OTG_BUSDROP
|OTG_B_BUSREQ
)
703 omap_writel(otg_ctrl
, OTG_CTRL
);
709 omap_writew(A_SRP_DETECT
, OTG_IRQ_SRC
);
712 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
713 * we don't track them separately
715 } else if (otg_irq
& A_REQ_TMROUT
) {
716 otg_ctrl
= omap_readl(OTG_CTRL
);
717 pr_info("otg: BCON_TMOUT from %s, %06x\n",
718 state_name(isp
), otg_ctrl
);
721 otg_ctrl
|= OTG_BUSDROP
;
722 otg_ctrl
&= ~OTG_A_BUSREQ
& OTG_CTRL_MASK
& ~OTG_XCEIV_INPUTS
;
723 omap_writel(otg_ctrl
, OTG_CTRL
);
724 isp
->phy
.otg
->state
= OTG_STATE_A_WAIT_VFALL
;
726 omap_writew(A_REQ_TMROUT
, OTG_IRQ_SRC
);
729 /* A-supplied voltage fell too low; overcurrent */
730 } else if (otg_irq
& A_VBUS_ERR
) {
731 otg_ctrl
= omap_readl(OTG_CTRL
);
732 printk(KERN_ERR
"otg: %s, VBUS_ERR %04x ctrl %06x\n",
733 state_name(isp
), otg_irq
, otg_ctrl
);
735 otg_ctrl
|= OTG_BUSDROP
;
736 otg_ctrl
&= ~OTG_A_BUSREQ
& OTG_CTRL_MASK
& ~OTG_XCEIV_INPUTS
;
737 omap_writel(otg_ctrl
, OTG_CTRL
);
738 isp
->phy
.otg
->state
= OTG_STATE_A_VBUS_ERR
;
740 omap_writew(A_VBUS_ERR
, OTG_IRQ_SRC
);
743 /* switch driver; the transceiver code activates it,
744 * ungating the udc clock or resuming OHCI.
746 } else if (otg_irq
& DRIVER_SWITCH
) {
749 otg_ctrl
= omap_readl(OTG_CTRL
);
750 printk(KERN_NOTICE
"otg: %s, SWITCH to %s, ctrl %06x\n",
752 (otg_ctrl
& OTG_DRIVER_SEL
)
755 isp1301_defer_work(isp
, WORK_UPDATE_ISP
);
757 /* role is peripheral */
758 if (otg_ctrl
& OTG_DRIVER_SEL
) {
759 switch (isp
->phy
.otg
->state
) {
760 case OTG_STATE_A_IDLE
:
761 b_idle(isp
, __func__
);
766 isp1301_defer_work(isp
, WORK_UPDATE_ISP
);
770 if (!(otg_ctrl
& OTG_ID
)) {
771 otg_ctrl
&= OTG_CTRL_MASK
& ~OTG_XCEIV_INPUTS
;
772 omap_writel(otg_ctrl
| OTG_A_BUSREQ
, OTG_CTRL
);
776 switch (isp
->phy
.otg
->state
) {
777 case OTG_STATE_B_WAIT_ACON
:
778 isp
->phy
.otg
->state
= OTG_STATE_B_HOST
;
779 pr_debug(" --> b_host\n");
782 case OTG_STATE_A_WAIT_BCON
:
783 isp
->phy
.otg
->state
= OTG_STATE_A_HOST
;
784 pr_debug(" --> a_host\n");
786 case OTG_STATE_A_PERIPHERAL
:
787 isp
->phy
.otg
->state
= OTG_STATE_A_WAIT_BCON
;
788 pr_debug(" --> a_wait_bcon\n");
793 isp1301_defer_work(isp
, WORK_HOST_RESUME
);
797 omap_writew(DRIVER_SWITCH
, OTG_IRQ_SRC
);
801 usb_bus_start_enum(otg
->host
, otg
->host
->otg_port
);
804 check_state(isp
, __func__
);
808 static struct platform_device
*otg_dev
;
810 static int isp1301_otg_init(struct isp1301
*isp
)
817 dump_regs(isp
, __func__
);
818 /* some of these values are board-specific... */
819 l
= omap_readl(OTG_SYSCON_2
);
822 | SRP_GPDATA
/* 9msec Bdev D+ pulse */
823 | SRP_GPDVBUS
/* discharge after VBUS pulse */
824 // | (3 << 24) /* 2msec VBUS pulse */
826 | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
827 | SRP_DPW
/* detect 167+ns SRP pulses */
828 | SRP_DATA
| SRP_VBUS
/* accept both kinds of SRP pulse */
830 omap_writel(l
, OTG_SYSCON_2
);
832 update_otg1(isp
, isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
));
833 update_otg2(isp
, isp1301_get_u8(isp
, ISP1301_OTG_STATUS
));
835 check_state(isp
, __func__
);
836 pr_debug("otg: %s, %s %06x\n",
837 state_name(isp
), __func__
, omap_readl(OTG_CTRL
));
839 omap_writew(DRIVER_SWITCH
| OPRT_CHG
840 | B_SRP_TMROUT
| B_HNP_FAIL
841 | A_VBUS_ERR
| A_SRP_DETECT
| A_REQ_TMROUT
, OTG_IRQ_EN
);
843 l
= omap_readl(OTG_SYSCON_2
);
845 omap_writel(l
, OTG_SYSCON_2
);
850 static int otg_probe(struct platform_device
*dev
)
852 // struct omap_usb_config *config = dev->platform_data;
858 static int otg_remove(struct platform_device
*dev
)
864 static struct platform_driver omap_otg_driver
= {
866 .remove
= otg_remove
,
872 static int otg_bind(struct isp1301
*isp
)
879 status
= platform_driver_register(&omap_otg_driver
);
884 status
= request_irq(otg_dev
->resource
[1].start
, omap_otg_irq
,
885 0, DRIVER_NAME
, isp
);
890 platform_driver_unregister(&omap_otg_driver
);
894 static void otg_unbind(struct isp1301
*isp
)
898 free_irq(otg_dev
->resource
[1].start
, isp
);
903 /* OTG controller isn't clocked */
905 #endif /* CONFIG_USB_OTG */
907 /*-------------------------------------------------------------------------*/
909 static void b_peripheral(struct isp1301
*isp
)
913 l
= omap_readl(OTG_CTRL
) & OTG_XCEIV_OUTPUTS
;
914 omap_writel(l
, OTG_CTRL
);
916 usb_gadget_vbus_connect(isp
->phy
.otg
->gadget
);
918 #ifdef CONFIG_USB_OTG
919 enable_vbus_draw(isp
, 8);
922 enable_vbus_draw(isp
, 100);
923 /* UDC driver just set OTG_BSESSVLD */
924 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
, OTG1_DP_PULLUP
);
925 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
, OTG1_DP_PULLDOWN
);
926 isp
->phy
.otg
->state
= OTG_STATE_B_PERIPHERAL
;
927 pr_debug(" --> b_peripheral\n");
928 dump_regs(isp
, "2periph");
932 static void isp_update_otg(struct isp1301
*isp
, u8 stat
)
934 struct usb_otg
*otg
= isp
->phy
.otg
;
935 u8 isp_stat
, isp_bstat
;
936 enum usb_otg_state state
= isp
->phy
.otg
->state
;
938 if (stat
& INTR_BDIS_ACON
)
939 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp
));
941 /* start certain state transitions right away */
942 isp_stat
= isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
);
943 if (isp_stat
& INTR_ID_GND
) {
944 if (otg
->default_a
) {
946 case OTG_STATE_B_IDLE
:
949 case OTG_STATE_A_IDLE
:
950 enable_vbus_source(isp
);
952 case OTG_STATE_A_WAIT_VRISE
:
953 /* we skip over OTG_STATE_A_WAIT_BCON, since
954 * the HC will transition to A_HOST (or
955 * A_SUSPEND!) without our noticing except
958 if (isp_stat
& INTR_VBUS_VLD
)
959 isp
->phy
.otg
->state
= OTG_STATE_A_HOST
;
961 case OTG_STATE_A_WAIT_VFALL
:
962 if (!(isp_stat
& INTR_SESS_VLD
))
963 a_idle(isp
, "vfell");
966 if (!(isp_stat
& INTR_VBUS_VLD
))
967 isp
->phy
.otg
->state
= OTG_STATE_A_VBUS_ERR
;
970 isp_bstat
= isp1301_get_u8(isp
, ISP1301_OTG_STATUS
);
973 case OTG_STATE_B_PERIPHERAL
:
974 case OTG_STATE_B_HOST
:
975 case OTG_STATE_B_WAIT_ACON
:
976 usb_gadget_vbus_disconnect(otg
->gadget
);
981 if (state
!= OTG_STATE_A_IDLE
)
983 if (otg
->host
&& state
== OTG_STATE_A_IDLE
)
984 isp1301_defer_work(isp
, WORK_HOST_RESUME
);
990 /* if user unplugged mini-A end of cable,
991 * don't bypass A_WAIT_VFALL.
993 if (otg
->default_a
) {
996 isp
->phy
.otg
->state
= OTG_STATE_A_WAIT_VFALL
;
998 case OTG_STATE_A_WAIT_VFALL
:
999 state
= OTG_STATE_A_IDLE
;
1000 /* hub_wq may take a while to notice and
1001 * handle this disconnect, so don't go
1002 * to B_IDLE quite yet.
1005 case OTG_STATE_A_IDLE
:
1007 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_1
,
1009 isp
->phy
.otg
->state
= OTG_STATE_B_IDLE
;
1010 l
= omap_readl(OTG_CTRL
) & OTG_CTRL_MASK
;
1011 l
&= ~OTG_CTRL_BITS
;
1012 omap_writel(l
, OTG_CTRL
);
1014 case OTG_STATE_B_IDLE
:
1018 isp_bstat
= isp1301_get_u8(isp
, ISP1301_OTG_STATUS
);
1020 switch (isp
->phy
.otg
->state
) {
1021 case OTG_STATE_B_PERIPHERAL
:
1022 case OTG_STATE_B_WAIT_ACON
:
1023 case OTG_STATE_B_HOST
:
1024 if (likely(isp_bstat
& OTG_B_SESS_VLD
))
1026 enable_vbus_draw(isp
, 0);
1027 #ifndef CONFIG_USB_OTG
1028 /* UDC driver will clear OTG_BSESSVLD */
1029 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
,
1031 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
,
1033 dump_regs(isp
, __func__
);
1036 case OTG_STATE_B_SRP_INIT
:
1037 b_idle(isp
, __func__
);
1038 l
= omap_readl(OTG_CTRL
) & OTG_XCEIV_OUTPUTS
;
1039 omap_writel(l
, OTG_CTRL
);
1041 case OTG_STATE_B_IDLE
:
1042 if (otg
->gadget
&& (isp_bstat
& OTG_B_SESS_VLD
)) {
1043 #ifdef CONFIG_USB_OTG
1044 update_otg1(isp
, isp_stat
);
1045 update_otg2(isp
, isp_bstat
);
1048 } else if (!(isp_stat
& (INTR_VBUS_VLD
|INTR_SESS_VLD
)))
1049 isp_bstat
|= OTG_B_SESS_END
;
1051 case OTG_STATE_A_WAIT_VFALL
:
1054 pr_debug("otg: unsupported b-device %s\n",
1060 if (state
!= isp
->phy
.otg
->state
)
1061 pr_debug(" isp, %s -> %s\n",
1062 usb_otg_state_string(state
), state_name(isp
));
1064 #ifdef CONFIG_USB_OTG
1065 /* update the OTG controller state to match the isp1301; may
1066 * trigger OPRT_CHG irqs for changes going to the isp1301.
1068 update_otg1(isp
, isp_stat
);
1069 update_otg2(isp
, isp_bstat
);
1070 check_state(isp
, __func__
);
1073 dump_regs(isp
, "isp1301->otg");
1076 /*-------------------------------------------------------------------------*/
1078 static u8
isp1301_clear_latch(struct isp1301
*isp
)
1080 u8 latch
= isp1301_get_u8(isp
, ISP1301_INTERRUPT_LATCH
);
1081 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_LATCH
, latch
);
1086 isp1301_work(struct work_struct
*work
)
1088 struct isp1301
*isp
= container_of(work
, struct isp1301
, work
);
1091 /* implicit lock: we're the only task using this device */
1094 stop
= test_bit(WORK_STOP
, &isp
->todo
);
1096 #ifdef CONFIG_USB_OTG
1097 /* transfer state from otg engine to isp1301 */
1098 if (test_and_clear_bit(WORK_UPDATE_ISP
, &isp
->todo
)) {
1099 otg_update_isp(isp
);
1100 put_device(&isp
->client
->dev
);
1103 /* transfer state from isp1301 to otg engine */
1104 if (test_and_clear_bit(WORK_UPDATE_OTG
, &isp
->todo
)) {
1105 u8 stat
= isp1301_clear_latch(isp
);
1107 isp_update_otg(isp
, stat
);
1108 put_device(&isp
->client
->dev
);
1111 if (test_and_clear_bit(WORK_HOST_RESUME
, &isp
->todo
)) {
1115 * skip A_WAIT_VRISE; hc transitions invisibly
1116 * skip A_WAIT_BCON; same.
1118 switch (isp
->phy
.otg
->state
) {
1119 case OTG_STATE_A_WAIT_BCON
:
1120 case OTG_STATE_A_WAIT_VRISE
:
1121 isp
->phy
.otg
->state
= OTG_STATE_A_HOST
;
1122 pr_debug(" --> a_host\n");
1123 otg_ctrl
= omap_readl(OTG_CTRL
);
1124 otg_ctrl
|= OTG_A_BUSREQ
;
1125 otg_ctrl
&= ~(OTG_BUSDROP
|OTG_B_BUSREQ
)
1127 omap_writel(otg_ctrl
, OTG_CTRL
);
1129 case OTG_STATE_B_WAIT_ACON
:
1130 isp
->phy
.otg
->state
= OTG_STATE_B_HOST
;
1131 pr_debug(" --> b_host (acon)\n");
1133 case OTG_STATE_B_HOST
:
1134 case OTG_STATE_B_IDLE
:
1135 case OTG_STATE_A_IDLE
:
1138 pr_debug(" host resume in %s\n",
1143 put_device(&isp
->client
->dev
);
1146 if (test_and_clear_bit(WORK_TIMER
, &isp
->todo
)) {
1148 dump_regs(isp
, "timer");
1150 mod_timer(&isp
->timer
, jiffies
+ TIMER_JIFFIES
);
1152 put_device(&isp
->client
->dev
);
1156 dev_vdbg(&isp
->client
->dev
,
1157 "work done, todo = 0x%lx\n",
1160 dev_dbg(&isp
->client
->dev
, "stop\n");
1163 } while (isp
->todo
);
1167 static irqreturn_t
isp1301_irq(int irq
, void *isp
)
1169 isp1301_defer_work(isp
, WORK_UPDATE_OTG
);
1173 static void isp1301_timer(struct timer_list
*t
)
1175 struct isp1301
*isp
= from_timer(isp
, t
, timer
);
1177 isp1301_defer_work(isp
, WORK_TIMER
);
1180 /*-------------------------------------------------------------------------*/
1182 static void isp1301_release(struct device
*dev
)
1184 struct isp1301
*isp
;
1186 isp
= dev_get_drvdata(dev
);
1188 /* FIXME -- not with a "new style" driver, it doesn't!! */
1190 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1191 if (isp
->i2c_release
)
1192 isp
->i2c_release(dev
);
1193 kfree(isp
->phy
.otg
);
1197 static struct isp1301
*the_transceiver
;
1199 static int isp1301_remove(struct i2c_client
*i2c
)
1201 struct isp1301
*isp
;
1203 isp
= i2c_get_clientdata(i2c
);
1205 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_FALLING
, ~0);
1206 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_RISING
, ~0);
1207 free_irq(i2c
->irq
, isp
);
1208 #ifdef CONFIG_USB_OTG
1211 if (machine_is_omap_h2())
1214 set_bit(WORK_STOP
, &isp
->todo
);
1215 del_timer_sync(&isp
->timer
);
1216 flush_work(&isp
->work
);
1218 put_device(&i2c
->dev
);
1219 the_transceiver
= NULL
;
1224 /*-------------------------------------------------------------------------*/
1226 /* NOTE: three modes are possible here, only one of which
1227 * will be standards-conformant on any given system:
1229 * - OTG mode (dual-role), required if there's a Mini-AB connector
1230 * - HOST mode, for when there's one or more A (host) connectors
1231 * - DEVICE mode, for when there's a B/Mini-B (device) connector
1233 * As a rule, you won't have an isp1301 chip unless it's there to
1234 * support the OTG mode. Other modes help testing USB controllers
1235 * in isolation from (full) OTG support, or maybe so later board
1236 * revisions can help to support those feature.
1239 #ifdef CONFIG_USB_OTG
1241 static int isp1301_otg_enable(struct isp1301
*isp
)
1244 isp1301_otg_init(isp
);
1246 /* NOTE: since we don't change this, this provides
1247 * a few more interrupts than are strictly needed.
1249 isp1301_set_bits(isp
, ISP1301_INTERRUPT_RISING
,
1250 INTR_VBUS_VLD
| INTR_SESS_VLD
| INTR_ID_GND
);
1251 isp1301_set_bits(isp
, ISP1301_INTERRUPT_FALLING
,
1252 INTR_VBUS_VLD
| INTR_SESS_VLD
| INTR_ID_GND
);
1254 dev_info(&isp
->client
->dev
, "ready for dual-role USB ...\n");
1261 /* add or disable the host device+driver */
1263 isp1301_set_host(struct usb_otg
*otg
, struct usb_bus
*host
)
1265 struct isp1301
*isp
= container_of(otg
->usb_phy
, struct isp1301
, phy
);
1267 if (isp
!= the_transceiver
)
1271 omap_writew(0, OTG_IRQ_EN
);
1277 #ifdef CONFIG_USB_OTG
1279 dev_dbg(&isp
->client
->dev
, "registered host\n");
1282 return isp1301_otg_enable(isp
);
1285 #elif !IS_ENABLED(CONFIG_USB_OMAP)
1286 // FIXME update its refcount
1291 if (machine_is_omap_h2())
1292 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_DAT_SE0
);
1294 dev_info(&isp
->client
->dev
, "A-Host sessions ok\n");
1295 isp1301_set_bits(isp
, ISP1301_INTERRUPT_RISING
,
1297 isp1301_set_bits(isp
, ISP1301_INTERRUPT_FALLING
,
1300 /* If this has a Mini-AB connector, this mode is highly
1301 * nonstandard ... but can be handy for testing, especially with
1302 * the Mini-A end of an OTG cable. (Or something nonstandard
1303 * like MiniB-to-StandardB, maybe built with a gender mender.)
1305 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
, OTG1_VBUS_DRV
);
1307 dump_regs(isp
, __func__
);
1312 dev_dbg(&isp
->client
->dev
, "host sessions not allowed\n");
1319 isp1301_set_peripheral(struct usb_otg
*otg
, struct usb_gadget
*gadget
)
1321 struct isp1301
*isp
= container_of(otg
->usb_phy
, struct isp1301
, phy
);
1323 if (isp
!= the_transceiver
)
1327 omap_writew(0, OTG_IRQ_EN
);
1328 if (!otg
->default_a
)
1329 enable_vbus_draw(isp
, 0);
1330 usb_gadget_vbus_disconnect(otg
->gadget
);
1336 #ifdef CONFIG_USB_OTG
1337 otg
->gadget
= gadget
;
1338 dev_dbg(&isp
->client
->dev
, "registered gadget\n");
1339 /* gadget driver may be suspended until vbus_connect () */
1341 return isp1301_otg_enable(isp
);
1344 #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1345 otg
->gadget
= gadget
;
1346 // FIXME update its refcount
1351 l
= omap_readl(OTG_CTRL
) & OTG_CTRL_MASK
;
1352 l
&= ~(OTG_XCEIV_OUTPUTS
|OTG_CTRL_BITS
);
1354 omap_writel(l
, OTG_CTRL
);
1358 isp
->phy
.otg
->state
= OTG_STATE_B_IDLE
;
1360 if (machine_is_omap_h2() || machine_is_omap_h3())
1361 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_DAT_SE0
);
1363 isp1301_set_bits(isp
, ISP1301_INTERRUPT_RISING
,
1365 isp1301_set_bits(isp
, ISP1301_INTERRUPT_FALLING
,
1367 dev_info(&isp
->client
->dev
, "B-Peripheral sessions ok\n");
1368 dump_regs(isp
, __func__
);
1370 /* If this has a Mini-AB connector, this mode is highly
1371 * nonstandard ... but can be handy for testing, so long
1372 * as you don't plug a Mini-A cable into the jack.
1374 if (isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
) & INTR_VBUS_VLD
)
1380 dev_dbg(&isp
->client
->dev
, "peripheral sessions not allowed\n");
1386 /*-------------------------------------------------------------------------*/
1389 isp1301_set_power(struct usb_phy
*dev
, unsigned mA
)
1391 if (!the_transceiver
)
1393 if (dev
->otg
->state
== OTG_STATE_B_PERIPHERAL
)
1394 enable_vbus_draw(the_transceiver
, mA
);
1399 isp1301_start_srp(struct usb_otg
*otg
)
1401 struct isp1301
*isp
= container_of(otg
->usb_phy
, struct isp1301
, phy
);
1404 if (isp
!= the_transceiver
|| isp
->phy
.otg
->state
!= OTG_STATE_B_IDLE
)
1407 otg_ctrl
= omap_readl(OTG_CTRL
);
1408 if (!(otg_ctrl
& OTG_BSESSEND
))
1411 otg_ctrl
|= OTG_B_BUSREQ
;
1412 otg_ctrl
&= ~OTG_A_BUSREQ
& OTG_CTRL_MASK
;
1413 omap_writel(otg_ctrl
, OTG_CTRL
);
1414 isp
->phy
.otg
->state
= OTG_STATE_B_SRP_INIT
;
1416 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp
),
1417 omap_readl(OTG_CTRL
));
1418 #ifdef CONFIG_USB_OTG
1419 check_state(isp
, __func__
);
1425 isp1301_start_hnp(struct usb_otg
*otg
)
1427 #ifdef CONFIG_USB_OTG
1428 struct isp1301
*isp
= container_of(otg
->usb_phy
, struct isp1301
, phy
);
1431 if (isp
!= the_transceiver
)
1433 if (otg
->default_a
&& (otg
->host
== NULL
|| !otg
->host
->b_hnp_enable
))
1435 if (!otg
->default_a
&& (otg
->gadget
== NULL
1436 || !otg
->gadget
->b_hnp_enable
))
1439 /* We want hardware to manage most HNP protocol timings.
1440 * So do this part as early as possible...
1442 switch (isp
->phy
.otg
->state
) {
1443 case OTG_STATE_B_HOST
:
1444 isp
->phy
.otg
->state
= OTG_STATE_B_PERIPHERAL
;
1445 /* caller will suspend next */
1447 case OTG_STATE_A_HOST
:
1449 /* autoconnect mode avoids irq latency bugs */
1450 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
,
1453 /* caller must suspend then clear A_BUSREQ */
1454 usb_gadget_vbus_connect(otg
->gadget
);
1455 l
= omap_readl(OTG_CTRL
);
1456 l
|= OTG_A_SETB_HNPEN
;
1457 omap_writel(l
, OTG_CTRL
);
1460 case OTG_STATE_A_PERIPHERAL
:
1461 /* initiated by B-Host suspend */
1466 pr_debug("otg: HNP %s, %06x ...\n",
1467 state_name(isp
), omap_readl(OTG_CTRL
));
1468 check_state(isp
, __func__
);
1476 /*-------------------------------------------------------------------------*/
1479 isp1301_probe(struct i2c_client
*i2c
, const struct i2c_device_id
*id
)
1482 struct isp1301
*isp
;
1484 if (the_transceiver
)
1487 isp
= kzalloc(sizeof *isp
, GFP_KERNEL
);
1491 isp
->phy
.otg
= kzalloc(sizeof *isp
->phy
.otg
, GFP_KERNEL
);
1492 if (!isp
->phy
.otg
) {
1497 INIT_WORK(&isp
->work
, isp1301_work
);
1498 timer_setup(&isp
->timer
, isp1301_timer
, 0);
1500 i2c_set_clientdata(i2c
, isp
);
1503 /* verify the chip (shouldn't be necessary) */
1504 status
= isp1301_get_u16(isp
, ISP1301_VENDOR_ID
);
1505 if (status
!= I2C_VENDOR_ID_PHILIPS
) {
1506 dev_dbg(&i2c
->dev
, "not philips id: %d\n", status
);
1509 status
= isp1301_get_u16(isp
, ISP1301_PRODUCT_ID
);
1510 if (status
!= I2C_PRODUCT_ID_PHILIPS_1301
) {
1511 dev_dbg(&i2c
->dev
, "not isp1301, %d\n", status
);
1514 isp
->i2c_release
= i2c
->dev
.release
;
1515 i2c
->dev
.release
= isp1301_release
;
1517 /* initial development used chiprev 2.00 */
1518 status
= i2c_smbus_read_word_data(i2c
, ISP1301_BCD_DEVICE
);
1519 dev_info(&i2c
->dev
, "chiprev %x.%02x, driver " DRIVER_VERSION
"\n",
1520 status
>> 8, status
& 0xff);
1522 /* make like power-on reset */
1523 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_MASK
);
1525 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_2
, MC2_BI_DI
);
1526 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_2
, ~MC2_BI_DI
);
1528 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
,
1529 OTG1_DM_PULLDOWN
| OTG1_DP_PULLDOWN
);
1530 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
,
1531 ~(OTG1_DM_PULLDOWN
| OTG1_DP_PULLDOWN
));
1533 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_LATCH
, ~0);
1534 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_FALLING
, ~0);
1535 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_RISING
, ~0);
1537 #ifdef CONFIG_USB_OTG
1538 status
= otg_bind(isp
);
1540 dev_dbg(&i2c
->dev
, "can't bind OTG\n");
1545 if (machine_is_omap_h2()) {
1546 /* full speed signaling by default */
1547 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
,
1549 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_2
,
1552 /* IRQ wired at M14 */
1553 omap_cfg_reg(M14_1510_GPIO2
);
1554 if (gpio_request(2, "isp1301") == 0)
1555 gpio_direction_input(2);
1556 isp
->irq_type
= IRQF_TRIGGER_FALLING
;
1559 status
= request_irq(i2c
->irq
, isp1301_irq
,
1560 isp
->irq_type
, DRIVER_NAME
, isp
);
1562 dev_dbg(&i2c
->dev
, "can't get IRQ %d, err %d\n",
1567 isp
->phy
.dev
= &i2c
->dev
;
1568 isp
->phy
.label
= DRIVER_NAME
;
1569 isp
->phy
.set_power
= isp1301_set_power
,
1571 isp
->phy
.otg
->usb_phy
= &isp
->phy
;
1572 isp
->phy
.otg
->set_host
= isp1301_set_host
,
1573 isp
->phy
.otg
->set_peripheral
= isp1301_set_peripheral
,
1574 isp
->phy
.otg
->start_srp
= isp1301_start_srp
,
1575 isp
->phy
.otg
->start_hnp
= isp1301_start_hnp
,
1577 enable_vbus_draw(isp
, 0);
1579 the_transceiver
= isp
;
1581 #ifdef CONFIG_USB_OTG
1582 update_otg1(isp
, isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
));
1583 update_otg2(isp
, isp1301_get_u8(isp
, ISP1301_OTG_STATUS
));
1586 dump_regs(isp
, __func__
);
1589 mod_timer(&isp
->timer
, jiffies
+ TIMER_JIFFIES
);
1590 dev_dbg(&i2c
->dev
, "scheduled timer, %d min\n", TIMER_MINUTES
);
1593 status
= usb_add_phy(&isp
->phy
, USB_PHY_TYPE_USB2
);
1595 dev_err(&i2c
->dev
, "can't register transceiver, %d\n",
1601 kfree(isp
->phy
.otg
);
1606 static const struct i2c_device_id isp1301_id
[] = {
1607 { "isp1301_omap", 0 },
1610 MODULE_DEVICE_TABLE(i2c
, isp1301_id
);
1612 static struct i2c_driver isp1301_driver
= {
1614 .name
= "isp1301_omap",
1616 .probe
= isp1301_probe
,
1617 .remove
= isp1301_remove
,
1618 .id_table
= isp1301_id
,
1621 /*-------------------------------------------------------------------------*/
1623 static int __init
isp_init(void)
1625 return i2c_add_driver(&isp1301_driver
);
1627 subsys_initcall(isp_init
);
1629 static void __exit
isp_exit(void)
1631 if (the_transceiver
)
1632 usb_remove_phy(&the_transceiver
->phy
);
1633 i2c_del_driver(&isp1301_driver
);
1635 module_exit(isp_exit
);