davinci_cpdma.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Texas Instruments CPDMA Driver
  3. *
  4. * Copyright (C) 2010 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef __DAVINCI_CPDMA_H__
  16. #define __DAVINCI_CPDMA_H__
  17. #define CPDMA_MAX_CHANNELS BITS_PER_LONG
  18. #define tx_chan_num(chan) (chan)
  19. #define rx_chan_num(chan) ((chan) + CPDMA_MAX_CHANNELS)
  20. #define is_rx_chan(chan) ((chan)->chan_num >= CPDMA_MAX_CHANNELS)
  21. #define is_tx_chan(chan) (!is_rx_chan(chan))
  22. #define __chan_linear(chan_num) ((chan_num) & (CPDMA_MAX_CHANNELS - 1))
  23. #define chan_linear(chan) __chan_linear((chan)->chan_num)
  24. struct cpdma_params {
  25. struct device *dev;
  26. void __iomem *dmaregs;
  27. void __iomem *txhdp, *rxhdp, *txcp, *rxcp;
  28. void __iomem *rxthresh, *rxfree;
  29. int num_chan;
  30. bool has_soft_reset;
  31. int min_packet_size;
  32. u32 desc_mem_phys;
  33. u32 desc_hw_addr;
  34. int desc_mem_size;
  35. int desc_align;
  36. /*
  37. * Some instances of embedded cpdma controllers have extra control and
  38. * status registers. The following flag enables access to these
  39. * "extended" registers.
  40. */
  41. bool has_ext_regs;
  42. };
  43. struct cpdma_chan_stats {
  44. u32 head_enqueue;
  45. u32 tail_enqueue;
  46. u32 pad_enqueue;
  47. u32 misqueued;
  48. u32 desc_alloc_fail;
  49. u32 pad_alloc_fail;
  50. u32 runt_receive_buff;
  51. u32 runt_transmit_buff;
  52. u32 empty_dequeue;
  53. u32 busy_dequeue;
  54. u32 good_dequeue;
  55. u32 requeue;
  56. u32 teardown_dequeue;
  57. };
  58. struct cpdma_ctlr;
  59. struct cpdma_chan;
  60. typedef void (*cpdma_handler_fn)(void *token, int len, int status);
  61. struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params);
  62. int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr);
  63. int cpdma_ctlr_start(struct cpdma_ctlr *ctlr);
  64. int cpdma_ctlr_stop(struct cpdma_ctlr *ctlr);
  65. int cpdma_ctlr_dump(struct cpdma_ctlr *ctlr);
  66. struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num,
  67. cpdma_handler_fn handler);
  68. int cpdma_chan_destroy(struct cpdma_chan *chan);
  69. int cpdma_chan_start(struct cpdma_chan *chan);
  70. int cpdma_chan_stop(struct cpdma_chan *chan);
  71. int cpdma_chan_dump(struct cpdma_chan *chan);
  72. int cpdma_chan_get_stats(struct cpdma_chan *chan,
  73. struct cpdma_chan_stats *stats);
  74. int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
  75. int len, gfp_t gfp_mask);
  76. int cpdma_chan_process(struct cpdma_chan *chan, int quota);
  77. int cpdma_ctlr_int_ctrl(struct cpdma_ctlr *ctlr, bool enable);
  78. void cpdma_ctlr_eoi(struct cpdma_ctlr *ctlr);
  79. int cpdma_chan_int_ctrl(struct cpdma_chan *chan, bool enable);
  80. enum cpdma_control {
  81. CPDMA_CMD_IDLE, /* write-only */
  82. CPDMA_COPY_ERROR_FRAMES, /* read-write */
  83. CPDMA_RX_OFF_LEN_UPDATE, /* read-write */
  84. CPDMA_RX_OWNERSHIP_FLIP, /* read-write */
  85. CPDMA_TX_PRIO_FIXED, /* read-write */
  86. CPDMA_STAT_IDLE, /* read-only */
  87. CPDMA_STAT_TX_ERR_CHAN, /* read-only */
  88. CPDMA_STAT_TX_ERR_CODE, /* read-only */
  89. CPDMA_STAT_RX_ERR_CHAN, /* read-only */
  90. CPDMA_STAT_RX_ERR_CODE, /* read-only */
  91. CPDMA_RX_BUFFER_OFFSET, /* read-write */
  92. };
  93. int cpdma_control_get(struct cpdma_ctlr *ctlr, int control);
  94. int cpdma_control_set(struct cpdma_ctlr *ctlr, int control, int value);
  95. #endif