Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[deliverable/linux.git] / sound / soc / pxa / brownstone.c
1 /*
2 * linux/sound/soc/pxa/brownstone.c
3 *
4 * Copyright (C) 2011 Marvell International Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12
13 #include <linux/module.h>
14 #include <sound/core.h>
15 #include <sound/pcm.h>
16 #include <sound/soc.h>
17 #include <sound/jack.h>
18
19 #include "../codecs/wm8994.h"
20 #include "mmp-sspa.h"
21
22 static const struct snd_kcontrol_new brownstone_dapm_control[] = {
23 SOC_DAPM_PIN_SWITCH("Ext Spk"),
24 };
25
26 static const struct snd_soc_dapm_widget brownstone_dapm_widgets[] = {
27 SND_SOC_DAPM_SPK("Ext Spk", NULL),
28 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
29 SND_SOC_DAPM_MIC("Headset Mic", NULL),
30 SND_SOC_DAPM_MIC("Main Mic", NULL),
31 };
32
33 static const struct snd_soc_dapm_route brownstone_audio_map[] = {
34 {"Ext Spk", NULL, "SPKOUTLP"},
35 {"Ext Spk", NULL, "SPKOUTLN"},
36 {"Ext Spk", NULL, "SPKOUTRP"},
37 {"Ext Spk", NULL, "SPKOUTRN"},
38
39 {"Headset Stereophone", NULL, "HPOUT1L"},
40 {"Headset Stereophone", NULL, "HPOUT1R"},
41
42 {"IN1RN", NULL, "Headset Mic"},
43
44 {"DMIC1DAT", NULL, "MICBIAS1"},
45 {"MICBIAS1", NULL, "Main Mic"},
46 };
47
48 static int brownstone_wm8994_init(struct snd_soc_pcm_runtime *rtd)
49 {
50 struct snd_soc_codec *codec = rtd->codec;
51 struct snd_soc_dapm_context *dapm = &codec->dapm;
52
53 /* set endpoints to not connected */
54 snd_soc_dapm_nc_pin(dapm, "HPOUT2P");
55 snd_soc_dapm_nc_pin(dapm, "HPOUT2N");
56 snd_soc_dapm_nc_pin(dapm, "LINEOUT1N");
57 snd_soc_dapm_nc_pin(dapm, "LINEOUT1P");
58 snd_soc_dapm_nc_pin(dapm, "LINEOUT2N");
59 snd_soc_dapm_nc_pin(dapm, "LINEOUT2P");
60 snd_soc_dapm_nc_pin(dapm, "IN1LN");
61 snd_soc_dapm_nc_pin(dapm, "IN1LP");
62 snd_soc_dapm_nc_pin(dapm, "IN1RP");
63 snd_soc_dapm_nc_pin(dapm, "IN2LP:VXRN");
64 snd_soc_dapm_nc_pin(dapm, "IN2RN");
65 snd_soc_dapm_nc_pin(dapm, "IN2RP:VXRP");
66 snd_soc_dapm_nc_pin(dapm, "IN2LN");
67
68 return 0;
69 }
70
71 static int brownstone_wm8994_hw_params(struct snd_pcm_substream *substream,
72 struct snd_pcm_hw_params *params)
73 {
74 struct snd_soc_pcm_runtime *rtd = substream->private_data;
75 struct snd_soc_dai *codec_dai = rtd->codec_dai;
76 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
77 int freq_out, sspa_mclk, sysclk;
78 int sspa_div;
79
80 if (params_rate(params) > 11025) {
81 freq_out = params_rate(params) * 512;
82 sysclk = params_rate(params) * 256;
83 sspa_mclk = params_rate(params) * 64;
84 } else {
85 freq_out = params_rate(params) * 1024;
86 sysclk = params_rate(params) * 512;
87 sspa_mclk = params_rate(params) * 64;
88 }
89 sspa_div = freq_out;
90 do_div(sspa_div, sspa_mclk);
91
92 snd_soc_dai_set_sysclk(cpu_dai, MMP_SSPA_CLK_AUDIO, freq_out, 0);
93 snd_soc_dai_set_pll(cpu_dai, MMP_SYSCLK, 0, freq_out, sysclk);
94 snd_soc_dai_set_pll(cpu_dai, MMP_SSPA_CLK, 0, freq_out, sspa_mclk);
95
96 /* set wm8994 sysclk */
97 snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1, sysclk, 0);
98
99 return 0;
100 }
101
102 /* machine stream operations */
103 static struct snd_soc_ops brownstone_ops = {
104 .hw_params = brownstone_wm8994_hw_params,
105 };
106
107 static struct snd_soc_dai_link brownstone_wm8994_dai[] = {
108 {
109 .name = "WM8994",
110 .stream_name = "WM8994 HiFi",
111 .cpu_dai_name = "mmp-sspa-dai.0",
112 .codec_dai_name = "wm8994-aif1",
113 .platform_name = "mmp-pcm-audio",
114 .codec_name = "wm8994-codec",
115 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
116 SND_SOC_DAIFMT_CBS_CFS,
117 .ops = &brownstone_ops,
118 .init = brownstone_wm8994_init,
119 },
120 };
121
122 /* audio machine driver */
123 static struct snd_soc_card brownstone = {
124 .name = "brownstone",
125 .owner = THIS_MODULE,
126 .dai_link = brownstone_wm8994_dai,
127 .num_links = ARRAY_SIZE(brownstone_wm8994_dai),
128
129 .controls = brownstone_dapm_control,
130 .num_controls = ARRAY_SIZE(brownstone_dapm_control),
131 .dapm_widgets = brownstone_dapm_widgets,
132 .num_dapm_widgets = ARRAY_SIZE(brownstone_dapm_widgets),
133 .dapm_routes = brownstone_audio_map,
134 .num_dapm_routes = ARRAY_SIZE(brownstone_audio_map),
135 };
136
137 static int brownstone_probe(struct platform_device *pdev)
138 {
139 int ret;
140
141 brownstone.dev = &pdev->dev;
142 ret = snd_soc_register_card(&brownstone);
143 if (ret)
144 dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
145 ret);
146 return ret;
147 }
148
149 static int brownstone_remove(struct platform_device *pdev)
150 {
151 snd_soc_unregister_card(&brownstone);
152 return 0;
153 }
154
155 static struct platform_driver mmp_driver = {
156 .driver = {
157 .name = "brownstone-audio",
158 .pm = &snd_soc_pm_ops,
159 },
160 .probe = brownstone_probe,
161 .remove = brownstone_remove,
162 };
163
164 module_platform_driver(mmp_driver);
165
166 MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
167 MODULE_DESCRIPTION("ALSA SoC Brownstone");
168 MODULE_LICENSE("GPL");
This page took 0.035403 seconds and 5 git commands to generate.