blob: 8b98507d7abc0ea43e9c4931e68971689fcae20a [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>
Guennadi Liakhovetski6e4b74e2012-02-14 11:37:21 +010022#include <linux/workqueue.h>
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090023#include <asm/dma.h>
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090024#include "pipe.h"
25
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090026struct usbhs_fifo {
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090027 char *name;
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090028 u32 port; /* xFIFO */
29 u32 sel; /* xFIFOSEL */
30 u32 ctr; /* xFIFOCTR */
Kuninori Morimotod77e3f42011-06-06 14:18:50 +090031
32 struct usbhs_pipe *pipe;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090033
34 struct dma_chan *tx_chan;
35 struct dma_chan *rx_chan;
36
37 struct sh_dmae_slave tx_slave;
38 struct sh_dmae_slave rx_slave;
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090039};
40
Yoshihiro Shimodad3cf6a42014-11-10 20:02:47 +090041#define USBHS_MAX_NUM_DFIFO 4
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090042struct usbhs_fifo_info {
43 struct usbhs_fifo cfifo;
Yoshihiro Shimodac907e422014-11-10 20:02:44 +090044 struct usbhs_fifo dfifo[USBHS_MAX_NUM_DFIFO];
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090045};
Yoshihiro Shimoda3a2634a2014-11-10 20:02:45 +090046#define usbhsf_get_dnfifo(p, n) (&((p)->fifo_info.dfifo[n]))
Kuninori Morimoto2d9c7f32015-04-14 04:10:04 +000047#define usbhs_for_each_dfifo(priv, dfifo, i) \
48 for ((i) = 0; \
49 ((i) < USBHS_MAX_NUM_DFIFO) && \
50 ((dfifo) = usbhsf_get_dnfifo(priv, (i))); \
51 (i)++)
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090052
Kuninori Morimotodad67392011-06-06 14:18:28 +090053struct usbhs_pkt_handle;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090054struct usbhs_pkt {
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090055 struct list_head node;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090056 struct usbhs_pipe *pipe;
Julia Lawallfcb42e22015-12-27 21:50:29 +010057 const struct usbhs_pkt_handle *handler;
Kuninori Morimotob3318722011-10-10 22:04:41 -070058 void (*done)(struct usbhs_priv *priv,
59 struct usbhs_pkt *pkt);
Guennadi Liakhovetski6e4b74e2012-02-14 11:37:21 +010060 struct work_struct work;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090061 dma_addr_t dma;
Yoshihiro Shimodaab330cf2015-03-12 15:35:20 +090062 dma_cookie_t cookie;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090063 void *buf;
64 int length;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090065 int trans;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090066 int actual;
Kuninori Morimoto659d4952011-06-06 14:18:23 +090067 int zero;
Kuninori Morimoto3edeee32011-12-08 18:28:54 -080068 int sequence;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090069};
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +090070
Kuninori Morimotodad67392011-06-06 14:18:28 +090071struct usbhs_pkt_handle {
Kuninori Morimoto97664a22011-06-06 14:18:38 +090072 int (*prepare)(struct usbhs_pkt *pkt, int *is_done);
73 int (*try_run)(struct usbhs_pkt *pkt, int *is_done);
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090074 int (*dma_done)(struct usbhs_pkt *pkt, int *is_done);
Kuninori Morimotodad67392011-06-06 14:18:28 +090075};
76
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +090077/*
78 * fifo
79 */
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090080int usbhs_fifo_probe(struct usbhs_priv *priv);
81void usbhs_fifo_remove(struct usbhs_priv *priv);
Kuninori Morimotodad67392011-06-06 14:18:28 +090082void usbhs_fifo_init(struct usbhs_priv *priv);
83void usbhs_fifo_quit(struct usbhs_priv *priv);
Yoshihiro Shimodacdeb7942014-11-04 10:05:45 +090084void usbhs_fifo_clear_dcp(struct usbhs_pipe *pipe);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +090085
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090086/*
87 * packet info
88 */
Julia Lawallfcb42e22015-12-27 21:50:29 +010089extern const struct usbhs_pkt_handle usbhs_fifo_pio_push_handler;
90extern const struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler;
91extern const struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
Kuninori Morimotodad67392011-06-06 14:18:28 +090092
Julia Lawallfcb42e22015-12-27 21:50:29 +010093extern const struct usbhs_pkt_handle usbhs_fifo_dma_push_handler;
94extern const struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090095
Julia Lawallfcb42e22015-12-27 21:50:29 +010096extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_in_handler;
97extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_out_handler;
Kuninori Morimoto9e74d602011-10-10 22:07:08 -070098
Julia Lawallfcb42e22015-12-27 21:50:29 +010099extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_in_handler;
100extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_out_handler;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +0900101
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +0900102void usbhs_pkt_init(struct usbhs_pkt *pkt);
Kuninori Morimoto659d4952011-06-06 14:18:23 +0900103void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
Kuninori Morimotob3318722011-10-10 22:04:41 -0700104 void (*done)(struct usbhs_priv *priv,
105 struct usbhs_pkt *pkt),
Kuninori Morimoto3edeee32011-12-08 18:28:54 -0800106 void *buf, int len, int zero, int sequence);
Kuninori Morimoto97664a22011-06-06 14:18:38 +0900107struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
Kuninori Morimoto51b8a022011-10-10 21:58:45 -0700108void usbhs_pkt_start(struct usbhs_pipe *pipe);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900109
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900110#endif /* RENESAS_USB_FIFO_H */