bf5xx-sport.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * File: bf5xx_ac97_sport.h
  3. * Based on:
  4. * Author: Roy Huang <roy.huang@analog.com>
  5. *
  6. * Created:
  7. * Description:
  8. *
  9. * Copyright 2004-2007 Analog Devices Inc.
  10. *
  11. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, see the file COPYING, or write
  25. * to the Free Software Foundation, Inc.,
  26. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. #ifndef __BF5XX_SPORT_H__
  29. #define __BF5XX_SPORT_H__
  30. #include <linux/types.h>
  31. #include <linux/wait.h>
  32. #include <linux/workqueue.h>
  33. #include <asm/dma.h>
  34. #include <asm/bfin_sport.h>
  35. #define DESC_ELEMENT_COUNT 9
  36. struct sport_device {
  37. int dma_rx_chan;
  38. int dma_tx_chan;
  39. int err_irq;
  40. struct sport_register *regs;
  41. unsigned char *rx_buf;
  42. unsigned char *tx_buf;
  43. unsigned int rx_fragsize;
  44. unsigned int tx_fragsize;
  45. unsigned int rx_frags;
  46. unsigned int tx_frags;
  47. unsigned int wdsize;
  48. /* for dummy dma transfer */
  49. void *dummy_buf;
  50. unsigned int dummy_count;
  51. /* DMA descriptor ring head of current audio stream*/
  52. struct dmasg *dma_rx_desc;
  53. struct dmasg *dma_tx_desc;
  54. unsigned int rx_desc_bytes;
  55. unsigned int tx_desc_bytes;
  56. unsigned int rx_run:1; /* rx is running */
  57. unsigned int tx_run:1; /* tx is running */
  58. struct dmasg *dummy_rx_desc;
  59. struct dmasg *dummy_tx_desc;
  60. struct dmasg *curr_rx_desc;
  61. struct dmasg *curr_tx_desc;
  62. int rx_curr_frag;
  63. int tx_curr_frag;
  64. unsigned int rcr1;
  65. unsigned int rcr2;
  66. int rx_tdm_count;
  67. unsigned int tcr1;
  68. unsigned int tcr2;
  69. int tx_tdm_count;
  70. void (*rx_callback)(void *data);
  71. void *rx_data;
  72. void (*tx_callback)(void *data);
  73. void *tx_data;
  74. void (*err_callback)(void *data);
  75. void *err_data;
  76. unsigned char *tx_dma_buf;
  77. unsigned char *rx_dma_buf;
  78. #ifdef CONFIG_SND_BF5XX_MMAP_SUPPORT
  79. dma_addr_t tx_dma_phy;
  80. dma_addr_t rx_dma_phy;
  81. int tx_pos;/*pcm sample count*/
  82. int rx_pos;
  83. unsigned int tx_buffer_size;
  84. unsigned int rx_buffer_size;
  85. int tx_delay_pos;
  86. int once;
  87. #endif
  88. void *private_data;
  89. };
  90. extern struct sport_device *sport_handle;
  91. struct sport_param {
  92. int dma_rx_chan;
  93. int dma_tx_chan;
  94. int err_irq;
  95. struct sport_register *regs;
  96. };
  97. struct sport_device *sport_init(struct sport_param *param, unsigned wdsize,
  98. unsigned dummy_count, void *private_data);
  99. void sport_done(struct sport_device *sport);
  100. /* first use these ...*/
  101. /* note: multichannel is in units of 8 channels, tdm_count is number of channels
  102. * NOT / 8 ! all channels are enabled by default */
  103. int sport_set_multichannel(struct sport_device *sport, int tdm_count,
  104. u32 mask, int packed);
  105. int sport_config_rx(struct sport_device *sport,
  106. unsigned int rcr1, unsigned int rcr2,
  107. unsigned int clkdiv, unsigned int fsdiv);
  108. int sport_config_tx(struct sport_device *sport,
  109. unsigned int tcr1, unsigned int tcr2,
  110. unsigned int clkdiv, unsigned int fsdiv);
  111. /* ... then these: */
  112. /* buffer size (in bytes) == fragcount * fragsize_bytes */
  113. /* this is not a very general api, it sets the dma to 2d autobuffer mode */
  114. int sport_config_rx_dma(struct sport_device *sport, void *buf,
  115. int fragcount, size_t fragsize_bytes);
  116. int sport_config_tx_dma(struct sport_device *sport, void *buf,
  117. int fragcount, size_t fragsize_bytes);
  118. int sport_tx_start(struct sport_device *sport);
  119. int sport_tx_stop(struct sport_device *sport);
  120. int sport_rx_start(struct sport_device *sport);
  121. int sport_rx_stop(struct sport_device *sport);
  122. /* for use in interrupt handler */
  123. unsigned long sport_curr_offset_rx(struct sport_device *sport);
  124. unsigned long sport_curr_offset_tx(struct sport_device *sport);
  125. void sport_incfrag(struct sport_device *sport, int *frag, int tx);
  126. void sport_decfrag(struct sport_device *sport, int *frag, int tx);
  127. int sport_set_rx_callback(struct sport_device *sport,
  128. void (*rx_callback)(void *), void *rx_data);
  129. int sport_set_tx_callback(struct sport_device *sport,
  130. void (*tx_callback)(void *), void *tx_data);
  131. int sport_set_err_callback(struct sport_device *sport,
  132. void (*err_callback)(void *), void *err_data);
  133. int sport_send_and_recv(struct sport_device *sport, u8 *out_data, \
  134. u8 *in_data, int len);
  135. #endif /* BF53X_SPORT_H */