fifo.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <linux/interrupt.h>
  11. #include <linux/sh_dma.h>
  12. #include <linux/workqueue.h>
  13. #include <asm/dma.h>
  14. #include "pipe.h"
  15. struct usbhs_fifo {
  16. char *name;
  17. u32 port; /* xFIFO */
  18. u32 sel; /* xFIFOSEL */
  19. u32 ctr; /* xFIFOCTR */
  20. struct usbhs_pipe *pipe;
  21. struct dma_chan *tx_chan;
  22. struct dma_chan *rx_chan;
  23. struct sh_dmae_slave tx_slave;
  24. struct sh_dmae_slave rx_slave;
  25. };
  26. #define USBHS_MAX_NUM_DFIFO 4
  27. struct usbhs_fifo_info {
  28. struct usbhs_fifo cfifo;
  29. struct usbhs_fifo dfifo[USBHS_MAX_NUM_DFIFO];
  30. };
  31. #define usbhsf_get_dnfifo(p, n) (&((p)->fifo_info.dfifo[n]))
  32. #define usbhs_for_each_dfifo(priv, dfifo, i) \
  33. for ((i) = 0; \
  34. ((i) < USBHS_MAX_NUM_DFIFO) && \
  35. ((dfifo) = usbhsf_get_dnfifo(priv, (i))); \
  36. (i)++)
  37. struct usbhs_pkt_handle;
  38. struct usbhs_pkt {
  39. struct list_head node;
  40. struct usbhs_pipe *pipe;
  41. const struct usbhs_pkt_handle *handler;
  42. void (*done)(struct usbhs_priv *priv,
  43. struct usbhs_pkt *pkt);
  44. struct work_struct work;
  45. dma_addr_t dma;
  46. dma_cookie_t cookie;
  47. void *buf;
  48. int length;
  49. int trans;
  50. int actual;
  51. int zero;
  52. int sequence;
  53. };
  54. struct usbhs_pkt_handle {
  55. int (*prepare)(struct usbhs_pkt *pkt, int *is_done);
  56. int (*try_run)(struct usbhs_pkt *pkt, int *is_done);
  57. int (*dma_done)(struct usbhs_pkt *pkt, int *is_done);
  58. };
  59. /*
  60. * fifo
  61. */
  62. int usbhs_fifo_probe(struct usbhs_priv *priv);
  63. void usbhs_fifo_remove(struct usbhs_priv *priv);
  64. void usbhs_fifo_init(struct usbhs_priv *priv);
  65. void usbhs_fifo_quit(struct usbhs_priv *priv);
  66. void usbhs_fifo_clear_dcp(struct usbhs_pipe *pipe);
  67. /*
  68. * packet info
  69. */
  70. extern const struct usbhs_pkt_handle usbhs_fifo_pio_push_handler;
  71. extern const struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler;
  72. extern const struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
  73. extern const struct usbhs_pkt_handle usbhs_fifo_dma_push_handler;
  74. extern const struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler;
  75. extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_in_handler;
  76. extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_out_handler;
  77. extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_in_handler;
  78. extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_out_handler;
  79. void usbhs_pkt_init(struct usbhs_pkt *pkt);
  80. void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
  81. void (*done)(struct usbhs_priv *priv,
  82. struct usbhs_pkt *pkt),
  83. void *buf, int len, int zero, int sequence);
  84. struct usbhs_pkt *usbhs_pkt_pop(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt);
  85. void usbhs_pkt_start(struct usbhs_pipe *pipe);
  86. struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe);
  87. #endif /* RENESAS_USB_FIFO_H */