aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Jun <b47624@freescale.com>2014-04-23 03:56:49 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-04-24 15:56:35 -0400
commite287b67b00c8d5306e0fe6be1d597e23d8c4783e (patch)
tree1f4f7cf13851e8935b2ace664db06032b133bbbb
parent826cfe751f3e1faf4a63b65245f5ee3a7efeb763 (diff)
usb: chipidea: OTG fsm timers initialization
This patch adds OTG fsm timers initialization, which use controller's 1ms interrupt as timeout counter, also adds some local timers which are not in otg_fsm_timer list. Signed-off-by: Peter Chen <peter.chen@freescale.com> Signed-off-by: Li Jun <b47624@freescale.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/chipidea/bits.h1
-rw-r--r--drivers/usb/chipidea/otg_fsm.c189
-rw-r--r--drivers/usb/chipidea/otg_fsm.h51
3 files changed, 241 insertions, 0 deletions
diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
index 44882c8133d6..ca57e3dcd3d5 100644
--- a/drivers/usb/chipidea/bits.h
+++ b/drivers/usb/chipidea/bits.h
@@ -81,6 +81,7 @@
81/* OTGSC */ 81/* OTGSC */
82#define OTGSC_IDPU BIT(5) 82#define OTGSC_IDPU BIT(5)
83#define OTGSC_HADP BIT(6) 83#define OTGSC_HADP BIT(6)
84#define OTGSC_HABA BIT(7)
84#define OTGSC_ID BIT(8) 85#define OTGSC_ID BIT(8)
85#define OTGSC_AVV BIT(9) 86#define OTGSC_AVV BIT(9)
86#define OTGSC_ASV BIT(10) 87#define OTGSC_ASV BIT(10)
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index 5afeb59acaa6..bb64fb486eef 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -26,6 +26,22 @@
26#include "otg.h" 26#include "otg.h"
27#include "otg_fsm.h" 27#include "otg_fsm.h"
28 28
29static struct ci_otg_fsm_timer *otg_timer_initializer
30(struct ci_hdrc *ci, void (*function)(void *, unsigned long),
31 unsigned long expires, unsigned long data)
32{
33 struct ci_otg_fsm_timer *timer;
34
35 timer = devm_kzalloc(ci->dev, sizeof(struct ci_otg_fsm_timer),
36 GFP_KERNEL);
37 if (!timer)
38 return NULL;
39 timer->function = function;
40 timer->expires = expires;
41 timer->data = data;
42 return timer;
43}
44
29/* 45/*
30 * Add timer to active timer list 46 * Add timer to active timer list
31 */ 47 */
@@ -77,6 +93,163 @@ static void ci_otg_del_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t)
77 hw_write_otgsc(ci, OTGSC_1MSIE, 0); 93 hw_write_otgsc(ci, OTGSC_1MSIE, 0);
78} 94}
79 95
96/* The timeout callback function to set time out bit */
97static void set_tmout(void *ptr, unsigned long indicator)
98{
99 *(int *)indicator = 1;
100}
101
102static void set_tmout_and_fsm(void *ptr, unsigned long indicator)
103{
104 struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
105
106 set_tmout(ci, indicator);
107
108 disable_irq_nosync(ci->irq);
109 queue_work(ci->wq, &ci->work);
110}
111
112static void a_wait_vfall_tmout_func(void *ptr, unsigned long indicator)
113{
114 struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
115
116 set_tmout(ci, indicator);
117 /* Disable port power */
118 hw_write(ci, OP_PORTSC, PORTSC_W1C_BITS | PORTSC_PP, 0);
119 /* Clear exsiting DP irq */
120 hw_write_otgsc(ci, OTGSC_DPIS, OTGSC_DPIS);
121 /* Enable data pulse irq */
122 hw_write_otgsc(ci, OTGSC_DPIE, OTGSC_DPIE);
123 disable_irq_nosync(ci->irq);
124 queue_work(ci->wq, &ci->work);
125}
126
127static void b_ase0_brst_tmout_func(void *ptr, unsigned long indicator)
128{
129 struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
130
131 set_tmout(ci, indicator);
132 if (!hw_read_otgsc(ci, OTGSC_BSV))
133 ci->fsm.b_sess_vld = 0;
134
135 disable_irq_nosync(ci->irq);
136 queue_work(ci->wq, &ci->work);
137}
138
139static void b_ssend_srp_tmout_func(void *ptr, unsigned long indicator)
140{
141 struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
142
143 set_tmout(ci, indicator);
144
145 /* only vbus fall below B_sess_vld in b_idle state */
146 if (ci->transceiver->state == OTG_STATE_B_IDLE) {
147 disable_irq_nosync(ci->irq);
148 queue_work(ci->wq, &ci->work);
149 }
150}
151
152static void b_sess_vld_tmout_func(void *ptr, unsigned long indicator)
153{
154 struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
155
156 /* Check if A detached */
157 if (!(hw_read_otgsc(ci, OTGSC_BSV))) {
158 ci->fsm.b_sess_vld = 0;
159 ci_otg_add_timer(ci, B_SSEND_SRP);
160 disable_irq_nosync(ci->irq);
161 queue_work(ci->wq, &ci->work);
162 }
163}
164
165static void b_data_pulse_end(void *ptr, unsigned long indicator)
166{
167 struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
168
169 ci->fsm.b_srp_done = 1;
170 ci->fsm.b_bus_req = 0;
171 if (ci->fsm.power_up)
172 ci->fsm.power_up = 0;
173
174 hw_write_otgsc(ci, OTGSC_HABA, 0);
175
176 disable_irq_nosync(ci->irq);
177 queue_work(ci->wq, &ci->work);
178}
179
180/* Initialize timers */
181static int ci_otg_init_timers(struct ci_hdrc *ci)
182{
183 struct otg_fsm *fsm = &ci->fsm;
184
185 /* FSM used timers */
186 ci->fsm_timer->timer_list[A_WAIT_VRISE] =
187 otg_timer_initializer(ci, &set_tmout_and_fsm, TA_WAIT_VRISE,
188 (unsigned long)&fsm->a_wait_vrise_tmout);
189 if (ci->fsm_timer->timer_list[A_WAIT_VRISE] == NULL)
190 return -ENOMEM;
191
192 ci->fsm_timer->timer_list[A_WAIT_VFALL] =
193 otg_timer_initializer(ci, &a_wait_vfall_tmout_func,
194 TA_WAIT_VFALL, (unsigned long)&fsm->a_wait_vfall_tmout);
195 if (ci->fsm_timer->timer_list[A_WAIT_VFALL] == NULL)
196 return -ENOMEM;
197
198 ci->fsm_timer->timer_list[A_WAIT_BCON] =
199 otg_timer_initializer(ci, &set_tmout_and_fsm, TA_WAIT_BCON,
200 (unsigned long)&fsm->a_wait_bcon_tmout);
201 if (ci->fsm_timer->timer_list[A_WAIT_BCON] == NULL)
202 return -ENOMEM;
203
204 ci->fsm_timer->timer_list[A_AIDL_BDIS] =
205 otg_timer_initializer(ci, &set_tmout_and_fsm, TA_AIDL_BDIS,
206 (unsigned long)&fsm->a_aidl_bdis_tmout);
207 if (ci->fsm_timer->timer_list[A_AIDL_BDIS] == NULL)
208 return -ENOMEM;
209
210 ci->fsm_timer->timer_list[A_BIDL_ADIS] =
211 otg_timer_initializer(ci, &set_tmout_and_fsm, TA_BIDL_ADIS,
212 (unsigned long)&fsm->a_bidl_adis_tmout);
213 if (ci->fsm_timer->timer_list[A_BIDL_ADIS] == NULL)
214 return -ENOMEM;
215
216 ci->fsm_timer->timer_list[B_ASE0_BRST] =
217 otg_timer_initializer(ci, &b_ase0_brst_tmout_func, TB_ASE0_BRST,
218 (unsigned long)&fsm->b_ase0_brst_tmout);
219 if (ci->fsm_timer->timer_list[B_ASE0_BRST] == NULL)
220 return -ENOMEM;
221
222 ci->fsm_timer->timer_list[B_SE0_SRP] =
223 otg_timer_initializer(ci, &set_tmout_and_fsm, TB_SE0_SRP,
224 (unsigned long)&fsm->b_se0_srp);
225 if (ci->fsm_timer->timer_list[B_SE0_SRP] == NULL)
226 return -ENOMEM;
227
228 ci->fsm_timer->timer_list[B_SSEND_SRP] =
229 otg_timer_initializer(ci, &b_ssend_srp_tmout_func, TB_SSEND_SRP,
230 (unsigned long)&fsm->b_ssend_srp);
231 if (ci->fsm_timer->timer_list[B_SSEND_SRP] == NULL)
232 return -ENOMEM;
233
234 ci->fsm_timer->timer_list[B_SRP_FAIL] =
235 otg_timer_initializer(ci, &set_tmout, TB_SRP_FAIL,
236 (unsigned long)&fsm->b_srp_done);
237 if (ci->fsm_timer->timer_list[B_SRP_FAIL] == NULL)
238 return -ENOMEM;
239
240 ci->fsm_timer->timer_list[B_DATA_PLS] =
241 otg_timer_initializer(ci, &b_data_pulse_end, TB_DATA_PLS, 0);
242 if (ci->fsm_timer->timer_list[B_DATA_PLS] == NULL)
243 return -ENOMEM;
244
245 ci->fsm_timer->timer_list[B_SESS_VLD] = otg_timer_initializer(ci,
246 &b_sess_vld_tmout_func, TB_SESS_VLD, 0);
247 if (ci->fsm_timer->timer_list[B_SESS_VLD] == NULL)
248 return -ENOMEM;
249
250 return 0;
251}
252
80/* -------------------------------------------------------------*/ 253/* -------------------------------------------------------------*/
81/* Operations that will be called from OTG Finite State Machine */ 254/* Operations that will be called from OTG Finite State Machine */
82/* -------------------------------------------------------------*/ 255/* -------------------------------------------------------------*/
@@ -223,6 +396,7 @@ static struct otg_fsm_ops ci_otg_ops = {
223 396
224int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci) 397int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
225{ 398{
399 int retval = 0;
226 struct usb_otg *otg; 400 struct usb_otg *otg;
227 401
228 otg = devm_kzalloc(ci->dev, 402 otg = devm_kzalloc(ci->dev,
@@ -244,6 +418,21 @@ int ci_hdrc_otg_fsm_init(struct ci_hdrc *ci)
244 418
245 mutex_init(&ci->fsm.lock); 419 mutex_init(&ci->fsm.lock);
246 420
421 ci->fsm_timer = devm_kzalloc(ci->dev,
422 sizeof(struct ci_otg_fsm_timer_list), GFP_KERNEL);
423 if (!ci->fsm_timer) {
424 dev_err(ci->dev,
425 "Failed to allocate timer structure for ci hdrc otg!\n");
426 return -ENOMEM;
427 }
428
429 INIT_LIST_HEAD(&ci->fsm_timer->active_timers);
430 retval = ci_otg_init_timers(ci);
431 if (retval) {
432 dev_err(ci->dev, "Couldn't init OTG timers\n");
433 return retval;
434 }
435
247 /* Enable A vbus valid irq */ 436 /* Enable A vbus valid irq */
248 hw_write_otgsc(ci, OTGSC_AVVIE, OTGSC_AVVIE); 437 hw_write_otgsc(ci, OTGSC_AVVIE, OTGSC_AVVIE);
249 438
diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h
index 4d0dfe6900d6..420f081e7e6a 100644
--- a/drivers/usb/chipidea/otg_fsm.h
+++ b/drivers/usb/chipidea/otg_fsm.h
@@ -13,6 +13,57 @@
13 13
14#include <linux/usb/otg-fsm.h> 14#include <linux/usb/otg-fsm.h>
15 15
16/*
17 * A-DEVICE timing constants
18 */
19
20/* Wait for VBUS Rise */
21#define TA_WAIT_VRISE (100) /* a_wait_vrise: section 7.1.2
22 * a_wait_vrise_tmr: section 7.4.5.1
23 * TA_VBUS_RISE <= 100ms, section 4.4
24 * Table 4-1: Electrical Characteristics
25 * ->DC Electrical Timing
26 */
27/* Wait for VBUS Fall */
28#define TA_WAIT_VFALL (1000) /* a_wait_vfall: section 7.1.7
29 * a_wait_vfall_tmr: section: 7.4.5.2
30 */
31/* Wait for B-Connect */
32#define TA_WAIT_BCON (10000) /* a_wait_bcon: section 7.1.3
33 * TA_WAIT_BCON: should be between 1100
34 * and 30000 ms, section 5.5, Table 5-1
35 */
36/* A-Idle to B-Disconnect */
37#define TA_AIDL_BDIS (5000) /* a_suspend min 200 ms, section 5.2.1
38 * TA_AIDL_BDIS: section 5.5, Table 5-1
39 */
40/* B-Idle to A-Disconnect */
41#define TA_BIDL_ADIS (500) /* TA_BIDL_ADIS: section 5.2.1
42 * 500ms is used for B switch to host
43 * for safe
44 */
45
46/*
47 * B-device timing constants
48 */
49
50/* Data-Line Pulse Time*/
51#define TB_DATA_PLS (10) /* b_srp_init,continue 5~10ms
52 * section:5.1.3
53 */
54/* SRP Fail Time */
55#define TB_SRP_FAIL (6000) /* b_srp_init,fail time 5~6s
56 * section:5.1.6
57 */
58/* A-SE0 to B-Reset */
59#define TB_ASE0_BRST (155) /* minimum 155 ms, section:5.3.1 */
60/* SE0 Time Before SRP */
61#define TB_SE0_SRP (1000) /* b_idle,minimum 1s, section:5.1.2 */
62/* SSEND time before SRP */
63#define TB_SSEND_SRP (1500) /* minimum 1.5 sec, section:5.1.2 */
64
65#define TB_SESS_VLD (1000)
66
16enum ci_otg_fsm_timer_index { 67enum ci_otg_fsm_timer_index {
17 /* 68 /*
18 * CI specific timers, start from the end 69 * CI specific timers, start from the end