sb8_main.c 18 KB

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