2 * harmony.c - Harmony machine ASoC driver
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010 - NVIDIA, Inc.
7 * Based on code copyright/by:
9 * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
11 * Copyright 2007 Wolfson Microelectronics PLC.
12 * Author: Graeme Gregory
13 * graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
31 #include <asm/mach-types.h>
32 #include <linux/module.h>
33 #include <sound/core.h>
34 #include <sound/pcm.h>
35 #include <sound/pcm_params.h>
36 #include <sound/soc.h>
38 #include "tegra_das.h"
39 #include "tegra_i2s.h"
40 #include "tegra_pcm.h"
41 #include "tegra_asoc_utils.h"
43 #define PREFIX "ASoC Harmony: "
45 static struct platform_device *harmony_snd_device;
47 static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,
48 struct snd_pcm_hw_params *params)
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
51 struct snd_soc_dai *codec_dai = rtd->codec_dai;
52 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
53 int srate, mclk, mclk_change;
56 srate = params_rate(params);
67 /* FIXME: Codec only requires >= 3MHz if OSR==0 */
68 while (mclk < 6000000)
71 err = tegra_asoc_utils_set_rate(srate, mclk, &mclk_change);
73 pr_err(PREFIX "Can't configure clocks\n");
77 err = snd_soc_dai_set_fmt(codec_dai,
79 SND_SOC_DAIFMT_NB_NF |
80 SND_SOC_DAIFMT_CBS_CFS);
82 pr_err(PREFIX "codec_dai fmt not set\n");
86 err = snd_soc_dai_set_fmt(cpu_dai,
88 SND_SOC_DAIFMT_NB_NF |
89 SND_SOC_DAIFMT_CBS_CFS);
91 pr_err(PREFIX "cpu_dai fmt not set\n");
96 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN);
98 pr_err(PREFIX "codec_dai clock not set\n");
106 static struct snd_soc_ops harmony_asoc_ops = {
107 .hw_params = harmony_asoc_hw_params,
110 static struct snd_soc_dai_link harmony_wm8903_dai = {
112 .stream_name = "WM8903 PCM",
113 .codec_name = "wm8903-codec.0-001a",
114 .platform_name = "tegra-pcm-audio",
115 .cpu_dai_name = "tegra-i2s.0",
116 .codec_dai_name = "wm8903-hifi",
117 .ops = &harmony_asoc_ops,
120 static struct snd_soc_card snd_soc_harmony = {
121 .name = "tegra-harmony",
122 .dai_link = &harmony_wm8903_dai,
126 static int __init harmony_soc_modinit(void)
130 if (!machine_is_harmony()) {
131 pr_err(PREFIX "Not running on Tegra Harmony!\n");
135 ret = tegra_asoc_utils_init();
141 * Create and register platform device
143 harmony_snd_device = platform_device_alloc("soc-audio", -1);
144 if (harmony_snd_device == NULL) {
145 pr_err(PREFIX "platform_device_alloc failed\n");
147 goto err_clock_utils;
150 platform_set_drvdata(harmony_snd_device, &snd_soc_harmony);
152 ret = platform_device_add(harmony_snd_device);
154 pr_err(PREFIX "platform_device_add failed (%d)\n",
162 platform_device_put(harmony_snd_device);
164 tegra_asoc_utils_fini();
167 module_init(harmony_soc_modinit);
169 static void __exit harmony_soc_modexit(void)
171 platform_device_unregister(harmony_snd_device);
173 tegra_asoc_utils_fini();
175 module_exit(harmony_soc_modexit);
177 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
178 MODULE_DESCRIPTION("Harmony machine ASoC driver");
179 MODULE_LICENSE("GPL");