blob: 7eacacda8589c05e405d8fff720ce14c6bf6ea94 [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 Morimotodad67392011-06-06 14:18:28 +090057 struct usbhs_pkt_handle *handler,
Kuninori Morimoto659d4952011-06-06 14:18:23 +090058 void *buf, int len, int zero)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090059{
Kuninori Morimotodad67392011-06-06 14:18:28 +090060 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
61 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimoto97664a22011-06-06 14:18:38 +090062 unsigned long flags;
63
64 /******************** spin lock ********************/
65 usbhs_lock(priv, flags);
Kuninori Morimotodad67392011-06-06 14:18:28 +090066
67 if (!handler) {
68 dev_err(dev, "no handler function\n");
69 handler = &usbhsf_null_handler;
70 }
71
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090072 list_del_init(&pkt->node);
73 list_add_tail(&pkt->node, &pipe->list);
74
Kuninori Morimoto659d4952011-06-06 14:18:23 +090075 pkt->pipe = pipe;
76 pkt->buf = buf;
Kuninori Morimotodad67392011-06-06 14:18:28 +090077 pkt->handler = handler;
Kuninori Morimoto659d4952011-06-06 14:18:23 +090078 pkt->length = len;
79 pkt->zero = zero;
80 pkt->actual = 0;
Kuninori Morimoto97664a22011-06-06 14:18:38 +090081
82 usbhs_unlock(priv, flags);
83 /******************** spin unlock ******************/
Kuninori Morimoto0432eed2011-06-06 14:18:54 +090084
85 usbhs_pkt_start(pipe);
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090086}
87
Kuninori Morimoto97664a22011-06-06 14:18:38 +090088static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090089{
90 list_del_init(&pkt->node);
91}
92
Kuninori Morimoto97664a22011-06-06 14:18:38 +090093static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090094{
95 if (list_empty(&pipe->list))
96 return NULL;
97
98 return list_entry(pipe->list.next, struct usbhs_pkt, node);
99}
100
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900101struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt)
102{
103 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
104 unsigned long flags;
105
106 /******************** spin lock ********************/
107 usbhs_lock(priv, flags);
108
109 if (!pkt)
110 pkt = __usbhsf_pkt_get(pipe);
111
112 if (pkt)
113 __usbhsf_pkt_del(pkt);
114
115 usbhs_unlock(priv, flags);
116 /******************** spin unlock ******************/
117
118 return pkt;
119}
120
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700121enum {
122 USBHSF_PKT_PREPARE,
123 USBHSF_PKT_TRY_RUN,
124 USBHSF_PKT_DMA_DONE,
125};
126
127static int usbhsf_pkt_handler(struct usbhs_pipe *pipe, int type)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900128{
129 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
130 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
131 struct usbhs_pkt *pkt;
132 struct device *dev = usbhs_priv_to_dev(priv);
133 int (*func)(struct usbhs_pkt *pkt, int *is_done);
134 unsigned long flags;
135 int ret = 0;
136 int is_done = 0;
137
138 /******************** spin lock ********************/
139 usbhs_lock(priv, flags);
140
141 pkt = __usbhsf_pkt_get(pipe);
142 if (!pkt)
143 goto __usbhs_pkt_handler_end;
144
145 switch (type) {
146 case USBHSF_PKT_PREPARE:
147 func = pkt->handler->prepare;
148 break;
149 case USBHSF_PKT_TRY_RUN:
150 func = pkt->handler->try_run;
151 break;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900152 case USBHSF_PKT_DMA_DONE:
153 func = pkt->handler->dma_done;
154 break;
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900155 default:
156 dev_err(dev, "unknown pkt hander\n");
157 goto __usbhs_pkt_handler_end;
158 }
159
160 ret = func(pkt, &is_done);
161
162 if (is_done)
163 __usbhsf_pkt_del(pkt);
164
165__usbhs_pkt_handler_end:
166 usbhs_unlock(priv, flags);
167 /******************** spin unlock ******************/
168
Kuninori Morimoto0432eed2011-06-06 14:18:54 +0900169 if (is_done) {
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900170 info->done(pkt);
Kuninori Morimoto0432eed2011-06-06 14:18:54 +0900171 usbhs_pkt_start(pipe);
172 }
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900173
174 return ret;
175}
176
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700177void usbhs_pkt_start(struct usbhs_pipe *pipe)
178{
179 usbhsf_pkt_handler(pipe, USBHSF_PKT_PREPARE);
180}
181
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900182/*
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900183 * irq enable/disable function
184 */
185#define usbhsf_irq_empty_ctrl(p, e) usbhsf_irq_callback_ctrl(p, bempsts, e)
186#define usbhsf_irq_ready_ctrl(p, e) usbhsf_irq_callback_ctrl(p, brdysts, e)
187#define usbhsf_irq_callback_ctrl(pipe, status, enable) \
188 ({ \
189 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); \
190 struct usbhs_mod *mod = usbhs_mod_get_current(priv); \
191 u16 status = (1 << usbhs_pipe_number(pipe)); \
192 if (!mod) \
193 return; \
194 if (enable) \
195 mod->irq_##status |= status; \
196 else \
197 mod->irq_##status &= ~status; \
198 usbhs_irq_callback_update(priv, mod); \
199 })
200
201static void usbhsf_tx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
202{
203 /*
204 * And DCP pipe can NOT use "ready interrupt" for "send"
205 * it should use "empty" interrupt.
206 * see
207 * "Operation" - "Interrupt Function" - "BRDY Interrupt"
208 *
209 * on the other hand, normal pipe can use "ready interrupt" for "send"
210 * even though it is single/double buffer
211 */
212 if (usbhs_pipe_is_dcp(pipe))
213 usbhsf_irq_empty_ctrl(pipe, enable);
214 else
215 usbhsf_irq_ready_ctrl(pipe, enable);
216}
217
218static void usbhsf_rx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
219{
220 usbhsf_irq_ready_ctrl(pipe, enable);
221}
222
223/*
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900224 * FIFO ctrl
225 */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900226static void usbhsf_send_terminator(struct usbhs_pipe *pipe,
227 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900228{
229 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
230
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900231 usbhs_bset(priv, fifo->ctr, BVAL, BVAL);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900232}
233
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900234static int usbhsf_fifo_barrier(struct usbhs_priv *priv,
235 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900236{
237 int timeout = 1024;
238
239 do {
240 /* The FIFO port is accessible */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900241 if (usbhs_read(priv, fifo->ctr) & FRDY)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900242 return 0;
243
244 udelay(10);
245 } while (timeout--);
246
247 return -EBUSY;
248}
249
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900250static void usbhsf_fifo_clear(struct usbhs_pipe *pipe,
251 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900252{
253 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
254
255 if (!usbhs_pipe_is_dcp(pipe))
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900256 usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900257
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900258 usbhs_write(priv, fifo->ctr, BCLR);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900259}
260
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900261static int usbhsf_fifo_rcv_len(struct usbhs_priv *priv,
262 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900263{
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900264 return usbhs_read(priv, fifo->ctr) & DTLN_MASK;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900265}
266
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900267static void usbhsf_fifo_unselect(struct usbhs_pipe *pipe,
268 struct usbhs_fifo *fifo)
269{
270 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
271
272 usbhs_pipe_select_fifo(pipe, NULL);
273 usbhs_write(priv, fifo->sel, 0);
274}
275
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900276static int usbhsf_fifo_select(struct usbhs_pipe *pipe,
277 struct usbhs_fifo *fifo,
278 int write)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900279{
280 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
281 struct device *dev = usbhs_priv_to_dev(priv);
282 int timeout = 1024;
283 u16 mask = ((1 << 5) | 0xF); /* mask of ISEL | CURPIPE */
284 u16 base = usbhs_pipe_number(pipe); /* CURPIPE */
285
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900286 if (usbhs_pipe_is_busy(pipe) ||
287 usbhsf_fifo_is_busy(fifo))
288 return -EBUSY;
289
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900290 if (usbhs_pipe_is_dcp(pipe))
291 base |= (1 == write) << 5; /* ISEL */
292
293 /* "base" will be used below */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900294 usbhs_write(priv, fifo->sel, base | MBW_32);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900295
296 /* check ISEL and CURPIPE value */
297 while (timeout--) {
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900298 if (base == (mask & usbhs_read(priv, fifo->sel))) {
299 usbhs_pipe_select_fifo(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900300 return 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900301 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900302 udelay(10);
303 }
304
305 dev_err(dev, "fifo select error\n");
306
307 return -EIO;
308}
309
310/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700311 * PIO push handler
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900312 */
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900313static int usbhsf_pio_try_push(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900314{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900315 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900316 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900317 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900318 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
319 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900320 u8 *buf;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900321 int maxp = usbhs_pipe_get_maxpacket(pipe);
322 int total_len;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900323 int i, ret, len;
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900324 int is_short;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900325
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900326 ret = usbhsf_fifo_select(pipe, fifo, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900327 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900328 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900329
Kuninori Morimotodad67392011-06-06 14:18:28 +0900330 ret = usbhs_pipe_is_accessible(pipe);
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700331 if (ret < 0) {
332 /* inaccessible pipe is not an error */
333 ret = 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900334 goto usbhs_fifo_write_busy;
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700335 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900336
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900337 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900338 if (ret < 0)
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900339 goto usbhs_fifo_write_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900340
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900341 buf = pkt->buf + pkt->actual;
342 len = pkt->length - pkt->actual;
343 len = min(len, maxp);
344 total_len = len;
345 is_short = total_len < maxp;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900346
347 /*
348 * FIXME
349 *
350 * 32-bit access only
351 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900352 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900353 iowrite32_rep(addr, buf, len / 4);
354 len %= 4;
355 buf += total_len - len;
356 }
357
358 /* the rest operation */
359 for (i = 0; i < len; i++)
360 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
361
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900362 /*
363 * variable update
364 */
365 pkt->actual += total_len;
366
367 if (pkt->actual < pkt->length)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900368 *is_done = 0; /* there are remainder data */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900369 else if (is_short)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900370 *is_done = 1; /* short packet */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900371 else
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900372 *is_done = !pkt->zero; /* send zero packet ? */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900373
374 /*
375 * pipe/irq handling
376 */
377 if (is_short)
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900378 usbhsf_send_terminator(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900379
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900380 usbhsf_tx_irq_ctrl(pipe, !*is_done);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900381 usbhs_pipe_enable(pipe);
382
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900383 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
384 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900385 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900386
387 /*
388 * Transmission end
389 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900390 if (*is_done) {
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900391 if (usbhs_pipe_is_dcp(pipe))
392 usbhs_dcp_control_transfer_done(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900393 }
394
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900395 usbhsf_fifo_unselect(pipe, fifo);
396
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900397 return 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900398
399usbhs_fifo_write_busy:
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900400 usbhsf_fifo_unselect(pipe, fifo);
401
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900402 /*
403 * pipe is busy.
404 * retry in interrupt
405 */
406 usbhsf_tx_irq_ctrl(pipe, 1);
407
408 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900409}
410
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900411struct usbhs_pkt_handle usbhs_fifo_pio_push_handler = {
412 .prepare = usbhsf_pio_try_push,
413 .try_run = usbhsf_pio_try_push,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900414};
415
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700416/*
417 * PIO pop handler
418 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900419static int usbhsf_prepare_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900420{
Kuninori Morimotodad67392011-06-06 14:18:28 +0900421 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900422
423 if (usbhs_pipe_is_busy(pipe))
424 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900425
426 /*
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900427 * pipe enable to prepare packet receive
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900428 */
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900429
430 usbhs_pipe_enable(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900431 usbhsf_rx_irq_ctrl(pipe, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900432
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900433 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900434}
435
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900436static int usbhsf_pio_try_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900437{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900438 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900439 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900440 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900441 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
442 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900443 u8 *buf;
444 u32 data = 0;
445 int maxp = usbhs_pipe_get_maxpacket(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900446 int rcv_len, len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900447 int i, ret;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900448 int total_len = 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900449
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900450 ret = usbhsf_fifo_select(pipe, fifo, 0);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900451 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900452 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900453
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900454 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900455 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900456 goto usbhs_fifo_read_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900457
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900458 rcv_len = usbhsf_fifo_rcv_len(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900459
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900460 buf = pkt->buf + pkt->actual;
461 len = pkt->length - pkt->actual;
462 len = min(len, rcv_len);
463 total_len = len;
464
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900465 /*
466 * Buffer clear if Zero-Length packet
467 *
468 * see
469 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
470 */
471 if (0 == rcv_len) {
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900472 usbhsf_fifo_clear(pipe, fifo);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900473 goto usbhs_fifo_read_end;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900474 }
475
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900476 /*
477 * FIXME
478 *
479 * 32-bit access only
480 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900481 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900482 ioread32_rep(addr, buf, len / 4);
483 len %= 4;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900484 buf += total_len - len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900485 }
486
487 /* the rest operation */
488 for (i = 0; i < len; i++) {
489 if (!(i & 0x03))
490 data = ioread32(addr);
491
492 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
493 }
494
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900495 pkt->actual += total_len;
496
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900497usbhs_fifo_read_end:
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900498 if ((pkt->actual == pkt->length) || /* receive all data */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900499 (total_len < maxp)) { /* short packet */
500 *is_done = 1;
501 usbhsf_rx_irq_ctrl(pipe, 0);
502 usbhs_pipe_disable(pipe);
503 }
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900504
505 dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
506 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900507 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900508
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900509usbhs_fifo_read_busy:
510 usbhsf_fifo_unselect(pipe, fifo);
511
512 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900513}
Kuninori Morimotodad67392011-06-06 14:18:28 +0900514
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900515struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler = {
Kuninori Morimotodad67392011-06-06 14:18:28 +0900516 .prepare = usbhsf_prepare_pop,
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900517 .try_run = usbhsf_pio_try_pop,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900518};
519
520/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700521 * DCP ctrol statge handler
Kuninori Morimotodad67392011-06-06 14:18:28 +0900522 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900523static int usbhsf_ctrl_stage_end(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotodad67392011-06-06 14:18:28 +0900524{
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900525 usbhs_dcp_control_transfer_done(pkt->pipe);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900526
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900527 *is_done = 1;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900528
529 return 0;
530}
531
532struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler = {
533 .prepare = usbhsf_ctrl_stage_end,
534 .try_run = usbhsf_ctrl_stage_end,
535};
536
537/*
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900538 * DMA fifo functions
539 */
540static struct dma_chan *usbhsf_dma_chan_get(struct usbhs_fifo *fifo,
541 struct usbhs_pkt *pkt)
542{
543 if (&usbhs_fifo_dma_push_handler == pkt->handler)
544 return fifo->tx_chan;
545
546 if (&usbhs_fifo_dma_pop_handler == pkt->handler)
547 return fifo->rx_chan;
548
549 return NULL;
550}
551
552static struct usbhs_fifo *usbhsf_get_dma_fifo(struct usbhs_priv *priv,
553 struct usbhs_pkt *pkt)
554{
555 struct usbhs_fifo *fifo;
556
557 /* DMA :: D0FIFO */
558 fifo = usbhsf_get_d0fifo(priv);
559 if (usbhsf_dma_chan_get(fifo, pkt) &&
560 !usbhsf_fifo_is_busy(fifo))
561 return fifo;
562
563 /* DMA :: D1FIFO */
564 fifo = usbhsf_get_d1fifo(priv);
565 if (usbhsf_dma_chan_get(fifo, pkt) &&
566 !usbhsf_fifo_is_busy(fifo))
567 return fifo;
568
569 return NULL;
570}
571
572#define usbhsf_dma_start(p, f) __usbhsf_dma_ctrl(p, f, DREQE)
573#define usbhsf_dma_stop(p, f) __usbhsf_dma_ctrl(p, f, 0)
574static void __usbhsf_dma_ctrl(struct usbhs_pipe *pipe,
575 struct usbhs_fifo *fifo,
576 u16 dreqe)
577{
578 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
579
580 usbhs_bset(priv, fifo->sel, DREQE, dreqe);
581}
582
583#define usbhsf_dma_map(p) __usbhsf_dma_map_ctrl(p, 1)
584#define usbhsf_dma_unmap(p) __usbhsf_dma_map_ctrl(p, 0)
585static int __usbhsf_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
586{
587 struct usbhs_pipe *pipe = pkt->pipe;
588 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
589 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
590
591 return info->dma_map_ctrl(pkt, map);
592}
593
594static void usbhsf_dma_complete(void *arg);
595static void usbhsf_dma_prepare_tasklet(unsigned long data)
596{
597 struct usbhs_pkt *pkt = (struct usbhs_pkt *)data;
598 struct usbhs_pipe *pipe = pkt->pipe;
599 struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe);
600 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
601 struct scatterlist sg;
602 struct dma_async_tx_descriptor *desc;
603 struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt);
604 struct device *dev = usbhs_priv_to_dev(priv);
605 enum dma_data_direction dir;
606 dma_cookie_t cookie;
607
608 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
609
610 sg_init_table(&sg, 1);
611 sg_set_page(&sg, virt_to_page(pkt->dma),
612 pkt->length, offset_in_page(pkt->dma));
613 sg_dma_address(&sg) = pkt->dma + pkt->actual;
614 sg_dma_len(&sg) = pkt->trans;
615
616 desc = chan->device->device_prep_slave_sg(chan, &sg, 1, dir,
617 DMA_PREP_INTERRUPT |
618 DMA_CTRL_ACK);
619 if (!desc)
620 return;
621
622 desc->callback = usbhsf_dma_complete;
623 desc->callback_param = pipe;
624
625 cookie = desc->tx_submit(desc);
626 if (cookie < 0) {
627 dev_err(dev, "Failed to submit dma descriptor\n");
628 return;
629 }
630
631 dev_dbg(dev, " %s %d (%d/ %d)\n",
632 fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero);
633
634 usbhsf_dma_start(pipe, fifo);
635 dma_async_issue_pending(chan);
636}
637
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700638/*
639 * DMA push handler
640 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900641static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done)
642{
643 struct usbhs_pipe *pipe = pkt->pipe;
644 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
645 struct usbhs_fifo *fifo;
646 int len = pkt->length - pkt->actual;
647 int ret;
648
649 if (usbhs_pipe_is_busy(pipe))
650 return 0;
651
652 /* use PIO if packet is less than pio_dma_border or pipe is DCP */
653 if ((len < usbhs_get_dparam(priv, pio_dma_border)) ||
654 usbhs_pipe_is_dcp(pipe))
655 goto usbhsf_pio_prepare_push;
656
657 if (len % 4) /* 32bit alignment */
658 goto usbhsf_pio_prepare_push;
659
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700660 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
661 goto usbhsf_pio_prepare_push;
662
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900663 /* get enable DMA fifo */
664 fifo = usbhsf_get_dma_fifo(priv, pkt);
665 if (!fifo)
666 goto usbhsf_pio_prepare_push;
667
668 if (usbhsf_dma_map(pkt) < 0)
669 goto usbhsf_pio_prepare_push;
670
671 ret = usbhsf_fifo_select(pipe, fifo, 0);
672 if (ret < 0)
673 goto usbhsf_pio_prepare_push_unmap;
674
675 pkt->trans = len;
676
677 tasklet_init(&fifo->tasklet,
678 usbhsf_dma_prepare_tasklet,
679 (unsigned long)pkt);
680
681 tasklet_schedule(&fifo->tasklet);
682
683 return 0;
684
685usbhsf_pio_prepare_push_unmap:
686 usbhsf_dma_unmap(pkt);
687usbhsf_pio_prepare_push:
688 /*
689 * change handler to PIO
690 */
691 pkt->handler = &usbhs_fifo_pio_push_handler;
692
693 return pkt->handler->prepare(pkt, is_done);
694}
695
696static int usbhsf_dma_push_done(struct usbhs_pkt *pkt, int *is_done)
697{
698 struct usbhs_pipe *pipe = pkt->pipe;
699
700 pkt->actual = pkt->trans;
701
702 *is_done = !pkt->zero; /* send zero packet ? */
703
704 usbhsf_dma_stop(pipe, pipe->fifo);
705 usbhsf_dma_unmap(pkt);
706 usbhsf_fifo_unselect(pipe, pipe->fifo);
707
708 return 0;
709}
710
711struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = {
712 .prepare = usbhsf_dma_prepare_push,
713 .dma_done = usbhsf_dma_push_done,
714};
715
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700716/*
717 * DMA pop handler
718 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900719static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done)
720{
721 struct usbhs_pipe *pipe = pkt->pipe;
722 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
723 struct usbhs_fifo *fifo;
724 int len, ret;
725
726 if (usbhs_pipe_is_busy(pipe))
727 return 0;
728
729 if (usbhs_pipe_is_dcp(pipe))
730 goto usbhsf_pio_prepare_pop;
731
732 /* get enable DMA fifo */
733 fifo = usbhsf_get_dma_fifo(priv, pkt);
734 if (!fifo)
735 goto usbhsf_pio_prepare_pop;
736
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700737 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
738 goto usbhsf_pio_prepare_pop;
739
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900740 ret = usbhsf_fifo_select(pipe, fifo, 0);
741 if (ret < 0)
742 goto usbhsf_pio_prepare_pop;
743
744 /* use PIO if packet is less than pio_dma_border */
745 len = usbhsf_fifo_rcv_len(priv, fifo);
746 len = min(pkt->length - pkt->actual, len);
747 if (len % 4) /* 32bit alignment */
748 goto usbhsf_pio_prepare_pop_unselect;
749
750 if (len < usbhs_get_dparam(priv, pio_dma_border))
751 goto usbhsf_pio_prepare_pop_unselect;
752
753 ret = usbhsf_fifo_barrier(priv, fifo);
754 if (ret < 0)
755 goto usbhsf_pio_prepare_pop_unselect;
756
757 if (usbhsf_dma_map(pkt) < 0)
758 goto usbhsf_pio_prepare_pop_unselect;
759
760 /* DMA */
761
762 /*
763 * usbhs_fifo_dma_pop_handler :: prepare
764 * enabled irq to come here.
765 * but it is no longer needed for DMA. disable it.
766 */
767 usbhsf_rx_irq_ctrl(pipe, 0);
768
769 pkt->trans = len;
770
771 tasklet_init(&fifo->tasklet,
772 usbhsf_dma_prepare_tasklet,
773 (unsigned long)pkt);
774
775 tasklet_schedule(&fifo->tasklet);
776
777 return 0;
778
779usbhsf_pio_prepare_pop_unselect:
780 usbhsf_fifo_unselect(pipe, fifo);
781usbhsf_pio_prepare_pop:
782
783 /*
784 * change handler to PIO
785 */
786 pkt->handler = &usbhs_fifo_pio_pop_handler;
787
788 return pkt->handler->try_run(pkt, is_done);
789}
790
791static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done)
792{
793 struct usbhs_pipe *pipe = pkt->pipe;
794 int maxp = usbhs_pipe_get_maxpacket(pipe);
795
796 usbhsf_dma_stop(pipe, pipe->fifo);
797 usbhsf_dma_unmap(pkt);
798 usbhsf_fifo_unselect(pipe, pipe->fifo);
799
800 pkt->actual += pkt->trans;
801
802 if ((pkt->actual == pkt->length) || /* receive all data */
803 (pkt->trans < maxp)) { /* short packet */
804 *is_done = 1;
805 } else {
806 /* re-enable */
807 usbhsf_prepare_pop(pkt, is_done);
808 }
809
810 return 0;
811}
812
813struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = {
814 .prepare = usbhsf_prepare_pop,
815 .try_run = usbhsf_dma_try_pop,
816 .dma_done = usbhsf_dma_pop_done
817};
818
819/*
820 * DMA setting
821 */
822static bool usbhsf_dma_filter(struct dma_chan *chan, void *param)
823{
824 struct sh_dmae_slave *slave = param;
825
826 /*
827 * FIXME
828 *
829 * usbhs doesn't recognize id = 0 as valid DMA
830 */
831 if (0 == slave->slave_id)
832 return false;
833
834 chan->private = slave;
835
836 return true;
837}
838
839static void usbhsf_dma_quit(struct usbhs_priv *priv, struct usbhs_fifo *fifo)
840{
841 if (fifo->tx_chan)
842 dma_release_channel(fifo->tx_chan);
843 if (fifo->rx_chan)
844 dma_release_channel(fifo->rx_chan);
845
846 fifo->tx_chan = NULL;
847 fifo->rx_chan = NULL;
848}
849
850static void usbhsf_dma_init(struct usbhs_priv *priv,
851 struct usbhs_fifo *fifo)
852{
853 struct device *dev = usbhs_priv_to_dev(priv);
854 dma_cap_mask_t mask;
855
856 dma_cap_zero(mask);
857 dma_cap_set(DMA_SLAVE, mask);
858 fifo->tx_chan = dma_request_channel(mask, usbhsf_dma_filter,
859 &fifo->tx_slave);
860
861 dma_cap_zero(mask);
862 dma_cap_set(DMA_SLAVE, mask);
863 fifo->rx_chan = dma_request_channel(mask, usbhsf_dma_filter,
864 &fifo->rx_slave);
865
866 if (fifo->tx_chan || fifo->rx_chan)
Kuninori Morimoto4ce68802011-06-21 09:33:43 +0900867 dev_dbg(dev, "enable DMAEngine (%s%s%s)\n",
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900868 fifo->name,
869 fifo->tx_chan ? "[TX]" : " ",
870 fifo->rx_chan ? "[RX]" : " ");
871}
872
873/*
Kuninori Morimotodad67392011-06-06 14:18:28 +0900874 * irq functions
875 */
876static int usbhsf_irq_empty(struct usbhs_priv *priv,
877 struct usbhs_irq_state *irq_state)
878{
879 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900880 struct device *dev = usbhs_priv_to_dev(priv);
881 int i, ret;
882
883 if (!irq_state->bempsts) {
884 dev_err(dev, "debug %s !!\n", __func__);
885 return -EIO;
886 }
887
888 dev_dbg(dev, "irq empty [0x%04x]\n", irq_state->bempsts);
889
890 /*
891 * search interrupted "pipe"
892 * not "uep".
893 */
894 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
895 if (!(irq_state->bempsts & (1 << i)))
896 continue;
897
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700898 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900899 if (ret < 0)
900 dev_err(dev, "irq_empty run_error %d : %d\n", i, ret);
901 }
902
903 return 0;
904}
905
906static int usbhsf_irq_ready(struct usbhs_priv *priv,
907 struct usbhs_irq_state *irq_state)
908{
909 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900910 struct device *dev = usbhs_priv_to_dev(priv);
911 int i, ret;
912
913 if (!irq_state->brdysts) {
914 dev_err(dev, "debug %s !!\n", __func__);
915 return -EIO;
916 }
917
918 dev_dbg(dev, "irq ready [0x%04x]\n", irq_state->brdysts);
919
920 /*
921 * search interrupted "pipe"
922 * not "uep".
923 */
924 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
925 if (!(irq_state->brdysts & (1 << i)))
926 continue;
927
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700928 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900929 if (ret < 0)
930 dev_err(dev, "irq_ready run_error %d : %d\n", i, ret);
931 }
932
933 return 0;
934}
935
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900936static void usbhsf_dma_complete(void *arg)
937{
938 struct usbhs_pipe *pipe = arg;
939 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
940 struct device *dev = usbhs_priv_to_dev(priv);
941 int ret;
942
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700943 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_DMA_DONE);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900944 if (ret < 0)
945 dev_err(dev, "dma_complete run_error %d : %d\n",
946 usbhs_pipe_number(pipe), ret);
947}
948
Kuninori Morimotodad67392011-06-06 14:18:28 +0900949/*
950 * fifo init
951 */
952void usbhs_fifo_init(struct usbhs_priv *priv)
953{
954 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900955 struct usbhs_fifo *cfifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900956 struct usbhs_fifo *d0fifo = usbhsf_get_d0fifo(priv);
957 struct usbhs_fifo *d1fifo = usbhsf_get_d1fifo(priv);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900958
959 mod->irq_empty = usbhsf_irq_empty;
960 mod->irq_ready = usbhsf_irq_ready;
961 mod->irq_bempsts = 0;
962 mod->irq_brdysts = 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900963
964 cfifo->pipe = NULL;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900965 cfifo->tx_chan = NULL;
966 cfifo->rx_chan = NULL;
967
968 d0fifo->pipe = NULL;
969 d0fifo->tx_chan = NULL;
970 d0fifo->rx_chan = NULL;
971
972 d1fifo->pipe = NULL;
973 d1fifo->tx_chan = NULL;
974 d1fifo->rx_chan = NULL;
975
976 usbhsf_dma_init(priv, usbhsf_get_d0fifo(priv));
977 usbhsf_dma_init(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +0900978}
979
980void usbhs_fifo_quit(struct usbhs_priv *priv)
981{
982 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
983
984 mod->irq_empty = NULL;
985 mod->irq_ready = NULL;
986 mod->irq_bempsts = 0;
987 mod->irq_brdysts = 0;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900988
989 usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv));
990 usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +0900991}
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900992
993int usbhs_fifo_probe(struct usbhs_priv *priv)
994{
995 struct usbhs_fifo *fifo;
996
997 /* CFIFO */
998 fifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900999 fifo->name = "CFIFO";
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001000 fifo->port = CFIFO;
1001 fifo->sel = CFIFOSEL;
1002 fifo->ctr = CFIFOCTR;
1003
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001004 /* D0FIFO */
1005 fifo = usbhsf_get_d0fifo(priv);
1006 fifo->name = "D0FIFO";
1007 fifo->port = D0FIFO;
1008 fifo->sel = D0FIFOSEL;
1009 fifo->ctr = D0FIFOCTR;
1010 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id);
1011 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id);
1012
1013 /* D1FIFO */
1014 fifo = usbhsf_get_d1fifo(priv);
1015 fifo->name = "D1FIFO";
1016 fifo->port = D1FIFO;
1017 fifo->sel = D1FIFOSEL;
1018 fifo->ctr = D1FIFOCTR;
1019 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id);
1020 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id);
1021
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001022 return 0;
1023}
1024
1025void usbhs_fifo_remove(struct usbhs_priv *priv)
1026{
1027}