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>
37 #include <asm/mach-types.h>
46 #define DRIVER_VERSION "24 August 2004"
47 #define DRIVER_NAME (isp1301_driver.driver.name)
49 MODULE_DESCRIPTION("ISP1301 USB OTG Transceiver Driver");
50 MODULE_LICENSE("GPL");
54 struct i2c_client
*client
;
55 void (*i2c_release
)(struct device
*dev
);
62 struct timer_list timer
;
64 /* use keventd context to change the state for us */
65 struct work_struct work
;
68 # define WORK_UPDATE_ISP 0 /* update ISP from OTG */
69 # define WORK_UPDATE_OTG 1 /* update OTG from ISP */
70 # define WORK_HOST_RESUME 4 /* resume host */
71 # define WORK_TIMER 6 /* timer fired */
72 # define WORK_STOP 7 /* don't resubmit */
76 /* bits in OTG_CTRL */
78 #define OTG_XCEIV_OUTPUTS \
79 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
80 #define OTG_XCEIV_INPUTS \
81 (OTG_PULLDOWN|OTG_PULLUP|OTG_DRV_VBUS|OTG_PD_VBUS|OTG_PU_VBUS|OTG_PU_ID)
82 #define OTG_CTRL_BITS \
83 (OTG_A_BUSREQ|OTG_A_SETB_HNPEN|OTG_B_BUSREQ|OTG_B_HNPEN|OTG_BUSDROP)
84 /* and OTG_PULLUP is sometimes written */
86 #define OTG_CTRL_MASK (OTG_DRIVER_SEL| \
87 OTG_XCEIV_OUTPUTS|OTG_XCEIV_INPUTS| \
91 /*-------------------------------------------------------------------------*/
93 /* board-specific PM hooks */
95 #if defined(CONFIG_MACH_OMAP_H2) || defined(CONFIG_MACH_OMAP_H3)
97 #if defined(CONFIG_TPS65010) || defined(CONFIG_TPS65010_MODULE)
99 #include <linux/i2c/tps65010.h>
103 static inline int tps65010_set_vbus_draw(unsigned mA
)
105 pr_debug("tps65010: draw %d mA (STUB)\n", mA
);
111 static void enable_vbus_draw(struct isp1301
*isp
, unsigned mA
)
113 int status
= tps65010_set_vbus_draw(mA
);
115 pr_debug(" VBUS %d mA error %d\n", mA
, status
);
120 static void enable_vbus_draw(struct isp1301
*isp
, unsigned mA
)
122 /* H4 controls this by DIP switch S2.4; no soft control.
123 * ON means the charger is always enabled. Leave it OFF
124 * unless the OTG port is used only in B-peripheral mode.
130 static void enable_vbus_source(struct isp1301
*isp
)
132 /* this board won't supply more than 8mA vbus power.
133 * some boards can switch a 100ma "unit load" (or more).
138 /* products will deliver OTG messages with LEDs, GUI, etc */
139 static inline void notresponding(struct isp1301
*isp
)
141 printk(KERN_NOTICE
"OTG device not responding.\n");
145 /*-------------------------------------------------------------------------*/
147 static struct i2c_driver isp1301_driver
;
149 /* smbus apis are used for portability */
152 isp1301_get_u8(struct isp1301
*isp
, u8 reg
)
154 return i2c_smbus_read_byte_data(isp
->client
, reg
+ 0);
158 isp1301_get_u16(struct isp1301
*isp
, u8 reg
)
160 return i2c_smbus_read_word_data(isp
->client
, reg
);
164 isp1301_set_bits(struct isp1301
*isp
, u8 reg
, u8 bits
)
166 return i2c_smbus_write_byte_data(isp
->client
, reg
+ 0, bits
);
170 isp1301_clear_bits(struct isp1301
*isp
, u8 reg
, u8 bits
)
172 return i2c_smbus_write_byte_data(isp
->client
, reg
+ 1, bits
);
175 /*-------------------------------------------------------------------------*/
178 #define ISP1301_VENDOR_ID 0x00 /* u16 read */
179 #define ISP1301_PRODUCT_ID 0x02 /* u16 read */
180 #define ISP1301_BCD_DEVICE 0x14 /* u16 read */
182 #define I2C_VENDOR_ID_PHILIPS 0x04cc
183 #define I2C_PRODUCT_ID_PHILIPS_1301 0x1301
185 /* operational registers */
186 #define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
187 # define MC1_SPEED (1 << 0)
188 # define MC1_SUSPEND (1 << 1)
189 # define MC1_DAT_SE0 (1 << 2)
190 # define MC1_TRANSPARENT (1 << 3)
191 # define MC1_BDIS_ACON_EN (1 << 4)
192 # define MC1_OE_INT_EN (1 << 5)
193 # define MC1_UART_EN (1 << 6)
194 # define MC1_MASK 0x7f
195 #define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
196 # define MC2_GLOBAL_PWR_DN (1 << 0)
197 # define MC2_SPD_SUSP_CTRL (1 << 1)
198 # define MC2_BI_DI (1 << 2)
199 # define MC2_TRANSP_BDIR0 (1 << 3)
200 # define MC2_TRANSP_BDIR1 (1 << 4)
201 # define MC2_AUDIO_EN (1 << 5)
202 # define MC2_PSW_EN (1 << 6)
203 # define MC2_EN2V7 (1 << 7)
204 #define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
205 # define OTG1_DP_PULLUP (1 << 0)
206 # define OTG1_DM_PULLUP (1 << 1)
207 # define OTG1_DP_PULLDOWN (1 << 2)
208 # define OTG1_DM_PULLDOWN (1 << 3)
209 # define OTG1_ID_PULLDOWN (1 << 4)
210 # define OTG1_VBUS_DRV (1 << 5)
211 # define OTG1_VBUS_DISCHRG (1 << 6)
212 # define OTG1_VBUS_CHRG (1 << 7)
213 #define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
214 # define OTG_B_SESS_END (1 << 6)
215 # define OTG_B_SESS_VLD (1 << 7)
217 #define ISP1301_INTERRUPT_SOURCE 0x08 /* u8 read */
218 #define ISP1301_INTERRUPT_LATCH 0x0A /* u8 read, set, +1 clear */
220 #define ISP1301_INTERRUPT_FALLING 0x0C /* u8 read, set, +1 clear */
221 #define ISP1301_INTERRUPT_RISING 0x0E /* u8 read, set, +1 clear */
223 /* same bitfields in all interrupt registers */
224 # define INTR_VBUS_VLD (1 << 0)
225 # define INTR_SESS_VLD (1 << 1)
226 # define INTR_DP_HI (1 << 2)
227 # define INTR_ID_GND (1 << 3)
228 # define INTR_DM_HI (1 << 4)
229 # define INTR_ID_FLOAT (1 << 5)
230 # define INTR_BDIS_ACON (1 << 6)
231 # define INTR_CR_INT (1 << 7)
233 /*-------------------------------------------------------------------------*/
235 static inline const char *state_name(struct isp1301
*isp
)
237 return usb_otg_state_string(isp
->phy
.state
);
240 /*-------------------------------------------------------------------------*/
242 /* NOTE: some of this ISP1301 setup is specific to H2 boards;
243 * not everything is guarded by board-specific checks, or even using
244 * omap_usb_config data to deduce MC1_DAT_SE0 and MC2_BI_DI.
246 * ALSO: this currently doesn't use ISP1301 low-power modes
247 * while OTG is running.
250 static void power_down(struct isp1301
*isp
)
252 isp
->phy
.state
= OTG_STATE_UNDEFINED
;
254 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
255 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_SUSPEND
);
257 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
, OTG1_ID_PULLDOWN
);
258 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_DAT_SE0
);
261 static void power_up(struct isp1301
*isp
)
263 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
264 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_SUSPEND
);
266 /* do this only when cpu is driving transceiver,
267 * so host won't see a low speed device...
269 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_DAT_SE0
);
272 #define NO_HOST_SUSPEND
274 static int host_suspend(struct isp1301
*isp
)
276 #ifdef NO_HOST_SUSPEND
281 if (!isp
->phy
.otg
->host
)
284 /* Currently ASSUMES only the OTG port matters;
285 * other ports could be active...
287 dev
= isp
->phy
.otg
->host
->controller
;
288 return dev
->driver
->suspend(dev
, 3, 0);
292 static int host_resume(struct isp1301
*isp
)
294 #ifdef NO_HOST_SUSPEND
299 if (!isp
->phy
.otg
->host
)
302 dev
= isp
->phy
.otg
->host
->controller
;
303 return dev
->driver
->resume(dev
, 0);
307 static int gadget_suspend(struct isp1301
*isp
)
309 isp
->phy
.otg
->gadget
->b_hnp_enable
= 0;
310 isp
->phy
.otg
->gadget
->a_hnp_support
= 0;
311 isp
->phy
.otg
->gadget
->a_alt_hnp_support
= 0;
312 return usb_gadget_vbus_disconnect(isp
->phy
.otg
->gadget
);
315 /*-------------------------------------------------------------------------*/
317 #define TIMER_MINUTES 10
318 #define TIMER_JIFFIES (TIMER_MINUTES * 60 * HZ)
320 /* Almost all our I2C messaging comes from a work queue's task context.
321 * NOTE: guaranteeing certain response times might mean we shouldn't
322 * share keventd's work queue; a realtime task might be safest.
324 static void isp1301_defer_work(struct isp1301
*isp
, int work
)
328 if (isp
&& !test_and_set_bit(work
, &isp
->todo
)) {
329 (void) get_device(&isp
->client
->dev
);
330 status
= schedule_work(&isp
->work
);
331 if (!status
&& !isp
->working
)
332 dev_vdbg(&isp
->client
->dev
,
333 "work item %d may be lost\n", work
);
337 /* called from irq handlers */
338 static void a_idle(struct isp1301
*isp
, const char *tag
)
342 if (isp
->phy
.state
== OTG_STATE_A_IDLE
)
345 isp
->phy
.otg
->default_a
= 1;
346 if (isp
->phy
.otg
->host
) {
347 isp
->phy
.otg
->host
->is_b_host
= 0;
350 if (isp
->phy
.otg
->gadget
) {
351 isp
->phy
.otg
->gadget
->is_a_peripheral
= 1;
354 isp
->phy
.state
= OTG_STATE_A_IDLE
;
355 l
= omap_readl(OTG_CTRL
) & OTG_XCEIV_OUTPUTS
;
356 omap_writel(l
, OTG_CTRL
);
357 isp
->last_otg_ctrl
= l
;
358 pr_debug(" --> %s/%s\n", state_name(isp
), tag
);
361 /* called from irq handlers */
362 static void b_idle(struct isp1301
*isp
, const char *tag
)
366 if (isp
->phy
.state
== OTG_STATE_B_IDLE
)
369 isp
->phy
.otg
->default_a
= 0;
370 if (isp
->phy
.otg
->host
) {
371 isp
->phy
.otg
->host
->is_b_host
= 1;
374 if (isp
->phy
.otg
->gadget
) {
375 isp
->phy
.otg
->gadget
->is_a_peripheral
= 0;
378 isp
->phy
.state
= OTG_STATE_B_IDLE
;
379 l
= omap_readl(OTG_CTRL
) & OTG_XCEIV_OUTPUTS
;
380 omap_writel(l
, OTG_CTRL
);
381 isp
->last_otg_ctrl
= l
;
382 pr_debug(" --> %s/%s\n", state_name(isp
), tag
);
386 dump_regs(struct isp1301
*isp
, const char *label
)
388 u8 ctrl
= isp1301_get_u8(isp
, ISP1301_OTG_CONTROL_1
);
389 u8 status
= isp1301_get_u8(isp
, ISP1301_OTG_STATUS
);
390 u8 src
= isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
);
392 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
393 omap_readl(OTG_CTRL
), label
, state_name(isp
),
395 /* mode control and irq enables don't change much */
398 /*-------------------------------------------------------------------------*/
400 #ifdef CONFIG_USB_OTG
403 * The OMAP OTG controller handles most of the OTG state transitions.
405 * We translate isp1301 outputs (mostly voltage comparator status) into
406 * OTG inputs; OTG outputs (mostly pullup/pulldown controls) and HNP state
407 * flags into isp1301 inputs ... and infer state transitions.
412 static void check_state(struct isp1301
*isp
, const char *tag
)
414 enum usb_otg_state state
= OTG_STATE_UNDEFINED
;
415 u8 fsm
= omap_readw(OTG_TEST
) & 0x0ff;
422 state
= OTG_STATE_B_IDLE
;
428 state
= OTG_STATE_B_PERIPHERAL
;
431 state
= OTG_STATE_B_SRP_INIT
;
434 /* extra dual-role default-b states */
440 state
= OTG_STATE_B_WAIT_ACON
;
443 state
= OTG_STATE_B_HOST
;
448 state
= OTG_STATE_A_IDLE
;
451 state
= OTG_STATE_A_WAIT_VFALL
;
454 state
= OTG_STATE_A_VBUS_ERR
;
460 state
= OTG_STATE_A_PERIPHERAL
;
463 state
= OTG_STATE_A_WAIT_VRISE
;
466 state
= OTG_STATE_A_WAIT_BCON
;
469 state
= OTG_STATE_A_HOST
;
472 state
= OTG_STATE_A_SUSPEND
;
477 if (isp
->phy
.state
== state
&& !extra
)
479 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag
,
480 usb_otg_state_string(state
), fsm
, state_name(isp
),
481 omap_readl(OTG_CTRL
));
486 static inline void check_state(struct isp1301
*isp
, const char *tag
) { }
490 /* outputs from ISP1301_INTERRUPT_SOURCE */
491 static void update_otg1(struct isp1301
*isp
, u8 int_src
)
495 otg_ctrl
= omap_readl(OTG_CTRL
) & OTG_CTRL_MASK
;
496 otg_ctrl
&= ~OTG_XCEIV_INPUTS
;
497 otg_ctrl
&= ~(OTG_ID
|OTG_ASESSVLD
|OTG_VBUSVLD
);
499 if (int_src
& INTR_SESS_VLD
)
500 otg_ctrl
|= OTG_ASESSVLD
;
501 else if (isp
->phy
.state
== OTG_STATE_A_WAIT_VFALL
) {
502 a_idle(isp
, "vfall");
503 otg_ctrl
&= ~OTG_CTRL_BITS
;
505 if (int_src
& INTR_VBUS_VLD
)
506 otg_ctrl
|= OTG_VBUSVLD
;
507 if (int_src
& INTR_ID_GND
) { /* default-A */
508 if (isp
->phy
.state
== OTG_STATE_B_IDLE
510 == OTG_STATE_UNDEFINED
) {
514 } else { /* default-B */
516 if (isp
->phy
.state
== OTG_STATE_A_IDLE
517 || isp
->phy
.state
== OTG_STATE_UNDEFINED
) {
522 omap_writel(otg_ctrl
, OTG_CTRL
);
525 /* outputs from ISP1301_OTG_STATUS */
526 static void update_otg2(struct isp1301
*isp
, u8 otg_status
)
530 otg_ctrl
= omap_readl(OTG_CTRL
) & OTG_CTRL_MASK
;
531 otg_ctrl
&= ~OTG_XCEIV_INPUTS
;
532 otg_ctrl
&= ~(OTG_BSESSVLD
| OTG_BSESSEND
);
533 if (otg_status
& OTG_B_SESS_VLD
)
534 otg_ctrl
|= OTG_BSESSVLD
;
535 else if (otg_status
& OTG_B_SESS_END
)
536 otg_ctrl
|= OTG_BSESSEND
;
537 omap_writel(otg_ctrl
, OTG_CTRL
);
540 /* inputs going to ISP1301 */
541 static void otg_update_isp(struct isp1301
*isp
)
543 u32 otg_ctrl
, otg_change
;
544 u8 set
= OTG1_DM_PULLDOWN
, clr
= OTG1_DM_PULLUP
;
546 otg_ctrl
= omap_readl(OTG_CTRL
);
547 otg_change
= otg_ctrl
^ isp
->last_otg_ctrl
;
548 isp
->last_otg_ctrl
= otg_ctrl
;
549 otg_ctrl
= otg_ctrl
& OTG_XCEIV_INPUTS
;
551 switch (isp
->phy
.state
) {
552 case OTG_STATE_B_IDLE
:
553 case OTG_STATE_B_PERIPHERAL
:
554 case OTG_STATE_B_SRP_INIT
:
555 if (!(otg_ctrl
& OTG_PULLUP
)) {
556 // if (otg_ctrl & OTG_B_HNPEN) {
557 if (isp
->phy
.otg
->gadget
->b_hnp_enable
) {
558 isp
->phy
.state
= OTG_STATE_B_WAIT_ACON
;
559 pr_debug(" --> b_wait_acon\n");
564 set
|= OTG1_DP_PULLUP
;
565 clr
|= OTG1_DP_PULLDOWN
;
567 case OTG_STATE_A_SUSPEND
:
568 case OTG_STATE_A_PERIPHERAL
:
569 if (otg_ctrl
& OTG_PULLUP
)
572 // case OTG_STATE_B_WAIT_ACON:
575 set
|= OTG1_DP_PULLDOWN
;
576 clr
|= OTG1_DP_PULLUP
;
580 # define toggle(OTG,ISP) do { \
581 if (otg_ctrl & OTG) set |= ISP; \
585 if (!(isp
->phy
.otg
->host
))
586 otg_ctrl
&= ~OTG_DRV_VBUS
;
588 switch (isp
->phy
.state
) {
589 case OTG_STATE_A_SUSPEND
:
590 if (otg_ctrl
& OTG_DRV_VBUS
) {
591 set
|= OTG1_VBUS_DRV
;
594 /* HNP failed for some reason (A_AIDL_BDIS timeout) */
598 case OTG_STATE_A_VBUS_ERR
:
599 isp
->phy
.state
= OTG_STATE_A_WAIT_VFALL
;
600 pr_debug(" --> a_wait_vfall\n");
602 case OTG_STATE_A_WAIT_VFALL
:
603 /* FIXME usbcore thinks port power is still on ... */
604 clr
|= OTG1_VBUS_DRV
;
606 case OTG_STATE_A_IDLE
:
607 if (otg_ctrl
& OTG_DRV_VBUS
) {
608 isp
->phy
.state
= OTG_STATE_A_WAIT_VRISE
;
609 pr_debug(" --> a_wait_vrise\n");
613 toggle(OTG_DRV_VBUS
, OTG1_VBUS_DRV
);
616 toggle(OTG_PU_VBUS
, OTG1_VBUS_CHRG
);
617 toggle(OTG_PD_VBUS
, OTG1_VBUS_DISCHRG
);
621 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
, set
);
622 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
, clr
);
624 /* HNP switch to host or peripheral; and SRP */
625 if (otg_change
& OTG_PULLUP
) {
628 switch (isp
->phy
.state
) {
629 case OTG_STATE_B_IDLE
:
630 if (clr
& OTG1_DP_PULLUP
)
632 isp
->phy
.state
= OTG_STATE_B_PERIPHERAL
;
633 pr_debug(" --> b_peripheral\n");
635 case OTG_STATE_A_SUSPEND
:
636 if (clr
& OTG1_DP_PULLUP
)
638 isp
->phy
.state
= OTG_STATE_A_PERIPHERAL
;
639 pr_debug(" --> a_peripheral\n");
644 l
= omap_readl(OTG_CTRL
);
646 omap_writel(l
, OTG_CTRL
);
649 check_state(isp
, __func__
);
650 dump_regs(isp
, "otg->isp1301");
653 static irqreturn_t
omap_otg_irq(int irq
, void *_isp
)
655 u16 otg_irq
= omap_readw(OTG_IRQ_SRC
);
658 struct isp1301
*isp
= _isp
;
659 struct usb_otg
*otg
= isp
->phy
.otg
;
661 /* update ISP1301 transceiver from OTG controller */
662 if (otg_irq
& OPRT_CHG
) {
663 omap_writew(OPRT_CHG
, OTG_IRQ_SRC
);
664 isp1301_defer_work(isp
, WORK_UPDATE_ISP
);
667 /* SRP to become b_peripheral failed */
668 } else if (otg_irq
& B_SRP_TMROUT
) {
669 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL
));
672 /* gadget drivers that care should monitor all kinds of
673 * remote wakeup (SRP, normal) using their own timer
674 * to give "check cable and A-device" messages.
676 if (isp
->phy
.state
== OTG_STATE_B_SRP_INIT
)
677 b_idle(isp
, "srp_timeout");
679 omap_writew(B_SRP_TMROUT
, OTG_IRQ_SRC
);
682 /* HNP to become b_host failed */
683 } else if (otg_irq
& B_HNP_FAIL
) {
684 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
685 state_name(isp
), omap_readl(OTG_CTRL
));
688 otg_ctrl
= omap_readl(OTG_CTRL
);
689 otg_ctrl
|= OTG_BUSDROP
;
690 otg_ctrl
&= OTG_CTRL_MASK
& ~OTG_XCEIV_INPUTS
;
691 omap_writel(otg_ctrl
, OTG_CTRL
);
693 /* subset of b_peripheral()... */
694 isp
->phy
.state
= OTG_STATE_B_PERIPHERAL
;
695 pr_debug(" --> b_peripheral\n");
697 omap_writew(B_HNP_FAIL
, OTG_IRQ_SRC
);
700 /* detect SRP from B-device ... */
701 } else if (otg_irq
& A_SRP_DETECT
) {
702 pr_debug("otg: %s SRP_DETECT, %06x\n",
703 state_name(isp
), omap_readl(OTG_CTRL
));
705 isp1301_defer_work(isp
, WORK_UPDATE_OTG
);
706 switch (isp
->phy
.state
) {
707 case OTG_STATE_A_IDLE
:
710 isp1301_defer_work(isp
, WORK_HOST_RESUME
);
711 otg_ctrl
= omap_readl(OTG_CTRL
);
712 otg_ctrl
|= OTG_A_BUSREQ
;
713 otg_ctrl
&= ~(OTG_BUSDROP
|OTG_B_BUSREQ
)
716 omap_writel(otg_ctrl
, OTG_CTRL
);
722 omap_writew(A_SRP_DETECT
, OTG_IRQ_SRC
);
725 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
726 * we don't track them separately
728 } else if (otg_irq
& A_REQ_TMROUT
) {
729 otg_ctrl
= omap_readl(OTG_CTRL
);
730 pr_info("otg: BCON_TMOUT from %s, %06x\n",
731 state_name(isp
), otg_ctrl
);
734 otg_ctrl
|= OTG_BUSDROP
;
735 otg_ctrl
&= ~OTG_A_BUSREQ
& OTG_CTRL_MASK
& ~OTG_XCEIV_INPUTS
;
736 omap_writel(otg_ctrl
, OTG_CTRL
);
737 isp
->phy
.state
= OTG_STATE_A_WAIT_VFALL
;
739 omap_writew(A_REQ_TMROUT
, OTG_IRQ_SRC
);
742 /* A-supplied voltage fell too low; overcurrent */
743 } else if (otg_irq
& A_VBUS_ERR
) {
744 otg_ctrl
= omap_readl(OTG_CTRL
);
745 printk(KERN_ERR
"otg: %s, VBUS_ERR %04x ctrl %06x\n",
746 state_name(isp
), otg_irq
, otg_ctrl
);
748 otg_ctrl
|= OTG_BUSDROP
;
749 otg_ctrl
&= ~OTG_A_BUSREQ
& OTG_CTRL_MASK
& ~OTG_XCEIV_INPUTS
;
750 omap_writel(otg_ctrl
, OTG_CTRL
);
751 isp
->phy
.state
= OTG_STATE_A_VBUS_ERR
;
753 omap_writew(A_VBUS_ERR
, OTG_IRQ_SRC
);
756 /* switch driver; the transceiver code activates it,
757 * ungating the udc clock or resuming OHCI.
759 } else if (otg_irq
& DRIVER_SWITCH
) {
762 otg_ctrl
= omap_readl(OTG_CTRL
);
763 printk(KERN_NOTICE
"otg: %s, SWITCH to %s, ctrl %06x\n",
765 (otg_ctrl
& OTG_DRIVER_SEL
)
768 isp1301_defer_work(isp
, WORK_UPDATE_ISP
);
770 /* role is peripheral */
771 if (otg_ctrl
& OTG_DRIVER_SEL
) {
772 switch (isp
->phy
.state
) {
773 case OTG_STATE_A_IDLE
:
774 b_idle(isp
, __func__
);
779 isp1301_defer_work(isp
, WORK_UPDATE_ISP
);
783 if (!(otg_ctrl
& OTG_ID
)) {
784 otg_ctrl
&= OTG_CTRL_MASK
& ~OTG_XCEIV_INPUTS
;
785 omap_writel(otg_ctrl
| OTG_A_BUSREQ
, OTG_CTRL
);
789 switch (isp
->phy
.state
) {
790 case OTG_STATE_B_WAIT_ACON
:
791 isp
->phy
.state
= OTG_STATE_B_HOST
;
792 pr_debug(" --> b_host\n");
795 case OTG_STATE_A_WAIT_BCON
:
796 isp
->phy
.state
= OTG_STATE_A_HOST
;
797 pr_debug(" --> a_host\n");
799 case OTG_STATE_A_PERIPHERAL
:
800 isp
->phy
.state
= OTG_STATE_A_WAIT_BCON
;
801 pr_debug(" --> a_wait_bcon\n");
806 isp1301_defer_work(isp
, WORK_HOST_RESUME
);
810 omap_writew(DRIVER_SWITCH
, OTG_IRQ_SRC
);
814 usb_bus_start_enum(otg
->host
, otg
->host
->otg_port
);
817 check_state(isp
, __func__
);
821 static struct platform_device
*otg_dev
;
823 static int isp1301_otg_init(struct isp1301
*isp
)
830 dump_regs(isp
, __func__
);
831 /* some of these values are board-specific... */
832 l
= omap_readl(OTG_SYSCON_2
);
835 | SRP_GPDATA
/* 9msec Bdev D+ pulse */
836 | SRP_GPDVBUS
/* discharge after VBUS pulse */
837 // | (3 << 24) /* 2msec VBUS pulse */
839 | (0 << 20) /* 200ms nominal A_WAIT_VRISE timer */
840 | SRP_DPW
/* detect 167+ns SRP pulses */
841 | SRP_DATA
| SRP_VBUS
/* accept both kinds of SRP pulse */
843 omap_writel(l
, OTG_SYSCON_2
);
845 update_otg1(isp
, isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
));
846 update_otg2(isp
, isp1301_get_u8(isp
, ISP1301_OTG_STATUS
));
848 check_state(isp
, __func__
);
849 pr_debug("otg: %s, %s %06x\n",
850 state_name(isp
), __func__
, omap_readl(OTG_CTRL
));
852 omap_writew(DRIVER_SWITCH
| OPRT_CHG
853 | B_SRP_TMROUT
| B_HNP_FAIL
854 | A_VBUS_ERR
| A_SRP_DETECT
| A_REQ_TMROUT
, OTG_IRQ_EN
);
856 l
= omap_readl(OTG_SYSCON_2
);
858 omap_writel(l
, OTG_SYSCON_2
);
863 static int otg_probe(struct platform_device
*dev
)
865 // struct omap_usb_config *config = dev->platform_data;
871 static int otg_remove(struct platform_device
*dev
)
877 static struct platform_driver omap_otg_driver
= {
879 .remove
= otg_remove
,
881 .owner
= THIS_MODULE
,
886 static int otg_bind(struct isp1301
*isp
)
893 status
= platform_driver_register(&omap_otg_driver
);
898 status
= request_irq(otg_dev
->resource
[1].start
, omap_otg_irq
,
899 0, DRIVER_NAME
, isp
);
904 platform_driver_unregister(&omap_otg_driver
);
908 static void otg_unbind(struct isp1301
*isp
)
912 free_irq(otg_dev
->resource
[1].start
, isp
);
917 /* OTG controller isn't clocked */
919 #endif /* CONFIG_USB_OTG */
921 /*-------------------------------------------------------------------------*/
923 static void b_peripheral(struct isp1301
*isp
)
927 l
= omap_readl(OTG_CTRL
) & OTG_XCEIV_OUTPUTS
;
928 omap_writel(l
, OTG_CTRL
);
930 usb_gadget_vbus_connect(isp
->phy
.otg
->gadget
);
932 #ifdef CONFIG_USB_OTG
933 enable_vbus_draw(isp
, 8);
936 enable_vbus_draw(isp
, 100);
937 /* UDC driver just set OTG_BSESSVLD */
938 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
, OTG1_DP_PULLUP
);
939 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
, OTG1_DP_PULLDOWN
);
940 isp
->phy
.state
= OTG_STATE_B_PERIPHERAL
;
941 pr_debug(" --> b_peripheral\n");
942 dump_regs(isp
, "2periph");
946 static void isp_update_otg(struct isp1301
*isp
, u8 stat
)
948 struct usb_otg
*otg
= isp
->phy
.otg
;
949 u8 isp_stat
, isp_bstat
;
950 enum usb_otg_state state
= isp
->phy
.state
;
952 if (stat
& INTR_BDIS_ACON
)
953 pr_debug("OTG: BDIS_ACON, %s\n", state_name(isp
));
955 /* start certain state transitions right away */
956 isp_stat
= isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
);
957 if (isp_stat
& INTR_ID_GND
) {
958 if (otg
->default_a
) {
960 case OTG_STATE_B_IDLE
:
963 case OTG_STATE_A_IDLE
:
964 enable_vbus_source(isp
);
966 case OTG_STATE_A_WAIT_VRISE
:
967 /* we skip over OTG_STATE_A_WAIT_BCON, since
968 * the HC will transition to A_HOST (or
969 * A_SUSPEND!) without our noticing except
972 if (isp_stat
& INTR_VBUS_VLD
)
973 isp
->phy
.state
= OTG_STATE_A_HOST
;
975 case OTG_STATE_A_WAIT_VFALL
:
976 if (!(isp_stat
& INTR_SESS_VLD
))
977 a_idle(isp
, "vfell");
980 if (!(isp_stat
& INTR_VBUS_VLD
))
981 isp
->phy
.state
= OTG_STATE_A_VBUS_ERR
;
984 isp_bstat
= isp1301_get_u8(isp
, ISP1301_OTG_STATUS
);
987 case OTG_STATE_B_PERIPHERAL
:
988 case OTG_STATE_B_HOST
:
989 case OTG_STATE_B_WAIT_ACON
:
990 usb_gadget_vbus_disconnect(otg
->gadget
);
995 if (state
!= OTG_STATE_A_IDLE
)
997 if (otg
->host
&& state
== OTG_STATE_A_IDLE
)
998 isp1301_defer_work(isp
, WORK_HOST_RESUME
);
1004 /* if user unplugged mini-A end of cable,
1005 * don't bypass A_WAIT_VFALL.
1007 if (otg
->default_a
) {
1010 isp
->phy
.state
= OTG_STATE_A_WAIT_VFALL
;
1012 case OTG_STATE_A_WAIT_VFALL
:
1013 state
= OTG_STATE_A_IDLE
;
1014 /* khubd may take a while to notice and
1015 * handle this disconnect, so don't go
1016 * to B_IDLE quite yet.
1019 case OTG_STATE_A_IDLE
:
1021 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_1
,
1023 isp
->phy
.state
= OTG_STATE_B_IDLE
;
1024 l
= omap_readl(OTG_CTRL
) & OTG_CTRL_MASK
;
1025 l
&= ~OTG_CTRL_BITS
;
1026 omap_writel(l
, OTG_CTRL
);
1028 case OTG_STATE_B_IDLE
:
1032 isp_bstat
= isp1301_get_u8(isp
, ISP1301_OTG_STATUS
);
1034 switch (isp
->phy
.state
) {
1035 case OTG_STATE_B_PERIPHERAL
:
1036 case OTG_STATE_B_WAIT_ACON
:
1037 case OTG_STATE_B_HOST
:
1038 if (likely(isp_bstat
& OTG_B_SESS_VLD
))
1040 enable_vbus_draw(isp
, 0);
1041 #ifndef CONFIG_USB_OTG
1042 /* UDC driver will clear OTG_BSESSVLD */
1043 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
,
1045 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
,
1047 dump_regs(isp
, __func__
);
1050 case OTG_STATE_B_SRP_INIT
:
1051 b_idle(isp
, __func__
);
1052 l
= omap_readl(OTG_CTRL
) & OTG_XCEIV_OUTPUTS
;
1053 omap_writel(l
, OTG_CTRL
);
1055 case OTG_STATE_B_IDLE
:
1056 if (otg
->gadget
&& (isp_bstat
& OTG_B_SESS_VLD
)) {
1057 #ifdef CONFIG_USB_OTG
1058 update_otg1(isp
, isp_stat
);
1059 update_otg2(isp
, isp_bstat
);
1062 } else if (!(isp_stat
& (INTR_VBUS_VLD
|INTR_SESS_VLD
)))
1063 isp_bstat
|= OTG_B_SESS_END
;
1065 case OTG_STATE_A_WAIT_VFALL
:
1068 pr_debug("otg: unsupported b-device %s\n",
1074 if (state
!= isp
->phy
.state
)
1075 pr_debug(" isp, %s -> %s\n",
1076 usb_otg_state_string(state
), state_name(isp
));
1078 #ifdef CONFIG_USB_OTG
1079 /* update the OTG controller state to match the isp1301; may
1080 * trigger OPRT_CHG irqs for changes going to the isp1301.
1082 update_otg1(isp
, isp_stat
);
1083 update_otg2(isp
, isp_bstat
);
1084 check_state(isp
, __func__
);
1087 dump_regs(isp
, "isp1301->otg");
1090 /*-------------------------------------------------------------------------*/
1092 static u8
isp1301_clear_latch(struct isp1301
*isp
)
1094 u8 latch
= isp1301_get_u8(isp
, ISP1301_INTERRUPT_LATCH
);
1095 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_LATCH
, latch
);
1100 isp1301_work(struct work_struct
*work
)
1102 struct isp1301
*isp
= container_of(work
, struct isp1301
, work
);
1105 /* implicit lock: we're the only task using this device */
1108 stop
= test_bit(WORK_STOP
, &isp
->todo
);
1110 #ifdef CONFIG_USB_OTG
1111 /* transfer state from otg engine to isp1301 */
1112 if (test_and_clear_bit(WORK_UPDATE_ISP
, &isp
->todo
)) {
1113 otg_update_isp(isp
);
1114 put_device(&isp
->client
->dev
);
1117 /* transfer state from isp1301 to otg engine */
1118 if (test_and_clear_bit(WORK_UPDATE_OTG
, &isp
->todo
)) {
1119 u8 stat
= isp1301_clear_latch(isp
);
1121 isp_update_otg(isp
, stat
);
1122 put_device(&isp
->client
->dev
);
1125 if (test_and_clear_bit(WORK_HOST_RESUME
, &isp
->todo
)) {
1129 * skip A_WAIT_VRISE; hc transitions invisibly
1130 * skip A_WAIT_BCON; same.
1132 switch (isp
->phy
.state
) {
1133 case OTG_STATE_A_WAIT_BCON
:
1134 case OTG_STATE_A_WAIT_VRISE
:
1135 isp
->phy
.state
= OTG_STATE_A_HOST
;
1136 pr_debug(" --> a_host\n");
1137 otg_ctrl
= omap_readl(OTG_CTRL
);
1138 otg_ctrl
|= OTG_A_BUSREQ
;
1139 otg_ctrl
&= ~(OTG_BUSDROP
|OTG_B_BUSREQ
)
1141 omap_writel(otg_ctrl
, OTG_CTRL
);
1143 case OTG_STATE_B_WAIT_ACON
:
1144 isp
->phy
.state
= OTG_STATE_B_HOST
;
1145 pr_debug(" --> b_host (acon)\n");
1147 case OTG_STATE_B_HOST
:
1148 case OTG_STATE_B_IDLE
:
1149 case OTG_STATE_A_IDLE
:
1152 pr_debug(" host resume in %s\n",
1157 put_device(&isp
->client
->dev
);
1160 if (test_and_clear_bit(WORK_TIMER
, &isp
->todo
)) {
1162 dump_regs(isp
, "timer");
1164 mod_timer(&isp
->timer
, jiffies
+ TIMER_JIFFIES
);
1166 put_device(&isp
->client
->dev
);
1170 dev_vdbg(&isp
->client
->dev
,
1171 "work done, todo = 0x%lx\n",
1174 dev_dbg(&isp
->client
->dev
, "stop\n");
1177 } while (isp
->todo
);
1181 static irqreturn_t
isp1301_irq(int irq
, void *isp
)
1183 isp1301_defer_work(isp
, WORK_UPDATE_OTG
);
1187 static void isp1301_timer(unsigned long _isp
)
1189 isp1301_defer_work((void *)_isp
, WORK_TIMER
);
1192 /*-------------------------------------------------------------------------*/
1194 static void isp1301_release(struct device
*dev
)
1196 struct isp1301
*isp
;
1198 isp
= dev_get_drvdata(dev
);
1200 /* FIXME -- not with a "new style" driver, it doesn't!! */
1202 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1203 if (isp
->i2c_release
)
1204 isp
->i2c_release(dev
);
1205 kfree(isp
->phy
.otg
);
1209 static struct isp1301
*the_transceiver
;
1211 static int isp1301_remove(struct i2c_client
*i2c
)
1213 struct isp1301
*isp
;
1215 isp
= i2c_get_clientdata(i2c
);
1217 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_FALLING
, ~0);
1218 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_RISING
, ~0);
1219 free_irq(i2c
->irq
, isp
);
1220 #ifdef CONFIG_USB_OTG
1223 if (machine_is_omap_h2())
1226 isp
->timer
.data
= 0;
1227 set_bit(WORK_STOP
, &isp
->todo
);
1228 del_timer_sync(&isp
->timer
);
1229 flush_work(&isp
->work
);
1231 put_device(&i2c
->dev
);
1232 the_transceiver
= NULL
;
1237 /*-------------------------------------------------------------------------*/
1239 /* NOTE: three modes are possible here, only one of which
1240 * will be standards-conformant on any given system:
1242 * - OTG mode (dual-role), required if there's a Mini-AB connector
1243 * - HOST mode, for when there's one or more A (host) connectors
1244 * - DEVICE mode, for when there's a B/Mini-B (device) connector
1246 * As a rule, you won't have an isp1301 chip unless it's there to
1247 * support the OTG mode. Other modes help testing USB controllers
1248 * in isolation from (full) OTG support, or maybe so later board
1249 * revisions can help to support those feature.
1252 #ifdef CONFIG_USB_OTG
1254 static int isp1301_otg_enable(struct isp1301
*isp
)
1257 isp1301_otg_init(isp
);
1259 /* NOTE: since we don't change this, this provides
1260 * a few more interrupts than are strictly needed.
1262 isp1301_set_bits(isp
, ISP1301_INTERRUPT_RISING
,
1263 INTR_VBUS_VLD
| INTR_SESS_VLD
| INTR_ID_GND
);
1264 isp1301_set_bits(isp
, ISP1301_INTERRUPT_FALLING
,
1265 INTR_VBUS_VLD
| INTR_SESS_VLD
| INTR_ID_GND
);
1267 dev_info(&isp
->client
->dev
, "ready for dual-role USB ...\n");
1274 /* add or disable the host device+driver */
1276 isp1301_set_host(struct usb_otg
*otg
, struct usb_bus
*host
)
1278 struct isp1301
*isp
= container_of(otg
->phy
, struct isp1301
, phy
);
1280 if (!otg
|| isp
!= the_transceiver
)
1284 omap_writew(0, OTG_IRQ_EN
);
1290 #ifdef CONFIG_USB_OTG
1292 dev_dbg(&isp
->client
->dev
, "registered host\n");
1295 return isp1301_otg_enable(isp
);
1298 #elif !IS_ENABLED(CONFIG_USB_OMAP)
1299 // FIXME update its refcount
1304 if (machine_is_omap_h2())
1305 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_DAT_SE0
);
1307 dev_info(&isp
->client
->dev
, "A-Host sessions ok\n");
1308 isp1301_set_bits(isp
, ISP1301_INTERRUPT_RISING
,
1310 isp1301_set_bits(isp
, ISP1301_INTERRUPT_FALLING
,
1313 /* If this has a Mini-AB connector, this mode is highly
1314 * nonstandard ... but can be handy for testing, especially with
1315 * the Mini-A end of an OTG cable. (Or something nonstandard
1316 * like MiniB-to-StandardB, maybe built with a gender mender.)
1318 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
, OTG1_VBUS_DRV
);
1320 dump_regs(isp
, __func__
);
1325 dev_dbg(&isp
->client
->dev
, "host sessions not allowed\n");
1332 isp1301_set_peripheral(struct usb_otg
*otg
, struct usb_gadget
*gadget
)
1334 struct isp1301
*isp
= container_of(otg
->phy
, struct isp1301
, phy
);
1336 if (!otg
|| isp
!= the_transceiver
)
1340 omap_writew(0, OTG_IRQ_EN
);
1341 if (!otg
->default_a
)
1342 enable_vbus_draw(isp
, 0);
1343 usb_gadget_vbus_disconnect(otg
->gadget
);
1349 #ifdef CONFIG_USB_OTG
1350 otg
->gadget
= gadget
;
1351 dev_dbg(&isp
->client
->dev
, "registered gadget\n");
1352 /* gadget driver may be suspended until vbus_connect () */
1354 return isp1301_otg_enable(isp
);
1357 #elif !defined(CONFIG_USB_OHCI_HCD) && !defined(CONFIG_USB_OHCI_HCD_MODULE)
1358 otg
->gadget
= gadget
;
1359 // FIXME update its refcount
1364 l
= omap_readl(OTG_CTRL
) & OTG_CTRL_MASK
;
1365 l
&= ~(OTG_XCEIV_OUTPUTS
|OTG_CTRL_BITS
);
1367 omap_writel(l
, OTG_CTRL
);
1371 isp
->phy
.state
= OTG_STATE_B_IDLE
;
1373 if (machine_is_omap_h2() || machine_is_omap_h3())
1374 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_DAT_SE0
);
1376 isp1301_set_bits(isp
, ISP1301_INTERRUPT_RISING
,
1378 isp1301_set_bits(isp
, ISP1301_INTERRUPT_FALLING
,
1380 dev_info(&isp
->client
->dev
, "B-Peripheral sessions ok\n");
1381 dump_regs(isp
, __func__
);
1383 /* If this has a Mini-AB connector, this mode is highly
1384 * nonstandard ... but can be handy for testing, so long
1385 * as you don't plug a Mini-A cable into the jack.
1387 if (isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
) & INTR_VBUS_VLD
)
1393 dev_dbg(&isp
->client
->dev
, "peripheral sessions not allowed\n");
1399 /*-------------------------------------------------------------------------*/
1402 isp1301_set_power(struct usb_phy
*dev
, unsigned mA
)
1404 if (!the_transceiver
)
1406 if (dev
->state
== OTG_STATE_B_PERIPHERAL
)
1407 enable_vbus_draw(the_transceiver
, mA
);
1412 isp1301_start_srp(struct usb_otg
*otg
)
1414 struct isp1301
*isp
= container_of(otg
->phy
, struct isp1301
, phy
);
1417 if (!otg
|| isp
!= the_transceiver
1418 || isp
->phy
.state
!= OTG_STATE_B_IDLE
)
1421 otg_ctrl
= omap_readl(OTG_CTRL
);
1422 if (!(otg_ctrl
& OTG_BSESSEND
))
1425 otg_ctrl
|= OTG_B_BUSREQ
;
1426 otg_ctrl
&= ~OTG_A_BUSREQ
& OTG_CTRL_MASK
;
1427 omap_writel(otg_ctrl
, OTG_CTRL
);
1428 isp
->phy
.state
= OTG_STATE_B_SRP_INIT
;
1430 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp
),
1431 omap_readl(OTG_CTRL
));
1432 #ifdef CONFIG_USB_OTG
1433 check_state(isp
, __func__
);
1439 isp1301_start_hnp(struct usb_otg
*otg
)
1441 #ifdef CONFIG_USB_OTG
1442 struct isp1301
*isp
= container_of(otg
->phy
, struct isp1301
, phy
);
1445 if (!otg
|| isp
!= the_transceiver
)
1447 if (otg
->default_a
&& (otg
->host
== NULL
|| !otg
->host
->b_hnp_enable
))
1449 if (!otg
->default_a
&& (otg
->gadget
== NULL
1450 || !otg
->gadget
->b_hnp_enable
))
1453 /* We want hardware to manage most HNP protocol timings.
1454 * So do this part as early as possible...
1456 switch (isp
->phy
.state
) {
1457 case OTG_STATE_B_HOST
:
1458 isp
->phy
.state
= OTG_STATE_B_PERIPHERAL
;
1459 /* caller will suspend next */
1461 case OTG_STATE_A_HOST
:
1463 /* autoconnect mode avoids irq latency bugs */
1464 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
,
1467 /* caller must suspend then clear A_BUSREQ */
1468 usb_gadget_vbus_connect(otg
->gadget
);
1469 l
= omap_readl(OTG_CTRL
);
1470 l
|= OTG_A_SETB_HNPEN
;
1471 omap_writel(l
, OTG_CTRL
);
1474 case OTG_STATE_A_PERIPHERAL
:
1475 /* initiated by B-Host suspend */
1480 pr_debug("otg: HNP %s, %06x ...\n",
1481 state_name(isp
), omap_readl(OTG_CTRL
));
1482 check_state(isp
, __func__
);
1490 /*-------------------------------------------------------------------------*/
1493 isp1301_probe(struct i2c_client
*i2c
, const struct i2c_device_id
*id
)
1496 struct isp1301
*isp
;
1498 if (the_transceiver
)
1501 isp
= kzalloc(sizeof *isp
, GFP_KERNEL
);
1505 isp
->phy
.otg
= kzalloc(sizeof *isp
->phy
.otg
, GFP_KERNEL
);
1506 if (!isp
->phy
.otg
) {
1511 INIT_WORK(&isp
->work
, isp1301_work
);
1512 init_timer(&isp
->timer
);
1513 isp
->timer
.function
= isp1301_timer
;
1514 isp
->timer
.data
= (unsigned long) isp
;
1516 i2c_set_clientdata(i2c
, isp
);
1519 /* verify the chip (shouldn't be necessary) */
1520 status
= isp1301_get_u16(isp
, ISP1301_VENDOR_ID
);
1521 if (status
!= I2C_VENDOR_ID_PHILIPS
) {
1522 dev_dbg(&i2c
->dev
, "not philips id: %d\n", status
);
1525 status
= isp1301_get_u16(isp
, ISP1301_PRODUCT_ID
);
1526 if (status
!= I2C_PRODUCT_ID_PHILIPS_1301
) {
1527 dev_dbg(&i2c
->dev
, "not isp1301, %d\n", status
);
1530 isp
->i2c_release
= i2c
->dev
.release
;
1531 i2c
->dev
.release
= isp1301_release
;
1533 /* initial development used chiprev 2.00 */
1534 status
= i2c_smbus_read_word_data(i2c
, ISP1301_BCD_DEVICE
);
1535 dev_info(&i2c
->dev
, "chiprev %x.%02x, driver " DRIVER_VERSION
"\n",
1536 status
>> 8, status
& 0xff);
1538 /* make like power-on reset */
1539 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_1
, MC1_MASK
);
1541 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_2
, MC2_BI_DI
);
1542 isp1301_clear_bits(isp
, ISP1301_MODE_CONTROL_2
, ~MC2_BI_DI
);
1544 isp1301_set_bits(isp
, ISP1301_OTG_CONTROL_1
,
1545 OTG1_DM_PULLDOWN
| OTG1_DP_PULLDOWN
);
1546 isp1301_clear_bits(isp
, ISP1301_OTG_CONTROL_1
,
1547 ~(OTG1_DM_PULLDOWN
| OTG1_DP_PULLDOWN
));
1549 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_LATCH
, ~0);
1550 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_FALLING
, ~0);
1551 isp1301_clear_bits(isp
, ISP1301_INTERRUPT_RISING
, ~0);
1553 #ifdef CONFIG_USB_OTG
1554 status
= otg_bind(isp
);
1556 dev_dbg(&i2c
->dev
, "can't bind OTG\n");
1561 if (machine_is_omap_h2()) {
1562 /* full speed signaling by default */
1563 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_1
,
1565 isp1301_set_bits(isp
, ISP1301_MODE_CONTROL_2
,
1568 /* IRQ wired at M14 */
1569 omap_cfg_reg(M14_1510_GPIO2
);
1570 if (gpio_request(2, "isp1301") == 0)
1571 gpio_direction_input(2);
1572 isp
->irq_type
= IRQF_TRIGGER_FALLING
;
1575 status
= request_irq(i2c
->irq
, isp1301_irq
,
1576 isp
->irq_type
, DRIVER_NAME
, isp
);
1578 dev_dbg(&i2c
->dev
, "can't get IRQ %d, err %d\n",
1583 isp
->phy
.dev
= &i2c
->dev
;
1584 isp
->phy
.label
= DRIVER_NAME
;
1585 isp
->phy
.set_power
= isp1301_set_power
,
1587 isp
->phy
.otg
->phy
= &isp
->phy
;
1588 isp
->phy
.otg
->set_host
= isp1301_set_host
,
1589 isp
->phy
.otg
->set_peripheral
= isp1301_set_peripheral
,
1590 isp
->phy
.otg
->start_srp
= isp1301_start_srp
,
1591 isp
->phy
.otg
->start_hnp
= isp1301_start_hnp
,
1593 enable_vbus_draw(isp
, 0);
1595 the_transceiver
= isp
;
1597 #ifdef CONFIG_USB_OTG
1598 update_otg1(isp
, isp1301_get_u8(isp
, ISP1301_INTERRUPT_SOURCE
));
1599 update_otg2(isp
, isp1301_get_u8(isp
, ISP1301_OTG_STATUS
));
1602 dump_regs(isp
, __func__
);
1605 mod_timer(&isp
->timer
, jiffies
+ TIMER_JIFFIES
);
1606 dev_dbg(&i2c
->dev
, "scheduled timer, %d min\n", TIMER_MINUTES
);
1609 status
= usb_add_phy(&isp
->phy
, USB_PHY_TYPE_USB2
);
1611 dev_err(&i2c
->dev
, "can't register transceiver, %d\n",
1617 kfree(isp
->phy
.otg
);
1622 static const struct i2c_device_id isp1301_id
[] = {
1623 { "isp1301_omap", 0 },
1626 MODULE_DEVICE_TABLE(i2c
, isp1301_id
);
1628 static struct i2c_driver isp1301_driver
= {
1630 .name
= "isp1301_omap",
1632 .probe
= isp1301_probe
,
1633 .remove
= isp1301_remove
,
1634 .id_table
= isp1301_id
,
1637 /*-------------------------------------------------------------------------*/
1639 static int __init
isp_init(void)
1641 return i2c_add_driver(&isp1301_driver
);
1643 subsys_initcall(isp_init
);
1645 static void __exit
isp_exit(void)
1647 if (the_transceiver
)
1648 usb_remove_phy(&the_transceiver
->phy
);
1649 i2c_del_driver(&isp1301_driver
);
1651 module_exit(isp_exit
);