blob: 1e51750fd3a2c5113989571774b10a70f47ceacf [file] [log] [blame]
Mark Brown9b8dc662011-04-12 17:24:39 -07001/*
2 * Speyside audio support
3 *
4 * Copyright 2011 Wolfson Microelectronics
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <sound/soc.h>
13#include <sound/soc-dapm.h>
14
15#include "../codecs/wm8915.h"
16
Mark Brownea0a5912011-04-11 23:32:03 -070017static int speyside_set_bias_level(struct snd_soc_card *card,
18 enum snd_soc_bias_level level)
19{
20 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
21 int ret;
22
23 switch (level) {
24 case SND_SOC_BIAS_STANDBY:
25 ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_MCLK1,
26 32768, SND_SOC_CLOCK_IN);
27 if (ret < 0)
28 return ret;
29
30 ret = snd_soc_dai_set_pll(codec_dai, WM8915_FLL_MCLK1,
31 0, 0, 0);
32 if (ret < 0) {
33 pr_err("Failed to stop FLL\n");
34 return ret;
35 }
36
37 default:
38 break;
39 }
40
41 return 0;
42}
43
Mark Brown9b8dc662011-04-12 17:24:39 -070044static int speyside_hw_params(struct snd_pcm_substream *substream,
45 struct snd_pcm_hw_params *params)
46{
47 struct snd_soc_pcm_runtime *rtd = substream->private_data;
48 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
49 struct snd_soc_dai *codec_dai = rtd->codec_dai;
50 int ret;
51
52 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
53 | SND_SOC_DAIFMT_NB_NF
54 | SND_SOC_DAIFMT_CBM_CFM);
55 if (ret < 0)
56 return ret;
57
58 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
59 | SND_SOC_DAIFMT_NB_NF
60 | SND_SOC_DAIFMT_CBM_CFM);
61 if (ret < 0)
62 return ret;
63
64 ret = snd_soc_dai_set_pll(codec_dai, 0, WM8915_FLL_MCLK1,
65 32768, 256 * 48000);
66 if (ret < 0)
67 return ret;
68
69 ret = snd_soc_dai_set_sysclk(codec_dai, WM8915_SYSCLK_FLL,
70 256 * 48000, SND_SOC_CLOCK_IN);
71 if (ret < 0)
72 return ret;
73
74 return 0;
75}
76
77static struct snd_soc_ops speyside_ops = {
78 .hw_params = speyside_hw_params,
79};
80
Mark Brownea0a5912011-04-11 23:32:03 -070081static int speyside_wm8915_init(struct snd_soc_pcm_runtime *rtd)
82{
83 struct snd_soc_dai *dai = rtd->codec_dai;
84
85 return snd_soc_dai_set_sysclk(dai, WM8915_SYSCLK_MCLK1, 32768, 0);
86}
87
Mark Brown9b8dc662011-04-12 17:24:39 -070088static struct snd_soc_dai_link speyside_dai[] = {
89 {
90 .name = "CPU",
91 .stream_name = "CPU",
92 .cpu_dai_name = "samsung-i2s.0",
93 .codec_dai_name = "wm8915-aif1",
94 .platform_name = "samsung-audio",
95 .codec_name = "wm8915.1-001a",
Mark Brownea0a5912011-04-11 23:32:03 -070096 .init = speyside_wm8915_init,
Mark Brown9b8dc662011-04-12 17:24:39 -070097 .ops = &speyside_ops,
98 },
99};
100
Mark Brownecfb1ad2011-04-11 23:09:15 -0700101static struct snd_soc_dapm_widget widgets[] = {
102 SND_SOC_DAPM_HP("Headphone", NULL),
103
104 SND_SOC_DAPM_SPK("Main Speaker", NULL),
105
106 SND_SOC_DAPM_MIC("Main AMIC", NULL),
107 SND_SOC_DAPM_MIC("Main DMIC", NULL),
108};
109
110static struct snd_soc_dapm_route audio_paths[] = {
111 { "IN1LP", NULL, "MICB2" },
112 { "MICB2", NULL, "Main AMIC" },
113
114 { "DMIC1DAT", NULL, "MICB1" },
115 { "DMIC2DAT", NULL, "MICB1" },
116 { "MICB1", NULL, "Main DMIC" },
117
118 { "Headphone", NULL, "HPOUT1L" },
119 { "Headphone", NULL, "HPOUT1R" },
120
121 { "Main Speaker", NULL, "SPKDAT" },
122};
123
Mark Brown9b8dc662011-04-12 17:24:39 -0700124static struct snd_soc_card speyside = {
125 .name = "Speyside",
126 .dai_link = speyside_dai,
127 .num_links = ARRAY_SIZE(speyside_dai),
Mark Brownecfb1ad2011-04-11 23:09:15 -0700128
Mark Brownea0a5912011-04-11 23:32:03 -0700129 .set_bias_level = speyside_set_bias_level,
130
Mark Brownecfb1ad2011-04-11 23:09:15 -0700131 .dapm_widgets = widgets,
132 .num_dapm_widgets = ARRAY_SIZE(widgets),
133 .dapm_routes = audio_paths,
134 .num_dapm_routes = ARRAY_SIZE(audio_paths),
Mark Brown9b8dc662011-04-12 17:24:39 -0700135};
136
137static __devinit int speyside_probe(struct platform_device *pdev)
138{
139 struct snd_soc_card *card = &speyside;
140 int ret;
141
142 card->dev = &pdev->dev;
143
144 ret = snd_soc_register_card(card);
145 if (ret) {
146 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
147 ret);
148 return ret;
149 }
150
151 return 0;
152}
153
154static int __devexit speyside_remove(struct platform_device *pdev)
155{
156 struct snd_soc_card *card = platform_get_drvdata(pdev);
157
158 snd_soc_unregister_card(card);
159
160 return 0;
161}
162
163static struct platform_driver speyside_driver = {
164 .driver = {
165 .name = "speyside",
166 .owner = THIS_MODULE,
167 .pm = &snd_soc_pm_ops,
168 },
169 .probe = speyside_probe,
170 .remove = __devexit_p(speyside_remove),
171};
172
173static int __init speyside_audio_init(void)
174{
175 return platform_driver_register(&speyside_driver);
176}
177module_init(speyside_audio_init);
178
179static void __exit speyside_audio_exit(void)
180{
181 platform_driver_unregister(&speyside_driver);
182}
183module_exit(speyside_audio_exit);
184
185MODULE_DESCRIPTION("Speyside audio support");
186MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
187MODULE_LICENSE("GPL");
188MODULE_ALIAS("platform:speyside");