162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-1.0+ */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Renesas USB driver
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2011 Renesas Solutions Corp.
662306a36Sopenharmony_ci * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci#ifndef RENESAS_USB_FIFO_H
962306a36Sopenharmony_ci#define RENESAS_USB_FIFO_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/interrupt.h>
1262306a36Sopenharmony_ci#include <linux/sh_dma.h>
1362306a36Sopenharmony_ci#include <linux/workqueue.h>
1462306a36Sopenharmony_ci#include <asm/dma.h>
1562306a36Sopenharmony_ci#include "pipe.h"
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_cistruct usbhs_fifo {
1862306a36Sopenharmony_ci	char *name;
1962306a36Sopenharmony_ci	u32 port;	/* xFIFO */
2062306a36Sopenharmony_ci	u32 sel;	/* xFIFOSEL */
2162306a36Sopenharmony_ci	u32 ctr;	/* xFIFOCTR */
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci	struct usbhs_pipe	*pipe;
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci	struct dma_chan		*tx_chan;
2662306a36Sopenharmony_ci	struct dma_chan		*rx_chan;
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci	struct sh_dmae_slave	tx_slave;
2962306a36Sopenharmony_ci	struct sh_dmae_slave	rx_slave;
3062306a36Sopenharmony_ci};
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define USBHS_MAX_NUM_DFIFO	4
3362306a36Sopenharmony_cistruct usbhs_fifo_info {
3462306a36Sopenharmony_ci	struct usbhs_fifo cfifo;
3562306a36Sopenharmony_ci	struct usbhs_fifo dfifo[USBHS_MAX_NUM_DFIFO];
3662306a36Sopenharmony_ci};
3762306a36Sopenharmony_ci#define usbhsf_get_dnfifo(p, n)	(&((p)->fifo_info.dfifo[n]))
3862306a36Sopenharmony_ci#define usbhs_for_each_dfifo(priv, dfifo, i)			\
3962306a36Sopenharmony_ci	for ((i) = 0;						\
4062306a36Sopenharmony_ci	     ((i) < USBHS_MAX_NUM_DFIFO) &&			\
4162306a36Sopenharmony_ci		     ((dfifo) = usbhsf_get_dnfifo(priv, (i)));	\
4262306a36Sopenharmony_ci	     (i)++)
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_cistruct usbhs_pkt_handle;
4562306a36Sopenharmony_cistruct usbhs_pkt {
4662306a36Sopenharmony_ci	struct list_head node;
4762306a36Sopenharmony_ci	struct usbhs_pipe *pipe;
4862306a36Sopenharmony_ci	const struct usbhs_pkt_handle *handler;
4962306a36Sopenharmony_ci	void (*done)(struct usbhs_priv *priv,
5062306a36Sopenharmony_ci		     struct usbhs_pkt *pkt);
5162306a36Sopenharmony_ci	struct work_struct work;
5262306a36Sopenharmony_ci	dma_addr_t dma;
5362306a36Sopenharmony_ci	const struct dmaengine_result *dma_result;
5462306a36Sopenharmony_ci	void *buf;
5562306a36Sopenharmony_ci	int length;
5662306a36Sopenharmony_ci	int trans;
5762306a36Sopenharmony_ci	int actual;
5862306a36Sopenharmony_ci	int zero;
5962306a36Sopenharmony_ci	int sequence;
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistruct usbhs_pkt_handle {
6362306a36Sopenharmony_ci	int (*prepare)(struct usbhs_pkt *pkt, int *is_done);
6462306a36Sopenharmony_ci	int (*try_run)(struct usbhs_pkt *pkt, int *is_done);
6562306a36Sopenharmony_ci	int (*dma_done)(struct usbhs_pkt *pkt, int *is_done);
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/*
6962306a36Sopenharmony_ci * fifo
7062306a36Sopenharmony_ci */
7162306a36Sopenharmony_ciint usbhs_fifo_probe(struct usbhs_priv *priv);
7262306a36Sopenharmony_civoid usbhs_fifo_remove(struct usbhs_priv *priv);
7362306a36Sopenharmony_civoid usbhs_fifo_init(struct usbhs_priv *priv);
7462306a36Sopenharmony_civoid usbhs_fifo_quit(struct usbhs_priv *priv);
7562306a36Sopenharmony_civoid usbhs_fifo_clear_dcp(struct usbhs_pipe *pipe);
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci/*
7862306a36Sopenharmony_ci * packet info
7962306a36Sopenharmony_ci */
8062306a36Sopenharmony_ciextern const struct usbhs_pkt_handle usbhs_fifo_pio_push_handler;
8162306a36Sopenharmony_ciextern const struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler;
8262306a36Sopenharmony_ciextern const struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ciextern const struct usbhs_pkt_handle usbhs_fifo_dma_push_handler;
8562306a36Sopenharmony_ciextern const struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler;
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ciextern const struct usbhs_pkt_handle usbhs_dcp_status_stage_in_handler;
8862306a36Sopenharmony_ciextern const struct usbhs_pkt_handle usbhs_dcp_status_stage_out_handler;
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ciextern const struct usbhs_pkt_handle usbhs_dcp_data_stage_in_handler;
9162306a36Sopenharmony_ciextern const struct usbhs_pkt_handle usbhs_dcp_data_stage_out_handler;
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_civoid usbhs_pkt_init(struct usbhs_pkt *pkt);
9462306a36Sopenharmony_civoid usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
9562306a36Sopenharmony_ci		    void (*done)(struct usbhs_priv *priv,
9662306a36Sopenharmony_ci				 struct usbhs_pkt *pkt),
9762306a36Sopenharmony_ci		    void *buf, int len, int zero, int sequence);
9862306a36Sopenharmony_cistruct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
9962306a36Sopenharmony_civoid usbhs_pkt_start(struct usbhs_pipe *pipe);
10062306a36Sopenharmony_cistruct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe);
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci#endif /* RENESAS_USB_FIFO_H */
103