pipe.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_PIPE_H
  9. #define RENESAS_USB_PIPE_H
  10. #include "common.h"
  11. #include "fifo.h"
  12. /*
  13. * struct
  14. */
  15. struct usbhs_pipe {
  16. u32 pipe_type; /* USB_ENDPOINT_XFER_xxx */
  17. struct usbhs_priv *priv;
  18. struct usbhs_fifo *fifo;
  19. struct list_head list;
  20. int maxp;
  21. u32 flags;
  22. #define USBHS_PIPE_FLAGS_IS_USED (1 << 0)
  23. #define USBHS_PIPE_FLAGS_IS_DIR_IN (1 << 1)
  24. #define USBHS_PIPE_FLAGS_IS_DIR_HOST (1 << 2)
  25. #define USBHS_PIPE_FLAGS_IS_RUNNING (1 << 3)
  26. const struct usbhs_pkt_handle *handler;
  27. void *mod_private;
  28. };
  29. struct usbhs_pipe_info {
  30. struct usbhs_pipe *pipe;
  31. int size; /* array size of "pipe" */
  32. int (*dma_map_ctrl)(struct device *dma_dev, struct usbhs_pkt *pkt,
  33. int map);
  34. };
  35. /*
  36. * pipe list
  37. */
  38. #define __usbhs_for_each_pipe(start, pos, info, i) \
  39. for ((i) = start; \
  40. ((i) < (info)->size) && ((pos) = (info)->pipe + (i)); \
  41. (i)++)
  42. #define usbhs_for_each_pipe(pos, priv, i) \
  43. __usbhs_for_each_pipe(1, pos, &((priv)->pipe_info), i)
  44. #define usbhs_for_each_pipe_with_dcp(pos, priv, i) \
  45. __usbhs_for_each_pipe(0, pos, &((priv)->pipe_info), i)
  46. /*
  47. * data
  48. */
  49. #define usbhs_priv_to_pipeinfo(pr) (&(pr)->pipe_info)
  50. /*
  51. * pipe control
  52. */
  53. char *usbhs_pipe_name(struct usbhs_pipe *pipe);
  54. struct usbhs_pipe
  55. *usbhs_pipe_malloc(struct usbhs_priv *priv, int endpoint_type, int dir_in);
  56. void usbhs_pipe_free(struct usbhs_pipe *pipe);
  57. int usbhs_pipe_probe(struct usbhs_priv *priv);
  58. void usbhs_pipe_remove(struct usbhs_priv *priv);
  59. int usbhs_pipe_is_dir_in(struct usbhs_pipe *pipe);
  60. int usbhs_pipe_is_dir_host(struct usbhs_pipe *pipe);
  61. int usbhs_pipe_is_running(struct usbhs_pipe *pipe);
  62. void usbhs_pipe_running(struct usbhs_pipe *pipe, int running);
  63. void usbhs_pipe_init(struct usbhs_priv *priv,
  64. int (*dma_map_ctrl)(struct device *dma_dev,
  65. struct usbhs_pkt *pkt, int map));
  66. int usbhs_pipe_get_maxpacket(struct usbhs_pipe *pipe);
  67. void usbhs_pipe_clear(struct usbhs_pipe *pipe);
  68. void usbhs_pipe_clear_without_sequence(struct usbhs_pipe *pipe,
  69. int needs_bfre, int bfre_enable);
  70. int usbhs_pipe_is_accessible(struct usbhs_pipe *pipe);
  71. bool usbhs_pipe_contains_transmittable_data(struct usbhs_pipe *pipe);
  72. void usbhs_pipe_enable(struct usbhs_pipe *pipe);
  73. void usbhs_pipe_disable(struct usbhs_pipe *pipe);
  74. void usbhs_pipe_stall(struct usbhs_pipe *pipe);
  75. int usbhs_pipe_is_stall(struct usbhs_pipe *pipe);
  76. void usbhs_pipe_set_trans_count_if_bulk(struct usbhs_pipe *pipe, int len);
  77. void usbhs_pipe_select_fifo(struct usbhs_pipe *pipe, struct usbhs_fifo *fifo);
  78. void usbhs_pipe_config_update(struct usbhs_pipe *pipe, u16 devsel,
  79. u16 epnum, u16 maxp);
  80. void usbhs_pipe_config_change_bfre(struct usbhs_pipe *pipe, int enable);
  81. #define usbhs_pipe_sequence_data0(pipe) usbhs_pipe_data_sequence(pipe, 0)
  82. #define usbhs_pipe_sequence_data1(pipe) usbhs_pipe_data_sequence(pipe, 1)
  83. void usbhs_pipe_data_sequence(struct usbhs_pipe *pipe, int data);
  84. #define usbhs_pipe_to_priv(p) ((p)->priv)
  85. #define usbhs_pipe_number(p) (int)((p) - (p)->priv->pipe_info.pipe)
  86. #define usbhs_pipe_is_dcp(p) ((p)->priv->pipe_info.pipe == (p))
  87. #define usbhs_pipe_to_fifo(p) ((p)->fifo)
  88. #define usbhs_pipe_is_busy(p) usbhs_pipe_to_fifo(p)
  89. #define usbhs_pipe_type(p) ((p)->pipe_type)
  90. #define usbhs_pipe_type_is(p, t) ((p)->pipe_type == t)
  91. /*
  92. * dcp control
  93. */
  94. struct usbhs_pipe *usbhs_dcp_malloc(struct usbhs_priv *priv);
  95. void usbhs_dcp_control_transfer_done(struct usbhs_pipe *pipe);
  96. void usbhs_dcp_dir_for_host(struct usbhs_pipe *pipe, int dir_out);
  97. #endif /* RENESAS_USB_PIPE_H */