atiixp_modem.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,352 行 · 第 1/3 页
C
1,352 行
((unsigned int)reg << ATI_REG_PHYS_OUT_ADDR_SHIFT) | ATI_REG_PHYS_OUT_ADDR_EN | codec; atiixp_write(chip, PHYS_OUT_ADDR, data);}static unsigned short snd_atiixp_ac97_read(ac97_t *ac97, unsigned short reg){ atiixp_t *chip = ac97->private_data; unsigned short data; spin_lock(&chip->ac97_lock); data = snd_atiixp_codec_read(chip, ac97->num, reg); spin_unlock(&chip->ac97_lock); return data; }static void snd_atiixp_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short val){ atiixp_t *chip = ac97->private_data; spin_lock(&chip->ac97_lock); snd_atiixp_codec_write(chip, ac97->num, reg, val); spin_unlock(&chip->ac97_lock);}/* * reset AC link */static int snd_atiixp_aclink_reset(atiixp_t *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); do_delay(); atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET); if (--timeout) { snd_printk(KERN_ERR "atiixp: 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(atiixp_t *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(atiixp_t *chip){ int timeout; chip->codec_not_ready_bits = 0; atiixp_write(chip, IER, CODEC_CHECK_BITS); /* wait for the interrupts */ timeout = HZ / 10; while (timeout-- > 0) { do_delay(); 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: no codec detected!\n"); return -ENXIO; } return 0;}/* * enable DMA and irqs */static int snd_atiixp_chip_start(atiixp_t *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(atiixp_t *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(snd_pcm_substream_t *substream){ atiixp_t *chip = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime = substream->runtime; atiixp_dma_t *dma = (atiixp_dma_t *)runtime->private_data; unsigned int curptr; spin_lock(&chip->reg_lock); curptr = readl(chip->remap_addr + dma->ops->dt_cur); if (curptr < dma->buf_addr) { snd_printdd("curptr = %x, base = %x\n", curptr, dma->buf_addr); curptr = 0; } else { curptr -= dma->buf_addr; if (curptr >= dma->buf_bytes) { snd_printdd("curptr = %x, size = %x\n", curptr, dma->buf_bytes); curptr = 0; } } spin_unlock(&chip->reg_lock); return bytes_to_frames(runtime, curptr);}/* * XRUN detected, and stop the PCM substream */static void snd_atiixp_xrun_dma(atiixp_t *chip, atiixp_dma_t *dma){ if (! dma->substream || ! dma->running) return; snd_printdd("atiixp: 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(atiixp_t *chip, atiixp_dma_t *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(atiixp_t *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(snd_pcm_substream_t *substream, int cmd){ atiixp_t *chip = snd_pcm_substream_chip(substream); atiixp_dma_t *dma = (atiixp_dma_t *)substream->runtime->private_data; unsigned int reg = 0; int i; snd_assert(dma->ops->enable_transfer && dma->ops->flush_dma, return -EINVAL); if (cmd != SNDRV_PCM_TRIGGER_START && cmd != SNDRV_PCM_TRIGGER_STOP) return -EINVAL; spin_lock(&chip->reg_lock); /* hook off/on: via GPIO_OUT */ for (i = 0; i < NUM_ATI_CODECS; i++) { if (chip->ac97[i]) { reg = snd_ac97_read(chip->ac97[i], AC97_GPIO_STATUS); break; } } if(cmd == SNDRV_PCM_TRIGGER_START) reg |= AC97_GPIO_LINE1_OH; else reg &= ~AC97_GPIO_LINE1_OH; reg = (reg << ATI_REG_MODEM_OUT_GPIO_DATA_SHIFT) | ATI_REG_MODEM_OUT_GPIO_EN ; atiixp_write(chip, MODEM_OUT_GPIO, reg); if (cmd == SNDRV_PCM_TRIGGER_START) { dma->ops->enable_transfer(chip, 1); dma->running = 1; } else { dma->ops->enable_transfer(chip, 0); dma->running = 0; } 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 0;}/* * 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(atiixp_t *chip){ atiixp_write(chip, MODEM_FIFO_FLUSH, ATI_REG_MODEM_FIFO_OUT1_FLUSH);}/* enable/disable analog OUT DMA */static void atiixp_out_enable_dma(atiixp_t *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(atiixp_t *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(atiixp_t *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(atiixp_t *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(atiixp_t *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(snd_pcm_substream_t *substream){ atiixp_t *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(snd_pcm_substream_t *substream){ return 0;}/* * hw_params - allocate the buffer and set up buffer descriptors */static int snd_atiixp_pcm_hw_params(snd_pcm_substream_t *substream, snd_pcm_hw_params_t *hw_params){ atiixp_t *chip = snd_pcm_substream_chip(substream); atiixp_dma_t *dma = (atiixp_dma_t *)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(snd_pcm_substream_t * substream){ atiixp_t *chip = snd_pcm_substream_chip(substream); atiixp_dma_t *dma = (atiixp_dma_t *)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 snd_pcm_hardware_t 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(snd_pcm_substream_t *substream, atiixp_dma_t *dma, int pcm_type){ atiixp_t *chip = snd_pcm_substream_chip(substream); snd_pcm_runtime_t *runtime = substream->runtime; int err; static unsigned int rates[] = { 8000, 9600, 12000, 16000 }; static snd_pcm_hw_constraint_list_t 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(snd_pcm_substream_t *substream, atiixp_dma_t *dma){ atiixp_t *chip = snd_pcm_substream_chip(substream); /* disable DMA bits */ snd_assert(dma->ops && dma->ops->enable_dma, return -EINVAL);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?