acw.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. #ifndef ACW_H_
  27. #define ACW_H_
  28. #include <rtthread.h>
  29. #include <rtdevice.h>
  30. #ifdef RT_USING_DFS
  31. #include <dfs_fs.h>
  32. #endif
  33. #include <rthw.h>
  34. #define ACW_CAP_DMA_CHAN 2
  35. #define ACW_PLY_DMA_CHAN 3
  36. typedef unsigned long long dma_addr_t;
  37. struct scatterlist {
  38. #ifdef CONFIG_DEBUG_SG
  39. unsigned long sg_magic;
  40. #endif
  41. unsigned long page_link;
  42. unsigned int offset;
  43. unsigned int length;
  44. dma_addr_t dma_address;
  45. #ifdef CONFIG_NEED_SG_DMA_LENGTH
  46. unsigned int dma_length;
  47. #endif
  48. };
  49. #define readl(a) (*(volatile rt_uint32_t *)(a))
  50. #define rkqueue_struct rt_workqueue
  51. #define work_struct rt_work
  52. #define INIT_WORK(work,func) rt_work_init(work,func,RT_NULL);
  53. #define queue_work rt_workqueue_dowork
  54. //timer
  55. #define timer_list rt_timer
  56. #define wait_queue_head_t struct rt_event
  57. #define init_waitqueue_head(event_t) rt_event_init(event_t, "audio_event", RT_IPC_FLAG_FIFO)
  58. typedef enum{
  59. AC_SR_8K = 8000,
  60. AC_SR_16K = 16000,
  61. AC_SR_32K = 32000,
  62. AC_SR_441K = 44100,
  63. AC_SR_48K = 48000,
  64. } FH_AC_SAMPLE_RATE_E;
  65. typedef enum{
  66. AC_BW_8 = 8,
  67. AC_BW_16 = 16,
  68. AC_BW_24 = 24,
  69. } FH_AC_BIT_WIDTH_E;
  70. enum io_select{
  71. mic_in = 0,
  72. line_in = 1,
  73. speaker_out = 2,
  74. line_out = 3,
  75. };
  76. struct fh_audio_cfg_arg{
  77. enum io_select io_type;
  78. int volume;
  79. int rate;
  80. int frame_bit;
  81. int channels;
  82. int buffer_size;
  83. int period_size;
  84. };
  85. typedef struct{
  86. unsigned int len;
  87. unsigned char *data;
  88. }FH_AC_FRAME_S;
  89. typedef enum{
  90. FH_AC_MIC_IN = 0,
  91. FH_AC_LINE_IN = 1,
  92. FH_AC_SPK_OUT = 2,
  93. FH_AC_LINE_OUT = 3
  94. }FH_AC_IO_TYPE_E;
  95. typedef struct {
  96. FH_AC_IO_TYPE_E io_type;
  97. FH_AC_SAMPLE_RATE_E sample_rate;
  98. FH_AC_BIT_WIDTH_E bit_width;
  99. unsigned int channels;
  100. unsigned int period_size;
  101. unsigned int volume;
  102. } FH_AC_CONFIG;
  103. struct device_dma_parameters {
  104. /*
  105. * a low level driver may set these to teach IOMMU code about
  106. * sg limitations.
  107. */
  108. unsigned int max_segment_size;
  109. unsigned long segment_boundary_mask;
  110. };
  111. struct list_head {
  112. struct list_head *next;
  113. struct list_head *prev;
  114. };
  115. struct dma_coherent_mem {
  116. void *virt_base;
  117. dma_addr_t device_base;
  118. int size;
  119. int flags;
  120. unsigned long *bitmap;
  121. };
  122. struct device_acw{
  123. unsigned long long *dma_mask; /* dma mask (if dma'able device) */
  124. unsigned long long coherent_dma_mask;/* Like dma_mask, but for
  125. alloc_coherent mappings as
  126. not all hardware supports
  127. 64 bit addresses for consistent
  128. allocations such descriptors. */
  129. struct device_dma_parameters *dma_parms;
  130. struct list_head dma_pools;
  131. struct dma_coherent_mem *dma_mem;
  132. };
  133. #define false 0
  134. #define true 1
  135. #define AC_INIT_CAPTURE_MEM 0x10
  136. #define AC_INIT_PLAYBACK_MEM 0x11
  137. #define AC_SET_VOL 0x12
  138. #define AC_SET_INPUT_MODE 0x13
  139. #define AC_SET_OUTPUT_MODE 0x14
  140. #define AC_AI_EN 0x15
  141. #define AC_AO_EN 0x16
  142. #define AC_AI_DISABLE 0x17
  143. #define AC_AO_DISABLE 0x18
  144. #define AC_AI_PAUSE 0x19
  145. #define AC_AI_RESUME 0x1a
  146. #define AC_AO_PAUSE 0x1b
  147. #define AC_AO_RESUME 0x1c
  148. #define AC_MIC_BOOST 0x1d
  149. #define POLLIN 0x001 /* There is data to read. */
  150. #define POLLPRI 0x002 /* There is urgent data to read. */
  151. #define POLLOUT 0x004 /* Writing now will not block. */
  152. /* These values are defined in XPG4.2. */
  153. # define POLLRDNORM 0x040 /* Normal data may be read. */
  154. # define POLLRDBAND 0x080 /* Priority data may be read. */
  155. # define POLLWRNORM 0x100 /* Writing now will not block. */
  156. # define POLLWRBAND 0x200 /* Priority data may be written. */
  157. /* These are extensions for Linux. */
  158. # define POLLMSG 0x400
  159. # define POLLREMOVE 0x1000
  160. # define POLLRDHUP 0x2000
  161. /* Event types always implicitly polled for. These bits need not be set in
  162. `events', but they will appear in `revents' to indicate the status of
  163. the file descriptor. */
  164. #define POLLERR 0x008 /* Error condition. */
  165. #define POLLHUP 0x010 /* Hung up. */
  166. #define POLLNVAL 0x020 /* Invalid polling request. */
  167. #define EPERM 1 /* Operation not permitted */
  168. #define ENOENT 2 /* No such file or directory */
  169. #define ESRCH 3 /* No such process */
  170. #define EINTR 4 /* Interrupted system call */
  171. #define EIO 5 /* I/O error */
  172. #define ENXIO 6 /* No such device or address */
  173. #define E2BIG 7 /* Argument list too long */
  174. #define ENOEXEC 8 /* Exec format error */
  175. #define EBADF 9 /* Bad file number */
  176. #define ECHILD 10 /* No child processes */
  177. #define EAGAIN 11 /* Try again */
  178. #define ENOMEM 12 /* Out of memory */
  179. #define EACCES 13 /* Permission denied */
  180. #define EFAULT 14 /* Bad address */
  181. #define ENOTBLK 15 /* Block device required */
  182. #define EBUSY 16 /* Device or resource busy */
  183. #define EEXIST 17 /* File exists */
  184. #define EXDEV 18 /* Cross-device link */
  185. #define ENODEV 19 /* No such device */
  186. #define ENOTDIR 20 /* Not a directory */
  187. #define EISDIR 21 /* Is a directory */
  188. #define EINVAL 22 /* Invalid argument */
  189. #define ENFILE 23 /* File table overflow */
  190. #define EMFILE 24 /* Too many open files */
  191. #define ENOTTY 25 /* Not a typewriter */
  192. #define ETXTBSY 26 /* Text file busy */
  193. #define EFBIG 27 /* File too large */
  194. #define ENOSPC 28 /* No space left on device */
  195. #define ESPIPE 29 /* Illegal seek */
  196. #define EROFS 30 /* Read-only file system */
  197. #define EMLINK 31 /* Too many links */
  198. #define EPIPE 32 /* Broken pipe */
  199. #define EDOM 33 /* Math argument out of domain of func */
  200. #define ERANGE 34 /* Math result not representable */
  201. extern void fh_audio_init(void);
  202. extern void fh_acw_test();
  203. #endif