xref: /kernel/linux/linux-5.10/sound/isa/sb/sb16_main.c (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
48c2ecf20Sopenharmony_ci *  Routines for control of 16-bit SoundBlaster cards and clones
58c2ecf20Sopenharmony_ci *  Note: This is very ugly hardware which uses one 8-bit DMA channel and
68c2ecf20Sopenharmony_ci *        second 16-bit DMA channel. Unfortunately 8-bit DMA channel can't
78c2ecf20Sopenharmony_ci *        transfer 16-bit samples and 16-bit DMA channels can't transfer
88c2ecf20Sopenharmony_ci *        8-bit samples. This make full duplex more complicated than
98c2ecf20Sopenharmony_ci *        can be... People, don't buy these soundcards for full 16-bit
108c2ecf20Sopenharmony_ci *        duplex!!!
118c2ecf20Sopenharmony_ci *  Note: 16-bit wide is assigned to first direction which made request.
128c2ecf20Sopenharmony_ci *        With full duplex - playback is preferred with abstract layer.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *  Note: Some chip revisions have hardware bug. Changing capture
158c2ecf20Sopenharmony_ci *        channel from full-duplex 8bit DMA to 16bit DMA will block
168c2ecf20Sopenharmony_ci *        16bit DMA transfers from DSP chip (capture) until 8bit transfer
178c2ecf20Sopenharmony_ci *        to DSP chip (playback) starts. This bug can be avoided with
188c2ecf20Sopenharmony_ci *        "16bit DMA Allocation" setting set to Playback or Capture.
198c2ecf20Sopenharmony_ci */
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <linux/io.h>
228c2ecf20Sopenharmony_ci#include <asm/dma.h>
238c2ecf20Sopenharmony_ci#include <linux/init.h>
248c2ecf20Sopenharmony_ci#include <linux/time.h>
258c2ecf20Sopenharmony_ci#include <linux/module.h>
268c2ecf20Sopenharmony_ci#include <sound/core.h>
278c2ecf20Sopenharmony_ci#include <sound/sb.h>
288c2ecf20Sopenharmony_ci#include <sound/sb16_csp.h>
298c2ecf20Sopenharmony_ci#include <sound/mpu401.h>
308c2ecf20Sopenharmony_ci#include <sound/control.h>
318c2ecf20Sopenharmony_ci#include <sound/info.h>
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciMODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
348c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Routines for control of 16-bit SoundBlaster cards and clones");
358c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#define runtime_format_bits(runtime) \
388c2ecf20Sopenharmony_ci	((unsigned int)pcm_format_to_bits((runtime)->format))
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_SB16_CSP
418c2ecf20Sopenharmony_cistatic void snd_sb16_csp_playback_prepare(struct snd_sb *chip, struct snd_pcm_runtime *runtime)
428c2ecf20Sopenharmony_ci{
438c2ecf20Sopenharmony_ci	if (chip->hardware == SB_HW_16CSP) {
448c2ecf20Sopenharmony_ci		struct snd_sb_csp *csp = chip->csp;
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci		if (csp->running & SNDRV_SB_CSP_ST_LOADED) {
478c2ecf20Sopenharmony_ci			/* manually loaded codec */
488c2ecf20Sopenharmony_ci			if ((csp->mode & SNDRV_SB_CSP_MODE_DSP_WRITE) &&
498c2ecf20Sopenharmony_ci			    (runtime_format_bits(runtime) == csp->acc_format)) {
508c2ecf20Sopenharmony_ci				/* Supported runtime PCM format for playback */
518c2ecf20Sopenharmony_ci				if (csp->ops.csp_use(csp) == 0) {
528c2ecf20Sopenharmony_ci					/* If CSP was successfully acquired */
538c2ecf20Sopenharmony_ci					goto __start_CSP;
548c2ecf20Sopenharmony_ci				}
558c2ecf20Sopenharmony_ci			} else if ((csp->mode & SNDRV_SB_CSP_MODE_QSOUND) && (csp->q_enabled)) {
568c2ecf20Sopenharmony_ci				/* QSound decoder is loaded and enabled */
578c2ecf20Sopenharmony_ci				if (runtime_format_bits(runtime) & (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
588c2ecf20Sopenharmony_ci							      SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE)) {
598c2ecf20Sopenharmony_ci					/* Only for simple PCM formats */
608c2ecf20Sopenharmony_ci					if (csp->ops.csp_use(csp) == 0) {
618c2ecf20Sopenharmony_ci						/* If CSP was successfully acquired */
628c2ecf20Sopenharmony_ci						goto __start_CSP;
638c2ecf20Sopenharmony_ci					}
648c2ecf20Sopenharmony_ci				}
658c2ecf20Sopenharmony_ci			}
668c2ecf20Sopenharmony_ci		} else if (csp->ops.csp_use(csp) == 0) {
678c2ecf20Sopenharmony_ci			/* Acquire CSP and try to autoload hardware codec */
688c2ecf20Sopenharmony_ci			if (csp->ops.csp_autoload(csp, runtime->format, SNDRV_SB_CSP_MODE_DSP_WRITE)) {
698c2ecf20Sopenharmony_ci				/* Unsupported format, release CSP */
708c2ecf20Sopenharmony_ci				csp->ops.csp_unuse(csp);
718c2ecf20Sopenharmony_ci			} else {
728c2ecf20Sopenharmony_ci		      __start_CSP:
738c2ecf20Sopenharmony_ci				/* Try to start CSP */
748c2ecf20Sopenharmony_ci				if (csp->ops.csp_start(csp, (chip->mode & SB_MODE_PLAYBACK_16) ?
758c2ecf20Sopenharmony_ci						       SNDRV_SB_CSP_SAMPLE_16BIT : SNDRV_SB_CSP_SAMPLE_8BIT,
768c2ecf20Sopenharmony_ci						       (runtime->channels > 1) ?
778c2ecf20Sopenharmony_ci						       SNDRV_SB_CSP_STEREO : SNDRV_SB_CSP_MONO)) {
788c2ecf20Sopenharmony_ci					/* Failed, release CSP */
798c2ecf20Sopenharmony_ci					csp->ops.csp_unuse(csp);
808c2ecf20Sopenharmony_ci				} else {
818c2ecf20Sopenharmony_ci					/* Success, CSP acquired and running */
828c2ecf20Sopenharmony_ci					chip->open = SNDRV_SB_CSP_MODE_DSP_WRITE;
838c2ecf20Sopenharmony_ci				}
848c2ecf20Sopenharmony_ci			}
858c2ecf20Sopenharmony_ci		}
868c2ecf20Sopenharmony_ci	}
878c2ecf20Sopenharmony_ci}
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cistatic void snd_sb16_csp_capture_prepare(struct snd_sb *chip, struct snd_pcm_runtime *runtime)
908c2ecf20Sopenharmony_ci{
918c2ecf20Sopenharmony_ci	if (chip->hardware == SB_HW_16CSP) {
928c2ecf20Sopenharmony_ci		struct snd_sb_csp *csp = chip->csp;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci		if (csp->running & SNDRV_SB_CSP_ST_LOADED) {
958c2ecf20Sopenharmony_ci			/* manually loaded codec */
968c2ecf20Sopenharmony_ci			if ((csp->mode & SNDRV_SB_CSP_MODE_DSP_READ) &&
978c2ecf20Sopenharmony_ci			    (runtime_format_bits(runtime) == csp->acc_format)) {
988c2ecf20Sopenharmony_ci				/* Supported runtime PCM format for capture */
998c2ecf20Sopenharmony_ci				if (csp->ops.csp_use(csp) == 0) {
1008c2ecf20Sopenharmony_ci					/* If CSP was successfully acquired */
1018c2ecf20Sopenharmony_ci					goto __start_CSP;
1028c2ecf20Sopenharmony_ci				}
1038c2ecf20Sopenharmony_ci			}
1048c2ecf20Sopenharmony_ci		} else if (csp->ops.csp_use(csp) == 0) {
1058c2ecf20Sopenharmony_ci			/* Acquire CSP and try to autoload hardware codec */
1068c2ecf20Sopenharmony_ci			if (csp->ops.csp_autoload(csp, runtime->format, SNDRV_SB_CSP_MODE_DSP_READ)) {
1078c2ecf20Sopenharmony_ci				/* Unsupported format, release CSP */
1088c2ecf20Sopenharmony_ci				csp->ops.csp_unuse(csp);
1098c2ecf20Sopenharmony_ci			} else {
1108c2ecf20Sopenharmony_ci		      __start_CSP:
1118c2ecf20Sopenharmony_ci				/* Try to start CSP */
1128c2ecf20Sopenharmony_ci				if (csp->ops.csp_start(csp, (chip->mode & SB_MODE_CAPTURE_16) ?
1138c2ecf20Sopenharmony_ci						       SNDRV_SB_CSP_SAMPLE_16BIT : SNDRV_SB_CSP_SAMPLE_8BIT,
1148c2ecf20Sopenharmony_ci						       (runtime->channels > 1) ?
1158c2ecf20Sopenharmony_ci						       SNDRV_SB_CSP_STEREO : SNDRV_SB_CSP_MONO)) {
1168c2ecf20Sopenharmony_ci					/* Failed, release CSP */
1178c2ecf20Sopenharmony_ci					csp->ops.csp_unuse(csp);
1188c2ecf20Sopenharmony_ci				} else {
1198c2ecf20Sopenharmony_ci					/* Success, CSP acquired and running */
1208c2ecf20Sopenharmony_ci					chip->open = SNDRV_SB_CSP_MODE_DSP_READ;
1218c2ecf20Sopenharmony_ci				}
1228c2ecf20Sopenharmony_ci			}
1238c2ecf20Sopenharmony_ci		}
1248c2ecf20Sopenharmony_ci	}
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic void snd_sb16_csp_update(struct snd_sb *chip)
1288c2ecf20Sopenharmony_ci{
1298c2ecf20Sopenharmony_ci	if (chip->hardware == SB_HW_16CSP) {
1308c2ecf20Sopenharmony_ci		struct snd_sb_csp *csp = chip->csp;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci		if (csp->qpos_changed) {
1338c2ecf20Sopenharmony_ci			spin_lock(&chip->reg_lock);
1348c2ecf20Sopenharmony_ci			csp->ops.csp_qsound_transfer (csp);
1358c2ecf20Sopenharmony_ci			spin_unlock(&chip->reg_lock);
1368c2ecf20Sopenharmony_ci		}
1378c2ecf20Sopenharmony_ci	}
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic void snd_sb16_csp_playback_open(struct snd_sb *chip, struct snd_pcm_runtime *runtime)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	/* CSP decoders (QSound excluded) support only 16bit transfers */
1438c2ecf20Sopenharmony_ci	if (chip->hardware == SB_HW_16CSP) {
1448c2ecf20Sopenharmony_ci		struct snd_sb_csp *csp = chip->csp;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci		if (csp->running & SNDRV_SB_CSP_ST_LOADED) {
1478c2ecf20Sopenharmony_ci			/* manually loaded codec */
1488c2ecf20Sopenharmony_ci			if (csp->mode & SNDRV_SB_CSP_MODE_DSP_WRITE) {
1498c2ecf20Sopenharmony_ci				runtime->hw.formats |= csp->acc_format;
1508c2ecf20Sopenharmony_ci			}
1518c2ecf20Sopenharmony_ci		} else {
1528c2ecf20Sopenharmony_ci			/* autoloaded codecs */
1538c2ecf20Sopenharmony_ci			runtime->hw.formats |= SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
1548c2ecf20Sopenharmony_ci					       SNDRV_PCM_FMTBIT_IMA_ADPCM;
1558c2ecf20Sopenharmony_ci		}
1568c2ecf20Sopenharmony_ci	}
1578c2ecf20Sopenharmony_ci}
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_cistatic void snd_sb16_csp_playback_close(struct snd_sb *chip)
1608c2ecf20Sopenharmony_ci{
1618c2ecf20Sopenharmony_ci	if ((chip->hardware == SB_HW_16CSP) && (chip->open == SNDRV_SB_CSP_MODE_DSP_WRITE)) {
1628c2ecf20Sopenharmony_ci		struct snd_sb_csp *csp = chip->csp;
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci		if (csp->ops.csp_stop(csp) == 0) {
1658c2ecf20Sopenharmony_ci			csp->ops.csp_unuse(csp);
1668c2ecf20Sopenharmony_ci			chip->open = 0;
1678c2ecf20Sopenharmony_ci		}
1688c2ecf20Sopenharmony_ci	}
1698c2ecf20Sopenharmony_ci}
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_cistatic void snd_sb16_csp_capture_open(struct snd_sb *chip, struct snd_pcm_runtime *runtime)
1728c2ecf20Sopenharmony_ci{
1738c2ecf20Sopenharmony_ci	/* CSP coders support only 16bit transfers */
1748c2ecf20Sopenharmony_ci	if (chip->hardware == SB_HW_16CSP) {
1758c2ecf20Sopenharmony_ci		struct snd_sb_csp *csp = chip->csp;
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci		if (csp->running & SNDRV_SB_CSP_ST_LOADED) {
1788c2ecf20Sopenharmony_ci			/* manually loaded codec */
1798c2ecf20Sopenharmony_ci			if (csp->mode & SNDRV_SB_CSP_MODE_DSP_READ) {
1808c2ecf20Sopenharmony_ci				runtime->hw.formats |= csp->acc_format;
1818c2ecf20Sopenharmony_ci			}
1828c2ecf20Sopenharmony_ci		} else {
1838c2ecf20Sopenharmony_ci			/* autoloaded codecs */
1848c2ecf20Sopenharmony_ci			runtime->hw.formats |= SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW |
1858c2ecf20Sopenharmony_ci					       SNDRV_PCM_FMTBIT_IMA_ADPCM;
1868c2ecf20Sopenharmony_ci		}
1878c2ecf20Sopenharmony_ci	}
1888c2ecf20Sopenharmony_ci}
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_cistatic void snd_sb16_csp_capture_close(struct snd_sb *chip)
1918c2ecf20Sopenharmony_ci{
1928c2ecf20Sopenharmony_ci	if ((chip->hardware == SB_HW_16CSP) && (chip->open == SNDRV_SB_CSP_MODE_DSP_READ)) {
1938c2ecf20Sopenharmony_ci		struct snd_sb_csp *csp = chip->csp;
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci		if (csp->ops.csp_stop(csp) == 0) {
1968c2ecf20Sopenharmony_ci			csp->ops.csp_unuse(csp);
1978c2ecf20Sopenharmony_ci			chip->open = 0;
1988c2ecf20Sopenharmony_ci		}
1998c2ecf20Sopenharmony_ci	}
2008c2ecf20Sopenharmony_ci}
2018c2ecf20Sopenharmony_ci#else
2028c2ecf20Sopenharmony_ci#define snd_sb16_csp_playback_prepare(chip, runtime)	/*nop*/
2038c2ecf20Sopenharmony_ci#define snd_sb16_csp_capture_prepare(chip, runtime)	/*nop*/
2048c2ecf20Sopenharmony_ci#define snd_sb16_csp_update(chip)			/*nop*/
2058c2ecf20Sopenharmony_ci#define snd_sb16_csp_playback_open(chip, runtime)	/*nop*/
2068c2ecf20Sopenharmony_ci#define snd_sb16_csp_playback_close(chip)		/*nop*/
2078c2ecf20Sopenharmony_ci#define snd_sb16_csp_capture_open(chip, runtime)	/*nop*/
2088c2ecf20Sopenharmony_ci#define snd_sb16_csp_capture_close(chip)      	 	/*nop*/
2098c2ecf20Sopenharmony_ci#endif
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_cistatic void snd_sb16_setup_rate(struct snd_sb *chip,
2138c2ecf20Sopenharmony_ci				unsigned short rate,
2148c2ecf20Sopenharmony_ci				int channel)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci	unsigned long flags;
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->reg_lock, flags);
2198c2ecf20Sopenharmony_ci	if (chip->mode & (channel == SNDRV_PCM_STREAM_PLAYBACK ? SB_MODE_PLAYBACK_16 : SB_MODE_CAPTURE_16))
2208c2ecf20Sopenharmony_ci		snd_sb_ack_16bit(chip);
2218c2ecf20Sopenharmony_ci	else
2228c2ecf20Sopenharmony_ci		snd_sb_ack_8bit(chip);
2238c2ecf20Sopenharmony_ci	if (!(chip->mode & SB_RATE_LOCK)) {
2248c2ecf20Sopenharmony_ci		chip->locked_rate = rate;
2258c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE_IN);
2268c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, rate >> 8);
2278c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, rate & 0xff);
2288c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE_OUT);
2298c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, rate >> 8);
2308c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, rate & 0xff);
2318c2ecf20Sopenharmony_ci	}
2328c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->reg_lock, flags);
2338c2ecf20Sopenharmony_ci}
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_cistatic int snd_sb16_playback_prepare(struct snd_pcm_substream *substream)
2368c2ecf20Sopenharmony_ci{
2378c2ecf20Sopenharmony_ci	unsigned long flags;
2388c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
2398c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
2408c2ecf20Sopenharmony_ci	unsigned char format;
2418c2ecf20Sopenharmony_ci	unsigned int size, count, dma;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	snd_sb16_csp_playback_prepare(chip, runtime);
2448c2ecf20Sopenharmony_ci	if (snd_pcm_format_unsigned(runtime->format) > 0) {
2458c2ecf20Sopenharmony_ci		format = runtime->channels > 1 ? SB_DSP4_MODE_UNS_STEREO : SB_DSP4_MODE_UNS_MONO;
2468c2ecf20Sopenharmony_ci	} else {
2478c2ecf20Sopenharmony_ci		format = runtime->channels > 1 ? SB_DSP4_MODE_SIGN_STEREO : SB_DSP4_MODE_SIGN_MONO;
2488c2ecf20Sopenharmony_ci	}
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci	snd_sb16_setup_rate(chip, runtime->rate, SNDRV_PCM_STREAM_PLAYBACK);
2518c2ecf20Sopenharmony_ci	size = chip->p_dma_size = snd_pcm_lib_buffer_bytes(substream);
2528c2ecf20Sopenharmony_ci	dma = (chip->mode & SB_MODE_PLAYBACK_8) ? chip->dma8 : chip->dma16;
2538c2ecf20Sopenharmony_ci	snd_dma_program(dma, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	count = snd_pcm_lib_period_bytes(substream);
2568c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->reg_lock, flags);
2578c2ecf20Sopenharmony_ci	if (chip->mode & SB_MODE_PLAYBACK_16) {
2588c2ecf20Sopenharmony_ci		count >>= 1;
2598c2ecf20Sopenharmony_ci		count--;
2608c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP4_OUT16_AI);
2618c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, format);
2628c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, count & 0xff);
2638c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, count >> 8);
2648c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP_DMA16_OFF);
2658c2ecf20Sopenharmony_ci	} else {
2668c2ecf20Sopenharmony_ci		count--;
2678c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP4_OUT8_AI);
2688c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, format);
2698c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, count & 0xff);
2708c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, count >> 8);
2718c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP_DMA8_OFF);
2728c2ecf20Sopenharmony_ci	}
2738c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->reg_lock, flags);
2748c2ecf20Sopenharmony_ci	return 0;
2758c2ecf20Sopenharmony_ci}
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_cistatic int snd_sb16_playback_trigger(struct snd_pcm_substream *substream,
2788c2ecf20Sopenharmony_ci				     int cmd)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
2818c2ecf20Sopenharmony_ci	int result = 0;
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	spin_lock(&chip->reg_lock);
2848c2ecf20Sopenharmony_ci	switch (cmd) {
2858c2ecf20Sopenharmony_ci	case SNDRV_PCM_TRIGGER_START:
2868c2ecf20Sopenharmony_ci	case SNDRV_PCM_TRIGGER_RESUME:
2878c2ecf20Sopenharmony_ci		chip->mode |= SB_RATE_LOCK_PLAYBACK;
2888c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, chip->mode & SB_MODE_PLAYBACK_16 ? SB_DSP_DMA16_ON : SB_DSP_DMA8_ON);
2898c2ecf20Sopenharmony_ci		break;
2908c2ecf20Sopenharmony_ci	case SNDRV_PCM_TRIGGER_STOP:
2918c2ecf20Sopenharmony_ci	case SNDRV_PCM_TRIGGER_SUSPEND:
2928c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, chip->mode & SB_MODE_PLAYBACK_16 ? SB_DSP_DMA16_OFF : SB_DSP_DMA8_OFF);
2938c2ecf20Sopenharmony_ci		/* next two lines are needed for some types of DSP4 (SB AWE 32 - 4.13) */
2948c2ecf20Sopenharmony_ci		if (chip->mode & SB_RATE_LOCK_CAPTURE)
2958c2ecf20Sopenharmony_ci			snd_sbdsp_command(chip, chip->mode & SB_MODE_CAPTURE_16 ? SB_DSP_DMA16_ON : SB_DSP_DMA8_ON);
2968c2ecf20Sopenharmony_ci		chip->mode &= ~SB_RATE_LOCK_PLAYBACK;
2978c2ecf20Sopenharmony_ci		break;
2988c2ecf20Sopenharmony_ci	default:
2998c2ecf20Sopenharmony_ci		result = -EINVAL;
3008c2ecf20Sopenharmony_ci	}
3018c2ecf20Sopenharmony_ci	spin_unlock(&chip->reg_lock);
3028c2ecf20Sopenharmony_ci	return result;
3038c2ecf20Sopenharmony_ci}
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_cistatic int snd_sb16_capture_prepare(struct snd_pcm_substream *substream)
3068c2ecf20Sopenharmony_ci{
3078c2ecf20Sopenharmony_ci	unsigned long flags;
3088c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
3098c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
3108c2ecf20Sopenharmony_ci	unsigned char format;
3118c2ecf20Sopenharmony_ci	unsigned int size, count, dma;
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	snd_sb16_csp_capture_prepare(chip, runtime);
3148c2ecf20Sopenharmony_ci	if (snd_pcm_format_unsigned(runtime->format) > 0) {
3158c2ecf20Sopenharmony_ci		format = runtime->channels > 1 ? SB_DSP4_MODE_UNS_STEREO : SB_DSP4_MODE_UNS_MONO;
3168c2ecf20Sopenharmony_ci	} else {
3178c2ecf20Sopenharmony_ci		format = runtime->channels > 1 ? SB_DSP4_MODE_SIGN_STEREO : SB_DSP4_MODE_SIGN_MONO;
3188c2ecf20Sopenharmony_ci	}
3198c2ecf20Sopenharmony_ci	snd_sb16_setup_rate(chip, runtime->rate, SNDRV_PCM_STREAM_CAPTURE);
3208c2ecf20Sopenharmony_ci	size = chip->c_dma_size = snd_pcm_lib_buffer_bytes(substream);
3218c2ecf20Sopenharmony_ci	dma = (chip->mode & SB_MODE_CAPTURE_8) ? chip->dma8 : chip->dma16;
3228c2ecf20Sopenharmony_ci	snd_dma_program(dma, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci	count = snd_pcm_lib_period_bytes(substream);
3258c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->reg_lock, flags);
3268c2ecf20Sopenharmony_ci	if (chip->mode & SB_MODE_CAPTURE_16) {
3278c2ecf20Sopenharmony_ci		count >>= 1;
3288c2ecf20Sopenharmony_ci		count--;
3298c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP4_IN16_AI);
3308c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, format);
3318c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, count & 0xff);
3328c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, count >> 8);
3338c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP_DMA16_OFF);
3348c2ecf20Sopenharmony_ci	} else {
3358c2ecf20Sopenharmony_ci		count--;
3368c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP4_IN8_AI);
3378c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, format);
3388c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, count & 0xff);
3398c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, count >> 8);
3408c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, SB_DSP_DMA8_OFF);
3418c2ecf20Sopenharmony_ci	}
3428c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->reg_lock, flags);
3438c2ecf20Sopenharmony_ci	return 0;
3448c2ecf20Sopenharmony_ci}
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_cistatic int snd_sb16_capture_trigger(struct snd_pcm_substream *substream,
3478c2ecf20Sopenharmony_ci				    int cmd)
3488c2ecf20Sopenharmony_ci{
3498c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
3508c2ecf20Sopenharmony_ci	int result = 0;
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	spin_lock(&chip->reg_lock);
3538c2ecf20Sopenharmony_ci	switch (cmd) {
3548c2ecf20Sopenharmony_ci	case SNDRV_PCM_TRIGGER_START:
3558c2ecf20Sopenharmony_ci	case SNDRV_PCM_TRIGGER_RESUME:
3568c2ecf20Sopenharmony_ci		chip->mode |= SB_RATE_LOCK_CAPTURE;
3578c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, chip->mode & SB_MODE_CAPTURE_16 ? SB_DSP_DMA16_ON : SB_DSP_DMA8_ON);
3588c2ecf20Sopenharmony_ci		break;
3598c2ecf20Sopenharmony_ci	case SNDRV_PCM_TRIGGER_STOP:
3608c2ecf20Sopenharmony_ci	case SNDRV_PCM_TRIGGER_SUSPEND:
3618c2ecf20Sopenharmony_ci		snd_sbdsp_command(chip, chip->mode & SB_MODE_CAPTURE_16 ? SB_DSP_DMA16_OFF : SB_DSP_DMA8_OFF);
3628c2ecf20Sopenharmony_ci		/* next two lines are needed for some types of DSP4 (SB AWE 32 - 4.13) */
3638c2ecf20Sopenharmony_ci		if (chip->mode & SB_RATE_LOCK_PLAYBACK)
3648c2ecf20Sopenharmony_ci			snd_sbdsp_command(chip, chip->mode & SB_MODE_PLAYBACK_16 ? SB_DSP_DMA16_ON : SB_DSP_DMA8_ON);
3658c2ecf20Sopenharmony_ci		chip->mode &= ~SB_RATE_LOCK_CAPTURE;
3668c2ecf20Sopenharmony_ci		break;
3678c2ecf20Sopenharmony_ci	default:
3688c2ecf20Sopenharmony_ci		result = -EINVAL;
3698c2ecf20Sopenharmony_ci	}
3708c2ecf20Sopenharmony_ci	spin_unlock(&chip->reg_lock);
3718c2ecf20Sopenharmony_ci	return result;
3728c2ecf20Sopenharmony_ci}
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ciirqreturn_t snd_sb16dsp_interrupt(int irq, void *dev_id)
3758c2ecf20Sopenharmony_ci{
3768c2ecf20Sopenharmony_ci	struct snd_sb *chip = dev_id;
3778c2ecf20Sopenharmony_ci	unsigned char status;
3788c2ecf20Sopenharmony_ci	int ok;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	spin_lock(&chip->mixer_lock);
3818c2ecf20Sopenharmony_ci	status = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS);
3828c2ecf20Sopenharmony_ci	spin_unlock(&chip->mixer_lock);
3838c2ecf20Sopenharmony_ci	if ((status & SB_IRQTYPE_MPUIN) && chip->rmidi_callback)
3848c2ecf20Sopenharmony_ci		chip->rmidi_callback(irq, chip->rmidi->private_data);
3858c2ecf20Sopenharmony_ci	if (status & SB_IRQTYPE_8BIT) {
3868c2ecf20Sopenharmony_ci		ok = 0;
3878c2ecf20Sopenharmony_ci		if (chip->mode & SB_MODE_PLAYBACK_8) {
3888c2ecf20Sopenharmony_ci			snd_pcm_period_elapsed(chip->playback_substream);
3898c2ecf20Sopenharmony_ci			snd_sb16_csp_update(chip);
3908c2ecf20Sopenharmony_ci			ok++;
3918c2ecf20Sopenharmony_ci		}
3928c2ecf20Sopenharmony_ci		if (chip->mode & SB_MODE_CAPTURE_8) {
3938c2ecf20Sopenharmony_ci			snd_pcm_period_elapsed(chip->capture_substream);
3948c2ecf20Sopenharmony_ci			ok++;
3958c2ecf20Sopenharmony_ci		}
3968c2ecf20Sopenharmony_ci		spin_lock(&chip->reg_lock);
3978c2ecf20Sopenharmony_ci		if (!ok)
3988c2ecf20Sopenharmony_ci			snd_sbdsp_command(chip, SB_DSP_DMA8_OFF);
3998c2ecf20Sopenharmony_ci		snd_sb_ack_8bit(chip);
4008c2ecf20Sopenharmony_ci		spin_unlock(&chip->reg_lock);
4018c2ecf20Sopenharmony_ci	}
4028c2ecf20Sopenharmony_ci	if (status & SB_IRQTYPE_16BIT) {
4038c2ecf20Sopenharmony_ci		ok = 0;
4048c2ecf20Sopenharmony_ci		if (chip->mode & SB_MODE_PLAYBACK_16) {
4058c2ecf20Sopenharmony_ci			snd_pcm_period_elapsed(chip->playback_substream);
4068c2ecf20Sopenharmony_ci			snd_sb16_csp_update(chip);
4078c2ecf20Sopenharmony_ci			ok++;
4088c2ecf20Sopenharmony_ci		}
4098c2ecf20Sopenharmony_ci		if (chip->mode & SB_MODE_CAPTURE_16) {
4108c2ecf20Sopenharmony_ci			snd_pcm_period_elapsed(chip->capture_substream);
4118c2ecf20Sopenharmony_ci			ok++;
4128c2ecf20Sopenharmony_ci		}
4138c2ecf20Sopenharmony_ci		spin_lock(&chip->reg_lock);
4148c2ecf20Sopenharmony_ci		if (!ok)
4158c2ecf20Sopenharmony_ci			snd_sbdsp_command(chip, SB_DSP_DMA16_OFF);
4168c2ecf20Sopenharmony_ci		snd_sb_ack_16bit(chip);
4178c2ecf20Sopenharmony_ci		spin_unlock(&chip->reg_lock);
4188c2ecf20Sopenharmony_ci	}
4198c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
4208c2ecf20Sopenharmony_ci}
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci/*
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci */
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_cistatic snd_pcm_uframes_t snd_sb16_playback_pointer(struct snd_pcm_substream *substream)
4278c2ecf20Sopenharmony_ci{
4288c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
4298c2ecf20Sopenharmony_ci	unsigned int dma;
4308c2ecf20Sopenharmony_ci	size_t ptr;
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci	dma = (chip->mode & SB_MODE_PLAYBACK_8) ? chip->dma8 : chip->dma16;
4338c2ecf20Sopenharmony_ci	ptr = snd_dma_pointer(dma, chip->p_dma_size);
4348c2ecf20Sopenharmony_ci	return bytes_to_frames(substream->runtime, ptr);
4358c2ecf20Sopenharmony_ci}
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_cistatic snd_pcm_uframes_t snd_sb16_capture_pointer(struct snd_pcm_substream *substream)
4388c2ecf20Sopenharmony_ci{
4398c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
4408c2ecf20Sopenharmony_ci	unsigned int dma;
4418c2ecf20Sopenharmony_ci	size_t ptr;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	dma = (chip->mode & SB_MODE_CAPTURE_8) ? chip->dma8 : chip->dma16;
4448c2ecf20Sopenharmony_ci	ptr = snd_dma_pointer(dma, chip->c_dma_size);
4458c2ecf20Sopenharmony_ci	return bytes_to_frames(substream->runtime, ptr);
4468c2ecf20Sopenharmony_ci}
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci/*
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci */
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_cistatic const struct snd_pcm_hardware snd_sb16_playback =
4538c2ecf20Sopenharmony_ci{
4548c2ecf20Sopenharmony_ci	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
4558c2ecf20Sopenharmony_ci				 SNDRV_PCM_INFO_MMAP_VALID),
4568c2ecf20Sopenharmony_ci	.formats =		0,
4578c2ecf20Sopenharmony_ci	.rates =		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_44100,
4588c2ecf20Sopenharmony_ci	.rate_min =		4000,
4598c2ecf20Sopenharmony_ci	.rate_max =		44100,
4608c2ecf20Sopenharmony_ci	.channels_min =		1,
4618c2ecf20Sopenharmony_ci	.channels_max =		2,
4628c2ecf20Sopenharmony_ci	.buffer_bytes_max =	(128*1024),
4638c2ecf20Sopenharmony_ci	.period_bytes_min =	64,
4648c2ecf20Sopenharmony_ci	.period_bytes_max =	(128*1024),
4658c2ecf20Sopenharmony_ci	.periods_min =		1,
4668c2ecf20Sopenharmony_ci	.periods_max =		1024,
4678c2ecf20Sopenharmony_ci	.fifo_size =		0,
4688c2ecf20Sopenharmony_ci};
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_cistatic const struct snd_pcm_hardware snd_sb16_capture =
4718c2ecf20Sopenharmony_ci{
4728c2ecf20Sopenharmony_ci	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
4738c2ecf20Sopenharmony_ci				 SNDRV_PCM_INFO_MMAP_VALID),
4748c2ecf20Sopenharmony_ci	.formats =		0,
4758c2ecf20Sopenharmony_ci	.rates =		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_44100,
4768c2ecf20Sopenharmony_ci	.rate_min =		4000,
4778c2ecf20Sopenharmony_ci	.rate_max =		44100,
4788c2ecf20Sopenharmony_ci	.channels_min =		1,
4798c2ecf20Sopenharmony_ci	.channels_max =		2,
4808c2ecf20Sopenharmony_ci	.buffer_bytes_max =	(128*1024),
4818c2ecf20Sopenharmony_ci	.period_bytes_min =	64,
4828c2ecf20Sopenharmony_ci	.period_bytes_max =	(128*1024),
4838c2ecf20Sopenharmony_ci	.periods_min =		1,
4848c2ecf20Sopenharmony_ci	.periods_max =		1024,
4858c2ecf20Sopenharmony_ci	.fifo_size =		0,
4868c2ecf20Sopenharmony_ci};
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci/*
4898c2ecf20Sopenharmony_ci *  open/close
4908c2ecf20Sopenharmony_ci */
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_cistatic int snd_sb16_playback_open(struct snd_pcm_substream *substream)
4938c2ecf20Sopenharmony_ci{
4948c2ecf20Sopenharmony_ci	unsigned long flags;
4958c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
4968c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->open_lock, flags);
4998c2ecf20Sopenharmony_ci	if (chip->mode & SB_MODE_PLAYBACK) {
5008c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&chip->open_lock, flags);
5018c2ecf20Sopenharmony_ci		return -EAGAIN;
5028c2ecf20Sopenharmony_ci	}
5038c2ecf20Sopenharmony_ci	runtime->hw = snd_sb16_playback;
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci	/* skip if 16 bit DMA was reserved for capture */
5068c2ecf20Sopenharmony_ci	if (chip->force_mode16 & SB_MODE_CAPTURE_16)
5078c2ecf20Sopenharmony_ci		goto __skip_16bit;
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	if (chip->dma16 >= 0 && !(chip->mode & SB_MODE_CAPTURE_16)) {
5108c2ecf20Sopenharmony_ci		chip->mode |= SB_MODE_PLAYBACK_16;
5118c2ecf20Sopenharmony_ci		runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE;
5128c2ecf20Sopenharmony_ci		/* Vibra16X hack */
5138c2ecf20Sopenharmony_ci		if (chip->dma16 <= 3) {
5148c2ecf20Sopenharmony_ci			runtime->hw.buffer_bytes_max =
5158c2ecf20Sopenharmony_ci			runtime->hw.period_bytes_max = 64 * 1024;
5168c2ecf20Sopenharmony_ci		} else {
5178c2ecf20Sopenharmony_ci			snd_sb16_csp_playback_open(chip, runtime);
5188c2ecf20Sopenharmony_ci		}
5198c2ecf20Sopenharmony_ci		goto __open_ok;
5208c2ecf20Sopenharmony_ci	}
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci      __skip_16bit:
5238c2ecf20Sopenharmony_ci	if (chip->dma8 >= 0 && !(chip->mode & SB_MODE_CAPTURE_8)) {
5248c2ecf20Sopenharmony_ci		chip->mode |= SB_MODE_PLAYBACK_8;
5258c2ecf20Sopenharmony_ci		/* DSP v 4.xx can transfer 16bit data through 8bit DMA channel, SBHWPG 2-7 */
5268c2ecf20Sopenharmony_ci		if (chip->dma16 < 0) {
5278c2ecf20Sopenharmony_ci			runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE;
5288c2ecf20Sopenharmony_ci			chip->mode |= SB_MODE_PLAYBACK_16;
5298c2ecf20Sopenharmony_ci		} else {
5308c2ecf20Sopenharmony_ci			runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8;
5318c2ecf20Sopenharmony_ci		}
5328c2ecf20Sopenharmony_ci		runtime->hw.buffer_bytes_max =
5338c2ecf20Sopenharmony_ci		runtime->hw.period_bytes_max = 64 * 1024;
5348c2ecf20Sopenharmony_ci		goto __open_ok;
5358c2ecf20Sopenharmony_ci	}
5368c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->open_lock, flags);
5378c2ecf20Sopenharmony_ci	return -EAGAIN;
5388c2ecf20Sopenharmony_ci
5398c2ecf20Sopenharmony_ci      __open_ok:
5408c2ecf20Sopenharmony_ci	if (chip->hardware == SB_HW_ALS100)
5418c2ecf20Sopenharmony_ci		runtime->hw.rate_max = 48000;
5428c2ecf20Sopenharmony_ci	if (chip->hardware == SB_HW_CS5530) {
5438c2ecf20Sopenharmony_ci		runtime->hw.buffer_bytes_max = 32 * 1024;
5448c2ecf20Sopenharmony_ci		runtime->hw.periods_min = 2;
5458c2ecf20Sopenharmony_ci		runtime->hw.rate_min = 44100;
5468c2ecf20Sopenharmony_ci	}
5478c2ecf20Sopenharmony_ci	if (chip->mode & SB_RATE_LOCK)
5488c2ecf20Sopenharmony_ci		runtime->hw.rate_min = runtime->hw.rate_max = chip->locked_rate;
5498c2ecf20Sopenharmony_ci	chip->playback_substream = substream;
5508c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->open_lock, flags);
5518c2ecf20Sopenharmony_ci	return 0;
5528c2ecf20Sopenharmony_ci}
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_cistatic int snd_sb16_playback_close(struct snd_pcm_substream *substream)
5558c2ecf20Sopenharmony_ci{
5568c2ecf20Sopenharmony_ci	unsigned long flags;
5578c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci	snd_sb16_csp_playback_close(chip);
5608c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->open_lock, flags);
5618c2ecf20Sopenharmony_ci	chip->playback_substream = NULL;
5628c2ecf20Sopenharmony_ci	chip->mode &= ~SB_MODE_PLAYBACK;
5638c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->open_lock, flags);
5648c2ecf20Sopenharmony_ci	return 0;
5658c2ecf20Sopenharmony_ci}
5668c2ecf20Sopenharmony_ci
5678c2ecf20Sopenharmony_cistatic int snd_sb16_capture_open(struct snd_pcm_substream *substream)
5688c2ecf20Sopenharmony_ci{
5698c2ecf20Sopenharmony_ci	unsigned long flags;
5708c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
5718c2ecf20Sopenharmony_ci	struct snd_pcm_runtime *runtime = substream->runtime;
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->open_lock, flags);
5748c2ecf20Sopenharmony_ci	if (chip->mode & SB_MODE_CAPTURE) {
5758c2ecf20Sopenharmony_ci		spin_unlock_irqrestore(&chip->open_lock, flags);
5768c2ecf20Sopenharmony_ci		return -EAGAIN;
5778c2ecf20Sopenharmony_ci	}
5788c2ecf20Sopenharmony_ci	runtime->hw = snd_sb16_capture;
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci	/* skip if 16 bit DMA was reserved for playback */
5818c2ecf20Sopenharmony_ci	if (chip->force_mode16 & SB_MODE_PLAYBACK_16)
5828c2ecf20Sopenharmony_ci		goto __skip_16bit;
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ci	if (chip->dma16 >= 0 && !(chip->mode & SB_MODE_PLAYBACK_16)) {
5858c2ecf20Sopenharmony_ci		chip->mode |= SB_MODE_CAPTURE_16;
5868c2ecf20Sopenharmony_ci		runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE;
5878c2ecf20Sopenharmony_ci		/* Vibra16X hack */
5888c2ecf20Sopenharmony_ci		if (chip->dma16 <= 3) {
5898c2ecf20Sopenharmony_ci			runtime->hw.buffer_bytes_max =
5908c2ecf20Sopenharmony_ci			runtime->hw.period_bytes_max = 64 * 1024;
5918c2ecf20Sopenharmony_ci		} else {
5928c2ecf20Sopenharmony_ci			snd_sb16_csp_capture_open(chip, runtime);
5938c2ecf20Sopenharmony_ci		}
5948c2ecf20Sopenharmony_ci		goto __open_ok;
5958c2ecf20Sopenharmony_ci	}
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ci      __skip_16bit:
5988c2ecf20Sopenharmony_ci	if (chip->dma8 >= 0 && !(chip->mode & SB_MODE_PLAYBACK_8)) {
5998c2ecf20Sopenharmony_ci		chip->mode |= SB_MODE_CAPTURE_8;
6008c2ecf20Sopenharmony_ci		/* DSP v 4.xx can transfer 16bit data through 8bit DMA channel, SBHWPG 2-7 */
6018c2ecf20Sopenharmony_ci		if (chip->dma16 < 0) {
6028c2ecf20Sopenharmony_ci			runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE;
6038c2ecf20Sopenharmony_ci			chip->mode |= SB_MODE_CAPTURE_16;
6048c2ecf20Sopenharmony_ci		} else {
6058c2ecf20Sopenharmony_ci			runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8;
6068c2ecf20Sopenharmony_ci		}
6078c2ecf20Sopenharmony_ci		runtime->hw.buffer_bytes_max =
6088c2ecf20Sopenharmony_ci		runtime->hw.period_bytes_max = 64 * 1024;
6098c2ecf20Sopenharmony_ci		goto __open_ok;
6108c2ecf20Sopenharmony_ci	}
6118c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->open_lock, flags);
6128c2ecf20Sopenharmony_ci	return -EAGAIN;
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci      __open_ok:
6158c2ecf20Sopenharmony_ci	if (chip->hardware == SB_HW_ALS100)
6168c2ecf20Sopenharmony_ci		runtime->hw.rate_max = 48000;
6178c2ecf20Sopenharmony_ci	if (chip->hardware == SB_HW_CS5530) {
6188c2ecf20Sopenharmony_ci		runtime->hw.buffer_bytes_max = 32 * 1024;
6198c2ecf20Sopenharmony_ci		runtime->hw.periods_min = 2;
6208c2ecf20Sopenharmony_ci		runtime->hw.rate_min = 44100;
6218c2ecf20Sopenharmony_ci	}
6228c2ecf20Sopenharmony_ci	if (chip->mode & SB_RATE_LOCK)
6238c2ecf20Sopenharmony_ci		runtime->hw.rate_min = runtime->hw.rate_max = chip->locked_rate;
6248c2ecf20Sopenharmony_ci	chip->capture_substream = substream;
6258c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->open_lock, flags);
6268c2ecf20Sopenharmony_ci	return 0;
6278c2ecf20Sopenharmony_ci}
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_cistatic int snd_sb16_capture_close(struct snd_pcm_substream *substream)
6308c2ecf20Sopenharmony_ci{
6318c2ecf20Sopenharmony_ci	unsigned long flags;
6328c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_pcm_substream_chip(substream);
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci	snd_sb16_csp_capture_close(chip);
6358c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->open_lock, flags);
6368c2ecf20Sopenharmony_ci	chip->capture_substream = NULL;
6378c2ecf20Sopenharmony_ci	chip->mode &= ~SB_MODE_CAPTURE;
6388c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->open_lock, flags);
6398c2ecf20Sopenharmony_ci	return 0;
6408c2ecf20Sopenharmony_ci}
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci/*
6438c2ecf20Sopenharmony_ci *  DMA control interface
6448c2ecf20Sopenharmony_ci */
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_cistatic int snd_sb16_set_dma_mode(struct snd_sb *chip, int what)
6478c2ecf20Sopenharmony_ci{
6488c2ecf20Sopenharmony_ci	if (chip->dma8 < 0 || chip->dma16 < 0) {
6498c2ecf20Sopenharmony_ci		if (snd_BUG_ON(what))
6508c2ecf20Sopenharmony_ci			return -EINVAL;
6518c2ecf20Sopenharmony_ci		return 0;
6528c2ecf20Sopenharmony_ci	}
6538c2ecf20Sopenharmony_ci	if (what == 0) {
6548c2ecf20Sopenharmony_ci		chip->force_mode16 = 0;
6558c2ecf20Sopenharmony_ci	} else if (what == 1) {
6568c2ecf20Sopenharmony_ci		chip->force_mode16 = SB_MODE_PLAYBACK_16;
6578c2ecf20Sopenharmony_ci	} else if (what == 2) {
6588c2ecf20Sopenharmony_ci		chip->force_mode16 = SB_MODE_CAPTURE_16;
6598c2ecf20Sopenharmony_ci	} else {
6608c2ecf20Sopenharmony_ci		return -EINVAL;
6618c2ecf20Sopenharmony_ci	}
6628c2ecf20Sopenharmony_ci	return 0;
6638c2ecf20Sopenharmony_ci}
6648c2ecf20Sopenharmony_ci
6658c2ecf20Sopenharmony_cistatic int snd_sb16_get_dma_mode(struct snd_sb *chip)
6668c2ecf20Sopenharmony_ci{
6678c2ecf20Sopenharmony_ci	if (chip->dma8 < 0 || chip->dma16 < 0)
6688c2ecf20Sopenharmony_ci		return 0;
6698c2ecf20Sopenharmony_ci	switch (chip->force_mode16) {
6708c2ecf20Sopenharmony_ci	case SB_MODE_PLAYBACK_16:
6718c2ecf20Sopenharmony_ci		return 1;
6728c2ecf20Sopenharmony_ci	case SB_MODE_CAPTURE_16:
6738c2ecf20Sopenharmony_ci		return 2;
6748c2ecf20Sopenharmony_ci	default:
6758c2ecf20Sopenharmony_ci		return 0;
6768c2ecf20Sopenharmony_ci	}
6778c2ecf20Sopenharmony_ci}
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_cistatic int snd_sb16_dma_control_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
6808c2ecf20Sopenharmony_ci{
6818c2ecf20Sopenharmony_ci	static const char * const texts[3] = {
6828c2ecf20Sopenharmony_ci		"Auto", "Playback", "Capture"
6838c2ecf20Sopenharmony_ci	};
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci	return snd_ctl_enum_info(uinfo, 1, 3, texts);
6868c2ecf20Sopenharmony_ci}
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_cistatic int snd_sb16_dma_control_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
6898c2ecf20Sopenharmony_ci{
6908c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_kcontrol_chip(kcontrol);
6918c2ecf20Sopenharmony_ci	unsigned long flags;
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->reg_lock, flags);
6948c2ecf20Sopenharmony_ci	ucontrol->value.enumerated.item[0] = snd_sb16_get_dma_mode(chip);
6958c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->reg_lock, flags);
6968c2ecf20Sopenharmony_ci	return 0;
6978c2ecf20Sopenharmony_ci}
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_cistatic int snd_sb16_dma_control_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
7008c2ecf20Sopenharmony_ci{
7018c2ecf20Sopenharmony_ci	struct snd_sb *chip = snd_kcontrol_chip(kcontrol);
7028c2ecf20Sopenharmony_ci	unsigned long flags;
7038c2ecf20Sopenharmony_ci	unsigned char nval, oval;
7048c2ecf20Sopenharmony_ci	int change;
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_ci	if ((nval = ucontrol->value.enumerated.item[0]) > 2)
7078c2ecf20Sopenharmony_ci		return -EINVAL;
7088c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->reg_lock, flags);
7098c2ecf20Sopenharmony_ci	oval = snd_sb16_get_dma_mode(chip);
7108c2ecf20Sopenharmony_ci	change = nval != oval;
7118c2ecf20Sopenharmony_ci	snd_sb16_set_dma_mode(chip, nval);
7128c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->reg_lock, flags);
7138c2ecf20Sopenharmony_ci	return change;
7148c2ecf20Sopenharmony_ci}
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new snd_sb16_dma_control = {
7178c2ecf20Sopenharmony_ci	.iface = SNDRV_CTL_ELEM_IFACE_CARD,
7188c2ecf20Sopenharmony_ci	.name = "16-bit DMA Allocation",
7198c2ecf20Sopenharmony_ci	.info = snd_sb16_dma_control_info,
7208c2ecf20Sopenharmony_ci	.get = snd_sb16_dma_control_get,
7218c2ecf20Sopenharmony_ci	.put = snd_sb16_dma_control_put
7228c2ecf20Sopenharmony_ci};
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci/*
7258c2ecf20Sopenharmony_ci *  Initialization part
7268c2ecf20Sopenharmony_ci */
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ciint snd_sb16dsp_configure(struct snd_sb * chip)
7298c2ecf20Sopenharmony_ci{
7308c2ecf20Sopenharmony_ci	unsigned long flags;
7318c2ecf20Sopenharmony_ci	unsigned char irqreg = 0, dmareg = 0, mpureg;
7328c2ecf20Sopenharmony_ci	unsigned char realirq, realdma, realmpureg;
7338c2ecf20Sopenharmony_ci	/* note: mpu register should be present only on SB16 Vibra soundcards */
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci	// printk(KERN_DEBUG "codec->irq=%i, codec->dma8=%i, codec->dma16=%i\n", chip->irq, chip->dma8, chip->dma16);
7368c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->mixer_lock, flags);
7378c2ecf20Sopenharmony_ci	mpureg = snd_sbmixer_read(chip, SB_DSP4_MPUSETUP) & ~0x06;
7388c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->mixer_lock, flags);
7398c2ecf20Sopenharmony_ci	switch (chip->irq) {
7408c2ecf20Sopenharmony_ci	case 2:
7418c2ecf20Sopenharmony_ci	case 9:
7428c2ecf20Sopenharmony_ci		irqreg |= SB_IRQSETUP_IRQ9;
7438c2ecf20Sopenharmony_ci		break;
7448c2ecf20Sopenharmony_ci	case 5:
7458c2ecf20Sopenharmony_ci		irqreg |= SB_IRQSETUP_IRQ5;
7468c2ecf20Sopenharmony_ci		break;
7478c2ecf20Sopenharmony_ci	case 7:
7488c2ecf20Sopenharmony_ci		irqreg |= SB_IRQSETUP_IRQ7;
7498c2ecf20Sopenharmony_ci		break;
7508c2ecf20Sopenharmony_ci	case 10:
7518c2ecf20Sopenharmony_ci		irqreg |= SB_IRQSETUP_IRQ10;
7528c2ecf20Sopenharmony_ci		break;
7538c2ecf20Sopenharmony_ci	default:
7548c2ecf20Sopenharmony_ci		return -EINVAL;
7558c2ecf20Sopenharmony_ci	}
7568c2ecf20Sopenharmony_ci	if (chip->dma8 >= 0) {
7578c2ecf20Sopenharmony_ci		switch (chip->dma8) {
7588c2ecf20Sopenharmony_ci		case 0:
7598c2ecf20Sopenharmony_ci			dmareg |= SB_DMASETUP_DMA0;
7608c2ecf20Sopenharmony_ci			break;
7618c2ecf20Sopenharmony_ci		case 1:
7628c2ecf20Sopenharmony_ci			dmareg |= SB_DMASETUP_DMA1;
7638c2ecf20Sopenharmony_ci			break;
7648c2ecf20Sopenharmony_ci		case 3:
7658c2ecf20Sopenharmony_ci			dmareg |= SB_DMASETUP_DMA3;
7668c2ecf20Sopenharmony_ci			break;
7678c2ecf20Sopenharmony_ci		default:
7688c2ecf20Sopenharmony_ci			return -EINVAL;
7698c2ecf20Sopenharmony_ci		}
7708c2ecf20Sopenharmony_ci	}
7718c2ecf20Sopenharmony_ci	if (chip->dma16 >= 0 && chip->dma16 != chip->dma8) {
7728c2ecf20Sopenharmony_ci		switch (chip->dma16) {
7738c2ecf20Sopenharmony_ci		case 5:
7748c2ecf20Sopenharmony_ci			dmareg |= SB_DMASETUP_DMA5;
7758c2ecf20Sopenharmony_ci			break;
7768c2ecf20Sopenharmony_ci		case 6:
7778c2ecf20Sopenharmony_ci			dmareg |= SB_DMASETUP_DMA6;
7788c2ecf20Sopenharmony_ci			break;
7798c2ecf20Sopenharmony_ci		case 7:
7808c2ecf20Sopenharmony_ci			dmareg |= SB_DMASETUP_DMA7;
7818c2ecf20Sopenharmony_ci			break;
7828c2ecf20Sopenharmony_ci		default:
7838c2ecf20Sopenharmony_ci			return -EINVAL;
7848c2ecf20Sopenharmony_ci		}
7858c2ecf20Sopenharmony_ci	}
7868c2ecf20Sopenharmony_ci	switch (chip->mpu_port) {
7878c2ecf20Sopenharmony_ci	case 0x300:
7888c2ecf20Sopenharmony_ci		mpureg |= 0x04;
7898c2ecf20Sopenharmony_ci		break;
7908c2ecf20Sopenharmony_ci	case 0x330:
7918c2ecf20Sopenharmony_ci		mpureg |= 0x00;
7928c2ecf20Sopenharmony_ci		break;
7938c2ecf20Sopenharmony_ci	default:
7948c2ecf20Sopenharmony_ci		mpureg |= 0x02;	/* disable MPU */
7958c2ecf20Sopenharmony_ci	}
7968c2ecf20Sopenharmony_ci	spin_lock_irqsave(&chip->mixer_lock, flags);
7978c2ecf20Sopenharmony_ci
7988c2ecf20Sopenharmony_ci	snd_sbmixer_write(chip, SB_DSP4_IRQSETUP, irqreg);
7998c2ecf20Sopenharmony_ci	realirq = snd_sbmixer_read(chip, SB_DSP4_IRQSETUP);
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_ci	snd_sbmixer_write(chip, SB_DSP4_DMASETUP, dmareg);
8028c2ecf20Sopenharmony_ci	realdma = snd_sbmixer_read(chip, SB_DSP4_DMASETUP);
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci	snd_sbmixer_write(chip, SB_DSP4_MPUSETUP, mpureg);
8058c2ecf20Sopenharmony_ci	realmpureg = snd_sbmixer_read(chip, SB_DSP4_MPUSETUP);
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&chip->mixer_lock, flags);
8088c2ecf20Sopenharmony_ci	if ((~realirq) & irqreg || (~realdma) & dmareg) {
8098c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "SB16 [0x%lx]: unable to set DMA & IRQ (PnP device?)\n", chip->port);
8108c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "SB16 [0x%lx]: wanted: irqreg=0x%x, dmareg=0x%x, mpureg = 0x%x\n", chip->port, realirq, realdma, realmpureg);
8118c2ecf20Sopenharmony_ci		snd_printk(KERN_ERR "SB16 [0x%lx]:    got: irqreg=0x%x, dmareg=0x%x, mpureg = 0x%x\n", chip->port, irqreg, dmareg, mpureg);
8128c2ecf20Sopenharmony_ci		return -ENODEV;
8138c2ecf20Sopenharmony_ci	}
8148c2ecf20Sopenharmony_ci	return 0;
8158c2ecf20Sopenharmony_ci}
8168c2ecf20Sopenharmony_ci
8178c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_sb16_playback_ops = {
8188c2ecf20Sopenharmony_ci	.open =		snd_sb16_playback_open,
8198c2ecf20Sopenharmony_ci	.close =	snd_sb16_playback_close,
8208c2ecf20Sopenharmony_ci	.prepare =	snd_sb16_playback_prepare,
8218c2ecf20Sopenharmony_ci	.trigger =	snd_sb16_playback_trigger,
8228c2ecf20Sopenharmony_ci	.pointer =	snd_sb16_playback_pointer,
8238c2ecf20Sopenharmony_ci};
8248c2ecf20Sopenharmony_ci
8258c2ecf20Sopenharmony_cistatic const struct snd_pcm_ops snd_sb16_capture_ops = {
8268c2ecf20Sopenharmony_ci	.open =		snd_sb16_capture_open,
8278c2ecf20Sopenharmony_ci	.close =	snd_sb16_capture_close,
8288c2ecf20Sopenharmony_ci	.prepare =	snd_sb16_capture_prepare,
8298c2ecf20Sopenharmony_ci	.trigger =	snd_sb16_capture_trigger,
8308c2ecf20Sopenharmony_ci	.pointer =	snd_sb16_capture_pointer,
8318c2ecf20Sopenharmony_ci};
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_ciint snd_sb16dsp_pcm(struct snd_sb *chip, int device)
8348c2ecf20Sopenharmony_ci{
8358c2ecf20Sopenharmony_ci	struct snd_card *card = chip->card;
8368c2ecf20Sopenharmony_ci	struct snd_pcm *pcm;
8378c2ecf20Sopenharmony_ci	int err;
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	if ((err = snd_pcm_new(card, "SB16 DSP", device, 1, 1, &pcm)) < 0)
8408c2ecf20Sopenharmony_ci		return err;
8418c2ecf20Sopenharmony_ci	sprintf(pcm->name, "DSP v%i.%i", chip->version >> 8, chip->version & 0xff);
8428c2ecf20Sopenharmony_ci	pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
8438c2ecf20Sopenharmony_ci	pcm->private_data = chip;
8448c2ecf20Sopenharmony_ci	chip->pcm = pcm;
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sb16_playback_ops);
8478c2ecf20Sopenharmony_ci	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_sb16_capture_ops);
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci	if (chip->dma16 >= 0 && chip->dma8 != chip->dma16)
8508c2ecf20Sopenharmony_ci		snd_ctl_add(card, snd_ctl_new1(&snd_sb16_dma_control, chip));
8518c2ecf20Sopenharmony_ci	else
8528c2ecf20Sopenharmony_ci		pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_ci	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
8558c2ecf20Sopenharmony_ci				       card->dev, 64*1024, 128*1024);
8568c2ecf20Sopenharmony_ci	return 0;
8578c2ecf20Sopenharmony_ci}
8588c2ecf20Sopenharmony_ci
8598c2ecf20Sopenharmony_ciconst struct snd_pcm_ops *snd_sb16dsp_get_pcm_ops(int direction)
8608c2ecf20Sopenharmony_ci{
8618c2ecf20Sopenharmony_ci	return direction == SNDRV_PCM_STREAM_PLAYBACK ?
8628c2ecf20Sopenharmony_ci		&snd_sb16_playback_ops : &snd_sb16_capture_ops;
8638c2ecf20Sopenharmony_ci}
8648c2ecf20Sopenharmony_ci
8658c2ecf20Sopenharmony_ciEXPORT_SYMBOL(snd_sb16dsp_pcm);
8668c2ecf20Sopenharmony_ciEXPORT_SYMBOL(snd_sb16dsp_get_pcm_ops);
8678c2ecf20Sopenharmony_ciEXPORT_SYMBOL(snd_sb16dsp_configure);
8688c2ecf20Sopenharmony_ciEXPORT_SYMBOL(snd_sb16dsp_interrupt);
869