[alsa-devel] [PATCH v3 1/4] ASoC: DMIC: Adding the OMAP DMIC driver

Varadarajan, Charulatha charu at ti.com
Fri Jan 28 08:43:15 CET 2011


On Wed, Jan 26, 2011 at 03:30, David Lambert <dlambert at ti.com> wrote:
> This patch adds support for the OMAP4 digital microphone DAI.
>
> This DAI can support support recording in 2, 4, or 6 channels
>
> When provided with a 19.2Mhz functional clock, can encode at 96Khz or
> 192Khz (all channels must have the same sample rate).
>
> Details of the hardware interface can be found in the OMAP4 TRM in Section 23.7
>
> Signed-off-by: David Lambert <dlambert at ti.com>
> ---
>  arch/arm/plat-omap/include/plat/dmic.h |   82 +++++
>  sound/soc/omap/Kconfig                 |    3 +
>  sound/soc/omap/Makefile                |    2 +
>  sound/soc/omap/omap-dmic.c             |  534 ++++++++++++++++++++++++++++++++
>  4 files changed, 621 insertions(+), 0 deletions(-)
>  create mode 100644 arch/arm/plat-omap/include/plat/dmic.h
>  create mode 100644 sound/soc/omap/omap-dmic.c
>
> diff --git a/arch/arm/plat-omap/include/plat/dmic.h b/arch/arm/plat-omap/include/plat/dmic.h
> new file mode 100644
> index 0000000..a72e080
> --- /dev/null
> +++ b/arch/arm/plat-omap/include/plat/dmic.h
> @@ -0,0 +1,82 @@
> +/*
> + * omap-dmic.h  --  OMAP Digital Microphone Controller
> + *
> + * Author: Liam Girdwood <lrg at slimlogic.co.uk>
> + *        David Lambert <dlambert at ti.com>
> + *        Misael Lopez Cruz <misael.lopez at ti.com>

Consider adding the copyright info.

> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#ifndef __ASM_ARCH_OMAP_DMIC_H
> +#define __ASM_ARCH_OMAP_DMIC_H
> +
> +#define OMAP44XX_DMIC_L3_BASE  0x4902e000
> +
> +#define OMAP_DMIC_REVISION             0x00
> +#define OMAP_DMIC_SYSCONFIG            0x10

As this driver would use hwmod framework, it would be good
to avoid defining this macro in the driver. Anyway it is not
used in the driver.

> +#define OMAP_DMIC_IRQSTATUS_RAW                0x24
> +#define OMAP_DMIC_IRQSTATUS            0x28
> +#define OMAP_DMIC_IRQENABLE_SET                0x2C
> +#define OMAP_DMIC_IRQENABLE_CLR                0x30
> +#define OMAP_DMIC_IRQWAKE_EN           0x34
> +#define OMAP_DMIC_DMAENABLE_SET                0x38
> +#define OMAP_DMIC_DMAENABLE_CLR                0x3C
> +#define OMAP_DMIC_DMAWAKEEN            0x40
> +#define OMAP_DMIC_CTRL                 0x44
> +#define OMAP_DMIC_DATA                 0x48
> +#define OMAP_DMIC_FIFO_CTRL            0x4C
> +#define OMAP_DMIC_FIFO_DMIC1R_DATA     0x50
> +#define OMAP_DMIC_FIFO_DMIC1L_DATA     0x54
> +#define OMAP_DMIC_FIFO_DMIC2R_DATA     0x58
> +#define OMAP_DMIC_FIFO_DMIC2L_DATA     0x5C
> +#define OMAP_DMIC_FIFO_DMIC3R_DATA     0x60
> +#define OMAP_DMIC_FIFO_DMIC3L_DATA     0x64
> +
> +/*

<<snip>>

> diff --git a/sound/soc/omap/omap-dmic.c b/sound/soc/omap/omap-dmic.c
> new file mode 100644
> index 0000000..06dbb99
> --- /dev/null
> +++ b/sound/soc/omap/omap-dmic.c
> @@ -0,0 +1,534 @@
> +/*
> + * omap-dmic.c  --  OMAP ASoC DMIC DAI driver
> + *
> + * Copyright (C) 2010 Texas Instruments
> + *
> + * Author: Liam Girdwood <lrg at slimlogic.co.uk>
> + *        David Lambert <dlambert at ti.com>
> + *        Misael Lopez Cruz <misael.lopez at ti.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
> + * 02110-1301 USA
> + *
> + */
> +
> +#undef DEBUG
> +
> +#include <linux/init.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/wait.h>
> +#include <linux/interrupt.h>
> +#include <linux/err.h>
> +#include <linux/clk.h>
> +#include <linux/delay.h>
> +#include <linux/io.h>
> +#include <linux/slab.h>
> +#include <linux/pm_runtime.h>
> +
> +#include <plat/control.h>
> +#include <plat/dma.h>
> +#include <plat/dmic.h>
> +#include <plat/omap_hwmod.h>

