2 * harmony.c - Harmony machine ASoC driver
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010-2011 - 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>
33 #include <linux/module.h>
34 #include <linux/platform_device.h>
35 #include <linux/slab.h>
37 #include <sound/core.h>
38 #include <sound/pcm.h>
39 #include <sound/pcm_params.h>
40 #include <sound/soc.h>
42 #include "tegra_das.h"
43 #include "tegra_i2s.h"
44 #include "tegra_pcm.h"
45 #include "tegra_asoc_utils.h"
47 #define DRV_NAME "tegra-snd-harmony"
48 #define PREFIX DRV_NAME ": "
50 struct tegra_harmony {
53 static int harmony_asoc_hw_params(struct snd_pcm_substream *substream,
54 struct snd_pcm_hw_params *params)
56 struct snd_soc_pcm_runtime *rtd = substream->private_data;
57 struct snd_soc_dai *codec_dai = rtd->codec_dai;
58 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
59 int srate, mclk, mclk_change;
62 srate = params_rate(params);
73 /* FIXME: Codec only requires >= 3MHz if OSR==0 */
74 while (mclk < 6000000)
77 err = tegra_asoc_utils_set_rate(srate, mclk, &mclk_change);
79 pr_err(PREFIX "Can't configure clocks\n");
83 err = snd_soc_dai_set_fmt(codec_dai,
85 SND_SOC_DAIFMT_NB_NF |
86 SND_SOC_DAIFMT_CBS_CFS);
88 pr_err(PREFIX "codec_dai fmt not set\n");
92 err = snd_soc_dai_set_fmt(cpu_dai,
94 SND_SOC_DAIFMT_NB_NF |
95 SND_SOC_DAIFMT_CBS_CFS);
97 pr_err(PREFIX "cpu_dai fmt not set\n");
102 err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, SND_SOC_CLOCK_IN);
104 pr_err(PREFIX "codec_dai clock not set\n");
112 static struct snd_soc_ops harmony_asoc_ops = {
113 .hw_params = harmony_asoc_hw_params,
116 static const struct snd_soc_dapm_widget harmony_dapm_widgets[] = {
117 SND_SOC_DAPM_HP("Headphone Jack", NULL),
118 SND_SOC_DAPM_MIC("Mic Jack", NULL),
121 static const struct snd_soc_dapm_route harmony_audio_map[] = {
122 {"Headphone Jack", NULL, "HPOUTR"},
123 {"Headphone Jack", NULL, "HPOUTL"},
124 {"Mic Bias", NULL, "Mic Jack"},
125 {"IN1L", NULL, "Mic Bias"},
128 static int harmony_asoc_init(struct snd_soc_pcm_runtime *rtd)
130 struct snd_soc_codec *codec = rtd->codec;
131 struct snd_soc_dapm_context *dapm = &codec->dapm;
133 snd_soc_dapm_new_controls(dapm, harmony_dapm_widgets,
134 ARRAY_SIZE(harmony_dapm_widgets));
136 snd_soc_dapm_add_routes(dapm, harmony_audio_map,
137 ARRAY_SIZE(harmony_audio_map));
139 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
140 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
141 snd_soc_dapm_sync(dapm);
146 static struct snd_soc_dai_link harmony_wm8903_dai = {
148 .stream_name = "WM8903 PCM",
149 .codec_name = "wm8903-codec.0-001a",
150 .platform_name = "tegra-pcm-audio",
151 .cpu_dai_name = "tegra-i2s.0",
152 .codec_dai_name = "wm8903-hifi",
153 .init = harmony_asoc_init,
154 .ops = &harmony_asoc_ops,
157 static struct snd_soc_card snd_soc_harmony = {
158 .name = "tegra-harmony",
159 .dai_link = &harmony_wm8903_dai,
163 static __devinit int tegra_snd_harmony_probe(struct platform_device *pdev)
165 struct snd_soc_card *card = &snd_soc_harmony;
166 struct tegra_harmony *harmony;
169 if (!machine_is_harmony()) {
170 dev_err(&pdev->dev, "Not running on Tegra Harmony!\n");
174 harmony = kzalloc(sizeof(struct tegra_harmony), GFP_KERNEL);
176 dev_err(&pdev->dev, "Can't allocate tegra_harmony\n");
180 ret = tegra_asoc_utils_init();
182 goto err_free_harmony;
184 card->dev = &pdev->dev;
185 platform_set_drvdata(pdev, card);
186 snd_soc_card_set_drvdata(card, harmony);
188 ret = snd_soc_register_card(card);
190 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
192 goto err_clear_drvdata;
198 snd_soc_card_set_drvdata(card, NULL);
199 platform_set_drvdata(pdev, NULL);
201 tegra_asoc_utils_fini();
207 static int __devexit tegra_snd_harmony_remove(struct platform_device *pdev)
209 struct snd_soc_card *card = platform_get_drvdata(pdev);
210 struct tegra_harmony *harmony = snd_soc_card_get_drvdata(card);
212 snd_soc_unregister_card(card);
214 snd_soc_card_set_drvdata(card, NULL);
215 platform_set_drvdata(pdev, NULL);
218 tegra_asoc_utils_fini();
225 static struct platform_driver tegra_snd_harmony_driver = {
228 .owner = THIS_MODULE,
230 .probe = tegra_snd_harmony_probe,
231 .remove = __devexit_p(tegra_snd_harmony_remove),
234 static int __init snd_tegra_harmony_init(void)
236 return platform_driver_register(&tegra_snd_harmony_driver);
238 module_init(snd_tegra_harmony_init);
240 static void __exit snd_tegra_harmony_exit(void)
242 platform_driver_unregister(&tegra_snd_harmony_driver);
244 module_exit(snd_tegra_harmony_exit);
246 MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
247 MODULE_DESCRIPTION("Harmony machine ASoC driver");
248 MODULE_LICENSE("GPL");