blob: 1a345c20105f22895e8bcb0ac58d52e9004dc40a [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 Morimoto6acb95d2011-06-06 14:18:16 +090096}
97
Kuninori Morimoto97664a22011-06-06 14:18:38 +090098static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090099{
100 list_del_init(&pkt->node);
101}
102
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900103static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +0900104{
105 if (list_empty(&pipe->list))
106 return NULL;
107
108 return list_entry(pipe->list.next, struct usbhs_pkt, node);
109}
110
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900111struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt)
112{
113 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
114 unsigned long flags;
115
116 /******************** spin lock ********************/
117 usbhs_lock(priv, flags);
118
119 if (!pkt)
120 pkt = __usbhsf_pkt_get(pipe);
121
122 if (pkt)
123 __usbhsf_pkt_del(pkt);
124
125 usbhs_unlock(priv, flags);
126 /******************** spin unlock ******************/
127
128 return pkt;
129}
130
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700131enum {
132 USBHSF_PKT_PREPARE,
133 USBHSF_PKT_TRY_RUN,
134 USBHSF_PKT_DMA_DONE,
135};
136
137static int usbhsf_pkt_handler(struct usbhs_pipe *pipe, int type)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900138{
139 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900140 struct usbhs_pkt *pkt;
141 struct device *dev = usbhs_priv_to_dev(priv);
142 int (*func)(struct usbhs_pkt *pkt, int *is_done);
143 unsigned long flags;
144 int ret = 0;
145 int is_done = 0;
146
147 /******************** spin lock ********************/
148 usbhs_lock(priv, flags);
149
150 pkt = __usbhsf_pkt_get(pipe);
151 if (!pkt)
152 goto __usbhs_pkt_handler_end;
153
154 switch (type) {
155 case USBHSF_PKT_PREPARE:
156 func = pkt->handler->prepare;
157 break;
158 case USBHSF_PKT_TRY_RUN:
159 func = pkt->handler->try_run;
160 break;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900161 case USBHSF_PKT_DMA_DONE:
162 func = pkt->handler->dma_done;
163 break;
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900164 default:
165 dev_err(dev, "unknown pkt hander\n");
166 goto __usbhs_pkt_handler_end;
167 }
168
169 ret = func(pkt, &is_done);
170
171 if (is_done)
172 __usbhsf_pkt_del(pkt);
173
174__usbhs_pkt_handler_end:
175 usbhs_unlock(priv, flags);
176 /******************** spin unlock ******************/
177
Kuninori Morimoto0432eed2011-06-06 14:18:54 +0900178 if (is_done) {
Kuninori Morimotob3318722011-10-10 22:04:41 -0700179 pkt->done(priv, pkt);
Kuninori Morimoto0432eed2011-06-06 14:18:54 +0900180 usbhs_pkt_start(pipe);
181 }
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900182
183 return ret;
184}
185
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700186void usbhs_pkt_start(struct usbhs_pipe *pipe)
187{
188 usbhsf_pkt_handler(pipe, USBHSF_PKT_PREPARE);
189}
190
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900191/*
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900192 * irq enable/disable function
193 */
194#define usbhsf_irq_empty_ctrl(p, e) usbhsf_irq_callback_ctrl(p, bempsts, e)
195#define usbhsf_irq_ready_ctrl(p, e) usbhsf_irq_callback_ctrl(p, brdysts, e)
196#define usbhsf_irq_callback_ctrl(pipe, status, enable) \
197 ({ \
198 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe); \
199 struct usbhs_mod *mod = usbhs_mod_get_current(priv); \
200 u16 status = (1 << usbhs_pipe_number(pipe)); \
201 if (!mod) \
202 return; \
203 if (enable) \
204 mod->irq_##status |= status; \
205 else \
206 mod->irq_##status &= ~status; \
207 usbhs_irq_callback_update(priv, mod); \
208 })
209
210static void usbhsf_tx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
211{
212 /*
213 * And DCP pipe can NOT use "ready interrupt" for "send"
214 * it should use "empty" interrupt.
215 * see
216 * "Operation" - "Interrupt Function" - "BRDY Interrupt"
217 *
218 * on the other hand, normal pipe can use "ready interrupt" for "send"
219 * even though it is single/double buffer
220 */
221 if (usbhs_pipe_is_dcp(pipe))
222 usbhsf_irq_empty_ctrl(pipe, enable);
223 else
224 usbhsf_irq_ready_ctrl(pipe, enable);
225}
226
227static void usbhsf_rx_irq_ctrl(struct usbhs_pipe *pipe, int enable)
228{
229 usbhsf_irq_ready_ctrl(pipe, enable);
230}
231
232/*
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900233 * FIFO ctrl
234 */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900235static void usbhsf_send_terminator(struct usbhs_pipe *pipe,
236 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900237{
238 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
239
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900240 usbhs_bset(priv, fifo->ctr, BVAL, BVAL);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900241}
242
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900243static int usbhsf_fifo_barrier(struct usbhs_priv *priv,
244 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900245{
246 int timeout = 1024;
247
248 do {
249 /* The FIFO port is accessible */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900250 if (usbhs_read(priv, fifo->ctr) & FRDY)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900251 return 0;
252
253 udelay(10);
254 } while (timeout--);
255
256 return -EBUSY;
257}
258
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900259static void usbhsf_fifo_clear(struct usbhs_pipe *pipe,
260 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900261{
262 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
263
264 if (!usbhs_pipe_is_dcp(pipe))
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900265 usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900266
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900267 usbhs_write(priv, fifo->ctr, BCLR);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900268}
269
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900270static int usbhsf_fifo_rcv_len(struct usbhs_priv *priv,
271 struct usbhs_fifo *fifo)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900272{
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900273 return usbhs_read(priv, fifo->ctr) & DTLN_MASK;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900274}
275
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900276static void usbhsf_fifo_unselect(struct usbhs_pipe *pipe,
277 struct usbhs_fifo *fifo)
278{
279 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
280
281 usbhs_pipe_select_fifo(pipe, NULL);
282 usbhs_write(priv, fifo->sel, 0);
283}
284
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900285static int usbhsf_fifo_select(struct usbhs_pipe *pipe,
286 struct usbhs_fifo *fifo,
287 int write)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900288{
289 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
290 struct device *dev = usbhs_priv_to_dev(priv);
291 int timeout = 1024;
292 u16 mask = ((1 << 5) | 0xF); /* mask of ISEL | CURPIPE */
293 u16 base = usbhs_pipe_number(pipe); /* CURPIPE */
294
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900295 if (usbhs_pipe_is_busy(pipe) ||
296 usbhsf_fifo_is_busy(fifo))
297 return -EBUSY;
298
Kuninori Morimoto92352072011-10-10 22:02:57 -0700299 if (usbhs_pipe_is_dcp(pipe)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900300 base |= (1 == write) << 5; /* ISEL */
301
Kuninori Morimoto92352072011-10-10 22:02:57 -0700302 if (usbhs_mod_is_host(priv))
303 usbhs_dcp_dir_for_host(pipe, write);
304 }
305
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900306 /* "base" will be used below */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900307 usbhs_write(priv, fifo->sel, base | MBW_32);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900308
309 /* check ISEL and CURPIPE value */
310 while (timeout--) {
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900311 if (base == (mask & usbhs_read(priv, fifo->sel))) {
312 usbhs_pipe_select_fifo(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900313 return 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900314 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900315 udelay(10);
316 }
317
318 dev_err(dev, "fifo select error\n");
319
320 return -EIO;
321}
322
323/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700324 * PIO push handler
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900325 */
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900326static int usbhsf_pio_try_push(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900327{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900328 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900329 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900330 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900331 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
332 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900333 u8 *buf;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900334 int maxp = usbhs_pipe_get_maxpacket(pipe);
335 int total_len;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900336 int i, ret, len;
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900337 int is_short;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900338
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900339 ret = usbhsf_fifo_select(pipe, fifo, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900340 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900341 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900342
Kuninori Morimotodad67392011-06-06 14:18:28 +0900343 ret = usbhs_pipe_is_accessible(pipe);
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700344 if (ret < 0) {
345 /* inaccessible pipe is not an error */
346 ret = 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900347 goto usbhs_fifo_write_busy;
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700348 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900349
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900350 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900351 if (ret < 0)
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900352 goto usbhs_fifo_write_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900353
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900354 buf = pkt->buf + pkt->actual;
355 len = pkt->length - pkt->actual;
356 len = min(len, maxp);
357 total_len = len;
358 is_short = total_len < maxp;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900359
360 /*
361 * FIXME
362 *
363 * 32-bit access only
364 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900365 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900366 iowrite32_rep(addr, buf, len / 4);
367 len %= 4;
368 buf += total_len - len;
369 }
370
371 /* the rest operation */
372 for (i = 0; i < len; i++)
373 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
374
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900375 /*
376 * variable update
377 */
378 pkt->actual += total_len;
379
380 if (pkt->actual < pkt->length)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900381 *is_done = 0; /* there are remainder data */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900382 else if (is_short)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900383 *is_done = 1; /* short packet */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900384 else
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900385 *is_done = !pkt->zero; /* send zero packet ? */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900386
387 /*
388 * pipe/irq handling
389 */
390 if (is_short)
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900391 usbhsf_send_terminator(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900392
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900393 usbhsf_tx_irq_ctrl(pipe, !*is_done);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900394 usbhs_pipe_enable(pipe);
395
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900396 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
397 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900398 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900399
400 /*
401 * Transmission end
402 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900403 if (*is_done) {
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900404 if (usbhs_pipe_is_dcp(pipe))
405 usbhs_dcp_control_transfer_done(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900406 }
407
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900408 usbhsf_fifo_unselect(pipe, fifo);
409
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900410 return 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900411
412usbhs_fifo_write_busy:
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900413 usbhsf_fifo_unselect(pipe, fifo);
414
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900415 /*
416 * pipe is busy.
417 * retry in interrupt
418 */
419 usbhsf_tx_irq_ctrl(pipe, 1);
420
421 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900422}
423
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900424struct usbhs_pkt_handle usbhs_fifo_pio_push_handler = {
425 .prepare = usbhsf_pio_try_push,
426 .try_run = usbhsf_pio_try_push,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900427};
428
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700429/*
430 * PIO pop handler
431 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900432static int usbhsf_prepare_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900433{
Kuninori Morimotodad67392011-06-06 14:18:28 +0900434 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900435
436 if (usbhs_pipe_is_busy(pipe))
437 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900438
439 /*
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900440 * pipe enable to prepare packet receive
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900441 */
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900442
443 usbhs_pipe_enable(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900444 usbhsf_rx_irq_ctrl(pipe, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900445
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900446 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900447}
448
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900449static int usbhsf_pio_try_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900450{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900451 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900452 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900453 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900454 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
455 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900456 u8 *buf;
457 u32 data = 0;
458 int maxp = usbhs_pipe_get_maxpacket(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900459 int rcv_len, len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900460 int i, ret;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900461 int total_len = 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900462
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900463 ret = usbhsf_fifo_select(pipe, fifo, 0);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900464 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900465 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900466
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900467 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900468 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900469 goto usbhs_fifo_read_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900470
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900471 rcv_len = usbhsf_fifo_rcv_len(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900472
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900473 buf = pkt->buf + pkt->actual;
474 len = pkt->length - pkt->actual;
475 len = min(len, rcv_len);
476 total_len = len;
477
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900478 /*
Kuninori Morimoto6ff5d092011-10-10 22:05:51 -0700479 * update actual length first here to decide disable pipe.
480 * if this pipe keeps BUF status and all data were popped,
481 * then, next interrupt/token will be issued again
482 */
483 pkt->actual += total_len;
484
485 if ((pkt->actual == pkt->length) || /* receive all data */
486 (total_len < maxp)) { /* short packet */
487 *is_done = 1;
488 usbhsf_rx_irq_ctrl(pipe, 0);
489 usbhs_pipe_disable(pipe); /* disable pipe first */
490 }
491
492 /*
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900493 * Buffer clear if Zero-Length packet
494 *
495 * see
496 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
497 */
498 if (0 == rcv_len) {
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900499 usbhsf_fifo_clear(pipe, fifo);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900500 goto usbhs_fifo_read_end;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900501 }
502
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900503 /*
504 * FIXME
505 *
506 * 32-bit access only
507 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900508 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900509 ioread32_rep(addr, buf, len / 4);
510 len %= 4;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900511 buf += total_len - len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900512 }
513
514 /* the rest operation */
515 for (i = 0; i < len; i++) {
516 if (!(i & 0x03))
517 data = ioread32(addr);
518
519 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
520 }
521
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900522usbhs_fifo_read_end:
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900523 dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
524 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900525 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900526
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900527usbhs_fifo_read_busy:
528 usbhsf_fifo_unselect(pipe, fifo);
529
530 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900531}
Kuninori Morimotodad67392011-06-06 14:18:28 +0900532
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900533struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler = {
Kuninori Morimotodad67392011-06-06 14:18:28 +0900534 .prepare = usbhsf_prepare_pop,
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900535 .try_run = usbhsf_pio_try_pop,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900536};
537
538/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700539 * DCP ctrol statge handler
Kuninori Morimotodad67392011-06-06 14:18:28 +0900540 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900541static int usbhsf_ctrl_stage_end(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotodad67392011-06-06 14:18:28 +0900542{
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900543 usbhs_dcp_control_transfer_done(pkt->pipe);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900544
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900545 *is_done = 1;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900546
547 return 0;
548}
549
550struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler = {
551 .prepare = usbhsf_ctrl_stage_end,
552 .try_run = usbhsf_ctrl_stage_end,
553};
554
555/*
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900556 * DMA fifo functions
557 */
558static struct dma_chan *usbhsf_dma_chan_get(struct usbhs_fifo *fifo,
559 struct usbhs_pkt *pkt)
560{
561 if (&usbhs_fifo_dma_push_handler == pkt->handler)
562 return fifo->tx_chan;
563
564 if (&usbhs_fifo_dma_pop_handler == pkt->handler)
565 return fifo->rx_chan;
566
567 return NULL;
568}
569
570static struct usbhs_fifo *usbhsf_get_dma_fifo(struct usbhs_priv *priv,
571 struct usbhs_pkt *pkt)
572{
573 struct usbhs_fifo *fifo;
574
575 /* DMA :: D0FIFO */
576 fifo = usbhsf_get_d0fifo(priv);
577 if (usbhsf_dma_chan_get(fifo, pkt) &&
578 !usbhsf_fifo_is_busy(fifo))
579 return fifo;
580
581 /* DMA :: D1FIFO */
582 fifo = usbhsf_get_d1fifo(priv);
583 if (usbhsf_dma_chan_get(fifo, pkt) &&
584 !usbhsf_fifo_is_busy(fifo))
585 return fifo;
586
587 return NULL;
588}
589
590#define usbhsf_dma_start(p, f) __usbhsf_dma_ctrl(p, f, DREQE)
591#define usbhsf_dma_stop(p, f) __usbhsf_dma_ctrl(p, f, 0)
592static void __usbhsf_dma_ctrl(struct usbhs_pipe *pipe,
593 struct usbhs_fifo *fifo,
594 u16 dreqe)
595{
596 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
597
598 usbhs_bset(priv, fifo->sel, DREQE, dreqe);
599}
600
601#define usbhsf_dma_map(p) __usbhsf_dma_map_ctrl(p, 1)
602#define usbhsf_dma_unmap(p) __usbhsf_dma_map_ctrl(p, 0)
603static int __usbhsf_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
604{
605 struct usbhs_pipe *pipe = pkt->pipe;
606 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
607 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
608
609 return info->dma_map_ctrl(pkt, map);
610}
611
612static void usbhsf_dma_complete(void *arg);
613static void usbhsf_dma_prepare_tasklet(unsigned long data)
614{
615 struct usbhs_pkt *pkt = (struct usbhs_pkt *)data;
616 struct usbhs_pipe *pipe = pkt->pipe;
617 struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe);
618 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
619 struct scatterlist sg;
620 struct dma_async_tx_descriptor *desc;
621 struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt);
622 struct device *dev = usbhs_priv_to_dev(priv);
623 enum dma_data_direction dir;
624 dma_cookie_t cookie;
625
626 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
627
628 sg_init_table(&sg, 1);
629 sg_set_page(&sg, virt_to_page(pkt->dma),
630 pkt->length, offset_in_page(pkt->dma));
631 sg_dma_address(&sg) = pkt->dma + pkt->actual;
632 sg_dma_len(&sg) = pkt->trans;
633
634 desc = chan->device->device_prep_slave_sg(chan, &sg, 1, dir,
635 DMA_PREP_INTERRUPT |
636 DMA_CTRL_ACK);
637 if (!desc)
638 return;
639
640 desc->callback = usbhsf_dma_complete;
641 desc->callback_param = pipe;
642
643 cookie = desc->tx_submit(desc);
644 if (cookie < 0) {
645 dev_err(dev, "Failed to submit dma descriptor\n");
646 return;
647 }
648
649 dev_dbg(dev, " %s %d (%d/ %d)\n",
650 fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero);
651
652 usbhsf_dma_start(pipe, fifo);
653 dma_async_issue_pending(chan);
654}
655
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700656/*
657 * DMA push handler
658 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900659static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done)
660{
661 struct usbhs_pipe *pipe = pkt->pipe;
662 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
663 struct usbhs_fifo *fifo;
664 int len = pkt->length - pkt->actual;
665 int ret;
666
667 if (usbhs_pipe_is_busy(pipe))
668 return 0;
669
670 /* use PIO if packet is less than pio_dma_border or pipe is DCP */
671 if ((len < usbhs_get_dparam(priv, pio_dma_border)) ||
672 usbhs_pipe_is_dcp(pipe))
673 goto usbhsf_pio_prepare_push;
674
675 if (len % 4) /* 32bit alignment */
676 goto usbhsf_pio_prepare_push;
677
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700678 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
679 goto usbhsf_pio_prepare_push;
680
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900681 /* get enable DMA fifo */
682 fifo = usbhsf_get_dma_fifo(priv, pkt);
683 if (!fifo)
684 goto usbhsf_pio_prepare_push;
685
686 if (usbhsf_dma_map(pkt) < 0)
687 goto usbhsf_pio_prepare_push;
688
689 ret = usbhsf_fifo_select(pipe, fifo, 0);
690 if (ret < 0)
691 goto usbhsf_pio_prepare_push_unmap;
692
693 pkt->trans = len;
694
695 tasklet_init(&fifo->tasklet,
696 usbhsf_dma_prepare_tasklet,
697 (unsigned long)pkt);
698
699 tasklet_schedule(&fifo->tasklet);
700
701 return 0;
702
703usbhsf_pio_prepare_push_unmap:
704 usbhsf_dma_unmap(pkt);
705usbhsf_pio_prepare_push:
706 /*
707 * change handler to PIO
708 */
709 pkt->handler = &usbhs_fifo_pio_push_handler;
710
711 return pkt->handler->prepare(pkt, is_done);
712}
713
714static int usbhsf_dma_push_done(struct usbhs_pkt *pkt, int *is_done)
715{
716 struct usbhs_pipe *pipe = pkt->pipe;
717
718 pkt->actual = pkt->trans;
719
720 *is_done = !pkt->zero; /* send zero packet ? */
721
722 usbhsf_dma_stop(pipe, pipe->fifo);
723 usbhsf_dma_unmap(pkt);
724 usbhsf_fifo_unselect(pipe, pipe->fifo);
725
726 return 0;
727}
728
729struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = {
730 .prepare = usbhsf_dma_prepare_push,
731 .dma_done = usbhsf_dma_push_done,
732};
733
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700734/*
735 * DMA pop handler
736 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900737static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done)
738{
739 struct usbhs_pipe *pipe = pkt->pipe;
740 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
741 struct usbhs_fifo *fifo;
742 int len, ret;
743
744 if (usbhs_pipe_is_busy(pipe))
745 return 0;
746
747 if (usbhs_pipe_is_dcp(pipe))
748 goto usbhsf_pio_prepare_pop;
749
750 /* get enable DMA fifo */
751 fifo = usbhsf_get_dma_fifo(priv, pkt);
752 if (!fifo)
753 goto usbhsf_pio_prepare_pop;
754
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700755 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
756 goto usbhsf_pio_prepare_pop;
757
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900758 ret = usbhsf_fifo_select(pipe, fifo, 0);
759 if (ret < 0)
760 goto usbhsf_pio_prepare_pop;
761
762 /* use PIO if packet is less than pio_dma_border */
763 len = usbhsf_fifo_rcv_len(priv, fifo);
764 len = min(pkt->length - pkt->actual, len);
765 if (len % 4) /* 32bit alignment */
766 goto usbhsf_pio_prepare_pop_unselect;
767
768 if (len < usbhs_get_dparam(priv, pio_dma_border))
769 goto usbhsf_pio_prepare_pop_unselect;
770
771 ret = usbhsf_fifo_barrier(priv, fifo);
772 if (ret < 0)
773 goto usbhsf_pio_prepare_pop_unselect;
774
775 if (usbhsf_dma_map(pkt) < 0)
776 goto usbhsf_pio_prepare_pop_unselect;
777
778 /* DMA */
779
780 /*
781 * usbhs_fifo_dma_pop_handler :: prepare
782 * enabled irq to come here.
783 * but it is no longer needed for DMA. disable it.
784 */
785 usbhsf_rx_irq_ctrl(pipe, 0);
786
787 pkt->trans = len;
788
789 tasklet_init(&fifo->tasklet,
790 usbhsf_dma_prepare_tasklet,
791 (unsigned long)pkt);
792
793 tasklet_schedule(&fifo->tasklet);
794
795 return 0;
796
797usbhsf_pio_prepare_pop_unselect:
798 usbhsf_fifo_unselect(pipe, fifo);
799usbhsf_pio_prepare_pop:
800
801 /*
802 * change handler to PIO
803 */
804 pkt->handler = &usbhs_fifo_pio_pop_handler;
805
806 return pkt->handler->try_run(pkt, is_done);
807}
808
809static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done)
810{
811 struct usbhs_pipe *pipe = pkt->pipe;
812 int maxp = usbhs_pipe_get_maxpacket(pipe);
813
814 usbhsf_dma_stop(pipe, pipe->fifo);
815 usbhsf_dma_unmap(pkt);
816 usbhsf_fifo_unselect(pipe, pipe->fifo);
817
818 pkt->actual += pkt->trans;
819
820 if ((pkt->actual == pkt->length) || /* receive all data */
821 (pkt->trans < maxp)) { /* short packet */
822 *is_done = 1;
823 } else {
824 /* re-enable */
825 usbhsf_prepare_pop(pkt, is_done);
826 }
827
828 return 0;
829}
830
831struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = {
832 .prepare = usbhsf_prepare_pop,
833 .try_run = usbhsf_dma_try_pop,
834 .dma_done = usbhsf_dma_pop_done
835};
836
837/*
838 * DMA setting
839 */
840static bool usbhsf_dma_filter(struct dma_chan *chan, void *param)
841{
842 struct sh_dmae_slave *slave = param;
843
844 /*
845 * FIXME
846 *
847 * usbhs doesn't recognize id = 0 as valid DMA
848 */
849 if (0 == slave->slave_id)
850 return false;
851
852 chan->private = slave;
853
854 return true;
855}
856
857static void usbhsf_dma_quit(struct usbhs_priv *priv, struct usbhs_fifo *fifo)
858{
859 if (fifo->tx_chan)
860 dma_release_channel(fifo->tx_chan);
861 if (fifo->rx_chan)
862 dma_release_channel(fifo->rx_chan);
863
864 fifo->tx_chan = NULL;
865 fifo->rx_chan = NULL;
866}
867
868static void usbhsf_dma_init(struct usbhs_priv *priv,
869 struct usbhs_fifo *fifo)
870{
871 struct device *dev = usbhs_priv_to_dev(priv);
872 dma_cap_mask_t mask;
873
874 dma_cap_zero(mask);
875 dma_cap_set(DMA_SLAVE, mask);
876 fifo->tx_chan = dma_request_channel(mask, usbhsf_dma_filter,
877 &fifo->tx_slave);
878
879 dma_cap_zero(mask);
880 dma_cap_set(DMA_SLAVE, mask);
881 fifo->rx_chan = dma_request_channel(mask, usbhsf_dma_filter,
882 &fifo->rx_slave);
883
884 if (fifo->tx_chan || fifo->rx_chan)
Kuninori Morimoto4ce68802011-06-21 09:33:43 +0900885 dev_dbg(dev, "enable DMAEngine (%s%s%s)\n",
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900886 fifo->name,
887 fifo->tx_chan ? "[TX]" : " ",
888 fifo->rx_chan ? "[RX]" : " ");
889}
890
891/*
Kuninori Morimotodad67392011-06-06 14:18:28 +0900892 * irq functions
893 */
894static int usbhsf_irq_empty(struct usbhs_priv *priv,
895 struct usbhs_irq_state *irq_state)
896{
897 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900898 struct device *dev = usbhs_priv_to_dev(priv);
899 int i, ret;
900
901 if (!irq_state->bempsts) {
902 dev_err(dev, "debug %s !!\n", __func__);
903 return -EIO;
904 }
905
906 dev_dbg(dev, "irq empty [0x%04x]\n", irq_state->bempsts);
907
908 /*
909 * search interrupted "pipe"
910 * not "uep".
911 */
912 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
913 if (!(irq_state->bempsts & (1 << i)))
914 continue;
915
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700916 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900917 if (ret < 0)
918 dev_err(dev, "irq_empty run_error %d : %d\n", i, ret);
919 }
920
921 return 0;
922}
923
924static int usbhsf_irq_ready(struct usbhs_priv *priv,
925 struct usbhs_irq_state *irq_state)
926{
927 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900928 struct device *dev = usbhs_priv_to_dev(priv);
929 int i, ret;
930
931 if (!irq_state->brdysts) {
932 dev_err(dev, "debug %s !!\n", __func__);
933 return -EIO;
934 }
935
936 dev_dbg(dev, "irq ready [0x%04x]\n", irq_state->brdysts);
937
938 /*
939 * search interrupted "pipe"
940 * not "uep".
941 */
942 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
943 if (!(irq_state->brdysts & (1 << i)))
944 continue;
945
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700946 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900947 if (ret < 0)
948 dev_err(dev, "irq_ready run_error %d : %d\n", i, ret);
949 }
950
951 return 0;
952}
953
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900954static void usbhsf_dma_complete(void *arg)
955{
956 struct usbhs_pipe *pipe = arg;
957 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
958 struct device *dev = usbhs_priv_to_dev(priv);
959 int ret;
960
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700961 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_DMA_DONE);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900962 if (ret < 0)
963 dev_err(dev, "dma_complete run_error %d : %d\n",
964 usbhs_pipe_number(pipe), ret);
965}
966
Kuninori Morimotodad67392011-06-06 14:18:28 +0900967/*
968 * fifo init
969 */
970void usbhs_fifo_init(struct usbhs_priv *priv)
971{
972 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900973 struct usbhs_fifo *cfifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900974 struct usbhs_fifo *d0fifo = usbhsf_get_d0fifo(priv);
975 struct usbhs_fifo *d1fifo = usbhsf_get_d1fifo(priv);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900976
977 mod->irq_empty = usbhsf_irq_empty;
978 mod->irq_ready = usbhsf_irq_ready;
979 mod->irq_bempsts = 0;
980 mod->irq_brdysts = 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900981
982 cfifo->pipe = NULL;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900983 cfifo->tx_chan = NULL;
984 cfifo->rx_chan = NULL;
985
986 d0fifo->pipe = NULL;
987 d0fifo->tx_chan = NULL;
988 d0fifo->rx_chan = NULL;
989
990 d1fifo->pipe = NULL;
991 d1fifo->tx_chan = NULL;
992 d1fifo->rx_chan = NULL;
993
994 usbhsf_dma_init(priv, usbhsf_get_d0fifo(priv));
995 usbhsf_dma_init(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +0900996}
997
998void usbhs_fifo_quit(struct usbhs_priv *priv)
999{
1000 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
1001
1002 mod->irq_empty = NULL;
1003 mod->irq_ready = NULL;
1004 mod->irq_bempsts = 0;
1005 mod->irq_brdysts = 0;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001006
1007 usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv));
1008 usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +09001009}
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001010
1011int usbhs_fifo_probe(struct usbhs_priv *priv)
1012{
1013 struct usbhs_fifo *fifo;
1014
1015 /* CFIFO */
1016 fifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001017 fifo->name = "CFIFO";
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001018 fifo->port = CFIFO;
1019 fifo->sel = CFIFOSEL;
1020 fifo->ctr = CFIFOCTR;
1021
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001022 /* D0FIFO */
1023 fifo = usbhsf_get_d0fifo(priv);
1024 fifo->name = "D0FIFO";
1025 fifo->port = D0FIFO;
1026 fifo->sel = D0FIFOSEL;
1027 fifo->ctr = D0FIFOCTR;
1028 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id);
1029 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id);
1030
1031 /* D1FIFO */
1032 fifo = usbhsf_get_d1fifo(priv);
1033 fifo->name = "D1FIFO";
1034 fifo->port = D1FIFO;
1035 fifo->sel = D1FIFOSEL;
1036 fifo->ctr = D1FIFOCTR;
1037 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id);
1038 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id);
1039
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001040 return 0;
1041}
1042
1043void usbhs_fifo_remove(struct usbhs_priv *priv)
1044{
1045}