diff options
author | Jarkko Nikula <jarkko.nikula@linux.intel.com> | 2014-02-24 10:27:00 -0500 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-02-24 23:44:39 -0500 |
commit | 6439c8ad1edcca1051936de9f624c5ab9ebe03f7 (patch) | |
tree | 583ca70920ccd9e20e7beeebd7777c204922799c | |
parent | aef1311a7d7e77408611cdf143d32bb1709527b6 (diff) |
ASoC: Intel: Add machine driver for Baytrail SST with RT5640 codec
Add machine driver for Baytrail SST DSP platform with RT5640 audio codec.
Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Acked-by: Liam Girdwood <liam.r.girdwood@intel.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | sound/soc/intel/byt-rt5640.c | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/sound/soc/intel/byt-rt5640.c b/sound/soc/intel/byt-rt5640.c new file mode 100644 index 000000000000..038547b48b2d --- /dev/null +++ b/sound/soc/intel/byt-rt5640.c | |||
@@ -0,0 +1,194 @@ | |||
1 | /* | ||
2 | * Intel Baytrail SST RT5640 machine driver | ||
3 | * Copyright (c) 2014, Intel Corporation. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
12 | * more details. | ||
13 | */ | ||
14 | |||
15 | #include <linux/init.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/acpi.h> | ||
19 | #include <linux/device.h> | ||
20 | #include <linux/slab.h> | ||
21 | #include <sound/pcm.h> | ||
22 | #include <sound/pcm_params.h> | ||
23 | #include <sound/soc.h> | ||
24 | #include <sound/jack.h> | ||
25 | #include "../codecs/rt5640.h" | ||
26 | |||
27 | #include "sst-dsp.h" | ||
28 | |||
29 | static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = { | ||
30 | SND_SOC_DAPM_HP("Headphone", NULL), | ||
31 | SND_SOC_DAPM_MIC("Headset Mic", NULL), | ||
32 | SND_SOC_DAPM_MIC("Int Mic", NULL), | ||
33 | SND_SOC_DAPM_SPK("Ext Spk", NULL), | ||
34 | }; | ||
35 | |||
36 | static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = { | ||
37 | {"IN2P", NULL, "Headset Mic"}, | ||
38 | {"IN2N", NULL, "Headset Mic"}, | ||
39 | {"DMIC1", NULL, "Int Mic"}, | ||
40 | {"Headphone", NULL, "HPOL"}, | ||
41 | {"Headphone", NULL, "HPOR"}, | ||
42 | {"Ext Spk", NULL, "SPOLP"}, | ||
43 | {"Ext Spk", NULL, "SPOLN"}, | ||
44 | {"Ext Spk", NULL, "SPORP"}, | ||
45 | {"Ext Spk", NULL, "SPORN"}, | ||
46 | }; | ||
47 | |||
48 | static const struct snd_kcontrol_new byt_rt5640_controls[] = { | ||
49 | SOC_DAPM_PIN_SWITCH("Headphone"), | ||
50 | SOC_DAPM_PIN_SWITCH("Headset Mic"), | ||
51 | SOC_DAPM_PIN_SWITCH("Int Mic"), | ||
52 | SOC_DAPM_PIN_SWITCH("Ext Spk"), | ||
53 | }; | ||
54 | |||
55 | static int byt_rt5640_hw_params(struct snd_pcm_substream *substream, | ||
56 | struct snd_pcm_hw_params *params) | ||
57 | { | ||
58 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | ||
59 | struct snd_soc_dai *codec_dai = rtd->codec_dai; | ||
60 | unsigned int fmt; | ||
61 | int ret; | ||
62 | |||
63 | fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | | ||
64 | SND_SOC_DAIFMT_CBS_CFS; | ||
65 | |||
66 | ret = snd_soc_dai_set_fmt(codec_dai, fmt); | ||
67 | if (ret < 0) { | ||
68 | dev_err(codec_dai->dev, | ||
69 | "can't set codec DAI configuration %d\n", ret); | ||
70 | return ret; | ||
71 | } | ||
72 | |||
73 | ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1, | ||
74 | params_rate(params) * 256, | ||
75 | SND_SOC_CLOCK_IN); | ||
76 | if (ret < 0) { | ||
77 | dev_err(codec_dai->dev, "can't set codec clock %d\n", ret); | ||
78 | return ret; | ||
79 | } | ||
80 | ret = snd_soc_dai_set_pll(codec_dai, 0, RT5640_PLL1_S_BCLK1, | ||
81 | params_rate(params) * 64, | ||
82 | params_rate(params) * 256); | ||
83 | if (ret < 0) { | ||
84 | dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret); | ||
85 | return ret; | ||
86 | } | ||
87 | return 0; | ||
88 | } | ||
89 | |||
90 | static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) | ||
91 | { | ||
92 | int ret; | ||
93 | struct snd_soc_codec *codec = runtime->codec; | ||
94 | struct snd_soc_dapm_context *dapm = &codec->dapm; | ||
95 | struct snd_soc_card *card = runtime->card; | ||
96 | |||
97 | card->dapm.idle_bias_off = true; | ||
98 | |||
99 | ret = snd_soc_add_card_controls(card, byt_rt5640_controls, | ||
100 | ARRAY_SIZE(byt_rt5640_controls)); | ||
101 | if (ret) { | ||
102 | dev_err(card->dev, "unable to add card controls\n"); | ||
103 | return ret; | ||
104 | } | ||
105 | |||
106 | snd_soc_dapm_ignore_suspend(dapm, "HPOL"); | ||
107 | snd_soc_dapm_ignore_suspend(dapm, "HPOR"); | ||
108 | |||
109 | snd_soc_dapm_ignore_suspend(dapm, "SPOLP"); | ||
110 | snd_soc_dapm_ignore_suspend(dapm, "SPOLN"); | ||
111 | snd_soc_dapm_ignore_suspend(dapm, "SPORP"); | ||
112 | snd_soc_dapm_ignore_suspend(dapm, "SPORN"); | ||
113 | |||
114 | snd_soc_dapm_enable_pin(dapm, "Headset Mic"); | ||
115 | snd_soc_dapm_enable_pin(dapm, "Headphone"); | ||
116 | snd_soc_dapm_enable_pin(dapm, "Ext Spk"); | ||
117 | snd_soc_dapm_enable_pin(dapm, "Int Mic"); | ||
118 | |||
119 | snd_soc_dapm_sync(dapm); | ||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | static struct snd_soc_ops byt_rt5640_ops = { | ||
124 | .hw_params = byt_rt5640_hw_params, | ||
125 | }; | ||
126 | |||
127 | static struct snd_soc_dai_link byt_rt5640_dais[] = { | ||
128 | { | ||
129 | .name = "Baytrail Audio", | ||
130 | .stream_name = "Audio", | ||
131 | .cpu_dai_name = "Front-cpu-dai", | ||
132 | .codec_dai_name = "rt5640-aif1", | ||
133 | .codec_name = "i2c-10EC5640:00", | ||
134 | .platform_name = "baytrail-pcm-audio", | ||
135 | .init = byt_rt5640_init, | ||
136 | .ignore_suspend = 1, | ||
137 | .ops = &byt_rt5640_ops, | ||
138 | }, | ||
139 | { | ||
140 | .name = "Baytrail Voice", | ||
141 | .stream_name = "Voice", | ||
142 | .cpu_dai_name = "Mic1-cpu-dai", | ||
143 | .codec_dai_name = "rt5640-aif1", | ||
144 | .codec_name = "i2c-10EC5640:00", | ||
145 | .platform_name = "baytrail-pcm-audio", | ||
146 | .init = NULL, | ||
147 | .ignore_suspend = 1, | ||
148 | .ops = &byt_rt5640_ops, | ||
149 | }, | ||
150 | }; | ||
151 | |||
152 | static struct snd_soc_card byt_rt5640_card = { | ||
153 | .name = "byt-rt5640", | ||
154 | .dai_link = byt_rt5640_dais, | ||
155 | .num_links = ARRAY_SIZE(byt_rt5640_dais), | ||
156 | .dapm_widgets = byt_rt5640_widgets, | ||
157 | .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets), | ||
158 | .dapm_routes = byt_rt5640_audio_map, | ||
159 | .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map), | ||
160 | }; | ||
161 | |||
162 | static int byt_rt5640_probe(struct platform_device *pdev) | ||
163 | { | ||
164 | struct snd_soc_card *card = &byt_rt5640_card; | ||
165 | struct device *dev = &pdev->dev; | ||
166 | |||
167 | card->dev = &pdev->dev; | ||
168 | dev_set_drvdata(dev, card); | ||
169 | return snd_soc_register_card(card); | ||
170 | } | ||
171 | |||
172 | static int byt_rt5640_remove(struct platform_device *pdev) | ||
173 | { | ||
174 | struct snd_soc_card *card = platform_get_drvdata(pdev); | ||
175 | |||
176 | snd_soc_unregister_card(card); | ||
177 | |||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | static struct platform_driver byt_rt5640_audio = { | ||
182 | .probe = byt_rt5640_probe, | ||
183 | .remove = byt_rt5640_remove, | ||
184 | .driver = { | ||
185 | .name = "byt-rt5640", | ||
186 | .owner = THIS_MODULE, | ||
187 | }, | ||
188 | }; | ||
189 | module_platform_driver(byt_rt5640_audio) | ||
190 | |||
191 | MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver"); | ||
192 | MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula"); | ||
193 | MODULE_LICENSE("GPL v2"); | ||
194 | MODULE_ALIAS("platform:byt-rt5640"); | ||