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 static struct ci_otg_fsm_timer
*otg_timer_initializer
34 (struct ci_hdrc
*ci
, void (*function
)(void *, unsigned long),
35 unsigned long expires
, unsigned long data
)
37 struct ci_otg_fsm_timer
*timer
;
39 timer
= devm_kzalloc(ci
->dev
, sizeof(struct ci_otg_fsm_timer
),
43 timer
->function
= function
;
44 timer
->expires
= expires
;
49 /* Add for otg: interact with user space app */
51 get_a_bus_req(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
55 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
59 t
= scnprintf(next
, size
, "%d\n", ci
->fsm
.a_bus_req
);
63 return PAGE_SIZE
- size
;
67 set_a_bus_req(struct device
*dev
, struct device_attribute
*attr
,
68 const char *buf
, size_t count
)
70 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
75 mutex_lock(&ci
->fsm
.lock
);
77 ci
->fsm
.a_bus_req
= 0;
78 } else if (buf
[0] == '1') {
79 /* If a_bus_drop is TRUE, a_bus_req can't be set */
80 if (ci
->fsm
.a_bus_drop
) {
81 mutex_unlock(&ci
->fsm
.lock
);
84 ci
->fsm
.a_bus_req
= 1;
87 ci_otg_queue_work(ci
);
88 mutex_unlock(&ci
->fsm
.lock
);
92 static DEVICE_ATTR(a_bus_req
, S_IRUGO
| S_IWUSR
, get_a_bus_req
, set_a_bus_req
);
95 get_a_bus_drop(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
99 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
103 t
= scnprintf(next
, size
, "%d\n", ci
->fsm
.a_bus_drop
);
107 return PAGE_SIZE
- size
;
111 set_a_bus_drop(struct device
*dev
, struct device_attribute
*attr
,
112 const char *buf
, size_t count
)
114 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
119 mutex_lock(&ci
->fsm
.lock
);
121 ci
->fsm
.a_bus_drop
= 0;
122 } else if (buf
[0] == '1') {
123 ci
->fsm
.a_bus_drop
= 1;
124 ci
->fsm
.a_bus_req
= 0;
127 ci_otg_queue_work(ci
);
128 mutex_unlock(&ci
->fsm
.lock
);
132 static DEVICE_ATTR(a_bus_drop
, S_IRUGO
| S_IWUSR
, get_a_bus_drop
,
136 get_b_bus_req(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
140 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
144 t
= scnprintf(next
, size
, "%d\n", ci
->fsm
.b_bus_req
);
148 return PAGE_SIZE
- size
;
152 set_b_bus_req(struct device
*dev
, struct device_attribute
*attr
,
153 const char *buf
, size_t count
)
155 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
160 mutex_lock(&ci
->fsm
.lock
);
162 ci
->fsm
.b_bus_req
= 0;
163 else if (buf
[0] == '1')
164 ci
->fsm
.b_bus_req
= 1;
166 ci_otg_queue_work(ci
);
167 mutex_unlock(&ci
->fsm
.lock
);
171 static DEVICE_ATTR(b_bus_req
, S_IRUGO
| S_IWUSR
, get_b_bus_req
, set_b_bus_req
);
174 set_a_clr_err(struct device
*dev
, struct device_attribute
*attr
,
175 const char *buf
, size_t count
)
177 struct ci_hdrc
*ci
= dev_get_drvdata(dev
);
182 mutex_lock(&ci
->fsm
.lock
);
184 ci
->fsm
.a_clr_err
= 1;
186 ci_otg_queue_work(ci
);
187 mutex_unlock(&ci
->fsm
.lock
);
191 static DEVICE_ATTR(a_clr_err
, S_IWUSR
, NULL
, set_a_clr_err
);
193 static struct attribute
*inputs_attrs
[] = {
194 &dev_attr_a_bus_req
.attr
,
195 &dev_attr_a_bus_drop
.attr
,
196 &dev_attr_b_bus_req
.attr
,
197 &dev_attr_a_clr_err
.attr
,
201 static struct attribute_group inputs_attr_group
= {
203 .attrs
= inputs_attrs
,
207 * Add timer to active timer list
209 static void ci_otg_add_timer(struct ci_hdrc
*ci
, enum ci_otg_fsm_timer_index t
)
211 struct ci_otg_fsm_timer
*tmp_timer
;
212 struct ci_otg_fsm_timer
*timer
= ci
->fsm_timer
->timer_list
[t
];
213 struct list_head
*active_timers
= &ci
->fsm_timer
->active_timers
;
215 if (t
>= NUM_CI_OTG_FSM_TIMERS
)
219 * Check if the timer is already in the active list,
220 * if so update timer count
222 list_for_each_entry(tmp_timer
, active_timers
, list
)
223 if (tmp_timer
== timer
) {
224 timer
->count
= timer
->expires
;
228 timer
->count
= timer
->expires
;
229 list_add_tail(&timer
->list
, active_timers
);
232 if (!(hw_read_otgsc(ci
, OTGSC_1MSIE
)))
233 hw_write_otgsc(ci
, OTGSC_1MSIE
, OTGSC_1MSIE
);
237 * Remove timer from active timer list
239 static void ci_otg_del_timer(struct ci_hdrc
*ci
, enum ci_otg_fsm_timer_index t
)
241 struct ci_otg_fsm_timer
*tmp_timer
, *del_tmp
;
242 struct ci_otg_fsm_timer
*timer
= ci
->fsm_timer
->timer_list
[t
];
243 struct list_head
*active_timers
= &ci
->fsm_timer
->active_timers
;
245 if (t
>= NUM_CI_OTG_FSM_TIMERS
)
248 list_for_each_entry_safe(tmp_timer
, del_tmp
, active_timers
, list
)
249 if (tmp_timer
== timer
)
250 list_del(&timer
->list
);
252 /* Disable 1ms irq if there is no any active timer */
253 if (list_empty(active_timers
))
254 hw_write_otgsc(ci
, OTGSC_1MSIE
, 0);
258 * Reduce timer count by 1, and find timeout conditions.
259 * Called by otg 1ms timer interrupt
261 static inline int ci_otg_tick_timer(struct ci_hdrc
*ci
)
263 struct ci_otg_fsm_timer
*tmp_timer
, *del_tmp
;
264 struct list_head
*active_timers
= &ci
->fsm_timer
->active_timers
;
267 list_for_each_entry_safe(tmp_timer
, del_tmp
, active_timers
, list
) {
269 /* check if timer expires */
270 if (!tmp_timer
->count
) {
271 list_del(&tmp_timer
->list
);
272 tmp_timer
->function(ci
, tmp_timer
->data
);
277 /* disable 1ms irq if there is no any timer active */
278 if ((expired
== 1) && list_empty(active_timers
))
279 hw_write_otgsc(ci
, OTGSC_1MSIE
, 0);
284 /* The timeout callback function to set time out bit */
285 static void set_tmout(void *ptr
, unsigned long indicator
)
287 *(int *)indicator
= 1;
290 static void set_tmout_and_fsm(void *ptr
, unsigned long indicator
)
292 struct ci_hdrc
*ci
= (struct ci_hdrc
*)ptr
;
294 set_tmout(ci
, indicator
);
296 ci_otg_queue_work(ci
);
299 static void a_wait_vfall_tmout_func(void *ptr
, unsigned long indicator
)
301 struct ci_hdrc
*ci
= (struct ci_hdrc
*)ptr
;
303 set_tmout(ci
, indicator
);
304 /* Disable port power */
305 hw_write(ci
, OP_PORTSC
, PORTSC_W1C_BITS
| PORTSC_PP
, 0);
306 /* Clear existing DP irq */
307 hw_write_otgsc(ci
, OTGSC_DPIS
, OTGSC_DPIS
);
308 /* Enable data pulse irq */
309 hw_write_otgsc(ci
, OTGSC_DPIE
, OTGSC_DPIE
);
310 ci_otg_queue_work(ci
);
313 static void b_ase0_brst_tmout_func(void *ptr
, unsigned long indicator
)
315 struct ci_hdrc
*ci
= (struct ci_hdrc
*)ptr
;
317 set_tmout(ci
, indicator
);
318 if (!hw_read_otgsc(ci
, OTGSC_BSV
))
319 ci
->fsm
.b_sess_vld
= 0;
321 ci_otg_queue_work(ci
);
324 static void b_ssend_srp_tmout_func(void *ptr
, unsigned long indicator
)
326 struct ci_hdrc
*ci
= (struct ci_hdrc
*)ptr
;
328 set_tmout(ci
, indicator
);
330 /* only vbus fall below B_sess_vld in b_idle state */
331 if (ci
->fsm
.otg
->state
== OTG_STATE_B_IDLE
)
332 ci_otg_queue_work(ci
);
335 static void b_sess_vld_tmout_func(void *ptr
, unsigned long indicator
)
337 struct ci_hdrc
*ci
= (struct ci_hdrc
*)ptr
;
339 /* Check if A detached */
340 if (!(hw_read_otgsc(ci
, OTGSC_BSV
))) {
341 ci
->fsm
.b_sess_vld
= 0;
342 ci_otg_add_timer(ci
, B_SSEND_SRP
);
343 ci_otg_queue_work(ci
);
347 static void b_data_pulse_end(void *ptr
, unsigned long indicator
)
349 struct ci_hdrc
*ci
= (struct ci_hdrc
*)ptr
;
351 ci
->fsm
.b_srp_done
= 1;
352 ci
->fsm
.b_bus_req
= 0;
353 if (ci
->fsm
.power_up
)
354 ci
->fsm
.power_up
= 0;
356 hw_write_otgsc(ci
, OTGSC_HABA
, 0);
358 ci_otg_queue_work(ci
);
361 /* Initialize timers */
362 static int ci_otg_init_timers(struct ci_hdrc
*ci
)
364 struct otg_fsm
*fsm
= &ci
->fsm
;
366 /* FSM used timers */
367 ci
->fsm_timer
->timer_list
[A_WAIT_VRISE
] =
368 otg_timer_initializer(ci
, &set_tmout_and_fsm
, TA_WAIT_VRISE
,
369 (unsigned long)&fsm
->a_wait_vrise_tmout
);
370 if (ci
->fsm_timer
->timer_list
[A_WAIT_VRISE
] == NULL
)
373 ci
->fsm_timer
->timer_list
[A_WAIT_VFALL
] =
374 otg_timer_initializer(ci
, &a_wait_vfall_tmout_func
,
375 TA_WAIT_VFALL
, (unsigned long)&fsm
->a_wait_vfall_tmout
);
376 if (ci
->fsm_timer
->timer_list
[A_WAIT_VFALL
] == NULL
)
379 ci
->fsm_timer
->timer_list
[A_WAIT_BCON
] =
380 otg_timer_initializer(ci
, &set_tmout_and_fsm
, TA_WAIT_BCON
,
381 (unsigned long)&fsm
->a_wait_bcon_tmout
);
382 if (ci
->fsm_timer
->timer_list
[A_WAIT_BCON
] == NULL
)
385 ci
->fsm_timer
->timer_list
[A_AIDL_BDIS
] =
386 otg_timer_initializer(ci
, &set_tmout_and_fsm
, TA_AIDL_BDIS
,
387 (unsigned long)&fsm
->a_aidl_bdis_tmout
);
388 if (ci
->fsm_timer
->timer_list
[A_AIDL_BDIS
] == NULL
)
391 ci
->fsm_timer
->timer_list
[A_BIDL_ADIS
] =
392 otg_timer_initializer(ci
, &set_tmout_and_fsm
, TA_BIDL_ADIS
,
393 (unsigned long)&fsm
->a_bidl_adis_tmout
);
394 if (ci
->fsm_timer
->timer_list
[A_BIDL_ADIS
] == NULL
)
397 ci
->fsm_timer
->timer_list
[B_ASE0_BRST
] =
398 otg_timer_initializer(ci
, &b_ase0_brst_tmout_func
, TB_ASE0_BRST
,
399 (unsigned long)&fsm
->b_ase0_brst_tmout
);
400 if (ci
->fsm_timer
->timer_list
[B_ASE0_BRST
] == NULL
)
403 ci
->fsm_timer
->timer_list
[B_SE0_SRP
] =
404 otg_timer_initializer(ci
, &set_tmout_and_fsm
, TB_SE0_SRP
,
405 (unsigned long)&fsm
->b_se0_srp
);
406 if (ci
->fsm_timer
->timer_list
[B_SE0_SRP
] == NULL
)
409 ci
->fsm_timer
->timer_list
[B_SSEND_SRP
] =
410 otg_timer_initializer(ci
, &b_ssend_srp_tmout_func
, TB_SSEND_SRP
,
411 (unsigned long)&fsm
->b_ssend_srp
);
412 if (ci
->fsm_timer
->timer_list
[B_SSEND_SRP
] == NULL
)
415 ci
->fsm_timer
->timer_list
[B_SRP_FAIL
] =
416 otg_timer_initializer(ci
, &set_tmout
, TB_SRP_FAIL
,
417 (unsigned long)&fsm
->b_srp_done
);
418 if (ci
->fsm_timer
->timer_list
[B_SRP_FAIL
] == NULL
)
421 ci
->fsm_timer
->timer_list
[B_DATA_PLS
] =
422 otg_timer_initializer(ci
, &b_data_pulse_end
, TB_DATA_PLS
, 0);
423 if (ci
->fsm_timer
->timer_list
[B_DATA_PLS
] == NULL
)
426 ci
->fsm_timer
->timer_list
[B_SESS_VLD
] = otg_timer_initializer(ci
,
427 &b_sess_vld_tmout_func
, TB_SESS_VLD
, 0);
428 if (ci
->fsm_timer
->timer_list
[B_SESS_VLD
] == NULL
)
434 /* -------------------------------------------------------------*/
435 /* Operations that will be called from OTG Finite State Machine */
436 /* -------------------------------------------------------------*/
437 static void ci_otg_fsm_add_timer(struct otg_fsm
*fsm
, enum otg_fsm_timer t
)
439 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
441 if (t
< NUM_OTG_FSM_TIMERS
)
442 ci_otg_add_timer(ci
, t
);
446 static void ci_otg_fsm_del_timer(struct otg_fsm
*fsm
, enum otg_fsm_timer t
)
448 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
450 if (t
< NUM_OTG_FSM_TIMERS
)
451 ci_otg_del_timer(ci
, t
);
456 * A-device drive vbus: turn on vbus regulator and enable port power
457 * Data pulse irq should be disabled while vbus is on.
459 static void ci_otg_drv_vbus(struct otg_fsm
*fsm
, int on
)
462 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
465 /* Enable power power */
466 hw_write(ci
, OP_PORTSC
, PORTSC_W1C_BITS
| PORTSC_PP
,
468 if (ci
->platdata
->reg_vbus
) {
469 ret
= regulator_enable(ci
->platdata
->reg_vbus
);
472 "Failed to enable vbus regulator, ret=%d\n",
477 /* Disable data pulse irq */
478 hw_write_otgsc(ci
, OTGSC_DPIE
, 0);
483 if (ci
->platdata
->reg_vbus
)
484 regulator_disable(ci
->platdata
->reg_vbus
);
492 * Control data line by Run Stop bit.
494 static void ci_otg_loc_conn(struct otg_fsm
*fsm
, int on
)
496 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
499 hw_write(ci
, OP_USBCMD
, USBCMD_RS
, USBCMD_RS
);
501 hw_write(ci
, OP_USBCMD
, USBCMD_RS
, 0);
505 * Generate SOF by host.
506 * This is controlled through suspend/resume the port.
507 * In host mode, controller will automatically send SOF.
508 * Suspend will block the data on the port.
510 static void ci_otg_loc_sof(struct otg_fsm
*fsm
, int on
)
512 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
515 hw_write(ci
, OP_PORTSC
, PORTSC_W1C_BITS
| PORTSC_FPR
,
518 hw_write(ci
, OP_PORTSC
, PORTSC_W1C_BITS
| PORTSC_SUSP
,
523 * Start SRP pulsing by data-line pulsing,
524 * no v-bus pulsing followed
526 static void ci_otg_start_pulse(struct otg_fsm
*fsm
)
528 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
530 /* Hardware Assistant Data pulse */
531 hw_write_otgsc(ci
, OTGSC_HADP
, OTGSC_HADP
);
533 ci_otg_add_timer(ci
, B_DATA_PLS
);
536 static int ci_otg_start_host(struct otg_fsm
*fsm
, int on
)
538 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
540 mutex_unlock(&fsm
->lock
);
543 ci_role_start(ci
, CI_ROLE_HOST
);
547 ci_role_start(ci
, CI_ROLE_GADGET
);
549 mutex_lock(&fsm
->lock
);
553 static int ci_otg_start_gadget(struct otg_fsm
*fsm
, int on
)
555 struct ci_hdrc
*ci
= container_of(fsm
, struct ci_hdrc
, fsm
);
557 mutex_unlock(&fsm
->lock
);
559 usb_gadget_vbus_connect(&ci
->gadget
);
561 usb_gadget_vbus_disconnect(&ci
->gadget
);
562 mutex_lock(&fsm
->lock
);
567 static struct otg_fsm_ops ci_otg_ops
= {
568 .drv_vbus
= ci_otg_drv_vbus
,
569 .loc_conn
= ci_otg_loc_conn
,
570 .loc_sof
= ci_otg_loc_sof
,
571 .start_pulse
= ci_otg_start_pulse
,
572 .add_timer
= ci_otg_fsm_add_timer
,
573 .del_timer
= ci_otg_fsm_del_timer
,
574 .start_host
= ci_otg_start_host
,
575 .start_gadget
= ci_otg_start_gadget
,
578 int ci_otg_fsm_work(struct ci_hdrc
*ci
)
581 * Don't do fsm transition for B device
582 * when there is no gadget class driver
584 if (ci
->fsm
.id
&& !(ci
->driver
) &&
585 ci
->fsm
.otg
->state
< OTG_STATE_A_IDLE
)
588 if (otg_statemachine(&ci
->fsm
)) {
589 if (ci
->fsm
.otg
->state
== OTG_STATE_A_IDLE
) {
591 * Further state change for cases:
592 * a_idle to b_idle; or
593 * a_idle to a_wait_vrise due to ID change(1->0), so
594 * B-dev becomes A-dev can try to start new session
596 * a_idle to a_wait_vrise when power up
598 if ((ci
->fsm
.id
) || (ci
->id_event
) ||
600 ci_otg_queue_work(ci
);
602 ci
->id_event
= false;
603 } else if (ci
->fsm
.otg
->state
== OTG_STATE_B_IDLE
) {
604 if (ci
->fsm
.b_sess_vld
) {
605 ci
->fsm
.power_up
= 0;
607 * Further transite to b_periphearl state
608 * when register gadget driver with vbus on
610 ci_otg_queue_work(ci
);
618 * Update fsm variables in each state if catching expected interrupts,
619 * called by otg fsm isr.
621 static void ci_otg_fsm_event(struct ci_hdrc
*ci
)
623 u32 intr_sts
, otg_bsess_vld
, port_conn
;
624 struct otg_fsm
*fsm
= &ci
->fsm
;
626 intr_sts
= hw_read_intr_status(ci
);
627 otg_bsess_vld
= hw_read_otgsc(ci
, OTGSC_BSV
);
628 port_conn
= hw_read(ci
, OP_PORTSC
, PORTSC_CCS
);
630 switch (ci
->fsm
.otg
->state
) {
631 case OTG_STATE_A_WAIT_BCON
:
635 ci_otg_queue_work(ci
);
638 case OTG_STATE_B_IDLE
:
639 if (otg_bsess_vld
&& (intr_sts
& USBi_PCI
) && port_conn
) {
641 ci_otg_queue_work(ci
);
644 case OTG_STATE_B_PERIPHERAL
:
645 if ((intr_sts
& USBi_SLI
) && port_conn
&& otg_bsess_vld
) {
646 fsm
->a_bus_suspend
= 1;
647 ci_otg_queue_work(ci
);
648 } else if (intr_sts
& USBi_PCI
) {
649 if (fsm
->a_bus_suspend
== 1)
650 fsm
->a_bus_suspend
= 0;
653 case OTG_STATE_B_HOST
:
654 if ((intr_sts
& USBi_PCI
) && !port_conn
) {
657 ci_otg_queue_work(ci
);
658 ci_otg_add_timer(ci
, B_SESS_VLD
);
661 case OTG_STATE_A_PERIPHERAL
:
662 if (intr_sts
& USBi_SLI
) {
663 fsm
->b_bus_suspend
= 1;
665 * Init a timer to know how long this suspend
666 * will continue, if time out, indicates B no longer
667 * wants to be host role
669 ci_otg_add_timer(ci
, A_BIDL_ADIS
);
672 if (intr_sts
& USBi_URI
)
673 ci_otg_del_timer(ci
, A_BIDL_ADIS
);
675 if (intr_sts
& USBi_PCI
) {
676 if (fsm
->b_bus_suspend
== 1) {
677 ci_otg_del_timer(ci
, A_BIDL_ADIS
);
678 fsm
->b_bus_suspend
= 0;
682 case OTG_STATE_A_SUSPEND
:
683 if ((intr_sts
& USBi_PCI
) && !port_conn
) {
686 /* if gadget driver is binded */
688 /* A device to be peripheral mode */
689 ci
->gadget
.is_a_peripheral
= 1;
691 ci_otg_queue_work(ci
);
694 case OTG_STATE_A_HOST
:
695 if ((intr_sts
& USBi_PCI
) && !port_conn
) {
697 ci_otg_queue_work(ci
);
700 case OTG_STATE_B_WAIT_ACON
:
701 if ((intr_sts
& USBi_PCI
) && port_conn
) {
703 ci_otg_queue_work(ci
);
712 * ci_otg_irq - otg fsm related irq handling
713 * and also update otg fsm variable by monitoring usb host and udc
714 * state change interrupts.
717 irqreturn_t
ci_otg_fsm_irq(struct ci_hdrc
*ci
)
719 irqreturn_t retval
= IRQ_NONE
;
720 u32 otgsc
, otg_int_src
= 0;
721 struct otg_fsm
*fsm
= &ci
->fsm
;
723 otgsc
= hw_read_otgsc(ci
, ~0);
724 otg_int_src
= otgsc
& OTGSC_INT_STATUS_BITS
& (otgsc
>> 8);
725 fsm
->id
= (otgsc
& OTGSC_ID
) ? 1 : 0;
728 if (otg_int_src
& OTGSC_1MSIS
) {
729 hw_write_otgsc(ci
, OTGSC_1MSIS
, OTGSC_1MSIS
);
730 retval
= ci_otg_tick_timer(ci
);
732 } else if (otg_int_src
& OTGSC_DPIS
) {
733 hw_write_otgsc(ci
, OTGSC_DPIS
, OTGSC_DPIS
);
736 } else if (otg_int_src
& OTGSC_IDIS
) {
737 hw_write_otgsc(ci
, OTGSC_IDIS
, OTGSC_IDIS
);
743 } else if (otg_int_src
& OTGSC_BSVIS
) {
744 hw_write_otgsc(ci
, OTGSC_BSVIS
, OTGSC_BSVIS
);
745 if (otgsc
& OTGSC_BSV
) {
747 ci_otg_del_timer(ci
, B_SSEND_SRP
);
748 ci_otg_del_timer(ci
, B_SRP_FAIL
);
749 fsm
->b_ssend_srp
= 0;
753 ci_otg_add_timer(ci
, B_SSEND_SRP
);
755 } else if (otg_int_src
& OTGSC_AVVIS
) {
756 hw_write_otgsc(ci
, OTGSC_AVVIS
, OTGSC_AVVIS
);
757 if (otgsc
& OTGSC_AVV
) {
764 ci_otg_queue_work(ci
);
768 ci_otg_fsm_event(ci
);
773 void ci_hdrc_otg_fsm_start(struct ci_hdrc
*ci
)
775 ci_otg_queue_work(ci
);
778 int ci_hdrc_otg_fsm_init(struct ci_hdrc
*ci
)
783 ci
->otg
.phy
= ci
->phy
;
785 ci
->otg
.usb_phy
= ci
->usb_phy
;
787 ci
->otg
.gadget
= &ci
->gadget
;
788 ci
->fsm
.otg
= &ci
->otg
;
789 ci
->fsm
.power_up
= 1;
790 ci
->fsm
.id
= hw_read_otgsc(ci
, OTGSC_ID
) ? 1 : 0;
791 ci
->fsm
.otg
->state
= OTG_STATE_UNDEFINED
;
792 ci
->fsm
.ops
= &ci_otg_ops
;
794 mutex_init(&ci
->fsm
.lock
);
796 ci
->fsm_timer
= devm_kzalloc(ci
->dev
,
797 sizeof(struct ci_otg_fsm_timer_list
), GFP_KERNEL
);
801 INIT_LIST_HEAD(&ci
->fsm_timer
->active_timers
);
802 retval
= ci_otg_init_timers(ci
);
804 dev_err(ci
->dev
, "Couldn't init OTG timers\n");
808 retval
= sysfs_create_group(&ci
->dev
->kobj
, &inputs_attr_group
);
811 "Can't register sysfs attr group: %d\n", retval
);
815 /* Enable A vbus valid irq */
816 hw_write_otgsc(ci
, OTGSC_AVVIE
, OTGSC_AVVIE
);
819 ci
->fsm
.b_ssend_srp
=
820 hw_read_otgsc(ci
, OTGSC_BSV
) ? 0 : 1;
822 hw_read_otgsc(ci
, OTGSC_BSV
) ? 1 : 0;
824 hw_write_otgsc(ci
, OTGSC_BSVIE
, OTGSC_BSVIE
);
830 void ci_hdrc_otg_fsm_remove(struct ci_hdrc
*ci
)
832 sysfs_remove_group(&ci
->dev
->kobj
, &inputs_attr_group
);