davinci_cpdma.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #define CPDMA_RX_SOURCE_PORT(__status__) ((__status__ >> 16) & 0x7)
  25. #define CPDMA_EOI_RX_THRESH 0x0
  26. #define CPDMA_EOI_RX 0x1
  27. #define CPDMA_EOI_TX 0x2
  28. #define CPDMA_EOI_MISC 0x3
  29. struct cpdma_params {
  30. struct device *dev;
  31. void __iomem *dmaregs;
  32. void __iomem *txhdp, *rxhdp, *txcp, *rxcp;
  33. void __iomem *rxthresh, *rxfree;
  34. int num_chan;
  35. bool has_soft_reset;
  36. int min_packet_size;
  37. u32 desc_mem_phys;
  38. u32 desc_hw_addr;
  39. int desc_mem_size;
  40. int desc_align;
  41. /*
  42. * Some instances of embedded cpdma controllers have extra control and
  43. * status registers. The following flag enables access to these
  44. * "extended" registers.
  45. */
  46. bool has_ext_regs;
  47. };
  48. struct cpdma_chan_stats {
  49. u32 head_enqueue;
  50. u32 tail_enqueue;
  51. u32 pad_enqueue;
  52. u32 misqueued;
  53. u32 desc_alloc_fail;
  54. u32 pad_alloc_fail;
  55. u32 runt_receive_buff;
  56. u32 runt_transmit_buff;
  57. u32 empty_dequeue;
  58. u32 busy_dequeue;
  59. u32 good_dequeue;
  60. u32 requeue;
  61. u32 teardown_dequeue;
  62. };
  63. struct cpdma_ctlr;
  64. struct cpdma_chan;
  65. typedef void (*cpdma_handler_fn)(void *token, int len, int status);
  66. struct cpdma_ctlr *cpdma_ctlr_create(struct cpdma_params *params);
  67. int cpdma_ctlr_destroy(struct cpdma_ctlr *ctlr);
  68. int cpdma_ctlr_start(struct cpdma_ctlr *ctlr);
  69. int cpdma_ctlr_stop(struct cpdma_ctlr *ctlr);
  70. int cpdma_ctlr_dump(struct cpdma_ctlr *ctlr);
  71. struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num,
  72. cpdma_handler_fn handler);
  73. int cpdma_chan_destroy(struct cpdma_chan *chan);
  74. int cpdma_chan_start(struct cpdma_chan *chan);
  75. int cpdma_chan_stop(struct cpdma_chan *chan);
  76. int cpdma_chan_dump(struct cpdma_chan *chan);
  77. int cpdma_chan_get_stats(struct cpdma_chan *chan,
  78. struct cpdma_chan_stats *stats);
  79. int cpdma_chan_submit(struct cpdma_chan *chan, void *token, void *data,
  80. int len, int directed);
  81. int cpdma_chan_process(struct cpdma_chan *chan, int quota);
  82. int cpdma_ctlr_int_ctrl(struct cpdma_ctlr *ctlr, bool enable);
  83. void cpdma_ctlr_eoi(struct cpdma_ctlr *ctlr, u32 value);
  84. int cpdma_chan_int_ctrl(struct cpdma_chan *chan, bool enable);
  85. bool cpdma_check_free_tx_desc(struct cpdma_chan *chan);
  86. enum cpdma_control {
  87. CPDMA_CMD_IDLE, /* write-only */
  88. CPDMA_COPY_ERROR_FRAMES, /* read-write */
  89. CPDMA_RX_OFF_LEN_UPDATE, /* read-write */
  90. CPDMA_RX_OWNERSHIP_FLIP, /* read-write */
  91. CPDMA_TX_PRIO_FIXED, /* read-write */
  92. CPDMA_STAT_IDLE, /* read-only */
  93. CPDMA_STAT_TX_ERR_CHAN, /* read-only */
  94. CPDMA_STAT_TX_ERR_CODE, /* read-only */
  95. CPDMA_STAT_RX_ERR_CHAN, /* read-only */
  96. CPDMA_STAT_RX_ERR_CODE, /* read-only */
  97. CPDMA_RX_BUFFER_OFFSET, /* read-write */
  98. };
  99. int cpdma_control_get(struct cpdma_ctlr *ctlr, int control);
  100. int cpdma_control_set(struct cpdma_ctlr *ctlr, int control, int value);
  101. #endif