2 * cht-bsw-max98090.c - ASoc Machine driver for Intel Cherryview-based
3 * platforms Cherrytrail and Braswell, with max98090 & TI codec.
5 * Copyright (C) 2015 Intel Corp
6 * Author: Fang, Yang A <yang.a.fang@intel.com>
7 * This file is modified from cht_bsw_rt5645.c
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 #include <linux/module.h>
23 #include <linux/platform_device.h>
24 #include <linux/slab.h>
25 #include <linux/acpi.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/soc.h>
29 #include <sound/jack.h>
30 #include "../../codecs/max98090.h"
31 #include "../atom/sst-atom-controls.h"
32 #include "../../codecs/ts3a227e.h"
34 #define CHT_PLAT_CLK_3_HZ 19200000
35 #define CHT_CODEC_DAI "HiFi"
37 struct cht_mc_private {
38 struct snd_soc_jack jack;
39 bool ts3a227e_present;
42 static const struct snd_soc_dapm_widget cht_dapm_widgets[] = {
43 SND_SOC_DAPM_HP("Headphone", NULL),
44 SND_SOC_DAPM_MIC("Headset Mic", NULL),
45 SND_SOC_DAPM_MIC("Int Mic", NULL),
46 SND_SOC_DAPM_SPK("Ext Spk", NULL),
49 static const struct snd_soc_dapm_route cht_audio_map[] = {
50 {"IN34", NULL, "Headset Mic"},
51 {"Headset Mic", NULL, "MICBIAS"},
52 {"DMICL", NULL, "Int Mic"},
53 {"Headphone", NULL, "HPL"},
54 {"Headphone", NULL, "HPR"},
55 {"Ext Spk", NULL, "SPKL"},
56 {"Ext Spk", NULL, "SPKR"},
57 {"HiFi Playback", NULL, "ssp2 Tx"},
58 {"ssp2 Tx", NULL, "codec_out0"},
59 {"ssp2 Tx", NULL, "codec_out1"},
60 {"codec_in0", NULL, "ssp2 Rx" },
61 {"codec_in1", NULL, "ssp2 Rx" },
62 {"ssp2 Rx", NULL, "HiFi Capture"},
65 static const struct snd_kcontrol_new cht_mc_controls[] = {
66 SOC_DAPM_PIN_SWITCH("Headphone"),
67 SOC_DAPM_PIN_SWITCH("Headset Mic"),
68 SOC_DAPM_PIN_SWITCH("Int Mic"),
69 SOC_DAPM_PIN_SWITCH("Ext Spk"),
72 static int cht_aif1_hw_params(struct snd_pcm_substream *substream,
73 struct snd_pcm_hw_params *params)
75 struct snd_soc_pcm_runtime *rtd = substream->private_data;
76 struct snd_soc_dai *codec_dai = rtd->codec_dai;
79 ret = snd_soc_dai_set_sysclk(codec_dai, M98090_REG_SYSTEM_CLOCK,
80 CHT_PLAT_CLK_3_HZ, SND_SOC_CLOCK_IN);
82 dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret);
89 static int cht_ti_jack_event(struct notifier_block *nb,
90 unsigned long event, void *data)
92 struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
93 struct snd_soc_dapm_context *dapm = &jack->card->dapm;
95 if (event & SND_JACK_MICROPHONE) {
96 snd_soc_dapm_force_enable_pin(dapm, "SHDN");
97 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS");
98 snd_soc_dapm_sync(dapm);
100 snd_soc_dapm_disable_pin(dapm, "MICBIAS");
101 snd_soc_dapm_disable_pin(dapm, "SHDN");
102 snd_soc_dapm_sync(dapm);
108 static struct notifier_block cht_jack_nb = {
109 .notifier_call = cht_ti_jack_event,
112 static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
116 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card);
117 struct snd_soc_jack *jack = &ctx->jack;
119 if (ctx->ts3a227e_present) {
121 * The jack has already been created in the
122 * cht_max98090_headset_init() function.
124 snd_soc_jack_notifier_register(jack, &cht_jack_nb);
128 jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE;
130 ret = snd_soc_card_jack_new(runtime->card, "Headset Jack",
131 jack_type, jack, NULL, 0);
133 dev_err(runtime->dev, "Headset Jack creation failed %d\n", ret);
137 if (ctx->ts3a227e_present)
138 snd_soc_jack_notifier_register(jack, &cht_jack_nb);
143 static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd,
144 struct snd_pcm_hw_params *params)
146 struct snd_interval *rate = hw_param_interval(params,
147 SNDRV_PCM_HW_PARAM_RATE);
148 struct snd_interval *channels = hw_param_interval(params,
149 SNDRV_PCM_HW_PARAM_CHANNELS);
151 unsigned int fmt = 0;
153 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
155 dev_err(rtd->dev, "can't set cpu_dai slot fmt: %d\n", ret);
159 fmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF
160 | SND_SOC_DAIFMT_CBS_CFS;
162 ret = snd_soc_dai_set_fmt(rtd->cpu_dai, fmt);
164 dev_err(rtd->dev, "can't set cpu_dai set fmt: %d\n", ret);
168 /* The DSP will covert the FE rate to 48k, stereo, 24bits */
169 rate->min = rate->max = 48000;
170 channels->min = channels->max = 2;
172 /* set SSP2 to 24-bit */
173 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
177 static int cht_aif1_startup(struct snd_pcm_substream *substream)
179 return snd_pcm_hw_constraint_single(substream->runtime,
180 SNDRV_PCM_HW_PARAM_RATE, 48000);
183 static int cht_max98090_headset_init(struct snd_soc_component *component)
185 struct snd_soc_card *card = component->card;
186 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card);
187 struct snd_soc_jack *jack = &ctx->jack;
192 * TI supports 4 butons headset detection
198 jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
199 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
200 SND_JACK_BTN_2 | SND_JACK_BTN_3;
202 ret = snd_soc_card_jack_new(card, "Headset Jack", jack_type,
205 dev_err(card->dev, "Headset Jack creation failed %d\n", ret);
209 return ts3a227e_enable_jack_detect(component, &ctx->jack);
212 static const struct snd_soc_ops cht_aif1_ops = {
213 .startup = cht_aif1_startup,
216 static const struct snd_soc_ops cht_be_ssp2_ops = {
217 .hw_params = cht_aif1_hw_params,
220 static struct snd_soc_aux_dev cht_max98090_headset_dev = {
221 .name = "Headset Chip",
222 .init = cht_max98090_headset_init,
223 .codec_name = "i2c-104C227E:00",
226 static struct snd_soc_dai_link cht_dailink[] = {
227 [MERR_DPCM_AUDIO] = {
228 .name = "Audio Port",
229 .stream_name = "Audio",
230 .cpu_dai_name = "media-cpu-dai",
231 .codec_dai_name = "snd-soc-dummy-dai",
232 .codec_name = "snd-soc-dummy",
233 .platform_name = "sst-mfld-platform",
238 .ops = &cht_aif1_ops,
240 [MERR_DPCM_DEEP_BUFFER] = {
241 .name = "Deep-Buffer Audio Port",
242 .stream_name = "Deep-Buffer Audio",
243 .cpu_dai_name = "deepbuffer-cpu-dai",
244 .codec_dai_name = "snd-soc-dummy-dai",
245 .codec_name = "snd-soc-dummy",
246 .platform_name = "sst-mfld-platform",
250 .ops = &cht_aif1_ops,
252 [MERR_DPCM_COMPR] = {
253 .name = "Compressed Port",
254 .stream_name = "Compress",
255 .cpu_dai_name = "compress-cpu-dai",
256 .codec_dai_name = "snd-soc-dummy-dai",
257 .codec_name = "snd-soc-dummy",
258 .platform_name = "sst-mfld-platform",
262 .name = "SSP2-Codec",
264 .cpu_dai_name = "ssp2-port",
265 .platform_name = "sst-mfld-platform",
267 .codec_dai_name = "HiFi",
268 .codec_name = "i2c-193C9890:00",
269 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
270 | SND_SOC_DAIFMT_CBS_CFS,
271 .init = cht_codec_init,
272 .be_hw_params_fixup = cht_codec_fixup,
275 .ops = &cht_be_ssp2_ops,
280 static struct snd_soc_card snd_soc_card_cht = {
281 .name = "chtmax98090",
282 .owner = THIS_MODULE,
283 .dai_link = cht_dailink,
284 .num_links = ARRAY_SIZE(cht_dailink),
285 .aux_dev = &cht_max98090_headset_dev,
287 .dapm_widgets = cht_dapm_widgets,
288 .num_dapm_widgets = ARRAY_SIZE(cht_dapm_widgets),
289 .dapm_routes = cht_audio_map,
290 .num_dapm_routes = ARRAY_SIZE(cht_audio_map),
291 .controls = cht_mc_controls,
292 .num_controls = ARRAY_SIZE(cht_mc_controls),
295 static int snd_cht_mc_probe(struct platform_device *pdev)
298 struct cht_mc_private *drv;
300 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_ATOMIC);
304 drv->ts3a227e_present = acpi_dev_found("104C227E");
305 if (!drv->ts3a227e_present) {
306 /* no need probe TI jack detection chip */
307 snd_soc_card_cht.aux_dev = NULL;
308 snd_soc_card_cht.num_aux_devs = 0;
311 /* register the soc card */
312 snd_soc_card_cht.dev = &pdev->dev;
313 snd_soc_card_set_drvdata(&snd_soc_card_cht, drv);
314 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_cht);
317 "snd_soc_register_card failed %d\n", ret_val);
320 platform_set_drvdata(pdev, &snd_soc_card_cht);
324 static struct platform_driver snd_cht_mc_driver = {
326 .name = "cht-bsw-max98090",
328 .probe = snd_cht_mc_probe,
331 module_platform_driver(snd_cht_mc_driver)
333 MODULE_DESCRIPTION("ASoC Intel(R) Braswell Machine driver");
334 MODULE_AUTHOR("Fang, Yang A <yang.a.fang@intel.com>");
335 MODULE_LICENSE("GPL v2");
336 MODULE_ALIAS("platform:cht-bsw-max98090");