^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-1.0+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Renesas USB driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2011 Renesas Solutions Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef RENESAS_USB_PIPE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define RENESAS_USB_PIPE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "fifo.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct usbhs_pipe {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) u32 pipe_type; /* USB_ENDPOINT_XFER_xxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct usbhs_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct usbhs_fifo *fifo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int maxp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define USBHS_PIPE_FLAGS_IS_USED (1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define USBHS_PIPE_FLAGS_IS_DIR_IN (1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define USBHS_PIPE_FLAGS_IS_DIR_HOST (1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define USBHS_PIPE_FLAGS_IS_RUNNING (1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) const struct usbhs_pkt_handle *handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void *mod_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct usbhs_pipe_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct usbhs_pipe *pipe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int size; /* array size of "pipe" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int (*dma_map_ctrl)(struct device *dma_dev, struct usbhs_pkt *pkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * pipe list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define __usbhs_for_each_pipe(start, pos, info, i) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) for ((i) = start; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ((i) < (info)->size) && ((pos) = (info)->pipe + (i)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) (i)++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define usbhs_for_each_pipe(pos, priv, i) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) __usbhs_for_each_pipe(1, pos, &((priv)->pipe_info), i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define usbhs_for_each_pipe_with_dcp(pos, priv, i) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) __usbhs_for_each_pipe(0, pos, &((priv)->pipe_info), i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define usbhs_priv_to_pipeinfo(pr) (&(pr)->pipe_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * pipe control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) char *usbhs_pipe_name(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct usbhs_pipe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *usbhs_pipe_malloc(struct usbhs_priv *priv, int endpoint_type, int dir_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) void usbhs_pipe_free(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int usbhs_pipe_probe(struct usbhs_priv *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) void usbhs_pipe_remove(struct usbhs_priv *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int usbhs_pipe_is_dir_host(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int usbhs_pipe_is_running(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) void usbhs_pipe_running(struct usbhs_pipe *pipe, int running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) void usbhs_pipe_init(struct usbhs_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int (*dma_map_ctrl)(struct device *dma_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct usbhs_pkt *pkt, int map));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) void usbhs_pipe_clear(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) void usbhs_pipe_clear_without_sequence(struct usbhs_pipe *pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int needs_bfre, int bfre_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) void usbhs_pipe_enable(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) void usbhs_pipe_disable(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) void usbhs_pipe_stall(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int usbhs_pipe_is_stall(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) void usbhs_pipe_set_trans_count_if_bulk(struct usbhs_pipe *pipe, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u16 epnum, u16 maxp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) void usbhs_pipe_config_change_bfre(struct usbhs_pipe *pipe, int enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define usbhs_pipe_sequence_data0(pipe) usbhs_pipe_data_sequence(pipe, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define usbhs_pipe_sequence_data1(pipe) usbhs_pipe_data_sequence(pipe, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) void usbhs_pipe_data_sequence(struct usbhs_pipe *pipe, int data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define usbhs_pipe_to_priv(p) ((p)->priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define usbhs_pipe_number(p) (int)((p) - (p)->priv->pipe_info.pipe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define usbhs_pipe_is_dcp(p) ((p)->priv->pipe_info.pipe == (p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define usbhs_pipe_to_fifo(p) ((p)->fifo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define usbhs_pipe_is_busy(p) usbhs_pipe_to_fifo(p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define usbhs_pipe_type(p) ((p)->pipe_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define usbhs_pipe_type_is(p, t) ((p)->pipe_type == t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * dcp control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) void usbhs_dcp_dir_for_host(struct usbhs_pipe *pipe, int dir_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #endif /* RENESAS_USB_PIPE_H */