Vitaliy Vasylskyy | 50bb758 | 2024-09-09 01:06:24 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-1.0+ */ |
| 2 | /* |
| 3 | * Renesas USB driver |
| 4 | * |
| 5 | * Copyright (C) 2011 Renesas Solutions Corp. |
| 6 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 7 | */ |
| 8 | #ifndef RENESAS_USB_FIFO_H |
| 9 | #define RENESAS_USB_FIFO_H |
| 10 | |
| 11 | #include <dma.h> |
| 12 | #include "pipe.h" |
| 13 | |
| 14 | /* |
| 15 | * Drivers, using this library are expected to embed struct shdma_dev, |
| 16 | * struct shdma_chan, struct shdma_desc, and struct shdma_slave |
| 17 | * in their respective device, channel, descriptor and slave objects. |
| 18 | */ |
| 19 | |
| 20 | struct shdma_slave { |
| 21 | int slave_id; |
| 22 | }; |
| 23 | |
| 24 | /* Used by slave DMA clients to request DMA to/from a specific peripheral */ |
| 25 | struct sh_dmae_slave { |
| 26 | struct shdma_slave shdma_slave; /* Set by the platform */ |
| 27 | }; |
| 28 | |
| 29 | struct usbhs_fifo { |
| 30 | char *name; |
| 31 | u32 port; /* xFIFO */ |
| 32 | u32 sel; /* xFIFOSEL */ |
| 33 | u32 ctr; /* xFIFOCTR */ |
| 34 | |
| 35 | struct usbhs_pipe *pipe; |
| 36 | |
| 37 | struct dma_chan *tx_chan; |
| 38 | struct dma_chan *rx_chan; |
| 39 | |
| 40 | struct sh_dmae_slave tx_slave; |
| 41 | struct sh_dmae_slave rx_slave; |
| 42 | }; |
| 43 | |
| 44 | #define USBHS_MAX_NUM_DFIFO 4 |
| 45 | struct usbhs_fifo_info { |
| 46 | struct usbhs_fifo cfifo; |
| 47 | struct usbhs_fifo dfifo[USBHS_MAX_NUM_DFIFO]; |
| 48 | }; |
| 49 | #define usbhsf_get_dnfifo(p, n) (&((p)->fifo_info.dfifo[n])) |
| 50 | #define usbhs_for_each_dfifo(priv, dfifo, i) \ |
| 51 | for ((i) = 0; \ |
| 52 | ((i) < USBHS_MAX_NUM_DFIFO) && \ |
| 53 | ((dfifo) = usbhsf_get_dnfifo(priv, (i))); \ |
| 54 | (i)++) |
| 55 | |
| 56 | struct usbhs_pkt_handle; |
| 57 | struct usbhs_pkt { |
| 58 | struct list_head node; |
| 59 | struct usbhs_pipe *pipe; |
| 60 | const struct usbhs_pkt_handle *handler; |
| 61 | void (*done)(struct usbhs_priv *priv, |
| 62 | struct usbhs_pkt *pkt); |
| 63 | struct work_struct work; |
| 64 | dma_addr_t dma; |
| 65 | const struct dmaengine_result *dma_result; |
| 66 | void *buf; |
| 67 | int length; |
| 68 | int trans; |
| 69 | int actual; |
| 70 | int zero; |
| 71 | int sequence; |
| 72 | }; |
| 73 | |
| 74 | struct usbhs_pkt_handle { |
| 75 | int (*prepare)(struct usbhs_pkt *pkt, int *is_done); |
| 76 | int (*try_run)(struct usbhs_pkt *pkt, int *is_done); |
| 77 | int (*dma_done)(struct usbhs_pkt *pkt, int *is_done); |
| 78 | }; |
| 79 | |
| 80 | /* |
| 81 | * fifo |
| 82 | */ |
| 83 | int usbhs_fifo_probe(struct usbhs_priv *priv); |
| 84 | void usbhs_fifo_remove(struct usbhs_priv *priv); |
| 85 | void usbhs_fifo_init(struct usbhs_priv *priv); |
| 86 | void usbhs_fifo_quit(struct usbhs_priv *priv); |
| 87 | void usbhs_fifo_clear_dcp(struct usbhs_pipe *pipe); |
| 88 | |
| 89 | /* |
| 90 | * packet info |
| 91 | */ |
| 92 | extern const struct usbhs_pkt_handle usbhs_fifo_pio_push_handler; |
| 93 | extern const struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler; |
| 94 | extern const struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler; |
| 95 | |
| 96 | extern const struct usbhs_pkt_handle usbhs_fifo_dma_push_handler; |
| 97 | extern const struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler; |
| 98 | |
| 99 | extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_in_handler; |
| 100 | extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_out_handler; |
| 101 | |
| 102 | extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_in_handler; |
| 103 | extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_out_handler; |
| 104 | |
| 105 | void usbhs_pkt_init(struct usbhs_pkt *pkt); |
| 106 | void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt, |
| 107 | void (*done)(struct usbhs_priv *priv, |
| 108 | struct usbhs_pkt *pkt), |
| 109 | void *buf, int len, int zero, int sequence); |
| 110 | struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt); |
| 111 | void usbhs_pkt_start(struct usbhs_pipe *pipe); |
| 112 | struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe); |
| 113 | |
| 114 | #endif /* RENESAS_USB_FIFO_H */ |