bf5xx-sport.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. struct sport_register {
  35. u16 tcr1; u16 reserved0;
  36. u16 tcr2; u16 reserved1;
  37. u16 tclkdiv; u16 reserved2;
  38. u16 tfsdiv; u16 reserved3;
  39. u32 tx;
  40. u32 reserved_l0;
  41. u32 rx;
  42. u32 reserved_l1;
  43. u16 rcr1; u16 reserved4;
  44. u16 rcr2; u16 reserved5;
  45. u16 rclkdiv; u16 reserved6;
  46. u16 rfsdiv; u16 reserved7;
  47. u16 stat; u16 reserved8;
  48. u16 chnl; u16 reserved9;
  49. u16 mcmc1; u16 reserved10;
  50. u16 mcmc2; u16 reserved11;
  51. u32 mtcs0;
  52. u32 mtcs1;
  53. u32 mtcs2;
  54. u32 mtcs3;
  55. u32 mrcs0;
  56. u32 mrcs1;
  57. u32 mrcs2;
  58. u32 mrcs3;
  59. };
  60. #define DESC_ELEMENT_COUNT 9
  61. struct sport_device {
  62. int dma_rx_chan;
  63. int dma_tx_chan;
  64. int err_irq;
  65. struct sport_register *regs;
  66. unsigned char *rx_buf;
  67. unsigned char *tx_buf;
  68. unsigned int rx_fragsize;
  69. unsigned int tx_fragsize;
  70. unsigned int rx_frags;
  71. unsigned int tx_frags;
  72. unsigned int wdsize;
  73. /* for dummy dma transfer */
  74. void *dummy_buf;
  75. unsigned int dummy_count;
  76. /* DMA descriptor ring head of current audio stream*/
  77. struct dmasg *dma_rx_desc;
  78. struct dmasg *dma_tx_desc;
  79. unsigned int rx_desc_bytes;
  80. unsigned int tx_desc_bytes;
  81. unsigned int rx_run:1; /* rx is running */
  82. unsigned int tx_run:1; /* tx is running */
  83. struct dmasg *dummy_rx_desc;
  84. struct dmasg *dummy_tx_desc;
  85. struct dmasg *curr_rx_desc;
  86. struct dmasg *curr_tx_desc;
  87. int rx_curr_frag;
  88. int tx_curr_frag;
  89. unsigned int rcr1;
  90. unsigned int rcr2;
  91. int rx_tdm_count;
  92. unsigned int tcr1;
  93. unsigned int tcr2;
  94. int tx_tdm_count;
  95. void (*rx_callback)(void *data);
  96. void *rx_data;
  97. void (*tx_callback)(void *data);
  98. void *tx_data;
  99. void (*err_callback)(void *data);
  100. void *err_data;
  101. unsigned char *tx_dma_buf;
  102. unsigned char *rx_dma_buf;
  103. #ifdef CONFIG_SND_BF5XX_MMAP_SUPPORT
  104. dma_addr_t tx_dma_phy;
  105. dma_addr_t rx_dma_phy;
  106. int tx_pos;/*pcm sample count*/
  107. int rx_pos;
  108. unsigned int tx_buffer_size;
  109. unsigned int rx_buffer_size;
  110. int tx_delay_pos;
  111. int once;
  112. #endif
  113. void *private_data;
  114. };
  115. extern struct sport_device *sport_handle;
  116. struct sport_param {
  117. int dma_rx_chan;
  118. int dma_tx_chan;
  119. int err_irq;
  120. struct sport_register *regs;
  121. };
  122. struct sport_device *sport_init(struct sport_param *param, unsigned wdsize,
  123. unsigned dummy_count, void *private_data);
  124. void sport_done(struct sport_device *sport);
  125. /* first use these ...*/
  126. /* note: multichannel is in units of 8 channels, tdm_count is number of channels
  127. * NOT / 8 ! all channels are enabled by default */
  128. int sport_set_multichannel(struct sport_device *sport, int tdm_count,
  129. u32 mask, int packed);
  130. int sport_config_rx(struct sport_device *sport,
  131. unsigned int rcr1, unsigned int rcr2,
  132. unsigned int clkdiv, unsigned int fsdiv);
  133. int sport_config_tx(struct sport_device *sport,
  134. unsigned int tcr1, unsigned int tcr2,
  135. unsigned int clkdiv, unsigned int fsdiv);
  136. /* ... then these: */
  137. /* buffer size (in bytes) == fragcount * fragsize_bytes */
  138. /* this is not a very general api, it sets the dma to 2d autobuffer mode */
  139. int sport_config_rx_dma(struct sport_device *sport, void *buf,
  140. int fragcount, size_t fragsize_bytes);
  141. int sport_config_tx_dma(struct sport_device *sport, void *buf,
  142. int fragcount, size_t fragsize_bytes);
  143. int sport_tx_start(struct sport_device *sport);
  144. int sport_tx_stop(struct sport_device *sport);
  145. int sport_rx_start(struct sport_device *sport);
  146. int sport_rx_stop(struct sport_device *sport);
  147. /* for use in interrupt handler */
  148. unsigned long sport_curr_offset_rx(struct sport_device *sport);
  149. unsigned long sport_curr_offset_tx(struct sport_device *sport);
  150. void sport_incfrag(struct sport_device *sport, int *frag, int tx);
  151. void sport_decfrag(struct sport_device *sport, int *frag, int tx);
  152. int sport_set_rx_callback(struct sport_device *sport,
  153. void (*rx_callback)(void *), void *rx_data);
  154. int sport_set_tx_callback(struct sport_device *sport,
  155. void (*tx_callback)(void *), void *tx_data);
  156. int sport_set_err_callback(struct sport_device *sport,
  157. void (*err_callback)(void *), void *err_data);
  158. int sport_send_and_recv(struct sport_device *sport, u8 *out_data, \
  159. u8 *in_data, int len);
  160. #endif /* BF53X_SPORT_H */