blob: b9ab8aefcae02f6c5c5428cc276c5c5b89fcec18 [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 Morimoto92352072011-10-10 22:02:57 -0700294 if (usbhs_pipe_is_dcp(pipe)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900295 base |= (1 == write) << 5; /* ISEL */
296
Kuninori Morimoto92352072011-10-10 22:02:57 -0700297 if (usbhs_mod_is_host(priv))
298 usbhs_dcp_dir_for_host(pipe, write);
299 }
300
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900301 /* "base" will be used below */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900302 usbhs_write(priv, fifo->sel, base | MBW_32);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900303
304 /* check ISEL and CURPIPE value */
305 while (timeout--) {
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900306 if (base == (mask & usbhs_read(priv, fifo->sel))) {
307 usbhs_pipe_select_fifo(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900308 return 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900309 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900310 udelay(10);
311 }
312
313 dev_err(dev, "fifo select error\n");
314
315 return -EIO;
316}
317
318/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700319 * PIO push handler
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900320 */
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900321static int usbhsf_pio_try_push(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900322{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900323 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900324 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900325 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900326 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
327 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900328 u8 *buf;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900329 int maxp = usbhs_pipe_get_maxpacket(pipe);
330 int total_len;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900331 int i, ret, len;
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900332 int is_short;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900333
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900334 ret = usbhsf_fifo_select(pipe, fifo, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900335 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900336 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900337
Kuninori Morimotodad67392011-06-06 14:18:28 +0900338 ret = usbhs_pipe_is_accessible(pipe);
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700339 if (ret < 0) {
340 /* inaccessible pipe is not an error */
341 ret = 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900342 goto usbhs_fifo_write_busy;
Kuninori Morimoto4ef85e02011-07-03 17:42:47 -0700343 }
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900344
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900345 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900346 if (ret < 0)
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900347 goto usbhs_fifo_write_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900348
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900349 buf = pkt->buf + pkt->actual;
350 len = pkt->length - pkt->actual;
351 len = min(len, maxp);
352 total_len = len;
353 is_short = total_len < maxp;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900354
355 /*
356 * FIXME
357 *
358 * 32-bit access only
359 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900360 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900361 iowrite32_rep(addr, buf, len / 4);
362 len %= 4;
363 buf += total_len - len;
364 }
365
366 /* the rest operation */
367 for (i = 0; i < len; i++)
368 iowrite8(buf[i], addr + (0x03 - (i & 0x03)));
369
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900370 /*
371 * variable update
372 */
373 pkt->actual += total_len;
374
375 if (pkt->actual < pkt->length)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900376 *is_done = 0; /* there are remainder data */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900377 else if (is_short)
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900378 *is_done = 1; /* short packet */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900379 else
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900380 *is_done = !pkt->zero; /* send zero packet ? */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900381
382 /*
383 * pipe/irq handling
384 */
385 if (is_short)
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900386 usbhsf_send_terminator(pipe, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900387
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900388 usbhsf_tx_irq_ctrl(pipe, !*is_done);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900389 usbhs_pipe_enable(pipe);
390
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900391 dev_dbg(dev, " send %d (%d/ %d/ %d/ %d)\n",
392 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900393 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900394
395 /*
396 * Transmission end
397 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900398 if (*is_done) {
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900399 if (usbhs_pipe_is_dcp(pipe))
400 usbhs_dcp_control_transfer_done(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900401 }
402
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900403 usbhsf_fifo_unselect(pipe, fifo);
404
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900405 return 0;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900406
407usbhs_fifo_write_busy:
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900408 usbhsf_fifo_unselect(pipe, fifo);
409
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900410 /*
411 * pipe is busy.
412 * retry in interrupt
413 */
414 usbhsf_tx_irq_ctrl(pipe, 1);
415
416 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900417}
418
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900419struct usbhs_pkt_handle usbhs_fifo_pio_push_handler = {
420 .prepare = usbhsf_pio_try_push,
421 .try_run = usbhsf_pio_try_push,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900422};
423
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700424/*
425 * PIO pop handler
426 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900427static int usbhsf_prepare_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900428{
Kuninori Morimotodad67392011-06-06 14:18:28 +0900429 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900430
431 if (usbhs_pipe_is_busy(pipe))
432 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900433
434 /*
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900435 * pipe enable to prepare packet receive
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900436 */
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900437
438 usbhs_pipe_enable(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900439 usbhsf_rx_irq_ctrl(pipe, 1);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900440
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900441 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900442}
443
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900444static int usbhsf_pio_try_pop(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900445{
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900446 struct usbhs_pipe *pipe = pkt->pipe;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900447 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900448 struct device *dev = usbhs_priv_to_dev(priv);
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900449 struct usbhs_fifo *fifo = usbhsf_get_cfifo(priv); /* CFIFO */
450 void __iomem *addr = priv->base + fifo->port;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900451 u8 *buf;
452 u32 data = 0;
453 int maxp = usbhs_pipe_get_maxpacket(pipe);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900454 int rcv_len, len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900455 int i, ret;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900456 int total_len = 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900457
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900458 ret = usbhsf_fifo_select(pipe, fifo, 0);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900459 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900460 return 0;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900461
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900462 ret = usbhsf_fifo_barrier(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900463 if (ret < 0)
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900464 goto usbhs_fifo_read_busy;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900465
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900466 rcv_len = usbhsf_fifo_rcv_len(priv, fifo);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900467
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900468 buf = pkt->buf + pkt->actual;
469 len = pkt->length - pkt->actual;
470 len = min(len, rcv_len);
471 total_len = len;
472
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900473 /*
474 * Buffer clear if Zero-Length packet
475 *
476 * see
477 * "Operation" - "FIFO Buffer Memory" - "FIFO Port Function"
478 */
479 if (0 == rcv_len) {
Kuninori Morimotod3af90a2011-06-06 14:18:44 +0900480 usbhsf_fifo_clear(pipe, fifo);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900481 goto usbhs_fifo_read_end;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900482 }
483
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900484 /*
485 * FIXME
486 *
487 * 32-bit access only
488 */
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900489 if (len >= 4 && !((unsigned long)buf & 0x03)) {
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900490 ioread32_rep(addr, buf, len / 4);
491 len %= 4;
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900492 buf += total_len - len;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900493 }
494
495 /* the rest operation */
496 for (i = 0; i < len; i++) {
497 if (!(i & 0x03))
498 data = ioread32(addr);
499
500 buf[i] = (data >> ((i & 0x03) * 8)) & 0xff;
501 }
502
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900503 pkt->actual += total_len;
504
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900505usbhs_fifo_read_end:
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900506 if ((pkt->actual == pkt->length) || /* receive all data */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900507 (total_len < maxp)) { /* short packet */
508 *is_done = 1;
509 usbhsf_rx_irq_ctrl(pipe, 0);
510 usbhs_pipe_disable(pipe);
511 }
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900512
513 dev_dbg(dev, " recv %d (%d/ %d/ %d/ %d)\n",
514 usbhs_pipe_number(pipe),
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900515 pkt->length, pkt->actual, *is_done, pkt->zero);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +0900516
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900517usbhs_fifo_read_busy:
518 usbhsf_fifo_unselect(pipe, fifo);
519
520 return ret;
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900521}
Kuninori Morimotodad67392011-06-06 14:18:28 +0900522
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900523struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler = {
Kuninori Morimotodad67392011-06-06 14:18:28 +0900524 .prepare = usbhsf_prepare_pop,
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +0900525 .try_run = usbhsf_pio_try_pop,
Kuninori Morimotodad67392011-06-06 14:18:28 +0900526};
527
528/*
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700529 * DCP ctrol statge handler
Kuninori Morimotodad67392011-06-06 14:18:28 +0900530 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900531static int usbhsf_ctrl_stage_end(struct usbhs_pkt *pkt, int *is_done)
Kuninori Morimotodad67392011-06-06 14:18:28 +0900532{
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900533 usbhs_dcp_control_transfer_done(pkt->pipe);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900534
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900535 *is_done = 1;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900536
537 return 0;
538}
539
540struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler = {
541 .prepare = usbhsf_ctrl_stage_end,
542 .try_run = usbhsf_ctrl_stage_end,
543};
544
545/*
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900546 * DMA fifo functions
547 */
548static struct dma_chan *usbhsf_dma_chan_get(struct usbhs_fifo *fifo,
549 struct usbhs_pkt *pkt)
550{
551 if (&usbhs_fifo_dma_push_handler == pkt->handler)
552 return fifo->tx_chan;
553
554 if (&usbhs_fifo_dma_pop_handler == pkt->handler)
555 return fifo->rx_chan;
556
557 return NULL;
558}
559
560static struct usbhs_fifo *usbhsf_get_dma_fifo(struct usbhs_priv *priv,
561 struct usbhs_pkt *pkt)
562{
563 struct usbhs_fifo *fifo;
564
565 /* DMA :: D0FIFO */
566 fifo = usbhsf_get_d0fifo(priv);
567 if (usbhsf_dma_chan_get(fifo, pkt) &&
568 !usbhsf_fifo_is_busy(fifo))
569 return fifo;
570
571 /* DMA :: D1FIFO */
572 fifo = usbhsf_get_d1fifo(priv);
573 if (usbhsf_dma_chan_get(fifo, pkt) &&
574 !usbhsf_fifo_is_busy(fifo))
575 return fifo;
576
577 return NULL;
578}
579
580#define usbhsf_dma_start(p, f) __usbhsf_dma_ctrl(p, f, DREQE)
581#define usbhsf_dma_stop(p, f) __usbhsf_dma_ctrl(p, f, 0)
582static void __usbhsf_dma_ctrl(struct usbhs_pipe *pipe,
583 struct usbhs_fifo *fifo,
584 u16 dreqe)
585{
586 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
587
588 usbhs_bset(priv, fifo->sel, DREQE, dreqe);
589}
590
591#define usbhsf_dma_map(p) __usbhsf_dma_map_ctrl(p, 1)
592#define usbhsf_dma_unmap(p) __usbhsf_dma_map_ctrl(p, 0)
593static int __usbhsf_dma_map_ctrl(struct usbhs_pkt *pkt, int map)
594{
595 struct usbhs_pipe *pipe = pkt->pipe;
596 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
597 struct usbhs_pipe_info *info = usbhs_priv_to_pipeinfo(priv);
598
599 return info->dma_map_ctrl(pkt, map);
600}
601
602static void usbhsf_dma_complete(void *arg);
603static void usbhsf_dma_prepare_tasklet(unsigned long data)
604{
605 struct usbhs_pkt *pkt = (struct usbhs_pkt *)data;
606 struct usbhs_pipe *pipe = pkt->pipe;
607 struct usbhs_fifo *fifo = usbhs_pipe_to_fifo(pipe);
608 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
609 struct scatterlist sg;
610 struct dma_async_tx_descriptor *desc;
611 struct dma_chan *chan = usbhsf_dma_chan_get(fifo, pkt);
612 struct device *dev = usbhs_priv_to_dev(priv);
613 enum dma_data_direction dir;
614 dma_cookie_t cookie;
615
616 dir = usbhs_pipe_is_dir_in(pipe) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
617
618 sg_init_table(&sg, 1);
619 sg_set_page(&sg, virt_to_page(pkt->dma),
620 pkt->length, offset_in_page(pkt->dma));
621 sg_dma_address(&sg) = pkt->dma + pkt->actual;
622 sg_dma_len(&sg) = pkt->trans;
623
624 desc = chan->device->device_prep_slave_sg(chan, &sg, 1, dir,
625 DMA_PREP_INTERRUPT |
626 DMA_CTRL_ACK);
627 if (!desc)
628 return;
629
630 desc->callback = usbhsf_dma_complete;
631 desc->callback_param = pipe;
632
633 cookie = desc->tx_submit(desc);
634 if (cookie < 0) {
635 dev_err(dev, "Failed to submit dma descriptor\n");
636 return;
637 }
638
639 dev_dbg(dev, " %s %d (%d/ %d)\n",
640 fifo->name, usbhs_pipe_number(pipe), pkt->length, pkt->zero);
641
642 usbhsf_dma_start(pipe, fifo);
643 dma_async_issue_pending(chan);
644}
645
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700646/*
647 * DMA push handler
648 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900649static int usbhsf_dma_prepare_push(struct usbhs_pkt *pkt, int *is_done)
650{
651 struct usbhs_pipe *pipe = pkt->pipe;
652 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
653 struct usbhs_fifo *fifo;
654 int len = pkt->length - pkt->actual;
655 int ret;
656
657 if (usbhs_pipe_is_busy(pipe))
658 return 0;
659
660 /* use PIO if packet is less than pio_dma_border or pipe is DCP */
661 if ((len < usbhs_get_dparam(priv, pio_dma_border)) ||
662 usbhs_pipe_is_dcp(pipe))
663 goto usbhsf_pio_prepare_push;
664
665 if (len % 4) /* 32bit alignment */
666 goto usbhsf_pio_prepare_push;
667
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700668 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
669 goto usbhsf_pio_prepare_push;
670
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900671 /* get enable DMA fifo */
672 fifo = usbhsf_get_dma_fifo(priv, pkt);
673 if (!fifo)
674 goto usbhsf_pio_prepare_push;
675
676 if (usbhsf_dma_map(pkt) < 0)
677 goto usbhsf_pio_prepare_push;
678
679 ret = usbhsf_fifo_select(pipe, fifo, 0);
680 if (ret < 0)
681 goto usbhsf_pio_prepare_push_unmap;
682
683 pkt->trans = len;
684
685 tasklet_init(&fifo->tasklet,
686 usbhsf_dma_prepare_tasklet,
687 (unsigned long)pkt);
688
689 tasklet_schedule(&fifo->tasklet);
690
691 return 0;
692
693usbhsf_pio_prepare_push_unmap:
694 usbhsf_dma_unmap(pkt);
695usbhsf_pio_prepare_push:
696 /*
697 * change handler to PIO
698 */
699 pkt->handler = &usbhs_fifo_pio_push_handler;
700
701 return pkt->handler->prepare(pkt, is_done);
702}
703
704static int usbhsf_dma_push_done(struct usbhs_pkt *pkt, int *is_done)
705{
706 struct usbhs_pipe *pipe = pkt->pipe;
707
708 pkt->actual = pkt->trans;
709
710 *is_done = !pkt->zero; /* send zero packet ? */
711
712 usbhsf_dma_stop(pipe, pipe->fifo);
713 usbhsf_dma_unmap(pkt);
714 usbhsf_fifo_unselect(pipe, pipe->fifo);
715
716 return 0;
717}
718
719struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = {
720 .prepare = usbhsf_dma_prepare_push,
721 .dma_done = usbhsf_dma_push_done,
722};
723
Kuninori Morimoto233f5192011-07-07 00:23:24 -0700724/*
725 * DMA pop handler
726 */
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900727static int usbhsf_dma_try_pop(struct usbhs_pkt *pkt, int *is_done)
728{
729 struct usbhs_pipe *pipe = pkt->pipe;
730 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
731 struct usbhs_fifo *fifo;
732 int len, ret;
733
734 if (usbhs_pipe_is_busy(pipe))
735 return 0;
736
737 if (usbhs_pipe_is_dcp(pipe))
738 goto usbhsf_pio_prepare_pop;
739
740 /* get enable DMA fifo */
741 fifo = usbhsf_get_dma_fifo(priv, pkt);
742 if (!fifo)
743 goto usbhsf_pio_prepare_pop;
744
Kuninori Morimoto9a12d092011-07-03 17:42:19 -0700745 if (((u32)pkt->buf + pkt->actual) & 0x7) /* 8byte alignment */
746 goto usbhsf_pio_prepare_pop;
747
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900748 ret = usbhsf_fifo_select(pipe, fifo, 0);
749 if (ret < 0)
750 goto usbhsf_pio_prepare_pop;
751
752 /* use PIO if packet is less than pio_dma_border */
753 len = usbhsf_fifo_rcv_len(priv, fifo);
754 len = min(pkt->length - pkt->actual, len);
755 if (len % 4) /* 32bit alignment */
756 goto usbhsf_pio_prepare_pop_unselect;
757
758 if (len < usbhs_get_dparam(priv, pio_dma_border))
759 goto usbhsf_pio_prepare_pop_unselect;
760
761 ret = usbhsf_fifo_barrier(priv, fifo);
762 if (ret < 0)
763 goto usbhsf_pio_prepare_pop_unselect;
764
765 if (usbhsf_dma_map(pkt) < 0)
766 goto usbhsf_pio_prepare_pop_unselect;
767
768 /* DMA */
769
770 /*
771 * usbhs_fifo_dma_pop_handler :: prepare
772 * enabled irq to come here.
773 * but it is no longer needed for DMA. disable it.
774 */
775 usbhsf_rx_irq_ctrl(pipe, 0);
776
777 pkt->trans = len;
778
779 tasklet_init(&fifo->tasklet,
780 usbhsf_dma_prepare_tasklet,
781 (unsigned long)pkt);
782
783 tasklet_schedule(&fifo->tasklet);
784
785 return 0;
786
787usbhsf_pio_prepare_pop_unselect:
788 usbhsf_fifo_unselect(pipe, fifo);
789usbhsf_pio_prepare_pop:
790
791 /*
792 * change handler to PIO
793 */
794 pkt->handler = &usbhs_fifo_pio_pop_handler;
795
796 return pkt->handler->try_run(pkt, is_done);
797}
798
799static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done)
800{
801 struct usbhs_pipe *pipe = pkt->pipe;
802 int maxp = usbhs_pipe_get_maxpacket(pipe);
803
804 usbhsf_dma_stop(pipe, pipe->fifo);
805 usbhsf_dma_unmap(pkt);
806 usbhsf_fifo_unselect(pipe, pipe->fifo);
807
808 pkt->actual += pkt->trans;
809
810 if ((pkt->actual == pkt->length) || /* receive all data */
811 (pkt->trans < maxp)) { /* short packet */
812 *is_done = 1;
813 } else {
814 /* re-enable */
815 usbhsf_prepare_pop(pkt, is_done);
816 }
817
818 return 0;
819}
820
821struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = {
822 .prepare = usbhsf_prepare_pop,
823 .try_run = usbhsf_dma_try_pop,
824 .dma_done = usbhsf_dma_pop_done
825};
826
827/*
828 * DMA setting
829 */
830static bool usbhsf_dma_filter(struct dma_chan *chan, void *param)
831{
832 struct sh_dmae_slave *slave = param;
833
834 /*
835 * FIXME
836 *
837 * usbhs doesn't recognize id = 0 as valid DMA
838 */
839 if (0 == slave->slave_id)
840 return false;
841
842 chan->private = slave;
843
844 return true;
845}
846
847static void usbhsf_dma_quit(struct usbhs_priv *priv, struct usbhs_fifo *fifo)
848{
849 if (fifo->tx_chan)
850 dma_release_channel(fifo->tx_chan);
851 if (fifo->rx_chan)
852 dma_release_channel(fifo->rx_chan);
853
854 fifo->tx_chan = NULL;
855 fifo->rx_chan = NULL;
856}
857
858static void usbhsf_dma_init(struct usbhs_priv *priv,
859 struct usbhs_fifo *fifo)
860{
861 struct device *dev = usbhs_priv_to_dev(priv);
862 dma_cap_mask_t mask;
863
864 dma_cap_zero(mask);
865 dma_cap_set(DMA_SLAVE, mask);
866 fifo->tx_chan = dma_request_channel(mask, usbhsf_dma_filter,
867 &fifo->tx_slave);
868
869 dma_cap_zero(mask);
870 dma_cap_set(DMA_SLAVE, mask);
871 fifo->rx_chan = dma_request_channel(mask, usbhsf_dma_filter,
872 &fifo->rx_slave);
873
874 if (fifo->tx_chan || fifo->rx_chan)
Kuninori Morimoto4ce68802011-06-21 09:33:43 +0900875 dev_dbg(dev, "enable DMAEngine (%s%s%s)\n",
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900876 fifo->name,
877 fifo->tx_chan ? "[TX]" : " ",
878 fifo->rx_chan ? "[RX]" : " ");
879}
880
881/*
Kuninori Morimotodad67392011-06-06 14:18:28 +0900882 * irq functions
883 */
884static int usbhsf_irq_empty(struct usbhs_priv *priv,
885 struct usbhs_irq_state *irq_state)
886{
887 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900888 struct device *dev = usbhs_priv_to_dev(priv);
889 int i, ret;
890
891 if (!irq_state->bempsts) {
892 dev_err(dev, "debug %s !!\n", __func__);
893 return -EIO;
894 }
895
896 dev_dbg(dev, "irq empty [0x%04x]\n", irq_state->bempsts);
897
898 /*
899 * search interrupted "pipe"
900 * not "uep".
901 */
902 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
903 if (!(irq_state->bempsts & (1 << i)))
904 continue;
905
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700906 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900907 if (ret < 0)
908 dev_err(dev, "irq_empty run_error %d : %d\n", i, ret);
909 }
910
911 return 0;
912}
913
914static int usbhsf_irq_ready(struct usbhs_priv *priv,
915 struct usbhs_irq_state *irq_state)
916{
917 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +0900918 struct device *dev = usbhs_priv_to_dev(priv);
919 int i, ret;
920
921 if (!irq_state->brdysts) {
922 dev_err(dev, "debug %s !!\n", __func__);
923 return -EIO;
924 }
925
926 dev_dbg(dev, "irq ready [0x%04x]\n", irq_state->brdysts);
927
928 /*
929 * search interrupted "pipe"
930 * not "uep".
931 */
932 usbhs_for_each_pipe_with_dcp(pipe, priv, i) {
933 if (!(irq_state->brdysts & (1 << i)))
934 continue;
935
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700936 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_TRY_RUN);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900937 if (ret < 0)
938 dev_err(dev, "irq_ready run_error %d : %d\n", i, ret);
939 }
940
941 return 0;
942}
943
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900944static void usbhsf_dma_complete(void *arg)
945{
946 struct usbhs_pipe *pipe = arg;
947 struct usbhs_priv *priv = usbhs_pipe_to_priv(pipe);
948 struct device *dev = usbhs_priv_to_dev(priv);
949 int ret;
950
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700951 ret = usbhsf_pkt_handler(pipe, USBHSF_PKT_DMA_DONE);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900952 if (ret < 0)
953 dev_err(dev, "dma_complete run_error %d : %d\n",
954 usbhs_pipe_number(pipe), ret);
955}
956
Kuninori Morimotodad67392011-06-06 14:18:28 +0900957/*
958 * fifo init
959 */
960void usbhs_fifo_init(struct usbhs_priv *priv)
961{
962 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900963 struct usbhs_fifo *cfifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900964 struct usbhs_fifo *d0fifo = usbhsf_get_d0fifo(priv);
965 struct usbhs_fifo *d1fifo = usbhsf_get_d1fifo(priv);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900966
967 mod->irq_empty = usbhsf_irq_empty;
968 mod->irq_ready = usbhsf_irq_ready;
969 mod->irq_bempsts = 0;
970 mod->irq_brdysts = 0;
Kuninori Morimotod77e3f42011-06-06 14:18:50 +0900971
972 cfifo->pipe = NULL;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900973 cfifo->tx_chan = NULL;
974 cfifo->rx_chan = NULL;
975
976 d0fifo->pipe = NULL;
977 d0fifo->tx_chan = NULL;
978 d0fifo->rx_chan = NULL;
979
980 d1fifo->pipe = NULL;
981 d1fifo->tx_chan = NULL;
982 d1fifo->rx_chan = NULL;
983
984 usbhsf_dma_init(priv, usbhsf_get_d0fifo(priv));
985 usbhsf_dma_init(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +0900986}
987
988void usbhs_fifo_quit(struct usbhs_priv *priv)
989{
990 struct usbhs_mod *mod = usbhs_mod_get_current(priv);
991
992 mod->irq_empty = NULL;
993 mod->irq_ready = NULL;
994 mod->irq_bempsts = 0;
995 mod->irq_brdysts = 0;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900996
997 usbhsf_dma_quit(priv, usbhsf_get_d0fifo(priv));
998 usbhsf_dma_quit(priv, usbhsf_get_d1fifo(priv));
Kuninori Morimotodad67392011-06-06 14:18:28 +0900999}
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001000
1001int usbhs_fifo_probe(struct usbhs_priv *priv)
1002{
1003 struct usbhs_fifo *fifo;
1004
1005 /* CFIFO */
1006 fifo = usbhsf_get_cfifo(priv);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001007 fifo->name = "CFIFO";
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001008 fifo->port = CFIFO;
1009 fifo->sel = CFIFOSEL;
1010 fifo->ctr = CFIFOCTR;
1011
Kuninori Morimotoe73a9892011-06-06 14:19:03 +09001012 /* D0FIFO */
1013 fifo = usbhsf_get_d0fifo(priv);
1014 fifo->name = "D0FIFO";
1015 fifo->port = D0FIFO;
1016 fifo->sel = D0FIFOSEL;
1017 fifo->ctr = D0FIFOCTR;
1018 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d0_tx_id);
1019 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d0_rx_id);
1020
1021 /* D1FIFO */
1022 fifo = usbhsf_get_d1fifo(priv);
1023 fifo->name = "D1FIFO";
1024 fifo->port = D1FIFO;
1025 fifo->sel = D1FIFOSEL;
1026 fifo->ctr = D1FIFOCTR;
1027 fifo->tx_slave.slave_id = usbhs_get_dparam(priv, d1_tx_id);
1028 fifo->rx_slave.slave_id = usbhs_get_dparam(priv, d1_rx_id);
1029
Kuninori Morimotod3af90a2011-06-06 14:18:44 +09001030 return 0;
1031}
1032
1033void usbhs_fifo_remove(struct usbhs_priv *priv)
1034{
1035}