The above header file is not required in the driver

> +
> +#include <sound/core.h>
> +#include <sound/pcm.h>
> +#include <sound/pcm_params.h>
> +#include <sound/initval.h>
> +#include <sound/soc.h>
> +

<<snip>>

> +
> +static int omap_dmic_dai_trigger(struct snd_pcm_substream *substream,
> +                                 int cmd, struct snd_soc_dai *dai)
> +{
> +       struct omap_dmic *dmic = snd_soc_dai_get_drvdata(dai);
> +       int dmic_id = dmic->link->channels;
> +
> +       switch (cmd) {
> +       case SNDRV_PCM_TRIGGER_START:
> +               omap_dmic_start(dmic, dmic_id);
> +               break;
> +       case SNDRV_PCM_TRIGGER_STOP:
> +               omap_dmic_stop(dmic, dmic_id);
> +               break;
> +       default:

You may consider adding a "command not supported" warning if it would
be meaningful.

> +               break;
> +       }
> +
> +       return 0;
> +}
> +

<<snip>>

> +
> +static struct snd_soc_dai_driver omap_dmic_dai = {
> +
> +       .name = "omap-dmic-dai-0",
> +       .capture = {
> +               .channels_min = 2,
> +               .channels_max = 6,
> +               .rates = OMAP_DMIC_RATES,
> +               .formats = OMAP_DMIC_FORMATS,
> +       },
> +       .ops = &omap_dmic_dai_ops,
> +};
> +
> +static __devinit int asoc_dmic_probe(struct platform_device *pdev)
> +{
> +       struct omap_dmic *dmic;
> +       struct resource *res;
> +       int ret;
> +
> +       dmic = kzalloc(sizeof(struct omap_dmic), GFP_KERNEL);
> +       if (!dmic)
> +               return -ENOMEM;
> +
> +       platform_set_drvdata(pdev, dmic);
> +       dmic->dev = &pdev->dev;
> +       dmic->link = &omap_dmic_link;
> +       dmic->sysclk = OMAP_DMIC_SYSCLK_SYNC_MUX_CLKS;
> +
> +       spin_lock_init(&dmic->lock);
> +
> +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +       if (!res) {
> +               dev_err(dmic->dev, "invalid memory resource\n");
> +               ret = -ENODEV;
> +               goto err_res;
> +       }
> +
> +       dmic->io_base = ioremap(res->start, resource_size(res));
> +       if (!dmic->io_base) {

Print the error.

> +               ret = -ENOMEM;
> +               goto err_res;
> +       }
> +
> +       res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
> +       if (!res) {
> +               dev_err(dmic->dev, "invalid dma resource\n");
> +               ret = -ENODEV;
> +               goto err_dai;
> +       }
> +       omap_dmic_dai_dma_params.dma_req = res->start;
> +
> +       pm_runtime_enable(dmic->dev);
> +

Before accessing the below register, you should be doing a pm_runtime_get*()

> +       /* Disable lines while request is ongoing */
> +       omap_dmic_write(dmic, OMAP_DMIC_CTRL, 0x00);
> +
> +       ret = snd_soc_register_dais(&pdev->dev, &omap_dmic_dai, 1);
> +       if (ret)
> +               goto err_dai;
> +
> +       return 0;
> +
> +err_dai:
> +       iounmap(dmic->io_base);
> +err_res:
> +       kfree(dmic);
> +       return ret;
> +}
> +

<<snip>>


More information about the Alsa-devel mailing list