2 * otg_fsm.c - ChipIdea USB IP core OTG FSM driver
4 * Copyright (C) 2014 Freescale Semiconductor, Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 * This file mainly handles OTG fsm, it includes OTG fsm operations
22 #include <linux/usb/otg.h>
23 #include <linux/usb/gadget.h>
24 #include <linux/usb/hcd.h>
25 #include <linux/usb/chipidea.h>
26 #include <linux/regulator/consumer.h>
33 /* Add for otg: interact with user space app */
35 get_a_bus_req(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
39 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
43 t
= scnprintf(next
, size
, "%d\n", ci
->fsm
.a_bus_req
);
47 return PAGE_SIZE
- size
;
51 set_a_bus_req(struct device
*dev
, struct device_attribute
*attr
,
52 const char *buf
, size_t count
)
54 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
59 mutex_lock(&ci
->fsm
.lock
);
61 ci
->fsm
.a_bus_req
= 0;
62 } else if (buf
[0] == '1') {
63 /* If a_bus_drop is TRUE, a_bus_req can't be set */
64 if (ci
->fsm
.a_bus_drop
) {
65 mutex_unlock(&ci
->fsm
.lock
);
68 ci
->fsm
.a_bus_req
= 1;
71 ci_otg_queue_work(ci
);
72 mutex_unlock(&ci
->fsm
.lock
);
76 static DEVICE_ATTR(a_bus_req
, S_IRUGO
| S_IWUSR
, get_a_bus_req
, set_a_bus_req
);
79 get_a_bus_drop(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
83 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
87 t
= scnprintf(next
, size
, "%d\n", ci
->fsm
.a_bus_drop
);
91 return PAGE_SIZE
- size
;
95 set_a_bus_drop(struct device
*dev
, struct device_attribute
*attr
,
96 const char *buf
, size_t count
)
98 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
103 mutex_lock(&ci
->fsm
.lock
);
105 ci
->fsm
.a_bus_drop
= 0;
106 } else if (buf
[0] == '1') {
107 ci
->fsm
.a_bus_drop
= 1;
108 ci
->fsm
.a_bus_req
= 0;
111 ci_otg_queue_work(ci
);
112 mutex_unlock(&ci
->fsm
.lock
);
116 static DEVICE_ATTR(a_bus_drop
, S_IRUGO
| S_IWUSR
, get_a_bus_drop
,
120 get_b_bus_req(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
124 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
128 t
= scnprintf(next
, size
, "%d\n", ci
->fsm
.b_bus_req
);
132 return PAGE_SIZE
- size
;
136 set_b_bus_req(struct device
*dev
, struct device_attribute
*attr
,
137 const char *buf
, size_t count
)
139 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
144 mutex_lock(&ci
->fsm
.lock
);
146 ci
->fsm
.b_bus_req
= 0;
147 else if (buf
[0] == '1')
148 ci
->fsm
.b_bus_req
= 1;
150 ci_otg_queue_work(ci
);
151 mutex_unlock(&ci
->fsm
.lock
);
155 static DEVICE_ATTR(b_bus_req
, S_IRUGO
| S_IWUSR
, get_b_bus_req
, set_b_bus_req
);
158 set_a_clr_err(struct device
*dev
, struct device_attribute
*attr
,
159 const char *buf
, size_t count
)
161 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
166 mutex_lock(&ci
->fsm
.lock
);
168 ci
->fsm
.a_clr_err
= 1;
170 ci_otg_queue_work(ci
);
171 mutex_unlock(&ci
->fsm
.lock
);
175 static DEVICE_ATTR(a_clr_err
, S_IWUSR
, NULL
, set_a_clr_err
);
177 static struct attribute
*inputs_attrs
[] = {
178 &dev_attr_a_bus_req
.attr
,
179 &dev_attr_a_bus_drop
.attr
,
180 &dev_attr_b_bus_req
.attr
,
181 &dev_attr_a_clr_err
.attr
,
185 static struct attribute_group inputs_attr_group
= {
187 .attrs
= inputs_attrs
,
191 * Keep this list in the same order as timers indexed
192 * by enum otg_fsm_timer in include/linux/usb/otg-fsm.h
194 static unsigned otg_timer_ms
[] = {
209 * Add timer to active timer list
211 static void ci_otg_add_timer(struct ci_hdrc
*ci
, enum otg_fsm_timer t
)
213 unsigned long flags
, timer_sec
, timer_nsec
;
215 if (t
>= NUM_OTG_FSM_TIMERS
)
218 spin_lock_irqsave(&ci
->lock
, flags
);
219 timer_sec
= otg_timer_ms
[t
] / MSEC_PER_SEC
;
220 timer_nsec
= (otg_timer_ms
[t
] % MSEC_PER_SEC
) * NSEC_PER_MSEC
;
221 ci
->hr_timeouts
[t
] = ktime_add(ktime_get(),
222 ktime_set(timer_sec
, timer_nsec
));
223 ci
->enabled_otg_timer_bits
|= (1 << t
);
224 if ((ci
->next_otg_timer
== NUM_OTG_FSM_TIMERS
) ||
225 (ci
->hr_timeouts
[ci
->next_otg_timer
].tv64
>
226 ci
->hr_timeouts
[t
].tv64
)) {
227 ci
->next_otg_timer
= t
;
228 hrtimer_start_range_ns(&ci
->otg_fsm_hrtimer
,
229 ci
->hr_timeouts
[t
], NSEC_PER_MSEC
,
232 spin_unlock_irqrestore(&ci
->lock
, flags
);
236 * Remove timer from active timer list
238 static void ci_otg_del_timer(struct ci_hdrc
*ci
, enum otg_fsm_timer t
)
240 unsigned long flags
, enabled_timer_bits
;
241 enum otg_fsm_timer cur_timer
, next_timer
= NUM_OTG_FSM_TIMERS
;
243 if ((t
>= NUM_OTG_FSM_TIMERS
) ||
244 !(ci
->enabled_otg_timer_bits
& (1 << t
)))
247 spin_lock_irqsave(&ci
->lock
, flags
);
248 ci
->enabled_otg_timer_bits
&= ~(1 << t
);
249 if (ci
->next_otg_timer
== t
) {
250 if (ci
->enabled_otg_timer_bits
== 0) {
251 /* No enabled timers after delete it */
252 hrtimer_cancel(&ci
->otg_fsm_hrtimer
);
253 ci
->next_otg_timer
= NUM_OTG_FSM_TIMERS
;
255 /* Find the next timer */
256 enabled_timer_bits
= ci
->enabled_otg_timer_bits
;
257 for_each_set_bit(cur_timer
, &enabled_timer_bits
,
258 NUM_OTG_FSM_TIMERS
) {
259 if ((next_timer
== NUM_OTG_FSM_TIMERS
) ||
260 (ci
->hr_timeouts
[next_timer
].tv64
<
261 ci
->hr_timeouts
[cur_timer
].tv64
))
262 next_timer
= cur_timer
;
266 if (next_timer
!= NUM_OTG_FSM_TIMERS
) {
267 ci
->next_otg_timer
= next_timer
;
268 hrtimer_start_range_ns(&ci
->otg_fsm_hrtimer
,
269 ci
->hr_timeouts
[next_timer
], NSEC_PER_MSEC
,
272 spin_unlock_irqrestore(&ci
->lock
, flags
);
275 /* OTG FSM timer handlers */
276 static int a_wait_vrise_tmout(struct ci_hdrc
*ci
)
278 ci
->fsm
.a_wait_vrise_tmout
= 1;
282 static int a_wait_vfall_tmout(struct ci_hdrc
*ci
)
284 ci
->fsm
.a_wait_vfall_tmout
= 1;
288 static int a_wait_bcon_tmout(struct ci_hdrc
*ci
)
290 ci
->fsm
.a_wait_bcon_tmout
= 1;
294 static int a_aidl_bdis_tmout(struct ci_hdrc
*ci
)
296 ci
->fsm
.a_aidl_bdis_tmout
= 1;
300 static int b_ase0_brst_tmout(struct ci_hdrc
*ci
)
302 ci
->fsm
.b_ase0_brst_tmout
= 1;
306 static int a_bidl_adis_tmout(struct ci_hdrc
*ci
)
308 ci
->fsm
.a_bidl_adis_tmout
= 1;
312 static int b_se0_srp_tmout(struct ci_hdrc
*ci
)
314 ci
->fsm
.b_se0_srp
= 1;
318 static int b_srp_fail_tmout(struct ci_hdrc
*ci
)
320 ci
->fsm
.b_srp_done
= 1;
324 static int b_data_pls_tmout(struct ci_hdrc
*ci
)
326 ci
->fsm
.b_srp_done
= 1;
327 ci
->fsm
.b_bus_req
= 0;
328 if (ci
->fsm
.power_up
)
329 ci
->fsm
.power_up
= 0;
330 hw_write_otgsc(ci
, OTGSC_HABA
, 0);
331 pm_runtime_put(ci
->dev
);
335 static int b_ssend_srp_tmout(struct ci_hdrc
*ci
)
337 ci
->fsm
.b_ssend_srp
= 1;
338 /* only vbus fall below B_sess_vld in b_idle state */
339 if (ci
->fsm
.otg
->state
== OTG_STATE_B_IDLE
)
346 * Keep this list in the same order as timers indexed
347 * by enum otg_fsm_timer in include/linux/usb/otg-fsm.h
349 static int (*otg_timer_handlers
[])(struct ci_hdrc
*) = {
350 a_wait_vrise_tmout
, /* A_WAIT_VRISE */
351 a_wait_vfall_tmout
, /* A_WAIT_VFALL */
352 a_wait_bcon_tmout
, /* A_WAIT_BCON */
353 a_aidl_bdis_tmout
, /* A_AIDL_BDIS */
354 b_ase0_brst_tmout
, /* B_ASE0_BRST */
355 a_bidl_adis_tmout
, /* A_BIDL_ADIS */
356 b_se0_srp_tmout
, /* B_SE0_SRP */
357 b_srp_fail_tmout
, /* B_SRP_FAIL */
358 NULL
, /* A_WAIT_ENUM */
359 b_data_pls_tmout
, /* B_DATA_PLS */
360 b_ssend_srp_tmout
, /* B_SSEND_SRP */
364 * Enable the next nearest enabled timer if have
366 static enum hrtimer_restart
ci_otg_hrtimer_func(struct hrtimer
*t
)
368 struct ci_hdrc
*ci
= container_of(t
, struct ci_hdrc
, otg_fsm_hrtimer
);
369 ktime_t now
, *timeout
;
370 unsigned long enabled_timer_bits
;
372 enum otg_fsm_timer cur_timer
, next_timer
= NUM_OTG_FSM_TIMERS
;
375 spin_lock_irqsave(&ci
->lock
, flags
);
376 enabled_timer_bits
= ci
->enabled_otg_timer_bits
;
377 ci
->next_otg_timer
= NUM_OTG_FSM_TIMERS
;
380 for_each_set_bit(cur_timer
, &enabled_timer_bits
, NUM_OTG_FSM_TIMERS
) {
381 if (now
.tv64
>= ci
->hr_timeouts
[cur_timer
].tv64
) {
382 ci
->enabled_otg_timer_bits
&= ~(1 << cur_timer
);
383 if (otg_timer_handlers
[cur_timer
])
384 ret
= otg_timer_handlers
[cur_timer
](ci
);
386 if ((next_timer
== NUM_OTG_FSM_TIMERS
) ||
387 (ci
->hr_timeouts
[cur_timer
].tv64
<
388 ci
->hr_timeouts
[next_timer
].tv64
))
389 next_timer
= cur_timer
;
392 /* Enable the next nearest timer */
393 if (next_timer
< NUM_OTG_FSM_TIMERS
) {
394 timeout
= &ci
->hr_timeouts
[next_timer
];
395 hrtimer_start_range_ns(&ci
->otg_fsm_hrtimer
, *timeout
,
396 NSEC_PER_MSEC
, HRTIMER_MODE_ABS
);
397 ci
->next_otg_timer
= next_timer
;
399 spin_unlock_irqrestore(&ci
->lock
, flags
);
402 ci_otg_queue_work(ci
);
404 return HRTIMER_NORESTART
;
407 /* Initialize timers */
408 static int ci_otg_init_timers(struct ci_hdrc
*ci
)
410 hrtimer_init(&ci
->otg_fsm_hrtimer
, CLOCK_MONOTONIC
, HRTIMER_MODE_ABS
);
411 ci
->otg_fsm_hrtimer
.function
= ci_otg_hrtimer_func
;
416 /* -------------------------------------------------------------*/
417 /* Operations that will be called from OTG Finite State Machine */
418 /* -------------------------------------------------------------*/
419 static void ci_otg_fsm_add_timer(struct otg_fsm
*fsm
, enum otg_fsm_timer t
)
421 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
423 if (t
< NUM_OTG_FSM_TIMERS
)
424 ci_otg_add_timer(ci
, t
);
428 static void ci_otg_fsm_del_timer(struct otg_fsm
*fsm
, enum otg_fsm_timer t
)
430 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
432 if (t
< NUM_OTG_FSM_TIMERS
)
433 ci_otg_del_timer(ci
, t
);
438 * A-device drive vbus: turn on vbus regulator and enable port power
439 * Data pulse irq should be disabled while vbus is on.
441 static void ci_otg_drv_vbus(struct otg_fsm
*fsm
, int on
)
444 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
447 /* Enable power power */
448 hw_write(ci
, OP_PORTSC
, PORTSC_W1C_BITS
| PORTSC_PP
,
450 if (ci
->platdata
->reg_vbus
) {
451 ret
= regulator_enable(ci
->platdata
->reg_vbus
);
454 "Failed to enable vbus regulator, ret=%d\n",
459 /* Disable data pulse irq */
460 hw_write_otgsc(ci
, OTGSC_DPIE
, 0);
465 if (ci
->platdata
->reg_vbus
)
466 regulator_disable(ci
->platdata
->reg_vbus
);
474 * Control data line by Run Stop bit.
476 static void ci_otg_loc_conn(struct otg_fsm
*fsm
, int on
)
478 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
481 hw_write(ci
, OP_USBCMD
, USBCMD_RS
, USBCMD_RS
);
483 hw_write(ci
, OP_USBCMD
, USBCMD_RS
, 0);
487 * Generate SOF by host.
488 * This is controlled through suspend/resume the port.
489 * In host mode, controller will automatically send SOF.
490 * Suspend will block the data on the port.
492 static void ci_otg_loc_sof(struct otg_fsm
*fsm
, int on
)
494 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
497 hw_write(ci
, OP_PORTSC
, PORTSC_W1C_BITS
| PORTSC_FPR
,
500 hw_write(ci
, OP_PORTSC
, PORTSC_W1C_BITS
| PORTSC_SUSP
,
505 * Start SRP pulsing by data-line pulsing,
506 * no v-bus pulsing followed
508 static void ci_otg_start_pulse(struct otg_fsm
*fsm
)
510 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
512 /* Hardware Assistant Data pulse */
513 hw_write_otgsc(ci
, OTGSC_HADP
, OTGSC_HADP
);
515 pm_runtime_get(ci
->dev
);
516 ci_otg_add_timer(ci
, B_DATA_PLS
);
519 static int ci_otg_start_host(struct otg_fsm
*fsm
, int on
)
521 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
525 ci_role_start(ci
, CI_ROLE_HOST
);
529 ci_role_start(ci
, CI_ROLE_GADGET
);
534 static int ci_otg_start_gadget(struct otg_fsm
*fsm
, int on
)
536 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
539 usb_gadget_vbus_connect(&ci
->gadget
);
541 usb_gadget_vbus_disconnect(&ci
->gadget
);
546 static struct otg_fsm_ops ci_otg_ops
= {
547 .drv_vbus
= ci_otg_drv_vbus
,
548 .loc_conn
= ci_otg_loc_conn
,
549 .loc_sof
= ci_otg_loc_sof
,
550 .start_pulse
= ci_otg_start_pulse
,
551 .add_timer
= ci_otg_fsm_add_timer
,
552 .del_timer
= ci_otg_fsm_del_timer
,
553 .start_host
= ci_otg_start_host
,
554 .start_gadget
= ci_otg_start_gadget
,
557 int ci_otg_fsm_work(struct ci_hdrc
*ci
)
560 * Don't do fsm transition for B device
561 * when there is no gadget class driver
563 if (ci
->fsm
.id
&& !(ci
->driver
) &&
564 ci
->fsm
.otg
->state
< OTG_STATE_A_IDLE
)
567 pm_runtime_get_sync(ci
->dev
);
568 if (otg_statemachine(&ci
->fsm
)) {
569 if (ci
->fsm
.otg
->state
== OTG_STATE_A_IDLE
) {
571 * Further state change for cases:
572 * a_idle to b_idle; or
573 * a_idle to a_wait_vrise due to ID change(1->0), so
574 * B-dev becomes A-dev can try to start new session
576 * a_idle to a_wait_vrise when power up
578 if ((ci
->fsm
.id
) || (ci
->id_event
) ||
579 (ci
->fsm
.power_up
)) {
580 ci_otg_queue_work(ci
);
582 /* Enable data pulse irq */
583 hw_write(ci
, OP_PORTSC
, PORTSC_W1C_BITS
|
585 hw_write_otgsc(ci
, OTGSC_DPIS
, OTGSC_DPIS
);
586 hw_write_otgsc(ci
, OTGSC_DPIE
, OTGSC_DPIE
);
589 ci
->id_event
= false;
590 } else if (ci
->fsm
.otg
->state
== OTG_STATE_B_IDLE
) {
591 if (ci
->fsm
.b_sess_vld
) {
592 ci
->fsm
.power_up
= 0;
594 * Further transite to b_periphearl state
595 * when register gadget driver with vbus on
597 ci_otg_queue_work(ci
);
599 } else if (ci
->fsm
.otg
->state
== OTG_STATE_A_HOST
) {
600 pm_runtime_mark_last_busy(ci
->dev
);
601 pm_runtime_put_autosuspend(ci
->dev
);
605 pm_runtime_put_sync(ci
->dev
);
610 * Update fsm variables in each state if catching expected interrupts,
611 * called by otg fsm isr.
613 static void ci_otg_fsm_event(struct ci_hdrc
*ci
)
615 u32 intr_sts
, otg_bsess_vld
, port_conn
;
616 struct otg_fsm
*fsm
= &ci
->fsm
;
618 intr_sts
= hw_read_intr_status(ci
);
619 otg_bsess_vld
= hw_read_otgsc(ci
, OTGSC_BSV
);
620 port_conn
= hw_read(ci
, OP_PORTSC
, PORTSC_CCS
);
622 switch (ci
->fsm
.otg
->state
) {
623 case OTG_STATE_A_WAIT_BCON
:
627 ci_otg_queue_work(ci
);
630 case OTG_STATE_B_IDLE
:
631 if (otg_bsess_vld
&& (intr_sts
& USBi_PCI
) && port_conn
) {
633 ci_otg_queue_work(ci
);
636 case OTG_STATE_B_PERIPHERAL
:
637 if ((intr_sts
& USBi_SLI
) && port_conn
&& otg_bsess_vld
) {
638 fsm
->a_bus_suspend
= 1;
639 ci_otg_queue_work(ci
);
640 } else if (intr_sts
& USBi_PCI
) {
641 if (fsm
->a_bus_suspend
== 1)
642 fsm
->a_bus_suspend
= 0;
645 case OTG_STATE_B_HOST
:
646 if ((intr_sts
& USBi_PCI
) && !port_conn
) {
649 ci_otg_queue_work(ci
);
652 case OTG_STATE_A_PERIPHERAL
:
653 if (intr_sts
& USBi_SLI
) {
654 fsm
->b_bus_suspend
= 1;
656 * Init a timer to know how long this suspend
657 * will continue, if time out, indicates B no longer
658 * wants to be host role
660 ci_otg_add_timer(ci
, A_BIDL_ADIS
);
663 if (intr_sts
& USBi_URI
)
664 ci_otg_del_timer(ci
, A_BIDL_ADIS
);
666 if (intr_sts
& USBi_PCI
) {
667 if (fsm
->b_bus_suspend
== 1) {
668 ci_otg_del_timer(ci
, A_BIDL_ADIS
);
669 fsm
->b_bus_suspend
= 0;
673 case OTG_STATE_A_SUSPEND
:
674 if ((intr_sts
& USBi_PCI
) && !port_conn
) {
677 /* if gadget driver is binded */
679 /* A device to be peripheral mode */
680 ci
->gadget
.is_a_peripheral
= 1;
682 ci_otg_queue_work(ci
);
685 case OTG_STATE_A_HOST
:
686 if ((intr_sts
& USBi_PCI
) && !port_conn
) {
688 ci_otg_queue_work(ci
);
691 case OTG_STATE_B_WAIT_ACON
:
692 if ((intr_sts
& USBi_PCI
) && port_conn
) {
694 ci_otg_queue_work(ci
);
703 * ci_otg_irq - otg fsm related irq handling
704 * and also update otg fsm variable by monitoring usb host and udc
705 * state change interrupts.
708 irqreturn_t
ci_otg_fsm_irq(struct ci_hdrc
*ci
)
710 irqreturn_t retval
= IRQ_NONE
;
711 u32 otgsc
, otg_int_src
= 0;
712 struct otg_fsm
*fsm
= &ci
->fsm
;
714 otgsc
= hw_read_otgsc(ci
, ~0);
715 otg_int_src
= otgsc
& OTGSC_INT_STATUS_BITS
& (otgsc
>> 8);
716 fsm
->id
= (otgsc
& OTGSC_ID
) ? 1 : 0;
719 if (otg_int_src
& OTGSC_DPIS
) {
720 hw_write_otgsc(ci
, OTGSC_DPIS
, OTGSC_DPIS
);
723 } else if (otg_int_src
& OTGSC_IDIS
) {
724 hw_write_otgsc(ci
, OTGSC_IDIS
, OTGSC_IDIS
);
730 } else if (otg_int_src
& OTGSC_BSVIS
) {
731 hw_write_otgsc(ci
, OTGSC_BSVIS
, OTGSC_BSVIS
);
732 if (otgsc
& OTGSC_BSV
) {
734 ci_otg_del_timer(ci
, B_SSEND_SRP
);
735 ci_otg_del_timer(ci
, B_SRP_FAIL
);
736 fsm
->b_ssend_srp
= 0;
740 ci_otg_add_timer(ci
, B_SSEND_SRP
);
742 } else if (otg_int_src
& OTGSC_AVVIS
) {
743 hw_write_otgsc(ci
, OTGSC_AVVIS
, OTGSC_AVVIS
);
744 if (otgsc
& OTGSC_AVV
) {
751 ci_otg_queue_work(ci
);
755 ci_otg_fsm_event(ci
);
760 void ci_hdrc_otg_fsm_start(struct ci_hdrc
*ci
)
762 ci_otg_queue_work(ci
);
765 int ci_hdrc_otg_fsm_init(struct ci_hdrc
*ci
)
770 ci
->otg
.phy
= ci
->phy
;
772 ci
->otg
.usb_phy
= ci
->usb_phy
;
774 ci
->otg
.gadget
= &ci
->gadget
;
775 ci
->fsm
.otg
= &ci
->otg
;
776 ci
->fsm
.power_up
= 1;
777 ci
->fsm
.id
= hw_read_otgsc(ci
, OTGSC_ID
) ? 1 : 0;
778 ci
->fsm
.otg
->state
= OTG_STATE_UNDEFINED
;
779 ci
->fsm
.ops
= &ci_otg_ops
;
781 mutex_init(&ci
->fsm
.lock
);
783 retval
= ci_otg_init_timers(ci
);
785 dev_err(ci
->dev
, "Couldn't init OTG timers\n");
788 ci
->enabled_otg_timer_bits
= 0;
789 ci
->next_otg_timer
= NUM_OTG_FSM_TIMERS
;
791 retval
= sysfs_create_group(&ci
->dev
->kobj
, &inputs_attr_group
);
794 "Can't register sysfs attr group: %d\n", retval
);
798 /* Enable A vbus valid irq */
799 hw_write_otgsc(ci
, OTGSC_AVVIE
, OTGSC_AVVIE
);
802 ci
->fsm
.b_ssend_srp
=
803 hw_read_otgsc(ci
, OTGSC_BSV
) ? 0 : 1;
805 hw_read_otgsc(ci
, OTGSC_BSV
) ? 1 : 0;
807 hw_write_otgsc(ci
, OTGSC_BSVIE
, OTGSC_BSVIE
);
813 void ci_hdrc_otg_fsm_remove(struct ci_hdrc
*ci
)
815 sysfs_remove_group(&ci
->dev
->kobj
, &inputs_attr_group
);