Tegra ALSA/ASoC driver
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
cover Tegra ALSA/ASoC driver
(My apologies; I sent this to both linux-tegra and alsa-devel mailing lists before, but posted from the wrong address, so it got dropped from the ALSA list. Here's a copy, hopefully threaded back into the same conversation as the original copy which made it to linux-tegra)
This patch series implements an ALSA/ASoC driver for Tegra, and implements minimal machine support for the Harmony reference board.
I believe I've addressed all the feedback from Mark re: the previous patchset.
Stephen Warren (7):
ASoC: Export debugfs root dentry
ASoC: tegra: Add tegra-das driver
ASoC: tegra: Add tegra-pcm driver
ASoC: tegra: Add tegra-i2s driver
ASoC: tegra: Machine utility code
ASoC: tegra: Harmony machine support
ASoC: tegra: Kconfig and Makefile
include/sound/soc.h | 4 + sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/soc-core.c | 19 +- sound/soc/tegra/Kconfig | 27 ++ sound/soc/tegra/Makefile | 14 + sound/soc/tegra/harmony.c | 179 +++++++++++++ sound/soc/tegra/tegra_asoc_utils.c | 154 +++++++++++ sound/soc/tegra/tegra_asoc_utils.h | 31 +++ sound/soc/tegra/tegra_das.c | 263 +++++++++++++++++++ sound/soc/tegra/tegra_das.h | 135 ++++++++++ sound/soc/tegra/tegra_i2s.c | 502 ++++++++++++++++++++++++++++++++++++ sound/soc/tegra/tegra_i2s.h | 165 ++++++++++++ sound/soc/tegra/tegra_pcm.c | 401 ++++++++++++++++++++++++++++ sound/soc/tegra/tegra_pcm.h | 55 ++++ 15 files changed, 1942 insertions(+), 9 deletions(-) create mode 100644 sound/soc/tegra/Kconfig create mode 100644 sound/soc/tegra/Makefile create mode 100644 sound/soc/tegra/harmony.c create mode 100644 sound/soc/tegra/tegra_asoc_utils.c create mode 100644 sound/soc/tegra/tegra_asoc_utils.h create mode 100644 sound/soc/tegra/tegra_das.c create mode 100644 sound/soc/tegra/tegra_das.h create mode 100644 sound/soc/tegra/tegra_i2s.c create mode 100644 sound/soc/tegra/tegra_i2s.h create mode 100644 sound/soc/tegra/tegra_pcm.c create mode 100644 sound/soc/tegra/tegra_pcm.h
PATCH 1/7 ASoC: Export debugfs root dentry
A couple Tegra ASoC drivers will create debugfs entries. Mark requested these by under debugfs/asoc/ not just debugfs/. To enable this, export the dentry representing debugfs/asoc/.
Also, rename debugfs_root -> asoc_debugfs_root now it's exported to prevent potential symbol name clashes.
--- include/sound/soc.h | 4 ++++ sound/soc/soc-core.c | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-)
include/sound/soc.h +4 -0
@@ -756,4 +756,8 @@ static inline void *snd_soc_pcm_get_drvdata(struct snd_soc_pcm_runtime *rtd)#include <sound/soc-dai.h> +#ifdef CONFIG_DEBUG_FS +extern struct dentry *asoc_debugfs_root; +#endif +#endif
sound/soc/soc-core.c +10 -9
@@ -48,7 +48,8 @@ static DEFINE_MUTEX(pcm_mutex);static DECLARE_WAIT_QUEUE_HEAD (soc_pm_waitq);#ifdef CONFIG_DEBUG_FS -static struct dentry *debugfs_root; +struct dentry *asoc_debugfs_root; +EXPORT_SYMBOL_GPL (asoc_debugfs_root);#endif static DEFINE_MUTEX (client_mutex);
@@ -356,7 +357,7 @@ static const struct file_operations platform_list_fops = {static void soc_init_card_debugfs (struct snd_soc_card *card) { card->debugfs_card_root =debugfs_create_dir (card->name, - debugfs_root); + asoc_debugfs_root);if (!card->debugfs_card_root) {dev_warn (card->dev,"ASoC: Failed to create codec debugfs directory\n" );
@@ -3577,22 +3578,22 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);static int __init snd_soc_init (void ) {#ifdef CONFIG_DEBUG_FS - debugfs_root =debugfs_create_dir ("asoc" ,NULL ); -if (IS_ERR (debugfs_root) || !debugfs_root) { + asoc_debugfs_root =debugfs_create_dir ("asoc" ,NULL ); +if (IS_ERR (asoc_debugfs_root) || !asoc_debugfs_root) {printk (KERN_WARNING "ASoC: Failed to create debugfs directory\n" ); - debugfs_root =NULL ; + asoc_debugfs_root =NULL ; } -if (!debugfs_create_file ("codecs" ,0444 , debugfs_root,NULL , +if (!debugfs_create_file ("codecs" ,0444 , asoc_debugfs_root,NULL , &codec_list_fops))pr_warn ("ASoC: Failed to create CODEC list debugfs file\n" ); -if (!debugfs_create_file ("dais" ,0444 , debugfs_root,NULL , +if (!debugfs_create_file ("dais" ,0444 , asoc_debugfs_root,NULL , &dai_list_fops))pr_warn ("ASoC: Failed to create DAI list debugfs file\n" ); -if (!debugfs_create_file ("platforms" ,0444 , debugfs_root,NULL , +if (!debugfs_create_file ("platforms" ,0444 , asoc_debugfs_root,NULL , &platform_list_fops))pr_warn ("ASoC: Failed to create platform list debugfs file\n" );#endif
@@ -3604,7 +3605,7 @@ module_init(snd_soc_init); static void __exit snd_soc_exit(void) {#ifdef CONFIG_DEBUG_FS -debugfs_remove_recursive (debugfs_root); +debugfs_remove_recursive (asoc_debugfs_root);#endif platform_driver_unregister (&soc_driver); }
Signature · 1 line
1.7.0.4
Re: [PATCH 1/7] ASoC: Export debugfs root dentry
Quoted 8 lines · Stephen Warren
A couple Tegra ASoC drivers will create debugfs entries. Mark requested these by under debugfs/asoc/ not just debugfs/. To enable this, export the dentry representing debugfs/asoc/.
Also, rename
debugfs_root->asoc_debugfs_rootnow it's exported to prevent potential symbol name clashes.Signed-off-by Stephen Warren <[email protected]>
This is OK but for consistency with the rest of ASoC that should be snd_soc_debugfs_root.
PATCH 2/7 ASoC: tegra: Add tegra-das driver
In reply to Stephen WarrenThe DAS (Digital Audio Switch) is a mux/crossbar which sits between the DACs (Digital Audio Controllers) and the DAPs (Digital Audio Ports). Audio data may be routed between DACs and DAPs in various combinations as required by board design/application.
--- sound/soc/tegra/tegra_das.c | 263 +++++++++++++++++++++++++++++++++++++++++++ sound/soc/tegra/tegra_das.h | 135 ++++++++++++++++++++++ 2 files changed, 398 insertions(+), 0 deletions(-) create mode 100644 sound/soc/tegra/tegra_das.c create mode 100644 sound/soc/tegra/tegra_das.h
sound/soc/tegra/tegra_das.c new file +263 -0
@@ -0,0 +1,263 @@ +/* +* tegra_das.c - Tegra DAS driver +* +* Author: Stephen Warren <[email protected]> +* Copyright (C) 2010 - NVIDIA, Inc. +* +* 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 +* +*/ + +#include <linux/module.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/platform_device.h> +#include <linux/seq_file.h> +#include <linux/slab.h> +#include <linux/io.h> +#include <mach/iomap.h> +#include <sound/soc.h> +#include "tegra_das.h" + +#define DRV_NAME "tegra-das" + +static struct tegra_das *das; + +static inline void tegra_das_write (u32 reg,u32 val) +{ +__raw_writel (val, das->regs + reg); +} + +static inline u32 tegra_das_read (u32 reg) +{ +return __raw_readl (das->regs + reg); +} + +int tegra_das_connect_dap_to_dac (int dap,int dac) +{ +u32 addr; +u32 reg; + +if (!das) +return -ENODEV ; + + addr =TEGRA_DAS_DAP_CTRL_SEL + + (dap *TEGRA_DAS_DAP_CTRL_SEL_STRIDE ); + reg = dac <<TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P ; + +tegra_das_write (addr, reg); + +return 0 ; +} +EXPORT_SYMBOL_GPL (tegra_das_connect_dap_to_dac); + +int tegra_das_connect_dap_to_dap (int dap,int otherdap,int master, +int sdata1rx,int sdata2rx) +{ +u32 addr; +u32 reg; + +if (!das) +return -ENODEV ; + + addr =TEGRA_DAS_DAP_CTRL_SEL + + (dap *TEGRA_DAS_DAP_CTRL_SEL_STRIDE ); + reg = otherdap <<TEGRA_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P | + !!sdata2rx <<TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P | + !!sdata1rx <<TEGRA_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P | + !!master <<TEGRA_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P ; + +tegra_das_write (addr, reg); + +return 0 ; +} +EXPORT_SYMBOL_GPL (tegra_das_connect_dap_to_dap); + +int tegra_das_connect_dac_to_dap (int dac,int dap) +{ +u32 addr; +u32 reg; + +if (!das) +return -ENODEV ; + + addr =TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL + + (dac *TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE ); + reg = dap <<TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P | + dap <<TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P | + dap <<TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P ; + +tegra_das_write (addr, reg); + +return 0 ; +} +EXPORT_SYMBOL_GPL (tegra_das_connect_dac_to_dap); + +#ifdef CONFIG_DEBUG_FS +static int tegra_das_show (struct seq_file *s,void *unused) +{ +int i; +u32 addr; +u32 reg; + +for (i =0 ; i <TEGRA_DAS_DAP_CTRL_SEL_COUNT ; i++) { + addr =TEGRA_DAS_DAP_CTRL_SEL + + (i *TEGRA_DAS_DAP_CTRL_SEL_STRIDE ); + reg =tegra_das_read (addr); +seq_printf (s,"TEGRA_DAS_DAP_CTRL_SEL[%d] = %08x\n" , i, reg); + } + +for (i =0 ; i <TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT ; i++) { + addr =TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL + + (i *TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE ); + reg =tegra_das_read (addr); +seq_printf (s,"TEGRA_DAS_DAC_INPUT_DATA_CLK_SEL[%d] = %08x\n" , + i, reg); + } + +return 0 ; +} + +static int tegra_das_debug_open (struct inode *inode,struct file *file) +{ +return single_open (file, tegra_das_show, inode->i_private); +} + +static const struct file_operations tegra_das_debug_fops = { + .open = tegra_das_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void tegra_das_debug_add (struct tegra_das *das) +{ + das->debug =debugfs_create_file (DRV_NAME ,S_IRUGO , asoc_debugfs_root, + das, &tegra_das_debug_fops); +} + +static void tegra_das_debug_remove (struct tegra_das *das) +{ +if (das->debug) +debugfs_remove (das->debug); +} +#else +static inline void tegra_das_debug_add (struct tegra_das *das) +{ +} + +static inline void tegra_das_debug_remove (struct tegra_das *das) +{ +} +#endif + +static int __devinit tegra_das_probe (struct platform_device *pdev) +{ +struct resource *res, *region; +int ret =0 ; + +if (das) +return -ENODEV ; + + das =kzalloc (sizeof (struct tegra_das ),GFP_KERNEL ); +if (!das) { +dev_err (&pdev->dev,"Can't allocate tegra_das\n" ); + ret = -ENOMEM ; + goto exit; + } + das->dev = &pdev->dev; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (&pdev->dev,"No memory resource\n" ); + ret = -ENODEV ; + goto err_free; + } + + region =request_mem_region (res->start,resource_size (res), + pdev->name); +if (!region) { +dev_err (&pdev->dev,"Memory region already claimed\n" ); + ret = -EBUSY ; + goto err_free; + } + + das->regs =ioremap (res->start,resource_size (res)); +if (!das->regs) { +dev_err (&pdev->dev,"ioremap failed\n" ); + ret = -ENOMEM ; + goto err_release; + } + +tegra_das_debug_add (das); + +platform_set_drvdata (pdev, das); + +return 0 ; + +err_release: +release_mem_region (res->start,resource_size (res)); +err_free: +kfree (das); + das =0 ; +exit: +return ret; +} + +static int __devexit tegra_das_remove(struct platform_device *pdev) +{ +struct resource *res; + +if (!das) +return -ENODEV ; + +platform_set_drvdata (pdev,NULL ); + +tegra_das_debug_remove (das); + +iounmap (das->regs); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +release_mem_region (res->start,resource_size (res)); + +kfree (das); + das =0 ; + +return 0 ; +} + +static struct platform_driver tegra_das_driver = { + .probe = tegra_das_probe, + .remove =__devexit_p (tegra_das_remove), + .driver = { + .name =DRV_NAME , + }, +}; + +static int __init tegra_das_modinit (void ) +{ +return platform_driver_register (&tegra_das_driver); +} +module_init (tegra_das_modinit); + +static void __exit tegra_das_modexit(void) +{ +platform_driver_unregister (&tegra_das_driver); +} +module_exit (tegra_das_modexit); + +MODULE_AUTHOR ("Stephen Warren <[email protected]>" ); +MODULE_DESCRIPTION ("Tegra DAS driver" ); +MODULE_LICENSE ("GPL" );
sound/soc/tegra/tegra_das.h new file +135 -0
135 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 3/7 ASoC: tegra: Add tegra-pcm driver
In reply to Stephen WarrenThis provides an ASoC platform driver that manages Tegra's APB DMA controller.
--- sound/soc/tegra/tegra_pcm.c | 401 +++++++++++++++++++++++++++++++++++++++++++ sound/soc/tegra/tegra_pcm.h | 55 ++++++ 2 files changed, 456 insertions(+), 0 deletions(-) create mode 100644 sound/soc/tegra/tegra_pcm.c create mode 100644 sound/soc/tegra/tegra_pcm.h
sound/soc/tegra/tegra_pcm.c new file +401 -0
@@ -0,0 +1,401 @@ +/* +* tegra_pcm.c - Tegra PCM driver +* +* Author: Stephen Warren <[email protected]> +* Copyright (C) 2010 - NVIDIA, Inc. +* +* Based on code copyright/by: +* +* Copyright (c) 2009-2010, NVIDIA Corporation. +* Scott Peterson <[email protected]> +* Vijay Mali <[email protected]> +* +* Copyright (C) 2010 Google, Inc. +* Iliyan Malchev <[email protected]> +* +* 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 +* +*/ + +#include <linux/module.h> +#include <linux/dma-mapping.h> +#include <linux/slab.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> + +#include "tegra_pcm.h" + +static const struct snd_pcm_hardware tegra_pcm_hardware = { + .info =SNDRV_PCM_INFO_MMAP | +SNDRV_PCM_INFO_MMAP_VALID | +SNDRV_PCM_INFO_PAUSE | +SNDRV_PCM_INFO_RESUME | +SNDRV_PCM_INFO_INTERLEAVED , + .formats =SNDRV_PCM_FMTBIT_S16_LE , + .channels_min =2 , + .channels_max =2 , + .period_bytes_min =1024 , + .period_bytes_max =PAGE_SIZE , + .periods_min =2 , + .periods_max =8 , + .buffer_bytes_max =PAGE_SIZE *8 , + .fifo_size =4 , +}; + +static void tegra_pcm_queue_dma (struct tegra_runtime_data *prtd) +{ +struct snd_pcm_substream *substream = prtd->substream; +struct snd_dma_buffer *buf = &substream->dma_buffer; +struct tegra_dma_req *dma_req; +unsigned long addr; + + dma_req = &prtd->dma_req[prtd->dma_req_idx]; + prtd->dma_req_idx =1 - prtd->dma_req_idx; + + addr = buf->addr + prtd->dma_pos; + prtd->dma_pos += dma_req->size; +if (prtd->dma_pos >= prtd->dma_pos_end) + prtd->dma_pos =0 ; + +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) + dma_req->source_addr = addr; +else + dma_req->dest_addr = addr; + +tegra_dma_enqueue_req (prtd->dma_chan, dma_req); +} + +static void dma_complete_callback (struct tegra_dma_req *req) +{ +struct tegra_runtime_data *prtd = (struct tegra_runtime_data *)req->dev; +struct snd_pcm_substream *substream = prtd->substream; +struct snd_pcm_runtime *runtime = substream->runtime; + +spin_lock (&prtd->lock); + +if (!prtd->running) { +spin_unlock (&prtd->lock); +return ; + } + +if (++prtd->period_index >= runtime->periods) + prtd->period_index =0 ; + +tegra_pcm_queue_dma (prtd); + +spin_unlock (&prtd->lock); + +snd_pcm_period_elapsed (substream); +} + +static void setup_dma_tx_request (struct tegra_dma_req *req, +struct tegra_pcm_dma_params * dmap) +{ + req->complete = dma_complete_callback; + req->to_memory = false; + req->dest_addr = dmap->addr; + req->dest_wrap = dmap->wrap; + req->source_bus_width =32 ; + req->source_wrap =0 ; + req->dest_bus_width = dmap->width; + req->req_sel = dmap->req_sel; +} + +static void setup_dma_rx_request (struct tegra_dma_req *req, +struct tegra_pcm_dma_params * dmap) +{ + req->complete = dma_complete_callback; + req->to_memory = true; + req->source_addr = dmap->addr; + req->dest_wrap =0 ; + req->source_bus_width = dmap->width; + req->source_wrap = dmap->wrap; + req->dest_bus_width =32 ; + req->req_sel = dmap->req_sel; +} + +static int tegra_pcm_open (struct snd_pcm_substream *substream) +{ +struct snd_pcm_runtime *runtime = substream->runtime; +struct tegra_runtime_data *prtd; +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct tegra_pcm_dma_params * dmap; +int ret =0 ; + + prtd =kzalloc (sizeof (struct tegra_runtime_data ),GFP_KERNEL ); +if (prtd ==NULL ) +return -ENOMEM ; + + runtime->private_data = prtd; + prtd->substream = substream; + +spin_lock_init (&prtd->lock); + +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { + dmap =snd_soc_dai_get_dma_data (rtd->cpu_dai, substream); +setup_dma_tx_request (&prtd->dma_req[0 ], dmap); +setup_dma_tx_request (&prtd->dma_req[1 ], dmap); + }else { + dmap =snd_soc_dai_get_dma_data (rtd->cpu_dai, substream); +setup_dma_rx_request (&prtd->dma_req[0 ], dmap); +setup_dma_rx_request (&prtd->dma_req[1 ], dmap); + } + + prtd->dma_req[0 ].dev = prtd; + prtd->dma_req[1 ].dev = prtd; + + prtd->dma_chan =tegra_dma_allocate_channel (TEGRA_DMA_MODE_ONESHOT ); +if (IS_ERR (prtd->dma_chan)) { + ret =PTR_ERR (prtd->dma_chan); + goto err; + } + +/* Set HW params now that initialization is complete */ +snd_soc_set_runtime_hwparams (substream, &tegra_pcm_hardware); + +/* Ensure that buffer size is a multiple of period size */ + ret =snd_pcm_hw_constraint_integer (runtime, +SNDRV_PCM_HW_PARAM_PERIODS ); +if (ret <0 ) + goto err; + +return 0 ; + +err: +if (prtd->dma_chan) { +tegra_dma_free_channel (prtd->dma_chan); + } + +kfree (prtd); + +return ret; +} + +static int tegra_pcm_close (struct snd_pcm_substream *substream) +{ +struct snd_pcm_runtime *runtime = substream->runtime; +struct tegra_runtime_data *prtd = runtime->private_data; + +tegra_dma_free_channel (prtd->dma_chan); + +kfree (prtd); + +return 0 ; +} + +static int tegra_pcm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_pcm_runtime *runtime = substream->runtime; +struct tegra_runtime_data *prtd = runtime->private_data; + +snd_pcm_set_runtime_buffer (substream, &substream->dma_buffer); + + prtd->dma_req[0 ].size =params_period_bytes (params); + prtd->dma_req[1 ].size = prtd->dma_req[0 ].size; + +return 0 ; +} + +static int tegra_pcm_hw_free (struct snd_pcm_substream *substream) +{ +snd_pcm_set_runtime_buffer (substream,NULL ); + +return 0 ; +} + +static int tegra_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +struct snd_pcm_runtime *runtime = substream->runtime; +struct tegra_runtime_data *prtd = runtime->private_data; +unsigned long flags; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : + prtd->dma_pos =0 ; + prtd->dma_pos_end =frames_to_bytes (runtime, runtime->periods * runtime->period_size); + prtd->period_index =0 ; + prtd->dma_req_idx =0 ; +/* Fall-through */ +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +spin_lock_irqsave (&prtd->lock, flags); + prtd->running =1 ; +spin_unlock_irqrestore (&prtd->lock, flags); +tegra_pcm_queue_dma (prtd); +tegra_pcm_queue_dma (prtd); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : +spin_lock_irqsave (&prtd->lock, flags); + prtd->running =0 ; +spin_unlock_irqrestore (&prtd->lock, flags); +tegra_dma_dequeue_req (prtd->dma_chan, &prtd->dma_req[0 ]); +tegra_dma_dequeue_req (prtd->dma_chan, &prtd->dma_req[1 ]); +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static snd_pcm_uframes_t tegra_pcm_pointer (struct snd_pcm_substream *substream) +{ +struct snd_pcm_runtime *runtime = substream->runtime; +struct tegra_runtime_data *prtd = runtime->private_data; + +return prtd->period_index * runtime->period_size; +} + + +static int tegra_pcm_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 tegra_pcm_ops = { + .open = tegra_pcm_open, + .close = tegra_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = tegra_pcm_hw_params, + .hw_free = tegra_pcm_hw_free, + .trigger = tegra_pcm_trigger, + .pointer = tegra_pcm_pointer, + .mmap = tegra_pcm_mmap, +}; + +static int tegra_pcm_preallocate_dma_buffer (struct snd_pcm *pcm,int stream) +{ +struct snd_pcm_substream *substream = pcm->streams[stream].substream; +struct snd_dma_buffer *buf = &substream->dma_buffer; +size_t size = tegra_pcm_hardware.buffer_bytes_max; + + buf->area =dma_alloc_writecombine (pcm->card->dev, size, + &buf->addr,GFP_KERNEL ); +if (!buf->area) +return -ENOMEM ; + + buf->dev.type =SNDRV_DMA_TYPE_DEV ; + buf->dev.dev = pcm->card->dev; + buf->private_data =NULL ; + buf->bytes = size; + +return 0 ; +} + +static void tegra_pcm_deallocate_dma_buffer (struct snd_pcm *pcm,int stream) +{ +struct snd_pcm_substream *substream = pcm->streams[stream].substream; +struct snd_dma_buffer *buf = &substream->dma_buffer; + +if (!buf->area) +return ; + +dma_free_writecombine (pcm->card->dev, buf->bytes, + buf->area, buf->addr); + buf->area =NULL ; +} + +static u64 tegra_dma_mask =DMA_BIT_MASK (32 ); + +static int tegra_pcm_new (struct snd_card *card, +struct snd_soc_dai *dai,struct snd_pcm *pcm) +{ +int ret =0 ; + +if (!card->dev->dma_mask) + card->dev->dma_mask = &tegra_dma_mask; +if (!card->dev->coherent_dma_mask) + card->dev->coherent_dma_mask =0xffffffff ; + +if (dai->driver->playback.channels_min) { + ret =tegra_pcm_preallocate_dma_buffer (pcm, +SNDRV_PCM_STREAM_PLAYBACK ); +if (ret) + goto err; + } + +if (dai->driver->capture.channels_min) { + ret =tegra_pcm_preallocate_dma_buffer (pcm, +SNDRV_PCM_STREAM_CAPTURE ); +if (ret) + goto err_free_play; + } + +return 0 ; + +err_free_play: +tegra_pcm_deallocate_dma_buffer (pcm,SNDRV_PCM_STREAM_PLAYBACK ); +err: +return ret; +} + +static void tegra_pcm_free (struct snd_pcm *pcm) +{ +tegra_pcm_deallocate_dma_buffer (pcm,SNDRV_PCM_STREAM_CAPTURE ); +tegra_pcm_deallocate_dma_buffer (pcm,SNDRV_PCM_STREAM_PLAYBACK ); +} + +struct snd_soc_platform_driver tegra_pcm_platform = { + .ops = &tegra_pcm_ops, + .pcm_new = tegra_pcm_new, + .pcm_free = tegra_pcm_free, +}; + +static int __devinit tegra_pcm_platform_probe (struct platform_device *pdev) +{ +return snd_soc_register_platform (&pdev->dev, &tegra_pcm_platform); +} + +static int __devexit tegra_pcm_platform_remove(struct platform_device *pdev) +{ +snd_soc_unregister_platform (&pdev->dev); +return 0 ; +} + +static struct platform_driver tegra_pcm_driver = { + .driver = { + .name ="tegra-pcm-audio" , + .owner =THIS_MODULE , + }, + .probe = tegra_pcm_platform_probe, + .remove =__devexit_p (tegra_pcm_platform_remove), +}; + +static int __init snd_tegra_pcm_init (void ) +{ +return platform_driver_register (&tegra_pcm_driver); +} +module_init (snd_tegra_pcm_init); + +static void __exit snd_tegra_pcm_exit(void) +{ +platform_driver_unregister (&tegra_pcm_driver); +} +module_exit (snd_tegra_pcm_exit); + +MODULE_AUTHOR ("Stephen Warren <[email protected]>" ); +MODULE_DESCRIPTION ("Tegra PCM ASoC driver" ); +MODULE_LICENSE ("GPL" );
sound/soc/tegra/tegra_pcm.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH 3/7] ASoC: tegra: Add tegra-pcm driver
Quoted 12 lines · ext Stephen Warren
This provides an ASoC platform driver that manages Tegra's APB DMA controller.
Signed-off-by Stephen Warren <[email protected]>--- sound/soc/tegra/tegra_pcm.c | 401 +++++++++++++++++++++++++++++++++++++++++++ sound/soc/tegra/tegra_pcm.h | 55 ++++++ 2 files changed, 456 insertions(+), 0 deletions(-) create mode 100644 sound/soc/tegra/tegra_pcm.c create mode 100644 sound/soc/tegra/tegra_pcm.hsound/soc/tegra/tegra_pcm.c +0
-0
...
Quoted 13 lines
sound/soc/tegra/tegra_pcm.c +13
-0+switch (cmd) { +case SNDRV_PCM_TRIGGER_START : + prtd->dma_pos =0 ; + prtd->dma_pos_end =frames_to_bytes (runtime, runtime->periods * runtime->period_size); + prtd->period_index =0 ; + prtd->dma_req_idx =0 ; +/* Fall-through */ +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +spin_lock_irqsave (&prtd->lock, flags); + prtd->running =1 ; +spin_unlock_irqrestore (&prtd->lock, flags); +tegra_pcm_queue_dma (prtd);
sound/soc/tegra/tegra_pcm.c line 249
Quoted 10 lines
sound/soc/tegra/tegra_pcm.c +10
-0+tegra_pcm_queue_dma (prtd); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : +spin_lock_irqsave (&prtd->lock, flags); + prtd->running =0 ; +spin_unlock_irqrestore (&prtd->lock, flags); +tegra_dma_dequeue_req (prtd->dma_chan, &prtd->dma_req[0 ]); +tegra_dma_dequeue_req (prtd->dma_chan, &prtd->dma_req[1 ]);
Does tegra_dma_dequeue_req stops the ongoing DMA transaction as well? If I read the code right, you have two DMA requests placed at every given time (one is currently running, the other is waiting). What happens if the dma_req[0] was running, and you dequeue it? Will the DMA engine moves to process the dma_req[1], which will be stopped a moment later?
Signature · 1 line
Péter
Re: [PATCH 3/7] ASoC: tegra: Add tegra-pcm driver
Quoted 8 lines · Peter Ujfalusi
Quoted 1 line · ext Stephen Warren
sound/soc/tegra/tegra_pcm.c +0
-0...
Quoted 2 lines
sound/soc/tegra/tegra_pcm.c +2
-0+switch (cmd) { +case SNDRV_PCM_TRIGGER_START :
...
Quoted 17 lines
Quoted 6 lines
sound/soc/tegra/tegra_pcm.c +6
-0+case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +spin_lock_irqsave (&prtd->lock, flags); + prtd->running =1 ; +spin_unlock_irqrestore (&prtd->lock, flags); +tegra_pcm_queue_dma (prtd);sound/soc/tegra/tegra_pcm.c line 249
Quoted 10 lines
sound/soc/tegra/tegra_pcm.c +10
-0+tegra_pcm_queue_dma (prtd); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : +spin_lock_irqsave (&prtd->lock, flags); + prtd->running =0 ; +spin_unlock_irqrestore (&prtd->lock, flags); +tegra_dma_dequeue_req (prtd->dma_chan, &prtd->dma_req[0 ]); +tegra_dma_dequeue_req (prtd->dma_chan, &prtd->dma_req[1 ]);
Quoted 6 lines
Does
tegra_dma_dequeue_reqstops the ongoing DMA transaction as well? If I read the code right, you have two DMA requests placed at every given time (one is currently running, the other is waiting). What happens if the dma_req[0] was running, and you dequeue it? Will the DMA engine moves to process the dma_req[1], which will be stopped a moment later?
Yes, that's my understanding.
The DMA driver internally implements tegra_dma_cancel(), which may be a better thing to use in the long run (simply disables the DMA engine, and drops everything from the queue without running any completion callbacks). However, that's not publicly exposed in the header right now; I was going to investigate why first before trying to use it.
Signature · 1 line
nvpublic
PATCH 4/7 ASoC: tegra: Add tegra-i2s driver
In reply to Stephen WarrenThis provides an ASoC DAI interface for Tegra's I2S controller.
--- sound/soc/tegra/tegra_i2s.c | 502 +++++++++++++++++++++++++++++++++++++++++++ sound/soc/tegra/tegra_i2s.h | 165 ++++++++++++++ 2 files changed, 667 insertions(+), 0 deletions(-) create mode 100644 sound/soc/tegra/tegra_i2s.c create mode 100644 sound/soc/tegra/tegra_i2s.h
sound/soc/tegra/tegra_i2s.c new file +502 -0
@@ -0,0 +1,502 @@ +/* +* tegra_i2s.c - Tegra I2S driver +* +* Author: Stephen Warren <[email protected]> +* Copyright (C) 2010 - NVIDIA, Inc. +* +* Based on code copyright/by: +* +* Copyright (c) 2009-2010, NVIDIA Corporation. +* Scott Peterson <[email protected]> +* +* Copyright (C) 2010 Google, Inc. +* Iliyan Malchev <[email protected]> +* +* 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 +* +*/ + +#include <linux/clk.h> +#include <linux/module.h> +#include <linux/debugfs.h> +#include <linux/device.h> +#include <linux/platform_device.h> +#include <linux/seq_file.h> +#include <linux/slab.h> +#include <linux/io.h> +#include <mach/iomap.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> + +#include "tegra_das.h" +#include "tegra_i2s.h" + +#define DRV_NAME "tegra-i2s" + +static inline void tegra_i2s_write (struct tegra_i2s *i2s,u32 reg,u32 val) +{ +__raw_writel (val, i2s->regs + reg); +} + +static inline u32 tegra_i2s_read (struct tegra_i2s *i2s,u32 reg) +{ +return __raw_readl (i2s->regs + reg); +} + +#ifdef CONFIG_DEBUG_FS +static int tegra_i2s_show (struct seq_file *s,void *unused) +{ +#define REG (r) { r, #r } +static const struct { +int offset; +const char *name; + } regs[] = { +REG (TEGRA_I2S_CTRL ), +REG (TEGRA_I2S_STATUS ), +REG (TEGRA_I2S_TIMING ), +REG (TEGRA_I2S_FIFO_SCR ), +REG (TEGRA_I2S_PCM_CTRL ), +REG (TEGRA_I2S_NW_CTRL ), +REG (TEGRA_I2S_TDM_CTRL ), +REG (TEGRA_I2S_TDM_TX_RX_CTRL ), + }; +#undef REG + +struct tegra_i2s *i2s = s->private; +int i; + +for (i =0 ; i <ARRAY_SIZE (regs); i++) { +u32 val =tegra_i2s_read (i2s, regs[i].offset); +seq_printf (s,"%s = %08x\n" , regs[i].name, val); + } + +return 0 ; +} + +static int tegra_i2s_debug_open (struct inode *inode,struct file *file) +{ +return single_open (file, tegra_i2s_show, inode->i_private); +} + +static const struct file_operations tegra_i2s_debug_fops = { + .open = tegra_i2s_debug_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void tegra_i2s_debug_add (struct tegra_i2s *i2s,int id) +{ +char name[] =DRV_NAME ".0" ; + +snprintf (name,sizeof (name),DRV_NAME ".%1d" , id); + i2s->debug =debugfs_create_file (name,S_IRUGO , asoc_debugfs_root, + i2s, &tegra_i2s_debug_fops); +} + +static void tegra_i2s_debug_remove (struct tegra_i2s *i2s) +{ +if (i2s->debug) +debugfs_remove (i2s->debug); +} +#else +static inline void tegra_i2s_debug_add (struct tegra_i2s *i2s) +{ +} + +static inline void tegra_i2s_debug_remove (struct tegra_i2s *i2s) +{ +} +#endif + +static int tegra_i2s_set_fmt (struct snd_soc_dai *dai, +unsigned int fmt) +{ +struct tegra_i2s *i2s =snd_soc_dai_get_drvdata (dai); + +switch (fmt &SND_SOC_DAIFMT_INV_MASK ) { +case SND_SOC_DAIFMT_NB_NF : +break ; +default : +return -EINVAL ; + } + + i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_MASTER_ENABLE ; +switch (fmt &SND_SOC_DAIFMT_MASTER_MASK ) { +case SND_SOC_DAIFMT_CBS_CFS : + i2s->reg_ctrl |=TEGRA_I2S_CTRL_MASTER_ENABLE ; +break ; +case SND_SOC_DAIFMT_CBM_CFM : +break ; +default : +return -EINVAL ; + } + + i2s->reg_ctrl &= ~(TEGRA_I2S_CTRL_BIT_FORMAT_MASK | +TEGRA_I2S_CTRL_LRCK_MASK ); +switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) { +case SND_SOC_DAIFMT_DSP_A : + i2s->reg_ctrl |=TEGRA_I2S_CTRL_BIT_FORMAT_DSP ; + i2s->reg_ctrl |=TEGRA_I2S_CTRL_LRCK_L_LOW ; +break ; +case SND_SOC_DAIFMT_DSP_B : + i2s->reg_ctrl |=TEGRA_I2S_CTRL_BIT_FORMAT_DSP ; + i2s->reg_ctrl |=TEGRA_I2S_CTRL_LRCK_R_LOW ; +break ; +case SND_SOC_DAIFMT_I2S : + i2s->reg_ctrl |=TEGRA_I2S_CTRL_BIT_FORMAT_I2S ; + i2s->reg_ctrl |=TEGRA_I2S_CTRL_LRCK_L_LOW ; +break ; +case SND_SOC_DAIFMT_RIGHT_J : + i2s->reg_ctrl |=TEGRA_I2S_CTRL_BIT_FORMAT_RJM ; + i2s->reg_ctrl |=TEGRA_I2S_CTRL_LRCK_L_LOW ; +break ; +case SND_SOC_DAIFMT_LEFT_J : + i2s->reg_ctrl |=TEGRA_I2S_CTRL_BIT_FORMAT_LJM ; + i2s->reg_ctrl |=TEGRA_I2S_CTRL_LRCK_L_LOW ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int tegra_i2s_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +struct device *dev = substream->pcm->card->dev; +struct tegra_i2s *i2s =snd_soc_dai_get_drvdata (dai); +u32 reg; +int ret, sample_size, srate, i2sclock, bitcnt; + + i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_BIT_SIZE_MASK ; +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : + i2s->reg_ctrl |=TEGRA_I2S_CTRL_BIT_SIZE_16 ; + sample_size =16 ; +break ; +case SNDRV_PCM_FORMAT_S24_LE : + i2s->reg_ctrl |=TEGRA_I2S_CTRL_BIT_SIZE_24 ; + sample_size =24 ; +break ; +case SNDRV_PCM_FORMAT_S32_LE : + i2s->reg_ctrl |=TEGRA_I2S_CTRL_BIT_SIZE_32 ; + sample_size =32 ; +break ; +default : +return -EINVAL ; + } + + srate =params_rate (params); + +/* Final "* 2" required by Tegra hardware */ + i2sclock = srate *params_channels (params) * sample_size *2 ; + + ret =clk_set_rate (i2s->clk_i2s, i2sclock); +if (ret) { +dev_err (dev,"Can't set I2S clock rate: %d\n" , ret); +return ret; + } + + bitcnt = (i2sclock / (2 * srate)) -1 ; +if (bitcnt <0 || bitcnt >TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US ) +return -EINVAL ; + reg = bitcnt <<TEGRA_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT ; + +if (i2sclock % (2 * srate)) + reg |=TEGRA_I2S_TIMING_NON_SYM_ENABLE ; + +tegra_i2s_write (i2s,TEGRA_I2S_TIMING , reg); + +tegra_i2s_write (i2s,TEGRA_I2S_FIFO_SCR , +TEGRA_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS | +TEGRA_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS ); + +return 0 ; +} + +static void tegra_i2s_start_playback (struct tegra_i2s *i2s) +{ + i2s->reg_ctrl |=TEGRA_I2S_CTRL_FIFO1_ENABLE ; +tegra_i2s_write (i2s,TEGRA_I2S_CTRL , i2s->reg_ctrl); +} + +static void tegra_i2s_stop_playback (struct tegra_i2s *i2s) +{ + i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_FIFO1_ENABLE ; +tegra_i2s_write (i2s,TEGRA_I2S_CTRL , i2s->reg_ctrl); +} + +static void tegra_i2s_start_capture (struct tegra_i2s *i2s) +{ + i2s->reg_ctrl |=TEGRA_I2S_CTRL_FIFO2_ENABLE ; +tegra_i2s_write (i2s,TEGRA_I2S_CTRL , i2s->reg_ctrl); +} + +static void tegra_i2s_stop_capture (struct tegra_i2s *i2s) +{ + i2s->reg_ctrl &= ~TEGRA_I2S_CTRL_FIFO2_ENABLE ; +tegra_i2s_write (i2s,TEGRA_I2S_CTRL , i2s->reg_ctrl); +} + +static int tegra_i2s_trigger (struct snd_pcm_substream *substream,int cmd, +struct snd_soc_dai *dai) +{ +struct tegra_i2s *i2s =snd_soc_dai_get_drvdata (dai); + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +case SNDRV_PCM_TRIGGER_RESUME : +if (!i2s->clk_refs) +clk_enable (i2s->clk_i2s); + i2s->clk_refs++; +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) +tegra_i2s_start_playback (i2s); +else +tegra_i2s_start_capture (i2s); +break ; +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : +case SNDRV_PCM_TRIGGER_SUSPEND : +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) +tegra_i2s_stop_playback (i2s); +else +tegra_i2s_stop_capture (i2s); + i2s->clk_refs--; +if (!i2s->clk_refs) +clk_disable (i2s->clk_i2s); +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +static int tegra_i2s_probe (struct snd_soc_dai *dai) +{ +struct tegra_i2s * i2s =snd_soc_dai_get_drvdata (dai); + + dai->capture_dma_data = &i2s->capture_dma_data; + dai->playback_dma_data = &i2s->playback_dma_data; + +return 0 ; +} + +static struct snd_soc_dai_ops tegra_i2s_dai_ops = { + .set_fmt = tegra_i2s_set_fmt, + .hw_params = tegra_i2s_hw_params, + .trigger = tegra_i2s_trigger, +}; + +struct snd_soc_dai_driver tegra_i2s_dai[] = { + { + .name =DRV_NAME ".0" , + .probe = tegra_i2s_probe, + .playback = { + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_8000_96000 , + .formats =SNDRV_PCM_FMTBIT_S16_LE , + }, + .capture = { + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_8000_96000 , + .formats =SNDRV_PCM_FMTBIT_S16_LE , + }, + .ops = &tegra_i2s_dai_ops, + .symmetric_rates =1 , + }, + { + .name =DRV_NAME ".1" , + .probe = tegra_i2s_probe, + .playback = { + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_8000_96000 , + .formats =SNDRV_PCM_FMTBIT_S16_LE , + }, + .capture = { + .channels_min =2 , + .channels_max =2 , + .rates =SNDRV_PCM_RATE_8000_96000 , + .formats =SNDRV_PCM_FMTBIT_S16_LE , + }, + .ops = &tegra_i2s_dai_ops, + .symmetric_rates =1 , + }, +}; + +static __devinit int tegra_i2s_platform_probe (struct platform_device *pdev) +{ +struct tegra_i2s * i2s; +char clk_name[12 ];/* tegra-i2s.0 */ +struct resource *mem, *memregion, *dmareq; +int ret; + +if ((pdev->id <0 ) || + (pdev->id >=ARRAY_SIZE (tegra_i2s_dai))) { +dev_err (&pdev->dev,"ID %d out of range\n" , pdev->id); +return -EINVAL ; + } + +/* +* FIXME: Until a codec driver exists for the tegra DAS, hard-code a +* 1:1 mapping between audio controllers and audio ports. +*/ + ret =tegra_das_connect_dap_to_dac (TEGRA_DAS_DAP_ID_1 + pdev->id, +TEGRA_DAS_DAP_SEL_DAC1 + pdev->id); +if (ret) { +dev_err (&pdev->dev,"Can't set up DAP connection\n" ); +return ret; + } + ret =tegra_das_connect_dac_to_dap (TEGRA_DAS_DAC_ID_1 + pdev->id, +TEGRA_DAS_DAC_SEL_DAP1 + pdev->id); +if (ret) { +dev_err (&pdev->dev,"Can't set up DAC connection\n" ); +return ret; + } + + i2s =kzalloc (sizeof (struct tegra_i2s ),GFP_KERNEL ); +if (!i2s) { +dev_err (&pdev->dev,"Can't allocate tegra_i2s\n" ); + ret = -ENOMEM ; + goto exit; + } +dev_set_drvdata (&pdev->dev, i2s); + +snprintf (clk_name,sizeof (clk_name),DRV_NAME ".%d" , pdev->id); + i2s->clk_i2s =clk_get_sys (clk_name,NULL ); +if (IS_ERR_OR_NULL (i2s->clk_i2s)) { +pr_err ("Can't retrieve i2s clock\n" ); + ret =PTR_ERR (i2s->clk_i2s); + goto err_free; + } + + mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!mem) { +dev_err (&pdev->dev,"No memory resource\n" ); + ret = -ENODEV ; + goto err_clk_put; + } + + dmareq =platform_get_resource (pdev,IORESOURCE_DMA ,0 ); +if (!dmareq) { +dev_err (&pdev->dev,"No DMA resource\n" ); + ret = -ENODEV ; + goto err_clk_put; + } + + memregion =request_mem_region (mem->start,resource_size (mem), +DRV_NAME ); +if (!memregion) { +dev_err (&pdev->dev,"Memory region already claimed\n" ); + ret = -EBUSY ; + goto err_clk_put; + } + + i2s->regs =ioremap (mem->start,resource_size (mem)); +if (!i2s->regs) { +dev_err (&pdev->dev,"ioremap failed\n" ); + ret = -ENOMEM ; + goto err_release; + } + + i2s->capture_dma_data.addr = mem->start +TEGRA_I2S_FIFO2 ; + i2s->capture_dma_data.wrap =4 ; + i2s->capture_dma_data.width =32 ; + i2s->capture_dma_data.req_sel = dmareq->start; + + i2s->playback_dma_data.addr = mem->start +TEGRA_I2S_FIFO1 ; + i2s->playback_dma_data.wrap =4 ; + i2s->playback_dma_data.width =32 ; + i2s->playback_dma_data.req_sel = dmareq->start; + + i2s->reg_ctrl =TEGRA_I2S_CTRL_FIFO_FORMAT_PACKED ; + + ret =snd_soc_register_dai (&pdev->dev, &tegra_i2s_dai[pdev->id]); +if (ret) { +dev_err (&pdev->dev,"Could not register DAI: %d\n" , ret); + ret = -ENOMEM ; + goto err_unmap; + } + +tegra_i2s_debug_add (i2s, pdev->id); + +return 0 ; + +err_unmap: +iounmap (i2s->regs); +err_release: +release_mem_region (mem->start,resource_size (mem)); +err_clk_put: +clk_put (i2s->clk_i2s); +err_free: +kfree (i2s); +exit: +return ret; +} + +static int __devexit tegra_i2s_platform_remove(struct platform_device *pdev) +{ +struct tegra_i2s *i2s =dev_get_drvdata (&pdev->dev); +struct resource *res; + +snd_soc_unregister_dai (&pdev->dev); + +tegra_i2s_debug_remove (i2s); + +iounmap (i2s->regs); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +release_mem_region (res->start,resource_size (res)); + +clk_put (i2s->clk_i2s); + +kfree (i2s); + +return 0 ; +} + +static struct platform_driver tegra_i2s_driver = { + .driver = { + .name =DRV_NAME , + .owner =THIS_MODULE , + }, + .probe = tegra_i2s_platform_probe, + .remove =__devexit_p (tegra_i2s_platform_remove), +}; + +static int __init snd_tegra_i2s_init (void ) +{ +return platform_driver_register (&tegra_i2s_driver); +} +module_init (snd_tegra_i2s_init); + +static void __exit snd_tegra_i2s_exit(void) +{ +platform_driver_unregister (&tegra_i2s_driver); +} +module_exit (snd_tegra_i2s_exit); + +MODULE_AUTHOR ("Stephen Warren <[email protected]>" ); +MODULE_DESCRIPTION ("Tegra I2S ASoC driver" ); +MODULE_LICENSE ("GPL" );
sound/soc/tegra/tegra_i2s.h new file +165 -0
165 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 5/7 ASoC: tegra: Machine utility code
In reply to Stephen WarrenMany portions of Tegra ASoC machine drivers will be similar or identical. To avoid cut/paste, this file will act as a repository for all that common code. For now, it solely includes code to reprogram the audio PLL for 44.1KHz- vs. 48KHz-based sample rates.
--- sound/soc/tegra/tegra_asoc_utils.c | 154 ++++++++++++++++++++++++++++++++++++ sound/soc/tegra/tegra_asoc_utils.h | 31 +++++++ 2 files changed, 185 insertions(+), 0 deletions(-) create mode 100644 sound/soc/tegra/tegra_asoc_utils.c create mode 100644 sound/soc/tegra/tegra_asoc_utils.h
sound/soc/tegra/tegra_asoc_utils.c new file +154 -0
@@ -0,0 +1,154 @@ +/* +* tegra_asoc_utils.c - Harmony machine ASoC driver +* +* Author: Stephen Warren <[email protected]> +* Copyright (C) 2010 - NVIDIA, Inc. +* +* 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 +* +*/ + +#include <linux/clk.h> +#include <linux/err.h> +#include <linux/kernel.h> + +#include "tegra_asoc_utils.h" + +#define PREFIX "ASoC Tegra: " + +static struct clk *clk_pll_a; +static struct clk *clk_pll_a_out0; +static struct clk *clk_cdev1; + +static int set_baseclock, set_mclk; + +int tegra_asoc_utils_set_rate (int srate,int mclk,int *mclk_change) +{ +int new_baseclock; +int err; + +switch (srate) { +case 11025 : +case 22050 : +case 44100 : +case 88200 : + new_baseclock =56448000 ; +break ; +case 8000 : +case 16000 : +case 32000 : +case 48000 : +case 64000 : +case 96000 : + new_baseclock =73728000 ; +break ; +default : +return -EINVAL ; + } + + *mclk_change = ((new_baseclock != set_baseclock) || + (mclk != set_mclk)); +if (!*mclk_change) +return 0 ; + + set_baseclock =0 ; + set_mclk =0 ; + +clk_disable (clk_cdev1); +clk_disable (clk_pll_a_out0); +clk_disable (clk_pll_a); + + err =clk_set_rate (clk_pll_a, new_baseclock); +if (err) { +pr_err (PREFIX "Can't set pll_a rate: %d\n" , err); +return err; + } + + err =clk_set_rate (clk_pll_a_out0, mclk); +if (err) { +pr_err (PREFIX "Can't set pll_a_out0 rate: %d\n" , err); +return err; + } + +/* Don't set cdev1 rate; its locked to pll_a_out0 */ + + err =clk_enable (clk_pll_a); +if (err) { +pr_err (PREFIX "Can't enable pll_a: %d\n" , err); +return err; + } + + err =clk_enable (clk_pll_a_out0); +if (err) { +pr_err (PREFIX "Can't enable pll_a_out0: %d\n" , err); +return err; + } + + err =clk_enable (clk_cdev1); +if (err) { +pr_err (PREFIX "Can't enable cdev1: %d\n" , err); +return err; + } + + set_baseclock = new_baseclock; + set_mclk = mclk; + +return 0 ; +} + +int tegra_asoc_utils_init (void ) +{ +int ret; + + clk_pll_a =clk_get_sys (NULL ,"pll_a" ); +if (IS_ERR_OR_NULL (clk_pll_a)) { +pr_err (PREFIX "Can't retrieve clk pll_a\n" ); + ret =PTR_ERR (clk_pll_a); + goto err; + } + + clk_pll_a_out0 =clk_get_sys (NULL ,"pll_a_out0" ); +if (IS_ERR_OR_NULL (clk_pll_a_out0)) { +pr_err (PREFIX "Can't retrieve clk pll_a_out0\n" ); + ret =PTR_ERR (clk_pll_a_out0); + goto err; + } + + clk_cdev1 =clk_get_sys (NULL ,"cdev1" ); +if (IS_ERR_OR_NULL (clk_cdev1)) { +pr_err (PREFIX "Can't retrieve clk cdev1\n" ); + ret =PTR_ERR (clk_cdev1); + goto err; + } + +return 0 ; + +err: +if (!IS_ERR_OR_NULL (clk_cdev1)) +clk_put (clk_cdev1); +if (!IS_ERR_OR_NULL (clk_pll_a_out0)) +clk_put (clk_pll_a_out0); +if (!IS_ERR_OR_NULL (clk_pll_a)) +clk_put (clk_pll_a); +return ret; +} + +void tegra_asoc_utils_fini (void ) +{ +clk_put (clk_cdev1); +clk_put (clk_pll_a_out0); +clk_put (clk_pll_a); +} +
sound/soc/tegra/tegra_asoc_utils.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* tegra_asoc_utils.h - Definitions for Tegra DAS driver +* +* Author: Stephen Warren <[email protected]> +* Copyright (C) 2010 - NVIDIA, Inc. +* +* 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 +* +*/ + +#ifndef __TEGRA_ASOC_UTILS_H__ +#define __TEGRA_ASOC_UTILS_H_ + +int tegra_asoc_utils_set_rate (int srate,int mclk_rate,int *mclk_change); +int tegra_asoc_utils_init (void ); +void tegra_asoc_utils_fini (void ); + +#endif +
Signature · 1 line
1.7.0.4
PATCH 6/7 ASoC: tegra: Harmony machine support
In reply to Stephen Warren--- sound/soc/tegra/harmony.c | 179 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 179 insertions(+), 0 deletions(-) create mode 100644 sound/soc/tegra/harmony.c
sound/soc/tegra/harmony.c new file +179 -0
@@ -0,0 +1,179 @@ +/* +* harmony.c - Harmony machine ASoC driver +* +* Author: Stephen Warren <[email protected]> +* Copyright (C) 2010 - NVIDIA, Inc. +* +* Based on code copyright/by: +* +* (c) 2009, 2010 Nvidia Graphics Pvt. Ltd. +* +* Copyright 2007 Wolfson Microelectronics PLC. +* Author: Graeme Gregory +* [email protected] or [email protected] +* +* 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 +* +*/ + +#include <asm/mach-types.h> +#include <linux/module.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> + +#include "tegra_das.h" +#include "tegra_i2s.h" +#include "tegra_pcm.h" +#include "tegra_asoc_utils.h" + +#define PREFIX "ASoC Harmony: " + +static struct platform_device *harmony_snd_device; + +static int harmony_asoc_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_soc_dai *codec_dai = rtd->codec_dai; +struct snd_soc_dai *cpu_dai = rtd->cpu_dai; +int srate, mclk, mclk_change; +int err; + + srate =params_rate (params); +switch (srate) { +case 64000 : +case 88200 : +case 96000 : + mclk =128 * srate; +break ; +default : + mclk =256 * srate; +break ; + } +/* FIXME: Codec only requires >= 3MHz if OSR==0 */ +while (mclk <6000000 ) + mclk *=2 ; + + err =tegra_asoc_utils_set_rate (srate, mclk, &mclk_change); +if (err <0 ) { +pr_err (PREFIX "Can't configure clocks\n" ); +return err; + } + + err =snd_soc_dai_set_fmt (codec_dai, +SND_SOC_DAIFMT_I2S | +SND_SOC_DAIFMT_NB_NF | +SND_SOC_DAIFMT_CBS_CFS ); +if (err <0 ) { +pr_err (PREFIX "codec_dai fmt not set\n" ); +return err; + } + + err =snd_soc_dai_set_fmt (cpu_dai, +SND_SOC_DAIFMT_I2S | +SND_SOC_DAIFMT_NB_NF | +SND_SOC_DAIFMT_CBS_CFS ); +if (err <0 ) { +pr_err (PREFIX "cpu_dai fmt not set\n" ); +return err; + } + +if (mclk_change) { + err =snd_soc_dai_set_sysclk (codec_dai,0 , mclk,SND_SOC_CLOCK_IN ); +if (err <0 ) { +pr_err (PREFIX "codec_dai clock not set\n" ); +return err; + } + } + +return 0 ; +} + +static struct snd_soc_ops harmony_asoc_ops = { + .hw_params = harmony_asoc_hw_params, +}; + +static struct snd_soc_dai_link harmony_wm8903_dai = { + .name ="WM8903" , + .stream_name ="WM8903 PCM" , + .codec_name ="wm8903-codec.0-001a" , + .platform_name ="tegra-pcm-audio" , + .cpu_dai_name ="tegra-i2s.0" , + .codec_dai_name ="wm8903-hifi" , + .ops = &harmony_asoc_ops, +}; + +static struct snd_soc_card snd_soc_harmony = { + .name ="tegra-harmony" , + .dai_link = &harmony_wm8903_dai, + .num_links =1 , +}; + +static int __init harmony_soc_modinit (void ) +{ +int ret; + +if (!machine_is_harmony ()) { +pr_err (PREFIX "Not running on Tegra Harmony!\n" ); +return -ENODEV ; + } + + ret =tegra_asoc_utils_init (); +if (ret) { +return ret; + } + +/* +* Create and register platform device +*/ + harmony_snd_device =platform_device_alloc ("soc-audio" ,-1 ); +if (harmony_snd_device ==NULL ) { +pr_err (PREFIX "platform_device_alloc failed\n" ); + ret = -ENOMEM ; + goto err_clock_utils; + } + +platform_set_drvdata (harmony_snd_device, &snd_soc_harmony); + + ret =platform_device_add (harmony_snd_device); +if (ret) { +pr_err (PREFIX "platform_device_add failed (%d)\n" , + ret); + goto err_device_put; + } + +return 0 ; + +err_device_put: +platform_device_put (harmony_snd_device); +err_clock_utils: +tegra_asoc_utils_fini (); +return ret; +} +module_init (harmony_soc_modinit); + +static void __exit harmony_soc_modexit(void) +{ +platform_device_unregister (harmony_snd_device); + +tegra_asoc_utils_fini (); +} +module_exit (harmony_soc_modexit); + +MODULE_AUTHOR ("Stephen Warren <[email protected]>" ); +MODULE_DESCRIPTION ("Harmony machine ASoC driver" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
1.7.0.4
PATCH 7/7 ASoC: tegra: Kconfig and Makefile
In reply to Stephen Warren--- sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/tegra/Kconfig | 27 +++++++++++++++++++++++++++ sound/soc/tegra/Makefile | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 0 deletions(-) create mode 100644 sound/soc/tegra/Kconfig create mode 100644 sound/soc/tegra/Makefile
sound/soc/Kconfig +1 -0
@@ -54,6 +54,7 @@ source "sound/soc/pxa/Kconfig" source "sound/soc/samsung/Kconfig" source "sound/soc/s6000/Kconfig" source "sound/soc/sh/Kconfig" +source "sound/soc/tegra/Kconfig" source "sound/soc/txx9/Kconfig" # Supported codecs
sound/soc/Makefile +1 -0
@@ -17,4 +17,5 @@ obj-$(CONFIG_SND_SOC) += pxa/ obj-$(CONFIG_SND_SOC) += samsung/ obj-$(CONFIG_SND_SOC) += s6000/ obj-$(CONFIG_SND_SOC) += sh/ +obj-$(CONFIG_SND_SOC) += tegra/ obj-$(CONFIG_SND_SOC) += txx9/
sound/soc/tegra/Kconfig new file +27 -0
@@ -0,0 +1,27 @@ +config SND_TEGRA_SOC + tristate "SoC Audio for the Tegra System-on-Chip" + depends on ARCH_TEGRA && TEGRA_SYSTEM_DMA + default m + help + Say Y or M here if you want support for SoC audio on Tegra. + +config SND_TEGRA_SOC_I2S + tristate + depends on SND_TEGRA_SOC + depends on !TEGRA_I2S_AUDIO + default m + help + Say Y or M if you want to add support for codecs attached to the + Tegra I2S interface. You will also need to select the individual + machine drivers to support below. + +config SND_TEGRA_SOC_HARMONY + tristate "SoC Audio support for Tegra Harmony reference board" + depends on SND_TEGRA_SOC && MACH_HARMONY && I2C + default m + select SND_TEGRA_SOC_I2S + select SND_SOC_WM8903 + help + Say Y or M here if you want to add support for SoC audio on the + Tegra Harmony reference board. +
sound/soc/tegra/Makefile new file +14 -0
@@ -0,0 +1,14 @@ +# Tegra platform Support +snd-soc-tegra-das-objs := tegra_das.o +snd-soc-tegra-pcm-objs := tegra_pcm.o +snd-soc-tegra-i2s-objs := tegra_i2s.o + +obj-$(CONFIG_SND_TEGRA_SOC) += snd-soc-tegra-das.o +obj-$(CONFIG_SND_TEGRA_SOC) += snd-soc-tegra-pcm.o +obj-$(CONFIG_SND_TEGRA_SOC_I2S) += snd-soc-tegra-i2s.o + +# Tegra machine Support +snd-soc-tegra-harmony-objs := harmony.o +snd-soc-tegra-harmony-objs += tegra_asoc_utils.o + +obj-$(CONFIG_SND_TEGRA_SOC_HARMONY) += snd-soc-tegra-harmony.o
Signature · 1 line
1.7.0.4
Quoted 4 lines · Stephen Warren
(My apologies; I sent this to both linux-tegra and alsa-devel mailing lists before, but posted from the wrong address, so it got dropped from the ALSA list. Here's a copy, hopefully threaded back into the same conversation as the original copy which made it to linux-tegra)
Please always CC maintainers on patches - the mailing lists are often high volume and things get lost, and if people are busy they're likely to check their inboxes more often.
CCing in Liam, I've not looked through the actual patches yet, I'll do so later today or on Monday.
Quoted 8 lines · Stephen Warren
Stephen Warren (7):
ASoC: Export debugfs root dentry
ASoC: tegra: Add tegra-das driver
ASoC: tegra: Add tegra-pcm driver
ASoC: tegra: Add tegra-i2s driver
ASoC: tegra: Machine utility code
ASoC: tegra: Harmony machine support
ASoC: tegra:KconfigandMakefile
This all looks good with the exception of the name of the debugfs root symbol and the issues we've previously discussed which I'll work on once I get this running on my Harmony. Don't worry about correcting the symbol name if Liam's OK with the rest of the series - it's easier for me to do an incremental patch fixing it than re-review.
Liam Girdwood
Acked-byQuoted 11 lines · Mark Brown
Quoted 8 lines · Stephen Warren
Stephen Warren (7):
ASoC: Export debugfs root dentry
ASoC: tegra: Add tegra-das driver
ASoC: tegra: Add tegra-pcm driver
ASoC: tegra: Add tegra-i2s driver
ASoC: tegra: Machine utility code
ASoC: tegra: Harmony machine support
ASoC: tegra:KconfigandMakefile
Quoted 5 lines
This all looks good with the exception of the name of the debugfs root symbol and the issues we've previously discussed which I'll work on once I get this running on my Harmony. Don't worry about correcting the symbol name if Liam's OK with the rest of the series - it's easier for me to do an incremental patch fixing it than re-review.
I've had a quick look and all is fine.
Signature · 3 lines
Freelance Developer, SlimLogic Ltd ASoC and Voltage Regulator Maintainer. http://www.slimlogic.co.uk
Quoted 3 lines · Liam Girdwood
I've had a quick look and all is fine.
Acked-by Liam Girdwood <[email protected]>
Applied, thanks, together with a patch renaming the debugfs export. I'll hold off on making any of my updates here until the merge window is over so that the matching clock tree updates get a chance to show up in -next and give me a stable base to work from.