⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atiixp_modem.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	atiixp_write(chip, PHYS_OUT_ADDR, data);}static unsigned short snd_atiixp_ac97_read(struct snd_ac97 *ac97,					   unsigned short reg){	struct atiixp_modem *chip = ac97->private_data;	return snd_atiixp_codec_read(chip, ac97->num, reg);    }static void snd_atiixp_ac97_write(struct snd_ac97 *ac97, unsigned short reg,				  unsigned short val){	struct atiixp_modem *chip = ac97->private_data;	if (reg == AC97_GPIO_STATUS) {		atiixp_write(chip, MODEM_OUT_GPIO,			(val << ATI_REG_MODEM_OUT_GPIO_DATA_SHIFT) | ATI_REG_MODEM_OUT_GPIO_EN);		return;	}	snd_atiixp_codec_write(chip, ac97->num, reg, val);}/* * reset AC link */static int snd_atiixp_aclink_reset(struct atiixp_modem *chip){	int timeout;	/* reset powerdoewn */	if (atiixp_update(chip, CMD, ATI_REG_CMD_POWERDOWN, 0))		udelay(10);	/* perform a software reset */	atiixp_update(chip, CMD, ATI_REG_CMD_AC_SOFT_RESET, ATI_REG_CMD_AC_SOFT_RESET);	atiixp_read(chip, CMD);	udelay(10);	atiixp_update(chip, CMD, ATI_REG_CMD_AC_SOFT_RESET, 0);    	timeout = 10;	while (! (atiixp_read(chip, CMD) & ATI_REG_CMD_ACLINK_ACTIVE)) {		/* do a hard reset */		atiixp_update(chip, CMD, ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET,			      ATI_REG_CMD_AC_SYNC);		atiixp_read(chip, CMD);		msleep(1);		atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET);		if (--timeout) {			snd_printk(KERN_ERR "atiixp-modem: codec reset timeout\n");			break;		}	}	/* deassert RESET and assert SYNC to make sure */	atiixp_update(chip, CMD, ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET,		      ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET);	return 0;}#ifdef CONFIG_PMstatic int snd_atiixp_aclink_down(struct atiixp_modem *chip){	// if (atiixp_read(chip, MODEM_MIRROR) & 0x1) /* modem running, too? */	//	return -EBUSY;	atiixp_update(chip, CMD,		     ATI_REG_CMD_POWERDOWN | ATI_REG_CMD_AC_RESET,		     ATI_REG_CMD_POWERDOWN);	return 0;}#endif/* * auto-detection of codecs * * the IXP chip can generate interrupts for the non-existing codecs. * NEW_FRAME interrupt is used to make sure that the interrupt is generated * even if all three codecs are connected. */#define ALL_CODEC_NOT_READY \	    (ATI_REG_ISR_CODEC0_NOT_READY |\	     ATI_REG_ISR_CODEC1_NOT_READY |\	     ATI_REG_ISR_CODEC2_NOT_READY)#define CODEC_CHECK_BITS (ALL_CODEC_NOT_READY|ATI_REG_ISR_NEW_FRAME)static int snd_atiixp_codec_detect(struct atiixp_modem *chip){	int timeout;	chip->codec_not_ready_bits = 0;	atiixp_write(chip, IER, CODEC_CHECK_BITS);	/* wait for the interrupts */	timeout = 50;	while (timeout-- > 0) {		msleep(1);		if (chip->codec_not_ready_bits)			break;	}	atiixp_write(chip, IER, 0); /* disable irqs */	if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) {		snd_printk(KERN_ERR "atiixp-modem: no codec detected!\n");		return -ENXIO;	}	return 0;}/* * enable DMA and irqs */static int snd_atiixp_chip_start(struct atiixp_modem *chip){	unsigned int reg;	/* set up spdif, enable burst mode */	reg = atiixp_read(chip, CMD);	reg |= ATI_REG_CMD_BURST_EN;	if(!(reg & ATI_REG_CMD_MODEM_PRESENT))		reg |= ATI_REG_CMD_MODEM_PRESENT;	atiixp_write(chip, CMD, reg);	/* clear all interrupt source */	atiixp_write(chip, ISR, 0xffffffff);	/* enable irqs */	atiixp_write(chip, IER,		     ATI_REG_IER_MODEM_STATUS_EN |		     ATI_REG_IER_MODEM_IN_XRUN_EN |		     ATI_REG_IER_MODEM_OUT1_XRUN_EN);	return 0;}/* * disable DMA and IRQs */static int snd_atiixp_chip_stop(struct atiixp_modem *chip){	/* clear interrupt source */	atiixp_write(chip, ISR, atiixp_read(chip, ISR));	/* disable irqs */	atiixp_write(chip, IER, 0);	return 0;}/* * PCM section *//* * pointer callback simplly reads XXX_DMA_DT_CUR register as the current * position.  when SG-buffer is implemented, the offset must be calculated * correctly... */static snd_pcm_uframes_t snd_atiixp_pcm_pointer(struct snd_pcm_substream *substream){	struct atiixp_modem *chip = snd_pcm_substream_chip(substream);	struct snd_pcm_runtime *runtime = substream->runtime;	struct atiixp_dma *dma = runtime->private_data;	unsigned int curptr;	int timeout = 1000;	while (timeout--) {		curptr = readl(chip->remap_addr + dma->ops->dt_cur);		if (curptr < dma->buf_addr)			continue;		curptr -= dma->buf_addr;		if (curptr >= dma->buf_bytes)			continue;		return bytes_to_frames(runtime, curptr);	}	snd_printd("atiixp-modem: invalid DMA pointer read 0x%x (buf=%x)\n",		   readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr);	return 0;}/* * XRUN detected, and stop the PCM substream */static void snd_atiixp_xrun_dma(struct atiixp_modem *chip,				struct atiixp_dma *dma){	if (! dma->substream || ! dma->running)		return;	snd_printdd("atiixp-modem: XRUN detected (DMA %d)\n", dma->ops->type);	snd_pcm_stop(dma->substream, SNDRV_PCM_STATE_XRUN);}/* * the period ack.  update the substream. */static void snd_atiixp_update_dma(struct atiixp_modem *chip,				  struct atiixp_dma *dma){	if (! dma->substream || ! dma->running)		return;	snd_pcm_period_elapsed(dma->substream);}/* set BUS_BUSY interrupt bit if any DMA is running *//* call with spinlock held */static void snd_atiixp_check_bus_busy(struct atiixp_modem *chip){	unsigned int bus_busy;	if (atiixp_read(chip, CMD) & (ATI_REG_CMD_MODEM_SEND1_EN |				      ATI_REG_CMD_MODEM_RECEIVE_EN))		bus_busy = ATI_REG_IER_MODEM_SET_BUS_BUSY;	else		bus_busy = 0;	atiixp_update(chip, IER, ATI_REG_IER_MODEM_SET_BUS_BUSY, bus_busy);}/* common trigger callback * calling the lowlevel callbacks in it */static int snd_atiixp_pcm_trigger(struct snd_pcm_substream *substream, int cmd){	struct atiixp_modem *chip = snd_pcm_substream_chip(substream);	struct atiixp_dma *dma = substream->runtime->private_data;	int err = 0;	snd_assert(dma->ops->enable_transfer && dma->ops->flush_dma, return -EINVAL);	spin_lock(&chip->reg_lock);	switch(cmd) {	case SNDRV_PCM_TRIGGER_START:		dma->ops->enable_transfer(chip, 1);		dma->running = 1;		break;	case SNDRV_PCM_TRIGGER_STOP:		dma->ops->enable_transfer(chip, 0);		dma->running = 0;		break;	default:		err = -EINVAL;		break;	}	if (! err) {	snd_atiixp_check_bus_busy(chip);	if (cmd == SNDRV_PCM_TRIGGER_STOP) {		dma->ops->flush_dma(chip);		snd_atiixp_check_bus_busy(chip);	}	}	spin_unlock(&chip->reg_lock);	return err;}/* * lowlevel callbacks for each DMA type * * every callback is supposed to be called in chip->reg_lock spinlock *//* flush FIFO of analog OUT DMA */static void atiixp_out_flush_dma(struct atiixp_modem *chip){	atiixp_write(chip, MODEM_FIFO_FLUSH, ATI_REG_MODEM_FIFO_OUT1_FLUSH);}/* enable/disable analog OUT DMA */static void atiixp_out_enable_dma(struct atiixp_modem *chip, int on){	unsigned int data;	data = atiixp_read(chip, CMD);	if (on) {		if (data & ATI_REG_CMD_MODEM_OUT_DMA1_EN)			return;		atiixp_out_flush_dma(chip);		data |= ATI_REG_CMD_MODEM_OUT_DMA1_EN;	} else		data &= ~ATI_REG_CMD_MODEM_OUT_DMA1_EN;	atiixp_write(chip, CMD, data);}/* start/stop transfer over OUT DMA */static void atiixp_out_enable_transfer(struct atiixp_modem *chip, int on){	atiixp_update(chip, CMD, ATI_REG_CMD_MODEM_SEND1_EN,		      on ? ATI_REG_CMD_MODEM_SEND1_EN : 0);}/* enable/disable analog IN DMA */static void atiixp_in_enable_dma(struct atiixp_modem *chip, int on){	atiixp_update(chip, CMD, ATI_REG_CMD_MODEM_IN_DMA_EN,		      on ? ATI_REG_CMD_MODEM_IN_DMA_EN : 0);}/* start/stop analog IN DMA */static void atiixp_in_enable_transfer(struct atiixp_modem *chip, int on){	if (on) {		unsigned int data = atiixp_read(chip, CMD);		if (! (data & ATI_REG_CMD_MODEM_RECEIVE_EN)) {			data |= ATI_REG_CMD_MODEM_RECEIVE_EN;			atiixp_write(chip, CMD, data);		}	} else		atiixp_update(chip, CMD, ATI_REG_CMD_MODEM_RECEIVE_EN, 0);}/* flush FIFO of analog IN DMA */static void atiixp_in_flush_dma(struct atiixp_modem *chip){	atiixp_write(chip, MODEM_FIFO_FLUSH, ATI_REG_MODEM_FIFO_IN_FLUSH);}/* set up slots and formats for analog OUT */static int snd_atiixp_playback_prepare(struct snd_pcm_substream *substream){	struct atiixp_modem *chip = snd_pcm_substream_chip(substream);	unsigned int data;	spin_lock_irq(&chip->reg_lock);	/* set output threshold */	data = atiixp_read(chip, MODEM_OUT_FIFO);	data &= ~ATI_REG_MODEM_OUT1_DMA_THRESHOLD_MASK;	data |= 0x04 << ATI_REG_MODEM_OUT1_DMA_THRESHOLD_SHIFT;	atiixp_write(chip, MODEM_OUT_FIFO, data);	spin_unlock_irq(&chip->reg_lock);	return 0;}/* set up slots and formats for analog IN */static int snd_atiixp_capture_prepare(struct snd_pcm_substream *substream){	return 0;}/* * hw_params - allocate the buffer and set up buffer descriptors */static int snd_atiixp_pcm_hw_params(struct snd_pcm_substream *substream,				   struct snd_pcm_hw_params *hw_params){	struct atiixp_modem *chip = snd_pcm_substream_chip(substream);	struct atiixp_dma *dma = substream->runtime->private_data;	int err;	int i;	err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));	if (err < 0)		return err;	dma->buf_addr = substream->runtime->dma_addr;	dma->buf_bytes = params_buffer_bytes(hw_params);	err = atiixp_build_dma_packets(chip, dma, substream,				       params_periods(hw_params),				       params_period_bytes(hw_params));	if (err < 0)		return err;	/* set up modem rate */	for (i = 0; i < NUM_ATI_CODECS; i++) {		if (! chip->ac97[i])			continue;		snd_ac97_write(chip->ac97[i], AC97_LINE1_RATE, params_rate(hw_params));		snd_ac97_write(chip->ac97[i], AC97_LINE1_LEVEL, 0);	}	return err;}static int snd_atiixp_pcm_hw_free(struct snd_pcm_substream *substream){	struct atiixp_modem *chip = snd_pcm_substream_chip(substream);	struct atiixp_dma *dma = substream->runtime->private_data;	atiixp_clear_dma_packets(chip, dma, substream);	snd_pcm_lib_free_pages(substream);	return 0;}/* * pcm hardware definition, identical for all DMA types */static struct snd_pcm_hardware snd_atiixp_pcm_hw ={	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |				 SNDRV_PCM_INFO_BLOCK_TRANSFER |				 SNDRV_PCM_INFO_MMAP_VALID),	.formats =		SNDRV_PCM_FMTBIT_S16_LE,	.rates =		(SNDRV_PCM_RATE_8000 |				 SNDRV_PCM_RATE_16000 |				 SNDRV_PCM_RATE_KNOT),	.rate_min =		8000,	.rate_max =		16000,	.channels_min =		2,	.channels_max =		2,	.buffer_bytes_max =	256 * 1024,	.period_bytes_min =	32,	.period_bytes_max =	128 * 1024,	.periods_min =		2,	.periods_max =		ATI_MAX_DESCRIPTORS,};static int snd_atiixp_pcm_open(struct snd_pcm_substream *substream,			       struct atiixp_dma *dma, int pcm_type){	struct atiixp_modem *chip = snd_pcm_substream_chip(substream);	struct snd_pcm_runtime *runtime = substream->runtime;	int err;	static unsigned int rates[] = { 8000,  9600, 12000, 16000 };	static struct snd_pcm_hw_constraint_list hw_constraints_rates = {		.count = ARRAY_SIZE(rates),		.list = rates,		.mask = 0,	};	snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL);	if (dma->opened)		return -EBUSY;	dma->substream = substream;	runtime->hw = snd_atiixp_pcm_hw;	dma->ac97_pcm_type = pcm_type;	if ((err = snd_pcm_hw_constraint_list(runtime, 0,					      SNDRV_PCM_HW_PARAM_RATE,					      &hw_constraints_rates)) < 0)		return err;	if ((err = snd_pcm_hw_constraint_integer(runtime,						 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)		return err;	runtime->private_data = dma;	/* enable DMA bits */	spin_lock_irq(&chip->reg_lock);	dma->ops->enable_dma(chip, 1);	spin_unlock_irq(&chip->reg_lock);	dma->opened = 1;	return 0;}static int snd_atiixp_pcm_close(struct snd_pcm_substream *substream,				struct atiixp_dma *dma){	struct atiixp_modem *chip = snd_pcm_substream_chip(substream);	/* disable DMA bits */	snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL);	spin_lock_irq(&chip->reg_lock);	dma->ops->enable_dma(chip, 0);	spin_unlock_irq(&chip->reg_lock);	dma->substream = NULL;	dma->opened = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -