sb.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. #ifndef __SOUND_SB_H
  2. #define __SOUND_SB_H
  3. /*
  4. * Header file for SoundBlaster cards
  5. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  6. *
  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; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <sound/pcm.h>
  24. #include <sound/rawmidi.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/io.h>
  27. enum sb_hw_type {
  28. SB_HW_AUTO,
  29. SB_HW_10,
  30. SB_HW_20,
  31. SB_HW_201,
  32. SB_HW_PRO,
  33. SB_HW_JAZZ16, /* Media Vision Jazz16 */
  34. SB_HW_16,
  35. SB_HW_16CSP, /* SB16 with CSP chip */
  36. SB_HW_ALS100, /* Avance Logic ALS100 chip */
  37. SB_HW_ALS4000, /* Avance Logic ALS4000 chip */
  38. SB_HW_DT019X, /* Diamond Tech. DT-019X / Avance Logic ALS-007 */
  39. SB_HW_CS5530, /* Cyrix/NatSemi 5530 VSA1 */
  40. };
  41. #define SB_OPEN_PCM 0x01
  42. #define SB_OPEN_MIDI_INPUT 0x02
  43. #define SB_OPEN_MIDI_OUTPUT 0x04
  44. #define SB_OPEN_MIDI_INPUT_TRIGGER 0x08
  45. #define SB_OPEN_MIDI_OUTPUT_TRIGGER 0x10
  46. #define SB_MODE_HALT 0x00
  47. #define SB_MODE_PLAYBACK_8 0x01
  48. #define SB_MODE_PLAYBACK_16 0x02
  49. #define SB_MODE_PLAYBACK (SB_MODE_PLAYBACK_8 | SB_MODE_PLAYBACK_16)
  50. #define SB_MODE_CAPTURE_8 0x04
  51. #define SB_MODE_CAPTURE_16 0x08
  52. #define SB_MODE_CAPTURE (SB_MODE_CAPTURE_8 | SB_MODE_CAPTURE_16)
  53. #define SB_RATE_LOCK_PLAYBACK 0x10
  54. #define SB_RATE_LOCK_CAPTURE 0x20
  55. #define SB_RATE_LOCK (SB_RATE_LOCK_PLAYBACK | SB_RATE_LOCK_CAPTURE)
  56. #define SB_MPU_INPUT 1
  57. struct snd_sb {
  58. unsigned long port; /* base port of DSP chip */
  59. struct resource *res_port;
  60. unsigned long mpu_port; /* MPU port for SB DSP 4.0+ */
  61. int irq; /* IRQ number of DSP chip */
  62. int dma8; /* 8-bit DMA */
  63. int dma16; /* 16-bit DMA */
  64. unsigned short version; /* version of DSP chip */
  65. enum sb_hw_type hardware; /* see to SB_HW_XXXX */
  66. unsigned long alt_port; /* alternate port (ALS4000) */
  67. struct pci_dev *pci; /* ALS4000 */
  68. unsigned int open; /* see to SB_OPEN_XXXX for sb8 */
  69. /* also SNDRV_SB_CSP_MODE_XXX for sb16_csp */
  70. unsigned int mode; /* current mode of stream */
  71. unsigned int force_mode16; /* force 16-bit mode of streams */
  72. unsigned int locked_rate; /* sb16 duplex */
  73. unsigned int playback_format;
  74. unsigned int capture_format;
  75. struct timer_list midi_timer;
  76. unsigned int p_dma_size;
  77. unsigned int p_period_size;
  78. unsigned int c_dma_size;
  79. unsigned int c_period_size;
  80. spinlock_t mixer_lock;
  81. char name[32];
  82. void *csp; /* used only when CONFIG_SND_SB16_CSP is set */
  83. struct snd_card *card;
  84. struct snd_pcm *pcm;
  85. struct snd_pcm_substream *playback_substream;
  86. struct snd_pcm_substream *capture_substream;
  87. struct snd_rawmidi *rmidi;
  88. struct snd_rawmidi_substream *midi_substream_input;
  89. struct snd_rawmidi_substream *midi_substream_output;
  90. irq_handler_t rmidi_callback;
  91. spinlock_t reg_lock;
  92. spinlock_t open_lock;
  93. spinlock_t midi_input_lock;
  94. struct snd_info_entry *proc_entry;
  95. #ifdef CONFIG_PM
  96. unsigned char saved_regs[0x20];
  97. #endif
  98. };
  99. /* I/O ports */
  100. #define SBP(chip, x) ((chip)->port + s_b_SB_##x)
  101. #define SBP1(port, x) ((port) + s_b_SB_##x)
  102. #define s_b_SB_RESET 0x6
  103. #define s_b_SB_READ 0xa
  104. #define s_b_SB_WRITE 0xc
  105. #define s_b_SB_COMMAND 0xc
  106. #define s_b_SB_STATUS 0xc
  107. #define s_b_SB_DATA_AVAIL 0xe
  108. #define s_b_SB_DATA_AVAIL_16 0xf
  109. #define s_b_SB_MIXER_ADDR 0x4
  110. #define s_b_SB_MIXER_DATA 0x5
  111. #define s_b_SB_OPL3_LEFT 0x0
  112. #define s_b_SB_OPL3_RIGHT 0x2
  113. #define s_b_SB_OPL3_BOTH 0x8
  114. #define SB_DSP_OUTPUT 0x14
  115. #define SB_DSP_INPUT 0x24
  116. #define SB_DSP_BLOCK_SIZE 0x48
  117. #define SB_DSP_HI_OUTPUT 0x91
  118. #define SB_DSP_HI_INPUT 0x99
  119. #define SB_DSP_LO_OUTPUT_AUTO 0x1c
  120. #define SB_DSP_LO_INPUT_AUTO 0x2c
  121. #define SB_DSP_HI_OUTPUT_AUTO 0x90
  122. #define SB_DSP_HI_INPUT_AUTO 0x98
  123. #define SB_DSP_IMMED_INT 0xf2
  124. #define SB_DSP_GET_VERSION 0xe1
  125. #define SB_DSP_SPEAKER_ON 0xd1
  126. #define SB_DSP_SPEAKER_OFF 0xd3
  127. #define SB_DSP_DMA8_OFF 0xd0
  128. #define SB_DSP_DMA8_ON 0xd4
  129. #define SB_DSP_DMA8_EXIT 0xda
  130. #define SB_DSP_DMA16_OFF 0xd5
  131. #define SB_DSP_DMA16_ON 0xd6
  132. #define SB_DSP_DMA16_EXIT 0xd9
  133. #define SB_DSP_SAMPLE_RATE 0x40
  134. #define SB_DSP_SAMPLE_RATE_OUT 0x41
  135. #define SB_DSP_SAMPLE_RATE_IN 0x42
  136. #define SB_DSP_MONO_8BIT 0xa0
  137. #define SB_DSP_MONO_16BIT 0xa4
  138. #define SB_DSP_STEREO_8BIT 0xa8
  139. #define SB_DSP_STEREO_16BIT 0xac
  140. #define SB_DSP_MIDI_INPUT_IRQ 0x31
  141. #define SB_DSP_MIDI_UART_IRQ 0x35
  142. #define SB_DSP_MIDI_OUTPUT 0x38
  143. #define SB_DSP4_OUT8_AI 0xc6
  144. #define SB_DSP4_IN8_AI 0xce
  145. #define SB_DSP4_OUT16_AI 0xb6
  146. #define SB_DSP4_IN16_AI 0xbe
  147. #define SB_DSP4_MODE_UNS_MONO 0x00
  148. #define SB_DSP4_MODE_SIGN_MONO 0x10
  149. #define SB_DSP4_MODE_UNS_STEREO 0x20
  150. #define SB_DSP4_MODE_SIGN_STEREO 0x30
  151. #define SB_DSP4_OUTPUT 0x3c
  152. #define SB_DSP4_INPUT_LEFT 0x3d
  153. #define SB_DSP4_INPUT_RIGHT 0x3e
  154. /* registers for SB 2.0 mixer */
  155. #define SB_DSP20_MASTER_DEV 0x02
  156. #define SB_DSP20_PCM_DEV 0x0A
  157. #define SB_DSP20_CD_DEV 0x08
  158. #define SB_DSP20_FM_DEV 0x06
  159. /* registers for SB PRO mixer */
  160. #define SB_DSP_MASTER_DEV 0x22
  161. #define SB_DSP_PCM_DEV 0x04
  162. #define SB_DSP_LINE_DEV 0x2e
  163. #define SB_DSP_CD_DEV 0x28
  164. #define SB_DSP_FM_DEV 0x26
  165. #define SB_DSP_MIC_DEV 0x0a
  166. #define SB_DSP_CAPTURE_SOURCE 0x0c
  167. #define SB_DSP_CAPTURE_FILT 0x0c
  168. #define SB_DSP_PLAYBACK_FILT 0x0e
  169. #define SB_DSP_STEREO_SW 0x0e
  170. #define SB_DSP_MIXS_MIC0 0x00 /* same as MIC */
  171. #define SB_DSP_MIXS_CD 0x01
  172. #define SB_DSP_MIXS_MIC 0x02
  173. #define SB_DSP_MIXS_LINE 0x03
  174. /* registers (only for left channel) for SB 16 mixer */
  175. #define SB_DSP4_MASTER_DEV 0x30
  176. #define SB_DSP4_BASS_DEV 0x46
  177. #define SB_DSP4_TREBLE_DEV 0x44
  178. #define SB_DSP4_SYNTH_DEV 0x34
  179. #define SB_DSP4_PCM_DEV 0x32
  180. #define SB_DSP4_SPEAKER_DEV 0x3b
  181. #define SB_DSP4_LINE_DEV 0x38
  182. #define SB_DSP4_MIC_DEV 0x3a
  183. #define SB_DSP4_OUTPUT_SW 0x3c
  184. #define SB_DSP4_CD_DEV 0x36
  185. #define SB_DSP4_IGAIN_DEV 0x3f
  186. #define SB_DSP4_OGAIN_DEV 0x41
  187. #define SB_DSP4_MIC_AGC 0x43
  188. /* additional registers for SB 16 mixer */
  189. #define SB_DSP4_IRQSETUP 0x80
  190. #define SB_DSP4_DMASETUP 0x81
  191. #define SB_DSP4_IRQSTATUS 0x82
  192. #define SB_DSP4_MPUSETUP 0x84
  193. #define SB_DSP4_3DSE 0x90
  194. /* Registers for DT-019x / ALS-007 mixer */
  195. #define SB_DT019X_MASTER_DEV 0x62
  196. #define SB_DT019X_PCM_DEV 0x64
  197. #define SB_DT019X_SYNTH_DEV 0x66
  198. #define SB_DT019X_CD_DEV 0x68
  199. #define SB_DT019X_MIC_DEV 0x6a
  200. #define SB_DT019X_SPKR_DEV 0x6a
  201. #define SB_DT019X_LINE_DEV 0x6e
  202. #define SB_DT019X_OUTPUT_SW2 0x4c
  203. #define SB_DT019X_CAPTURE_SW 0x6c
  204. #define SB_DT019X_CAP_CD 0x02
  205. #define SB_DT019X_CAP_MIC 0x04
  206. #define SB_DT019X_CAP_LINE 0x06
  207. #define SB_DT019X_CAP_SYNTH 0x07
  208. #define SB_DT019X_CAP_MAIN 0x07
  209. #define SB_ALS4000_MONO_IO_CTRL 0x4b
  210. #define SB_ALS4000_OUT_MIXER_CTRL_2 0x4c
  211. #define SB_ALS4000_MIC_IN_GAIN 0x4d
  212. #define SB_ALS4000_ANALOG_REFRNC_VOLT_CTRL 0x4e
  213. #define SB_ALS4000_FMDAC 0x4f
  214. #define SB_ALS4000_3D_SND_FX 0x50
  215. #define SB_ALS4000_3D_TIME_DELAY 0x51
  216. #define SB_ALS4000_3D_AUTO_MUTE 0x52
  217. #define SB_ALS4000_ANALOG_BLOCK_CTRL 0x53
  218. #define SB_ALS4000_3D_DELAYLINE_PATTERN 0x54
  219. #define SB_ALS4000_CR3_CONFIGURATION 0xc3 /* bit 7 is Digital Loop Enable */
  220. #define SB_ALS4000_QSOUND 0xdb
  221. /* IRQ setting bitmap */
  222. #define SB_IRQSETUP_IRQ9 0x01
  223. #define SB_IRQSETUP_IRQ5 0x02
  224. #define SB_IRQSETUP_IRQ7 0x04
  225. #define SB_IRQSETUP_IRQ10 0x08
  226. /* IRQ types */
  227. #define SB_IRQTYPE_8BIT 0x01
  228. #define SB_IRQTYPE_16BIT 0x02
  229. #define SB_IRQTYPE_MPUIN 0x04
  230. #define ALS4K_IRQTYPE_CR1E_DMA 0x20
  231. /* DMA setting bitmap */
  232. #define SB_DMASETUP_DMA0 0x01
  233. #define SB_DMASETUP_DMA1 0x02
  234. #define SB_DMASETUP_DMA3 0x08
  235. #define SB_DMASETUP_DMA5 0x20
  236. #define SB_DMASETUP_DMA6 0x40
  237. #define SB_DMASETUP_DMA7 0x80
  238. /*
  239. *
  240. */
  241. static inline void snd_sb_ack_8bit(struct snd_sb *chip)
  242. {
  243. inb(SBP(chip, DATA_AVAIL));
  244. }
  245. static inline void snd_sb_ack_16bit(struct snd_sb *chip)
  246. {
  247. inb(SBP(chip, DATA_AVAIL_16));
  248. }
  249. /* sb_common.c */
  250. int snd_sbdsp_command(struct snd_sb *chip, unsigned char val);
  251. int snd_sbdsp_get_byte(struct snd_sb *chip);
  252. int snd_sbdsp_reset(struct snd_sb *chip);
  253. int snd_sbdsp_create(struct snd_card *card,
  254. unsigned long port,
  255. int irq,
  256. irq_handler_t irq_handler,
  257. int dma8, int dma16,
  258. unsigned short hardware,
  259. struct snd_sb **r_chip);
  260. /* sb_mixer.c */
  261. void snd_sbmixer_write(struct snd_sb *chip, unsigned char reg, unsigned char data);
  262. unsigned char snd_sbmixer_read(struct snd_sb *chip, unsigned char reg);
  263. int snd_sbmixer_new(struct snd_sb *chip);
  264. #ifdef CONFIG_PM
  265. void snd_sbmixer_suspend(struct snd_sb *chip);
  266. void snd_sbmixer_resume(struct snd_sb *chip);
  267. #endif
  268. /* sb8_init.c */
  269. int snd_sb8dsp_pcm(struct snd_sb *chip, int device);
  270. /* sb8.c */
  271. irqreturn_t snd_sb8dsp_interrupt(struct snd_sb *chip);
  272. int snd_sb8_playback_open(struct snd_pcm_substream *substream);
  273. int snd_sb8_capture_open(struct snd_pcm_substream *substream);
  274. int snd_sb8_playback_close(struct snd_pcm_substream *substream);
  275. int snd_sb8_capture_close(struct snd_pcm_substream *substream);
  276. /* midi8.c */
  277. irqreturn_t snd_sb8dsp_midi_interrupt(struct snd_sb *chip);
  278. int snd_sb8dsp_midi(struct snd_sb *chip, int device);
  279. /* sb16_init.c */
  280. int snd_sb16dsp_pcm(struct snd_sb *chip, int device);
  281. const struct snd_pcm_ops *snd_sb16dsp_get_pcm_ops(int direction);
  282. int snd_sb16dsp_configure(struct snd_sb *chip);
  283. /* sb16.c */
  284. irqreturn_t snd_sb16dsp_interrupt(int irq, void *dev_id);
  285. /* exported mixer stuffs */
  286. enum {
  287. SB_MIX_SINGLE,
  288. SB_MIX_DOUBLE,
  289. SB_MIX_INPUT_SW,
  290. SB_MIX_CAPTURE_PRO,
  291. SB_MIX_CAPTURE_DT019X,
  292. SB_MIX_MONO_CAPTURE_ALS4K
  293. };
  294. #define SB_MIXVAL_DOUBLE(left_reg, right_reg, left_shift, right_shift, mask) \
  295. ((left_reg) | ((right_reg) << 8) | ((left_shift) << 16) | ((right_shift) << 19) | ((mask) << 24))
  296. #define SB_MIXVAL_SINGLE(reg, shift, mask) \
  297. ((reg) | ((shift) << 16) | ((mask) << 24))
  298. #define SB_MIXVAL_INPUT_SW(reg1, reg2, left_shift, right_shift) \
  299. ((reg1) | ((reg2) << 8) | ((left_shift) << 16) | ((right_shift) << 24))
  300. int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int type, unsigned long value);
  301. /* for ease of use */
  302. struct sbmix_elem {
  303. const char *name;
  304. int type;
  305. unsigned long private_value;
  306. };
  307. #define SB_SINGLE(xname, reg, shift, mask) \
  308. { .name = xname, \
  309. .type = SB_MIX_SINGLE, \
  310. .private_value = SB_MIXVAL_SINGLE(reg, shift, mask) }
  311. #define SB_DOUBLE(xname, left_reg, right_reg, left_shift, right_shift, mask) \
  312. { .name = xname, \
  313. .type = SB_MIX_DOUBLE, \
  314. .private_value = SB_MIXVAL_DOUBLE(left_reg, right_reg, left_shift, right_shift, mask) }
  315. #define SB16_INPUT_SW(xname, reg1, reg2, left_shift, right_shift) \
  316. { .name = xname, \
  317. .type = SB_MIX_INPUT_SW, \
  318. .private_value = SB_MIXVAL_INPUT_SW(reg1, reg2, left_shift, right_shift) }
  319. static inline int snd_sbmixer_add_ctl_elem(struct snd_sb *chip, const struct sbmix_elem *c)
  320. {
  321. return snd_sbmixer_add_ctl(chip, c->name, 0, c->type, c->private_value);
  322. }
  323. #endif /* __SOUND_SB_H */