sb16_csp.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef __SOUND_SB16_CSP_H
  2. #define __SOUND_SB16_CSP_H
  3. /*
  4. * Copyright (c) 1999 by Uros Bizjak <uros@kss-loka.si>
  5. * Takashi Iwai <tiwai@suse.de>
  6. *
  7. * SB16ASP/AWE32 CSP control
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. /* CSP modes */
  25. #define SNDRV_SB_CSP_MODE_NONE 0x00
  26. #define SNDRV_SB_CSP_MODE_DSP_READ 0x01 /* Record from DSP */
  27. #define SNDRV_SB_CSP_MODE_DSP_WRITE 0x02 /* Play to DSP */
  28. #define SNDRV_SB_CSP_MODE_QSOUND 0x04 /* QSound */
  29. /* CSP load flags */
  30. #define SNDRV_SB_CSP_LOAD_FROMUSER 0x01
  31. #define SNDRV_SB_CSP_LOAD_INITBLOCK 0x02
  32. /* CSP sample width */
  33. #define SNDRV_SB_CSP_SAMPLE_8BIT 0x01
  34. #define SNDRV_SB_CSP_SAMPLE_16BIT 0x02
  35. /* CSP channels */
  36. #define SNDRV_SB_CSP_MONO 0x01
  37. #define SNDRV_SB_CSP_STEREO 0x02
  38. /* CSP rates */
  39. #define SNDRV_SB_CSP_RATE_8000 0x01
  40. #define SNDRV_SB_CSP_RATE_11025 0x02
  41. #define SNDRV_SB_CSP_RATE_22050 0x04
  42. #define SNDRV_SB_CSP_RATE_44100 0x08
  43. #define SNDRV_SB_CSP_RATE_ALL 0x0f
  44. /* CSP running state */
  45. #define SNDRV_SB_CSP_ST_IDLE 0x00
  46. #define SNDRV_SB_CSP_ST_LOADED 0x01
  47. #define SNDRV_SB_CSP_ST_RUNNING 0x02
  48. #define SNDRV_SB_CSP_ST_PAUSED 0x04
  49. #define SNDRV_SB_CSP_ST_AUTO 0x08
  50. #define SNDRV_SB_CSP_ST_QSOUND 0x10
  51. /* maximum QSound value (180 degrees right) */
  52. #define SNDRV_SB_CSP_QSOUND_MAX_RIGHT 0x20
  53. /* maximum microcode RIFF file size */
  54. #define SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE 0x3000
  55. /* microcode header */
  56. struct snd_sb_csp_mc_header {
  57. char codec_name[16]; /* id name of codec */
  58. unsigned short func_req; /* requested function */
  59. };
  60. /* microcode to be loaded */
  61. struct snd_sb_csp_microcode {
  62. struct snd_sb_csp_mc_header info;
  63. unsigned char data[SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE];
  64. };
  65. /* start CSP with sample_width in mono/stereo */
  66. struct snd_sb_csp_start {
  67. int sample_width; /* sample width, look above */
  68. int channels; /* channels, look above */
  69. };
  70. /* CSP information */
  71. struct snd_sb_csp_info {
  72. char codec_name[16]; /* id name of codec */
  73. unsigned short func_nr; /* function number */
  74. unsigned int acc_format; /* accepted PCM formats */
  75. unsigned short acc_channels; /* accepted channels */
  76. unsigned short acc_width; /* accepted sample width */
  77. unsigned short acc_rates; /* accepted sample rates */
  78. unsigned short csp_mode; /* CSP mode, see above */
  79. unsigned short run_channels; /* current channels */
  80. unsigned short run_width; /* current sample width */
  81. unsigned short version; /* version id: 0x10 - 0x1f */
  82. unsigned short state; /* state bits */
  83. };
  84. /* HWDEP controls */
  85. /* get CSP information */
  86. #define SNDRV_SB_CSP_IOCTL_INFO _IOR('H', 0x10, struct snd_sb_csp_info)
  87. /* load microcode to CSP */
  88. /* NOTE: struct snd_sb_csp_microcode overflows the max size (13 bits)
  89. * defined for some architectures like MIPS, and it leads to build errors.
  90. * (x86 and co have 14-bit size, thus it's valid, though.)
  91. * As a workaround for skipping the size-limit check, here we don't use the
  92. * normal _IOW() macro but _IOC() with the manual argument.
  93. */
  94. #define SNDRV_SB_CSP_IOCTL_LOAD_CODE \
  95. _IOC(_IOC_WRITE, 'H', 0x11, sizeof(struct snd_sb_csp_microcode))
  96. /* unload microcode from CSP */
  97. #define SNDRV_SB_CSP_IOCTL_UNLOAD_CODE _IO('H', 0x12)
  98. /* start CSP */
  99. #define SNDRV_SB_CSP_IOCTL_START _IOW('H', 0x13, struct snd_sb_csp_start)
  100. /* stop CSP */
  101. #define SNDRV_SB_CSP_IOCTL_STOP _IO('H', 0x14)
  102. /* pause CSP and DMA transfer */
  103. #define SNDRV_SB_CSP_IOCTL_PAUSE _IO('H', 0x15)
  104. /* restart CSP and DMA transfer */
  105. #define SNDRV_SB_CSP_IOCTL_RESTART _IO('H', 0x16)
  106. #ifdef __KERNEL__
  107. #include "sb.h"
  108. #include "hwdep.h"
  109. #include <linux/firmware.h>
  110. struct snd_sb_csp;
  111. /* indices for the known CSP programs */
  112. enum {
  113. CSP_PROGRAM_MULAW,
  114. CSP_PROGRAM_ALAW,
  115. CSP_PROGRAM_ADPCM_INIT,
  116. CSP_PROGRAM_ADPCM_PLAYBACK,
  117. CSP_PROGRAM_ADPCM_CAPTURE,
  118. CSP_PROGRAM_COUNT
  119. };
  120. /*
  121. * CSP operators
  122. */
  123. struct snd_sb_csp_ops {
  124. int (*csp_use) (struct snd_sb_csp * p);
  125. int (*csp_unuse) (struct snd_sb_csp * p);
  126. int (*csp_autoload) (struct snd_sb_csp * p, int pcm_sfmt, int play_rec_mode);
  127. int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
  128. int (*csp_stop) (struct snd_sb_csp * p);
  129. int (*csp_qsound_transfer) (struct snd_sb_csp * p);
  130. };
  131. /*
  132. * CSP private data
  133. */
  134. struct snd_sb_csp {
  135. struct snd_sb *chip; /* SB16 DSP */
  136. int used; /* usage flag - exclusive */
  137. char codec_name[16]; /* name of codec */
  138. unsigned short func_nr; /* function number */
  139. unsigned int acc_format; /* accepted PCM formats */
  140. int acc_channels; /* accepted channels */
  141. int acc_width; /* accepted sample width */
  142. int acc_rates; /* accepted sample rates */
  143. int mode; /* MODE */
  144. int run_channels; /* current CSP channels */
  145. int run_width; /* current sample width */
  146. int version; /* CSP version (0x10 - 0x1f) */
  147. int running; /* running state */
  148. struct snd_sb_csp_ops ops; /* operators */
  149. spinlock_t q_lock; /* locking */
  150. int q_enabled; /* enabled flag */
  151. int qpos_left; /* left position */
  152. int qpos_right; /* right position */
  153. int qpos_changed; /* position changed flag */
  154. struct snd_kcontrol *qsound_switch;
  155. struct snd_kcontrol *qsound_space;
  156. struct mutex access_mutex; /* locking */
  157. const struct firmware *csp_programs[CSP_PROGRAM_COUNT];
  158. };
  159. int snd_sb_csp_new(struct snd_sb *chip, int device, struct snd_hwdep ** rhwdep);
  160. #endif
  161. #endif /* __SOUND_SB16_CSP */