blob: 8b40726ba9661ac939a6ee105f756c4c98899339 [file] [log] [blame]
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +09001/*
2 * Renesas USB driver
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 */
17#include <linux/delay.h>
18#include <linux/io.h>
Rafael J. Wysocki9c646cf2011-07-26 20:51:01 +020019#include <linux/scatterlist.h>
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +090020#include "./common.h"
21#include "./pipe.h"
22
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090023#define usbhsf_get_cfifo(p) (&((p)->fifo_info.cfifo))
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090024#define usbhsf_get_d0fifo(p) (&((p)->fifo_info.d0fifo))
25#define usbhsf_get_d1fifo(p) (&((p)->fifo_info.d1fifo))
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090026
Kuninori Morimotod77e3f42011-06-06 14:18:50 +090027#define usbhsf_fifo_is_busy(f) ((f)->pipe) /* see usbhs_pipe_select_fifo */
28
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +090029/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -070030 * packet initialize
31 */
32void usbhs_pkt_init(struct usbhs_pkt *pkt)
33{
34 pkt->dma = DMA_ADDR_INVALID;
35 INIT_LIST_HEAD(&pkt->node);
36}
37
38/*
39 * packet control function
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090040 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +090041static int usbhsf_null_handle(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotodad67392011-06-06 14:18:28 +090042{
43 struct usbhs_priv *priv = usbhs_pipe_to_priv(pkt->pipe);
44 struct device *dev = usbhs_priv_to_dev(priv);
45
46 dev_err(dev, "null handler\n");
47
48 return -EINVAL;
49}
50
51static struct usbhs_pkt_handle usbhsf_null_handler = {
52 .prepare = usbhsf_null_handle,
53 .try_run = usbhsf_null_handle,
54};
55
Kuninori Morimoto659d4952011-06-06 14:18:23 +090056void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
Kuninori Morimotob3318722011-10-10 22:04:41 -070057 void (*done)(struct usbhs_priv *priv,
58 struct usbhs_pkt *pkt),
Kuninori Morimoto659d4952011-06-06 14:18:23 +090059 void *buf, int len, int zero)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090060{
Kuninori Morimotodad67392011-06-06 14:18:28 +090061 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
62 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimoto97664a22011-06-06 14:18:38 +090063 unsigned long flags;
64
65 /******************** spin lock ********************/
66 usbhs_lock(priv, flags);
Kuninori Morimotodad67392011-06-06 14:18:28 +090067
Kuninori Morimotob3318722011-10-10 22:04:41 -070068 if (!done) {
69 dev_err(dev, "no done function\n");
70 return;
71 }
72
Kuninori Morimoto0c6ef982011-10-10 22:00:59 -070073 if (!pipe->handler) {
Kuninori Morimotodad67392011-06-06 14:18:28 +090074 dev_err(dev, "no handler function\n");
Kuninori Morimoto0c6ef982011-10-10 22:00:59 -070075 pipe->handler = &usbhsf_null_handler;
Kuninori Morimotodad67392011-06-06 14:18:28 +090076 }
77
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090078 list_del_init(&pkt->node);
79 list_add_tail(&pkt->node, &pipe->list);
80
Kuninori Morimoto0c6ef982011-10-10 22:00:59 -070081 /*
82 * each pkt must hold own handler.
83 * because handler might be changed by its situation.
84 * dma handler -> pio handler.
85 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +090086 pkt->pipe = pipe;
87 pkt->buf = buf;
Kuninori Morimoto0c6ef982011-10-10 22:00:59 -070088 pkt->handler = pipe->handler;
Kuninori Morimoto659d4952011-06-06 14:18:23 +090089 pkt->length = len;
90 pkt->zero = zero;
91 pkt->actual = 0;
Kuninori Morimotob3318722011-10-10 22:04:41 -070092 pkt->done = done;
Kuninori Morimoto97664a22011-06-06 14:18:38 +090093
94 usbhs_unlock(priv, flags);
95 /******************** spin unlock ******************/
Kuninori Morimoto0432eed2011-06-06 14:18:54 +090096
97 usbhs_pkt_start(pipe);
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090098}
99
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900100static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +0900101{
102 list_del_init(&pkt->node);
103}
104
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900105static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +0900106{
107 if (list_empty(&pipe->list))
108 return NULL;
109
110 return list_entry(pipe->list.next, struct usbhs_pkt, node);
111}
112
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900113struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt)
114{
115 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
116 unsigned long flags;
117
118 /******************** spin lock ********************/
119 usbhs_lock(priv, flags);
120
121 if (!pkt)
122 pkt = __usbhsf_pkt_get(pipe);
123
124 if (pkt)
125 __usbhsf_pkt_del(pkt);
126
127 usbhs_unlock(priv, flags);
128 /******************** spin unlock ******************/
129
130 return pkt;
131}
132
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700133enum {
134 USBHSF_PKT_PREPARE,
135 USBHSF_PKT_TRY_RUN,
136 USBHSF_PKT_DMA_DONE,
137};
138
139static int usbhsf_pkt_handler(struct usbhs_pipe *pipe, int type)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900140{
141 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900142 struct usbhs_pkt *pkt;
143 struct device *dev = usbhs_priv_to_dev(priv);
144 int (*func)(struct usbhs_pkt *pkt, int *is_done);
145 unsigned long flags;
146 int ret = 0;
147 int is_done = 0;
148
149 /******************** spin lock ********************/
150 usbhs_lock(priv, flags);
151
152 pkt = __usbhsf_pkt_get(pipe);
153 if (!pkt)
154 goto __usbhs_pkt_handler_end;
155
156 switch (type) {
157 case USBHSF_PKT_PREPARE:
158 func = pkt->handler->prepare;
159 break;
160 case USBHSF_PKT_TRY_RUN:
161 func = pkt->handler->try_run;
162 break;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900163 case USBHSF_PKT_DMA_DONE:
164 func = pkt->handler->dma_done;
165 break;
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900166 default:
167 dev_err(dev, "unknown pkt hander\n");
168 goto __usbhs_pkt_handler_end;
169 }
170
171 ret = func(pkt, &is_done);
172
173 if (is_done)
174 __usbhsf_pkt_del(pkt);
175
176__usbhs_pkt_handler_end:
177 usbhs_unlock(priv, flags);
178 /******************** spin unlock ******************/
179
Kuninori Morimoto0432eed2011-06-06 14:18:54 +0900180 if (is_done) {
Kuninori Morimotob3318722011-10-10 22:04:41 -0700181 pkt->done(priv, pkt);
Kuninori Morimoto0432eed2011-06-06 14:18:54 +0900182 usbhs_pkt_start(pipe);
183 }
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900184
185 return ret;
186}
187
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700188void usbhs_pkt_start(struct usbhs_pipe *pipe)
189{
190 usbhsf_pkt_handler(pipe, USBHSF_PKT_PREPARE);
191}
192
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900193/*
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900194 * irq enable/disable function
195 */
196#define usbhsf_irq_empty_ctrl(p, e) usbhsf_irq_callback_ctrl(p, bempsts, e)
197#define usbhsf_irq_ready_ctrl(p, e) usbhsf_irq_callback_ctrl(p, brdysts, e)
198#define usbhsf_irq_callback_ctrl(pipe, status, enable) \
199 ({ \
200 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); \
201 struct usbhs_mod *mod = usbhs_mod_get_current(priv); \
202 u16 status = (1 << usbhs_pipe_number(pipe)); \
203 if (!mod) \
204 return; \
205 if (enable) \
206 mod->irq_##status |= status; \
207 else \
208 mod->irq_##status &= ~status; \
209 usbhs_irq_callback_update(priv, mod); \
210 })
211
212static void usbhsf_tx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
213{
214 /*
215 * And DCP pipe can NOT use "ready interrupt" for "send"
216 * it should use "empty" interrupt.
217 * see
218 * "Operation" - "Interrupt Function" - "BRDY Interrupt"
219 *
220 * on the other hand, normal pipe can use "ready interrupt" for "send"
221 * even though it is single/double buffer
222 */
223 if (usbhs_pipe_is_dcp(pipe))
224 usbhsf_irq_empty_ctrl(pipe, enable);
225 else
226 usbhsf_irq_ready_ctrl(pipe, enable);
227}
228
229static void usbhsf_rx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
230{
231 usbhsf_irq_ready_ctrl(pipe, enable);
232}
233
234/*
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900235 * FIFO ctrl
236 */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900237static void usbhsf_send_terminator(struct usbhs_pipe *pipe,
238 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900239{
240 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
241
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900242 usbhs_bset(priv, fifo->ctr, BVAL, BVAL);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900243}
244
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900245static int usbhsf_fifo_barrier(struct usbhs_priv *priv,
246 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900247{
248 int timeout = 1024;
249
250 do {
251 /* The FIFO port is accessible */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900252 if (usbhs_read(priv, fifo->ctr) & FRDY)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900253 return 0;
254
255 udelay(10);
256 } while (timeout--);
257
258 return -EBUSY;
259}
260
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900261static void usbhsf_fifo_clear(struct usbhs_pipe *pipe,
262 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900263{
264 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
265
266 if (!usbhs_pipe_is_dcp(pipe))
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900267 usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900268
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900269 usbhs_write(priv, fifo->ctr, BCLR);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900270}
271
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900272static int usbhsf_fifo_rcv_len(struct usbhs_priv *priv,
273 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900274{
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900275 return usbhs_read(priv, fifo->ctr) & DTLN_MASK;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900276}
277
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900278static void usbhsf_fifo_unselect(struct usbhs_pipe *pipe,
279 struct usbhs_fifo *fifo)
280{
281 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
282
283 usbhs_pipe_select_fifo(pipe, NULL);
284 usbhs_write(priv, fifo->sel, 0);
285}
286
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900287static int usbhsf_fifo_select(struct usbhs_pipe *pipe,
288 struct usbhs_fifo *fifo,
289 int write)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900290{
291 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
292 struct device *dev = usbhs_priv_to_dev(priv);
293 int timeout = 1024;
294 u16 mask = ((1 << 5) | 0xF); /* mask of ISEL | CURPIPE */
295 u16 base = usbhs_pipe_number(pipe); /* CURPIPE */
296
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900297 if (usbhs_pipe_is_busy(pipe) ||
298 usbhsf_fifo_is_busy(fifo))
299 return -EBUSY;
300
Kuninori Morimoto92352072011-10-10 22:02:57 -0700301 if (usbhs_pipe_is_dcp(pipe)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900302 base |= (1 == write) << 5; /* ISEL */
303
Kuninori Morimoto92352072011-10-10 22:02:57 -0700304 if (usbhs_mod_is_host(priv))
305 usbhs_dcp_dir_for_host(pipe, write);
306 }
307
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900308 /* "base" will be used below */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900309 usbhs_write(priv, fifo->sel, base | MBW_32);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900310
311 /* check ISEL and CURPIPE value */
312 while (timeout--) {
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900313 if (base == (mask & usbhs_read(priv, fifo->sel))) {
314 usbhs_pipe_select_fifo(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900315 return 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900316 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900317 udelay(10);
318 }
319
320 dev_err(dev, "fifo select error\n");
321
322 return -EIO;
323}
324
325/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700326 * PIO push handler
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900327 */
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900328static int usbhsf_pio_try_push(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900329{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900330 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900331 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900332 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900333 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
334 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900335 u8 *buf;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900336 int maxp = usbhs_pipe_get_maxpacket(pipe);
337 int total_len;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900338 int i, ret, len;
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900339 int is_short;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900340
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900341 ret = usbhsf_fifo_select(pipe, fifo, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900342 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900343 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900344
Kuninori Morimotodad67392011-06-06 14:18:28 +0900345 ret = usbhs_pipe_is_accessible(pipe);
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700346 if (ret < 0) {
347 /* inaccessible pipe is not an error */
348 ret = 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900349 goto usbhs_fifo_write_busy;
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700350 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900351
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900352 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900353 if (ret < 0)
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900354 goto usbhs_fifo_write_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900355
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900356 buf = pkt->buf + pkt->actual;
357 len = pkt->length - pkt->actual;
358 len = min(len, maxp);
359 total_len = len;
360 is_short = total_len < maxp;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900361
362 /*
363 * FIXME
364 *
365 * 32-bit access only
366 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900367 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900368 iowrite32_rep(addr, buf, len / 4);
369 len %= 4;
370 buf += total_len - len;
371 }
372
373 /* the rest operation */
374 for (i = 0; i < len; i++)
375 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
376
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900377 /*
378 * variable update
379 */
380 pkt->actual += total_len;
381
382 if (pkt->actual < pkt->length)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900383 *is_done = 0; /* there are remainder data */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900384 else if (is_short)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900385 *is_done = 1; /* short packet */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900386 else
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900387 *is_done = !pkt->zero; /* send zero packet ? */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900388
389 /*
390 * pipe/irq handling
391 */
392 if (is_short)
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900393 usbhsf_send_terminator(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900394
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900395 usbhsf_tx_irq_ctrl(pipe, !*is_done);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900396 usbhs_pipe_enable(pipe);
397
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900398 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
399 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900400 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900401
402 /*
403 * Transmission end
404 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900405 if (*is_done) {
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900406 if (usbhs_pipe_is_dcp(pipe))
407 usbhs_dcp_control_transfer_done(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900408 }
409
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900410 usbhsf_fifo_unselect(pipe, fifo);
411
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900412 return 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900413
414usbhs_fifo_write_busy:
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900415 usbhsf_fifo_unselect(pipe, fifo);
416
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900417 /*
418 * pipe is busy.
419 * retry in interrupt
420 */
421 usbhsf_tx_irq_ctrl(pipe, 1);
422
423 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900424}
425
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900426struct usbhs_pkt_handle usbhs_fifo_pio_push_handler = {
427 .prepare = usbhsf_pio_try_push,
428 .try_run = usbhsf_pio_try_push,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900429};
430
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700431/*
432 * PIO pop handler
433 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900434static int usbhsf_prepare_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900435{
Kuninori Morimotodad67392011-06-06 14:18:28 +0900436 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900437
438 if (usbhs_pipe_is_busy(pipe))
439 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900440
441 /*
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900442 * pipe enable to prepare packet receive
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900443 */
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900444
445 usbhs_pipe_enable(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900446 usbhsf_rx_irq_ctrl(pipe, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900447
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900448 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900449}
450
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900451static int usbhsf_pio_try_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900452{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900453 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900454 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900455 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900456 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
457 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900458 u8 *buf;
459 u32 data = 0;
460 int maxp = usbhs_pipe_get_maxpacket(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900461 int rcv_len, len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900462 int i, ret;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900463 int total_len = 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900464
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900465 ret = usbhsf_fifo_select(pipe, fifo, 0);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900466 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900467 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900468
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900469 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900470 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900471 goto usbhs_fifo_read_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900472
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900473 rcv_len = usbhsf_fifo_rcv_len(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900474
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900475 buf = pkt->buf + pkt->actual;
476 len = pkt->length - pkt->actual;
477 len = min(len, rcv_len);
478 total_len = len;
479
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900480 /*
481 * Buffer clear if Zero-Length packet
482 *
483 * see
484 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
485 */
486 if (0 == rcv_len) {
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900487 usbhsf_fifo_clear(pipe, fifo);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900488 goto usbhs_fifo_read_end;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900489 }
490
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900491 /*
492 * FIXME
493 *
494 * 32-bit access only
495 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900496 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900497 ioread32_rep(addr, buf, len / 4);
498 len %= 4;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900499 buf += total_len - len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900500 }
501
502 /* the rest operation */
503 for (i = 0; i < len; i++) {
504 if (!(i & 0x03))
505 data = ioread32(addr);
506
507 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
508 }
509
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900510 pkt->actual += total_len;
511
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900512usbhs_fifo_read_end:
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900513 if ((pkt->actual == pkt->length) || /* receive all data */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900514 (total_len < maxp)) { /* short packet */
515 *is_done = 1;
516 usbhsf_rx_irq_ctrl(pipe, 0);
517 usbhs_pipe_disable(pipe);
518 }
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900519
520 dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
521 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900522 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900523
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900524usbhs_fifo_read_busy:
525 usbhsf_fifo_unselect(pipe, fifo);
526
527 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900528}
Kuninori Morimotodad67392011-06-06 14:18:28 +0900529
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900530struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler = {
Kuninori Morimotodad67392011-06-06 14:18:28 +0900531 .prepare = usbhsf_prepare_pop,
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900532 .try_run = usbhsf_pio_try_pop,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900533};
534
535/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700536 * DCP ctrol statge handler
Kuninori Morimotodad67392011-06-06 14:18:28 +0900537 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900538static int usbhsf_ctrl_stage_end(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotodad67392011-06-06 14:18:28 +0900539{
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900540 usbhs_dcp_control_transfer_done(pkt->pipe);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900541
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900542 *is_done = 1;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900543
544 return 0;
545}
546
547struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler = {
548 .prepare = usbhsf_ctrl_stage_end,
549 .try_run = usbhsf_ctrl_stage_end,
550};
551
552/*
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900553 * DMA fifo functions
554 */
555static struct dma_chan *usbhsf_dma_chan_get(struct usbhs_fifo *fifo,
556 struct usbhs_pkt *pkt)
557{
558 if (&usbhs_fifo_dma_push_handler == pkt->handler)
559 return fifo->tx_chan;
560
561 if (&usbhs_fifo_dma_pop_handler == pkt->handler)
562 return fifo->rx_chan;
563
564 return NULL;
565}
566
567static struct usbhs_fifo *usbhsf_get_dma_fifo(struct usbhs_priv *priv,
568 struct usbhs_pkt *pkt)
569{
570 struct usbhs_fifo *fifo;
571
572 /* DMA :: D0FIFO */
573 fifo = usbhsf_get_d0fifo(priv);
574 if (usbhsf_dma_chan_get(fifo, pkt) &&
575 !usbhsf_fifo_is_busy(fifo))
576 return fifo;
577
578 /* DMA :: D1FIFO */
579 fifo = usbhsf_get_d1fifo(priv);
580 if (usbhsf_dma_chan_get(fifo, pkt) &&
581 !usbhsf_fifo_is_busy(fifo))
582 return fifo;
583
584 return NULL;
585}
586
587#define usbhsf_dma_start(p, f) __usbhsf_dma_ctrl(p, f, DREQE)
588#define usbhsf_dma_stop(p, f) __usbhsf_dma_ctrl(p, f, 0)
589static void __usbhsf_dma_ctrl(struct usbhs_pipe *pipe,
590 struct usbhs_fifo *fifo,
591 u16 dreqe)
592{
593 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
594
595 usbhs_bset(priv, fifo->sel, DREQE, dreqe);
596}
597
598#define usbhsf_dma_map(p) __usbhsf_dma_map_ctrl(p, 1)
599#define usbhsf_dma_unmap(p) __usbhsf_dma_map_ctrl(p, 0)
600static int __usbhsf_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
601{
602 struct usbhs_pipe *pipe = pkt->pipe;
603 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
604 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
605
606 return info->dma_map_ctrl(pkt, map);
607}
608
609static void usbhsf_dma_complete(void *arg);
610static void usbhsf_dma_prepare_tasklet(unsigned long data)
611{
612 struct usbhs_pkt *pkt = (struct usbhs_pkt *)data;
613 struct usbhs_pipe *pipe = pkt->pipe;
614 struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe);
615 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
616 struct scatterlist sg;
617 struct dma_async_tx_descriptor *desc;
618 struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt);
619 struct device *dev = usbhs_priv_to_dev(priv);
620 enum dma_data_direction dir;
621 dma_cookie_t cookie;
622
623 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
624
625 sg_init_table(&sg, 1);
626 sg_set_page(&sg, virt_to_page(pkt->dma),
627 pkt->length, offset_in_page(pkt->dma));
628 sg_dma_address(&sg) = pkt->dma + pkt->actual;
629 sg_dma_len(&sg) = pkt->trans;
630
631 desc = chan->device->device_prep_slave_sg(chan, &sg, 1, dir,
632 DMA_PREP_INTERRUPT |
633 DMA_CTRL_ACK);
634 if (!desc)
635 return;
636
637 desc->callback = usbhsf_dma_complete;
638 desc->callback_param = pipe;
639
640 cookie = desc->tx_submit(desc);
641 if (cookie < 0) {
642 dev_err(dev, "Failed to submit dma descriptor\n");
643 return;
644 }
645
646 dev_dbg(dev, " %s %d (%d/ %d)\n",
647 fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero);
648
649 usbhsf_dma_start(pipe, fifo);
650 dma_async_issue_pending(chan);
651}
652
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700653/*
654 * DMA push handler
655 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900656static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done)
657{
658 struct usbhs_pipe *pipe = pkt->pipe;
659 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
660 struct usbhs_fifo *fifo;
661 int len = pkt->length - pkt->actual;
662 int ret;
663
664 if (usbhs_pipe_is_busy(pipe))
665 return 0;
666
667 /* use PIO if packet is less than pio_dma_border or pipe is DCP */
668 if ((len < usbhs_get_dparam(priv, pio_dma_border)) ||
669 usbhs_pipe_is_dcp(pipe))
670 goto usbhsf_pio_prepare_push;
671
672 if (len % 4) /* 32bit alignment */
673 goto usbhsf_pio_prepare_push;
674
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700675 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
676 goto usbhsf_pio_prepare_push;
677
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900678 /* get enable DMA fifo */
679 fifo = usbhsf_get_dma_fifo(priv, pkt);
680 if (!fifo)
681 goto usbhsf_pio_prepare_push;
682
683 if (usbhsf_dma_map(pkt) < 0)
684 goto usbhsf_pio_prepare_push;
685
686 ret = usbhsf_fifo_select(pipe, fifo, 0);
687 if (ret < 0)
688 goto usbhsf_pio_prepare_push_unmap;
689
690 pkt->trans = len;
691
692 tasklet_init(&fifo->tasklet,
693 usbhsf_dma_prepare_tasklet,
694 (unsigned long)pkt);
695
696 tasklet_schedule(&fifo->tasklet);
697
698 return 0;
699
700usbhsf_pio_prepare_push_unmap:
701 usbhsf_dma_unmap(pkt);
702usbhsf_pio_prepare_push:
703 /*
704 * change handler to PIO
705 */
706 pkt->handler = &usbhs_fifo_pio_push_handler;
707
708 return pkt->handler->prepare(pkt, is_done);
709}
710
711static int usbhsf_dma_push_done(struct usbhs_pkt *pkt, int *is_done)
712{
713 struct usbhs_pipe *pipe = pkt->pipe;
714
715 pkt->actual = pkt->trans;
716
717 *is_done = !pkt->zero; /* send zero packet ? */
718
719 usbhsf_dma_stop(pipe, pipe->fifo);
720 usbhsf_dma_unmap(pkt);
721 usbhsf_fifo_unselect(pipe, pipe->fifo);
722
723 return 0;
724}
725
726struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = {
727 .prepare = usbhsf_dma_prepare_push,
728 .dma_done = usbhsf_dma_push_done,
729};
730
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700731/*
732 * DMA pop handler
733 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900734static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done)
735{
736 struct usbhs_pipe *pipe = pkt->pipe;
737 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
738 struct usbhs_fifo *fifo;
739 int len, ret;
740
741 if (usbhs_pipe_is_busy(pipe))
742 return 0;
743
744 if (usbhs_pipe_is_dcp(pipe))
745 goto usbhsf_pio_prepare_pop;
746
747 /* get enable DMA fifo */
748 fifo = usbhsf_get_dma_fifo(priv, pkt);
749 if (!fifo)
750 goto usbhsf_pio_prepare_pop;
751
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700752 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
753 goto usbhsf_pio_prepare_pop;
754
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900755 ret = usbhsf_fifo_select(pipe, fifo, 0);
756 if (ret < 0)
757 goto usbhsf_pio_prepare_pop;
758
759 /* use PIO if packet is less than pio_dma_border */
760 len = usbhsf_fifo_rcv_len(priv, fifo);
761 len = min(pkt->length - pkt->actual, len);
762 if (len % 4) /* 32bit alignment */
763 goto usbhsf_pio_prepare_pop_unselect;
764
765 if (len < usbhs_get_dparam(priv, pio_dma_border))
766 goto usbhsf_pio_prepare_pop_unselect;
767
768 ret = usbhsf_fifo_barrier(priv, fifo);
769 if (ret < 0)
770 goto usbhsf_pio_prepare_pop_unselect;
771
772 if (usbhsf_dma_map(pkt) < 0)
773 goto usbhsf_pio_prepare_pop_unselect;
774
775 /* DMA */
776
777 /*
778 * usbhs_fifo_dma_pop_handler :: prepare
779 * enabled irq to come here.
780 * but it is no longer needed for DMA. disable it.
781 */
782 usbhsf_rx_irq_ctrl(pipe, 0);
783
784 pkt->trans = len;
785
786 tasklet_init(&fifo->tasklet,
787 usbhsf_dma_prepare_tasklet,
788 (unsigned long)pkt);
789
790 tasklet_schedule(&fifo->tasklet);
791
792 return 0;
793
794usbhsf_pio_prepare_pop_unselect:
795 usbhsf_fifo_unselect(pipe, fifo);
796usbhsf_pio_prepare_pop:
797
798 /*
799 * change handler to PIO
800 */
801 pkt->handler = &usbhs_fifo_pio_pop_handler;
802
803 return pkt->handler->try_run(pkt, is_done);
804}
805
806static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done)
807{
808 struct usbhs_pipe *pipe = pkt->pipe;
809 int maxp = usbhs_pipe_get_maxpacket(pipe);
810
811 usbhsf_dma_stop(pipe, pipe->fifo);
812 usbhsf_dma_unmap(pkt);
813 usbhsf_fifo_unselect(pipe, pipe->fifo);
814
815 pkt->actual += pkt->trans;
816
817 if ((pkt->actual == pkt->length) || /* receive all data */
818 (pkt->trans < maxp)) { /* short packet */
819 *is_done = 1;
820 } else {
821 /* re-enable */
822 usbhsf_prepare_pop(pkt, is_done);
823 }
824
825 return 0;
826}
827
828struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = {
829 .prepare = usbhsf_prepare_pop,
830 .try_run = usbhsf_dma_try_pop,
831 .dma_done = usbhsf_dma_pop_done
832};
833
834/*
835 * DMA setting
836 */
837static bool usbhsf_dma_filter(struct dma_chan *chan, void *param)
838{
839 struct sh_dmae_slave *slave = param;
840
841 /*
842 * FIXME
843 *
844 * usbhs doesn't recognize id = 0 as valid DMA
845 */
846 if (0 == slave->slave_id)
847 return false;
848
849 chan->private = slave;
850
851 return true;
852}
853
854static void usbhsf_dma_quit(struct usbhs_priv *priv, struct usbhs_fifo *fifo)
855{
856 if (fifo->tx_chan)
857 dma_release_channel(fifo->tx_chan);
858 if (fifo->rx_chan)
859 dma_release_channel(fifo->rx_chan);
860
861 fifo->tx_chan = NULL;
862 fifo->rx_chan = NULL;
863}
864
865static void usbhsf_dma_init(struct usbhs_priv *priv,
866 struct usbhs_fifo *fifo)
867{
868 struct device *dev = usbhs_priv_to_dev(priv);
869 dma_cap_mask_t mask;
870
871 dma_cap_zero(mask);
872 dma_cap_set(DMA_SLAVE, mask);
873 fifo->tx_chan = dma_request_channel(mask, usbhsf_dma_filter,
874 &fifo->tx_slave);
875
876 dma_cap_zero(mask);
877 dma_cap_set(DMA_SLAVE, mask);
878 fifo->rx_chan = dma_request_channel(mask, usbhsf_dma_filter,
879 &fifo->rx_slave);
880
881 if (fifo->tx_chan || fifo->rx_chan)
Kuninori Morimoto4ce68802011-06-21 09:33:43 +0900882 dev_dbg(dev, "enable DMAEngine (%s%s%s)\n",
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900883 fifo->name,
884 fifo->tx_chan ? "[TX]" : " ",
885 fifo->rx_chan ? "[RX]" : " ");
886}
887
888/*
Kuninori Morimotodad67392011-06-06 14:18:28 +0900889 * irq functions
890 */
891static int usbhsf_irq_empty(struct usbhs_priv *priv,
892 struct usbhs_irq_state *irq_state)
893{
894 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900895 struct device *dev = usbhs_priv_to_dev(priv);
896 int i, ret;
897
898 if (!irq_state->bempsts) {
899 dev_err(dev, "debug %s !!\n", __func__);
900 return -EIO;
901 }
902
903 dev_dbg(dev, "irq empty [0x%04x]\n", irq_state->bempsts);
904
905 /*
906 * search interrupted "pipe"
907 * not "uep".
908 */
909 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
910 if (!(irq_state->bempsts & (1 << i)))
911 continue;
912
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700913 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900914 if (ret < 0)
915 dev_err(dev, "irq_empty run_error %d : %d\n", i, ret);
916 }
917
918 return 0;
919}
920
921static int usbhsf_irq_ready(struct usbhs_priv *priv,
922 struct usbhs_irq_state *irq_state)
923{
924 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900925 struct device *dev = usbhs_priv_to_dev(priv);
926 int i, ret;
927
928 if (!irq_state->brdysts) {
929 dev_err(dev, "debug %s !!\n", __func__);
930 return -EIO;
931 }
932
933 dev_dbg(dev, "irq ready [0x%04x]\n", irq_state->brdysts);
934
935 /*
936 * search interrupted "pipe"
937 * not "uep".
938 */
939 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
940 if (!(irq_state->brdysts & (1 << i)))
941 continue;
942
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700943 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900944 if (ret < 0)
945 dev_err(dev, "irq_ready run_error %d : %d\n", i, ret);
946 }
947
948 return 0;
949}
950
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900951static void usbhsf_dma_complete(void *arg)
952{
953 struct usbhs_pipe *pipe = arg;
954 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
955 struct device *dev = usbhs_priv_to_dev(priv);
956 int ret;
957
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700958 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_DMA_DONE);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900959 if (ret < 0)
960 dev_err(dev, "dma_complete run_error %d : %d\n",
961 usbhs_pipe_number(pipe), ret);
962}
963
Kuninori Morimotodad67392011-06-06 14:18:28 +0900964/*
965 * fifo init
966 */
967void usbhs_fifo_init(struct usbhs_priv *priv)
968{
969 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900970 struct usbhs_fifo *cfifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900971 struct usbhs_fifo *d0fifo = usbhsf_get_d0fifo(priv);
972 struct usbhs_fifo *d1fifo = usbhsf_get_d1fifo(priv);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900973
974 mod->irq_empty = usbhsf_irq_empty;
975 mod->irq_ready = usbhsf_irq_ready;
976 mod->irq_bempsts = 0;
977 mod->irq_brdysts = 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900978
979 cfifo->pipe = NULL;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900980 cfifo->tx_chan = NULL;
981 cfifo->rx_chan = NULL;
982
983 d0fifo->pipe = NULL;
984 d0fifo->tx_chan = NULL;
985 d0fifo->rx_chan = NULL;
986
987 d1fifo->pipe = NULL;
988 d1fifo->tx_chan = NULL;
989 d1fifo->rx_chan = NULL;
990
991 usbhsf_dma_init(priv, usbhsf_get_d0fifo(priv));
992 usbhsf_dma_init(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +0900993}
994
995void usbhs_fifo_quit(struct usbhs_priv *priv)
996{
997 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
998
999 mod->irq_empty = NULL;
1000 mod->irq_ready = NULL;
1001 mod->irq_bempsts = 0;
1002 mod->irq_brdysts = 0;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001003
1004 usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv));
1005 usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +09001006}
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001007
1008int usbhs_fifo_probe(struct usbhs_priv *priv)
1009{
1010 struct usbhs_fifo *fifo;
1011
1012 /* CFIFO */
1013 fifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001014 fifo->name = "CFIFO";
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001015 fifo->port = CFIFO;
1016 fifo->sel = CFIFOSEL;
1017 fifo->ctr = CFIFOCTR;
1018
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001019 /* D0FIFO */
1020 fifo = usbhsf_get_d0fifo(priv);
1021 fifo->name = "D0FIFO";
1022 fifo->port = D0FIFO;
1023 fifo->sel = D0FIFOSEL;
1024 fifo->ctr = D0FIFOCTR;
1025 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id);
1026 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id);
1027
1028 /* D1FIFO */
1029 fifo = usbhsf_get_d1fifo(priv);
1030 fifo->name = "D1FIFO";
1031 fifo->port = D1FIFO;
1032 fifo->sel = D1FIFOSEL;
1033 fifo->ctr = D1FIFOCTR;
1034 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id);
1035 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id);
1036
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001037 return 0;
1038}
1039
1040void usbhs_fifo_remove(struct usbhs_priv *priv)
1041{
1042}