blob: 6faa8de24f243fb17299d3d4b54829be5563bd34 [file] [log] [blame]
Mark Browna4b12992014-03-12 23:04:35 +00001/*
2 * Intel Haswell Lynxpoint SST Audio
3 *
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
5 *
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.
9 *
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.
14 *
15 */
16
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>
23
24#include "sst-dsp.h"
25#include "sst-haswell-ipc.h"
26
27#include "../codecs/rt5640.h"
28
29/* Haswell ULT platforms have a Headphone and Mic jack */
30static const struct snd_soc_dapm_widget haswell_widgets[] = {
31 SND_SOC_DAPM_HP("Headphones", NULL),
32 SND_SOC_DAPM_MIC("Mic", NULL),
33};
34
35static const struct snd_soc_dapm_route haswell_rt5640_map[] = {
36
37 {"Headphones", NULL, "HPOR"},
38 {"Headphones", NULL, "HPOL"},
39 {"IN2P", NULL, "Mic"},
40
41 /* CODEC BE connections */
42 {"SSP0 CODEC IN", NULL, "AIF1 Capture"},
43 {"AIF1 Playback", NULL, "SSP0 CODEC OUT"},
44};
45
46static int haswell_ssp0_fixup(struct snd_soc_pcm_runtime *rtd,
47 struct snd_pcm_hw_params *params)
48{
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);
53
54 /* The ADSP will covert the FE rate to 48k, stereo */
55 rate->min = rate->max = 48000;
56 channels->min = channels->max = 2;
57
58 /* set SSP0 to 16 bit */
59 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
60 SNDRV_PCM_HW_PARAM_FIRST_MASK],
61 SNDRV_PCM_FORMAT_S16_LE);
62 return 0;
63}
64
65static int haswell_rt5640_hw_params(struct snd_pcm_substream *substream,
66 struct snd_pcm_hw_params *params)
67{
68 struct snd_soc_pcm_runtime *rtd = substream->private_data;
69 struct snd_soc_dai *codec_dai = rtd->codec_dai;
70 int ret;
71
72 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_MCLK, 12288000,
73 SND_SOC_CLOCK_IN);
74
75 if (ret < 0) {
76 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
77 return ret;
78 }
79
80 /* set correct codec filter for DAI format and clock config */
81 snd_soc_update_bits(rtd->codec, 0x83, 0xffff, 0x8000);
82
83 return ret;
84}
85
86static struct snd_soc_ops haswell_rt5640_ops = {
87 .hw_params = haswell_rt5640_hw_params,
88};
89
90static int haswell_rtd_init(struct snd_soc_pcm_runtime *rtd)
91{
92 struct snd_soc_codec *codec = rtd->codec;
93 struct snd_soc_dapm_context *dapm = &codec->dapm;
94 struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
95 struct sst_hsw *haswell = pdata->dsp;
96 int ret;
97
98 /* Set ADSP SSP port settings */
99 ret = sst_hsw_device_set_config(haswell, SST_HSW_DEVICE_SSP_0,
100 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ,
101 SST_HSW_DEVICE_CLOCK_MASTER, 9);
102 if (ret < 0) {
103 dev_err(rtd->dev, "failed to set device config\n");
104 return ret;
105 }
106
107 /* always connected */
108 snd_soc_dapm_enable_pin(dapm, "Headphones");
109 snd_soc_dapm_enable_pin(dapm, "Mic");
110
111 return 0;
112}
113
114static struct snd_soc_dai_link haswell_rt5640_dais[] = {
115 /* Front End DAI links */
116 {
117 .name = "System",
118 .stream_name = "System Playback",
119 .cpu_dai_name = "System Pin",
120 .platform_name = "haswell-pcm-audio",
121 .dynamic = 1,
122 .codec_name = "snd-soc-dummy",
123 .codec_dai_name = "snd-soc-dummy-dai",
124 .init = haswell_rtd_init,
125 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
126 .dpcm_playback = 1,
127 },
128 {
129 .name = "Offload0",
130 .stream_name = "Offload0 Playback",
131 .cpu_dai_name = "Offload0 Pin",
132 .platform_name = "haswell-pcm-audio",
133 .dynamic = 1,
134 .codec_name = "snd-soc-dummy",
135 .codec_dai_name = "snd-soc-dummy-dai",
136 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
137 .dpcm_playback = 1,
138 },
139 {
140 .name = "Offload1",
141 .stream_name = "Offload1 Playback",
142 .cpu_dai_name = "Offload1 Pin",
143 .platform_name = "haswell-pcm-audio",
144 .dynamic = 1,
145 .codec_name = "snd-soc-dummy",
146 .codec_dai_name = "snd-soc-dummy-dai",
147 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
148 .dpcm_playback = 1,
149 },
150 {
151 .name = "Loopback",
152 .stream_name = "Loopback",
153 .cpu_dai_name = "Loopback Pin",
154 .platform_name = "haswell-pcm-audio",
155 .dynamic = 0,
156 .codec_name = "snd-soc-dummy",
157 .codec_dai_name = "snd-soc-dummy-dai",
158 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
159 .dpcm_capture = 1,
160 },
161 {
162 .name = "Capture",
163 .stream_name = "Capture",
164 .cpu_dai_name = "Capture Pin",
165 .platform_name = "haswell-pcm-audio",
166 .dynamic = 1,
167 .codec_name = "snd-soc-dummy",
168 .codec_dai_name = "snd-soc-dummy-dai",
169 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
170 .dpcm_capture = 1,
171 },
172
173 /* Back End DAI links */
174 {
175 /* SSP0 - Codec */
176 .name = "Codec",
177 .be_id = 0,
178 .cpu_dai_name = "snd-soc-dummy-dai",
179 .platform_name = "snd-soc-dummy",
180 .no_pcm = 1,
181 .codec_name = "i2c-INT33CA:00",
182 .codec_dai_name = "rt5640-aif1",
183 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
184 SND_SOC_DAIFMT_CBS_CFS,
185 .ignore_suspend = 1,
186 .ignore_pmdown_time = 1,
187 .be_hw_params_fixup = haswell_ssp0_fixup,
188 .ops = &haswell_rt5640_ops,
189 .dpcm_playback = 1,
190 .dpcm_capture = 1,
191 },
192};
193
194/* audio machine driver for Haswell Lynxpoint DSP + RT5640 */
195static struct snd_soc_card haswell_rt5640 = {
196 .name = "haswell-rt5640",
197 .owner = THIS_MODULE,
198 .dai_link = haswell_rt5640_dais,
199 .num_links = ARRAY_SIZE(haswell_rt5640_dais),
200 .dapm_widgets = haswell_widgets,
201 .num_dapm_widgets = ARRAY_SIZE(haswell_widgets),
202 .dapm_routes = haswell_rt5640_map,
203 .num_dapm_routes = ARRAY_SIZE(haswell_rt5640_map),
204 .fully_routed = true,
205};
206
207static int haswell_audio_probe(struct platform_device *pdev)
208{
209 haswell_rt5640.dev = &pdev->dev;
210
Jarkko Nikula8eb776a2014-05-28 12:35:39 +0300211 return devm_snd_soc_register_card(&pdev->dev, &haswell_rt5640);
Mark Browna4b12992014-03-12 23:04:35 +0000212}
213
214static struct platform_driver haswell_audio = {
215 .probe = haswell_audio_probe,
Mark Browna4b12992014-03-12 23:04:35 +0000216 .driver = {
217 .name = "haswell-audio",
218 .owner = THIS_MODULE,
219 },
220};
221
222module_platform_driver(haswell_audio)
223
224/* Module information */
225MODULE_AUTHOR("Liam Girdwood, Xingchao Wang");
226MODULE_DESCRIPTION("Intel SST Audio for Haswell Lynxpoint");
227MODULE_LICENSE("GPL v2");
228MODULE_ALIAS("platform:haswell-audio");