blob: 328238c373f67a894dcf778012b3fb91c3b4fbf6 [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,
57 void *buf, int len, int zero)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090058{
Kuninori Morimotodad67392011-06-06 14:18:28 +090059 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
60 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimoto97664a22011-06-06 14:18:38 +090061 unsigned long flags;
62
63 /******************** spin lock ********************/
64 usbhs_lock(priv, flags);
Kuninori Morimotodad67392011-06-06 14:18:28 +090065
Kuninori Morimoto0c6ef982011-10-10 22:00:59 -070066 if (!pipe->handler) {
Kuninori Morimotodad67392011-06-06 14:18:28 +090067 dev_err(dev, "no handler function\n");
Kuninori Morimoto0c6ef982011-10-10 22:00:59 -070068 pipe->handler = &usbhsf_null_handler;
Kuninori Morimotodad67392011-06-06 14:18:28 +090069 }
70
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090071 list_del_init(&pkt->node);
72 list_add_tail(&pkt->node, &pipe->list);
73
Kuninori Morimoto0c6ef982011-10-10 22:00:59 -070074 /*
75 * each pkt must hold own handler.
76 * because handler might be changed by its situation.
77 * dma handler -> pio handler.
78 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +090079 pkt->pipe = pipe;
80 pkt->buf = buf;
Kuninori Morimoto0c6ef982011-10-10 22:00:59 -070081 pkt->handler = pipe->handler;
Kuninori Morimoto659d4952011-06-06 14:18:23 +090082 pkt->length = len;
83 pkt->zero = zero;
84 pkt->actual = 0;
Kuninori Morimoto97664a22011-06-06 14:18:38 +090085
86 usbhs_unlock(priv, flags);
87 /******************** spin unlock ******************/
Kuninori Morimoto0432eed2011-06-06 14:18:54 +090088
89 usbhs_pkt_start(pipe);
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090090}
91
Kuninori Morimoto97664a22011-06-06 14:18:38 +090092static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090093{
94 list_del_init(&pkt->node);
95}
96
Kuninori Morimoto97664a22011-06-06 14:18:38 +090097static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090098{
99 if (list_empty(&pipe->list))
100 return NULL;
101
102 return list_entry(pipe->list.next, struct usbhs_pkt, node);
103}
104
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900105struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt)
106{
107 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
108 unsigned long flags;
109
110 /******************** spin lock ********************/
111 usbhs_lock(priv, flags);
112
113 if (!pkt)
114 pkt = __usbhsf_pkt_get(pipe);
115
116 if (pkt)
117 __usbhsf_pkt_del(pkt);
118
119 usbhs_unlock(priv, flags);
120 /******************** spin unlock ******************/
121
122 return pkt;
123}
124
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700125enum {
126 USBHSF_PKT_PREPARE,
127 USBHSF_PKT_TRY_RUN,
128 USBHSF_PKT_DMA_DONE,
129};
130
131static int usbhsf_pkt_handler(struct usbhs_pipe *pipe, int type)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900132{
133 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
134 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
135 struct usbhs_pkt *pkt;
136 struct device *dev = usbhs_priv_to_dev(priv);
137 int (*func)(struct usbhs_pkt *pkt, int *is_done);
138 unsigned long flags;
139 int ret = 0;
140 int is_done = 0;
141
142 /******************** spin lock ********************/
143 usbhs_lock(priv, flags);
144
145 pkt = __usbhsf_pkt_get(pipe);
146 if (!pkt)
147 goto __usbhs_pkt_handler_end;
148
149 switch (type) {
150 case USBHSF_PKT_PREPARE:
151 func = pkt->handler->prepare;
152 break;
153 case USBHSF_PKT_TRY_RUN:
154 func = pkt->handler->try_run;
155 break;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900156 case USBHSF_PKT_DMA_DONE:
157 func = pkt->handler->dma_done;
158 break;
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900159 default:
160 dev_err(dev, "unknown pkt hander\n");
161 goto __usbhs_pkt_handler_end;
162 }
163
164 ret = func(pkt, &is_done);
165
166 if (is_done)
167 __usbhsf_pkt_del(pkt);
168
169__usbhs_pkt_handler_end:
170 usbhs_unlock(priv, flags);
171 /******************** spin unlock ******************/
172
Kuninori Morimoto0432eed2011-06-06 14:18:54 +0900173 if (is_done) {
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900174 info->done(pkt);
Kuninori Morimoto0432eed2011-06-06 14:18:54 +0900175 usbhs_pkt_start(pipe);
176 }
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900177
178 return ret;
179}
180
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700181void usbhs_pkt_start(struct usbhs_pipe *pipe)
182{
183 usbhsf_pkt_handler(pipe, USBHSF_PKT_PREPARE);
184}
185
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900186/*
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900187 * irq enable/disable function
188 */
189#define usbhsf_irq_empty_ctrl(p, e) usbhsf_irq_callback_ctrl(p, bempsts, e)
190#define usbhsf_irq_ready_ctrl(p, e) usbhsf_irq_callback_ctrl(p, brdysts, e)
191#define usbhsf_irq_callback_ctrl(pipe, status, enable) \
192 ({ \
193 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); \
194 struct usbhs_mod *mod = usbhs_mod_get_current(priv); \
195 u16 status = (1 << usbhs_pipe_number(pipe)); \
196 if (!mod) \
197 return; \
198 if (enable) \
199 mod->irq_##status |= status; \
200 else \
201 mod->irq_##status &= ~status; \
202 usbhs_irq_callback_update(priv, mod); \
203 })
204
205static void usbhsf_tx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
206{
207 /*
208 * And DCP pipe can NOT use "ready interrupt" for "send"
209 * it should use "empty" interrupt.
210 * see
211 * "Operation" - "Interrupt Function" - "BRDY Interrupt"
212 *
213 * on the other hand, normal pipe can use "ready interrupt" for "send"
214 * even though it is single/double buffer
215 */
216 if (usbhs_pipe_is_dcp(pipe))
217 usbhsf_irq_empty_ctrl(pipe, enable);
218 else
219 usbhsf_irq_ready_ctrl(pipe, enable);
220}
221
222static void usbhsf_rx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
223{
224 usbhsf_irq_ready_ctrl(pipe, enable);
225}
226
227/*
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900228 * FIFO ctrl
229 */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900230static void usbhsf_send_terminator(struct usbhs_pipe *pipe,
231 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900232{
233 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
234
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900235 usbhs_bset(priv, fifo->ctr, BVAL, BVAL);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900236}
237
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900238static int usbhsf_fifo_barrier(struct usbhs_priv *priv,
239 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900240{
241 int timeout = 1024;
242
243 do {
244 /* The FIFO port is accessible */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900245 if (usbhs_read(priv, fifo->ctr) & FRDY)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900246 return 0;
247
248 udelay(10);
249 } while (timeout--);
250
251 return -EBUSY;
252}
253
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900254static void usbhsf_fifo_clear(struct usbhs_pipe *pipe,
255 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900256{
257 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
258
259 if (!usbhs_pipe_is_dcp(pipe))
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900260 usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900261
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900262 usbhs_write(priv, fifo->ctr, BCLR);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900263}
264
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900265static int usbhsf_fifo_rcv_len(struct usbhs_priv *priv,
266 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900267{
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900268 return usbhs_read(priv, fifo->ctr) & DTLN_MASK;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900269}
270
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900271static void usbhsf_fifo_unselect(struct usbhs_pipe *pipe,
272 struct usbhs_fifo *fifo)
273{
274 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
275
276 usbhs_pipe_select_fifo(pipe, NULL);
277 usbhs_write(priv, fifo->sel, 0);
278}
279
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900280static int usbhsf_fifo_select(struct usbhs_pipe *pipe,
281 struct usbhs_fifo *fifo,
282 int write)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900283{
284 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
285 struct device *dev = usbhs_priv_to_dev(priv);
286 int timeout = 1024;
287 u16 mask = ((1 << 5) | 0xF); /* mask of ISEL | CURPIPE */
288 u16 base = usbhs_pipe_number(pipe); /* CURPIPE */
289
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900290 if (usbhs_pipe_is_busy(pipe) ||
291 usbhsf_fifo_is_busy(fifo))
292 return -EBUSY;
293
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900294 if (usbhs_pipe_is_dcp(pipe))
295 base |= (1 == write) << 5; /* ISEL */
296
297 /* "base" will be used below */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900298 usbhs_write(priv, fifo->sel, base | MBW_32);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900299
300 /* check ISEL and CURPIPE value */
301 while (timeout--) {
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900302 if (base == (mask & usbhs_read(priv, fifo->sel))) {
303 usbhs_pipe_select_fifo(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900304 return 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900305 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900306 udelay(10);
307 }
308
309 dev_err(dev, "fifo select error\n");
310
311 return -EIO;
312}
313
314/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700315 * PIO push handler
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900316 */
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900317static int usbhsf_pio_try_push(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900318{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900319 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900320 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900321 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900322 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
323 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900324 u8 *buf;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900325 int maxp = usbhs_pipe_get_maxpacket(pipe);
326 int total_len;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900327 int i, ret, len;
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900328 int is_short;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900329
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900330 ret = usbhsf_fifo_select(pipe, fifo, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900331 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900332 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900333
Kuninori Morimotodad67392011-06-06 14:18:28 +0900334 ret = usbhs_pipe_is_accessible(pipe);
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700335 if (ret < 0) {
336 /* inaccessible pipe is not an error */
337 ret = 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900338 goto usbhs_fifo_write_busy;
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700339 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900340
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900341 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900342 if (ret < 0)
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900343 goto usbhs_fifo_write_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900344
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900345 buf = pkt->buf + pkt->actual;
346 len = pkt->length - pkt->actual;
347 len = min(len, maxp);
348 total_len = len;
349 is_short = total_len < maxp;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900350
351 /*
352 * FIXME
353 *
354 * 32-bit access only
355 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900356 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900357 iowrite32_rep(addr, buf, len / 4);
358 len %= 4;
359 buf += total_len - len;
360 }
361
362 /* the rest operation */
363 for (i = 0; i < len; i++)
364 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
365
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900366 /*
367 * variable update
368 */
369 pkt->actual += total_len;
370
371 if (pkt->actual < pkt->length)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900372 *is_done = 0; /* there are remainder data */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900373 else if (is_short)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900374 *is_done = 1; /* short packet */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900375 else
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900376 *is_done = !pkt->zero; /* send zero packet ? */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900377
378 /*
379 * pipe/irq handling
380 */
381 if (is_short)
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900382 usbhsf_send_terminator(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900383
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900384 usbhsf_tx_irq_ctrl(pipe, !*is_done);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900385 usbhs_pipe_enable(pipe);
386
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900387 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
388 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900389 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900390
391 /*
392 * Transmission end
393 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900394 if (*is_done) {
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900395 if (usbhs_pipe_is_dcp(pipe))
396 usbhs_dcp_control_transfer_done(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900397 }
398
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900399 usbhsf_fifo_unselect(pipe, fifo);
400
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900401 return 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900402
403usbhs_fifo_write_busy:
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900404 usbhsf_fifo_unselect(pipe, fifo);
405
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900406 /*
407 * pipe is busy.
408 * retry in interrupt
409 */
410 usbhsf_tx_irq_ctrl(pipe, 1);
411
412 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900413}
414
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900415struct usbhs_pkt_handle usbhs_fifo_pio_push_handler = {
416 .prepare = usbhsf_pio_try_push,
417 .try_run = usbhsf_pio_try_push,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900418};
419
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700420/*
421 * PIO pop handler
422 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900423static int usbhsf_prepare_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900424{
Kuninori Morimotodad67392011-06-06 14:18:28 +0900425 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900426
427 if (usbhs_pipe_is_busy(pipe))
428 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900429
430 /*
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900431 * pipe enable to prepare packet receive
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900432 */
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900433
434 usbhs_pipe_enable(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900435 usbhsf_rx_irq_ctrl(pipe, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900436
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900437 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900438}
439
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900440static int usbhsf_pio_try_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900441{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900442 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900443 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900444 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900445 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
446 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900447 u8 *buf;
448 u32 data = 0;
449 int maxp = usbhs_pipe_get_maxpacket(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900450 int rcv_len, len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900451 int i, ret;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900452 int total_len = 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900453
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900454 ret = usbhsf_fifo_select(pipe, fifo, 0);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900455 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900456 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900457
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900458 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900459 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900460 goto usbhs_fifo_read_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900461
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900462 rcv_len = usbhsf_fifo_rcv_len(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900463
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900464 buf = pkt->buf + pkt->actual;
465 len = pkt->length - pkt->actual;
466 len = min(len, rcv_len);
467 total_len = len;
468
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900469 /*
470 * Buffer clear if Zero-Length packet
471 *
472 * see
473 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
474 */
475 if (0 == rcv_len) {
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900476 usbhsf_fifo_clear(pipe, fifo);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900477 goto usbhs_fifo_read_end;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900478 }
479
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900480 /*
481 * FIXME
482 *
483 * 32-bit access only
484 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900485 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900486 ioread32_rep(addr, buf, len / 4);
487 len %= 4;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900488 buf += total_len - len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900489 }
490
491 /* the rest operation */
492 for (i = 0; i < len; i++) {
493 if (!(i & 0x03))
494 data = ioread32(addr);
495
496 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
497 }
498
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900499 pkt->actual += total_len;
500
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900501usbhs_fifo_read_end:
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900502 if ((pkt->actual == pkt->length) || /* receive all data */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900503 (total_len < maxp)) { /* short packet */
504 *is_done = 1;
505 usbhsf_rx_irq_ctrl(pipe, 0);
506 usbhs_pipe_disable(pipe);
507 }
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900508
509 dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
510 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900511 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900512
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900513usbhs_fifo_read_busy:
514 usbhsf_fifo_unselect(pipe, fifo);
515
516 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900517}
Kuninori Morimotodad67392011-06-06 14:18:28 +0900518
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900519struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler = {
Kuninori Morimotodad67392011-06-06 14:18:28 +0900520 .prepare = usbhsf_prepare_pop,
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900521 .try_run = usbhsf_pio_try_pop,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900522};
523
524/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700525 * DCP ctrol statge handler
Kuninori Morimotodad67392011-06-06 14:18:28 +0900526 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900527static int usbhsf_ctrl_stage_end(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotodad67392011-06-06 14:18:28 +0900528{
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900529 usbhs_dcp_control_transfer_done(pkt->pipe);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900530
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900531 *is_done = 1;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900532
533 return 0;
534}
535
536struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler = {
537 .prepare = usbhsf_ctrl_stage_end,
538 .try_run = usbhsf_ctrl_stage_end,
539};
540
541/*
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900542 * DMA fifo functions
543 */
544static struct dma_chan *usbhsf_dma_chan_get(struct usbhs_fifo *fifo,
545 struct usbhs_pkt *pkt)
546{
547 if (&usbhs_fifo_dma_push_handler == pkt->handler)
548 return fifo->tx_chan;
549
550 if (&usbhs_fifo_dma_pop_handler == pkt->handler)
551 return fifo->rx_chan;
552
553 return NULL;
554}
555
556static struct usbhs_fifo *usbhsf_get_dma_fifo(struct usbhs_priv *priv,
557 struct usbhs_pkt *pkt)
558{
559 struct usbhs_fifo *fifo;
560
561 /* DMA :: D0FIFO */
562 fifo = usbhsf_get_d0fifo(priv);
563 if (usbhsf_dma_chan_get(fifo, pkt) &&
564 !usbhsf_fifo_is_busy(fifo))
565 return fifo;
566
567 /* DMA :: D1FIFO */
568 fifo = usbhsf_get_d1fifo(priv);
569 if (usbhsf_dma_chan_get(fifo, pkt) &&
570 !usbhsf_fifo_is_busy(fifo))
571 return fifo;
572
573 return NULL;
574}
575
576#define usbhsf_dma_start(p, f) __usbhsf_dma_ctrl(p, f, DREQE)
577#define usbhsf_dma_stop(p, f) __usbhsf_dma_ctrl(p, f, 0)
578static void __usbhsf_dma_ctrl(struct usbhs_pipe *pipe,
579 struct usbhs_fifo *fifo,
580 u16 dreqe)
581{
582 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
583
584 usbhs_bset(priv, fifo->sel, DREQE, dreqe);
585}
586
587#define usbhsf_dma_map(p) __usbhsf_dma_map_ctrl(p, 1)
588#define usbhsf_dma_unmap(p) __usbhsf_dma_map_ctrl(p, 0)
589static int __usbhsf_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
590{
591 struct usbhs_pipe *pipe = pkt->pipe;
592 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
593 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
594
595 return info->dma_map_ctrl(pkt, map);
596}
597
598static void usbhsf_dma_complete(void *arg);
599static void usbhsf_dma_prepare_tasklet(unsigned long data)
600{
601 struct usbhs_pkt *pkt = (struct usbhs_pkt *)data;
602 struct usbhs_pipe *pipe = pkt->pipe;
603 struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe);
604 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
605 struct scatterlist sg;
606 struct dma_async_tx_descriptor *desc;
607 struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt);
608 struct device *dev = usbhs_priv_to_dev(priv);
609 enum dma_data_direction dir;
610 dma_cookie_t cookie;
611
612 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
613
614 sg_init_table(&sg, 1);
615 sg_set_page(&sg, virt_to_page(pkt->dma),
616 pkt->length, offset_in_page(pkt->dma));
617 sg_dma_address(&sg) = pkt->dma + pkt->actual;
618 sg_dma_len(&sg) = pkt->trans;
619
620 desc = chan->device->device_prep_slave_sg(chan, &sg, 1, dir,
621 DMA_PREP_INTERRUPT |
622 DMA_CTRL_ACK);
623 if (!desc)
624 return;
625
626 desc->callback = usbhsf_dma_complete;
627 desc->callback_param = pipe;
628
629 cookie = desc->tx_submit(desc);
630 if (cookie < 0) {
631 dev_err(dev, "Failed to submit dma descriptor\n");
632 return;
633 }
634
635 dev_dbg(dev, " %s %d (%d/ %d)\n",
636 fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero);
637
638 usbhsf_dma_start(pipe, fifo);
639 dma_async_issue_pending(chan);
640}
641
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700642/*
643 * DMA push handler
644 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900645static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done)
646{
647 struct usbhs_pipe *pipe = pkt->pipe;
648 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
649 struct usbhs_fifo *fifo;
650 int len = pkt->length - pkt->actual;
651 int ret;
652
653 if (usbhs_pipe_is_busy(pipe))
654 return 0;
655
656 /* use PIO if packet is less than pio_dma_border or pipe is DCP */
657 if ((len < usbhs_get_dparam(priv, pio_dma_border)) ||
658 usbhs_pipe_is_dcp(pipe))
659 goto usbhsf_pio_prepare_push;
660
661 if (len % 4) /* 32bit alignment */
662 goto usbhsf_pio_prepare_push;
663
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700664 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
665 goto usbhsf_pio_prepare_push;
666
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900667 /* get enable DMA fifo */
668 fifo = usbhsf_get_dma_fifo(priv, pkt);
669 if (!fifo)
670 goto usbhsf_pio_prepare_push;
671
672 if (usbhsf_dma_map(pkt) < 0)
673 goto usbhsf_pio_prepare_push;
674
675 ret = usbhsf_fifo_select(pipe, fifo, 0);
676 if (ret < 0)
677 goto usbhsf_pio_prepare_push_unmap;
678
679 pkt->trans = len;
680
681 tasklet_init(&fifo->tasklet,
682 usbhsf_dma_prepare_tasklet,
683 (unsigned long)pkt);
684
685 tasklet_schedule(&fifo->tasklet);
686
687 return 0;
688
689usbhsf_pio_prepare_push_unmap:
690 usbhsf_dma_unmap(pkt);
691usbhsf_pio_prepare_push:
692 /*
693 * change handler to PIO
694 */
695 pkt->handler = &usbhs_fifo_pio_push_handler;
696
697 return pkt->handler->prepare(pkt, is_done);
698}
699
700static int usbhsf_dma_push_done(struct usbhs_pkt *pkt, int *is_done)
701{
702 struct usbhs_pipe *pipe = pkt->pipe;
703
704 pkt->actual = pkt->trans;
705
706 *is_done = !pkt->zero; /* send zero packet ? */
707
708 usbhsf_dma_stop(pipe, pipe->fifo);
709 usbhsf_dma_unmap(pkt);
710 usbhsf_fifo_unselect(pipe, pipe->fifo);
711
712 return 0;
713}
714
715struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = {
716 .prepare = usbhsf_dma_prepare_push,
717 .dma_done = usbhsf_dma_push_done,
718};
719
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700720/*
721 * DMA pop handler
722 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900723static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done)
724{
725 struct usbhs_pipe *pipe = pkt->pipe;
726 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
727 struct usbhs_fifo *fifo;
728 int len, ret;
729
730 if (usbhs_pipe_is_busy(pipe))
731 return 0;
732
733 if (usbhs_pipe_is_dcp(pipe))
734 goto usbhsf_pio_prepare_pop;
735
736 /* get enable DMA fifo */
737 fifo = usbhsf_get_dma_fifo(priv, pkt);
738 if (!fifo)
739 goto usbhsf_pio_prepare_pop;
740
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700741 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
742 goto usbhsf_pio_prepare_pop;
743
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900744 ret = usbhsf_fifo_select(pipe, fifo, 0);
745 if (ret < 0)
746 goto usbhsf_pio_prepare_pop;
747
748 /* use PIO if packet is less than pio_dma_border */
749 len = usbhsf_fifo_rcv_len(priv, fifo);
750 len = min(pkt->length - pkt->actual, len);
751 if (len % 4) /* 32bit alignment */
752 goto usbhsf_pio_prepare_pop_unselect;
753
754 if (len < usbhs_get_dparam(priv, pio_dma_border))
755 goto usbhsf_pio_prepare_pop_unselect;
756
757 ret = usbhsf_fifo_barrier(priv, fifo);
758 if (ret < 0)
759 goto usbhsf_pio_prepare_pop_unselect;
760
761 if (usbhsf_dma_map(pkt) < 0)
762 goto usbhsf_pio_prepare_pop_unselect;
763
764 /* DMA */
765
766 /*
767 * usbhs_fifo_dma_pop_handler :: prepare
768 * enabled irq to come here.
769 * but it is no longer needed for DMA. disable it.
770 */
771 usbhsf_rx_irq_ctrl(pipe, 0);
772
773 pkt->trans = len;
774
775 tasklet_init(&fifo->tasklet,
776 usbhsf_dma_prepare_tasklet,
777 (unsigned long)pkt);
778
779 tasklet_schedule(&fifo->tasklet);
780
781 return 0;
782
783usbhsf_pio_prepare_pop_unselect:
784 usbhsf_fifo_unselect(pipe, fifo);
785usbhsf_pio_prepare_pop:
786
787 /*
788 * change handler to PIO
789 */
790 pkt->handler = &usbhs_fifo_pio_pop_handler;
791
792 return pkt->handler->try_run(pkt, is_done);
793}
794
795static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done)
796{
797 struct usbhs_pipe *pipe = pkt->pipe;
798 int maxp = usbhs_pipe_get_maxpacket(pipe);
799
800 usbhsf_dma_stop(pipe, pipe->fifo);
801 usbhsf_dma_unmap(pkt);
802 usbhsf_fifo_unselect(pipe, pipe->fifo);
803
804 pkt->actual += pkt->trans;
805
806 if ((pkt->actual == pkt->length) || /* receive all data */
807 (pkt->trans < maxp)) { /* short packet */
808 *is_done = 1;
809 } else {
810 /* re-enable */
811 usbhsf_prepare_pop(pkt, is_done);
812 }
813
814 return 0;
815}
816
817struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = {
818 .prepare = usbhsf_prepare_pop,
819 .try_run = usbhsf_dma_try_pop,
820 .dma_done = usbhsf_dma_pop_done
821};
822
823/*
824 * DMA setting
825 */
826static bool usbhsf_dma_filter(struct dma_chan *chan, void *param)
827{
828 struct sh_dmae_slave *slave = param;
829
830 /*
831 * FIXME
832 *
833 * usbhs doesn't recognize id = 0 as valid DMA
834 */
835 if (0 == slave->slave_id)
836 return false;
837
838 chan->private = slave;
839
840 return true;
841}
842
843static void usbhsf_dma_quit(struct usbhs_priv *priv, struct usbhs_fifo *fifo)
844{
845 if (fifo->tx_chan)
846 dma_release_channel(fifo->tx_chan);
847 if (fifo->rx_chan)
848 dma_release_channel(fifo->rx_chan);
849
850 fifo->tx_chan = NULL;
851 fifo->rx_chan = NULL;
852}
853
854static void usbhsf_dma_init(struct usbhs_priv *priv,
855 struct usbhs_fifo *fifo)
856{
857 struct device *dev = usbhs_priv_to_dev(priv);
858 dma_cap_mask_t mask;
859
860 dma_cap_zero(mask);
861 dma_cap_set(DMA_SLAVE, mask);
862 fifo->tx_chan = dma_request_channel(mask, usbhsf_dma_filter,
863 &fifo->tx_slave);
864
865 dma_cap_zero(mask);
866 dma_cap_set(DMA_SLAVE, mask);
867 fifo->rx_chan = dma_request_channel(mask, usbhsf_dma_filter,
868 &fifo->rx_slave);
869
870 if (fifo->tx_chan || fifo->rx_chan)
Kuninori Morimoto4ce68802011-06-21 09:33:43 +0900871 dev_dbg(dev, "enable DMAEngine (%s%s%s)\n",
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900872 fifo->name,
873 fifo->tx_chan ? "[TX]" : " ",
874 fifo->rx_chan ? "[RX]" : " ");
875}
876
877/*
Kuninori Morimotodad67392011-06-06 14:18:28 +0900878 * irq functions
879 */
880static int usbhsf_irq_empty(struct usbhs_priv *priv,
881 struct usbhs_irq_state *irq_state)
882{
883 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900884 struct device *dev = usbhs_priv_to_dev(priv);
885 int i, ret;
886
887 if (!irq_state->bempsts) {
888 dev_err(dev, "debug %s !!\n", __func__);
889 return -EIO;
890 }
891
892 dev_dbg(dev, "irq empty [0x%04x]\n", irq_state->bempsts);
893
894 /*
895 * search interrupted "pipe"
896 * not "uep".
897 */
898 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
899 if (!(irq_state->bempsts & (1 << i)))
900 continue;
901
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700902 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900903 if (ret < 0)
904 dev_err(dev, "irq_empty run_error %d : %d\n", i, ret);
905 }
906
907 return 0;
908}
909
910static int usbhsf_irq_ready(struct usbhs_priv *priv,
911 struct usbhs_irq_state *irq_state)
912{
913 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900914 struct device *dev = usbhs_priv_to_dev(priv);
915 int i, ret;
916
917 if (!irq_state->brdysts) {
918 dev_err(dev, "debug %s !!\n", __func__);
919 return -EIO;
920 }
921
922 dev_dbg(dev, "irq ready [0x%04x]\n", irq_state->brdysts);
923
924 /*
925 * search interrupted "pipe"
926 * not "uep".
927 */
928 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
929 if (!(irq_state->brdysts & (1 << i)))
930 continue;
931
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700932 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900933 if (ret < 0)
934 dev_err(dev, "irq_ready run_error %d : %d\n", i, ret);
935 }
936
937 return 0;
938}
939
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900940static void usbhsf_dma_complete(void *arg)
941{
942 struct usbhs_pipe *pipe = arg;
943 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
944 struct device *dev = usbhs_priv_to_dev(priv);
945 int ret;
946
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700947 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_DMA_DONE);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900948 if (ret < 0)
949 dev_err(dev, "dma_complete run_error %d : %d\n",
950 usbhs_pipe_number(pipe), ret);
951}
952
Kuninori Morimotodad67392011-06-06 14:18:28 +0900953/*
954 * fifo init
955 */
956void usbhs_fifo_init(struct usbhs_priv *priv)
957{
958 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900959 struct usbhs_fifo *cfifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900960 struct usbhs_fifo *d0fifo = usbhsf_get_d0fifo(priv);
961 struct usbhs_fifo *d1fifo = usbhsf_get_d1fifo(priv);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900962
963 mod->irq_empty = usbhsf_irq_empty;
964 mod->irq_ready = usbhsf_irq_ready;
965 mod->irq_bempsts = 0;
966 mod->irq_brdysts = 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900967
968 cfifo->pipe = NULL;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900969 cfifo->tx_chan = NULL;
970 cfifo->rx_chan = NULL;
971
972 d0fifo->pipe = NULL;
973 d0fifo->tx_chan = NULL;
974 d0fifo->rx_chan = NULL;
975
976 d1fifo->pipe = NULL;
977 d1fifo->tx_chan = NULL;
978 d1fifo->rx_chan = NULL;
979
980 usbhsf_dma_init(priv, usbhsf_get_d0fifo(priv));
981 usbhsf_dma_init(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +0900982}
983
984void usbhs_fifo_quit(struct usbhs_priv *priv)
985{
986 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
987
988 mod->irq_empty = NULL;
989 mod->irq_ready = NULL;
990 mod->irq_bempsts = 0;
991 mod->irq_brdysts = 0;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900992
993 usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv));
994 usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +0900995}
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900996
997int usbhs_fifo_probe(struct usbhs_priv *priv)
998{
999 struct usbhs_fifo *fifo;
1000
1001 /* CFIFO */
1002 fifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001003 fifo->name = "CFIFO";
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001004 fifo->port = CFIFO;
1005 fifo->sel = CFIFOSEL;
1006 fifo->ctr = CFIFOCTR;
1007
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001008 /* D0FIFO */
1009 fifo = usbhsf_get_d0fifo(priv);
1010 fifo->name = "D0FIFO";
1011 fifo->port = D0FIFO;
1012 fifo->sel = D0FIFOSEL;
1013 fifo->ctr = D0FIFOCTR;
1014 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id);
1015 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id);
1016
1017 /* D1FIFO */
1018 fifo = usbhsf_get_d1fifo(priv);
1019 fifo->name = "D1FIFO";
1020 fifo->port = D1FIFO;
1021 fifo->sel = D1FIFOSEL;
1022 fifo->ctr = D1FIFOCTR;
1023 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id);
1024 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id);
1025
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001026 return 0;
1027}
1028
1029void usbhs_fifo_remove(struct usbhs_priv *priv)
1030{
1031}