aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/phy
diff options
context:
space:
mode:
authorAnton Tikhomirov <av.tikhomirov@samsung.com>2013-10-02 23:42:04 -0400
committerFelipe Balbi <balbi@ti.com>2013-10-04 10:44:46 -0400
commitf6de27eed372f41646b7bd95d6903923f5308517 (patch)
tree16ec735ae61a94ff35dd15474a92e54c0b73cca7 /drivers/usb/phy
parent425d710172cee47ed5e18eefd3308d88643de76d (diff)
usb: phy: Fix OTG FSM timer handling
Get rid of using OTG driver specific timers by passing timer type to corresponding callbacks. Signed-off-by: Anton Tikhomirov <av.tikhomirov@samsung.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/phy')
-rw-r--r--drivers/usb/phy/phy-fsl-usb.c60
-rw-r--r--drivers/usb/phy/phy-fsm-usb.c28
-rw-r--r--drivers/usb/phy/phy-fsm-usb.h24
3 files changed, 87 insertions, 25 deletions
diff --git a/drivers/usb/phy/phy-fsl-usb.c b/drivers/usb/phy/phy-fsl-usb.c
index 8b34694ac48f..649586169be5 100644
--- a/drivers/usb/phy/phy-fsl-usb.c
+++ b/drivers/usb/phy/phy-fsl-usb.c
@@ -375,6 +375,40 @@ void fsl_otg_uninit_timers(void)
375 kfree(b_vbus_pulse_tmr); 375 kfree(b_vbus_pulse_tmr);
376} 376}
377 377
378static struct fsl_otg_timer *fsl_otg_get_timer(enum otg_fsm_timer t)
379{
380 struct fsl_otg_timer *timer;
381
382 /* REVISIT: use array of pointers to timers instead */
383 switch (t) {
384 case A_WAIT_VRISE:
385 timer = a_wait_vrise_tmr;
386 break;
387 case A_WAIT_BCON:
388 timer = a_wait_vrise_tmr;
389 break;
390 case A_AIDL_BDIS:
391 timer = a_wait_vrise_tmr;
392 break;
393 case B_ASE0_BRST:
394 timer = a_wait_vrise_tmr;
395 break;
396 case B_SE0_SRP:
397 timer = a_wait_vrise_tmr;
398 break;
399 case B_SRP_FAIL:
400 timer = a_wait_vrise_tmr;
401 break;
402 case A_WAIT_ENUM:
403 timer = a_wait_vrise_tmr;
404 break;
405 default:
406 timer = NULL;
407 }
408
409 return timer;
410}
411
378/* Add timer to timer list */ 412/* Add timer to timer list */
379void fsl_otg_add_timer(struct otg_fsm *fsm, void *gtimer) 413void fsl_otg_add_timer(struct otg_fsm *fsm, void *gtimer)
380{ 414{
@@ -394,6 +428,17 @@ void fsl_otg_add_timer(struct otg_fsm *fsm, void *gtimer)
394 list_add_tail(&timer->list, &active_timers); 428 list_add_tail(&timer->list, &active_timers);
395} 429}
396 430
431static void fsl_otg_fsm_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer t)
432{
433 struct fsl_otg_timer *timer;
434
435 timer = fsl_otg_get_timer(t);
436 if (!timer)
437 return;
438
439 fsl_otg_add_timer(fsm, timer);
440}
441
397/* Remove timer from the timer list; clear timeout status */ 442/* Remove timer from the timer list; clear timeout status */
398void fsl_otg_del_timer(struct otg_fsm *fsm, void *gtimer) 443void fsl_otg_del_timer(struct otg_fsm *fsm, void *gtimer)
399{ 444{
@@ -405,6 +450,17 @@ void fsl_otg_del_timer(struct otg_fsm *fsm, void *gtimer)
405 list_del(&timer->list); 450 list_del(&timer->list);
406} 451}
407 452
453static void fsl_otg_fsm_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer t)
454{
455 struct fsl_otg_timer *timer;
456
457 timer = fsl_otg_get_timer(t);
458 if (!timer)
459 return;
460
461 fsl_otg_del_timer(fsm, timer);
462}
463
408/* 464/*
409 * Reduce timer count by 1, and find timeout conditions. 465 * Reduce timer count by 1, and find timeout conditions.
410 * Called by fsl_otg 1ms timer interrupt 466 * Called by fsl_otg 1ms timer interrupt
@@ -757,8 +813,8 @@ static struct otg_fsm_ops fsl_otg_ops = {
757 .loc_sof = fsl_otg_loc_sof, 813 .loc_sof = fsl_otg_loc_sof,
758 .start_pulse = fsl_otg_start_pulse, 814 .start_pulse = fsl_otg_start_pulse,
759 815
760 .add_timer = fsl_otg_add_timer, 816 .add_timer = fsl_otg_fsm_add_timer,
761 .del_timer = fsl_otg_del_timer, 817 .del_timer = fsl_otg_fsm_del_timer,
762 818
763 .start_host = fsl_otg_start_host, 819 .start_host = fsl_otg_start_host,
764 .start_gadget = fsl_otg_start_gadget, 820 .start_gadget = fsl_otg_start_gadget,
diff --git a/drivers/usb/phy/phy-fsm-usb.c b/drivers/usb/phy/phy-fsm-usb.c
index 78984591ee74..f8fe7ec620e6 100644
--- a/drivers/usb/phy/phy-fsm-usb.c
+++ b/drivers/usb/phy/phy-fsm-usb.c
@@ -69,7 +69,7 @@ void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state)
69{ 69{
70 switch (old_state) { 70 switch (old_state) {
71 case OTG_STATE_B_IDLE: 71 case OTG_STATE_B_IDLE:
72 otg_del_timer(fsm, b_se0_srp_tmr); 72 otg_del_timer(fsm, B_SE0_SRP);
73 fsm->b_se0_srp = 0; 73 fsm->b_se0_srp = 0;
74 break; 74 break;
75 case OTG_STATE_B_SRP_INIT: 75 case OTG_STATE_B_SRP_INIT:
@@ -78,7 +78,7 @@ void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state)
78 case OTG_STATE_B_PERIPHERAL: 78 case OTG_STATE_B_PERIPHERAL:
79 break; 79 break;
80 case OTG_STATE_B_WAIT_ACON: 80 case OTG_STATE_B_WAIT_ACON:
81 otg_del_timer(fsm, b_ase0_brst_tmr); 81 otg_del_timer(fsm, B_ASE0_BRST);
82 fsm->b_ase0_brst_tmout = 0; 82 fsm->b_ase0_brst_tmout = 0;
83 break; 83 break;
84 case OTG_STATE_B_HOST: 84 case OTG_STATE_B_HOST:
@@ -86,25 +86,25 @@ void otg_leave_state(struct otg_fsm *fsm, enum usb_otg_state old_state)
86 case OTG_STATE_A_IDLE: 86 case OTG_STATE_A_IDLE:
87 break; 87 break;
88 case OTG_STATE_A_WAIT_VRISE: 88 case OTG_STATE_A_WAIT_VRISE:
89 otg_del_timer(fsm, a_wait_vrise_tmr); 89 otg_del_timer(fsm, A_WAIT_VRISE);
90 fsm->a_wait_vrise_tmout = 0; 90 fsm->a_wait_vrise_tmout = 0;
91 break; 91 break;
92 case OTG_STATE_A_WAIT_BCON: 92 case OTG_STATE_A_WAIT_BCON:
93 otg_del_timer(fsm, a_wait_bcon_tmr); 93 otg_del_timer(fsm, A_WAIT_BCON);
94 fsm->a_wait_bcon_tmout = 0; 94 fsm->a_wait_bcon_tmout = 0;
95 break; 95 break;
96 case OTG_STATE_A_HOST: 96 case OTG_STATE_A_HOST:
97 otg_del_timer(fsm, a_wait_enum_tmr); 97 otg_del_timer(fsm, A_WAIT_ENUM);
98 break; 98 break;
99 case OTG_STATE_A_SUSPEND: 99 case OTG_STATE_A_SUSPEND:
100 otg_del_timer(fsm, a_aidl_bdis_tmr); 100 otg_del_timer(fsm, A_AIDL_BDIS);
101 fsm->a_aidl_bdis_tmout = 0; 101 fsm->a_aidl_bdis_tmout = 0;
102 fsm->a_suspend_req = 0; 102 fsm->a_suspend_req = 0;
103 break; 103 break;
104 case OTG_STATE_A_PERIPHERAL: 104 case OTG_STATE_A_PERIPHERAL:
105 break; 105 break;
106 case OTG_STATE_A_WAIT_VFALL: 106 case OTG_STATE_A_WAIT_VFALL:
107 otg_del_timer(fsm, a_wait_vrise_tmr); 107 otg_del_timer(fsm, A_WAIT_VRISE);
108 break; 108 break;
109 case OTG_STATE_A_VBUS_ERR: 109 case OTG_STATE_A_VBUS_ERR:
110 break; 110 break;
@@ -128,13 +128,13 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
128 otg_loc_conn(fsm, 0); 128 otg_loc_conn(fsm, 0);
129 otg_loc_sof(fsm, 0); 129 otg_loc_sof(fsm, 0);
130 otg_set_protocol(fsm, PROTO_UNDEF); 130 otg_set_protocol(fsm, PROTO_UNDEF);
131 otg_add_timer(fsm, b_se0_srp_tmr); 131 otg_add_timer(fsm, B_SE0_SRP);
132 break; 132 break;
133 case OTG_STATE_B_SRP_INIT: 133 case OTG_STATE_B_SRP_INIT:
134 otg_start_pulse(fsm); 134 otg_start_pulse(fsm);
135 otg_loc_sof(fsm, 0); 135 otg_loc_sof(fsm, 0);
136 otg_set_protocol(fsm, PROTO_UNDEF); 136 otg_set_protocol(fsm, PROTO_UNDEF);
137 otg_add_timer(fsm, b_srp_fail_tmr); 137 otg_add_timer(fsm, B_SRP_FAIL);
138 break; 138 break;
139 case OTG_STATE_B_PERIPHERAL: 139 case OTG_STATE_B_PERIPHERAL:
140 otg_chrg_vbus(fsm, 0); 140 otg_chrg_vbus(fsm, 0);
@@ -147,7 +147,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
147 otg_loc_conn(fsm, 0); 147 otg_loc_conn(fsm, 0);
148 otg_loc_sof(fsm, 0); 148 otg_loc_sof(fsm, 0);
149 otg_set_protocol(fsm, PROTO_HOST); 149 otg_set_protocol(fsm, PROTO_HOST);
150 otg_add_timer(fsm, b_ase0_brst_tmr); 150 otg_add_timer(fsm, B_ASE0_BRST);
151 fsm->a_bus_suspend = 0; 151 fsm->a_bus_suspend = 0;
152 break; 152 break;
153 case OTG_STATE_B_HOST: 153 case OTG_STATE_B_HOST:
@@ -170,14 +170,14 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
170 otg_loc_conn(fsm, 0); 170 otg_loc_conn(fsm, 0);
171 otg_loc_sof(fsm, 0); 171 otg_loc_sof(fsm, 0);
172 otg_set_protocol(fsm, PROTO_HOST); 172 otg_set_protocol(fsm, PROTO_HOST);
173 otg_add_timer(fsm, a_wait_vrise_tmr); 173 otg_add_timer(fsm, A_WAIT_VRISE);
174 break; 174 break;
175 case OTG_STATE_A_WAIT_BCON: 175 case OTG_STATE_A_WAIT_BCON:
176 otg_drv_vbus(fsm, 1); 176 otg_drv_vbus(fsm, 1);
177 otg_loc_conn(fsm, 0); 177 otg_loc_conn(fsm, 0);
178 otg_loc_sof(fsm, 0); 178 otg_loc_sof(fsm, 0);
179 otg_set_protocol(fsm, PROTO_HOST); 179 otg_set_protocol(fsm, PROTO_HOST);
180 otg_add_timer(fsm, a_wait_bcon_tmr); 180 otg_add_timer(fsm, A_WAIT_BCON);
181 break; 181 break;
182 case OTG_STATE_A_HOST: 182 case OTG_STATE_A_HOST:
183 otg_drv_vbus(fsm, 1); 183 otg_drv_vbus(fsm, 1);
@@ -189,14 +189,14 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
189 * suspend too fast to complete a_set_b_hnp_en 189 * suspend too fast to complete a_set_b_hnp_en
190 */ 190 */
191 if (!fsm->a_bus_req || fsm->a_suspend_req) 191 if (!fsm->a_bus_req || fsm->a_suspend_req)
192 otg_add_timer(fsm, a_wait_enum_tmr); 192 otg_add_timer(fsm, A_WAIT_ENUM);
193 break; 193 break;
194 case OTG_STATE_A_SUSPEND: 194 case OTG_STATE_A_SUSPEND:
195 otg_drv_vbus(fsm, 1); 195 otg_drv_vbus(fsm, 1);
196 otg_loc_conn(fsm, 0); 196 otg_loc_conn(fsm, 0);
197 otg_loc_sof(fsm, 0); 197 otg_loc_sof(fsm, 0);
198 otg_set_protocol(fsm, PROTO_HOST); 198 otg_set_protocol(fsm, PROTO_HOST);
199 otg_add_timer(fsm, a_aidl_bdis_tmr); 199 otg_add_timer(fsm, A_AIDL_BDIS);
200 200
201 break; 201 break;
202 case OTG_STATE_A_PERIPHERAL: 202 case OTG_STATE_A_PERIPHERAL:
diff --git a/drivers/usb/phy/phy-fsm-usb.h b/drivers/usb/phy/phy-fsm-usb.h
index 157f10672767..b47b32c6ed1f 100644
--- a/drivers/usb/phy/phy-fsm-usb.h
+++ b/drivers/usb/phy/phy-fsm-usb.h
@@ -34,6 +34,17 @@
34#define PROTO_HOST (1) 34#define PROTO_HOST (1)
35#define PROTO_GADGET (2) 35#define PROTO_GADGET (2)
36 36
37enum otg_fsm_timer {
38 A_WAIT_VRISE,
39 A_WAIT_BCON,
40 A_AIDL_BDIS,
41 B_ASE0_BRST,
42 B_SE0_SRP,
43 B_SRP_FAIL,
44 A_WAIT_ENUM,
45 NUM_OTG_FSM_TIMERS,
46};
47
37/* OTG state machine according to the OTG spec */ 48/* OTG state machine according to the OTG spec */
38struct otg_fsm { 49struct otg_fsm {
39 /* Input */ 50 /* Input */
@@ -88,8 +99,8 @@ struct otg_fsm_ops {
88 void (*loc_conn)(struct otg_fsm *fsm, int on); 99 void (*loc_conn)(struct otg_fsm *fsm, int on);
89 void (*loc_sof)(struct otg_fsm *fsm, int on); 100 void (*loc_sof)(struct otg_fsm *fsm, int on);
90 void (*start_pulse)(struct otg_fsm *fsm); 101 void (*start_pulse)(struct otg_fsm *fsm);
91 void (*add_timer)(struct otg_fsm *fsm, void *timer); 102 void (*add_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
92 void (*del_timer)(struct otg_fsm *fsm, void *timer); 103 void (*del_timer)(struct otg_fsm *fsm, enum otg_fsm_timer timer);
93 int (*start_host)(struct otg_fsm *fsm, int on); 104 int (*start_host)(struct otg_fsm *fsm, int on);
94 int (*start_gadget)(struct otg_fsm *fsm, int on); 105 int (*start_gadget)(struct otg_fsm *fsm, int on);
95}; 106};
@@ -144,7 +155,7 @@ static inline int otg_start_pulse(struct otg_fsm *fsm)
144 return 0; 155 return 0;
145} 156}
146 157
147static inline int otg_add_timer(struct otg_fsm *fsm, void *timer) 158static inline int otg_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
148{ 159{
149 if (!fsm->ops->add_timer) 160 if (!fsm->ops->add_timer)
150 return -EOPNOTSUPP; 161 return -EOPNOTSUPP;
@@ -152,7 +163,7 @@ static inline int otg_add_timer(struct otg_fsm *fsm, void *timer)
152 return 0; 163 return 0;
153} 164}
154 165
155static inline int otg_del_timer(struct otg_fsm *fsm, void *timer) 166static inline int otg_del_timer(struct otg_fsm *fsm, enum otg_fsm_timer timer)
156{ 167{
157 if (!fsm->ops->del_timer) 168 if (!fsm->ops->del_timer)
158 return -EOPNOTSUPP; 169 return -EOPNOTSUPP;
@@ -175,8 +186,3 @@ static inline int otg_start_gadget(struct otg_fsm *fsm, int on)
175} 186}
176 187
177int otg_statemachine(struct otg_fsm *fsm); 188int otg_statemachine(struct otg_fsm *fsm);
178
179/* Defined by device specific driver, for different timer implementation */
180extern struct fsl_otg_timer *a_wait_vrise_tmr, *a_wait_bcon_tmr,
181 *a_aidl_bdis_tmr, *b_ase0_brst_tmr, *b_se0_srp_tmr, *b_srp_fail_tmr,
182 *a_wait_enum_tmr;