bf5xx-sport.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * File: bf5xx_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 <linux/platform_device.h>
  34. #include <asm/dma.h>
  35. #include <asm/bfin_sport.h>
  36. #define DESC_ELEMENT_COUNT 9
  37. struct sport_device {
  38. int num;
  39. int dma_rx_chan;
  40. int dma_tx_chan;
  41. int err_irq;
  42. const unsigned short *pin_req;
  43. struct sport_register *regs;
  44. unsigned char *rx_buf;
  45. unsigned char *tx_buf;
  46. unsigned int rx_fragsize;
  47. unsigned int tx_fragsize;
  48. unsigned int rx_frags;
  49. unsigned int tx_frags;
  50. unsigned int wdsize;
  51. /* for dummy dma transfer */
  52. void *dummy_buf;
  53. unsigned int dummy_count;
  54. /* DMA descriptor ring head of current audio stream*/
  55. struct dmasg *dma_rx_desc;
  56. struct dmasg *dma_tx_desc;
  57. unsigned int rx_desc_bytes;
  58. unsigned int tx_desc_bytes;
  59. unsigned int rx_run:1; /* rx is running */
  60. unsigned int tx_run:1; /* tx is running */
  61. struct dmasg *dummy_rx_desc;
  62. struct dmasg *dummy_tx_desc;
  63. struct dmasg *curr_rx_desc;
  64. struct dmasg *curr_tx_desc;
  65. int rx_curr_frag;
  66. int tx_curr_frag;
  67. unsigned int rcr1;
  68. unsigned int rcr2;
  69. int rx_tdm_count;
  70. unsigned int tcr1;
  71. unsigned int tcr2;
  72. int tx_tdm_count;
  73. void (*rx_callback)(void *data);
  74. void *rx_data;
  75. void (*tx_callback)(void *data);
  76. void *tx_data;
  77. void (*err_callback)(void *data);
  78. void *err_data;
  79. unsigned char *tx_dma_buf;
  80. unsigned char *rx_dma_buf;
  81. #ifdef CONFIG_SND_BF5XX_MMAP_SUPPORT
  82. dma_addr_t tx_dma_phy;
  83. dma_addr_t rx_dma_phy;
  84. int tx_pos;/*pcm sample count*/
  85. int rx_pos;
  86. unsigned int tx_buffer_size;
  87. unsigned int rx_buffer_size;
  88. int tx_delay_pos;
  89. int once;
  90. #endif
  91. void *private_data;
  92. };
  93. struct sport_param {
  94. int num;
  95. int dma_rx_chan;
  96. int dma_tx_chan;
  97. int err_irq;
  98. const unsigned short *pin_req;
  99. struct sport_register *regs;
  100. unsigned int wdsize;
  101. unsigned int dummy_count;
  102. void *private_data;
  103. };
  104. struct sport_device *sport_init(struct platform_device *pdev,
  105. unsigned int wdsize, unsigned int dummy_count, size_t priv_size);
  106. void sport_done(struct sport_device *sport);
  107. /* first use these ...*/
  108. /* note: multichannel is in units of 8 channels, tdm_count is number of channels
  109. * NOT / 8 ! all channels are enabled by default */
  110. int sport_set_multichannel(struct sport_device *sport, int tdm_count,
  111. u32 tx_mask, u32 rx_mask, int packed);
  112. int sport_config_rx(struct sport_device *sport,
  113. unsigned int rcr1, unsigned int rcr2,
  114. unsigned int clkdiv, unsigned int fsdiv);
  115. int sport_config_tx(struct sport_device *sport,
  116. unsigned int tcr1, unsigned int tcr2,
  117. unsigned int clkdiv, unsigned int fsdiv);
  118. /* ... then these: */
  119. /* buffer size (in bytes) == fragcount * fragsize_bytes */
  120. /* this is not a very general api, it sets the dma to 2d autobuffer mode */
  121. int sport_config_rx_dma(struct sport_device *sport, void *buf,
  122. int fragcount, size_t fragsize_bytes);
  123. int sport_config_tx_dma(struct sport_device *sport, void *buf,
  124. int fragcount, size_t fragsize_bytes);
  125. int sport_tx_start(struct sport_device *sport);
  126. int sport_tx_stop(struct sport_device *sport);
  127. int sport_rx_start(struct sport_device *sport);
  128. int sport_rx_stop(struct sport_device *sport);
  129. /* for use in interrupt handler */
  130. unsigned long sport_curr_offset_rx(struct sport_device *sport);
  131. unsigned long sport_curr_offset_tx(struct sport_device *sport);
  132. void sport_incfrag(struct sport_device *sport, int *frag, int tx);
  133. void sport_decfrag(struct sport_device *sport, int *frag, int tx);
  134. int sport_set_rx_callback(struct sport_device *sport,
  135. void (*rx_callback)(void *), void *rx_data);
  136. int sport_set_tx_callback(struct sport_device *sport,
  137. void (*tx_callback)(void *), void *tx_data);
  138. int sport_set_err_callback(struct sport_device *sport,
  139. void (*err_callback)(void *), void *err_data);
  140. int sport_send_and_recv(struct sport_device *sport, u8 *out_data, \
  141. u8 *in_data, int len);
  142. #endif /* BF53X_SPORT_H */