From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: new ALSA driver for audio on the ARM PXA2xx platform Date: Wed, 26 Jan 2005 11:36:31 +0100 Message-ID: References: Mime-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Nicolas Pitre Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org Hi Nicolas, At Tue, 25 Jan 2005 16:33:40 -0500 (EST), Nicolas Pitre wrote: > > > This patch adds two modules: one for generic PCM support on PXA2xx and > another to interface with the AC97 link on the PXA2xx. Eventually > additional modules could be written to use the PCM module with SSP or > I2S audio ports. > > Signed-off-by: Nicolas Pitre Thanks, the code looks nice. > +static int pxa2xx_ac97_pcm_startup(snd_pcm_substream_t *substream) > +{ > + snd_pcm_runtime_t *runtime = substream->runtime; > + pxa2xx_audio_ops_t *platform_ops; > + int vra_mask; > + > + runtime->hw.channels_min = 2; > + runtime->hw.channels_max = 2; > + > + vra_mask = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? > + AC97_EA_VRA : AC97_EA_VRM; > + if (pxa2xx_ac97_ac97->regs[AC97_EXTENDED_STATUS] & vra_mask) { > + runtime->hw.rates = SNDRV_PCM_RATE_8000_48000; > + runtime->hw.rate_min = 8000; > + runtime->hw.rate_max = 48000; > + } else { > + runtime->hw.rates = SNDRV_PCM_RATE_48000; > + runtime->hw.rate_min = 48000; > + runtime->hw.rate_max = 48000; > + } You can use ac97->rates[AC97_RATES_FRONT_DAC] and ac97->rates[AC97_RATES_ADC] for rates bits, and call snd_pcm_limit_hw_rates(runtime) to set rate_min/max automatically. Some codecs don't support non-standard rate even VRA is set. > +static int pxa2xx_ac97_probe(struct device *dev) (snip) > + snprintf(card->shortname, sizeof(card->shortname), "%s", > + snd_ac97_get_short_name(pxa2xx_ac97_ac97)); Set longname, too. It will appear in /proc/asound/cards. > Index: linux-2.6/sound/arm/pxa2xx-pcm.c (snip) > +static const snd_pcm_hardware_t pxa2xx_pcm_hardware = { > + .info = SNDRV_PCM_INFO_MMAP | > + SNDRV_PCM_INFO_MMAP_VALID | > + SNDRV_PCM_INFO_INTERLEAVED | > + SNDRV_PCM_INFO_PAUSE, Don't forget SNDRV_PCM_INFO_RESUME if the driver supports PM. > + .formats = SNDRV_PCM_FMTBIT_S16_LE, > + .period_bytes_min = 32, > + .period_bytes_max = 8192 - 32, I suppose this 32 is fifo size? If so, you don't have to count it here. The period size defines the size of DMA interrupt period. (The fifo_size isn't used in the driver currently.) > +static void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id, struct pt_regs *regs) > +{ > + snd_pcm_substream_t *substream = dev_id; > + struct pxa2xx_runtime_data *rtd = substream->runtime->private_data; > + int dcsr; > + > + dcsr = DCSR(dma_ch); > + DCSR(dma_ch) = dcsr & ~DCSR_STOPIRQEN; > + > + if (dcsr & DCSR_ENDINTR) { > + snd_pcm_period_elapsed(substream); > + } else { > + printk( KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n", > + rtd->params->name, dma_ch, dcsr ); You can call here snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN) to notify the buffer over/underrun. > +static int > +pxa2xx_pcm_mmap(snd_pcm_substream_t *substream, struct vm_area_struct *vma) > +{ > + snd_pcm_runtime_t *runtime = substream->runtime; > + return dma_mmap_writecombine(substream->pcm->card->dev, vma, > + runtime->dma_area, > + runtime->dma_addr, > + runtime->dma_bytes); > +} > + > +static snd_pcm_ops_t pxa2xx_pcm_ops = { > + .open = pxa2xx_pcm_open, > + .close = pxa2xx_pcm_close, > + .ioctl = snd_pcm_lib_ioctl, > + .hw_params = pxa2xx_pcm_hw_params, > + .hw_free = pxa2xx_pcm_hw_free, > + .prepare = pxa2xx_pcm_prepare, > + .trigger = pxa2xx_pcm_trigger, > + .pointer = pxa2xx_pcm_pointer, > + .mmap = pxa2xx_pcm_mmap, > +}; Heh, finally a right driver using mmap callback ;) Takashi ------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl