blob: ed6d8e56c13c0f241f0381945c3420d316f063dc [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#ifndef RENESAS_USB_FIFO_H
18#define RENESAS_USB_FIFO_H
19
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090020#include <linux/interrupt.h>
21#include <linux/sh_dma.h>
22#include <asm/dma.h>
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090023#include "pipe.h"
24
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090025#define DMA_ADDR_INVALID (~(dma_addr_t)0)
26
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090027struct usbhs_fifo {
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090028 char *name;
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090029 u32 port; /* xFIFO */
30 u32 sel; /* xFIFOSEL */
31 u32 ctr; /* xFIFOCTR */
Kuninori Morimotod77e3f42011-06-06 14:18:50 +090032
33 struct usbhs_pipe *pipe;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090034 struct tasklet_struct tasklet;
35
36 struct dma_chan *tx_chan;
37 struct dma_chan *rx_chan;
38
39 struct sh_dmae_slave tx_slave;
40 struct sh_dmae_slave rx_slave;
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090041};
42
43struct usbhs_fifo_info {
44 struct usbhs_fifo cfifo;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090045 struct usbhs_fifo d0fifo;
46 struct usbhs_fifo d1fifo;
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090047};
48
Kuninori Morimotodad67392011-06-06 14:18:28 +090049struct usbhs_pkt_handle;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090050struct usbhs_pkt {
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090051 struct list_head node;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090052 struct usbhs_pipe *pipe;
Kuninori Morimotodad67392011-06-06 14:18:28 +090053 struct usbhs_pkt_handle *handler;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090054 dma_addr_t dma;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090055 void *buf;
56 int length;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090057 int trans;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090058 int actual;
Kuninori Morimoto659d4952011-06-06 14:18:23 +090059 int zero;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090060};
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +090061
Kuninori Morimotodad67392011-06-06 14:18:28 +090062struct usbhs_pkt_handle {
Kuninori Morimoto97664a22011-06-06 14:18:38 +090063 int (*prepare)(struct usbhs_pkt *pkt, int *is_done);
64 int (*try_run)(struct usbhs_pkt *pkt, int *is_done);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090065 int (*dma_done)(struct usbhs_pkt *pkt, int *is_done);
Kuninori Morimotodad67392011-06-06 14:18:28 +090066};
67
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +090068/*
69 * fifo
70 */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090071int usbhs_fifo_probe(struct usbhs_priv *priv);
72void usbhs_fifo_remove(struct usbhs_priv *priv);
Kuninori Morimotodad67392011-06-06 14:18:28 +090073void usbhs_fifo_init(struct usbhs_priv *priv);
74void usbhs_fifo_quit(struct usbhs_priv *priv);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +090075
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090076/*
77 * packet info
78 */
Kuninori Morimoto97664a22011-06-06 14:18:38 +090079enum {
80 USBHSF_PKT_PREPARE,
81 USBHSF_PKT_TRY_RUN,
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090082 USBHSF_PKT_DMA_DONE,
Kuninori Morimoto97664a22011-06-06 14:18:38 +090083};
84
Kuninori Morimoto0cb7e612011-06-06 14:18:58 +090085extern struct usbhs_pkt_handle usbhs_fifo_pio_push_handler;
86extern struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler;
Kuninori Morimotodad67392011-06-06 14:18:28 +090087extern struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
88
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090089extern struct usbhs_pkt_handle usbhs_fifo_dma_push_handler;
90extern struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler;
91
92
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090093void usbhs_pkt_init(struct usbhs_pkt *pkt);
Kuninori Morimoto659d4952011-06-06 14:18:23 +090094void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
Kuninori Morimotodad67392011-06-06 14:18:28 +090095 struct usbhs_pkt_handle *handler,
Kuninori Morimoto659d4952011-06-06 14:18:23 +090096 void *buf, int len, int zero);
Kuninori Morimoto97664a22011-06-06 14:18:38 +090097struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
98int __usbhs_pkt_handler(struct usbhs_pipe *pipe, int type);
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090099
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900100#define usbhs_pkt_start(p) __usbhs_pkt_handler(p, USBHSF_PKT_PREPARE)
101#define usbhs_pkt_run(p) __usbhs_pkt_handler(p, USBHSF_PKT_TRY_RUN)
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900102#define usbhs_pkt_dmadone(p) __usbhs_pkt_handler(p, USBHSF_PKT_DMA_DONE)
Kuninori Morimotodad67392011-06-06 14:18:28 +0900103
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900104#endif /* RENESAS_USB_FIFO_H */