lx_core.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* -*- linux-c -*- *
  2. *
  3. * ALSA driver for the digigram lx6464es interface
  4. * low-level interface
  5. *
  6. * Copyright (c) 2009 Tim Blechmann <tim@klingt.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; see the file COPYING. If not, write to
  20. * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. * Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. #ifndef LX_CORE_H
  25. #define LX_CORE_H
  26. #include <linux/interrupt.h>
  27. #include "lx_defs.h"
  28. #define REG_CRM_NUMBER 12
  29. struct lx6464es;
  30. /* low-level register access */
  31. /* dsp register access */
  32. enum {
  33. eReg_BASE,
  34. eReg_CSM,
  35. eReg_CRM1,
  36. eReg_CRM2,
  37. eReg_CRM3,
  38. eReg_CRM4,
  39. eReg_CRM5,
  40. eReg_CRM6,
  41. eReg_CRM7,
  42. eReg_CRM8,
  43. eReg_CRM9,
  44. eReg_CRM10,
  45. eReg_CRM11,
  46. eReg_CRM12,
  47. eReg_ICR,
  48. eReg_CVR,
  49. eReg_ISR,
  50. eReg_RXHTXH,
  51. eReg_RXMTXM,
  52. eReg_RHLTXL,
  53. eReg_RESETDSP,
  54. eReg_CSUF,
  55. eReg_CSES,
  56. eReg_CRESMSB,
  57. eReg_CRESLSB,
  58. eReg_ADMACESMSB,
  59. eReg_ADMACESLSB,
  60. eReg_CONFES,
  61. eMaxPortLx
  62. };
  63. unsigned long lx_dsp_reg_read(struct lx6464es *chip, int port);
  64. void lx_dsp_reg_readbuf(struct lx6464es *chip, int port, u32 *data, u32 len);
  65. void lx_dsp_reg_write(struct lx6464es *chip, int port, unsigned data);
  66. void lx_dsp_reg_writebuf(struct lx6464es *chip, int port, const u32 *data,
  67. u32 len);
  68. /* plx register access */
  69. enum {
  70. ePLX_PCICR,
  71. ePLX_MBOX0,
  72. ePLX_MBOX1,
  73. ePLX_MBOX2,
  74. ePLX_MBOX3,
  75. ePLX_MBOX4,
  76. ePLX_MBOX5,
  77. ePLX_MBOX6,
  78. ePLX_MBOX7,
  79. ePLX_L2PCIDB,
  80. ePLX_IRQCS,
  81. ePLX_CHIPSC,
  82. eMaxPort
  83. };
  84. unsigned long lx_plx_reg_read(struct lx6464es *chip, int port);
  85. void lx_plx_reg_write(struct lx6464es *chip, int port, u32 data);
  86. /* rhm */
  87. struct lx_rmh {
  88. u16 cmd_len; /* length of the command to send (WORDs) */
  89. u16 stat_len; /* length of the status received (WORDs) */
  90. u16 dsp_stat; /* status type, RMP_SSIZE_XXX */
  91. u16 cmd_idx; /* index of the command */
  92. u32 cmd[REG_CRM_NUMBER];
  93. u32 stat[REG_CRM_NUMBER];
  94. };
  95. /* low-level dsp access */
  96. int __devinit lx_dsp_get_version(struct lx6464es *chip, u32 *rdsp_version);
  97. int lx_dsp_get_clock_frequency(struct lx6464es *chip, u32 *rfreq);
  98. int lx_dsp_set_granularity(struct lx6464es *chip, u32 gran);
  99. int lx_dsp_read_async_events(struct lx6464es *chip, u32 *data);
  100. int lx_dsp_get_mac(struct lx6464es *chip, u8 *mac_address);
  101. /* low-level pipe handling */
  102. int lx_pipe_allocate(struct lx6464es *chip, u32 pipe, int is_capture,
  103. int channels);
  104. int lx_pipe_release(struct lx6464es *chip, u32 pipe, int is_capture);
  105. int lx_pipe_sample_count(struct lx6464es *chip, u32 pipe, int is_capture,
  106. u64 *rsample_count);
  107. int lx_pipe_state(struct lx6464es *chip, u32 pipe, int is_capture, u16 *rstate);
  108. int lx_pipe_stop(struct lx6464es *chip, u32 pipe, int is_capture);
  109. int lx_pipe_start(struct lx6464es *chip, u32 pipe, int is_capture);
  110. int lx_pipe_pause(struct lx6464es *chip, u32 pipe, int is_capture);
  111. int lx_pipe_wait_for_start(struct lx6464es *chip, u32 pipe, int is_capture);
  112. int lx_pipe_wait_for_idle(struct lx6464es *chip, u32 pipe, int is_capture);
  113. /* low-level stream handling */
  114. int lx_stream_set_format(struct lx6464es *chip, struct snd_pcm_runtime *runtime,
  115. u32 pipe, int is_capture);
  116. int lx_stream_state(struct lx6464es *chip, u32 pipe, int is_capture,
  117. int *rstate);
  118. int lx_stream_sample_position(struct lx6464es *chip, u32 pipe, int is_capture,
  119. u64 *r_bytepos);
  120. int lx_stream_set_state(struct lx6464es *chip, u32 pipe,
  121. int is_capture, enum stream_state_t state);
  122. static inline int lx_stream_start(struct lx6464es *chip, u32 pipe,
  123. int is_capture)
  124. {
  125. snd_printdd("->lx_stream_start\n");
  126. return lx_stream_set_state(chip, pipe, is_capture, SSTATE_RUN);
  127. }
  128. static inline int lx_stream_pause(struct lx6464es *chip, u32 pipe,
  129. int is_capture)
  130. {
  131. snd_printdd("->lx_stream_pause\n");
  132. return lx_stream_set_state(chip, pipe, is_capture, SSTATE_PAUSE);
  133. }
  134. static inline int lx_stream_stop(struct lx6464es *chip, u32 pipe,
  135. int is_capture)
  136. {
  137. snd_printdd("->lx_stream_stop\n");
  138. return lx_stream_set_state(chip, pipe, is_capture, SSTATE_STOP);
  139. }
  140. /* low-level buffer handling */
  141. int lx_buffer_ask(struct lx6464es *chip, u32 pipe, int is_capture,
  142. u32 *r_needed, u32 *r_freed, u32 *size_array);
  143. int lx_buffer_give(struct lx6464es *chip, u32 pipe, int is_capture,
  144. u32 buffer_size, u32 buf_address_lo, u32 buf_address_hi,
  145. u32 *r_buffer_index);
  146. int lx_buffer_free(struct lx6464es *chip, u32 pipe, int is_capture,
  147. u32 *r_buffer_size);
  148. int lx_buffer_cancel(struct lx6464es *chip, u32 pipe, int is_capture,
  149. u32 buffer_index);
  150. /* low-level gain/peak handling */
  151. int lx_level_unmute(struct lx6464es *chip, int is_capture, int unmute);
  152. int lx_level_peaks(struct lx6464es *chip, int is_capture, int channels,
  153. u32 *r_levels);
  154. /* interrupt handling */
  155. irqreturn_t lx_interrupt(int irq, void *dev_id);
  156. void lx_irq_enable(struct lx6464es *chip);
  157. void lx_irq_disable(struct lx6464es *chip);
  158. void lx_tasklet_capture(unsigned long data);
  159. void lx_tasklet_playback(unsigned long data);
  160. /* Stream Format Header Defines (for LIN and IEEE754) */
  161. #define HEADER_FMT_BASE HEADER_FMT_BASE_LIN
  162. #define HEADER_FMT_BASE_LIN 0xFED00000
  163. #define HEADER_FMT_BASE_FLOAT 0xFAD00000
  164. #define HEADER_FMT_MONO 0x00000080 /* bit 23 in header_lo. WARNING: old
  165. * bit 22 is ignored in float
  166. * format */
  167. #define HEADER_FMT_INTEL 0x00008000
  168. #define HEADER_FMT_16BITS 0x00002000
  169. #define HEADER_FMT_24BITS 0x00004000
  170. #define HEADER_FMT_UPTO11 0x00000200 /* frequency is less or equ. to 11k.
  171. * */
  172. #define HEADER_FMT_UPTO32 0x00000100 /* frequency is over 11k and less
  173. * then 32k.*/
  174. #define BIT_FMP_HEADER 23
  175. #define BIT_FMP_SD 22
  176. #define BIT_FMP_MULTICHANNEL 19
  177. #define START_STATE 1
  178. #define PAUSE_STATE 0
  179. /* from PcxAll_e.h */
  180. /* Start/Pause condition for pipes (PCXStartPipe, PCXPausePipe) */
  181. #define START_PAUSE_IMMEDIATE 0
  182. #define START_PAUSE_ON_SYNCHRO 1
  183. #define START_PAUSE_ON_TIME_CODE 2
  184. /* Pipe / Stream state */
  185. #define START_STATE 1
  186. #define PAUSE_STATE 0
  187. static inline void unpack_pointer(dma_addr_t ptr, u32 *r_low, u32 *r_high)
  188. {
  189. *r_low = (u32)(ptr & 0xffffffff);
  190. #if BITS_PER_LONG == 32
  191. *r_high = 0;
  192. #else
  193. *r_high = (u32)((u64)ptr>>32);
  194. #endif
  195. }
  196. #endif /* LX_CORE_H */