blob: c3d3cc35cee0f640784d48b5f3a471a9608ac6cf [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-1.0+
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +09002/*
3 * Renesas USB driver
4 *
5 * Copyright (C) 2011 Renesas Solutions Corp.
6 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +09007 */
8#ifndef RENESAS_USB_FIFO_H
9#define RENESAS_USB_FIFO_H
10
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090011#include <linux/interrupt.h>
12#include <linux/sh_dma.h>
Guennadi Liakhovetski6e4b74e2012-02-14 11:37:21 +010013#include <linux/workqueue.h>
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090014#include <asm/dma.h>
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090015#include "pipe.h"
16
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090017struct usbhs_fifo {
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090018 char *name;
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090019 u32 port; /* xFIFO */
20 u32 sel; /* xFIFOSEL */
21 u32 ctr; /* xFIFOCTR */
Kuninori Morimotod77e3f42011-06-06 14:18:50 +090022
23 struct usbhs_pipe *pipe;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090024
25 struct dma_chan *tx_chan;
26 struct dma_chan *rx_chan;
27
28 struct sh_dmae_slave tx_slave;
29 struct sh_dmae_slave rx_slave;
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090030};
31
Yoshihiro Shimodad3cf6a42014-11-10 20:02:47 +090032#define USBHS_MAX_NUM_DFIFO 4
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090033struct usbhs_fifo_info {
34 struct usbhs_fifo cfifo;
Yoshihiro Shimodac907e422014-11-10 20:02:44 +090035 struct usbhs_fifo dfifo[USBHS_MAX_NUM_DFIFO];
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090036};
Yoshihiro Shimoda3a2634a2014-11-10 20:02:45 +090037#define usbhsf_get_dnfifo(p, n) (&((p)->fifo_info.dfifo[n]))
Kuninori Morimoto2d9c7f32015-04-14 04:10:04 +000038#define usbhs_for_each_dfifo(priv, dfifo, i) \
39 for ((i) = 0; \
40 ((i) < USBHS_MAX_NUM_DFIFO) && \
41 ((dfifo) = usbhsf_get_dnfifo(priv, (i))); \
42 (i)++)
Kuninori Morimotod3af90a2011-06-06 14:18:44 +090043
Kuninori Morimotodad67392011-06-06 14:18:28 +090044struct usbhs_pkt_handle;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090045struct usbhs_pkt {
Kuninori Morimoto6acb95d2011-06-06 14:18:16 +090046 struct list_head node;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090047 struct usbhs_pipe *pipe;
Julia Lawallfcb42e22015-12-27 21:50:29 +010048 const struct usbhs_pkt_handle *handler;
Kuninori Morimotob3318722011-10-10 22:04:41 -070049 void (*done)(struct usbhs_priv *priv,
50 struct usbhs_pkt *pkt);
Guennadi Liakhovetski6e4b74e2012-02-14 11:37:21 +010051 struct work_struct work;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090052 dma_addr_t dma;
Yoshihiro Shimodaab330cf2015-03-12 15:35:20 +090053 dma_cookie_t cookie;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090054 void *buf;
55 int length;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090056 int trans;
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090057 int actual;
Kuninori Morimoto659d4952011-06-06 14:18:23 +090058 int zero;
Kuninori Morimoto3edeee32011-12-08 18:28:54 -080059 int sequence;
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);
Yoshihiro Shimodacdeb7942014-11-04 10:05:45 +090075void usbhs_fifo_clear_dcp(struct usbhs_pipe *pipe);
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +090076
Kuninori Morimoto4bd04812011-06-06 14:18:07 +090077/*
78 * packet info
79 */
Julia Lawallfcb42e22015-12-27 21:50:29 +010080extern const struct usbhs_pkt_handle usbhs_fifo_pio_push_handler;
81extern const struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler;
82extern const struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
Kuninori Morimotodad67392011-06-06 14:18:28 +090083
Julia Lawallfcb42e22015-12-27 21:50:29 +010084extern const struct usbhs_pkt_handle usbhs_fifo_dma_push_handler;
85extern const struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090086
Julia Lawallfcb42e22015-12-27 21:50:29 +010087extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_in_handler;
88extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_out_handler;
Kuninori Morimoto9e74d602011-10-10 22:07:08 -070089
Julia Lawallfcb42e22015-12-27 21:50:29 +010090extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_in_handler;
91extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_out_handler;
Kuninori Morimotoe73a9892011-06-06 14:19:03 +090092
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 Morimotob3318722011-10-10 22:04:41 -070095 void (*done)(struct usbhs_priv *priv,
96 struct usbhs_pkt *pkt),
Kuninori Morimoto3edeee32011-12-08 18:28:54 -080097 void *buf, int len, int zero, int sequence);
Kuninori Morimoto97664a22011-06-06 14:18:38 +090098struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
Kuninori Morimoto51b8a022011-10-10 21:58:45 -070099void usbhs_pkt_start(struct usbhs_pipe *pipe);
Yoshihiro Shimoda4d599cd2019-10-01 19:10:33 +0900100struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe);
Kuninori Morimotodad67392011-06-06 14:18:28 +0900101
Kuninori Morimotoe8d548d2011-06-06 14:18:03 +0900102#endif /* RENESAS_USB_FIFO_H */