Commit 1082e270 authored by Wan ZongShun's avatar Wan ZongShun Committed by Mark Brown

ASoC: NUC900/audio: add nuc900 audio driver support

Add support for NUC900 AC97
Signed-off-by: default avatarWan ZongShun <mcuos.com@gmail.com>
Acked-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent b6f4bb38
......@@ -30,6 +30,7 @@ source "sound/soc/blackfin/Kconfig"
source "sound/soc/davinci/Kconfig"
source "sound/soc/fsl/Kconfig"
source "sound/soc/imx/Kconfig"
source "sound/soc/nuc900/Kconfig"
source "sound/soc/omap/Kconfig"
source "sound/soc/pxa/Kconfig"
source "sound/soc/s3c24xx/Kconfig"
......
......@@ -8,6 +8,7 @@ obj-$(CONFIG_SND_SOC) += blackfin/
obj-$(CONFIG_SND_SOC) += davinci/
obj-$(CONFIG_SND_SOC) += fsl/
obj-$(CONFIG_SND_SOC) += imx/
obj-$(CONFIG_SND_SOC) += nuc900/
obj-$(CONFIG_SND_SOC) += omap/
obj-$(CONFIG_SND_SOC) += pxa/
obj-$(CONFIG_SND_SOC) += s3c24xx/
......
##
## NUC900 series AC97 API
##
config SND_SOC_NUC900
tristate "SoC Audio for NUC900 series"
depends on ARCH_W90X900
help
This option enables support for AC97 mode on the NUC900 SoC.
config SND_SOC_NUC900_AC97
tristate
select AC97_BUS
select SND_AC97_CODEC
select SND_SOC_AC97_BUS
##
## Boards
##
config SND_SOC_NUC900EVB
tristate "NUC900 AC97 support for demo board"
depends on SND_SOC_NUC900
select SND_SOC_NUC900_AC97
select SND_SOC_AC97_CODEC
help
Select this option to enable audio (AC97) on the
NUC900 demoboard.
# NUC900 series audio
snd-soc-nuc900-pcm-objs := nuc900-pcm.o
snd-soc-nuc900-ac97-objs := nuc900-ac97.o
obj-$(CONFIG_SND_SOC_NUC900) += snd-soc-nuc900-pcm.o
obj-$(CONFIG_SND_SOC_NUC900_AC97) += snd-soc-nuc900-ac97.o
# Boards
snd-soc-nuc900-audio-objs := nuc900-audio.o
obj-$(CONFIG_SND_SOC_NUC900EVB) += snd-soc-nuc900-audio.o
This diff is collapsed.
/*
* Copyright (c) 2010 Nuvoton technology corporation.
*
* Wan ZongShun <mcuos.com@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation;version 2 of the License.
*
*/
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include "../codecs/ac97.h"
#include "nuc900-auido.h"
static struct snd_soc_dai_link nuc900evb_ac97_dai = {
.name = "AC97",
.stream_name = "AC97 HiFi",
.cpu_dai = &nuc900_ac97_dai,
.codec_dai = &ac97_dai,
};
static struct snd_soc_card nuc900evb_audio_machine = {
.name = "NUC900EVB_AC97",
.dai_link = &nuc900evb_ac97_dai,
.num_links = 1,
.platform = &nuc900_soc_platform,
};
static struct snd_soc_device nuc900evb_ac97_devdata = {
.card = &nuc900evb_audio_machine,
.codec_dev = &soc_codec_dev_ac97,
};
static struct platform_device *nuc900evb_asoc_dev;
static int __init nuc900evb_audio_init(void)
{
int ret;
ret = -ENOMEM;
nuc900evb_asoc_dev = platform_device_alloc("soc-audio", -1);
if (!nuc900evb_asoc_dev)
goto out;
/* nuc900 board audio device */
platform_set_drvdata(nuc900evb_asoc_dev, &nuc900evb_ac97_devdata);
nuc900evb_ac97_devdata.dev = &nuc900evb_asoc_dev->dev;
ret = platform_device_add(nuc900evb_asoc_dev);
if (ret) {
platform_device_put(nuc900evb_asoc_dev);
nuc900evb_asoc_dev = NULL;
}
out:
return ret;
}
static void __exit nuc900evb_audio_exit(void)
{
platform_device_unregister(nuc900evb_asoc_dev);
}
module_init(nuc900evb_audio_init);
module_exit(nuc900evb_audio_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("NUC900 Series ASoC audio support");
MODULE_AUTHOR("Wan ZongShun");
/*
* Copyright (c) 2010 Nuvoton technology corporation.
*
* Wan ZongShun <mcuos.com@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation;version 2 of the License.
*
*/
#ifndef _NUC900_AUDIO_H
#define _NUC900_AUDIO_H
#include <linux/io.h>
/* Audio Control Registers */
#define ACTL_CON 0x00
#define ACTL_RESET 0x04
#define ACTL_RDSTB 0x08
#define ACTL_RDST_LENGTH 0x0C
#define ACTL_RDSTC 0x10
#define ACTL_RSR 0x14
#define ACTL_PDSTB 0x18
#define ACTL_PDST_LENGTH 0x1C
#define ACTL_PDSTC 0x20
#define ACTL_PSR 0x24
#define ACTL_IISCON 0x28
#define ACTL_ACCON 0x2C
#define ACTL_ACOS0 0x30
#define ACTL_ACOS1 0x34
#define ACTL_ACOS2 0x38
#define ACTL_ACIS0 0x3C
#define ACTL_ACIS1 0x40
#define ACTL_ACIS2 0x44
#define ACTL_COUNTER 0x48
/* bit definition of REG_ACTL_CON register */
#define R_DMA_IRQ 0x1000
#define T_DMA_IRQ 0x0800
#define IIS_AC_PIN_SEL 0x0100
#define FIFO_TH 0x0080
#define ADC_EN 0x0010
#define M80_EN 0x0008
#define ACLINK_EN 0x0004
#define IIS_EN 0x0002
/* bit definition of REG_ACTL_RESET register */
#define W5691_PLAY 0x20000
#define ACTL_RESET_BIT 0x10000
#define RECORD_RIGHT_CHNNEL 0x08000
#define RECORD_LEFT_CHNNEL 0x04000
#define PLAY_RIGHT_CHNNEL 0x02000
#define PLAY_LEFT_CHNNEL 0x01000
#define DAC_PLAY 0x00800
#define ADC_RECORD 0x00400
#define M80_PLAY 0x00200
#define AC_RECORD 0x00100
#define AC_PLAY 0x00080
#define IIS_RECORD 0x00040
#define IIS_PLAY 0x00020
#define DAC_RESET 0x00010
#define ADC_RESET 0x00008
#define M80_RESET 0x00004
#define AC_RESET 0x00002
#define IIS_RESET 0x00001
/* bit definition of REG_ACTL_ACCON register */
#define AC_BCLK_PU_EN 0x20
#define AC_R_FINISH 0x10
#define AC_W_FINISH 0x08
#define AC_W_RES 0x04
#define AC_C_RES 0x02
/* bit definition of ACTL_RSR register */
#define R_FIFO_EMPTY 0x04
#define R_DMA_END_IRQ 0x02
#define R_DMA_MIDDLE_IRQ 0x01
/* bit definition of ACTL_PSR register */
#define P_FIFO_EMPTY 0x04
#define P_DMA_END_IRQ 0x02
#define P_DMA_MIDDLE_IRQ 0x01
/* bit definition of ACTL_ACOS0 register */
#define SLOT1_VALID 0x01
#define SLOT2_VALID 0x02
#define SLOT3_VALID 0x04
#define SLOT4_VALID 0x08
#define VALID_FRAME 0x10
/* bit definition of ACTL_ACOS1 register */
#define R_WB 0x80
#define CODEC_READY 0x10
#define RESET_PRSR 0x00
#define AUDIO_WRITE(addr, val) __raw_writel(val, addr)
#define AUDIO_READ(addr) __raw_readl(addr)
#define PCM_TX 0
#define PCM_RX 1
#define SUBSTREAM_TYPE(substream) \
((substream)->stream == SNDRV_PCM_STREAM_PLAYBACK ? PCM_TX : PCM_RX)
struct nuc900_audio {
void __iomem *mmio;
spinlock_t lock;
dma_addr_t dma_addr[2];
unsigned long buffersize[2];
unsigned long irq_num;
struct snd_pcm_substream *substream;
struct resource *res;
struct clk *clk;
struct device *dev;
};
extern struct nuc900_audio *nuc900_ac97_data;
extern struct snd_soc_dai nuc900_ac97_dai;
extern struct snd_soc_platform nuc900_soc_platform;
#endif /*end _NUC900_AUDIO_H */
/*
* Copyright (c) 2010 Nuvoton technology corporation.
*
* Wan ZongShun <mcuos.com@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation;version 2 of the License.
*
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/dma-mapping.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <mach/hardware.h>
#include "nuc900-auido.h"
static const struct snd_pcm_hardware nuc900_pcm_hardware = {
.info = SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_PAUSE |
SNDRV_PCM_INFO_RESUME,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
.channels_min = 1,
.channels_max = 2,
.buffer_bytes_max = 4*1024,
.period_bytes_min = 1*1024,
.period_bytes_max = 4*1024,
.periods_min = 1,
.periods_max = 1024,
};
static int nuc900_dma_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct nuc900_audio *nuc900_audio = runtime->private_data;
unsigned long flags, stype = SUBSTREAM_TYPE(substream);
int ret = 0;
spin_lock_irqsave(&nuc900_audio->lock, flags);
ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
if (ret < 0)
return ret;
nuc900_audio->substream = substream;
nuc900_audio->dma_addr[stype] = runtime->dma_addr;
nuc900_audio->buffersize[stype] = params_buffer_bytes(params);
spin_unlock_irqrestore(&nuc900_audio->lock, flags);
return ret;
}
static void nuc900_update_dma_register(struct snd_pcm_substream *substream,
dma_addr_t dma_addr, size_t count)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct nuc900_audio *nuc900_audio = runtime->private_data;
void __iomem *mmio_addr, *mmio_len;
if (SUBSTREAM_TYPE(substream) == PCM_TX) {
mmio_addr = nuc900_audio->mmio + ACTL_PDSTB;
mmio_len = nuc900_audio->mmio + ACTL_PDST_LENGTH;
} else {
mmio_addr = nuc900_audio->mmio + ACTL_RDSTB;
mmio_len = nuc900_audio->mmio + ACTL_RDST_LENGTH;
}
AUDIO_WRITE(mmio_addr, dma_addr);
AUDIO_WRITE(mmio_len, count);
}
static void nuc900_dma_start(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct nuc900_audio *nuc900_audio = runtime->private_data;
unsigned long val;
val = AUDIO_READ(nuc900_audio->mmio + ACTL_CON);
val |= (T_DMA_IRQ | R_DMA_IRQ);
AUDIO_WRITE(nuc900_audio->mmio + ACTL_CON, val);
}
static void nuc900_dma_stop(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct nuc900_audio *nuc900_audio = runtime->private_data;
unsigned long val;
val = AUDIO_READ(nuc900_audio->mmio + ACTL_CON);
val &= ~(T_DMA_IRQ | R_DMA_IRQ);
AUDIO_WRITE(nuc900_audio->mmio + ACTL_CON, val);
}
static irqreturn_t nuc900_dma_interrupt(int irq, void *dev_id)
{
struct snd_pcm_substream *substream = dev_id;
struct nuc900_audio *nuc900_audio = substream->runtime->private_data;
unsigned long val;
spin_lock(&nuc900_audio->lock);
val = AUDIO_READ(nuc900_audio->mmio + ACTL_CON);
if (val & R_DMA_IRQ) {
AUDIO_WRITE(nuc900_audio->mmio + ACTL_CON, val | R_DMA_IRQ);
val = AUDIO_READ(nuc900_audio->mmio + ACTL_RSR);
if (val & R_DMA_MIDDLE_IRQ) {
val |= R_DMA_MIDDLE_IRQ;
AUDIO_WRITE(nuc900_audio->mmio + ACTL_RSR, val);
}
if (val & R_DMA_END_IRQ) {
val |= R_DMA_END_IRQ;
AUDIO_WRITE(nuc900_audio->mmio + ACTL_RSR, val);
}
} else if (val & T_DMA_IRQ) {
AUDIO_WRITE(nuc900_audio->mmio + ACTL_CON, val | T_DMA_IRQ);
val = AUDIO_READ(nuc900_audio->mmio + ACTL_PSR);
if (val & P_DMA_MIDDLE_IRQ) {
val |= P_DMA_MIDDLE_IRQ;
AUDIO_WRITE(nuc900_audio->mmio + ACTL_PSR, val);
}
if (val & P_DMA_END_IRQ) {
val |= P_DMA_END_IRQ;
AUDIO_WRITE(nuc900_audio->mmio + ACTL_PSR, val);
}
} else {
dev_err(nuc900_audio->dev, "Wrong DMA interrupt status!\n");
spin_unlock(&nuc900_audio->lock);
return IRQ_HANDLED;
}
spin_unlock(&nuc900_audio->lock);
snd_pcm_period_elapsed(substream);
return IRQ_HANDLED;
}
static int nuc900_dma_hw_free(struct snd_pcm_substream *substream)
{
snd_pcm_lib_free_pages(substream);
return 0;
}
static int nuc900_dma_prepare(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct nuc900_audio *nuc900_audio = runtime->private_data;
unsigned long flags, val, stype = SUBSTREAM_TYPE(substream);;
spin_lock_irqsave(&nuc900_audio->lock, flags);
nuc900_update_dma_register(substream,
nuc900_audio->dma_addr[stype], nuc900_audio->buffersize[stype]);
val = AUDIO_READ(nuc900_audio->mmio + ACTL_RESET);
switch (runtime->channels) {
case 1:
if (PCM_TX == stype) {
val &= ~(PLAY_LEFT_CHNNEL | PLAY_RIGHT_CHNNEL);
val |= PLAY_RIGHT_CHNNEL;
} else {
val &= ~(RECORD_LEFT_CHNNEL | RECORD_RIGHT_CHNNEL);
val |= RECORD_RIGHT_CHNNEL;
}
AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val);
break;
case 2:
if (PCM_TX == stype)
val |= (PLAY_LEFT_CHNNEL | PLAY_RIGHT_CHNNEL);
else
val |= (RECORD_LEFT_CHNNEL | RECORD_RIGHT_CHNNEL);
AUDIO_WRITE(nuc900_audio->mmio + ACTL_RESET, val);
break;
default:
return -EINVAL;
}
spin_unlock_irqrestore(&nuc900_audio->lock, flags);
return 0;
}
static int nuc900_dma_trigger(struct snd_pcm_substream *substream, int cmd)
{
int ret = 0;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
nuc900_dma_start(substream);
break;
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
nuc900_dma_stop(substream);
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
int nuc900_dma_getposition(struct snd_pcm_substream *substream,
dma_addr_t *src, dma_addr_t *dst)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct nuc900_audio *nuc900_audio = runtime->private_data;
if (src != NULL)
*src = AUDIO_READ(nuc900_audio->mmio + ACTL_PDSTC);
if (dst != NULL)
*dst = AUDIO_READ(nuc900_audio->mmio + ACTL_RDSTC);
return 0;
}
static snd_pcm_uframes_t nuc900_dma_pointer(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
dma_addr_t src, dst;
unsigned long res;
nuc900_dma_getposition(substream, &src, &dst);
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
res = dst - runtime->dma_addr;
else
res = src - runtime->dma_addr;
return bytes_to_frames(substream->runtime, res);
}
static int nuc900_dma_open(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct nuc900_audio *nuc900_audio;
snd_soc_set_runtime_hwparams(substream, &nuc900_pcm_hardware);
nuc900_audio = nuc900_ac97_data;
if (request_irq(nuc900_audio->irq_num, nuc900_dma_interrupt,
IRQF_DISABLED, "nuc900-dma", substream))
return -EBUSY;
runtime->private_data = nuc900_audio;
return 0;
}
static int nuc900_dma_close(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct nuc900_audio *nuc900_audio = runtime->private_data;
free_irq(nuc900_audio->irq_num, substream);
return 0;
}
static int nuc900_dma_mmap(struct snd_pcm_substream *substream,
struct vm_area_struct *vma)
{
struct snd_pcm_runtime *runtime = substream->runtime;
return dma_mmap_writecombine(substream->pcm->card->dev, vma,
runtime->dma_area,
runtime->dma_addr,
runtime->dma_bytes);
}
static struct snd_pcm_ops nuc900_dma_ops = {
.open = nuc900_dma_open,
.close = nuc900_dma_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = nuc900_dma_hw_params,
.hw_free = nuc900_dma_hw_free,
.prepare = nuc900_dma_prepare,
.trigger = nuc900_dma_trigger,
.pointer = nuc900_dma_pointer,
.mmap = nuc900_dma_mmap,
};
static void nuc900_dma_free_dma_buffers(struct snd_pcm *pcm)
{
snd_pcm_lib_preallocate_free_for_all(pcm);
}
static u64 nuc900_pcm_dmamask = DMA_BIT_MASK(32);
static int nuc900_dma_new(struct snd_card *card,
struct snd_soc_dai *dai, struct snd_pcm *pcm)
{
if (!card->dev->dma_mask)
card->dev->dma_mask = &nuc900_pcm_dmamask;
if (!card->dev->coherent_dma_mask)
card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
card->dev, 4 * 1024, (4 * 1024) - 1);
return 0;
}
struct snd_soc_platform nuc900_soc_platform = {
.name = "nuc900-dma",
.pcm_ops = &nuc900_dma_ops,
.pcm_new = nuc900_dma_new,
.pcm_free = nuc900_dma_free_dma_buffers,
}
EXPORT_SYMBOL_GPL(nuc900_soc_platform);
static int __init nuc900_soc_platform_init(void)
{
return snd_soc_register_platform(&nuc900_soc_platform);
}
static void __exit nuc900_soc_platform_exit(void)
{
snd_soc_unregister_platform(&nuc900_soc_platform);
}
module_init(nuc900_soc_platform_init);
module_exit(nuc900_soc_platform_exit);
MODULE_AUTHOR("Wan ZongShun, <mcuos.com@gmail.com>");
MODULE_DESCRIPTION("nuc900 Audio DMA module");
MODULE_LICENSE("GPL");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment