blob: 09591144ea7d2ed1bc6159a534a356e1242b767c [file] [log] [blame]
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301/*
2 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
3 *
4 * Copyright (C) 2014 Intel Corp
5 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 */
19
Hans de Goede6a7c05e2018-05-08 17:35:54 +020020#include <linux/i2c.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053021#include <linux/init.h>
22#include <linux/module.h>
Takashi Iwai9f2cf732017-04-23 09:22:56 +020023#include <linux/moduleparam.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053024#include <linux/platform_device.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060025#include <linux/acpi.h>
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -050026#include <linux/clk.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053027#include <linux/device.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060028#include <linux/dmi.h>
Hans de Goede77323102018-05-13 09:24:28 +020029#include <linux/input.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053030#include <linux/slab.h>
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -050031#include <asm/cpu_device_id.h>
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053032#include <sound/pcm.h>
33#include <sound/pcm_params.h>
34#include <sound/soc.h>
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -060035#include <sound/jack.h>
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -050036#include <sound/soc-acpi.h>
Hans de Goedea3ad2912018-05-13 09:24:26 +020037#include <dt-bindings/sound/rt5640.h>
Jie Yange56c72d2015-04-02 15:37:02 +080038#include "../../codecs/rt5640.h"
Jie Yangb97169d2015-04-02 15:37:04 +080039#include "../atom/sst-atom-controls.h"
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -050040#include "../common/sst-dsp.h"
Subhransu S. Prusty996cc842014-11-19 15:13:27 +053041
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060042enum {
43 BYT_RT5640_DMIC1_MAP,
44 BYT_RT5640_DMIC2_MAP,
45 BYT_RT5640_IN1_MAP,
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -050046 BYT_RT5640_IN3_MAP,
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060047};
48
Hans de Goede77323102018-05-13 09:24:28 +020049enum {
50 BYT_RT5640_JD_SRC_GPIO1 = (RT5640_JD_SRC_GPIO1 << 4),
51 BYT_RT5640_JD_SRC_JD1_IN4P = (RT5640_JD_SRC_JD1_IN4P << 4),
52 BYT_RT5640_JD_SRC_JD2_IN4N = (RT5640_JD_SRC_JD2_IN4N << 4),
53 BYT_RT5640_JD_SRC_GPIO2 = (RT5640_JD_SRC_GPIO2 << 4),
54 BYT_RT5640_JD_SRC_GPIO3 = (RT5640_JD_SRC_GPIO3 << 4),
55 BYT_RT5640_JD_SRC_GPIO4 = (RT5640_JD_SRC_GPIO4 << 4),
56};
Irina Tirdeadf1a2772016-08-12 16:27:57 -050057
Hans de Goede77323102018-05-13 09:24:28 +020058enum {
59 BYT_RT5640_OVCD_TH_600UA = (6 << 8),
60 BYT_RT5640_OVCD_TH_1500UA = (15 << 8),
61 BYT_RT5640_OVCD_TH_2000UA = (20 << 8),
62};
63
64enum {
65 BYT_RT5640_OVCD_SF_0P5 = (RT5640_OVCD_SF_0P5 << 13),
66 BYT_RT5640_OVCD_SF_0P75 = (RT5640_OVCD_SF_0P75 << 13),
67 BYT_RT5640_OVCD_SF_1P0 = (RT5640_OVCD_SF_1P0 << 13),
68 BYT_RT5640_OVCD_SF_1P5 = (RT5640_OVCD_SF_1P5 << 13),
69};
70
71#define BYT_RT5640_MAP(quirk) ((quirk) & GENMASK(3, 0))
72#define BYT_RT5640_JDSRC(quirk) (((quirk) & GENMASK(7, 4)) >> 4)
73#define BYT_RT5640_OVCD_TH(quirk) (((quirk) & GENMASK(12, 8)) >> 8)
74#define BYT_RT5640_OVCD_SF(quirk) (((quirk) & GENMASK(14, 13)) >> 13)
75#define BYT_RT5640_JD_NOT_INV BIT(16)
76#define BYT_RT5640_MONO_SPEAKER BIT(17)
77#define BYT_RT5640_DIFF_MIC BIT(18) /* default is single-ended */
78#define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
79#define BYT_RT5640_SSP0_AIF1 BIT(20)
80#define BYT_RT5640_SSP0_AIF2 BIT(21)
81#define BYT_RT5640_MCLK_EN BIT(22)
82#define BYT_RT5640_MCLK_25MHZ BIT(23)
83
Hans de Goede96a388fe2018-05-13 09:24:30 +020084#define BYTCR_INPUT_DEFAULTS \
85 (BYT_RT5640_IN3_MAP | \
Hans de Goede56ff4402018-05-13 09:24:31 +020086 BYT_RT5640_JD_SRC_JD1_IN4P | \
87 BYT_RT5640_OVCD_TH_2000UA | \
88 BYT_RT5640_OVCD_SF_0P75 | \
Hans de Goede96a388fe2018-05-13 09:24:30 +020089 BYT_RT5640_DIFF_MIC)
90
Hans de Goede77323102018-05-13 09:24:28 +020091/* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
92#define MAX_NO_PROPS 6
Hans de Goede6a7c05e2018-05-08 17:35:54 +020093
Irina Tirdeadf1a2772016-08-12 16:27:57 -050094struct byt_rt5640_private {
Hans de Goede77323102018-05-13 09:24:28 +020095 struct snd_soc_jack jack;
Irina Tirdeadf1a2772016-08-12 16:27:57 -050096 struct clk *mclk;
97};
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -050098static bool is_bytcr;
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -060099
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -0600100static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
Takashi Iwai9f2cf732017-04-23 09:22:56 +0200101static unsigned int quirk_override;
Takashi Iwai0b2c9f82017-04-24 23:34:30 +0200102module_param_named(quirk, quirk_override, uint, 0444);
Takashi Iwai9f2cf732017-04-23 09:22:56 +0200103MODULE_PARM_DESC(quirk, "Board-specific quirk override");
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500104
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500105static void log_quirks(struct device *dev)
106{
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500107 int map;
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500108 bool has_mclk = false;
109 bool has_ssp0 = false;
110 bool has_ssp0_aif1 = false;
111 bool has_ssp0_aif2 = false;
112 bool has_ssp2_aif2 = false;
113
114 map = BYT_RT5640_MAP(byt_rt5640_quirk);
115 switch (map) {
116 case BYT_RT5640_DMIC1_MAP:
117 dev_info(dev, "quirk DMIC1_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500118 break;
119 case BYT_RT5640_DMIC2_MAP:
120 dev_info(dev, "quirk DMIC2_MAP enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500121 break;
122 case BYT_RT5640_IN1_MAP:
123 dev_info(dev, "quirk IN1_MAP enabled\n");
124 break;
125 case BYT_RT5640_IN3_MAP:
126 dev_info(dev, "quirk IN3_MAP enabled\n");
127 break;
128 default:
129 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
130 break;
131 }
Hans de Goede77323102018-05-13 09:24:28 +0200132 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
133 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
134 BYT_RT5640_JDSRC(byt_rt5640_quirk));
135 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
136 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
137 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
138 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
139 }
140 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
141 dev_info(dev, "quirk JD_NOT_INV enabled\n");
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500142 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500143 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
Hans de Goedea3ad2912018-05-13 09:24:26 +0200144 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
145 dev_info(dev, "quirk DIFF_MIC enabled\n");
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500146 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
147 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
148 has_ssp0 = true;
149 has_ssp0_aif1 = true;
150 }
151 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
152 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
153 has_ssp0 = true;
154 has_ssp0_aif2 = true;
155 }
156 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
157 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
158 has_ssp2_aif2 = true;
159 }
160 if (is_bytcr && !has_ssp0)
161 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
162 if (has_ssp0_aif1 && has_ssp0_aif2)
163 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
164 if (has_ssp0 && has_ssp2_aif2)
165 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
166
167 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
168 dev_info(dev, "quirk MCLK_EN enabled\n");
169 has_mclk = true;
170 }
171 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
172 if (has_mclk)
173 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
174 else
175 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
176 }
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500177}
178
Hans de Goedebcd9a322018-05-08 17:35:53 +0200179static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
180 int rate)
181{
182 int ret;
183
184 /* Configure the PLL before selecting it */
185 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
186 /* use bitclock as PLL input */
187 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
188 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
189 /* 2x16 bit slots on SSP0 */
190 ret = snd_soc_dai_set_pll(codec_dai, 0,
191 RT5640_PLL1_S_BCLK1,
192 rate * 32, rate * 512);
193 } else {
194 /* 2x15 bit slots on SSP2 */
195 ret = snd_soc_dai_set_pll(codec_dai, 0,
196 RT5640_PLL1_S_BCLK1,
197 rate * 50, rate * 512);
198 }
199 } else {
200 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
201 ret = snd_soc_dai_set_pll(codec_dai, 0,
202 RT5640_PLL1_S_MCLK,
203 25000000, rate * 512);
204 } else {
205 ret = snd_soc_dai_set_pll(codec_dai, 0,
206 RT5640_PLL1_S_MCLK,
207 19200000, rate * 512);
208 }
209 }
210
211 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200212 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200213 return ret;
214 }
215
216 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
217 rate * 512, SND_SOC_CLOCK_IN);
218 if (ret < 0) {
Hans de Goedea3a956a2018-05-11 11:52:16 +0200219 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
Hans de Goedebcd9a322018-05-08 17:35:53 +0200220 return ret;
221 }
222
223 return 0;
224}
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -0500225
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500226#define BYT_CODEC_DAI1 "rt5640-aif1"
227#define BYT_CODEC_DAI2 "rt5640-aif2"
228
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500229static int platform_clock_control(struct snd_soc_dapm_widget *w,
230 struct snd_kcontrol *k, int event)
231{
232 struct snd_soc_dapm_context *dapm = w->dapm;
233 struct snd_soc_card *card = dapm->card;
234 struct snd_soc_dai *codec_dai;
235 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
236 int ret;
237
Pierre-Louis Bossartdfb6ec72017-10-12 18:38:03 -0500238 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
239 if (!codec_dai)
240 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
241
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500242 if (!codec_dai) {
243 dev_err(card->dev,
244 "Codec dai not found; Unable to set platform clock\n");
245 return -EIO;
246 }
247
248 if (SND_SOC_DAPM_EVENT_ON(event)) {
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500249 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500250 ret = clk_prepare_enable(priv->mclk);
251 if (ret < 0) {
252 dev_err(card->dev,
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -0500253 "could not configure MCLK state\n");
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500254 return ret;
255 }
256 }
Hans de Goedebcd9a322018-05-08 17:35:53 +0200257 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500258 } else {
259 /*
260 * Set codec clock source to internal clock before
261 * turning off the platform clock. Codec needs clock
262 * for Jack detection and button press
263 */
264 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
Pierre-Louis Bossart60448b02017-01-04 15:44:52 -0600265 48000 * 512,
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500266 SND_SOC_CLOCK_IN);
267 if (!ret) {
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500268 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500269 clk_disable_unprepare(priv->mclk);
270 }
271 }
272
273 if (ret < 0) {
274 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
275 return ret;
276 }
277
278 return 0;
279}
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -0600280
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600281static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530282 SND_SOC_DAPM_HP("Headphone", NULL),
283 SND_SOC_DAPM_MIC("Headset Mic", NULL),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600284 SND_SOC_DAPM_MIC("Internal Mic", NULL),
285 SND_SOC_DAPM_SPK("Speaker", NULL),
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500286 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
287 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
288 SND_SOC_DAPM_POST_PMD),
289
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530290};
291
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600292static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500293 {"Headphone", NULL, "Platform Clock"},
294 {"Headset Mic", NULL, "Platform Clock"},
295 {"Internal Mic", NULL, "Platform Clock"},
296 {"Speaker", NULL, "Platform Clock"},
297
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530298 {"Headset Mic", NULL, "MICBIAS1"},
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600299 {"IN2P", NULL, "Headset Mic"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530300 {"Headphone", NULL, "HPOL"},
301 {"Headphone", NULL, "HPOR"},
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530302};
303
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600304static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
305 {"DMIC1", NULL, "Internal Mic"},
306};
307
308static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
309 {"DMIC2", NULL, "Internal Mic"},
310};
311
312static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
313 {"Internal Mic", NULL, "MICBIAS1"},
314 {"IN1P", NULL, "Internal Mic"},
315};
316
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500317static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
318 {"Internal Mic", NULL, "MICBIAS1"},
319 {"IN3P", NULL, "Internal Mic"},
320};
321
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500322static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
323 {"ssp2 Tx", NULL, "codec_out0"},
324 {"ssp2 Tx", NULL, "codec_out1"},
325 {"codec_in0", NULL, "ssp2 Rx"},
326 {"codec_in1", NULL, "ssp2 Rx"},
327
328 {"AIF1 Playback", NULL, "ssp2 Tx"},
329 {"ssp2 Rx", NULL, "AIF1 Capture"},
330};
331
332static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
333 {"ssp2 Tx", NULL, "codec_out0"},
334 {"ssp2 Tx", NULL, "codec_out1"},
335 {"codec_in0", NULL, "ssp2 Rx"},
336 {"codec_in1", NULL, "ssp2 Rx"},
337
338 {"AIF2 Playback", NULL, "ssp2 Tx"},
339 {"ssp2 Rx", NULL, "AIF2 Capture"},
340};
341
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500342static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
343 {"ssp0 Tx", NULL, "modem_out"},
344 {"modem_in", NULL, "ssp0 Rx"},
345
346 {"AIF1 Playback", NULL, "ssp0 Tx"},
347 {"ssp0 Rx", NULL, "AIF1 Capture"},
348};
349
350static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
351 {"ssp0 Tx", NULL, "modem_out"},
352 {"modem_in", NULL, "ssp0 Rx"},
353
354 {"AIF2 Playback", NULL, "ssp0 Tx"},
355 {"ssp0 Rx", NULL, "AIF2 Capture"},
356};
357
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500358static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
359 {"Speaker", NULL, "SPOLP"},
360 {"Speaker", NULL, "SPOLN"},
361 {"Speaker", NULL, "SPORP"},
362 {"Speaker", NULL, "SPORN"},
363};
364
365static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
366 {"Speaker", NULL, "SPOLP"},
367 {"Speaker", NULL, "SPOLN"},
368};
369
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600370static const struct snd_kcontrol_new byt_rt5640_controls[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530371 SOC_DAPM_PIN_SWITCH("Headphone"),
372 SOC_DAPM_PIN_SWITCH("Headset Mic"),
Pierre-Louis Bossarte2be1da2015-12-17 20:35:40 -0600373 SOC_DAPM_PIN_SWITCH("Internal Mic"),
374 SOC_DAPM_PIN_SWITCH("Speaker"),
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530375};
376
Hans de Goede77323102018-05-13 09:24:28 +0200377static struct snd_soc_jack_pin rt5640_pins[] = {
378 {
379 .pin = "Headphone",
380 .mask = SND_JACK_HEADPHONE,
381 },
382 {
383 .pin = "Headset Mic",
384 .mask = SND_JACK_MICROPHONE,
385 },
386};
387
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600388static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530389 struct snd_pcm_hw_params *params)
390{
391 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Hans de Goedebcd9a322018-05-08 17:35:53 +0200392 struct snd_soc_dai *dai = rtd->codec_dai;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530393
Hans de Goedebcd9a322018-05-08 17:35:53 +0200394 return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530395}
396
Hans de Goede3c0d0112018-05-13 09:24:32 +0200397/* Please keep this list alphabetically sorted */
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600398static const struct dmi_system_id byt_rt5640_quirk_table[] = {
Hans de Goedeec8e8412018-05-13 09:24:34 +0200399 { /* Acer Iconia Tab 8 W1-810 */
400 .matches = {
401 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
402 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
403 },
404 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
405 BYT_RT5640_JD_SRC_JD1_IN4P |
Hans de Goedef12a0a32018-06-03 15:42:32 +0200406 BYT_RT5640_OVCD_TH_1500UA |
Hans de Goedeec8e8412018-05-13 09:24:34 +0200407 BYT_RT5640_OVCD_SF_0P75 |
408 BYT_RT5640_SSP0_AIF1 |
409 BYT_RT5640_MCLK_EN),
410 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600411 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600412 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200413 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
414 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
415 },
416 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
417 BYT_RT5640_MCLK_EN |
418 BYT_RT5640_SSP0_AIF1),
419
420 },
421 {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200422 .matches = {
Hans de Goedebcf441a2018-05-28 22:26:49 +0200423 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
424 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
425 },
426 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
427 BYT_RT5640_MONO_SPEAKER |
428 BYT_RT5640_SSP0_AIF1 |
429 BYT_RT5640_MCLK_EN),
430 },
431 {
432 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500433 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
434 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600435 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500436 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200437 BYT_RT5640_JD_SRC_JD2_IN4N |
438 BYT_RT5640_OVCD_TH_2000UA |
439 BYT_RT5640_OVCD_SF_0P75 |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500440 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600441 },
442 {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600443 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500444 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
445 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
446 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500447 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
448 BYT_RT5640_MONO_SPEAKER |
449 BYT_RT5640_DIFF_MIC |
450 BYT_RT5640_SSP0_AIF2 |
451 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500452 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200453 { /* Chuwi Vi8 (CWI506) */
454 .matches = {
455 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
456 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
457 /* The above are too generic, also match BIOS info */
458 DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
459 },
460 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
461 BYT_RT5640_MONO_SPEAKER |
462 BYT_RT5640_SSP0_AIF1 |
463 BYT_RT5640_MCLK_EN),
464 },
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500465 {
Hans de Goeded5a18262018-06-08 10:19:25 +0200466 /* Chuwi Vi10 (CWI505) */
467 .matches = {
468 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
469 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
470 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
471 DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
472 },
473 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
474 BYT_RT5640_JD_SRC_JD2_IN4N |
475 BYT_RT5640_OVCD_TH_2000UA |
476 BYT_RT5640_OVCD_SF_0P75 |
477 BYT_RT5640_DIFF_MIC |
478 BYT_RT5640_SSP0_AIF1 |
479 BYT_RT5640_MCLK_EN),
480 },
481 {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500482 .matches = {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200483 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
484 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
485 },
486 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
487 },
Hans de Goede9ee6f8a2018-07-01 11:30:23 +0200488 { /* Connect Tablet 9 */
489 .matches = {
490 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
491 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
492 },
493 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
494 BYT_RT5640_MONO_SPEAKER |
495 BYT_RT5640_SSP0_AIF1 |
496 BYT_RT5640_MCLK_EN),
497 },
Hans de Goede3c0d0112018-05-13 09:24:32 +0200498 {
Hans de Goede3c0d0112018-05-13 09:24:32 +0200499 .matches = {
Hans de Goede6748fb72018-05-13 09:24:27 +0200500 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500501 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600502 },
Hans de Goede6748fb72018-05-13 09:24:27 +0200503 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
Hans de Goede77323102018-05-13 09:24:28 +0200504 BYT_RT5640_JD_SRC_JD2_IN4N |
505 BYT_RT5640_OVCD_TH_2000UA |
506 BYT_RT5640_OVCD_SF_0P75 |
Hans de Goede6748fb72018-05-13 09:24:27 +0200507 BYT_RT5640_MONO_SPEAKER |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500508 BYT_RT5640_MCLK_EN),
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600509 },
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600510 {
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600511 .matches = {
Pierre-Louis Bossart73442e32016-08-12 16:27:44 -0500512 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
513 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600514 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500515 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
516 BYT_RT5640_MCLK_EN),
Jorge Fernandez Monteagudo55fc2052016-01-04 17:20:30 -0600517 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200518 { /* HP Pavilion x2 10-n000nd */
519 .matches = {
520 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
521 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
522 },
523 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
524 BYT_RT5640_JD_SRC_JD2_IN4N |
525 BYT_RT5640_OVCD_TH_1500UA |
526 BYT_RT5640_OVCD_SF_0P75 |
527 BYT_RT5640_SSP0_AIF1 |
528 BYT_RT5640_MCLK_EN),
529 },
530 { /* HP Stream 7 */
531 .matches = {
532 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
533 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
534 },
535 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
536 BYT_RT5640_MONO_SPEAKER |
537 BYT_RT5640_JD_NOT_INV |
538 BYT_RT5640_SSP0_AIF1 |
539 BYT_RT5640_MCLK_EN),
540 },
541 { /* I.T.Works TW891 */
542 .matches = {
543 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
544 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
545 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
546 DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
547 },
548 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
549 BYT_RT5640_MONO_SPEAKER |
550 BYT_RT5640_SSP0_AIF1 |
551 BYT_RT5640_MCLK_EN),
552 },
553 { /* Lamina I8270 / T701BR.SE */
554 .matches = {
555 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
556 DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
557 },
558 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
559 BYT_RT5640_MONO_SPEAKER |
560 BYT_RT5640_JD_NOT_INV |
561 BYT_RT5640_SSP0_AIF1 |
562 BYT_RT5640_MCLK_EN),
563 },
Hans de Goede81583af2018-07-07 12:22:10 +0200564 { /* Lenovo Miix 2 8 */
565 .matches = {
566 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
567 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
568 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
569 },
570 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
571 BYT_RT5640_JD_SRC_JD2_IN4N |
572 BYT_RT5640_OVCD_TH_2000UA |
573 BYT_RT5640_OVCD_SF_0P75 |
574 BYT_RT5640_MONO_SPEAKER |
575 BYT_RT5640_MCLK_EN),
576 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200577 { /* Linx Linx7 tablet */
578 .matches = {
579 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
580 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
581 },
582 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
583 BYT_RT5640_MONO_SPEAKER |
584 BYT_RT5640_JD_NOT_INV |
585 BYT_RT5640_SSP0_AIF1 |
586 BYT_RT5640_MCLK_EN),
587 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200588 { /* MSI S100 tablet */
589 .matches = {
590 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
591 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
592 },
593 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
594 BYT_RT5640_JD_SRC_JD2_IN4N |
595 BYT_RT5640_OVCD_TH_2000UA |
596 BYT_RT5640_OVCD_SF_0P75 |
597 BYT_RT5640_MONO_SPEAKER |
598 BYT_RT5640_DIFF_MIC |
599 BYT_RT5640_MCLK_EN),
600 },
Hans de Goede6cea3592018-06-03 15:42:31 +0200601 { /* Nuvison/TMax TM800W560 */
602 .matches = {
603 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
604 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
605 },
606 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
607 BYT_RT5640_JD_SRC_JD2_IN4N |
608 BYT_RT5640_OVCD_TH_2000UA |
609 BYT_RT5640_OVCD_SF_0P75 |
610 BYT_RT5640_JD_NOT_INV |
611 BYT_RT5640_DIFF_MIC |
612 BYT_RT5640_SSP0_AIF1 |
613 BYT_RT5640_MCLK_EN),
614 },
Hans de Goede260c48b2018-08-12 13:42:06 +0200615 { /* Onda v975w */
616 .matches = {
617 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
618 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
619 /* The above are too generic, also match BIOS info */
620 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
621 DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
622 },
623 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
624 BYT_RT5640_JD_SRC_JD2_IN4N |
625 BYT_RT5640_OVCD_TH_2000UA |
626 BYT_RT5640_OVCD_SF_0P75 |
627 BYT_RT5640_DIFF_MIC |
628 BYT_RT5640_MCLK_EN),
629 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200630 { /* Pipo W4 */
631 .matches = {
632 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
633 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
634 /* The above are too generic, also match BIOS info */
635 DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
636 },
637 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
638 BYT_RT5640_MONO_SPEAKER |
639 BYT_RT5640_SSP0_AIF1 |
640 BYT_RT5640_MCLK_EN),
641 },
642 { /* Point of View Mobii TAB-P800W (V2.0) */
643 .matches = {
644 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
645 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
646 /* The above are too generic, also match BIOS info */
647 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
648 DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
649 },
650 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
651 BYT_RT5640_JD_SRC_JD2_IN4N |
652 BYT_RT5640_OVCD_TH_2000UA |
653 BYT_RT5640_OVCD_SF_0P75 |
654 BYT_RT5640_MONO_SPEAKER |
655 BYT_RT5640_DIFF_MIC |
656 BYT_RT5640_SSP0_AIF2 |
657 BYT_RT5640_MCLK_EN),
658 },
659 { /* Point of View Mobii TAB-P800W (V2.1) */
660 .matches = {
661 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
662 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
663 /* The above are too generic, also match BIOS info */
664 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
665 DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
666 },
667 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
668 BYT_RT5640_JD_SRC_JD2_IN4N |
669 BYT_RT5640_OVCD_TH_2000UA |
670 BYT_RT5640_OVCD_SF_0P75 |
671 BYT_RT5640_MONO_SPEAKER |
672 BYT_RT5640_DIFF_MIC |
673 BYT_RT5640_SSP0_AIF2 |
674 BYT_RT5640_MCLK_EN),
675 },
Irina Tirdea0565e772016-08-12 16:27:58 -0500676 {
Irina Tirdea0565e772016-08-12 16:27:58 -0500677 .matches = {
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500678 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
679 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
680 },
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500681 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
682 BYT_RT5640_MCLK_EN |
683 BYT_RT5640_SSP0_AIF1),
Pierre-Louis Bossartec1c90e2016-08-12 16:27:59 -0500684 },
Hans de Goedeec8e8412018-05-13 09:24:34 +0200685 { /* Toshiba Satellite Click Mini L9W-B */
686 .matches = {
687 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
688 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
689 },
690 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
691 BYT_RT5640_JD_SRC_JD2_IN4N |
692 BYT_RT5640_OVCD_TH_1500UA |
693 BYT_RT5640_OVCD_SF_0P75 |
694 BYT_RT5640_SSP0_AIF1 |
695 BYT_RT5640_MCLK_EN),
696 },
Hans de Goede3c0d0112018-05-13 09:24:32 +0200697 { /* Catch-all for generic Insyde tablets, must be last */
youling25757180042017-01-04 15:44:53 -0600698 .matches = {
699 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
700 },
Hans de Goede96a388fe2018-05-13 09:24:30 +0200701 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500702 BYT_RT5640_MCLK_EN |
703 BYT_RT5640_SSP0_AIF1),
youling25757180042017-01-04 15:44:53 -0600704
705 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600706 {}
707};
708
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200709/*
710 * Note this MUST be called before snd_soc_register_card(), so that the props
711 * are in place before the codec component driver's probe function parses them.
712 */
713static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name)
714{
715 struct property_entry props[MAX_NO_PROPS] = {};
716 struct device *i2c_dev;
717 int ret, cnt = 0;
718
719 i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name);
720 if (!i2c_dev)
721 return -EPROBE_DEFER;
722
723 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
Hans de Goedea3ad2912018-05-13 09:24:26 +0200724 case BYT_RT5640_DMIC1_MAP:
725 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
726 RT5640_DMIC1_DATA_PIN_IN1P);
727 break;
728 case BYT_RT5640_DMIC2_MAP:
729 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
730 RT5640_DMIC2_DATA_PIN_IN1N);
731 break;
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200732 case BYT_RT5640_IN1_MAP:
733 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
734 props[cnt++] =
735 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
736 break;
737 case BYT_RT5640_IN3_MAP:
738 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
739 props[cnt++] =
740 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
741 break;
742 }
743
Hans de Goede77323102018-05-13 09:24:28 +0200744 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
745 props[cnt++] = PROPERTY_ENTRY_U32(
746 "realtek,jack-detect-source",
747 BYT_RT5640_JDSRC(byt_rt5640_quirk));
748
749 props[cnt++] = PROPERTY_ENTRY_U32(
750 "realtek,over-current-threshold-microamp",
751 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
752
753 props[cnt++] = PROPERTY_ENTRY_U32(
754 "realtek,over-current-scale-factor",
755 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
756 }
757
758 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
759 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
760
Hans de Goede6a7c05e2018-05-08 17:35:54 +0200761 ret = device_add_properties(i2c_dev, props);
762 put_device(i2c_dev);
763
764 return ret;
765}
766
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600767static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
768{
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600769 struct snd_soc_card *card = runtime->card;
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500770 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000771 struct snd_soc_component *component = runtime->codec_dai->component;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500772 const struct snd_soc_dapm_route *custom_map;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600773 int num_routes;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500774 int ret;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600775
776 card->dapm.idle_bias_off = true;
777
Hans de Goede77323102018-05-13 09:24:28 +0200778 /* Start with RC clk for jack-detect (we disable MCLK below) */
779 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
780 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
781 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
782
Kuninori Morimotod5a41b52018-01-29 03:42:46 +0000783 rt5640_sel_asrc_clk_src(component,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -0600784 RT5640_DA_STEREO_FILTER |
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500785 RT5640_DA_MONO_L_FILTER |
786 RT5640_DA_MONO_R_FILTER |
787 RT5640_AD_STEREO_FILTER |
788 RT5640_AD_MONO_L_FILTER |
789 RT5640_AD_MONO_R_FILTER,
Pierre-Louis Bossart0ec66e2d2016-01-04 17:20:27 -0600790 RT5640_CLK_SEL_ASRC);
791
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600792 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
793 ARRAY_SIZE(byt_rt5640_controls));
794 if (ret) {
795 dev_err(card->dev, "unable to add card controls\n");
796 return ret;
797 }
798
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600799 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
800 case BYT_RT5640_IN1_MAP:
801 custom_map = byt_rt5640_intmic_in1_map;
802 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
803 break;
Pierre-Louis Bossart59e8b652016-08-12 16:27:54 -0500804 case BYT_RT5640_IN3_MAP:
805 custom_map = byt_rt5640_intmic_in3_map;
806 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
807 break;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600808 case BYT_RT5640_DMIC2_MAP:
809 custom_map = byt_rt5640_intmic_dmic2_map;
810 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
811 break;
812 default:
813 custom_map = byt_rt5640_intmic_dmic1_map;
814 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
815 }
816
817 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
818 if (ret)
819 return ret;
820
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500821 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
822 ret = snd_soc_dapm_add_routes(&card->dapm,
823 byt_rt5640_ssp2_aif2_map,
824 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -0500825 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
826 ret = snd_soc_dapm_add_routes(&card->dapm,
827 byt_rt5640_ssp0_aif1_map,
828 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
829 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
830 ret = snd_soc_dapm_add_routes(&card->dapm,
831 byt_rt5640_ssp0_aif2_map,
832 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -0500833 } else {
834 ret = snd_soc_dapm_add_routes(&card->dapm,
835 byt_rt5640_ssp2_aif1_map,
836 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
837 }
838 if (ret)
839 return ret;
840
Pierre-Louis Bossart68817cd2016-08-12 16:27:45 -0500841 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
842 ret = snd_soc_dapm_add_routes(&card->dapm,
843 byt_rt5640_mono_spk_map,
844 ARRAY_SIZE(byt_rt5640_mono_spk_map));
845 } else {
846 ret = snd_soc_dapm_add_routes(&card->dapm,
847 byt_rt5640_stereo_spk_map,
848 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
849 }
850 if (ret)
851 return ret;
852
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600853 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
854 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
855
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -0500856 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500857 /*
858 * The firmware might enable the clock at
859 * boot (this information may or may not
860 * be reflected in the enable clock register).
861 * To change the rate we must disable the clock
862 * first to cover these cases. Due to common
863 * clock framework restrictions that do not allow
864 * to disable a clock that has not been enabled,
865 * we need to enable the clock first.
866 */
867 ret = clk_prepare_enable(priv->mclk);
868 if (!ret)
869 clk_disable_unprepare(priv->mclk);
870
871 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
872 ret = clk_set_rate(priv->mclk, 25000000);
873 else
874 ret = clk_set_rate(priv->mclk, 19200000);
875
Hans de Goede77323102018-05-13 09:24:28 +0200876 if (ret) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500877 dev_err(card->dev, "unable to set MCLK rate\n");
Hans de Goede77323102018-05-13 09:24:28 +0200878 return ret;
879 }
Irina Tirdeadf1a2772016-08-12 16:27:57 -0500880 }
881
Hans de Goede77323102018-05-13 09:24:28 +0200882 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
883 ret = snd_soc_card_jack_new(card, "Headset",
884 SND_JACK_HEADSET | SND_JACK_BTN_0,
885 &priv->jack, rt5640_pins,
886 ARRAY_SIZE(rt5640_pins));
887 if (ret) {
888 dev_err(card->dev, "Jack creation failed %d\n", ret);
889 return ret;
890 }
891 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
892 KEY_PLAYPAUSE);
893 snd_soc_component_set_jack(component, &priv->jack, NULL);
894 }
895
896 return 0;
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -0600897}
898
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600899static const struct snd_soc_pcm_stream byt_rt5640_dai_params = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530900 .formats = SNDRV_PCM_FMTBIT_S24_LE,
901 .rate_min = 48000,
902 .rate_max = 48000,
903 .channels_min = 2,
904 .channels_max = 2,
905};
906
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600907static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530908 struct snd_pcm_hw_params *params)
909{
910 struct snd_interval *rate = hw_param_interval(params,
911 SNDRV_PCM_HW_PARAM_RATE);
912 struct snd_interval *channels = hw_param_interval(params,
913 SNDRV_PCM_HW_PARAM_CHANNELS);
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -0600914 int ret;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530915
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500916 /* The DSP will covert the FE rate to 48k, stereo */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530917 rate->min = rate->max = 48000;
918 channels->min = channels->max = 2;
919
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500920 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
921 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -0600922
Pierre-Louis Bossart8f98307d2016-08-16 18:28:22 -0500923 /* set SSP0 to 16-bit */
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500924 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
925
926 /*
927 * Default mode for SSP configuration is TDM 4 slot, override config
928 * with explicit setting to I2S 2ch 16-bit. The word length is set with
929 * dai_set_tdm_slot() since there is no other API exposed
930 */
931 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
932 SND_SOC_DAIFMT_I2S |
Pierre-Louis Bossartf12f5c82017-01-26 14:09:29 -0600933 SND_SOC_DAIFMT_NB_NF |
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500934 SND_SOC_DAIFMT_CBS_CFS
935 );
936 if (ret < 0) {
937 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
938 return ret;
939 }
940
941 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
942 if (ret < 0) {
943 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
944 return ret;
945 }
946
947 } else {
948
949 /* set SSP2 to 24-bit */
950 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
951
952 /*
953 * Default mode for SSP configuration is TDM 4 slot, override config
954 * with explicit setting to I2S 2ch 24-bit. The word length is set with
955 * dai_set_tdm_slot() since there is no other API exposed
956 */
957 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
958 SND_SOC_DAIFMT_I2S |
Pierre-Louis Bossartf12f5c82017-01-26 14:09:29 -0600959 SND_SOC_DAIFMT_NB_NF |
Pierre-Louis Bossart038a50e2016-08-12 16:27:52 -0500960 SND_SOC_DAIFMT_CBS_CFS
961 );
962 if (ret < 0) {
963 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
964 return ret;
965 }
966
967 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
968 if (ret < 0) {
969 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
970 return ret;
971 }
Sebastien Guiriec3f27ded2015-12-17 20:35:39 -0600972 }
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530973 return 0;
974}
975
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600976static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530977{
Lars-Peter Clausend0a1b662015-10-18 15:39:30 +0200978 return snd_pcm_hw_constraint_single(substream->runtime,
979 SNDRV_PCM_HW_PARAM_RATE, 48000);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530980}
981
Julia Lawall9b6fdef2016-10-15 16:55:49 +0200982static const struct snd_soc_ops byt_rt5640_aif1_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600983 .startup = byt_rt5640_aif1_startup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530984};
985
Julia Lawall9b6fdef2016-10-15 16:55:49 +0200986static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600987 .hw_params = byt_rt5640_aif1_hw_params,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530988};
989
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -0600990static struct snd_soc_dai_link byt_rt5640_dais[] = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530991 [MERR_DPCM_AUDIO] = {
992 .name = "Baytrail Audio Port",
993 .stream_name = "Baytrail Audio",
994 .cpu_dai_name = "media-cpu-dai",
995 .codec_dai_name = "snd-soc-dummy-dai",
996 .codec_name = "snd-soc-dummy",
997 .platform_name = "sst-mfld-platform",
Takashi Iwai6e4cac22017-04-24 14:09:55 +0200998 .nonatomic = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +0530999 .dynamic = 1,
1000 .dpcm_playback = 1,
1001 .dpcm_capture = 1,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001002 .ops = &byt_rt5640_aif1_ops,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301003 },
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001004 [MERR_DPCM_DEEP_BUFFER] = {
1005 .name = "Deep-Buffer Audio Port",
1006 .stream_name = "Deep-Buffer Audio",
1007 .cpu_dai_name = "deepbuffer-cpu-dai",
1008 .codec_dai_name = "snd-soc-dummy-dai",
1009 .codec_name = "snd-soc-dummy",
1010 .platform_name = "sst-mfld-platform",
Pierre-Louis Bossartd35eb962015-12-17 20:35:45 -06001011 .nonatomic = true,
1012 .dynamic = 1,
1013 .dpcm_playback = 1,
1014 .ops = &byt_rt5640_aif1_ops,
1015 },
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301016 /* back ends */
1017 {
1018 .name = "SSP2-Codec",
Pierre-Louis Bossart149f7752017-10-12 18:38:04 -05001019 .id = 0,
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001020 .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301021 .platform_name = "sst-mfld-platform",
1022 .no_pcm = 1,
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001023 .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */
Pierre-Louis Bossart7762ef42016-01-04 17:20:29 -06001024 .codec_name = "i2c-10EC5640:00", /* overwritten with HID */
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301025 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1026 | SND_SOC_DAIFMT_CBS_CFS,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001027 .be_hw_params_fixup = byt_rt5640_codec_fixup,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301028 .ignore_suspend = 1,
Takashi Iwai6e4cac22017-04-24 14:09:55 +02001029 .nonatomic = true,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301030 .dpcm_playback = 1,
1031 .dpcm_capture = 1,
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001032 .init = byt_rt5640_init,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001033 .ops = &byt_rt5640_be_ssp2_ops,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301034 },
1035};
1036
1037/* SoC card */
Hans de Goede77323102018-05-13 09:24:28 +02001038static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
1039static char byt_rt5640_codec_aif_name[12]; /* = "rt5640-aif[1|2]" */
1040static char byt_rt5640_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
Hans de Goede063422c2018-05-13 09:24:35 +02001041static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
Hans de Goede77323102018-05-13 09:24:28 +02001042
1043static int byt_rt5640_suspend(struct snd_soc_card *card)
1044{
1045 struct snd_soc_component *component;
1046
1047 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1048 return 0;
1049
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001050 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001051 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1052 dev_dbg(component->dev, "disabling jack detect before suspend\n");
1053 snd_soc_component_set_jack(component, NULL, NULL);
1054 break;
1055 }
1056 }
1057
1058 return 0;
1059}
1060
1061static int byt_rt5640_resume(struct snd_soc_card *card)
1062{
1063 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1064 struct snd_soc_component *component;
1065
1066 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1067 return 0;
1068
Kuninori Morimotof70f18f72018-09-18 01:29:55 +00001069 for_each_card_components(card, component) {
Hans de Goede77323102018-05-13 09:24:28 +02001070 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1071 dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1072 snd_soc_component_set_jack(component, &priv->jack, NULL);
1073 break;
1074 }
1075 }
1076
1077 return 0;
1078}
1079
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001080static struct snd_soc_card byt_rt5640_card = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001081 .name = "bytcr-rt5640",
Axel Lin54d86972015-08-21 20:59:21 +08001082 .owner = THIS_MODULE,
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001083 .dai_link = byt_rt5640_dais,
1084 .num_links = ARRAY_SIZE(byt_rt5640_dais),
1085 .dapm_widgets = byt_rt5640_widgets,
1086 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1087 .dapm_routes = byt_rt5640_audio_map,
1088 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001089 .fully_routed = true,
Hans de Goede77323102018-05-13 09:24:28 +02001090 .suspend_pre = byt_rt5640_suspend,
1091 .resume_post = byt_rt5640_resume,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301092};
1093
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001094static bool is_valleyview(void)
1095{
Pierre-Louis Bossartcac17732016-08-16 18:28:21 -05001096 static const struct x86_cpu_id cpu_ids[] = {
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001097 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
1098 {}
1099 };
1100
1101 if (!x86_match_cpu(cpu_ids))
1102 return false;
1103 return true;
1104}
1105
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001106struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
1107 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1108 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
1109};
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001110
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001111static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301112{
Hans de Goede063422c2018-05-13 09:24:35 +02001113 const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3" };
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001114 const struct dmi_system_id *dmi_id;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001115 struct byt_rt5640_private *priv;
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001116 struct snd_soc_acpi_mach *mach;
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001117 const char *i2c_name = NULL;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001118 int ret_val = 0;
Pierre-Louis Bossart2193eb92017-10-12 18:38:05 -05001119 int dai_index = 0;
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001120 int i;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001121
Pierre-Louis Bossartcb67d762017-04-24 16:34:33 -05001122 is_bytcr = false;
Jia-Ju Bai7a3a6322018-04-09 18:47:37 +08001123 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001124 if (!priv)
1125 return -ENOMEM;
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301126
1127 /* register the soc card */
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001128 byt_rt5640_card.dev = &pdev->dev;
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001129 mach = byt_rt5640_card.dev->platform_data;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001130 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001131
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001132 /* fix index of codec dai */
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001133 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
1134 if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) {
1135 dai_index = i;
1136 break;
1137 }
1138 }
1139
Pierre-Louis Bossartcaf94ed2016-01-04 17:20:28 -06001140 /* fixup codec name based on HID */
Andy Shevchenko3a147952018-01-12 23:16:17 +02001141 i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1);
Pierre-Louis Bossart17b52732017-10-12 18:37:58 -05001142 if (i2c_name) {
Pierre-Louis Bossarta232b962016-03-03 21:36:38 -06001143 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
1144 "%s%s", "i2c-", i2c_name);
1145
1146 byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name;
1147 }
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301148
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001149 /*
1150 * swap SSP0 if bytcr is detected
1151 * (will be overridden if DMI quirk is detected)
1152 */
1153 if (is_valleyview()) {
Pierre-Louis Bossart3ee1cd42018-11-01 16:34:50 -05001154 if (mach->mach_params.acpi_ipc_irq_index == 0)
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001155 is_bytcr = true;
1156 }
1157
1158 if (is_bytcr) {
1159 /*
1160 * Baytrail CR platforms may have CHAN package in BIOS, try
1161 * to find relevant routing quirk based as done on Windows
1162 * platforms. We have to read the information directly from the
1163 * BIOS, at this stage the card is not created and the links
1164 * with the codec driver/pdata are non-existent
1165 */
1166
1167 struct acpi_chan_package chan_package;
1168
1169 /* format specified: 2 64-bit integers */
1170 struct acpi_buffer format = {sizeof("NN"), "NN"};
1171 struct acpi_buffer state = {0, NULL};
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001172 struct snd_soc_acpi_package_context pkg_ctx;
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001173 bool pkg_found = false;
1174
1175 state.length = sizeof(chan_package);
1176 state.pointer = &chan_package;
1177
1178 pkg_ctx.name = "CHAN";
1179 pkg_ctx.length = 2;
1180 pkg_ctx.format = &format;
1181 pkg_ctx.state = &state;
1182 pkg_ctx.data_valid = false;
1183
Pierre-Louis Bossart7feb2f72017-10-12 18:49:38 -05001184 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1185 &pkg_ctx);
Pierre-Louis Bossart64e84302016-11-12 18:07:45 -06001186 if (pkg_found) {
1187 if (chan_package.aif_value == 1) {
1188 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1189 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1190 } else if (chan_package.aif_value == 2) {
1191 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1192 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1193 } else {
1194 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1195 pkg_found = false;
1196 }
1197 }
1198
1199 if (!pkg_found) {
1200 /* no BIOS indications, assume SSP0-AIF2 connection */
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001201 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1202 }
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001203
1204 /* change defaults for Baytrail-CR capture */
Hans de Goede96a388fe2018-05-13 09:24:30 +02001205 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
Pierre-Louis Bossartbf462412016-11-12 18:07:46 -06001206 } else {
Hans de Goede56ff4402018-05-13 09:24:31 +02001207 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1208 BYT_RT5640_JD_SRC_JD2_IN4N |
1209 BYT_RT5640_OVCD_TH_2000UA |
1210 BYT_RT5640_OVCD_SF_0P75;
Pierre-Louis Bossarte214f5e2016-08-12 16:27:53 -05001211 }
1212
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001213 /* check quirks before creating card */
Hans de Goede6d1bfcc2018-05-13 09:24:33 +02001214 dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1215 if (dmi_id)
1216 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
Takashi Iwai9f2cf732017-04-23 09:22:56 +02001217 if (quirk_override) {
Takashi Iwai0b2c9f82017-04-24 23:34:30 +02001218 dev_info(&pdev->dev, "Overriding quirk 0x%x => 0x%x\n",
Takashi Iwai9f2cf732017-04-23 09:22:56 +02001219 (unsigned int)byt_rt5640_quirk, quirk_override);
1220 byt_rt5640_quirk = quirk_override;
1221 }
Hans de Goede6a7c05e2018-05-08 17:35:54 +02001222
1223 /* Must be called before register_card, also see declaration comment. */
1224 ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name);
1225 if (ret_val)
1226 return ret_val;
1227
Pierre-Louis Bossartd7e60d52016-08-12 16:28:00 -05001228 log_quirks(&pdev->dev);
Pierre-Louis Bossartab738e42016-03-03 21:36:37 -06001229
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001230 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
1231 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
Pierre-Louis Bossart89b89072016-08-12 16:27:50 -05001232
1233 /* fixup codec aif name */
1234 snprintf(byt_rt5640_codec_aif_name,
1235 sizeof(byt_rt5640_codec_aif_name),
1236 "%s", "rt5640-aif2");
1237
1238 byt_rt5640_dais[dai_index].codec_dai_name =
1239 byt_rt5640_codec_aif_name;
1240 }
1241
Pierre-Louis Bossartf47088d2016-08-12 16:27:51 -05001242 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1243 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1244
1245 /* fixup cpu dai name name */
1246 snprintf(byt_rt5640_cpu_dai_name,
1247 sizeof(byt_rt5640_cpu_dai_name),
1248 "%s", "ssp0-port");
1249
1250 byt_rt5640_dais[dai_index].cpu_dai_name =
1251 byt_rt5640_cpu_dai_name;
1252 }
1253
Pierre-Louis Bossart7735bce2017-09-08 12:43:52 -05001254 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001255 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1256 if (IS_ERR(priv->mclk)) {
Pierre-Louis Bossart4a8b3a62016-12-16 10:55:49 -06001257 ret_val = PTR_ERR(priv->mclk);
1258
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001259 dev_err(&pdev->dev,
Pierre-Louis Bossart4a8b3a62016-12-16 10:55:49 -06001260 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1261 ret_val);
1262
1263 /*
1264 * Fall back to bit clock usage for -ENOENT (clock not
1265 * available likely due to missing dependencies), bail
1266 * for all other errors, including -EPROBE_DEFER
1267 */
1268 if (ret_val != -ENOENT)
1269 return ret_val;
1270 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
Irina Tirdeadf1a2772016-08-12 16:27:57 -05001271 }
1272 }
1273
Hans de Goede063422c2018-05-13 09:24:35 +02001274 snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
1275 "bytcr-rt5640-%s-spk-%s-mic",
1276 (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) ?
1277 "mono" : "stereo",
1278 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1279 byt_rt5640_card.long_name = byt_rt5640_long_name;
1280
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001281 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1282
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301283 if (ret_val) {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001284 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1285 ret_val);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301286 return ret_val;
1287 }
Pierre-Louis Bossart9fd57472015-12-17 20:35:42 -06001288 platform_set_drvdata(pdev, &byt_rt5640_card);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301289 return ret_val;
1290}
1291
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001292static struct platform_driver snd_byt_rt5640_mc_driver = {
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301293 .driver = {
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001294 .name = "bytcr_rt5640",
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301295 },
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001296 .probe = snd_byt_rt5640_mc_probe,
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301297};
1298
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001299module_platform_driver(snd_byt_rt5640_mc_driver);
Subhransu S. Prusty996cc842014-11-19 15:13:27 +05301300
1301MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1302MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1303MODULE_LICENSE("GPL v2");
Pierre-Louis Bossarta2d55632015-12-17 20:35:41 -06001304MODULE_ALIAS("platform:bytcr_rt5640");