sb8_main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * Uros Bizjak <uros@kss-loka.si>
  4. *
  5. * Routines for control of 8-bit SoundBlaster cards and clones
  6. * Please note: I don't have access to old SB8 soundcards.
  7. *
  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. *
  25. * Thu Apr 29 20:36:17 BST 1999 George David Morrison <gdm@gedamo.demon.co.uk>
  26. * DSP can't respond to commands whilst in "high speed" mode. Caused
  27. * glitching during playback. Fixed.
  28. *
  29. * Wed Jul 12 22:02:55 CEST 2000 Uros Bizjak <uros@kss-loka.si>
  30. * Cleaned up and rewrote lowlevel routines.
  31. */
  32. #include <linux/io.h>
  33. #include <asm/dma.h>
  34. #include <linux/init.h>
  35. #include <linux/time.h>
  36. #include <linux/module.h>
  37. #include <sound/core.h>
  38. #include <sound/sb.h>
  39. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Uros Bizjak <uros@kss-loka.si>");
  40. MODULE_DESCRIPTION("Routines for control of 8-bit SoundBlaster cards and clones");
  41. MODULE_LICENSE("GPL");
  42. #define SB8_CLOCK 1000000
  43. #define SB8_DEN(v) ((SB8_CLOCK + (v) / 2) / (v))
  44. #define SB8_RATE(v) (SB8_CLOCK / SB8_DEN(v))
  45. static struct snd_ratnum clock = {
  46. .num = SB8_CLOCK,
  47. .den_min = 1,
  48. .den_max = 256,
  49. .den_step = 1,
  50. };
  51. static struct snd_pcm_hw_constraint_ratnums hw_constraints_clock = {
  52. .nrats = 1,
  53. .rats = &clock,
  54. };
  55. static struct snd_ratnum stereo_clocks[] = {
  56. {
  57. .num = SB8_CLOCK,
  58. .den_min = SB8_DEN(22050),
  59. .den_max = SB8_DEN(22050),
  60. .den_step = 1,
  61. },
  62. {
  63. .num = SB8_CLOCK,
  64. .den_min = SB8_DEN(11025),
  65. .den_max = SB8_DEN(11025),
  66. .den_step = 1,
  67. }
  68. };
  69. static int snd_sb8_hw_constraint_rate_channels(struct snd_pcm_hw_params *params,
  70. struct snd_pcm_hw_rule *rule)
  71. {
  72. struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
  73. if (c->min > 1) {
  74. unsigned int num = 0, den = 0;
  75. int err = snd_interval_ratnum(hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE),
  76. 2, stereo_clocks, &num, &den);
  77. if (err >= 0 && den) {
  78. params->rate_num = num;
  79. params->rate_den = den;
  80. }
  81. return err;
  82. }
  83. return 0;
  84. }
  85. static int snd_sb8_hw_constraint_channels_rate(struct snd_pcm_hw_params *params,
  86. struct snd_pcm_hw_rule *rule)
  87. {
  88. struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
  89. if (r->min > SB8_RATE(22050) || r->max <= SB8_RATE(11025)) {
  90. struct snd_interval t = { .min = 1, .max = 1 };
  91. return snd_interval_refine(hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS), &t);
  92. }
  93. return 0;
  94. }
  95. static int snd_sb8_playback_prepare(struct snd_pcm_substream *substream)
  96. {
  97. unsigned long flags;
  98. struct snd_sb *chip = snd_pcm_substream_chip(substream);
  99. struct snd_pcm_runtime *runtime = substream->runtime;
  100. unsigned int mixreg, rate, size, count;
  101. unsigned char format;
  102. unsigned char stereo = runtime->channels > 1;
  103. int dma;
  104. rate = runtime->rate;
  105. switch (chip->hardware) {
  106. case SB_HW_JAZZ16:
  107. if (runtime->format == SNDRV_PCM_FORMAT_S16_LE) {
  108. if (chip->mode & SB_MODE_CAPTURE_16)
  109. return -EBUSY;
  110. else
  111. chip->mode |= SB_MODE_PLAYBACK_16;
  112. }
  113. chip->playback_format = SB_DSP_LO_OUTPUT_AUTO;
  114. break;
  115. case SB_HW_PRO:
  116. if (runtime->channels > 1) {
  117. if (snd_BUG_ON(rate != SB8_RATE(11025) &&
  118. rate != SB8_RATE(22050)))
  119. return -EINVAL;
  120. chip->playback_format = SB_DSP_HI_OUTPUT_AUTO;
  121. break;
  122. }
  123. /* fallthru */
  124. case SB_HW_201:
  125. if (rate > 23000) {
  126. chip->playback_format = SB_DSP_HI_OUTPUT_AUTO;
  127. break;
  128. }
  129. /* fallthru */
  130. case SB_HW_20:
  131. chip->playback_format = SB_DSP_LO_OUTPUT_AUTO;
  132. break;
  133. case SB_HW_10:
  134. chip->playback_format = SB_DSP_OUTPUT;
  135. break;
  136. default:
  137. return -EINVAL;
  138. }
  139. if (chip->mode & SB_MODE_PLAYBACK_16) {
  140. format = stereo ? SB_DSP_STEREO_16BIT : SB_DSP_MONO_16BIT;
  141. dma = chip->dma16;
  142. } else {
  143. format = stereo ? SB_DSP_STEREO_8BIT : SB_DSP_MONO_8BIT;
  144. chip->mode |= SB_MODE_PLAYBACK_8;
  145. dma = chip->dma8;
  146. }
  147. size = chip->p_dma_size = snd_pcm_lib_buffer_bytes(substream);
  148. count = chip->p_period_size = snd_pcm_lib_period_bytes(substream);
  149. spin_lock_irqsave(&chip->reg_lock, flags);
  150. snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON);
  151. if (chip->hardware == SB_HW_JAZZ16)
  152. snd_sbdsp_command(chip, format);
  153. else if (stereo) {
  154. /* set playback stereo mode */
  155. spin_lock(&chip->mixer_lock);
  156. mixreg = snd_sbmixer_read(chip, SB_DSP_STEREO_SW);
  157. snd_sbmixer_write(chip, SB_DSP_STEREO_SW, mixreg | 0x02);
  158. spin_unlock(&chip->mixer_lock);
  159. /* Soundblaster hardware programming reference guide, 3-23 */
  160. snd_sbdsp_command(chip, SB_DSP_DMA8_EXIT);
  161. runtime->dma_area[0] = 0x80;
  162. snd_dma_program(dma, runtime->dma_addr, 1, DMA_MODE_WRITE);
  163. /* force interrupt */
  164. snd_sbdsp_command(chip, SB_DSP_OUTPUT);
  165. snd_sbdsp_command(chip, 0);
  166. snd_sbdsp_command(chip, 0);
  167. }
  168. snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE);
  169. if (stereo) {
  170. snd_sbdsp_command(chip, 256 - runtime->rate_den / 2);
  171. spin_lock(&chip->mixer_lock);
  172. /* save output filter status and turn it off */
  173. mixreg = snd_sbmixer_read(chip, SB_DSP_PLAYBACK_FILT);
  174. snd_sbmixer_write(chip, SB_DSP_PLAYBACK_FILT, mixreg | 0x20);
  175. spin_unlock(&chip->mixer_lock);
  176. /* just use force_mode16 for temporary storate... */
  177. chip->force_mode16 = mixreg;
  178. } else {
  179. snd_sbdsp_command(chip, 256 - runtime->rate_den);
  180. }
  181. if (chip->playback_format != SB_DSP_OUTPUT) {
  182. if (chip->mode & SB_MODE_PLAYBACK_16)
  183. count /= 2;
  184. count--;
  185. snd_sbdsp_command(chip, SB_DSP_BLOCK_SIZE);
  186. snd_sbdsp_command(chip, count & 0xff);
  187. snd_sbdsp_command(chip, count >> 8);
  188. }
  189. spin_unlock_irqrestore(&chip->reg_lock, flags);
  190. snd_dma_program(dma, runtime->dma_addr,
  191. size, DMA_MODE_WRITE | DMA_AUTOINIT);
  192. return 0;
  193. }
  194. static int snd_sb8_playback_trigger(struct snd_pcm_substream *substream,
  195. int cmd)
  196. {
  197. unsigned long flags;
  198. struct snd_sb *chip = snd_pcm_substream_chip(substream);
  199. unsigned int count;
  200. spin_lock_irqsave(&chip->reg_lock, flags);
  201. switch (cmd) {
  202. case SNDRV_PCM_TRIGGER_START:
  203. snd_sbdsp_command(chip, chip->playback_format);
  204. if (chip->playback_format == SB_DSP_OUTPUT) {
  205. count = chip->p_period_size - 1;
  206. snd_sbdsp_command(chip, count & 0xff);
  207. snd_sbdsp_command(chip, count >> 8);
  208. }
  209. break;
  210. case SNDRV_PCM_TRIGGER_STOP:
  211. if (chip->playback_format == SB_DSP_HI_OUTPUT_AUTO) {
  212. struct snd_pcm_runtime *runtime = substream->runtime;
  213. snd_sbdsp_reset(chip);
  214. if (runtime->channels > 1) {
  215. spin_lock(&chip->mixer_lock);
  216. /* restore output filter and set hardware to mono mode */
  217. snd_sbmixer_write(chip, SB_DSP_STEREO_SW, chip->force_mode16 & ~0x02);
  218. spin_unlock(&chip->mixer_lock);
  219. }
  220. } else {
  221. snd_sbdsp_command(chip, SB_DSP_DMA8_OFF);
  222. }
  223. snd_sbdsp_command(chip, SB_DSP_SPEAKER_OFF);
  224. }
  225. spin_unlock_irqrestore(&chip->reg_lock, flags);
  226. return 0;
  227. }
  228. static int snd_sb8_hw_params(struct snd_pcm_substream *substream,
  229. struct snd_pcm_hw_params *hw_params)
  230. {
  231. return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  232. }
  233. static int snd_sb8_hw_free(struct snd_pcm_substream *substream)
  234. {
  235. snd_pcm_lib_free_pages(substream);
  236. return 0;
  237. }
  238. static int snd_sb8_capture_prepare(struct snd_pcm_substream *substream)
  239. {
  240. unsigned long flags;
  241. struct snd_sb *chip = snd_pcm_substream_chip(substream);
  242. struct snd_pcm_runtime *runtime = substream->runtime;
  243. unsigned int mixreg, rate, size, count;
  244. unsigned char format;
  245. unsigned char stereo = runtime->channels > 1;
  246. int dma;
  247. rate = runtime->rate;
  248. switch (chip->hardware) {
  249. case SB_HW_JAZZ16:
  250. if (runtime->format == SNDRV_PCM_FORMAT_S16_LE) {
  251. if (chip->mode & SB_MODE_PLAYBACK_16)
  252. return -EBUSY;
  253. else
  254. chip->mode |= SB_MODE_CAPTURE_16;
  255. }
  256. chip->capture_format = SB_DSP_LO_INPUT_AUTO;
  257. break;
  258. case SB_HW_PRO:
  259. if (runtime->channels > 1) {
  260. if (snd_BUG_ON(rate != SB8_RATE(11025) &&
  261. rate != SB8_RATE(22050)))
  262. return -EINVAL;
  263. chip->capture_format = SB_DSP_HI_INPUT_AUTO;
  264. break;
  265. }
  266. chip->capture_format = (rate > 23000) ? SB_DSP_HI_INPUT_AUTO : SB_DSP_LO_INPUT_AUTO;
  267. break;
  268. case SB_HW_201:
  269. if (rate > 13000) {
  270. chip->capture_format = SB_DSP_HI_INPUT_AUTO;
  271. break;
  272. }
  273. /* fallthru */
  274. case SB_HW_20:
  275. chip->capture_format = SB_DSP_LO_INPUT_AUTO;
  276. break;
  277. case SB_HW_10:
  278. chip->capture_format = SB_DSP_INPUT;
  279. break;
  280. default:
  281. return -EINVAL;
  282. }
  283. if (chip->mode & SB_MODE_CAPTURE_16) {
  284. format = stereo ? SB_DSP_STEREO_16BIT : SB_DSP_MONO_16BIT;
  285. dma = chip->dma16;
  286. } else {
  287. format = stereo ? SB_DSP_STEREO_8BIT : SB_DSP_MONO_8BIT;
  288. chip->mode |= SB_MODE_CAPTURE_8;
  289. dma = chip->dma8;
  290. }
  291. size = chip->c_dma_size = snd_pcm_lib_buffer_bytes(substream);
  292. count = chip->c_period_size = snd_pcm_lib_period_bytes(substream);
  293. spin_lock_irqsave(&chip->reg_lock, flags);
  294. snd_sbdsp_command(chip, SB_DSP_SPEAKER_OFF);
  295. if (chip->hardware == SB_HW_JAZZ16)
  296. snd_sbdsp_command(chip, format);
  297. else if (stereo)
  298. snd_sbdsp_command(chip, SB_DSP_STEREO_8BIT);
  299. snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE);
  300. if (stereo) {
  301. snd_sbdsp_command(chip, 256 - runtime->rate_den / 2);
  302. spin_lock(&chip->mixer_lock);
  303. /* save input filter status and turn it off */
  304. mixreg = snd_sbmixer_read(chip, SB_DSP_CAPTURE_FILT);
  305. snd_sbmixer_write(chip, SB_DSP_CAPTURE_FILT, mixreg | 0x20);
  306. spin_unlock(&chip->mixer_lock);
  307. /* just use force_mode16 for temporary storate... */
  308. chip->force_mode16 = mixreg;
  309. } else {
  310. snd_sbdsp_command(chip, 256 - runtime->rate_den);
  311. }
  312. if (chip->capture_format != SB_DSP_INPUT) {
  313. if (chip->mode & SB_MODE_PLAYBACK_16)
  314. count /= 2;
  315. count--;
  316. snd_sbdsp_command(chip, SB_DSP_BLOCK_SIZE);
  317. snd_sbdsp_command(chip, count & 0xff);
  318. snd_sbdsp_command(chip, count >> 8);
  319. }
  320. spin_unlock_irqrestore(&chip->reg_lock, flags);
  321. snd_dma_program(dma, runtime->dma_addr,
  322. size, DMA_MODE_READ | DMA_AUTOINIT);
  323. return 0;
  324. }
  325. static int snd_sb8_capture_trigger(struct snd_pcm_substream *substream,
  326. int cmd)
  327. {
  328. unsigned long flags;
  329. struct snd_sb *chip = snd_pcm_substream_chip(substream);
  330. unsigned int count;
  331. spin_lock_irqsave(&chip->reg_lock, flags);
  332. switch (cmd) {
  333. case SNDRV_PCM_TRIGGER_START:
  334. snd_sbdsp_command(chip, chip->capture_format);
  335. if (chip->capture_format == SB_DSP_INPUT) {
  336. count = chip->c_period_size - 1;
  337. snd_sbdsp_command(chip, count & 0xff);
  338. snd_sbdsp_command(chip, count >> 8);
  339. }
  340. break;
  341. case SNDRV_PCM_TRIGGER_STOP:
  342. if (chip->capture_format == SB_DSP_HI_INPUT_AUTO) {
  343. struct snd_pcm_runtime *runtime = substream->runtime;
  344. snd_sbdsp_reset(chip);
  345. if (runtime->channels > 1) {
  346. /* restore input filter status */
  347. spin_lock(&chip->mixer_lock);
  348. snd_sbmixer_write(chip, SB_DSP_CAPTURE_FILT, chip->force_mode16);
  349. spin_unlock(&chip->mixer_lock);
  350. /* set hardware to mono mode */
  351. snd_sbdsp_command(chip, SB_DSP_MONO_8BIT);
  352. }
  353. } else {
  354. snd_sbdsp_command(chip, SB_DSP_DMA8_OFF);
  355. }
  356. snd_sbdsp_command(chip, SB_DSP_SPEAKER_OFF);
  357. }
  358. spin_unlock_irqrestore(&chip->reg_lock, flags);
  359. return 0;
  360. }
  361. irqreturn_t snd_sb8dsp_interrupt(struct snd_sb *chip)
  362. {
  363. struct snd_pcm_substream *substream;
  364. struct snd_pcm_runtime *runtime;
  365. snd_sb_ack_8bit(chip);
  366. switch (chip->mode) {
  367. case SB_MODE_PLAYBACK_16: /* ok.. playback is active */
  368. if (chip->hardware != SB_HW_JAZZ16)
  369. break;
  370. /* fallthru */
  371. case SB_MODE_PLAYBACK_8:
  372. substream = chip->playback_substream;
  373. runtime = substream->runtime;
  374. if (chip->playback_format == SB_DSP_OUTPUT)
  375. snd_sb8_playback_trigger(substream, SNDRV_PCM_TRIGGER_START);
  376. snd_pcm_period_elapsed(substream);
  377. break;
  378. case SB_MODE_CAPTURE_16:
  379. if (chip->hardware != SB_HW_JAZZ16)
  380. break;
  381. /* fallthru */
  382. case SB_MODE_CAPTURE_8:
  383. substream = chip->capture_substream;
  384. runtime = substream->runtime;
  385. if (chip->capture_format == SB_DSP_INPUT)
  386. snd_sb8_capture_trigger(substream, SNDRV_PCM_TRIGGER_START);
  387. snd_pcm_period_elapsed(substream);
  388. break;
  389. }
  390. return IRQ_HANDLED;
  391. }
  392. static snd_pcm_uframes_t snd_sb8_playback_pointer(struct snd_pcm_substream *substream)
  393. {
  394. struct snd_sb *chip = snd_pcm_substream_chip(substream);
  395. size_t ptr;
  396. int dma;
  397. if (chip->mode & SB_MODE_PLAYBACK_8)
  398. dma = chip->dma8;
  399. else if (chip->mode & SB_MODE_PLAYBACK_16)
  400. dma = chip->dma16;
  401. else
  402. return 0;
  403. ptr = snd_dma_pointer(dma, chip->p_dma_size);
  404. return bytes_to_frames(substream->runtime, ptr);
  405. }
  406. static snd_pcm_uframes_t snd_sb8_capture_pointer(struct snd_pcm_substream *substream)
  407. {
  408. struct snd_sb *chip = snd_pcm_substream_chip(substream);
  409. size_t ptr;
  410. int dma;
  411. if (chip->mode & SB_MODE_CAPTURE_8)
  412. dma = chip->dma8;
  413. else if (chip->mode & SB_MODE_CAPTURE_16)
  414. dma = chip->dma16;
  415. else
  416. return 0;
  417. ptr = snd_dma_pointer(dma, chip->c_dma_size);
  418. return bytes_to_frames(substream->runtime, ptr);
  419. }
  420. /*
  421. */
  422. static struct snd_pcm_hardware snd_sb8_playback =
  423. {
  424. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  425. SNDRV_PCM_INFO_MMAP_VALID),
  426. .formats = SNDRV_PCM_FMTBIT_U8,
  427. .rates = (SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000 |
  428. SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_22050),
  429. .rate_min = 4000,
  430. .rate_max = 23000,
  431. .channels_min = 1,
  432. .channels_max = 1,
  433. .buffer_bytes_max = 65536,
  434. .period_bytes_min = 64,
  435. .period_bytes_max = 65536,
  436. .periods_min = 1,
  437. .periods_max = 1024,
  438. .fifo_size = 0,
  439. };
  440. static struct snd_pcm_hardware snd_sb8_capture =
  441. {
  442. .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  443. SNDRV_PCM_INFO_MMAP_VALID),
  444. .formats = SNDRV_PCM_FMTBIT_U8,
  445. .rates = (SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000 |
  446. SNDRV_PCM_RATE_11025),
  447. .rate_min = 4000,
  448. .rate_max = 13000,
  449. .channels_min = 1,
  450. .channels_max = 1,
  451. .buffer_bytes_max = 65536,
  452. .period_bytes_min = 64,
  453. .period_bytes_max = 65536,
  454. .periods_min = 1,
  455. .periods_max = 1024,
  456. .fifo_size = 0,
  457. };
  458. /*
  459. *
  460. */
  461. static int snd_sb8_open(struct snd_pcm_substream *substream)
  462. {
  463. struct snd_sb *chip = snd_pcm_substream_chip(substream);
  464. struct snd_pcm_runtime *runtime = substream->runtime;
  465. unsigned long flags;
  466. spin_lock_irqsave(&chip->open_lock, flags);
  467. if (chip->open) {
  468. spin_unlock_irqrestore(&chip->open_lock, flags);
  469. return -EAGAIN;
  470. }
  471. chip->open |= SB_OPEN_PCM;
  472. spin_unlock_irqrestore(&chip->open_lock, flags);
  473. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  474. chip->playback_substream = substream;
  475. runtime->hw = snd_sb8_playback;
  476. } else {
  477. chip->capture_substream = substream;
  478. runtime->hw = snd_sb8_capture;
  479. }
  480. switch (chip->hardware) {
  481. case SB_HW_JAZZ16:
  482. if (chip->dma16 == 5 || chip->dma16 == 7)
  483. runtime->hw.formats |= SNDRV_PCM_FMTBIT_S16_LE;
  484. runtime->hw.rates |= SNDRV_PCM_RATE_8000_48000;
  485. runtime->hw.rate_min = 4000;
  486. runtime->hw.rate_max = 50000;
  487. runtime->hw.channels_max = 2;
  488. break;
  489. case SB_HW_PRO:
  490. runtime->hw.rate_max = 44100;
  491. runtime->hw.channels_max = 2;
  492. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  493. snd_sb8_hw_constraint_rate_channels, NULL,
  494. SNDRV_PCM_HW_PARAM_CHANNELS,
  495. SNDRV_PCM_HW_PARAM_RATE, -1);
  496. snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
  497. snd_sb8_hw_constraint_channels_rate, NULL,
  498. SNDRV_PCM_HW_PARAM_RATE, -1);
  499. break;
  500. case SB_HW_201:
  501. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  502. runtime->hw.rate_max = 44100;
  503. } else {
  504. runtime->hw.rate_max = 15000;
  505. }
  506. default:
  507. break;
  508. }
  509. snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  510. &hw_constraints_clock);
  511. if (chip->dma8 > 3 || chip->dma16 >= 0) {
  512. snd_pcm_hw_constraint_step(runtime, 0,
  513. SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 2);
  514. snd_pcm_hw_constraint_step(runtime, 0,
  515. SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 2);
  516. runtime->hw.buffer_bytes_max = 128 * 1024 * 1024;
  517. runtime->hw.period_bytes_max = 128 * 1024 * 1024;
  518. }
  519. return 0;
  520. }
  521. static int snd_sb8_close(struct snd_pcm_substream *substream)
  522. {
  523. unsigned long flags;
  524. struct snd_sb *chip = snd_pcm_substream_chip(substream);
  525. chip->playback_substream = NULL;
  526. chip->capture_substream = NULL;
  527. spin_lock_irqsave(&chip->open_lock, flags);
  528. chip->open &= ~SB_OPEN_PCM;
  529. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  530. chip->mode &= ~SB_MODE_PLAYBACK;
  531. else
  532. chip->mode &= ~SB_MODE_CAPTURE;
  533. spin_unlock_irqrestore(&chip->open_lock, flags);
  534. return 0;
  535. }
  536. /*
  537. * Initialization part
  538. */
  539. static struct snd_pcm_ops snd_sb8_playback_ops = {
  540. .open = snd_sb8_open,
  541. .close = snd_sb8_close,
  542. .ioctl = snd_pcm_lib_ioctl,
  543. .hw_params = snd_sb8_hw_params,
  544. .hw_free = snd_sb8_hw_free,
  545. .prepare = snd_sb8_playback_prepare,
  546. .trigger = snd_sb8_playback_trigger,
  547. .pointer = snd_sb8_playback_pointer,
  548. };
  549. static struct snd_pcm_ops snd_sb8_capture_ops = {
  550. .open = snd_sb8_open,
  551. .close = snd_sb8_close,
  552. .ioctl = snd_pcm_lib_ioctl,
  553. .hw_params = snd_sb8_hw_params,
  554. .hw_free = snd_sb8_hw_free,
  555. .prepare = snd_sb8_capture_prepare,
  556. .trigger = snd_sb8_capture_trigger,
  557. .pointer = snd_sb8_capture_pointer,
  558. };
  559. int snd_sb8dsp_pcm(struct snd_sb *chip, int device)
  560. {
  561. struct snd_card *card = chip->card;
  562. struct snd_pcm *pcm;
  563. int err;
  564. size_t max_prealloc = 64 * 1024;
  565. if ((err = snd_pcm_new(card, "SB8 DSP", device, 1, 1, &pcm)) < 0)
  566. return err;
  567. sprintf(pcm->name, "DSP v%i.%i", chip->version >> 8, chip->version & 0xff);
  568. pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
  569. pcm->private_data = chip;
  570. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sb8_playback_ops);
  571. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_sb8_capture_ops);
  572. if (chip->dma8 > 3 || chip->dma16 >= 0)
  573. max_prealloc = 128 * 1024;
  574. snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
  575. snd_dma_isa_data(),
  576. 64*1024, max_prealloc);
  577. return 0;
  578. }
  579. EXPORT_SYMBOL(snd_sb8dsp_pcm);
  580. EXPORT_SYMBOL(snd_sb8dsp_interrupt);
  581. /* sb8_midi.c */
  582. EXPORT_SYMBOL(snd_sb8dsp_midi_interrupt);
  583. EXPORT_SYMBOL(snd_sb8dsp_midi);
  584. /*
  585. * INIT part
  586. */
  587. static int __init alsa_sb8_init(void)
  588. {
  589. return 0;
  590. }
  591. static void __exit alsa_sb8_exit(void)
  592. {
  593. }
  594. module_init(alsa_sb8_init)
  595. module_exit(alsa_sb8_exit)