2 * Intel Haswell Lynxpoint SST Audio
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 #include <sound/soc.h>
22 #include <sound/pcm_params.h>
25 #include "sst-haswell-ipc.h"
27 #include "../codecs/rt5640.h"
29 /* Haswell ULT platforms have a Headphone and Mic jack */
30 static const struct snd_soc_dapm_widget haswell_widgets[] = {
31 SND_SOC_DAPM_HP("Headphones", NULL),
32 SND_SOC_DAPM_MIC("Mic", NULL),
35 static const struct snd_soc_dapm_route haswell_rt5640_map[] = {
37 {"Headphones", NULL, "HPOR"},
38 {"Headphones", NULL, "HPOL"},
39 {"IN2P", NULL, "Mic"},
41 /* CODEC BE connections */
42 {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
43 {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
46 static int haswell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
47 struct snd_pcm_hw_params *params)
49 struct snd_interval *rate = hw_param_interval(params,
50 SNDRV_PCM_HW_PARAM_RATE);
51 struct snd_interval *channels = hw_param_interval(params,
52 SNDRV_PCM_HW_PARAM_CHANNELS);
54 /* The ADSP will covert the FE rate to 48k, stereo */
55 rate->min = rate->max = 48000;
56 channels->min = channels->max = 2;
58 /* set SSP0 to 16 bit */
59 snd_mask_set(¶ms->masks[SNDRV_PCM_HW_PARAM_FORMAT -
60 SNDRV_PCM_HW_PARAM_FIRST_MASK],
61 SNDRV_PCM_FORMAT_S16_LE);
65 static int haswell_rt5640_hw_params(struct snd_pcm_substream *substream,
66 struct snd_pcm_hw_params *params)
68 struct snd_soc_pcm_runtime *rtd = substream->private_data;
69 struct snd_soc_dai *codec_dai = rtd->codec_dai;
72 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_MCLK, 12288000,
76 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
80 /* set correct codec filter for DAI format and clock config */
81 snd_soc_update_bits(rtd->codec, 0x83, 0xffff, 0x8000);
86 static struct snd_soc_ops haswell_rt5640_ops = {
87 .hw_params = haswell_rt5640_hw_params,
90 static int haswell_rtd_init(struct snd_soc_pcm_runtime *rtd)
92 struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
93 struct sst_hsw *haswell = pdata->dsp;
96 /* Set ADSP SSP port settings */
97 ret = sst_hsw_device_set_config(haswell, SST_HSW_DEVICE_SSP_0,
98 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
99 SST_HSW_DEVICE_CLOCK_MASTER, 9);
101 dev_err(rtd->dev, "failed to set device config\n");
108 static struct snd_soc_dai_link haswell_rt5640_dais[] = {
109 /* Front End DAI links */
112 .stream_name = "System Playback/Capture",
113 .cpu_dai_name = "System Pin",
114 .platform_name = "haswell-pcm-audio",
116 .codec_name = "snd-soc-dummy",
117 .codec_dai_name = "snd-soc-dummy-dai",
118 .init = haswell_rtd_init,
119 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
125 .stream_name = "Offload0 Playback",
126 .cpu_dai_name = "Offload0 Pin",
127 .platform_name = "haswell-pcm-audio",
129 .codec_name = "snd-soc-dummy",
130 .codec_dai_name = "snd-soc-dummy-dai",
131 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
136 .stream_name = "Offload1 Playback",
137 .cpu_dai_name = "Offload1 Pin",
138 .platform_name = "haswell-pcm-audio",
140 .codec_name = "snd-soc-dummy",
141 .codec_dai_name = "snd-soc-dummy-dai",
142 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
147 .stream_name = "Loopback",
148 .cpu_dai_name = "Loopback Pin",
149 .platform_name = "haswell-pcm-audio",
151 .codec_name = "snd-soc-dummy",
152 .codec_dai_name = "snd-soc-dummy-dai",
153 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
157 /* Back End DAI links */
162 .cpu_dai_name = "snd-soc-dummy-dai",
163 .platform_name = "snd-soc-dummy",
165 .codec_name = "i2c-INT33CA:00",
166 .codec_dai_name = "rt5640-aif1",
167 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
168 SND_SOC_DAIFMT_CBS_CFS,
170 .ignore_pmdown_time = 1,
171 .be_hw_params_fixup = haswell_ssp0_fixup,
172 .ops = &haswell_rt5640_ops,
178 /* audio machine driver for Haswell Lynxpoint DSP + RT5640 */
179 static struct snd_soc_card haswell_rt5640 = {
180 .name = "haswell-rt5640",
181 .owner = THIS_MODULE,
182 .dai_link = haswell_rt5640_dais,
183 .num_links = ARRAY_SIZE(haswell_rt5640_dais),
184 .dapm_widgets = haswell_widgets,
185 .num_dapm_widgets = ARRAY_SIZE(haswell_widgets),
186 .dapm_routes = haswell_rt5640_map,
187 .num_dapm_routes = ARRAY_SIZE(haswell_rt5640_map),
188 .fully_routed = true,
191 static int haswell_audio_probe(struct platform_device *pdev)
193 haswell_rt5640.dev = &pdev->dev;
195 return devm_snd_soc_register_card(&pdev->dev, &haswell_rt5640);
198 static struct platform_driver haswell_audio = {
199 .probe = haswell_audio_probe,
201 .name = "haswell-audio",
205 module_platform_driver(haswell_audio)
207 /* Module information */
208 MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
209 MODULE_DESCRIPTION("Intel SST Audio for Haswell Lynxpoint");
210 MODULE_LICENSE("GPL v2");
211 MODULE_ALIAS("platform:haswell-audio");