예제 #1
0
int DMAbuf_open(int dev, int mode)
{
	struct audio_operations *adev = audio_devs[dev];
	int retval;
	struct dma_buffparms *dmap_in = NULL;
	struct dma_buffparms *dmap_out = NULL;

	if (!adev)
		  return -ENXIO;
	if (!(adev->flags & DMA_DUPLEX))
		adev->dmap_in = adev->dmap_out;
	check_driver(adev->d);

	if ((retval = adev->d->open(dev, mode)) < 0)
		return retval;
	dmap_out = adev->dmap_out;
	dmap_in = adev->dmap_in;
	if (dmap_in == dmap_out)
		adev->flags &= ~DMA_DUPLEX;

	if (mode & OPEN_WRITE) {
		if ((retval = open_dmap(adev, mode, dmap_out)) < 0) {
			adev->d->close(dev);
			return retval;
		}
	}
	adev->enable_bits = mode;

	if (mode == OPEN_READ || (mode != OPEN_WRITE && (adev->flags & DMA_DUPLEX))) {
		if ((retval = open_dmap(adev, mode, dmap_in)) < 0) {
			adev->d->close(dev);
			if (mode & OPEN_WRITE)
				close_dmap(adev, dmap_out);
			return retval;
		}
	}
	adev->open_mode = mode;
	adev->go = 1;

	adev->d->set_bits(dev, 8);
	adev->d->set_channels(dev, 1);
	adev->d->set_speed(dev, DSP_DEFAULT_SPEED);
	if (adev->dmap_out->dma_mode == DMODE_OUTPUT) 
		memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte,
		       adev->dmap_out->bytes_in_use);
	return 0;
}
예제 #2
0
파일: dmabuf.c 프로젝트: xricson/knoppix
int DMAbuf_open_dma(int dev)
{
	/*
	 *    NOTE!  This routine opens only the primary DMA channel (output).
	 */
	struct audio_operations *adev = audio_devs[dev];
	int err;

	if ((err = open_dmap(adev, OPEN_READWRITE, adev->dmap_out)) < 0)
		return -EBUSY;
	dma_init_buffers(adev->dmap_out);
	adev->dmap_out->flags |= DMA_ALLOC_DONE;
	adev->dmap_out->fragment_size = adev->dmap_out->buffsize;

	if (adev->dmap_out->dma >= 0) {
		unsigned long flags;

		flags=claim_dma_lock();
		clear_dma_ff(adev->dmap_out->dma);
		disable_dma(adev->dmap_out->dma);
		release_dma_lock(flags);
	}
	return 0;
}